Fossil SCM

Update the built-in SQLite to the [https://www.sqlite.org/src/timeline?c=d5b0def96ba6d90f|lastest 3.32 alpha].

drh 2020-04-19 17:35 trunk
Commit 05fd5e17b97050d021c5065cb587a0776e6f4fc2dc765512f9833947aba16770
3 files changed +246 -88 +252 -74 +48 -8
+246 -88
--- src/shell.c
+++ src/shell.c
@@ -33,10 +33,18 @@
3333
#if (defined(_WIN32) || defined(WIN32)) && !defined(_CRT_SECURE_NO_WARNINGS)
3434
/* This needs to come before any includes for MSVC compiler */
3535
#define _CRT_SECURE_NO_WARNINGS
3636
#endif
3737
38
+/*
39
+** Determine if we are dealing with WinRT, which provides only a subset of
40
+** the full Win32 API.
41
+*/
42
+#if !defined(SQLITE_OS_WINRT)
43
+# define SQLITE_OS_WINRT 0
44
+#endif
45
+
3846
/*
3947
** Warning pragmas copied from msvc.h in the core.
4048
*/
4149
#if defined(_MSC_VER)
4250
#pragma warning(disable : 4054)
@@ -145,26 +153,30 @@
145153
# define SHELL_USE_LOCAL_GETLINE 1
146154
#endif
147155
148156
149157
#if defined(_WIN32) || defined(WIN32)
150
-# include <io.h>
151
-# include <fcntl.h>
152
-# define isatty(h) _isatty(h)
153
-# ifndef access
154
-# define access(f,m) _access((f),(m))
155
-# endif
156
-# ifndef unlink
157
-# define unlink _unlink
158
-# endif
159
-# ifndef strdup
160
-# define strdup _strdup
161
-# endif
162
-# undef popen
163
-# define popen _popen
164
-# undef pclose
165
-# define pclose _pclose
158
+# if SQLITE_OS_WINRT
159
+# define SQLITE_OMIT_POPEN 1
160
+# else
161
+# include <io.h>
162
+# include <fcntl.h>
163
+# define isatty(h) _isatty(h)
164
+# ifndef access
165
+# define access(f,m) _access((f),(m))
166
+# endif
167
+# ifndef unlink
168
+# define unlink _unlink
169
+# endif
170
+# ifndef strdup
171
+# define strdup _strdup
172
+# endif
173
+# undef popen
174
+# define popen _popen
175
+# undef pclose
176
+# define pclose _pclose
177
+# endif
166178
#else
167179
/* Make sure isatty() has a prototype. */
168180
extern int isatty(int);
169181
170182
# if !defined(__RTP__) && !defined(_WRS_KERNEL)
@@ -189,10 +201,13 @@
189201
#define IsSpace(X) isspace((unsigned char)X)
190202
#define IsDigit(X) isdigit((unsigned char)X)
191203
#define ToLower(X) (char)tolower((unsigned char)X)
192204
193205
#if defined(_WIN32) || defined(WIN32)
206
+#if SQLITE_OS_WINRT
207
+#include <intrin.h>
208
+#endif
194209
#include <windows.h>
195210
196211
/* string conversion routines only needed on Win32 */
197212
extern char *sqlite3_win32_unicode_to_utf8(LPCWSTR);
198213
extern char *sqlite3_win32_mbcs_to_utf8_v2(const char *, int);
@@ -204,11 +219,11 @@
204219
** are automatically translated into \r\n. However, this behavior needs
205220
** to be disabled in some cases (ex: when generating CSV output and when
206221
** rendering quoted strings that contain \n characters). The following
207222
** routines take care of that.
208223
*/
209
-#if defined(_WIN32) || defined(WIN32)
224
+#if (defined(_WIN32) || defined(WIN32)) && !SQLITE_OS_WINRT
210225
static void setBinaryMode(FILE *file, int isOutput){
211226
if( isOutput ) fflush(file);
212227
_setmode(_fileno(file), _O_BINARY);
213228
}
214229
static void setTextMode(FILE *file, int isOutput){
@@ -308,10 +323,11 @@
308323
*/
309324
static int hasTimer(void){
310325
if( getProcessTimesAddr ){
311326
return 1;
312327
} else {
328
+#if !SQLITE_OS_WINRT
313329
/* GetProcessTimes() isn't supported in WIN95 and some other Windows
314330
** versions. See if the version we are running on has it, and if it
315331
** does, save off a pointer to it and the current process handle.
316332
*/
317333
hProcess = GetCurrentProcess();
@@ -324,10 +340,11 @@
324340
return 1;
325341
}
326342
FreeLibrary(hinstLib);
327343
}
328344
}
345
+#endif
329346
}
330347
return 0;
331348
}
332349
333350
/*
@@ -2476,10 +2493,11 @@
24762493
}
24772494
}
24782495
24792496
if( mtime>=0 ){
24802497
#if defined(_WIN32)
2498
+#if !SQLITE_OS_WINRT
24812499
/* Windows */
24822500
FILETIME lastAccess;
24832501
FILETIME lastWrite;
24842502
SYSTEMTIME currentTime;
24852503
LONGLONG intervals;
@@ -2506,10 +2524,11 @@
25062524
CloseHandle(hFile);
25072525
return !bResult;
25082526
}else{
25092527
return 1;
25102528
}
2529
+#endif
25112530
#elif defined(AT_FDCWD) && 0 /* utimensat() is not universally available */
25122531
/* Recent unix */
25132532
struct timespec times[2];
25142533
times[0].tv_nsec = times[1].tv_nsec = 0;
25152534
times[0].tv_sec = time(0);
@@ -4263,10 +4282,104 @@
42634282
memtraceOut = 0;
42644283
return rc;
42654284
}
42664285
42674286
/************************* End ../ext/misc/memtrace.c ********************/
4287
+/************************* Begin ../ext/misc/uint.c ******************/
4288
+/*
4289
+** 2020-04-14
4290
+**
4291
+** The author disclaims copyright to this source code. In place of
4292
+** a legal notice, here is a blessing:
4293
+**
4294
+** May you do good and not evil.
4295
+** May you find forgiveness for yourself and forgive others.
4296
+** May you share freely, never taking more than you give.
4297
+**
4298
+******************************************************************************
4299
+**
4300
+** This SQLite extension implements the UINT collating sequence.
4301
+**
4302
+** UINT works like BINARY for text, except that embedded strings
4303
+** of digits compare in numeric order.
4304
+**
4305
+** * Leading zeros are handled properly, in the sense that
4306
+** they do not mess of the maginitude comparison of embedded
4307
+** strings of digits. "x00123y" is equal to "x123y".
4308
+**
4309
+** * Only unsigned integers are recognized. Plus and minus
4310
+** signs are ignored. Decimal points and exponential notation
4311
+** are ignored.
4312
+**
4313
+** * Embedded integers can be of arbitrary length. Comparison
4314
+** is *not* limited integers that can be expressed as a
4315
+** 64-bit machine integer.
4316
+*/
4317
+/* #include "sqlite3ext.h" */
4318
+SQLITE_EXTENSION_INIT1
4319
+#include <assert.h>
4320
+#include <string.h>
4321
+#include <ctype.h>
4322
+
4323
+/*
4324
+** Compare text in lexicographic order, except strings of digits
4325
+** compare in numeric order.
4326
+*/
4327
+static int uintCollFunc(
4328
+ void *notUsed,
4329
+ int nKey1, const void *pKey1,
4330
+ int nKey2, const void *pKey2
4331
+){
4332
+ const unsigned char *zA = (const unsigned char*)pKey1;
4333
+ const unsigned char *zB = (const unsigned char*)pKey2;
4334
+ int i=0, j=0, x;
4335
+ while( i<nKey1 && j<nKey2 ){
4336
+ x = zA[i] - zB[j];
4337
+ if( isdigit(zA[i]) ){
4338
+ int k;
4339
+ if( !isdigit(zB[j]) ) return x;
4340
+ while( i<nKey1 && zA[i]=='0' ){ i++; }
4341
+ while( j<nKey2 && zB[j]=='0' ){ j++; }
4342
+ k = 0;
4343
+ while( i+k<nKey1 && isdigit(zA[i+k])
4344
+ && j+k<nKey2 && isdigit(zB[j+k]) ){
4345
+ k++;
4346
+ }
4347
+ if( i+k<nKey1 && isdigit(zA[i+k]) ){
4348
+ return +1;
4349
+ }else if( j+k<nKey2 && isdigit(zB[j+k]) ){
4350
+ return -1;
4351
+ }else{
4352
+ x = memcmp(zA+i, zB+j, k);
4353
+ if( x ) return x;
4354
+ i += k;
4355
+ j += k;
4356
+ }
4357
+ }else if( x ){
4358
+ return x;
4359
+ }else{
4360
+ i++;
4361
+ j++;
4362
+ }
4363
+ }
4364
+ return (nKey1 - i) - (nKey2 - j);
4365
+}
4366
+
4367
+#ifdef _WIN32
4368
+
4369
+#endif
4370
+int sqlite3_uint_init(
4371
+ sqlite3 *db,
4372
+ char **pzErrMsg,
4373
+ const sqlite3_api_routines *pApi
4374
+){
4375
+ SQLITE_EXTENSION_INIT2(pApi);
4376
+ (void)pzErrMsg; /* Unused parameter */
4377
+ return sqlite3_create_collation(db, "uint", SQLITE_UTF8, 0, uintCollFunc);
4378
+}
4379
+
4380
+/************************* End ../ext/misc/uint.c ********************/
42684381
#ifdef SQLITE_HAVE_ZLIB
42694382
/************************* Begin ../ext/misc/zipfile.c ******************/
42704383
/*
42714384
** 2017-12-26
42724385
**
@@ -9652,10 +9765,11 @@
96529765
int nCheck; /* Number of ".check" commands run */
96539766
unsigned nProgress; /* Number of progress callbacks encountered */
96549767
unsigned mxProgress; /* Maximum progress callbacks before failing */
96559768
unsigned flgProgress; /* Flags for the progress callback */
96569769
unsigned shellFlgs; /* Various flags */
9770
+ unsigned priorShFlgs; /* Saved copy of flags */
96579771
sqlite3_int64 szMax; /* --maxsize argument to .open */
96589772
char *zDestTable; /* Name of destination table when MODE_Insert */
96599773
char *zTempFile; /* Temporary file that might need deleting */
96609774
char zTestcase[30]; /* Name of current test case */
96619775
char colSeparator[20]; /* Column separator character for several modes */
@@ -9952,15 +10066,17 @@
995210066
/*
995310067
** Save or restore the current output mode
995410068
*/
995510069
static void outputModePush(ShellState *p){
995610070
p->modePrior = p->mode;
10071
+ p->priorShFlgs = p->shellFlgs;
995710072
memcpy(p->colSepPrior, p->colSeparator, sizeof(p->colSeparator));
995810073
memcpy(p->rowSepPrior, p->rowSeparator, sizeof(p->rowSeparator));
995910074
}
996010075
static void outputModePop(ShellState *p){
996110076
p->mode = p->modePrior;
10077
+ p->shellFlgs = p->priorShFlgs;
996210078
memcpy(p->colSeparator, p->colSepPrior, sizeof(p->colSeparator));
996310079
memcpy(p->rowSeparator, p->rowSepPrior, sizeof(p->rowSeparator));
996410080
}
996510081
996610082
/*
@@ -10921,12 +11037,11 @@
1092111037
** "--" comment occurs at the end of the statement, the comment
1092211038
** won't consume the semicolon terminator.
1092311039
*/
1092411040
static int run_table_dump_query(
1092511041
ShellState *p, /* Query context */
10926
- const char *zSelect, /* SELECT statement to extract content */
10927
- const char *zFirstRow /* Print before first row, if not NULL */
11042
+ const char *zSelect /* SELECT statement to extract content */
1092811043
){
1092911044
sqlite3_stmt *pSelect;
1093011045
int rc;
1093111046
int nResult;
1093211047
int i;
@@ -10939,14 +11054,10 @@
1093911054
return rc;
1094011055
}
1094111056
rc = sqlite3_step(pSelect);
1094211057
nResult = sqlite3_column_count(pSelect);
1094311058
while( rc==SQLITE_ROW ){
10944
- if( zFirstRow ){
10945
- utf8_printf(p->out, "%s", zFirstRow);
10946
- zFirstRow = 0;
10947
- }
1094811059
z = (const char*)sqlite3_column_text(pSelect, 0);
1094911060
utf8_printf(p->out, "%s", z);
1095011061
for(i=1; i<nResult; i++){
1095111062
utf8_printf(p->out, ",%s", sqlite3_column_text(pSelect, i));
1095211063
}
@@ -11399,13 +11510,13 @@
1139911510
** Parameter bindings are taken from a TEMP table of the form:
1140011511
**
1140111512
** CREATE TEMP TABLE sqlite_parameters(key TEXT PRIMARY KEY, value)
1140211513
** WITHOUT ROWID;
1140311514
**
11404
-** No bindings occur if this table does not exist. The special character '$'
11405
-** is included in the table name to help prevent collisions with actual tables.
11406
-** The table must be in the TEMP schema.
11515
+** No bindings occur if this table does not exist. The name of the table
11516
+** begins with "sqlite_" so that it will not collide with ordinary application
11517
+** tables. The table must be in the TEMP schema.
1140711518
*/
1140811519
static void bind_prepared_stmt(ShellState *pArg, sqlite3_stmt *pStmt){
1140911520
int nVar;
1141011521
int i;
1141111522
int rc;
@@ -12115,24 +12226,26 @@
1211512226
".check GLOB Fail if output since .testcase does not match",
1211612227
".clone NEWDB Clone data into NEWDB from the existing database",
1211712228
".databases List names and files of attached databases",
1211812229
".dbconfig ?op? ?val? List or change sqlite3_db_config() options",
1211912230
".dbinfo ?DB? Show status information about the database",
12120
- ".dump ?TABLE? ... Render all database content as SQL",
12231
+ ".dump ?TABLE? Render database content as SQL",
1212112232
" Options:",
1212212233
" --preserve-rowids Include ROWID values in the output",
1212312234
" --newlines Allow unescaped newline characters in output",
1212412235
" TABLE is a LIKE pattern for the tables to dump",
12236
+ " Additional LIKE patterns can be given in subsequent arguments",
1212512237
".echo on|off Turn command echo on or off",
1212612238
".eqp on|off|full|... Enable or disable automatic EXPLAIN QUERY PLAN",
1212712239
" Other Modes:",
1212812240
#ifdef SQLITE_DEBUG
1212912241
" test Show raw EXPLAIN QUERY PLAN output",
1213012242
" trace Like \"full\" but enable \"PRAGMA vdbe_trace\"",
1213112243
#endif
1213212244
" trigger Like \"full\" but also show trigger bytecode",
1213312245
".excel Display the output of next command in spreadsheet",
12246
+ " --bom Put a UTF8 byte-order mark on intermediate file",
1213412247
".exit ?CODE? Exit this program with return-code CODE",
1213512248
".expert EXPERIMENTAL. Suggest indexes for queries",
1213612249
".explain ?on|off|auto? Change the EXPLAIN formatting mode. Default: auto",
1213712250
".filectrl CMD ... Run various sqlite3_file_control() operations",
1213812251
" Run \".filectrl\" with no arguments for details",
@@ -12180,15 +12293,15 @@
1218012293
" list Values delimited by \"|\"",
1218112294
" quote Escape answers as for SQL",
1218212295
" tabs Tab-separated values",
1218312296
" tcl TCL list elements",
1218412297
".nullvalue STRING Use STRING in place of NULL values",
12185
- ".once (-e|-x|FILE) Output for the next SQL command only to FILE",
12298
+ ".once ?OPTIONS? ?FILE? Output for the next SQL command only to FILE",
1218612299
" If FILE begins with '|' then open as a pipe",
12187
- " Other options:",
12188
- " -e Invoke system text editor",
12189
- " -x Open in a spreadsheet",
12300
+ " --bom Put a UTF8 byte-order mark at the beginning",
12301
+ " -e Send output to the system text editor",
12302
+ " -x Send output as CSV to a spreadsheet (same as \".excel\")",
1219012303
#ifdef SQLITE_DEBUG
1219112304
".oom [--repeat M] [N] Simulate an OOM error on the N-th allocation",
1219212305
#endif
1219312306
".open ?OPTIONS? ?FILE? Close existing database and reopen FILE",
1219412307
" Options:",
@@ -12201,11 +12314,15 @@
1220112314
" --new Initialize FILE to an empty database",
1220212315
" --nofollow Do not follow symbolic links",
1220312316
" --readonly Open FILE readonly",
1220412317
" --zip FILE is a ZIP archive",
1220512318
".output ?FILE? Send output to FILE or stdout if FILE is omitted",
12206
- " If FILE begins with '|' then open it as a pipe.",
12319
+ " If FILE begins with '|' then open it as a pipe.",
12320
+ " Options:",
12321
+ " --bom Prefix output with a UTF8 byte-order mark",
12322
+ " -e Send output to the system text editor",
12323
+ " -x Send output as CSV to a spreadsheet",
1220712324
".parameter CMD ... Manage SQL parameter bindings",
1220812325
" clear Erase all bindings",
1220912326
" init Initialize the TEMP table that holds bindings",
1221012327
" list List the current parameter bindings",
1221112328
" set PARAMETER VALUE Given SQL parameter PARAMETER a value of VALUE",
@@ -12321,10 +12438,11 @@
1232112438
char *zPat;
1232212439
if( zPattern==0
1232312440
|| zPattern[0]=='0'
1232412441
|| strcmp(zPattern,"-a")==0
1232512442
|| strcmp(zPattern,"-all")==0
12443
+ || strcmp(zPattern,"--all")==0
1232612444
){
1232712445
/* Show all commands, but only one line per command */
1232812446
if( zPattern==0 ) zPattern = "";
1232912447
for(i=0; i<ArraySize(azHelp); i++){
1233012448
if( azHelp[i][0]=='.' || zPattern[0] ){
@@ -12802,10 +12920,11 @@
1280212920
sqlite3_enable_load_extension(p->db, 1);
1280312921
#endif
1280412922
sqlite3_fileio_init(p->db, 0, 0);
1280512923
sqlite3_shathree_init(p->db, 0, 0);
1280612924
sqlite3_completion_init(p->db, 0, 0);
12925
+ sqlite3_uint_init(p->db, 0, 0);
1280712926
#if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_ENABLE_DBPAGE_VTAB)
1280812927
sqlite3_dbdata_init(p->db, 0, 0);
1280912928
#endif
1281012929
#ifdef SQLITE_HAVE_ZLIB
1281112930
sqlite3_zipfile_init(p->db, 0, 0);
@@ -13521,15 +13640,19 @@
1352113640
#endif
1352213641
char *zCmd;
1352313642
zCmd = sqlite3_mprintf("%s %s", zXdgOpenCmd, p->zTempFile);
1352413643
if( system(zCmd) ){
1352513644
utf8_printf(stderr, "Failed: [%s]\n", zCmd);
13645
+ }else{
13646
+ /* Give the start/open/xdg-open command some time to get
13647
+ ** going before we continue, and potential delete the
13648
+ ** p->zTempFile data file out from under it */
13649
+ sqlite3_sleep(2000);
1352613650
}
1352713651
sqlite3_free(zCmd);
1352813652
outputModePop(p);
1352913653
p->doXdgOpen = 0;
13530
- sqlite3_sleep(100);
1353113654
}
1353213655
#endif /* !defined(SQLITE_NOHAVE_SYSTEM) */
1353313656
}
1353413657
p->outfile[0] = 0;
1353513658
p->out = stdout;
@@ -13815,13 +13938,25 @@
1381513938
p->zTempFile = 0;
1381613939
if( p->db ){
1381713940
sqlite3_file_control(p->db, 0, SQLITE_FCNTL_TEMPFILENAME, &p->zTempFile);
1381813941
}
1381913942
if( p->zTempFile==0 ){
13943
+ /* If p->db is an in-memory database then the TEMPFILENAME file-control
13944
+ ** will not work and we will need to fallback to guessing */
13945
+ char *zTemp;
1382013946
sqlite3_uint64 r;
1382113947
sqlite3_randomness(sizeof(r), &r);
13822
- p->zTempFile = sqlite3_mprintf("temp%llx.%s", r, zSuffix);
13948
+ zTemp = getenv("TEMP");
13949
+ if( zTemp==0 ) zTemp = getenv("TMP");
13950
+ if( zTemp==0 ){
13951
+#ifdef _WIN32
13952
+ zTemp = "\\tmp";
13953
+#else
13954
+ zTemp = "/tmp";
13955
+#endif
13956
+ }
13957
+ p->zTempFile = sqlite3_mprintf("%s/temp%llx.%s", zTemp, r, zSuffix);
1382313958
}else{
1382413959
p->zTempFile = sqlite3_mprintf("%z.%s", p->zTempFile, zSuffix);
1382513960
}
1382613961
if( p->zTempFile==0 ){
1382713962
raw_printf(stderr, "out of memory\n");
@@ -15841,11 +15976,12 @@
1584115976
rc = recoverDatabaseCmd(p, nArg, azArg);
1584215977
}else
1584315978
#endif /* !(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_ENABLE_DBPAGE_VTAB) */
1584415979
1584515980
if( c=='d' && strncmp(azArg[0], "dump", n)==0 ){
15846
- const char *zLike = 0;
15981
+ char *zLike = 0;
15982
+ char *zSql;
1584715983
int i;
1584815984
int savedShowHeader = p->showHeader;
1584915985
int savedShellFlags = p->shellFlgs;
1585015986
ShellClearFlag(p, SHFLG_PreserveRowid|SHFLG_Newlines|SHFLG_Echo);
1585115987
for(i=1; i<nArg; i++){
@@ -15869,16 +16005,14 @@
1586916005
raw_printf(stderr, "Unknown option \"%s\" on \".dump\"\n", azArg[i]);
1587016006
rc = 1;
1587116007
goto meta_command_exit;
1587216008
}
1587316009
}else if( zLike ){
15874
- raw_printf(stderr, "Usage: .dump ?--preserve-rowids? "
15875
- "?--newlines? ?LIKE-PATTERN?\n");
15876
- rc = 1;
15877
- goto meta_command_exit;
16010
+ zLike = sqlite3_mprintf("%z OR name LIKE %Q ESCAPE '\\'",
16011
+ zLike, azArg[i]);
1587816012
}else{
15879
- zLike = azArg[i];
16013
+ zLike = sqlite3_mprintf("name LIKE %Q ESCAPE '\\'", azArg[i]);
1588016014
}
1588116015
}
1588216016
1588316017
open_db(p, 0);
1588416018
@@ -15892,39 +16026,29 @@
1589216026
/* Set writable_schema=ON since doing so forces SQLite to initialize
1589316027
** as much of the schema as it can even if the sqlite_master table is
1589416028
** corrupt. */
1589516029
sqlite3_exec(p->db, "SAVEPOINT dump; PRAGMA writable_schema=ON", 0, 0, 0);
1589616030
p->nErr = 0;
15897
- if( zLike==0 ){
15898
- run_schema_dump_query(p,
15899
- "SELECT name, type, sql FROM sqlite_master "
15900
- "WHERE sql NOT NULL AND type=='table' AND name!='sqlite_sequence'"
15901
- );
15902
- run_schema_dump_query(p,
15903
- "SELECT name, type, sql FROM sqlite_master "
15904
- "WHERE name=='sqlite_sequence'"
15905
- );
15906
- run_table_dump_query(p,
15907
- "SELECT sql FROM sqlite_master "
15908
- "WHERE sql NOT NULL AND type IN ('index','trigger','view')", 0
15909
- );
15910
- }else{
15911
- char *zSql;
15912
- zSql = sqlite3_mprintf(
15913
- "SELECT name, type, sql FROM sqlite_master "
15914
- "WHERE tbl_name LIKE %Q AND type=='table'"
15915
- " AND sql NOT NULL", zLike);
15916
- run_schema_dump_query(p,zSql);
15917
- sqlite3_free(zSql);
15918
- zSql = sqlite3_mprintf(
15919
- "SELECT sql FROM sqlite_master "
15920
- "WHERE sql NOT NULL"
15921
- " AND type IN ('index','trigger','view')"
15922
- " AND tbl_name LIKE %Q", zLike);
15923
- run_table_dump_query(p, zSql, 0);
15924
- sqlite3_free(zSql);
15925
- }
16031
+ if( zLike==0 ) zLike = sqlite3_mprintf("true");
16032
+ zSql = sqlite3_mprintf(
16033
+ "SELECT name, type, sql FROM sqlite_master "
16034
+ "WHERE (%s) AND type=='table'"
16035
+ " AND sql NOT NULL"
16036
+ " ORDER BY tbl_name='sqlite_sequence', rowid",
16037
+ zLike
16038
+ );
16039
+ run_schema_dump_query(p,zSql);
16040
+ sqlite3_free(zSql);
16041
+ zSql = sqlite3_mprintf(
16042
+ "SELECT sql FROM sqlite_master "
16043
+ "WHERE (%s) AND sql NOT NULL"
16044
+ " AND type IN ('index','trigger','view')",
16045
+ zLike
16046
+ );
16047
+ run_table_dump_query(p, zSql);
16048
+ sqlite3_free(zSql);
16049
+ sqlite3_free(zLike);
1592616050
if( p->writableSchema ){
1592716051
raw_printf(p->out, "PRAGMA writable_schema=OFF;\n");
1592816052
p->writableSchema = 0;
1592916053
}
1593016054
sqlite3_exec(p->db, "PRAGMA writable_schema=OFF;", 0, 0, 0);
@@ -16850,46 +16974,70 @@
1685016974
1685116975
if( (c=='o'
1685216976
&& (strncmp(azArg[0], "output", n)==0||strncmp(azArg[0], "once", n)==0))
1685316977
|| (c=='e' && n==5 && strcmp(azArg[0],"excel")==0)
1685416978
){
16855
- const char *zFile = nArg>=2 ? azArg[1] : "stdout";
16979
+ const char *zFile = 0;
1685616980
int bTxtMode = 0;
16857
- if( azArg[0][0]=='e' ){
16858
- /* Transform the ".excel" command into ".once -x" */
16859
- nArg = 2;
16860
- azArg[0] = "once";
16861
- zFile = azArg[1] = "-x";
16862
- n = 4;
16863
- }
16864
- if( nArg>2 ){
16865
- utf8_printf(stderr, "Usage: .%s [-e|-x|FILE]\n", azArg[0]);
16866
- rc = 1;
16867
- goto meta_command_exit;
16868
- }
16869
- if( n>1 && strncmp(azArg[0], "once", n)==0 ){
16870
- if( nArg<2 ){
16871
- raw_printf(stderr, "Usage: .once (-e|-x|FILE)\n");
16981
+ int i;
16982
+ int eMode = 0;
16983
+ int bBOM = 0;
16984
+ int bOnce;
16985
+
16986
+ if( c=='e' ){
16987
+ eMode = 'x';
16988
+ bOnce = 2;
16989
+ }else if( strncmp(azArg[0],"once",n)==0 ){
16990
+ bOnce = 1;
16991
+ }
16992
+ for(i=1; i<nArg; i++){
16993
+ char *z = azArg[i];
16994
+ if( z[0]=='-' ){
16995
+ if( z[1]=='-' ) z++;
16996
+ if( strcmp(z,"-bom")==0 ){
16997
+ bBOM = 1;
16998
+ }else if( c!='e' && strcmp(z,"-x")==0 ){
16999
+ eMode = 'x'; /* spreadsheet */
17000
+ }else if( c!='e' && strcmp(z,"-e")==0 ){
17001
+ eMode = 'e'; /* text editor */
17002
+ }else{
17003
+ utf8_printf(p->out, "ERROR: unknown option: \"%s\". Usage:\n",
17004
+ azArg[i]);
17005
+ showHelp(p->out, azArg[0]);
17006
+ rc = 1;
17007
+ goto meta_command_exit;
17008
+ }
17009
+ }else if( zFile==0 ){
17010
+ zFile = z;
17011
+ }else{
17012
+ utf8_printf(p->out,"ERROR: extra parameter: \"%s\". Usage:\n",
17013
+ azArg[i]);
17014
+ showHelp(p->out, azArg[0]);
1687217015
rc = 1;
1687317016
goto meta_command_exit;
1687417017
}
17018
+ }
17019
+ if( zFile==0 ) zFile = "stdout";
17020
+ if( bOnce ){
1687517021
p->outCount = 2;
1687617022
}else{
1687717023
p->outCount = 0;
1687817024
}
1687917025
output_reset(p);
16880
- if( zFile[0]=='-' && zFile[1]=='-' ) zFile++;
1688117026
#ifndef SQLITE_NOHAVE_SYSTEM
16882
- if( strcmp(zFile, "-e")==0 || strcmp(zFile, "-x")==0 ){
17027
+ if( eMode=='e' || eMode=='x' ){
1688317028
p->doXdgOpen = 1;
1688417029
outputModePush(p);
16885
- if( zFile[1]=='x' ){
17030
+ if( eMode=='x' ){
17031
+ /* spreadsheet mode. Output as CSV. */
1688617032
newTempFile(p, "csv");
17033
+ ShellClearFlag(p, SHFLG_Echo);
1688717034
p->mode = MODE_Csv;
1688817035
sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Comma);
1688917036
sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_CrLf);
1689017037
}else{
17038
+ /* text editor mode */
1689117039
newTempFile(p, "txt");
1689217040
bTxtMode = 1;
1689317041
}
1689417042
zFile = p->zTempFile;
1689517043
}
@@ -16904,10 +17052,11 @@
1690417052
if( p->out==0 ){
1690517053
utf8_printf(stderr,"Error: cannot open pipe \"%s\"\n", zFile + 1);
1690617054
p->out = stdout;
1690717055
rc = 1;
1690817056
}else{
17057
+ if( bBOM ) fprintf(p->out,"\357\273\277");
1690917058
sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile);
1691017059
}
1691117060
#endif
1691217061
}else{
1691317062
p->out = output_file_open(zFile, bTxtMode);
@@ -16916,10 +17065,11 @@
1691617065
utf8_printf(stderr,"Error: cannot write to \"%s\"\n", zFile);
1691717066
}
1691817067
p->out = stdout;
1691917068
rc = 1;
1692017069
} else {
17070
+ if( bBOM ) fprintf(p->out,"\357\273\277");
1692117071
sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile);
1692217072
}
1692317073
}
1692417074
}else
1692517075
@@ -18804,18 +18954,22 @@
1880418954
/*
1880518955
** Output text to the console in a font that attracts extra attention.
1880618956
*/
1880718957
#ifdef _WIN32
1880818958
static void printBold(const char *zText){
18959
+#if !SQLITE_OS_WINRT
1880918960
HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);
1881018961
CONSOLE_SCREEN_BUFFER_INFO defaultScreenInfo;
1881118962
GetConsoleScreenBufferInfo(out, &defaultScreenInfo);
1881218963
SetConsoleTextAttribute(out,
1881318964
FOREGROUND_RED|FOREGROUND_INTENSITY
1881418965
);
18966
+#endif
1881518967
printf("%s", zText);
18968
+#if !SQLITE_OS_WINRT
1881618969
SetConsoleTextAttribute(out, defaultScreenInfo.wAttributes);
18970
+#endif
1881718971
}
1881818972
#else
1881918973
static void printBold(const char *zText){
1882018974
printf("\033[1m%s\033[0m", zText);
1882118975
}
@@ -18879,11 +19033,15 @@
1887919033
"attach debugger to process %d and press any key to continue.\n",
1888019034
GETPID());
1888119035
fgetc(stdin);
1888219036
}else{
1888319037
#if defined(_WIN32) || defined(WIN32)
19038
+#if SQLITE_OS_WINRT
19039
+ __debugbreak();
19040
+#else
1888419041
DebugBreak();
19042
+#endif
1888519043
#elif defined(SIGTRAP)
1888619044
raise(SIGTRAP);
1888719045
#endif
1888819046
}
1888919047
}
1889019048
--- src/shell.c
+++ src/shell.c
@@ -33,10 +33,18 @@
33 #if (defined(_WIN32) || defined(WIN32)) && !defined(_CRT_SECURE_NO_WARNINGS)
34 /* This needs to come before any includes for MSVC compiler */
35 #define _CRT_SECURE_NO_WARNINGS
36 #endif
37
 
 
 
 
 
 
 
 
38 /*
39 ** Warning pragmas copied from msvc.h in the core.
40 */
41 #if defined(_MSC_VER)
42 #pragma warning(disable : 4054)
@@ -145,26 +153,30 @@
145 # define SHELL_USE_LOCAL_GETLINE 1
146 #endif
147
148
149 #if defined(_WIN32) || defined(WIN32)
150 # include <io.h>
151 # include <fcntl.h>
152 # define isatty(h) _isatty(h)
153 # ifndef access
154 # define access(f,m) _access((f),(m))
155 # endif
156 # ifndef unlink
157 # define unlink _unlink
158 # endif
159 # ifndef strdup
160 # define strdup _strdup
161 # endif
162 # undef popen
163 # define popen _popen
164 # undef pclose
165 # define pclose _pclose
 
 
 
 
166 #else
167 /* Make sure isatty() has a prototype. */
168 extern int isatty(int);
169
170 # if !defined(__RTP__) && !defined(_WRS_KERNEL)
@@ -189,10 +201,13 @@
189 #define IsSpace(X) isspace((unsigned char)X)
190 #define IsDigit(X) isdigit((unsigned char)X)
191 #define ToLower(X) (char)tolower((unsigned char)X)
192
193 #if defined(_WIN32) || defined(WIN32)
 
 
 
194 #include <windows.h>
195
196 /* string conversion routines only needed on Win32 */
197 extern char *sqlite3_win32_unicode_to_utf8(LPCWSTR);
198 extern char *sqlite3_win32_mbcs_to_utf8_v2(const char *, int);
@@ -204,11 +219,11 @@
204 ** are automatically translated into \r\n. However, this behavior needs
205 ** to be disabled in some cases (ex: when generating CSV output and when
206 ** rendering quoted strings that contain \n characters). The following
207 ** routines take care of that.
208 */
209 #if defined(_WIN32) || defined(WIN32)
210 static void setBinaryMode(FILE *file, int isOutput){
211 if( isOutput ) fflush(file);
212 _setmode(_fileno(file), _O_BINARY);
213 }
214 static void setTextMode(FILE *file, int isOutput){
@@ -308,10 +323,11 @@
308 */
309 static int hasTimer(void){
310 if( getProcessTimesAddr ){
311 return 1;
312 } else {
 
313 /* GetProcessTimes() isn't supported in WIN95 and some other Windows
314 ** versions. See if the version we are running on has it, and if it
315 ** does, save off a pointer to it and the current process handle.
316 */
317 hProcess = GetCurrentProcess();
@@ -324,10 +340,11 @@
324 return 1;
325 }
326 FreeLibrary(hinstLib);
327 }
328 }
 
329 }
330 return 0;
331 }
332
333 /*
@@ -2476,10 +2493,11 @@
2476 }
2477 }
2478
2479 if( mtime>=0 ){
2480 #if defined(_WIN32)
 
2481 /* Windows */
2482 FILETIME lastAccess;
2483 FILETIME lastWrite;
2484 SYSTEMTIME currentTime;
2485 LONGLONG intervals;
@@ -2506,10 +2524,11 @@
2506 CloseHandle(hFile);
2507 return !bResult;
2508 }else{
2509 return 1;
2510 }
 
2511 #elif defined(AT_FDCWD) && 0 /* utimensat() is not universally available */
2512 /* Recent unix */
2513 struct timespec times[2];
2514 times[0].tv_nsec = times[1].tv_nsec = 0;
2515 times[0].tv_sec = time(0);
@@ -4263,10 +4282,104 @@
4263 memtraceOut = 0;
4264 return rc;
4265 }
4266
4267 /************************* End ../ext/misc/memtrace.c ********************/
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4268 #ifdef SQLITE_HAVE_ZLIB
4269 /************************* Begin ../ext/misc/zipfile.c ******************/
4270 /*
4271 ** 2017-12-26
4272 **
@@ -9652,10 +9765,11 @@
9652 int nCheck; /* Number of ".check" commands run */
9653 unsigned nProgress; /* Number of progress callbacks encountered */
9654 unsigned mxProgress; /* Maximum progress callbacks before failing */
9655 unsigned flgProgress; /* Flags for the progress callback */
9656 unsigned shellFlgs; /* Various flags */
 
9657 sqlite3_int64 szMax; /* --maxsize argument to .open */
9658 char *zDestTable; /* Name of destination table when MODE_Insert */
9659 char *zTempFile; /* Temporary file that might need deleting */
9660 char zTestcase[30]; /* Name of current test case */
9661 char colSeparator[20]; /* Column separator character for several modes */
@@ -9952,15 +10066,17 @@
9952 /*
9953 ** Save or restore the current output mode
9954 */
9955 static void outputModePush(ShellState *p){
9956 p->modePrior = p->mode;
 
9957 memcpy(p->colSepPrior, p->colSeparator, sizeof(p->colSeparator));
9958 memcpy(p->rowSepPrior, p->rowSeparator, sizeof(p->rowSeparator));
9959 }
9960 static void outputModePop(ShellState *p){
9961 p->mode = p->modePrior;
 
9962 memcpy(p->colSeparator, p->colSepPrior, sizeof(p->colSeparator));
9963 memcpy(p->rowSeparator, p->rowSepPrior, sizeof(p->rowSeparator));
9964 }
9965
9966 /*
@@ -10921,12 +11037,11 @@
10921 ** "--" comment occurs at the end of the statement, the comment
10922 ** won't consume the semicolon terminator.
10923 */
10924 static int run_table_dump_query(
10925 ShellState *p, /* Query context */
10926 const char *zSelect, /* SELECT statement to extract content */
10927 const char *zFirstRow /* Print before first row, if not NULL */
10928 ){
10929 sqlite3_stmt *pSelect;
10930 int rc;
10931 int nResult;
10932 int i;
@@ -10939,14 +11054,10 @@
10939 return rc;
10940 }
10941 rc = sqlite3_step(pSelect);
10942 nResult = sqlite3_column_count(pSelect);
10943 while( rc==SQLITE_ROW ){
10944 if( zFirstRow ){
10945 utf8_printf(p->out, "%s", zFirstRow);
10946 zFirstRow = 0;
10947 }
10948 z = (const char*)sqlite3_column_text(pSelect, 0);
10949 utf8_printf(p->out, "%s", z);
10950 for(i=1; i<nResult; i++){
10951 utf8_printf(p->out, ",%s", sqlite3_column_text(pSelect, i));
10952 }
@@ -11399,13 +11510,13 @@
11399 ** Parameter bindings are taken from a TEMP table of the form:
11400 **
11401 ** CREATE TEMP TABLE sqlite_parameters(key TEXT PRIMARY KEY, value)
11402 ** WITHOUT ROWID;
11403 **
11404 ** No bindings occur if this table does not exist. The special character '$'
11405 ** is included in the table name to help prevent collisions with actual tables.
11406 ** The table must be in the TEMP schema.
11407 */
11408 static void bind_prepared_stmt(ShellState *pArg, sqlite3_stmt *pStmt){
11409 int nVar;
11410 int i;
11411 int rc;
@@ -12115,24 +12226,26 @@
12115 ".check GLOB Fail if output since .testcase does not match",
12116 ".clone NEWDB Clone data into NEWDB from the existing database",
12117 ".databases List names and files of attached databases",
12118 ".dbconfig ?op? ?val? List or change sqlite3_db_config() options",
12119 ".dbinfo ?DB? Show status information about the database",
12120 ".dump ?TABLE? ... Render all database content as SQL",
12121 " Options:",
12122 " --preserve-rowids Include ROWID values in the output",
12123 " --newlines Allow unescaped newline characters in output",
12124 " TABLE is a LIKE pattern for the tables to dump",
 
12125 ".echo on|off Turn command echo on or off",
12126 ".eqp on|off|full|... Enable or disable automatic EXPLAIN QUERY PLAN",
12127 " Other Modes:",
12128 #ifdef SQLITE_DEBUG
12129 " test Show raw EXPLAIN QUERY PLAN output",
12130 " trace Like \"full\" but enable \"PRAGMA vdbe_trace\"",
12131 #endif
12132 " trigger Like \"full\" but also show trigger bytecode",
12133 ".excel Display the output of next command in spreadsheet",
 
12134 ".exit ?CODE? Exit this program with return-code CODE",
12135 ".expert EXPERIMENTAL. Suggest indexes for queries",
12136 ".explain ?on|off|auto? Change the EXPLAIN formatting mode. Default: auto",
12137 ".filectrl CMD ... Run various sqlite3_file_control() operations",
12138 " Run \".filectrl\" with no arguments for details",
@@ -12180,15 +12293,15 @@
12180 " list Values delimited by \"|\"",
12181 " quote Escape answers as for SQL",
12182 " tabs Tab-separated values",
12183 " tcl TCL list elements",
12184 ".nullvalue STRING Use STRING in place of NULL values",
12185 ".once (-e|-x|FILE) Output for the next SQL command only to FILE",
12186 " If FILE begins with '|' then open as a pipe",
12187 " Other options:",
12188 " -e Invoke system text editor",
12189 " -x Open in a spreadsheet",
12190 #ifdef SQLITE_DEBUG
12191 ".oom [--repeat M] [N] Simulate an OOM error on the N-th allocation",
12192 #endif
12193 ".open ?OPTIONS? ?FILE? Close existing database and reopen FILE",
12194 " Options:",
@@ -12201,11 +12314,15 @@
12201 " --new Initialize FILE to an empty database",
12202 " --nofollow Do not follow symbolic links",
12203 " --readonly Open FILE readonly",
12204 " --zip FILE is a ZIP archive",
12205 ".output ?FILE? Send output to FILE or stdout if FILE is omitted",
12206 " If FILE begins with '|' then open it as a pipe.",
 
 
 
 
12207 ".parameter CMD ... Manage SQL parameter bindings",
12208 " clear Erase all bindings",
12209 " init Initialize the TEMP table that holds bindings",
12210 " list List the current parameter bindings",
12211 " set PARAMETER VALUE Given SQL parameter PARAMETER a value of VALUE",
@@ -12321,10 +12438,11 @@
12321 char *zPat;
12322 if( zPattern==0
12323 || zPattern[0]=='0'
12324 || strcmp(zPattern,"-a")==0
12325 || strcmp(zPattern,"-all")==0
 
12326 ){
12327 /* Show all commands, but only one line per command */
12328 if( zPattern==0 ) zPattern = "";
12329 for(i=0; i<ArraySize(azHelp); i++){
12330 if( azHelp[i][0]=='.' || zPattern[0] ){
@@ -12802,10 +12920,11 @@
12802 sqlite3_enable_load_extension(p->db, 1);
12803 #endif
12804 sqlite3_fileio_init(p->db, 0, 0);
12805 sqlite3_shathree_init(p->db, 0, 0);
12806 sqlite3_completion_init(p->db, 0, 0);
 
12807 #if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_ENABLE_DBPAGE_VTAB)
12808 sqlite3_dbdata_init(p->db, 0, 0);
12809 #endif
12810 #ifdef SQLITE_HAVE_ZLIB
12811 sqlite3_zipfile_init(p->db, 0, 0);
@@ -13521,15 +13640,19 @@
13521 #endif
13522 char *zCmd;
13523 zCmd = sqlite3_mprintf("%s %s", zXdgOpenCmd, p->zTempFile);
13524 if( system(zCmd) ){
13525 utf8_printf(stderr, "Failed: [%s]\n", zCmd);
 
 
 
 
 
13526 }
13527 sqlite3_free(zCmd);
13528 outputModePop(p);
13529 p->doXdgOpen = 0;
13530 sqlite3_sleep(100);
13531 }
13532 #endif /* !defined(SQLITE_NOHAVE_SYSTEM) */
13533 }
13534 p->outfile[0] = 0;
13535 p->out = stdout;
@@ -13815,13 +13938,25 @@
13815 p->zTempFile = 0;
13816 if( p->db ){
13817 sqlite3_file_control(p->db, 0, SQLITE_FCNTL_TEMPFILENAME, &p->zTempFile);
13818 }
13819 if( p->zTempFile==0 ){
 
 
 
13820 sqlite3_uint64 r;
13821 sqlite3_randomness(sizeof(r), &r);
13822 p->zTempFile = sqlite3_mprintf("temp%llx.%s", r, zSuffix);
 
 
 
 
 
 
 
 
 
13823 }else{
13824 p->zTempFile = sqlite3_mprintf("%z.%s", p->zTempFile, zSuffix);
13825 }
13826 if( p->zTempFile==0 ){
13827 raw_printf(stderr, "out of memory\n");
@@ -15841,11 +15976,12 @@
15841 rc = recoverDatabaseCmd(p, nArg, azArg);
15842 }else
15843 #endif /* !(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_ENABLE_DBPAGE_VTAB) */
15844
15845 if( c=='d' && strncmp(azArg[0], "dump", n)==0 ){
15846 const char *zLike = 0;
 
15847 int i;
15848 int savedShowHeader = p->showHeader;
15849 int savedShellFlags = p->shellFlgs;
15850 ShellClearFlag(p, SHFLG_PreserveRowid|SHFLG_Newlines|SHFLG_Echo);
15851 for(i=1; i<nArg; i++){
@@ -15869,16 +16005,14 @@
15869 raw_printf(stderr, "Unknown option \"%s\" on \".dump\"\n", azArg[i]);
15870 rc = 1;
15871 goto meta_command_exit;
15872 }
15873 }else if( zLike ){
15874 raw_printf(stderr, "Usage: .dump ?--preserve-rowids? "
15875 "?--newlines? ?LIKE-PATTERN?\n");
15876 rc = 1;
15877 goto meta_command_exit;
15878 }else{
15879 zLike = azArg[i];
15880 }
15881 }
15882
15883 open_db(p, 0);
15884
@@ -15892,39 +16026,29 @@
15892 /* Set writable_schema=ON since doing so forces SQLite to initialize
15893 ** as much of the schema as it can even if the sqlite_master table is
15894 ** corrupt. */
15895 sqlite3_exec(p->db, "SAVEPOINT dump; PRAGMA writable_schema=ON", 0, 0, 0);
15896 p->nErr = 0;
15897 if( zLike==0 ){
15898 run_schema_dump_query(p,
15899 "SELECT name, type, sql FROM sqlite_master "
15900 "WHERE sql NOT NULL AND type=='table' AND name!='sqlite_sequence'"
15901 );
15902 run_schema_dump_query(p,
15903 "SELECT name, type, sql FROM sqlite_master "
15904 "WHERE name=='sqlite_sequence'"
15905 );
15906 run_table_dump_query(p,
15907 "SELECT sql FROM sqlite_master "
15908 "WHERE sql NOT NULL AND type IN ('index','trigger','view')", 0
15909 );
15910 }else{
15911 char *zSql;
15912 zSql = sqlite3_mprintf(
15913 "SELECT name, type, sql FROM sqlite_master "
15914 "WHERE tbl_name LIKE %Q AND type=='table'"
15915 " AND sql NOT NULL", zLike);
15916 run_schema_dump_query(p,zSql);
15917 sqlite3_free(zSql);
15918 zSql = sqlite3_mprintf(
15919 "SELECT sql FROM sqlite_master "
15920 "WHERE sql NOT NULL"
15921 " AND type IN ('index','trigger','view')"
15922 " AND tbl_name LIKE %Q", zLike);
15923 run_table_dump_query(p, zSql, 0);
15924 sqlite3_free(zSql);
15925 }
15926 if( p->writableSchema ){
15927 raw_printf(p->out, "PRAGMA writable_schema=OFF;\n");
15928 p->writableSchema = 0;
15929 }
15930 sqlite3_exec(p->db, "PRAGMA writable_schema=OFF;", 0, 0, 0);
@@ -16850,46 +16974,70 @@
16850
16851 if( (c=='o'
16852 && (strncmp(azArg[0], "output", n)==0||strncmp(azArg[0], "once", n)==0))
16853 || (c=='e' && n==5 && strcmp(azArg[0],"excel")==0)
16854 ){
16855 const char *zFile = nArg>=2 ? azArg[1] : "stdout";
16856 int bTxtMode = 0;
16857 if( azArg[0][0]=='e' ){
16858 /* Transform the ".excel" command into ".once -x" */
16859 nArg = 2;
16860 azArg[0] = "once";
16861 zFile = azArg[1] = "-x";
16862 n = 4;
16863 }
16864 if( nArg>2 ){
16865 utf8_printf(stderr, "Usage: .%s [-e|-x|FILE]\n", azArg[0]);
16866 rc = 1;
16867 goto meta_command_exit;
16868 }
16869 if( n>1 && strncmp(azArg[0], "once", n)==0 ){
16870 if( nArg<2 ){
16871 raw_printf(stderr, "Usage: .once (-e|-x|FILE)\n");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16872 rc = 1;
16873 goto meta_command_exit;
16874 }
 
 
 
16875 p->outCount = 2;
16876 }else{
16877 p->outCount = 0;
16878 }
16879 output_reset(p);
16880 if( zFile[0]=='-' && zFile[1]=='-' ) zFile++;
16881 #ifndef SQLITE_NOHAVE_SYSTEM
16882 if( strcmp(zFile, "-e")==0 || strcmp(zFile, "-x")==0 ){
16883 p->doXdgOpen = 1;
16884 outputModePush(p);
16885 if( zFile[1]=='x' ){
 
16886 newTempFile(p, "csv");
 
16887 p->mode = MODE_Csv;
16888 sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Comma);
16889 sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_CrLf);
16890 }else{
 
16891 newTempFile(p, "txt");
16892 bTxtMode = 1;
16893 }
16894 zFile = p->zTempFile;
16895 }
@@ -16904,10 +17052,11 @@
16904 if( p->out==0 ){
16905 utf8_printf(stderr,"Error: cannot open pipe \"%s\"\n", zFile + 1);
16906 p->out = stdout;
16907 rc = 1;
16908 }else{
 
16909 sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile);
16910 }
16911 #endif
16912 }else{
16913 p->out = output_file_open(zFile, bTxtMode);
@@ -16916,10 +17065,11 @@
16916 utf8_printf(stderr,"Error: cannot write to \"%s\"\n", zFile);
16917 }
16918 p->out = stdout;
16919 rc = 1;
16920 } else {
 
16921 sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile);
16922 }
16923 }
16924 }else
16925
@@ -18804,18 +18954,22 @@
18804 /*
18805 ** Output text to the console in a font that attracts extra attention.
18806 */
18807 #ifdef _WIN32
18808 static void printBold(const char *zText){
 
18809 HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);
18810 CONSOLE_SCREEN_BUFFER_INFO defaultScreenInfo;
18811 GetConsoleScreenBufferInfo(out, &defaultScreenInfo);
18812 SetConsoleTextAttribute(out,
18813 FOREGROUND_RED|FOREGROUND_INTENSITY
18814 );
 
18815 printf("%s", zText);
 
18816 SetConsoleTextAttribute(out, defaultScreenInfo.wAttributes);
 
18817 }
18818 #else
18819 static void printBold(const char *zText){
18820 printf("\033[1m%s\033[0m", zText);
18821 }
@@ -18879,11 +19033,15 @@
18879 "attach debugger to process %d and press any key to continue.\n",
18880 GETPID());
18881 fgetc(stdin);
18882 }else{
18883 #if defined(_WIN32) || defined(WIN32)
 
 
 
18884 DebugBreak();
 
18885 #elif defined(SIGTRAP)
18886 raise(SIGTRAP);
18887 #endif
18888 }
18889 }
18890
--- src/shell.c
+++ src/shell.c
@@ -33,10 +33,18 @@
33 #if (defined(_WIN32) || defined(WIN32)) && !defined(_CRT_SECURE_NO_WARNINGS)
34 /* This needs to come before any includes for MSVC compiler */
35 #define _CRT_SECURE_NO_WARNINGS
36 #endif
37
38 /*
39 ** Determine if we are dealing with WinRT, which provides only a subset of
40 ** the full Win32 API.
41 */
42 #if !defined(SQLITE_OS_WINRT)
43 # define SQLITE_OS_WINRT 0
44 #endif
45
46 /*
47 ** Warning pragmas copied from msvc.h in the core.
48 */
49 #if defined(_MSC_VER)
50 #pragma warning(disable : 4054)
@@ -145,26 +153,30 @@
153 # define SHELL_USE_LOCAL_GETLINE 1
154 #endif
155
156
157 #if defined(_WIN32) || defined(WIN32)
158 # if SQLITE_OS_WINRT
159 # define SQLITE_OMIT_POPEN 1
160 # else
161 # include <io.h>
162 # include <fcntl.h>
163 # define isatty(h) _isatty(h)
164 # ifndef access
165 # define access(f,m) _access((f),(m))
166 # endif
167 # ifndef unlink
168 # define unlink _unlink
169 # endif
170 # ifndef strdup
171 # define strdup _strdup
172 # endif
173 # undef popen
174 # define popen _popen
175 # undef pclose
176 # define pclose _pclose
177 # endif
178 #else
179 /* Make sure isatty() has a prototype. */
180 extern int isatty(int);
181
182 # if !defined(__RTP__) && !defined(_WRS_KERNEL)
@@ -189,10 +201,13 @@
201 #define IsSpace(X) isspace((unsigned char)X)
202 #define IsDigit(X) isdigit((unsigned char)X)
203 #define ToLower(X) (char)tolower((unsigned char)X)
204
205 #if defined(_WIN32) || defined(WIN32)
206 #if SQLITE_OS_WINRT
207 #include <intrin.h>
208 #endif
209 #include <windows.h>
210
211 /* string conversion routines only needed on Win32 */
212 extern char *sqlite3_win32_unicode_to_utf8(LPCWSTR);
213 extern char *sqlite3_win32_mbcs_to_utf8_v2(const char *, int);
@@ -204,11 +219,11 @@
219 ** are automatically translated into \r\n. However, this behavior needs
220 ** to be disabled in some cases (ex: when generating CSV output and when
221 ** rendering quoted strings that contain \n characters). The following
222 ** routines take care of that.
223 */
224 #if (defined(_WIN32) || defined(WIN32)) && !SQLITE_OS_WINRT
225 static void setBinaryMode(FILE *file, int isOutput){
226 if( isOutput ) fflush(file);
227 _setmode(_fileno(file), _O_BINARY);
228 }
229 static void setTextMode(FILE *file, int isOutput){
@@ -308,10 +323,11 @@
323 */
324 static int hasTimer(void){
325 if( getProcessTimesAddr ){
326 return 1;
327 } else {
328 #if !SQLITE_OS_WINRT
329 /* GetProcessTimes() isn't supported in WIN95 and some other Windows
330 ** versions. See if the version we are running on has it, and if it
331 ** does, save off a pointer to it and the current process handle.
332 */
333 hProcess = GetCurrentProcess();
@@ -324,10 +340,11 @@
340 return 1;
341 }
342 FreeLibrary(hinstLib);
343 }
344 }
345 #endif
346 }
347 return 0;
348 }
349
350 /*
@@ -2476,10 +2493,11 @@
2493 }
2494 }
2495
2496 if( mtime>=0 ){
2497 #if defined(_WIN32)
2498 #if !SQLITE_OS_WINRT
2499 /* Windows */
2500 FILETIME lastAccess;
2501 FILETIME lastWrite;
2502 SYSTEMTIME currentTime;
2503 LONGLONG intervals;
@@ -2506,10 +2524,11 @@
2524 CloseHandle(hFile);
2525 return !bResult;
2526 }else{
2527 return 1;
2528 }
2529 #endif
2530 #elif defined(AT_FDCWD) && 0 /* utimensat() is not universally available */
2531 /* Recent unix */
2532 struct timespec times[2];
2533 times[0].tv_nsec = times[1].tv_nsec = 0;
2534 times[0].tv_sec = time(0);
@@ -4263,10 +4282,104 @@
4282 memtraceOut = 0;
4283 return rc;
4284 }
4285
4286 /************************* End ../ext/misc/memtrace.c ********************/
4287 /************************* Begin ../ext/misc/uint.c ******************/
4288 /*
4289 ** 2020-04-14
4290 **
4291 ** The author disclaims copyright to this source code. In place of
4292 ** a legal notice, here is a blessing:
4293 **
4294 ** May you do good and not evil.
4295 ** May you find forgiveness for yourself and forgive others.
4296 ** May you share freely, never taking more than you give.
4297 **
4298 ******************************************************************************
4299 **
4300 ** This SQLite extension implements the UINT collating sequence.
4301 **
4302 ** UINT works like BINARY for text, except that embedded strings
4303 ** of digits compare in numeric order.
4304 **
4305 ** * Leading zeros are handled properly, in the sense that
4306 ** they do not mess of the maginitude comparison of embedded
4307 ** strings of digits. "x00123y" is equal to "x123y".
4308 **
4309 ** * Only unsigned integers are recognized. Plus and minus
4310 ** signs are ignored. Decimal points and exponential notation
4311 ** are ignored.
4312 **
4313 ** * Embedded integers can be of arbitrary length. Comparison
4314 ** is *not* limited integers that can be expressed as a
4315 ** 64-bit machine integer.
4316 */
4317 /* #include "sqlite3ext.h" */
4318 SQLITE_EXTENSION_INIT1
4319 #include <assert.h>
4320 #include <string.h>
4321 #include <ctype.h>
4322
4323 /*
4324 ** Compare text in lexicographic order, except strings of digits
4325 ** compare in numeric order.
4326 */
4327 static int uintCollFunc(
4328 void *notUsed,
4329 int nKey1, const void *pKey1,
4330 int nKey2, const void *pKey2
4331 ){
4332 const unsigned char *zA = (const unsigned char*)pKey1;
4333 const unsigned char *zB = (const unsigned char*)pKey2;
4334 int i=0, j=0, x;
4335 while( i<nKey1 && j<nKey2 ){
4336 x = zA[i] - zB[j];
4337 if( isdigit(zA[i]) ){
4338 int k;
4339 if( !isdigit(zB[j]) ) return x;
4340 while( i<nKey1 && zA[i]=='0' ){ i++; }
4341 while( j<nKey2 && zB[j]=='0' ){ j++; }
4342 k = 0;
4343 while( i+k<nKey1 && isdigit(zA[i+k])
4344 && j+k<nKey2 && isdigit(zB[j+k]) ){
4345 k++;
4346 }
4347 if( i+k<nKey1 && isdigit(zA[i+k]) ){
4348 return +1;
4349 }else if( j+k<nKey2 && isdigit(zB[j+k]) ){
4350 return -1;
4351 }else{
4352 x = memcmp(zA+i, zB+j, k);
4353 if( x ) return x;
4354 i += k;
4355 j += k;
4356 }
4357 }else if( x ){
4358 return x;
4359 }else{
4360 i++;
4361 j++;
4362 }
4363 }
4364 return (nKey1 - i) - (nKey2 - j);
4365 }
4366
4367 #ifdef _WIN32
4368
4369 #endif
4370 int sqlite3_uint_init(
4371 sqlite3 *db,
4372 char **pzErrMsg,
4373 const sqlite3_api_routines *pApi
4374 ){
4375 SQLITE_EXTENSION_INIT2(pApi);
4376 (void)pzErrMsg; /* Unused parameter */
4377 return sqlite3_create_collation(db, "uint", SQLITE_UTF8, 0, uintCollFunc);
4378 }
4379
4380 /************************* End ../ext/misc/uint.c ********************/
4381 #ifdef SQLITE_HAVE_ZLIB
4382 /************************* Begin ../ext/misc/zipfile.c ******************/
4383 /*
4384 ** 2017-12-26
4385 **
@@ -9652,10 +9765,11 @@
9765 int nCheck; /* Number of ".check" commands run */
9766 unsigned nProgress; /* Number of progress callbacks encountered */
9767 unsigned mxProgress; /* Maximum progress callbacks before failing */
9768 unsigned flgProgress; /* Flags for the progress callback */
9769 unsigned shellFlgs; /* Various flags */
9770 unsigned priorShFlgs; /* Saved copy of flags */
9771 sqlite3_int64 szMax; /* --maxsize argument to .open */
9772 char *zDestTable; /* Name of destination table when MODE_Insert */
9773 char *zTempFile; /* Temporary file that might need deleting */
9774 char zTestcase[30]; /* Name of current test case */
9775 char colSeparator[20]; /* Column separator character for several modes */
@@ -9952,15 +10066,17 @@
10066 /*
10067 ** Save or restore the current output mode
10068 */
10069 static void outputModePush(ShellState *p){
10070 p->modePrior = p->mode;
10071 p->priorShFlgs = p->shellFlgs;
10072 memcpy(p->colSepPrior, p->colSeparator, sizeof(p->colSeparator));
10073 memcpy(p->rowSepPrior, p->rowSeparator, sizeof(p->rowSeparator));
10074 }
10075 static void outputModePop(ShellState *p){
10076 p->mode = p->modePrior;
10077 p->shellFlgs = p->priorShFlgs;
10078 memcpy(p->colSeparator, p->colSepPrior, sizeof(p->colSeparator));
10079 memcpy(p->rowSeparator, p->rowSepPrior, sizeof(p->rowSeparator));
10080 }
10081
10082 /*
@@ -10921,12 +11037,11 @@
11037 ** "--" comment occurs at the end of the statement, the comment
11038 ** won't consume the semicolon terminator.
11039 */
11040 static int run_table_dump_query(
11041 ShellState *p, /* Query context */
11042 const char *zSelect /* SELECT statement to extract content */
 
11043 ){
11044 sqlite3_stmt *pSelect;
11045 int rc;
11046 int nResult;
11047 int i;
@@ -10939,14 +11054,10 @@
11054 return rc;
11055 }
11056 rc = sqlite3_step(pSelect);
11057 nResult = sqlite3_column_count(pSelect);
11058 while( rc==SQLITE_ROW ){
 
 
 
 
11059 z = (const char*)sqlite3_column_text(pSelect, 0);
11060 utf8_printf(p->out, "%s", z);
11061 for(i=1; i<nResult; i++){
11062 utf8_printf(p->out, ",%s", sqlite3_column_text(pSelect, i));
11063 }
@@ -11399,13 +11510,13 @@
11510 ** Parameter bindings are taken from a TEMP table of the form:
11511 **
11512 ** CREATE TEMP TABLE sqlite_parameters(key TEXT PRIMARY KEY, value)
11513 ** WITHOUT ROWID;
11514 **
11515 ** No bindings occur if this table does not exist. The name of the table
11516 ** begins with "sqlite_" so that it will not collide with ordinary application
11517 ** tables. The table must be in the TEMP schema.
11518 */
11519 static void bind_prepared_stmt(ShellState *pArg, sqlite3_stmt *pStmt){
11520 int nVar;
11521 int i;
11522 int rc;
@@ -12115,24 +12226,26 @@
12226 ".check GLOB Fail if output since .testcase does not match",
12227 ".clone NEWDB Clone data into NEWDB from the existing database",
12228 ".databases List names and files of attached databases",
12229 ".dbconfig ?op? ?val? List or change sqlite3_db_config() options",
12230 ".dbinfo ?DB? Show status information about the database",
12231 ".dump ?TABLE? Render database content as SQL",
12232 " Options:",
12233 " --preserve-rowids Include ROWID values in the output",
12234 " --newlines Allow unescaped newline characters in output",
12235 " TABLE is a LIKE pattern for the tables to dump",
12236 " Additional LIKE patterns can be given in subsequent arguments",
12237 ".echo on|off Turn command echo on or off",
12238 ".eqp on|off|full|... Enable or disable automatic EXPLAIN QUERY PLAN",
12239 " Other Modes:",
12240 #ifdef SQLITE_DEBUG
12241 " test Show raw EXPLAIN QUERY PLAN output",
12242 " trace Like \"full\" but enable \"PRAGMA vdbe_trace\"",
12243 #endif
12244 " trigger Like \"full\" but also show trigger bytecode",
12245 ".excel Display the output of next command in spreadsheet",
12246 " --bom Put a UTF8 byte-order mark on intermediate file",
12247 ".exit ?CODE? Exit this program with return-code CODE",
12248 ".expert EXPERIMENTAL. Suggest indexes for queries",
12249 ".explain ?on|off|auto? Change the EXPLAIN formatting mode. Default: auto",
12250 ".filectrl CMD ... Run various sqlite3_file_control() operations",
12251 " Run \".filectrl\" with no arguments for details",
@@ -12180,15 +12293,15 @@
12293 " list Values delimited by \"|\"",
12294 " quote Escape answers as for SQL",
12295 " tabs Tab-separated values",
12296 " tcl TCL list elements",
12297 ".nullvalue STRING Use STRING in place of NULL values",
12298 ".once ?OPTIONS? ?FILE? Output for the next SQL command only to FILE",
12299 " If FILE begins with '|' then open as a pipe",
12300 " --bom Put a UTF8 byte-order mark at the beginning",
12301 " -e Send output to the system text editor",
12302 " -x Send output as CSV to a spreadsheet (same as \".excel\")",
12303 #ifdef SQLITE_DEBUG
12304 ".oom [--repeat M] [N] Simulate an OOM error on the N-th allocation",
12305 #endif
12306 ".open ?OPTIONS? ?FILE? Close existing database and reopen FILE",
12307 " Options:",
@@ -12201,11 +12314,15 @@
12314 " --new Initialize FILE to an empty database",
12315 " --nofollow Do not follow symbolic links",
12316 " --readonly Open FILE readonly",
12317 " --zip FILE is a ZIP archive",
12318 ".output ?FILE? Send output to FILE or stdout if FILE is omitted",
12319 " If FILE begins with '|' then open it as a pipe.",
12320 " Options:",
12321 " --bom Prefix output with a UTF8 byte-order mark",
12322 " -e Send output to the system text editor",
12323 " -x Send output as CSV to a spreadsheet",
12324 ".parameter CMD ... Manage SQL parameter bindings",
12325 " clear Erase all bindings",
12326 " init Initialize the TEMP table that holds bindings",
12327 " list List the current parameter bindings",
12328 " set PARAMETER VALUE Given SQL parameter PARAMETER a value of VALUE",
@@ -12321,10 +12438,11 @@
12438 char *zPat;
12439 if( zPattern==0
12440 || zPattern[0]=='0'
12441 || strcmp(zPattern,"-a")==0
12442 || strcmp(zPattern,"-all")==0
12443 || strcmp(zPattern,"--all")==0
12444 ){
12445 /* Show all commands, but only one line per command */
12446 if( zPattern==0 ) zPattern = "";
12447 for(i=0; i<ArraySize(azHelp); i++){
12448 if( azHelp[i][0]=='.' || zPattern[0] ){
@@ -12802,10 +12920,11 @@
12920 sqlite3_enable_load_extension(p->db, 1);
12921 #endif
12922 sqlite3_fileio_init(p->db, 0, 0);
12923 sqlite3_shathree_init(p->db, 0, 0);
12924 sqlite3_completion_init(p->db, 0, 0);
12925 sqlite3_uint_init(p->db, 0, 0);
12926 #if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_ENABLE_DBPAGE_VTAB)
12927 sqlite3_dbdata_init(p->db, 0, 0);
12928 #endif
12929 #ifdef SQLITE_HAVE_ZLIB
12930 sqlite3_zipfile_init(p->db, 0, 0);
@@ -13521,15 +13640,19 @@
13640 #endif
13641 char *zCmd;
13642 zCmd = sqlite3_mprintf("%s %s", zXdgOpenCmd, p->zTempFile);
13643 if( system(zCmd) ){
13644 utf8_printf(stderr, "Failed: [%s]\n", zCmd);
13645 }else{
13646 /* Give the start/open/xdg-open command some time to get
13647 ** going before we continue, and potential delete the
13648 ** p->zTempFile data file out from under it */
13649 sqlite3_sleep(2000);
13650 }
13651 sqlite3_free(zCmd);
13652 outputModePop(p);
13653 p->doXdgOpen = 0;
 
13654 }
13655 #endif /* !defined(SQLITE_NOHAVE_SYSTEM) */
13656 }
13657 p->outfile[0] = 0;
13658 p->out = stdout;
@@ -13815,13 +13938,25 @@
13938 p->zTempFile = 0;
13939 if( p->db ){
13940 sqlite3_file_control(p->db, 0, SQLITE_FCNTL_TEMPFILENAME, &p->zTempFile);
13941 }
13942 if( p->zTempFile==0 ){
13943 /* If p->db is an in-memory database then the TEMPFILENAME file-control
13944 ** will not work and we will need to fallback to guessing */
13945 char *zTemp;
13946 sqlite3_uint64 r;
13947 sqlite3_randomness(sizeof(r), &r);
13948 zTemp = getenv("TEMP");
13949 if( zTemp==0 ) zTemp = getenv("TMP");
13950 if( zTemp==0 ){
13951 #ifdef _WIN32
13952 zTemp = "\\tmp";
13953 #else
13954 zTemp = "/tmp";
13955 #endif
13956 }
13957 p->zTempFile = sqlite3_mprintf("%s/temp%llx.%s", zTemp, r, zSuffix);
13958 }else{
13959 p->zTempFile = sqlite3_mprintf("%z.%s", p->zTempFile, zSuffix);
13960 }
13961 if( p->zTempFile==0 ){
13962 raw_printf(stderr, "out of memory\n");
@@ -15841,11 +15976,12 @@
15976 rc = recoverDatabaseCmd(p, nArg, azArg);
15977 }else
15978 #endif /* !(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_ENABLE_DBPAGE_VTAB) */
15979
15980 if( c=='d' && strncmp(azArg[0], "dump", n)==0 ){
15981 char *zLike = 0;
15982 char *zSql;
15983 int i;
15984 int savedShowHeader = p->showHeader;
15985 int savedShellFlags = p->shellFlgs;
15986 ShellClearFlag(p, SHFLG_PreserveRowid|SHFLG_Newlines|SHFLG_Echo);
15987 for(i=1; i<nArg; i++){
@@ -15869,16 +16005,14 @@
16005 raw_printf(stderr, "Unknown option \"%s\" on \".dump\"\n", azArg[i]);
16006 rc = 1;
16007 goto meta_command_exit;
16008 }
16009 }else if( zLike ){
16010 zLike = sqlite3_mprintf("%z OR name LIKE %Q ESCAPE '\\'",
16011 zLike, azArg[i]);
 
 
16012 }else{
16013 zLike = sqlite3_mprintf("name LIKE %Q ESCAPE '\\'", azArg[i]);
16014 }
16015 }
16016
16017 open_db(p, 0);
16018
@@ -15892,39 +16026,29 @@
16026 /* Set writable_schema=ON since doing so forces SQLite to initialize
16027 ** as much of the schema as it can even if the sqlite_master table is
16028 ** corrupt. */
16029 sqlite3_exec(p->db, "SAVEPOINT dump; PRAGMA writable_schema=ON", 0, 0, 0);
16030 p->nErr = 0;
16031 if( zLike==0 ) zLike = sqlite3_mprintf("true");
16032 zSql = sqlite3_mprintf(
16033 "SELECT name, type, sql FROM sqlite_master "
16034 "WHERE (%s) AND type=='table'"
16035 " AND sql NOT NULL"
16036 " ORDER BY tbl_name='sqlite_sequence', rowid",
16037 zLike
16038 );
16039 run_schema_dump_query(p,zSql);
16040 sqlite3_free(zSql);
16041 zSql = sqlite3_mprintf(
16042 "SELECT sql FROM sqlite_master "
16043 "WHERE (%s) AND sql NOT NULL"
16044 " AND type IN ('index','trigger','view')",
16045 zLike
16046 );
16047 run_table_dump_query(p, zSql);
16048 sqlite3_free(zSql);
16049 sqlite3_free(zLike);
 
 
 
 
 
 
 
 
 
 
16050 if( p->writableSchema ){
16051 raw_printf(p->out, "PRAGMA writable_schema=OFF;\n");
16052 p->writableSchema = 0;
16053 }
16054 sqlite3_exec(p->db, "PRAGMA writable_schema=OFF;", 0, 0, 0);
@@ -16850,46 +16974,70 @@
16974
16975 if( (c=='o'
16976 && (strncmp(azArg[0], "output", n)==0||strncmp(azArg[0], "once", n)==0))
16977 || (c=='e' && n==5 && strcmp(azArg[0],"excel")==0)
16978 ){
16979 const char *zFile = 0;
16980 int bTxtMode = 0;
16981 int i;
16982 int eMode = 0;
16983 int bBOM = 0;
16984 int bOnce;
16985
16986 if( c=='e' ){
16987 eMode = 'x';
16988 bOnce = 2;
16989 }else if( strncmp(azArg[0],"once",n)==0 ){
16990 bOnce = 1;
16991 }
16992 for(i=1; i<nArg; i++){
16993 char *z = azArg[i];
16994 if( z[0]=='-' ){
16995 if( z[1]=='-' ) z++;
16996 if( strcmp(z,"-bom")==0 ){
16997 bBOM = 1;
16998 }else if( c!='e' && strcmp(z,"-x")==0 ){
16999 eMode = 'x'; /* spreadsheet */
17000 }else if( c!='e' && strcmp(z,"-e")==0 ){
17001 eMode = 'e'; /* text editor */
17002 }else{
17003 utf8_printf(p->out, "ERROR: unknown option: \"%s\". Usage:\n",
17004 azArg[i]);
17005 showHelp(p->out, azArg[0]);
17006 rc = 1;
17007 goto meta_command_exit;
17008 }
17009 }else if( zFile==0 ){
17010 zFile = z;
17011 }else{
17012 utf8_printf(p->out,"ERROR: extra parameter: \"%s\". Usage:\n",
17013 azArg[i]);
17014 showHelp(p->out, azArg[0]);
17015 rc = 1;
17016 goto meta_command_exit;
17017 }
17018 }
17019 if( zFile==0 ) zFile = "stdout";
17020 if( bOnce ){
17021 p->outCount = 2;
17022 }else{
17023 p->outCount = 0;
17024 }
17025 output_reset(p);
 
17026 #ifndef SQLITE_NOHAVE_SYSTEM
17027 if( eMode=='e' || eMode=='x' ){
17028 p->doXdgOpen = 1;
17029 outputModePush(p);
17030 if( eMode=='x' ){
17031 /* spreadsheet mode. Output as CSV. */
17032 newTempFile(p, "csv");
17033 ShellClearFlag(p, SHFLG_Echo);
17034 p->mode = MODE_Csv;
17035 sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Comma);
17036 sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_CrLf);
17037 }else{
17038 /* text editor mode */
17039 newTempFile(p, "txt");
17040 bTxtMode = 1;
17041 }
17042 zFile = p->zTempFile;
17043 }
@@ -16904,10 +17052,11 @@
17052 if( p->out==0 ){
17053 utf8_printf(stderr,"Error: cannot open pipe \"%s\"\n", zFile + 1);
17054 p->out = stdout;
17055 rc = 1;
17056 }else{
17057 if( bBOM ) fprintf(p->out,"\357\273\277");
17058 sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile);
17059 }
17060 #endif
17061 }else{
17062 p->out = output_file_open(zFile, bTxtMode);
@@ -16916,10 +17065,11 @@
17065 utf8_printf(stderr,"Error: cannot write to \"%s\"\n", zFile);
17066 }
17067 p->out = stdout;
17068 rc = 1;
17069 } else {
17070 if( bBOM ) fprintf(p->out,"\357\273\277");
17071 sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile);
17072 }
17073 }
17074 }else
17075
@@ -18804,18 +18954,22 @@
18954 /*
18955 ** Output text to the console in a font that attracts extra attention.
18956 */
18957 #ifdef _WIN32
18958 static void printBold(const char *zText){
18959 #if !SQLITE_OS_WINRT
18960 HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);
18961 CONSOLE_SCREEN_BUFFER_INFO defaultScreenInfo;
18962 GetConsoleScreenBufferInfo(out, &defaultScreenInfo);
18963 SetConsoleTextAttribute(out,
18964 FOREGROUND_RED|FOREGROUND_INTENSITY
18965 );
18966 #endif
18967 printf("%s", zText);
18968 #if !SQLITE_OS_WINRT
18969 SetConsoleTextAttribute(out, defaultScreenInfo.wAttributes);
18970 #endif
18971 }
18972 #else
18973 static void printBold(const char *zText){
18974 printf("\033[1m%s\033[0m", zText);
18975 }
@@ -18879,11 +19033,15 @@
19033 "attach debugger to process %d and press any key to continue.\n",
19034 GETPID());
19035 fgetc(stdin);
19036 }else{
19037 #if defined(_WIN32) || defined(WIN32)
19038 #if SQLITE_OS_WINRT
19039 __debugbreak();
19040 #else
19041 DebugBreak();
19042 #endif
19043 #elif defined(SIGTRAP)
19044 raise(SIGTRAP);
19045 #endif
19046 }
19047 }
19048
+252 -74
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1162,11 +1162,11 @@
11621162
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
11631163
** [sqlite_version()] and [sqlite_source_id()].
11641164
*/
11651165
#define SQLITE_VERSION "3.32.0"
11661166
#define SQLITE_VERSION_NUMBER 3032000
1167
-#define SQLITE_SOURCE_ID "2020-03-21 23:10:38 5d14a1c4f2fc17de98ad685ad1422cdfda89dfccb00afcaf32ee416b6f84f525"
1167
+#define SQLITE_SOURCE_ID "2020-04-18 14:12:00 d5b0def96ba6d90f47bc96fab1ccf9c501d84885d086744035b16fd96f3e248c"
11681168
11691169
/*
11701170
** CAPI3REF: Run-Time Library Version Numbers
11711171
** KEYWORDS: sqlite3_version sqlite3_sourceid
11721172
**
@@ -2124,14 +2124,16 @@
21242124
** so that all subsequent write operations are independent.
21252125
** ^SQLite will never invoke SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE without
21262126
** a prior successful call to [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE].
21272127
**
21282128
** <li>[[SQLITE_FCNTL_LOCK_TIMEOUT]]
2129
-** The [SQLITE_FCNTL_LOCK_TIMEOUT] opcode causes attempts to obtain
2130
-** a file lock using the xLock or xShmLock methods of the VFS to wait
2131
-** for up to M milliseconds before failing, where M is the single
2132
-** unsigned integer parameter.
2129
+** The [SQLITE_FCNTL_LOCK_TIMEOUT] opcode is used to configure a VFS
2130
+** to block for up to M milliseconds before failing when attempting to
2131
+** obtain a file lock using the xLock or xShmLock methods of the VFS.
2132
+** The parameter is a pointer to a 32-bit signed integer that contains
2133
+** the value that M is to be set to. Before returning, the 32-bit signed
2134
+** integer is overwritten with the previous value of M.
21332135
**
21342136
** <li>[[SQLITE_FCNTL_DATA_VERSION]]
21352137
** The [SQLITE_FCNTL_DATA_VERSION] opcode is used to detect changes to
21362138
** a database file. The argument is a pointer to a 32-bit unsigned integer.
21372139
** The "data version" for the pager is written into the pointer. The
@@ -5295,10 +5297,28 @@
52955297
**
52965298
** ^The third argument is the value to bind to the parameter.
52975299
** ^If the third parameter to sqlite3_bind_text() or sqlite3_bind_text16()
52985300
** or sqlite3_bind_blob() is a NULL pointer then the fourth parameter
52995301
** is ignored and the end result is the same as sqlite3_bind_null().
5302
+** ^If the third parameter to sqlite3_bind_text() is not NULL, then
5303
+** it should be a pointer to well-formed UTF8 text.
5304
+** ^If the third parameter to sqlite3_bind_text16() is not NULL, then
5305
+** it should be a pointer to well-formed UTF16 text.
5306
+** ^If the third parameter to sqlite3_bind_text64() is not NULL, then
5307
+** it should be a pointer to a well-formed unicode string that is
5308
+** either UTF8 if the sixth parameter is SQLITE_UTF8, or UTF16
5309
+** otherwise.
5310
+**
5311
+** [[byte-order determination rules]] ^The byte-order of
5312
+** UTF16 input text is determined by the byte-order mark (BOM, U+FEFF)
5313
+** found in first character, which is removed, or in the absence of a BOM
5314
+** the byte order is the native byte order of the host
5315
+** machine for sqlite3_bind_text16() or the byte order specified in
5316
+** the 6th parameter for sqlite3_bind_text64().)^
5317
+** ^If UTF16 input text contains invalid unicode
5318
+** characters, then SQLite might change those invalid characters
5319
+** into the unicode replacement character: U+FFFD.
53005320
**
53015321
** ^(In those routines that have a fourth argument, its value is the
53025322
** number of bytes in the parameter. To be clear: the value is the
53035323
** number of <u>bytes</u> in the value, not the number of characters.)^
53045324
** ^If the fourth parameter to sqlite3_bind_text() or sqlite3_bind_text16()
@@ -5308,11 +5328,11 @@
53085328
** the behavior is undefined.
53095329
** If a non-negative fourth parameter is provided to sqlite3_bind_text()
53105330
** or sqlite3_bind_text16() or sqlite3_bind_text64() then
53115331
** that parameter must be the byte offset
53125332
** where the NUL terminator would occur assuming the string were NUL
5313
-** terminated. If any NUL characters occur at byte offsets less than
5333
+** terminated. If any NUL characters occurs at byte offsets less than
53145334
** the value of the fourth parameter then the resulting string value will
53155335
** contain embedded NULs. The result of expressions involving strings
53165336
** with embedded NULs is undefined.
53175337
**
53185338
** ^The fifth argument to the BLOB and string binding interfaces
@@ -6633,12 +6653,13 @@
66336653
** cause the implemented SQL function to throw an exception.
66346654
** ^SQLite uses the string pointed to by the
66356655
** 2nd parameter of sqlite3_result_error() or sqlite3_result_error16()
66366656
** as the text of an error message. ^SQLite interprets the error
66376657
** message string from sqlite3_result_error() as UTF-8. ^SQLite
6638
-** interprets the string from sqlite3_result_error16() as UTF-16 in native
6639
-** byte order. ^If the third parameter to sqlite3_result_error()
6658
+** interprets the string from sqlite3_result_error16() as UTF-16 using
6659
+** the same [byte-order determination rules] as [sqlite3_bind_text16()].
6660
+** ^If the third parameter to sqlite3_result_error()
66406661
** or sqlite3_result_error16() is negative then SQLite takes as the error
66416662
** message all text up through the first zero character.
66426663
** ^If the third parameter to sqlite3_result_error() or
66436664
** sqlite3_result_error16() is non-negative then SQLite takes that many
66446665
** bytes (not characters) from the 2nd parameter as the error message.
@@ -6701,10 +6722,29 @@
67016722
** when it has finished using that result.
67026723
** ^If the 4th parameter to the sqlite3_result_text* interfaces
67036724
** or sqlite3_result_blob is the special constant SQLITE_TRANSIENT
67046725
** then SQLite makes a copy of the result into space obtained
67056726
** from [sqlite3_malloc()] before it returns.
6727
+**
6728
+** ^For the sqlite3_result_text16(), sqlite3_result_text16le(), and
6729
+** sqlite3_result_text16be() routines, and for sqlite3_result_text64()
6730
+** when the encoding is not UTF8, if the input UTF16 begins with a
6731
+** byte-order mark (BOM, U+FEFF) then the BOM is removed from the
6732
+** string and the rest of the string is interpreted according to the
6733
+** byte-order specified by the BOM. ^The byte-order specified by
6734
+** the BOM at the beginning of the text overrides the byte-order
6735
+** specified by the interface procedure. ^So, for example, if
6736
+** sqlite3_result_text16le() is invoked with text that begins
6737
+** with bytes 0xfe, 0xff (a big-endian byte-order mark) then the
6738
+** first two bytes of input are skipped and the remaining input
6739
+** is interpreted as UTF16BE text.
6740
+**
6741
+** ^For UTF16 input text to the sqlite3_result_text16(),
6742
+** sqlite3_result_text16be(), sqlite3_result_text16le(), and
6743
+** sqlite3_result_text64() routines, if the text contains invalid
6744
+** UTF16 characters, the invalid characters might be converted
6745
+** into the unicode replacement character, U+FFFD.
67066746
**
67076747
** ^The sqlite3_result_value() interface sets the result of
67086748
** the application-defined function to be a copy of the
67096749
** [unprotected sqlite3_value] object specified by the 2nd parameter. ^The
67106750
** sqlite3_result_value() interface makes a copy of the [sqlite3_value]
@@ -13369,10 +13409,25 @@
1336913409
#pragma warn -aus /* Assigned value is never used */
1337013410
#pragma warn -csu /* Comparing signed and unsigned */
1337113411
#pragma warn -spa /* Suspicious pointer arithmetic */
1337213412
#endif
1337313413
13414
+/*
13415
+** WAL mode depends on atomic aligned 32-bit loads and stores in a few
13416
+** places. The following macros try to make this explicit.
13417
+*/
13418
+#ifndef __has_feature
13419
+# define __has_feature(x) 0 /* compatibility with non-clang compilers */
13420
+#endif
13421
+#if GCC_VERSION>=4007000 || __has_feature(c_atomic)
13422
+# define AtomicLoad(PTR) __atomic_load_n((PTR),__ATOMIC_RELAXED)
13423
+# define AtomicStore(PTR,VAL) __atomic_store_n((PTR),(VAL),__ATOMIC_RELAXED)
13424
+#else
13425
+# define AtomicLoad(PTR) (*(PTR))
13426
+# define AtomicStore(PTR,VAL) (*(PTR) = (VAL))
13427
+#endif
13428
+
1337413429
/*
1337513430
** Include standard header files as necessary
1337613431
*/
1337713432
#ifdef HAVE_STDINT_H
1337813433
#include <stdint.h>
@@ -17209,10 +17264,11 @@
1720917264
Expr *pDflt; /* Default value or GENERATED ALWAYS AS value */
1721017265
char *zColl; /* Collating sequence. If NULL, use the default */
1721117266
u8 notNull; /* An OE_ code for handling a NOT NULL constraint */
1721217267
char affinity; /* One of the SQLITE_AFF_... values */
1721317268
u8 szEst; /* Estimated size of value in this column. sizeof(INT)==1 */
17269
+ u8 hName; /* Column name hash for faster lookup */
1721417270
u16 colFlags; /* Boolean properties. See COLFLAG_ defines below */
1721517271
};
1721617272
1721717273
/* Allowed values for Column.colFlags:
1721817274
*/
@@ -19827,10 +19883,11 @@
1982719883
const char*,
1982819884
const char*,
1982919885
const char*
1983019886
);
1983119887
SQLITE_PRIVATE Bitmask sqlite3ExprColUsed(Expr*);
19888
+SQLITE_PRIVATE u8 sqlite3StrIHash(const char*);
1983219889
SQLITE_PRIVATE int sqlite3ResolveExprNames(NameContext*, Expr*);
1983319890
SQLITE_PRIVATE int sqlite3ResolveExprListNames(NameContext*, ExprList*);
1983419891
SQLITE_PRIVATE void sqlite3ResolveSelectNames(Parse*, Select*, NameContext*);
1983519892
SQLITE_PRIVATE int sqlite3ResolveSelfReference(Parse*,Table*,int,Expr*,ExprList*);
1983619893
SQLITE_PRIVATE int sqlite3ResolveOrderGroupBy(Parse*, Select*, ExprList*, const char*);
@@ -22165,16 +22222,16 @@
2216522222
u8 nName; /* Length of th name */
2216622223
char *zName; /* Name of the transformation */
2216722224
double rLimit; /* Maximum NNN value for this transform */
2216822225
double rXform; /* Constant used for this transform */
2216922226
} aXformType[] = {
22170
- { 0, 6, "second", 464269060800.0, 86400000.0/(24.0*60.0*60.0) },
22171
- { 0, 6, "minute", 7737817680.0, 86400000.0/(24.0*60.0) },
22172
- { 0, 4, "hour", 128963628.0, 86400000.0/24.0 },
22173
- { 0, 3, "day", 5373485.0, 86400000.0 },
22174
- { 1, 5, "month", 176546.0, 30.0*86400000.0 },
22175
- { 2, 4, "year", 14713.0, 365.0*86400000.0 },
22227
+ { 0, 6, "second", 464269060800.0, 1000.0 },
22228
+ { 0, 6, "minute", 7737817680.0, 60000.0 },
22229
+ { 0, 4, "hour", 128963628.0, 3600000.0 },
22230
+ { 0, 3, "day", 5373485.0, 86400000.0 },
22231
+ { 1, 5, "month", 176546.0, 2592000000.0 },
22232
+ { 2, 4, "year", 14713.0, 31536000000.0 },
2217622233
};
2217722234
2217822235
/*
2217922236
** Process a modifier to a date-time stamp. The modifiers are
2218022237
** as follows:
@@ -27907,11 +27964,11 @@
2790727964
*/
2790827965
SQLITE_PRIVATE void sqlite3OomFault(sqlite3 *db){
2790927966
if( db->mallocFailed==0 && db->bBenignMalloc==0 ){
2791027967
db->mallocFailed = 1;
2791127968
if( db->nVdbeExec>0 ){
27912
- db->u1.isInterrupted = 1;
27969
+ AtomicStore(&db->u1.isInterrupted, 1);
2791327970
}
2791427971
DisableLookaside;
2791527972
if( db->pParse ){
2791627973
db->pParse->rc = SQLITE_NOMEM_BKPT;
2791727974
}
@@ -27926,11 +27983,11 @@
2792627983
** VDBEs.
2792727984
*/
2792827985
SQLITE_PRIVATE void sqlite3OomClear(sqlite3 *db){
2792927986
if( db->mallocFailed && db->nVdbeExec==0 ){
2793027987
db->mallocFailed = 0;
27931
- db->u1.isInterrupted = 0;
27988
+ AtomicStore(&db->u1.isInterrupted, 0);
2793227989
assert( db->lookaside.bDisable>0 );
2793327990
EnableLookaside;
2793427991
}
2793527992
}
2793627993
@@ -31300,10 +31357,23 @@
3130031357
a = (unsigned char *)zLeft;
3130131358
b = (unsigned char *)zRight;
3130231359
while( N-- > 0 && *a!=0 && UpperToLower[*a]==UpperToLower[*b]){ a++; b++; }
3130331360
return N<0 ? 0 : UpperToLower[*a] - UpperToLower[*b];
3130431361
}
31362
+
31363
+/*
31364
+** Compute an 8-bit hash on a string that is insensitive to case differences
31365
+*/
31366
+SQLITE_PRIVATE u8 sqlite3StrIHash(const char *z){
31367
+ u8 h = 0;
31368
+ if( z==0 ) return 0;
31369
+ while( z[0] ){
31370
+ h += UpperToLower[(unsigned char)z[0]];
31371
+ z++;
31372
+ }
31373
+ return h;
31374
+}
3130531375
3130631376
/*
3130731377
** Compute 10 to the E-th power. Examples: E==1 results in 10.
3130831378
** E==2 results in 100. E==50 results in 1.0e50.
3130931379
**
@@ -37287,11 +37357,13 @@
3728737357
*(int*)pArg = fileHasMoved(pFile);
3728837358
return SQLITE_OK;
3728937359
}
3729037360
#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
3729137361
case SQLITE_FCNTL_LOCK_TIMEOUT: {
37362
+ int iOld = pFile->iBusyTimeout;
3729237363
pFile->iBusyTimeout = *(int*)pArg;
37364
+ *(int*)pArg = iOld;
3729337365
return SQLITE_OK;
3729437366
}
3729537367
#endif
3729637368
#if SQLITE_MAX_MMAP_SIZE>0
3729737369
case SQLITE_FCNTL_MMAP_SIZE: {
@@ -38108,10 +38180,28 @@
3810838180
|| flags==(SQLITE_SHM_UNLOCK | SQLITE_SHM_SHARED)
3810938181
|| flags==(SQLITE_SHM_UNLOCK | SQLITE_SHM_EXCLUSIVE) );
3811038182
assert( n==1 || (flags & SQLITE_SHM_EXCLUSIVE)!=0 );
3811138183
assert( pShmNode->hShm>=0 || pDbFd->pInode->bProcessLock==1 );
3811238184
assert( pShmNode->hShm<0 || pDbFd->pInode->bProcessLock==0 );
38185
+
38186
+ /* Check that, if this to be a blocking lock, that locks have been
38187
+ ** obtained in the following order.
38188
+ **
38189
+ ** 1. Checkpointer lock (ofst==1).
38190
+ ** 2. Recover lock (ofst==2).
38191
+ ** 3. Read locks (ofst>=3 && ofst<SQLITE_SHM_NLOCK).
38192
+ ** 4. Write lock (ofst==0).
38193
+ **
38194
+ ** In other words, if this is a blocking lock, none of the locks that
38195
+ ** occur later in the above list than the lock being obtained may be
38196
+ ** held. */
38197
+#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
38198
+ assert( pDbFd->iBusyTimeout==0
38199
+ || (flags & SQLITE_SHM_UNLOCK) || ofst==0
38200
+ || ((p->exclMask|p->sharedMask)&~((1<<ofst)-2))==0
38201
+ );
38202
+#endif
3811338203
3811438204
mask = (1<<(ofst+n)) - (1<<ofst);
3811538205
assert( n>1 || mask==(1<<ofst) );
3811638206
sqlite3_mutex_enter(pShmNode->pShmMutex);
3811738207
if( flags & SQLITE_SHM_UNLOCK ){
@@ -59322,22 +59412,10 @@
5932259412
# define WALTRACE(X) if(sqlite3WalTrace) sqlite3DebugPrintf X
5932359413
#else
5932459414
# define WALTRACE(X)
5932559415
#endif
5932659416
59327
-/*
59328
-** WAL mode depends on atomic aligned 32-bit loads and stores in a few
59329
-** places. The following macros try to make this explicit.
59330
-*/
59331
-#if GCC_VESRION>=5004000
59332
-# define AtomicLoad(PTR) __atomic_load_n((PTR),__ATOMIC_RELAXED)
59333
-# define AtomicStore(PTR,VAL) __atomic_store_n((PTR),(VAL),__ATOMIC_RELAXED)
59334
-#else
59335
-# define AtomicLoad(PTR) (*(PTR))
59336
-# define AtomicStore(PTR,VAL) (*(PTR) = (VAL))
59337
-#endif
59338
-
5933959417
/*
5934059418
** The maximum (and only) versions of the wal and wal-index formats
5934159419
** that may be interpreted by this version of SQLite.
5934259420
**
5934359421
** If a client begins recovering a WAL file and finds that (a) the checksum
@@ -60203,10 +60281,15 @@
6020360281
static int walIndexRecover(Wal *pWal){
6020460282
int rc; /* Return Code */
6020560283
i64 nSize; /* Size of log file */
6020660284
u32 aFrameCksum[2] = {0, 0};
6020760285
int iLock; /* Lock offset to lock for checkpoint */
60286
+
60287
+#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
60288
+ int tmout = 0;
60289
+ sqlite3OsFileControl(pWal->pDbFd, SQLITE_FCNTL_LOCK_TIMEOUT, (void*)&tmout);
60290
+#endif
6020860291
6020960292
/* Obtain an exclusive lock on all byte in the locking range not already
6021060293
** locked by the caller. The caller is guaranteed to have locked the
6021160294
** WAL_WRITE_LOCK byte, and may have also locked the WAL_CKPT_LOCK byte.
6021260295
** If successful, the same bytes that are locked here are unlocked before
@@ -60950,11 +61033,11 @@
6095061033
6095161034
/* Iterate through the contents of the WAL, copying data to the db file */
6095261035
while( rc==SQLITE_OK && 0==walIteratorNext(pIter, &iDbpage, &iFrame) ){
6095361036
i64 iOffset;
6095461037
assert( walFramePgno(pWal, iFrame)==iDbpage );
60955
- if( db->u1.isInterrupted ){
61038
+ if( AtomicLoad(&db->u1.isInterrupted) ){
6095661039
rc = db->mallocFailed ? SQLITE_NOMEM_BKPT : SQLITE_INTERRUPT;
6095761040
break;
6095861041
}
6095961042
if( iFrame<=nBackfill || iFrame>mxSafeFrame || iDbpage>mxPage ){
6096061043
continue;
@@ -61663,11 +61746,12 @@
6166361746
&& (mxReadMark<mxFrame || mxI==0)
6166461747
){
6166561748
for(i=1; i<WAL_NREADER; i++){
6166661749
rc = walLockExclusive(pWal, WAL_READ_LOCK(i), 1);
6166761750
if( rc==SQLITE_OK ){
61668
- mxReadMark = AtomicStore(pInfo->aReadMark+i,mxFrame);
61751
+ AtomicStore(pInfo->aReadMark+i,mxFrame);
61752
+ mxReadMark = mxFrame;
6166961753
mxI = i;
6167061754
walUnlockExclusive(pWal, WAL_READ_LOCK(i), 1);
6167161755
break;
6167261756
}else if( rc!=SQLITE_BUSY ){
6167361757
return rc;
@@ -61822,26 +61906,45 @@
6182261906
** needs to be flushed.
6182361907
*/
6182461908
SQLITE_PRIVATE int sqlite3WalBeginReadTransaction(Wal *pWal, int *pChanged){
6182561909
int rc; /* Return code */
6182661910
int cnt = 0; /* Number of TryBeginRead attempts */
61911
+#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
61912
+ int tmout = 0;
61913
+#endif
6182761914
6182861915
#ifdef SQLITE_ENABLE_SNAPSHOT
6182961916
int bChanged = 0;
6183061917
WalIndexHdr *pSnapshot = pWal->pSnapshot;
6183161918
if( pSnapshot && memcmp(pSnapshot, &pWal->hdr, sizeof(WalIndexHdr))!=0 ){
6183261919
bChanged = 1;
6183361920
}
6183461921
#endif
6183561922
61923
+#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
61924
+ /* Disable blocking locks. They are not useful when trying to open a
61925
+ ** read-transaction, and blocking may cause deadlock anyway. */
61926
+ sqlite3OsFileControl(pWal->pDbFd, SQLITE_FCNTL_LOCK_TIMEOUT, (void*)&tmout);
61927
+#endif
61928
+
6183661929
do{
6183761930
rc = walTryBeginRead(pWal, pChanged, 0, ++cnt);
6183861931
}while( rc==WAL_RETRY );
6183961932
testcase( (rc&0xff)==SQLITE_BUSY );
6184061933
testcase( (rc&0xff)==SQLITE_IOERR );
6184161934
testcase( rc==SQLITE_PROTOCOL );
6184261935
testcase( rc==SQLITE_OK );
61936
+
61937
+#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
61938
+ /* If they were disabled earlier and the read-transaction has been
61939
+ ** successfully opened, re-enable blocking locks. This is because the
61940
+ ** connection may attempt to upgrade to a write-transaction, which does
61941
+ ** benefit from using blocking locks. */
61942
+ if( rc==SQLITE_OK ){
61943
+ sqlite3OsFileControl(pWal->pDbFd, SQLITE_FCNTL_LOCK_TIMEOUT, (void*)&tmout);
61944
+ }
61945
+#endif
6184361946
6184461947
#ifdef SQLITE_ENABLE_SNAPSHOT
6184561948
if( rc==SQLITE_OK ){
6184661949
if( pSnapshot && memcmp(pSnapshot, &pWal->hdr, sizeof(WalIndexHdr))!=0 ){
6184761950
/* At this point the client has a lock on an aReadMark[] slot holding
@@ -73477,11 +73580,11 @@
7347773580
}
7347873581
7347973582
/* Unless an error occurs, the following loop runs one iteration for each
7348073583
** page in the B-Tree structure (not including overflow pages).
7348173584
*/
73482
- while( rc==SQLITE_OK && !db->u1.isInterrupted ){
73585
+ while( rc==SQLITE_OK && !AtomicLoad(&db->u1.isInterrupted) ){
7348373586
int iIdx; /* Index of child node in parent */
7348473587
MemPage *pPage; /* Current page of the b-tree */
7348573588
7348673589
/* If this is a leaf page or the tree is not an int-key tree, then
7348773590
** this page contains countable entries. Increment the entry counter
@@ -73603,11 +73706,11 @@
7360373706
}
7360473707
if( getPageReferenced(pCheck, iPage) ){
7360573708
checkAppendMsg(pCheck, "2nd reference to page %d", iPage);
7360673709
return 1;
7360773710
}
73608
- if( pCheck->db->u1.isInterrupted ) return 1;
73711
+ if( AtomicLoad(&pCheck->db->u1.isInterrupted) ) return 1;
7360973712
setPageReferenced(pCheck, iPage);
7361073713
return 0;
7361173714
}
7361273715
7361373716
#ifndef SQLITE_OMIT_AUTOVACUUM
@@ -79233,11 +79336,11 @@
7923379336
if( pOp->opcode==OP_Explain ) break;
7923479337
if( pOp->opcode==OP_Init && p->pc>1 ) break;
7923579338
}
7923679339
7923779340
if( rc==SQLITE_OK ){
79238
- if( db->u1.isInterrupted ){
79341
+ if( AtomicLoad(&db->u1.isInterrupted) ){
7923979342
p->rc = SQLITE_INTERRUPT;
7924079343
rc = SQLITE_ERROR;
7924179344
sqlite3VdbeError(p, sqlite3ErrStr(p->rc));
7924279345
}else{
7924379346
char *zP4;
@@ -83028,11 +83131,11 @@
8302883131
/* If there are no other statements currently running, then
8302983132
** reset the interrupt flag. This prevents a call to sqlite3_interrupt
8303083133
** from interrupting a statement that has not yet started.
8303183134
*/
8303283135
if( db->nVdbeActive==0 ){
83033
- db->u1.isInterrupted = 0;
83136
+ AtomicStore(&db->u1.isInterrupted, 0);
8303483137
}
8303583138
8303683139
assert( db->nVdbeWrite>0 || db->autoCommit==0
8303783140
|| (db->nDeferredCons==0 && db->nDeferredImmCons==0)
8303883141
);
@@ -85413,11 +85516,11 @@
8541385516
assert( p->bIsReader || p->readOnly!=0 );
8541485517
p->iCurrentTime = 0;
8541585518
assert( p->explain==0 );
8541685519
p->pResultSet = 0;
8541785520
db->busyHandler.nBusy = 0;
85418
- if( db->u1.isInterrupted ) goto abort_due_to_interrupt;
85521
+ if( AtomicLoad(&db->u1.isInterrupted) ) goto abort_due_to_interrupt;
8541985522
sqlite3VdbeIOTraceSql(p);
8542085523
#ifdef SQLITE_DEBUG
8542185524
sqlite3BeginBenignMalloc();
8542285525
if( p->pc==0
8542385526
&& (p->db->flags & (SQLITE_VdbeListing|SQLITE_VdbeEQP|SQLITE_VdbeTrace))!=0
@@ -85597,11 +85700,11 @@
8559785700
** But that is not due to sloppy coding habits. The code is written this
8559885701
** way for performance, to avoid having to run the interrupt and progress
8559985702
** checks on every opcode. This helps sqlite3_step() to run about 1.5%
8560085703
** faster according to "valgrind --tool=cachegrind" */
8560185704
check_for_interrupt:
85602
- if( db->u1.isInterrupted ) goto abort_due_to_interrupt;
85705
+ if( AtomicLoad(&db->u1.isInterrupted) ) goto abort_due_to_interrupt;
8560385706
#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
8560485707
/* Call the progress callback if it is configured and the required number
8560585708
** of VDBE ops have been executed (either since this invocation of
8560685709
** sqlite3VdbeExec() or since last time the progress callback was called).
8560785710
** If the progress callback returns non-zero, exit the virtual machine with
@@ -92705,11 +92808,11 @@
9270592808
9270692809
/* Jump to here if the sqlite3_interrupt() API sets the interrupt
9270792810
** flag.
9270892811
*/
9270992812
abort_due_to_interrupt:
92710
- assert( db->u1.isInterrupted );
92813
+ assert( AtomicLoad(&db->u1.isInterrupted) );
9271192814
rc = db->mallocFailed ? SQLITE_NOMEM_BKPT : SQLITE_INTERRUPT;
9271292815
p->rc = rc;
9271392816
sqlite3VdbeError(p, "%s", sqlite3ErrStr(rc));
9271492817
goto abort_due_to_error;
9271592818
}
@@ -96775,11 +96878,11 @@
9677596878
const char *zTab,
9677696879
const char *zDb
9677796880
){
9677896881
int n;
9677996882
const char *zSpan;
96780
- if( NEVER(pItem->eEName!=ENAME_TAB) ) return 0;
96883
+ if( pItem->eEName!=ENAME_TAB ) return 0;
9678196884
zSpan = pItem->zEName;
9678296885
for(n=0; ALWAYS(zSpan[n]) && zSpan[n]!='.'; n++){}
9678396886
if( zDb && (sqlite3StrNICmp(zSpan, zDb, n)!=0 || zDb[n]!=0) ){
9678496887
return 0;
9678596888
}
@@ -96929,10 +97032,11 @@
9692997032
ExprList *pEList;
9693097033
SrcList *pSrcList = pNC->pSrcList;
9693197034
9693297035
if( pSrcList ){
9693397036
for(i=0, pItem=pSrcList->a; i<pSrcList->nSrc; i++, pItem++){
97037
+ u8 hCol;
9693497038
pTab = pItem->pTab;
9693597039
assert( pTab!=0 && pTab->zName!=0 );
9693697040
assert( pTab->nCol>0 );
9693797041
if( pItem->pSelect && (pItem->pSelect->selFlags & SF_NestedFrom)!=0 ){
9693897042
int hit = 0;
@@ -96962,12 +97066,13 @@
9696297066
}
9696397067
}
9696497068
if( 0==(cntTab++) ){
9696597069
pMatch = pItem;
9696697070
}
97071
+ hCol = sqlite3StrIHash(zCol);
9696797072
for(j=0, pCol=pTab->aCol; j<pTab->nCol; j++, pCol++){
96968
- if( sqlite3StrICmp(pCol->zName, zCol)==0 ){
97073
+ if( pCol->hName==hCol && sqlite3StrICmp(pCol->zName, zCol)==0 ){
9696997074
/* If there has been exactly one prior match and this match
9697097075
** is for the right-hand table of a NATURAL JOIN or is in a
9697197076
** USING clause, then skip this match.
9697297077
*/
9697397078
if( cnt==1 ){
@@ -97024,14 +97129,15 @@
9702497129
}
9702597130
#endif /* SQLITE_OMIT_UPSERT */
9702697131
9702797132
if( pTab ){
9702897133
int iCol;
97134
+ u8 hCol = sqlite3StrIHash(zCol);
9702997135
pSchema = pTab->pSchema;
9703097136
cntTab++;
9703197137
for(iCol=0, pCol=pTab->aCol; iCol<pTab->nCol; iCol++, pCol++){
97032
- if( sqlite3StrICmp(pCol->zName, zCol)==0 ){
97138
+ if( pCol->hName==hCol && sqlite3StrICmp(pCol->zName, zCol)==0 ){
9703397139
if( iCol==pTab->iPKey ){
9703497140
iCol = -1;
9703597141
}
9703697142
break;
9703797143
}
@@ -97828,11 +97934,11 @@
9782897934
nc.uNC.pEList = pEList;
9782997935
nc.ncFlags = NC_AllowAgg|NC_UEList;
9783097936
nc.nErr = 0;
9783197937
db = pParse->db;
9783297938
savedSuppErr = db->suppressErr;
97833
- db->suppressErr = 1;
97939
+ if( IN_RENAME_OBJECT==0 ) db->suppressErr = 1;
9783497940
rc = sqlite3ResolveExprNames(&nc, pE);
9783597941
db->suppressErr = savedSuppErr;
9783697942
if( rc ) return 0;
9783797943
9783897944
/* Try to match the ORDER BY expression against an expression
@@ -98463,15 +98569,45 @@
9846398569
SQLITE_PRIVATE int sqlite3ResolveExprListNames(
9846498570
NameContext *pNC, /* Namespace to resolve expressions in. */
9846598571
ExprList *pList /* The expression list to be analyzed. */
9846698572
){
9846798573
int i;
98468
- if( pList ){
98469
- for(i=0; i<pList->nExpr; i++){
98470
- if( sqlite3ResolveExprNames(pNC, pList->a[i].pExpr) ) return WRC_Abort;
98574
+ int savedHasAgg = 0;
98575
+ Walker w;
98576
+ if( pList==0 ) return WRC_Continue;
98577
+ w.pParse = pNC->pParse;
98578
+ w.xExprCallback = resolveExprStep;
98579
+ w.xSelectCallback = resolveSelectStep;
98580
+ w.xSelectCallback2 = 0;
98581
+ w.u.pNC = pNC;
98582
+ savedHasAgg = pNC->ncFlags & (NC_HasAgg|NC_MinMaxAgg|NC_HasWin);
98583
+ pNC->ncFlags &= ~(NC_HasAgg|NC_MinMaxAgg|NC_HasWin);
98584
+ for(i=0; i<pList->nExpr; i++){
98585
+ Expr *pExpr = pList->a[i].pExpr;
98586
+ if( pExpr==0 ) continue;
98587
+#if SQLITE_MAX_EXPR_DEPTH>0
98588
+ w.pParse->nHeight += pExpr->nHeight;
98589
+ if( sqlite3ExprCheckHeight(w.pParse, w.pParse->nHeight) ){
98590
+ return WRC_Abort;
9847198591
}
98592
+#endif
98593
+ sqlite3WalkExpr(&w, pExpr);
98594
+#if SQLITE_MAX_EXPR_DEPTH>0
98595
+ w.pParse->nHeight -= pExpr->nHeight;
98596
+#endif
98597
+ assert( EP_Agg==NC_HasAgg );
98598
+ assert( EP_Win==NC_HasWin );
98599
+ testcase( pNC->ncFlags & NC_HasAgg );
98600
+ testcase( pNC->ncFlags & NC_HasWin );
98601
+ if( pNC->ncFlags & (NC_HasAgg|NC_MinMaxAgg|NC_HasWin) ){
98602
+ ExprSetProperty(pExpr, pNC->ncFlags & (NC_HasAgg|NC_HasWin) );
98603
+ savedHasAgg |= pNC->ncFlags & (NC_HasAgg|NC_MinMaxAgg|NC_HasWin);
98604
+ pNC->ncFlags &= ~(NC_HasAgg|NC_MinMaxAgg|NC_HasWin);
98605
+ }
98606
+ if( pNC->nErr>0 || w.pParse->nErr>0 ) return WRC_Abort;
9847298607
}
98608
+ pNC->ncFlags |= savedHasAgg;
9847398609
return WRC_Continue;
9847498610
}
9847598611
9847698612
/*
9847798613
** Resolve all names in all expressions of a SELECT and in all
@@ -100343,20 +100479,26 @@
100343100479
ExprList *pList, /* List to which to add the span. */
100344100480
Token *pName, /* Name to be added */
100345100481
int dequote /* True to cause the name to be dequoted */
100346100482
){
100347100483
assert( pList!=0 || pParse->db->mallocFailed!=0 );
100484
+ assert( pParse->eParseMode!=PARSE_MODE_UNMAP || dequote==0 );
100348100485
if( pList ){
100349100486
struct ExprList_item *pItem;
100350100487
assert( pList->nExpr>0 );
100351100488
pItem = &pList->a[pList->nExpr-1];
100352100489
assert( pItem->zEName==0 );
100353100490
assert( pItem->eEName==ENAME_NAME );
100354100491
pItem->zEName = sqlite3DbStrNDup(pParse->db, pName->z, pName->n);
100355
- if( dequote ) sqlite3Dequote(pItem->zEName);
100356
- if( IN_RENAME_OBJECT ){
100357
- sqlite3RenameTokenMap(pParse, (void*)pItem->zEName, pName);
100492
+ if( dequote ){
100493
+ /* If dequote==0, then pName->z does not point to part of a DDL
100494
+ ** statement handled by the parser. And so no token need be added
100495
+ ** to the token-map. */
100496
+ sqlite3Dequote(pItem->zEName);
100497
+ if( IN_RENAME_OBJECT ){
100498
+ sqlite3RenameTokenMap(pParse, (void*)pItem->zEName, pName);
100499
+ }
100358100500
}
100359100501
}
100360100502
}
100361100503
100362100504
/*
@@ -101497,10 +101639,12 @@
101497101639
struct ExprList_item *pItem;
101498101640
int r1, r2;
101499101641
affinity = sqlite3ExprAffinity(pLeft);
101500101642
if( affinity<=SQLITE_AFF_NONE ){
101501101643
affinity = SQLITE_AFF_BLOB;
101644
+ }else if( affinity==SQLITE_AFF_REAL ){
101645
+ affinity = SQLITE_AFF_NUMERIC;
101502101646
}
101503101647
if( pKeyInfo ){
101504101648
assert( sqlite3KeyInfoIsWriteable(pKeyInfo) );
101505101649
pKeyInfo->aColl[0] = sqlite3ExprCollSeq(pParse, pExpr->pLeft);
101506101650
}
@@ -101735,10 +101879,11 @@
101735101879
int destStep6 = 0; /* Start of code for Step 6 */
101736101880
int addrTruthOp; /* Address of opcode that determines the IN is true */
101737101881
int destNotNull; /* Jump here if a comparison is not true in step 6 */
101738101882
int addrTop; /* Top of the step-6 loop */
101739101883
int iTab = 0; /* Index to use */
101884
+ u8 okConstFactor = pParse->okConstFactor;
101740101885
101741101886
assert( !ExprHasVVAProperty(pExpr,EP_Immutable) );
101742101887
pLeft = pExpr->pLeft;
101743101888
if( sqlite3ExprCheckIN(pParse, pExpr) ) return;
101744101889
zAff = exprINAffinity(pParse, pExpr);
@@ -101779,12 +101924,18 @@
101779101924
**
101780101925
** sqlite3FindInIndex() might have reordered the fields of the LHS vector
101781101926
** so that the fields are in the same order as an existing index. The
101782101927
** aiMap[] array contains a mapping from the original LHS field order to
101783101928
** the field order that matches the RHS index.
101784
- */
101929
+ **
101930
+ ** Avoid factoring the LHS of the IN(...) expression out of the loop,
101931
+ ** even if it is constant, as OP_Affinity may be used on the register
101932
+ ** by code generated below. */
101933
+ assert( pParse->okConstFactor==okConstFactor );
101934
+ pParse->okConstFactor = 0;
101785101935
rLhsOrig = exprCodeVector(pParse, pLeft, &iDummy);
101936
+ pParse->okConstFactor = okConstFactor;
101786101937
for(i=0; i<nVector && aiMap[i]==i; i++){} /* Are LHS fields reordered? */
101787101938
if( i==nVector ){
101788101939
/* LHS fields are not reordered */
101789101940
rLhs = rLhsOrig;
101790101941
}else{
@@ -101806,25 +101957,17 @@
101806101957
CollSeq *pColl = sqlite3ExprCollSeq(pParse, pExpr->pLeft);
101807101958
int labelOk = sqlite3VdbeMakeLabel(pParse);
101808101959
int r2, regToFree;
101809101960
int regCkNull = 0;
101810101961
int ii;
101811
- int bLhsReal; /* True if the LHS of the IN has REAL affinity */
101812101962
assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
101813101963
if( destIfNull!=destIfFalse ){
101814101964
regCkNull = sqlite3GetTempReg(pParse);
101815101965
sqlite3VdbeAddOp3(v, OP_BitAnd, rLhs, rLhs, regCkNull);
101816101966
}
101817
- bLhsReal = sqlite3ExprAffinity(pExpr->pLeft)==SQLITE_AFF_REAL;
101818101967
for(ii=0; ii<pList->nExpr; ii++){
101819
- if( bLhsReal ){
101820
- r2 = regToFree = sqlite3GetTempReg(pParse);
101821
- sqlite3ExprCode(pParse, pList->a[ii].pExpr, r2);
101822
- sqlite3VdbeAddOp4(v, OP_Affinity, r2, 1, 0, "E", P4_STATIC);
101823
- }else{
101824
- r2 = sqlite3ExprCodeTemp(pParse, pList->a[ii].pExpr, &regToFree);
101825
- }
101968
+ r2 = sqlite3ExprCodeTemp(pParse, pList->a[ii].pExpr, &regToFree);
101826101969
if( regCkNull && sqlite3ExprCanBeNull(pList->a[ii].pExpr) ){
101827101970
sqlite3VdbeAddOp3(v, OP_BitAnd, regCkNull, r2, regCkNull);
101828101971
}
101829101972
sqlite3ReleaseTempReg(pParse, regToFree);
101830101973
if( ii<pList->nExpr-1 || destIfNull!=destIfFalse ){
@@ -102394,14 +102537,10 @@
102394102537
}
102395102538
if( aff>SQLITE_AFF_BLOB ){
102396102539
static const char zAff[] = "B\000C\000D\000E";
102397102540
assert( SQLITE_AFF_BLOB=='A' );
102398102541
assert( SQLITE_AFF_TEXT=='B' );
102399
- if( iReg!=target ){
102400
- sqlite3VdbeAddOp2(v, OP_SCopy, iReg, target);
102401
- iReg = target;
102402
- }
102403102542
sqlite3VdbeAddOp4(v, OP_Affinity, iReg, 1, 0,
102404102543
&zAff[(aff-'B')*2], P4_STATIC);
102405102544
}
102406102545
return iReg;
102407102546
}
@@ -105020,10 +105159,11 @@
105020105159
}
105021105160
memcpy(pNew->aCol, pTab->aCol, sizeof(Column)*pNew->nCol);
105022105161
for(i=0; i<pNew->nCol; i++){
105023105162
Column *pCol = &pNew->aCol[i];
105024105163
pCol->zName = sqlite3DbStrDup(db, pCol->zName);
105164
+ pCol->hName = sqlite3StrIHash(pCol->zName);
105025105165
pCol->zColl = 0;
105026105166
pCol->pDflt = 0;
105027105167
}
105028105168
pNew->pSchema = db->aDb[iDb].pSchema;
105029105169
pNew->addColOffset = pTab->addColOffset;
@@ -105248,11 +105388,11 @@
105248105388
*/
105249105389
SQLITE_PRIVATE void *sqlite3RenameTokenMap(Parse *pParse, void *pPtr, Token *pToken){
105250105390
RenameToken *pNew;
105251105391
assert( pPtr || pParse->db->mallocFailed );
105252105392
renameTokenCheckAll(pParse, pPtr);
105253
- if( pParse->eParseMode!=PARSE_MODE_UNMAP ){
105393
+ if( ALWAYS(pParse->eParseMode!=PARSE_MODE_UNMAP) ){
105254105394
pNew = sqlite3DbMallocZero(pParse->db, sizeof(RenameToken));
105255105395
if( pNew ){
105256105396
pNew->p = pPtr;
105257105397
pNew->t = *pToken;
105258105398
pNew->pNext = pParse->pRename;
@@ -105305,10 +105445,25 @@
105305105445
sqlite3WalkSelect(pWalker, p);
105306105446
sqlite3RenameExprlistUnmap(pWalker->pParse, pWith->a[i].pCols);
105307105447
}
105308105448
}
105309105449
}
105450
+
105451
+/*
105452
+** Unmap all tokens in the IdList object passed as the second argument.
105453
+*/
105454
+static void unmapColumnIdlistNames(
105455
+ Parse *pParse,
105456
+ IdList *pIdList
105457
+){
105458
+ if( pIdList ){
105459
+ int ii;
105460
+ for(ii=0; ii<pIdList->nId; ii++){
105461
+ sqlite3RenameTokenRemap(pParse, 0, (void*)pIdList->a[ii].zName);
105462
+ }
105463
+ }
105464
+}
105310105465
105311105466
/*
105312105467
** Walker callback used by sqlite3RenameExprUnmap().
105313105468
*/
105314105469
static int renameUnmapSelectCb(Walker *pWalker, Select *p){
@@ -105327,10 +105482,11 @@
105327105482
if( ALWAYS(p->pSrc) ){ /* Every Select as a SrcList, even if it is empty */
105328105483
SrcList *pSrc = p->pSrc;
105329105484
for(i=0; i<pSrc->nSrc; i++){
105330105485
sqlite3RenameTokenRemap(pParse, 0, (void*)pSrc->a[i].zName);
105331105486
if( sqlite3WalkExpr(pWalker, pSrc->a[i].pOn) ) return WRC_Abort;
105487
+ unmapColumnIdlistNames(pParse, pSrc->a[i].pUsing);
105332105488
}
105333105489
}
105334105490
105335105491
renameWalkWith(pWalker, p);
105336105492
return WRC_Continue;
@@ -105534,10 +105690,11 @@
105534105690
renameTokenFind(pParse, pCtx, (void*)zName);
105535105691
}
105536105692
}
105537105693
}
105538105694
}
105695
+
105539105696
105540105697
/*
105541105698
** Parse the SQL statement zSql using Parse object (*p). The Parse object
105542105699
** is initialized by this function before it is used.
105543105700
*/
@@ -109619,10 +109776,11 @@
109619109776
int i;
109620109777
Column *pCol;
109621109778
assert( pTable!=0 );
109622109779
if( (pCol = pTable->aCol)!=0 ){
109623109780
for(i=0; i<pTable->nCol; i++, pCol++){
109781
+ assert( pCol->zName==0 || pCol->hName==sqlite3StrIHash(pCol->zName) );
109624109782
sqlite3DbFree(db, pCol->zName);
109625109783
sqlite3ExprDelete(db, pCol->pDflt);
109626109784
sqlite3DbFree(db, pCol->zColl);
109627109785
}
109628109786
sqlite3DbFree(db, pTable->aCol);
@@ -110267,10 +110425,11 @@
110267110425
p->aCol = aNew;
110268110426
}
110269110427
pCol = &p->aCol[p->nCol];
110270110428
memset(pCol, 0, sizeof(p->aCol[0]));
110271110429
pCol->zName = z;
110430
+ pCol->hName = sqlite3StrIHash(z);
110272110431
sqlite3ColumnPropertiesFromName(p, pCol);
110273110432
110274110433
if( pType->n==0 ){
110275110434
/* If there is no type specified, columns have the default affinity
110276110435
** 'BLOB' with a default size of 4 bytes. */
@@ -129768,10 +129927,11 @@
129768129927
}
129769129928
zName = sqlite3MPrintf(db, "%.*z:%u", nName, zName, ++cnt);
129770129929
if( cnt>3 ) sqlite3_randomness(sizeof(cnt), &cnt);
129771129930
}
129772129931
pCol->zName = zName;
129932
+ pCol->hName = sqlite3StrIHash(zName);
129773129933
sqlite3ColumnPropertiesFromName(0, pCol);
129774129934
if( zName && sqlite3HashInsert(&ht, zName, pCol)==pCol ){
129775129935
sqlite3OomFault(db);
129776129936
}
129777129937
}
@@ -131221,11 +131381,14 @@
131221131381
if( ExprHasProperty(pExpr, EP_FromJoin)
131222131382
&& pExpr->iRightJoinTable==pSubst->iTable
131223131383
){
131224131384
pExpr->iRightJoinTable = pSubst->iNewTable;
131225131385
}
131226
- if( pExpr->op==TK_COLUMN && pExpr->iTable==pSubst->iTable ){
131386
+ if( pExpr->op==TK_COLUMN
131387
+ && pExpr->iTable==pSubst->iTable
131388
+ && !ExprHasProperty(pExpr, EP_FixedCol)
131389
+ ){
131227131390
if( pExpr->iColumn<0 ){
131228131391
pExpr->op = TK_NULL;
131229131392
}else{
131230131393
Expr *pNew;
131231131394
Expr *pCopy = pSubst->pEList->a[pExpr->iColumn].pExpr;
@@ -133133,10 +133296,11 @@
133133133296
Vdbe *v = pParse->pVdbe;
133134133297
int i;
133135133298
struct AggInfo_func *pFunc;
133136133299
int nReg = pAggInfo->nFunc + pAggInfo->nColumn;
133137133300
if( nReg==0 ) return;
133301
+ if( pParse->nErr ) return;
133138133302
#ifdef SQLITE_DEBUG
133139133303
/* Verify that all AggInfo registers are within the range specified by
133140133304
** AggInfo.mnReg..AggInfo.mxReg */
133141133305
assert( nReg==pAggInfo->mxReg-pAggInfo->mnReg+1 );
133142133306
for(i=0; i<pAggInfo->nColumn; i++){
@@ -156491,14 +156655,15 @@
156491156655
** simplify to constants 0 (false) and 1 (true), respectively,
156492156656
** regardless of the value of expr1.
156493156657
*/
156494156658
sqlite3ExprUnmapAndDelete(pParse, yymsp[-4].minor.yy202);
156495156659
yymsp[-4].minor.yy202 = sqlite3Expr(pParse->db, TK_INTEGER, yymsp[-3].minor.yy192 ? "1" : "0");
156496
- }else if( 0 && yymsp[-1].minor.yy242->nExpr==1 && sqlite3ExprIsConstant(yymsp[-1].minor.yy242->a[0].pExpr) ){
156660
+ }else if( yymsp[-1].minor.yy242->nExpr==1 && sqlite3ExprIsConstant(yymsp[-1].minor.yy242->a[0].pExpr) ){
156497156661
Expr *pRHS = yymsp[-1].minor.yy242->a[0].pExpr;
156498156662
yymsp[-1].minor.yy242->a[0].pExpr = 0;
156499156663
sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy242);
156664
+ pRHS = sqlite3PExpr(pParse, TK_UPLUS, pRHS, 0);
156500156665
yymsp[-4].minor.yy202 = sqlite3PExpr(pParse, TK_EQ, yymsp[-4].minor.yy202, pRHS);
156501156666
if( yymsp[-3].minor.yy192 ) yymsp[-4].minor.yy202 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy202, 0);
156502156667
}else{
156503156668
yymsp[-4].minor.yy202 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy202, 0);
156504156669
if( yymsp[-4].minor.yy202 ){
@@ -158376,11 +158541,11 @@
158376158541
VVA_ONLY( u8 startedWithOom = db->mallocFailed );
158377158542
158378158543
assert( zSql!=0 );
158379158544
mxSqlLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];
158380158545
if( db->nVdbeActive==0 ){
158381
- db->u1.isInterrupted = 0;
158546
+ AtomicStore(&db->u1.isInterrupted, 0);
158382158547
}
158383158548
pParse->rc = SQLITE_OK;
158384158549
pParse->zTail = zSql;
158385158550
assert( pzErrMsg!=0 );
158386158551
#ifdef SQLITE_DEBUG
@@ -158421,11 +158586,11 @@
158421158586
);
158422158587
#else
158423158588
if( tokenType>=TK_SPACE ){
158424158589
assert( tokenType==TK_SPACE || tokenType==TK_ILLEGAL );
158425158590
#endif /* SQLITE_OMIT_WINDOWFUNC */
158426
- if( db->u1.isInterrupted ){
158591
+ if( AtomicLoad(&db->u1.isInterrupted) ){
158427158592
pParse->rc = SQLITE_INTERRUPT;
158428158593
break;
158429158594
}
158430158595
if( tokenType==TK_SPACE ){
158431158596
zSql += n;
@@ -160632,13 +160797,25 @@
160632160797
int delay, prior;
160633160798
160634160799
#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
160635160800
if( sqlite3OsFileControl(pFile,SQLITE_FCNTL_LOCK_TIMEOUT,&tmout)==SQLITE_OK ){
160636160801
if( count ){
160637
- tmout = 0;
160638
- sqlite3OsFileControl(pFile, SQLITE_FCNTL_LOCK_TIMEOUT, &tmout);
160639
- return 0;
160802
+ /* If this is the second or later invocation of the busy-handler,
160803
+ ** but tmout==0, then code in wal.c must have disabled the blocking
160804
+ ** lock before the SQLITE_BUSY error was hit. In this case, no delay
160805
+ ** occurred while waiting for the lock, so fall through to the xSleep()
160806
+ ** code below to delay a while before retrying the lock.
160807
+ **
160808
+ ** Alternatively, if tmout!=0, then SQLite has already waited
160809
+ ** sqlite3.busyTimeout ms for a lock. In this case, return 0 to
160810
+ ** indicate that the lock should not be retried and the SQLITE_BUSY
160811
+ ** error returned to the application. */
160812
+ if( tmout ){
160813
+ tmout = 0;
160814
+ sqlite3OsFileControl(pFile, SQLITE_FCNTL_LOCK_TIMEOUT, &tmout);
160815
+ return 0;
160816
+ }
160640160817
}else{
160641160818
return 1;
160642160819
}
160643160820
}
160644160821
#else
@@ -160784,11 +160961,11 @@
160784160961
if( !sqlite3SafetyCheckOk(db) && (db==0 || db->magic!=SQLITE_MAGIC_ZOMBIE) ){
160785160962
(void)SQLITE_MISUSE_BKPT;
160786160963
return;
160787160964
}
160788160965
#endif
160789
- db->u1.isInterrupted = 1;
160966
+ AtomicStore(&db->u1.isInterrupted, 1);
160790160967
}
160791160968
160792160969
160793160970
/*
160794160971
** This function is exactly the same as sqlite3_create_function(), except
@@ -161406,11 +161583,11 @@
161406161583
rc = sqlite3ApiExit(db, rc);
161407161584
161408161585
/* If there are no active statements, clear the interrupt flag at this
161409161586
** point. */
161410161587
if( db->nVdbeActive==0 ){
161411
- db->u1.isInterrupted = 0;
161588
+ AtomicStore(&db->u1.isInterrupted, 0);
161412161589
}
161413161590
161414161591
sqlite3_mutex_leave(db->mutex);
161415161592
return rc;
161416161593
#endif
@@ -176558,10 +176735,11 @@
176558176735
** b-tree node. And that the final byte of the doclist is 0x00. If either
176559176736
** of these statements is untrue, then the data structure is corrupt.
176560176737
*/
176561176738
if( pReader->nDoclist > pReader->nNode-(pReader->aDoclist-pReader->aNode)
176562176739
|| (pReader->nPopulate==0 && pReader->aDoclist[pReader->nDoclist-1])
176740
+ || pReader->nDoclist==0
176563176741
){
176564176742
return FTS_CORRUPT_VTAB;
176565176743
}
176566176744
return SQLITE_OK;
176567176745
}
@@ -223728,11 +223906,11 @@
223728223906
int nArg, /* Number of args */
223729223907
sqlite3_value **apUnused /* Function arguments */
223730223908
){
223731223909
assert( nArg==0 );
223732223910
UNUSED_PARAM2(nArg, apUnused);
223733
- sqlite3_result_text(pCtx, "fts5: 2020-03-21 23:10:38 5d14a1c4f2fc17de98ad685ad1422cdfda89dfccb00afcaf32ee416b6f84f525", -1, SQLITE_TRANSIENT);
223911
+ sqlite3_result_text(pCtx, "fts5: 2020-04-18 14:12:00 d5b0def96ba6d90f47bc96fab1ccf9c501d84885d086744035b16fd96f3e248c", -1, SQLITE_TRANSIENT);
223734223912
}
223735223913
223736223914
/*
223737223915
** Return true if zName is the extension on one of the shadow tables used
223738223916
** by this module.
@@ -228510,12 +228688,12 @@
228510228688
}
228511228689
#endif /* SQLITE_CORE */
228512228690
#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
228513228691
228514228692
/************** End of stmt.c ************************************************/
228515
-#if __LINE__!=228515
228693
+#if __LINE__!=228693
228516228694
#undef SQLITE_SOURCE_ID
228517
-#define SQLITE_SOURCE_ID "2020-03-21 23:10:38 5d14a1c4f2fc17de98ad685ad1422cdfda89dfccb00afcaf32ee416b6f84alt2"
228695
+#define SQLITE_SOURCE_ID "2020-04-18 14:12:00 d5b0def96ba6d90f47bc96fab1ccf9c501d84885d086744035b16fd96f3ealt2"
228518228696
#endif
228519228697
/* Return the source-id for this library */
228520228698
SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
228521228699
/************************** End of sqlite3.c ******************************/
228522228700
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1162,11 +1162,11 @@
1162 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
1163 ** [sqlite_version()] and [sqlite_source_id()].
1164 */
1165 #define SQLITE_VERSION "3.32.0"
1166 #define SQLITE_VERSION_NUMBER 3032000
1167 #define SQLITE_SOURCE_ID "2020-03-21 23:10:38 5d14a1c4f2fc17de98ad685ad1422cdfda89dfccb00afcaf32ee416b6f84f525"
1168
1169 /*
1170 ** CAPI3REF: Run-Time Library Version Numbers
1171 ** KEYWORDS: sqlite3_version sqlite3_sourceid
1172 **
@@ -2124,14 +2124,16 @@
2124 ** so that all subsequent write operations are independent.
2125 ** ^SQLite will never invoke SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE without
2126 ** a prior successful call to [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE].
2127 **
2128 ** <li>[[SQLITE_FCNTL_LOCK_TIMEOUT]]
2129 ** The [SQLITE_FCNTL_LOCK_TIMEOUT] opcode causes attempts to obtain
2130 ** a file lock using the xLock or xShmLock methods of the VFS to wait
2131 ** for up to M milliseconds before failing, where M is the single
2132 ** unsigned integer parameter.
 
 
2133 **
2134 ** <li>[[SQLITE_FCNTL_DATA_VERSION]]
2135 ** The [SQLITE_FCNTL_DATA_VERSION] opcode is used to detect changes to
2136 ** a database file. The argument is a pointer to a 32-bit unsigned integer.
2137 ** The "data version" for the pager is written into the pointer. The
@@ -5295,10 +5297,28 @@
5295 **
5296 ** ^The third argument is the value to bind to the parameter.
5297 ** ^If the third parameter to sqlite3_bind_text() or sqlite3_bind_text16()
5298 ** or sqlite3_bind_blob() is a NULL pointer then the fourth parameter
5299 ** is ignored and the end result is the same as sqlite3_bind_null().
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5300 **
5301 ** ^(In those routines that have a fourth argument, its value is the
5302 ** number of bytes in the parameter. To be clear: the value is the
5303 ** number of <u>bytes</u> in the value, not the number of characters.)^
5304 ** ^If the fourth parameter to sqlite3_bind_text() or sqlite3_bind_text16()
@@ -5308,11 +5328,11 @@
5308 ** the behavior is undefined.
5309 ** If a non-negative fourth parameter is provided to sqlite3_bind_text()
5310 ** or sqlite3_bind_text16() or sqlite3_bind_text64() then
5311 ** that parameter must be the byte offset
5312 ** where the NUL terminator would occur assuming the string were NUL
5313 ** terminated. If any NUL characters occur at byte offsets less than
5314 ** the value of the fourth parameter then the resulting string value will
5315 ** contain embedded NULs. The result of expressions involving strings
5316 ** with embedded NULs is undefined.
5317 **
5318 ** ^The fifth argument to the BLOB and string binding interfaces
@@ -6633,12 +6653,13 @@
6633 ** cause the implemented SQL function to throw an exception.
6634 ** ^SQLite uses the string pointed to by the
6635 ** 2nd parameter of sqlite3_result_error() or sqlite3_result_error16()
6636 ** as the text of an error message. ^SQLite interprets the error
6637 ** message string from sqlite3_result_error() as UTF-8. ^SQLite
6638 ** interprets the string from sqlite3_result_error16() as UTF-16 in native
6639 ** byte order. ^If the third parameter to sqlite3_result_error()
 
6640 ** or sqlite3_result_error16() is negative then SQLite takes as the error
6641 ** message all text up through the first zero character.
6642 ** ^If the third parameter to sqlite3_result_error() or
6643 ** sqlite3_result_error16() is non-negative then SQLite takes that many
6644 ** bytes (not characters) from the 2nd parameter as the error message.
@@ -6701,10 +6722,29 @@
6701 ** when it has finished using that result.
6702 ** ^If the 4th parameter to the sqlite3_result_text* interfaces
6703 ** or sqlite3_result_blob is the special constant SQLITE_TRANSIENT
6704 ** then SQLite makes a copy of the result into space obtained
6705 ** from [sqlite3_malloc()] before it returns.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6706 **
6707 ** ^The sqlite3_result_value() interface sets the result of
6708 ** the application-defined function to be a copy of the
6709 ** [unprotected sqlite3_value] object specified by the 2nd parameter. ^The
6710 ** sqlite3_result_value() interface makes a copy of the [sqlite3_value]
@@ -13369,10 +13409,25 @@
13369 #pragma warn -aus /* Assigned value is never used */
13370 #pragma warn -csu /* Comparing signed and unsigned */
13371 #pragma warn -spa /* Suspicious pointer arithmetic */
13372 #endif
13373
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13374 /*
13375 ** Include standard header files as necessary
13376 */
13377 #ifdef HAVE_STDINT_H
13378 #include <stdint.h>
@@ -17209,10 +17264,11 @@
17209 Expr *pDflt; /* Default value or GENERATED ALWAYS AS value */
17210 char *zColl; /* Collating sequence. If NULL, use the default */
17211 u8 notNull; /* An OE_ code for handling a NOT NULL constraint */
17212 char affinity; /* One of the SQLITE_AFF_... values */
17213 u8 szEst; /* Estimated size of value in this column. sizeof(INT)==1 */
 
17214 u16 colFlags; /* Boolean properties. See COLFLAG_ defines below */
17215 };
17216
17217 /* Allowed values for Column.colFlags:
17218 */
@@ -19827,10 +19883,11 @@
19827 const char*,
19828 const char*,
19829 const char*
19830 );
19831 SQLITE_PRIVATE Bitmask sqlite3ExprColUsed(Expr*);
 
19832 SQLITE_PRIVATE int sqlite3ResolveExprNames(NameContext*, Expr*);
19833 SQLITE_PRIVATE int sqlite3ResolveExprListNames(NameContext*, ExprList*);
19834 SQLITE_PRIVATE void sqlite3ResolveSelectNames(Parse*, Select*, NameContext*);
19835 SQLITE_PRIVATE int sqlite3ResolveSelfReference(Parse*,Table*,int,Expr*,ExprList*);
19836 SQLITE_PRIVATE int sqlite3ResolveOrderGroupBy(Parse*, Select*, ExprList*, const char*);
@@ -22165,16 +22222,16 @@
22165 u8 nName; /* Length of th name */
22166 char *zName; /* Name of the transformation */
22167 double rLimit; /* Maximum NNN value for this transform */
22168 double rXform; /* Constant used for this transform */
22169 } aXformType[] = {
22170 { 0, 6, "second", 464269060800.0, 86400000.0/(24.0*60.0*60.0) },
22171 { 0, 6, "minute", 7737817680.0, 86400000.0/(24.0*60.0) },
22172 { 0, 4, "hour", 128963628.0, 86400000.0/24.0 },
22173 { 0, 3, "day", 5373485.0, 86400000.0 },
22174 { 1, 5, "month", 176546.0, 30.0*86400000.0 },
22175 { 2, 4, "year", 14713.0, 365.0*86400000.0 },
22176 };
22177
22178 /*
22179 ** Process a modifier to a date-time stamp. The modifiers are
22180 ** as follows:
@@ -27907,11 +27964,11 @@
27907 */
27908 SQLITE_PRIVATE void sqlite3OomFault(sqlite3 *db){
27909 if( db->mallocFailed==0 && db->bBenignMalloc==0 ){
27910 db->mallocFailed = 1;
27911 if( db->nVdbeExec>0 ){
27912 db->u1.isInterrupted = 1;
27913 }
27914 DisableLookaside;
27915 if( db->pParse ){
27916 db->pParse->rc = SQLITE_NOMEM_BKPT;
27917 }
@@ -27926,11 +27983,11 @@
27926 ** VDBEs.
27927 */
27928 SQLITE_PRIVATE void sqlite3OomClear(sqlite3 *db){
27929 if( db->mallocFailed && db->nVdbeExec==0 ){
27930 db->mallocFailed = 0;
27931 db->u1.isInterrupted = 0;
27932 assert( db->lookaside.bDisable>0 );
27933 EnableLookaside;
27934 }
27935 }
27936
@@ -31300,10 +31357,23 @@
31300 a = (unsigned char *)zLeft;
31301 b = (unsigned char *)zRight;
31302 while( N-- > 0 && *a!=0 && UpperToLower[*a]==UpperToLower[*b]){ a++; b++; }
31303 return N<0 ? 0 : UpperToLower[*a] - UpperToLower[*b];
31304 }
 
 
 
 
 
 
 
 
 
 
 
 
 
31305
31306 /*
31307 ** Compute 10 to the E-th power. Examples: E==1 results in 10.
31308 ** E==2 results in 100. E==50 results in 1.0e50.
31309 **
@@ -37287,11 +37357,13 @@
37287 *(int*)pArg = fileHasMoved(pFile);
37288 return SQLITE_OK;
37289 }
37290 #ifdef SQLITE_ENABLE_SETLK_TIMEOUT
37291 case SQLITE_FCNTL_LOCK_TIMEOUT: {
 
37292 pFile->iBusyTimeout = *(int*)pArg;
 
37293 return SQLITE_OK;
37294 }
37295 #endif
37296 #if SQLITE_MAX_MMAP_SIZE>0
37297 case SQLITE_FCNTL_MMAP_SIZE: {
@@ -38108,10 +38180,28 @@
38108 || flags==(SQLITE_SHM_UNLOCK | SQLITE_SHM_SHARED)
38109 || flags==(SQLITE_SHM_UNLOCK | SQLITE_SHM_EXCLUSIVE) );
38110 assert( n==1 || (flags & SQLITE_SHM_EXCLUSIVE)!=0 );
38111 assert( pShmNode->hShm>=0 || pDbFd->pInode->bProcessLock==1 );
38112 assert( pShmNode->hShm<0 || pDbFd->pInode->bProcessLock==0 );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38113
38114 mask = (1<<(ofst+n)) - (1<<ofst);
38115 assert( n>1 || mask==(1<<ofst) );
38116 sqlite3_mutex_enter(pShmNode->pShmMutex);
38117 if( flags & SQLITE_SHM_UNLOCK ){
@@ -59322,22 +59412,10 @@
59322 # define WALTRACE(X) if(sqlite3WalTrace) sqlite3DebugPrintf X
59323 #else
59324 # define WALTRACE(X)
59325 #endif
59326
59327 /*
59328 ** WAL mode depends on atomic aligned 32-bit loads and stores in a few
59329 ** places. The following macros try to make this explicit.
59330 */
59331 #if GCC_VESRION>=5004000
59332 # define AtomicLoad(PTR) __atomic_load_n((PTR),__ATOMIC_RELAXED)
59333 # define AtomicStore(PTR,VAL) __atomic_store_n((PTR),(VAL),__ATOMIC_RELAXED)
59334 #else
59335 # define AtomicLoad(PTR) (*(PTR))
59336 # define AtomicStore(PTR,VAL) (*(PTR) = (VAL))
59337 #endif
59338
59339 /*
59340 ** The maximum (and only) versions of the wal and wal-index formats
59341 ** that may be interpreted by this version of SQLite.
59342 **
59343 ** If a client begins recovering a WAL file and finds that (a) the checksum
@@ -60203,10 +60281,15 @@
60203 static int walIndexRecover(Wal *pWal){
60204 int rc; /* Return Code */
60205 i64 nSize; /* Size of log file */
60206 u32 aFrameCksum[2] = {0, 0};
60207 int iLock; /* Lock offset to lock for checkpoint */
 
 
 
 
 
60208
60209 /* Obtain an exclusive lock on all byte in the locking range not already
60210 ** locked by the caller. The caller is guaranteed to have locked the
60211 ** WAL_WRITE_LOCK byte, and may have also locked the WAL_CKPT_LOCK byte.
60212 ** If successful, the same bytes that are locked here are unlocked before
@@ -60950,11 +61033,11 @@
60950
60951 /* Iterate through the contents of the WAL, copying data to the db file */
60952 while( rc==SQLITE_OK && 0==walIteratorNext(pIter, &iDbpage, &iFrame) ){
60953 i64 iOffset;
60954 assert( walFramePgno(pWal, iFrame)==iDbpage );
60955 if( db->u1.isInterrupted ){
60956 rc = db->mallocFailed ? SQLITE_NOMEM_BKPT : SQLITE_INTERRUPT;
60957 break;
60958 }
60959 if( iFrame<=nBackfill || iFrame>mxSafeFrame || iDbpage>mxPage ){
60960 continue;
@@ -61663,11 +61746,12 @@
61663 && (mxReadMark<mxFrame || mxI==0)
61664 ){
61665 for(i=1; i<WAL_NREADER; i++){
61666 rc = walLockExclusive(pWal, WAL_READ_LOCK(i), 1);
61667 if( rc==SQLITE_OK ){
61668 mxReadMark = AtomicStore(pInfo->aReadMark+i,mxFrame);
 
61669 mxI = i;
61670 walUnlockExclusive(pWal, WAL_READ_LOCK(i), 1);
61671 break;
61672 }else if( rc!=SQLITE_BUSY ){
61673 return rc;
@@ -61822,26 +61906,45 @@
61822 ** needs to be flushed.
61823 */
61824 SQLITE_PRIVATE int sqlite3WalBeginReadTransaction(Wal *pWal, int *pChanged){
61825 int rc; /* Return code */
61826 int cnt = 0; /* Number of TryBeginRead attempts */
 
 
 
61827
61828 #ifdef SQLITE_ENABLE_SNAPSHOT
61829 int bChanged = 0;
61830 WalIndexHdr *pSnapshot = pWal->pSnapshot;
61831 if( pSnapshot && memcmp(pSnapshot, &pWal->hdr, sizeof(WalIndexHdr))!=0 ){
61832 bChanged = 1;
61833 }
61834 #endif
61835
 
 
 
 
 
 
61836 do{
61837 rc = walTryBeginRead(pWal, pChanged, 0, ++cnt);
61838 }while( rc==WAL_RETRY );
61839 testcase( (rc&0xff)==SQLITE_BUSY );
61840 testcase( (rc&0xff)==SQLITE_IOERR );
61841 testcase( rc==SQLITE_PROTOCOL );
61842 testcase( rc==SQLITE_OK );
 
 
 
 
 
 
 
 
 
 
61843
61844 #ifdef SQLITE_ENABLE_SNAPSHOT
61845 if( rc==SQLITE_OK ){
61846 if( pSnapshot && memcmp(pSnapshot, &pWal->hdr, sizeof(WalIndexHdr))!=0 ){
61847 /* At this point the client has a lock on an aReadMark[] slot holding
@@ -73477,11 +73580,11 @@
73477 }
73478
73479 /* Unless an error occurs, the following loop runs one iteration for each
73480 ** page in the B-Tree structure (not including overflow pages).
73481 */
73482 while( rc==SQLITE_OK && !db->u1.isInterrupted ){
73483 int iIdx; /* Index of child node in parent */
73484 MemPage *pPage; /* Current page of the b-tree */
73485
73486 /* If this is a leaf page or the tree is not an int-key tree, then
73487 ** this page contains countable entries. Increment the entry counter
@@ -73603,11 +73706,11 @@
73603 }
73604 if( getPageReferenced(pCheck, iPage) ){
73605 checkAppendMsg(pCheck, "2nd reference to page %d", iPage);
73606 return 1;
73607 }
73608 if( pCheck->db->u1.isInterrupted ) return 1;
73609 setPageReferenced(pCheck, iPage);
73610 return 0;
73611 }
73612
73613 #ifndef SQLITE_OMIT_AUTOVACUUM
@@ -79233,11 +79336,11 @@
79233 if( pOp->opcode==OP_Explain ) break;
79234 if( pOp->opcode==OP_Init && p->pc>1 ) break;
79235 }
79236
79237 if( rc==SQLITE_OK ){
79238 if( db->u1.isInterrupted ){
79239 p->rc = SQLITE_INTERRUPT;
79240 rc = SQLITE_ERROR;
79241 sqlite3VdbeError(p, sqlite3ErrStr(p->rc));
79242 }else{
79243 char *zP4;
@@ -83028,11 +83131,11 @@
83028 /* If there are no other statements currently running, then
83029 ** reset the interrupt flag. This prevents a call to sqlite3_interrupt
83030 ** from interrupting a statement that has not yet started.
83031 */
83032 if( db->nVdbeActive==0 ){
83033 db->u1.isInterrupted = 0;
83034 }
83035
83036 assert( db->nVdbeWrite>0 || db->autoCommit==0
83037 || (db->nDeferredCons==0 && db->nDeferredImmCons==0)
83038 );
@@ -85413,11 +85516,11 @@
85413 assert( p->bIsReader || p->readOnly!=0 );
85414 p->iCurrentTime = 0;
85415 assert( p->explain==0 );
85416 p->pResultSet = 0;
85417 db->busyHandler.nBusy = 0;
85418 if( db->u1.isInterrupted ) goto abort_due_to_interrupt;
85419 sqlite3VdbeIOTraceSql(p);
85420 #ifdef SQLITE_DEBUG
85421 sqlite3BeginBenignMalloc();
85422 if( p->pc==0
85423 && (p->db->flags & (SQLITE_VdbeListing|SQLITE_VdbeEQP|SQLITE_VdbeTrace))!=0
@@ -85597,11 +85700,11 @@
85597 ** But that is not due to sloppy coding habits. The code is written this
85598 ** way for performance, to avoid having to run the interrupt and progress
85599 ** checks on every opcode. This helps sqlite3_step() to run about 1.5%
85600 ** faster according to "valgrind --tool=cachegrind" */
85601 check_for_interrupt:
85602 if( db->u1.isInterrupted ) goto abort_due_to_interrupt;
85603 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
85604 /* Call the progress callback if it is configured and the required number
85605 ** of VDBE ops have been executed (either since this invocation of
85606 ** sqlite3VdbeExec() or since last time the progress callback was called).
85607 ** If the progress callback returns non-zero, exit the virtual machine with
@@ -92705,11 +92808,11 @@
92705
92706 /* Jump to here if the sqlite3_interrupt() API sets the interrupt
92707 ** flag.
92708 */
92709 abort_due_to_interrupt:
92710 assert( db->u1.isInterrupted );
92711 rc = db->mallocFailed ? SQLITE_NOMEM_BKPT : SQLITE_INTERRUPT;
92712 p->rc = rc;
92713 sqlite3VdbeError(p, "%s", sqlite3ErrStr(rc));
92714 goto abort_due_to_error;
92715 }
@@ -96775,11 +96878,11 @@
96775 const char *zTab,
96776 const char *zDb
96777 ){
96778 int n;
96779 const char *zSpan;
96780 if( NEVER(pItem->eEName!=ENAME_TAB) ) return 0;
96781 zSpan = pItem->zEName;
96782 for(n=0; ALWAYS(zSpan[n]) && zSpan[n]!='.'; n++){}
96783 if( zDb && (sqlite3StrNICmp(zSpan, zDb, n)!=0 || zDb[n]!=0) ){
96784 return 0;
96785 }
@@ -96929,10 +97032,11 @@
96929 ExprList *pEList;
96930 SrcList *pSrcList = pNC->pSrcList;
96931
96932 if( pSrcList ){
96933 for(i=0, pItem=pSrcList->a; i<pSrcList->nSrc; i++, pItem++){
 
96934 pTab = pItem->pTab;
96935 assert( pTab!=0 && pTab->zName!=0 );
96936 assert( pTab->nCol>0 );
96937 if( pItem->pSelect && (pItem->pSelect->selFlags & SF_NestedFrom)!=0 ){
96938 int hit = 0;
@@ -96962,12 +97066,13 @@
96962 }
96963 }
96964 if( 0==(cntTab++) ){
96965 pMatch = pItem;
96966 }
 
96967 for(j=0, pCol=pTab->aCol; j<pTab->nCol; j++, pCol++){
96968 if( sqlite3StrICmp(pCol->zName, zCol)==0 ){
96969 /* If there has been exactly one prior match and this match
96970 ** is for the right-hand table of a NATURAL JOIN or is in a
96971 ** USING clause, then skip this match.
96972 */
96973 if( cnt==1 ){
@@ -97024,14 +97129,15 @@
97024 }
97025 #endif /* SQLITE_OMIT_UPSERT */
97026
97027 if( pTab ){
97028 int iCol;
 
97029 pSchema = pTab->pSchema;
97030 cntTab++;
97031 for(iCol=0, pCol=pTab->aCol; iCol<pTab->nCol; iCol++, pCol++){
97032 if( sqlite3StrICmp(pCol->zName, zCol)==0 ){
97033 if( iCol==pTab->iPKey ){
97034 iCol = -1;
97035 }
97036 break;
97037 }
@@ -97828,11 +97934,11 @@
97828 nc.uNC.pEList = pEList;
97829 nc.ncFlags = NC_AllowAgg|NC_UEList;
97830 nc.nErr = 0;
97831 db = pParse->db;
97832 savedSuppErr = db->suppressErr;
97833 db->suppressErr = 1;
97834 rc = sqlite3ResolveExprNames(&nc, pE);
97835 db->suppressErr = savedSuppErr;
97836 if( rc ) return 0;
97837
97838 /* Try to match the ORDER BY expression against an expression
@@ -98463,15 +98569,45 @@
98463 SQLITE_PRIVATE int sqlite3ResolveExprListNames(
98464 NameContext *pNC, /* Namespace to resolve expressions in. */
98465 ExprList *pList /* The expression list to be analyzed. */
98466 ){
98467 int i;
98468 if( pList ){
98469 for(i=0; i<pList->nExpr; i++){
98470 if( sqlite3ResolveExprNames(pNC, pList->a[i].pExpr) ) return WRC_Abort;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
98471 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
98472 }
 
98473 return WRC_Continue;
98474 }
98475
98476 /*
98477 ** Resolve all names in all expressions of a SELECT and in all
@@ -100343,20 +100479,26 @@
100343 ExprList *pList, /* List to which to add the span. */
100344 Token *pName, /* Name to be added */
100345 int dequote /* True to cause the name to be dequoted */
100346 ){
100347 assert( pList!=0 || pParse->db->mallocFailed!=0 );
 
100348 if( pList ){
100349 struct ExprList_item *pItem;
100350 assert( pList->nExpr>0 );
100351 pItem = &pList->a[pList->nExpr-1];
100352 assert( pItem->zEName==0 );
100353 assert( pItem->eEName==ENAME_NAME );
100354 pItem->zEName = sqlite3DbStrNDup(pParse->db, pName->z, pName->n);
100355 if( dequote ) sqlite3Dequote(pItem->zEName);
100356 if( IN_RENAME_OBJECT ){
100357 sqlite3RenameTokenMap(pParse, (void*)pItem->zEName, pName);
 
 
 
 
 
100358 }
100359 }
100360 }
100361
100362 /*
@@ -101497,10 +101639,12 @@
101497 struct ExprList_item *pItem;
101498 int r1, r2;
101499 affinity = sqlite3ExprAffinity(pLeft);
101500 if( affinity<=SQLITE_AFF_NONE ){
101501 affinity = SQLITE_AFF_BLOB;
 
 
101502 }
101503 if( pKeyInfo ){
101504 assert( sqlite3KeyInfoIsWriteable(pKeyInfo) );
101505 pKeyInfo->aColl[0] = sqlite3ExprCollSeq(pParse, pExpr->pLeft);
101506 }
@@ -101735,10 +101879,11 @@
101735 int destStep6 = 0; /* Start of code for Step 6 */
101736 int addrTruthOp; /* Address of opcode that determines the IN is true */
101737 int destNotNull; /* Jump here if a comparison is not true in step 6 */
101738 int addrTop; /* Top of the step-6 loop */
101739 int iTab = 0; /* Index to use */
 
101740
101741 assert( !ExprHasVVAProperty(pExpr,EP_Immutable) );
101742 pLeft = pExpr->pLeft;
101743 if( sqlite3ExprCheckIN(pParse, pExpr) ) return;
101744 zAff = exprINAffinity(pParse, pExpr);
@@ -101779,12 +101924,18 @@
101779 **
101780 ** sqlite3FindInIndex() might have reordered the fields of the LHS vector
101781 ** so that the fields are in the same order as an existing index. The
101782 ** aiMap[] array contains a mapping from the original LHS field order to
101783 ** the field order that matches the RHS index.
101784 */
 
 
 
 
 
101785 rLhsOrig = exprCodeVector(pParse, pLeft, &iDummy);
 
101786 for(i=0; i<nVector && aiMap[i]==i; i++){} /* Are LHS fields reordered? */
101787 if( i==nVector ){
101788 /* LHS fields are not reordered */
101789 rLhs = rLhsOrig;
101790 }else{
@@ -101806,25 +101957,17 @@
101806 CollSeq *pColl = sqlite3ExprCollSeq(pParse, pExpr->pLeft);
101807 int labelOk = sqlite3VdbeMakeLabel(pParse);
101808 int r2, regToFree;
101809 int regCkNull = 0;
101810 int ii;
101811 int bLhsReal; /* True if the LHS of the IN has REAL affinity */
101812 assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
101813 if( destIfNull!=destIfFalse ){
101814 regCkNull = sqlite3GetTempReg(pParse);
101815 sqlite3VdbeAddOp3(v, OP_BitAnd, rLhs, rLhs, regCkNull);
101816 }
101817 bLhsReal = sqlite3ExprAffinity(pExpr->pLeft)==SQLITE_AFF_REAL;
101818 for(ii=0; ii<pList->nExpr; ii++){
101819 if( bLhsReal ){
101820 r2 = regToFree = sqlite3GetTempReg(pParse);
101821 sqlite3ExprCode(pParse, pList->a[ii].pExpr, r2);
101822 sqlite3VdbeAddOp4(v, OP_Affinity, r2, 1, 0, "E", P4_STATIC);
101823 }else{
101824 r2 = sqlite3ExprCodeTemp(pParse, pList->a[ii].pExpr, &regToFree);
101825 }
101826 if( regCkNull && sqlite3ExprCanBeNull(pList->a[ii].pExpr) ){
101827 sqlite3VdbeAddOp3(v, OP_BitAnd, regCkNull, r2, regCkNull);
101828 }
101829 sqlite3ReleaseTempReg(pParse, regToFree);
101830 if( ii<pList->nExpr-1 || destIfNull!=destIfFalse ){
@@ -102394,14 +102537,10 @@
102394 }
102395 if( aff>SQLITE_AFF_BLOB ){
102396 static const char zAff[] = "B\000C\000D\000E";
102397 assert( SQLITE_AFF_BLOB=='A' );
102398 assert( SQLITE_AFF_TEXT=='B' );
102399 if( iReg!=target ){
102400 sqlite3VdbeAddOp2(v, OP_SCopy, iReg, target);
102401 iReg = target;
102402 }
102403 sqlite3VdbeAddOp4(v, OP_Affinity, iReg, 1, 0,
102404 &zAff[(aff-'B')*2], P4_STATIC);
102405 }
102406 return iReg;
102407 }
@@ -105020,10 +105159,11 @@
105020 }
105021 memcpy(pNew->aCol, pTab->aCol, sizeof(Column)*pNew->nCol);
105022 for(i=0; i<pNew->nCol; i++){
105023 Column *pCol = &pNew->aCol[i];
105024 pCol->zName = sqlite3DbStrDup(db, pCol->zName);
 
105025 pCol->zColl = 0;
105026 pCol->pDflt = 0;
105027 }
105028 pNew->pSchema = db->aDb[iDb].pSchema;
105029 pNew->addColOffset = pTab->addColOffset;
@@ -105248,11 +105388,11 @@
105248 */
105249 SQLITE_PRIVATE void *sqlite3RenameTokenMap(Parse *pParse, void *pPtr, Token *pToken){
105250 RenameToken *pNew;
105251 assert( pPtr || pParse->db->mallocFailed );
105252 renameTokenCheckAll(pParse, pPtr);
105253 if( pParse->eParseMode!=PARSE_MODE_UNMAP ){
105254 pNew = sqlite3DbMallocZero(pParse->db, sizeof(RenameToken));
105255 if( pNew ){
105256 pNew->p = pPtr;
105257 pNew->t = *pToken;
105258 pNew->pNext = pParse->pRename;
@@ -105305,10 +105445,25 @@
105305 sqlite3WalkSelect(pWalker, p);
105306 sqlite3RenameExprlistUnmap(pWalker->pParse, pWith->a[i].pCols);
105307 }
105308 }
105309 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105310
105311 /*
105312 ** Walker callback used by sqlite3RenameExprUnmap().
105313 */
105314 static int renameUnmapSelectCb(Walker *pWalker, Select *p){
@@ -105327,10 +105482,11 @@
105327 if( ALWAYS(p->pSrc) ){ /* Every Select as a SrcList, even if it is empty */
105328 SrcList *pSrc = p->pSrc;
105329 for(i=0; i<pSrc->nSrc; i++){
105330 sqlite3RenameTokenRemap(pParse, 0, (void*)pSrc->a[i].zName);
105331 if( sqlite3WalkExpr(pWalker, pSrc->a[i].pOn) ) return WRC_Abort;
 
105332 }
105333 }
105334
105335 renameWalkWith(pWalker, p);
105336 return WRC_Continue;
@@ -105534,10 +105690,11 @@
105534 renameTokenFind(pParse, pCtx, (void*)zName);
105535 }
105536 }
105537 }
105538 }
 
105539
105540 /*
105541 ** Parse the SQL statement zSql using Parse object (*p). The Parse object
105542 ** is initialized by this function before it is used.
105543 */
@@ -109619,10 +109776,11 @@
109619 int i;
109620 Column *pCol;
109621 assert( pTable!=0 );
109622 if( (pCol = pTable->aCol)!=0 ){
109623 for(i=0; i<pTable->nCol; i++, pCol++){
 
109624 sqlite3DbFree(db, pCol->zName);
109625 sqlite3ExprDelete(db, pCol->pDflt);
109626 sqlite3DbFree(db, pCol->zColl);
109627 }
109628 sqlite3DbFree(db, pTable->aCol);
@@ -110267,10 +110425,11 @@
110267 p->aCol = aNew;
110268 }
110269 pCol = &p->aCol[p->nCol];
110270 memset(pCol, 0, sizeof(p->aCol[0]));
110271 pCol->zName = z;
 
110272 sqlite3ColumnPropertiesFromName(p, pCol);
110273
110274 if( pType->n==0 ){
110275 /* If there is no type specified, columns have the default affinity
110276 ** 'BLOB' with a default size of 4 bytes. */
@@ -129768,10 +129927,11 @@
129768 }
129769 zName = sqlite3MPrintf(db, "%.*z:%u", nName, zName, ++cnt);
129770 if( cnt>3 ) sqlite3_randomness(sizeof(cnt), &cnt);
129771 }
129772 pCol->zName = zName;
 
129773 sqlite3ColumnPropertiesFromName(0, pCol);
129774 if( zName && sqlite3HashInsert(&ht, zName, pCol)==pCol ){
129775 sqlite3OomFault(db);
129776 }
129777 }
@@ -131221,11 +131381,14 @@
131221 if( ExprHasProperty(pExpr, EP_FromJoin)
131222 && pExpr->iRightJoinTable==pSubst->iTable
131223 ){
131224 pExpr->iRightJoinTable = pSubst->iNewTable;
131225 }
131226 if( pExpr->op==TK_COLUMN && pExpr->iTable==pSubst->iTable ){
 
 
 
131227 if( pExpr->iColumn<0 ){
131228 pExpr->op = TK_NULL;
131229 }else{
131230 Expr *pNew;
131231 Expr *pCopy = pSubst->pEList->a[pExpr->iColumn].pExpr;
@@ -133133,10 +133296,11 @@
133133 Vdbe *v = pParse->pVdbe;
133134 int i;
133135 struct AggInfo_func *pFunc;
133136 int nReg = pAggInfo->nFunc + pAggInfo->nColumn;
133137 if( nReg==0 ) return;
 
133138 #ifdef SQLITE_DEBUG
133139 /* Verify that all AggInfo registers are within the range specified by
133140 ** AggInfo.mnReg..AggInfo.mxReg */
133141 assert( nReg==pAggInfo->mxReg-pAggInfo->mnReg+1 );
133142 for(i=0; i<pAggInfo->nColumn; i++){
@@ -156491,14 +156655,15 @@
156491 ** simplify to constants 0 (false) and 1 (true), respectively,
156492 ** regardless of the value of expr1.
156493 */
156494 sqlite3ExprUnmapAndDelete(pParse, yymsp[-4].minor.yy202);
156495 yymsp[-4].minor.yy202 = sqlite3Expr(pParse->db, TK_INTEGER, yymsp[-3].minor.yy192 ? "1" : "0");
156496 }else if( 0 && yymsp[-1].minor.yy242->nExpr==1 && sqlite3ExprIsConstant(yymsp[-1].minor.yy242->a[0].pExpr) ){
156497 Expr *pRHS = yymsp[-1].minor.yy242->a[0].pExpr;
156498 yymsp[-1].minor.yy242->a[0].pExpr = 0;
156499 sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy242);
 
156500 yymsp[-4].minor.yy202 = sqlite3PExpr(pParse, TK_EQ, yymsp[-4].minor.yy202, pRHS);
156501 if( yymsp[-3].minor.yy192 ) yymsp[-4].minor.yy202 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy202, 0);
156502 }else{
156503 yymsp[-4].minor.yy202 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy202, 0);
156504 if( yymsp[-4].minor.yy202 ){
@@ -158376,11 +158541,11 @@
158376 VVA_ONLY( u8 startedWithOom = db->mallocFailed );
158377
158378 assert( zSql!=0 );
158379 mxSqlLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];
158380 if( db->nVdbeActive==0 ){
158381 db->u1.isInterrupted = 0;
158382 }
158383 pParse->rc = SQLITE_OK;
158384 pParse->zTail = zSql;
158385 assert( pzErrMsg!=0 );
158386 #ifdef SQLITE_DEBUG
@@ -158421,11 +158586,11 @@
158421 );
158422 #else
158423 if( tokenType>=TK_SPACE ){
158424 assert( tokenType==TK_SPACE || tokenType==TK_ILLEGAL );
158425 #endif /* SQLITE_OMIT_WINDOWFUNC */
158426 if( db->u1.isInterrupted ){
158427 pParse->rc = SQLITE_INTERRUPT;
158428 break;
158429 }
158430 if( tokenType==TK_SPACE ){
158431 zSql += n;
@@ -160632,13 +160797,25 @@
160632 int delay, prior;
160633
160634 #ifdef SQLITE_ENABLE_SETLK_TIMEOUT
160635 if( sqlite3OsFileControl(pFile,SQLITE_FCNTL_LOCK_TIMEOUT,&tmout)==SQLITE_OK ){
160636 if( count ){
160637 tmout = 0;
160638 sqlite3OsFileControl(pFile, SQLITE_FCNTL_LOCK_TIMEOUT, &tmout);
160639 return 0;
 
 
 
 
 
 
 
 
 
 
 
 
160640 }else{
160641 return 1;
160642 }
160643 }
160644 #else
@@ -160784,11 +160961,11 @@
160784 if( !sqlite3SafetyCheckOk(db) && (db==0 || db->magic!=SQLITE_MAGIC_ZOMBIE) ){
160785 (void)SQLITE_MISUSE_BKPT;
160786 return;
160787 }
160788 #endif
160789 db->u1.isInterrupted = 1;
160790 }
160791
160792
160793 /*
160794 ** This function is exactly the same as sqlite3_create_function(), except
@@ -161406,11 +161583,11 @@
161406 rc = sqlite3ApiExit(db, rc);
161407
161408 /* If there are no active statements, clear the interrupt flag at this
161409 ** point. */
161410 if( db->nVdbeActive==0 ){
161411 db->u1.isInterrupted = 0;
161412 }
161413
161414 sqlite3_mutex_leave(db->mutex);
161415 return rc;
161416 #endif
@@ -176558,10 +176735,11 @@
176558 ** b-tree node. And that the final byte of the doclist is 0x00. If either
176559 ** of these statements is untrue, then the data structure is corrupt.
176560 */
176561 if( pReader->nDoclist > pReader->nNode-(pReader->aDoclist-pReader->aNode)
176562 || (pReader->nPopulate==0 && pReader->aDoclist[pReader->nDoclist-1])
 
176563 ){
176564 return FTS_CORRUPT_VTAB;
176565 }
176566 return SQLITE_OK;
176567 }
@@ -223728,11 +223906,11 @@
223728 int nArg, /* Number of args */
223729 sqlite3_value **apUnused /* Function arguments */
223730 ){
223731 assert( nArg==0 );
223732 UNUSED_PARAM2(nArg, apUnused);
223733 sqlite3_result_text(pCtx, "fts5: 2020-03-21 23:10:38 5d14a1c4f2fc17de98ad685ad1422cdfda89dfccb00afcaf32ee416b6f84f525", -1, SQLITE_TRANSIENT);
223734 }
223735
223736 /*
223737 ** Return true if zName is the extension on one of the shadow tables used
223738 ** by this module.
@@ -228510,12 +228688,12 @@
228510 }
228511 #endif /* SQLITE_CORE */
228512 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
228513
228514 /************** End of stmt.c ************************************************/
228515 #if __LINE__!=228515
228516 #undef SQLITE_SOURCE_ID
228517 #define SQLITE_SOURCE_ID "2020-03-21 23:10:38 5d14a1c4f2fc17de98ad685ad1422cdfda89dfccb00afcaf32ee416b6f84alt2"
228518 #endif
228519 /* Return the source-id for this library */
228520 SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
228521 /************************** End of sqlite3.c ******************************/
228522
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1162,11 +1162,11 @@
1162 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
1163 ** [sqlite_version()] and [sqlite_source_id()].
1164 */
1165 #define SQLITE_VERSION "3.32.0"
1166 #define SQLITE_VERSION_NUMBER 3032000
1167 #define SQLITE_SOURCE_ID "2020-04-18 14:12:00 d5b0def96ba6d90f47bc96fab1ccf9c501d84885d086744035b16fd96f3e248c"
1168
1169 /*
1170 ** CAPI3REF: Run-Time Library Version Numbers
1171 ** KEYWORDS: sqlite3_version sqlite3_sourceid
1172 **
@@ -2124,14 +2124,16 @@
2124 ** so that all subsequent write operations are independent.
2125 ** ^SQLite will never invoke SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE without
2126 ** a prior successful call to [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE].
2127 **
2128 ** <li>[[SQLITE_FCNTL_LOCK_TIMEOUT]]
2129 ** The [SQLITE_FCNTL_LOCK_TIMEOUT] opcode is used to configure a VFS
2130 ** to block for up to M milliseconds before failing when attempting to
2131 ** obtain a file lock using the xLock or xShmLock methods of the VFS.
2132 ** The parameter is a pointer to a 32-bit signed integer that contains
2133 ** the value that M is to be set to. Before returning, the 32-bit signed
2134 ** integer is overwritten with the previous value of M.
2135 **
2136 ** <li>[[SQLITE_FCNTL_DATA_VERSION]]
2137 ** The [SQLITE_FCNTL_DATA_VERSION] opcode is used to detect changes to
2138 ** a database file. The argument is a pointer to a 32-bit unsigned integer.
2139 ** The "data version" for the pager is written into the pointer. The
@@ -5295,10 +5297,28 @@
5297 **
5298 ** ^The third argument is the value to bind to the parameter.
5299 ** ^If the third parameter to sqlite3_bind_text() or sqlite3_bind_text16()
5300 ** or sqlite3_bind_blob() is a NULL pointer then the fourth parameter
5301 ** is ignored and the end result is the same as sqlite3_bind_null().
5302 ** ^If the third parameter to sqlite3_bind_text() is not NULL, then
5303 ** it should be a pointer to well-formed UTF8 text.
5304 ** ^If the third parameter to sqlite3_bind_text16() is not NULL, then
5305 ** it should be a pointer to well-formed UTF16 text.
5306 ** ^If the third parameter to sqlite3_bind_text64() is not NULL, then
5307 ** it should be a pointer to a well-formed unicode string that is
5308 ** either UTF8 if the sixth parameter is SQLITE_UTF8, or UTF16
5309 ** otherwise.
5310 **
5311 ** [[byte-order determination rules]] ^The byte-order of
5312 ** UTF16 input text is determined by the byte-order mark (BOM, U+FEFF)
5313 ** found in first character, which is removed, or in the absence of a BOM
5314 ** the byte order is the native byte order of the host
5315 ** machine for sqlite3_bind_text16() or the byte order specified in
5316 ** the 6th parameter for sqlite3_bind_text64().)^
5317 ** ^If UTF16 input text contains invalid unicode
5318 ** characters, then SQLite might change those invalid characters
5319 ** into the unicode replacement character: U+FFFD.
5320 **
5321 ** ^(In those routines that have a fourth argument, its value is the
5322 ** number of bytes in the parameter. To be clear: the value is the
5323 ** number of <u>bytes</u> in the value, not the number of characters.)^
5324 ** ^If the fourth parameter to sqlite3_bind_text() or sqlite3_bind_text16()
@@ -5308,11 +5328,11 @@
5328 ** the behavior is undefined.
5329 ** If a non-negative fourth parameter is provided to sqlite3_bind_text()
5330 ** or sqlite3_bind_text16() or sqlite3_bind_text64() then
5331 ** that parameter must be the byte offset
5332 ** where the NUL terminator would occur assuming the string were NUL
5333 ** terminated. If any NUL characters occurs at byte offsets less than
5334 ** the value of the fourth parameter then the resulting string value will
5335 ** contain embedded NULs. The result of expressions involving strings
5336 ** with embedded NULs is undefined.
5337 **
5338 ** ^The fifth argument to the BLOB and string binding interfaces
@@ -6633,12 +6653,13 @@
6653 ** cause the implemented SQL function to throw an exception.
6654 ** ^SQLite uses the string pointed to by the
6655 ** 2nd parameter of sqlite3_result_error() or sqlite3_result_error16()
6656 ** as the text of an error message. ^SQLite interprets the error
6657 ** message string from sqlite3_result_error() as UTF-8. ^SQLite
6658 ** interprets the string from sqlite3_result_error16() as UTF-16 using
6659 ** the same [byte-order determination rules] as [sqlite3_bind_text16()].
6660 ** ^If the third parameter to sqlite3_result_error()
6661 ** or sqlite3_result_error16() is negative then SQLite takes as the error
6662 ** message all text up through the first zero character.
6663 ** ^If the third parameter to sqlite3_result_error() or
6664 ** sqlite3_result_error16() is non-negative then SQLite takes that many
6665 ** bytes (not characters) from the 2nd parameter as the error message.
@@ -6701,10 +6722,29 @@
6722 ** when it has finished using that result.
6723 ** ^If the 4th parameter to the sqlite3_result_text* interfaces
6724 ** or sqlite3_result_blob is the special constant SQLITE_TRANSIENT
6725 ** then SQLite makes a copy of the result into space obtained
6726 ** from [sqlite3_malloc()] before it returns.
6727 **
6728 ** ^For the sqlite3_result_text16(), sqlite3_result_text16le(), and
6729 ** sqlite3_result_text16be() routines, and for sqlite3_result_text64()
6730 ** when the encoding is not UTF8, if the input UTF16 begins with a
6731 ** byte-order mark (BOM, U+FEFF) then the BOM is removed from the
6732 ** string and the rest of the string is interpreted according to the
6733 ** byte-order specified by the BOM. ^The byte-order specified by
6734 ** the BOM at the beginning of the text overrides the byte-order
6735 ** specified by the interface procedure. ^So, for example, if
6736 ** sqlite3_result_text16le() is invoked with text that begins
6737 ** with bytes 0xfe, 0xff (a big-endian byte-order mark) then the
6738 ** first two bytes of input are skipped and the remaining input
6739 ** is interpreted as UTF16BE text.
6740 **
6741 ** ^For UTF16 input text to the sqlite3_result_text16(),
6742 ** sqlite3_result_text16be(), sqlite3_result_text16le(), and
6743 ** sqlite3_result_text64() routines, if the text contains invalid
6744 ** UTF16 characters, the invalid characters might be converted
6745 ** into the unicode replacement character, U+FFFD.
6746 **
6747 ** ^The sqlite3_result_value() interface sets the result of
6748 ** the application-defined function to be a copy of the
6749 ** [unprotected sqlite3_value] object specified by the 2nd parameter. ^The
6750 ** sqlite3_result_value() interface makes a copy of the [sqlite3_value]
@@ -13369,10 +13409,25 @@
13409 #pragma warn -aus /* Assigned value is never used */
13410 #pragma warn -csu /* Comparing signed and unsigned */
13411 #pragma warn -spa /* Suspicious pointer arithmetic */
13412 #endif
13413
13414 /*
13415 ** WAL mode depends on atomic aligned 32-bit loads and stores in a few
13416 ** places. The following macros try to make this explicit.
13417 */
13418 #ifndef __has_feature
13419 # define __has_feature(x) 0 /* compatibility with non-clang compilers */
13420 #endif
13421 #if GCC_VERSION>=4007000 || __has_feature(c_atomic)
13422 # define AtomicLoad(PTR) __atomic_load_n((PTR),__ATOMIC_RELAXED)
13423 # define AtomicStore(PTR,VAL) __atomic_store_n((PTR),(VAL),__ATOMIC_RELAXED)
13424 #else
13425 # define AtomicLoad(PTR) (*(PTR))
13426 # define AtomicStore(PTR,VAL) (*(PTR) = (VAL))
13427 #endif
13428
13429 /*
13430 ** Include standard header files as necessary
13431 */
13432 #ifdef HAVE_STDINT_H
13433 #include <stdint.h>
@@ -17209,10 +17264,11 @@
17264 Expr *pDflt; /* Default value or GENERATED ALWAYS AS value */
17265 char *zColl; /* Collating sequence. If NULL, use the default */
17266 u8 notNull; /* An OE_ code for handling a NOT NULL constraint */
17267 char affinity; /* One of the SQLITE_AFF_... values */
17268 u8 szEst; /* Estimated size of value in this column. sizeof(INT)==1 */
17269 u8 hName; /* Column name hash for faster lookup */
17270 u16 colFlags; /* Boolean properties. See COLFLAG_ defines below */
17271 };
17272
17273 /* Allowed values for Column.colFlags:
17274 */
@@ -19827,10 +19883,11 @@
19883 const char*,
19884 const char*,
19885 const char*
19886 );
19887 SQLITE_PRIVATE Bitmask sqlite3ExprColUsed(Expr*);
19888 SQLITE_PRIVATE u8 sqlite3StrIHash(const char*);
19889 SQLITE_PRIVATE int sqlite3ResolveExprNames(NameContext*, Expr*);
19890 SQLITE_PRIVATE int sqlite3ResolveExprListNames(NameContext*, ExprList*);
19891 SQLITE_PRIVATE void sqlite3ResolveSelectNames(Parse*, Select*, NameContext*);
19892 SQLITE_PRIVATE int sqlite3ResolveSelfReference(Parse*,Table*,int,Expr*,ExprList*);
19893 SQLITE_PRIVATE int sqlite3ResolveOrderGroupBy(Parse*, Select*, ExprList*, const char*);
@@ -22165,16 +22222,16 @@
22222 u8 nName; /* Length of th name */
22223 char *zName; /* Name of the transformation */
22224 double rLimit; /* Maximum NNN value for this transform */
22225 double rXform; /* Constant used for this transform */
22226 } aXformType[] = {
22227 { 0, 6, "second", 464269060800.0, 1000.0 },
22228 { 0, 6, "minute", 7737817680.0, 60000.0 },
22229 { 0, 4, "hour", 128963628.0, 3600000.0 },
22230 { 0, 3, "day", 5373485.0, 86400000.0 },
22231 { 1, 5, "month", 176546.0, 2592000000.0 },
22232 { 2, 4, "year", 14713.0, 31536000000.0 },
22233 };
22234
22235 /*
22236 ** Process a modifier to a date-time stamp. The modifiers are
22237 ** as follows:
@@ -27907,11 +27964,11 @@
27964 */
27965 SQLITE_PRIVATE void sqlite3OomFault(sqlite3 *db){
27966 if( db->mallocFailed==0 && db->bBenignMalloc==0 ){
27967 db->mallocFailed = 1;
27968 if( db->nVdbeExec>0 ){
27969 AtomicStore(&db->u1.isInterrupted, 1);
27970 }
27971 DisableLookaside;
27972 if( db->pParse ){
27973 db->pParse->rc = SQLITE_NOMEM_BKPT;
27974 }
@@ -27926,11 +27983,11 @@
27983 ** VDBEs.
27984 */
27985 SQLITE_PRIVATE void sqlite3OomClear(sqlite3 *db){
27986 if( db->mallocFailed && db->nVdbeExec==0 ){
27987 db->mallocFailed = 0;
27988 AtomicStore(&db->u1.isInterrupted, 0);
27989 assert( db->lookaside.bDisable>0 );
27990 EnableLookaside;
27991 }
27992 }
27993
@@ -31300,10 +31357,23 @@
31357 a = (unsigned char *)zLeft;
31358 b = (unsigned char *)zRight;
31359 while( N-- > 0 && *a!=0 && UpperToLower[*a]==UpperToLower[*b]){ a++; b++; }
31360 return N<0 ? 0 : UpperToLower[*a] - UpperToLower[*b];
31361 }
31362
31363 /*
31364 ** Compute an 8-bit hash on a string that is insensitive to case differences
31365 */
31366 SQLITE_PRIVATE u8 sqlite3StrIHash(const char *z){
31367 u8 h = 0;
31368 if( z==0 ) return 0;
31369 while( z[0] ){
31370 h += UpperToLower[(unsigned char)z[0]];
31371 z++;
31372 }
31373 return h;
31374 }
31375
31376 /*
31377 ** Compute 10 to the E-th power. Examples: E==1 results in 10.
31378 ** E==2 results in 100. E==50 results in 1.0e50.
31379 **
@@ -37287,11 +37357,13 @@
37357 *(int*)pArg = fileHasMoved(pFile);
37358 return SQLITE_OK;
37359 }
37360 #ifdef SQLITE_ENABLE_SETLK_TIMEOUT
37361 case SQLITE_FCNTL_LOCK_TIMEOUT: {
37362 int iOld = pFile->iBusyTimeout;
37363 pFile->iBusyTimeout = *(int*)pArg;
37364 *(int*)pArg = iOld;
37365 return SQLITE_OK;
37366 }
37367 #endif
37368 #if SQLITE_MAX_MMAP_SIZE>0
37369 case SQLITE_FCNTL_MMAP_SIZE: {
@@ -38108,10 +38180,28 @@
38180 || flags==(SQLITE_SHM_UNLOCK | SQLITE_SHM_SHARED)
38181 || flags==(SQLITE_SHM_UNLOCK | SQLITE_SHM_EXCLUSIVE) );
38182 assert( n==1 || (flags & SQLITE_SHM_EXCLUSIVE)!=0 );
38183 assert( pShmNode->hShm>=0 || pDbFd->pInode->bProcessLock==1 );
38184 assert( pShmNode->hShm<0 || pDbFd->pInode->bProcessLock==0 );
38185
38186 /* Check that, if this to be a blocking lock, that locks have been
38187 ** obtained in the following order.
38188 **
38189 ** 1. Checkpointer lock (ofst==1).
38190 ** 2. Recover lock (ofst==2).
38191 ** 3. Read locks (ofst>=3 && ofst<SQLITE_SHM_NLOCK).
38192 ** 4. Write lock (ofst==0).
38193 **
38194 ** In other words, if this is a blocking lock, none of the locks that
38195 ** occur later in the above list than the lock being obtained may be
38196 ** held. */
38197 #ifdef SQLITE_ENABLE_SETLK_TIMEOUT
38198 assert( pDbFd->iBusyTimeout==0
38199 || (flags & SQLITE_SHM_UNLOCK) || ofst==0
38200 || ((p->exclMask|p->sharedMask)&~((1<<ofst)-2))==0
38201 );
38202 #endif
38203
38204 mask = (1<<(ofst+n)) - (1<<ofst);
38205 assert( n>1 || mask==(1<<ofst) );
38206 sqlite3_mutex_enter(pShmNode->pShmMutex);
38207 if( flags & SQLITE_SHM_UNLOCK ){
@@ -59322,22 +59412,10 @@
59412 # define WALTRACE(X) if(sqlite3WalTrace) sqlite3DebugPrintf X
59413 #else
59414 # define WALTRACE(X)
59415 #endif
59416
 
 
 
 
 
 
 
 
 
 
 
 
59417 /*
59418 ** The maximum (and only) versions of the wal and wal-index formats
59419 ** that may be interpreted by this version of SQLite.
59420 **
59421 ** If a client begins recovering a WAL file and finds that (a) the checksum
@@ -60203,10 +60281,15 @@
60281 static int walIndexRecover(Wal *pWal){
60282 int rc; /* Return Code */
60283 i64 nSize; /* Size of log file */
60284 u32 aFrameCksum[2] = {0, 0};
60285 int iLock; /* Lock offset to lock for checkpoint */
60286
60287 #ifdef SQLITE_ENABLE_SETLK_TIMEOUT
60288 int tmout = 0;
60289 sqlite3OsFileControl(pWal->pDbFd, SQLITE_FCNTL_LOCK_TIMEOUT, (void*)&tmout);
60290 #endif
60291
60292 /* Obtain an exclusive lock on all byte in the locking range not already
60293 ** locked by the caller. The caller is guaranteed to have locked the
60294 ** WAL_WRITE_LOCK byte, and may have also locked the WAL_CKPT_LOCK byte.
60295 ** If successful, the same bytes that are locked here are unlocked before
@@ -60950,11 +61033,11 @@
61033
61034 /* Iterate through the contents of the WAL, copying data to the db file */
61035 while( rc==SQLITE_OK && 0==walIteratorNext(pIter, &iDbpage, &iFrame) ){
61036 i64 iOffset;
61037 assert( walFramePgno(pWal, iFrame)==iDbpage );
61038 if( AtomicLoad(&db->u1.isInterrupted) ){
61039 rc = db->mallocFailed ? SQLITE_NOMEM_BKPT : SQLITE_INTERRUPT;
61040 break;
61041 }
61042 if( iFrame<=nBackfill || iFrame>mxSafeFrame || iDbpage>mxPage ){
61043 continue;
@@ -61663,11 +61746,12 @@
61746 && (mxReadMark<mxFrame || mxI==0)
61747 ){
61748 for(i=1; i<WAL_NREADER; i++){
61749 rc = walLockExclusive(pWal, WAL_READ_LOCK(i), 1);
61750 if( rc==SQLITE_OK ){
61751 AtomicStore(pInfo->aReadMark+i,mxFrame);
61752 mxReadMark = mxFrame;
61753 mxI = i;
61754 walUnlockExclusive(pWal, WAL_READ_LOCK(i), 1);
61755 break;
61756 }else if( rc!=SQLITE_BUSY ){
61757 return rc;
@@ -61822,26 +61906,45 @@
61906 ** needs to be flushed.
61907 */
61908 SQLITE_PRIVATE int sqlite3WalBeginReadTransaction(Wal *pWal, int *pChanged){
61909 int rc; /* Return code */
61910 int cnt = 0; /* Number of TryBeginRead attempts */
61911 #ifdef SQLITE_ENABLE_SETLK_TIMEOUT
61912 int tmout = 0;
61913 #endif
61914
61915 #ifdef SQLITE_ENABLE_SNAPSHOT
61916 int bChanged = 0;
61917 WalIndexHdr *pSnapshot = pWal->pSnapshot;
61918 if( pSnapshot && memcmp(pSnapshot, &pWal->hdr, sizeof(WalIndexHdr))!=0 ){
61919 bChanged = 1;
61920 }
61921 #endif
61922
61923 #ifdef SQLITE_ENABLE_SETLK_TIMEOUT
61924 /* Disable blocking locks. They are not useful when trying to open a
61925 ** read-transaction, and blocking may cause deadlock anyway. */
61926 sqlite3OsFileControl(pWal->pDbFd, SQLITE_FCNTL_LOCK_TIMEOUT, (void*)&tmout);
61927 #endif
61928
61929 do{
61930 rc = walTryBeginRead(pWal, pChanged, 0, ++cnt);
61931 }while( rc==WAL_RETRY );
61932 testcase( (rc&0xff)==SQLITE_BUSY );
61933 testcase( (rc&0xff)==SQLITE_IOERR );
61934 testcase( rc==SQLITE_PROTOCOL );
61935 testcase( rc==SQLITE_OK );
61936
61937 #ifdef SQLITE_ENABLE_SETLK_TIMEOUT
61938 /* If they were disabled earlier and the read-transaction has been
61939 ** successfully opened, re-enable blocking locks. This is because the
61940 ** connection may attempt to upgrade to a write-transaction, which does
61941 ** benefit from using blocking locks. */
61942 if( rc==SQLITE_OK ){
61943 sqlite3OsFileControl(pWal->pDbFd, SQLITE_FCNTL_LOCK_TIMEOUT, (void*)&tmout);
61944 }
61945 #endif
61946
61947 #ifdef SQLITE_ENABLE_SNAPSHOT
61948 if( rc==SQLITE_OK ){
61949 if( pSnapshot && memcmp(pSnapshot, &pWal->hdr, sizeof(WalIndexHdr))!=0 ){
61950 /* At this point the client has a lock on an aReadMark[] slot holding
@@ -73477,11 +73580,11 @@
73580 }
73581
73582 /* Unless an error occurs, the following loop runs one iteration for each
73583 ** page in the B-Tree structure (not including overflow pages).
73584 */
73585 while( rc==SQLITE_OK && !AtomicLoad(&db->u1.isInterrupted) ){
73586 int iIdx; /* Index of child node in parent */
73587 MemPage *pPage; /* Current page of the b-tree */
73588
73589 /* If this is a leaf page or the tree is not an int-key tree, then
73590 ** this page contains countable entries. Increment the entry counter
@@ -73603,11 +73706,11 @@
73706 }
73707 if( getPageReferenced(pCheck, iPage) ){
73708 checkAppendMsg(pCheck, "2nd reference to page %d", iPage);
73709 return 1;
73710 }
73711 if( AtomicLoad(&pCheck->db->u1.isInterrupted) ) return 1;
73712 setPageReferenced(pCheck, iPage);
73713 return 0;
73714 }
73715
73716 #ifndef SQLITE_OMIT_AUTOVACUUM
@@ -79233,11 +79336,11 @@
79336 if( pOp->opcode==OP_Explain ) break;
79337 if( pOp->opcode==OP_Init && p->pc>1 ) break;
79338 }
79339
79340 if( rc==SQLITE_OK ){
79341 if( AtomicLoad(&db->u1.isInterrupted) ){
79342 p->rc = SQLITE_INTERRUPT;
79343 rc = SQLITE_ERROR;
79344 sqlite3VdbeError(p, sqlite3ErrStr(p->rc));
79345 }else{
79346 char *zP4;
@@ -83028,11 +83131,11 @@
83131 /* If there are no other statements currently running, then
83132 ** reset the interrupt flag. This prevents a call to sqlite3_interrupt
83133 ** from interrupting a statement that has not yet started.
83134 */
83135 if( db->nVdbeActive==0 ){
83136 AtomicStore(&db->u1.isInterrupted, 0);
83137 }
83138
83139 assert( db->nVdbeWrite>0 || db->autoCommit==0
83140 || (db->nDeferredCons==0 && db->nDeferredImmCons==0)
83141 );
@@ -85413,11 +85516,11 @@
85516 assert( p->bIsReader || p->readOnly!=0 );
85517 p->iCurrentTime = 0;
85518 assert( p->explain==0 );
85519 p->pResultSet = 0;
85520 db->busyHandler.nBusy = 0;
85521 if( AtomicLoad(&db->u1.isInterrupted) ) goto abort_due_to_interrupt;
85522 sqlite3VdbeIOTraceSql(p);
85523 #ifdef SQLITE_DEBUG
85524 sqlite3BeginBenignMalloc();
85525 if( p->pc==0
85526 && (p->db->flags & (SQLITE_VdbeListing|SQLITE_VdbeEQP|SQLITE_VdbeTrace))!=0
@@ -85597,11 +85700,11 @@
85700 ** But that is not due to sloppy coding habits. The code is written this
85701 ** way for performance, to avoid having to run the interrupt and progress
85702 ** checks on every opcode. This helps sqlite3_step() to run about 1.5%
85703 ** faster according to "valgrind --tool=cachegrind" */
85704 check_for_interrupt:
85705 if( AtomicLoad(&db->u1.isInterrupted) ) goto abort_due_to_interrupt;
85706 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
85707 /* Call the progress callback if it is configured and the required number
85708 ** of VDBE ops have been executed (either since this invocation of
85709 ** sqlite3VdbeExec() or since last time the progress callback was called).
85710 ** If the progress callback returns non-zero, exit the virtual machine with
@@ -92705,11 +92808,11 @@
92808
92809 /* Jump to here if the sqlite3_interrupt() API sets the interrupt
92810 ** flag.
92811 */
92812 abort_due_to_interrupt:
92813 assert( AtomicLoad(&db->u1.isInterrupted) );
92814 rc = db->mallocFailed ? SQLITE_NOMEM_BKPT : SQLITE_INTERRUPT;
92815 p->rc = rc;
92816 sqlite3VdbeError(p, "%s", sqlite3ErrStr(rc));
92817 goto abort_due_to_error;
92818 }
@@ -96775,11 +96878,11 @@
96878 const char *zTab,
96879 const char *zDb
96880 ){
96881 int n;
96882 const char *zSpan;
96883 if( pItem->eEName!=ENAME_TAB ) return 0;
96884 zSpan = pItem->zEName;
96885 for(n=0; ALWAYS(zSpan[n]) && zSpan[n]!='.'; n++){}
96886 if( zDb && (sqlite3StrNICmp(zSpan, zDb, n)!=0 || zDb[n]!=0) ){
96887 return 0;
96888 }
@@ -96929,10 +97032,11 @@
97032 ExprList *pEList;
97033 SrcList *pSrcList = pNC->pSrcList;
97034
97035 if( pSrcList ){
97036 for(i=0, pItem=pSrcList->a; i<pSrcList->nSrc; i++, pItem++){
97037 u8 hCol;
97038 pTab = pItem->pTab;
97039 assert( pTab!=0 && pTab->zName!=0 );
97040 assert( pTab->nCol>0 );
97041 if( pItem->pSelect && (pItem->pSelect->selFlags & SF_NestedFrom)!=0 ){
97042 int hit = 0;
@@ -96962,12 +97066,13 @@
97066 }
97067 }
97068 if( 0==(cntTab++) ){
97069 pMatch = pItem;
97070 }
97071 hCol = sqlite3StrIHash(zCol);
97072 for(j=0, pCol=pTab->aCol; j<pTab->nCol; j++, pCol++){
97073 if( pCol->hName==hCol && sqlite3StrICmp(pCol->zName, zCol)==0 ){
97074 /* If there has been exactly one prior match and this match
97075 ** is for the right-hand table of a NATURAL JOIN or is in a
97076 ** USING clause, then skip this match.
97077 */
97078 if( cnt==1 ){
@@ -97024,14 +97129,15 @@
97129 }
97130 #endif /* SQLITE_OMIT_UPSERT */
97131
97132 if( pTab ){
97133 int iCol;
97134 u8 hCol = sqlite3StrIHash(zCol);
97135 pSchema = pTab->pSchema;
97136 cntTab++;
97137 for(iCol=0, pCol=pTab->aCol; iCol<pTab->nCol; iCol++, pCol++){
97138 if( pCol->hName==hCol && sqlite3StrICmp(pCol->zName, zCol)==0 ){
97139 if( iCol==pTab->iPKey ){
97140 iCol = -1;
97141 }
97142 break;
97143 }
@@ -97828,11 +97934,11 @@
97934 nc.uNC.pEList = pEList;
97935 nc.ncFlags = NC_AllowAgg|NC_UEList;
97936 nc.nErr = 0;
97937 db = pParse->db;
97938 savedSuppErr = db->suppressErr;
97939 if( IN_RENAME_OBJECT==0 ) db->suppressErr = 1;
97940 rc = sqlite3ResolveExprNames(&nc, pE);
97941 db->suppressErr = savedSuppErr;
97942 if( rc ) return 0;
97943
97944 /* Try to match the ORDER BY expression against an expression
@@ -98463,15 +98569,45 @@
98569 SQLITE_PRIVATE int sqlite3ResolveExprListNames(
98570 NameContext *pNC, /* Namespace to resolve expressions in. */
98571 ExprList *pList /* The expression list to be analyzed. */
98572 ){
98573 int i;
98574 int savedHasAgg = 0;
98575 Walker w;
98576 if( pList==0 ) return WRC_Continue;
98577 w.pParse = pNC->pParse;
98578 w.xExprCallback = resolveExprStep;
98579 w.xSelectCallback = resolveSelectStep;
98580 w.xSelectCallback2 = 0;
98581 w.u.pNC = pNC;
98582 savedHasAgg = pNC->ncFlags & (NC_HasAgg|NC_MinMaxAgg|NC_HasWin);
98583 pNC->ncFlags &= ~(NC_HasAgg|NC_MinMaxAgg|NC_HasWin);
98584 for(i=0; i<pList->nExpr; i++){
98585 Expr *pExpr = pList->a[i].pExpr;
98586 if( pExpr==0 ) continue;
98587 #if SQLITE_MAX_EXPR_DEPTH>0
98588 w.pParse->nHeight += pExpr->nHeight;
98589 if( sqlite3ExprCheckHeight(w.pParse, w.pParse->nHeight) ){
98590 return WRC_Abort;
98591 }
98592 #endif
98593 sqlite3WalkExpr(&w, pExpr);
98594 #if SQLITE_MAX_EXPR_DEPTH>0
98595 w.pParse->nHeight -= pExpr->nHeight;
98596 #endif
98597 assert( EP_Agg==NC_HasAgg );
98598 assert( EP_Win==NC_HasWin );
98599 testcase( pNC->ncFlags & NC_HasAgg );
98600 testcase( pNC->ncFlags & NC_HasWin );
98601 if( pNC->ncFlags & (NC_HasAgg|NC_MinMaxAgg|NC_HasWin) ){
98602 ExprSetProperty(pExpr, pNC->ncFlags & (NC_HasAgg|NC_HasWin) );
98603 savedHasAgg |= pNC->ncFlags & (NC_HasAgg|NC_MinMaxAgg|NC_HasWin);
98604 pNC->ncFlags &= ~(NC_HasAgg|NC_MinMaxAgg|NC_HasWin);
98605 }
98606 if( pNC->nErr>0 || w.pParse->nErr>0 ) return WRC_Abort;
98607 }
98608 pNC->ncFlags |= savedHasAgg;
98609 return WRC_Continue;
98610 }
98611
98612 /*
98613 ** Resolve all names in all expressions of a SELECT and in all
@@ -100343,20 +100479,26 @@
100479 ExprList *pList, /* List to which to add the span. */
100480 Token *pName, /* Name to be added */
100481 int dequote /* True to cause the name to be dequoted */
100482 ){
100483 assert( pList!=0 || pParse->db->mallocFailed!=0 );
100484 assert( pParse->eParseMode!=PARSE_MODE_UNMAP || dequote==0 );
100485 if( pList ){
100486 struct ExprList_item *pItem;
100487 assert( pList->nExpr>0 );
100488 pItem = &pList->a[pList->nExpr-1];
100489 assert( pItem->zEName==0 );
100490 assert( pItem->eEName==ENAME_NAME );
100491 pItem->zEName = sqlite3DbStrNDup(pParse->db, pName->z, pName->n);
100492 if( dequote ){
100493 /* If dequote==0, then pName->z does not point to part of a DDL
100494 ** statement handled by the parser. And so no token need be added
100495 ** to the token-map. */
100496 sqlite3Dequote(pItem->zEName);
100497 if( IN_RENAME_OBJECT ){
100498 sqlite3RenameTokenMap(pParse, (void*)pItem->zEName, pName);
100499 }
100500 }
100501 }
100502 }
100503
100504 /*
@@ -101497,10 +101639,12 @@
101639 struct ExprList_item *pItem;
101640 int r1, r2;
101641 affinity = sqlite3ExprAffinity(pLeft);
101642 if( affinity<=SQLITE_AFF_NONE ){
101643 affinity = SQLITE_AFF_BLOB;
101644 }else if( affinity==SQLITE_AFF_REAL ){
101645 affinity = SQLITE_AFF_NUMERIC;
101646 }
101647 if( pKeyInfo ){
101648 assert( sqlite3KeyInfoIsWriteable(pKeyInfo) );
101649 pKeyInfo->aColl[0] = sqlite3ExprCollSeq(pParse, pExpr->pLeft);
101650 }
@@ -101735,10 +101879,11 @@
101879 int destStep6 = 0; /* Start of code for Step 6 */
101880 int addrTruthOp; /* Address of opcode that determines the IN is true */
101881 int destNotNull; /* Jump here if a comparison is not true in step 6 */
101882 int addrTop; /* Top of the step-6 loop */
101883 int iTab = 0; /* Index to use */
101884 u8 okConstFactor = pParse->okConstFactor;
101885
101886 assert( !ExprHasVVAProperty(pExpr,EP_Immutable) );
101887 pLeft = pExpr->pLeft;
101888 if( sqlite3ExprCheckIN(pParse, pExpr) ) return;
101889 zAff = exprINAffinity(pParse, pExpr);
@@ -101779,12 +101924,18 @@
101924 **
101925 ** sqlite3FindInIndex() might have reordered the fields of the LHS vector
101926 ** so that the fields are in the same order as an existing index. The
101927 ** aiMap[] array contains a mapping from the original LHS field order to
101928 ** the field order that matches the RHS index.
101929 **
101930 ** Avoid factoring the LHS of the IN(...) expression out of the loop,
101931 ** even if it is constant, as OP_Affinity may be used on the register
101932 ** by code generated below. */
101933 assert( pParse->okConstFactor==okConstFactor );
101934 pParse->okConstFactor = 0;
101935 rLhsOrig = exprCodeVector(pParse, pLeft, &iDummy);
101936 pParse->okConstFactor = okConstFactor;
101937 for(i=0; i<nVector && aiMap[i]==i; i++){} /* Are LHS fields reordered? */
101938 if( i==nVector ){
101939 /* LHS fields are not reordered */
101940 rLhs = rLhsOrig;
101941 }else{
@@ -101806,25 +101957,17 @@
101957 CollSeq *pColl = sqlite3ExprCollSeq(pParse, pExpr->pLeft);
101958 int labelOk = sqlite3VdbeMakeLabel(pParse);
101959 int r2, regToFree;
101960 int regCkNull = 0;
101961 int ii;
 
101962 assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
101963 if( destIfNull!=destIfFalse ){
101964 regCkNull = sqlite3GetTempReg(pParse);
101965 sqlite3VdbeAddOp3(v, OP_BitAnd, rLhs, rLhs, regCkNull);
101966 }
 
101967 for(ii=0; ii<pList->nExpr; ii++){
101968 r2 = sqlite3ExprCodeTemp(pParse, pList->a[ii].pExpr, &regToFree);
 
 
 
 
 
 
101969 if( regCkNull && sqlite3ExprCanBeNull(pList->a[ii].pExpr) ){
101970 sqlite3VdbeAddOp3(v, OP_BitAnd, regCkNull, r2, regCkNull);
101971 }
101972 sqlite3ReleaseTempReg(pParse, regToFree);
101973 if( ii<pList->nExpr-1 || destIfNull!=destIfFalse ){
@@ -102394,14 +102537,10 @@
102537 }
102538 if( aff>SQLITE_AFF_BLOB ){
102539 static const char zAff[] = "B\000C\000D\000E";
102540 assert( SQLITE_AFF_BLOB=='A' );
102541 assert( SQLITE_AFF_TEXT=='B' );
 
 
 
 
102542 sqlite3VdbeAddOp4(v, OP_Affinity, iReg, 1, 0,
102543 &zAff[(aff-'B')*2], P4_STATIC);
102544 }
102545 return iReg;
102546 }
@@ -105020,10 +105159,11 @@
105159 }
105160 memcpy(pNew->aCol, pTab->aCol, sizeof(Column)*pNew->nCol);
105161 for(i=0; i<pNew->nCol; i++){
105162 Column *pCol = &pNew->aCol[i];
105163 pCol->zName = sqlite3DbStrDup(db, pCol->zName);
105164 pCol->hName = sqlite3StrIHash(pCol->zName);
105165 pCol->zColl = 0;
105166 pCol->pDflt = 0;
105167 }
105168 pNew->pSchema = db->aDb[iDb].pSchema;
105169 pNew->addColOffset = pTab->addColOffset;
@@ -105248,11 +105388,11 @@
105388 */
105389 SQLITE_PRIVATE void *sqlite3RenameTokenMap(Parse *pParse, void *pPtr, Token *pToken){
105390 RenameToken *pNew;
105391 assert( pPtr || pParse->db->mallocFailed );
105392 renameTokenCheckAll(pParse, pPtr);
105393 if( ALWAYS(pParse->eParseMode!=PARSE_MODE_UNMAP) ){
105394 pNew = sqlite3DbMallocZero(pParse->db, sizeof(RenameToken));
105395 if( pNew ){
105396 pNew->p = pPtr;
105397 pNew->t = *pToken;
105398 pNew->pNext = pParse->pRename;
@@ -105305,10 +105445,25 @@
105445 sqlite3WalkSelect(pWalker, p);
105446 sqlite3RenameExprlistUnmap(pWalker->pParse, pWith->a[i].pCols);
105447 }
105448 }
105449 }
105450
105451 /*
105452 ** Unmap all tokens in the IdList object passed as the second argument.
105453 */
105454 static void unmapColumnIdlistNames(
105455 Parse *pParse,
105456 IdList *pIdList
105457 ){
105458 if( pIdList ){
105459 int ii;
105460 for(ii=0; ii<pIdList->nId; ii++){
105461 sqlite3RenameTokenRemap(pParse, 0, (void*)pIdList->a[ii].zName);
105462 }
105463 }
105464 }
105465
105466 /*
105467 ** Walker callback used by sqlite3RenameExprUnmap().
105468 */
105469 static int renameUnmapSelectCb(Walker *pWalker, Select *p){
@@ -105327,10 +105482,11 @@
105482 if( ALWAYS(p->pSrc) ){ /* Every Select as a SrcList, even if it is empty */
105483 SrcList *pSrc = p->pSrc;
105484 for(i=0; i<pSrc->nSrc; i++){
105485 sqlite3RenameTokenRemap(pParse, 0, (void*)pSrc->a[i].zName);
105486 if( sqlite3WalkExpr(pWalker, pSrc->a[i].pOn) ) return WRC_Abort;
105487 unmapColumnIdlistNames(pParse, pSrc->a[i].pUsing);
105488 }
105489 }
105490
105491 renameWalkWith(pWalker, p);
105492 return WRC_Continue;
@@ -105534,10 +105690,11 @@
105690 renameTokenFind(pParse, pCtx, (void*)zName);
105691 }
105692 }
105693 }
105694 }
105695
105696
105697 /*
105698 ** Parse the SQL statement zSql using Parse object (*p). The Parse object
105699 ** is initialized by this function before it is used.
105700 */
@@ -109619,10 +109776,11 @@
109776 int i;
109777 Column *pCol;
109778 assert( pTable!=0 );
109779 if( (pCol = pTable->aCol)!=0 ){
109780 for(i=0; i<pTable->nCol; i++, pCol++){
109781 assert( pCol->zName==0 || pCol->hName==sqlite3StrIHash(pCol->zName) );
109782 sqlite3DbFree(db, pCol->zName);
109783 sqlite3ExprDelete(db, pCol->pDflt);
109784 sqlite3DbFree(db, pCol->zColl);
109785 }
109786 sqlite3DbFree(db, pTable->aCol);
@@ -110267,10 +110425,11 @@
110425 p->aCol = aNew;
110426 }
110427 pCol = &p->aCol[p->nCol];
110428 memset(pCol, 0, sizeof(p->aCol[0]));
110429 pCol->zName = z;
110430 pCol->hName = sqlite3StrIHash(z);
110431 sqlite3ColumnPropertiesFromName(p, pCol);
110432
110433 if( pType->n==0 ){
110434 /* If there is no type specified, columns have the default affinity
110435 ** 'BLOB' with a default size of 4 bytes. */
@@ -129768,10 +129927,11 @@
129927 }
129928 zName = sqlite3MPrintf(db, "%.*z:%u", nName, zName, ++cnt);
129929 if( cnt>3 ) sqlite3_randomness(sizeof(cnt), &cnt);
129930 }
129931 pCol->zName = zName;
129932 pCol->hName = sqlite3StrIHash(zName);
129933 sqlite3ColumnPropertiesFromName(0, pCol);
129934 if( zName && sqlite3HashInsert(&ht, zName, pCol)==pCol ){
129935 sqlite3OomFault(db);
129936 }
129937 }
@@ -131221,11 +131381,14 @@
131381 if( ExprHasProperty(pExpr, EP_FromJoin)
131382 && pExpr->iRightJoinTable==pSubst->iTable
131383 ){
131384 pExpr->iRightJoinTable = pSubst->iNewTable;
131385 }
131386 if( pExpr->op==TK_COLUMN
131387 && pExpr->iTable==pSubst->iTable
131388 && !ExprHasProperty(pExpr, EP_FixedCol)
131389 ){
131390 if( pExpr->iColumn<0 ){
131391 pExpr->op = TK_NULL;
131392 }else{
131393 Expr *pNew;
131394 Expr *pCopy = pSubst->pEList->a[pExpr->iColumn].pExpr;
@@ -133133,10 +133296,11 @@
133296 Vdbe *v = pParse->pVdbe;
133297 int i;
133298 struct AggInfo_func *pFunc;
133299 int nReg = pAggInfo->nFunc + pAggInfo->nColumn;
133300 if( nReg==0 ) return;
133301 if( pParse->nErr ) return;
133302 #ifdef SQLITE_DEBUG
133303 /* Verify that all AggInfo registers are within the range specified by
133304 ** AggInfo.mnReg..AggInfo.mxReg */
133305 assert( nReg==pAggInfo->mxReg-pAggInfo->mnReg+1 );
133306 for(i=0; i<pAggInfo->nColumn; i++){
@@ -156491,14 +156655,15 @@
156655 ** simplify to constants 0 (false) and 1 (true), respectively,
156656 ** regardless of the value of expr1.
156657 */
156658 sqlite3ExprUnmapAndDelete(pParse, yymsp[-4].minor.yy202);
156659 yymsp[-4].minor.yy202 = sqlite3Expr(pParse->db, TK_INTEGER, yymsp[-3].minor.yy192 ? "1" : "0");
156660 }else if( yymsp[-1].minor.yy242->nExpr==1 && sqlite3ExprIsConstant(yymsp[-1].minor.yy242->a[0].pExpr) ){
156661 Expr *pRHS = yymsp[-1].minor.yy242->a[0].pExpr;
156662 yymsp[-1].minor.yy242->a[0].pExpr = 0;
156663 sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy242);
156664 pRHS = sqlite3PExpr(pParse, TK_UPLUS, pRHS, 0);
156665 yymsp[-4].minor.yy202 = sqlite3PExpr(pParse, TK_EQ, yymsp[-4].minor.yy202, pRHS);
156666 if( yymsp[-3].minor.yy192 ) yymsp[-4].minor.yy202 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy202, 0);
156667 }else{
156668 yymsp[-4].minor.yy202 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy202, 0);
156669 if( yymsp[-4].minor.yy202 ){
@@ -158376,11 +158541,11 @@
158541 VVA_ONLY( u8 startedWithOom = db->mallocFailed );
158542
158543 assert( zSql!=0 );
158544 mxSqlLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];
158545 if( db->nVdbeActive==0 ){
158546 AtomicStore(&db->u1.isInterrupted, 0);
158547 }
158548 pParse->rc = SQLITE_OK;
158549 pParse->zTail = zSql;
158550 assert( pzErrMsg!=0 );
158551 #ifdef SQLITE_DEBUG
@@ -158421,11 +158586,11 @@
158586 );
158587 #else
158588 if( tokenType>=TK_SPACE ){
158589 assert( tokenType==TK_SPACE || tokenType==TK_ILLEGAL );
158590 #endif /* SQLITE_OMIT_WINDOWFUNC */
158591 if( AtomicLoad(&db->u1.isInterrupted) ){
158592 pParse->rc = SQLITE_INTERRUPT;
158593 break;
158594 }
158595 if( tokenType==TK_SPACE ){
158596 zSql += n;
@@ -160632,13 +160797,25 @@
160797 int delay, prior;
160798
160799 #ifdef SQLITE_ENABLE_SETLK_TIMEOUT
160800 if( sqlite3OsFileControl(pFile,SQLITE_FCNTL_LOCK_TIMEOUT,&tmout)==SQLITE_OK ){
160801 if( count ){
160802 /* If this is the second or later invocation of the busy-handler,
160803 ** but tmout==0, then code in wal.c must have disabled the blocking
160804 ** lock before the SQLITE_BUSY error was hit. In this case, no delay
160805 ** occurred while waiting for the lock, so fall through to the xSleep()
160806 ** code below to delay a while before retrying the lock.
160807 **
160808 ** Alternatively, if tmout!=0, then SQLite has already waited
160809 ** sqlite3.busyTimeout ms for a lock. In this case, return 0 to
160810 ** indicate that the lock should not be retried and the SQLITE_BUSY
160811 ** error returned to the application. */
160812 if( tmout ){
160813 tmout = 0;
160814 sqlite3OsFileControl(pFile, SQLITE_FCNTL_LOCK_TIMEOUT, &tmout);
160815 return 0;
160816 }
160817 }else{
160818 return 1;
160819 }
160820 }
160821 #else
@@ -160784,11 +160961,11 @@
160961 if( !sqlite3SafetyCheckOk(db) && (db==0 || db->magic!=SQLITE_MAGIC_ZOMBIE) ){
160962 (void)SQLITE_MISUSE_BKPT;
160963 return;
160964 }
160965 #endif
160966 AtomicStore(&db->u1.isInterrupted, 1);
160967 }
160968
160969
160970 /*
160971 ** This function is exactly the same as sqlite3_create_function(), except
@@ -161406,11 +161583,11 @@
161583 rc = sqlite3ApiExit(db, rc);
161584
161585 /* If there are no active statements, clear the interrupt flag at this
161586 ** point. */
161587 if( db->nVdbeActive==0 ){
161588 AtomicStore(&db->u1.isInterrupted, 0);
161589 }
161590
161591 sqlite3_mutex_leave(db->mutex);
161592 return rc;
161593 #endif
@@ -176558,10 +176735,11 @@
176735 ** b-tree node. And that the final byte of the doclist is 0x00. If either
176736 ** of these statements is untrue, then the data structure is corrupt.
176737 */
176738 if( pReader->nDoclist > pReader->nNode-(pReader->aDoclist-pReader->aNode)
176739 || (pReader->nPopulate==0 && pReader->aDoclist[pReader->nDoclist-1])
176740 || pReader->nDoclist==0
176741 ){
176742 return FTS_CORRUPT_VTAB;
176743 }
176744 return SQLITE_OK;
176745 }
@@ -223728,11 +223906,11 @@
223906 int nArg, /* Number of args */
223907 sqlite3_value **apUnused /* Function arguments */
223908 ){
223909 assert( nArg==0 );
223910 UNUSED_PARAM2(nArg, apUnused);
223911 sqlite3_result_text(pCtx, "fts5: 2020-04-18 14:12:00 d5b0def96ba6d90f47bc96fab1ccf9c501d84885d086744035b16fd96f3e248c", -1, SQLITE_TRANSIENT);
223912 }
223913
223914 /*
223915 ** Return true if zName is the extension on one of the shadow tables used
223916 ** by this module.
@@ -228510,12 +228688,12 @@
228688 }
228689 #endif /* SQLITE_CORE */
228690 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
228691
228692 /************** End of stmt.c ************************************************/
228693 #if __LINE__!=228693
228694 #undef SQLITE_SOURCE_ID
228695 #define SQLITE_SOURCE_ID "2020-04-18 14:12:00 d5b0def96ba6d90f47bc96fab1ccf9c501d84885d086744035b16fd96f3ealt2"
228696 #endif
228697 /* Return the source-id for this library */
228698 SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
228699 /************************** End of sqlite3.c ******************************/
228700
+48 -8
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -123,11 +123,11 @@
123123
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124124
** [sqlite_version()] and [sqlite_source_id()].
125125
*/
126126
#define SQLITE_VERSION "3.32.0"
127127
#define SQLITE_VERSION_NUMBER 3032000
128
-#define SQLITE_SOURCE_ID "2020-03-21 23:10:38 5d14a1c4f2fc17de98ad685ad1422cdfda89dfccb00afcaf32ee416b6f84f525"
128
+#define SQLITE_SOURCE_ID "2020-04-18 14:12:00 d5b0def96ba6d90f47bc96fab1ccf9c501d84885d086744035b16fd96f3e248c"
129129
130130
/*
131131
** CAPI3REF: Run-Time Library Version Numbers
132132
** KEYWORDS: sqlite3_version sqlite3_sourceid
133133
**
@@ -1085,14 +1085,16 @@
10851085
** so that all subsequent write operations are independent.
10861086
** ^SQLite will never invoke SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE without
10871087
** a prior successful call to [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE].
10881088
**
10891089
** <li>[[SQLITE_FCNTL_LOCK_TIMEOUT]]
1090
-** The [SQLITE_FCNTL_LOCK_TIMEOUT] opcode causes attempts to obtain
1091
-** a file lock using the xLock or xShmLock methods of the VFS to wait
1092
-** for up to M milliseconds before failing, where M is the single
1093
-** unsigned integer parameter.
1090
+** The [SQLITE_FCNTL_LOCK_TIMEOUT] opcode is used to configure a VFS
1091
+** to block for up to M milliseconds before failing when attempting to
1092
+** obtain a file lock using the xLock or xShmLock methods of the VFS.
1093
+** The parameter is a pointer to a 32-bit signed integer that contains
1094
+** the value that M is to be set to. Before returning, the 32-bit signed
1095
+** integer is overwritten with the previous value of M.
10941096
**
10951097
** <li>[[SQLITE_FCNTL_DATA_VERSION]]
10961098
** The [SQLITE_FCNTL_DATA_VERSION] opcode is used to detect changes to
10971099
** a database file. The argument is a pointer to a 32-bit unsigned integer.
10981100
** The "data version" for the pager is written into the pointer. The
@@ -4256,10 +4258,28 @@
42564258
**
42574259
** ^The third argument is the value to bind to the parameter.
42584260
** ^If the third parameter to sqlite3_bind_text() or sqlite3_bind_text16()
42594261
** or sqlite3_bind_blob() is a NULL pointer then the fourth parameter
42604262
** is ignored and the end result is the same as sqlite3_bind_null().
4263
+** ^If the third parameter to sqlite3_bind_text() is not NULL, then
4264
+** it should be a pointer to well-formed UTF8 text.
4265
+** ^If the third parameter to sqlite3_bind_text16() is not NULL, then
4266
+** it should be a pointer to well-formed UTF16 text.
4267
+** ^If the third parameter to sqlite3_bind_text64() is not NULL, then
4268
+** it should be a pointer to a well-formed unicode string that is
4269
+** either UTF8 if the sixth parameter is SQLITE_UTF8, or UTF16
4270
+** otherwise.
4271
+**
4272
+** [[byte-order determination rules]] ^The byte-order of
4273
+** UTF16 input text is determined by the byte-order mark (BOM, U+FEFF)
4274
+** found in first character, which is removed, or in the absence of a BOM
4275
+** the byte order is the native byte order of the host
4276
+** machine for sqlite3_bind_text16() or the byte order specified in
4277
+** the 6th parameter for sqlite3_bind_text64().)^
4278
+** ^If UTF16 input text contains invalid unicode
4279
+** characters, then SQLite might change those invalid characters
4280
+** into the unicode replacement character: U+FFFD.
42614281
**
42624282
** ^(In those routines that have a fourth argument, its value is the
42634283
** number of bytes in the parameter. To be clear: the value is the
42644284
** number of <u>bytes</u> in the value, not the number of characters.)^
42654285
** ^If the fourth parameter to sqlite3_bind_text() or sqlite3_bind_text16()
@@ -4269,11 +4289,11 @@
42694289
** the behavior is undefined.
42704290
** If a non-negative fourth parameter is provided to sqlite3_bind_text()
42714291
** or sqlite3_bind_text16() or sqlite3_bind_text64() then
42724292
** that parameter must be the byte offset
42734293
** where the NUL terminator would occur assuming the string were NUL
4274
-** terminated. If any NUL characters occur at byte offsets less than
4294
+** terminated. If any NUL characters occurs at byte offsets less than
42754295
** the value of the fourth parameter then the resulting string value will
42764296
** contain embedded NULs. The result of expressions involving strings
42774297
** with embedded NULs is undefined.
42784298
**
42794299
** ^The fifth argument to the BLOB and string binding interfaces
@@ -5594,12 +5614,13 @@
55945614
** cause the implemented SQL function to throw an exception.
55955615
** ^SQLite uses the string pointed to by the
55965616
** 2nd parameter of sqlite3_result_error() or sqlite3_result_error16()
55975617
** as the text of an error message. ^SQLite interprets the error
55985618
** message string from sqlite3_result_error() as UTF-8. ^SQLite
5599
-** interprets the string from sqlite3_result_error16() as UTF-16 in native
5600
-** byte order. ^If the third parameter to sqlite3_result_error()
5619
+** interprets the string from sqlite3_result_error16() as UTF-16 using
5620
+** the same [byte-order determination rules] as [sqlite3_bind_text16()].
5621
+** ^If the third parameter to sqlite3_result_error()
56015622
** or sqlite3_result_error16() is negative then SQLite takes as the error
56025623
** message all text up through the first zero character.
56035624
** ^If the third parameter to sqlite3_result_error() or
56045625
** sqlite3_result_error16() is non-negative then SQLite takes that many
56055626
** bytes (not characters) from the 2nd parameter as the error message.
@@ -5662,10 +5683,29 @@
56625683
** when it has finished using that result.
56635684
** ^If the 4th parameter to the sqlite3_result_text* interfaces
56645685
** or sqlite3_result_blob is the special constant SQLITE_TRANSIENT
56655686
** then SQLite makes a copy of the result into space obtained
56665687
** from [sqlite3_malloc()] before it returns.
5688
+**
5689
+** ^For the sqlite3_result_text16(), sqlite3_result_text16le(), and
5690
+** sqlite3_result_text16be() routines, and for sqlite3_result_text64()
5691
+** when the encoding is not UTF8, if the input UTF16 begins with a
5692
+** byte-order mark (BOM, U+FEFF) then the BOM is removed from the
5693
+** string and the rest of the string is interpreted according to the
5694
+** byte-order specified by the BOM. ^The byte-order specified by
5695
+** the BOM at the beginning of the text overrides the byte-order
5696
+** specified by the interface procedure. ^So, for example, if
5697
+** sqlite3_result_text16le() is invoked with text that begins
5698
+** with bytes 0xfe, 0xff (a big-endian byte-order mark) then the
5699
+** first two bytes of input are skipped and the remaining input
5700
+** is interpreted as UTF16BE text.
5701
+**
5702
+** ^For UTF16 input text to the sqlite3_result_text16(),
5703
+** sqlite3_result_text16be(), sqlite3_result_text16le(), and
5704
+** sqlite3_result_text64() routines, if the text contains invalid
5705
+** UTF16 characters, the invalid characters might be converted
5706
+** into the unicode replacement character, U+FFFD.
56675707
**
56685708
** ^The sqlite3_result_value() interface sets the result of
56695709
** the application-defined function to be a copy of the
56705710
** [unprotected sqlite3_value] object specified by the 2nd parameter. ^The
56715711
** sqlite3_result_value() interface makes a copy of the [sqlite3_value]
56725712
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -123,11 +123,11 @@
123 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124 ** [sqlite_version()] and [sqlite_source_id()].
125 */
126 #define SQLITE_VERSION "3.32.0"
127 #define SQLITE_VERSION_NUMBER 3032000
128 #define SQLITE_SOURCE_ID "2020-03-21 23:10:38 5d14a1c4f2fc17de98ad685ad1422cdfda89dfccb00afcaf32ee416b6f84f525"
129
130 /*
131 ** CAPI3REF: Run-Time Library Version Numbers
132 ** KEYWORDS: sqlite3_version sqlite3_sourceid
133 **
@@ -1085,14 +1085,16 @@
1085 ** so that all subsequent write operations are independent.
1086 ** ^SQLite will never invoke SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE without
1087 ** a prior successful call to [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE].
1088 **
1089 ** <li>[[SQLITE_FCNTL_LOCK_TIMEOUT]]
1090 ** The [SQLITE_FCNTL_LOCK_TIMEOUT] opcode causes attempts to obtain
1091 ** a file lock using the xLock or xShmLock methods of the VFS to wait
1092 ** for up to M milliseconds before failing, where M is the single
1093 ** unsigned integer parameter.
 
 
1094 **
1095 ** <li>[[SQLITE_FCNTL_DATA_VERSION]]
1096 ** The [SQLITE_FCNTL_DATA_VERSION] opcode is used to detect changes to
1097 ** a database file. The argument is a pointer to a 32-bit unsigned integer.
1098 ** The "data version" for the pager is written into the pointer. The
@@ -4256,10 +4258,28 @@
4256 **
4257 ** ^The third argument is the value to bind to the parameter.
4258 ** ^If the third parameter to sqlite3_bind_text() or sqlite3_bind_text16()
4259 ** or sqlite3_bind_blob() is a NULL pointer then the fourth parameter
4260 ** is ignored and the end result is the same as sqlite3_bind_null().
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4261 **
4262 ** ^(In those routines that have a fourth argument, its value is the
4263 ** number of bytes in the parameter. To be clear: the value is the
4264 ** number of <u>bytes</u> in the value, not the number of characters.)^
4265 ** ^If the fourth parameter to sqlite3_bind_text() or sqlite3_bind_text16()
@@ -4269,11 +4289,11 @@
4269 ** the behavior is undefined.
4270 ** If a non-negative fourth parameter is provided to sqlite3_bind_text()
4271 ** or sqlite3_bind_text16() or sqlite3_bind_text64() then
4272 ** that parameter must be the byte offset
4273 ** where the NUL terminator would occur assuming the string were NUL
4274 ** terminated. If any NUL characters occur at byte offsets less than
4275 ** the value of the fourth parameter then the resulting string value will
4276 ** contain embedded NULs. The result of expressions involving strings
4277 ** with embedded NULs is undefined.
4278 **
4279 ** ^The fifth argument to the BLOB and string binding interfaces
@@ -5594,12 +5614,13 @@
5594 ** cause the implemented SQL function to throw an exception.
5595 ** ^SQLite uses the string pointed to by the
5596 ** 2nd parameter of sqlite3_result_error() or sqlite3_result_error16()
5597 ** as the text of an error message. ^SQLite interprets the error
5598 ** message string from sqlite3_result_error() as UTF-8. ^SQLite
5599 ** interprets the string from sqlite3_result_error16() as UTF-16 in native
5600 ** byte order. ^If the third parameter to sqlite3_result_error()
 
5601 ** or sqlite3_result_error16() is negative then SQLite takes as the error
5602 ** message all text up through the first zero character.
5603 ** ^If the third parameter to sqlite3_result_error() or
5604 ** sqlite3_result_error16() is non-negative then SQLite takes that many
5605 ** bytes (not characters) from the 2nd parameter as the error message.
@@ -5662,10 +5683,29 @@
5662 ** when it has finished using that result.
5663 ** ^If the 4th parameter to the sqlite3_result_text* interfaces
5664 ** or sqlite3_result_blob is the special constant SQLITE_TRANSIENT
5665 ** then SQLite makes a copy of the result into space obtained
5666 ** from [sqlite3_malloc()] before it returns.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5667 **
5668 ** ^The sqlite3_result_value() interface sets the result of
5669 ** the application-defined function to be a copy of the
5670 ** [unprotected sqlite3_value] object specified by the 2nd parameter. ^The
5671 ** sqlite3_result_value() interface makes a copy of the [sqlite3_value]
5672
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -123,11 +123,11 @@
123 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124 ** [sqlite_version()] and [sqlite_source_id()].
125 */
126 #define SQLITE_VERSION "3.32.0"
127 #define SQLITE_VERSION_NUMBER 3032000
128 #define SQLITE_SOURCE_ID "2020-04-18 14:12:00 d5b0def96ba6d90f47bc96fab1ccf9c501d84885d086744035b16fd96f3e248c"
129
130 /*
131 ** CAPI3REF: Run-Time Library Version Numbers
132 ** KEYWORDS: sqlite3_version sqlite3_sourceid
133 **
@@ -1085,14 +1085,16 @@
1085 ** so that all subsequent write operations are independent.
1086 ** ^SQLite will never invoke SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE without
1087 ** a prior successful call to [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE].
1088 **
1089 ** <li>[[SQLITE_FCNTL_LOCK_TIMEOUT]]
1090 ** The [SQLITE_FCNTL_LOCK_TIMEOUT] opcode is used to configure a VFS
1091 ** to block for up to M milliseconds before failing when attempting to
1092 ** obtain a file lock using the xLock or xShmLock methods of the VFS.
1093 ** The parameter is a pointer to a 32-bit signed integer that contains
1094 ** the value that M is to be set to. Before returning, the 32-bit signed
1095 ** integer is overwritten with the previous value of M.
1096 **
1097 ** <li>[[SQLITE_FCNTL_DATA_VERSION]]
1098 ** The [SQLITE_FCNTL_DATA_VERSION] opcode is used to detect changes to
1099 ** a database file. The argument is a pointer to a 32-bit unsigned integer.
1100 ** The "data version" for the pager is written into the pointer. The
@@ -4256,10 +4258,28 @@
4258 **
4259 ** ^The third argument is the value to bind to the parameter.
4260 ** ^If the third parameter to sqlite3_bind_text() or sqlite3_bind_text16()
4261 ** or sqlite3_bind_blob() is a NULL pointer then the fourth parameter
4262 ** is ignored and the end result is the same as sqlite3_bind_null().
4263 ** ^If the third parameter to sqlite3_bind_text() is not NULL, then
4264 ** it should be a pointer to well-formed UTF8 text.
4265 ** ^If the third parameter to sqlite3_bind_text16() is not NULL, then
4266 ** it should be a pointer to well-formed UTF16 text.
4267 ** ^If the third parameter to sqlite3_bind_text64() is not NULL, then
4268 ** it should be a pointer to a well-formed unicode string that is
4269 ** either UTF8 if the sixth parameter is SQLITE_UTF8, or UTF16
4270 ** otherwise.
4271 **
4272 ** [[byte-order determination rules]] ^The byte-order of
4273 ** UTF16 input text is determined by the byte-order mark (BOM, U+FEFF)
4274 ** found in first character, which is removed, or in the absence of a BOM
4275 ** the byte order is the native byte order of the host
4276 ** machine for sqlite3_bind_text16() or the byte order specified in
4277 ** the 6th parameter for sqlite3_bind_text64().)^
4278 ** ^If UTF16 input text contains invalid unicode
4279 ** characters, then SQLite might change those invalid characters
4280 ** into the unicode replacement character: U+FFFD.
4281 **
4282 ** ^(In those routines that have a fourth argument, its value is the
4283 ** number of bytes in the parameter. To be clear: the value is the
4284 ** number of <u>bytes</u> in the value, not the number of characters.)^
4285 ** ^If the fourth parameter to sqlite3_bind_text() or sqlite3_bind_text16()
@@ -4269,11 +4289,11 @@
4289 ** the behavior is undefined.
4290 ** If a non-negative fourth parameter is provided to sqlite3_bind_text()
4291 ** or sqlite3_bind_text16() or sqlite3_bind_text64() then
4292 ** that parameter must be the byte offset
4293 ** where the NUL terminator would occur assuming the string were NUL
4294 ** terminated. If any NUL characters occurs at byte offsets less than
4295 ** the value of the fourth parameter then the resulting string value will
4296 ** contain embedded NULs. The result of expressions involving strings
4297 ** with embedded NULs is undefined.
4298 **
4299 ** ^The fifth argument to the BLOB and string binding interfaces
@@ -5594,12 +5614,13 @@
5614 ** cause the implemented SQL function to throw an exception.
5615 ** ^SQLite uses the string pointed to by the
5616 ** 2nd parameter of sqlite3_result_error() or sqlite3_result_error16()
5617 ** as the text of an error message. ^SQLite interprets the error
5618 ** message string from sqlite3_result_error() as UTF-8. ^SQLite
5619 ** interprets the string from sqlite3_result_error16() as UTF-16 using
5620 ** the same [byte-order determination rules] as [sqlite3_bind_text16()].
5621 ** ^If the third parameter to sqlite3_result_error()
5622 ** or sqlite3_result_error16() is negative then SQLite takes as the error
5623 ** message all text up through the first zero character.
5624 ** ^If the third parameter to sqlite3_result_error() or
5625 ** sqlite3_result_error16() is non-negative then SQLite takes that many
5626 ** bytes (not characters) from the 2nd parameter as the error message.
@@ -5662,10 +5683,29 @@
5683 ** when it has finished using that result.
5684 ** ^If the 4th parameter to the sqlite3_result_text* interfaces
5685 ** or sqlite3_result_blob is the special constant SQLITE_TRANSIENT
5686 ** then SQLite makes a copy of the result into space obtained
5687 ** from [sqlite3_malloc()] before it returns.
5688 **
5689 ** ^For the sqlite3_result_text16(), sqlite3_result_text16le(), and
5690 ** sqlite3_result_text16be() routines, and for sqlite3_result_text64()
5691 ** when the encoding is not UTF8, if the input UTF16 begins with a
5692 ** byte-order mark (BOM, U+FEFF) then the BOM is removed from the
5693 ** string and the rest of the string is interpreted according to the
5694 ** byte-order specified by the BOM. ^The byte-order specified by
5695 ** the BOM at the beginning of the text overrides the byte-order
5696 ** specified by the interface procedure. ^So, for example, if
5697 ** sqlite3_result_text16le() is invoked with text that begins
5698 ** with bytes 0xfe, 0xff (a big-endian byte-order mark) then the
5699 ** first two bytes of input are skipped and the remaining input
5700 ** is interpreted as UTF16BE text.
5701 **
5702 ** ^For UTF16 input text to the sqlite3_result_text16(),
5703 ** sqlite3_result_text16be(), sqlite3_result_text16le(), and
5704 ** sqlite3_result_text64() routines, if the text contains invalid
5705 ** UTF16 characters, the invalid characters might be converted
5706 ** into the unicode replacement character, U+FFFD.
5707 **
5708 ** ^The sqlite3_result_value() interface sets the result of
5709 ** the application-defined function to be a copy of the
5710 ** [unprotected sqlite3_value] object specified by the 2nd parameter. ^The
5711 ** sqlite3_result_value() interface makes a copy of the [sqlite3_value]
5712

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button