update bundled sqlite to 3.8.6.0

The "Fixed CE build of sqlite3" patch is *updated* in this change.
Since sqlite 3.8.6, SQLITE_OS_WINCE isn't defined early enough so we
have to check _WIN32_WCE directly.
(ea70ec8711)

Change-Id: I63ee5163fb915274c9780c169e1f8673755bba47
Reviewed-by: Andy Shaw <andy.shaw@digia.com>
This commit is contained in:
Mark Brand 2014-09-17 10:03:53 +02:00
parent 55fbf1db19
commit 095f760463
3 changed files with 2446 additions and 1187 deletions

View File

@ -64,6 +64,7 @@
#if defined(_WIN32) || defined(WIN32) #if defined(_WIN32) || defined(WIN32)
# include <io.h> # include <io.h>
# include <fcntl.h>
#define isatty(h) _isatty(h) #define isatty(h) _isatty(h)
#ifndef access #ifndef access
# define access(f,m) _access((f),(m)) # define access(f,m) _access((f),(m))
@ -458,6 +459,7 @@ struct callback_data {
int showHeader; /* True to show column names in List or Column mode */ int showHeader; /* True to show column names in List or Column mode */
char *zDestTable; /* Name of destination table when MODE_Insert */ char *zDestTable; /* Name of destination table when MODE_Insert */
char separator[20]; /* Separator character for MODE_List */ char separator[20]; /* Separator character for MODE_List */
char newline[20]; /* Record separator in MODE_Csv */
int colWidth[100]; /* Requested width of each column when in column mode*/ int colWidth[100]; /* Requested width of each column when in column mode*/
int actualWidth[100]; /* Actual width of each column */ int actualWidth[100]; /* Actual width of each column */
char nullvalue[20]; /* The text to print when a NULL comes back from char nullvalue[20]; /* The text to print when a NULL comes back from
@ -659,7 +661,8 @@ static const char needCsvQuote[] = {
/* /*
** Output a single term of CSV. Actually, p->separator is used for ** Output a single term of CSV. Actually, p->separator is used for
** the separator, which may or may not be a comma. p->nullvalue is ** the separator, which may or may not be a comma. p->nullvalue is
** the null value. Strings are quoted if necessary. ** the null value. Strings are quoted if necessary. The separator
** is only issued if bSep is true.
*/ */
static void output_csv(struct callback_data *p, const char *z, int bSep){ static void output_csv(struct callback_data *p, const char *z, int bSep){
FILE *out = p->out; FILE *out = p->out;
@ -855,17 +858,26 @@ static int shell_callback(void *pArg, int nArg, char **azArg, char **azCol, int
break; break;
} }
case MODE_Csv: { case MODE_Csv: {
#if defined(WIN32) || defined(_WIN32)
fflush(p->out);
_setmode(_fileno(p->out), _O_BINARY);
#endif
if( p->cnt++==0 && p->showHeader ){ if( p->cnt++==0 && p->showHeader ){
for(i=0; i<nArg; i++){ for(i=0; i<nArg; i++){
output_csv(p, azCol[i] ? azCol[i] : "", i<nArg-1); output_csv(p, azCol[i] ? azCol[i] : "", i<nArg-1);
} }
fprintf(p->out,"\n"); fprintf(p->out,"%s",p->newline);
} }
if( azArg==0 ) break; if( azArg>0 ){
for(i=0; i<nArg; i++){ for(i=0; i<nArg; i++){
output_csv(p, azArg[i], i<nArg-1); output_csv(p, azArg[i], i<nArg-1);
} }
fprintf(p->out,"\n"); fprintf(p->out,"%s",p->newline);
}
#if defined(WIN32) || defined(_WIN32)
fflush(p->out);
_setmode(_fileno(p->out), _O_TEXT);
#endif
break; break;
} }
case MODE_Insert: { case MODE_Insert: {
@ -1579,9 +1591,11 @@ static char zHelp[] =
" If TABLE specified, only dump tables matching\n" " If TABLE specified, only dump tables matching\n"
" LIKE pattern TABLE.\n" " LIKE pattern TABLE.\n"
".echo on|off Turn command echo on or off\n" ".echo on|off Turn command echo on or off\n"
".eqp on|off Enable or disable automatic EXPLAIN QUERY PLAN\n"
".exit Exit this program\n" ".exit Exit this program\n"
".explain ?on|off? Turn output mode suitable for EXPLAIN on or off.\n" ".explain ?on|off? Turn output mode suitable for EXPLAIN on or off.\n"
" With no args, it turns EXPLAIN on.\n" " With no args, it turns EXPLAIN on.\n"
".fullschema Show schema and the content of sqlite_stat tables\n"
".headers on|off Turn display of headers on or off\n" ".headers on|off Turn display of headers on or off\n"
".help Show this message\n" ".help Show this message\n"
".import FILE TABLE Import data from FILE into TABLE\n" ".import FILE TABLE Import data from FILE into TABLE\n"
@ -1617,7 +1631,8 @@ static char zHelp[] =
".schema ?TABLE? Show the CREATE statements\n" ".schema ?TABLE? Show the CREATE statements\n"
" If TABLE specified, only show tables matching\n" " If TABLE specified, only show tables matching\n"
" LIKE pattern TABLE.\n" " LIKE pattern TABLE.\n"
".separator STRING Change separator used by output mode and .import\n" ".separator STRING ?NL? Change separator used by output mode and .import\n"
" NL is the end-of-line mark for CSV\n"
".shell CMD ARGS... Run CMD ARGS... in a system shell\n" ".shell CMD ARGS... Run CMD ARGS... in a system shell\n"
".show Show the current values for various settings\n" ".show Show the current values for various settings\n"
".stats on|off Turn stats on or off\n" ".stats on|off Turn stats on or off\n"
@ -1635,6 +1650,66 @@ static char zHelp[] =
/* Forward reference */ /* Forward reference */
static int process_input(struct callback_data *p, FILE *in); static int process_input(struct callback_data *p, FILE *in);
/*
** Implementation of the "readfile(X)" SQL function. The entire content
** of the file named X is read and returned as a BLOB. NULL is returned
** if the file does not exist or is unreadable.
*/
static void readfileFunc(
sqlite3_context *context,
int argc,
sqlite3_value **argv
){
const char *zName;
FILE *in;
long nIn;
void *pBuf;
zName = (const char*)sqlite3_value_text(argv[0]);
if( zName==0 ) return;
in = fopen(zName, "rb");
if( in==0 ) return;
fseek(in, 0, SEEK_END);
nIn = ftell(in);
rewind(in);
pBuf = sqlite3_malloc( nIn );
if( pBuf && 1==fread(pBuf, nIn, 1, in) ){
sqlite3_result_blob(context, pBuf, nIn, sqlite3_free);
}else{
sqlite3_free(pBuf);
}
fclose(in);
}
/*
** Implementation of the "writefile(X,Y)" SQL function. The argument Y
** is written into file X. The number of bytes written is returned. Or
** NULL is returned if something goes wrong, such as being unable to open
** file X for writing.
*/
static void writefileFunc(
sqlite3_context *context,
int argc,
sqlite3_value **argv
){
FILE *out;
const char *z;
sqlite3_int64 rc;
const char *zFile;
zFile = (const char*)sqlite3_value_text(argv[0]);
if( zFile==0 ) return;
out = fopen(zFile, "wb");
if( out==0 ) return;
z = (const char*)sqlite3_value_blob(argv[1]);
if( z==0 ){
rc = 0;
}else{
rc = fwrite(z, 1, sqlite3_value_bytes(argv[1]), out);
}
fclose(out);
sqlite3_result_int64(context, rc);
}
/* /*
** Make sure the database is open. If it is not, then open it. If ** Make sure the database is open. If it is not, then open it. If
@ -1658,6 +1733,10 @@ static void open_db(struct callback_data *p, int keepAlive){
#ifndef SQLITE_OMIT_LOAD_EXTENSION #ifndef SQLITE_OMIT_LOAD_EXTENSION
sqlite3_enable_load_extension(p->db, 1); sqlite3_enable_load_extension(p->db, 1);
#endif #endif
sqlite3_create_function(db, "readfile", 1, SQLITE_UTF8, 0,
readfileFunc, 0, 0);
sqlite3_create_function(db, "writefile", 2, SQLITE_UTF8, 0,
writefileFunc, 0, 0);
} }
} }
@ -2411,6 +2490,57 @@ static int do_meta_command(char *zLine, struct callback_data *p){
} }
}else }else
if( c=='f' && strncmp(azArg[0], "fullschema", n)==0 ){
struct callback_data data;
char *zErrMsg = 0;
int doStats = 0;
if( nArg!=1 ){
fprintf(stderr, "Usage: .fullschema\n");
rc = 1;
goto meta_command_exit;
}
open_db(p, 0);
memcpy(&data, p, sizeof(data));
data.showHeader = 0;
data.mode = MODE_Semi;
rc = sqlite3_exec(p->db,
"SELECT sql FROM"
" (SELECT sql sql, type type, tbl_name tbl_name, name name, rowid x"
" FROM sqlite_master UNION ALL"
" SELECT sql, type, tbl_name, name, rowid FROM sqlite_temp_master) "
"WHERE type!='meta' AND sql NOTNULL AND name NOT LIKE 'sqlite_%'"
"ORDER BY rowid",
callback, &data, &zErrMsg
);
if( rc==SQLITE_OK ){
sqlite3_stmt *pStmt;
rc = sqlite3_prepare_v2(p->db,
"SELECT rowid FROM sqlite_master"
" WHERE name GLOB 'sqlite_stat[134]'",
-1, &pStmt, 0);
doStats = sqlite3_step(pStmt)==SQLITE_ROW;
sqlite3_finalize(pStmt);
}
if( doStats==0 ){
fprintf(p->out, "/* No STAT tables available */\n");
}else{
fprintf(p->out, "ANALYZE sqlite_master;\n");
sqlite3_exec(p->db, "SELECT 'ANALYZE sqlite_master'",
callback, &data, &zErrMsg);
data.mode = MODE_Insert;
data.zDestTable = "sqlite_stat1";
shell_exec(p->db, "SELECT * FROM sqlite_stat1",
shell_callback, &data,&zErrMsg);
data.zDestTable = "sqlite_stat3";
shell_exec(p->db, "SELECT * FROM sqlite_stat3",
shell_callback, &data,&zErrMsg);
data.zDestTable = "sqlite_stat4";
shell_exec(p->db, "SELECT * FROM sqlite_stat4",
shell_callback, &data, &zErrMsg);
fprintf(p->out, "ANALYZE sqlite_master;\n");
}
}else
if( c=='h' && strncmp(azArg[0], "headers", n)==0 ){ if( c=='h' && strncmp(azArg[0], "headers", n)==0 ){
if( nArg==2 ){ if( nArg==2 ){
p->showHeader = booleanValue(azArg[1]); p->showHeader = booleanValue(azArg[1]);
@ -2553,7 +2683,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){
"filling the rest with NULL\n", "filling the rest with NULL\n",
sCsv.zFile, startLine, nCol, i+1); sCsv.zFile, startLine, nCol, i+1);
i++; i++;
while( i<nCol ){ sqlite3_bind_null(pStmt, i); i++; } while( i<=nCol ){ sqlite3_bind_null(pStmt, i); i++; }
} }
} }
if( sCsv.cTerm==sCsv.cSeparator ){ if( sCsv.cTerm==sCsv.cSeparator ){
@ -2698,6 +2828,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){
}else if( c2=='c' && strncmp(azArg[1],"csv",n2)==0 ){ }else if( c2=='c' && strncmp(azArg[1],"csv",n2)==0 ){
p->mode = MODE_Csv; p->mode = MODE_Csv;
sqlite3_snprintf(sizeof(p->separator), p->separator, ","); sqlite3_snprintf(sizeof(p->separator), p->separator, ",");
sqlite3_snprintf(sizeof(p->newline), p->newline, "\r\n");
}else if( c2=='t' && strncmp(azArg[1],"tabs",n2)==0 ){ }else if( c2=='t' && strncmp(azArg[1],"tabs",n2)==0 ){
p->mode = MODE_List; p->mode = MODE_List;
sqlite3_snprintf(sizeof(p->separator), p->separator, "\t"); sqlite3_snprintf(sizeof(p->separator), p->separator, "\t");
@ -2976,20 +3107,23 @@ static int do_meta_command(char *zLine, struct callback_data *p){
#endif #endif
if( c=='s' && strncmp(azArg[0], "separator", n)==0 ){ if( c=='s' && strncmp(azArg[0], "separator", n)==0 ){
if( nArg==2 ){ if( nArg<2 || nArg>3 ){
sqlite3_snprintf(sizeof(p->separator), p->separator, fprintf(stderr, "Usage: .separator SEPARATOR ?NEWLINE?\n");
"%.*s", (int)sizeof(p->separator)-1, azArg[1]);
}else{
fprintf(stderr, "Usage: .separator STRING\n");
rc = 1; rc = 1;
} }
if( nArg>=2 ){
sqlite3_snprintf(sizeof(p->separator), p->separator, azArg[1]);
}
if( nArg>=3 ){
sqlite3_snprintf(sizeof(p->newline), p->newline, azArg[2]);
}
}else }else
if( c=='s' if( c=='s'
&& (strncmp(azArg[0], "shell", n)==0 || strncmp(azArg[0],"system",n)==0) && (strncmp(azArg[0], "shell", n)==0 || strncmp(azArg[0],"system",n)==0)
){ ){
char *zCmd; char *zCmd;
int i; int i, x;
if( nArg<2 ){ if( nArg<2 ){
fprintf(stderr, "Usage: .system COMMAND\n"); fprintf(stderr, "Usage: .system COMMAND\n");
rc = 1; rc = 1;
@ -3000,8 +3134,9 @@ static int do_meta_command(char *zLine, struct callback_data *p){
zCmd = sqlite3_mprintf(strchr(azArg[i],' ')==0?"%z %s":"%z \"%s\"", zCmd = sqlite3_mprintf(strchr(azArg[i],' ')==0?"%z %s":"%z \"%s\"",
zCmd, azArg[i]); zCmd, azArg[i]);
} }
(void)system(zCmd); x = system(zCmd);
sqlite3_free(zCmd); sqlite3_free(zCmd);
if( x ) fprintf(stderr, "System command returns %d\n", x);
}else }else
if( c=='s' && strncmp(azArg[0], "show", n)==0 ){ if( c=='s' && strncmp(azArg[0], "show", n)==0 ){
@ -3023,6 +3158,8 @@ static int do_meta_command(char *zLine, struct callback_data *p){
strlen30(p->outfile) ? p->outfile : "stdout"); strlen30(p->outfile) ? p->outfile : "stdout");
fprintf(p->out,"%9.9s: ", "separator"); fprintf(p->out,"%9.9s: ", "separator");
output_c_string(p->out, p->separator); output_c_string(p->out, p->separator);
fprintf(p->out," ");
output_c_string(p->out, p->newline);
fprintf(p->out, "\n"); fprintf(p->out, "\n");
fprintf(p->out,"%9.9s: %s\n","stats", p->statsOn ? "on" : "off"); fprintf(p->out,"%9.9s: %s\n","stats", p->statsOn ? "on" : "off");
fprintf(p->out,"%9.9s: ","width"); fprintf(p->out,"%9.9s: ","width");
@ -3639,6 +3776,7 @@ static const char zOptions[] =
#ifdef SQLITE_ENABLE_MULTIPLEX #ifdef SQLITE_ENABLE_MULTIPLEX
" -multiplex enable the multiplexor VFS\n" " -multiplex enable the multiplexor VFS\n"
#endif #endif
" -newline SEP set newline character(s) for CSV\n"
" -nullvalue TEXT set text string for NULL values. Default ''\n" " -nullvalue TEXT set text string for NULL values. Default ''\n"
" -separator SEP set output field separator. Default: '|'\n" " -separator SEP set output field separator. Default: '|'\n"
" -stats print memory stats before each finalize\n" " -stats print memory stats before each finalize\n"
@ -3668,6 +3806,7 @@ static void main_init(struct callback_data *data) {
memset(data, 0, sizeof(*data)); memset(data, 0, sizeof(*data));
data->mode = MODE_List; data->mode = MODE_List;
memcpy(data->separator,"|", 2); memcpy(data->separator,"|", 2);
memcpy(data->newline,"\r\n", 3);
data->showHeader = 0; data->showHeader = 0;
sqlite3_config(SQLITE_CONFIG_URI, 1); sqlite3_config(SQLITE_CONFIG_URI, 1);
sqlite3_config(SQLITE_CONFIG_LOG, shellLog, data); sqlite3_config(SQLITE_CONFIG_LOG, shellLog, data);
@ -3760,6 +3899,7 @@ int main(int argc, char **argv){
if( z[1]=='-' ) z++; if( z[1]=='-' ) z++;
if( strcmp(z,"-separator")==0 if( strcmp(z,"-separator")==0
|| strcmp(z,"-nullvalue")==0 || strcmp(z,"-nullvalue")==0
|| strcmp(z,"-newline")==0
|| strcmp(z,"-cmd")==0 || strcmp(z,"-cmd")==0
){ ){
(void)cmdline_option_value(argc, argv, ++i); (void)cmdline_option_value(argc, argv, ++i);
@ -3869,6 +4009,9 @@ int main(int argc, char **argv){
}else if( strcmp(z,"-separator")==0 ){ }else if( strcmp(z,"-separator")==0 ){
sqlite3_snprintf(sizeof(data.separator), data.separator, sqlite3_snprintf(sizeof(data.separator), data.separator,
"%s",cmdline_option_value(argc,argv,++i)); "%s",cmdline_option_value(argc,argv,++i));
}else if( strcmp(z,"-newline")==0 ){
sqlite3_snprintf(sizeof(data.newline), data.newline,
"%s",cmdline_option_value(argc,argv,++i));
}else if( strcmp(z,"-nullvalue")==0 ){ }else if( strcmp(z,"-nullvalue")==0 ){
sqlite3_snprintf(sizeof(data.nullvalue), data.nullvalue, sqlite3_snprintf(sizeof(data.nullvalue), data.nullvalue,
"%s",cmdline_option_value(argc,argv,++i)); "%s",cmdline_option_value(argc,argv,++i));

File diff suppressed because it is too large Load Diff

View File

@ -107,9 +107,9 @@ extern "C" {
** [sqlite3_libversion_number()], [sqlite3_sourceid()], ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
** [sqlite_version()] and [sqlite_source_id()]. ** [sqlite_version()] and [sqlite_source_id()].
*/ */
#define SQLITE_VERSION "3.8.5" #define SQLITE_VERSION "3.8.6"
#define SQLITE_VERSION_NUMBER 3008005 #define SQLITE_VERSION_NUMBER 3008006
#define SQLITE_SOURCE_ID "2014-06-04 14:06:34 b1ed4f2a34ba66c29b130f8d13e9092758019212" #define SQLITE_SOURCE_ID "2014-08-15 11:46:33 9491ba7d738528f168657adb43a198238abde19e"
/* /*
** CAPI3REF: Run-Time Library Version Numbers ** CAPI3REF: Run-Time Library Version Numbers
@ -269,7 +269,7 @@ typedef sqlite_uint64 sqlite3_uint64;
** **
** ^The sqlite3_close() and sqlite3_close_v2() routines are destructors ** ^The sqlite3_close() and sqlite3_close_v2() routines are destructors
** for the [sqlite3] object. ** for the [sqlite3] object.
** ^Calls to sqlite3_close() and sqlite3_close_v2() return SQLITE_OK if ** ^Calls to sqlite3_close() and sqlite3_close_v2() return [SQLITE_OK] if
** the [sqlite3] object is successfully destroyed and all associated ** the [sqlite3] object is successfully destroyed and all associated
** resources are deallocated. ** resources are deallocated.
** **
@ -277,7 +277,7 @@ typedef sqlite_uint64 sqlite3_uint64;
** statements or unfinished sqlite3_backup objects then sqlite3_close() ** statements or unfinished sqlite3_backup objects then sqlite3_close()
** will leave the database connection open and return [SQLITE_BUSY]. ** will leave the database connection open and return [SQLITE_BUSY].
** ^If sqlite3_close_v2() is called with unfinalized prepared statements ** ^If sqlite3_close_v2() is called with unfinalized prepared statements
** and unfinished sqlite3_backups, then the database connection becomes ** and/or unfinished sqlite3_backups, then the database connection becomes
** an unusable "zombie" which will automatically be deallocated when the ** an unusable "zombie" which will automatically be deallocated when the
** last prepared statement is finalized or the last sqlite3_backup is ** last prepared statement is finalized or the last sqlite3_backup is
** finished. The sqlite3_close_v2() interface is intended for use with ** finished. The sqlite3_close_v2() interface is intended for use with
@ -290,7 +290,7 @@ typedef sqlite_uint64 sqlite3_uint64;
** with the [sqlite3] object prior to attempting to close the object. ^If ** with the [sqlite3] object prior to attempting to close the object. ^If
** sqlite3_close_v2() is called on a [database connection] that still has ** sqlite3_close_v2() is called on a [database connection] that still has
** outstanding [prepared statements], [BLOB handles], and/or ** outstanding [prepared statements], [BLOB handles], and/or
** [sqlite3_backup] objects then it returns SQLITE_OK but the deallocation ** [sqlite3_backup] objects then it returns [SQLITE_OK] and the deallocation
** of resources is deferred until all [prepared statements], [BLOB handles], ** of resources is deferred until all [prepared statements], [BLOB handles],
** and [sqlite3_backup] objects are also destroyed. ** and [sqlite3_backup] objects are also destroyed.
** **
@ -386,16 +386,14 @@ SQLITE_API int sqlite3_exec(
/* /*
** CAPI3REF: Result Codes ** CAPI3REF: Result Codes
** KEYWORDS: SQLITE_OK {error code} {error codes} ** KEYWORDS: {result code definitions}
** KEYWORDS: {result code} {result codes}
** **
** Many SQLite functions return an integer result code from the set shown ** Many SQLite functions return an integer result code from the set shown
** here in order to indicate success or failure. ** here in order to indicate success or failure.
** **
** New error codes may be added in future versions of SQLite. ** New error codes may be added in future versions of SQLite.
** **
** See also: [SQLITE_IOERR_READ | extended result codes], ** See also: [extended result code definitions]
** [sqlite3_vtab_on_conflict()] [SQLITE_ROLLBACK | result codes].
*/ */
#define SQLITE_OK 0 /* Successful result */ #define SQLITE_OK 0 /* Successful result */
/* beginning-of-error-codes */ /* beginning-of-error-codes */
@ -433,26 +431,19 @@ SQLITE_API int sqlite3_exec(
/* /*
** CAPI3REF: Extended Result Codes ** CAPI3REF: Extended Result Codes
** KEYWORDS: {extended error code} {extended error codes} ** KEYWORDS: {extended result code definitions}
** KEYWORDS: {extended result code} {extended result codes}
** **
** In its default configuration, SQLite API routines return one of 26 integer ** In its default configuration, SQLite API routines return one of 30 integer
** [SQLITE_OK | result codes]. However, experience has shown that many of ** [result codes]. However, experience has shown that many of
** these result codes are too coarse-grained. They do not provide as ** these result codes are too coarse-grained. They do not provide as
** much information about problems as programmers might like. In an effort to ** 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 ** address this, newer versions of SQLite (version 3.3.8 and later) include
** support for additional result codes that provide more detailed information ** support for additional result codes that provide more detailed information
** about errors. The extended result codes are enabled or disabled ** about errors. These [extended result codes] are enabled or disabled
** on a per database connection basis using the ** on a per database connection basis using the
** [sqlite3_extended_result_codes()] API. ** [sqlite3_extended_result_codes()] API. Or, the extended code for
** ** the most recent error can be obtained using
** Some of the available extended result codes are listed here. ** [sqlite3_extended_errcode()].
** One may expect the number of extended result codes will increase
** over time. Software that uses extended result codes should expect
** to see new result codes in future releases of SQLite.
**
** The SQLITE_OK result code will never be extended. It will always
** be exactly zero.
*/ */
#define SQLITE_IOERR_READ (SQLITE_IOERR | (1<<8)) #define SQLITE_IOERR_READ (SQLITE_IOERR | (1<<8))
#define SQLITE_IOERR_SHORT_READ (SQLITE_IOERR | (2<<8)) #define SQLITE_IOERR_SHORT_READ (SQLITE_IOERR | (2<<8))
@ -685,7 +676,7 @@ struct sqlite3_file {
** locking strategy (for example to use dot-file locks), to inquire ** locking strategy (for example to use dot-file locks), to inquire
** about the status of a lock, or to break stale locks. The SQLite ** 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 all opcodes less than 100 for its own use.
** A [SQLITE_FCNTL_LOCKSTATE | list of opcodes] less than 100 is available. ** A [file control opcodes | 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. VFS implementations should ** greater than 100 to avoid conflicts. VFS implementations should
** return [SQLITE_NOTFOUND] for file control opcodes that they do not ** return [SQLITE_NOTFOUND] for file control opcodes that they do not
@ -758,6 +749,7 @@ struct sqlite3_io_methods {
/* /*
** CAPI3REF: Standard File Control Opcodes ** CAPI3REF: Standard File Control Opcodes
** KEYWORDS: {file control opcodes} {file control opcode}
** **
** These integer constants are opcodes for the xFileControl method ** 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 for the [sqlite3_file_control()]
@ -2037,27 +2029,33 @@ SQLITE_API int sqlite3_complete16(const void *sql);
/* /*
** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors ** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors
** **
** ^This routine sets a callback function that might be invoked whenever ** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X
** an attempt is made to open a database table that another thread ** that might be invoked with argument P whenever
** or process has locked. ** an attempt is made to access a database table associated with
** [database connection] D when another thread
** or process has the table locked.
** The sqlite3_busy_handler() interface is used to implement
** [sqlite3_busy_timeout()] and [PRAGMA busy_timeout].
** **
** ^If the busy callback is NULL, then [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED] ** ^If the busy callback is NULL, then [SQLITE_BUSY]
** is returned immediately upon encountering the lock. ^If the busy callback ** is returned immediately upon encountering the lock. ^If the busy callback
** is not NULL, then the callback might be invoked with two arguments. ** is not NULL, then the callback might be invoked with two arguments.
** **
** ^The first argument to the busy handler is a copy of the void* pointer which ** ^The first argument to the busy handler is a copy of the void* pointer which
** is the third argument to sqlite3_busy_handler(). ^The second argument to ** is the third argument to sqlite3_busy_handler(). ^The second argument to
** the busy handler callback is the number of times that the busy handler has ** the busy handler callback is the number of times that the busy handler has
** been invoked for this locking event. ^If the ** been invoked for the same locking event. ^If the
** busy callback returns 0, then no additional attempts are made to ** busy callback returns 0, then no additional attempts are made to
** access the database and [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED] is returned. ** access the database and [SQLITE_BUSY] is returned
** to the application.
** ^If the callback returns non-zero, then another attempt ** ^If the callback returns non-zero, then another attempt
** is made to open the database for reading and the cycle repeats. ** is made to access the database and the cycle repeats.
** **
** The presence of a busy handler does not guarantee that it will be invoked ** 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 ** 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] ** handler could result in a deadlock, it will go ahead and return [SQLITE_BUSY]
** or [SQLITE_IOERR_BLOCKED] instead of invoking the busy handler. ** to the application instead of invoking the
** busy handler.
** Consider a scenario where one process is holding a read lock that ** Consider a scenario where one process is holding a read lock that
** it is trying to promote to a reserved lock and ** it is trying to promote to a reserved lock and
** a second process is holding a reserved lock that it is trying ** a second process is holding a reserved lock that it is trying
@ -2071,28 +2069,15 @@ SQLITE_API int sqlite3_complete16(const void *sql);
** **
** ^The default busy callback is NULL. ** ^The default busy callback is NULL.
** **
** ^The [SQLITE_BUSY] error is converted to [SQLITE_IOERR_BLOCKED]
** when SQLite is in the middle of a large transaction where all the
** changes will not fit into the in-memory cache. SQLite will
** already hold a RESERVED lock on the database file, but it needs
** to promote this lock to EXCLUSIVE so that it can spill cache
** pages into the database file without harm to concurrent
** readers. ^If it is unable to promote the lock, then the in-memory
** cache will be left in an inconsistent state and so the error
** 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
** <a href="/cvstrac/wiki?p=CorruptionFollowingBusyError">
** CorruptionFollowingBusyError</a> wiki page for a discussion of why
** this is important.
**
** ^(There can only be a single busy handler defined for each ** ^(There can only be a single busy handler defined for each
** [database connection]. Setting a new busy handler clears any ** [database connection]. Setting a new busy handler clears any
** previously set handler.)^ ^Note that calling [sqlite3_busy_timeout()] ** previously set handler.)^ ^Note that calling [sqlite3_busy_timeout()]
** will also set or clear the busy handler. ** or evaluating [PRAGMA busy_timeout=N] will change the
** busy handler and thus clear any previously set busy handler.
** **
** The busy callback should not take any actions which modify the ** The busy callback should not take any actions which modify the
** database connection that invoked the busy handler. Any such actions ** database connection that invoked the busy handler. In other words,
** the busy handler is not reentrant. Any such actions
** result in undefined behavior. ** result in undefined behavior.
** **
** A busy handler must not close the database connection ** A busy handler must not close the database connection
@ -2108,7 +2093,7 @@ SQLITE_API int sqlite3_busy_handler(sqlite3*, int(*)(void*,int), void*);
** will sleep multiple times until at least "ms" milliseconds of sleeping ** will sleep multiple times until at least "ms" milliseconds of sleeping
** have accumulated. ^After at least "ms" milliseconds of sleeping, ** have accumulated. ^After at least "ms" milliseconds of sleeping,
** the handler returns 0 which causes [sqlite3_step()] to return ** the handler returns 0 which causes [sqlite3_step()] to return
** [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED]. ** [SQLITE_BUSY].
** **
** ^Calling this routine with an argument less than or equal to zero ** ^Calling this routine with an argument less than or equal to zero
** turns off all busy handlers. ** turns off all busy handlers.
@ -2117,6 +2102,8 @@ SQLITE_API int sqlite3_busy_handler(sqlite3*, int(*)(void*,int), void*);
** [database connection] any any given moment. If another busy handler ** [database connection] any any given moment. If another busy handler
** was defined (using [sqlite3_busy_handler()]) prior to calling ** was defined (using [sqlite3_busy_handler()]) prior to calling
** this routine, that other busy handler is cleared.)^ ** this routine, that other busy handler is cleared.)^
**
** See also: [PRAGMA busy_timeout]
*/ */
SQLITE_API int sqlite3_busy_timeout(sqlite3*, int ms); SQLITE_API int sqlite3_busy_timeout(sqlite3*, int ms);
@ -2518,8 +2505,8 @@ SQLITE_API int sqlite3_set_authorizer(
** [sqlite3_set_authorizer | authorizer documentation] for additional ** [sqlite3_set_authorizer | authorizer documentation] for additional
** information. ** information.
** **
** Note that SQLITE_IGNORE is also used as a [SQLITE_ROLLBACK | return code] ** Note that SQLITE_IGNORE is also used as a [conflict resolution mode]
** from the [sqlite3_vtab_on_conflict()] interface. ** returned from the [sqlite3_vtab_on_conflict()] interface.
*/ */
#define SQLITE_DENY 1 /* Abort the SQL statement with an error */ #define SQLITE_DENY 1 /* Abort the SQL statement with an error */
#define SQLITE_IGNORE 2 /* Don't allow access, but don't generate an error */ #define SQLITE_IGNORE 2 /* Don't allow access, but don't generate an error */
@ -4706,6 +4693,13 @@ SQLITE_API int sqlite3_sleep(int);
** is a NULL pointer, then SQLite performs a search for an appropriate ** is a NULL pointer, then SQLite performs a search for an appropriate
** temporary file directory. ** temporary file directory.
** **
** Applications are strongly discouraged from using this global variable.
** It is required to set a temporary folder on Windows Runtime (WinRT).
** But for all other platforms, it is highly recommended that applications
** neither read nor write this variable. This global variable is a relic
** that exists for backwards compatibility of legacy applications and should
** be avoided in new projects.
**
** It is not safe to read or modify this variable in more than one ** It is not safe to read or modify this variable in more than one
** thread at a time. It is not safe to read or modify this variable ** thread at a time. It is not safe to read or modify this variable
** if a [database connection] is being used at the same time in a separate ** if a [database connection] is being used at the same time in a separate
@ -4724,6 +4718,11 @@ SQLITE_API int sqlite3_sleep(int);
** Hence, if this variable is modified directly, either it should be ** Hence, if this variable is modified directly, either it should be
** made NULL or made to point to memory obtained from [sqlite3_malloc] ** made NULL or made to point to memory obtained from [sqlite3_malloc]
** or else the use of the [temp_store_directory pragma] should be avoided. ** or else the use of the [temp_store_directory pragma] should be avoided.
** Except when requested by the [temp_store_directory pragma], SQLite
** does not free the memory that sqlite3_temp_directory points to. If
** the application wants that memory to be freed, it must do
** so itself, taking care to only do so after all [database connection]
** objects have been destroyed.
** **
** <b>Note to Windows Runtime users:</b> The temporary directory must be set ** <b>Note to Windows Runtime users:</b> The temporary directory must be set
** prior to calling [sqlite3_open] or [sqlite3_open_v2]. Otherwise, various ** prior to calling [sqlite3_open] or [sqlite3_open_v2]. Otherwise, various
@ -5858,10 +5857,12 @@ SQLITE_API int sqlite3_vfs_unregister(sqlite3_vfs*);
** <li> SQLITE_MUTEX_RECURSIVE ** <li> SQLITE_MUTEX_RECURSIVE
** <li> SQLITE_MUTEX_STATIC_MASTER ** <li> SQLITE_MUTEX_STATIC_MASTER
** <li> SQLITE_MUTEX_STATIC_MEM ** <li> SQLITE_MUTEX_STATIC_MEM
** <li> SQLITE_MUTEX_STATIC_MEM2 ** <li> SQLITE_MUTEX_STATIC_OPEN
** <li> SQLITE_MUTEX_STATIC_PRNG ** <li> SQLITE_MUTEX_STATIC_PRNG
** <li> SQLITE_MUTEX_STATIC_LRU ** <li> SQLITE_MUTEX_STATIC_LRU
** <li> SQLITE_MUTEX_STATIC_LRU2 ** <li> SQLITE_MUTEX_STATIC_PMEM
** <li> SQLITE_MUTEX_STATIC_APP1
** <li> SQLITE_MUTEX_STATIC_APP2
** </ul>)^ ** </ul>)^
** **
** ^The first two constants (SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE) ** ^The first two constants (SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE)
@ -6065,6 +6066,9 @@ SQLITE_API int sqlite3_mutex_notheld(sqlite3_mutex*);
#define SQLITE_MUTEX_STATIC_LRU 6 /* lru page list */ #define SQLITE_MUTEX_STATIC_LRU 6 /* lru page list */
#define SQLITE_MUTEX_STATIC_LRU2 7 /* NOT USED */ #define SQLITE_MUTEX_STATIC_LRU2 7 /* NOT USED */
#define SQLITE_MUTEX_STATIC_PMEM 7 /* sqlite3PageMalloc() */ #define SQLITE_MUTEX_STATIC_PMEM 7 /* sqlite3PageMalloc() */
#define SQLITE_MUTEX_STATIC_APP1 8 /* For use by application */
#define SQLITE_MUTEX_STATIC_APP2 9 /* For use by application */
#define SQLITE_MUTEX_STATIC_APP3 10 /* For use by application */
/* /*
** CAPI3REF: Retrieve the mutex for a database connection ** CAPI3REF: Retrieve the mutex for a database connection
@ -6160,7 +6164,8 @@ SQLITE_API int sqlite3_test_control(int op, ...);
#define SQLITE_TESTCTRL_NEVER_CORRUPT 20 #define SQLITE_TESTCTRL_NEVER_CORRUPT 20
#define SQLITE_TESTCTRL_VDBE_COVERAGE 21 #define SQLITE_TESTCTRL_VDBE_COVERAGE 21
#define SQLITE_TESTCTRL_BYTEORDER 22 #define SQLITE_TESTCTRL_BYTEORDER 22
#define SQLITE_TESTCTRL_LAST 22 #define SQLITE_TESTCTRL_ISINIT 23
#define SQLITE_TESTCTRL_LAST 23
/* /*
** CAPI3REF: SQLite Runtime Status ** CAPI3REF: SQLite Runtime Status
@ -7144,6 +7149,9 @@ SQLITE_API void *sqlite3_wal_hook(
** ^The [wal_autocheckpoint pragma] can be used to invoke this interface ** ^The [wal_autocheckpoint pragma] can be used to invoke this interface
** from SQL. ** from SQL.
** **
** ^Checkpoints initiated by this mechanism are
** [sqlite3_wal_checkpoint_v2|PASSIVE].
**
** ^Every new [database connection] defaults to having the auto-checkpoint ** ^Every new [database connection] defaults to having the auto-checkpoint
** enabled with a threshold of 1000 or [SQLITE_DEFAULT_WAL_AUTOCHECKPOINT] ** enabled with a threshold of 1000 or [SQLITE_DEFAULT_WAL_AUTOCHECKPOINT]
** pages. The use of this interface ** pages. The use of this interface
@ -7160,6 +7168,10 @@ SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
** empty string, then a checkpoint is run on all databases of ** empty string, then a checkpoint is run on all databases of
** connection D. ^If the database connection D is not in ** connection D. ^If the database connection D is not in
** [WAL | write-ahead log mode] then this interface is a harmless no-op. ** [WAL | write-ahead log mode] then this interface is a harmless no-op.
** ^The [sqlite3_wal_checkpoint(D,X)] interface initiates a
** [sqlite3_wal_checkpoint_v2|PASSIVE] checkpoint.
** Use the [sqlite3_wal_checkpoint_v2()] interface to get a FULL
** or RESET checkpoint.
** **
** ^The [wal_checkpoint pragma] can be used to invoke this interface ** ^The [wal_checkpoint pragma] can be used to invoke this interface
** from SQL. ^The [sqlite3_wal_autocheckpoint()] interface and the ** from SQL. ^The [sqlite3_wal_autocheckpoint()] interface and the
@ -7182,10 +7194,12 @@ SQLITE_API int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb);
** Checkpoint as many frames as possible without waiting for any database ** Checkpoint as many frames as possible without waiting for any database
** readers or writers to finish. Sync the db file if all frames in the log ** readers or writers to finish. Sync the db file if all frames in the log
** are checkpointed. This mode is the same as calling ** are checkpointed. This mode is the same as calling
** sqlite3_wal_checkpoint(). The busy-handler callback is never invoked. ** sqlite3_wal_checkpoint(). The [sqlite3_busy_handler|busy-handler callback]
** is never invoked.
** **
** <dt>SQLITE_CHECKPOINT_FULL<dd> ** <dt>SQLITE_CHECKPOINT_FULL<dd>
** This mode blocks (calls the busy-handler callback) until there is no ** This mode blocks (it invokes the
** [sqlite3_busy_handler|busy-handler callback]) until there is no
** database writer and all readers are reading from the most recent database ** database writer and all readers are reading from the most recent database
** snapshot. It then checkpoints all frames in the log file and syncs the ** snapshot. It then checkpoints all frames in the log file and syncs the
** database file. This call blocks database writers while it is running, ** database file. This call blocks database writers while it is running,
@ -7193,7 +7207,8 @@ SQLITE_API int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb);
** **
** <dt>SQLITE_CHECKPOINT_RESTART<dd> ** <dt>SQLITE_CHECKPOINT_RESTART<dd>
** This mode works the same way as SQLITE_CHECKPOINT_FULL, except after ** This mode works the same way as SQLITE_CHECKPOINT_FULL, except after
** checkpointing the log file it blocks (calls the busy-handler callback) ** checkpointing the log file it blocks (calls the
** [sqlite3_busy_handler|busy-handler callback])
** until all readers are reading from the database file only. This ensures ** until all readers are reading from the database file only. This ensures
** that the next client to write to the database file restarts the log file ** that the next client to write to the database file restarts the log file
** from the beginning. This call blocks database writers while it is running, ** from the beginning. This call blocks database writers while it is running,
@ -7331,6 +7346,7 @@ SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *);
/* /*
** CAPI3REF: Conflict resolution modes ** CAPI3REF: Conflict resolution modes
** KEYWORDS: {conflict resolution mode}
** **
** These constants are returned by [sqlite3_vtab_on_conflict()] to ** These constants are returned by [sqlite3_vtab_on_conflict()] to
** inform a [virtual table] implementation what the [ON CONFLICT] mode ** inform a [virtual table] implementation what the [ON CONFLICT] mode