From e08477d95689a87dcf12ecb8211cf92e0d1e06ba Mon Sep 17 00:00:00 2001 From: "sdwilsh%shawnwilsher.com" Date: Fri, 21 Nov 2008 19:38:01 +0000 Subject: [PATCH] Backout of bug 464299 (SQLite upgrade to 3.6.4) due to possible dataloss regression git-svn-id: svn://10.0.0.236/trunk@255169 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/configure.in | 2 +- mozilla/db/sqlite3/README.MOZILLA | 4 +- mozilla/db/sqlite3/src/sqlite.def | 2 + mozilla/db/sqlite3/src/sqlite3.c | 37185 ++++++---------- mozilla/db/sqlite3/src/sqlite3.h | 4779 +- .../components/places/src/nsNavHistory.cpp | 5 - 6 files changed, 15155 insertions(+), 26822 deletions(-) diff --git a/mozilla/configure.in b/mozilla/configure.in index fb2dac898c4..9ed43014a28 100644 --- a/mozilla/configure.in +++ b/mozilla/configure.in @@ -128,7 +128,7 @@ LIBGNOME_VERSION=2.0 STARTUP_NOTIFICATION_VERSION=0.8 DBUS_VERSION=0.60 LCMS_VERSION=1.17 -SQLITE_VERSION=3.6.4 +SQLITE_VERSION=3.5.9 MSMANIFEST_TOOL= diff --git a/mozilla/db/sqlite3/README.MOZILLA b/mozilla/db/sqlite3/README.MOZILLA index 3aa3e01e55f..ef6b0f666be 100644 --- a/mozilla/db/sqlite3/README.MOZILLA +++ b/mozilla/db/sqlite3/README.MOZILLA @@ -1,6 +1,6 @@ -This is sqlite 3.6.4 +This is sqlite 3.5.9 --- Shawn Wilsher , 11/2008 +-- Shawn Wilsher , 06/2008 See http://www.sqlite.org/ for more info. diff --git a/mozilla/db/sqlite3/src/sqlite.def b/mozilla/db/sqlite3/src/sqlite.def index 2cd57c7c217..ae39ec34b37 100644 --- a/mozilla/db/sqlite3/src/sqlite.def +++ b/mozilla/db/sqlite3/src/sqlite.def @@ -111,7 +111,9 @@ EXPORTS sqlite3_mutex_alloc sqlite3_mutex_enter sqlite3_mutex_free + sqlite3_mutex_held sqlite3_mutex_leave + sqlite3_mutex_notheld sqlite3_mutex_try sqlite3_mprintf sqlite3_open diff --git a/mozilla/db/sqlite3/src/sqlite3.c b/mozilla/db/sqlite3/src/sqlite3.c index 08a468fb65f..9044ec504c5 100644 --- a/mozilla/db/sqlite3/src/sqlite3.c +++ b/mozilla/db/sqlite3/src/sqlite3.c @@ -1,6 +1,6 @@ /****************************************************************************** ** This file is an amalgamation of many separate C source files from SQLite -** version 3.6.4. By combining all the individual C code files into this +** version 3.5.9. By combining all the individual C code files into this ** single large file, the entire code can be compiled as a one translation ** unit. This allows many compilers to do optimizations that would not be ** possible if the files were compiled separately. Performance improvements @@ -11,13 +11,13 @@ ** programs, you need this file and the "sqlite3.h" header file that defines ** the programming interface to the SQLite library. (If you do not have ** the "sqlite3.h" header file at hand, you will find a copy in the first -** 6527 lines past this header comment.) Additional code files may be +** 5638 lines past this header comment.) Additional code files may be ** needed if you want a wrapper to interface SQLite with your choice of ** programming language. The code for the "sqlite3" command-line shell ** is also in a separate file. This file contains only code for the core ** SQLite library. ** -** This amalgamation was generated on 2008-10-15 11:26:48 UTC. +** This amalgamation was generated on 2008-05-14 16:20:58 UTC. */ #define SQLITE_CORE 1 #define SQLITE_AMALGAMATION 1 @@ -41,7 +41,7 @@ ************************************************************************* ** Internal interface definitions for SQLite. ** -** @(#) $Id: sqliteInt.h,v 1.784 2008/10/13 15:35:09 drh Exp $ +** @(#) $Id: sqliteInt.h,v 1.704 2008/05/13 13:27:34 drh Exp $ */ #ifndef _SQLITEINT_H_ #define _SQLITEINT_H_ @@ -253,9 +253,7 @@ #endif /* Needed for various definitions... */ -#ifndef _GNU_SOURCE -# define _GNU_SOURCE -#endif +#define _GNU_SOURCE /* ** Include standard header files as necessary @@ -281,26 +279,6 @@ SQLITE_PRIVATE void sqlite3Coverage(int); # define testcase(X) #endif -/* -** The ALWAYS and NEVER macros surround boolean expressions which -** are intended to always be true or false, respectively. Such -** expressions could be omitted from the code completely. But they -** are included in a few cases in order to enhance the resilience -** of SQLite to unexpected behavior - to make the code "self-healing" -** or "ductile" rather than being "brittle" and crashing at the first -** hint of unplanned behavior. -** -** When doing coverage testing ALWAYS and NEVER are hard-coded to -** be true and false so that the unreachable code then specify will -** not be counted as untested code. -*/ -#ifdef SQLITE_COVERAGE_TEST -# define ALWAYS(X) (1) -# define NEVER(X) (0) -#else -# define ALWAYS(X) (X) -# define NEVER(X) (X) -#endif /* ** The macro unlikely() is a hint that surrounds a boolean @@ -316,22 +294,6 @@ SQLITE_PRIVATE void sqlite3Coverage(int); # define unlikely(X) !!(X) #endif -/* - * This macro is used to "hide" some ugliness in casting an int - * value to a ptr value under the MSVC 64-bit compiler. Casting - * non 64-bit values to ptr types results in a "hard" error with - * the MSVC 64-bit compiler which this attempts to avoid. - * - * A simple compiler pragma or casting sequence could not be found - * to correct this in all situations, so this macro was introduced. - * - * It could be argued that the intptr_t type could be used in this - * case, but that type is not available on all compilers, or - * requires the #include of specific headers which differs between - * platforms. - */ -#define SQLITE_INT_TO_PTR(X) ((void*)&((char*)0)[X]) -#define SQLITE_PTR_TO_INT(X) ((int)(((char*)X)-(char*)0)) /* ** These #defines should enable >2GB file support on Posix if the @@ -374,16 +336,6 @@ SQLITE_PRIVATE void sqlite3Coverage(int); #endif #endif -/* -** The SQLITE_DEFAULT_MEMSTATUS macro must be defined as either 0 or 1. -** It determines whether or not the features related to -** SQLITE_CONFIG_MEMSTATUS are availabe by default or not. This value can -** be overridden at runtime using the sqlite3_config() API. -*/ -#if !defined(SQLITE_DEFAULT_MEMSTATUS) -# define SQLITE_DEFAULT_MEMSTATUS 1 -#endif - /* ** Exactly one of the following macros must be defined in order to ** specify which memory allocation subsystem to use. @@ -435,9 +387,6 @@ SQLITE_PRIVATE void sqlite3Coverage(int); # define _XOPEN_SOURCE 500 /* Needed to enable pthread recursive mutexes */ #endif -/* -** The TCL headers are only needed when compiling the TCL bindings. -*/ #if defined(SQLITE_TCL) || defined(TCLSH) # include #endif @@ -474,7 +423,7 @@ SQLITE_PRIVATE void sqlite3Coverage(int); ** ** Some of the definitions that are in this file are marked as ** "experimental". Experimental interfaces are normally new -** features recently added to SQLite. We do not anticipate changes +** features recently added to SQLite. We do not anticipate changes ** to experimental interfaces but reserve to make minor changes if ** experience from use "in the wild" suggest such changes are prudent. ** @@ -487,7 +436,7 @@ SQLITE_PRIVATE void sqlite3Coverage(int); ** the version number) and changes its name to "sqlite3.h" as ** part of the build process. ** -** @(#) $Id: sqlite.h.in,v 1.404 2008/10/12 00:27:54 shane Exp $ +** @(#) $Id: sqlite.h.in,v 1.312 2008/05/12 12:39:56 drh Exp $ */ #ifndef _SQLITE3_H_ #define _SQLITE3_H_ @@ -509,23 +458,8 @@ extern "C" { #endif /* -** These no-op macros are used in front of interfaces to mark those -** interfaces as either deprecated or experimental. New applications -** should not use deprecated intrfaces - they are support for backwards -** compatibility only. Application writers should be aware that -** experimental interfaces are subject to change in point releases. -** -** These macros used to resolve to various kinds of compiler magic that -** would generate warning messages when they were used. But that -** compiler magic ended up generating such a flurry of bug reports -** that we have taken it all out and gone back to using simple -** noop macros. -*/ -#define SQLITE_DEPRECATED -#define SQLITE_EXPERIMENTAL - -/* -** Ensure these symbols were not defined by some previous header file. +** Make sure these symbols where not defined by some previous header +** file. */ #ifdef SQLITE_VERSION # undef SQLITE_VERSION @@ -535,7 +469,7 @@ extern "C" { #endif /* -** CAPI3REF: Compile-Time Library Version Numbers {H10010} +** CAPI3REF: Compile-Time Library Version Numbers {F10010} ** ** The SQLITE_VERSION and SQLITE_VERSION_NUMBER #defines in ** the sqlite3.h file specify the version of SQLite with which @@ -544,38 +478,39 @@ extern "C" { ** The "version" of SQLite is a string of the form "X.Y.Z". ** The phrase "alpha" or "beta" might be appended after the Z. ** The X value is major version number always 3 in SQLite3. -** The X value only changes when backwards compatibility is -** broken and we intend to never break backwards compatibility. -** The Y value is the minor version number and only changes when +** The X value only changes when backwards compatibility is +** broken and we intend to never break +** backwards compatibility. The Y value is the minor version +** number and only changes when ** there are major feature enhancements that are forwards compatible -** but not backwards compatible. -** The Z value is the release number and is incremented with -** each release but resets back to 0 whenever Y is incremented. +** but not backwards compatible. The Z value is release number +** and is incremented with +** each release but resets back to 0 when Y is incremented. ** ** See also: [sqlite3_libversion()] and [sqlite3_libversion_number()]. ** ** INVARIANTS: ** -** {H10011} The SQLITE_VERSION #define in the sqlite3.h header file shall -** evaluate to a string literal that is the SQLite version +** {F10011} The SQLITE_VERSION #define in the sqlite3.h header file +** evaluates to a string literal that is the SQLite version ** with which the header file is associated. ** -** {H10014} The SQLITE_VERSION_NUMBER #define shall resolve to an integer -** with the value (X*1000000 + Y*1000 + Z) where X, Y, and Z -** are the major version, minor version, and release number. +** {F10014} The SQLITE_VERSION_NUMBER #define resolves to an integer +** with the value (X*1000000 + Y*1000 + Z) where X, Y, and +** Z are the major version, minor version, and release number. */ -#define SQLITE_VERSION "3.6.4" -#define SQLITE_VERSION_NUMBER 3006004 +#define SQLITE_VERSION "3.5.9" +#define SQLITE_VERSION_NUMBER 3005009 /* -** CAPI3REF: Run-Time Library Version Numbers {H10020} +** CAPI3REF: Run-Time Library Version Numbers {F10020} ** KEYWORDS: sqlite3_version ** ** These features provide the same information as the [SQLITE_VERSION] ** and [SQLITE_VERSION_NUMBER] #defines in the header, but are associated ** with the library instead of the header file. Cautious programmers might -** include a check in their application to verify that -** sqlite3_libversion_number() always returns the value +** include a check in their application to verify that +** sqlite3_libversion_number() always returns the value ** [SQLITE_VERSION_NUMBER]. ** ** The sqlite3_libversion() function returns the same information as is @@ -585,13 +520,13 @@ extern "C" { ** ** INVARIANTS: ** -** {H10021} The [sqlite3_libversion_number()] interface shall return -** an integer equal to [SQLITE_VERSION_NUMBER]. +** {F10021} The [sqlite3_libversion_number()] interface returns an integer +** equal to [SQLITE_VERSION_NUMBER]. ** -** {H10022} The [sqlite3_version] string constant shall contain -** the text of the [SQLITE_VERSION] string. +** {F10022} The [sqlite3_version] string constant contains the text of the +** [SQLITE_VERSION] string. ** -** {H10023} The [sqlite3_libversion()] function shall return +** {F10023} The [sqlite3_libversion()] function returns ** a pointer to the [sqlite3_version] string constant. */ SQLITE_API const char sqlite3_version[]; @@ -599,77 +534,64 @@ SQLITE_API const char *sqlite3_libversion(void); SQLITE_API int sqlite3_libversion_number(void); /* -** CAPI3REF: Test To See If The Library Is Threadsafe {H10100} +** CAPI3REF: Test To See If The Library Is Threadsafe {F10100} ** ** SQLite can be compiled with or without mutexes. When -** the [SQLITE_THREADSAFE] C preprocessor macro 1 or 2, mutexes -** are enabled and SQLite is threadsafe. When the -** [SQLITE_THREADSAFE] macro is 0, +** the SQLITE_THREADSAFE C preprocessor macro is true, mutexes +** are enabled and SQLite is threadsafe. When that macro is false, ** the mutexes are omitted. Without the mutexes, it is not safe -** to use SQLite concurrently from more than one thread. +** to use SQLite from more than one thread. ** -** Enabling mutexes incurs a measurable performance penalty. +** There is a measurable performance penalty for enabling mutexes. ** So if speed is of utmost importance, it makes sense to disable ** the mutexes. But for maximum safety, mutexes should be enabled. ** The default behavior is for mutexes to be enabled. ** ** This interface can be used by a program to make sure that the ** version of SQLite that it is linking against was compiled with -** the desired setting of the [SQLITE_THREADSAFE] macro. -** -** This interface only reports on the compile-time mutex setting -** of the [SQLITE_THREADSAFE] flag. If SQLite is compiled with -** SQLITE_THREADSAFE=1 then mutexes are enabled by default but -** can be fully or partially disabled using a call to [sqlite3_config()] -** with the verbs [SQLITE_CONFIG_SINGLETHREAD], [SQLITE_CONFIG_MULTITHREAD], -** or [SQLITE_CONFIG_MUTEX]. The return value of this function shows -** only the default compile-time setting, not any run-time changes -** to that setting. -** -** See the [threading mode] documentation for additional information. +** the desired setting of the SQLITE_THREADSAFE macro. ** ** INVARIANTS: ** -** {H10101} The [sqlite3_threadsafe()] function shall return zero if -** and only if SQLite was compiled with mutexing code omitted. -** -** {H10102} The value returned by the [sqlite3_threadsafe()] function -** shall remain the same across calls to [sqlite3_config()]. +** {F10101} The [sqlite3_threadsafe()] function returns nonzero if +** SQLite was compiled with its mutexes enabled or zero +** if SQLite was compiled with mutexes disabled. */ SQLITE_API int sqlite3_threadsafe(void); /* -** CAPI3REF: Database Connection Handle {H12000} +** CAPI3REF: Database Connection Handle {F12000} ** KEYWORDS: {database connection} {database connections} ** -** Each open SQLite database is represented by a pointer to an instance of -** the opaque structure named "sqlite3". It is useful to think of an sqlite3 +** Each open SQLite database is represented by pointer to an instance of the +** opaque structure named "sqlite3". It is useful to think of an sqlite3 ** pointer as an object. The [sqlite3_open()], [sqlite3_open16()], and -** [sqlite3_open_v2()] interfaces are its constructors, and [sqlite3_close()] -** is its destructor. There are many other interfaces (such as -** [sqlite3_prepare_v2()], [sqlite3_create_function()], and -** [sqlite3_busy_timeout()] to name but three) that are methods on an -** sqlite3 object. +** [sqlite3_open_v2()] interfaces are its constructors +** and [sqlite3_close()] is its destructor. There are many other interfaces +** (such as [sqlite3_prepare_v2()], [sqlite3_create_function()], and +** [sqlite3_busy_timeout()] to name but three) that are methods on this +** object. */ typedef struct sqlite3 sqlite3; + /* -** CAPI3REF: 64-Bit Integer Types {H10200} +** CAPI3REF: 64-Bit Integer Types {F10200} ** KEYWORDS: sqlite_int64 sqlite_uint64 ** ** Because there is no cross-platform way to specify 64-bit integer types ** SQLite includes typedefs for 64-bit signed and unsigned integers. ** -** The sqlite3_int64 and sqlite3_uint64 are the preferred type definitions. -** The sqlite_int64 and sqlite_uint64 types are supported for backwards -** compatibility only. +** The sqlite3_int64 and sqlite3_uint64 are the preferred type +** definitions. The sqlite_int64 and sqlite_uint64 types are +** supported for backwards compatibility only. ** ** INVARIANTS: ** -** {H10201} The [sqlite_int64] and [sqlite3_int64] type shall specify -** a 64-bit signed integer. +** {F10201} The [sqlite_int64] and [sqlite3_int64] types specify a +** 64-bit signed integer. ** -** {H10202} The [sqlite_uint64] and [sqlite3_uint64] type shall specify +** {F10202} The [sqlite_uint64] and [sqlite3_uint64] types specify ** a 64-bit unsigned integer. */ #ifdef SQLITE_INT64_TYPE @@ -687,62 +609,50 @@ typedef sqlite_uint64 sqlite3_uint64; /* ** If compiling for a processor that lacks floating point support, -** substitute integer for floating-point. +** substitute integer for floating-point */ #ifdef SQLITE_OMIT_FLOATING_POINT # define double sqlite3_int64 #endif /* -** CAPI3REF: Closing A Database Connection {H12010} +** CAPI3REF: Closing A Database Connection {F12010} ** -** This routine is the destructor for the [sqlite3] object. +** This routine is the destructor for the [sqlite3] object. ** -** Applications should [sqlite3_finalize | finalize] all [prepared statements] -** and [sqlite3_blob_close | close] all [BLOB handles] associated with -** the [sqlite3] object prior to attempting to close the object. -** The [sqlite3_next_stmt()] interface can be used to locate all -** [prepared statements] associated with a [database connection] if desired. -** Typical code might look like this: +** Applications should [sqlite3_finalize | finalize] all +** [prepared statements] and +** [sqlite3_blob_close | close] all [sqlite3_blob | BLOBs] +** associated with the [sqlite3] object prior +** to attempting to close the [sqlite3] object. ** -**
-** sqlite3_stmt *pStmt;
-** while( (pStmt = sqlite3_next_stmt(db, 0))!=0 ){
-**     sqlite3_finalize(pStmt);
-** }
-** 
-** -** If [sqlite3_close()] is invoked while a transaction is open, -** the transaction is automatically rolled back. +** What happens to pending transactions? Are they +** rolled back, or abandoned? ** ** INVARIANTS: ** -** {H12011} A successful call to [sqlite3_close(C)] shall destroy the -** [database connection] object C. +** {F12011} The [sqlite3_close()] interface destroys an [sqlite3] object +** allocated by a prior call to [sqlite3_open()], +** [sqlite3_open16()], or [sqlite3_open_v2()]. ** -** {H12012} A successful call to [sqlite3_close(C)] shall return SQLITE_OK. +** {F12012} The [sqlite3_close()] function releases all memory used by the +** connection and closes all open files. ** -** {H12013} A successful call to [sqlite3_close(C)] shall release all -** memory and system resources associated with [database connection] -** C. +** {F12013} If the database connection contains +** [prepared statements] that have not been +** finalized by [sqlite3_finalize()], then [sqlite3_close()] +** returns [SQLITE_BUSY] and leaves the connection open. ** -** {H12014} A call to [sqlite3_close(C)] on a [database connection] C that -** has one or more open [prepared statements] shall fail with -** an [SQLITE_BUSY] error code. +** {F12014} Giving sqlite3_close() a NULL pointer is a harmless no-op. ** -** {H12015} A call to [sqlite3_close(C)] where C is a NULL pointer shall -** be a harmless no-op returning SQLITE_OK. +** LIMITATIONS: ** -** {H12019} When [sqlite3_close(C)] is invoked on a [database connection] C -** that has a pending transaction, the transaction shall be -** rolled back. +** {U12015} The parameter to [sqlite3_close()] must be an [sqlite3] object +** pointer previously obtained from [sqlite3_open()] or the +** equivalent, or NULL. ** -** ASSUMPTIONS: -** -** {A12016} The C parameter to [sqlite3_close(C)] must be either a NULL -** pointer or an [sqlite3] object pointer obtained -** from [sqlite3_open()], [sqlite3_open16()], or -** [sqlite3_open_v2()], and not previously closed. +** {U12016} The parameter to [sqlite3_close()] must not have been previously +** closed. */ SQLITE_API int sqlite3_close(sqlite3 *); @@ -754,129 +664,115 @@ SQLITE_API int sqlite3_close(sqlite3 *); typedef int (*sqlite3_callback)(void*,int,char**, char**); /* -** CAPI3REF: One-Step Query Execution Interface {H12100} +** CAPI3REF: One-Step Query Execution Interface {F12100} ** -** The sqlite3_exec() interface is a convenient way of running one or more -** SQL statements without having to write a lot of C code. The UTF-8 encoded -** SQL statements are passed in as the second parameter to sqlite3_exec(). -** The statements are evaluated one by one until either an error or -** an interrupt is encountered, or until they are all done. The 3rd parameter -** is an optional callback that is invoked once for each row of any query -** results produced by the SQL statements. The 5th parameter tells where +** The sqlite3_exec() interface is a convenient way of running +** one or more SQL statements without a lot of C code. The +** SQL statements are passed in as the second parameter to +** sqlite3_exec(). The statements are evaluated one by one +** until either an error or an interrupt is encountered or +** until they are all done. The 3rd parameter is an optional +** callback that is invoked once for each row of any query results +** produced by the SQL statements. The 5th parameter tells where ** to write any error messages. ** -** The error message passed back through the 5th parameter is held -** in memory obtained from [sqlite3_malloc()]. To avoid a memory leak, -** the calling application should call [sqlite3_free()] on any error -** message returned through the 5th parameter when it has finished using -** the error message. -** -** If the SQL statement in the 2nd parameter is NULL or an empty string -** or a string containing only whitespace and comments, then no SQL -** statements are evaluated and the database is not changed. -** ** The sqlite3_exec() interface is implemented in terms of ** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()]. -** The sqlite3_exec() routine does nothing to the database that cannot be done +** The sqlite3_exec() routine does nothing that cannot be done ** by [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()]. +** The sqlite3_exec() is just a convenient wrapper. ** ** INVARIANTS: +** +** {F12101} The [sqlite3_exec()] interface evaluates zero or more UTF-8 +** encoded, semicolon-separated, SQL statements in the +** zero-terminated string of its 2nd parameter within the +** context of the [sqlite3] object given in the 1st parameter. ** -** {H12101} A successful invocation of [sqlite3_exec(D,S,C,A,E)] -** shall sequentially evaluate all of the UTF-8 encoded, -** semicolon-separated SQL statements in the zero-terminated -** string S within the context of the [database connection] D. +** {F12104} The return value of [sqlite3_exec()] is SQLITE_OK if all +** SQL statements run successfully. ** -** {H12102} If the S parameter to [sqlite3_exec(D,S,C,A,E)] is NULL then -** the actions of the interface shall be the same as if the -** S parameter were an empty string. +** {F12105} The return value of [sqlite3_exec()] is an appropriate +** non-zero error code if any SQL statement fails. ** -** {H12104} The return value of [sqlite3_exec()] shall be [SQLITE_OK] if all -** SQL statements run successfully and to completion. -** -** {H12105} The return value of [sqlite3_exec()] shall be an appropriate -** non-zero [error code] if any SQL statement fails. -** -** {H12107} If one or more of the SQL statements handed to [sqlite3_exec()] +** {F12107} If one or more of the SQL statements handed to [sqlite3_exec()] ** return results and the 3rd parameter is not NULL, then -** the callback function specified by the 3rd parameter shall be +** the callback function specified by the 3rd parameter is ** invoked once for each row of result. ** -** {H12110} If the callback returns a non-zero value then [sqlite3_exec()] -** shall abort the SQL statement it is currently evaluating, +** {F12110} If the callback returns a non-zero value then [sqlite3_exec()] +** will aborted the SQL statement it is currently evaluating, ** skip all subsequent SQL statements, and return [SQLITE_ABORT]. +** What happens to *errmsg here? Does the result code for +** sqlite3_errcode() get set? ** -** {H12113} The [sqlite3_exec()] routine shall pass its 4th parameter through +** {F12113} The [sqlite3_exec()] routine will pass its 4th parameter through ** as the 1st parameter of the callback. ** -** {H12116} The [sqlite3_exec()] routine shall set the 2nd parameter of its +** {F12116} The [sqlite3_exec()] routine sets the 2nd parameter of its ** callback to be the number of columns in the current row of ** result. ** -** {H12119} The [sqlite3_exec()] routine shall set the 3rd parameter of its +** {F12119} The [sqlite3_exec()] routine sets the 3rd parameter of its ** callback to be an array of pointers to strings holding the ** values for each column in the current result set row as ** obtained from [sqlite3_column_text()]. ** -** {H12122} The [sqlite3_exec()] routine shall set the 4th parameter of its +** {F12122} The [sqlite3_exec()] routine sets the 4th parameter of its ** callback to be an array of pointers to strings holding the ** names of result columns as obtained from [sqlite3_column_name()]. ** -** {H12125} If the 3rd parameter to [sqlite3_exec()] is NULL then -** [sqlite3_exec()] shall silently discard query results. +** {F12125} If the 3rd parameter to [sqlite3_exec()] is NULL then +** [sqlite3_exec()] never invokes a callback. All query +** results are silently discarded. ** -** {H12131} If an error occurs while parsing or evaluating any of the SQL -** statements in the S parameter of [sqlite3_exec(D,S,C,A,E)] and if -** the E parameter is not NULL, then [sqlite3_exec()] shall store -** in *E an appropriate error message written into memory obtained -** from [sqlite3_malloc()]. +** {F12128} If an error occurs while parsing or evaluating any of the SQL +** statements handed to [sqlite3_exec()] then [sqlite3_exec()] will +** return an [error code] other than [SQLITE_OK]. ** -** {H12134} The [sqlite3_exec(D,S,C,A,E)] routine shall set the value of -** *E to NULL if E is not NULL and there are no errors. +** {F12131} If an error occurs while parsing or evaluating any of the SQL +** handed to [sqlite3_exec()] and if the 5th parameter (errmsg) +** to [sqlite3_exec()] is not NULL, then an error message is +** allocated using the equivalent of [sqlite3_mprintf()] and +** *errmsg is made to point to that message. ** -** {H12137} The [sqlite3_exec(D,S,C,A,E)] function shall set the [error code] -** and message accessible via [sqlite3_errcode()], -** [sqlite3_errmsg()], and [sqlite3_errmsg16()]. +** {F12134} The [sqlite3_exec()] routine does not change the value of +** *errmsg if errmsg is NULL or if there are no errors. ** -** {H12138} If the S parameter to [sqlite3_exec(D,S,C,A,E)] is NULL or an -** empty string or contains nothing other than whitespace, comments, -** and/or semicolons, then results of [sqlite3_errcode()], -** [sqlite3_errmsg()], and [sqlite3_errmsg16()] -** shall reset to indicate no errors. +** {F12137} The [sqlite3_exec()] function sets the error code and message +** accessible via [sqlite3_errcode()], [sqlite3_errmsg()], and +** [sqlite3_errmsg16()]. ** -** ASSUMPTIONS: +** LIMITATIONS: ** -** {A12141} The first parameter to [sqlite3_exec()] must be an valid and open +** {U12141} The first parameter to [sqlite3_exec()] must be an valid and open ** [database connection]. ** -** {A12142} The database connection must not be closed while +** {U12142} The database connection must not be closed while ** [sqlite3_exec()] is running. -** -** {A12143} The calling function should use [sqlite3_free()] to free +** +** {U12143} The calling function is should use [sqlite3_free()] to free ** the memory that *errmsg is left pointing at once the error ** message is no longer needed. ** -** {A12145} The SQL statement text in the 2nd parameter to [sqlite3_exec()] +** {U12145} The SQL statement text in the 2nd parameter to [sqlite3_exec()] ** must remain unchanged while [sqlite3_exec()] is running. */ SQLITE_API int sqlite3_exec( sqlite3*, /* An open database */ - const char *sql, /* SQL to be evaluated */ + const char *sql, /* SQL to be evaluted */ int (*callback)(void*,int,char**,char**), /* Callback function */ void *, /* 1st argument to callback */ char **errmsg /* Error msg written here */ ); /* -** CAPI3REF: Result Codes {H10210} +** CAPI3REF: Result Codes {F10210} ** KEYWORDS: SQLITE_OK {error code} {error codes} -** KEYWORDS: {result code} {result codes} ** ** Many SQLite functions return an integer result code from the set shown ** here in order to indicates success or failure. ** -** New error codes may be added in future versions of SQLite. -** ** See also: [SQLITE_IOERR_READ | extended result codes] */ #define SQLITE_OK 0 /* Successful result */ @@ -912,20 +808,20 @@ SQLITE_API int sqlite3_exec( /* end-of-error-codes */ /* -** CAPI3REF: Extended Result Codes {H10220} +** CAPI3REF: Extended Result Codes {F10220} ** KEYWORDS: {extended error code} {extended error codes} -** KEYWORDS: {extended result code} {extended result codes} +** KEYWORDS: {extended result codes} ** ** In its default configuration, SQLite API routines return one of 26 integer -** [SQLITE_OK | result codes]. However, experience has shown that many of -** these result codes are too coarse-grained. They do not provide as +** [SQLITE_OK | result codes]. However, experience has shown that +** many of these result codes are too course-grained. They do not provide as ** much information about problems as programmers might like. In an effort to ** address this, newer versions of SQLite (version 3.3.8 and later) include ** support for additional result codes that provide more detailed information ** about errors. The extended result codes are enabled or disabled -** on a per database connection basis using the -** [sqlite3_extended_result_codes()] API. -** +** for each database connection using the [sqlite3_extended_result_codes()] +** API. +** ** Some of the available extended result codes are listed here. ** One may expect the number of extended result codes will be expand ** over time. Software that uses extended result codes should expect @@ -933,38 +829,35 @@ SQLITE_API int sqlite3_exec( ** ** The SQLITE_OK result code will never be extended. It will always ** be exactly zero. -** +** ** INVARIANTS: ** -** {H10223} The symbolic name for an extended result code shall contains +** {F10223} The symbolic name for an extended result code always contains ** a related primary result code as a prefix. ** -** {H10224} Primary result code names shall contain a single "_" character. +** {F10224} Primary result code names contain a single "_" character. ** -** {H10225} Extended result code names shall contain two or more "_" characters. +** {F10225} Extended result code names contain two or more "_" characters. ** -** {H10226} The numeric value of an extended result code shall contain the +** {F10226} The numeric value of an extended result code contains the ** numeric value of its corresponding primary result code in ** its least significant 8 bits. */ -#define SQLITE_IOERR_READ (SQLITE_IOERR | (1<<8)) -#define SQLITE_IOERR_SHORT_READ (SQLITE_IOERR | (2<<8)) -#define SQLITE_IOERR_WRITE (SQLITE_IOERR | (3<<8)) -#define SQLITE_IOERR_FSYNC (SQLITE_IOERR | (4<<8)) -#define SQLITE_IOERR_DIR_FSYNC (SQLITE_IOERR | (5<<8)) -#define SQLITE_IOERR_TRUNCATE (SQLITE_IOERR | (6<<8)) -#define SQLITE_IOERR_FSTAT (SQLITE_IOERR | (7<<8)) -#define SQLITE_IOERR_UNLOCK (SQLITE_IOERR | (8<<8)) -#define SQLITE_IOERR_RDLOCK (SQLITE_IOERR | (9<<8)) -#define SQLITE_IOERR_DELETE (SQLITE_IOERR | (10<<8)) -#define SQLITE_IOERR_BLOCKED (SQLITE_IOERR | (11<<8)) -#define SQLITE_IOERR_NOMEM (SQLITE_IOERR | (12<<8)) -#define SQLITE_IOERR_ACCESS (SQLITE_IOERR | (13<<8)) -#define SQLITE_IOERR_CHECKRESERVEDLOCK (SQLITE_IOERR | (14<<8)) -#define SQLITE_IOERR_LOCK (SQLITE_IOERR | (15<<8)) +#define SQLITE_IOERR_READ (SQLITE_IOERR | (1<<8)) +#define SQLITE_IOERR_SHORT_READ (SQLITE_IOERR | (2<<8)) +#define SQLITE_IOERR_WRITE (SQLITE_IOERR | (3<<8)) +#define SQLITE_IOERR_FSYNC (SQLITE_IOERR | (4<<8)) +#define SQLITE_IOERR_DIR_FSYNC (SQLITE_IOERR | (5<<8)) +#define SQLITE_IOERR_TRUNCATE (SQLITE_IOERR | (6<<8)) +#define SQLITE_IOERR_FSTAT (SQLITE_IOERR | (7<<8)) +#define SQLITE_IOERR_UNLOCK (SQLITE_IOERR | (8<<8)) +#define SQLITE_IOERR_RDLOCK (SQLITE_IOERR | (9<<8)) +#define SQLITE_IOERR_DELETE (SQLITE_IOERR | (10<<8)) +#define SQLITE_IOERR_BLOCKED (SQLITE_IOERR | (11<<8)) +#define SQLITE_IOERR_NOMEM (SQLITE_IOERR | (12<<8)) /* -** CAPI3REF: Flags For File Open Operations {H10230} +** CAPI3REF: Flags For File Open Operations {F10230} ** ** These bit values are intended for use in the ** 3rd parameter to the [sqlite3_open_v2()] interface and @@ -983,11 +876,9 @@ SQLITE_API int sqlite3_exec( #define SQLITE_OPEN_TEMP_JOURNAL 0x00001000 #define SQLITE_OPEN_SUBJOURNAL 0x00002000 #define SQLITE_OPEN_MASTER_JOURNAL 0x00004000 -#define SQLITE_OPEN_NOMUTEX 0x00008000 -#define SQLITE_OPEN_FULLMUTEX 0x00010000 /* -** CAPI3REF: Device Characteristics {H10240} +** CAPI3REF: Device Characteristics {F10240} ** ** The xDeviceCapabilities method of the [sqlite3_io_methods] ** object returns an integer which is a vector of the these @@ -1019,7 +910,7 @@ SQLITE_API int sqlite3_exec( #define SQLITE_IOCAP_SEQUENTIAL 0x00000400 /* -** CAPI3REF: File Locking Levels {H10250} +** CAPI3REF: File Locking Levels {F10250} ** ** SQLite uses one of these integer values as the second ** argument to calls it makes to the xLock() and xUnlock() methods @@ -1032,7 +923,7 @@ SQLITE_API int sqlite3_exec( #define SQLITE_LOCK_EXCLUSIVE 4 /* -** CAPI3REF: Synchronization Type Flags {H10260} +** CAPI3REF: Synchronization Type Flags {F10260} ** ** When SQLite invokes the xSync() method of an ** [sqlite3_io_methods] object it uses a combination of @@ -1040,16 +931,17 @@ SQLITE_API int sqlite3_exec( ** ** When the SQLITE_SYNC_DATAONLY flag is used, it means that the ** sync operation only needs to flush data to mass storage. Inode -** information need not be flushed. The SQLITE_SYNC_NORMAL flag means -** to use normal fsync() semantics. The SQLITE_SYNC_FULL flag means +** information need not be flushed. The SQLITE_SYNC_NORMAL flag means +** to use normal fsync() semantics. The SQLITE_SYNC_FULL flag means ** to use Mac OS-X style fullsync instead of fsync(). */ #define SQLITE_SYNC_NORMAL 0x00002 #define SQLITE_SYNC_FULL 0x00003 #define SQLITE_SYNC_DATAONLY 0x00010 + /* -** CAPI3REF: OS Interface Open File Handle {H11110} +** CAPI3REF: OS Interface Open File Handle {F11110} ** ** An [sqlite3_file] object represents an open file in the OS ** interface layer. Individual OS interface implementations will @@ -1064,20 +956,19 @@ struct sqlite3_file { }; /* -** CAPI3REF: OS Interface File Virtual Methods Object {H11120} +** CAPI3REF: OS Interface File Virtual Methods Object {F11120} ** -** Every file opened by the [sqlite3_vfs] xOpen method populates an -** [sqlite3_file] object (or, more commonly, a subclass of the -** [sqlite3_file] object) with a pointer to an instance of this object. -** This object defines the methods used to perform various operations -** against the open file represented by the [sqlite3_file] object. +** Every file opened by the [sqlite3_vfs] xOpen method contains a pointer to +** an instance of this object. This object defines the +** methods used to perform various operations against the open file. ** ** The flags argument to xSync may be one of [SQLITE_SYNC_NORMAL] or ** [SQLITE_SYNC_FULL]. The first choice is the normal fsync(). -** The second choice is a Mac OS-X style fullsync. The [SQLITE_SYNC_DATAONLY] -** flag may be ORed in to indicate that only the data of the file -** and not its inode needs to be synced. -** +* The second choice is an +** OS-X style fullsync. The SQLITE_SYNC_DATA flag may be ORed in to +** indicate that only the data of the file and not its inode needs to be +** synced. +** ** The integer values to xLock() and xUnlock() are one of **
    **
  • [SQLITE_LOCK_NONE], @@ -1086,24 +977,26 @@ struct sqlite3_file { **
  • [SQLITE_LOCK_PENDING], or **
  • [SQLITE_LOCK_EXCLUSIVE]. **
-** xLock() increases the lock. xUnlock() decreases the lock. -** The xCheckReservedLock() method checks whether any database connection, -** either in this process or in some other process, is holding a RESERVED, +** xLock() increases the lock. xUnlock() decreases the lock. +** The xCheckReservedLock() method looks +** to see if any database connection, either in this +** process or in some other process, is holding an RESERVED, ** PENDING, or EXCLUSIVE lock on the file. It returns true -** if such a lock exists and false otherwise. -** +** if such a lock exists and false if not. +** ** The xFileControl() method is a generic interface that allows custom ** VFS implementations to directly control an open file using the -** [sqlite3_file_control()] interface. The second "op" argument is an -** integer opcode. The third argument is a generic pointer intended to -** point to a structure that may contain arguments or space in which to +** [sqlite3_file_control()] interface. The second "op" argument +** is an integer opcode. The third +** argument is a generic pointer which is intended to be a pointer +** to a structure that may contain arguments or space in which to ** write return values. Potential uses for xFileControl() might be ** functions to enable blocking locks with timeouts, to change the ** locking strategy (for example to use dot-file locks), to inquire ** about the status of a lock, or to break stale locks. The SQLite -** core reserves all opcodes less than 100 for its own use. +** core reserves opcodes less than 100 for its own use. ** A [SQLITE_FCNTL_LOCKSTATE | list of opcodes] less than 100 is available. -** Applications that define a custom xFileControl method should use opcodes +** Applications that define a custom xFileControl method should use opcodes ** greater than 100 to avoid conflicts. ** ** The xSectorSize() method returns the sector size of the @@ -1149,7 +1042,7 @@ struct sqlite3_io_methods { int (*xFileSize)(sqlite3_file*, sqlite3_int64 *pSize); int (*xLock)(sqlite3_file*, int); int (*xUnlock)(sqlite3_file*, int); - int (*xCheckReservedLock)(sqlite3_file*, int *pResOut); + int (*xCheckReservedLock)(sqlite3_file*); int (*xFileControl)(sqlite3_file*, int op, void *pArg); int (*xSectorSize)(sqlite3_file*); int (*xDeviceCharacteristics)(sqlite3_file*); @@ -1157,10 +1050,10 @@ struct sqlite3_io_methods { }; /* -** CAPI3REF: Standard File Control Opcodes {H11310} +** CAPI3REF: Standard File Control Opcodes {F11310} ** ** These integer constants are opcodes for the xFileControl method -** of the [sqlite3_io_methods] object and for the [sqlite3_file_control()] +** of the [sqlite3_io_methods] object and to the [sqlite3_file_control()] ** interface. ** ** The [SQLITE_FCNTL_LOCKSTATE] opcode is used for debugging. This @@ -1174,7 +1067,7 @@ struct sqlite3_io_methods { #define SQLITE_FCNTL_LOCKSTATE 1 /* -** CAPI3REF: Mutex Handle {H17110} +** CAPI3REF: Mutex Handle {F17110} ** ** The mutex module within SQLite defines [sqlite3_mutex] to be an ** abstract type for a mutex object. The SQLite core never looks @@ -1186,18 +1079,15 @@ struct sqlite3_io_methods { typedef struct sqlite3_mutex sqlite3_mutex; /* -** CAPI3REF: OS Interface Object {H11140} +** CAPI3REF: OS Interface Object {F11140} ** -** An instance of the sqlite3_vfs object defines the interface between -** the SQLite core and the underlying operating system. The "vfs" +** An instance of this object defines the interface between the +** SQLite core and the underlying operating system. The "vfs" ** in the name of the object stands for "virtual file system". ** -** The value of the iVersion field is initially 1 but may be larger in -** future versions of SQLite. Additional fields may be appended to this -** object when the iVersion value is increased. Note that the structure -** of the sqlite3_vfs object changes in the transaction between -** SQLite version 3.5.9 and 3.6.0 and yet the iVersion field was not -** modified. +** The iVersion field is initially 1 but may be larger for future +** versions of SQLite. Additional fields may be appended to this +** object when the iVersion value is increased. ** ** The szOsFile field is the size of the subclassed [sqlite3_file] ** structure used by this VFS. mxPathname is the maximum length of @@ -1207,10 +1097,9 @@ typedef struct sqlite3_mutex sqlite3_mutex; ** the pNext pointer. The [sqlite3_vfs_register()] ** and [sqlite3_vfs_unregister()] interfaces manage this list ** in a thread-safe way. The [sqlite3_vfs_find()] interface -** searches the list. Neither the application code nor the VFS -** implementation should use the pNext pointer. +** searches the list. ** -** The pNext field is the only field in the sqlite3_vfs +** The pNext field is the only field in the sqlite3_vfs ** structure that SQLite will ever modify. SQLite will only access ** or modify this field while holding a particular static mutex. ** The application should never modify anything within the sqlite3_vfs @@ -1219,28 +1108,23 @@ typedef struct sqlite3_mutex sqlite3_mutex; ** The zName field holds the name of the VFS module. The name must ** be unique across all VFS modules. ** -** {H11141} SQLite will guarantee that the zFilename parameter to xOpen -** is either a NULL pointer or string obtained -** from xFullPathname(). SQLite further guarantees that -** the string will be valid and unchanged until xClose() is -** called. {END} Because of the previous sentense, -** the [sqlite3_file] can safely store a pointer to the +** {F11141} SQLite will guarantee that the zFilename string passed to +** xOpen() is a full pathname as generated by xFullPathname() and +** that the string will be valid and unchanged until xClose() is +** called. {END} So the [sqlite3_file] can store a pointer to the ** filename if it needs to remember the filename for some reason. -** If the zFilename parameter is xOpen is a NULL pointer then xOpen -** must invite its own temporary name for the file. Whenever the -** xFilename parameter is NULL it will also be the case that the -** flags parameter will include [SQLITE_OPEN_DELETEONCLOSE]. ** -** {H11142} The flags argument to xOpen() includes all bits set in +** {F11142} The flags argument to xOpen() includes all bits set in ** the flags argument to [sqlite3_open_v2()]. Or if [sqlite3_open()] ** or [sqlite3_open16()] is used, then flags includes at least ** [SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]. {END} ** If xOpen() opens a file read-only then it sets *pOutFlags to -** include [SQLITE_OPEN_READONLY]. Other bits in *pOutFlags may be set. -** -** {H11143} SQLite will also add one of the following flags to the xOpen() +** include [SQLITE_OPEN_READONLY]. Other bits in *pOutFlags may be +** set. +** +** {F11143} SQLite will also add one of the following flags to the xOpen() ** call, depending on the object being opened: -** +** **
    **
  • [SQLITE_OPEN_MAIN_DB] **
  • [SQLITE_OPEN_MAIN_JOURNAL] @@ -1252,56 +1136,59 @@ typedef struct sqlite3_mutex sqlite3_mutex; **
{END} ** ** The file I/O implementation can use the object type flags to -** change the way it deals with files. For example, an application +** changes the way it deals with files. For example, an application ** that does not care about crash recovery or rollback might make ** the open of a journal file a no-op. Writes to this journal would -** also be no-ops, and any attempt to read the journal would return -** SQLITE_IOERR. Or the implementation might recognize that a database -** file will be doing page-aligned sector reads and writes in a random +** also be no-ops, and any attempt to read the journal would return +** SQLITE_IOERR. Or the implementation might recognize that a database +** file will be doing page-aligned sector reads and writes in a random ** order and set up its I/O subsystem accordingly. -** -** SQLite might also add one of the following flags to the xOpen method: -** +** +** SQLite might also add one of the following flags to the xOpen +** method: +** **
    **
  • [SQLITE_OPEN_DELETEONCLOSE] **
  • [SQLITE_OPEN_EXCLUSIVE] **
-** -** {H11145} The [SQLITE_OPEN_DELETEONCLOSE] flag means the file should be -** deleted when it is closed. {H11146} The [SQLITE_OPEN_DELETEONCLOSE] -** will be set for TEMP databases, journals and for subjournals. -** -** {H11147} The [SQLITE_OPEN_EXCLUSIVE] flag means the file should be opened +** +** {F11145} The [SQLITE_OPEN_DELETEONCLOSE] flag means the file should be +** deleted when it is closed. {F11146} The [SQLITE_OPEN_DELETEONCLOSE] +** will be set for TEMP databases, journals and for subjournals. +** {F11147} The [SQLITE_OPEN_EXCLUSIVE] flag means the file should be opened ** for exclusive access. This flag is set for all files except -** for the main database file. -** -** {H11148} At least szOsFile bytes of memory are allocated by SQLite -** to hold the [sqlite3_file] structure passed as the third -** argument to xOpen. {END} The xOpen method does not have to +** for the main database file. {END} +** +** {F11148} At least szOsFile bytes of memory are allocated by SQLite +** to hold the [sqlite3_file] structure passed as the third +** argument to xOpen. {END} The xOpen method does not have to ** allocate the structure; it should just fill it in. -** -** {H11149} The flags argument to xAccess() may be [SQLITE_ACCESS_EXISTS] -** to test for the existence of a file, or [SQLITE_ACCESS_READWRITE] to -** test whether a file is readable and writable, or [SQLITE_ACCESS_READ] -** to test whether a file is at least readable. {END} The file can be a +** +** {F11149} The flags argument to xAccess() may be [SQLITE_ACCESS_EXISTS] +** to test for the existance of a file, +** or [SQLITE_ACCESS_READWRITE] to test to see +** if a file is readable and writable, or [SQLITE_ACCESS_READ] +** to test to see if a file is at least readable. {END} The file can be a ** directory. -** -** {H11150} SQLite will always allocate at least mxPathname+1 bytes for the -** output buffer xFullPathname. {H11151} The exact size of the output buffer -** is also passed as a parameter to both methods. {END} If the output buffer -** is not large enough, [SQLITE_CANTOPEN] should be returned. Since this is -** handled as a fatal error by SQLite, vfs implementations should endeavor -** to prevent this by setting mxPathname to a sufficiently large value. -** +** +** {F11150} SQLite will always allocate at least mxPathname+1 bytes for +** the output buffers for xGetTempname and xFullPathname. {F11151} The exact +** size of the output buffer is also passed as a parameter to both +** methods. {END} If the output buffer is not large enough, SQLITE_CANTOPEN +** should be returned. As this is handled as a fatal error by SQLite, +** vfs implementations should endeavor to prevent this by setting +** mxPathname to a sufficiently large value. +** ** The xRandomness(), xSleep(), and xCurrentTime() interfaces ** are not strictly a part of the filesystem, but they are ** included in the VFS structure for completeness. ** The xRandomness() function attempts to return nBytes bytes ** of good-quality randomness into zOut. The return value is -** the actual number of bytes of randomness obtained. -** The xSleep() method causes the calling thread to sleep for at +** the actual number of bytes of randomness obtained. The +** xSleep() method causes the calling thread to sleep for at ** least the number of microseconds given. The xCurrentTime() -** method returns a Julian Day Number for the current date and time. +** method returns a Julian Day Number for the current date and +** time. */ typedef struct sqlite3_vfs sqlite3_vfs; struct sqlite3_vfs { @@ -1314,7 +1201,8 @@ struct sqlite3_vfs { int (*xOpen)(sqlite3_vfs*, const char *zName, sqlite3_file*, int flags, int *pOutFlags); int (*xDelete)(sqlite3_vfs*, const char *zName, int syncDir); - int (*xAccess)(sqlite3_vfs*, const char *zName, int flags, int *pResOut); + int (*xAccess)(sqlite3_vfs*, const char *zName, int flags); + int (*xGetTempname)(sqlite3_vfs*, int nOut, char *zOut); int (*xFullPathname)(sqlite3_vfs*, const char *zName, int nOut, char *zOut); void *(*xDlOpen)(sqlite3_vfs*, const char *zFilename); void (*xDlError)(sqlite3_vfs*, int nByte, char *zErrMsg); @@ -1323,518 +1211,50 @@ struct sqlite3_vfs { int (*xRandomness)(sqlite3_vfs*, int nByte, char *zOut); int (*xSleep)(sqlite3_vfs*, int microseconds); int (*xCurrentTime)(sqlite3_vfs*, double*); - int (*xGetLastError)(sqlite3_vfs*, int, char *); /* New fields may be appended in figure versions. The iVersion ** value will increment whenever this happens. */ }; /* -** CAPI3REF: Flags for the xAccess VFS method {H11190} +** CAPI3REF: Flags for the xAccess VFS method {F11190} ** -** {H11191} These integer constants can be used as the third parameter to +** {F11191} These integer constants can be used as the third parameter to ** the xAccess method of an [sqlite3_vfs] object. {END} They determine -** what kind of permissions the xAccess method is looking for. -** {H11192} With SQLITE_ACCESS_EXISTS, the xAccess method -** simply checks whether the file exists. -** {H11193} With SQLITE_ACCESS_READWRITE, the xAccess method -** checks whether the file is both readable and writable. -** {H11194} With SQLITE_ACCESS_READ, the xAccess method -** checks whether the file is readable. +** what kind of permissions the xAccess method is +** looking for. {F11192} With SQLITE_ACCESS_EXISTS, the xAccess method +** simply checks to see if the file exists. {F11193} With +** SQLITE_ACCESS_READWRITE, the xAccess method checks to see +** if the file is both readable and writable. {F11194} With +** SQLITE_ACCESS_READ the xAccess method +** checks to see if the file is readable. */ #define SQLITE_ACCESS_EXISTS 0 #define SQLITE_ACCESS_READWRITE 1 #define SQLITE_ACCESS_READ 2 /* -** CAPI3REF: Initialize The SQLite Library {H10130} -** -** The sqlite3_initialize() routine initializes the -** SQLite library. The sqlite3_shutdown() routine -** deallocates any resources that were allocated by sqlite3_initialize(). -** -** A call to sqlite3_initialize() is an "effective" call if it is -** the first time sqlite3_initialize() is invoked during the lifetime of -** the process, or if it is the first time sqlite3_initialize() is invoked -** following a call to sqlite3_shutdown(). Only an effective call -** of sqlite3_initialize() does any initialization. All other calls -** are harmless no-ops. -** -** Among other things, sqlite3_initialize() shall invoke -** sqlite3_os_init(). Similarly, sqlite3_shutdown() -** shall invoke sqlite3_os_end(). -** -** The sqlite3_initialize() routine returns [SQLITE_OK] on success. -** If for some reason, sqlite3_initialize() is unable to initialize -** the library (perhaps it is unable to allocate a needed resource such -** as a mutex) it returns an [error code] other than [SQLITE_OK]. -** -** The sqlite3_initialize() routine is called internally by many other -** SQLite interfaces so that an application usually does not need to -** invoke sqlite3_initialize() directly. For example, [sqlite3_open()] -** calls sqlite3_initialize() so the SQLite library will be automatically -** initialized when [sqlite3_open()] is called if it has not be initialized -** already. However, if SQLite is compiled with the [SQLITE_OMIT_AUTOINIT] -** compile-time option, then the automatic calls to sqlite3_initialize() -** are omitted and the application must call sqlite3_initialize() directly -** prior to using any other SQLite interface. For maximum portability, -** it is recommended that applications always invoke sqlite3_initialize() -** directly prior to using any other SQLite interface. Future releases -** of SQLite may require this. In other words, the behavior exhibited -** when SQLite is compiled with [SQLITE_OMIT_AUTOINIT] might become the -** default behavior in some future release of SQLite. -** -** The sqlite3_os_init() routine does operating-system specific -** initialization of the SQLite library. The sqlite3_os_end() -** routine undoes the effect of sqlite3_os_init(). Typical tasks -** performed by these routines include allocation or deallocation -** of static resources, initialization of global variables, -** setting up a default [sqlite3_vfs] module, or setting up -** a default configuration using [sqlite3_config()]. -** -** The application should never invoke either sqlite3_os_init() -** or sqlite3_os_end() directly. The application should only invoke -** sqlite3_initialize() and sqlite3_shutdown(). The sqlite3_os_init() -** interface is called automatically by sqlite3_initialize() and -** sqlite3_os_end() is called by sqlite3_shutdown(). Appropriate -** implementations for sqlite3_os_init() and sqlite3_os_end() -** are built into SQLite when it is compiled for unix, windows, or os/2. -** When built for other platforms (using the [SQLITE_OS_OTHER=1] compile-time -** option) the application must supply a suitable implementation for -** sqlite3_os_init() and sqlite3_os_end(). An application-supplied -** implementation of sqlite3_os_init() or sqlite3_os_end() -** must return [SQLITE_OK] on success and some other [error code] upon -** failure. -*/ -SQLITE_API int sqlite3_initialize(void); -SQLITE_API int sqlite3_shutdown(void); -SQLITE_API int sqlite3_os_init(void); -SQLITE_API int sqlite3_os_end(void); - -/* -** CAPI3REF: Configuring The SQLite Library {H14100} -** EXPERIMENTAL -** -** The sqlite3_config() interface is used to make global configuration -** changes to SQLite in order to tune SQLite to the specific needs of -** the application. The default configuration is recommended for most -** applications and so this routine is usually not necessary. It is -** provided to support rare applications with unusual needs. -** -** The sqlite3_config() interface is not threadsafe. The application -** must insure that no other SQLite interfaces are invoked by other -** threads while sqlite3_config() is running. Furthermore, sqlite3_config() -** may only be invoked prior to library initialization using -** [sqlite3_initialize()] or after shutdown by [sqlite3_shutdown()]. -** Note, however, that sqlite3_config() can be called as part of the -** implementation of an application-defined [sqlite3_os_init()]. -** -** The first argument to sqlite3_config() is an integer -** [SQLITE_CONFIG_SINGLETHREAD | configuration option] that determines -** what property of SQLite is to be configured. Subsequent arguments -** vary depending on the [SQLITE_CONFIG_SINGLETHREAD | configuration option] -** in the first argument. -** -** When a configuration option is set, sqlite3_config() returns [SQLITE_OK]. -** If the option is unknown or SQLite is unable to set the option -** then this routine returns a non-zero [error code]. -** -** INVARIANTS: -** -** {H14103} A successful invocation of [sqlite3_config()] shall return -** [SQLITE_OK]. -** -** {H14106} The [sqlite3_config()] interface shall return [SQLITE_MISUSE] -** if it is invoked in between calls to [sqlite3_initialize()] and -** [sqlite3_shutdown()]. -** -** {H14120} A successful call to [sqlite3_config]([SQLITE_CONFIG_SINGLETHREAD]) -** shall set the default [threading mode] to Single-thread. -** -** {H14123} A successful call to [sqlite3_config]([SQLITE_CONFIG_MULTITHREAD]) -** shall set the default [threading mode] to Multi-thread. -** -** {H14126} A successful call to [sqlite3_config]([SQLITE_CONFIG_SERIALIZED]) -** shall set the default [threading mode] to Serialized. -** -** {H14129} A successful call to [sqlite3_config]([SQLITE_CONFIG_MUTEX],X) -** where X is a pointer to an initialized [sqlite3_mutex_methods] -** object shall cause all subsequent mutex operations performed -** by SQLite to use the mutex methods that were present in X -** during the call to [sqlite3_config()]. -** -** {H14132} A successful call to [sqlite3_config]([SQLITE_CONFIG_GETMUTEX],X) -** where X is a pointer to an [sqlite3_mutex_methods] object -** shall overwrite the content of [sqlite3_mutex_methods] object -** with the mutex methods currently in use by SQLite. -** -** {H14135} A successful call to [sqlite3_config]([SQLITE_CONFIG_MALLOC],M) -** where M is a pointer to an initialized [sqlite3_mem_methods] -** object shall cause all subsequent memory allocation operations -** performed by SQLite to use the methods that were present in -** M during the call to [sqlite3_config()]. -** -** {H14138} A successful call to [sqlite3_config]([SQLITE_CONFIG_GETMALLOC],M) -** where M is a pointer to an [sqlite3_mem_methods] object shall -** overwrite the content of [sqlite3_mem_methods] object with -** the memory allocation methods currently in use by -** SQLite. -** -** {H14141} A successful call to [sqlite3_config]([SQLITE_CONFIG_MEMSTATUS],1) -** shall enable the memory allocation status collection logic. -** -** {H14144} A successful call to [sqlite3_config]([SQLITE_CONFIG_MEMSTATUS],0) -** shall disable the memory allocation status collection logic. -** -** {H14147} The memory allocation status collection logic shall be -** enabled by default. -** -** {H14150} A successful call to [sqlite3_config]([SQLITE_CONFIG_SCRATCH],S,Z,N) -** where Z and N are non-negative integers and -** S is a pointer to an aligned memory buffer not less than -** Z*N bytes in size shall cause S to be used by the -** [scratch memory allocator] for as many as N simulataneous -** allocations each of size Z. -** -** {H14153} A successful call to [sqlite3_config]([SQLITE_CONFIG_SCRATCH],S,Z,N) -** where S is a NULL pointer shall disable the -** [scratch memory allocator]. -** -** {H14156} A successful call to -** [sqlite3_config]([SQLITE_CONFIG_PAGECACHE],S,Z,N) -** where Z and N are non-negative integers and -** S is a pointer to an aligned memory buffer not less than -** Z*N bytes in size shall cause S to be used by the -** [pagecache memory allocator] for as many as N simulataneous -** allocations each of size Z. -** -** {H14159} A successful call to -** [sqlite3_config]([SQLITE_CONFIG_PAGECACHE],S,Z,N) -** where S is a NULL pointer shall disable the -** [pagecache memory allocator]. -** -** {H14162} A successful call to [sqlite3_config]([SQLITE_CONFIG_HEAP],H,Z,N) -** where Z and N are non-negative integers and -** H is a pointer to an aligned memory buffer not less than -** Z bytes in size shall enable the [memsys5] memory allocator -** and cause it to use buffer S as its memory source and to use -** a minimum allocation size of N. -** -** {H14165} A successful call to [sqlite3_config]([SQLITE_CONFIG_HEAP],H,Z,N) -** where H is a NULL pointer shall disable the -** [memsys5] memory allocator. -** -** {H14168} A successful call to [sqlite3_config]([SQLITE_CONFIG_LOOKASIDE],Z,N) -** shall cause the default [lookaside memory allocator] configuration -** for new [database connections] to be N slots of Z bytes each. -*/ -SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_config(int, ...); - -/* -** CAPI3REF: Configure database connections {H14200} -** EXPERIMENTAL -** -** The sqlite3_db_config() interface is used to make configuration -** changes to a [database connection]. The interface is similar to -** [sqlite3_config()] except that the changes apply to a single -** [database connection] (specified in the first argument). The -** sqlite3_db_config() interface can only be used immediately after -** the database connection is created using [sqlite3_open()], -** [sqlite3_open16()], or [sqlite3_open_v2()]. -** -** The second argument to sqlite3_db_config(D,V,...) is the -** configuration verb - an integer code that indicates what -** aspect of the [database connection] is being configured. -** The only choice for this value is [SQLITE_DBCONFIG_LOOKASIDE]. -** New verbs are likely to be added in future releases of SQLite. -** Additional arguments depend on the verb. -** -** INVARIANTS: -** -** {H14203} A call to [sqlite3_db_config(D,V,...)] shall return [SQLITE_OK] -** if and only if the call is successful. -** -** {H14206} If one or more slots of the [lookaside memory allocator] for -** [database connection] D are in use, then a call to -** [sqlite3_db_config](D,[SQLITE_DBCONFIG_LOOKASIDE],...) shall -** fail with an [SQLITE_BUSY] return code. -** -** {H14209} A successful call to -** [sqlite3_db_config](D,[SQLITE_DBCONFIG_LOOKASIDE],B,Z,N) where -** D is an open [database connection] and Z and N are positive -** integers and B is an aligned buffer at least Z*N bytes in size -** shall cause the [lookaside memory allocator] for D to use buffer B -** with N slots of Z bytes each. -** -** {H14212} A successful call to -** [sqlite3_db_config](D,[SQLITE_DBCONFIG_LOOKASIDE],B,Z,N) where -** D is an open [database connection] and Z and N are positive -** integers and B is NULL pointer shall cause the -** [lookaside memory allocator] for D to a obtain Z*N byte buffer -** from the primary memory allocator and use that buffer -** with N lookaside slots of Z bytes each. -** -** {H14215} A successful call to -** [sqlite3_db_config](D,[SQLITE_DBCONFIG_LOOKASIDE],B,Z,N) where -** D is an open [database connection] and Z and N are zero shall -** disable the [lookaside memory allocator] for D. -** -** -*/ -SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_db_config(sqlite3*, int op, ...); - -/* -** CAPI3REF: Memory Allocation Routines {H10155} -** EXPERIMENTAL -** -** An instance of this object defines the interface between SQLite -** and low-level memory allocation routines. -** -** This object is used in only one place in the SQLite interface. -** A pointer to an instance of this object is the argument to -** [sqlite3_config()] when the configuration option is -** [SQLITE_CONFIG_MALLOC]. By creating an instance of this object -** and passing it to [sqlite3_config()] during configuration, an -** application can specify an alternative memory allocation subsystem -** for SQLite to use for all of its dynamic memory needs. -** -** Note that SQLite comes with a built-in memory allocator that is -** perfectly adequate for the overwhelming majority of applications -** and that this object is only useful to a tiny minority of applications -** with specialized memory allocation requirements. This object is -** also used during testing of SQLite in order to specify an alternative -** memory allocator that simulates memory out-of-memory conditions in -** order to verify that SQLite recovers gracefully from such -** conditions. -** -** The xMalloc, xFree, and xRealloc methods must work like the -** malloc(), free(), and realloc() functions from the standard library. -** -** xSize should return the allocated size of a memory allocation -** previously obtained from xMalloc or xRealloc. The allocated size -** is always at least as big as the requested size but may be larger. -** -** The xRoundup method returns what would be the allocated size of -** a memory allocation given a particular requested size. Most memory -** allocators round up memory allocations at least to the next multiple -** of 8. Some allocators round up to a larger multiple or to a power of 2. -** -** The xInit method initializes the memory allocator. (For example, -** it might allocate any require mutexes or initialize internal data -** structures. The xShutdown method is invoked (indirectly) by -** [sqlite3_shutdown()] and should deallocate any resources acquired -** by xInit. The pAppData pointer is used as the only parameter to -** xInit and xShutdown. -*/ -typedef struct sqlite3_mem_methods sqlite3_mem_methods; -struct sqlite3_mem_methods { - void *(*xMalloc)(int); /* Memory allocation function */ - void (*xFree)(void*); /* Free a prior allocation */ - void *(*xRealloc)(void*,int); /* Resize an allocation */ - int (*xSize)(void*); /* Return the size of an allocation */ - int (*xRoundup)(int); /* Round up request size to allocation size */ - int (*xInit)(void*); /* Initialize the memory allocator */ - void (*xShutdown)(void*); /* Deinitialize the memory allocator */ - void *pAppData; /* Argument to xInit() and xShutdown() */ -}; - -/* -** CAPI3REF: Configuration Options {H10160} -** EXPERIMENTAL -** -** These constants are the available integer configuration options that -** can be passed as the first argument to the [sqlite3_config()] interface. -** -** New configuration options may be added in future releases of SQLite. -** Existing configuration options might be discontinued. Applications -** should check the return code from [sqlite3_config()] to make sure that -** the call worked. The [sqlite3_config()] interface will return a -** non-zero [error code] if a discontinued or unsupported configuration option -** is invoked. -** -**
-**
SQLITE_CONFIG_SINGLETHREAD
-**
There are no arguments to this option. This option disables -** all mutexing and puts SQLite into a mode where it can only be used -** by a single thread.
-** -**
SQLITE_CONFIG_MULTITHREAD
-**
There are no arguments to this option. This option disables -** mutexing on [database connection] and [prepared statement] objects. -** The application is responsible for serializing access to -** [database connections] and [prepared statements]. But other mutexes -** are enabled so that SQLite will be safe to use in a multi-threaded -** environment as long as no two threads attempt to use the same -** [database connection] at the same time. See the [threading mode] -** documentation for additional information.
-** -**
SQLITE_CONFIG_SERIALIZED
-**
There are no arguments to this option. This option enables -** all mutexes including the recursive -** mutexes on [database connection] and [prepared statement] objects. -** In this mode (which is the default when SQLite is compiled with -** [SQLITE_THREADSAFE=1]) the SQLite library will itself serialize access -** to [database connections] and [prepared statements] so that the -** application is free to use the same [database connection] or the -** same [prepared statement] in different threads at the same time. -** See the [threading mode] documentation for additional information.
-** -**
SQLITE_CONFIG_MALLOC
-**
This option takes a single argument which is a pointer to an -** instance of the [sqlite3_mem_methods] structure. The argument specifies -** alternative low-level memory allocation routines to be used in place of -** the memory allocation routines built into SQLite.
-** -**
SQLITE_CONFIG_GETMALLOC
-**
This option takes a single argument which is a pointer to an -** instance of the [sqlite3_mem_methods] structure. The [sqlite3_mem_methods] -** structure is filled with the currently defined memory allocation routines. -** This option can be used to overload the default memory allocation -** routines with a wrapper that simulations memory allocation failure or -** tracks memory usage, for example.
-** -**
SQLITE_CONFIG_MEMSTATUS
-**
This option takes single argument of type int, interpreted as a -** boolean, which enables or disables the collection of memory allocation -** statistics. When disabled, the following SQLite interfaces become -** non-operational: -**
    -**
  • [sqlite3_memory_used()] -**
  • [sqlite3_memory_highwater()] -**
  • [sqlite3_soft_heap_limit()] -**
  • [sqlite3_status()] -**
-**
-** -**
SQLITE_CONFIG_SCRATCH
-**
This option specifies a static memory buffer that SQLite can use for -** scratch memory. There are three arguments: A pointer to the memory, the -** size of each scratch buffer (sz), and the number of buffers (N). The sz -** argument must be a multiple of 16. The sz parameter should be a few bytes -** larger than the actual scratch space required due internal overhead. -** The first -** argument should point to an allocation of at least sz*N bytes of memory. -** SQLite will use no more than one scratch buffer at once per thread, so -** N should be set to the expected maximum number of threads. The sz -** parameter should be 6 times the size of the largest database page size. -** Scratch buffers are used as part of the btree balance operation. If -** The btree balancer needs additional memory beyond what is provided by -** scratch buffers or if no scratch buffer space is specified, then SQLite -** goes to [sqlite3_malloc()] to obtain the memory it needs.
-** -**
SQLITE_CONFIG_PAGECACHE
-**
This option specifies a static memory buffer that SQLite can use for -** the database page cache. There are three arguments: A pointer to the -** memory, the size of each page buffer (sz), and the number of pages (N). -** The sz argument must be a power of two between 512 and 32768. The first -** argument should point to an allocation of at least sz*N bytes of memory. -** SQLite will use the memory provided by the first argument to satisfy its -** memory needs for the first N pages that it adds to cache. If additional -** page cache memory is needed beyond what is provided by this option, then -** SQLite goes to [sqlite3_malloc()] for the additional storage space. -** The implementation might use one or more of the N buffers to hold -** memory accounting information.
-** -**
SQLITE_CONFIG_HEAP
-**
This option specifies a static memory buffer that SQLite will use -** for all of its dynamic memory allocation needs beyond those provided -** for by [SQLITE_CONFIG_SCRATCH] and [SQLITE_CONFIG_PAGECACHE]. -** There are three arguments: A pointer to the memory, the number of -** bytes in the memory buffer, and the minimum allocation size. If -** the first pointer (the memory pointer) is NULL, then SQLite reverts -** to using its default memory allocator (the system malloc() implementation), -** undoing any prior invocation of [SQLITE_CONFIG_MALLOC]. If the -** memory pointer is not NULL and either [SQLITE_ENABLE_MEMSYS3] or -** [SQLITE_ENABLE_MEMSYS5] are defined, then the alternative memory -** allocator is engaged to handle all of SQLites memory allocation needs.
-** -**
SQLITE_CONFIG_MUTEX
-**
This option takes a single argument which is a pointer to an -** instance of the [sqlite3_mutex_methods] structure. The argument specifies -** alternative low-level mutex routines to be used in place -** the mutex routines built into SQLite.
-** -**
SQLITE_CONFIG_GETMUTEX
-**
This option takes a single argument which is a pointer to an -** instance of the [sqlite3_mutex_methods] structure. The -** [sqlite3_mutex_methods] -** structure is filled with the currently defined mutex routines. -** This option can be used to overload the default mutex allocation -** routines with a wrapper used to track mutex usage for performance -** profiling or testing, for example.
-** -**
SQLITE_CONFIG_LOOKASIDE
-**
This option takes two arguments that determine the default -** memory allcation lookaside optimization. The first argument is the -** size of each lookaside buffer slot and the second is the number of -** slots allocated to each database connection.
-** -**
-*/ -#define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */ -#define SQLITE_CONFIG_MULTITHREAD 2 /* nil */ -#define SQLITE_CONFIG_SERIALIZED 3 /* nil */ -#define SQLITE_CONFIG_MALLOC 4 /* sqlite3_mem_methods* */ -#define SQLITE_CONFIG_GETMALLOC 5 /* sqlite3_mem_methods* */ -#define SQLITE_CONFIG_SCRATCH 6 /* void*, int sz, int N */ -#define SQLITE_CONFIG_PAGECACHE 7 /* void*, int sz, int N */ -#define SQLITE_CONFIG_HEAP 8 /* void*, int nByte, int min */ -#define SQLITE_CONFIG_MEMSTATUS 9 /* boolean */ -#define SQLITE_CONFIG_MUTEX 10 /* sqlite3_mutex_methods* */ -#define SQLITE_CONFIG_GETMUTEX 11 /* sqlite3_mutex_methods* */ -#define SQLITE_CONFIG_CHUNKALLOC 12 /* int threshold */ -#define SQLITE_CONFIG_LOOKASIDE 13 /* int int */ - -/* -** CAPI3REF: Configuration Options {H10170} -** EXPERIMENTAL -** -** These constants are the available integer configuration options that -** can be passed as the second argument to the [sqlite3_db_config()] interface. -** -** New configuration options may be added in future releases of SQLite. -** Existing configuration options might be discontinued. Applications -** should check the return code from [sqlite3_db_config()] to make sure that -** the call worked. The [sqlite3_db_config()] interface will return a -** non-zero [error code] if a discontinued or unsupported configuration option -** is invoked. -** -**
-**
SQLITE_DBCONFIG_LOOKASIDE
-**
This option takes three additional arguments that determine the -** [lookaside memory allocator] configuration for the [database connection]. -** The first argument (the third parameter to [sqlite3_db_config()] is a -** pointer to a memory buffer to use for lookaside memory. The first -** argument may be NULL in which case SQLite will allocate the lookaside -** buffer itself using [sqlite3_malloc()]. The second argument is the -** size of each lookaside buffer slot and the third argument is the number of -** slots. The size of the buffer in the first argument must be greater than -** or equal to the product of the second and third arguments.
-** -**
-*/ -#define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */ - - -/* -** CAPI3REF: Enable Or Disable Extended Result Codes {H12200} +** CAPI3REF: Enable Or Disable Extended Result Codes {F12200} ** ** The sqlite3_extended_result_codes() routine enables or disables the -** [extended result codes] feature of SQLite. The extended result -** codes are disabled by default for historical compatibility considerations. +** [SQLITE_IOERR_READ | extended result codes] feature of SQLite. +** The extended result codes are disabled by default for historical +** compatibility. ** ** INVARIANTS: ** -** {H12201} Each new [database connection] shall have the -** [extended result codes] feature disabled by default. +** {F12201} Each new [database connection] has the +** [extended result codes] feature +** disabled by default. ** -** {H12202} The [sqlite3_extended_result_codes(D,F)] interface shall enable -** [extended result codes] for the [database connection] D -** if the F parameter is true, or disable them if F is false. +** {F12202} The [sqlite3_extended_result_codes(D,F)] interface will enable +** [extended result codes] for the +** [database connection] D if the F parameter +** is true, or disable them if F is false. */ SQLITE_API int sqlite3_extended_result_codes(sqlite3*, int onoff); /* -** CAPI3REF: Last Insert Rowid {H12220} +** CAPI3REF: Last Insert Rowid {F12220} ** ** Each entry in an SQLite table has a unique 64-bit signed ** integer key called the "rowid". The rowid is always available @@ -1844,43 +1264,44 @@ SQLITE_API int sqlite3_extended_result_codes(sqlite3*, int onoff); ** is another alias for the rowid. ** ** This routine returns the rowid of the most recent -** successful [INSERT] into the database from the [database connection] -** in the first argument. If no successful [INSERT]s -** have ever occurred on that database connection, zero is returned. +** successful INSERT into the database from the database connection +** shown in the first argument. If no successful inserts +** have ever occurred on this database connection, zero is returned. ** -** If an [INSERT] occurs within a trigger, then the rowid of the inserted -** row is returned by this routine as long as the trigger is running. -** But once the trigger terminates, the value returned by this routine -** reverts to the last value inserted before the trigger fired. +** If an INSERT occurs within a trigger, then the rowid of the +** inserted row is returned by this routine as long as the trigger +** is running. But once the trigger terminates, the value returned +** by this routine reverts to the last value inserted before the +** trigger fired. ** -** An [INSERT] that fails due to a constraint violation is not a -** successful [INSERT] and does not change the value returned by this +** An INSERT that fails due to a constraint violation is not a +** successful insert and does not change the value returned by this ** routine. Thus INSERT OR FAIL, INSERT OR IGNORE, INSERT OR ROLLBACK, ** and INSERT OR ABORT make no changes to the return value of this -** routine when their insertion fails. When INSERT OR REPLACE +** routine when their insertion fails. When INSERT OR REPLACE ** encounters a constraint violation, it does not fail. The ** INSERT continues to completion after deleting rows that caused ** the constraint problem so INSERT OR REPLACE will always change -** the return value of this interface. +** the return value of this interface. ** -** For the purposes of this routine, an [INSERT] is considered to +** For the purposes of this routine, an insert is considered to ** be successful even if it is subsequently rolled back. ** ** INVARIANTS: ** -** {H12221} The [sqlite3_last_insert_rowid()] function shall return the rowid -** of the most recent successful [INSERT] performed on the same -** [database connection] and within the same or higher level -** trigger context, or zero if there have been no qualifying -** [INSERT] statements. +** {F12221} The [sqlite3_last_insert_rowid()] function returns the +** rowid of the most recent successful insert done +** on the same database connection and within the same +** trigger context, or zero if there have +** been no qualifying inserts on that connection. ** -** {H12223} The [sqlite3_last_insert_rowid()] function shall return the +** {F12223} The [sqlite3_last_insert_rowid()] function returns ** same value when called from the same trigger context -** immediately before and after a [ROLLBACK]. +** immediately before and after a ROLLBACK. ** -** ASSUMPTIONS: +** LIMITATIONS: ** -** {A12232} If a separate thread performs a new [INSERT] on the same +** {U12232} If a separate thread does a new insert on the same ** database connection while the [sqlite3_last_insert_rowid()] ** function is running and thus changes the last insert rowid, ** then the value returned by [sqlite3_last_insert_rowid()] is @@ -1890,13 +1311,13 @@ SQLITE_API int sqlite3_extended_result_codes(sqlite3*, int onoff); SQLITE_API sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*); /* -** CAPI3REF: Count The Number Of Rows Modified {H12240} +** CAPI3REF: Count The Number Of Rows Modified {F12240} ** ** This function returns the number of database rows that were changed ** or inserted or deleted by the most recently completed SQL statement -** on the [database connection] specified by the first parameter. -** Only changes that are directly specified by the [INSERT], [UPDATE], -** or [DELETE] statement are counted. Auxiliary changes caused by +** on the connection specified by the first parameter. Only +** changes that are directly specified by the INSERT, UPDATE, or +** DELETE statement are counted. Auxiliary changes caused by ** triggers are not counted. Use the [sqlite3_total_changes()] function ** to find the total number of changes including changes caused by triggers. ** @@ -1920,93 +1341,84 @@ SQLITE_API sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*); ** most recent INSERT, UPDATE, or DELETE statement within the same ** trigger context. ** -** Thus, when called from the top level, this function returns the +** So when called from the top level, this function returns the ** number of changes in the most recent INSERT, UPDATE, or DELETE -** that also occurred at the top level. Within the body of a trigger, -** the sqlite3_changes() interface can be called to find the number of +** that also occurred at the top level. +** Within the body of a trigger, the sqlite3_changes() interface +** can be called to find the number of ** changes in the most recently completed INSERT, UPDATE, or DELETE ** statement within the body of the same trigger. -** However, the number returned does not include changes -** caused by subtriggers since those have their own context. +** However, the number returned does not include in changes +** caused by subtriggers since they have their own context. ** -** SQLite implements the command "DELETE FROM table" without a WHERE clause -** by dropping and recreating the table. Doing so is much faster than going -** through and deleting individual elements from the table. Because of this -** optimization, the deletions in "DELETE FROM table" are not row changes and -** will not be counted by the sqlite3_changes() or [sqlite3_total_changes()] -** functions, regardless of the number of elements that were originally -** in the table. To get an accurate count of the number of rows deleted, use -** "DELETE FROM table WHERE 1" instead. Or recompile using the -** [SQLITE_OMIT_TRUNCATE_OPTIMIZATION] compile-time option to disable the -** optimization on all queries. +** SQLite implements the command "DELETE FROM table" without +** a WHERE clause by dropping and recreating the table. (This is much +** faster than going through and deleting individual elements from the +** table.) Because of this optimization, the deletions in +** "DELETE FROM table" are not row changes and will not be counted +** by the sqlite3_changes() or [sqlite3_total_changes()] functions. +** To get an accurate count of the number of rows deleted, use +** "DELETE FROM table WHERE 1" instead. ** ** INVARIANTS: ** -** {H12241} The [sqlite3_changes()] function shall return the number of +** {F12241} The [sqlite3_changes()] function returns the number of ** row changes caused by the most recent INSERT, UPDATE, ** or DELETE statement on the same database connection and -** within the same or higher trigger context, or zero if there have +** within the same trigger context, or zero if there have ** not been any qualifying row changes. ** -** {H12243} Statements of the form "DELETE FROM tablename" with no -** WHERE clause shall cause subsequent calls to -** [sqlite3_changes()] to return zero, regardless of the -** number of rows originally in the table. +** LIMITATIONS: ** -** ASSUMPTIONS: -** -** {A12252} If a separate thread makes changes on the same database connection +** {U12252} If a separate thread makes changes on the same database connection ** while [sqlite3_changes()] is running then the value returned -** is unpredictable and not meaningful. +** is unpredictable and unmeaningful. */ SQLITE_API int sqlite3_changes(sqlite3*); /* -** CAPI3REF: Total Number Of Rows Modified {H12260} -** -** This function returns the number of row changes caused by INSERT, -** UPDATE or DELETE statements since the [database connection] was opened. -** The count includes all changes from all trigger contexts. However, -** the count does not include changes used to implement REPLACE constraints, -** do rollbacks or ABORT processing, or DROP table processing. -** The changes are counted as soon as the statement that makes them is -** completed (when the statement handle is passed to [sqlite3_reset()] or +** CAPI3REF: Total Number Of Rows Modified {F12260} +*** +** This function returns the number of row changes caused +** by INSERT, UPDATE or DELETE statements since the database handle +** was opened. The count includes all changes from all trigger +** contexts. But the count does not include changes used to +** implement REPLACE constraints, do rollbacks or ABORT processing, +** or DROP table processing. +** The changes +** are counted as soon as the statement that makes them is completed +** (when the statement handle is passed to [sqlite3_reset()] or ** [sqlite3_finalize()]). ** -** SQLite implements the command "DELETE FROM table" without a WHERE clause -** by dropping and recreating the table. (This is much faster than going -** through and deleting individual elements from the table.) Because of this -** optimization, the deletions in "DELETE FROM table" are not row changes and -** will not be counted by the sqlite3_changes() or [sqlite3_total_changes()] -** functions, regardless of the number of elements that were originally -** in the table. To get an accurate count of the number of rows deleted, use -** "DELETE FROM table WHERE 1" instead. Or recompile using the -** [SQLITE_OMIT_TRUNCATE_OPTIMIZATION] compile-time option to disable the -** optimization on all queries. +** SQLite implements the command "DELETE FROM table" without +** a WHERE clause by dropping and recreating the table. (This is much +** faster than going +** through and deleting individual elements from the table.) Because of +** this optimization, the change count for "DELETE FROM table" will be +** zero regardless of the number of elements that were originally in the +** table. To get an accurate count of the number of rows deleted, use +** "DELETE FROM table WHERE 1" instead. ** ** See also the [sqlite3_changes()] interface. ** ** INVARIANTS: -** -** {H12261} The [sqlite3_total_changes()] returns the total number +** +** {F12261} The [sqlite3_total_changes()] returns the total number ** of row changes caused by INSERT, UPDATE, and/or DELETE ** statements on the same [database connection], in any -** trigger context, since the database connection was created. +** trigger context, since the database connection was +** created. ** -** {H12263} Statements of the form "DELETE FROM tablename" with no -** WHERE clause shall not change the value returned -** by [sqlite3_total_changes()]. +** LIMITATIONS: ** -** ASSUMPTIONS: -** -** {A12264} If a separate thread makes changes on the same database connection -** while [sqlite3_total_changes()] is running then the value -** returned is unpredictable and not meaningful. +** {U12264} If a separate thread makes changes on the same database connection +** while [sqlite3_total_changes()] is running then the value +** returned is unpredictable and unmeaningful. */ SQLITE_API int sqlite3_total_changes(sqlite3*); /* -** CAPI3REF: Interrupt A Long-Running Query {H12270} +** CAPI3REF: Interrupt A Long-Running Query {F12270} ** ** This function causes any pending database operation to abort and ** return at its earliest opportunity. This routine is typically @@ -2016,39 +1428,38 @@ SQLITE_API int sqlite3_total_changes(sqlite3*); ** ** It is safe to call this routine from a thread different from the ** thread that is currently running the database operation. But it -** is not safe to call this routine with a [database connection] that +** is not safe to call this routine with a database connection that ** is closed or might close before sqlite3_interrupt() returns. ** -** If an SQL operation is very nearly finished at the time when -** sqlite3_interrupt() is called, then it might not have an opportunity -** to be interrupted and might continue to completion. -** -** An SQL operation that is interrupted will return [SQLITE_INTERRUPT]. -** If the interrupted SQL operation is an INSERT, UPDATE, or DELETE -** that is inside an explicit transaction, then the entire transaction -** will be rolled back automatically. -** +** If an SQL is very nearly finished at the time when sqlite3_interrupt() +** is called, then it might not have an opportunity to be interrupted. +** It might continue to completion. +** An SQL operation that is interrupted will return +** [SQLITE_INTERRUPT]. If the interrupted SQL operation is an +** INSERT, UPDATE, or DELETE that is inside an explicit transaction, +** then the entire transaction will be rolled back automatically. ** A call to sqlite3_interrupt() has no effect on SQL statements ** that are started after sqlite3_interrupt() returns. ** ** INVARIANTS: ** -** {H12271} The [sqlite3_interrupt()] interface will force all running +** {F12271} The [sqlite3_interrupt()] interface will force all running ** SQL statements associated with the same database connection -** to halt after processing at most one additional row of data. +** to halt after processing at most one additional row of +** data. ** -** {H12272} Any SQL statement that is interrupted by [sqlite3_interrupt()] +** {F12272} Any SQL statement that is interrupted by [sqlite3_interrupt()] ** will return [SQLITE_INTERRUPT]. ** -** ASSUMPTIONS: +** LIMITATIONS: ** -** {A12279} If the database connection closes while [sqlite3_interrupt()] +** {U12279} If the database connection closes while [sqlite3_interrupt()] ** is running then bad things will likely happen. */ SQLITE_API void sqlite3_interrupt(sqlite3*); /* -** CAPI3REF: Determine If An SQL Statement Is Complete {H10510} +** CAPI3REF: Determine If An SQL Statement Is Complete {F10510} ** ** These routines are useful for command-line input to determine if the ** currently entered text seems to form complete a SQL statement or @@ -2061,56 +1472,54 @@ SQLITE_API void sqlite3_interrupt(sqlite3*); ** independent tokens (they are part of the token in which they are ** embedded) and thus do not count as a statement terminator. ** -** These routines do not parse the SQL statements thus -** will not detect syntactically incorrect SQL. +** These routines do not parse the SQL and +** so will not detect syntactically incorrect SQL. ** ** INVARIANTS: ** -** {H10511} A successful evaluation of [sqlite3_complete()] or -** [sqlite3_complete16()] functions shall -** return a numeric 1 if and only if the last non-whitespace -** token in their input is a semicolon that is not in between -** the BEGIN and END of a CREATE TRIGGER statement. +** {F10511} The sqlite3_complete() and sqlite3_complete16() functions +** return true (non-zero) if and only if the last +** non-whitespace token in their input is a semicolon that +** is not in between the BEGIN and END of a CREATE TRIGGER +** statement. ** -** {H10512} If a memory allocation error occurs during an invocation -** of [sqlite3_complete()] or [sqlite3_complete16()] then the -** routine shall return [SQLITE_NOMEM]. +** LIMITATIONS: ** -** ASSUMPTIONS: -** -** {A10512} The input to [sqlite3_complete()] must be a zero-terminated +** {U10512} The input to sqlite3_complete() must be a zero-terminated ** UTF-8 string. ** -** {A10513} The input to [sqlite3_complete16()] must be a zero-terminated +** {U10513} The input to sqlite3_complete16() must be a zero-terminated ** UTF-16 string in native byte order. */ SQLITE_API int sqlite3_complete(const char *sql); SQLITE_API int sqlite3_complete16(const void *sql); /* -** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors {H12310} +** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors {F12310} ** -** This routine sets a callback function that might be invoked whenever -** an attempt is made to open a database table that another thread -** or process has locked. -** -** If the busy callback is NULL, then [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED] -** is returned immediately upon encountering the lock. If the busy callback -** is not NULL, then the callback will be invoked with two arguments. -** -** The first argument to the handler is a copy of the void* pointer which -** is the third argument to sqlite3_busy_handler(). The second argument to -** the handler callback is the number of times that the busy handler has -** been invoked for this locking event. If the +** This routine identifies a callback function that might be +** invoked whenever an attempt is made to open a database table +** that another thread or process has locked. +** If the busy callback is NULL, then [SQLITE_BUSY] +** or [SQLITE_IOERR_BLOCKED] +** is returned immediately upon encountering the lock. +** If the busy callback is not NULL, then the +** callback will be invoked with two arguments. The +** first argument to the handler is a copy of the void* pointer which +** is the third argument to this routine. The second argument to +** the handler is the number of times that the busy handler has +** been invoked for this locking event. If the ** busy callback returns 0, then no additional attempts are made to ** access the database and [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED] is returned. ** If the callback returns non-zero, then another attempt ** is made to open the database for reading and the cycle repeats. ** -** The presence of a busy handler does not guarantee that it will be invoked -** when there is lock contention. If SQLite determines that invoking the busy -** handler could result in a deadlock, it will go ahead and return [SQLITE_BUSY] -** or [SQLITE_IOERR_BLOCKED] instead of invoking the busy handler. +** The presence of a busy handler does not guarantee that +** it will be invoked when there is lock contention. +** If SQLite determines that invoking the busy handler could result in +** a deadlock, it will go ahead and return [SQLITE_BUSY] or +** [SQLITE_IOERR_BLOCKED] instead of invoking the +** busy handler. ** Consider a scenario where one process is holding a read lock that ** it is trying to promote to a reserved lock and ** a second process is holding a reserved lock that it is trying @@ -2135,86 +1544,82 @@ SQLITE_API int sqlite3_complete16(const void *sql); ** code is promoted from the relatively benign [SQLITE_BUSY] to ** the more severe [SQLITE_IOERR_BLOCKED]. This error code promotion ** forces an automatic rollback of the changes. See the -** +** ** CorruptionFollowingBusyError wiki page for a discussion of why ** this is important. +** +** There can only be a single busy handler defined for each database +** connection. Setting a new busy handler clears any previous one. +** Note that calling [sqlite3_busy_timeout()] will also set or clear +** the busy handler. ** -** There can only be a single busy handler defined for each -** [database connection]. Setting a new busy handler clears any -** previously set handler. Note that calling [sqlite3_busy_timeout()] -** will also set or clear the busy handler. -** -** The busy callback should not take any actions which modify the -** database connection that invoked the busy handler. Any such actions -** result in undefined behavior. -** ** INVARIANTS: ** -** {H12311} The [sqlite3_busy_handler(D,C,A)] function shall replace -** busy callback in the [database connection] D with a new -** a new busy handler C and application data pointer A. +** {F12311} The [sqlite3_busy_handler()] function replaces the busy handler +** callback in the database connection identified by the 1st +** parameter with a new busy handler identified by the 2nd and 3rd +** parameters. ** -** {H12312} Newly created [database connections] shall have a busy -** handler of NULL. +** {F12312} The default busy handler for new database connections is NULL. ** -** {H12314} When two or more [database connections] share a -** [sqlite3_enable_shared_cache | common cache], +** {F12314} When two or more database connection share a common cache, ** the busy handler for the database connection currently using -** the cache shall be invoked when the cache encounters a lock. +** the cache is invoked when the cache encounters a lock. ** -** {H12316} If a busy handler callback returns zero, then the SQLite interface -** that provoked the locking event shall return [SQLITE_BUSY]. +** {F12316} If a busy handler callback returns zero, then the SQLite +** interface that provoked the locking event will return +** [SQLITE_BUSY]. ** -** {H12318} SQLite shall invokes the busy handler with two arguments which +** {F12318} SQLite will invokes the busy handler with two argument which ** are a copy of the pointer supplied by the 3rd parameter to ** [sqlite3_busy_handler()] and a count of the number of prior ** invocations of the busy handler for the same locking event. ** -** ASSUMPTIONS: +** LIMITATIONS: ** -** {A12319} A busy handler must not close the database connection -** or [prepared statement] that invoked the busy handler. +** {U12319} A busy handler should not call close the database connection +** or prepared statement that invoked the busy handler. */ SQLITE_API int sqlite3_busy_handler(sqlite3*, int(*)(void*,int), void*); /* -** CAPI3REF: Set A Busy Timeout {H12340} +** CAPI3REF: Set A Busy Timeout {F12340} ** -** This routine sets a [sqlite3_busy_handler | busy handler] that sleeps -** for a specified amount of time when a table is locked. The handler -** will sleep multiple times until at least "ms" milliseconds of sleeping -** have accumulated. {H12343} After "ms" milliseconds of sleeping, -** the handler returns 0 which causes [sqlite3_step()] to return -** [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED]. +** This routine sets a [sqlite3_busy_handler | busy handler] +** that sleeps for a while when a +** table is locked. The handler will sleep multiple times until +** at least "ms" milliseconds of sleeping have been done. {F12343} After +** "ms" milliseconds of sleeping, the handler returns 0 which +** causes [sqlite3_step()] to return [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED]. ** ** Calling this routine with an argument less than or equal to zero ** turns off all busy handlers. ** -** There can only be a single busy handler for a particular -** [database connection] any any given moment. If another busy handler -** was defined (using [sqlite3_busy_handler()]) prior to calling +** There can only be a single busy handler for a particular database +** connection. If another busy handler was defined +** (using [sqlite3_busy_handler()]) prior to calling ** this routine, that other busy handler is cleared. ** ** INVARIANTS: ** -** {H12341} The [sqlite3_busy_timeout()] function shall override any prior +** {F12341} The [sqlite3_busy_timeout()] function overrides any prior ** [sqlite3_busy_timeout()] or [sqlite3_busy_handler()] setting -** on the same [database connection]. +** on the same database connection. ** -** {H12343} If the 2nd parameter to [sqlite3_busy_timeout()] is less than -** or equal to zero, then the busy handler shall be cleared so that +** {F12343} If the 2nd parameter to [sqlite3_busy_timeout()] is less than +** or equal to zero, then the busy handler is cleared so that ** all subsequent locking events immediately return [SQLITE_BUSY]. ** -** {H12344} If the 2nd parameter to [sqlite3_busy_timeout()] is a positive -** number N, then a busy handler shall be set that repeatedly calls -** the xSleep() method in the [sqlite3_vfs | VFS interface] until -** either the lock clears or until the cumulative sleep time -** reported back by xSleep() exceeds N milliseconds. +** {F12344} If the 2nd parameter to [sqlite3_busy_timeout()] is a positive +** number N, then a busy handler is set that repeatedly calls +** the xSleep() method in the VFS interface until either the +** lock clears or until the cumulative sleep time reported back +** by xSleep() exceeds N milliseconds. */ SQLITE_API int sqlite3_busy_timeout(sqlite3*, int ms); /* -** CAPI3REF: Convenience Routines For Running Queries {H12370} +** CAPI3REF: Convenience Routines For Running Queries {F12370} ** ** Definition: A result table is memory data structure created by the ** [sqlite3_get_table()] interface. A result table records the @@ -2225,14 +1630,16 @@ SQLITE_API int sqlite3_busy_timeout(sqlite3*, int ms); ** numbers are obtained separately. Let N be the number of rows ** and M be the number of columns. ** -** A result table is an array of pointers to zero-terminated UTF-8 strings. -** There are (N+1)*M elements in the array. The first M pointers point -** to zero-terminated strings that contain the names of the columns. -** The remaining entries all point to query results. NULL values result -** in NULL pointers. All other values are in their UTF-8 zero-terminated -** string representation as returned by [sqlite3_column_text()]. +** A result table is an array of pointers to zero-terminated +** UTF-8 strings. There are (N+1)*M elements in the array. +** The first M pointers point to zero-terminated strings that +** contain the names of the columns. +** The remaining entries all point to query results. NULL +** values are give a NULL pointer. All other values are in +** their UTF-8 zero-terminated string representation as returned by +** [sqlite3_column_text()]. ** -** A result table might consist of one or more memory allocations. +** A result table might consists of one or more memory allocations. ** It is not safe to pass a result table directly to [sqlite3_free()]. ** A result table should be deallocated using [sqlite3_free_table()]. ** @@ -2267,11 +1674,11 @@ SQLITE_API int sqlite3_busy_timeout(sqlite3*, int ms); ** string of its 2nd parameter. It returns a result table to the ** pointer given in its 3rd parameter. ** -** After the calling function has finished using the result, it should -** pass the pointer to the result table to sqlite3_free_table() in order to -** release the memory that was malloced. Because of the way the +** After the calling function has finished using the result, it should +** pass the pointer to the result table to sqlite3_free_table() in order to +** release the memory that was malloc-ed. Because of the way the ** [sqlite3_malloc()] happens within sqlite3_get_table(), the calling -** function must not try to call [sqlite3_free()] directly. Only +** function must not try to call [sqlite3_free()] directly. Only ** [sqlite3_free_table()] is able to release the memory properly and safely. ** ** The sqlite3_get_table() interface is implemented as a wrapper around @@ -2279,53 +1686,43 @@ SQLITE_API int sqlite3_busy_timeout(sqlite3*, int ms); ** to any internal data structures of SQLite. It uses only the public ** interface defined here. As a consequence, errors that occur in the ** wrapper layer outside of the internal [sqlite3_exec()] call are not -** reflected in subsequent calls to [sqlite3_errcode()] or [sqlite3_errmsg()]. +** reflected in subsequent calls to [sqlite3_errcode()] or +** [sqlite3_errmsg()]. ** ** INVARIANTS: ** -** {H12371} If a [sqlite3_get_table()] fails a memory allocation, then -** it shall free the result table under construction, abort the -** query in process, skip any subsequent queries, set the -** *pazResult output pointer to NULL and return [SQLITE_NOMEM]. +** {F12371} If a [sqlite3_get_table()] fails a memory allocation, then +** it frees the result table under construction, aborts the +** query in process, skips any subsequent queries, sets the +** *resultp output pointer to NULL and returns [SQLITE_NOMEM]. ** -** {H12373} If the pnColumn parameter to [sqlite3_get_table()] is not NULL -** then a successful invocation of [sqlite3_get_table()] shall -** write the number of columns in the -** result set of the query into *pnColumn. +** {F12373} If the ncolumn parameter to [sqlite3_get_table()] is not NULL +** then [sqlite3_get_table()] write the number of columns in the +** result set of the query into *ncolumn if the query is +** successful (if the function returns SQLITE_OK). ** -** {H12374} If the pnRow parameter to [sqlite3_get_table()] is not NULL -** then a successful invocation of [sqlite3_get_table()] shall -** writes the number of rows in the -** result set of the query into *pnRow. +** {F12374} If the nrow parameter to [sqlite3_get_table()] is not NULL +** then [sqlite3_get_table()] write the number of rows in the +** result set of the query into *nrow if the query is +** successful (if the function returns SQLITE_OK). ** -** {H12376} A successful invocation of [sqlite3_get_table()] that computes -** N rows of result with C columns per row shall make *pazResult -** point to an array of pointers to (N+1)*C strings where the first -** C strings are column names as obtained from -** [sqlite3_column_name()] and the rest are column result values -** obtained from [sqlite3_column_text()]. -** -** {H12379} The values in the pazResult array returned by [sqlite3_get_table()] -** shall remain valid until cleared by [sqlite3_free_table()]. -** -** {H12382} When an error occurs during evaluation of [sqlite3_get_table()] -** the function shall set *pazResult to NULL, write an error message -** into memory obtained from [sqlite3_malloc()], make -** **pzErrmsg point to that error message, and return a -** appropriate [error code]. +** {F12376} The [sqlite3_get_table()] function sets its *ncolumn value +** to the number of columns in the result set of the query in the +** sql parameter, or to zero if the query in sql has an empty +** result set. */ SQLITE_API int sqlite3_get_table( - sqlite3 *db, /* An open database */ - const char *zSql, /* SQL to be evaluated */ - char ***pazResult, /* Results of the query */ - int *pnRow, /* Number of result rows written here */ - int *pnColumn, /* Number of result columns written here */ - char **pzErrmsg /* Error msg written here */ + sqlite3*, /* An open database */ + const char *sql, /* SQL to be evaluated */ + char ***pResult, /* Results of the query */ + int *nrow, /* Number of result rows written here */ + int *ncolumn, /* Number of result columns written here */ + char **errmsg /* Error msg written here */ ); SQLITE_API void sqlite3_free_table(char **result); /* -** CAPI3REF: Formatted String Printing Functions {H17400} +** CAPI3REF: Formatted String Printing Functions {F17400} ** ** These routines are workalikes of the "printf()" family of functions ** from the standard C library. @@ -2333,7 +1730,7 @@ SQLITE_API void sqlite3_free_table(char **result); ** The sqlite3_mprintf() and sqlite3_vmprintf() routines write their ** results into memory obtained from [sqlite3_malloc()]. ** The strings returned by these two routines should be -** released by [sqlite3_free()]. Both routines return a +** released by [sqlite3_free()]. Both routines return a ** NULL pointer if [sqlite3_malloc()] is unable to allocate enough ** memory to hold the resulting string. ** @@ -2358,7 +1755,7 @@ SQLITE_API void sqlite3_free_table(char **result); ** ** These routines all implement some additional formatting ** options that are useful for constructing SQL statements. -** All of the usual printf() formatting options apply. In addition, there +** All of the usual printf formatting options apply. In addition, there ** is are "%q", "%Q", and "%z" options. ** ** The %q option works like %s in that it substitutes a null-terminated @@ -2367,7 +1764,7 @@ SQLITE_API void sqlite3_free_table(char **result); ** character it escapes that character and allows it to be inserted into ** the string. ** -** For example, assume the string variable zText contains text as follows: +** For example, so some string variable contains text as follows: ** **
 **  char *zText = "It's a happy day!";
@@ -2395,13 +1792,14 @@ SQLITE_API void sqlite3_free_table(char **result);
 **  INSERT INTO table1 VALUES('It's a happy day!');
 ** 
** -** This second example is an SQL syntax error. As a general rule you should -** always use %q instead of %s when inserting text into a string literal. +** This second example is an SQL syntax error. As a general rule you +** should always use %q instead of %s when inserting text into a string +** literal. ** ** The %Q option works like %q except it also adds single quotes around -** the outside of the total string. Additionally, if the parameter in the -** argument list is a NULL pointer, %Q substitutes the text "NULL" (without -** single quotes) in place of the %Q option. So, for example, one could say: +** the outside of the total string. Or if the parameter in the argument +** list is a NULL pointer, %Q substitutes the text "NULL" (without single +** quotes) in place of the %Q option. {END} So, for example, one could say: ** **
 **  char *zSQL = sqlite3_mprintf("INSERT INTO table VALUES(%Q)", zText);
@@ -2418,32 +1816,33 @@ SQLITE_API void sqlite3_free_table(char **result);
 **
 ** INVARIANTS:
 **
-** {H17403}  The [sqlite3_mprintf()] and [sqlite3_vmprintf()] interfaces
+** {F17403}  The [sqlite3_mprintf()] and [sqlite3_vmprintf()] interfaces
 **           return either pointers to zero-terminated UTF-8 strings held in
 **           memory obtained from [sqlite3_malloc()] or NULL pointers if
 **           a call to [sqlite3_malloc()] fails.
 **
-** {H17406}  The [sqlite3_snprintf()] interface writes a zero-terminated
+** {F17406}  The [sqlite3_snprintf()] interface writes a zero-terminated
 **           UTF-8 string into the buffer pointed to by the second parameter
 **           provided that the first parameter is greater than zero.
 **
-** {H17407}  The [sqlite3_snprintf()] interface does not write slots of
+** {F17407}  The [sqlite3_snprintf()] interface does not writes slots of
 **           its output buffer (the second parameter) outside the range
 **           of 0 through N-1 (where N is the first parameter)
 **           regardless of the length of the string
 **           requested by the format specification.
+**   
 */
 SQLITE_API char *sqlite3_mprintf(const char*,...);
 SQLITE_API char *sqlite3_vmprintf(const char*, va_list);
 SQLITE_API char *sqlite3_snprintf(int,char*,const char*, ...);
 
 /*
-** CAPI3REF: Memory Allocation Subsystem {H17300} 
+** CAPI3REF: Memory Allocation Subsystem {F17300}
 **
 ** The SQLite core  uses these three routines for all of its own
 ** internal memory allocation needs. "Core" in the previous sentence
 ** does not include operating-system specific VFS implementation.  The
-** Windows VFS uses native malloc() and free() for some operations.
+** windows VFS uses native malloc and free for some operations.
 **
 ** The sqlite3_malloc() routine returns a pointer to a block
 ** of memory at least N bytes in length, where N is the parameter.
@@ -2472,7 +1871,7 @@ SQLITE_API char *sqlite3_snprintf(int,char*,const char*, ...);
 ** If the second parameter to sqlite3_realloc() is zero or
 ** negative then the behavior is exactly the same as calling
 ** sqlite3_free(P) where P is the first parameter to sqlite3_realloc().
-** sqlite3_realloc() returns a pointer to a memory allocation
+** Sqlite3_realloc() returns a pointer to a memory allocation
 ** of at least N bytes in size or NULL if sufficient memory is unavailable.
 ** If M is the size of the prior allocation, then min(N,M) bytes
 ** of the prior allocation are copied into the beginning of buffer returned
@@ -2483,123 +1882,128 @@ SQLITE_API char *sqlite3_snprintf(int,char*,const char*, ...);
 ** The memory returned by sqlite3_malloc() and sqlite3_realloc()
 ** is always aligned to at least an 8 byte boundary. {END}
 **
-** The default implementation of the memory allocation subsystem uses
-** the malloc(), realloc() and free() provided by the standard C library.
-** {H17382} However, if SQLite is compiled with the
-** SQLITE_MEMORY_SIZE=NNN C preprocessor macro (where NNN
-** is an integer), then SQLite create a static array of at least
-** NNN bytes in size and uses that array for all of its dynamic
-** memory allocation needs. {END}  Additional memory allocator options
-** may be added in future releases.
+** The default implementation
+** of the memory allocation subsystem uses the malloc(), realloc()
+** and free() provided by the standard C library. {F17382} However, if 
+** SQLite is compiled with the following C preprocessor macro
+**
+** 
SQLITE_MEMORY_SIZE=NNN
+** +** where NNN is an integer, then SQLite create a static +** array of at least NNN bytes in size and use that array +** for all of its dynamic memory allocation needs. {END} Additional +** memory allocator options may be added in future releases. ** ** In SQLite version 3.5.0 and 3.5.1, it was possible to define ** the SQLITE_OMIT_MEMORY_ALLOCATION which would cause the built-in ** implementation of these routines to be omitted. That capability -** is no longer provided. Only built-in memory allocators can be used. +** is no longer provided. Only built-in memory allocators can be +** used. ** -** The Windows OS interface layer calls +** The windows OS interface layer calls ** the system malloc() and free() directly when converting ** filenames between the UTF-8 encoding used by SQLite -** and whatever filename encoding is used by the particular Windows +** and whatever filename encoding is used by the particular windows ** installation. Memory allocation errors are detected, but ** they are reported back as [SQLITE_CANTOPEN] or ** [SQLITE_IOERR] rather than [SQLITE_NOMEM]. ** ** INVARIANTS: ** -** {H17303} The [sqlite3_malloc(N)] interface returns either a pointer to -** a newly checked-out block of at least N bytes of memory -** that is 8-byte aligned, or it returns NULL if it is unable -** to fulfill the request. +** {F17303} The [sqlite3_malloc(N)] interface returns either a pointer to +** newly checked-out block of at least N bytes of memory +** that is 8-byte aligned, +** or it returns NULL if it is unable to fulfill the request. ** -** {H17304} The [sqlite3_malloc(N)] interface returns a NULL pointer if +** {F17304} The [sqlite3_malloc(N)] interface returns a NULL pointer if ** N is less than or equal to zero. ** -** {H17305} The [sqlite3_free(P)] interface releases memory previously +** {F17305} The [sqlite3_free(P)] interface releases memory previously ** returned from [sqlite3_malloc()] or [sqlite3_realloc()], ** making it available for reuse. ** -** {H17306} A call to [sqlite3_free(NULL)] is a harmless no-op. +** {F17306} A call to [sqlite3_free(NULL)] is a harmless no-op. ** -** {H17310} A call to [sqlite3_realloc(0,N)] is equivalent to a call +** {F17310} A call to [sqlite3_realloc(0,N)] is equivalent to a call ** to [sqlite3_malloc(N)]. ** -** {H17312} A call to [sqlite3_realloc(P,0)] is equivalent to a call +** {F17312} A call to [sqlite3_realloc(P,0)] is equivalent to a call ** to [sqlite3_free(P)]. ** -** {H17315} The SQLite core uses [sqlite3_malloc()], [sqlite3_realloc()], +** {F17315} The SQLite core uses [sqlite3_malloc()], [sqlite3_realloc()], ** and [sqlite3_free()] for all of its memory allocation and ** deallocation needs. ** -** {H17318} The [sqlite3_realloc(P,N)] interface returns either a pointer +** {F17318} The [sqlite3_realloc(P,N)] interface returns either a pointer ** to a block of checked-out memory of at least N bytes in size ** that is 8-byte aligned, or a NULL pointer. ** -** {H17321} When [sqlite3_realloc(P,N)] returns a non-NULL pointer, it first -** copies the first K bytes of content from P into the newly -** allocated block, where K is the lesser of N and the size of -** the buffer P. +** {F17321} When [sqlite3_realloc(P,N)] returns a non-NULL pointer, it first +** copies the first K bytes of content from P into the newly allocated +** where K is the lessor of N and the size of the buffer P. ** -** {H17322} When [sqlite3_realloc(P,N)] returns a non-NULL pointer, it first +** {F17322} When [sqlite3_realloc(P,N)] returns a non-NULL pointer, it first ** releases the buffer P. ** -** {H17323} When [sqlite3_realloc(P,N)] returns NULL, the buffer P is +** {F17323} When [sqlite3_realloc(P,N)] returns NULL, the buffer P is ** not modified or released. ** -** ASSUMPTIONS: +** LIMITATIONS: ** -** {A17350} The pointer arguments to [sqlite3_free()] and [sqlite3_realloc()] -** must be either NULL or else pointers obtained from a prior -** invocation of [sqlite3_malloc()] or [sqlite3_realloc()] that have -** not yet been released. +** {U17350} The pointer arguments to [sqlite3_free()] and [sqlite3_realloc()] +** must be either NULL or else a pointer obtained from a prior +** invocation of [sqlite3_malloc()] or [sqlite3_realloc()] that has +** not been released. ** -** {A17351} The application must not read or write any part of +** {U17351} The application must not read or write any part of ** a block of memory after it has been released using ** [sqlite3_free()] or [sqlite3_realloc()]. +** */ SQLITE_API void *sqlite3_malloc(int); SQLITE_API void *sqlite3_realloc(void*, int); SQLITE_API void sqlite3_free(void*); /* -** CAPI3REF: Memory Allocator Statistics {H17370} +** CAPI3REF: Memory Allocator Statistics {F17370} ** ** SQLite provides these two interfaces for reporting on the status ** of the [sqlite3_malloc()], [sqlite3_free()], and [sqlite3_realloc()] -** routines, which form the built-in memory allocation subsystem. +** the memory allocation subsystem included within the SQLite. ** ** INVARIANTS: ** -** {H17371} The [sqlite3_memory_used()] routine returns the number of bytes -** of memory currently outstanding (malloced but not freed). +** {F17371} The [sqlite3_memory_used()] routine returns the +** number of bytes of memory currently outstanding +** (malloced but not freed). ** -** {H17373} The [sqlite3_memory_highwater()] routine returns the maximum -** value of [sqlite3_memory_used()] since the high-water mark -** was last reset. +** {F17373} The [sqlite3_memory_highwater()] routine returns the maximum +** value of [sqlite3_memory_used()] +** since the highwater mark was last reset. ** -** {H17374} The values returned by [sqlite3_memory_used()] and +** {F17374} The values returned by [sqlite3_memory_used()] and ** [sqlite3_memory_highwater()] include any overhead ** added by SQLite in its implementation of [sqlite3_malloc()], ** but not overhead added by the any underlying system library ** routines that [sqlite3_malloc()] may call. -** -** {H17375} The memory high-water mark is reset to the current value of +** +** {F17375} The memory highwater mark is reset to the current value of ** [sqlite3_memory_used()] if and only if the parameter to ** [sqlite3_memory_highwater()] is true. The value returned -** by [sqlite3_memory_highwater(1)] is the high-water mark +** by [sqlite3_memory_highwater(1)] is the highwater mark ** prior to the reset. */ SQLITE_API sqlite3_int64 sqlite3_memory_used(void); SQLITE_API sqlite3_int64 sqlite3_memory_highwater(int resetFlag); /* -** CAPI3REF: Pseudo-Random Number Generator {H17390} +** CAPI3REF: Pseudo-Random Number Generator {F17390} ** ** SQLite contains a high-quality pseudo-random number generator (PRNG) used to ** select random ROWIDs when inserting new records into a table that ** already uses the largest possible ROWID. The PRNG is also used for ** the build-in random() and randomblob() SQL functions. This interface allows -** applications to access the same PRNG for other purposes. +** appliations to access the same PRNG for other purposes. ** ** A call to this routine stores N bytes of randomness into buffer P. ** @@ -2612,13 +2016,13 @@ SQLITE_API sqlite3_int64 sqlite3_memory_highwater(int resetFlag); ** ** INVARIANTS: ** -** {H17392} The [sqlite3_randomness(N,P)] interface writes N bytes of +** {F17392} The [sqlite3_randomness(N,P)] interface writes N bytes of ** high-quality pseudo-randomness into buffer P. */ SQLITE_API void sqlite3_randomness(int N, void *P); /* -** CAPI3REF: Compile-Time Authorization Callbacks {H12500} +** CAPI3REF: Compile-Time Authorization Callbacks {F12500} ** ** This routine registers a authorizer callback with a particular ** [database connection], supplied in the first argument. @@ -2631,9 +2035,9 @@ SQLITE_API void sqlite3_randomness(int N, void *P); ** return [SQLITE_OK] to allow the action, [SQLITE_IGNORE] to disallow the ** specific action but allow the SQL statement to continue to be ** compiled, or [SQLITE_DENY] to cause the entire SQL statement to be -** rejected with an error. If the authorizer callback returns +** rejected with an error. If the authorizer callback returns ** any value other than [SQLITE_IGNORE], [SQLITE_OK], or [SQLITE_DENY] -** then the [sqlite3_prepare_v2()] or equivalent call that triggered +** then [sqlite3_prepare_v2()] or equivalent call that triggered ** the authorizer will fail with an error message. ** ** When the callback returns [SQLITE_OK], that means the operation @@ -2648,17 +2052,19 @@ SQLITE_API void sqlite3_randomness(int N, void *P); ** return can be used to deny an untrusted user access to individual ** columns of a table. ** -** The first parameter to the authorizer callback is a copy of the third -** parameter to the sqlite3_set_authorizer() interface. The second parameter -** to the callback is an integer [SQLITE_COPY | action code] that specifies -** the particular action to be authorized. The third through sixth parameters -** to the callback are zero-terminated strings that contain additional -** details about the action to be authorized. +** The first parameter to the authorizer callback is a copy of +** the third parameter to the sqlite3_set_authorizer() interface. +** The second parameter to the callback is an integer +** [SQLITE_COPY | action code] that specifies the particular action +** to be authorized. The third through sixth +** parameters to the callback are zero-terminated strings that contain +** additional details about the action to be authorized. ** ** An authorizer is used when [sqlite3_prepare | preparing] -** SQL statements from an untrusted source, to ensure that the SQL statements -** do not try to access data they are not allowed to see, or that they do not -** try to execute malicious statements that damage the database. For +** SQL statements from an untrusted +** source, to ensure that the SQL statements do not try to access data +** that they are not allowed to see, or that they do not try to +** execute malicious statements that damage the database. For ** example, an application may allow a user to enter arbitrary ** SQL queries for evaluation by a database. But the application does ** not want the user to be able to make arbitrary changes to the @@ -2676,71 +2082,61 @@ SQLITE_API void sqlite3_randomness(int N, void *P); ** previous call. Disable the authorizer by installing a NULL callback. ** The authorizer is disabled by default. ** -** The authorizer callback must not do anything that will modify -** the database connection that invoked the authorizer callback. -** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their -** database connections for the meaning of "modify" in this paragraph. -** -** When [sqlite3_prepare_v2()] is used to prepare a statement, the -** statement might be reprepared during [sqlite3_step()] due to a -** schema change. Hence, the application should ensure that the -** correct authorizer callback remains in place during the [sqlite3_step()]. -** -** Note that the authorizer callback is invoked only during +** Note that the authorizer callback is invoked only during ** [sqlite3_prepare()] or its variants. Authorization is not ** performed during statement evaluation in [sqlite3_step()]. ** ** INVARIANTS: ** -** {H12501} The [sqlite3_set_authorizer(D,...)] interface registers a +** {F12501} The [sqlite3_set_authorizer(D,...)] interface registers a ** authorizer callback with database connection D. ** -** {H12502} The authorizer callback is invoked as SQL statements are -** being parseed and compiled. +** {F12502} The authorizer callback is invoked as SQL statements are +** being compiled ** -** {H12503} If the authorizer callback returns any value other than -** [SQLITE_IGNORE], [SQLITE_OK], or [SQLITE_DENY], then -** the application interface call that caused +** {F12503} If the authorizer callback returns any value other than +** [SQLITE_IGNORE], [SQLITE_OK], or [SQLITE_DENY] then +** the [sqlite3_prepare_v2()] or equivalent call that caused ** the authorizer callback to run shall fail with an ** [SQLITE_ERROR] error code and an appropriate error message. ** -** {H12504} When the authorizer callback returns [SQLITE_OK], the operation -** described is processed normally. +** {F12504} When the authorizer callback returns [SQLITE_OK], the operation +** described is coded normally. ** -** {H12505} When the authorizer callback returns [SQLITE_DENY], the -** application interface call that caused the +** {F12505} When the authorizer callback returns [SQLITE_DENY], the +** [sqlite3_prepare_v2()] or equivalent call that caused the ** authorizer callback to run shall fail ** with an [SQLITE_ERROR] error code and an error message ** explaining that access is denied. ** -** {H12506} If the authorizer code (the 2nd parameter to the authorizer +** {F12506} If the authorizer code (the 2nd parameter to the authorizer ** callback) is [SQLITE_READ] and the authorizer callback returns -** [SQLITE_IGNORE], then the prepared statement is constructed to +** [SQLITE_IGNORE] then the prepared statement is constructed to ** insert a NULL value in place of the table column that would have ** been read if [SQLITE_OK] had been returned. ** -** {H12507} If the authorizer code (the 2nd parameter to the authorizer +** {F12507} If the authorizer code (the 2nd parameter to the authorizer ** callback) is anything other than [SQLITE_READ], then -** a return of [SQLITE_IGNORE] has the same effect as [SQLITE_DENY]. +** a return of [SQLITE_IGNORE] has the same effect as [SQLITE_DENY]. ** -** {H12510} The first parameter to the authorizer callback is a copy of +** {F12510} The first parameter to the authorizer callback is a copy of ** the third parameter to the [sqlite3_set_authorizer()] interface. ** -** {H12511} The second parameter to the callback is an integer +** {F12511} The second parameter to the callback is an integer ** [SQLITE_COPY | action code] that specifies the particular action ** to be authorized. ** -** {H12512} The third through sixth parameters to the callback are -** zero-terminated strings that contain +** {F12512} The third through sixth parameters to the callback are +** zero-terminated strings that contain ** additional details about the action to be authorized. ** -** {H12520} Each call to [sqlite3_set_authorizer()] overrides +** {F12520} Each call to [sqlite3_set_authorizer()] overrides the ** any previously installed authorizer. ** -** {H12521} A NULL authorizer means that no authorization +** {F12521} A NULL authorizer means that no authorization ** callback is invoked. ** -** {H12522} The default authorizer is NULL. +** {F12522} The default authorizer is NULL. */ SQLITE_API int sqlite3_set_authorizer( sqlite3*, @@ -2749,7 +2145,7 @@ SQLITE_API int sqlite3_set_authorizer( ); /* -** CAPI3REF: Authorizer Return Codes {H12590} +** CAPI3REF: Authorizer Return Codes {F12590} ** ** The [sqlite3_set_authorizer | authorizer callback function] must ** return either [SQLITE_OK] or one of these two constants in order @@ -2761,44 +2157,44 @@ SQLITE_API int sqlite3_set_authorizer( #define SQLITE_IGNORE 2 /* Don't allow access, but don't generate an error */ /* -** CAPI3REF: Authorizer Action Codes {H12550} +** CAPI3REF: Authorizer Action Codes {F12550} ** ** The [sqlite3_set_authorizer()] interface registers a callback function -** that is invoked to authorize certain SQL statement actions. The +** that is invoked to authorizer certain SQL statement actions. The ** second parameter to the callback is an integer code that specifies ** what action is being authorized. These are the integer action codes that ** the authorizer callback may be passed. ** -** These action code values signify what kind of operation is to be +** These action code values signify what kind of operation is to be ** authorized. The 3rd and 4th parameters to the authorization ** callback function will be parameters or NULL depending on which of these ** codes is used as the second parameter. The 5th parameter to the -** authorizer callback is the name of the database ("main", "temp", +** authorizer callback is the name of the database ("main", "temp", ** etc.) if applicable. The 6th parameter to the authorizer callback ** is the name of the inner-most trigger or view that is responsible for -** the access attempt or NULL if this access attempt is directly from +** the access attempt or NULL if this access attempt is directly from ** top-level SQL code. ** ** INVARIANTS: ** -** {H12551} The second parameter to an -** [sqlite3_set_authorizer | authorizer callback] shall be an integer +** {F12551} The second parameter to an +** [sqlite3_set_authorizer | authorizer callback is always an integer ** [SQLITE_COPY | authorizer code] that specifies what action ** is being authorized. ** -** {H12552} The 3rd and 4th parameters to the -** [sqlite3_set_authorizer | authorization callback] -** shall be parameters or NULL depending on which +** {F12552} The 3rd and 4th parameters to the +** [sqlite3_set_authorizer | authorization callback function] +** will be parameters or NULL depending on which ** [SQLITE_COPY | authorizer code] is used as the second parameter. ** -** {H12553} The 5th parameter to the -** [sqlite3_set_authorizer | authorizer callback] shall be the name +** {F12553} The 5th parameter to the +** [sqlite3_set_authorizer | authorizer callback] is the name ** of the database (example: "main", "temp", etc.) if applicable. ** -** {H12554} The 6th parameter to the -** [sqlite3_set_authorizer | authorizer callback] shall be the name +** {F12554} The 6th parameter to the +** [sqlite3_set_authorizer | authorizer callback] is the name ** of the inner-most trigger or view that is responsible for -** the access attempt or NULL if this access attempt is directly from +** the access attempt or NULL if this access attempt is directly from ** top-level SQL code. */ /******************************************* 3rd ************ 4th ***********/ @@ -2836,8 +2232,7 @@ SQLITE_API int sqlite3_set_authorizer( #define SQLITE_COPY 0 /* No longer used */ /* -** CAPI3REF: Tracing And Profiling Functions {H12280} -** EXPERIMENTAL +** CAPI3REF: Tracing And Profiling Functions {F12280} ** ** These routines register callback functions that can be used for ** tracing and profiling the execution of SQL statements. @@ -2846,252 +2241,245 @@ SQLITE_API int sqlite3_set_authorizer( ** various times when an SQL statement is being run by [sqlite3_step()]. ** The callback returns a UTF-8 rendering of the SQL statement text ** as the statement first begins executing. Additional callbacks occur -** as each triggered subprogram is entered. The callbacks for triggers +** as each triggersubprogram is entered. The callbacks for triggers ** contain a UTF-8 SQL comment that identifies the trigger. -** +** ** The callback function registered by sqlite3_profile() is invoked ** as each SQL statement finishes. The profile callback contains ** the original statement text and an estimate of wall-clock time ** of how long that statement took to run. ** +** The sqlite3_profile() API is currently considered experimental and +** is subject to change or removal in a future release. +** +** The trigger reporting feature of the trace callback is considered +** experimental and is subject to change or removal in future releases. +** Future versions of SQLite might also add new trace callback +** invocations. +** ** INVARIANTS: ** -** {H12281} The callback function registered by [sqlite3_trace()] -** shall be invoked +** {F12281} The callback function registered by [sqlite3_trace()] is ** whenever an SQL statement first begins to execute and ** whenever a trigger subprogram first begins to run. ** -** {H12282} Each call to [sqlite3_trace()] shall override the previously +** {F12282} Each call to [sqlite3_trace()] overrides the previously ** registered trace callback. ** -** {H12283} A NULL trace callback shall disable tracing. +** {F12283} A NULL trace callback disables tracing. ** -** {H12284} The first argument to the trace callback shall be a copy of +** {F12284} The first argument to the trace callback is a copy of ** the pointer which was the 3rd argument to [sqlite3_trace()]. ** -** {H12285} The second argument to the trace callback is a -** zero-terminated UTF-8 string containing the original text +** {F12285} The second argument to the trace callback is a +** zero-terminated UTF8 string containing the original text ** of the SQL statement as it was passed into [sqlite3_prepare_v2()] ** or the equivalent, or an SQL comment indicating the beginning ** of a trigger subprogram. ** -** {H12287} The callback function registered by [sqlite3_profile()] is invoked +** {F12287} The callback function registered by [sqlite3_profile()] is invoked ** as each SQL statement finishes. ** -** {H12288} The first parameter to the profile callback is a copy of +** {F12288} The first parameter to the profile callback is a copy of ** the 3rd parameter to [sqlite3_profile()]. ** -** {H12289} The second parameter to the profile callback is a +** {F12289} The second parameter to the profile callback is a ** zero-terminated UTF-8 string that contains the complete text of ** the SQL statement as it was processed by [sqlite3_prepare_v2()] ** or the equivalent. ** -** {H12290} The third parameter to the profile callback is an estimate +** {F12290} The third parameter to the profile callback is an estimate ** of the number of nanoseconds of wall-clock time required to ** run the SQL statement from start to finish. */ -SQLITE_API SQLITE_EXPERIMENTAL void *sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*); -SQLITE_API SQLITE_EXPERIMENTAL void *sqlite3_profile(sqlite3*, +SQLITE_API void *sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*); +SQLITE_API void *sqlite3_profile(sqlite3*, void(*xProfile)(void*,const char*,sqlite3_uint64), void*); /* -** CAPI3REF: Query Progress Callbacks {H12910} +** CAPI3REF: Query Progress Callbacks {F12910} ** ** This routine configures a callback function - the ** progress callback - that is invoked periodically during long ** running calls to [sqlite3_exec()], [sqlite3_step()] and -** [sqlite3_get_table()]. An example use for this +** [sqlite3_get_table()]. An example use for this ** interface is to keep a GUI updated during a large query. ** -** If the progress callback returns non-zero, the operation is +** If the progress callback returns non-zero, the opertion is ** interrupted. This feature can be used to implement a -** "Cancel" button on a GUI progress dialog box. -** -** The progress handler must not do anything that will modify -** the database connection that invoked the progress handler. -** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their -** database connections for the meaning of "modify" in this paragraph. +** "Cancel" button on a GUI dialog box. ** ** INVARIANTS: ** -** {H12911} The callback function registered by sqlite3_progress_handler() +** {F12911} The callback function registered by [sqlite3_progress_handler()] ** is invoked periodically during long running calls to ** [sqlite3_step()]. ** -** {H12912} The progress callback is invoked once for every N virtual -** machine opcodes, where N is the second argument to +** {F12912} The progress callback is invoked once for every N virtual +** machine opcodes, where N is the second argument to ** the [sqlite3_progress_handler()] call that registered -** the callback. If N is less than 1, sqlite3_progress_handler() -** acts as if a NULL progress handler had been specified. +** the callback. What if N is less than 1? ** -** {H12913} The progress callback itself is identified by the third -** argument to sqlite3_progress_handler(). +** {F12913} The progress callback itself is identified by the third +** argument to [sqlite3_progress_handler()]. ** -** {H12914} The fourth argument to sqlite3_progress_handler() is a -** void pointer passed to the progress callback +** {F12914} The fourth argument [sqlite3_progress_handler()] is a +*** void pointer passed to the progress callback ** function each time it is invoked. ** -** {H12915} If a call to [sqlite3_step()] results in fewer than N opcodes -** being executed, then the progress callback is never invoked. +** {F12915} If a call to [sqlite3_step()] results in fewer than +** N opcodes being executed, +** then the progress callback is never invoked. {END} +** +** {F12916} Every call to [sqlite3_progress_handler()] +** overwrites any previously registere progress handler. ** -** {H12916} Every call to [sqlite3_progress_handler()] -** overwrites any previously registered progress handler. -** -** {H12917} If the progress handler callback is NULL then no progress +** {F12917} If the progress handler callback is NULL then no progress ** handler is invoked. ** -** {H12918} If the progress callback returns a result other than 0, then +** {F12918} If the progress callback returns a result other than 0, then ** the behavior is a if [sqlite3_interrupt()] had been called. -** */ SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*); /* -** CAPI3REF: Opening A New Database Connection {H12700} +** CAPI3REF: Opening A New Database Connection {F12700} ** -** These routines open an SQLite database file whose name is given by the -** filename argument. The filename argument is interpreted as UTF-8 for -** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte -** order for sqlite3_open16(). A [database connection] handle is usually -** returned in *ppDb, even if an error occurs. The only exception is that -** if SQLite is unable to allocate memory to hold the [sqlite3] object, -** a NULL will be written into *ppDb instead of a pointer to the [sqlite3] -** object. If the database is opened (and/or created) successfully, then -** [SQLITE_OK] is returned. Otherwise an [error code] is returned. The -** [sqlite3_errmsg()] or [sqlite3_errmsg16()] routines can be used to obtain +** These routines open an SQLite database file whose name +** is given by the filename argument. +** The filename argument is interpreted as UTF-8 +** for [sqlite3_open()] and [sqlite3_open_v2()] and as UTF-16 +** in the native byte order for [sqlite3_open16()]. +** An [sqlite3*] handle is usually returned in *ppDb, even +** if an error occurs. The only exception is if SQLite is unable +** to allocate memory to hold the [sqlite3] object, a NULL will +** be written into *ppDb instead of a pointer to the [sqlite3] object. +** If the database is opened (and/or created) +** successfully, then [SQLITE_OK] is returned. Otherwise an +** error code is returned. The +** [sqlite3_errmsg()] or [sqlite3_errmsg16()] routines can be used to obtain ** an English language description of the error. ** ** The default encoding for the database will be UTF-8 if -** sqlite3_open() or sqlite3_open_v2() is called and -** UTF-16 in the native byte order if sqlite3_open16() is used. +** [sqlite3_open()] or [sqlite3_open_v2()] is called and +** UTF-16 in the native byte order if [sqlite3_open16()] is used. ** ** Whether or not an error occurs when it is opened, resources -** associated with the [database connection] handle should be released by -** passing it to [sqlite3_close()] when it is no longer required. +** associated with the [sqlite3*] handle should be released by passing it +** to [sqlite3_close()] when it is no longer required. ** -** The sqlite3_open_v2() interface works like sqlite3_open() -** except that it accepts two additional parameters for additional control -** over the new database connection. The flags parameter can take one of -** the following three values, optionally combined with the -** [SQLITE_OPEN_NOMUTEX] or [SQLITE_OPEN_FULLMUTEX] flags: +** The [sqlite3_open_v2()] interface works like [sqlite3_open()] +** except that it acccepts two additional parameters for additional control +** over the new database connection. The flags parameter can be +** one of: ** -**
-**
[SQLITE_OPEN_READONLY]
-**
The database is opened in read-only mode. If the database does not -** already exist, an error is returned.
+**
    +**
  1. [SQLITE_OPEN_READONLY] +**
  2. [SQLITE_OPEN_READWRITE] +**
  3. [SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE] +**
** -**
[SQLITE_OPEN_READWRITE]
-**
The database is opened for reading and writing if possible, or reading -** only if the file is write protected by the operating system. In either -** case the database must already exist, otherwise an error is returned.
+** The first value opens the database read-only. +** If the database does not previously exist, an error is returned. +** The second option opens +** the database for reading and writing if possible, or reading only if +** if the file is write protected. In either case the database +** must already exist or an error is returned. The third option +** opens the database for reading and writing and creates it if it does +** not already exist. +** The third options is behavior that is always used for [sqlite3_open()] +** and [sqlite3_open16()]. ** -**
[SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]
-**
The database is opened for reading and writing, and is creates it if -** it does not already exist. This is the behavior that is always used for -** sqlite3_open() and sqlite3_open16().
-**
+** If the 3rd parameter to [sqlite3_open_v2()] is not one of the +** combinations shown above then the behavior is undefined. ** -** If the 3rd parameter to sqlite3_open_v2() is not one of the -** combinations shown above or one of the combinations shown above combined -** with the [SQLITE_OPEN_NOMUTEX] or [SQLITE_OPEN_FULLMUTEX] flags, -** then the behavior is undefined. +** If the filename is ":memory:", then an private +** in-memory database is created for the connection. This in-memory +** database will vanish when the database connection is closed. Future +** version of SQLite might make use of additional special filenames +** that begin with the ":" character. It is recommended that +** when a database filename really does begin with +** ":" that you prefix the filename with a pathname like "./" to +** avoid ambiguity. ** -** If the [SQLITE_OPEN_NOMUTEX] flag is set, then the database connection -** opens in the multi-thread [threading mode] as long as the single-thread -** mode has not been set at compile-time or start-time. If the -** [SQLITE_OPEN_FULLMUTEX] flag is set then the database connection opens -** in the serialized [threading mode] unless single-thread was -** previously selected at compile-time or start-time. -** -** If the filename is ":memory:", then a private, temporary in-memory database -** is created for the connection. This in-memory database will vanish when -** the database connection is closed. Future versions of SQLite might -** make use of additional special filenames that begin with the ":" character. -** It is recommended that when a database filename actually does begin with -** a ":" character you should prefix the filename with a pathname such as -** "./" to avoid ambiguity. -** -** If the filename is an empty string, then a private, temporary +** If the filename is an empty string, then a private temporary ** on-disk database will be created. This private database will be ** automatically deleted as soon as the database connection is closed. ** ** The fourth parameter to sqlite3_open_v2() is the name of the -** [sqlite3_vfs] object that defines the operating system interface that -** the new database connection should use. If the fourth parameter is -** a NULL pointer then the default [sqlite3_vfs] object is used. +** [sqlite3_vfs] object that defines the operating system +** interface that the new database connection should use. If the +** fourth parameter is a NULL pointer then the default [sqlite3_vfs] +** object is used. ** -** Note to Windows users: The encoding used for the filename argument -** of sqlite3_open() and sqlite3_open_v2() must be UTF-8, not whatever +** Note to windows users: The encoding used for the filename argument +** of [sqlite3_open()] and [sqlite3_open_v2()] must be UTF-8, not whatever ** codepage is currently defined. Filenames containing international ** characters must be converted to UTF-8 prior to passing them into -** sqlite3_open() or sqlite3_open_v2(). +** [sqlite3_open()] or [sqlite3_open_v2()]. ** ** INVARIANTS: ** -** {H12701} The [sqlite3_open()], [sqlite3_open16()], and +** {F12701} The [sqlite3_open()], [sqlite3_open16()], and ** [sqlite3_open_v2()] interfaces create a new ** [database connection] associated with ** the database file given in their first parameter. ** -** {H12702} The filename argument is interpreted as UTF-8 +** {F12702} The filename argument is interpreted as UTF-8 ** for [sqlite3_open()] and [sqlite3_open_v2()] and as UTF-16 ** in the native byte order for [sqlite3_open16()]. ** -** {H12703} A successful invocation of [sqlite3_open()], [sqlite3_open16()], +** {F12703} A successful invocation of [sqlite3_open()], [sqlite3_open16()], ** or [sqlite3_open_v2()] writes a pointer to a new ** [database connection] into *ppDb. ** -** {H12704} The [sqlite3_open()], [sqlite3_open16()], and +** {F12704} The [sqlite3_open()], [sqlite3_open16()], and ** [sqlite3_open_v2()] interfaces return [SQLITE_OK] upon success, ** or an appropriate [error code] on failure. ** -** {H12706} The default text encoding for a new database created using +** {F12706} The default text encoding for a new database created using ** [sqlite3_open()] or [sqlite3_open_v2()] will be UTF-8. ** -** {H12707} The default text encoding for a new database created using +** {F12707} The default text encoding for a new database created using ** [sqlite3_open16()] will be UTF-16. ** -** {H12709} The [sqlite3_open(F,D)] interface is equivalent to +** {F12709} The [sqlite3_open(F,D)] interface is equivalent to ** [sqlite3_open_v2(F,D,G,0)] where the G parameter is ** [SQLITE_OPEN_READWRITE]|[SQLITE_OPEN_CREATE]. ** -** {H12711} If the G parameter to [sqlite3_open_v2(F,D,G,V)] contains the +** {F12711} If the G parameter to [sqlite3_open_v2(F,D,G,V)] contains the ** bit value [SQLITE_OPEN_READONLY] then the database is opened ** for reading only. ** -** {H12712} If the G parameter to [sqlite3_open_v2(F,D,G,V)] contains the +** {F12712} If the G parameter to [sqlite3_open_v2(F,D,G,V)] contains the ** bit value [SQLITE_OPEN_READWRITE] then the database is opened ** reading and writing if possible, or for reading only if the ** file is write protected by the operating system. ** -** {H12713} If the G parameter to [sqlite3_open_v2(F,D,G,V)] omits the +** {F12713} If the G parameter to [sqlite3_open(v2(F,D,G,V)] omits the ** bit value [SQLITE_OPEN_CREATE] and the database does not ** previously exist, an error is returned. ** -** {H12714} If the G parameter to [sqlite3_open_v2(F,D,G,V)] contains the +** {F12714} If the G parameter to [sqlite3_open(v2(F,D,G,V)] contains the ** bit value [SQLITE_OPEN_CREATE] and the database does not ** previously exist, then an attempt is made to create and ** initialize the database. ** -** {H12717} If the filename argument to [sqlite3_open()], [sqlite3_open16()], +** {F12717} If the filename argument to [sqlite3_open()], [sqlite3_open16()], ** or [sqlite3_open_v2()] is ":memory:", then an private, ** ephemeral, in-memory database is created for the connection. ** Is SQLITE_OPEN_CREATE|SQLITE_OPEN_READWRITE required ** in sqlite3_open_v2()? ** -** {H12719} If the filename is NULL or an empty string, then a private, -** ephemeral on-disk database will be created. +** {F12719} If the filename is NULL or an empty string, then a private, +** ephermeral on-disk database will be created. ** Is SQLITE_OPEN_CREATE|SQLITE_OPEN_READWRITE required ** in sqlite3_open_v2()? ** -** {H12721} The [database connection] created by [sqlite3_open_v2(F,D,G,V)] -** will use the [sqlite3_vfs] object identified by the V parameter, -** or the default [sqlite3_vfs] object if V is a NULL pointer. -** -** {H12723} Two [database connections] will share a common cache if both were -** opened with the same VFS while [shared cache mode] was enabled and -** if both filenames compare equal using memcmp() after having been -** processed by the [sqlite3_vfs | xFullPathname] method of the VFS. +** {F12721} The [database connection] created by +** [sqlite3_open_v2(F,D,G,V)] will use the +** [sqlite3_vfs] object identified by the V parameter, or +** the default [sqlite3_vfs] object is V is a NULL pointer. */ SQLITE_API int sqlite3_open( const char *filename, /* Database filename (UTF-8) */ @@ -3109,45 +2497,44 @@ SQLITE_API int sqlite3_open_v2( ); /* -** CAPI3REF: Error Codes And Messages {H12800} +** CAPI3REF: Error Codes And Messages {F12800} ** -** The sqlite3_errcode() interface returns the numeric [result code] or -** [extended result code] for the most recent failed sqlite3_* API call -** associated with a [database connection]. If a prior API call failed -** but the most recent API call succeeded, the return value from -** sqlite3_errcode() is undefined. +** The sqlite3_errcode() interface returns the numeric +** [SQLITE_OK | result code] or [SQLITE_IOERR_READ | extended result code] +** for the most recent failed sqlite3_* API call associated +** with [sqlite3] handle 'db'. If a prior API call failed but the +** most recent API call succeeded, the return value from sqlite3_errcode() +** is undefined. ** ** The sqlite3_errmsg() and sqlite3_errmsg16() return English-language -** text that describes the error, as either UTF-8 or UTF-16 respectively. +** text that describes the error, as either UTF8 or UTF16 respectively. ** Memory to hold the error message string is managed internally. -** The application does not need to worry about freeing the result. +** The application does not need to worry with freeing the result. ** However, the error string might be overwritten or deallocated by ** subsequent calls to other SQLite interface functions. ** -** If an interface fails with SQLITE_MISUSE, that means the interface -** was invoked incorrectly by the application. In that case, the -** error code and message may or may not be set. -** ** INVARIANTS: ** -** {H12801} The [sqlite3_errcode(D)] interface returns the numeric -** [result code] or [extended result code] for the most recently -** failed interface call associated with the [database connection] D. +** {F12801} The [sqlite3_errcode(D)] interface returns the numeric +** [SQLITE_OK | result code] or +** [SQLITE_IOERR_READ | extended result code] +** for the most recently failed interface call associated +** with [database connection] D. ** -** {H12803} The [sqlite3_errmsg(D)] and [sqlite3_errmsg16(D)] +** {F12803} The [sqlite3_errmsg(D)] and [sqlite3_errmsg16(D)] ** interfaces return English-language text that describes ** the error in the mostly recently failed interface call, -** encoded as either UTF-8 or UTF-16 respectively. +** encoded as either UTF8 or UTF16 respectively. ** -** {H12807} The strings returned by [sqlite3_errmsg()] and [sqlite3_errmsg16()] +** {F12807} The strings returned by [sqlite3_errmsg()] and [sqlite3_errmsg16()] ** are valid until the next SQLite interface call. ** -** {H12808} Calls to API routines that do not return an error code +** {F12808} Calls to API routines that do not return an error code ** (example: [sqlite3_data_count()]) do not ** change the error code or message returned by ** [sqlite3_errcode()], [sqlite3_errmsg()], or [sqlite3_errmsg16()]. ** -** {H12809} Interfaces that are not associated with a specific +** {F12809} Interfaces that are not associated with a specific ** [database connection] (examples: ** [sqlite3_mprintf()] or [sqlite3_enable_shared_cache()] ** do not change the values returned by @@ -3158,20 +2545,20 @@ SQLITE_API const char *sqlite3_errmsg(sqlite3*); SQLITE_API const void *sqlite3_errmsg16(sqlite3*); /* -** CAPI3REF: SQL Statement Object {H13000} +** CAPI3REF: SQL Statement Object {F13000} ** KEYWORDS: {prepared statement} {prepared statements} ** -** An instance of this object represents a single SQL statement. -** This object is variously known as a "prepared statement" or a +** An instance of this object represent single SQL statements. This +** object is variously known as a "prepared statement" or a ** "compiled SQL statement" or simply as a "statement". -** +** ** The life of a statement object goes something like this: ** **
    **
  1. Create the object using [sqlite3_prepare_v2()] or a related ** function. -**
  2. Bind values to [host parameters] using the sqlite3_bind_*() -** interfaces. +**
  3. Bind values to host parameters using +** [sqlite3_bind_blob | sqlite3_bind_* interfaces]. **
  4. Run the SQL by calling [sqlite3_step()] one or more times. **
  5. Reset the statement using [sqlite3_reset()] then go back ** to step 2. Do this zero or more times. @@ -3184,7 +2571,7 @@ SQLITE_API const void *sqlite3_errmsg16(sqlite3*); typedef struct sqlite3_stmt sqlite3_stmt; /* -** CAPI3REF: Run-time Limits {H12760} +** CAPI3REF: Run-time Limits {F12760} ** ** This interface allows the size of various constructs to be limited ** on a connection by connection basis. The first parameter is the @@ -3195,7 +2582,7 @@ typedef struct sqlite3_stmt sqlite3_stmt; ** ** If the new limit is a negative number, the limit is unchanged. ** For the limit category of SQLITE_LIMIT_XYZ there is a hard upper -** bound set by a compile-time C preprocessor macro named SQLITE_MAX_XYZ. +** bound set by a compile-time C-preprocess macro named SQLITE_MAX_XYZ. ** (The "_LIMIT_" in the name is changed to "_MAX_".) ** Attempts to increase a limit above its hard upper bound are ** silently truncated to the hard upper limit. @@ -3204,44 +2591,47 @@ typedef struct sqlite3_stmt sqlite3_stmt; ** both their own internal database and also databases that are controlled ** by untrusted external sources. An example application might be a ** webbrowser that has its own databases for storing history and -** separate databases controlled by JavaScript applications downloaded -** off the Internet. The internal databases can be given the +** separate databases controlled by javascript applications downloaded +** off the internet. The internal databases can be given the ** large, default limits. Databases managed by external sources can ** be given much smaller limits designed to prevent a denial of service -** attack. Developers might also want to use the [sqlite3_set_authorizer()] +** attach. Developers might also want to use the [sqlite3_set_authorizer()] ** interface to further control untrusted SQL. The size of the database ** created by an untrusted script can be contained using the ** [max_page_count] [PRAGMA]. ** -** New run-time limit categories may be added in future releases. +** This interface is currently considered experimental and is subject +** to change or removal without prior notice. ** ** INVARIANTS: ** -** {H12762} A successful call to [sqlite3_limit(D,C,V)] where V is -** positive changes the limit on the size of construct C in the -** [database connection] D to the lesser of V and the hard upper -** bound on the size of C that is set at compile-time. +** {F12762} A successful call to [sqlite3_limit(D,C,V)] where V is +** positive changes the +** limit on the size of construct C in [database connection] D +** to the lessor of V and the hard upper bound on the size +** of C that is set at compile-time. ** -** {H12766} A successful call to [sqlite3_limit(D,C,V)] where V is negative -** leaves the state of the [database connection] D unchanged. +** {F12766} A successful call to [sqlite3_limit(D,C,V)] where V is negative +** leaves the state of [database connection] D unchanged. ** -** {H12769} A successful call to [sqlite3_limit(D,C,V)] returns the -** value of the limit on the size of construct C in the -** [database connection] D as it was prior to the call. +** {F12769} A successful call to [sqlite3_limit(D,C,V)] returns the +** value of the limit on the size of construct C in +** in [database connection] D as it was prior to the call. */ SQLITE_API int sqlite3_limit(sqlite3*, int id, int newVal); /* -** CAPI3REF: Run-Time Limit Categories {H12790} +** CAPI3REF: Run-Time Limit Categories {F12790} ** KEYWORDS: {limit category} {limit categories} -** +** ** These constants define various aspects of a [database connection] ** that can be limited in size by calls to [sqlite3_limit()]. ** The meanings of the various limits are as follows: ** **
    **
    SQLITE_LIMIT_LENGTH
    -**
    The maximum size of any string or BLOB or table row.
    +**
    The maximum size of any +** string or blob or table row.
    ** **
    SQLITE_LIMIT_SQL_LENGTH
    **
    The maximum length of an SQL statement.
    @@ -3288,50 +2678,52 @@ SQLITE_API int sqlite3_limit(sqlite3*, int id, int newVal); #define SQLITE_LIMIT_VARIABLE_NUMBER 9 /* -** CAPI3REF: Compiling An SQL Statement {H13010} -** KEYWORDS: {SQL statement compiler} +** CAPI3REF: Compiling An SQL Statement {F13010} ** ** To execute an SQL query, it must first be compiled into a byte-code -** program using one of these routines. +** program using one of these routines. ** -** The first argument, "db", is a [database connection] obtained from a -** prior call to [sqlite3_open()], [sqlite3_open_v2()] or [sqlite3_open16()]. -** -** The second argument, "zSql", is the statement to be compiled, encoded +** The first argument "db" is an [database connection] +** obtained from a prior call to [sqlite3_open()], [sqlite3_open_v2()] +** or [sqlite3_open16()]. +** The second argument "zSql" is the statement to be compiled, encoded ** as either UTF-8 or UTF-16. The sqlite3_prepare() and sqlite3_prepare_v2() -** interfaces use UTF-8, and sqlite3_prepare16() and sqlite3_prepare16_v2() -** use UTF-16. +** interfaces uses UTF-8 and sqlite3_prepare16() and sqlite3_prepare16_v2() +** use UTF-16. {END} ** -** If the nByte argument is less than zero, then zSql is read up to the -** first zero terminator. If nByte is non-negative, then it is the maximum -** number of bytes read from zSql. When nByte is non-negative, the -** zSql string ends at either the first '\000' or '\u0000' character or +** If the nByte argument is less +** than zero, then zSql is read up to the first zero terminator. +** If nByte is non-negative, then it is the maximum number of +** bytes read from zSql. When nByte is non-negative, the +** zSql string ends at either the first '\000' or '\u0000' character or ** the nByte-th byte, whichever comes first. If the caller knows ** that the supplied string is nul-terminated, then there is a small -** performance advantage to be gained by passing an nByte parameter that -** is equal to the number of bytes in the input string including -** the nul-terminator bytes. +** performance advantage to be had by passing an nByte parameter that +** is equal to the number of bytes in the input string including +** the nul-terminator bytes.{END} ** ** *pzTail is made to point to the first byte past the end of the -** first SQL statement in zSql. These routines only compile the first +** first SQL statement in zSql. These routines only compiles the first ** statement in zSql, so *pzTail is left pointing to what remains ** uncompiled. ** ** *ppStmt is left pointing to a compiled [prepared statement] that can be -** executed using [sqlite3_step()]. If there is an error, *ppStmt is set -** to NULL. If the input text contains no SQL (if the input is an empty -** string or a comment) then *ppStmt is set to NULL. -** {A13018} The calling procedure is responsible for deleting the compiled -** SQL statement using [sqlite3_finalize()] after it has finished with it. +** executed using [sqlite3_step()]. Or if there is an error, *ppStmt is +** set to NULL. If the input text contains no SQL (if the input +** is and empty string or a comment) then *ppStmt is set to NULL. +** {U13018} The calling procedure is responsible for deleting the +** compiled SQL statement +** using [sqlite3_finalize()] after it has finished with it. ** -** On success, [SQLITE_OK] is returned, otherwise an [error code] is returned. +** On success, [SQLITE_OK] is returned. Otherwise an +** [error code] is returned. ** ** The sqlite3_prepare_v2() and sqlite3_prepare16_v2() interfaces are ** recommended for all new programs. The two older interfaces are retained ** for backwards compatibility, but their use is discouraged. ** In the "v2" interfaces, the prepared statement -** that is returned (the [sqlite3_stmt] object) contains a copy of the -** original SQL text. This causes the [sqlite3_step()] interface to +** that is returned (the [sqlite3_stmt] object) contains a copy of the +** original SQL text. {END} This causes the [sqlite3_step()] interface to ** behave a differently in two ways: ** **
      @@ -3340,57 +2732,60 @@ SQLITE_API int sqlite3_limit(sqlite3*, int id, int newVal); ** always used to do, [sqlite3_step()] will automatically recompile the SQL ** statement and try to run it again. If the schema has changed in ** a way that makes the statement no longer valid, [sqlite3_step()] will still -** return [SQLITE_SCHEMA]. But unlike the legacy behavior, [SQLITE_SCHEMA] is -** now a fatal error. Calling [sqlite3_prepare_v2()] again will not make the +** return [SQLITE_SCHEMA]. But unlike the legacy behavior, +** [SQLITE_SCHEMA] is now a fatal error. Calling +** [sqlite3_prepare_v2()] again will not make the ** error go away. Note: use [sqlite3_errmsg()] to find the text -** of the parsing error that results in an [SQLITE_SCHEMA] return. +** of the parsing error that results in an [SQLITE_SCHEMA] return. {END} ** ** **
    1. -** When an error occurs, [sqlite3_step()] will return one of the detailed -** [error codes] or [extended error codes]. The legacy behavior was that -** [sqlite3_step()] would only return a generic [SQLITE_ERROR] result code -** and you would have to make a second call to [sqlite3_reset()] in order -** to find the underlying cause of the problem. With the "v2" prepare -** interfaces, the underlying reason for the error is returned immediately. +** When an error occurs, +** [sqlite3_step()] will return one of the detailed +** [error codes] or [extended error codes]. +** The legacy behavior was that [sqlite3_step()] would only return a generic +** [SQLITE_ERROR] result code and you would have to make a second call to +** [sqlite3_reset()] in order to find the underlying cause of the problem. +** With the "v2" prepare interfaces, the underlying reason for the error is +** returned immediately. **
    2. **
    ** ** INVARIANTS: ** -** {H13011} The [sqlite3_prepare(db,zSql,...)] and +** {F13011} The [sqlite3_prepare(db,zSql,...)] and ** [sqlite3_prepare_v2(db,zSql,...)] interfaces interpret the ** text in their zSql parameter as UTF-8. ** -** {H13012} The [sqlite3_prepare16(db,zSql,...)] and +** {F13012} The [sqlite3_prepare16(db,zSql,...)] and ** [sqlite3_prepare16_v2(db,zSql,...)] interfaces interpret the ** text in their zSql parameter as UTF-16 in the native byte order. ** -** {H13013} If the nByte argument to [sqlite3_prepare_v2(db,zSql,nByte,...)] -** and its variants is less than zero, the SQL text is +** {F13013} If the nByte argument to [sqlite3_prepare_v2(db,zSql,nByte,...)] +** and its variants is less than zero, then SQL text is ** read from zSql is read up to the first zero terminator. ** -** {H13014} If the nByte argument to [sqlite3_prepare_v2(db,zSql,nByte,...)] -** and its variants is non-negative, then at most nBytes bytes of +** {F13014} If the nByte argument to [sqlite3_prepare_v2(db,zSql,nByte,...)] +** and its variants is non-negative, then at most nBytes bytes ** SQL text is read from zSql. ** -** {H13015} In [sqlite3_prepare_v2(db,zSql,N,P,pzTail)] and its variants +** {F13015} In [sqlite3_prepare_v2(db,zSql,N,P,pzTail)] and its variants ** if the zSql input text contains more than one SQL statement ** and pzTail is not NULL, then *pzTail is made to point to the ** first byte past the end of the first SQL statement in zSql. ** What does *pzTail point to if there is one statement? ** -** {H13016} A successful call to [sqlite3_prepare_v2(db,zSql,N,ppStmt,...)] +** {F13016} A successful call to [sqlite3_prepare_v2(db,zSql,N,ppStmt,...)] ** or one of its variants writes into *ppStmt a pointer to a new -** [prepared statement] or a pointer to NULL if zSql contains -** nothing other than whitespace or comments. +** [prepared statement] or a pointer to NULL +** if zSql contains nothing other than whitespace or comments. ** -** {H13019} The [sqlite3_prepare_v2()] interface and its variants return +** {F13019} The [sqlite3_prepare_v2()] interface and its variants return ** [SQLITE_OK] or an appropriate [error code] upon failure. ** -** {H13021} Before [sqlite3_prepare(db,zSql,nByte,ppStmt,pzTail)] or its -** variants returns an error (any value other than [SQLITE_OK]), -** they first set *ppStmt to NULL. +** {F13021} Before [sqlite3_prepare(db,zSql,nByte,ppStmt,pzTail)] or its +** variants returns an error (any value other than [SQLITE_OK]) +** it first sets *ppStmt to NULL. */ SQLITE_API int sqlite3_prepare( sqlite3 *db, /* Database handle */ @@ -3422,89 +2817,85 @@ SQLITE_API int sqlite3_prepare16_v2( ); /* -** CAPI3REF: Retrieving Statement SQL {H13100} +** CAPIREF: Retrieving Statement SQL {F13100} ** -** This interface can be used to retrieve a saved copy of the original -** SQL text used to create a [prepared statement] if that statement was -** compiled using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()]. +** This intereface can be used to retrieve a saved copy of the original +** SQL text used to create a [prepared statement]. ** ** INVARIANTS: ** -** {H13101} If the [prepared statement] passed as the argument to -** [sqlite3_sql()] was compiled using either [sqlite3_prepare_v2()] or -** [sqlite3_prepare16_v2()], then [sqlite3_sql()] returns -** a pointer to a zero-terminated string containing a UTF-8 rendering +** {F13101} If the [prepared statement] passed as +** the an argument to [sqlite3_sql()] was compiled +** compiled using either [sqlite3_prepare_v2()] or +** [sqlite3_prepare16_v2()], +** then [sqlite3_sql()] function returns a pointer to a +** zero-terminated string containing a UTF-8 rendering ** of the original SQL statement. ** -** {H13102} If the [prepared statement] passed as the argument to -** [sqlite3_sql()] was compiled using either [sqlite3_prepare()] or -** [sqlite3_prepare16()], then [sqlite3_sql()] returns a NULL pointer. +** {F13102} If the [prepared statement] passed as +** the an argument to [sqlite3_sql()] was compiled +** compiled using either [sqlite3_prepare()] or +** [sqlite3_prepare16()], +** then [sqlite3_sql()] function returns a NULL pointer. ** -** {H13103} The string returned by [sqlite3_sql(S)] is valid until the +** {F13103} The string returned by [sqlite3_sql(S)] is valid until the ** [prepared statement] S is deleted using [sqlite3_finalize(S)]. */ SQLITE_API const char *sqlite3_sql(sqlite3_stmt *pStmt); /* -** CAPI3REF: Dynamically Typed Value Object {H15000} +** CAPI3REF: Dynamically Typed Value Object {F15000} ** KEYWORDS: {protected sqlite3_value} {unprotected sqlite3_value} ** ** SQLite uses the sqlite3_value object to represent all values -** that can be stored in a database table. SQLite uses dynamic typing -** for the values it stores. Values stored in sqlite3_value objects -** can be integers, floating point values, strings, BLOBs, or NULL. +** that can be stored in a database table. +** SQLite uses dynamic typing for the values it stores. +** Values stored in sqlite3_value objects can be +** be integers, floating point values, strings, BLOBs, or NULL. ** ** An sqlite3_value object may be either "protected" or "unprotected". ** Some interfaces require a protected sqlite3_value. Other interfaces ** will accept either a protected or an unprotected sqlite3_value. -** Every interface that accepts sqlite3_value arguments specifies +** Every interface that accepts sqlite3_value arguments specifies ** whether or not it requires a protected sqlite3_value. ** ** The terms "protected" and "unprotected" refer to whether or not ** a mutex is held. A internal mutex is held for a protected ** sqlite3_value object but no mutex is held for an unprotected ** sqlite3_value object. If SQLite is compiled to be single-threaded -** (with [SQLITE_THREADSAFE=0] and with [sqlite3_threadsafe()] returning 0) -** or if SQLite is run in one of reduced mutex modes -** [SQLITE_CONFIG_SINGLETHREAD] or [SQLITE_CONFIG_MULTITHREAD] -** then there is no distinction between protected and unprotected -** sqlite3_value objects and they can be used interchangeably. However, -** for maximum code portability it is recommended that applications -** still make the distinction between between protected and unprotected -** sqlite3_value objects even when not strictly required. +** (with SQLITE_THREADSAFE=0 and with [sqlite3_threadsafe()] returning 0) +** then there is no distinction between +** protected and unprotected sqlite3_value objects and they can be +** used interchangable. However, for maximum code portability it +** is recommended that applications make the distinction between +** between protected and unprotected sqlite3_value objects even if +** they are single threaded. ** ** The sqlite3_value objects that are passed as parameters into the -** implementation of [application-defined SQL functions] are protected. +** implementation of application-defined SQL functions are protected. ** The sqlite3_value object returned by ** [sqlite3_column_value()] is unprotected. ** Unprotected sqlite3_value objects may only be used with -** [sqlite3_result_value()] and [sqlite3_bind_value()]. -** The [sqlite3_value_blob | sqlite3_value_type()] family of -** interfaces require protected sqlite3_value objects. +** [sqlite3_result_value()] and [sqlite3_bind_value()]. All other +** interfaces that use sqlite3_value require protected sqlite3_value objects. */ typedef struct Mem sqlite3_value; /* -** CAPI3REF: SQL Function Context Object {H16001} +** CAPI3REF: SQL Function Context Object {F16001} ** ** The context in which an SQL function executes is stored in an -** sqlite3_context object. A pointer to an sqlite3_context object -** is always first parameter to [application-defined SQL functions]. -** The application-defined SQL function implementation will pass this -** pointer through into calls to [sqlite3_result_int | sqlite3_result()], -** [sqlite3_aggregate_context()], [sqlite3_user_data()], -** [sqlite3_context_db_handle()], [sqlite3_get_auxdata()], -** and/or [sqlite3_set_auxdata()]. +** sqlite3_context object. A pointer to an sqlite3_context +** object is always first parameter to application-defined SQL functions. */ typedef struct sqlite3_context sqlite3_context; /* -** CAPI3REF: Binding Values To Prepared Statements {H13500} -** KEYWORDS: {host parameter} {host parameters} {host parameter name} -** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding} +** CAPI3REF: Binding Values To Prepared Statements {F13500} ** -** In the SQL strings input to [sqlite3_prepare_v2()] and its variants, -** literals may be replaced by a parameter in one of these forms: +** In the SQL strings input to [sqlite3_prepare_v2()] and its +** variants, literals may be replace by a parameter in one +** of these forms: ** **
      **
    • ? @@ -3515,31 +2906,32 @@ typedef struct sqlite3_context sqlite3_context; **
    ** ** In the parameter forms shown above NNN is an integer literal, -** and VVV is an alpha-numeric parameter name. The values of these -** parameters (also called "host parameter names" or "SQL parameters") +** VVV alpha-numeric parameter name. +** The values of these parameters (also called "host parameter names" +** or "SQL parameters") ** can be set using the sqlite3_bind_*() routines defined here. ** -** The first argument to the sqlite3_bind_*() routines is always -** a pointer to the [sqlite3_stmt] object returned from -** [sqlite3_prepare_v2()] or its variants. -** -** The second argument is the index of the SQL parameter to be set. -** The leftmost SQL parameter has an index of 1. When the same named -** SQL parameter is used more than once, second and subsequent -** occurrences have the same index as the first occurrence. +** The first argument to the sqlite3_bind_*() routines always +** is a pointer to the [sqlite3_stmt] object returned from +** [sqlite3_prepare_v2()] or its variants. The second +** argument is the index of the parameter to be set. The +** first parameter has an index of 1. When the same named +** parameter is used more than once, second and subsequent +** occurrences have the same index as the first occurrence. ** The index for named parameters can be looked up using the -** [sqlite3_bind_parameter_index()] API if desired. The index +** [sqlite3_bind_parameter_name()] API if desired. The index ** for "?NNN" parameters is the value of NNN. -** The NNN value must be between 1 and the [sqlite3_limit()] -** parameter [SQLITE_LIMIT_VARIABLE_NUMBER] (default value: 999). +** The NNN value must be between 1 and the compile-time +** parameter SQLITE_MAX_VARIABLE_NUMBER (default value: 999). ** ** The third argument is the value to bind to the parameter. ** -** In those routines that have a fourth argument, its value is the -** number of bytes in the parameter. To be clear: the value is the -** number of bytes in the value, not the number of characters. +** In those +** routines that have a fourth argument, its value is the number of bytes +** in the parameter. To be clear: the value is the number of bytes +** in the value, not the number of characters. ** If the fourth parameter is negative, the length of the string is -** the number of bytes up to the first zero terminator. +** number of bytes up to the first zero terminator. ** ** The fifth argument to sqlite3_bind_blob(), sqlite3_bind_text(), and ** sqlite3_bind_text16() is a destructor used to dispose of the BLOB or @@ -3551,12 +2943,12 @@ typedef struct sqlite3_context sqlite3_context; ** the sqlite3_bind_*() routine returns. ** ** The sqlite3_bind_zeroblob() routine binds a BLOB of length N that -** is filled with zeroes. A zeroblob uses a fixed amount of memory -** (just an integer to hold its size) while it is being processed. -** Zeroblobs are intended to serve as placeholders for BLOBs whose -** content is later written using -** [sqlite3_blob_open | incremental BLOB I/O] routines. -** A negative value for the zeroblob results in a zero-length BLOB. +** is filled with zeros. A zeroblob uses a fixed amount of memory +** (just an integer to hold it size) while it is being processed. +** Zeroblobs are intended to serve as place-holders for BLOBs whose +** content is later written using +** [sqlite3_blob_open | increment BLOB I/O] routines. A negative +** value for the zeroblob results in a zero-length BLOB. ** ** The sqlite3_bind_*() routines must be called after ** [sqlite3_prepare_v2()] (and its variants) or [sqlite3_reset()] and @@ -3566,7 +2958,7 @@ typedef struct sqlite3_context sqlite3_context; ** ** These routines return [SQLITE_OK] on success or an error code if ** anything goes wrong. [SQLITE_RANGE] is returned if the parameter -** index is out of range. [SQLITE_NOMEM] is returned if malloc() fails. +** index is out of range. [SQLITE_NOMEM] is returned if malloc fails. ** [SQLITE_MISUSE] might be returned if these routines are called on a ** virtual machine that is the wrong state or which has already been finalized. ** Detection of misuse is unreliable. Applications should not depend @@ -3575,79 +2967,79 @@ typedef struct sqlite3_context sqlite3_context; ** panic rather than return SQLITE_MISUSE. ** ** See also: [sqlite3_bind_parameter_count()], -** [sqlite3_bind_parameter_name()], and [sqlite3_bind_parameter_index()]. +** [sqlite3_bind_parameter_name()], and +** [sqlite3_bind_parameter_index()]. ** ** INVARIANTS: ** -** {H13506} The [SQL statement compiler] recognizes tokens of the forms -** "?", "?NNN", "$VVV", ":VVV", and "@VVV" as SQL parameters, -** where NNN is any sequence of one or more digits -** and where VVV is any sequence of one or more alphanumeric -** characters or "::" optionally followed by a string containing -** no spaces and contained within parentheses. +** {F13506} The [sqlite3_prepare | SQL statement compiler] recognizes +** tokens of the forms "?", "?NNN", "$VVV", ":VVV", and "@VVV" +** as SQL parameters, where NNN is any sequence of one or more +** digits and where VVV is any sequence of one or more +** alphanumeric characters or "::" optionally followed by +** a string containing no spaces and contained within parentheses. ** -** {H13509} The initial value of an SQL parameter is NULL. +** {F13509} The initial value of an SQL parameter is NULL. ** -** {H13512} The index of an "?" SQL parameter is one larger than the +** {F13512} The index of an "?" SQL parameter is one larger than the ** largest index of SQL parameter to the left, or 1 if ** the "?" is the leftmost SQL parameter. ** -** {H13515} The index of an "?NNN" SQL parameter is the integer NNN. +** {F13515} The index of an "?NNN" SQL parameter is the integer NNN. ** -** {H13518} The index of an ":VVV", "$VVV", or "@VVV" SQL parameter is -** the same as the index of leftmost occurrences of the same +** {F13518} The index of an ":VVV", "$VVV", or "@VVV" SQL parameter is +** the same as the index of leftmost occurances of the same ** parameter, or one more than the largest index over all -** parameters to the left if this is the first occurrence +** parameters to the left if this is the first occurrance ** of this parameter, or 1 if this is the leftmost parameter. ** -** {H13521} The [SQL statement compiler] fails with an [SQLITE_RANGE] -** error if the index of an SQL parameter is less than 1 -** or greater than the compile-time SQLITE_MAX_VARIABLE_NUMBER -** parameter. +** {F13521} The [sqlite3_prepare | SQL statement compiler] fail with +** an [SQLITE_RANGE] error if the index of an SQL parameter +** is less than 1 or greater than SQLITE_MAX_VARIABLE_NUMBER. ** -** {H13524} Calls to [sqlite3_bind_text | sqlite3_bind(S,N,V,...)] +** {F13524} Calls to [sqlite3_bind_text | sqlite3_bind(S,N,V,...)] ** associate the value V with all SQL parameters having an ** index of N in the [prepared statement] S. ** -** {H13527} Calls to [sqlite3_bind_text | sqlite3_bind(S,N,...)] +** {F13527} Calls to [sqlite3_bind_text | sqlite3_bind(S,N,...)] ** override prior calls with the same values of S and N. ** -** {H13530} Bindings established by [sqlite3_bind_text | sqlite3_bind(S,...)] +** {F13530} Bindings established by [sqlite3_bind_text | sqlite3_bind(S,...)] ** persist across calls to [sqlite3_reset(S)]. ** -** {H13533} In calls to [sqlite3_bind_blob(S,N,V,L,D)], +** {F13533} In calls to [sqlite3_bind_blob(S,N,V,L,D)], ** [sqlite3_bind_text(S,N,V,L,D)], or ** [sqlite3_bind_text16(S,N,V,L,D)] SQLite binds the first L -** bytes of the BLOB or string pointed to by V, when L +** bytes of the blob or string pointed to by V, when L ** is non-negative. ** -** {H13536} In calls to [sqlite3_bind_text(S,N,V,L,D)] or +** {F13536} In calls to [sqlite3_bind_text(S,N,V,L,D)] or ** [sqlite3_bind_text16(S,N,V,L,D)] SQLite binds characters ** from V through the first zero character when L is negative. ** -** {H13539} In calls to [sqlite3_bind_blob(S,N,V,L,D)], +** {F13539} In calls to [sqlite3_bind_blob(S,N,V,L,D)], ** [sqlite3_bind_text(S,N,V,L,D)], or ** [sqlite3_bind_text16(S,N,V,L,D)] when D is the special ** constant [SQLITE_STATIC], SQLite assumes that the value V ** is held in static unmanaged space that will not change ** during the lifetime of the binding. ** -** {H13542} In calls to [sqlite3_bind_blob(S,N,V,L,D)], +** {F13542} In calls to [sqlite3_bind_blob(S,N,V,L,D)], ** [sqlite3_bind_text(S,N,V,L,D)], or ** [sqlite3_bind_text16(S,N,V,L,D)] when D is the special -** constant [SQLITE_TRANSIENT], the routine makes a -** private copy of the value V before it returns. +** constant [SQLITE_TRANSIENT], the routine makes a +** private copy of V value before it returns. ** -** {H13545} In calls to [sqlite3_bind_blob(S,N,V,L,D)], +** {F13545} In calls to [sqlite3_bind_blob(S,N,V,L,D)], ** [sqlite3_bind_text(S,N,V,L,D)], or ** [sqlite3_bind_text16(S,N,V,L,D)] when D is a pointer to ** a function, SQLite invokes that function to destroy the -** value V after it has finished using the value V. +** V value after it has finished using the V value. ** -** {H13548} In calls to [sqlite3_bind_zeroblob(S,N,V,L)] the value bound -** is a BLOB of L bytes, or a zero-length BLOB if L is negative. +** {F13548} In calls to [sqlite3_bind_zeroblob(S,N,V,L)] the value bound +** is a blob of L bytes, or a zero-length blob if L is negative. ** -** {H13551} In calls to [sqlite3_bind_value(S,N,V)] the V argument may +** {F13551} In calls to [sqlite3_bind_value(S,N,V)] the V argument may ** be either a [protected sqlite3_value] object or an ** [unprotected sqlite3_value] object. */ @@ -3662,18 +3054,18 @@ SQLITE_API int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*); SQLITE_API int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n); /* -** CAPI3REF: Number Of SQL Parameters {H13600} +** CAPI3REF: Number Of SQL Parameters {F13600} ** -** This routine can be used to find the number of [SQL parameters] -** in a [prepared statement]. SQL parameters are tokens of the +** This routine can be used to find the number of SQL parameters +** in a prepared statement. SQL parameters are tokens of the ** form "?", "?NNN", ":AAA", "$AAA", or "@AAA" that serve as -** placeholders for values that are [sqlite3_bind_blob | bound] +** place-holders for values that are [sqlite3_bind_blob | bound] ** to the parameters at a later time. ** -** This routine actually returns the index of the largest (rightmost) -** parameter. For all forms except ?NNN, this will correspond to the -** number of unique parameters. If parameters of the ?NNN are used, -** there may be gaps in the list. +** This routine actually returns the index of the largest parameter. +** For all forms except ?NNN, this will correspond to the number of +** unique parameters. If parameters of the ?NNN are used, there may +** be gaps in the list. ** ** See also: [sqlite3_bind_blob|sqlite3_bind()], ** [sqlite3_bind_parameter_name()], and @@ -3681,30 +3073,30 @@ SQLITE_API int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n); ** ** INVARIANTS: ** -** {H13601} The [sqlite3_bind_parameter_count(S)] interface returns +** {F13601} The [sqlite3_bind_parameter_count(S)] interface returns ** the largest index of all SQL parameters in the -** [prepared statement] S, or 0 if S contains no SQL parameters. +** [prepared statement] S, or 0 if S +** contains no SQL parameters. */ SQLITE_API int sqlite3_bind_parameter_count(sqlite3_stmt*); /* -** CAPI3REF: Name Of A Host Parameter {H13620} +** CAPI3REF: Name Of A Host Parameter {F13620} ** ** This routine returns a pointer to the name of the n-th -** [SQL parameter] in a [prepared statement]. +** SQL parameter in a [prepared statement]. ** SQL parameters of the form "?NNN" or ":AAA" or "@AAA" or "$AAA" ** have a name which is the string "?NNN" or ":AAA" or "@AAA" or "$AAA" ** respectively. ** In other words, the initial ":" or "$" or "@" or "?" ** is included as part of the name. -** Parameters of the form "?" without a following integer have no name -** and are also referred to as "anonymous parameters". +** Parameters of the form "?" without a following integer have no name. ** ** The first host parameter has an index of 1, not 0. ** ** If the value n is out of range or if the n-th parameter is ** nameless, then NULL is returned. The returned string is -** always in UTF-8 encoding even if the named parameter was +** always in the UTF-8 encoding even if the named parameter was ** originally specified as UTF-16 in [sqlite3_prepare16()] or ** [sqlite3_prepare16_v2()]. ** @@ -3714,16 +3106,16 @@ SQLITE_API int sqlite3_bind_parameter_count(sqlite3_stmt*); ** ** INVARIANTS: ** -** {H13621} The [sqlite3_bind_parameter_name(S,N)] interface returns +** {F13621} The [sqlite3_bind_parameter_name(S,N)] interface returns ** a UTF-8 rendering of the name of the SQL parameter in -** the [prepared statement] S having index N, or +** [prepared statement] S having index N, or ** NULL if there is no SQL parameter with index N or if the ** parameter with index N is an anonymous parameter "?". */ SQLITE_API const char *sqlite3_bind_parameter_name(sqlite3_stmt*, int); /* -** CAPI3REF: Index Of A Parameter With A Given Name {H13640} +** CAPI3REF: Index Of A Parameter With A Given Name {F13640} ** ** Return the index of an SQL parameter given its name. The ** index value returned is suitable for use as the second @@ -3738,56 +3130,62 @@ SQLITE_API const char *sqlite3_bind_parameter_name(sqlite3_stmt*, int); ** ** INVARIANTS: ** -** {H13641} The [sqlite3_bind_parameter_index(S,N)] interface returns -** the index of SQL parameter in the [prepared statement] +** {F13641} The [sqlite3_bind_parameter_index(S,N)] interface returns +** the index of SQL parameter in [prepared statement] ** S whose name matches the UTF-8 string N, or 0 if there is ** no match. */ SQLITE_API int sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName); /* -** CAPI3REF: Reset All Bindings On A Prepared Statement {H13660} +** CAPI3REF: Reset All Bindings On A Prepared Statement {F13660} ** -** Contrary to the intuition of many, [sqlite3_reset()] does not reset -** the [sqlite3_bind_blob | bindings] on a [prepared statement]. -** Use this routine to reset all host parameters to NULL. +** Contrary to the intuition of many, [sqlite3_reset()] does not +** reset the [sqlite3_bind_blob | bindings] on a +** [prepared statement]. Use this routine to +** reset all host parameters to NULL. ** ** INVARIANTS: ** -** {H13661} The [sqlite3_clear_bindings(S)] interface resets all SQL -** parameter bindings in the [prepared statement] S back to NULL. +** {F13661} The [sqlite3_clear_bindings(S)] interface resets all +** SQL parameter bindings in [prepared statement] S +** back to NULL. */ SQLITE_API int sqlite3_clear_bindings(sqlite3_stmt*); /* -** CAPI3REF: Number Of Columns In A Result Set {H13710} +** CAPI3REF: Number Of Columns In A Result Set {F13710} ** -** Return the number of columns in the result set returned by the -** [prepared statement]. This routine returns 0 if pStmt is an SQL -** statement that does not return data (for example an [UPDATE]). +** Return the number of columns in the result set returned by the +** [prepared statement]. This routine returns 0 +** if pStmt is an SQL statement that does not return data (for +** example an UPDATE). ** ** INVARIANTS: ** -** {H13711} The [sqlite3_column_count(S)] interface returns the number of -** columns in the result set generated by the [prepared statement] S, -** or 0 if S does not generate a result set. +** {F13711} The [sqlite3_column_count(S)] interface returns the number of +** columns in the result set generated by the +** [prepared statement] S, or 0 if S does not generate +** a result set. */ SQLITE_API int sqlite3_column_count(sqlite3_stmt *pStmt); /* -** CAPI3REF: Column Names In A Result Set {H13720} +** CAPI3REF: Column Names In A Result Set {F13720} ** ** These routines return the name assigned to a particular column -** in the result set of a [SELECT] statement. The sqlite3_column_name() -** interface returns a pointer to a zero-terminated UTF-8 string +** in the result set of a SELECT statement. The sqlite3_column_name() +** interface returns a pointer to a zero-terminated UTF8 string ** and sqlite3_column_name16() returns a pointer to a zero-terminated -** UTF-16 string. The first parameter is the [prepared statement] -** that implements the [SELECT] statement. The second parameter is the -** column number. The leftmost column is number 0. +** UTF16 string. The first parameter is the +** [prepared statement] that implements the SELECT statement. +** The second parameter is the column number. The left-most column is +** number 0. ** -** The returned string pointer is valid until either the [prepared statement] -** is destroyed by [sqlite3_finalize()] or until the next call to -** sqlite3_column_name() or sqlite3_column_name16() on the same column. +** The returned string pointer is valid until either the +** [prepared statement] is destroyed by [sqlite3_finalize()] +** or until the next call sqlite3_column_name() or sqlite3_column_name16() +** on the same column. ** ** If sqlite3_malloc() fails during the processing of either routine ** (for example during a conversion from UTF-8 to UTF-16) then a @@ -3800,124 +3198,136 @@ SQLITE_API int sqlite3_column_count(sqlite3_stmt *pStmt); ** ** INVARIANTS: ** -** {H13721} A successful invocation of the [sqlite3_column_name(S,N)] -** interface returns the name of the Nth column (where 0 is -** the leftmost column) for the result set of the -** [prepared statement] S as a zero-terminated UTF-8 string. +** {F13721} A successful invocation of the [sqlite3_column_name(S,N)] +** interface returns the name +** of the Nth column (where 0 is the left-most column) for the +** result set of [prepared statement] S as a +** zero-terminated UTF-8 string. ** -** {H13723} A successful invocation of the [sqlite3_column_name16(S,N)] -** interface returns the name of the Nth column (where 0 is -** the leftmost column) for the result set of the -** [prepared statement] S as a zero-terminated UTF-16 string -** in the native byte order. +** {F13723} A successful invocation of the [sqlite3_column_name16(S,N)] +** interface returns the name +** of the Nth column (where 0 is the left-most column) for the +** result set of [prepared statement] S as a +** zero-terminated UTF-16 string in the native byte order. ** -** {H13724} The [sqlite3_column_name()] and [sqlite3_column_name16()] +** {F13724} The [sqlite3_column_name()] and [sqlite3_column_name16()] ** interfaces return a NULL pointer if they are unable to -** allocate memory to hold their normal return strings. +** allocate memory memory to hold there normal return strings. ** -** {H13725} If the N parameter to [sqlite3_column_name(S,N)] or +** {F13725} If the N parameter to [sqlite3_column_name(S,N)] or ** [sqlite3_column_name16(S,N)] is out of range, then the -** interfaces return a NULL pointer. -** -** {H13726} The strings returned by [sqlite3_column_name(S,N)] and +** interfaces returns a NULL pointer. +** +** {F13726} The strings returned by [sqlite3_column_name(S,N)] and ** [sqlite3_column_name16(S,N)] are valid until the next ** call to either routine with the same S and N parameters ** or until [sqlite3_finalize(S)] is called. ** -** {H13727} When a result column of a [SELECT] statement contains -** an AS clause, the name of that column is the identifier +** {F13727} When a result column of a [SELECT] statement contains +** an AS clause, the name of that column is the indentifier ** to the right of the AS keyword. */ SQLITE_API const char *sqlite3_column_name(sqlite3_stmt*, int N); SQLITE_API const void *sqlite3_column_name16(sqlite3_stmt*, int N); /* -** CAPI3REF: Source Of Data In A Query Result {H13740} +** CAPI3REF: Source Of Data In A Query Result {F13740} ** ** These routines provide a means to determine what column of what -** table in which database a result of a [SELECT] statement comes from. +** table in which database a result of a SELECT statement comes from. ** The name of the database or table or column can be returned as -** either a UTF-8 or UTF-16 string. The _database_ routines return +** either a UTF8 or UTF16 string. The _database_ routines return ** the database name, the _table_ routines return the table name, and ** the origin_ routines return the column name. -** The returned string is valid until the [prepared statement] is destroyed -** using [sqlite3_finalize()] or until the same information is requested +** The returned string is valid until +** the [prepared statement] is destroyed using +** [sqlite3_finalize()] or until the same information is requested ** again in a different encoding. ** ** The names returned are the original un-aliased names of the ** database, table, and column. ** ** The first argument to the following calls is a [prepared statement]. -** These functions return information about the Nth column returned by +** These functions return information about the Nth column returned by ** the statement, where N is the second function argument. ** -** If the Nth column returned by the statement is an expression or -** subquery and is not a column value, then all of these functions return -** NULL. These routine might also return NULL if a memory allocation error -** occurs. Otherwise, they return the name of the attached database, table -** and column that query result column was extracted from. +** If the Nth column returned by the statement is an expression +** or subquery and is not a column value, then all of these functions +** return NULL. These routine might also return NULL if a memory +** allocation error occurs. Otherwise, they return the +** name of the attached database, table and column that query result +** column was extracted from. ** ** As with all other SQLite APIs, those postfixed with "16" return ** UTF-16 encoded strings, the other functions return UTF-8. {END} ** -** These APIs are only available if the library was compiled with the -** [SQLITE_ENABLE_COLUMN_METADATA] C-preprocessor symbol defined. +** These APIs are only available if the library was compiled with the +** SQLITE_ENABLE_COLUMN_METADATA preprocessor symbol defined. ** -** {A13751} +** {U13751} ** If two or more threads call one or more of these routines against the same ** prepared statement and column at the same time then the results are ** undefined. ** ** INVARIANTS: ** -** {H13741} The [sqlite3_column_database_name(S,N)] interface returns either -** the UTF-8 zero-terminated name of the database from which the -** Nth result column of the [prepared statement] S is extracted, -** or NULL if the Nth column of S is a general expression -** or if unable to allocate memory to store the name. -** -** {H13742} The [sqlite3_column_database_name16(S,N)] interface returns either -** the UTF-16 native byte order zero-terminated name of the database -** from which the Nth result column of the [prepared statement] S is -** extracted, or NULL if the Nth column of S is a general expression -** or if unable to allocate memory to store the name. -** -** {H13743} The [sqlite3_column_table_name(S,N)] interface returns either -** the UTF-8 zero-terminated name of the table from which the -** Nth result column of the [prepared statement] S is extracted, -** or NULL if the Nth column of S is a general expression -** or if unable to allocate memory to store the name. -** -** {H13744} The [sqlite3_column_table_name16(S,N)] interface returns either -** the UTF-16 native byte order zero-terminated name of the table -** from which the Nth result column of the [prepared statement] S is -** extracted, or NULL if the Nth column of S is a general expression -** or if unable to allocate memory to store the name. -** -** {H13745} The [sqlite3_column_origin_name(S,N)] interface returns either -** the UTF-8 zero-terminated name of the table column from which the -** Nth result column of the [prepared statement] S is extracted, -** or NULL if the Nth column of S is a general expression -** or if unable to allocate memory to store the name. -** -** {H13746} The [sqlite3_column_origin_name16(S,N)] interface returns either -** the UTF-16 native byte order zero-terminated name of the table -** column from which the Nth result column of the -** [prepared statement] S is extracted, or NULL if the Nth column -** of S is a general expression or if unable to allocate memory +** {F13741} The [sqlite3_column_database_name(S,N)] interface returns either +** the UTF-8 zero-terminated name of the database from which the +** Nth result column of [prepared statement] S +** is extracted, or NULL if the the Nth column of S is a +** general expression or if unable to allocate memory ** to store the name. -** -** {H13748} The return values from -** [sqlite3_column_database_name | column metadata interfaces] -** are valid for the lifetime of the [prepared statement] +** +** {F13742} The [sqlite3_column_database_name16(S,N)] interface returns either +** the UTF-16 native byte order +** zero-terminated name of the database from which the +** Nth result column of [prepared statement] S +** is extracted, or NULL if the the Nth column of S is a +** general expression or if unable to allocate memory +** to store the name. +** +** {F13743} The [sqlite3_column_table_name(S,N)] interface returns either +** the UTF-8 zero-terminated name of the table from which the +** Nth result column of [prepared statement] S +** is extracted, or NULL if the the Nth column of S is a +** general expression or if unable to allocate memory +** to store the name. +** +** {F13744} The [sqlite3_column_table_name16(S,N)] interface returns either +** the UTF-16 native byte order +** zero-terminated name of the table from which the +** Nth result column of [prepared statement] S +** is extracted, or NULL if the the Nth column of S is a +** general expression or if unable to allocate memory +** to store the name. +** +** {F13745} The [sqlite3_column_origin_name(S,N)] interface returns either +** the UTF-8 zero-terminated name of the table column from which the +** Nth result column of [prepared statement] S +** is extracted, or NULL if the the Nth column of S is a +** general expression or if unable to allocate memory +** to store the name. +** +** {F13746} The [sqlite3_column_origin_name16(S,N)] interface returns either +** the UTF-16 native byte order +** zero-terminated name of the table column from which the +** Nth result column of [prepared statement] S +** is extracted, or NULL if the the Nth column of S is a +** general expression or if unable to allocate memory +** to store the name. +** +** {F13748} The return values from +** [sqlite3_column_database_name|column metadata interfaces] +** are valid +** for the lifetime of the [prepared statement] ** or until the encoding is changed by another metadata ** interface call for the same prepared statement and column. ** -** ASSUMPTIONS: +** LIMITATIONS: ** -** {A13751} If two or more threads call one or more -** [sqlite3_column_database_name | column metadata interfaces] -** for the same [prepared statement] and result column +** {U13751} If two or more threads call one or more +** [sqlite3_column_database_name|column metadata interfaces] +** the same [prepared statement] and result column ** at the same time then the results are undefined. */ SQLITE_API const char *sqlite3_column_database_name(sqlite3_stmt*,int); @@ -3928,26 +3338,26 @@ SQLITE_API const char *sqlite3_column_origin_name(sqlite3_stmt*,int); SQLITE_API const void *sqlite3_column_origin_name16(sqlite3_stmt*,int); /* -** CAPI3REF: Declared Datatype Of A Query Result {H13760} +** CAPI3REF: Declared Datatype Of A Query Result {F13760} ** -** The first parameter is a [prepared statement]. -** If this statement is a [SELECT] statement and the Nth column of the -** returned result set of that [SELECT] is a table column (not an +** The first parameter is a [prepared statement]. +** If this statement is a SELECT statement and the Nth column of the +** returned result set of that SELECT is a table column (not an ** expression or subquery) then the declared type of the table ** column is returned. If the Nth column of the result set is an ** expression or subquery, then a NULL pointer is returned. -** The returned string is always UTF-8 encoded. {END} -** -** For example, given the database schema: +** The returned string is always UTF-8 encoded. {END} +** For example, in the database schema: ** ** CREATE TABLE t1(c1 VARIANT); ** -** and the following statement to be compiled: +** And the following statement compiled: ** ** SELECT c1 + 1, c1 FROM t1; ** -** this routine would return the string "VARIANT" for the second result -** column (i==1), and a NULL pointer for the first result column (i==0). +** Then this routine would return the string "VARIANT" for the second +** result column (i==1), and a NULL pointer for the first result column +** (i==0). ** ** SQLite uses dynamic run-time typing. So just because a column ** is declared to contain a particular type does not mean that the @@ -3958,21 +3368,22 @@ SQLITE_API const void *sqlite3_column_origin_name16(sqlite3_stmt*,int); ** ** INVARIANTS: ** -** {H13761} A successful call to [sqlite3_column_decltype(S,N)] returns a -** zero-terminated UTF-8 string containing the declared datatype -** of the table column that appears as the Nth column (numbered -** from 0) of the result set to the [prepared statement] S. +** {F13761} A successful call to [sqlite3_column_decltype(S,N)] +** returns a zero-terminated UTF-8 string containing the +** the declared datatype of the table column that appears +** as the Nth column (numbered from 0) of the result set to the +** [prepared statement] S. ** -** {H13762} A successful call to [sqlite3_column_decltype16(S,N)] +** {F13762} A successful call to [sqlite3_column_decltype16(S,N)] ** returns a zero-terminated UTF-16 native byte order string ** containing the declared datatype of the table column that appears ** as the Nth column (numbered from 0) of the result set to the ** [prepared statement] S. ** -** {H13763} If N is less than 0 or N is greater than or equal to -** the number of columns in the [prepared statement] S, +** {F13763} If N is less than 0 or N is greater than or equal to +** the number of columns in [prepared statement] S ** or if the Nth column of S is an expression or subquery rather -** than a table column, or if a memory allocation failure +** than a table column or if a memory allocation failure ** occurs during encoding conversions, then ** calls to [sqlite3_column_decltype(S,N)] or ** [sqlite3_column_decltype16(S,N)] return NULL. @@ -3980,30 +3391,32 @@ SQLITE_API const void *sqlite3_column_origin_name16(sqlite3_stmt*,int); SQLITE_API const char *sqlite3_column_decltype(sqlite3_stmt*,int); SQLITE_API const void *sqlite3_column_decltype16(sqlite3_stmt*,int); -/* -** CAPI3REF: Evaluate An SQL Statement {H13200} +/* +** CAPI3REF: Evaluate An SQL Statement {F13200} ** -** After a [prepared statement] has been prepared using either -** [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] or one of the legacy -** interfaces [sqlite3_prepare()] or [sqlite3_prepare16()], this function -** must be called one or more times to evaluate the statement. +** After an [prepared statement] has been prepared with a call +** to either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] or to one of +** the legacy interfaces [sqlite3_prepare()] or [sqlite3_prepare16()], +** then this function must be called one or more times to evaluate the +** statement. ** -** The details of the behavior of the sqlite3_step() interface depend +** The details of the behavior of this sqlite3_step() interface depend ** on whether the statement was prepared using the newer "v2" interface ** [sqlite3_prepare_v2()] and [sqlite3_prepare16_v2()] or the older legacy ** interface [sqlite3_prepare()] and [sqlite3_prepare16()]. The use of the ** new "v2" interface is recommended for new applications but the legacy ** interface will continue to be supported. ** -** In the legacy interface, the return value will be either [SQLITE_BUSY], +** In the legacy interface, the return value will be either [SQLITE_BUSY], ** [SQLITE_DONE], [SQLITE_ROW], [SQLITE_ERROR], or [SQLITE_MISUSE]. -** With the "v2" interface, any of the other [result codes] or -** [extended result codes] might be returned as well. +** With the "v2" interface, any of the other [SQLITE_OK | result code] +** or [SQLITE_IOERR_READ | extended result code] might be returned as +** well. ** ** [SQLITE_BUSY] means that the database engine was unable to acquire the -** database locks it needs to do its job. If the statement is a [COMMIT] +** database locks it needs to do its job. If the statement is a COMMIT ** or occurs outside of an explicit transaction, then you can retry the -** statement. If the statement is not a [COMMIT] and occurs within a +** statement. If the statement is not a COMMIT and occurs within a ** explicit transaction then you should rollback the transaction before ** continuing. ** @@ -4012,15 +3425,16 @@ SQLITE_API const void *sqlite3_column_decltype16(sqlite3_stmt*,int); ** machine without first calling [sqlite3_reset()] to reset the virtual ** machine back to its initial state. ** -** If the SQL statement being executed returns any data, then [SQLITE_ROW] -** is returned each time a new row of data is ready for processing by the -** caller. The values may be accessed using the [column access functions]. +** If the SQL statement being executed returns any data, then +** [SQLITE_ROW] is returned each time a new row of data is ready +** for processing by the caller. The values may be accessed using +** the [sqlite3_column_int | column access functions]. ** sqlite3_step() is called again to retrieve the next row of data. -** +** ** [SQLITE_ERROR] means that a run-time error (such as a constraint ** violation) has occurred. sqlite3_step() should not be called again on ** the VM. More information may be found by calling [sqlite3_errmsg()]. -** With the legacy interface, a more specific error code (for example, +** With the legacy interface, a more specific error code (example: ** [SQLITE_INTERRUPT], [SQLITE_SCHEMA], [SQLITE_CORRUPT], and so forth) ** can be obtained by calling [sqlite3_reset()] on the ** [prepared statement]. In the "v2" interface, @@ -4028,75 +3442,80 @@ SQLITE_API const void *sqlite3_column_decltype16(sqlite3_stmt*,int); ** ** [SQLITE_MISUSE] means that the this routine was called inappropriately. ** Perhaps it was called on a [prepared statement] that has -** already been [sqlite3_finalize | finalized] or on one that had +** already been [sqlite3_finalize | finalized] or on one that had ** previously returned [SQLITE_ERROR] or [SQLITE_DONE]. Or it could ** be the case that the same database connection is being used by two or ** more threads at the same moment in time. ** -** Goofy Interface Alert: In the legacy interface, the sqlite3_step() -** API always returns a generic error code, [SQLITE_ERROR], following any -** error other than [SQLITE_BUSY] and [SQLITE_MISUSE]. You must call -** [sqlite3_reset()] or [sqlite3_finalize()] in order to find one of the -** specific [error codes] that better describes the error. +** Goofy Interface Alert: +** In the legacy interface, +** the sqlite3_step() API always returns a generic error code, +** [SQLITE_ERROR], following any error other than [SQLITE_BUSY] +** and [SQLITE_MISUSE]. You must call [sqlite3_reset()] or +** [sqlite3_finalize()] in order to find one of the specific +** [error codes] that better describes the error. ** We admit that this is a goofy design. The problem has been fixed ** with the "v2" interface. If you prepare all of your SQL statements ** using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] instead -** of the legacy [sqlite3_prepare()] and [sqlite3_prepare16()] interfaces, -** then the more specific [error codes] are returned directly +** of the legacy [sqlite3_prepare()] and [sqlite3_prepare16()], then the +** more specific [error codes] are returned directly ** by sqlite3_step(). The use of the "v2" interface is recommended. ** ** INVARIANTS: ** -** {H13202} If the [prepared statement] S is ready to be run, then -** [sqlite3_step(S)] advances that prepared statement until -** completion or until it is ready to return another row of the -** result set, or until an [sqlite3_interrupt | interrupt] -** or a run-time error occurs. +** {F13202} If [prepared statement] S is ready to be +** run, then [sqlite3_step(S)] advances that prepared statement +** until to completion or until it is ready to return another +** row of the result set or an interrupt or run-time error occurs. ** -** {H15304} When a call to [sqlite3_step(S)] causes the [prepared statement] -** S to run to completion, the function returns [SQLITE_DONE]. +** {F15304} When a call to [sqlite3_step(S)] causes the +** [prepared statement] S to run to completion, +** the function returns [SQLITE_DONE]. ** -** {H15306} When a call to [sqlite3_step(S)] stops because it is ready to -** return another row of the result set, it returns [SQLITE_ROW]. +** {F15306} When a call to [sqlite3_step(S)] stops because it is ready +** to return another row of the result set, it returns +** [SQLITE_ROW]. ** -** {H15308} If a call to [sqlite3_step(S)] encounters an -** [sqlite3_interrupt | interrupt] or a run-time error, -** it returns an appropriate error code that is not one of +** {F15308} If a call to [sqlite3_step(S)] encounters an +** [sqlite3_interrupt|interrupt] or a run-time error, +** it returns an appropraite error code that is not one of ** [SQLITE_OK], [SQLITE_ROW], or [SQLITE_DONE]. ** -** {H15310} If an [sqlite3_interrupt | interrupt] or a run-time error +** {F15310} If an [sqlite3_interrupt|interrupt] or run-time error ** occurs during a call to [sqlite3_step(S)] ** for a [prepared statement] S created using ** legacy interfaces [sqlite3_prepare()] or -** [sqlite3_prepare16()], then the function returns either +** [sqlite3_prepare16()] then the function returns either ** [SQLITE_ERROR], [SQLITE_BUSY], or [SQLITE_MISUSE]. */ SQLITE_API int sqlite3_step(sqlite3_stmt*); /* -** CAPI3REF: Number of columns in a result set {H13770} +** CAPI3REF: Number of columns in a result set {F13770} ** -** Returns the number of values in the current row of the result set. +** Return the number of values in the current row of the result set. ** ** INVARIANTS: ** -** {H13771} After a call to [sqlite3_step(S)] that returns [SQLITE_ROW], -** the [sqlite3_data_count(S)] routine will return the same value -** as the [sqlite3_column_count(S)] function. +** {F13771} After a call to [sqlite3_step(S)] that returns +** [SQLITE_ROW], the [sqlite3_data_count(S)] routine +** will return the same value as the +** [sqlite3_column_count(S)] function. ** -** {H13772} After [sqlite3_step(S)] has returned any value other than -** [SQLITE_ROW] or before [sqlite3_step(S)] has been called on the -** [prepared statement] for the first time since it was -** [sqlite3_prepare | prepared] or [sqlite3_reset | reset], -** the [sqlite3_data_count(S)] routine returns zero. +** {F13772} After [sqlite3_step(S)] has returned any value other than +** [SQLITE_ROW] or before [sqlite3_step(S)] has been +** called on the [prepared statement] for +** the first time since it was [sqlite3_prepare|prepared] +** or [sqlite3_reset|reset], the [sqlite3_data_count(S)] +** routine returns zero. */ SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt); /* -** CAPI3REF: Fundamental Datatypes {H10265} +** CAPI3REF: Fundamental Datatypes {F10265} ** KEYWORDS: SQLITE_TEXT ** -** {H10266} Every value in SQLite has one of five fundamental datatypes: +** {F10266}Every value in SQLite has one of five fundamental datatypes: ** **
      **
    • 64-bit signed integer @@ -4110,7 +3529,7 @@ SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt); ** ** Note that the SQLITE_TEXT constant was also used in SQLite version 2 ** for a completely different meaning. Software that links against both -** SQLite version 2 and SQLite version 3 should use SQLITE3_TEXT, not +** SQLite version 2 and SQLite version 3 should use SQLITE3_TEXT not ** SQLITE_TEXT. */ #define SQLITE_INTEGER 1 @@ -4125,31 +3544,33 @@ SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt); #define SQLITE3_TEXT 3 /* -** CAPI3REF: Result Values From A Query {H13800} -** KEYWORDS: {column access functions} +** CAPI3REF: Results Values From A Query {F13800} ** ** These routines form the "result set query" interface. ** -** These routines return information about a single column of the current -** result row of a query. In every case the first argument is a pointer -** to the [prepared statement] that is being evaluated (the [sqlite3_stmt*] -** that was returned from [sqlite3_prepare_v2()] or one of its variants) -** and the second argument is the index of the column for which information -** should be returned. The leftmost column of the result set has the index 0. +** These routines return information about +** a single column of the current result row of a query. In every +** case the first argument is a pointer to the +** [prepared statement] that is being +** evaluated (the [sqlite3_stmt*] that was returned from +** [sqlite3_prepare_v2()] or one of its variants) and +** the second argument is the index of the column for which information +** should be returned. The left-most column of the result set +** has an index of 0. ** -** If the SQL statement does not currently point to a valid row, or if the -** column index is out of range, the result is undefined. +** If the SQL statement is not currently point to a valid row, or if the +** the column index is out of range, the result is undefined. ** These routines may only be called when the most recent call to ** [sqlite3_step()] has returned [SQLITE_ROW] and neither -** [sqlite3_reset()] nor [sqlite3_finalize()] have been called subsequently. +** [sqlite3_reset()] nor [sqlite3_finalize()] has been call subsequently. ** If any of these routines are called after [sqlite3_reset()] or ** [sqlite3_finalize()] or after [sqlite3_step()] has returned ** something other than [SQLITE_ROW], the results are undefined. ** If [sqlite3_step()] or [sqlite3_reset()] or [sqlite3_finalize()] ** are called from a different thread while any of these routines -** are pending, then the results are undefined. +** are pending, then the results are undefined. ** -** The sqlite3_column_type() routine returns the +** The sqlite3_column_type() routine returns ** [SQLITE_INTEGER | datatype code] for the initial data type ** of the result column. The returned value is one of [SQLITE_INTEGER], ** [SQLITE_FLOAT], [SQLITE_TEXT], [SQLITE_BLOB], or [SQLITE_NULL]. The value @@ -4159,7 +3580,7 @@ SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt); ** versions of SQLite may change the behavior of sqlite3_column_type() ** following a type conversion. ** -** If the result is a BLOB or UTF-8 string then the sqlite3_column_bytes() +** If the result is a BLOB or UTF-8 string then the sqlite3_column_bytes() ** routine returns the number of bytes in that BLOB or string. ** If the result is a UTF-16 string, then sqlite3_column_bytes() converts ** the string to UTF-8 and then returns the number of bytes. @@ -4172,11 +3593,11 @@ SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt); ** ** Strings returned by sqlite3_column_text() and sqlite3_column_text16(), ** even empty strings, are always zero terminated. The return -** value from sqlite3_column_blob() for a zero-length BLOB is an arbitrary +** value from sqlite3_column_blob() for a zero-length blob is an arbitrary ** pointer, possibly even a NULL pointer. ** ** The sqlite3_column_bytes16() routine is similar to sqlite3_column_bytes() -** but leaves the result in UTF-16 in native byte order instead of UTF-8. +** but leaves the result in UTF-16 in native byte order instead of UTF-8. ** The zero terminator is not included in this count. ** ** The object returned by [sqlite3_column_value()] is an @@ -4184,14 +3605,15 @@ SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt); ** may only be used with [sqlite3_bind_value()] and [sqlite3_result_value()]. ** If the [unprotected sqlite3_value] object returned by ** [sqlite3_column_value()] is used in any other way, including calls -** to routines like [sqlite3_value_int()], [sqlite3_value_text()], -** or [sqlite3_value_bytes()], then the behavior is undefined. +** to routines like +** [sqlite3_value_int()], [sqlite3_value_text()], or [sqlite3_value_bytes()], +** then the behavior is undefined. ** ** These routines attempt to convert the value where appropriate. For ** example, if the internal representation is FLOAT and a text result -** is requested, [sqlite3_snprintf()] is used internally to perform the -** conversion automatically. The following table details the conversions -** that are applied: +** is requested, [sqlite3_snprintf()] is used internally to do the conversion +** automatically. The following table details the conversions that +** are applied: ** **
      ** @@ -4203,7 +3625,7 @@ SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt); **
      NULL BLOB Result is NULL pointer **
      INTEGER FLOAT Convert from integer to float **
      INTEGER TEXT ASCII rendering of the integer -**
      INTEGER BLOB Same as INTEGER->TEXT +**
      INTEGER BLOB Same as for INTEGER->TEXT **
      FLOAT INTEGER Convert from float to integer **
      FLOAT TEXT ASCII rendering of the float **
      FLOAT BLOB Same as FLOAT->TEXT @@ -4218,56 +3640,57 @@ SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt); ** ** The table above makes reference to standard C library functions atoi() ** and atof(). SQLite does not really use these functions. It has its -** own equivalent internal routines. The atoi() and atof() names are +** on equavalent internal routines. The atoi() and atof() names are ** used in the table for brevity and because they are familiar to most ** C programmers. ** ** Note that when type conversions occur, pointers returned by prior ** calls to sqlite3_column_blob(), sqlite3_column_text(), and/or -** sqlite3_column_text16() may be invalidated. +** sqlite3_column_text16() may be invalidated. ** Type conversions and pointer invalidations might occur ** in the following cases: ** **
        -**
      • The initial content is a BLOB and sqlite3_column_text() or -** sqlite3_column_text16() is called. A zero-terminator might -** need to be added to the string.
      • -**
      • The initial content is UTF-8 text and sqlite3_column_bytes16() or -** sqlite3_column_text16() is called. The content must be converted -** to UTF-16.
      • -**
      • The initial content is UTF-16 text and sqlite3_column_bytes() or -** sqlite3_column_text() is called. The content must be converted -** to UTF-8.
      • +**
      • The initial content is a BLOB and sqlite3_column_text() +** or sqlite3_column_text16() is called. A zero-terminator might +** need to be added to the string.

      • +** +**
      • The initial content is UTF-8 text and sqlite3_column_bytes16() or +** sqlite3_column_text16() is called. The content must be converted +** to UTF-16.

      • +** +**
      • The initial content is UTF-16 text and sqlite3_column_bytes() or +** sqlite3_column_text() is called. The content must be converted +** to UTF-8.

      • **
      ** ** Conversions between UTF-16be and UTF-16le are always done in place and do ** not invalidate a prior pointer, though of course the content of the buffer ** that the prior pointer points to will have been modified. Other kinds -** of conversion are done in place when it is possible, but sometimes they -** are not possible and in those cases prior pointers are invalidated. +** of conversion are done in place when it is possible, but sometime it is +** not possible and in those cases prior pointers are invalidated. ** ** The safest and easiest to remember policy is to invoke these routines ** in one of the following ways: ** -**
        +**
          **
        • sqlite3_column_text() followed by sqlite3_column_bytes()
        • **
        • sqlite3_column_blob() followed by sqlite3_column_bytes()
        • **
        • sqlite3_column_text16() followed by sqlite3_column_bytes16()
        • -**
        +**
      ** -** In other words, you should call sqlite3_column_text(), -** sqlite3_column_blob(), or sqlite3_column_text16() first to force the result -** into the desired format, then invoke sqlite3_column_bytes() or -** sqlite3_column_bytes16() to find the size of the result. Do not mix calls -** to sqlite3_column_text() or sqlite3_column_blob() with calls to -** sqlite3_column_bytes16(), and do not mix calls to sqlite3_column_text16() -** with calls to sqlite3_column_bytes(). +** In other words, you should call sqlite3_column_text(), sqlite3_column_blob(), +** or sqlite3_column_text16() first to force the result into the desired +** format, then invoke sqlite3_column_bytes() or sqlite3_column_bytes16() to +** find the size of the result. Do not mix call to sqlite3_column_text() or +** sqlite3_column_blob() with calls to sqlite3_column_bytes16(). And do not +** mix calls to sqlite3_column_text16() with calls to sqlite3_column_bytes(). ** ** The pointers returned are valid until a type conversion occurs as ** described above, or until [sqlite3_step()] or [sqlite3_reset()] or ** [sqlite3_finalize()] is called. The memory space used to hold strings -** and BLOBs is freed automatically. Do not pass the pointers returned -** [sqlite3_column_blob()], [sqlite3_column_text()], etc. into +** and blobs is freed automatically. Do not pass the pointers returned +** [sqlite3_column_blob()], [sqlite3_column_text()], etc. into ** [sqlite3_free()]. ** ** If a memory allocation error occurs during the evaluation of any @@ -4278,58 +3701,58 @@ SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt); ** ** INVARIANTS: ** -** {H13803} The [sqlite3_column_blob(S,N)] interface converts the +** {F13803} The [sqlite3_column_blob(S,N)] interface converts the ** Nth column in the current row of the result set for -** the [prepared statement] S into a BLOB and then returns a +** [prepared statement] S into a blob and then returns a ** pointer to the converted value. ** -** {H13806} The [sqlite3_column_bytes(S,N)] interface returns the -** number of bytes in the BLOB or string (exclusive of the +** {F13806} The [sqlite3_column_bytes(S,N)] interface returns the +** number of bytes in the blob or string (exclusive of the ** zero terminator on the string) that was returned by the ** most recent call to [sqlite3_column_blob(S,N)] or ** [sqlite3_column_text(S,N)]. ** -** {H13809} The [sqlite3_column_bytes16(S,N)] interface returns the +** {F13809} The [sqlite3_column_bytes16(S,N)] interface returns the ** number of bytes in the string (exclusive of the ** zero terminator on the string) that was returned by the ** most recent call to [sqlite3_column_text16(S,N)]. ** -** {H13812} The [sqlite3_column_double(S,N)] interface converts the -** Nth column in the current row of the result set for the +** {F13812} The [sqlite3_column_double(S,N)] interface converts the +** Nth column in the current row of the result set for ** [prepared statement] S into a floating point value and ** returns a copy of that value. ** -** {H13815} The [sqlite3_column_int(S,N)] interface converts the -** Nth column in the current row of the result set for the +** {F13815} The [sqlite3_column_int(S,N)] interface converts the +** Nth column in the current row of the result set for ** [prepared statement] S into a 64-bit signed integer and ** returns the lower 32 bits of that integer. ** -** {H13818} The [sqlite3_column_int64(S,N)] interface converts the -** Nth column in the current row of the result set for the +** {F13818} The [sqlite3_column_int64(S,N)] interface converts the +** Nth column in the current row of the result set for ** [prepared statement] S into a 64-bit signed integer and ** returns a copy of that integer. ** -** {H13821} The [sqlite3_column_text(S,N)] interface converts the +** {F13821} The [sqlite3_column_text(S,N)] interface converts the ** Nth column in the current row of the result set for -** the [prepared statement] S into a zero-terminated UTF-8 +** [prepared statement] S into a zero-terminated UTF-8 ** string and returns a pointer to that string. ** -** {H13824} The [sqlite3_column_text16(S,N)] interface converts the -** Nth column in the current row of the result set for the +** {F13824} The [sqlite3_column_text16(S,N)] interface converts the +** Nth column in the current row of the result set for ** [prepared statement] S into a zero-terminated 2-byte -** aligned UTF-16 native byte order string and returns -** a pointer to that string. +** aligned UTF-16 native byte order +** string and returns a pointer to that string. ** -** {H13827} The [sqlite3_column_type(S,N)] interface returns +** {F13827} The [sqlite3_column_type(S,N)] interface returns ** one of [SQLITE_NULL], [SQLITE_INTEGER], [SQLITE_FLOAT], ** [SQLITE_TEXT], or [SQLITE_BLOB] as appropriate for ** the Nth column in the current row of the result set for -** the [prepared statement] S. +** [prepared statement] S. ** -** {H13830} The [sqlite3_column_value(S,N)] interface returns a +** {F13830} The [sqlite3_column_value(S,N)] interface returns a ** pointer to an [unprotected sqlite3_value] object for the ** Nth column in the current row of the result set for -** the [prepared statement] S. +** [prepared statement] S. */ SQLITE_API const void *sqlite3_column_blob(sqlite3_stmt*, int iCol); SQLITE_API int sqlite3_column_bytes(sqlite3_stmt*, int iCol); @@ -4343,89 +3766,90 @@ SQLITE_API int sqlite3_column_type(sqlite3_stmt*, int iCol); SQLITE_API sqlite3_value *sqlite3_column_value(sqlite3_stmt*, int iCol); /* -** CAPI3REF: Destroy A Prepared Statement Object {H13300} +** CAPI3REF: Destroy A Prepared Statement Object {F13300} ** -** The sqlite3_finalize() function is called to delete a [prepared statement]. -** If the statement was executed successfully or not executed at all, then -** SQLITE_OK is returned. If execution of the statement failed then an -** [error code] or [extended error code] is returned. +** The sqlite3_finalize() function is called to delete a +** [prepared statement]. If the statement was +** executed successfully, or not executed at all, then SQLITE_OK is returned. +** If execution of the statement failed then an +** [error code] or [extended error code] +** is returned. ** ** This routine can be called at any point during the execution of the -** [prepared statement]. If the virtual machine has not +** [prepared statement]. If the virtual machine has not ** completed execution when this routine is called, that is like -** encountering an error or an [sqlite3_interrupt | interrupt]. -** Incomplete updates may be rolled back and transactions canceled, -** depending on the circumstances, and the +** encountering an error or an interrupt. (See [sqlite3_interrupt()].) +** Incomplete updates may be rolled back and transactions cancelled, +** depending on the circumstances, and the ** [error code] returned will be [SQLITE_ABORT]. ** ** INVARIANTS: ** -** {H11302} The [sqlite3_finalize(S)] interface destroys the +** {F11302} The [sqlite3_finalize(S)] interface destroys the ** [prepared statement] S and releases all ** memory and file resources held by that object. ** -** {H11304} If the most recent call to [sqlite3_step(S)] for the +** {F11304} If the most recent call to [sqlite3_step(S)] for the ** [prepared statement] S returned an error, ** then [sqlite3_finalize(S)] returns that same error. */ SQLITE_API int sqlite3_finalize(sqlite3_stmt *pStmt); /* -** CAPI3REF: Reset A Prepared Statement Object {H13330} +** CAPI3REF: Reset A Prepared Statement Object {F13330} ** -** The sqlite3_reset() function is called to reset a [prepared statement] -** object back to its initial state, ready to be re-executed. +** The sqlite3_reset() function is called to reset a +** [prepared statement] object. +** back to its initial state, ready to be re-executed. ** Any SQL statement variables that had values bound to them using ** the [sqlite3_bind_blob | sqlite3_bind_*() API] retain their values. ** Use [sqlite3_clear_bindings()] to reset the bindings. ** -** {H11332} The [sqlite3_reset(S)] interface resets the [prepared statement] S +** {F11332} The [sqlite3_reset(S)] interface resets the [prepared statement] S ** back to the beginning of its program. ** -** {H11334} If the most recent call to [sqlite3_step(S)] for the +** {F11334} If the most recent call to [sqlite3_step(S)] for ** [prepared statement] S returned [SQLITE_ROW] or [SQLITE_DONE], ** or if [sqlite3_step(S)] has never before been called on S, ** then [sqlite3_reset(S)] returns [SQLITE_OK]. ** -** {H11336} If the most recent call to [sqlite3_step(S)] for the +** {F11336} If the most recent call to [sqlite3_step(S)] for ** [prepared statement] S indicated an error, then ** [sqlite3_reset(S)] returns an appropriate [error code]. ** -** {H11338} The [sqlite3_reset(S)] interface does not change the values -** of any [sqlite3_bind_blob|bindings] on the [prepared statement] S. +** {F11338} The [sqlite3_reset(S)] interface does not change the values +** of any [sqlite3_bind_blob|bindings] on [prepared statement] S. */ SQLITE_API int sqlite3_reset(sqlite3_stmt *pStmt); /* -** CAPI3REF: Create Or Redefine SQL Functions {H16100} -** KEYWORDS: {function creation routines} -** KEYWORDS: {application-defined SQL function} -** KEYWORDS: {application-defined SQL functions} +** CAPI3REF: Create Or Redefine SQL Functions {F16100} +** KEYWORDS: {function creation routines} ** -** These two functions (collectively known as "function creation routines") -** are used to add SQL functions or aggregates or to redefine the behavior -** of existing SQL functions or aggregates. The only difference between the -** two is that the second parameter, the name of the (scalar) function or -** aggregate, is encoded in UTF-8 for sqlite3_create_function() and UTF-16 -** for sqlite3_create_function16(). +** These two functions (collectively known as +** "function creation routines") are used to add SQL functions or aggregates +** or to redefine the behavior of existing SQL functions or aggregates. The +** difference only between the two is that the second parameter, the +** name of the (scalar) function or aggregate, is encoded in UTF-8 for +** sqlite3_create_function() and UTF-16 for sqlite3_create_function16(). ** ** The first parameter is the [database connection] to which the SQL -** function is to be added. If a single program uses more than one database -** connection internally, then SQL functions must be added individually to -** each database connection. +** function is to be added. If a single +** program uses more than one [database connection] internally, then SQL +** functions must be added individually to each [database connection]. ** -** The second parameter is the name of the SQL function to be created or -** redefined. The length of the name is limited to 255 bytes, exclusive of -** the zero-terminator. Note that the name length limit is in bytes, not +** The second parameter is the name of the SQL function to be created +** or redefined. +** The length of the name is limited to 255 bytes, exclusive of the +** zero-terminator. Note that the name length limit is in bytes, not ** characters. Any attempt to create a function with a longer name -** will result in [SQLITE_ERROR] being returned. +** will result in an SQLITE_ERROR error. ** -** The third parameter (nArg) -** is the number of arguments that the SQL function or +** The third parameter is the number of arguments that the SQL function or ** aggregate takes. If this parameter is negative, then the SQL function or ** aggregate may take any number of arguments. ** -** The fourth parameter, eTextRep, specifies what +** The fourth parameter, eTextRep, specifies what ** [SQLITE_UTF8 | text encoding] this SQL function prefers for ** its parameters. Any SQL function implementation should be able to work ** work with UTF-8, UTF-16le, or UTF-16be. But some implementations may be @@ -4434,109 +3858,94 @@ SQLITE_API int sqlite3_reset(sqlite3_stmt *pStmt); ** times with the same function but with different values of eTextRep. ** When multiple implementations of the same function are available, SQLite ** will pick the one that involves the least amount of data conversion. -** If there is only a single implementation which does not care what text -** encoding is used, then the fourth argument should be [SQLITE_ANY]. +** If there is only a single implementation which does not care what +** text encoding is used, then the fourth argument should be +** [SQLITE_ANY]. ** -** The fifth parameter is an arbitrary pointer. The implementation of the -** function can gain access to this pointer using [sqlite3_user_data()]. +** The fifth parameter is an arbitrary pointer. The implementation +** of the function can gain access to this pointer using +** [sqlite3_user_data()]. ** ** The seventh, eighth and ninth parameters, xFunc, xStep and xFinal, are -** pointers to C-language functions that implement the SQL function or -** aggregate. A scalar SQL function requires an implementation of the xFunc -** callback only, NULL pointers should be passed as the xStep and xFinal -** parameters. An aggregate SQL function requires an implementation of xStep -** and xFinal and NULL should be passed for xFunc. To delete an existing -** SQL function or aggregate, pass NULL for all three function callbacks. +** pointers to C-language functions that implement the SQL +** function or aggregate. A scalar SQL function requires an implementation of +** the xFunc callback only, NULL pointers should be passed as the xStep +** and xFinal parameters. An aggregate SQL function requires an implementation +** of xStep and xFinal and NULL should be passed for xFunc. To delete an +** existing SQL function or aggregate, pass NULL for all three function +** callback. ** ** It is permitted to register multiple implementations of the same ** functions with the same name but with either differing numbers of -** arguments or differing preferred text encodings. SQLite will use +** arguments or differing perferred text encodings. SQLite will use ** the implementation most closely matches the way in which the -** SQL function is used. A function implementation with a non-negative -** nArg parameter is a better match than a function implementation with -** a negative nArg. A function where the preferred text encoding -** matches the database encoding is a better -** match than a function where the encoding is different. -** A function where the encoding difference is between UTF16le and UTF16be -** is a closer match than a function where the encoding difference is -** between UTF8 and UTF16. -** -** Built-in functions may be overloaded by new application-defined functions. -** The first application-defined function with a given name overrides all -** built-in functions in the same [database connection] with the same name. -** Subsequent application-defined functions of the same name only override -** prior application-defined functions that are an exact match for the -** number of parameters and preferred encoding. -** -** An application-defined function is permitted to call other -** SQLite interfaces. However, such calls must not -** close the database connection nor finalize or reset the prepared -** statement in which the function is running. +** SQL function is used. ** ** INVARIANTS: ** -** {H16103} The [sqlite3_create_function16(D,X,...)] interface shall behave -** as [sqlite3_create_function(D,X,...)] in every way except that it -** interprets the X argument as zero-terminated UTF-16 -** native byte order instead of as zero-terminated UTF-8. +** {F16103} The [sqlite3_create_function16()] interface behaves exactly +** like [sqlite3_create_function()] in every way except that it +** interprets the zFunctionName argument as +** zero-terminated UTF-16 native byte order instead of as a +** zero-terminated UTF-8. ** -** {H16106} A successful invocation of the -** [sqlite3_create_function(D,X,N,E,...)] interface shall register -** or replaces callback functions in the [database connection] D +** {F16106} A successful invocation of +** the [sqlite3_create_function(D,X,N,E,...)] interface registers +** or replaces callback functions in [database connection] D ** used to implement the SQL function named X with N parameters -** and having a preferred text encoding of E. +** and having a perferred text encoding of E. ** -** {H16109} A successful call to [sqlite3_create_function(D,X,N,E,P,F,S,L)] -** shall replace the P, F, S, and L values from any prior calls with +** {F16109} A successful call to [sqlite3_create_function(D,X,N,E,P,F,S,L)] +** replaces the P, F, S, and L values from any prior calls with ** the same D, X, N, and E values. ** -** {H16112} The [sqlite3_create_function(D,X,...)] interface shall fail -** if the SQL function name X is +** {F16112} The [sqlite3_create_function(D,X,...)] interface fails with +** a return code of [SQLITE_ERROR] if the SQL function name X is ** longer than 255 bytes exclusive of the zero terminator. ** -** {H16118} The [sqlite3_create_function(D,X,N,E,P,F,S,L)] interface -** shall fail unless either F is NULL and S and L are non-NULL or -*** F is non-NULL and S and L are NULL. +** {F16118} Either F must be NULL and S and L are non-NULL or else F +** is non-NULL and S and L are NULL, otherwise +** [sqlite3_create_function(D,X,N,E,P,F,S,L)] returns [SQLITE_ERROR]. ** -** {H16121} The [sqlite3_create_function(D,...)] interface shall fails with an +** {F16121} The [sqlite3_create_function(D,...)] interface fails with an ** error code of [SQLITE_BUSY] if there exist [prepared statements] ** associated with the [database connection] D. ** -** {H16124} The [sqlite3_create_function(D,X,N,...)] interface shall fail with -** an error code of [SQLITE_ERROR] if parameter N is less +** {F16124} The [sqlite3_create_function(D,X,N,...)] interface fails with an +** error code of [SQLITE_ERROR] if parameter N (specifying the number +** of arguments to the SQL function being registered) is less ** than -1 or greater than 127. ** -** {H16127} When N is non-negative, the [sqlite3_create_function(D,X,N,...)] -** interface shall register callbacks to be invoked for the -** SQL function +** {F16127} When N is non-negative, the [sqlite3_create_function(D,X,N,...)] +** interface causes callbacks to be invoked for the SQL function ** named X when the number of arguments to the SQL function is ** exactly N. ** -** {H16130} When N is -1, the [sqlite3_create_function(D,X,N,...)] -** interface shall register callbacks to be invoked for the SQL -** function named X with any number of arguments. +** {F16130} When N is -1, the [sqlite3_create_function(D,X,N,...)] +** interface causes callbacks to be invoked for the SQL function +** named X with any number of arguments. ** -** {H16133} When calls to [sqlite3_create_function(D,X,N,...)] +** {F16133} When calls to [sqlite3_create_function(D,X,N,...)] ** specify multiple implementations of the same function X ** and when one implementation has N>=0 and the other has N=(-1) -** the implementation with a non-zero N shall be preferred. +** the implementation with a non-zero N is preferred. ** -** {H16136} When calls to [sqlite3_create_function(D,X,N,E,...)] +** {F16136} When calls to [sqlite3_create_function(D,X,N,E,...)] ** specify multiple implementations of the same function X with ** the same number of arguments N but with different ** encodings E, then the implementation where E matches the -** database encoding shall preferred. +** database encoding is preferred. ** -** {H16139} For an aggregate SQL function created using -** [sqlite3_create_function(D,X,N,E,P,0,S,L)] the finalizer -** function L shall always be invoked exactly once if the +** {F16139} For an aggregate SQL function created using +** [sqlite3_create_function(D,X,N,E,P,0,S,L)] the finializer +** function L will always be invoked exactly once if the ** step function S is called one or more times. ** -** {H16142} When SQLite invokes either the xFunc or xStep function of +** {F16142} When SQLite invokes either the xFunc or xStep function of ** an application-defined SQL function or aggregate created ** by [sqlite3_create_function()] or [sqlite3_create_function16()], ** then the array of [sqlite3_value] objects passed as the -** third parameter shall be [protected sqlite3_value] objects. +** third parameter are always [protected sqlite3_value] objects. */ SQLITE_API int sqlite3_create_function( sqlite3 *db, @@ -4560,7 +3969,7 @@ SQLITE_API int sqlite3_create_function16( ); /* -** CAPI3REF: Text Encodings {H10267} +** CAPI3REF: Text Encodings {F10267} ** ** These constant define integer codes that represent the various ** text encodings supported by SQLite. @@ -4573,26 +3982,23 @@ SQLITE_API int sqlite3_create_function16( #define SQLITE_UTF16_ALIGNED 8 /* sqlite3_create_collation only */ /* -** CAPI3REF: Deprecated Functions -** DEPRECATED +** CAPI3REF: Obsolete Functions ** -** These functions are [deprecated]. In order to maintain -** backwards compatibility with older code, these functions continue -** to be supported. However, new applications should avoid +** These functions are all now obsolete. In order to maintain +** backwards compatibility with older code, we continue to support +** these functions. However, new development projects should avoid ** the use of these functions. To help encourage people to avoid ** using these functions, we are not going to tell you want they do. */ -#ifndef SQLITE_OMIT_DEPRECATED -SQLITE_API SQLITE_DEPRECATED int sqlite3_aggregate_count(sqlite3_context*); -SQLITE_API SQLITE_DEPRECATED int sqlite3_expired(sqlite3_stmt*); -SQLITE_API SQLITE_DEPRECATED int sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*); -SQLITE_API SQLITE_DEPRECATED int sqlite3_global_recover(void); -SQLITE_API SQLITE_DEPRECATED void sqlite3_thread_cleanup(void); -SQLITE_API SQLITE_DEPRECATED int sqlite3_memory_alarm(void(*)(void*,sqlite3_int64,int),void*,sqlite3_int64); -#endif +SQLITE_API int sqlite3_aggregate_count(sqlite3_context*); +SQLITE_API int sqlite3_expired(sqlite3_stmt*); +SQLITE_API int sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*); +SQLITE_API int sqlite3_global_recover(void); +SQLITE_API void sqlite3_thread_cleanup(void); +SQLITE_API int sqlite3_memory_alarm(void(*)(void*,sqlite3_int64,int),void*,sqlite3_int64); /* -** CAPI3REF: Obtaining SQL Function Parameter Values {H15100} +** CAPI3REF: Obtaining SQL Function Parameter Values {F15100} ** ** The C-language implementation of SQL functions and aggregates uses ** this set of interface routines to access the parameter values on @@ -4610,93 +4016,95 @@ SQLITE_API SQLITE_DEPRECATED int sqlite3_memory_alarm(void(*)(void*,sqlite3_int6 ** Any attempt to use these routines on an [unprotected sqlite3_value] ** object results in undefined behavior. ** -** These routines work just like the corresponding [column access functions] -** except that these routines take a single [protected sqlite3_value] object -** pointer instead of a [sqlite3_stmt*] pointer and an integer column number. +** These routines work just like the corresponding +** [sqlite3_column_blob | sqlite3_column_* routines] except that +** these routines take a single [protected sqlite3_value] object pointer +** instead of an [sqlite3_stmt*] pointer and an integer column number. ** -** The sqlite3_value_text16() interface extracts a UTF-16 string +** The sqlite3_value_text16() interface extracts a UTF16 string ** in the native byte-order of the host machine. The ** sqlite3_value_text16be() and sqlite3_value_text16le() interfaces -** extract UTF-16 strings as big-endian and little-endian respectively. +** extract UTF16 strings as big-endian and little-endian respectively. ** ** The sqlite3_value_numeric_type() interface attempts to apply ** numeric affinity to the value. This means that an attempt is ** made to convert the value to an integer or floating point. If ** such a conversion is possible without loss of information (in other -** words, if the value is a string that looks like a number) -** then the conversion is performed. Otherwise no conversion occurs. -** The [SQLITE_INTEGER | datatype] after conversion is returned. +** words if the value is a string that looks like a number) +** then the conversion is done. Otherwise no conversion occurs. The +** [SQLITE_INTEGER | datatype] after conversion is returned. ** -** Please pay particular attention to the fact that the pointer returned -** from [sqlite3_value_blob()], [sqlite3_value_text()], or +** Please pay particular attention to the fact that the pointer that +** is returned from [sqlite3_value_blob()], [sqlite3_value_text()], or ** [sqlite3_value_text16()] can be invalidated by a subsequent call to ** [sqlite3_value_bytes()], [sqlite3_value_bytes16()], [sqlite3_value_text()], -** or [sqlite3_value_text16()]. +** or [sqlite3_value_text16()]. ** ** These routines must be called from the same thread as ** the SQL function that supplied the [sqlite3_value*] parameters. ** +** ** INVARIANTS: ** -** {H15103} The [sqlite3_value_blob(V)] interface converts the -** [protected sqlite3_value] object V into a BLOB and then -** returns a pointer to the converted value. +** {F15103} The [sqlite3_value_blob(V)] interface converts the +** [protected sqlite3_value] object V into a blob and then returns a +** pointer to the converted value. ** -** {H15106} The [sqlite3_value_bytes(V)] interface returns the -** number of bytes in the BLOB or string (exclusive of the +** {F15106} The [sqlite3_value_bytes(V)] interface returns the +** number of bytes in the blob or string (exclusive of the ** zero terminator on the string) that was returned by the ** most recent call to [sqlite3_value_blob(V)] or ** [sqlite3_value_text(V)]. ** -** {H15109} The [sqlite3_value_bytes16(V)] interface returns the +** {F15109} The [sqlite3_value_bytes16(V)] interface returns the ** number of bytes in the string (exclusive of the ** zero terminator on the string) that was returned by the ** most recent call to [sqlite3_value_text16(V)], ** [sqlite3_value_text16be(V)], or [sqlite3_value_text16le(V)]. ** -** {H15112} The [sqlite3_value_double(V)] interface converts the +** {F15112} The [sqlite3_value_double(V)] interface converts the ** [protected sqlite3_value] object V into a floating point value and ** returns a copy of that value. ** -** {H15115} The [sqlite3_value_int(V)] interface converts the +** {F15115} The [sqlite3_value_int(V)] interface converts the ** [protected sqlite3_value] object V into a 64-bit signed integer and ** returns the lower 32 bits of that integer. ** -** {H15118} The [sqlite3_value_int64(V)] interface converts the +** {F15118} The [sqlite3_value_int64(V)] interface converts the ** [protected sqlite3_value] object V into a 64-bit signed integer and ** returns a copy of that integer. ** -** {H15121} The [sqlite3_value_text(V)] interface converts the -** [protected sqlite3_value] object V into a zero-terminated UTF-8 +** {F15121} The [sqlite3_value_text(V)] interface converts the +** [protected sqlite3_value] object V into a zero-terminated UTF-8 ** string and returns a pointer to that string. ** -** {H15124} The [sqlite3_value_text16(V)] interface converts the +** {F15124} The [sqlite3_value_text16(V)] interface converts the ** [protected sqlite3_value] object V into a zero-terminated 2-byte ** aligned UTF-16 native byte order ** string and returns a pointer to that string. ** -** {H15127} The [sqlite3_value_text16be(V)] interface converts the +** {F15127} The [sqlite3_value_text16be(V)] interface converts the ** [protected sqlite3_value] object V into a zero-terminated 2-byte ** aligned UTF-16 big-endian ** string and returns a pointer to that string. ** -** {H15130} The [sqlite3_value_text16le(V)] interface converts the +** {F15130} The [sqlite3_value_text16le(V)] interface converts the ** [protected sqlite3_value] object V into a zero-terminated 2-byte ** aligned UTF-16 little-endian ** string and returns a pointer to that string. ** -** {H15133} The [sqlite3_value_type(V)] interface returns +** {F15133} The [sqlite3_value_type(V)] interface returns ** one of [SQLITE_NULL], [SQLITE_INTEGER], [SQLITE_FLOAT], ** [SQLITE_TEXT], or [SQLITE_BLOB] as appropriate for ** the [sqlite3_value] object V. ** -** {H15136} The [sqlite3_value_numeric_type(V)] interface converts +** {F15136} The [sqlite3_value_numeric_type(V)] interface converts ** the [protected sqlite3_value] object V into either an integer or ** a floating point value if it can do so without loss of ** information, and returns one of [SQLITE_NULL], ** [SQLITE_INTEGER], [SQLITE_FLOAT], [SQLITE_TEXT], or -** [SQLITE_BLOB] as appropriate for the -** [protected sqlite3_value] object V after the conversion attempt. +** [SQLITE_BLOB] as appropriate for +** the [protected sqlite3_value] object V after the conversion attempt. */ SQLITE_API const void *sqlite3_value_blob(sqlite3_value*); SQLITE_API int sqlite3_value_bytes(sqlite3_value*); @@ -4712,44 +4120,46 @@ SQLITE_API int sqlite3_value_type(sqlite3_value*); SQLITE_API int sqlite3_value_numeric_type(sqlite3_value*); /* -** CAPI3REF: Obtain Aggregate Function Context {H16210} +** CAPI3REF: Obtain Aggregate Function Context {F16210} ** ** The implementation of aggregate SQL functions use this routine to allocate -** a structure for storing their state. -** -** The first time the sqlite3_aggregate_context() routine is called for a -** particular aggregate, SQLite allocates nBytes of memory, zeroes out that -** memory, and returns a pointer to it. On second and subsequent calls to -** sqlite3_aggregate_context() for the same aggregate function index, -** the same buffer is returned. The implementation of the aggregate can use -** the returned buffer to accumulate data. +** a structure for storing their state. +** The first time the sqlite3_aggregate_context() routine is +** is called for a particular aggregate, SQLite allocates nBytes of memory +** zeros that memory, and returns a pointer to it. +** On second and subsequent calls to sqlite3_aggregate_context() +** for the same aggregate function index, the same buffer is returned. +** The implementation +** of the aggregate can use the returned buffer to accumulate data. ** ** SQLite automatically frees the allocated buffer when the aggregate ** query concludes. ** -** The first parameter should be a copy of the -** [sqlite3_context | SQL function context] that is the first parameter -** to the callback routine that implements the aggregate function. +** The first parameter should be a copy of the +** [sqlite3_context | SQL function context] that is the first +** parameter to the callback routine that implements the aggregate +** function. ** ** This routine must be called from the same thread in which ** the aggregate SQL function is running. ** ** INVARIANTS: ** -** {H16211} The first invocation of [sqlite3_aggregate_context(C,N)] for +** {F16211} The first invocation of [sqlite3_aggregate_context(C,N)] for ** a particular instance of an aggregate function (for a particular -** context C) causes SQLite to allocate N bytes of memory, -** zero that memory, and return a pointer to the allocated memory. +** context C) causes SQLite to allocation N bytes of memory, +** zero that memory, and return a pointer to the allocationed +** memory. ** -** {H16213} If a memory allocation error occurs during +** {F16213} If a memory allocation error occurs during ** [sqlite3_aggregate_context(C,N)] then the function returns 0. ** -** {H16215} Second and subsequent invocations of +** {F16215} Second and subsequent invocations of ** [sqlite3_aggregate_context(C,N)] for the same context pointer C ** ignore the N parameter and return a pointer to the same ** block of memory returned by the first invocation. ** -** {H16217} The memory allocated by [sqlite3_aggregate_context(C,N)] is +** {F16217} The memory allocated by [sqlite3_aggregate_context(C,N)] is ** automatically freed on the next call to [sqlite3_reset()] ** or [sqlite3_finalize()] for the [prepared statement] containing ** the aggregate function associated with context C. @@ -4757,11 +4167,11 @@ SQLITE_API int sqlite3_value_numeric_type(sqlite3_value*); SQLITE_API void *sqlite3_aggregate_context(sqlite3_context*, int nBytes); /* -** CAPI3REF: User Data For Functions {H16240} +** CAPI3REF: User Data For Functions {F16240} ** ** The sqlite3_user_data() interface returns a copy of ** the pointer that was the pUserData parameter (the 5th parameter) -** of the [sqlite3_create_function()] +** of the the [sqlite3_create_function()] ** and [sqlite3_create_function16()] routines that originally ** registered the application defined function. {END} ** @@ -4770,67 +4180,71 @@ SQLITE_API void *sqlite3_aggregate_context(sqlite3_context*, int nBytes); ** ** INVARIANTS: ** -** {H16243} The [sqlite3_user_data(C)] interface returns a copy of the +** {F16243} The [sqlite3_user_data(C)] interface returns a copy of the ** P pointer from the [sqlite3_create_function(D,X,N,E,P,F,S,L)] ** or [sqlite3_create_function16(D,X,N,E,P,F,S,L)] call that -** registered the SQL function associated with [sqlite3_context] C. +** registered the SQL function associated with +** [sqlite3_context] C. */ SQLITE_API void *sqlite3_user_data(sqlite3_context*); /* -** CAPI3REF: Database Connection For Functions {H16250} +** CAPI3REF: Database Connection For Functions {F16250} ** ** The sqlite3_context_db_handle() interface returns a copy of ** the pointer to the [database connection] (the 1st parameter) -** of the [sqlite3_create_function()] +** of the the [sqlite3_create_function()] ** and [sqlite3_create_function16()] routines that originally ** registered the application defined function. ** ** INVARIANTS: ** -** {H16253} The [sqlite3_context_db_handle(C)] interface returns a copy of the +** {F16253} The [sqlite3_context_db_handle(C)] interface returns a copy of the ** D pointer from the [sqlite3_create_function(D,X,N,E,P,F,S,L)] ** or [sqlite3_create_function16(D,X,N,E,P,F,S,L)] call that -** registered the SQL function associated with [sqlite3_context] C. +** registered the SQL function associated with +** [sqlite3_context] C. */ SQLITE_API sqlite3 *sqlite3_context_db_handle(sqlite3_context*); /* -** CAPI3REF: Function Auxiliary Data {H16270} +** CAPI3REF: Function Auxiliary Data {F16270} ** ** The following two functions may be used by scalar SQL functions to -** associate metadata with argument values. If the same value is passed to +** associate meta-data with argument values. If the same value is passed to ** multiple invocations of the same SQL function during query execution, under -** some circumstances the associated metadata may be preserved. This may +** some circumstances the associated meta-data may be preserved. This may ** be used, for example, to add a regular-expression matching scalar ** function. The compiled version of the regular expression is stored as -** metadata associated with the SQL value passed as the regular expression +** meta-data associated with the SQL value passed as the regular expression ** pattern. The compiled regular expression can be reused on multiple ** invocations of the same function so that the original pattern string ** does not need to be recompiled on each invocation. ** -** The sqlite3_get_auxdata() interface returns a pointer to the metadata +** The sqlite3_get_auxdata() interface returns a pointer to the meta-data ** associated by the sqlite3_set_auxdata() function with the Nth argument -** value to the application-defined function. If no metadata has been ever -** been set for the Nth argument of the function, or if the corresponding -** function parameter has changed since the meta-data was set, -** then sqlite3_get_auxdata() returns a NULL pointer. +** value to the application-defined function. +** If no meta-data has been ever been set for the Nth +** argument of the function, or if the cooresponding function parameter +** has changed since the meta-data was set, then sqlite3_get_auxdata() +** returns a NULL pointer. ** -** The sqlite3_set_auxdata() interface saves the metadata -** pointed to by its 3rd parameter as the metadata for the N-th +** The sqlite3_set_auxdata() interface saves the meta-data +** pointed to by its 3rd parameter as the meta-data for the N-th ** argument of the application-defined function. Subsequent ** calls to sqlite3_get_auxdata() might return this data, if it has -** not been destroyed. -** If it is not NULL, SQLite will invoke the destructor +** not been destroyed. +** If it is not NULL, SQLite will invoke the destructor ** function given by the 4th parameter to sqlite3_set_auxdata() on -** the metadata when the corresponding function parameter changes +** the meta-data when the corresponding function parameter changes ** or when the SQL statement completes, whichever comes first. ** -** SQLite is free to call the destructor and drop metadata on any -** parameter of any function at any time. The only guarantee is that -** the destructor will be called before the metadata is dropped. +** SQLite is free to call the destructor and drop meta-data on +** any parameter of any function at any time. The only guarantee +** is that the destructor will be called before the metadata is +** dropped. ** -** In practice, metadata is preserved between function calls for +** In practice, meta-data is preserved between function calls for ** expressions that are constant at compile time. This includes literal ** values and SQL variables. ** @@ -4839,27 +4253,28 @@ SQLITE_API sqlite3 *sqlite3_context_db_handle(sqlite3_context*); ** ** INVARIANTS: ** -** {H16272} The [sqlite3_get_auxdata(C,N)] interface returns a pointer +** {F16272} The [sqlite3_get_auxdata(C,N)] interface returns a pointer ** to metadata associated with the Nth parameter of the SQL function ** whose context is C, or NULL if there is no metadata associated ** with that parameter. ** -** {H16274} The [sqlite3_set_auxdata(C,N,P,D)] interface assigns a metadata -** pointer P to the Nth parameter of the SQL function with context C. +** {F16274} The [sqlite3_set_auxdata(C,N,P,D)] interface assigns a metadata +** pointer P to the Nth parameter of the SQL function with context +** C. ** -** {H16276} SQLite will invoke the destructor D with a single argument +** {F16276} SQLite will invoke the destructor D with a single argument ** which is the metadata pointer P following a call to ** [sqlite3_set_auxdata(C,N,P,D)] when SQLite ceases to hold ** the metadata. ** -** {H16277} SQLite ceases to hold metadata for an SQL function parameter +** {F16277} SQLite ceases to hold metadata for an SQL function parameter ** when the value of that parameter changes. ** -** {H16278} When [sqlite3_set_auxdata(C,N,P,D)] is invoked, the destructor +** {F16278} When [sqlite3_set_auxdata(C,N,P,D)] is invoked, the destructor ** is called for any prior metadata associated with the same function ** context C and parameter N. ** -** {H16279} SQLite will call destructors for any metadata it is holding +** {F16279} SQLite will call destructors for any metadata it is holding ** in a particular [prepared statement] S when either ** [sqlite3_reset(S)] or [sqlite3_finalize(S)] is called. */ @@ -4868,12 +4283,12 @@ SQLITE_API void sqlite3_set_auxdata(sqlite3_context*, int N, void*, void (*)(voi /* -** CAPI3REF: Constants Defining Special Destructor Behavior {H10280} +** CAPI3REF: Constants Defining Special Destructor Behavior {F10280} ** -** These are special values for the destructor that is passed in as the +** These are special value for the destructor that is passed in as the ** final argument to routines like [sqlite3_result_blob()]. If the destructor ** argument is SQLITE_STATIC, it means that the content pointer is constant -** and will never change. It does not need to be destroyed. The +** and will never change. It does not need to be destroyed. The ** SQLITE_TRANSIENT value means that the content will likely change in ** the near future and that SQLite should make its own private copy of ** the content before returning. @@ -4886,28 +4301,30 @@ typedef void (*sqlite3_destructor_type)(void*); #define SQLITE_TRANSIENT ((sqlite3_destructor_type)-1) /* -** CAPI3REF: Setting The Result Of An SQL Function {H16400} +** CAPI3REF: Setting The Result Of An SQL Function {F16400} ** ** These routines are used by the xFunc or xFinal callbacks that ** implement SQL functions and aggregates. See ** [sqlite3_create_function()] and [sqlite3_create_function16()] ** for additional information. ** -** These functions work very much like the [parameter binding] family of -** functions used to bind values to host parameters in prepared statements. -** Refer to the [SQL parameter] documentation for additional information. +** These functions work very much like the +** [sqlite3_bind_blob | sqlite3_bind_*] family of functions used +** to bind values to host parameters in prepared statements. +** Refer to the +** [sqlite3_bind_blob | sqlite3_bind_* documentation] for +** additional information. ** ** The sqlite3_result_blob() interface sets the result from -** an application-defined function to be the BLOB whose content is pointed +** an application defined function to be the BLOB whose content is pointed ** to by the second parameter and which is N bytes long where N is the -** third parameter. -** -** The sqlite3_result_zeroblob() interfaces set the result of -** the application-defined function to be a BLOB containing all zero +** third parameter. +** The sqlite3_result_zeroblob() inerfaces set the result of +** the application defined function to be a BLOB containing all zero ** bytes and N bytes in size, where N is the value of the 2nd parameter. ** ** The sqlite3_result_double() interface sets the result from -** an application-defined function to be a floating point value specified +** an application defined function to be a floating point value specified ** by its 2nd argument. ** ** The sqlite3_result_error() and sqlite3_result_error16() functions @@ -4915,8 +4332,8 @@ typedef void (*sqlite3_destructor_type)(void*); ** SQLite uses the string pointed to by the ** 2nd parameter of sqlite3_result_error() or sqlite3_result_error16() ** as the text of an error message. SQLite interprets the error -** message string from sqlite3_result_error() as UTF-8. SQLite -** interprets the string from sqlite3_result_error16() as UTF-16 in native +** message string from sqlite3_result_error() as UTF8. SQLite +** interprets the string from sqlite3_result_error16() as UTF16 in native ** byte order. If the third parameter to sqlite3_result_error() ** or sqlite3_result_error16() is negative then SQLite takes as the error ** message all text up through the first zero character. @@ -4924,7 +4341,7 @@ typedef void (*sqlite3_destructor_type)(void*); ** sqlite3_result_error16() is non-negative then SQLite takes that many ** bytes (not characters) from the 2nd parameter as the error message. ** The sqlite3_result_error() and sqlite3_result_error16() -** routines make a private copy of the error message text before +** routines make a copy private copy of the error message text before ** they return. Hence, the calling function can deallocate or ** modify the text after they return without harm. ** The sqlite3_result_error_code() function changes the error code @@ -4932,11 +4349,11 @@ typedef void (*sqlite3_destructor_type)(void*); ** the error code is SQLITE_ERROR. A subsequent call to sqlite3_result_error() ** or sqlite3_result_error16() resets the error code to SQLITE_ERROR. ** -** The sqlite3_result_toobig() interface causes SQLite to throw an error -** indicating that a string or BLOB is to long to represent. -** -** The sqlite3_result_nomem() interface causes SQLite to throw an error -** indicating that a memory allocation failed. +** The sqlite3_result_toobig() interface causes SQLite +** to throw an error indicating that a string or BLOB is to long +** to represent. The sqlite3_result_nomem() interface +** causes SQLite to throw an exception indicating that the a +** memory allocation failed. ** ** The sqlite3_result_int() interface sets the return value ** of the application-defined function to be the 32-bit signed integer @@ -4948,7 +4365,7 @@ typedef void (*sqlite3_destructor_type)(void*); ** The sqlite3_result_null() interface sets the return value ** of the application-defined function to be NULL. ** -** The sqlite3_result_text(), sqlite3_result_text16(), +** The sqlite3_result_text(), sqlite3_result_text16(), ** sqlite3_result_text16le(), and sqlite3_result_text16be() interfaces ** set the return value of the application-defined function to be ** a text string which is represented as UTF-8, UTF-16 native byte order, @@ -4956,7 +4373,7 @@ typedef void (*sqlite3_destructor_type)(void*); ** SQLite takes the text result from the application from ** the 2nd parameter of the sqlite3_result_text* interfaces. ** If the 3rd parameter to the sqlite3_result_text* interfaces -** is negative, then SQLite takes result text from the 2nd parameter +** is negative, then SQLite takes result text from the 2nd parameter ** through the first zero character. ** If the 3rd parameter to the sqlite3_result_text* interfaces ** is non-negative, then as many bytes (not characters) of the text @@ -4964,12 +4381,13 @@ typedef void (*sqlite3_destructor_type)(void*); ** function result. ** If the 4th parameter to the sqlite3_result_text* interfaces ** or sqlite3_result_blob is a non-NULL pointer, then SQLite calls that -** function as the destructor on the text or BLOB result when it has +** function as the destructor on the text or blob result when it has +** finished using that result. +** If the 4th parameter to the sqlite3_result_text* interfaces +** or sqlite3_result_blob is the special constant SQLITE_STATIC, then +** SQLite assumes that the text or blob result is constant space and +** does not copy the space or call a destructor when it has ** finished using that result. -** If the 4th parameter to the sqlite3_result_text* interfaces or -** sqlite3_result_blob is the special constant SQLITE_STATIC, then SQLite -** assumes that the text or BLOB result is in constant space and does not -** copy the it or call a destructor when it has finished using that result. ** If the 4th parameter to the sqlite3_result_text* interfaces ** or sqlite3_result_blob is the special constant SQLITE_TRANSIENT ** then SQLite makes a copy of the result into space obtained from @@ -4979,109 +4397,109 @@ typedef void (*sqlite3_destructor_type)(void*); ** the application-defined function to be a copy the ** [unprotected sqlite3_value] object specified by the 2nd parameter. The ** sqlite3_result_value() interface makes a copy of the [sqlite3_value] -** so that the [sqlite3_value] specified in the parameter may change or +** so that [sqlite3_value] specified in the parameter may change or ** be deallocated after sqlite3_result_value() returns without harm. ** A [protected sqlite3_value] object may always be used where an ** [unprotected sqlite3_value] object is required, so either ** kind of [sqlite3_value] object can be used with this interface. ** -** If these routines are called from within the different thread -** than the one containing the application-defined function that received +** If these routines are called from within the different thread +** than the one containing the application-defined function that recieved ** the [sqlite3_context] pointer, the results are undefined. ** ** INVARIANTS: ** -** {H16403} The default return value from any SQL function is NULL. +** {F16403} The default return value from any SQL function is NULL. ** -** {H16406} The [sqlite3_result_blob(C,V,N,D)] interface changes the -** return value of function C to be a BLOB that is N bytes +** {F16406} The [sqlite3_result_blob(C,V,N,D)] interface changes the +** return value of function C to be a blob that is N bytes ** in length and with content pointed to by V. ** -** {H16409} The [sqlite3_result_double(C,V)] interface changes the +** {F16409} The [sqlite3_result_double(C,V)] interface changes the ** return value of function C to be the floating point value V. ** -** {H16412} The [sqlite3_result_error(C,V,N)] interface changes the return +** {F16412} The [sqlite3_result_error(C,V,N)] interface changes the return ** value of function C to be an exception with error code -** [SQLITE_ERROR] and a UTF-8 error message copied from V up to the +** [SQLITE_ERROR] and a UTF8 error message copied from V up to the ** first zero byte or until N bytes are read if N is positive. ** -** {H16415} The [sqlite3_result_error16(C,V,N)] interface changes the return +** {F16415} The [sqlite3_result_error16(C,V,N)] interface changes the return ** value of function C to be an exception with error code -** [SQLITE_ERROR] and a UTF-16 native byte order error message +** [SQLITE_ERROR] and a UTF16 native byte order error message ** copied from V up to the first zero terminator or until N bytes ** are read if N is positive. ** -** {H16418} The [sqlite3_result_error_toobig(C)] interface changes the return +** {F16418} The [sqlite3_result_error_toobig(C)] interface changes the return ** value of the function C to be an exception with error code ** [SQLITE_TOOBIG] and an appropriate error message. ** -** {H16421} The [sqlite3_result_error_nomem(C)] interface changes the return +** {F16421} The [sqlite3_result_error_nomem(C)] interface changes the return ** value of the function C to be an exception with error code ** [SQLITE_NOMEM] and an appropriate error message. ** -** {H16424} The [sqlite3_result_error_code(C,E)] interface changes the return +** {F16424} The [sqlite3_result_error_code(C,E)] interface changes the return ** value of the function C to be an exception with error code E. ** The error message text is unchanged. ** -** {H16427} The [sqlite3_result_int(C,V)] interface changes the +** {F16427} The [sqlite3_result_int(C,V)] interface changes the ** return value of function C to be the 32-bit integer value V. ** -** {H16430} The [sqlite3_result_int64(C,V)] interface changes the +** {F16430} The [sqlite3_result_int64(C,V)] interface changes the ** return value of function C to be the 64-bit integer value V. ** -** {H16433} The [sqlite3_result_null(C)] interface changes the +** {F16433} The [sqlite3_result_null(C)] interface changes the ** return value of function C to be NULL. ** -** {H16436} The [sqlite3_result_text(C,V,N,D)] interface changes the -** return value of function C to be the UTF-8 string +** {F16436} The [sqlite3_result_text(C,V,N,D)] interface changes the +** return value of function C to be the UTF8 string ** V up to the first zero if N is negative ** or the first N bytes of V if N is non-negative. ** -** {H16439} The [sqlite3_result_text16(C,V,N,D)] interface changes the -** return value of function C to be the UTF-16 native byte order -** string V up to the first zero if N is negative -** or the first N bytes of V if N is non-negative. +** {F16439} The [sqlite3_result_text16(C,V,N,D)] interface changes the +** return value of function C to be the UTF16 native byte order +** string V up to the first zero if N is +** negative or the first N bytes of V if N is non-negative. ** -** {H16442} The [sqlite3_result_text16be(C,V,N,D)] interface changes the -** return value of function C to be the UTF-16 big-endian -** string V up to the first zero if N is negative -** or the first N bytes or V if N is non-negative. +** {F16442} The [sqlite3_result_text16be(C,V,N,D)] interface changes the +** return value of function C to be the UTF16 big-endian +** string V up to the first zero if N is +** is negative or the first N bytes or V if N is non-negative. ** -** {H16445} The [sqlite3_result_text16le(C,V,N,D)] interface changes the -** return value of function C to be the UTF-16 little-endian -** string V up to the first zero if N is negative -** or the first N bytes of V if N is non-negative. +** {F16445} The [sqlite3_result_text16le(C,V,N,D)] interface changes the +** return value of function C to be the UTF16 little-endian +** string V up to the first zero if N is +** negative or the first N bytes of V if N is non-negative. ** -** {H16448} The [sqlite3_result_value(C,V)] interface changes the -** return value of function C to be the [unprotected sqlite3_value] +** {F16448} The [sqlite3_result_value(C,V)] interface changes the +** return value of function C to be [unprotected sqlite3_value] ** object V. ** -** {H16451} The [sqlite3_result_zeroblob(C,N)] interface changes the -** return value of function C to be an N-byte BLOB of all zeros. +** {F16451} The [sqlite3_result_zeroblob(C,N)] interface changes the +** return value of function C to be an N-byte blob of all zeros. ** -** {H16454} The [sqlite3_result_error()] and [sqlite3_result_error16()] +** {F16454} The [sqlite3_result_error()] and [sqlite3_result_error16()] ** interfaces make a copy of their error message strings before ** returning. ** -** {H16457} If the D destructor parameter to [sqlite3_result_blob(C,V,N,D)], +** {F16457} If the D destructor parameter to [sqlite3_result_blob(C,V,N,D)], ** [sqlite3_result_text(C,V,N,D)], [sqlite3_result_text16(C,V,N,D)], ** [sqlite3_result_text16be(C,V,N,D)], or ** [sqlite3_result_text16le(C,V,N,D)] is the constant [SQLITE_STATIC] ** then no destructor is ever called on the pointer V and SQLite ** assumes that V is immutable. ** -** {H16460} If the D destructor parameter to [sqlite3_result_blob(C,V,N,D)], +** {F16460} If the D destructor parameter to [sqlite3_result_blob(C,V,N,D)], ** [sqlite3_result_text(C,V,N,D)], [sqlite3_result_text16(C,V,N,D)], ** [sqlite3_result_text16be(C,V,N,D)], or ** [sqlite3_result_text16le(C,V,N,D)] is the constant ** [SQLITE_TRANSIENT] then the interfaces makes a copy of the ** content of V and retains the copy. ** -** {H16463} If the D destructor parameter to [sqlite3_result_blob(C,V,N,D)], +** {F16463} If the D destructor parameter to [sqlite3_result_blob(C,V,N,D)], ** [sqlite3_result_text(C,V,N,D)], [sqlite3_result_text16(C,V,N,D)], ** [sqlite3_result_text16be(C,V,N,D)], or ** [sqlite3_result_text16le(C,V,N,D)] is some value other than -** the constants [SQLITE_STATIC] and [SQLITE_TRANSIENT] then +** the constants [SQLITE_STATIC] and [SQLITE_TRANSIENT] then ** SQLite will invoke the destructor D with V as its only argument ** when it has finished with the V value. */ @@ -5103,10 +4521,10 @@ SQLITE_API void sqlite3_result_value(sqlite3_context*, sqlite3_value*); SQLITE_API void sqlite3_result_zeroblob(sqlite3_context*, int n); /* -** CAPI3REF: Define New Collating Sequences {H16600} +** CAPI3REF: Define New Collating Sequences {F16600} ** ** These functions are used to add new collation sequences to the -** [database connection] specified as the first argument. +** [sqlite3*] handle specified as the first argument. ** ** The name of the new collation sequence is specified as a UTF-8 string ** for sqlite3_create_collation() and sqlite3_create_collation_v2() @@ -5116,79 +4534,81 @@ SQLITE_API void sqlite3_result_zeroblob(sqlite3_context*, int n); ** The third argument may be one of the constants [SQLITE_UTF8], ** [SQLITE_UTF16LE] or [SQLITE_UTF16BE], indicating that the user-supplied ** routine expects to be passed pointers to strings encoded using UTF-8, -** UTF-16 little-endian, or UTF-16 big-endian, respectively. The +** UTF-16 little-endian or UTF-16 big-endian respectively. The ** third argument might also be [SQLITE_UTF16_ALIGNED] to indicate that ** the routine expects pointers to 16-bit word aligned strings -** of UTF-16 in the native byte order of the host computer. +** of UTF16 in the native byte order of the host computer. ** ** A pointer to the user supplied routine must be passed as the fifth ** argument. If it is NULL, this is the same as deleting the collation ** sequence (so that SQLite cannot call it anymore). -** Each time the application supplied function is invoked, it is passed -** as its first parameter a copy of the void* passed as the fourth argument -** to sqlite3_create_collation() or sqlite3_create_collation16(). +** Each time the application +** supplied function is invoked, it is passed a copy of the void* passed as +** the fourth argument to sqlite3_create_collation() or +** sqlite3_create_collation16() as its first parameter. ** ** The remaining arguments to the application-supplied routine are two strings, ** each represented by a (length, data) pair and encoded in the encoding ** that was passed as the third argument when the collation sequence was -** registered. {END} The application defined collation routine should -** return negative, zero or positive if the first string is less than, -** equal to, or greater than the second string. i.e. (STRING1 - STRING2). +** registered. {END} The application defined collation routine should +** return negative, zero or positive if +** the first string is less than, equal to, or greater than the second +** string. i.e. (STRING1 - STRING2). ** ** The sqlite3_create_collation_v2() works like sqlite3_create_collation() -** except that it takes an extra argument which is a destructor for +** excapt that it takes an extra argument which is a destructor for ** the collation. The destructor is called when the collation is ** destroyed and is passed a copy of the fourth parameter void* pointer ** of the sqlite3_create_collation_v2(). -** Collations are destroyed when they are overridden by later calls to the -** collation creation functions or when the [database connection] is closed -** using [sqlite3_close()]. +** Collations are destroyed when +** they are overridden by later calls to the collation creation functions +** or when the [sqlite3*] database handle is closed using [sqlite3_close()]. ** ** INVARIANTS: ** -** {H16603} A successful call to the +** {F16603} A successful call to the ** [sqlite3_create_collation_v2(B,X,E,P,F,D)] interface ** registers function F as the comparison function used to -** implement collation X on the [database connection] B for +** implement collation X on [database connection] B for ** databases having encoding E. ** -** {H16604} SQLite understands the X parameter to +** {F16604} SQLite understands the X parameter to ** [sqlite3_create_collation_v2(B,X,E,P,F,D)] as a zero-terminated ** UTF-8 string in which case is ignored for ASCII characters and ** is significant for non-ASCII characters. ** -** {H16606} Successive calls to [sqlite3_create_collation_v2(B,X,E,P,F,D)] +** {F16606} Successive calls to [sqlite3_create_collation_v2(B,X,E,P,F,D)] ** with the same values for B, X, and E, override prior values ** of P, F, and D. ** -** {H16609} If the destructor D in [sqlite3_create_collation_v2(B,X,E,P,F,D)] +** {F16609} The destructor D in [sqlite3_create_collation_v2(B,X,E,P,F,D)] ** is not NULL then it is called with argument P when the ** collating function is dropped by SQLite. ** -** {H16612} A collating function is dropped when it is overloaded. +** {F16612} A collating function is dropped when it is overloaded. ** -** {H16615} A collating function is dropped when the database connection +** {F16615} A collating function is dropped when the database connection ** is closed using [sqlite3_close()]. ** -** {H16618} The pointer P in [sqlite3_create_collation_v2(B,X,E,P,F,D)] +** {F16618} The pointer P in [sqlite3_create_collation_v2(B,X,E,P,F,D)] ** is passed through as the first parameter to the comparison ** function F for all subsequent invocations of F. ** -** {H16621} A call to [sqlite3_create_collation(B,X,E,P,F)] is exactly +** {F16621} A call to [sqlite3_create_collation(B,X,E,P,F)] is exactly ** the same as a call to [sqlite3_create_collation_v2()] with ** the same parameters and a NULL destructor. ** -** {H16624} Following a [sqlite3_create_collation_v2(B,X,E,P,F,D)], +** {F16624} Following a [sqlite3_create_collation_v2(B,X,E,P,F,D)], ** SQLite uses the comparison function F for all text comparison -** operations on the [database connection] B on text values that -** use the collating sequence named X. +** operations on [database connection] B on text values that +** use the collating sequence name X. ** -** {H16627} The [sqlite3_create_collation16(B,X,E,P,F)] works the same +** {F16627} The [sqlite3_create_collation16(B,X,E,P,F)] works the same ** as [sqlite3_create_collation(B,X,E,P,F)] except that the ** collation name X is understood as UTF-16 in native byte order ** instead of UTF-8. ** -** {H16630} When multiple comparison functions are available for the same +** {F16630} When multiple comparison functions are available for the same ** collating sequence, SQLite chooses the one whose text encoding ** requires the least amount of conversion from the default ** text encoding of the database. @@ -5210,32 +4630,33 @@ SQLITE_API int sqlite3_create_collation_v2( ); SQLITE_API int sqlite3_create_collation16( sqlite3*, - const void *zName, + const char *zName, int eTextRep, void*, int(*xCompare)(void*,int,const void*,int,const void*) ); /* -** CAPI3REF: Collation Needed Callbacks {H16700} +** CAPI3REF: Collation Needed Callbacks {F16700} ** ** To avoid having to register all collation sequences before a database ** can be used, a single callback function may be registered with the -** [database connection] to be called whenever an undefined collation -** sequence is required. +** database handle to be called whenever an undefined collation sequence is +** required. ** ** If the function is registered using the sqlite3_collation_needed() API, ** then it is passed the names of undefined collation sequences as strings -** encoded in UTF-8. {H16703} If sqlite3_collation_needed16() is used, -** the names are passed as UTF-16 in machine native byte order. -** A call to either function replaces any existing callback. +** encoded in UTF-8. {F16703} If sqlite3_collation_needed16() is used, the names +** are passed as UTF-16 in machine native byte order. A call to either +** function replaces any existing callback. ** ** When the callback is invoked, the first argument passed is a copy ** of the second argument to sqlite3_collation_needed() or ** sqlite3_collation_needed16(). The second argument is the database -** connection. The third argument is one of [SQLITE_UTF8], [SQLITE_UTF16BE], -** or [SQLITE_UTF16LE], indicating the most desirable form of the collation -** sequence function required. The fourth parameter is the name of the +** handle. The third argument is one of [SQLITE_UTF8], +** [SQLITE_UTF16BE], or [SQLITE_UTF16LE], indicating the most +** desirable form of the collation sequence function required. +** The fourth parameter is the name of the ** required collation sequence. ** ** The callback function should register the desired collation using @@ -5244,22 +4665,24 @@ SQLITE_API int sqlite3_create_collation16( ** ** INVARIANTS: ** -** {H16702} A successful call to [sqlite3_collation_needed(D,P,F)] +** {F16702} A successful call to [sqlite3_collation_needed(D,P,F)] ** or [sqlite3_collation_needed16(D,P,F)] causes ** the [database connection] D to invoke callback F with first ** parameter P whenever it needs a comparison function for a ** collating sequence that it does not know about. ** -** {H16704} Each successful call to [sqlite3_collation_needed()] or +** {F16704} Each successful call to [sqlite3_collation_needed()] or ** [sqlite3_collation_needed16()] overrides the callback registered ** on the same [database connection] by prior calls to either ** interface. ** -** {H16706} The name of the requested collating function passed in the +** {F16706} The name of the requested collating function passed in the ** 4th parameter to the callback is in UTF-8 if the callback ** was registered using [sqlite3_collation_needed()] and ** is in UTF-16 native byte order if the callback was ** registered using [sqlite3_collation_needed16()]. +** +** */ SQLITE_API int sqlite3_collation_needed( sqlite3*, @@ -5298,14 +4721,15 @@ SQLITE_API int sqlite3_rekey( ); /* -** CAPI3REF: Suspend Execution For A Short Time {H10530} +** CAPI3REF: Suspend Execution For A Short Time {F10530} ** -** The sqlite3_sleep() function causes the current thread to suspend execution +** The sqlite3_sleep() function +** causes the current thread to suspend execution ** for at least a number of milliseconds specified in its parameter. ** -** If the operating system does not support sleep requests with -** millisecond time resolution, then the time will be rounded up to -** the nearest second. The number of milliseconds of sleep actually +** If the operating system does not support sleep requests with +** millisecond time resolution, then the time will be rounded up to +** the nearest second. The number of milliseconds of sleep actually ** requested from the operating system is returned. ** ** SQLite implements this interface by calling the xSleep() @@ -5313,27 +4737,27 @@ SQLITE_API int sqlite3_rekey( ** ** INVARIANTS: ** -** {H10533} The [sqlite3_sleep(M)] interface invokes the xSleep +** {F10533} The [sqlite3_sleep(M)] interface invokes the xSleep ** method of the default [sqlite3_vfs|VFS] in order to ** suspend execution of the current thread for at least ** M milliseconds. ** -** {H10536} The [sqlite3_sleep(M)] interface returns the number of +** {F10536} The [sqlite3_sleep(M)] interface returns the number of ** milliseconds of sleep actually requested of the operating ** system, which might be larger than the parameter M. */ SQLITE_API int sqlite3_sleep(int); /* -** CAPI3REF: Name Of The Folder Holding Temporary Files {H10310} +** CAPI3REF: Name Of The Folder Holding Temporary Files {F10310} ** ** If this global variable is made to point to a string which is -** the name of a folder (a.k.a. directory), then all temporary files +** the name of a folder (a.ka. directory), then all temporary files ** created by SQLite will be placed in that directory. If this variable -** is a NULL pointer, then SQLite performs a search for an appropriate -** temporary file directory. +** is NULL pointer, then SQLite does a search for an appropriate temporary +** file directory. ** -** It is not safe to modify this variable once a [database connection] +** It is not safe to modify this variable once a database connection ** has been opened. It is intended that this variable be set once ** as part of process initialization and before any SQLite interface ** routines have been call and remain unchanged thereafter. @@ -5341,99 +4765,65 @@ SQLITE_API int sqlite3_sleep(int); SQLITE_API char *sqlite3_temp_directory; /* -** CAPI3REF: Test For Auto-Commit Mode {H12930} -** KEYWORDS: {autocommit mode} +** CAPI3REF: Test To See If The Database Is In Auto-Commit Mode {F12930} ** -** The sqlite3_get_autocommit() interface returns non-zero or +** The sqlite3_get_autocommit() interfaces returns non-zero or ** zero if the given database connection is or is not in autocommit mode, -** respectively. Autocommit mode is on by default. -** Autocommit mode is disabled by a [BEGIN] statement. -** Autocommit mode is re-enabled by a [COMMIT] or [ROLLBACK]. +** respectively. Autocommit mode is on +** by default. Autocommit mode is disabled by a [BEGIN] statement. +** Autocommit mode is reenabled by a [COMMIT] or [ROLLBACK]. ** ** If certain kinds of errors occur on a statement within a multi-statement -** transaction (errors including [SQLITE_FULL], [SQLITE_IOERR], +** transactions (errors including [SQLITE_FULL], [SQLITE_IOERR], ** [SQLITE_NOMEM], [SQLITE_BUSY], and [SQLITE_INTERRUPT]) then the ** transaction might be rolled back automatically. The only way to -** find out whether SQLite automatically rolled back the transaction after +** find out if SQLite automatically rolled back the transaction after ** an error is to use this function. ** ** INVARIANTS: ** -** {H12931} The [sqlite3_get_autocommit(D)] interface returns non-zero or +** {F12931} The [sqlite3_get_autocommit(D)] interface returns non-zero or ** zero if the [database connection] D is or is not in autocommit ** mode, respectively. ** -** {H12932} Autocommit mode is on by default. +** {F12932} Autocommit mode is on by default. ** -** {H12933} Autocommit mode is disabled by a successful [BEGIN] statement. +** {F12933} Autocommit mode is disabled by a successful [BEGIN] statement. ** -** {H12934} Autocommit mode is enabled by a successful [COMMIT] or [ROLLBACK] +** {F12934} Autocommit mode is enabled by a successful [COMMIT] or [ROLLBACK] ** statement. +** ** -** ASSUMPTIONS: -** -** {A12936} If another thread changes the autocommit status of the database +** LIMITATIONS: +*** +** {U12936} If another thread changes the autocommit status of the database ** connection while this routine is running, then the return value ** is undefined. */ SQLITE_API int sqlite3_get_autocommit(sqlite3*); /* -** CAPI3REF: Find The Database Handle Of A Prepared Statement {H13120} +** CAPI3REF: Find The Database Handle Of A Prepared Statement {F13120} ** -** The sqlite3_db_handle interface returns the [database connection] handle -** to which a [prepared statement] belongs. The database handle returned by -** sqlite3_db_handle is the same database handle that was the first argument -** to the [sqlite3_prepare_v2()] call (or its variants) that was used to -** create the statement in the first place. +** The sqlite3_db_handle interface +** returns the [sqlite3*] database handle to which a +** [prepared statement] belongs. +** The database handle returned by sqlite3_db_handle +** is the same database handle that was +** the first argument to the [sqlite3_prepare_v2()] or its variants +** that was used to create the statement in the first place. ** ** INVARIANTS: ** -** {H13123} The [sqlite3_db_handle(S)] interface returns a pointer -** to the [database connection] associated with the +** {F13123} The [sqlite3_db_handle(S)] interface returns a pointer +** to the [database connection] associated with ** [prepared statement] S. */ SQLITE_API sqlite3 *sqlite3_db_handle(sqlite3_stmt*); -/* -** CAPI3REF: Find the next prepared statement {H13140} -** -** This interface returns a pointer to the next [prepared statement] after -** pStmt associated with the [database connection] pDb. If pStmt is NULL -** then this interface returns a pointer to the first prepared statement -** associated with the database connection pDb. If no prepared statement -** satisfies the conditions of this routine, it returns NULL. -** -** INVARIANTS: -** -** {H13143} If D is a [database connection] that holds one or more -** unfinalized [prepared statements] and S is a NULL pointer, -** then [sqlite3_next_stmt(D, S)] routine shall return a pointer -** to one of the prepared statements associated with D. -** -** {H13146} If D is a [database connection] that holds no unfinalized -** [prepared statements] and S is a NULL pointer, then -** [sqlite3_next_stmt(D, S)] routine shall return a NULL pointer. -** -** {H13149} If S is a [prepared statement] in the [database connection] D -** and S is not the last prepared statement in D, then -** [sqlite3_next_stmt(D, S)] routine shall return a pointer -** to the next prepared statement in D after S. -** -** {H13152} If S is the last [prepared statement] in the -** [database connection] D then the [sqlite3_next_stmt(D, S)] -** routine shall return a NULL pointer. -** -** ASSUMPTIONS: -** -** {A13154} The [database connection] pointer D in a call to -** [sqlite3_next_stmt(D,S)] must refer to an open database -** connection and in particular must not be a NULL pointer. -*/ -SQLITE_API sqlite3_stmt *sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt); /* -** CAPI3REF: Commit And Rollback Notification Callbacks {H12950} +** CAPI3REF: Commit And Rollback Notification Callbacks {F12950} ** ** The sqlite3_commit_hook() interface registers a callback ** function to be invoked whenever a transaction is committed. @@ -5443,24 +4833,16 @@ SQLITE_API sqlite3_stmt *sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt); ** function to be invoked whenever a transaction is committed. ** Any callback set by a previous call to sqlite3_commit_hook() ** for the same database connection is overridden. -** The pArg argument is passed through to the callback. -** If the callback on a commit hook function returns non-zero, -** then the commit is converted into a rollback. +** The pArg argument is passed through +** to the callback. If the callback on a commit hook function +** returns non-zero, then the commit is converted into a rollback. ** ** If another function was previously registered, its ** pArg value is returned. Otherwise NULL is returned. ** -** The callback implementation must not do anything that will modify -** the database connection that invoked the callback. Any actions -** to modify the database connection must be deferred until after the -** completion of the [sqlite3_step()] call that triggered the commit -** or rollback hook in the first place. -** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their -** database connections for the meaning of "modify" in this paragraph. -** ** Registering a NULL function disables the callback. ** -** For the purposes of this API, a transaction is said to have been +** For the purposes of this API, a transaction is said to have been ** rolled back if an explicit "ROLLBACK" statement is executed, or ** an error or constraint causes an implicit rollback to occur. ** The rollback callback is not invoked if a transaction is @@ -5469,108 +4851,107 @@ SQLITE_API sqlite3_stmt *sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt); ** rolled back because a commit callback returned non-zero. ** Check on this ** +** These are experimental interfaces and are subject to change. +** ** INVARIANTS: ** -** {H12951} The [sqlite3_commit_hook(D,F,P)] interface registers the +** {F12951} The [sqlite3_commit_hook(D,F,P)] interface registers the ** callback function F to be invoked with argument P whenever -** a transaction commits on the [database connection] D. +** a transaction commits on [database connection] D. ** -** {H12952} The [sqlite3_commit_hook(D,F,P)] interface returns the P argument -** from the previous call with the same [database connection] D, -** or NULL on the first call for a particular database connection D. +** {F12952} The [sqlite3_commit_hook(D,F,P)] interface returns the P +** argument from the previous call with the same +** [database connection ] D , or NULL on the first call +** for a particular [database connection] D. ** -** {H12953} Each call to [sqlite3_commit_hook()] overwrites the callback +** {F12953} Each call to [sqlite3_commit_hook()] overwrites the callback ** registered by prior calls. ** -** {H12954} If the F argument to [sqlite3_commit_hook(D,F,P)] is NULL -** then the commit hook callback is canceled and no callback +** {F12954} If the F argument to [sqlite3_commit_hook(D,F,P)] is NULL +** then the commit hook callback is cancelled and no callback ** is invoked when a transaction commits. ** -** {H12955} If the commit callback returns non-zero then the commit is +** {F12955} If the commit callback returns non-zero then the commit is ** converted into a rollback. ** -** {H12961} The [sqlite3_rollback_hook(D,F,P)] interface registers the +** {F12961} The [sqlite3_rollback_hook(D,F,P)] interface registers the ** callback function F to be invoked with argument P whenever -** a transaction rolls back on the [database connection] D. +** a transaction rolls back on [database connection] D. ** -** {H12962} The [sqlite3_rollback_hook(D,F,P)] interface returns the P -** argument from the previous call with the same -** [database connection] D, or NULL on the first call -** for a particular database connection D. +** {F12962} The [sqlite3_rollback_hook(D,F,P)] interface returns the P +** argument from the previous call with the same +** [database connection ] D , or NULL on the first call +** for a particular [database connection] D. ** -** {H12963} Each call to [sqlite3_rollback_hook()] overwrites the callback +** {F12963} Each call to [sqlite3_rollback_hook()] overwrites the callback ** registered by prior calls. ** -** {H12964} If the F argument to [sqlite3_rollback_hook(D,F,P)] is NULL -** then the rollback hook callback is canceled and no callback +** {F12964} If the F argument to [sqlite3_rollback_hook(D,F,P)] is NULL +** then the rollback hook callback is cancelled and no callback ** is invoked when a transaction rolls back. */ SQLITE_API void *sqlite3_commit_hook(sqlite3*, int(*)(void*), void*); SQLITE_API void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*); /* -** CAPI3REF: Data Change Notification Callbacks {H12970} +** CAPI3REF: Data Change Notification Callbacks {F12970} ** -** The sqlite3_update_hook() interface registers a callback function -** with the [database connection] identified by the first argument -** to be invoked whenever a row is updated, inserted or deleted. -** Any callback set by a previous call to this function -** for the same database connection is overridden. +** The sqlite3_update_hook() interface +** registers a callback function with the database connection identified by the +** first argument to be invoked whenever a row is updated, inserted or deleted. +** Any callback set by a previous call to this function for the same +** database connection is overridden. ** -** The second argument is a pointer to the function to invoke when a -** row is updated, inserted or deleted. -** The first argument to the callback is a copy of the third argument -** to sqlite3_update_hook(). -** The second callback argument is one of [SQLITE_INSERT], [SQLITE_DELETE], -** or [SQLITE_UPDATE], depending on the operation that caused the callback -** to be invoked. -** The third and fourth arguments to the callback contain pointers to the -** database and table name containing the affected row. -** The final callback parameter is the rowid of the row. In the case of -** an update, this is the rowid after the update takes place. +** The second argument is a pointer to the function to invoke when a +** row is updated, inserted or deleted. +** The first argument to the callback is +** a copy of the third argument to sqlite3_update_hook(). +** The second callback +** argument is one of [SQLITE_INSERT], [SQLITE_DELETE] or [SQLITE_UPDATE], +** depending on the operation that caused the callback to be invoked. +** The third and +** fourth arguments to the callback contain pointers to the database and +** table name containing the affected row. +** The final callback parameter is +** the rowid of the row. +** In the case of an update, this is the rowid after +** the update takes place. ** ** The update hook is not invoked when internal system tables are ** modified (i.e. sqlite_master and sqlite_sequence). ** -** The update hook implementation must not do anything that will modify -** the database connection that invoked the update hook. Any actions -** to modify the database connection must be deferred until after the -** completion of the [sqlite3_step()] call that triggered the update hook. -** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their -** database connections for the meaning of "modify" in this paragraph. -** ** If another function was previously registered, its pArg value ** is returned. Otherwise NULL is returned. ** ** INVARIANTS: ** -** {H12971} The [sqlite3_update_hook(D,F,P)] interface causes the callback +** {F12971} The [sqlite3_update_hook(D,F,P)] interface causes callback ** function F to be invoked with first parameter P whenever ** a table row is modified, inserted, or deleted on -** the [database connection] D. +** [database connection] D. ** -** {H12973} The [sqlite3_update_hook(D,F,P)] interface returns the value +** {F12973} The [sqlite3_update_hook(D,F,P)] interface returns the value ** of P for the previous call on the same [database connection] D, ** or NULL for the first call. ** -** {H12975} If the update hook callback F in [sqlite3_update_hook(D,F,P)] +** {F12975} If the update hook callback F in [sqlite3_update_hook(D,F,P)] ** is NULL then the no update callbacks are made. ** -** {H12977} Each call to [sqlite3_update_hook(D,F,P)] overrides prior calls +** {F12977} Each call to [sqlite3_update_hook(D,F,P)] overrides prior calls ** to the same interface on the same [database connection] D. ** -** {H12979} The update hook callback is not invoked when internal system +** {F12979} The update hook callback is not invoked when internal system ** tables such as sqlite_master and sqlite_sequence are modified. ** -** {H12981} The second parameter to the update callback +** {F12981} The second parameter to the update callback ** is one of [SQLITE_INSERT], [SQLITE_DELETE] or [SQLITE_UPDATE], ** depending on the operation that caused the callback to be invoked. ** -** {H12983} The third and fourth arguments to the callback contain pointers +** {F12983} The third and fourth arguments to the callback contain pointers ** to zero-terminated UTF-8 strings which are the names of the ** database and table that is being updated. -** {H12985} The final callback parameter is the rowid of the row after +** {F12985} The final callback parameter is the rowid of the row after ** the change occurs. */ SQLITE_API void *sqlite3_update_hook( @@ -5580,92 +4961,96 @@ SQLITE_API void *sqlite3_update_hook( ); /* -** CAPI3REF: Enable Or Disable Shared Pager Cache {H10330} -** KEYWORDS: {shared cache} {shared cache mode} +** CAPI3REF: Enable Or Disable Shared Pager Cache {F10330} ** ** This routine enables or disables the sharing of the database cache -** and schema data structures between [database connection | connections] -** to the same database. Sharing is enabled if the argument is true -** and disabled if the argument is false. +** and schema data structures between connections to the same database. +** Sharing is enabled if the argument is true and disabled if the argument +** is false. ** -** Cache sharing is enabled and disabled for an entire process. {END} -** This is a change as of SQLite version 3.5.0. In prior versions of SQLite, -** sharing was enabled or disabled for each thread separately. +** Cache sharing is enabled and disabled +** for an entire process. {END} This is a change as of SQLite version 3.5.0. +** In prior versions of SQLite, sharing was +** enabled or disabled for each thread separately. ** ** The cache sharing mode set by this interface effects all subsequent ** calls to [sqlite3_open()], [sqlite3_open_v2()], and [sqlite3_open16()]. ** Existing database connections continue use the sharing mode ** that was in effect at the time they were opened. ** -** Virtual tables cannot be used with a shared cache. When shared +** Virtual tables cannot be used with a shared cache. When shared ** cache is enabled, the [sqlite3_create_module()] API used to register ** virtual tables will always return an error. ** -** This routine returns [SQLITE_OK] if shared cache was enabled or disabled -** successfully. An [error code] is returned otherwise. +** This routine returns [SQLITE_OK] if shared cache was +** enabled or disabled successfully. An [error code] +** is returned otherwise. ** ** Shared cache is disabled by default. But this might change in ** future releases of SQLite. Applications that care about shared ** cache setting should set it explicitly. ** ** INVARIANTS: -** -** {H10331} A successful invocation of [sqlite3_enable_shared_cache(B)] +** +** {F10331} A successful invocation of [sqlite3_enable_shared_cache(B)] ** will enable or disable shared cache mode for any subsequently ** created [database connection] in the same process. ** -** {H10336} When shared cache is enabled, the [sqlite3_create_module()] +** {F10336} When shared cache is enabled, the [sqlite3_create_module()] ** interface will always return an error. ** -** {H10337} The [sqlite3_enable_shared_cache(B)] interface returns +** {F10337} The [sqlite3_enable_shared_cache(B)] interface returns ** [SQLITE_OK] if shared cache was enabled or disabled successfully. ** -** {H10339} Shared cache is disabled by default. +** {F10339} Shared cache is disabled by default. */ SQLITE_API int sqlite3_enable_shared_cache(int); /* -** CAPI3REF: Attempt To Free Heap Memory {H17340} +** CAPI3REF: Attempt To Free Heap Memory {F17340} ** -** The sqlite3_release_memory() interface attempts to free N bytes -** of heap memory by deallocating non-essential memory allocations -** held by the database library. {END} Memory used to cache database -** pages to improve performance is an example of non-essential memory. -** sqlite3_release_memory() returns the number of bytes actually freed, -** which might be more or less than the amount requested. +** The sqlite3_release_memory() interface attempts to +** free N bytes of heap memory by deallocating non-essential memory +** allocations held by the database labrary. {END} Memory used +** to cache database pages to improve performance is an example of +** non-essential memory. Sqlite3_release_memory() returns +** the number of bytes actually freed, which might be more or less +** than the amount requested. ** ** INVARIANTS: ** -** {H17341} The [sqlite3_release_memory(N)] interface attempts to +** {F17341} The [sqlite3_release_memory(N)] interface attempts to ** free N bytes of heap memory by deallocating non-essential -** memory allocations held by the database library. +** memory allocations held by the database labrary. ** -** {H16342} The [sqlite3_release_memory(N)] returns the number +** {F16342} The [sqlite3_release_memory(N)] returns the number ** of bytes actually freed, which might be more or less ** than the amount requested. */ SQLITE_API int sqlite3_release_memory(int); /* -** CAPI3REF: Impose A Limit On Heap Size {H17350} +** CAPI3REF: Impose A Limit On Heap Size {F17350} ** -** The sqlite3_soft_heap_limit() interface places a "soft" limit -** on the amount of heap memory that may be allocated by SQLite. -** If an internal allocation is requested that would exceed the -** soft heap limit, [sqlite3_release_memory()] is invoked one or -** more times to free up some space before the allocation is performed. +** The sqlite3_soft_heap_limit() interface +** places a "soft" limit on the amount of heap memory that may be allocated +** by SQLite. If an internal allocation is requested +** that would exceed the soft heap limit, [sqlite3_release_memory()] is +** invoked one or more times to free up some space before the allocation +** is made. ** -** The limit is called "soft", because if [sqlite3_release_memory()] -** cannot free sufficient memory to prevent the limit from being exceeded, +** The limit is called "soft", because if +** [sqlite3_release_memory()] cannot +** free sufficient memory to prevent the limit from being exceeded, ** the memory is allocated anyway and the current operation proceeds. ** ** A negative or zero value for N means that there is no soft heap limit and ** [sqlite3_release_memory()] will only be called when memory is exhausted. ** The default value for the soft heap limit is zero. ** -** SQLite makes a best effort to honor the soft heap limit. -** But if the soft heap limit cannot be honored, execution will -** continue without error or notification. This is why the limit is +** SQLite makes a best effort to honor the soft heap limit. +** But if the soft heap limit cannot honored, execution will +** continue without error or notification. This is why the limit is ** called a "soft" limit. It is advisory only. ** ** Prior to SQLite version 3.5.0, this routine only constrained the memory @@ -5678,79 +5063,81 @@ SQLITE_API int sqlite3_release_memory(int); ** ** INVARIANTS: ** -** {H16351} The [sqlite3_soft_heap_limit(N)] interface places a soft limit +** {F16351} The [sqlite3_soft_heap_limit(N)] interface places a soft limit ** of N bytes on the amount of heap memory that may be allocated ** using [sqlite3_malloc()] or [sqlite3_realloc()] at any point ** in time. ** -** {H16352} If a call to [sqlite3_malloc()] or [sqlite3_realloc()] would +** {F16352} If a call to [sqlite3_malloc()] or [sqlite3_realloc()] would ** cause the total amount of allocated memory to exceed the ** soft heap limit, then [sqlite3_release_memory()] is invoked ** in an attempt to reduce the memory usage prior to proceeding ** with the memory allocation attempt. ** -** {H16353} Calls to [sqlite3_malloc()] or [sqlite3_realloc()] that trigger +** {F16353} Calls to [sqlite3_malloc()] or [sqlite3_realloc()] that trigger ** attempts to reduce memory usage through the soft heap limit ** mechanism continue even if the attempt to reduce memory ** usage is unsuccessful. ** -** {H16354} A negative or zero value for N in a call to +** {F16354} A negative or zero value for N in a call to ** [sqlite3_soft_heap_limit(N)] means that there is no soft ** heap limit and [sqlite3_release_memory()] will only be ** called when memory is completely exhausted. ** -** {H16355} The default value for the soft heap limit is zero. +** {F16355} The default value for the soft heap limit is zero. ** -** {H16358} Each call to [sqlite3_soft_heap_limit(N)] overrides the +** {F16358} Each call to [sqlite3_soft_heap_limit(N)] overrides the ** values set by all prior calls. */ SQLITE_API void sqlite3_soft_heap_limit(int); /* -** CAPI3REF: Extract Metadata About A Column Of A Table {H12850} +** CAPI3REF: Extract Metadata About A Column Of A Table {F12850} ** -** This routine returns metadata about a specific column of a specific -** database table accessible using the [database connection] handle -** passed as the first function argument. +** This routine +** returns meta-data about a specific column of a specific database +** table accessible using the connection handle passed as the first function +** argument. ** -** The column is identified by the second, third and fourth parameters to +** The column is identified by the second, third and fourth parameters to ** this function. The second parameter is either the name of the database ** (i.e. "main", "temp" or an attached database) containing the specified ** table or NULL. If it is NULL, then all attached databases are searched -** for the table using the same algorithm used by the database engine to +** for the table using the same algorithm as the database engine uses to ** resolve unqualified table references. ** -** The third and fourth parameters to this function are the table and column -** name of the desired column, respectively. Neither of these parameters +** The third and fourth parameters to this function are the table and column +** name of the desired column, respectively. Neither of these parameters ** may be NULL. ** -** Metadata is returned by writing to the memory locations passed as the 5th -** and subsequent parameters to this function. Any of these arguments may be -** NULL, in which case the corresponding element of metadata is omitted. +** Meta information is returned by writing to the memory locations passed as +** the 5th and subsequent parameters to this function. Any of these +** arguments may be NULL, in which case the corresponding element of meta +** information is ommitted. ** -**
      -** -**
      Parameter Output
      Type
      Description +**
      +** Parameter     Output Type      Description
      +** -----------------------------------
       **
      -** 
      5th const char* Data type -**
      6th const char* Name of default collation sequence -**
      7th int True if column has a NOT NULL constraint -**
      8th int True if column is part of the PRIMARY KEY -**
      9th int True if column is AUTOINCREMENT -**
      -**
      +** 5th const char* Data type +** 6th const char* Name of the default collation sequence +** 7th int True if the column has a NOT NULL constraint +** 8th int True if the column is part of the PRIMARY KEY +** 9th int True if the column is AUTOINCREMENT +** ** -** The memory pointed to by the character pointers returned for the -** declaration type and collation sequence is valid only until the next -** call to any SQLite API function. ** -** If the specified table is actually a view, an [error code] is returned. +** The memory pointed to by the character pointers returned for the +** declaration type and collation sequence is valid only until the next +** call to any sqlite API function. ** -** If the specified column is "rowid", "oid" or "_rowid_" and an -** INTEGER PRIMARY KEY column has been explicitly declared, then the output +** If the specified table is actually a view, then an error is returned. +** +** If the specified column is "rowid", "oid" or "_rowid_" and an +** INTEGER PRIMARY KEY column has been explicitly declared, then the output ** parameters are set for the explicitly declared column. If there is no -** explicitly declared INTEGER PRIMARY KEY column, then the output -** parameters are set as follows: +** explicitly declared IPK column, then the output parameters are set as +** follows: ** **
       **     data type: "INTEGER"
      @@ -5762,11 +5149,11 @@ SQLITE_API void sqlite3_soft_heap_limit(int);
       **
       ** This function may load one or more schemas from database files. If an
       ** error occurs during this process, or if the requested table or column
      -** cannot be found, an [error code] is returned and an error message left
      -** in the [database connection] (to be retrieved using sqlite3_errmsg()).
      +** cannot be found, an SQLITE error code is returned and an error message
      +** left in the database handle (to be retrieved using sqlite3_errmsg()).
       **
       ** This API is only available if the library was compiled with the
      -** [SQLITE_ENABLE_COLUMN_METADATA] C-preprocessor symbol defined.
      +** SQLITE_ENABLE_COLUMN_METADATA preprocessor symbol defined.
       */
       SQLITE_API int sqlite3_table_column_metadata(
         sqlite3 *db,                /* Connection handle */
      @@ -5781,30 +5168,27 @@ SQLITE_API int sqlite3_table_column_metadata(
       );
       
       /*
      -** CAPI3REF: Load An Extension {H12600} 
      +** CAPI3REF: Load An Extension {F12600}
       **
      -** This interface loads an SQLite extension library from the named file.
      +** {F12601} The sqlite3_load_extension() interface
      +** attempts to load an SQLite extension library contained in the file
      +** zFile. {F12602} The entry point is zProc. {F12603} zProc may be 0
      +** in which case the name of the entry point defaults
      +** to "sqlite3_extension_init".
       **
      -** {H12601} The sqlite3_load_extension() interface attempts to load an
      -**          SQLite extension library contained in the file zFile.
      +** {F12604} The sqlite3_load_extension() interface shall
      +** return [SQLITE_OK] on success and [SQLITE_ERROR] if something goes wrong.
       **
      -** {H12602} The entry point is zProc.
      +** {F12605}
      +** If an error occurs and pzErrMsg is not 0, then the
      +** sqlite3_load_extension() interface shall attempt to fill *pzErrMsg with 
      +** error message text stored in memory obtained from [sqlite3_malloc()].
      +** {END}  The calling function should free this memory
      +** by calling [sqlite3_free()].
       **
      -** {H12603} zProc may be 0, in which case the name of the entry point
      -**          defaults to "sqlite3_extension_init".
      -**
      -** {H12604} The sqlite3_load_extension() interface shall return
      -**          [SQLITE_OK] on success and [SQLITE_ERROR] if something goes wrong.
      -**
      -** {H12605} If an error occurs and pzErrMsg is not 0, then the
      -**          [sqlite3_load_extension()] interface shall attempt to
      -**          fill *pzErrMsg with error message text stored in memory
      -**          obtained from [sqlite3_malloc()]. {END}  The calling function
      -**          should free this memory by calling [sqlite3_free()].
      -**
      -** {H12606} Extension loading must be enabled using
      -**          [sqlite3_enable_load_extension()] prior to calling this API,
      -**          otherwise an error will be returned.
      +** {F12606}
      +** Extension loading must be enabled using [sqlite3_enable_load_extension()]
      +** prior to calling this API or an error will be returned.
       */
       SQLITE_API int sqlite3_load_extension(
         sqlite3 *db,          /* Load the extension into this database connection */
      @@ -5814,64 +5198,65 @@ SQLITE_API int sqlite3_load_extension(
       );
       
       /*
      -** CAPI3REF: Enable Or Disable Extension Loading {H12620} 
      +** CAPI3REF:  Enable Or Disable Extension Loading {F12620}
       **
       ** So as not to open security holes in older applications that are
       ** unprepared to deal with extension loading, and as a means of disabling
      -** extension loading while evaluating user-entered SQL, the following API
      -** is provided to turn the [sqlite3_load_extension()] mechanism on and off.
      +** extension loading while evaluating user-entered SQL, the following
      +** API is provided to turn the [sqlite3_load_extension()] mechanism on and
      +** off.  {F12622} It is off by default. {END} See ticket #1863.
       **
      -** Extension loading is off by default. See ticket #1863.
      -**
      -** {H12621} Call the sqlite3_enable_load_extension() routine with onoff==1
      -**          to turn extension loading on and call it with onoff==0 to turn
      -**          it back off again.
      -**
      -** {H12622} Extension loading is off by default.
      +** {F12621} Call the sqlite3_enable_load_extension() routine
      +** with onoff==1 to turn extension loading on
      +** and call it with onoff==0 to turn it back off again. {END}
       */
       SQLITE_API int sqlite3_enable_load_extension(sqlite3 *db, int onoff);
       
       /*
      -** CAPI3REF: Automatically Load An Extensions {H12640} 
      +** CAPI3REF: Make Arrangements To Automatically Load An Extension {F12640}
      +**
      +** {F12641} This function
      +** registers an extension entry point that is automatically invoked
      +** whenever a new database connection is opened using
      +** [sqlite3_open()], [sqlite3_open16()], or [sqlite3_open_v2()]. {END}
       **
       ** This API can be invoked at program startup in order to register
       ** one or more statically linked extensions that will be available
      -** to all new [database connections]. {END}
      +** to all new database connections.
       **
      -** This routine stores a pointer to the extension in an array that is
      -** obtained from [sqlite3_malloc()].  If you run a memory leak checker
      -** on your program and it reports a leak because of this array, invoke
      -** [sqlite3_reset_auto_extension()] prior to shutdown to free the memory.
      +** {F12642} Duplicate extensions are detected so calling this routine multiple
      +** times with the same extension is harmless.
       **
      -** {H12641} This function registers an extension entry point that is
      -**          automatically invoked whenever a new [database connection]
      -**          is opened using [sqlite3_open()], [sqlite3_open16()],
      -**          or [sqlite3_open_v2()].
      +** {F12643} This routine stores a pointer to the extension in an array
      +** that is obtained from sqlite_malloc(). {END} If you run a memory leak
      +** checker on your program and it reports a leak because of this
      +** array, then invoke [sqlite3_reset_auto_extension()] prior
      +** to shutdown to free the memory.
       **
      -** {H12642} Duplicate extensions are detected so calling this routine
      -**          multiple times with the same extension is harmless.
      +** {F12644} Automatic extensions apply across all threads. {END}
       **
      -** {H12643} This routine stores a pointer to the extension in an array
      -**          that is obtained from [sqlite3_malloc()].
      -**
      -** {H12644} Automatic extensions apply across all threads.
      +** This interface is experimental and is subject to change or
      +** removal in future releases of SQLite.
       */
       SQLITE_API int sqlite3_auto_extension(void *xEntryPoint);
       
      +
       /*
      -** CAPI3REF: Reset Automatic Extension Loading {H12660} 
      +** CAPI3REF: Reset Automatic Extension Loading {F12660}
       **
      -** This function disables all previously registered automatic
      -** extensions. {END}  It undoes the effect of all prior
      -** [sqlite3_auto_extension()] calls.
      +** {F12661} This function disables all previously registered
      +** automatic extensions. {END}  This
      +** routine undoes the effect of all prior [sqlite3_auto_extension()]
      +** calls.
       **
      -** {H12661} This function disables all previously registered
      -**          automatic extensions.
      +** {F12662} This call disabled automatic extensions in all threads. {END}
       **
      -** {H12662} This function disables automatic extensions in all threads.
      +** This interface is experimental and is subject to change or
      +** removal in future releases of SQLite.
       */
       SQLITE_API void sqlite3_reset_auto_extension(void);
       
      +
       /*
       ****** EXPERIMENTAL - subject to change without notice **************
       **
      @@ -5879,7 +5264,7 @@ SQLITE_API void sqlite3_reset_auto_extension(void);
       ** to be experimental.  The interface might change in incompatible ways.
       ** If this is a problem for you, do not use the interface at this time.
       **
      -** When the virtual-table mechanism stabilizes, we will declare the
      +** When the virtual-table mechanism stablizes, we will declare the
       ** interface fixed, support it indefinitely, and remove this comment.
       */
       
      @@ -5892,16 +5277,12 @@ typedef struct sqlite3_vtab_cursor sqlite3_vtab_cursor;
       typedef struct sqlite3_module sqlite3_module;
       
       /*
      -** CAPI3REF: Virtual Table Object {H18000} 
      +** CAPI3REF: Virtual Table Object {F18000}
       ** KEYWORDS: sqlite3_module
      -** EXPERIMENTAL
       **
       ** A module is a class of virtual tables.  Each module is defined
       ** by an instance of the following structure.  This structure consists
       ** mostly of methods for the module.
      -**
      -** This interface is experimental and is subject to change or
      -** removal in future releases of SQLite.
       */
       struct sqlite3_module {
         int iVersion;
      @@ -5930,13 +5311,13 @@ struct sqlite3_module {
         int (*xFindFunction)(sqlite3_vtab *pVtab, int nArg, const char *zName,
                              void (**pxFunc)(sqlite3_context*,int,sqlite3_value**),
                              void **ppArg);
      +
         int (*xRename)(sqlite3_vtab *pVtab, const char *zNew);
       };
       
       /*
      -** CAPI3REF: Virtual Table Indexing Information {H18100} 
      +** CAPI3REF: Virtual Table Indexing Information {F18100}
       ** KEYWORDS: sqlite3_index_info
      -** EXPERIMENTAL
       **
       ** The sqlite3_index_info structure and its substructures is used to
       ** pass information into and receive the reply from the xBestIndex
      @@ -5944,12 +5325,14 @@ struct sqlite3_module {
       ** inputs to xBestIndex and are read-only.  xBestIndex inserts its
       ** results into the **Outputs** fields.
       **
      -** The aConstraint[] array records WHERE clause constraints of the form:
      +** The aConstraint[] array records WHERE clause constraints of the
      +** form:
       **
      -** 
      column OP expr
      +** column OP expr ** -** where OP is =, <, <=, >, or >=. The particular operator is -** stored in aConstraint[].op. The index of the column is stored in +** Where OP is =, <, <=, >, or >=. +** The particular operator is stored +** in aConstraint[].op. The index of the column is stored in ** aConstraint[].iColumn. aConstraint[].usable is TRUE if the ** expr on the right-hand side can be evaluated (and thus the constraint ** is usable) and false if it cannot. @@ -5981,9 +5364,6 @@ struct sqlite3_module { ** particular lookup. A full scan of a table with N entries should have ** a cost of N. A binary search of a table of N entries should have a ** cost of approximately log(N). -** -** This interface is experimental and is subject to change or -** removal in future releases of SQLite. */ struct sqlite3_index_info { /* Inputs */ @@ -5999,6 +5379,7 @@ struct sqlite3_index_info { int iColumn; /* Column number */ unsigned char desc; /* True for DESC. False for ASC. */ } *aOrderBy; /* The ORDER BY clause */ + /* Outputs */ struct sqlite3_index_constraint_usage { int argvIndex; /* if >0, constraint is part of argv to xFilter */ @@ -6018,18 +5399,14 @@ struct sqlite3_index_info { #define SQLITE_INDEX_CONSTRAINT_MATCH 64 /* -** CAPI3REF: Register A Virtual Table Implementation {H18200} -** EXPERIMENTAL +** CAPI3REF: Register A Virtual Table Implementation {F18200} ** -** This routine is used to register a new module name with a -** [database connection]. Module names must be registered before -** creating new virtual tables on the module, or before using -** preexisting virtual tables of the module. -** -** This interface is experimental and is subject to change or -** removal in future releases of SQLite. +** This routine is used to register a new module name with an SQLite +** connection. Module names must be registered before creating new +** virtual tables on the module, or before using preexisting virtual +** tables of the module. */ -SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_create_module( +SQLITE_API int sqlite3_create_module( sqlite3 *db, /* SQLite connection to register module with */ const char *zName, /* Name of the module */ const sqlite3_module *, /* Methods for the module */ @@ -6037,14 +5414,13 @@ SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_create_module( ); /* -** CAPI3REF: Register A Virtual Table Implementation {H18210} -** EXPERIMENTAL +** CAPI3REF: Register A Virtual Table Implementation {F18210} ** -** This routine is identical to the [sqlite3_create_module()] method above, +** This routine is identical to the sqlite3_create_module() method above, ** except that it allows a destructor function to be specified. It is ** even more experimental than the rest of the virtual tables API. */ -SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_create_module_v2( +SQLITE_API int sqlite3_create_module_v2( sqlite3 *db, /* SQLite connection to register module with */ const char *zName, /* Name of the module */ const sqlite3_module *, /* Methods for the module */ @@ -6053,28 +5429,24 @@ SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_create_module_v2( ); /* -** CAPI3REF: Virtual Table Instance Object {H18010} +** CAPI3REF: Virtual Table Instance Object {F18010} ** KEYWORDS: sqlite3_vtab -** EXPERIMENTAL ** ** Every module implementation uses a subclass of the following structure ** to describe a particular instance of the module. Each subclass will -** be tailored to the specific needs of the module implementation. -** The purpose of this superclass is to define certain fields that are -** common to all module implementations. +** be tailored to the specific needs of the module implementation. The +** purpose of this superclass is to define certain fields that are common +** to all module implementations. ** ** Virtual tables methods can set an error message by assigning a -** string obtained from [sqlite3_mprintf()] to zErrMsg. The method should -** take care that any prior string is freed by a call to [sqlite3_free()] +** string obtained from sqlite3_mprintf() to zErrMsg. The method should +** take care that any prior string is freed by a call to sqlite3_free() ** prior to assigning a new string to zErrMsg. After the error message ** is delivered up to the client application, the string will be automatically ** freed by sqlite3_free() and the zErrMsg field will be zeroed. Note ** that sqlite3_mprintf() and sqlite3_free() are used on the zErrMsg field ** since virtual tables are commonly implemented in loadable extensions which ** do not have access to sqlite3MPrintf() or sqlite3Free(). -** -** This interface is experimental and is subject to change or -** removal in future releases of SQLite. */ struct sqlite3_vtab { const sqlite3_module *pModule; /* The module for this virtual table */ @@ -6084,9 +5456,8 @@ struct sqlite3_vtab { }; /* -** CAPI3REF: Virtual Table Cursor Object {H18020} +** CAPI3REF: Virtual Table Cursor Object {F18020} ** KEYWORDS: sqlite3_vtab_cursor -** EXPERIMENTAL ** ** Every module implementation uses a subclass of the following structure ** to describe cursors that point into the virtual table and are used @@ -6096,9 +5467,6 @@ struct sqlite3_vtab { ** ** This superclass exists in order to define fields of the cursor that ** are common to all implementations. -** -** This interface is experimental and is subject to change or -** removal in future releases of SQLite. */ struct sqlite3_vtab_cursor { sqlite3_vtab *pVtab; /* Virtual table of this cursor */ @@ -6106,21 +5474,16 @@ struct sqlite3_vtab_cursor { }; /* -** CAPI3REF: Declare The Schema Of A Virtual Table {H18280} -** EXPERIMENTAL +** CAPI3REF: Declare The Schema Of A Virtual Table {F18280} ** ** The xCreate and xConnect methods of a module use the following API ** to declare the format (the names and datatypes of the columns) of ** the virtual tables they implement. -** -** This interface is experimental and is subject to change or -** removal in future releases of SQLite. */ -SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_declare_vtab(sqlite3*, const char *zCreateTable); +SQLITE_API int sqlite3_declare_vtab(sqlite3*, const char *zCreateTable); /* -** CAPI3REF: Overload A Function For A Virtual Table {H18300} -** EXPERIMENTAL +** CAPI3REF: Overload A Function For A Virtual Table {F18300} ** ** Virtual tables can provide alternative implementations of functions ** using the xFindFunction method. But global versions of those functions @@ -6131,13 +5494,13 @@ SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_declare_vtab(sqlite3*, const char *zC ** before this API is called, a new function is created. The implementation ** of the new function always causes an exception to be thrown. So ** the new function is not good for anything by itself. Its only -** purpose is to be a placeholder function that can be overloaded +** purpose is to be a place-holder function that can be overloaded ** by virtual tables. ** ** This API should be considered part of the virtual table interface, ** which is experimental and subject to change. */ -SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg); +SQLITE_API int sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg); /* ** The interface to the virtual-table mechanism defined above (back up @@ -6152,83 +5515,68 @@ SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_overload_function(sqlite3*, const cha */ /* -** CAPI3REF: A Handle To An Open BLOB {H17800} -** KEYWORDS: {BLOB handle} {BLOB handles} +** CAPI3REF: A Handle To An Open BLOB {F17800} ** ** An instance of this object represents an open BLOB on which -** [sqlite3_blob_open | incremental BLOB I/O] can be performed. -** Objects of this type are created by [sqlite3_blob_open()] -** and destroyed by [sqlite3_blob_close()]. +** incremental I/O can be preformed. +** Objects of this type are created by +** [sqlite3_blob_open()] and destroyed by [sqlite3_blob_close()]. ** The [sqlite3_blob_read()] and [sqlite3_blob_write()] interfaces -** can be used to read or write small subsections of the BLOB. -** The [sqlite3_blob_bytes()] interface returns the size of the BLOB in bytes. +** can be used to read or write small subsections of the blob. +** The [sqlite3_blob_bytes()] interface returns the size of the +** blob in bytes. */ typedef struct sqlite3_blob sqlite3_blob; /* -** CAPI3REF: Open A BLOB For Incremental I/O {H17810} +** CAPI3REF: Open A BLOB For Incremental I/O {F17810} ** -** This interfaces opens a [BLOB handle | handle] to the BLOB located +** This interfaces opens a handle to the blob located ** in row iRow, column zColumn, table zTable in database zDb; -** in other words, the same BLOB that would be selected by: +** in other words, the same blob that would be selected by: ** **
       **     SELECT zColumn FROM zDb.zTable WHERE rowid = iRow;
       ** 
      {END} ** -** If the flags parameter is non-zero, the the BLOB is opened for read -** and write access. If it is zero, the BLOB is opened for read access. +** If the flags parameter is non-zero, the blob is opened for +** read and write access. If it is zero, the blob is opened for read +** access. ** ** Note that the database name is not the filename that contains ** the database but rather the symbolic name of the database that ** is assigned when the database is connected using [ATTACH]. -** For the main database file, the database name is "main". -** For TEMP tables, the database name is "temp". +** For the main database file, the database name is "main". For +** TEMP tables, the database name is "temp". ** -** On success, [SQLITE_OK] is returned and the new [BLOB handle] is written -** to *ppBlob. Otherwise an [error code] is returned and any value written -** to *ppBlob should not be used by the caller. -** This function sets the [database connection] error code and message +** On success, [SQLITE_OK] is returned and the new +** [sqlite3_blob | blob handle] is written to *ppBlob. +** Otherwise an error code is returned and +** any value written to *ppBlob should not be used by the caller. +** This function sets the database-handle error code and message ** accessible via [sqlite3_errcode()] and [sqlite3_errmsg()]. -** -** If the row that a BLOB handle points to is modified by an -** [UPDATE], [DELETE], or by [ON CONFLICT] side-effects -** then the BLOB handle is marked as "expired". -** This is true if any column of the row is changed, even a column -** other than the one the BLOB handle is open on. -** Calls to [sqlite3_blob_read()] and [sqlite3_blob_write()] for -** a expired BLOB handle fail with an return code of [SQLITE_ABORT]. -** Changes written into a BLOB prior to the BLOB expiring are not -** rollback by the expiration of the BLOB. Such changes will eventually -** commit if the transaction continues to completion. -** +** ** INVARIANTS: ** -** {H17813} A successful invocation of the [sqlite3_blob_open(D,B,T,C,R,F,P)] -** interface shall open an [sqlite3_blob] object P on the BLOB -** in column C of the table T in the database B on -** the [database connection] D. +** {F17813} A successful invocation of the [sqlite3_blob_open(D,B,T,C,R,F,P)] +** interface opens an [sqlite3_blob] object P on the blob +** in column C of table T in database B on [database connection] D. ** -** {H17814} A successful invocation of [sqlite3_blob_open(D,...)] shall start -** a new transaction on the [database connection] D if that -** connection is not already in a transaction. +** {F17814} A successful invocation of [sqlite3_blob_open(D,...)] starts +** a new transaction on [database connection] D if that connection +** is not already in a transaction. ** -** {H17816} The [sqlite3_blob_open(D,B,T,C,R,F,P)] interface shall open -** the BLOB for read and write access if and only if the F -** parameter is non-zero. +** {F17816} The [sqlite3_blob_open(D,B,T,C,R,F,P)] interface opens the blob +** for read and write access if and only if the F parameter +** is non-zero. ** -** {H17819} The [sqlite3_blob_open()] interface shall return [SQLITE_OK] on +** {F17819} The [sqlite3_blob_open()] interface returns [SQLITE_OK] on ** success and an appropriate [error code] on failure. ** -** {H17821} If an error occurs during evaluation of [sqlite3_blob_open(D,...)] +** {F17821} If an error occurs during evaluation of [sqlite3_blob_open(D,...)] ** then subsequent calls to [sqlite3_errcode(D)], -** [sqlite3_errmsg(D)], and [sqlite3_errmsg16(D)] shall return -** information appropriate for that error. -** -** {H17824} If any column in the row that a [sqlite3_blob] has open is -** changed by a separate [UPDATE] or [DELETE] statement or by -** an [ON CONFLICT] side effect, then the [sqlite3_blob] shall -** be marked as invalid. +** [sqlite3_errmsg(D)], and [sqlite3_errmsg16(D)] will return +** information approprate for that error. */ SQLITE_API int sqlite3_blob_open( sqlite3*, @@ -6241,19 +5589,18 @@ SQLITE_API int sqlite3_blob_open( ); /* -** CAPI3REF: Close A BLOB Handle {H17830} +** CAPI3REF: Close A BLOB Handle {F17830} ** -** Closes an open [BLOB handle]. +** Close an open [sqlite3_blob | blob handle]. ** ** Closing a BLOB shall cause the current transaction to commit ** if there are no other BLOBs, no pending prepared statements, and the -** database connection is in [autocommit mode]. +** database connection is in autocommit mode. ** If any writes were made to the BLOB, they might be held in cache ** until the close operation if they will fit. {END} -** ** Closing the BLOB often forces the changes ** out to disk and so if any I/O errors occur, they will likely occur -** at the time when the BLOB is closed. {H17833} Any errors that occur during +** at the time when the BLOB is closed. {F17833} Any errors that occur during ** closing are reported as a non-zero return value. ** ** The BLOB is closed unconditionally. Even if this routine returns @@ -6261,156 +5608,139 @@ SQLITE_API int sqlite3_blob_open( ** ** INVARIANTS: ** -** {H17833} The [sqlite3_blob_close(P)] interface closes an [sqlite3_blob] -** object P previously opened using [sqlite3_blob_open()]. +** {F17833} The [sqlite3_blob_close(P)] interface closes an +** [sqlite3_blob] object P previously opened using +** [sqlite3_blob_open()]. ** -** {H17836} Closing an [sqlite3_blob] object using +** {F17836} Closing an [sqlite3_blob] object using ** [sqlite3_blob_close()] shall cause the current transaction to ** commit if there are no other open [sqlite3_blob] objects ** or [prepared statements] on the same [database connection] and -** the database connection is in [autocommit mode]. +** the [database connection] is in +** [sqlite3_get_autocommit | autocommit mode]. ** -** {H17839} The [sqlite3_blob_close(P)] interfaces shall close the +** {F17839} The [sqlite3_blob_close(P)] interfaces closes the ** [sqlite3_blob] object P unconditionally, even if ** [sqlite3_blob_close(P)] returns something other than [SQLITE_OK]. +** */ SQLITE_API int sqlite3_blob_close(sqlite3_blob *); /* -** CAPI3REF: Return The Size Of An Open BLOB {H17840} +** CAPI3REF: Return The Size Of An Open BLOB {F17840} ** -** Returns the size in bytes of the BLOB accessible via the open -** []BLOB handle] in its only argument. +** Return the size in bytes of the blob accessible via the open +** [sqlite3_blob] object in its only argument. ** ** INVARIANTS: ** -** {H17843} The [sqlite3_blob_bytes(P)] interface returns the size +** {F17843} The [sqlite3_blob_bytes(P)] interface returns the size ** in bytes of the BLOB that the [sqlite3_blob] object P ** refers to. */ SQLITE_API int sqlite3_blob_bytes(sqlite3_blob *); /* -** CAPI3REF: Read Data From A BLOB Incrementally {H17850} +** CAPI3REF: Read Data From A BLOB Incrementally {F17850} ** -** This function is used to read data from an open [BLOB handle] into a -** caller-supplied buffer. N bytes of data are copied into buffer Z -** from the open BLOB, starting at offset iOffset. +** This function is used to read data from an open +** [sqlite3_blob | blob-handle] into a caller supplied buffer. +** N bytes of data are copied into buffer +** Z from the open blob, starting at offset iOffset. ** -** If offset iOffset is less than N bytes from the end of the BLOB, +** If offset iOffset is less than N bytes from the end of the blob, ** [SQLITE_ERROR] is returned and no data is read. If N or iOffset is -** less than zero, [SQLITE_ERROR] is returned and no data is read. +** less than zero [SQLITE_ERROR] is returned and no data is read. ** -** An attempt to read from an expired [BLOB handle] fails with an -** error code of [SQLITE_ABORT]. -** -** On success, SQLITE_OK is returned. -** Otherwise, an [error code] or an [extended error code] is returned. +** On success, SQLITE_OK is returned. Otherwise, an +** [error code] or an [extended error code] is returned. ** ** INVARIANTS: ** -** {H17853} A successful invocation of [sqlite3_blob_read(P,Z,N,X)] -** shall reads N bytes of data out of the BLOB referenced by -** [BLOB handle] P beginning at offset X and store those bytes -** into buffer Z. +** {F17853} The [sqlite3_blob_read(P,Z,N,X)] interface reads N bytes +** beginning at offset X from +** the blob that [sqlite3_blob] object P refers to +** and writes those N bytes into buffer Z. ** -** {H17856} In [sqlite3_blob_read(P,Z,N,X)] if the size of the BLOB -** is less than N+X bytes, then the function shall leave the -** Z buffer unchanged and return [SQLITE_ERROR]. +** {F17856} In [sqlite3_blob_read(P,Z,N,X)] if the size of the blob +** is less than N+X bytes, then the function returns [SQLITE_ERROR] +** and nothing is read from the blob. ** -** {H17859} In [sqlite3_blob_read(P,Z,N,X)] if X or N is less than zero -** then the function shall leave the Z buffer unchanged -** and return [SQLITE_ERROR]. +** {F17859} In [sqlite3_blob_read(P,Z,N,X)] if X or N is less than zero +** then the function returns [SQLITE_ERROR] +** and nothing is read from the blob. ** -** {H17862} The [sqlite3_blob_read(P,Z,N,X)] interface shall return [SQLITE_OK] -** if N bytes are successfully read into buffer Z. +** {F17862} The [sqlite3_blob_read(P,Z,N,X)] interface returns [SQLITE_OK] +** if N bytes where successfully read into buffer Z. ** -** {H17863} If the [BLOB handle] P is expired and X and N are within bounds -** then [sqlite3_blob_read(P,Z,N,X)] shall leave the Z buffer -** unchanged and return [SQLITE_ABORT]. -** -** {H17865} If the requested read could not be completed, -** the [sqlite3_blob_read(P,Z,N,X)] interface shall return an +** {F17865} If the requested read could not be completed, +** the [sqlite3_blob_read(P,Z,N,X)] interface returns an ** appropriate [error code] or [extended error code]. ** -** {H17868} If an error occurs during evaluation of [sqlite3_blob_read(P,...)] +** {F17868} If an error occurs during evaluation of [sqlite3_blob_read(P,...)] ** then subsequent calls to [sqlite3_errcode(D)], -** [sqlite3_errmsg(D)], and [sqlite3_errmsg16(D)] shall return -** information appropriate for that error, where D is the -** [database connection] that was used to open the [BLOB handle] P. +** [sqlite3_errmsg(D)], and [sqlite3_errmsg16(D)] will return +** information approprate for that error, where D is the +** database handle that was used to open blob handle P. */ SQLITE_API int sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset); /* -** CAPI3REF: Write Data Into A BLOB Incrementally {H17870} +** CAPI3REF: Write Data Into A BLOB Incrementally {F17870} ** -** This function is used to write data into an open [BLOB handle] from a -** caller-supplied buffer. N bytes of data are copied from the buffer Z -** into the open BLOB, starting at offset iOffset. +** This function is used to write data into an open +** [sqlite3_blob | blob-handle] from a user supplied buffer. +** n bytes of data are copied from the buffer +** pointed to by z into the open blob, starting at offset iOffset. ** -** If the [BLOB handle] passed as the first argument was not opened for -** writing (the flags parameter to [sqlite3_blob_open()] was zero), -** this function returns [SQLITE_READONLY]. +** If the [sqlite3_blob | blob-handle] passed as the first argument +** was not opened for writing (the flags parameter to [sqlite3_blob_open()] +*** was zero), this function returns [SQLITE_READONLY]. ** -** This function may only modify the contents of the BLOB; it is -** not possible to increase the size of a BLOB using this API. -** If offset iOffset is less than N bytes from the end of the BLOB, -** [SQLITE_ERROR] is returned and no data is written. If N is +** This function may only modify the contents of the blob; it is +** not possible to increase the size of a blob using this API. +** If offset iOffset is less than n bytes from the end of the blob, +** [SQLITE_ERROR] is returned and no data is written. If n is ** less than zero [SQLITE_ERROR] is returned and no data is written. ** -** An attempt to write to an expired [BLOB handle] fails with an -** error code of [SQLITE_ABORT]. Writes to the BLOB that occurred -** before the [BLOB handle] expired are not rolled back by the -** expiration of the handle, though of course those changes might -** have been overwritten by the statement that expired the BLOB handle -** or by other independent statements. -** -** On success, SQLITE_OK is returned. -** Otherwise, an [error code] or an [extended error code] is returned. +** On success, SQLITE_OK is returned. Otherwise, an +** [error code] or an [extended error code] is returned. ** ** INVARIANTS: ** -** {H17873} A successful invocation of [sqlite3_blob_write(P,Z,N,X)] -** shall write N bytes of data from buffer Z into the BLOB -** referenced by [BLOB handle] P beginning at offset X into -** the BLOB. +** {F17873} The [sqlite3_blob_write(P,Z,N,X)] interface writes N bytes +** from buffer Z into +** the blob that [sqlite3_blob] object P refers to +** beginning at an offset of X into the blob. ** -** {H17874} In the absence of other overridding changes, the changes -** written to a BLOB by [sqlite3_blob_write()] shall -** remain in effect after the associated [BLOB handle] expires. +** {F17875} The [sqlite3_blob_write(P,Z,N,X)] interface returns +** [SQLITE_READONLY] if the [sqlite3_blob] object P was +** [sqlite3_blob_open | opened] for reading only. ** -** {H17875} If the [BLOB handle] P was opened for reading only then -** an invocation of [sqlite3_blob_write(P,Z,N,X)] shall leave -** the referenced BLOB unchanged and return [SQLITE_READONLY]. +** {F17876} In [sqlite3_blob_write(P,Z,N,X)] if the size of the blob +** is less than N+X bytes, then the function returns [SQLITE_ERROR] +** and nothing is written into the blob. ** -** {H17876} If the size of the BLOB referenced by [BLOB handle] P is -** less than N+X bytes then [sqlite3_blob_write(P,Z,N,X)] shall -** leave the BLOB unchanged and return [SQLITE_ERROR]. +** {F17879} In [sqlite3_blob_write(P,Z,N,X)] if X or N is less than zero +** then the function returns [SQLITE_ERROR] +** and nothing is written into the blob. ** -** {H17877} If the [BLOB handle] P is expired and X and N are within bounds -** then [sqlite3_blob_read(P,Z,N,X)] shall leave the BLOB -** unchanged and return [SQLITE_ABORT]. +** {F17882} The [sqlite3_blob_write(P,Z,N,X)] interface returns [SQLITE_OK] +** if N bytes where successfully written into blob. ** -** {H17879} If X or N are less than zero then [sqlite3_blob_write(P,Z,N,X)] -** shall leave the BLOB referenced by [BLOB handle] P unchanged -** and return [SQLITE_ERROR]. -** -** {H17882} The [sqlite3_blob_write(P,Z,N,X)] interface shall return -** [SQLITE_OK] if N bytes where successfully written into the BLOB. -** -** {H17885} If the requested write could not be completed, -** the [sqlite3_blob_write(P,Z,N,X)] interface shall return an +** {F17885} If the requested write could not be completed, +** the [sqlite3_blob_write(P,Z,N,X)] interface returns an ** appropriate [error code] or [extended error code]. ** -** {H17888} If an error occurs during evaluation of [sqlite3_blob_write(D,...)] +** {F17888} If an error occurs during evaluation of [sqlite3_blob_write(D,...)] ** then subsequent calls to [sqlite3_errcode(D)], -** [sqlite3_errmsg(D)], and [sqlite3_errmsg16(D)] shall return -** information appropriate for that error. +** [sqlite3_errmsg(D)], and [sqlite3_errmsg16(D)] will return +** information approprate for that error. */ SQLITE_API int sqlite3_blob_write(sqlite3_blob *, const void *z, int n, int iOffset); /* -** CAPI3REF: Virtual File System Objects {H11200} +** CAPI3REF: Virtual File System Objects {F11200} ** ** A virtual filesystem (VFS) is an [sqlite3_vfs] object ** that SQLite uses to interact @@ -6419,11 +5749,12 @@ SQLITE_API int sqlite3_blob_write(sqlite3_blob *, const void *z, int n, int iOff ** New VFSes can be registered and existing VFSes can be unregistered. ** The following interfaces are provided. ** -** The sqlite3_vfs_find() interface returns a pointer to a VFS given its name. -** Names are case sensitive. +** The sqlite3_vfs_find() interface returns a pointer to +** a VFS given its name. Names are case sensitive. ** Names are zero-terminated UTF-8 strings. -** If there is no match, a NULL pointer is returned. -** If zVfsName is NULL then the default VFS is returned. +** If there is no match, a NULL +** pointer is returned. If zVfsName is NULL then the default +** VFS is returned. ** ** New VFSes are registered with sqlite3_vfs_register(). ** Each new VFS becomes the default VFS if the makeDflt flag is set. @@ -6433,34 +5764,35 @@ SQLITE_API int sqlite3_blob_write(sqlite3_blob *, const void *z, int n, int iOff ** same name are registered, the behavior is undefined. If a ** VFS is registered with a name that is NULL or an empty string, ** then the behavior is undefined. -** +** ** Unregister a VFS with the sqlite3_vfs_unregister() interface. ** If the default VFS is unregistered, another VFS is chosen as ** the default. The choice for the new VFS is arbitrary. ** ** INVARIANTS: ** -** {H11203} The [sqlite3_vfs_find(N)] interface returns a pointer to the +** {F11203} The [sqlite3_vfs_find(N)] interface returns a pointer to the ** registered [sqlite3_vfs] object whose name exactly matches ** the zero-terminated UTF-8 string N, or it returns NULL if ** there is no match. ** -** {H11206} If the N parameter to [sqlite3_vfs_find(N)] is NULL then +** {F11206} If the N parameter to [sqlite3_vfs_find(N)] is NULL then ** the function returns a pointer to the default [sqlite3_vfs] -** object if there is one, or NULL if there is no default +** object if there is one, or NULL if there is no default ** [sqlite3_vfs] object. ** -** {H11209} The [sqlite3_vfs_register(P,F)] interface registers the +** {F11209} The [sqlite3_vfs_register(P,F)] interface registers the ** well-formed [sqlite3_vfs] object P using the name given ** by the zName field of the object. ** -** {H11212} Using the [sqlite3_vfs_register(P,F)] interface to register +** {F11212} Using the [sqlite3_vfs_register(P,F)] interface to register ** the same [sqlite3_vfs] object multiple times is a harmless no-op. ** -** {H11215} The [sqlite3_vfs_register(P,F)] interface makes the [sqlite3_vfs] -** object P the default [sqlite3_vfs] object if F is non-zero. +** {F11215} The [sqlite3_vfs_register(P,F)] interface makes the +** the [sqlite3_vfs] object P the default [sqlite3_vfs] object +** if F is non-zero. ** -** {H11218} The [sqlite3_vfs_unregister(P)] interface unregisters the +** {F11218} The [sqlite3_vfs_unregister(P)] interface unregisters the ** [sqlite3_vfs] object P so that it is no longer returned by ** subsequent calls to [sqlite3_vfs_find()]. */ @@ -6469,14 +5801,14 @@ SQLITE_API int sqlite3_vfs_register(sqlite3_vfs*, int makeDflt); SQLITE_API int sqlite3_vfs_unregister(sqlite3_vfs*); /* -** CAPI3REF: Mutexes {H17000} +** CAPI3REF: Mutexes {F17000} ** ** The SQLite core uses these routines for thread -** synchronization. Though they are intended for internal +** synchronization. Though they are intended for internal ** use by SQLite, code that links against SQLite is ** permitted to use any of these routines. ** -** The SQLite source code contains multiple implementations +** The SQLite source code contains multiple implementations ** of these mutex routines. An appropriate implementation ** is selected automatically at compile-time. The following ** implementations are available in the SQLite core: @@ -6488,24 +5820,25 @@ SQLITE_API int sqlite3_vfs_unregister(sqlite3_vfs*); **
    • SQLITE_MUTEX_NOOP ** ** -** The SQLITE_MUTEX_NOOP implementation is a set of routines -** that does no real locking and is appropriate for use in +** The SQLITE_MUTEX_NOOP implementation is a set of routines +** that does no real locking and is appropriate for use in ** a single-threaded application. The SQLITE_MUTEX_OS2, ** SQLITE_MUTEX_PTHREAD, and SQLITE_MUTEX_W32 implementations -** are appropriate for use on OS/2, Unix, and Windows. -** +** are appropriate for use on os/2, unix, and windows. +** ** If SQLite is compiled with the SQLITE_MUTEX_APPDEF preprocessor ** macro defined (with "-DSQLITE_MUTEX_APPDEF=1"), then no mutex -** implementation is included with the library. In this case the -** application must supply a custom mutex implementation using the -** [SQLITE_CONFIG_MUTEX] option of the sqlite3_config() function -** before calling sqlite3_initialize() or any other public sqlite3_ -** function that calls sqlite3_initialize(). +** implementation is included with the library. The +** mutex interface routines defined here become external +** references in the SQLite library for which implementations +** must be provided by the application. This facility allows an +** application that links against SQLite to provide its own mutex +** implementation without having to modify the SQLite core. ** -** {H17011} The sqlite3_mutex_alloc() routine allocates a new -** mutex and returns a pointer to it. {H17012} If it returns NULL -** that means that a mutex could not be allocated. {H17013} SQLite -** will unwind its stack and return an error. {H17014} The argument +** {F17011} The sqlite3_mutex_alloc() routine allocates a new +** mutex and returns a pointer to it. {F17012} If it returns NULL +** that means that a mutex could not be allocated. {F17013} SQLite +** will unwind its stack and return an error. {F17014} The argument ** to sqlite3_mutex_alloc() is one of these integer constants: ** **
        @@ -6517,19 +5850,19 @@ SQLITE_API int sqlite3_vfs_unregister(sqlite3_vfs*); **
      • SQLITE_MUTEX_STATIC_PRNG **
      • SQLITE_MUTEX_STATIC_LRU **
      • SQLITE_MUTEX_STATIC_LRU2 -**
      +** {END} ** -** {H17015} The first two constants cause sqlite3_mutex_alloc() to create +** {F17015} The first two constants cause sqlite3_mutex_alloc() to create ** a new mutex. The new mutex is recursive when SQLITE_MUTEX_RECURSIVE ** is used but not necessarily so when SQLITE_MUTEX_FAST is used. {END} ** The mutex implementation does not need to make a distinction ** between SQLITE_MUTEX_RECURSIVE and SQLITE_MUTEX_FAST if it does -** not want to. {H17016} But SQLite will only request a recursive mutex in +** not want to. {F17016} But SQLite will only request a recursive mutex in ** cases where it really needs one. {END} If a faster non-recursive mutex ** implementation is available on the host platform, the mutex subsystem ** might return such a mutex in response to SQLITE_MUTEX_FAST. ** -** {H17017} The other allowed parameters to sqlite3_mutex_alloc() each return +** {F17017} The other allowed parameters to sqlite3_mutex_alloc() each return ** a pointer to a static preexisting mutex. {END} Four static mutexes are ** used by the current version of SQLite. Future versions of SQLite ** may add additional static mutexes. Static mutexes are for internal @@ -6537,47 +5870,43 @@ SQLITE_API int sqlite3_vfs_unregister(sqlite3_vfs*); ** use only the dynamic mutexes returned by SQLITE_MUTEX_FAST or ** SQLITE_MUTEX_RECURSIVE. ** -** {H17018} Note that if one of the dynamic mutex parameters (SQLITE_MUTEX_FAST +** {F17018} Note that if one of the dynamic mutex parameters (SQLITE_MUTEX_FAST ** or SQLITE_MUTEX_RECURSIVE) is used then sqlite3_mutex_alloc() -** returns a different mutex on every call. {H17034} But for the static +** returns a different mutex on every call. {F17034} But for the static ** mutex types, the same mutex is returned on every call that has -** the same type number. +** the same type number. {END} ** -** {H17019} The sqlite3_mutex_free() routine deallocates a previously -** allocated dynamic mutex. {H17020} SQLite is careful to deallocate every -** dynamic mutex that it allocates. {A17021} The dynamic mutexes must not be in -** use when they are deallocated. {A17022} Attempting to deallocate a static -** mutex results in undefined behavior. {H17023} SQLite never deallocates +** {F17019} The sqlite3_mutex_free() routine deallocates a previously +** allocated dynamic mutex. {F17020} SQLite is careful to deallocate every +** dynamic mutex that it allocates. {U17021} The dynamic mutexes must not be in +** use when they are deallocated. {U17022} Attempting to deallocate a static +** mutex results in undefined behavior. {F17023} SQLite never deallocates ** a static mutex. {END} ** ** The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt -** to enter a mutex. {H17024} If another thread is already within the mutex, +** to enter a mutex. {F17024} If another thread is already within the mutex, ** sqlite3_mutex_enter() will block and sqlite3_mutex_try() will return -** SQLITE_BUSY. {H17025} The sqlite3_mutex_try() interface returns [SQLITE_OK] -** upon successful entry. {H17026} Mutexes created using +** SQLITE_BUSY. {F17025} The sqlite3_mutex_try() interface returns SQLITE_OK +** upon successful entry. {F17026} Mutexes created using ** SQLITE_MUTEX_RECURSIVE can be entered multiple times by the same thread. -** {H17027} In such cases the, +** {F17027} In such cases the, ** mutex must be exited an equal number of times before another thread -** can enter. {A17028} If the same thread tries to enter any other +** can enter. {U17028} If the same thread tries to enter any other ** kind of mutex more than once, the behavior is undefined. -** {H17029} SQLite will never exhibit -** such behavior in its own use of mutexes. +** {F17029} SQLite will never exhibit +** such behavior in its own use of mutexes. {END} ** -** Some systems (for example, Windows 95) do not support the operation -** implemented by sqlite3_mutex_try(). On those systems, sqlite3_mutex_try() -** will always return SQLITE_BUSY. {H17030} The SQLite core only ever uses -** sqlite3_mutex_try() as an optimization so this is acceptable behavior. +** Some systems (ex: windows95) do not the operation implemented by +** sqlite3_mutex_try(). On those systems, sqlite3_mutex_try() will +** always return SQLITE_BUSY. {F17030} The SQLite core only ever uses +** sqlite3_mutex_try() as an optimization so this is acceptable behavior. {END} ** -** {H17031} The sqlite3_mutex_leave() routine exits a mutex that was -** previously entered by the same thread. {A17032} The behavior +** {F17031} The sqlite3_mutex_leave() routine exits a mutex that was +** previously entered by the same thread. {U17032} The behavior ** is undefined if the mutex is not currently entered by the -** calling thread or is not currently allocated. {H17033} SQLite will +** calling thread or is not currently allocated. {F17033} SQLite will ** never do either. {END} ** -** If the argument to sqlite3_mutex_enter(), sqlite3_mutex_try(), or -** sqlite3_mutex_leave() is a NULL pointer, then all three routines -** behave as no-ops. -** ** See also: [sqlite3_mutex_held()] and [sqlite3_mutex_notheld()]. */ SQLITE_API sqlite3_mutex *sqlite3_mutex_alloc(int); @@ -6587,110 +5916,44 @@ SQLITE_API int sqlite3_mutex_try(sqlite3_mutex*); SQLITE_API void sqlite3_mutex_leave(sqlite3_mutex*); /* -** CAPI3REF: Mutex Methods Object {H17120} -** EXPERIMENTAL -** -** An instance of this structure defines the low-level routines -** used to allocate and use mutexes. -** -** Usually, the default mutex implementations provided by SQLite are -** sufficient, however the user has the option of substituting a custom -** implementation for specialized deployments or systems for which SQLite -** does not provide a suitable implementation. In this case, the user -** creates and populates an instance of this structure to pass -** to sqlite3_config() along with the [SQLITE_CONFIG_MUTEX] option. -** Additionally, an instance of this structure can be used as an -** output variable when querying the system for the current mutex -** implementation, using the [SQLITE_CONFIG_GETMUTEX] option. -** -** The xMutexInit method defined by this structure is invoked as -** part of system initialization by the sqlite3_initialize() function. -** {H17001} The xMutexInit routine shall be called by SQLite once for each -** effective call to [sqlite3_initialize()]. -** -** The xMutexEnd method defined by this structure is invoked as -** part of system shutdown by the sqlite3_shutdown() function. The -** implementation of this method is expected to release all outstanding -** resources obtained by the mutex methods implementation, especially -** those obtained by the xMutexInit method. {H17003} The xMutexEnd() -** interface shall be invoked once for each call to [sqlite3_shutdown()]. -** -** The remaining seven methods defined by this structure (xMutexAlloc, -** xMutexFree, xMutexEnter, xMutexTry, xMutexLeave, xMutexHeld and -** xMutexNotheld) implement the following interfaces (respectively): -** -**
        -**
      • [sqlite3_mutex_alloc()]
      • -**
      • [sqlite3_mutex_free()]
      • -**
      • [sqlite3_mutex_enter()]
      • -**
      • [sqlite3_mutex_try()]
      • -**
      • [sqlite3_mutex_leave()]
      • -**
      • [sqlite3_mutex_held()]
      • -**
      • [sqlite3_mutex_notheld()]
      • -**
      -** -** The only difference is that the public sqlite3_XXX functions enumerated -** above silently ignore any invocations that pass a NULL pointer instead -** of a valid mutex handle. The implementations of the methods defined -** by this structure are not required to handle this case, the results -** of passing a NULL pointer instead of a valid mutex handle are undefined -** (i.e. it is acceptable to provide an implementation that segfaults if -** it is passed a NULL pointer). -*/ -typedef struct sqlite3_mutex_methods sqlite3_mutex_methods; -struct sqlite3_mutex_methods { - int (*xMutexInit)(void); - int (*xMutexEnd)(void); - sqlite3_mutex *(*xMutexAlloc)(int); - void (*xMutexFree)(sqlite3_mutex *); - void (*xMutexEnter)(sqlite3_mutex *); - int (*xMutexTry)(sqlite3_mutex *); - void (*xMutexLeave)(sqlite3_mutex *); - int (*xMutexHeld)(sqlite3_mutex *); - int (*xMutexNotheld)(sqlite3_mutex *); -}; - -/* -** CAPI3REF: Mutex Verification Routines {H17080} +** CAPI3REF: Mutex Verifcation Routines {F17080} ** ** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routines -** are intended for use inside assert() statements. {H17081} The SQLite core +** are intended for use inside assert() statements. {F17081} The SQLite core ** never uses these routines except inside an assert() and applications -** are advised to follow the lead of the core. {H17082} The core only +** are advised to follow the lead of the core. {F17082} The core only ** provides implementations for these routines when it is compiled -** with the SQLITE_DEBUG flag. {A17087} External mutex implementations +** with the SQLITE_DEBUG flag. {U17087} External mutex implementations ** are only required to provide these routines if SQLITE_DEBUG is ** defined and if NDEBUG is not defined. ** -** {H17083} These routines should return true if the mutex in their argument -** is held or not held, respectively, by the calling thread. +** {F17083} These routines should return true if the mutex in their argument +** is held or not held, respectively, by the calling thread. {END} ** ** {X17084} The implementation is not required to provided versions of these -** routines that actually work. If the implementation does not provide working -** versions of these routines, it should at least provide stubs that always -** return true so that one does not get spurious assertion failures. +** routines that actually work. +** If the implementation does not provide working +** versions of these routines, it should at least provide stubs +** that always return true so that one does not get spurious +** assertion failures. {END} ** -** {H17085} If the argument to sqlite3_mutex_held() is a NULL pointer then +** {F17085} If the argument to sqlite3_mutex_held() is a NULL pointer then ** the routine should return 1. {END} This seems counter-intuitive since ** clearly the mutex cannot be held if it does not exist. But the ** the reason the mutex does not exist is because the build is not ** using mutexes. And we do not want the assert() containing the ** call to sqlite3_mutex_held() to fail, so a non-zero return is -** the appropriate thing to do. {H17086} The sqlite3_mutex_notheld() +** the appropriate thing to do. {F17086} The sqlite3_mutex_notheld() ** interface should also return 1 when given a NULL pointer. */ SQLITE_API int sqlite3_mutex_held(sqlite3_mutex*); SQLITE_API int sqlite3_mutex_notheld(sqlite3_mutex*); /* -** CAPI3REF: Mutex Types {H17001} +** CAPI3REF: Mutex Types {F17001} ** -** The [sqlite3_mutex_alloc()] interface takes a single argument -** which is one of these integer constants. -** -** The set of static mutexes may change from one SQLite release to the -** next. Applications that override the built-in mutex logic must be -** prepared to accommodate additional static mutexes. +** {F17002} The [sqlite3_mutex_alloc()] interface takes a single argument +** which is one of these integer constants. {END} */ #define SQLITE_MUTEX_FAST 0 #define SQLITE_MUTEX_RECURSIVE 1 @@ -6702,24 +5965,24 @@ SQLITE_API int sqlite3_mutex_notheld(sqlite3_mutex*); #define SQLITE_MUTEX_STATIC_LRU2 7 /* lru page list */ /* -** CAPI3REF: Low-Level Control Of Database Files {H11300} +** CAPI3REF: Low-Level Control Of Database Files {F11300} ** -** {H11301} The [sqlite3_file_control()] interface makes a direct call to the +** {F11301} The [sqlite3_file_control()] interface makes a direct call to the ** xFileControl method for the [sqlite3_io_methods] object associated -** with a particular database identified by the second argument. {H11302} The +** with a particular database identified by the second argument. {F11302} The ** name of the database is the name assigned to the database by the ** ATTACH SQL command that opened the -** database. {H11303} To control the main database file, use the name "main" -** or a NULL pointer. {H11304} The third and fourth parameters to this routine +** database. {F11303} To control the main database file, use the name "main" +** or a NULL pointer. {F11304} The third and fourth parameters to this routine ** are passed directly through to the second and third parameters of -** the xFileControl method. {H11305} The return value of the xFileControl +** the xFileControl method. {F11305} The return value of the xFileControl ** method becomes the return value of this routine. ** -** {H11306} If the second parameter (zDbName) does not match the name of any -** open database file, then SQLITE_ERROR is returned. {H11307} This error +** {F11306} If the second parameter (zDbName) does not match the name of any +** open database file, then SQLITE_ERROR is returned. {F11307} This error ** code is not remembered and will not be recalled by [sqlite3_errcode()] -** or [sqlite3_errmsg()]. {A11308} The underlying xFileControl method might -** also return SQLITE_ERROR. {A11309} There is no way to distinguish between +** or [sqlite3_errmsg()]. {U11308} The underlying xFileControl method might +** also return SQLITE_ERROR. {U11309} There is no way to distinguish between ** an incorrect zDbName and an SQLITE_ERROR return from the underlying ** xFileControl method. {END} ** @@ -6728,11 +5991,11 @@ SQLITE_API int sqlite3_mutex_notheld(sqlite3_mutex*); SQLITE_API int sqlite3_file_control(sqlite3*, const char *zDbName, int op, void*); /* -** CAPI3REF: Testing Interface {H11400} +** CAPI3REF: Testing Interface {F11400} ** ** The sqlite3_test_control() interface is used to read out internal ** state of SQLite and to inject faults into SQLite for testing -** purposes. The first parameter is an operation code that determines +** purposes. The first parameter a operation code that determines ** the number, meaning, and operation of all subsequent parameters. ** ** This interface is not for use by applications. It exists solely @@ -6747,228 +6010,25 @@ SQLITE_API int sqlite3_file_control(sqlite3*, const char *zDbName, int op, void* SQLITE_API int sqlite3_test_control(int op, ...); /* -** CAPI3REF: Testing Interface Operation Codes {H11410} +** CAPI3REF: Testing Interface Operation Codes {F11410} ** ** These constants are the valid operation code parameters used ** as the first argument to [sqlite3_test_control()]. ** -** These parameters and their meanings are subject to change +** These parameters and their meansing are subject to change ** without notice. These values are for testing purposes only. ** Applications should not use any of these parameters or the ** [sqlite3_test_control()] interface. */ +#define SQLITE_TESTCTRL_FAULT_CONFIG 1 +#define SQLITE_TESTCTRL_FAULT_FAILURES 2 +#define SQLITE_TESTCTRL_FAULT_BENIGN_FAILURES 3 +#define SQLITE_TESTCTRL_FAULT_PENDING 4 #define SQLITE_TESTCTRL_PRNG_SAVE 5 #define SQLITE_TESTCTRL_PRNG_RESTORE 6 #define SQLITE_TESTCTRL_PRNG_RESET 7 #define SQLITE_TESTCTRL_BITVEC_TEST 8 -#define SQLITE_TESTCTRL_FAULT_INSTALL 9 -#define SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS 10 -/* -** CAPI3REF: SQLite Runtime Status {H17200} -** EXPERIMENTAL -** -** This interface is used to retrieve runtime status information -** about the preformance of SQLite, and optionally to reset various -** highwater marks. The first argument is an integer code for -** the specific parameter to measure. Recognized integer codes -** are of the form [SQLITE_STATUS_MEMORY_USED | SQLITE_STATUS_...]. -** The current value of the parameter is returned into *pCurrent. -** The highest recorded value is returned in *pHighwater. If the -** resetFlag is true, then the highest record value is reset after -** *pHighwater is written. Some parameters do not record the highest -** value. For those parameters -** nothing is written into *pHighwater and the resetFlag is ignored. -** Other parameters record only the highwater mark and not the current -** value. For these latter parameters nothing is written into *pCurrent. -** -** This routine returns SQLITE_OK on success and a non-zero -** [error code] on failure. -** -** This routine is threadsafe but is not atomic. This routine can -** called while other threads are running the same or different SQLite -** interfaces. However the values returned in *pCurrent and -** *pHighwater reflect the status of SQLite at different points in time -** and it is possible that another thread might change the parameter -** in between the times when *pCurrent and *pHighwater are written. -** -** See also: [sqlite3_db_status()] -*/ -SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag); - - -/* -** CAPI3REF: Status Parameters {H17250} -** EXPERIMENTAL -** -** These integer constants designate various run-time status parameters -** that can be returned by [sqlite3_status()]. -** -**
      -**
      SQLITE_STATUS_MEMORY_USED
      -**
      This parameter is the current amount of memory checked out -** using [sqlite3_malloc()], either directly or indirectly. The -** figure includes calls made to [sqlite3_malloc()] by the application -** and internal memory usage by the SQLite library. Scratch memory -** controlled by [SQLITE_CONFIG_SCRATCH] and auxiliary page-cache -** memory controlled by [SQLITE_CONFIG_PAGECACHE] is not included in -** this parameter. The amount returned is the sum of the allocation -** sizes as reported by the xSize method in [sqlite3_mem_methods].
      -** -**
      SQLITE_STATUS_MALLOC_SIZE
      -**
      This parameter records the largest memory allocation request -** handed to [sqlite3_malloc()] or [sqlite3_realloc()] (or their -** internal equivalents). Only the value returned in the -** *pHighwater parameter to [sqlite3_status()] is of interest. -** The value written into the *pCurrent parameter is undefined.
      -** -**
      SQLITE_STATUS_PAGECACHE_USED
      -**
      This parameter returns the number of pages used out of the -** [pagecache memory allocator] that was configured using -** [SQLITE_CONFIG_PAGECACHE]. The -** value returned is in pages, not in bytes.
      -** -**
      SQLITE_STATUS_PAGECACHE_OVERFLOW
      -**
      This parameter returns the number of bytes of page cache -** allocation which could not be statisfied by the [SQLITE_CONFIG_PAGECACHE] -** buffer and where forced to overflow to [sqlite3_malloc()]. The -** returned value includes allocations that overflowed because they -** where too large (they were larger than the "sz" parameter to -** [SQLITE_CONFIG_PAGECACHE]) and allocations that overflowed because -** no space was left in the page cache.
      -** -**
      SQLITE_STATUS_PAGECACHE_SIZE
      -**
      This parameter records the largest memory allocation request -** handed to [pagecache memory allocator]. Only the value returned in the -** *pHighwater parameter to [sqlite3_status()] is of interest. -** The value written into the *pCurrent parameter is undefined.
      -** -**
      SQLITE_STATUS_SCRATCH_USED
      -**
      This parameter returns the number of allocations used out of the -** [scratch memory allocator] configured using -** [SQLITE_CONFIG_SCRATCH]. The value returned is in allocations, not -** in bytes. Since a single thread may only have one scratch allocation -** outstanding at time, this parameter also reports the number of threads -** using scratch memory at the same time.
      -** -**
      SQLITE_STATUS_SCRATCH_OVERFLOW
      -**
      This parameter returns the number of bytes of scratch memory -** allocation which could not be statisfied by the [SQLITE_CONFIG_SCRATCH] -** buffer and where forced to overflow to [sqlite3_malloc()]. The values -** returned include overflows because the requested allocation was too -** larger (that is, because the requested allocation was larger than the -** "sz" parameter to [SQLITE_CONFIG_SCRATCH]) and because no scratch buffer -** slots were available. -**
      -** -**
      SQLITE_STATUS_SCRATCH_SIZE
      -**
      This parameter records the largest memory allocation request -** handed to [scratch memory allocator]. Only the value returned in the -** *pHighwater parameter to [sqlite3_status()] is of interest. -** The value written into the *pCurrent parameter is undefined.
      -** -**
      SQLITE_STATUS_PARSER_STACK
      -**
      This parameter records the deepest parser stack. It is only -** meaningful if SQLite is compiled with [YYTRACKMAXSTACKDEPTH].
      -**
      -** -** New status parameters may be added from time to time. -*/ -#define SQLITE_STATUS_MEMORY_USED 0 -#define SQLITE_STATUS_PAGECACHE_USED 1 -#define SQLITE_STATUS_PAGECACHE_OVERFLOW 2 -#define SQLITE_STATUS_SCRATCH_USED 3 -#define SQLITE_STATUS_SCRATCH_OVERFLOW 4 -#define SQLITE_STATUS_MALLOC_SIZE 5 -#define SQLITE_STATUS_PARSER_STACK 6 -#define SQLITE_STATUS_PAGECACHE_SIZE 7 -#define SQLITE_STATUS_SCRATCH_SIZE 8 - -/* -** CAPI3REF: Database Connection Status {H17500} -** EXPERIMENTAL -** -** This interface is used to retrieve runtime status information -** about a single [database connection]. The first argument is the -** database connection object to be interrogated. The second argument -** is the parameter to interrogate. Currently, the only allowed value -** for the second parameter is [SQLITE_DBSTATUS_LOOKASIDE_USED]. -** Additional options will likely appear in future releases of SQLite. -** -** The current value of the requested parameter is written into *pCur -** and the highest instantaneous value is written into *pHiwtr. If -** the resetFlg is true, then the highest instantaneous value is -** reset back down to the current value. -** -** See also: [sqlite3_status()] and [sqlite3_stmt_status()]. -*/ -SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg); - -/* -** CAPI3REF: Status Parameters for database connections {H17520} -** EXPERIMENTAL -** -** Status verbs for [sqlite3_db_status()]. -** -**
      -**
      SQLITE_DBSTATUS_LOOKASIDE_USED
      -**
      This parameter returns the number of lookaside memory slots currently -** checked out.
      -**
      -*/ -#define SQLITE_DBSTATUS_LOOKASIDE_USED 0 - - -/* -** CAPI3REF: Prepared Statement Status {H17550} -** EXPERIMENTAL -** -** Each prepared statement maintains various -** [SQLITE_STMTSTATUS_SORT | counters] that measure the number -** of times it has performed specific operations. These counters can -** be used to monitor the performance characteristics of the prepared -** statements. For example, if the number of table steps greatly exceeds -** the number of table searches or result rows, that would tend to indicate -** that the prepared statement is using a full table scan rather than -** an index. -** -** This interface is used to retrieve and reset counter values from -** a [prepared statement]. The first argument is the prepared statement -** object to be interrogated. The second argument -** is an integer code for a specific [SQLITE_STMTSTATUS_SORT | counter] -** to be interrogated. -** The current value of the requested counter is returned. -** If the resetFlg is true, then the counter is reset to zero after this -** interface call returns. -** -** See also: [sqlite3_status()] and [sqlite3_db_status()]. -*/ -SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg); - -/* -** CAPI3REF: Status Parameters for prepared statements {H17570} -** EXPERIMENTAL -** -** These preprocessor macros define integer codes that name counter -** values associated with the [sqlite3_stmt_status()] interface. -** The meanings of the various counters are as follows: -** -**
      -**
      SQLITE_STMTSTATUS_FULLSCAN_STEP
      -**
      This is the number of times that SQLite has stepped forward in -** a table as part of a full table scan. Large numbers for this counter -** may indicate opportunities for performance improvement through -** careful use of indices.
      -** -**
      SQLITE_STMTSTATUS_SORT
      -**
      This is the number of sort operations that have occurred. -** A non-zero value in this counter may indicate an opportunity to -** improvement performance through careful use of indices.
      -** -**
      -*/ -#define SQLITE_STMTSTATUS_FULLSCAN_STEP 1 -#define SQLITE_STMTSTATUS_SORT 2 /* ** Undo the hack that converts floating point types to integer for @@ -7001,7 +6061,7 @@ SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_stmt_status(sqlite3_stmt*, int op,int ** This is the header file for the generic hash-table implemenation ** used in SQLite. ** -** $Id: hash.h,v 1.12 2008/10/10 17:41:29 drh Exp $ +** $Id: hash.h,v 1.11 2007/09/04 14:31:47 danielk1977 Exp $ */ #ifndef _SQLITE_HASH_H_ #define _SQLITE_HASH_H_ @@ -7019,13 +6079,14 @@ typedef struct HashElem HashElem; ** this structure opaque. */ struct Hash { - unsigned int copyKey: 1; /* True if copy of key made on insert */ - unsigned int htsize : 31; /* Number of buckets in the hash table */ - unsigned int count; /* Number of entries in this table */ - HashElem *first; /* The first element of the array */ - struct _ht { /* the hash table */ - int count; /* Number of entries with this hash */ - HashElem *chain; /* Pointer to first entry with this hash */ + char keyClass; /* SQLITE_HASH_INT, _POINTER, _STRING, _BINARY */ + char copyKey; /* True if copy of key made on insert */ + int count; /* Number of entries in this table */ + int htsize; /* Number of buckets in the hash table */ + HashElem *first; /* The first element of the array */ + struct _ht { /* the hash table */ + int count; /* Number of entries with this hash */ + HashElem *chain; /* Pointer to first entry with this hash */ } *ht; }; @@ -7041,10 +6102,32 @@ struct HashElem { void *pKey; int nKey; /* Key associated with this element */ }; +/* +** There are 4 different modes of operation for a hash table: +** +** SQLITE_HASH_INT nKey is used as the key and pKey is ignored. +** +** SQLITE_HASH_POINTER pKey is used as the key and nKey is ignored. +** +** SQLITE_HASH_STRING pKey points to a string that is nKey bytes long +** (including the null-terminator, if any). Case +** is ignored in comparisons. +** +** SQLITE_HASH_BINARY pKey points to binary data nKey bytes long. +** memcmp() is used to compare keys. +** +** A copy of the key is made for SQLITE_HASH_STRING and SQLITE_HASH_BINARY +** if the copyKey parameter to HashInit is 1. +*/ +/* #define SQLITE_HASH_INT 1 // NOT USED */ +/* #define SQLITE_HASH_POINTER 2 // NOT USED */ +#define SQLITE_HASH_STRING 3 +#define SQLITE_HASH_BINARY 4 + /* ** Access routines. To delete, insert a NULL pointer. */ -SQLITE_PRIVATE void sqlite3HashInit(Hash*, int copyKey); +SQLITE_PRIVATE void sqlite3HashInit(Hash*, int keytype, int copyKey); SQLITE_PRIVATE void *sqlite3HashInsert(Hash*, const void *pKey, int nKey, void *pData); SQLITE_PRIVATE void *sqlite3HashFind(const Hash*, const void *pKey, int nKey); SQLITE_PRIVATE HashElem *sqlite3HashFindElem(const Hash*, const void *pKey, int nKey); @@ -7193,39 +6276,39 @@ SQLITE_PRIVATE void sqlite3HashClear(Hash*); #define TK_DOT 112 #define TK_FROM 113 #define TK_JOIN 114 -#define TK_INDEXED 115 -#define TK_BY 116 -#define TK_USING 117 -#define TK_ORDER 118 -#define TK_GROUP 119 -#define TK_HAVING 120 -#define TK_LIMIT 121 -#define TK_WHERE 122 -#define TK_INTO 123 -#define TK_VALUES 124 -#define TK_INTEGER 125 -#define TK_FLOAT 126 -#define TK_BLOB 127 -#define TK_REGISTER 128 -#define TK_VARIABLE 129 -#define TK_CASE 130 -#define TK_WHEN 131 -#define TK_THEN 132 -#define TK_ELSE 133 -#define TK_INDEX 134 -#define TK_ALTER 135 -#define TK_TO 136 -#define TK_ADD 137 -#define TK_COLUMNKW 138 -#define TK_TO_TEXT 139 -#define TK_TO_BLOB 140 -#define TK_TO_NUMERIC 141 -#define TK_TO_INT 142 -#define TK_TO_REAL 143 -#define TK_END_OF_FILE 144 -#define TK_ILLEGAL 145 -#define TK_SPACE 146 -#define TK_UNCLOSED_STRING 147 +#define TK_USING 115 +#define TK_ORDER 116 +#define TK_BY 117 +#define TK_GROUP 118 +#define TK_HAVING 119 +#define TK_LIMIT 120 +#define TK_WHERE 121 +#define TK_INTO 122 +#define TK_VALUES 123 +#define TK_INTEGER 124 +#define TK_FLOAT 125 +#define TK_BLOB 126 +#define TK_REGISTER 127 +#define TK_VARIABLE 128 +#define TK_CASE 129 +#define TK_WHEN 130 +#define TK_THEN 131 +#define TK_ELSE 132 +#define TK_INDEX 133 +#define TK_ALTER 134 +#define TK_TO 135 +#define TK_ADD 136 +#define TK_COLUMNKW 137 +#define TK_TO_TEXT 138 +#define TK_TO_BLOB 139 +#define TK_TO_NUMERIC 140 +#define TK_TO_INT 141 +#define TK_TO_REAL 142 +#define TK_END_OF_FILE 143 +#define TK_ILLEGAL 144 +#define TK_SPACE 145 +#define TK_UNCLOSED_STRING 146 +#define TK_COMMENT 147 #define TK_FUNCTION 148 #define TK_COLUMN 149 #define TK_AGG_FUNCTION 150 @@ -7295,11 +6378,11 @@ SQLITE_PRIVATE void sqlite3HashClear(Hash*); #endif /* -** Provide a default value for SQLITE_TEMP_STORE in case it is not specified +** Provide a default value for TEMP_STORE in case it is not specified ** on the command-line */ -#ifndef SQLITE_TEMP_STORE -# define SQLITE_TEMP_STORE 1 +#ifndef TEMP_STORE +# define TEMP_STORE 1 #endif /* @@ -7371,7 +6454,7 @@ typedef UINT32_TYPE u32; /* 4-byte unsigned integer */ typedef UINT16_TYPE u16; /* 2-byte unsigned integer */ typedef INT16_TYPE i16; /* 2-byte signed integer */ typedef UINT8_TYPE u8; /* 1-byte unsigned integer */ -typedef INT8_TYPE i8; /* 1-byte signed integer */ +typedef UINT8_TYPE i8; /* 1-byte signed integer */ /* ** Macros to determine whether the machine is big or little endian, @@ -7382,8 +6465,7 @@ SQLITE_PRIVATE const int sqlite3one; #else SQLITE_PRIVATE const int sqlite3one; #endif -#if defined(i386) || defined(__i386__) || defined(_M_IX86)\ - || defined(__x86_64) || defined(__x86_64__) +#if defined(i386) || defined(__i386__) || defined(_M_IX86) # define SQLITE_BIGENDIAN 0 # define SQLITE_LITTLEENDIAN 1 # define SQLITE_UTF16NATIVE SQLITE_UTF16LE @@ -7441,38 +6523,6 @@ struct BusyHandler { */ #define ArraySize(X) (sizeof(X)/sizeof(X[0])) -/* -** The following value as a destructor means to use sqlite3DbFree(). -** This is an internal extension to SQLITE_STATIC and SQLITE_TRANSIENT. -*/ -#define SQLITE_DYNAMIC ((sqlite3_destructor_type)sqlite3DbFree) - -/* -** When SQLITE_OMIT_WSD is defined, it means that the target platform does -** not support Writable Static Data (WSD) such as global and static variables. -** All variables must either be on the stack or dynamically allocated from -** the heap. When WSD is unsupported, the variable declarations scattered -** throughout the SQLite code must become constants instead. The SQLITE_WSD -** macro is used for this purpose. And instead of referencing the variable -** directly, we use its constant as a key to lookup the run-time allocated -** buffer that holds real variable. The constant is also the initializer -** for the run-time allocated buffer. -** -** In the usually case where WSD is supported, the SQLITE_WSD and GLOBAL -** macros become no-ops and have zero performance impact. -*/ -#ifdef SQLITE_OMIT_WSD - #define SQLITE_WSD const - #define GLOBAL(t,v) (*(t*)sqlite3_wsd_find((void*)&(v), sizeof(v))) - #define sqlite3GlobalConfig GLOBAL(struct Sqlite3Config, sqlite3Config) -SQLITE_API int sqlite3_wsd_init(int N, int J); -SQLITE_API void *sqlite3_wsd_find(void *K, int L); -#else - #define SQLITE_WSD - #define GLOBAL(t,v) v - #define sqlite3GlobalConfig sqlite3Config -#endif - /* ** Forward references to structures */ @@ -7487,13 +6537,10 @@ typedef struct Expr Expr; typedef struct ExprList ExprList; typedef struct FKey FKey; typedef struct FuncDef FuncDef; -typedef struct FuncDefHash FuncDefHash; typedef struct IdList IdList; typedef struct Index Index; typedef struct KeyClass KeyClass; typedef struct KeyInfo KeyInfo; -typedef struct Lookaside Lookaside; -typedef struct LookasideSlot LookasideSlot; typedef struct Module Module; typedef struct NameContext NameContext; typedef struct Parse Parse; @@ -7506,8 +6553,6 @@ typedef struct Token Token; typedef struct TriggerStack TriggerStack; typedef struct TriggerStep TriggerStep; typedef struct Trigger Trigger; -typedef struct UnpackedRecord UnpackedRecord; -typedef struct Walker Walker; typedef struct WhereInfo WhereInfo; typedef struct WhereLevel WhereLevel; @@ -7533,7 +6578,7 @@ typedef struct WhereLevel WhereLevel; ** subsystem. See comments in the source code for a detailed description ** of what each interface routine does. ** -** @(#) $Id: btree.h,v 1.104 2008/10/08 17:58:49 danielk1977 Exp $ +** @(#) $Id: btree.h,v 1.98 2008/04/26 13:39:47 drh Exp $ */ #ifndef _BTREE_H_ #define _BTREE_H_ @@ -7596,6 +6641,11 @@ SQLITE_PRIVATE int sqlite3BtreeOpen( #define BTREE_READWRITE 16 /* Open for both reading and writing */ #define BTREE_CREATE 32 /* Create the database if it does not exist */ +/* Additional values for the 4th argument of sqlite3BtreeOpen that +** are not associated with PAGER_ values. +*/ +#define BTREE_PRIVATE 64 /* Never share with other connections */ + SQLITE_PRIVATE int sqlite3BtreeClose(Btree*); SQLITE_PRIVATE int sqlite3BtreeSetCacheSize(Btree*,int); SQLITE_PRIVATE int sqlite3BtreeSetSafetyLevel(Btree*,int,int); @@ -7642,6 +6692,8 @@ SQLITE_PRIVATE int sqlite3BtreeGetMeta(Btree*, int idx, u32 *pValue); SQLITE_PRIVATE int sqlite3BtreeUpdateMeta(Btree*, int idx, u32 value); SQLITE_PRIVATE void sqlite3BtreeTripAllCursors(Btree*, int); +struct UnpackedRecord; /* Forward declaration. Definition in vdbeaux.c. */ + SQLITE_PRIVATE int sqlite3BtreeCursor( Btree*, /* BTree containing table to open */ int iTable, /* Index of root page */ @@ -7655,18 +6707,11 @@ SQLITE_PRIVATE int sqlite3BtreeCloseCursor(BtCursor*); SQLITE_PRIVATE int sqlite3BtreeMoveto( BtCursor*, const void *pKey, + struct UnpackedRecord *pUnKey, i64 nKey, int bias, int *pRes ); -SQLITE_PRIVATE int sqlite3BtreeMovetoUnpacked( - BtCursor*, - UnpackedRecord *pUnKey, - i64 intKey, - int bias, - int *pRes -); -SQLITE_PRIVATE int sqlite3BtreeCursorHasMoved(BtCursor*, int*); SQLITE_PRIVATE int sqlite3BtreeDelete(BtCursor*); SQLITE_PRIVATE int sqlite3BtreeInsert(BtCursor*, const void *pKey, i64 nKey, const void *pData, int nData, @@ -7690,11 +6735,11 @@ SQLITE_PRIVATE struct Pager *sqlite3BtreePager(Btree*); SQLITE_PRIVATE int sqlite3BtreePutData(BtCursor*, u32 offset, u32 amt, void*); SQLITE_PRIVATE void sqlite3BtreeCacheOverflow(BtCursor *); -SQLITE_PRIVATE void sqlite3BtreeClearCursor(BtCursor *); #ifdef SQLITE_TEST SQLITE_PRIVATE int sqlite3BtreeCursorInfo(BtCursor*, int*, int); SQLITE_PRIVATE void sqlite3BtreeCursorList(Btree*); +SQLITE_PRIVATE int sqlite3BtreePageDump(Btree*, int, int recursive); #endif /* @@ -7705,36 +6750,24 @@ SQLITE_PRIVATE void sqlite3BtreeCursorList(Btree*); #if !defined(SQLITE_OMIT_SHARED_CACHE) && SQLITE_THREADSAFE SQLITE_PRIVATE void sqlite3BtreeEnter(Btree*); SQLITE_PRIVATE void sqlite3BtreeLeave(Btree*); -#ifndef NDEBUG - /* This routine is used inside assert() statements only. */ SQLITE_PRIVATE int sqlite3BtreeHoldsMutex(Btree*); -#endif SQLITE_PRIVATE void sqlite3BtreeEnterCursor(BtCursor*); SQLITE_PRIVATE void sqlite3BtreeLeaveCursor(BtCursor*); SQLITE_PRIVATE void sqlite3BtreeEnterAll(sqlite3*); SQLITE_PRIVATE void sqlite3BtreeLeaveAll(sqlite3*); -#ifndef NDEBUG - /* This routine is used inside assert() statements only. */ SQLITE_PRIVATE int sqlite3BtreeHoldsAllMutexes(sqlite3*); -#endif SQLITE_PRIVATE void sqlite3BtreeMutexArrayEnter(BtreeMutexArray*); SQLITE_PRIVATE void sqlite3BtreeMutexArrayLeave(BtreeMutexArray*); SQLITE_PRIVATE void sqlite3BtreeMutexArrayInsert(BtreeMutexArray*, Btree*); #else # define sqlite3BtreeEnter(X) # define sqlite3BtreeLeave(X) -#ifndef NDEBUG - /* This routine is used inside assert() statements only. */ # define sqlite3BtreeHoldsMutex(X) 1 -#endif # define sqlite3BtreeEnterCursor(X) # define sqlite3BtreeLeaveCursor(X) # define sqlite3BtreeEnterAll(X) # define sqlite3BtreeLeaveAll(X) -#ifndef NDEBUG - /* This routine is used inside assert() statements only. */ # define sqlite3BtreeHoldsAllMutexes(X) 1 -#endif # define sqlite3BtreeMutexArrayEnter(X) # define sqlite3BtreeMutexArrayLeave(X) # define sqlite3BtreeMutexArrayInsert(X,Y) @@ -7764,7 +6797,7 @@ SQLITE_PRIVATE void sqlite3BtreeMutexArrayInsert(BtreeMutexArray*, Btree*); ** or VDBE. The VDBE implements an abstract machine that runs a ** simple program to access and modify the underlying database. ** -** $Id: vdbe.h,v 1.138 2008/08/20 22:06:48 drh Exp $ +** $Id: vdbe.h,v 1.131 2008/05/01 17:03:49 drh Exp $ */ #ifndef _SQLITE_VDBE_H_ #define _SQLITE_VDBE_H_ @@ -7782,6 +6815,7 @@ typedef struct Vdbe Vdbe; */ typedef struct VdbeFunc VdbeFunc; typedef struct Mem Mem; +typedef struct UnpackedRecord UnpackedRecord; /* ** A single instruction of the virtual machine has an opcode @@ -7808,14 +6842,13 @@ struct VdbeOp { Mem *pMem; /* Used when p4type is P4_MEM */ sqlite3_vtab *pVtab; /* Used when p4type is P4_VTAB */ KeyInfo *pKeyInfo; /* Used when p4type is P4_KEYINFO */ - int *ai; /* Used when p4type is P4_INTARRAY */ } p4; #ifdef SQLITE_DEBUG - char *zComment; /* Comment to improve readability */ + char *zComment; /* Comment to improve readability */ #endif #ifdef VDBE_PROFILE - int cnt; /* Number of times this instruction was executed */ - u64 cycles; /* Total time spent executing this instruction */ + int cnt; /* Number of times this instruction was executed */ + long long cycles; /* Total time spend executing this instruction */ #endif }; typedef struct VdbeOp VdbeOp; @@ -7849,7 +6882,6 @@ typedef struct VdbeOpList VdbeOpList; #define P4_REAL (-12) /* P4 is a 64-bit floating point value */ #define P4_INT64 (-13) /* P4 is a 64-bit signed integer */ #define P4_INT32 (-14) /* P4 is a 32-bit signed integer */ -#define P4_INTARRAY (-15) /* P4 is a vector of 32-bit integers */ /* When adding a P4 argument using P4_KEYINFO, a copy of the KeyInfo structure ** is made. That copy is freed when the Vdbe is finalized. But if the @@ -7858,8 +6890,7 @@ typedef struct VdbeOpList VdbeOpList; ** from a single sqliteMalloc(). But no copy is made and the calling ** function should *not* try to free the KeyInfo. */ -#define P4_KEYINFO_HANDOFF (-16) -#define P4_KEYINFO_STATIC (-17) +#define P4_KEYINFO_HANDOFF (-9) /* ** The Vdbe.aColName array contains 5n Mem structures, where n is the @@ -7900,7 +6931,7 @@ typedef struct VdbeOpList VdbeOpList; #define OP_Affinity 2 #define OP_Column 3 #define OP_SetCookie 4 -#define OP_Real 126 /* same as TK_FLOAT */ +#define OP_Real 125 /* same as TK_FLOAT */ #define OP_Sequence 5 #define OP_MoveGt 6 #define OP_Ge 72 /* same as TK_GE */ @@ -7910,7 +6941,7 @@ typedef struct VdbeOpList VdbeOpList; #define OP_OpenWrite 9 #define OP_NotNull 66 /* same as TK_NOTNULL */ #define OP_If 10 -#define OP_ToInt 142 /* same as TK_TO_INT */ +#define OP_ToInt 141 /* same as TK_TO_INT */ #define OP_String8 88 /* same as TK_STRING */ #define OP_VRowid 11 #define OP_CollSeq 12 @@ -7918,121 +6949,121 @@ typedef struct VdbeOpList VdbeOpList; #define OP_Expire 14 #define OP_AutoCommit 15 #define OP_Gt 69 /* same as TK_GT */ -#define OP_Pagecount 17 -#define OP_IntegrityCk 18 -#define OP_Sort 19 -#define OP_Copy 20 -#define OP_Trace 21 -#define OP_Function 22 -#define OP_IfNeg 23 +#define OP_IntegrityCk 17 +#define OP_Sort 18 +#define OP_Copy 19 +#define OP_Trace 20 +#define OP_Function 21 +#define OP_IfNeg 22 #define OP_And 61 /* same as TK_AND */ #define OP_Subtract 79 /* same as TK_MINUS */ -#define OP_Noop 24 -#define OP_Return 25 +#define OP_Noop 23 +#define OP_Return 24 #define OP_Remainder 82 /* same as TK_REM */ -#define OP_NewRowid 26 +#define OP_NewRowid 25 #define OP_Multiply 80 /* same as TK_STAR */ -#define OP_Variable 27 -#define OP_String 28 -#define OP_RealAffinity 29 -#define OP_VRename 30 -#define OP_ParseSchema 31 -#define OP_VOpen 32 -#define OP_Close 33 -#define OP_CreateIndex 34 -#define OP_IsUnique 35 -#define OP_NotFound 36 -#define OP_Int64 37 -#define OP_MustBeInt 38 -#define OP_Halt 39 -#define OP_Rowid 40 -#define OP_IdxLT 41 -#define OP_AddImm 42 -#define OP_Statement 43 -#define OP_RowData 44 -#define OP_MemMax 45 +#define OP_Variable 26 +#define OP_String 27 +#define OP_RealAffinity 28 +#define OP_VRename 29 +#define OP_ParseSchema 30 +#define OP_VOpen 31 +#define OP_Close 32 +#define OP_CreateIndex 33 +#define OP_IsUnique 34 +#define OP_NotFound 35 +#define OP_Int64 36 +#define OP_MustBeInt 37 +#define OP_Halt 38 +#define OP_Rowid 39 +#define OP_IdxLT 40 +#define OP_AddImm 41 +#define OP_Statement 42 +#define OP_RowData 43 +#define OP_MemMax 44 #define OP_Or 60 /* same as TK_OR */ -#define OP_NotExists 46 -#define OP_Gosub 47 +#define OP_NotExists 45 +#define OP_Gosub 46 #define OP_Divide 81 /* same as TK_SLASH */ -#define OP_Integer 48 -#define OP_ToNumeric 141 /* same as TK_TO_NUMERIC*/ -#define OP_Prev 49 +#define OP_Integer 47 +#define OP_ToNumeric 140 /* same as TK_TO_NUMERIC*/ +#define OP_Prev 48 #define OP_Concat 83 /* same as TK_CONCAT */ #define OP_BitAnd 74 /* same as TK_BITAND */ -#define OP_VColumn 50 -#define OP_CreateTable 51 -#define OP_Last 52 +#define OP_VColumn 49 +#define OP_CreateTable 50 +#define OP_Last 51 #define OP_IsNull 65 /* same as TK_ISNULL */ -#define OP_IncrVacuum 53 -#define OP_IdxRowid 54 +#define OP_IncrVacuum 52 +#define OP_IdxRowid 53 #define OP_ShiftRight 77 /* same as TK_RSHIFT */ -#define OP_ResetCount 55 -#define OP_FifoWrite 56 -#define OP_ContextPush 57 -#define OP_Yield 58 -#define OP_DropTrigger 59 -#define OP_DropIndex 62 -#define OP_IdxGE 63 -#define OP_IdxDelete 64 -#define OP_Vacuum 73 -#define OP_MoveLe 84 -#define OP_IfNot 85 -#define OP_DropTable 86 -#define OP_MakeRecord 89 -#define OP_ToBlob 140 /* same as TK_TO_BLOB */ -#define OP_ResultRow 90 -#define OP_Delete 91 -#define OP_AggFinal 92 -#define OP_Compare 93 +#define OP_ResetCount 54 +#define OP_FifoWrite 55 +#define OP_ContextPush 56 +#define OP_DropTrigger 57 +#define OP_DropIndex 58 +#define OP_IdxGE 59 +#define OP_IdxDelete 62 +#define OP_Vacuum 63 +#define OP_MoveLe 64 +#define OP_IfNot 73 +#define OP_DropTable 84 +#define OP_MakeRecord 85 +#define OP_ToBlob 139 /* same as TK_TO_BLOB */ +#define OP_ResultRow 86 +#define OP_Delete 89 +#define OP_AggFinal 90 #define OP_ShiftLeft 76 /* same as TK_LSHIFT */ -#define OP_Goto 94 -#define OP_TableLock 95 -#define OP_FifoRead 96 -#define OP_Clear 97 -#define OP_MoveLt 98 +#define OP_Goto 91 +#define OP_TableLock 92 +#define OP_FifoRead 93 +#define OP_Clear 94 +#define OP_MoveLt 95 #define OP_Le 70 /* same as TK_LE */ -#define OP_VerifyCookie 99 -#define OP_AggStep 100 -#define OP_ToText 139 /* same as TK_TO_TEXT */ +#define OP_VerifyCookie 96 +#define OP_AggStep 97 +#define OP_ToText 138 /* same as TK_TO_TEXT */ #define OP_Not 16 /* same as TK_NOT */ -#define OP_ToReal 143 /* same as TK_TO_REAL */ -#define OP_SetNumColumns 101 -#define OP_Transaction 102 -#define OP_VFilter 103 +#define OP_ToReal 142 /* same as TK_TO_REAL */ +#define OP_SetNumColumns 98 +#define OP_Transaction 99 +#define OP_VFilter 100 #define OP_Ne 67 /* same as TK_NE */ -#define OP_VDestroy 104 -#define OP_ContextPop 105 +#define OP_VDestroy 101 +#define OP_ContextPop 102 #define OP_BitOr 75 /* same as TK_BITOR */ -#define OP_Next 106 -#define OP_IdxInsert 107 +#define OP_Next 103 +#define OP_IdxInsert 104 #define OP_Lt 71 /* same as TK_LT */ -#define OP_Insert 108 -#define OP_Destroy 109 -#define OP_ReadCookie 110 -#define OP_ForceInt 111 -#define OP_LoadAnalysis 112 -#define OP_Explain 113 -#define OP_OpenPseudo 114 -#define OP_OpenEphemeral 115 -#define OP_Null 116 -#define OP_Move 117 -#define OP_Blob 118 +#define OP_Insert 105 +#define OP_Destroy 106 +#define OP_ReadCookie 107 +#define OP_ForceInt 108 +#define OP_LoadAnalysis 109 +#define OP_Explain 110 +#define OP_OpenPseudo 111 +#define OP_OpenEphemeral 112 +#define OP_Null 113 +#define OP_Move 114 +#define OP_Blob 115 #define OP_Add 78 /* same as TK_PLUS */ -#define OP_Rewind 119 -#define OP_MoveGe 120 -#define OP_VBegin 121 -#define OP_VUpdate 122 -#define OP_IfZero 123 +#define OP_Rewind 116 +#define OP_MoveGe 117 +#define OP_VBegin 118 +#define OP_VUpdate 119 +#define OP_IfZero 120 #define OP_BitNot 87 /* same as TK_BITNOT */ -#define OP_VCreate 124 -#define OP_Found 125 -#define OP_IfPos 127 -#define OP_NullRow 128 -#define OP_Jump 129 -#define OP_Permutation 130 +#define OP_VCreate 121 +#define OP_Found 122 +#define OP_IfPos 123 +#define OP_NullRow 124 /* The following opcode values are never used */ +#define OP_NotUsed_126 126 +#define OP_NotUsed_127 127 +#define OP_NotUsed_128 128 +#define OP_NotUsed_129 129 +#define OP_NotUsed_130 130 #define OP_NotUsed_131 131 #define OP_NotUsed_132 132 #define OP_NotUsed_133 133 @@ -8040,7 +7071,6 @@ typedef struct VdbeOpList VdbeOpList; #define OP_NotUsed_135 135 #define OP_NotUsed_136 136 #define OP_NotUsed_137 137 -#define OP_NotUsed_138 138 /* Properties such as "out2" or "jump" that are specified in @@ -8056,23 +7086,22 @@ typedef struct VdbeOpList VdbeOpList; #define OPFLG_INITIALIZER {\ /* 0 */ 0x00, 0x01, 0x00, 0x00, 0x10, 0x02, 0x11, 0x00,\ /* 8 */ 0x00, 0x00, 0x05, 0x02, 0x00, 0x00, 0x00, 0x00,\ -/* 16 */ 0x04, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x05,\ -/* 24 */ 0x00, 0x04, 0x02, 0x02, 0x02, 0x04, 0x00, 0x00,\ -/* 32 */ 0x00, 0x00, 0x02, 0x11, 0x11, 0x02, 0x05, 0x00,\ -/* 40 */ 0x02, 0x11, 0x04, 0x00, 0x00, 0x0c, 0x11, 0x01,\ -/* 48 */ 0x02, 0x01, 0x00, 0x02, 0x01, 0x01, 0x02, 0x00,\ -/* 56 */ 0x04, 0x00, 0x00, 0x00, 0x2c, 0x2c, 0x00, 0x11,\ -/* 64 */ 0x00, 0x05, 0x05, 0x15, 0x15, 0x15, 0x15, 0x15,\ -/* 72 */ 0x15, 0x00, 0x2c, 0x2c, 0x2c, 0x2c, 0x2c, 0x2c,\ -/* 80 */ 0x2c, 0x2c, 0x2c, 0x2c, 0x11, 0x05, 0x00, 0x04,\ -/* 88 */ 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,\ -/* 96 */ 0x01, 0x00, 0x11, 0x00, 0x00, 0x00, 0x00, 0x01,\ -/* 104 */ 0x00, 0x00, 0x01, 0x08, 0x00, 0x02, 0x02, 0x05,\ -/* 112 */ 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x02, 0x01,\ -/* 120 */ 0x11, 0x00, 0x00, 0x05, 0x00, 0x11, 0x02, 0x05,\ -/* 128 */ 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ -/* 136 */ 0x00, 0x00, 0x00, 0x04, 0x04, 0x04, 0x04, 0x04,\ -} +/* 16 */ 0x04, 0x00, 0x01, 0x00, 0x00, 0x00, 0x05, 0x00,\ +/* 24 */ 0x00, 0x02, 0x02, 0x02, 0x04, 0x00, 0x00, 0x00,\ +/* 32 */ 0x00, 0x02, 0x11, 0x11, 0x02, 0x05, 0x00, 0x02,\ +/* 40 */ 0x11, 0x04, 0x00, 0x00, 0x0c, 0x11, 0x01, 0x02,\ +/* 48 */ 0x01, 0x00, 0x02, 0x01, 0x01, 0x02, 0x00, 0x04,\ +/* 56 */ 0x00, 0x00, 0x00, 0x11, 0x2c, 0x2c, 0x00, 0x00,\ +/* 64 */ 0x11, 0x05, 0x05, 0x15, 0x15, 0x15, 0x15, 0x15,\ +/* 72 */ 0x15, 0x05, 0x2c, 0x2c, 0x2c, 0x2c, 0x2c, 0x2c,\ +/* 80 */ 0x2c, 0x2c, 0x2c, 0x2c, 0x00, 0x00, 0x00, 0x04,\ +/* 88 */ 0x02, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x11,\ +/* 96 */ 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01,\ +/* 104 */ 0x08, 0x00, 0x02, 0x02, 0x05, 0x00, 0x00, 0x00,\ +/* 112 */ 0x00, 0x02, 0x00, 0x02, 0x01, 0x11, 0x00, 0x00,\ +/* 120 */ 0x05, 0x00, 0x11, 0x05, 0x00, 0x02, 0x00, 0x00,\ +/* 128 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ +/* 136 */ 0x00, 0x00, 0x04, 0x04, 0x04, 0x04, 0x04,} /************** End of opcodes.h *********************************************/ /************** Continuing where we left off in vdbe.h ***********************/ @@ -8107,7 +7136,7 @@ SQLITE_PRIVATE int sqlite3VdbeCurrentAddr(Vdbe*); SQLITE_PRIVATE void sqlite3VdbeTrace(Vdbe*,FILE*); #endif SQLITE_PRIVATE void sqlite3VdbeResetStepResult(Vdbe*); -SQLITE_PRIVATE int sqlite3VdbeReset(Vdbe*); +SQLITE_PRIVATE int sqlite3VdbeReset(Vdbe*, int); SQLITE_PRIVATE void sqlite3VdbeSetNumCols(Vdbe*,int); SQLITE_PRIVATE int sqlite3VdbeSetColName(Vdbe*, int, int, const char *, int); SQLITE_PRIVATE void sqlite3VdbeCountChanges(Vdbe*); @@ -8118,8 +7147,7 @@ SQLITE_PRIVATE void sqlite3VdbeSwap(Vdbe*,Vdbe*); #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT SQLITE_PRIVATE int sqlite3VdbeReleaseMemory(int); #endif -SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeRecordUnpack(KeyInfo*,int,const void*, - UnpackedRecord*,int); +SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeRecordUnpack(KeyInfo*,int,const void*,void*,int); SQLITE_PRIVATE void sqlite3VdbeDeleteUnpackedRecord(UnpackedRecord*); SQLITE_PRIVATE int sqlite3VdbeRecordCompare(int,const void*,UnpackedRecord*); @@ -8127,11 +7155,8 @@ SQLITE_PRIVATE int sqlite3VdbeRecordCompare(int,const void*,UnpackedRecord*); #ifndef NDEBUG SQLITE_PRIVATE void sqlite3VdbeComment(Vdbe*, const char*, ...); # define VdbeComment(X) sqlite3VdbeComment X -SQLITE_PRIVATE void sqlite3VdbeNoopComment(Vdbe*, const char*, ...); -# define VdbeNoopComment(X) sqlite3VdbeNoopComment X #else # define VdbeComment(X) -# define VdbeNoopComment(X) #endif #endif @@ -8155,25 +7180,17 @@ SQLITE_PRIVATE void sqlite3VdbeNoopComment(Vdbe*, const char*, ...); ** subsystem. The page cache subsystem reads and writes a file a page ** at a time and provides a journal for rollback. ** -** @(#) $Id: pager.h,v 1.85 2008/09/29 11:49:48 danielk1977 Exp $ +** @(#) $Id: pager.h,v 1.72 2008/05/01 17:03:49 drh Exp $ */ #ifndef _PAGER_H_ #define _PAGER_H_ -/* -** If defined as non-zero, auto-vacuum is enabled by default. Otherwise -** it must be turned on for each database using "PRAGMA auto_vacuum = 1". -*/ -#ifndef SQLITE_DEFAULT_JOURNAL_SIZE_LIMIT - #define SQLITE_DEFAULT_JOURNAL_SIZE_LIMIT -1 -#endif - /* ** The type used to represent a page number. The first page in a file ** is called page 1. 0 is used to represent "not a page". */ -typedef u32 Pgno; +typedef unsigned int Pgno; /* ** Each open file is managed by a separate instance of the "Pager" structure. @@ -8207,7 +7224,6 @@ typedef struct PgHdr DbPage; #define PAGER_JOURNALMODE_DELETE 0 /* Commit by deleting journal file */ #define PAGER_JOURNALMODE_PERSIST 1 /* Commit by zeroing journal header */ #define PAGER_JOURNALMODE_OFF 2 /* Journal omitted. */ -#define PAGER_JOURNALMODE_TRUNCATE 3 /* Commit by truncating journal */ /* ** See source code comments for a detailed description of the following @@ -8215,7 +7231,8 @@ typedef struct PgHdr DbPage; */ SQLITE_PRIVATE int sqlite3PagerOpen(sqlite3_vfs *, Pager **ppPager, const char*, int,int,int); SQLITE_PRIVATE void sqlite3PagerSetBusyhandler(Pager*, BusyHandler *pBusyHandler); -SQLITE_PRIVATE void sqlite3PagerSetReiniter(Pager*, void(*)(DbPage*)); +SQLITE_PRIVATE void sqlite3PagerSetDestructor(Pager*, void(*)(DbPage*,int)); +SQLITE_PRIVATE void sqlite3PagerSetReiniter(Pager*, void(*)(DbPage*,int)); SQLITE_PRIVATE int sqlite3PagerSetPagesize(Pager*, u16*); SQLITE_PRIVATE int sqlite3PagerMaxPageCount(Pager*, int); SQLITE_PRIVATE int sqlite3PagerReadFileheader(Pager*, int, unsigned char*); @@ -8224,11 +7241,10 @@ SQLITE_PRIVATE int sqlite3PagerClose(Pager *pPager); SQLITE_PRIVATE int sqlite3PagerAcquire(Pager *pPager, Pgno pgno, DbPage **ppPage, int clrFlag); #define sqlite3PagerGet(A,B,C) sqlite3PagerAcquire(A,B,C,0) SQLITE_PRIVATE DbPage *sqlite3PagerLookup(Pager *pPager, Pgno pgno); -SQLITE_PRIVATE int sqlite3PagerPageRefcount(DbPage*); SQLITE_PRIVATE int sqlite3PagerRef(DbPage*); SQLITE_PRIVATE int sqlite3PagerUnref(DbPage*); SQLITE_PRIVATE int sqlite3PagerWrite(DbPage*); -SQLITE_PRIVATE int sqlite3PagerPagecount(Pager*, int*); +SQLITE_PRIVATE int sqlite3PagerPagecount(Pager*); SQLITE_PRIVATE int sqlite3PagerTruncate(Pager*,Pgno); SQLITE_PRIVATE int sqlite3PagerBegin(DbPage*, int exFlag); SQLITE_PRIVATE int sqlite3PagerCommitPhaseOne(Pager*,const char *zMaster, Pgno, int); @@ -8239,7 +7255,7 @@ SQLITE_PRIVATE int sqlite3PagerStmtBegin(Pager*); SQLITE_PRIVATE int sqlite3PagerStmtCommit(Pager*); SQLITE_PRIVATE int sqlite3PagerStmtRollback(Pager*); SQLITE_PRIVATE void sqlite3PagerDontRollback(DbPage*); -SQLITE_PRIVATE int sqlite3PagerDontWrite(DbPage*); +SQLITE_PRIVATE void sqlite3PagerDontWrite(DbPage*); SQLITE_PRIVATE int sqlite3PagerRefcount(Pager*); SQLITE_PRIVATE void sqlite3PagerSetSafetyLevel(Pager*,int,int); SQLITE_PRIVATE const char *sqlite3PagerFilename(Pager*); @@ -8248,15 +7264,18 @@ SQLITE_PRIVATE sqlite3_file *sqlite3PagerFile(Pager*); SQLITE_PRIVATE const char *sqlite3PagerDirname(Pager*); SQLITE_PRIVATE const char *sqlite3PagerJournalname(Pager*); SQLITE_PRIVATE int sqlite3PagerNosync(Pager*); -SQLITE_PRIVATE int sqlite3PagerMovepage(Pager*,DbPage*,Pgno,int); +SQLITE_PRIVATE int sqlite3PagerMovepage(Pager*,DbPage*,Pgno); SQLITE_PRIVATE void *sqlite3PagerGetData(DbPage *); SQLITE_PRIVATE void *sqlite3PagerGetExtra(DbPage *); SQLITE_PRIVATE int sqlite3PagerLockingMode(Pager *, int); SQLITE_PRIVATE int sqlite3PagerJournalMode(Pager *, int); -SQLITE_PRIVATE i64 sqlite3PagerJournalSizeLimit(Pager *, i64); SQLITE_PRIVATE void *sqlite3PagerTempSpace(Pager*); SQLITE_PRIVATE int sqlite3PagerSync(Pager *pPager); +#if defined(SQLITE_ENABLE_MEMORY_MANAGEMENT) && !defined(SQLITE_OMIT_DISKIO) +SQLITE_PRIVATE int sqlite3PagerReleaseMemory(int); +#endif + #ifdef SQLITE_HAS_CODEC SQLITE_PRIVATE void sqlite3PagerSetCodec(Pager*,void*(*)(void*,void*,Pgno,int),void*); #endif @@ -8269,7 +7288,6 @@ SQLITE_PRIVATE int sqlite3PagerIswriteable(DbPage*); #ifdef SQLITE_TEST SQLITE_PRIVATE int *sqlite3PagerStats(Pager*); SQLITE_PRIVATE void sqlite3PagerRefdump(Pager*); -SQLITE_PRIVATE int sqlite3PagerIsMemdb(Pager*); #endif #ifdef SQLITE_TEST @@ -8284,187 +7302,6 @@ void enable_simulated_io_errors(void); /************** End of pager.h ***********************************************/ /************** Continuing where we left off in sqliteInt.h ******************/ -/************** Include pcache.h in the middle of sqliteInt.h ****************/ -/************** Begin file pcache.h ******************************************/ -/* -** 2008 August 05 -** -** The author disclaims copyright to this source code. In place of -** a legal notice, here is a blessing: -** -** May you do good and not evil. -** May you find forgiveness for yourself and forgive others. -** May you share freely, never taking more than you give. -** -************************************************************************* -** This header file defines the interface that the sqlite page cache -** subsystem. -** -** @(#) $Id: pcache.h,v 1.13 2008/10/11 17:42:29 drh Exp $ -*/ - -#ifndef _PCACHE_H_ - -typedef struct PgHdr PgHdr; -typedef struct PCache PCache; - -/* -** Every page in the cache is controlled by an instance of the following -** structure. -*/ -struct PgHdr { - void *pData; /* Content of this page */ - void *pExtra; /* Extra content */ - PgHdr *pDirty; /* Transient list of dirty pages */ - Pgno pgno; /* Page number for this page */ - Pager *pPager; /* The pager this page is part of */ -#ifdef SQLITE_CHECK_PAGES - u32 pageHash; /* Hash of page content */ -#endif - u16 flags; /* PGHDR flags defined below */ - /********************************************************************** - ** Elements above are public. All that follows is private to pcache.c - ** and should not be accessed by other modules. - */ - i16 nRef; /* Number of users of this page */ - PCache *pCache; /* Cache that owns this page */ - void *apSave[2]; /* Journal entries for in-memory databases */ - /********************************************************************** - ** Elements above are accessible at any time by the owner of the cache - ** without the need for a mutex. The elements that follow can only be - ** accessed while holding the SQLITE_MUTEX_STATIC_LRU mutex. - */ - PgHdr *pNextHash, *pPrevHash; /* Hash collision chain for PgHdr.pgno */ - PgHdr *pNext, *pPrev; /* List of clean or dirty pages */ - PgHdr *pNextLru, *pPrevLru; /* Part of global LRU list */ -}; - -/* Bit values for PgHdr.flags */ -#define PGHDR_IN_JOURNAL 0x001 /* Page is in rollback journal */ -#define PGHDR_DIRTY 0x002 /* Page has changed */ -#define PGHDR_NEED_SYNC 0x004 /* Fsync the rollback journal before - ** writing this page to the database */ -#define PGHDR_NEED_READ 0x008 /* Content is unread */ -#define PGHDR_REUSE_UNLIKELY 0x010 /* A hint that reuse is unlikely */ -#define PGHDR_DONT_WRITE 0x020 /* Do not write content to disk */ - -/* Initialize and shutdown the page cache subsystem */ -SQLITE_PRIVATE int sqlite3PcacheInitialize(void); -SQLITE_PRIVATE void sqlite3PcacheShutdown(void); - -/* Page cache buffer management: -** These routines implement SQLITE_CONFIG_PAGECACHE. -*/ -SQLITE_PRIVATE void sqlite3PCacheBufferSetup(void *, int sz, int n); -SQLITE_PRIVATE void *sqlite3PCacheMalloc(int sz); -SQLITE_PRIVATE void sqlite3PCacheFree(void*); - -/* Create a new pager cache. -** Under memory stress, invoke xStress to try to make pages clean. -** Only clean and unpinned pages can be reclaimed. -*/ -SQLITE_PRIVATE void sqlite3PcacheOpen( - int szPage, /* Size of every page */ - int szExtra, /* Extra space associated with each page */ - int bPurgeable, /* True if pages are on backing store */ - int (*xStress)(void*, PgHdr*), /* Call to try to make pages clean */ - void *pStress, /* Argument to xStress */ - PCache *pToInit /* Preallocated space for the PCache */ -); - -/* Modify the page-size after the cache has been created. */ -SQLITE_PRIVATE void sqlite3PcacheSetPageSize(PCache *, int); - -/* Return the size in bytes of a PCache object. Used to preallocate -** storage space. -*/ -SQLITE_PRIVATE int sqlite3PcacheSize(void); - -/* One release per successful fetch. Page is pinned until released. -** Reference counted. -*/ -SQLITE_PRIVATE int sqlite3PcacheFetch(PCache*, Pgno, int createFlag, PgHdr**); -SQLITE_PRIVATE void sqlite3PcacheRelease(PgHdr*); - -SQLITE_PRIVATE void sqlite3PcacheDrop(PgHdr*); /* Remove page from cache */ -SQLITE_PRIVATE void sqlite3PcacheMakeDirty(PgHdr*); /* Make sure page is marked dirty */ -SQLITE_PRIVATE void sqlite3PcacheMakeClean(PgHdr*); /* Mark a single page as clean */ -SQLITE_PRIVATE void sqlite3PcacheCleanAll(PCache*); /* Mark all dirty list pages as clean */ - -/* Change a page number. Used by incr-vacuum. */ -SQLITE_PRIVATE void sqlite3PcacheMove(PgHdr*, Pgno); - -/* Remove all pages with pgno>x. Reset the cache if x==0 */ -SQLITE_PRIVATE void sqlite3PcacheTruncate(PCache*, Pgno x); - -/* Routines used to implement transactions on memory-only databases. */ -SQLITE_PRIVATE int sqlite3PcachePreserve(PgHdr*, int); /* Preserve current page content */ -SQLITE_PRIVATE void sqlite3PcacheCommit(PCache*, int); /* Drop preserved copy */ -SQLITE_PRIVATE void sqlite3PcacheRollback(PCache*, int, void (*xReiniter)(PgHdr*)); - -/* Get a list of all dirty pages in the cache, sorted by page number */ -SQLITE_PRIVATE PgHdr *sqlite3PcacheDirtyList(PCache*); - -/* Reset and close the cache object */ -SQLITE_PRIVATE void sqlite3PcacheClose(PCache*); - -/* Clear flags from pages of the page cache */ -SQLITE_PRIVATE void sqlite3PcacheClearFlags(PCache*, int mask); - -/* Assert flags settings on all pages. Debugging only */ -#ifndef NDEBUG -SQLITE_PRIVATE void sqlite3PcacheAssertFlags(PCache*, int trueMask, int falseMask); -#else -# define sqlite3PcacheAssertFlags(A,B,C) -#endif - -/* Return true if the number of dirty pages is 0 or 1 */ -SQLITE_PRIVATE int sqlite3PcacheZeroOrOneDirtyPages(PCache*); - -/* Discard the contents of the cache */ -SQLITE_PRIVATE int sqlite3PcacheClear(PCache*); - -/* Return the total number of outstanding page references */ -SQLITE_PRIVATE int sqlite3PcacheRefCount(PCache*); - -/* Increment the reference count of an existing page */ -SQLITE_PRIVATE void sqlite3PcacheRef(PgHdr*); - -SQLITE_PRIVATE int sqlite3PcachePageRefcount(PgHdr*); - -/* Return the total number of pages stored in the cache */ -SQLITE_PRIVATE int sqlite3PcachePagecount(PCache*); - -#ifdef SQLITE_CHECK_PAGES -/* Iterate through all pages currently stored in the cache. This interface -** is only available if SQLITE_CHECK_PAGES is defined when the library is -** built. -*/ -SQLITE_PRIVATE void sqlite3PcacheIterate(PCache *pCache, void (*xIter)(PgHdr *)); -#endif - -/* Set and get the suggested cache-size for the specified pager-cache. -** -** If no global maximum is configured, then the system attempts to limit -** the total number of pages cached by purgeable pager-caches to the sum -** of the suggested cache-sizes. -*/ -SQLITE_PRIVATE int sqlite3PcacheGetCachesize(PCache *); -SQLITE_PRIVATE void sqlite3PcacheSetCachesize(PCache *, int); - -#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT -/* Try to return memory used by the pcache module to the main memory heap */ -SQLITE_PRIVATE int sqlite3PcacheReleaseMemory(int); -#endif - -#ifdef SQLITE_TEST -SQLITE_PRIVATE void sqlite3PcacheStats(int*,int*,int*,int*); -#endif - -#endif /* _PCACHE_H_ */ - -/************** End of pcache.h **********************************************/ -/************** Continuing where we left off in sqliteInt.h ******************/ /************** Include os.h in the middle of sqliteInt.h ********************/ /************** Begin file os.h **********************************************/ @@ -8486,8 +7323,6 @@ SQLITE_PRIVATE void sqlite3PcacheStats(int*,int*,int*,int*); ** ** This header file is #include-ed by sqliteInt.h and thus ends up ** being included by every source file. -** -** $Id: os.h,v 1.105 2008/06/26 10:41:19 danielk1977 Exp $ */ #ifndef _SQLITE_OS_H_ #define _SQLITE_OS_H_ @@ -8495,66 +7330,56 @@ SQLITE_PRIVATE void sqlite3PcacheStats(int*,int*,int*,int*); /* ** Figure out if we are dealing with Unix, Windows, or some other ** operating system. After the following block of preprocess macros, -** all of SQLITE_OS_UNIX, SQLITE_OS_WIN, SQLITE_OS_OS2, and SQLITE_OS_OTHER -** will defined to either 1 or 0. One of the four will be 1. The other -** three will be 0. +** all of OS_UNIX, OS_WIN, OS_OS2, and OS_OTHER will defined to either +** 1 or 0. One of the four will be 1. The other three will be 0. */ -#if defined(SQLITE_OS_OTHER) -# if SQLITE_OS_OTHER==1 -# undef SQLITE_OS_UNIX -# define SQLITE_OS_UNIX 0 -# undef SQLITE_OS_WIN -# define SQLITE_OS_WIN 0 -# undef SQLITE_OS_OS2 -# define SQLITE_OS_OS2 0 +#if defined(OS_OTHER) +# if OS_OTHER==1 +# undef OS_UNIX +# define OS_UNIX 0 +# undef OS_WIN +# define OS_WIN 0 +# undef OS_OS2 +# define OS_OS2 0 # else -# undef SQLITE_OS_OTHER +# undef OS_OTHER # endif #endif -#if !defined(SQLITE_OS_UNIX) && !defined(SQLITE_OS_OTHER) -# define SQLITE_OS_OTHER 0 -# ifndef SQLITE_OS_WIN +#if !defined(OS_UNIX) && !defined(OS_OTHER) +# define OS_OTHER 0 +# ifndef OS_WIN # if defined(_WIN32) || defined(WIN32) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__BORLANDC__) -# define SQLITE_OS_WIN 1 -# define SQLITE_OS_UNIX 0 -# define SQLITE_OS_OS2 0 +# define OS_WIN 1 +# define OS_UNIX 0 +# define OS_OS2 0 # elif defined(__EMX__) || defined(_OS2) || defined(OS2) || defined(_OS2_) || defined(__OS2__) -# define SQLITE_OS_WIN 0 -# define SQLITE_OS_UNIX 0 -# define SQLITE_OS_OS2 1 +# define OS_WIN 0 +# define OS_UNIX 0 +# define OS_OS2 1 # else -# define SQLITE_OS_WIN 0 -# define SQLITE_OS_UNIX 1 -# define SQLITE_OS_OS2 0 +# define OS_WIN 0 +# define OS_UNIX 1 +# define OS_OS2 0 # endif # else -# define SQLITE_OS_UNIX 0 -# define SQLITE_OS_OS2 0 +# define OS_UNIX 0 +# define OS_OS2 0 # endif #else -# ifndef SQLITE_OS_WIN -# define SQLITE_OS_WIN 0 +# ifndef OS_WIN +# define OS_WIN 0 # endif #endif -/* -** Determine if we are dealing with WindowsCE - which has a much -** reduced API. -*/ -#if defined(_WIN32_WCE) -# define SQLITE_OS_WINCE 1 -#else -# define SQLITE_OS_WINCE 0 -#endif /* ** Define the maximum size of a temporary filename */ -#if SQLITE_OS_WIN +#if OS_WIN # include # define SQLITE_TEMPNAME_SIZE (MAX_PATH+50) -#elif SQLITE_OS_OS2 +#elif OS_OS2 # if (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ >= 3) && defined(OS2_HIGH_MEMORY) # include /* has to be included before os2.h for linking to work */ # endif @@ -8713,7 +7538,7 @@ SQLITE_PRIVATE int sqlite3OsSync(sqlite3_file*, int); SQLITE_PRIVATE int sqlite3OsFileSize(sqlite3_file*, i64 *pSize); SQLITE_PRIVATE int sqlite3OsLock(sqlite3_file*, int); SQLITE_PRIVATE int sqlite3OsUnlock(sqlite3_file*, int); -SQLITE_PRIVATE int sqlite3OsCheckReservedLock(sqlite3_file *id, int *pResOut); +SQLITE_PRIVATE int sqlite3OsCheckReservedLock(sqlite3_file *id); SQLITE_PRIVATE int sqlite3OsFileControl(sqlite3_file*,int,void*); SQLITE_PRIVATE int sqlite3OsSectorSize(sqlite3_file *id); SQLITE_PRIVATE int sqlite3OsDeviceCharacteristics(sqlite3_file *id); @@ -8723,14 +7548,13 @@ SQLITE_PRIVATE int sqlite3OsDeviceCharacteristics(sqlite3_file *id); */ SQLITE_PRIVATE int sqlite3OsOpen(sqlite3_vfs *, const char *, sqlite3_file*, int, int *); SQLITE_PRIVATE int sqlite3OsDelete(sqlite3_vfs *, const char *, int); -SQLITE_PRIVATE int sqlite3OsAccess(sqlite3_vfs *, const char *, int, int *pResOut); +SQLITE_PRIVATE int sqlite3OsAccess(sqlite3_vfs *, const char *, int); +SQLITE_PRIVATE int sqlite3OsGetTempname(sqlite3_vfs *, int, char *); SQLITE_PRIVATE int sqlite3OsFullPathname(sqlite3_vfs *, const char *, int, char *); -#ifndef SQLITE_OMIT_LOAD_EXTENSION SQLITE_PRIVATE void *sqlite3OsDlOpen(sqlite3_vfs *, const char *); SQLITE_PRIVATE void sqlite3OsDlError(sqlite3_vfs *, int, char *); SQLITE_PRIVATE void *sqlite3OsDlSym(sqlite3_vfs *, void *, const char *); SQLITE_PRIVATE void sqlite3OsDlClose(sqlite3_vfs *, void *); -#endif /* SQLITE_OMIT_LOAD_EXTENSION */ SQLITE_PRIVATE int sqlite3OsRandomness(sqlite3_vfs *, int, char *); SQLITE_PRIVATE int sqlite3OsSleep(sqlite3_vfs *, int); SQLITE_PRIVATE int sqlite3OsCurrentTime(sqlite3_vfs *, double*); @@ -8742,6 +7566,16 @@ SQLITE_PRIVATE int sqlite3OsCurrentTime(sqlite3_vfs *, double*); SQLITE_PRIVATE int sqlite3OsOpenMalloc(sqlite3_vfs *, const char *, sqlite3_file **, int,int*); SQLITE_PRIVATE int sqlite3OsCloseFree(sqlite3_file *); +/* +** Each OS-specific backend defines an instance of the following +** structure for returning a pointer to its sqlite3_vfs. If OS_OTHER +** is defined (meaning that the application-defined OS interface layer +** is used) then there is no default VFS. The application must +** register one or more VFS structures using sqlite3_vfs_register() +** before attempting to use SQLite. +*/ +SQLITE_PRIVATE sqlite3_vfs *sqlite3OsDefaultVfs(void); + #endif /* _SQLITE_OS_H_ */ /************** End of os.h **************************************************/ @@ -8769,21 +7603,28 @@ SQLITE_PRIVATE int sqlite3OsCloseFree(sqlite3_file *); ** Source files should #include the sqliteInt.h file and let that file ** include this one indirectly. ** -** $Id: mutex.h,v 1.9 2008/10/07 15:25:48 drh Exp $ +** $Id: mutex.h,v 1.2 2007/08/30 14:10:30 drh Exp $ */ +#ifdef SQLITE_MUTEX_APPDEF +/* +** If SQLITE_MUTEX_APPDEF is defined, then this whole module is +** omitted and equivalent functionality must be provided by the +** application that links against the SQLite library. +*/ +#else /* ** Figure out what version of the code to use. The choices are ** -** SQLITE_MUTEX_OMIT No mutex logic. Not even stubs. The -** mutexes implemention cannot be overridden -** at start-time. +** SQLITE_MUTEX_NOOP For single-threaded applications that +** do not desire error checking. ** -** SQLITE_MUTEX_NOOP For single-threaded applications. No -** mutual exclusion is provided. But this -** implementation can be overridden at -** start-time. +** SQLITE_MUTEX_NOOP_DEBUG For single-threaded applications with +** error checking to help verify that mutexes +** are being used correctly even though they +** are not needed. Used when SQLITE_DEBUG is +** defined on single-threaded builds. ** ** SQLITE_MUTEX_PTHREADS For multi-threaded applications on Unix. ** @@ -8791,22 +7632,25 @@ SQLITE_PRIVATE int sqlite3OsCloseFree(sqlite3_file *); ** ** SQLITE_MUTEX_OS2 For multi-threaded applications on OS/2. */ -#if !SQLITE_THREADSAFE -# define SQLITE_MUTEX_OMIT +#define SQLITE_MUTEX_NOOP 1 /* The default */ +#if defined(SQLITE_DEBUG) && !SQLITE_THREADSAFE +# undef SQLITE_MUTEX_NOOP +# define SQLITE_MUTEX_NOOP_DEBUG #endif -#if SQLITE_THREADSAFE && !defined(SQLITE_MUTEX_NOOP) -# if SQLITE_OS_UNIX -# define SQLITE_MUTEX_PTHREADS -# elif SQLITE_OS_WIN -# define SQLITE_MUTEX_W32 -# elif SQLITE_OS_OS2 -# define SQLITE_MUTEX_OS2 -# else -# define SQLITE_MUTEX_NOOP -# endif +#if defined(SQLITE_MUTEX_NOOP) && SQLITE_THREADSAFE && OS_UNIX +# undef SQLITE_MUTEX_NOOP +# define SQLITE_MUTEX_PTHREADS +#endif +#if defined(SQLITE_MUTEX_NOOP) && SQLITE_THREADSAFE && OS_WIN +# undef SQLITE_MUTEX_NOOP +# define SQLITE_MUTEX_W32 +#endif +#if defined(SQLITE_MUTEX_NOOP) && SQLITE_THREADSAFE && OS_OS2 +# undef SQLITE_MUTEX_NOOP +# define SQLITE_MUTEX_OS2 #endif -#ifdef SQLITE_MUTEX_OMIT +#ifdef SQLITE_MUTEX_NOOP /* ** If this is a no-op implementation, implement everything as macros. */ @@ -8817,10 +7661,9 @@ SQLITE_PRIVATE int sqlite3OsCloseFree(sqlite3_file *); #define sqlite3_mutex_leave(X) #define sqlite3_mutex_held(X) 1 #define sqlite3_mutex_notheld(X) 1 -#define sqlite3MutexAlloc(X) ((sqlite3_mutex*)8) -#define sqlite3MutexInit() SQLITE_OK -#define sqlite3MutexEnd() -#endif /* defined(SQLITE_OMIT_MUTEX) */ +#endif + +#endif /* SQLITE_MUTEX_APPDEF */ /************** End of mutex.h ***********************************************/ /************** Continuing where we left off in sqliteInt.h ******************/ @@ -8899,43 +7742,6 @@ struct Schema { */ #define SQLITE_N_LIMIT (SQLITE_LIMIT_VARIABLE_NUMBER+1) -/* -** Lookaside malloc is a set of fixed-size buffers that can be used -** to satisify small transient memory allocation requests for objects -** associated with a particular database connection. The use of -** lookaside malloc provides a significant performance enhancement -** (approx 10%) by avoiding numerous malloc/free requests while parsing -** SQL statements. -** -** The Lookaside structure holds configuration information about the -** lookaside malloc subsystem. Each available memory allocation in -** the lookaside subsystem is stored on a linked list of LookasideSlot -** objects. -*/ -struct Lookaside { - u16 sz; /* Size of each buffer in bytes */ - u8 bEnabled; /* True if use lookaside. False to ignore it */ - u8 bMalloced; /* True if pStart obtained from sqlite3_malloc() */ - int nOut; /* Number of buffers currently checked out */ - int mxOut; /* Highwater mark for nOut */ - LookasideSlot *pFree; /* List of available buffers */ - void *pStart; /* First byte of available memory space */ - void *pEnd; /* First byte past end of available space */ -}; -struct LookasideSlot { - LookasideSlot *pNext; /* Next buffer in the list of free buffers */ -}; - -/* -** A hash table for function definitions. -** -** Hash each FuncDef structure into one of the FuncDefHash.a[] slots. -** Collisions are on the FuncDef.pHash chain. -*/ -struct FuncDefHash { - FuncDef *a[23]; /* Hash table for functions */ -}; - /* ** Each database is an instance of the following structure. ** @@ -9012,10 +7818,9 @@ struct sqlite3 { char *zErrMsg; /* Most recent error message (UTF-8 encoded) */ char *zErrMsg16; /* Most recent error message (UTF-16 encoded) */ union { - volatile int isInterrupted; /* True if sqlite3_interrupt has been called */ + int isInterrupted; /* True if sqlite3_interrupt has been called */ double notUsed1; /* Spacer */ } u1; - Lookaside lookaside; /* Lookaside malloc configuration */ #ifndef SQLITE_OMIT_AUTHORIZATION int (*xAuth)(void*,int,const char*,const char*,const char*,const char*); /* Access authorization function */ @@ -9032,7 +7837,7 @@ struct sqlite3 { sqlite3_vtab **aVTrans; /* Virtual tables with open transactions */ int nVTrans; /* Allocated size of aVTrans */ #endif - FuncDefHash aFunc; /* Hash table of connection functions */ + Hash aFunc; /* All functions that can be in SQL exprs */ Hash aCollSeq; /* All collating sequences */ BusyHandler busyHandler; /* Busy callback */ int busyTimeout; /* Busy handler timeout, in msec */ @@ -9099,59 +7904,16 @@ struct sqlite3 { struct FuncDef { i16 nArg; /* Number of arguments. -1 means unlimited */ u8 iPrefEnc; /* Preferred text encoding (SQLITE_UTF8, 16LE, 16BE) */ + u8 needCollSeq; /* True if sqlite3GetFuncCollSeq() might be called */ u8 flags; /* Some combination of SQLITE_FUNC_* */ void *pUserData; /* User data parameter */ FuncDef *pNext; /* Next function with same name */ void (*xFunc)(sqlite3_context*,int,sqlite3_value**); /* Regular function */ void (*xStep)(sqlite3_context*,int,sqlite3_value**); /* Aggregate step */ void (*xFinalize)(sqlite3_context*); /* Aggregate finializer */ - char *zName; /* SQL name of the function. */ - FuncDef *pHash; /* Next with a different name but the same hash */ + char zName[1]; /* SQL name of the function. MUST BE LAST */ }; -/* -** Possible values for FuncDef.flags -*/ -#define SQLITE_FUNC_LIKE 0x01 /* Candidate for the LIKE optimization */ -#define SQLITE_FUNC_CASE 0x02 /* Case-sensitive LIKE-type function */ -#define SQLITE_FUNC_EPHEM 0x04 /* Ephermeral. Delete with VDBE */ -#define SQLITE_FUNC_NEEDCOLL 0x08 /* sqlite3GetFuncCollSeq() might be called */ - -/* -** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are -** used to create the initializers for the FuncDef structures. -** -** FUNCTION(zName, nArg, iArg, bNC, xFunc) -** Used to create a scalar function definition of a function zName -** implemented by C function xFunc that accepts nArg arguments. The -** value passed as iArg is cast to a (void*) and made available -** as the user-data (sqlite3_user_data()) for the function. If -** argument bNC is true, then the FuncDef.needCollate flag is set. -** -** AGGREGATE(zName, nArg, iArg, bNC, xStep, xFinal) -** Used to create an aggregate function definition implemented by -** the C functions xStep and xFinal. The first four parameters -** are interpreted in the same way as the first 4 parameters to -** FUNCTION(). -** -** LIKEFUNC(zName, nArg, pArg, flags) -** Used to create a scalar function definition of a function zName -** that accepts nArg arguments and is implemented by a call to C -** function likeFunc. Argument pArg is cast to a (void *) and made -** available as the function user-data (sqlite3_user_data()). The -** FuncDef.flags variable is set to the value passed as the flags -** parameter. -*/ -#define FUNCTION(zName, nArg, iArg, bNC, xFunc) \ - {nArg, SQLITE_UTF8, bNC*8, SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName} -#define STR_FUNCTION(zName, nArg, pArg, bNC, xFunc) \ - {nArg, SQLITE_UTF8, bNC*8, pArg, 0, xFunc, 0, 0, #zName} -#define LIKEFUNC(zName, nArg, arg, flags) \ - {nArg, SQLITE_UTF8, flags, (void *)arg, 0, likeFunc, 0, 0, #zName} -#define AGGREGATE(zName, nArg, arg, nc, xStep, xFinal) \ - {nArg, SQLITE_UTF8, nc*8, SQLITE_INT_TO_PTR(arg), 0, 0, xStep,xFinal, #zName} - - /* ** Each SQLite module (virtual table definition) is defined by an ** instance of the following structure, stored in the sqlite3.aModule @@ -9164,6 +7926,13 @@ struct Module { void (*xDestroy)(void *); /* Module destructor function */ }; +/* +** Possible values for FuncDef.flags +*/ +#define SQLITE_FUNC_LIKE 0x01 /* Candidate for the LIKE optimization */ +#define SQLITE_FUNC_CASE 0x02 /* Case-sensitive LIKE-type function */ +#define SQLITE_FUNC_EPHEM 0x04 /* Ephermeral. Delete with VDBE */ + /* ** information about each column of an SQL table is held in an instance ** of this structure. @@ -9212,7 +7981,7 @@ struct CollSeq { }; /* -** Allowed values of CollSeq.type: +** Allowed values of CollSeq flags: */ #define SQLITE_COLL_BINARY 1 /* The default memcmp() collating sequence */ #define SQLITE_COLL_NOCASE 2 /* The built-in NOCASE collating sequence */ @@ -9230,7 +7999,7 @@ struct CollSeq { ** ** These used to have mnemonic name like 'i' for SQLITE_AFF_INTEGER and ** 't' for SQLITE_AFF_TEXT. But we can save a little space and improve -** the speed a little by numbering the values consecutively. +** the speed a little by number the values consecutively. ** ** But rather than start with 0 or 1, we begin with 'a'. That way, ** when multiple affinity types are concatenated into a string and @@ -9258,7 +8027,8 @@ struct CollSeq { ** changing the affinity. */ #define SQLITE_JUMPIFNULL 0x08 /* jumps if either operand is NULL */ -#define SQLITE_STOREP2 0x10 /* Store result in reg[P2] rather than jump */ +#define SQLITE_NULLEQUAL 0x10 /* compare NULLs equal */ +#define SQLITE_STOREP2 0x80 /* Store result in reg[P2] rather than jump */ /* ** Each SQL table is represented in memory by an instance of the @@ -9276,14 +8046,14 @@ struct CollSeq { ** that the datatype of the PRIMARY KEY must be INTEGER for this field to ** be set. An INTEGER PRIMARY KEY is used as the rowid for each row of ** the table. If a table has no INTEGER PRIMARY KEY, then a random rowid -** is generated for each row of the table. TF_HasPrimaryKey is set if +** is generated for each row of the table. Table.hasPrimKey is true if ** the table has any PRIMARY KEY, INTEGER or otherwise. ** ** Table.tnum is the page number for the root BTree page of the table in the ** database file. If Table.iDb is the index of the database table backend ** in sqlite.aDb[]. 0 is for the main database and 1 is for the file that -** holds temporary tables and indices. If TF_Ephemeral is set -** then the table is stored in a file that is automatically deleted +** holds temporary tables and indices. If Table.isEphem +** is true, then the table is stored in a file that is automatically deleted ** when the VDBE cursor to the table is closed. In this case Table.tnum ** refers VDBE cursor number that holds the table open, not to the root ** page number. Transient tables are used to hold the results of a @@ -9291,55 +8061,46 @@ struct CollSeq { ** of a SELECT statement. */ struct Table { - sqlite3 *db; /* Associated database connection. Might be NULL. */ - char *zName; /* Name of the table or view */ - int iPKey; /* If not negative, use aCol[iPKey] as the primary key */ - int nCol; /* Number of columns in this table */ - Column *aCol; /* Information about each column */ - Index *pIndex; /* List of SQL indexes on this table. */ - int tnum; /* Root BTree node for this table (see note above) */ - Select *pSelect; /* NULL for tables. Points to definition if a view. */ - u16 nRef; /* Number of pointers to this Table */ - u8 tabFlags; /* Mask of TF_* values */ - u8 keyConf; /* What to do in case of uniqueness conflict on iPKey */ - Trigger *pTrigger; /* List of SQL triggers on this table */ - FKey *pFKey; /* Linked list of all foreign keys in this table */ - char *zColAff; /* String defining the affinity of each column */ + char *zName; /* Name of the table */ + int nCol; /* Number of columns in this table */ + Column *aCol; /* Information about each column */ + int iPKey; /* If not less then 0, use aCol[iPKey] as the primary key */ + Index *pIndex; /* List of SQL indexes on this table. */ + int tnum; /* Root BTree node for this table (see note above) */ + Select *pSelect; /* NULL for tables. Points to definition if a view. */ + int nRef; /* Number of pointers to this Table */ + Trigger *pTrigger; /* List of SQL triggers on this table */ + FKey *pFKey; /* Linked list of all foreign keys in this table */ + char *zColAff; /* String defining the affinity of each column */ #ifndef SQLITE_OMIT_CHECK - Expr *pCheck; /* The AND of all CHECK constraints */ + Expr *pCheck; /* The AND of all CHECK constraints */ #endif #ifndef SQLITE_OMIT_ALTERTABLE - int addColOffset; /* Offset in CREATE TABLE stmt to add a new column */ + int addColOffset; /* Offset in CREATE TABLE statement to add a new column */ #endif + u8 readOnly; /* True if this table should not be written by the user */ + u8 isEphem; /* True if created using OP_OpenEphermeral */ + u8 hasPrimKey; /* True if there exists a primary key */ + u8 keyConf; /* What to do in case of uniqueness conflict on iPKey */ + u8 autoInc; /* True if the integer primary key is autoincrement */ #ifndef SQLITE_OMIT_VIRTUALTABLE - Module *pMod; /* Pointer to the implementation of the module */ - sqlite3_vtab *pVtab; /* Pointer to the module instance */ - int nModuleArg; /* Number of arguments to the module */ - char **azModuleArg; /* Text of all module args. [0] is module name */ + u8 isVirtual; /* True if this is a virtual table */ + u8 isCommit; /* True once the CREATE TABLE has been committed */ + Module *pMod; /* Pointer to the implementation of the module */ + sqlite3_vtab *pVtab; /* Pointer to the module instance */ + int nModuleArg; /* Number of arguments to the module */ + char **azModuleArg; /* Text of all module args. [0] is module name */ #endif - Schema *pSchema; /* Schema that contains this table */ - Table *pNextZombie; /* Next on the Parse.pZombieTab list */ + Schema *pSchema; /* Schema that contains this table */ }; -/* -** Allowed values for Tabe.tabFlags. -*/ -#define TF_Readonly 0x01 /* Read-only system table */ -#define TF_Ephemeral 0x02 /* An emphermal table */ -#define TF_HasPrimaryKey 0x04 /* Table has a primary key */ -#define TF_Autoincrement 0x08 /* Integer primary key is autoincrement */ -#define TF_Virtual 0x10 /* Is a virtual table */ -#define TF_NeedMetadata 0x20 /* aCol[].zType and aCol[].pColl missing */ - - - /* ** Test to see whether or not a table is a virtual table. This is ** done as a macro so that it will be optimized out when virtual ** table support is omitted from the build. */ #ifndef SQLITE_OMIT_VIRTUALTABLE -# define IsVirtual(X) (((X)->tabFlags & TF_Virtual)!=0) +# define IsVirtual(X) ((X)->isVirtual) # define IsHiddenColumn(X) ((X)->isHidden) #else # define IsVirtual(X) 0 @@ -9431,45 +8192,21 @@ struct FKey { ** An instance of the following structure is passed as the first ** argument to sqlite3VdbeKeyCompare and is used to control the ** comparison of the two index keys. +** +** If the KeyInfo.incrKey value is true and the comparison would +** otherwise be equal, then return a result as if the second key +** were larger. */ struct KeyInfo { sqlite3 *db; /* The database connection */ u8 enc; /* Text encoding - one of the TEXT_Utf* values */ - u16 nField; /* Number of entries in aColl[] */ + u8 incrKey; /* Increase 2nd key by epsilon before comparison */ + u8 prefixIsEqual; /* Treat a prefix as equal */ + int nField; /* Number of entries in aColl[] */ u8 *aSortOrder; /* If defined an aSortOrder[i] is true, sort DESC */ CollSeq *aColl[1]; /* Collating sequence for each term of the key */ }; -/* -** An instance of the following structure holds information about a -** single index record that has already been parsed out into individual -** values. -** -** A record is an object that contains one or more fields of data. -** Records are used to store the content of a table row and to store -** the key of an index. A blob encoding of a record is created by -** the OP_MakeRecord opcode of the VDBE and is disassemblied by the -** OP_Column opcode. -** -** This structure holds a record that has already been disassembled -** into its constitutent fields. -*/ -struct UnpackedRecord { - KeyInfo *pKeyInfo; /* Collation and sort-order information */ - u16 nField; /* Number of entries in apMem[] */ - u16 flags; /* Boolean settings. UNPACKED_... below */ - Mem *aMem; /* Values */ -}; - -/* -** Allowed values of UnpackedRecord.flags -*/ -#define UNPACKED_NEED_FREE 0x0001 /* Memory is from sqlite3Malloc() */ -#define UNPACKED_NEED_DESTROY 0x0002 /* apMem[]s should all be destroyed */ -#define UNPACKED_IGNORE_ROWID 0x0004 /* Ignore trailing rowid on key1 */ -#define UNPACKED_INCRKEY 0x0008 /* Make this key an epsilon larger */ -#define UNPACKED_PREFIX_MATCH 0x0010 /* A prefix match is considered OK */ - /* ** Each SQL index is represented in memory by an ** instance of the following structure. @@ -9633,8 +8370,9 @@ struct Expr { int iRightJoinTable; /* If EP_FromJoin, the right table of the join */ Select *pSelect; /* When the expression is a sub-select. Also the ** right side of " IN ( ** -** If prNotFound parameter is 0, then the structure will be used to iterate -** through the set members, skipping any duplicates. In this case an -** epheremal table must be used unless the selected is guaranteed -** to be unique - either because it is an INTEGER PRIMARY KEY or it -** is unique by virtue of a constraint or implicit index. -** -** If the prNotFound parameter is not 0, then the structure will be used +** If the mustBeUnique parameter is false, the structure will be used ** for fast set membership tests. In this case an epheremal table must ** be used unless is an INTEGER PRIMARY KEY or an index can ** be found with as its left-most column. ** -** When the structure is being used for set membership tests, the user -** needs to know whether or not the structure contains an SQL NULL -** value in order to correctly evaluate expressions like "X IN (Y, Z)". -** If there is a chance that the structure may contain a NULL value at -** runtime, then a register is allocated and the register number written -** to *prNotFound. If there is no chance that the structure contains a -** NULL value, then *prNotFound is left unchanged. -** -** If a register is allocated and its location stored in *prNotFound, then -** its initial value is NULL. If the structure does not remain constant -** for the duration of the query (i.e. the set is a correlated sub-select), -** the value of the allocated register is reset to NULL each time the -** structure is repopulated. This allows the caller to use vdbe code -** equivalent to the following: -** -** if( register==NULL ){ -** has_null = -** register = 1 -** } -** -** in order to avoid running the -** test more often than is necessary. +** If mustBeUnique is true, then the structure will be used to iterate +** through the set members, skipping any duplicates. In this case an +** epheremal table must be used unless the selected is guaranteed +** to be unique - either because it is an INTEGER PRIMARY KEY or it +** is unique by virtue of a constraint or implicit index. */ #ifndef SQLITE_OMIT_SUBQUERY -SQLITE_PRIVATE int sqlite3FindInIndex(Parse *pParse, Expr *pX, int *prNotFound){ +SQLITE_PRIVATE int sqlite3FindInIndex(Parse *pParse, Expr *pX, int mustBeUnique){ Select *p; int eType = 0; int iTab = pParse->nTab++; - int mustBeUnique = !prNotFound; /* The follwing if(...) expression is true if the SELECT is of the ** simple form: @@ -54160,23 +49249,14 @@ SQLITE_PRIVATE int sqlite3FindInIndex(Parse *pParse, Expr *pX, int *prNotFound){ eType = IN_INDEX_INDEX; sqlite3VdbeJumpHere(v, iAddr); - if( prNotFound && !pTab->aCol[iCol].notNull ){ - *prNotFound = ++pParse->nMem; - } } } } } if( eType==0 ){ - int rMayHaveNull = 0; + sqlite3CodeSubselect(pParse, pX); eType = IN_INDEX_EPH; - if( prNotFound ){ - *prNotFound = rMayHaveNull = ++pParse->nMem; - }else if( pX->pLeft->iColumn<0 && pX->pSelect==0 ){ - eType = IN_INDEX_ROWID; - } - sqlite3CodeSubselect(pParse, pX, rMayHaveNull, eType==IN_INDEX_ROWID); }else{ pX->iTable = iTab; } @@ -54195,20 +49275,9 @@ SQLITE_PRIVATE int sqlite3FindInIndex(Parse *pParse, Expr *pX, int *prNotFound){ ** ** The pExpr parameter describes the expression that contains the IN ** operator or subquery. -** -** If parameter isRowid is non-zero, then expression pExpr is guaranteed -** to be of the form " IN (?, ?, ?)", where is a reference -** to some integer key column of a table B-Tree. In this case, use an -** intkey B-Tree to store the set of IN(...) values instead of the usual -** (slower) variable length keys B-Tree. */ #ifndef SQLITE_OMIT_SUBQUERY -SQLITE_PRIVATE void sqlite3CodeSubselect( - Parse *pParse, - Expr *pExpr, - int rMayHaveNull, - int isRowid -){ +SQLITE_PRIVATE void sqlite3CodeSubselect(Parse *pParse, Expr *pExpr){ int testAddr = 0; /* One-time test address */ Vdbe *v = sqlite3GetVdbe(pParse); if( v==0 ) return; @@ -54236,13 +49305,8 @@ SQLITE_PRIVATE void sqlite3CodeSubselect( char affinity; KeyInfo keyInfo; int addr; /* Address of OP_OpenEphemeral instruction */ - Expr *pLeft = pExpr->pLeft; - if( rMayHaveNull ){ - sqlite3VdbeAddOp2(v, OP_Null, 0, rMayHaveNull); - } - - affinity = sqlite3ExprAffinity(pLeft); + affinity = sqlite3ExprAffinity(pExpr->pLeft); /* Whether this is an 'x IN(SELECT...)' or an 'x IN()' ** expression it is handled the same way. A virtual table is @@ -54258,7 +49322,7 @@ SQLITE_PRIVATE void sqlite3CodeSubselect( ** is used. */ pExpr->iTable = pParse->nTab++; - addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pExpr->iTable, !isRowid); + addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pExpr->iTable, 1); memset(&keyInfo, 0, sizeof(keyInfo)); keyInfo.nField = 1; @@ -54271,11 +49335,10 @@ SQLITE_PRIVATE void sqlite3CodeSubselect( SelectDest dest; ExprList *pEList; - assert( !isRowid ); sqlite3SelectDestInit(&dest, SRT_Set, pExpr->iTable); dest.affinity = (int)affinity; assert( (pExpr->iTable&0x0000FFFF)==pExpr->iTable ); - if( sqlite3Select(pParse, pExpr->pSelect, &dest) ){ + if( sqlite3Select(pParse, pExpr->pSelect, &dest, 0, 0, 0, 0) ){ return; } pEList = pExpr->pSelect->pEList; @@ -54294,17 +49357,16 @@ SQLITE_PRIVATE void sqlite3CodeSubselect( int i; ExprList *pList = pExpr->pList; struct ExprList_item *pItem; - int r1, r2, r3; + int r1, r2; if( !affinity ){ affinity = SQLITE_AFF_NONE; } - keyInfo.aColl[0] = sqlite3ExprCollSeq(pParse, pExpr->pLeft); + keyInfo.aColl[0] = pExpr->pLeft->pColl; /* Loop through each expression in . */ r1 = sqlite3GetTempReg(pParse); r2 = sqlite3GetTempReg(pParse); - sqlite3VdbeAddOp2(v, OP_Null, 0, r2); for(i=pList->nExpr, pItem=pList->a; i>0; i--, pItem++){ Expr *pE2 = pItem->pExpr; @@ -54320,25 +49382,17 @@ SQLITE_PRIVATE void sqlite3CodeSubselect( /* Evaluate the expression and insert it into the temp table */ pParse->disableColCache++; - r3 = sqlite3ExprCodeTarget(pParse, pE2, r1); + sqlite3ExprCode(pParse, pE2, r1); assert( pParse->disableColCache>0 ); pParse->disableColCache--; - - if( isRowid ){ - sqlite3VdbeAddOp2(v, OP_MustBeInt, r3, sqlite3VdbeCurrentAddr(v)+2); - sqlite3VdbeAddOp3(v, OP_Insert, pExpr->iTable, r2, r3); - }else{ - sqlite3VdbeAddOp4(v, OP_MakeRecord, r3, 1, r2, &affinity, 1); - sqlite3ExprCacheAffinityChange(pParse, r3, 1); - sqlite3VdbeAddOp2(v, OP_IdxInsert, pExpr->iTable, r2); - } + sqlite3VdbeAddOp4(v, OP_MakeRecord, r1, 1, r2, &affinity, 1); + sqlite3ExprCacheAffinityChange(pParse, r1, 1); + sqlite3VdbeAddOp2(v, OP_IdxInsert, pExpr->iTable, r2); } sqlite3ReleaseTempReg(pParse, r1); sqlite3ReleaseTempReg(pParse, r2); } - if( !isRowid ){ - sqlite3VdbeChangeP4(v, addr, (void *)&keyInfo, P4_KEYINFO); - } + sqlite3VdbeChangeP4(v, addr, (void *)&keyInfo, P4_KEYINFO); break; } @@ -54363,9 +49417,9 @@ SQLITE_PRIVATE void sqlite3CodeSubselect( sqlite3VdbeAddOp2(v, OP_Integer, 0, dest.iParm); VdbeComment((v, "Init EXISTS result")); } - sqlite3ExprDelete(pParse->db, pSel->pLimit); + sqlite3ExprDelete(pSel->pLimit); pSel->pLimit = sqlite3PExpr(pParse, TK_INTEGER, 0, 0, &one); - if( sqlite3Select(pParse, pSel, &dest) ){ + if( sqlite3Select(pParse, pSel, &dest, 0, 0, 0, 0) ){ return; } pExpr->iColumn = dest.iParm; @@ -54426,15 +49480,10 @@ static void codeReal(Vdbe *v, const char *z, int n, int negateFlag, int iMem){ ** z[n] character is guaranteed to be something that does not look ** like the continuation of the number. */ -static void codeInteger(Vdbe *v, Expr *pExpr, int negFlag, int iMem){ - const char *z; - if( pExpr->flags & EP_IntValue ){ - int i = pExpr->iTable; - if( negFlag ) i = -i; - sqlite3VdbeAddOp2(v, OP_Integer, i, iMem); - }else if( (z = (char*)pExpr->token.z)!=0 ){ +static void codeInteger(Vdbe *v, const char *z, int n, int negFlag, int iMem){ + assert( z || v==0 || sqlite3VdbeDb(v)->mallocFailed ); + if( z ){ int i; - int n = pExpr->token.n; assert( !isdigit(z[n]) ); if( sqlite3GetInt32(z, &i) ){ if( negFlag ) i = -i; @@ -54557,33 +49606,20 @@ SQLITE_PRIVATE void sqlite3ExprCacheAffinityChange(Parse *pParse, int iStart, in } /* -** Generate code to move content from registers iFrom...iFrom+nReg-1 -** over to iTo..iTo+nReg-1. Keep the column cache up-to-date. +** Generate code to moves content from one register to another. +** Keep the column cache up-to-date. */ -SQLITE_PRIVATE void sqlite3ExprCodeMove(Parse *pParse, int iFrom, int iTo, int nReg){ +SQLITE_PRIVATE void sqlite3ExprCodeMove(Parse *pParse, int iFrom, int iTo){ int i; if( iFrom==iTo ) return; - sqlite3VdbeAddOp3(pParse->pVdbe, OP_Move, iFrom, iTo, nReg); + sqlite3VdbeAddOp2(pParse->pVdbe, OP_Move, iFrom, iTo); for(i=0; inColCache; i++){ - int x = pParse->aColCache[i].iReg; - if( x>=iFrom && xaColCache[i].iReg += iTo-iFrom; + if( pParse->aColCache[i].iReg==iFrom ){ + pParse->aColCache[i].iReg = iTo; } } } -/* -** Generate code to copy content from registers iFrom...iFrom+nReg-1 -** over to iTo..iTo+nReg-1. -*/ -SQLITE_PRIVATE void sqlite3ExprCodeCopy(Parse *pParse, int iFrom, int iTo, int nReg){ - int i; - if( iFrom==iTo ) return; - for(i=0; ipVdbe, OP_Copy, iFrom+i, iTo+i); - } -} - /* ** Return true if any register in the range iFrom..iTo (inclusive) ** is used as part of the column cache. @@ -54646,47 +49682,12 @@ SQLITE_PRIVATE void sqlite3ExprHardCopy(Parse *pParse, int iReg, int nReg){ } } -/* -** Generate code to store the value of the iAlias-th alias in register -** target. The first time this is called, pExpr is evaluated to compute -** the value of the alias. The value is stored in an auxiliary register -** and the number of that register is returned. On subsequent calls, -** the register number is returned without generating any code. -** -** Note that in order for this to work, code must be generated in the -** same order that it is executed. -** -** Aliases are numbered starting with 1. So iAlias is in the range -** of 1 to pParse->nAlias inclusive. -** -** pParse->aAlias[iAlias-1] records the register number where the value -** of the iAlias-th alias is stored. If zero, that means that the -** alias has not yet been computed. -*/ -static int codeAlias(Parse *pParse, int iAlias, Expr *pExpr){ - sqlite3 *db = pParse->db; - int iReg; - if( pParse->aAlias==0 ){ - pParse->aAlias = sqlite3DbMallocZero(db, - sizeof(pParse->aAlias[0])*pParse->nAlias ); - if( db->mallocFailed ) return 0; - } - assert( iAlias>0 && iAlias<=pParse->nAlias ); - iReg = pParse->aAlias[iAlias-1]; - if( iReg==0 ){ - iReg = ++pParse->nMem; - sqlite3ExprCode(pParse, pExpr, iReg); - pParse->aAlias[iAlias-1] = iReg; - } - return iReg; -} - /* ** Generate code into the current Vdbe to evaluate the given ** expression. Attempt to store the results in register "target". ** Return the register where results are stored. ** -** With this routine, there is no guarantee that results will +** With this routine, there is no guaranteed that results will ** be stored in target. The result might be stored in some other ** register if it is convenient to do so. The calling function ** must check the return code and move the results to the desired @@ -54699,10 +49700,8 @@ SQLITE_PRIVATE int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target) int regFree1 = 0; /* If non-zero free this temporary register */ int regFree2 = 0; /* If non-zero free this temporary register */ int r1, r2, r3, r4; /* Various register numbers */ - sqlite3 *db; - db = pParse->db; - assert( v!=0 || db->mallocFailed ); + assert( v!=0 || pParse->db->mallocFailed ); assert( target>0 && target<=pParse->nMem ); if( v==0 ) return 0; @@ -54740,7 +49739,7 @@ SQLITE_PRIVATE int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target) break; } case TK_INTEGER: { - codeInteger(v, pExpr, 0, target); + codeInteger(v, (char*)pExpr->token.z, pExpr->token.n, 0, target); break; } case TK_FLOAT: { @@ -54748,7 +49747,7 @@ SQLITE_PRIVATE int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target) break; } case TK_STRING: { - sqlite3DequoteExpr(db, pExpr); + sqlite3DequoteExpr(pParse->db, pExpr); sqlite3VdbeAddOp4(v,OP_String8, 0, target, 0, (char*)pExpr->token.z, pExpr->token.n); break; @@ -54784,10 +49783,6 @@ SQLITE_PRIVATE int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target) inReg = pExpr->iTable; break; } - case TK_AS: { - inReg = codeAlias(pParse, pExpr->iTable, pExpr->pLeft); - break; - } #ifndef SQLITE_OMIT_CAST case TK_CAST: { /* Expressions of the form: CAST(pLeft AS token) */ @@ -54882,10 +49877,11 @@ SQLITE_PRIVATE int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target) Expr *pLeft = pExpr->pLeft; assert( pLeft ); if( pLeft->op==TK_FLOAT || pLeft->op==TK_INTEGER ){ + Token *p = &pLeft->token; if( pLeft->op==TK_FLOAT ){ - codeReal(v, (char*)pLeft->token.z, pLeft->token.n, 1, target); + codeReal(v, (char*)p->z, p->n, 1, target); }else{ - codeInteger(v, pLeft, 1, target); + codeInteger(v, (char*)p->z, p->n, 1, target); } }else{ regFree1 = r1 = sqlite3GetTempReg(pParse); @@ -54944,6 +49940,7 @@ SQLITE_PRIVATE int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target) const char *zId; int constMask = 0; int i; + sqlite3 *db = pParse->db; u8 enc = ENC(db); CollSeq *pColl = 0; @@ -54951,7 +49948,7 @@ SQLITE_PRIVATE int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target) testcase( op==TK_FUNCTION ); zId = (char*)pExpr->token.z; nId = pExpr->token.n; - pDef = sqlite3FindFunction(db, zId, nId, nExpr, enc, 0); + pDef = sqlite3FindFunction(pParse->db, zId, nId, nExpr, enc, 0); assert( pDef!=0 ); if( pList ){ nExpr = pList->nExpr; @@ -54983,12 +49980,12 @@ SQLITE_PRIVATE int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target) if( sqlite3ExprIsConstant(pList->a[i].pExpr) ){ constMask |= (1<flags & SQLITE_FUNC_NEEDCOLL)!=0 && !pColl ){ + if( pDef->needCollSeq && !pColl ){ pColl = sqlite3ExprCollSeq(pParse, pList->a[i].pExpr); } } - if( pDef->flags & SQLITE_FUNC_NEEDCOLL ){ - if( !pColl ) pColl = db->pDfltColl; + if( pDef->needCollSeq ){ + if( !pColl ) pColl = pParse->db->pDfltColl; sqlite3VdbeAddOp4(v, OP_CollSeq, 0, 0, 0, (char *)pColl, P4_COLLSEQ); } sqlite3VdbeAddOp4(v, OP_Function, constMask, r1, target, @@ -55006,23 +50003,17 @@ SQLITE_PRIVATE int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target) testcase( op==TK_EXISTS ); testcase( op==TK_SELECT ); if( pExpr->iColumn==0 ){ - sqlite3CodeSubselect(pParse, pExpr, 0, 0); + sqlite3CodeSubselect(pParse, pExpr); } inReg = pExpr->iColumn; break; } case TK_IN: { - int rNotFound = 0; - int rMayHaveNull = 0; - int j2, j3, j4, j5; + int j1, j2, j3, j4, j5; char affinity; int eType; - VdbeNoopComment((v, "begin IN expr r%d", target)); - eType = sqlite3FindInIndex(pParse, pExpr, &rMayHaveNull); - if( rMayHaveNull ){ - rNotFound = ++pParse->nMem; - } + eType = sqlite3FindInIndex(pParse, pExpr, 0); /* Figure out the affinity to use to create a key from the results ** of the expression. affinityStr stores a static string suitable for @@ -55030,74 +50021,32 @@ SQLITE_PRIVATE int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target) */ affinity = comparisonAffinity(pExpr); + sqlite3VdbeAddOp2(v, OP_Integer, 1, target); /* Code the from " IN (...)". The temporary table ** pExpr->iTable contains the values that make up the (...) set. */ - pParse->disableColCache++; - sqlite3ExprCode(pParse, pExpr->pLeft, target); - pParse->disableColCache--; - j2 = sqlite3VdbeAddOp1(v, OP_IsNull, target); + r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, ®Free1); + testcase( regFree1==0 ); + j1 = sqlite3VdbeAddOp1(v, OP_NotNull, r1); + sqlite3VdbeAddOp2(v, OP_Null, 0, target); + j2 = sqlite3VdbeAddOp0(v, OP_Goto); + sqlite3VdbeJumpHere(v, j1); if( eType==IN_INDEX_ROWID ){ - j3 = sqlite3VdbeAddOp1(v, OP_MustBeInt, target); - j4 = sqlite3VdbeAddOp3(v, OP_NotExists, pExpr->iTable, 0, target); - sqlite3VdbeAddOp2(v, OP_Integer, 1, target); + j3 = sqlite3VdbeAddOp1(v, OP_MustBeInt, r1); + j4 = sqlite3VdbeAddOp3(v, OP_NotExists, pExpr->iTable, 0, r1); j5 = sqlite3VdbeAddOp0(v, OP_Goto); sqlite3VdbeJumpHere(v, j3); sqlite3VdbeJumpHere(v, j4); - sqlite3VdbeAddOp2(v, OP_Integer, 0, target); }else{ r2 = regFree2 = sqlite3GetTempReg(pParse); - - /* Create a record and test for set membership. If the set contains - ** the value, then jump to the end of the test code. The target - ** register still contains the true (1) value written to it earlier. - */ - sqlite3VdbeAddOp4(v, OP_MakeRecord, target, 1, r2, &affinity, 1); - sqlite3VdbeAddOp2(v, OP_Integer, 1, target); + sqlite3VdbeAddOp4(v, OP_MakeRecord, r1, 1, r2, &affinity, 1); + sqlite3ExprCacheAffinityChange(pParse, r1, 1); j5 = sqlite3VdbeAddOp3(v, OP_Found, pExpr->iTable, 0, r2); - - /* If the set membership test fails, then the result of the - ** "x IN (...)" expression must be either 0 or NULL. If the set - ** contains no NULL values, then the result is 0. If the set - ** contains one or more NULL values, then the result of the - ** expression is also NULL. - */ - if( rNotFound==0 ){ - /* This branch runs if it is known at compile time (now) that - ** the set contains no NULL values. This happens as the result - ** of a "NOT NULL" constraint in the database schema. No need - ** to test the data structure at runtime in this case. - */ - sqlite3VdbeAddOp2(v, OP_Integer, 0, target); - }else{ - /* This block populates the rNotFound register with either NULL - ** or 0 (an integer value). If the data structure contains one - ** or more NULLs, then set rNotFound to NULL. Otherwise, set it - ** to 0. If register rMayHaveNull is already set to some value - ** other than NULL, then the test has already been run and - ** rNotFound is already populated. - */ - static const char nullRecord[] = { 0x02, 0x00 }; - j3 = sqlite3VdbeAddOp1(v, OP_NotNull, rMayHaveNull); - sqlite3VdbeAddOp2(v, OP_Null, 0, rNotFound); - sqlite3VdbeAddOp4(v, OP_Blob, 2, rMayHaveNull, 0, - nullRecord, P4_STATIC); - j4 = sqlite3VdbeAddOp3(v, OP_Found, pExpr->iTable, 0, rMayHaveNull); - sqlite3VdbeAddOp2(v, OP_Integer, 0, rNotFound); - sqlite3VdbeJumpHere(v, j4); - sqlite3VdbeJumpHere(v, j3); - - /* Copy the value of register rNotFound (which is either NULL or 0) - ** into the target register. This will be the result of the - ** expression. - */ - sqlite3VdbeAddOp2(v, OP_Copy, rNotFound, target); - } } + sqlite3VdbeAddOp2(v, OP_AddImm, target, -1); sqlite3VdbeJumpHere(v, j2); sqlite3VdbeJumpHere(v, j5); - VdbeComment((v, "end IN expr r%d", target)); break; } #endif @@ -55187,6 +50136,7 @@ SQLITE_PRIVATE int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target) cacheX.iTable = sqlite3ExprCodeTemp(pParse, pX, ®Free1); testcase( regFree1==0 ); cacheX.op = TK_REGISTER; + cacheX.iColumn = 0; opCompare.op = TK_EQ; opCompare.pLeft = &cacheX; pTest = &opCompare; @@ -55228,7 +50178,7 @@ SQLITE_PRIVATE int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target) assert( pExpr->iColumn==OE_Rollback || pExpr->iColumn == OE_Abort || pExpr->iColumn == OE_Fail ); - sqlite3DequoteExpr(db, pExpr); + sqlite3DequoteExpr(pParse->db, pExpr); sqlite3VdbeAddOp4(v, OP_Halt, SQLITE_CONSTRAINT, pExpr->iColumn, 0, (char*)pExpr->token.z, pExpr->token.n); } else { @@ -55306,6 +50256,7 @@ SQLITE_PRIVATE int sqlite3ExprCodeAndCache(Parse *pParse, Expr *pExpr, int targe iMem = ++pParse->nMem; sqlite3VdbeAddOp2(v, OP_Copy, inReg, iMem); pExpr->iTable = iMem; + pExpr->iColumn = pExpr->op; pExpr->op = TK_REGISTER; } return inReg; @@ -55376,8 +50327,8 @@ static int isAppropriateForFactoring(Expr *p){ ** into a register and convert the expression into a TK_REGISTER ** expression. */ -static int evalConstExpr(Walker *pWalker, Expr *pExpr){ - Parse *pParse = pWalker->pParse; +static int evalConstExpr(void *pArg, Expr *pExpr){ + Parse *pParse = (Parse*)pArg; switch( pExpr->op ){ case TK_REGISTER: { return 1; @@ -55405,11 +50356,12 @@ static int evalConstExpr(Walker *pWalker, Expr *pExpr){ int r2; r2 = sqlite3ExprCodeTarget(pParse, pExpr, r1); if( r1!=r2 ) sqlite3ReleaseTempReg(pParse, r1); + pExpr->iColumn = pExpr->op; pExpr->op = TK_REGISTER; pExpr->iTable = r2; - return WRC_Prune; + return 1; } - return WRC_Continue; + return 0; } /* @@ -55418,11 +50370,7 @@ static int evalConstExpr(Walker *pWalker, Expr *pExpr){ ** are TK_REGISTER opcodes that refer to the precomputed values. */ SQLITE_PRIVATE void sqlite3ExprCodeConstants(Parse *pParse, Expr *pExpr){ - Walker w; - w.xExprCallback = evalConstExpr; - w.xSelectCallback = 0; - w.pParse = pParse; - sqlite3WalkExpr(&w, pExpr); + walkExprTree(pExpr, evalConstExpr, pParse); } @@ -55436,24 +50384,19 @@ SQLITE_PRIVATE int sqlite3ExprCodeExprList( Parse *pParse, /* Parsing context */ ExprList *pList, /* The expression list to be coded */ int target, /* Where to write results */ - int doHardCopy /* Make a hard copy of every element */ + int doHardCopy /* Call sqlite3ExprHardCopy on each element if true */ ){ struct ExprList_item *pItem; int i, n; - assert( pList!=0 ); + assert( pList!=0 || pParse->db->mallocFailed ); + if( pList==0 ){ + return 0; + } assert( target>0 ); n = pList->nExpr; for(pItem=pList->a, i=0; iiAlias ){ - int iReg = codeAlias(pParse, pItem->iAlias, pItem->pExpr); - Vdbe *v = sqlite3GetVdbe(pParse); - sqlite3VdbeAddOp2(v, OP_SCopy, iReg, target+i); - }else{ - sqlite3ExprCode(pParse, pItem->pExpr, target+i); - } - if( doHardCopy ){ - sqlite3ExprHardCopy(pParse, target, n); - } + sqlite3ExprCode(pParse, pItem->pExpr, target+i); + if( doHardCopy ) sqlite3ExprHardCopy(pParse, target, n); } return n; } @@ -55827,13 +50770,15 @@ static int addAggInfoFunc(sqlite3 *db, AggInfo *pInfo){ } /* -** This is the xExprCallback for a tree walker. It is used to -** implement sqlite3ExprAnalyzeAggregates(). See sqlite3ExprAnalyzeAggregates +** This is an xFunc for walkExprTree() used to implement +** sqlite3ExprAnalyzeAggregates(). See sqlite3ExprAnalyzeAggregates ** for additional information. +** +** This routine analyzes the aggregate function at pExpr. */ -static int analyzeAggregate(Walker *pWalker, Expr *pExpr){ +static int analyzeAggregate(void *pArg, Expr *pExpr){ int i; - NameContext *pNC = pWalker->u.pNC; + NameContext *pNC = (NameContext *)pArg; Parse *pParse = pNC->pParse; SrcList *pSrcList = pNC->pSrcList; AggInfo *pAggInfo = pNC->pAggInfo; @@ -55841,8 +50786,6 @@ static int analyzeAggregate(Walker *pWalker, Expr *pExpr){ switch( pExpr->op ){ case TK_AGG_COLUMN: case TK_COLUMN: { - testcase( pExpr->op==TK_AGG_COLUMN ); - testcase( pExpr->op==TK_COLUMN ); /* Check to see if the column is in one of the tables in the FROM ** clause of the aggregate query */ if( pSrcList ){ @@ -55904,7 +50847,7 @@ static int analyzeAggregate(Walker *pWalker, Expr *pExpr){ } /* endif pExpr->iTable==pItem->iCursor */ } /* end loop over pSrcList */ } - return WRC_Prune; + return 1; } case TK_AGG_FUNCTION: { /* The pNC->nDepth==0 test causes aggregate functions in subqueries @@ -55942,22 +50885,21 @@ static int analyzeAggregate(Walker *pWalker, Expr *pExpr){ */ pExpr->iAgg = i; pExpr->pAggInfo = pAggInfo; - return WRC_Prune; + return 1; } } } - return WRC_Continue; -} -static int analyzeAggregatesInSelect(Walker *pWalker, Select *pSelect){ - NameContext *pNC = pWalker->u.pNC; - if( pNC->nDepth==0 ){ + + /* Recursively walk subqueries looking for TK_COLUMN nodes that need + ** to be changed to TK_AGG_COLUMN. But increment nDepth so that + ** TK_AGG_FUNCTION nodes in subqueries will be unchanged. + */ + if( pExpr->pSelect ){ pNC->nDepth++; - sqlite3WalkSelect(pWalker, pSelect); + walkSelectExpr(pExpr->pSelect, analyzeAggregate, pNC); pNC->nDepth--; - return WRC_Prune; - }else{ - return WRC_Continue; } + return 0; } /* @@ -55966,14 +50908,10 @@ static int analyzeAggregatesInSelect(Walker *pWalker, Select *pSelect){ ** Make additional entries to the pParse->aAgg[] array as necessary. ** ** This routine should only be called after the expression has been -** analyzed by sqlite3ResolveExprNames(). +** analyzed by sqlite3ExprResolveNames(). */ SQLITE_PRIVATE void sqlite3ExprAnalyzeAggregates(NameContext *pNC, Expr *pExpr){ - Walker w; - w.xExprCallback = analyzeAggregate; - w.xSelectCallback = analyzeAggregatesInSelect; - w.u.pNC = pNC; - sqlite3WalkExpr(&w, pExpr); + walkExprTree(pExpr, analyzeAggregate, pNC); } /* @@ -55996,14 +50934,25 @@ SQLITE_PRIVATE void sqlite3ExprAnalyzeAggList(NameContext *pNC, ExprList *pList) ** Allocate or deallocate temporary use registers during code generation. */ SQLITE_PRIVATE int sqlite3GetTempReg(Parse *pParse){ + int i, r; if( pParse->nTempReg==0 ){ return ++pParse->nMem; } - return pParse->aTempReg[--pParse->nTempReg]; + for(i=0; inTempReg; i++){ + r = pParse->aTempReg[i]; + if( usedAsColumnCache(pParse, r, r) ) continue; + } + if( i>=pParse->nTempReg ){ + return ++pParse->nMem; + } + while( inTempReg-1 ){ + pParse->aTempReg[i] = pParse->aTempReg[i+1]; + } + pParse->nTempReg--; + return r; } SQLITE_PRIVATE void sqlite3ReleaseTempReg(Parse *pParse, int iReg){ if( iReg && pParse->nTempRegaTempReg) ){ - sqlite3ExprWritableRegister(pParse, iReg, iReg); pParse->aTempReg[pParse->nTempReg++] = iReg; } } @@ -56047,7 +50996,7 @@ SQLITE_PRIVATE void sqlite3ReleaseTempRange(Parse *pParse, int iReg, int nReg){ ** This file contains C code routines that used to generate VDBE code ** that implements the ALTER TABLE command. ** -** $Id: alter.c,v 1.48 2008/08/08 14:19:41 drh Exp $ +** $Id: alter.c,v 1.44 2008/05/09 14:17:52 drh Exp $ */ /* @@ -56088,7 +51037,7 @@ static void renameTableFunc( /* The principle used to locate the table name in the CREATE TABLE ** statement is that the table name is the first non-space token that - ** is immediately followed by a TK_LP or TK_USING token. + ** is immediately followed by a left parenthesis - TK_LP - or "USING" TK_USING. */ if( zSql ){ do { @@ -56107,13 +51056,13 @@ static void renameTableFunc( do { zCsr += len; len = sqlite3GetToken(zCsr, &token); - } while( token==TK_SPACE ); + } while( token==TK_SPACE || token==TK_COMMENT ); assert( len>0 ); } while( token!=TK_LP && token!=TK_USING ); zRet = sqlite3MPrintf(db, "%.*s\"%w\"%s", tname.z - zSql, zSql, zTableName, tname.z+tname.n); - sqlite3_result_text(context, zRet, -1, SQLITE_DYNAMIC); + sqlite3_result_text(context, zRet, -1, sqlite3_free); } } @@ -56188,7 +51137,7 @@ static void renameTriggerFunc( */ zRet = sqlite3MPrintf(db, "%.*s\"%w\"%s", tname.z - zSql, zSql, zTableName, tname.z+tname.n); - sqlite3_result_text(context, zRet, -1, SQLITE_DYNAMIC); + sqlite3_result_text(context, zRet, -1, sqlite3_free); } } #endif /* !SQLITE_OMIT_TRIGGER */ @@ -56197,12 +51146,22 @@ static void renameTriggerFunc( ** Register built-in functions used to help implement ALTER TABLE */ SQLITE_PRIVATE void sqlite3AlterFunctions(sqlite3 *db){ - sqlite3CreateFunc(db, "sqlite_rename_table", 2, SQLITE_UTF8, 0, - renameTableFunc, 0, 0); + static const struct { + char *zName; + signed char nArg; + void (*xFunc)(sqlite3_context*,int,sqlite3_value **); + } aFuncs[] = { + { "sqlite_rename_table", 2, renameTableFunc}, #ifndef SQLITE_OMIT_TRIGGER - sqlite3CreateFunc(db, "sqlite_rename_trigger", 2, SQLITE_UTF8, 0, - renameTriggerFunc, 0, 0); + { "sqlite_rename_trigger", 2, renameTriggerFunc}, #endif + }; + int i; + + for(i=0; iname); - sqlite3DbFree(db, tmp); + sqlite3_free(tmp); } } } @@ -56442,7 +51401,7 @@ SQLITE_PRIVATE void sqlite3AlterRenameTable( "sql = sqlite_rename_trigger(sql, %Q), " "tbl_name = %Q " "WHERE %s;", zName, zName, zWhere); - sqlite3DbFree(db, zWhere); + sqlite3_free(zWhere); } #endif @@ -56450,8 +51409,8 @@ SQLITE_PRIVATE void sqlite3AlterRenameTable( reloadTableSchema(pParse, pTab, zName); exit_rename_table: - sqlite3SrcListDelete(db, pSrc); - sqlite3DbFree(db, zName); + sqlite3SrcListDelete(pSrc); + sqlite3_free(zName); } @@ -56551,7 +51510,7 @@ SQLITE_PRIVATE void sqlite3AlterFinishAddColumn(Parse *pParse, Token *pColDef){ zDb, SCHEMA_TABLE(iDb), pNew->addColOffset, zCol, pNew->addColOffset+1, zTab ); - sqlite3DbFree(db, zCol); + sqlite3_free(zCol); } /* If the default value of the new column is NULL, then set the file @@ -56618,7 +51577,6 @@ SQLITE_PRIVATE void sqlite3AlterBeginAddColumn(Parse *pParse, SrcList *pSrc){ if( !pNew ) goto exit_begin_add_column; pParse->pNewTable = pNew; pNew->nRef = 1; - pNew->db = db; pNew->nCol = pTab->nCol; assert( pNew->nCol>0 ); nAlloc = (((pNew->nCol-1)/8)*8)+8; @@ -56648,7 +51606,7 @@ SQLITE_PRIVATE void sqlite3AlterBeginAddColumn(Parse *pParse, SrcList *pSrc){ sqlite3ChangeCookie(pParse, iDb); exit_begin_add_column: - sqlite3SrcListDelete(db, pSrc); + sqlite3SrcListDelete(pSrc); return; } #endif /* SQLITE_ALTER_TABLE */ @@ -56668,7 +51626,7 @@ exit_begin_add_column: ************************************************************************* ** This file contains code associated with the ANALYZE command. ** -** @(#) $Id: analyze.c,v 1.43 2008/07/28 19:34:53 drh Exp $ +** @(#) $Id: analyze.c,v 1.42 2008/03/25 09:47:35 danielk1977 Exp $ */ #ifndef SQLITE_OMIT_ANALYZE @@ -56972,7 +51930,7 @@ SQLITE_PRIVATE void sqlite3Analyze(Parse *pParse, Token *pName1, Token *pName2){ z = sqlite3NameFromToken(db, pName1); if( z ){ pTab = sqlite3LocateTable(pParse, 0, z, 0); - sqlite3DbFree(db, z); + sqlite3_free(z); if( pTab ){ analyzeTable(pParse, pTab); } @@ -56986,7 +51944,7 @@ SQLITE_PRIVATE void sqlite3Analyze(Parse *pParse, Token *pName1, Token *pName2){ z = sqlite3NameFromToken(db, pTableName); if( z ){ pTab = sqlite3LocateTable(pParse, 0, z, zDb); - sqlite3DbFree(db, z); + sqlite3_free(z); if( pTab ){ analyzeTable(pParse, pTab); } @@ -57073,7 +52031,7 @@ SQLITE_PRIVATE int sqlite3AnalysisLoad(sqlite3 *db, int iDb){ (void)sqlite3SafetyOff(db); rc = sqlite3_exec(db, zSql, analysisLoader, &sInfo, 0); (void)sqlite3SafetyOn(db); - sqlite3DbFree(db, zSql); + sqlite3_free(zSql); return rc; } @@ -57095,7 +52053,7 @@ SQLITE_PRIVATE int sqlite3AnalysisLoad(sqlite3 *db, int iDb){ ************************************************************************* ** This file contains code used to implement the ATTACH and DETACH commands. ** -** $Id: attach.c,v 1.78 2008/08/20 16:35:10 drh Exp $ +** $Id: attach.c,v 1.75 2008/04/17 17:02:01 drh Exp $ */ #ifndef SQLITE_OMIT_ATTACH @@ -57122,7 +52080,7 @@ static int resolveAttachExpr(NameContext *pName, Expr *pExpr) int rc = SQLITE_OK; if( pExpr ){ if( pExpr->op!=TK_ID ){ - rc = sqlite3ResolveExprNames(pName, pExpr); + rc = sqlite3ExprResolveNames(pName, pExpr); if( rc==SQLITE_OK && !sqlite3ExprIsConstant(pExpr) ){ sqlite3ErrorMsg(pName->pParse, "invalid name: \"%T\"", &pExpr->span); return SQLITE_ERROR; @@ -57195,12 +52153,18 @@ static void attachFunc( ** hash tables. */ if( db->aDb==db->aDbStatic ){ - aNew = sqlite3DbMallocRaw(db, sizeof(db->aDb[0])*3 ); - if( aNew==0 ) return; + aNew = sqlite3_malloc( sizeof(db->aDb[0])*3 ); + if( aNew==0 ){ + db->mallocFailed = 1; + return; + } memcpy(aNew, db->aDb, sizeof(db->aDb[0])*2); }else{ - aNew = sqlite3DbRealloc(db, db->aDb, sizeof(db->aDb[0])*(db->nDb+1) ); - if( aNew==0 ) return; + aNew = sqlite3_realloc(db->aDb, sizeof(db->aDb[0])*(db->nDb+1) ); + if( aNew==0 ){ + db->mallocFailed = 1; + return; + } } db->aDb = aNew; aNew = &db->aDb[db->nDb++]; @@ -57297,7 +52261,7 @@ attach_error: /* Return an error if we get here */ if( zErrDyn ){ sqlite3_result_error(context, zErrDyn, -1); - sqlite3DbFree(db, zErrDyn); + sqlite3_free(zErrDyn); }else{ zErr[sizeof(zErr)-1] = 0; sqlite3_result_error(context, zErr, -1); @@ -57388,7 +52352,7 @@ static void codeAttach( goto attach_end; } rc = sqlite3AuthCheck(pParse, type, zAuthArg, 0, 0); - sqlite3DbFree(db, zAuthArg); + sqlite3_free(zAuthArg); if(rc!=SQLITE_OK ){ goto attach_end; } @@ -57428,9 +52392,9 @@ static void codeAttach( } attach_end: - sqlite3ExprDelete(db, pFilename); - sqlite3ExprDelete(db, pDbname); - sqlite3ExprDelete(db, pKey); + sqlite3ExprDelete(pFilename); + sqlite3ExprDelete(pDbname); + sqlite3ExprDelete(pKey); } /* @@ -57868,7 +52832,7 @@ SQLITE_PRIVATE void sqlite3AuthContextPop(AuthContext *pContext){ ** COMMIT ** ROLLBACK ** -** $Id: build.c,v 1.498 2008/10/06 16:18:40 danielk1977 Exp $ +** $Id: build.c,v 1.484 2008/05/01 17:16:53 drh Exp $ */ /* @@ -57981,6 +52945,12 @@ SQLITE_PRIVATE void sqlite3FinishCoding(Parse *pParse){ if( db->mallocFailed ) return; if( pParse->nested ) return; if( pParse->nErr ) return; + if( !pParse->pVdbe ){ + if( pParse->rc==SQLITE_OK && pParse->nErr ){ + pParse->rc = SQLITE_ERROR; + return; + } + } /* Begin by generating some termination code at the end of the ** vdbe program @@ -58076,25 +53046,23 @@ SQLITE_PRIVATE void sqlite3FinishCoding(Parse *pParse){ SQLITE_PRIVATE void sqlite3NestedParse(Parse *pParse, const char *zFormat, ...){ va_list ap; char *zSql; - char *zErrMsg = 0; - sqlite3 *db = pParse->db; # define SAVE_SZ (sizeof(Parse) - offsetof(Parse,nVar)) char saveBuf[SAVE_SZ]; if( pParse->nErr ) return; assert( pParse->nested<10 ); /* Nesting should only be of limited depth */ va_start(ap, zFormat); - zSql = sqlite3VMPrintf(db, zFormat, ap); + zSql = sqlite3VMPrintf(pParse->db, zFormat, ap); va_end(ap); if( zSql==0 ){ + pParse->db->mallocFailed = 1; return; /* A malloc must have failed */ } pParse->nested++; memcpy(saveBuf, &pParse->nVar, SAVE_SZ); memset(&pParse->nVar, 0, SAVE_SZ); - sqlite3RunParser(pParse, zSql, &zErrMsg); - sqlite3DbFree(db, zErrMsg); - sqlite3DbFree(db, zSql); + sqlite3RunParser(pParse, zSql, 0); + sqlite3_free(zSql); memcpy(&pParse->nVar, saveBuf, SAVE_SZ); pParse->nested--; } @@ -58114,13 +53082,11 @@ SQLITE_PRIVATE void sqlite3NestedParse(Parse *pParse, const char *zFormat, ...){ SQLITE_PRIVATE Table *sqlite3FindTable(sqlite3 *db, const char *zName, const char *zDatabase){ Table *p = 0; int i; - int nName; assert( zName!=0 ); - nName = sqlite3Strlen(db, zName) + 1; for(i=OMIT_TEMPDB; inDb; i++){ int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */ if( zDatabase!=0 && sqlite3StrICmp(zDatabase, db->aDb[j].zName) ) continue; - p = sqlite3HashFind(&db->aDb[j].pSchema->tblHash, zName, nName); + p = sqlite3HashFind(&db->aDb[j].pSchema->tblHash, zName, strlen(zName)+1); if( p ) break; } return p; @@ -58178,14 +53144,13 @@ SQLITE_PRIVATE Table *sqlite3LocateTable( SQLITE_PRIVATE Index *sqlite3FindIndex(sqlite3 *db, const char *zName, const char *zDb){ Index *p = 0; int i; - int nName = sqlite3Strlen(db, zName)+1; for(i=OMIT_TEMPDB; inDb; i++){ int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */ Schema *pSchema = db->aDb[j].pSchema; if( zDb && sqlite3StrICmp(zDb, db->aDb[j].zName) ) continue; assert( pSchema || (j==1 && !db->aDb[1].pBt) ); if( pSchema ){ - p = sqlite3HashFind(&pSchema->idxHash, zName, nName); + p = sqlite3HashFind(&pSchema->idxHash, zName, strlen(zName)+1); } if( p ) break; } @@ -58196,9 +53161,8 @@ SQLITE_PRIVATE Index *sqlite3FindIndex(sqlite3 *db, const char *zName, const cha ** Reclaim the memory used by an index */ static void freeIndex(Index *p){ - sqlite3 *db = p->pTable->db; - sqlite3DbFree(db, p->zColAff); - sqlite3DbFree(db, p); + sqlite3_free(p->zColAff); + sqlite3_free(p); } /* @@ -58213,7 +53177,7 @@ static void sqliteDeleteIndex(Index *p){ Index *pOld; const char *zName = p->zName; - pOld = sqlite3HashInsert(&p->pSchema->idxHash, zName, strlen(zName)+1, 0); + pOld = sqlite3HashInsert(&p->pSchema->idxHash, zName, strlen( zName)+1, 0); assert( pOld==0 || pOld==p ); freeIndex(p); } @@ -58229,7 +53193,7 @@ SQLITE_PRIVATE void sqlite3UnlinkAndDeleteIndex(sqlite3 *db, int iDb, const char int len; Hash *pHash = &db->aDb[iDb].pSchema->idxHash; - len = sqlite3Strlen(db, zIdxName); + len = strlen(zIdxName); pIndex = sqlite3HashInsert(pHash, zIdxName, len+1, 0); if( pIndex ){ if( pIndex->pTable->pIndex==pIndex ){ @@ -58292,7 +53256,7 @@ SQLITE_PRIVATE void sqlite3ResetInternalSchema(sqlite3 *db, int iDb){ for(i=j=2; inDb; i++){ struct Db *pDb = &db->aDb[i]; if( pDb->pBt==0 ){ - sqlite3DbFree(db, pDb->zName); + sqlite3_free(pDb->zName); pDb->zName = 0; continue; } @@ -58305,7 +53269,7 @@ SQLITE_PRIVATE void sqlite3ResetInternalSchema(sqlite3 *db, int iDb){ db->nDb = j; if( db->nDb<=2 && db->aDb!=db->aDbStatic ){ memcpy(db->aDbStatic, db->aDb, 2*sizeof(db->aDb[0])); - sqlite3DbFree(db, db->aDb); + sqlite3_free(db->aDb); db->aDb = db->aDbStatic; } } @@ -58323,16 +53287,15 @@ SQLITE_PRIVATE void sqlite3CommitInternalChanges(sqlite3 *db){ static void sqliteResetColumnNames(Table *pTable){ int i; Column *pCol; - sqlite3 *db = pTable->db; assert( pTable!=0 ); if( (pCol = pTable->aCol)!=0 ){ for(i=0; inCol; i++, pCol++){ - sqlite3DbFree(db, pCol->zName); - sqlite3ExprDelete(db, pCol->pDflt); - sqlite3DbFree(db, pCol->zType); - sqlite3DbFree(db, pCol->zColl); + sqlite3_free(pCol->zName); + sqlite3ExprDelete(pCol->pDflt); + sqlite3_free(pCol->zType); + sqlite3_free(pCol->zColl); } - sqlite3DbFree(db, pTable->aCol); + sqlite3_free(pTable->aCol); } pTable->aCol = 0; pTable->nCol = 0; @@ -58351,10 +53314,8 @@ static void sqliteResetColumnNames(Table *pTable){ SQLITE_PRIVATE void sqlite3DeleteTable(Table *pTable){ Index *pIndex, *pNext; FKey *pFKey, *pNextFKey; - sqlite3 *db; if( pTable==0 ) return; - db = pTable->db; /* Do not delete the table until the reference count reaches zero. */ pTable->nRef--; @@ -58379,21 +53340,21 @@ SQLITE_PRIVATE void sqlite3DeleteTable(Table *pTable){ pNextFKey = pFKey->pNextFrom; assert( sqlite3HashFind(&pTable->pSchema->aFKey, pFKey->zTo, strlen(pFKey->zTo)+1)!=pFKey ); - sqlite3DbFree(db, pFKey); + sqlite3_free(pFKey); } #endif /* Delete the Table structure itself. */ sqliteResetColumnNames(pTable); - sqlite3DbFree(db, pTable->zName); - sqlite3DbFree(db, pTable->zColAff); - sqlite3SelectDelete(db, pTable->pSelect); + sqlite3_free(pTable->zName); + sqlite3_free(pTable->zColAff); + sqlite3SelectDelete(pTable->pSelect); #ifndef SQLITE_OMIT_CHECK - sqlite3ExprDelete(db, pTable->pCheck); + sqlite3ExprDelete(pTable->pCheck); #endif sqlite3VtabClear(pTable); - sqlite3DbFree(db, pTable); + sqlite3_free(pTable); } /* @@ -58483,7 +53444,7 @@ SQLITE_PRIVATE int sqlite3FindDb(sqlite3 *db, Token *pName){ break; } } - sqlite3DbFree(db, zName); + sqlite3_free(zName); } return i; } @@ -58674,7 +53635,6 @@ SQLITE_PRIVATE void sqlite3StartTable( pTable->iPKey = -1; pTable->pSchema = db->aDb[iDb].pSchema; pTable->nRef = 1; - pTable->db = db; if( pParse->pNewTable ) sqlite3DeleteTable(pParse->pNewTable); pParse->pNewTable = pTable; @@ -58754,7 +53714,7 @@ SQLITE_PRIVATE void sqlite3StartTable( /* If an error occurs, we jump here */ begin_table_error: - sqlite3DbFree(db, zName); + sqlite3_free(zName); return; } @@ -58797,7 +53757,7 @@ SQLITE_PRIVATE void sqlite3AddColumn(Parse *pParse, Token *pName){ for(i=0; inCol; i++){ if( STRICMP(z, p->aCol[i].zName) ){ sqlite3ErrorMsg(pParse, "duplicate column name: %s", z); - sqlite3DbFree(db, z); + sqlite3_free(z); return; } } @@ -58805,7 +53765,7 @@ SQLITE_PRIVATE void sqlite3AddColumn(Parse *pParse, Token *pName){ Column *aNew; aNew = sqlite3DbRealloc(pParse->db,p->aCol,(p->nCol+8)*sizeof(p->aCol[0])); if( aNew==0 ){ - sqlite3DbFree(db, z); + sqlite3_free(z); return; } p->aCol = aNew; @@ -58912,15 +53872,13 @@ SQLITE_PRIVATE void sqlite3AddColumnType(Parse *pParse, Token *pType){ Table *p; int i; Column *pCol; - sqlite3 *db; if( (p = pParse->pNewTable)==0 ) return; i = p->nCol-1; if( i<0 ) return; pCol = &p->aCol[i]; - db = pParse->db; - sqlite3DbFree(db, pCol->zType); - pCol->zType = sqlite3NameFromToken(db, pType); + sqlite3_free(pCol->zType); + pCol->zType = sqlite3NameFromToken(pParse->db, pType); pCol->affinity = sqlite3AffinityType(pType); } @@ -58937,7 +53895,6 @@ SQLITE_PRIVATE void sqlite3AddColumnType(Parse *pParse, Token *pType){ SQLITE_PRIVATE void sqlite3AddDefaultValue(Parse *pParse, Expr *pExpr){ Table *p; Column *pCol; - sqlite3 *db = pParse->db; if( (p = pParse->pNewTable)!=0 ){ pCol = &(p->aCol[p->nCol-1]); if( !sqlite3ExprIsConstantOrFunction(pExpr) ){ @@ -58945,14 +53902,15 @@ SQLITE_PRIVATE void sqlite3AddDefaultValue(Parse *pParse, Expr *pExpr){ pCol->zName); }else{ Expr *pCopy; - sqlite3ExprDelete(db, pCol->pDflt); + sqlite3 *db = pParse->db; + sqlite3ExprDelete(pCol->pDflt); pCol->pDflt = pCopy = sqlite3ExprDup(db, pExpr); if( pCopy ){ sqlite3TokenCopy(db, &pCopy->span, &pExpr->span); } } } - sqlite3ExprDelete(db, pExpr); + sqlite3ExprDelete(pExpr); } /* @@ -58984,12 +53942,12 @@ SQLITE_PRIVATE void sqlite3AddPrimaryKey( char *zType = 0; int iCol = -1, i; if( pTab==0 || IN_DECLARE_VTAB ) goto primary_key_exit; - if( pTab->tabFlags & TF_HasPrimaryKey ){ + if( pTab->hasPrimKey ){ sqlite3ErrorMsg(pParse, "table \"%s\" has more than one primary key", pTab->zName); goto primary_key_exit; } - pTab->tabFlags |= TF_HasPrimaryKey; + pTab->hasPrimKey = 1; if( pList==0 ){ iCol = pTab->nCol - 1; pTab->aCol[iCol].isPrimKey = 1; @@ -59013,8 +53971,7 @@ SQLITE_PRIVATE void sqlite3AddPrimaryKey( && sortOrder==SQLITE_SO_ASC ){ pTab->iPKey = iCol; pTab->keyConf = onError; - assert( autoInc==0 || autoInc==1 ); - pTab->tabFlags |= autoInc*TF_Autoincrement; + pTab->autoInc = autoInc; }else if( autoInc ){ #ifndef SQLITE_OMIT_AUTOINCREMENT sqlite3ErrorMsg(pParse, "AUTOINCREMENT is only allowed on an " @@ -59026,7 +53983,7 @@ SQLITE_PRIVATE void sqlite3AddPrimaryKey( } primary_key_exit: - sqlite3ExprListDelete(pParse->db, pList); + sqlite3ExprListDelete(pList); return; } @@ -59037,9 +53994,9 @@ SQLITE_PRIVATE void sqlite3AddCheckConstraint( Parse *pParse, /* Parsing context */ Expr *pCheckExpr /* The check expression */ ){ - sqlite3 *db = pParse->db; #ifndef SQLITE_OMIT_CHECK Table *pTab = pParse->pNewTable; + sqlite3 *db = pParse->db; if( pTab && !IN_DECLARE_VTAB ){ /* The CHECK expression must be duplicated so that tokens refer ** to malloced space and not the (ephemeral) text of the CREATE TABLE @@ -59048,7 +54005,7 @@ SQLITE_PRIVATE void sqlite3AddCheckConstraint( sqlite3ExprDup(db, pCheckExpr)); } #endif - sqlite3ExprDelete(db, pCheckExpr); + sqlite3ExprDelete(pCheckExpr); } /* @@ -59059,12 +54016,11 @@ SQLITE_PRIVATE void sqlite3AddCollateType(Parse *pParse, Token *pToken){ Table *p; int i; char *zColl; /* Dequoted name of collation sequence */ - sqlite3 *db; if( (p = pParse->pNewTable)==0 ) return; i = p->nCol-1; - db = pParse->db; - zColl = sqlite3NameFromToken(db, pToken); + + zColl = sqlite3NameFromToken(pParse->db, pToken); if( !zColl ) return; if( sqlite3LocateCollSeq(pParse, zColl, -1) ){ @@ -59082,7 +54038,7 @@ SQLITE_PRIVATE void sqlite3AddCollateType(Parse *pParse, Token *pToken){ } } }else{ - sqlite3DbFree(db, zColl); + sqlite3_free(zColl); } } @@ -59115,7 +54071,7 @@ SQLITE_PRIVATE CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char *zName, i pColl = sqlite3GetCollSeq(db, pColl, zName, nName); if( !pColl ){ if( nName<0 ){ - nName = sqlite3Strlen(db, zName); + nName = strlen(zName); } sqlite3ErrorMsg(pParse, "no such collation sequence: %.*s", nName, zName); pColl = 0; @@ -59219,7 +54175,7 @@ static char *createTableStmt(sqlite3 *db, Table *p, int isTemp){ zEnd = "\n)"; } n += 35 + 6*p->nCol; - zStmt = sqlite3Malloc( n ); + zStmt = sqlite3_malloc( n ); if( zStmt==0 ){ db->mallocFailed = 1; return 0; @@ -59301,7 +54257,7 @@ SQLITE_PRIVATE void sqlite3EndTable( sNC.pParse = pParse; sNC.pSrcList = &sSrc; sNC.isCheck = 1; - if( sqlite3ResolveExprNames(&sNC, p->pCheck) ){ + if( sqlite3ExprResolveNames(&sNC, p->pCheck) ){ return; } } @@ -59369,15 +54325,14 @@ SQLITE_PRIVATE void sqlite3EndTable( SelectDest dest; Table *pSelTab; - assert(pParse->nTab==0); sqlite3VdbeAddOp3(v, OP_OpenWrite, 1, pParse->regRoot, iDb); sqlite3VdbeChangeP5(v, 1); pParse->nTab = 2; sqlite3SelectDestInit(&dest, SRT_Table, 1); - sqlite3Select(pParse, pSelect, &dest); + sqlite3Select(pParse, pSelect, &dest, 0, 0, 0, 0); sqlite3VdbeAddOp1(v, OP_Close, 1); if( pParse->nErr==0 ){ - pSelTab = sqlite3ResultSetOfSelect(pParse, pSelect); + pSelTab = sqlite3ResultSetOfSelect(pParse, 0, pSelect); if( pSelTab==0 ) return; assert( p->aCol==0 ); p->nCol = pSelTab->nCol; @@ -59416,14 +54371,14 @@ SQLITE_PRIVATE void sqlite3EndTable( zStmt, pParse->regRowid ); - sqlite3DbFree(db, zStmt); + sqlite3_free(zStmt); sqlite3ChangeCookie(pParse, iDb); #ifndef SQLITE_OMIT_AUTOINCREMENT /* Check to see if we need to create an sqlite_sequence table for ** keeping track of autoincrement keys. */ - if( p->tabFlags & TF_Autoincrement ){ + if( p->autoInc ){ Db *pDb = &db->aDb[iDb]; if( pDb->pSchema->pSeqTab==0 ){ sqlite3NestedParse(pParse, @@ -59506,13 +54461,13 @@ SQLITE_PRIVATE void sqlite3CreateView( if( pParse->nVar>0 ){ sqlite3ErrorMsg(pParse, "parameters are not allowed in views"); - sqlite3SelectDelete(db, pSelect); + sqlite3SelectDelete(pSelect); return; } sqlite3StartTable(pParse, pName1, pName2, isTemp, 1, 0, noErr); p = pParse->pNewTable; if( p==0 || pParse->nErr ){ - sqlite3SelectDelete(db, pSelect); + sqlite3SelectDelete(pSelect); return; } sqlite3TwoPartName(pParse, pName1, pName2, &pName); @@ -59520,7 +54475,7 @@ SQLITE_PRIVATE void sqlite3CreateView( if( sqlite3FixInit(&sFix, pParse, iDb, "view", pName) && sqlite3FixSelect(&sFix, pSelect) ){ - sqlite3SelectDelete(db, pSelect); + sqlite3SelectDelete(pSelect); return; } @@ -59530,7 +54485,7 @@ SQLITE_PRIVATE void sqlite3CreateView( ** they will persist after the current sqlite3_exec() call returns. */ p->pSelect = sqlite3SelectDup(db, pSelect); - sqlite3SelectDelete(db, pSelect); + sqlite3SelectDelete(pSelect); if( db->mallocFailed ){ return; } @@ -59619,10 +54574,10 @@ SQLITE_PRIVATE int sqlite3ViewGetColumnNames(Parse *pParse, Table *pTable){ #ifndef SQLITE_OMIT_AUTHORIZATION xAuth = db->xAuth; db->xAuth = 0; - pSelTab = sqlite3ResultSetOfSelect(pParse, pSel); + pSelTab = sqlite3ResultSetOfSelect(pParse, 0, pSel); db->xAuth = xAuth; #else - pSelTab = sqlite3ResultSetOfSelect(pParse, pSel); + pSelTab = sqlite3ResultSetOfSelect(pParse, 0, pSel); #endif pParse->nTab = n; if( pSelTab ){ @@ -59637,7 +54592,7 @@ SQLITE_PRIVATE int sqlite3ViewGetColumnNames(Parse *pParse, Table *pTable){ pTable->nCol = 0; nErr++; } - sqlite3SelectDelete(db, pSel); + sqlite3SelectDelete(pSel); } else { nErr++; } @@ -59856,7 +54811,7 @@ SQLITE_PRIVATE void sqlite3DropTable(Parse *pParse, SrcList *pName, int isView, } } #endif - if( sqlite3StrNICmp(pTab->zName, "sqlite_", 7)==0 ){ + if( pTab->readOnly || pTab==db->aDb[iDb].pSchema->pSeqTab ){ sqlite3ErrorMsg(pParse, "table %s may not be dropped", pTab->zName); goto exit_drop_table; } @@ -59911,7 +54866,7 @@ SQLITE_PRIVATE void sqlite3DropTable(Parse *pParse, SrcList *pName, int isView, ** at the btree level, in case the sqlite_sequence table needs to ** move as a result of the drop (can happen in auto-vacuum mode). */ - if( pTab->tabFlags & TF_Autoincrement ){ + if( pTab->autoInc ){ sqlite3NestedParse(pParse, "DELETE FROM %s.sqlite_sequence WHERE name=%Q", pDb->zName, pTab->zName @@ -59953,7 +54908,7 @@ SQLITE_PRIVATE void sqlite3DropTable(Parse *pParse, SrcList *pName, int isView, sqliteViewResetAll(db, iDb); exit_drop_table: - sqlite3SrcListDelete(db, pName); + sqlite3SrcListDelete(pName); } /* @@ -59981,7 +54936,6 @@ SQLITE_PRIVATE void sqlite3CreateForeignKey( ExprList *pToCol, /* Columns in the other table */ int flags /* Conflict resolution algorithms. */ ){ - sqlite3 *db = pParse->db; #ifndef SQLITE_OMIT_FOREIGN_KEY FKey *pFKey = 0; Table *p = pParse->pNewTable; @@ -60016,7 +54970,7 @@ SQLITE_PRIVATE void sqlite3CreateForeignKey( nByte += strlen(pToCol->a[i].zName) + 1; } } - pFKey = sqlite3DbMallocZero(db, nByte ); + pFKey = sqlite3DbMallocZero(pParse->db, nByte ); if( pFKey==0 ){ goto fk_end; } @@ -60070,10 +55024,10 @@ SQLITE_PRIVATE void sqlite3CreateForeignKey( pFKey = 0; fk_end: - sqlite3DbFree(db, pFKey); + sqlite3_free(pFKey); #endif /* !defined(SQLITE_OMIT_FOREIGN_KEY) */ - sqlite3ExprListDelete(db, pFromCol); - sqlite3ExprListDelete(db, pToCol); + sqlite3ExprListDelete(pFromCol); + sqlite3ExprListDelete(pToCol); } /* @@ -60151,7 +55105,7 @@ static void sqlite3RefillIndex(Parse *pParse, Index *pIndex, int memRootPage){ regRowid = regIdxKey + pIndex->nColumn; j1 = sqlite3VdbeAddOp3(v, OP_IsNull, regIdxKey, 0, pIndex->nColumn); j2 = sqlite3VdbeAddOp4(v, OP_IsUnique, iIdx, - 0, regRowid, SQLITE_INT_TO_PTR(regRecord), P4_INT32); + 0, regRowid, (char*)regRecord, P4_INT32); sqlite3VdbeAddOp4(v, OP_Halt, SQLITE_CONSTRAINT, OE_Abort, 0, "indexed columns are not unique", P4_STATIC); sqlite3VdbeJumpHere(v, j1); @@ -60256,7 +55210,7 @@ SQLITE_PRIVATE void sqlite3CreateIndex( pDb = &db->aDb[iDb]; if( pTab==0 || pParse->nErr ) goto exit_create_index; - if( sqlite3StrNICmp(pTab->zName, "sqlite_", 7)==0 ){ + if( pTab->readOnly ){ sqlite3ErrorMsg(pParse, "table %s may not be indexed", pTab->zName); goto exit_create_index; } @@ -60307,11 +55261,15 @@ SQLITE_PRIVATE void sqlite3CreateIndex( goto exit_create_index; } }else{ + char zBuf[30]; int n; Index *pLoop; for(pLoop=pTab->pIndex, n=1; pLoop; pLoop=pLoop->pNext, n++){} - zName = sqlite3MPrintf(db, "sqlite_autoindex_%s_%d", pTab->zName, n); + sqlite3_snprintf(sizeof(zBuf),zBuf,"_%d",n); + zName = 0; + sqlite3SetString(&zName, "sqlite_autoindex_", pTab->zName, zBuf, (char*)0); if( zName==0 ){ + db->mallocFailed = 1; goto exit_create_index; } } @@ -60348,10 +55306,9 @@ SQLITE_PRIVATE void sqlite3CreateIndex( ** specified collation sequence names. */ for(i=0; inExpr; i++){ - Expr *pExpr; - CollSeq *pColl; - if( (pExpr = pList->a[i].pExpr)!=0 && (pColl = pExpr->pColl)!=0 ){ - nExtra += (1 + strlen(pColl->zName)); + Expr *pExpr = pList->a[i].pExpr; + if( pExpr ){ + nExtra += (1 + strlen(pExpr->pColl->zName)); } } @@ -60418,7 +55375,7 @@ SQLITE_PRIVATE void sqlite3CreateIndex( ** break backwards compatibility - it needs to be a warning. */ pIndex->aiColumn[i] = j; - if( pListItem->pExpr && pListItem->pExpr->pColl ){ + if( pListItem->pExpr ){ assert( pListItem->pExpr->pColl ); zColl = zExtra; sqlite3_snprintf(nExtra, zExtra, "%s", pListItem->pExpr->pColl->zName); @@ -60561,7 +55518,7 @@ SQLITE_PRIVATE void sqlite3CreateIndex( iMem, zStmt ); - sqlite3DbFree(db, zStmt); + sqlite3_free(zStmt); /* Fill the index with data and reparse the schema. Code an OP_Expire ** to invalidate all pre-compiled statements. @@ -60601,9 +55558,9 @@ exit_create_index: if( pIndex ){ freeIndex(pIndex); } - sqlite3ExprListDelete(db, pList); - sqlite3SrcListDelete(db, pTblName); - sqlite3DbFree(db, zName); + sqlite3ExprListDelete(pList); + sqlite3SrcListDelete(pTblName); + sqlite3_free(zName); return; } @@ -60732,7 +55689,7 @@ SQLITE_PRIVATE void sqlite3DropIndex(Parse *pParse, SrcList *pName, int ifExists } exit_drop_index: - sqlite3SrcListDelete(db, pName); + sqlite3SrcListDelete(pName); } /* @@ -60802,7 +55759,7 @@ SQLITE_PRIVATE IdList *sqlite3IdListAppend(sqlite3 *db, IdList *pList, Token *pT &i ); if( i<0 ){ - sqlite3IdListDelete(db, pList); + sqlite3IdListDelete(pList); return 0; } pList->a[i].zName = sqlite3NameFromToken(db, pToken); @@ -60812,14 +55769,14 @@ SQLITE_PRIVATE IdList *sqlite3IdListAppend(sqlite3 *db, IdList *pList, Token *pT /* ** Delete an IdList. */ -SQLITE_PRIVATE void sqlite3IdListDelete(sqlite3 *db, IdList *pList){ +SQLITE_PRIVATE void sqlite3IdListDelete(IdList *pList){ int i; if( pList==0 ) return; for(i=0; inId; i++){ - sqlite3DbFree(db, pList->a[i].zName); + sqlite3_free(pList->a[i].zName); } - sqlite3DbFree(db, pList->a); - sqlite3DbFree(db, pList); + sqlite3_free(pList->a); + sqlite3_free(pList); } /* @@ -60878,7 +55835,7 @@ SQLITE_PRIVATE SrcList *sqlite3SrcListAppend( pNew = sqlite3DbRealloc(db, pList, sizeof(*pList) + (pList->nAlloc-1)*sizeof(pList->a[0]) ); if( pNew==0 ){ - sqlite3SrcListDelete(db, pList); + sqlite3SrcListDelete(pList); return 0; } pList = pNew; @@ -60896,6 +55853,7 @@ SQLITE_PRIVATE SrcList *sqlite3SrcListAppend( pItem->zName = sqlite3NameFromToken(db, pTable); pItem->zDatabase = sqlite3NameFromToken(db, pDatabase); pItem->iCursor = -1; + pItem->isPopulated = 0; pList->nSrc++; return pList; } @@ -60921,21 +55879,20 @@ SQLITE_PRIVATE void sqlite3SrcListAssignCursors(Parse *pParse, SrcList *pList){ /* ** Delete an entire SrcList including all its substructure. */ -SQLITE_PRIVATE void sqlite3SrcListDelete(sqlite3 *db, SrcList *pList){ +SQLITE_PRIVATE void sqlite3SrcListDelete(SrcList *pList){ int i; struct SrcList_item *pItem; if( pList==0 ) return; for(pItem=pList->a, i=0; inSrc; i++, pItem++){ - sqlite3DbFree(db, pItem->zDatabase); - sqlite3DbFree(db, pItem->zName); - sqlite3DbFree(db, pItem->zAlias); - sqlite3DbFree(db, pItem->zIndex); + sqlite3_free(pItem->zDatabase); + sqlite3_free(pItem->zName); + sqlite3_free(pItem->zAlias); sqlite3DeleteTable(pItem->pTab); - sqlite3SelectDelete(db, pItem->pSelect); - sqlite3ExprDelete(db, pItem->pOn); - sqlite3IdListDelete(db, pItem->pUsing); + sqlite3SelectDelete(pItem->pSelect); + sqlite3ExprDelete(pItem->pOn); + sqlite3IdListDelete(pItem->pUsing); } - sqlite3DbFree(db, pList); + sqlite3_free(pList); } /* @@ -60968,9 +55925,9 @@ SQLITE_PRIVATE SrcList *sqlite3SrcListAppendFromTerm( sqlite3 *db = pParse->db; p = sqlite3SrcListAppend(db, p, pTable, pDatabase); if( p==0 || p->nSrc==0 ){ - sqlite3ExprDelete(db, pOn); - sqlite3IdListDelete(db, pUsing); - sqlite3SelectDelete(db, pSubquery); + sqlite3ExprDelete(pOn); + sqlite3IdListDelete(pUsing); + sqlite3SelectDelete(pSubquery); return p; } pItem = &p->a[p->nSrc-1]; @@ -60983,24 +55940,6 @@ SQLITE_PRIVATE SrcList *sqlite3SrcListAppendFromTerm( return p; } -/* -** Add an INDEXED BY or NOT INDEXED clause to the most recently added -** element of the source-list passed as the second argument. -*/ -SQLITE_PRIVATE void sqlite3SrcListIndexedBy(Parse *pParse, SrcList *p, Token *pIndexedBy){ - if( pIndexedBy && p && p->nSrc>0 ){ - struct SrcList_item *pItem = &p->a[p->nSrc-1]; - assert( pItem->notIndexed==0 && pItem->zIndex==0 ); - if( pIndexedBy->n==1 && !pIndexedBy->z ){ - /* A "NOT INDEXED" clause was supplied. See parse.y - ** construct "indexed_opt" for details. */ - pItem->notIndexed = 1; - }else{ - pItem->zIndex = sqlite3NameFromToken(pParse->db, pIndexedBy); - } - } -} - /* ** When building up a FROM clause in the parser, the join operator ** is initially attached to the left operand. But the code generator @@ -61293,11 +56232,11 @@ SQLITE_PRIVATE void sqlite3Reindex(Parse *pParse, Token *pName1, Token *pName2){ if( pColl ){ if( zColl ){ reindexDatabases(pParse, zColl); - sqlite3DbFree(db, zColl); + sqlite3_free(zColl); } return; } - sqlite3DbFree(db, zColl); + sqlite3_free(zColl); } iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pObjName); if( iDb<0 ) return; @@ -61307,11 +56246,11 @@ SQLITE_PRIVATE void sqlite3Reindex(Parse *pParse, Token *pName1, Token *pName2){ pTab = sqlite3FindTable(db, z, zDb); if( pTab ){ reindexTable(pParse, pTab, 0); - sqlite3DbFree(db, z); + sqlite3_free(z); return; } pIndex = sqlite3FindIndex(db, z, zDb); - sqlite3DbFree(db, z); + sqlite3_free(z); if( pIndex ){ sqlite3BeginWriteOperation(pParse, 0, iDb); sqlite3RefillIndex(pParse, pIndex, -1); @@ -61326,7 +56265,7 @@ SQLITE_PRIVATE void sqlite3Reindex(Parse *pParse, Token *pName1, Token *pName2){ ** with OP_OpenRead or OP_OpenWrite to access database index pIdx. ** ** If successful, a pointer to the new structure is returned. In this case -** the caller is responsible for calling sqlite3DbFree(db, ) on the returned +** the caller is responsible for calling sqlite3_free() on the returned ** pointer. If an error occurs (out of memory or missing collation ** sequence), NULL is returned and the state of pParse updated to reflect ** the error. @@ -61335,8 +56274,7 @@ SQLITE_PRIVATE KeyInfo *sqlite3IndexKeyinfo(Parse *pParse, Index *pIdx){ int i; int nCol = pIdx->nColumn; int nBytes = sizeof(KeyInfo) + (nCol-1)*sizeof(CollSeq*) + nCol; - sqlite3 *db = pParse->db; - KeyInfo *pKey = (KeyInfo *)sqlite3DbMallocZero(db, nBytes); + KeyInfo *pKey = (KeyInfo *)sqlite3DbMallocZero(pParse->db, nBytes); if( pKey ){ pKey->db = pParse->db; @@ -61352,7 +56290,7 @@ SQLITE_PRIVATE KeyInfo *sqlite3IndexKeyinfo(Parse *pParse, Index *pIdx){ } if( pParse->nErr ){ - sqlite3DbFree(db, pKey); + sqlite3_free(pKey); pKey = 0; } return pKey; @@ -61375,7 +56313,7 @@ SQLITE_PRIVATE KeyInfo *sqlite3IndexKeyinfo(Parse *pParse, Index *pIdx){ ** This file contains functions used to access the internal hash tables ** of user defined functions and collation sequences. ** -** $Id: callback.c,v 1.32 2008/10/10 17:41:29 drh Exp $ +** $Id: callback.c,v 1.23 2007/08/29 12:31:26 danielk1977 Exp $ */ @@ -61386,12 +56324,12 @@ SQLITE_PRIVATE KeyInfo *sqlite3IndexKeyinfo(Parse *pParse, Index *pIdx){ */ static void callCollNeeded(sqlite3 *db, const char *zName, int nName){ assert( !db->xCollNeeded || !db->xCollNeeded16 ); - if( nName<0 ) nName = sqlite3Strlen(db, zName); + if( nName<0 ) nName = strlen(zName); if( db->xCollNeeded ){ char *zExternal = sqlite3DbStrNDup(db, zName, nName); if( !zExternal ) return; db->xCollNeeded(db->pCollNeededArg, db, (int)ENC(db), zExternal); - sqlite3DbFree(db, zExternal); + sqlite3_free(zExternal); } #ifndef SQLITE_OMIT_UTF16 if( db->xCollNeeded16 ){ @@ -61519,7 +56457,7 @@ static CollSeq *findCollSeqEntry( int create ){ CollSeq *pColl; - if( nName<0 ) nName = sqlite3Strlen(db, zName); + if( nName<0 ) nName = strlen(zName); pColl = sqlite3HashFind(&db->aCollSeq, zName, nName); if( 0==pColl && create ){ @@ -61543,7 +56481,7 @@ static CollSeq *findCollSeqEntry( assert( pDel==0 || pDel==pColl ); if( pDel!=0 ){ db->mallocFailed = 1; - sqlite3DbFree(db, pDel); + sqlite3_free(pDel); pColl = 0; } } @@ -61583,87 +56521,6 @@ SQLITE_PRIVATE CollSeq *sqlite3FindCollSeq( return pColl; } -/* During the search for the best function definition, this procedure -** is called to test how well the function passed as the first argument -** matches the request for a function with nArg arguments in a system -** that uses encoding enc. The value returned indicates how well the -** request is matched. A higher value indicates a better match. -** -** The returned value is always between 1 and 6, as follows: -** -** 1: A variable arguments function that prefers UTF-8 when a UTF-16 -** encoding is requested, or vice versa. -** 2: A variable arguments function that uses UTF-16BE when UTF-16LE is -** requested, or vice versa. -** 3: A variable arguments function using the same text encoding. -** 4: A function with the exact number of arguments requested that -** prefers UTF-8 when a UTF-16 encoding is requested, or vice versa. -** 5: A function with the exact number of arguments requested that -** prefers UTF-16LE when UTF-16BE is requested, or vice versa. -** 6: An exact match. -** -*/ -static int matchQuality(FuncDef *p, int nArg, u8 enc){ - int match = 0; - if( p->nArg==-1 || p->nArg==nArg || nArg==-1 ){ - match = 1; - if( p->nArg==nArg || nArg==-1 ){ - match = 4; - } - if( enc==p->iPrefEnc ){ - match += 2; - } - else if( (enc==SQLITE_UTF16LE && p->iPrefEnc==SQLITE_UTF16BE) || - (enc==SQLITE_UTF16BE && p->iPrefEnc==SQLITE_UTF16LE) ){ - match += 1; - } - } - return match; -} - -/* -** Search a FuncDefHash for a function with the given name. Return -** a pointer to the matching FuncDef if found, or 0 if there is no match. -*/ -static FuncDef *functionSearch( - FuncDefHash *pHash, /* Hash table to search */ - int h, /* Hash of the name */ - const char *zFunc, /* Name of function */ - int nFunc /* Number of bytes in zFunc */ -){ - FuncDef *p; - for(p=pHash->a[h]; p; p=p->pHash){ - if( sqlite3StrNICmp(p->zName, zFunc, nFunc)==0 && p->zName[nFunc]==0 ){ - return p; - } - } - return 0; -} - -/* -** Insert a new FuncDef into a FuncDefHash hash table. -*/ -SQLITE_PRIVATE void sqlite3FuncDefInsert( - FuncDefHash *pHash, /* The hash table into which to insert */ - FuncDef *pDef /* The function definition to insert */ -){ - FuncDef *pOther; - int nName = strlen(pDef->zName); - u8 c1 = (u8)pDef->zName[0]; - int h = (sqlite3UpperToLower[c1] + nName) % ArraySize(pHash->a); - pOther = functionSearch(pHash, h, pDef->zName, nName); - if( pOther ){ - pDef->pNext = pOther->pNext; - pOther->pNext = pDef; - }else{ - pDef->pNext = 0; - pDef->pHash = pHash->a[h]; - pHash->a[h] = pDef; - } -} - - - /* ** Locate a user function given a name, a number of arguments and a flag ** indicating whether the function prefers UTF-16 over UTF-8. Return a @@ -61693,60 +56550,70 @@ SQLITE_PRIVATE FuncDef *sqlite3FindFunction( int createFlag /* Create new entry if true and does not otherwise exist */ ){ FuncDef *p; /* Iterator variable */ + FuncDef *pFirst; /* First function with this name */ FuncDef *pBest = 0; /* Best match found so far */ - int bestScore = 0; /* Score of best match */ - int h; /* Hash value */ + int bestmatch = 0; assert( enc==SQLITE_UTF8 || enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE ); if( nArg<-1 ) nArg = -1; - h = (sqlite3UpperToLower[(u8)zName[0]] + nName) % ArraySize(db->aFunc.a); - /* First search for a match amongst the application-defined functions. - */ - p = functionSearch(&db->aFunc, h, zName, nName); - while( p ){ - int score = matchQuality(p, nArg, enc); - if( score>bestScore ){ - pBest = p; - bestScore = score; - } - p = p->pNext; - } - - /* If no match is found, search the built-in functions. - ** - ** Except, if createFlag is true, that means that we are trying to - ** install a new function. Whatever FuncDef structure is returned will - ** have fields overwritten with new information appropriate for the - ** new function. But the FuncDefs for built-in functions are read-only. - ** So we must not search for built-ins when creating a new function. - */ - if( !createFlag && !pBest ){ - FuncDefHash *pHash = &GLOBAL(FuncDefHash, sqlite3GlobalFunctions); - p = functionSearch(pHash, h, zName, nName); - while( p ){ - int score = matchQuality(p, nArg, enc); - if( score>bestScore ){ - pBest = p; - bestScore = score; + pFirst = (FuncDef*)sqlite3HashFind(&db->aFunc, zName, nName); + for(p=pFirst; p; p=p->pNext){ + /* During the search for the best function definition, bestmatch is set + ** as follows to indicate the quality of the match with the definition + ** pointed to by pBest: + ** + ** 0: pBest is NULL. No match has been found. + ** 1: A variable arguments function that prefers UTF-8 when a UTF-16 + ** encoding is requested, or vice versa. + ** 2: A variable arguments function that uses UTF-16BE when UTF-16LE is + ** requested, or vice versa. + ** 3: A variable arguments function using the same text encoding. + ** 4: A function with the exact number of arguments requested that + ** prefers UTF-8 when a UTF-16 encoding is requested, or vice versa. + ** 5: A function with the exact number of arguments requested that + ** prefers UTF-16LE when UTF-16BE is requested, or vice versa. + ** 6: An exact match. + ** + ** A larger value of 'matchqual' indicates a more desirable match. + */ + if( p->nArg==-1 || p->nArg==nArg || nArg==-1 ){ + int match = 1; /* Quality of this match */ + if( p->nArg==nArg || nArg==-1 ){ + match = 4; + } + if( enc==p->iPrefEnc ){ + match += 2; + } + else if( (enc==SQLITE_UTF16LE && p->iPrefEnc==SQLITE_UTF16BE) || + (enc==SQLITE_UTF16BE && p->iPrefEnc==SQLITE_UTF16LE) ){ + match += 1; + } + + if( match>bestmatch ){ + pBest = p; + bestmatch = match; } - p = p->pNext; } } - /* If the createFlag parameter is true and the search did not reveal an + /* If the createFlag parameter is true, and the seach did not reveal an ** exact match for the name, number of arguments and encoding, then add a ** new entry to the hash table and return it. */ - if( createFlag && (bestScore<6 || pBest->nArg!=nArg) && - (pBest = sqlite3DbMallocZero(db, sizeof(*pBest)+nName+1))!=0 ){ - pBest->zName = (char *)&pBest[1]; + if( createFlag && bestmatch<6 && + (pBest = sqlite3DbMallocZero(db, sizeof(*pBest)+nName))!=0 ){ pBest->nArg = nArg; + pBest->pNext = pFirst; pBest->iPrefEnc = enc; memcpy(pBest->zName, zName, nName); pBest->zName[nName] = 0; - sqlite3FuncDefInsert(&db->aFunc, pBest); + if( pBest==sqlite3HashInsert(&db->aFunc,pBest->zName,nName,(void*)pBest) ){ + db->mallocFailed = 1; + sqlite3_free(pBest); + return 0; + } } if( pBest && (pBest->xStep || pBest->xFunc || createFlag) ){ @@ -61757,11 +56624,9 @@ SQLITE_PRIVATE FuncDef *sqlite3FindFunction( /* ** Free all resources held by the schema structure. The void* argument points -** at a Schema struct. This function does not call sqlite3DbFree(db, ) on the +** at a Schema struct. This function does not call sqlite3_free() on the ** pointer itself, it just cleans up subsiduary resources (i.e. the contents ** of the schema hash tables). -** -** The Schema.cache_size variable is not cleared. */ SQLITE_PRIVATE void sqlite3SchemaFree(void *p){ Hash temp1; @@ -61771,14 +56636,14 @@ SQLITE_PRIVATE void sqlite3SchemaFree(void *p){ temp1 = pSchema->tblHash; temp2 = pSchema->trigHash; - sqlite3HashInit(&pSchema->trigHash, 0); + sqlite3HashInit(&pSchema->trigHash, SQLITE_HASH_STRING, 0); sqlite3HashClear(&pSchema->aFKey); sqlite3HashClear(&pSchema->idxHash); for(pElem=sqliteHashFirst(&temp2); pElem; pElem=sqliteHashNext(pElem)){ - sqlite3DeleteTrigger(0, (Trigger*)sqliteHashData(pElem)); + sqlite3DeleteTrigger((Trigger*)sqliteHashData(pElem)); } sqlite3HashClear(&temp2); - sqlite3HashInit(&pSchema->tblHash, 0); + sqlite3HashInit(&pSchema->tblHash, SQLITE_HASH_STRING, 0); for(pElem=sqliteHashFirst(&temp1); pElem; pElem=sqliteHashNext(pElem)){ Table *pTab = sqliteHashData(pElem); sqlite3DeleteTable(pTab); @@ -61802,10 +56667,10 @@ SQLITE_PRIVATE Schema *sqlite3SchemaGet(sqlite3 *db, Btree *pBt){ if( !p ){ db->mallocFailed = 1; }else if ( 0==p->file_format ){ - sqlite3HashInit(&p->tblHash, 0); - sqlite3HashInit(&p->idxHash, 0); - sqlite3HashInit(&p->trigHash, 0); - sqlite3HashInit(&p->aFKey, 1); + sqlite3HashInit(&p->tblHash, SQLITE_HASH_STRING, 0); + sqlite3HashInit(&p->idxHash, SQLITE_HASH_STRING, 0); + sqlite3HashInit(&p->trigHash, SQLITE_HASH_STRING, 0); + sqlite3HashInit(&p->aFKey, SQLITE_HASH_STRING, 1); p->enc = SQLITE_UTF8; } return p; @@ -61827,7 +56692,7 @@ SQLITE_PRIVATE Schema *sqlite3SchemaGet(sqlite3 *db, Btree *pBt){ ** This file contains C code routines that are called by the parser ** in order to generate code for DELETE FROM statements. ** -** $Id: delete.c,v 1.182 2008/10/10 23:48:26 drh Exp $ +** $Id: delete.c,v 1.169 2008/04/28 18:46:43 drh Exp $ */ /* @@ -61836,17 +56701,16 @@ SQLITE_PRIVATE Schema *sqlite3SchemaGet(sqlite3 *db, Btree *pBt){ ** are found, return a pointer to the last table. */ SQLITE_PRIVATE Table *sqlite3SrcListLookup(Parse *pParse, SrcList *pSrc){ - struct SrcList_item *pItem = pSrc->a; - Table *pTab; - assert( pItem && pSrc->nSrc==1 ); - pTab = sqlite3LocateTable(pParse, 0, pItem->zName, pItem->zDatabase); - sqlite3DeleteTable(pItem->pTab); - pItem->pTab = pTab; - if( pTab ){ - pTab->nRef++; - } - if( sqlite3IndexedByLookup(pParse, pItem) ){ - pTab = 0; + Table *pTab = 0; + int i; + struct SrcList_item *pItem; + for(i=0, pItem=pSrc->a; inSrc; i++, pItem++){ + pTab = sqlite3LocateTable(pParse, 0, pItem->zName, pItem->zDatabase); + sqlite3DeleteTable(pItem->pTab); + pItem->pTab = pTab; + if( pTab ){ + pTab->nRef++; + } } return pTab; } @@ -61857,8 +56721,7 @@ SQLITE_PRIVATE Table *sqlite3SrcListLookup(Parse *pParse, SrcList *pSrc){ ** writable return 0; */ SQLITE_PRIVATE int sqlite3IsReadOnly(Parse *pParse, Table *pTab, int viewOk){ - if( ((pTab->tabFlags & TF_Readonly)!=0 - && (pParse->db->flags & SQLITE_WriteSchema)==0 + if( (pTab->readOnly && (pParse->db->flags & SQLITE_WriteSchema)==0 && pParse->nested==0) #ifndef SQLITE_OMIT_VIRTUALTABLE || (pTab->pMod && pTab->pMod->pModule->xUpdate==0) @@ -61905,7 +56768,7 @@ SQLITE_PRIVATE void sqlite3OpenTable( */ SQLITE_PRIVATE void sqlite3MaterializeView( Parse *pParse, /* Parsing context */ - Table *pView, /* View definition */ + Select *pView, /* View definition */ Expr *pWhere, /* Optional WHERE clause to be added */ int iCur /* Cursor number for ephemerial table */ ){ @@ -61913,114 +56776,20 @@ SQLITE_PRIVATE void sqlite3MaterializeView( Select *pDup; sqlite3 *db = pParse->db; - pDup = sqlite3SelectDup(db, pView->pSelect); + pDup = sqlite3SelectDup(db, pView); if( pWhere ){ SrcList *pFrom; - Token viewName; pWhere = sqlite3ExprDup(db, pWhere); - viewName.z = (u8*)pView->zName; - viewName.n = (unsigned int)strlen((const char*)viewName.z); - pFrom = sqlite3SrcListAppendFromTerm(pParse, 0, 0, 0, &viewName, pDup, 0,0); + pFrom = sqlite3SrcListAppendFromTerm(pParse, 0, 0, 0, 0, pDup, 0, 0); pDup = sqlite3SelectNew(pParse, 0, pFrom, pWhere, 0, 0, 0, 0, 0, 0); } sqlite3SelectDestInit(&dest, SRT_EphemTab, iCur); - sqlite3Select(pParse, pDup, &dest); - sqlite3SelectDelete(db, pDup); + sqlite3Select(pParse, pDup, &dest, 0, 0, 0, 0); + sqlite3SelectDelete(pDup); } #endif /* !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER) */ -#if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) && !defined(SQLITE_OMIT_SUBQUERY) -/* -** Generate an expression tree to implement the WHERE, ORDER BY, -** and LIMIT/OFFSET portion of DELETE and UPDATE statements. -** -** DELETE FROM table_wxyz WHERE a<5 ORDER BY a LIMIT 1; -** \__________________________/ -** pLimitWhere (pInClause) -*/ -SQLITE_PRIVATE Expr *sqlite3LimitWhere( - Parse *pParse, /* The parser context */ - SrcList *pSrc, /* the FROM clause -- which tables to scan */ - Expr *pWhere, /* The WHERE clause. May be null */ - ExprList *pOrderBy, /* The ORDER BY clause. May be null */ - Expr *pLimit, /* The LIMIT clause. May be null */ - Expr *pOffset, /* The OFFSET clause. May be null */ - char *zStmtType /* Either DELETE or UPDATE. For error messages. */ -){ - Expr *pWhereRowid = NULL; /* WHERE rowid .. */ - Expr *pInClause = NULL; /* WHERE rowid IN ( select ) */ - Expr *pSelectRowid = NULL; /* SELECT rowid ... */ - ExprList *pEList = NULL; /* Expression list contaning only pSelectRowid */ - SrcList *pSelectSrc = NULL; /* SELECT rowid FROM x ... (dup of pSrc) */ - Select *pSelect = NULL; /* Complete SELECT tree */ - - /* Check that there isn't an ORDER BY without a LIMIT clause. - */ - if( pOrderBy && (pLimit == 0) ) { - sqlite3ErrorMsg(pParse, "ORDER BY without LIMIT on %s", zStmtType); - pParse->parseError = 1; - goto limit_where_cleanup_2; - } - - /* We only need to generate a select expression if there - ** is a limit/offset term to enforce. - */ - if( pLimit == 0 ) { - /* if pLimit is null, pOffset will always be null as well. */ - assert( pOffset == 0 ); - return pWhere; - } - - /* Generate a select expression tree to enforce the limit/offset - ** term for the DELETE or UPDATE statement. For example: - ** DELETE FROM table_a WHERE col1=1 ORDER BY col2 LIMIT 1 OFFSET 1 - ** becomes: - ** DELETE FROM table_a WHERE rowid IN ( - ** SELECT rowid FROM table_a WHERE col1=1 ORDER BY col2 LIMIT 1 OFFSET 1 - ** ); - */ - - pSelectRowid = sqlite3Expr(pParse->db, TK_ROW, 0, 0, 0); - if( pSelectRowid == 0 ) goto limit_where_cleanup_2; - pEList = sqlite3ExprListAppend(pParse, 0, pSelectRowid, 0); - if( pEList == 0 ) goto limit_where_cleanup_2; - - /* duplicate the FROM clause as it is needed by both the DELETE/UPDATE tree - ** and the SELECT subtree. */ - pSelectSrc = sqlite3SrcListDup(pParse->db, pSrc); - if( pSelectSrc == 0 ) { - sqlite3ExprListDelete(pParse->db, pEList); - goto limit_where_cleanup_2; - } - - /* generate the SELECT expression tree. */ - pSelect = sqlite3SelectNew(pParse,pEList,pSelectSrc,pWhere,0,0,pOrderBy,0,pLimit,pOffset); - if( pSelect == 0 ) return 0; - - /* now generate the new WHERE rowid IN clause for the DELETE/UDPATE */ - pWhereRowid = sqlite3Expr(pParse->db, TK_ROW, 0, 0, 0); - if( pWhereRowid == 0 ) goto limit_where_cleanup_1; - pInClause = sqlite3PExpr(pParse, TK_IN, pWhereRowid, 0, 0); - if( pInClause == 0 ) goto limit_where_cleanup_1; - - pInClause->pSelect = pSelect; - sqlite3ExprSetHeight(pParse, pInClause); - return pInClause; - - /* something went wrong. clean up anything allocated. */ -limit_where_cleanup_1: - sqlite3SelectDelete(pParse->db, pSelect); - return 0; - -limit_where_cleanup_2: - sqlite3ExprDelete(pParse->db, pWhere); - sqlite3ExprListDelete(pParse->db, pOrderBy); - sqlite3ExprDelete(pParse->db, pLimit); - sqlite3ExprDelete(pParse->db, pOffset); - return 0; -} -#endif /* defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) && !defined(SQLITE_OMIT_SUBQUERY) */ /* ** Generate code for a DELETE FROM statement. @@ -62155,18 +56924,16 @@ SQLITE_PRIVATE void sqlite3DeleteFrom( /* If we are trying to delete from a view, realize that view into ** a ephemeral table. */ -#if !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER) if( isView ){ - sqlite3MaterializeView(pParse, pTab, pWhere, iCur); + sqlite3MaterializeView(pParse, pTab->pSelect, pWhere, iCur); } -#endif /* Resolve the column names in the WHERE clause. */ memset(&sNC, 0, sizeof(sNC)); sNC.pParse = pParse; sNC.pSrcList = pTabList; - if( sqlite3ResolveExprNames(&sNC, pWhere) ){ + if( sqlite3ExprResolveNames(&sNC, pWhere) ){ goto delete_from_cleanup; } @@ -62178,7 +56945,6 @@ SQLITE_PRIVATE void sqlite3DeleteFrom( sqlite3VdbeAddOp2(v, OP_Integer, 0, memCnt); } -#ifndef SQLITE_OMIT_TRUNCATE_OPTIMIZATION /* Special case: A DELETE without a WHERE clause deletes everything. ** It is easier just to erase the whole table. Note, however, that ** this means that the row change count will be incorrect. @@ -62206,12 +56972,11 @@ SQLITE_PRIVATE void sqlite3DeleteFrom( sqlite3VdbeAddOp2(v, OP_Clear, pIdx->tnum, iDb); } } - }else -#endif /* SQLITE_OMIT_TRUNCATE_OPTIMIZATION */ + } /* The usual case: There is a WHERE clause so we have to scan through ** the table and pick which records to delete. */ - { + else{ int iRowid = ++pParse->nMem; /* Used for storing rowid values. */ /* Begin the database scan @@ -62329,8 +57094,8 @@ SQLITE_PRIVATE void sqlite3DeleteFrom( delete_from_cleanup: sqlite3AuthContextPop(&sContext); - sqlite3SrcListDelete(db, pTabList); - sqlite3ExprDelete(db, pWhere); + sqlite3SrcListDelete(pTabList); + sqlite3ExprDelete(pWhere); return; } @@ -62477,9 +57242,10 @@ SQLITE_PRIVATE int sqlite3GenerateIndexKey( ** sqliteRegisterBuildinFunctions() found at the bottom of the file. ** All other code has file scope. ** -** $Id: func.c,v 1.203 2008/09/03 17:11:16 drh Exp $ +** $Id: func.c,v 1.192 2008/04/27 18:40:12 drh Exp $ */ + /* ** Return the collating function associated with a function. */ @@ -62704,7 +57470,7 @@ static void *contextMalloc(sqlite3_context *context, i64 nByte){ sqlite3_result_error_toobig(context); z = 0; }else{ - z = sqlite3Malloc(nByte); + z = sqlite3_malloc(nByte); if( !z && nByte>0 ){ sqlite3_result_error_nomem(context); } @@ -63287,14 +58053,14 @@ static void replaceFunc( nOut += nRep - nPattern; if( nOut>=db->aLimit[SQLITE_LIMIT_LENGTH] ){ sqlite3_result_error_toobig(context); - sqlite3DbFree(db, zOut); + sqlite3_free(zOut); return; } zOld = zOut; zOut = sqlite3_realloc(zOut, (int)nOut); if( zOut==0 ){ sqlite3_result_error_nomem(context); - sqlite3DbFree(db, zOld); + sqlite3_free(zOld); return; } memcpy(&zOut[j], zRep, nRep); @@ -63337,7 +58103,7 @@ static void trimFunc( assert( zIn==sqlite3_value_text(argv[0]) ); if( argc==1 ){ static const unsigned char lenOne[] = { 1 }; - static unsigned char * const azOne[] = { (u8*)" " }; + static const unsigned char *azOne[] = { (u8*)" " }; nChar = 1; aLen = (u8*)lenOne; azChar = (unsigned char **)azOne; @@ -63363,7 +58129,7 @@ static void trimFunc( } } if( nChar>0 ){ - flags = SQLITE_PTR_TO_INT(sqlite3_user_data(context)); + flags = (int)sqlite3_user_data(context); if( flags & 1 ){ while( nIn>0 ){ int len; @@ -63394,7 +58160,6 @@ static void trimFunc( sqlite3_result_text(context, (char*)zIn, nIn, SQLITE_TRANSIENT); } - #ifdef SQLITE_SOUNDEX /* ** Compute the soundex encoding of a word. @@ -63622,8 +58387,8 @@ static void groupConcatStep( const char *zVal; StrAccum *pAccum; const char *zSep; - int nVal, nSep, i; - if( argc==0 || sqlite3_value_type(argv[0])==SQLITE_NULL ) return; + int nVal, nSep; + if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return; pAccum = (StrAccum*)sqlite3_aggregate_context(context, sizeof(*pAccum)); if( pAccum ){ @@ -63631,22 +58396,18 @@ static void groupConcatStep( pAccum->useMalloc = 1; pAccum->mxAlloc = db->aLimit[SQLITE_LIMIT_LENGTH]; if( pAccum->nChar ){ - if( argc>1 ){ - zSep = (char*)sqlite3_value_text(argv[argc-1]); - nSep = sqlite3_value_bytes(argv[argc-1]); + if( argc==2 ){ + zSep = (char*)sqlite3_value_text(argv[1]); + nSep = sqlite3_value_bytes(argv[1]); }else{ zSep = ","; nSep = 1; } sqlite3StrAccumAppend(pAccum, zSep, nSep); } - i = 0; - do{ - zVal = (char*)sqlite3_value_text(argv[i]); - nVal = sqlite3_value_bytes(argv[i]); - sqlite3StrAccumAppend(pAccum, zVal, nVal); - i++; - }while( ineedCollSeq = 1; + } + } + } #ifndef SQLITE_OMIT_ALTERTABLE sqlite3AlterFunctions(db); #endif #ifndef SQLITE_OMIT_PARSER sqlite3AttachFunctions(db); #endif + for(i=0; ineedCollSeq = 1; + } + } + } + sqlite3RegisterDateTimeFunctions(db); if( !db->mallocFailed ){ int rc = sqlite3_overload_function(db, "MATCH", 2); assert( rc==SQLITE_NOMEM || rc==SQLITE_OK ); @@ -63686,6 +58544,11 @@ SQLITE_PRIVATE void sqlite3RegisterBuiltinFunctions(sqlite3 *db){ #ifdef SQLITE_SSE (void)sqlite3SseFunctions(db); #endif +#ifdef SQLITE_CASE_SENSITIVE_LIKE + sqlite3RegisterLikeFunctions(db, 1); +#else + sqlite3RegisterLikeFunctions(db, 0); +#endif } /* @@ -63753,93 +58616,6 @@ SQLITE_PRIVATE int sqlite3IsLikeFunction(sqlite3 *db, Expr *pExpr, int *pIsNocas return 1; } -/* -** All all of the FuncDef structures in the aBuiltinFunc[] array above -** to the global function hash table. This occurs at start-time (as -** a consequence of calling sqlite3_initialize()). -** -** After this routine runs -*/ -SQLITE_PRIVATE void sqlite3RegisterGlobalFunctions(void){ - /* - ** The following array holds FuncDef structures for all of the functions - ** defined in this file. - ** - ** The array cannot be constant since changes are made to the - ** FuncDef.pHash elements at start-time. The elements of this array - ** are read-only after initialization is complete. - */ - static SQLITE_WSD FuncDef aBuiltinFunc[] = { - FUNCTION(ltrim, 1, 1, 0, trimFunc ), - FUNCTION(ltrim, 2, 1, 0, trimFunc ), - FUNCTION(rtrim, 1, 2, 0, trimFunc ), - FUNCTION(rtrim, 2, 2, 0, trimFunc ), - FUNCTION(trim, 1, 3, 0, trimFunc ), - FUNCTION(trim, 2, 3, 0, trimFunc ), - FUNCTION(min, -1, 0, 1, minmaxFunc ), - FUNCTION(min, 0, 0, 1, 0 ), - AGGREGATE(min, 1, 0, 1, minmaxStep, minMaxFinalize ), - FUNCTION(max, -1, 1, 1, minmaxFunc ), - FUNCTION(max, 0, 1, 1, 0 ), - AGGREGATE(max, 1, 1, 1, minmaxStep, minMaxFinalize ), - FUNCTION(typeof, 1, 0, 0, typeofFunc ), - FUNCTION(length, 1, 0, 0, lengthFunc ), - FUNCTION(substr, 2, 0, 0, substrFunc ), - FUNCTION(substr, 3, 0, 0, substrFunc ), - FUNCTION(abs, 1, 0, 0, absFunc ), - FUNCTION(round, 1, 0, 0, roundFunc ), - FUNCTION(round, 2, 0, 0, roundFunc ), - FUNCTION(upper, 1, 0, 0, upperFunc ), - FUNCTION(lower, 1, 0, 0, lowerFunc ), - FUNCTION(coalesce, 1, 0, 0, 0 ), - FUNCTION(coalesce, -1, 0, 0, ifnullFunc ), - FUNCTION(coalesce, 0, 0, 0, 0 ), - FUNCTION(hex, 1, 0, 0, hexFunc ), - FUNCTION(ifnull, 2, 0, 1, ifnullFunc ), - FUNCTION(random, -1, 0, 0, randomFunc ), - FUNCTION(randomblob, 1, 0, 0, randomBlob ), - FUNCTION(nullif, 2, 0, 1, nullifFunc ), - FUNCTION(sqlite_version, 0, 0, 0, versionFunc ), - FUNCTION(quote, 1, 0, 0, quoteFunc ), - FUNCTION(last_insert_rowid, 0, 0, 0, last_insert_rowid), - FUNCTION(changes, 0, 0, 0, changes ), - FUNCTION(total_changes, 0, 0, 0, total_changes ), - FUNCTION(replace, 3, 0, 0, replaceFunc ), - FUNCTION(zeroblob, 1, 0, 0, zeroblobFunc ), - #ifdef SQLITE_SOUNDEX - FUNCTION(soundex, 1, 0, 0, soundexFunc ), - #endif - #ifndef SQLITE_OMIT_LOAD_EXTENSION - FUNCTION(load_extension, 1, 0, 0, loadExt ), - FUNCTION(load_extension, 2, 0, 0, loadExt ), - #endif - AGGREGATE(sum, 1, 0, 0, sumStep, sumFinalize ), - AGGREGATE(total, 1, 0, 0, sumStep, totalFinalize ), - AGGREGATE(avg, 1, 0, 0, sumStep, avgFinalize ), - AGGREGATE(count, 0, 0, 0, countStep, countFinalize ), - AGGREGATE(count, 1, 0, 0, countStep, countFinalize ), - AGGREGATE(group_concat, -1, 0, 0, groupConcatStep, groupConcatFinalize), - - LIKEFUNC(glob, 2, &globInfo, SQLITE_FUNC_LIKE|SQLITE_FUNC_CASE), - #ifdef SQLITE_CASE_SENSITIVE_LIKE - LIKEFUNC(like, 2, &likeInfoAlt, SQLITE_FUNC_LIKE|SQLITE_FUNC_CASE), - LIKEFUNC(like, 3, &likeInfoAlt, SQLITE_FUNC_LIKE|SQLITE_FUNC_CASE), - #else - LIKEFUNC(like, 2, &likeInfoNorm, SQLITE_FUNC_LIKE), - LIKEFUNC(like, 3, &likeInfoNorm, SQLITE_FUNC_LIKE), - #endif - }; - - int i; - FuncDefHash *pHash = &GLOBAL(FuncDefHash, sqlite3GlobalFunctions); - FuncDef *aFunc = (FuncDef*)&GLOBAL(FuncDef, aBuiltinFunc); - - for(i=0; ipTable; sqlite3 *db = sqlite3VdbeDb(v); - pIdx->zColAff = (char *)sqlite3Malloc(pIdx->nColumn+2); + pIdx->zColAff = (char *)sqlite3DbMallocRaw(db, pIdx->nColumn+2); if( !pIdx->zColAff ){ - db->mallocFailed = 1; return; } for(n=0; nnColumn; n++){ @@ -63930,9 +58705,8 @@ SQLITE_PRIVATE void sqlite3TableAffinityStr(Vdbe *v, Table *pTab){ int i; sqlite3 *db = sqlite3VdbeDb(v); - zColAff = (char *)sqlite3Malloc(pTab->nCol+1); + zColAff = (char *)sqlite3DbMallocRaw(db, pTab->nCol+1); if( !zColAff ){ - db->mallocFailed = 1; return; } @@ -64008,7 +58782,7 @@ static int autoIncBegin( Table *pTab /* The table we are writing to */ ){ int memId = 0; /* Register holding maximum rowid */ - if( pTab->tabFlags & TF_Autoincrement ){ + if( pTab->autoInc ){ Vdbe *v = pParse->pVdbe; Db *pDb = &pParse->db->aDb[iDb]; int iCur = pParse->nTab; @@ -64020,15 +58794,14 @@ static int autoIncBegin( sqlite3OpenTable(pParse, iCur, iDb, pDb->pSchema->pSeqTab, OP_OpenRead); addr = sqlite3VdbeCurrentAddr(v); sqlite3VdbeAddOp4(v, OP_String8, 0, memId-1, 0, pTab->zName, 0); - sqlite3VdbeAddOp2(v, OP_Rewind, iCur, addr+9); + sqlite3VdbeAddOp2(v, OP_Rewind, iCur, addr+8); sqlite3VdbeAddOp3(v, OP_Column, iCur, 0, memId); sqlite3VdbeAddOp3(v, OP_Ne, memId-1, addr+7, memId); sqlite3VdbeChangeP5(v, SQLITE_JUMPIFNULL); sqlite3VdbeAddOp2(v, OP_Rowid, iCur, memId+1); sqlite3VdbeAddOp3(v, OP_Column, iCur, 1, memId); - sqlite3VdbeAddOp2(v, OP_Goto, 0, addr+9); + sqlite3VdbeAddOp2(v, OP_Goto, 0, addr+8); sqlite3VdbeAddOp2(v, OP_Next, iCur, addr+2); - sqlite3VdbeAddOp2(v, OP_Integer, 0, memId); sqlite3VdbeAddOp2(v, OP_Close, iCur, 0); } return memId; @@ -64059,7 +58832,7 @@ static void autoIncEnd( Table *pTab, /* Table we are inserting into */ int memId /* Memory cell holding the maximum rowid */ ){ - if( pTab->tabFlags & TF_Autoincrement ){ + if( pTab->autoInc ){ int iCur = pParse->nTab; Vdbe *v = pParse->pVdbe; Db *pDb = &pParse->db->aDb[iDb]; @@ -64114,8 +58887,7 @@ static int xferOptimization( ** ** The code generated follows one of four templates. For a simple ** select with data coming from a VALUES clause, the code executes -** once straight down through. Pseudo-code follows (we call this -** the "1st template"): +** once straight down through. The template looks like this: ** ** open write cursor to
      and its indices ** puts VALUES clause expressions onto the stack @@ -64133,7 +58905,7 @@ static int xferOptimization( ** schemas, including all the same indices, then a special optimization ** is invoked that copies raw records from over to . ** See the xferOptimization() function for the implementation of this -** template. This is the 2nd template. +** template. This is the second template. ** ** open a write cursor to
      ** open read cursor on @@ -64146,58 +58918,45 @@ static int xferOptimization( ** close cursors ** end foreach ** -** The 3rd template is for when the second template does not apply +** The third template is for when the second template does not apply ** and the SELECT clause does not read from
      at any time. ** The generated code follows this template: ** -** EOF <- 0 -** X <- A ** goto B ** A: setup for the SELECT ** loop over the rows in the SELECT -** load values into registers R..R+n -** yield X +** gosub C ** end loop ** cleanup after the SELECT -** EOF <- 1 -** yield X -** goto A +** goto D ** B: open write cursor to
      and its indices -** C: yield X -** if EOF goto D -** insert the select result into
      from R..R+n -** goto C +** goto A +** C: insert the select result into
      +** return ** D: cleanup ** -** The 4th template is used if the insert statement takes its +** The fourth template is used if the insert statement takes its ** values from a SELECT but the data is being inserted into a table ** that is also read as part of the SELECT. In the third form, ** we have to use a intermediate table to store the results of ** the select. The template is like this: ** -** EOF <- 0 -** X <- A ** goto B ** A: setup for the SELECT ** loop over the tables in the SELECT -** load value into register R..R+n -** yield X +** gosub C ** end loop ** cleanup after the SELECT -** EOF <- 1 -** yield X -** halt-error -** B: open temp table -** L: yield X -** if EOF goto M -** insert row from R..R+n into temp table -** goto L -** M: open write cursor to
      and its indices -** rewind temp table -** C: loop over rows of intermediate table +** goto D +** C: insert the select result into the intermediate table +** return +** B: open a cursor to an intermediate table +** goto A +** D: open write cursor to
      and its indices +** loop over the intermediate table ** transfer values form intermediate table into
      -** end loop -** D: cleanup +** end the loop +** cleanup */ SQLITE_PRIVATE void sqlite3Insert( Parse *pParse, /* Parser context */ @@ -64221,10 +58980,10 @@ SQLITE_PRIVATE void sqlite3Insert( int endOfLoop; /* Label for the end of the insertion loop */ int useTempTable = 0; /* Store SELECT results in intermediate table */ int srcTab = 0; /* Data comes from this temporary cursor if >=0 */ - int addrInsTop = 0; /* Jump to label "D" */ - int addrCont = 0; /* Top of insert loop. Label "C" in templates 3 and 4 */ - int addrSelect = 0; /* Address of coroutine that implements the SELECT */ - SelectDest dest; /* Destination for SELECT on rhs of INSERT */ + int iCont=0,iBreak=0; /* Beginning and end of the loop over srcTab */ + int iSelectLoop = 0; /* Address of code that implements the SELECT */ + int iCleanup = 0; /* Address of the cleanup code */ + int iInsertBlock = 0; /* Address of the subroutine used to insert data */ int newIdx = -1; /* Cursor for the NEW pseudo-table */ int iDb; /* Index of database holding TABLE */ Db *pDb; /* The database containing table being inserted into */ @@ -64238,7 +58997,6 @@ SQLITE_PRIVATE void sqlite3Insert( int regRowid; /* registers holding insert rowid */ int regData; /* register holding first column to insert */ int regRecord; /* Holds the assemblied row record */ - int regEof; /* Register recording end of SELECT data */ int *aRegIdx = 0; /* One register allocated to each index */ @@ -64320,8 +59078,6 @@ SQLITE_PRIVATE void sqlite3Insert( ** ** Then special optimizations can be applied that make the transfer ** very fast and which reduce fragmentation of indices. - ** - ** This is the 2nd template. */ if( pColumn==0 && xferOptimization(pParse, pTab, pSelect, onError, iDb) ){ assert( !triggers_exist ); @@ -64336,103 +59092,75 @@ SQLITE_PRIVATE void sqlite3Insert( regAutoinc = autoIncBegin(pParse, iDb, pTab); /* Figure out how many columns of data are supplied. If the data - ** is coming from a SELECT statement, then generate a co-routine that - ** produces a single row of the SELECT on each invocation. The - ** co-routine is the common header to the 3rd and 4th templates. + ** is coming from a SELECT statement, then this step also generates + ** all the code to implement the SELECT statement and invoke a subroutine + ** to process each row of the result. (Template 2.) If the SELECT + ** statement uses the the table that is being inserted into, then the + ** subroutine is also coded here. That subroutine stores the SELECT + ** results in a temporary table. (Template 3.) */ if( pSelect ){ /* Data is coming from a SELECT. Generate code to implement that SELECT - ** as a co-routine. The code is common to both the 3rd and 4th - ** templates: - ** - ** EOF <- 0 - ** X <- A - ** goto B - ** A: setup for the SELECT - ** loop over the tables in the SELECT - ** load value into register R..R+n - ** yield X - ** end loop - ** cleanup after the SELECT - ** EOF <- 1 - ** yield X - ** halt-error - ** - ** On each invocation of the co-routine, it puts a single row of the - ** SELECT result into registers dest.iMem...dest.iMem+dest.nMem-1. - ** (These output registers are allocated by sqlite3Select().) When - ** the SELECT completes, it sets the EOF flag stored in regEof. */ - int rc, j1; + SelectDest dest; + int rc, iInitCode; - regEof = ++pParse->nMem; - sqlite3VdbeAddOp2(v, OP_Integer, 0, regEof); /* EOF <- 0 */ - VdbeComment((v, "SELECT eof flag")); - sqlite3SelectDestInit(&dest, SRT_Coroutine, ++pParse->nMem); - addrSelect = sqlite3VdbeCurrentAddr(v)+2; - sqlite3VdbeAddOp2(v, OP_Integer, addrSelect-1, dest.iParm); - j1 = sqlite3VdbeAddOp2(v, OP_Goto, 0, 0); - VdbeComment((v, "Jump over SELECT coroutine")); + iInitCode = sqlite3VdbeAddOp2(v, OP_Goto, 0, 0); + iSelectLoop = sqlite3VdbeCurrentAddr(v); + iInsertBlock = sqlite3VdbeMakeLabel(v); + sqlite3SelectDestInit(&dest, SRT_Subroutine, iInsertBlock); /* Resolve the expressions in the SELECT statement and execute it. */ - rc = sqlite3Select(pParse, pSelect, &dest); + rc = sqlite3Select(pParse, pSelect, &dest, 0, 0, 0, 0); if( rc || pParse->nErr || db->mallocFailed ){ goto insert_cleanup; } - sqlite3VdbeAddOp2(v, OP_Integer, 1, regEof); /* EOF <- 1 */ - sqlite3VdbeAddOp1(v, OP_Yield, dest.iParm); /* yield X */ - sqlite3VdbeAddOp2(v, OP_Halt, SQLITE_INTERNAL, OE_Abort); - VdbeComment((v, "End of SELECT coroutine")); - sqlite3VdbeJumpHere(v, j1); /* label B: */ regFromSelect = dest.iMem; + iCleanup = sqlite3VdbeMakeLabel(v); + sqlite3VdbeAddOp2(v, OP_Goto, 0, iCleanup); assert( pSelect->pEList ); nColumn = pSelect->pEList->nExpr; - assert( dest.nMem==nColumn ); /* Set useTempTable to TRUE if the result of the SELECT statement - ** should be written into a temporary table (template 4). Set to - ** FALSE if each* row of the SELECT can be written directly into - ** the destination table (template 3). + ** should be written into a temporary table. Set to FALSE if each + ** row of the SELECT can be written directly into the result table. ** ** A temp table must be used if the table being updated is also one ** of the tables being read by the SELECT statement. Also use a ** temp table in the case of row triggers. */ - if( triggers_exist || readsTable(v, addrSelect, iDb, pTab) ){ + if( triggers_exist || readsTable(v, iSelectLoop, iDb, pTab) ){ useTempTable = 1; } if( useTempTable ){ - /* Invoke the coroutine to extract information from the SELECT - ** and add it to a transient table srcTab. The code generated - ** here is from the 4th template: - ** - ** B: open temp table - ** L: yield X - ** if EOF goto M - ** insert row from R..R+n into temp table - ** goto L - ** M: ... + /* Generate the subroutine that SELECT calls to process each row of + ** the result. Store the result in a temporary table */ - int regRec; /* Register to hold packed record */ - int regRowid; /* Register to hold temp table ROWID */ - int addrTop; /* Label "L" */ - int addrIf; /* Address of jump to M */ + int regRec, regRowid; srcTab = pParse->nTab++; regRec = sqlite3GetTempReg(pParse); regRowid = sqlite3GetTempReg(pParse); - sqlite3VdbeAddOp2(v, OP_OpenEphemeral, srcTab, nColumn); - addrTop = sqlite3VdbeAddOp1(v, OP_Yield, dest.iParm); - addrIf = sqlite3VdbeAddOp1(v, OP_If, regEof); + sqlite3VdbeResolveLabel(v, iInsertBlock); sqlite3VdbeAddOp3(v, OP_MakeRecord, regFromSelect, nColumn, regRec); sqlite3VdbeAddOp2(v, OP_NewRowid, srcTab, regRowid); sqlite3VdbeAddOp3(v, OP_Insert, srcTab, regRec, regRowid); - sqlite3VdbeAddOp2(v, OP_Goto, 0, addrTop); - sqlite3VdbeJumpHere(v, addrIf); + sqlite3VdbeAddOp2(v, OP_Return, 0, 0); sqlite3ReleaseTempReg(pParse, regRec); sqlite3ReleaseTempReg(pParse, regRowid); + + /* The following code runs first because the GOTO at the very top + ** of the program jumps to it. Create the temporary table, then jump + ** back up and execute the SELECT code above. + */ + sqlite3VdbeJumpHere(v, iInitCode); + sqlite3VdbeAddOp2(v, OP_OpenEphemeral, srcTab, nColumn); + sqlite3VdbeAddOp2(v, OP_Goto, 0, iSelectLoop); + sqlite3VdbeResolveLabel(v, iCleanup); + }else{ + sqlite3VdbeJumpHere(v, iInitCode); } }else{ /* This is the case if the data for the INSERT is coming from a VALUES @@ -64445,7 +59173,7 @@ SQLITE_PRIVATE void sqlite3Insert( assert( useTempTable==0 ); nColumn = pList ? pList->nExpr : 0; for(i=0; ia[i].pExpr) ){ + if( sqlite3ExprResolveNames(&sNC, pList->a[i].pExpr) ){ goto insert_cleanup; } } @@ -64546,31 +59274,18 @@ SQLITE_PRIVATE void sqlite3Insert( } } - /* This is the top of the main insertion loop */ + /* If the data source is a temporary table, then we have to create + ** a loop because there might be multiple rows of data. If the data + ** source is a subroutine call from the SELECT statement, then we need + ** to launch the SELECT statement processing. + */ if( useTempTable ){ - /* This block codes the top of loop only. The complete loop is the - ** following pseudocode (template 4): - ** - ** rewind temp table - ** C: loop over rows of intermediate table - ** transfer values form intermediate table into
      - ** end loop - ** D: ... - */ - addrInsTop = sqlite3VdbeAddOp1(v, OP_Rewind, srcTab); - addrCont = sqlite3VdbeCurrentAddr(v); + iBreak = sqlite3VdbeMakeLabel(v); + sqlite3VdbeAddOp2(v, OP_Rewind, srcTab, iBreak); + iCont = sqlite3VdbeCurrentAddr(v); }else if( pSelect ){ - /* This block codes the top of loop only. The complete loop is the - ** following pseudocode (template 3): - ** - ** C: yield X - ** if EOF goto D - ** insert the select result into
      from R..R+n - ** goto C - ** D: ... - */ - addrCont = sqlite3VdbeAddOp1(v, OP_Yield, dest.iParm); - addrInsTop = sqlite3VdbeAddOp1(v, OP_If, regEof); + sqlite3VdbeAddOp2(v, OP_Goto, 0, iSelectLoop); + sqlite3VdbeResolveLabel(v, iInsertBlock); } /* Allocate registers for holding the rowid of the new row, @@ -64681,7 +59396,7 @@ SQLITE_PRIVATE void sqlite3Insert( VdbeOp *pOp; sqlite3ExprCode(pParse, pList->a[keyColumn].pExpr, regRowid); pOp = sqlite3VdbeGetOp(v, sqlite3VdbeCurrentAddr(v) - 1); - if( pOp && pOp->opcode==OP_Null && !IsVirtual(pTab) ){ + if( pOp && pOp->opcode==OP_Null ){ appendFlag = 1; pOp->opcode = OP_NewRowid; pOp->p1 = baseCur; @@ -64694,14 +59409,9 @@ SQLITE_PRIVATE void sqlite3Insert( */ if( !appendFlag ){ int j1; - if( !IsVirtual(pTab) ){ - j1 = sqlite3VdbeAddOp1(v, OP_NotNull, regRowid); - sqlite3VdbeAddOp3(v, OP_NewRowid, baseCur, regRowid, regAutoinc); - sqlite3VdbeJumpHere(v, j1); - }else{ - j1 = sqlite3VdbeCurrentAddr(v); - sqlite3VdbeAddOp2(v, OP_IsNull, regRowid, j1+2); - } + j1 = sqlite3VdbeAddOp1(v, OP_NotNull, regRowid); + sqlite3VdbeAddOp3(v, OP_NewRowid, baseCur, regRowid, regAutoinc); + sqlite3VdbeJumpHere(v, j1); sqlite3VdbeAddOp1(v, OP_MustBeInt, regRowid); } }else if( IsVirtual(pTab) ){ @@ -64800,24 +59510,23 @@ SQLITE_PRIVATE void sqlite3Insert( } } - /* The bottom of the main insertion loop, if the data source - ** is a SELECT statement. + /* The bottom of the loop, if the data source is a SELECT statement */ sqlite3VdbeResolveLabel(v, endOfLoop); if( useTempTable ){ - sqlite3VdbeAddOp2(v, OP_Next, srcTab, addrCont); - sqlite3VdbeJumpHere(v, addrInsTop); - sqlite3VdbeAddOp1(v, OP_Close, srcTab); + sqlite3VdbeAddOp2(v, OP_Next, srcTab, iCont); + sqlite3VdbeResolveLabel(v, iBreak); + sqlite3VdbeAddOp2(v, OP_Close, srcTab, 0); }else if( pSelect ){ - sqlite3VdbeAddOp2(v, OP_Goto, 0, addrCont); - sqlite3VdbeJumpHere(v, addrInsTop); + sqlite3VdbeAddOp2(v, OP_Return, 0, 0); + sqlite3VdbeResolveLabel(v, iCleanup); } if( !IsVirtual(pTab) && !isView ){ /* Close all tables opened */ - sqlite3VdbeAddOp1(v, OP_Close, baseCur); + sqlite3VdbeAddOp2(v, OP_Close, baseCur, 0); for(idx=1, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, idx++){ - sqlite3VdbeAddOp1(v, OP_Close, idx+baseCur); + sqlite3VdbeAddOp2(v, OP_Close, idx+baseCur, 0); } } @@ -64839,11 +59548,11 @@ SQLITE_PRIVATE void sqlite3Insert( } insert_cleanup: - sqlite3SrcListDelete(db, pTabList); - sqlite3ExprListDelete(db, pList); - sqlite3SelectDelete(db, pSelect); - sqlite3IdListDelete(db, pColumn); - sqlite3DbFree(db, aRegIdx); + sqlite3SrcListDelete(pTabList); + sqlite3ExprListDelete(pList); + sqlite3SelectDelete(pSelect); + sqlite3IdListDelete(pColumn); + sqlite3_free(aRegIdx); } /* @@ -64975,10 +59684,10 @@ SQLITE_PRIVATE void sqlite3GenerateConstraintChecks( case OE_Rollback: case OE_Abort: case OE_Fail: { - char *zMsg; + char *zMsg = 0; sqlite3VdbeAddOp2(v, OP_Halt, SQLITE_CONSTRAINT, onError); - zMsg = sqlite3MPrintf(pParse->db, "%s.%s may not be NULL", - pTab->zName, pTab->aCol[i].zName); + sqlite3SetString(&zMsg, pTab->zName, ".", pTab->aCol[i].zName, + " may not be NULL", (char*)0); sqlite3VdbeChangeP4(v, -1, zMsg, P4_DYNAMIC); break; } @@ -65103,7 +59812,7 @@ SQLITE_PRIVATE void sqlite3GenerateConstraintChecks( regR = sqlite3GetTempReg(pParse); sqlite3VdbeAddOp2(v, OP_SCopy, regRowid-hasTwoRowids, regR); j3 = sqlite3VdbeAddOp4(v, OP_IsUnique, baseCur+iCur+1, 0, - regR, SQLITE_INT_TO_PTR(aRegIdx[iCur]), + regR, (char*)aRegIdx[iCur], P4_INT32); /* Generate code that executes if the new index entry is not unique */ @@ -65378,7 +60087,7 @@ static int xferOptimization( return 0; /* tab1 must not have triggers */ } #ifndef SQLITE_OMIT_VIRTUALTABLE - if( pDest->tabFlags & TF_Virtual ){ + if( pDest->isVirtual ){ return 0; /* tab1 must not be a virtual table */ } #endif @@ -65413,7 +60122,7 @@ static int xferOptimization( if( pSelect->pPrior ){ return 0; /* SELECT may not be a compound query */ } - if( pSelect->selFlags & SF_Distinct ){ + if( pSelect->isDistinct ){ return 0; /* SELECT may not be DISTINCT */ } pEList = pSelect->pEList; @@ -65439,7 +60148,7 @@ static int xferOptimization( return 0; /* tab1 and tab2 may not be the same table */ } #ifndef SQLITE_OMIT_VIRTUALTABLE - if( pSrc->tabFlags & TF_Virtual ){ + if( pSrc->isVirtual ){ return 0; /* tab2 must not be a virtual table */ } #endif @@ -65530,7 +60239,7 @@ static int xferOptimization( addr1 = sqlite3VdbeAddOp2(v, OP_NewRowid, iDest, regRowid); }else{ addr1 = sqlite3VdbeAddOp2(v, OP_Rowid, iSrc, regRowid); - assert( (pDest->tabFlags & TF_Autoincrement)==0 ); + assert( pDest->autoInc==0 ); } sqlite3VdbeAddOp2(v, OP_RowData, iSrc, regData); sqlite3VdbeAddOp3(v, OP_Insert, iDest, regData, regRowid); @@ -65598,7 +60307,7 @@ static int xferOptimization( ** other files are for internal use by SQLite and should not be ** accessed by users of the library. ** -** $Id: legacy.c,v 1.29 2008/08/02 03:50:39 drh Exp $ +** $Id: legacy.c,v 1.24 2008/03/21 18:01:14 drh Exp $ */ @@ -65627,10 +60336,9 @@ SQLITE_API int sqlite3_exec( int nRetry = 0; int nCallback; - if( zSql==0 ) zSql = ""; + if( zSql==0 ) return SQLITE_OK; sqlite3_mutex_enter(db->mutex); - sqlite3Error(db, SQLITE_OK, 0); while( (rc==SQLITE_OK || (rc==SQLITE_SCHEMA && (++nRetry)<2)) && zSql[0] ){ int nCol; char **azVals = 0; @@ -65666,9 +60374,10 @@ SQLITE_API int sqlite3_exec( } for(i=0; imallocFailed = 1; + goto exec_out; + } } nCallback++; } @@ -65684,9 +60393,6 @@ SQLITE_API int sqlite3_exec( } if( xCallback(pArg, nCol, azVals, azCols) ){ rc = SQLITE_ABORT; - sqlite3_finalize(pStmt); - pStmt = 0; - sqlite3Error(db, SQLITE_ABORT, 0); goto exec_out; } } @@ -65703,18 +60409,18 @@ SQLITE_API int sqlite3_exec( } } - sqlite3DbFree(db, azCols); + sqlite3_free(azCols); azCols = 0; } exec_out: if( pStmt ) sqlite3_finalize(pStmt); - sqlite3DbFree(db, azCols); + if( azCols ) sqlite3_free(azCols); rc = sqlite3ApiExit(db, rc); if( rc!=SQLITE_OK && rc==sqlite3_errcode(db) && pzErrMsg ){ int nErrMsg = 1 + strlen(sqlite3_errmsg(db)); - *pzErrMsg = sqlite3Malloc(nErrMsg); + *pzErrMsg = sqlite3_malloc(nErrMsg); if( *pzErrMsg ){ memcpy(*pzErrMsg, sqlite3_errmsg(db), nErrMsg); } @@ -65742,8 +60448,6 @@ exec_out: ************************************************************************* ** This file contains code used to dynamically load extensions into ** the SQLite library. -** -** $Id: loadext.c,v 1.56 2008/10/12 00:27:53 shane Exp $ */ #ifndef SQLITE_CORE @@ -65768,7 +60472,7 @@ exec_out: ** as extensions by SQLite should #include this file instead of ** sqlite3.h. ** -** @(#) $Id: sqlite3ext.h,v 1.25 2008/10/12 00:27:54 shane Exp $ +** @(#) $Id: sqlite3ext.h,v 1.21 2008/03/19 21:45:51 drh Exp $ */ #ifndef _SQLITE3EXT_H_ #define _SQLITE3EXT_H_ @@ -65830,7 +60534,7 @@ struct sqlite3_api_routines { int (*complete)(const char*sql); int (*complete16)(const void*sql); int (*create_collation)(sqlite3*,const char*,int,void*,int(*)(void*,int,const void*,int,const void*)); - int (*create_collation16)(sqlite3*,const void*,int,void*,int(*)(void*,int,const void*,int,const void*)); + int (*create_collation16)(sqlite3*,const char*,int,void*,int(*)(void*,int,const void*,int,const void*)); int (*create_function)(sqlite3*,const char*,int,int,void*,void (*xFunc)(sqlite3_context*,int,sqlite3_value**),void (*xStep)(sqlite3_context*,int,sqlite3_value**),void (*xFinal)(sqlite3_context*)); int (*create_function16)(sqlite3*,const void*,int,int,void*,void (*xFunc)(sqlite3_context*,int,sqlite3_value**),void (*xStep)(sqlite3_context*,int,sqlite3_value**),void (*xFinal)(sqlite3_context*)); int (*create_module)(sqlite3*,const char*,const sqlite3_module*,void*); @@ -65940,11 +60644,6 @@ struct sqlite3_api_routines { int (*test_control)(int, ...); void (*randomness)(int,void*); sqlite3 *(*context_db_handle)(sqlite3_context*); - int (*extended_result_codes)(sqlite3*,int); - int (*limit)(sqlite3*,int,int); - sqlite3_stmt *(*next_stmt)(sqlite3*,sqlite3_stmt*); - const char *(*sql)(sqlite3_stmt*); - int (*status)(int,int*,int*,int); }; /* @@ -65960,9 +60659,7 @@ struct sqlite3_api_routines { */ #ifndef SQLITE_CORE #define sqlite3_aggregate_context sqlite3_api->aggregate_context -#ifndef SQLITE_OMIT_DEPRECATED #define sqlite3_aggregate_count sqlite3_api->aggregate_count -#endif #define sqlite3_bind_blob sqlite3_api->bind_blob #define sqlite3_bind_double sqlite3_api->bind_double #define sqlite3_bind_int sqlite3_api->bind_int @@ -66018,18 +60715,14 @@ struct sqlite3_api_routines { #define sqlite3_errmsg sqlite3_api->errmsg #define sqlite3_errmsg16 sqlite3_api->errmsg16 #define sqlite3_exec sqlite3_api->exec -#ifndef SQLITE_OMIT_DEPRECATED #define sqlite3_expired sqlite3_api->expired -#endif #define sqlite3_finalize sqlite3_api->finalize #define sqlite3_free sqlite3_api->free #define sqlite3_free_table sqlite3_api->free_table #define sqlite3_get_autocommit sqlite3_api->get_autocommit #define sqlite3_get_auxdata sqlite3_api->get_auxdata #define sqlite3_get_table sqlite3_api->get_table -#ifndef SQLITE_OMIT_DEPRECATED #define sqlite3_global_recover sqlite3_api->global_recover -#endif #define sqlite3_interrupt sqlite3_api->interruptx #define sqlite3_last_insert_rowid sqlite3_api->last_insert_rowid #define sqlite3_libversion sqlite3_api->libversion @@ -66067,9 +60760,7 @@ struct sqlite3_api_routines { #define sqlite3_thread_cleanup sqlite3_api->thread_cleanup #define sqlite3_total_changes sqlite3_api->total_changes #define sqlite3_trace sqlite3_api->trace -#ifndef SQLITE_OMIT_DEPRECATED #define sqlite3_transfer_bindings sqlite3_api->transfer_bindings -#endif #define sqlite3_update_hook sqlite3_api->update_hook #define sqlite3_user_data sqlite3_api->user_data #define sqlite3_value_blob sqlite3_api->value_blob @@ -66119,14 +60810,9 @@ struct sqlite3_api_routines { #define sqlite3_test_control sqlite3_api->test_control #define sqlite3_randomness sqlite3_api->randomness #define sqlite3_context_db_handle sqlite3_api->context_db_handle -#define sqlite3_extended_result_codes sqlite3_api->extended_result_codes -#define sqlite3_limit sqlite3_api->limit -#define sqlite3_next_stmt sqlite3_api->next_stmt -#define sqlite3_sql sqlite3_api->sql -#define sqlite3_status sqlite3_api->status #endif /* SQLITE_CORE */ -#define SQLITE_EXTENSION_INIT1 const sqlite3_api_routines *sqlite3_api = 0; +#define SQLITE_EXTENSION_INIT1 const sqlite3_api_routines *sqlite3_api; #define SQLITE_EXTENSION_INIT2(v) sqlite3_api = v; #endif /* _SQLITE3EXT_H_ */ @@ -66235,11 +60921,7 @@ struct sqlite3_api_routines { */ static const sqlite3_api_routines sqlite3Apis = { sqlite3_aggregate_context, -#ifndef SQLITE_OMIT_DEPRECATED sqlite3_aggregate_count, -#else - 0, -#endif sqlite3_bind_blob, sqlite3_bind_double, sqlite3_bind_int, @@ -66294,11 +60976,7 @@ static const sqlite3_api_routines sqlite3Apis = { sqlite3_errmsg, sqlite3_errmsg16, sqlite3_exec, -#ifndef SQLITE_OMIT_DEPRECATED sqlite3_expired, -#else - 0, -#endif sqlite3_finalize, sqlite3_free, sqlite3_free_table, @@ -66338,18 +61016,10 @@ static const sqlite3_api_routines sqlite3Apis = { sqlite3_snprintf, sqlite3_step, sqlite3_table_column_metadata, -#ifndef SQLITE_OMIT_DEPRECATED sqlite3_thread_cleanup, -#else - 0, -#endif sqlite3_total_changes, sqlite3_trace, -#ifndef SQLITE_OMIT_DEPRECATED sqlite3_transfer_bindings, -#else - 0, -#endif sqlite3_update_hook, sqlite3_user_data, sqlite3_value_blob, @@ -66400,7 +61070,7 @@ static const sqlite3_api_routines sqlite3Apis = { sqlite3_file_control, sqlite3_memory_highwater, sqlite3_memory_used, -#ifdef SQLITE_MUTEX_OMIT +#ifdef SQLITE_MUTEX_NOOP 0, 0, 0, @@ -66432,15 +61102,6 @@ static const sqlite3_api_routines sqlite3Apis = { sqlite3_test_control, sqlite3_randomness, sqlite3_context_db_handle, - - /* - ** Added for 3.6.0 - */ - sqlite3_extended_result_codes, - sqlite3_limit, - sqlite3_next_stmt, - sqlite3_sql, - sqlite3_status, }; /* @@ -66453,7 +61114,7 @@ static const sqlite3_api_routines sqlite3Apis = { ** ** If an error occurs and pzErrMsg is not 0, then fill *pzErrMsg with ** error message text. The calling function should free this memory -** by calling sqlite3DbFree(db, ). +** by calling sqlite3_free(). */ static int sqlite3LoadExtension( sqlite3 *db, /* Load the extension into this database connection */ @@ -66492,7 +61153,7 @@ static int sqlite3LoadExtension( sqlite3_snprintf(sizeof(zErr)-1, zErr, "unable to open shared library [%s]", zFile); sqlite3OsDlError(pVfs, sizeof(zErr)-1, zErr); - *pzErrMsg = sqlite3DbStrDup(0, zErr); + *pzErrMsg = sqlite3DbStrDup(db, zErr); } return SQLITE_ERROR; } @@ -66505,7 +61166,7 @@ static int sqlite3LoadExtension( sqlite3_snprintf(sizeof(zErr)-1, zErr, "no entry point [%s] in shared library [%s]", zProc,zFile); sqlite3OsDlError(pVfs, sizeof(zErr)-1, zErr); - *pzErrMsg = sqlite3DbStrDup(0, zErr); + *pzErrMsg = sqlite3DbStrDup(db, zErr); sqlite3OsDlClose(pVfs, handle); } return SQLITE_ERROR; @@ -66519,17 +61180,18 @@ static int sqlite3LoadExtension( } /* Append the new shared library handle to the db->aExtension array. */ - aHandle = sqlite3DbMallocZero(db, sizeof(handle)*(db->nExtension+1)); + db->nExtension++; + aHandle = sqlite3DbMallocZero(db, sizeof(handle)*db->nExtension); if( aHandle==0 ){ return SQLITE_NOMEM; } if( db->nExtension>0 ){ - memcpy(aHandle, db->aExtension, sizeof(handle)*db->nExtension); + memcpy(aHandle, db->aExtension, sizeof(handle)*(db->nExtension-1)); } - sqlite3DbFree(db, db->aExtension); + sqlite3_free(db->aExtension); db->aExtension = aHandle; - db->aExtension[db->nExtension++] = handle; + db->aExtension[db->nExtension-1] = handle; return SQLITE_OK; } SQLITE_API int sqlite3_load_extension( @@ -66555,7 +61217,7 @@ SQLITE_PRIVATE void sqlite3CloseExtensions(sqlite3 *db){ for(i=0; inExtension; i++){ sqlite3OsDlClose(db->pVfs, db->aExtension[i]); } - sqlite3DbFree(db, db->aExtension); + sqlite3_free(db->aExtension); } /* @@ -66593,26 +61255,10 @@ static const sqlite3_api_routines sqlite3Apis = { 0 }; ** This list is shared across threads. The SQLITE_MUTEX_STATIC_MASTER ** mutex must be held while accessing this list. */ -typedef struct sqlite3ExtType sqlite3ExtType; -static SQLITE_WSD struct sqlite3ExtType { +static struct { int nExt; /* Number of entries in aExt[] */ void **aExt; /* Pointers to the extension init functions */ -} sqlite3Autoext = { 0, 0 }; - -/* The "wsdAutoext" macro will resolve to the autoextension -** state vector. If writable static data is unsupported on the target, -** we have to locate the state vector at run-time. In the more common -** case where writable static data is supported, wsdStat can refer directly -** to the "sqlite3Autoext" state vector declared above. -*/ -#ifdef SQLITE_OMIT_WSD -# define wsdAutoextInit \ - sqlite3ExtType *x = &GLOBAL(sqlite3ExtType,sqlite3Autoext) -# define wsdAutoext x[0] -#else -# define wsdAutoextInit -# define wsdAutoext sqlite3Autoext -#endif +} autoext = { 0, 0 }; /* @@ -66620,59 +61266,44 @@ static SQLITE_WSD struct sqlite3ExtType { ** loaded by every new database connection. */ SQLITE_API int sqlite3_auto_extension(void *xInit){ + int i; int rc = SQLITE_OK; -#ifndef SQLITE_OMIT_AUTOINIT - rc = sqlite3_initialize(); - if( rc ){ - return rc; - }else +#ifndef SQLITE_MUTEX_NOOP + sqlite3_mutex *mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MASTER); #endif - { - int i; -#if SQLITE_THREADSAFE - sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); -#endif - wsdAutoextInit; - sqlite3_mutex_enter(mutex); - for(i=0; i=wsdAutoext.nExt ){ + if( i>=autoext.nExt ){ xInit = 0; go = 0; }else{ xInit = (int(*)(sqlite3*,char**,const sqlite3_api_routines*)) - wsdAutoext.aExt[i]; + autoext.aExt[i]; } sqlite3_mutex_leave(mutex); if( xInit && xInit(db, &zErrmsg, &sqlite3Apis) ){ @@ -66729,7 +61359,7 @@ SQLITE_PRIVATE int sqlite3AutoLoadExtensions(sqlite3 *db){ ************************************************************************* ** This file contains code used to implement the PRAGMA command. ** -** $Id: pragma.c,v 1.189 2008/10/10 17:47:21 danielk1977 Exp $ +** $Id: pragma.c,v 1.176 2008/04/17 20:59:38 drh Exp $ */ /* Ignore this whole file if pragmas are disabled @@ -66827,7 +61457,7 @@ static int getTempStore(const char *z){ static int invalidateTempStorage(Parse *pParse){ sqlite3 *db = pParse->db; if( db->aDb[1].pBt!=0 ){ - if( !db->autoCommit || sqlite3BtreeIsInReadTrans(db->aDb[1].pBt) ){ + if( !db->autoCommit ){ sqlite3ErrorMsg(pParse, "temporary storage cannot be changed " "from within a transaction"); return SQLITE_ERROR; @@ -66843,7 +61473,7 @@ static int invalidateTempStorage(Parse *pParse){ #ifndef SQLITE_OMIT_PAGER_PRAGMAS /* ** If the TEMP database is open, close it and mark the database schema -** as needing reloading. This must be done when using the SQLITE_TEMP_STORE +** as needing reloading. This must be done when using the TEMP_STORE ** or DEFAULT_TEMP_STORE pragmas. */ static int changeTempStorage(Parse *pParse, const char *zStorageType){ @@ -66937,16 +61567,6 @@ static int flagPragma(Parse *pParse, const char *zLeft, const char *zRight){ } #endif /* SQLITE_OMIT_FLAG_PRAGMAS */ -static const char *actionName(u8 action){ - switch( action ){ - case OE_SetNull: return "SET NULL"; - case OE_SetDflt: return "SET DEFAULT"; - case OE_Restrict: return "RESTRICT"; - case OE_Cascade: return "CASCADE"; - } - return ""; -} - /* ** Process a pragma statement. ** @@ -67001,7 +61621,7 @@ SQLITE_PRIVATE void sqlite3Pragma( zRight = sqlite3NameFromToken(db, pValue); } - zDb = ((pId2 && pId2->n>0)?pDb->zName:0); + zDb = ((iDb>0)?pDb->zName:0); if( sqlite3AuthCheck(pParse, SQLITE_PRAGMA, zLeft, zRight, zDb) ){ goto pragma_out; } @@ -67104,24 +61724,6 @@ SQLITE_PRIVATE void sqlite3Pragma( returnSingleInt(pParse, "max_page_count", newMax); }else - /* - ** PRAGMA [database.]page_count - ** - ** Return the number of pages in the specified database. - */ - if( sqlite3StrICmp(zLeft,"page_count")==0 ){ - Vdbe *v; - int iReg; - v = sqlite3GetVdbe(pParse); - if( !v || sqlite3ReadSchema(pParse) ) goto pragma_out; - sqlite3CodeVerifySchema(pParse, iDb); - iReg = ++pParse->nMem; - sqlite3VdbeAddOp2(v, OP_Pagecount, iDb, iReg); - sqlite3VdbeAddOp2(v, OP_ResultRow, iReg, 1); - sqlite3VdbeSetNumCols(v, 1); - sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "page_count", P4_STATIC); - }else - /* ** PRAGMA [database.]locking_mode ** PRAGMA [database.]locking_mode = (normal|exclusive) @@ -67175,19 +61777,19 @@ SQLITE_PRIVATE void sqlite3Pragma( */ if( sqlite3StrICmp(zLeft,"journal_mode")==0 ){ int eMode; - static char * const azModeName[] = {"delete", "persist", "off", "truncate"}; + static const char *azModeName[] = {"delete", "persist", "off"}; if( zRight==0 ){ eMode = PAGER_JOURNALMODE_QUERY; }else{ int n = strlen(zRight); - eMode = sizeof(azModeName)/sizeof(azModeName[0]) - 1; + eMode = 2; while( eMode>=0 && sqlite3StrNICmp(zRight, azModeName[eMode], n)!=0 ){ eMode--; } } if( pId2->n==0 && eMode==PAGER_JOURNALMODE_QUERY ){ - /* Simple "PRAGMA journal_mode;" statement. This is a query for + /* Simple "PRAGMA persistent_journal;" statement. This is a query for ** the current default journal mode (which may be different to ** the journal-mode of the main database). */ @@ -67217,7 +61819,6 @@ SQLITE_PRIVATE void sqlite3Pragma( eMode = sqlite3PagerJournalMode(pPager, eMode); } assert( eMode==PAGER_JOURNALMODE_DELETE - || eMode==PAGER_JOURNALMODE_TRUNCATE || eMode==PAGER_JOURNALMODE_PERSIST || eMode==PAGER_JOURNALMODE_OFF ); sqlite3VdbeSetNumCols(v, 1); @@ -67226,27 +61827,6 @@ SQLITE_PRIVATE void sqlite3Pragma( azModeName[eMode], P4_STATIC); sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1); }else - - /* - ** PRAGMA [database.]journal_size_limit - ** PRAGMA [database.]journal_size_limit=N - ** - ** Get or set the (boolean) value of the database 'auto-vacuum' parameter. - */ - if( sqlite3StrICmp(zLeft,"journal_size_limit")==0 ){ - Pager *pPager = sqlite3BtreePager(pDb->pBt); - i64 iLimit = -2; - if( zRight ){ - int iLimit32 = atoi(zRight); - if( iLimit32<-1 ){ - iLimit32 = -1; - } - iLimit = iLimit32; - } - iLimit = sqlite3PagerJournalSizeLimit(pPager, iLimit); - returnSingleInt(pParse, "journal_size_limit", (int)iLimit); - }else - #endif /* SQLITE_OMIT_PAGER_PRAGMAS */ /* @@ -67393,29 +61973,25 @@ SQLITE_PRIVATE void sqlite3Pragma( sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1); } }else{ -#ifndef SQLITE_OMIT_WSD - if( zRight[0] ){ - int rc; - int res; - rc = sqlite3OsAccess(db->pVfs, zRight, SQLITE_ACCESS_READWRITE, &res); - if( rc!=SQLITE_OK || res==0 ){ - sqlite3ErrorMsg(pParse, "not a writable directory"); - goto pragma_out; - } + if( zRight[0] + && sqlite3OsAccess(db->pVfs, zRight, SQLITE_ACCESS_READWRITE)==0 + ){ + sqlite3ErrorMsg(pParse, "not a writable directory"); + goto pragma_out; } - if( SQLITE_TEMP_STORE==0 - || (SQLITE_TEMP_STORE==1 && db->temp_store<=1) - || (SQLITE_TEMP_STORE==2 && db->temp_store==1) + if( TEMP_STORE==0 + || (TEMP_STORE==1 && db->temp_store<=1) + || (TEMP_STORE==2 && db->temp_store==1) ){ invalidateTempStorage(pParse); } sqlite3_free(sqlite3_temp_directory); if( zRight[0] ){ - sqlite3_temp_directory = sqlite3DbStrDup(0, zRight); + sqlite3_temp_directory = zRight; + zRight = 0; }else{ sqlite3_temp_directory = 0; } -#endif /* SQLITE_OMIT_WSD */ } }else @@ -67599,32 +62175,24 @@ SQLITE_PRIVATE void sqlite3Pragma( pFK = pTab->pFKey; if( pFK ){ int i = 0; - sqlite3VdbeSetNumCols(v, 8); - pParse->nMem = 8; + sqlite3VdbeSetNumCols(v, 5); + pParse->nMem = 5; sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "id", P4_STATIC); sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "seq", P4_STATIC); sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "table", P4_STATIC); sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "from", P4_STATIC); sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "to", P4_STATIC); - sqlite3VdbeSetColName(v, 5, COLNAME_NAME, "on_update", P4_STATIC); - sqlite3VdbeSetColName(v, 6, COLNAME_NAME, "on_delete", P4_STATIC); - sqlite3VdbeSetColName(v, 7, COLNAME_NAME, "match", P4_STATIC); while(pFK){ int j; for(j=0; jnCol; j++){ char *zCol = pFK->aCol[j].zCol; - char *zOnUpdate = (char *)actionName(pFK->updateConf); - char *zOnDelete = (char *)actionName(pFK->deleteConf); sqlite3VdbeAddOp2(v, OP_Integer, i, 1); sqlite3VdbeAddOp2(v, OP_Integer, j, 2); sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, pFK->zTo, 0); sqlite3VdbeAddOp4(v, OP_String8, 0, 4, 0, pTab->aCol[pFK->aCol[j].iFrom].zName, 0); sqlite3VdbeAddOp4(v, zCol ? OP_String8 : OP_Null, 0, 5, 0, zCol, 0); - sqlite3VdbeAddOp4(v, OP_String8, 0, 6, 0, zOnUpdate, 0); - sqlite3VdbeAddOp4(v, OP_String8, 0, 7, 0, zOnDelete, 0); - sqlite3VdbeAddOp4(v, OP_String8, 0, 8, 0, "NONE", 0); - sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 8); + sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 5); } ++i; pFK = pFK->pNextFrom; @@ -67741,7 +62309,7 @@ SQLITE_PRIVATE void sqlite3Pragma( sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, sqlite3MPrintf(db, "*** in database %s ***\n", db->aDb[i].zName), P4_DYNAMIC); - sqlite3VdbeAddOp3(v, OP_Move, 2, 4, 1); + sqlite3VdbeAddOp2(v, OP_Move, 2, 4); sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 2); sqlite3VdbeAddOp2(v, OP_ResultRow, 2, 1); sqlite3VdbeJumpHere(v, addr); @@ -67928,6 +62496,7 @@ SQLITE_PRIVATE void sqlite3Pragma( || sqlite3StrICmp(zLeft, "user_version")==0 || sqlite3StrICmp(zLeft, "freelist_count")==0 ){ + int iCookie; /* Cookie index. 0 for schema-cookie, 6 for user-cookie. */ sqlite3VdbeUsesBtree(v, iDb); switch( zLeft[0] ){ @@ -68002,7 +62571,6 @@ SQLITE_PRIVATE void sqlite3Pragma( sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, zState, P4_STATIC); sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 2); } - }else #endif @@ -68060,8 +62628,8 @@ SQLITE_PRIVATE void sqlite3Pragma( #endif } pragma_out: - sqlite3DbFree(db, zLeft); - sqlite3DbFree(db, zRight); + sqlite3_free(zLeft); + sqlite3_free(zRight); } #endif /* SQLITE_OMIT_PRAGMA || SQLITE_OMIT_PARSER */ @@ -68083,7 +62651,7 @@ pragma_out: ** interface, and routines that contribute to loading the database schema ** from disk. ** -** $Id: prepare.c,v 1.97 2008/09/08 09:06:19 danielk1977 Exp $ +** $Id: prepare.c,v 1.83 2008/04/03 14:36:26 danielk1977 Exp $ */ /* @@ -68095,15 +62663,10 @@ static void corruptSchema( const char *zObj, /* Object being parsed at the point of error */ const char *zExtra /* Error information */ ){ - sqlite3 *db = pData->db; - if( !db->mallocFailed && (db->flags & SQLITE_RecoveryMode)==0 ){ + if( !pData->db->mallocFailed ){ if( zObj==0 ) zObj = "?"; - sqlite3SetString(pData->pzErrMsg, pData->db, - "malformed database schema (%s)", zObj); - if( zExtra && zExtra[0] ){ - *pData->pzErrMsg = sqlite3MAppendf(pData->db, *pData->pzErrMsg, "%s - %s", - *pData->pzErrMsg, zExtra); - } + sqlite3SetString(pData->pzErrMsg, "malformed database schema (", zObj, ")", + zExtra!=0 && zExtra[0]!=0 ? " - " : (char*)0, zExtra, (char*)0); } pData->rc = SQLITE_CORRUPT; } @@ -68126,6 +62689,7 @@ SQLITE_PRIVATE int sqlite3InitCallback(void *pInit, int argc, char **argv, char int iDb = pData->iDb; assert( sqlite3_mutex_held(db->mutex) ); + pData->rc = SQLITE_OK; DbClearProperty(db, iDb, DB_Empty); if( db->mallocFailed ){ corruptSchema(pData, argv[0], 0); @@ -68133,11 +62697,13 @@ SQLITE_PRIVATE int sqlite3InitCallback(void *pInit, int argc, char **argv, char } assert( argc==3 ); - assert( iDb>=0 && iDbnDb ); if( argv==0 ) return 0; /* Might happen if EMPTY_RESULT_CALLBACKS are on */ if( argv[1]==0 ){ corruptSchema(pData, argv[0], 0); - }else if( argv[2] && argv[2][0] ){ + return 1; + } + assert( iDb>=0 && iDbnDb ); + if( argv[2] && argv[2][0] ){ /* Call the parser to process a CREATE TABLE, INDEX or VIEW. ** But because db->init.busy is set to 1, no VDBE code is generated ** or executed. All the parser does is build the internal data @@ -68145,15 +62711,11 @@ SQLITE_PRIVATE int sqlite3InitCallback(void *pInit, int argc, char **argv, char */ char *zErr; int rc; - u8 lookasideEnabled; assert( db->init.busy ); db->init.iDb = iDb; db->init.newTnum = atoi(argv[1]); - lookasideEnabled = db->lookaside.bEnabled; - db->lookaside.bEnabled = 0; rc = sqlite3_exec(db, argv[2], 0, 0, &zErr); db->init.iDb = 0; - db->lookaside.bEnabled = lookasideEnabled; assert( rc!=SQLITE_OK || zErr==0 ); if( SQLITE_OK!=rc ){ pData->rc = rc; @@ -68162,7 +62724,8 @@ SQLITE_PRIVATE int sqlite3InitCallback(void *pInit, int argc, char **argv, char }else if( rc!=SQLITE_INTERRUPT ){ corruptSchema(pData, argv[0], zErr); } - sqlite3DbFree(db, zErr); + sqlite3_free(zErr); + return 1; } }else if( argv[0]==0 ){ corruptSchema(pData, 0, 0); @@ -68258,18 +62821,17 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){ azArg[3] = 0; initData.db = db; initData.iDb = iDb; - initData.rc = SQLITE_OK; initData.pzErrMsg = pzErrMsg; (void)sqlite3SafetyOff(db); - sqlite3InitCallback(&initData, 3, (char **)azArg, 0); + rc = sqlite3InitCallback(&initData, 3, (char **)azArg, 0); (void)sqlite3SafetyOn(db); - if( initData.rc ){ + if( rc ){ rc = initData.rc; goto error_out; } pTab = sqlite3FindTable(db, zMasterName, db->aDb[iDb].zName); if( pTab ){ - pTab->tabFlags |= TF_Readonly; + pTab->readOnly = 1; } /* Create a cursor to hold the database open @@ -68289,8 +62851,8 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){ sqlite3BtreeEnter(pDb->pBt); rc = sqlite3BtreeCursor(pDb->pBt, MASTER_ROOT, 0, 0, curMain); if( rc!=SQLITE_OK && rc!=SQLITE_EMPTY ){ - sqlite3SetString(pzErrMsg, db, "%s", sqlite3ErrStr(rc)); - goto initone_error_out; + sqlite3SetString(pzErrMsg, sqlite3ErrStr(rc), (char*)0); + goto leave_error_out; } /* Get the database meta information. @@ -68312,12 +62874,12 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){ */ if( rc==SQLITE_OK ){ int i; - for(i=0; ipBt, i+1, (u32 *)&meta[i]); - if( rc ){ - sqlite3SetString(pzErrMsg, db, "%s", sqlite3ErrStr(rc)); - goto initone_error_out; - } + } + if( rc ){ + sqlite3SetString(pzErrMsg, sqlite3ErrStr(rc), (char*)0); + goto leave_error_out; } }else{ memset(meta, 0, sizeof(meta)); @@ -68337,10 +62899,10 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){ }else{ /* If opening an attached database, the encoding much match ENC(db) */ if( meta[4]!=ENC(db) ){ - sqlite3SetString(pzErrMsg, db, "attached databases must use the same" - " text encoding as main database"); + sqlite3SetString(pzErrMsg, "attached databases must use the same" + " text encoding as main database", (char*)0); rc = SQLITE_ERROR; - goto initone_error_out; + goto leave_error_out; } } }else{ @@ -68348,13 +62910,11 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){ } pDb->pSchema->enc = ENC(db); - if( pDb->pSchema->cache_size==0 ){ - size = meta[2]; - if( size==0 ){ size = SQLITE_DEFAULT_CACHE_SIZE; } - if( size<0 ) size = -size; - pDb->pSchema->cache_size = size; - sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size); - } + size = meta[2]; + if( size==0 ){ size = SQLITE_DEFAULT_CACHE_SIZE; } + if( size<0 ) size = -size; + pDb->pSchema->cache_size = size; + sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size); /* ** file_format==1 Version 3.0.0. @@ -68367,9 +62927,9 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){ pDb->pSchema->file_format = 1; } if( pDb->pSchema->file_format>SQLITE_MAX_FILE_FORMAT ){ - sqlite3SetString(pzErrMsg, db, "unsupported file format"); + sqlite3SetString(pzErrMsg, "unsupported file format", (char*)0); rc = SQLITE_ERROR; - goto initone_error_out; + goto leave_error_out; } /* Ticket #2804: When we open a database in the newer file format, @@ -68404,9 +62964,9 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){ db->xAuth = xAuth; } #endif - if( rc==SQLITE_OK ) rc = initData.rc; + if( rc==SQLITE_ABORT ) rc = initData.rc; (void)sqlite3SafetyOn(db); - sqlite3DbFree(db, zSql); + sqlite3_free(zSql); #ifndef SQLITE_OMIT_ANALYZE if( rc==SQLITE_OK ){ sqlite3AnalysisLoad(db, iDb); @@ -68414,6 +62974,7 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){ #endif } if( db->mallocFailed ){ + /* sqlite3SetString(pzErrMsg, "out of memory", (char*)0); */ rc = SQLITE_NOMEM; sqlite3ResetInternalSchema(db, 0); } @@ -68434,7 +62995,7 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){ ** curMain and calling sqlite3BtreeEnter(). For an error that occurs ** before that point, jump to error_out. */ -initone_error_out: +leave_error_out: sqlite3BtreeCloseCursor(curMain); sqlite3_free(curMain); sqlite3BtreeLeave(pDb->pBt); @@ -68523,7 +63084,7 @@ static int schemaIsValid(sqlite3 *db){ int cookie; int allOk = 1; - curTemp = (BtCursor *)sqlite3Malloc(sqlite3BtreeCursorSize()); + curTemp = (BtCursor *)sqlite3_malloc(sqlite3BtreeCursorSize()); if( curTemp ){ assert( sqlite3_mutex_held(db->mutex) ); for(iDb=0; allOk && iDbnDb; iDb++){ @@ -68620,25 +63181,25 @@ static int sqlite3Prepare( const char *zDb = db->aDb[i].zName; sqlite3Error(db, SQLITE_LOCKED, "database schema is locked: %s", zDb); (void)sqlite3SafetyOff(db); - return sqlite3ApiExit(db, SQLITE_LOCKED); + return SQLITE_LOCKED; } } } memset(&sParse, 0, sizeof(sParse)); sParse.db = db; - if( nBytes>=0 && (nBytes==0 || zSql[nBytes-1]!=0) ){ + if( nBytes>=0 && zSql[nBytes-1]!=0 ){ char *zSqlCopy; int mxLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH]; if( nBytes>mxLen ){ sqlite3Error(db, SQLITE_TOOBIG, "statement too long"); (void)sqlite3SafetyOff(db); - return sqlite3ApiExit(db, SQLITE_TOOBIG); + return SQLITE_TOOBIG; } zSqlCopy = sqlite3DbStrNDup(db, zSql, nBytes); if( zSqlCopy ){ sqlite3RunParser(&sParse, zSqlCopy, &zErrMsg); - sqlite3DbFree(db, zSqlCopy); + sqlite3_free(zSqlCopy); sParse.zTail = &zSql[sParse.zTail-zSqlCopy]; }else{ sParse.zTail = &zSql[nBytes]; @@ -68702,7 +63263,7 @@ static int sqlite3Prepare( if( zErrMsg ){ sqlite3Error(db, rc, "%s", zErrMsg); - sqlite3DbFree(db, zErrMsg); + sqlite3_free(zErrMsg); }else{ sqlite3Error(db, rc, 0); } @@ -68758,7 +63319,7 @@ SQLITE_PRIVATE int sqlite3Reprepare(Vdbe *p){ assert( pNew!=0 ); } sqlite3VdbeSwap((Vdbe*)pNew, p); - sqlite3TransferBindings(pNew, (sqlite3_stmt*)p); + sqlite3_transfer_bindings(pNew, (sqlite3_stmt*)p); sqlite3VdbeResetStepResult((Vdbe*)pNew); sqlite3VdbeFinalize((Vdbe*)pNew); return 1; @@ -68837,7 +63398,7 @@ static int sqlite3Prepare16( int chars_parsed = sqlite3Utf8CharLen(zSql8, zTail8-zSql8); *pzTail = (u8 *)zSql + sqlite3Utf16ByteLen(zSql, chars_parsed); } - sqlite3DbFree(db, zSql8); + sqlite3_free(zSql8); rc = sqlite3ApiExit(db, rc); sqlite3_mutex_leave(db->mutex); return rc; @@ -68894,7 +63455,7 @@ SQLITE_API int sqlite3_prepare16_v2( ** This file contains C code routines that are called by the parser ** to handle SELECT statements in SQLite. ** -** $Id: select.c,v 1.480 2008/10/07 19:53:14 drh Exp $ +** $Id: select.c,v 1.429 2008/05/01 17:03:49 drh Exp $ */ @@ -68902,16 +63463,16 @@ SQLITE_API int sqlite3_prepare16_v2( ** Delete all the content of a Select structure but do not deallocate ** the select structure itself. */ -static void clearSelect(sqlite3 *db, Select *p){ - sqlite3ExprListDelete(db, p->pEList); - sqlite3SrcListDelete(db, p->pSrc); - sqlite3ExprDelete(db, p->pWhere); - sqlite3ExprListDelete(db, p->pGroupBy); - sqlite3ExprDelete(db, p->pHaving); - sqlite3ExprListDelete(db, p->pOrderBy); - sqlite3SelectDelete(db, p->pPrior); - sqlite3ExprDelete(db, p->pLimit); - sqlite3ExprDelete(db, p->pOffset); +static void clearSelect(Select *p){ + sqlite3ExprListDelete(p->pEList); + sqlite3SrcListDelete(p->pSrc); + sqlite3ExprDelete(p->pWhere); + sqlite3ExprListDelete(p->pGroupBy); + sqlite3ExprDelete(p->pHaving); + sqlite3ExprListDelete(p->pOrderBy); + sqlite3SelectDelete(p->pPrior); + sqlite3ExprDelete(p->pLimit); + sqlite3ExprDelete(p->pOffset); } /* @@ -68960,16 +63521,18 @@ SQLITE_PRIVATE Select *sqlite3SelectNew( pNew->pGroupBy = pGroupBy; pNew->pHaving = pHaving; pNew->pOrderBy = pOrderBy; - pNew->selFlags = isDistinct ? SF_Distinct : 0; + pNew->isDistinct = isDistinct; pNew->op = TK_SELECT; + assert( pOffset==0 || pLimit!=0 ); pNew->pLimit = pLimit; pNew->pOffset = pOffset; + pNew->iLimit = -1; + pNew->iOffset = -1; pNew->addrOpenEphm[0] = -1; pNew->addrOpenEphm[1] = -1; pNew->addrOpenEphm[2] = -1; - if( db->mallocFailed ) { - clearSelect(db, pNew); - if( pNew!=&standin ) sqlite3DbFree(db, pNew); + if( pNew==&standin) { + clearSelect(pNew); pNew = 0; } return pNew; @@ -68978,10 +63541,10 @@ SQLITE_PRIVATE Select *sqlite3SelectNew( /* ** Delete the given Select structure and all of its substructures. */ -SQLITE_PRIVATE void sqlite3SelectDelete(sqlite3 *db, Select *p){ +SQLITE_PRIVATE void sqlite3SelectDelete(Select *p){ if( p ){ - clearSelect(db, p); - sqlite3DbFree(db, p); + clearSelect(p); + sqlite3_free(p); } } @@ -69041,11 +63604,12 @@ SQLITE_PRIVATE int sqlite3JoinType(Parse *pParse, Token *pA, Token *pB, Token *p (jointype & (JT_INNER|JT_OUTER))==(JT_INNER|JT_OUTER) || (jointype & JT_ERROR)!=0 ){ - const char *zSp = " "; - assert( pB!=0 ); - if( pC==0 ){ zSp++; } + const char *zSp1 = " "; + const char *zSp2 = " "; + if( pB==0 ){ zSp1++; } + if( pC==0 ){ zSp2++; } sqlite3ErrorMsg(pParse, "unknown or unsupported join type: " - "%T %T%s%T", pA, pB, zSp, pC); + "%T%s%T%s%T", pA, zSp1, pB, zSp2, pC); jointype = JT_INNER; }else if( jointype & JT_RIGHT ){ sqlite3ErrorMsg(pParse, @@ -69084,17 +63648,15 @@ static void setToken(Token *p, const char *z){ */ static void setQuotedToken(Parse *pParse, Token *p, const char *z){ - /* Check if the string appears to be quoted using "..." or `...` - ** or [...] or '...' or if the string contains any " characters. - ** If it does, then record a version of the string with the special - ** characters escaped. + /* Check if the string contains any " characters. If it does, then + ** this function will malloc space to create a quoted version of + ** the string in. Otherwise, save a call to sqlite3MPrintf() by + ** just copying the pointer to the string. */ const char *z2 = z; - if( *z2!='[' && *z2!='`' && *z2!='\'' ){ - while( *z2 ){ - if( *z2=='"' ) break; - z2++; - } + while( *z2 ){ + if( *z2=='"' ) break; + z2++; } if( *z2 ){ @@ -69304,15 +63866,15 @@ static void pushOntoSorter( int regRecord = sqlite3GetTempReg(pParse); sqlite3ExprCodeExprList(pParse, pOrderBy, regBase, 0); sqlite3VdbeAddOp2(v, OP_Sequence, pOrderBy->iECursor, regBase+nExpr); - sqlite3ExprCodeMove(pParse, regData, regBase+nExpr+1, 1); + sqlite3ExprCodeMove(pParse, regData, regBase+nExpr+1); sqlite3VdbeAddOp3(v, OP_MakeRecord, regBase, nExpr + 2, regRecord); sqlite3VdbeAddOp2(v, OP_IdxInsert, pOrderBy->iECursor, regRecord); sqlite3ReleaseTempReg(pParse, regRecord); sqlite3ReleaseTempRange(pParse, regBase, nExpr+2); - if( pSelect->iLimit ){ + if( pSelect->iLimit>=0 ){ int addr1, addr2; int iLimit; - if( pSelect->iOffset ){ + if( pSelect->pOffset ){ iLimit = pSelect->iOffset+1; }else{ iLimit = pSelect->iLimit; @@ -69324,7 +63886,7 @@ static void pushOntoSorter( sqlite3VdbeAddOp1(v, OP_Last, pOrderBy->iECursor); sqlite3VdbeAddOp1(v, OP_Delete, pOrderBy->iECursor); sqlite3VdbeJumpHere(v, addr2); - pSelect->iLimit = 0; + pSelect->iLimit = -1; } } @@ -69336,7 +63898,7 @@ static void codeOffset( Select *p, /* The SELECT statement being coded */ int iContinue /* Jump here to skip the current record */ ){ - if( p->iOffset && iContinue!=0 ){ + if( p->iOffset>=0 && iContinue!=0 ){ int addr; sqlite3VdbeAddOp2(v, OP_AddImm, p->iOffset, -1); addr = sqlite3VdbeAddOp1(v, OP_IfNeg, p->iOffset); @@ -69413,7 +63975,8 @@ static void selectInnerLoop( int distinct, /* If >=0, make sure results are distinct */ SelectDest *pDest, /* How to dispose of the results */ int iContinue, /* Jump here to continue with next row */ - int iBreak /* Jump here to break out of the inner loop */ + int iBreak, /* Jump here to break out of the inner loop */ + char *aff /* affinity string if eDest is SRT_Union */ ){ Vdbe *v = pParse->pVdbe; int i; @@ -69425,7 +63988,11 @@ static void selectInnerLoop( if( v==0 ) return; assert( pEList!=0 ); - hasDistinct = distinct>=0; + + /* If there was a LIMIT clause on the SELECT statement, then do the check + ** to see if this row should be output. + */ + hasDistinct = distinct>=0 && pEList->nExpr>0; if( pOrderBy==0 && !hasDistinct ){ codeOffset(v, p, iContinue); } @@ -69438,9 +64005,8 @@ static void selectInnerLoop( nResultCol = pEList->nExpr; } if( pDest->iMem==0 ){ - pDest->iMem = pParse->nMem+1; + pDest->iMem = sqlite3GetTempRange(pParse, nResultCol); pDest->nMem = nResultCol; - pParse->nMem += nResultCol; }else if( pDest->nMem!=nResultCol ){ /* This happens when two SELECTs of a compound SELECT have differing ** numbers of result columns. The error message will be generated by @@ -69456,7 +64022,7 @@ static void selectInnerLoop( /* If the destination is an EXISTS(...) expression, the actual ** values returned by the SELECT are not required. */ - sqlite3ExprCodeExprList(pParse, pEList, regResult, eDest==SRT_Output); + sqlite3ExprCodeExprList(pParse, pEList, regResult, eDest==SRT_Callback); } nColumn = nResultCol; @@ -69486,6 +64052,9 @@ static void selectInnerLoop( int r1; r1 = sqlite3GetTempReg(pParse); sqlite3VdbeAddOp3(v, OP_MakeRecord, regResult, nColumn, r1); + if( aff ){ + sqlite3VdbeChangeP4(v, -1, aff, P4_STATIC); + } sqlite3VdbeAddOp2(v, OP_IdxInsert, iParm, r1); sqlite3ReleaseTempReg(pParse, r1); break; @@ -69526,7 +64095,10 @@ static void selectInnerLoop( ** item into the set table with bogus data. */ case SRT_Set: { + int addr2; + assert( nColumn==1 ); + addr2 = sqlite3VdbeAddOp1(v, OP_IsNull, regResult); p->affinity = sqlite3CompareAffinity(pEList->a[0].pExpr, pDest->affinity); if( pOrderBy ){ /* At first glance you would think we could optimize out the @@ -69541,6 +64113,7 @@ static void selectInnerLoop( sqlite3VdbeAddOp2(v, OP_IdxInsert, iParm, r1); sqlite3ReleaseTempReg(pParse, r1); } + sqlite3VdbeJumpHere(v, addr2); break; } @@ -69561,7 +64134,7 @@ static void selectInnerLoop( if( pOrderBy ){ pushOntoSorter(pParse, pOrderBy, p, regResult); }else{ - sqlite3ExprCodeMove(pParse, regResult, iParm, 1); + sqlite3ExprCodeMove(pParse, regResult, iParm); /* The LIMIT clause will jump out of the loop for us */ } break; @@ -69572,15 +64145,15 @@ static void selectInnerLoop( ** case of a subroutine, the subroutine itself is responsible for ** popping the data from the stack. */ - case SRT_Coroutine: - case SRT_Output: { + case SRT_Subroutine: + case SRT_Callback: { if( pOrderBy ){ int r1 = sqlite3GetTempReg(pParse); sqlite3VdbeAddOp3(v, OP_MakeRecord, regResult, nColumn, r1); pushOntoSorter(pParse, pOrderBy, p, r1); sqlite3ReleaseTempReg(pParse, r1); - }else if( eDest==SRT_Coroutine ){ - sqlite3VdbeAddOp1(v, OP_Yield, pDest->iParm); + }else if( eDest==SRT_Subroutine ){ + sqlite3VdbeAddOp2(v, OP_Gosub, 0, iParm); }else{ sqlite3VdbeAddOp2(v, OP_ResultRow, regResult, nColumn); sqlite3ExprCacheAffinityChange(pParse, regResult, nColumn); @@ -69603,9 +64176,7 @@ static void selectInnerLoop( /* Jump to the end of the loop if the LIMIT is reached. */ - if( p->iLimit ){ - assert( pOrderBy==0 ); /* If there is an ORDER BY, the call to - ** pushOntoSorter() would have cleared p->iLimit */ + if( p->iLimit>=0 && pOrderBy==0 ){ sqlite3VdbeAddOp2(v, OP_AddImm, p->iLimit, -1); sqlite3VdbeAddOp2(v, OP_IfZero, p->iLimit, iBreak); } @@ -69680,10 +64251,10 @@ static void generateSortTail( int regRowid; iTab = pOrderBy->iECursor; - if( eDest==SRT_Output || eDest==SRT_Coroutine ){ + if( eDest==SRT_Callback || eDest==SRT_Subroutine ){ pseudoTab = pParse->nTab++; sqlite3VdbeAddOp2(v, OP_SetNumColumns, 0, nColumn); - sqlite3VdbeAddOp2(v, OP_OpenPseudo, pseudoTab, eDest==SRT_Output); + sqlite3VdbeAddOp2(v, OP_OpenPseudo, pseudoTab, eDest==SRT_Callback); } addr = 1 + sqlite3VdbeAddOp2(v, OP_Sort, iTab, brk); codeOffset(v, p, cont); @@ -69700,21 +64271,24 @@ static void generateSortTail( } #ifndef SQLITE_OMIT_SUBQUERY case SRT_Set: { + int j1; assert( nColumn==1 ); + j1 = sqlite3VdbeAddOp1(v, OP_IsNull, regRow); sqlite3VdbeAddOp4(v, OP_MakeRecord, regRow, 1, regRowid, &p->affinity, 1); sqlite3ExprCacheAffinityChange(pParse, regRow, 1); sqlite3VdbeAddOp2(v, OP_IdxInsert, iParm, regRowid); + sqlite3VdbeJumpHere(v, j1); break; } case SRT_Mem: { assert( nColumn==1 ); - sqlite3ExprCodeMove(pParse, regRow, iParm, 1); + sqlite3ExprCodeMove(pParse, regRow, iParm); /* The LIMIT clause will terminate the loop for us */ break; } #endif - case SRT_Output: - case SRT_Coroutine: { + case SRT_Callback: + case SRT_Subroutine: { int i; sqlite3VdbeAddOp2(v, OP_Integer, 1, regRowid); sqlite3VdbeAddOp3(v, OP_Insert, pseudoTab, regRow, regRowid); @@ -69722,11 +64296,11 @@ static void generateSortTail( assert( regRow!=pDest->iMem+i ); sqlite3VdbeAddOp3(v, OP_Column, pseudoTab, i, pDest->iMem+i); } - if( eDest==SRT_Output ){ + if( eDest==SRT_Callback ){ sqlite3VdbeAddOp2(v, OP_ResultRow, pDest->iMem, nColumn); sqlite3ExprCacheAffinityChange(pParse, pDest->iMem, nColumn); }else{ - sqlite3VdbeAddOp1(v, OP_Yield, pDest->iParm); + sqlite3VdbeAddOp2(v, OP_Gosub, 0, iParm); } break; } @@ -69738,16 +64312,19 @@ static void generateSortTail( sqlite3ReleaseTempReg(pParse, regRow); sqlite3ReleaseTempReg(pParse, regRowid); - /* LIMIT has been implemented by the pushOntoSorter() routine. + /* Jump to the end of the loop when the LIMIT is reached */ - assert( p->iLimit==0 ); + if( p->iLimit>=0 ){ + sqlite3VdbeAddOp2(v, OP_AddImm, p->iLimit, -1); + sqlite3VdbeAddOp2(v, OP_IfZero, p->iLimit, brk); + } /* The bottom of the loop */ sqlite3VdbeResolveLabel(v, cont); sqlite3VdbeAddOp2(v, OP_Next, iTab, addr); sqlite3VdbeResolveLabel(v, brk); - if( eDest==SRT_Output || eDest==SRT_Coroutine ){ + if( eDest==SRT_Callback || eDest==SRT_Subroutine ){ sqlite3VdbeAddOp2(v, OP_Close, pseudoTab, 0); } @@ -69960,7 +64537,9 @@ static void generateColumnNames( if( pEList->a[i].zName ){ char *zName = pEList->a[i].zName; sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, strlen(zName)); - }else if( (p->op==TK_COLUMN || p->op==TK_AGG_COLUMN) && pTabList ){ + continue; + } + if( p->op==TK_COLUMN && pTabList ){ Table *pTab; char *zCol; int iCol = p->iColumn; @@ -69974,7 +64553,7 @@ static void generateColumnNames( }else{ zCol = pTab->aCol[iCol].zName; } - if( !shortNames && !fullNames ){ + if( !shortNames && !fullNames && p->span.z && p->span.z[0] ){ sqlite3VdbeSetColName(v, i, COLNAME_NAME, (char*)p->span.z, p->span.n); }else if( fullNames || (!shortNames && pTabList->nSrc>1) ){ char *zName = 0; @@ -69982,13 +64561,19 @@ static void generateColumnNames( zTab = pTabList->a[j].zAlias; if( fullNames || zTab==0 ) zTab = pTab->zName; - zName = sqlite3MPrintf(db, "%s.%s", zTab, zCol); + sqlite3SetString(&zName, zTab, ".", zCol, (char*)0); sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, P4_DYNAMIC); }else{ sqlite3VdbeSetColName(v, i, COLNAME_NAME, zCol, strlen(zCol)); } - }else{ + }else if( p->span.z && p->span.z[0] ){ sqlite3VdbeSetColName(v, i, COLNAME_NAME, (char*)p->span.z, p->span.n); + /* sqlite3VdbeCompressSpace(v, addr); */ + }else{ + char zName[30]; + assert( p->op!=TK_COLUMN || pTabList==0 ); + sqlite3_snprintf(sizeof(zName), zName, "column%d", i+1); + sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, 0); } } generateColumnTypes(pParse, pTabList, pEList); @@ -70011,36 +64596,47 @@ static const char *selectOpName(int id){ #endif /* SQLITE_OMIT_COMPOUND_SELECT */ /* -** Given a an expression list (which is really the list of expressions -** that form the result set of a SELECT statement) compute appropriate -** column names for a table that would hold the expression list. -** -** All column names will be unique. -** -** Only the column names are computed. Column.zType, Column.zColl, -** and other fields of Column are zeroed. -** -** Return SQLITE_OK on success. If a memory allocation error occurs, -** store NULL in *paCol and 0 in *pnCol and return SQLITE_NOMEM. +** Forward declaration */ -static int selectColumnsFromExprList( - Parse *pParse, /* Parsing context */ - ExprList *pEList, /* Expr list from which to derive column names */ - int *pnCol, /* Write the number of columns here */ - Column **paCol /* Write the new column list here */ -){ - sqlite3 *db = pParse->db; - int i, j, cnt; - Column *aCol, *pCol; - int nCol; - Expr *p; - char *zName; - int nName; +static int prepSelectStmt(Parse*, Select*); - *pnCol = nCol = pEList->nExpr; - aCol = *paCol = sqlite3DbMallocZero(db, sizeof(aCol[0])*nCol); - if( aCol==0 ) return SQLITE_NOMEM; - for(i=0, pCol=aCol; idb; + + while( pSelect->pPrior ) pSelect = pSelect->pPrior; + if( prepSelectStmt(pParse, pSelect) ){ + return 0; + } + if( sqlite3SelectResolve(pParse, pSelect, 0) ){ + return 0; + } + pTab = sqlite3DbMallocZero(db, sizeof(Table) ); + if( pTab==0 ){ + return 0; + } + pTab->nRef = 1; + pTab->zName = zTabName ? sqlite3DbStrDup(db, zTabName) : 0; + pEList = pSelect->pEList; + pTab->nCol = pEList->nExpr; + assert( pTab->nCol>0 ); + pTab->aCol = aCol = sqlite3DbMallocZero(db, sizeof(pTab->aCol[0])*pTab->nCol); + for(i=0, pCol=aCol; inCol; i++, pCol++){ + Expr *p, *pR; + char *zType; + char *zName; + int nName; + CollSeq *pColl; + int cnt; + NameContext sNC; + /* Get an appropriate name for the column */ p = pEList->a[i].pExpr; @@ -70048,24 +64644,22 @@ static int selectColumnsFromExprList( if( (zName = pEList->a[i].zName)!=0 ){ /* If the column contains an "AS " phrase, use as the name */ zName = sqlite3DbStrDup(db, zName); + }else if( p->op==TK_DOT + && (pR=p->pRight)!=0 && pR->token.z && pR->token.z[0] ){ + /* For columns of the from A.B use B as the name */ + zName = sqlite3MPrintf(db, "%T", &pR->token); + }else if( p->span.z && p->span.z[0] ){ + /* Use the original text of the column expression as its name */ + zName = sqlite3MPrintf(db, "%T", &p->span); }else{ - Expr *pCol = p; - Table *pTab; - while( pCol->op==TK_DOT ) pCol = pCol->pRight; - if( pCol->op==TK_COLUMN && (pTab = pCol->pTab)!=0 ){ - /* For columns use the column name name */ - int iCol = pCol->iColumn; - if( iCol<0 ) iCol = pTab->iPKey; - zName = sqlite3MPrintf(db, "%s", - iCol>=0 ? pTab->aCol[iCol].zName : "rowid"); - }else{ - /* Use the original text of the column expression as its name */ - zName = sqlite3MPrintf(db, "%T", &pCol->span); - } + /* If all else fails, make up a name */ + zName = sqlite3MPrintf(db, "column%d", i+1); } - if( db->mallocFailed ){ - sqlite3DbFree(db, zName); - break; + if( !zName || db->mallocFailed ){ + db->mallocFailed = 1; + sqlite3_free(zName); + sqlite3DeleteTable(pTab); + return 0; } sqlite3Dequote(zName); @@ -70075,104 +64669,531 @@ static int selectColumnsFromExprList( nName = strlen(zName); for(j=cnt=0; jzName = zName; - } - if( db->mallocFailed ){ - int j; - for(j=0; jdb; - NameContext sNC; - Column *pCol; - CollSeq *pColl; - int i; - Expr *p; - struct ExprList_item *a; - - assert( pSelect!=0 ); - assert( (pSelect->selFlags & SF_Resolved)!=0 ); - assert( nCol==pSelect->pEList->nExpr || db->mallocFailed ); - if( db->mallocFailed ) return; - memset(&sNC, 0, sizeof(sNC)); - sNC.pSrcList = pSelect->pSrc; - a = pSelect->pEList->a; - for(i=0, pCol=aCol; izType = sqlite3DbStrDup(db, columnType(&sNC, p, 0, 0, 0)); + /* Get the typename, type affinity, and collating sequence for the + ** column. + */ + memset(&sNC, 0, sizeof(sNC)); + sNC.pSrcList = pSelect->pSrc; + zType = sqlite3DbStrDup(db, columnType(&sNC, p, 0, 0, 0)); + pCol->zType = zType; pCol->affinity = sqlite3ExprAffinity(p); pColl = sqlite3ExprCollSeq(pParse, p); if( pColl ){ pCol->zColl = sqlite3DbStrDup(db, pColl->zName); } } + pTab->iPKey = -1; + return pTab; } /* -** Given a SELECT statement, generate a Table structure that describes -** the result set of that SELECT. +** Prepare a SELECT statement for processing by doing the following +** things: +** +** (1) Make sure VDBE cursor numbers have been assigned to every +** element of the FROM clause. +** +** (2) Fill in the pTabList->a[].pTab fields in the SrcList that +** defines FROM clause. When views appear in the FROM clause, +** fill pTabList->a[].pSelect with a copy of the SELECT statement +** that implements the view. A copy is made of the view's SELECT +** statement so that we can freely modify or delete that statement +** without worrying about messing up the presistent representation +** of the view. +** +** (3) Add terms to the WHERE clause to accomodate the NATURAL keyword +** on joins and the ON and USING clause of joins. +** +** (4) Scan the list of columns in the result set (pEList) looking +** for instances of the "*" operator or the TABLE.* operator. +** If found, expand each "*" to be every column in every table +** and TABLE.* to be every column in TABLE. +** +** Return 0 on success. If there are problems, leave an error message +** in pParse and return non-zero. */ -SQLITE_PRIVATE Table *sqlite3ResultSetOfSelect(Parse *pParse, Select *pSelect){ - Table *pTab; +static int prepSelectStmt(Parse *pParse, Select *p){ + int i, j, k, rc; + SrcList *pTabList; + ExprList *pEList; + struct SrcList_item *pFrom; sqlite3 *db = pParse->db; - int savedFlags; - savedFlags = db->flags; - db->flags &= ~SQLITE_FullColNames; - db->flags |= SQLITE_ShortColNames; - sqlite3SelectPrep(pParse, pSelect, 0); - if( pParse->nErr ) return 0; - while( pSelect->pPrior ) pSelect = pSelect->pPrior; - db->flags = savedFlags; - pTab = sqlite3DbMallocZero(db, sizeof(Table) ); - if( pTab==0 ){ - return 0; + if( p==0 || p->pSrc==0 || db->mallocFailed ){ + return 1; } - pTab->db = db; - pTab->nRef = 1; - pTab->zName = 0; - selectColumnsFromExprList(pParse, pSelect->pEList, &pTab->nCol, &pTab->aCol); - selectAddColumnTypeAndCollation(pParse, pTab->nCol, pTab->aCol, pSelect); - pTab->iPKey = -1; + pTabList = p->pSrc; + pEList = p->pEList; + + /* Make sure cursor numbers have been assigned to all entries in + ** the FROM clause of the SELECT statement. + */ + sqlite3SrcListAssignCursors(pParse, p->pSrc); + + /* Look up every table named in the FROM clause of the select. If + ** an entry of the FROM clause is a subquery instead of a table or view, + ** then create a transient table structure to describe the subquery. + */ + for(i=0, pFrom=pTabList->a; inSrc; i++, pFrom++){ + Table *pTab; + if( pFrom->pTab!=0 ){ + /* This statement has already been prepared. There is no need + ** to go further. */ + assert( i==0 ); + return 0; + } + if( pFrom->zName==0 ){ +#ifndef SQLITE_OMIT_SUBQUERY + /* A sub-query in the FROM clause of a SELECT */ + assert( pFrom->pSelect!=0 ); + if( pFrom->zAlias==0 ){ + pFrom->zAlias = + sqlite3MPrintf(db, "sqlite_subquery_%p_", (void*)pFrom->pSelect); + } + assert( pFrom->pTab==0 ); + pFrom->pTab = pTab = + sqlite3ResultSetOfSelect(pParse, pFrom->zAlias, pFrom->pSelect); + if( pTab==0 ){ + return 1; + } + /* The isEphem flag indicates that the Table structure has been + ** dynamically allocated and may be freed at any time. In other words, + ** pTab is not pointing to a persistent table structure that defines + ** part of the schema. */ + pTab->isEphem = 1; +#endif + }else{ + /* An ordinary table or view name in the FROM clause */ + assert( pFrom->pTab==0 ); + pFrom->pTab = pTab = + sqlite3LocateTable(pParse,0,pFrom->zName,pFrom->zDatabase); + if( pTab==0 ){ + return 1; + } + pTab->nRef++; +#if !defined(SQLITE_OMIT_VIEW) || !defined (SQLITE_OMIT_VIRTUALTABLE) + if( pTab->pSelect || IsVirtual(pTab) ){ + /* We reach here if the named table is a really a view */ + if( sqlite3ViewGetColumnNames(pParse, pTab) ){ + return 1; + } + /* If pFrom->pSelect!=0 it means we are dealing with a + ** view within a view. The SELECT structure has already been + ** copied by the outer view so we can skip the copy step here + ** in the inner view. + */ + if( pFrom->pSelect==0 ){ + pFrom->pSelect = sqlite3SelectDup(db, pTab->pSelect); + } + } +#endif + } + } + + /* Process NATURAL keywords, and ON and USING clauses of joins. + */ + if( sqliteProcessJoin(pParse, p) ) return 1; + + /* For every "*" that occurs in the column list, insert the names of + ** all columns in all tables. And for every TABLE.* insert the names + ** of all columns in TABLE. The parser inserted a special expression + ** with the TK_ALL operator for each "*" that it found in the column list. + ** The following code just has to locate the TK_ALL expressions and expand + ** each one to the list of all columns in all tables. + ** + ** The first loop just checks to see if there are any "*" operators + ** that need expanding. + */ + for(k=0; knExpr; k++){ + Expr *pE = pEList->a[k].pExpr; + if( pE->op==TK_ALL ) break; + if( pE->op==TK_DOT && pE->pRight && pE->pRight->op==TK_ALL + && pE->pLeft && pE->pLeft->op==TK_ID ) break; + } + rc = 0; + if( knExpr ){ + /* + ** If we get here it means the result set contains one or more "*" + ** operators that need to be expanded. Loop through each expression + ** in the result set and expand them one by one. + */ + struct ExprList_item *a = pEList->a; + ExprList *pNew = 0; + int flags = pParse->db->flags; + int longNames = (flags & SQLITE_FullColNames)!=0 && + (flags & SQLITE_ShortColNames)==0; + + for(k=0; knExpr; k++){ + Expr *pE = a[k].pExpr; + if( pE->op!=TK_ALL && + (pE->op!=TK_DOT || pE->pRight==0 || pE->pRight->op!=TK_ALL) ){ + /* This particular expression does not need to be expanded. + */ + pNew = sqlite3ExprListAppend(pParse, pNew, a[k].pExpr, 0); + if( pNew ){ + pNew->a[pNew->nExpr-1].zName = a[k].zName; + }else{ + rc = 1; + } + a[k].pExpr = 0; + a[k].zName = 0; + }else{ + /* This expression is a "*" or a "TABLE.*" and needs to be + ** expanded. */ + int tableSeen = 0; /* Set to 1 when TABLE matches */ + char *zTName; /* text of name of TABLE */ + if( pE->op==TK_DOT && pE->pLeft ){ + zTName = sqlite3NameFromToken(db, &pE->pLeft->token); + }else{ + zTName = 0; + } + for(i=0, pFrom=pTabList->a; inSrc; i++, pFrom++){ + Table *pTab = pFrom->pTab; + char *zTabName = pFrom->zAlias; + if( zTabName==0 || zTabName[0]==0 ){ + zTabName = pTab->zName; + } + if( zTName && (zTabName==0 || zTabName[0]==0 || + sqlite3StrICmp(zTName, zTabName)!=0) ){ + continue; + } + tableSeen = 1; + for(j=0; jnCol; j++){ + Expr *pExpr, *pRight; + char *zName = pTab->aCol[j].zName; + + /* If a column is marked as 'hidden' (currently only possible + ** for virtual tables), do not include it in the expanded + ** result-set list. + */ + if( IsHiddenColumn(&pTab->aCol[j]) ){ + assert(IsVirtual(pTab)); + continue; + } + + if( i>0 ){ + struct SrcList_item *pLeft = &pTabList->a[i-1]; + if( (pLeft[1].jointype & JT_NATURAL)!=0 && + columnIndex(pLeft->pTab, zName)>=0 ){ + /* In a NATURAL join, omit the join columns from the + ** table on the right */ + continue; + } + if( sqlite3IdListIndex(pLeft[1].pUsing, zName)>=0 ){ + /* In a join with a USING clause, omit columns in the + ** using clause from the table on the right. */ + continue; + } + } + pRight = sqlite3PExpr(pParse, TK_ID, 0, 0, 0); + if( pRight==0 ) break; + setQuotedToken(pParse, &pRight->token, zName); + if( zTabName && (longNames || pTabList->nSrc>1) ){ + Expr *pLeft = sqlite3PExpr(pParse, TK_ID, 0, 0, 0); + pExpr = sqlite3PExpr(pParse, TK_DOT, pLeft, pRight, 0); + if( pExpr==0 ) break; + setQuotedToken(pParse, &pLeft->token, zTabName); + setToken(&pExpr->span, + sqlite3MPrintf(db, "%s.%s", zTabName, zName)); + pExpr->span.dyn = 1; + pExpr->token.z = 0; + pExpr->token.n = 0; + pExpr->token.dyn = 0; + }else{ + pExpr = pRight; + pExpr->span = pExpr->token; + pExpr->span.dyn = 0; + } + if( longNames ){ + pNew = sqlite3ExprListAppend(pParse, pNew, pExpr, &pExpr->span); + }else{ + pNew = sqlite3ExprListAppend(pParse, pNew, pExpr, &pRight->token); + } + } + } + if( !tableSeen ){ + if( zTName ){ + sqlite3ErrorMsg(pParse, "no such table: %s", zTName); + }else{ + sqlite3ErrorMsg(pParse, "no tables specified"); + } + rc = 1; + } + sqlite3_free(zTName); + } + } + sqlite3ExprListDelete(pEList); + p->pEList = pNew; + } +#if SQLITE_MAX_COLUMN + if( p->pEList && p->pEList->nExpr>db->aLimit[SQLITE_LIMIT_COLUMN] ){ + sqlite3ErrorMsg(pParse, "too many columns in result set"); + rc = SQLITE_ERROR; + } +#endif if( db->mallocFailed ){ - sqlite3DeleteTable(pTab); + rc = SQLITE_NOMEM; + } + return rc; +} + +/* +** pE is a pointer to an expression which is a single term in +** ORDER BY or GROUP BY clause. +** +** If pE evaluates to an integer constant i, then return i. +** This is an indication to the caller that it should sort +** by the i-th column of the result set. +** +** If pE is a well-formed expression and the SELECT statement +** is not compound, then return 0. This indicates to the +** caller that it should sort by the value of the ORDER BY +** expression. +** +** If the SELECT is compound, then attempt to match pE against +** result set columns in the left-most SELECT statement. Return +** the index i of the matching column, as an indication to the +** caller that it should sort by the i-th column. If there is +** no match, return -1 and leave an error message in pParse. +*/ +static int matchOrderByTermToExprList( + Parse *pParse, /* Parsing context for error messages */ + Select *pSelect, /* The SELECT statement with the ORDER BY clause */ + Expr *pE, /* The specific ORDER BY term */ + int idx, /* When ORDER BY term is this */ + int isCompound, /* True if this is a compound SELECT */ + u8 *pHasAgg /* True if expression contains aggregate functions */ +){ + int i; /* Loop counter */ + ExprList *pEList; /* The columns of the result set */ + NameContext nc; /* Name context for resolving pE */ + + + /* If the term is an integer constant, return the value of that + ** constant */ + pEList = pSelect->pEList; + if( sqlite3ExprIsInteger(pE, &i) ){ + if( i<=0 ){ + /* If i is too small, make it too big. That way the calling + ** function still sees a value that is out of range, but does + ** not confuse the column number with 0 or -1 result code. + */ + i = pEList->nExpr+1; + } + return i; + } + + /* If the term is a simple identifier that try to match that identifier + ** against a column name in the result set. + */ + if( pE->op==TK_ID || (pE->op==TK_STRING && pE->token.z[0]!='\'') ){ + sqlite3 *db = pParse->db; + char *zCol = sqlite3NameFromToken(db, &pE->token); + if( zCol==0 ){ + return -1; + } + for(i=0; inExpr; i++){ + char *zAs = pEList->a[i].zName; + if( zAs!=0 && sqlite3StrICmp(zAs, zCol)==0 ){ + sqlite3_free(zCol); + return i+1; + } + } + sqlite3_free(zCol); + } + + /* Resolve all names in the ORDER BY term expression + */ + memset(&nc, 0, sizeof(nc)); + nc.pParse = pParse; + nc.pSrcList = pSelect->pSrc; + nc.pEList = pEList; + nc.allowAgg = 1; + nc.nErr = 0; + if( sqlite3ExprResolveNames(&nc, pE) ){ + if( isCompound ){ + sqlite3ErrorClear(pParse); + return 0; + }else{ + return -1; + } + } + if( nc.hasAgg && pHasAgg ){ + *pHasAgg = 1; + } + + /* For a compound SELECT, we need to try to match the ORDER BY + ** expression against an expression in the result set + */ + if( isCompound ){ + for(i=0; inExpr; i++){ + if( sqlite3ExprCompare(pEList->a[i].pExpr, pE) ){ + return i+1; + } + } + } + return 0; +} + + +/* +** Analyze and ORDER BY or GROUP BY clause in a simple SELECT statement. +** Return the number of errors seen. +** +** Every term of the ORDER BY or GROUP BY clause needs to be an +** expression. If any expression is an integer constant, then +** that expression is replaced by the corresponding +** expression from the result set. +*/ +static int processOrderGroupBy( + Parse *pParse, /* Parsing context. Leave error messages here */ + Select *pSelect, /* The SELECT statement containing the clause */ + ExprList *pOrderBy, /* The ORDER BY or GROUP BY clause to be processed */ + int isOrder, /* 1 for ORDER BY. 0 for GROUP BY */ + u8 *pHasAgg /* Set to TRUE if any term contains an aggregate */ +){ + int i; + sqlite3 *db = pParse->db; + ExprList *pEList; + + if( pOrderBy==0 || pParse->db->mallocFailed ) return 0; +#if SQLITE_MAX_COLUMN + if( pOrderBy->nExpr>db->aLimit[SQLITE_LIMIT_COLUMN] ){ + const char *zType = isOrder ? "ORDER" : "GROUP"; + sqlite3ErrorMsg(pParse, "too many terms in %s BY clause", zType); + return 1; + } +#endif + pEList = pSelect->pEList; + if( pEList==0 ){ return 0; } - return pTab; + for(i=0; inExpr; i++){ + int iCol; + Expr *pE = pOrderBy->a[i].pExpr; + iCol = matchOrderByTermToExprList(pParse, pSelect, pE, i+1, 0, pHasAgg); + if( iCol<0 ){ + return 1; + } + if( iCol>pEList->nExpr ){ + const char *zType = isOrder ? "ORDER" : "GROUP"; + sqlite3ErrorMsg(pParse, + "%r %s BY term out of range - should be " + "between 1 and %d", i+1, zType, pEList->nExpr); + return 1; + } + if( iCol>0 ){ + CollSeq *pColl = pE->pColl; + int flags = pE->flags & EP_ExpCollate; + sqlite3ExprDelete(pE); + pE = sqlite3ExprDup(db, pEList->a[iCol-1].pExpr); + pOrderBy->a[i].pExpr = pE; + if( pE && pColl && flags ){ + pE->pColl = pColl; + pE->flags |= flags; + } + } + } + return 0; +} + +/* +** Analyze and ORDER BY or GROUP BY clause in a SELECT statement. Return +** the number of errors seen. +** +** The processing depends on whether the SELECT is simple or compound. +** For a simple SELECT statement, evry term of the ORDER BY or GROUP BY +** clause needs to be an expression. If any expression is an integer +** constant, then that expression is replaced by the corresponding +** expression from the result set. +** +** For compound SELECT statements, every expression needs to be of +** type TK_COLUMN with a iTable value as given in the 4th parameter. +** If any expression is an integer, that becomes the column number. +** Otherwise, match the expression against result set columns from +** the left-most SELECT. +*/ +static int processCompoundOrderBy( + Parse *pParse, /* Parsing context. Leave error messages here */ + Select *pSelect, /* The SELECT statement containing the ORDER BY */ + int iTable /* Output table for compound SELECT statements */ +){ + int i; + ExprList *pOrderBy; + ExprList *pEList; + sqlite3 *db; + int moreToDo = 1; + + pOrderBy = pSelect->pOrderBy; + if( pOrderBy==0 ) return 0; + db = pParse->db; +#if SQLITE_MAX_COLUMN + if( pOrderBy->nExpr>db->aLimit[SQLITE_LIMIT_COLUMN] ){ + sqlite3ErrorMsg(pParse, "too many terms in ORDER BY clause"); + return 1; + } +#endif + for(i=0; inExpr; i++){ + pOrderBy->a[i].done = 0; + } + while( pSelect->pPrior ){ + pSelect = pSelect->pPrior; + } + while( pSelect && moreToDo ){ + moreToDo = 0; + for(i=0; inExpr; i++){ + int iCol = -1; + Expr *pE, *pDup; + if( pOrderBy->a[i].done ) continue; + pE = pOrderBy->a[i].pExpr; + pDup = sqlite3ExprDup(db, pE); + if( !db->mallocFailed ){ + assert(pDup); + iCol = matchOrderByTermToExprList(pParse, pSelect, pDup, i+1, 1, 0); + } + sqlite3ExprDelete(pDup); + if( iCol<0 ){ + return 1; + } + pEList = pSelect->pEList; + if( pEList==0 ){ + return 1; + } + if( iCol>pEList->nExpr ){ + sqlite3ErrorMsg(pParse, + "%r ORDER BY term out of range - should be " + "between 1 and %d", i+1, pEList->nExpr); + return 1; + } + if( iCol>0 ){ + pE->op = TK_COLUMN; + pE->iTable = iTable; + pE->iAgg = -1; + pE->iColumn = iCol-1; + pE->pTab = 0; + pOrderBy->a[i].done = 1; + }else{ + moreToDo = 1; + } + } + pSelect = pSelect->pNext; + } + for(i=0; inExpr; i++){ + if( pOrderBy->a[i].done==0 ){ + sqlite3ErrorMsg(pParse, "%r ORDER BY term does not match any " + "column in the result set", i+1); + return 1; + } + } + return 0; } /* @@ -70216,7 +65237,6 @@ static void computeLimitRegisters(Parse *pParse, Select *p, int iBreak){ int iLimit = 0; int iOffset; int addr1; - if( p->iLimit ) return; /* ** "LIMIT -1" always shows all rows. There is some @@ -70256,6 +65276,21 @@ static void computeLimitRegisters(Parse *pParse, Select *p, int iBreak){ } } +/* +** Allocate a virtual index to use for sorting. +*/ +static void createSortingIndex(Parse *pParse, Select *p, ExprList *pOrderBy){ + if( pOrderBy ){ + int addr; + assert( pOrderBy->iECursor==0 ); + pOrderBy->iECursor = pParse->nTab++; + addr = sqlite3VdbeAddOp2(pParse->pVdbe, OP_OpenEphemeral, + pOrderBy->iECursor, pOrderBy->nExpr+1); + assert( p->addrOpenEphm[2] == -1 ); + p->addrOpenEphm[2] = addr; + } +} + #ifndef SQLITE_OMIT_COMPOUND_SELECT /* ** Return the appropriate collating sequence for the iCol-th column of @@ -70279,19 +65314,10 @@ static CollSeq *multiSelectCollSeq(Parse *pParse, Select *p, int iCol){ } #endif /* SQLITE_OMIT_COMPOUND_SELECT */ -/* Forward reference */ -static int multiSelectOrderBy( - Parse *pParse, /* Parsing context */ - Select *p, /* The right-most of SELECTs to be coded */ - SelectDest *pDest /* What to do with query results */ -); - - #ifndef SQLITE_OMIT_COMPOUND_SELECT /* -** This routine is called to process a compound query form from -** two or more separate queries using UNION, UNION ALL, EXCEPT, or -** INTERSECT +** This routine is called to process a query that is really the union +** or intersection of two or more separate queries. ** ** "p" points to the right-most of the two queries. the query on the ** left is p->pPrior. The left query could also be a compound query @@ -70322,24 +65348,30 @@ static int multiSelectOrderBy( static int multiSelect( Parse *pParse, /* Parsing context */ Select *p, /* The right-most of SELECTs to be coded */ - SelectDest *pDest /* What to do with query results */ + SelectDest *pDest, /* What to do with query results */ + char *aff /* If eDest is SRT_Union, the affinity string */ ){ int rc = SQLITE_OK; /* Success code from a subroutine */ Select *pPrior; /* Another SELECT immediately to our left */ Vdbe *v; /* Generate code to this VDBE */ + int nCol; /* Number of columns in the result set */ + ExprList *pOrderBy; /* The ORDER BY clause on p */ + int aSetP2[2]; /* Set P2 value of these op to number of columns */ + int nSetP2 = 0; /* Number of slots in aSetP2[] used */ SelectDest dest; /* Alternative data destination */ - Select *pDelete = 0; /* Chain of simple selects to delete */ - sqlite3 *db; /* Database connection */ + + dest = *pDest; /* Make sure there is no ORDER BY or LIMIT clause on prior SELECTs. Only ** the last (right-most) SELECT in the series may have an ORDER BY or LIMIT. */ - assert( p && p->pPrior ); /* Calling function guarantees this much */ - db = pParse->db; + if( p==0 || p->pPrior==0 ){ + rc = 1; + goto multi_select_end; + } pPrior = p->pPrior; assert( pPrior->pRightmost!=pPrior ); assert( pPrior->pRightmost==p->pRightmost ); - dest = *pDest; if( pPrior->pOrderBy ){ sqlite3ErrorMsg(pParse,"ORDER BY clause should come after %s not before", selectOpName(p->op)); @@ -70353,65 +65385,57 @@ static int multiSelect( goto multi_select_end; } + /* Make sure we have a valid query engine. If not, create a new one. + */ v = sqlite3GetVdbe(pParse); - assert( v!=0 ); /* The VDBE already created by calling function */ + if( v==0 ){ + rc = 1; + goto multi_select_end; + } /* Create the destination temporary table if necessary */ if( dest.eDest==SRT_EphemTab ){ assert( p->pEList ); - sqlite3VdbeAddOp2(v, OP_OpenEphemeral, dest.iParm, p->pEList->nExpr); + assert( nSetP2pEList && pPrior->pEList ); - if( p->pEList->nExpr!=pPrior->pEList->nExpr ){ - sqlite3ErrorMsg(pParse, "SELECTs to the left and right of %s" - " do not have the same number of result columns", selectOpName(p->op)); - rc = 1; - goto multi_select_end; - } - - /* Compound SELECTs that have an ORDER BY clause are handled separately. - */ - if( p->pOrderBy ){ - return multiSelectOrderBy(pParse, p, pDest); - } - /* Generate code for the left and right SELECT statements. */ + pOrderBy = p->pOrderBy; switch( p->op ){ case TK_ALL: { - int addr = 0; - assert( !pPrior->pLimit ); - pPrior->pLimit = p->pLimit; - pPrior->pOffset = p->pOffset; - rc = sqlite3Select(pParse, pPrior, &dest); - p->pLimit = 0; - p->pOffset = 0; - if( rc ){ - goto multi_select_end; + if( pOrderBy==0 ){ + int addr = 0; + assert( !pPrior->pLimit ); + pPrior->pLimit = p->pLimit; + pPrior->pOffset = p->pOffset; + rc = sqlite3Select(pParse, pPrior, &dest, 0, 0, 0, aff); + p->pLimit = 0; + p->pOffset = 0; + if( rc ){ + goto multi_select_end; + } + p->pPrior = 0; + p->iLimit = pPrior->iLimit; + p->iOffset = pPrior->iOffset; + if( p->iLimit>=0 ){ + addr = sqlite3VdbeAddOp1(v, OP_IfZero, p->iLimit); + VdbeComment((v, "Jump ahead if LIMIT reached")); + } + rc = sqlite3Select(pParse, p, &dest, 0, 0, 0, aff); + p->pPrior = pPrior; + if( rc ){ + goto multi_select_end; + } + if( addr ){ + sqlite3VdbeJumpHere(v, addr); + } + break; } - p->pPrior = 0; - p->iLimit = pPrior->iLimit; - p->iOffset = pPrior->iOffset; - if( p->iLimit ){ - addr = sqlite3VdbeAddOp1(v, OP_IfZero, p->iLimit); - VdbeComment((v, "Jump ahead if LIMIT reached")); - } - rc = sqlite3Select(pParse, p, &dest); - pDelete = p->pPrior; - p->pPrior = pPrior; - if( rc ){ - goto multi_select_end; - } - if( addr ){ - sqlite3VdbeJumpHere(v, addr); - } - break; + /* For UNION ALL ... ORDER BY fall through to the next case */ } case TK_EXCEPT: case TK_UNION: { @@ -70422,8 +65446,8 @@ static int multiSelect( int addr; SelectDest uniondest; - priorOp = SRT_Union; - if( dest.eDest==priorOp && !p->pLimit && !p->pOffset ){ + priorOp = p->op==TK_ALL ? SRT_Table : SRT_Union; + if( dest.eDest==priorOp && pOrderBy==0 && !p->pLimit && !p->pOffset ){ /* We can reuse a temporary table generated by a SELECT to our ** right. */ @@ -70433,11 +65457,20 @@ static int multiSelect( ** intermediate results. */ unionTab = pParse->nTab++; - assert( p->pOrderBy==0 ); + if( processCompoundOrderBy(pParse, p, unionTab) ){ + rc = 1; + goto multi_select_end; + } addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, unionTab, 0); - assert( p->addrOpenEphm[0] == -1 ); - p->addrOpenEphm[0] = addr; - p->pRightmost->selFlags |= SF_UsesEphemeral; + if( priorOp==SRT_Table ){ + assert( nSetP2addrOpenEphm[0] == -1 ); + p->addrOpenEphm[0] = addr; + p->pRightmost->usesEphm = 1; + } + createSortingIndex(pParse, p, pOrderBy); assert( p->pEList ); } @@ -70445,37 +65478,37 @@ static int multiSelect( */ assert( !pPrior->pOrderBy ); sqlite3SelectDestInit(&uniondest, priorOp, unionTab); - rc = sqlite3Select(pParse, pPrior, &uniondest); + rc = sqlite3Select(pParse, pPrior, &uniondest, 0, 0, 0, aff); if( rc ){ goto multi_select_end; } /* Code the current SELECT statement */ - if( p->op==TK_EXCEPT ){ - op = SRT_Except; - }else{ - assert( p->op==TK_UNION ); - op = SRT_Union; + switch( p->op ){ + case TK_EXCEPT: op = SRT_Except; break; + case TK_UNION: op = SRT_Union; break; + case TK_ALL: op = SRT_Table; break; } p->pPrior = 0; + p->pOrderBy = 0; + p->disallowOrderBy = pOrderBy!=0; pLimit = p->pLimit; p->pLimit = 0; pOffset = p->pOffset; p->pOffset = 0; uniondest.eDest = op; - rc = sqlite3Select(pParse, p, &uniondest); + rc = sqlite3Select(pParse, p, &uniondest, 0, 0, 0, aff); /* Query flattening in sqlite3Select() might refill p->pOrderBy. ** Be sure to delete p->pOrderBy, therefore, to avoid a memory leak. */ - sqlite3ExprListDelete(db, p->pOrderBy); - pDelete = p->pPrior; + sqlite3ExprListDelete(p->pOrderBy); p->pPrior = pPrior; - p->pOrderBy = 0; - sqlite3ExprDelete(db, p->pLimit); + p->pOrderBy = pOrderBy; + sqlite3ExprDelete(p->pLimit); p->pLimit = pLimit; p->pOffset = pOffset; - p->iLimit = 0; - p->iOffset = 0; + p->iLimit = -1; + p->iOffset = -1; if( rc ){ goto multi_select_end; } @@ -70487,7 +65520,7 @@ static int multiSelect( if( dest.eDest!=priorOp || unionTab!=dest.iParm ){ int iCont, iBreak, iStart; assert( p->pEList ); - if( dest.eDest==SRT_Output ){ + if( dest.eDest==SRT_Callback ){ Select *pFirst = p; while( pFirst->pPrior ) pFirst = pFirst->pPrior; generateColumnNames(pParse, 0, pFirst->pEList); @@ -70498,7 +65531,7 @@ static int multiSelect( sqlite3VdbeAddOp2(v, OP_Rewind, unionTab, iBreak); iStart = sqlite3VdbeCurrentAddr(v); selectInnerLoop(pParse, p, p->pEList, unionTab, p->pEList->nExpr, - 0, -1, &dest, iCont, iBreak); + pOrderBy, -1, &dest, iCont, iBreak, 0); sqlite3VdbeResolveLabel(v, iCont); sqlite3VdbeAddOp2(v, OP_Next, unionTab, iStart); sqlite3VdbeResolveLabel(v, iBreak); @@ -70520,18 +65553,22 @@ static int multiSelect( */ tab1 = pParse->nTab++; tab2 = pParse->nTab++; - assert( p->pOrderBy==0 ); + if( processCompoundOrderBy(pParse, p, tab1) ){ + rc = 1; + goto multi_select_end; + } + createSortingIndex(pParse, p, pOrderBy); addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, tab1, 0); assert( p->addrOpenEphm[0] == -1 ); p->addrOpenEphm[0] = addr; - p->pRightmost->selFlags |= SF_UsesEphemeral; + p->pRightmost->usesEphm = 1; assert( p->pEList ); /* Code the SELECTs to our left into temporary table "tab1". */ sqlite3SelectDestInit(&intersectdest, SRT_Union, tab1); - rc = sqlite3Select(pParse, pPrior, &intersectdest); + rc = sqlite3Select(pParse, pPrior, &intersectdest, 0, 0, 0, aff); if( rc ){ goto multi_select_end; } @@ -70547,10 +65584,9 @@ static int multiSelect( pOffset = p->pOffset; p->pOffset = 0; intersectdest.iParm = tab2; - rc = sqlite3Select(pParse, p, &intersectdest); - pDelete = p->pPrior; + rc = sqlite3Select(pParse, p, &intersectdest, 0, 0, 0, aff); p->pPrior = pPrior; - sqlite3ExprDelete(db, p->pLimit); + sqlite3ExprDelete(p->pLimit); p->pLimit = pLimit; p->pOffset = pOffset; if( rc ){ @@ -70561,7 +65597,7 @@ static int multiSelect( ** tables. */ assert( p->pEList ); - if( dest.eDest==SRT_Output ){ + if( dest.eDest==SRT_Callback ){ Select *pFirst = p; while( pFirst->pPrior ) pFirst = pFirst->pPrior; generateColumnNames(pParse, 0, pFirst->pEList); @@ -70575,7 +65611,7 @@ static int multiSelect( sqlite3VdbeAddOp3(v, OP_NotFound, tab2, iCont, r1); sqlite3ReleaseTempReg(pParse, r1); selectInnerLoop(pParse, p, p->pEList, tab1, p->pEList->nExpr, - 0, -1, &dest, iCont, iBreak); + pOrderBy, -1, &dest, iCont, iBreak, 0); sqlite3VdbeResolveLabel(v, iCont); sqlite3VdbeAddOp2(v, OP_Next, tab1, iStart); sqlite3VdbeResolveLabel(v, iBreak); @@ -70585,38 +65621,58 @@ static int multiSelect( } } - /* Compute collating sequences used by - ** temporary tables needed to implement the compound select. - ** Attach the KeyInfo structure to all temporary tables. + /* Make sure all SELECTs in the statement have the same number of elements + ** in their result sets. + */ + assert( p->pEList && pPrior->pEList ); + if( p->pEList->nExpr!=pPrior->pEList->nExpr ){ + sqlite3ErrorMsg(pParse, "SELECTs to the left and right of %s" + " do not have the same number of result columns", selectOpName(p->op)); + rc = 1; + goto multi_select_end; + } + + /* Set the number of columns in temporary tables + */ + nCol = p->pEList->nExpr; + while( nSetP2 ){ + sqlite3VdbeChangeP2(v, aSetP2[--nSetP2], nCol); + } + + /* Compute collating sequences used by either the ORDER BY clause or + ** by any temporary tables needed to implement the compound select. + ** Attach the KeyInfo structure to all temporary tables. Invoke the + ** ORDER BY processing if there is an ORDER BY clause. ** ** This section is run by the right-most SELECT statement only. ** SELECT statements to the left always skip this part. The right-most ** SELECT might also skip this part if it has no ORDER BY clause and ** no temp tables are required. */ - if( p->selFlags & SF_UsesEphemeral ){ + if( pOrderBy || p->usesEphm ){ int i; /* Loop counter */ KeyInfo *pKeyInfo; /* Collating sequence for the result set */ Select *pLoop; /* For looping through SELECT statements */ + int nKeyCol; /* Number of entries in pKeyInfo->aCol[] */ CollSeq **apColl; /* For looping through pKeyInfo->aColl[] */ - int nCol; /* Number of columns in result set */ + CollSeq **aCopy; /* A copy of pKeyInfo->aColl[] */ assert( p->pRightmost==p ); - nCol = p->pEList->nExpr; - pKeyInfo = sqlite3DbMallocZero(db, - sizeof(*pKeyInfo)+nCol*(sizeof(CollSeq*) + 1)); + nKeyCol = nCol + (pOrderBy ? pOrderBy->nExpr : 0); + pKeyInfo = sqlite3DbMallocZero(pParse->db, + sizeof(*pKeyInfo)+nKeyCol*(sizeof(CollSeq*) + 1)); if( !pKeyInfo ){ rc = SQLITE_NOMEM; goto multi_select_end; } - pKeyInfo->enc = ENC(db); + pKeyInfo->enc = ENC(pParse->db); pKeyInfo->nField = nCol; for(i=0, apColl=pKeyInfo->aColl; ipDfltColl; + *apColl = pParse->db->pDfltColl; } } @@ -70634,608 +65690,62 @@ static int multiSelect( pLoop->addrOpenEphm[i] = -1; } } - sqlite3DbFree(db, pKeyInfo); + + if( pOrderBy ){ + struct ExprList_item *pOTerm = pOrderBy->a; + int nOrderByExpr = pOrderBy->nExpr; + int addr; + u8 *pSortOrder; + + /* Reuse the same pKeyInfo for the ORDER BY as was used above for + ** the compound select statements. Except we have to change out the + ** pKeyInfo->aColl[] values. Some of the aColl[] values will be + ** reused when constructing the pKeyInfo for the ORDER BY, so make + ** a copy. Sufficient space to hold both the nCol entries for + ** the compound select and the nOrderbyExpr entries for the ORDER BY + ** was allocated above. But we need to move the compound select + ** entries out of the way before constructing the ORDER BY entries. + ** Move the compound select entries into aCopy[] where they can be + ** accessed and reused when constructing the ORDER BY entries. + ** Because nCol might be greater than or less than nOrderByExpr + ** we have to use memmove() when doing the copy. + */ + aCopy = &pKeyInfo->aColl[nOrderByExpr]; + pSortOrder = pKeyInfo->aSortOrder = (u8*)&aCopy[nCol]; + memmove(aCopy, pKeyInfo->aColl, nCol*sizeof(CollSeq*)); + + apColl = pKeyInfo->aColl; + for(i=0; ipExpr; + if( (pExpr->flags & EP_ExpCollate) ){ + assert( pExpr->pColl!=0 ); + *apColl = pExpr->pColl; + }else{ + *apColl = aCopy[pExpr->iColumn]; + } + *pSortOrder = pOTerm->sortOrder; + } + assert( p->pRightmost==p ); + assert( p->addrOpenEphm[2]>=0 ); + addr = p->addrOpenEphm[2]; + sqlite3VdbeChangeP2(v, addr, p->pOrderBy->nExpr+2); + pKeyInfo->nField = nOrderByExpr; + sqlite3VdbeChangeP4(v, addr, (char*)pKeyInfo, P4_KEYINFO_HANDOFF); + pKeyInfo = 0; + generateSortTail(pParse, p, v, p->pEList->nExpr, &dest); + } + + sqlite3_free(pKeyInfo); } multi_select_end: pDest->iMem = dest.iMem; pDest->nMem = dest.nMem; - sqlite3SelectDelete(db, pDelete); return rc; } #endif /* SQLITE_OMIT_COMPOUND_SELECT */ -/* -** Code an output subroutine for a coroutine implementation of a -** SELECT statment. -** -** The data to be output is contained in pIn->iMem. There are -** pIn->nMem columns to be output. pDest is where the output should -** be sent. -** -** regReturn is the number of the register holding the subroutine -** return address. -** -** If regPrev>0 then it is a the first register in a vector that -** records the previous output. mem[regPrev] is a flag that is false -** if there has been no previous output. If regPrev>0 then code is -** generated to suppress duplicates. pKeyInfo is used for comparing -** keys. -** -** If the LIMIT found in p->iLimit is reached, jump immediately to -** iBreak. -*/ -static int generateOutputSubroutine( - Parse *pParse, /* Parsing context */ - Select *p, /* The SELECT statement */ - SelectDest *pIn, /* Coroutine supplying data */ - SelectDest *pDest, /* Where to send the data */ - int regReturn, /* The return address register */ - int regPrev, /* Previous result register. No uniqueness if 0 */ - KeyInfo *pKeyInfo, /* For comparing with previous entry */ - int p4type, /* The p4 type for pKeyInfo */ - int iBreak /* Jump here if we hit the LIMIT */ -){ - Vdbe *v = pParse->pVdbe; - int iContinue; - int addr; - - addr = sqlite3VdbeCurrentAddr(v); - iContinue = sqlite3VdbeMakeLabel(v); - - /* Suppress duplicates for UNION, EXCEPT, and INTERSECT - */ - if( regPrev ){ - int j1, j2; - j1 = sqlite3VdbeAddOp1(v, OP_IfNot, regPrev); - j2 = sqlite3VdbeAddOp4(v, OP_Compare, pIn->iMem, regPrev+1, pIn->nMem, - (char*)pKeyInfo, p4type); - sqlite3VdbeAddOp3(v, OP_Jump, j2+2, iContinue, j2+2); - sqlite3VdbeJumpHere(v, j1); - sqlite3ExprCodeCopy(pParse, pIn->iMem, regPrev+1, pIn->nMem); - sqlite3VdbeAddOp2(v, OP_Integer, 1, regPrev); - } - if( pParse->db->mallocFailed ) return 0; - - /* Suppress the the first OFFSET entries if there is an OFFSET clause - */ - codeOffset(v, p, iContinue); - - switch( pDest->eDest ){ - /* Store the result as data using a unique key. - */ - case SRT_Table: - case SRT_EphemTab: { - int r1 = sqlite3GetTempReg(pParse); - int r2 = sqlite3GetTempReg(pParse); - sqlite3VdbeAddOp3(v, OP_MakeRecord, pIn->iMem, pIn->nMem, r1); - sqlite3VdbeAddOp2(v, OP_NewRowid, pDest->iParm, r2); - sqlite3VdbeAddOp3(v, OP_Insert, pDest->iParm, r1, r2); - sqlite3VdbeChangeP5(v, OPFLAG_APPEND); - sqlite3ReleaseTempReg(pParse, r2); - sqlite3ReleaseTempReg(pParse, r1); - break; - } - -#ifndef SQLITE_OMIT_SUBQUERY - /* If we are creating a set for an "expr IN (SELECT ...)" construct, - ** then there should be a single item on the stack. Write this - ** item into the set table with bogus data. - */ - case SRT_Set: { - int r1; - assert( pIn->nMem==1 ); - p->affinity = - sqlite3CompareAffinity(p->pEList->a[0].pExpr, pDest->affinity); - r1 = sqlite3GetTempReg(pParse); - sqlite3VdbeAddOp4(v, OP_MakeRecord, pIn->iMem, 1, r1, &p->affinity, 1); - sqlite3ExprCacheAffinityChange(pParse, pIn->iMem, 1); - sqlite3VdbeAddOp2(v, OP_IdxInsert, pDest->iParm, r1); - sqlite3ReleaseTempReg(pParse, r1); - break; - } - -#if 0 /* Never occurs on an ORDER BY query */ - /* If any row exist in the result set, record that fact and abort. - */ - case SRT_Exists: { - sqlite3VdbeAddOp2(v, OP_Integer, 1, pDest->iParm); - /* The LIMIT clause will terminate the loop for us */ - break; - } -#endif - - /* If this is a scalar select that is part of an expression, then - ** store the results in the appropriate memory cell and break out - ** of the scan loop. - */ - case SRT_Mem: { - assert( pIn->nMem==1 ); - sqlite3ExprCodeMove(pParse, pIn->iMem, pDest->iParm, 1); - /* The LIMIT clause will jump out of the loop for us */ - break; - } -#endif /* #ifndef SQLITE_OMIT_SUBQUERY */ - - /* The results are stored in a sequence of registers - ** starting at pDest->iMem. Then the co-routine yields. - */ - case SRT_Coroutine: { - if( pDest->iMem==0 ){ - pDest->iMem = sqlite3GetTempRange(pParse, pIn->nMem); - pDest->nMem = pIn->nMem; - } - sqlite3ExprCodeMove(pParse, pIn->iMem, pDest->iMem, pDest->nMem); - sqlite3VdbeAddOp1(v, OP_Yield, pDest->iParm); - break; - } - - /* Results are stored in a sequence of registers. Then the - ** OP_ResultRow opcode is used to cause sqlite3_step() to return - ** the next row of result. - */ - case SRT_Output: { - sqlite3VdbeAddOp2(v, OP_ResultRow, pIn->iMem, pIn->nMem); - sqlite3ExprCacheAffinityChange(pParse, pIn->iMem, pIn->nMem); - break; - } - -#if !defined(SQLITE_OMIT_TRIGGER) - /* Discard the results. This is used for SELECT statements inside - ** the body of a TRIGGER. The purpose of such selects is to call - ** user-defined functions that have side effects. We do not care - ** about the actual results of the select. - */ - default: { - break; - } -#endif - } - - /* Jump to the end of the loop if the LIMIT is reached. - */ - if( p->iLimit ){ - sqlite3VdbeAddOp2(v, OP_AddImm, p->iLimit, -1); - sqlite3VdbeAddOp2(v, OP_IfZero, p->iLimit, iBreak); - } - - /* Generate the subroutine return - */ - sqlite3VdbeResolveLabel(v, iContinue); - sqlite3VdbeAddOp1(v, OP_Return, regReturn); - - return addr; -} - -/* -** Alternative compound select code generator for cases when there -** is an ORDER BY clause. -** -** We assume a query of the following form: -** -** ORDER BY -** -** is one of UNION ALL, UNION, EXCEPT, or INTERSECT. The idea -** is to code both and with the ORDER BY clause as -** co-routines. Then run the co-routines in parallel and merge the results -** into the output. In addition to the two coroutines (called selectA and -** selectB) there are 7 subroutines: -** -** outA: Move the output of the selectA coroutine into the output -** of the compound query. -** -** outB: Move the output of the selectB coroutine into the output -** of the compound query. (Only generated for UNION and -** UNION ALL. EXCEPT and INSERTSECT never output a row that -** appears only in B.) -** -** AltB: Called when there is data from both coroutines and AB. -** -** EofA: Called when data is exhausted from selectA. -** -** EofB: Called when data is exhausted from selectB. -** -** The implementation of the latter five subroutines depend on which -** is used: -** -** -** UNION ALL UNION EXCEPT INTERSECT -** ------------- ----------------- -------------- ----------------- -** AltB: outA, nextA outA, nextA outA, nextA nextA -** -** AeqB: outA, nextA nextA nextA outA, nextA -** -** AgtB: outB, nextB outB, nextB nextB nextB -** -** EofA: outB, nextB outB, nextB halt halt -** -** EofB: outA, nextA outA, nextA outA, nextA halt -** -** In the AltB, AeqB, and AgtB subroutines, an EOF on A following nextA -** causes an immediate jump to EofA and an EOF on B following nextB causes -** an immediate jump to EofB. Within EofA and EofB, and EOF on entry or -** following nextX causes a jump to the end of the select processing. -** -** Duplicate removal in the UNION, EXCEPT, and INTERSECT cases is handled -** within the output subroutine. The regPrev register set holds the previously -** output value. A comparison is made against this value and the output -** is skipped if the next results would be the same as the previous. -** -** The implementation plan is to implement the two coroutines and seven -** subroutines first, then put the control logic at the bottom. Like this: -** -** goto Init -** coA: coroutine for left query (A) -** coB: coroutine for right query (B) -** outA: output one row of A -** outB: output one row of B (UNION and UNION ALL only) -** EofA: ... -** EofB: ... -** AltB: ... -** AeqB: ... -** AgtB: ... -** Init: initialize coroutine registers -** yield coA -** if eof(A) goto EofA -** yield coB -** if eof(B) goto EofB -** Cmpr: Compare A, B -** Jump AltB, AeqB, AgtB -** End: ... -** -** We call AltB, AeqB, AgtB, EofA, and EofB "subroutines" but they are not -** actually called using Gosub and they do not Return. EofA and EofB loop -** until all data is exhausted then jump to the "end" labe. AltB, AeqB, -** and AgtB jump to either L2 or to one of EofA or EofB. -*/ -#ifndef SQLITE_OMIT_COMPOUND_SELECT -static int multiSelectOrderBy( - Parse *pParse, /* Parsing context */ - Select *p, /* The right-most of SELECTs to be coded */ - SelectDest *pDest /* What to do with query results */ -){ - int i, j; /* Loop counters */ - Select *pPrior; /* Another SELECT immediately to our left */ - Vdbe *v; /* Generate code to this VDBE */ - SelectDest destA; /* Destination for coroutine A */ - SelectDest destB; /* Destination for coroutine B */ - int regAddrA; /* Address register for select-A coroutine */ - int regEofA; /* Flag to indicate when select-A is complete */ - int regAddrB; /* Address register for select-B coroutine */ - int regEofB; /* Flag to indicate when select-B is complete */ - int addrSelectA; /* Address of the select-A coroutine */ - int addrSelectB; /* Address of the select-B coroutine */ - int regOutA; /* Address register for the output-A subroutine */ - int regOutB; /* Address register for the output-B subroutine */ - int addrOutA; /* Address of the output-A subroutine */ - int addrOutB; /* Address of the output-B subroutine */ - int addrEofA; /* Address of the select-A-exhausted subroutine */ - int addrEofB; /* Address of the select-B-exhausted subroutine */ - int addrAltB; /* Address of the AB subroutine */ - int regLimitA; /* Limit register for select-A */ - int regLimitB; /* Limit register for select-A */ - int regPrev; /* A range of registers to hold previous output */ - int savedLimit; /* Saved value of p->iLimit */ - int savedOffset; /* Saved value of p->iOffset */ - int labelCmpr; /* Label for the start of the merge algorithm */ - int labelEnd; /* Label for the end of the overall SELECT stmt */ - int j1; /* Jump instructions that get retargetted */ - int op; /* One of TK_ALL, TK_UNION, TK_EXCEPT, TK_INTERSECT */ - KeyInfo *pKeyDup = 0; /* Comparison information for duplicate removal */ - KeyInfo *pKeyMerge; /* Comparison information for merging rows */ - sqlite3 *db; /* Database connection */ - ExprList *pOrderBy; /* The ORDER BY clause */ - int nOrderBy; /* Number of terms in the ORDER BY clause */ - int *aPermute; /* Mapping from ORDER BY terms to result set columns */ - - assert( p->pOrderBy!=0 ); - assert( pKeyDup==0 ); /* "Managed" code needs this. Ticket #3382. */ - db = pParse->db; - v = pParse->pVdbe; - if( v==0 ) return SQLITE_NOMEM; - labelEnd = sqlite3VdbeMakeLabel(v); - labelCmpr = sqlite3VdbeMakeLabel(v); - - - /* Patch up the ORDER BY clause - */ - op = p->op; - pPrior = p->pPrior; - assert( pPrior->pOrderBy==0 ); - pOrderBy = p->pOrderBy; - assert( pOrderBy ); - nOrderBy = pOrderBy->nExpr; - - /* For operators other than UNION ALL we have to make sure that - ** the ORDER BY clause covers every term of the result set. Add - ** terms to the ORDER BY clause as necessary. - */ - if( op!=TK_ALL ){ - for(i=1; db->mallocFailed==0 && i<=p->pEList->nExpr; i++){ - struct ExprList_item *pItem; - for(j=0, pItem=pOrderBy->a; jiCol>0 ); - if( pItem->iCol==i ) break; - } - if( j==nOrderBy ){ - Expr *pNew = sqlite3PExpr(pParse, TK_INTEGER, 0, 0, 0); - if( pNew==0 ) return SQLITE_NOMEM; - pNew->flags |= EP_IntValue; - pNew->iTable = i; - pOrderBy = sqlite3ExprListAppend(pParse, pOrderBy, pNew, 0); - pOrderBy->a[nOrderBy++].iCol = i; - } - } - } - - /* Compute the comparison permutation and keyinfo that is used with - ** the permutation in order to comparisons to determine if the next - ** row of results comes from selectA or selectB. Also add explicit - ** collations to the ORDER BY clause terms so that when the subqueries - ** to the right and the left are evaluated, they use the correct - ** collation. - */ - aPermute = sqlite3DbMallocRaw(db, sizeof(int)*nOrderBy); - if( aPermute ){ - struct ExprList_item *pItem; - for(i=0, pItem=pOrderBy->a; iiCol>0 && pItem->iCol<=p->pEList->nExpr ); - aPermute[i] = pItem->iCol - 1; - } - pKeyMerge = - sqlite3DbMallocRaw(db, sizeof(*pKeyMerge)+nOrderBy*(sizeof(CollSeq*)+1)); - if( pKeyMerge ){ - pKeyMerge->aSortOrder = (u8*)&pKeyMerge->aColl[nOrderBy]; - pKeyMerge->nField = nOrderBy; - pKeyMerge->enc = ENC(db); - for(i=0; ia[i].pExpr; - if( pTerm->flags & EP_ExpCollate ){ - pColl = pTerm->pColl; - }else{ - pColl = multiSelectCollSeq(pParse, p, aPermute[i]); - pTerm->flags |= EP_ExpCollate; - pTerm->pColl = pColl; - } - pKeyMerge->aColl[i] = pColl; - pKeyMerge->aSortOrder[i] = pOrderBy->a[i].sortOrder; - } - } - }else{ - pKeyMerge = 0; - } - - /* Reattach the ORDER BY clause to the query. - */ - p->pOrderBy = pOrderBy; - pPrior->pOrderBy = sqlite3ExprListDup(pParse->db, pOrderBy); - - /* Allocate a range of temporary registers and the KeyInfo needed - ** for the logic that removes duplicate result rows when the - ** operator is UNION, EXCEPT, or INTERSECT (but not UNION ALL). - */ - if( op==TK_ALL ){ - regPrev = 0; - }else{ - int nExpr = p->pEList->nExpr; - assert( nOrderBy>=nExpr ); - regPrev = sqlite3GetTempRange(pParse, nExpr+1); - sqlite3VdbeAddOp2(v, OP_Integer, 0, regPrev); - pKeyDup = sqlite3DbMallocZero(db, - sizeof(*pKeyDup) + nExpr*(sizeof(CollSeq*)+1) ); - if( pKeyDup ){ - pKeyDup->aSortOrder = (u8*)&pKeyDup->aColl[nExpr]; - pKeyDup->nField = nExpr; - pKeyDup->enc = ENC(db); - for(i=0; iaColl[i] = multiSelectCollSeq(pParse, p, i); - pKeyDup->aSortOrder[i] = 0; - } - } - } - - /* Separate the left and the right query from one another - */ - p->pPrior = 0; - pPrior->pRightmost = 0; - sqlite3ResolveOrderGroupBy(pParse, p, p->pOrderBy, "ORDER"); - if( pPrior->pPrior==0 ){ - sqlite3ResolveOrderGroupBy(pParse, pPrior, pPrior->pOrderBy, "ORDER"); - } - - /* Compute the limit registers */ - computeLimitRegisters(pParse, p, labelEnd); - if( p->iLimit && op==TK_ALL ){ - regLimitA = ++pParse->nMem; - regLimitB = ++pParse->nMem; - sqlite3VdbeAddOp2(v, OP_Copy, p->iOffset ? p->iOffset+1 : p->iLimit, - regLimitA); - sqlite3VdbeAddOp2(v, OP_Copy, regLimitA, regLimitB); - }else{ - regLimitA = regLimitB = 0; - } - sqlite3ExprDelete(db, p->pLimit); - p->pLimit = 0; - sqlite3ExprDelete(db, p->pOffset); - p->pOffset = 0; - - regAddrA = ++pParse->nMem; - regEofA = ++pParse->nMem; - regAddrB = ++pParse->nMem; - regEofB = ++pParse->nMem; - regOutA = ++pParse->nMem; - regOutB = ++pParse->nMem; - sqlite3SelectDestInit(&destA, SRT_Coroutine, regAddrA); - sqlite3SelectDestInit(&destB, SRT_Coroutine, regAddrB); - - /* Jump past the various subroutines and coroutines to the main - ** merge loop - */ - j1 = sqlite3VdbeAddOp0(v, OP_Goto); - addrSelectA = sqlite3VdbeCurrentAddr(v); - - - /* Generate a coroutine to evaluate the SELECT statement to the - ** left of the compound operator - the "A" select. - */ - VdbeNoopComment((v, "Begin coroutine for left SELECT")); - pPrior->iLimit = regLimitA; - sqlite3Select(pParse, pPrior, &destA); - sqlite3VdbeAddOp2(v, OP_Integer, 1, regEofA); - sqlite3VdbeAddOp1(v, OP_Yield, regAddrA); - VdbeNoopComment((v, "End coroutine for left SELECT")); - - /* Generate a coroutine to evaluate the SELECT statement on - ** the right - the "B" select - */ - addrSelectB = sqlite3VdbeCurrentAddr(v); - VdbeNoopComment((v, "Begin coroutine for right SELECT")); - savedLimit = p->iLimit; - savedOffset = p->iOffset; - p->iLimit = regLimitB; - p->iOffset = 0; - sqlite3Select(pParse, p, &destB); - p->iLimit = savedLimit; - p->iOffset = savedOffset; - sqlite3VdbeAddOp2(v, OP_Integer, 1, regEofB); - sqlite3VdbeAddOp1(v, OP_Yield, regAddrB); - VdbeNoopComment((v, "End coroutine for right SELECT")); - - /* Generate a subroutine that outputs the current row of the A - ** select as the next output row of the compound select. - */ - VdbeNoopComment((v, "Output routine for A")); - addrOutA = generateOutputSubroutine(pParse, - p, &destA, pDest, regOutA, - regPrev, pKeyDup, P4_KEYINFO_HANDOFF, labelEnd); - - /* Generate a subroutine that outputs the current row of the B - ** select as the next output row of the compound select. - */ - if( op==TK_ALL || op==TK_UNION ){ - VdbeNoopComment((v, "Output routine for B")); - addrOutB = generateOutputSubroutine(pParse, - p, &destB, pDest, regOutB, - regPrev, pKeyDup, P4_KEYINFO_STATIC, labelEnd); - } - - /* Generate a subroutine to run when the results from select A - ** are exhausted and only data in select B remains. - */ - VdbeNoopComment((v, "eof-A subroutine")); - if( op==TK_EXCEPT || op==TK_INTERSECT ){ - addrEofA = sqlite3VdbeAddOp2(v, OP_Goto, 0, labelEnd); - }else{ - addrEofA = sqlite3VdbeAddOp2(v, OP_If, regEofB, labelEnd); - sqlite3VdbeAddOp2(v, OP_Gosub, regOutB, addrOutB); - sqlite3VdbeAddOp1(v, OP_Yield, regAddrB); - sqlite3VdbeAddOp2(v, OP_Goto, 0, addrEofA); - } - - /* Generate a subroutine to run when the results from select B - ** are exhausted and only data in select A remains. - */ - if( op==TK_INTERSECT ){ - addrEofB = addrEofA; - }else{ - VdbeNoopComment((v, "eof-B subroutine")); - addrEofB = sqlite3VdbeAddOp2(v, OP_If, regEofA, labelEnd); - sqlite3VdbeAddOp2(v, OP_Gosub, regOutA, addrOutA); - sqlite3VdbeAddOp1(v, OP_Yield, regAddrA); - sqlite3VdbeAddOp2(v, OP_Goto, 0, addrEofB); - } - - /* Generate code to handle the case of AB - */ - VdbeNoopComment((v, "A-gt-B subroutine")); - addrAgtB = sqlite3VdbeCurrentAddr(v); - if( op==TK_ALL || op==TK_UNION ){ - sqlite3VdbeAddOp2(v, OP_Gosub, regOutB, addrOutB); - } - sqlite3VdbeAddOp1(v, OP_Yield, regAddrB); - sqlite3VdbeAddOp2(v, OP_If, regEofB, addrEofB); - sqlite3VdbeAddOp2(v, OP_Goto, 0, labelCmpr); - - /* This code runs once to initialize everything. - */ - sqlite3VdbeJumpHere(v, j1); - sqlite3VdbeAddOp2(v, OP_Integer, 0, regEofA); - sqlite3VdbeAddOp2(v, OP_Integer, 0, regEofB); - sqlite3VdbeAddOp2(v, OP_Gosub, regAddrA, addrSelectA); - sqlite3VdbeAddOp2(v, OP_Gosub, regAddrB, addrSelectB); - sqlite3VdbeAddOp2(v, OP_If, regEofA, addrEofA); - sqlite3VdbeAddOp2(v, OP_If, regEofB, addrEofB); - - /* Implement the main merge loop - */ - sqlite3VdbeResolveLabel(v, labelCmpr); - sqlite3VdbeAddOp4(v, OP_Permutation, 0, 0, 0, (char*)aPermute, P4_INTARRAY); - sqlite3VdbeAddOp4(v, OP_Compare, destA.iMem, destB.iMem, nOrderBy, - (char*)pKeyMerge, P4_KEYINFO_HANDOFF); - sqlite3VdbeAddOp3(v, OP_Jump, addrAltB, addrAeqB, addrAgtB); - - /* Release temporary registers - */ - if( regPrev ){ - sqlite3ReleaseTempRange(pParse, regPrev, nOrderBy+1); - } - - /* Jump to the this point in order to terminate the query. - */ - sqlite3VdbeResolveLabel(v, labelEnd); - - /* Set the number of output columns - */ - if( pDest->eDest==SRT_Output ){ - Select *pFirst = pPrior; - while( pFirst->pPrior ) pFirst = pFirst->pPrior; - generateColumnNames(pParse, 0, pFirst->pEList); - } - - /* Reassembly the compound query so that it will be freed correctly - ** by the calling function */ - if( p->pPrior ){ - sqlite3SelectDelete(db, p->pPrior); - } - p->pPrior = pPrior; - - /*** TBD: Insert subroutine calls to close cursors on incomplete - **** subqueries ****/ - return SQLITE_OK; -} -#endif - -#if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) +#ifndef SQLITE_OMIT_VIEW /* Forward Declarations */ static void substExprList(sqlite3*, ExprList*, int, ExprList*); static void substSelect(sqlite3*, Select *, int, ExprList *); @@ -71310,9 +65820,6 @@ static void substSelect( int iTable, /* Table to be replaced */ ExprList *pEList /* Substitute values */ ){ - SrcList *pSrc; - struct SrcList_item *pItem; - int i; if( !p ) return; substExprList(db, p->pEList, iTable, pEList); substExprList(db, p->pGroupBy, iTable, pEList); @@ -71320,16 +65827,10 @@ static void substSelect( substExpr(db, p->pHaving, iTable, pEList); substExpr(db, p->pWhere, iTable, pEList); substSelect(db, p->pPrior, iTable, pEList); - pSrc = p->pSrc; - if( pSrc ){ - for(i=pSrc->nSrc, pItem=pSrc->a; i>0; i--, pItem++){ - substSelect(db, pItem->pSelect, iTable, pEList); - } - } } -#endif /* !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) */ +#endif /* !defined(SQLITE_OMIT_VIEW) */ -#if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) +#ifndef SQLITE_OMIT_VIEW /* ** This routine attempts to flatten subqueries in order to speed ** execution. It returns 1 if it makes changes and 0 if no flattening @@ -71363,8 +65864,8 @@ static void substSelect( ** ** (2) The subquery is not an aggregate or the outer query is not a join. ** -** (3) The subquery is not the right operand of a left outer join -** (Originally ticket #306. Strenghtened by ticket #3300) +** (3) The subquery is not the right operand of a left outer join, or +** the subquery is not itself a join. (Ticket #306) ** ** (4) The subquery is not DISTINCT or the outer query is not a join. ** @@ -71386,8 +65887,8 @@ static void substSelect( ** ** (11) The subquery and the outer query do not both have ORDER BY clauses. ** -** (12) Not implemented. Subsumed into restriction (3). Was previously -** a separate restriction deriving from ticket #350. +** (12) The subquery is not the right term of a LEFT OUTER JOIN or the +** subquery has no WHERE clause. (added by ticket #350) ** ** (13) The subquery and outer query do not both use LIMIT ** @@ -71401,25 +65902,6 @@ static void substSelect( ** not contain ORDER BY. (Ticket #2942) This used to not matter ** until we introduced the group_concat() function. ** -** (17) The sub-query is not a compound select, or it is a UNION ALL -** compound clause made up entirely of non-aggregate queries, and -** the parent query: -** -** * is not itself part of a compound select, -** * is not an aggregate or DISTINCT query, and -** * has no other tables or sub-selects in the FROM clause. -** -** The parent and sub-query may contain WHERE clauses. Subject to -** rules (11), (13) and (14), they may also contain ORDER BY, -** LIMIT and OFFSET clauses. -** -** (18) If the sub-query is a compound select, then all terms of the -** ORDER by clause of the parent must be simple references to -** columns of the sub-query. -** -** (19) The subquery does not use LIMIT or the outer query does not -** have a WHERE clause. -** ** In this routine, the "p" parameter is a pointer to the outer query. ** The subquery is p->pSrc->a[iFrom]. isAgg is true if the outer query ** uses aggregates and subqueryIsAgg is true if the subquery uses aggregates. @@ -71431,16 +65913,13 @@ static void substSelect( ** the subquery before this routine runs. */ static int flattenSubquery( - Parse *pParse, /* Parsing context */ + sqlite3 *db, /* Database connection */ Select *p, /* The parent or outer SELECT statement */ int iFrom, /* Index in p->pSrc->a[] of the inner subquery */ int isAgg, /* True if outer SELECT uses aggregate functions */ int subqueryIsAgg /* True if the subquery uses aggregate functions */ ){ - const char *zSavedAuthContext = pParse->zAuthContext; - Select *pParent; Select *pSub; /* The inner query or "subquery" */ - Select *pSub1; /* Pointer to the rightmost select in sub-query */ SrcList *pSrc; /* The FROM clause of the outer query */ SrcList *pSubSrc; /* The FROM clause of the subquery */ ExprList *pList; /* The result set of the outer query */ @@ -71448,7 +65927,6 @@ static int flattenSubquery( int i; /* Loop counter */ Expr *pWhere; /* The WHERE clause */ struct SrcList_item *pSubitem; /* The subquery */ - sqlite3 *db = pParse->db; /* Check to see if flattening is permitted. Return 0 if not. */ @@ -71456,7 +65934,6 @@ static int flattenSubquery( pSrc = p->pSrc; assert( pSrc && iFrom>=0 && iFromnSrc ); pSubitem = &pSrc->a[iFrom]; - iParent = pSubitem->iCursor; pSub = pSubitem->pSelect; assert( pSub!=0 ); if( isAgg && subqueryIsAgg ) return 0; /* Restriction (1) */ @@ -71474,21 +65951,17 @@ static int flattenSubquery( return 0; /* Restriction (15) */ } if( pSubSrc->nSrc==0 ) return 0; /* Restriction (7) */ - if( ((pSub->selFlags & SF_Distinct)!=0 || pSub->pLimit) + if( (pSub->isDistinct || pSub->pLimit) && (pSrc->nSrc>1 || isAgg) ){ /* Restrictions (4)(5)(8)(9) */ return 0; } - if( (p->selFlags & SF_Distinct)!=0 && subqueryIsAgg ){ - return 0; /* Restriction (6) */ - } - if( p->pOrderBy && pSub->pOrderBy ){ + if( p->isDistinct && subqueryIsAgg ) return 0; /* Restriction (6) */ + if( (p->disallowOrderBy || p->pOrderBy) && pSub->pOrderBy ){ return 0; /* Restriction (11) */ } if( isAgg && pSub->pOrderBy ) return 0; /* Restriction (16) */ - if( pSub->pLimit && p->pWhere ) return 0; /* Restriction (19) */ - /* OBSOLETE COMMENT 1: - ** Restriction 3: If the subquery is a join, make sure the subquery is + /* Restriction 3: If the subquery is a join, make sure the subquery is ** not used as the right operand of an outer join. Examples of why this ** is not allowed: ** @@ -71499,9 +65972,12 @@ static int flattenSubquery( ** (t1 LEFT OUTER JOIN t2) JOIN t3 ** ** which is not at all the same thing. - ** - ** OBSOLETE COMMENT 2: - ** Restriction 12: If the subquery is the right operand of a left outer + */ + if( pSubSrc->nSrc>1 && (pSubitem->jointype & JT_OUTER)!=0 ){ + return 0; + } + + /* Restriction 12: If the subquery is the right operand of a left outer ** join, make sure the subquery has no WHERE clause. ** An examples of why this is not allowed: ** @@ -71513,139 +65989,46 @@ static int flattenSubquery( ** ** But the t2.x>0 test will always fail on a NULL row of t2, which ** effectively converts the OUTER JOIN into an INNER JOIN. - ** - ** THIS OVERRIDES OBSOLETE COMMENTS 1 AND 2 ABOVE: - ** Ticket #3300 shows that flattening the right term of a LEFT JOIN - ** is fraught with danger. Best to avoid the whole thing. If the - ** subquery is the right term of a LEFT JOIN, then do not flatten. */ - if( (pSubitem->jointype & JT_OUTER)!=0 ){ + if( (pSubitem->jointype & JT_OUTER)!=0 && pSub->pWhere!=0 ){ return 0; } - /* Restriction 17: If the sub-query is a compound SELECT, then it must - ** use only the UNION ALL operator. And none of the simple select queries - ** that make up the compound SELECT are allowed to be aggregate or distinct - ** queries. + /* If we reach this point, it means flattening is permitted for the + ** iFrom-th entry of the FROM clause in the outer query. */ - if( pSub->pPrior ){ - if( p->pPrior || isAgg || (p->selFlags & SF_Distinct)!=0 || pSrc->nSrc!=1 ){ - return 0; - } - for(pSub1=pSub; pSub1; pSub1=pSub1->pPrior){ - if( (pSub1->selFlags & (SF_Distinct|SF_Aggregate))!=0 - || (pSub1->pPrior && pSub1->op!=TK_ALL) - || !pSub1->pSrc || pSub1->pSrc->nSrc!=1 - ){ - return 0; - } - } - /* Restriction 18. */ - if( p->pOrderBy ){ - int ii; - for(ii=0; iipOrderBy->nExpr; ii++){ - if( p->pOrderBy->a[ii].iCol==0 ) return 0; - } - } - } - - /***** If we reach this point, flattening is permitted. *****/ - - /* Authorize the subquery */ - pParse->zAuthContext = pSubitem->zName; - sqlite3AuthCheck(pParse, SQLITE_SELECT, 0, 0, 0); - pParse->zAuthContext = zSavedAuthContext; - - /* If the sub-query is a compound SELECT statement, then (by restrictions - ** 17 and 18 above) it must be a UNION ALL and the parent query must - ** be of the form: - ** - ** SELECT FROM () - ** - ** followed by any ORDER BY, LIMIT and/or OFFSET clauses. This block - ** creates N copies of the parent query without any ORDER BY, LIMIT or - ** OFFSET clauses and joins them to the left-hand-side of the original - ** using UNION ALL operators. In this case N is the number of simple - ** select statements in the compound sub-query. + /* Move all of the FROM elements of the subquery into the + ** the FROM clause of the outer query. Before doing this, remember + ** the cursor number for the original outer query FROM element in + ** iParent. The iParent cursor will never be used. Subsequent code + ** will scan expressions looking for iParent references and replace + ** those references with expressions that resolve to the subquery FROM + ** elements we are now copying in. */ - for(pSub=pSub->pPrior; pSub; pSub=pSub->pPrior){ - Select *pNew; - ExprList *pOrderBy = p->pOrderBy; - Expr *pLimit = p->pLimit; - Expr *pOffset = p->pOffset; - Select *pPrior = p->pPrior; - p->pOrderBy = 0; - p->pSrc = 0; - p->pPrior = 0; - p->pLimit = 0; - pNew = sqlite3SelectDup(db, p); - pNew->pPrior = pPrior; - p->pPrior = pNew; - p->pOrderBy = pOrderBy; - p->op = TK_ALL; - p->pSrc = pSrc; - p->pLimit = pLimit; - p->pOffset = pOffset; - p->pRightmost = 0; - pNew->pRightmost = 0; - } - - /* Begin flattening the iFrom-th entry of the FROM clause - ** in the outer query. - */ - pSub = pSub1 = pSubitem->pSelect; - for(pParent=p; pParent; pParent=pParent->pPrior, pSub=pSub->pPrior){ + iParent = pSubitem->iCursor; + { int nSubSrc = pSubSrc->nSrc; - int jointype = 0; - pSubSrc = pSub->pSrc; - pSrc = pParent->pSrc; + int jointype = pSubitem->jointype; - /* Move all of the FROM elements of the subquery into the - ** the FROM clause of the outer query. Before doing this, remember - ** the cursor number for the original outer query FROM element in - ** iParent. The iParent cursor will never be used. Subsequent code - ** will scan expressions looking for iParent references and replace - ** those references with expressions that resolve to the subquery FROM - ** elements we are now copying in. - */ - if( pSrc ){ - Table *pTabToDel; - pSubitem = &pSrc->a[iFrom]; - nSubSrc = pSubSrc->nSrc; - jointype = pSubitem->jointype; - sqlite3DbFree(db, pSubitem->zDatabase); - sqlite3DbFree(db, pSubitem->zName); - sqlite3DbFree(db, pSubitem->zAlias); - pSubitem->zDatabase = 0; - pSubitem->zName = 0; - pSubitem->zAlias = 0; - - /* If the FROM element is a subquery, defer deleting the Table - ** object associated with that subquery until code generation is - ** complete, since there may still exist Expr.pTab entires that - ** refer to the subquery even after flattening. Ticket #3346. - */ - if( (pTabToDel = pSubitem->pTab)!=0 ){ - if( pTabToDel->nRef==1 ){ - pTabToDel->pNextZombie = pParse->pZombieTab; - pParse->pZombieTab = pTabToDel; - }else{ - pTabToDel->nRef--; - } - } - pSubitem->pTab = 0; - } - if( nSubSrc!=1 || !pSrc ){ + sqlite3DeleteTable(pSubitem->pTab); + sqlite3_free(pSubitem->zDatabase); + sqlite3_free(pSubitem->zName); + sqlite3_free(pSubitem->zAlias); + pSubitem->pTab = 0; + pSubitem->zDatabase = 0; + pSubitem->zName = 0; + pSubitem->zAlias = 0; + if( nSubSrc>1 ){ int extra = nSubSrc - 1; - for(i=(pSrc?1:0); ipSrc = 0; + p->pSrc = 0; return 1; } } - pParent->pSrc = pSrc; + p->pSrc = pSrc; for(i=pSrc->nSrc-1; i-extra>=iFrom; i--){ pSrc->a[i] = pSrc->a[i-extra]; } @@ -71655,83 +66038,82 @@ static int flattenSubquery( memset(&pSubSrc->a[i], 0, sizeof(pSubSrc->a[i])); } pSrc->a[iFrom].jointype = jointype; - - /* Now begin substituting subquery result set expressions for - ** references to the iParent in the outer query. - ** - ** Example: - ** - ** SELECT a+5, b*10 FROM (SELECT x*3 AS a, y+10 AS b FROM t1) WHERE a>b; - ** \ \_____________ subquery __________/ / - ** \_____________________ outer query ______________________________/ - ** - ** We look at every expression in the outer query and every place we see - ** "a" we substitute "x*3" and every place we see "b" we substitute "y+10". - */ - pList = pParent->pEList; - for(i=0; inExpr; i++){ - Expr *pExpr; - if( pList->a[i].zName==0 && (pExpr = pList->a[i].pExpr)->span.z!=0 ){ - pList->a[i].zName = - sqlite3DbStrNDup(db, (char*)pExpr->span.z, pExpr->span.n); - } - } - substExprList(db, pParent->pEList, iParent, pSub->pEList); - if( isAgg ){ - substExprList(db, pParent->pGroupBy, iParent, pSub->pEList); - substExpr(db, pParent->pHaving, iParent, pSub->pEList); - } - if( pSub->pOrderBy ){ - assert( pParent->pOrderBy==0 ); - pParent->pOrderBy = pSub->pOrderBy; - pSub->pOrderBy = 0; - }else if( pParent->pOrderBy ){ - substExprList(db, pParent->pOrderBy, iParent, pSub->pEList); - } - if( pSub->pWhere ){ - pWhere = sqlite3ExprDup(db, pSub->pWhere); - }else{ - pWhere = 0; - } - if( subqueryIsAgg ){ - assert( pParent->pHaving==0 ); - pParent->pHaving = pParent->pWhere; - pParent->pWhere = pWhere; - substExpr(db, pParent->pHaving, iParent, pSub->pEList); - pParent->pHaving = sqlite3ExprAnd(db, pParent->pHaving, - sqlite3ExprDup(db, pSub->pHaving)); - assert( pParent->pGroupBy==0 ); - pParent->pGroupBy = sqlite3ExprListDup(db, pSub->pGroupBy); - }else{ - substExpr(db, pParent->pWhere, iParent, pSub->pEList); - pParent->pWhere = sqlite3ExprAnd(db, pParent->pWhere, pWhere); - } - - /* The flattened query is distinct if either the inner or the - ** outer query is distinct. - */ - pParent->selFlags |= pSub->selFlags & SF_Distinct; - - /* - ** SELECT ... FROM (SELECT ... LIMIT a OFFSET b) LIMIT x OFFSET y; - ** - ** One is tempted to try to add a and b to combine the limits. But this - ** does not work if either limit is negative. - */ - if( pSub->pLimit ){ - pParent->pLimit = pSub->pLimit; - pSub->pLimit = 0; + } + + /* Now begin substituting subquery result set expressions for + ** references to the iParent in the outer query. + ** + ** Example: + ** + ** SELECT a+5, b*10 FROM (SELECT x*3 AS a, y+10 AS b FROM t1) WHERE a>b; + ** \ \_____________ subquery __________/ / + ** \_____________________ outer query ______________________________/ + ** + ** We look at every expression in the outer query and every place we see + ** "a" we substitute "x*3" and every place we see "b" we substitute "y+10". + */ + pList = p->pEList; + for(i=0; inExpr; i++){ + Expr *pExpr; + if( pList->a[i].zName==0 && (pExpr = pList->a[i].pExpr)->span.z!=0 ){ + pList->a[i].zName = + sqlite3DbStrNDup(db, (char*)pExpr->span.z, pExpr->span.n); } } + substExprList(db, p->pEList, iParent, pSub->pEList); + if( isAgg ){ + substExprList(db, p->pGroupBy, iParent, pSub->pEList); + substExpr(db, p->pHaving, iParent, pSub->pEList); + } + if( pSub->pOrderBy ){ + assert( p->pOrderBy==0 ); + p->pOrderBy = pSub->pOrderBy; + pSub->pOrderBy = 0; + }else if( p->pOrderBy ){ + substExprList(db, p->pOrderBy, iParent, pSub->pEList); + } + if( pSub->pWhere ){ + pWhere = sqlite3ExprDup(db, pSub->pWhere); + }else{ + pWhere = 0; + } + if( subqueryIsAgg ){ + assert( p->pHaving==0 ); + p->pHaving = p->pWhere; + p->pWhere = pWhere; + substExpr(db, p->pHaving, iParent, pSub->pEList); + p->pHaving = sqlite3ExprAnd(db, p->pHaving, + sqlite3ExprDup(db, pSub->pHaving)); + assert( p->pGroupBy==0 ); + p->pGroupBy = sqlite3ExprListDup(db, pSub->pGroupBy); + }else{ + substExpr(db, p->pWhere, iParent, pSub->pEList); + p->pWhere = sqlite3ExprAnd(db, p->pWhere, pWhere); + } + + /* The flattened query is distinct if either the inner or the + ** outer query is distinct. + */ + p->isDistinct = p->isDistinct || pSub->isDistinct; + + /* + ** SELECT ... FROM (SELECT ... LIMIT a OFFSET b) LIMIT x OFFSET y; + ** + ** One is tempted to try to add a and b to combine the limits. But this + ** does not work if either limit is negative. + */ + if( pSub->pLimit ){ + p->pLimit = pSub->pLimit; + pSub->pLimit = 0; + } /* Finially, delete what is left of the subquery and return ** success. */ - sqlite3SelectDelete(db, pSub1); - + sqlite3SelectDelete(pSub); return 1; } -#endif /* !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) */ +#endif /* SQLITE_OMIT_VIEW */ /* ** Analyze the SELECT statement passed as an argument to see if it @@ -71763,399 +66145,133 @@ static int minMaxQuery(Parse *pParse, Select *p){ } /* -** If the source-list item passed as an argument was augmented with an -** INDEXED BY clause, then try to locate the specified index. If there -** was such a clause and the named index cannot be found, return -** SQLITE_ERROR and leave an error in pParse. Otherwise, populate -** pFrom->pIndex and return SQLITE_OK. +** This routine resolves any names used in the result set of the +** supplied SELECT statement. If the SELECT statement being resolved +** is a sub-select, then pOuterNC is a pointer to the NameContext +** of the parent SELECT. */ -SQLITE_PRIVATE int sqlite3IndexedByLookup(Parse *pParse, struct SrcList_item *pFrom){ - if( pFrom->pTab && pFrom->zIndex ){ - Table *pTab = pFrom->pTab; - char *zIndex = pFrom->zIndex; - Index *pIdx; - for(pIdx=pTab->pIndex; - pIdx && sqlite3StrICmp(pIdx->zName, zIndex); - pIdx=pIdx->pNext - ); - if( !pIdx ){ - sqlite3ErrorMsg(pParse, "no such index: %s", zIndex, 0); - return SQLITE_ERROR; - } - pFrom->pIndex = pIdx; - } - return SQLITE_OK; -} - -/* -** This routine is a Walker callback for "expanding" a SELECT statement. -** "Expanding" means to do the following: -** -** (1) Make sure VDBE cursor numbers have been assigned to every -** element of the FROM clause. -** -** (2) Fill in the pTabList->a[].pTab fields in the SrcList that -** defines FROM clause. When views appear in the FROM clause, -** fill pTabList->a[].pSelect with a copy of the SELECT statement -** that implements the view. A copy is made of the view's SELECT -** statement so that we can freely modify or delete that statement -** without worrying about messing up the presistent representation -** of the view. -** -** (3) Add terms to the WHERE clause to accomodate the NATURAL keyword -** on joins and the ON and USING clause of joins. -** -** (4) Scan the list of columns in the result set (pEList) looking -** for instances of the "*" operator or the TABLE.* operator. -** If found, expand each "*" to be every column in every table -** and TABLE.* to be every column in TABLE. -** -*/ -static int selectExpander(Walker *pWalker, Select *p){ - Parse *pParse = pWalker->pParse; - int i, j, k; - SrcList *pTabList; - ExprList *pEList; - struct SrcList_item *pFrom; - sqlite3 *db = pParse->db; - - if( db->mallocFailed ){ - return WRC_Abort; - } - if( p->pSrc==0 || (p->selFlags & SF_Expanded)!=0 ){ - return WRC_Prune; - } - p->selFlags |= SF_Expanded; - pTabList = p->pSrc; - pEList = p->pEList; - - /* Make sure cursor numbers have been assigned to all entries in - ** the FROM clause of the SELECT statement. - */ - sqlite3SrcListAssignCursors(pParse, pTabList); - - /* Look up every table named in the FROM clause of the select. If - ** an entry of the FROM clause is a subquery instead of a table or view, - ** then create a transient table structure to describe the subquery. - */ - for(i=0, pFrom=pTabList->a; inSrc; i++, pFrom++){ - Table *pTab; - if( pFrom->pTab!=0 ){ - /* This statement has already been prepared. There is no need - ** to go further. */ - assert( i==0 ); - return WRC_Prune; - } - if( pFrom->zName==0 ){ -#ifndef SQLITE_OMIT_SUBQUERY - Select *pSel = pFrom->pSelect; - /* A sub-query in the FROM clause of a SELECT */ - assert( pSel!=0 ); - assert( pFrom->pTab==0 ); - sqlite3WalkSelect(pWalker, pSel); - pFrom->pTab = pTab = sqlite3DbMallocZero(db, sizeof(Table)); - if( pTab==0 ) return WRC_Abort; - pTab->db = db; - pTab->nRef = 1; - pTab->zName = sqlite3MPrintf(db, "sqlite_subquery_%p_", (void*)pTab); - while( pSel->pPrior ){ pSel = pSel->pPrior; } - selectColumnsFromExprList(pParse, pSel->pEList, &pTab->nCol, &pTab->aCol); - pTab->iPKey = -1; - pTab->tabFlags |= TF_Ephemeral; -#endif - }else{ - /* An ordinary table or view name in the FROM clause */ - assert( pFrom->pTab==0 ); - pFrom->pTab = pTab = - sqlite3LocateTable(pParse,0,pFrom->zName,pFrom->zDatabase); - if( pTab==0 ) return WRC_Abort; - pTab->nRef++; -#if !defined(SQLITE_OMIT_VIEW) || !defined (SQLITE_OMIT_VIRTUALTABLE) - if( pTab->pSelect || IsVirtual(pTab) ){ - /* We reach here if the named table is a really a view */ - if( sqlite3ViewGetColumnNames(pParse, pTab) ) return WRC_Abort; - - /* If pFrom->pSelect!=0 it means we are dealing with a - ** view within a view. The SELECT structure has already been - ** copied by the outer view so we can skip the copy step here - ** in the inner view. - */ - if( pFrom->pSelect==0 ){ - pFrom->pSelect = sqlite3SelectDup(db, pTab->pSelect); - sqlite3WalkSelect(pWalker, pFrom->pSelect); - } - } -#endif - } - - /* Locate the index named by the INDEXED BY clause, if any. */ - if( sqlite3IndexedByLookup(pParse, pFrom) ){ - return WRC_Abort; - } - } - - /* Process NATURAL keywords, and ON and USING clauses of joins. - */ - if( db->mallocFailed || sqliteProcessJoin(pParse, p) ){ - return WRC_Abort; - } - - /* For every "*" that occurs in the column list, insert the names of - ** all columns in all tables. And for every TABLE.* insert the names - ** of all columns in TABLE. The parser inserted a special expression - ** with the TK_ALL operator for each "*" that it found in the column list. - ** The following code just has to locate the TK_ALL expressions and expand - ** each one to the list of all columns in all tables. - ** - ** The first loop just checks to see if there are any "*" operators - ** that need expanding. - */ - for(k=0; knExpr; k++){ - Expr *pE = pEList->a[k].pExpr; - if( pE->op==TK_ALL ) break; - if( pE->op==TK_DOT && pE->pRight && pE->pRight->op==TK_ALL - && pE->pLeft && pE->pLeft->op==TK_ID ) break; - } - if( knExpr ){ - /* - ** If we get here it means the result set contains one or more "*" - ** operators that need to be expanded. Loop through each expression - ** in the result set and expand them one by one. - */ - struct ExprList_item *a = pEList->a; - ExprList *pNew = 0; - int flags = pParse->db->flags; - int longNames = (flags & SQLITE_FullColNames)!=0 - && (flags & SQLITE_ShortColNames)==0; - - for(k=0; knExpr; k++){ - Expr *pE = a[k].pExpr; - if( pE->op!=TK_ALL && - (pE->op!=TK_DOT || pE->pRight==0 || pE->pRight->op!=TK_ALL) ){ - /* This particular expression does not need to be expanded. - */ - pNew = sqlite3ExprListAppend(pParse, pNew, a[k].pExpr, 0); - if( pNew ){ - pNew->a[pNew->nExpr-1].zName = a[k].zName; - } - a[k].pExpr = 0; - a[k].zName = 0; - }else{ - /* This expression is a "*" or a "TABLE.*" and needs to be - ** expanded. */ - int tableSeen = 0; /* Set to 1 when TABLE matches */ - char *zTName; /* text of name of TABLE */ - if( pE->op==TK_DOT && pE->pLeft ){ - zTName = sqlite3NameFromToken(db, &pE->pLeft->token); - }else{ - zTName = 0; - } - for(i=0, pFrom=pTabList->a; inSrc; i++, pFrom++){ - Table *pTab = pFrom->pTab; - char *zTabName = pFrom->zAlias; - if( zTabName==0 || zTabName[0]==0 ){ - zTabName = pTab->zName; - } - if( db->mallocFailed ) break; - if( zTName && sqlite3StrICmp(zTName, zTabName)!=0 ){ - continue; - } - tableSeen = 1; - for(j=0; jnCol; j++){ - Expr *pExpr, *pRight; - char *zName = pTab->aCol[j].zName; - - /* If a column is marked as 'hidden' (currently only possible - ** for virtual tables), do not include it in the expanded - ** result-set list. - */ - if( IsHiddenColumn(&pTab->aCol[j]) ){ - assert(IsVirtual(pTab)); - continue; - } - - if( i>0 ){ - struct SrcList_item *pLeft = &pTabList->a[i-1]; - if( (pLeft[1].jointype & JT_NATURAL)!=0 && - columnIndex(pLeft->pTab, zName)>=0 ){ - /* In a NATURAL join, omit the join columns from the - ** table on the right */ - continue; - } - if( sqlite3IdListIndex(pLeft[1].pUsing, zName)>=0 ){ - /* In a join with a USING clause, omit columns in the - ** using clause from the table on the right. */ - continue; - } - } - pRight = sqlite3PExpr(pParse, TK_ID, 0, 0, 0); - if( pRight==0 ) break; - setQuotedToken(pParse, &pRight->token, zName); - if( longNames || pTabList->nSrc>1 ){ - Expr *pLeft = sqlite3PExpr(pParse, TK_ID, 0, 0, 0); - pExpr = sqlite3PExpr(pParse, TK_DOT, pLeft, pRight, 0); - if( pExpr==0 ) break; - setQuotedToken(pParse, &pLeft->token, zTabName); - setToken(&pExpr->span, - sqlite3MPrintf(db, "%s.%s", zTabName, zName)); - pExpr->span.dyn = 1; - pExpr->token.z = 0; - pExpr->token.n = 0; - pExpr->token.dyn = 0; - }else{ - pExpr = pRight; - pExpr->span = pExpr->token; - pExpr->span.dyn = 0; - } - if( longNames ){ - pNew = sqlite3ExprListAppend(pParse, pNew, pExpr, &pExpr->span); - }else{ - pNew = sqlite3ExprListAppend(pParse, pNew, pExpr, &pRight->token); - } - } - } - if( !tableSeen ){ - if( zTName ){ - sqlite3ErrorMsg(pParse, "no such table: %s", zTName); - }else{ - sqlite3ErrorMsg(pParse, "no tables specified"); - } - } - sqlite3DbFree(db, zTName); - } - } - sqlite3ExprListDelete(db, pEList); - p->pEList = pNew; - } -#if SQLITE_MAX_COLUMN - if( p->pEList && p->pEList->nExpr>db->aLimit[SQLITE_LIMIT_COLUMN] ){ - sqlite3ErrorMsg(pParse, "too many columns in result set"); - } -#endif - return WRC_Continue; -} - -/* -** No-op routine for the parse-tree walker. -** -** When this routine is the Walker.xExprCallback then expression trees -** are walked without any actions being taken at each node. Presumably, -** when this routine is used for Walker.xExprCallback then -** Walker.xSelectCallback is set to do something useful for every -** subquery in the parser tree. -*/ -static int exprWalkNoop(Walker *pWalker, Expr *pExpr){ - return WRC_Continue; -} - -/* -** This routine "expands" a SELECT statement and all of its subqueries. -** For additional information on what it means to "expand" a SELECT -** statement, see the comment on the selectExpand worker callback above. -** -** Expanding a SELECT statement is the first step in processing a -** SELECT statement. The SELECT statement must be expanded before -** name resolution is performed. -** -** If anything goes wrong, an error message is written into pParse. -** The calling function can detect the problem by looking at pParse->nErr -** and/or pParse->db->mallocFailed. -*/ -static void sqlite3SelectExpand(Parse *pParse, Select *pSelect){ - Walker w; - w.xSelectCallback = selectExpander; - w.xExprCallback = exprWalkNoop; - w.pParse = pParse; - sqlite3WalkSelect(&w, pSelect); -} - - -#ifndef SQLITE_OMIT_SUBQUERY -/* -** This is a Walker.xSelectCallback callback for the sqlite3SelectTypeInfo() -** interface. -** -** For each FROM-clause subquery, add Column.zType and Column.zColl -** information to the Table structure that represents the result set -** of that subquery. -** -** The Table structure that represents the result set was constructed -** by selectExpander() but the type and collation information was omitted -** at that point because identifiers had not yet been resolved. This -** routine is called after identifier resolution. -*/ -static int selectAddSubqueryTypeInfo(Walker *pWalker, Select *p){ - Parse *pParse; - int i; - SrcList *pTabList; - struct SrcList_item *pFrom; - - assert( p->selFlags & SF_Resolved ); - if( (p->selFlags & SF_HasTypeInfo)==0 ){ - p->selFlags |= SF_HasTypeInfo; - pParse = pWalker->pParse; - pTabList = p->pSrc; - for(i=0, pFrom=pTabList->a; inSrc; i++, pFrom++){ - Table *pTab = pFrom->pTab; - if( pTab && (pTab->tabFlags & TF_Ephemeral)!=0 ){ - /* A sub-query in the FROM clause of a SELECT */ - Select *pSel = pFrom->pSelect; - assert( pSel ); - while( pSel->pPrior ) pSel = pSel->pPrior; - selectAddColumnTypeAndCollation(pParse, pTab->nCol, pTab->aCol, pSel); - } - } - } - return WRC_Continue; -} -#endif - - -/* -** This routine adds datatype and collating sequence information to -** the Table structures of all FROM-clause subqueries in a -** SELECT statement. -** -** Use this routine after name resolution. -*/ -static void sqlite3SelectAddTypeInfo(Parse *pParse, Select *pSelect){ -#ifndef SQLITE_OMIT_SUBQUERY - Walker w; - w.xSelectCallback = selectAddSubqueryTypeInfo; - w.xExprCallback = exprWalkNoop; - w.pParse = pParse; - sqlite3WalkSelect(&w, pSelect); -#endif -} - - -/* -** This routine sets of a SELECT statement for processing. The -** following is accomplished: -** -** * VDBE Cursor numbers are assigned to all FROM-clause terms. -** * Ephemeral Table objects are created for all FROM-clause subqueries. -** * ON and USING clauses are shifted into WHERE statements -** * Wildcards "*" and "TABLE.*" in result sets are expanded. -** * Identifiers in expression are matched to tables. -** -** This routine acts recursively on all subqueries within the SELECT. -*/ -SQLITE_PRIVATE void sqlite3SelectPrep( +SQLITE_PRIVATE int sqlite3SelectResolve( Parse *pParse, /* The parser context */ Select *p, /* The SELECT statement being coded. */ - NameContext *pOuterNC /* Name context for container */ + NameContext *pOuterNC /* The outer name context. May be NULL. */ ){ - sqlite3 *db; - if( p==0 ) return; - db = pParse->db; - if( p->selFlags & SF_HasTypeInfo ) return; - if( pParse->nErr || db->mallocFailed ) return; - sqlite3SelectExpand(pParse, p); - if( pParse->nErr || db->mallocFailed ) return; - sqlite3ResolveSelectNames(pParse, p, pOuterNC); - if( pParse->nErr || db->mallocFailed ) return; - sqlite3SelectAddTypeInfo(pParse, p); + ExprList *pEList; /* Result set. */ + int i; /* For-loop variable used in multiple places */ + NameContext sNC; /* Local name-context */ + ExprList *pGroupBy; /* The group by clause */ + + /* If this routine has run before, return immediately. */ + if( p->isResolved ){ + assert( !pOuterNC ); + return SQLITE_OK; + } + p->isResolved = 1; + + /* If there have already been errors, do nothing. */ + if( pParse->nErr>0 ){ + return SQLITE_ERROR; + } + + /* Prepare the select statement. This call will allocate all cursors + ** required to handle the tables and subqueries in the FROM clause. + */ + if( prepSelectStmt(pParse, p) ){ + return SQLITE_ERROR; + } + + /* Resolve the expressions in the LIMIT and OFFSET clauses. These + ** are not allowed to refer to any names, so pass an empty NameContext. + */ + memset(&sNC, 0, sizeof(sNC)); + sNC.pParse = pParse; + if( sqlite3ExprResolveNames(&sNC, p->pLimit) || + sqlite3ExprResolveNames(&sNC, p->pOffset) ){ + return SQLITE_ERROR; + } + + /* Set up the local name-context to pass to ExprResolveNames() to + ** resolve the expression-list. + */ + sNC.allowAgg = 1; + sNC.pSrcList = p->pSrc; + sNC.pNext = pOuterNC; + + /* Resolve names in the result set. */ + pEList = p->pEList; + if( !pEList ) return SQLITE_ERROR; + for(i=0; inExpr; i++){ + Expr *pX = pEList->a[i].pExpr; + if( sqlite3ExprResolveNames(&sNC, pX) ){ + return SQLITE_ERROR; + } + } + + /* If there are no aggregate functions in the result-set, and no GROUP BY + ** expression, do not allow aggregates in any of the other expressions. + */ + assert( !p->isAgg ); + pGroupBy = p->pGroupBy; + if( pGroupBy || sNC.hasAgg ){ + p->isAgg = 1; + }else{ + sNC.allowAgg = 0; + } + + /* If a HAVING clause is present, then there must be a GROUP BY clause. + */ + if( p->pHaving && !pGroupBy ){ + sqlite3ErrorMsg(pParse, "a GROUP BY clause is required before HAVING"); + return SQLITE_ERROR; + } + + /* Add the expression list to the name-context before parsing the + ** other expressions in the SELECT statement. This is so that + ** expressions in the WHERE clause (etc.) can refer to expressions by + ** aliases in the result set. + ** + ** Minor point: If this is the case, then the expression will be + ** re-evaluated for each reference to it. + */ + sNC.pEList = p->pEList; + if( sqlite3ExprResolveNames(&sNC, p->pWhere) || + sqlite3ExprResolveNames(&sNC, p->pHaving) ){ + return SQLITE_ERROR; + } + if( p->pPrior==0 ){ + if( processOrderGroupBy(pParse, p, p->pOrderBy, 1, &sNC.hasAgg) ){ + return SQLITE_ERROR; + } + } + if( processOrderGroupBy(pParse, p, pGroupBy, 0, &sNC.hasAgg) ){ + return SQLITE_ERROR; + } + + if( pParse->db->mallocFailed ){ + return SQLITE_NOMEM; + } + + /* Make sure the GROUP BY clause does not contain aggregate functions. + */ + if( pGroupBy ){ + struct ExprList_item *pItem; + + for(i=0, pItem=pGroupBy->a; inExpr; i++, pItem++){ + if( ExprHasProperty(pItem->pExpr, EP_Agg) ){ + sqlite3ErrorMsg(pParse, "aggregate functions are not allowed in " + "the GROUP BY clause"); + return SQLITE_ERROR; + } + } + } + + /* If this is one SELECT of a compound, be sure to resolve names + ** in the other SELECTs. + */ + if( p->pPrior ){ + return sqlite3SelectResolve(pParse, p->pPrior, pOuterNC); + }else{ + return SQLITE_OK; + } } /* @@ -72236,11 +66352,11 @@ static void updateAccumulator(Parse *pParse, AggInfo *pAggInfo){ assert( nArg==1 ); codeDistinct(pParse, pF->iDistinct, addrNext, 1, regAgg); } - if( pF->pFunc->flags & SQLITE_FUNC_NEEDCOLL ){ + if( pF->pFunc->needCollSeq ){ CollSeq *pColl = 0; struct ExprList_item *pItem; int j; - assert( pList!=0 ); /* pList!=0 if pF->pFunc has NEEDCOLL */ + assert( pList!=0 ); /* pList!=0 if pF->pFunc->needCollSeq is true */ for(j=0, pItem=pList->a; !pColl && jpExpr); } @@ -72264,8 +66380,35 @@ static void updateAccumulator(Parse *pParse, AggInfo *pAggInfo){ pAggInfo->directMode = 0; } +#if 0 /* -** Generate code for the SELECT statement given in the p argument. +** This function is used when a SELECT statement is used to create a +** temporary table for iterating through when running an INSTEAD OF +** UPDATE or INSTEAD OF DELETE trigger. +** +** If possible, the SELECT statement is modified so that NULL values +** are stored in the temporary table for all columns for which the +** corresponding bit in argument mask is not set. If mask takes the +** special value 0xffffffff, then all columns are populated. +*/ +SQLITE_PRIVATE void sqlite3SelectMask(Parse *pParse, Select *p, u32 mask){ + if( p && !p->pPrior && !p->isDistinct && mask!=0xffffffff ){ + ExprList *pEList; + int i; + sqlite3SelectResolve(pParse, p, 0); + pEList = p->pEList; + for(i=0; pEList && inExpr && i<32; i++){ + if( !(mask&((u32)1<a[i].pExpr); + pEList->a[i].pExpr = sqlite3Expr(pParse->db, TK_NULL, 0, 0, 0); + } + } + } +} +#endif + +/* +** Generate code for the given SELECT statement. ** ** The results are distributed in various ways depending on the ** contents of the SelectDest structure pointed to by argument pDest @@ -72273,43 +66416,34 @@ static void updateAccumulator(Parse *pParse, AggInfo *pAggInfo){ ** ** pDest->eDest Result ** ------------ ------------------------------------------- -** SRT_Output Generate a row of output (using the OP_ResultRow -** opcode) for each row in the result set. +** SRT_Callback Invoke the callback for each row of the result. ** -** SRT_Mem Only valid if the result is a single column. -** Store the first column of the first result row -** in register pDest->iParm then abandon the rest -** of the query. This destination implies "LIMIT 1". +** SRT_Mem Store first result in memory cell pDest->iParm ** -** SRT_Set The result must be a single column. Store each -** row of result as the key in table pDest->iParm. -** Apply the affinity pDest->affinity before storing -** results. Used to implement "IN (SELECT ...)". +** SRT_Set Store non-null results as keys of table pDest->iParm. +** Apply the affinity pDest->affinity before storing them. ** ** SRT_Union Store results as a key in a temporary table pDest->iParm. ** ** SRT_Except Remove results from the temporary table pDest->iParm. ** -** SRT_Table Store results in temporary table pDest->iParm. -** This is like SRT_EphemTab except that the table -** is assumed to already be open. +** SRT_Table Store results in temporary table pDest->iParm ** ** SRT_EphemTab Create an temporary table pDest->iParm and store ** the result there. The cursor is left open after -** returning. This is like SRT_Table except that -** this destination uses OP_OpenEphemeral to create -** the table first. +** returning. ** -** SRT_Coroutine Generate a co-routine that returns a new row of -** results each time it is invoked. The entry point -** of the co-routine is stored in register pDest->iParm. +** SRT_Subroutine For each row returned, push the results onto the +** vdbe stack and call the subroutine (via OP_Gosub) +** at address pDest->iParm. ** ** SRT_Exists Store a 1 in memory cell pDest->iParm if the result ** set is not empty. ** -** SRT_Discard Throw the results away. This is used by SELECT -** statements within triggers whose only purpose is -** the side-effects of functions. +** SRT_Discard Throw the results away. +** +** See the selectInnerLoop() function for a canonical listing of the +** allowed values of eDest and their meanings. ** ** This routine returns the number of errors. If any errors are ** encountered, then an appropriate error message is left in @@ -72317,11 +66451,36 @@ static void updateAccumulator(Parse *pParse, AggInfo *pAggInfo){ ** ** This routine does NOT free the Select structure passed in. The ** calling function needs to do that. +** +** The pParent, parentTab, and *pParentAgg fields are filled in if this +** SELECT is a subquery. This routine may try to combine this SELECT +** with its parent to form a single flat query. In so doing, it might +** change the parent query from a non-aggregate to an aggregate query. +** For that reason, the pParentAgg flag is passed as a pointer, so it +** can be changed. +** +** Example 1: The meaning of the pParent parameter. +** +** SELECT * FROM t1 JOIN (SELECT x, count(*) FROM t2) JOIN t3; +** \ \_______ subquery _______/ / +** \ / +** \____________________ outer query ___________________/ +** +** This routine is called for the outer query first. For that call, +** pParent will be NULL. During the processing of the outer query, this +** routine is called recursively to handle the subquery. For the recursive +** call, pParent will point to the outer query. Because the subquery is +** the second element in a three-way join, the parentTab parameter will +** be 1 (the 2nd value of a 0-indexed array.) */ SQLITE_PRIVATE int sqlite3Select( Parse *pParse, /* The parser context */ Select *p, /* The SELECT statement being coded. */ - SelectDest *pDest /* What to do with the query results */ + SelectDest *pDest, /* What to do with the query results */ + Select *pParent, /* Another SELECT for which this is a sub-query */ + int parentTab, /* Index in pParent->pSrc of this query */ + int *pParentAgg, /* True if pParent uses aggregate functions */ + char *aff /* If eDest is SRT_Union, the affinity string */ ){ int i, j; /* Loop counters */ WhereInfo *pWInfo; /* Return from sqlite3WhereBegin() */ @@ -72357,89 +66516,13 @@ SQLITE_PRIVATE int sqlite3Select( */ assert(pDest->eDest==SRT_Exists || pDest->eDest==SRT_Union || pDest->eDest==SRT_Except || pDest->eDest==SRT_Discard); - p->selFlags &= ~SF_Distinct; + p->isDistinct = 0; } - sqlite3SelectPrep(pParse, p, 0); - if( pParse->nErr ){ + if( sqlite3SelectResolve(pParse, p, 0) ){ goto select_end; } p->pOrderBy = pOrderBy; - - /* Make local copies of the parameters for this query. - */ - pTabList = p->pSrc; - isAgg = (p->selFlags & SF_Aggregate)!=0; - pEList = p->pEList; - if( pEList==0 ) goto select_end; - - /* - ** Do not even attempt to generate any code if we have already seen - ** errors before this routine starts. - */ - if( pParse->nErr>0 ) goto select_end; - - /* ORDER BY is ignored for some destinations. - */ - if( IgnorableOrderby(pDest) ){ - pOrderBy = 0; - } - - /* Begin generating code. - */ - v = sqlite3GetVdbe(pParse); - if( v==0 ) goto select_end; - - /* Generate code for all sub-queries in the FROM clause - */ -#if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) - for(i=0; !p->pPrior && inSrc; i++){ - struct SrcList_item *pItem = &pTabList->a[i]; - SelectDest dest; - Select *pSub = pItem->pSelect; - int isAggSub; - - if( pSub==0 || pItem->isPopulated ) continue; - - /* Increment Parse.nHeight by the height of the largest expression - ** tree refered to by this, the parent select. The child select - ** may contain expression trees of at most - ** (SQLITE_MAX_EXPR_DEPTH-Parse.nHeight) height. This is a bit - ** more conservative than necessary, but much easier than enforcing - ** an exact limit. - */ - pParse->nHeight += sqlite3SelectExprHeight(p); - - /* Check to see if the subquery can be absorbed into the parent. */ - isAggSub = (pSub->selFlags & SF_Aggregate)!=0; - if( flattenSubquery(pParse, p, i, isAgg, isAggSub) ){ - if( isAggSub ){ - isAgg = 1; - p->selFlags |= SF_Aggregate; - } - i = -1; - }else{ - sqlite3SelectDestInit(&dest, SRT_EphemTab, pItem->iCursor); - assert( pItem->isPopulated==0 ); - sqlite3Select(pParse, pSub, &dest); - pItem->isPopulated = 1; - } - if( pParse->nErr || db->mallocFailed ){ - goto select_end; - } - pParse->nHeight -= sqlite3SelectExprHeight(p); - pTabList = p->pSrc; - if( !IgnorableOrderby(pDest) ){ - pOrderBy = p->pOrderBy; - } - } - pEList = p->pEList; -#endif - pWhere = p->pWhere; - pGroupBy = p->pGroupBy; - pHaving = p->pHaving; - isDistinct = (p->selFlags & SF_Distinct)!=0; - #ifndef SQLITE_OMIT_COMPOUND_SELECT /* If there is are a sequence of queries, do the earlier ones first. */ @@ -72459,10 +66542,27 @@ SQLITE_PRIVATE int sqlite3Select( return 1; } } - return multiSelect(pParse, p, pDest); + return multiSelect(pParse, p, pDest, aff); } #endif + /* Make local copies of the parameters for this query. + */ + pTabList = p->pSrc; + pWhere = p->pWhere; + pGroupBy = p->pGroupBy; + pHaving = p->pHaving; + isAgg = p->isAgg; + isDistinct = p->isDistinct; + pEList = p->pEList; + if( pEList==0 ) goto select_end; + + /* + ** Do not even attempt to generate any code if we have already seen + ** errors before this routine starts. + */ + if( pParse->nErr>0 ) goto select_end; + /* If writing to memory or generating a set ** only a single column may be output. */ @@ -72472,13 +66572,80 @@ SQLITE_PRIVATE int sqlite3Select( } #endif - /* If possible, rewrite the query to use GROUP BY instead of DISTINCT. - ** GROUP BY might use an index, DISTINCT never does. + /* ORDER BY is ignored for some destinations. */ - if( (p->selFlags & (SF_Distinct|SF_Aggregate))==SF_Distinct && !p->pGroupBy ){ + if( IgnorableOrderby(pDest) ){ + pOrderBy = 0; + } + + /* Begin generating code. + */ + v = sqlite3GetVdbe(pParse); + if( v==0 ) goto select_end; + + /* Generate code for all sub-queries in the FROM clause + */ +#if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) + for(i=0; inSrc; i++){ + const char *zSavedAuthContext = 0; + int needRestoreContext; + struct SrcList_item *pItem = &pTabList->a[i]; + SelectDest dest; + + if( pItem->pSelect==0 || pItem->isPopulated ) continue; + if( pItem->zName!=0 ){ + zSavedAuthContext = pParse->zAuthContext; + pParse->zAuthContext = pItem->zName; + needRestoreContext = 1; + }else{ + needRestoreContext = 0; + } + /* Increment Parse.nHeight by the height of the largest expression + ** tree refered to by this, the parent select. The child select + ** may contain expression trees of at most + ** (SQLITE_MAX_EXPR_DEPTH-Parse.nHeight) height. This is a bit + ** more conservative than necessary, but much easier than enforcing + ** an exact limit. + */ + pParse->nHeight += sqlite3SelectExprHeight(p); + sqlite3SelectDestInit(&dest, SRT_EphemTab, pItem->iCursor); + sqlite3Select(pParse, pItem->pSelect, &dest, p, i, &isAgg, 0); + if( db->mallocFailed ){ + goto select_end; + } + pParse->nHeight -= sqlite3SelectExprHeight(p); + if( needRestoreContext ){ + pParse->zAuthContext = zSavedAuthContext; + } + pTabList = p->pSrc; + pWhere = p->pWhere; + if( !IgnorableOrderby(pDest) ){ + pOrderBy = p->pOrderBy; + } + pGroupBy = p->pGroupBy; + pHaving = p->pHaving; + isDistinct = p->isDistinct; + } +#endif + + /* Check to see if this is a subquery that can be "flattened" into its parent. + ** If flattening is a possiblity, do so and return immediately. + */ +#ifndef SQLITE_OMIT_VIEW + if( pParent && pParentAgg && + flattenSubquery(db, pParent, parentTab, *pParentAgg, isAgg) ){ + if( isAgg ) *pParentAgg = 1; + goto select_end; + } +#endif + + /* If possible, rewrite the query to use GROUP BY instead of DISTINCT. + ** GROUP BY may use an index, DISTINCT never does. + */ + if( p->isDistinct && !p->isAgg && !p->pGroupBy ){ p->pGroupBy = sqlite3ExprListDup(db, p->pEList); pGroupBy = p->pGroupBy; - p->selFlags &= ~SF_Distinct; + p->isDistinct = 0; isDistinct = 0; } @@ -72546,7 +66713,7 @@ SQLITE_PRIVATE int sqlite3Select( */ assert(!isDistinct); selectInnerLoop(pParse, p, pEList, 0, 0, pOrderBy, -1, pDest, - pWInfo->iContinue, pWInfo->iBreak); + pWInfo->iContinue, pWInfo->iBreak, aff); /* End the database scan loop. */ @@ -72561,25 +66728,20 @@ SQLITE_PRIVATE int sqlite3Select( ** processed */ int iAbortFlag; /* Mem address which causes query abort if positive */ int groupBySort; /* Rows come from source in GROUP BY order */ - int addrEnd; /* End of processing for this SELECT */ - /* Remove any and all aliases between the result set and the - ** GROUP BY clause. - */ - if( pGroupBy ){ - int i; /* Loop counter */ - struct ExprList_item *pItem; /* For looping over expression in a list */ - for(i=p->pEList->nExpr, pItem=p->pEList->a; i>0; i--, pItem++){ - pItem->iAlias = 0; - } - for(i=pGroupBy->nExpr, pItem=pGroupBy->a; i>0; i--, pItem++){ - pItem->iAlias = 0; - } - } + /* The following variables hold addresses or labels for parts of the + ** virtual machine program we are putting together */ + int addrOutputRow; /* Start of subroutine that outputs a result row */ + int addrSetAbort; /* Set the abort flag and return */ + int addrInitializeLoop; /* Start of code that initializes the input loop */ + int addrTopOfLoop; /* Top of the input loop */ + int addrGroupByChange; /* Code that runs when any GROUP BY term changes */ + int addrProcessRow; /* Code to process a single input row */ + int addrEnd; /* End of all processing */ + int addrSortingIdx; /* The OP_OpenEphemeral for the sorting index */ + int addrReset; /* Subroutine for resetting the accumulator */ - - /* Create a label to jump to when we want to abort the query */ addrEnd = sqlite3VdbeMakeLabel(v); /* Convert TK_COLUMN nodes into TK_AGG_COLUMN and make entries in @@ -72608,14 +66770,13 @@ SQLITE_PRIVATE int sqlite3Select( */ if( pGroupBy ){ KeyInfo *pKeyInfo; /* Keying information for the group by clause */ - int j1; /* A-vs-B comparision jump */ - int addrOutputRow; /* Start of subroutine that outputs a result row */ - int regOutputRow; /* Return address register for output subroutine */ - int addrSetAbort; /* Set the abort flag and return */ - int addrTopOfLoop; /* Top of the input loop */ - int addrSortingIdx; /* The OP_OpenEphemeral for the sorting index */ - int addrReset; /* Subroutine for resetting the accumulator */ - int regReset; /* Return address register for reset subroutine */ + + /* Create labels that we will be needing + */ + + addrInitializeLoop = sqlite3VdbeMakeLabel(v); + addrGroupByChange = sqlite3VdbeMakeLabel(v); + addrProcessRow = sqlite3VdbeMakeLabel(v); /* If there is a GROUP BY clause we might need a sorting index to ** implement it. Allocate that sorting index now. If it turns out @@ -72632,10 +66793,6 @@ SQLITE_PRIVATE int sqlite3Select( */ iUseFlag = ++pParse->nMem; iAbortFlag = ++pParse->nMem; - regOutputRow = ++pParse->nMem; - addrOutputRow = sqlite3VdbeMakeLabel(v); - regReset = ++pParse->nMem; - addrReset = sqlite3VdbeMakeLabel(v); iAMem = pParse->nMem + 1; pParse->nMem += pGroupBy->nExpr; iBMem = pParse->nMem + 1; @@ -72644,13 +66801,46 @@ SQLITE_PRIVATE int sqlite3Select( VdbeComment((v, "clear abort flag")); sqlite3VdbeAddOp2(v, OP_Integer, 0, iUseFlag); VdbeComment((v, "indicate accumulator empty")); + sqlite3VdbeAddOp2(v, OP_Goto, 0, addrInitializeLoop); + + /* Generate a subroutine that outputs a single row of the result + ** set. This subroutine first looks at the iUseFlag. If iUseFlag + ** is less than or equal to zero, the subroutine is a no-op. If + ** the processing calls for the query to abort, this subroutine + ** increments the iAbortFlag memory location before returning in + ** order to signal the caller to abort. + */ + addrSetAbort = sqlite3VdbeCurrentAddr(v); + sqlite3VdbeAddOp2(v, OP_Integer, 1, iAbortFlag); + VdbeComment((v, "set abort flag")); + sqlite3VdbeAddOp2(v, OP_Return, 0, 0); + addrOutputRow = sqlite3VdbeCurrentAddr(v); + sqlite3VdbeAddOp2(v, OP_IfPos, iUseFlag, addrOutputRow+2); + VdbeComment((v, "Groupby result generator entry point")); + sqlite3VdbeAddOp2(v, OP_Return, 0, 0); + finalizeAggFunctions(pParse, &sAggInfo); + if( pHaving ){ + sqlite3ExprIfFalse(pParse, pHaving, addrOutputRow+1, SQLITE_JUMPIFNULL); + } + selectInnerLoop(pParse, p, p->pEList, 0, 0, pOrderBy, + distinct, pDest, + addrOutputRow+1, addrSetAbort, aff); + sqlite3VdbeAddOp2(v, OP_Return, 0, 0); + VdbeComment((v, "end groupby result generator")); + + /* Generate a subroutine that will reset the group-by accumulator + */ + addrReset = sqlite3VdbeCurrentAddr(v); + resetAccumulator(pParse, &sAggInfo); + sqlite3VdbeAddOp2(v, OP_Return, 0, 0); /* Begin a loop that will extract all source rows in GROUP BY order. ** This might involve two separate loops with an OP_Sort in between, or ** it might be a single loop that uses an index to extract information ** in the right order to begin with. */ - sqlite3VdbeAddOp2(v, OP_Gosub, regReset, addrReset); + sqlite3VdbeResolveLabel(v, addrInitializeLoop); + sqlite3VdbeAddOp2(v, OP_Gosub, 0, addrReset); pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, &pGroupBy, 0); if( pWInfo==0 ) goto select_end; if( pGroupBy==0 ){ @@ -72689,9 +66879,7 @@ SQLITE_PRIVATE int sqlite3Select( struct AggInfo_col *pCol = &sAggInfo.aCol[i]; if( pCol->iSorterColumn>=j ){ int r1 = j + regBase; - int r2; - - r2 = sqlite3ExprCodeGetColumn(pParse, + int r2 = sqlite3ExprCodeGetColumn(pParse, pCol->pTab, pCol->iColumn, pCol->iTable, r1, 0); if( r1!=r2 ){ sqlite3VdbeAddOp2(v, OP_SCopy, r2, r1); @@ -72724,13 +66912,18 @@ SQLITE_PRIVATE int sqlite3Select( sqlite3ExprCode(pParse, pGroupBy->a[j].pExpr, iBMem+j); } } - sqlite3VdbeAddOp4(v, OP_Compare, iAMem, iBMem, pGroupBy->nExpr, - (char*)pKeyInfo, P4_KEYINFO); - j1 = sqlite3VdbeCurrentAddr(v); - sqlite3VdbeAddOp3(v, OP_Jump, j1+1, 0, j1+1); + for(j=pGroupBy->nExpr-1; j>=0; j--){ + if( j==0 ){ + sqlite3VdbeAddOp3(v, OP_Eq, iAMem+j, addrProcessRow, iBMem+j); + }else{ + sqlite3VdbeAddOp3(v, OP_Ne, iAMem+j, addrGroupByChange, iBMem+j); + } + sqlite3VdbeChangeP4(v, -1, (void*)pKeyInfo->aColl[j], P4_COLLSEQ); + sqlite3VdbeChangeP5(v, SQLITE_NULLEQUAL); + } /* Generate code that runs whenever the GROUP BY changes. - ** Changes in the GROUP BY are detected by the previous code + ** Change in the GROUP BY are detected by the previous code ** block. If there were no changes, this block is skipped. ** ** This code copies current group by terms in b0,b1,b2,... @@ -72738,18 +66931,21 @@ SQLITE_PRIVATE int sqlite3Select( ** and resets the aggregate accumulator registers in preparation ** for the next GROUP BY batch. */ - sqlite3ExprCodeMove(pParse, iBMem, iAMem, pGroupBy->nExpr); - sqlite3VdbeAddOp2(v, OP_Gosub, regOutputRow, addrOutputRow); + sqlite3VdbeResolveLabel(v, addrGroupByChange); + for(j=0; jnExpr; j++){ + sqlite3ExprCodeMove(pParse, iBMem+j, iAMem+j); + } + sqlite3VdbeAddOp2(v, OP_Gosub, 0, addrOutputRow); VdbeComment((v, "output one row")); sqlite3VdbeAddOp2(v, OP_IfPos, iAbortFlag, addrEnd); VdbeComment((v, "check abort flag")); - sqlite3VdbeAddOp2(v, OP_Gosub, regReset, addrReset); + sqlite3VdbeAddOp2(v, OP_Gosub, 0, addrReset); VdbeComment((v, "reset accumulator")); /* Update the aggregate accumulators based on the content of ** the current row */ - sqlite3VdbeJumpHere(v, j1); + sqlite3VdbeResolveLabel(v, addrProcessRow); updateAccumulator(pParse, &sAggInfo); sqlite3VdbeAddOp2(v, OP_Integer, 1, iUseFlag); VdbeComment((v, "indicate data in accumulator")); @@ -72765,45 +66961,9 @@ SQLITE_PRIVATE int sqlite3Select( /* Output the final row of result */ - sqlite3VdbeAddOp2(v, OP_Gosub, regOutputRow, addrOutputRow); + sqlite3VdbeAddOp2(v, OP_Gosub, 0, addrOutputRow); VdbeComment((v, "output final row")); - - /* Jump over the subroutines - */ - sqlite3VdbeAddOp2(v, OP_Goto, 0, addrEnd); - - /* Generate a subroutine that outputs a single row of the result - ** set. This subroutine first looks at the iUseFlag. If iUseFlag - ** is less than or equal to zero, the subroutine is a no-op. If - ** the processing calls for the query to abort, this subroutine - ** increments the iAbortFlag memory location before returning in - ** order to signal the caller to abort. - */ - addrSetAbort = sqlite3VdbeCurrentAddr(v); - sqlite3VdbeAddOp2(v, OP_Integer, 1, iAbortFlag); - VdbeComment((v, "set abort flag")); - sqlite3VdbeAddOp1(v, OP_Return, regOutputRow); - sqlite3VdbeResolveLabel(v, addrOutputRow); - addrOutputRow = sqlite3VdbeCurrentAddr(v); - sqlite3VdbeAddOp2(v, OP_IfPos, iUseFlag, addrOutputRow+2); - VdbeComment((v, "Groupby result generator entry point")); - sqlite3VdbeAddOp1(v, OP_Return, regOutputRow); - finalizeAggFunctions(pParse, &sAggInfo); - if( pHaving ){ - sqlite3ExprIfFalse(pParse, pHaving, addrOutputRow+1, SQLITE_JUMPIFNULL); - } - selectInnerLoop(pParse, p, p->pEList, 0, 0, pOrderBy, - distinct, pDest, - addrOutputRow+1, addrSetAbort); - sqlite3VdbeAddOp1(v, OP_Return, regOutputRow); - VdbeComment((v, "end groupby result generator")); - - /* Generate a subroutine that will reset the group-by accumulator - */ - sqlite3VdbeResolveLabel(v, addrReset); - resetAccumulator(pParse, &sAggInfo); - sqlite3VdbeAddOp1(v, OP_Return, regReset); - + } /* endif pGroupBy */ else { ExprList *pMinMax = 0; @@ -72839,7 +66999,7 @@ SQLITE_PRIVATE int sqlite3Select( if( flag ){ pDel = pMinMax = sqlite3ExprListDup(db, p->pEList->a[0].pExpr->pList); if( pMinMax && !db->mallocFailed ){ - pMinMax->a[0].sortOrder = flag!=WHERE_ORDERBY_MIN; + pMinMax->a[0].sortOrder = ((flag==WHERE_ORDERBY_MIN)?0:1); pMinMax->a[0].pExpr->op = TK_COLUMN; } } @@ -72851,13 +67011,13 @@ SQLITE_PRIVATE int sqlite3Select( resetAccumulator(pParse, &sAggInfo); pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, &pMinMax, flag); if( pWInfo==0 ){ - sqlite3ExprListDelete(db, pDel); + sqlite3ExprListDelete(pDel); goto select_end; } updateAccumulator(pParse, &sAggInfo); if( !pMinMax && flag ){ sqlite3VdbeAddOp2(v, OP_Goto, 0, pWInfo->iBreak); - VdbeComment((v, "%s() by index",(flag==WHERE_ORDERBY_MIN?"min":"max"))); + VdbeComment((v, "%s() by index", (flag==WHERE_ORDERBY_MIN?"min":"max"))); } sqlite3WhereEnd(pWInfo); finalizeAggFunctions(pParse, &sAggInfo); @@ -72866,9 +67026,9 @@ SQLITE_PRIVATE int sqlite3Select( sqlite3ExprIfFalse(pParse, pHaving, addrEnd, SQLITE_JUMPIFNULL); } selectInnerLoop(pParse, p, p->pEList, 0, 0, 0, -1, - pDest, addrEnd, addrEnd); + pDest, addrEnd, addrEnd, aff); - sqlite3ExprListDelete(db, pDel); + sqlite3ExprListDelete(pDel); } sqlite3VdbeResolveLabel(v, addrEnd); @@ -72881,6 +67041,19 @@ SQLITE_PRIVATE int sqlite3Select( generateSortTail(pParse, p, v, pEList->nExpr, pDest); } +#ifndef SQLITE_OMIT_SUBQUERY + /* If this was a subquery, we have now converted the subquery into a + ** temporary table. So set the SrcList_item.isPopulated flag to prevent + ** this subquery from being evaluated again and to force the use of + ** the temporary table. + */ + if( pParent ){ + assert( pParent->pSrc->nSrc>parentTab ); + assert( pParent->pSrc->a[parentTab].pSelect==p ); + pParent->pSrc->a[parentTab].isPopulated = 1; + } +#endif + /* Jump here to skip this query */ sqlite3VdbeResolveLabel(v, iEnd); @@ -72895,14 +67068,15 @@ SQLITE_PRIVATE int sqlite3Select( */ select_end: - /* Identify column names if results of the SELECT are to be output. + /* Identify column names if we will be using them in a callback. This + ** step is skipped if the output is going to some other destination. */ - if( rc==SQLITE_OK && pDest->eDest==SRT_Output ){ + if( rc==SQLITE_OK && pDest->eDest==SRT_Callback ){ generateColumnNames(pParse, pTabList, pEList); } - sqlite3DbFree(db, sAggInfo.aCol); - sqlite3DbFree(db, sAggInfo.aFunc); + sqlite3_free(sAggInfo.aCol); + sqlite3_free(sAggInfo.aFunc); return rc; } @@ -73021,8 +67195,6 @@ SQLITE_PRIVATE void sqlite3PrintSelect(Select *p, int indent){ ** ** These routines are in a separate files so that they will not be linked ** if they are not used. -** -** $Id: table.c,v 1.36 2008/07/08 22:28:49 shane Exp $ */ #ifndef SQLITE_OMIT_GET_TABLE @@ -73150,7 +67322,7 @@ SQLITE_API int sqlite3_get_table( res.azResult[0] = 0; rc = sqlite3_exec(db, zSql, sqlite3_get_table_cb, &res, pzErrMsg); assert( sizeof(res.azResult[0])>= sizeof(res.nData) ); - res.azResult[0] = SQLITE_INT_TO_PTR(res.nData); + res.azResult[0] = (char*)res.nData; if( (rc&0xff)==SQLITE_ABORT ){ sqlite3_free_table(&res.azResult[1]); if( res.zErrMsg ){ @@ -73195,7 +67367,7 @@ SQLITE_API void sqlite3_free_table( int i, n; azResult--; assert( azResult!=0 ); - n = SQLITE_PTR_TO_INT(azResult[0]); + n = (int)azResult[0]; for(i=1; ipNext; - if( pTmp->target.dyn ) sqlite3DbFree(db, (char*)pTmp->target.z); - sqlite3ExprDelete(db, pTmp->pWhere); - sqlite3ExprListDelete(db, pTmp->pExprList); - sqlite3SelectDelete(db, pTmp->pSelect); - sqlite3IdListDelete(db, pTmp->pIdList); + if( pTmp->target.dyn ) sqlite3_free((char*)pTmp->target.z); + sqlite3ExprDelete(pTmp->pWhere); + sqlite3ExprListDelete(pTmp->pExprList); + sqlite3SelectDelete(pTmp->pSelect); + sqlite3IdListDelete(pTmp->pIdList); - sqlite3DbFree(db, pTmp); + sqlite3_free(pTmp); } } @@ -73392,12 +67562,12 @@ SQLITE_PRIVATE void sqlite3BeginTrigger( pParse->pNewTrigger = pTrigger; trigger_cleanup: - sqlite3DbFree(db, zName); - sqlite3SrcListDelete(db, pTableName); - sqlite3IdListDelete(db, pColumns); - sqlite3ExprDelete(db, pWhen); + sqlite3_free(zName); + sqlite3SrcListDelete(pTableName); + sqlite3IdListDelete(pColumns); + sqlite3ExprDelete(pWhen); if( !pParse->pNewTrigger ){ - sqlite3DeleteTrigger(db, pTrigger); + sqlite3DeleteTrigger(pTrigger); }else{ assert( pParse->pNewTrigger==pTrigger ); } @@ -73447,7 +67617,7 @@ SQLITE_PRIVATE void sqlite3FinishTrigger( "INSERT INTO %Q.%s VALUES('trigger',%Q,%Q,0,'CREATE TRIGGER %q')", db->aDb[iDb].zName, SCHEMA_TABLE(iDb), pTrig->name, pTrig->table, z); - sqlite3DbFree(db, z); + sqlite3_free(z); sqlite3ChangeCookie(pParse, iDb); sqlite3VdbeAddOp4(v, OP_ParseSchema, iDb, 0, 0, sqlite3MPrintf( db, "type='trigger' AND name='%q'", pTrig->name), P4_DYNAMIC @@ -73474,9 +67644,9 @@ SQLITE_PRIVATE void sqlite3FinishTrigger( } triggerfinish_cleanup: - sqlite3DeleteTrigger(db, pTrig); + sqlite3DeleteTrigger(pTrig); assert( !pParse->pNewTrigger ); - sqlite3DeleteTriggerStep(db, pStepList); + sqlite3DeleteTriggerStep(pStepList); } /* @@ -73496,22 +67666,22 @@ static void sqlitePersistTriggerStep(sqlite3 *db, TriggerStep *p){ } if( p->pSelect ){ Select *pNew = sqlite3SelectDup(db, p->pSelect); - sqlite3SelectDelete(db, p->pSelect); + sqlite3SelectDelete(p->pSelect); p->pSelect = pNew; } if( p->pWhere ){ Expr *pNew = sqlite3ExprDup(db, p->pWhere); - sqlite3ExprDelete(db, p->pWhere); + sqlite3ExprDelete(p->pWhere); p->pWhere = pNew; } if( p->pExprList ){ ExprList *pNew = sqlite3ExprListDup(db, p->pExprList); - sqlite3ExprListDelete(db, p->pExprList); + sqlite3ExprListDelete(p->pExprList); p->pExprList = pNew; } if( p->pIdList ){ IdList *pNew = sqlite3IdListDup(db, p->pIdList); - sqlite3IdListDelete(db, p->pIdList); + sqlite3IdListDelete(p->pIdList); p->pIdList = pNew; } } @@ -73526,7 +67696,7 @@ static void sqlitePersistTriggerStep(sqlite3 *db, TriggerStep *p){ SQLITE_PRIVATE TriggerStep *sqlite3TriggerSelectStep(sqlite3 *db, Select *pSelect){ TriggerStep *pTriggerStep = sqlite3DbMallocZero(db, sizeof(TriggerStep)); if( pTriggerStep==0 ) { - sqlite3SelectDelete(db, pSelect); + sqlite3SelectDelete(pSelect); return 0; } @@ -73568,9 +67738,9 @@ SQLITE_PRIVATE TriggerStep *sqlite3TriggerInsertStep( pTriggerStep->orconf = orconf; sqlitePersistTriggerStep(db, pTriggerStep); }else{ - sqlite3IdListDelete(db, pColumn); - sqlite3ExprListDelete(db, pEList); - sqlite3SelectDelete(db, pSelect); + sqlite3IdListDelete(pColumn); + sqlite3ExprListDelete(pEList); + sqlite3SelectDelete(pSelect); } return pTriggerStep; @@ -73590,8 +67760,8 @@ SQLITE_PRIVATE TriggerStep *sqlite3TriggerUpdateStep( ){ TriggerStep *pTriggerStep = sqlite3DbMallocZero(db, sizeof(TriggerStep)); if( pTriggerStep==0 ){ - sqlite3ExprListDelete(db, pEList); - sqlite3ExprDelete(db, pWhere); + sqlite3ExprListDelete(pEList); + sqlite3ExprDelete(pWhere); return 0; } @@ -73617,7 +67787,7 @@ SQLITE_PRIVATE TriggerStep *sqlite3TriggerDeleteStep( ){ TriggerStep *pTriggerStep = sqlite3DbMallocZero(db, sizeof(TriggerStep)); if( pTriggerStep==0 ){ - sqlite3ExprDelete(db, pWhere); + sqlite3ExprDelete(pWhere); return 0; } @@ -73633,15 +67803,15 @@ SQLITE_PRIVATE TriggerStep *sqlite3TriggerDeleteStep( /* ** Recursively delete a Trigger structure */ -SQLITE_PRIVATE void sqlite3DeleteTrigger(sqlite3 *db, Trigger *pTrigger){ +SQLITE_PRIVATE void sqlite3DeleteTrigger(Trigger *pTrigger){ if( pTrigger==0 ) return; - sqlite3DeleteTriggerStep(db, pTrigger->step_list); - sqlite3DbFree(db, pTrigger->name); - sqlite3DbFree(db, pTrigger->table); - sqlite3ExprDelete(db, pTrigger->pWhen); - sqlite3IdListDelete(db, pTrigger->pColumns); - if( pTrigger->nameToken.dyn ) sqlite3DbFree(db, (char*)pTrigger->nameToken.z); - sqlite3DbFree(db, pTrigger); + sqlite3DeleteTriggerStep(pTrigger->step_list); + sqlite3_free(pTrigger->name); + sqlite3_free(pTrigger->table); + sqlite3ExprDelete(pTrigger->pWhen); + sqlite3IdListDelete(pTrigger->pColumns); + if( pTrigger->nameToken.dyn ) sqlite3_free((char*)pTrigger->nameToken.z); + sqlite3_free(pTrigger); } /* @@ -73684,7 +67854,7 @@ SQLITE_PRIVATE void sqlite3DropTrigger(Parse *pParse, SrcList *pName, int noErr) sqlite3DropTriggerPtr(pParse, pTrigger); drop_trigger_cleanup: - sqlite3SrcListDelete(db, pName); + sqlite3SrcListDelete(pName); } /* @@ -73776,7 +67946,7 @@ SQLITE_PRIVATE void sqlite3UnlinkAndDeleteTrigger(sqlite3 *db, int iDb, const ch } assert(cc); } - sqlite3DeleteTrigger(db, pTrigger); + sqlite3DeleteTrigger(pTrigger); db->flags |= SQLITE_InternChanges; } } @@ -73885,8 +68055,9 @@ static int codeTriggerProgram( SelectDest dest; sqlite3SelectDestInit(&dest, SRT_Discard, 0); - sqlite3Select(pParse, ss, &dest); - sqlite3SelectDelete(db, ss); + sqlite3SelectResolve(pParse, ss, 0); + sqlite3Select(pParse, ss, &dest, 0, 0, 0, 0); + sqlite3SelectDelete(ss); } break; } @@ -74034,13 +68205,13 @@ SQLITE_PRIVATE int sqlite3CodeRowTrigger( /* code the WHEN clause */ endTrigger = sqlite3VdbeMakeLabel(pParse->pVdbe); whenExpr = sqlite3ExprDup(db, p->pWhen); - if( db->mallocFailed || sqlite3ResolveExprNames(&sNC, whenExpr) ){ + if( db->mallocFailed || sqlite3ExprResolveNames(&sNC, whenExpr) ){ pParse->trigStack = trigStackEntry.pNext; - sqlite3ExprDelete(db, whenExpr); + sqlite3ExprDelete(whenExpr); return 1; } sqlite3ExprIfFalse(pParse, whenExpr, endTrigger, SQLITE_JUMPIFNULL); - sqlite3ExprDelete(db, whenExpr); + sqlite3ExprDelete(whenExpr); codeTriggerProgram(pParse, p->step_list, orconf); @@ -74073,7 +68244,7 @@ SQLITE_PRIVATE int sqlite3CodeRowTrigger( ** This file contains C code routines that are called by the parser ** to handle UPDATE statements. ** -** $Id: update.c,v 1.185 2008/10/09 18:48:31 danielk1977 Exp $ +** $Id: update.c,v 1.178 2008/04/28 18:46:43 drh Exp $ */ #ifndef SQLITE_OMIT_VIRTUALTABLE @@ -74254,7 +68425,7 @@ SQLITE_PRIVATE void sqlite3Update( */ chngRowid = 0; for(i=0; inExpr; i++){ - if( sqlite3ResolveExprNames(&sNC, pChanges->a[i].pExpr) ){ + if( sqlite3ExprResolveNames(&sNC, pChanges->a[i].pExpr) ){ goto update_cleanup; } for(j=0; jnCol; j++){ @@ -74388,16 +68559,14 @@ SQLITE_PRIVATE void sqlite3Update( /* If we are trying to update a view, realize that view into ** a ephemeral table. */ -#if !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER) if( isView ){ - sqlite3MaterializeView(pParse, pTab, pWhere, iCur); + sqlite3MaterializeView(pParse, pTab->pSelect, pWhere, iCur); } -#endif /* Resolve the column names in all the expressions in the ** WHERE clause. */ - if( sqlite3ResolveExprNames(&sNC, pWhere) ){ + if( sqlite3ExprResolveNames(&sNC, pWhere) ){ goto update_cleanup; } @@ -74493,7 +68662,6 @@ SQLITE_PRIVATE void sqlite3Update( */ if( chngRowid ){ sqlite3ExprCodeAndCache(pParse, pRowidExpr, regRowid); - sqlite3VdbeAddOp1(v, OP_MustBeInt, regRowid); }else{ sqlite3VdbeAddOp2(v, OP_Rowid, iCur, regRowid); } @@ -74521,7 +68689,7 @@ SQLITE_PRIVATE void sqlite3Update( sqlite3ExprCacheAffinityChange(pParse, regCols, pTab->nCol); } sqlite3ReleaseTempRange(pParse, regCols, pTab->nCol); - /* if( pParse->nErr ) goto update_cleanup; */ + if( pParse->nErr ) goto update_cleanup; sqlite3VdbeAddOp3(v, OP_Insert, newIdx, regRow, regRowid); sqlite3ReleaseTempReg(pParse, regRowid); sqlite3ReleaseTempReg(pParse, regRow); @@ -74633,11 +68801,11 @@ SQLITE_PRIVATE void sqlite3Update( update_cleanup: sqlite3AuthContextPop(&sContext); - sqlite3DbFree(db, aRegIdx); - sqlite3DbFree(db, aXRef); - sqlite3SrcListDelete(db, pTabList); - sqlite3ExprListDelete(db, pChanges); - sqlite3ExprDelete(db, pWhere); + sqlite3_free(aRegIdx); + sqlite3_free(aXRef); + sqlite3SrcListDelete(pTabList); + sqlite3ExprListDelete(pChanges); + sqlite3ExprDelete(pWhere); return; } @@ -74712,7 +68880,7 @@ static void updateVirtualTable( /* fill the ephemeral table */ sqlite3SelectDestInit(&dest, SRT_Table, ephemTab); - sqlite3Select(pParse, pSelect, &dest); + sqlite3Select(pParse, pSelect, &dest, 0, 0, 0, 0); /* Generate code to scan the ephemeral table and call VUpdate. */ iReg = ++pParse->nMem; @@ -74731,7 +68899,7 @@ static void updateVirtualTable( sqlite3VdbeAddOp2(v, OP_Close, ephemTab, 0); /* Cleanup */ - sqlite3SelectDelete(db, pSelect); + sqlite3SelectDelete(pSelect); } #endif /* SQLITE_OMIT_VIRTUALTABLE */ @@ -74758,7 +68926,7 @@ static void updateVirtualTable( ** Most of the code in this file may be omitted by defining the ** SQLITE_OMIT_VACUUM macro. ** -** $Id: vacuum.c,v 1.83 2008/08/26 21:07:27 drh Exp $ +** $Id: vacuum.c,v 1.78 2008/04/30 16:38:23 drh Exp $ */ #if !defined(SQLITE_OMIT_VACUUM) && !defined(SQLITE_OMIT_ATTACH) @@ -74823,30 +68991,23 @@ SQLITE_PRIVATE void sqlite3Vacuum(Parse *pParse){ SQLITE_PRIVATE int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){ int rc = SQLITE_OK; /* Return code from service routines */ Btree *pMain; /* The database being vacuumed */ - Pager *pMainPager; /* Pager for database being vacuumed */ Btree *pTemp; /* The temporary database we vacuum into */ char *zSql = 0; /* SQL statements */ int saved_flags; /* Saved value of the db->flags */ - int saved_nChange; /* Saved value of db->nChange */ - int saved_nTotalChange; /* Saved value of db->nTotalChange */ Db *pDb = 0; /* Database to detach at end of vacuum */ - int isMemDb; /* True is vacuuming a :memory: database */ int nRes; /* Save the current value of the write-schema flag before setting it. */ saved_flags = db->flags; - saved_nChange = db->nChange; - saved_nTotalChange = db->nTotalChange; db->flags |= SQLITE_WriteSchema | SQLITE_IgnoreChecks; if( !db->autoCommit ){ - sqlite3SetString(pzErrMsg, db, "cannot VACUUM from within a transaction"); + sqlite3SetString(pzErrMsg, "cannot VACUUM from within a transaction", + (char*)0); rc = SQLITE_ERROR; goto end_of_vacuum; } pMain = db->aDb[0].pBt; - pMainPager = sqlite3BtreePager(pMain); - isMemDb = sqlite3PagerFile(pMainPager)->pMethods==0; /* Attach the temporary database as 'vacuum_db'. The synchronous pragma ** can be set to 'off' for this file, as it is not recovered if a crash @@ -74870,20 +69031,8 @@ SQLITE_PRIVATE int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){ pTemp = db->aDb[db->nDb-1].pBt; nRes = sqlite3BtreeGetReserve(pMain); - - /* A VACUUM cannot change the pagesize of an encrypted database. */ -#ifdef SQLITE_HAS_CODEC - if( db->nextPagesize ){ - extern void sqlite3CodecGetKey(sqlite3*, int, void**, int*); - int nKey; - char *zKey; - sqlite3CodecGetKey(db, 0, (void**)&zKey, &nKey); - if( nKey ) db->nextPagesize = 0; - } -#endif - if( sqlite3BtreeSetPageSize(pTemp, sqlite3BtreeGetPageSize(pMain), nRes) - || (!isMemDb && sqlite3BtreeSetPageSize(pTemp, db->nextPagesize, nRes)) + || sqlite3BtreeSetPageSize(pTemp, db->nextPagesize, nRes) || db->mallocFailed ){ rc = SQLITE_NOMEM; @@ -75004,9 +69153,6 @@ SQLITE_PRIVATE int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){ if( rc!=SQLITE_OK ) goto end_of_vacuum; rc = sqlite3BtreeCommit(pTemp); if( rc!=SQLITE_OK ) goto end_of_vacuum; -#ifndef SQLITE_OMIT_AUTOVACUUM - sqlite3BtreeSetAutoVacuum(pMain, sqlite3BtreeGetAutoVacuum(pTemp)); -#endif rc = sqlite3BtreeCommit(pMain); } @@ -75017,8 +69163,6 @@ SQLITE_PRIVATE int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){ end_of_vacuum: /* Restore the original value of db->flags */ db->flags = saved_flags; - db->nChange = saved_nChange; - db->nTotalChange = saved_nTotalChange; /* Currently there is an SQL level transaction open on the vacuum ** database. No locks are held on any other files (since the main file @@ -75056,7 +69200,7 @@ end_of_vacuum: ************************************************************************* ** This file contains code used to help implement virtual tables. ** -** $Id: vtab.c,v 1.76 2008/08/20 16:35:10 drh Exp $ +** $Id: vtab.c,v 1.69 2008/05/05 13:23:04 drh Exp $ */ #ifndef SQLITE_OMIT_VIRTUALTABLE @@ -75074,21 +69218,17 @@ static int createModule( nName = strlen(zName); pMod = (Module *)sqlite3DbMallocRaw(db, sizeof(Module) + nName + 1); if( pMod ){ - Module *pDel; char *zCopy = (char *)(&pMod[1]); memcpy(zCopy, zName, nName+1); pMod->zName = zCopy; pMod->pModule = pModule; pMod->pAux = pAux; pMod->xDestroy = xDestroy; - pDel = (Module *)sqlite3HashInsert(&db->aModule, zCopy, nName, (void*)pMod); - if( pDel && pDel->xDestroy ){ - pDel->xDestroy(pDel->pAux); - } - sqlite3DbFree(db, pDel); - if( pDel==pMod ){ - db->mallocFailed = 1; + pMod = (Module *)sqlite3HashInsert(&db->aModule, zCopy, nName, (void*)pMod); + if( pMod && pMod->xDestroy ){ + pMod->xDestroy(pMod->pAux); } + sqlite3_free(pMod); sqlite3ResetInternalSchema(db, 0); } rc = sqlite3ApiExit(db, SQLITE_OK); @@ -75160,18 +69300,17 @@ SQLITE_PRIVATE void sqlite3VtabUnlock(sqlite3 *db, sqlite3_vtab *pVtab){ */ SQLITE_PRIVATE void sqlite3VtabClear(Table *p){ sqlite3_vtab *pVtab = p->pVtab; - sqlite3 *db = p->db; if( pVtab ){ assert( p->pMod && p->pMod->pModule ); - sqlite3VtabUnlock(db, pVtab); + sqlite3VtabUnlock(p->pSchema->db, pVtab); p->pVtab = 0; } if( p->azModuleArg ){ int i; for(i=0; inModuleArg; i++){ - sqlite3DbFree(db, p->azModuleArg[i]); + sqlite3_free(p->azModuleArg[i]); } - sqlite3DbFree(db, p->azModuleArg); + sqlite3_free(p->azModuleArg); } } @@ -75189,10 +69328,10 @@ static void addModuleArgument(sqlite3 *db, Table *pTable, char *zArg){ if( azModuleArg==0 ){ int j; for(j=0; jazModuleArg[j]); + sqlite3_free(pTable->azModuleArg[j]); } - sqlite3DbFree(db, zArg); - sqlite3DbFree(db, pTable->azModuleArg); + sqlite3_free(zArg); + sqlite3_free(pTable->azModuleArg); pTable->nModuleArg = 0; }else{ azModuleArg[i] = zArg; @@ -75230,7 +69369,7 @@ SQLITE_PRIVATE void sqlite3VtabBeginParse( iDb = sqlite3SchemaToIndex(db, pTable->pSchema); assert( iDb>=0 ); - pTable->tabFlags |= TF_Virtual; + pTable->isVirtual = 1; pTable->nModuleArg = 0; addModuleArgument(db, pTable, sqlite3NameFromToken(db, pModuleName)); addModuleArgument(db, pTable, sqlite3DbStrDup(db, db->aDb[iDb].zName)); @@ -75323,7 +69462,7 @@ SQLITE_PRIVATE void sqlite3VtabFinishParse(Parse *pParse, Token *pEnd){ zStmt, pParse->regRowid ); - sqlite3DbFree(db, zStmt); + sqlite3_free(zStmt); v = sqlite3GetVdbe(pParse); sqlite3ChangeCookie(pParse, iDb); @@ -75422,7 +69561,7 @@ static int vtabCallConstructor( *pzErr = sqlite3MPrintf(db, "vtable constructor failed: %s", zModuleName); }else { *pzErr = sqlite3MPrintf(db, "%s", zErr); - sqlite3DbFree(db, zErr); + sqlite3_free(zErr); } }else if( db->pVTab ){ const char *zFormat = "vtable constructor did not declare schema: %s"; @@ -75433,7 +69572,7 @@ static int vtabCallConstructor( rc = rc2; } db->pVTab = 0; - sqlite3DbFree(db, zModuleName); + sqlite3_free(zModuleName); /* If everything went according to plan, loop through the columns ** of the table to see if any of them contain the token "hidden". @@ -75486,7 +69625,7 @@ SQLITE_PRIVATE int sqlite3VtabCallConnect(Parse *pParse, Table *pTab){ Module *pMod; int rc = SQLITE_OK; - if( !pTab || (pTab->tabFlags & TF_Virtual)==0 || pTab->pVtab ){ + if( !pTab || !pTab->isVirtual || pTab->pVtab ){ return SQLITE_OK; } @@ -75502,7 +69641,7 @@ SQLITE_PRIVATE int sqlite3VtabCallConnect(Parse *pParse, Table *pTab){ if( rc!=SQLITE_OK ){ sqlite3ErrorMsg(pParse, "%s", zErr); } - sqlite3DbFree(db, zErr); + sqlite3_free(zErr); } return rc; @@ -75538,7 +69677,7 @@ static int addToVTrans(sqlite3 *db, sqlite3_vtab *pVtab){ ** ** If an error occurs, *pzErr is set to point an an English language ** description of the error and an SQLITE_XXX error code is returned. -** In this case the caller must call sqlite3DbFree(db, ) on *pzErr. +** In this case the caller must call sqlite3_free() on *pzErr. */ SQLITE_PRIVATE int sqlite3VtabCallCreate(sqlite3 *db, int iDb, const char *zTab, char **pzErr){ int rc = SQLITE_OK; @@ -75547,7 +69686,7 @@ SQLITE_PRIVATE int sqlite3VtabCallCreate(sqlite3 *db, int iDb, const char *zTab, const char *zModule; pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zName); - assert(pTab && (pTab->tabFlags & TF_Virtual)!=0 && !pTab->pVtab); + assert(pTab && pTab->isVirtual && !pTab->pVtab); pMod = pTab->pMod; zModule = pTab->azModuleArg[0]; @@ -75588,7 +69727,7 @@ SQLITE_API int sqlite3_declare_vtab(sqlite3 *db, const char *zCreateTable){ sqlite3_mutex_leave(db->mutex); return SQLITE_MISUSE; } - assert((pTab->tabFlags & TF_Virtual)!=0 && pTab->nCol==0 && pTab->aCol==0); + assert(pTab->isVirtual && pTab->nCol==0 && pTab->aCol==0); memset(&sParse, 0, sizeof(Parse)); sParse.declareVtab = 1; @@ -75598,7 +69737,7 @@ SQLITE_API int sqlite3_declare_vtab(sqlite3 *db, const char *zCreateTable){ SQLITE_OK == sqlite3RunParser(&sParse, zCreateTable, &zErr) && sParse.pNewTable && !sParse.pNewTable->pSelect && - (sParse.pNewTable->tabFlags & TF_Virtual)==0 + !sParse.pNewTable->isVirtual ){ pTab->aCol = sParse.pNewTable->aCol; pTab->nCol = sParse.pNewTable->nCol; @@ -75607,7 +69746,7 @@ SQLITE_API int sqlite3_declare_vtab(sqlite3 *db, const char *zCreateTable){ db->pVTab = 0; } else { sqlite3Error(db, SQLITE_ERROR, zErr); - sqlite3DbFree(db, zErr); + sqlite3_free(zErr); rc = SQLITE_ERROR; } sParse.declareVtab = 0; @@ -75677,25 +69816,24 @@ static void callFinaliser(sqlite3 *db, int offset){ if( x ) x(pVtab); sqlite3VtabUnlock(db, pVtab); } - sqlite3DbFree(db, db->aVTrans); + sqlite3_free(db->aVTrans); db->nVTrans = 0; db->aVTrans = 0; } } /* -** Invoke the xSync method of all virtual tables in the sqlite3.aVTrans -** array. Return the error code for the first error that occurs, or -** SQLITE_OK if all xSync operations are successful. -** -** Set *pzErrmsg to point to a buffer that should be released using -** sqlite3DbFree() containing an error message, if one is available. +** If argument rc2 is not SQLITE_OK, then return it and do nothing. +** Otherwise, invoke the xSync method of all virtual tables in the +** sqlite3.aVTrans array. Return the error code for the first error +** that occurs, or SQLITE_OK if all xSync operations are successful. */ -SQLITE_PRIVATE int sqlite3VtabSync(sqlite3 *db, char **pzErrmsg){ +SQLITE_PRIVATE int sqlite3VtabSync(sqlite3 *db, int rc2){ int i; int rc = SQLITE_OK; int rcsafety; sqlite3_vtab **aVTrans = db->aVTrans; + if( rc2!=SQLITE_OK ) return rc2; rc = sqlite3SafetyOff(db); db->aVTrans = 0; @@ -75705,9 +69843,6 @@ SQLITE_PRIVATE int sqlite3VtabSync(sqlite3 *db, char **pzErrmsg){ x = pVtab->pModule->xSync; if( x ){ rc = x(pVtab); - sqlite3DbFree(db, *pzErrmsg); - *pzErrmsg = pVtab->zErrMsg; - pVtab->zErrMsg = 0; } } db->aVTrans = aVTrans; @@ -75775,9 +69910,11 @@ SQLITE_PRIVATE int sqlite3VtabBegin(sqlite3 *db, sqlite3_vtab *pVtab){ /* Invoke the xBegin method */ rc = pModule->xBegin(pVtab); - if( rc==SQLITE_OK ){ - rc = addToVTrans(db, pVtab); + if( rc!=SQLITE_OK ){ + return rc; } + + rc = addToVTrans(db, pVtab); } return rc; } @@ -75817,7 +69954,7 @@ SQLITE_PRIVATE FuncDef *sqlite3VtabOverloadFunction( if( pExpr->op!=TK_COLUMN ) return pDef; pTab = pExpr->pTab; if( pTab==0 ) return pDef; - if( (pTab->tabFlags & TF_Virtual)==0 ) return pDef; + if( !pTab->isVirtual ) return pDef; pVtab = pTab->pVtab; assert( pVtab!=0 ); assert( pVtab->pModule!=0 ); @@ -75833,12 +69970,7 @@ SQLITE_PRIVATE FuncDef *sqlite3VtabOverloadFunction( *z = sqlite3UpperToLower[*z]; } rc = pMod->xFindFunction(pVtab, nArg, zLowerName, &xFunc, &pArg); - sqlite3DbFree(db, zLowerName); - if( pVtab->zErrMsg ){ - sqlite3Error(db, rc, "%s", pVtab->zErrMsg); - sqlite3DbFree(db, pVtab->zErrMsg); - pVtab->zErrMsg = 0; - } + sqlite3_free(zLowerName); } if( rc==0 ){ return pDef; @@ -75851,7 +69983,6 @@ SQLITE_PRIVATE FuncDef *sqlite3VtabOverloadFunction( return pDef; } *pNew = *pDef; - pNew->zName = (char *)&pNew[1]; memcpy(pNew->zName, pDef->zName, strlen(pDef->zName)+1); pNew->xFunc = xFunc; pNew->pUserData = pArg; @@ -75896,13 +70027,13 @@ SQLITE_PRIVATE void sqlite3VtabMakeWritable(Parse *pParse, Table *pTab){ ** ************************************************************************* ** This module contains C code that generates VDBE code used to process -** the WHERE clause of SQL statements. This module is responsible for +** the WHERE clause of SQL statements. This module is reponsible for ** generating the code that loops through a table looking for applicable ** rows. Indices are selected and used to speed the search when doing ** so is applicable. Because this module is responsible for selecting ** indices, you might also think of this module as the "query optimizer". ** -** $Id: where.c,v 1.326 2008/10/11 16:47:36 drh Exp $ +** $Id: where.c,v 1.302 2008/04/19 14:40:44 drh Exp $ */ /* @@ -75915,8 +70046,6 @@ SQLITE_PRIVATE void sqlite3VtabMakeWritable(Parse *pParse, Table *pTab){ */ #if defined(SQLITE_TEST) || defined(SQLITE_DEBUG) SQLITE_PRIVATE int sqlite3WhereTrace = 0; -#endif -#if 0 # define WHERETRACE(X) if(sqlite3WhereTrace) sqlite3DebugPrintf X #else # define WHERETRACE(X) @@ -75977,7 +70106,7 @@ struct WhereTerm { /* ** Allowed values of WhereTerm.flags */ -#define TERM_DYNAMIC 0x01 /* Need to call sqlite3ExprDelete(db, pExpr) */ +#define TERM_DYNAMIC 0x01 /* Need to call sqlite3ExprDelete(pExpr) */ #define TERM_VIRTUAL 0x02 /* Added by the optimizer. Do not code */ #define TERM_CODED 0x04 /* This term is already coded */ #define TERM_COPIED 0x08 /* Has a child */ @@ -76088,14 +70217,13 @@ static void whereClauseInit( static void whereClauseClear(WhereClause *pWC){ int i; WhereTerm *a; - sqlite3 *db = pWC->pParse->db; for(i=pWC->nTerm-1, a=pWC->a; i>=0; i--, a++){ if( a->flags & TERM_DYNAMIC ){ - sqlite3ExprDelete(db, a->pExpr); + sqlite3ExprDelete(a->pExpr); } } if( pWC->a!=pWC->aStatic ){ - sqlite3DbFree(db, pWC->a); + sqlite3_free(pWC->a); } } @@ -76107,7 +70235,7 @@ static void whereClauseClear(WhereClause *pWC){ ** for freeing the expression p is assumed by the WhereClause object. ** ** WARNING: This routine might reallocate the space used to store -** WhereTerms. All pointers to WhereTerms should be invalidated after +** WhereTerms. All pointers to WhereTerms should be invalided after ** calling this routine. Such pointers may be reinitialized by referencing ** the pWC->a[] array. */ @@ -76116,18 +70244,18 @@ static int whereClauseInsert(WhereClause *pWC, Expr *p, int flags){ int idx; if( pWC->nTerm>=pWC->nSlot ){ WhereTerm *pOld = pWC->a; - sqlite3 *db = pWC->pParse->db; - pWC->a = sqlite3DbMallocRaw(db, sizeof(pWC->a[0])*pWC->nSlot*2 ); + pWC->a = sqlite3_malloc( sizeof(pWC->a[0])*pWC->nSlot*2 ); if( pWC->a==0 ){ + pWC->pParse->db->mallocFailed = 1; if( flags & TERM_DYNAMIC ){ - sqlite3ExprDelete(db, p); + sqlite3ExprDelete(p); } pWC->a = pOld; return 0; } memcpy(pWC->a, pOld, sizeof(pWC->a[0])*pWC->nTerm); if( pOld!=pWC->aStatic ){ - sqlite3DbFree(db, pOld); + sqlite3_free(pOld); } pWC->nSlot *= 2; } @@ -76205,9 +70333,9 @@ static void createMask(ExprMaskSet *pMaskSet, int iCursor){ ** tree. ** ** In order for this routine to work, the calling function must have -** previously invoked sqlite3ResolveExprNames() on the expression. See +** previously invoked sqlite3ExprResolveNames() on the expression. See ** the header comment on that routine for additional information. -** The sqlite3ResolveExprNames() routines looks for column names and +** The sqlite3ExprResolveNames() routines looks for column names and ** sets their opcodes to TK_COLUMN and their Expr.iTable fields to ** the VDBE cursor number of the table. This routine just has to ** translate the cursor numbers into bitmask values and OR all @@ -76270,7 +70398,7 @@ static int allowedOp(int op){ #define SWAP(TYPE,A,B) {TYPE t=A; A=B; B=t;} /* -** Commute a comparison operator. Expressions of the form "X op Y" +** Commute a comparision operator. Expressions of the form "X op Y" ** are converted into "Y op X". ** ** If a collation sequence is associated with either the left or right @@ -76281,12 +70409,10 @@ static int allowedOp(int op){ ** attached to the right. For the same reason the EP_ExpCollate flag ** is not commuted. */ -static void exprCommute(Parse *pParse, Expr *pExpr){ +static void exprCommute(Expr *pExpr){ u16 expRight = (pExpr->pRight->flags & EP_ExpCollate); u16 expLeft = (pExpr->pLeft->flags & EP_ExpCollate); assert( allowedOp(pExpr->op) && pExpr->op!=TK_IN ); - pExpr->pRight->pColl = sqlite3ExprCollSeq(pParse, pExpr->pRight); - pExpr->pLeft->pColl = sqlite3ExprCollSeq(pParse, pExpr->pLeft); SWAP(CollSeq*,pExpr->pRight->pColl,pExpr->pLeft->pColl); pExpr->pRight->flags = (pExpr->pRight->flags & ~EP_ExpCollate) | expLeft; pExpr->pLeft->flags = (pExpr->pLeft->flags & ~EP_ExpCollate) | expRight; @@ -76340,14 +70466,13 @@ static WhereTerm *findTerm( ){ WhereTerm *pTerm; int k; - assert( iCur>=0 ); for(pTerm=pWC->a, k=pWC->nTerm; k; k--, pTerm++){ if( pTerm->leftCursor==iCur && (pTerm->prereqRight & notReady)==0 && pTerm->leftColumn==iColumn && (pTerm->eOperator & op)!=0 ){ - if( pIdx && pTerm->eOperator!=WO_ISNULL ){ + if( iCur>=0 && pIdx && pTerm->eOperator!=WO_ISNULL ){ Expr *pX = pTerm->pExpr; CollSeq *pColl; char idxaff; @@ -76367,9 +70492,8 @@ static WhereTerm *findTerm( pColl = pParse->db->pDfltColl; } - for(j=0; pIdx->aiColumn[j]!=iColumn; j++){ - if( NEVER(j>=pIdx->nColumn) ) return 0; - } + for(j=0; jnColumn && pIdx->aiColumn[j]!=iColumn; j++){} + assert( jnColumn ); if( sqlite3StrICmp(pColl->zName, pIdx->azColl[j]) ) continue; } return pTerm; @@ -76406,7 +70530,7 @@ static void exprAnalyzeAll( ** literal that does not begin with a wildcard. */ static int isLikeOrGlob( - Parse *pParse, /* Parsing and code generating context */ + sqlite3 *db, /* The database */ Expr *pExpr, /* Test this expression */ int *pnPattern, /* Number of non-wildcard prefix characters */ int *pisComplete, /* True if the only wildcard is % in the last character */ @@ -76418,7 +70542,6 @@ static int isLikeOrGlob( int c, cnt; char wc[3]; CollSeq *pColl; - sqlite3 *db = pParse->db; if( !sqlite3IsLikeFunction(db, pExpr, pnoCase, wc) ){ return 0; @@ -76436,7 +70559,7 @@ static int isLikeOrGlob( if( pLeft->op!=TK_COLUMN ){ return 0; } - pColl = sqlite3ExprCollSeq(pParse, pLeft); + pColl = pLeft->pColl; assert( pColl!=0 || pLeft->iColumn==-1 ); if( pColl==0 ){ /* No collation is defined for the ROWID. Use the default. */ @@ -76514,7 +70637,7 @@ static void transferJoinMarkings(Expr *pDerived, Expr *pBase){ ** a= OR a= OR b= OR ... ** ** The pOrTerm input to this routine corresponds to a single term of -** this OR clause. In order for the term to be a candidate for +** this OR clause. In order for the term to be a condidate for ** conversion to an IN operator, the following must be true: ** ** * The left-hand side of the term must be the column which @@ -76569,7 +70692,7 @@ static int orTermIsOptCandidate(WhereTerm *pOrTerm, int iCursor, int iColumn){ ** This routine merely checks to see if pOrTerm has a duplicate that ** might qualify. If there is a duplicate that has not yet been ** disqualified, then return true. If there are no duplicates, or -** the duplicate has also been disqualified, return false. +** the duplicate has also been disqualifed, return false. */ static int orTermHasOkDuplicate(WhereClause *pOr, WhereTerm *pOrTerm){ if( pOrTerm->flags & TERM_COPIED ){ @@ -76662,7 +70785,7 @@ static void exprAnalyze( int idxNew; pDup = sqlite3ExprDup(db, pExpr); if( db->mallocFailed ){ - sqlite3ExprDelete(db, pDup); + sqlite3ExprDelete(pDup); return; } idxNew = whereClauseInsert(pWC, pDup, TERM_VIRTUAL|TERM_DYNAMIC); @@ -76676,7 +70799,7 @@ static void exprAnalyze( pDup = pExpr; pNew = pTerm; } - exprCommute(pParse, pDup); + exprCommute(pDup); pLeft = pDup->pLeft; pNew->leftCursor = pLeft->iTable; pNew->leftColumn = pLeft->iColumn; @@ -76759,7 +70882,7 @@ static void exprAnalyze( ExprList *pList = 0; Expr *pNew, *pDup; Expr *pLeft = 0; - for(i=sOr.nTerm-1, pOrTerm=sOr.a; i>=0; i--, pOrTerm++){ + for(i=sOr.nTerm-1, pOrTerm=sOr.a; i>=0 && ok; i--, pOrTerm++){ if( (pOrTerm->flags & TERM_OR_OK)==0 ) continue; pDup = sqlite3ExprDup(db, pOrTerm->pExpr->pRight); pList = sqlite3ExprListAppend(pWC->pParse, pList, pDup, 0); @@ -76778,7 +70901,7 @@ static void exprAnalyze( pWC->a[idxNew].iParent = idxTerm; pTerm->nChild = 1; }else{ - sqlite3ExprListDelete(db, pList); + sqlite3ExprListDelete(pList); } } or_not_possible: @@ -76795,9 +70918,10 @@ or_not_possible: ** x>='abc' AND x<'abd' AND x LIKE 'abc%' ** ** The last character of the prefix "abc" is incremented to form the - ** termination condition "abd". + ** termination condidtion "abd". This trick of incrementing the last + ** is not 255 and if the character set is not EBCDIC. */ - if( isLikeOrGlob(pParse, pExpr, &nPattern, &isComplete, &noCase) ){ + if( isLikeOrGlob(db, pExpr, &nPattern, &isComplete, &noCase) ){ Expr *pLeft, *pRight; Expr *pStr1, *pStr2; Expr *pNewExpr1, *pNewExpr2; @@ -76817,10 +70941,7 @@ or_not_possible: assert( pStr2->token.dyn ); pC = (u8*)&pStr2->token.z[nPattern-1]; c = *pC; - if( noCase ){ - if( c=='@' ) isComplete = 0; - c = sqlite3UpperToLower[c]; - } + if( noCase ) c = sqlite3UpperToLower[c]; *pC = c + 1; } pNewExpr1 = sqlite3PExpr(pParse, TK_GE, sqlite3ExprDup(db,pLeft), pStr1, 0); @@ -76982,9 +71103,6 @@ static int isSortingIndex( ** ORDER BY term, that is OK. Just ignore that column of the index */ continue; - }else if( i==pIdx->nColumn ){ - /* Index column i is the rowid. All other terms match. */ - break; }else{ /* If an index column fails to match and is not constrained by == ** then the index cannot satisfy the ORDER BY constraint. @@ -77062,7 +71180,7 @@ static int sortableByRowid( /* ** Prepare a crude estimate of the logarithm of the input value. ** The results need not be exact. This is only used for estimating -** the total cost of performing operations with O(logN) or O(NlogN) +** the total cost of performing operatings with O(logN) or O(NlogN) ** complexity. Because N is just a guess, it is no great tragedy if ** logN is a little off. */ @@ -77147,7 +71265,6 @@ static double bestVirtualIndex( sqlite3_index_info **ppIdxInfo /* Index information passed to xBestIndex */ ){ Table *pTab = pSrc->pTab; - sqlite3_vtab *pVtab = pTab->pVtab; sqlite3_index_info *pIdxInfo; struct sqlite3_index_constraint *pIdxCons; struct sqlite3_index_orderby *pIdxOrderBy; @@ -77171,7 +71288,7 @@ static double bestVirtualIndex( ** to this virtual table */ for(i=nTerm=0, pTerm=pWC->a; inTerm; i++, pTerm++){ if( pTerm->leftCursor != pSrc->iCursor ) continue; - assert( (pTerm->eOperator&(pTerm->eOperator-1))==0 ); + if( (pTerm->eOperator&(pTerm->eOperator-1))==0 ); testcase( pTerm->eOperator==WO_IN ); testcase( pTerm->eOperator==WO_ISNULL ); if( pTerm->eOperator & (WO_IN|WO_ISNULL) ) continue; @@ -77221,7 +71338,7 @@ static double bestVirtualIndex( for(i=j=0, pTerm=pWC->a; inTerm; i++, pTerm++){ if( pTerm->leftCursor != pSrc->iCursor ) continue; - assert( (pTerm->eOperator&(pTerm->eOperator-1))==0 ); + if( (pTerm->eOperator&(pTerm->eOperator-1))==0 ); testcase( pTerm->eOperator==WO_IN ); testcase( pTerm->eOperator==WO_ISNULL ); if( pTerm->eOperator & (WO_IN|WO_ISNULL) ) continue; @@ -77259,7 +71376,7 @@ static double bestVirtualIndex( ** sqlite3ViewGetColumnNames() would have picked up the error. */ assert( pTab->azModuleArg && pTab->azModuleArg[0] ); - assert( pVtab ); + assert( pTab->pVtab ); #if 0 if( pTab->pVtab==0 ){ sqlite3ErrorMsg(pParse, "undefined module %s for table %s", @@ -77312,22 +71429,10 @@ static double bestVirtualIndex( (void)sqlite3SafetyOff(pParse->db); WHERETRACE(("xBestIndex for %s\n", pTab->zName)); TRACE_IDX_INPUTS(pIdxInfo); - rc = pVtab->pModule->xBestIndex(pVtab, pIdxInfo); + rc = pTab->pVtab->pModule->xBestIndex(pTab->pVtab, pIdxInfo); TRACE_IDX_OUTPUTS(pIdxInfo); (void)sqlite3SafetyOn(pParse->db); - if( rc!=SQLITE_OK ){ - if( rc==SQLITE_NOMEM ){ - pParse->db->mallocFailed = 1; - }else if( !pVtab->zErrMsg ){ - sqlite3ErrorMsg(pParse, "%s", sqlite3ErrStr(rc)); - }else{ - sqlite3ErrorMsg(pParse, "%s", pVtab->zErrMsg); - } - } - sqlite3DbFree(pParse->db, pVtab->zErrMsg); - pVtab->zErrMsg = 0; - for(i=0; inConstraint; i++){ if( !pIdxInfo->aConstraint[i].usable && pUsage[i].argvIndex>0 ){ sqlite3ErrorMsg(pParse, @@ -77336,7 +71441,15 @@ static double bestVirtualIndex( } } + if( rc!=SQLITE_OK ){ + if( rc==SQLITE_NOMEM ){ + pParse->db->mallocFailed = 1; + }else { + sqlite3ErrorMsg(pParse, "%s", sqlite3ErrStr(rc)); + } + } *(int*)&pIdxInfo->nOrderBy = nOrderBy; + return pIdxInfo->estimatedCost; } #endif /* SQLITE_OMIT_VIRTUALTABLE */ @@ -77358,16 +71471,6 @@ static double bestVirtualIndex( ** * Whether or not there must be separate lookups in the ** index and in the main table. ** -** If there was an INDEXED BY clause attached to the table in the SELECT -** statement, then this function only considers strategies using the -** named index. If one cannot be found, then the returned cost is -** SQLITE_BIG_DBL. If a strategy can be found that uses the named index, -** then the cost is calculated in the usual way. -** -** If a NOT INDEXED clause was attached to the table in the SELECT -** statement, then no indexes are considered. However, the selected -** stategy may still take advantage of the tables built-in rowid -** index. */ static double bestIndex( Parse *pParse, /* The parsing context */ @@ -77392,12 +71495,9 @@ static double bestIndex( int eqTermMask; /* Mask of valid equality operators */ double cost; /* Cost of using pProbe */ - WHERETRACE(("bestIndex: tbl=%s notReady=%llx\n", pSrc->pTab->zName, notReady)); + WHERETRACE(("bestIndex: tbl=%s notReady=%x\n", pSrc->pTab->zName, notReady)); lowestCost = SQLITE_BIG_DBL; pProbe = pSrc->pTab->pIndex; - if( pSrc->notIndexed ){ - pProbe = 0; - } /* If the table has no indices and there are no terms in the where ** clause that refer to the ROWID, then we will never be able to do @@ -77414,77 +71514,74 @@ static double bestIndex( return 0.0; } - /* Check for a rowid=EXPR or rowid IN (...) constraints. If there was - ** an INDEXED BY clause attached to this table, skip this step. + /* Check for a rowid=EXPR or rowid IN (...) constraints */ - if( !pSrc->pIndex ){ - pTerm = findTerm(pWC, iCur, -1, notReady, WO_EQ|WO_IN, 0); - if( pTerm ){ - Expr *pExpr; - *ppIndex = 0; - bestFlags = WHERE_ROWID_EQ; - if( pTerm->eOperator & WO_EQ ){ - /* Rowid== is always the best pick. Look no further. Because only - ** a single row is generated, output is always in sorted order */ - *pFlags = WHERE_ROWID_EQ | WHERE_UNIQUE; - *pnEq = 1; - WHERETRACE(("... best is rowid\n")); - return 0.0; - }else if( (pExpr = pTerm->pExpr)->pList!=0 ){ - /* Rowid IN (LIST): cost is NlogN where N is the number of list - ** elements. */ - lowestCost = pExpr->pList->nExpr; - lowestCost *= estLog(lowestCost); - }else{ - /* Rowid IN (SELECT): cost is NlogN where N is the number of rows - ** in the result of the inner select. We have no way to estimate - ** that value so make a wild guess. */ - lowestCost = 200; - } - WHERETRACE(("... rowid IN cost: %.9g\n", lowestCost)); - } - - /* Estimate the cost of a table scan. If we do not know how many - ** entries are in the table, use 1 million as a guess. - */ - cost = pProbe ? pProbe->aiRowEst[0] : 1000000; - WHERETRACE(("... table scan base cost: %.9g\n", cost)); - flags = WHERE_ROWID_RANGE; - - /* Check for constraints on a range of rowids in a table scan. - */ - pTerm = findTerm(pWC, iCur, -1, notReady, WO_LT|WO_LE|WO_GT|WO_GE, 0); - if( pTerm ){ - if( findTerm(pWC, iCur, -1, notReady, WO_LT|WO_LE, 0) ){ - flags |= WHERE_TOP_LIMIT; - cost /= 3; /* Guess that rowidEXPR eliminates two-thirds of rows */ - } - WHERETRACE(("... rowid range reduces cost to %.9g\n", cost)); + pTerm = findTerm(pWC, iCur, -1, notReady, WO_EQ|WO_IN, 0); + if( pTerm ){ + Expr *pExpr; + *ppIndex = 0; + bestFlags = WHERE_ROWID_EQ; + if( pTerm->eOperator & WO_EQ ){ + /* Rowid== is always the best pick. Look no further. Because only + ** a single row is generated, output is always in sorted order */ + *pFlags = WHERE_ROWID_EQ | WHERE_UNIQUE; + *pnEq = 1; + WHERETRACE(("... best is rowid\n")); + return 0.0; + }else if( (pExpr = pTerm->pExpr)->pList!=0 ){ + /* Rowid IN (LIST): cost is NlogN where N is the number of list + ** elements. */ + lowestCost = pExpr->pList->nExpr; + lowestCost *= estLog(lowestCost); }else{ - flags = 0; + /* Rowid IN (SELECT): cost is NlogN where N is the number of rows + ** in the result of the inner select. We have no way to estimate + ** that value so make a wild guess. */ + lowestCost = 200; } - - /* If the table scan does not satisfy the ORDER BY clause, increase - ** the cost by NlogN to cover the expense of sorting. */ - if( pOrderBy ){ - if( sortableByRowid(iCur, pOrderBy, pWC->pMaskSet, &rev) ){ - flags |= WHERE_ORDERBY|WHERE_ROWID_RANGE; - if( rev ){ - flags |= WHERE_REVERSE; - } - }else{ - cost += cost*estLog(cost); - WHERETRACE(("... sorting increases cost to %.9g\n", cost)); + WHERETRACE(("... rowid IN cost: %.9g\n", lowestCost)); + } + + /* Estimate the cost of a table scan. If we do not know how many + ** entries are in the table, use 1 million as a guess. + */ + cost = pProbe ? pProbe->aiRowEst[0] : 1000000; + WHERETRACE(("... table scan base cost: %.9g\n", cost)); + flags = WHERE_ROWID_RANGE; + + /* Check for constraints on a range of rowids in a table scan. + */ + pTerm = findTerm(pWC, iCur, -1, notReady, WO_LT|WO_LE|WO_GT|WO_GE, 0); + if( pTerm ){ + if( findTerm(pWC, iCur, -1, notReady, WO_LT|WO_LE, 0) ){ + flags |= WHERE_TOP_LIMIT; + cost /= 3; /* Guess that rowidEXPR eliminates two-thirds of rows */ + } + WHERETRACE(("... rowid range reduces cost to %.9g\n", cost)); + }else{ + flags = 0; + } + + /* If the table scan does not satisfy the ORDER BY clause, increase + ** the cost by NlogN to cover the expense of sorting. */ + if( pOrderBy ){ + if( sortableByRowid(iCur, pOrderBy, pWC->pMaskSet, &rev) ){ + flags |= WHERE_ORDERBY|WHERE_ROWID_RANGE; + if( rev ){ + flags |= WHERE_REVERSE; } + }else{ + cost += cost*estLog(cost); + WHERETRACE(("... sorting increases cost to %.9g\n", cost)); } - if( costpIndex ){ - pProbe = pSrc->pIndex; - } - for(; pProbe; pProbe=(pSrc->pIndex ? 0 : pProbe->pNext)){ + for(; pProbe; pProbe=pProbe->pNext){ int i; /* Loop counter */ double inMultiplier = 1; @@ -77523,7 +71617,7 @@ static double bestIndex( flags |= WHERE_COLUMN_IN; if( pExpr->pSelect!=0 ){ inMultiplier *= 25; - }else if( ALWAYS(pExpr->pList) ){ + }else if( pExpr->pList!=0 ){ inMultiplier *= pExpr->pList->nExpr + 1; } } @@ -77639,7 +71733,7 @@ static double bestIndex( */ static void disableTerm(WhereLevel *pLevel, WhereTerm *pTerm){ if( pTerm - && ALWAYS((pTerm->flags & TERM_CODED)==0) + && (pTerm->flags & TERM_CODED)==0 && (pLevel->iLeftJoin==0 || ExprHasProperty(pTerm->pExpr, EP_FromJoin)) ){ pTerm->flags |= TERM_CODED; @@ -77688,7 +71782,9 @@ static int codeEqualityTerm( Vdbe *v = pParse->pVdbe; int iReg; /* Register holding results */ - assert( iTarget>0 ); + if( iTarget<=0 ){ + iReg = iTarget = sqlite3GetTempReg(pParse); + } if( pX->op==TK_EQ ){ iReg = sqlite3ExprCodeTarget(pParse, pX->pRight, iTarget); }else if( pX->op==TK_ISNULL ){ @@ -77702,7 +71798,7 @@ static int codeEqualityTerm( assert( pX->op==TK_IN ); iReg = iTarget; - eType = sqlite3FindInIndex(pParse, pX, 0); + eType = sqlite3FindInIndex(pParse, pX, 1); iTab = pX->iTable; sqlite3VdbeAddOp2(v, OP_Rewind, iTab, 0); VdbeComment((v, "%.*s", pX->span.n, pX->span.z)); @@ -77785,7 +71881,7 @@ static int codeAllEqualityTerms( int r1; int k = pIdx->aiColumn[j]; pTerm = findTerm(pWC, iCur, k, notReady, pLevel->flags, pIdx); - if( NEVER(pTerm==0) ) break; + if( pTerm==0 ) break; assert( (pTerm->flags & TERM_CODED)==0 ); r1 = codeEqualityTerm(pParse, pTerm, pLevel, regBase+j); if( r1!=regBase+j ){ @@ -77816,17 +71912,17 @@ static int nQPlan = 0; /* Next free slow in _query_plan[] */ /* ** Free a WhereInfo structure */ -static void whereInfoFree(sqlite3 *db, WhereInfo *pWInfo){ +static void whereInfoFree(WhereInfo *pWInfo){ if( pWInfo ){ int i; for(i=0; inLevel; i++){ sqlite3_index_info *pInfo = pWInfo->a[i].pIdxInfo; if( pInfo ){ assert( pInfo->needToFreeIdxStr==0 ); - sqlite3DbFree(db, pInfo); + sqlite3_free(pInfo); } } - sqlite3DbFree(db, pWInfo); + sqlite3_free(pWInfo); } } @@ -77968,7 +72064,7 @@ SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin( pWInfo = sqlite3DbMallocZero(db, sizeof(WhereInfo) + pTabList->nSrc*sizeof(WhereLevel)); if( db->mallocFailed ){ - goto whereBeginError; + goto whereBeginNoMem; } pWInfo->nLevel = pTabList->nSrc; pWInfo->pParse = pParse; @@ -78015,7 +72111,7 @@ SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin( */ exprAnalyzeAll(pTabList, &wc); if( db->mallocFailed ){ - goto whereBeginError; + goto whereBeginNoMem; } /* Chose the best index to use for each table in the FROM clause. @@ -78025,7 +72121,7 @@ SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin( ** pWInfo->a[].pIdx The index to use for this level of the loop. ** pWInfo->a[].flags WHERE_xxx flags associated with pIdx ** pWInfo->a[].nEq The number of == and IN constraints - ** pWInfo->a[].iFrom Which term of the FROM clause is being coded + ** pWInfo->a[].iFrom When term of the FROM clause is being coded ** pWInfo->a[].iTabCur The VDBE cursor for the database table ** pWInfo->a[].iIdxCur The VDBE cursor for the index ** @@ -78104,7 +72200,7 @@ SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin( } if( doNotReorder ) break; } - WHERETRACE(("*** Optimizer selects table %d for loop %d\n", bestJ, + WHERETRACE(("*** Optimizer choose table %d for loop %d\n", bestJ, pLevel-pWInfo->a)); if( (bestFlags & WHERE_ORDERBY)!=0 ){ *ppOrderBy = 0; @@ -78122,18 +72218,6 @@ SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin( } notReady &= ~getMask(&maskSet, pTabList->a[bestJ].iCursor); pLevel->iFrom = bestJ; - - /* Check that if the table scanned by this loop iteration had an - ** INDEXED BY clause attached to it, that the named index is being - ** used for the scan. If not, then query compilation has failed. - ** Return an error. - */ - pIdx = pTabList->a[bestJ].pIndex; - assert( !pIdx || !pBest || pIdx==pBest ); - if( pIdx && pBest!=pIdx ){ - sqlite3ErrorMsg(pParse, "cannot use index: %s", pIdx->zName); - goto whereBeginError; - } } WHERETRACE(("*** Optimizer Finished ***\n")); @@ -78171,22 +72255,22 @@ SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin( struct SrcList_item *pItem = &pTabList->a[pLevel->iFrom]; zMsg = sqlite3MPrintf(db, "TABLE %s", pItem->zName); if( pItem->zAlias ){ - zMsg = sqlite3MAppendf(db, zMsg, "%s AS %s", zMsg, pItem->zAlias); + zMsg = sqlite3MPrintf(db, "%z AS %s", zMsg, pItem->zAlias); } if( (pIx = pLevel->pIdx)!=0 ){ - zMsg = sqlite3MAppendf(db, zMsg, "%s WITH INDEX %s", zMsg, pIx->zName); + zMsg = sqlite3MPrintf(db, "%z WITH INDEX %s", zMsg, pIx->zName); }else if( pLevel->flags & (WHERE_ROWID_EQ|WHERE_ROWID_RANGE) ){ - zMsg = sqlite3MAppendf(db, zMsg, "%s USING PRIMARY KEY", zMsg); + zMsg = sqlite3MPrintf(db, "%z USING PRIMARY KEY", zMsg); } #ifndef SQLITE_OMIT_VIRTUALTABLE else if( pLevel->pBestIdx ){ sqlite3_index_info *pBestIdx = pLevel->pBestIdx; - zMsg = sqlite3MAppendf(db, zMsg, "%s VIRTUAL TABLE INDEX %d:%s", zMsg, + zMsg = sqlite3MPrintf(db, "%z VIRTUAL TABLE INDEX %d:%s", zMsg, pBestIdx->idxNum, pBestIdx->idxStr); } #endif if( pLevel->flags & WHERE_ORDERBY ){ - zMsg = sqlite3MAppendf(db, zMsg, "%s ORDER BY", zMsg); + zMsg = sqlite3MPrintf(db, "%z ORDER BY", zMsg); } sqlite3VdbeAddOp4(v, OP_Explain, i, pLevel->iFrom, 0, zMsg, P4_DYNAMIC); } @@ -78194,7 +72278,7 @@ SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin( pTabItem = &pTabList->a[pLevel->iFrom]; pTab = pTabItem->pTab; iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema); - if( (pTab->tabFlags & TF_Ephemeral)!=0 || pTab->pSelect ) continue; + if( pTab->isEphem || pTab->pSelect ) continue; #ifndef SQLITE_OMIT_VIRTUALTABLE if( pLevel->pBestIdx ){ int iCur = pTabItem->iCursor; @@ -78287,28 +72371,24 @@ SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin( pBestIdx->aConstraint; iReg = sqlite3GetTempRange(pParse, nConstraint+2); - pParse->disableColCache++; for(j=1; j<=nConstraint; j++){ int k; for(k=0; kdisableColCache ); sqlite3ExprCode(pParse, wc.a[iTerm].pExpr->pRight, iReg+j+1); break; } } if( k==nConstraint ) break; } - assert( pParse->disableColCache ); - pParse->disableColCache--; sqlite3VdbeAddOp2(v, OP_Integer, pBestIdx->idxNum, iReg); sqlite3VdbeAddOp2(v, OP_Integer, j-1, iReg+1); sqlite3VdbeAddOp4(v, OP_VFilter, iCur, brk, iReg, pBestIdx->idxStr, pBestIdx->needToFreeIdxStr ? P4_MPRINTF : P4_STATIC); sqlite3ReleaseTempRange(pParse, iReg, nConstraint+2); pBestIdx->needToFreeIdxStr = 0; - for(j=0; jnConstraint; j++){ if( aUsage[j].omit ){ int iTerm = aConstraint[j].iTermOffset; disableTerm(pLevel, &wc.a[iTerm]); @@ -78327,17 +72407,15 @@ SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin( ** construct. */ int r1; - int rtmp = sqlite3GetTempReg(pParse); pTerm = findTerm(&wc, iCur, -1, notReady, WO_EQ|WO_IN, 0); assert( pTerm!=0 ); assert( pTerm->pExpr!=0 ); assert( pTerm->leftCursor==iCur ); assert( omitTable==0 ); - r1 = codeEqualityTerm(pParse, pTerm, pLevel, rtmp); + r1 = codeEqualityTerm(pParse, pTerm, pLevel, 0); nxt = pLevel->nxt; sqlite3VdbeAddOp2(v, OP_MustBeInt, r1, nxt); sqlite3VdbeAddOp3(v, OP_NotExists, iCur, nxt, r1); - sqlite3ReleaseTempReg(pParse, rtmp); VdbeComment((v, "pk")); pLevel->op = OP_Noop; }else if( pLevel->flags & WHERE_ROWID_RANGE ){ @@ -78475,9 +72553,8 @@ SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin( if( (wflags&WHERE_ORDERBY_MIN)!=0 && (pLevel->flags&WHERE_ORDERBY) && (pIdx->nColumn>nEq) + && (pOrderBy->a[0].pExpr->iColumn==pIdx->aiColumn[nEq]) ){ - assert( pOrderBy->nExpr==1 ); - assert( pOrderBy->a[0].pExpr->iColumn==pIdx->aiColumn[nEq] ); isMinQuery = 1; } @@ -78512,7 +72589,7 @@ SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin( if( pRangeStart ){ int dcc = pParse->disableColCache; if( pRangeEnd ){ - pParse->disableColCache++; + pParse->disableColCache = 1; } sqlite3ExprCode(pParse, pRangeStart->pExpr->pRight, regBase+nEq); pParse->disableColCache = dcc; @@ -78534,7 +72611,7 @@ SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin( testcase( op==OP_MoveLe ); testcase( op==OP_MoveLt ); sqlite3VdbeAddOp4(v, op, iIdxCur, nxt, regBase, - SQLITE_INT_TO_PTR(nConstraint), P4_INT32); + (char*)nConstraint, P4_INT32); /* Load the value for the inequality constraint at the end of the ** range (if any). @@ -78556,7 +72633,7 @@ SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin( testcase( op==OP_IdxGE ); testcase( op==OP_IdxLT ); sqlite3VdbeAddOp4(v, op, iIdxCur, nxt, regBase, - SQLITE_INT_TO_PTR(nConstraint), P4_INT32); + (char*)nConstraint, P4_INT32); sqlite3VdbeChangeP5(v, endEq!=bRev); /* If there are inequality constraints, check that the value @@ -78594,7 +72671,6 @@ SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin( pLevel->op = OP_Next; pLevel->p1 = iCur; pLevel->p2 = 1 + sqlite3VdbeAddOp2(v, OP_Rewind, iCur, brk); - pLevel->p5 = SQLITE_STMTSTATUS_FULLSCAN_STEP; } notReady &= ~getMask(&maskSet, iCur); @@ -78694,9 +72770,9 @@ SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin( return pWInfo; /* Jump here if malloc fails */ -whereBeginError: +whereBeginNoMem: whereClauseClear(&wc); - whereInfoFree(db, pWInfo); + whereInfoFree(pWInfo); return 0; } @@ -78705,22 +72781,19 @@ whereBeginError: ** sqlite3WhereBegin() for additional information. */ SQLITE_PRIVATE void sqlite3WhereEnd(WhereInfo *pWInfo){ - Parse *pParse = pWInfo->pParse; - Vdbe *v = pParse->pVdbe; + Vdbe *v = pWInfo->pParse->pVdbe; int i; WhereLevel *pLevel; SrcList *pTabList = pWInfo->pTabList; - sqlite3 *db = pParse->db; /* Generate loop termination code. */ - sqlite3ExprClearColumnCache(pParse, -1); + sqlite3ExprClearColumnCache(pWInfo->pParse, -1); for(i=pTabList->nSrc-1; i>=0; i--){ pLevel = &pWInfo->a[i]; sqlite3VdbeResolveLabel(v, pLevel->cont); if( pLevel->op!=OP_Noop ){ sqlite3VdbeAddOp2(v, pLevel->op, pLevel->p1, pLevel->p2); - sqlite3VdbeChangeP5(v, pLevel->p5); } if( pLevel->nIn ){ struct InLoop *pIn; @@ -78731,7 +72804,7 @@ SQLITE_PRIVATE void sqlite3WhereEnd(WhereInfo *pWInfo){ sqlite3VdbeAddOp2(v, OP_Next, pIn->iCur, pIn->topAddr); sqlite3VdbeJumpHere(v, pIn->topAddr-1); } - sqlite3DbFree(db, pLevel->aInLoop); + sqlite3_free(pLevel->aInLoop); } sqlite3VdbeResolveLabel(v, pLevel->brk); if( pLevel->iLeftJoin ){ @@ -78757,7 +72830,7 @@ SQLITE_PRIVATE void sqlite3WhereEnd(WhereInfo *pWInfo){ struct SrcList_item *pTabItem = &pTabList->a[pLevel->iFrom]; Table *pTab = pTabItem->pTab; assert( pTab!=0 ); - if( (pTab->tabFlags & TF_Ephemeral)!=0 || pTab->pSelect ) continue; + if( pTab->isEphem || pTab->pSelect ) continue; if( !pWInfo->okOnePass && (pLevel->flags & WHERE_IDX_ONLY)==0 ){ sqlite3VdbeAddOp1(v, OP_Close, pTabItem->iCursor); } @@ -78810,7 +72883,7 @@ SQLITE_PRIVATE void sqlite3WhereEnd(WhereInfo *pWInfo){ /* Final cleanup */ - whereInfoFree(db, pWInfo); + whereInfoFree(pWInfo); return; } @@ -78819,8 +72892,8 @@ SQLITE_PRIVATE void sqlite3WhereEnd(WhereInfo *pWInfo){ /* Driver template for the LEMON parser generator. ** The author disclaims copyright to this source code. */ -/* First off, code is included that follows the "include" declaration -** in the input grammar file. */ +/* First off, code is include which follows the "include" declaration +** in the input file. */ /* @@ -78907,23 +72980,24 @@ struct AttachKey { int type; Token key; }; ** defined, then do no error processing. */ #define YYCODETYPE unsigned char -#define YYNOCODE 249 +#define YYNOCODE 248 #define YYACTIONTYPE unsigned short int #define YYWILDCARD 59 #define sqlite3ParserTOKENTYPE Token typedef union { sqlite3ParserTOKENTYPE yy0; - Select* yy43; - TriggerStep* yy75; - struct LimitVal yy84; - struct LikeOp yy86; - struct {int value; int mask;} yy207; - ExprList* yy242; - int yy316; - IdList* yy352; - struct TrigEvent yy354; - SrcList* yy419; - Expr* yy450; + int yy46; + struct LikeOp yy72; + Expr* yy172; + ExprList* yy174; + Select* yy219; + struct LimitVal yy234; + TriggerStep* yy243; + struct TrigEvent yy370; + SrcList* yy373; + struct {int value; int mask;} yy405; + Token yy410; + IdList* yy432; } YYMINORTYPE; #ifndef YYSTACKDEPTH #define YYSTACKDEPTH 100 @@ -78932,8 +73006,8 @@ typedef union { #define sqlite3ParserARG_PDECL ,Parse *pParse #define sqlite3ParserARG_FETCH Parse *pParse = yypParser->pParse #define sqlite3ParserARG_STORE yypParser->pParse = pParse -#define YYNSTATE 598 -#define YYNRULE 315 +#define YYNSTATE 589 +#define YYNRULE 313 #define YYFALLBACK 1 #define YY_NO_ACTION (YYNSTATE+YYNRULE+2) #define YY_ACCEPT_ACTION (YYNSTATE+YYNRULE+1) @@ -78941,13 +73015,9 @@ typedef union { /* The yyzerominor constant is used to initialize instances of ** YYMINORTYPE objects to zero. */ -#if 0 -static YYMINORTYPE yyzerominor; -#else static const YYMINORTYPE yyzerominor; -#endif -/* Next are the tables used to determine what action to take based on the +/* Next are that tables used to determine what action to take based on the ** current state and lookahead token. These tables are used to implement ** functions that take a state number and lookahead value and return an ** action integer. @@ -78995,420 +73065,416 @@ static const YYMINORTYPE yyzerominor; ** yy_default[] Default action for each state. */ static const YYACTIONTYPE yy_action[] = { - /* 0 */ 296, 914, 120, 597, 2, 172, 425, 425, 62, 62, - /* 10 */ 62, 62, 210, 64, 64, 64, 64, 65, 65, 66, - /* 20 */ 66, 66, 67, 212, 398, 395, 432, 438, 69, 64, - /* 30 */ 64, 64, 64, 65, 65, 66, 66, 66, 67, 212, - /* 40 */ 458, 456, 327, 168, 61, 60, 301, 442, 443, 439, - /* 50 */ 439, 63, 63, 62, 62, 62, 62, 256, 64, 64, - /* 60 */ 64, 64, 65, 65, 66, 66, 66, 67, 212, 296, - /* 70 */ 498, 425, 425, 212, 427, 83, 68, 469, 70, 154, - /* 80 */ 64, 64, 64, 64, 65, 65, 66, 66, 66, 67, - /* 90 */ 212, 68, 307, 70, 154, 432, 438, 454, 214, 59, - /* 100 */ 65, 65, 66, 66, 66, 67, 212, 429, 429, 429, - /* 110 */ 497, 583, 296, 61, 60, 301, 442, 443, 439, 439, - /* 120 */ 63, 63, 62, 62, 62, 62, 321, 64, 64, 64, - /* 130 */ 64, 65, 65, 66, 66, 66, 67, 212, 432, 438, - /* 140 */ 95, 66, 66, 66, 67, 212, 403, 256, 421, 35, - /* 150 */ 57, 67, 212, 175, 417, 499, 61, 60, 301, 442, - /* 160 */ 443, 439, 439, 63, 63, 62, 62, 62, 62, 19, - /* 170 */ 64, 64, 64, 64, 65, 65, 66, 66, 66, 67, - /* 180 */ 212, 296, 225, 532, 299, 581, 109, 422, 242, 458, - /* 190 */ 416, 335, 414, 21, 502, 503, 346, 403, 527, 176, - /* 200 */ 160, 454, 214, 580, 579, 344, 500, 432, 438, 149, - /* 210 */ 150, 404, 405, 539, 514, 418, 151, 541, 8, 498, - /* 220 */ 538, 577, 578, 427, 296, 61, 60, 301, 442, 443, - /* 230 */ 439, 439, 63, 63, 62, 62, 62, 62, 196, 64, - /* 240 */ 64, 64, 64, 65, 65, 66, 66, 66, 67, 212, - /* 250 */ 432, 438, 454, 598, 398, 395, 429, 429, 429, 369, - /* 260 */ 558, 481, 404, 405, 372, 576, 213, 296, 61, 60, - /* 270 */ 301, 442, 443, 439, 439, 63, 63, 62, 62, 62, - /* 280 */ 62, 321, 64, 64, 64, 64, 65, 65, 66, 66, - /* 290 */ 66, 67, 212, 432, 438, 555, 503, 304, 557, 532, - /* 300 */ 218, 557, 552, 421, 36, 234, 397, 2, 542, 21, - /* 310 */ 540, 61, 60, 301, 442, 443, 439, 439, 63, 63, - /* 320 */ 62, 62, 62, 62, 388, 64, 64, 64, 64, 65, - /* 330 */ 65, 66, 66, 66, 67, 212, 415, 530, 85, 381, - /* 340 */ 78, 323, 296, 210, 304, 527, 493, 492, 379, 274, - /* 350 */ 273, 379, 274, 273, 347, 463, 241, 387, 268, 210, - /* 360 */ 533, 581, 210, 403, 20, 224, 144, 464, 432, 438, - /* 370 */ 485, 164, 114, 248, 349, 253, 350, 177, 554, 580, - /* 380 */ 465, 420, 331, 81, 257, 419, 61, 60, 301, 442, - /* 390 */ 443, 439, 439, 63, 63, 62, 62, 62, 62, 391, - /* 400 */ 64, 64, 64, 64, 65, 65, 66, 66, 66, 67, - /* 410 */ 212, 296, 224, 203, 249, 496, 403, 440, 837, 114, - /* 420 */ 248, 349, 253, 350, 177, 250, 321, 152, 404, 405, - /* 430 */ 321, 257, 303, 324, 155, 445, 445, 432, 438, 317, - /* 440 */ 400, 389, 213, 68, 209, 70, 154, 422, 421, 35, - /* 450 */ 393, 202, 421, 42, 481, 61, 60, 301, 442, 443, - /* 460 */ 439, 439, 63, 63, 62, 62, 62, 62, 422, 64, - /* 470 */ 64, 64, 64, 65, 65, 66, 66, 66, 67, 212, - /* 480 */ 296, 404, 405, 183, 513, 422, 351, 354, 355, 403, - /* 490 */ 77, 335, 79, 489, 216, 183, 334, 356, 351, 354, - /* 500 */ 355, 433, 434, 406, 407, 408, 432, 438, 235, 356, - /* 510 */ 386, 68, 291, 70, 154, 456, 531, 168, 198, 302, - /* 520 */ 449, 450, 436, 437, 61, 60, 301, 442, 443, 439, - /* 530 */ 439, 63, 63, 62, 62, 62, 62, 394, 64, 64, - /* 540 */ 64, 64, 65, 65, 66, 66, 66, 67, 212, 296, - /* 550 */ 321, 435, 422, 260, 404, 405, 321, 183, 153, 321, - /* 560 */ 351, 354, 355, 446, 332, 321, 595, 905, 321, 905, - /* 570 */ 1, 356, 421, 28, 403, 432, 438, 376, 421, 42, - /* 580 */ 477, 421, 35, 213, 548, 366, 548, 421, 50, 159, - /* 590 */ 421, 50, 422, 61, 60, 301, 442, 443, 439, 439, - /* 600 */ 63, 63, 62, 62, 62, 62, 592, 64, 64, 64, - /* 610 */ 64, 65, 65, 66, 66, 66, 67, 212, 296, 337, - /* 620 */ 217, 463, 256, 94, 339, 326, 449, 450, 172, 340, - /* 630 */ 425, 345, 532, 464, 312, 595, 904, 313, 904, 404, - /* 640 */ 405, 588, 21, 226, 432, 438, 465, 243, 504, 324, - /* 650 */ 322, 445, 445, 421, 3, 459, 230, 308, 505, 194, - /* 660 */ 278, 296, 61, 60, 301, 442, 443, 439, 439, 63, - /* 670 */ 63, 62, 62, 62, 62, 592, 64, 64, 64, 64, - /* 680 */ 65, 65, 66, 66, 66, 67, 212, 432, 438, 213, - /* 690 */ 179, 180, 181, 422, 324, 425, 445, 445, 281, 262, - /* 700 */ 279, 402, 194, 481, 296, 61, 60, 301, 442, 443, - /* 710 */ 439, 439, 63, 63, 62, 62, 62, 62, 377, 64, - /* 720 */ 64, 64, 64, 65, 65, 66, 66, 66, 67, 212, - /* 730 */ 432, 438, 591, 295, 115, 268, 422, 266, 211, 264, - /* 740 */ 373, 324, 246, 445, 445, 56, 256, 296, 61, 71, - /* 750 */ 301, 442, 443, 439, 439, 63, 63, 62, 62, 62, - /* 760 */ 62, 377, 64, 64, 64, 64, 65, 65, 66, 66, - /* 770 */ 66, 67, 212, 432, 438, 550, 269, 474, 18, 549, - /* 780 */ 280, 309, 343, 380, 171, 160, 256, 268, 5, 268, - /* 790 */ 296, 368, 60, 301, 442, 443, 439, 439, 63, 63, - /* 800 */ 62, 62, 62, 62, 321, 64, 64, 64, 64, 65, - /* 810 */ 65, 66, 66, 66, 67, 212, 432, 438, 403, 10, - /* 820 */ 403, 310, 268, 403, 268, 485, 421, 29, 566, 22, - /* 830 */ 568, 420, 428, 425, 376, 419, 301, 442, 443, 439, - /* 840 */ 439, 63, 63, 62, 62, 62, 62, 321, 64, 64, - /* 850 */ 64, 64, 65, 65, 66, 66, 66, 67, 212, 73, - /* 860 */ 328, 485, 4, 569, 268, 570, 300, 268, 147, 421, - /* 870 */ 24, 321, 359, 321, 325, 73, 328, 491, 4, 455, - /* 880 */ 321, 342, 300, 404, 405, 404, 405, 367, 404, 405, - /* 890 */ 325, 330, 321, 421, 33, 421, 54, 321, 425, 178, - /* 900 */ 229, 458, 421, 53, 321, 227, 321, 330, 228, 478, - /* 910 */ 165, 321, 315, 119, 421, 99, 333, 458, 321, 421, - /* 920 */ 97, 76, 75, 311, 268, 519, 421, 102, 421, 103, - /* 930 */ 74, 319, 320, 421, 108, 427, 467, 76, 75, 490, - /* 940 */ 421, 110, 452, 452, 321, 520, 74, 319, 320, 73, - /* 950 */ 328, 427, 4, 210, 298, 321, 300, 321, 156, 257, - /* 960 */ 321, 210, 185, 182, 325, 284, 421, 17, 429, 429, - /* 970 */ 429, 430, 431, 12, 593, 378, 188, 421, 100, 421, - /* 980 */ 34, 330, 421, 98, 429, 429, 429, 430, 431, 12, - /* 990 */ 475, 458, 422, 162, 480, 321, 422, 306, 231, 232, - /* 1000 */ 233, 105, 484, 632, 476, 321, 486, 447, 321, 23, - /* 1010 */ 422, 76, 75, 594, 207, 178, 286, 421, 25, 254, - /* 1020 */ 74, 319, 320, 287, 321, 427, 321, 421, 55, 321, - /* 1030 */ 421, 111, 321, 471, 321, 205, 515, 557, 511, 363, - /* 1040 */ 472, 204, 321, 516, 206, 321, 421, 112, 421, 113, - /* 1050 */ 321, 421, 26, 321, 421, 37, 421, 38, 429, 429, - /* 1060 */ 429, 430, 431, 12, 421, 27, 521, 421, 39, 321, - /* 1070 */ 298, 158, 421, 40, 255, 421, 41, 321, 483, 321, - /* 1080 */ 173, 523, 321, 182, 321, 522, 321, 384, 283, 273, - /* 1090 */ 321, 421, 43, 297, 534, 321, 476, 321, 210, 421, - /* 1100 */ 44, 421, 45, 321, 421, 30, 421, 31, 421, 46, - /* 1110 */ 508, 509, 421, 47, 259, 321, 182, 421, 48, 421, - /* 1120 */ 49, 321, 358, 390, 182, 421, 32, 321, 261, 518, - /* 1130 */ 517, 553, 561, 182, 173, 412, 191, 421, 11, 562, - /* 1140 */ 573, 92, 92, 421, 51, 590, 263, 294, 265, 421, - /* 1150 */ 52, 267, 272, 371, 146, 374, 375, 275, 276, 277, - /* 1160 */ 565, 575, 285, 288, 289, 587, 470, 451, 236, 453, - /* 1170 */ 329, 244, 473, 514, 251, 524, 560, 163, 401, 572, - /* 1180 */ 426, 525, 282, 528, 409, 7, 410, 411, 385, 318, - /* 1190 */ 85, 237, 338, 526, 84, 336, 353, 58, 80, 215, - /* 1200 */ 170, 468, 121, 86, 341, 348, 305, 501, 506, 124, - /* 1210 */ 511, 222, 360, 423, 252, 186, 512, 510, 221, 223, - /* 1220 */ 238, 507, 239, 535, 240, 292, 424, 529, 536, 537, - /* 1230 */ 293, 543, 187, 189, 245, 362, 482, 488, 247, 190, - /* 1240 */ 364, 89, 545, 192, 117, 370, 132, 556, 563, 195, - /* 1250 */ 382, 383, 314, 133, 134, 571, 138, 135, 136, 584, - /* 1260 */ 589, 585, 142, 399, 101, 413, 220, 586, 270, 104, - /* 1270 */ 141, 633, 634, 166, 167, 441, 444, 72, 460, 448, - /* 1280 */ 457, 546, 143, 157, 6, 461, 14, 479, 169, 462, - /* 1290 */ 93, 466, 82, 122, 13, 174, 487, 96, 123, 161, - /* 1300 */ 494, 495, 87, 125, 126, 116, 258, 88, 127, 184, - /* 1310 */ 250, 361, 219, 107, 544, 145, 128, 193, 365, 118, - /* 1320 */ 352, 357, 173, 271, 130, 9, 316, 559, 197, 90, - /* 1330 */ 547, 131, 129, 15, 199, 551, 564, 200, 567, 201, - /* 1340 */ 139, 137, 582, 91, 16, 106, 140, 208, 574, 392, - /* 1350 */ 396, 290, 148, 596, + /* 0 */ 292, 903, 124, 588, 409, 172, 2, 418, 61, 61, + /* 10 */ 61, 61, 519, 63, 63, 63, 63, 64, 64, 65, + /* 20 */ 65, 65, 66, 210, 447, 212, 425, 431, 68, 63, + /* 30 */ 63, 63, 63, 64, 64, 65, 65, 65, 66, 210, + /* 40 */ 391, 388, 396, 451, 60, 59, 297, 435, 436, 432, + /* 50 */ 432, 62, 62, 61, 61, 61, 61, 263, 63, 63, + /* 60 */ 63, 63, 64, 64, 65, 65, 65, 66, 210, 292, + /* 70 */ 493, 494, 418, 489, 208, 82, 67, 420, 69, 154, + /* 80 */ 63, 63, 63, 63, 64, 64, 65, 65, 65, 66, + /* 90 */ 210, 67, 462, 69, 154, 425, 431, 574, 264, 58, + /* 100 */ 64, 64, 65, 65, 65, 66, 210, 397, 398, 422, + /* 110 */ 422, 422, 292, 60, 59, 297, 435, 436, 432, 432, + /* 120 */ 62, 62, 61, 61, 61, 61, 317, 63, 63, 63, + /* 130 */ 63, 64, 64, 65, 65, 65, 66, 210, 425, 431, + /* 140 */ 94, 65, 65, 65, 66, 210, 396, 210, 414, 34, + /* 150 */ 56, 298, 442, 443, 410, 418, 60, 59, 297, 435, + /* 160 */ 436, 432, 432, 62, 62, 61, 61, 61, 61, 208, + /* 170 */ 63, 63, 63, 63, 64, 64, 65, 65, 65, 66, + /* 180 */ 210, 292, 372, 524, 295, 572, 113, 408, 522, 451, + /* 190 */ 331, 317, 407, 20, 244, 340, 519, 396, 478, 531, + /* 200 */ 505, 447, 212, 571, 570, 245, 530, 425, 431, 149, + /* 210 */ 150, 397, 398, 414, 41, 211, 151, 533, 488, 489, + /* 220 */ 418, 568, 569, 420, 292, 60, 59, 297, 435, 436, + /* 230 */ 432, 432, 62, 62, 61, 61, 61, 61, 317, 63, + /* 240 */ 63, 63, 63, 64, 64, 65, 65, 65, 66, 210, + /* 250 */ 425, 431, 447, 333, 215, 422, 422, 422, 363, 299, + /* 260 */ 414, 41, 397, 398, 366, 567, 211, 292, 60, 59, + /* 270 */ 297, 435, 436, 432, 432, 62, 62, 61, 61, 61, + /* 280 */ 61, 396, 63, 63, 63, 63, 64, 64, 65, 65, + /* 290 */ 65, 66, 210, 425, 431, 491, 300, 524, 474, 66, + /* 300 */ 210, 214, 474, 229, 411, 286, 534, 20, 449, 523, + /* 310 */ 168, 60, 59, 297, 435, 436, 432, 432, 62, 62, + /* 320 */ 61, 61, 61, 61, 474, 63, 63, 63, 63, 64, + /* 330 */ 64, 65, 65, 65, 66, 210, 209, 480, 317, 77, + /* 340 */ 292, 239, 300, 55, 484, 490, 397, 398, 181, 547, + /* 350 */ 494, 345, 348, 349, 67, 152, 69, 154, 339, 524, + /* 360 */ 414, 35, 350, 241, 221, 370, 425, 431, 579, 20, + /* 370 */ 164, 118, 243, 343, 248, 344, 176, 322, 442, 443, + /* 380 */ 414, 3, 80, 252, 60, 59, 297, 435, 436, 432, + /* 390 */ 432, 62, 62, 61, 61, 61, 61, 174, 63, 63, + /* 400 */ 63, 63, 64, 64, 65, 65, 65, 66, 210, 292, + /* 410 */ 221, 550, 236, 487, 510, 353, 317, 118, 243, 343, + /* 420 */ 248, 344, 176, 181, 317, 532, 345, 348, 349, 252, + /* 430 */ 223, 415, 155, 464, 511, 425, 431, 350, 414, 34, + /* 440 */ 465, 211, 177, 175, 160, 525, 414, 34, 338, 549, + /* 450 */ 449, 323, 168, 60, 59, 297, 435, 436, 432, 432, + /* 460 */ 62, 62, 61, 61, 61, 61, 415, 63, 63, 63, + /* 470 */ 63, 64, 64, 65, 65, 65, 66, 210, 292, 542, + /* 480 */ 335, 517, 504, 541, 456, 572, 302, 19, 331, 144, + /* 490 */ 317, 390, 317, 330, 2, 362, 457, 294, 483, 373, + /* 500 */ 269, 268, 252, 571, 425, 431, 589, 391, 388, 458, + /* 510 */ 208, 495, 414, 49, 414, 49, 303, 586, 894, 230, + /* 520 */ 894, 496, 60, 59, 297, 435, 436, 432, 432, 62, + /* 530 */ 62, 61, 61, 61, 61, 201, 63, 63, 63, 63, + /* 540 */ 64, 64, 65, 65, 65, 66, 210, 292, 317, 181, + /* 550 */ 439, 255, 345, 348, 349, 370, 153, 583, 308, 251, + /* 560 */ 309, 452, 76, 350, 78, 382, 211, 426, 427, 415, + /* 570 */ 414, 27, 319, 425, 431, 440, 1, 22, 586, 893, + /* 580 */ 396, 893, 544, 478, 320, 263, 438, 438, 429, 430, + /* 590 */ 415, 60, 59, 297, 435, 436, 432, 432, 62, 62, + /* 600 */ 61, 61, 61, 61, 237, 63, 63, 63, 63, 64, + /* 610 */ 64, 65, 65, 65, 66, 210, 292, 428, 583, 374, + /* 620 */ 224, 93, 517, 9, 159, 396, 557, 396, 456, 67, + /* 630 */ 396, 69, 154, 399, 400, 401, 320, 328, 438, 438, + /* 640 */ 457, 336, 425, 431, 361, 397, 398, 320, 433, 438, + /* 650 */ 438, 582, 291, 458, 238, 327, 318, 222, 546, 292, + /* 660 */ 60, 59, 297, 435, 436, 432, 432, 62, 62, 61, + /* 670 */ 61, 61, 61, 225, 63, 63, 63, 63, 64, 64, + /* 680 */ 65, 65, 65, 66, 210, 425, 431, 482, 313, 392, + /* 690 */ 397, 398, 397, 398, 207, 397, 398, 825, 273, 517, + /* 700 */ 251, 200, 292, 60, 59, 297, 435, 436, 432, 432, + /* 710 */ 62, 62, 61, 61, 61, 61, 470, 63, 63, 63, + /* 720 */ 63, 64, 64, 65, 65, 65, 66, 210, 425, 431, + /* 730 */ 171, 160, 263, 263, 304, 415, 276, 395, 274, 263, + /* 740 */ 517, 517, 263, 517, 192, 292, 60, 70, 297, 435, + /* 750 */ 436, 432, 432, 62, 62, 61, 61, 61, 61, 379, + /* 760 */ 63, 63, 63, 63, 64, 64, 65, 65, 65, 66, + /* 770 */ 210, 425, 431, 384, 559, 305, 306, 251, 415, 320, + /* 780 */ 560, 438, 438, 561, 540, 360, 540, 387, 292, 196, + /* 790 */ 59, 297, 435, 436, 432, 432, 62, 62, 61, 61, + /* 800 */ 61, 61, 371, 63, 63, 63, 63, 64, 64, 65, + /* 810 */ 65, 65, 66, 210, 425, 431, 396, 275, 251, 251, + /* 820 */ 172, 250, 418, 415, 386, 367, 178, 179, 180, 469, + /* 830 */ 311, 123, 156, 5, 297, 435, 436, 432, 432, 62, + /* 840 */ 62, 61, 61, 61, 61, 317, 63, 63, 63, 63, + /* 850 */ 64, 64, 65, 65, 65, 66, 210, 72, 324, 194, + /* 860 */ 4, 317, 263, 317, 296, 263, 415, 414, 28, 317, + /* 870 */ 257, 317, 321, 72, 324, 317, 4, 119, 165, 177, + /* 880 */ 296, 397, 398, 414, 23, 414, 32, 418, 321, 326, + /* 890 */ 421, 414, 53, 414, 52, 317, 158, 414, 98, 451, + /* 900 */ 317, 263, 317, 277, 317, 326, 378, 471, 261, 317, + /* 910 */ 259, 18, 478, 445, 445, 451, 317, 414, 96, 75, + /* 920 */ 74, 469, 414, 101, 414, 102, 414, 112, 73, 315, + /* 930 */ 316, 414, 114, 420, 294, 75, 74, 481, 414, 16, + /* 940 */ 381, 317, 279, 467, 73, 315, 316, 72, 324, 420, + /* 950 */ 4, 208, 317, 183, 296, 317, 186, 128, 84, 208, + /* 960 */ 8, 341, 321, 414, 99, 422, 422, 422, 423, 424, + /* 970 */ 11, 623, 380, 307, 414, 33, 413, 414, 97, 326, + /* 980 */ 412, 422, 422, 422, 423, 424, 11, 415, 413, 451, + /* 990 */ 415, 162, 412, 317, 499, 500, 226, 227, 228, 104, + /* 1000 */ 448, 476, 317, 173, 507, 317, 509, 508, 317, 75, + /* 1010 */ 74, 329, 205, 21, 281, 414, 24, 418, 73, 315, + /* 1020 */ 316, 282, 317, 420, 414, 54, 460, 414, 115, 317, + /* 1030 */ 414, 116, 502, 203, 147, 549, 514, 468, 128, 202, + /* 1040 */ 317, 473, 204, 317, 414, 117, 317, 477, 317, 584, + /* 1050 */ 317, 414, 25, 317, 249, 422, 422, 422, 423, 424, + /* 1060 */ 11, 506, 414, 36, 512, 414, 37, 317, 414, 26, + /* 1070 */ 414, 38, 414, 39, 526, 414, 40, 317, 254, 317, + /* 1080 */ 128, 317, 418, 317, 256, 377, 278, 268, 585, 414, + /* 1090 */ 42, 293, 317, 352, 317, 128, 208, 513, 258, 414, + /* 1100 */ 43, 414, 44, 414, 29, 414, 30, 545, 260, 128, + /* 1110 */ 317, 553, 317, 173, 414, 45, 414, 46, 317, 262, + /* 1120 */ 383, 554, 317, 91, 564, 317, 91, 317, 581, 189, + /* 1130 */ 290, 357, 414, 47, 414, 48, 267, 365, 368, 369, + /* 1140 */ 414, 31, 270, 271, 414, 10, 272, 414, 50, 414, + /* 1150 */ 51, 556, 566, 280, 283, 284, 578, 146, 419, 405, + /* 1160 */ 231, 505, 444, 325, 516, 463, 163, 446, 552, 394, + /* 1170 */ 466, 563, 246, 515, 518, 520, 402, 403, 404, 7, + /* 1180 */ 314, 84, 232, 334, 347, 83, 332, 57, 170, 79, + /* 1190 */ 213, 461, 125, 85, 337, 342, 492, 502, 497, 301, + /* 1200 */ 498, 416, 105, 219, 247, 218, 503, 501, 233, 220, + /* 1210 */ 287, 234, 527, 528, 235, 529, 417, 521, 354, 288, + /* 1220 */ 184, 121, 185, 240, 535, 475, 242, 356, 187, 479, + /* 1230 */ 188, 358, 537, 88, 190, 548, 364, 193, 132, 376, + /* 1240 */ 555, 375, 133, 134, 135, 310, 562, 138, 136, 575, + /* 1250 */ 576, 577, 580, 100, 393, 406, 217, 142, 624, 625, + /* 1260 */ 103, 141, 265, 166, 167, 434, 71, 453, 441, 437, + /* 1270 */ 450, 143, 538, 157, 120, 454, 161, 472, 455, 169, + /* 1280 */ 459, 81, 6, 12, 13, 92, 95, 126, 216, 127, + /* 1290 */ 111, 485, 486, 17, 86, 346, 106, 122, 253, 107, + /* 1300 */ 87, 108, 182, 245, 355, 145, 351, 536, 129, 359, + /* 1310 */ 312, 130, 543, 173, 539, 266, 191, 109, 289, 551, + /* 1320 */ 195, 14, 131, 198, 197, 558, 137, 199, 139, 140, + /* 1330 */ 15, 565, 89, 90, 573, 110, 385, 206, 148, 389, + /* 1340 */ 285, 587, }; static const YYCODETYPE yy_lookahead[] = { - /* 0 */ 16, 140, 141, 142, 143, 21, 23, 23, 69, 70, - /* 10 */ 71, 72, 110, 74, 75, 76, 77, 78, 79, 80, - /* 20 */ 81, 82, 83, 84, 1, 2, 42, 43, 73, 74, + /* 0 */ 16, 139, 140, 141, 168, 21, 144, 23, 69, 70, + /* 10 */ 71, 72, 176, 74, 75, 76, 77, 78, 79, 80, + /* 20 */ 81, 82, 83, 84, 78, 79, 42, 43, 73, 74, /* 30 */ 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, - /* 40 */ 58, 162, 163, 164, 60, 61, 62, 63, 64, 65, - /* 50 */ 66, 67, 68, 69, 70, 71, 72, 148, 74, 75, + /* 40 */ 1, 2, 23, 58, 60, 61, 62, 63, 64, 65, + /* 50 */ 66, 67, 68, 69, 70, 71, 72, 147, 74, 75, /* 60 */ 76, 77, 78, 79, 80, 81, 82, 83, 84, 16, - /* 70 */ 88, 88, 88, 84, 92, 22, 219, 220, 221, 222, + /* 70 */ 185, 186, 88, 88, 110, 22, 217, 92, 219, 220, /* 80 */ 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, - /* 90 */ 84, 219, 183, 221, 222, 42, 43, 78, 79, 46, - /* 100 */ 78, 79, 80, 81, 82, 83, 84, 125, 126, 127, - /* 110 */ 170, 239, 16, 60, 61, 62, 63, 64, 65, 66, - /* 120 */ 67, 68, 69, 70, 71, 72, 148, 74, 75, 76, + /* 90 */ 84, 217, 218, 219, 220, 42, 43, 238, 188, 46, + /* 100 */ 78, 79, 80, 81, 82, 83, 84, 88, 89, 124, + /* 110 */ 125, 126, 16, 60, 61, 62, 63, 64, 65, 66, + /* 120 */ 67, 68, 69, 70, 71, 72, 147, 74, 75, 76, /* 130 */ 77, 78, 79, 80, 81, 82, 83, 84, 42, 43, - /* 140 */ 44, 80, 81, 82, 83, 84, 23, 148, 170, 171, - /* 150 */ 19, 83, 84, 156, 23, 170, 60, 61, 62, 63, - /* 160 */ 64, 65, 66, 67, 68, 69, 70, 71, 72, 19, + /* 140 */ 44, 80, 81, 82, 83, 84, 23, 84, 169, 170, + /* 150 */ 19, 164, 165, 166, 23, 23, 60, 61, 62, 63, + /* 160 */ 64, 65, 66, 67, 68, 69, 70, 71, 72, 110, /* 170 */ 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, - /* 180 */ 84, 16, 183, 148, 151, 148, 21, 190, 148, 58, - /* 190 */ 169, 213, 157, 158, 186, 187, 218, 23, 177, 202, - /* 200 */ 203, 78, 79, 166, 167, 208, 161, 42, 43, 78, - /* 210 */ 79, 88, 89, 177, 178, 170, 181, 182, 68, 88, - /* 220 */ 184, 98, 99, 92, 16, 60, 61, 62, 63, 64, - /* 230 */ 65, 66, 67, 68, 69, 70, 71, 72, 22, 74, + /* 180 */ 84, 16, 123, 147, 150, 147, 21, 167, 168, 58, + /* 190 */ 211, 147, 156, 157, 92, 216, 176, 23, 147, 176, + /* 200 */ 177, 78, 79, 165, 166, 103, 183, 42, 43, 78, + /* 210 */ 79, 88, 89, 169, 170, 228, 180, 181, 169, 88, + /* 220 */ 88, 98, 99, 92, 16, 60, 61, 62, 63, 64, + /* 230 */ 65, 66, 67, 68, 69, 70, 71, 72, 147, 74, /* 240 */ 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, - /* 250 */ 42, 43, 78, 0, 1, 2, 125, 126, 127, 226, - /* 260 */ 11, 162, 88, 89, 231, 228, 229, 16, 60, 61, + /* 250 */ 42, 43, 78, 209, 210, 124, 125, 126, 224, 208, + /* 260 */ 169, 170, 88, 89, 230, 227, 228, 16, 60, 61, /* 270 */ 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, - /* 280 */ 72, 148, 74, 75, 76, 77, 78, 79, 80, 81, - /* 290 */ 82, 83, 84, 42, 43, 186, 187, 16, 49, 148, - /* 300 */ 201, 49, 18, 170, 171, 154, 142, 143, 157, 158, - /* 310 */ 182, 60, 61, 62, 63, 64, 65, 66, 67, 68, - /* 320 */ 69, 70, 71, 72, 91, 74, 75, 76, 77, 78, - /* 330 */ 79, 80, 81, 82, 83, 84, 168, 169, 122, 55, - /* 340 */ 132, 16, 16, 110, 16, 177, 20, 20, 99, 100, - /* 350 */ 101, 99, 100, 101, 80, 12, 223, 124, 148, 110, - /* 360 */ 182, 148, 110, 23, 19, 84, 21, 24, 42, 43, - /* 370 */ 148, 90, 91, 92, 93, 94, 95, 96, 94, 166, - /* 380 */ 37, 107, 39, 132, 103, 111, 60, 61, 62, 63, - /* 390 */ 64, 65, 66, 67, 68, 69, 70, 71, 72, 189, - /* 400 */ 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, - /* 410 */ 84, 16, 84, 156, 92, 20, 23, 92, 134, 91, - /* 420 */ 92, 93, 94, 95, 96, 103, 148, 22, 88, 89, - /* 430 */ 148, 103, 210, 106, 156, 108, 109, 42, 43, 144, - /* 440 */ 145, 228, 229, 219, 149, 221, 222, 190, 170, 171, - /* 450 */ 240, 156, 170, 171, 162, 60, 61, 62, 63, 64, - /* 460 */ 65, 66, 67, 68, 69, 70, 71, 72, 190, 74, - /* 470 */ 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, - /* 480 */ 16, 88, 89, 90, 20, 190, 93, 94, 95, 23, - /* 490 */ 131, 213, 133, 201, 212, 90, 218, 104, 93, 94, - /* 500 */ 95, 42, 43, 7, 8, 9, 42, 43, 191, 104, - /* 510 */ 215, 219, 159, 221, 222, 162, 163, 164, 156, 165, - /* 520 */ 166, 167, 63, 64, 60, 61, 62, 63, 64, 65, - /* 530 */ 66, 67, 68, 69, 70, 71, 72, 242, 74, 75, - /* 540 */ 76, 77, 78, 79, 80, 81, 82, 83, 84, 16, - /* 550 */ 148, 92, 190, 20, 88, 89, 148, 90, 156, 148, - /* 560 */ 93, 94, 95, 20, 187, 148, 19, 20, 148, 22, - /* 570 */ 19, 104, 170, 171, 23, 42, 43, 148, 170, 171, - /* 580 */ 114, 170, 171, 229, 99, 100, 101, 170, 171, 148, - /* 590 */ 170, 171, 190, 60, 61, 62, 63, 64, 65, 66, - /* 600 */ 67, 68, 69, 70, 71, 72, 59, 74, 75, 76, - /* 610 */ 77, 78, 79, 80, 81, 82, 83, 84, 16, 211, - /* 620 */ 212, 12, 148, 21, 213, 165, 166, 167, 21, 148, - /* 630 */ 23, 148, 148, 24, 217, 19, 20, 217, 22, 88, - /* 640 */ 89, 157, 158, 214, 42, 43, 37, 148, 39, 106, - /* 650 */ 148, 108, 109, 170, 171, 20, 146, 183, 49, 156, - /* 660 */ 14, 16, 60, 61, 62, 63, 64, 65, 66, 67, - /* 670 */ 68, 69, 70, 71, 72, 59, 74, 75, 76, 77, - /* 680 */ 78, 79, 80, 81, 82, 83, 84, 42, 43, 229, - /* 690 */ 99, 100, 101, 190, 106, 88, 108, 109, 52, 14, - /* 700 */ 54, 148, 156, 162, 16, 60, 61, 62, 63, 64, - /* 710 */ 65, 66, 67, 68, 69, 70, 71, 72, 215, 74, - /* 720 */ 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, - /* 730 */ 42, 43, 245, 246, 148, 148, 190, 52, 193, 54, - /* 740 */ 237, 106, 201, 108, 109, 200, 148, 16, 60, 61, - /* 750 */ 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, - /* 760 */ 72, 215, 74, 75, 76, 77, 78, 79, 80, 81, - /* 770 */ 82, 83, 84, 42, 43, 25, 189, 22, 232, 29, - /* 780 */ 134, 183, 16, 237, 202, 203, 148, 148, 192, 148, - /* 790 */ 16, 41, 61, 62, 63, 64, 65, 66, 67, 68, - /* 800 */ 69, 70, 71, 72, 148, 74, 75, 76, 77, 78, - /* 810 */ 79, 80, 81, 82, 83, 84, 42, 43, 23, 19, - /* 820 */ 23, 183, 148, 23, 148, 148, 170, 171, 189, 19, - /* 830 */ 189, 107, 148, 23, 148, 111, 62, 63, 64, 65, - /* 840 */ 66, 67, 68, 69, 70, 71, 72, 148, 74, 75, - /* 850 */ 76, 77, 78, 79, 80, 81, 82, 83, 84, 16, - /* 860 */ 17, 148, 19, 189, 148, 189, 23, 148, 113, 170, - /* 870 */ 171, 148, 16, 148, 31, 16, 17, 80, 19, 162, - /* 880 */ 148, 115, 23, 88, 89, 88, 89, 210, 88, 89, - /* 890 */ 31, 48, 148, 170, 171, 170, 171, 148, 88, 43, - /* 900 */ 214, 58, 170, 171, 148, 189, 148, 48, 189, 114, - /* 910 */ 19, 148, 243, 244, 170, 171, 148, 58, 148, 170, - /* 920 */ 171, 78, 79, 210, 148, 30, 170, 171, 170, 171, - /* 930 */ 87, 88, 89, 170, 171, 92, 148, 78, 79, 80, - /* 940 */ 170, 171, 125, 126, 148, 50, 87, 88, 89, 16, - /* 950 */ 17, 92, 19, 110, 98, 148, 23, 148, 156, 103, - /* 960 */ 148, 110, 156, 22, 31, 189, 170, 171, 125, 126, - /* 970 */ 127, 128, 129, 130, 20, 124, 156, 170, 171, 170, - /* 980 */ 171, 48, 170, 171, 125, 126, 127, 128, 129, 130, - /* 990 */ 204, 58, 190, 5, 148, 148, 190, 102, 10, 11, - /* 1000 */ 12, 13, 148, 112, 22, 148, 148, 20, 148, 22, - /* 1010 */ 190, 78, 79, 59, 26, 43, 28, 170, 171, 148, - /* 1020 */ 87, 88, 89, 35, 148, 92, 148, 170, 171, 148, - /* 1030 */ 170, 171, 148, 27, 148, 47, 148, 49, 97, 234, - /* 1040 */ 34, 53, 148, 179, 56, 148, 170, 171, 170, 171, - /* 1050 */ 148, 170, 171, 148, 170, 171, 170, 171, 125, 126, - /* 1060 */ 127, 128, 129, 130, 170, 171, 179, 170, 171, 148, - /* 1070 */ 98, 89, 170, 171, 148, 170, 171, 148, 20, 148, - /* 1080 */ 22, 20, 148, 22, 148, 179, 148, 99, 100, 101, - /* 1090 */ 148, 170, 171, 105, 148, 148, 114, 148, 110, 170, - /* 1100 */ 171, 170, 171, 148, 170, 171, 170, 171, 170, 171, - /* 1110 */ 7, 8, 170, 171, 20, 148, 22, 170, 171, 170, - /* 1120 */ 171, 148, 20, 135, 22, 170, 171, 148, 148, 91, - /* 1130 */ 92, 20, 20, 22, 22, 150, 233, 170, 171, 20, - /* 1140 */ 20, 22, 22, 170, 171, 20, 148, 22, 148, 170, - /* 1150 */ 171, 148, 148, 148, 192, 148, 148, 148, 148, 148, - /* 1160 */ 148, 148, 148, 148, 148, 148, 173, 230, 194, 230, - /* 1170 */ 225, 205, 173, 178, 173, 173, 195, 6, 147, 195, - /* 1180 */ 162, 162, 205, 162, 147, 22, 147, 147, 205, 155, - /* 1190 */ 122, 195, 119, 173, 120, 118, 174, 121, 131, 224, - /* 1200 */ 112, 153, 153, 98, 117, 98, 40, 172, 172, 19, - /* 1210 */ 97, 84, 15, 190, 172, 152, 172, 174, 227, 227, - /* 1220 */ 196, 180, 197, 172, 198, 175, 199, 180, 172, 172, - /* 1230 */ 175, 153, 152, 152, 206, 153, 207, 207, 206, 153, - /* 1240 */ 38, 131, 153, 152, 60, 153, 19, 185, 195, 185, - /* 1250 */ 153, 15, 153, 188, 188, 195, 185, 188, 188, 33, - /* 1260 */ 138, 153, 216, 1, 160, 20, 176, 153, 235, 176, - /* 1270 */ 216, 112, 112, 112, 112, 92, 107, 19, 11, 20, - /* 1280 */ 20, 236, 19, 19, 116, 20, 116, 114, 22, 20, - /* 1290 */ 238, 20, 22, 19, 22, 116, 115, 238, 20, 112, - /* 1300 */ 20, 20, 19, 19, 19, 32, 20, 19, 19, 96, - /* 1310 */ 103, 16, 44, 241, 17, 21, 98, 98, 36, 244, - /* 1320 */ 44, 44, 22, 134, 19, 5, 247, 1, 123, 68, - /* 1330 */ 51, 102, 45, 19, 113, 45, 1, 14, 17, 117, - /* 1340 */ 102, 113, 20, 68, 19, 14, 123, 136, 124, 57, - /* 1350 */ 3, 137, 19, 4, + /* 280 */ 72, 23, 74, 75, 76, 77, 78, 79, 80, 81, + /* 290 */ 82, 83, 84, 42, 43, 160, 16, 147, 161, 83, + /* 300 */ 84, 210, 161, 153, 169, 158, 156, 157, 161, 162, + /* 310 */ 163, 60, 61, 62, 63, 64, 65, 66, 67, 68, + /* 320 */ 69, 70, 71, 72, 161, 74, 75, 76, 77, 78, + /* 330 */ 79, 80, 81, 82, 83, 84, 192, 200, 147, 131, + /* 340 */ 16, 200, 16, 199, 20, 169, 88, 89, 90, 185, + /* 350 */ 186, 93, 94, 95, 217, 22, 219, 220, 147, 147, + /* 360 */ 169, 170, 104, 200, 84, 147, 42, 43, 156, 157, + /* 370 */ 90, 91, 92, 93, 94, 95, 96, 164, 165, 166, + /* 380 */ 169, 170, 131, 103, 60, 61, 62, 63, 64, 65, + /* 390 */ 66, 67, 68, 69, 70, 71, 72, 155, 74, 75, + /* 400 */ 76, 77, 78, 79, 80, 81, 82, 83, 84, 16, + /* 410 */ 84, 11, 221, 20, 30, 16, 147, 91, 92, 93, + /* 420 */ 94, 95, 96, 90, 147, 181, 93, 94, 95, 103, + /* 430 */ 212, 189, 155, 27, 50, 42, 43, 104, 169, 170, + /* 440 */ 34, 228, 43, 201, 202, 181, 169, 170, 206, 49, + /* 450 */ 161, 162, 163, 60, 61, 62, 63, 64, 65, 66, + /* 460 */ 67, 68, 69, 70, 71, 72, 189, 74, 75, 76, + /* 470 */ 77, 78, 79, 80, 81, 82, 83, 84, 16, 25, + /* 480 */ 211, 147, 20, 29, 12, 147, 102, 19, 211, 21, + /* 490 */ 147, 141, 147, 216, 144, 41, 24, 98, 20, 99, + /* 500 */ 100, 101, 103, 165, 42, 43, 0, 1, 2, 37, + /* 510 */ 110, 39, 169, 170, 169, 170, 182, 19, 20, 190, + /* 520 */ 22, 49, 60, 61, 62, 63, 64, 65, 66, 67, + /* 530 */ 68, 69, 70, 71, 72, 155, 74, 75, 76, 77, + /* 540 */ 78, 79, 80, 81, 82, 83, 84, 16, 147, 90, + /* 550 */ 20, 20, 93, 94, 95, 147, 155, 59, 215, 225, + /* 560 */ 215, 20, 130, 104, 132, 227, 228, 42, 43, 189, + /* 570 */ 169, 170, 16, 42, 43, 20, 19, 22, 19, 20, + /* 580 */ 23, 22, 18, 147, 106, 147, 108, 109, 63, 64, + /* 590 */ 189, 60, 61, 62, 63, 64, 65, 66, 67, 68, + /* 600 */ 69, 70, 71, 72, 147, 74, 75, 76, 77, 78, + /* 610 */ 79, 80, 81, 82, 83, 84, 16, 92, 59, 55, + /* 620 */ 212, 21, 147, 19, 147, 23, 188, 23, 12, 217, + /* 630 */ 23, 219, 220, 7, 8, 9, 106, 186, 108, 109, + /* 640 */ 24, 147, 42, 43, 208, 88, 89, 106, 92, 108, + /* 650 */ 109, 244, 245, 37, 147, 39, 147, 182, 94, 16, + /* 660 */ 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, + /* 670 */ 70, 71, 72, 145, 74, 75, 76, 77, 78, 79, + /* 680 */ 80, 81, 82, 83, 84, 42, 43, 80, 142, 143, + /* 690 */ 88, 89, 88, 89, 148, 88, 89, 133, 14, 147, + /* 700 */ 225, 155, 16, 60, 61, 62, 63, 64, 65, 66, + /* 710 */ 67, 68, 69, 70, 71, 72, 114, 74, 75, 76, + /* 720 */ 77, 78, 79, 80, 81, 82, 83, 84, 42, 43, + /* 730 */ 201, 202, 147, 147, 182, 189, 52, 147, 54, 147, + /* 740 */ 147, 147, 147, 147, 155, 16, 60, 61, 62, 63, + /* 750 */ 64, 65, 66, 67, 68, 69, 70, 71, 72, 213, + /* 760 */ 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, + /* 770 */ 84, 42, 43, 188, 188, 182, 182, 225, 189, 106, + /* 780 */ 188, 108, 109, 188, 99, 100, 101, 241, 16, 155, + /* 790 */ 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, + /* 800 */ 71, 72, 213, 74, 75, 76, 77, 78, 79, 80, + /* 810 */ 81, 82, 83, 84, 42, 43, 23, 133, 225, 225, + /* 820 */ 21, 225, 23, 189, 239, 236, 99, 100, 101, 22, + /* 830 */ 242, 243, 155, 191, 62, 63, 64, 65, 66, 67, + /* 840 */ 68, 69, 70, 71, 72, 147, 74, 75, 76, 77, + /* 850 */ 78, 79, 80, 81, 82, 83, 84, 16, 17, 22, + /* 860 */ 19, 147, 147, 147, 23, 147, 189, 169, 170, 147, + /* 870 */ 14, 147, 31, 16, 17, 147, 19, 147, 19, 43, + /* 880 */ 23, 88, 89, 169, 170, 169, 170, 88, 31, 48, + /* 890 */ 147, 169, 170, 169, 170, 147, 89, 169, 170, 58, + /* 900 */ 147, 147, 147, 188, 147, 48, 188, 114, 52, 147, + /* 910 */ 54, 19, 147, 124, 125, 58, 147, 169, 170, 78, + /* 920 */ 79, 114, 169, 170, 169, 170, 169, 170, 87, 88, + /* 930 */ 89, 169, 170, 92, 98, 78, 79, 80, 169, 170, + /* 940 */ 91, 147, 188, 22, 87, 88, 89, 16, 17, 92, + /* 950 */ 19, 110, 147, 155, 23, 147, 155, 22, 121, 110, + /* 960 */ 68, 80, 31, 169, 170, 124, 125, 126, 127, 128, + /* 970 */ 129, 112, 123, 208, 169, 170, 107, 169, 170, 48, + /* 980 */ 111, 124, 125, 126, 127, 128, 129, 189, 107, 58, + /* 990 */ 189, 5, 111, 147, 7, 8, 10, 11, 12, 13, + /* 1000 */ 161, 20, 147, 22, 178, 147, 91, 92, 147, 78, + /* 1010 */ 79, 147, 26, 19, 28, 169, 170, 23, 87, 88, + /* 1020 */ 89, 35, 147, 92, 169, 170, 147, 169, 170, 147, + /* 1030 */ 169, 170, 97, 47, 113, 49, 20, 203, 22, 53, + /* 1040 */ 147, 147, 56, 147, 169, 170, 147, 147, 147, 20, + /* 1050 */ 147, 169, 170, 147, 147, 124, 125, 126, 127, 128, + /* 1060 */ 129, 147, 169, 170, 178, 169, 170, 147, 169, 170, + /* 1070 */ 169, 170, 169, 170, 147, 169, 170, 147, 20, 147, + /* 1080 */ 22, 147, 88, 147, 147, 99, 100, 101, 59, 169, + /* 1090 */ 170, 105, 147, 20, 147, 22, 110, 178, 147, 169, + /* 1100 */ 170, 169, 170, 169, 170, 169, 170, 20, 147, 22, + /* 1110 */ 147, 20, 147, 22, 169, 170, 169, 170, 147, 147, + /* 1120 */ 134, 20, 147, 22, 20, 147, 22, 147, 20, 232, + /* 1130 */ 22, 233, 169, 170, 169, 170, 147, 147, 147, 147, + /* 1140 */ 169, 170, 147, 147, 169, 170, 147, 169, 170, 169, + /* 1150 */ 170, 147, 147, 147, 147, 147, 147, 191, 161, 149, + /* 1160 */ 193, 177, 229, 223, 161, 172, 6, 229, 194, 146, + /* 1170 */ 172, 194, 172, 172, 172, 161, 146, 146, 146, 22, + /* 1180 */ 154, 121, 194, 118, 173, 119, 116, 120, 112, 130, + /* 1190 */ 222, 152, 152, 98, 115, 98, 171, 97, 171, 40, + /* 1200 */ 179, 189, 19, 84, 171, 226, 171, 173, 195, 226, + /* 1210 */ 174, 196, 171, 171, 197, 171, 198, 179, 15, 174, + /* 1220 */ 151, 60, 151, 204, 152, 205, 204, 152, 151, 205, + /* 1230 */ 152, 38, 152, 130, 151, 184, 152, 184, 19, 15, + /* 1240 */ 194, 152, 187, 187, 187, 152, 194, 184, 187, 33, + /* 1250 */ 152, 152, 137, 159, 1, 20, 175, 214, 112, 112, + /* 1260 */ 175, 214, 234, 112, 112, 92, 19, 11, 20, 107, + /* 1270 */ 20, 19, 235, 19, 32, 20, 112, 114, 20, 22, + /* 1280 */ 20, 22, 117, 22, 117, 237, 237, 19, 44, 20, + /* 1290 */ 240, 20, 20, 231, 19, 44, 19, 243, 20, 19, + /* 1300 */ 19, 19, 96, 103, 16, 21, 44, 17, 98, 36, + /* 1310 */ 246, 45, 45, 22, 51, 133, 98, 19, 5, 1, + /* 1320 */ 122, 19, 102, 14, 113, 17, 113, 115, 102, 122, + /* 1330 */ 19, 123, 68, 68, 20, 14, 57, 135, 19, 3, + /* 1340 */ 136, 4, }; -#define YY_SHIFT_USE_DFLT (-99) -#define YY_SHIFT_MAX 396 +#define YY_SHIFT_USE_DFLT (-62) +#define YY_SHIFT_MAX 389 static const short yy_shift_ofst[] = { - /* 0 */ 23, 843, 988, -16, 843, 933, 933, 393, 123, 252, - /* 10 */ -98, 96, 933, 933, 933, 933, 933, -45, 249, 174, - /* 20 */ 340, -17, 19, 19, 53, 165, 208, 251, 326, 395, - /* 30 */ 464, 533, 602, 645, 688, 645, 645, 645, 645, 645, - /* 40 */ 645, 645, 645, 645, 645, 645, 645, 645, 645, 645, - /* 50 */ 645, 645, 645, 731, 774, 774, 859, 933, 933, 933, - /* 60 */ 933, 933, 933, 933, 933, 933, 933, 933, 933, 933, - /* 70 */ 933, 933, 933, 933, 933, 933, 933, 933, 933, 933, - /* 80 */ 933, 933, 933, 933, 933, 933, 933, 933, 933, 933, - /* 90 */ 933, 933, 933, 933, 933, 933, 933, -61, -61, 6, - /* 100 */ 6, 281, 22, 61, 856, 284, 340, 340, 68, -17, - /* 110 */ -11, -99, -99, -99, 131, 328, 609, 609, 547, 616, - /* 120 */ 253, 607, 340, 607, 340, 340, 340, 340, 340, 340, - /* 130 */ 340, 340, 340, 340, 340, 340, 340, 340, 340, 340, - /* 140 */ 340, 233, 851, -98, -98, -98, -99, -99, -99, -18, - /* 150 */ -18, 405, 467, 327, 551, 543, 635, 343, 466, 795, - /* 160 */ 800, 797, 496, 340, 340, 274, 340, 340, 810, 340, - /* 170 */ 340, 982, 340, 340, 340, 588, 982, 340, 340, 895, - /* 180 */ 895, 895, 340, 340, 340, 588, 340, 340, 588, 340, - /* 190 */ 750, 485, 340, 340, 588, 340, 340, 340, 588, 340, - /* 200 */ 340, 340, 588, 588, 340, 340, 340, 340, 340, 345, - /* 210 */ 724, 755, -17, 817, 817, 359, 1006, 1006, 766, 1006, - /* 220 */ 972, 1006, -17, 1006, -17, 941, 216, 766, 766, 216, - /* 230 */ 1171, 1171, 1171, 1171, 1163, -98, 1068, 1073, 1074, 1077, - /* 240 */ 1076, 1067, 1088, 1088, 1105, 1087, 1105, 1087, 1107, 1107, - /* 250 */ 1166, 1107, 1113, 1107, 1190, 1127, 1127, 1166, 1107, 1107, - /* 260 */ 1107, 1190, 1197, 1088, 1197, 1088, 1197, 1088, 1088, 1202, - /* 270 */ 1110, 1197, 1088, 1184, 1184, 1227, 1068, 1088, 1236, 1236, - /* 280 */ 1236, 1236, 1068, 1184, 1227, 1088, 1226, 1226, 1088, 1088, - /* 290 */ 1122, -99, -99, -99, -99, -99, 459, 646, 591, 685, - /* 300 */ 891, 325, 987, 1058, 322, 1103, 1038, 1061, 1094, 1102, - /* 310 */ 1111, 1112, 1119, 1120, 150, 1125, 954, 1262, 1245, 1159, - /* 320 */ 1160, 1161, 1162, 1183, 1169, 1258, 1259, 1260, 1263, 1267, - /* 330 */ 1264, 1265, 1266, 1269, 1271, 1270, 1168, 1272, 1170, 1270, - /* 340 */ 1173, 1274, 1179, 1181, 1278, 1187, 1280, 1281, 1273, 1268, - /* 350 */ 1283, 1276, 1284, 1286, 1285, 1288, 1277, 1289, 1213, 1207, - /* 360 */ 1295, 1297, 1294, 1218, 1282, 1279, 1287, 1300, 1290, 1189, - /* 370 */ 1219, 1305, 1320, 1326, 1229, 1261, 1275, 1205, 1314, 1221, - /* 380 */ 1335, 1323, 1222, 1321, 1228, 1238, 1223, 1325, 1224, 1322, - /* 390 */ 1331, 1292, 1211, 1214, 1333, 1347, 1349, + /* 0 */ 39, 841, 986, -16, 841, 931, 931, 258, 123, -36, + /* 10 */ 96, 931, 931, 931, 931, 931, -45, 400, 174, 19, + /* 20 */ 132, -54, -54, 53, 165, 208, 251, 324, 393, 462, + /* 30 */ 531, 600, 643, 686, 643, 643, 643, 643, 643, 643, + /* 40 */ 643, 643, 643, 643, 643, 643, 643, 643, 643, 643, + /* 50 */ 643, 643, 729, 772, 772, 857, 931, 931, 931, 931, + /* 60 */ 931, 931, 931, 931, 931, 931, 931, 931, 931, 931, + /* 70 */ 931, 931, 931, 931, 931, 931, 931, 931, 931, 931, + /* 80 */ 931, 931, 931, 931, 931, 931, 931, 931, 931, 931, + /* 90 */ 931, 931, 931, 931, 931, 931, -61, -61, 6, 6, + /* 100 */ 280, 22, 61, 399, 564, 19, 19, 19, 19, 19, + /* 110 */ 19, 19, 216, 132, 63, -62, -62, -62, 131, 326, + /* 120 */ 472, 472, 498, 559, 506, 799, 19, 799, 19, 19, + /* 130 */ 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, + /* 140 */ 19, 849, 59, -36, -36, -36, -62, -62, -62, -15, + /* 150 */ -15, 333, 459, 478, 557, 530, 541, 616, 602, 793, + /* 160 */ 604, 607, 626, 19, 19, 881, 19, 19, 994, 19, + /* 170 */ 19, 807, 19, 19, 673, 807, 19, 19, 384, 384, + /* 180 */ 384, 19, 19, 673, 19, 19, 673, 19, 454, 685, + /* 190 */ 19, 19, 673, 19, 19, 19, 673, 19, 19, 19, + /* 200 */ 673, 673, 19, 19, 19, 19, 19, 468, 869, 921, + /* 210 */ 132, 789, 789, 432, 406, 406, 406, 836, 406, 132, + /* 220 */ 406, 132, 935, 837, 837, 1160, 1160, 1160, 1160, 1157, + /* 230 */ -36, 1060, 1065, 1066, 1070, 1067, 1059, 1076, 1076, 1095, + /* 240 */ 1079, 1095, 1079, 1097, 1097, 1159, 1097, 1100, 1097, 1183, + /* 250 */ 1119, 1119, 1159, 1097, 1097, 1097, 1183, 1203, 1076, 1203, + /* 260 */ 1076, 1203, 1076, 1076, 1193, 1103, 1203, 1076, 1161, 1161, + /* 270 */ 1219, 1060, 1076, 1224, 1224, 1224, 1224, 1060, 1161, 1219, + /* 280 */ 1076, 1216, 1216, 1076, 1076, 1115, -62, -62, -62, -62, + /* 290 */ -62, -62, 525, 684, 727, 856, 859, 556, 555, 981, + /* 300 */ 102, 987, 915, 1016, 1058, 1073, 1087, 1091, 1101, 1104, + /* 310 */ 892, 1108, 1029, 1253, 1235, 1146, 1147, 1151, 1152, 1173, + /* 320 */ 1162, 1247, 1248, 1250, 1252, 1256, 1254, 1255, 1257, 1258, + /* 330 */ 1260, 1259, 1165, 1261, 1167, 1259, 1163, 1268, 1269, 1164, + /* 340 */ 1271, 1272, 1242, 1244, 1275, 1251, 1277, 1278, 1280, 1281, + /* 350 */ 1262, 1282, 1206, 1200, 1288, 1290, 1284, 1210, 1273, 1263, + /* 360 */ 1266, 1291, 1267, 1182, 1218, 1298, 1313, 1318, 1220, 1264, + /* 370 */ 1265, 1198, 1302, 1211, 1309, 1212, 1308, 1213, 1226, 1207, + /* 380 */ 1311, 1208, 1314, 1321, 1279, 1202, 1204, 1319, 1336, 1337, }; -#define YY_REDUCE_USE_DFLT (-144) -#define YY_REDUCE_MAX 295 +#define YY_REDUCE_USE_DFLT (-165) +#define YY_REDUCE_MAX 291 static const short yy_reduce_ofst[] = { - /* 0 */ -139, 278, 295, 292, 402, -22, 408, 35, 37, 546, - /* 10 */ -3, -128, 133, 282, 411, 417, 420, -143, 503, 213, - /* 20 */ 151, 353, 354, 460, 224, 224, 224, 224, 224, 224, - /* 30 */ 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, - /* 40 */ 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, - /* 50 */ 224, 224, 224, 224, 224, 224, 483, 656, 699, 723, - /* 60 */ 725, 732, 744, 749, 756, 758, 763, 770, 796, 807, - /* 70 */ 809, 812, 847, 857, 860, 876, 878, 881, 884, 886, - /* 80 */ 894, 897, 902, 905, 921, 929, 931, 934, 936, 938, - /* 90 */ 942, 947, 949, 955, 967, 973, 979, 224, 224, 224, - /* 100 */ 224, 168, 224, 224, 36, 33, 210, 484, 224, -121, - /* 110 */ 224, 224, 224, 224, 45, 21, 8, 109, 487, 487, - /* 120 */ 164, 99, 222, 541, -91, -1, 474, 598, 587, 677, - /* 130 */ 638, 429, 713, 639, 641, 674, 676, 716, 719, 686, - /* 140 */ 776, 257, 362, 802, 806, 820, 545, 582, 669, -60, - /* 150 */ -15, 128, 178, 317, 40, 317, 317, 377, 441, 481, - /* 160 */ 499, 502, 510, 553, 586, 596, 502, 684, 717, 768, - /* 170 */ 788, 786, 846, 854, 858, 317, 786, 871, 888, 864, - /* 180 */ 887, 906, 926, 946, 980, 317, 998, 1000, 317, 1003, - /* 190 */ 903, 805, 1004, 1005, 317, 1007, 1008, 1009, 317, 1010, - /* 200 */ 1011, 1012, 317, 317, 1013, 1014, 1015, 1016, 1017, 985, - /* 210 */ 962, 974, 1018, 937, 939, 945, 993, 999, 966, 1001, - /* 220 */ 995, 1002, 1019, 1020, 1021, 1022, 981, 977, 983, 984, - /* 230 */ 1031, 1037, 1039, 1040, 1034, 1023, 996, 1024, 1025, 1026, - /* 240 */ 1027, 975, 1048, 1049, 1028, 1029, 1032, 1030, 1035, 1036, - /* 250 */ 1041, 1042, 1043, 1044, 1050, 991, 992, 1047, 1051, 1056, - /* 260 */ 1057, 1055, 1063, 1078, 1080, 1082, 1081, 1086, 1089, 1033, - /* 270 */ 1045, 1091, 1092, 1062, 1064, 1046, 1053, 1097, 1065, 1066, - /* 280 */ 1069, 1070, 1060, 1071, 1054, 1099, 1052, 1059, 1108, 1114, - /* 290 */ 1072, 1104, 1090, 1093, 1075, 1079, + /* 0 */ -138, 277, 546, 137, 401, -21, 44, 36, 38, 242, + /* 10 */ -141, 191, 91, 269, 343, 345, -126, 589, 338, 150, + /* 20 */ 147, -13, 213, 412, 412, 412, 412, 412, 412, 412, + /* 30 */ 412, 412, 412, 412, 412, 412, 412, 412, 412, 412, + /* 40 */ 412, 412, 412, 412, 412, 412, 412, 412, 412, 412, + /* 50 */ 412, 412, 412, 412, 412, 211, 698, 714, 716, 722, + /* 60 */ 724, 728, 748, 753, 755, 757, 762, 769, 794, 805, + /* 70 */ 808, 846, 855, 858, 861, 875, 882, 893, 896, 899, + /* 80 */ 901, 903, 906, 920, 930, 932, 934, 936, 945, 947, + /* 90 */ 963, 965, 971, 975, 978, 980, 412, 412, 412, 412, + /* 100 */ 20, 412, 412, 23, 34, 334, 475, 552, 593, 594, + /* 110 */ 585, 212, 412, 289, 412, 412, 412, 412, 135, -164, + /* 120 */ -115, 164, 407, 407, 350, 141, 51, 163, 596, -90, + /* 130 */ 436, 218, 765, 438, 586, 592, 595, 715, 718, 408, + /* 140 */ 754, 380, 634, 677, 798, 801, 144, 529, 588, 49, + /* 150 */ 176, 244, 264, 329, 457, 329, 329, 451, 477, 494, + /* 160 */ 507, 509, 528, 590, 730, 642, 509, 743, 839, 864, + /* 170 */ 879, 834, 894, 900, 329, 834, 907, 914, 826, 886, + /* 180 */ 919, 927, 937, 329, 951, 961, 329, 972, 897, 898, + /* 190 */ 989, 990, 329, 991, 992, 995, 329, 996, 999, 1004, + /* 200 */ 329, 329, 1005, 1006, 1007, 1008, 1009, 1010, 966, 967, + /* 210 */ 997, 933, 938, 940, 993, 998, 1000, 984, 1001, 1003, + /* 220 */ 1002, 1014, 1011, 974, 977, 1023, 1030, 1031, 1032, 1026, + /* 230 */ 1012, 988, 1013, 1015, 1017, 1018, 968, 1039, 1040, 1019, + /* 240 */ 1020, 1022, 1024, 1025, 1027, 1021, 1033, 1034, 1035, 1036, + /* 250 */ 979, 983, 1038, 1041, 1042, 1044, 1045, 1069, 1072, 1071, + /* 260 */ 1075, 1077, 1078, 1080, 1028, 1037, 1083, 1084, 1051, 1053, + /* 270 */ 1043, 1046, 1089, 1055, 1056, 1057, 1061, 1052, 1063, 1047, + /* 280 */ 1093, 1048, 1049, 1098, 1099, 1050, 1094, 1081, 1085, 1062, + /* 290 */ 1054, 1064, }; static const YYACTIONTYPE yy_default[] = { - /* 0 */ 603, 832, 913, 719, 913, 832, 913, 913, 859, 913, - /* 10 */ 723, 888, 830, 913, 913, 913, 913, 804, 913, 859, - /* 20 */ 913, 635, 859, 859, 755, 913, 913, 913, 913, 913, - /* 30 */ 913, 913, 913, 756, 913, 834, 829, 825, 827, 826, - /* 40 */ 833, 757, 746, 753, 760, 735, 872, 762, 763, 769, - /* 50 */ 770, 889, 887, 792, 791, 810, 913, 913, 913, 913, - /* 60 */ 913, 913, 913, 913, 913, 913, 913, 913, 913, 913, - /* 70 */ 913, 913, 913, 913, 913, 913, 913, 913, 913, 913, - /* 80 */ 913, 913, 913, 913, 913, 913, 913, 913, 913, 913, - /* 90 */ 913, 913, 913, 913, 913, 913, 913, 794, 816, 793, - /* 100 */ 803, 628, 795, 796, 688, 623, 913, 913, 797, 913, - /* 110 */ 798, 811, 812, 813, 913, 913, 913, 913, 913, 913, - /* 120 */ 603, 719, 913, 719, 913, 913, 913, 913, 913, 913, - /* 130 */ 913, 913, 913, 913, 913, 913, 913, 913, 913, 913, - /* 140 */ 913, 913, 913, 913, 913, 913, 713, 723, 906, 913, - /* 150 */ 913, 679, 913, 913, 913, 913, 913, 913, 913, 913, - /* 160 */ 913, 913, 611, 609, 913, 711, 913, 913, 637, 913, - /* 170 */ 913, 721, 913, 913, 913, 726, 727, 913, 913, 913, - /* 180 */ 913, 913, 913, 913, 913, 625, 913, 913, 700, 913, - /* 190 */ 865, 913, 913, 913, 879, 913, 913, 913, 877, 913, - /* 200 */ 913, 913, 702, 765, 845, 913, 892, 894, 913, 913, - /* 210 */ 711, 720, 913, 913, 913, 828, 749, 749, 737, 749, - /* 220 */ 658, 749, 913, 749, 913, 661, 759, 737, 737, 759, - /* 230 */ 608, 608, 608, 608, 678, 913, 759, 750, 752, 742, - /* 240 */ 754, 913, 728, 728, 736, 741, 736, 741, 690, 690, - /* 250 */ 675, 690, 661, 690, 838, 842, 842, 675, 690, 690, - /* 260 */ 690, 838, 620, 728, 620, 728, 620, 728, 728, 869, - /* 270 */ 871, 620, 728, 692, 692, 771, 759, 728, 699, 699, - /* 280 */ 699, 699, 759, 692, 771, 728, 891, 891, 728, 728, - /* 290 */ 899, 645, 663, 663, 906, 911, 913, 913, 913, 913, - /* 300 */ 778, 913, 913, 913, 913, 913, 913, 913, 913, 913, - /* 310 */ 913, 913, 913, 913, 852, 913, 913, 913, 913, 783, - /* 320 */ 779, 913, 780, 913, 705, 913, 913, 913, 913, 913, - /* 330 */ 913, 913, 913, 913, 913, 831, 913, 743, 913, 751, - /* 340 */ 913, 913, 913, 913, 913, 913, 913, 913, 913, 913, - /* 350 */ 913, 913, 913, 913, 913, 913, 913, 913, 913, 913, - /* 360 */ 913, 913, 913, 913, 913, 913, 867, 868, 913, 913, - /* 370 */ 913, 913, 913, 913, 913, 913, 913, 913, 913, 913, - /* 380 */ 913, 913, 913, 913, 913, 913, 913, 913, 913, 913, - /* 390 */ 913, 898, 913, 913, 901, 604, 913, 599, 601, 602, - /* 400 */ 606, 607, 610, 632, 633, 634, 612, 613, 614, 615, - /* 410 */ 616, 617, 618, 624, 626, 644, 646, 630, 648, 709, - /* 420 */ 710, 775, 703, 704, 708, 631, 786, 777, 781, 782, - /* 430 */ 784, 785, 799, 800, 802, 808, 815, 818, 801, 806, - /* 440 */ 807, 809, 814, 817, 706, 707, 821, 638, 639, 642, - /* 450 */ 643, 855, 857, 856, 858, 641, 640, 787, 790, 823, - /* 460 */ 824, 880, 881, 882, 883, 884, 819, 729, 822, 805, - /* 470 */ 744, 747, 748, 745, 712, 722, 731, 732, 733, 734, - /* 480 */ 717, 718, 724, 740, 773, 774, 738, 739, 725, 714, - /* 490 */ 715, 716, 820, 776, 788, 789, 649, 650, 783, 651, - /* 500 */ 652, 653, 691, 694, 695, 696, 654, 673, 676, 677, - /* 510 */ 655, 662, 656, 657, 664, 665, 666, 669, 670, 671, - /* 520 */ 672, 667, 668, 839, 840, 843, 841, 659, 660, 674, - /* 530 */ 647, 636, 629, 680, 683, 684, 685, 686, 687, 689, - /* 540 */ 681, 682, 627, 619, 621, 730, 861, 870, 866, 862, - /* 550 */ 863, 864, 622, 835, 836, 693, 767, 768, 860, 873, - /* 560 */ 875, 772, 876, 878, 874, 903, 697, 698, 701, 844, - /* 570 */ 885, 758, 761, 764, 766, 846, 847, 848, 849, 850, - /* 580 */ 853, 854, 851, 886, 890, 893, 895, 896, 897, 900, - /* 590 */ 902, 907, 908, 909, 912, 910, 605, 600, + /* 0 */ 595, 820, 902, 710, 902, 820, 902, 902, 848, 714, + /* 10 */ 877, 818, 902, 902, 902, 902, 792, 902, 848, 902, + /* 20 */ 626, 848, 848, 743, 902, 902, 902, 902, 902, 902, + /* 30 */ 902, 902, 744, 902, 822, 817, 813, 815, 814, 821, + /* 40 */ 745, 734, 741, 748, 726, 861, 750, 751, 757, 758, + /* 50 */ 878, 876, 780, 779, 798, 902, 902, 902, 902, 902, + /* 60 */ 902, 902, 902, 902, 902, 902, 902, 902, 902, 902, + /* 70 */ 902, 902, 902, 902, 902, 902, 902, 902, 902, 902, + /* 80 */ 902, 902, 902, 902, 902, 902, 902, 902, 902, 902, + /* 90 */ 902, 902, 902, 902, 902, 902, 782, 804, 781, 791, + /* 100 */ 619, 783, 784, 679, 614, 902, 902, 902, 902, 902, + /* 110 */ 902, 902, 785, 902, 786, 799, 800, 801, 902, 902, + /* 120 */ 902, 902, 902, 902, 595, 710, 902, 710, 902, 902, + /* 130 */ 902, 902, 902, 902, 902, 902, 902, 902, 902, 902, + /* 140 */ 902, 902, 902, 902, 902, 902, 704, 714, 895, 902, + /* 150 */ 902, 670, 902, 902, 902, 902, 902, 902, 902, 902, + /* 160 */ 902, 902, 602, 600, 902, 702, 902, 902, 628, 902, + /* 170 */ 902, 712, 902, 902, 717, 718, 902, 902, 902, 902, + /* 180 */ 902, 902, 902, 616, 902, 902, 691, 902, 854, 902, + /* 190 */ 902, 902, 868, 902, 902, 902, 866, 902, 902, 902, + /* 200 */ 693, 753, 834, 902, 881, 883, 902, 902, 702, 711, + /* 210 */ 902, 902, 902, 816, 737, 737, 737, 649, 737, 902, + /* 220 */ 737, 902, 652, 747, 747, 599, 599, 599, 599, 669, + /* 230 */ 902, 747, 738, 740, 730, 742, 902, 719, 719, 727, + /* 240 */ 729, 727, 729, 681, 681, 666, 681, 652, 681, 826, + /* 250 */ 831, 831, 666, 681, 681, 681, 826, 611, 719, 611, + /* 260 */ 719, 611, 719, 719, 858, 860, 611, 719, 683, 683, + /* 270 */ 759, 747, 719, 690, 690, 690, 690, 747, 683, 759, + /* 280 */ 719, 880, 880, 719, 719, 888, 636, 654, 654, 863, + /* 290 */ 895, 900, 902, 902, 902, 902, 766, 902, 902, 902, + /* 300 */ 902, 902, 902, 902, 902, 902, 902, 902, 902, 902, + /* 310 */ 841, 902, 902, 902, 902, 771, 767, 902, 768, 902, + /* 320 */ 696, 902, 902, 902, 902, 902, 902, 902, 902, 902, + /* 330 */ 902, 819, 902, 731, 902, 739, 902, 902, 902, 902, + /* 340 */ 902, 902, 902, 902, 902, 902, 902, 902, 902, 902, + /* 350 */ 902, 902, 902, 902, 902, 902, 902, 902, 902, 902, + /* 360 */ 856, 857, 902, 902, 902, 902, 902, 902, 902, 902, + /* 370 */ 902, 902, 902, 902, 902, 902, 902, 902, 902, 902, + /* 380 */ 902, 902, 902, 902, 887, 902, 902, 890, 596, 902, + /* 390 */ 590, 593, 592, 594, 598, 601, 623, 624, 625, 603, + /* 400 */ 604, 605, 606, 607, 608, 609, 615, 617, 635, 637, + /* 410 */ 621, 639, 700, 701, 763, 694, 695, 699, 622, 774, + /* 420 */ 765, 769, 770, 772, 773, 787, 788, 790, 796, 803, + /* 430 */ 806, 789, 794, 795, 797, 802, 805, 697, 698, 809, + /* 440 */ 629, 630, 633, 634, 844, 846, 845, 847, 632, 631, + /* 450 */ 775, 778, 811, 812, 869, 870, 871, 872, 873, 807, + /* 460 */ 720, 810, 793, 732, 735, 736, 733, 703, 713, 722, + /* 470 */ 723, 724, 725, 708, 709, 715, 728, 761, 762, 716, + /* 480 */ 705, 706, 707, 808, 764, 776, 777, 640, 641, 771, + /* 490 */ 642, 643, 644, 682, 685, 686, 687, 645, 664, 667, + /* 500 */ 668, 646, 653, 647, 648, 655, 656, 657, 660, 661, + /* 510 */ 662, 663, 658, 659, 827, 828, 832, 830, 829, 650, + /* 520 */ 651, 665, 638, 627, 620, 671, 674, 675, 676, 677, + /* 530 */ 678, 680, 672, 673, 618, 610, 612, 721, 850, 859, + /* 540 */ 855, 851, 852, 853, 613, 823, 824, 684, 755, 756, + /* 550 */ 849, 862, 864, 760, 865, 867, 892, 688, 689, 692, + /* 560 */ 833, 874, 746, 749, 752, 754, 835, 836, 837, 838, + /* 570 */ 839, 842, 843, 840, 875, 879, 882, 884, 885, 886, + /* 580 */ 889, 891, 896, 897, 898, 901, 899, 597, 591, }; #define YY_SZ_ACTTAB (int)(sizeof(yy_action)/sizeof(yy_action[0])) @@ -79417,7 +73483,7 @@ static const YYACTIONTYPE yy_default[] = { ** ** %fallback ID X Y Z. ** -** appears in the grammar, then ID becomes a fallback token for X, Y, +** appears in the grammer, then ID becomes a fallback token for X, Y, ** and Z. Whenever one of the tokens X, Y, or Z is input to the parser ** but it does not parse, the type of the token is changed to ID and ** the parse is retried before an error is thrown. @@ -79539,10 +73605,9 @@ static const YYCODETYPE yyFallback[] = { 0, /* DOT => nothing */ 0, /* FROM => nothing */ 0, /* JOIN => nothing */ - 0, /* INDEXED => nothing */ - 0, /* BY => nothing */ 0, /* USING => nothing */ 0, /* ORDER => nothing */ + 0, /* BY => nothing */ 0, /* GROUP => nothing */ 0, /* HAVING => nothing */ 0, /* LIMIT => nothing */ @@ -79579,11 +73644,11 @@ static const YYCODETYPE yyFallback[] = { ** It is sometimes called the "minor" token. */ struct yyStackEntry { - YYACTIONTYPE stateno; /* The state-number */ - YYCODETYPE major; /* The major token value. This is the code - ** number for the token at this stack level */ - YYMINORTYPE minor; /* The user-supplied minor token value. This - ** is the value of the token */ + int stateno; /* The state-number */ + int major; /* The major token value. This is the code + ** number for the token at this stack level */ + YYMINORTYPE minor; /* The user-supplied minor token value. This + ** is the value of the token */ }; typedef struct yyStackEntry yyStackEntry; @@ -79591,9 +73656,6 @@ typedef struct yyStackEntry yyStackEntry; ** the following structure */ struct yyParser { int yyidx; /* Index of top element in stack */ -#ifdef YYTRACKMAXSTACKDEPTH - int yyidxMax; /* Maximum value of yyidx */ -#endif int yyerrcnt; /* Shifts left before out of the error */ sqlite3ParserARG_SDECL /* A place to hold %extra_argument */ #if YYSTACKDEPTH<=0 @@ -79668,40 +73730,40 @@ static const char *const yyTokenName[] = { "UPDATE", "INSERT", "SET", "DEFERRABLE", "FOREIGN", "DROP", "UNION", "ALL", "EXCEPT", "INTERSECT", "SELECT", "DISTINCT", - "DOT", "FROM", "JOIN", "INDEXED", - "BY", "USING", "ORDER", "GROUP", - "HAVING", "LIMIT", "WHERE", "INTO", - "VALUES", "INTEGER", "FLOAT", "BLOB", - "REGISTER", "VARIABLE", "CASE", "WHEN", - "THEN", "ELSE", "INDEX", "ALTER", - "TO", "ADD", "COLUMNKW", "error", - "input", "cmdlist", "ecmd", "explain", - "cmdx", "cmd", "transtype", "trans_opt", - "nm", "create_table", "create_table_args", "temp", - "ifnotexists", "dbnm", "columnlist", "conslist_opt", - "select", "column", "columnid", "type", - "carglist", "id", "ids", "typetoken", - "typename", "signed", "plus_num", "minus_num", - "carg", "ccons", "term", "expr", - "onconf", "sortorder", "autoinc", "idxlist_opt", - "refargs", "defer_subclause", "refarg", "refact", - "init_deferred_pred_opt", "conslist", "tcons", "idxlist", - "defer_subclause_opt", "orconf", "resolvetype", "raisetype", - "ifexists", "fullname", "oneselect", "multiselect_op", - "distinct", "selcollist", "from", "where_opt", - "groupby_opt", "having_opt", "orderby_opt", "limit_opt", - "sclp", "as", "seltablist", "stl_prefix", - "joinop", "indexed_opt", "on_opt", "using_opt", - "seltablist_paren", "joinop2", "inscollist", "sortlist", - "sortitem", "nexprlist", "setlist", "insert_cmd", - "inscollist_opt", "itemlist", "exprlist", "likeop", - "escape", "between_op", "in_op", "case_operand", - "case_exprlist", "case_else", "uniqueflag", "collate", - "nmnum", "plus_opt", "number", "trigger_decl", - "trigger_cmd_list", "trigger_time", "trigger_event", "foreach_clause", - "when_clause", "trigger_cmd", "database_kw_opt", "key_opt", - "add_column_fullname", "kwcolumn_opt", "create_vtab", "vtabarglist", - "vtabarg", "vtabargtoken", "lp", "anylist", + "DOT", "FROM", "JOIN", "USING", + "ORDER", "BY", "GROUP", "HAVING", + "LIMIT", "WHERE", "INTO", "VALUES", + "INTEGER", "FLOAT", "BLOB", "REGISTER", + "VARIABLE", "CASE", "WHEN", "THEN", + "ELSE", "INDEX", "ALTER", "TO", + "ADD", "COLUMNKW", "error", "input", + "cmdlist", "ecmd", "cmdx", "cmd", + "explain", "transtype", "trans_opt", "nm", + "create_table", "create_table_args", "temp", "ifnotexists", + "dbnm", "columnlist", "conslist_opt", "select", + "column", "columnid", "type", "carglist", + "id", "ids", "typetoken", "typename", + "signed", "plus_num", "minus_num", "carg", + "ccons", "term", "expr", "onconf", + "sortorder", "autoinc", "idxlist_opt", "refargs", + "defer_subclause", "refarg", "refact", "init_deferred_pred_opt", + "conslist", "tcons", "idxlist", "defer_subclause_opt", + "orconf", "resolvetype", "raisetype", "ifexists", + "fullname", "oneselect", "multiselect_op", "distinct", + "selcollist", "from", "where_opt", "groupby_opt", + "having_opt", "orderby_opt", "limit_opt", "sclp", + "as", "seltablist", "stl_prefix", "joinop", + "on_opt", "using_opt", "seltablist_paren", "joinop2", + "inscollist", "sortlist", "sortitem", "nexprlist", + "setlist", "insert_cmd", "inscollist_opt", "itemlist", + "exprlist", "likeop", "escape", "between_op", + "in_op", "case_operand", "case_exprlist", "case_else", + "uniqueflag", "idxitem", "collate", "nmnum", + "plus_opt", "number", "trigger_decl", "trigger_cmd_list", + "trigger_time", "trigger_event", "foreach_clause", "when_clause", + "trigger_cmd", "database_kw_opt", "key_opt", "add_column_fullname", + "kwcolumn_opt", "create_vtab", "vtabarglist", "vtabarg", + "vtabargtoken", "lp", "anylist", }; #endif /* NDEBUG */ @@ -79712,12 +73774,12 @@ static const char *const yyRuleName[] = { /* 0 */ "input ::= cmdlist", /* 1 */ "cmdlist ::= cmdlist ecmd", /* 2 */ "cmdlist ::= ecmd", - /* 3 */ "ecmd ::= SEMI", - /* 4 */ "ecmd ::= explain cmdx SEMI", - /* 5 */ "explain ::=", - /* 6 */ "explain ::= EXPLAIN", - /* 7 */ "explain ::= EXPLAIN QUERY PLAN", - /* 8 */ "cmdx ::= cmd", + /* 3 */ "cmdx ::= cmd", + /* 4 */ "ecmd ::= SEMI", + /* 5 */ "ecmd ::= explain cmdx SEMI", + /* 6 */ "explain ::=", + /* 7 */ "explain ::= EXPLAIN", + /* 8 */ "explain ::= EXPLAIN QUERY PLAN", /* 9 */ "cmd ::= BEGIN transtype trans_opt", /* 10 */ "trans_opt ::=", /* 11 */ "trans_opt ::= TRANSACTION", @@ -79835,7 +73897,7 @@ static const char *const yyRuleName[] = { /* 123 */ "from ::= FROM seltablist", /* 124 */ "stl_prefix ::= seltablist joinop", /* 125 */ "stl_prefix ::=", - /* 126 */ "seltablist ::= stl_prefix nm dbnm as indexed_opt on_opt using_opt", + /* 126 */ "seltablist ::= stl_prefix nm dbnm as on_opt using_opt", /* 127 */ "seltablist ::= stl_prefix LP seltablist_paren RP as on_opt using_opt", /* 128 */ "seltablist_paren ::= select", /* 129 */ "seltablist_paren ::= seltablist", @@ -79848,182 +73910,180 @@ static const char *const yyRuleName[] = { /* 136 */ "joinop ::= JOIN_KW nm nm JOIN", /* 137 */ "on_opt ::= ON expr", /* 138 */ "on_opt ::=", - /* 139 */ "indexed_opt ::=", - /* 140 */ "indexed_opt ::= INDEXED BY nm", - /* 141 */ "indexed_opt ::= NOT INDEXED", - /* 142 */ "using_opt ::= USING LP inscollist RP", - /* 143 */ "using_opt ::=", - /* 144 */ "orderby_opt ::=", - /* 145 */ "orderby_opt ::= ORDER BY sortlist", - /* 146 */ "sortlist ::= sortlist COMMA sortitem sortorder", - /* 147 */ "sortlist ::= sortitem sortorder", - /* 148 */ "sortitem ::= expr", - /* 149 */ "sortorder ::= ASC", - /* 150 */ "sortorder ::= DESC", - /* 151 */ "sortorder ::=", - /* 152 */ "groupby_opt ::=", - /* 153 */ "groupby_opt ::= GROUP BY nexprlist", - /* 154 */ "having_opt ::=", - /* 155 */ "having_opt ::= HAVING expr", - /* 156 */ "limit_opt ::=", - /* 157 */ "limit_opt ::= LIMIT expr", - /* 158 */ "limit_opt ::= LIMIT expr OFFSET expr", - /* 159 */ "limit_opt ::= LIMIT expr COMMA expr", - /* 160 */ "cmd ::= DELETE FROM fullname indexed_opt where_opt", - /* 161 */ "where_opt ::=", - /* 162 */ "where_opt ::= WHERE expr", - /* 163 */ "cmd ::= UPDATE orconf fullname indexed_opt SET setlist where_opt", - /* 164 */ "setlist ::= setlist COMMA nm EQ expr", - /* 165 */ "setlist ::= nm EQ expr", - /* 166 */ "cmd ::= insert_cmd INTO fullname inscollist_opt VALUES LP itemlist RP", - /* 167 */ "cmd ::= insert_cmd INTO fullname inscollist_opt select", - /* 168 */ "cmd ::= insert_cmd INTO fullname inscollist_opt DEFAULT VALUES", - /* 169 */ "insert_cmd ::= INSERT orconf", - /* 170 */ "insert_cmd ::= REPLACE", - /* 171 */ "itemlist ::= itemlist COMMA expr", - /* 172 */ "itemlist ::= expr", - /* 173 */ "inscollist_opt ::=", - /* 174 */ "inscollist_opt ::= LP inscollist RP", - /* 175 */ "inscollist ::= inscollist COMMA nm", - /* 176 */ "inscollist ::= nm", - /* 177 */ "expr ::= term", - /* 178 */ "expr ::= LP expr RP", - /* 179 */ "term ::= NULL", - /* 180 */ "expr ::= ID", - /* 181 */ "expr ::= JOIN_KW", - /* 182 */ "expr ::= nm DOT nm", - /* 183 */ "expr ::= nm DOT nm DOT nm", - /* 184 */ "term ::= INTEGER|FLOAT|BLOB", - /* 185 */ "term ::= STRING", - /* 186 */ "expr ::= REGISTER", - /* 187 */ "expr ::= VARIABLE", - /* 188 */ "expr ::= expr COLLATE ids", - /* 189 */ "expr ::= CAST LP expr AS typetoken RP", - /* 190 */ "expr ::= ID LP distinct exprlist RP", - /* 191 */ "expr ::= ID LP STAR RP", - /* 192 */ "term ::= CTIME_KW", - /* 193 */ "expr ::= expr AND expr", - /* 194 */ "expr ::= expr OR expr", - /* 195 */ "expr ::= expr LT|GT|GE|LE expr", - /* 196 */ "expr ::= expr EQ|NE expr", - /* 197 */ "expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr", - /* 198 */ "expr ::= expr PLUS|MINUS expr", - /* 199 */ "expr ::= expr STAR|SLASH|REM expr", - /* 200 */ "expr ::= expr CONCAT expr", - /* 201 */ "likeop ::= LIKE_KW", - /* 202 */ "likeop ::= NOT LIKE_KW", - /* 203 */ "likeop ::= MATCH", - /* 204 */ "likeop ::= NOT MATCH", - /* 205 */ "escape ::= ESCAPE expr", - /* 206 */ "escape ::=", - /* 207 */ "expr ::= expr likeop expr escape", - /* 208 */ "expr ::= expr ISNULL|NOTNULL", - /* 209 */ "expr ::= expr IS NULL", - /* 210 */ "expr ::= expr NOT NULL", - /* 211 */ "expr ::= expr IS NOT NULL", - /* 212 */ "expr ::= NOT expr", - /* 213 */ "expr ::= BITNOT expr", - /* 214 */ "expr ::= MINUS expr", - /* 215 */ "expr ::= PLUS expr", - /* 216 */ "between_op ::= BETWEEN", - /* 217 */ "between_op ::= NOT BETWEEN", - /* 218 */ "expr ::= expr between_op expr AND expr", - /* 219 */ "in_op ::= IN", - /* 220 */ "in_op ::= NOT IN", - /* 221 */ "expr ::= expr in_op LP exprlist RP", - /* 222 */ "expr ::= LP select RP", - /* 223 */ "expr ::= expr in_op LP select RP", - /* 224 */ "expr ::= expr in_op nm dbnm", - /* 225 */ "expr ::= EXISTS LP select RP", - /* 226 */ "expr ::= CASE case_operand case_exprlist case_else END", - /* 227 */ "case_exprlist ::= case_exprlist WHEN expr THEN expr", - /* 228 */ "case_exprlist ::= WHEN expr THEN expr", - /* 229 */ "case_else ::= ELSE expr", - /* 230 */ "case_else ::=", - /* 231 */ "case_operand ::= expr", - /* 232 */ "case_operand ::=", - /* 233 */ "exprlist ::= nexprlist", - /* 234 */ "exprlist ::=", - /* 235 */ "nexprlist ::= nexprlist COMMA expr", - /* 236 */ "nexprlist ::= expr", - /* 237 */ "cmd ::= CREATE uniqueflag INDEX ifnotexists nm dbnm ON nm LP idxlist RP", - /* 238 */ "uniqueflag ::= UNIQUE", - /* 239 */ "uniqueflag ::=", - /* 240 */ "idxlist_opt ::=", - /* 241 */ "idxlist_opt ::= LP idxlist RP", - /* 242 */ "idxlist ::= idxlist COMMA nm collate sortorder", - /* 243 */ "idxlist ::= nm collate sortorder", - /* 244 */ "collate ::=", - /* 245 */ "collate ::= COLLATE ids", - /* 246 */ "cmd ::= DROP INDEX ifexists fullname", - /* 247 */ "cmd ::= VACUUM", - /* 248 */ "cmd ::= VACUUM nm", - /* 249 */ "cmd ::= PRAGMA nm dbnm EQ nmnum", - /* 250 */ "cmd ::= PRAGMA nm dbnm EQ ON", - /* 251 */ "cmd ::= PRAGMA nm dbnm EQ DELETE", - /* 252 */ "cmd ::= PRAGMA nm dbnm EQ minus_num", - /* 253 */ "cmd ::= PRAGMA nm dbnm LP nmnum RP", - /* 254 */ "cmd ::= PRAGMA nm dbnm", - /* 255 */ "nmnum ::= plus_num", - /* 256 */ "nmnum ::= nm", - /* 257 */ "plus_num ::= plus_opt number", - /* 258 */ "minus_num ::= MINUS number", - /* 259 */ "number ::= INTEGER|FLOAT", - /* 260 */ "plus_opt ::= PLUS", - /* 261 */ "plus_opt ::=", - /* 262 */ "cmd ::= CREATE trigger_decl BEGIN trigger_cmd_list END", - /* 263 */ "trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause", - /* 264 */ "trigger_time ::= BEFORE", - /* 265 */ "trigger_time ::= AFTER", - /* 266 */ "trigger_time ::= INSTEAD OF", - /* 267 */ "trigger_time ::=", - /* 268 */ "trigger_event ::= DELETE|INSERT", - /* 269 */ "trigger_event ::= UPDATE", - /* 270 */ "trigger_event ::= UPDATE OF inscollist", - /* 271 */ "foreach_clause ::=", - /* 272 */ "foreach_clause ::= FOR EACH ROW", - /* 273 */ "when_clause ::=", - /* 274 */ "when_clause ::= WHEN expr", - /* 275 */ "trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI", - /* 276 */ "trigger_cmd_list ::= trigger_cmd SEMI", - /* 277 */ "trigger_cmd ::= UPDATE orconf nm SET setlist where_opt", - /* 278 */ "trigger_cmd ::= insert_cmd INTO nm inscollist_opt VALUES LP itemlist RP", - /* 279 */ "trigger_cmd ::= insert_cmd INTO nm inscollist_opt select", - /* 280 */ "trigger_cmd ::= DELETE FROM nm where_opt", - /* 281 */ "trigger_cmd ::= select", - /* 282 */ "expr ::= RAISE LP IGNORE RP", - /* 283 */ "expr ::= RAISE LP raisetype COMMA nm RP", - /* 284 */ "raisetype ::= ROLLBACK", - /* 285 */ "raisetype ::= ABORT", - /* 286 */ "raisetype ::= FAIL", - /* 287 */ "cmd ::= DROP TRIGGER ifexists fullname", - /* 288 */ "cmd ::= ATTACH database_kw_opt expr AS expr key_opt", - /* 289 */ "cmd ::= DETACH database_kw_opt expr", - /* 290 */ "key_opt ::=", - /* 291 */ "key_opt ::= KEY expr", - /* 292 */ "database_kw_opt ::= DATABASE", - /* 293 */ "database_kw_opt ::=", - /* 294 */ "cmd ::= REINDEX", - /* 295 */ "cmd ::= REINDEX nm dbnm", - /* 296 */ "cmd ::= ANALYZE", - /* 297 */ "cmd ::= ANALYZE nm dbnm", - /* 298 */ "cmd ::= ALTER TABLE fullname RENAME TO nm", - /* 299 */ "cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt column", - /* 300 */ "add_column_fullname ::= fullname", - /* 301 */ "kwcolumn_opt ::=", - /* 302 */ "kwcolumn_opt ::= COLUMNKW", - /* 303 */ "cmd ::= create_vtab", - /* 304 */ "cmd ::= create_vtab LP vtabarglist RP", - /* 305 */ "create_vtab ::= CREATE VIRTUAL TABLE nm dbnm USING nm", - /* 306 */ "vtabarglist ::= vtabarg", - /* 307 */ "vtabarglist ::= vtabarglist COMMA vtabarg", - /* 308 */ "vtabarg ::=", - /* 309 */ "vtabarg ::= vtabarg vtabargtoken", - /* 310 */ "vtabargtoken ::= ANY", - /* 311 */ "vtabargtoken ::= lp anylist RP", - /* 312 */ "lp ::= LP", - /* 313 */ "anylist ::=", - /* 314 */ "anylist ::= anylist ANY", + /* 139 */ "using_opt ::= USING LP inscollist RP", + /* 140 */ "using_opt ::=", + /* 141 */ "orderby_opt ::=", + /* 142 */ "orderby_opt ::= ORDER BY sortlist", + /* 143 */ "sortlist ::= sortlist COMMA sortitem sortorder", + /* 144 */ "sortlist ::= sortitem sortorder", + /* 145 */ "sortitem ::= expr", + /* 146 */ "sortorder ::= ASC", + /* 147 */ "sortorder ::= DESC", + /* 148 */ "sortorder ::=", + /* 149 */ "groupby_opt ::=", + /* 150 */ "groupby_opt ::= GROUP BY nexprlist", + /* 151 */ "having_opt ::=", + /* 152 */ "having_opt ::= HAVING expr", + /* 153 */ "limit_opt ::=", + /* 154 */ "limit_opt ::= LIMIT expr", + /* 155 */ "limit_opt ::= LIMIT expr OFFSET expr", + /* 156 */ "limit_opt ::= LIMIT expr COMMA expr", + /* 157 */ "cmd ::= DELETE FROM fullname where_opt", + /* 158 */ "where_opt ::=", + /* 159 */ "where_opt ::= WHERE expr", + /* 160 */ "cmd ::= UPDATE orconf fullname SET setlist where_opt", + /* 161 */ "setlist ::= setlist COMMA nm EQ expr", + /* 162 */ "setlist ::= nm EQ expr", + /* 163 */ "cmd ::= insert_cmd INTO fullname inscollist_opt VALUES LP itemlist RP", + /* 164 */ "cmd ::= insert_cmd INTO fullname inscollist_opt select", + /* 165 */ "cmd ::= insert_cmd INTO fullname inscollist_opt DEFAULT VALUES", + /* 166 */ "insert_cmd ::= INSERT orconf", + /* 167 */ "insert_cmd ::= REPLACE", + /* 168 */ "itemlist ::= itemlist COMMA expr", + /* 169 */ "itemlist ::= expr", + /* 170 */ "inscollist_opt ::=", + /* 171 */ "inscollist_opt ::= LP inscollist RP", + /* 172 */ "inscollist ::= inscollist COMMA nm", + /* 173 */ "inscollist ::= nm", + /* 174 */ "expr ::= term", + /* 175 */ "expr ::= LP expr RP", + /* 176 */ "term ::= NULL", + /* 177 */ "expr ::= ID", + /* 178 */ "expr ::= JOIN_KW", + /* 179 */ "expr ::= nm DOT nm", + /* 180 */ "expr ::= nm DOT nm DOT nm", + /* 181 */ "term ::= INTEGER|FLOAT|BLOB", + /* 182 */ "term ::= STRING", + /* 183 */ "expr ::= REGISTER", + /* 184 */ "expr ::= VARIABLE", + /* 185 */ "expr ::= expr COLLATE ids", + /* 186 */ "expr ::= CAST LP expr AS typetoken RP", + /* 187 */ "expr ::= ID LP distinct exprlist RP", + /* 188 */ "expr ::= ID LP STAR RP", + /* 189 */ "term ::= CTIME_KW", + /* 190 */ "expr ::= expr AND expr", + /* 191 */ "expr ::= expr OR expr", + /* 192 */ "expr ::= expr LT|GT|GE|LE expr", + /* 193 */ "expr ::= expr EQ|NE expr", + /* 194 */ "expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr", + /* 195 */ "expr ::= expr PLUS|MINUS expr", + /* 196 */ "expr ::= expr STAR|SLASH|REM expr", + /* 197 */ "expr ::= expr CONCAT expr", + /* 198 */ "likeop ::= LIKE_KW", + /* 199 */ "likeop ::= NOT LIKE_KW", + /* 200 */ "likeop ::= MATCH", + /* 201 */ "likeop ::= NOT MATCH", + /* 202 */ "escape ::= ESCAPE expr", + /* 203 */ "escape ::=", + /* 204 */ "expr ::= expr likeop expr escape", + /* 205 */ "expr ::= expr ISNULL|NOTNULL", + /* 206 */ "expr ::= expr IS NULL", + /* 207 */ "expr ::= expr NOT NULL", + /* 208 */ "expr ::= expr IS NOT NULL", + /* 209 */ "expr ::= NOT expr", + /* 210 */ "expr ::= BITNOT expr", + /* 211 */ "expr ::= MINUS expr", + /* 212 */ "expr ::= PLUS expr", + /* 213 */ "between_op ::= BETWEEN", + /* 214 */ "between_op ::= NOT BETWEEN", + /* 215 */ "expr ::= expr between_op expr AND expr", + /* 216 */ "in_op ::= IN", + /* 217 */ "in_op ::= NOT IN", + /* 218 */ "expr ::= expr in_op LP exprlist RP", + /* 219 */ "expr ::= LP select RP", + /* 220 */ "expr ::= expr in_op LP select RP", + /* 221 */ "expr ::= expr in_op nm dbnm", + /* 222 */ "expr ::= EXISTS LP select RP", + /* 223 */ "expr ::= CASE case_operand case_exprlist case_else END", + /* 224 */ "case_exprlist ::= case_exprlist WHEN expr THEN expr", + /* 225 */ "case_exprlist ::= WHEN expr THEN expr", + /* 226 */ "case_else ::= ELSE expr", + /* 227 */ "case_else ::=", + /* 228 */ "case_operand ::= expr", + /* 229 */ "case_operand ::=", + /* 230 */ "exprlist ::= nexprlist", + /* 231 */ "exprlist ::=", + /* 232 */ "nexprlist ::= nexprlist COMMA expr", + /* 233 */ "nexprlist ::= expr", + /* 234 */ "cmd ::= CREATE uniqueflag INDEX ifnotexists nm dbnm ON nm LP idxlist RP", + /* 235 */ "uniqueflag ::= UNIQUE", + /* 236 */ "uniqueflag ::=", + /* 237 */ "idxlist_opt ::=", + /* 238 */ "idxlist_opt ::= LP idxlist RP", + /* 239 */ "idxlist ::= idxlist COMMA idxitem collate sortorder", + /* 240 */ "idxlist ::= idxitem collate sortorder", + /* 241 */ "idxitem ::= nm", + /* 242 */ "collate ::=", + /* 243 */ "collate ::= COLLATE ids", + /* 244 */ "cmd ::= DROP INDEX ifexists fullname", + /* 245 */ "cmd ::= VACUUM", + /* 246 */ "cmd ::= VACUUM nm", + /* 247 */ "cmd ::= PRAGMA nm dbnm EQ nmnum", + /* 248 */ "cmd ::= PRAGMA nm dbnm EQ ON", + /* 249 */ "cmd ::= PRAGMA nm dbnm EQ DELETE", + /* 250 */ "cmd ::= PRAGMA nm dbnm EQ minus_num", + /* 251 */ "cmd ::= PRAGMA nm dbnm LP nmnum RP", + /* 252 */ "cmd ::= PRAGMA nm dbnm", + /* 253 */ "nmnum ::= plus_num", + /* 254 */ "nmnum ::= nm", + /* 255 */ "plus_num ::= plus_opt number", + /* 256 */ "minus_num ::= MINUS number", + /* 257 */ "number ::= INTEGER|FLOAT", + /* 258 */ "plus_opt ::= PLUS", + /* 259 */ "plus_opt ::=", + /* 260 */ "cmd ::= CREATE trigger_decl BEGIN trigger_cmd_list END", + /* 261 */ "trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause", + /* 262 */ "trigger_time ::= BEFORE", + /* 263 */ "trigger_time ::= AFTER", + /* 264 */ "trigger_time ::= INSTEAD OF", + /* 265 */ "trigger_time ::=", + /* 266 */ "trigger_event ::= DELETE|INSERT", + /* 267 */ "trigger_event ::= UPDATE", + /* 268 */ "trigger_event ::= UPDATE OF inscollist", + /* 269 */ "foreach_clause ::=", + /* 270 */ "foreach_clause ::= FOR EACH ROW", + /* 271 */ "when_clause ::=", + /* 272 */ "when_clause ::= WHEN expr", + /* 273 */ "trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI", + /* 274 */ "trigger_cmd_list ::=", + /* 275 */ "trigger_cmd ::= UPDATE orconf nm SET setlist where_opt", + /* 276 */ "trigger_cmd ::= insert_cmd INTO nm inscollist_opt VALUES LP itemlist RP", + /* 277 */ "trigger_cmd ::= insert_cmd INTO nm inscollist_opt select", + /* 278 */ "trigger_cmd ::= DELETE FROM nm where_opt", + /* 279 */ "trigger_cmd ::= select", + /* 280 */ "expr ::= RAISE LP IGNORE RP", + /* 281 */ "expr ::= RAISE LP raisetype COMMA nm RP", + /* 282 */ "raisetype ::= ROLLBACK", + /* 283 */ "raisetype ::= ABORT", + /* 284 */ "raisetype ::= FAIL", + /* 285 */ "cmd ::= DROP TRIGGER ifexists fullname", + /* 286 */ "cmd ::= ATTACH database_kw_opt expr AS expr key_opt", + /* 287 */ "cmd ::= DETACH database_kw_opt expr", + /* 288 */ "key_opt ::=", + /* 289 */ "key_opt ::= KEY expr", + /* 290 */ "database_kw_opt ::= DATABASE", + /* 291 */ "database_kw_opt ::=", + /* 292 */ "cmd ::= REINDEX", + /* 293 */ "cmd ::= REINDEX nm dbnm", + /* 294 */ "cmd ::= ANALYZE", + /* 295 */ "cmd ::= ANALYZE nm dbnm", + /* 296 */ "cmd ::= ALTER TABLE fullname RENAME TO nm", + /* 297 */ "cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt column", + /* 298 */ "add_column_fullname ::= fullname", + /* 299 */ "kwcolumn_opt ::=", + /* 300 */ "kwcolumn_opt ::= COLUMNKW", + /* 301 */ "cmd ::= create_vtab", + /* 302 */ "cmd ::= create_vtab LP vtabarglist RP", + /* 303 */ "create_vtab ::= CREATE VIRTUAL TABLE nm dbnm USING nm", + /* 304 */ "vtabarglist ::= vtabarg", + /* 305 */ "vtabarglist ::= vtabarglist COMMA vtabarg", + /* 306 */ "vtabarg ::=", + /* 307 */ "vtabarg ::= vtabarg vtabargtoken", + /* 308 */ "vtabargtoken ::= ANY", + /* 309 */ "vtabargtoken ::= lp anylist RP", + /* 310 */ "lp ::= LP", + /* 311 */ "anylist ::=", + /* 312 */ "anylist ::= anylist ANY", }; #endif /* NDEBUG */ @@ -80068,9 +74128,6 @@ SQLITE_PRIVATE void *sqlite3ParserAlloc(void *(*mallocProc)(size_t)){ pParser = (yyParser*)(*mallocProc)( (size_t)sizeof(yyParser) ); if( pParser ){ pParser->yyidx = -1; -#ifdef YYTRACKMAXSTACKDEPTH - pParser->yyidxMax = 0; -#endif #if YYSTACKDEPTH<=0 yyGrowStack(pParser); #endif @@ -80083,12 +74140,7 @@ SQLITE_PRIVATE void *sqlite3ParserAlloc(void *(*mallocProc)(size_t)){ ** "yymajor" is the symbol code, and "yypminor" is a pointer to ** the value. */ -static void yy_destructor( - yyParser *yypParser, /* The parser */ - YYCODETYPE yymajor, /* Type code for object to destroy */ - YYMINORTYPE *yypminor /* The object to be destroyed */ -){ - sqlite3ParserARG_FETCH; +static void yy_destructor(YYCODETYPE yymajor, YYMINORTYPE *yypminor){ switch( yymajor ){ /* Here is inserted the actions which take place when a ** terminal or non-terminal is destroyed. This can happen @@ -80100,68 +74152,184 @@ static void yy_destructor( ** which appear on the RHS of the rule, but which are not used ** inside the C code. */ - case 156: /* select */ - case 190: /* oneselect */ - case 208: /* seltablist_paren */ + case 155: /* select */ { -sqlite3SelectDelete(pParse->db, (yypminor->yy43)); +sqlite3SelectDelete((yypminor->yy219)); } break; - case 170: /* term */ - case 171: /* expr */ - case 195: /* where_opt */ - case 197: /* having_opt */ - case 206: /* on_opt */ - case 212: /* sortitem */ - case 220: /* escape */ - case 223: /* case_operand */ - case 225: /* case_else */ - case 236: /* when_clause */ - case 239: /* key_opt */ + case 169: /* term */ { -sqlite3ExprDelete(pParse->db, (yypminor->yy450)); +sqlite3ExprDelete((yypminor->yy172)); } break; - case 175: /* idxlist_opt */ - case 183: /* idxlist */ - case 193: /* selcollist */ - case 196: /* groupby_opt */ - case 198: /* orderby_opt */ - case 200: /* sclp */ - case 211: /* sortlist */ - case 213: /* nexprlist */ - case 214: /* setlist */ - case 217: /* itemlist */ - case 218: /* exprlist */ - case 224: /* case_exprlist */ + case 170: /* expr */ { -sqlite3ExprListDelete(pParse->db, (yypminor->yy242)); +sqlite3ExprDelete((yypminor->yy172)); } break; - case 189: /* fullname */ - case 194: /* from */ - case 202: /* seltablist */ - case 203: /* stl_prefix */ + case 174: /* idxlist_opt */ { -sqlite3SrcListDelete(pParse->db, (yypminor->yy419)); +sqlite3ExprListDelete((yypminor->yy174)); } break; - case 207: /* using_opt */ - case 210: /* inscollist */ - case 216: /* inscollist_opt */ + case 182: /* idxlist */ { -sqlite3IdListDelete(pParse->db, (yypminor->yy352)); +sqlite3ExprListDelete((yypminor->yy174)); } break; - case 232: /* trigger_cmd_list */ - case 237: /* trigger_cmd */ + case 188: /* fullname */ { -sqlite3DeleteTriggerStep(pParse->db, (yypminor->yy75)); +sqlite3SrcListDelete((yypminor->yy373)); } break; - case 234: /* trigger_event */ + case 189: /* oneselect */ { -sqlite3IdListDelete(pParse->db, (yypminor->yy354).b); +sqlite3SelectDelete((yypminor->yy219)); +} + break; + case 192: /* selcollist */ +{ +sqlite3ExprListDelete((yypminor->yy174)); +} + break; + case 193: /* from */ +{ +sqlite3SrcListDelete((yypminor->yy373)); +} + break; + case 194: /* where_opt */ +{ +sqlite3ExprDelete((yypminor->yy172)); +} + break; + case 195: /* groupby_opt */ +{ +sqlite3ExprListDelete((yypminor->yy174)); +} + break; + case 196: /* having_opt */ +{ +sqlite3ExprDelete((yypminor->yy172)); +} + break; + case 197: /* orderby_opt */ +{ +sqlite3ExprListDelete((yypminor->yy174)); +} + break; + case 199: /* sclp */ +{ +sqlite3ExprListDelete((yypminor->yy174)); +} + break; + case 201: /* seltablist */ +{ +sqlite3SrcListDelete((yypminor->yy373)); +} + break; + case 202: /* stl_prefix */ +{ +sqlite3SrcListDelete((yypminor->yy373)); +} + break; + case 204: /* on_opt */ +{ +sqlite3ExprDelete((yypminor->yy172)); +} + break; + case 205: /* using_opt */ +{ +sqlite3IdListDelete((yypminor->yy432)); +} + break; + case 206: /* seltablist_paren */ +{ +sqlite3SelectDelete((yypminor->yy219)); +} + break; + case 208: /* inscollist */ +{ +sqlite3IdListDelete((yypminor->yy432)); +} + break; + case 209: /* sortlist */ +{ +sqlite3ExprListDelete((yypminor->yy174)); +} + break; + case 210: /* sortitem */ +{ +sqlite3ExprDelete((yypminor->yy172)); +} + break; + case 211: /* nexprlist */ +{ +sqlite3ExprListDelete((yypminor->yy174)); +} + break; + case 212: /* setlist */ +{ +sqlite3ExprListDelete((yypminor->yy174)); +} + break; + case 214: /* inscollist_opt */ +{ +sqlite3IdListDelete((yypminor->yy432)); +} + break; + case 215: /* itemlist */ +{ +sqlite3ExprListDelete((yypminor->yy174)); +} + break; + case 216: /* exprlist */ +{ +sqlite3ExprListDelete((yypminor->yy174)); +} + break; + case 218: /* escape */ +{ +sqlite3ExprDelete((yypminor->yy172)); +} + break; + case 221: /* case_operand */ +{ +sqlite3ExprDelete((yypminor->yy172)); +} + break; + case 222: /* case_exprlist */ +{ +sqlite3ExprListDelete((yypminor->yy174)); +} + break; + case 223: /* case_else */ +{ +sqlite3ExprDelete((yypminor->yy172)); +} + break; + case 231: /* trigger_cmd_list */ +{ +sqlite3DeleteTriggerStep((yypminor->yy243)); +} + break; + case 233: /* trigger_event */ +{ +sqlite3IdListDelete((yypminor->yy370).b); +} + break; + case 235: /* when_clause */ +{ +sqlite3ExprDelete((yypminor->yy172)); +} + break; + case 236: /* trigger_cmd */ +{ +sqlite3DeleteTriggerStep((yypminor->yy243)); +} + break; + case 238: /* key_opt */ +{ +sqlite3ExprDelete((yypminor->yy172)); } break; default: break; /* If no destructor action specified: do nothing */ @@ -80189,7 +74357,7 @@ static int yy_pop_parser_stack(yyParser *pParser){ } #endif yymajor = yytos->major; - yy_destructor(pParser, yymajor, &yytos->minor); + yy_destructor( yymajor, &yytos->minor); pParser->yyidx--; return yymajor; } @@ -80219,16 +74387,6 @@ SQLITE_PRIVATE void sqlite3ParserFree( (*freeProc)((void*)pParser); } -/* -** Return the peak depth of the stack for a parser. -*/ -#ifdef YYTRACKMAXSTACKDEPTH -SQLITE_PRIVATE int sqlite3ParserStackPeak(void *p){ - yyParser *pParser = (yyParser*)p; - return pParser->yyidxMax; -} -#endif - /* ** Find the appropriate action for a parser given the terminal ** look-ahead token iLookAhead. @@ -80347,15 +74505,10 @@ static void yy_shift( yyParser *yypParser, /* The parser to be shifted */ int yyNewState, /* The new state to shift in */ int yyMajor, /* The major token to shift in */ - YYMINORTYPE *yypMinor /* Pointer to the minor token to shift in */ + YYMINORTYPE *yypMinor /* Pointer ot the minor token to shift in */ ){ yyStackEntry *yytos; yypParser->yyidx++; -#ifdef YYTRACKMAXSTACKDEPTH - if( yypParser->yyidx>yypParser->yyidxMax ){ - yypParser->yyidxMax = yypParser->yyidx; - } -#endif #if YYSTACKDEPTH>0 if( yypParser->yyidx>=YYSTACKDEPTH ){ yyStackOverflow(yypParser, yypMinor); @@ -80393,321 +74546,319 @@ static const struct { YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */ unsigned char nrhs; /* Number of right-hand side symbols in the rule */ } yyRuleInfo[] = { + { 139, 1 }, + { 140, 2 }, { 140, 1 }, - { 141, 2 }, - { 141, 1 }, { 142, 1 }, - { 142, 3 }, - { 143, 0 }, - { 143, 1 }, - { 143, 3 }, + { 141, 1 }, + { 141, 3 }, + { 144, 0 }, { 144, 1 }, - { 145, 3 }, - { 147, 0 }, - { 147, 1 }, - { 147, 2 }, + { 144, 3 }, + { 143, 3 }, { 146, 0 }, { 146, 1 }, - { 146, 1 }, - { 146, 1 }, - { 145, 2 }, - { 145, 2 }, - { 145, 2 }, - { 145, 2 }, - { 149, 6 }, - { 152, 0 }, - { 152, 3 }, - { 151, 1 }, - { 151, 0 }, - { 150, 4 }, - { 150, 2 }, - { 154, 3 }, - { 154, 1 }, - { 157, 3 }, - { 158, 1 }, - { 161, 1 }, - { 162, 1 }, - { 148, 1 }, - { 148, 1 }, - { 148, 1 }, - { 159, 0 }, - { 159, 1 }, - { 163, 1 }, - { 163, 4 }, - { 163, 6 }, - { 164, 1 }, - { 164, 2 }, - { 165, 1 }, - { 165, 1 }, - { 160, 2 }, - { 160, 0 }, - { 168, 3 }, - { 168, 1 }, - { 169, 2 }, - { 169, 4 }, - { 169, 3 }, - { 169, 3 }, - { 169, 2 }, - { 169, 2 }, - { 169, 3 }, - { 169, 5 }, - { 169, 2 }, - { 169, 4 }, - { 169, 4 }, - { 169, 1 }, - { 169, 2 }, - { 174, 0 }, - { 174, 1 }, - { 176, 0 }, - { 176, 2 }, - { 178, 2 }, - { 178, 3 }, - { 178, 3 }, - { 178, 3 }, - { 179, 2 }, - { 179, 2 }, - { 179, 1 }, - { 179, 1 }, - { 177, 3 }, - { 177, 2 }, - { 180, 0 }, - { 180, 2 }, - { 180, 2 }, - { 155, 0 }, - { 155, 2 }, - { 181, 3 }, - { 181, 2 }, - { 181, 1 }, - { 182, 2 }, - { 182, 7 }, - { 182, 5 }, - { 182, 5 }, - { 182, 10 }, - { 184, 0 }, - { 184, 1 }, - { 172, 0 }, - { 172, 3 }, - { 185, 0 }, - { 185, 2 }, - { 186, 1 }, - { 186, 1 }, - { 186, 1 }, - { 145, 4 }, - { 188, 2 }, - { 188, 0 }, - { 145, 8 }, - { 145, 4 }, + { 146, 2 }, + { 145, 0 }, { 145, 1 }, - { 156, 1 }, + { 145, 1 }, + { 145, 1 }, + { 143, 2 }, + { 143, 2 }, + { 143, 2 }, + { 143, 2 }, + { 148, 6 }, + { 151, 0 }, + { 151, 3 }, + { 150, 1 }, + { 150, 0 }, + { 149, 4 }, + { 149, 2 }, + { 153, 3 }, + { 153, 1 }, { 156, 3 }, + { 157, 1 }, + { 160, 1 }, + { 161, 1 }, + { 147, 1 }, + { 147, 1 }, + { 147, 1 }, + { 158, 0 }, + { 158, 1 }, + { 162, 1 }, + { 162, 4 }, + { 162, 6 }, + { 163, 1 }, + { 163, 2 }, + { 164, 1 }, + { 164, 1 }, + { 159, 2 }, + { 159, 0 }, + { 167, 3 }, + { 167, 1 }, + { 168, 2 }, + { 168, 4 }, + { 168, 3 }, + { 168, 3 }, + { 168, 2 }, + { 168, 2 }, + { 168, 3 }, + { 168, 5 }, + { 168, 2 }, + { 168, 4 }, + { 168, 4 }, + { 168, 1 }, + { 168, 2 }, + { 173, 0 }, + { 173, 1 }, + { 175, 0 }, + { 175, 2 }, + { 177, 2 }, + { 177, 3 }, + { 177, 3 }, + { 177, 3 }, + { 178, 2 }, + { 178, 2 }, + { 178, 1 }, + { 178, 1 }, + { 176, 3 }, + { 176, 2 }, + { 179, 0 }, + { 179, 2 }, + { 179, 2 }, + { 154, 0 }, + { 154, 2 }, + { 180, 3 }, + { 180, 2 }, + { 180, 1 }, + { 181, 2 }, + { 181, 7 }, + { 181, 5 }, + { 181, 5 }, + { 181, 10 }, + { 183, 0 }, + { 183, 1 }, + { 171, 0 }, + { 171, 3 }, + { 184, 0 }, + { 184, 2 }, + { 185, 1 }, + { 185, 1 }, + { 185, 1 }, + { 143, 4 }, + { 187, 2 }, + { 187, 0 }, + { 143, 8 }, + { 143, 4 }, + { 143, 1 }, + { 155, 1 }, + { 155, 3 }, + { 190, 1 }, + { 190, 2 }, + { 190, 1 }, + { 189, 9 }, { 191, 1 }, - { 191, 2 }, { 191, 1 }, - { 190, 9 }, - { 192, 1 }, - { 192, 1 }, - { 192, 0 }, + { 191, 0 }, + { 199, 2 }, + { 199, 0 }, + { 192, 3 }, + { 192, 2 }, + { 192, 4 }, { 200, 2 }, + { 200, 1 }, { 200, 0 }, - { 193, 3 }, + { 193, 0 }, { 193, 2 }, - { 193, 4 }, - { 201, 2 }, - { 201, 1 }, - { 201, 0 }, + { 202, 2 }, + { 202, 0 }, + { 201, 6 }, + { 201, 7 }, + { 206, 1 }, + { 206, 1 }, + { 152, 0 }, + { 152, 2 }, + { 188, 2 }, + { 203, 1 }, + { 203, 2 }, + { 203, 3 }, + { 203, 4 }, + { 204, 2 }, + { 204, 0 }, + { 205, 4 }, + { 205, 0 }, + { 197, 0 }, + { 197, 3 }, + { 209, 4 }, + { 209, 2 }, + { 210, 1 }, + { 172, 1 }, + { 172, 1 }, + { 172, 0 }, + { 195, 0 }, + { 195, 3 }, + { 196, 0 }, + { 196, 2 }, + { 198, 0 }, + { 198, 2 }, + { 198, 4 }, + { 198, 4 }, + { 143, 4 }, { 194, 0 }, { 194, 2 }, - { 203, 2 }, - { 203, 0 }, - { 202, 7 }, - { 202, 7 }, - { 208, 1 }, - { 208, 1 }, - { 153, 0 }, - { 153, 2 }, - { 189, 2 }, - { 204, 1 }, - { 204, 2 }, - { 204, 3 }, - { 204, 4 }, - { 206, 2 }, - { 206, 0 }, - { 205, 0 }, - { 205, 3 }, - { 205, 2 }, - { 207, 4 }, - { 207, 0 }, - { 198, 0 }, - { 198, 3 }, - { 211, 4 }, - { 211, 2 }, - { 212, 1 }, - { 173, 1 }, - { 173, 1 }, - { 173, 0 }, - { 196, 0 }, - { 196, 3 }, - { 197, 0 }, - { 197, 2 }, - { 199, 0 }, - { 199, 2 }, - { 199, 4 }, - { 199, 4 }, - { 145, 5 }, - { 195, 0 }, - { 195, 2 }, - { 145, 7 }, - { 214, 5 }, - { 214, 3 }, - { 145, 8 }, - { 145, 5 }, - { 145, 6 }, - { 215, 2 }, - { 215, 1 }, - { 217, 3 }, - { 217, 1 }, - { 216, 0 }, - { 216, 3 }, - { 210, 3 }, - { 210, 1 }, - { 171, 1 }, - { 171, 3 }, - { 170, 1 }, - { 171, 1 }, - { 171, 1 }, - { 171, 3 }, - { 171, 5 }, - { 170, 1 }, - { 170, 1 }, - { 171, 1 }, - { 171, 1 }, - { 171, 3 }, - { 171, 6 }, - { 171, 5 }, - { 171, 4 }, - { 170, 1 }, - { 171, 3 }, - { 171, 3 }, - { 171, 3 }, - { 171, 3 }, - { 171, 3 }, - { 171, 3 }, - { 171, 3 }, - { 171, 3 }, - { 219, 1 }, - { 219, 2 }, - { 219, 1 }, - { 219, 2 }, - { 220, 2 }, - { 220, 0 }, - { 171, 4 }, - { 171, 2 }, - { 171, 3 }, - { 171, 3 }, - { 171, 4 }, - { 171, 2 }, - { 171, 2 }, - { 171, 2 }, - { 171, 2 }, - { 221, 1 }, - { 221, 2 }, - { 171, 5 }, - { 222, 1 }, - { 222, 2 }, - { 171, 5 }, - { 171, 3 }, - { 171, 5 }, - { 171, 4 }, - { 171, 4 }, - { 171, 5 }, - { 224, 5 }, - { 224, 4 }, - { 225, 2 }, - { 225, 0 }, - { 223, 1 }, - { 223, 0 }, - { 218, 1 }, - { 218, 0 }, - { 213, 3 }, + { 143, 6 }, + { 212, 5 }, + { 212, 3 }, + { 143, 8 }, + { 143, 5 }, + { 143, 6 }, + { 213, 2 }, { 213, 1 }, - { 145, 11 }, - { 226, 1 }, + { 215, 3 }, + { 215, 1 }, + { 214, 0 }, + { 214, 3 }, + { 208, 3 }, + { 208, 1 }, + { 170, 1 }, + { 170, 3 }, + { 169, 1 }, + { 170, 1 }, + { 170, 1 }, + { 170, 3 }, + { 170, 5 }, + { 169, 1 }, + { 169, 1 }, + { 170, 1 }, + { 170, 1 }, + { 170, 3 }, + { 170, 6 }, + { 170, 5 }, + { 170, 4 }, + { 169, 1 }, + { 170, 3 }, + { 170, 3 }, + { 170, 3 }, + { 170, 3 }, + { 170, 3 }, + { 170, 3 }, + { 170, 3 }, + { 170, 3 }, + { 217, 1 }, + { 217, 2 }, + { 217, 1 }, + { 217, 2 }, + { 218, 2 }, + { 218, 0 }, + { 170, 4 }, + { 170, 2 }, + { 170, 3 }, + { 170, 3 }, + { 170, 4 }, + { 170, 2 }, + { 170, 2 }, + { 170, 2 }, + { 170, 2 }, + { 219, 1 }, + { 219, 2 }, + { 170, 5 }, + { 220, 1 }, + { 220, 2 }, + { 170, 5 }, + { 170, 3 }, + { 170, 5 }, + { 170, 4 }, + { 170, 4 }, + { 170, 5 }, + { 222, 5 }, + { 222, 4 }, + { 223, 2 }, + { 223, 0 }, + { 221, 1 }, + { 221, 0 }, + { 216, 1 }, + { 216, 0 }, + { 211, 3 }, + { 211, 1 }, + { 143, 11 }, + { 224, 1 }, + { 224, 0 }, + { 174, 0 }, + { 174, 3 }, + { 182, 5 }, + { 182, 3 }, + { 225, 1 }, { 226, 0 }, - { 175, 0 }, - { 175, 3 }, - { 183, 5 }, - { 183, 3 }, - { 227, 0 }, - { 227, 2 }, - { 145, 4 }, - { 145, 1 }, - { 145, 2 }, - { 145, 5 }, - { 145, 5 }, - { 145, 5 }, - { 145, 5 }, - { 145, 6 }, - { 145, 3 }, - { 228, 1 }, - { 228, 1 }, + { 226, 2 }, + { 143, 4 }, + { 143, 1 }, + { 143, 2 }, + { 143, 5 }, + { 143, 5 }, + { 143, 5 }, + { 143, 5 }, + { 143, 6 }, + { 143, 3 }, + { 227, 1 }, + { 227, 1 }, + { 165, 2 }, { 166, 2 }, - { 167, 2 }, - { 230, 1 }, { 229, 1 }, - { 229, 0 }, - { 145, 5 }, - { 231, 11 }, + { 228, 1 }, + { 228, 0 }, + { 143, 5 }, + { 230, 11 }, + { 232, 1 }, + { 232, 1 }, + { 232, 2 }, + { 232, 0 }, { 233, 1 }, { 233, 1 }, - { 233, 2 }, - { 233, 0 }, - { 234, 1 }, - { 234, 1 }, + { 233, 3 }, + { 234, 0 }, { 234, 3 }, { 235, 0 }, - { 235, 3 }, - { 236, 0 }, - { 236, 2 }, - { 232, 3 }, - { 232, 2 }, - { 237, 6 }, - { 237, 8 }, - { 237, 5 }, - { 237, 4 }, - { 237, 1 }, - { 171, 4 }, - { 171, 6 }, - { 187, 1 }, - { 187, 1 }, - { 187, 1 }, - { 145, 4 }, - { 145, 6 }, - { 145, 3 }, - { 239, 0 }, - { 239, 2 }, - { 238, 1 }, + { 235, 2 }, + { 231, 3 }, + { 231, 0 }, + { 236, 6 }, + { 236, 8 }, + { 236, 5 }, + { 236, 4 }, + { 236, 1 }, + { 170, 4 }, + { 170, 6 }, + { 186, 1 }, + { 186, 1 }, + { 186, 1 }, + { 143, 4 }, + { 143, 6 }, + { 143, 3 }, { 238, 0 }, - { 145, 1 }, - { 145, 3 }, - { 145, 1 }, - { 145, 3 }, - { 145, 6 }, - { 145, 6 }, + { 238, 2 }, + { 237, 1 }, + { 237, 0 }, + { 143, 1 }, + { 143, 3 }, + { 143, 1 }, + { 143, 3 }, + { 143, 6 }, + { 143, 6 }, + { 239, 1 }, + { 240, 0 }, { 240, 1 }, - { 241, 0 }, - { 241, 1 }, - { 145, 1 }, - { 145, 4 }, - { 242, 7 }, - { 243, 1 }, - { 243, 3 }, - { 244, 0 }, - { 244, 2 }, + { 143, 1 }, + { 143, 4 }, + { 241, 7 }, + { 242, 1 }, + { 242, 3 }, + { 243, 0 }, + { 243, 2 }, + { 244, 1 }, + { 244, 3 }, { 245, 1 }, - { 245, 3 }, - { 246, 1 }, - { 247, 0 }, - { 247, 2 }, + { 246, 0 }, + { 246, 2 }, }; static void yy_accept(yyParser*); /* Forward Declaration */ @@ -80765,8 +74916,8 @@ static void yy_reduce( case 0: /* input ::= cmdlist */ case 1: /* cmdlist ::= cmdlist ecmd */ case 2: /* cmdlist ::= ecmd */ - case 3: /* ecmd ::= SEMI */ - case 4: /* ecmd ::= explain cmdx SEMI */ + case 4: /* ecmd ::= SEMI */ + case 5: /* ecmd ::= explain cmdx SEMI */ case 10: /* trans_opt ::= */ case 11: /* trans_opt ::= TRANSACTION */ case 12: /* trans_opt ::= TRANSACTION nm */ @@ -80785,45 +74936,45 @@ static void yy_reduce( case 83: /* conslist ::= conslist tcons */ case 84: /* conslist ::= tcons */ case 85: /* tcons ::= CONSTRAINT nm */ - case 260: /* plus_opt ::= PLUS */ - case 261: /* plus_opt ::= */ - case 271: /* foreach_clause ::= */ - case 272: /* foreach_clause ::= FOR EACH ROW */ - case 292: /* database_kw_opt ::= DATABASE */ - case 293: /* database_kw_opt ::= */ - case 301: /* kwcolumn_opt ::= */ - case 302: /* kwcolumn_opt ::= COLUMNKW */ - case 306: /* vtabarglist ::= vtabarg */ - case 307: /* vtabarglist ::= vtabarglist COMMA vtabarg */ - case 309: /* vtabarg ::= vtabarg vtabargtoken */ - case 313: /* anylist ::= */ + case 258: /* plus_opt ::= PLUS */ + case 259: /* plus_opt ::= */ + case 269: /* foreach_clause ::= */ + case 270: /* foreach_clause ::= FOR EACH ROW */ + case 290: /* database_kw_opt ::= DATABASE */ + case 291: /* database_kw_opt ::= */ + case 299: /* kwcolumn_opt ::= */ + case 300: /* kwcolumn_opt ::= COLUMNKW */ + case 304: /* vtabarglist ::= vtabarg */ + case 305: /* vtabarglist ::= vtabarglist COMMA vtabarg */ + case 307: /* vtabarg ::= vtabarg vtabargtoken */ + case 311: /* anylist ::= */ { } break; - case 5: /* explain ::= */ -{ sqlite3BeginParse(pParse, 0); } - break; - case 6: /* explain ::= EXPLAIN */ -{ sqlite3BeginParse(pParse, 1); } - break; - case 7: /* explain ::= EXPLAIN QUERY PLAN */ -{ sqlite3BeginParse(pParse, 2); } - break; - case 8: /* cmdx ::= cmd */ + case 3: /* cmdx ::= cmd */ { sqlite3FinishCoding(pParse); } break; + case 6: /* explain ::= */ +{ sqlite3BeginParse(pParse, 0); } + break; + case 7: /* explain ::= EXPLAIN */ +{ sqlite3BeginParse(pParse, 1); } + break; + case 8: /* explain ::= EXPLAIN QUERY PLAN */ +{ sqlite3BeginParse(pParse, 2); } + break; case 9: /* cmd ::= BEGIN transtype trans_opt */ -{sqlite3BeginTransaction(pParse, yymsp[-1].minor.yy316);} +{sqlite3BeginTransaction(pParse, yymsp[-1].minor.yy46);} break; case 13: /* transtype ::= */ -{yygotominor.yy316 = TK_DEFERRED;} +{yygotominor.yy46 = TK_DEFERRED;} break; case 14: /* transtype ::= DEFERRED */ case 15: /* transtype ::= IMMEDIATE */ case 16: /* transtype ::= EXCLUSIVE */ case 107: /* multiselect_op ::= UNION */ case 109: /* multiselect_op ::= EXCEPT|INTERSECT */ -{yygotominor.yy316 = yymsp[0].major;} +{yygotominor.yy46 = yymsp[0].major;} break; case 17: /* cmd ::= COMMIT trans_opt */ case 18: /* cmd ::= END trans_opt */ @@ -80834,7 +74985,7 @@ static void yy_reduce( break; case 21: /* create_table ::= CREATE temp TABLE ifnotexists nm dbnm */ { - sqlite3StartTable(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,yymsp[-4].minor.yy316,0,0,yymsp[-2].minor.yy316); + sqlite3StartTable(pParse,&yymsp[-1].minor.yy410,&yymsp[0].minor.yy410,yymsp[-4].minor.yy46,0,0,yymsp[-2].minor.yy46); } break; case 22: /* ifnotexists ::= */ @@ -80846,9 +74997,9 @@ static void yy_reduce( case 101: /* ifexists ::= */ case 112: /* distinct ::= ALL */ case 113: /* distinct ::= */ - case 216: /* between_op ::= BETWEEN */ - case 219: /* in_op ::= IN */ -{yygotominor.yy316 = 0;} + case 213: /* between_op ::= BETWEEN */ + case 216: /* in_op ::= IN */ +{yygotominor.yy46 = 0;} break; case 23: /* ifnotexists ::= IF NOT EXISTS */ case 24: /* temp ::= TEMP */ @@ -80856,31 +75007,31 @@ static void yy_reduce( case 78: /* init_deferred_pred_opt ::= INITIALLY DEFERRED */ case 100: /* ifexists ::= IF EXISTS */ case 111: /* distinct ::= DISTINCT */ - case 217: /* between_op ::= NOT BETWEEN */ - case 220: /* in_op ::= NOT IN */ -{yygotominor.yy316 = 1;} + case 214: /* between_op ::= NOT BETWEEN */ + case 217: /* in_op ::= NOT IN */ +{yygotominor.yy46 = 1;} break; case 26: /* create_table_args ::= LP columnlist conslist_opt RP */ { - sqlite3EndTable(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,0); + sqlite3EndTable(pParse,&yymsp[-1].minor.yy410,&yymsp[0].minor.yy0,0); } break; case 27: /* create_table_args ::= AS select */ { - sqlite3EndTable(pParse,0,0,yymsp[0].minor.yy43); - sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy43); + sqlite3EndTable(pParse,0,0,yymsp[0].minor.yy219); + sqlite3SelectDelete(yymsp[0].minor.yy219); } break; case 30: /* column ::= columnid type carglist */ { - yygotominor.yy0.z = yymsp[-2].minor.yy0.z; - yygotominor.yy0.n = (pParse->sLastToken.z-yymsp[-2].minor.yy0.z) + pParse->sLastToken.n; + yygotominor.yy410.z = yymsp[-2].minor.yy410.z; + yygotominor.yy410.n = (pParse->sLastToken.z-yymsp[-2].minor.yy410.z) + pParse->sLastToken.n; } break; case 31: /* columnid ::= nm */ { - sqlite3AddColumn(pParse,&yymsp[0].minor.yy0); - yygotominor.yy0 = yymsp[0].minor.yy0; + sqlite3AddColumn(pParse,&yymsp[0].minor.yy410); + yygotominor.yy410 = yymsp[0].minor.yy410; } break; case 32: /* id ::= ID */ @@ -80888,107 +75039,109 @@ static void yy_reduce( case 34: /* nm ::= ID */ case 35: /* nm ::= STRING */ case 36: /* nm ::= JOIN_KW */ + case 257: /* number ::= INTEGER|FLOAT */ +{yygotominor.yy410 = yymsp[0].minor.yy0;} + break; + case 38: /* type ::= typetoken */ +{sqlite3AddColumnType(pParse,&yymsp[0].minor.yy410);} + break; case 39: /* typetoken ::= typename */ case 42: /* typename ::= ids */ case 119: /* as ::= AS nm */ case 120: /* as ::= ids */ case 131: /* dbnm ::= DOT nm */ - case 140: /* indexed_opt ::= INDEXED BY nm */ - case 245: /* collate ::= COLLATE ids */ - case 255: /* nmnum ::= plus_num */ - case 256: /* nmnum ::= nm */ - case 257: /* plus_num ::= plus_opt number */ - case 258: /* minus_num ::= MINUS number */ - case 259: /* number ::= INTEGER|FLOAT */ -{yygotominor.yy0 = yymsp[0].minor.yy0;} - break; - case 38: /* type ::= typetoken */ -{sqlite3AddColumnType(pParse,&yymsp[0].minor.yy0);} + case 241: /* idxitem ::= nm */ + case 243: /* collate ::= COLLATE ids */ + case 253: /* nmnum ::= plus_num */ + case 254: /* nmnum ::= nm */ + case 255: /* plus_num ::= plus_opt number */ + case 256: /* minus_num ::= MINUS number */ +{yygotominor.yy410 = yymsp[0].minor.yy410;} break; case 40: /* typetoken ::= typename LP signed RP */ { - yygotominor.yy0.z = yymsp[-3].minor.yy0.z; - yygotominor.yy0.n = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n] - yymsp[-3].minor.yy0.z; + yygotominor.yy410.z = yymsp[-3].minor.yy410.z; + yygotominor.yy410.n = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n] - yymsp[-3].minor.yy410.z; } break; case 41: /* typetoken ::= typename LP signed COMMA signed RP */ { - yygotominor.yy0.z = yymsp[-5].minor.yy0.z; - yygotominor.yy0.n = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n] - yymsp[-5].minor.yy0.z; + yygotominor.yy410.z = yymsp[-5].minor.yy410.z; + yygotominor.yy410.n = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n] - yymsp[-5].minor.yy410.z; } break; case 43: /* typename ::= typename ids */ -{yygotominor.yy0.z=yymsp[-1].minor.yy0.z; yygotominor.yy0.n=yymsp[0].minor.yy0.n+(yymsp[0].minor.yy0.z-yymsp[-1].minor.yy0.z);} +{yygotominor.yy410.z=yymsp[-1].minor.yy410.z; yygotominor.yy410.n=yymsp[0].minor.yy410.n+(yymsp[0].minor.yy410.z-yymsp[-1].minor.yy410.z);} break; case 50: /* ccons ::= DEFAULT term */ case 52: /* ccons ::= DEFAULT PLUS term */ -{sqlite3AddDefaultValue(pParse,yymsp[0].minor.yy450);} +{sqlite3AddDefaultValue(pParse,yymsp[0].minor.yy172);} break; case 51: /* ccons ::= DEFAULT LP expr RP */ -{sqlite3AddDefaultValue(pParse,yymsp[-1].minor.yy450);} +{sqlite3AddDefaultValue(pParse,yymsp[-1].minor.yy172);} break; case 53: /* ccons ::= DEFAULT MINUS term */ { - Expr *p = sqlite3PExpr(pParse, TK_UMINUS, yymsp[0].minor.yy450, 0, 0); + Expr *p = sqlite3PExpr(pParse, TK_UMINUS, yymsp[0].minor.yy172, 0, 0); sqlite3AddDefaultValue(pParse,p); } break; case 54: /* ccons ::= DEFAULT id */ { - Expr *p = sqlite3PExpr(pParse, TK_STRING, 0, 0, &yymsp[0].minor.yy0); + Expr *p = sqlite3PExpr(pParse, TK_STRING, 0, 0, &yymsp[0].minor.yy410); sqlite3AddDefaultValue(pParse,p); } break; case 56: /* ccons ::= NOT NULL onconf */ -{sqlite3AddNotNull(pParse, yymsp[0].minor.yy316);} +{sqlite3AddNotNull(pParse, yymsp[0].minor.yy46);} break; case 57: /* ccons ::= PRIMARY KEY sortorder onconf autoinc */ -{sqlite3AddPrimaryKey(pParse,0,yymsp[-1].minor.yy316,yymsp[0].minor.yy316,yymsp[-2].minor.yy316);} +{sqlite3AddPrimaryKey(pParse,0,yymsp[-1].minor.yy46,yymsp[0].minor.yy46,yymsp[-2].minor.yy46);} break; case 58: /* ccons ::= UNIQUE onconf */ -{sqlite3CreateIndex(pParse,0,0,0,0,yymsp[0].minor.yy316,0,0,0,0);} +{sqlite3CreateIndex(pParse,0,0,0,0,yymsp[0].minor.yy46,0,0,0,0);} break; case 59: /* ccons ::= CHECK LP expr RP */ -{sqlite3AddCheckConstraint(pParse,yymsp[-1].minor.yy450);} +{sqlite3AddCheckConstraint(pParse,yymsp[-1].minor.yy172);} break; case 60: /* ccons ::= REFERENCES nm idxlist_opt refargs */ -{sqlite3CreateForeignKey(pParse,0,&yymsp[-2].minor.yy0,yymsp[-1].minor.yy242,yymsp[0].minor.yy316);} +{sqlite3CreateForeignKey(pParse,0,&yymsp[-2].minor.yy410,yymsp[-1].minor.yy174,yymsp[0].minor.yy46);} break; case 61: /* ccons ::= defer_subclause */ -{sqlite3DeferForeignKey(pParse,yymsp[0].minor.yy316);} +{sqlite3DeferForeignKey(pParse,yymsp[0].minor.yy46);} break; case 62: /* ccons ::= COLLATE ids */ -{sqlite3AddCollateType(pParse, &yymsp[0].minor.yy0);} +{sqlite3AddCollateType(pParse, &yymsp[0].minor.yy410);} break; case 65: /* refargs ::= */ -{ yygotominor.yy316 = OE_Restrict * 0x010101; } +{ yygotominor.yy46 = OE_Restrict * 0x010101; } break; case 66: /* refargs ::= refargs refarg */ -{ yygotominor.yy316 = (yymsp[-1].minor.yy316 & ~yymsp[0].minor.yy207.mask) | yymsp[0].minor.yy207.value; } +{ yygotominor.yy46 = (yymsp[-1].minor.yy46 & yymsp[0].minor.yy405.mask) | yymsp[0].minor.yy405.value; } break; case 67: /* refarg ::= MATCH nm */ -{ yygotominor.yy207.value = 0; yygotominor.yy207.mask = 0x000000; } +{ yygotominor.yy405.value = 0; yygotominor.yy405.mask = 0x000000; } break; case 68: /* refarg ::= ON DELETE refact */ -{ yygotominor.yy207.value = yymsp[0].minor.yy316; yygotominor.yy207.mask = 0x0000ff; } +{ yygotominor.yy405.value = yymsp[0].minor.yy46; yygotominor.yy405.mask = 0x0000ff; } break; case 69: /* refarg ::= ON UPDATE refact */ -{ yygotominor.yy207.value = yymsp[0].minor.yy316<<8; yygotominor.yy207.mask = 0x00ff00; } +{ yygotominor.yy405.value = yymsp[0].minor.yy46<<8; yygotominor.yy405.mask = 0x00ff00; } break; case 70: /* refarg ::= ON INSERT refact */ -{ yygotominor.yy207.value = yymsp[0].minor.yy316<<16; yygotominor.yy207.mask = 0xff0000; } +{ yygotominor.yy405.value = yymsp[0].minor.yy46<<16; yygotominor.yy405.mask = 0xff0000; } break; case 71: /* refact ::= SET NULL */ -{ yygotominor.yy316 = OE_SetNull; } +{ yygotominor.yy46 = OE_SetNull; } break; case 72: /* refact ::= SET DEFAULT */ -{ yygotominor.yy316 = OE_SetDflt; } +{ yygotominor.yy46 = OE_SetDflt; } break; case 73: /* refact ::= CASCADE */ -{ yygotominor.yy316 = OE_Cascade; } +{ yygotominor.yy46 = OE_Cascade; } break; case 74: /* refact ::= RESTRICT */ -{ yygotominor.yy316 = OE_Restrict; } +{ yygotominor.yy46 = OE_Restrict; } break; case 75: /* defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt */ case 76: /* defer_subclause ::= DEFERRABLE init_deferred_pred_opt */ @@ -80996,760 +75149,744 @@ static void yy_reduce( case 93: /* onconf ::= ON CONFLICT resolvetype */ case 95: /* orconf ::= OR resolvetype */ case 96: /* resolvetype ::= raisetype */ - case 169: /* insert_cmd ::= INSERT orconf */ -{yygotominor.yy316 = yymsp[0].minor.yy316;} + case 166: /* insert_cmd ::= INSERT orconf */ +{yygotominor.yy46 = yymsp[0].minor.yy46;} break; case 80: /* conslist_opt ::= */ -{yygotominor.yy0.n = 0; yygotominor.yy0.z = 0;} +{yygotominor.yy410.n = 0; yygotominor.yy410.z = 0;} break; case 81: /* conslist_opt ::= COMMA conslist */ -{yygotominor.yy0 = yymsp[-1].minor.yy0;} +{yygotominor.yy410 = yymsp[-1].minor.yy0;} break; case 86: /* tcons ::= PRIMARY KEY LP idxlist autoinc RP onconf */ -{sqlite3AddPrimaryKey(pParse,yymsp[-3].minor.yy242,yymsp[0].minor.yy316,yymsp[-2].minor.yy316,0);} +{sqlite3AddPrimaryKey(pParse,yymsp[-3].minor.yy174,yymsp[0].minor.yy46,yymsp[-2].minor.yy46,0);} break; case 87: /* tcons ::= UNIQUE LP idxlist RP onconf */ -{sqlite3CreateIndex(pParse,0,0,0,yymsp[-2].minor.yy242,yymsp[0].minor.yy316,0,0,0,0);} +{sqlite3CreateIndex(pParse,0,0,0,yymsp[-2].minor.yy174,yymsp[0].minor.yy46,0,0,0,0);} break; case 88: /* tcons ::= CHECK LP expr RP onconf */ -{sqlite3AddCheckConstraint(pParse,yymsp[-2].minor.yy450);} +{sqlite3AddCheckConstraint(pParse,yymsp[-2].minor.yy172);} break; case 89: /* tcons ::= FOREIGN KEY LP idxlist RP REFERENCES nm idxlist_opt refargs defer_subclause_opt */ { - sqlite3CreateForeignKey(pParse, yymsp[-6].minor.yy242, &yymsp[-3].minor.yy0, yymsp[-2].minor.yy242, yymsp[-1].minor.yy316); - sqlite3DeferForeignKey(pParse, yymsp[0].minor.yy316); + sqlite3CreateForeignKey(pParse, yymsp[-6].minor.yy174, &yymsp[-3].minor.yy410, yymsp[-2].minor.yy174, yymsp[-1].minor.yy46); + sqlite3DeferForeignKey(pParse, yymsp[0].minor.yy46); } break; case 92: /* onconf ::= */ case 94: /* orconf ::= */ -{yygotominor.yy316 = OE_Default;} +{yygotominor.yy46 = OE_Default;} break; case 97: /* resolvetype ::= IGNORE */ -{yygotominor.yy316 = OE_Ignore;} +{yygotominor.yy46 = OE_Ignore;} break; case 98: /* resolvetype ::= REPLACE */ - case 170: /* insert_cmd ::= REPLACE */ -{yygotominor.yy316 = OE_Replace;} + case 167: /* insert_cmd ::= REPLACE */ +{yygotominor.yy46 = OE_Replace;} break; case 99: /* cmd ::= DROP TABLE ifexists fullname */ { - sqlite3DropTable(pParse, yymsp[0].minor.yy419, 0, yymsp[-1].minor.yy316); + sqlite3DropTable(pParse, yymsp[0].minor.yy373, 0, yymsp[-1].minor.yy46); } break; case 102: /* cmd ::= CREATE temp VIEW ifnotexists nm dbnm AS select */ { - sqlite3CreateView(pParse, &yymsp[-7].minor.yy0, &yymsp[-3].minor.yy0, &yymsp[-2].minor.yy0, yymsp[0].minor.yy43, yymsp[-6].minor.yy316, yymsp[-4].minor.yy316); + sqlite3CreateView(pParse, &yymsp[-7].minor.yy0, &yymsp[-3].minor.yy410, &yymsp[-2].minor.yy410, yymsp[0].minor.yy219, yymsp[-6].minor.yy46, yymsp[-4].minor.yy46); } break; case 103: /* cmd ::= DROP VIEW ifexists fullname */ { - sqlite3DropTable(pParse, yymsp[0].minor.yy419, 1, yymsp[-1].minor.yy316); + sqlite3DropTable(pParse, yymsp[0].minor.yy373, 1, yymsp[-1].minor.yy46); } break; case 104: /* cmd ::= select */ { - SelectDest dest = {SRT_Output, 0, 0, 0, 0}; - sqlite3Select(pParse, yymsp[0].minor.yy43, &dest); - sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy43); + SelectDest dest = {SRT_Callback, 0, 0, 0, 0}; + sqlite3Select(pParse, yymsp[0].minor.yy219, &dest, 0, 0, 0, 0); + sqlite3SelectDelete(yymsp[0].minor.yy219); } break; case 105: /* select ::= oneselect */ case 128: /* seltablist_paren ::= select */ -{yygotominor.yy43 = yymsp[0].minor.yy43;} +{yygotominor.yy219 = yymsp[0].minor.yy219;} break; case 106: /* select ::= select multiselect_op oneselect */ { - if( yymsp[0].minor.yy43 ){ - yymsp[0].minor.yy43->op = yymsp[-1].minor.yy316; - yymsp[0].minor.yy43->pPrior = yymsp[-2].minor.yy43; + if( yymsp[0].minor.yy219 ){ + yymsp[0].minor.yy219->op = yymsp[-1].minor.yy46; + yymsp[0].minor.yy219->pPrior = yymsp[-2].minor.yy219; }else{ - sqlite3SelectDelete(pParse->db, yymsp[-2].minor.yy43); + sqlite3SelectDelete(yymsp[-2].minor.yy219); } - yygotominor.yy43 = yymsp[0].minor.yy43; + yygotominor.yy219 = yymsp[0].minor.yy219; } break; case 108: /* multiselect_op ::= UNION ALL */ -{yygotominor.yy316 = TK_ALL;} +{yygotominor.yy46 = TK_ALL;} break; case 110: /* oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt */ { - yygotominor.yy43 = sqlite3SelectNew(pParse,yymsp[-6].minor.yy242,yymsp[-5].minor.yy419,yymsp[-4].minor.yy450,yymsp[-3].minor.yy242,yymsp[-2].minor.yy450,yymsp[-1].minor.yy242,yymsp[-7].minor.yy316,yymsp[0].minor.yy84.pLimit,yymsp[0].minor.yy84.pOffset); + yygotominor.yy219 = sqlite3SelectNew(pParse,yymsp[-6].minor.yy174,yymsp[-5].minor.yy373,yymsp[-4].minor.yy172,yymsp[-3].minor.yy174,yymsp[-2].minor.yy172,yymsp[-1].minor.yy174,yymsp[-7].minor.yy46,yymsp[0].minor.yy234.pLimit,yymsp[0].minor.yy234.pOffset); } break; case 114: /* sclp ::= selcollist COMMA */ - case 241: /* idxlist_opt ::= LP idxlist RP */ -{yygotominor.yy242 = yymsp[-1].minor.yy242;} + case 238: /* idxlist_opt ::= LP idxlist RP */ +{yygotominor.yy174 = yymsp[-1].minor.yy174;} break; case 115: /* sclp ::= */ - case 144: /* orderby_opt ::= */ - case 152: /* groupby_opt ::= */ - case 234: /* exprlist ::= */ - case 240: /* idxlist_opt ::= */ -{yygotominor.yy242 = 0;} + case 141: /* orderby_opt ::= */ + case 149: /* groupby_opt ::= */ + case 231: /* exprlist ::= */ + case 237: /* idxlist_opt ::= */ +{yygotominor.yy174 = 0;} break; case 116: /* selcollist ::= sclp expr as */ { - yygotominor.yy242 = sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy242,yymsp[-1].minor.yy450,yymsp[0].minor.yy0.n?&yymsp[0].minor.yy0:0); + yygotominor.yy174 = sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy174,yymsp[-1].minor.yy172,yymsp[0].minor.yy410.n?&yymsp[0].minor.yy410:0); } break; case 117: /* selcollist ::= sclp STAR */ { Expr *p = sqlite3PExpr(pParse, TK_ALL, 0, 0, 0); - yygotominor.yy242 = sqlite3ExprListAppend(pParse, yymsp[-1].minor.yy242, p, 0); + yygotominor.yy174 = sqlite3ExprListAppend(pParse, yymsp[-1].minor.yy174, p, 0); } break; case 118: /* selcollist ::= sclp nm DOT STAR */ { - Expr *pRight = sqlite3PExpr(pParse, TK_ALL, 0, 0, &yymsp[0].minor.yy0); - Expr *pLeft = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[-2].minor.yy0); + Expr *pRight = sqlite3PExpr(pParse, TK_ALL, 0, 0, 0); + Expr *pLeft = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[-2].minor.yy410); Expr *pDot = sqlite3PExpr(pParse, TK_DOT, pLeft, pRight, 0); - yygotominor.yy242 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy242, pDot, 0); + yygotominor.yy174 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy174, pDot, 0); } break; case 121: /* as ::= */ -{yygotominor.yy0.n = 0;} +{yygotominor.yy410.n = 0;} break; case 122: /* from ::= */ -{yygotominor.yy419 = sqlite3DbMallocZero(pParse->db, sizeof(*yygotominor.yy419));} +{yygotominor.yy373 = sqlite3DbMallocZero(pParse->db, sizeof(*yygotominor.yy373));} break; case 123: /* from ::= FROM seltablist */ { - yygotominor.yy419 = yymsp[0].minor.yy419; - sqlite3SrcListShiftJoinType(yygotominor.yy419); + yygotominor.yy373 = yymsp[0].minor.yy373; + sqlite3SrcListShiftJoinType(yygotominor.yy373); } break; case 124: /* stl_prefix ::= seltablist joinop */ { - yygotominor.yy419 = yymsp[-1].minor.yy419; - if( yygotominor.yy419 && yygotominor.yy419->nSrc>0 ) yygotominor.yy419->a[yygotominor.yy419->nSrc-1].jointype = yymsp[0].minor.yy316; + yygotominor.yy373 = yymsp[-1].minor.yy373; + if( yygotominor.yy373 && yygotominor.yy373->nSrc>0 ) yygotominor.yy373->a[yygotominor.yy373->nSrc-1].jointype = yymsp[0].minor.yy46; } break; case 125: /* stl_prefix ::= */ -{yygotominor.yy419 = 0;} +{yygotominor.yy373 = 0;} break; - case 126: /* seltablist ::= stl_prefix nm dbnm as indexed_opt on_opt using_opt */ + case 126: /* seltablist ::= stl_prefix nm dbnm as on_opt using_opt */ { - yygotominor.yy419 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy419,&yymsp[-5].minor.yy0,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,0,yymsp[-1].minor.yy450,yymsp[0].minor.yy352); - sqlite3SrcListIndexedBy(pParse, yygotominor.yy419, &yymsp[-2].minor.yy0); + yygotominor.yy373 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-5].minor.yy373,&yymsp[-4].minor.yy410,&yymsp[-3].minor.yy410,&yymsp[-2].minor.yy410,0,yymsp[-1].minor.yy172,yymsp[0].minor.yy432); } break; case 127: /* seltablist ::= stl_prefix LP seltablist_paren RP as on_opt using_opt */ { - yygotominor.yy419 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy419,0,0,&yymsp[-2].minor.yy0,yymsp[-4].minor.yy43,yymsp[-1].minor.yy450,yymsp[0].minor.yy352); + yygotominor.yy373 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy373,0,0,&yymsp[-2].minor.yy410,yymsp[-4].minor.yy219,yymsp[-1].minor.yy172,yymsp[0].minor.yy432); } break; case 129: /* seltablist_paren ::= seltablist */ { - sqlite3SrcListShiftJoinType(yymsp[0].minor.yy419); - yygotominor.yy43 = sqlite3SelectNew(pParse,0,yymsp[0].minor.yy419,0,0,0,0,0,0,0); + sqlite3SrcListShiftJoinType(yymsp[0].minor.yy373); + yygotominor.yy219 = sqlite3SelectNew(pParse,0,yymsp[0].minor.yy373,0,0,0,0,0,0,0); } break; case 130: /* dbnm ::= */ - case 139: /* indexed_opt ::= */ -{yygotominor.yy0.z=0; yygotominor.yy0.n=0;} +{yygotominor.yy410.z=0; yygotominor.yy410.n=0;} break; case 132: /* fullname ::= nm dbnm */ -{yygotominor.yy419 = sqlite3SrcListAppend(pParse->db,0,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0);} +{yygotominor.yy373 = sqlite3SrcListAppend(pParse->db,0,&yymsp[-1].minor.yy410,&yymsp[0].minor.yy410);} break; case 133: /* joinop ::= COMMA|JOIN */ -{ yygotominor.yy316 = JT_INNER; } +{ yygotominor.yy46 = JT_INNER; } break; case 134: /* joinop ::= JOIN_KW JOIN */ -{ yygotominor.yy316 = sqlite3JoinType(pParse,&yymsp[-1].minor.yy0,0,0); } +{ yygotominor.yy46 = sqlite3JoinType(pParse,&yymsp[-1].minor.yy0,0,0); } break; case 135: /* joinop ::= JOIN_KW nm JOIN */ -{ yygotominor.yy316 = sqlite3JoinType(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,0); } +{ yygotominor.yy46 = sqlite3JoinType(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy410,0); } break; case 136: /* joinop ::= JOIN_KW nm nm JOIN */ -{ yygotominor.yy316 = sqlite3JoinType(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0); } +{ yygotominor.yy46 = sqlite3JoinType(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy410,&yymsp[-1].minor.yy410); } break; case 137: /* on_opt ::= ON expr */ - case 148: /* sortitem ::= expr */ - case 155: /* having_opt ::= HAVING expr */ - case 162: /* where_opt ::= WHERE expr */ - case 177: /* expr ::= term */ - case 205: /* escape ::= ESCAPE expr */ - case 229: /* case_else ::= ELSE expr */ - case 231: /* case_operand ::= expr */ -{yygotominor.yy450 = yymsp[0].minor.yy450;} + case 145: /* sortitem ::= expr */ + case 152: /* having_opt ::= HAVING expr */ + case 159: /* where_opt ::= WHERE expr */ + case 174: /* expr ::= term */ + case 202: /* escape ::= ESCAPE expr */ + case 226: /* case_else ::= ELSE expr */ + case 228: /* case_operand ::= expr */ +{yygotominor.yy172 = yymsp[0].minor.yy172;} break; case 138: /* on_opt ::= */ - case 154: /* having_opt ::= */ - case 161: /* where_opt ::= */ - case 206: /* escape ::= */ - case 230: /* case_else ::= */ - case 232: /* case_operand ::= */ -{yygotominor.yy450 = 0;} + case 151: /* having_opt ::= */ + case 158: /* where_opt ::= */ + case 203: /* escape ::= */ + case 227: /* case_else ::= */ + case 229: /* case_operand ::= */ +{yygotominor.yy172 = 0;} break; - case 141: /* indexed_opt ::= NOT INDEXED */ -{yygotominor.yy0.z=0; yygotominor.yy0.n=1;} + case 139: /* using_opt ::= USING LP inscollist RP */ + case 171: /* inscollist_opt ::= LP inscollist RP */ +{yygotominor.yy432 = yymsp[-1].minor.yy432;} break; - case 142: /* using_opt ::= USING LP inscollist RP */ - case 174: /* inscollist_opt ::= LP inscollist RP */ -{yygotominor.yy352 = yymsp[-1].minor.yy352;} + case 140: /* using_opt ::= */ + case 170: /* inscollist_opt ::= */ +{yygotominor.yy432 = 0;} break; - case 143: /* using_opt ::= */ - case 173: /* inscollist_opt ::= */ -{yygotominor.yy352 = 0;} + case 142: /* orderby_opt ::= ORDER BY sortlist */ + case 150: /* groupby_opt ::= GROUP BY nexprlist */ + case 230: /* exprlist ::= nexprlist */ +{yygotominor.yy174 = yymsp[0].minor.yy174;} break; - case 145: /* orderby_opt ::= ORDER BY sortlist */ - case 153: /* groupby_opt ::= GROUP BY nexprlist */ - case 233: /* exprlist ::= nexprlist */ -{yygotominor.yy242 = yymsp[0].minor.yy242;} - break; - case 146: /* sortlist ::= sortlist COMMA sortitem sortorder */ + case 143: /* sortlist ::= sortlist COMMA sortitem sortorder */ { - yygotominor.yy242 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy242,yymsp[-1].minor.yy450,0); - if( yygotominor.yy242 ) yygotominor.yy242->a[yygotominor.yy242->nExpr-1].sortOrder = yymsp[0].minor.yy316; + yygotominor.yy174 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy174,yymsp[-1].minor.yy172,0); + if( yygotominor.yy174 ) yygotominor.yy174->a[yygotominor.yy174->nExpr-1].sortOrder = yymsp[0].minor.yy46; } break; - case 147: /* sortlist ::= sortitem sortorder */ + case 144: /* sortlist ::= sortitem sortorder */ { - yygotominor.yy242 = sqlite3ExprListAppend(pParse,0,yymsp[-1].minor.yy450,0); - if( yygotominor.yy242 && yygotominor.yy242->a ) yygotominor.yy242->a[0].sortOrder = yymsp[0].minor.yy316; + yygotominor.yy174 = sqlite3ExprListAppend(pParse,0,yymsp[-1].minor.yy172,0); + if( yygotominor.yy174 && yygotominor.yy174->a ) yygotominor.yy174->a[0].sortOrder = yymsp[0].minor.yy46; } break; - case 149: /* sortorder ::= ASC */ - case 151: /* sortorder ::= */ -{yygotominor.yy316 = SQLITE_SO_ASC;} + case 146: /* sortorder ::= ASC */ + case 148: /* sortorder ::= */ +{yygotominor.yy46 = SQLITE_SO_ASC;} break; - case 150: /* sortorder ::= DESC */ -{yygotominor.yy316 = SQLITE_SO_DESC;} + case 147: /* sortorder ::= DESC */ +{yygotominor.yy46 = SQLITE_SO_DESC;} break; - case 156: /* limit_opt ::= */ -{yygotominor.yy84.pLimit = 0; yygotominor.yy84.pOffset = 0;} + case 153: /* limit_opt ::= */ +{yygotominor.yy234.pLimit = 0; yygotominor.yy234.pOffset = 0;} break; - case 157: /* limit_opt ::= LIMIT expr */ -{yygotominor.yy84.pLimit = yymsp[0].minor.yy450; yygotominor.yy84.pOffset = 0;} + case 154: /* limit_opt ::= LIMIT expr */ +{yygotominor.yy234.pLimit = yymsp[0].minor.yy172; yygotominor.yy234.pOffset = 0;} break; - case 158: /* limit_opt ::= LIMIT expr OFFSET expr */ -{yygotominor.yy84.pLimit = yymsp[-2].minor.yy450; yygotominor.yy84.pOffset = yymsp[0].minor.yy450;} + case 155: /* limit_opt ::= LIMIT expr OFFSET expr */ +{yygotominor.yy234.pLimit = yymsp[-2].minor.yy172; yygotominor.yy234.pOffset = yymsp[0].minor.yy172;} break; - case 159: /* limit_opt ::= LIMIT expr COMMA expr */ -{yygotominor.yy84.pOffset = yymsp[-2].minor.yy450; yygotominor.yy84.pLimit = yymsp[0].minor.yy450;} + case 156: /* limit_opt ::= LIMIT expr COMMA expr */ +{yygotominor.yy234.pOffset = yymsp[-2].minor.yy172; yygotominor.yy234.pLimit = yymsp[0].minor.yy172;} break; - case 160: /* cmd ::= DELETE FROM fullname indexed_opt where_opt */ + case 157: /* cmd ::= DELETE FROM fullname where_opt */ +{sqlite3DeleteFrom(pParse,yymsp[-1].minor.yy373,yymsp[0].minor.yy172);} + break; + case 160: /* cmd ::= UPDATE orconf fullname SET setlist where_opt */ { - sqlite3SrcListIndexedBy(pParse, yymsp[-2].minor.yy419, &yymsp[-1].minor.yy0); - sqlite3DeleteFrom(pParse,yymsp[-2].minor.yy419,yymsp[0].minor.yy450); + sqlite3ExprListCheckLength(pParse,yymsp[-1].minor.yy174,"set list"); + sqlite3Update(pParse,yymsp[-3].minor.yy373,yymsp[-1].minor.yy174,yymsp[0].minor.yy172,yymsp[-4].minor.yy46); } break; - case 163: /* cmd ::= UPDATE orconf fullname indexed_opt SET setlist where_opt */ + case 161: /* setlist ::= setlist COMMA nm EQ expr */ +{yygotominor.yy174 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy174,yymsp[0].minor.yy172,&yymsp[-2].minor.yy410);} + break; + case 162: /* setlist ::= nm EQ expr */ +{yygotominor.yy174 = sqlite3ExprListAppend(pParse,0,yymsp[0].minor.yy172,&yymsp[-2].minor.yy410);} + break; + case 163: /* cmd ::= insert_cmd INTO fullname inscollist_opt VALUES LP itemlist RP */ +{sqlite3Insert(pParse, yymsp[-5].minor.yy373, yymsp[-1].minor.yy174, 0, yymsp[-4].minor.yy432, yymsp[-7].minor.yy46);} + break; + case 164: /* cmd ::= insert_cmd INTO fullname inscollist_opt select */ +{sqlite3Insert(pParse, yymsp[-2].minor.yy373, 0, yymsp[0].minor.yy219, yymsp[-1].minor.yy432, yymsp[-4].minor.yy46);} + break; + case 165: /* cmd ::= insert_cmd INTO fullname inscollist_opt DEFAULT VALUES */ +{sqlite3Insert(pParse, yymsp[-3].minor.yy373, 0, 0, yymsp[-2].minor.yy432, yymsp[-5].minor.yy46);} + break; + case 168: /* itemlist ::= itemlist COMMA expr */ + case 232: /* nexprlist ::= nexprlist COMMA expr */ +{yygotominor.yy174 = sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy174,yymsp[0].minor.yy172,0);} + break; + case 169: /* itemlist ::= expr */ + case 233: /* nexprlist ::= expr */ +{yygotominor.yy174 = sqlite3ExprListAppend(pParse,0,yymsp[0].minor.yy172,0);} + break; + case 172: /* inscollist ::= inscollist COMMA nm */ +{yygotominor.yy432 = sqlite3IdListAppend(pParse->db,yymsp[-2].minor.yy432,&yymsp[0].minor.yy410);} + break; + case 173: /* inscollist ::= nm */ +{yygotominor.yy432 = sqlite3IdListAppend(pParse->db,0,&yymsp[0].minor.yy410);} + break; + case 175: /* expr ::= LP expr RP */ +{yygotominor.yy172 = yymsp[-1].minor.yy172; sqlite3ExprSpan(yygotominor.yy172,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); } + break; + case 176: /* term ::= NULL */ + case 181: /* term ::= INTEGER|FLOAT|BLOB */ + case 182: /* term ::= STRING */ +{yygotominor.yy172 = sqlite3PExpr(pParse, yymsp[0].major, 0, 0, &yymsp[0].minor.yy0);} + break; + case 177: /* expr ::= ID */ + case 178: /* expr ::= JOIN_KW */ +{yygotominor.yy172 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[0].minor.yy0);} + break; + case 179: /* expr ::= nm DOT nm */ { - sqlite3SrcListIndexedBy(pParse, yymsp[-4].minor.yy419, &yymsp[-3].minor.yy0); - sqlite3ExprListCheckLength(pParse,yymsp[-1].minor.yy242,"set list"); - sqlite3Update(pParse,yymsp[-4].minor.yy419,yymsp[-1].minor.yy242,yymsp[0].minor.yy450,yymsp[-5].minor.yy316); + Expr *temp1 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[-2].minor.yy410); + Expr *temp2 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[0].minor.yy410); + yygotominor.yy172 = sqlite3PExpr(pParse, TK_DOT, temp1, temp2, 0); } break; - case 164: /* setlist ::= setlist COMMA nm EQ expr */ -{yygotominor.yy242 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy242,yymsp[0].minor.yy450,&yymsp[-2].minor.yy0);} - break; - case 165: /* setlist ::= nm EQ expr */ -{yygotominor.yy242 = sqlite3ExprListAppend(pParse,0,yymsp[0].minor.yy450,&yymsp[-2].minor.yy0);} - break; - case 166: /* cmd ::= insert_cmd INTO fullname inscollist_opt VALUES LP itemlist RP */ -{sqlite3Insert(pParse, yymsp[-5].minor.yy419, yymsp[-1].minor.yy242, 0, yymsp[-4].minor.yy352, yymsp[-7].minor.yy316);} - break; - case 167: /* cmd ::= insert_cmd INTO fullname inscollist_opt select */ -{sqlite3Insert(pParse, yymsp[-2].minor.yy419, 0, yymsp[0].minor.yy43, yymsp[-1].minor.yy352, yymsp[-4].minor.yy316);} - break; - case 168: /* cmd ::= insert_cmd INTO fullname inscollist_opt DEFAULT VALUES */ -{sqlite3Insert(pParse, yymsp[-3].minor.yy419, 0, 0, yymsp[-2].minor.yy352, yymsp[-5].minor.yy316);} - break; - case 171: /* itemlist ::= itemlist COMMA expr */ - case 235: /* nexprlist ::= nexprlist COMMA expr */ -{yygotominor.yy242 = sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy242,yymsp[0].minor.yy450,0);} - break; - case 172: /* itemlist ::= expr */ - case 236: /* nexprlist ::= expr */ -{yygotominor.yy242 = sqlite3ExprListAppend(pParse,0,yymsp[0].minor.yy450,0);} - break; - case 175: /* inscollist ::= inscollist COMMA nm */ -{yygotominor.yy352 = sqlite3IdListAppend(pParse->db,yymsp[-2].minor.yy352,&yymsp[0].minor.yy0);} - break; - case 176: /* inscollist ::= nm */ -{yygotominor.yy352 = sqlite3IdListAppend(pParse->db,0,&yymsp[0].minor.yy0);} - break; - case 178: /* expr ::= LP expr RP */ -{yygotominor.yy450 = yymsp[-1].minor.yy450; sqlite3ExprSpan(yygotominor.yy450,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); } - break; - case 179: /* term ::= NULL */ - case 184: /* term ::= INTEGER|FLOAT|BLOB */ - case 185: /* term ::= STRING */ -{yygotominor.yy450 = sqlite3PExpr(pParse, yymsp[0].major, 0, 0, &yymsp[0].minor.yy0);} - break; - case 180: /* expr ::= ID */ - case 181: /* expr ::= JOIN_KW */ -{yygotominor.yy450 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[0].minor.yy0);} - break; - case 182: /* expr ::= nm DOT nm */ + case 180: /* expr ::= nm DOT nm DOT nm */ { - Expr *temp1 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[-2].minor.yy0); - Expr *temp2 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[0].minor.yy0); - yygotominor.yy450 = sqlite3PExpr(pParse, TK_DOT, temp1, temp2, 0); -} - break; - case 183: /* expr ::= nm DOT nm DOT nm */ -{ - Expr *temp1 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[-4].minor.yy0); - Expr *temp2 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[-2].minor.yy0); - Expr *temp3 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[0].minor.yy0); + Expr *temp1 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[-4].minor.yy410); + Expr *temp2 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[-2].minor.yy410); + Expr *temp3 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[0].minor.yy410); Expr *temp4 = sqlite3PExpr(pParse, TK_DOT, temp2, temp3, 0); - yygotominor.yy450 = sqlite3PExpr(pParse, TK_DOT, temp1, temp4, 0); + yygotominor.yy172 = sqlite3PExpr(pParse, TK_DOT, temp1, temp4, 0); } break; - case 186: /* expr ::= REGISTER */ -{yygotominor.yy450 = sqlite3RegisterExpr(pParse, &yymsp[0].minor.yy0);} + case 183: /* expr ::= REGISTER */ +{yygotominor.yy172 = sqlite3RegisterExpr(pParse, &yymsp[0].minor.yy0);} break; - case 187: /* expr ::= VARIABLE */ + case 184: /* expr ::= VARIABLE */ { Token *pToken = &yymsp[0].minor.yy0; - Expr *pExpr = yygotominor.yy450 = sqlite3PExpr(pParse, TK_VARIABLE, 0, 0, pToken); + Expr *pExpr = yygotominor.yy172 = sqlite3PExpr(pParse, TK_VARIABLE, 0, 0, pToken); sqlite3ExprAssignVarNumber(pParse, pExpr); } break; - case 188: /* expr ::= expr COLLATE ids */ + case 185: /* expr ::= expr COLLATE ids */ { - yygotominor.yy450 = sqlite3ExprSetColl(pParse, yymsp[-2].minor.yy450, &yymsp[0].minor.yy0); + yygotominor.yy172 = sqlite3ExprSetColl(pParse, yymsp[-2].minor.yy172, &yymsp[0].minor.yy410); } break; - case 189: /* expr ::= CAST LP expr AS typetoken RP */ + case 186: /* expr ::= CAST LP expr AS typetoken RP */ { - yygotominor.yy450 = sqlite3PExpr(pParse, TK_CAST, yymsp[-3].minor.yy450, 0, &yymsp[-1].minor.yy0); - sqlite3ExprSpan(yygotominor.yy450,&yymsp[-5].minor.yy0,&yymsp[0].minor.yy0); + yygotominor.yy172 = sqlite3PExpr(pParse, TK_CAST, yymsp[-3].minor.yy172, 0, &yymsp[-1].minor.yy410); + sqlite3ExprSpan(yygotominor.yy172,&yymsp[-5].minor.yy0,&yymsp[0].minor.yy0); } break; - case 190: /* expr ::= ID LP distinct exprlist RP */ + case 187: /* expr ::= ID LP distinct exprlist RP */ { - if( yymsp[-1].minor.yy242 && yymsp[-1].minor.yy242->nExpr>SQLITE_MAX_FUNCTION_ARG ){ + if( yymsp[-1].minor.yy174 && yymsp[-1].minor.yy174->nExpr>SQLITE_MAX_FUNCTION_ARG ){ sqlite3ErrorMsg(pParse, "too many arguments on function %T", &yymsp[-4].minor.yy0); } - yygotominor.yy450 = sqlite3ExprFunction(pParse, yymsp[-1].minor.yy242, &yymsp[-4].minor.yy0); - sqlite3ExprSpan(yygotominor.yy450,&yymsp[-4].minor.yy0,&yymsp[0].minor.yy0); - if( yymsp[-2].minor.yy316 && yygotominor.yy450 ){ - yygotominor.yy450->flags |= EP_Distinct; + yygotominor.yy172 = sqlite3ExprFunction(pParse, yymsp[-1].minor.yy174, &yymsp[-4].minor.yy0); + sqlite3ExprSpan(yygotominor.yy172,&yymsp[-4].minor.yy0,&yymsp[0].minor.yy0); + if( yymsp[-2].minor.yy46 && yygotominor.yy172 ){ + yygotominor.yy172->flags |= EP_Distinct; } } break; - case 191: /* expr ::= ID LP STAR RP */ + case 188: /* expr ::= ID LP STAR RP */ { - yygotominor.yy450 = sqlite3ExprFunction(pParse, 0, &yymsp[-3].minor.yy0); - sqlite3ExprSpan(yygotominor.yy450,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0); + yygotominor.yy172 = sqlite3ExprFunction(pParse, 0, &yymsp[-3].minor.yy0); + sqlite3ExprSpan(yygotominor.yy172,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0); } break; - case 192: /* term ::= CTIME_KW */ + case 189: /* term ::= CTIME_KW */ { /* The CURRENT_TIME, CURRENT_DATE, and CURRENT_TIMESTAMP values are ** treated as functions that return constants */ - yygotominor.yy450 = sqlite3ExprFunction(pParse, 0,&yymsp[0].minor.yy0); - if( yygotominor.yy450 ){ - yygotominor.yy450->op = TK_CONST_FUNC; - yygotominor.yy450->span = yymsp[0].minor.yy0; + yygotominor.yy172 = sqlite3ExprFunction(pParse, 0,&yymsp[0].minor.yy0); + if( yygotominor.yy172 ){ + yygotominor.yy172->op = TK_CONST_FUNC; + yygotominor.yy172->span = yymsp[0].minor.yy0; } } break; - case 193: /* expr ::= expr AND expr */ - case 194: /* expr ::= expr OR expr */ - case 195: /* expr ::= expr LT|GT|GE|LE expr */ - case 196: /* expr ::= expr EQ|NE expr */ - case 197: /* expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr */ - case 198: /* expr ::= expr PLUS|MINUS expr */ - case 199: /* expr ::= expr STAR|SLASH|REM expr */ - case 200: /* expr ::= expr CONCAT expr */ -{yygotominor.yy450 = sqlite3PExpr(pParse,yymsp[-1].major,yymsp[-2].minor.yy450,yymsp[0].minor.yy450,0);} + case 190: /* expr ::= expr AND expr */ + case 191: /* expr ::= expr OR expr */ + case 192: /* expr ::= expr LT|GT|GE|LE expr */ + case 193: /* expr ::= expr EQ|NE expr */ + case 194: /* expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr */ + case 195: /* expr ::= expr PLUS|MINUS expr */ + case 196: /* expr ::= expr STAR|SLASH|REM expr */ + case 197: /* expr ::= expr CONCAT expr */ +{yygotominor.yy172 = sqlite3PExpr(pParse,yymsp[-1].major,yymsp[-2].minor.yy172,yymsp[0].minor.yy172,0);} break; - case 201: /* likeop ::= LIKE_KW */ - case 203: /* likeop ::= MATCH */ -{yygotominor.yy86.eOperator = yymsp[0].minor.yy0; yygotominor.yy86.not = 0;} + case 198: /* likeop ::= LIKE_KW */ + case 200: /* likeop ::= MATCH */ +{yygotominor.yy72.eOperator = yymsp[0].minor.yy0; yygotominor.yy72.not = 0;} break; - case 202: /* likeop ::= NOT LIKE_KW */ - case 204: /* likeop ::= NOT MATCH */ -{yygotominor.yy86.eOperator = yymsp[0].minor.yy0; yygotominor.yy86.not = 1;} + case 199: /* likeop ::= NOT LIKE_KW */ + case 201: /* likeop ::= NOT MATCH */ +{yygotominor.yy72.eOperator = yymsp[0].minor.yy0; yygotominor.yy72.not = 1;} break; - case 207: /* expr ::= expr likeop expr escape */ + case 204: /* expr ::= expr likeop expr escape */ { ExprList *pList; - pList = sqlite3ExprListAppend(pParse,0, yymsp[-1].minor.yy450, 0); - pList = sqlite3ExprListAppend(pParse,pList, yymsp[-3].minor.yy450, 0); - if( yymsp[0].minor.yy450 ){ - pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy450, 0); + pList = sqlite3ExprListAppend(pParse,0, yymsp[-1].minor.yy172, 0); + pList = sqlite3ExprListAppend(pParse,pList, yymsp[-3].minor.yy172, 0); + if( yymsp[0].minor.yy172 ){ + pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy172, 0); } - yygotominor.yy450 = sqlite3ExprFunction(pParse, pList, &yymsp[-2].minor.yy86.eOperator); - if( yymsp[-2].minor.yy86.not ) yygotominor.yy450 = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy450, 0, 0); - sqlite3ExprSpan(yygotominor.yy450, &yymsp[-3].minor.yy450->span, &yymsp[-1].minor.yy450->span); - if( yygotominor.yy450 ) yygotominor.yy450->flags |= EP_InfixFunc; + yygotominor.yy172 = sqlite3ExprFunction(pParse, pList, &yymsp[-2].minor.yy72.eOperator); + if( yymsp[-2].minor.yy72.not ) yygotominor.yy172 = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy172, 0, 0); + sqlite3ExprSpan(yygotominor.yy172, &yymsp[-3].minor.yy172->span, &yymsp[-1].minor.yy172->span); + if( yygotominor.yy172 ) yygotominor.yy172->flags |= EP_InfixFunc; } break; - case 208: /* expr ::= expr ISNULL|NOTNULL */ + case 205: /* expr ::= expr ISNULL|NOTNULL */ { - yygotominor.yy450 = sqlite3PExpr(pParse, yymsp[0].major, yymsp[-1].minor.yy450, 0, 0); - sqlite3ExprSpan(yygotominor.yy450,&yymsp[-1].minor.yy450->span,&yymsp[0].minor.yy0); + yygotominor.yy172 = sqlite3PExpr(pParse, yymsp[0].major, yymsp[-1].minor.yy172, 0, 0); + sqlite3ExprSpan(yygotominor.yy172,&yymsp[-1].minor.yy172->span,&yymsp[0].minor.yy0); } break; - case 209: /* expr ::= expr IS NULL */ + case 206: /* expr ::= expr IS NULL */ { - yygotominor.yy450 = sqlite3PExpr(pParse, TK_ISNULL, yymsp[-2].minor.yy450, 0, 0); - sqlite3ExprSpan(yygotominor.yy450,&yymsp[-2].minor.yy450->span,&yymsp[0].minor.yy0); + yygotominor.yy172 = sqlite3PExpr(pParse, TK_ISNULL, yymsp[-2].minor.yy172, 0, 0); + sqlite3ExprSpan(yygotominor.yy172,&yymsp[-2].minor.yy172->span,&yymsp[0].minor.yy0); } break; - case 210: /* expr ::= expr NOT NULL */ + case 207: /* expr ::= expr NOT NULL */ { - yygotominor.yy450 = sqlite3PExpr(pParse, TK_NOTNULL, yymsp[-2].minor.yy450, 0, 0); - sqlite3ExprSpan(yygotominor.yy450,&yymsp[-2].minor.yy450->span,&yymsp[0].minor.yy0); + yygotominor.yy172 = sqlite3PExpr(pParse, TK_NOTNULL, yymsp[-2].minor.yy172, 0, 0); + sqlite3ExprSpan(yygotominor.yy172,&yymsp[-2].minor.yy172->span,&yymsp[0].minor.yy0); } break; - case 211: /* expr ::= expr IS NOT NULL */ + case 208: /* expr ::= expr IS NOT NULL */ { - yygotominor.yy450 = sqlite3PExpr(pParse, TK_NOTNULL, yymsp[-3].minor.yy450, 0, 0); - sqlite3ExprSpan(yygotominor.yy450,&yymsp[-3].minor.yy450->span,&yymsp[0].minor.yy0); + yygotominor.yy172 = sqlite3PExpr(pParse, TK_NOTNULL, yymsp[-3].minor.yy172, 0, 0); + sqlite3ExprSpan(yygotominor.yy172,&yymsp[-3].minor.yy172->span,&yymsp[0].minor.yy0); } break; - case 212: /* expr ::= NOT expr */ - case 213: /* expr ::= BITNOT expr */ + case 209: /* expr ::= NOT expr */ + case 210: /* expr ::= BITNOT expr */ { - yygotominor.yy450 = sqlite3PExpr(pParse, yymsp[-1].major, yymsp[0].minor.yy450, 0, 0); - sqlite3ExprSpan(yygotominor.yy450,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy450->span); + yygotominor.yy172 = sqlite3PExpr(pParse, yymsp[-1].major, yymsp[0].minor.yy172, 0, 0); + sqlite3ExprSpan(yygotominor.yy172,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy172->span); } break; - case 214: /* expr ::= MINUS expr */ + case 211: /* expr ::= MINUS expr */ { - yygotominor.yy450 = sqlite3PExpr(pParse, TK_UMINUS, yymsp[0].minor.yy450, 0, 0); - sqlite3ExprSpan(yygotominor.yy450,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy450->span); + yygotominor.yy172 = sqlite3PExpr(pParse, TK_UMINUS, yymsp[0].minor.yy172, 0, 0); + sqlite3ExprSpan(yygotominor.yy172,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy172->span); } break; - case 215: /* expr ::= PLUS expr */ + case 212: /* expr ::= PLUS expr */ { - yygotominor.yy450 = sqlite3PExpr(pParse, TK_UPLUS, yymsp[0].minor.yy450, 0, 0); - sqlite3ExprSpan(yygotominor.yy450,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy450->span); + yygotominor.yy172 = sqlite3PExpr(pParse, TK_UPLUS, yymsp[0].minor.yy172, 0, 0); + sqlite3ExprSpan(yygotominor.yy172,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy172->span); } break; - case 218: /* expr ::= expr between_op expr AND expr */ + case 215: /* expr ::= expr between_op expr AND expr */ { - ExprList *pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy450, 0); - pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy450, 0); - yygotominor.yy450 = sqlite3PExpr(pParse, TK_BETWEEN, yymsp[-4].minor.yy450, 0, 0); - if( yygotominor.yy450 ){ - yygotominor.yy450->pList = pList; + ExprList *pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy172, 0); + pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy172, 0); + yygotominor.yy172 = sqlite3PExpr(pParse, TK_BETWEEN, yymsp[-4].minor.yy172, 0, 0); + if( yygotominor.yy172 ){ + yygotominor.yy172->pList = pList; }else{ - sqlite3ExprListDelete(pParse->db, pList); + sqlite3ExprListDelete(pList); } - if( yymsp[-3].minor.yy316 ) yygotominor.yy450 = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy450, 0, 0); - sqlite3ExprSpan(yygotominor.yy450,&yymsp[-4].minor.yy450->span,&yymsp[0].minor.yy450->span); + if( yymsp[-3].minor.yy46 ) yygotominor.yy172 = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy172, 0, 0); + sqlite3ExprSpan(yygotominor.yy172,&yymsp[-4].minor.yy172->span,&yymsp[0].minor.yy172->span); } break; - case 221: /* expr ::= expr in_op LP exprlist RP */ + case 218: /* expr ::= expr in_op LP exprlist RP */ { - yygotominor.yy450 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy450, 0, 0); - if( yygotominor.yy450 ){ - yygotominor.yy450->pList = yymsp[-1].minor.yy242; - sqlite3ExprSetHeight(pParse, yygotominor.yy450); + yygotominor.yy172 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy172, 0, 0); + if( yygotominor.yy172 ){ + yygotominor.yy172->pList = yymsp[-1].minor.yy174; + sqlite3ExprSetHeight(yygotominor.yy172); }else{ - sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy242); + sqlite3ExprListDelete(yymsp[-1].minor.yy174); } - if( yymsp[-3].minor.yy316 ) yygotominor.yy450 = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy450, 0, 0); - sqlite3ExprSpan(yygotominor.yy450,&yymsp[-4].minor.yy450->span,&yymsp[0].minor.yy0); + if( yymsp[-3].minor.yy46 ) yygotominor.yy172 = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy172, 0, 0); + sqlite3ExprSpan(yygotominor.yy172,&yymsp[-4].minor.yy172->span,&yymsp[0].minor.yy0); } break; - case 222: /* expr ::= LP select RP */ + case 219: /* expr ::= LP select RP */ { - yygotominor.yy450 = sqlite3PExpr(pParse, TK_SELECT, 0, 0, 0); - if( yygotominor.yy450 ){ - yygotominor.yy450->pSelect = yymsp[-1].minor.yy43; - sqlite3ExprSetHeight(pParse, yygotominor.yy450); + yygotominor.yy172 = sqlite3PExpr(pParse, TK_SELECT, 0, 0, 0); + if( yygotominor.yy172 ){ + yygotominor.yy172->pSelect = yymsp[-1].minor.yy219; + sqlite3ExprSetHeight(yygotominor.yy172); }else{ - sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy43); + sqlite3SelectDelete(yymsp[-1].minor.yy219); } - sqlite3ExprSpan(yygotominor.yy450,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); + sqlite3ExprSpan(yygotominor.yy172,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); } break; - case 223: /* expr ::= expr in_op LP select RP */ + case 220: /* expr ::= expr in_op LP select RP */ { - yygotominor.yy450 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy450, 0, 0); - if( yygotominor.yy450 ){ - yygotominor.yy450->pSelect = yymsp[-1].minor.yy43; - sqlite3ExprSetHeight(pParse, yygotominor.yy450); + yygotominor.yy172 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy172, 0, 0); + if( yygotominor.yy172 ){ + yygotominor.yy172->pSelect = yymsp[-1].minor.yy219; + sqlite3ExprSetHeight(yygotominor.yy172); }else{ - sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy43); + sqlite3SelectDelete(yymsp[-1].minor.yy219); } - if( yymsp[-3].minor.yy316 ) yygotominor.yy450 = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy450, 0, 0); - sqlite3ExprSpan(yygotominor.yy450,&yymsp[-4].minor.yy450->span,&yymsp[0].minor.yy0); + if( yymsp[-3].minor.yy46 ) yygotominor.yy172 = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy172, 0, 0); + sqlite3ExprSpan(yygotominor.yy172,&yymsp[-4].minor.yy172->span,&yymsp[0].minor.yy0); } break; - case 224: /* expr ::= expr in_op nm dbnm */ + case 221: /* expr ::= expr in_op nm dbnm */ { - SrcList *pSrc = sqlite3SrcListAppend(pParse->db, 0,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0); - yygotominor.yy450 = sqlite3PExpr(pParse, TK_IN, yymsp[-3].minor.yy450, 0, 0); - if( yygotominor.yy450 ){ - yygotominor.yy450->pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0,0); - sqlite3ExprSetHeight(pParse, yygotominor.yy450); + SrcList *pSrc = sqlite3SrcListAppend(pParse->db, 0,&yymsp[-1].minor.yy410,&yymsp[0].minor.yy410); + yygotominor.yy172 = sqlite3PExpr(pParse, TK_IN, yymsp[-3].minor.yy172, 0, 0); + if( yygotominor.yy172 ){ + yygotominor.yy172->pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0,0); + sqlite3ExprSetHeight(yygotominor.yy172); }else{ - sqlite3SrcListDelete(pParse->db, pSrc); + sqlite3SrcListDelete(pSrc); } - if( yymsp[-2].minor.yy316 ) yygotominor.yy450 = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy450, 0, 0); - sqlite3ExprSpan(yygotominor.yy450,&yymsp[-3].minor.yy450->span,yymsp[0].minor.yy0.z?&yymsp[0].minor.yy0:&yymsp[-1].minor.yy0); + if( yymsp[-2].minor.yy46 ) yygotominor.yy172 = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy172, 0, 0); + sqlite3ExprSpan(yygotominor.yy172,&yymsp[-3].minor.yy172->span,yymsp[0].minor.yy410.z?&yymsp[0].minor.yy410:&yymsp[-1].minor.yy410); } break; - case 225: /* expr ::= EXISTS LP select RP */ + case 222: /* expr ::= EXISTS LP select RP */ { - Expr *p = yygotominor.yy450 = sqlite3PExpr(pParse, TK_EXISTS, 0, 0, 0); + Expr *p = yygotominor.yy172 = sqlite3PExpr(pParse, TK_EXISTS, 0, 0, 0); if( p ){ - p->pSelect = yymsp[-1].minor.yy43; + p->pSelect = yymsp[-1].minor.yy219; sqlite3ExprSpan(p,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0); - sqlite3ExprSetHeight(pParse, yygotominor.yy450); + sqlite3ExprSetHeight(yygotominor.yy172); }else{ - sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy43); + sqlite3SelectDelete(yymsp[-1].minor.yy219); } } break; - case 226: /* expr ::= CASE case_operand case_exprlist case_else END */ + case 223: /* expr ::= CASE case_operand case_exprlist case_else END */ { - yygotominor.yy450 = sqlite3PExpr(pParse, TK_CASE, yymsp[-3].minor.yy450, yymsp[-1].minor.yy450, 0); - if( yygotominor.yy450 ){ - yygotominor.yy450->pList = yymsp[-2].minor.yy242; - sqlite3ExprSetHeight(pParse, yygotominor.yy450); + yygotominor.yy172 = sqlite3PExpr(pParse, TK_CASE, yymsp[-3].minor.yy172, yymsp[-1].minor.yy172, 0); + if( yygotominor.yy172 ){ + yygotominor.yy172->pList = yymsp[-2].minor.yy174; + sqlite3ExprSetHeight(yygotominor.yy172); }else{ - sqlite3ExprListDelete(pParse->db, yymsp[-2].minor.yy242); + sqlite3ExprListDelete(yymsp[-2].minor.yy174); } - sqlite3ExprSpan(yygotominor.yy450, &yymsp[-4].minor.yy0, &yymsp[0].minor.yy0); + sqlite3ExprSpan(yygotominor.yy172, &yymsp[-4].minor.yy0, &yymsp[0].minor.yy0); } break; - case 227: /* case_exprlist ::= case_exprlist WHEN expr THEN expr */ + case 224: /* case_exprlist ::= case_exprlist WHEN expr THEN expr */ { - yygotominor.yy242 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy242, yymsp[-2].minor.yy450, 0); - yygotominor.yy242 = sqlite3ExprListAppend(pParse,yygotominor.yy242, yymsp[0].minor.yy450, 0); + yygotominor.yy174 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy174, yymsp[-2].minor.yy172, 0); + yygotominor.yy174 = sqlite3ExprListAppend(pParse,yygotominor.yy174, yymsp[0].minor.yy172, 0); } break; - case 228: /* case_exprlist ::= WHEN expr THEN expr */ + case 225: /* case_exprlist ::= WHEN expr THEN expr */ { - yygotominor.yy242 = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy450, 0); - yygotominor.yy242 = sqlite3ExprListAppend(pParse,yygotominor.yy242, yymsp[0].minor.yy450, 0); + yygotominor.yy174 = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy172, 0); + yygotominor.yy174 = sqlite3ExprListAppend(pParse,yygotominor.yy174, yymsp[0].minor.yy172, 0); } break; - case 237: /* cmd ::= CREATE uniqueflag INDEX ifnotexists nm dbnm ON nm LP idxlist RP */ + case 234: /* cmd ::= CREATE uniqueflag INDEX ifnotexists nm dbnm ON nm LP idxlist RP */ { - sqlite3CreateIndex(pParse, &yymsp[-6].minor.yy0, &yymsp[-5].minor.yy0, - sqlite3SrcListAppend(pParse->db,0,&yymsp[-3].minor.yy0,0), yymsp[-1].minor.yy242, yymsp[-9].minor.yy316, - &yymsp[-10].minor.yy0, &yymsp[0].minor.yy0, SQLITE_SO_ASC, yymsp[-7].minor.yy316); + sqlite3CreateIndex(pParse, &yymsp[-6].minor.yy410, &yymsp[-5].minor.yy410, + sqlite3SrcListAppend(pParse->db,0,&yymsp[-3].minor.yy410,0), yymsp[-1].minor.yy174, yymsp[-9].minor.yy46, + &yymsp[-10].minor.yy0, &yymsp[0].minor.yy0, SQLITE_SO_ASC, yymsp[-7].minor.yy46); } break; - case 238: /* uniqueflag ::= UNIQUE */ - case 285: /* raisetype ::= ABORT */ -{yygotominor.yy316 = OE_Abort;} + case 235: /* uniqueflag ::= UNIQUE */ + case 283: /* raisetype ::= ABORT */ +{yygotominor.yy46 = OE_Abort;} break; - case 239: /* uniqueflag ::= */ -{yygotominor.yy316 = OE_None;} + case 236: /* uniqueflag ::= */ +{yygotominor.yy46 = OE_None;} break; - case 242: /* idxlist ::= idxlist COMMA nm collate sortorder */ + case 239: /* idxlist ::= idxlist COMMA idxitem collate sortorder */ { Expr *p = 0; - if( yymsp[-1].minor.yy0.n>0 ){ + if( yymsp[-1].minor.yy410.n>0 ){ p = sqlite3PExpr(pParse, TK_COLUMN, 0, 0, 0); - sqlite3ExprSetColl(pParse, p, &yymsp[-1].minor.yy0); + sqlite3ExprSetColl(pParse, p, &yymsp[-1].minor.yy410); } - yygotominor.yy242 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy242, p, &yymsp[-2].minor.yy0); - sqlite3ExprListCheckLength(pParse, yygotominor.yy242, "index"); - if( yygotominor.yy242 ) yygotominor.yy242->a[yygotominor.yy242->nExpr-1].sortOrder = yymsp[0].minor.yy316; + yygotominor.yy174 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy174, p, &yymsp[-2].minor.yy410); + sqlite3ExprListCheckLength(pParse, yygotominor.yy174, "index"); + if( yygotominor.yy174 ) yygotominor.yy174->a[yygotominor.yy174->nExpr-1].sortOrder = yymsp[0].minor.yy46; } break; - case 243: /* idxlist ::= nm collate sortorder */ + case 240: /* idxlist ::= idxitem collate sortorder */ { Expr *p = 0; - if( yymsp[-1].minor.yy0.n>0 ){ + if( yymsp[-1].minor.yy410.n>0 ){ p = sqlite3PExpr(pParse, TK_COLUMN, 0, 0, 0); - sqlite3ExprSetColl(pParse, p, &yymsp[-1].minor.yy0); + sqlite3ExprSetColl(pParse, p, &yymsp[-1].minor.yy410); } - yygotominor.yy242 = sqlite3ExprListAppend(pParse,0, p, &yymsp[-2].minor.yy0); - sqlite3ExprListCheckLength(pParse, yygotominor.yy242, "index"); - if( yygotominor.yy242 ) yygotominor.yy242->a[yygotominor.yy242->nExpr-1].sortOrder = yymsp[0].minor.yy316; + yygotominor.yy174 = sqlite3ExprListAppend(pParse,0, p, &yymsp[-2].minor.yy410); + sqlite3ExprListCheckLength(pParse, yygotominor.yy174, "index"); + if( yygotominor.yy174 ) yygotominor.yy174->a[yygotominor.yy174->nExpr-1].sortOrder = yymsp[0].minor.yy46; } break; - case 244: /* collate ::= */ -{yygotominor.yy0.z = 0; yygotominor.yy0.n = 0;} + case 242: /* collate ::= */ +{yygotominor.yy410.z = 0; yygotominor.yy410.n = 0;} break; - case 246: /* cmd ::= DROP INDEX ifexists fullname */ -{sqlite3DropIndex(pParse, yymsp[0].minor.yy419, yymsp[-1].minor.yy316);} + case 244: /* cmd ::= DROP INDEX ifexists fullname */ +{sqlite3DropIndex(pParse, yymsp[0].minor.yy373, yymsp[-1].minor.yy46);} break; - case 247: /* cmd ::= VACUUM */ - case 248: /* cmd ::= VACUUM nm */ + case 245: /* cmd ::= VACUUM */ + case 246: /* cmd ::= VACUUM nm */ {sqlite3Vacuum(pParse);} break; - case 249: /* cmd ::= PRAGMA nm dbnm EQ nmnum */ - case 250: /* cmd ::= PRAGMA nm dbnm EQ ON */ - case 251: /* cmd ::= PRAGMA nm dbnm EQ DELETE */ -{sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,0);} + case 247: /* cmd ::= PRAGMA nm dbnm EQ nmnum */ +{sqlite3Pragma(pParse,&yymsp[-3].minor.yy410,&yymsp[-2].minor.yy410,&yymsp[0].minor.yy410,0);} break; - case 252: /* cmd ::= PRAGMA nm dbnm EQ minus_num */ + case 248: /* cmd ::= PRAGMA nm dbnm EQ ON */ + case 249: /* cmd ::= PRAGMA nm dbnm EQ DELETE */ +{sqlite3Pragma(pParse,&yymsp[-3].minor.yy410,&yymsp[-2].minor.yy410,&yymsp[0].minor.yy0,0);} + break; + case 250: /* cmd ::= PRAGMA nm dbnm EQ minus_num */ { - sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,1); + sqlite3Pragma(pParse,&yymsp[-3].minor.yy410,&yymsp[-2].minor.yy410,&yymsp[0].minor.yy410,1); } break; - case 253: /* cmd ::= PRAGMA nm dbnm LP nmnum RP */ -{sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,0);} + case 251: /* cmd ::= PRAGMA nm dbnm LP nmnum RP */ +{sqlite3Pragma(pParse,&yymsp[-4].minor.yy410,&yymsp[-3].minor.yy410,&yymsp[-1].minor.yy410,0);} break; - case 254: /* cmd ::= PRAGMA nm dbnm */ -{sqlite3Pragma(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,0,0);} + case 252: /* cmd ::= PRAGMA nm dbnm */ +{sqlite3Pragma(pParse,&yymsp[-1].minor.yy410,&yymsp[0].minor.yy410,0,0);} break; - case 262: /* cmd ::= CREATE trigger_decl BEGIN trigger_cmd_list END */ + case 260: /* cmd ::= CREATE trigger_decl BEGIN trigger_cmd_list END */ { Token all; - all.z = yymsp[-3].minor.yy0.z; - all.n = (yymsp[0].minor.yy0.z - yymsp[-3].minor.yy0.z) + yymsp[0].minor.yy0.n; - sqlite3FinishTrigger(pParse, yymsp[-1].minor.yy75, &all); + all.z = yymsp[-3].minor.yy410.z; + all.n = (yymsp[0].minor.yy0.z - yymsp[-3].minor.yy410.z) + yymsp[0].minor.yy0.n; + sqlite3FinishTrigger(pParse, yymsp[-1].minor.yy243, &all); } break; - case 263: /* trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */ + case 261: /* trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */ { - sqlite3BeginTrigger(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0, yymsp[-5].minor.yy316, yymsp[-4].minor.yy354.a, yymsp[-4].minor.yy354.b, yymsp[-2].minor.yy419, yymsp[0].minor.yy450, yymsp[-10].minor.yy316, yymsp[-8].minor.yy316); - yygotominor.yy0 = (yymsp[-6].minor.yy0.n==0?yymsp[-7].minor.yy0:yymsp[-6].minor.yy0); + sqlite3BeginTrigger(pParse, &yymsp[-7].minor.yy410, &yymsp[-6].minor.yy410, yymsp[-5].minor.yy46, yymsp[-4].minor.yy370.a, yymsp[-4].minor.yy370.b, yymsp[-2].minor.yy373, yymsp[0].minor.yy172, yymsp[-10].minor.yy46, yymsp[-8].minor.yy46); + yygotominor.yy410 = (yymsp[-6].minor.yy410.n==0?yymsp[-7].minor.yy410:yymsp[-6].minor.yy410); } break; - case 264: /* trigger_time ::= BEFORE */ - case 267: /* trigger_time ::= */ -{ yygotominor.yy316 = TK_BEFORE; } + case 262: /* trigger_time ::= BEFORE */ + case 265: /* trigger_time ::= */ +{ yygotominor.yy46 = TK_BEFORE; } break; - case 265: /* trigger_time ::= AFTER */ -{ yygotominor.yy316 = TK_AFTER; } + case 263: /* trigger_time ::= AFTER */ +{ yygotominor.yy46 = TK_AFTER; } break; - case 266: /* trigger_time ::= INSTEAD OF */ -{ yygotominor.yy316 = TK_INSTEAD;} + case 264: /* trigger_time ::= INSTEAD OF */ +{ yygotominor.yy46 = TK_INSTEAD;} break; - case 268: /* trigger_event ::= DELETE|INSERT */ - case 269: /* trigger_event ::= UPDATE */ -{yygotominor.yy354.a = yymsp[0].major; yygotominor.yy354.b = 0;} + case 266: /* trigger_event ::= DELETE|INSERT */ + case 267: /* trigger_event ::= UPDATE */ +{yygotominor.yy370.a = yymsp[0].major; yygotominor.yy370.b = 0;} break; - case 270: /* trigger_event ::= UPDATE OF inscollist */ -{yygotominor.yy354.a = TK_UPDATE; yygotominor.yy354.b = yymsp[0].minor.yy352;} + case 268: /* trigger_event ::= UPDATE OF inscollist */ +{yygotominor.yy370.a = TK_UPDATE; yygotominor.yy370.b = yymsp[0].minor.yy432;} break; - case 273: /* when_clause ::= */ - case 290: /* key_opt ::= */ -{ yygotominor.yy450 = 0; } + case 271: /* when_clause ::= */ + case 288: /* key_opt ::= */ +{ yygotominor.yy172 = 0; } break; - case 274: /* when_clause ::= WHEN expr */ - case 291: /* key_opt ::= KEY expr */ -{ yygotominor.yy450 = yymsp[0].minor.yy450; } + case 272: /* when_clause ::= WHEN expr */ + case 289: /* key_opt ::= KEY expr */ +{ yygotominor.yy172 = yymsp[0].minor.yy172; } break; - case 275: /* trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */ + case 273: /* trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */ { -/* - if( yymsp[-2].minor.yy75 ){ - yymsp[-2].minor.yy75->pLast->pNext = yymsp[-1].minor.yy75; + if( yymsp[-2].minor.yy243 ){ + yymsp[-2].minor.yy243->pLast->pNext = yymsp[-1].minor.yy243; }else{ - yymsp[-2].minor.yy75 = yymsp[-1].minor.yy75; + yymsp[-2].minor.yy243 = yymsp[-1].minor.yy243; } -*/ - assert( yymsp[-2].minor.yy75!=0 ); - yymsp[-2].minor.yy75->pLast->pNext = yymsp[-1].minor.yy75; - yymsp[-2].minor.yy75->pLast = yymsp[-1].minor.yy75; - yygotominor.yy75 = yymsp[-2].minor.yy75; + yymsp[-2].minor.yy243->pLast = yymsp[-1].minor.yy243; + yygotominor.yy243 = yymsp[-2].minor.yy243; } break; - case 276: /* trigger_cmd_list ::= trigger_cmd SEMI */ -{ - /* if( yymsp[-1].minor.yy75 ) */ - assert( yymsp[-1].minor.yy75!=0 ); - yymsp[-1].minor.yy75->pLast = yymsp[-1].minor.yy75; - yygotominor.yy75 = yymsp[-1].minor.yy75; -} + case 274: /* trigger_cmd_list ::= */ +{ yygotominor.yy243 = 0; } break; - case 277: /* trigger_cmd ::= UPDATE orconf nm SET setlist where_opt */ -{ yygotominor.yy75 = sqlite3TriggerUpdateStep(pParse->db, &yymsp[-3].minor.yy0, yymsp[-1].minor.yy242, yymsp[0].minor.yy450, yymsp[-4].minor.yy316); } + case 275: /* trigger_cmd ::= UPDATE orconf nm SET setlist where_opt */ +{ yygotominor.yy243 = sqlite3TriggerUpdateStep(pParse->db, &yymsp[-3].minor.yy410, yymsp[-1].minor.yy174, yymsp[0].minor.yy172, yymsp[-4].minor.yy46); } break; - case 278: /* trigger_cmd ::= insert_cmd INTO nm inscollist_opt VALUES LP itemlist RP */ -{yygotominor.yy75 = sqlite3TriggerInsertStep(pParse->db, &yymsp[-5].minor.yy0, yymsp[-4].minor.yy352, yymsp[-1].minor.yy242, 0, yymsp[-7].minor.yy316);} + case 276: /* trigger_cmd ::= insert_cmd INTO nm inscollist_opt VALUES LP itemlist RP */ +{yygotominor.yy243 = sqlite3TriggerInsertStep(pParse->db, &yymsp[-5].minor.yy410, yymsp[-4].minor.yy432, yymsp[-1].minor.yy174, 0, yymsp[-7].minor.yy46);} break; - case 279: /* trigger_cmd ::= insert_cmd INTO nm inscollist_opt select */ -{yygotominor.yy75 = sqlite3TriggerInsertStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy352, 0, yymsp[0].minor.yy43, yymsp[-4].minor.yy316);} + case 277: /* trigger_cmd ::= insert_cmd INTO nm inscollist_opt select */ +{yygotominor.yy243 = sqlite3TriggerInsertStep(pParse->db, &yymsp[-2].minor.yy410, yymsp[-1].minor.yy432, 0, yymsp[0].minor.yy219, yymsp[-4].minor.yy46);} break; - case 280: /* trigger_cmd ::= DELETE FROM nm where_opt */ -{yygotominor.yy75 = sqlite3TriggerDeleteStep(pParse->db, &yymsp[-1].minor.yy0, yymsp[0].minor.yy450);} + case 278: /* trigger_cmd ::= DELETE FROM nm where_opt */ +{yygotominor.yy243 = sqlite3TriggerDeleteStep(pParse->db, &yymsp[-1].minor.yy410, yymsp[0].minor.yy172);} break; - case 281: /* trigger_cmd ::= select */ -{yygotominor.yy75 = sqlite3TriggerSelectStep(pParse->db, yymsp[0].minor.yy43); } + case 279: /* trigger_cmd ::= select */ +{yygotominor.yy243 = sqlite3TriggerSelectStep(pParse->db, yymsp[0].minor.yy219); } break; - case 282: /* expr ::= RAISE LP IGNORE RP */ + case 280: /* expr ::= RAISE LP IGNORE RP */ { - yygotominor.yy450 = sqlite3PExpr(pParse, TK_RAISE, 0, 0, 0); - if( yygotominor.yy450 ){ - yygotominor.yy450->iColumn = OE_Ignore; - sqlite3ExprSpan(yygotominor.yy450, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0); + yygotominor.yy172 = sqlite3PExpr(pParse, TK_RAISE, 0, 0, 0); + if( yygotominor.yy172 ){ + yygotominor.yy172->iColumn = OE_Ignore; + sqlite3ExprSpan(yygotominor.yy172, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0); } } break; - case 283: /* expr ::= RAISE LP raisetype COMMA nm RP */ + case 281: /* expr ::= RAISE LP raisetype COMMA nm RP */ { - yygotominor.yy450 = sqlite3PExpr(pParse, TK_RAISE, 0, 0, &yymsp[-1].minor.yy0); - if( yygotominor.yy450 ) { - yygotominor.yy450->iColumn = yymsp[-3].minor.yy316; - sqlite3ExprSpan(yygotominor.yy450, &yymsp[-5].minor.yy0, &yymsp[0].minor.yy0); + yygotominor.yy172 = sqlite3PExpr(pParse, TK_RAISE, 0, 0, &yymsp[-1].minor.yy410); + if( yygotominor.yy172 ) { + yygotominor.yy172->iColumn = yymsp[-3].minor.yy46; + sqlite3ExprSpan(yygotominor.yy172, &yymsp[-5].minor.yy0, &yymsp[0].minor.yy0); } } break; - case 284: /* raisetype ::= ROLLBACK */ -{yygotominor.yy316 = OE_Rollback;} + case 282: /* raisetype ::= ROLLBACK */ +{yygotominor.yy46 = OE_Rollback;} break; - case 286: /* raisetype ::= FAIL */ -{yygotominor.yy316 = OE_Fail;} + case 284: /* raisetype ::= FAIL */ +{yygotominor.yy46 = OE_Fail;} break; - case 287: /* cmd ::= DROP TRIGGER ifexists fullname */ + case 285: /* cmd ::= DROP TRIGGER ifexists fullname */ { - sqlite3DropTrigger(pParse,yymsp[0].minor.yy419,yymsp[-1].minor.yy316); + sqlite3DropTrigger(pParse,yymsp[0].minor.yy373,yymsp[-1].minor.yy46); } break; - case 288: /* cmd ::= ATTACH database_kw_opt expr AS expr key_opt */ + case 286: /* cmd ::= ATTACH database_kw_opt expr AS expr key_opt */ { - sqlite3Attach(pParse, yymsp[-3].minor.yy450, yymsp[-1].minor.yy450, yymsp[0].minor.yy450); + sqlite3Attach(pParse, yymsp[-3].minor.yy172, yymsp[-1].minor.yy172, yymsp[0].minor.yy172); } break; - case 289: /* cmd ::= DETACH database_kw_opt expr */ + case 287: /* cmd ::= DETACH database_kw_opt expr */ { - sqlite3Detach(pParse, yymsp[0].minor.yy450); + sqlite3Detach(pParse, yymsp[0].minor.yy172); } break; - case 294: /* cmd ::= REINDEX */ + case 292: /* cmd ::= REINDEX */ {sqlite3Reindex(pParse, 0, 0);} break; - case 295: /* cmd ::= REINDEX nm dbnm */ -{sqlite3Reindex(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);} + case 293: /* cmd ::= REINDEX nm dbnm */ +{sqlite3Reindex(pParse, &yymsp[-1].minor.yy410, &yymsp[0].minor.yy410);} break; - case 296: /* cmd ::= ANALYZE */ + case 294: /* cmd ::= ANALYZE */ {sqlite3Analyze(pParse, 0, 0);} break; - case 297: /* cmd ::= ANALYZE nm dbnm */ -{sqlite3Analyze(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);} + case 295: /* cmd ::= ANALYZE nm dbnm */ +{sqlite3Analyze(pParse, &yymsp[-1].minor.yy410, &yymsp[0].minor.yy410);} break; - case 298: /* cmd ::= ALTER TABLE fullname RENAME TO nm */ + case 296: /* cmd ::= ALTER TABLE fullname RENAME TO nm */ { - sqlite3AlterRenameTable(pParse,yymsp[-3].minor.yy419,&yymsp[0].minor.yy0); + sqlite3AlterRenameTable(pParse,yymsp[-3].minor.yy373,&yymsp[0].minor.yy410); } break; - case 299: /* cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt column */ + case 297: /* cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt column */ { - sqlite3AlterFinishAddColumn(pParse, &yymsp[0].minor.yy0); + sqlite3AlterFinishAddColumn(pParse, &yymsp[0].minor.yy410); } break; - case 300: /* add_column_fullname ::= fullname */ + case 298: /* add_column_fullname ::= fullname */ { - sqlite3AlterBeginAddColumn(pParse, yymsp[0].minor.yy419); + sqlite3AlterBeginAddColumn(pParse, yymsp[0].minor.yy373); } break; - case 303: /* cmd ::= create_vtab */ + case 301: /* cmd ::= create_vtab */ {sqlite3VtabFinishParse(pParse,0);} break; - case 304: /* cmd ::= create_vtab LP vtabarglist RP */ + case 302: /* cmd ::= create_vtab LP vtabarglist RP */ {sqlite3VtabFinishParse(pParse,&yymsp[0].minor.yy0);} break; - case 305: /* create_vtab ::= CREATE VIRTUAL TABLE nm dbnm USING nm */ + case 303: /* create_vtab ::= CREATE VIRTUAL TABLE nm dbnm USING nm */ { - sqlite3VtabBeginParse(pParse, &yymsp[-3].minor.yy0, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); + sqlite3VtabBeginParse(pParse, &yymsp[-3].minor.yy410, &yymsp[-2].minor.yy410, &yymsp[0].minor.yy410); } break; - case 308: /* vtabarg ::= */ + case 306: /* vtabarg ::= */ {sqlite3VtabArgInit(pParse);} break; - case 310: /* vtabargtoken ::= ANY */ - case 311: /* vtabargtoken ::= lp anylist RP */ - case 312: /* lp ::= LP */ - case 314: /* anylist ::= anylist ANY */ + case 308: /* vtabargtoken ::= ANY */ + case 309: /* vtabargtoken ::= lp anylist RP */ + case 310: /* lp ::= LP */ + case 312: /* anylist ::= anylist ANY */ {sqlite3VtabArgExtend(pParse,&yymsp[0].minor.yy0);} break; }; @@ -81942,7 +76079,7 @@ SQLITE_PRIVATE void sqlite3Parser( yyTracePrompt,yyTokenName[yymajor]); } #endif - yy_destructor(yypParser, yymajor,&yyminorunion); + yy_destructor(yymajor,&yyminorunion); yymajor = YYNOCODE; }else{ while( @@ -81955,7 +76092,7 @@ SQLITE_PRIVATE void sqlite3Parser( yy_pop_parser_stack(yypParser); } if( yypParser->yyidx < 0 || yymajor==0 ){ - yy_destructor(yypParser,yymajor,&yyminorunion); + yy_destructor(yymajor,&yyminorunion); yy_parse_failed(yypParser); yymajor = YYNOCODE; }else if( yymx!=YYERRORSYMBOL ){ @@ -81980,7 +76117,7 @@ SQLITE_PRIVATE void sqlite3Parser( yy_syntax_error(yypParser,yymajor,yyminorunion); } yypParser->yyerrcnt = 3; - yy_destructor(yypParser,yymajor,&yyminorunion); + yy_destructor(yymajor,&yyminorunion); if( yyendofinput ){ yy_parse_failed(yypParser); } @@ -82010,7 +76147,7 @@ SQLITE_PRIVATE void sqlite3Parser( ** individual tokens and sends those tokens one-by-one over to the ** parser for analysis. ** -** $Id: tokenize.c,v 1.152 2008/09/01 15:52:11 drh Exp $ +** $Id: tokenize.c,v 1.142 2008/04/28 18:46:43 drh Exp $ */ /* @@ -82063,7 +76200,7 @@ const unsigned char ebcdicToAscii[] = { ** ** The code in this file has been automatically generated by ** -** $Header: /sqlite/sqlite/tool/mkkeywordhash.c,v 1.32 2008/10/06 05:32:19 danielk1977 Exp $ +** $Header: /sqlite/sqlite/tool/mkkeywordhash.c,v 1.31 2007/07/30 18:26:20 rse Exp $ ** ** The code in this file implements a function that determines whether ** or not a given identifier is really an SQL keyword. The same thing @@ -82072,89 +76209,89 @@ const unsigned char ebcdicToAscii[] = { ** is substantially reduced. This is important for embedded applications ** on platforms with limited memory. */ -/* Hash score: 167 */ +/* Hash score: 165 */ static int keywordCode(const char *z, int n){ - /* zText[] encodes 783 bytes of keywords in 528 bytes */ - static const char zText[528] = - "REINDEXEDESCAPEACHECKEYBEFOREIGNOREGEXPLAINSTEADDATABASELECTABLE" - "FTHENDEFERRABLELSEXCEPTRANSACTIONATURALTERAISEXCLUSIVEXISTSCONSTRAINT" - "ERSECTRIGGEREFERENCESUNIQUERYATTACHAVINGROUPDATEMPORARYBEGINNER" - "ENAMEBETWEENOTNULLIKECASCADELETECASECOLLATECREATECURRENT_DATE" - "DETACHIMMEDIATEJOINSERTMATCHPLANALYZEPRAGMABORTVALUESVIRTUALIMIT" - "WHENWHEREPLACEAFTERESTRICTANDEFAULTAUTOINCREMENTCASTCOLUMNCOMMIT" - "CONFLICTCROSSCURRENT_TIMESTAMPRIMARYDEFERREDISTINCTDROPFAILFROM" - "FULLGLOBYIFINTOFFSETISNULLORDERIGHTOUTEROLLBACKROWUNIONUSINGVACUUM" + /* zText[] encodes 775 bytes of keywords in 526 bytes */ + static const char zText[526] = + "BEFOREIGNOREGEXPLAINSTEADDESCAPEACHECKEYCONSTRAINTERSECTABLEFT" + "HENDATABASELECTRANSACTIONATURALTERAISELSEXCEPTRIGGEREFERENCES" + "UNIQUERYATTACHAVINGROUPDATEMPORARYBEGINNEREINDEXCLUSIVEXISTSBETWEEN" + "OTNULLIKECASCADEFERRABLECASECOLLATECREATECURRENT_DATEDELETEDETACH" + "IMMEDIATEJOINSERTMATCHPLANALYZEPRAGMABORTVALUESVIRTUALIMITWHEN" + "WHERENAMEAFTEREPLACEANDEFAULTAUTOINCREMENTCASTCOLUMNCOMMITCONFLICT" + "CROSSCURRENT_TIMESTAMPRIMARYDEFERREDISTINCTDROPFAILFROMFULLGLOB" + "YIFINTOFFSETISNULLORDERESTRICTOUTERIGHTROLLBACKROWUNIONUSINGVACUUM" "VIEWINITIALLY"; static const unsigned char aHash[127] = { - 65, 94, 110, 63, 0, 44, 0, 0, 71, 0, 66, 0, 0, - 104, 12, 67, 15, 0, 108, 74, 105, 101, 0, 19, 0, 0, - 114, 0, 112, 78, 0, 22, 82, 0, 9, 0, 0, 59, 60, - 0, 58, 6, 0, 39, 79, 91, 0, 111, 90, 0, 0, 45, - 0, 92, 24, 0, 17, 0, 115, 40, 23, 0, 5, 99, 25, - 85, 0, 0, 117, 95, 50, 116, 47, 7, 42, 0, 80, 0, - 89, 26, 0, 88, 0, 0, 0, 84, 81, 86, 77, 98, 14, - 34, 97, 0, 70, 0, 18, 76, 100, 31, 0, 113, 69, 106, - 52, 46, 73, 0, 0, 83, 102, 0, 109, 0, 35, 0, 0, - 28, 0, 75, 48, 53, 0, 20, 51, 0, 43, + 63, 92, 109, 61, 0, 38, 0, 0, 69, 0, 64, 0, 0, + 102, 4, 65, 7, 0, 108, 72, 103, 99, 0, 22, 0, 0, + 113, 0, 111, 106, 0, 18, 80, 0, 1, 0, 0, 56, 57, + 0, 55, 11, 0, 33, 77, 89, 0, 110, 88, 0, 0, 45, + 0, 90, 54, 0, 20, 0, 114, 34, 19, 0, 10, 97, 28, + 83, 0, 0, 116, 93, 47, 115, 41, 12, 44, 0, 78, 0, + 87, 29, 0, 86, 0, 0, 0, 82, 79, 84, 75, 96, 6, + 14, 95, 0, 68, 0, 21, 76, 98, 27, 0, 112, 67, 104, + 49, 40, 71, 0, 0, 81, 100, 0, 107, 0, 15, 0, 0, + 24, 0, 73, 42, 50, 0, 16, 48, 0, 37, }; - static const unsigned char aNext[117] = { - 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 2, 0, 0, 0, 0, 0, 0, 13, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 3, 38, 0, 32, 21, 0, 0, 0, 0, 29, 0, - 0, 37, 0, 0, 0, 1, 55, 0, 0, 56, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 54, 0, 0, 0, 0, 30, 0, - 16, 33, 10, 0, 0, 0, 0, 0, 0, 0, 11, 61, 68, - 0, 8, 0, 93, 87, 0, 96, 0, 49, 0, 0, 64, 0, - 41, 103, 0, 27, 107, 36, 62, 72, 0, 0, 57, 0, 0, + static const unsigned char aNext[116] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, + 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 0, 0, + 17, 0, 0, 0, 36, 39, 0, 0, 25, 0, 0, 31, 0, + 0, 0, 43, 52, 0, 0, 0, 53, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 51, 0, 0, 0, 0, 26, 0, 8, 46, + 2, 0, 0, 0, 0, 0, 0, 0, 3, 58, 66, 0, 13, + 0, 91, 85, 0, 94, 0, 74, 0, 0, 62, 0, 35, 101, + 0, 0, 105, 23, 30, 60, 70, 0, 0, 59, 0, 0, }; - static const unsigned char aLen[117] = { - 7, 7, 5, 4, 6, 4, 5, 3, 6, 7, 3, 6, 6, - 7, 7, 3, 8, 2, 6, 5, 4, 4, 3, 10, 4, 6, - 11, 2, 7, 5, 5, 9, 6, 10, 9, 7, 10, 6, 5, - 6, 6, 5, 6, 4, 9, 2, 5, 5, 6, 7, 7, 3, - 4, 4, 7, 3, 6, 4, 7, 6, 12, 6, 9, 4, 6, - 5, 4, 7, 6, 5, 6, 7, 5, 4, 5, 7, 5, 8, - 3, 7, 13, 2, 2, 4, 6, 6, 8, 5, 17, 12, 7, - 8, 8, 2, 4, 4, 4, 4, 4, 2, 2, 4, 6, 2, - 3, 6, 5, 5, 5, 8, 3, 5, 5, 6, 4, 9, 3, + static const unsigned char aLen[116] = { + 6, 7, 3, 6, 6, 7, 7, 3, 4, 6, 4, 5, 3, + 10, 9, 5, 4, 4, 3, 8, 2, 6, 11, 2, 7, 5, + 5, 4, 6, 7, 10, 6, 5, 6, 6, 5, 6, 4, 9, + 2, 5, 5, 7, 5, 9, 6, 7, 7, 3, 4, 4, 7, + 3, 10, 4, 7, 6, 12, 6, 6, 9, 4, 6, 5, 4, + 7, 6, 5, 6, 7, 5, 4, 5, 6, 5, 7, 3, 7, + 13, 2, 2, 4, 6, 6, 8, 5, 17, 12, 7, 8, 8, + 2, 4, 4, 4, 4, 4, 2, 2, 4, 6, 2, 3, 6, + 5, 8, 5, 5, 8, 3, 5, 5, 6, 4, 9, 3, }; - static const unsigned short int aOffset[117] = { - 0, 2, 2, 8, 9, 14, 16, 20, 23, 25, 25, 29, 33, - 36, 41, 46, 48, 53, 54, 59, 62, 65, 67, 69, 78, 81, - 86, 95, 96, 101, 105, 109, 117, 123, 130, 138, 144, 154, 157, - 162, 167, 172, 175, 179, 179, 183, 188, 191, 195, 201, 207, 207, - 210, 213, 217, 218, 222, 228, 232, 239, 245, 257, 263, 272, 274, - 280, 285, 287, 294, 299, 304, 310, 316, 321, 325, 328, 335, 339, - 347, 349, 356, 358, 360, 369, 373, 379, 385, 393, 398, 398, 414, - 421, 428, 429, 436, 440, 444, 448, 452, 455, 457, 459, 462, 462, - 465, 468, 474, 478, 483, 487, 495, 498, 503, 508, 514, 518, 523, + static const unsigned short int aOffset[116] = { + 0, 2, 2, 6, 10, 13, 18, 23, 25, 26, 31, 33, 37, + 40, 47, 55, 58, 61, 63, 65, 70, 71, 76, 85, 86, 91, + 95, 99, 102, 107, 113, 123, 126, 131, 136, 141, 144, 148, 148, + 152, 157, 160, 164, 166, 169, 177, 183, 189, 189, 192, 195, 199, + 200, 204, 214, 218, 225, 231, 243, 249, 255, 264, 266, 272, 277, + 279, 286, 291, 296, 302, 308, 313, 317, 320, 326, 330, 337, 339, + 346, 348, 350, 359, 363, 369, 375, 383, 388, 388, 404, 411, 418, + 419, 426, 430, 434, 438, 442, 445, 447, 449, 452, 452, 455, 458, + 464, 468, 476, 480, 485, 493, 496, 501, 506, 512, 516, 521, }; - static const unsigned char aCode[117] = { - TK_REINDEX, TK_INDEXED, TK_INDEX, TK_DESC, TK_ESCAPE, - TK_EACH, TK_CHECK, TK_KEY, TK_BEFORE, TK_FOREIGN, - TK_FOR, TK_IGNORE, TK_LIKE_KW, TK_EXPLAIN, TK_INSTEAD, - TK_ADD, TK_DATABASE, TK_AS, TK_SELECT, TK_TABLE, - TK_JOIN_KW, TK_THEN, TK_END, TK_DEFERRABLE, TK_ELSE, - TK_EXCEPT, TK_TRANSACTION,TK_ON, TK_JOIN_KW, TK_ALTER, - TK_RAISE, TK_EXCLUSIVE, TK_EXISTS, TK_CONSTRAINT, TK_INTERSECT, - TK_TRIGGER, TK_REFERENCES, TK_UNIQUE, TK_QUERY, TK_ATTACH, - TK_HAVING, TK_GROUP, TK_UPDATE, TK_TEMP, TK_TEMP, - TK_OR, TK_BEGIN, TK_JOIN_KW, TK_RENAME, TK_BETWEEN, - TK_NOTNULL, TK_NOT, TK_NULL, TK_LIKE_KW, TK_CASCADE, - TK_ASC, TK_DELETE, TK_CASE, TK_COLLATE, TK_CREATE, - TK_CTIME_KW, TK_DETACH, TK_IMMEDIATE, TK_JOIN, TK_INSERT, - TK_MATCH, TK_PLAN, TK_ANALYZE, TK_PRAGMA, TK_ABORT, - TK_VALUES, TK_VIRTUAL, TK_LIMIT, TK_WHEN, TK_WHERE, - TK_REPLACE, TK_AFTER, TK_RESTRICT, TK_AND, TK_DEFAULT, - TK_AUTOINCR, TK_TO, TK_IN, TK_CAST, TK_COLUMNKW, - TK_COMMIT, TK_CONFLICT, TK_JOIN_KW, TK_CTIME_KW, TK_CTIME_KW, - TK_PRIMARY, TK_DEFERRED, TK_DISTINCT, TK_IS, TK_DROP, - TK_FAIL, TK_FROM, TK_JOIN_KW, TK_LIKE_KW, TK_BY, - TK_IF, TK_INTO, TK_OFFSET, TK_OF, TK_SET, - TK_ISNULL, TK_ORDER, TK_JOIN_KW, TK_JOIN_KW, TK_ROLLBACK, - TK_ROW, TK_UNION, TK_USING, TK_VACUUM, TK_VIEW, - TK_INITIALLY, TK_ALL, + static const unsigned char aCode[116] = { + TK_BEFORE, TK_FOREIGN, TK_FOR, TK_IGNORE, TK_LIKE_KW, + TK_EXPLAIN, TK_INSTEAD, TK_ADD, TK_DESC, TK_ESCAPE, + TK_EACH, TK_CHECK, TK_KEY, TK_CONSTRAINT, TK_INTERSECT, + TK_TABLE, TK_JOIN_KW, TK_THEN, TK_END, TK_DATABASE, + TK_AS, TK_SELECT, TK_TRANSACTION,TK_ON, TK_JOIN_KW, + TK_ALTER, TK_RAISE, TK_ELSE, TK_EXCEPT, TK_TRIGGER, + TK_REFERENCES, TK_UNIQUE, TK_QUERY, TK_ATTACH, TK_HAVING, + TK_GROUP, TK_UPDATE, TK_TEMP, TK_TEMP, TK_OR, + TK_BEGIN, TK_JOIN_KW, TK_REINDEX, TK_INDEX, TK_EXCLUSIVE, + TK_EXISTS, TK_BETWEEN, TK_NOTNULL, TK_NOT, TK_NULL, + TK_LIKE_KW, TK_CASCADE, TK_ASC, TK_DEFERRABLE, TK_CASE, + TK_COLLATE, TK_CREATE, TK_CTIME_KW, TK_DELETE, TK_DETACH, + TK_IMMEDIATE, TK_JOIN, TK_INSERT, TK_MATCH, TK_PLAN, + TK_ANALYZE, TK_PRAGMA, TK_ABORT, TK_VALUES, TK_VIRTUAL, + TK_LIMIT, TK_WHEN, TK_WHERE, TK_RENAME, TK_AFTER, + TK_REPLACE, TK_AND, TK_DEFAULT, TK_AUTOINCR, TK_TO, + TK_IN, TK_CAST, TK_COLUMNKW, TK_COMMIT, TK_CONFLICT, + TK_JOIN_KW, TK_CTIME_KW, TK_CTIME_KW, TK_PRIMARY, TK_DEFERRED, + TK_DISTINCT, TK_IS, TK_DROP, TK_FAIL, TK_FROM, + TK_JOIN_KW, TK_LIKE_KW, TK_BY, TK_IF, TK_INTO, + TK_OFFSET, TK_OF, TK_SET, TK_ISNULL, TK_ORDER, + TK_RESTRICT, TK_JOIN_KW, TK_JOIN_KW, TK_ROLLBACK, TK_ROW, + TK_UNION, TK_USING, TK_VACUUM, TK_VIEW, TK_INITIALLY, + TK_ALL, }; int h, i; if( n<2 ) return TK_ID; @@ -82239,7 +76376,7 @@ SQLITE_PRIVATE int sqlite3GetToken(const unsigned char *z, int *tokenType){ case '-': { if( z[1]=='-' ){ for(i=2; (c=z[i])!=0 && c!='\n'; i++){} - *tokenType = TK_SPACE; + *tokenType = TK_COMMENT; return i; } *tokenType = TK_MINUS; @@ -82272,7 +76409,7 @@ SQLITE_PRIVATE int sqlite3GetToken(const unsigned char *z, int *tokenType){ } for(i=3, c=z[2]; (c!='*' || z[i]!='/') && (c=z[i])!=0; i++){} if( c ) i++; - *tokenType = TK_SPACE; + *tokenType = TK_COMMENT; return i; } case '%': { @@ -82353,12 +76490,9 @@ SQLITE_PRIVATE int sqlite3GetToken(const unsigned char *z, int *tokenType){ } } } - if( c=='\'' ){ + if( c ){ *tokenType = TK_STRING; return i+1; - }else if( c!=0 ){ - *tokenType = TK_ID; - return i+1; }else{ *tokenType = TK_ILLEGAL; return i; @@ -82485,9 +76619,9 @@ SQLITE_PRIVATE int sqlite3GetToken(const unsigned char *z, int *tokenType){ /* ** Run the parser on the given SQL string. The parser structure is ** passed in. An SQLITE_ status code is returned. If an error occurs -** then an and attempt is made to write an error message into -** memory obtained from sqlite3_malloc() and to make *pzErrMsg point to that -** error message. +** and pzErrMsg!=NULL then an error message might be written into +** memory obtained from sqlite3_malloc() and *pzErrMsg made to point to that +** error message. Or maybe not. */ SQLITE_PRIVATE int sqlite3RunParser(Parse *pParse, const char *zSql, char **pzErrMsg){ int nErr = 0; @@ -82504,8 +76638,7 @@ SQLITE_PRIVATE int sqlite3RunParser(Parse *pParse, const char *zSql, char **pzEr pParse->rc = SQLITE_OK; pParse->zTail = pParse->zSql = zSql; i = 0; - assert( pzErrMsg!=0 ); - pEngine = sqlite3ParserAlloc((void*(*)(size_t))sqlite3Malloc); + pEngine = sqlite3ParserAlloc((void*(*)(size_t))sqlite3_malloc); if( pEngine==0 ){ db->mallocFailed = 1; return SQLITE_NOMEM; @@ -82528,18 +76661,21 @@ SQLITE_PRIVATE int sqlite3RunParser(Parse *pParse, const char *zSql, char **pzEr break; } switch( tokenType ){ - case TK_SPACE: { + case TK_SPACE: + case TK_COMMENT: { if( db->u1.isInterrupted ){ pParse->rc = SQLITE_INTERRUPT; - sqlite3SetString(pzErrMsg, db, "interrupt"); + sqlite3SetString(pzErrMsg, "interrupt", (char*)0); goto abort_parse; } break; } case TK_ILLEGAL: { - sqlite3DbFree(db, *pzErrMsg); - *pzErrMsg = sqlite3MPrintf(db, "unrecognized token: \"%T\"", - &pParse->sLastToken); + if( pzErrMsg ){ + sqlite3_free(*pzErrMsg); + *pzErrMsg = sqlite3MPrintf(db, "unrecognized token: \"%T\"", + &pParse->sLastToken); + } nErr++; goto abort_parse; } @@ -82565,23 +76701,18 @@ abort_parse: } sqlite3Parser(pEngine, 0, pParse->sLastToken, pParse); } -#ifdef YYTRACKMAXSTACKDEPTH - sqlite3StatusSet(SQLITE_STATUS_PARSER_STACK, - sqlite3ParserStackPeak(pEngine) - ); -#endif /* YYDEBUG */ sqlite3ParserFree(pEngine, sqlite3_free); if( db->mallocFailed ){ pParse->rc = SQLITE_NOMEM; } if( pParse->rc!=SQLITE_OK && pParse->rc!=SQLITE_DONE && pParse->zErrMsg==0 ){ - sqlite3SetString(&pParse->zErrMsg, db, "%s", sqlite3ErrStr(pParse->rc)); + sqlite3SetString(&pParse->zErrMsg, sqlite3ErrStr(pParse->rc), (char*)0); } if( pParse->zErrMsg ){ - if( *pzErrMsg==0 ){ + if( pzErrMsg && *pzErrMsg==0 ){ *pzErrMsg = pParse->zErrMsg; }else{ - sqlite3DbFree(db, pParse->zErrMsg); + sqlite3_free(pParse->zErrMsg); } pParse->zErrMsg = 0; nErr++; @@ -82592,13 +76723,13 @@ abort_parse: } #ifndef SQLITE_OMIT_SHARED_CACHE if( pParse->nested==0 ){ - sqlite3DbFree(db, pParse->aTableLock); + sqlite3_free(pParse->aTableLock); pParse->aTableLock = 0; pParse->nTableLock = 0; } #endif #ifndef SQLITE_OMIT_VIRTUALTABLE - sqlite3DbFree(db, pParse->apVtabLock); + sqlite3_free(pParse->apVtabLock); #endif if( !IN_DECLARE_VTAB ){ @@ -82609,14 +76740,8 @@ abort_parse: sqlite3DeleteTable(pParse->pNewTable); } - sqlite3DeleteTrigger(db, pParse->pNewTrigger); - sqlite3DbFree(db, pParse->apVarExpr); - sqlite3DbFree(db, pParse->aAlias); - while( pParse->pZombieTab ){ - Table *p = pParse->pZombieTab; - pParse->pZombieTab = p->pNextZombie; - sqlite3DeleteTable(p); - } + sqlite3DeleteTrigger(pParse->pNewTrigger); + sqlite3_free(pParse->apVarExpr); if( nErr>0 && (pParse->rc==SQLITE_OK || pParse->rc==SQLITE_DONE) ){ pParse->rc = SQLITE_ERROR; } @@ -82643,7 +76768,7 @@ abort_parse: ** separating it out, the code will be automatically omitted from ** static links that do not use it. ** -** $Id: complete.c,v 1.7 2008/06/13 18:24:27 drh Exp $ +** $Id: complete.c,v 1.6 2007/08/27 23:26:59 drh Exp $ */ #ifndef SQLITE_OMIT_COMPLETE @@ -82884,17 +77009,11 @@ SQLITE_API int sqlite3_complete16(const void *zSql){ char const *zSql8; int rc = SQLITE_NOMEM; -#ifndef SQLITE_OMIT_AUTOINIT - rc = sqlite3_initialize(); - if( rc ) return rc; -#endif pVal = sqlite3ValueNew(0); sqlite3ValueSetStr(pVal, -1, zSql, SQLITE_UTF16NATIVE, SQLITE_STATIC); zSql8 = sqlite3ValueText(pVal, SQLITE_UTF8); if( zSql8 ){ rc = sqlite3_complete(zSql8); - }else{ - rc = SQLITE_NOMEM; } sqlite3ValueFree(pVal); return sqlite3ApiExit(0, rc); @@ -82920,9 +77039,8 @@ SQLITE_API int sqlite3_complete16(const void *zSql){ ** other files are for internal use by SQLite and should not be ** accessed by users of the library. ** -** $Id: main.c,v 1.508 2008/10/12 00:27:53 shane Exp $ +** $Id: main.c,v 1.439 2008/05/13 13:27:34 drh Exp $ */ - #ifdef SQLITE_ENABLE_FTS3 /************** Include fts3.h in the middle of main.c ***********************/ /************** Begin file fts3.h ********************************************/ @@ -82955,71 +77073,6 @@ SQLITE_PRIVATE int sqlite3Fts3Init(sqlite3 *db); /************** End of fts3.h ************************************************/ /************** Continuing where we left off in main.c ***********************/ #endif -#ifdef SQLITE_ENABLE_RTREE -/************** Include rtree.h in the middle of main.c **********************/ -/************** Begin file rtree.h *******************************************/ -/* -** 2008 May 26 -** -** The author disclaims copyright to this source code. In place of -** a legal notice, here is a blessing: -** -** May you do good and not evil. -** May you find forgiveness for yourself and forgive others. -** May you share freely, never taking more than you give. -** -****************************************************************************** -** -** This header file is used by programs that want to link against the -** RTREE library. All it does is declare the sqlite3RtreeInit() interface. -*/ - -#if 0 -extern "C" { -#endif /* __cplusplus */ - -SQLITE_PRIVATE int sqlite3RtreeInit(sqlite3 *db); - -#if 0 -} /* extern "C" */ -#endif /* __cplusplus */ - -/************** End of rtree.h ***********************************************/ -/************** Continuing where we left off in main.c ***********************/ -#endif -#ifdef SQLITE_ENABLE_ICU -/************** Include sqliteicu.h in the middle of main.c ******************/ -/************** Begin file sqliteicu.h ***************************************/ -/* -** 2008 May 26 -** -** The author disclaims copyright to this source code. In place of -** a legal notice, here is a blessing: -** -** May you do good and not evil. -** May you find forgiveness for yourself and forgive others. -** May you share freely, never taking more than you give. -** -****************************************************************************** -** -** This header file is used by programs that want to link against the -** ICU extension. All it does is declare the sqlite3IcuInit() interface. -*/ - -#if 0 -extern "C" { -#endif /* __cplusplus */ - -SQLITE_PRIVATE int sqlite3IcuInit(sqlite3 *db); - -#if 0 -} /* extern "C" */ -#endif /* __cplusplus */ - - -/************** End of sqliteicu.h *******************************************/ -/************** Continuing where we left off in main.c ***********************/ -#endif /* ** The version of the library @@ -83048,389 +77101,6 @@ SQLITE_PRIVATE void (*sqlite3IoTrace)(const char*, ...) = 0; */ SQLITE_API char *sqlite3_temp_directory = 0; -/* -** Initialize SQLite. -** -** This routine must be called to initialize the memory allocation, -** VFS, and mutex subsystems prior to doing any serious work with -** SQLite. But as long as you do not compile with SQLITE_OMIT_AUTOINIT -** this routine will be called automatically by key routines such as -** sqlite3_open(). -** -** This routine is a no-op except on its very first call for the process, -** or for the first call after a call to sqlite3_shutdown. -** -** The first thread to call this routine runs the initialization to -** completion. If subsequent threads call this routine before the first -** thread has finished the initialization process, then the subsequent -** threads must block until the first thread finishes with the initialization. -** -** The first thread might call this routine recursively. Recursive -** calls to this routine should not block, of course. Otherwise the -** initialization process would never complete. -** -** Let X be the first thread to enter this routine. Let Y be some other -** thread. Then while the initial invocation of this routine by X is -** incomplete, it is required that: -** -** * Calls to this routine from Y must block until the outer-most -** call by X completes. -** -** * Recursive calls to this routine from thread X return immediately -** without blocking. -*/ -SQLITE_API int sqlite3_initialize(void){ - sqlite3_mutex *pMaster; /* The main static mutex */ - int rc; /* Result code */ - -#ifdef SQLITE_OMIT_WSD - rc = sqlite3_wsd_init(4096, 24); - if( rc!=SQLITE_OK ){ - return rc; - } -#endif - - /* If SQLite is already completely initialized, then this call - ** to sqlite3_initialize() should be a no-op. But the initialization - ** must be complete. So isInit must not be set until the very end - ** of this routine. - */ - if( sqlite3GlobalConfig.isInit ) return SQLITE_OK; - - /* Make sure the mutex subsystem is initialized. If unable to - ** initialize the mutex subsystem, return early with the error. - ** If the system is so sick that we are unable to allocate a mutex, - ** there is not much SQLite is going to be able to do. - ** - ** The mutex subsystem must take care of serializing its own - ** initialization. - */ - rc = sqlite3MutexInit(); - if( rc ) return rc; - - /* Initialize the malloc() system and the recursive pInitMutex mutex. - ** This operation is protected by the STATIC_MASTER mutex. Note that - ** MutexAlloc() is called for a static mutex prior to initializing the - ** malloc subsystem - this implies that the allocation of a static - ** mutex must not require support from the malloc subsystem. - */ - pMaster = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); - sqlite3_mutex_enter(pMaster); - if( !sqlite3GlobalConfig.isMallocInit ){ - rc = sqlite3MallocInit(); - } - if( rc==SQLITE_OK ){ - sqlite3GlobalConfig.isMallocInit = 1; - if( !sqlite3GlobalConfig.pInitMutex ){ - sqlite3GlobalConfig.pInitMutex = sqlite3MutexAlloc(SQLITE_MUTEX_RECURSIVE); - if( sqlite3GlobalConfig.bCoreMutex && !sqlite3GlobalConfig.pInitMutex ){ - rc = SQLITE_NOMEM; - } - } - } - if( rc==SQLITE_OK ){ - sqlite3GlobalConfig.nRefInitMutex++; - } - sqlite3_mutex_leave(pMaster); - - /* If unable to initialize the malloc subsystem, then return early. - ** There is little hope of getting SQLite to run if the malloc - ** subsystem cannot be initialized. - */ - if( rc!=SQLITE_OK ){ - return rc; - } - - /* Do the rest of the initialization under the recursive mutex so - ** that we will be able to handle recursive calls into - ** sqlite3_initialize(). The recursive calls normally come through - ** sqlite3_os_init() when it invokes sqlite3_vfs_register(), but other - ** recursive calls might also be possible. - */ - sqlite3_mutex_enter(sqlite3GlobalConfig.pInitMutex); - if( sqlite3GlobalConfig.isInit==0 && sqlite3GlobalConfig.inProgress==0 ){ - FuncDefHash *pHash = &GLOBAL(FuncDefHash, sqlite3GlobalFunctions); - sqlite3GlobalConfig.inProgress = 1; - memset(pHash, 0, sizeof(sqlite3GlobalFunctions)); - sqlite3RegisterGlobalFunctions(); - rc = sqlite3_os_init(); - if( rc==SQLITE_OK ){ - rc = sqlite3PcacheInitialize(); - sqlite3PCacheBufferSetup( sqlite3GlobalConfig.pPage, - sqlite3GlobalConfig.szPage, sqlite3GlobalConfig.nPage); - } - sqlite3GlobalConfig.inProgress = 0; - sqlite3GlobalConfig.isInit = (rc==SQLITE_OK ? 1 : 0); - } - sqlite3_mutex_leave(sqlite3GlobalConfig.pInitMutex); - - /* Go back under the static mutex and clean up the recursive - ** mutex to prevent a resource leak. - */ - sqlite3_mutex_enter(pMaster); - sqlite3GlobalConfig.nRefInitMutex--; - if( sqlite3GlobalConfig.nRefInitMutex<=0 ){ - assert( sqlite3GlobalConfig.nRefInitMutex==0 ); - sqlite3_mutex_free(sqlite3GlobalConfig.pInitMutex); - sqlite3GlobalConfig.pInitMutex = 0; - } - sqlite3_mutex_leave(pMaster); - - /* The following is just a sanity check to make sure SQLite has - ** been compiled correctly. It is important to run this code, but - ** we don't want to run it too often and soak up CPU cycles for no - ** reason. So we run it once during initialization. - */ -#ifndef NDEBUG - /* This section of code's only "output" is via assert() statements. */ - if ( rc==SQLITE_OK ){ - u64 x = (((u64)1)<<63)-1; - double y; - assert(sizeof(x)==8); - assert(sizeof(x)==sizeof(y)); - memcpy(&y, &x, 8); - assert( sqlite3IsNaN(y) ); - } -#endif - - return rc; -} - -/* -** Undo the effects of sqlite3_initialize(). Must not be called while -** there are outstanding database connections or memory allocations or -** while any part of SQLite is otherwise in use in any thread. This -** routine is not threadsafe. Not by a long shot. -*/ -SQLITE_API int sqlite3_shutdown(void){ - sqlite3GlobalConfig.isMallocInit = 0; - sqlite3PcacheShutdown(); - if( sqlite3GlobalConfig.isInit ){ - sqlite3_os_end(); - } - sqlite3MallocEnd(); - sqlite3MutexEnd(); - sqlite3GlobalConfig.isInit = 0; - return SQLITE_OK; -} - -/* -** This API allows applications to modify the global configuration of -** the SQLite library at run-time. -** -** This routine should only be called when there are no outstanding -** database connections or memory allocations. This routine is not -** threadsafe. Failure to heed these warnings can lead to unpredictable -** behavior. -*/ -SQLITE_API int sqlite3_config(int op, ...){ - va_list ap; - int rc = SQLITE_OK; - - /* sqlite3_config() shall return SQLITE_MISUSE if it is invoked while - ** the SQLite library is in use. */ - if( sqlite3GlobalConfig.isInit ) return SQLITE_MISUSE; - - va_start(ap, op); - switch( op ){ - - /* Mutex configuration options are only available in a threadsafe - ** compile. - */ -#if SQLITE_THREADSAFE - case SQLITE_CONFIG_SINGLETHREAD: { - /* Disable all mutexing */ - sqlite3GlobalConfig.bCoreMutex = 0; - sqlite3GlobalConfig.bFullMutex = 0; - break; - } - case SQLITE_CONFIG_MULTITHREAD: { - /* Disable mutexing of database connections */ - /* Enable mutexing of core data structures */ - sqlite3GlobalConfig.bCoreMutex = 1; - sqlite3GlobalConfig.bFullMutex = 0; - break; - } - case SQLITE_CONFIG_SERIALIZED: { - /* Enable all mutexing */ - sqlite3GlobalConfig.bCoreMutex = 1; - sqlite3GlobalConfig.bFullMutex = 1; - break; - } - case SQLITE_CONFIG_MUTEX: { - /* Specify an alternative mutex implementation */ - sqlite3GlobalConfig.mutex = *va_arg(ap, sqlite3_mutex_methods*); - break; - } - case SQLITE_CONFIG_GETMUTEX: { - /* Retrieve the current mutex implementation */ - *va_arg(ap, sqlite3_mutex_methods*) = sqlite3GlobalConfig.mutex; - break; - } -#endif - - - case SQLITE_CONFIG_MALLOC: { - /* Specify an alternative malloc implementation */ - sqlite3GlobalConfig.m = *va_arg(ap, sqlite3_mem_methods*); - break; - } - case SQLITE_CONFIG_GETMALLOC: { - /* Retrieve the current malloc() implementation */ - if( sqlite3GlobalConfig.m.xMalloc==0 ) sqlite3MemSetDefault(); - *va_arg(ap, sqlite3_mem_methods*) = sqlite3GlobalConfig.m; - break; - } - case SQLITE_CONFIG_MEMSTATUS: { - /* Enable or disable the malloc status collection */ - sqlite3GlobalConfig.bMemstat = va_arg(ap, int); - break; - } - case SQLITE_CONFIG_SCRATCH: { - /* Designate a buffer for scratch memory space */ - sqlite3GlobalConfig.pScratch = va_arg(ap, void*); - sqlite3GlobalConfig.szScratch = va_arg(ap, int); - sqlite3GlobalConfig.nScratch = va_arg(ap, int); - break; - } - case SQLITE_CONFIG_PAGECACHE: { - /* Designate a buffer for scratch memory space */ - sqlite3GlobalConfig.pPage = va_arg(ap, void*); - sqlite3GlobalConfig.szPage = va_arg(ap, int); - sqlite3GlobalConfig.nPage = va_arg(ap, int); - break; - } - -#if defined(SQLITE_ENABLE_MEMSYS3) || defined(SQLITE_ENABLE_MEMSYS5) - case SQLITE_CONFIG_HEAP: { - /* Designate a buffer for heap memory space */ - sqlite3GlobalConfig.pHeap = va_arg(ap, void*); - sqlite3GlobalConfig.nHeap = va_arg(ap, int); - sqlite3GlobalConfig.mnReq = va_arg(ap, int); - - if( sqlite3GlobalConfig.pHeap==0 ){ - /* If the heap pointer is NULL, then restore the malloc implementation - ** back to NULL pointers too. This will cause the malloc to go - ** back to its default implementation when sqlite3_initialize() is - ** run. - */ - memset(&sqlite3GlobalConfig.m, 0, sizeof(sqlite3GlobalConfig.m)); - }else{ - /* The heap pointer is not NULL, then install one of the - ** mem5.c/mem3.c methods. If neither ENABLE_MEMSYS3 nor - ** ENABLE_MEMSYS5 is defined, return an error. - ** the default case and return an error. - */ -#ifdef SQLITE_ENABLE_MEMSYS3 - sqlite3GlobalConfig.m = *sqlite3MemGetMemsys3(); -#endif -#ifdef SQLITE_ENABLE_MEMSYS5 - sqlite3GlobalConfig.m = *sqlite3MemGetMemsys5(); -#endif - } - break; - } -#endif - -#if defined(SQLITE_ENABLE_MEMSYS6) - case SQLITE_CONFIG_CHUNKALLOC: { - sqlite3GlobalConfig.nSmall = va_arg(ap, int); - sqlite3GlobalConfig.m = *sqlite3MemGetMemsys6(); - break; - } -#endif - - case SQLITE_CONFIG_LOOKASIDE: { - sqlite3GlobalConfig.szLookaside = va_arg(ap, int); - sqlite3GlobalConfig.nLookaside = va_arg(ap, int); - break; - } - - default: { - rc = SQLITE_ERROR; - break; - } - } - va_end(ap); - return rc; -} - -/* -** Set up the lookaside buffers for a database connection. -** Return SQLITE_OK on success. -** If lookaside is already active, return SQLITE_BUSY. -** -** The sz parameter is the number of bytes in each lookaside slot. -** The cnt parameter is the number of slots. If pStart is NULL the -** space for the lookaside memory is obtained from sqlite3_malloc(). -** If pStart is not NULL then it is sz*cnt bytes of memory to use for -** the lookaside memory. -*/ -static int setupLookaside(sqlite3 *db, void *pBuf, int sz, int cnt){ - void *pStart; - if( db->lookaside.nOut ){ - return SQLITE_BUSY; - } - if( sz<0 ) sz = 0; - if( cnt<0 ) cnt = 0; - if( pBuf==0 ){ - sz = (sz + 7)&~7; - sqlite3BeginBenignMalloc(); - pStart = sqlite3Malloc( sz*cnt ); - sqlite3EndBenignMalloc(); - }else{ - sz = sz&~7; - pStart = pBuf; - } - if( db->lookaside.bMalloced ){ - sqlite3_free(db->lookaside.pStart); - } - db->lookaside.pStart = pStart; - db->lookaside.pFree = 0; - db->lookaside.sz = sz; - db->lookaside.bMalloced = pBuf==0; - if( pStart ){ - int i; - LookasideSlot *p; - p = (LookasideSlot*)pStart; - for(i=cnt-1; i>=0; i--){ - p->pNext = db->lookaside.pFree; - db->lookaside.pFree = p; - p = (LookasideSlot*)&((u8*)p)[sz]; - } - db->lookaside.pEnd = p; - db->lookaside.bEnabled = 1; - }else{ - db->lookaside.pEnd = 0; - db->lookaside.bEnabled = 0; - } - return SQLITE_OK; -} - -/* -** Configuration settings for an individual database connection -*/ -SQLITE_API int sqlite3_db_config(sqlite3 *db, int op, ...){ - va_list ap; - int rc; - va_start(ap, op); - switch( op ){ - case SQLITE_DBCONFIG_LOOKASIDE: { - void *pBuf = va_arg(ap, void*); - int sz = va_arg(ap, int); - int cnt = va_arg(ap, int); - rc = setupLookaside(db, pBuf, sz, cnt); - break; - } - default: { - rc = SQLITE_ERROR; - break; - } - } - va_end(ap); - return rc; -} - /* ** Routine needed to support the testcase() macro. */ @@ -83576,17 +77246,14 @@ SQLITE_API int sqlite3_close(sqlite3 *db){ sqlite3ResetInternalSchema(db, 0); assert( db->nDb<=2 ); assert( db->aDb==db->aDbStatic ); - for(j=0; jaFunc.a); j++){ - FuncDef *pNext, *pHash, *p; - for(p=db->aFunc.a[j]; p; p=pHash){ - pHash = p->pHash; - while( p ){ - pNext = p->pNext; - sqlite3DbFree(db, p); - p = pNext; - } + for(i=sqliteHashFirst(&db->aFunc); i; i=sqliteHashNext(i)){ + FuncDef *pFunc, *pNext; + for(pFunc = (FuncDef*)sqliteHashData(i); pFunc; pFunc=pNext){ + pNext = pFunc->pNext; + sqlite3_free(pFunc); } } + for(i=sqliteHashFirst(&db->aCollSeq); i; i=sqliteHashNext(i)){ CollSeq *pColl = (CollSeq *)sqliteHashData(i); /* Invoke any destructors registered for collation sequence user data. */ @@ -83595,7 +77262,7 @@ SQLITE_API int sqlite3_close(sqlite3 *db){ pColl[j].xDel(pColl[j].pUser); } } - sqlite3DbFree(db, pColl); + sqlite3_free(pColl); } sqlite3HashClear(&db->aCollSeq); #ifndef SQLITE_OMIT_VIRTUALTABLE @@ -83604,11 +77271,12 @@ SQLITE_API int sqlite3_close(sqlite3 *db){ if( pMod->xDestroy ){ pMod->xDestroy(pMod->pAux); } - sqlite3DbFree(db, pMod); + sqlite3_free(pMod); } sqlite3HashClear(&db->aModule); #endif + sqlite3HashClear(&db->aFunc); sqlite3Error(db, SQLITE_OK, 0); /* Deallocates any cached error strings. */ if( db->pErr ){ sqlite3ValueFree(db->pErr); @@ -83623,14 +77291,10 @@ SQLITE_API int sqlite3_close(sqlite3 *db){ ** the same sqliteMalloc() as the one that allocates the database ** structure? */ - sqlite3DbFree(db, db->aDb[1].pSchema); + sqlite3_free(db->aDb[1].pSchema); sqlite3_mutex_leave(db->mutex); db->magic = SQLITE_MAGIC_CLOSED; sqlite3_mutex_free(db->mutex); - assert( db->lookaside.nOut==0 ); /* Fails on a lookaside memory leak */ - if( db->lookaside.bMalloced ){ - sqlite3_free(db->lookaside.pStart); - } sqlite3_free(db); return SQLITE_OK; } @@ -83642,7 +77306,7 @@ SQLITE_PRIVATE void sqlite3RollbackAll(sqlite3 *db){ int i; int inTrans = 0; assert( sqlite3_mutex_held(db->mutex) ); - sqlite3BeginBenignMalloc(); + sqlite3FaultBeginBenign(SQLITE_FAULTINJECTOR_MALLOC); for(i=0; inDb; i++){ if( db->aDb[i].pBt ){ if( sqlite3BtreeIsInTrans(db->aDb[i].pBt) ){ @@ -83653,7 +77317,7 @@ SQLITE_PRIVATE void sqlite3RollbackAll(sqlite3 *db){ } } sqlite3VtabRollback(db); - sqlite3EndBenignMalloc(); + sqlite3FaultEndBenign(SQLITE_FAULTINJECTOR_MALLOC); if( db->flags&SQLITE_InternChanges ){ sqlite3ExpirePreparedStatements(db); @@ -83714,7 +77378,7 @@ static int sqliteDefaultBusyCallback( void *ptr, /* Database connection */ int count /* Number of times table has been busy */ ){ -#if SQLITE_OS_WIN || (defined(HAVE_USLEEP) && HAVE_USLEEP) +#if OS_WIN || (defined(HAVE_USLEEP) && HAVE_USLEEP) static const u8 delays[] = { 1, 2, 5, 10, 15, 20, 25, 25, 25, 50, 50, 100 }; static const u8 totals[] = @@ -83758,7 +77422,7 @@ static int sqliteDefaultBusyCallback( */ SQLITE_PRIVATE int sqlite3InvokeBusyHandler(BusyHandler *p){ int rc; - if( NEVER(p==0) || p->xFunc==0 || p->nBusy<0 ) return 0; + if( p==0 || p->xFunc==0 || p->nBusy<0 ) return 0; rc = p->xFunc(p->pArg, p->nBusy); if( rc==0 ){ p->nBusy = -1; @@ -83797,17 +77461,19 @@ SQLITE_API void sqlite3_progress_handler( int (*xProgress)(void*), void *pArg ){ - sqlite3_mutex_enter(db->mutex); - if( nOps>0 ){ - db->xProgress = xProgress; - db->nProgressOps = nOps; - db->pProgressArg = pArg; - }else{ - db->xProgress = 0; - db->nProgressOps = 0; - db->pProgressArg = 0; + if( sqlite3SafetyCheckOk(db) ){ + sqlite3_mutex_enter(db->mutex); + if( nOps>0 ){ + db->xProgress = xProgress; + db->nProgressOps = nOps; + db->pProgressArg = pArg; + }else{ + db->xProgress = 0; + db->nProgressOps = 0; + db->pProgressArg = 0; + } + sqlite3_mutex_leave(db->mutex); } - sqlite3_mutex_leave(db->mutex); } #endif @@ -83830,7 +77496,9 @@ SQLITE_API int sqlite3_busy_timeout(sqlite3 *db, int ms){ ** Cause any pending operation to stop at its earliest opportunity. */ SQLITE_API void sqlite3_interrupt(sqlite3 *db){ - db->u1.isInterrupted = 1; + if( sqlite3SafetyCheckOk(db) ){ + db->u1.isInterrupted = 1; + } } @@ -83858,8 +77526,8 @@ SQLITE_PRIVATE int sqlite3CreateFunc( (xFunc && (xFinal || xStep)) || (!xFunc && (xFinal && !xStep)) || (!xFunc && (!xFinal && xStep)) || - (nArg<-1 || nArg>SQLITE_MAX_FUNCTION_ARG) || - (255<(nName = sqlite3Strlen(db, zFunctionName))) ){ + (nArg<-1 || nArg>127) || + (255<(nName = strlen(zFunctionName))) ){ sqlite3Error(db, SQLITE_ERROR, "bad parameters"); return SQLITE_ERROR; } @@ -83960,7 +77628,7 @@ SQLITE_API int sqlite3_create_function16( assert( !db->mallocFailed ); zFunc8 = sqlite3Utf16to8(db, zFunctionName, -1); rc = sqlite3CreateFunc(db, zFunc8, nArg, eTextRep, p, xFunc, xStep, xFinal); - sqlite3DbFree(db, zFunc8); + sqlite3_free(zFunc8); rc = sqlite3ApiExit(db, rc); sqlite3_mutex_leave(db->mutex); return rc; @@ -83985,7 +77653,7 @@ SQLITE_API int sqlite3_overload_function( const char *zName, int nArg ){ - int nName = sqlite3Strlen(db, zName); + int nName = strlen(zName); int rc; sqlite3_mutex_enter(db->mutex); if( sqlite3FindFunction(db, zName, nName, nArg, SQLITE_UTF8, 0)==0 ){ @@ -84105,19 +77773,19 @@ SQLITE_API void *sqlite3_rollback_hook( ** ** A virtual database can be either a disk file (that is automatically ** deleted when the file is closed) or it an be held entirely in memory, -** depending on the values of the SQLITE_TEMP_STORE compile-time macro and the +** depending on the values of the TEMP_STORE compile-time macro and the ** db->temp_store variable, according to the following chart: ** -** SQLITE_TEMP_STORE db->temp_store Location of temporary database -** ----------------- -------------- ------------------------------ -** 0 any file -** 1 1 file -** 1 2 memory -** 1 0 file -** 2 1 file -** 2 2 memory -** 2 0 memory -** 3 any memory +** TEMP_STORE db->temp_store Location of temporary database +** ---------- -------------- ------------------------------ +** 0 any file +** 1 1 file +** 1 2 memory +** 1 0 file +** 2 1 file +** 2 2 memory +** 2 0 memory +** 3 any memory */ SQLITE_PRIVATE int sqlite3BtreeFactory( const sqlite3 *db, /* Main database when opening aux otherwise 0 */ @@ -84139,17 +77807,17 @@ SQLITE_PRIVATE int sqlite3BtreeFactory( btFlags |= BTREE_NO_READLOCK; } if( zFilename==0 ){ -#if SQLITE_TEMP_STORE==0 +#if TEMP_STORE==0 /* Do nothing */ #endif #ifndef SQLITE_OMIT_MEMORYDB -#if SQLITE_TEMP_STORE==1 +#if TEMP_STORE==1 if( db->temp_store==2 ) zFilename = ":memory:"; #endif -#if SQLITE_TEMP_STORE==2 +#if TEMP_STORE==2 if( db->temp_store!=1 ) zFilename = ":memory:"; #endif -#if SQLITE_TEMP_STORE==3 +#if TEMP_STORE==3 zFilename = ":memory:"; #endif #endif /* SQLITE_OMIT_MEMORYDB */ @@ -84159,13 +77827,7 @@ SQLITE_PRIVATE int sqlite3BtreeFactory( vfsFlags = (vfsFlags & ~SQLITE_OPEN_MAIN_DB) | SQLITE_OPEN_TEMP_DB; } rc = sqlite3BtreeOpen(zFilename, (sqlite3 *)db, ppBtree, btFlags, vfsFlags); - - /* If the B-Tree was successfully opened, set the pager-cache size to the - ** default value. Except, if the call to BtreeOpen() returned a handle - ** open on an existing shared pager-cache, do not change the pager-cache - ** size. - */ - if( rc==SQLITE_OK && 0==sqlite3BtreeSchema(*ppBtree, 0, 0) ){ + if( rc==SQLITE_OK ){ sqlite3BtreeSetCacheSize(*ppBtree, nCache); } return rc; @@ -84180,13 +77842,12 @@ SQLITE_API const char *sqlite3_errmsg(sqlite3 *db){ if( !db ){ return sqlite3ErrStr(SQLITE_NOMEM); } - if( !sqlite3SafetyCheckSickOrOk(db) ){ + if( !sqlite3SafetyCheckSickOrOk(db) || db->errCode==SQLITE_MISUSE ){ return sqlite3ErrStr(SQLITE_MISUSE); } sqlite3_mutex_enter(db->mutex); assert( !db->mallocFailed ); z = (char*)sqlite3_value_text(db->pErr); - assert( !db->mallocFailed ); if( z==0 ){ z = sqlite3ErrStr(db->errCode); } @@ -84223,7 +77884,7 @@ SQLITE_API const void *sqlite3_errmsg16(sqlite3 *db){ if( !db ){ return (void *)(&outOfMemBe[SQLITE_UTF16NATIVE==SQLITE_UTF16LE?1:0]); } - if( !sqlite3SafetyCheckSickOrOk(db) ){ + if( !sqlite3SafetyCheckSickOrOk(db) || db->errCode==SQLITE_MISUSE ){ return (void *)(&misuseBe[SQLITE_UTF16NATIVE==SQLITE_UTF16LE?1:0]); } sqlite3_mutex_enter(db->mutex); @@ -84234,12 +77895,7 @@ SQLITE_API const void *sqlite3_errmsg16(sqlite3 *db){ SQLITE_UTF8, SQLITE_STATIC); z = sqlite3_value_text16(db->pErr); } - /* A malloc() may have failed within the call to sqlite3_value_text16() - ** above. If this is the case, then the db->mallocFailed flag needs to - ** be cleared before returning. Do this directly, instead of via - ** sqlite3ApiExit(), to avoid setting the database handle error message. - */ - db->mallocFailed = 0; + sqlite3ApiExit(0, 0); sqlite3_mutex_leave(db->mutex); return z; } @@ -84273,7 +77929,6 @@ static int createCollation( ){ CollSeq *pColl; int enc2; - int nName; assert( sqlite3_mutex_held(db->mutex) ); @@ -84285,16 +77940,17 @@ static int createCollation( if( enc2==SQLITE_UTF16 ){ enc2 = SQLITE_UTF16NATIVE; } + if( (enc2&~3)!=0 ){ - return SQLITE_MISUSE; + sqlite3Error(db, SQLITE_ERROR, "unknown encoding"); + return SQLITE_ERROR; } /* Check if this call is removing or replacing an existing collation ** sequence. If so, and there are active VMs, return busy. If there ** are no active VMs, invalidate any pre-compiled statements. */ - nName = sqlite3Strlen(db, zName); - pColl = sqlite3FindCollSeq(db, (u8)enc2, zName, nName, 0); + pColl = sqlite3FindCollSeq(db, (u8)enc2, zName, strlen(zName), 0); if( pColl && pColl->xCmp ){ if( db->activeVdbeCnt ){ sqlite3Error(db, SQLITE_BUSY, @@ -84310,7 +77966,7 @@ static int createCollation( ** to be called. */ if( (pColl->enc & ~SQLITE_UTF16_ALIGNED)==enc2 ){ - CollSeq *aColl = sqlite3HashFind(&db->aCollSeq, zName, nName); + CollSeq *aColl = sqlite3HashFind(&db->aCollSeq, zName, strlen(zName)); int j; for(j=0; j<3; j++){ CollSeq *p = &aColl[j]; @@ -84324,7 +77980,7 @@ static int createCollation( } } - pColl = sqlite3FindCollSeq(db, (u8)enc2, zName, nName, 1); + pColl = sqlite3FindCollSeq(db, (u8)enc2, zName, strlen(zName), 1); if( pColl ){ pColl->xCmp = xCompare; pColl->pUser = pCtx; @@ -84372,11 +78028,11 @@ static const int aHardLimit[] = { #if SQLITE_MAX_VDBE_OP<40 # error SQLITE_MAX_VDBE_OP must be at least 40 #endif -#if SQLITE_MAX_FUNCTION_ARG<0 || SQLITE_MAX_FUNCTION_ARG>1000 -# error SQLITE_MAX_FUNCTION_ARG must be between 0 and 1000 +#if SQLITE_MAX_FUNCTION_ARG<0 || SQLITE_MAX_FUNCTION_ARG>255 +# error SQLITE_MAX_FUNCTION_ARG must be between 0 and 255 #endif -#if SQLITE_MAX_ATTACHED<0 || SQLITE_MAX_ATTACHED>30 -# error SQLITE_MAX_ATTACHED must be between 0 and 30 +#if SQLITE_MAX_ATTACH<0 || SQLITE_MAX_ATTACH>30 +# error SQLITE_MAX_ATTACH must be between 0 and 30 #endif #if SQLITE_MAX_LIKE_PATTERN_LENGTH<1 # error SQLITE_MAX_LIKE_PATTERN_LENGTH must be at least 1 @@ -84384,9 +78040,6 @@ static const int aHardLimit[] = { #if SQLITE_MAX_VARIABLE_NUMBER<1 # error SQLITE_MAX_VARIABLE_NUMBER must be at least 1 #endif -#if SQLITE_MAX_COLUMN>32767 -# error SQLITE_MAX_COLUMN must not exceed 32767 -#endif /* @@ -84428,22 +78081,6 @@ static int openDatabase( sqlite3 *db; int rc; CollSeq *pColl; - int isThreadsafe; - -#ifndef SQLITE_OMIT_AUTOINIT - rc = sqlite3_initialize(); - if( rc ) return rc; -#endif - - if( sqlite3GlobalConfig.bCoreMutex==0 ){ - isThreadsafe = 0; - }else if( flags & SQLITE_OPEN_NOMUTEX ){ - isThreadsafe = 0; - }else if( flags & SQLITE_OPEN_FULLMUTEX ){ - isThreadsafe = 1; - }else{ - isThreadsafe = sqlite3GlobalConfig.bFullMutex; - } /* Remove harmful bits from the flags parameter */ flags &= ~( SQLITE_OPEN_DELETEONCLOSE | @@ -84453,21 +78090,17 @@ static int openDatabase( SQLITE_OPEN_MAIN_JOURNAL | SQLITE_OPEN_TEMP_JOURNAL | SQLITE_OPEN_SUBJOURNAL | - SQLITE_OPEN_MASTER_JOURNAL | - SQLITE_OPEN_NOMUTEX | - SQLITE_OPEN_FULLMUTEX + SQLITE_OPEN_MASTER_JOURNAL ); /* Allocate the sqlite data structure */ db = sqlite3MallocZero( sizeof(sqlite3) ); if( db==0 ) goto opendb_out; - if( isThreadsafe ){ - db->mutex = sqlite3MutexAlloc(SQLITE_MUTEX_RECURSIVE); - if( db->mutex==0 ){ - sqlite3_free(db); - db = 0; - goto opendb_out; - } + db->mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_RECURSIVE); + if( db->mutex==0 ){ + sqlite3_free(db); + db = 0; + goto opendb_out; } sqlite3_mutex_enter(db->mutex); db->errMask = 0xff; @@ -84475,7 +78108,6 @@ static int openDatabase( db->nDb = 2; db->magic = SQLITE_MAGIC_BUSY; db->aDb = db->aDbStatic; - assert( sizeof(db->aLimit)==sizeof(aHardLimit) ); memcpy(db->aLimit, aHardLimit, sizeof(db->aLimit)); db->autoCommit = 1; @@ -84489,14 +78121,16 @@ static int openDatabase( | SQLITE_LoadExtension #endif ; - sqlite3HashInit(&db->aCollSeq, 0); + sqlite3HashInit(&db->aFunc, SQLITE_HASH_STRING, 0); + sqlite3HashInit(&db->aCollSeq, SQLITE_HASH_STRING, 0); #ifndef SQLITE_OMIT_VIRTUALTABLE - sqlite3HashInit(&db->aModule, 0); + sqlite3HashInit(&db->aModule, SQLITE_HASH_STRING, 0); #endif db->pVfs = sqlite3_vfs_find(zVfs); if( !db->pVfs ){ rc = SQLITE_ERROR; + db->magic = SQLITE_MAGIC_SICK; sqlite3Error(db, rc, "no such vfs: %s", zVfs); goto opendb_out; } @@ -84510,6 +78144,7 @@ static int openDatabase( createCollation(db, "BINARY", SQLITE_UTF16LE, 0, binCollFunc, 0); createCollation(db, "RTRIM", SQLITE_UTF8, (void*)1, binCollFunc, 0); if( db->mallocFailed ){ + db->magic = SQLITE_MAGIC_SICK; goto opendb_out; } db->pDfltColl = sqlite3FindCollSeq(db, SQLITE_UTF8, "BINARY", 6, 0); @@ -84531,10 +78166,8 @@ static int openDatabase( flags | SQLITE_OPEN_MAIN_DB, &db->aDb[0].pBt); if( rc!=SQLITE_OK ){ - if( rc==SQLITE_IOERR_NOMEM ){ - rc = SQLITE_NOMEM; - } sqlite3Error(db, rc, 0); + db->magic = SQLITE_MAGIC_SICK; goto opendb_out; } db->aDb[0].pSchema = sqlite3SchemaGet(db, db->aDb[0].pBt); @@ -84593,16 +78226,10 @@ static int openDatabase( #ifdef SQLITE_ENABLE_ICU if( !db->mallocFailed && rc==SQLITE_OK ){ + extern int sqlite3IcuInit(sqlite3*); rc = sqlite3IcuInit(db); } #endif - -#ifdef SQLITE_ENABLE_RTREE - if( !db->mallocFailed && rc==SQLITE_OK){ - rc = sqlite3RtreeInit(db); - } -#endif - sqlite3Error(db, rc, 0); /* -DSQLITE_DEFAULT_LOCKING_MODE=1 makes EXCLUSIVE the default locking @@ -84615,21 +78242,14 @@ static int openDatabase( SQLITE_DEFAULT_LOCKING_MODE); #endif - /* Enable the lookaside-malloc subsystem */ - setupLookaside(db, 0, sqlite3GlobalConfig.szLookaside, - sqlite3GlobalConfig.nLookaside); - opendb_out: if( db ){ - assert( db->mutex!=0 || isThreadsafe==0 || sqlite3GlobalConfig.bFullMutex==0 ); + assert( db->mutex!=0 ); sqlite3_mutex_leave(db->mutex); } - rc = sqlite3_errcode(db); - if( rc==SQLITE_NOMEM ){ + if( SQLITE_NOMEM==(rc = sqlite3_errcode(db)) ){ sqlite3_close(db); db = 0; - }else if( rc!=SQLITE_OK ){ - db->magic = SQLITE_MAGIC_SICK; } *ppDb = db; return sqlite3ApiExit(0, rc); @@ -84664,15 +78284,11 @@ SQLITE_API int sqlite3_open16( ){ char const *zFilename8; /* zFilename encoded in UTF-8 instead of UTF-16 */ sqlite3_value *pVal; - int rc; + int rc = SQLITE_NOMEM; assert( zFilename ); assert( ppDb ); *ppDb = 0; -#ifndef SQLITE_OMIT_AUTOINIT - rc = sqlite3_initialize(); - if( rc ) return rc; -#endif pVal = sqlite3ValueNew(0); sqlite3ValueSetStr(pVal, -1, zFilename, SQLITE_UTF16NATIVE, SQLITE_STATIC); zFilename8 = sqlite3ValueText(pVal, SQLITE_UTF8); @@ -84683,8 +78299,6 @@ SQLITE_API int sqlite3_open16( if( rc==SQLITE_OK && !DbHasProperty(*ppDb, 0, DB_SchemaLoaded) ){ ENC(*ppDb) = SQLITE_UTF16NATIVE; } - }else{ - rc = SQLITE_NOMEM; } sqlite3ValueFree(pVal); @@ -84737,7 +78351,7 @@ SQLITE_API int sqlite3_create_collation_v2( */ SQLITE_API int sqlite3_create_collation16( sqlite3* db, - const void *zName, + const char *zName, int enc, void* pCtx, int(*xCompare)(void*,int,const void*,int,const void*) @@ -84749,7 +78363,7 @@ SQLITE_API int sqlite3_create_collation16( zName8 = sqlite3Utf16to8(db, zName, -1); if( zName8 ){ rc = createCollation(db, zName8, enc, pCtx, xCompare, 0); - sqlite3DbFree(db, zName8); + sqlite3_free(zName8); } rc = sqlite3ApiExit(db, rc); sqlite3_mutex_leave(db->mutex); @@ -84794,7 +78408,6 @@ SQLITE_API int sqlite3_collation_needed16( #endif /* SQLITE_OMIT_UTF16 */ #ifndef SQLITE_OMIT_GLOBALRECOVER -#ifndef SQLITE_OMIT_DEPRECATED /* ** This function is now an anachronism. It used to be used to recover from a ** malloc() failure, but SQLite now does this automatically. @@ -84803,7 +78416,6 @@ SQLITE_API int sqlite3_global_recover(void){ return SQLITE_OK; } #endif -#endif /* ** Test to see whether or not the database connection is in autocommit @@ -84828,7 +78440,6 @@ SQLITE_PRIVATE int sqlite3Corrupt(void){ } #endif -#ifndef SQLITE_OMIT_DEPRECATED /* ** This is a convenience routine that makes sure that all thread-specific ** data for this thread has been deallocated. @@ -84838,7 +78449,6 @@ SQLITE_PRIVATE int sqlite3Corrupt(void){ */ SQLITE_API void sqlite3_thread_cleanup(void){ } -#endif /* ** Return meta information about a specific column of a database table. @@ -84854,7 +78464,7 @@ SQLITE_API int sqlite3_table_column_metadata( char const **pzCollSeq, /* OUTPUT: Collation sequence name */ int *pNotNull, /* OUTPUT: True if NOT NULL constraint exists */ int *pPrimaryKey, /* OUTPUT: True if column part of PK */ - int *pAutoinc /* OUTPUT: True if column is auto-increment */ + int *pAutoinc /* OUTPUT: True if colums is auto-increment */ ){ int rc; char *zErrMsg = 0; @@ -84917,9 +78527,9 @@ SQLITE_API int sqlite3_table_column_metadata( if( pCol ){ zDataType = pCol->zType; zCollSeq = pCol->zColl; - notnull = pCol->notNull!=0; - primarykey = pCol->isPrimKey!=0; - autoinc = pTab->iPKey==iCol && (pTab->tabFlags & TF_Autoincrement)!=0; + notnull = (pCol->notNull?1:0); + primarykey = (pCol->isPrimKey?1:0); + autoinc = ((pTab->iPKey==iCol && pTab->autoInc)?1:0); }else{ zDataType = "INTEGER"; primarykey = 1; @@ -84942,13 +78552,12 @@ error_out: if( pAutoinc ) *pAutoinc = autoinc; if( SQLITE_OK==rc && !pTab ){ - sqlite3DbFree(db, zErrMsg); - zErrMsg = sqlite3MPrintf(db, "no such table column: %s.%s", zTableName, - zColumnName); + sqlite3SetString(&zErrMsg, "no such table column: ", zTableName, ".", + zColumnName, 0); rc = SQLITE_ERROR; } sqlite3Error(db, rc, (zErrMsg?"%s":0), zErrMsg); - sqlite3DbFree(db, zErrMsg); + sqlite3_free(zErrMsg); rc = sqlite3ApiExit(db, rc); sqlite3_mutex_leave(db->mutex); return rc; @@ -84962,7 +78571,6 @@ SQLITE_API int sqlite3_sleep(int ms){ sqlite3_vfs *pVfs; int rc; pVfs = sqlite3_vfs_find(0); - if( pVfs==0 ) return 0; /* This function works in milliseconds, but the underlying OsSleep() ** API uses microseconds. Hence the 1000's. @@ -85024,6 +78632,58 @@ SQLITE_API int sqlite3_test_control(int op, ...){ va_list ap; va_start(ap, op); switch( op ){ + /* + ** sqlite3_test_control(FAULT_CONFIG, fault_id, nDelay, nRepeat) + ** + ** Configure a fault injector. The specific fault injector is + ** identified by the fault_id argument. (ex: SQLITE_FAULTINJECTOR_MALLOC) + ** The fault will occur after a delay of nDelay calls. The fault + ** will repeat nRepeat times. + */ + case SQLITE_TESTCTRL_FAULT_CONFIG: { + int id = va_arg(ap, int); + int nDelay = va_arg(ap, int); + int nRepeat = va_arg(ap, int); + sqlite3FaultConfig(id, nDelay, nRepeat); + break; + } + + /* + ** sqlite3_test_control(FAULT_FAILURES, fault_id) + ** + ** Return the number of faults (both hard and benign faults) that have + ** occurred since the injector identified by fault_id) was last configured. + */ + case SQLITE_TESTCTRL_FAULT_FAILURES: { + int id = va_arg(ap, int); + rc = sqlite3FaultFailures(id); + break; + } + + /* + ** sqlite3_test_control(FAULT_BENIGN_FAILURES, fault_id) + ** + ** Return the number of benign faults that have occurred since the + ** injector identified by fault_id was last configured. + */ + case SQLITE_TESTCTRL_FAULT_BENIGN_FAILURES: { + int id = va_arg(ap, int); + rc = sqlite3FaultBenignFailures(id); + break; + } + + /* + ** sqlite3_test_control(FAULT_PENDING, fault_id) + ** + ** Return the number of successes that will occur before the next + ** scheduled failure on fault injector fault_id. + ** If no failures are scheduled, return -1. + */ + case SQLITE_TESTCTRL_FAULT_PENDING: { + int id = va_arg(ap, int); + rc = sqlite3FaultPending(id); + break; + } /* ** Save the current state of the PRNG. @@ -85067,22 +78727,6 @@ SQLITE_API int sqlite3_test_control(int op, ...){ rc = sqlite3BitvecBuiltinTest(sz, aProg); break; } - - /* - ** sqlite3_test_control(BENIGN_MALLOC_HOOKS, xBegin, xEnd) - ** - ** Register hooks to call to indicate which malloc() failures - ** are benign. - */ - case SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS: { - typedef void (*void_function)(void); - void_function xBenignBegin; - void_function xBenignEnd; - xBenignBegin = va_arg(ap, void_function); - xBenignEnd = va_arg(ap, void_function); - sqlite3BenignMallocHooks(xBenignBegin, xBenignEnd); - break; - } } va_end(ap); #endif /* SQLITE_OMIT_BUILTIN_TEST */ @@ -87172,7 +80816,7 @@ typedef struct QueryTerm { short int nPhrase; /* How many following terms are part of the same phrase */ short int iPhrase; /* This is the i-th term of a phrase. */ short int iColumn; /* Column of the index that must match this term */ - short int nNear; /* term followed by a NEAR operator with span=(nNear-1) */ + signed char nNear; /* term followed by a NEAR operator with span=(nNear-1) */ signed char isOr; /* this term is preceded by "OR" */ signed char isNot; /* this term is preceded by "-" */ signed char isPrefix; /* this term is followed by "*" */ @@ -87253,22 +80897,17 @@ typedef enum fulltext_statement { CONTENT_SELECT_STMT, CONTENT_UPDATE_STMT, CONTENT_DELETE_STMT, - CONTENT_EXISTS_STMT, BLOCK_INSERT_STMT, BLOCK_SELECT_STMT, BLOCK_DELETE_STMT, - BLOCK_DELETE_ALL_STMT, SEGDIR_MAX_INDEX_STMT, SEGDIR_SET_STMT, - SEGDIR_SELECT_LEVEL_STMT, + SEGDIR_SELECT_STMT, SEGDIR_SPAN_STMT, SEGDIR_DELETE_STMT, - SEGDIR_SELECT_SEGMENT_STMT, SEGDIR_SELECT_ALL_STMT, - SEGDIR_DELETE_ALL_STMT, - SEGDIR_COUNT_STMT, MAX_STMT /* Always at end! */ } fulltext_statement; @@ -87283,35 +80922,23 @@ static const char *const fulltext_zStatement[MAX_STMT] = { /* CONTENT_SELECT */ NULL, /* generated in contentSelectStatement() */ /* CONTENT_UPDATE */ NULL, /* generated in contentUpdateStatement() */ /* CONTENT_DELETE */ "delete from %_content where docid = ?", - /* CONTENT_EXISTS */ "select docid from %_content limit 1", /* BLOCK_INSERT */ "insert into %_segments (blockid, block) values (null, ?)", /* BLOCK_SELECT */ "select block from %_segments where blockid = ?", /* BLOCK_DELETE */ "delete from %_segments where blockid between ? and ?", - /* BLOCK_DELETE_ALL */ "delete from %_segments", /* SEGDIR_MAX_INDEX */ "select max(idx) from %_segdir where level = ?", /* SEGDIR_SET */ "insert into %_segdir values (?, ?, ?, ?, ?, ?)", - /* SEGDIR_SELECT_LEVEL */ + /* SEGDIR_SELECT */ "select start_block, leaves_end_block, root from %_segdir " " where level = ? order by idx", /* SEGDIR_SPAN */ "select min(start_block), max(end_block) from %_segdir " " where level = ? and start_block <> 0", /* SEGDIR_DELETE */ "delete from %_segdir where level = ?", - - /* NOTE(shess): The first three results of the following two - ** statements must match. - */ - /* SEGDIR_SELECT_SEGMENT */ - "select start_block, leaves_end_block, root from %_segdir " - " where level = ? and idx = ?", /* SEGDIR_SELECT_ALL */ - "select start_block, leaves_end_block, root from %_segdir " - " order by level desc, idx asc", - /* SEGDIR_DELETE_ALL */ "delete from %_segdir", - /* SEGDIR_COUNT */ "select count(*), ifnull(max(level),0) from %_segdir", + "select root, leaves_end_block from %_segdir order by level desc, idx", }; /* @@ -87476,18 +81103,15 @@ static int sql_single_step(sqlite3_stmt *s){ } /* Like sql_get_statement(), but for special replicated LEAF_SELECT -** statements. idx -1 is a special case for an uncached version of -** the statement (used in the optimize implementation). +** statements. */ /* TODO(shess) Write version for generic statements and then share ** that between the cached-statement functions. */ static int sql_get_leaf_statement(fulltext_vtab *v, int idx, sqlite3_stmt **ppStmt){ - assert( idx>=-1 && idxdb, v->zDb, v->zName, ppStmt, LEAF_SELECT); - }else if( v->pLeafSelectStmts[idx]==NULL ){ + assert( idx>=0 && idxpLeafSelectStmts[idx]==NULL ){ int rc = sql_prepare(v->db, v->zDb, v->zName, &v->pLeafSelectStmts[idx], LEAF_SELECT); if( rc!=SQLITE_OK ) return rc; @@ -87608,25 +81232,6 @@ static int content_delete(fulltext_vtab *v, sqlite_int64 iDocid){ return sql_single_step(s); } -/* Returns SQLITE_ROW if any rows exist in %_content, SQLITE_DONE if -** no rows exist, and any error in case of failure. -*/ -static int content_exists(fulltext_vtab *v){ - sqlite3_stmt *s; - int rc = sql_get_statement(v, CONTENT_EXISTS_STMT, &s); - if( rc!=SQLITE_OK ) return rc; - - rc = sqlite3_step(s); - if( rc!=SQLITE_ROW ) return rc; - - /* We expect only one row. We must execute another sqlite3_step() - * to complete the iteration; otherwise the table will remain locked. */ - rc = sqlite3_step(s); - if( rc==SQLITE_DONE ) return SQLITE_ROW; - if( rc==SQLITE_ROW ) return SQLITE_ERROR; - return rc; -} - /* insert into %_segments values ([pData]) ** returns assigned blockid in *piBlockid */ @@ -87801,54 +81406,6 @@ static int segdir_delete(fulltext_vtab *v, int iLevel){ return sql_single_step(s); } -/* Delete entire fts index, SQLITE_OK on success, relevant error on -** failure. -*/ -static int segdir_delete_all(fulltext_vtab *v){ - sqlite3_stmt *s; - int rc = sql_get_statement(v, SEGDIR_DELETE_ALL_STMT, &s); - if( rc!=SQLITE_OK ) return rc; - - rc = sql_single_step(s); - if( rc!=SQLITE_OK ) return rc; - - rc = sql_get_statement(v, BLOCK_DELETE_ALL_STMT, &s); - if( rc!=SQLITE_OK ) return rc; - - return sql_single_step(s); -} - -/* Returns SQLITE_OK with *pnSegments set to the number of entries in -** %_segdir and *piMaxLevel set to the highest level which has a -** segment. Otherwise returns the SQLite error which caused failure. -*/ -static int segdir_count(fulltext_vtab *v, int *pnSegments, int *piMaxLevel){ - sqlite3_stmt *s; - int rc = sql_get_statement(v, SEGDIR_COUNT_STMT, &s); - if( rc!=SQLITE_OK ) return rc; - - rc = sqlite3_step(s); - /* TODO(shess): This case should not be possible? Should stronger - ** measures be taken if it happens? - */ - if( rc==SQLITE_DONE ){ - *pnSegments = 0; - *piMaxLevel = 0; - return SQLITE_OK; - } - if( rc!=SQLITE_ROW ) return rc; - - *pnSegments = sqlite3_column_int(s, 0); - *piMaxLevel = sqlite3_column_int(s, 1); - - /* We expect only one row. We must execute another sqlite3_step() - * to complete the iteration; otherwise the table will remain locked. */ - rc = sqlite3_step(s); - if( rc==SQLITE_DONE ) return SQLITE_OK; - if( rc==SQLITE_ROW ) return SQLITE_ERROR; - return rc; -} - /* TODO(shess) clearPendingTerms() is far down the file because ** writeZeroSegment() is far down the file because LeafWriter is far ** down the file. Consider refactoring the code to move the non-vtab @@ -89153,10 +82710,10 @@ static int checkColumnSpecifier( } /* -** Parse the text at zSegment[0..nSegment-1]. Add additional terms +** Parse the text at pSegment[0..nSegment-1]. Add additional terms ** to the query being assemblied in pQuery. ** -** inPhrase is true if zSegment[0..nSegement-1] is contained within +** inPhrase is true if pSegment[0..nSegement-1] is contained within ** double-quotes. If inPhrase is true, then the first term ** is marked with the number of terms in the phrase less one and ** OR and "-" syntax is ignored. If inPhrase is false, then every @@ -89164,7 +82721,7 @@ static int checkColumnSpecifier( */ static int tokenizeSegment( sqlite3_tokenizer *pTokenizer, /* The tokenizer to use */ - const char *zSegment, int nSegment, /* Query expression being parsed */ + const char *pSegment, int nSegment, /* Query expression being parsed */ int inPhrase, /* True if within "..." */ Query *pQuery /* Append results here */ ){ @@ -89174,45 +82731,49 @@ static int tokenizeSegment( int iCol; int nTerm = 1; - int rc = pModule->xOpen(pTokenizer, zSegment, nSegment, &pCursor); + int rc = pModule->xOpen(pTokenizer, pSegment, nSegment, &pCursor); if( rc!=SQLITE_OK ) return rc; pCursor->pTokenizer = pTokenizer; while( 1 ){ - const char *zToken; + const char *pToken; int nToken, iBegin, iEnd, iPos; rc = pModule->xNext(pCursor, - &zToken, &nToken, + &pToken, &nToken, &iBegin, &iEnd, &iPos); if( rc!=SQLITE_OK ) break; if( !inPhrase && - zSegment[iEnd]==':' && - (iCol = checkColumnSpecifier(pQuery->pFts, zToken, nToken))>=0 ){ + pSegment[iEnd]==':' && + (iCol = checkColumnSpecifier(pQuery->pFts, pToken, nToken))>=0 ){ pQuery->nextColumn = iCol; continue; } if( !inPhrase && pQuery->nTerms>0 && nToken==2 - && zSegment[iBegin+0]=='O' - && zSegment[iBegin+1]=='R' + && pSegment[iBegin+0]=='O' + && pSegment[iBegin+1]=='R' ){ pQuery->nextIsOr = 1; continue; } if( !inPhrase && pQuery->nTerms>0 && !pQuery->nextIsOr && nToken==4 - && memcmp(&zSegment[iBegin], "NEAR", 4)==0 + && pSegment[iBegin+0]=='N' + && pSegment[iBegin+1]=='E' + && pSegment[iBegin+2]=='A' + && pSegment[iBegin+3]=='R' ){ QueryTerm *pTerm = &pQuery->pTerms[pQuery->nTerms-1]; if( (iBegin+6)='0' && pSegment[iBegin+5]<='9' ){ - int k; - pTerm->nNear = 0; - for(k=5; (iBegin+k)<=nSegment && isdigit(zSegment[iBegin+k]); k++){ - pTerm->nNear = pTerm->nNear*10 + (zSegment[iBegin+k] - '0'); + pTerm->nNear = (pSegment[iBegin+5] - '0'); + nToken += 2; + if( pSegment[iBegin+6]>='0' && pSegment[iBegin+6]<=9 ){ + pTerm->nNear = pTerm->nNear * 10 + (pSegment[iBegin+6] - '0'); + iEnd++; } - pModule->xNext(pCursor, &zToken, &nToken, &iBegin, &iEnd, &iPos); + pModule->xNext(pCursor, &pToken, &nToken, &iBegin, &iEnd, &iPos); } else { pTerm->nNear = SQLITE_FTS3_DEFAULT_NEAR_PARAM; } @@ -89220,11 +82781,11 @@ static int tokenizeSegment( continue; } - queryAdd(pQuery, zToken, nToken); - if( !inPhrase && iBegin>0 && zSegment[iBegin-1]=='-' ){ + queryAdd(pQuery, pToken, nToken); + if( !inPhrase && iBegin>0 && pSegment[iBegin-1]=='-' ){ pQuery->pTerms[pQuery->nTerms-1].isNot = 1; } - if( iEndpTerms[pQuery->nTerms-1].isPrefix = 1; } pQuery->pTerms[pQuery->nTerms-1].iPhrase = nTerm; @@ -89446,43 +83007,21 @@ static int fulltextFilter( fulltext_cursor *c = (fulltext_cursor *) pCursor; fulltext_vtab *v = cursor_vtab(c); int rc; + StringBuffer sb; FTSTRACE(("FTS3 Filter %p\n",pCursor)); - /* If the cursor has a statement that was not prepared according to - ** idxNum, clear it. I believe all calls to fulltextFilter with a - ** given cursor will have the same idxNum , but in this case it's - ** easy to be safe. - */ - if( c->pStmt && c->iCursorType!=idxNum ){ - sqlite3_finalize(c->pStmt); - c->pStmt = NULL; - } - - /* Get a fresh statement appropriate to idxNum. */ - /* TODO(shess): Add a prepared-statement cache in the vt structure. - ** The cache must handle multiple open cursors. Easier to cache the - ** statement variants at the vt to reduce malloc/realloc/free here. - ** Or we could have a StringBuffer variant which allowed stack - ** construction for small values. - */ - if( !c->pStmt ){ - StringBuffer sb; - initStringBuffer(&sb); - append(&sb, "SELECT docid, "); - appendList(&sb, v->nColumn, v->azContentColumn); - append(&sb, " FROM %_content"); - if( idxNum!=QUERY_GENERIC ) append(&sb, " WHERE docid = ?"); - rc = sql_prepare(v->db, v->zDb, v->zName, &c->pStmt, - stringBufferData(&sb)); - stringBufferDestroy(&sb); - if( rc!=SQLITE_OK ) return rc; - c->iCursorType = idxNum; - }else{ - sqlite3_reset(c->pStmt); - assert( c->iCursorType==idxNum ); - } + initStringBuffer(&sb); + append(&sb, "SELECT docid, "); + appendList(&sb, v->nColumn, v->azContentColumn); + append(&sb, " FROM %_content"); + if( idxNum!=QUERY_GENERIC ) append(&sb, " WHERE docid = ?"); + sqlite3_finalize(c->pStmt); + rc = sql_prepare(v->db, v->zDb, v->zName, &c->pStmt, stringBufferData(&sb)); + stringBufferDestroy(&sb); + if( rc!=SQLITE_OK ) return rc; + c->iCursorType = idxNum; switch( idxNum ){ case QUERY_GENERIC: break; @@ -90742,12 +84281,6 @@ static int leavesReaderReset(LeavesReader *pReader){ } static void leavesReaderDestroy(LeavesReader *pReader){ - /* If idx is -1, that means we're using a non-cached statement - ** handle in the optimize() case, so we need to release it. - */ - if( pReader->pStmt!=NULL && pReader->idx==-1 ){ - sqlite3_finalize(pReader->pStmt); - } leafReaderDestroy(&pReader->leafReader); dataBufferDestroy(&pReader->rootData); SCRAMBLE(pReader); @@ -90868,7 +84401,7 @@ static void leavesReaderReorder(LeavesReader *pLr, int nLr){ static int leavesReadersInit(fulltext_vtab *v, int iLevel, LeavesReader *pReaders, int *piReaders){ sqlite3_stmt *s; - int i, rc = sql_get_statement(v, SEGDIR_SELECT_LEVEL_STMT, &s); + int i, rc = sql_get_statement(v, SEGDIR_SELECT_STMT, &s); if( rc!=SQLITE_OK ) return rc; rc = sqlite3_bind_int(s, 1, iLevel); @@ -91406,8 +84939,8 @@ static int termSelect(fulltext_vtab *v, int iColumn, ** elements for given docids overwrite older elements. */ while( (rc = sqlite3_step(s))==SQLITE_ROW ){ - const char *pData = sqlite3_column_blob(s, 2); - const int nData = sqlite3_column_bytes(s, 2); + const char *pData = sqlite3_column_blob(s, 0); + const int nData = sqlite3_column_bytes(s, 0); const sqlite_int64 iLeavesEnd = sqlite3_column_int64(s, 1); rc = loadSegment(v, pData, nData, iLeavesEnd, pTerm, nTerm, isPrefix, &doclist); @@ -91561,23 +85094,6 @@ static int fulltextUpdate(sqlite3_vtab *pVtab, int nArg, sqlite3_value **ppArg, if( nArg<2 ){ rc = index_delete(v, sqlite3_value_int64(ppArg[0])); - if( rc==SQLITE_OK ){ - /* If we just deleted the last row in the table, clear out the - ** index data. - */ - rc = content_exists(v); - if( rc==SQLITE_ROW ){ - rc = SQLITE_OK; - }else if( rc==SQLITE_DONE ){ - /* Clear the pending terms so we don't flush a useless level-0 - ** segment when the transaction closes. - */ - rc = clearPendingTerms(v); - if( rc==SQLITE_OK ){ - rc = segdir_delete_all(v); - } - } - } } else if( sqlite3_value_type(ppArg[0]) != SQLITE_NULL ){ /* An update: * ppArg[0] = old rowid @@ -91714,665 +85230,6 @@ static void snippetOffsetsFunc( } } -/* OptLeavesReader is nearly identical to LeavesReader, except that -** where LeavesReader is geared towards the merging of complete -** segment levels (with exactly MERGE_COUNT segments), OptLeavesReader -** is geared towards implementation of the optimize() function, and -** can merge all segments simultaneously. This version may be -** somewhat less efficient than LeavesReader because it merges into an -** accumulator rather than doing an N-way merge, but since segment -** size grows exponentially (so segment count logrithmically) this is -** probably not an immediate problem. -*/ -/* TODO(shess): Prove that assertion, or extend the merge code to -** merge tree fashion (like the prefix-searching code does). -*/ -/* TODO(shess): OptLeavesReader and LeavesReader could probably be -** merged with little or no loss of performance for LeavesReader. The -** merged code would need to handle >MERGE_COUNT segments, and would -** also need to be able to optionally optimize away deletes. -*/ -typedef struct OptLeavesReader { - /* Segment number, to order readers by age. */ - int segment; - LeavesReader reader; -} OptLeavesReader; - -static int optLeavesReaderAtEnd(OptLeavesReader *pReader){ - return leavesReaderAtEnd(&pReader->reader); -} -static int optLeavesReaderTermBytes(OptLeavesReader *pReader){ - return leavesReaderTermBytes(&pReader->reader); -} -static const char *optLeavesReaderData(OptLeavesReader *pReader){ - return leavesReaderData(&pReader->reader); -} -static int optLeavesReaderDataBytes(OptLeavesReader *pReader){ - return leavesReaderDataBytes(&pReader->reader); -} -static const char *optLeavesReaderTerm(OptLeavesReader *pReader){ - return leavesReaderTerm(&pReader->reader); -} -static int optLeavesReaderStep(fulltext_vtab *v, OptLeavesReader *pReader){ - return leavesReaderStep(v, &pReader->reader); -} -static int optLeavesReaderTermCmp(OptLeavesReader *lr1, OptLeavesReader *lr2){ - return leavesReaderTermCmp(&lr1->reader, &lr2->reader); -} -/* Order by term ascending, segment ascending (oldest to newest), with -** exhausted readers to the end. -*/ -static int optLeavesReaderCmp(OptLeavesReader *lr1, OptLeavesReader *lr2){ - int c = optLeavesReaderTermCmp(lr1, lr2); - if( c!=0 ) return c; - return lr1->segment-lr2->segment; -} -/* Bubble pLr[0] to appropriate place in pLr[1..nLr-1]. Assumes that -** pLr[1..nLr-1] is already sorted. -*/ -static void optLeavesReaderReorder(OptLeavesReader *pLr, int nLr){ - while( nLr>1 && optLeavesReaderCmp(pLr, pLr+1)>0 ){ - OptLeavesReader tmp = pLr[0]; - pLr[0] = pLr[1]; - pLr[1] = tmp; - nLr--; - pLr++; - } -} - -/* optimize() helper function. Put the readers in order and iterate -** through them, merging doclists for matching terms into pWriter. -** Returns SQLITE_OK on success, or the SQLite error code which -** prevented success. -*/ -static int optimizeInternal(fulltext_vtab *v, - OptLeavesReader *readers, int nReaders, - LeafWriter *pWriter){ - int i, rc = SQLITE_OK; - DataBuffer doclist, merged, tmp; - - /* Order the readers. */ - i = nReaders; - while( i-- > 0 ){ - optLeavesReaderReorder(&readers[i], nReaders-i); - } - - dataBufferInit(&doclist, LEAF_MAX); - dataBufferInit(&merged, LEAF_MAX); - - /* Exhausted readers bubble to the end, so when the first reader is - ** at eof, all are at eof. - */ - while( !optLeavesReaderAtEnd(&readers[0]) ){ - - /* Figure out how many readers share the next term. */ - for(i=1; i 0 ){ - dlrDestroy(&dlReaders[nReaders]); - } - - /* Accumulated doclist to reader 0 for next pass. */ - dlrInit(&dlReaders[0], DL_DEFAULT, doclist.pData, doclist.nData); - } - - /* Destroy reader that was left in the pipeline. */ - dlrDestroy(&dlReaders[0]); - - /* Trim deletions from the doclist. */ - dataBufferReset(&merged); - docListTrim(DL_DEFAULT, doclist.pData, doclist.nData, - -1, DL_DEFAULT, &merged); - } - - /* Only pass doclists with hits (skip if all hits deleted). */ - if( merged.nData>0 ){ - rc = leafWriterStep(v, pWriter, - optLeavesReaderTerm(&readers[0]), - optLeavesReaderTermBytes(&readers[0]), - merged.pData, merged.nData); - if( rc!=SQLITE_OK ) goto err; - } - - /* Step merged readers to next term and reorder. */ - while( i-- > 0 ){ - rc = optLeavesReaderStep(v, &readers[i]); - if( rc!=SQLITE_OK ) goto err; - - optLeavesReaderReorder(&readers[i], nReaders-i); - } - } - - err: - dataBufferDestroy(&doclist); - dataBufferDestroy(&merged); - return rc; -} - -/* Implement optimize() function for FTS3. optimize(t) merges all -** segments in the fts index into a single segment. 't' is the magic -** table-named column. -*/ -static void optimizeFunc(sqlite3_context *pContext, - int argc, sqlite3_value **argv){ - fulltext_cursor *pCursor; - if( argc>1 ){ - sqlite3_result_error(pContext, "excess arguments to optimize()",-1); - }else if( sqlite3_value_type(argv[0])!=SQLITE_BLOB || - sqlite3_value_bytes(argv[0])!=sizeof(pCursor) ){ - sqlite3_result_error(pContext, "illegal first argument to optimize",-1); - }else{ - fulltext_vtab *v; - int i, rc, iMaxLevel; - OptLeavesReader *readers; - int nReaders; - LeafWriter writer; - sqlite3_stmt *s; - - memcpy(&pCursor, sqlite3_value_blob(argv[0]), sizeof(pCursor)); - v = cursor_vtab(pCursor); - - /* Flush any buffered updates before optimizing. */ - rc = flushPendingTerms(v); - if( rc!=SQLITE_OK ) goto err; - - rc = segdir_count(v, &nReaders, &iMaxLevel); - if( rc!=SQLITE_OK ) goto err; - if( nReaders==0 || nReaders==1 ){ - sqlite3_result_text(pContext, "Index already optimal", -1, - SQLITE_STATIC); - return; - } - - rc = sql_get_statement(v, SEGDIR_SELECT_ALL_STMT, &s); - if( rc!=SQLITE_OK ) goto err; - - readers = sqlite3_malloc(nReaders*sizeof(readers[0])); - if( readers==NULL ) goto err; - - /* Note that there will already be a segment at this position - ** until we call segdir_delete() on iMaxLevel. - */ - leafWriterInit(iMaxLevel, 0, &writer); - - i = 0; - while( (rc = sqlite3_step(s))==SQLITE_ROW ){ - sqlite_int64 iStart = sqlite3_column_int64(s, 0); - sqlite_int64 iEnd = sqlite3_column_int64(s, 1); - const char *pRootData = sqlite3_column_blob(s, 2); - int nRootData = sqlite3_column_bytes(s, 2); - - assert( i 0 ){ - leavesReaderDestroy(&readers[i].reader); - } - sqlite3_free(readers); - - /* If we've successfully gotten to here, delete the old segments - ** and flush the interior structure of the new segment. - */ - if( rc==SQLITE_OK ){ - for( i=0; i<=iMaxLevel; i++ ){ - rc = segdir_delete(v, i); - if( rc!=SQLITE_OK ) break; - } - - if( rc==SQLITE_OK ) rc = leafWriterFinalize(v, &writer); - } - - leafWriterDestroy(&writer); - - if( rc!=SQLITE_OK ) goto err; - - sqlite3_result_text(pContext, "Index optimized", -1, SQLITE_STATIC); - return; - - /* TODO(shess): Error-handling needs to be improved along the - ** lines of the dump_ functions. - */ - err: - { - char buf[512]; - sqlite3_snprintf(sizeof(buf), buf, "Error in optimize: %s", - sqlite3_errmsg(sqlite3_context_db_handle(pContext))); - sqlite3_result_error(pContext, buf, -1); - } - } -} - -#ifdef SQLITE_TEST -/* Generate an error of the form ": ". If msg is NULL, -** pull the error from the context's db handle. -*/ -static void generateError(sqlite3_context *pContext, - const char *prefix, const char *msg){ - char buf[512]; - if( msg==NULL ) msg = sqlite3_errmsg(sqlite3_context_db_handle(pContext)); - sqlite3_snprintf(sizeof(buf), buf, "%s: %s", prefix, msg); - sqlite3_result_error(pContext, buf, -1); -} - -/* Helper function to collect the set of terms in the segment into -** pTerms. The segment is defined by the leaf nodes between -** iStartBlockid and iEndBlockid, inclusive, or by the contents of -** pRootData if iStartBlockid is 0 (in which case the entire segment -** fit in a leaf). -*/ -static int collectSegmentTerms(fulltext_vtab *v, sqlite3_stmt *s, - fts3Hash *pTerms){ - const sqlite_int64 iStartBlockid = sqlite3_column_int64(s, 0); - const sqlite_int64 iEndBlockid = sqlite3_column_int64(s, 1); - const char *pRootData = sqlite3_column_blob(s, 2); - const int nRootData = sqlite3_column_bytes(s, 2); - LeavesReader reader; - int rc = leavesReaderInit(v, 0, iStartBlockid, iEndBlockid, - pRootData, nRootData, &reader); - if( rc!=SQLITE_OK ) return rc; - - while( rc==SQLITE_OK && !leavesReaderAtEnd(&reader) ){ - const char *pTerm = leavesReaderTerm(&reader); - const int nTerm = leavesReaderTermBytes(&reader); - void *oldValue = sqlite3Fts3HashFind(pTerms, pTerm, nTerm); - void *newValue = (void *)((char *)oldValue+1); - - /* From the comment before sqlite3Fts3HashInsert in fts3_hash.c, - ** the data value passed is returned in case of malloc failure. - */ - if( newValue==sqlite3Fts3HashInsert(pTerms, pTerm, nTerm, newValue) ){ - rc = SQLITE_NOMEM; - }else{ - rc = leavesReaderStep(v, &reader); - } - } - - leavesReaderDestroy(&reader); - return rc; -} - -/* Helper function to build the result string for dump_terms(). */ -static int generateTermsResult(sqlite3_context *pContext, fts3Hash *pTerms){ - int iTerm, nTerms, nResultBytes, iByte; - char *result; - TermData *pData; - fts3HashElem *e; - - /* Iterate pTerms to generate an array of terms in pData for - ** sorting. - */ - nTerms = fts3HashCount(pTerms); - assert( nTerms>0 ); - pData = sqlite3_malloc(nTerms*sizeof(TermData)); - if( pData==NULL ) return SQLITE_NOMEM; - - nResultBytes = 0; - for(iTerm = 0, e = fts3HashFirst(pTerms); e; iTerm++, e = fts3HashNext(e)){ - nResultBytes += fts3HashKeysize(e)+1; /* Term plus trailing space */ - assert( iTerm0 ); /* nTerms>0, nResultsBytes must be, too. */ - result = sqlite3_malloc(nResultBytes); - if( result==NULL ){ - sqlite3_free(pData); - return SQLITE_NOMEM; - } - - if( nTerms>1 ) qsort(pData, nTerms, sizeof(*pData), termDataCmp); - - /* Read the terms in order to build the result. */ - iByte = 0; - for(iTerm=0; iTerm0 ){ - rc = generateTermsResult(pContext, &terms); - if( rc==SQLITE_NOMEM ){ - generateError(pContext, "dump_terms", "out of memory"); - }else{ - assert( rc==SQLITE_OK ); - } - }else if( argc==3 ){ - /* The specific segment asked for could not be found. */ - generateError(pContext, "dump_terms", "segment not found"); - }else{ - /* No segments found. */ - /* TODO(shess): It should be impossible to reach this. This - ** case can only happen for an empty table, in which case - ** SQLite has no rows to call this function on. - */ - sqlite3_result_null(pContext); - } - } - sqlite3Fts3HashClear(&terms); - } -} - -/* Expand the DL_DEFAULT doclist in pData into a text result in -** pContext. -*/ -static void createDoclistResult(sqlite3_context *pContext, - const char *pData, int nData){ - DataBuffer dump; - DLReader dlReader; - - assert( pData!=NULL && nData>0 ); - - dataBufferInit(&dump, 0); - dlrInit(&dlReader, DL_DEFAULT, pData, nData); - for( ; !dlrAtEnd(&dlReader); dlrStep(&dlReader) ){ - char buf[256]; - PLReader plReader; - - plrInit(&plReader, &dlReader); - if( DL_DEFAULT==DL_DOCIDS || plrAtEnd(&plReader) ){ - sqlite3_snprintf(sizeof(buf), buf, "[%lld] ", dlrDocid(&dlReader)); - dataBufferAppend(&dump, buf, strlen(buf)); - }else{ - int iColumn = plrColumn(&plReader); - - sqlite3_snprintf(sizeof(buf), buf, "[%lld %d[", - dlrDocid(&dlReader), iColumn); - dataBufferAppend(&dump, buf, strlen(buf)); - - for( ; !plrAtEnd(&plReader); plrStep(&plReader) ){ - if( plrColumn(&plReader)!=iColumn ){ - iColumn = plrColumn(&plReader); - sqlite3_snprintf(sizeof(buf), buf, "] %d[", iColumn); - assert( dump.nData>0 ); - dump.nData--; /* Overwrite trailing space. */ - assert( dump.pData[dump.nData]==' '); - dataBufferAppend(&dump, buf, strlen(buf)); - } - if( DL_DEFAULT==DL_POSITIONS_OFFSETS ){ - sqlite3_snprintf(sizeof(buf), buf, "%d,%d,%d ", - plrPosition(&plReader), - plrStartOffset(&plReader), plrEndOffset(&plReader)); - }else if( DL_DEFAULT==DL_POSITIONS ){ - sqlite3_snprintf(sizeof(buf), buf, "%d ", plrPosition(&plReader)); - }else{ - assert( NULL=="Unhandled DL_DEFAULT value"); - } - dataBufferAppend(&dump, buf, strlen(buf)); - } - plrDestroy(&plReader); - - assert( dump.nData>0 ); - dump.nData--; /* Overwrite trailing space. */ - assert( dump.pData[dump.nData]==' '); - dataBufferAppend(&dump, "]] ", 3); - } - } - dlrDestroy(&dlReader); - - assert( dump.nData>0 ); - dump.nData--; /* Overwrite trailing space. */ - assert( dump.pData[dump.nData]==' '); - dump.pData[dump.nData] = '\0'; - assert( dump.nData>0 ); - - /* Passes ownership of dump's buffer to pContext. */ - sqlite3_result_text(pContext, dump.pData, dump.nData, sqlite3_free); - dump.pData = NULL; - dump.nData = dump.nCapacity = 0; -} - -/* Implements dump_doclist() for use in inspecting the fts3 index from -** tests. TEXT result containing a string representation of the -** doclist for the indicated term. dump_doclist(t, term, level, idx) -** dumps the doclist for term from the segment specified by level, idx -** (in %_segdir), while dump_doclist(t, term) dumps the logical -** doclist for the term across all segments. The per-segment doclist -** can contain deletions, while the full-index doclist will not -** (deletions are omitted). -** -** Result formats differ with the setting of DL_DEFAULTS. Examples: -** -** DL_DOCIDS: [1] [3] [7] -** DL_POSITIONS: [1 0[0 4] 1[17]] [3 1[5]] -** DL_POSITIONS_OFFSETS: [1 0[0,0,3 4,23,26] 1[17,102,105]] [3 1[5,20,23]] -** -** In each case the number after the outer '[' is the docid. In the -** latter two cases, the number before the inner '[' is the column -** associated with the values within. For DL_POSITIONS the numbers -** within are the positions, for DL_POSITIONS_OFFSETS they are the -** position, the start offset, and the end offset. -*/ -static void dumpDoclistFunc( - sqlite3_context *pContext, - int argc, sqlite3_value **argv -){ - fulltext_cursor *pCursor; - if( argc!=2 && argc!=4 ){ - generateError(pContext, "dump_doclist", "incorrect arguments"); - }else if( sqlite3_value_type(argv[0])!=SQLITE_BLOB || - sqlite3_value_bytes(argv[0])!=sizeof(pCursor) ){ - generateError(pContext, "dump_doclist", "illegal first argument"); - }else if( sqlite3_value_text(argv[1])==NULL || - sqlite3_value_text(argv[1])[0]=='\0' ){ - generateError(pContext, "dump_doclist", "empty second argument"); - }else{ - const char *pTerm = (const char *)sqlite3_value_text(argv[1]); - const int nTerm = strlen(pTerm); - fulltext_vtab *v; - int rc; - DataBuffer doclist; - - memcpy(&pCursor, sqlite3_value_blob(argv[0]), sizeof(pCursor)); - v = cursor_vtab(pCursor); - - dataBufferInit(&doclist, 0); - - /* termSelect() yields the same logical doclist that queries are - ** run against. - */ - if( argc==2 ){ - rc = termSelect(v, v->nColumn, pTerm, nTerm, 0, DL_DEFAULT, &doclist); - }else{ - sqlite3_stmt *s = NULL; - - /* Get our specific segment's information. */ - rc = sql_get_statement(v, SEGDIR_SELECT_SEGMENT_STMT, &s); - if( rc==SQLITE_OK ){ - rc = sqlite3_bind_int(s, 1, sqlite3_value_int(argv[2])); - if( rc==SQLITE_OK ){ - rc = sqlite3_bind_int(s, 2, sqlite3_value_int(argv[3])); - } - } - - if( rc==SQLITE_OK ){ - rc = sqlite3_step(s); - - if( rc==SQLITE_DONE ){ - dataBufferDestroy(&doclist); - generateError(pContext, "dump_doclist", "segment not found"); - return; - } - - /* Found a segment, load it into doclist. */ - if( rc==SQLITE_ROW ){ - const sqlite_int64 iLeavesEnd = sqlite3_column_int64(s, 1); - const char *pData = sqlite3_column_blob(s, 2); - const int nData = sqlite3_column_bytes(s, 2); - - /* loadSegment() is used by termSelect() to load each - ** segment's data. - */ - rc = loadSegment(v, pData, nData, iLeavesEnd, pTerm, nTerm, 0, - &doclist); - if( rc==SQLITE_OK ){ - rc = sqlite3_step(s); - - /* Should not have more than one matching segment. */ - if( rc!=SQLITE_DONE ){ - sqlite3_reset(s); - dataBufferDestroy(&doclist); - generateError(pContext, "dump_doclist", "invalid segdir"); - return; - } - rc = SQLITE_OK; - } - } - } - - sqlite3_reset(s); - } - - if( rc==SQLITE_OK ){ - if( doclist.nData>0 ){ - createDoclistResult(pContext, doclist.pData, doclist.nData); - }else{ - /* TODO(shess): This can happen if the term is not present, or - ** if all instances of the term have been deleted and this is - ** an all-index dump. It may be interesting to distinguish - ** these cases. - */ - sqlite3_result_text(pContext, "", 0, SQLITE_STATIC); - } - }else if( rc==SQLITE_NOMEM ){ - /* Handle out-of-memory cases specially because if they are - ** generated in fts3 code they may not be reflected in the db - ** handle. - */ - /* TODO(shess): Handle this more comprehensively. - ** sqlite3ErrStr() has what I need, but is internal. - */ - generateError(pContext, "dump_doclist", "out of memory"); - }else{ - generateError(pContext, "dump_doclist", NULL); - } - - dataBufferDestroy(&doclist); - } -} -#endif - /* ** This routine implements the xFindFunction method for the FTS3 ** virtual table. @@ -92390,23 +85247,6 @@ static int fulltextFindFunction( }else if( strcmp(zName,"offsets")==0 ){ *pxFunc = snippetOffsetsFunc; return 1; - }else if( strcmp(zName,"optimize")==0 ){ - *pxFunc = optimizeFunc; - return 1; -#ifdef SQLITE_TEST - /* NOTE(shess): These functions are present only for testing - ** purposes. No particular effort is made to optimize their - ** execution or how they build their results. - */ - }else if( strcmp(zName,"dump_terms")==0 ){ - /* fprintf(stderr, "Found dump_terms\n"); */ - *pxFunc = dumpTermsFunc; - return 1; - }else if( strcmp(zName,"dump_doclist")==0 ){ - /* fprintf(stderr, "Found dump_doclist\n"); */ - *pxFunc = dumpDoclistFunc; - return 1; -#endif } return 0; } @@ -92526,11 +85366,6 @@ SQLITE_PRIVATE int sqlite3Fts3Init(sqlite3 *db){ && SQLITE_OK==(rc = sqlite3Fts3InitHashTable(db, pHash, "fts3_tokenizer")) && SQLITE_OK==(rc = sqlite3_overload_function(db, "snippet", -1)) && SQLITE_OK==(rc = sqlite3_overload_function(db, "offsets", -1)) - && SQLITE_OK==(rc = sqlite3_overload_function(db, "optimize", -1)) -#ifdef SQLITE_TEST - && SQLITE_OK==(rc = sqlite3_overload_function(db, "dump_terms", -1)) - && SQLITE_OK==(rc = sqlite3_overload_function(db, "dump_doclist", -1)) -#endif ){ return sqlite3_create_module_v2( db, "fts3", &fts3Module, (void *)pHash, hashDestroy @@ -94166,3613 +87001,3 @@ SQLITE_PRIVATE void sqlite3Fts3SimpleTokenizerModule( #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) */ /************** End of fts3_tokenizer1.c *************************************/ -/************** Begin file rtree.c *******************************************/ -/* -** 2001 September 15 -** -** The author disclaims copyright to this source code. In place of -** a legal notice, here is a blessing: -** -** May you do good and not evil. -** May you find forgiveness for yourself and forgive others. -** May you share freely, never taking more than you give. -** -************************************************************************* -** This file contains code for implementations of the r-tree and r*-tree -** algorithms packaged as an SQLite virtual table module. -** -** $Id: rtree.c,v 1.9 2008/09/08 11:07:03 danielk1977 Exp $ -*/ - -#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_RTREE) - -/* -** This file contains an implementation of a couple of different variants -** of the r-tree algorithm. See the README file for further details. The -** same data-structure is used for all, but the algorithms for insert and -** delete operations vary. The variants used are selected at compile time -** by defining the following symbols: -*/ - -/* Either, both or none of the following may be set to activate -** r*tree variant algorithms. -*/ -#define VARIANT_RSTARTREE_CHOOSESUBTREE 0 -#define VARIANT_RSTARTREE_REINSERT 1 - -/* -** Exactly one of the following must be set to 1. -*/ -#define VARIANT_GUTTMAN_QUADRATIC_SPLIT 0 -#define VARIANT_GUTTMAN_LINEAR_SPLIT 0 -#define VARIANT_RSTARTREE_SPLIT 1 - -#define VARIANT_GUTTMAN_SPLIT \ - (VARIANT_GUTTMAN_LINEAR_SPLIT||VARIANT_GUTTMAN_QUADRATIC_SPLIT) - -#if VARIANT_GUTTMAN_QUADRATIC_SPLIT - #define PickNext QuadraticPickNext - #define PickSeeds QuadraticPickSeeds - #define AssignCells splitNodeGuttman -#endif -#if VARIANT_GUTTMAN_LINEAR_SPLIT - #define PickNext LinearPickNext - #define PickSeeds LinearPickSeeds - #define AssignCells splitNodeGuttman -#endif -#if VARIANT_RSTARTREE_SPLIT - #define AssignCells splitNodeStartree -#endif - - -#ifndef SQLITE_CORE - SQLITE_EXTENSION_INIT1 -#else -#endif - - -#ifndef SQLITE_AMALGAMATION -typedef sqlite3_int64 i64; -typedef unsigned char u8; -typedef unsigned int u32; -#endif - -typedef struct Rtree Rtree; -typedef struct RtreeCursor RtreeCursor; -typedef struct RtreeNode RtreeNode; -typedef struct RtreeCell RtreeCell; -typedef struct RtreeConstraint RtreeConstraint; -typedef union RtreeCoord RtreeCoord; - -/* The rtree may have between 1 and RTREE_MAX_DIMENSIONS dimensions. */ -#define RTREE_MAX_DIMENSIONS 5 - -/* Size of hash table Rtree.aHash. This hash table is not expected to -** ever contain very many entries, so a fixed number of buckets is -** used. -*/ -#define HASHSIZE 128 - -/* -** An rtree virtual-table object. -*/ -struct Rtree { - sqlite3_vtab base; - sqlite3 *db; /* Host database connection */ - int iNodeSize; /* Size in bytes of each node in the node table */ - int nDim; /* Number of dimensions */ - int nBytesPerCell; /* Bytes consumed per cell */ - int iDepth; /* Current depth of the r-tree structure */ - char *zDb; /* Name of database containing r-tree table */ - char *zName; /* Name of r-tree table */ - RtreeNode *aHash[HASHSIZE]; /* Hash table of in-memory nodes. */ - int nBusy; /* Current number of users of this structure */ - - /* List of nodes removed during a CondenseTree operation. List is - ** linked together via the pointer normally used for hash chains - - ** RtreeNode.pNext. RtreeNode.iNode stores the depth of the sub-tree - ** headed by the node (leaf nodes have RtreeNode.iNode==0). - */ - RtreeNode *pDeleted; - int iReinsertHeight; /* Height of sub-trees Reinsert() has run on */ - - /* Statements to read/write/delete a record from xxx_node */ - sqlite3_stmt *pReadNode; - sqlite3_stmt *pWriteNode; - sqlite3_stmt *pDeleteNode; - - /* Statements to read/write/delete a record from xxx_rowid */ - sqlite3_stmt *pReadRowid; - sqlite3_stmt *pWriteRowid; - sqlite3_stmt *pDeleteRowid; - - /* Statements to read/write/delete a record from xxx_parent */ - sqlite3_stmt *pReadParent; - sqlite3_stmt *pWriteParent; - sqlite3_stmt *pDeleteParent; - - int eCoordType; -}; - -/* Possible values for eCoordType: */ -#define RTREE_COORD_REAL32 0 -#define RTREE_COORD_INT32 1 - -/* -** The minimum number of cells allowed for a node is a third of the -** maximum. In Gutman's notation: -** -** m = M/3 -** -** If an R*-tree "Reinsert" operation is required, the same number of -** cells are removed from the overfull node and reinserted into the tree. -*/ -#define RTREE_MINCELLS(p) ((((p)->iNodeSize-4)/(p)->nBytesPerCell)/3) -#define RTREE_REINSERT(p) RTREE_MINCELLS(p) -#define RTREE_MAXCELLS 51 - -/* -** An rtree cursor object. -*/ -struct RtreeCursor { - sqlite3_vtab_cursor base; - RtreeNode *pNode; /* Node cursor is currently pointing at */ - int iCell; /* Index of current cell in pNode */ - int iStrategy; /* Copy of idxNum search parameter */ - int nConstraint; /* Number of entries in aConstraint */ - RtreeConstraint *aConstraint; /* Search constraints. */ -}; - -union RtreeCoord { - float f; - int i; -}; - -/* -** The argument is an RtreeCoord. Return the value stored within the RtreeCoord -** formatted as a double. This macro assumes that local variable pRtree points -** to the Rtree structure associated with the RtreeCoord. -*/ -#define DCOORD(coord) ( \ - (pRtree->eCoordType==RTREE_COORD_REAL32) ? \ - ((double)coord.f) : \ - ((double)coord.i) \ -) - -/* -** A search constraint. -*/ -struct RtreeConstraint { - int iCoord; /* Index of constrained coordinate */ - int op; /* Constraining operation */ - double rValue; /* Constraint value. */ -}; - -/* Possible values for RtreeConstraint.op */ -#define RTREE_EQ 0x41 -#define RTREE_LE 0x42 -#define RTREE_LT 0x43 -#define RTREE_GE 0x44 -#define RTREE_GT 0x45 - -/* -** An rtree structure node. -** -** Data format (RtreeNode.zData): -** -** 1. If the node is the root node (node 1), then the first 2 bytes -** of the node contain the tree depth as a big-endian integer. -** For non-root nodes, the first 2 bytes are left unused. -** -** 2. The next 2 bytes contain the number of entries currently -** stored in the node. -** -** 3. The remainder of the node contains the node entries. Each entry -** consists of a single 8-byte integer followed by an even number -** of 4-byte coordinates. For leaf nodes the integer is the rowid -** of a record. For internal nodes it is the node number of a -** child page. -*/ -struct RtreeNode { - RtreeNode *pParent; /* Parent node */ - i64 iNode; - int nRef; - int isDirty; - u8 *zData; - RtreeNode *pNext; /* Next node in this hash chain */ -}; -#define NCELL(pNode) readInt16(&(pNode)->zData[2]) - -/* -** Structure to store a deserialized rtree record. -*/ -struct RtreeCell { - i64 iRowid; - RtreeCoord aCoord[RTREE_MAX_DIMENSIONS*2]; -}; - -#define MAX(x,y) ((x) < (y) ? (y) : (x)) -#define MIN(x,y) ((x) > (y) ? (y) : (x)) - -/* -** Functions to deserialize a 16 bit integer, 32 bit real number and -** 64 bit integer. The deserialized value is returned. -*/ -static int readInt16(u8 *p){ - return (p[0]<<8) + p[1]; -} -static void readCoord(u8 *p, RtreeCoord *pCoord){ - u32 i = ( - (((u32)p[0]) << 24) + - (((u32)p[1]) << 16) + - (((u32)p[2]) << 8) + - (((u32)p[3]) << 0) - ); - *(u32 *)pCoord = i; -} -static i64 readInt64(u8 *p){ - return ( - (((i64)p[0]) << 56) + - (((i64)p[1]) << 48) + - (((i64)p[2]) << 40) + - (((i64)p[3]) << 32) + - (((i64)p[4]) << 24) + - (((i64)p[5]) << 16) + - (((i64)p[6]) << 8) + - (((i64)p[7]) << 0) - ); -} - -/* -** Functions to serialize a 16 bit integer, 32 bit real number and -** 64 bit integer. The value returned is the number of bytes written -** to the argument buffer (always 2, 4 and 8 respectively). -*/ -static int writeInt16(u8 *p, int i){ - p[0] = (i>> 8)&0xFF; - p[1] = (i>> 0)&0xFF; - return 2; -} -static int writeCoord(u8 *p, RtreeCoord *pCoord){ - u32 i; - assert( sizeof(RtreeCoord)==4 ); - assert( sizeof(u32)==4 ); - i = *(u32 *)pCoord; - p[0] = (i>>24)&0xFF; - p[1] = (i>>16)&0xFF; - p[2] = (i>> 8)&0xFF; - p[3] = (i>> 0)&0xFF; - return 4; -} -static int writeInt64(u8 *p, i64 i){ - p[0] = (i>>56)&0xFF; - p[1] = (i>>48)&0xFF; - p[2] = (i>>40)&0xFF; - p[3] = (i>>32)&0xFF; - p[4] = (i>>24)&0xFF; - p[5] = (i>>16)&0xFF; - p[6] = (i>> 8)&0xFF; - p[7] = (i>> 0)&0xFF; - return 8; -} - -/* -** Increment the reference count of node p. -*/ -static void nodeReference(RtreeNode *p){ - if( p ){ - p->nRef++; - } -} - -/* -** Clear the content of node p (set all bytes to 0x00). -*/ -static void nodeZero(Rtree *pRtree, RtreeNode *p){ - if( p ){ - memset(&p->zData[2], 0, pRtree->iNodeSize-2); - p->isDirty = 1; - } -} - -/* -** Given a node number iNode, return the corresponding key to use -** in the Rtree.aHash table. -*/ -static int nodeHash(i64 iNode){ - return ( - (iNode>>56) ^ (iNode>>48) ^ (iNode>>40) ^ (iNode>>32) ^ - (iNode>>24) ^ (iNode>>16) ^ (iNode>> 8) ^ (iNode>> 0) - ) % HASHSIZE; -} - -/* -** Search the node hash table for node iNode. If found, return a pointer -** to it. Otherwise, return 0. -*/ -static RtreeNode *nodeHashLookup(Rtree *pRtree, i64 iNode){ - RtreeNode *p; - assert( iNode!=0 ); - for(p=pRtree->aHash[nodeHash(iNode)]; p && p->iNode!=iNode; p=p->pNext); - return p; -} - -/* -** Add node pNode to the node hash table. -*/ -static void nodeHashInsert(Rtree *pRtree, RtreeNode *pNode){ - if( pNode ){ - int iHash; - assert( pNode->pNext==0 ); - iHash = nodeHash(pNode->iNode); - pNode->pNext = pRtree->aHash[iHash]; - pRtree->aHash[iHash] = pNode; - } -} - -/* -** Remove node pNode from the node hash table. -*/ -static void nodeHashDelete(Rtree *pRtree, RtreeNode *pNode){ - RtreeNode **pp; - if( pNode->iNode!=0 ){ - pp = &pRtree->aHash[nodeHash(pNode->iNode)]; - for( ; (*pp)!=pNode; pp = &(*pp)->pNext){ assert(*pp); } - *pp = pNode->pNext; - pNode->pNext = 0; - } -} - -/* -** Allocate and return new r-tree node. Initially, (RtreeNode.iNode==0), -** indicating that node has not yet been assigned a node number. It is -** assigned a node number when nodeWrite() is called to write the -** node contents out to the database. -*/ -static RtreeNode *nodeNew(Rtree *pRtree, RtreeNode *pParent, int zero){ - RtreeNode *pNode; - pNode = (RtreeNode *)sqlite3_malloc(sizeof(RtreeNode) + pRtree->iNodeSize); - if( pNode ){ - memset(pNode, 0, sizeof(RtreeNode) + (zero?pRtree->iNodeSize:0)); - pNode->zData = (u8 *)&pNode[1]; - pNode->nRef = 1; - pNode->pParent = pParent; - pNode->isDirty = 1; - nodeReference(pParent); - } - return pNode; -} - -/* -** Obtain a reference to an r-tree node. -*/ -static int -nodeAcquire( - Rtree *pRtree, /* R-tree structure */ - i64 iNode, /* Node number to load */ - RtreeNode *pParent, /* Either the parent node or NULL */ - RtreeNode **ppNode /* OUT: Acquired node */ -){ - int rc; - RtreeNode *pNode; - - /* Check if the requested node is already in the hash table. If so, - ** increase its reference count and return it. - */ - if( (pNode = nodeHashLookup(pRtree, iNode)) ){ - assert( !pParent || !pNode->pParent || pNode->pParent==pParent ); - if( pParent ){ - pNode->pParent = pParent; - } - pNode->nRef++; - *ppNode = pNode; - return SQLITE_OK; - } - - pNode = (RtreeNode *)sqlite3_malloc(sizeof(RtreeNode) + pRtree->iNodeSize); - if( !pNode ){ - *ppNode = 0; - return SQLITE_NOMEM; - } - pNode->pParent = pParent; - pNode->zData = (u8 *)&pNode[1]; - pNode->nRef = 1; - pNode->iNode = iNode; - pNode->isDirty = 0; - pNode->pNext = 0; - - sqlite3_bind_int64(pRtree->pReadNode, 1, iNode); - rc = sqlite3_step(pRtree->pReadNode); - if( rc==SQLITE_ROW ){ - const u8 *zBlob = sqlite3_column_blob(pRtree->pReadNode, 0); - memcpy(pNode->zData, zBlob, pRtree->iNodeSize); - nodeReference(pParent); - }else{ - sqlite3_free(pNode); - pNode = 0; - } - - *ppNode = pNode; - rc = sqlite3_reset(pRtree->pReadNode); - - if( rc==SQLITE_OK && iNode==1 ){ - pRtree->iDepth = readInt16(pNode->zData); - } - - assert( (rc==SQLITE_OK && pNode) || (pNode==0 && rc!=SQLITE_OK) ); - nodeHashInsert(pRtree, pNode); - - return rc; -} - -/* -** Overwrite cell iCell of node pNode with the contents of pCell. -*/ -static void nodeOverwriteCell( - Rtree *pRtree, - RtreeNode *pNode, - RtreeCell *pCell, - int iCell -){ - int ii; - u8 *p = &pNode->zData[4 + pRtree->nBytesPerCell*iCell]; - p += writeInt64(p, pCell->iRowid); - for(ii=0; ii<(pRtree->nDim*2); ii++){ - p += writeCoord(p, &pCell->aCoord[ii]); - } - pNode->isDirty = 1; -} - -/* -** Remove cell the cell with index iCell from node pNode. -*/ -static void nodeDeleteCell(Rtree *pRtree, RtreeNode *pNode, int iCell){ - u8 *pDst = &pNode->zData[4 + pRtree->nBytesPerCell*iCell]; - u8 *pSrc = &pDst[pRtree->nBytesPerCell]; - int nByte = (NCELL(pNode) - iCell - 1) * pRtree->nBytesPerCell; - memmove(pDst, pSrc, nByte); - writeInt16(&pNode->zData[2], NCELL(pNode)-1); - pNode->isDirty = 1; -} - -/* -** Insert the contents of cell pCell into node pNode. If the insert -** is successful, return SQLITE_OK. -** -** If there is not enough free space in pNode, return SQLITE_FULL. -*/ -static int -nodeInsertCell( - Rtree *pRtree, - RtreeNode *pNode, - RtreeCell *pCell -){ - int nCell; /* Current number of cells in pNode */ - int nMaxCell; /* Maximum number of cells for pNode */ - - nMaxCell = (pRtree->iNodeSize-4)/pRtree->nBytesPerCell; - nCell = NCELL(pNode); - - assert(nCell<=nMaxCell); - - if( nCellzData[2], nCell+1); - pNode->isDirty = 1; - } - - return (nCell==nMaxCell); -} - -/* -** If the node is dirty, write it out to the database. -*/ -static int -nodeWrite(Rtree *pRtree, RtreeNode *pNode){ - int rc = SQLITE_OK; - if( pNode->isDirty ){ - sqlite3_stmt *p = pRtree->pWriteNode; - if( pNode->iNode ){ - sqlite3_bind_int64(p, 1, pNode->iNode); - }else{ - sqlite3_bind_null(p, 1); - } - sqlite3_bind_blob(p, 2, pNode->zData, pRtree->iNodeSize, SQLITE_STATIC); - sqlite3_step(p); - pNode->isDirty = 0; - rc = sqlite3_reset(p); - if( pNode->iNode==0 && rc==SQLITE_OK ){ - pNode->iNode = sqlite3_last_insert_rowid(pRtree->db); - nodeHashInsert(pRtree, pNode); - } - } - return rc; -} - -/* -** Release a reference to a node. If the node is dirty and the reference -** count drops to zero, the node data is written to the database. -*/ -static int -nodeRelease(Rtree *pRtree, RtreeNode *pNode){ - int rc = SQLITE_OK; - if( pNode ){ - assert( pNode->nRef>0 ); - pNode->nRef--; - if( pNode->nRef==0 ){ - if( pNode->iNode==1 ){ - pRtree->iDepth = -1; - } - if( pNode->pParent ){ - rc = nodeRelease(pRtree, pNode->pParent); - } - if( rc==SQLITE_OK ){ - rc = nodeWrite(pRtree, pNode); - } - nodeHashDelete(pRtree, pNode); - sqlite3_free(pNode); - } - } - return rc; -} - -/* -** Return the 64-bit integer value associated with cell iCell of -** node pNode. If pNode is a leaf node, this is a rowid. If it is -** an internal node, then the 64-bit integer is a child page number. -*/ -static i64 nodeGetRowid( - Rtree *pRtree, - RtreeNode *pNode, - int iCell -){ - assert( iCellzData[4 + pRtree->nBytesPerCell*iCell]); -} - -/* -** Return coordinate iCoord from cell iCell in node pNode. -*/ -static void nodeGetCoord( - Rtree *pRtree, - RtreeNode *pNode, - int iCell, - int iCoord, - RtreeCoord *pCoord /* Space to write result to */ -){ - readCoord(&pNode->zData[12 + pRtree->nBytesPerCell*iCell + 4*iCoord], pCoord); -} - -/* -** Deserialize cell iCell of node pNode. Populate the structure pointed -** to by pCell with the results. -*/ -static void nodeGetCell( - Rtree *pRtree, - RtreeNode *pNode, - int iCell, - RtreeCell *pCell -){ - int ii; - pCell->iRowid = nodeGetRowid(pRtree, pNode, iCell); - for(ii=0; iinDim*2; ii++){ - nodeGetCoord(pRtree, pNode, iCell, ii, &pCell->aCoord[ii]); - } -} - - -/* Forward declaration for the function that does the work of -** the virtual table module xCreate() and xConnect() methods. -*/ -static int rtreeInit( - sqlite3 *, void *, int, const char *const*, sqlite3_vtab **, char **, int, int -); - -/* -** Rtree virtual table module xCreate method. -*/ -static int rtreeCreate( - sqlite3 *db, - void *pAux, - int argc, const char *const*argv, - sqlite3_vtab **ppVtab, - char **pzErr -){ - return rtreeInit(db, pAux, argc, argv, ppVtab, pzErr, 1, (int)pAux); -} - -/* -** Rtree virtual table module xConnect method. -*/ -static int rtreeConnect( - sqlite3 *db, - void *pAux, - int argc, const char *const*argv, - sqlite3_vtab **ppVtab, - char **pzErr -){ - return rtreeInit(db, pAux, argc, argv, ppVtab, pzErr, 0, (int)pAux); -} - -/* -** Increment the r-tree reference count. -*/ -static void rtreeReference(Rtree *pRtree){ - pRtree->nBusy++; -} - -/* -** Decrement the r-tree reference count. When the reference count reaches -** zero the structure is deleted. -*/ -static void rtreeRelease(Rtree *pRtree){ - pRtree->nBusy--; - if( pRtree->nBusy==0 ){ - sqlite3_finalize(pRtree->pReadNode); - sqlite3_finalize(pRtree->pWriteNode); - sqlite3_finalize(pRtree->pDeleteNode); - sqlite3_finalize(pRtree->pReadRowid); - sqlite3_finalize(pRtree->pWriteRowid); - sqlite3_finalize(pRtree->pDeleteRowid); - sqlite3_finalize(pRtree->pReadParent); - sqlite3_finalize(pRtree->pWriteParent); - sqlite3_finalize(pRtree->pDeleteParent); - sqlite3_free(pRtree); - } -} - -/* -** Rtree virtual table module xDisconnect method. -*/ -static int rtreeDisconnect(sqlite3_vtab *pVtab){ - rtreeRelease((Rtree *)pVtab); - return SQLITE_OK; -} - -/* -** Rtree virtual table module xDestroy method. -*/ -static int rtreeDestroy(sqlite3_vtab *pVtab){ - Rtree *pRtree = (Rtree *)pVtab; - int rc; - char *zCreate = sqlite3_mprintf( - "DROP TABLE '%q'.'%q_node';" - "DROP TABLE '%q'.'%q_rowid';" - "DROP TABLE '%q'.'%q_parent';", - pRtree->zDb, pRtree->zName, - pRtree->zDb, pRtree->zName, - pRtree->zDb, pRtree->zName - ); - if( !zCreate ){ - rc = SQLITE_NOMEM; - }else{ - rc = sqlite3_exec(pRtree->db, zCreate, 0, 0, 0); - sqlite3_free(zCreate); - } - if( rc==SQLITE_OK ){ - rtreeRelease(pRtree); - } - - return rc; -} - -/* -** Rtree virtual table module xOpen method. -*/ -static int rtreeOpen(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor){ - int rc = SQLITE_NOMEM; - RtreeCursor *pCsr; - - pCsr = (RtreeCursor *)sqlite3_malloc(sizeof(RtreeCursor)); - if( pCsr ){ - memset(pCsr, 0, sizeof(RtreeCursor)); - pCsr->base.pVtab = pVTab; - rc = SQLITE_OK; - } - *ppCursor = (sqlite3_vtab_cursor *)pCsr; - - return rc; -} - -/* -** Rtree virtual table module xClose method. -*/ -static int rtreeClose(sqlite3_vtab_cursor *cur){ - Rtree *pRtree = (Rtree *)(cur->pVtab); - int rc; - RtreeCursor *pCsr = (RtreeCursor *)cur; - sqlite3_free(pCsr->aConstraint); - rc = nodeRelease(pRtree, pCsr->pNode); - sqlite3_free(pCsr); - return rc; -} - -/* -** Rtree virtual table module xEof method. -** -** Return non-zero if the cursor does not currently point to a valid -** record (i.e if the scan has finished), or zero otherwise. -*/ -static int rtreeEof(sqlite3_vtab_cursor *cur){ - RtreeCursor *pCsr = (RtreeCursor *)cur; - return (pCsr->pNode==0); -} - -/* -** Cursor pCursor currently points to a cell in a non-leaf page. -** Return true if the sub-tree headed by the cell is filtered -** (excluded) by the constraints in the pCursor->aConstraint[] -** array, or false otherwise. -*/ -static int testRtreeCell(Rtree *pRtree, RtreeCursor *pCursor){ - RtreeCell cell; - int ii; - int bRes = 0; - - nodeGetCell(pRtree, pCursor->pNode, pCursor->iCell, &cell); - for(ii=0; bRes==0 && iinConstraint; ii++){ - RtreeConstraint *p = &pCursor->aConstraint[ii]; - double cell_min = DCOORD(cell.aCoord[(p->iCoord>>1)*2]); - double cell_max = DCOORD(cell.aCoord[(p->iCoord>>1)*2+1]); - - assert(p->op==RTREE_LE || p->op==RTREE_LT || p->op==RTREE_GE - || p->op==RTREE_GT || p->op==RTREE_EQ - ); - - switch( p->op ){ - case RTREE_LE: case RTREE_LT: bRes = p->rValuerValue>cell_max; break; - case RTREE_EQ: - bRes = (p->rValue>cell_max || p->rValueaConstraint[] array, or false otherwise. -** -** This function assumes that the cell is part of a leaf node. -*/ -static int testRtreeEntry(Rtree *pRtree, RtreeCursor *pCursor){ - RtreeCell cell; - int ii; - - nodeGetCell(pRtree, pCursor->pNode, pCursor->iCell, &cell); - for(ii=0; iinConstraint; ii++){ - RtreeConstraint *p = &pCursor->aConstraint[ii]; - double coord = DCOORD(cell.aCoord[p->iCoord]); - int res; - assert(p->op==RTREE_LE || p->op==RTREE_LT || p->op==RTREE_GE - || p->op==RTREE_GT || p->op==RTREE_EQ - ); - switch( p->op ){ - case RTREE_LE: res = (coord<=p->rValue); break; - case RTREE_LT: res = (coordrValue); break; - case RTREE_GE: res = (coord>=p->rValue); break; - case RTREE_GT: res = (coord>p->rValue); break; - case RTREE_EQ: res = (coord==p->rValue); break; - } - - if( !res ) return 1; - } - - return 0; -} - -/* -** Cursor pCursor currently points at a node that heads a sub-tree of -** height iHeight (if iHeight==0, then the node is a leaf). Descend -** to point to the left-most cell of the sub-tree that matches the -** configured constraints. -*/ -static int descendToCell( - Rtree *pRtree, - RtreeCursor *pCursor, - int iHeight, - int *pEof /* OUT: Set to true if cannot descend */ -){ - int isEof; - int rc; - int ii; - RtreeNode *pChild; - sqlite3_int64 iRowid; - - RtreeNode *pSavedNode = pCursor->pNode; - int iSavedCell = pCursor->iCell; - - assert( iHeight>=0 ); - - if( iHeight==0 ){ - isEof = testRtreeEntry(pRtree, pCursor); - }else{ - isEof = testRtreeCell(pRtree, pCursor); - } - if( isEof || iHeight==0 ){ - *pEof = isEof; - return SQLITE_OK; - } - - iRowid = nodeGetRowid(pRtree, pCursor->pNode, pCursor->iCell); - rc = nodeAcquire(pRtree, iRowid, pCursor->pNode, &pChild); - if( rc!=SQLITE_OK ){ - return rc; - } - - nodeRelease(pRtree, pCursor->pNode); - pCursor->pNode = pChild; - isEof = 1; - for(ii=0; isEof && iiiCell = ii; - rc = descendToCell(pRtree, pCursor, iHeight-1, &isEof); - if( rc!=SQLITE_OK ){ - return rc; - } - } - - if( isEof ){ - assert( pCursor->pNode==pChild ); - nodeReference(pSavedNode); - nodeRelease(pRtree, pChild); - pCursor->pNode = pSavedNode; - pCursor->iCell = iSavedCell; - } - - *pEof = isEof; - return SQLITE_OK; -} - -/* -** One of the cells in node pNode is guaranteed to have a 64-bit -** integer value equal to iRowid. Return the index of this cell. -*/ -static int nodeRowidIndex(Rtree *pRtree, RtreeNode *pNode, i64 iRowid){ - int ii; - for(ii=0; nodeGetRowid(pRtree, pNode, ii)!=iRowid; ii++){ - assert( ii<(NCELL(pNode)-1) ); - } - return ii; -} - -/* -** Return the index of the cell containing a pointer to node pNode -** in its parent. If pNode is the root node, return -1. -*/ -static int nodeParentIndex(Rtree *pRtree, RtreeNode *pNode){ - RtreeNode *pParent = pNode->pParent; - if( pParent ){ - return nodeRowidIndex(pRtree, pParent, pNode->iNode); - } - return -1; -} - -/* -** Rtree virtual table module xNext method. -*/ -static int rtreeNext(sqlite3_vtab_cursor *pVtabCursor){ - Rtree *pRtree = (Rtree *)(pVtabCursor->pVtab); - RtreeCursor *pCsr = (RtreeCursor *)pVtabCursor; - int rc = SQLITE_OK; - - if( pCsr->iStrategy==1 ){ - /* This "scan" is a direct lookup by rowid. There is no next entry. */ - nodeRelease(pRtree, pCsr->pNode); - pCsr->pNode = 0; - } - - else if( pCsr->pNode ){ - /* Move to the next entry that matches the configured constraints. */ - int iHeight = 0; - while( pCsr->pNode ){ - RtreeNode *pNode = pCsr->pNode; - int nCell = NCELL(pNode); - for(pCsr->iCell++; pCsr->iCelliCell++){ - int isEof; - rc = descendToCell(pRtree, pCsr, iHeight, &isEof); - if( rc!=SQLITE_OK || !isEof ){ - return rc; - } - } - pCsr->pNode = pNode->pParent; - pCsr->iCell = nodeParentIndex(pRtree, pNode); - nodeReference(pCsr->pNode); - nodeRelease(pRtree, pNode); - iHeight++; - } - } - - return rc; -} - -/* -** Rtree virtual table module xRowid method. -*/ -static int rtreeRowid(sqlite3_vtab_cursor *pVtabCursor, sqlite_int64 *pRowid){ - Rtree *pRtree = (Rtree *)pVtabCursor->pVtab; - RtreeCursor *pCsr = (RtreeCursor *)pVtabCursor; - - assert(pCsr->pNode); - *pRowid = nodeGetRowid(pRtree, pCsr->pNode, pCsr->iCell); - - return SQLITE_OK; -} - -/* -** Rtree virtual table module xColumn method. -*/ -static int rtreeColumn(sqlite3_vtab_cursor *cur, sqlite3_context *ctx, int i){ - Rtree *pRtree = (Rtree *)cur->pVtab; - RtreeCursor *pCsr = (RtreeCursor *)cur; - - if( i==0 ){ - i64 iRowid = nodeGetRowid(pRtree, pCsr->pNode, pCsr->iCell); - sqlite3_result_int64(ctx, iRowid); - }else{ - RtreeCoord c; - nodeGetCoord(pRtree, pCsr->pNode, pCsr->iCell, i-1, &c); - if( pRtree->eCoordType==RTREE_COORD_REAL32 ){ - sqlite3_result_double(ctx, c.f); - }else{ - assert( pRtree->eCoordType==RTREE_COORD_INT32 ); - sqlite3_result_int(ctx, c.i); - } - } - - return SQLITE_OK; -} - -/* -** Use nodeAcquire() to obtain the leaf node containing the record with -** rowid iRowid. If successful, set *ppLeaf to point to the node and -** return SQLITE_OK. If there is no such record in the table, set -** *ppLeaf to 0 and return SQLITE_OK. If an error occurs, set *ppLeaf -** to zero and return an SQLite error code. -*/ -static int findLeafNode(Rtree *pRtree, i64 iRowid, RtreeNode **ppLeaf){ - int rc; - *ppLeaf = 0; - sqlite3_bind_int64(pRtree->pReadRowid, 1, iRowid); - if( sqlite3_step(pRtree->pReadRowid)==SQLITE_ROW ){ - i64 iNode = sqlite3_column_int64(pRtree->pReadRowid, 0); - rc = nodeAcquire(pRtree, iNode, 0, ppLeaf); - sqlite3_reset(pRtree->pReadRowid); - }else{ - rc = sqlite3_reset(pRtree->pReadRowid); - } - return rc; -} - - -/* -** Rtree virtual table module xFilter method. -*/ -static int rtreeFilter( - sqlite3_vtab_cursor *pVtabCursor, - int idxNum, const char *idxStr, - int argc, sqlite3_value **argv -){ - Rtree *pRtree = (Rtree *)pVtabCursor->pVtab; - RtreeCursor *pCsr = (RtreeCursor *)pVtabCursor; - - RtreeNode *pRoot = 0; - int ii; - int rc = SQLITE_OK; - - rtreeReference(pRtree); - - sqlite3_free(pCsr->aConstraint); - pCsr->aConstraint = 0; - pCsr->iStrategy = idxNum; - - if( idxNum==1 ){ - /* Special case - lookup by rowid. */ - RtreeNode *pLeaf; /* Leaf on which the required cell resides */ - i64 iRowid = sqlite3_value_int64(argv[0]); - rc = findLeafNode(pRtree, iRowid, &pLeaf); - pCsr->pNode = pLeaf; - if( pLeaf && rc==SQLITE_OK ){ - pCsr->iCell = nodeRowidIndex(pRtree, pLeaf, iRowid); - } - }else{ - /* Normal case - r-tree scan. Set up the RtreeCursor.aConstraint array - ** with the configured constraints. - */ - if( argc>0 ){ - pCsr->aConstraint = sqlite3_malloc(sizeof(RtreeConstraint)*argc); - pCsr->nConstraint = argc; - if( !pCsr->aConstraint ){ - rc = SQLITE_NOMEM; - }else{ - assert( (idxStr==0 && argc==0) || strlen(idxStr)==argc*2 ); - for(ii=0; iiaConstraint[ii]; - p->op = idxStr[ii*2]; - p->iCoord = idxStr[ii*2+1]-'a'; - p->rValue = sqlite3_value_double(argv[ii]); - } - } - } - - if( rc==SQLITE_OK ){ - pCsr->pNode = 0; - rc = nodeAcquire(pRtree, 1, 0, &pRoot); - } - if( rc==SQLITE_OK ){ - int isEof = 1; - int nCell = NCELL(pRoot); - pCsr->pNode = pRoot; - for(pCsr->iCell=0; rc==SQLITE_OK && pCsr->iCelliCell++){ - assert( pCsr->pNode==pRoot ); - rc = descendToCell(pRtree, pCsr, pRtree->iDepth, &isEof); - if( !isEof ){ - break; - } - } - if( rc==SQLITE_OK && isEof ){ - assert( pCsr->pNode==pRoot ); - nodeRelease(pRtree, pRoot); - pCsr->pNode = 0; - } - assert( rc!=SQLITE_OK || !pCsr->pNode || pCsr->iCellpNode) ); - } - } - - rtreeRelease(pRtree); - return rc; -} - -/* -** Rtree virtual table module xBestIndex method. There are three -** table scan strategies to choose from (in order from most to -** least desirable): -** -** idxNum idxStr Strategy -** ------------------------------------------------ -** 1 Unused Direct lookup by rowid. -** 2 See below R-tree query. -** 3 Unused Full table scan. -** ------------------------------------------------ -** -** If strategy 1 or 3 is used, then idxStr is not meaningful. If strategy -** 2 is used, idxStr is formatted to contain 2 bytes for each -** constraint used. The first two bytes of idxStr correspond to -** the constraint in sqlite3_index_info.aConstraintUsage[] with -** (argvIndex==1) etc. -** -** The first of each pair of bytes in idxStr identifies the constraint -** operator as follows: -** -** Operator Byte Value -** ---------------------- -** = 0x41 ('A') -** <= 0x42 ('B') -** < 0x43 ('C') -** >= 0x44 ('D') -** > 0x45 ('E') -** ---------------------- -** -** The second of each pair of bytes identifies the coordinate column -** to which the constraint applies. The leftmost coordinate column -** is 'a', the second from the left 'b' etc. -*/ -static int rtreeBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){ - int rc = SQLITE_OK; - int ii, cCol; - - int iIdx = 0; - char zIdxStr[RTREE_MAX_DIMENSIONS*8+1]; - memset(zIdxStr, 0, sizeof(zIdxStr)); - - assert( pIdxInfo->idxStr==0 ); - for(ii=0; iinConstraint; ii++){ - struct sqlite3_index_constraint *p = &pIdxInfo->aConstraint[ii]; - - if( p->usable && p->iColumn==0 && p->op==SQLITE_INDEX_CONSTRAINT_EQ ){ - /* We have an equality constraint on the rowid. Use strategy 1. */ - int jj; - for(jj=0; jjaConstraintUsage[jj].argvIndex = 0; - pIdxInfo->aConstraintUsage[jj].omit = 0; - } - pIdxInfo->idxNum = 1; - pIdxInfo->aConstraintUsage[ii].argvIndex = 1; - pIdxInfo->aConstraintUsage[jj].omit = 1; - - /* This strategy involves a two rowid lookups on an B-Tree structures - ** and then a linear search of an R-Tree node. This should be - ** considered almost as quick as a direct rowid lookup (for which - ** sqlite uses an internal cost of 0.0). - */ - pIdxInfo->estimatedCost = 10.0; - return SQLITE_OK; - } - - if( p->usable && p->iColumn>0 ){ - u8 op = 0; - switch( p->op ){ - case SQLITE_INDEX_CONSTRAINT_EQ: op = RTREE_EQ; break; - case SQLITE_INDEX_CONSTRAINT_GT: op = RTREE_GT; break; - case SQLITE_INDEX_CONSTRAINT_LE: op = RTREE_LE; break; - case SQLITE_INDEX_CONSTRAINT_LT: op = RTREE_LT; break; - case SQLITE_INDEX_CONSTRAINT_GE: op = RTREE_GE; break; - } - if( op ){ - /* Make sure this particular constraint has not been used before. - ** If it has been used before, ignore it. - ** - ** A <= or < can be used if there is a prior >= or >. - ** A >= or > can be used if there is a prior < or <=. - ** A <= or < is disqualified if there is a prior <=, <, or ==. - ** A >= or > is disqualified if there is a prior >=, >, or ==. - ** A == is disqualifed if there is any prior constraint. - */ - int j, opmsk; - static const unsigned char compatible[] = { 0, 0, 1, 1, 2, 2 }; - assert( compatible[RTREE_EQ & 7]==0 ); - assert( compatible[RTREE_LT & 7]==1 ); - assert( compatible[RTREE_LE & 7]==1 ); - assert( compatible[RTREE_GT & 7]==2 ); - assert( compatible[RTREE_GE & 7]==2 ); - cCol = p->iColumn - 1 + 'a'; - opmsk = compatible[op & 7]; - for(j=0; jaConstraintUsage[ii].argvIndex = (iIdx/2); - pIdxInfo->aConstraintUsage[ii].omit = 1; - } - } - } - - pIdxInfo->idxNum = 2; - pIdxInfo->needToFreeIdxStr = 1; - if( iIdx>0 && 0==(pIdxInfo->idxStr = sqlite3_mprintf("%s", zIdxStr)) ){ - return SQLITE_NOMEM; - } - assert( iIdx>=0 ); - pIdxInfo->estimatedCost = (2000000.0 / (double)(iIdx + 1)); - return rc; -} - -/* -** Return the N-dimensional volumn of the cell stored in *p. -*/ -static float cellArea(Rtree *pRtree, RtreeCell *p){ - float area = 1.0; - int ii; - for(ii=0; ii<(pRtree->nDim*2); ii+=2){ - area = area * (DCOORD(p->aCoord[ii+1]) - DCOORD(p->aCoord[ii])); - } - return area; -} - -/* -** Return the margin length of cell p. The margin length is the sum -** of the objects size in each dimension. -*/ -static float cellMargin(Rtree *pRtree, RtreeCell *p){ - float margin = 0.0; - int ii; - for(ii=0; ii<(pRtree->nDim*2); ii+=2){ - margin += (DCOORD(p->aCoord[ii+1]) - DCOORD(p->aCoord[ii])); - } - return margin; -} - -/* -** Store the union of cells p1 and p2 in p1. -*/ -static void cellUnion(Rtree *pRtree, RtreeCell *p1, RtreeCell *p2){ - int ii; - if( pRtree->eCoordType==RTREE_COORD_REAL32 ){ - for(ii=0; ii<(pRtree->nDim*2); ii+=2){ - p1->aCoord[ii].f = MIN(p1->aCoord[ii].f, p2->aCoord[ii].f); - p1->aCoord[ii+1].f = MAX(p1->aCoord[ii+1].f, p2->aCoord[ii+1].f); - } - }else{ - for(ii=0; ii<(pRtree->nDim*2); ii+=2){ - p1->aCoord[ii].i = MIN(p1->aCoord[ii].i, p2->aCoord[ii].i); - p1->aCoord[ii+1].i = MAX(p1->aCoord[ii+1].i, p2->aCoord[ii+1].i); - } - } -} - -/* -** Return true if the area covered by p2 is a subset of the area covered -** by p1. False otherwise. -*/ -static int cellContains(Rtree *pRtree, RtreeCell *p1, RtreeCell *p2){ - int ii; - int isInt = (pRtree->eCoordType==RTREE_COORD_INT32); - for(ii=0; ii<(pRtree->nDim*2); ii+=2){ - RtreeCoord *a1 = &p1->aCoord[ii]; - RtreeCoord *a2 = &p2->aCoord[ii]; - if( (!isInt && (a2[0].fa1[1].f)) - || ( isInt && (a2[0].ia1[1].i)) - ){ - return 0; - } - } - return 1; -} - -/* -** Return the amount cell p would grow by if it were unioned with pCell. -*/ -static float cellGrowth(Rtree *pRtree, RtreeCell *p, RtreeCell *pCell){ - float area; - RtreeCell cell; - memcpy(&cell, p, sizeof(RtreeCell)); - area = cellArea(pRtree, &cell); - cellUnion(pRtree, &cell, pCell); - return (cellArea(pRtree, &cell)-area); -} - -#if VARIANT_RSTARTREE_CHOOSESUBTREE || VARIANT_RSTARTREE_SPLIT -static float cellOverlap( - Rtree *pRtree, - RtreeCell *p, - RtreeCell *aCell, - int nCell, - int iExclude -){ - int ii; - float overlap = 0.0; - for(ii=0; iinDim*2); jj+=2){ - double x1; - double x2; - - x1 = MAX(DCOORD(p->aCoord[jj]), DCOORD(aCell[ii].aCoord[jj])); - x2 = MIN(DCOORD(p->aCoord[jj+1]), DCOORD(aCell[ii].aCoord[jj+1])); - - if( x2iDepth-iHeight); ii++){ - int iCell; - sqlite3_int64 iBest; - - float fMinGrowth; - float fMinArea; - float fMinOverlap; - - int nCell = NCELL(pNode); - RtreeCell cell; - RtreeNode *pChild; - - RtreeCell *aCell = 0; - -#if VARIANT_RSTARTREE_CHOOSESUBTREE - if( ii==(pRtree->iDepth-1) ){ - int jj; - aCell = sqlite3_malloc(sizeof(RtreeCell)*nCell); - if( !aCell ){ - rc = SQLITE_NOMEM; - nodeRelease(pRtree, pNode); - pNode = 0; - continue; - } - for(jj=0; jjiDepth-1) ){ - overlap = cellOverlapEnlargement(pRtree,&cell,pCell,aCell,nCell,iCell); - } -#endif - if( (iCell==0) - || (overlappParent ){ - RtreeCell cell; - RtreeNode *pParent = p->pParent; - int iCell = nodeParentIndex(pRtree, p); - - nodeGetCell(pRtree, pParent, iCell, &cell); - if( !cellContains(pRtree, &cell, pCell) ){ - cellUnion(pRtree, &cell, pCell); - nodeOverwriteCell(pRtree, pParent, &cell, iCell); - } - - p = pParent; - } -} - -/* -** Write mapping (iRowid->iNode) to the _rowid table. -*/ -static int rowidWrite(Rtree *pRtree, sqlite3_int64 iRowid, sqlite3_int64 iNode){ - sqlite3_bind_int64(pRtree->pWriteRowid, 1, iRowid); - sqlite3_bind_int64(pRtree->pWriteRowid, 2, iNode); - sqlite3_step(pRtree->pWriteRowid); - return sqlite3_reset(pRtree->pWriteRowid); -} - -/* -** Write mapping (iNode->iPar) to the _parent table. -*/ -static int parentWrite(Rtree *pRtree, sqlite3_int64 iNode, sqlite3_int64 iPar){ - sqlite3_bind_int64(pRtree->pWriteParent, 1, iNode); - sqlite3_bind_int64(pRtree->pWriteParent, 2, iPar); - sqlite3_step(pRtree->pWriteParent); - return sqlite3_reset(pRtree->pWriteParent); -} - -static int rtreeInsertCell(Rtree *, RtreeNode *, RtreeCell *, int); - -#if VARIANT_GUTTMAN_LINEAR_SPLIT -/* -** Implementation of the linear variant of the PickNext() function from -** Guttman[84]. -*/ -static RtreeCell *LinearPickNext( - Rtree *pRtree, - RtreeCell *aCell, - int nCell, - RtreeCell *pLeftBox, - RtreeCell *pRightBox, - int *aiUsed -){ - int ii; - for(ii=0; aiUsed[ii]; ii++); - aiUsed[ii] = 1; - return &aCell[ii]; -} - -/* -** Implementation of the linear variant of the PickSeeds() function from -** Guttman[84]. -*/ -static void LinearPickSeeds( - Rtree *pRtree, - RtreeCell *aCell, - int nCell, - int *piLeftSeed, - int *piRightSeed -){ - int i; - int iLeftSeed = 0; - int iRightSeed = 1; - float maxNormalInnerWidth = 0.0; - - /* Pick two "seed" cells from the array of cells. The algorithm used - ** here is the LinearPickSeeds algorithm from Gutman[1984]. The - ** indices of the two seed cells in the array are stored in local - ** variables iLeftSeek and iRightSeed. - */ - for(i=0; inDim; i++){ - float x1 = aCell[0].aCoord[i*2]; - float x2 = aCell[0].aCoord[i*2+1]; - float x3 = x1; - float x4 = x2; - int jj; - - int iCellLeft = 0; - int iCellRight = 0; - - for(jj=1; jjx4 ) x4 = right; - if( left>x3 ){ - x3 = left; - iCellRight = jj; - } - if( rightmaxNormalInnerWidth ){ - iLeftSeed = iCellLeft; - iRightSeed = iCellRight; - } - } - } - - *piLeftSeed = iLeftSeed; - *piRightSeed = iRightSeed; -} -#endif /* VARIANT_GUTTMAN_LINEAR_SPLIT */ - -#if VARIANT_GUTTMAN_QUADRATIC_SPLIT -/* -** Implementation of the quadratic variant of the PickNext() function from -** Guttman[84]. -*/ -static RtreeCell *QuadraticPickNext( - Rtree *pRtree, - RtreeCell *aCell, - int nCell, - RtreeCell *pLeftBox, - RtreeCell *pRightBox, - int *aiUsed -){ - #define FABS(a) ((a)<0.0?-1.0*(a):(a)) - - int iSelect = -1; - float fDiff; - int ii; - for(ii=0; iifDiff ){ - fDiff = diff; - iSelect = ii; - } - } - } - aiUsed[iSelect] = 1; - return &aCell[iSelect]; -} - -/* -** Implementation of the quadratic variant of the PickSeeds() function from -** Guttman[84]. -*/ -static void QuadraticPickSeeds( - Rtree *pRtree, - RtreeCell *aCell, - int nCell, - int *piLeftSeed, - int *piRightSeed -){ - int ii; - int jj; - - int iLeftSeed = 0; - int iRightSeed = 1; - float fWaste = 0.0; - - for(ii=0; iifWaste ){ - iLeftSeed = ii; - iRightSeed = jj; - fWaste = waste; - } - } - } - - *piLeftSeed = iLeftSeed; - *piRightSeed = iRightSeed; -} -#endif /* VARIANT_GUTTMAN_QUADRATIC_SPLIT */ - -/* -** Arguments aIdx, aDistance and aSpare all point to arrays of size -** nIdx. The aIdx array contains the set of integers from 0 to -** (nIdx-1) in no particular order. This function sorts the values -** in aIdx according to the indexed values in aDistance. For -** example, assuming the inputs: -** -** aIdx = { 0, 1, 2, 3 } -** aDistance = { 5.0, 2.0, 7.0, 6.0 } -** -** this function sets the aIdx array to contain: -** -** aIdx = { 0, 1, 2, 3 } -** -** The aSpare array is used as temporary working space by the -** sorting algorithm. -*/ -static void SortByDistance( - int *aIdx, - int nIdx, - float *aDistance, - int *aSpare -){ - if( nIdx>1 ){ - int iLeft = 0; - int iRight = 0; - - int nLeft = nIdx/2; - int nRight = nIdx-nLeft; - int *aLeft = aIdx; - int *aRight = &aIdx[nLeft]; - - SortByDistance(aLeft, nLeft, aDistance, aSpare); - SortByDistance(aRight, nRight, aDistance, aSpare); - - memcpy(aSpare, aLeft, sizeof(int)*nLeft); - aLeft = aSpare; - - while( iLeft1 ){ - - int iLeft = 0; - int iRight = 0; - - int nLeft = nIdx/2; - int nRight = nIdx-nLeft; - int *aLeft = aIdx; - int *aRight = &aIdx[nLeft]; - - SortByDimension(pRtree, aLeft, nLeft, iDim, aCell, aSpare); - SortByDimension(pRtree, aRight, nRight, iDim, aCell, aSpare); - - memcpy(aSpare, aLeft, sizeof(int)*nLeft); - aLeft = aSpare; - while( iLeftnDim+1)*(sizeof(int*)+nCell*sizeof(int)); - - aaSorted = (int **)sqlite3_malloc(nByte); - if( !aaSorted ){ - return SQLITE_NOMEM; - } - - aSpare = &((int *)&aaSorted[pRtree->nDim])[pRtree->nDim*nCell]; - memset(aaSorted, 0, nByte); - for(ii=0; iinDim; ii++){ - int jj; - aaSorted[ii] = &((int *)&aaSorted[pRtree->nDim])[ii*nCell]; - for(jj=0; jjnDim; ii++){ - float margin = 0.0; - float fBestOverlap; - float fBestArea; - int iBestLeft; - int nLeft; - - for( - nLeft=RTREE_MINCELLS(pRtree); - nLeft<=(nCell-RTREE_MINCELLS(pRtree)); - nLeft++ - ){ - RtreeCell left; - RtreeCell right; - int kk; - float overlap; - float area; - - memcpy(&left, &aCell[aaSorted[ii][0]], sizeof(RtreeCell)); - memcpy(&right, &aCell[aaSorted[ii][nCell-1]], sizeof(RtreeCell)); - for(kk=1; kk<(nCell-1); kk++){ - if( kk0; i--){ - RtreeCell *pNext; - pNext = PickNext(pRtree, aCell, nCell, pBboxLeft, pBboxRight, aiUsed); - float diff = - cellGrowth(pRtree, pBboxLeft, pNext) - - cellGrowth(pRtree, pBboxRight, pNext) - ; - if( (RTREE_MINCELLS(pRtree)-NCELL(pRight)==i) - || (diff>0.0 && (RTREE_MINCELLS(pRtree)-NCELL(pLeft)!=i)) - ){ - nodeInsertCell(pRtree, pRight, pNext); - cellUnion(pRtree, pBboxRight, pNext); - }else{ - nodeInsertCell(pRtree, pLeft, pNext); - cellUnion(pRtree, pBboxLeft, pNext); - } - } - - sqlite3_free(aiUsed); - return SQLITE_OK; -} -#endif - -static int updateMapping( - Rtree *pRtree, - i64 iRowid, - RtreeNode *pNode, - int iHeight -){ - int (*xSetMapping)(Rtree *, sqlite3_int64, sqlite3_int64); - xSetMapping = ((iHeight==0)?rowidWrite:parentWrite); - if( iHeight>0 ){ - RtreeNode *pChild = nodeHashLookup(pRtree, iRowid); - if( pChild ){ - nodeRelease(pRtree, pChild->pParent); - nodeReference(pNode); - pChild->pParent = pNode; - } - } - return xSetMapping(pRtree, iRowid, pNode->iNode); -} - -static int SplitNode( - Rtree *pRtree, - RtreeNode *pNode, - RtreeCell *pCell, - int iHeight -){ - int i; - int newCellIsRight = 0; - - int rc = SQLITE_OK; - int nCell = NCELL(pNode); - RtreeCell *aCell; - int *aiUsed; - - RtreeNode *pLeft = 0; - RtreeNode *pRight = 0; - - RtreeCell leftbbox; - RtreeCell rightbbox; - - /* Allocate an array and populate it with a copy of pCell and - ** all cells from node pLeft. Then zero the original node. - */ - aCell = sqlite3_malloc((sizeof(RtreeCell)+sizeof(int))*(nCell+1)); - if( !aCell ){ - rc = SQLITE_NOMEM; - goto splitnode_out; - } - aiUsed = (int *)&aCell[nCell+1]; - memset(aiUsed, 0, sizeof(int)*(nCell+1)); - for(i=0; iiNode==1 ){ - pRight = nodeNew(pRtree, pNode, 1); - pLeft = nodeNew(pRtree, pNode, 1); - pRtree->iDepth++; - pNode->isDirty = 1; - writeInt16(pNode->zData, pRtree->iDepth); - }else{ - pLeft = pNode; - pRight = nodeNew(pRtree, pLeft->pParent, 1); - nodeReference(pLeft); - } - - if( !pLeft || !pRight ){ - rc = SQLITE_NOMEM; - goto splitnode_out; - } - - memset(pLeft->zData, 0, pRtree->iNodeSize); - memset(pRight->zData, 0, pRtree->iNodeSize); - - rc = AssignCells(pRtree, aCell, nCell, pLeft, pRight, &leftbbox, &rightbbox); - if( rc!=SQLITE_OK ){ - goto splitnode_out; - } - - /* Ensure both child nodes have node numbers assigned to them. */ - if( (0==pRight->iNode && SQLITE_OK!=(rc = nodeWrite(pRtree, pRight))) - || (0==pLeft->iNode && SQLITE_OK!=(rc = nodeWrite(pRtree, pLeft))) - ){ - goto splitnode_out; - } - - rightbbox.iRowid = pRight->iNode; - leftbbox.iRowid = pLeft->iNode; - - if( pNode->iNode==1 ){ - rc = rtreeInsertCell(pRtree, pLeft->pParent, &leftbbox, iHeight+1); - if( rc!=SQLITE_OK ){ - goto splitnode_out; - } - }else{ - RtreeNode *pParent = pLeft->pParent; - int iCell = nodeParentIndex(pRtree, pLeft); - nodeOverwriteCell(pRtree, pParent, &leftbbox, iCell); - AdjustTree(pRtree, pParent, &leftbbox); - } - if( (rc = rtreeInsertCell(pRtree, pRight->pParent, &rightbbox, iHeight+1)) ){ - goto splitnode_out; - } - - for(i=0; iiRowid ){ - newCellIsRight = 1; - } - if( rc!=SQLITE_OK ){ - goto splitnode_out; - } - } - if( pNode->iNode==1 ){ - for(i=0; iiRowid, pLeft, iHeight); - } - - if( rc==SQLITE_OK ){ - rc = nodeRelease(pRtree, pRight); - pRight = 0; - } - if( rc==SQLITE_OK ){ - rc = nodeRelease(pRtree, pLeft); - pLeft = 0; - } - -splitnode_out: - nodeRelease(pRtree, pRight); - nodeRelease(pRtree, pLeft); - sqlite3_free(aCell); - return rc; -} - -static int fixLeafParent(Rtree *pRtree, RtreeNode *pLeaf){ - int rc = SQLITE_OK; - if( pLeaf->iNode!=1 && pLeaf->pParent==0 ){ - sqlite3_bind_int64(pRtree->pReadParent, 1, pLeaf->iNode); - if( sqlite3_step(pRtree->pReadParent)==SQLITE_ROW ){ - i64 iNode = sqlite3_column_int64(pRtree->pReadParent, 0); - rc = nodeAcquire(pRtree, iNode, 0, &pLeaf->pParent); - }else{ - rc = SQLITE_ERROR; - } - sqlite3_reset(pRtree->pReadParent); - if( rc==SQLITE_OK ){ - rc = fixLeafParent(pRtree, pLeaf->pParent); - } - } - return rc; -} - -static int deleteCell(Rtree *, RtreeNode *, int, int); - -static int removeNode(Rtree *pRtree, RtreeNode *pNode, int iHeight){ - int rc; - RtreeNode *pParent; - int iCell; - - assert( pNode->nRef==1 ); - - /* Remove the entry in the parent cell. */ - iCell = nodeParentIndex(pRtree, pNode); - pParent = pNode->pParent; - pNode->pParent = 0; - if( SQLITE_OK!=(rc = deleteCell(pRtree, pParent, iCell, iHeight+1)) - || SQLITE_OK!=(rc = nodeRelease(pRtree, pParent)) - ){ - return rc; - } - - /* Remove the xxx_node entry. */ - sqlite3_bind_int64(pRtree->pDeleteNode, 1, pNode->iNode); - sqlite3_step(pRtree->pDeleteNode); - if( SQLITE_OK!=(rc = sqlite3_reset(pRtree->pDeleteNode)) ){ - return rc; - } - - /* Remove the xxx_parent entry. */ - sqlite3_bind_int64(pRtree->pDeleteParent, 1, pNode->iNode); - sqlite3_step(pRtree->pDeleteParent); - if( SQLITE_OK!=(rc = sqlite3_reset(pRtree->pDeleteParent)) ){ - return rc; - } - - /* Remove the node from the in-memory hash table and link it into - ** the Rtree.pDeleted list. Its contents will be re-inserted later on. - */ - nodeHashDelete(pRtree, pNode); - pNode->iNode = iHeight; - pNode->pNext = pRtree->pDeleted; - pNode->nRef++; - pRtree->pDeleted = pNode; - - return SQLITE_OK; -} - -static void fixBoundingBox(Rtree *pRtree, RtreeNode *pNode){ - RtreeNode *pParent = pNode->pParent; - if( pParent ){ - int ii; - int nCell = NCELL(pNode); - RtreeCell box; /* Bounding box for pNode */ - nodeGetCell(pRtree, pNode, 0, &box); - for(ii=1; iiiNode; - ii = nodeParentIndex(pRtree, pNode); - nodeOverwriteCell(pRtree, pParent, &box, ii); - fixBoundingBox(pRtree, pParent); - } -} - -/* -** Delete the cell at index iCell of node pNode. After removing the -** cell, adjust the r-tree data structure if required. -*/ -static int deleteCell(Rtree *pRtree, RtreeNode *pNode, int iCell, int iHeight){ - int rc; - - if( SQLITE_OK!=(rc = fixLeafParent(pRtree, pNode)) ){ - return rc; - } - - /* Remove the cell from the node. This call just moves bytes around - ** the in-memory node image, so it cannot fail. - */ - nodeDeleteCell(pRtree, pNode, iCell); - - /* If the node is not the tree root and now has less than the minimum - ** number of cells, remove it from the tree. Otherwise, update the - ** cell in the parent node so that it tightly contains the updated - ** node. - */ - if( pNode->iNode!=1 ){ - RtreeNode *pParent = pNode->pParent; - if( (pParent->iNode!=1 || NCELL(pParent)!=1) - && (NCELL(pNode)nDim; iDim++){ - aCenterCoord[iDim] += DCOORD(aCell[ii].aCoord[iDim*2]); - aCenterCoord[iDim] += DCOORD(aCell[ii].aCoord[iDim*2+1]); - } - } - for(iDim=0; iDimnDim; iDim++){ - aCenterCoord[iDim] = aCenterCoord[iDim]/((float)nCell*2.0); - } - - for(ii=0; iinDim; iDim++){ - float coord = DCOORD(aCell[ii].aCoord[iDim*2+1]) - - DCOORD(aCell[ii].aCoord[iDim*2]); - aDistance[ii] += (coord-aCenterCoord[iDim])*(coord-aCenterCoord[iDim]); - } - } - - SortByDistance(aOrder, nCell, aDistance, aSpare); - nodeZero(pRtree, pNode); - - for(ii=0; rc==SQLITE_OK && ii<(nCell-(RTREE_MINCELLS(pRtree)+1)); ii++){ - RtreeCell *p = &aCell[aOrder[ii]]; - nodeInsertCell(pRtree, pNode, p); - if( p->iRowid==pCell->iRowid ){ - if( iHeight==0 ){ - rc = rowidWrite(pRtree, p->iRowid, pNode->iNode); - }else{ - rc = parentWrite(pRtree, p->iRowid, pNode->iNode); - } - } - } - if( rc==SQLITE_OK ){ - fixBoundingBox(pRtree, pNode); - } - for(; rc==SQLITE_OK && iiiNode currently contains - ** the height of the sub-tree headed by the cell. - */ - RtreeNode *pInsert; - RtreeCell *p = &aCell[aOrder[ii]]; - rc = ChooseLeaf(pRtree, p, iHeight, &pInsert); - if( rc==SQLITE_OK ){ - int rc2; - rc = rtreeInsertCell(pRtree, pInsert, p, iHeight); - rc2 = nodeRelease(pRtree, pInsert); - if( rc==SQLITE_OK ){ - rc = rc2; - } - } - } - - sqlite3_free(aCell); - return rc; -} - -/* -** Insert cell pCell into node pNode. Node pNode is the head of a -** subtree iHeight high (leaf nodes have iHeight==0). -*/ -static int rtreeInsertCell( - Rtree *pRtree, - RtreeNode *pNode, - RtreeCell *pCell, - int iHeight -){ - int rc = SQLITE_OK; - if( iHeight>0 ){ - RtreeNode *pChild = nodeHashLookup(pRtree, pCell->iRowid); - if( pChild ){ - nodeRelease(pRtree, pChild->pParent); - nodeReference(pNode); - pChild->pParent = pNode; - } - } - if( nodeInsertCell(pRtree, pNode, pCell) ){ -#if VARIANT_RSTARTREE_REINSERT - if( iHeight<=pRtree->iReinsertHeight || pNode->iNode==1){ - rc = SplitNode(pRtree, pNode, pCell, iHeight); - }else{ - pRtree->iReinsertHeight = iHeight; - rc = Reinsert(pRtree, pNode, pCell, iHeight); - } -#else - rc = SplitNode(pRtree, pNode, pCell, iHeight); -#endif - }else{ - AdjustTree(pRtree, pNode, pCell); - if( iHeight==0 ){ - rc = rowidWrite(pRtree, pCell->iRowid, pNode->iNode); - }else{ - rc = parentWrite(pRtree, pCell->iRowid, pNode->iNode); - } - } - return rc; -} - -static int reinsertNodeContent(Rtree *pRtree, RtreeNode *pNode){ - int ii; - int rc = SQLITE_OK; - int nCell = NCELL(pNode); - - for(ii=0; rc==SQLITE_OK && iiiNode currently contains - ** the height of the sub-tree headed by the cell. - */ - rc = ChooseLeaf(pRtree, &cell, pNode->iNode, &pInsert); - if( rc==SQLITE_OK ){ - int rc2; - rc = rtreeInsertCell(pRtree, pInsert, &cell, pNode->iNode); - rc2 = nodeRelease(pRtree, pInsert); - if( rc==SQLITE_OK ){ - rc = rc2; - } - } - } - return rc; -} - -/* -** Select a currently unused rowid for a new r-tree record. -*/ -static int newRowid(Rtree *pRtree, i64 *piRowid){ - int rc; - sqlite3_bind_null(pRtree->pWriteRowid, 1); - sqlite3_bind_null(pRtree->pWriteRowid, 2); - sqlite3_step(pRtree->pWriteRowid); - rc = sqlite3_reset(pRtree->pWriteRowid); - *piRowid = sqlite3_last_insert_rowid(pRtree->db); - return rc; -} - -#ifndef NDEBUG -static int hashIsEmpty(Rtree *pRtree){ - int ii; - for(ii=0; iiaHash[ii] ); - } - return 1; -} -#endif - -/* -** The xUpdate method for rtree module virtual tables. -*/ -int rtreeUpdate( - sqlite3_vtab *pVtab, - int nData, - sqlite3_value **azData, - sqlite_int64 *pRowid -){ - Rtree *pRtree = (Rtree *)pVtab; - int rc = SQLITE_OK; - - rtreeReference(pRtree); - - assert(nData>=1); - assert(hashIsEmpty(pRtree)); - - /* If azData[0] is not an SQL NULL value, it is the rowid of a - ** record to delete from the r-tree table. The following block does - ** just that. - */ - if( sqlite3_value_type(azData[0])!=SQLITE_NULL ){ - i64 iDelete; /* The rowid to delete */ - RtreeNode *pLeaf; /* Leaf node containing record iDelete */ - int iCell; /* Index of iDelete cell in pLeaf */ - RtreeNode *pRoot; - - /* Obtain a reference to the root node to initialise Rtree.iDepth */ - rc = nodeAcquire(pRtree, 1, 0, &pRoot); - - /* Obtain a reference to the leaf node that contains the entry - ** about to be deleted. - */ - if( rc==SQLITE_OK ){ - iDelete = sqlite3_value_int64(azData[0]); - rc = findLeafNode(pRtree, iDelete, &pLeaf); - } - - /* Delete the cell in question from the leaf node. */ - if( rc==SQLITE_OK ){ - int rc2; - iCell = nodeRowidIndex(pRtree, pLeaf, iDelete); - rc = deleteCell(pRtree, pLeaf, iCell, 0); - rc2 = nodeRelease(pRtree, pLeaf); - if( rc==SQLITE_OK ){ - rc = rc2; - } - } - - /* Delete the corresponding entry in the _rowid table. */ - if( rc==SQLITE_OK ){ - sqlite3_bind_int64(pRtree->pDeleteRowid, 1, iDelete); - sqlite3_step(pRtree->pDeleteRowid); - rc = sqlite3_reset(pRtree->pDeleteRowid); - } - - /* Check if the root node now has exactly one child. If so, remove - ** it, schedule the contents of the child for reinsertion and - ** reduce the tree height by one. - ** - ** This is equivalent to copying the contents of the child into - ** the root node (the operation that Gutman's paper says to perform - ** in this scenario). - */ - if( rc==SQLITE_OK && pRtree->iDepth>0 ){ - if( rc==SQLITE_OK && NCELL(pRoot)==1 ){ - RtreeNode *pChild; - i64 iChild = nodeGetRowid(pRtree, pRoot, 0); - rc = nodeAcquire(pRtree, iChild, pRoot, &pChild); - if( rc==SQLITE_OK ){ - rc = removeNode(pRtree, pChild, pRtree->iDepth-1); - } - if( rc==SQLITE_OK ){ - pRtree->iDepth--; - writeInt16(pRoot->zData, pRtree->iDepth); - pRoot->isDirty = 1; - } - } - } - - /* Re-insert the contents of any underfull nodes removed from the tree. */ - for(pLeaf=pRtree->pDeleted; pLeaf; pLeaf=pRtree->pDeleted){ - if( rc==SQLITE_OK ){ - rc = reinsertNodeContent(pRtree, pLeaf); - } - pRtree->pDeleted = pLeaf->pNext; - sqlite3_free(pLeaf); - } - - /* Release the reference to the root node. */ - if( rc==SQLITE_OK ){ - rc = nodeRelease(pRtree, pRoot); - }else{ - nodeRelease(pRtree, pRoot); - } - } - - /* If the azData[] array contains more than one element, elements - ** (azData[2]..azData[argc-1]) contain a new record to insert into - ** the r-tree structure. - */ - if( rc==SQLITE_OK && nData>1 ){ - /* Insert a new record into the r-tree */ - RtreeCell cell; - int ii; - RtreeNode *pLeaf; - - /* Populate the cell.aCoord[] array. The first coordinate is azData[3]. */ - assert( nData==(pRtree->nDim*2 + 3) ); - if( pRtree->eCoordType==RTREE_COORD_REAL32 ){ - for(ii=0; ii<(pRtree->nDim*2); ii+=2){ - cell.aCoord[ii].f = (float)sqlite3_value_double(azData[ii+3]); - cell.aCoord[ii+1].f = (float)sqlite3_value_double(azData[ii+4]); - if( cell.aCoord[ii].f>cell.aCoord[ii+1].f ){ - rc = SQLITE_CONSTRAINT; - goto constraint; - } - } - }else{ - for(ii=0; ii<(pRtree->nDim*2); ii+=2){ - cell.aCoord[ii].i = sqlite3_value_int(azData[ii+3]); - cell.aCoord[ii+1].i = sqlite3_value_int(azData[ii+4]); - if( cell.aCoord[ii].i>cell.aCoord[ii+1].i ){ - rc = SQLITE_CONSTRAINT; - goto constraint; - } - } - } - - /* Figure out the rowid of the new row. */ - if( sqlite3_value_type(azData[2])==SQLITE_NULL ){ - rc = newRowid(pRtree, &cell.iRowid); - }else{ - cell.iRowid = sqlite3_value_int64(azData[2]); - sqlite3_bind_int64(pRtree->pReadRowid, 1, cell.iRowid); - if( SQLITE_ROW==sqlite3_step(pRtree->pReadRowid) ){ - sqlite3_reset(pRtree->pReadRowid); - rc = SQLITE_CONSTRAINT; - goto constraint; - } - rc = sqlite3_reset(pRtree->pReadRowid); - } - - if( rc==SQLITE_OK ){ - rc = ChooseLeaf(pRtree, &cell, 0, &pLeaf); - } - if( rc==SQLITE_OK ){ - int rc2; - pRtree->iReinsertHeight = -1; - rc = rtreeInsertCell(pRtree, pLeaf, &cell, 0); - rc2 = nodeRelease(pRtree, pLeaf); - if( rc==SQLITE_OK ){ - rc = rc2; - } - } - } - -constraint: - rtreeRelease(pRtree); - return rc; -} - -/* -** The xRename method for rtree module virtual tables. -*/ -static int rtreeRename(sqlite3_vtab *pVtab, const char *zNewName){ - Rtree *pRtree = (Rtree *)pVtab; - int rc = SQLITE_NOMEM; - char *zSql = sqlite3_mprintf( - "ALTER TABLE %Q.'%q_node' RENAME TO \"%w_node\";" - "ALTER TABLE %Q.'%q_parent' RENAME TO \"%w_parent\";" - "ALTER TABLE %Q.'%q_rowid' RENAME TO \"%w_rowid\";" - , pRtree->zDb, pRtree->zName, zNewName - , pRtree->zDb, pRtree->zName, zNewName - , pRtree->zDb, pRtree->zName, zNewName - ); - if( zSql ){ - rc = sqlite3_exec(pRtree->db, zSql, 0, 0, 0); - sqlite3_free(zSql); - } - return rc; -} - -static sqlite3_module rtreeModule = { - 0, /* iVersion */ - rtreeCreate, /* xCreate - create a table */ - rtreeConnect, /* xConnect - connect to an existing table */ - rtreeBestIndex, /* xBestIndex - Determine search strategy */ - rtreeDisconnect, /* xDisconnect - Disconnect from a table */ - rtreeDestroy, /* xDestroy - Drop a table */ - rtreeOpen, /* xOpen - open a cursor */ - rtreeClose, /* xClose - close a cursor */ - rtreeFilter, /* xFilter - configure scan constraints */ - rtreeNext, /* xNext - advance a cursor */ - rtreeEof, /* xEof */ - rtreeColumn, /* xColumn - read data */ - rtreeRowid, /* xRowid - read data */ - rtreeUpdate, /* xUpdate - write data */ - 0, /* xBegin - begin transaction */ - 0, /* xSync - sync transaction */ - 0, /* xCommit - commit transaction */ - 0, /* xRollback - rollback transaction */ - 0, /* xFindFunction - function overloading */ - rtreeRename /* xRename - rename the table */ -}; - -static int rtreeSqlInit( - Rtree *pRtree, - sqlite3 *db, - const char *zDb, - const char *zPrefix, - int isCreate -){ - int rc = SQLITE_OK; - - #define N_STATEMENT 9 - static const char *azSql[N_STATEMENT] = { - /* Read and write the xxx_node table */ - "SELECT data FROM '%q'.'%q_node' WHERE nodeno = :1", - "INSERT OR REPLACE INTO '%q'.'%q_node' VALUES(:1, :2)", - "DELETE FROM '%q'.'%q_node' WHERE nodeno = :1", - - /* Read and write the xxx_rowid table */ - "SELECT nodeno FROM '%q'.'%q_rowid' WHERE rowid = :1", - "INSERT OR REPLACE INTO '%q'.'%q_rowid' VALUES(:1, :2)", - "DELETE FROM '%q'.'%q_rowid' WHERE rowid = :1", - - /* Read and write the xxx_parent table */ - "SELECT parentnode FROM '%q'.'%q_parent' WHERE nodeno = :1", - "INSERT OR REPLACE INTO '%q'.'%q_parent' VALUES(:1, :2)", - "DELETE FROM '%q'.'%q_parent' WHERE nodeno = :1" - }; - sqlite3_stmt **appStmt[N_STATEMENT]; - int i; - - pRtree->db = db; - - if( isCreate ){ - char *zCreate = sqlite3_mprintf( -"CREATE TABLE \"%w\".\"%w_node\"(nodeno INTEGER PRIMARY KEY, data BLOB);" -"CREATE TABLE \"%w\".\"%w_rowid\"(rowid INTEGER PRIMARY KEY, nodeno INTEGER);" -"CREATE TABLE \"%w\".\"%w_parent\"(nodeno INTEGER PRIMARY KEY, parentnode INTEGER);" -"INSERT INTO '%q'.'%q_node' VALUES(1, zeroblob(%d))", - zDb, zPrefix, zDb, zPrefix, zDb, zPrefix, zDb, zPrefix, pRtree->iNodeSize - ); - if( !zCreate ){ - return SQLITE_NOMEM; - } - rc = sqlite3_exec(db, zCreate, 0, 0, 0); - sqlite3_free(zCreate); - if( rc!=SQLITE_OK ){ - return rc; - } - } - - appStmt[0] = &pRtree->pReadNode; - appStmt[1] = &pRtree->pWriteNode; - appStmt[2] = &pRtree->pDeleteNode; - appStmt[3] = &pRtree->pReadRowid; - appStmt[4] = &pRtree->pWriteRowid; - appStmt[5] = &pRtree->pDeleteRowid; - appStmt[6] = &pRtree->pReadParent; - appStmt[7] = &pRtree->pWriteParent; - appStmt[8] = &pRtree->pDeleteParent; - - for(i=0; i module name -** argv[1] -> database name -** argv[2] -> table name -** argv[...] -> column names... -*/ -static int rtreeInit( - sqlite3 *db, /* Database connection */ - void *pAux, /* Pointer to head of rtree list */ - int argc, const char *const*argv, /* Parameters to CREATE TABLE statement */ - sqlite3_vtab **ppVtab, /* OUT: New virtual table */ - char **pzErr, /* OUT: Error message, if any */ - int isCreate, /* True for xCreate, false for xConnect */ - int eCoordType /* One of the RTREE_COORD_* constants */ -){ - int rc = SQLITE_OK; - int iPageSize = 0; - Rtree *pRtree; - int nDb; /* Length of string argv[1] */ - int nName; /* Length of string argv[2] */ - - const char *aErrMsg[] = { - 0, /* 0 */ - "Wrong number of columns for an rtree table", /* 1 */ - "Too few columns for an rtree table", /* 2 */ - "Too many columns for an rtree table" /* 3 */ - }; - - int iErr = (argc<6) ? 2 : argc>(RTREE_MAX_DIMENSIONS*2+4) ? 3 : argc%2; - if( aErrMsg[iErr] ){ - *pzErr = sqlite3_mprintf("%s", aErrMsg[iErr]); - return SQLITE_ERROR; - } - - rc = getPageSize(db, argv[1], &iPageSize); - if( rc!=SQLITE_OK ){ - return rc; - } - - /* Allocate the sqlite3_vtab structure */ - nDb = strlen(argv[1]); - nName = strlen(argv[2]); - pRtree = (Rtree *)sqlite3_malloc(sizeof(Rtree)+nDb+nName+2); - if( !pRtree ){ - return SQLITE_NOMEM; - } - memset(pRtree, 0, sizeof(Rtree)+nDb+nName+2); - pRtree->nBusy = 1; - pRtree->base.pModule = &rtreeModule; - pRtree->zDb = (char *)&pRtree[1]; - pRtree->zName = &pRtree->zDb[nDb+1]; - pRtree->nDim = (argc-4)/2; - pRtree->nBytesPerCell = 8 + pRtree->nDim*4*2; - pRtree->eCoordType = eCoordType; - memcpy(pRtree->zDb, argv[1], nDb); - memcpy(pRtree->zName, argv[2], nName); - - /* Figure out the node size to use. By default, use 64 bytes less than - ** the database page-size. This ensures that each node is stored on - ** a single database page. - ** - ** If the databasd page-size is so large that more than RTREE_MAXCELLS - ** entries would fit in a single node, use a smaller node-size. - */ - pRtree->iNodeSize = iPageSize-64; - if( (4+pRtree->nBytesPerCell*RTREE_MAXCELLS)iNodeSize ){ - pRtree->iNodeSize = 4+pRtree->nBytesPerCell*RTREE_MAXCELLS; - } - - /* Create/Connect to the underlying relational database schema. If - ** that is successful, call sqlite3_declare_vtab() to configure - ** the r-tree table schema. - */ - if( (rc = rtreeSqlInit(pRtree, db, argv[1], argv[2], isCreate)) ){ - *pzErr = sqlite3_mprintf("%s", sqlite3_errmsg(db)); - }else{ - char *zSql = sqlite3_mprintf("CREATE TABLE x(%s", argv[3]); - char *zTmp; - int ii; - for(ii=4; zSql && ii*2 coordinates. -*/ -static void rtreenode(sqlite3_context *ctx, int nArg, sqlite3_value **apArg){ - char *zText = 0; - RtreeNode node; - Rtree tree; - int ii; - - memset(&node, 0, sizeof(RtreeNode)); - memset(&tree, 0, sizeof(Rtree)); - tree.nDim = sqlite3_value_int(apArg[0]); - tree.nBytesPerCell = 8 + 8 * tree.nDim; - node.zData = (u8 *)sqlite3_value_blob(apArg[1]); - - for(ii=0; ii -#include -#include -#include - - -#ifndef SQLITE_CORE - SQLITE_EXTENSION_INIT1 -#else -#endif - -/* -** Maximum length (in bytes) of the pattern in a LIKE or GLOB -** operator. -*/ -#ifndef SQLITE_MAX_LIKE_PATTERN_LENGTH -# define SQLITE_MAX_LIKE_PATTERN_LENGTH 50000 -#endif - -/* -** Version of sqlite3_free() that is always a function, never a macro. -*/ -static void xFree(void *p){ - sqlite3_free(p); -} - -/* -** Compare two UTF-8 strings for equality where the first string is -** a "LIKE" expression. Return true (1) if they are the same and -** false (0) if they are different. -*/ -static int icuLikeCompare( - const uint8_t *zPattern, /* LIKE pattern */ - const uint8_t *zString, /* The UTF-8 string to compare against */ - const UChar32 uEsc /* The escape character */ -){ - static const int MATCH_ONE = (UChar32)'_'; - static const int MATCH_ALL = (UChar32)'%'; - - int iPattern = 0; /* Current byte index in zPattern */ - int iString = 0; /* Current byte index in zString */ - - int prevEscape = 0; /* True if the previous character was uEsc */ - - while( zPattern[iPattern]!=0 ){ - - /* Read (and consume) the next character from the input pattern. */ - UChar32 uPattern; - U8_NEXT_UNSAFE(zPattern, iPattern, uPattern); - assert(uPattern!=0); - - /* There are now 4 possibilities: - ** - ** 1. uPattern is an unescaped match-all character "%", - ** 2. uPattern is an unescaped match-one character "_", - ** 3. uPattern is an unescaped escape character, or - ** 4. uPattern is to be handled as an ordinary character - */ - if( !prevEscape && uPattern==MATCH_ALL ){ - /* Case 1. */ - uint8_t c; - - /* Skip any MATCH_ALL or MATCH_ONE characters that follow a - ** MATCH_ALL. For each MATCH_ONE, skip one character in the - ** test string. - */ - while( (c=zPattern[iPattern]) == MATCH_ALL || c == MATCH_ONE ){ - if( c==MATCH_ONE ){ - if( zString[iString]==0 ) return 0; - U8_FWD_1_UNSAFE(zString, iString); - } - iPattern++; - } - - if( zPattern[iPattern]==0 ) return 1; - - while( zString[iString] ){ - if( icuLikeCompare(&zPattern[iPattern], &zString[iString], uEsc) ){ - return 1; - } - U8_FWD_1_UNSAFE(zString, iString); - } - return 0; - - }else if( !prevEscape && uPattern==MATCH_ONE ){ - /* Case 2. */ - if( zString[iString]==0 ) return 0; - U8_FWD_1_UNSAFE(zString, iString); - - }else if( !prevEscape && uPattern==uEsc){ - /* Case 3. */ - prevEscape = 1; - - }else{ - /* Case 4. */ - UChar32 uString; - U8_NEXT_UNSAFE(zString, iString, uString); - uString = u_foldCase(uString, U_FOLD_CASE_DEFAULT); - uPattern = u_foldCase(uPattern, U_FOLD_CASE_DEFAULT); - if( uString!=uPattern ){ - return 0; - } - prevEscape = 0; - } - } - - return zString[iString]==0; -} - -/* -** Implementation of the like() SQL function. This function implements -** the build-in LIKE operator. The first argument to the function is the -** pattern and the second argument is the string. So, the SQL statements: -** -** A LIKE B -** -** is implemented as like(B, A). If there is an escape character E, -** -** A LIKE B ESCAPE E -** -** is mapped to like(B, A, E). -*/ -static void icuLikeFunc( - sqlite3_context *context, - int argc, - sqlite3_value **argv -){ - const unsigned char *zA = sqlite3_value_text(argv[0]); - const unsigned char *zB = sqlite3_value_text(argv[1]); - UChar32 uEsc = 0; - - /* Limit the length of the LIKE or GLOB pattern to avoid problems - ** of deep recursion and N*N behavior in patternCompare(). - */ - if( sqlite3_value_bytes(argv[0])>SQLITE_MAX_LIKE_PATTERN_LENGTH ){ - sqlite3_result_error(context, "LIKE or GLOB pattern too complex", -1); - return; - } - - - if( argc==3 ){ - /* The escape character string must consist of a single UTF-8 character. - ** Otherwise, return an error. - */ - int nE= sqlite3_value_bytes(argv[2]); - const unsigned char *zE = sqlite3_value_text(argv[2]); - int i = 0; - if( zE==0 ) return; - U8_NEXT(zE, i, nE, uEsc); - if( i!=nE){ - sqlite3_result_error(context, - "ESCAPE expression must be a single character", -1); - return; - } - } - - if( zA && zB ){ - sqlite3_result_int(context, icuLikeCompare(zA, zB, uEsc)); - } -} - -/* -** This function is called when an ICU function called from within -** the implementation of an SQL scalar function returns an error. -** -** The scalar function context passed as the first argument is -** loaded with an error message based on the following two args. -*/ -static void icuFunctionError( - sqlite3_context *pCtx, /* SQLite scalar function context */ - const char *zName, /* Name of ICU function that failed */ - UErrorCode e /* Error code returned by ICU function */ -){ - char zBuf[128]; - sqlite3_snprintf(128, zBuf, "ICU error: %s(): %s", zName, u_errorName(e)); - zBuf[127] = '\0'; - sqlite3_result_error(pCtx, zBuf, -1); -} - -/* -** Function to delete compiled regexp objects. Registered as -** a destructor function with sqlite3_set_auxdata(). -*/ -static void icuRegexpDelete(void *p){ - URegularExpression *pExpr = (URegularExpression *)p; - uregex_close(pExpr); -} - -/* -** Implementation of SQLite REGEXP operator. This scalar function takes -** two arguments. The first is a regular expression pattern to compile -** the second is a string to match against that pattern. If either -** argument is an SQL NULL, then NULL Is returned. Otherwise, the result -** is 1 if the string matches the pattern, or 0 otherwise. -** -** SQLite maps the regexp() function to the regexp() operator such -** that the following two are equivalent: -** -** zString REGEXP zPattern -** regexp(zPattern, zString) -** -** Uses the following ICU regexp APIs: -** -** uregex_open() -** uregex_matches() -** uregex_close() -*/ -static void icuRegexpFunc(sqlite3_context *p, int nArg, sqlite3_value **apArg){ - UErrorCode status = U_ZERO_ERROR; - URegularExpression *pExpr; - UBool res; - const UChar *zString = sqlite3_value_text16(apArg[1]); - - /* If the left hand side of the regexp operator is NULL, - ** then the result is also NULL. - */ - if( !zString ){ - return; - } - - pExpr = sqlite3_get_auxdata(p, 0); - if( !pExpr ){ - const UChar *zPattern = sqlite3_value_text16(apArg[0]); - if( !zPattern ){ - return; - } - pExpr = uregex_open(zPattern, -1, 0, 0, &status); - - if( U_SUCCESS(status) ){ - sqlite3_set_auxdata(p, 0, pExpr, icuRegexpDelete); - }else{ - assert(!pExpr); - icuFunctionError(p, "uregex_open", status); - return; - } - } - - /* Configure the text that the regular expression operates on. */ - uregex_setText(pExpr, zString, -1, &status); - if( !U_SUCCESS(status) ){ - icuFunctionError(p, "uregex_setText", status); - return; - } - - /* Attempt the match */ - res = uregex_matches(pExpr, 0, &status); - if( !U_SUCCESS(status) ){ - icuFunctionError(p, "uregex_matches", status); - return; - } - - /* Set the text that the regular expression operates on to a NULL - ** pointer. This is not really necessary, but it is tidier than - ** leaving the regular expression object configured with an invalid - ** pointer after this function returns. - */ - uregex_setText(pExpr, 0, 0, &status); - - /* Return 1 or 0. */ - sqlite3_result_int(p, res ? 1 : 0); -} - -/* -** Implementations of scalar functions for case mapping - upper() and -** lower(). Function upper() converts its input to upper-case (ABC). -** Function lower() converts to lower-case (abc). -** -** ICU provides two types of case mapping, "general" case mapping and -** "language specific". Refer to ICU documentation for the differences -** between the two. -** -** To utilise "general" case mapping, the upper() or lower() scalar -** functions are invoked with one argument: -** -** upper('ABC') -> 'abc' -** lower('abc') -> 'ABC' -** -** To access ICU "language specific" case mapping, upper() or lower() -** should be invoked with two arguments. The second argument is the name -** of the locale to use. Passing an empty string ("") or SQL NULL value -** as the second argument is the same as invoking the 1 argument version -** of upper() or lower(). -** -** lower('I', 'en_us') -> 'i' -** lower('I', 'tr_tr') -> 'ı' (small dotless i) -** -** http://www.icu-project.org/userguide/posix.html#case_mappings -*/ -static void icuCaseFunc16(sqlite3_context *p, int nArg, sqlite3_value **apArg){ - const UChar *zInput; - UChar *zOutput; - int nInput; - int nOutput; - - UErrorCode status = U_ZERO_ERROR; - const char *zLocale = 0; - - assert(nArg==1 || nArg==2); - if( nArg==2 ){ - zLocale = (const char *)sqlite3_value_text(apArg[1]); - } - - zInput = sqlite3_value_text16(apArg[0]); - if( !zInput ){ - return; - } - nInput = sqlite3_value_bytes16(apArg[0]); - - nOutput = nInput * 2 + 2; - zOutput = sqlite3_malloc(nOutput); - if( !zOutput ){ - return; - } - - if( sqlite3_user_data(p) ){ - u_strToUpper(zOutput, nOutput/2, zInput, nInput/2, zLocale, &status); - }else{ - u_strToLower(zOutput, nOutput/2, zInput, nInput/2, zLocale, &status); - } - - if( !U_SUCCESS(status) ){ - icuFunctionError(p, "u_strToLower()/u_strToUpper", status); - return; - } - - sqlite3_result_text16(p, zOutput, -1, xFree); -} - -/* -** Collation sequence destructor function. The pCtx argument points to -** a UCollator structure previously allocated using ucol_open(). -*/ -static void icuCollationDel(void *pCtx){ - UCollator *p = (UCollator *)pCtx; - ucol_close(p); -} - -/* -** Collation sequence comparison function. The pCtx argument points to -** a UCollator structure previously allocated using ucol_open(). -*/ -static int icuCollationColl( - void *pCtx, - int nLeft, - const void *zLeft, - int nRight, - const void *zRight -){ - UCollationResult res; - UCollator *p = (UCollator *)pCtx; - res = ucol_strcoll(p, (UChar *)zLeft, nLeft/2, (UChar *)zRight, nRight/2); - switch( res ){ - case UCOL_LESS: return -1; - case UCOL_GREATER: return +1; - case UCOL_EQUAL: return 0; - } - assert(!"Unexpected return value from ucol_strcoll()"); - return 0; -} - -/* -** Implementation of the scalar function icu_load_collation(). -** -** This scalar function is used to add ICU collation based collation -** types to an SQLite database connection. It is intended to be called -** as follows: -** -** SELECT icu_load_collation(, ); -** -** Where is a string containing an ICU locale identifier (i.e. -** "en_AU", "tr_TR" etc.) and is the name of the -** collation sequence to create. -*/ -static void icuLoadCollation( - sqlite3_context *p, - int nArg, - sqlite3_value **apArg -){ - sqlite3 *db = (sqlite3 *)sqlite3_user_data(p); - UErrorCode status = U_ZERO_ERROR; - const char *zLocale; /* Locale identifier - (eg. "jp_JP") */ - const char *zName; /* SQL Collation sequence name (eg. "japanese") */ - UCollator *pUCollator; /* ICU library collation object */ - int rc; /* Return code from sqlite3_create_collation_x() */ - - assert(nArg==2); - zLocale = (const char *)sqlite3_value_text(apArg[0]); - zName = (const char *)sqlite3_value_text(apArg[1]); - - if( !zLocale || !zName ){ - return; - } - - pUCollator = ucol_open(zLocale, &status); - if( !U_SUCCESS(status) ){ - icuFunctionError(p, "ucol_open", status); - return; - } - assert(p); - - rc = sqlite3_create_collation_v2(db, zName, SQLITE_UTF16, (void *)pUCollator, - icuCollationColl, icuCollationDel - ); - if( rc!=SQLITE_OK ){ - ucol_close(pUCollator); - sqlite3_result_error(p, "Error registering collation function", -1); - } -} - -/* -** Register the ICU extension functions with database db. -*/ -SQLITE_PRIVATE int sqlite3IcuInit(sqlite3 *db){ - struct IcuScalar { - const char *zName; /* Function name */ - int nArg; /* Number of arguments */ - int enc; /* Optimal text encoding */ - void *pContext; /* sqlite3_user_data() context */ - void (*xFunc)(sqlite3_context*,int,sqlite3_value**); - } scalars[] = { - {"regexp",-1, SQLITE_ANY, 0, icuRegexpFunc}, - - {"lower", 1, SQLITE_UTF16, 0, icuCaseFunc16}, - {"lower", 2, SQLITE_UTF16, 0, icuCaseFunc16}, - {"upper", 1, SQLITE_UTF16, (void*)1, icuCaseFunc16}, - {"upper", 2, SQLITE_UTF16, (void*)1, icuCaseFunc16}, - - {"lower", 1, SQLITE_UTF8, 0, icuCaseFunc16}, - {"lower", 2, SQLITE_UTF8, 0, icuCaseFunc16}, - {"upper", 1, SQLITE_UTF8, (void*)1, icuCaseFunc16}, - {"upper", 2, SQLITE_UTF8, (void*)1, icuCaseFunc16}, - - {"like", 2, SQLITE_UTF8, 0, icuLikeFunc}, - {"like", 3, SQLITE_UTF8, 0, icuLikeFunc}, - - {"icu_load_collation", 2, SQLITE_UTF8, (void*)db, icuLoadCollation}, - }; - - int rc = SQLITE_OK; - int i; - - for(i=0; rc==SQLITE_OK && i<(sizeof(scalars)/sizeof(struct IcuScalar)); i++){ - struct IcuScalar *p = &scalars[i]; - rc = sqlite3_create_function( - db, p->zName, p->nArg, p->enc, p->pContext, p->xFunc, 0, 0 - ); - } - - return rc; -} - -#if !SQLITE_CORE -SQLITE_API int sqlite3_extension_init( - sqlite3 *db, - char **pzErrMsg, - const sqlite3_api_routines *pApi -){ - SQLITE_EXTENSION_INIT2(pApi) - return sqlite3IcuInit(db); -} -#endif - -#endif - -/************** End of icu.c *************************************************/ -/************** Begin file fts3_icu.c ****************************************/ -/* -** 2007 June 22 -** -** The author disclaims copyright to this source code. In place of -** a legal notice, here is a blessing: -** -** May you do good and not evil. -** May you find forgiveness for yourself and forgive others. -** May you share freely, never taking more than you give. -** -************************************************************************* -** This file implements a tokenizer for fts3 based on the ICU library. -** -** $Id: fts3_icu.c,v 1.3 2008/09/01 18:34:20 danielk1977 Exp $ -*/ - -#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) -#ifdef SQLITE_ENABLE_ICU - - -#include -#include - -typedef struct IcuTokenizer IcuTokenizer; -typedef struct IcuCursor IcuCursor; - -struct IcuTokenizer { - sqlite3_tokenizer base; - char *zLocale; -}; - -struct IcuCursor { - sqlite3_tokenizer_cursor base; - - UBreakIterator *pIter; /* ICU break-iterator object */ - int nChar; /* Number of UChar elements in pInput */ - UChar *aChar; /* Copy of input using utf-16 encoding */ - int *aOffset; /* Offsets of each character in utf-8 input */ - - int nBuffer; - char *zBuffer; - - int iToken; -}; - -/* -** Create a new tokenizer instance. -*/ -static int icuCreate( - int argc, /* Number of entries in argv[] */ - const char * const *argv, /* Tokenizer creation arguments */ - sqlite3_tokenizer **ppTokenizer /* OUT: Created tokenizer */ -){ - IcuTokenizer *p; - int n = 0; - - if( argc>0 ){ - n = strlen(argv[0])+1; - } - p = (IcuTokenizer *)sqlite3_malloc(sizeof(IcuTokenizer)+n); - if( !p ){ - return SQLITE_NOMEM; - } - memset(p, 0, sizeof(IcuTokenizer)); - - if( n ){ - p->zLocale = (char *)&p[1]; - memcpy(p->zLocale, argv[0], n); - } - - *ppTokenizer = (sqlite3_tokenizer *)p; - - return SQLITE_OK; -} - -/* -** Destroy a tokenizer -*/ -static int icuDestroy(sqlite3_tokenizer *pTokenizer){ - IcuTokenizer *p = (IcuTokenizer *)pTokenizer; - sqlite3_free(p); - return SQLITE_OK; -} - -/* -** Prepare to begin tokenizing a particular string. The input -** string to be tokenized is pInput[0..nBytes-1]. A cursor -** used to incrementally tokenize this string is returned in -** *ppCursor. -*/ -static int icuOpen( - sqlite3_tokenizer *pTokenizer, /* The tokenizer */ - const char *zInput, /* Input string */ - int nInput, /* Length of zInput in bytes */ - sqlite3_tokenizer_cursor **ppCursor /* OUT: Tokenization cursor */ -){ - IcuTokenizer *p = (IcuTokenizer *)pTokenizer; - IcuCursor *pCsr; - - const int32_t opt = U_FOLD_CASE_DEFAULT; - UErrorCode status = U_ZERO_ERROR; - int nChar; - - UChar32 c; - int iInput = 0; - int iOut = 0; - - *ppCursor = 0; - - if( nInput<0 ){ - nInput = strlen(zInput); - } - nChar = nInput+1; - pCsr = (IcuCursor *)sqlite3_malloc( - sizeof(IcuCursor) + /* IcuCursor */ - nChar * sizeof(UChar) + /* IcuCursor.aChar[] */ - (nChar+1) * sizeof(int) /* IcuCursor.aOffset[] */ - ); - if( !pCsr ){ - return SQLITE_NOMEM; - } - memset(pCsr, 0, sizeof(IcuCursor)); - pCsr->aChar = (UChar *)&pCsr[1]; - pCsr->aOffset = (int *)&pCsr->aChar[nChar]; - - pCsr->aOffset[iOut] = iInput; - U8_NEXT(zInput, iInput, nInput, c); - while( c>0 ){ - int isError = 0; - c = u_foldCase(c, opt); - U16_APPEND(pCsr->aChar, iOut, nChar, c, isError); - if( isError ){ - sqlite3_free(pCsr); - return SQLITE_ERROR; - } - pCsr->aOffset[iOut] = iInput; - - if( iInputpIter = ubrk_open(UBRK_WORD, p->zLocale, pCsr->aChar, iOut, &status); - if( !U_SUCCESS(status) ){ - sqlite3_free(pCsr); - return SQLITE_ERROR; - } - pCsr->nChar = iOut; - - ubrk_first(pCsr->pIter); - *ppCursor = (sqlite3_tokenizer_cursor *)pCsr; - return SQLITE_OK; -} - -/* -** Close a tokenization cursor previously opened by a call to icuOpen(). -*/ -static int icuClose(sqlite3_tokenizer_cursor *pCursor){ - IcuCursor *pCsr = (IcuCursor *)pCursor; - ubrk_close(pCsr->pIter); - sqlite3_free(pCsr->zBuffer); - sqlite3_free(pCsr); - return SQLITE_OK; -} - -/* -** Extract the next token from a tokenization cursor. -*/ -static int icuNext( - sqlite3_tokenizer_cursor *pCursor, /* Cursor returned by simpleOpen */ - const char **ppToken, /* OUT: *ppToken is the token text */ - int *pnBytes, /* OUT: Number of bytes in token */ - int *piStartOffset, /* OUT: Starting offset of token */ - int *piEndOffset, /* OUT: Ending offset of token */ - int *piPosition /* OUT: Position integer of token */ -){ - IcuCursor *pCsr = (IcuCursor *)pCursor; - - int iStart = 0; - int iEnd = 0; - int nByte = 0; - - while( iStart==iEnd ){ - UChar32 c; - - iStart = ubrk_current(pCsr->pIter); - iEnd = ubrk_next(pCsr->pIter); - if( iEnd==UBRK_DONE ){ - return SQLITE_DONE; - } - - while( iStartaChar, iWhite, pCsr->nChar, c); - if( u_isspace(c) ){ - iStart = iWhite; - }else{ - break; - } - } - assert(iStart<=iEnd); - } - - do { - UErrorCode status = U_ZERO_ERROR; - if( nByte ){ - char *zNew = sqlite3_realloc(pCsr->zBuffer, nByte); - if( !zNew ){ - return SQLITE_NOMEM; - } - pCsr->zBuffer = zNew; - pCsr->nBuffer = nByte; - } - - u_strToUTF8( - pCsr->zBuffer, pCsr->nBuffer, &nByte, /* Output vars */ - &pCsr->aChar[iStart], iEnd-iStart, /* Input vars */ - &status /* Output success/failure */ - ); - } while( nByte>pCsr->nBuffer ); - - *ppToken = pCsr->zBuffer; - *pnBytes = nByte; - *piStartOffset = pCsr->aOffset[iStart]; - *piEndOffset = pCsr->aOffset[iEnd]; - *piPosition = pCsr->iToken++; - - return SQLITE_OK; -} - -/* -** The set of routines that implement the simple tokenizer -*/ -static const sqlite3_tokenizer_module icuTokenizerModule = { - 0, /* iVersion */ - icuCreate, /* xCreate */ - icuDestroy, /* xCreate */ - icuOpen, /* xOpen */ - icuClose, /* xClose */ - icuNext, /* xNext */ -}; - -/* -** Set *ppModule to point at the implementation of the ICU tokenizer. -*/ -SQLITE_PRIVATE void sqlite3Fts3IcuTokenizerModule( - sqlite3_tokenizer_module const**ppModule -){ - *ppModule = &icuTokenizerModule; -} - -#endif /* defined(SQLITE_ENABLE_ICU) */ -#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) */ - -/************** End of fts3_icu.c ********************************************/ diff --git a/mozilla/db/sqlite3/src/sqlite3.h b/mozilla/db/sqlite3/src/sqlite3.h index e8356498bee..a492b6d22fc 100644 --- a/mozilla/db/sqlite3/src/sqlite3.h +++ b/mozilla/db/sqlite3/src/sqlite3.h @@ -17,7 +17,7 @@ ** ** Some of the definitions that are in this file are marked as ** "experimental". Experimental interfaces are normally new -** features recently added to SQLite. We do not anticipate changes +** features recently added to SQLite. We do not anticipate changes ** to experimental interfaces but reserve to make minor changes if ** experience from use "in the wild" suggest such changes are prudent. ** @@ -30,7 +30,7 @@ ** the version number) and changes its name to "sqlite3.h" as ** part of the build process. ** -** @(#) $Id: sqlite.h.in,v 1.404 2008/10/12 00:27:54 shane Exp $ +** @(#) $Id: sqlite.h.in,v 1.312 2008/05/12 12:39:56 drh Exp $ */ #ifndef _SQLITE3_H_ #define _SQLITE3_H_ @@ -52,23 +52,8 @@ extern "C" { #endif /* -** These no-op macros are used in front of interfaces to mark those -** interfaces as either deprecated or experimental. New applications -** should not use deprecated intrfaces - they are support for backwards -** compatibility only. Application writers should be aware that -** experimental interfaces are subject to change in point releases. -** -** These macros used to resolve to various kinds of compiler magic that -** would generate warning messages when they were used. But that -** compiler magic ended up generating such a flurry of bug reports -** that we have taken it all out and gone back to using simple -** noop macros. -*/ -#define SQLITE_DEPRECATED -#define SQLITE_EXPERIMENTAL - -/* -** Ensure these symbols were not defined by some previous header file. +** Make sure these symbols where not defined by some previous header +** file. */ #ifdef SQLITE_VERSION # undef SQLITE_VERSION @@ -78,7 +63,7 @@ extern "C" { #endif /* -** CAPI3REF: Compile-Time Library Version Numbers {H10010} +** CAPI3REF: Compile-Time Library Version Numbers {F10010} ** ** The SQLITE_VERSION and SQLITE_VERSION_NUMBER #defines in ** the sqlite3.h file specify the version of SQLite with which @@ -87,38 +72,39 @@ extern "C" { ** The "version" of SQLite is a string of the form "X.Y.Z". ** The phrase "alpha" or "beta" might be appended after the Z. ** The X value is major version number always 3 in SQLite3. -** The X value only changes when backwards compatibility is -** broken and we intend to never break backwards compatibility. -** The Y value is the minor version number and only changes when +** The X value only changes when backwards compatibility is +** broken and we intend to never break +** backwards compatibility. The Y value is the minor version +** number and only changes when ** there are major feature enhancements that are forwards compatible -** but not backwards compatible. -** The Z value is the release number and is incremented with -** each release but resets back to 0 whenever Y is incremented. +** but not backwards compatible. The Z value is release number +** and is incremented with +** each release but resets back to 0 when Y is incremented. ** ** See also: [sqlite3_libversion()] and [sqlite3_libversion_number()]. ** ** INVARIANTS: ** -** {H10011} The SQLITE_VERSION #define in the sqlite3.h header file shall -** evaluate to a string literal that is the SQLite version +** {F10011} The SQLITE_VERSION #define in the sqlite3.h header file +** evaluates to a string literal that is the SQLite version ** with which the header file is associated. ** -** {H10014} The SQLITE_VERSION_NUMBER #define shall resolve to an integer -** with the value (X*1000000 + Y*1000 + Z) where X, Y, and Z -** are the major version, minor version, and release number. +** {F10014} The SQLITE_VERSION_NUMBER #define resolves to an integer +** with the value (X*1000000 + Y*1000 + Z) where X, Y, and +** Z are the major version, minor version, and release number. */ -#define SQLITE_VERSION "3.6.4" -#define SQLITE_VERSION_NUMBER 3006004 +#define SQLITE_VERSION "3.5.9" +#define SQLITE_VERSION_NUMBER 3005009 /* -** CAPI3REF: Run-Time Library Version Numbers {H10020} +** CAPI3REF: Run-Time Library Version Numbers {F10020} ** KEYWORDS: sqlite3_version ** ** These features provide the same information as the [SQLITE_VERSION] ** and [SQLITE_VERSION_NUMBER] #defines in the header, but are associated ** with the library instead of the header file. Cautious programmers might -** include a check in their application to verify that -** sqlite3_libversion_number() always returns the value +** include a check in their application to verify that +** sqlite3_libversion_number() always returns the value ** [SQLITE_VERSION_NUMBER]. ** ** The sqlite3_libversion() function returns the same information as is @@ -128,13 +114,13 @@ extern "C" { ** ** INVARIANTS: ** -** {H10021} The [sqlite3_libversion_number()] interface shall return -** an integer equal to [SQLITE_VERSION_NUMBER]. +** {F10021} The [sqlite3_libversion_number()] interface returns an integer +** equal to [SQLITE_VERSION_NUMBER]. ** -** {H10022} The [sqlite3_version] string constant shall contain -** the text of the [SQLITE_VERSION] string. +** {F10022} The [sqlite3_version] string constant contains the text of the +** [SQLITE_VERSION] string. ** -** {H10023} The [sqlite3_libversion()] function shall return +** {F10023} The [sqlite3_libversion()] function returns ** a pointer to the [sqlite3_version] string constant. */ SQLITE_EXTERN const char sqlite3_version[]; @@ -142,77 +128,64 @@ const char *sqlite3_libversion(void); int sqlite3_libversion_number(void); /* -** CAPI3REF: Test To See If The Library Is Threadsafe {H10100} +** CAPI3REF: Test To See If The Library Is Threadsafe {F10100} ** ** SQLite can be compiled with or without mutexes. When -** the [SQLITE_THREADSAFE] C preprocessor macro 1 or 2, mutexes -** are enabled and SQLite is threadsafe. When the -** [SQLITE_THREADSAFE] macro is 0, +** the SQLITE_THREADSAFE C preprocessor macro is true, mutexes +** are enabled and SQLite is threadsafe. When that macro is false, ** the mutexes are omitted. Without the mutexes, it is not safe -** to use SQLite concurrently from more than one thread. +** to use SQLite from more than one thread. ** -** Enabling mutexes incurs a measurable performance penalty. +** There is a measurable performance penalty for enabling mutexes. ** So if speed is of utmost importance, it makes sense to disable ** the mutexes. But for maximum safety, mutexes should be enabled. ** The default behavior is for mutexes to be enabled. ** ** This interface can be used by a program to make sure that the ** version of SQLite that it is linking against was compiled with -** the desired setting of the [SQLITE_THREADSAFE] macro. -** -** This interface only reports on the compile-time mutex setting -** of the [SQLITE_THREADSAFE] flag. If SQLite is compiled with -** SQLITE_THREADSAFE=1 then mutexes are enabled by default but -** can be fully or partially disabled using a call to [sqlite3_config()] -** with the verbs [SQLITE_CONFIG_SINGLETHREAD], [SQLITE_CONFIG_MULTITHREAD], -** or [SQLITE_CONFIG_MUTEX]. The return value of this function shows -** only the default compile-time setting, not any run-time changes -** to that setting. -** -** See the [threading mode] documentation for additional information. +** the desired setting of the SQLITE_THREADSAFE macro. ** ** INVARIANTS: ** -** {H10101} The [sqlite3_threadsafe()] function shall return zero if -** and only if SQLite was compiled with mutexing code omitted. -** -** {H10102} The value returned by the [sqlite3_threadsafe()] function -** shall remain the same across calls to [sqlite3_config()]. +** {F10101} The [sqlite3_threadsafe()] function returns nonzero if +** SQLite was compiled with its mutexes enabled or zero +** if SQLite was compiled with mutexes disabled. */ int sqlite3_threadsafe(void); /* -** CAPI3REF: Database Connection Handle {H12000} +** CAPI3REF: Database Connection Handle {F12000} ** KEYWORDS: {database connection} {database connections} ** -** Each open SQLite database is represented by a pointer to an instance of -** the opaque structure named "sqlite3". It is useful to think of an sqlite3 +** Each open SQLite database is represented by pointer to an instance of the +** opaque structure named "sqlite3". It is useful to think of an sqlite3 ** pointer as an object. The [sqlite3_open()], [sqlite3_open16()], and -** [sqlite3_open_v2()] interfaces are its constructors, and [sqlite3_close()] -** is its destructor. There are many other interfaces (such as -** [sqlite3_prepare_v2()], [sqlite3_create_function()], and -** [sqlite3_busy_timeout()] to name but three) that are methods on an -** sqlite3 object. +** [sqlite3_open_v2()] interfaces are its constructors +** and [sqlite3_close()] is its destructor. There are many other interfaces +** (such as [sqlite3_prepare_v2()], [sqlite3_create_function()], and +** [sqlite3_busy_timeout()] to name but three) that are methods on this +** object. */ typedef struct sqlite3 sqlite3; + /* -** CAPI3REF: 64-Bit Integer Types {H10200} +** CAPI3REF: 64-Bit Integer Types {F10200} ** KEYWORDS: sqlite_int64 sqlite_uint64 ** ** Because there is no cross-platform way to specify 64-bit integer types ** SQLite includes typedefs for 64-bit signed and unsigned integers. ** -** The sqlite3_int64 and sqlite3_uint64 are the preferred type definitions. -** The sqlite_int64 and sqlite_uint64 types are supported for backwards -** compatibility only. +** The sqlite3_int64 and sqlite3_uint64 are the preferred type +** definitions. The sqlite_int64 and sqlite_uint64 types are +** supported for backwards compatibility only. ** ** INVARIANTS: ** -** {H10201} The [sqlite_int64] and [sqlite3_int64] type shall specify -** a 64-bit signed integer. +** {F10201} The [sqlite_int64] and [sqlite3_int64] types specify a +** 64-bit signed integer. ** -** {H10202} The [sqlite_uint64] and [sqlite3_uint64] type shall specify +** {F10202} The [sqlite_uint64] and [sqlite3_uint64] types specify ** a 64-bit unsigned integer. */ #ifdef SQLITE_INT64_TYPE @@ -230,62 +203,50 @@ typedef sqlite_uint64 sqlite3_uint64; /* ** If compiling for a processor that lacks floating point support, -** substitute integer for floating-point. +** substitute integer for floating-point */ #ifdef SQLITE_OMIT_FLOATING_POINT # define double sqlite3_int64 #endif /* -** CAPI3REF: Closing A Database Connection {H12010} +** CAPI3REF: Closing A Database Connection {F12010} ** -** This routine is the destructor for the [sqlite3] object. +** This routine is the destructor for the [sqlite3] object. ** -** Applications should [sqlite3_finalize | finalize] all [prepared statements] -** and [sqlite3_blob_close | close] all [BLOB handles] associated with -** the [sqlite3] object prior to attempting to close the object. -** The [sqlite3_next_stmt()] interface can be used to locate all -** [prepared statements] associated with a [database connection] if desired. -** Typical code might look like this: +** Applications should [sqlite3_finalize | finalize] all +** [prepared statements] and +** [sqlite3_blob_close | close] all [sqlite3_blob | BLOBs] +** associated with the [sqlite3] object prior +** to attempting to close the [sqlite3] object. ** -**
      -** sqlite3_stmt *pStmt;
      -** while( (pStmt = sqlite3_next_stmt(db, 0))!=0 ){
      -**     sqlite3_finalize(pStmt);
      -** }
      -** 
      -** -** If [sqlite3_close()] is invoked while a transaction is open, -** the transaction is automatically rolled back. +** What happens to pending transactions? Are they +** rolled back, or abandoned? ** ** INVARIANTS: ** -** {H12011} A successful call to [sqlite3_close(C)] shall destroy the -** [database connection] object C. +** {F12011} The [sqlite3_close()] interface destroys an [sqlite3] object +** allocated by a prior call to [sqlite3_open()], +** [sqlite3_open16()], or [sqlite3_open_v2()]. ** -** {H12012} A successful call to [sqlite3_close(C)] shall return SQLITE_OK. +** {F12012} The [sqlite3_close()] function releases all memory used by the +** connection and closes all open files. ** -** {H12013} A successful call to [sqlite3_close(C)] shall release all -** memory and system resources associated with [database connection] -** C. +** {F12013} If the database connection contains +** [prepared statements] that have not been +** finalized by [sqlite3_finalize()], then [sqlite3_close()] +** returns [SQLITE_BUSY] and leaves the connection open. ** -** {H12014} A call to [sqlite3_close(C)] on a [database connection] C that -** has one or more open [prepared statements] shall fail with -** an [SQLITE_BUSY] error code. +** {F12014} Giving sqlite3_close() a NULL pointer is a harmless no-op. ** -** {H12015} A call to [sqlite3_close(C)] where C is a NULL pointer shall -** be a harmless no-op returning SQLITE_OK. +** LIMITATIONS: ** -** {H12019} When [sqlite3_close(C)] is invoked on a [database connection] C -** that has a pending transaction, the transaction shall be -** rolled back. +** {U12015} The parameter to [sqlite3_close()] must be an [sqlite3] object +** pointer previously obtained from [sqlite3_open()] or the +** equivalent, or NULL. ** -** ASSUMPTIONS: -** -** {A12016} The C parameter to [sqlite3_close(C)] must be either a NULL -** pointer or an [sqlite3] object pointer obtained -** from [sqlite3_open()], [sqlite3_open16()], or -** [sqlite3_open_v2()], and not previously closed. +** {U12016} The parameter to [sqlite3_close()] must not have been previously +** closed. */ int sqlite3_close(sqlite3 *); @@ -297,129 +258,115 @@ int sqlite3_close(sqlite3 *); typedef int (*sqlite3_callback)(void*,int,char**, char**); /* -** CAPI3REF: One-Step Query Execution Interface {H12100} +** CAPI3REF: One-Step Query Execution Interface {F12100} ** -** The sqlite3_exec() interface is a convenient way of running one or more -** SQL statements without having to write a lot of C code. The UTF-8 encoded -** SQL statements are passed in as the second parameter to sqlite3_exec(). -** The statements are evaluated one by one until either an error or -** an interrupt is encountered, or until they are all done. The 3rd parameter -** is an optional callback that is invoked once for each row of any query -** results produced by the SQL statements. The 5th parameter tells where +** The sqlite3_exec() interface is a convenient way of running +** one or more SQL statements without a lot of C code. The +** SQL statements are passed in as the second parameter to +** sqlite3_exec(). The statements are evaluated one by one +** until either an error or an interrupt is encountered or +** until they are all done. The 3rd parameter is an optional +** callback that is invoked once for each row of any query results +** produced by the SQL statements. The 5th parameter tells where ** to write any error messages. ** -** The error message passed back through the 5th parameter is held -** in memory obtained from [sqlite3_malloc()]. To avoid a memory leak, -** the calling application should call [sqlite3_free()] on any error -** message returned through the 5th parameter when it has finished using -** the error message. -** -** If the SQL statement in the 2nd parameter is NULL or an empty string -** or a string containing only whitespace and comments, then no SQL -** statements are evaluated and the database is not changed. -** ** The sqlite3_exec() interface is implemented in terms of ** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()]. -** The sqlite3_exec() routine does nothing to the database that cannot be done +** The sqlite3_exec() routine does nothing that cannot be done ** by [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()]. +** The sqlite3_exec() is just a convenient wrapper. ** ** INVARIANTS: +** +** {F12101} The [sqlite3_exec()] interface evaluates zero or more UTF-8 +** encoded, semicolon-separated, SQL statements in the +** zero-terminated string of its 2nd parameter within the +** context of the [sqlite3] object given in the 1st parameter. ** -** {H12101} A successful invocation of [sqlite3_exec(D,S,C,A,E)] -** shall sequentially evaluate all of the UTF-8 encoded, -** semicolon-separated SQL statements in the zero-terminated -** string S within the context of the [database connection] D. +** {F12104} The return value of [sqlite3_exec()] is SQLITE_OK if all +** SQL statements run successfully. ** -** {H12102} If the S parameter to [sqlite3_exec(D,S,C,A,E)] is NULL then -** the actions of the interface shall be the same as if the -** S parameter were an empty string. +** {F12105} The return value of [sqlite3_exec()] is an appropriate +** non-zero error code if any SQL statement fails. ** -** {H12104} The return value of [sqlite3_exec()] shall be [SQLITE_OK] if all -** SQL statements run successfully and to completion. -** -** {H12105} The return value of [sqlite3_exec()] shall be an appropriate -** non-zero [error code] if any SQL statement fails. -** -** {H12107} If one or more of the SQL statements handed to [sqlite3_exec()] +** {F12107} If one or more of the SQL statements handed to [sqlite3_exec()] ** return results and the 3rd parameter is not NULL, then -** the callback function specified by the 3rd parameter shall be +** the callback function specified by the 3rd parameter is ** invoked once for each row of result. ** -** {H12110} If the callback returns a non-zero value then [sqlite3_exec()] -** shall abort the SQL statement it is currently evaluating, +** {F12110} If the callback returns a non-zero value then [sqlite3_exec()] +** will aborted the SQL statement it is currently evaluating, ** skip all subsequent SQL statements, and return [SQLITE_ABORT]. +** What happens to *errmsg here? Does the result code for +** sqlite3_errcode() get set? ** -** {H12113} The [sqlite3_exec()] routine shall pass its 4th parameter through +** {F12113} The [sqlite3_exec()] routine will pass its 4th parameter through ** as the 1st parameter of the callback. ** -** {H12116} The [sqlite3_exec()] routine shall set the 2nd parameter of its +** {F12116} The [sqlite3_exec()] routine sets the 2nd parameter of its ** callback to be the number of columns in the current row of ** result. ** -** {H12119} The [sqlite3_exec()] routine shall set the 3rd parameter of its +** {F12119} The [sqlite3_exec()] routine sets the 3rd parameter of its ** callback to be an array of pointers to strings holding the ** values for each column in the current result set row as ** obtained from [sqlite3_column_text()]. ** -** {H12122} The [sqlite3_exec()] routine shall set the 4th parameter of its +** {F12122} The [sqlite3_exec()] routine sets the 4th parameter of its ** callback to be an array of pointers to strings holding the ** names of result columns as obtained from [sqlite3_column_name()]. ** -** {H12125} If the 3rd parameter to [sqlite3_exec()] is NULL then -** [sqlite3_exec()] shall silently discard query results. +** {F12125} If the 3rd parameter to [sqlite3_exec()] is NULL then +** [sqlite3_exec()] never invokes a callback. All query +** results are silently discarded. ** -** {H12131} If an error occurs while parsing or evaluating any of the SQL -** statements in the S parameter of [sqlite3_exec(D,S,C,A,E)] and if -** the E parameter is not NULL, then [sqlite3_exec()] shall store -** in *E an appropriate error message written into memory obtained -** from [sqlite3_malloc()]. +** {F12128} If an error occurs while parsing or evaluating any of the SQL +** statements handed to [sqlite3_exec()] then [sqlite3_exec()] will +** return an [error code] other than [SQLITE_OK]. ** -** {H12134} The [sqlite3_exec(D,S,C,A,E)] routine shall set the value of -** *E to NULL if E is not NULL and there are no errors. +** {F12131} If an error occurs while parsing or evaluating any of the SQL +** handed to [sqlite3_exec()] and if the 5th parameter (errmsg) +** to [sqlite3_exec()] is not NULL, then an error message is +** allocated using the equivalent of [sqlite3_mprintf()] and +** *errmsg is made to point to that message. ** -** {H12137} The [sqlite3_exec(D,S,C,A,E)] function shall set the [error code] -** and message accessible via [sqlite3_errcode()], -** [sqlite3_errmsg()], and [sqlite3_errmsg16()]. +** {F12134} The [sqlite3_exec()] routine does not change the value of +** *errmsg if errmsg is NULL or if there are no errors. ** -** {H12138} If the S parameter to [sqlite3_exec(D,S,C,A,E)] is NULL or an -** empty string or contains nothing other than whitespace, comments, -** and/or semicolons, then results of [sqlite3_errcode()], -** [sqlite3_errmsg()], and [sqlite3_errmsg16()] -** shall reset to indicate no errors. +** {F12137} The [sqlite3_exec()] function sets the error code and message +** accessible via [sqlite3_errcode()], [sqlite3_errmsg()], and +** [sqlite3_errmsg16()]. ** -** ASSUMPTIONS: +** LIMITATIONS: ** -** {A12141} The first parameter to [sqlite3_exec()] must be an valid and open +** {U12141} The first parameter to [sqlite3_exec()] must be an valid and open ** [database connection]. ** -** {A12142} The database connection must not be closed while +** {U12142} The database connection must not be closed while ** [sqlite3_exec()] is running. -** -** {A12143} The calling function should use [sqlite3_free()] to free +** +** {U12143} The calling function is should use [sqlite3_free()] to free ** the memory that *errmsg is left pointing at once the error ** message is no longer needed. ** -** {A12145} The SQL statement text in the 2nd parameter to [sqlite3_exec()] +** {U12145} The SQL statement text in the 2nd parameter to [sqlite3_exec()] ** must remain unchanged while [sqlite3_exec()] is running. */ int sqlite3_exec( sqlite3*, /* An open database */ - const char *sql, /* SQL to be evaluated */ + const char *sql, /* SQL to be evaluted */ int (*callback)(void*,int,char**,char**), /* Callback function */ void *, /* 1st argument to callback */ char **errmsg /* Error msg written here */ ); /* -** CAPI3REF: Result Codes {H10210} +** CAPI3REF: Result Codes {F10210} ** KEYWORDS: SQLITE_OK {error code} {error codes} -** KEYWORDS: {result code} {result codes} ** ** Many SQLite functions return an integer result code from the set shown ** here in order to indicates success or failure. ** -** New error codes may be added in future versions of SQLite. -** ** See also: [SQLITE_IOERR_READ | extended result codes] */ #define SQLITE_OK 0 /* Successful result */ @@ -455,20 +402,20 @@ int sqlite3_exec( /* end-of-error-codes */ /* -** CAPI3REF: Extended Result Codes {H10220} +** CAPI3REF: Extended Result Codes {F10220} ** KEYWORDS: {extended error code} {extended error codes} -** KEYWORDS: {extended result code} {extended result codes} +** KEYWORDS: {extended result codes} ** ** In its default configuration, SQLite API routines return one of 26 integer -** [SQLITE_OK | result codes]. However, experience has shown that many of -** these result codes are too coarse-grained. They do not provide as +** [SQLITE_OK | result codes]. However, experience has shown that +** many of these result codes are too course-grained. They do not provide as ** much information about problems as programmers might like. In an effort to ** address this, newer versions of SQLite (version 3.3.8 and later) include ** support for additional result codes that provide more detailed information ** about errors. The extended result codes are enabled or disabled -** on a per database connection basis using the -** [sqlite3_extended_result_codes()] API. -** +** for each database connection using the [sqlite3_extended_result_codes()] +** API. +** ** Some of the available extended result codes are listed here. ** One may expect the number of extended result codes will be expand ** over time. Software that uses extended result codes should expect @@ -476,38 +423,35 @@ int sqlite3_exec( ** ** The SQLITE_OK result code will never be extended. It will always ** be exactly zero. -** +** ** INVARIANTS: ** -** {H10223} The symbolic name for an extended result code shall contains +** {F10223} The symbolic name for an extended result code always contains ** a related primary result code as a prefix. ** -** {H10224} Primary result code names shall contain a single "_" character. +** {F10224} Primary result code names contain a single "_" character. ** -** {H10225} Extended result code names shall contain two or more "_" characters. +** {F10225} Extended result code names contain two or more "_" characters. ** -** {H10226} The numeric value of an extended result code shall contain the +** {F10226} The numeric value of an extended result code contains the ** numeric value of its corresponding primary result code in ** its least significant 8 bits. */ -#define SQLITE_IOERR_READ (SQLITE_IOERR | (1<<8)) -#define SQLITE_IOERR_SHORT_READ (SQLITE_IOERR | (2<<8)) -#define SQLITE_IOERR_WRITE (SQLITE_IOERR | (3<<8)) -#define SQLITE_IOERR_FSYNC (SQLITE_IOERR | (4<<8)) -#define SQLITE_IOERR_DIR_FSYNC (SQLITE_IOERR | (5<<8)) -#define SQLITE_IOERR_TRUNCATE (SQLITE_IOERR | (6<<8)) -#define SQLITE_IOERR_FSTAT (SQLITE_IOERR | (7<<8)) -#define SQLITE_IOERR_UNLOCK (SQLITE_IOERR | (8<<8)) -#define SQLITE_IOERR_RDLOCK (SQLITE_IOERR | (9<<8)) -#define SQLITE_IOERR_DELETE (SQLITE_IOERR | (10<<8)) -#define SQLITE_IOERR_BLOCKED (SQLITE_IOERR | (11<<8)) -#define SQLITE_IOERR_NOMEM (SQLITE_IOERR | (12<<8)) -#define SQLITE_IOERR_ACCESS (SQLITE_IOERR | (13<<8)) -#define SQLITE_IOERR_CHECKRESERVEDLOCK (SQLITE_IOERR | (14<<8)) -#define SQLITE_IOERR_LOCK (SQLITE_IOERR | (15<<8)) +#define SQLITE_IOERR_READ (SQLITE_IOERR | (1<<8)) +#define SQLITE_IOERR_SHORT_READ (SQLITE_IOERR | (2<<8)) +#define SQLITE_IOERR_WRITE (SQLITE_IOERR | (3<<8)) +#define SQLITE_IOERR_FSYNC (SQLITE_IOERR | (4<<8)) +#define SQLITE_IOERR_DIR_FSYNC (SQLITE_IOERR | (5<<8)) +#define SQLITE_IOERR_TRUNCATE (SQLITE_IOERR | (6<<8)) +#define SQLITE_IOERR_FSTAT (SQLITE_IOERR | (7<<8)) +#define SQLITE_IOERR_UNLOCK (SQLITE_IOERR | (8<<8)) +#define SQLITE_IOERR_RDLOCK (SQLITE_IOERR | (9<<8)) +#define SQLITE_IOERR_DELETE (SQLITE_IOERR | (10<<8)) +#define SQLITE_IOERR_BLOCKED (SQLITE_IOERR | (11<<8)) +#define SQLITE_IOERR_NOMEM (SQLITE_IOERR | (12<<8)) /* -** CAPI3REF: Flags For File Open Operations {H10230} +** CAPI3REF: Flags For File Open Operations {F10230} ** ** These bit values are intended for use in the ** 3rd parameter to the [sqlite3_open_v2()] interface and @@ -526,11 +470,9 @@ int sqlite3_exec( #define SQLITE_OPEN_TEMP_JOURNAL 0x00001000 #define SQLITE_OPEN_SUBJOURNAL 0x00002000 #define SQLITE_OPEN_MASTER_JOURNAL 0x00004000 -#define SQLITE_OPEN_NOMUTEX 0x00008000 -#define SQLITE_OPEN_FULLMUTEX 0x00010000 /* -** CAPI3REF: Device Characteristics {H10240} +** CAPI3REF: Device Characteristics {F10240} ** ** The xDeviceCapabilities method of the [sqlite3_io_methods] ** object returns an integer which is a vector of the these @@ -562,7 +504,7 @@ int sqlite3_exec( #define SQLITE_IOCAP_SEQUENTIAL 0x00000400 /* -** CAPI3REF: File Locking Levels {H10250} +** CAPI3REF: File Locking Levels {F10250} ** ** SQLite uses one of these integer values as the second ** argument to calls it makes to the xLock() and xUnlock() methods @@ -575,7 +517,7 @@ int sqlite3_exec( #define SQLITE_LOCK_EXCLUSIVE 4 /* -** CAPI3REF: Synchronization Type Flags {H10260} +** CAPI3REF: Synchronization Type Flags {F10260} ** ** When SQLite invokes the xSync() method of an ** [sqlite3_io_methods] object it uses a combination of @@ -583,16 +525,17 @@ int sqlite3_exec( ** ** When the SQLITE_SYNC_DATAONLY flag is used, it means that the ** sync operation only needs to flush data to mass storage. Inode -** information need not be flushed. The SQLITE_SYNC_NORMAL flag means -** to use normal fsync() semantics. The SQLITE_SYNC_FULL flag means +** information need not be flushed. The SQLITE_SYNC_NORMAL flag means +** to use normal fsync() semantics. The SQLITE_SYNC_FULL flag means ** to use Mac OS-X style fullsync instead of fsync(). */ #define SQLITE_SYNC_NORMAL 0x00002 #define SQLITE_SYNC_FULL 0x00003 #define SQLITE_SYNC_DATAONLY 0x00010 + /* -** CAPI3REF: OS Interface Open File Handle {H11110} +** CAPI3REF: OS Interface Open File Handle {F11110} ** ** An [sqlite3_file] object represents an open file in the OS ** interface layer. Individual OS interface implementations will @@ -607,20 +550,19 @@ struct sqlite3_file { }; /* -** CAPI3REF: OS Interface File Virtual Methods Object {H11120} +** CAPI3REF: OS Interface File Virtual Methods Object {F11120} ** -** Every file opened by the [sqlite3_vfs] xOpen method populates an -** [sqlite3_file] object (or, more commonly, a subclass of the -** [sqlite3_file] object) with a pointer to an instance of this object. -** This object defines the methods used to perform various operations -** against the open file represented by the [sqlite3_file] object. +** Every file opened by the [sqlite3_vfs] xOpen method contains a pointer to +** an instance of this object. This object defines the +** methods used to perform various operations against the open file. ** ** The flags argument to xSync may be one of [SQLITE_SYNC_NORMAL] or ** [SQLITE_SYNC_FULL]. The first choice is the normal fsync(). -** The second choice is a Mac OS-X style fullsync. The [SQLITE_SYNC_DATAONLY] -** flag may be ORed in to indicate that only the data of the file -** and not its inode needs to be synced. -** +* The second choice is an +** OS-X style fullsync. The SQLITE_SYNC_DATA flag may be ORed in to +** indicate that only the data of the file and not its inode needs to be +** synced. +** ** The integer values to xLock() and xUnlock() are one of **
        **
      • [SQLITE_LOCK_NONE], @@ -629,24 +571,26 @@ struct sqlite3_file { **
      • [SQLITE_LOCK_PENDING], or **
      • [SQLITE_LOCK_EXCLUSIVE]. **
      -** xLock() increases the lock. xUnlock() decreases the lock. -** The xCheckReservedLock() method checks whether any database connection, -** either in this process or in some other process, is holding a RESERVED, +** xLock() increases the lock. xUnlock() decreases the lock. +** The xCheckReservedLock() method looks +** to see if any database connection, either in this +** process or in some other process, is holding an RESERVED, ** PENDING, or EXCLUSIVE lock on the file. It returns true -** if such a lock exists and false otherwise. -** +** if such a lock exists and false if not. +** ** The xFileControl() method is a generic interface that allows custom ** VFS implementations to directly control an open file using the -** [sqlite3_file_control()] interface. The second "op" argument is an -** integer opcode. The third argument is a generic pointer intended to -** point to a structure that may contain arguments or space in which to +** [sqlite3_file_control()] interface. The second "op" argument +** is an integer opcode. The third +** argument is a generic pointer which is intended to be a pointer +** to a structure that may contain arguments or space in which to ** write return values. Potential uses for xFileControl() might be ** functions to enable blocking locks with timeouts, to change the ** locking strategy (for example to use dot-file locks), to inquire ** about the status of a lock, or to break stale locks. The SQLite -** core reserves all opcodes less than 100 for its own use. +** core reserves opcodes less than 100 for its own use. ** A [SQLITE_FCNTL_LOCKSTATE | list of opcodes] less than 100 is available. -** Applications that define a custom xFileControl method should use opcodes +** Applications that define a custom xFileControl method should use opcodes ** greater than 100 to avoid conflicts. ** ** The xSectorSize() method returns the sector size of the @@ -692,7 +636,7 @@ struct sqlite3_io_methods { int (*xFileSize)(sqlite3_file*, sqlite3_int64 *pSize); int (*xLock)(sqlite3_file*, int); int (*xUnlock)(sqlite3_file*, int); - int (*xCheckReservedLock)(sqlite3_file*, int *pResOut); + int (*xCheckReservedLock)(sqlite3_file*); int (*xFileControl)(sqlite3_file*, int op, void *pArg); int (*xSectorSize)(sqlite3_file*); int (*xDeviceCharacteristics)(sqlite3_file*); @@ -700,10 +644,10 @@ struct sqlite3_io_methods { }; /* -** CAPI3REF: Standard File Control Opcodes {H11310} +** CAPI3REF: Standard File Control Opcodes {F11310} ** ** These integer constants are opcodes for the xFileControl method -** of the [sqlite3_io_methods] object and for the [sqlite3_file_control()] +** of the [sqlite3_io_methods] object and to the [sqlite3_file_control()] ** interface. ** ** The [SQLITE_FCNTL_LOCKSTATE] opcode is used for debugging. This @@ -717,7 +661,7 @@ struct sqlite3_io_methods { #define SQLITE_FCNTL_LOCKSTATE 1 /* -** CAPI3REF: Mutex Handle {H17110} +** CAPI3REF: Mutex Handle {F17110} ** ** The mutex module within SQLite defines [sqlite3_mutex] to be an ** abstract type for a mutex object. The SQLite core never looks @@ -729,18 +673,15 @@ struct sqlite3_io_methods { typedef struct sqlite3_mutex sqlite3_mutex; /* -** CAPI3REF: OS Interface Object {H11140} +** CAPI3REF: OS Interface Object {F11140} ** -** An instance of the sqlite3_vfs object defines the interface between -** the SQLite core and the underlying operating system. The "vfs" +** An instance of this object defines the interface between the +** SQLite core and the underlying operating system. The "vfs" ** in the name of the object stands for "virtual file system". ** -** The value of the iVersion field is initially 1 but may be larger in -** future versions of SQLite. Additional fields may be appended to this -** object when the iVersion value is increased. Note that the structure -** of the sqlite3_vfs object changes in the transaction between -** SQLite version 3.5.9 and 3.6.0 and yet the iVersion field was not -** modified. +** The iVersion field is initially 1 but may be larger for future +** versions of SQLite. Additional fields may be appended to this +** object when the iVersion value is increased. ** ** The szOsFile field is the size of the subclassed [sqlite3_file] ** structure used by this VFS. mxPathname is the maximum length of @@ -750,10 +691,9 @@ typedef struct sqlite3_mutex sqlite3_mutex; ** the pNext pointer. The [sqlite3_vfs_register()] ** and [sqlite3_vfs_unregister()] interfaces manage this list ** in a thread-safe way. The [sqlite3_vfs_find()] interface -** searches the list. Neither the application code nor the VFS -** implementation should use the pNext pointer. +** searches the list. ** -** The pNext field is the only field in the sqlite3_vfs +** The pNext field is the only field in the sqlite3_vfs ** structure that SQLite will ever modify. SQLite will only access ** or modify this field while holding a particular static mutex. ** The application should never modify anything within the sqlite3_vfs @@ -762,28 +702,23 @@ typedef struct sqlite3_mutex sqlite3_mutex; ** The zName field holds the name of the VFS module. The name must ** be unique across all VFS modules. ** -** {H11141} SQLite will guarantee that the zFilename parameter to xOpen -** is either a NULL pointer or string obtained -** from xFullPathname(). SQLite further guarantees that -** the string will be valid and unchanged until xClose() is -** called. {END} Because of the previous sentense, -** the [sqlite3_file] can safely store a pointer to the +** {F11141} SQLite will guarantee that the zFilename string passed to +** xOpen() is a full pathname as generated by xFullPathname() and +** that the string will be valid and unchanged until xClose() is +** called. {END} So the [sqlite3_file] can store a pointer to the ** filename if it needs to remember the filename for some reason. -** If the zFilename parameter is xOpen is a NULL pointer then xOpen -** must invite its own temporary name for the file. Whenever the -** xFilename parameter is NULL it will also be the case that the -** flags parameter will include [SQLITE_OPEN_DELETEONCLOSE]. ** -** {H11142} The flags argument to xOpen() includes all bits set in +** {F11142} The flags argument to xOpen() includes all bits set in ** the flags argument to [sqlite3_open_v2()]. Or if [sqlite3_open()] ** or [sqlite3_open16()] is used, then flags includes at least ** [SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]. {END} ** If xOpen() opens a file read-only then it sets *pOutFlags to -** include [SQLITE_OPEN_READONLY]. Other bits in *pOutFlags may be set. -** -** {H11143} SQLite will also add one of the following flags to the xOpen() +** include [SQLITE_OPEN_READONLY]. Other bits in *pOutFlags may be +** set. +** +** {F11143} SQLite will also add one of the following flags to the xOpen() ** call, depending on the object being opened: -** +** **
        **
      • [SQLITE_OPEN_MAIN_DB] **
      • [SQLITE_OPEN_MAIN_JOURNAL] @@ -795,56 +730,59 @@ typedef struct sqlite3_mutex sqlite3_mutex; **
      {END} ** ** The file I/O implementation can use the object type flags to -** change the way it deals with files. For example, an application +** changes the way it deals with files. For example, an application ** that does not care about crash recovery or rollback might make ** the open of a journal file a no-op. Writes to this journal would -** also be no-ops, and any attempt to read the journal would return -** SQLITE_IOERR. Or the implementation might recognize that a database -** file will be doing page-aligned sector reads and writes in a random +** also be no-ops, and any attempt to read the journal would return +** SQLITE_IOERR. Or the implementation might recognize that a database +** file will be doing page-aligned sector reads and writes in a random ** order and set up its I/O subsystem accordingly. -** -** SQLite might also add one of the following flags to the xOpen method: -** +** +** SQLite might also add one of the following flags to the xOpen +** method: +** **
        **
      • [SQLITE_OPEN_DELETEONCLOSE] **
      • [SQLITE_OPEN_EXCLUSIVE] **
      -** -** {H11145} The [SQLITE_OPEN_DELETEONCLOSE] flag means the file should be -** deleted when it is closed. {H11146} The [SQLITE_OPEN_DELETEONCLOSE] -** will be set for TEMP databases, journals and for subjournals. -** -** {H11147} The [SQLITE_OPEN_EXCLUSIVE] flag means the file should be opened +** +** {F11145} The [SQLITE_OPEN_DELETEONCLOSE] flag means the file should be +** deleted when it is closed. {F11146} The [SQLITE_OPEN_DELETEONCLOSE] +** will be set for TEMP databases, journals and for subjournals. +** {F11147} The [SQLITE_OPEN_EXCLUSIVE] flag means the file should be opened ** for exclusive access. This flag is set for all files except -** for the main database file. -** -** {H11148} At least szOsFile bytes of memory are allocated by SQLite -** to hold the [sqlite3_file] structure passed as the third -** argument to xOpen. {END} The xOpen method does not have to +** for the main database file. {END} +** +** {F11148} At least szOsFile bytes of memory are allocated by SQLite +** to hold the [sqlite3_file] structure passed as the third +** argument to xOpen. {END} The xOpen method does not have to ** allocate the structure; it should just fill it in. -** -** {H11149} The flags argument to xAccess() may be [SQLITE_ACCESS_EXISTS] -** to test for the existence of a file, or [SQLITE_ACCESS_READWRITE] to -** test whether a file is readable and writable, or [SQLITE_ACCESS_READ] -** to test whether a file is at least readable. {END} The file can be a +** +** {F11149} The flags argument to xAccess() may be [SQLITE_ACCESS_EXISTS] +** to test for the existance of a file, +** or [SQLITE_ACCESS_READWRITE] to test to see +** if a file is readable and writable, or [SQLITE_ACCESS_READ] +** to test to see if a file is at least readable. {END} The file can be a ** directory. -** -** {H11150} SQLite will always allocate at least mxPathname+1 bytes for the -** output buffer xFullPathname. {H11151} The exact size of the output buffer -** is also passed as a parameter to both methods. {END} If the output buffer -** is not large enough, [SQLITE_CANTOPEN] should be returned. Since this is -** handled as a fatal error by SQLite, vfs implementations should endeavor -** to prevent this by setting mxPathname to a sufficiently large value. -** +** +** {F11150} SQLite will always allocate at least mxPathname+1 bytes for +** the output buffers for xGetTempname and xFullPathname. {F11151} The exact +** size of the output buffer is also passed as a parameter to both +** methods. {END} If the output buffer is not large enough, SQLITE_CANTOPEN +** should be returned. As this is handled as a fatal error by SQLite, +** vfs implementations should endeavor to prevent this by setting +** mxPathname to a sufficiently large value. +** ** The xRandomness(), xSleep(), and xCurrentTime() interfaces ** are not strictly a part of the filesystem, but they are ** included in the VFS structure for completeness. ** The xRandomness() function attempts to return nBytes bytes ** of good-quality randomness into zOut. The return value is -** the actual number of bytes of randomness obtained. -** The xSleep() method causes the calling thread to sleep for at +** the actual number of bytes of randomness obtained. The +** xSleep() method causes the calling thread to sleep for at ** least the number of microseconds given. The xCurrentTime() -** method returns a Julian Day Number for the current date and time. +** method returns a Julian Day Number for the current date and +** time. */ typedef struct sqlite3_vfs sqlite3_vfs; struct sqlite3_vfs { @@ -857,7 +795,8 @@ struct sqlite3_vfs { int (*xOpen)(sqlite3_vfs*, const char *zName, sqlite3_file*, int flags, int *pOutFlags); int (*xDelete)(sqlite3_vfs*, const char *zName, int syncDir); - int (*xAccess)(sqlite3_vfs*, const char *zName, int flags, int *pResOut); + int (*xAccess)(sqlite3_vfs*, const char *zName, int flags); + int (*xGetTempname)(sqlite3_vfs*, int nOut, char *zOut); int (*xFullPathname)(sqlite3_vfs*, const char *zName, int nOut, char *zOut); void *(*xDlOpen)(sqlite3_vfs*, const char *zFilename); void (*xDlError)(sqlite3_vfs*, int nByte, char *zErrMsg); @@ -866,518 +805,50 @@ struct sqlite3_vfs { int (*xRandomness)(sqlite3_vfs*, int nByte, char *zOut); int (*xSleep)(sqlite3_vfs*, int microseconds); int (*xCurrentTime)(sqlite3_vfs*, double*); - int (*xGetLastError)(sqlite3_vfs*, int, char *); /* New fields may be appended in figure versions. The iVersion ** value will increment whenever this happens. */ }; /* -** CAPI3REF: Flags for the xAccess VFS method {H11190} +** CAPI3REF: Flags for the xAccess VFS method {F11190} ** -** {H11191} These integer constants can be used as the third parameter to +** {F11191} These integer constants can be used as the third parameter to ** the xAccess method of an [sqlite3_vfs] object. {END} They determine -** what kind of permissions the xAccess method is looking for. -** {H11192} With SQLITE_ACCESS_EXISTS, the xAccess method -** simply checks whether the file exists. -** {H11193} With SQLITE_ACCESS_READWRITE, the xAccess method -** checks whether the file is both readable and writable. -** {H11194} With SQLITE_ACCESS_READ, the xAccess method -** checks whether the file is readable. +** what kind of permissions the xAccess method is +** looking for. {F11192} With SQLITE_ACCESS_EXISTS, the xAccess method +** simply checks to see if the file exists. {F11193} With +** SQLITE_ACCESS_READWRITE, the xAccess method checks to see +** if the file is both readable and writable. {F11194} With +** SQLITE_ACCESS_READ the xAccess method +** checks to see if the file is readable. */ #define SQLITE_ACCESS_EXISTS 0 #define SQLITE_ACCESS_READWRITE 1 #define SQLITE_ACCESS_READ 2 /* -** CAPI3REF: Initialize The SQLite Library {H10130} -** -** The sqlite3_initialize() routine initializes the -** SQLite library. The sqlite3_shutdown() routine -** deallocates any resources that were allocated by sqlite3_initialize(). -** -** A call to sqlite3_initialize() is an "effective" call if it is -** the first time sqlite3_initialize() is invoked during the lifetime of -** the process, or if it is the first time sqlite3_initialize() is invoked -** following a call to sqlite3_shutdown(). Only an effective call -** of sqlite3_initialize() does any initialization. All other calls -** are harmless no-ops. -** -** Among other things, sqlite3_initialize() shall invoke -** sqlite3_os_init(). Similarly, sqlite3_shutdown() -** shall invoke sqlite3_os_end(). -** -** The sqlite3_initialize() routine returns [SQLITE_OK] on success. -** If for some reason, sqlite3_initialize() is unable to initialize -** the library (perhaps it is unable to allocate a needed resource such -** as a mutex) it returns an [error code] other than [SQLITE_OK]. -** -** The sqlite3_initialize() routine is called internally by many other -** SQLite interfaces so that an application usually does not need to -** invoke sqlite3_initialize() directly. For example, [sqlite3_open()] -** calls sqlite3_initialize() so the SQLite library will be automatically -** initialized when [sqlite3_open()] is called if it has not be initialized -** already. However, if SQLite is compiled with the [SQLITE_OMIT_AUTOINIT] -** compile-time option, then the automatic calls to sqlite3_initialize() -** are omitted and the application must call sqlite3_initialize() directly -** prior to using any other SQLite interface. For maximum portability, -** it is recommended that applications always invoke sqlite3_initialize() -** directly prior to using any other SQLite interface. Future releases -** of SQLite may require this. In other words, the behavior exhibited -** when SQLite is compiled with [SQLITE_OMIT_AUTOINIT] might become the -** default behavior in some future release of SQLite. -** -** The sqlite3_os_init() routine does operating-system specific -** initialization of the SQLite library. The sqlite3_os_end() -** routine undoes the effect of sqlite3_os_init(). Typical tasks -** performed by these routines include allocation or deallocation -** of static resources, initialization of global variables, -** setting up a default [sqlite3_vfs] module, or setting up -** a default configuration using [sqlite3_config()]. -** -** The application should never invoke either sqlite3_os_init() -** or sqlite3_os_end() directly. The application should only invoke -** sqlite3_initialize() and sqlite3_shutdown(). The sqlite3_os_init() -** interface is called automatically by sqlite3_initialize() and -** sqlite3_os_end() is called by sqlite3_shutdown(). Appropriate -** implementations for sqlite3_os_init() and sqlite3_os_end() -** are built into SQLite when it is compiled for unix, windows, or os/2. -** When built for other platforms (using the [SQLITE_OS_OTHER=1] compile-time -** option) the application must supply a suitable implementation for -** sqlite3_os_init() and sqlite3_os_end(). An application-supplied -** implementation of sqlite3_os_init() or sqlite3_os_end() -** must return [SQLITE_OK] on success and some other [error code] upon -** failure. -*/ -int sqlite3_initialize(void); -int sqlite3_shutdown(void); -int sqlite3_os_init(void); -int sqlite3_os_end(void); - -/* -** CAPI3REF: Configuring The SQLite Library {H14100} -** EXPERIMENTAL -** -** The sqlite3_config() interface is used to make global configuration -** changes to SQLite in order to tune SQLite to the specific needs of -** the application. The default configuration is recommended for most -** applications and so this routine is usually not necessary. It is -** provided to support rare applications with unusual needs. -** -** The sqlite3_config() interface is not threadsafe. The application -** must insure that no other SQLite interfaces are invoked by other -** threads while sqlite3_config() is running. Furthermore, sqlite3_config() -** may only be invoked prior to library initialization using -** [sqlite3_initialize()] or after shutdown by [sqlite3_shutdown()]. -** Note, however, that sqlite3_config() can be called as part of the -** implementation of an application-defined [sqlite3_os_init()]. -** -** The first argument to sqlite3_config() is an integer -** [SQLITE_CONFIG_SINGLETHREAD | configuration option] that determines -** what property of SQLite is to be configured. Subsequent arguments -** vary depending on the [SQLITE_CONFIG_SINGLETHREAD | configuration option] -** in the first argument. -** -** When a configuration option is set, sqlite3_config() returns [SQLITE_OK]. -** If the option is unknown or SQLite is unable to set the option -** then this routine returns a non-zero [error code]. -** -** INVARIANTS: -** -** {H14103} A successful invocation of [sqlite3_config()] shall return -** [SQLITE_OK]. -** -** {H14106} The [sqlite3_config()] interface shall return [SQLITE_MISUSE] -** if it is invoked in between calls to [sqlite3_initialize()] and -** [sqlite3_shutdown()]. -** -** {H14120} A successful call to [sqlite3_config]([SQLITE_CONFIG_SINGLETHREAD]) -** shall set the default [threading mode] to Single-thread. -** -** {H14123} A successful call to [sqlite3_config]([SQLITE_CONFIG_MULTITHREAD]) -** shall set the default [threading mode] to Multi-thread. -** -** {H14126} A successful call to [sqlite3_config]([SQLITE_CONFIG_SERIALIZED]) -** shall set the default [threading mode] to Serialized. -** -** {H14129} A successful call to [sqlite3_config]([SQLITE_CONFIG_MUTEX],X) -** where X is a pointer to an initialized [sqlite3_mutex_methods] -** object shall cause all subsequent mutex operations performed -** by SQLite to use the mutex methods that were present in X -** during the call to [sqlite3_config()]. -** -** {H14132} A successful call to [sqlite3_config]([SQLITE_CONFIG_GETMUTEX],X) -** where X is a pointer to an [sqlite3_mutex_methods] object -** shall overwrite the content of [sqlite3_mutex_methods] object -** with the mutex methods currently in use by SQLite. -** -** {H14135} A successful call to [sqlite3_config]([SQLITE_CONFIG_MALLOC],M) -** where M is a pointer to an initialized [sqlite3_mem_methods] -** object shall cause all subsequent memory allocation operations -** performed by SQLite to use the methods that were present in -** M during the call to [sqlite3_config()]. -** -** {H14138} A successful call to [sqlite3_config]([SQLITE_CONFIG_GETMALLOC],M) -** where M is a pointer to an [sqlite3_mem_methods] object shall -** overwrite the content of [sqlite3_mem_methods] object with -** the memory allocation methods currently in use by -** SQLite. -** -** {H14141} A successful call to [sqlite3_config]([SQLITE_CONFIG_MEMSTATUS],1) -** shall enable the memory allocation status collection logic. -** -** {H14144} A successful call to [sqlite3_config]([SQLITE_CONFIG_MEMSTATUS],0) -** shall disable the memory allocation status collection logic. -** -** {H14147} The memory allocation status collection logic shall be -** enabled by default. -** -** {H14150} A successful call to [sqlite3_config]([SQLITE_CONFIG_SCRATCH],S,Z,N) -** where Z and N are non-negative integers and -** S is a pointer to an aligned memory buffer not less than -** Z*N bytes in size shall cause S to be used by the -** [scratch memory allocator] for as many as N simulataneous -** allocations each of size Z. -** -** {H14153} A successful call to [sqlite3_config]([SQLITE_CONFIG_SCRATCH],S,Z,N) -** where S is a NULL pointer shall disable the -** [scratch memory allocator]. -** -** {H14156} A successful call to -** [sqlite3_config]([SQLITE_CONFIG_PAGECACHE],S,Z,N) -** where Z and N are non-negative integers and -** S is a pointer to an aligned memory buffer not less than -** Z*N bytes in size shall cause S to be used by the -** [pagecache memory allocator] for as many as N simulataneous -** allocations each of size Z. -** -** {H14159} A successful call to -** [sqlite3_config]([SQLITE_CONFIG_PAGECACHE],S,Z,N) -** where S is a NULL pointer shall disable the -** [pagecache memory allocator]. -** -** {H14162} A successful call to [sqlite3_config]([SQLITE_CONFIG_HEAP],H,Z,N) -** where Z and N are non-negative integers and -** H is a pointer to an aligned memory buffer not less than -** Z bytes in size shall enable the [memsys5] memory allocator -** and cause it to use buffer S as its memory source and to use -** a minimum allocation size of N. -** -** {H14165} A successful call to [sqlite3_config]([SQLITE_CONFIG_HEAP],H,Z,N) -** where H is a NULL pointer shall disable the -** [memsys5] memory allocator. -** -** {H14168} A successful call to [sqlite3_config]([SQLITE_CONFIG_LOOKASIDE],Z,N) -** shall cause the default [lookaside memory allocator] configuration -** for new [database connections] to be N slots of Z bytes each. -*/ -SQLITE_EXPERIMENTAL int sqlite3_config(int, ...); - -/* -** CAPI3REF: Configure database connections {H14200} -** EXPERIMENTAL -** -** The sqlite3_db_config() interface is used to make configuration -** changes to a [database connection]. The interface is similar to -** [sqlite3_config()] except that the changes apply to a single -** [database connection] (specified in the first argument). The -** sqlite3_db_config() interface can only be used immediately after -** the database connection is created using [sqlite3_open()], -** [sqlite3_open16()], or [sqlite3_open_v2()]. -** -** The second argument to sqlite3_db_config(D,V,...) is the -** configuration verb - an integer code that indicates what -** aspect of the [database connection] is being configured. -** The only choice for this value is [SQLITE_DBCONFIG_LOOKASIDE]. -** New verbs are likely to be added in future releases of SQLite. -** Additional arguments depend on the verb. -** -** INVARIANTS: -** -** {H14203} A call to [sqlite3_db_config(D,V,...)] shall return [SQLITE_OK] -** if and only if the call is successful. -** -** {H14206} If one or more slots of the [lookaside memory allocator] for -** [database connection] D are in use, then a call to -** [sqlite3_db_config](D,[SQLITE_DBCONFIG_LOOKASIDE],...) shall -** fail with an [SQLITE_BUSY] return code. -** -** {H14209} A successful call to -** [sqlite3_db_config](D,[SQLITE_DBCONFIG_LOOKASIDE],B,Z,N) where -** D is an open [database connection] and Z and N are positive -** integers and B is an aligned buffer at least Z*N bytes in size -** shall cause the [lookaside memory allocator] for D to use buffer B -** with N slots of Z bytes each. -** -** {H14212} A successful call to -** [sqlite3_db_config](D,[SQLITE_DBCONFIG_LOOKASIDE],B,Z,N) where -** D is an open [database connection] and Z and N are positive -** integers and B is NULL pointer shall cause the -** [lookaside memory allocator] for D to a obtain Z*N byte buffer -** from the primary memory allocator and use that buffer -** with N lookaside slots of Z bytes each. -** -** {H14215} A successful call to -** [sqlite3_db_config](D,[SQLITE_DBCONFIG_LOOKASIDE],B,Z,N) where -** D is an open [database connection] and Z and N are zero shall -** disable the [lookaside memory allocator] for D. -** -** -*/ -SQLITE_EXPERIMENTAL int sqlite3_db_config(sqlite3*, int op, ...); - -/* -** CAPI3REF: Memory Allocation Routines {H10155} -** EXPERIMENTAL -** -** An instance of this object defines the interface between SQLite -** and low-level memory allocation routines. -** -** This object is used in only one place in the SQLite interface. -** A pointer to an instance of this object is the argument to -** [sqlite3_config()] when the configuration option is -** [SQLITE_CONFIG_MALLOC]. By creating an instance of this object -** and passing it to [sqlite3_config()] during configuration, an -** application can specify an alternative memory allocation subsystem -** for SQLite to use for all of its dynamic memory needs. -** -** Note that SQLite comes with a built-in memory allocator that is -** perfectly adequate for the overwhelming majority of applications -** and that this object is only useful to a tiny minority of applications -** with specialized memory allocation requirements. This object is -** also used during testing of SQLite in order to specify an alternative -** memory allocator that simulates memory out-of-memory conditions in -** order to verify that SQLite recovers gracefully from such -** conditions. -** -** The xMalloc, xFree, and xRealloc methods must work like the -** malloc(), free(), and realloc() functions from the standard library. -** -** xSize should return the allocated size of a memory allocation -** previously obtained from xMalloc or xRealloc. The allocated size -** is always at least as big as the requested size but may be larger. -** -** The xRoundup method returns what would be the allocated size of -** a memory allocation given a particular requested size. Most memory -** allocators round up memory allocations at least to the next multiple -** of 8. Some allocators round up to a larger multiple or to a power of 2. -** -** The xInit method initializes the memory allocator. (For example, -** it might allocate any require mutexes or initialize internal data -** structures. The xShutdown method is invoked (indirectly) by -** [sqlite3_shutdown()] and should deallocate any resources acquired -** by xInit. The pAppData pointer is used as the only parameter to -** xInit and xShutdown. -*/ -typedef struct sqlite3_mem_methods sqlite3_mem_methods; -struct sqlite3_mem_methods { - void *(*xMalloc)(int); /* Memory allocation function */ - void (*xFree)(void*); /* Free a prior allocation */ - void *(*xRealloc)(void*,int); /* Resize an allocation */ - int (*xSize)(void*); /* Return the size of an allocation */ - int (*xRoundup)(int); /* Round up request size to allocation size */ - int (*xInit)(void*); /* Initialize the memory allocator */ - void (*xShutdown)(void*); /* Deinitialize the memory allocator */ - void *pAppData; /* Argument to xInit() and xShutdown() */ -}; - -/* -** CAPI3REF: Configuration Options {H10160} -** EXPERIMENTAL -** -** These constants are the available integer configuration options that -** can be passed as the first argument to the [sqlite3_config()] interface. -** -** New configuration options may be added in future releases of SQLite. -** Existing configuration options might be discontinued. Applications -** should check the return code from [sqlite3_config()] to make sure that -** the call worked. The [sqlite3_config()] interface will return a -** non-zero [error code] if a discontinued or unsupported configuration option -** is invoked. -** -**
      -**
      SQLITE_CONFIG_SINGLETHREAD
      -**
      There are no arguments to this option. This option disables -** all mutexing and puts SQLite into a mode where it can only be used -** by a single thread.
      -** -**
      SQLITE_CONFIG_MULTITHREAD
      -**
      There are no arguments to this option. This option disables -** mutexing on [database connection] and [prepared statement] objects. -** The application is responsible for serializing access to -** [database connections] and [prepared statements]. But other mutexes -** are enabled so that SQLite will be safe to use in a multi-threaded -** environment as long as no two threads attempt to use the same -** [database connection] at the same time. See the [threading mode] -** documentation for additional information.
      -** -**
      SQLITE_CONFIG_SERIALIZED
      -**
      There are no arguments to this option. This option enables -** all mutexes including the recursive -** mutexes on [database connection] and [prepared statement] objects. -** In this mode (which is the default when SQLite is compiled with -** [SQLITE_THREADSAFE=1]) the SQLite library will itself serialize access -** to [database connections] and [prepared statements] so that the -** application is free to use the same [database connection] or the -** same [prepared statement] in different threads at the same time. -** See the [threading mode] documentation for additional information.
      -** -**
      SQLITE_CONFIG_MALLOC
      -**
      This option takes a single argument which is a pointer to an -** instance of the [sqlite3_mem_methods] structure. The argument specifies -** alternative low-level memory allocation routines to be used in place of -** the memory allocation routines built into SQLite.
      -** -**
      SQLITE_CONFIG_GETMALLOC
      -**
      This option takes a single argument which is a pointer to an -** instance of the [sqlite3_mem_methods] structure. The [sqlite3_mem_methods] -** structure is filled with the currently defined memory allocation routines. -** This option can be used to overload the default memory allocation -** routines with a wrapper that simulations memory allocation failure or -** tracks memory usage, for example.
      -** -**
      SQLITE_CONFIG_MEMSTATUS
      -**
      This option takes single argument of type int, interpreted as a -** boolean, which enables or disables the collection of memory allocation -** statistics. When disabled, the following SQLite interfaces become -** non-operational: -**
        -**
      • [sqlite3_memory_used()] -**
      • [sqlite3_memory_highwater()] -**
      • [sqlite3_soft_heap_limit()] -**
      • [sqlite3_status()] -**
      -**
      -** -**
      SQLITE_CONFIG_SCRATCH
      -**
      This option specifies a static memory buffer that SQLite can use for -** scratch memory. There are three arguments: A pointer to the memory, the -** size of each scratch buffer (sz), and the number of buffers (N). The sz -** argument must be a multiple of 16. The sz parameter should be a few bytes -** larger than the actual scratch space required due internal overhead. -** The first -** argument should point to an allocation of at least sz*N bytes of memory. -** SQLite will use no more than one scratch buffer at once per thread, so -** N should be set to the expected maximum number of threads. The sz -** parameter should be 6 times the size of the largest database page size. -** Scratch buffers are used as part of the btree balance operation. If -** The btree balancer needs additional memory beyond what is provided by -** scratch buffers or if no scratch buffer space is specified, then SQLite -** goes to [sqlite3_malloc()] to obtain the memory it needs.
      -** -**
      SQLITE_CONFIG_PAGECACHE
      -**
      This option specifies a static memory buffer that SQLite can use for -** the database page cache. There are three arguments: A pointer to the -** memory, the size of each page buffer (sz), and the number of pages (N). -** The sz argument must be a power of two between 512 and 32768. The first -** argument should point to an allocation of at least sz*N bytes of memory. -** SQLite will use the memory provided by the first argument to satisfy its -** memory needs for the first N pages that it adds to cache. If additional -** page cache memory is needed beyond what is provided by this option, then -** SQLite goes to [sqlite3_malloc()] for the additional storage space. -** The implementation might use one or more of the N buffers to hold -** memory accounting information.
      -** -**
      SQLITE_CONFIG_HEAP
      -**
      This option specifies a static memory buffer that SQLite will use -** for all of its dynamic memory allocation needs beyond those provided -** for by [SQLITE_CONFIG_SCRATCH] and [SQLITE_CONFIG_PAGECACHE]. -** There are three arguments: A pointer to the memory, the number of -** bytes in the memory buffer, and the minimum allocation size. If -** the first pointer (the memory pointer) is NULL, then SQLite reverts -** to using its default memory allocator (the system malloc() implementation), -** undoing any prior invocation of [SQLITE_CONFIG_MALLOC]. If the -** memory pointer is not NULL and either [SQLITE_ENABLE_MEMSYS3] or -** [SQLITE_ENABLE_MEMSYS5] are defined, then the alternative memory -** allocator is engaged to handle all of SQLites memory allocation needs.
      -** -**
      SQLITE_CONFIG_MUTEX
      -**
      This option takes a single argument which is a pointer to an -** instance of the [sqlite3_mutex_methods] structure. The argument specifies -** alternative low-level mutex routines to be used in place -** the mutex routines built into SQLite.
      -** -**
      SQLITE_CONFIG_GETMUTEX
      -**
      This option takes a single argument which is a pointer to an -** instance of the [sqlite3_mutex_methods] structure. The -** [sqlite3_mutex_methods] -** structure is filled with the currently defined mutex routines. -** This option can be used to overload the default mutex allocation -** routines with a wrapper used to track mutex usage for performance -** profiling or testing, for example.
      -** -**
      SQLITE_CONFIG_LOOKASIDE
      -**
      This option takes two arguments that determine the default -** memory allcation lookaside optimization. The first argument is the -** size of each lookaside buffer slot and the second is the number of -** slots allocated to each database connection.
      -** -**
      -*/ -#define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */ -#define SQLITE_CONFIG_MULTITHREAD 2 /* nil */ -#define SQLITE_CONFIG_SERIALIZED 3 /* nil */ -#define SQLITE_CONFIG_MALLOC 4 /* sqlite3_mem_methods* */ -#define SQLITE_CONFIG_GETMALLOC 5 /* sqlite3_mem_methods* */ -#define SQLITE_CONFIG_SCRATCH 6 /* void*, int sz, int N */ -#define SQLITE_CONFIG_PAGECACHE 7 /* void*, int sz, int N */ -#define SQLITE_CONFIG_HEAP 8 /* void*, int nByte, int min */ -#define SQLITE_CONFIG_MEMSTATUS 9 /* boolean */ -#define SQLITE_CONFIG_MUTEX 10 /* sqlite3_mutex_methods* */ -#define SQLITE_CONFIG_GETMUTEX 11 /* sqlite3_mutex_methods* */ -#define SQLITE_CONFIG_CHUNKALLOC 12 /* int threshold */ -#define SQLITE_CONFIG_LOOKASIDE 13 /* int int */ - -/* -** CAPI3REF: Configuration Options {H10170} -** EXPERIMENTAL -** -** These constants are the available integer configuration options that -** can be passed as the second argument to the [sqlite3_db_config()] interface. -** -** New configuration options may be added in future releases of SQLite. -** Existing configuration options might be discontinued. Applications -** should check the return code from [sqlite3_db_config()] to make sure that -** the call worked. The [sqlite3_db_config()] interface will return a -** non-zero [error code] if a discontinued or unsupported configuration option -** is invoked. -** -**
      -**
      SQLITE_DBCONFIG_LOOKASIDE
      -**
      This option takes three additional arguments that determine the -** [lookaside memory allocator] configuration for the [database connection]. -** The first argument (the third parameter to [sqlite3_db_config()] is a -** pointer to a memory buffer to use for lookaside memory. The first -** argument may be NULL in which case SQLite will allocate the lookaside -** buffer itself using [sqlite3_malloc()]. The second argument is the -** size of each lookaside buffer slot and the third argument is the number of -** slots. The size of the buffer in the first argument must be greater than -** or equal to the product of the second and third arguments.
      -** -**
      -*/ -#define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */ - - -/* -** CAPI3REF: Enable Or Disable Extended Result Codes {H12200} +** CAPI3REF: Enable Or Disable Extended Result Codes {F12200} ** ** The sqlite3_extended_result_codes() routine enables or disables the -** [extended result codes] feature of SQLite. The extended result -** codes are disabled by default for historical compatibility considerations. +** [SQLITE_IOERR_READ | extended result codes] feature of SQLite. +** The extended result codes are disabled by default for historical +** compatibility. ** ** INVARIANTS: ** -** {H12201} Each new [database connection] shall have the -** [extended result codes] feature disabled by default. +** {F12201} Each new [database connection] has the +** [extended result codes] feature +** disabled by default. ** -** {H12202} The [sqlite3_extended_result_codes(D,F)] interface shall enable -** [extended result codes] for the [database connection] D -** if the F parameter is true, or disable them if F is false. +** {F12202} The [sqlite3_extended_result_codes(D,F)] interface will enable +** [extended result codes] for the +** [database connection] D if the F parameter +** is true, or disable them if F is false. */ int sqlite3_extended_result_codes(sqlite3*, int onoff); /* -** CAPI3REF: Last Insert Rowid {H12220} +** CAPI3REF: Last Insert Rowid {F12220} ** ** Each entry in an SQLite table has a unique 64-bit signed ** integer key called the "rowid". The rowid is always available @@ -1387,43 +858,44 @@ int sqlite3_extended_result_codes(sqlite3*, int onoff); ** is another alias for the rowid. ** ** This routine returns the rowid of the most recent -** successful [INSERT] into the database from the [database connection] -** in the first argument. If no successful [INSERT]s -** have ever occurred on that database connection, zero is returned. +** successful INSERT into the database from the database connection +** shown in the first argument. If no successful inserts +** have ever occurred on this database connection, zero is returned. ** -** If an [INSERT] occurs within a trigger, then the rowid of the inserted -** row is returned by this routine as long as the trigger is running. -** But once the trigger terminates, the value returned by this routine -** reverts to the last value inserted before the trigger fired. +** If an INSERT occurs within a trigger, then the rowid of the +** inserted row is returned by this routine as long as the trigger +** is running. But once the trigger terminates, the value returned +** by this routine reverts to the last value inserted before the +** trigger fired. ** -** An [INSERT] that fails due to a constraint violation is not a -** successful [INSERT] and does not change the value returned by this +** An INSERT that fails due to a constraint violation is not a +** successful insert and does not change the value returned by this ** routine. Thus INSERT OR FAIL, INSERT OR IGNORE, INSERT OR ROLLBACK, ** and INSERT OR ABORT make no changes to the return value of this -** routine when their insertion fails. When INSERT OR REPLACE +** routine when their insertion fails. When INSERT OR REPLACE ** encounters a constraint violation, it does not fail. The ** INSERT continues to completion after deleting rows that caused ** the constraint problem so INSERT OR REPLACE will always change -** the return value of this interface. +** the return value of this interface. ** -** For the purposes of this routine, an [INSERT] is considered to +** For the purposes of this routine, an insert is considered to ** be successful even if it is subsequently rolled back. ** ** INVARIANTS: ** -** {H12221} The [sqlite3_last_insert_rowid()] function shall return the rowid -** of the most recent successful [INSERT] performed on the same -** [database connection] and within the same or higher level -** trigger context, or zero if there have been no qualifying -** [INSERT] statements. +** {F12221} The [sqlite3_last_insert_rowid()] function returns the +** rowid of the most recent successful insert done +** on the same database connection and within the same +** trigger context, or zero if there have +** been no qualifying inserts on that connection. ** -** {H12223} The [sqlite3_last_insert_rowid()] function shall return the +** {F12223} The [sqlite3_last_insert_rowid()] function returns ** same value when called from the same trigger context -** immediately before and after a [ROLLBACK]. +** immediately before and after a ROLLBACK. ** -** ASSUMPTIONS: +** LIMITATIONS: ** -** {A12232} If a separate thread performs a new [INSERT] on the same +** {U12232} If a separate thread does a new insert on the same ** database connection while the [sqlite3_last_insert_rowid()] ** function is running and thus changes the last insert rowid, ** then the value returned by [sqlite3_last_insert_rowid()] is @@ -1433,13 +905,13 @@ int sqlite3_extended_result_codes(sqlite3*, int onoff); sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*); /* -** CAPI3REF: Count The Number Of Rows Modified {H12240} +** CAPI3REF: Count The Number Of Rows Modified {F12240} ** ** This function returns the number of database rows that were changed ** or inserted or deleted by the most recently completed SQL statement -** on the [database connection] specified by the first parameter. -** Only changes that are directly specified by the [INSERT], [UPDATE], -** or [DELETE] statement are counted. Auxiliary changes caused by +** on the connection specified by the first parameter. Only +** changes that are directly specified by the INSERT, UPDATE, or +** DELETE statement are counted. Auxiliary changes caused by ** triggers are not counted. Use the [sqlite3_total_changes()] function ** to find the total number of changes including changes caused by triggers. ** @@ -1463,93 +935,84 @@ sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*); ** most recent INSERT, UPDATE, or DELETE statement within the same ** trigger context. ** -** Thus, when called from the top level, this function returns the +** So when called from the top level, this function returns the ** number of changes in the most recent INSERT, UPDATE, or DELETE -** that also occurred at the top level. Within the body of a trigger, -** the sqlite3_changes() interface can be called to find the number of +** that also occurred at the top level. +** Within the body of a trigger, the sqlite3_changes() interface +** can be called to find the number of ** changes in the most recently completed INSERT, UPDATE, or DELETE ** statement within the body of the same trigger. -** However, the number returned does not include changes -** caused by subtriggers since those have their own context. +** However, the number returned does not include in changes +** caused by subtriggers since they have their own context. ** -** SQLite implements the command "DELETE FROM table" without a WHERE clause -** by dropping and recreating the table. Doing so is much faster than going -** through and deleting individual elements from the table. Because of this -** optimization, the deletions in "DELETE FROM table" are not row changes and -** will not be counted by the sqlite3_changes() or [sqlite3_total_changes()] -** functions, regardless of the number of elements that were originally -** in the table. To get an accurate count of the number of rows deleted, use -** "DELETE FROM table WHERE 1" instead. Or recompile using the -** [SQLITE_OMIT_TRUNCATE_OPTIMIZATION] compile-time option to disable the -** optimization on all queries. +** SQLite implements the command "DELETE FROM table" without +** a WHERE clause by dropping and recreating the table. (This is much +** faster than going through and deleting individual elements from the +** table.) Because of this optimization, the deletions in +** "DELETE FROM table" are not row changes and will not be counted +** by the sqlite3_changes() or [sqlite3_total_changes()] functions. +** To get an accurate count of the number of rows deleted, use +** "DELETE FROM table WHERE 1" instead. ** ** INVARIANTS: ** -** {H12241} The [sqlite3_changes()] function shall return the number of +** {F12241} The [sqlite3_changes()] function returns the number of ** row changes caused by the most recent INSERT, UPDATE, ** or DELETE statement on the same database connection and -** within the same or higher trigger context, or zero if there have +** within the same trigger context, or zero if there have ** not been any qualifying row changes. ** -** {H12243} Statements of the form "DELETE FROM tablename" with no -** WHERE clause shall cause subsequent calls to -** [sqlite3_changes()] to return zero, regardless of the -** number of rows originally in the table. +** LIMITATIONS: ** -** ASSUMPTIONS: -** -** {A12252} If a separate thread makes changes on the same database connection +** {U12252} If a separate thread makes changes on the same database connection ** while [sqlite3_changes()] is running then the value returned -** is unpredictable and not meaningful. +** is unpredictable and unmeaningful. */ int sqlite3_changes(sqlite3*); /* -** CAPI3REF: Total Number Of Rows Modified {H12260} -** -** This function returns the number of row changes caused by INSERT, -** UPDATE or DELETE statements since the [database connection] was opened. -** The count includes all changes from all trigger contexts. However, -** the count does not include changes used to implement REPLACE constraints, -** do rollbacks or ABORT processing, or DROP table processing. -** The changes are counted as soon as the statement that makes them is -** completed (when the statement handle is passed to [sqlite3_reset()] or +** CAPI3REF: Total Number Of Rows Modified {F12260} +*** +** This function returns the number of row changes caused +** by INSERT, UPDATE or DELETE statements since the database handle +** was opened. The count includes all changes from all trigger +** contexts. But the count does not include changes used to +** implement REPLACE constraints, do rollbacks or ABORT processing, +** or DROP table processing. +** The changes +** are counted as soon as the statement that makes them is completed +** (when the statement handle is passed to [sqlite3_reset()] or ** [sqlite3_finalize()]). ** -** SQLite implements the command "DELETE FROM table" without a WHERE clause -** by dropping and recreating the table. (This is much faster than going -** through and deleting individual elements from the table.) Because of this -** optimization, the deletions in "DELETE FROM table" are not row changes and -** will not be counted by the sqlite3_changes() or [sqlite3_total_changes()] -** functions, regardless of the number of elements that were originally -** in the table. To get an accurate count of the number of rows deleted, use -** "DELETE FROM table WHERE 1" instead. Or recompile using the -** [SQLITE_OMIT_TRUNCATE_OPTIMIZATION] compile-time option to disable the -** optimization on all queries. +** SQLite implements the command "DELETE FROM table" without +** a WHERE clause by dropping and recreating the table. (This is much +** faster than going +** through and deleting individual elements from the table.) Because of +** this optimization, the change count for "DELETE FROM table" will be +** zero regardless of the number of elements that were originally in the +** table. To get an accurate count of the number of rows deleted, use +** "DELETE FROM table WHERE 1" instead. ** ** See also the [sqlite3_changes()] interface. ** ** INVARIANTS: -** -** {H12261} The [sqlite3_total_changes()] returns the total number +** +** {F12261} The [sqlite3_total_changes()] returns the total number ** of row changes caused by INSERT, UPDATE, and/or DELETE ** statements on the same [database connection], in any -** trigger context, since the database connection was created. +** trigger context, since the database connection was +** created. ** -** {H12263} Statements of the form "DELETE FROM tablename" with no -** WHERE clause shall not change the value returned -** by [sqlite3_total_changes()]. +** LIMITATIONS: ** -** ASSUMPTIONS: -** -** {A12264} If a separate thread makes changes on the same database connection -** while [sqlite3_total_changes()] is running then the value -** returned is unpredictable and not meaningful. +** {U12264} If a separate thread makes changes on the same database connection +** while [sqlite3_total_changes()] is running then the value +** returned is unpredictable and unmeaningful. */ int sqlite3_total_changes(sqlite3*); /* -** CAPI3REF: Interrupt A Long-Running Query {H12270} +** CAPI3REF: Interrupt A Long-Running Query {F12270} ** ** This function causes any pending database operation to abort and ** return at its earliest opportunity. This routine is typically @@ -1559,39 +1022,38 @@ int sqlite3_total_changes(sqlite3*); ** ** It is safe to call this routine from a thread different from the ** thread that is currently running the database operation. But it -** is not safe to call this routine with a [database connection] that +** is not safe to call this routine with a database connection that ** is closed or might close before sqlite3_interrupt() returns. ** -** If an SQL operation is very nearly finished at the time when -** sqlite3_interrupt() is called, then it might not have an opportunity -** to be interrupted and might continue to completion. -** -** An SQL operation that is interrupted will return [SQLITE_INTERRUPT]. -** If the interrupted SQL operation is an INSERT, UPDATE, or DELETE -** that is inside an explicit transaction, then the entire transaction -** will be rolled back automatically. -** +** If an SQL is very nearly finished at the time when sqlite3_interrupt() +** is called, then it might not have an opportunity to be interrupted. +** It might continue to completion. +** An SQL operation that is interrupted will return +** [SQLITE_INTERRUPT]. If the interrupted SQL operation is an +** INSERT, UPDATE, or DELETE that is inside an explicit transaction, +** then the entire transaction will be rolled back automatically. ** A call to sqlite3_interrupt() has no effect on SQL statements ** that are started after sqlite3_interrupt() returns. ** ** INVARIANTS: ** -** {H12271} The [sqlite3_interrupt()] interface will force all running +** {F12271} The [sqlite3_interrupt()] interface will force all running ** SQL statements associated with the same database connection -** to halt after processing at most one additional row of data. +** to halt after processing at most one additional row of +** data. ** -** {H12272} Any SQL statement that is interrupted by [sqlite3_interrupt()] +** {F12272} Any SQL statement that is interrupted by [sqlite3_interrupt()] ** will return [SQLITE_INTERRUPT]. ** -** ASSUMPTIONS: +** LIMITATIONS: ** -** {A12279} If the database connection closes while [sqlite3_interrupt()] +** {U12279} If the database connection closes while [sqlite3_interrupt()] ** is running then bad things will likely happen. */ void sqlite3_interrupt(sqlite3*); /* -** CAPI3REF: Determine If An SQL Statement Is Complete {H10510} +** CAPI3REF: Determine If An SQL Statement Is Complete {F10510} ** ** These routines are useful for command-line input to determine if the ** currently entered text seems to form complete a SQL statement or @@ -1604,56 +1066,54 @@ void sqlite3_interrupt(sqlite3*); ** independent tokens (they are part of the token in which they are ** embedded) and thus do not count as a statement terminator. ** -** These routines do not parse the SQL statements thus -** will not detect syntactically incorrect SQL. +** These routines do not parse the SQL and +** so will not detect syntactically incorrect SQL. ** ** INVARIANTS: ** -** {H10511} A successful evaluation of [sqlite3_complete()] or -** [sqlite3_complete16()] functions shall -** return a numeric 1 if and only if the last non-whitespace -** token in their input is a semicolon that is not in between -** the BEGIN and END of a CREATE TRIGGER statement. +** {F10511} The sqlite3_complete() and sqlite3_complete16() functions +** return true (non-zero) if and only if the last +** non-whitespace token in their input is a semicolon that +** is not in between the BEGIN and END of a CREATE TRIGGER +** statement. ** -** {H10512} If a memory allocation error occurs during an invocation -** of [sqlite3_complete()] or [sqlite3_complete16()] then the -** routine shall return [SQLITE_NOMEM]. +** LIMITATIONS: ** -** ASSUMPTIONS: -** -** {A10512} The input to [sqlite3_complete()] must be a zero-terminated +** {U10512} The input to sqlite3_complete() must be a zero-terminated ** UTF-8 string. ** -** {A10513} The input to [sqlite3_complete16()] must be a zero-terminated +** {U10513} The input to sqlite3_complete16() must be a zero-terminated ** UTF-16 string in native byte order. */ int sqlite3_complete(const char *sql); int sqlite3_complete16(const void *sql); /* -** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors {H12310} +** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors {F12310} ** -** This routine sets a callback function that might be invoked whenever -** an attempt is made to open a database table that another thread -** or process has locked. -** -** If the busy callback is NULL, then [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED] -** is returned immediately upon encountering the lock. If the busy callback -** is not NULL, then the callback will be invoked with two arguments. -** -** The first argument to the handler is a copy of the void* pointer which -** is the third argument to sqlite3_busy_handler(). The second argument to -** the handler callback is the number of times that the busy handler has -** been invoked for this locking event. If the +** This routine identifies a callback function that might be +** invoked whenever an attempt is made to open a database table +** that another thread or process has locked. +** If the busy callback is NULL, then [SQLITE_BUSY] +** or [SQLITE_IOERR_BLOCKED] +** is returned immediately upon encountering the lock. +** If the busy callback is not NULL, then the +** callback will be invoked with two arguments. The +** first argument to the handler is a copy of the void* pointer which +** is the third argument to this routine. The second argument to +** the handler is the number of times that the busy handler has +** been invoked for this locking event. If the ** busy callback returns 0, then no additional attempts are made to ** access the database and [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED] is returned. ** If the callback returns non-zero, then another attempt ** is made to open the database for reading and the cycle repeats. ** -** The presence of a busy handler does not guarantee that it will be invoked -** when there is lock contention. If SQLite determines that invoking the busy -** handler could result in a deadlock, it will go ahead and return [SQLITE_BUSY] -** or [SQLITE_IOERR_BLOCKED] instead of invoking the busy handler. +** The presence of a busy handler does not guarantee that +** it will be invoked when there is lock contention. +** If SQLite determines that invoking the busy handler could result in +** a deadlock, it will go ahead and return [SQLITE_BUSY] or +** [SQLITE_IOERR_BLOCKED] instead of invoking the +** busy handler. ** Consider a scenario where one process is holding a read lock that ** it is trying to promote to a reserved lock and ** a second process is holding a reserved lock that it is trying @@ -1678,86 +1138,82 @@ int sqlite3_complete16(const void *sql); ** code is promoted from the relatively benign [SQLITE_BUSY] to ** the more severe [SQLITE_IOERR_BLOCKED]. This error code promotion ** forces an automatic rollback of the changes. See the -** +** ** CorruptionFollowingBusyError wiki page for a discussion of why ** this is important. +** +** There can only be a single busy handler defined for each database +** connection. Setting a new busy handler clears any previous one. +** Note that calling [sqlite3_busy_timeout()] will also set or clear +** the busy handler. ** -** There can only be a single busy handler defined for each -** [database connection]. Setting a new busy handler clears any -** previously set handler. Note that calling [sqlite3_busy_timeout()] -** will also set or clear the busy handler. -** -** The busy callback should not take any actions which modify the -** database connection that invoked the busy handler. Any such actions -** result in undefined behavior. -** ** INVARIANTS: ** -** {H12311} The [sqlite3_busy_handler(D,C,A)] function shall replace -** busy callback in the [database connection] D with a new -** a new busy handler C and application data pointer A. +** {F12311} The [sqlite3_busy_handler()] function replaces the busy handler +** callback in the database connection identified by the 1st +** parameter with a new busy handler identified by the 2nd and 3rd +** parameters. ** -** {H12312} Newly created [database connections] shall have a busy -** handler of NULL. +** {F12312} The default busy handler for new database connections is NULL. ** -** {H12314} When two or more [database connections] share a -** [sqlite3_enable_shared_cache | common cache], +** {F12314} When two or more database connection share a common cache, ** the busy handler for the database connection currently using -** the cache shall be invoked when the cache encounters a lock. +** the cache is invoked when the cache encounters a lock. ** -** {H12316} If a busy handler callback returns zero, then the SQLite interface -** that provoked the locking event shall return [SQLITE_BUSY]. +** {F12316} If a busy handler callback returns zero, then the SQLite +** interface that provoked the locking event will return +** [SQLITE_BUSY]. ** -** {H12318} SQLite shall invokes the busy handler with two arguments which +** {F12318} SQLite will invokes the busy handler with two argument which ** are a copy of the pointer supplied by the 3rd parameter to ** [sqlite3_busy_handler()] and a count of the number of prior ** invocations of the busy handler for the same locking event. ** -** ASSUMPTIONS: +** LIMITATIONS: ** -** {A12319} A busy handler must not close the database connection -** or [prepared statement] that invoked the busy handler. +** {U12319} A busy handler should not call close the database connection +** or prepared statement that invoked the busy handler. */ int sqlite3_busy_handler(sqlite3*, int(*)(void*,int), void*); /* -** CAPI3REF: Set A Busy Timeout {H12340} +** CAPI3REF: Set A Busy Timeout {F12340} ** -** This routine sets a [sqlite3_busy_handler | busy handler] that sleeps -** for a specified amount of time when a table is locked. The handler -** will sleep multiple times until at least "ms" milliseconds of sleeping -** have accumulated. {H12343} After "ms" milliseconds of sleeping, -** the handler returns 0 which causes [sqlite3_step()] to return -** [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED]. +** This routine sets a [sqlite3_busy_handler | busy handler] +** that sleeps for a while when a +** table is locked. The handler will sleep multiple times until +** at least "ms" milliseconds of sleeping have been done. {F12343} After +** "ms" milliseconds of sleeping, the handler returns 0 which +** causes [sqlite3_step()] to return [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED]. ** ** Calling this routine with an argument less than or equal to zero ** turns off all busy handlers. ** -** There can only be a single busy handler for a particular -** [database connection] any any given moment. If another busy handler -** was defined (using [sqlite3_busy_handler()]) prior to calling +** There can only be a single busy handler for a particular database +** connection. If another busy handler was defined +** (using [sqlite3_busy_handler()]) prior to calling ** this routine, that other busy handler is cleared. ** ** INVARIANTS: ** -** {H12341} The [sqlite3_busy_timeout()] function shall override any prior +** {F12341} The [sqlite3_busy_timeout()] function overrides any prior ** [sqlite3_busy_timeout()] or [sqlite3_busy_handler()] setting -** on the same [database connection]. +** on the same database connection. ** -** {H12343} If the 2nd parameter to [sqlite3_busy_timeout()] is less than -** or equal to zero, then the busy handler shall be cleared so that +** {F12343} If the 2nd parameter to [sqlite3_busy_timeout()] is less than +** or equal to zero, then the busy handler is cleared so that ** all subsequent locking events immediately return [SQLITE_BUSY]. ** -** {H12344} If the 2nd parameter to [sqlite3_busy_timeout()] is a positive -** number N, then a busy handler shall be set that repeatedly calls -** the xSleep() method in the [sqlite3_vfs | VFS interface] until -** either the lock clears or until the cumulative sleep time -** reported back by xSleep() exceeds N milliseconds. +** {F12344} If the 2nd parameter to [sqlite3_busy_timeout()] is a positive +** number N, then a busy handler is set that repeatedly calls +** the xSleep() method in the VFS interface until either the +** lock clears or until the cumulative sleep time reported back +** by xSleep() exceeds N milliseconds. */ int sqlite3_busy_timeout(sqlite3*, int ms); /* -** CAPI3REF: Convenience Routines For Running Queries {H12370} +** CAPI3REF: Convenience Routines For Running Queries {F12370} ** ** Definition: A result table is memory data structure created by the ** [sqlite3_get_table()] interface. A result table records the @@ -1768,14 +1224,16 @@ int sqlite3_busy_timeout(sqlite3*, int ms); ** numbers are obtained separately. Let N be the number of rows ** and M be the number of columns. ** -** A result table is an array of pointers to zero-terminated UTF-8 strings. -** There are (N+1)*M elements in the array. The first M pointers point -** to zero-terminated strings that contain the names of the columns. -** The remaining entries all point to query results. NULL values result -** in NULL pointers. All other values are in their UTF-8 zero-terminated -** string representation as returned by [sqlite3_column_text()]. +** A result table is an array of pointers to zero-terminated +** UTF-8 strings. There are (N+1)*M elements in the array. +** The first M pointers point to zero-terminated strings that +** contain the names of the columns. +** The remaining entries all point to query results. NULL +** values are give a NULL pointer. All other values are in +** their UTF-8 zero-terminated string representation as returned by +** [sqlite3_column_text()]. ** -** A result table might consist of one or more memory allocations. +** A result table might consists of one or more memory allocations. ** It is not safe to pass a result table directly to [sqlite3_free()]. ** A result table should be deallocated using [sqlite3_free_table()]. ** @@ -1810,11 +1268,11 @@ int sqlite3_busy_timeout(sqlite3*, int ms); ** string of its 2nd parameter. It returns a result table to the ** pointer given in its 3rd parameter. ** -** After the calling function has finished using the result, it should -** pass the pointer to the result table to sqlite3_free_table() in order to -** release the memory that was malloced. Because of the way the +** After the calling function has finished using the result, it should +** pass the pointer to the result table to sqlite3_free_table() in order to +** release the memory that was malloc-ed. Because of the way the ** [sqlite3_malloc()] happens within sqlite3_get_table(), the calling -** function must not try to call [sqlite3_free()] directly. Only +** function must not try to call [sqlite3_free()] directly. Only ** [sqlite3_free_table()] is able to release the memory properly and safely. ** ** The sqlite3_get_table() interface is implemented as a wrapper around @@ -1822,53 +1280,43 @@ int sqlite3_busy_timeout(sqlite3*, int ms); ** to any internal data structures of SQLite. It uses only the public ** interface defined here. As a consequence, errors that occur in the ** wrapper layer outside of the internal [sqlite3_exec()] call are not -** reflected in subsequent calls to [sqlite3_errcode()] or [sqlite3_errmsg()]. +** reflected in subsequent calls to [sqlite3_errcode()] or +** [sqlite3_errmsg()]. ** ** INVARIANTS: ** -** {H12371} If a [sqlite3_get_table()] fails a memory allocation, then -** it shall free the result table under construction, abort the -** query in process, skip any subsequent queries, set the -** *pazResult output pointer to NULL and return [SQLITE_NOMEM]. +** {F12371} If a [sqlite3_get_table()] fails a memory allocation, then +** it frees the result table under construction, aborts the +** query in process, skips any subsequent queries, sets the +** *resultp output pointer to NULL and returns [SQLITE_NOMEM]. ** -** {H12373} If the pnColumn parameter to [sqlite3_get_table()] is not NULL -** then a successful invocation of [sqlite3_get_table()] shall -** write the number of columns in the -** result set of the query into *pnColumn. +** {F12373} If the ncolumn parameter to [sqlite3_get_table()] is not NULL +** then [sqlite3_get_table()] write the number of columns in the +** result set of the query into *ncolumn if the query is +** successful (if the function returns SQLITE_OK). ** -** {H12374} If the pnRow parameter to [sqlite3_get_table()] is not NULL -** then a successful invocation of [sqlite3_get_table()] shall -** writes the number of rows in the -** result set of the query into *pnRow. +** {F12374} If the nrow parameter to [sqlite3_get_table()] is not NULL +** then [sqlite3_get_table()] write the number of rows in the +** result set of the query into *nrow if the query is +** successful (if the function returns SQLITE_OK). ** -** {H12376} A successful invocation of [sqlite3_get_table()] that computes -** N rows of result with C columns per row shall make *pazResult -** point to an array of pointers to (N+1)*C strings where the first -** C strings are column names as obtained from -** [sqlite3_column_name()] and the rest are column result values -** obtained from [sqlite3_column_text()]. -** -** {H12379} The values in the pazResult array returned by [sqlite3_get_table()] -** shall remain valid until cleared by [sqlite3_free_table()]. -** -** {H12382} When an error occurs during evaluation of [sqlite3_get_table()] -** the function shall set *pazResult to NULL, write an error message -** into memory obtained from [sqlite3_malloc()], make -** **pzErrmsg point to that error message, and return a -** appropriate [error code]. +** {F12376} The [sqlite3_get_table()] function sets its *ncolumn value +** to the number of columns in the result set of the query in the +** sql parameter, or to zero if the query in sql has an empty +** result set. */ int sqlite3_get_table( - sqlite3 *db, /* An open database */ - const char *zSql, /* SQL to be evaluated */ - char ***pazResult, /* Results of the query */ - int *pnRow, /* Number of result rows written here */ - int *pnColumn, /* Number of result columns written here */ - char **pzErrmsg /* Error msg written here */ + sqlite3*, /* An open database */ + const char *sql, /* SQL to be evaluated */ + char ***pResult, /* Results of the query */ + int *nrow, /* Number of result rows written here */ + int *ncolumn, /* Number of result columns written here */ + char **errmsg /* Error msg written here */ ); void sqlite3_free_table(char **result); /* -** CAPI3REF: Formatted String Printing Functions {H17400} +** CAPI3REF: Formatted String Printing Functions {F17400} ** ** These routines are workalikes of the "printf()" family of functions ** from the standard C library. @@ -1876,7 +1324,7 @@ void sqlite3_free_table(char **result); ** The sqlite3_mprintf() and sqlite3_vmprintf() routines write their ** results into memory obtained from [sqlite3_malloc()]. ** The strings returned by these two routines should be -** released by [sqlite3_free()]. Both routines return a +** released by [sqlite3_free()]. Both routines return a ** NULL pointer if [sqlite3_malloc()] is unable to allocate enough ** memory to hold the resulting string. ** @@ -1901,7 +1349,7 @@ void sqlite3_free_table(char **result); ** ** These routines all implement some additional formatting ** options that are useful for constructing SQL statements. -** All of the usual printf() formatting options apply. In addition, there +** All of the usual printf formatting options apply. In addition, there ** is are "%q", "%Q", and "%z" options. ** ** The %q option works like %s in that it substitutes a null-terminated @@ -1910,7 +1358,7 @@ void sqlite3_free_table(char **result); ** character it escapes that character and allows it to be inserted into ** the string. ** -** For example, assume the string variable zText contains text as follows: +** For example, so some string variable contains text as follows: ** **
       **  char *zText = "It's a happy day!";
      @@ -1938,13 +1386,14 @@ void sqlite3_free_table(char **result);
       **  INSERT INTO table1 VALUES('It's a happy day!');
       ** 
      ** -** This second example is an SQL syntax error. As a general rule you should -** always use %q instead of %s when inserting text into a string literal. +** This second example is an SQL syntax error. As a general rule you +** should always use %q instead of %s when inserting text into a string +** literal. ** ** The %Q option works like %q except it also adds single quotes around -** the outside of the total string. Additionally, if the parameter in the -** argument list is a NULL pointer, %Q substitutes the text "NULL" (without -** single quotes) in place of the %Q option. So, for example, one could say: +** the outside of the total string. Or if the parameter in the argument +** list is a NULL pointer, %Q substitutes the text "NULL" (without single +** quotes) in place of the %Q option. {END} So, for example, one could say: ** **
       **  char *zSQL = sqlite3_mprintf("INSERT INTO table VALUES(%Q)", zText);
      @@ -1961,32 +1410,33 @@ void sqlite3_free_table(char **result);
       **
       ** INVARIANTS:
       **
      -** {H17403}  The [sqlite3_mprintf()] and [sqlite3_vmprintf()] interfaces
      +** {F17403}  The [sqlite3_mprintf()] and [sqlite3_vmprintf()] interfaces
       **           return either pointers to zero-terminated UTF-8 strings held in
       **           memory obtained from [sqlite3_malloc()] or NULL pointers if
       **           a call to [sqlite3_malloc()] fails.
       **
      -** {H17406}  The [sqlite3_snprintf()] interface writes a zero-terminated
      +** {F17406}  The [sqlite3_snprintf()] interface writes a zero-terminated
       **           UTF-8 string into the buffer pointed to by the second parameter
       **           provided that the first parameter is greater than zero.
       **
      -** {H17407}  The [sqlite3_snprintf()] interface does not write slots of
      +** {F17407}  The [sqlite3_snprintf()] interface does not writes slots of
       **           its output buffer (the second parameter) outside the range
       **           of 0 through N-1 (where N is the first parameter)
       **           regardless of the length of the string
       **           requested by the format specification.
      +**   
       */
       char *sqlite3_mprintf(const char*,...);
       char *sqlite3_vmprintf(const char*, va_list);
       char *sqlite3_snprintf(int,char*,const char*, ...);
       
       /*
      -** CAPI3REF: Memory Allocation Subsystem {H17300} 
      +** CAPI3REF: Memory Allocation Subsystem {F17300}
       **
       ** The SQLite core  uses these three routines for all of its own
       ** internal memory allocation needs. "Core" in the previous sentence
       ** does not include operating-system specific VFS implementation.  The
      -** Windows VFS uses native malloc() and free() for some operations.
      +** windows VFS uses native malloc and free for some operations.
       **
       ** The sqlite3_malloc() routine returns a pointer to a block
       ** of memory at least N bytes in length, where N is the parameter.
      @@ -2015,7 +1465,7 @@ char *sqlite3_snprintf(int,char*,const char*, ...);
       ** If the second parameter to sqlite3_realloc() is zero or
       ** negative then the behavior is exactly the same as calling
       ** sqlite3_free(P) where P is the first parameter to sqlite3_realloc().
      -** sqlite3_realloc() returns a pointer to a memory allocation
      +** Sqlite3_realloc() returns a pointer to a memory allocation
       ** of at least N bytes in size or NULL if sufficient memory is unavailable.
       ** If M is the size of the prior allocation, then min(N,M) bytes
       ** of the prior allocation are copied into the beginning of buffer returned
      @@ -2026,123 +1476,128 @@ char *sqlite3_snprintf(int,char*,const char*, ...);
       ** The memory returned by sqlite3_malloc() and sqlite3_realloc()
       ** is always aligned to at least an 8 byte boundary. {END}
       **
      -** The default implementation of the memory allocation subsystem uses
      -** the malloc(), realloc() and free() provided by the standard C library.
      -** {H17382} However, if SQLite is compiled with the
      -** SQLITE_MEMORY_SIZE=NNN C preprocessor macro (where NNN
      -** is an integer), then SQLite create a static array of at least
      -** NNN bytes in size and uses that array for all of its dynamic
      -** memory allocation needs. {END}  Additional memory allocator options
      -** may be added in future releases.
      +** The default implementation
      +** of the memory allocation subsystem uses the malloc(), realloc()
      +** and free() provided by the standard C library. {F17382} However, if 
      +** SQLite is compiled with the following C preprocessor macro
      +**
      +** 
      SQLITE_MEMORY_SIZE=NNN
      +** +** where NNN is an integer, then SQLite create a static +** array of at least NNN bytes in size and use that array +** for all of its dynamic memory allocation needs. {END} Additional +** memory allocator options may be added in future releases. ** ** In SQLite version 3.5.0 and 3.5.1, it was possible to define ** the SQLITE_OMIT_MEMORY_ALLOCATION which would cause the built-in ** implementation of these routines to be omitted. That capability -** is no longer provided. Only built-in memory allocators can be used. +** is no longer provided. Only built-in memory allocators can be +** used. ** -** The Windows OS interface layer calls +** The windows OS interface layer calls ** the system malloc() and free() directly when converting ** filenames between the UTF-8 encoding used by SQLite -** and whatever filename encoding is used by the particular Windows +** and whatever filename encoding is used by the particular windows ** installation. Memory allocation errors are detected, but ** they are reported back as [SQLITE_CANTOPEN] or ** [SQLITE_IOERR] rather than [SQLITE_NOMEM]. ** ** INVARIANTS: ** -** {H17303} The [sqlite3_malloc(N)] interface returns either a pointer to -** a newly checked-out block of at least N bytes of memory -** that is 8-byte aligned, or it returns NULL if it is unable -** to fulfill the request. +** {F17303} The [sqlite3_malloc(N)] interface returns either a pointer to +** newly checked-out block of at least N bytes of memory +** that is 8-byte aligned, +** or it returns NULL if it is unable to fulfill the request. ** -** {H17304} The [sqlite3_malloc(N)] interface returns a NULL pointer if +** {F17304} The [sqlite3_malloc(N)] interface returns a NULL pointer if ** N is less than or equal to zero. ** -** {H17305} The [sqlite3_free(P)] interface releases memory previously +** {F17305} The [sqlite3_free(P)] interface releases memory previously ** returned from [sqlite3_malloc()] or [sqlite3_realloc()], ** making it available for reuse. ** -** {H17306} A call to [sqlite3_free(NULL)] is a harmless no-op. +** {F17306} A call to [sqlite3_free(NULL)] is a harmless no-op. ** -** {H17310} A call to [sqlite3_realloc(0,N)] is equivalent to a call +** {F17310} A call to [sqlite3_realloc(0,N)] is equivalent to a call ** to [sqlite3_malloc(N)]. ** -** {H17312} A call to [sqlite3_realloc(P,0)] is equivalent to a call +** {F17312} A call to [sqlite3_realloc(P,0)] is equivalent to a call ** to [sqlite3_free(P)]. ** -** {H17315} The SQLite core uses [sqlite3_malloc()], [sqlite3_realloc()], +** {F17315} The SQLite core uses [sqlite3_malloc()], [sqlite3_realloc()], ** and [sqlite3_free()] for all of its memory allocation and ** deallocation needs. ** -** {H17318} The [sqlite3_realloc(P,N)] interface returns either a pointer +** {F17318} The [sqlite3_realloc(P,N)] interface returns either a pointer ** to a block of checked-out memory of at least N bytes in size ** that is 8-byte aligned, or a NULL pointer. ** -** {H17321} When [sqlite3_realloc(P,N)] returns a non-NULL pointer, it first -** copies the first K bytes of content from P into the newly -** allocated block, where K is the lesser of N and the size of -** the buffer P. +** {F17321} When [sqlite3_realloc(P,N)] returns a non-NULL pointer, it first +** copies the first K bytes of content from P into the newly allocated +** where K is the lessor of N and the size of the buffer P. ** -** {H17322} When [sqlite3_realloc(P,N)] returns a non-NULL pointer, it first +** {F17322} When [sqlite3_realloc(P,N)] returns a non-NULL pointer, it first ** releases the buffer P. ** -** {H17323} When [sqlite3_realloc(P,N)] returns NULL, the buffer P is +** {F17323} When [sqlite3_realloc(P,N)] returns NULL, the buffer P is ** not modified or released. ** -** ASSUMPTIONS: +** LIMITATIONS: ** -** {A17350} The pointer arguments to [sqlite3_free()] and [sqlite3_realloc()] -** must be either NULL or else pointers obtained from a prior -** invocation of [sqlite3_malloc()] or [sqlite3_realloc()] that have -** not yet been released. +** {U17350} The pointer arguments to [sqlite3_free()] and [sqlite3_realloc()] +** must be either NULL or else a pointer obtained from a prior +** invocation of [sqlite3_malloc()] or [sqlite3_realloc()] that has +** not been released. ** -** {A17351} The application must not read or write any part of +** {U17351} The application must not read or write any part of ** a block of memory after it has been released using ** [sqlite3_free()] or [sqlite3_realloc()]. +** */ void *sqlite3_malloc(int); void *sqlite3_realloc(void*, int); void sqlite3_free(void*); /* -** CAPI3REF: Memory Allocator Statistics {H17370} +** CAPI3REF: Memory Allocator Statistics {F17370} ** ** SQLite provides these two interfaces for reporting on the status ** of the [sqlite3_malloc()], [sqlite3_free()], and [sqlite3_realloc()] -** routines, which form the built-in memory allocation subsystem. +** the memory allocation subsystem included within the SQLite. ** ** INVARIANTS: ** -** {H17371} The [sqlite3_memory_used()] routine returns the number of bytes -** of memory currently outstanding (malloced but not freed). +** {F17371} The [sqlite3_memory_used()] routine returns the +** number of bytes of memory currently outstanding +** (malloced but not freed). ** -** {H17373} The [sqlite3_memory_highwater()] routine returns the maximum -** value of [sqlite3_memory_used()] since the high-water mark -** was last reset. +** {F17373} The [sqlite3_memory_highwater()] routine returns the maximum +** value of [sqlite3_memory_used()] +** since the highwater mark was last reset. ** -** {H17374} The values returned by [sqlite3_memory_used()] and +** {F17374} The values returned by [sqlite3_memory_used()] and ** [sqlite3_memory_highwater()] include any overhead ** added by SQLite in its implementation of [sqlite3_malloc()], ** but not overhead added by the any underlying system library ** routines that [sqlite3_malloc()] may call. -** -** {H17375} The memory high-water mark is reset to the current value of +** +** {F17375} The memory highwater mark is reset to the current value of ** [sqlite3_memory_used()] if and only if the parameter to ** [sqlite3_memory_highwater()] is true. The value returned -** by [sqlite3_memory_highwater(1)] is the high-water mark +** by [sqlite3_memory_highwater(1)] is the highwater mark ** prior to the reset. */ sqlite3_int64 sqlite3_memory_used(void); sqlite3_int64 sqlite3_memory_highwater(int resetFlag); /* -** CAPI3REF: Pseudo-Random Number Generator {H17390} +** CAPI3REF: Pseudo-Random Number Generator {F17390} ** ** SQLite contains a high-quality pseudo-random number generator (PRNG) used to ** select random ROWIDs when inserting new records into a table that ** already uses the largest possible ROWID. The PRNG is also used for ** the build-in random() and randomblob() SQL functions. This interface allows -** applications to access the same PRNG for other purposes. +** appliations to access the same PRNG for other purposes. ** ** A call to this routine stores N bytes of randomness into buffer P. ** @@ -2155,13 +1610,13 @@ sqlite3_int64 sqlite3_memory_highwater(int resetFlag); ** ** INVARIANTS: ** -** {H17392} The [sqlite3_randomness(N,P)] interface writes N bytes of +** {F17392} The [sqlite3_randomness(N,P)] interface writes N bytes of ** high-quality pseudo-randomness into buffer P. */ void sqlite3_randomness(int N, void *P); /* -** CAPI3REF: Compile-Time Authorization Callbacks {H12500} +** CAPI3REF: Compile-Time Authorization Callbacks {F12500} ** ** This routine registers a authorizer callback with a particular ** [database connection], supplied in the first argument. @@ -2174,9 +1629,9 @@ void sqlite3_randomness(int N, void *P); ** return [SQLITE_OK] to allow the action, [SQLITE_IGNORE] to disallow the ** specific action but allow the SQL statement to continue to be ** compiled, or [SQLITE_DENY] to cause the entire SQL statement to be -** rejected with an error. If the authorizer callback returns +** rejected with an error. If the authorizer callback returns ** any value other than [SQLITE_IGNORE], [SQLITE_OK], or [SQLITE_DENY] -** then the [sqlite3_prepare_v2()] or equivalent call that triggered +** then [sqlite3_prepare_v2()] or equivalent call that triggered ** the authorizer will fail with an error message. ** ** When the callback returns [SQLITE_OK], that means the operation @@ -2191,17 +1646,19 @@ void sqlite3_randomness(int N, void *P); ** return can be used to deny an untrusted user access to individual ** columns of a table. ** -** The first parameter to the authorizer callback is a copy of the third -** parameter to the sqlite3_set_authorizer() interface. The second parameter -** to the callback is an integer [SQLITE_COPY | action code] that specifies -** the particular action to be authorized. The third through sixth parameters -** to the callback are zero-terminated strings that contain additional -** details about the action to be authorized. +** The first parameter to the authorizer callback is a copy of +** the third parameter to the sqlite3_set_authorizer() interface. +** The second parameter to the callback is an integer +** [SQLITE_COPY | action code] that specifies the particular action +** to be authorized. The third through sixth +** parameters to the callback are zero-terminated strings that contain +** additional details about the action to be authorized. ** ** An authorizer is used when [sqlite3_prepare | preparing] -** SQL statements from an untrusted source, to ensure that the SQL statements -** do not try to access data they are not allowed to see, or that they do not -** try to execute malicious statements that damage the database. For +** SQL statements from an untrusted +** source, to ensure that the SQL statements do not try to access data +** that they are not allowed to see, or that they do not try to +** execute malicious statements that damage the database. For ** example, an application may allow a user to enter arbitrary ** SQL queries for evaluation by a database. But the application does ** not want the user to be able to make arbitrary changes to the @@ -2219,71 +1676,61 @@ void sqlite3_randomness(int N, void *P); ** previous call. Disable the authorizer by installing a NULL callback. ** The authorizer is disabled by default. ** -** The authorizer callback must not do anything that will modify -** the database connection that invoked the authorizer callback. -** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their -** database connections for the meaning of "modify" in this paragraph. -** -** When [sqlite3_prepare_v2()] is used to prepare a statement, the -** statement might be reprepared during [sqlite3_step()] due to a -** schema change. Hence, the application should ensure that the -** correct authorizer callback remains in place during the [sqlite3_step()]. -** -** Note that the authorizer callback is invoked only during +** Note that the authorizer callback is invoked only during ** [sqlite3_prepare()] or its variants. Authorization is not ** performed during statement evaluation in [sqlite3_step()]. ** ** INVARIANTS: ** -** {H12501} The [sqlite3_set_authorizer(D,...)] interface registers a +** {F12501} The [sqlite3_set_authorizer(D,...)] interface registers a ** authorizer callback with database connection D. ** -** {H12502} The authorizer callback is invoked as SQL statements are -** being parseed and compiled. +** {F12502} The authorizer callback is invoked as SQL statements are +** being compiled ** -** {H12503} If the authorizer callback returns any value other than -** [SQLITE_IGNORE], [SQLITE_OK], or [SQLITE_DENY], then -** the application interface call that caused +** {F12503} If the authorizer callback returns any value other than +** [SQLITE_IGNORE], [SQLITE_OK], or [SQLITE_DENY] then +** the [sqlite3_prepare_v2()] or equivalent call that caused ** the authorizer callback to run shall fail with an ** [SQLITE_ERROR] error code and an appropriate error message. ** -** {H12504} When the authorizer callback returns [SQLITE_OK], the operation -** described is processed normally. +** {F12504} When the authorizer callback returns [SQLITE_OK], the operation +** described is coded normally. ** -** {H12505} When the authorizer callback returns [SQLITE_DENY], the -** application interface call that caused the +** {F12505} When the authorizer callback returns [SQLITE_DENY], the +** [sqlite3_prepare_v2()] or equivalent call that caused the ** authorizer callback to run shall fail ** with an [SQLITE_ERROR] error code and an error message ** explaining that access is denied. ** -** {H12506} If the authorizer code (the 2nd parameter to the authorizer +** {F12506} If the authorizer code (the 2nd parameter to the authorizer ** callback) is [SQLITE_READ] and the authorizer callback returns -** [SQLITE_IGNORE], then the prepared statement is constructed to +** [SQLITE_IGNORE] then the prepared statement is constructed to ** insert a NULL value in place of the table column that would have ** been read if [SQLITE_OK] had been returned. ** -** {H12507} If the authorizer code (the 2nd parameter to the authorizer +** {F12507} If the authorizer code (the 2nd parameter to the authorizer ** callback) is anything other than [SQLITE_READ], then -** a return of [SQLITE_IGNORE] has the same effect as [SQLITE_DENY]. +** a return of [SQLITE_IGNORE] has the same effect as [SQLITE_DENY]. ** -** {H12510} The first parameter to the authorizer callback is a copy of +** {F12510} The first parameter to the authorizer callback is a copy of ** the third parameter to the [sqlite3_set_authorizer()] interface. ** -** {H12511} The second parameter to the callback is an integer +** {F12511} The second parameter to the callback is an integer ** [SQLITE_COPY | action code] that specifies the particular action ** to be authorized. ** -** {H12512} The third through sixth parameters to the callback are -** zero-terminated strings that contain +** {F12512} The third through sixth parameters to the callback are +** zero-terminated strings that contain ** additional details about the action to be authorized. ** -** {H12520} Each call to [sqlite3_set_authorizer()] overrides +** {F12520} Each call to [sqlite3_set_authorizer()] overrides the ** any previously installed authorizer. ** -** {H12521} A NULL authorizer means that no authorization +** {F12521} A NULL authorizer means that no authorization ** callback is invoked. ** -** {H12522} The default authorizer is NULL. +** {F12522} The default authorizer is NULL. */ int sqlite3_set_authorizer( sqlite3*, @@ -2292,7 +1739,7 @@ int sqlite3_set_authorizer( ); /* -** CAPI3REF: Authorizer Return Codes {H12590} +** CAPI3REF: Authorizer Return Codes {F12590} ** ** The [sqlite3_set_authorizer | authorizer callback function] must ** return either [SQLITE_OK] or one of these two constants in order @@ -2304,44 +1751,44 @@ int sqlite3_set_authorizer( #define SQLITE_IGNORE 2 /* Don't allow access, but don't generate an error */ /* -** CAPI3REF: Authorizer Action Codes {H12550} +** CAPI3REF: Authorizer Action Codes {F12550} ** ** The [sqlite3_set_authorizer()] interface registers a callback function -** that is invoked to authorize certain SQL statement actions. The +** that is invoked to authorizer certain SQL statement actions. The ** second parameter to the callback is an integer code that specifies ** what action is being authorized. These are the integer action codes that ** the authorizer callback may be passed. ** -** These action code values signify what kind of operation is to be +** These action code values signify what kind of operation is to be ** authorized. The 3rd and 4th parameters to the authorization ** callback function will be parameters or NULL depending on which of these ** codes is used as the second parameter. The 5th parameter to the -** authorizer callback is the name of the database ("main", "temp", +** authorizer callback is the name of the database ("main", "temp", ** etc.) if applicable. The 6th parameter to the authorizer callback ** is the name of the inner-most trigger or view that is responsible for -** the access attempt or NULL if this access attempt is directly from +** the access attempt or NULL if this access attempt is directly from ** top-level SQL code. ** ** INVARIANTS: ** -** {H12551} The second parameter to an -** [sqlite3_set_authorizer | authorizer callback] shall be an integer +** {F12551} The second parameter to an +** [sqlite3_set_authorizer | authorizer callback is always an integer ** [SQLITE_COPY | authorizer code] that specifies what action ** is being authorized. ** -** {H12552} The 3rd and 4th parameters to the -** [sqlite3_set_authorizer | authorization callback] -** shall be parameters or NULL depending on which +** {F12552} The 3rd and 4th parameters to the +** [sqlite3_set_authorizer | authorization callback function] +** will be parameters or NULL depending on which ** [SQLITE_COPY | authorizer code] is used as the second parameter. ** -** {H12553} The 5th parameter to the -** [sqlite3_set_authorizer | authorizer callback] shall be the name +** {F12553} The 5th parameter to the +** [sqlite3_set_authorizer | authorizer callback] is the name ** of the database (example: "main", "temp", etc.) if applicable. ** -** {H12554} The 6th parameter to the -** [sqlite3_set_authorizer | authorizer callback] shall be the name +** {F12554} The 6th parameter to the +** [sqlite3_set_authorizer | authorizer callback] is the name ** of the inner-most trigger or view that is responsible for -** the access attempt or NULL if this access attempt is directly from +** the access attempt or NULL if this access attempt is directly from ** top-level SQL code. */ /******************************************* 3rd ************ 4th ***********/ @@ -2379,8 +1826,7 @@ int sqlite3_set_authorizer( #define SQLITE_COPY 0 /* No longer used */ /* -** CAPI3REF: Tracing And Profiling Functions {H12280} -** EXPERIMENTAL +** CAPI3REF: Tracing And Profiling Functions {F12280} ** ** These routines register callback functions that can be used for ** tracing and profiling the execution of SQL statements. @@ -2389,252 +1835,245 @@ int sqlite3_set_authorizer( ** various times when an SQL statement is being run by [sqlite3_step()]. ** The callback returns a UTF-8 rendering of the SQL statement text ** as the statement first begins executing. Additional callbacks occur -** as each triggered subprogram is entered. The callbacks for triggers +** as each triggersubprogram is entered. The callbacks for triggers ** contain a UTF-8 SQL comment that identifies the trigger. -** +** ** The callback function registered by sqlite3_profile() is invoked ** as each SQL statement finishes. The profile callback contains ** the original statement text and an estimate of wall-clock time ** of how long that statement took to run. ** +** The sqlite3_profile() API is currently considered experimental and +** is subject to change or removal in a future release. +** +** The trigger reporting feature of the trace callback is considered +** experimental and is subject to change or removal in future releases. +** Future versions of SQLite might also add new trace callback +** invocations. +** ** INVARIANTS: ** -** {H12281} The callback function registered by [sqlite3_trace()] -** shall be invoked +** {F12281} The callback function registered by [sqlite3_trace()] is ** whenever an SQL statement first begins to execute and ** whenever a trigger subprogram first begins to run. ** -** {H12282} Each call to [sqlite3_trace()] shall override the previously +** {F12282} Each call to [sqlite3_trace()] overrides the previously ** registered trace callback. ** -** {H12283} A NULL trace callback shall disable tracing. +** {F12283} A NULL trace callback disables tracing. ** -** {H12284} The first argument to the trace callback shall be a copy of +** {F12284} The first argument to the trace callback is a copy of ** the pointer which was the 3rd argument to [sqlite3_trace()]. ** -** {H12285} The second argument to the trace callback is a -** zero-terminated UTF-8 string containing the original text +** {F12285} The second argument to the trace callback is a +** zero-terminated UTF8 string containing the original text ** of the SQL statement as it was passed into [sqlite3_prepare_v2()] ** or the equivalent, or an SQL comment indicating the beginning ** of a trigger subprogram. ** -** {H12287} The callback function registered by [sqlite3_profile()] is invoked +** {F12287} The callback function registered by [sqlite3_profile()] is invoked ** as each SQL statement finishes. ** -** {H12288} The first parameter to the profile callback is a copy of +** {F12288} The first parameter to the profile callback is a copy of ** the 3rd parameter to [sqlite3_profile()]. ** -** {H12289} The second parameter to the profile callback is a +** {F12289} The second parameter to the profile callback is a ** zero-terminated UTF-8 string that contains the complete text of ** the SQL statement as it was processed by [sqlite3_prepare_v2()] ** or the equivalent. ** -** {H12290} The third parameter to the profile callback is an estimate +** {F12290} The third parameter to the profile callback is an estimate ** of the number of nanoseconds of wall-clock time required to ** run the SQL statement from start to finish. */ -SQLITE_EXPERIMENTAL void *sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*); -SQLITE_EXPERIMENTAL void *sqlite3_profile(sqlite3*, +void *sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*); +void *sqlite3_profile(sqlite3*, void(*xProfile)(void*,const char*,sqlite3_uint64), void*); /* -** CAPI3REF: Query Progress Callbacks {H12910} +** CAPI3REF: Query Progress Callbacks {F12910} ** ** This routine configures a callback function - the ** progress callback - that is invoked periodically during long ** running calls to [sqlite3_exec()], [sqlite3_step()] and -** [sqlite3_get_table()]. An example use for this +** [sqlite3_get_table()]. An example use for this ** interface is to keep a GUI updated during a large query. ** -** If the progress callback returns non-zero, the operation is +** If the progress callback returns non-zero, the opertion is ** interrupted. This feature can be used to implement a -** "Cancel" button on a GUI progress dialog box. -** -** The progress handler must not do anything that will modify -** the database connection that invoked the progress handler. -** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their -** database connections for the meaning of "modify" in this paragraph. +** "Cancel" button on a GUI dialog box. ** ** INVARIANTS: ** -** {H12911} The callback function registered by sqlite3_progress_handler() +** {F12911} The callback function registered by [sqlite3_progress_handler()] ** is invoked periodically during long running calls to ** [sqlite3_step()]. ** -** {H12912} The progress callback is invoked once for every N virtual -** machine opcodes, where N is the second argument to +** {F12912} The progress callback is invoked once for every N virtual +** machine opcodes, where N is the second argument to ** the [sqlite3_progress_handler()] call that registered -** the callback. If N is less than 1, sqlite3_progress_handler() -** acts as if a NULL progress handler had been specified. +** the callback. What if N is less than 1? ** -** {H12913} The progress callback itself is identified by the third -** argument to sqlite3_progress_handler(). +** {F12913} The progress callback itself is identified by the third +** argument to [sqlite3_progress_handler()]. ** -** {H12914} The fourth argument to sqlite3_progress_handler() is a -** void pointer passed to the progress callback +** {F12914} The fourth argument [sqlite3_progress_handler()] is a +*** void pointer passed to the progress callback ** function each time it is invoked. ** -** {H12915} If a call to [sqlite3_step()] results in fewer than N opcodes -** being executed, then the progress callback is never invoked. +** {F12915} If a call to [sqlite3_step()] results in fewer than +** N opcodes being executed, +** then the progress callback is never invoked. {END} +** +** {F12916} Every call to [sqlite3_progress_handler()] +** overwrites any previously registere progress handler. ** -** {H12916} Every call to [sqlite3_progress_handler()] -** overwrites any previously registered progress handler. -** -** {H12917} If the progress handler callback is NULL then no progress +** {F12917} If the progress handler callback is NULL then no progress ** handler is invoked. ** -** {H12918} If the progress callback returns a result other than 0, then +** {F12918} If the progress callback returns a result other than 0, then ** the behavior is a if [sqlite3_interrupt()] had been called. -** */ void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*); /* -** CAPI3REF: Opening A New Database Connection {H12700} +** CAPI3REF: Opening A New Database Connection {F12700} ** -** These routines open an SQLite database file whose name is given by the -** filename argument. The filename argument is interpreted as UTF-8 for -** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte -** order for sqlite3_open16(). A [database connection] handle is usually -** returned in *ppDb, even if an error occurs. The only exception is that -** if SQLite is unable to allocate memory to hold the [sqlite3] object, -** a NULL will be written into *ppDb instead of a pointer to the [sqlite3] -** object. If the database is opened (and/or created) successfully, then -** [SQLITE_OK] is returned. Otherwise an [error code] is returned. The -** [sqlite3_errmsg()] or [sqlite3_errmsg16()] routines can be used to obtain +** These routines open an SQLite database file whose name +** is given by the filename argument. +** The filename argument is interpreted as UTF-8 +** for [sqlite3_open()] and [sqlite3_open_v2()] and as UTF-16 +** in the native byte order for [sqlite3_open16()]. +** An [sqlite3*] handle is usually returned in *ppDb, even +** if an error occurs. The only exception is if SQLite is unable +** to allocate memory to hold the [sqlite3] object, a NULL will +** be written into *ppDb instead of a pointer to the [sqlite3] object. +** If the database is opened (and/or created) +** successfully, then [SQLITE_OK] is returned. Otherwise an +** error code is returned. The +** [sqlite3_errmsg()] or [sqlite3_errmsg16()] routines can be used to obtain ** an English language description of the error. ** ** The default encoding for the database will be UTF-8 if -** sqlite3_open() or sqlite3_open_v2() is called and -** UTF-16 in the native byte order if sqlite3_open16() is used. +** [sqlite3_open()] or [sqlite3_open_v2()] is called and +** UTF-16 in the native byte order if [sqlite3_open16()] is used. ** ** Whether or not an error occurs when it is opened, resources -** associated with the [database connection] handle should be released by -** passing it to [sqlite3_close()] when it is no longer required. +** associated with the [sqlite3*] handle should be released by passing it +** to [sqlite3_close()] when it is no longer required. ** -** The sqlite3_open_v2() interface works like sqlite3_open() -** except that it accepts two additional parameters for additional control -** over the new database connection. The flags parameter can take one of -** the following three values, optionally combined with the -** [SQLITE_OPEN_NOMUTEX] or [SQLITE_OPEN_FULLMUTEX] flags: +** The [sqlite3_open_v2()] interface works like [sqlite3_open()] +** except that it acccepts two additional parameters for additional control +** over the new database connection. The flags parameter can be +** one of: ** -**
      -**
      [SQLITE_OPEN_READONLY]
      -**
      The database is opened in read-only mode. If the database does not -** already exist, an error is returned.
      +**
        +**
      1. [SQLITE_OPEN_READONLY] +**
      2. [SQLITE_OPEN_READWRITE] +**
      3. [SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE] +**
      ** -**
      [SQLITE_OPEN_READWRITE]
      -**
      The database is opened for reading and writing if possible, or reading -** only if the file is write protected by the operating system. In either -** case the database must already exist, otherwise an error is returned.
      +** The first value opens the database read-only. +** If the database does not previously exist, an error is returned. +** The second option opens +** the database for reading and writing if possible, or reading only if +** if the file is write protected. In either case the database +** must already exist or an error is returned. The third option +** opens the database for reading and writing and creates it if it does +** not already exist. +** The third options is behavior that is always used for [sqlite3_open()] +** and [sqlite3_open16()]. ** -**
      [SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]
      -**
      The database is opened for reading and writing, and is creates it if -** it does not already exist. This is the behavior that is always used for -** sqlite3_open() and sqlite3_open16().
      -**
      +** If the 3rd parameter to [sqlite3_open_v2()] is not one of the +** combinations shown above then the behavior is undefined. ** -** If the 3rd parameter to sqlite3_open_v2() is not one of the -** combinations shown above or one of the combinations shown above combined -** with the [SQLITE_OPEN_NOMUTEX] or [SQLITE_OPEN_FULLMUTEX] flags, -** then the behavior is undefined. +** If the filename is ":memory:", then an private +** in-memory database is created for the connection. This in-memory +** database will vanish when the database connection is closed. Future +** version of SQLite might make use of additional special filenames +** that begin with the ":" character. It is recommended that +** when a database filename really does begin with +** ":" that you prefix the filename with a pathname like "./" to +** avoid ambiguity. ** -** If the [SQLITE_OPEN_NOMUTEX] flag is set, then the database connection -** opens in the multi-thread [threading mode] as long as the single-thread -** mode has not been set at compile-time or start-time. If the -** [SQLITE_OPEN_FULLMUTEX] flag is set then the database connection opens -** in the serialized [threading mode] unless single-thread was -** previously selected at compile-time or start-time. -** -** If the filename is ":memory:", then a private, temporary in-memory database -** is created for the connection. This in-memory database will vanish when -** the database connection is closed. Future versions of SQLite might -** make use of additional special filenames that begin with the ":" character. -** It is recommended that when a database filename actually does begin with -** a ":" character you should prefix the filename with a pathname such as -** "./" to avoid ambiguity. -** -** If the filename is an empty string, then a private, temporary +** If the filename is an empty string, then a private temporary ** on-disk database will be created. This private database will be ** automatically deleted as soon as the database connection is closed. ** ** The fourth parameter to sqlite3_open_v2() is the name of the -** [sqlite3_vfs] object that defines the operating system interface that -** the new database connection should use. If the fourth parameter is -** a NULL pointer then the default [sqlite3_vfs] object is used. +** [sqlite3_vfs] object that defines the operating system +** interface that the new database connection should use. If the +** fourth parameter is a NULL pointer then the default [sqlite3_vfs] +** object is used. ** -** Note to Windows users: The encoding used for the filename argument -** of sqlite3_open() and sqlite3_open_v2() must be UTF-8, not whatever +** Note to windows users: The encoding used for the filename argument +** of [sqlite3_open()] and [sqlite3_open_v2()] must be UTF-8, not whatever ** codepage is currently defined. Filenames containing international ** characters must be converted to UTF-8 prior to passing them into -** sqlite3_open() or sqlite3_open_v2(). +** [sqlite3_open()] or [sqlite3_open_v2()]. ** ** INVARIANTS: ** -** {H12701} The [sqlite3_open()], [sqlite3_open16()], and +** {F12701} The [sqlite3_open()], [sqlite3_open16()], and ** [sqlite3_open_v2()] interfaces create a new ** [database connection] associated with ** the database file given in their first parameter. ** -** {H12702} The filename argument is interpreted as UTF-8 +** {F12702} The filename argument is interpreted as UTF-8 ** for [sqlite3_open()] and [sqlite3_open_v2()] and as UTF-16 ** in the native byte order for [sqlite3_open16()]. ** -** {H12703} A successful invocation of [sqlite3_open()], [sqlite3_open16()], +** {F12703} A successful invocation of [sqlite3_open()], [sqlite3_open16()], ** or [sqlite3_open_v2()] writes a pointer to a new ** [database connection] into *ppDb. ** -** {H12704} The [sqlite3_open()], [sqlite3_open16()], and +** {F12704} The [sqlite3_open()], [sqlite3_open16()], and ** [sqlite3_open_v2()] interfaces return [SQLITE_OK] upon success, ** or an appropriate [error code] on failure. ** -** {H12706} The default text encoding for a new database created using +** {F12706} The default text encoding for a new database created using ** [sqlite3_open()] or [sqlite3_open_v2()] will be UTF-8. ** -** {H12707} The default text encoding for a new database created using +** {F12707} The default text encoding for a new database created using ** [sqlite3_open16()] will be UTF-16. ** -** {H12709} The [sqlite3_open(F,D)] interface is equivalent to +** {F12709} The [sqlite3_open(F,D)] interface is equivalent to ** [sqlite3_open_v2(F,D,G,0)] where the G parameter is ** [SQLITE_OPEN_READWRITE]|[SQLITE_OPEN_CREATE]. ** -** {H12711} If the G parameter to [sqlite3_open_v2(F,D,G,V)] contains the +** {F12711} If the G parameter to [sqlite3_open_v2(F,D,G,V)] contains the ** bit value [SQLITE_OPEN_READONLY] then the database is opened ** for reading only. ** -** {H12712} If the G parameter to [sqlite3_open_v2(F,D,G,V)] contains the +** {F12712} If the G parameter to [sqlite3_open_v2(F,D,G,V)] contains the ** bit value [SQLITE_OPEN_READWRITE] then the database is opened ** reading and writing if possible, or for reading only if the ** file is write protected by the operating system. ** -** {H12713} If the G parameter to [sqlite3_open_v2(F,D,G,V)] omits the +** {F12713} If the G parameter to [sqlite3_open(v2(F,D,G,V)] omits the ** bit value [SQLITE_OPEN_CREATE] and the database does not ** previously exist, an error is returned. ** -** {H12714} If the G parameter to [sqlite3_open_v2(F,D,G,V)] contains the +** {F12714} If the G parameter to [sqlite3_open(v2(F,D,G,V)] contains the ** bit value [SQLITE_OPEN_CREATE] and the database does not ** previously exist, then an attempt is made to create and ** initialize the database. ** -** {H12717} If the filename argument to [sqlite3_open()], [sqlite3_open16()], +** {F12717} If the filename argument to [sqlite3_open()], [sqlite3_open16()], ** or [sqlite3_open_v2()] is ":memory:", then an private, ** ephemeral, in-memory database is created for the connection. ** Is SQLITE_OPEN_CREATE|SQLITE_OPEN_READWRITE required ** in sqlite3_open_v2()? ** -** {H12719} If the filename is NULL or an empty string, then a private, -** ephemeral on-disk database will be created. +** {F12719} If the filename is NULL or an empty string, then a private, +** ephermeral on-disk database will be created. ** Is SQLITE_OPEN_CREATE|SQLITE_OPEN_READWRITE required ** in sqlite3_open_v2()? ** -** {H12721} The [database connection] created by [sqlite3_open_v2(F,D,G,V)] -** will use the [sqlite3_vfs] object identified by the V parameter, -** or the default [sqlite3_vfs] object if V is a NULL pointer. -** -** {H12723} Two [database connections] will share a common cache if both were -** opened with the same VFS while [shared cache mode] was enabled and -** if both filenames compare equal using memcmp() after having been -** processed by the [sqlite3_vfs | xFullPathname] method of the VFS. +** {F12721} The [database connection] created by +** [sqlite3_open_v2(F,D,G,V)] will use the +** [sqlite3_vfs] object identified by the V parameter, or +** the default [sqlite3_vfs] object is V is a NULL pointer. */ int sqlite3_open( const char *filename, /* Database filename (UTF-8) */ @@ -2652,45 +2091,44 @@ int sqlite3_open_v2( ); /* -** CAPI3REF: Error Codes And Messages {H12800} +** CAPI3REF: Error Codes And Messages {F12800} ** -** The sqlite3_errcode() interface returns the numeric [result code] or -** [extended result code] for the most recent failed sqlite3_* API call -** associated with a [database connection]. If a prior API call failed -** but the most recent API call succeeded, the return value from -** sqlite3_errcode() is undefined. +** The sqlite3_errcode() interface returns the numeric +** [SQLITE_OK | result code] or [SQLITE_IOERR_READ | extended result code] +** for the most recent failed sqlite3_* API call associated +** with [sqlite3] handle 'db'. If a prior API call failed but the +** most recent API call succeeded, the return value from sqlite3_errcode() +** is undefined. ** ** The sqlite3_errmsg() and sqlite3_errmsg16() return English-language -** text that describes the error, as either UTF-8 or UTF-16 respectively. +** text that describes the error, as either UTF8 or UTF16 respectively. ** Memory to hold the error message string is managed internally. -** The application does not need to worry about freeing the result. +** The application does not need to worry with freeing the result. ** However, the error string might be overwritten or deallocated by ** subsequent calls to other SQLite interface functions. ** -** If an interface fails with SQLITE_MISUSE, that means the interface -** was invoked incorrectly by the application. In that case, the -** error code and message may or may not be set. -** ** INVARIANTS: ** -** {H12801} The [sqlite3_errcode(D)] interface returns the numeric -** [result code] or [extended result code] for the most recently -** failed interface call associated with the [database connection] D. +** {F12801} The [sqlite3_errcode(D)] interface returns the numeric +** [SQLITE_OK | result code] or +** [SQLITE_IOERR_READ | extended result code] +** for the most recently failed interface call associated +** with [database connection] D. ** -** {H12803} The [sqlite3_errmsg(D)] and [sqlite3_errmsg16(D)] +** {F12803} The [sqlite3_errmsg(D)] and [sqlite3_errmsg16(D)] ** interfaces return English-language text that describes ** the error in the mostly recently failed interface call, -** encoded as either UTF-8 or UTF-16 respectively. +** encoded as either UTF8 or UTF16 respectively. ** -** {H12807} The strings returned by [sqlite3_errmsg()] and [sqlite3_errmsg16()] +** {F12807} The strings returned by [sqlite3_errmsg()] and [sqlite3_errmsg16()] ** are valid until the next SQLite interface call. ** -** {H12808} Calls to API routines that do not return an error code +** {F12808} Calls to API routines that do not return an error code ** (example: [sqlite3_data_count()]) do not ** change the error code or message returned by ** [sqlite3_errcode()], [sqlite3_errmsg()], or [sqlite3_errmsg16()]. ** -** {H12809} Interfaces that are not associated with a specific +** {F12809} Interfaces that are not associated with a specific ** [database connection] (examples: ** [sqlite3_mprintf()] or [sqlite3_enable_shared_cache()] ** do not change the values returned by @@ -2701,20 +2139,20 @@ const char *sqlite3_errmsg(sqlite3*); const void *sqlite3_errmsg16(sqlite3*); /* -** CAPI3REF: SQL Statement Object {H13000} +** CAPI3REF: SQL Statement Object {F13000} ** KEYWORDS: {prepared statement} {prepared statements} ** -** An instance of this object represents a single SQL statement. -** This object is variously known as a "prepared statement" or a +** An instance of this object represent single SQL statements. This +** object is variously known as a "prepared statement" or a ** "compiled SQL statement" or simply as a "statement". -** +** ** The life of a statement object goes something like this: ** **
        **
      1. Create the object using [sqlite3_prepare_v2()] or a related ** function. -**
      2. Bind values to [host parameters] using the sqlite3_bind_*() -** interfaces. +**
      3. Bind values to host parameters using +** [sqlite3_bind_blob | sqlite3_bind_* interfaces]. **
      4. Run the SQL by calling [sqlite3_step()] one or more times. **
      5. Reset the statement using [sqlite3_reset()] then go back ** to step 2. Do this zero or more times. @@ -2727,7 +2165,7 @@ const void *sqlite3_errmsg16(sqlite3*); typedef struct sqlite3_stmt sqlite3_stmt; /* -** CAPI3REF: Run-time Limits {H12760} +** CAPI3REF: Run-time Limits {F12760} ** ** This interface allows the size of various constructs to be limited ** on a connection by connection basis. The first parameter is the @@ -2738,7 +2176,7 @@ typedef struct sqlite3_stmt sqlite3_stmt; ** ** If the new limit is a negative number, the limit is unchanged. ** For the limit category of SQLITE_LIMIT_XYZ there is a hard upper -** bound set by a compile-time C preprocessor macro named SQLITE_MAX_XYZ. +** bound set by a compile-time C-preprocess macro named SQLITE_MAX_XYZ. ** (The "_LIMIT_" in the name is changed to "_MAX_".) ** Attempts to increase a limit above its hard upper bound are ** silently truncated to the hard upper limit. @@ -2747,44 +2185,47 @@ typedef struct sqlite3_stmt sqlite3_stmt; ** both their own internal database and also databases that are controlled ** by untrusted external sources. An example application might be a ** webbrowser that has its own databases for storing history and -** separate databases controlled by JavaScript applications downloaded -** off the Internet. The internal databases can be given the +** separate databases controlled by javascript applications downloaded +** off the internet. The internal databases can be given the ** large, default limits. Databases managed by external sources can ** be given much smaller limits designed to prevent a denial of service -** attack. Developers might also want to use the [sqlite3_set_authorizer()] +** attach. Developers might also want to use the [sqlite3_set_authorizer()] ** interface to further control untrusted SQL. The size of the database ** created by an untrusted script can be contained using the ** [max_page_count] [PRAGMA]. ** -** New run-time limit categories may be added in future releases. +** This interface is currently considered experimental and is subject +** to change or removal without prior notice. ** ** INVARIANTS: ** -** {H12762} A successful call to [sqlite3_limit(D,C,V)] where V is -** positive changes the limit on the size of construct C in the -** [database connection] D to the lesser of V and the hard upper -** bound on the size of C that is set at compile-time. +** {F12762} A successful call to [sqlite3_limit(D,C,V)] where V is +** positive changes the +** limit on the size of construct C in [database connection] D +** to the lessor of V and the hard upper bound on the size +** of C that is set at compile-time. ** -** {H12766} A successful call to [sqlite3_limit(D,C,V)] where V is negative -** leaves the state of the [database connection] D unchanged. +** {F12766} A successful call to [sqlite3_limit(D,C,V)] where V is negative +** leaves the state of [database connection] D unchanged. ** -** {H12769} A successful call to [sqlite3_limit(D,C,V)] returns the -** value of the limit on the size of construct C in the -** [database connection] D as it was prior to the call. +** {F12769} A successful call to [sqlite3_limit(D,C,V)] returns the +** value of the limit on the size of construct C in +** in [database connection] D as it was prior to the call. */ int sqlite3_limit(sqlite3*, int id, int newVal); /* -** CAPI3REF: Run-Time Limit Categories {H12790} +** CAPI3REF: Run-Time Limit Categories {F12790} ** KEYWORDS: {limit category} {limit categories} -** +** ** These constants define various aspects of a [database connection] ** that can be limited in size by calls to [sqlite3_limit()]. ** The meanings of the various limits are as follows: ** **
        **
        SQLITE_LIMIT_LENGTH
        -**
        The maximum size of any string or BLOB or table row.
        +**
        The maximum size of any +** string or blob or table row.
        ** **
        SQLITE_LIMIT_SQL_LENGTH
        **
        The maximum length of an SQL statement.
        @@ -2831,50 +2272,52 @@ int sqlite3_limit(sqlite3*, int id, int newVal); #define SQLITE_LIMIT_VARIABLE_NUMBER 9 /* -** CAPI3REF: Compiling An SQL Statement {H13010} -** KEYWORDS: {SQL statement compiler} +** CAPI3REF: Compiling An SQL Statement {F13010} ** ** To execute an SQL query, it must first be compiled into a byte-code -** program using one of these routines. +** program using one of these routines. ** -** The first argument, "db", is a [database connection] obtained from a -** prior call to [sqlite3_open()], [sqlite3_open_v2()] or [sqlite3_open16()]. -** -** The second argument, "zSql", is the statement to be compiled, encoded +** The first argument "db" is an [database connection] +** obtained from a prior call to [sqlite3_open()], [sqlite3_open_v2()] +** or [sqlite3_open16()]. +** The second argument "zSql" is the statement to be compiled, encoded ** as either UTF-8 or UTF-16. The sqlite3_prepare() and sqlite3_prepare_v2() -** interfaces use UTF-8, and sqlite3_prepare16() and sqlite3_prepare16_v2() -** use UTF-16. +** interfaces uses UTF-8 and sqlite3_prepare16() and sqlite3_prepare16_v2() +** use UTF-16. {END} ** -** If the nByte argument is less than zero, then zSql is read up to the -** first zero terminator. If nByte is non-negative, then it is the maximum -** number of bytes read from zSql. When nByte is non-negative, the -** zSql string ends at either the first '\000' or '\u0000' character or +** If the nByte argument is less +** than zero, then zSql is read up to the first zero terminator. +** If nByte is non-negative, then it is the maximum number of +** bytes read from zSql. When nByte is non-negative, the +** zSql string ends at either the first '\000' or '\u0000' character or ** the nByte-th byte, whichever comes first. If the caller knows ** that the supplied string is nul-terminated, then there is a small -** performance advantage to be gained by passing an nByte parameter that -** is equal to the number of bytes in the input string including -** the nul-terminator bytes. +** performance advantage to be had by passing an nByte parameter that +** is equal to the number of bytes in the input string including +** the nul-terminator bytes.{END} ** ** *pzTail is made to point to the first byte past the end of the -** first SQL statement in zSql. These routines only compile the first +** first SQL statement in zSql. These routines only compiles the first ** statement in zSql, so *pzTail is left pointing to what remains ** uncompiled. ** ** *ppStmt is left pointing to a compiled [prepared statement] that can be -** executed using [sqlite3_step()]. If there is an error, *ppStmt is set -** to NULL. If the input text contains no SQL (if the input is an empty -** string or a comment) then *ppStmt is set to NULL. -** {A13018} The calling procedure is responsible for deleting the compiled -** SQL statement using [sqlite3_finalize()] after it has finished with it. +** executed using [sqlite3_step()]. Or if there is an error, *ppStmt is +** set to NULL. If the input text contains no SQL (if the input +** is and empty string or a comment) then *ppStmt is set to NULL. +** {U13018} The calling procedure is responsible for deleting the +** compiled SQL statement +** using [sqlite3_finalize()] after it has finished with it. ** -** On success, [SQLITE_OK] is returned, otherwise an [error code] is returned. +** On success, [SQLITE_OK] is returned. Otherwise an +** [error code] is returned. ** ** The sqlite3_prepare_v2() and sqlite3_prepare16_v2() interfaces are ** recommended for all new programs. The two older interfaces are retained ** for backwards compatibility, but their use is discouraged. ** In the "v2" interfaces, the prepared statement -** that is returned (the [sqlite3_stmt] object) contains a copy of the -** original SQL text. This causes the [sqlite3_step()] interface to +** that is returned (the [sqlite3_stmt] object) contains a copy of the +** original SQL text. {END} This causes the [sqlite3_step()] interface to ** behave a differently in two ways: ** **
          @@ -2883,57 +2326,60 @@ int sqlite3_limit(sqlite3*, int id, int newVal); ** always used to do, [sqlite3_step()] will automatically recompile the SQL ** statement and try to run it again. If the schema has changed in ** a way that makes the statement no longer valid, [sqlite3_step()] will still -** return [SQLITE_SCHEMA]. But unlike the legacy behavior, [SQLITE_SCHEMA] is -** now a fatal error. Calling [sqlite3_prepare_v2()] again will not make the +** return [SQLITE_SCHEMA]. But unlike the legacy behavior, +** [SQLITE_SCHEMA] is now a fatal error. Calling +** [sqlite3_prepare_v2()] again will not make the ** error go away. Note: use [sqlite3_errmsg()] to find the text -** of the parsing error that results in an [SQLITE_SCHEMA] return. +** of the parsing error that results in an [SQLITE_SCHEMA] return. {END} ** ** **
        1. -** When an error occurs, [sqlite3_step()] will return one of the detailed -** [error codes] or [extended error codes]. The legacy behavior was that -** [sqlite3_step()] would only return a generic [SQLITE_ERROR] result code -** and you would have to make a second call to [sqlite3_reset()] in order -** to find the underlying cause of the problem. With the "v2" prepare -** interfaces, the underlying reason for the error is returned immediately. +** When an error occurs, +** [sqlite3_step()] will return one of the detailed +** [error codes] or [extended error codes]. +** The legacy behavior was that [sqlite3_step()] would only return a generic +** [SQLITE_ERROR] result code and you would have to make a second call to +** [sqlite3_reset()] in order to find the underlying cause of the problem. +** With the "v2" prepare interfaces, the underlying reason for the error is +** returned immediately. **
        2. **
        ** ** INVARIANTS: ** -** {H13011} The [sqlite3_prepare(db,zSql,...)] and +** {F13011} The [sqlite3_prepare(db,zSql,...)] and ** [sqlite3_prepare_v2(db,zSql,...)] interfaces interpret the ** text in their zSql parameter as UTF-8. ** -** {H13012} The [sqlite3_prepare16(db,zSql,...)] and +** {F13012} The [sqlite3_prepare16(db,zSql,...)] and ** [sqlite3_prepare16_v2(db,zSql,...)] interfaces interpret the ** text in their zSql parameter as UTF-16 in the native byte order. ** -** {H13013} If the nByte argument to [sqlite3_prepare_v2(db,zSql,nByte,...)] -** and its variants is less than zero, the SQL text is +** {F13013} If the nByte argument to [sqlite3_prepare_v2(db,zSql,nByte,...)] +** and its variants is less than zero, then SQL text is ** read from zSql is read up to the first zero terminator. ** -** {H13014} If the nByte argument to [sqlite3_prepare_v2(db,zSql,nByte,...)] -** and its variants is non-negative, then at most nBytes bytes of +** {F13014} If the nByte argument to [sqlite3_prepare_v2(db,zSql,nByte,...)] +** and its variants is non-negative, then at most nBytes bytes ** SQL text is read from zSql. ** -** {H13015} In [sqlite3_prepare_v2(db,zSql,N,P,pzTail)] and its variants +** {F13015} In [sqlite3_prepare_v2(db,zSql,N,P,pzTail)] and its variants ** if the zSql input text contains more than one SQL statement ** and pzTail is not NULL, then *pzTail is made to point to the ** first byte past the end of the first SQL statement in zSql. ** What does *pzTail point to if there is one statement? ** -** {H13016} A successful call to [sqlite3_prepare_v2(db,zSql,N,ppStmt,...)] +** {F13016} A successful call to [sqlite3_prepare_v2(db,zSql,N,ppStmt,...)] ** or one of its variants writes into *ppStmt a pointer to a new -** [prepared statement] or a pointer to NULL if zSql contains -** nothing other than whitespace or comments. +** [prepared statement] or a pointer to NULL +** if zSql contains nothing other than whitespace or comments. ** -** {H13019} The [sqlite3_prepare_v2()] interface and its variants return +** {F13019} The [sqlite3_prepare_v2()] interface and its variants return ** [SQLITE_OK] or an appropriate [error code] upon failure. ** -** {H13021} Before [sqlite3_prepare(db,zSql,nByte,ppStmt,pzTail)] or its -** variants returns an error (any value other than [SQLITE_OK]), -** they first set *ppStmt to NULL. +** {F13021} Before [sqlite3_prepare(db,zSql,nByte,ppStmt,pzTail)] or its +** variants returns an error (any value other than [SQLITE_OK]) +** it first sets *ppStmt to NULL. */ int sqlite3_prepare( sqlite3 *db, /* Database handle */ @@ -2965,89 +2411,85 @@ int sqlite3_prepare16_v2( ); /* -** CAPI3REF: Retrieving Statement SQL {H13100} +** CAPIREF: Retrieving Statement SQL {F13100} ** -** This interface can be used to retrieve a saved copy of the original -** SQL text used to create a [prepared statement] if that statement was -** compiled using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()]. +** This intereface can be used to retrieve a saved copy of the original +** SQL text used to create a [prepared statement]. ** ** INVARIANTS: ** -** {H13101} If the [prepared statement] passed as the argument to -** [sqlite3_sql()] was compiled using either [sqlite3_prepare_v2()] or -** [sqlite3_prepare16_v2()], then [sqlite3_sql()] returns -** a pointer to a zero-terminated string containing a UTF-8 rendering +** {F13101} If the [prepared statement] passed as +** the an argument to [sqlite3_sql()] was compiled +** compiled using either [sqlite3_prepare_v2()] or +** [sqlite3_prepare16_v2()], +** then [sqlite3_sql()] function returns a pointer to a +** zero-terminated string containing a UTF-8 rendering ** of the original SQL statement. ** -** {H13102} If the [prepared statement] passed as the argument to -** [sqlite3_sql()] was compiled using either [sqlite3_prepare()] or -** [sqlite3_prepare16()], then [sqlite3_sql()] returns a NULL pointer. +** {F13102} If the [prepared statement] passed as +** the an argument to [sqlite3_sql()] was compiled +** compiled using either [sqlite3_prepare()] or +** [sqlite3_prepare16()], +** then [sqlite3_sql()] function returns a NULL pointer. ** -** {H13103} The string returned by [sqlite3_sql(S)] is valid until the +** {F13103} The string returned by [sqlite3_sql(S)] is valid until the ** [prepared statement] S is deleted using [sqlite3_finalize(S)]. */ const char *sqlite3_sql(sqlite3_stmt *pStmt); /* -** CAPI3REF: Dynamically Typed Value Object {H15000} +** CAPI3REF: Dynamically Typed Value Object {F15000} ** KEYWORDS: {protected sqlite3_value} {unprotected sqlite3_value} ** ** SQLite uses the sqlite3_value object to represent all values -** that can be stored in a database table. SQLite uses dynamic typing -** for the values it stores. Values stored in sqlite3_value objects -** can be integers, floating point values, strings, BLOBs, or NULL. +** that can be stored in a database table. +** SQLite uses dynamic typing for the values it stores. +** Values stored in sqlite3_value objects can be +** be integers, floating point values, strings, BLOBs, or NULL. ** ** An sqlite3_value object may be either "protected" or "unprotected". ** Some interfaces require a protected sqlite3_value. Other interfaces ** will accept either a protected or an unprotected sqlite3_value. -** Every interface that accepts sqlite3_value arguments specifies +** Every interface that accepts sqlite3_value arguments specifies ** whether or not it requires a protected sqlite3_value. ** ** The terms "protected" and "unprotected" refer to whether or not ** a mutex is held. A internal mutex is held for a protected ** sqlite3_value object but no mutex is held for an unprotected ** sqlite3_value object. If SQLite is compiled to be single-threaded -** (with [SQLITE_THREADSAFE=0] and with [sqlite3_threadsafe()] returning 0) -** or if SQLite is run in one of reduced mutex modes -** [SQLITE_CONFIG_SINGLETHREAD] or [SQLITE_CONFIG_MULTITHREAD] -** then there is no distinction between protected and unprotected -** sqlite3_value objects and they can be used interchangeably. However, -** for maximum code portability it is recommended that applications -** still make the distinction between between protected and unprotected -** sqlite3_value objects even when not strictly required. +** (with SQLITE_THREADSAFE=0 and with [sqlite3_threadsafe()] returning 0) +** then there is no distinction between +** protected and unprotected sqlite3_value objects and they can be +** used interchangable. However, for maximum code portability it +** is recommended that applications make the distinction between +** between protected and unprotected sqlite3_value objects even if +** they are single threaded. ** ** The sqlite3_value objects that are passed as parameters into the -** implementation of [application-defined SQL functions] are protected. +** implementation of application-defined SQL functions are protected. ** The sqlite3_value object returned by ** [sqlite3_column_value()] is unprotected. ** Unprotected sqlite3_value objects may only be used with -** [sqlite3_result_value()] and [sqlite3_bind_value()]. -** The [sqlite3_value_blob | sqlite3_value_type()] family of -** interfaces require protected sqlite3_value objects. +** [sqlite3_result_value()] and [sqlite3_bind_value()]. All other +** interfaces that use sqlite3_value require protected sqlite3_value objects. */ typedef struct Mem sqlite3_value; /* -** CAPI3REF: SQL Function Context Object {H16001} +** CAPI3REF: SQL Function Context Object {F16001} ** ** The context in which an SQL function executes is stored in an -** sqlite3_context object. A pointer to an sqlite3_context object -** is always first parameter to [application-defined SQL functions]. -** The application-defined SQL function implementation will pass this -** pointer through into calls to [sqlite3_result_int | sqlite3_result()], -** [sqlite3_aggregate_context()], [sqlite3_user_data()], -** [sqlite3_context_db_handle()], [sqlite3_get_auxdata()], -** and/or [sqlite3_set_auxdata()]. +** sqlite3_context object. A pointer to an sqlite3_context +** object is always first parameter to application-defined SQL functions. */ typedef struct sqlite3_context sqlite3_context; /* -** CAPI3REF: Binding Values To Prepared Statements {H13500} -** KEYWORDS: {host parameter} {host parameters} {host parameter name} -** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding} +** CAPI3REF: Binding Values To Prepared Statements {F13500} ** -** In the SQL strings input to [sqlite3_prepare_v2()] and its variants, -** literals may be replaced by a parameter in one of these forms: +** In the SQL strings input to [sqlite3_prepare_v2()] and its +** variants, literals may be replace by a parameter in one +** of these forms: ** **
          **
        • ? @@ -3058,31 +2500,32 @@ typedef struct sqlite3_context sqlite3_context; **
        ** ** In the parameter forms shown above NNN is an integer literal, -** and VVV is an alpha-numeric parameter name. The values of these -** parameters (also called "host parameter names" or "SQL parameters") +** VVV alpha-numeric parameter name. +** The values of these parameters (also called "host parameter names" +** or "SQL parameters") ** can be set using the sqlite3_bind_*() routines defined here. ** -** The first argument to the sqlite3_bind_*() routines is always -** a pointer to the [sqlite3_stmt] object returned from -** [sqlite3_prepare_v2()] or its variants. -** -** The second argument is the index of the SQL parameter to be set. -** The leftmost SQL parameter has an index of 1. When the same named -** SQL parameter is used more than once, second and subsequent -** occurrences have the same index as the first occurrence. +** The first argument to the sqlite3_bind_*() routines always +** is a pointer to the [sqlite3_stmt] object returned from +** [sqlite3_prepare_v2()] or its variants. The second +** argument is the index of the parameter to be set. The +** first parameter has an index of 1. When the same named +** parameter is used more than once, second and subsequent +** occurrences have the same index as the first occurrence. ** The index for named parameters can be looked up using the -** [sqlite3_bind_parameter_index()] API if desired. The index +** [sqlite3_bind_parameter_name()] API if desired. The index ** for "?NNN" parameters is the value of NNN. -** The NNN value must be between 1 and the [sqlite3_limit()] -** parameter [SQLITE_LIMIT_VARIABLE_NUMBER] (default value: 999). +** The NNN value must be between 1 and the compile-time +** parameter SQLITE_MAX_VARIABLE_NUMBER (default value: 999). ** ** The third argument is the value to bind to the parameter. ** -** In those routines that have a fourth argument, its value is the -** number of bytes in the parameter. To be clear: the value is the -** number of bytes in the value, not the number of characters. +** In those +** routines that have a fourth argument, its value is the number of bytes +** in the parameter. To be clear: the value is the number of bytes +** in the value, not the number of characters. ** If the fourth parameter is negative, the length of the string is -** the number of bytes up to the first zero terminator. +** number of bytes up to the first zero terminator. ** ** The fifth argument to sqlite3_bind_blob(), sqlite3_bind_text(), and ** sqlite3_bind_text16() is a destructor used to dispose of the BLOB or @@ -3094,12 +2537,12 @@ typedef struct sqlite3_context sqlite3_context; ** the sqlite3_bind_*() routine returns. ** ** The sqlite3_bind_zeroblob() routine binds a BLOB of length N that -** is filled with zeroes. A zeroblob uses a fixed amount of memory -** (just an integer to hold its size) while it is being processed. -** Zeroblobs are intended to serve as placeholders for BLOBs whose -** content is later written using -** [sqlite3_blob_open | incremental BLOB I/O] routines. -** A negative value for the zeroblob results in a zero-length BLOB. +** is filled with zeros. A zeroblob uses a fixed amount of memory +** (just an integer to hold it size) while it is being processed. +** Zeroblobs are intended to serve as place-holders for BLOBs whose +** content is later written using +** [sqlite3_blob_open | increment BLOB I/O] routines. A negative +** value for the zeroblob results in a zero-length BLOB. ** ** The sqlite3_bind_*() routines must be called after ** [sqlite3_prepare_v2()] (and its variants) or [sqlite3_reset()] and @@ -3109,7 +2552,7 @@ typedef struct sqlite3_context sqlite3_context; ** ** These routines return [SQLITE_OK] on success or an error code if ** anything goes wrong. [SQLITE_RANGE] is returned if the parameter -** index is out of range. [SQLITE_NOMEM] is returned if malloc() fails. +** index is out of range. [SQLITE_NOMEM] is returned if malloc fails. ** [SQLITE_MISUSE] might be returned if these routines are called on a ** virtual machine that is the wrong state or which has already been finalized. ** Detection of misuse is unreliable. Applications should not depend @@ -3118,79 +2561,79 @@ typedef struct sqlite3_context sqlite3_context; ** panic rather than return SQLITE_MISUSE. ** ** See also: [sqlite3_bind_parameter_count()], -** [sqlite3_bind_parameter_name()], and [sqlite3_bind_parameter_index()]. +** [sqlite3_bind_parameter_name()], and +** [sqlite3_bind_parameter_index()]. ** ** INVARIANTS: ** -** {H13506} The [SQL statement compiler] recognizes tokens of the forms -** "?", "?NNN", "$VVV", ":VVV", and "@VVV" as SQL parameters, -** where NNN is any sequence of one or more digits -** and where VVV is any sequence of one or more alphanumeric -** characters or "::" optionally followed by a string containing -** no spaces and contained within parentheses. +** {F13506} The [sqlite3_prepare | SQL statement compiler] recognizes +** tokens of the forms "?", "?NNN", "$VVV", ":VVV", and "@VVV" +** as SQL parameters, where NNN is any sequence of one or more +** digits and where VVV is any sequence of one or more +** alphanumeric characters or "::" optionally followed by +** a string containing no spaces and contained within parentheses. ** -** {H13509} The initial value of an SQL parameter is NULL. +** {F13509} The initial value of an SQL parameter is NULL. ** -** {H13512} The index of an "?" SQL parameter is one larger than the +** {F13512} The index of an "?" SQL parameter is one larger than the ** largest index of SQL parameter to the left, or 1 if ** the "?" is the leftmost SQL parameter. ** -** {H13515} The index of an "?NNN" SQL parameter is the integer NNN. +** {F13515} The index of an "?NNN" SQL parameter is the integer NNN. ** -** {H13518} The index of an ":VVV", "$VVV", or "@VVV" SQL parameter is -** the same as the index of leftmost occurrences of the same +** {F13518} The index of an ":VVV", "$VVV", or "@VVV" SQL parameter is +** the same as the index of leftmost occurances of the same ** parameter, or one more than the largest index over all -** parameters to the left if this is the first occurrence +** parameters to the left if this is the first occurrance ** of this parameter, or 1 if this is the leftmost parameter. ** -** {H13521} The [SQL statement compiler] fails with an [SQLITE_RANGE] -** error if the index of an SQL parameter is less than 1 -** or greater than the compile-time SQLITE_MAX_VARIABLE_NUMBER -** parameter. +** {F13521} The [sqlite3_prepare | SQL statement compiler] fail with +** an [SQLITE_RANGE] error if the index of an SQL parameter +** is less than 1 or greater than SQLITE_MAX_VARIABLE_NUMBER. ** -** {H13524} Calls to [sqlite3_bind_text | sqlite3_bind(S,N,V,...)] +** {F13524} Calls to [sqlite3_bind_text | sqlite3_bind(S,N,V,...)] ** associate the value V with all SQL parameters having an ** index of N in the [prepared statement] S. ** -** {H13527} Calls to [sqlite3_bind_text | sqlite3_bind(S,N,...)] +** {F13527} Calls to [sqlite3_bind_text | sqlite3_bind(S,N,...)] ** override prior calls with the same values of S and N. ** -** {H13530} Bindings established by [sqlite3_bind_text | sqlite3_bind(S,...)] +** {F13530} Bindings established by [sqlite3_bind_text | sqlite3_bind(S,...)] ** persist across calls to [sqlite3_reset(S)]. ** -** {H13533} In calls to [sqlite3_bind_blob(S,N,V,L,D)], +** {F13533} In calls to [sqlite3_bind_blob(S,N,V,L,D)], ** [sqlite3_bind_text(S,N,V,L,D)], or ** [sqlite3_bind_text16(S,N,V,L,D)] SQLite binds the first L -** bytes of the BLOB or string pointed to by V, when L +** bytes of the blob or string pointed to by V, when L ** is non-negative. ** -** {H13536} In calls to [sqlite3_bind_text(S,N,V,L,D)] or +** {F13536} In calls to [sqlite3_bind_text(S,N,V,L,D)] or ** [sqlite3_bind_text16(S,N,V,L,D)] SQLite binds characters ** from V through the first zero character when L is negative. ** -** {H13539} In calls to [sqlite3_bind_blob(S,N,V,L,D)], +** {F13539} In calls to [sqlite3_bind_blob(S,N,V,L,D)], ** [sqlite3_bind_text(S,N,V,L,D)], or ** [sqlite3_bind_text16(S,N,V,L,D)] when D is the special ** constant [SQLITE_STATIC], SQLite assumes that the value V ** is held in static unmanaged space that will not change ** during the lifetime of the binding. ** -** {H13542} In calls to [sqlite3_bind_blob(S,N,V,L,D)], +** {F13542} In calls to [sqlite3_bind_blob(S,N,V,L,D)], ** [sqlite3_bind_text(S,N,V,L,D)], or ** [sqlite3_bind_text16(S,N,V,L,D)] when D is the special -** constant [SQLITE_TRANSIENT], the routine makes a -** private copy of the value V before it returns. +** constant [SQLITE_TRANSIENT], the routine makes a +** private copy of V value before it returns. ** -** {H13545} In calls to [sqlite3_bind_blob(S,N,V,L,D)], +** {F13545} In calls to [sqlite3_bind_blob(S,N,V,L,D)], ** [sqlite3_bind_text(S,N,V,L,D)], or ** [sqlite3_bind_text16(S,N,V,L,D)] when D is a pointer to ** a function, SQLite invokes that function to destroy the -** value V after it has finished using the value V. +** V value after it has finished using the V value. ** -** {H13548} In calls to [sqlite3_bind_zeroblob(S,N,V,L)] the value bound -** is a BLOB of L bytes, or a zero-length BLOB if L is negative. +** {F13548} In calls to [sqlite3_bind_zeroblob(S,N,V,L)] the value bound +** is a blob of L bytes, or a zero-length blob if L is negative. ** -** {H13551} In calls to [sqlite3_bind_value(S,N,V)] the V argument may +** {F13551} In calls to [sqlite3_bind_value(S,N,V)] the V argument may ** be either a [protected sqlite3_value] object or an ** [unprotected sqlite3_value] object. */ @@ -3205,18 +2648,18 @@ int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*); int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n); /* -** CAPI3REF: Number Of SQL Parameters {H13600} +** CAPI3REF: Number Of SQL Parameters {F13600} ** -** This routine can be used to find the number of [SQL parameters] -** in a [prepared statement]. SQL parameters are tokens of the +** This routine can be used to find the number of SQL parameters +** in a prepared statement. SQL parameters are tokens of the ** form "?", "?NNN", ":AAA", "$AAA", or "@AAA" that serve as -** placeholders for values that are [sqlite3_bind_blob | bound] +** place-holders for values that are [sqlite3_bind_blob | bound] ** to the parameters at a later time. ** -** This routine actually returns the index of the largest (rightmost) -** parameter. For all forms except ?NNN, this will correspond to the -** number of unique parameters. If parameters of the ?NNN are used, -** there may be gaps in the list. +** This routine actually returns the index of the largest parameter. +** For all forms except ?NNN, this will correspond to the number of +** unique parameters. If parameters of the ?NNN are used, there may +** be gaps in the list. ** ** See also: [sqlite3_bind_blob|sqlite3_bind()], ** [sqlite3_bind_parameter_name()], and @@ -3224,30 +2667,30 @@ int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n); ** ** INVARIANTS: ** -** {H13601} The [sqlite3_bind_parameter_count(S)] interface returns +** {F13601} The [sqlite3_bind_parameter_count(S)] interface returns ** the largest index of all SQL parameters in the -** [prepared statement] S, or 0 if S contains no SQL parameters. +** [prepared statement] S, or 0 if S +** contains no SQL parameters. */ int sqlite3_bind_parameter_count(sqlite3_stmt*); /* -** CAPI3REF: Name Of A Host Parameter {H13620} +** CAPI3REF: Name Of A Host Parameter {F13620} ** ** This routine returns a pointer to the name of the n-th -** [SQL parameter] in a [prepared statement]. +** SQL parameter in a [prepared statement]. ** SQL parameters of the form "?NNN" or ":AAA" or "@AAA" or "$AAA" ** have a name which is the string "?NNN" or ":AAA" or "@AAA" or "$AAA" ** respectively. ** In other words, the initial ":" or "$" or "@" or "?" ** is included as part of the name. -** Parameters of the form "?" without a following integer have no name -** and are also referred to as "anonymous parameters". +** Parameters of the form "?" without a following integer have no name. ** ** The first host parameter has an index of 1, not 0. ** ** If the value n is out of range or if the n-th parameter is ** nameless, then NULL is returned. The returned string is -** always in UTF-8 encoding even if the named parameter was +** always in the UTF-8 encoding even if the named parameter was ** originally specified as UTF-16 in [sqlite3_prepare16()] or ** [sqlite3_prepare16_v2()]. ** @@ -3257,16 +2700,16 @@ int sqlite3_bind_parameter_count(sqlite3_stmt*); ** ** INVARIANTS: ** -** {H13621} The [sqlite3_bind_parameter_name(S,N)] interface returns +** {F13621} The [sqlite3_bind_parameter_name(S,N)] interface returns ** a UTF-8 rendering of the name of the SQL parameter in -** the [prepared statement] S having index N, or +** [prepared statement] S having index N, or ** NULL if there is no SQL parameter with index N or if the ** parameter with index N is an anonymous parameter "?". */ const char *sqlite3_bind_parameter_name(sqlite3_stmt*, int); /* -** CAPI3REF: Index Of A Parameter With A Given Name {H13640} +** CAPI3REF: Index Of A Parameter With A Given Name {F13640} ** ** Return the index of an SQL parameter given its name. The ** index value returned is suitable for use as the second @@ -3281,56 +2724,62 @@ const char *sqlite3_bind_parameter_name(sqlite3_stmt*, int); ** ** INVARIANTS: ** -** {H13641} The [sqlite3_bind_parameter_index(S,N)] interface returns -** the index of SQL parameter in the [prepared statement] +** {F13641} The [sqlite3_bind_parameter_index(S,N)] interface returns +** the index of SQL parameter in [prepared statement] ** S whose name matches the UTF-8 string N, or 0 if there is ** no match. */ int sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName); /* -** CAPI3REF: Reset All Bindings On A Prepared Statement {H13660} +** CAPI3REF: Reset All Bindings On A Prepared Statement {F13660} ** -** Contrary to the intuition of many, [sqlite3_reset()] does not reset -** the [sqlite3_bind_blob | bindings] on a [prepared statement]. -** Use this routine to reset all host parameters to NULL. +** Contrary to the intuition of many, [sqlite3_reset()] does not +** reset the [sqlite3_bind_blob | bindings] on a +** [prepared statement]. Use this routine to +** reset all host parameters to NULL. ** ** INVARIANTS: ** -** {H13661} The [sqlite3_clear_bindings(S)] interface resets all SQL -** parameter bindings in the [prepared statement] S back to NULL. +** {F13661} The [sqlite3_clear_bindings(S)] interface resets all +** SQL parameter bindings in [prepared statement] S +** back to NULL. */ int sqlite3_clear_bindings(sqlite3_stmt*); /* -** CAPI3REF: Number Of Columns In A Result Set {H13710} +** CAPI3REF: Number Of Columns In A Result Set {F13710} ** -** Return the number of columns in the result set returned by the -** [prepared statement]. This routine returns 0 if pStmt is an SQL -** statement that does not return data (for example an [UPDATE]). +** Return the number of columns in the result set returned by the +** [prepared statement]. This routine returns 0 +** if pStmt is an SQL statement that does not return data (for +** example an UPDATE). ** ** INVARIANTS: ** -** {H13711} The [sqlite3_column_count(S)] interface returns the number of -** columns in the result set generated by the [prepared statement] S, -** or 0 if S does not generate a result set. +** {F13711} The [sqlite3_column_count(S)] interface returns the number of +** columns in the result set generated by the +** [prepared statement] S, or 0 if S does not generate +** a result set. */ int sqlite3_column_count(sqlite3_stmt *pStmt); /* -** CAPI3REF: Column Names In A Result Set {H13720} +** CAPI3REF: Column Names In A Result Set {F13720} ** ** These routines return the name assigned to a particular column -** in the result set of a [SELECT] statement. The sqlite3_column_name() -** interface returns a pointer to a zero-terminated UTF-8 string +** in the result set of a SELECT statement. The sqlite3_column_name() +** interface returns a pointer to a zero-terminated UTF8 string ** and sqlite3_column_name16() returns a pointer to a zero-terminated -** UTF-16 string. The first parameter is the [prepared statement] -** that implements the [SELECT] statement. The second parameter is the -** column number. The leftmost column is number 0. +** UTF16 string. The first parameter is the +** [prepared statement] that implements the SELECT statement. +** The second parameter is the column number. The left-most column is +** number 0. ** -** The returned string pointer is valid until either the [prepared statement] -** is destroyed by [sqlite3_finalize()] or until the next call to -** sqlite3_column_name() or sqlite3_column_name16() on the same column. +** The returned string pointer is valid until either the +** [prepared statement] is destroyed by [sqlite3_finalize()] +** or until the next call sqlite3_column_name() or sqlite3_column_name16() +** on the same column. ** ** If sqlite3_malloc() fails during the processing of either routine ** (for example during a conversion from UTF-8 to UTF-16) then a @@ -3343,124 +2792,136 @@ int sqlite3_column_count(sqlite3_stmt *pStmt); ** ** INVARIANTS: ** -** {H13721} A successful invocation of the [sqlite3_column_name(S,N)] -** interface returns the name of the Nth column (where 0 is -** the leftmost column) for the result set of the -** [prepared statement] S as a zero-terminated UTF-8 string. +** {F13721} A successful invocation of the [sqlite3_column_name(S,N)] +** interface returns the name +** of the Nth column (where 0 is the left-most column) for the +** result set of [prepared statement] S as a +** zero-terminated UTF-8 string. ** -** {H13723} A successful invocation of the [sqlite3_column_name16(S,N)] -** interface returns the name of the Nth column (where 0 is -** the leftmost column) for the result set of the -** [prepared statement] S as a zero-terminated UTF-16 string -** in the native byte order. +** {F13723} A successful invocation of the [sqlite3_column_name16(S,N)] +** interface returns the name +** of the Nth column (where 0 is the left-most column) for the +** result set of [prepared statement] S as a +** zero-terminated UTF-16 string in the native byte order. ** -** {H13724} The [sqlite3_column_name()] and [sqlite3_column_name16()] +** {F13724} The [sqlite3_column_name()] and [sqlite3_column_name16()] ** interfaces return a NULL pointer if they are unable to -** allocate memory to hold their normal return strings. +** allocate memory memory to hold there normal return strings. ** -** {H13725} If the N parameter to [sqlite3_column_name(S,N)] or +** {F13725} If the N parameter to [sqlite3_column_name(S,N)] or ** [sqlite3_column_name16(S,N)] is out of range, then the -** interfaces return a NULL pointer. -** -** {H13726} The strings returned by [sqlite3_column_name(S,N)] and +** interfaces returns a NULL pointer. +** +** {F13726} The strings returned by [sqlite3_column_name(S,N)] and ** [sqlite3_column_name16(S,N)] are valid until the next ** call to either routine with the same S and N parameters ** or until [sqlite3_finalize(S)] is called. ** -** {H13727} When a result column of a [SELECT] statement contains -** an AS clause, the name of that column is the identifier +** {F13727} When a result column of a [SELECT] statement contains +** an AS clause, the name of that column is the indentifier ** to the right of the AS keyword. */ const char *sqlite3_column_name(sqlite3_stmt*, int N); const void *sqlite3_column_name16(sqlite3_stmt*, int N); /* -** CAPI3REF: Source Of Data In A Query Result {H13740} +** CAPI3REF: Source Of Data In A Query Result {F13740} ** ** These routines provide a means to determine what column of what -** table in which database a result of a [SELECT] statement comes from. +** table in which database a result of a SELECT statement comes from. ** The name of the database or table or column can be returned as -** either a UTF-8 or UTF-16 string. The _database_ routines return +** either a UTF8 or UTF16 string. The _database_ routines return ** the database name, the _table_ routines return the table name, and ** the origin_ routines return the column name. -** The returned string is valid until the [prepared statement] is destroyed -** using [sqlite3_finalize()] or until the same information is requested +** The returned string is valid until +** the [prepared statement] is destroyed using +** [sqlite3_finalize()] or until the same information is requested ** again in a different encoding. ** ** The names returned are the original un-aliased names of the ** database, table, and column. ** ** The first argument to the following calls is a [prepared statement]. -** These functions return information about the Nth column returned by +** These functions return information about the Nth column returned by ** the statement, where N is the second function argument. ** -** If the Nth column returned by the statement is an expression or -** subquery and is not a column value, then all of these functions return -** NULL. These routine might also return NULL if a memory allocation error -** occurs. Otherwise, they return the name of the attached database, table -** and column that query result column was extracted from. +** If the Nth column returned by the statement is an expression +** or subquery and is not a column value, then all of these functions +** return NULL. These routine might also return NULL if a memory +** allocation error occurs. Otherwise, they return the +** name of the attached database, table and column that query result +** column was extracted from. ** ** As with all other SQLite APIs, those postfixed with "16" return ** UTF-16 encoded strings, the other functions return UTF-8. {END} ** -** These APIs are only available if the library was compiled with the -** [SQLITE_ENABLE_COLUMN_METADATA] C-preprocessor symbol defined. +** These APIs are only available if the library was compiled with the +** SQLITE_ENABLE_COLUMN_METADATA preprocessor symbol defined. ** -** {A13751} +** {U13751} ** If two or more threads call one or more of these routines against the same ** prepared statement and column at the same time then the results are ** undefined. ** ** INVARIANTS: ** -** {H13741} The [sqlite3_column_database_name(S,N)] interface returns either -** the UTF-8 zero-terminated name of the database from which the -** Nth result column of the [prepared statement] S is extracted, -** or NULL if the Nth column of S is a general expression -** or if unable to allocate memory to store the name. -** -** {H13742} The [sqlite3_column_database_name16(S,N)] interface returns either -** the UTF-16 native byte order zero-terminated name of the database -** from which the Nth result column of the [prepared statement] S is -** extracted, or NULL if the Nth column of S is a general expression -** or if unable to allocate memory to store the name. -** -** {H13743} The [sqlite3_column_table_name(S,N)] interface returns either -** the UTF-8 zero-terminated name of the table from which the -** Nth result column of the [prepared statement] S is extracted, -** or NULL if the Nth column of S is a general expression -** or if unable to allocate memory to store the name. -** -** {H13744} The [sqlite3_column_table_name16(S,N)] interface returns either -** the UTF-16 native byte order zero-terminated name of the table -** from which the Nth result column of the [prepared statement] S is -** extracted, or NULL if the Nth column of S is a general expression -** or if unable to allocate memory to store the name. -** -** {H13745} The [sqlite3_column_origin_name(S,N)] interface returns either -** the UTF-8 zero-terminated name of the table column from which the -** Nth result column of the [prepared statement] S is extracted, -** or NULL if the Nth column of S is a general expression -** or if unable to allocate memory to store the name. -** -** {H13746} The [sqlite3_column_origin_name16(S,N)] interface returns either -** the UTF-16 native byte order zero-terminated name of the table -** column from which the Nth result column of the -** [prepared statement] S is extracted, or NULL if the Nth column -** of S is a general expression or if unable to allocate memory +** {F13741} The [sqlite3_column_database_name(S,N)] interface returns either +** the UTF-8 zero-terminated name of the database from which the +** Nth result column of [prepared statement] S +** is extracted, or NULL if the the Nth column of S is a +** general expression or if unable to allocate memory ** to store the name. -** -** {H13748} The return values from -** [sqlite3_column_database_name | column metadata interfaces] -** are valid for the lifetime of the [prepared statement] +** +** {F13742} The [sqlite3_column_database_name16(S,N)] interface returns either +** the UTF-16 native byte order +** zero-terminated name of the database from which the +** Nth result column of [prepared statement] S +** is extracted, or NULL if the the Nth column of S is a +** general expression or if unable to allocate memory +** to store the name. +** +** {F13743} The [sqlite3_column_table_name(S,N)] interface returns either +** the UTF-8 zero-terminated name of the table from which the +** Nth result column of [prepared statement] S +** is extracted, or NULL if the the Nth column of S is a +** general expression or if unable to allocate memory +** to store the name. +** +** {F13744} The [sqlite3_column_table_name16(S,N)] interface returns either +** the UTF-16 native byte order +** zero-terminated name of the table from which the +** Nth result column of [prepared statement] S +** is extracted, or NULL if the the Nth column of S is a +** general expression or if unable to allocate memory +** to store the name. +** +** {F13745} The [sqlite3_column_origin_name(S,N)] interface returns either +** the UTF-8 zero-terminated name of the table column from which the +** Nth result column of [prepared statement] S +** is extracted, or NULL if the the Nth column of S is a +** general expression or if unable to allocate memory +** to store the name. +** +** {F13746} The [sqlite3_column_origin_name16(S,N)] interface returns either +** the UTF-16 native byte order +** zero-terminated name of the table column from which the +** Nth result column of [prepared statement] S +** is extracted, or NULL if the the Nth column of S is a +** general expression or if unable to allocate memory +** to store the name. +** +** {F13748} The return values from +** [sqlite3_column_database_name|column metadata interfaces] +** are valid +** for the lifetime of the [prepared statement] ** or until the encoding is changed by another metadata ** interface call for the same prepared statement and column. ** -** ASSUMPTIONS: +** LIMITATIONS: ** -** {A13751} If two or more threads call one or more -** [sqlite3_column_database_name | column metadata interfaces] -** for the same [prepared statement] and result column +** {U13751} If two or more threads call one or more +** [sqlite3_column_database_name|column metadata interfaces] +** the same [prepared statement] and result column ** at the same time then the results are undefined. */ const char *sqlite3_column_database_name(sqlite3_stmt*,int); @@ -3471,26 +2932,26 @@ const char *sqlite3_column_origin_name(sqlite3_stmt*,int); const void *sqlite3_column_origin_name16(sqlite3_stmt*,int); /* -** CAPI3REF: Declared Datatype Of A Query Result {H13760} +** CAPI3REF: Declared Datatype Of A Query Result {F13760} ** -** The first parameter is a [prepared statement]. -** If this statement is a [SELECT] statement and the Nth column of the -** returned result set of that [SELECT] is a table column (not an +** The first parameter is a [prepared statement]. +** If this statement is a SELECT statement and the Nth column of the +** returned result set of that SELECT is a table column (not an ** expression or subquery) then the declared type of the table ** column is returned. If the Nth column of the result set is an ** expression or subquery, then a NULL pointer is returned. -** The returned string is always UTF-8 encoded. {END} -** -** For example, given the database schema: +** The returned string is always UTF-8 encoded. {END} +** For example, in the database schema: ** ** CREATE TABLE t1(c1 VARIANT); ** -** and the following statement to be compiled: +** And the following statement compiled: ** ** SELECT c1 + 1, c1 FROM t1; ** -** this routine would return the string "VARIANT" for the second result -** column (i==1), and a NULL pointer for the first result column (i==0). +** Then this routine would return the string "VARIANT" for the second +** result column (i==1), and a NULL pointer for the first result column +** (i==0). ** ** SQLite uses dynamic run-time typing. So just because a column ** is declared to contain a particular type does not mean that the @@ -3501,21 +2962,22 @@ const void *sqlite3_column_origin_name16(sqlite3_stmt*,int); ** ** INVARIANTS: ** -** {H13761} A successful call to [sqlite3_column_decltype(S,N)] returns a -** zero-terminated UTF-8 string containing the declared datatype -** of the table column that appears as the Nth column (numbered -** from 0) of the result set to the [prepared statement] S. +** {F13761} A successful call to [sqlite3_column_decltype(S,N)] +** returns a zero-terminated UTF-8 string containing the +** the declared datatype of the table column that appears +** as the Nth column (numbered from 0) of the result set to the +** [prepared statement] S. ** -** {H13762} A successful call to [sqlite3_column_decltype16(S,N)] +** {F13762} A successful call to [sqlite3_column_decltype16(S,N)] ** returns a zero-terminated UTF-16 native byte order string ** containing the declared datatype of the table column that appears ** as the Nth column (numbered from 0) of the result set to the ** [prepared statement] S. ** -** {H13763} If N is less than 0 or N is greater than or equal to -** the number of columns in the [prepared statement] S, +** {F13763} If N is less than 0 or N is greater than or equal to +** the number of columns in [prepared statement] S ** or if the Nth column of S is an expression or subquery rather -** than a table column, or if a memory allocation failure +** than a table column or if a memory allocation failure ** occurs during encoding conversions, then ** calls to [sqlite3_column_decltype(S,N)] or ** [sqlite3_column_decltype16(S,N)] return NULL. @@ -3523,30 +2985,32 @@ const void *sqlite3_column_origin_name16(sqlite3_stmt*,int); const char *sqlite3_column_decltype(sqlite3_stmt*,int); const void *sqlite3_column_decltype16(sqlite3_stmt*,int); -/* -** CAPI3REF: Evaluate An SQL Statement {H13200} +/* +** CAPI3REF: Evaluate An SQL Statement {F13200} ** -** After a [prepared statement] has been prepared using either -** [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] or one of the legacy -** interfaces [sqlite3_prepare()] or [sqlite3_prepare16()], this function -** must be called one or more times to evaluate the statement. +** After an [prepared statement] has been prepared with a call +** to either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] or to one of +** the legacy interfaces [sqlite3_prepare()] or [sqlite3_prepare16()], +** then this function must be called one or more times to evaluate the +** statement. ** -** The details of the behavior of the sqlite3_step() interface depend +** The details of the behavior of this sqlite3_step() interface depend ** on whether the statement was prepared using the newer "v2" interface ** [sqlite3_prepare_v2()] and [sqlite3_prepare16_v2()] or the older legacy ** interface [sqlite3_prepare()] and [sqlite3_prepare16()]. The use of the ** new "v2" interface is recommended for new applications but the legacy ** interface will continue to be supported. ** -** In the legacy interface, the return value will be either [SQLITE_BUSY], +** In the legacy interface, the return value will be either [SQLITE_BUSY], ** [SQLITE_DONE], [SQLITE_ROW], [SQLITE_ERROR], or [SQLITE_MISUSE]. -** With the "v2" interface, any of the other [result codes] or -** [extended result codes] might be returned as well. +** With the "v2" interface, any of the other [SQLITE_OK | result code] +** or [SQLITE_IOERR_READ | extended result code] might be returned as +** well. ** ** [SQLITE_BUSY] means that the database engine was unable to acquire the -** database locks it needs to do its job. If the statement is a [COMMIT] +** database locks it needs to do its job. If the statement is a COMMIT ** or occurs outside of an explicit transaction, then you can retry the -** statement. If the statement is not a [COMMIT] and occurs within a +** statement. If the statement is not a COMMIT and occurs within a ** explicit transaction then you should rollback the transaction before ** continuing. ** @@ -3555,15 +3019,16 @@ const void *sqlite3_column_decltype16(sqlite3_stmt*,int); ** machine without first calling [sqlite3_reset()] to reset the virtual ** machine back to its initial state. ** -** If the SQL statement being executed returns any data, then [SQLITE_ROW] -** is returned each time a new row of data is ready for processing by the -** caller. The values may be accessed using the [column access functions]. +** If the SQL statement being executed returns any data, then +** [SQLITE_ROW] is returned each time a new row of data is ready +** for processing by the caller. The values may be accessed using +** the [sqlite3_column_int | column access functions]. ** sqlite3_step() is called again to retrieve the next row of data. -** +** ** [SQLITE_ERROR] means that a run-time error (such as a constraint ** violation) has occurred. sqlite3_step() should not be called again on ** the VM. More information may be found by calling [sqlite3_errmsg()]. -** With the legacy interface, a more specific error code (for example, +** With the legacy interface, a more specific error code (example: ** [SQLITE_INTERRUPT], [SQLITE_SCHEMA], [SQLITE_CORRUPT], and so forth) ** can be obtained by calling [sqlite3_reset()] on the ** [prepared statement]. In the "v2" interface, @@ -3571,75 +3036,80 @@ const void *sqlite3_column_decltype16(sqlite3_stmt*,int); ** ** [SQLITE_MISUSE] means that the this routine was called inappropriately. ** Perhaps it was called on a [prepared statement] that has -** already been [sqlite3_finalize | finalized] or on one that had +** already been [sqlite3_finalize | finalized] or on one that had ** previously returned [SQLITE_ERROR] or [SQLITE_DONE]. Or it could ** be the case that the same database connection is being used by two or ** more threads at the same moment in time. ** -** Goofy Interface Alert: In the legacy interface, the sqlite3_step() -** API always returns a generic error code, [SQLITE_ERROR], following any -** error other than [SQLITE_BUSY] and [SQLITE_MISUSE]. You must call -** [sqlite3_reset()] or [sqlite3_finalize()] in order to find one of the -** specific [error codes] that better describes the error. +** Goofy Interface Alert: +** In the legacy interface, +** the sqlite3_step() API always returns a generic error code, +** [SQLITE_ERROR], following any error other than [SQLITE_BUSY] +** and [SQLITE_MISUSE]. You must call [sqlite3_reset()] or +** [sqlite3_finalize()] in order to find one of the specific +** [error codes] that better describes the error. ** We admit that this is a goofy design. The problem has been fixed ** with the "v2" interface. If you prepare all of your SQL statements ** using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] instead -** of the legacy [sqlite3_prepare()] and [sqlite3_prepare16()] interfaces, -** then the more specific [error codes] are returned directly +** of the legacy [sqlite3_prepare()] and [sqlite3_prepare16()], then the +** more specific [error codes] are returned directly ** by sqlite3_step(). The use of the "v2" interface is recommended. ** ** INVARIANTS: ** -** {H13202} If the [prepared statement] S is ready to be run, then -** [sqlite3_step(S)] advances that prepared statement until -** completion or until it is ready to return another row of the -** result set, or until an [sqlite3_interrupt | interrupt] -** or a run-time error occurs. +** {F13202} If [prepared statement] S is ready to be +** run, then [sqlite3_step(S)] advances that prepared statement +** until to completion or until it is ready to return another +** row of the result set or an interrupt or run-time error occurs. ** -** {H15304} When a call to [sqlite3_step(S)] causes the [prepared statement] -** S to run to completion, the function returns [SQLITE_DONE]. +** {F15304} When a call to [sqlite3_step(S)] causes the +** [prepared statement] S to run to completion, +** the function returns [SQLITE_DONE]. ** -** {H15306} When a call to [sqlite3_step(S)] stops because it is ready to -** return another row of the result set, it returns [SQLITE_ROW]. +** {F15306} When a call to [sqlite3_step(S)] stops because it is ready +** to return another row of the result set, it returns +** [SQLITE_ROW]. ** -** {H15308} If a call to [sqlite3_step(S)] encounters an -** [sqlite3_interrupt | interrupt] or a run-time error, -** it returns an appropriate error code that is not one of +** {F15308} If a call to [sqlite3_step(S)] encounters an +** [sqlite3_interrupt|interrupt] or a run-time error, +** it returns an appropraite error code that is not one of ** [SQLITE_OK], [SQLITE_ROW], or [SQLITE_DONE]. ** -** {H15310} If an [sqlite3_interrupt | interrupt] or a run-time error +** {F15310} If an [sqlite3_interrupt|interrupt] or run-time error ** occurs during a call to [sqlite3_step(S)] ** for a [prepared statement] S created using ** legacy interfaces [sqlite3_prepare()] or -** [sqlite3_prepare16()], then the function returns either +** [sqlite3_prepare16()] then the function returns either ** [SQLITE_ERROR], [SQLITE_BUSY], or [SQLITE_MISUSE]. */ int sqlite3_step(sqlite3_stmt*); /* -** CAPI3REF: Number of columns in a result set {H13770} +** CAPI3REF: Number of columns in a result set {F13770} ** -** Returns the number of values in the current row of the result set. +** Return the number of values in the current row of the result set. ** ** INVARIANTS: ** -** {H13771} After a call to [sqlite3_step(S)] that returns [SQLITE_ROW], -** the [sqlite3_data_count(S)] routine will return the same value -** as the [sqlite3_column_count(S)] function. +** {F13771} After a call to [sqlite3_step(S)] that returns +** [SQLITE_ROW], the [sqlite3_data_count(S)] routine +** will return the same value as the +** [sqlite3_column_count(S)] function. ** -** {H13772} After [sqlite3_step(S)] has returned any value other than -** [SQLITE_ROW] or before [sqlite3_step(S)] has been called on the -** [prepared statement] for the first time since it was -** [sqlite3_prepare | prepared] or [sqlite3_reset | reset], -** the [sqlite3_data_count(S)] routine returns zero. +** {F13772} After [sqlite3_step(S)] has returned any value other than +** [SQLITE_ROW] or before [sqlite3_step(S)] has been +** called on the [prepared statement] for +** the first time since it was [sqlite3_prepare|prepared] +** or [sqlite3_reset|reset], the [sqlite3_data_count(S)] +** routine returns zero. */ int sqlite3_data_count(sqlite3_stmt *pStmt); /* -** CAPI3REF: Fundamental Datatypes {H10265} +** CAPI3REF: Fundamental Datatypes {F10265} ** KEYWORDS: SQLITE_TEXT ** -** {H10266} Every value in SQLite has one of five fundamental datatypes: +** {F10266}Every value in SQLite has one of five fundamental datatypes: ** **
          **
        • 64-bit signed integer @@ -3653,7 +3123,7 @@ int sqlite3_data_count(sqlite3_stmt *pStmt); ** ** Note that the SQLITE_TEXT constant was also used in SQLite version 2 ** for a completely different meaning. Software that links against both -** SQLite version 2 and SQLite version 3 should use SQLITE3_TEXT, not +** SQLite version 2 and SQLite version 3 should use SQLITE3_TEXT not ** SQLITE_TEXT. */ #define SQLITE_INTEGER 1 @@ -3668,31 +3138,33 @@ int sqlite3_data_count(sqlite3_stmt *pStmt); #define SQLITE3_TEXT 3 /* -** CAPI3REF: Result Values From A Query {H13800} -** KEYWORDS: {column access functions} +** CAPI3REF: Results Values From A Query {F13800} ** ** These routines form the "result set query" interface. ** -** These routines return information about a single column of the current -** result row of a query. In every case the first argument is a pointer -** to the [prepared statement] that is being evaluated (the [sqlite3_stmt*] -** that was returned from [sqlite3_prepare_v2()] or one of its variants) -** and the second argument is the index of the column for which information -** should be returned. The leftmost column of the result set has the index 0. +** These routines return information about +** a single column of the current result row of a query. In every +** case the first argument is a pointer to the +** [prepared statement] that is being +** evaluated (the [sqlite3_stmt*] that was returned from +** [sqlite3_prepare_v2()] or one of its variants) and +** the second argument is the index of the column for which information +** should be returned. The left-most column of the result set +** has an index of 0. ** -** If the SQL statement does not currently point to a valid row, or if the -** column index is out of range, the result is undefined. +** If the SQL statement is not currently point to a valid row, or if the +** the column index is out of range, the result is undefined. ** These routines may only be called when the most recent call to ** [sqlite3_step()] has returned [SQLITE_ROW] and neither -** [sqlite3_reset()] nor [sqlite3_finalize()] have been called subsequently. +** [sqlite3_reset()] nor [sqlite3_finalize()] has been call subsequently. ** If any of these routines are called after [sqlite3_reset()] or ** [sqlite3_finalize()] or after [sqlite3_step()] has returned ** something other than [SQLITE_ROW], the results are undefined. ** If [sqlite3_step()] or [sqlite3_reset()] or [sqlite3_finalize()] ** are called from a different thread while any of these routines -** are pending, then the results are undefined. +** are pending, then the results are undefined. ** -** The sqlite3_column_type() routine returns the +** The sqlite3_column_type() routine returns ** [SQLITE_INTEGER | datatype code] for the initial data type ** of the result column. The returned value is one of [SQLITE_INTEGER], ** [SQLITE_FLOAT], [SQLITE_TEXT], [SQLITE_BLOB], or [SQLITE_NULL]. The value @@ -3702,7 +3174,7 @@ int sqlite3_data_count(sqlite3_stmt *pStmt); ** versions of SQLite may change the behavior of sqlite3_column_type() ** following a type conversion. ** -** If the result is a BLOB or UTF-8 string then the sqlite3_column_bytes() +** If the result is a BLOB or UTF-8 string then the sqlite3_column_bytes() ** routine returns the number of bytes in that BLOB or string. ** If the result is a UTF-16 string, then sqlite3_column_bytes() converts ** the string to UTF-8 and then returns the number of bytes. @@ -3715,11 +3187,11 @@ int sqlite3_data_count(sqlite3_stmt *pStmt); ** ** Strings returned by sqlite3_column_text() and sqlite3_column_text16(), ** even empty strings, are always zero terminated. The return -** value from sqlite3_column_blob() for a zero-length BLOB is an arbitrary +** value from sqlite3_column_blob() for a zero-length blob is an arbitrary ** pointer, possibly even a NULL pointer. ** ** The sqlite3_column_bytes16() routine is similar to sqlite3_column_bytes() -** but leaves the result in UTF-16 in native byte order instead of UTF-8. +** but leaves the result in UTF-16 in native byte order instead of UTF-8. ** The zero terminator is not included in this count. ** ** The object returned by [sqlite3_column_value()] is an @@ -3727,14 +3199,15 @@ int sqlite3_data_count(sqlite3_stmt *pStmt); ** may only be used with [sqlite3_bind_value()] and [sqlite3_result_value()]. ** If the [unprotected sqlite3_value] object returned by ** [sqlite3_column_value()] is used in any other way, including calls -** to routines like [sqlite3_value_int()], [sqlite3_value_text()], -** or [sqlite3_value_bytes()], then the behavior is undefined. +** to routines like +** [sqlite3_value_int()], [sqlite3_value_text()], or [sqlite3_value_bytes()], +** then the behavior is undefined. ** ** These routines attempt to convert the value where appropriate. For ** example, if the internal representation is FLOAT and a text result -** is requested, [sqlite3_snprintf()] is used internally to perform the -** conversion automatically. The following table details the conversions -** that are applied: +** is requested, [sqlite3_snprintf()] is used internally to do the conversion +** automatically. The following table details the conversions that +** are applied: ** **
          **
      @@ -3746,7 +3219,7 @@ int sqlite3_data_count(sqlite3_stmt *pStmt); **
      NULL BLOB Result is NULL pointer **
      INTEGER FLOAT Convert from integer to float **
      INTEGER TEXT ASCII rendering of the integer -**
      INTEGER BLOB Same as INTEGER->TEXT +**
      INTEGER BLOB Same as for INTEGER->TEXT **
      FLOAT INTEGER Convert from float to integer **
      FLOAT TEXT ASCII rendering of the float **
      FLOAT BLOB Same as FLOAT->TEXT @@ -3761,56 +3234,57 @@ int sqlite3_data_count(sqlite3_stmt *pStmt); ** ** The table above makes reference to standard C library functions atoi() ** and atof(). SQLite does not really use these functions. It has its -** own equivalent internal routines. The atoi() and atof() names are +** on equavalent internal routines. The atoi() and atof() names are ** used in the table for brevity and because they are familiar to most ** C programmers. ** ** Note that when type conversions occur, pointers returned by prior ** calls to sqlite3_column_blob(), sqlite3_column_text(), and/or -** sqlite3_column_text16() may be invalidated. +** sqlite3_column_text16() may be invalidated. ** Type conversions and pointer invalidations might occur ** in the following cases: ** **
        -**
      • The initial content is a BLOB and sqlite3_column_text() or -** sqlite3_column_text16() is called. A zero-terminator might -** need to be added to the string.
      • -**
      • The initial content is UTF-8 text and sqlite3_column_bytes16() or -** sqlite3_column_text16() is called. The content must be converted -** to UTF-16.
      • -**
      • The initial content is UTF-16 text and sqlite3_column_bytes() or -** sqlite3_column_text() is called. The content must be converted -** to UTF-8.
      • +**
      • The initial content is a BLOB and sqlite3_column_text() +** or sqlite3_column_text16() is called. A zero-terminator might +** need to be added to the string.

      • +** +**
      • The initial content is UTF-8 text and sqlite3_column_bytes16() or +** sqlite3_column_text16() is called. The content must be converted +** to UTF-16.

      • +** +**
      • The initial content is UTF-16 text and sqlite3_column_bytes() or +** sqlite3_column_text() is called. The content must be converted +** to UTF-8.

      • **
      ** ** Conversions between UTF-16be and UTF-16le are always done in place and do ** not invalidate a prior pointer, though of course the content of the buffer ** that the prior pointer points to will have been modified. Other kinds -** of conversion are done in place when it is possible, but sometimes they -** are not possible and in those cases prior pointers are invalidated. +** of conversion are done in place when it is possible, but sometime it is +** not possible and in those cases prior pointers are invalidated. ** ** The safest and easiest to remember policy is to invoke these routines ** in one of the following ways: ** -**
        +**
          **
        • sqlite3_column_text() followed by sqlite3_column_bytes()
        • **
        • sqlite3_column_blob() followed by sqlite3_column_bytes()
        • **
        • sqlite3_column_text16() followed by sqlite3_column_bytes16()
        • -**
        +**
      ** -** In other words, you should call sqlite3_column_text(), -** sqlite3_column_blob(), or sqlite3_column_text16() first to force the result -** into the desired format, then invoke sqlite3_column_bytes() or -** sqlite3_column_bytes16() to find the size of the result. Do not mix calls -** to sqlite3_column_text() or sqlite3_column_blob() with calls to -** sqlite3_column_bytes16(), and do not mix calls to sqlite3_column_text16() -** with calls to sqlite3_column_bytes(). +** In other words, you should call sqlite3_column_text(), sqlite3_column_blob(), +** or sqlite3_column_text16() first to force the result into the desired +** format, then invoke sqlite3_column_bytes() or sqlite3_column_bytes16() to +** find the size of the result. Do not mix call to sqlite3_column_text() or +** sqlite3_column_blob() with calls to sqlite3_column_bytes16(). And do not +** mix calls to sqlite3_column_text16() with calls to sqlite3_column_bytes(). ** ** The pointers returned are valid until a type conversion occurs as ** described above, or until [sqlite3_step()] or [sqlite3_reset()] or ** [sqlite3_finalize()] is called. The memory space used to hold strings -** and BLOBs is freed automatically. Do not pass the pointers returned -** [sqlite3_column_blob()], [sqlite3_column_text()], etc. into +** and blobs is freed automatically. Do not pass the pointers returned +** [sqlite3_column_blob()], [sqlite3_column_text()], etc. into ** [sqlite3_free()]. ** ** If a memory allocation error occurs during the evaluation of any @@ -3821,58 +3295,58 @@ int sqlite3_data_count(sqlite3_stmt *pStmt); ** ** INVARIANTS: ** -** {H13803} The [sqlite3_column_blob(S,N)] interface converts the +** {F13803} The [sqlite3_column_blob(S,N)] interface converts the ** Nth column in the current row of the result set for -** the [prepared statement] S into a BLOB and then returns a +** [prepared statement] S into a blob and then returns a ** pointer to the converted value. ** -** {H13806} The [sqlite3_column_bytes(S,N)] interface returns the -** number of bytes in the BLOB or string (exclusive of the +** {F13806} The [sqlite3_column_bytes(S,N)] interface returns the +** number of bytes in the blob or string (exclusive of the ** zero terminator on the string) that was returned by the ** most recent call to [sqlite3_column_blob(S,N)] or ** [sqlite3_column_text(S,N)]. ** -** {H13809} The [sqlite3_column_bytes16(S,N)] interface returns the +** {F13809} The [sqlite3_column_bytes16(S,N)] interface returns the ** number of bytes in the string (exclusive of the ** zero terminator on the string) that was returned by the ** most recent call to [sqlite3_column_text16(S,N)]. ** -** {H13812} The [sqlite3_column_double(S,N)] interface converts the -** Nth column in the current row of the result set for the +** {F13812} The [sqlite3_column_double(S,N)] interface converts the +** Nth column in the current row of the result set for ** [prepared statement] S into a floating point value and ** returns a copy of that value. ** -** {H13815} The [sqlite3_column_int(S,N)] interface converts the -** Nth column in the current row of the result set for the +** {F13815} The [sqlite3_column_int(S,N)] interface converts the +** Nth column in the current row of the result set for ** [prepared statement] S into a 64-bit signed integer and ** returns the lower 32 bits of that integer. ** -** {H13818} The [sqlite3_column_int64(S,N)] interface converts the -** Nth column in the current row of the result set for the +** {F13818} The [sqlite3_column_int64(S,N)] interface converts the +** Nth column in the current row of the result set for ** [prepared statement] S into a 64-bit signed integer and ** returns a copy of that integer. ** -** {H13821} The [sqlite3_column_text(S,N)] interface converts the +** {F13821} The [sqlite3_column_text(S,N)] interface converts the ** Nth column in the current row of the result set for -** the [prepared statement] S into a zero-terminated UTF-8 +** [prepared statement] S into a zero-terminated UTF-8 ** string and returns a pointer to that string. ** -** {H13824} The [sqlite3_column_text16(S,N)] interface converts the -** Nth column in the current row of the result set for the +** {F13824} The [sqlite3_column_text16(S,N)] interface converts the +** Nth column in the current row of the result set for ** [prepared statement] S into a zero-terminated 2-byte -** aligned UTF-16 native byte order string and returns -** a pointer to that string. +** aligned UTF-16 native byte order +** string and returns a pointer to that string. ** -** {H13827} The [sqlite3_column_type(S,N)] interface returns +** {F13827} The [sqlite3_column_type(S,N)] interface returns ** one of [SQLITE_NULL], [SQLITE_INTEGER], [SQLITE_FLOAT], ** [SQLITE_TEXT], or [SQLITE_BLOB] as appropriate for ** the Nth column in the current row of the result set for -** the [prepared statement] S. +** [prepared statement] S. ** -** {H13830} The [sqlite3_column_value(S,N)] interface returns a +** {F13830} The [sqlite3_column_value(S,N)] interface returns a ** pointer to an [unprotected sqlite3_value] object for the ** Nth column in the current row of the result set for -** the [prepared statement] S. +** [prepared statement] S. */ const void *sqlite3_column_blob(sqlite3_stmt*, int iCol); int sqlite3_column_bytes(sqlite3_stmt*, int iCol); @@ -3886,89 +3360,90 @@ int sqlite3_column_type(sqlite3_stmt*, int iCol); sqlite3_value *sqlite3_column_value(sqlite3_stmt*, int iCol); /* -** CAPI3REF: Destroy A Prepared Statement Object {H13300} +** CAPI3REF: Destroy A Prepared Statement Object {F13300} ** -** The sqlite3_finalize() function is called to delete a [prepared statement]. -** If the statement was executed successfully or not executed at all, then -** SQLITE_OK is returned. If execution of the statement failed then an -** [error code] or [extended error code] is returned. +** The sqlite3_finalize() function is called to delete a +** [prepared statement]. If the statement was +** executed successfully, or not executed at all, then SQLITE_OK is returned. +** If execution of the statement failed then an +** [error code] or [extended error code] +** is returned. ** ** This routine can be called at any point during the execution of the -** [prepared statement]. If the virtual machine has not +** [prepared statement]. If the virtual machine has not ** completed execution when this routine is called, that is like -** encountering an error or an [sqlite3_interrupt | interrupt]. -** Incomplete updates may be rolled back and transactions canceled, -** depending on the circumstances, and the +** encountering an error or an interrupt. (See [sqlite3_interrupt()].) +** Incomplete updates may be rolled back and transactions cancelled, +** depending on the circumstances, and the ** [error code] returned will be [SQLITE_ABORT]. ** ** INVARIANTS: ** -** {H11302} The [sqlite3_finalize(S)] interface destroys the +** {F11302} The [sqlite3_finalize(S)] interface destroys the ** [prepared statement] S and releases all ** memory and file resources held by that object. ** -** {H11304} If the most recent call to [sqlite3_step(S)] for the +** {F11304} If the most recent call to [sqlite3_step(S)] for the ** [prepared statement] S returned an error, ** then [sqlite3_finalize(S)] returns that same error. */ int sqlite3_finalize(sqlite3_stmt *pStmt); /* -** CAPI3REF: Reset A Prepared Statement Object {H13330} +** CAPI3REF: Reset A Prepared Statement Object {F13330} ** -** The sqlite3_reset() function is called to reset a [prepared statement] -** object back to its initial state, ready to be re-executed. +** The sqlite3_reset() function is called to reset a +** [prepared statement] object. +** back to its initial state, ready to be re-executed. ** Any SQL statement variables that had values bound to them using ** the [sqlite3_bind_blob | sqlite3_bind_*() API] retain their values. ** Use [sqlite3_clear_bindings()] to reset the bindings. ** -** {H11332} The [sqlite3_reset(S)] interface resets the [prepared statement] S +** {F11332} The [sqlite3_reset(S)] interface resets the [prepared statement] S ** back to the beginning of its program. ** -** {H11334} If the most recent call to [sqlite3_step(S)] for the +** {F11334} If the most recent call to [sqlite3_step(S)] for ** [prepared statement] S returned [SQLITE_ROW] or [SQLITE_DONE], ** or if [sqlite3_step(S)] has never before been called on S, ** then [sqlite3_reset(S)] returns [SQLITE_OK]. ** -** {H11336} If the most recent call to [sqlite3_step(S)] for the +** {F11336} If the most recent call to [sqlite3_step(S)] for ** [prepared statement] S indicated an error, then ** [sqlite3_reset(S)] returns an appropriate [error code]. ** -** {H11338} The [sqlite3_reset(S)] interface does not change the values -** of any [sqlite3_bind_blob|bindings] on the [prepared statement] S. +** {F11338} The [sqlite3_reset(S)] interface does not change the values +** of any [sqlite3_bind_blob|bindings] on [prepared statement] S. */ int sqlite3_reset(sqlite3_stmt *pStmt); /* -** CAPI3REF: Create Or Redefine SQL Functions {H16100} -** KEYWORDS: {function creation routines} -** KEYWORDS: {application-defined SQL function} -** KEYWORDS: {application-defined SQL functions} +** CAPI3REF: Create Or Redefine SQL Functions {F16100} +** KEYWORDS: {function creation routines} ** -** These two functions (collectively known as "function creation routines") -** are used to add SQL functions or aggregates or to redefine the behavior -** of existing SQL functions or aggregates. The only difference between the -** two is that the second parameter, the name of the (scalar) function or -** aggregate, is encoded in UTF-8 for sqlite3_create_function() and UTF-16 -** for sqlite3_create_function16(). +** These two functions (collectively known as +** "function creation routines") are used to add SQL functions or aggregates +** or to redefine the behavior of existing SQL functions or aggregates. The +** difference only between the two is that the second parameter, the +** name of the (scalar) function or aggregate, is encoded in UTF-8 for +** sqlite3_create_function() and UTF-16 for sqlite3_create_function16(). ** ** The first parameter is the [database connection] to which the SQL -** function is to be added. If a single program uses more than one database -** connection internally, then SQL functions must be added individually to -** each database connection. +** function is to be added. If a single +** program uses more than one [database connection] internally, then SQL +** functions must be added individually to each [database connection]. ** -** The second parameter is the name of the SQL function to be created or -** redefined. The length of the name is limited to 255 bytes, exclusive of -** the zero-terminator. Note that the name length limit is in bytes, not +** The second parameter is the name of the SQL function to be created +** or redefined. +** The length of the name is limited to 255 bytes, exclusive of the +** zero-terminator. Note that the name length limit is in bytes, not ** characters. Any attempt to create a function with a longer name -** will result in [SQLITE_ERROR] being returned. +** will result in an SQLITE_ERROR error. ** -** The third parameter (nArg) -** is the number of arguments that the SQL function or +** The third parameter is the number of arguments that the SQL function or ** aggregate takes. If this parameter is negative, then the SQL function or ** aggregate may take any number of arguments. ** -** The fourth parameter, eTextRep, specifies what +** The fourth parameter, eTextRep, specifies what ** [SQLITE_UTF8 | text encoding] this SQL function prefers for ** its parameters. Any SQL function implementation should be able to work ** work with UTF-8, UTF-16le, or UTF-16be. But some implementations may be @@ -3977,109 +3452,94 @@ int sqlite3_reset(sqlite3_stmt *pStmt); ** times with the same function but with different values of eTextRep. ** When multiple implementations of the same function are available, SQLite ** will pick the one that involves the least amount of data conversion. -** If there is only a single implementation which does not care what text -** encoding is used, then the fourth argument should be [SQLITE_ANY]. +** If there is only a single implementation which does not care what +** text encoding is used, then the fourth argument should be +** [SQLITE_ANY]. ** -** The fifth parameter is an arbitrary pointer. The implementation of the -** function can gain access to this pointer using [sqlite3_user_data()]. +** The fifth parameter is an arbitrary pointer. The implementation +** of the function can gain access to this pointer using +** [sqlite3_user_data()]. ** ** The seventh, eighth and ninth parameters, xFunc, xStep and xFinal, are -** pointers to C-language functions that implement the SQL function or -** aggregate. A scalar SQL function requires an implementation of the xFunc -** callback only, NULL pointers should be passed as the xStep and xFinal -** parameters. An aggregate SQL function requires an implementation of xStep -** and xFinal and NULL should be passed for xFunc. To delete an existing -** SQL function or aggregate, pass NULL for all three function callbacks. +** pointers to C-language functions that implement the SQL +** function or aggregate. A scalar SQL function requires an implementation of +** the xFunc callback only, NULL pointers should be passed as the xStep +** and xFinal parameters. An aggregate SQL function requires an implementation +** of xStep and xFinal and NULL should be passed for xFunc. To delete an +** existing SQL function or aggregate, pass NULL for all three function +** callback. ** ** It is permitted to register multiple implementations of the same ** functions with the same name but with either differing numbers of -** arguments or differing preferred text encodings. SQLite will use +** arguments or differing perferred text encodings. SQLite will use ** the implementation most closely matches the way in which the -** SQL function is used. A function implementation with a non-negative -** nArg parameter is a better match than a function implementation with -** a negative nArg. A function where the preferred text encoding -** matches the database encoding is a better -** match than a function where the encoding is different. -** A function where the encoding difference is between UTF16le and UTF16be -** is a closer match than a function where the encoding difference is -** between UTF8 and UTF16. -** -** Built-in functions may be overloaded by new application-defined functions. -** The first application-defined function with a given name overrides all -** built-in functions in the same [database connection] with the same name. -** Subsequent application-defined functions of the same name only override -** prior application-defined functions that are an exact match for the -** number of parameters and preferred encoding. -** -** An application-defined function is permitted to call other -** SQLite interfaces. However, such calls must not -** close the database connection nor finalize or reset the prepared -** statement in which the function is running. +** SQL function is used. ** ** INVARIANTS: ** -** {H16103} The [sqlite3_create_function16(D,X,...)] interface shall behave -** as [sqlite3_create_function(D,X,...)] in every way except that it -** interprets the X argument as zero-terminated UTF-16 -** native byte order instead of as zero-terminated UTF-8. +** {F16103} The [sqlite3_create_function16()] interface behaves exactly +** like [sqlite3_create_function()] in every way except that it +** interprets the zFunctionName argument as +** zero-terminated UTF-16 native byte order instead of as a +** zero-terminated UTF-8. ** -** {H16106} A successful invocation of the -** [sqlite3_create_function(D,X,N,E,...)] interface shall register -** or replaces callback functions in the [database connection] D +** {F16106} A successful invocation of +** the [sqlite3_create_function(D,X,N,E,...)] interface registers +** or replaces callback functions in [database connection] D ** used to implement the SQL function named X with N parameters -** and having a preferred text encoding of E. +** and having a perferred text encoding of E. ** -** {H16109} A successful call to [sqlite3_create_function(D,X,N,E,P,F,S,L)] -** shall replace the P, F, S, and L values from any prior calls with +** {F16109} A successful call to [sqlite3_create_function(D,X,N,E,P,F,S,L)] +** replaces the P, F, S, and L values from any prior calls with ** the same D, X, N, and E values. ** -** {H16112} The [sqlite3_create_function(D,X,...)] interface shall fail -** if the SQL function name X is +** {F16112} The [sqlite3_create_function(D,X,...)] interface fails with +** a return code of [SQLITE_ERROR] if the SQL function name X is ** longer than 255 bytes exclusive of the zero terminator. ** -** {H16118} The [sqlite3_create_function(D,X,N,E,P,F,S,L)] interface -** shall fail unless either F is NULL and S and L are non-NULL or -*** F is non-NULL and S and L are NULL. +** {F16118} Either F must be NULL and S and L are non-NULL or else F +** is non-NULL and S and L are NULL, otherwise +** [sqlite3_create_function(D,X,N,E,P,F,S,L)] returns [SQLITE_ERROR]. ** -** {H16121} The [sqlite3_create_function(D,...)] interface shall fails with an +** {F16121} The [sqlite3_create_function(D,...)] interface fails with an ** error code of [SQLITE_BUSY] if there exist [prepared statements] ** associated with the [database connection] D. ** -** {H16124} The [sqlite3_create_function(D,X,N,...)] interface shall fail with -** an error code of [SQLITE_ERROR] if parameter N is less +** {F16124} The [sqlite3_create_function(D,X,N,...)] interface fails with an +** error code of [SQLITE_ERROR] if parameter N (specifying the number +** of arguments to the SQL function being registered) is less ** than -1 or greater than 127. ** -** {H16127} When N is non-negative, the [sqlite3_create_function(D,X,N,...)] -** interface shall register callbacks to be invoked for the -** SQL function +** {F16127} When N is non-negative, the [sqlite3_create_function(D,X,N,...)] +** interface causes callbacks to be invoked for the SQL function ** named X when the number of arguments to the SQL function is ** exactly N. ** -** {H16130} When N is -1, the [sqlite3_create_function(D,X,N,...)] -** interface shall register callbacks to be invoked for the SQL -** function named X with any number of arguments. +** {F16130} When N is -1, the [sqlite3_create_function(D,X,N,...)] +** interface causes callbacks to be invoked for the SQL function +** named X with any number of arguments. ** -** {H16133} When calls to [sqlite3_create_function(D,X,N,...)] +** {F16133} When calls to [sqlite3_create_function(D,X,N,...)] ** specify multiple implementations of the same function X ** and when one implementation has N>=0 and the other has N=(-1) -** the implementation with a non-zero N shall be preferred. +** the implementation with a non-zero N is preferred. ** -** {H16136} When calls to [sqlite3_create_function(D,X,N,E,...)] +** {F16136} When calls to [sqlite3_create_function(D,X,N,E,...)] ** specify multiple implementations of the same function X with ** the same number of arguments N but with different ** encodings E, then the implementation where E matches the -** database encoding shall preferred. +** database encoding is preferred. ** -** {H16139} For an aggregate SQL function created using -** [sqlite3_create_function(D,X,N,E,P,0,S,L)] the finalizer -** function L shall always be invoked exactly once if the +** {F16139} For an aggregate SQL function created using +** [sqlite3_create_function(D,X,N,E,P,0,S,L)] the finializer +** function L will always be invoked exactly once if the ** step function S is called one or more times. ** -** {H16142} When SQLite invokes either the xFunc or xStep function of +** {F16142} When SQLite invokes either the xFunc or xStep function of ** an application-defined SQL function or aggregate created ** by [sqlite3_create_function()] or [sqlite3_create_function16()], ** then the array of [sqlite3_value] objects passed as the -** third parameter shall be [protected sqlite3_value] objects. +** third parameter are always [protected sqlite3_value] objects. */ int sqlite3_create_function( sqlite3 *db, @@ -4103,7 +3563,7 @@ int sqlite3_create_function16( ); /* -** CAPI3REF: Text Encodings {H10267} +** CAPI3REF: Text Encodings {F10267} ** ** These constant define integer codes that represent the various ** text encodings supported by SQLite. @@ -4116,26 +3576,23 @@ int sqlite3_create_function16( #define SQLITE_UTF16_ALIGNED 8 /* sqlite3_create_collation only */ /* -** CAPI3REF: Deprecated Functions -** DEPRECATED +** CAPI3REF: Obsolete Functions ** -** These functions are [deprecated]. In order to maintain -** backwards compatibility with older code, these functions continue -** to be supported. However, new applications should avoid +** These functions are all now obsolete. In order to maintain +** backwards compatibility with older code, we continue to support +** these functions. However, new development projects should avoid ** the use of these functions. To help encourage people to avoid ** using these functions, we are not going to tell you want they do. */ -#ifndef SQLITE_OMIT_DEPRECATED -SQLITE_DEPRECATED int sqlite3_aggregate_count(sqlite3_context*); -SQLITE_DEPRECATED int sqlite3_expired(sqlite3_stmt*); -SQLITE_DEPRECATED int sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*); -SQLITE_DEPRECATED int sqlite3_global_recover(void); -SQLITE_DEPRECATED void sqlite3_thread_cleanup(void); -SQLITE_DEPRECATED int sqlite3_memory_alarm(void(*)(void*,sqlite3_int64,int),void*,sqlite3_int64); -#endif +int sqlite3_aggregate_count(sqlite3_context*); +int sqlite3_expired(sqlite3_stmt*); +int sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*); +int sqlite3_global_recover(void); +void sqlite3_thread_cleanup(void); +int sqlite3_memory_alarm(void(*)(void*,sqlite3_int64,int),void*,sqlite3_int64); /* -** CAPI3REF: Obtaining SQL Function Parameter Values {H15100} +** CAPI3REF: Obtaining SQL Function Parameter Values {F15100} ** ** The C-language implementation of SQL functions and aggregates uses ** this set of interface routines to access the parameter values on @@ -4153,93 +3610,95 @@ SQLITE_DEPRECATED int sqlite3_memory_alarm(void(*)(void*,sqlite3_int64,int),void ** Any attempt to use these routines on an [unprotected sqlite3_value] ** object results in undefined behavior. ** -** These routines work just like the corresponding [column access functions] -** except that these routines take a single [protected sqlite3_value] object -** pointer instead of a [sqlite3_stmt*] pointer and an integer column number. +** These routines work just like the corresponding +** [sqlite3_column_blob | sqlite3_column_* routines] except that +** these routines take a single [protected sqlite3_value] object pointer +** instead of an [sqlite3_stmt*] pointer and an integer column number. ** -** The sqlite3_value_text16() interface extracts a UTF-16 string +** The sqlite3_value_text16() interface extracts a UTF16 string ** in the native byte-order of the host machine. The ** sqlite3_value_text16be() and sqlite3_value_text16le() interfaces -** extract UTF-16 strings as big-endian and little-endian respectively. +** extract UTF16 strings as big-endian and little-endian respectively. ** ** The sqlite3_value_numeric_type() interface attempts to apply ** numeric affinity to the value. This means that an attempt is ** made to convert the value to an integer or floating point. If ** such a conversion is possible without loss of information (in other -** words, if the value is a string that looks like a number) -** then the conversion is performed. Otherwise no conversion occurs. -** The [SQLITE_INTEGER | datatype] after conversion is returned. +** words if the value is a string that looks like a number) +** then the conversion is done. Otherwise no conversion occurs. The +** [SQLITE_INTEGER | datatype] after conversion is returned. ** -** Please pay particular attention to the fact that the pointer returned -** from [sqlite3_value_blob()], [sqlite3_value_text()], or +** Please pay particular attention to the fact that the pointer that +** is returned from [sqlite3_value_blob()], [sqlite3_value_text()], or ** [sqlite3_value_text16()] can be invalidated by a subsequent call to ** [sqlite3_value_bytes()], [sqlite3_value_bytes16()], [sqlite3_value_text()], -** or [sqlite3_value_text16()]. +** or [sqlite3_value_text16()]. ** ** These routines must be called from the same thread as ** the SQL function that supplied the [sqlite3_value*] parameters. ** +** ** INVARIANTS: ** -** {H15103} The [sqlite3_value_blob(V)] interface converts the -** [protected sqlite3_value] object V into a BLOB and then -** returns a pointer to the converted value. +** {F15103} The [sqlite3_value_blob(V)] interface converts the +** [protected sqlite3_value] object V into a blob and then returns a +** pointer to the converted value. ** -** {H15106} The [sqlite3_value_bytes(V)] interface returns the -** number of bytes in the BLOB or string (exclusive of the +** {F15106} The [sqlite3_value_bytes(V)] interface returns the +** number of bytes in the blob or string (exclusive of the ** zero terminator on the string) that was returned by the ** most recent call to [sqlite3_value_blob(V)] or ** [sqlite3_value_text(V)]. ** -** {H15109} The [sqlite3_value_bytes16(V)] interface returns the +** {F15109} The [sqlite3_value_bytes16(V)] interface returns the ** number of bytes in the string (exclusive of the ** zero terminator on the string) that was returned by the ** most recent call to [sqlite3_value_text16(V)], ** [sqlite3_value_text16be(V)], or [sqlite3_value_text16le(V)]. ** -** {H15112} The [sqlite3_value_double(V)] interface converts the +** {F15112} The [sqlite3_value_double(V)] interface converts the ** [protected sqlite3_value] object V into a floating point value and ** returns a copy of that value. ** -** {H15115} The [sqlite3_value_int(V)] interface converts the +** {F15115} The [sqlite3_value_int(V)] interface converts the ** [protected sqlite3_value] object V into a 64-bit signed integer and ** returns the lower 32 bits of that integer. ** -** {H15118} The [sqlite3_value_int64(V)] interface converts the +** {F15118} The [sqlite3_value_int64(V)] interface converts the ** [protected sqlite3_value] object V into a 64-bit signed integer and ** returns a copy of that integer. ** -** {H15121} The [sqlite3_value_text(V)] interface converts the -** [protected sqlite3_value] object V into a zero-terminated UTF-8 +** {F15121} The [sqlite3_value_text(V)] interface converts the +** [protected sqlite3_value] object V into a zero-terminated UTF-8 ** string and returns a pointer to that string. ** -** {H15124} The [sqlite3_value_text16(V)] interface converts the +** {F15124} The [sqlite3_value_text16(V)] interface converts the ** [protected sqlite3_value] object V into a zero-terminated 2-byte ** aligned UTF-16 native byte order ** string and returns a pointer to that string. ** -** {H15127} The [sqlite3_value_text16be(V)] interface converts the +** {F15127} The [sqlite3_value_text16be(V)] interface converts the ** [protected sqlite3_value] object V into a zero-terminated 2-byte ** aligned UTF-16 big-endian ** string and returns a pointer to that string. ** -** {H15130} The [sqlite3_value_text16le(V)] interface converts the +** {F15130} The [sqlite3_value_text16le(V)] interface converts the ** [protected sqlite3_value] object V into a zero-terminated 2-byte ** aligned UTF-16 little-endian ** string and returns a pointer to that string. ** -** {H15133} The [sqlite3_value_type(V)] interface returns +** {F15133} The [sqlite3_value_type(V)] interface returns ** one of [SQLITE_NULL], [SQLITE_INTEGER], [SQLITE_FLOAT], ** [SQLITE_TEXT], or [SQLITE_BLOB] as appropriate for ** the [sqlite3_value] object V. ** -** {H15136} The [sqlite3_value_numeric_type(V)] interface converts +** {F15136} The [sqlite3_value_numeric_type(V)] interface converts ** the [protected sqlite3_value] object V into either an integer or ** a floating point value if it can do so without loss of ** information, and returns one of [SQLITE_NULL], ** [SQLITE_INTEGER], [SQLITE_FLOAT], [SQLITE_TEXT], or -** [SQLITE_BLOB] as appropriate for the -** [protected sqlite3_value] object V after the conversion attempt. +** [SQLITE_BLOB] as appropriate for +** the [protected sqlite3_value] object V after the conversion attempt. */ const void *sqlite3_value_blob(sqlite3_value*); int sqlite3_value_bytes(sqlite3_value*); @@ -4255,44 +3714,46 @@ int sqlite3_value_type(sqlite3_value*); int sqlite3_value_numeric_type(sqlite3_value*); /* -** CAPI3REF: Obtain Aggregate Function Context {H16210} +** CAPI3REF: Obtain Aggregate Function Context {F16210} ** ** The implementation of aggregate SQL functions use this routine to allocate -** a structure for storing their state. -** -** The first time the sqlite3_aggregate_context() routine is called for a -** particular aggregate, SQLite allocates nBytes of memory, zeroes out that -** memory, and returns a pointer to it. On second and subsequent calls to -** sqlite3_aggregate_context() for the same aggregate function index, -** the same buffer is returned. The implementation of the aggregate can use -** the returned buffer to accumulate data. +** a structure for storing their state. +** The first time the sqlite3_aggregate_context() routine is +** is called for a particular aggregate, SQLite allocates nBytes of memory +** zeros that memory, and returns a pointer to it. +** On second and subsequent calls to sqlite3_aggregate_context() +** for the same aggregate function index, the same buffer is returned. +** The implementation +** of the aggregate can use the returned buffer to accumulate data. ** ** SQLite automatically frees the allocated buffer when the aggregate ** query concludes. ** -** The first parameter should be a copy of the -** [sqlite3_context | SQL function context] that is the first parameter -** to the callback routine that implements the aggregate function. +** The first parameter should be a copy of the +** [sqlite3_context | SQL function context] that is the first +** parameter to the callback routine that implements the aggregate +** function. ** ** This routine must be called from the same thread in which ** the aggregate SQL function is running. ** ** INVARIANTS: ** -** {H16211} The first invocation of [sqlite3_aggregate_context(C,N)] for +** {F16211} The first invocation of [sqlite3_aggregate_context(C,N)] for ** a particular instance of an aggregate function (for a particular -** context C) causes SQLite to allocate N bytes of memory, -** zero that memory, and return a pointer to the allocated memory. +** context C) causes SQLite to allocation N bytes of memory, +** zero that memory, and return a pointer to the allocationed +** memory. ** -** {H16213} If a memory allocation error occurs during +** {F16213} If a memory allocation error occurs during ** [sqlite3_aggregate_context(C,N)] then the function returns 0. ** -** {H16215} Second and subsequent invocations of +** {F16215} Second and subsequent invocations of ** [sqlite3_aggregate_context(C,N)] for the same context pointer C ** ignore the N parameter and return a pointer to the same ** block of memory returned by the first invocation. ** -** {H16217} The memory allocated by [sqlite3_aggregate_context(C,N)] is +** {F16217} The memory allocated by [sqlite3_aggregate_context(C,N)] is ** automatically freed on the next call to [sqlite3_reset()] ** or [sqlite3_finalize()] for the [prepared statement] containing ** the aggregate function associated with context C. @@ -4300,11 +3761,11 @@ int sqlite3_value_numeric_type(sqlite3_value*); void *sqlite3_aggregate_context(sqlite3_context*, int nBytes); /* -** CAPI3REF: User Data For Functions {H16240} +** CAPI3REF: User Data For Functions {F16240} ** ** The sqlite3_user_data() interface returns a copy of ** the pointer that was the pUserData parameter (the 5th parameter) -** of the [sqlite3_create_function()] +** of the the [sqlite3_create_function()] ** and [sqlite3_create_function16()] routines that originally ** registered the application defined function. {END} ** @@ -4313,67 +3774,71 @@ void *sqlite3_aggregate_context(sqlite3_context*, int nBytes); ** ** INVARIANTS: ** -** {H16243} The [sqlite3_user_data(C)] interface returns a copy of the +** {F16243} The [sqlite3_user_data(C)] interface returns a copy of the ** P pointer from the [sqlite3_create_function(D,X,N,E,P,F,S,L)] ** or [sqlite3_create_function16(D,X,N,E,P,F,S,L)] call that -** registered the SQL function associated with [sqlite3_context] C. +** registered the SQL function associated with +** [sqlite3_context] C. */ void *sqlite3_user_data(sqlite3_context*); /* -** CAPI3REF: Database Connection For Functions {H16250} +** CAPI3REF: Database Connection For Functions {F16250} ** ** The sqlite3_context_db_handle() interface returns a copy of ** the pointer to the [database connection] (the 1st parameter) -** of the [sqlite3_create_function()] +** of the the [sqlite3_create_function()] ** and [sqlite3_create_function16()] routines that originally ** registered the application defined function. ** ** INVARIANTS: ** -** {H16253} The [sqlite3_context_db_handle(C)] interface returns a copy of the +** {F16253} The [sqlite3_context_db_handle(C)] interface returns a copy of the ** D pointer from the [sqlite3_create_function(D,X,N,E,P,F,S,L)] ** or [sqlite3_create_function16(D,X,N,E,P,F,S,L)] call that -** registered the SQL function associated with [sqlite3_context] C. +** registered the SQL function associated with +** [sqlite3_context] C. */ sqlite3 *sqlite3_context_db_handle(sqlite3_context*); /* -** CAPI3REF: Function Auxiliary Data {H16270} +** CAPI3REF: Function Auxiliary Data {F16270} ** ** The following two functions may be used by scalar SQL functions to -** associate metadata with argument values. If the same value is passed to +** associate meta-data with argument values. If the same value is passed to ** multiple invocations of the same SQL function during query execution, under -** some circumstances the associated metadata may be preserved. This may +** some circumstances the associated meta-data may be preserved. This may ** be used, for example, to add a regular-expression matching scalar ** function. The compiled version of the regular expression is stored as -** metadata associated with the SQL value passed as the regular expression +** meta-data associated with the SQL value passed as the regular expression ** pattern. The compiled regular expression can be reused on multiple ** invocations of the same function so that the original pattern string ** does not need to be recompiled on each invocation. ** -** The sqlite3_get_auxdata() interface returns a pointer to the metadata +** The sqlite3_get_auxdata() interface returns a pointer to the meta-data ** associated by the sqlite3_set_auxdata() function with the Nth argument -** value to the application-defined function. If no metadata has been ever -** been set for the Nth argument of the function, or if the corresponding -** function parameter has changed since the meta-data was set, -** then sqlite3_get_auxdata() returns a NULL pointer. +** value to the application-defined function. +** If no meta-data has been ever been set for the Nth +** argument of the function, or if the cooresponding function parameter +** has changed since the meta-data was set, then sqlite3_get_auxdata() +** returns a NULL pointer. ** -** The sqlite3_set_auxdata() interface saves the metadata -** pointed to by its 3rd parameter as the metadata for the N-th +** The sqlite3_set_auxdata() interface saves the meta-data +** pointed to by its 3rd parameter as the meta-data for the N-th ** argument of the application-defined function. Subsequent ** calls to sqlite3_get_auxdata() might return this data, if it has -** not been destroyed. -** If it is not NULL, SQLite will invoke the destructor +** not been destroyed. +** If it is not NULL, SQLite will invoke the destructor ** function given by the 4th parameter to sqlite3_set_auxdata() on -** the metadata when the corresponding function parameter changes +** the meta-data when the corresponding function parameter changes ** or when the SQL statement completes, whichever comes first. ** -** SQLite is free to call the destructor and drop metadata on any -** parameter of any function at any time. The only guarantee is that -** the destructor will be called before the metadata is dropped. +** SQLite is free to call the destructor and drop meta-data on +** any parameter of any function at any time. The only guarantee +** is that the destructor will be called before the metadata is +** dropped. ** -** In practice, metadata is preserved between function calls for +** In practice, meta-data is preserved between function calls for ** expressions that are constant at compile time. This includes literal ** values and SQL variables. ** @@ -4382,27 +3847,28 @@ sqlite3 *sqlite3_context_db_handle(sqlite3_context*); ** ** INVARIANTS: ** -** {H16272} The [sqlite3_get_auxdata(C,N)] interface returns a pointer +** {F16272} The [sqlite3_get_auxdata(C,N)] interface returns a pointer ** to metadata associated with the Nth parameter of the SQL function ** whose context is C, or NULL if there is no metadata associated ** with that parameter. ** -** {H16274} The [sqlite3_set_auxdata(C,N,P,D)] interface assigns a metadata -** pointer P to the Nth parameter of the SQL function with context C. +** {F16274} The [sqlite3_set_auxdata(C,N,P,D)] interface assigns a metadata +** pointer P to the Nth parameter of the SQL function with context +** C. ** -** {H16276} SQLite will invoke the destructor D with a single argument +** {F16276} SQLite will invoke the destructor D with a single argument ** which is the metadata pointer P following a call to ** [sqlite3_set_auxdata(C,N,P,D)] when SQLite ceases to hold ** the metadata. ** -** {H16277} SQLite ceases to hold metadata for an SQL function parameter +** {F16277} SQLite ceases to hold metadata for an SQL function parameter ** when the value of that parameter changes. ** -** {H16278} When [sqlite3_set_auxdata(C,N,P,D)] is invoked, the destructor +** {F16278} When [sqlite3_set_auxdata(C,N,P,D)] is invoked, the destructor ** is called for any prior metadata associated with the same function ** context C and parameter N. ** -** {H16279} SQLite will call destructors for any metadata it is holding +** {F16279} SQLite will call destructors for any metadata it is holding ** in a particular [prepared statement] S when either ** [sqlite3_reset(S)] or [sqlite3_finalize(S)] is called. */ @@ -4411,12 +3877,12 @@ void sqlite3_set_auxdata(sqlite3_context*, int N, void*, void (*)(void*)); /* -** CAPI3REF: Constants Defining Special Destructor Behavior {H10280} +** CAPI3REF: Constants Defining Special Destructor Behavior {F10280} ** -** These are special values for the destructor that is passed in as the +** These are special value for the destructor that is passed in as the ** final argument to routines like [sqlite3_result_blob()]. If the destructor ** argument is SQLITE_STATIC, it means that the content pointer is constant -** and will never change. It does not need to be destroyed. The +** and will never change. It does not need to be destroyed. The ** SQLITE_TRANSIENT value means that the content will likely change in ** the near future and that SQLite should make its own private copy of ** the content before returning. @@ -4429,28 +3895,30 @@ typedef void (*sqlite3_destructor_type)(void*); #define SQLITE_TRANSIENT ((sqlite3_destructor_type)-1) /* -** CAPI3REF: Setting The Result Of An SQL Function {H16400} +** CAPI3REF: Setting The Result Of An SQL Function {F16400} ** ** These routines are used by the xFunc or xFinal callbacks that ** implement SQL functions and aggregates. See ** [sqlite3_create_function()] and [sqlite3_create_function16()] ** for additional information. ** -** These functions work very much like the [parameter binding] family of -** functions used to bind values to host parameters in prepared statements. -** Refer to the [SQL parameter] documentation for additional information. +** These functions work very much like the +** [sqlite3_bind_blob | sqlite3_bind_*] family of functions used +** to bind values to host parameters in prepared statements. +** Refer to the +** [sqlite3_bind_blob | sqlite3_bind_* documentation] for +** additional information. ** ** The sqlite3_result_blob() interface sets the result from -** an application-defined function to be the BLOB whose content is pointed +** an application defined function to be the BLOB whose content is pointed ** to by the second parameter and which is N bytes long where N is the -** third parameter. -** -** The sqlite3_result_zeroblob() interfaces set the result of -** the application-defined function to be a BLOB containing all zero +** third parameter. +** The sqlite3_result_zeroblob() inerfaces set the result of +** the application defined function to be a BLOB containing all zero ** bytes and N bytes in size, where N is the value of the 2nd parameter. ** ** The sqlite3_result_double() interface sets the result from -** an application-defined function to be a floating point value specified +** an application defined function to be a floating point value specified ** by its 2nd argument. ** ** The sqlite3_result_error() and sqlite3_result_error16() functions @@ -4458,8 +3926,8 @@ typedef void (*sqlite3_destructor_type)(void*); ** SQLite uses the string pointed to by the ** 2nd parameter of sqlite3_result_error() or sqlite3_result_error16() ** as the text of an error message. SQLite interprets the error -** message string from sqlite3_result_error() as UTF-8. SQLite -** interprets the string from sqlite3_result_error16() as UTF-16 in native +** message string from sqlite3_result_error() as UTF8. SQLite +** interprets the string from sqlite3_result_error16() as UTF16 in native ** byte order. If the third parameter to sqlite3_result_error() ** or sqlite3_result_error16() is negative then SQLite takes as the error ** message all text up through the first zero character. @@ -4467,7 +3935,7 @@ typedef void (*sqlite3_destructor_type)(void*); ** sqlite3_result_error16() is non-negative then SQLite takes that many ** bytes (not characters) from the 2nd parameter as the error message. ** The sqlite3_result_error() and sqlite3_result_error16() -** routines make a private copy of the error message text before +** routines make a copy private copy of the error message text before ** they return. Hence, the calling function can deallocate or ** modify the text after they return without harm. ** The sqlite3_result_error_code() function changes the error code @@ -4475,11 +3943,11 @@ typedef void (*sqlite3_destructor_type)(void*); ** the error code is SQLITE_ERROR. A subsequent call to sqlite3_result_error() ** or sqlite3_result_error16() resets the error code to SQLITE_ERROR. ** -** The sqlite3_result_toobig() interface causes SQLite to throw an error -** indicating that a string or BLOB is to long to represent. -** -** The sqlite3_result_nomem() interface causes SQLite to throw an error -** indicating that a memory allocation failed. +** The sqlite3_result_toobig() interface causes SQLite +** to throw an error indicating that a string or BLOB is to long +** to represent. The sqlite3_result_nomem() interface +** causes SQLite to throw an exception indicating that the a +** memory allocation failed. ** ** The sqlite3_result_int() interface sets the return value ** of the application-defined function to be the 32-bit signed integer @@ -4491,7 +3959,7 @@ typedef void (*sqlite3_destructor_type)(void*); ** The sqlite3_result_null() interface sets the return value ** of the application-defined function to be NULL. ** -** The sqlite3_result_text(), sqlite3_result_text16(), +** The sqlite3_result_text(), sqlite3_result_text16(), ** sqlite3_result_text16le(), and sqlite3_result_text16be() interfaces ** set the return value of the application-defined function to be ** a text string which is represented as UTF-8, UTF-16 native byte order, @@ -4499,7 +3967,7 @@ typedef void (*sqlite3_destructor_type)(void*); ** SQLite takes the text result from the application from ** the 2nd parameter of the sqlite3_result_text* interfaces. ** If the 3rd parameter to the sqlite3_result_text* interfaces -** is negative, then SQLite takes result text from the 2nd parameter +** is negative, then SQLite takes result text from the 2nd parameter ** through the first zero character. ** If the 3rd parameter to the sqlite3_result_text* interfaces ** is non-negative, then as many bytes (not characters) of the text @@ -4507,12 +3975,13 @@ typedef void (*sqlite3_destructor_type)(void*); ** function result. ** If the 4th parameter to the sqlite3_result_text* interfaces ** or sqlite3_result_blob is a non-NULL pointer, then SQLite calls that -** function as the destructor on the text or BLOB result when it has +** function as the destructor on the text or blob result when it has +** finished using that result. +** If the 4th parameter to the sqlite3_result_text* interfaces +** or sqlite3_result_blob is the special constant SQLITE_STATIC, then +** SQLite assumes that the text or blob result is constant space and +** does not copy the space or call a destructor when it has ** finished using that result. -** If the 4th parameter to the sqlite3_result_text* interfaces or -** sqlite3_result_blob is the special constant SQLITE_STATIC, then SQLite -** assumes that the text or BLOB result is in constant space and does not -** copy the it or call a destructor when it has finished using that result. ** If the 4th parameter to the sqlite3_result_text* interfaces ** or sqlite3_result_blob is the special constant SQLITE_TRANSIENT ** then SQLite makes a copy of the result into space obtained from @@ -4522,109 +3991,109 @@ typedef void (*sqlite3_destructor_type)(void*); ** the application-defined function to be a copy the ** [unprotected sqlite3_value] object specified by the 2nd parameter. The ** sqlite3_result_value() interface makes a copy of the [sqlite3_value] -** so that the [sqlite3_value] specified in the parameter may change or +** so that [sqlite3_value] specified in the parameter may change or ** be deallocated after sqlite3_result_value() returns without harm. ** A [protected sqlite3_value] object may always be used where an ** [unprotected sqlite3_value] object is required, so either ** kind of [sqlite3_value] object can be used with this interface. ** -** If these routines are called from within the different thread -** than the one containing the application-defined function that received +** If these routines are called from within the different thread +** than the one containing the application-defined function that recieved ** the [sqlite3_context] pointer, the results are undefined. ** ** INVARIANTS: ** -** {H16403} The default return value from any SQL function is NULL. +** {F16403} The default return value from any SQL function is NULL. ** -** {H16406} The [sqlite3_result_blob(C,V,N,D)] interface changes the -** return value of function C to be a BLOB that is N bytes +** {F16406} The [sqlite3_result_blob(C,V,N,D)] interface changes the +** return value of function C to be a blob that is N bytes ** in length and with content pointed to by V. ** -** {H16409} The [sqlite3_result_double(C,V)] interface changes the +** {F16409} The [sqlite3_result_double(C,V)] interface changes the ** return value of function C to be the floating point value V. ** -** {H16412} The [sqlite3_result_error(C,V,N)] interface changes the return +** {F16412} The [sqlite3_result_error(C,V,N)] interface changes the return ** value of function C to be an exception with error code -** [SQLITE_ERROR] and a UTF-8 error message copied from V up to the +** [SQLITE_ERROR] and a UTF8 error message copied from V up to the ** first zero byte or until N bytes are read if N is positive. ** -** {H16415} The [sqlite3_result_error16(C,V,N)] interface changes the return +** {F16415} The [sqlite3_result_error16(C,V,N)] interface changes the return ** value of function C to be an exception with error code -** [SQLITE_ERROR] and a UTF-16 native byte order error message +** [SQLITE_ERROR] and a UTF16 native byte order error message ** copied from V up to the first zero terminator or until N bytes ** are read if N is positive. ** -** {H16418} The [sqlite3_result_error_toobig(C)] interface changes the return +** {F16418} The [sqlite3_result_error_toobig(C)] interface changes the return ** value of the function C to be an exception with error code ** [SQLITE_TOOBIG] and an appropriate error message. ** -** {H16421} The [sqlite3_result_error_nomem(C)] interface changes the return +** {F16421} The [sqlite3_result_error_nomem(C)] interface changes the return ** value of the function C to be an exception with error code ** [SQLITE_NOMEM] and an appropriate error message. ** -** {H16424} The [sqlite3_result_error_code(C,E)] interface changes the return +** {F16424} The [sqlite3_result_error_code(C,E)] interface changes the return ** value of the function C to be an exception with error code E. ** The error message text is unchanged. ** -** {H16427} The [sqlite3_result_int(C,V)] interface changes the +** {F16427} The [sqlite3_result_int(C,V)] interface changes the ** return value of function C to be the 32-bit integer value V. ** -** {H16430} The [sqlite3_result_int64(C,V)] interface changes the +** {F16430} The [sqlite3_result_int64(C,V)] interface changes the ** return value of function C to be the 64-bit integer value V. ** -** {H16433} The [sqlite3_result_null(C)] interface changes the +** {F16433} The [sqlite3_result_null(C)] interface changes the ** return value of function C to be NULL. ** -** {H16436} The [sqlite3_result_text(C,V,N,D)] interface changes the -** return value of function C to be the UTF-8 string +** {F16436} The [sqlite3_result_text(C,V,N,D)] interface changes the +** return value of function C to be the UTF8 string ** V up to the first zero if N is negative ** or the first N bytes of V if N is non-negative. ** -** {H16439} The [sqlite3_result_text16(C,V,N,D)] interface changes the -** return value of function C to be the UTF-16 native byte order -** string V up to the first zero if N is negative -** or the first N bytes of V if N is non-negative. +** {F16439} The [sqlite3_result_text16(C,V,N,D)] interface changes the +** return value of function C to be the UTF16 native byte order +** string V up to the first zero if N is +** negative or the first N bytes of V if N is non-negative. ** -** {H16442} The [sqlite3_result_text16be(C,V,N,D)] interface changes the -** return value of function C to be the UTF-16 big-endian -** string V up to the first zero if N is negative -** or the first N bytes or V if N is non-negative. +** {F16442} The [sqlite3_result_text16be(C,V,N,D)] interface changes the +** return value of function C to be the UTF16 big-endian +** string V up to the first zero if N is +** is negative or the first N bytes or V if N is non-negative. ** -** {H16445} The [sqlite3_result_text16le(C,V,N,D)] interface changes the -** return value of function C to be the UTF-16 little-endian -** string V up to the first zero if N is negative -** or the first N bytes of V if N is non-negative. +** {F16445} The [sqlite3_result_text16le(C,V,N,D)] interface changes the +** return value of function C to be the UTF16 little-endian +** string V up to the first zero if N is +** negative or the first N bytes of V if N is non-negative. ** -** {H16448} The [sqlite3_result_value(C,V)] interface changes the -** return value of function C to be the [unprotected sqlite3_value] +** {F16448} The [sqlite3_result_value(C,V)] interface changes the +** return value of function C to be [unprotected sqlite3_value] ** object V. ** -** {H16451} The [sqlite3_result_zeroblob(C,N)] interface changes the -** return value of function C to be an N-byte BLOB of all zeros. +** {F16451} The [sqlite3_result_zeroblob(C,N)] interface changes the +** return value of function C to be an N-byte blob of all zeros. ** -** {H16454} The [sqlite3_result_error()] and [sqlite3_result_error16()] +** {F16454} The [sqlite3_result_error()] and [sqlite3_result_error16()] ** interfaces make a copy of their error message strings before ** returning. ** -** {H16457} If the D destructor parameter to [sqlite3_result_blob(C,V,N,D)], +** {F16457} If the D destructor parameter to [sqlite3_result_blob(C,V,N,D)], ** [sqlite3_result_text(C,V,N,D)], [sqlite3_result_text16(C,V,N,D)], ** [sqlite3_result_text16be(C,V,N,D)], or ** [sqlite3_result_text16le(C,V,N,D)] is the constant [SQLITE_STATIC] ** then no destructor is ever called on the pointer V and SQLite ** assumes that V is immutable. ** -** {H16460} If the D destructor parameter to [sqlite3_result_blob(C,V,N,D)], +** {F16460} If the D destructor parameter to [sqlite3_result_blob(C,V,N,D)], ** [sqlite3_result_text(C,V,N,D)], [sqlite3_result_text16(C,V,N,D)], ** [sqlite3_result_text16be(C,V,N,D)], or ** [sqlite3_result_text16le(C,V,N,D)] is the constant ** [SQLITE_TRANSIENT] then the interfaces makes a copy of the ** content of V and retains the copy. ** -** {H16463} If the D destructor parameter to [sqlite3_result_blob(C,V,N,D)], +** {F16463} If the D destructor parameter to [sqlite3_result_blob(C,V,N,D)], ** [sqlite3_result_text(C,V,N,D)], [sqlite3_result_text16(C,V,N,D)], ** [sqlite3_result_text16be(C,V,N,D)], or ** [sqlite3_result_text16le(C,V,N,D)] is some value other than -** the constants [SQLITE_STATIC] and [SQLITE_TRANSIENT] then +** the constants [SQLITE_STATIC] and [SQLITE_TRANSIENT] then ** SQLite will invoke the destructor D with V as its only argument ** when it has finished with the V value. */ @@ -4646,10 +4115,10 @@ void sqlite3_result_value(sqlite3_context*, sqlite3_value*); void sqlite3_result_zeroblob(sqlite3_context*, int n); /* -** CAPI3REF: Define New Collating Sequences {H16600} +** CAPI3REF: Define New Collating Sequences {F16600} ** ** These functions are used to add new collation sequences to the -** [database connection] specified as the first argument. +** [sqlite3*] handle specified as the first argument. ** ** The name of the new collation sequence is specified as a UTF-8 string ** for sqlite3_create_collation() and sqlite3_create_collation_v2() @@ -4659,79 +4128,81 @@ void sqlite3_result_zeroblob(sqlite3_context*, int n); ** The third argument may be one of the constants [SQLITE_UTF8], ** [SQLITE_UTF16LE] or [SQLITE_UTF16BE], indicating that the user-supplied ** routine expects to be passed pointers to strings encoded using UTF-8, -** UTF-16 little-endian, or UTF-16 big-endian, respectively. The +** UTF-16 little-endian or UTF-16 big-endian respectively. The ** third argument might also be [SQLITE_UTF16_ALIGNED] to indicate that ** the routine expects pointers to 16-bit word aligned strings -** of UTF-16 in the native byte order of the host computer. +** of UTF16 in the native byte order of the host computer. ** ** A pointer to the user supplied routine must be passed as the fifth ** argument. If it is NULL, this is the same as deleting the collation ** sequence (so that SQLite cannot call it anymore). -** Each time the application supplied function is invoked, it is passed -** as its first parameter a copy of the void* passed as the fourth argument -** to sqlite3_create_collation() or sqlite3_create_collation16(). +** Each time the application +** supplied function is invoked, it is passed a copy of the void* passed as +** the fourth argument to sqlite3_create_collation() or +** sqlite3_create_collation16() as its first parameter. ** ** The remaining arguments to the application-supplied routine are two strings, ** each represented by a (length, data) pair and encoded in the encoding ** that was passed as the third argument when the collation sequence was -** registered. {END} The application defined collation routine should -** return negative, zero or positive if the first string is less than, -** equal to, or greater than the second string. i.e. (STRING1 - STRING2). +** registered. {END} The application defined collation routine should +** return negative, zero or positive if +** the first string is less than, equal to, or greater than the second +** string. i.e. (STRING1 - STRING2). ** ** The sqlite3_create_collation_v2() works like sqlite3_create_collation() -** except that it takes an extra argument which is a destructor for +** excapt that it takes an extra argument which is a destructor for ** the collation. The destructor is called when the collation is ** destroyed and is passed a copy of the fourth parameter void* pointer ** of the sqlite3_create_collation_v2(). -** Collations are destroyed when they are overridden by later calls to the -** collation creation functions or when the [database connection] is closed -** using [sqlite3_close()]. +** Collations are destroyed when +** they are overridden by later calls to the collation creation functions +** or when the [sqlite3*] database handle is closed using [sqlite3_close()]. ** ** INVARIANTS: ** -** {H16603} A successful call to the +** {F16603} A successful call to the ** [sqlite3_create_collation_v2(B,X,E,P,F,D)] interface ** registers function F as the comparison function used to -** implement collation X on the [database connection] B for +** implement collation X on [database connection] B for ** databases having encoding E. ** -** {H16604} SQLite understands the X parameter to +** {F16604} SQLite understands the X parameter to ** [sqlite3_create_collation_v2(B,X,E,P,F,D)] as a zero-terminated ** UTF-8 string in which case is ignored for ASCII characters and ** is significant for non-ASCII characters. ** -** {H16606} Successive calls to [sqlite3_create_collation_v2(B,X,E,P,F,D)] +** {F16606} Successive calls to [sqlite3_create_collation_v2(B,X,E,P,F,D)] ** with the same values for B, X, and E, override prior values ** of P, F, and D. ** -** {H16609} If the destructor D in [sqlite3_create_collation_v2(B,X,E,P,F,D)] +** {F16609} The destructor D in [sqlite3_create_collation_v2(B,X,E,P,F,D)] ** is not NULL then it is called with argument P when the ** collating function is dropped by SQLite. ** -** {H16612} A collating function is dropped when it is overloaded. +** {F16612} A collating function is dropped when it is overloaded. ** -** {H16615} A collating function is dropped when the database connection +** {F16615} A collating function is dropped when the database connection ** is closed using [sqlite3_close()]. ** -** {H16618} The pointer P in [sqlite3_create_collation_v2(B,X,E,P,F,D)] +** {F16618} The pointer P in [sqlite3_create_collation_v2(B,X,E,P,F,D)] ** is passed through as the first parameter to the comparison ** function F for all subsequent invocations of F. ** -** {H16621} A call to [sqlite3_create_collation(B,X,E,P,F)] is exactly +** {F16621} A call to [sqlite3_create_collation(B,X,E,P,F)] is exactly ** the same as a call to [sqlite3_create_collation_v2()] with ** the same parameters and a NULL destructor. ** -** {H16624} Following a [sqlite3_create_collation_v2(B,X,E,P,F,D)], +** {F16624} Following a [sqlite3_create_collation_v2(B,X,E,P,F,D)], ** SQLite uses the comparison function F for all text comparison -** operations on the [database connection] B on text values that -** use the collating sequence named X. +** operations on [database connection] B on text values that +** use the collating sequence name X. ** -** {H16627} The [sqlite3_create_collation16(B,X,E,P,F)] works the same +** {F16627} The [sqlite3_create_collation16(B,X,E,P,F)] works the same ** as [sqlite3_create_collation(B,X,E,P,F)] except that the ** collation name X is understood as UTF-16 in native byte order ** instead of UTF-8. ** -** {H16630} When multiple comparison functions are available for the same +** {F16630} When multiple comparison functions are available for the same ** collating sequence, SQLite chooses the one whose text encoding ** requires the least amount of conversion from the default ** text encoding of the database. @@ -4753,32 +4224,33 @@ int sqlite3_create_collation_v2( ); int sqlite3_create_collation16( sqlite3*, - const void *zName, + const char *zName, int eTextRep, void*, int(*xCompare)(void*,int,const void*,int,const void*) ); /* -** CAPI3REF: Collation Needed Callbacks {H16700} +** CAPI3REF: Collation Needed Callbacks {F16700} ** ** To avoid having to register all collation sequences before a database ** can be used, a single callback function may be registered with the -** [database connection] to be called whenever an undefined collation -** sequence is required. +** database handle to be called whenever an undefined collation sequence is +** required. ** ** If the function is registered using the sqlite3_collation_needed() API, ** then it is passed the names of undefined collation sequences as strings -** encoded in UTF-8. {H16703} If sqlite3_collation_needed16() is used, -** the names are passed as UTF-16 in machine native byte order. -** A call to either function replaces any existing callback. +** encoded in UTF-8. {F16703} If sqlite3_collation_needed16() is used, the names +** are passed as UTF-16 in machine native byte order. A call to either +** function replaces any existing callback. ** ** When the callback is invoked, the first argument passed is a copy ** of the second argument to sqlite3_collation_needed() or ** sqlite3_collation_needed16(). The second argument is the database -** connection. The third argument is one of [SQLITE_UTF8], [SQLITE_UTF16BE], -** or [SQLITE_UTF16LE], indicating the most desirable form of the collation -** sequence function required. The fourth parameter is the name of the +** handle. The third argument is one of [SQLITE_UTF8], +** [SQLITE_UTF16BE], or [SQLITE_UTF16LE], indicating the most +** desirable form of the collation sequence function required. +** The fourth parameter is the name of the ** required collation sequence. ** ** The callback function should register the desired collation using @@ -4787,22 +4259,24 @@ int sqlite3_create_collation16( ** ** INVARIANTS: ** -** {H16702} A successful call to [sqlite3_collation_needed(D,P,F)] +** {F16702} A successful call to [sqlite3_collation_needed(D,P,F)] ** or [sqlite3_collation_needed16(D,P,F)] causes ** the [database connection] D to invoke callback F with first ** parameter P whenever it needs a comparison function for a ** collating sequence that it does not know about. ** -** {H16704} Each successful call to [sqlite3_collation_needed()] or +** {F16704} Each successful call to [sqlite3_collation_needed()] or ** [sqlite3_collation_needed16()] overrides the callback registered ** on the same [database connection] by prior calls to either ** interface. ** -** {H16706} The name of the requested collating function passed in the +** {F16706} The name of the requested collating function passed in the ** 4th parameter to the callback is in UTF-8 if the callback ** was registered using [sqlite3_collation_needed()] and ** is in UTF-16 native byte order if the callback was ** registered using [sqlite3_collation_needed16()]. +** +** */ int sqlite3_collation_needed( sqlite3*, @@ -4841,14 +4315,15 @@ int sqlite3_rekey( ); /* -** CAPI3REF: Suspend Execution For A Short Time {H10530} +** CAPI3REF: Suspend Execution For A Short Time {F10530} ** -** The sqlite3_sleep() function causes the current thread to suspend execution +** The sqlite3_sleep() function +** causes the current thread to suspend execution ** for at least a number of milliseconds specified in its parameter. ** -** If the operating system does not support sleep requests with -** millisecond time resolution, then the time will be rounded up to -** the nearest second. The number of milliseconds of sleep actually +** If the operating system does not support sleep requests with +** millisecond time resolution, then the time will be rounded up to +** the nearest second. The number of milliseconds of sleep actually ** requested from the operating system is returned. ** ** SQLite implements this interface by calling the xSleep() @@ -4856,27 +4331,27 @@ int sqlite3_rekey( ** ** INVARIANTS: ** -** {H10533} The [sqlite3_sleep(M)] interface invokes the xSleep +** {F10533} The [sqlite3_sleep(M)] interface invokes the xSleep ** method of the default [sqlite3_vfs|VFS] in order to ** suspend execution of the current thread for at least ** M milliseconds. ** -** {H10536} The [sqlite3_sleep(M)] interface returns the number of +** {F10536} The [sqlite3_sleep(M)] interface returns the number of ** milliseconds of sleep actually requested of the operating ** system, which might be larger than the parameter M. */ int sqlite3_sleep(int); /* -** CAPI3REF: Name Of The Folder Holding Temporary Files {H10310} +** CAPI3REF: Name Of The Folder Holding Temporary Files {F10310} ** ** If this global variable is made to point to a string which is -** the name of a folder (a.k.a. directory), then all temporary files +** the name of a folder (a.ka. directory), then all temporary files ** created by SQLite will be placed in that directory. If this variable -** is a NULL pointer, then SQLite performs a search for an appropriate -** temporary file directory. +** is NULL pointer, then SQLite does a search for an appropriate temporary +** file directory. ** -** It is not safe to modify this variable once a [database connection] +** It is not safe to modify this variable once a database connection ** has been opened. It is intended that this variable be set once ** as part of process initialization and before any SQLite interface ** routines have been call and remain unchanged thereafter. @@ -4884,99 +4359,65 @@ int sqlite3_sleep(int); SQLITE_EXTERN char *sqlite3_temp_directory; /* -** CAPI3REF: Test For Auto-Commit Mode {H12930} -** KEYWORDS: {autocommit mode} +** CAPI3REF: Test To See If The Database Is In Auto-Commit Mode {F12930} ** -** The sqlite3_get_autocommit() interface returns non-zero or +** The sqlite3_get_autocommit() interfaces returns non-zero or ** zero if the given database connection is or is not in autocommit mode, -** respectively. Autocommit mode is on by default. -** Autocommit mode is disabled by a [BEGIN] statement. -** Autocommit mode is re-enabled by a [COMMIT] or [ROLLBACK]. +** respectively. Autocommit mode is on +** by default. Autocommit mode is disabled by a [BEGIN] statement. +** Autocommit mode is reenabled by a [COMMIT] or [ROLLBACK]. ** ** If certain kinds of errors occur on a statement within a multi-statement -** transaction (errors including [SQLITE_FULL], [SQLITE_IOERR], +** transactions (errors including [SQLITE_FULL], [SQLITE_IOERR], ** [SQLITE_NOMEM], [SQLITE_BUSY], and [SQLITE_INTERRUPT]) then the ** transaction might be rolled back automatically. The only way to -** find out whether SQLite automatically rolled back the transaction after +** find out if SQLite automatically rolled back the transaction after ** an error is to use this function. ** ** INVARIANTS: ** -** {H12931} The [sqlite3_get_autocommit(D)] interface returns non-zero or +** {F12931} The [sqlite3_get_autocommit(D)] interface returns non-zero or ** zero if the [database connection] D is or is not in autocommit ** mode, respectively. ** -** {H12932} Autocommit mode is on by default. +** {F12932} Autocommit mode is on by default. ** -** {H12933} Autocommit mode is disabled by a successful [BEGIN] statement. +** {F12933} Autocommit mode is disabled by a successful [BEGIN] statement. ** -** {H12934} Autocommit mode is enabled by a successful [COMMIT] or [ROLLBACK] +** {F12934} Autocommit mode is enabled by a successful [COMMIT] or [ROLLBACK] ** statement. +** ** -** ASSUMPTIONS: -** -** {A12936} If another thread changes the autocommit status of the database +** LIMITATIONS: +*** +** {U12936} If another thread changes the autocommit status of the database ** connection while this routine is running, then the return value ** is undefined. */ int sqlite3_get_autocommit(sqlite3*); /* -** CAPI3REF: Find The Database Handle Of A Prepared Statement {H13120} +** CAPI3REF: Find The Database Handle Of A Prepared Statement {F13120} ** -** The sqlite3_db_handle interface returns the [database connection] handle -** to which a [prepared statement] belongs. The database handle returned by -** sqlite3_db_handle is the same database handle that was the first argument -** to the [sqlite3_prepare_v2()] call (or its variants) that was used to -** create the statement in the first place. +** The sqlite3_db_handle interface +** returns the [sqlite3*] database handle to which a +** [prepared statement] belongs. +** The database handle returned by sqlite3_db_handle +** is the same database handle that was +** the first argument to the [sqlite3_prepare_v2()] or its variants +** that was used to create the statement in the first place. ** ** INVARIANTS: ** -** {H13123} The [sqlite3_db_handle(S)] interface returns a pointer -** to the [database connection] associated with the +** {F13123} The [sqlite3_db_handle(S)] interface returns a pointer +** to the [database connection] associated with ** [prepared statement] S. */ sqlite3 *sqlite3_db_handle(sqlite3_stmt*); -/* -** CAPI3REF: Find the next prepared statement {H13140} -** -** This interface returns a pointer to the next [prepared statement] after -** pStmt associated with the [database connection] pDb. If pStmt is NULL -** then this interface returns a pointer to the first prepared statement -** associated with the database connection pDb. If no prepared statement -** satisfies the conditions of this routine, it returns NULL. -** -** INVARIANTS: -** -** {H13143} If D is a [database connection] that holds one or more -** unfinalized [prepared statements] and S is a NULL pointer, -** then [sqlite3_next_stmt(D, S)] routine shall return a pointer -** to one of the prepared statements associated with D. -** -** {H13146} If D is a [database connection] that holds no unfinalized -** [prepared statements] and S is a NULL pointer, then -** [sqlite3_next_stmt(D, S)] routine shall return a NULL pointer. -** -** {H13149} If S is a [prepared statement] in the [database connection] D -** and S is not the last prepared statement in D, then -** [sqlite3_next_stmt(D, S)] routine shall return a pointer -** to the next prepared statement in D after S. -** -** {H13152} If S is the last [prepared statement] in the -** [database connection] D then the [sqlite3_next_stmt(D, S)] -** routine shall return a NULL pointer. -** -** ASSUMPTIONS: -** -** {A13154} The [database connection] pointer D in a call to -** [sqlite3_next_stmt(D,S)] must refer to an open database -** connection and in particular must not be a NULL pointer. -*/ -sqlite3_stmt *sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt); /* -** CAPI3REF: Commit And Rollback Notification Callbacks {H12950} +** CAPI3REF: Commit And Rollback Notification Callbacks {F12950} ** ** The sqlite3_commit_hook() interface registers a callback ** function to be invoked whenever a transaction is committed. @@ -4986,24 +4427,16 @@ sqlite3_stmt *sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt); ** function to be invoked whenever a transaction is committed. ** Any callback set by a previous call to sqlite3_commit_hook() ** for the same database connection is overridden. -** The pArg argument is passed through to the callback. -** If the callback on a commit hook function returns non-zero, -** then the commit is converted into a rollback. +** The pArg argument is passed through +** to the callback. If the callback on a commit hook function +** returns non-zero, then the commit is converted into a rollback. ** ** If another function was previously registered, its ** pArg value is returned. Otherwise NULL is returned. ** -** The callback implementation must not do anything that will modify -** the database connection that invoked the callback. Any actions -** to modify the database connection must be deferred until after the -** completion of the [sqlite3_step()] call that triggered the commit -** or rollback hook in the first place. -** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their -** database connections for the meaning of "modify" in this paragraph. -** ** Registering a NULL function disables the callback. ** -** For the purposes of this API, a transaction is said to have been +** For the purposes of this API, a transaction is said to have been ** rolled back if an explicit "ROLLBACK" statement is executed, or ** an error or constraint causes an implicit rollback to occur. ** The rollback callback is not invoked if a transaction is @@ -5012,108 +4445,107 @@ sqlite3_stmt *sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt); ** rolled back because a commit callback returned non-zero. ** Check on this ** +** These are experimental interfaces and are subject to change. +** ** INVARIANTS: ** -** {H12951} The [sqlite3_commit_hook(D,F,P)] interface registers the +** {F12951} The [sqlite3_commit_hook(D,F,P)] interface registers the ** callback function F to be invoked with argument P whenever -** a transaction commits on the [database connection] D. +** a transaction commits on [database connection] D. ** -** {H12952} The [sqlite3_commit_hook(D,F,P)] interface returns the P argument -** from the previous call with the same [database connection] D, -** or NULL on the first call for a particular database connection D. +** {F12952} The [sqlite3_commit_hook(D,F,P)] interface returns the P +** argument from the previous call with the same +** [database connection ] D , or NULL on the first call +** for a particular [database connection] D. ** -** {H12953} Each call to [sqlite3_commit_hook()] overwrites the callback +** {F12953} Each call to [sqlite3_commit_hook()] overwrites the callback ** registered by prior calls. ** -** {H12954} If the F argument to [sqlite3_commit_hook(D,F,P)] is NULL -** then the commit hook callback is canceled and no callback +** {F12954} If the F argument to [sqlite3_commit_hook(D,F,P)] is NULL +** then the commit hook callback is cancelled and no callback ** is invoked when a transaction commits. ** -** {H12955} If the commit callback returns non-zero then the commit is +** {F12955} If the commit callback returns non-zero then the commit is ** converted into a rollback. ** -** {H12961} The [sqlite3_rollback_hook(D,F,P)] interface registers the +** {F12961} The [sqlite3_rollback_hook(D,F,P)] interface registers the ** callback function F to be invoked with argument P whenever -** a transaction rolls back on the [database connection] D. +** a transaction rolls back on [database connection] D. ** -** {H12962} The [sqlite3_rollback_hook(D,F,P)] interface returns the P -** argument from the previous call with the same -** [database connection] D, or NULL on the first call -** for a particular database connection D. +** {F12962} The [sqlite3_rollback_hook(D,F,P)] interface returns the P +** argument from the previous call with the same +** [database connection ] D , or NULL on the first call +** for a particular [database connection] D. ** -** {H12963} Each call to [sqlite3_rollback_hook()] overwrites the callback +** {F12963} Each call to [sqlite3_rollback_hook()] overwrites the callback ** registered by prior calls. ** -** {H12964} If the F argument to [sqlite3_rollback_hook(D,F,P)] is NULL -** then the rollback hook callback is canceled and no callback +** {F12964} If the F argument to [sqlite3_rollback_hook(D,F,P)] is NULL +** then the rollback hook callback is cancelled and no callback ** is invoked when a transaction rolls back. */ void *sqlite3_commit_hook(sqlite3*, int(*)(void*), void*); void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*); /* -** CAPI3REF: Data Change Notification Callbacks {H12970} +** CAPI3REF: Data Change Notification Callbacks {F12970} ** -** The sqlite3_update_hook() interface registers a callback function -** with the [database connection] identified by the first argument -** to be invoked whenever a row is updated, inserted or deleted. -** Any callback set by a previous call to this function -** for the same database connection is overridden. +** The sqlite3_update_hook() interface +** registers a callback function with the database connection identified by the +** first argument to be invoked whenever a row is updated, inserted or deleted. +** Any callback set by a previous call to this function for the same +** database connection is overridden. ** -** The second argument is a pointer to the function to invoke when a -** row is updated, inserted or deleted. -** The first argument to the callback is a copy of the third argument -** to sqlite3_update_hook(). -** The second callback argument is one of [SQLITE_INSERT], [SQLITE_DELETE], -** or [SQLITE_UPDATE], depending on the operation that caused the callback -** to be invoked. -** The third and fourth arguments to the callback contain pointers to the -** database and table name containing the affected row. -** The final callback parameter is the rowid of the row. In the case of -** an update, this is the rowid after the update takes place. +** The second argument is a pointer to the function to invoke when a +** row is updated, inserted or deleted. +** The first argument to the callback is +** a copy of the third argument to sqlite3_update_hook(). +** The second callback +** argument is one of [SQLITE_INSERT], [SQLITE_DELETE] or [SQLITE_UPDATE], +** depending on the operation that caused the callback to be invoked. +** The third and +** fourth arguments to the callback contain pointers to the database and +** table name containing the affected row. +** The final callback parameter is +** the rowid of the row. +** In the case of an update, this is the rowid after +** the update takes place. ** ** The update hook is not invoked when internal system tables are ** modified (i.e. sqlite_master and sqlite_sequence). ** -** The update hook implementation must not do anything that will modify -** the database connection that invoked the update hook. Any actions -** to modify the database connection must be deferred until after the -** completion of the [sqlite3_step()] call that triggered the update hook. -** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their -** database connections for the meaning of "modify" in this paragraph. -** ** If another function was previously registered, its pArg value ** is returned. Otherwise NULL is returned. ** ** INVARIANTS: ** -** {H12971} The [sqlite3_update_hook(D,F,P)] interface causes the callback +** {F12971} The [sqlite3_update_hook(D,F,P)] interface causes callback ** function F to be invoked with first parameter P whenever ** a table row is modified, inserted, or deleted on -** the [database connection] D. +** [database connection] D. ** -** {H12973} The [sqlite3_update_hook(D,F,P)] interface returns the value +** {F12973} The [sqlite3_update_hook(D,F,P)] interface returns the value ** of P for the previous call on the same [database connection] D, ** or NULL for the first call. ** -** {H12975} If the update hook callback F in [sqlite3_update_hook(D,F,P)] +** {F12975} If the update hook callback F in [sqlite3_update_hook(D,F,P)] ** is NULL then the no update callbacks are made. ** -** {H12977} Each call to [sqlite3_update_hook(D,F,P)] overrides prior calls +** {F12977} Each call to [sqlite3_update_hook(D,F,P)] overrides prior calls ** to the same interface on the same [database connection] D. ** -** {H12979} The update hook callback is not invoked when internal system +** {F12979} The update hook callback is not invoked when internal system ** tables such as sqlite_master and sqlite_sequence are modified. ** -** {H12981} The second parameter to the update callback +** {F12981} The second parameter to the update callback ** is one of [SQLITE_INSERT], [SQLITE_DELETE] or [SQLITE_UPDATE], ** depending on the operation that caused the callback to be invoked. ** -** {H12983} The third and fourth arguments to the callback contain pointers +** {F12983} The third and fourth arguments to the callback contain pointers ** to zero-terminated UTF-8 strings which are the names of the ** database and table that is being updated. -** {H12985} The final callback parameter is the rowid of the row after +** {F12985} The final callback parameter is the rowid of the row after ** the change occurs. */ void *sqlite3_update_hook( @@ -5123,92 +4555,96 @@ void *sqlite3_update_hook( ); /* -** CAPI3REF: Enable Or Disable Shared Pager Cache {H10330} -** KEYWORDS: {shared cache} {shared cache mode} +** CAPI3REF: Enable Or Disable Shared Pager Cache {F10330} ** ** This routine enables or disables the sharing of the database cache -** and schema data structures between [database connection | connections] -** to the same database. Sharing is enabled if the argument is true -** and disabled if the argument is false. +** and schema data structures between connections to the same database. +** Sharing is enabled if the argument is true and disabled if the argument +** is false. ** -** Cache sharing is enabled and disabled for an entire process. {END} -** This is a change as of SQLite version 3.5.0. In prior versions of SQLite, -** sharing was enabled or disabled for each thread separately. +** Cache sharing is enabled and disabled +** for an entire process. {END} This is a change as of SQLite version 3.5.0. +** In prior versions of SQLite, sharing was +** enabled or disabled for each thread separately. ** ** The cache sharing mode set by this interface effects all subsequent ** calls to [sqlite3_open()], [sqlite3_open_v2()], and [sqlite3_open16()]. ** Existing database connections continue use the sharing mode ** that was in effect at the time they were opened. ** -** Virtual tables cannot be used with a shared cache. When shared +** Virtual tables cannot be used with a shared cache. When shared ** cache is enabled, the [sqlite3_create_module()] API used to register ** virtual tables will always return an error. ** -** This routine returns [SQLITE_OK] if shared cache was enabled or disabled -** successfully. An [error code] is returned otherwise. +** This routine returns [SQLITE_OK] if shared cache was +** enabled or disabled successfully. An [error code] +** is returned otherwise. ** ** Shared cache is disabled by default. But this might change in ** future releases of SQLite. Applications that care about shared ** cache setting should set it explicitly. ** ** INVARIANTS: -** -** {H10331} A successful invocation of [sqlite3_enable_shared_cache(B)] +** +** {F10331} A successful invocation of [sqlite3_enable_shared_cache(B)] ** will enable or disable shared cache mode for any subsequently ** created [database connection] in the same process. ** -** {H10336} When shared cache is enabled, the [sqlite3_create_module()] +** {F10336} When shared cache is enabled, the [sqlite3_create_module()] ** interface will always return an error. ** -** {H10337} The [sqlite3_enable_shared_cache(B)] interface returns +** {F10337} The [sqlite3_enable_shared_cache(B)] interface returns ** [SQLITE_OK] if shared cache was enabled or disabled successfully. ** -** {H10339} Shared cache is disabled by default. +** {F10339} Shared cache is disabled by default. */ int sqlite3_enable_shared_cache(int); /* -** CAPI3REF: Attempt To Free Heap Memory {H17340} +** CAPI3REF: Attempt To Free Heap Memory {F17340} ** -** The sqlite3_release_memory() interface attempts to free N bytes -** of heap memory by deallocating non-essential memory allocations -** held by the database library. {END} Memory used to cache database -** pages to improve performance is an example of non-essential memory. -** sqlite3_release_memory() returns the number of bytes actually freed, -** which might be more or less than the amount requested. +** The sqlite3_release_memory() interface attempts to +** free N bytes of heap memory by deallocating non-essential memory +** allocations held by the database labrary. {END} Memory used +** to cache database pages to improve performance is an example of +** non-essential memory. Sqlite3_release_memory() returns +** the number of bytes actually freed, which might be more or less +** than the amount requested. ** ** INVARIANTS: ** -** {H17341} The [sqlite3_release_memory(N)] interface attempts to +** {F17341} The [sqlite3_release_memory(N)] interface attempts to ** free N bytes of heap memory by deallocating non-essential -** memory allocations held by the database library. +** memory allocations held by the database labrary. ** -** {H16342} The [sqlite3_release_memory(N)] returns the number +** {F16342} The [sqlite3_release_memory(N)] returns the number ** of bytes actually freed, which might be more or less ** than the amount requested. */ int sqlite3_release_memory(int); /* -** CAPI3REF: Impose A Limit On Heap Size {H17350} +** CAPI3REF: Impose A Limit On Heap Size {F17350} ** -** The sqlite3_soft_heap_limit() interface places a "soft" limit -** on the amount of heap memory that may be allocated by SQLite. -** If an internal allocation is requested that would exceed the -** soft heap limit, [sqlite3_release_memory()] is invoked one or -** more times to free up some space before the allocation is performed. +** The sqlite3_soft_heap_limit() interface +** places a "soft" limit on the amount of heap memory that may be allocated +** by SQLite. If an internal allocation is requested +** that would exceed the soft heap limit, [sqlite3_release_memory()] is +** invoked one or more times to free up some space before the allocation +** is made. ** -** The limit is called "soft", because if [sqlite3_release_memory()] -** cannot free sufficient memory to prevent the limit from being exceeded, +** The limit is called "soft", because if +** [sqlite3_release_memory()] cannot +** free sufficient memory to prevent the limit from being exceeded, ** the memory is allocated anyway and the current operation proceeds. ** ** A negative or zero value for N means that there is no soft heap limit and ** [sqlite3_release_memory()] will only be called when memory is exhausted. ** The default value for the soft heap limit is zero. ** -** SQLite makes a best effort to honor the soft heap limit. -** But if the soft heap limit cannot be honored, execution will -** continue without error or notification. This is why the limit is +** SQLite makes a best effort to honor the soft heap limit. +** But if the soft heap limit cannot honored, execution will +** continue without error or notification. This is why the limit is ** called a "soft" limit. It is advisory only. ** ** Prior to SQLite version 3.5.0, this routine only constrained the memory @@ -5221,79 +4657,81 @@ int sqlite3_release_memory(int); ** ** INVARIANTS: ** -** {H16351} The [sqlite3_soft_heap_limit(N)] interface places a soft limit +** {F16351} The [sqlite3_soft_heap_limit(N)] interface places a soft limit ** of N bytes on the amount of heap memory that may be allocated ** using [sqlite3_malloc()] or [sqlite3_realloc()] at any point ** in time. ** -** {H16352} If a call to [sqlite3_malloc()] or [sqlite3_realloc()] would +** {F16352} If a call to [sqlite3_malloc()] or [sqlite3_realloc()] would ** cause the total amount of allocated memory to exceed the ** soft heap limit, then [sqlite3_release_memory()] is invoked ** in an attempt to reduce the memory usage prior to proceeding ** with the memory allocation attempt. ** -** {H16353} Calls to [sqlite3_malloc()] or [sqlite3_realloc()] that trigger +** {F16353} Calls to [sqlite3_malloc()] or [sqlite3_realloc()] that trigger ** attempts to reduce memory usage through the soft heap limit ** mechanism continue even if the attempt to reduce memory ** usage is unsuccessful. ** -** {H16354} A negative or zero value for N in a call to +** {F16354} A negative or zero value for N in a call to ** [sqlite3_soft_heap_limit(N)] means that there is no soft ** heap limit and [sqlite3_release_memory()] will only be ** called when memory is completely exhausted. ** -** {H16355} The default value for the soft heap limit is zero. +** {F16355} The default value for the soft heap limit is zero. ** -** {H16358} Each call to [sqlite3_soft_heap_limit(N)] overrides the +** {F16358} Each call to [sqlite3_soft_heap_limit(N)] overrides the ** values set by all prior calls. */ void sqlite3_soft_heap_limit(int); /* -** CAPI3REF: Extract Metadata About A Column Of A Table {H12850} +** CAPI3REF: Extract Metadata About A Column Of A Table {F12850} ** -** This routine returns metadata about a specific column of a specific -** database table accessible using the [database connection] handle -** passed as the first function argument. +** This routine +** returns meta-data about a specific column of a specific database +** table accessible using the connection handle passed as the first function +** argument. ** -** The column is identified by the second, third and fourth parameters to +** The column is identified by the second, third and fourth parameters to ** this function. The second parameter is either the name of the database ** (i.e. "main", "temp" or an attached database) containing the specified ** table or NULL. If it is NULL, then all attached databases are searched -** for the table using the same algorithm used by the database engine to +** for the table using the same algorithm as the database engine uses to ** resolve unqualified table references. ** -** The third and fourth parameters to this function are the table and column -** name of the desired column, respectively. Neither of these parameters +** The third and fourth parameters to this function are the table and column +** name of the desired column, respectively. Neither of these parameters ** may be NULL. ** -** Metadata is returned by writing to the memory locations passed as the 5th -** and subsequent parameters to this function. Any of these arguments may be -** NULL, in which case the corresponding element of metadata is omitted. +** Meta information is returned by writing to the memory locations passed as +** the 5th and subsequent parameters to this function. Any of these +** arguments may be NULL, in which case the corresponding element of meta +** information is ommitted. ** -**
      -** -**
      Parameter Output
      Type
      Description +**
      +** Parameter     Output Type      Description
      +** -----------------------------------
       **
      -** 
      5th const char* Data type -**
      6th const char* Name of default collation sequence -**
      7th int True if column has a NOT NULL constraint -**
      8th int True if column is part of the PRIMARY KEY -**
      9th int True if column is AUTOINCREMENT -**
      -**
      +** 5th const char* Data type +** 6th const char* Name of the default collation sequence +** 7th int True if the column has a NOT NULL constraint +** 8th int True if the column is part of the PRIMARY KEY +** 9th int True if the column is AUTOINCREMENT +** ** -** The memory pointed to by the character pointers returned for the -** declaration type and collation sequence is valid only until the next -** call to any SQLite API function. ** -** If the specified table is actually a view, an [error code] is returned. +** The memory pointed to by the character pointers returned for the +** declaration type and collation sequence is valid only until the next +** call to any sqlite API function. ** -** If the specified column is "rowid", "oid" or "_rowid_" and an -** INTEGER PRIMARY KEY column has been explicitly declared, then the output +** If the specified table is actually a view, then an error is returned. +** +** If the specified column is "rowid", "oid" or "_rowid_" and an +** INTEGER PRIMARY KEY column has been explicitly declared, then the output ** parameters are set for the explicitly declared column. If there is no -** explicitly declared INTEGER PRIMARY KEY column, then the output -** parameters are set as follows: +** explicitly declared IPK column, then the output parameters are set as +** follows: ** **
       **     data type: "INTEGER"
      @@ -5305,11 +4743,11 @@ void sqlite3_soft_heap_limit(int);
       **
       ** This function may load one or more schemas from database files. If an
       ** error occurs during this process, or if the requested table or column
      -** cannot be found, an [error code] is returned and an error message left
      -** in the [database connection] (to be retrieved using sqlite3_errmsg()).
      +** cannot be found, an SQLITE error code is returned and an error message
      +** left in the database handle (to be retrieved using sqlite3_errmsg()).
       **
       ** This API is only available if the library was compiled with the
      -** [SQLITE_ENABLE_COLUMN_METADATA] C-preprocessor symbol defined.
      +** SQLITE_ENABLE_COLUMN_METADATA preprocessor symbol defined.
       */
       int sqlite3_table_column_metadata(
         sqlite3 *db,                /* Connection handle */
      @@ -5324,30 +4762,27 @@ int sqlite3_table_column_metadata(
       );
       
       /*
      -** CAPI3REF: Load An Extension {H12600} 
      +** CAPI3REF: Load An Extension {F12600}
       **
      -** This interface loads an SQLite extension library from the named file.
      +** {F12601} The sqlite3_load_extension() interface
      +** attempts to load an SQLite extension library contained in the file
      +** zFile. {F12602} The entry point is zProc. {F12603} zProc may be 0
      +** in which case the name of the entry point defaults
      +** to "sqlite3_extension_init".
       **
      -** {H12601} The sqlite3_load_extension() interface attempts to load an
      -**          SQLite extension library contained in the file zFile.
      +** {F12604} The sqlite3_load_extension() interface shall
      +** return [SQLITE_OK] on success and [SQLITE_ERROR] if something goes wrong.
       **
      -** {H12602} The entry point is zProc.
      +** {F12605}
      +** If an error occurs and pzErrMsg is not 0, then the
      +** sqlite3_load_extension() interface shall attempt to fill *pzErrMsg with 
      +** error message text stored in memory obtained from [sqlite3_malloc()].
      +** {END}  The calling function should free this memory
      +** by calling [sqlite3_free()].
       **
      -** {H12603} zProc may be 0, in which case the name of the entry point
      -**          defaults to "sqlite3_extension_init".
      -**
      -** {H12604} The sqlite3_load_extension() interface shall return
      -**          [SQLITE_OK] on success and [SQLITE_ERROR] if something goes wrong.
      -**
      -** {H12605} If an error occurs and pzErrMsg is not 0, then the
      -**          [sqlite3_load_extension()] interface shall attempt to
      -**          fill *pzErrMsg with error message text stored in memory
      -**          obtained from [sqlite3_malloc()]. {END}  The calling function
      -**          should free this memory by calling [sqlite3_free()].
      -**
      -** {H12606} Extension loading must be enabled using
      -**          [sqlite3_enable_load_extension()] prior to calling this API,
      -**          otherwise an error will be returned.
      +** {F12606}
      +** Extension loading must be enabled using [sqlite3_enable_load_extension()]
      +** prior to calling this API or an error will be returned.
       */
       int sqlite3_load_extension(
         sqlite3 *db,          /* Load the extension into this database connection */
      @@ -5357,64 +4792,65 @@ int sqlite3_load_extension(
       );
       
       /*
      -** CAPI3REF: Enable Or Disable Extension Loading {H12620} 
      +** CAPI3REF:  Enable Or Disable Extension Loading {F12620}
       **
       ** So as not to open security holes in older applications that are
       ** unprepared to deal with extension loading, and as a means of disabling
      -** extension loading while evaluating user-entered SQL, the following API
      -** is provided to turn the [sqlite3_load_extension()] mechanism on and off.
      +** extension loading while evaluating user-entered SQL, the following
      +** API is provided to turn the [sqlite3_load_extension()] mechanism on and
      +** off.  {F12622} It is off by default. {END} See ticket #1863.
       **
      -** Extension loading is off by default. See ticket #1863.
      -**
      -** {H12621} Call the sqlite3_enable_load_extension() routine with onoff==1
      -**          to turn extension loading on and call it with onoff==0 to turn
      -**          it back off again.
      -**
      -** {H12622} Extension loading is off by default.
      +** {F12621} Call the sqlite3_enable_load_extension() routine
      +** with onoff==1 to turn extension loading on
      +** and call it with onoff==0 to turn it back off again. {END}
       */
       int sqlite3_enable_load_extension(sqlite3 *db, int onoff);
       
       /*
      -** CAPI3REF: Automatically Load An Extensions {H12640} 
      +** CAPI3REF: Make Arrangements To Automatically Load An Extension {F12640}
      +**
      +** {F12641} This function
      +** registers an extension entry point that is automatically invoked
      +** whenever a new database connection is opened using
      +** [sqlite3_open()], [sqlite3_open16()], or [sqlite3_open_v2()]. {END}
       **
       ** This API can be invoked at program startup in order to register
       ** one or more statically linked extensions that will be available
      -** to all new [database connections]. {END}
      +** to all new database connections.
       **
      -** This routine stores a pointer to the extension in an array that is
      -** obtained from [sqlite3_malloc()].  If you run a memory leak checker
      -** on your program and it reports a leak because of this array, invoke
      -** [sqlite3_reset_auto_extension()] prior to shutdown to free the memory.
      +** {F12642} Duplicate extensions are detected so calling this routine multiple
      +** times with the same extension is harmless.
       **
      -** {H12641} This function registers an extension entry point that is
      -**          automatically invoked whenever a new [database connection]
      -**          is opened using [sqlite3_open()], [sqlite3_open16()],
      -**          or [sqlite3_open_v2()].
      +** {F12643} This routine stores a pointer to the extension in an array
      +** that is obtained from sqlite_malloc(). {END} If you run a memory leak
      +** checker on your program and it reports a leak because of this
      +** array, then invoke [sqlite3_reset_auto_extension()] prior
      +** to shutdown to free the memory.
       **
      -** {H12642} Duplicate extensions are detected so calling this routine
      -**          multiple times with the same extension is harmless.
      +** {F12644} Automatic extensions apply across all threads. {END}
       **
      -** {H12643} This routine stores a pointer to the extension in an array
      -**          that is obtained from [sqlite3_malloc()].
      -**
      -** {H12644} Automatic extensions apply across all threads.
      +** This interface is experimental and is subject to change or
      +** removal in future releases of SQLite.
       */
       int sqlite3_auto_extension(void *xEntryPoint);
       
      +
       /*
      -** CAPI3REF: Reset Automatic Extension Loading {H12660} 
      +** CAPI3REF: Reset Automatic Extension Loading {F12660}
       **
      -** This function disables all previously registered automatic
      -** extensions. {END}  It undoes the effect of all prior
      -** [sqlite3_auto_extension()] calls.
      +** {F12661} This function disables all previously registered
      +** automatic extensions. {END}  This
      +** routine undoes the effect of all prior [sqlite3_auto_extension()]
      +** calls.
       **
      -** {H12661} This function disables all previously registered
      -**          automatic extensions.
      +** {F12662} This call disabled automatic extensions in all threads. {END}
       **
      -** {H12662} This function disables automatic extensions in all threads.
      +** This interface is experimental and is subject to change or
      +** removal in future releases of SQLite.
       */
       void sqlite3_reset_auto_extension(void);
       
      +
       /*
       ****** EXPERIMENTAL - subject to change without notice **************
       **
      @@ -5422,7 +4858,7 @@ void sqlite3_reset_auto_extension(void);
       ** to be experimental.  The interface might change in incompatible ways.
       ** If this is a problem for you, do not use the interface at this time.
       **
      -** When the virtual-table mechanism stabilizes, we will declare the
      +** When the virtual-table mechanism stablizes, we will declare the
       ** interface fixed, support it indefinitely, and remove this comment.
       */
       
      @@ -5435,16 +4871,12 @@ typedef struct sqlite3_vtab_cursor sqlite3_vtab_cursor;
       typedef struct sqlite3_module sqlite3_module;
       
       /*
      -** CAPI3REF: Virtual Table Object {H18000} 
      +** CAPI3REF: Virtual Table Object {F18000}
       ** KEYWORDS: sqlite3_module
      -** EXPERIMENTAL
       **
       ** A module is a class of virtual tables.  Each module is defined
       ** by an instance of the following structure.  This structure consists
       ** mostly of methods for the module.
      -**
      -** This interface is experimental and is subject to change or
      -** removal in future releases of SQLite.
       */
       struct sqlite3_module {
         int iVersion;
      @@ -5473,13 +4905,13 @@ struct sqlite3_module {
         int (*xFindFunction)(sqlite3_vtab *pVtab, int nArg, const char *zName,
                              void (**pxFunc)(sqlite3_context*,int,sqlite3_value**),
                              void **ppArg);
      +
         int (*xRename)(sqlite3_vtab *pVtab, const char *zNew);
       };
       
       /*
      -** CAPI3REF: Virtual Table Indexing Information {H18100} 
      +** CAPI3REF: Virtual Table Indexing Information {F18100}
       ** KEYWORDS: sqlite3_index_info
      -** EXPERIMENTAL
       **
       ** The sqlite3_index_info structure and its substructures is used to
       ** pass information into and receive the reply from the xBestIndex
      @@ -5487,12 +4919,14 @@ struct sqlite3_module {
       ** inputs to xBestIndex and are read-only.  xBestIndex inserts its
       ** results into the **Outputs** fields.
       **
      -** The aConstraint[] array records WHERE clause constraints of the form:
      +** The aConstraint[] array records WHERE clause constraints of the
      +** form:
       **
      -** 
      column OP expr
      +** column OP expr ** -** where OP is =, <, <=, >, or >=. The particular operator is -** stored in aConstraint[].op. The index of the column is stored in +** Where OP is =, <, <=, >, or >=. +** The particular operator is stored +** in aConstraint[].op. The index of the column is stored in ** aConstraint[].iColumn. aConstraint[].usable is TRUE if the ** expr on the right-hand side can be evaluated (and thus the constraint ** is usable) and false if it cannot. @@ -5524,9 +4958,6 @@ struct sqlite3_module { ** particular lookup. A full scan of a table with N entries should have ** a cost of N. A binary search of a table of N entries should have a ** cost of approximately log(N). -** -** This interface is experimental and is subject to change or -** removal in future releases of SQLite. */ struct sqlite3_index_info { /* Inputs */ @@ -5542,6 +4973,7 @@ struct sqlite3_index_info { int iColumn; /* Column number */ unsigned char desc; /* True for DESC. False for ASC. */ } *aOrderBy; /* The ORDER BY clause */ + /* Outputs */ struct sqlite3_index_constraint_usage { int argvIndex; /* if >0, constraint is part of argv to xFilter */ @@ -5561,18 +4993,14 @@ struct sqlite3_index_info { #define SQLITE_INDEX_CONSTRAINT_MATCH 64 /* -** CAPI3REF: Register A Virtual Table Implementation {H18200} -** EXPERIMENTAL +** CAPI3REF: Register A Virtual Table Implementation {F18200} ** -** This routine is used to register a new module name with a -** [database connection]. Module names must be registered before -** creating new virtual tables on the module, or before using -** preexisting virtual tables of the module. -** -** This interface is experimental and is subject to change or -** removal in future releases of SQLite. +** This routine is used to register a new module name with an SQLite +** connection. Module names must be registered before creating new +** virtual tables on the module, or before using preexisting virtual +** tables of the module. */ -SQLITE_EXPERIMENTAL int sqlite3_create_module( +int sqlite3_create_module( sqlite3 *db, /* SQLite connection to register module with */ const char *zName, /* Name of the module */ const sqlite3_module *, /* Methods for the module */ @@ -5580,14 +5008,13 @@ SQLITE_EXPERIMENTAL int sqlite3_create_module( ); /* -** CAPI3REF: Register A Virtual Table Implementation {H18210} -** EXPERIMENTAL +** CAPI3REF: Register A Virtual Table Implementation {F18210} ** -** This routine is identical to the [sqlite3_create_module()] method above, +** This routine is identical to the sqlite3_create_module() method above, ** except that it allows a destructor function to be specified. It is ** even more experimental than the rest of the virtual tables API. */ -SQLITE_EXPERIMENTAL int sqlite3_create_module_v2( +int sqlite3_create_module_v2( sqlite3 *db, /* SQLite connection to register module with */ const char *zName, /* Name of the module */ const sqlite3_module *, /* Methods for the module */ @@ -5596,28 +5023,24 @@ SQLITE_EXPERIMENTAL int sqlite3_create_module_v2( ); /* -** CAPI3REF: Virtual Table Instance Object {H18010} +** CAPI3REF: Virtual Table Instance Object {F18010} ** KEYWORDS: sqlite3_vtab -** EXPERIMENTAL ** ** Every module implementation uses a subclass of the following structure ** to describe a particular instance of the module. Each subclass will -** be tailored to the specific needs of the module implementation. -** The purpose of this superclass is to define certain fields that are -** common to all module implementations. +** be tailored to the specific needs of the module implementation. The +** purpose of this superclass is to define certain fields that are common +** to all module implementations. ** ** Virtual tables methods can set an error message by assigning a -** string obtained from [sqlite3_mprintf()] to zErrMsg. The method should -** take care that any prior string is freed by a call to [sqlite3_free()] +** string obtained from sqlite3_mprintf() to zErrMsg. The method should +** take care that any prior string is freed by a call to sqlite3_free() ** prior to assigning a new string to zErrMsg. After the error message ** is delivered up to the client application, the string will be automatically ** freed by sqlite3_free() and the zErrMsg field will be zeroed. Note ** that sqlite3_mprintf() and sqlite3_free() are used on the zErrMsg field ** since virtual tables are commonly implemented in loadable extensions which ** do not have access to sqlite3MPrintf() or sqlite3Free(). -** -** This interface is experimental and is subject to change or -** removal in future releases of SQLite. */ struct sqlite3_vtab { const sqlite3_module *pModule; /* The module for this virtual table */ @@ -5627,9 +5050,8 @@ struct sqlite3_vtab { }; /* -** CAPI3REF: Virtual Table Cursor Object {H18020} +** CAPI3REF: Virtual Table Cursor Object {F18020} ** KEYWORDS: sqlite3_vtab_cursor -** EXPERIMENTAL ** ** Every module implementation uses a subclass of the following structure ** to describe cursors that point into the virtual table and are used @@ -5639,9 +5061,6 @@ struct sqlite3_vtab { ** ** This superclass exists in order to define fields of the cursor that ** are common to all implementations. -** -** This interface is experimental and is subject to change or -** removal in future releases of SQLite. */ struct sqlite3_vtab_cursor { sqlite3_vtab *pVtab; /* Virtual table of this cursor */ @@ -5649,21 +5068,16 @@ struct sqlite3_vtab_cursor { }; /* -** CAPI3REF: Declare The Schema Of A Virtual Table {H18280} -** EXPERIMENTAL +** CAPI3REF: Declare The Schema Of A Virtual Table {F18280} ** ** The xCreate and xConnect methods of a module use the following API ** to declare the format (the names and datatypes of the columns) of ** the virtual tables they implement. -** -** This interface is experimental and is subject to change or -** removal in future releases of SQLite. */ -SQLITE_EXPERIMENTAL int sqlite3_declare_vtab(sqlite3*, const char *zCreateTable); +int sqlite3_declare_vtab(sqlite3*, const char *zCreateTable); /* -** CAPI3REF: Overload A Function For A Virtual Table {H18300} -** EXPERIMENTAL +** CAPI3REF: Overload A Function For A Virtual Table {F18300} ** ** Virtual tables can provide alternative implementations of functions ** using the xFindFunction method. But global versions of those functions @@ -5674,13 +5088,13 @@ SQLITE_EXPERIMENTAL int sqlite3_declare_vtab(sqlite3*, const char *zCreateTable) ** before this API is called, a new function is created. The implementation ** of the new function always causes an exception to be thrown. So ** the new function is not good for anything by itself. Its only -** purpose is to be a placeholder function that can be overloaded +** purpose is to be a place-holder function that can be overloaded ** by virtual tables. ** ** This API should be considered part of the virtual table interface, ** which is experimental and subject to change. */ -SQLITE_EXPERIMENTAL int sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg); +int sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg); /* ** The interface to the virtual-table mechanism defined above (back up @@ -5695,83 +5109,68 @@ SQLITE_EXPERIMENTAL int sqlite3_overload_function(sqlite3*, const char *zFuncNam */ /* -** CAPI3REF: A Handle To An Open BLOB {H17800} -** KEYWORDS: {BLOB handle} {BLOB handles} +** CAPI3REF: A Handle To An Open BLOB {F17800} ** ** An instance of this object represents an open BLOB on which -** [sqlite3_blob_open | incremental BLOB I/O] can be performed. -** Objects of this type are created by [sqlite3_blob_open()] -** and destroyed by [sqlite3_blob_close()]. +** incremental I/O can be preformed. +** Objects of this type are created by +** [sqlite3_blob_open()] and destroyed by [sqlite3_blob_close()]. ** The [sqlite3_blob_read()] and [sqlite3_blob_write()] interfaces -** can be used to read or write small subsections of the BLOB. -** The [sqlite3_blob_bytes()] interface returns the size of the BLOB in bytes. +** can be used to read or write small subsections of the blob. +** The [sqlite3_blob_bytes()] interface returns the size of the +** blob in bytes. */ typedef struct sqlite3_blob sqlite3_blob; /* -** CAPI3REF: Open A BLOB For Incremental I/O {H17810} +** CAPI3REF: Open A BLOB For Incremental I/O {F17810} ** -** This interfaces opens a [BLOB handle | handle] to the BLOB located +** This interfaces opens a handle to the blob located ** in row iRow, column zColumn, table zTable in database zDb; -** in other words, the same BLOB that would be selected by: +** in other words, the same blob that would be selected by: ** **
       **     SELECT zColumn FROM zDb.zTable WHERE rowid = iRow;
       ** 
      {END} ** -** If the flags parameter is non-zero, the the BLOB is opened for read -** and write access. If it is zero, the BLOB is opened for read access. +** If the flags parameter is non-zero, the blob is opened for +** read and write access. If it is zero, the blob is opened for read +** access. ** ** Note that the database name is not the filename that contains ** the database but rather the symbolic name of the database that ** is assigned when the database is connected using [ATTACH]. -** For the main database file, the database name is "main". -** For TEMP tables, the database name is "temp". +** For the main database file, the database name is "main". For +** TEMP tables, the database name is "temp". ** -** On success, [SQLITE_OK] is returned and the new [BLOB handle] is written -** to *ppBlob. Otherwise an [error code] is returned and any value written -** to *ppBlob should not be used by the caller. -** This function sets the [database connection] error code and message +** On success, [SQLITE_OK] is returned and the new +** [sqlite3_blob | blob handle] is written to *ppBlob. +** Otherwise an error code is returned and +** any value written to *ppBlob should not be used by the caller. +** This function sets the database-handle error code and message ** accessible via [sqlite3_errcode()] and [sqlite3_errmsg()]. -** -** If the row that a BLOB handle points to is modified by an -** [UPDATE], [DELETE], or by [ON CONFLICT] side-effects -** then the BLOB handle is marked as "expired". -** This is true if any column of the row is changed, even a column -** other than the one the BLOB handle is open on. -** Calls to [sqlite3_blob_read()] and [sqlite3_blob_write()] for -** a expired BLOB handle fail with an return code of [SQLITE_ABORT]. -** Changes written into a BLOB prior to the BLOB expiring are not -** rollback by the expiration of the BLOB. Such changes will eventually -** commit if the transaction continues to completion. -** +** ** INVARIANTS: ** -** {H17813} A successful invocation of the [sqlite3_blob_open(D,B,T,C,R,F,P)] -** interface shall open an [sqlite3_blob] object P on the BLOB -** in column C of the table T in the database B on -** the [database connection] D. +** {F17813} A successful invocation of the [sqlite3_blob_open(D,B,T,C,R,F,P)] +** interface opens an [sqlite3_blob] object P on the blob +** in column C of table T in database B on [database connection] D. ** -** {H17814} A successful invocation of [sqlite3_blob_open(D,...)] shall start -** a new transaction on the [database connection] D if that -** connection is not already in a transaction. +** {F17814} A successful invocation of [sqlite3_blob_open(D,...)] starts +** a new transaction on [database connection] D if that connection +** is not already in a transaction. ** -** {H17816} The [sqlite3_blob_open(D,B,T,C,R,F,P)] interface shall open -** the BLOB for read and write access if and only if the F -** parameter is non-zero. +** {F17816} The [sqlite3_blob_open(D,B,T,C,R,F,P)] interface opens the blob +** for read and write access if and only if the F parameter +** is non-zero. ** -** {H17819} The [sqlite3_blob_open()] interface shall return [SQLITE_OK] on +** {F17819} The [sqlite3_blob_open()] interface returns [SQLITE_OK] on ** success and an appropriate [error code] on failure. ** -** {H17821} If an error occurs during evaluation of [sqlite3_blob_open(D,...)] +** {F17821} If an error occurs during evaluation of [sqlite3_blob_open(D,...)] ** then subsequent calls to [sqlite3_errcode(D)], -** [sqlite3_errmsg(D)], and [sqlite3_errmsg16(D)] shall return -** information appropriate for that error. -** -** {H17824} If any column in the row that a [sqlite3_blob] has open is -** changed by a separate [UPDATE] or [DELETE] statement or by -** an [ON CONFLICT] side effect, then the [sqlite3_blob] shall -** be marked as invalid. +** [sqlite3_errmsg(D)], and [sqlite3_errmsg16(D)] will return +** information approprate for that error. */ int sqlite3_blob_open( sqlite3*, @@ -5784,19 +5183,18 @@ int sqlite3_blob_open( ); /* -** CAPI3REF: Close A BLOB Handle {H17830} +** CAPI3REF: Close A BLOB Handle {F17830} ** -** Closes an open [BLOB handle]. +** Close an open [sqlite3_blob | blob handle]. ** ** Closing a BLOB shall cause the current transaction to commit ** if there are no other BLOBs, no pending prepared statements, and the -** database connection is in [autocommit mode]. +** database connection is in autocommit mode. ** If any writes were made to the BLOB, they might be held in cache ** until the close operation if they will fit. {END} -** ** Closing the BLOB often forces the changes ** out to disk and so if any I/O errors occur, they will likely occur -** at the time when the BLOB is closed. {H17833} Any errors that occur during +** at the time when the BLOB is closed. {F17833} Any errors that occur during ** closing are reported as a non-zero return value. ** ** The BLOB is closed unconditionally. Even if this routine returns @@ -5804,156 +5202,139 @@ int sqlite3_blob_open( ** ** INVARIANTS: ** -** {H17833} The [sqlite3_blob_close(P)] interface closes an [sqlite3_blob] -** object P previously opened using [sqlite3_blob_open()]. +** {F17833} The [sqlite3_blob_close(P)] interface closes an +** [sqlite3_blob] object P previously opened using +** [sqlite3_blob_open()]. ** -** {H17836} Closing an [sqlite3_blob] object using +** {F17836} Closing an [sqlite3_blob] object using ** [sqlite3_blob_close()] shall cause the current transaction to ** commit if there are no other open [sqlite3_blob] objects ** or [prepared statements] on the same [database connection] and -** the database connection is in [autocommit mode]. +** the [database connection] is in +** [sqlite3_get_autocommit | autocommit mode]. ** -** {H17839} The [sqlite3_blob_close(P)] interfaces shall close the +** {F17839} The [sqlite3_blob_close(P)] interfaces closes the ** [sqlite3_blob] object P unconditionally, even if ** [sqlite3_blob_close(P)] returns something other than [SQLITE_OK]. +** */ int sqlite3_blob_close(sqlite3_blob *); /* -** CAPI3REF: Return The Size Of An Open BLOB {H17840} +** CAPI3REF: Return The Size Of An Open BLOB {F17840} ** -** Returns the size in bytes of the BLOB accessible via the open -** []BLOB handle] in its only argument. +** Return the size in bytes of the blob accessible via the open +** [sqlite3_blob] object in its only argument. ** ** INVARIANTS: ** -** {H17843} The [sqlite3_blob_bytes(P)] interface returns the size +** {F17843} The [sqlite3_blob_bytes(P)] interface returns the size ** in bytes of the BLOB that the [sqlite3_blob] object P ** refers to. */ int sqlite3_blob_bytes(sqlite3_blob *); /* -** CAPI3REF: Read Data From A BLOB Incrementally {H17850} +** CAPI3REF: Read Data From A BLOB Incrementally {F17850} ** -** This function is used to read data from an open [BLOB handle] into a -** caller-supplied buffer. N bytes of data are copied into buffer Z -** from the open BLOB, starting at offset iOffset. +** This function is used to read data from an open +** [sqlite3_blob | blob-handle] into a caller supplied buffer. +** N bytes of data are copied into buffer +** Z from the open blob, starting at offset iOffset. ** -** If offset iOffset is less than N bytes from the end of the BLOB, +** If offset iOffset is less than N bytes from the end of the blob, ** [SQLITE_ERROR] is returned and no data is read. If N or iOffset is -** less than zero, [SQLITE_ERROR] is returned and no data is read. +** less than zero [SQLITE_ERROR] is returned and no data is read. ** -** An attempt to read from an expired [BLOB handle] fails with an -** error code of [SQLITE_ABORT]. -** -** On success, SQLITE_OK is returned. -** Otherwise, an [error code] or an [extended error code] is returned. +** On success, SQLITE_OK is returned. Otherwise, an +** [error code] or an [extended error code] is returned. ** ** INVARIANTS: ** -** {H17853} A successful invocation of [sqlite3_blob_read(P,Z,N,X)] -** shall reads N bytes of data out of the BLOB referenced by -** [BLOB handle] P beginning at offset X and store those bytes -** into buffer Z. +** {F17853} The [sqlite3_blob_read(P,Z,N,X)] interface reads N bytes +** beginning at offset X from +** the blob that [sqlite3_blob] object P refers to +** and writes those N bytes into buffer Z. ** -** {H17856} In [sqlite3_blob_read(P,Z,N,X)] if the size of the BLOB -** is less than N+X bytes, then the function shall leave the -** Z buffer unchanged and return [SQLITE_ERROR]. +** {F17856} In [sqlite3_blob_read(P,Z,N,X)] if the size of the blob +** is less than N+X bytes, then the function returns [SQLITE_ERROR] +** and nothing is read from the blob. ** -** {H17859} In [sqlite3_blob_read(P,Z,N,X)] if X or N is less than zero -** then the function shall leave the Z buffer unchanged -** and return [SQLITE_ERROR]. +** {F17859} In [sqlite3_blob_read(P,Z,N,X)] if X or N is less than zero +** then the function returns [SQLITE_ERROR] +** and nothing is read from the blob. ** -** {H17862} The [sqlite3_blob_read(P,Z,N,X)] interface shall return [SQLITE_OK] -** if N bytes are successfully read into buffer Z. +** {F17862} The [sqlite3_blob_read(P,Z,N,X)] interface returns [SQLITE_OK] +** if N bytes where successfully read into buffer Z. ** -** {H17863} If the [BLOB handle] P is expired and X and N are within bounds -** then [sqlite3_blob_read(P,Z,N,X)] shall leave the Z buffer -** unchanged and return [SQLITE_ABORT]. -** -** {H17865} If the requested read could not be completed, -** the [sqlite3_blob_read(P,Z,N,X)] interface shall return an +** {F17865} If the requested read could not be completed, +** the [sqlite3_blob_read(P,Z,N,X)] interface returns an ** appropriate [error code] or [extended error code]. ** -** {H17868} If an error occurs during evaluation of [sqlite3_blob_read(P,...)] +** {F17868} If an error occurs during evaluation of [sqlite3_blob_read(P,...)] ** then subsequent calls to [sqlite3_errcode(D)], -** [sqlite3_errmsg(D)], and [sqlite3_errmsg16(D)] shall return -** information appropriate for that error, where D is the -** [database connection] that was used to open the [BLOB handle] P. +** [sqlite3_errmsg(D)], and [sqlite3_errmsg16(D)] will return +** information approprate for that error, where D is the +** database handle that was used to open blob handle P. */ int sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset); /* -** CAPI3REF: Write Data Into A BLOB Incrementally {H17870} +** CAPI3REF: Write Data Into A BLOB Incrementally {F17870} ** -** This function is used to write data into an open [BLOB handle] from a -** caller-supplied buffer. N bytes of data are copied from the buffer Z -** into the open BLOB, starting at offset iOffset. +** This function is used to write data into an open +** [sqlite3_blob | blob-handle] from a user supplied buffer. +** n bytes of data are copied from the buffer +** pointed to by z into the open blob, starting at offset iOffset. ** -** If the [BLOB handle] passed as the first argument was not opened for -** writing (the flags parameter to [sqlite3_blob_open()] was zero), -** this function returns [SQLITE_READONLY]. +** If the [sqlite3_blob | blob-handle] passed as the first argument +** was not opened for writing (the flags parameter to [sqlite3_blob_open()] +*** was zero), this function returns [SQLITE_READONLY]. ** -** This function may only modify the contents of the BLOB; it is -** not possible to increase the size of a BLOB using this API. -** If offset iOffset is less than N bytes from the end of the BLOB, -** [SQLITE_ERROR] is returned and no data is written. If N is +** This function may only modify the contents of the blob; it is +** not possible to increase the size of a blob using this API. +** If offset iOffset is less than n bytes from the end of the blob, +** [SQLITE_ERROR] is returned and no data is written. If n is ** less than zero [SQLITE_ERROR] is returned and no data is written. ** -** An attempt to write to an expired [BLOB handle] fails with an -** error code of [SQLITE_ABORT]. Writes to the BLOB that occurred -** before the [BLOB handle] expired are not rolled back by the -** expiration of the handle, though of course those changes might -** have been overwritten by the statement that expired the BLOB handle -** or by other independent statements. -** -** On success, SQLITE_OK is returned. -** Otherwise, an [error code] or an [extended error code] is returned. +** On success, SQLITE_OK is returned. Otherwise, an +** [error code] or an [extended error code] is returned. ** ** INVARIANTS: ** -** {H17873} A successful invocation of [sqlite3_blob_write(P,Z,N,X)] -** shall write N bytes of data from buffer Z into the BLOB -** referenced by [BLOB handle] P beginning at offset X into -** the BLOB. +** {F17873} The [sqlite3_blob_write(P,Z,N,X)] interface writes N bytes +** from buffer Z into +** the blob that [sqlite3_blob] object P refers to +** beginning at an offset of X into the blob. ** -** {H17874} In the absence of other overridding changes, the changes -** written to a BLOB by [sqlite3_blob_write()] shall -** remain in effect after the associated [BLOB handle] expires. +** {F17875} The [sqlite3_blob_write(P,Z,N,X)] interface returns +** [SQLITE_READONLY] if the [sqlite3_blob] object P was +** [sqlite3_blob_open | opened] for reading only. ** -** {H17875} If the [BLOB handle] P was opened for reading only then -** an invocation of [sqlite3_blob_write(P,Z,N,X)] shall leave -** the referenced BLOB unchanged and return [SQLITE_READONLY]. +** {F17876} In [sqlite3_blob_write(P,Z,N,X)] if the size of the blob +** is less than N+X bytes, then the function returns [SQLITE_ERROR] +** and nothing is written into the blob. ** -** {H17876} If the size of the BLOB referenced by [BLOB handle] P is -** less than N+X bytes then [sqlite3_blob_write(P,Z,N,X)] shall -** leave the BLOB unchanged and return [SQLITE_ERROR]. +** {F17879} In [sqlite3_blob_write(P,Z,N,X)] if X or N is less than zero +** then the function returns [SQLITE_ERROR] +** and nothing is written into the blob. ** -** {H17877} If the [BLOB handle] P is expired and X and N are within bounds -** then [sqlite3_blob_read(P,Z,N,X)] shall leave the BLOB -** unchanged and return [SQLITE_ABORT]. +** {F17882} The [sqlite3_blob_write(P,Z,N,X)] interface returns [SQLITE_OK] +** if N bytes where successfully written into blob. ** -** {H17879} If X or N are less than zero then [sqlite3_blob_write(P,Z,N,X)] -** shall leave the BLOB referenced by [BLOB handle] P unchanged -** and return [SQLITE_ERROR]. -** -** {H17882} The [sqlite3_blob_write(P,Z,N,X)] interface shall return -** [SQLITE_OK] if N bytes where successfully written into the BLOB. -** -** {H17885} If the requested write could not be completed, -** the [sqlite3_blob_write(P,Z,N,X)] interface shall return an +** {F17885} If the requested write could not be completed, +** the [sqlite3_blob_write(P,Z,N,X)] interface returns an ** appropriate [error code] or [extended error code]. ** -** {H17888} If an error occurs during evaluation of [sqlite3_blob_write(D,...)] +** {F17888} If an error occurs during evaluation of [sqlite3_blob_write(D,...)] ** then subsequent calls to [sqlite3_errcode(D)], -** [sqlite3_errmsg(D)], and [sqlite3_errmsg16(D)] shall return -** information appropriate for that error. +** [sqlite3_errmsg(D)], and [sqlite3_errmsg16(D)] will return +** information approprate for that error. */ int sqlite3_blob_write(sqlite3_blob *, const void *z, int n, int iOffset); /* -** CAPI3REF: Virtual File System Objects {H11200} +** CAPI3REF: Virtual File System Objects {F11200} ** ** A virtual filesystem (VFS) is an [sqlite3_vfs] object ** that SQLite uses to interact @@ -5962,11 +5343,12 @@ int sqlite3_blob_write(sqlite3_blob *, const void *z, int n, int iOffset); ** New VFSes can be registered and existing VFSes can be unregistered. ** The following interfaces are provided. ** -** The sqlite3_vfs_find() interface returns a pointer to a VFS given its name. -** Names are case sensitive. +** The sqlite3_vfs_find() interface returns a pointer to +** a VFS given its name. Names are case sensitive. ** Names are zero-terminated UTF-8 strings. -** If there is no match, a NULL pointer is returned. -** If zVfsName is NULL then the default VFS is returned. +** If there is no match, a NULL +** pointer is returned. If zVfsName is NULL then the default +** VFS is returned. ** ** New VFSes are registered with sqlite3_vfs_register(). ** Each new VFS becomes the default VFS if the makeDflt flag is set. @@ -5976,34 +5358,35 @@ int sqlite3_blob_write(sqlite3_blob *, const void *z, int n, int iOffset); ** same name are registered, the behavior is undefined. If a ** VFS is registered with a name that is NULL or an empty string, ** then the behavior is undefined. -** +** ** Unregister a VFS with the sqlite3_vfs_unregister() interface. ** If the default VFS is unregistered, another VFS is chosen as ** the default. The choice for the new VFS is arbitrary. ** ** INVARIANTS: ** -** {H11203} The [sqlite3_vfs_find(N)] interface returns a pointer to the +** {F11203} The [sqlite3_vfs_find(N)] interface returns a pointer to the ** registered [sqlite3_vfs] object whose name exactly matches ** the zero-terminated UTF-8 string N, or it returns NULL if ** there is no match. ** -** {H11206} If the N parameter to [sqlite3_vfs_find(N)] is NULL then +** {F11206} If the N parameter to [sqlite3_vfs_find(N)] is NULL then ** the function returns a pointer to the default [sqlite3_vfs] -** object if there is one, or NULL if there is no default +** object if there is one, or NULL if there is no default ** [sqlite3_vfs] object. ** -** {H11209} The [sqlite3_vfs_register(P,F)] interface registers the +** {F11209} The [sqlite3_vfs_register(P,F)] interface registers the ** well-formed [sqlite3_vfs] object P using the name given ** by the zName field of the object. ** -** {H11212} Using the [sqlite3_vfs_register(P,F)] interface to register +** {F11212} Using the [sqlite3_vfs_register(P,F)] interface to register ** the same [sqlite3_vfs] object multiple times is a harmless no-op. ** -** {H11215} The [sqlite3_vfs_register(P,F)] interface makes the [sqlite3_vfs] -** object P the default [sqlite3_vfs] object if F is non-zero. +** {F11215} The [sqlite3_vfs_register(P,F)] interface makes the +** the [sqlite3_vfs] object P the default [sqlite3_vfs] object +** if F is non-zero. ** -** {H11218} The [sqlite3_vfs_unregister(P)] interface unregisters the +** {F11218} The [sqlite3_vfs_unregister(P)] interface unregisters the ** [sqlite3_vfs] object P so that it is no longer returned by ** subsequent calls to [sqlite3_vfs_find()]. */ @@ -6012,14 +5395,14 @@ int sqlite3_vfs_register(sqlite3_vfs*, int makeDflt); int sqlite3_vfs_unregister(sqlite3_vfs*); /* -** CAPI3REF: Mutexes {H17000} +** CAPI3REF: Mutexes {F17000} ** ** The SQLite core uses these routines for thread -** synchronization. Though they are intended for internal +** synchronization. Though they are intended for internal ** use by SQLite, code that links against SQLite is ** permitted to use any of these routines. ** -** The SQLite source code contains multiple implementations +** The SQLite source code contains multiple implementations ** of these mutex routines. An appropriate implementation ** is selected automatically at compile-time. The following ** implementations are available in the SQLite core: @@ -6031,24 +5414,25 @@ int sqlite3_vfs_unregister(sqlite3_vfs*); **
    • SQLITE_MUTEX_NOOP ** ** -** The SQLITE_MUTEX_NOOP implementation is a set of routines -** that does no real locking and is appropriate for use in +** The SQLITE_MUTEX_NOOP implementation is a set of routines +** that does no real locking and is appropriate for use in ** a single-threaded application. The SQLITE_MUTEX_OS2, ** SQLITE_MUTEX_PTHREAD, and SQLITE_MUTEX_W32 implementations -** are appropriate for use on OS/2, Unix, and Windows. -** +** are appropriate for use on os/2, unix, and windows. +** ** If SQLite is compiled with the SQLITE_MUTEX_APPDEF preprocessor ** macro defined (with "-DSQLITE_MUTEX_APPDEF=1"), then no mutex -** implementation is included with the library. In this case the -** application must supply a custom mutex implementation using the -** [SQLITE_CONFIG_MUTEX] option of the sqlite3_config() function -** before calling sqlite3_initialize() or any other public sqlite3_ -** function that calls sqlite3_initialize(). +** implementation is included with the library. The +** mutex interface routines defined here become external +** references in the SQLite library for which implementations +** must be provided by the application. This facility allows an +** application that links against SQLite to provide its own mutex +** implementation without having to modify the SQLite core. ** -** {H17011} The sqlite3_mutex_alloc() routine allocates a new -** mutex and returns a pointer to it. {H17012} If it returns NULL -** that means that a mutex could not be allocated. {H17013} SQLite -** will unwind its stack and return an error. {H17014} The argument +** {F17011} The sqlite3_mutex_alloc() routine allocates a new +** mutex and returns a pointer to it. {F17012} If it returns NULL +** that means that a mutex could not be allocated. {F17013} SQLite +** will unwind its stack and return an error. {F17014} The argument ** to sqlite3_mutex_alloc() is one of these integer constants: ** **
        @@ -6060,19 +5444,19 @@ int sqlite3_vfs_unregister(sqlite3_vfs*); **
      • SQLITE_MUTEX_STATIC_PRNG **
      • SQLITE_MUTEX_STATIC_LRU **
      • SQLITE_MUTEX_STATIC_LRU2 -**
      +** {END} ** -** {H17015} The first two constants cause sqlite3_mutex_alloc() to create +** {F17015} The first two constants cause sqlite3_mutex_alloc() to create ** a new mutex. The new mutex is recursive when SQLITE_MUTEX_RECURSIVE ** is used but not necessarily so when SQLITE_MUTEX_FAST is used. {END} ** The mutex implementation does not need to make a distinction ** between SQLITE_MUTEX_RECURSIVE and SQLITE_MUTEX_FAST if it does -** not want to. {H17016} But SQLite will only request a recursive mutex in +** not want to. {F17016} But SQLite will only request a recursive mutex in ** cases where it really needs one. {END} If a faster non-recursive mutex ** implementation is available on the host platform, the mutex subsystem ** might return such a mutex in response to SQLITE_MUTEX_FAST. ** -** {H17017} The other allowed parameters to sqlite3_mutex_alloc() each return +** {F17017} The other allowed parameters to sqlite3_mutex_alloc() each return ** a pointer to a static preexisting mutex. {END} Four static mutexes are ** used by the current version of SQLite. Future versions of SQLite ** may add additional static mutexes. Static mutexes are for internal @@ -6080,47 +5464,43 @@ int sqlite3_vfs_unregister(sqlite3_vfs*); ** use only the dynamic mutexes returned by SQLITE_MUTEX_FAST or ** SQLITE_MUTEX_RECURSIVE. ** -** {H17018} Note that if one of the dynamic mutex parameters (SQLITE_MUTEX_FAST +** {F17018} Note that if one of the dynamic mutex parameters (SQLITE_MUTEX_FAST ** or SQLITE_MUTEX_RECURSIVE) is used then sqlite3_mutex_alloc() -** returns a different mutex on every call. {H17034} But for the static +** returns a different mutex on every call. {F17034} But for the static ** mutex types, the same mutex is returned on every call that has -** the same type number. +** the same type number. {END} ** -** {H17019} The sqlite3_mutex_free() routine deallocates a previously -** allocated dynamic mutex. {H17020} SQLite is careful to deallocate every -** dynamic mutex that it allocates. {A17021} The dynamic mutexes must not be in -** use when they are deallocated. {A17022} Attempting to deallocate a static -** mutex results in undefined behavior. {H17023} SQLite never deallocates +** {F17019} The sqlite3_mutex_free() routine deallocates a previously +** allocated dynamic mutex. {F17020} SQLite is careful to deallocate every +** dynamic mutex that it allocates. {U17021} The dynamic mutexes must not be in +** use when they are deallocated. {U17022} Attempting to deallocate a static +** mutex results in undefined behavior. {F17023} SQLite never deallocates ** a static mutex. {END} ** ** The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt -** to enter a mutex. {H17024} If another thread is already within the mutex, +** to enter a mutex. {F17024} If another thread is already within the mutex, ** sqlite3_mutex_enter() will block and sqlite3_mutex_try() will return -** SQLITE_BUSY. {H17025} The sqlite3_mutex_try() interface returns [SQLITE_OK] -** upon successful entry. {H17026} Mutexes created using +** SQLITE_BUSY. {F17025} The sqlite3_mutex_try() interface returns SQLITE_OK +** upon successful entry. {F17026} Mutexes created using ** SQLITE_MUTEX_RECURSIVE can be entered multiple times by the same thread. -** {H17027} In such cases the, +** {F17027} In such cases the, ** mutex must be exited an equal number of times before another thread -** can enter. {A17028} If the same thread tries to enter any other +** can enter. {U17028} If the same thread tries to enter any other ** kind of mutex more than once, the behavior is undefined. -** {H17029} SQLite will never exhibit -** such behavior in its own use of mutexes. +** {F17029} SQLite will never exhibit +** such behavior in its own use of mutexes. {END} ** -** Some systems (for example, Windows 95) do not support the operation -** implemented by sqlite3_mutex_try(). On those systems, sqlite3_mutex_try() -** will always return SQLITE_BUSY. {H17030} The SQLite core only ever uses -** sqlite3_mutex_try() as an optimization so this is acceptable behavior. +** Some systems (ex: windows95) do not the operation implemented by +** sqlite3_mutex_try(). On those systems, sqlite3_mutex_try() will +** always return SQLITE_BUSY. {F17030} The SQLite core only ever uses +** sqlite3_mutex_try() as an optimization so this is acceptable behavior. {END} ** -** {H17031} The sqlite3_mutex_leave() routine exits a mutex that was -** previously entered by the same thread. {A17032} The behavior +** {F17031} The sqlite3_mutex_leave() routine exits a mutex that was +** previously entered by the same thread. {U17032} The behavior ** is undefined if the mutex is not currently entered by the -** calling thread or is not currently allocated. {H17033} SQLite will +** calling thread or is not currently allocated. {F17033} SQLite will ** never do either. {END} ** -** If the argument to sqlite3_mutex_enter(), sqlite3_mutex_try(), or -** sqlite3_mutex_leave() is a NULL pointer, then all three routines -** behave as no-ops. -** ** See also: [sqlite3_mutex_held()] and [sqlite3_mutex_notheld()]. */ sqlite3_mutex *sqlite3_mutex_alloc(int); @@ -6130,110 +5510,44 @@ int sqlite3_mutex_try(sqlite3_mutex*); void sqlite3_mutex_leave(sqlite3_mutex*); /* -** CAPI3REF: Mutex Methods Object {H17120} -** EXPERIMENTAL -** -** An instance of this structure defines the low-level routines -** used to allocate and use mutexes. -** -** Usually, the default mutex implementations provided by SQLite are -** sufficient, however the user has the option of substituting a custom -** implementation for specialized deployments or systems for which SQLite -** does not provide a suitable implementation. In this case, the user -** creates and populates an instance of this structure to pass -** to sqlite3_config() along with the [SQLITE_CONFIG_MUTEX] option. -** Additionally, an instance of this structure can be used as an -** output variable when querying the system for the current mutex -** implementation, using the [SQLITE_CONFIG_GETMUTEX] option. -** -** The xMutexInit method defined by this structure is invoked as -** part of system initialization by the sqlite3_initialize() function. -** {H17001} The xMutexInit routine shall be called by SQLite once for each -** effective call to [sqlite3_initialize()]. -** -** The xMutexEnd method defined by this structure is invoked as -** part of system shutdown by the sqlite3_shutdown() function. The -** implementation of this method is expected to release all outstanding -** resources obtained by the mutex methods implementation, especially -** those obtained by the xMutexInit method. {H17003} The xMutexEnd() -** interface shall be invoked once for each call to [sqlite3_shutdown()]. -** -** The remaining seven methods defined by this structure (xMutexAlloc, -** xMutexFree, xMutexEnter, xMutexTry, xMutexLeave, xMutexHeld and -** xMutexNotheld) implement the following interfaces (respectively): -** -**
        -**
      • [sqlite3_mutex_alloc()]
      • -**
      • [sqlite3_mutex_free()]
      • -**
      • [sqlite3_mutex_enter()]
      • -**
      • [sqlite3_mutex_try()]
      • -**
      • [sqlite3_mutex_leave()]
      • -**
      • [sqlite3_mutex_held()]
      • -**
      • [sqlite3_mutex_notheld()]
      • -**
      -** -** The only difference is that the public sqlite3_XXX functions enumerated -** above silently ignore any invocations that pass a NULL pointer instead -** of a valid mutex handle. The implementations of the methods defined -** by this structure are not required to handle this case, the results -** of passing a NULL pointer instead of a valid mutex handle are undefined -** (i.e. it is acceptable to provide an implementation that segfaults if -** it is passed a NULL pointer). -*/ -typedef struct sqlite3_mutex_methods sqlite3_mutex_methods; -struct sqlite3_mutex_methods { - int (*xMutexInit)(void); - int (*xMutexEnd)(void); - sqlite3_mutex *(*xMutexAlloc)(int); - void (*xMutexFree)(sqlite3_mutex *); - void (*xMutexEnter)(sqlite3_mutex *); - int (*xMutexTry)(sqlite3_mutex *); - void (*xMutexLeave)(sqlite3_mutex *); - int (*xMutexHeld)(sqlite3_mutex *); - int (*xMutexNotheld)(sqlite3_mutex *); -}; - -/* -** CAPI3REF: Mutex Verification Routines {H17080} +** CAPI3REF: Mutex Verifcation Routines {F17080} ** ** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routines -** are intended for use inside assert() statements. {H17081} The SQLite core +** are intended for use inside assert() statements. {F17081} The SQLite core ** never uses these routines except inside an assert() and applications -** are advised to follow the lead of the core. {H17082} The core only +** are advised to follow the lead of the core. {F17082} The core only ** provides implementations for these routines when it is compiled -** with the SQLITE_DEBUG flag. {A17087} External mutex implementations +** with the SQLITE_DEBUG flag. {U17087} External mutex implementations ** are only required to provide these routines if SQLITE_DEBUG is ** defined and if NDEBUG is not defined. ** -** {H17083} These routines should return true if the mutex in their argument -** is held or not held, respectively, by the calling thread. +** {F17083} These routines should return true if the mutex in their argument +** is held or not held, respectively, by the calling thread. {END} ** ** {X17084} The implementation is not required to provided versions of these -** routines that actually work. If the implementation does not provide working -** versions of these routines, it should at least provide stubs that always -** return true so that one does not get spurious assertion failures. +** routines that actually work. +** If the implementation does not provide working +** versions of these routines, it should at least provide stubs +** that always return true so that one does not get spurious +** assertion failures. {END} ** -** {H17085} If the argument to sqlite3_mutex_held() is a NULL pointer then +** {F17085} If the argument to sqlite3_mutex_held() is a NULL pointer then ** the routine should return 1. {END} This seems counter-intuitive since ** clearly the mutex cannot be held if it does not exist. But the ** the reason the mutex does not exist is because the build is not ** using mutexes. And we do not want the assert() containing the ** call to sqlite3_mutex_held() to fail, so a non-zero return is -** the appropriate thing to do. {H17086} The sqlite3_mutex_notheld() +** the appropriate thing to do. {F17086} The sqlite3_mutex_notheld() ** interface should also return 1 when given a NULL pointer. */ int sqlite3_mutex_held(sqlite3_mutex*); int sqlite3_mutex_notheld(sqlite3_mutex*); /* -** CAPI3REF: Mutex Types {H17001} +** CAPI3REF: Mutex Types {F17001} ** -** The [sqlite3_mutex_alloc()] interface takes a single argument -** which is one of these integer constants. -** -** The set of static mutexes may change from one SQLite release to the -** next. Applications that override the built-in mutex logic must be -** prepared to accommodate additional static mutexes. +** {F17002} The [sqlite3_mutex_alloc()] interface takes a single argument +** which is one of these integer constants. {END} */ #define SQLITE_MUTEX_FAST 0 #define SQLITE_MUTEX_RECURSIVE 1 @@ -6245,24 +5559,24 @@ int sqlite3_mutex_notheld(sqlite3_mutex*); #define SQLITE_MUTEX_STATIC_LRU2 7 /* lru page list */ /* -** CAPI3REF: Low-Level Control Of Database Files {H11300} +** CAPI3REF: Low-Level Control Of Database Files {F11300} ** -** {H11301} The [sqlite3_file_control()] interface makes a direct call to the +** {F11301} The [sqlite3_file_control()] interface makes a direct call to the ** xFileControl method for the [sqlite3_io_methods] object associated -** with a particular database identified by the second argument. {H11302} The +** with a particular database identified by the second argument. {F11302} The ** name of the database is the name assigned to the database by the ** ATTACH SQL command that opened the -** database. {H11303} To control the main database file, use the name "main" -** or a NULL pointer. {H11304} The third and fourth parameters to this routine +** database. {F11303} To control the main database file, use the name "main" +** or a NULL pointer. {F11304} The third and fourth parameters to this routine ** are passed directly through to the second and third parameters of -** the xFileControl method. {H11305} The return value of the xFileControl +** the xFileControl method. {F11305} The return value of the xFileControl ** method becomes the return value of this routine. ** -** {H11306} If the second parameter (zDbName) does not match the name of any -** open database file, then SQLITE_ERROR is returned. {H11307} This error +** {F11306} If the second parameter (zDbName) does not match the name of any +** open database file, then SQLITE_ERROR is returned. {F11307} This error ** code is not remembered and will not be recalled by [sqlite3_errcode()] -** or [sqlite3_errmsg()]. {A11308} The underlying xFileControl method might -** also return SQLITE_ERROR. {A11309} There is no way to distinguish between +** or [sqlite3_errmsg()]. {U11308} The underlying xFileControl method might +** also return SQLITE_ERROR. {U11309} There is no way to distinguish between ** an incorrect zDbName and an SQLITE_ERROR return from the underlying ** xFileControl method. {END} ** @@ -6271,11 +5585,11 @@ int sqlite3_mutex_notheld(sqlite3_mutex*); int sqlite3_file_control(sqlite3*, const char *zDbName, int op, void*); /* -** CAPI3REF: Testing Interface {H11400} +** CAPI3REF: Testing Interface {F11400} ** ** The sqlite3_test_control() interface is used to read out internal ** state of SQLite and to inject faults into SQLite for testing -** purposes. The first parameter is an operation code that determines +** purposes. The first parameter a operation code that determines ** the number, meaning, and operation of all subsequent parameters. ** ** This interface is not for use by applications. It exists solely @@ -6290,228 +5604,25 @@ int sqlite3_file_control(sqlite3*, const char *zDbName, int op, void*); int sqlite3_test_control(int op, ...); /* -** CAPI3REF: Testing Interface Operation Codes {H11410} +** CAPI3REF: Testing Interface Operation Codes {F11410} ** ** These constants are the valid operation code parameters used ** as the first argument to [sqlite3_test_control()]. ** -** These parameters and their meanings are subject to change +** These parameters and their meansing are subject to change ** without notice. These values are for testing purposes only. ** Applications should not use any of these parameters or the ** [sqlite3_test_control()] interface. */ +#define SQLITE_TESTCTRL_FAULT_CONFIG 1 +#define SQLITE_TESTCTRL_FAULT_FAILURES 2 +#define SQLITE_TESTCTRL_FAULT_BENIGN_FAILURES 3 +#define SQLITE_TESTCTRL_FAULT_PENDING 4 #define SQLITE_TESTCTRL_PRNG_SAVE 5 #define SQLITE_TESTCTRL_PRNG_RESTORE 6 #define SQLITE_TESTCTRL_PRNG_RESET 7 #define SQLITE_TESTCTRL_BITVEC_TEST 8 -#define SQLITE_TESTCTRL_FAULT_INSTALL 9 -#define SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS 10 -/* -** CAPI3REF: SQLite Runtime Status {H17200} -** EXPERIMENTAL -** -** This interface is used to retrieve runtime status information -** about the preformance of SQLite, and optionally to reset various -** highwater marks. The first argument is an integer code for -** the specific parameter to measure. Recognized integer codes -** are of the form [SQLITE_STATUS_MEMORY_USED | SQLITE_STATUS_...]. -** The current value of the parameter is returned into *pCurrent. -** The highest recorded value is returned in *pHighwater. If the -** resetFlag is true, then the highest record value is reset after -** *pHighwater is written. Some parameters do not record the highest -** value. For those parameters -** nothing is written into *pHighwater and the resetFlag is ignored. -** Other parameters record only the highwater mark and not the current -** value. For these latter parameters nothing is written into *pCurrent. -** -** This routine returns SQLITE_OK on success and a non-zero -** [error code] on failure. -** -** This routine is threadsafe but is not atomic. This routine can -** called while other threads are running the same or different SQLite -** interfaces. However the values returned in *pCurrent and -** *pHighwater reflect the status of SQLite at different points in time -** and it is possible that another thread might change the parameter -** in between the times when *pCurrent and *pHighwater are written. -** -** See also: [sqlite3_db_status()] -*/ -SQLITE_EXPERIMENTAL int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag); - - -/* -** CAPI3REF: Status Parameters {H17250} -** EXPERIMENTAL -** -** These integer constants designate various run-time status parameters -** that can be returned by [sqlite3_status()]. -** -**
      -**
      SQLITE_STATUS_MEMORY_USED
      -**
      This parameter is the current amount of memory checked out -** using [sqlite3_malloc()], either directly or indirectly. The -** figure includes calls made to [sqlite3_malloc()] by the application -** and internal memory usage by the SQLite library. Scratch memory -** controlled by [SQLITE_CONFIG_SCRATCH] and auxiliary page-cache -** memory controlled by [SQLITE_CONFIG_PAGECACHE] is not included in -** this parameter. The amount returned is the sum of the allocation -** sizes as reported by the xSize method in [sqlite3_mem_methods].
      -** -**
      SQLITE_STATUS_MALLOC_SIZE
      -**
      This parameter records the largest memory allocation request -** handed to [sqlite3_malloc()] or [sqlite3_realloc()] (or their -** internal equivalents). Only the value returned in the -** *pHighwater parameter to [sqlite3_status()] is of interest. -** The value written into the *pCurrent parameter is undefined.
      -** -**
      SQLITE_STATUS_PAGECACHE_USED
      -**
      This parameter returns the number of pages used out of the -** [pagecache memory allocator] that was configured using -** [SQLITE_CONFIG_PAGECACHE]. The -** value returned is in pages, not in bytes.
      -** -**
      SQLITE_STATUS_PAGECACHE_OVERFLOW
      -**
      This parameter returns the number of bytes of page cache -** allocation which could not be statisfied by the [SQLITE_CONFIG_PAGECACHE] -** buffer and where forced to overflow to [sqlite3_malloc()]. The -** returned value includes allocations that overflowed because they -** where too large (they were larger than the "sz" parameter to -** [SQLITE_CONFIG_PAGECACHE]) and allocations that overflowed because -** no space was left in the page cache.
      -** -**
      SQLITE_STATUS_PAGECACHE_SIZE
      -**
      This parameter records the largest memory allocation request -** handed to [pagecache memory allocator]. Only the value returned in the -** *pHighwater parameter to [sqlite3_status()] is of interest. -** The value written into the *pCurrent parameter is undefined.
      -** -**
      SQLITE_STATUS_SCRATCH_USED
      -**
      This parameter returns the number of allocations used out of the -** [scratch memory allocator] configured using -** [SQLITE_CONFIG_SCRATCH]. The value returned is in allocations, not -** in bytes. Since a single thread may only have one scratch allocation -** outstanding at time, this parameter also reports the number of threads -** using scratch memory at the same time.
      -** -**
      SQLITE_STATUS_SCRATCH_OVERFLOW
      -**
      This parameter returns the number of bytes of scratch memory -** allocation which could not be statisfied by the [SQLITE_CONFIG_SCRATCH] -** buffer and where forced to overflow to [sqlite3_malloc()]. The values -** returned include overflows because the requested allocation was too -** larger (that is, because the requested allocation was larger than the -** "sz" parameter to [SQLITE_CONFIG_SCRATCH]) and because no scratch buffer -** slots were available. -**
      -** -**
      SQLITE_STATUS_SCRATCH_SIZE
      -**
      This parameter records the largest memory allocation request -** handed to [scratch memory allocator]. Only the value returned in the -** *pHighwater parameter to [sqlite3_status()] is of interest. -** The value written into the *pCurrent parameter is undefined.
      -** -**
      SQLITE_STATUS_PARSER_STACK
      -**
      This parameter records the deepest parser stack. It is only -** meaningful if SQLite is compiled with [YYTRACKMAXSTACKDEPTH].
      -**
      -** -** New status parameters may be added from time to time. -*/ -#define SQLITE_STATUS_MEMORY_USED 0 -#define SQLITE_STATUS_PAGECACHE_USED 1 -#define SQLITE_STATUS_PAGECACHE_OVERFLOW 2 -#define SQLITE_STATUS_SCRATCH_USED 3 -#define SQLITE_STATUS_SCRATCH_OVERFLOW 4 -#define SQLITE_STATUS_MALLOC_SIZE 5 -#define SQLITE_STATUS_PARSER_STACK 6 -#define SQLITE_STATUS_PAGECACHE_SIZE 7 -#define SQLITE_STATUS_SCRATCH_SIZE 8 - -/* -** CAPI3REF: Database Connection Status {H17500} -** EXPERIMENTAL -** -** This interface is used to retrieve runtime status information -** about a single [database connection]. The first argument is the -** database connection object to be interrogated. The second argument -** is the parameter to interrogate. Currently, the only allowed value -** for the second parameter is [SQLITE_DBSTATUS_LOOKASIDE_USED]. -** Additional options will likely appear in future releases of SQLite. -** -** The current value of the requested parameter is written into *pCur -** and the highest instantaneous value is written into *pHiwtr. If -** the resetFlg is true, then the highest instantaneous value is -** reset back down to the current value. -** -** See also: [sqlite3_status()] and [sqlite3_stmt_status()]. -*/ -SQLITE_EXPERIMENTAL int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg); - -/* -** CAPI3REF: Status Parameters for database connections {H17520} -** EXPERIMENTAL -** -** Status verbs for [sqlite3_db_status()]. -** -**
      -**
      SQLITE_DBSTATUS_LOOKASIDE_USED
      -**
      This parameter returns the number of lookaside memory slots currently -** checked out.
      -**
      -*/ -#define SQLITE_DBSTATUS_LOOKASIDE_USED 0 - - -/* -** CAPI3REF: Prepared Statement Status {H17550} -** EXPERIMENTAL -** -** Each prepared statement maintains various -** [SQLITE_STMTSTATUS_SORT | counters] that measure the number -** of times it has performed specific operations. These counters can -** be used to monitor the performance characteristics of the prepared -** statements. For example, if the number of table steps greatly exceeds -** the number of table searches or result rows, that would tend to indicate -** that the prepared statement is using a full table scan rather than -** an index. -** -** This interface is used to retrieve and reset counter values from -** a [prepared statement]. The first argument is the prepared statement -** object to be interrogated. The second argument -** is an integer code for a specific [SQLITE_STMTSTATUS_SORT | counter] -** to be interrogated. -** The current value of the requested counter is returned. -** If the resetFlg is true, then the counter is reset to zero after this -** interface call returns. -** -** See also: [sqlite3_status()] and [sqlite3_db_status()]. -*/ -SQLITE_EXPERIMENTAL int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg); - -/* -** CAPI3REF: Status Parameters for prepared statements {H17570} -** EXPERIMENTAL -** -** These preprocessor macros define integer codes that name counter -** values associated with the [sqlite3_stmt_status()] interface. -** The meanings of the various counters are as follows: -** -**
      -**
      SQLITE_STMTSTATUS_FULLSCAN_STEP
      -**
      This is the number of times that SQLite has stepped forward in -** a table as part of a full table scan. Large numbers for this counter -** may indicate opportunities for performance improvement through -** careful use of indices.
      -** -**
      SQLITE_STMTSTATUS_SORT
      -**
      This is the number of sort operations that have occurred. -** A non-zero value in this counter may indicate an opportunity to -** improvement performance through careful use of indices.
      -** -**
      -*/ -#define SQLITE_STMTSTATUS_FULLSCAN_STEP 1 -#define SQLITE_STMTSTATUS_SORT 2 /* ** Undo the hack that converts floating point types to integer for diff --git a/mozilla/toolkit/components/places/src/nsNavHistory.cpp b/mozilla/toolkit/components/places/src/nsNavHistory.cpp index d9f9b690d3d..7493086a2be 100644 --- a/mozilla/toolkit/components/places/src/nsNavHistory.cpp +++ b/mozilla/toolkit/components/places/src/nsNavHistory.cpp @@ -766,11 +766,6 @@ nsNavHistory::InitDB(PRInt16 *aMadeChanges) NS_LITERAL_CSTRING("PRAGMA locking_mode = EXCLUSIVE")); NS_ENSURE_SUCCESS(rv, rv); - // We use the TRUNCATE journal mode to reduce the number of fsyncs - rv = mDBConn->ExecuteSimpleSQL( - NS_LITERAL_CSTRING("PRAGMA journal_mode = TRUNCATE")); - NS_ENSURE_SUCCESS(rv, rv); - // moz_places if (!tableExists) { *aMadeChanges = DB_MIGRATION_CREATED;