Fossil SCM

Update the built-in SQLite to version 3.31.1 plus the s390x architecture fix.

jan.nijtmans 2020-02-12 09:25 UTC trunk
Commit 22a9cc7f8bba729630b5531aebd223dad7139e520ffa0bf87a8c9de1348f6e7c
+1 -1
--- Dockerfile
+++ Dockerfile
@@ -5,11 +5,11 @@
55
66
### Now install some additional parts we will need for the build
77
RUN dnf update -y && dnf install -y gcc make tcl tcl-devel zlib-devel openssl-devel tar && dnf clean all && groupadd -r fossil -g 433 && useradd -u 431 -r -g fossil -d /opt/fossil -s /sbin/nologin -c "Fossil user" fossil
88
99
### If you want to build "trunk", change the next line accordingly.
10
-ENV FOSSIL_INSTALL_VERSION release
10
+ENV FOSSIL_INSTALL_VERSION branch-2.10
1111
1212
RUN curl "https://www.fossil-scm.org/index.html/tarball/fossil-src.tar.gz?name=fossil-src&uuid=${FOSSIL_INSTALL_VERSION}" | tar zx
1313
RUN cd fossil-src && ./configure --disable-fusefs --json --with-th1-docs --with-th1-hooks --with-tcl=1 --with-tcl-stubs --with-tcl-private-stubs
1414
RUN cd fossil-src/src && mv main.c main.c.orig && sed s/\"now\"/0/ <main.c.orig >main.c
1515
RUN cd fossil-src && make && strip fossil && cp fossil /usr/bin && cd .. && rm -rf fossil-src && chmod a+rx /usr/bin/fossil && mkdir -p /opt/fossil && chown fossil:fossil /opt/fossil
1616
--- Dockerfile
+++ Dockerfile
@@ -5,11 +5,11 @@
5
6 ### Now install some additional parts we will need for the build
7 RUN dnf update -y && dnf install -y gcc make tcl tcl-devel zlib-devel openssl-devel tar && dnf clean all && groupadd -r fossil -g 433 && useradd -u 431 -r -g fossil -d /opt/fossil -s /sbin/nologin -c "Fossil user" fossil
8
9 ### If you want to build "trunk", change the next line accordingly.
10 ENV FOSSIL_INSTALL_VERSION release
11
12 RUN curl "https://www.fossil-scm.org/index.html/tarball/fossil-src.tar.gz?name=fossil-src&uuid=${FOSSIL_INSTALL_VERSION}" | tar zx
13 RUN cd fossil-src && ./configure --disable-fusefs --json --with-th1-docs --with-th1-hooks --with-tcl=1 --with-tcl-stubs --with-tcl-private-stubs
14 RUN cd fossil-src/src && mv main.c main.c.orig && sed s/\"now\"/0/ <main.c.orig >main.c
15 RUN cd fossil-src && make && strip fossil && cp fossil /usr/bin && cd .. && rm -rf fossil-src && chmod a+rx /usr/bin/fossil && mkdir -p /opt/fossil && chown fossil:fossil /opt/fossil
16
--- Dockerfile
+++ Dockerfile
@@ -5,11 +5,11 @@
5
6 ### Now install some additional parts we will need for the build
7 RUN dnf update -y && dnf install -y gcc make tcl tcl-devel zlib-devel openssl-devel tar && dnf clean all && groupadd -r fossil -g 433 && useradd -u 431 -r -g fossil -d /opt/fossil -s /sbin/nologin -c "Fossil user" fossil
8
9 ### If you want to build "trunk", change the next line accordingly.
10 ENV FOSSIL_INSTALL_VERSION branch-2.10
11
12 RUN curl "https://www.fossil-scm.org/index.html/tarball/fossil-src.tar.gz?name=fossil-src&uuid=${FOSSIL_INSTALL_VERSION}" | tar zx
13 RUN cd fossil-src && ./configure --disable-fusefs --json --with-th1-docs --with-th1-hooks --with-tcl=1 --with-tcl-stubs --with-tcl-private-stubs
14 RUN cd fossil-src/src && mv main.c main.c.orig && sed s/\"now\"/0/ <main.c.orig >main.c
15 RUN cd fossil-src && make && strip fossil && cp fossil /usr/bin && cd .. && rm -rf fossil-src && chmod a+rx /usr/bin/fossil && mkdir -p /opt/fossil && chown fossil:fossil /opt/fossil
16
+1 -1
--- Dockerfile
+++ Dockerfile
@@ -5,11 +5,11 @@
55
66
### Now install some additional parts we will need for the build
77
RUN dnf update -y && dnf install -y gcc make tcl tcl-devel zlib-devel openssl-devel tar && dnf clean all && groupadd -r fossil -g 433 && useradd -u 431 -r -g fossil -d /opt/fossil -s /sbin/nologin -c "Fossil user" fossil
88
99
### If you want to build "trunk", change the next line accordingly.
10
-ENV FOSSIL_INSTALL_VERSION release
10
+ENV FOSSIL_INSTALL_VERSION branch-2.10
1111
1212
RUN curl "https://www.fossil-scm.org/index.html/tarball/fossil-src.tar.gz?name=fossil-src&uuid=${FOSSIL_INSTALL_VERSION}" | tar zx
1313
RUN cd fossil-src && ./configure --disable-fusefs --json --with-th1-docs --with-th1-hooks --with-tcl=1 --with-tcl-stubs --with-tcl-private-stubs
1414
RUN cd fossil-src/src && mv main.c main.c.orig && sed s/\"now\"/0/ <main.c.orig >main.c
1515
RUN cd fossil-src && make && strip fossil && cp fossil /usr/bin && cd .. && rm -rf fossil-src && chmod a+rx /usr/bin/fossil && mkdir -p /opt/fossil && chown fossil:fossil /opt/fossil
1616
--- Dockerfile
+++ Dockerfile
@@ -5,11 +5,11 @@
5
6 ### Now install some additional parts we will need for the build
7 RUN dnf update -y && dnf install -y gcc make tcl tcl-devel zlib-devel openssl-devel tar && dnf clean all && groupadd -r fossil -g 433 && useradd -u 431 -r -g fossil -d /opt/fossil -s /sbin/nologin -c "Fossil user" fossil
8
9 ### If you want to build "trunk", change the next line accordingly.
10 ENV FOSSIL_INSTALL_VERSION release
11
12 RUN curl "https://www.fossil-scm.org/index.html/tarball/fossil-src.tar.gz?name=fossil-src&uuid=${FOSSIL_INSTALL_VERSION}" | tar zx
13 RUN cd fossil-src && ./configure --disable-fusefs --json --with-th1-docs --with-th1-hooks --with-tcl=1 --with-tcl-stubs --with-tcl-private-stubs
14 RUN cd fossil-src/src && mv main.c main.c.orig && sed s/\"now\"/0/ <main.c.orig >main.c
15 RUN cd fossil-src && make && strip fossil && cp fossil /usr/bin && cd .. && rm -rf fossil-src && chmod a+rx /usr/bin/fossil && mkdir -p /opt/fossil && chown fossil:fossil /opt/fossil
16
--- Dockerfile
+++ Dockerfile
@@ -5,11 +5,11 @@
5
6 ### Now install some additional parts we will need for the build
7 RUN dnf update -y && dnf install -y gcc make tcl tcl-devel zlib-devel openssl-devel tar && dnf clean all && groupadd -r fossil -g 433 && useradd -u 431 -r -g fossil -d /opt/fossil -s /sbin/nologin -c "Fossil user" fossil
8
9 ### If you want to build "trunk", change the next line accordingly.
10 ENV FOSSIL_INSTALL_VERSION branch-2.10
11
12 RUN curl "https://www.fossil-scm.org/index.html/tarball/fossil-src.tar.gz?name=fossil-src&uuid=${FOSSIL_INSTALL_VERSION}" | tar zx
13 RUN cd fossil-src && ./configure --disable-fusefs --json --with-th1-docs --with-th1-hooks --with-tcl=1 --with-tcl-stubs --with-tcl-private-stubs
14 RUN cd fossil-src/src && mv main.c main.c.orig && sed s/\"now\"/0/ <main.c.orig >main.c
15 RUN cd fossil-src && make && strip fossil && cp fossil /usr/bin && cd .. && rm -rf fossil-src && chmod a+rx /usr/bin/fossil && mkdir -p /opt/fossil && chown fossil:fossil /opt/fossil
16
+1 -1
--- Dockerfile
+++ Dockerfile
@@ -5,11 +5,11 @@
55
66
### Now install some additional parts we will need for the build
77
RUN dnf update -y && dnf install -y gcc make tcl tcl-devel zlib-devel openssl-devel tar && dnf clean all && groupadd -r fossil -g 433 && useradd -u 431 -r -g fossil -d /opt/fossil -s /sbin/nologin -c "Fossil user" fossil
88
99
### If you want to build "trunk", change the next line accordingly.
10
-ENV FOSSIL_INSTALL_VERSION release
10
+ENV FOSSIL_INSTALL_VERSION branch-2.10
1111
1212
RUN curl "https://www.fossil-scm.org/index.html/tarball/fossil-src.tar.gz?name=fossil-src&uuid=${FOSSIL_INSTALL_VERSION}" | tar zx
1313
RUN cd fossil-src && ./configure --disable-fusefs --json --with-th1-docs --with-th1-hooks --with-tcl=1 --with-tcl-stubs --with-tcl-private-stubs
1414
RUN cd fossil-src/src && mv main.c main.c.orig && sed s/\"now\"/0/ <main.c.orig >main.c
1515
RUN cd fossil-src && make && strip fossil && cp fossil /usr/bin && cd .. && rm -rf fossil-src && chmod a+rx /usr/bin/fossil && mkdir -p /opt/fossil && chown fossil:fossil /opt/fossil
1616
--- Dockerfile
+++ Dockerfile
@@ -5,11 +5,11 @@
5
6 ### Now install some additional parts we will need for the build
7 RUN dnf update -y && dnf install -y gcc make tcl tcl-devel zlib-devel openssl-devel tar && dnf clean all && groupadd -r fossil -g 433 && useradd -u 431 -r -g fossil -d /opt/fossil -s /sbin/nologin -c "Fossil user" fossil
8
9 ### If you want to build "trunk", change the next line accordingly.
10 ENV FOSSIL_INSTALL_VERSION release
11
12 RUN curl "https://www.fossil-scm.org/index.html/tarball/fossil-src.tar.gz?name=fossil-src&uuid=${FOSSIL_INSTALL_VERSION}" | tar zx
13 RUN cd fossil-src && ./configure --disable-fusefs --json --with-th1-docs --with-th1-hooks --with-tcl=1 --with-tcl-stubs --with-tcl-private-stubs
14 RUN cd fossil-src/src && mv main.c main.c.orig && sed s/\"now\"/0/ <main.c.orig >main.c
15 RUN cd fossil-src && make && strip fossil && cp fossil /usr/bin && cd .. && rm -rf fossil-src && chmod a+rx /usr/bin/fossil && mkdir -p /opt/fossil && chown fossil:fossil /opt/fossil
16
--- Dockerfile
+++ Dockerfile
@@ -5,11 +5,11 @@
5
6 ### Now install some additional parts we will need for the build
7 RUN dnf update -y && dnf install -y gcc make tcl tcl-devel zlib-devel openssl-devel tar && dnf clean all && groupadd -r fossil -g 433 && useradd -u 431 -r -g fossil -d /opt/fossil -s /sbin/nologin -c "Fossil user" fossil
8
9 ### If you want to build "trunk", change the next line accordingly.
10 ENV FOSSIL_INSTALL_VERSION branch-2.10
11
12 RUN curl "https://www.fossil-scm.org/index.html/tarball/fossil-src.tar.gz?name=fossil-src&uuid=${FOSSIL_INSTALL_VERSION}" | tar zx
13 RUN cd fossil-src && ./configure --disable-fusefs --json --with-th1-docs --with-th1-hooks --with-tcl=1 --with-tcl-stubs --with-tcl-private-stubs
14 RUN cd fossil-src/src && mv main.c main.c.orig && sed s/\"now\"/0/ <main.c.orig >main.c
15 RUN cd fossil-src && make && strip fossil && cp fossil /usr/bin && cd .. && rm -rf fossil-src && chmod a+rx /usr/bin/fossil && mkdir -p /opt/fossil && chown fossil:fossil /opt/fossil
16
+10 -9
--- src/search.c
+++ src/search.c
@@ -530,26 +530,27 @@
530530
** Register the various SQL functions (defined above) needed to implement
531531
** full-scan search.
532532
*/
533533
void search_sql_setup(sqlite3 *db){
534534
static int once = 0;
535
+ static const int enc = SQLITE_UTF8|SQLITE_INNOCUOUS;
535536
if( once++ ) return;
536
- sqlite3_create_function(db, "search_match", -1, SQLITE_UTF8, 0,
537
+ sqlite3_create_function(db, "search_match", -1, enc, 0,
537538
search_match_sqlfunc, 0, 0);
538
- sqlite3_create_function(db, "search_score", 0, SQLITE_UTF8, 0,
539
+ sqlite3_create_function(db, "search_score", 0, enc, 0,
539540
search_score_sqlfunc, 0, 0);
540
- sqlite3_create_function(db, "search_snippet", 0, SQLITE_UTF8, 0,
541
+ sqlite3_create_function(db, "search_snippet", 0, enc, 0,
541542
search_snippet_sqlfunc, 0, 0);
542
- sqlite3_create_function(db, "search_init", -1, SQLITE_UTF8, 0,
543
+ sqlite3_create_function(db, "search_init", -1, enc, 0,
543544
search_init_sqlfunc, 0, 0);
544
- sqlite3_create_function(db, "stext", 3, SQLITE_UTF8, 0,
545
+ sqlite3_create_function(db, "stext", 3, enc, 0,
545546
search_stext_sqlfunc, 0, 0);
546
- sqlite3_create_function(db, "title", 3, SQLITE_UTF8, 0,
547
+ sqlite3_create_function(db, "title", 3, enc, 0,
547548
search_title_sqlfunc, 0, 0);
548
- sqlite3_create_function(db, "body", 3, SQLITE_UTF8, 0,
549
+ sqlite3_create_function(db, "body", 3, enc, 0,
549550
search_body_sqlfunc, 0, 0);
550
- sqlite3_create_function(db, "urlencode", 1, SQLITE_UTF8, 0,
551
+ sqlite3_create_function(db, "urlencode", 1, enc, 0,
551552
search_urlencode_sqlfunc, 0, 0);
552553
}
553554
554555
/*
555556
** Testing the search function.
@@ -905,11 +906,11 @@
905906
const char *zPattern, /* The query pattern */
906907
unsigned int srchFlags /* What to search over */
907908
){
908909
Blob sql;
909910
if( srchFlags==0 ) return;
910
- sqlite3_create_function(g.db, "rank", 1, SQLITE_UTF8, 0,
911
+ sqlite3_create_function(g.db, "rank", 1, SQLITE_UTF8|SQLITE_INNOCUOUS, 0,
911912
search_rank_sqlfunc, 0, 0);
912913
blob_init(&sql, 0, 0);
913914
blob_appendf(&sql,
914915
"INSERT INTO x(label,url,score,id,date,snip) "
915916
" SELECT ftsdocs.label,"
916917
--- src/search.c
+++ src/search.c
@@ -530,26 +530,27 @@
530 ** Register the various SQL functions (defined above) needed to implement
531 ** full-scan search.
532 */
533 void search_sql_setup(sqlite3 *db){
534 static int once = 0;
 
535 if( once++ ) return;
536 sqlite3_create_function(db, "search_match", -1, SQLITE_UTF8, 0,
537 search_match_sqlfunc, 0, 0);
538 sqlite3_create_function(db, "search_score", 0, SQLITE_UTF8, 0,
539 search_score_sqlfunc, 0, 0);
540 sqlite3_create_function(db, "search_snippet", 0, SQLITE_UTF8, 0,
541 search_snippet_sqlfunc, 0, 0);
542 sqlite3_create_function(db, "search_init", -1, SQLITE_UTF8, 0,
543 search_init_sqlfunc, 0, 0);
544 sqlite3_create_function(db, "stext", 3, SQLITE_UTF8, 0,
545 search_stext_sqlfunc, 0, 0);
546 sqlite3_create_function(db, "title", 3, SQLITE_UTF8, 0,
547 search_title_sqlfunc, 0, 0);
548 sqlite3_create_function(db, "body", 3, SQLITE_UTF8, 0,
549 search_body_sqlfunc, 0, 0);
550 sqlite3_create_function(db, "urlencode", 1, SQLITE_UTF8, 0,
551 search_urlencode_sqlfunc, 0, 0);
552 }
553
554 /*
555 ** Testing the search function.
@@ -905,11 +906,11 @@
905 const char *zPattern, /* The query pattern */
906 unsigned int srchFlags /* What to search over */
907 ){
908 Blob sql;
909 if( srchFlags==0 ) return;
910 sqlite3_create_function(g.db, "rank", 1, SQLITE_UTF8, 0,
911 search_rank_sqlfunc, 0, 0);
912 blob_init(&sql, 0, 0);
913 blob_appendf(&sql,
914 "INSERT INTO x(label,url,score,id,date,snip) "
915 " SELECT ftsdocs.label,"
916
--- src/search.c
+++ src/search.c
@@ -530,26 +530,27 @@
530 ** Register the various SQL functions (defined above) needed to implement
531 ** full-scan search.
532 */
533 void search_sql_setup(sqlite3 *db){
534 static int once = 0;
535 static const int enc = SQLITE_UTF8|SQLITE_INNOCUOUS;
536 if( once++ ) return;
537 sqlite3_create_function(db, "search_match", -1, enc, 0,
538 search_match_sqlfunc, 0, 0);
539 sqlite3_create_function(db, "search_score", 0, enc, 0,
540 search_score_sqlfunc, 0, 0);
541 sqlite3_create_function(db, "search_snippet", 0, enc, 0,
542 search_snippet_sqlfunc, 0, 0);
543 sqlite3_create_function(db, "search_init", -1, enc, 0,
544 search_init_sqlfunc, 0, 0);
545 sqlite3_create_function(db, "stext", 3, enc, 0,
546 search_stext_sqlfunc, 0, 0);
547 sqlite3_create_function(db, "title", 3, enc, 0,
548 search_title_sqlfunc, 0, 0);
549 sqlite3_create_function(db, "body", 3, enc, 0,
550 search_body_sqlfunc, 0, 0);
551 sqlite3_create_function(db, "urlencode", 1, enc, 0,
552 search_urlencode_sqlfunc, 0, 0);
553 }
554
555 /*
556 ** Testing the search function.
@@ -905,11 +906,11 @@
906 const char *zPattern, /* The query pattern */
907 unsigned int srchFlags /* What to search over */
908 ){
909 Blob sql;
910 if( srchFlags==0 ) return;
911 sqlite3_create_function(g.db, "rank", 1, SQLITE_UTF8|SQLITE_INNOCUOUS, 0,
912 search_rank_sqlfunc, 0, 0);
913 blob_init(&sql, 0, 0);
914 blob_appendf(&sql,
915 "INSERT INTO x(label,url,score,id,date,snip) "
916 " SELECT ftsdocs.label,"
917
+129 -62
--- src/shell.c
+++ src/shell.c
@@ -2005,23 +2005,27 @@
20052005
const sqlite3_api_routines *pApi
20062006
){
20072007
int rc = SQLITE_OK;
20082008
SQLITE_EXTENSION_INIT2(pApi);
20092009
(void)pzErrMsg; /* Unused parameter */
2010
- rc = sqlite3_create_function(db, "sha3", 1, SQLITE_UTF8, 0,
2011
- sha3Func, 0, 0);
2010
+ rc = sqlite3_create_function(db, "sha3", 1,
2011
+ SQLITE_UTF8 | SQLITE_INNOCUOUS | SQLITE_DETERMINISTIC,
2012
+ 0, sha3Func, 0, 0);
2013
+ if( rc==SQLITE_OK ){
2014
+ rc = sqlite3_create_function(db, "sha3", 2,
2015
+ SQLITE_UTF8 | SQLITE_INNOCUOUS | SQLITE_DETERMINISTIC,
2016
+ 0, sha3Func, 0, 0);
2017
+ }
20122018
if( rc==SQLITE_OK ){
2013
- rc = sqlite3_create_function(db, "sha3", 2, SQLITE_UTF8, 0,
2014
- sha3Func, 0, 0);
2019
+ rc = sqlite3_create_function(db, "sha3_query", 1,
2020
+ SQLITE_UTF8 | SQLITE_DIRECTONLY,
2021
+ 0, sha3QueryFunc, 0, 0);
20152022
}
20162023
if( rc==SQLITE_OK ){
2017
- rc = sqlite3_create_function(db, "sha3_query", 1, SQLITE_UTF8, 0,
2018
- sha3QueryFunc, 0, 0);
2019
- }
2020
- if( rc==SQLITE_OK ){
2021
- rc = sqlite3_create_function(db, "sha3_query", 2, SQLITE_UTF8, 0,
2022
- sha3QueryFunc, 0, 0);
2024
+ rc = sqlite3_create_function(db, "sha3_query", 2,
2025
+ SQLITE_UTF8 | SQLITE_DIRECTONLY,
2026
+ 0, sha3QueryFunc, 0, 0);
20232027
}
20242028
return rc;
20252029
}
20262030
20272031
/************************* End ../ext/misc/shathree.c ********************/
@@ -2611,10 +2615,11 @@
26112615
rc = sqlite3_declare_vtab(db, "CREATE TABLE x" FSDIR_SCHEMA);
26122616
if( rc==SQLITE_OK ){
26132617
pNew = (fsdir_tab*)sqlite3_malloc( sizeof(*pNew) );
26142618
if( pNew==0 ) return SQLITE_NOMEM;
26152619
memset(pNew, 0, sizeof(*pNew));
2620
+ sqlite3_vtab_config(db, SQLITE_VTAB_DIRECTONLY);
26162621
}
26172622
*ppVtab = (sqlite3_vtab*)pNew;
26182623
return rc;
26192624
}
26202625
@@ -3004,14 +3009,16 @@
30043009
const sqlite3_api_routines *pApi
30053010
){
30063011
int rc = SQLITE_OK;
30073012
SQLITE_EXTENSION_INIT2(pApi);
30083013
(void)pzErrMsg; /* Unused parameter */
3009
- rc = sqlite3_create_function(db, "readfile", 1, SQLITE_UTF8, 0,
3014
+ rc = sqlite3_create_function(db, "readfile", 1,
3015
+ SQLITE_UTF8|SQLITE_DIRECTONLY, 0,
30103016
readfileFunc, 0, 0);
30113017
if( rc==SQLITE_OK ){
3012
- rc = sqlite3_create_function(db, "writefile", -1, SQLITE_UTF8, 0,
3018
+ rc = sqlite3_create_function(db, "writefile", -1,
3019
+ SQLITE_UTF8|SQLITE_DIRECTONLY, 0,
30133020
writefileFunc, 0, 0);
30143021
}
30153022
if( rc==SQLITE_OK ){
30163023
rc = sqlite3_create_function(db, "lsmode", 1, SQLITE_UTF8, 0,
30173024
lsModeFunc, 0, 0);
@@ -3142,10 +3149,11 @@
31423149
#define COMPLETION_COLUMN_CANDIDATE 0 /* Suggested completion of the input */
31433150
#define COMPLETION_COLUMN_PREFIX 1 /* Prefix of the word to be completed */
31443151
#define COMPLETION_COLUMN_WHOLELINE 2 /* Entire line seen so far */
31453152
#define COMPLETION_COLUMN_PHASE 3 /* ePhase - used for debugging only */
31463153
3154
+ sqlite3_vtab_config(db, SQLITE_VTAB_INNOCUOUS);
31473155
rc = sqlite3_declare_vtab(db,
31483156
"CREATE TABLE x("
31493157
" candidate TEXT,"
31503158
" prefix TEXT HIDDEN,"
31513159
" wholeline TEXT HIDDEN,"
@@ -4576,10 +4584,11 @@
45764584
pNew->zFile = (char*)&pNew->aBuffer[ZIPFILE_BUFFER_SIZE];
45774585
memcpy(pNew->zFile, zFile, nFile);
45784586
zipfileDequote(pNew->zFile);
45794587
}
45804588
}
4589
+ sqlite3_vtab_config(db, SQLITE_VTAB_DIRECTONLY);
45814590
*ppVtab = (sqlite3_vtab*)pNew;
45824591
return rc;
45834592
}
45844593
45854594
/*
@@ -5188,29 +5197,29 @@
51885197
static int zipfileDeflate(
51895198
const u8 *aIn, int nIn, /* Input */
51905199
u8 **ppOut, int *pnOut, /* Output */
51915200
char **pzErr /* OUT: Error message */
51925201
){
5193
- sqlite3_int64 nAlloc = compressBound(nIn);
5202
+ int rc = SQLITE_OK;
5203
+ sqlite3_int64 nAlloc;
5204
+ z_stream str;
51945205
u8 *aOut;
5195
- int rc = SQLITE_OK;
51965206
5207
+ memset(&str, 0, sizeof(str));
5208
+ str.next_in = (Bytef*)aIn;
5209
+ str.avail_in = nIn;
5210
+ deflateInit2(&str, 9, Z_DEFLATED, -15, 8, Z_DEFAULT_STRATEGY);
5211
+
5212
+ nAlloc = deflateBound(&str, nIn);
51975213
aOut = (u8*)sqlite3_malloc64(nAlloc);
51985214
if( aOut==0 ){
51995215
rc = SQLITE_NOMEM;
52005216
}else{
52015217
int res;
5202
- z_stream str;
5203
- memset(&str, 0, sizeof(str));
5204
- str.next_in = (Bytef*)aIn;
5205
- str.avail_in = nIn;
52065218
str.next_out = aOut;
52075219
str.avail_out = nAlloc;
5208
-
5209
- deflateInit2(&str, 9, Z_DEFLATED, -15, 8, Z_DEFAULT_STRATEGY);
52105220
res = deflate(&str, Z_FINISH);
5211
-
52125221
if( res==Z_STREAM_END ){
52135222
*ppOut = aOut;
52145223
*pnOut = (int)str.total_out;
52155224
}else{
52165225
sqlite3_free(aOut);
@@ -5515,14 +5524,14 @@
55155524
unusable = 1;
55165525
}else if( pCons->op==SQLITE_INDEX_CONSTRAINT_EQ ){
55175526
idx = i;
55185527
}
55195528
}
5529
+ pIdxInfo->estimatedCost = 1000.0;
55205530
if( idx>=0 ){
55215531
pIdxInfo->aConstraintUsage[idx].argvIndex = 1;
55225532
pIdxInfo->aConstraintUsage[idx].omit = 1;
5523
- pIdxInfo->estimatedCost = 1000.0;
55245533
pIdxInfo->idxNum = 1;
55255534
}else if( unusable ){
55265535
return SQLITE_CONSTRAINT;
55275536
}
55285537
return SQLITE_OK;
@@ -5640,21 +5649,25 @@
56405649
** Both (const char*) arguments point to nul-terminated strings. Argument
56415650
** nB is the value of strlen(zB). This function returns 0 if the strings are
56425651
** identical, ignoring any trailing '/' character in either path. */
56435652
static int zipfileComparePath(const char *zA, const char *zB, int nB){
56445653
int nA = (int)strlen(zA);
5645
- if( zA[nA-1]=='/' ) nA--;
5646
- if( zB[nB-1]=='/' ) nB--;
5654
+ if( nA>0 && zA[nA-1]=='/' ) nA--;
5655
+ if( nB>0 && zB[nB-1]=='/' ) nB--;
56475656
if( nA==nB && memcmp(zA, zB, nA)==0 ) return 0;
56485657
return 1;
56495658
}
56505659
56515660
static int zipfileBegin(sqlite3_vtab *pVtab){
56525661
ZipfileTab *pTab = (ZipfileTab*)pVtab;
56535662
int rc = SQLITE_OK;
56545663
56555664
assert( pTab->pWriteFd==0 );
5665
+ if( pTab->zFile==0 || pTab->zFile[0]==0 ){
5666
+ pTab->base.zErrMsg = sqlite3_mprintf("zipfile: missing filename");
5667
+ return SQLITE_ERROR;
5668
+ }
56565669
56575670
/* Open a write fd on the file. Also load the entire central directory
56585671
** structure into memory. During the transaction any new file data is
56595672
** appended to the archive file, but the central directory is accumulated
56605673
** in main-memory until the transaction is committed. */
@@ -5825,24 +5838,29 @@
58255838
rc = zipfileGetMode(apVal[3], bIsDir, &mode, &pTab->base.zErrMsg);
58265839
}
58275840
58285841
if( rc==SQLITE_OK ){
58295842
zPath = (const char*)sqlite3_value_text(apVal[2]);
5843
+ if( zPath==0 ) zPath = "";
58305844
nPath = (int)strlen(zPath);
58315845
mTime = zipfileGetTime(apVal[4]);
58325846
}
58335847
58345848
if( rc==SQLITE_OK && bIsDir ){
58355849
/* For a directory, check that the last character in the path is a
58365850
** '/'. This appears to be required for compatibility with info-zip
58375851
** (the unzip command on unix). It does not create directories
58385852
** otherwise. */
5839
- if( zPath[nPath-1]!='/' ){
5853
+ if( nPath<=0 || zPath[nPath-1]!='/' ){
58405854
zFree = sqlite3_mprintf("%s/", zPath);
5841
- if( zFree==0 ){ rc = SQLITE_NOMEM; }
58425855
zPath = (const char*)zFree;
5843
- nPath++;
5856
+ if( zFree==0 ){
5857
+ rc = SQLITE_NOMEM;
5858
+ nPath = 0;
5859
+ }else{
5860
+ nPath = (int)strlen(zPath);
5861
+ }
58445862
}
58455863
}
58465864
58475865
/* Check that we're not inserting a duplicate entry -OR- updating an
58485866
** entry with a path, thereby making it into a duplicate. */
@@ -6231,23 +6249,23 @@
62316249
62326250
/* If this is a directory entry, ensure that there is exactly one '/'
62336251
** at the end of the path. Or, if this is not a directory and the path
62346252
** ends in '/' it is an error. */
62356253
if( bIsDir==0 ){
6236
- if( zName[nName-1]=='/' ){
6254
+ if( nName>0 && zName[nName-1]=='/' ){
62376255
zErr = sqlite3_mprintf("non-directory name must not end with /");
62386256
rc = SQLITE_ERROR;
62396257
goto zipfile_step_out;
62406258
}
62416259
}else{
6242
- if( zName[nName-1]!='/' ){
6260
+ if( nName==0 || zName[nName-1]!='/' ){
62436261
zName = zFree = sqlite3_mprintf("%s/", zName);
6244
- nName++;
62456262
if( zName==0 ){
62466263
rc = SQLITE_NOMEM;
62476264
goto zipfile_step_out;
62486265
}
6266
+ nName = (int)strlen(zName);
62496267
}else{
62506268
while( nName>1 && zName[nName-2]=='/' ) nName--;
62516269
}
62526270
}
62536271
@@ -6499,14 +6517,16 @@
64996517
const sqlite3_api_routines *pApi
65006518
){
65016519
int rc = SQLITE_OK;
65026520
SQLITE_EXTENSION_INIT2(pApi);
65036521
(void)pzErrMsg; /* Unused parameter */
6504
- rc = sqlite3_create_function(db, "sqlar_compress", 1, SQLITE_UTF8, 0,
6522
+ rc = sqlite3_create_function(db, "sqlar_compress", 1,
6523
+ SQLITE_UTF8|SQLITE_INNOCUOUS, 0,
65056524
sqlarCompressFunc, 0, 0);
65066525
if( rc==SQLITE_OK ){
6507
- rc = sqlite3_create_function(db, "sqlar_uncompress", 2, SQLITE_UTF8, 0,
6526
+ rc = sqlite3_create_function(db, "sqlar_uncompress", 2,
6527
+ SQLITE_UTF8|SQLITE_INNOCUOUS, 0,
65086528
sqlarUncompressFunc, 0, 0);
65096529
}
65106530
return rc;
65116531
}
65126532
@@ -6523,12 +6543,12 @@
65236543
** May you find forgiveness for yourself and forgive others.
65246544
** May you share freely, never taking more than you give.
65256545
**
65266546
*************************************************************************
65276547
*/
6528
-
6529
-
6548
+#if !defined(SQLITEEXPERT_H)
6549
+#define SQLITEEXPERT_H 1
65306550
/* #include "sqlite3.h" */
65316551
65326552
typedef struct sqlite3expert sqlite3expert;
65336553
65346554
/*
@@ -6678,11 +6698,11 @@
66786698
** should be one call to this function for each successful call to
66796699
** sqlite3-expert_new().
66806700
*/
66816701
void sqlite3_expert_destroy(sqlite3expert*);
66826702
6683
-
6703
+#endif /* !defined(SQLITEEXPERT_H) */
66846704
66856705
/************************* End ../ext/expert/sqlite3expert.h ********************/
66866706
/************************* Begin ../ext/expert/sqlite3expert.c ******************/
66876707
/*
66886708
** 2017 April 09
@@ -9564,10 +9584,11 @@
95649584
u8 eTraceType; /* SHELL_TRACE_* value for type of trace */
95659585
unsigned mEqpLines; /* Mask of veritical lines in the EQP output graph */
95669586
int outCount; /* Revert to stdout when reaching zero */
95679587
int cnt; /* Number of records displayed so far */
95689588
int lineno; /* Line number of last line read from in */
9589
+ int openFlags; /* Additional flags to open. (SQLITE_OPEN_NOFOLLOW) */
95699590
FILE *in; /* Read commands from this stream */
95709591
FILE *out; /* Write results here */
95719592
FILE *traceOut; /* Output for sqlite3_trace() */
95729593
int nErr; /* Number of errors seen */
95739594
int mode; /* An output mode setting */
@@ -10398,23 +10419,26 @@
1039810419
case MODE_Column: {
1039910420
static const int aExplainWidths[] = {4, 13, 4, 4, 4, 13, 2, 13};
1040010421
const int *colWidth;
1040110422
int showHdr;
1040210423
char *rowSep;
10424
+ int nWidth;
1040310425
if( p->cMode==MODE_Column ){
1040410426
colWidth = p->colWidth;
10427
+ nWidth = ArraySize(p->colWidth);
1040510428
showHdr = p->showHeader;
1040610429
rowSep = p->rowSeparator;
1040710430
}else{
1040810431
colWidth = aExplainWidths;
10432
+ nWidth = ArraySize(aExplainWidths);
1040910433
showHdr = 1;
1041010434
rowSep = SEP_Row;
1041110435
}
1041210436
if( p->cnt++==0 ){
1041310437
for(i=0; i<nArg; i++){
1041410438
int w, n;
10415
- if( i<ArraySize(p->colWidth) ){
10439
+ if( i<nWidth ){
1041610440
w = colWidth[i];
1041710441
}else{
1041810442
w = 0;
1041910443
}
1042010444
if( w==0 ){
@@ -11300,19 +11324,23 @@
1130011324
}
1130111325
1130211326
/* Create the TEMP table used to store parameter bindings */
1130311327
static void bind_table_init(ShellState *p){
1130411328
int wrSchema = 0;
11329
+ int defensiveMode = 0;
11330
+ sqlite3_db_config(p->db, SQLITE_DBCONFIG_DEFENSIVE, -1, &defensiveMode);
11331
+ sqlite3_db_config(p->db, SQLITE_DBCONFIG_DEFENSIVE, 0, 0);
1130511332
sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, -1, &wrSchema);
1130611333
sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, 1, 0);
1130711334
sqlite3_exec(p->db,
1130811335
"CREATE TABLE IF NOT EXISTS temp.sqlite_parameters(\n"
1130911336
" key TEXT PRIMARY KEY,\n"
1131011337
" value ANY\n"
1131111338
") WITHOUT ROWID;",
1131211339
0, 0, 0);
1131311340
sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, wrSchema, 0);
11341
+ sqlite3_db_config(p->db, SQLITE_DBCONFIG_DEFENSIVE, defensiveMode, 0);
1131411342
}
1131511343
1131611344
/*
1131711345
** Bind parameters on a prepared statement.
1131811346
**
@@ -12051,13 +12079,11 @@
1205112079
#endif
1205212080
" trigger Like \"full\" but also show trigger bytecode",
1205312081
".excel Display the output of next command in spreadsheet",
1205412082
".exit ?CODE? Exit this program with return-code CODE",
1205512083
".expert EXPERIMENTAL. Suggest indexes for queries",
12056
-/* Because explain mode comes on automatically now, the ".explain" mode
12057
-** is removed from the help screen. It is still supported for legacy, however */
12058
-/*".explain ?on|off|auto? Turn EXPLAIN output mode on or off",*/
12084
+ ".explain ?on|off|auto? Change the EXPLAIN formatting mode. Default: auto",
1205912085
".filectrl CMD ... Run various sqlite3_file_control() operations",
1206012086
" Run \".filectrl\" with no arguments for details",
1206112087
".fullschema ?--indent? Show schema and the content of sqlite_stat tables",
1206212088
".headers on|off Turn display of headers on or off",
1206312089
".help ?-all? ?PATTERN? Show help text for PATTERN",
@@ -12104,10 +12130,11 @@
1210412130
" --deserialize Load into memory useing sqlite3_deserialize()",
1210512131
" --hexdb Load the output of \"dbtotxt\" as an in-memory db",
1210612132
" --maxsize N Maximum size for --hexdb or --deserialized database",
1210712133
#endif
1210812134
" --new Initialize FILE to an empty database",
12135
+ " --nofollow Do not follow symbolic links",
1210912136
" --readonly Open FILE readonly",
1211012137
" --zip FILE is a ZIP archive",
1211112138
".output ?FILE? Send output to FILE or stdout if FILE is omitted",
1211212139
" If FILE begins with '|' then open it as a pipe.",
1211312140
".parameter CMD ... Manage SQL parameter bindings",
@@ -12668,11 +12695,11 @@
1266812695
}
1266912696
}
1267012697
switch( p->openMode ){
1267112698
case SHELL_OPEN_APPENDVFS: {
1267212699
sqlite3_open_v2(p->zDbFilename, &p->db,
12673
- SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE, "apndvfs");
12700
+ SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|p->openFlags, "apndvfs");
1267412701
break;
1267512702
}
1267612703
case SHELL_OPEN_HEXDB:
1267712704
case SHELL_OPEN_DESERIALIZE: {
1267812705
sqlite3_open(0, &p->db);
@@ -12681,16 +12708,18 @@
1268112708
case SHELL_OPEN_ZIPFILE: {
1268212709
sqlite3_open(":memory:", &p->db);
1268312710
break;
1268412711
}
1268512712
case SHELL_OPEN_READONLY: {
12686
- sqlite3_open_v2(p->zDbFilename, &p->db, SQLITE_OPEN_READONLY, 0);
12713
+ sqlite3_open_v2(p->zDbFilename, &p->db,
12714
+ SQLITE_OPEN_READONLY|p->openFlags, 0);
1268712715
break;
1268812716
}
1268912717
case SHELL_OPEN_UNSPEC:
1269012718
case SHELL_OPEN_NORMAL: {
12691
- sqlite3_open(p->zDbFilename, &p->db);
12719
+ sqlite3_open_v2(p->zDbFilename, &p->db,
12720
+ SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|p->openFlags, 0);
1269212721
break;
1269312722
}
1269412723
}
1269512724
globalDb = p->db;
1269612725
if( p->db==0 || SQLITE_OK!=sqlite3_errcode(p->db) ){
@@ -13460,11 +13489,11 @@
1346013489
static unsigned int get4byteInt(unsigned char *a){
1346113490
return (a[0]<<24) + (a[1]<<16) + (a[2]<<8) + a[3];
1346213491
}
1346313492
1346413493
/*
13465
-** Implementation of the ".info" command.
13494
+** Implementation of the ".dbinfo" command.
1346613495
**
1346713496
** Return 1 on error, 2 to exit, and 0 otherwise.
1346813497
*/
1346913498
static int shell_dbinfo_command(ShellState *p, int nArg, char **azArg){
1347013499
static const struct { const char *zName; int ofst; } aField[] = {
@@ -15697,34 +15726,36 @@
1569715726
if( c=='d' && n>=3 && strncmp(azArg[0], "dbconfig", n)==0 ){
1569815727
static const struct DbConfigChoices {
1569915728
const char *zName;
1570015729
int op;
1570115730
} aDbConfig[] = {
15731
+ { "defensive", SQLITE_DBCONFIG_DEFENSIVE },
15732
+ { "dqs_ddl", SQLITE_DBCONFIG_DQS_DDL },
15733
+ { "dqs_dml", SQLITE_DBCONFIG_DQS_DML },
1570215734
{ "enable_fkey", SQLITE_DBCONFIG_ENABLE_FKEY },
15735
+ { "enable_qpsg", SQLITE_DBCONFIG_ENABLE_QPSG },
1570315736
{ "enable_trigger", SQLITE_DBCONFIG_ENABLE_TRIGGER },
1570415737
{ "enable_view", SQLITE_DBCONFIG_ENABLE_VIEW },
1570515738
{ "fts3_tokenizer", SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER },
15739
+ { "legacy_alter_table", SQLITE_DBCONFIG_LEGACY_ALTER_TABLE },
15740
+ { "legacy_file_format", SQLITE_DBCONFIG_LEGACY_FILE_FORMAT },
1570615741
{ "load_extension", SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION },
1570715742
{ "no_ckpt_on_close", SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE },
15708
- { "enable_qpsg", SQLITE_DBCONFIG_ENABLE_QPSG },
15743
+ { "reset_database", SQLITE_DBCONFIG_RESET_DATABASE },
1570915744
{ "trigger_eqp", SQLITE_DBCONFIG_TRIGGER_EQP },
15710
- { "reset_database", SQLITE_DBCONFIG_RESET_DATABASE },
15711
- { "defensive", SQLITE_DBCONFIG_DEFENSIVE },
15745
+ { "trusted_schema", SQLITE_DBCONFIG_TRUSTED_SCHEMA },
1571215746
{ "writable_schema", SQLITE_DBCONFIG_WRITABLE_SCHEMA },
15713
- { "legacy_alter_table", SQLITE_DBCONFIG_LEGACY_ALTER_TABLE },
15714
- { "dqs_dml", SQLITE_DBCONFIG_DQS_DML },
15715
- { "dqs_ddl", SQLITE_DBCONFIG_DQS_DDL },
1571615747
};
1571715748
int ii, v;
1571815749
open_db(p, 0);
1571915750
for(ii=0; ii<ArraySize(aDbConfig); ii++){
1572015751
if( nArg>1 && strcmp(azArg[1], aDbConfig[ii].zName)!=0 ) continue;
1572115752
if( nArg>=3 ){
1572215753
sqlite3_db_config(p->db, aDbConfig[ii].op, booleanValue(azArg[2]), 0);
1572315754
}
1572415755
sqlite3_db_config(p->db, aDbConfig[ii].op, -1, &v);
15725
- utf8_printf(p->out, "%18s %s\n", aDbConfig[ii].zName, v ? "on" : "off");
15756
+ utf8_printf(p->out, "%19s %s\n", aDbConfig[ii].zName, v ? "on" : "off");
1572615757
if( nArg>1 ) break;
1572715758
}
1572815759
if( nArg>1 && ii==ArraySize(aDbConfig) ){
1572915760
utf8_printf(stderr, "Error: unknown dbconfig \"%s\"\n", azArg[1]);
1573015761
utf8_printf(stderr, "Enter \".dbconfig\" with no arguments for a list\n");
@@ -16301,35 +16332,47 @@
1630116332
if( c=='i' && strncmp(azArg[0], "imposter", n)==0 ){
1630216333
char *zSql;
1630316334
char *zCollist = 0;
1630416335
sqlite3_stmt *pStmt;
1630516336
int tnum = 0;
16337
+ int isWO = 0; /* True if making an imposter of a WITHOUT ROWID table */
16338
+ int lenPK = 0; /* Length of the PRIMARY KEY string for isWO tables */
1630616339
int i;
1630716340
if( !(nArg==3 || (nArg==2 && sqlite3_stricmp(azArg[1],"off")==0)) ){
1630816341
utf8_printf(stderr, "Usage: .imposter INDEX IMPOSTER\n"
1630916342
" .imposter off\n");
16343
+ /* Also allowed, but not documented:
16344
+ **
16345
+ ** .imposter TABLE IMPOSTER
16346
+ **
16347
+ ** where TABLE is a WITHOUT ROWID table. In that case, the
16348
+ ** imposter is another WITHOUT ROWID table with the columns in
16349
+ ** storage order. */
1631016350
rc = 1;
1631116351
goto meta_command_exit;
1631216352
}
1631316353
open_db(p, 0);
1631416354
if( nArg==2 ){
1631516355
sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->db, "main", 0, 1);
1631616356
goto meta_command_exit;
1631716357
}
16318
- zSql = sqlite3_mprintf("SELECT rootpage FROM sqlite_master"
16319
- " WHERE name='%q' AND type='index'", azArg[1]);
16358
+ zSql = sqlite3_mprintf(
16359
+ "SELECT rootpage, 0 FROM sqlite_master"
16360
+ " WHERE name='%q' AND type='index'"
16361
+ "UNION ALL "
16362
+ "SELECT rootpage, 1 FROM sqlite_master"
16363
+ " WHERE name='%q' AND type='table'"
16364
+ " AND sql LIKE '%%without%%rowid%%'",
16365
+ azArg[1], azArg[1]
16366
+ );
1632016367
sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
1632116368
sqlite3_free(zSql);
1632216369
if( sqlite3_step(pStmt)==SQLITE_ROW ){
1632316370
tnum = sqlite3_column_int(pStmt, 0);
16371
+ isWO = sqlite3_column_int(pStmt, 1);
1632416372
}
1632516373
sqlite3_finalize(pStmt);
16326
- if( tnum==0 ){
16327
- utf8_printf(stderr, "no such index: \"%s\"\n", azArg[1]);
16328
- rc = 1;
16329
- goto meta_command_exit;
16330
- }
1633116374
zSql = sqlite3_mprintf("PRAGMA index_xinfo='%q'", azArg[1]);
1633216375
rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
1633316376
sqlite3_free(zSql);
1633416377
i = 0;
1633516378
while( sqlite3_step(pStmt)==SQLITE_ROW ){
@@ -16342,20 +16385,30 @@
1634216385
}else{
1634316386
sqlite3_snprintf(sizeof(zLabel),zLabel,"expr%d",i);
1634416387
zCol = zLabel;
1634516388
}
1634616389
}
16390
+ if( isWO && lenPK==0 && sqlite3_column_int(pStmt,5)==0 && zCollist ){
16391
+ lenPK = (int)strlen(zCollist);
16392
+ }
1634716393
if( zCollist==0 ){
1634816394
zCollist = sqlite3_mprintf("\"%w\"", zCol);
1634916395
}else{
1635016396
zCollist = sqlite3_mprintf("%z,\"%w\"", zCollist, zCol);
1635116397
}
1635216398
}
1635316399
sqlite3_finalize(pStmt);
16400
+ if( i==0 || tnum==0 ){
16401
+ utf8_printf(stderr, "no such index: \"%s\"\n", azArg[1]);
16402
+ rc = 1;
16403
+ sqlite3_free(zCollist);
16404
+ goto meta_command_exit;
16405
+ }
16406
+ if( lenPK==0 ) lenPK = 100000;
1635416407
zSql = sqlite3_mprintf(
16355
- "CREATE TABLE \"%w\"(%s,PRIMARY KEY(%s))WITHOUT ROWID",
16356
- azArg[2], zCollist, zCollist);
16408
+ "CREATE TABLE \"%w\"(%s,PRIMARY KEY(%.*s))WITHOUT ROWID",
16409
+ azArg[2], zCollist, lenPK, zCollist);
1635716410
sqlite3_free(zCollist);
1635816411
rc = sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->db, "main", 1, tnum);
1635916412
if( rc==SQLITE_OK ){
1636016413
rc = sqlite3_exec(p->db, zSql, 0, 0, 0);
1636116414
sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->db, "main", 0, 0);
@@ -16362,11 +16415,12 @@
1636216415
if( rc ){
1636316416
utf8_printf(stderr, "Error in [%s]: %s\n", zSql, sqlite3_errmsg(p->db));
1636416417
}else{
1636516418
utf8_printf(stdout, "%s;\n", zSql);
1636616419
raw_printf(stdout,
16367
- "WARNING: writing to an imposter table will corrupt the index!\n"
16420
+ "WARNING: writing to an imposter table will corrupt the \"%s\" %s!\n",
16421
+ azArg[1], isWO ? "table" : "index"
1636816422
);
1636916423
}
1637016424
}else{
1637116425
raw_printf(stderr, "SQLITE_TESTCTRL_IMPOSTER returns %d\n", rc);
1637216426
rc = 1;
@@ -16560,10 +16614,11 @@
1656016614
p->db = 0;
1656116615
p->zDbFilename = 0;
1656216616
sqlite3_free(p->zFreeOnClose);
1656316617
p->zFreeOnClose = 0;
1656416618
p->openMode = SHELL_OPEN_UNSPEC;
16619
+ p->openFlags = 0;
1656516620
p->szMax = 0;
1656616621
/* Check for command-line arguments */
1656716622
for(iName=1; iName<nArg && azArg[iName][0]=='-'; iName++){
1656816623
const char *z = azArg[iName];
1656916624
if( optionMatch(z,"new") ){
@@ -16574,10 +16629,12 @@
1657416629
#endif
1657516630
}else if( optionMatch(z, "append") ){
1657616631
p->openMode = SHELL_OPEN_APPENDVFS;
1657716632
}else if( optionMatch(z, "readonly") ){
1657816633
p->openMode = SHELL_OPEN_READONLY;
16634
+ }else if( optionMatch(z, "nofollow") ){
16635
+ p->openFlags |= SQLITE_OPEN_NOFOLLOW;
1657916636
#ifdef SQLITE_ENABLE_DESERIALIZE
1658016637
}else if( optionMatch(z, "deserialize") ){
1658116638
p->openMode = SHELL_OPEN_DESERIALIZE;
1658216639
}else if( optionMatch(z, "hexdb") ){
1658316640
p->openMode = SHELL_OPEN_HEXDB;
@@ -17730,11 +17787,11 @@
1773017787
/*{ "bitvec_test", SQLITE_TESTCTRL_BITVEC_TEST, "" },*/
1773117788
{ "byteorder", SQLITE_TESTCTRL_BYTEORDER, "" },
1773217789
{ "extra_schema_checks",SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS,"BOOLEAN" },
1773317790
/*{ "fault_install", SQLITE_TESTCTRL_FAULT_INSTALL, "" },*/
1773417791
{ "imposter", SQLITE_TESTCTRL_IMPOSTER, "SCHEMA ON/OFF ROOTPAGE"},
17735
- { "internal_functions", SQLITE_TESTCTRL_INTERNAL_FUNCTIONS, "BOOLEAN" },
17792
+ { "internal_functions", SQLITE_TESTCTRL_INTERNAL_FUNCTIONS, "" },
1773617793
{ "localtime_fault", SQLITE_TESTCTRL_LOCALTIME_FAULT,"BOOLEAN" },
1773717794
{ "never_corrupt", SQLITE_TESTCTRL_NEVER_CORRUPT, "BOOLEAN" },
1773817795
{ "optimizations", SQLITE_TESTCTRL_OPTIMIZATIONS, "DISABLE-MASK" },
1773917796
#ifdef YYCOVERAGE
1774017797
{ "parser_coverage", SQLITE_TESTCTRL_PARSER_COVERAGE, "" },
@@ -17846,11 +17903,10 @@
1784617903
break;
1784717904
1784817905
/* sqlite3_test_control(int, int) */
1784917906
case SQLITE_TESTCTRL_ASSERT:
1785017907
case SQLITE_TESTCTRL_ALWAYS:
17851
- case SQLITE_TESTCTRL_INTERNAL_FUNCTIONS:
1785217908
if( nArg==3 ){
1785317909
int opt = booleanValue(azArg[2]);
1785417910
rc2 = sqlite3_test_control(testctrl, opt);
1785517911
isOk = 1;
1785617912
}
@@ -17863,10 +17919,16 @@
1786317919
int opt = booleanValue(azArg[2]);
1786417920
rc2 = sqlite3_test_control(testctrl, opt);
1786517921
isOk = 3;
1786617922
}
1786717923
break;
17924
+
17925
+ /* sqlite3_test_control(sqlite3*) */
17926
+ case SQLITE_TESTCTRL_INTERNAL_FUNCTIONS:
17927
+ rc2 = sqlite3_test_control(testctrl, p->db);
17928
+ isOk = 3;
17929
+ break;
1786817930
1786917931
case SQLITE_TESTCTRL_IMPOSTER:
1787017932
if( nArg==5 ){
1787117933
rc2 = sqlite3_test_control(testctrl, p->db,
1787217934
azArg[2],
@@ -18494,10 +18556,11 @@
1849418556
" -mmap N default mmap size set to N\n"
1849518557
#ifdef SQLITE_ENABLE_MULTIPLEX
1849618558
" -multiplex enable the multiplexor VFS\n"
1849718559
#endif
1849818560
" -newline SEP set output row separator. Default: '\\n'\n"
18561
+ " -nofollow refuse to open symbolic links to database files\n"
1849918562
" -nullvalue TEXT set text string for NULL values. Default ''\n"
1850018563
" -pagecache SIZE N use N slots of SZ bytes each for page cache memory\n"
1850118564
" -quote set output mode to 'quote'\n"
1850218565
" -readonly open the database read-only\n"
1850318566
" -separator SEP set output column separator. Default: '|'\n"
@@ -18804,10 +18867,12 @@
1880418867
}else if( strcmp(z,"-maxsize")==0 && i+1<argc ){
1880518868
data.szMax = integerValue(argv[++i]);
1880618869
#endif
1880718870
}else if( strcmp(z,"-readonly")==0 ){
1880818871
data.openMode = SHELL_OPEN_READONLY;
18872
+ }else if( strcmp(z,"-nofollow")==0 ){
18873
+ data.openFlags = SQLITE_OPEN_NOFOLLOW;
1880918874
#if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_HAVE_ZLIB)
1881018875
}else if( strncmp(z, "-A",2)==0 ){
1881118876
/* All remaining command-line arguments are passed to the ".archive"
1881218877
** command, so ignore them */
1881318878
break;
@@ -18907,10 +18972,12 @@
1890718972
}else if( strcmp(z,"-maxsize")==0 && i+1<argc ){
1890818973
data.szMax = integerValue(argv[++i]);
1890918974
#endif
1891018975
}else if( strcmp(z,"-readonly")==0 ){
1891118976
data.openMode = SHELL_OPEN_READONLY;
18977
+ }else if( strcmp(z,"-nofollow")==0 ){
18978
+ data.openFlags |= SQLITE_OPEN_NOFOLLOW;
1891218979
}else if( strcmp(z,"-ascii")==0 ){
1891318980
data.mode = MODE_Ascii;
1891418981
sqlite3_snprintf(sizeof(data.colSeparator), data.colSeparator,
1891518982
SEP_Unit);
1891618983
sqlite3_snprintf(sizeof(data.rowSeparator), data.rowSeparator,
1891718984
--- src/shell.c
+++ src/shell.c
@@ -2005,23 +2005,27 @@
2005 const sqlite3_api_routines *pApi
2006 ){
2007 int rc = SQLITE_OK;
2008 SQLITE_EXTENSION_INIT2(pApi);
2009 (void)pzErrMsg; /* Unused parameter */
2010 rc = sqlite3_create_function(db, "sha3", 1, SQLITE_UTF8, 0,
2011 sha3Func, 0, 0);
 
 
 
 
 
 
2012 if( rc==SQLITE_OK ){
2013 rc = sqlite3_create_function(db, "sha3", 2, SQLITE_UTF8, 0,
2014 sha3Func, 0, 0);
 
2015 }
2016 if( rc==SQLITE_OK ){
2017 rc = sqlite3_create_function(db, "sha3_query", 1, SQLITE_UTF8, 0,
2018 sha3QueryFunc, 0, 0);
2019 }
2020 if( rc==SQLITE_OK ){
2021 rc = sqlite3_create_function(db, "sha3_query", 2, SQLITE_UTF8, 0,
2022 sha3QueryFunc, 0, 0);
2023 }
2024 return rc;
2025 }
2026
2027 /************************* End ../ext/misc/shathree.c ********************/
@@ -2611,10 +2615,11 @@
2611 rc = sqlite3_declare_vtab(db, "CREATE TABLE x" FSDIR_SCHEMA);
2612 if( rc==SQLITE_OK ){
2613 pNew = (fsdir_tab*)sqlite3_malloc( sizeof(*pNew) );
2614 if( pNew==0 ) return SQLITE_NOMEM;
2615 memset(pNew, 0, sizeof(*pNew));
 
2616 }
2617 *ppVtab = (sqlite3_vtab*)pNew;
2618 return rc;
2619 }
2620
@@ -3004,14 +3009,16 @@
3004 const sqlite3_api_routines *pApi
3005 ){
3006 int rc = SQLITE_OK;
3007 SQLITE_EXTENSION_INIT2(pApi);
3008 (void)pzErrMsg; /* Unused parameter */
3009 rc = sqlite3_create_function(db, "readfile", 1, SQLITE_UTF8, 0,
 
3010 readfileFunc, 0, 0);
3011 if( rc==SQLITE_OK ){
3012 rc = sqlite3_create_function(db, "writefile", -1, SQLITE_UTF8, 0,
 
3013 writefileFunc, 0, 0);
3014 }
3015 if( rc==SQLITE_OK ){
3016 rc = sqlite3_create_function(db, "lsmode", 1, SQLITE_UTF8, 0,
3017 lsModeFunc, 0, 0);
@@ -3142,10 +3149,11 @@
3142 #define COMPLETION_COLUMN_CANDIDATE 0 /* Suggested completion of the input */
3143 #define COMPLETION_COLUMN_PREFIX 1 /* Prefix of the word to be completed */
3144 #define COMPLETION_COLUMN_WHOLELINE 2 /* Entire line seen so far */
3145 #define COMPLETION_COLUMN_PHASE 3 /* ePhase - used for debugging only */
3146
 
3147 rc = sqlite3_declare_vtab(db,
3148 "CREATE TABLE x("
3149 " candidate TEXT,"
3150 " prefix TEXT HIDDEN,"
3151 " wholeline TEXT HIDDEN,"
@@ -4576,10 +4584,11 @@
4576 pNew->zFile = (char*)&pNew->aBuffer[ZIPFILE_BUFFER_SIZE];
4577 memcpy(pNew->zFile, zFile, nFile);
4578 zipfileDequote(pNew->zFile);
4579 }
4580 }
 
4581 *ppVtab = (sqlite3_vtab*)pNew;
4582 return rc;
4583 }
4584
4585 /*
@@ -5188,29 +5197,29 @@
5188 static int zipfileDeflate(
5189 const u8 *aIn, int nIn, /* Input */
5190 u8 **ppOut, int *pnOut, /* Output */
5191 char **pzErr /* OUT: Error message */
5192 ){
5193 sqlite3_int64 nAlloc = compressBound(nIn);
 
 
5194 u8 *aOut;
5195 int rc = SQLITE_OK;
5196
 
 
 
 
 
 
5197 aOut = (u8*)sqlite3_malloc64(nAlloc);
5198 if( aOut==0 ){
5199 rc = SQLITE_NOMEM;
5200 }else{
5201 int res;
5202 z_stream str;
5203 memset(&str, 0, sizeof(str));
5204 str.next_in = (Bytef*)aIn;
5205 str.avail_in = nIn;
5206 str.next_out = aOut;
5207 str.avail_out = nAlloc;
5208
5209 deflateInit2(&str, 9, Z_DEFLATED, -15, 8, Z_DEFAULT_STRATEGY);
5210 res = deflate(&str, Z_FINISH);
5211
5212 if( res==Z_STREAM_END ){
5213 *ppOut = aOut;
5214 *pnOut = (int)str.total_out;
5215 }else{
5216 sqlite3_free(aOut);
@@ -5515,14 +5524,14 @@
5515 unusable = 1;
5516 }else if( pCons->op==SQLITE_INDEX_CONSTRAINT_EQ ){
5517 idx = i;
5518 }
5519 }
 
5520 if( idx>=0 ){
5521 pIdxInfo->aConstraintUsage[idx].argvIndex = 1;
5522 pIdxInfo->aConstraintUsage[idx].omit = 1;
5523 pIdxInfo->estimatedCost = 1000.0;
5524 pIdxInfo->idxNum = 1;
5525 }else if( unusable ){
5526 return SQLITE_CONSTRAINT;
5527 }
5528 return SQLITE_OK;
@@ -5640,21 +5649,25 @@
5640 ** Both (const char*) arguments point to nul-terminated strings. Argument
5641 ** nB is the value of strlen(zB). This function returns 0 if the strings are
5642 ** identical, ignoring any trailing '/' character in either path. */
5643 static int zipfileComparePath(const char *zA, const char *zB, int nB){
5644 int nA = (int)strlen(zA);
5645 if( zA[nA-1]=='/' ) nA--;
5646 if( zB[nB-1]=='/' ) nB--;
5647 if( nA==nB && memcmp(zA, zB, nA)==0 ) return 0;
5648 return 1;
5649 }
5650
5651 static int zipfileBegin(sqlite3_vtab *pVtab){
5652 ZipfileTab *pTab = (ZipfileTab*)pVtab;
5653 int rc = SQLITE_OK;
5654
5655 assert( pTab->pWriteFd==0 );
 
 
 
 
5656
5657 /* Open a write fd on the file. Also load the entire central directory
5658 ** structure into memory. During the transaction any new file data is
5659 ** appended to the archive file, but the central directory is accumulated
5660 ** in main-memory until the transaction is committed. */
@@ -5825,24 +5838,29 @@
5825 rc = zipfileGetMode(apVal[3], bIsDir, &mode, &pTab->base.zErrMsg);
5826 }
5827
5828 if( rc==SQLITE_OK ){
5829 zPath = (const char*)sqlite3_value_text(apVal[2]);
 
5830 nPath = (int)strlen(zPath);
5831 mTime = zipfileGetTime(apVal[4]);
5832 }
5833
5834 if( rc==SQLITE_OK && bIsDir ){
5835 /* For a directory, check that the last character in the path is a
5836 ** '/'. This appears to be required for compatibility with info-zip
5837 ** (the unzip command on unix). It does not create directories
5838 ** otherwise. */
5839 if( zPath[nPath-1]!='/' ){
5840 zFree = sqlite3_mprintf("%s/", zPath);
5841 if( zFree==0 ){ rc = SQLITE_NOMEM; }
5842 zPath = (const char*)zFree;
5843 nPath++;
 
 
 
 
 
5844 }
5845 }
5846
5847 /* Check that we're not inserting a duplicate entry -OR- updating an
5848 ** entry with a path, thereby making it into a duplicate. */
@@ -6231,23 +6249,23 @@
6231
6232 /* If this is a directory entry, ensure that there is exactly one '/'
6233 ** at the end of the path. Or, if this is not a directory and the path
6234 ** ends in '/' it is an error. */
6235 if( bIsDir==0 ){
6236 if( zName[nName-1]=='/' ){
6237 zErr = sqlite3_mprintf("non-directory name must not end with /");
6238 rc = SQLITE_ERROR;
6239 goto zipfile_step_out;
6240 }
6241 }else{
6242 if( zName[nName-1]!='/' ){
6243 zName = zFree = sqlite3_mprintf("%s/", zName);
6244 nName++;
6245 if( zName==0 ){
6246 rc = SQLITE_NOMEM;
6247 goto zipfile_step_out;
6248 }
 
6249 }else{
6250 while( nName>1 && zName[nName-2]=='/' ) nName--;
6251 }
6252 }
6253
@@ -6499,14 +6517,16 @@
6499 const sqlite3_api_routines *pApi
6500 ){
6501 int rc = SQLITE_OK;
6502 SQLITE_EXTENSION_INIT2(pApi);
6503 (void)pzErrMsg; /* Unused parameter */
6504 rc = sqlite3_create_function(db, "sqlar_compress", 1, SQLITE_UTF8, 0,
 
6505 sqlarCompressFunc, 0, 0);
6506 if( rc==SQLITE_OK ){
6507 rc = sqlite3_create_function(db, "sqlar_uncompress", 2, SQLITE_UTF8, 0,
 
6508 sqlarUncompressFunc, 0, 0);
6509 }
6510 return rc;
6511 }
6512
@@ -6523,12 +6543,12 @@
6523 ** May you find forgiveness for yourself and forgive others.
6524 ** May you share freely, never taking more than you give.
6525 **
6526 *************************************************************************
6527 */
6528
6529
6530 /* #include "sqlite3.h" */
6531
6532 typedef struct sqlite3expert sqlite3expert;
6533
6534 /*
@@ -6678,11 +6698,11 @@
6678 ** should be one call to this function for each successful call to
6679 ** sqlite3-expert_new().
6680 */
6681 void sqlite3_expert_destroy(sqlite3expert*);
6682
6683
6684
6685 /************************* End ../ext/expert/sqlite3expert.h ********************/
6686 /************************* Begin ../ext/expert/sqlite3expert.c ******************/
6687 /*
6688 ** 2017 April 09
@@ -9564,10 +9584,11 @@
9564 u8 eTraceType; /* SHELL_TRACE_* value for type of trace */
9565 unsigned mEqpLines; /* Mask of veritical lines in the EQP output graph */
9566 int outCount; /* Revert to stdout when reaching zero */
9567 int cnt; /* Number of records displayed so far */
9568 int lineno; /* Line number of last line read from in */
 
9569 FILE *in; /* Read commands from this stream */
9570 FILE *out; /* Write results here */
9571 FILE *traceOut; /* Output for sqlite3_trace() */
9572 int nErr; /* Number of errors seen */
9573 int mode; /* An output mode setting */
@@ -10398,23 +10419,26 @@
10398 case MODE_Column: {
10399 static const int aExplainWidths[] = {4, 13, 4, 4, 4, 13, 2, 13};
10400 const int *colWidth;
10401 int showHdr;
10402 char *rowSep;
 
10403 if( p->cMode==MODE_Column ){
10404 colWidth = p->colWidth;
 
10405 showHdr = p->showHeader;
10406 rowSep = p->rowSeparator;
10407 }else{
10408 colWidth = aExplainWidths;
 
10409 showHdr = 1;
10410 rowSep = SEP_Row;
10411 }
10412 if( p->cnt++==0 ){
10413 for(i=0; i<nArg; i++){
10414 int w, n;
10415 if( i<ArraySize(p->colWidth) ){
10416 w = colWidth[i];
10417 }else{
10418 w = 0;
10419 }
10420 if( w==0 ){
@@ -11300,19 +11324,23 @@
11300 }
11301
11302 /* Create the TEMP table used to store parameter bindings */
11303 static void bind_table_init(ShellState *p){
11304 int wrSchema = 0;
 
 
 
11305 sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, -1, &wrSchema);
11306 sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, 1, 0);
11307 sqlite3_exec(p->db,
11308 "CREATE TABLE IF NOT EXISTS temp.sqlite_parameters(\n"
11309 " key TEXT PRIMARY KEY,\n"
11310 " value ANY\n"
11311 ") WITHOUT ROWID;",
11312 0, 0, 0);
11313 sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, wrSchema, 0);
 
11314 }
11315
11316 /*
11317 ** Bind parameters on a prepared statement.
11318 **
@@ -12051,13 +12079,11 @@
12051 #endif
12052 " trigger Like \"full\" but also show trigger bytecode",
12053 ".excel Display the output of next command in spreadsheet",
12054 ".exit ?CODE? Exit this program with return-code CODE",
12055 ".expert EXPERIMENTAL. Suggest indexes for queries",
12056 /* Because explain mode comes on automatically now, the ".explain" mode
12057 ** is removed from the help screen. It is still supported for legacy, however */
12058 /*".explain ?on|off|auto? Turn EXPLAIN output mode on or off",*/
12059 ".filectrl CMD ... Run various sqlite3_file_control() operations",
12060 " Run \".filectrl\" with no arguments for details",
12061 ".fullschema ?--indent? Show schema and the content of sqlite_stat tables",
12062 ".headers on|off Turn display of headers on or off",
12063 ".help ?-all? ?PATTERN? Show help text for PATTERN",
@@ -12104,10 +12130,11 @@
12104 " --deserialize Load into memory useing sqlite3_deserialize()",
12105 " --hexdb Load the output of \"dbtotxt\" as an in-memory db",
12106 " --maxsize N Maximum size for --hexdb or --deserialized database",
12107 #endif
12108 " --new Initialize FILE to an empty database",
 
12109 " --readonly Open FILE readonly",
12110 " --zip FILE is a ZIP archive",
12111 ".output ?FILE? Send output to FILE or stdout if FILE is omitted",
12112 " If FILE begins with '|' then open it as a pipe.",
12113 ".parameter CMD ... Manage SQL parameter bindings",
@@ -12668,11 +12695,11 @@
12668 }
12669 }
12670 switch( p->openMode ){
12671 case SHELL_OPEN_APPENDVFS: {
12672 sqlite3_open_v2(p->zDbFilename, &p->db,
12673 SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE, "apndvfs");
12674 break;
12675 }
12676 case SHELL_OPEN_HEXDB:
12677 case SHELL_OPEN_DESERIALIZE: {
12678 sqlite3_open(0, &p->db);
@@ -12681,16 +12708,18 @@
12681 case SHELL_OPEN_ZIPFILE: {
12682 sqlite3_open(":memory:", &p->db);
12683 break;
12684 }
12685 case SHELL_OPEN_READONLY: {
12686 sqlite3_open_v2(p->zDbFilename, &p->db, SQLITE_OPEN_READONLY, 0);
 
12687 break;
12688 }
12689 case SHELL_OPEN_UNSPEC:
12690 case SHELL_OPEN_NORMAL: {
12691 sqlite3_open(p->zDbFilename, &p->db);
 
12692 break;
12693 }
12694 }
12695 globalDb = p->db;
12696 if( p->db==0 || SQLITE_OK!=sqlite3_errcode(p->db) ){
@@ -13460,11 +13489,11 @@
13460 static unsigned int get4byteInt(unsigned char *a){
13461 return (a[0]<<24) + (a[1]<<16) + (a[2]<<8) + a[3];
13462 }
13463
13464 /*
13465 ** Implementation of the ".info" command.
13466 **
13467 ** Return 1 on error, 2 to exit, and 0 otherwise.
13468 */
13469 static int shell_dbinfo_command(ShellState *p, int nArg, char **azArg){
13470 static const struct { const char *zName; int ofst; } aField[] = {
@@ -15697,34 +15726,36 @@
15697 if( c=='d' && n>=3 && strncmp(azArg[0], "dbconfig", n)==0 ){
15698 static const struct DbConfigChoices {
15699 const char *zName;
15700 int op;
15701 } aDbConfig[] = {
 
 
 
15702 { "enable_fkey", SQLITE_DBCONFIG_ENABLE_FKEY },
 
15703 { "enable_trigger", SQLITE_DBCONFIG_ENABLE_TRIGGER },
15704 { "enable_view", SQLITE_DBCONFIG_ENABLE_VIEW },
15705 { "fts3_tokenizer", SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER },
 
 
15706 { "load_extension", SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION },
15707 { "no_ckpt_on_close", SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE },
15708 { "enable_qpsg", SQLITE_DBCONFIG_ENABLE_QPSG },
15709 { "trigger_eqp", SQLITE_DBCONFIG_TRIGGER_EQP },
15710 { "reset_database", SQLITE_DBCONFIG_RESET_DATABASE },
15711 { "defensive", SQLITE_DBCONFIG_DEFENSIVE },
15712 { "writable_schema", SQLITE_DBCONFIG_WRITABLE_SCHEMA },
15713 { "legacy_alter_table", SQLITE_DBCONFIG_LEGACY_ALTER_TABLE },
15714 { "dqs_dml", SQLITE_DBCONFIG_DQS_DML },
15715 { "dqs_ddl", SQLITE_DBCONFIG_DQS_DDL },
15716 };
15717 int ii, v;
15718 open_db(p, 0);
15719 for(ii=0; ii<ArraySize(aDbConfig); ii++){
15720 if( nArg>1 && strcmp(azArg[1], aDbConfig[ii].zName)!=0 ) continue;
15721 if( nArg>=3 ){
15722 sqlite3_db_config(p->db, aDbConfig[ii].op, booleanValue(azArg[2]), 0);
15723 }
15724 sqlite3_db_config(p->db, aDbConfig[ii].op, -1, &v);
15725 utf8_printf(p->out, "%18s %s\n", aDbConfig[ii].zName, v ? "on" : "off");
15726 if( nArg>1 ) break;
15727 }
15728 if( nArg>1 && ii==ArraySize(aDbConfig) ){
15729 utf8_printf(stderr, "Error: unknown dbconfig \"%s\"\n", azArg[1]);
15730 utf8_printf(stderr, "Enter \".dbconfig\" with no arguments for a list\n");
@@ -16301,35 +16332,47 @@
16301 if( c=='i' && strncmp(azArg[0], "imposter", n)==0 ){
16302 char *zSql;
16303 char *zCollist = 0;
16304 sqlite3_stmt *pStmt;
16305 int tnum = 0;
 
 
16306 int i;
16307 if( !(nArg==3 || (nArg==2 && sqlite3_stricmp(azArg[1],"off")==0)) ){
16308 utf8_printf(stderr, "Usage: .imposter INDEX IMPOSTER\n"
16309 " .imposter off\n");
 
 
 
 
 
 
 
16310 rc = 1;
16311 goto meta_command_exit;
16312 }
16313 open_db(p, 0);
16314 if( nArg==2 ){
16315 sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->db, "main", 0, 1);
16316 goto meta_command_exit;
16317 }
16318 zSql = sqlite3_mprintf("SELECT rootpage FROM sqlite_master"
16319 " WHERE name='%q' AND type='index'", azArg[1]);
 
 
 
 
 
 
 
16320 sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
16321 sqlite3_free(zSql);
16322 if( sqlite3_step(pStmt)==SQLITE_ROW ){
16323 tnum = sqlite3_column_int(pStmt, 0);
 
16324 }
16325 sqlite3_finalize(pStmt);
16326 if( tnum==0 ){
16327 utf8_printf(stderr, "no such index: \"%s\"\n", azArg[1]);
16328 rc = 1;
16329 goto meta_command_exit;
16330 }
16331 zSql = sqlite3_mprintf("PRAGMA index_xinfo='%q'", azArg[1]);
16332 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
16333 sqlite3_free(zSql);
16334 i = 0;
16335 while( sqlite3_step(pStmt)==SQLITE_ROW ){
@@ -16342,20 +16385,30 @@
16342 }else{
16343 sqlite3_snprintf(sizeof(zLabel),zLabel,"expr%d",i);
16344 zCol = zLabel;
16345 }
16346 }
 
 
 
16347 if( zCollist==0 ){
16348 zCollist = sqlite3_mprintf("\"%w\"", zCol);
16349 }else{
16350 zCollist = sqlite3_mprintf("%z,\"%w\"", zCollist, zCol);
16351 }
16352 }
16353 sqlite3_finalize(pStmt);
 
 
 
 
 
 
 
16354 zSql = sqlite3_mprintf(
16355 "CREATE TABLE \"%w\"(%s,PRIMARY KEY(%s))WITHOUT ROWID",
16356 azArg[2], zCollist, zCollist);
16357 sqlite3_free(zCollist);
16358 rc = sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->db, "main", 1, tnum);
16359 if( rc==SQLITE_OK ){
16360 rc = sqlite3_exec(p->db, zSql, 0, 0, 0);
16361 sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->db, "main", 0, 0);
@@ -16362,11 +16415,12 @@
16362 if( rc ){
16363 utf8_printf(stderr, "Error in [%s]: %s\n", zSql, sqlite3_errmsg(p->db));
16364 }else{
16365 utf8_printf(stdout, "%s;\n", zSql);
16366 raw_printf(stdout,
16367 "WARNING: writing to an imposter table will corrupt the index!\n"
 
16368 );
16369 }
16370 }else{
16371 raw_printf(stderr, "SQLITE_TESTCTRL_IMPOSTER returns %d\n", rc);
16372 rc = 1;
@@ -16560,10 +16614,11 @@
16560 p->db = 0;
16561 p->zDbFilename = 0;
16562 sqlite3_free(p->zFreeOnClose);
16563 p->zFreeOnClose = 0;
16564 p->openMode = SHELL_OPEN_UNSPEC;
 
16565 p->szMax = 0;
16566 /* Check for command-line arguments */
16567 for(iName=1; iName<nArg && azArg[iName][0]=='-'; iName++){
16568 const char *z = azArg[iName];
16569 if( optionMatch(z,"new") ){
@@ -16574,10 +16629,12 @@
16574 #endif
16575 }else if( optionMatch(z, "append") ){
16576 p->openMode = SHELL_OPEN_APPENDVFS;
16577 }else if( optionMatch(z, "readonly") ){
16578 p->openMode = SHELL_OPEN_READONLY;
 
 
16579 #ifdef SQLITE_ENABLE_DESERIALIZE
16580 }else if( optionMatch(z, "deserialize") ){
16581 p->openMode = SHELL_OPEN_DESERIALIZE;
16582 }else if( optionMatch(z, "hexdb") ){
16583 p->openMode = SHELL_OPEN_HEXDB;
@@ -17730,11 +17787,11 @@
17730 /*{ "bitvec_test", SQLITE_TESTCTRL_BITVEC_TEST, "" },*/
17731 { "byteorder", SQLITE_TESTCTRL_BYTEORDER, "" },
17732 { "extra_schema_checks",SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS,"BOOLEAN" },
17733 /*{ "fault_install", SQLITE_TESTCTRL_FAULT_INSTALL, "" },*/
17734 { "imposter", SQLITE_TESTCTRL_IMPOSTER, "SCHEMA ON/OFF ROOTPAGE"},
17735 { "internal_functions", SQLITE_TESTCTRL_INTERNAL_FUNCTIONS, "BOOLEAN" },
17736 { "localtime_fault", SQLITE_TESTCTRL_LOCALTIME_FAULT,"BOOLEAN" },
17737 { "never_corrupt", SQLITE_TESTCTRL_NEVER_CORRUPT, "BOOLEAN" },
17738 { "optimizations", SQLITE_TESTCTRL_OPTIMIZATIONS, "DISABLE-MASK" },
17739 #ifdef YYCOVERAGE
17740 { "parser_coverage", SQLITE_TESTCTRL_PARSER_COVERAGE, "" },
@@ -17846,11 +17903,10 @@
17846 break;
17847
17848 /* sqlite3_test_control(int, int) */
17849 case SQLITE_TESTCTRL_ASSERT:
17850 case SQLITE_TESTCTRL_ALWAYS:
17851 case SQLITE_TESTCTRL_INTERNAL_FUNCTIONS:
17852 if( nArg==3 ){
17853 int opt = booleanValue(azArg[2]);
17854 rc2 = sqlite3_test_control(testctrl, opt);
17855 isOk = 1;
17856 }
@@ -17863,10 +17919,16 @@
17863 int opt = booleanValue(azArg[2]);
17864 rc2 = sqlite3_test_control(testctrl, opt);
17865 isOk = 3;
17866 }
17867 break;
 
 
 
 
 
 
17868
17869 case SQLITE_TESTCTRL_IMPOSTER:
17870 if( nArg==5 ){
17871 rc2 = sqlite3_test_control(testctrl, p->db,
17872 azArg[2],
@@ -18494,10 +18556,11 @@
18494 " -mmap N default mmap size set to N\n"
18495 #ifdef SQLITE_ENABLE_MULTIPLEX
18496 " -multiplex enable the multiplexor VFS\n"
18497 #endif
18498 " -newline SEP set output row separator. Default: '\\n'\n"
 
18499 " -nullvalue TEXT set text string for NULL values. Default ''\n"
18500 " -pagecache SIZE N use N slots of SZ bytes each for page cache memory\n"
18501 " -quote set output mode to 'quote'\n"
18502 " -readonly open the database read-only\n"
18503 " -separator SEP set output column separator. Default: '|'\n"
@@ -18804,10 +18867,12 @@
18804 }else if( strcmp(z,"-maxsize")==0 && i+1<argc ){
18805 data.szMax = integerValue(argv[++i]);
18806 #endif
18807 }else if( strcmp(z,"-readonly")==0 ){
18808 data.openMode = SHELL_OPEN_READONLY;
 
 
18809 #if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_HAVE_ZLIB)
18810 }else if( strncmp(z, "-A",2)==0 ){
18811 /* All remaining command-line arguments are passed to the ".archive"
18812 ** command, so ignore them */
18813 break;
@@ -18907,10 +18972,12 @@
18907 }else if( strcmp(z,"-maxsize")==0 && i+1<argc ){
18908 data.szMax = integerValue(argv[++i]);
18909 #endif
18910 }else if( strcmp(z,"-readonly")==0 ){
18911 data.openMode = SHELL_OPEN_READONLY;
 
 
18912 }else if( strcmp(z,"-ascii")==0 ){
18913 data.mode = MODE_Ascii;
18914 sqlite3_snprintf(sizeof(data.colSeparator), data.colSeparator,
18915 SEP_Unit);
18916 sqlite3_snprintf(sizeof(data.rowSeparator), data.rowSeparator,
18917
--- src/shell.c
+++ src/shell.c
@@ -2005,23 +2005,27 @@
2005 const sqlite3_api_routines *pApi
2006 ){
2007 int rc = SQLITE_OK;
2008 SQLITE_EXTENSION_INIT2(pApi);
2009 (void)pzErrMsg; /* Unused parameter */
2010 rc = sqlite3_create_function(db, "sha3", 1,
2011 SQLITE_UTF8 | SQLITE_INNOCUOUS | SQLITE_DETERMINISTIC,
2012 0, sha3Func, 0, 0);
2013 if( rc==SQLITE_OK ){
2014 rc = sqlite3_create_function(db, "sha3", 2,
2015 SQLITE_UTF8 | SQLITE_INNOCUOUS | SQLITE_DETERMINISTIC,
2016 0, sha3Func, 0, 0);
2017 }
2018 if( rc==SQLITE_OK ){
2019 rc = sqlite3_create_function(db, "sha3_query", 1,
2020 SQLITE_UTF8 | SQLITE_DIRECTONLY,
2021 0, sha3QueryFunc, 0, 0);
2022 }
2023 if( rc==SQLITE_OK ){
2024 rc = sqlite3_create_function(db, "sha3_query", 2,
2025 SQLITE_UTF8 | SQLITE_DIRECTONLY,
2026 0, sha3QueryFunc, 0, 0);
 
 
 
2027 }
2028 return rc;
2029 }
2030
2031 /************************* End ../ext/misc/shathree.c ********************/
@@ -2611,10 +2615,11 @@
2615 rc = sqlite3_declare_vtab(db, "CREATE TABLE x" FSDIR_SCHEMA);
2616 if( rc==SQLITE_OK ){
2617 pNew = (fsdir_tab*)sqlite3_malloc( sizeof(*pNew) );
2618 if( pNew==0 ) return SQLITE_NOMEM;
2619 memset(pNew, 0, sizeof(*pNew));
2620 sqlite3_vtab_config(db, SQLITE_VTAB_DIRECTONLY);
2621 }
2622 *ppVtab = (sqlite3_vtab*)pNew;
2623 return rc;
2624 }
2625
@@ -3004,14 +3009,16 @@
3009 const sqlite3_api_routines *pApi
3010 ){
3011 int rc = SQLITE_OK;
3012 SQLITE_EXTENSION_INIT2(pApi);
3013 (void)pzErrMsg; /* Unused parameter */
3014 rc = sqlite3_create_function(db, "readfile", 1,
3015 SQLITE_UTF8|SQLITE_DIRECTONLY, 0,
3016 readfileFunc, 0, 0);
3017 if( rc==SQLITE_OK ){
3018 rc = sqlite3_create_function(db, "writefile", -1,
3019 SQLITE_UTF8|SQLITE_DIRECTONLY, 0,
3020 writefileFunc, 0, 0);
3021 }
3022 if( rc==SQLITE_OK ){
3023 rc = sqlite3_create_function(db, "lsmode", 1, SQLITE_UTF8, 0,
3024 lsModeFunc, 0, 0);
@@ -3142,10 +3149,11 @@
3149 #define COMPLETION_COLUMN_CANDIDATE 0 /* Suggested completion of the input */
3150 #define COMPLETION_COLUMN_PREFIX 1 /* Prefix of the word to be completed */
3151 #define COMPLETION_COLUMN_WHOLELINE 2 /* Entire line seen so far */
3152 #define COMPLETION_COLUMN_PHASE 3 /* ePhase - used for debugging only */
3153
3154 sqlite3_vtab_config(db, SQLITE_VTAB_INNOCUOUS);
3155 rc = sqlite3_declare_vtab(db,
3156 "CREATE TABLE x("
3157 " candidate TEXT,"
3158 " prefix TEXT HIDDEN,"
3159 " wholeline TEXT HIDDEN,"
@@ -4576,10 +4584,11 @@
4584 pNew->zFile = (char*)&pNew->aBuffer[ZIPFILE_BUFFER_SIZE];
4585 memcpy(pNew->zFile, zFile, nFile);
4586 zipfileDequote(pNew->zFile);
4587 }
4588 }
4589 sqlite3_vtab_config(db, SQLITE_VTAB_DIRECTONLY);
4590 *ppVtab = (sqlite3_vtab*)pNew;
4591 return rc;
4592 }
4593
4594 /*
@@ -5188,29 +5197,29 @@
5197 static int zipfileDeflate(
5198 const u8 *aIn, int nIn, /* Input */
5199 u8 **ppOut, int *pnOut, /* Output */
5200 char **pzErr /* OUT: Error message */
5201 ){
5202 int rc = SQLITE_OK;
5203 sqlite3_int64 nAlloc;
5204 z_stream str;
5205 u8 *aOut;
 
5206
5207 memset(&str, 0, sizeof(str));
5208 str.next_in = (Bytef*)aIn;
5209 str.avail_in = nIn;
5210 deflateInit2(&str, 9, Z_DEFLATED, -15, 8, Z_DEFAULT_STRATEGY);
5211
5212 nAlloc = deflateBound(&str, nIn);
5213 aOut = (u8*)sqlite3_malloc64(nAlloc);
5214 if( aOut==0 ){
5215 rc = SQLITE_NOMEM;
5216 }else{
5217 int res;
 
 
 
 
5218 str.next_out = aOut;
5219 str.avail_out = nAlloc;
 
 
5220 res = deflate(&str, Z_FINISH);
 
5221 if( res==Z_STREAM_END ){
5222 *ppOut = aOut;
5223 *pnOut = (int)str.total_out;
5224 }else{
5225 sqlite3_free(aOut);
@@ -5515,14 +5524,14 @@
5524 unusable = 1;
5525 }else if( pCons->op==SQLITE_INDEX_CONSTRAINT_EQ ){
5526 idx = i;
5527 }
5528 }
5529 pIdxInfo->estimatedCost = 1000.0;
5530 if( idx>=0 ){
5531 pIdxInfo->aConstraintUsage[idx].argvIndex = 1;
5532 pIdxInfo->aConstraintUsage[idx].omit = 1;
 
5533 pIdxInfo->idxNum = 1;
5534 }else if( unusable ){
5535 return SQLITE_CONSTRAINT;
5536 }
5537 return SQLITE_OK;
@@ -5640,21 +5649,25 @@
5649 ** Both (const char*) arguments point to nul-terminated strings. Argument
5650 ** nB is the value of strlen(zB). This function returns 0 if the strings are
5651 ** identical, ignoring any trailing '/' character in either path. */
5652 static int zipfileComparePath(const char *zA, const char *zB, int nB){
5653 int nA = (int)strlen(zA);
5654 if( nA>0 && zA[nA-1]=='/' ) nA--;
5655 if( nB>0 && zB[nB-1]=='/' ) nB--;
5656 if( nA==nB && memcmp(zA, zB, nA)==0 ) return 0;
5657 return 1;
5658 }
5659
5660 static int zipfileBegin(sqlite3_vtab *pVtab){
5661 ZipfileTab *pTab = (ZipfileTab*)pVtab;
5662 int rc = SQLITE_OK;
5663
5664 assert( pTab->pWriteFd==0 );
5665 if( pTab->zFile==0 || pTab->zFile[0]==0 ){
5666 pTab->base.zErrMsg = sqlite3_mprintf("zipfile: missing filename");
5667 return SQLITE_ERROR;
5668 }
5669
5670 /* Open a write fd on the file. Also load the entire central directory
5671 ** structure into memory. During the transaction any new file data is
5672 ** appended to the archive file, but the central directory is accumulated
5673 ** in main-memory until the transaction is committed. */
@@ -5825,24 +5838,29 @@
5838 rc = zipfileGetMode(apVal[3], bIsDir, &mode, &pTab->base.zErrMsg);
5839 }
5840
5841 if( rc==SQLITE_OK ){
5842 zPath = (const char*)sqlite3_value_text(apVal[2]);
5843 if( zPath==0 ) zPath = "";
5844 nPath = (int)strlen(zPath);
5845 mTime = zipfileGetTime(apVal[4]);
5846 }
5847
5848 if( rc==SQLITE_OK && bIsDir ){
5849 /* For a directory, check that the last character in the path is a
5850 ** '/'. This appears to be required for compatibility with info-zip
5851 ** (the unzip command on unix). It does not create directories
5852 ** otherwise. */
5853 if( nPath<=0 || zPath[nPath-1]!='/' ){
5854 zFree = sqlite3_mprintf("%s/", zPath);
 
5855 zPath = (const char*)zFree;
5856 if( zFree==0 ){
5857 rc = SQLITE_NOMEM;
5858 nPath = 0;
5859 }else{
5860 nPath = (int)strlen(zPath);
5861 }
5862 }
5863 }
5864
5865 /* Check that we're not inserting a duplicate entry -OR- updating an
5866 ** entry with a path, thereby making it into a duplicate. */
@@ -6231,23 +6249,23 @@
6249
6250 /* If this is a directory entry, ensure that there is exactly one '/'
6251 ** at the end of the path. Or, if this is not a directory and the path
6252 ** ends in '/' it is an error. */
6253 if( bIsDir==0 ){
6254 if( nName>0 && zName[nName-1]=='/' ){
6255 zErr = sqlite3_mprintf("non-directory name must not end with /");
6256 rc = SQLITE_ERROR;
6257 goto zipfile_step_out;
6258 }
6259 }else{
6260 if( nName==0 || zName[nName-1]!='/' ){
6261 zName = zFree = sqlite3_mprintf("%s/", zName);
 
6262 if( zName==0 ){
6263 rc = SQLITE_NOMEM;
6264 goto zipfile_step_out;
6265 }
6266 nName = (int)strlen(zName);
6267 }else{
6268 while( nName>1 && zName[nName-2]=='/' ) nName--;
6269 }
6270 }
6271
@@ -6499,14 +6517,16 @@
6517 const sqlite3_api_routines *pApi
6518 ){
6519 int rc = SQLITE_OK;
6520 SQLITE_EXTENSION_INIT2(pApi);
6521 (void)pzErrMsg; /* Unused parameter */
6522 rc = sqlite3_create_function(db, "sqlar_compress", 1,
6523 SQLITE_UTF8|SQLITE_INNOCUOUS, 0,
6524 sqlarCompressFunc, 0, 0);
6525 if( rc==SQLITE_OK ){
6526 rc = sqlite3_create_function(db, "sqlar_uncompress", 2,
6527 SQLITE_UTF8|SQLITE_INNOCUOUS, 0,
6528 sqlarUncompressFunc, 0, 0);
6529 }
6530 return rc;
6531 }
6532
@@ -6523,12 +6543,12 @@
6543 ** May you find forgiveness for yourself and forgive others.
6544 ** May you share freely, never taking more than you give.
6545 **
6546 *************************************************************************
6547 */
6548 #if !defined(SQLITEEXPERT_H)
6549 #define SQLITEEXPERT_H 1
6550 /* #include "sqlite3.h" */
6551
6552 typedef struct sqlite3expert sqlite3expert;
6553
6554 /*
@@ -6678,11 +6698,11 @@
6698 ** should be one call to this function for each successful call to
6699 ** sqlite3-expert_new().
6700 */
6701 void sqlite3_expert_destroy(sqlite3expert*);
6702
6703 #endif /* !defined(SQLITEEXPERT_H) */
6704
6705 /************************* End ../ext/expert/sqlite3expert.h ********************/
6706 /************************* Begin ../ext/expert/sqlite3expert.c ******************/
6707 /*
6708 ** 2017 April 09
@@ -9564,10 +9584,11 @@
9584 u8 eTraceType; /* SHELL_TRACE_* value for type of trace */
9585 unsigned mEqpLines; /* Mask of veritical lines in the EQP output graph */
9586 int outCount; /* Revert to stdout when reaching zero */
9587 int cnt; /* Number of records displayed so far */
9588 int lineno; /* Line number of last line read from in */
9589 int openFlags; /* Additional flags to open. (SQLITE_OPEN_NOFOLLOW) */
9590 FILE *in; /* Read commands from this stream */
9591 FILE *out; /* Write results here */
9592 FILE *traceOut; /* Output for sqlite3_trace() */
9593 int nErr; /* Number of errors seen */
9594 int mode; /* An output mode setting */
@@ -10398,23 +10419,26 @@
10419 case MODE_Column: {
10420 static const int aExplainWidths[] = {4, 13, 4, 4, 4, 13, 2, 13};
10421 const int *colWidth;
10422 int showHdr;
10423 char *rowSep;
10424 int nWidth;
10425 if( p->cMode==MODE_Column ){
10426 colWidth = p->colWidth;
10427 nWidth = ArraySize(p->colWidth);
10428 showHdr = p->showHeader;
10429 rowSep = p->rowSeparator;
10430 }else{
10431 colWidth = aExplainWidths;
10432 nWidth = ArraySize(aExplainWidths);
10433 showHdr = 1;
10434 rowSep = SEP_Row;
10435 }
10436 if( p->cnt++==0 ){
10437 for(i=0; i<nArg; i++){
10438 int w, n;
10439 if( i<nWidth ){
10440 w = colWidth[i];
10441 }else{
10442 w = 0;
10443 }
10444 if( w==0 ){
@@ -11300,19 +11324,23 @@
11324 }
11325
11326 /* Create the TEMP table used to store parameter bindings */
11327 static void bind_table_init(ShellState *p){
11328 int wrSchema = 0;
11329 int defensiveMode = 0;
11330 sqlite3_db_config(p->db, SQLITE_DBCONFIG_DEFENSIVE, -1, &defensiveMode);
11331 sqlite3_db_config(p->db, SQLITE_DBCONFIG_DEFENSIVE, 0, 0);
11332 sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, -1, &wrSchema);
11333 sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, 1, 0);
11334 sqlite3_exec(p->db,
11335 "CREATE TABLE IF NOT EXISTS temp.sqlite_parameters(\n"
11336 " key TEXT PRIMARY KEY,\n"
11337 " value ANY\n"
11338 ") WITHOUT ROWID;",
11339 0, 0, 0);
11340 sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, wrSchema, 0);
11341 sqlite3_db_config(p->db, SQLITE_DBCONFIG_DEFENSIVE, defensiveMode, 0);
11342 }
11343
11344 /*
11345 ** Bind parameters on a prepared statement.
11346 **
@@ -12051,13 +12079,11 @@
12079 #endif
12080 " trigger Like \"full\" but also show trigger bytecode",
12081 ".excel Display the output of next command in spreadsheet",
12082 ".exit ?CODE? Exit this program with return-code CODE",
12083 ".expert EXPERIMENTAL. Suggest indexes for queries",
12084 ".explain ?on|off|auto? Change the EXPLAIN formatting mode. Default: auto",
 
 
12085 ".filectrl CMD ... Run various sqlite3_file_control() operations",
12086 " Run \".filectrl\" with no arguments for details",
12087 ".fullschema ?--indent? Show schema and the content of sqlite_stat tables",
12088 ".headers on|off Turn display of headers on or off",
12089 ".help ?-all? ?PATTERN? Show help text for PATTERN",
@@ -12104,10 +12130,11 @@
12130 " --deserialize Load into memory useing sqlite3_deserialize()",
12131 " --hexdb Load the output of \"dbtotxt\" as an in-memory db",
12132 " --maxsize N Maximum size for --hexdb or --deserialized database",
12133 #endif
12134 " --new Initialize FILE to an empty database",
12135 " --nofollow Do not follow symbolic links",
12136 " --readonly Open FILE readonly",
12137 " --zip FILE is a ZIP archive",
12138 ".output ?FILE? Send output to FILE or stdout if FILE is omitted",
12139 " If FILE begins with '|' then open it as a pipe.",
12140 ".parameter CMD ... Manage SQL parameter bindings",
@@ -12668,11 +12695,11 @@
12695 }
12696 }
12697 switch( p->openMode ){
12698 case SHELL_OPEN_APPENDVFS: {
12699 sqlite3_open_v2(p->zDbFilename, &p->db,
12700 SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|p->openFlags, "apndvfs");
12701 break;
12702 }
12703 case SHELL_OPEN_HEXDB:
12704 case SHELL_OPEN_DESERIALIZE: {
12705 sqlite3_open(0, &p->db);
@@ -12681,16 +12708,18 @@
12708 case SHELL_OPEN_ZIPFILE: {
12709 sqlite3_open(":memory:", &p->db);
12710 break;
12711 }
12712 case SHELL_OPEN_READONLY: {
12713 sqlite3_open_v2(p->zDbFilename, &p->db,
12714 SQLITE_OPEN_READONLY|p->openFlags, 0);
12715 break;
12716 }
12717 case SHELL_OPEN_UNSPEC:
12718 case SHELL_OPEN_NORMAL: {
12719 sqlite3_open_v2(p->zDbFilename, &p->db,
12720 SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|p->openFlags, 0);
12721 break;
12722 }
12723 }
12724 globalDb = p->db;
12725 if( p->db==0 || SQLITE_OK!=sqlite3_errcode(p->db) ){
@@ -13460,11 +13489,11 @@
13489 static unsigned int get4byteInt(unsigned char *a){
13490 return (a[0]<<24) + (a[1]<<16) + (a[2]<<8) + a[3];
13491 }
13492
13493 /*
13494 ** Implementation of the ".dbinfo" command.
13495 **
13496 ** Return 1 on error, 2 to exit, and 0 otherwise.
13497 */
13498 static int shell_dbinfo_command(ShellState *p, int nArg, char **azArg){
13499 static const struct { const char *zName; int ofst; } aField[] = {
@@ -15697,34 +15726,36 @@
15726 if( c=='d' && n>=3 && strncmp(azArg[0], "dbconfig", n)==0 ){
15727 static const struct DbConfigChoices {
15728 const char *zName;
15729 int op;
15730 } aDbConfig[] = {
15731 { "defensive", SQLITE_DBCONFIG_DEFENSIVE },
15732 { "dqs_ddl", SQLITE_DBCONFIG_DQS_DDL },
15733 { "dqs_dml", SQLITE_DBCONFIG_DQS_DML },
15734 { "enable_fkey", SQLITE_DBCONFIG_ENABLE_FKEY },
15735 { "enable_qpsg", SQLITE_DBCONFIG_ENABLE_QPSG },
15736 { "enable_trigger", SQLITE_DBCONFIG_ENABLE_TRIGGER },
15737 { "enable_view", SQLITE_DBCONFIG_ENABLE_VIEW },
15738 { "fts3_tokenizer", SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER },
15739 { "legacy_alter_table", SQLITE_DBCONFIG_LEGACY_ALTER_TABLE },
15740 { "legacy_file_format", SQLITE_DBCONFIG_LEGACY_FILE_FORMAT },
15741 { "load_extension", SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION },
15742 { "no_ckpt_on_close", SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE },
15743 { "reset_database", SQLITE_DBCONFIG_RESET_DATABASE },
15744 { "trigger_eqp", SQLITE_DBCONFIG_TRIGGER_EQP },
15745 { "trusted_schema", SQLITE_DBCONFIG_TRUSTED_SCHEMA },
 
15746 { "writable_schema", SQLITE_DBCONFIG_WRITABLE_SCHEMA },
 
 
 
15747 };
15748 int ii, v;
15749 open_db(p, 0);
15750 for(ii=0; ii<ArraySize(aDbConfig); ii++){
15751 if( nArg>1 && strcmp(azArg[1], aDbConfig[ii].zName)!=0 ) continue;
15752 if( nArg>=3 ){
15753 sqlite3_db_config(p->db, aDbConfig[ii].op, booleanValue(azArg[2]), 0);
15754 }
15755 sqlite3_db_config(p->db, aDbConfig[ii].op, -1, &v);
15756 utf8_printf(p->out, "%19s %s\n", aDbConfig[ii].zName, v ? "on" : "off");
15757 if( nArg>1 ) break;
15758 }
15759 if( nArg>1 && ii==ArraySize(aDbConfig) ){
15760 utf8_printf(stderr, "Error: unknown dbconfig \"%s\"\n", azArg[1]);
15761 utf8_printf(stderr, "Enter \".dbconfig\" with no arguments for a list\n");
@@ -16301,35 +16332,47 @@
16332 if( c=='i' && strncmp(azArg[0], "imposter", n)==0 ){
16333 char *zSql;
16334 char *zCollist = 0;
16335 sqlite3_stmt *pStmt;
16336 int tnum = 0;
16337 int isWO = 0; /* True if making an imposter of a WITHOUT ROWID table */
16338 int lenPK = 0; /* Length of the PRIMARY KEY string for isWO tables */
16339 int i;
16340 if( !(nArg==3 || (nArg==2 && sqlite3_stricmp(azArg[1],"off")==0)) ){
16341 utf8_printf(stderr, "Usage: .imposter INDEX IMPOSTER\n"
16342 " .imposter off\n");
16343 /* Also allowed, but not documented:
16344 **
16345 ** .imposter TABLE IMPOSTER
16346 **
16347 ** where TABLE is a WITHOUT ROWID table. In that case, the
16348 ** imposter is another WITHOUT ROWID table with the columns in
16349 ** storage order. */
16350 rc = 1;
16351 goto meta_command_exit;
16352 }
16353 open_db(p, 0);
16354 if( nArg==2 ){
16355 sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->db, "main", 0, 1);
16356 goto meta_command_exit;
16357 }
16358 zSql = sqlite3_mprintf(
16359 "SELECT rootpage, 0 FROM sqlite_master"
16360 " WHERE name='%q' AND type='index'"
16361 "UNION ALL "
16362 "SELECT rootpage, 1 FROM sqlite_master"
16363 " WHERE name='%q' AND type='table'"
16364 " AND sql LIKE '%%without%%rowid%%'",
16365 azArg[1], azArg[1]
16366 );
16367 sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
16368 sqlite3_free(zSql);
16369 if( sqlite3_step(pStmt)==SQLITE_ROW ){
16370 tnum = sqlite3_column_int(pStmt, 0);
16371 isWO = sqlite3_column_int(pStmt, 1);
16372 }
16373 sqlite3_finalize(pStmt);
 
 
 
 
 
16374 zSql = sqlite3_mprintf("PRAGMA index_xinfo='%q'", azArg[1]);
16375 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
16376 sqlite3_free(zSql);
16377 i = 0;
16378 while( sqlite3_step(pStmt)==SQLITE_ROW ){
@@ -16342,20 +16385,30 @@
16385 }else{
16386 sqlite3_snprintf(sizeof(zLabel),zLabel,"expr%d",i);
16387 zCol = zLabel;
16388 }
16389 }
16390 if( isWO && lenPK==0 && sqlite3_column_int(pStmt,5)==0 && zCollist ){
16391 lenPK = (int)strlen(zCollist);
16392 }
16393 if( zCollist==0 ){
16394 zCollist = sqlite3_mprintf("\"%w\"", zCol);
16395 }else{
16396 zCollist = sqlite3_mprintf("%z,\"%w\"", zCollist, zCol);
16397 }
16398 }
16399 sqlite3_finalize(pStmt);
16400 if( i==0 || tnum==0 ){
16401 utf8_printf(stderr, "no such index: \"%s\"\n", azArg[1]);
16402 rc = 1;
16403 sqlite3_free(zCollist);
16404 goto meta_command_exit;
16405 }
16406 if( lenPK==0 ) lenPK = 100000;
16407 zSql = sqlite3_mprintf(
16408 "CREATE TABLE \"%w\"(%s,PRIMARY KEY(%.*s))WITHOUT ROWID",
16409 azArg[2], zCollist, lenPK, zCollist);
16410 sqlite3_free(zCollist);
16411 rc = sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->db, "main", 1, tnum);
16412 if( rc==SQLITE_OK ){
16413 rc = sqlite3_exec(p->db, zSql, 0, 0, 0);
16414 sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->db, "main", 0, 0);
@@ -16362,11 +16415,12 @@
16415 if( rc ){
16416 utf8_printf(stderr, "Error in [%s]: %s\n", zSql, sqlite3_errmsg(p->db));
16417 }else{
16418 utf8_printf(stdout, "%s;\n", zSql);
16419 raw_printf(stdout,
16420 "WARNING: writing to an imposter table will corrupt the \"%s\" %s!\n",
16421 azArg[1], isWO ? "table" : "index"
16422 );
16423 }
16424 }else{
16425 raw_printf(stderr, "SQLITE_TESTCTRL_IMPOSTER returns %d\n", rc);
16426 rc = 1;
@@ -16560,10 +16614,11 @@
16614 p->db = 0;
16615 p->zDbFilename = 0;
16616 sqlite3_free(p->zFreeOnClose);
16617 p->zFreeOnClose = 0;
16618 p->openMode = SHELL_OPEN_UNSPEC;
16619 p->openFlags = 0;
16620 p->szMax = 0;
16621 /* Check for command-line arguments */
16622 for(iName=1; iName<nArg && azArg[iName][0]=='-'; iName++){
16623 const char *z = azArg[iName];
16624 if( optionMatch(z,"new") ){
@@ -16574,10 +16629,12 @@
16629 #endif
16630 }else if( optionMatch(z, "append") ){
16631 p->openMode = SHELL_OPEN_APPENDVFS;
16632 }else if( optionMatch(z, "readonly") ){
16633 p->openMode = SHELL_OPEN_READONLY;
16634 }else if( optionMatch(z, "nofollow") ){
16635 p->openFlags |= SQLITE_OPEN_NOFOLLOW;
16636 #ifdef SQLITE_ENABLE_DESERIALIZE
16637 }else if( optionMatch(z, "deserialize") ){
16638 p->openMode = SHELL_OPEN_DESERIALIZE;
16639 }else if( optionMatch(z, "hexdb") ){
16640 p->openMode = SHELL_OPEN_HEXDB;
@@ -17730,11 +17787,11 @@
17787 /*{ "bitvec_test", SQLITE_TESTCTRL_BITVEC_TEST, "" },*/
17788 { "byteorder", SQLITE_TESTCTRL_BYTEORDER, "" },
17789 { "extra_schema_checks",SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS,"BOOLEAN" },
17790 /*{ "fault_install", SQLITE_TESTCTRL_FAULT_INSTALL, "" },*/
17791 { "imposter", SQLITE_TESTCTRL_IMPOSTER, "SCHEMA ON/OFF ROOTPAGE"},
17792 { "internal_functions", SQLITE_TESTCTRL_INTERNAL_FUNCTIONS, "" },
17793 { "localtime_fault", SQLITE_TESTCTRL_LOCALTIME_FAULT,"BOOLEAN" },
17794 { "never_corrupt", SQLITE_TESTCTRL_NEVER_CORRUPT, "BOOLEAN" },
17795 { "optimizations", SQLITE_TESTCTRL_OPTIMIZATIONS, "DISABLE-MASK" },
17796 #ifdef YYCOVERAGE
17797 { "parser_coverage", SQLITE_TESTCTRL_PARSER_COVERAGE, "" },
@@ -17846,11 +17903,10 @@
17903 break;
17904
17905 /* sqlite3_test_control(int, int) */
17906 case SQLITE_TESTCTRL_ASSERT:
17907 case SQLITE_TESTCTRL_ALWAYS:
 
17908 if( nArg==3 ){
17909 int opt = booleanValue(azArg[2]);
17910 rc2 = sqlite3_test_control(testctrl, opt);
17911 isOk = 1;
17912 }
@@ -17863,10 +17919,16 @@
17919 int opt = booleanValue(azArg[2]);
17920 rc2 = sqlite3_test_control(testctrl, opt);
17921 isOk = 3;
17922 }
17923 break;
17924
17925 /* sqlite3_test_control(sqlite3*) */
17926 case SQLITE_TESTCTRL_INTERNAL_FUNCTIONS:
17927 rc2 = sqlite3_test_control(testctrl, p->db);
17928 isOk = 3;
17929 break;
17930
17931 case SQLITE_TESTCTRL_IMPOSTER:
17932 if( nArg==5 ){
17933 rc2 = sqlite3_test_control(testctrl, p->db,
17934 azArg[2],
@@ -18494,10 +18556,11 @@
18556 " -mmap N default mmap size set to N\n"
18557 #ifdef SQLITE_ENABLE_MULTIPLEX
18558 " -multiplex enable the multiplexor VFS\n"
18559 #endif
18560 " -newline SEP set output row separator. Default: '\\n'\n"
18561 " -nofollow refuse to open symbolic links to database files\n"
18562 " -nullvalue TEXT set text string for NULL values. Default ''\n"
18563 " -pagecache SIZE N use N slots of SZ bytes each for page cache memory\n"
18564 " -quote set output mode to 'quote'\n"
18565 " -readonly open the database read-only\n"
18566 " -separator SEP set output column separator. Default: '|'\n"
@@ -18804,10 +18867,12 @@
18867 }else if( strcmp(z,"-maxsize")==0 && i+1<argc ){
18868 data.szMax = integerValue(argv[++i]);
18869 #endif
18870 }else if( strcmp(z,"-readonly")==0 ){
18871 data.openMode = SHELL_OPEN_READONLY;
18872 }else if( strcmp(z,"-nofollow")==0 ){
18873 data.openFlags = SQLITE_OPEN_NOFOLLOW;
18874 #if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_HAVE_ZLIB)
18875 }else if( strncmp(z, "-A",2)==0 ){
18876 /* All remaining command-line arguments are passed to the ".archive"
18877 ** command, so ignore them */
18878 break;
@@ -18907,10 +18972,12 @@
18972 }else if( strcmp(z,"-maxsize")==0 && i+1<argc ){
18973 data.szMax = integerValue(argv[++i]);
18974 #endif
18975 }else if( strcmp(z,"-readonly")==0 ){
18976 data.openMode = SHELL_OPEN_READONLY;
18977 }else if( strcmp(z,"-nofollow")==0 ){
18978 data.openFlags |= SQLITE_OPEN_NOFOLLOW;
18979 }else if( strcmp(z,"-ascii")==0 ){
18980 data.mode = MODE_Ascii;
18981 sqlite3_snprintf(sizeof(data.colSeparator), data.colSeparator,
18982 SEP_Unit);
18983 sqlite3_snprintf(sizeof(data.rowSeparator), data.rowSeparator,
18984
+129 -62
--- src/shell.c
+++ src/shell.c
@@ -2005,23 +2005,27 @@
20052005
const sqlite3_api_routines *pApi
20062006
){
20072007
int rc = SQLITE_OK;
20082008
SQLITE_EXTENSION_INIT2(pApi);
20092009
(void)pzErrMsg; /* Unused parameter */
2010
- rc = sqlite3_create_function(db, "sha3", 1, SQLITE_UTF8, 0,
2011
- sha3Func, 0, 0);
2010
+ rc = sqlite3_create_function(db, "sha3", 1,
2011
+ SQLITE_UTF8 | SQLITE_INNOCUOUS | SQLITE_DETERMINISTIC,
2012
+ 0, sha3Func, 0, 0);
2013
+ if( rc==SQLITE_OK ){
2014
+ rc = sqlite3_create_function(db, "sha3", 2,
2015
+ SQLITE_UTF8 | SQLITE_INNOCUOUS | SQLITE_DETERMINISTIC,
2016
+ 0, sha3Func, 0, 0);
2017
+ }
20122018
if( rc==SQLITE_OK ){
2013
- rc = sqlite3_create_function(db, "sha3", 2, SQLITE_UTF8, 0,
2014
- sha3Func, 0, 0);
2019
+ rc = sqlite3_create_function(db, "sha3_query", 1,
2020
+ SQLITE_UTF8 | SQLITE_DIRECTONLY,
2021
+ 0, sha3QueryFunc, 0, 0);
20152022
}
20162023
if( rc==SQLITE_OK ){
2017
- rc = sqlite3_create_function(db, "sha3_query", 1, SQLITE_UTF8, 0,
2018
- sha3QueryFunc, 0, 0);
2019
- }
2020
- if( rc==SQLITE_OK ){
2021
- rc = sqlite3_create_function(db, "sha3_query", 2, SQLITE_UTF8, 0,
2022
- sha3QueryFunc, 0, 0);
2024
+ rc = sqlite3_create_function(db, "sha3_query", 2,
2025
+ SQLITE_UTF8 | SQLITE_DIRECTONLY,
2026
+ 0, sha3QueryFunc, 0, 0);
20232027
}
20242028
return rc;
20252029
}
20262030
20272031
/************************* End ../ext/misc/shathree.c ********************/
@@ -2611,10 +2615,11 @@
26112615
rc = sqlite3_declare_vtab(db, "CREATE TABLE x" FSDIR_SCHEMA);
26122616
if( rc==SQLITE_OK ){
26132617
pNew = (fsdir_tab*)sqlite3_malloc( sizeof(*pNew) );
26142618
if( pNew==0 ) return SQLITE_NOMEM;
26152619
memset(pNew, 0, sizeof(*pNew));
2620
+ sqlite3_vtab_config(db, SQLITE_VTAB_DIRECTONLY);
26162621
}
26172622
*ppVtab = (sqlite3_vtab*)pNew;
26182623
return rc;
26192624
}
26202625
@@ -3004,14 +3009,16 @@
30043009
const sqlite3_api_routines *pApi
30053010
){
30063011
int rc = SQLITE_OK;
30073012
SQLITE_EXTENSION_INIT2(pApi);
30083013
(void)pzErrMsg; /* Unused parameter */
3009
- rc = sqlite3_create_function(db, "readfile", 1, SQLITE_UTF8, 0,
3014
+ rc = sqlite3_create_function(db, "readfile", 1,
3015
+ SQLITE_UTF8|SQLITE_DIRECTONLY, 0,
30103016
readfileFunc, 0, 0);
30113017
if( rc==SQLITE_OK ){
3012
- rc = sqlite3_create_function(db, "writefile", -1, SQLITE_UTF8, 0,
3018
+ rc = sqlite3_create_function(db, "writefile", -1,
3019
+ SQLITE_UTF8|SQLITE_DIRECTONLY, 0,
30133020
writefileFunc, 0, 0);
30143021
}
30153022
if( rc==SQLITE_OK ){
30163023
rc = sqlite3_create_function(db, "lsmode", 1, SQLITE_UTF8, 0,
30173024
lsModeFunc, 0, 0);
@@ -3142,10 +3149,11 @@
31423149
#define COMPLETION_COLUMN_CANDIDATE 0 /* Suggested completion of the input */
31433150
#define COMPLETION_COLUMN_PREFIX 1 /* Prefix of the word to be completed */
31443151
#define COMPLETION_COLUMN_WHOLELINE 2 /* Entire line seen so far */
31453152
#define COMPLETION_COLUMN_PHASE 3 /* ePhase - used for debugging only */
31463153
3154
+ sqlite3_vtab_config(db, SQLITE_VTAB_INNOCUOUS);
31473155
rc = sqlite3_declare_vtab(db,
31483156
"CREATE TABLE x("
31493157
" candidate TEXT,"
31503158
" prefix TEXT HIDDEN,"
31513159
" wholeline TEXT HIDDEN,"
@@ -4576,10 +4584,11 @@
45764584
pNew->zFile = (char*)&pNew->aBuffer[ZIPFILE_BUFFER_SIZE];
45774585
memcpy(pNew->zFile, zFile, nFile);
45784586
zipfileDequote(pNew->zFile);
45794587
}
45804588
}
4589
+ sqlite3_vtab_config(db, SQLITE_VTAB_DIRECTONLY);
45814590
*ppVtab = (sqlite3_vtab*)pNew;
45824591
return rc;
45834592
}
45844593
45854594
/*
@@ -5188,29 +5197,29 @@
51885197
static int zipfileDeflate(
51895198
const u8 *aIn, int nIn, /* Input */
51905199
u8 **ppOut, int *pnOut, /* Output */
51915200
char **pzErr /* OUT: Error message */
51925201
){
5193
- sqlite3_int64 nAlloc = compressBound(nIn);
5202
+ int rc = SQLITE_OK;
5203
+ sqlite3_int64 nAlloc;
5204
+ z_stream str;
51945205
u8 *aOut;
5195
- int rc = SQLITE_OK;
51965206
5207
+ memset(&str, 0, sizeof(str));
5208
+ str.next_in = (Bytef*)aIn;
5209
+ str.avail_in = nIn;
5210
+ deflateInit2(&str, 9, Z_DEFLATED, -15, 8, Z_DEFAULT_STRATEGY);
5211
+
5212
+ nAlloc = deflateBound(&str, nIn);
51975213
aOut = (u8*)sqlite3_malloc64(nAlloc);
51985214
if( aOut==0 ){
51995215
rc = SQLITE_NOMEM;
52005216
}else{
52015217
int res;
5202
- z_stream str;
5203
- memset(&str, 0, sizeof(str));
5204
- str.next_in = (Bytef*)aIn;
5205
- str.avail_in = nIn;
52065218
str.next_out = aOut;
52075219
str.avail_out = nAlloc;
5208
-
5209
- deflateInit2(&str, 9, Z_DEFLATED, -15, 8, Z_DEFAULT_STRATEGY);
52105220
res = deflate(&str, Z_FINISH);
5211
-
52125221
if( res==Z_STREAM_END ){
52135222
*ppOut = aOut;
52145223
*pnOut = (int)str.total_out;
52155224
}else{
52165225
sqlite3_free(aOut);
@@ -5515,14 +5524,14 @@
55155524
unusable = 1;
55165525
}else if( pCons->op==SQLITE_INDEX_CONSTRAINT_EQ ){
55175526
idx = i;
55185527
}
55195528
}
5529
+ pIdxInfo->estimatedCost = 1000.0;
55205530
if( idx>=0 ){
55215531
pIdxInfo->aConstraintUsage[idx].argvIndex = 1;
55225532
pIdxInfo->aConstraintUsage[idx].omit = 1;
5523
- pIdxInfo->estimatedCost = 1000.0;
55245533
pIdxInfo->idxNum = 1;
55255534
}else if( unusable ){
55265535
return SQLITE_CONSTRAINT;
55275536
}
55285537
return SQLITE_OK;
@@ -5640,21 +5649,25 @@
56405649
** Both (const char*) arguments point to nul-terminated strings. Argument
56415650
** nB is the value of strlen(zB). This function returns 0 if the strings are
56425651
** identical, ignoring any trailing '/' character in either path. */
56435652
static int zipfileComparePath(const char *zA, const char *zB, int nB){
56445653
int nA = (int)strlen(zA);
5645
- if( zA[nA-1]=='/' ) nA--;
5646
- if( zB[nB-1]=='/' ) nB--;
5654
+ if( nA>0 && zA[nA-1]=='/' ) nA--;
5655
+ if( nB>0 && zB[nB-1]=='/' ) nB--;
56475656
if( nA==nB && memcmp(zA, zB, nA)==0 ) return 0;
56485657
return 1;
56495658
}
56505659
56515660
static int zipfileBegin(sqlite3_vtab *pVtab){
56525661
ZipfileTab *pTab = (ZipfileTab*)pVtab;
56535662
int rc = SQLITE_OK;
56545663
56555664
assert( pTab->pWriteFd==0 );
5665
+ if( pTab->zFile==0 || pTab->zFile[0]==0 ){
5666
+ pTab->base.zErrMsg = sqlite3_mprintf("zipfile: missing filename");
5667
+ return SQLITE_ERROR;
5668
+ }
56565669
56575670
/* Open a write fd on the file. Also load the entire central directory
56585671
** structure into memory. During the transaction any new file data is
56595672
** appended to the archive file, but the central directory is accumulated
56605673
** in main-memory until the transaction is committed. */
@@ -5825,24 +5838,29 @@
58255838
rc = zipfileGetMode(apVal[3], bIsDir, &mode, &pTab->base.zErrMsg);
58265839
}
58275840
58285841
if( rc==SQLITE_OK ){
58295842
zPath = (const char*)sqlite3_value_text(apVal[2]);
5843
+ if( zPath==0 ) zPath = "";
58305844
nPath = (int)strlen(zPath);
58315845
mTime = zipfileGetTime(apVal[4]);
58325846
}
58335847
58345848
if( rc==SQLITE_OK && bIsDir ){
58355849
/* For a directory, check that the last character in the path is a
58365850
** '/'. This appears to be required for compatibility with info-zip
58375851
** (the unzip command on unix). It does not create directories
58385852
** otherwise. */
5839
- if( zPath[nPath-1]!='/' ){
5853
+ if( nPath<=0 || zPath[nPath-1]!='/' ){
58405854
zFree = sqlite3_mprintf("%s/", zPath);
5841
- if( zFree==0 ){ rc = SQLITE_NOMEM; }
58425855
zPath = (const char*)zFree;
5843
- nPath++;
5856
+ if( zFree==0 ){
5857
+ rc = SQLITE_NOMEM;
5858
+ nPath = 0;
5859
+ }else{
5860
+ nPath = (int)strlen(zPath);
5861
+ }
58445862
}
58455863
}
58465864
58475865
/* Check that we're not inserting a duplicate entry -OR- updating an
58485866
** entry with a path, thereby making it into a duplicate. */
@@ -6231,23 +6249,23 @@
62316249
62326250
/* If this is a directory entry, ensure that there is exactly one '/'
62336251
** at the end of the path. Or, if this is not a directory and the path
62346252
** ends in '/' it is an error. */
62356253
if( bIsDir==0 ){
6236
- if( zName[nName-1]=='/' ){
6254
+ if( nName>0 && zName[nName-1]=='/' ){
62376255
zErr = sqlite3_mprintf("non-directory name must not end with /");
62386256
rc = SQLITE_ERROR;
62396257
goto zipfile_step_out;
62406258
}
62416259
}else{
6242
- if( zName[nName-1]!='/' ){
6260
+ if( nName==0 || zName[nName-1]!='/' ){
62436261
zName = zFree = sqlite3_mprintf("%s/", zName);
6244
- nName++;
62456262
if( zName==0 ){
62466263
rc = SQLITE_NOMEM;
62476264
goto zipfile_step_out;
62486265
}
6266
+ nName = (int)strlen(zName);
62496267
}else{
62506268
while( nName>1 && zName[nName-2]=='/' ) nName--;
62516269
}
62526270
}
62536271
@@ -6499,14 +6517,16 @@
64996517
const sqlite3_api_routines *pApi
65006518
){
65016519
int rc = SQLITE_OK;
65026520
SQLITE_EXTENSION_INIT2(pApi);
65036521
(void)pzErrMsg; /* Unused parameter */
6504
- rc = sqlite3_create_function(db, "sqlar_compress", 1, SQLITE_UTF8, 0,
6522
+ rc = sqlite3_create_function(db, "sqlar_compress", 1,
6523
+ SQLITE_UTF8|SQLITE_INNOCUOUS, 0,
65056524
sqlarCompressFunc, 0, 0);
65066525
if( rc==SQLITE_OK ){
6507
- rc = sqlite3_create_function(db, "sqlar_uncompress", 2, SQLITE_UTF8, 0,
6526
+ rc = sqlite3_create_function(db, "sqlar_uncompress", 2,
6527
+ SQLITE_UTF8|SQLITE_INNOCUOUS, 0,
65086528
sqlarUncompressFunc, 0, 0);
65096529
}
65106530
return rc;
65116531
}
65126532
@@ -6523,12 +6543,12 @@
65236543
** May you find forgiveness for yourself and forgive others.
65246544
** May you share freely, never taking more than you give.
65256545
**
65266546
*************************************************************************
65276547
*/
6528
-
6529
-
6548
+#if !defined(SQLITEEXPERT_H)
6549
+#define SQLITEEXPERT_H 1
65306550
/* #include "sqlite3.h" */
65316551
65326552
typedef struct sqlite3expert sqlite3expert;
65336553
65346554
/*
@@ -6678,11 +6698,11 @@
66786698
** should be one call to this function for each successful call to
66796699
** sqlite3-expert_new().
66806700
*/
66816701
void sqlite3_expert_destroy(sqlite3expert*);
66826702
6683
-
6703
+#endif /* !defined(SQLITEEXPERT_H) */
66846704
66856705
/************************* End ../ext/expert/sqlite3expert.h ********************/
66866706
/************************* Begin ../ext/expert/sqlite3expert.c ******************/
66876707
/*
66886708
** 2017 April 09
@@ -9564,10 +9584,11 @@
95649584
u8 eTraceType; /* SHELL_TRACE_* value for type of trace */
95659585
unsigned mEqpLines; /* Mask of veritical lines in the EQP output graph */
95669586
int outCount; /* Revert to stdout when reaching zero */
95679587
int cnt; /* Number of records displayed so far */
95689588
int lineno; /* Line number of last line read from in */
9589
+ int openFlags; /* Additional flags to open. (SQLITE_OPEN_NOFOLLOW) */
95699590
FILE *in; /* Read commands from this stream */
95709591
FILE *out; /* Write results here */
95719592
FILE *traceOut; /* Output for sqlite3_trace() */
95729593
int nErr; /* Number of errors seen */
95739594
int mode; /* An output mode setting */
@@ -10398,23 +10419,26 @@
1039810419
case MODE_Column: {
1039910420
static const int aExplainWidths[] = {4, 13, 4, 4, 4, 13, 2, 13};
1040010421
const int *colWidth;
1040110422
int showHdr;
1040210423
char *rowSep;
10424
+ int nWidth;
1040310425
if( p->cMode==MODE_Column ){
1040410426
colWidth = p->colWidth;
10427
+ nWidth = ArraySize(p->colWidth);
1040510428
showHdr = p->showHeader;
1040610429
rowSep = p->rowSeparator;
1040710430
}else{
1040810431
colWidth = aExplainWidths;
10432
+ nWidth = ArraySize(aExplainWidths);
1040910433
showHdr = 1;
1041010434
rowSep = SEP_Row;
1041110435
}
1041210436
if( p->cnt++==0 ){
1041310437
for(i=0; i<nArg; i++){
1041410438
int w, n;
10415
- if( i<ArraySize(p->colWidth) ){
10439
+ if( i<nWidth ){
1041610440
w = colWidth[i];
1041710441
}else{
1041810442
w = 0;
1041910443
}
1042010444
if( w==0 ){
@@ -11300,19 +11324,23 @@
1130011324
}
1130111325
1130211326
/* Create the TEMP table used to store parameter bindings */
1130311327
static void bind_table_init(ShellState *p){
1130411328
int wrSchema = 0;
11329
+ int defensiveMode = 0;
11330
+ sqlite3_db_config(p->db, SQLITE_DBCONFIG_DEFENSIVE, -1, &defensiveMode);
11331
+ sqlite3_db_config(p->db, SQLITE_DBCONFIG_DEFENSIVE, 0, 0);
1130511332
sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, -1, &wrSchema);
1130611333
sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, 1, 0);
1130711334
sqlite3_exec(p->db,
1130811335
"CREATE TABLE IF NOT EXISTS temp.sqlite_parameters(\n"
1130911336
" key TEXT PRIMARY KEY,\n"
1131011337
" value ANY\n"
1131111338
") WITHOUT ROWID;",
1131211339
0, 0, 0);
1131311340
sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, wrSchema, 0);
11341
+ sqlite3_db_config(p->db, SQLITE_DBCONFIG_DEFENSIVE, defensiveMode, 0);
1131411342
}
1131511343
1131611344
/*
1131711345
** Bind parameters on a prepared statement.
1131811346
**
@@ -12051,13 +12079,11 @@
1205112079
#endif
1205212080
" trigger Like \"full\" but also show trigger bytecode",
1205312081
".excel Display the output of next command in spreadsheet",
1205412082
".exit ?CODE? Exit this program with return-code CODE",
1205512083
".expert EXPERIMENTAL. Suggest indexes for queries",
12056
-/* Because explain mode comes on automatically now, the ".explain" mode
12057
-** is removed from the help screen. It is still supported for legacy, however */
12058
-/*".explain ?on|off|auto? Turn EXPLAIN output mode on or off",*/
12084
+ ".explain ?on|off|auto? Change the EXPLAIN formatting mode. Default: auto",
1205912085
".filectrl CMD ... Run various sqlite3_file_control() operations",
1206012086
" Run \".filectrl\" with no arguments for details",
1206112087
".fullschema ?--indent? Show schema and the content of sqlite_stat tables",
1206212088
".headers on|off Turn display of headers on or off",
1206312089
".help ?-all? ?PATTERN? Show help text for PATTERN",
@@ -12104,10 +12130,11 @@
1210412130
" --deserialize Load into memory useing sqlite3_deserialize()",
1210512131
" --hexdb Load the output of \"dbtotxt\" as an in-memory db",
1210612132
" --maxsize N Maximum size for --hexdb or --deserialized database",
1210712133
#endif
1210812134
" --new Initialize FILE to an empty database",
12135
+ " --nofollow Do not follow symbolic links",
1210912136
" --readonly Open FILE readonly",
1211012137
" --zip FILE is a ZIP archive",
1211112138
".output ?FILE? Send output to FILE or stdout if FILE is omitted",
1211212139
" If FILE begins with '|' then open it as a pipe.",
1211312140
".parameter CMD ... Manage SQL parameter bindings",
@@ -12668,11 +12695,11 @@
1266812695
}
1266912696
}
1267012697
switch( p->openMode ){
1267112698
case SHELL_OPEN_APPENDVFS: {
1267212699
sqlite3_open_v2(p->zDbFilename, &p->db,
12673
- SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE, "apndvfs");
12700
+ SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|p->openFlags, "apndvfs");
1267412701
break;
1267512702
}
1267612703
case SHELL_OPEN_HEXDB:
1267712704
case SHELL_OPEN_DESERIALIZE: {
1267812705
sqlite3_open(0, &p->db);
@@ -12681,16 +12708,18 @@
1268112708
case SHELL_OPEN_ZIPFILE: {
1268212709
sqlite3_open(":memory:", &p->db);
1268312710
break;
1268412711
}
1268512712
case SHELL_OPEN_READONLY: {
12686
- sqlite3_open_v2(p->zDbFilename, &p->db, SQLITE_OPEN_READONLY, 0);
12713
+ sqlite3_open_v2(p->zDbFilename, &p->db,
12714
+ SQLITE_OPEN_READONLY|p->openFlags, 0);
1268712715
break;
1268812716
}
1268912717
case SHELL_OPEN_UNSPEC:
1269012718
case SHELL_OPEN_NORMAL: {
12691
- sqlite3_open(p->zDbFilename, &p->db);
12719
+ sqlite3_open_v2(p->zDbFilename, &p->db,
12720
+ SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|p->openFlags, 0);
1269212721
break;
1269312722
}
1269412723
}
1269512724
globalDb = p->db;
1269612725
if( p->db==0 || SQLITE_OK!=sqlite3_errcode(p->db) ){
@@ -13460,11 +13489,11 @@
1346013489
static unsigned int get4byteInt(unsigned char *a){
1346113490
return (a[0]<<24) + (a[1]<<16) + (a[2]<<8) + a[3];
1346213491
}
1346313492
1346413493
/*
13465
-** Implementation of the ".info" command.
13494
+** Implementation of the ".dbinfo" command.
1346613495
**
1346713496
** Return 1 on error, 2 to exit, and 0 otherwise.
1346813497
*/
1346913498
static int shell_dbinfo_command(ShellState *p, int nArg, char **azArg){
1347013499
static const struct { const char *zName; int ofst; } aField[] = {
@@ -15697,34 +15726,36 @@
1569715726
if( c=='d' && n>=3 && strncmp(azArg[0], "dbconfig", n)==0 ){
1569815727
static const struct DbConfigChoices {
1569915728
const char *zName;
1570015729
int op;
1570115730
} aDbConfig[] = {
15731
+ { "defensive", SQLITE_DBCONFIG_DEFENSIVE },
15732
+ { "dqs_ddl", SQLITE_DBCONFIG_DQS_DDL },
15733
+ { "dqs_dml", SQLITE_DBCONFIG_DQS_DML },
1570215734
{ "enable_fkey", SQLITE_DBCONFIG_ENABLE_FKEY },
15735
+ { "enable_qpsg", SQLITE_DBCONFIG_ENABLE_QPSG },
1570315736
{ "enable_trigger", SQLITE_DBCONFIG_ENABLE_TRIGGER },
1570415737
{ "enable_view", SQLITE_DBCONFIG_ENABLE_VIEW },
1570515738
{ "fts3_tokenizer", SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER },
15739
+ { "legacy_alter_table", SQLITE_DBCONFIG_LEGACY_ALTER_TABLE },
15740
+ { "legacy_file_format", SQLITE_DBCONFIG_LEGACY_FILE_FORMAT },
1570615741
{ "load_extension", SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION },
1570715742
{ "no_ckpt_on_close", SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE },
15708
- { "enable_qpsg", SQLITE_DBCONFIG_ENABLE_QPSG },
15743
+ { "reset_database", SQLITE_DBCONFIG_RESET_DATABASE },
1570915744
{ "trigger_eqp", SQLITE_DBCONFIG_TRIGGER_EQP },
15710
- { "reset_database", SQLITE_DBCONFIG_RESET_DATABASE },
15711
- { "defensive", SQLITE_DBCONFIG_DEFENSIVE },
15745
+ { "trusted_schema", SQLITE_DBCONFIG_TRUSTED_SCHEMA },
1571215746
{ "writable_schema", SQLITE_DBCONFIG_WRITABLE_SCHEMA },
15713
- { "legacy_alter_table", SQLITE_DBCONFIG_LEGACY_ALTER_TABLE },
15714
- { "dqs_dml", SQLITE_DBCONFIG_DQS_DML },
15715
- { "dqs_ddl", SQLITE_DBCONFIG_DQS_DDL },
1571615747
};
1571715748
int ii, v;
1571815749
open_db(p, 0);
1571915750
for(ii=0; ii<ArraySize(aDbConfig); ii++){
1572015751
if( nArg>1 && strcmp(azArg[1], aDbConfig[ii].zName)!=0 ) continue;
1572115752
if( nArg>=3 ){
1572215753
sqlite3_db_config(p->db, aDbConfig[ii].op, booleanValue(azArg[2]), 0);
1572315754
}
1572415755
sqlite3_db_config(p->db, aDbConfig[ii].op, -1, &v);
15725
- utf8_printf(p->out, "%18s %s\n", aDbConfig[ii].zName, v ? "on" : "off");
15756
+ utf8_printf(p->out, "%19s %s\n", aDbConfig[ii].zName, v ? "on" : "off");
1572615757
if( nArg>1 ) break;
1572715758
}
1572815759
if( nArg>1 && ii==ArraySize(aDbConfig) ){
1572915760
utf8_printf(stderr, "Error: unknown dbconfig \"%s\"\n", azArg[1]);
1573015761
utf8_printf(stderr, "Enter \".dbconfig\" with no arguments for a list\n");
@@ -16301,35 +16332,47 @@
1630116332
if( c=='i' && strncmp(azArg[0], "imposter", n)==0 ){
1630216333
char *zSql;
1630316334
char *zCollist = 0;
1630416335
sqlite3_stmt *pStmt;
1630516336
int tnum = 0;
16337
+ int isWO = 0; /* True if making an imposter of a WITHOUT ROWID table */
16338
+ int lenPK = 0; /* Length of the PRIMARY KEY string for isWO tables */
1630616339
int i;
1630716340
if( !(nArg==3 || (nArg==2 && sqlite3_stricmp(azArg[1],"off")==0)) ){
1630816341
utf8_printf(stderr, "Usage: .imposter INDEX IMPOSTER\n"
1630916342
" .imposter off\n");
16343
+ /* Also allowed, but not documented:
16344
+ **
16345
+ ** .imposter TABLE IMPOSTER
16346
+ **
16347
+ ** where TABLE is a WITHOUT ROWID table. In that case, the
16348
+ ** imposter is another WITHOUT ROWID table with the columns in
16349
+ ** storage order. */
1631016350
rc = 1;
1631116351
goto meta_command_exit;
1631216352
}
1631316353
open_db(p, 0);
1631416354
if( nArg==2 ){
1631516355
sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->db, "main", 0, 1);
1631616356
goto meta_command_exit;
1631716357
}
16318
- zSql = sqlite3_mprintf("SELECT rootpage FROM sqlite_master"
16319
- " WHERE name='%q' AND type='index'", azArg[1]);
16358
+ zSql = sqlite3_mprintf(
16359
+ "SELECT rootpage, 0 FROM sqlite_master"
16360
+ " WHERE name='%q' AND type='index'"
16361
+ "UNION ALL "
16362
+ "SELECT rootpage, 1 FROM sqlite_master"
16363
+ " WHERE name='%q' AND type='table'"
16364
+ " AND sql LIKE '%%without%%rowid%%'",
16365
+ azArg[1], azArg[1]
16366
+ );
1632016367
sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
1632116368
sqlite3_free(zSql);
1632216369
if( sqlite3_step(pStmt)==SQLITE_ROW ){
1632316370
tnum = sqlite3_column_int(pStmt, 0);
16371
+ isWO = sqlite3_column_int(pStmt, 1);
1632416372
}
1632516373
sqlite3_finalize(pStmt);
16326
- if( tnum==0 ){
16327
- utf8_printf(stderr, "no such index: \"%s\"\n", azArg[1]);
16328
- rc = 1;
16329
- goto meta_command_exit;
16330
- }
1633116374
zSql = sqlite3_mprintf("PRAGMA index_xinfo='%q'", azArg[1]);
1633216375
rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
1633316376
sqlite3_free(zSql);
1633416377
i = 0;
1633516378
while( sqlite3_step(pStmt)==SQLITE_ROW ){
@@ -16342,20 +16385,30 @@
1634216385
}else{
1634316386
sqlite3_snprintf(sizeof(zLabel),zLabel,"expr%d",i);
1634416387
zCol = zLabel;
1634516388
}
1634616389
}
16390
+ if( isWO && lenPK==0 && sqlite3_column_int(pStmt,5)==0 && zCollist ){
16391
+ lenPK = (int)strlen(zCollist);
16392
+ }
1634716393
if( zCollist==0 ){
1634816394
zCollist = sqlite3_mprintf("\"%w\"", zCol);
1634916395
}else{
1635016396
zCollist = sqlite3_mprintf("%z,\"%w\"", zCollist, zCol);
1635116397
}
1635216398
}
1635316399
sqlite3_finalize(pStmt);
16400
+ if( i==0 || tnum==0 ){
16401
+ utf8_printf(stderr, "no such index: \"%s\"\n", azArg[1]);
16402
+ rc = 1;
16403
+ sqlite3_free(zCollist);
16404
+ goto meta_command_exit;
16405
+ }
16406
+ if( lenPK==0 ) lenPK = 100000;
1635416407
zSql = sqlite3_mprintf(
16355
- "CREATE TABLE \"%w\"(%s,PRIMARY KEY(%s))WITHOUT ROWID",
16356
- azArg[2], zCollist, zCollist);
16408
+ "CREATE TABLE \"%w\"(%s,PRIMARY KEY(%.*s))WITHOUT ROWID",
16409
+ azArg[2], zCollist, lenPK, zCollist);
1635716410
sqlite3_free(zCollist);
1635816411
rc = sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->db, "main", 1, tnum);
1635916412
if( rc==SQLITE_OK ){
1636016413
rc = sqlite3_exec(p->db, zSql, 0, 0, 0);
1636116414
sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->db, "main", 0, 0);
@@ -16362,11 +16415,12 @@
1636216415
if( rc ){
1636316416
utf8_printf(stderr, "Error in [%s]: %s\n", zSql, sqlite3_errmsg(p->db));
1636416417
}else{
1636516418
utf8_printf(stdout, "%s;\n", zSql);
1636616419
raw_printf(stdout,
16367
- "WARNING: writing to an imposter table will corrupt the index!\n"
16420
+ "WARNING: writing to an imposter table will corrupt the \"%s\" %s!\n",
16421
+ azArg[1], isWO ? "table" : "index"
1636816422
);
1636916423
}
1637016424
}else{
1637116425
raw_printf(stderr, "SQLITE_TESTCTRL_IMPOSTER returns %d\n", rc);
1637216426
rc = 1;
@@ -16560,10 +16614,11 @@
1656016614
p->db = 0;
1656116615
p->zDbFilename = 0;
1656216616
sqlite3_free(p->zFreeOnClose);
1656316617
p->zFreeOnClose = 0;
1656416618
p->openMode = SHELL_OPEN_UNSPEC;
16619
+ p->openFlags = 0;
1656516620
p->szMax = 0;
1656616621
/* Check for command-line arguments */
1656716622
for(iName=1; iName<nArg && azArg[iName][0]=='-'; iName++){
1656816623
const char *z = azArg[iName];
1656916624
if( optionMatch(z,"new") ){
@@ -16574,10 +16629,12 @@
1657416629
#endif
1657516630
}else if( optionMatch(z, "append") ){
1657616631
p->openMode = SHELL_OPEN_APPENDVFS;
1657716632
}else if( optionMatch(z, "readonly") ){
1657816633
p->openMode = SHELL_OPEN_READONLY;
16634
+ }else if( optionMatch(z, "nofollow") ){
16635
+ p->openFlags |= SQLITE_OPEN_NOFOLLOW;
1657916636
#ifdef SQLITE_ENABLE_DESERIALIZE
1658016637
}else if( optionMatch(z, "deserialize") ){
1658116638
p->openMode = SHELL_OPEN_DESERIALIZE;
1658216639
}else if( optionMatch(z, "hexdb") ){
1658316640
p->openMode = SHELL_OPEN_HEXDB;
@@ -17730,11 +17787,11 @@
1773017787
/*{ "bitvec_test", SQLITE_TESTCTRL_BITVEC_TEST, "" },*/
1773117788
{ "byteorder", SQLITE_TESTCTRL_BYTEORDER, "" },
1773217789
{ "extra_schema_checks",SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS,"BOOLEAN" },
1773317790
/*{ "fault_install", SQLITE_TESTCTRL_FAULT_INSTALL, "" },*/
1773417791
{ "imposter", SQLITE_TESTCTRL_IMPOSTER, "SCHEMA ON/OFF ROOTPAGE"},
17735
- { "internal_functions", SQLITE_TESTCTRL_INTERNAL_FUNCTIONS, "BOOLEAN" },
17792
+ { "internal_functions", SQLITE_TESTCTRL_INTERNAL_FUNCTIONS, "" },
1773617793
{ "localtime_fault", SQLITE_TESTCTRL_LOCALTIME_FAULT,"BOOLEAN" },
1773717794
{ "never_corrupt", SQLITE_TESTCTRL_NEVER_CORRUPT, "BOOLEAN" },
1773817795
{ "optimizations", SQLITE_TESTCTRL_OPTIMIZATIONS, "DISABLE-MASK" },
1773917796
#ifdef YYCOVERAGE
1774017797
{ "parser_coverage", SQLITE_TESTCTRL_PARSER_COVERAGE, "" },
@@ -17846,11 +17903,10 @@
1784617903
break;
1784717904
1784817905
/* sqlite3_test_control(int, int) */
1784917906
case SQLITE_TESTCTRL_ASSERT:
1785017907
case SQLITE_TESTCTRL_ALWAYS:
17851
- case SQLITE_TESTCTRL_INTERNAL_FUNCTIONS:
1785217908
if( nArg==3 ){
1785317909
int opt = booleanValue(azArg[2]);
1785417910
rc2 = sqlite3_test_control(testctrl, opt);
1785517911
isOk = 1;
1785617912
}
@@ -17863,10 +17919,16 @@
1786317919
int opt = booleanValue(azArg[2]);
1786417920
rc2 = sqlite3_test_control(testctrl, opt);
1786517921
isOk = 3;
1786617922
}
1786717923
break;
17924
+
17925
+ /* sqlite3_test_control(sqlite3*) */
17926
+ case SQLITE_TESTCTRL_INTERNAL_FUNCTIONS:
17927
+ rc2 = sqlite3_test_control(testctrl, p->db);
17928
+ isOk = 3;
17929
+ break;
1786817930
1786917931
case SQLITE_TESTCTRL_IMPOSTER:
1787017932
if( nArg==5 ){
1787117933
rc2 = sqlite3_test_control(testctrl, p->db,
1787217934
azArg[2],
@@ -18494,10 +18556,11 @@
1849418556
" -mmap N default mmap size set to N\n"
1849518557
#ifdef SQLITE_ENABLE_MULTIPLEX
1849618558
" -multiplex enable the multiplexor VFS\n"
1849718559
#endif
1849818560
" -newline SEP set output row separator. Default: '\\n'\n"
18561
+ " -nofollow refuse to open symbolic links to database files\n"
1849918562
" -nullvalue TEXT set text string for NULL values. Default ''\n"
1850018563
" -pagecache SIZE N use N slots of SZ bytes each for page cache memory\n"
1850118564
" -quote set output mode to 'quote'\n"
1850218565
" -readonly open the database read-only\n"
1850318566
" -separator SEP set output column separator. Default: '|'\n"
@@ -18804,10 +18867,12 @@
1880418867
}else if( strcmp(z,"-maxsize")==0 && i+1<argc ){
1880518868
data.szMax = integerValue(argv[++i]);
1880618869
#endif
1880718870
}else if( strcmp(z,"-readonly")==0 ){
1880818871
data.openMode = SHELL_OPEN_READONLY;
18872
+ }else if( strcmp(z,"-nofollow")==0 ){
18873
+ data.openFlags = SQLITE_OPEN_NOFOLLOW;
1880918874
#if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_HAVE_ZLIB)
1881018875
}else if( strncmp(z, "-A",2)==0 ){
1881118876
/* All remaining command-line arguments are passed to the ".archive"
1881218877
** command, so ignore them */
1881318878
break;
@@ -18907,10 +18972,12 @@
1890718972
}else if( strcmp(z,"-maxsize")==0 && i+1<argc ){
1890818973
data.szMax = integerValue(argv[++i]);
1890918974
#endif
1891018975
}else if( strcmp(z,"-readonly")==0 ){
1891118976
data.openMode = SHELL_OPEN_READONLY;
18977
+ }else if( strcmp(z,"-nofollow")==0 ){
18978
+ data.openFlags |= SQLITE_OPEN_NOFOLLOW;
1891218979
}else if( strcmp(z,"-ascii")==0 ){
1891318980
data.mode = MODE_Ascii;
1891418981
sqlite3_snprintf(sizeof(data.colSeparator), data.colSeparator,
1891518982
SEP_Unit);
1891618983
sqlite3_snprintf(sizeof(data.rowSeparator), data.rowSeparator,
1891718984
--- src/shell.c
+++ src/shell.c
@@ -2005,23 +2005,27 @@
2005 const sqlite3_api_routines *pApi
2006 ){
2007 int rc = SQLITE_OK;
2008 SQLITE_EXTENSION_INIT2(pApi);
2009 (void)pzErrMsg; /* Unused parameter */
2010 rc = sqlite3_create_function(db, "sha3", 1, SQLITE_UTF8, 0,
2011 sha3Func, 0, 0);
 
 
 
 
 
 
2012 if( rc==SQLITE_OK ){
2013 rc = sqlite3_create_function(db, "sha3", 2, SQLITE_UTF8, 0,
2014 sha3Func, 0, 0);
 
2015 }
2016 if( rc==SQLITE_OK ){
2017 rc = sqlite3_create_function(db, "sha3_query", 1, SQLITE_UTF8, 0,
2018 sha3QueryFunc, 0, 0);
2019 }
2020 if( rc==SQLITE_OK ){
2021 rc = sqlite3_create_function(db, "sha3_query", 2, SQLITE_UTF8, 0,
2022 sha3QueryFunc, 0, 0);
2023 }
2024 return rc;
2025 }
2026
2027 /************************* End ../ext/misc/shathree.c ********************/
@@ -2611,10 +2615,11 @@
2611 rc = sqlite3_declare_vtab(db, "CREATE TABLE x" FSDIR_SCHEMA);
2612 if( rc==SQLITE_OK ){
2613 pNew = (fsdir_tab*)sqlite3_malloc( sizeof(*pNew) );
2614 if( pNew==0 ) return SQLITE_NOMEM;
2615 memset(pNew, 0, sizeof(*pNew));
 
2616 }
2617 *ppVtab = (sqlite3_vtab*)pNew;
2618 return rc;
2619 }
2620
@@ -3004,14 +3009,16 @@
3004 const sqlite3_api_routines *pApi
3005 ){
3006 int rc = SQLITE_OK;
3007 SQLITE_EXTENSION_INIT2(pApi);
3008 (void)pzErrMsg; /* Unused parameter */
3009 rc = sqlite3_create_function(db, "readfile", 1, SQLITE_UTF8, 0,
 
3010 readfileFunc, 0, 0);
3011 if( rc==SQLITE_OK ){
3012 rc = sqlite3_create_function(db, "writefile", -1, SQLITE_UTF8, 0,
 
3013 writefileFunc, 0, 0);
3014 }
3015 if( rc==SQLITE_OK ){
3016 rc = sqlite3_create_function(db, "lsmode", 1, SQLITE_UTF8, 0,
3017 lsModeFunc, 0, 0);
@@ -3142,10 +3149,11 @@
3142 #define COMPLETION_COLUMN_CANDIDATE 0 /* Suggested completion of the input */
3143 #define COMPLETION_COLUMN_PREFIX 1 /* Prefix of the word to be completed */
3144 #define COMPLETION_COLUMN_WHOLELINE 2 /* Entire line seen so far */
3145 #define COMPLETION_COLUMN_PHASE 3 /* ePhase - used for debugging only */
3146
 
3147 rc = sqlite3_declare_vtab(db,
3148 "CREATE TABLE x("
3149 " candidate TEXT,"
3150 " prefix TEXT HIDDEN,"
3151 " wholeline TEXT HIDDEN,"
@@ -4576,10 +4584,11 @@
4576 pNew->zFile = (char*)&pNew->aBuffer[ZIPFILE_BUFFER_SIZE];
4577 memcpy(pNew->zFile, zFile, nFile);
4578 zipfileDequote(pNew->zFile);
4579 }
4580 }
 
4581 *ppVtab = (sqlite3_vtab*)pNew;
4582 return rc;
4583 }
4584
4585 /*
@@ -5188,29 +5197,29 @@
5188 static int zipfileDeflate(
5189 const u8 *aIn, int nIn, /* Input */
5190 u8 **ppOut, int *pnOut, /* Output */
5191 char **pzErr /* OUT: Error message */
5192 ){
5193 sqlite3_int64 nAlloc = compressBound(nIn);
 
 
5194 u8 *aOut;
5195 int rc = SQLITE_OK;
5196
 
 
 
 
 
 
5197 aOut = (u8*)sqlite3_malloc64(nAlloc);
5198 if( aOut==0 ){
5199 rc = SQLITE_NOMEM;
5200 }else{
5201 int res;
5202 z_stream str;
5203 memset(&str, 0, sizeof(str));
5204 str.next_in = (Bytef*)aIn;
5205 str.avail_in = nIn;
5206 str.next_out = aOut;
5207 str.avail_out = nAlloc;
5208
5209 deflateInit2(&str, 9, Z_DEFLATED, -15, 8, Z_DEFAULT_STRATEGY);
5210 res = deflate(&str, Z_FINISH);
5211
5212 if( res==Z_STREAM_END ){
5213 *ppOut = aOut;
5214 *pnOut = (int)str.total_out;
5215 }else{
5216 sqlite3_free(aOut);
@@ -5515,14 +5524,14 @@
5515 unusable = 1;
5516 }else if( pCons->op==SQLITE_INDEX_CONSTRAINT_EQ ){
5517 idx = i;
5518 }
5519 }
 
5520 if( idx>=0 ){
5521 pIdxInfo->aConstraintUsage[idx].argvIndex = 1;
5522 pIdxInfo->aConstraintUsage[idx].omit = 1;
5523 pIdxInfo->estimatedCost = 1000.0;
5524 pIdxInfo->idxNum = 1;
5525 }else if( unusable ){
5526 return SQLITE_CONSTRAINT;
5527 }
5528 return SQLITE_OK;
@@ -5640,21 +5649,25 @@
5640 ** Both (const char*) arguments point to nul-terminated strings. Argument
5641 ** nB is the value of strlen(zB). This function returns 0 if the strings are
5642 ** identical, ignoring any trailing '/' character in either path. */
5643 static int zipfileComparePath(const char *zA, const char *zB, int nB){
5644 int nA = (int)strlen(zA);
5645 if( zA[nA-1]=='/' ) nA--;
5646 if( zB[nB-1]=='/' ) nB--;
5647 if( nA==nB && memcmp(zA, zB, nA)==0 ) return 0;
5648 return 1;
5649 }
5650
5651 static int zipfileBegin(sqlite3_vtab *pVtab){
5652 ZipfileTab *pTab = (ZipfileTab*)pVtab;
5653 int rc = SQLITE_OK;
5654
5655 assert( pTab->pWriteFd==0 );
 
 
 
 
5656
5657 /* Open a write fd on the file. Also load the entire central directory
5658 ** structure into memory. During the transaction any new file data is
5659 ** appended to the archive file, but the central directory is accumulated
5660 ** in main-memory until the transaction is committed. */
@@ -5825,24 +5838,29 @@
5825 rc = zipfileGetMode(apVal[3], bIsDir, &mode, &pTab->base.zErrMsg);
5826 }
5827
5828 if( rc==SQLITE_OK ){
5829 zPath = (const char*)sqlite3_value_text(apVal[2]);
 
5830 nPath = (int)strlen(zPath);
5831 mTime = zipfileGetTime(apVal[4]);
5832 }
5833
5834 if( rc==SQLITE_OK && bIsDir ){
5835 /* For a directory, check that the last character in the path is a
5836 ** '/'. This appears to be required for compatibility with info-zip
5837 ** (the unzip command on unix). It does not create directories
5838 ** otherwise. */
5839 if( zPath[nPath-1]!='/' ){
5840 zFree = sqlite3_mprintf("%s/", zPath);
5841 if( zFree==0 ){ rc = SQLITE_NOMEM; }
5842 zPath = (const char*)zFree;
5843 nPath++;
 
 
 
 
 
5844 }
5845 }
5846
5847 /* Check that we're not inserting a duplicate entry -OR- updating an
5848 ** entry with a path, thereby making it into a duplicate. */
@@ -6231,23 +6249,23 @@
6231
6232 /* If this is a directory entry, ensure that there is exactly one '/'
6233 ** at the end of the path. Or, if this is not a directory and the path
6234 ** ends in '/' it is an error. */
6235 if( bIsDir==0 ){
6236 if( zName[nName-1]=='/' ){
6237 zErr = sqlite3_mprintf("non-directory name must not end with /");
6238 rc = SQLITE_ERROR;
6239 goto zipfile_step_out;
6240 }
6241 }else{
6242 if( zName[nName-1]!='/' ){
6243 zName = zFree = sqlite3_mprintf("%s/", zName);
6244 nName++;
6245 if( zName==0 ){
6246 rc = SQLITE_NOMEM;
6247 goto zipfile_step_out;
6248 }
 
6249 }else{
6250 while( nName>1 && zName[nName-2]=='/' ) nName--;
6251 }
6252 }
6253
@@ -6499,14 +6517,16 @@
6499 const sqlite3_api_routines *pApi
6500 ){
6501 int rc = SQLITE_OK;
6502 SQLITE_EXTENSION_INIT2(pApi);
6503 (void)pzErrMsg; /* Unused parameter */
6504 rc = sqlite3_create_function(db, "sqlar_compress", 1, SQLITE_UTF8, 0,
 
6505 sqlarCompressFunc, 0, 0);
6506 if( rc==SQLITE_OK ){
6507 rc = sqlite3_create_function(db, "sqlar_uncompress", 2, SQLITE_UTF8, 0,
 
6508 sqlarUncompressFunc, 0, 0);
6509 }
6510 return rc;
6511 }
6512
@@ -6523,12 +6543,12 @@
6523 ** May you find forgiveness for yourself and forgive others.
6524 ** May you share freely, never taking more than you give.
6525 **
6526 *************************************************************************
6527 */
6528
6529
6530 /* #include "sqlite3.h" */
6531
6532 typedef struct sqlite3expert sqlite3expert;
6533
6534 /*
@@ -6678,11 +6698,11 @@
6678 ** should be one call to this function for each successful call to
6679 ** sqlite3-expert_new().
6680 */
6681 void sqlite3_expert_destroy(sqlite3expert*);
6682
6683
6684
6685 /************************* End ../ext/expert/sqlite3expert.h ********************/
6686 /************************* Begin ../ext/expert/sqlite3expert.c ******************/
6687 /*
6688 ** 2017 April 09
@@ -9564,10 +9584,11 @@
9564 u8 eTraceType; /* SHELL_TRACE_* value for type of trace */
9565 unsigned mEqpLines; /* Mask of veritical lines in the EQP output graph */
9566 int outCount; /* Revert to stdout when reaching zero */
9567 int cnt; /* Number of records displayed so far */
9568 int lineno; /* Line number of last line read from in */
 
9569 FILE *in; /* Read commands from this stream */
9570 FILE *out; /* Write results here */
9571 FILE *traceOut; /* Output for sqlite3_trace() */
9572 int nErr; /* Number of errors seen */
9573 int mode; /* An output mode setting */
@@ -10398,23 +10419,26 @@
10398 case MODE_Column: {
10399 static const int aExplainWidths[] = {4, 13, 4, 4, 4, 13, 2, 13};
10400 const int *colWidth;
10401 int showHdr;
10402 char *rowSep;
 
10403 if( p->cMode==MODE_Column ){
10404 colWidth = p->colWidth;
 
10405 showHdr = p->showHeader;
10406 rowSep = p->rowSeparator;
10407 }else{
10408 colWidth = aExplainWidths;
 
10409 showHdr = 1;
10410 rowSep = SEP_Row;
10411 }
10412 if( p->cnt++==0 ){
10413 for(i=0; i<nArg; i++){
10414 int w, n;
10415 if( i<ArraySize(p->colWidth) ){
10416 w = colWidth[i];
10417 }else{
10418 w = 0;
10419 }
10420 if( w==0 ){
@@ -11300,19 +11324,23 @@
11300 }
11301
11302 /* Create the TEMP table used to store parameter bindings */
11303 static void bind_table_init(ShellState *p){
11304 int wrSchema = 0;
 
 
 
11305 sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, -1, &wrSchema);
11306 sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, 1, 0);
11307 sqlite3_exec(p->db,
11308 "CREATE TABLE IF NOT EXISTS temp.sqlite_parameters(\n"
11309 " key TEXT PRIMARY KEY,\n"
11310 " value ANY\n"
11311 ") WITHOUT ROWID;",
11312 0, 0, 0);
11313 sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, wrSchema, 0);
 
11314 }
11315
11316 /*
11317 ** Bind parameters on a prepared statement.
11318 **
@@ -12051,13 +12079,11 @@
12051 #endif
12052 " trigger Like \"full\" but also show trigger bytecode",
12053 ".excel Display the output of next command in spreadsheet",
12054 ".exit ?CODE? Exit this program with return-code CODE",
12055 ".expert EXPERIMENTAL. Suggest indexes for queries",
12056 /* Because explain mode comes on automatically now, the ".explain" mode
12057 ** is removed from the help screen. It is still supported for legacy, however */
12058 /*".explain ?on|off|auto? Turn EXPLAIN output mode on or off",*/
12059 ".filectrl CMD ... Run various sqlite3_file_control() operations",
12060 " Run \".filectrl\" with no arguments for details",
12061 ".fullschema ?--indent? Show schema and the content of sqlite_stat tables",
12062 ".headers on|off Turn display of headers on or off",
12063 ".help ?-all? ?PATTERN? Show help text for PATTERN",
@@ -12104,10 +12130,11 @@
12104 " --deserialize Load into memory useing sqlite3_deserialize()",
12105 " --hexdb Load the output of \"dbtotxt\" as an in-memory db",
12106 " --maxsize N Maximum size for --hexdb or --deserialized database",
12107 #endif
12108 " --new Initialize FILE to an empty database",
 
12109 " --readonly Open FILE readonly",
12110 " --zip FILE is a ZIP archive",
12111 ".output ?FILE? Send output to FILE or stdout if FILE is omitted",
12112 " If FILE begins with '|' then open it as a pipe.",
12113 ".parameter CMD ... Manage SQL parameter bindings",
@@ -12668,11 +12695,11 @@
12668 }
12669 }
12670 switch( p->openMode ){
12671 case SHELL_OPEN_APPENDVFS: {
12672 sqlite3_open_v2(p->zDbFilename, &p->db,
12673 SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE, "apndvfs");
12674 break;
12675 }
12676 case SHELL_OPEN_HEXDB:
12677 case SHELL_OPEN_DESERIALIZE: {
12678 sqlite3_open(0, &p->db);
@@ -12681,16 +12708,18 @@
12681 case SHELL_OPEN_ZIPFILE: {
12682 sqlite3_open(":memory:", &p->db);
12683 break;
12684 }
12685 case SHELL_OPEN_READONLY: {
12686 sqlite3_open_v2(p->zDbFilename, &p->db, SQLITE_OPEN_READONLY, 0);
 
12687 break;
12688 }
12689 case SHELL_OPEN_UNSPEC:
12690 case SHELL_OPEN_NORMAL: {
12691 sqlite3_open(p->zDbFilename, &p->db);
 
12692 break;
12693 }
12694 }
12695 globalDb = p->db;
12696 if( p->db==0 || SQLITE_OK!=sqlite3_errcode(p->db) ){
@@ -13460,11 +13489,11 @@
13460 static unsigned int get4byteInt(unsigned char *a){
13461 return (a[0]<<24) + (a[1]<<16) + (a[2]<<8) + a[3];
13462 }
13463
13464 /*
13465 ** Implementation of the ".info" command.
13466 **
13467 ** Return 1 on error, 2 to exit, and 0 otherwise.
13468 */
13469 static int shell_dbinfo_command(ShellState *p, int nArg, char **azArg){
13470 static const struct { const char *zName; int ofst; } aField[] = {
@@ -15697,34 +15726,36 @@
15697 if( c=='d' && n>=3 && strncmp(azArg[0], "dbconfig", n)==0 ){
15698 static const struct DbConfigChoices {
15699 const char *zName;
15700 int op;
15701 } aDbConfig[] = {
 
 
 
15702 { "enable_fkey", SQLITE_DBCONFIG_ENABLE_FKEY },
 
15703 { "enable_trigger", SQLITE_DBCONFIG_ENABLE_TRIGGER },
15704 { "enable_view", SQLITE_DBCONFIG_ENABLE_VIEW },
15705 { "fts3_tokenizer", SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER },
 
 
15706 { "load_extension", SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION },
15707 { "no_ckpt_on_close", SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE },
15708 { "enable_qpsg", SQLITE_DBCONFIG_ENABLE_QPSG },
15709 { "trigger_eqp", SQLITE_DBCONFIG_TRIGGER_EQP },
15710 { "reset_database", SQLITE_DBCONFIG_RESET_DATABASE },
15711 { "defensive", SQLITE_DBCONFIG_DEFENSIVE },
15712 { "writable_schema", SQLITE_DBCONFIG_WRITABLE_SCHEMA },
15713 { "legacy_alter_table", SQLITE_DBCONFIG_LEGACY_ALTER_TABLE },
15714 { "dqs_dml", SQLITE_DBCONFIG_DQS_DML },
15715 { "dqs_ddl", SQLITE_DBCONFIG_DQS_DDL },
15716 };
15717 int ii, v;
15718 open_db(p, 0);
15719 for(ii=0; ii<ArraySize(aDbConfig); ii++){
15720 if( nArg>1 && strcmp(azArg[1], aDbConfig[ii].zName)!=0 ) continue;
15721 if( nArg>=3 ){
15722 sqlite3_db_config(p->db, aDbConfig[ii].op, booleanValue(azArg[2]), 0);
15723 }
15724 sqlite3_db_config(p->db, aDbConfig[ii].op, -1, &v);
15725 utf8_printf(p->out, "%18s %s\n", aDbConfig[ii].zName, v ? "on" : "off");
15726 if( nArg>1 ) break;
15727 }
15728 if( nArg>1 && ii==ArraySize(aDbConfig) ){
15729 utf8_printf(stderr, "Error: unknown dbconfig \"%s\"\n", azArg[1]);
15730 utf8_printf(stderr, "Enter \".dbconfig\" with no arguments for a list\n");
@@ -16301,35 +16332,47 @@
16301 if( c=='i' && strncmp(azArg[0], "imposter", n)==0 ){
16302 char *zSql;
16303 char *zCollist = 0;
16304 sqlite3_stmt *pStmt;
16305 int tnum = 0;
 
 
16306 int i;
16307 if( !(nArg==3 || (nArg==2 && sqlite3_stricmp(azArg[1],"off")==0)) ){
16308 utf8_printf(stderr, "Usage: .imposter INDEX IMPOSTER\n"
16309 " .imposter off\n");
 
 
 
 
 
 
 
16310 rc = 1;
16311 goto meta_command_exit;
16312 }
16313 open_db(p, 0);
16314 if( nArg==2 ){
16315 sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->db, "main", 0, 1);
16316 goto meta_command_exit;
16317 }
16318 zSql = sqlite3_mprintf("SELECT rootpage FROM sqlite_master"
16319 " WHERE name='%q' AND type='index'", azArg[1]);
 
 
 
 
 
 
 
16320 sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
16321 sqlite3_free(zSql);
16322 if( sqlite3_step(pStmt)==SQLITE_ROW ){
16323 tnum = sqlite3_column_int(pStmt, 0);
 
16324 }
16325 sqlite3_finalize(pStmt);
16326 if( tnum==0 ){
16327 utf8_printf(stderr, "no such index: \"%s\"\n", azArg[1]);
16328 rc = 1;
16329 goto meta_command_exit;
16330 }
16331 zSql = sqlite3_mprintf("PRAGMA index_xinfo='%q'", azArg[1]);
16332 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
16333 sqlite3_free(zSql);
16334 i = 0;
16335 while( sqlite3_step(pStmt)==SQLITE_ROW ){
@@ -16342,20 +16385,30 @@
16342 }else{
16343 sqlite3_snprintf(sizeof(zLabel),zLabel,"expr%d",i);
16344 zCol = zLabel;
16345 }
16346 }
 
 
 
16347 if( zCollist==0 ){
16348 zCollist = sqlite3_mprintf("\"%w\"", zCol);
16349 }else{
16350 zCollist = sqlite3_mprintf("%z,\"%w\"", zCollist, zCol);
16351 }
16352 }
16353 sqlite3_finalize(pStmt);
 
 
 
 
 
 
 
16354 zSql = sqlite3_mprintf(
16355 "CREATE TABLE \"%w\"(%s,PRIMARY KEY(%s))WITHOUT ROWID",
16356 azArg[2], zCollist, zCollist);
16357 sqlite3_free(zCollist);
16358 rc = sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->db, "main", 1, tnum);
16359 if( rc==SQLITE_OK ){
16360 rc = sqlite3_exec(p->db, zSql, 0, 0, 0);
16361 sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->db, "main", 0, 0);
@@ -16362,11 +16415,12 @@
16362 if( rc ){
16363 utf8_printf(stderr, "Error in [%s]: %s\n", zSql, sqlite3_errmsg(p->db));
16364 }else{
16365 utf8_printf(stdout, "%s;\n", zSql);
16366 raw_printf(stdout,
16367 "WARNING: writing to an imposter table will corrupt the index!\n"
 
16368 );
16369 }
16370 }else{
16371 raw_printf(stderr, "SQLITE_TESTCTRL_IMPOSTER returns %d\n", rc);
16372 rc = 1;
@@ -16560,10 +16614,11 @@
16560 p->db = 0;
16561 p->zDbFilename = 0;
16562 sqlite3_free(p->zFreeOnClose);
16563 p->zFreeOnClose = 0;
16564 p->openMode = SHELL_OPEN_UNSPEC;
 
16565 p->szMax = 0;
16566 /* Check for command-line arguments */
16567 for(iName=1; iName<nArg && azArg[iName][0]=='-'; iName++){
16568 const char *z = azArg[iName];
16569 if( optionMatch(z,"new") ){
@@ -16574,10 +16629,12 @@
16574 #endif
16575 }else if( optionMatch(z, "append") ){
16576 p->openMode = SHELL_OPEN_APPENDVFS;
16577 }else if( optionMatch(z, "readonly") ){
16578 p->openMode = SHELL_OPEN_READONLY;
 
 
16579 #ifdef SQLITE_ENABLE_DESERIALIZE
16580 }else if( optionMatch(z, "deserialize") ){
16581 p->openMode = SHELL_OPEN_DESERIALIZE;
16582 }else if( optionMatch(z, "hexdb") ){
16583 p->openMode = SHELL_OPEN_HEXDB;
@@ -17730,11 +17787,11 @@
17730 /*{ "bitvec_test", SQLITE_TESTCTRL_BITVEC_TEST, "" },*/
17731 { "byteorder", SQLITE_TESTCTRL_BYTEORDER, "" },
17732 { "extra_schema_checks",SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS,"BOOLEAN" },
17733 /*{ "fault_install", SQLITE_TESTCTRL_FAULT_INSTALL, "" },*/
17734 { "imposter", SQLITE_TESTCTRL_IMPOSTER, "SCHEMA ON/OFF ROOTPAGE"},
17735 { "internal_functions", SQLITE_TESTCTRL_INTERNAL_FUNCTIONS, "BOOLEAN" },
17736 { "localtime_fault", SQLITE_TESTCTRL_LOCALTIME_FAULT,"BOOLEAN" },
17737 { "never_corrupt", SQLITE_TESTCTRL_NEVER_CORRUPT, "BOOLEAN" },
17738 { "optimizations", SQLITE_TESTCTRL_OPTIMIZATIONS, "DISABLE-MASK" },
17739 #ifdef YYCOVERAGE
17740 { "parser_coverage", SQLITE_TESTCTRL_PARSER_COVERAGE, "" },
@@ -17846,11 +17903,10 @@
17846 break;
17847
17848 /* sqlite3_test_control(int, int) */
17849 case SQLITE_TESTCTRL_ASSERT:
17850 case SQLITE_TESTCTRL_ALWAYS:
17851 case SQLITE_TESTCTRL_INTERNAL_FUNCTIONS:
17852 if( nArg==3 ){
17853 int opt = booleanValue(azArg[2]);
17854 rc2 = sqlite3_test_control(testctrl, opt);
17855 isOk = 1;
17856 }
@@ -17863,10 +17919,16 @@
17863 int opt = booleanValue(azArg[2]);
17864 rc2 = sqlite3_test_control(testctrl, opt);
17865 isOk = 3;
17866 }
17867 break;
 
 
 
 
 
 
17868
17869 case SQLITE_TESTCTRL_IMPOSTER:
17870 if( nArg==5 ){
17871 rc2 = sqlite3_test_control(testctrl, p->db,
17872 azArg[2],
@@ -18494,10 +18556,11 @@
18494 " -mmap N default mmap size set to N\n"
18495 #ifdef SQLITE_ENABLE_MULTIPLEX
18496 " -multiplex enable the multiplexor VFS\n"
18497 #endif
18498 " -newline SEP set output row separator. Default: '\\n'\n"
 
18499 " -nullvalue TEXT set text string for NULL values. Default ''\n"
18500 " -pagecache SIZE N use N slots of SZ bytes each for page cache memory\n"
18501 " -quote set output mode to 'quote'\n"
18502 " -readonly open the database read-only\n"
18503 " -separator SEP set output column separator. Default: '|'\n"
@@ -18804,10 +18867,12 @@
18804 }else if( strcmp(z,"-maxsize")==0 && i+1<argc ){
18805 data.szMax = integerValue(argv[++i]);
18806 #endif
18807 }else if( strcmp(z,"-readonly")==0 ){
18808 data.openMode = SHELL_OPEN_READONLY;
 
 
18809 #if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_HAVE_ZLIB)
18810 }else if( strncmp(z, "-A",2)==0 ){
18811 /* All remaining command-line arguments are passed to the ".archive"
18812 ** command, so ignore them */
18813 break;
@@ -18907,10 +18972,12 @@
18907 }else if( strcmp(z,"-maxsize")==0 && i+1<argc ){
18908 data.szMax = integerValue(argv[++i]);
18909 #endif
18910 }else if( strcmp(z,"-readonly")==0 ){
18911 data.openMode = SHELL_OPEN_READONLY;
 
 
18912 }else if( strcmp(z,"-ascii")==0 ){
18913 data.mode = MODE_Ascii;
18914 sqlite3_snprintf(sizeof(data.colSeparator), data.colSeparator,
18915 SEP_Unit);
18916 sqlite3_snprintf(sizeof(data.rowSeparator), data.rowSeparator,
18917
--- src/shell.c
+++ src/shell.c
@@ -2005,23 +2005,27 @@
2005 const sqlite3_api_routines *pApi
2006 ){
2007 int rc = SQLITE_OK;
2008 SQLITE_EXTENSION_INIT2(pApi);
2009 (void)pzErrMsg; /* Unused parameter */
2010 rc = sqlite3_create_function(db, "sha3", 1,
2011 SQLITE_UTF8 | SQLITE_INNOCUOUS | SQLITE_DETERMINISTIC,
2012 0, sha3Func, 0, 0);
2013 if( rc==SQLITE_OK ){
2014 rc = sqlite3_create_function(db, "sha3", 2,
2015 SQLITE_UTF8 | SQLITE_INNOCUOUS | SQLITE_DETERMINISTIC,
2016 0, sha3Func, 0, 0);
2017 }
2018 if( rc==SQLITE_OK ){
2019 rc = sqlite3_create_function(db, "sha3_query", 1,
2020 SQLITE_UTF8 | SQLITE_DIRECTONLY,
2021 0, sha3QueryFunc, 0, 0);
2022 }
2023 if( rc==SQLITE_OK ){
2024 rc = sqlite3_create_function(db, "sha3_query", 2,
2025 SQLITE_UTF8 | SQLITE_DIRECTONLY,
2026 0, sha3QueryFunc, 0, 0);
 
 
 
2027 }
2028 return rc;
2029 }
2030
2031 /************************* End ../ext/misc/shathree.c ********************/
@@ -2611,10 +2615,11 @@
2615 rc = sqlite3_declare_vtab(db, "CREATE TABLE x" FSDIR_SCHEMA);
2616 if( rc==SQLITE_OK ){
2617 pNew = (fsdir_tab*)sqlite3_malloc( sizeof(*pNew) );
2618 if( pNew==0 ) return SQLITE_NOMEM;
2619 memset(pNew, 0, sizeof(*pNew));
2620 sqlite3_vtab_config(db, SQLITE_VTAB_DIRECTONLY);
2621 }
2622 *ppVtab = (sqlite3_vtab*)pNew;
2623 return rc;
2624 }
2625
@@ -3004,14 +3009,16 @@
3009 const sqlite3_api_routines *pApi
3010 ){
3011 int rc = SQLITE_OK;
3012 SQLITE_EXTENSION_INIT2(pApi);
3013 (void)pzErrMsg; /* Unused parameter */
3014 rc = sqlite3_create_function(db, "readfile", 1,
3015 SQLITE_UTF8|SQLITE_DIRECTONLY, 0,
3016 readfileFunc, 0, 0);
3017 if( rc==SQLITE_OK ){
3018 rc = sqlite3_create_function(db, "writefile", -1,
3019 SQLITE_UTF8|SQLITE_DIRECTONLY, 0,
3020 writefileFunc, 0, 0);
3021 }
3022 if( rc==SQLITE_OK ){
3023 rc = sqlite3_create_function(db, "lsmode", 1, SQLITE_UTF8, 0,
3024 lsModeFunc, 0, 0);
@@ -3142,10 +3149,11 @@
3149 #define COMPLETION_COLUMN_CANDIDATE 0 /* Suggested completion of the input */
3150 #define COMPLETION_COLUMN_PREFIX 1 /* Prefix of the word to be completed */
3151 #define COMPLETION_COLUMN_WHOLELINE 2 /* Entire line seen so far */
3152 #define COMPLETION_COLUMN_PHASE 3 /* ePhase - used for debugging only */
3153
3154 sqlite3_vtab_config(db, SQLITE_VTAB_INNOCUOUS);
3155 rc = sqlite3_declare_vtab(db,
3156 "CREATE TABLE x("
3157 " candidate TEXT,"
3158 " prefix TEXT HIDDEN,"
3159 " wholeline TEXT HIDDEN,"
@@ -4576,10 +4584,11 @@
4584 pNew->zFile = (char*)&pNew->aBuffer[ZIPFILE_BUFFER_SIZE];
4585 memcpy(pNew->zFile, zFile, nFile);
4586 zipfileDequote(pNew->zFile);
4587 }
4588 }
4589 sqlite3_vtab_config(db, SQLITE_VTAB_DIRECTONLY);
4590 *ppVtab = (sqlite3_vtab*)pNew;
4591 return rc;
4592 }
4593
4594 /*
@@ -5188,29 +5197,29 @@
5197 static int zipfileDeflate(
5198 const u8 *aIn, int nIn, /* Input */
5199 u8 **ppOut, int *pnOut, /* Output */
5200 char **pzErr /* OUT: Error message */
5201 ){
5202 int rc = SQLITE_OK;
5203 sqlite3_int64 nAlloc;
5204 z_stream str;
5205 u8 *aOut;
 
5206
5207 memset(&str, 0, sizeof(str));
5208 str.next_in = (Bytef*)aIn;
5209 str.avail_in = nIn;
5210 deflateInit2(&str, 9, Z_DEFLATED, -15, 8, Z_DEFAULT_STRATEGY);
5211
5212 nAlloc = deflateBound(&str, nIn);
5213 aOut = (u8*)sqlite3_malloc64(nAlloc);
5214 if( aOut==0 ){
5215 rc = SQLITE_NOMEM;
5216 }else{
5217 int res;
 
 
 
 
5218 str.next_out = aOut;
5219 str.avail_out = nAlloc;
 
 
5220 res = deflate(&str, Z_FINISH);
 
5221 if( res==Z_STREAM_END ){
5222 *ppOut = aOut;
5223 *pnOut = (int)str.total_out;
5224 }else{
5225 sqlite3_free(aOut);
@@ -5515,14 +5524,14 @@
5524 unusable = 1;
5525 }else if( pCons->op==SQLITE_INDEX_CONSTRAINT_EQ ){
5526 idx = i;
5527 }
5528 }
5529 pIdxInfo->estimatedCost = 1000.0;
5530 if( idx>=0 ){
5531 pIdxInfo->aConstraintUsage[idx].argvIndex = 1;
5532 pIdxInfo->aConstraintUsage[idx].omit = 1;
 
5533 pIdxInfo->idxNum = 1;
5534 }else if( unusable ){
5535 return SQLITE_CONSTRAINT;
5536 }
5537 return SQLITE_OK;
@@ -5640,21 +5649,25 @@
5649 ** Both (const char*) arguments point to nul-terminated strings. Argument
5650 ** nB is the value of strlen(zB). This function returns 0 if the strings are
5651 ** identical, ignoring any trailing '/' character in either path. */
5652 static int zipfileComparePath(const char *zA, const char *zB, int nB){
5653 int nA = (int)strlen(zA);
5654 if( nA>0 && zA[nA-1]=='/' ) nA--;
5655 if( nB>0 && zB[nB-1]=='/' ) nB--;
5656 if( nA==nB && memcmp(zA, zB, nA)==0 ) return 0;
5657 return 1;
5658 }
5659
5660 static int zipfileBegin(sqlite3_vtab *pVtab){
5661 ZipfileTab *pTab = (ZipfileTab*)pVtab;
5662 int rc = SQLITE_OK;
5663
5664 assert( pTab->pWriteFd==0 );
5665 if( pTab->zFile==0 || pTab->zFile[0]==0 ){
5666 pTab->base.zErrMsg = sqlite3_mprintf("zipfile: missing filename");
5667 return SQLITE_ERROR;
5668 }
5669
5670 /* Open a write fd on the file. Also load the entire central directory
5671 ** structure into memory. During the transaction any new file data is
5672 ** appended to the archive file, but the central directory is accumulated
5673 ** in main-memory until the transaction is committed. */
@@ -5825,24 +5838,29 @@
5838 rc = zipfileGetMode(apVal[3], bIsDir, &mode, &pTab->base.zErrMsg);
5839 }
5840
5841 if( rc==SQLITE_OK ){
5842 zPath = (const char*)sqlite3_value_text(apVal[2]);
5843 if( zPath==0 ) zPath = "";
5844 nPath = (int)strlen(zPath);
5845 mTime = zipfileGetTime(apVal[4]);
5846 }
5847
5848 if( rc==SQLITE_OK && bIsDir ){
5849 /* For a directory, check that the last character in the path is a
5850 ** '/'. This appears to be required for compatibility with info-zip
5851 ** (the unzip command on unix). It does not create directories
5852 ** otherwise. */
5853 if( nPath<=0 || zPath[nPath-1]!='/' ){
5854 zFree = sqlite3_mprintf("%s/", zPath);
 
5855 zPath = (const char*)zFree;
5856 if( zFree==0 ){
5857 rc = SQLITE_NOMEM;
5858 nPath = 0;
5859 }else{
5860 nPath = (int)strlen(zPath);
5861 }
5862 }
5863 }
5864
5865 /* Check that we're not inserting a duplicate entry -OR- updating an
5866 ** entry with a path, thereby making it into a duplicate. */
@@ -6231,23 +6249,23 @@
6249
6250 /* If this is a directory entry, ensure that there is exactly one '/'
6251 ** at the end of the path. Or, if this is not a directory and the path
6252 ** ends in '/' it is an error. */
6253 if( bIsDir==0 ){
6254 if( nName>0 && zName[nName-1]=='/' ){
6255 zErr = sqlite3_mprintf("non-directory name must not end with /");
6256 rc = SQLITE_ERROR;
6257 goto zipfile_step_out;
6258 }
6259 }else{
6260 if( nName==0 || zName[nName-1]!='/' ){
6261 zName = zFree = sqlite3_mprintf("%s/", zName);
 
6262 if( zName==0 ){
6263 rc = SQLITE_NOMEM;
6264 goto zipfile_step_out;
6265 }
6266 nName = (int)strlen(zName);
6267 }else{
6268 while( nName>1 && zName[nName-2]=='/' ) nName--;
6269 }
6270 }
6271
@@ -6499,14 +6517,16 @@
6517 const sqlite3_api_routines *pApi
6518 ){
6519 int rc = SQLITE_OK;
6520 SQLITE_EXTENSION_INIT2(pApi);
6521 (void)pzErrMsg; /* Unused parameter */
6522 rc = sqlite3_create_function(db, "sqlar_compress", 1,
6523 SQLITE_UTF8|SQLITE_INNOCUOUS, 0,
6524 sqlarCompressFunc, 0, 0);
6525 if( rc==SQLITE_OK ){
6526 rc = sqlite3_create_function(db, "sqlar_uncompress", 2,
6527 SQLITE_UTF8|SQLITE_INNOCUOUS, 0,
6528 sqlarUncompressFunc, 0, 0);
6529 }
6530 return rc;
6531 }
6532
@@ -6523,12 +6543,12 @@
6543 ** May you find forgiveness for yourself and forgive others.
6544 ** May you share freely, never taking more than you give.
6545 **
6546 *************************************************************************
6547 */
6548 #if !defined(SQLITEEXPERT_H)
6549 #define SQLITEEXPERT_H 1
6550 /* #include "sqlite3.h" */
6551
6552 typedef struct sqlite3expert sqlite3expert;
6553
6554 /*
@@ -6678,11 +6698,11 @@
6698 ** should be one call to this function for each successful call to
6699 ** sqlite3-expert_new().
6700 */
6701 void sqlite3_expert_destroy(sqlite3expert*);
6702
6703 #endif /* !defined(SQLITEEXPERT_H) */
6704
6705 /************************* End ../ext/expert/sqlite3expert.h ********************/
6706 /************************* Begin ../ext/expert/sqlite3expert.c ******************/
6707 /*
6708 ** 2017 April 09
@@ -9564,10 +9584,11 @@
9584 u8 eTraceType; /* SHELL_TRACE_* value for type of trace */
9585 unsigned mEqpLines; /* Mask of veritical lines in the EQP output graph */
9586 int outCount; /* Revert to stdout when reaching zero */
9587 int cnt; /* Number of records displayed so far */
9588 int lineno; /* Line number of last line read from in */
9589 int openFlags; /* Additional flags to open. (SQLITE_OPEN_NOFOLLOW) */
9590 FILE *in; /* Read commands from this stream */
9591 FILE *out; /* Write results here */
9592 FILE *traceOut; /* Output for sqlite3_trace() */
9593 int nErr; /* Number of errors seen */
9594 int mode; /* An output mode setting */
@@ -10398,23 +10419,26 @@
10419 case MODE_Column: {
10420 static const int aExplainWidths[] = {4, 13, 4, 4, 4, 13, 2, 13};
10421 const int *colWidth;
10422 int showHdr;
10423 char *rowSep;
10424 int nWidth;
10425 if( p->cMode==MODE_Column ){
10426 colWidth = p->colWidth;
10427 nWidth = ArraySize(p->colWidth);
10428 showHdr = p->showHeader;
10429 rowSep = p->rowSeparator;
10430 }else{
10431 colWidth = aExplainWidths;
10432 nWidth = ArraySize(aExplainWidths);
10433 showHdr = 1;
10434 rowSep = SEP_Row;
10435 }
10436 if( p->cnt++==0 ){
10437 for(i=0; i<nArg; i++){
10438 int w, n;
10439 if( i<nWidth ){
10440 w = colWidth[i];
10441 }else{
10442 w = 0;
10443 }
10444 if( w==0 ){
@@ -11300,19 +11324,23 @@
11324 }
11325
11326 /* Create the TEMP table used to store parameter bindings */
11327 static void bind_table_init(ShellState *p){
11328 int wrSchema = 0;
11329 int defensiveMode = 0;
11330 sqlite3_db_config(p->db, SQLITE_DBCONFIG_DEFENSIVE, -1, &defensiveMode);
11331 sqlite3_db_config(p->db, SQLITE_DBCONFIG_DEFENSIVE, 0, 0);
11332 sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, -1, &wrSchema);
11333 sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, 1, 0);
11334 sqlite3_exec(p->db,
11335 "CREATE TABLE IF NOT EXISTS temp.sqlite_parameters(\n"
11336 " key TEXT PRIMARY KEY,\n"
11337 " value ANY\n"
11338 ") WITHOUT ROWID;",
11339 0, 0, 0);
11340 sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, wrSchema, 0);
11341 sqlite3_db_config(p->db, SQLITE_DBCONFIG_DEFENSIVE, defensiveMode, 0);
11342 }
11343
11344 /*
11345 ** Bind parameters on a prepared statement.
11346 **
@@ -12051,13 +12079,11 @@
12079 #endif
12080 " trigger Like \"full\" but also show trigger bytecode",
12081 ".excel Display the output of next command in spreadsheet",
12082 ".exit ?CODE? Exit this program with return-code CODE",
12083 ".expert EXPERIMENTAL. Suggest indexes for queries",
12084 ".explain ?on|off|auto? Change the EXPLAIN formatting mode. Default: auto",
 
 
12085 ".filectrl CMD ... Run various sqlite3_file_control() operations",
12086 " Run \".filectrl\" with no arguments for details",
12087 ".fullschema ?--indent? Show schema and the content of sqlite_stat tables",
12088 ".headers on|off Turn display of headers on or off",
12089 ".help ?-all? ?PATTERN? Show help text for PATTERN",
@@ -12104,10 +12130,11 @@
12130 " --deserialize Load into memory useing sqlite3_deserialize()",
12131 " --hexdb Load the output of \"dbtotxt\" as an in-memory db",
12132 " --maxsize N Maximum size for --hexdb or --deserialized database",
12133 #endif
12134 " --new Initialize FILE to an empty database",
12135 " --nofollow Do not follow symbolic links",
12136 " --readonly Open FILE readonly",
12137 " --zip FILE is a ZIP archive",
12138 ".output ?FILE? Send output to FILE or stdout if FILE is omitted",
12139 " If FILE begins with '|' then open it as a pipe.",
12140 ".parameter CMD ... Manage SQL parameter bindings",
@@ -12668,11 +12695,11 @@
12695 }
12696 }
12697 switch( p->openMode ){
12698 case SHELL_OPEN_APPENDVFS: {
12699 sqlite3_open_v2(p->zDbFilename, &p->db,
12700 SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|p->openFlags, "apndvfs");
12701 break;
12702 }
12703 case SHELL_OPEN_HEXDB:
12704 case SHELL_OPEN_DESERIALIZE: {
12705 sqlite3_open(0, &p->db);
@@ -12681,16 +12708,18 @@
12708 case SHELL_OPEN_ZIPFILE: {
12709 sqlite3_open(":memory:", &p->db);
12710 break;
12711 }
12712 case SHELL_OPEN_READONLY: {
12713 sqlite3_open_v2(p->zDbFilename, &p->db,
12714 SQLITE_OPEN_READONLY|p->openFlags, 0);
12715 break;
12716 }
12717 case SHELL_OPEN_UNSPEC:
12718 case SHELL_OPEN_NORMAL: {
12719 sqlite3_open_v2(p->zDbFilename, &p->db,
12720 SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|p->openFlags, 0);
12721 break;
12722 }
12723 }
12724 globalDb = p->db;
12725 if( p->db==0 || SQLITE_OK!=sqlite3_errcode(p->db) ){
@@ -13460,11 +13489,11 @@
13489 static unsigned int get4byteInt(unsigned char *a){
13490 return (a[0]<<24) + (a[1]<<16) + (a[2]<<8) + a[3];
13491 }
13492
13493 /*
13494 ** Implementation of the ".dbinfo" command.
13495 **
13496 ** Return 1 on error, 2 to exit, and 0 otherwise.
13497 */
13498 static int shell_dbinfo_command(ShellState *p, int nArg, char **azArg){
13499 static const struct { const char *zName; int ofst; } aField[] = {
@@ -15697,34 +15726,36 @@
15726 if( c=='d' && n>=3 && strncmp(azArg[0], "dbconfig", n)==0 ){
15727 static const struct DbConfigChoices {
15728 const char *zName;
15729 int op;
15730 } aDbConfig[] = {
15731 { "defensive", SQLITE_DBCONFIG_DEFENSIVE },
15732 { "dqs_ddl", SQLITE_DBCONFIG_DQS_DDL },
15733 { "dqs_dml", SQLITE_DBCONFIG_DQS_DML },
15734 { "enable_fkey", SQLITE_DBCONFIG_ENABLE_FKEY },
15735 { "enable_qpsg", SQLITE_DBCONFIG_ENABLE_QPSG },
15736 { "enable_trigger", SQLITE_DBCONFIG_ENABLE_TRIGGER },
15737 { "enable_view", SQLITE_DBCONFIG_ENABLE_VIEW },
15738 { "fts3_tokenizer", SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER },
15739 { "legacy_alter_table", SQLITE_DBCONFIG_LEGACY_ALTER_TABLE },
15740 { "legacy_file_format", SQLITE_DBCONFIG_LEGACY_FILE_FORMAT },
15741 { "load_extension", SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION },
15742 { "no_ckpt_on_close", SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE },
15743 { "reset_database", SQLITE_DBCONFIG_RESET_DATABASE },
15744 { "trigger_eqp", SQLITE_DBCONFIG_TRIGGER_EQP },
15745 { "trusted_schema", SQLITE_DBCONFIG_TRUSTED_SCHEMA },
 
15746 { "writable_schema", SQLITE_DBCONFIG_WRITABLE_SCHEMA },
 
 
 
15747 };
15748 int ii, v;
15749 open_db(p, 0);
15750 for(ii=0; ii<ArraySize(aDbConfig); ii++){
15751 if( nArg>1 && strcmp(azArg[1], aDbConfig[ii].zName)!=0 ) continue;
15752 if( nArg>=3 ){
15753 sqlite3_db_config(p->db, aDbConfig[ii].op, booleanValue(azArg[2]), 0);
15754 }
15755 sqlite3_db_config(p->db, aDbConfig[ii].op, -1, &v);
15756 utf8_printf(p->out, "%19s %s\n", aDbConfig[ii].zName, v ? "on" : "off");
15757 if( nArg>1 ) break;
15758 }
15759 if( nArg>1 && ii==ArraySize(aDbConfig) ){
15760 utf8_printf(stderr, "Error: unknown dbconfig \"%s\"\n", azArg[1]);
15761 utf8_printf(stderr, "Enter \".dbconfig\" with no arguments for a list\n");
@@ -16301,35 +16332,47 @@
16332 if( c=='i' && strncmp(azArg[0], "imposter", n)==0 ){
16333 char *zSql;
16334 char *zCollist = 0;
16335 sqlite3_stmt *pStmt;
16336 int tnum = 0;
16337 int isWO = 0; /* True if making an imposter of a WITHOUT ROWID table */
16338 int lenPK = 0; /* Length of the PRIMARY KEY string for isWO tables */
16339 int i;
16340 if( !(nArg==3 || (nArg==2 && sqlite3_stricmp(azArg[1],"off")==0)) ){
16341 utf8_printf(stderr, "Usage: .imposter INDEX IMPOSTER\n"
16342 " .imposter off\n");
16343 /* Also allowed, but not documented:
16344 **
16345 ** .imposter TABLE IMPOSTER
16346 **
16347 ** where TABLE is a WITHOUT ROWID table. In that case, the
16348 ** imposter is another WITHOUT ROWID table with the columns in
16349 ** storage order. */
16350 rc = 1;
16351 goto meta_command_exit;
16352 }
16353 open_db(p, 0);
16354 if( nArg==2 ){
16355 sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->db, "main", 0, 1);
16356 goto meta_command_exit;
16357 }
16358 zSql = sqlite3_mprintf(
16359 "SELECT rootpage, 0 FROM sqlite_master"
16360 " WHERE name='%q' AND type='index'"
16361 "UNION ALL "
16362 "SELECT rootpage, 1 FROM sqlite_master"
16363 " WHERE name='%q' AND type='table'"
16364 " AND sql LIKE '%%without%%rowid%%'",
16365 azArg[1], azArg[1]
16366 );
16367 sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
16368 sqlite3_free(zSql);
16369 if( sqlite3_step(pStmt)==SQLITE_ROW ){
16370 tnum = sqlite3_column_int(pStmt, 0);
16371 isWO = sqlite3_column_int(pStmt, 1);
16372 }
16373 sqlite3_finalize(pStmt);
 
 
 
 
 
16374 zSql = sqlite3_mprintf("PRAGMA index_xinfo='%q'", azArg[1]);
16375 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
16376 sqlite3_free(zSql);
16377 i = 0;
16378 while( sqlite3_step(pStmt)==SQLITE_ROW ){
@@ -16342,20 +16385,30 @@
16385 }else{
16386 sqlite3_snprintf(sizeof(zLabel),zLabel,"expr%d",i);
16387 zCol = zLabel;
16388 }
16389 }
16390 if( isWO && lenPK==0 && sqlite3_column_int(pStmt,5)==0 && zCollist ){
16391 lenPK = (int)strlen(zCollist);
16392 }
16393 if( zCollist==0 ){
16394 zCollist = sqlite3_mprintf("\"%w\"", zCol);
16395 }else{
16396 zCollist = sqlite3_mprintf("%z,\"%w\"", zCollist, zCol);
16397 }
16398 }
16399 sqlite3_finalize(pStmt);
16400 if( i==0 || tnum==0 ){
16401 utf8_printf(stderr, "no such index: \"%s\"\n", azArg[1]);
16402 rc = 1;
16403 sqlite3_free(zCollist);
16404 goto meta_command_exit;
16405 }
16406 if( lenPK==0 ) lenPK = 100000;
16407 zSql = sqlite3_mprintf(
16408 "CREATE TABLE \"%w\"(%s,PRIMARY KEY(%.*s))WITHOUT ROWID",
16409 azArg[2], zCollist, lenPK, zCollist);
16410 sqlite3_free(zCollist);
16411 rc = sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->db, "main", 1, tnum);
16412 if( rc==SQLITE_OK ){
16413 rc = sqlite3_exec(p->db, zSql, 0, 0, 0);
16414 sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->db, "main", 0, 0);
@@ -16362,11 +16415,12 @@
16415 if( rc ){
16416 utf8_printf(stderr, "Error in [%s]: %s\n", zSql, sqlite3_errmsg(p->db));
16417 }else{
16418 utf8_printf(stdout, "%s;\n", zSql);
16419 raw_printf(stdout,
16420 "WARNING: writing to an imposter table will corrupt the \"%s\" %s!\n",
16421 azArg[1], isWO ? "table" : "index"
16422 );
16423 }
16424 }else{
16425 raw_printf(stderr, "SQLITE_TESTCTRL_IMPOSTER returns %d\n", rc);
16426 rc = 1;
@@ -16560,10 +16614,11 @@
16614 p->db = 0;
16615 p->zDbFilename = 0;
16616 sqlite3_free(p->zFreeOnClose);
16617 p->zFreeOnClose = 0;
16618 p->openMode = SHELL_OPEN_UNSPEC;
16619 p->openFlags = 0;
16620 p->szMax = 0;
16621 /* Check for command-line arguments */
16622 for(iName=1; iName<nArg && azArg[iName][0]=='-'; iName++){
16623 const char *z = azArg[iName];
16624 if( optionMatch(z,"new") ){
@@ -16574,10 +16629,12 @@
16629 #endif
16630 }else if( optionMatch(z, "append") ){
16631 p->openMode = SHELL_OPEN_APPENDVFS;
16632 }else if( optionMatch(z, "readonly") ){
16633 p->openMode = SHELL_OPEN_READONLY;
16634 }else if( optionMatch(z, "nofollow") ){
16635 p->openFlags |= SQLITE_OPEN_NOFOLLOW;
16636 #ifdef SQLITE_ENABLE_DESERIALIZE
16637 }else if( optionMatch(z, "deserialize") ){
16638 p->openMode = SHELL_OPEN_DESERIALIZE;
16639 }else if( optionMatch(z, "hexdb") ){
16640 p->openMode = SHELL_OPEN_HEXDB;
@@ -17730,11 +17787,11 @@
17787 /*{ "bitvec_test", SQLITE_TESTCTRL_BITVEC_TEST, "" },*/
17788 { "byteorder", SQLITE_TESTCTRL_BYTEORDER, "" },
17789 { "extra_schema_checks",SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS,"BOOLEAN" },
17790 /*{ "fault_install", SQLITE_TESTCTRL_FAULT_INSTALL, "" },*/
17791 { "imposter", SQLITE_TESTCTRL_IMPOSTER, "SCHEMA ON/OFF ROOTPAGE"},
17792 { "internal_functions", SQLITE_TESTCTRL_INTERNAL_FUNCTIONS, "" },
17793 { "localtime_fault", SQLITE_TESTCTRL_LOCALTIME_FAULT,"BOOLEAN" },
17794 { "never_corrupt", SQLITE_TESTCTRL_NEVER_CORRUPT, "BOOLEAN" },
17795 { "optimizations", SQLITE_TESTCTRL_OPTIMIZATIONS, "DISABLE-MASK" },
17796 #ifdef YYCOVERAGE
17797 { "parser_coverage", SQLITE_TESTCTRL_PARSER_COVERAGE, "" },
@@ -17846,11 +17903,10 @@
17903 break;
17904
17905 /* sqlite3_test_control(int, int) */
17906 case SQLITE_TESTCTRL_ASSERT:
17907 case SQLITE_TESTCTRL_ALWAYS:
 
17908 if( nArg==3 ){
17909 int opt = booleanValue(azArg[2]);
17910 rc2 = sqlite3_test_control(testctrl, opt);
17911 isOk = 1;
17912 }
@@ -17863,10 +17919,16 @@
17919 int opt = booleanValue(azArg[2]);
17920 rc2 = sqlite3_test_control(testctrl, opt);
17921 isOk = 3;
17922 }
17923 break;
17924
17925 /* sqlite3_test_control(sqlite3*) */
17926 case SQLITE_TESTCTRL_INTERNAL_FUNCTIONS:
17927 rc2 = sqlite3_test_control(testctrl, p->db);
17928 isOk = 3;
17929 break;
17930
17931 case SQLITE_TESTCTRL_IMPOSTER:
17932 if( nArg==5 ){
17933 rc2 = sqlite3_test_control(testctrl, p->db,
17934 azArg[2],
@@ -18494,10 +18556,11 @@
18556 " -mmap N default mmap size set to N\n"
18557 #ifdef SQLITE_ENABLE_MULTIPLEX
18558 " -multiplex enable the multiplexor VFS\n"
18559 #endif
18560 " -newline SEP set output row separator. Default: '\\n'\n"
18561 " -nofollow refuse to open symbolic links to database files\n"
18562 " -nullvalue TEXT set text string for NULL values. Default ''\n"
18563 " -pagecache SIZE N use N slots of SZ bytes each for page cache memory\n"
18564 " -quote set output mode to 'quote'\n"
18565 " -readonly open the database read-only\n"
18566 " -separator SEP set output column separator. Default: '|'\n"
@@ -18804,10 +18867,12 @@
18867 }else if( strcmp(z,"-maxsize")==0 && i+1<argc ){
18868 data.szMax = integerValue(argv[++i]);
18869 #endif
18870 }else if( strcmp(z,"-readonly")==0 ){
18871 data.openMode = SHELL_OPEN_READONLY;
18872 }else if( strcmp(z,"-nofollow")==0 ){
18873 data.openFlags = SQLITE_OPEN_NOFOLLOW;
18874 #if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_HAVE_ZLIB)
18875 }else if( strncmp(z, "-A",2)==0 ){
18876 /* All remaining command-line arguments are passed to the ".archive"
18877 ** command, so ignore them */
18878 break;
@@ -18907,10 +18972,12 @@
18972 }else if( strcmp(z,"-maxsize")==0 && i+1<argc ){
18973 data.szMax = integerValue(argv[++i]);
18974 #endif
18975 }else if( strcmp(z,"-readonly")==0 ){
18976 data.openMode = SHELL_OPEN_READONLY;
18977 }else if( strcmp(z,"-nofollow")==0 ){
18978 data.openFlags |= SQLITE_OPEN_NOFOLLOW;
18979 }else if( strcmp(z,"-ascii")==0 ){
18980 data.mode = MODE_Ascii;
18981 sqlite3_snprintf(sizeof(data.colSeparator), data.colSeparator,
18982 SEP_Unit);
18983 sqlite3_snprintf(sizeof(data.rowSeparator), data.rowSeparator,
18984
+9107 -5700
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
11
/******************************************************************************
22
** This file is an amalgamation of many separate C source files from SQLite
3
-** version 3.30.0. By combining all the individual C code files into this
3
+** version 3.31.1. By combining all the individual C code files into this
44
** single large file, the entire code can be compiled as a single translation
55
** unit. This allows many compilers to do optimizations that would not be
66
** possible if the files were compiled separately. Performance improvements
77
** of 5% or more are commonly seen when SQLite is compiled as a single
88
** translation unit.
@@ -1163,13 +1163,13 @@
11631163
**
11641164
** See also: [sqlite3_libversion()],
11651165
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
11661166
** [sqlite_version()] and [sqlite_source_id()].
11671167
*/
1168
-#define SQLITE_VERSION "3.30.0"
1169
-#define SQLITE_VERSION_NUMBER 3030000
1170
-#define SQLITE_SOURCE_ID "2019-10-04 15:03:17 c20a35336432025445f9f7e289d0cc3e4003fb17f45a4ce74c6269c407c6e09f"
1168
+#define SQLITE_VERSION "3.31.1"
1169
+#define SQLITE_VERSION_NUMBER 3031001
1170
+#define SQLITE_SOURCE_ID "2020-01-28 15:02:23 04885763c4cd00cbca26d048f2b19316bfc93e8edebeceaa171ebfc6c563d53e"
11711171
11721172
/*
11731173
** CAPI3REF: Run-Time Library Version Numbers
11741174
** KEYWORDS: sqlite3_version sqlite3_sourceid
11751175
**
@@ -1556,10 +1556,11 @@
15561556
#define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8))
15571557
#define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8))
15581558
#define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8))
15591559
#define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8))
15601560
#define SQLITE_CANTOPEN_DIRTYWAL (SQLITE_CANTOPEN | (5<<8)) /* Not Used */
1561
+#define SQLITE_CANTOPEN_SYMLINK (SQLITE_CANTOPEN | (6<<8))
15611562
#define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8))
15621563
#define SQLITE_CORRUPT_SEQUENCE (SQLITE_CORRUPT | (2<<8))
15631564
#define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8))
15641565
#define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8))
15651566
#define SQLITE_READONLY_ROLLBACK (SQLITE_READONLY | (3<<8))
@@ -1575,15 +1576,17 @@
15751576
#define SQLITE_CONSTRAINT_PRIMARYKEY (SQLITE_CONSTRAINT | (6<<8))
15761577
#define SQLITE_CONSTRAINT_TRIGGER (SQLITE_CONSTRAINT | (7<<8))
15771578
#define SQLITE_CONSTRAINT_UNIQUE (SQLITE_CONSTRAINT | (8<<8))
15781579
#define SQLITE_CONSTRAINT_VTAB (SQLITE_CONSTRAINT | (9<<8))
15791580
#define SQLITE_CONSTRAINT_ROWID (SQLITE_CONSTRAINT |(10<<8))
1581
+#define SQLITE_CONSTRAINT_PINNED (SQLITE_CONSTRAINT |(11<<8))
15801582
#define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8))
15811583
#define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8))
15821584
#define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8))
15831585
#define SQLITE_AUTH_USER (SQLITE_AUTH | (1<<8))
15841586
#define SQLITE_OK_LOAD_PERMANENTLY (SQLITE_OK | (1<<8))
1587
+#define SQLITE_OK_SYMLINK (SQLITE_OK | (2<<8))
15851588
15861589
/*
15871590
** CAPI3REF: Flags For File Open Operations
15881591
**
15891592
** These bit values are intended for use in the
@@ -1608,10 +1611,11 @@
16081611
#define SQLITE_OPEN_NOMUTEX 0x00008000 /* Ok for sqlite3_open_v2() */
16091612
#define SQLITE_OPEN_FULLMUTEX 0x00010000 /* Ok for sqlite3_open_v2() */
16101613
#define SQLITE_OPEN_SHAREDCACHE 0x00020000 /* Ok for sqlite3_open_v2() */
16111614
#define SQLITE_OPEN_PRIVATECACHE 0x00040000 /* Ok for sqlite3_open_v2() */
16121615
#define SQLITE_OPEN_WAL 0x00080000 /* VFS only */
1616
+#define SQLITE_OPEN_NOFOLLOW 0x01000000 /* Ok for sqlite3_open_v2() */
16131617
16141618
/* Reserved: 0x00F00000 */
16151619
16161620
/*
16171621
** CAPI3REF: Device Characteristics
@@ -2019,20 +2023,20 @@
20192023
**
20202024
** <li>[[SQLITE_FCNTL_BUSYHANDLER]]
20212025
** ^The [SQLITE_FCNTL_BUSYHANDLER]
20222026
** file-control may be invoked by SQLite on the database file handle
20232027
** shortly after it is opened in order to provide a custom VFS with access
2024
-** to the connections busy-handler callback. The argument is of type (void **)
2028
+** to the connection's busy-handler callback. The argument is of type (void**)
20252029
** - an array of two (void *) values. The first (void *) actually points
2026
-** to a function of type (int (*)(void *)). In order to invoke the connections
2030
+** to a function of type (int (*)(void *)). In order to invoke the connection's
20272031
** busy-handler, this function should be invoked with the second (void *) in
20282032
** the array as the only argument. If it returns non-zero, then the operation
20292033
** should be retried. If it returns zero, the custom VFS should abandon the
20302034
** current operation.
20312035
**
20322036
** <li>[[SQLITE_FCNTL_TEMPFILENAME]]
2033
-** ^Application can invoke the [SQLITE_FCNTL_TEMPFILENAME] file-control
2037
+** ^Applications can invoke the [SQLITE_FCNTL_TEMPFILENAME] file-control
20342038
** to have SQLite generate a
20352039
** temporary filename using the same algorithm that is followed to generate
20362040
** temporary filenames for TEMP tables and other internal uses. The
20372041
** argument should be a char** which will be filled with the filename
20382042
** written into memory obtained from [sqlite3_malloc()]. The caller should
@@ -2141,16 +2145,22 @@
21412145
** interface can be used to find if any database on the connection has changed,
21422146
** but that interface responds to changes on TEMP as well as MAIN and does
21432147
** not provide a mechanism to detect changes to MAIN only. Also, the
21442148
** [sqlite3_total_changes()] interface responds to internal changes only and
21452149
** omits changes made by other database connections. The
2146
-** [PRAGMA data_version] command provide a mechanism to detect changes to
2150
+** [PRAGMA data_version] command provides a mechanism to detect changes to
21472151
** a single attached database that occur due to other database connections,
21482152
** but omits changes implemented by the database connection on which it is
21492153
** called. This file control is the only mechanism to detect changes that
21502154
** happen either internally or externally and that are associated with
21512155
** a particular attached database.
2156
+**
2157
+** <li>[[SQLITE_FCNTL_CKPT_DONE]]
2158
+** The [SQLITE_FCNTL_CKPT_DONE] opcode is invoked from within a checkpoint
2159
+** in wal mode after the client has finished copying pages from the wal
2160
+** file to the database file, but before the *-shm file is updated to
2161
+** record the fact that the pages have been checkpointed.
21522162
** </ul>
21532163
*/
21542164
#define SQLITE_FCNTL_LOCKSTATE 1
21552165
#define SQLITE_FCNTL_GET_LOCKPROXYFILE 2
21562166
#define SQLITE_FCNTL_SET_LOCKPROXYFILE 3
@@ -2184,10 +2194,11 @@
21842194
#define SQLITE_FCNTL_COMMIT_ATOMIC_WRITE 32
21852195
#define SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE 33
21862196
#define SQLITE_FCNTL_LOCK_TIMEOUT 34
21872197
#define SQLITE_FCNTL_DATA_VERSION 35
21882198
#define SQLITE_FCNTL_SIZE_LIMIT 36
2199
+#define SQLITE_FCNTL_CKPT_DONE 37
21892200
21902201
/* deprecated names */
21912202
#define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE
21922203
#define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE
21932204
#define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO
@@ -2229,14 +2240,14 @@
22292240
** SQLite [version 3.5.0] on [dateof:3.5.0], then increased to 2
22302241
** with SQLite [version 3.7.0] on [dateof:3.7.0], and then increased
22312242
** to 3 with SQLite [version 3.7.6] on [dateof:3.7.6]. Additional fields
22322243
** may be appended to the sqlite3_vfs object and the iVersion value
22332244
** may increase again in future versions of SQLite.
2234
-** Note that the structure
2235
-** of the sqlite3_vfs object changes in the transition from
2245
+** Note that due to an oversight, the structure
2246
+** of the sqlite3_vfs object changed in the transition from
22362247
** SQLite [version 3.5.9] to [version 3.6.0] on [dateof:3.6.0]
2237
-** and yet the iVersion field was not modified.
2248
+** and yet the iVersion field was not increased.
22382249
**
22392250
** The szOsFile field is the size of the subclassed [sqlite3_file]
22402251
** structure used by this VFS. mxPathname is the maximum length of
22412252
** a pathname in this VFS.
22422253
**
@@ -2323,11 +2334,11 @@
23232334
** be created, and that it is an error if it already exists.
23242335
** It is <i>not</i> used to indicate the file should be opened
23252336
** for exclusive access.
23262337
**
23272338
** ^At least szOsFile bytes of memory are allocated by SQLite
2328
-** to hold the [sqlite3_file] structure passed as the third
2339
+** to hold the [sqlite3_file] structure passed as the third
23292340
** argument to xOpen. The xOpen method does not have to
23302341
** allocate the structure; it should just fill it in. Note that
23312342
** the xOpen method must set the sqlite3_file.pMethods to either
23322343
** a valid [sqlite3_io_methods] object or to NULL. xOpen must do
23332344
** this even if the open fails. SQLite expects that the sqlite3_file.pMethods
@@ -2660,11 +2671,11 @@
26602671
** Every memory allocation request coming in through [sqlite3_malloc()]
26612672
** or [sqlite3_realloc()] first calls xRoundup. If xRoundup returns 0,
26622673
** that causes the corresponding memory allocation to fail.
26632674
**
26642675
** The xInit method initializes the memory allocator. For example,
2665
-** it might allocate any require mutexes or initialize internal data
2676
+** it might allocate any required mutexes or initialize internal data
26662677
** structures. The xShutdown method is invoked (indirectly) by
26672678
** [sqlite3_shutdown()] and should deallocate any resources acquired
26682679
** by xInit. The pAppData pointer is used as the only parameter to
26692680
** xInit and xShutdown.
26702681
**
@@ -2782,10 +2793,11 @@
27822793
** <dd> ^The SQLITE_CONFIG_MEMSTATUS option takes single argument of type int,
27832794
** interpreted as a boolean, which enables or disables the collection of
27842795
** memory allocation statistics. ^(When memory allocation statistics are
27852796
** disabled, the following SQLite interfaces become non-operational:
27862797
** <ul>
2798
+** <li> [sqlite3_hard_heap_limit64()]
27872799
** <li> [sqlite3_memory_used()]
27882800
** <li> [sqlite3_memory_highwater()]
27892801
** <li> [sqlite3_soft_heap_limit64()]
27902802
** <li> [sqlite3_status64()]
27912803
** </ul>)^
@@ -2800,11 +2812,11 @@
28002812
**
28012813
** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt>
28022814
** <dd> ^The SQLITE_CONFIG_PAGECACHE option specifies a memory pool
28032815
** that SQLite can use for the database page cache with the default page
28042816
** cache implementation.
2805
-** This configuration option is a no-op if an application-define page
2817
+** This configuration option is a no-op if an application-defined page
28062818
** cache implementation is loaded using the [SQLITE_CONFIG_PCACHE2].
28072819
** ^There are three arguments to SQLITE_CONFIG_PAGECACHE: A pointer to
28082820
** 8-byte aligned memory (pMem), the size of each page cache line (sz),
28092821
** and the number of cache lines (N).
28102822
** The sz argument should be the size of the largest database page
@@ -3285,11 +3297,11 @@
32853297
** </dd>
32863298
**
32873299
** [[SQLITE_DBCONFIG_DQS_DML]]
32883300
** <dt>SQLITE_DBCONFIG_DQS_DML</td>
32893301
** <dd>The SQLITE_DBCONFIG_DQS_DML option activates or deactivates
3290
-** the legacy [double-quoted string literal] misfeature for DML statement
3302
+** the legacy [double-quoted string literal] misfeature for DML statements
32913303
** only, that is DELETE, INSERT, SELECT, and UPDATE statements. The
32923304
** default value of this setting is determined by the [-DSQLITE_DQS]
32933305
** compile-time option.
32943306
** </dd>
32953307
**
@@ -3299,10 +3311,53 @@
32993311
** the legacy [double-quoted string literal] misfeature for DDL statements,
33003312
** such as CREATE TABLE and CREATE INDEX. The
33013313
** default value of this setting is determined by the [-DSQLITE_DQS]
33023314
** compile-time option.
33033315
** </dd>
3316
+**
3317
+** [[SQLITE_DBCONFIG_TRUSTED_SCHEMA]]
3318
+** <dt>SQLITE_DBCONFIG_TRUSTED_SCHEMA</td>
3319
+** <dd>The SQLITE_DBCONFIG_TRUSTED_SCHEMA option tells SQLite to
3320
+** assume that database schemas (the contents of the [sqlite_master] tables)
3321
+** are untainted by malicious content.
3322
+** When the SQLITE_DBCONFIG_TRUSTED_SCHEMA option is disabled, SQLite
3323
+** takes additional defensive steps to protect the application from harm
3324
+** including:
3325
+** <ul>
3326
+** <li> Prohibit the use of SQL functions inside triggers, views,
3327
+** CHECK constraints, DEFAULT clauses, expression indexes,
3328
+** partial indexes, or generated columns
3329
+** unless those functions are tagged with [SQLITE_INNOCUOUS].
3330
+** <li> Prohibit the use of virtual tables inside of triggers or views
3331
+** unless those virtual tables are tagged with [SQLITE_VTAB_INNOCUOUS].
3332
+** </ul>
3333
+** This setting defaults to "on" for legacy compatibility, however
3334
+** all applications are advised to turn it off if possible. This setting
3335
+** can also be controlled using the [PRAGMA trusted_schema] statement.
3336
+** </dd>
3337
+**
3338
+** [[SQLITE_DBCONFIG_LEGACY_FILE_FORMAT]]
3339
+** <dt>SQLITE_DBCONFIG_LEGACY_FILE_FORMAT</td>
3340
+** <dd>The SQLITE_DBCONFIG_LEGACY_FILE_FORMAT option activates or deactivates
3341
+** the legacy file format flag. When activated, this flag causes all newly
3342
+** created database file to have a schema format version number (the 4-byte
3343
+** integer found at offset 44 into the database header) of 1. This in turn
3344
+** means that the resulting database file will be readable and writable by
3345
+** any SQLite version back to 3.0.0 ([dateof:3.0.0]). Without this setting,
3346
+** newly created databases are generally not understandable by SQLite versions
3347
+** prior to 3.3.0 ([dateof:3.3.0]). As these words are written, there
3348
+** is now scarcely any need to generated database files that are compatible
3349
+** all the way back to version 3.0.0, and so this setting is of little
3350
+** practical use, but is provided so that SQLite can continue to claim the
3351
+** ability to generate new database files that are compatible with version
3352
+** 3.0.0.
3353
+** <p>Note that when the SQLITE_DBCONFIG_LEGACY_FILE_FORMAT setting is on,
3354
+** the [VACUUM] command will fail with an obscure error when attempting to
3355
+** process a table with generated columns and a descending index. This is
3356
+** not considered a bug since SQLite versions 3.3.0 and earlier do not support
3357
+** either generated columns or decending indexes.
3358
+** </dd>
33043359
** </dl>
33053360
*/
33063361
#define SQLITE_DBCONFIG_MAINDBNAME 1000 /* const char* */
33073362
#define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
33083363
#define SQLITE_DBCONFIG_ENABLE_FKEY 1002 /* int int* */
@@ -3317,11 +3372,13 @@
33173372
#define SQLITE_DBCONFIG_WRITABLE_SCHEMA 1011 /* int int* */
33183373
#define SQLITE_DBCONFIG_LEGACY_ALTER_TABLE 1012 /* int int* */
33193374
#define SQLITE_DBCONFIG_DQS_DML 1013 /* int int* */
33203375
#define SQLITE_DBCONFIG_DQS_DDL 1014 /* int int* */
33213376
#define SQLITE_DBCONFIG_ENABLE_VIEW 1015 /* int int* */
3322
-#define SQLITE_DBCONFIG_MAX 1015 /* Largest DBCONFIG */
3377
+#define SQLITE_DBCONFIG_LEGACY_FILE_FORMAT 1016 /* int int* */
3378
+#define SQLITE_DBCONFIG_TRUSTED_SCHEMA 1017 /* int int* */
3379
+#define SQLITE_DBCONFIG_MAX 1017 /* Largest DBCONFIG */
33233380
33243381
/*
33253382
** CAPI3REF: Enable Or Disable Extended Result Codes
33263383
** METHOD: sqlite3
33273384
**
@@ -3523,11 +3580,11 @@
35233580
** will be rolled back automatically.
35243581
**
35253582
** ^The sqlite3_interrupt(D) call is in effect until all currently running
35263583
** SQL statements on [database connection] D complete. ^Any new SQL statements
35273584
** that are started after the sqlite3_interrupt() call and before the
3528
-** running statements reaches zero are interrupted as if they had been
3585
+** running statement count reaches zero are interrupted as if they had been
35293586
** running prior to the sqlite3_interrupt() call. ^New SQL statements
35303587
** that are started after the running statement count reaches zero are
35313588
** not effected by the sqlite3_interrupt().
35323589
** ^A call to sqlite3_interrupt(D) that occurs when there are no running
35333590
** SQL statements is a no-op and has no effect on SQL statements
@@ -3691,13 +3748,13 @@
36913748
** Alice | 43
36923749
** Bob | 28
36933750
** Cindy | 21
36943751
** </pre></blockquote>
36953752
**
3696
-** There are two column (M==2) and three rows (N==3). Thus the
3753
+** There are two columns (M==2) and three rows (N==3). Thus the
36973754
** result table has 8 entries. Suppose the result table is stored
3698
-** in an array names azResult. Then azResult holds this content:
3755
+** in an array named azResult. Then azResult holds this content:
36993756
**
37003757
** <blockquote><pre>
37013758
** azResult&#91;0] = "Name";
37023759
** azResult&#91;1] = "Age";
37033760
** azResult&#91;2] = "Alice";
@@ -3786,11 +3843,11 @@
37863843
/*
37873844
** CAPI3REF: Memory Allocation Subsystem
37883845
**
37893846
** The SQLite core uses these three routines for all of its own
37903847
** internal memory allocation needs. "Core" in the previous sentence
3791
-** does not include operating-system specific VFS implementation. The
3848
+** does not include operating-system specific [VFS] implementation. The
37923849
** Windows VFS uses native malloc() and free() for some operations.
37933850
**
37943851
** ^The sqlite3_malloc() routine returns a pointer to a block
37953852
** of memory at least N bytes in length, where N is the parameter.
37963853
** ^If sqlite3_malloc() is unable to obtain sufficient free
@@ -3847,23 +3904,10 @@
38473904
** sqlite3_malloc64(), and sqlite3_realloc64()
38483905
** is always aligned to at least an 8 byte boundary, or to a
38493906
** 4 byte boundary if the [SQLITE_4_BYTE_ALIGNED_MALLOC] compile-time
38503907
** option is used.
38513908
**
3852
-** In SQLite version 3.5.0 and 3.5.1, it was possible to define
3853
-** the SQLITE_OMIT_MEMORY_ALLOCATION which would cause the built-in
3854
-** implementation of these routines to be omitted. That capability
3855
-** is no longer provided. Only built-in memory allocators can be used.
3856
-**
3857
-** Prior to SQLite version 3.7.10, the Windows OS interface layer called
3858
-** the system malloc() and free() directly when converting
3859
-** filenames between the UTF-8 encoding used by SQLite
3860
-** and whatever filename encoding is used by the particular Windows
3861
-** installation. Memory allocation errors were detected, but
3862
-** they were reported back as [SQLITE_CANTOPEN] or
3863
-** [SQLITE_IOERR] rather than [SQLITE_NOMEM].
3864
-**
38653909
** The pointer arguments to [sqlite3_free()] and [sqlite3_realloc()]
38663910
** must be either NULL or else pointers obtained from a prior
38673911
** invocation of [sqlite3_malloc()] or [sqlite3_realloc()] that have
38683912
** not yet been released.
38693913
**
@@ -3908,11 +3952,11 @@
39083952
** CAPI3REF: Pseudo-Random Number Generator
39093953
**
39103954
** SQLite contains a high-quality pseudo-random number generator (PRNG) used to
39113955
** select random [ROWID | ROWIDs] when inserting new records into a table that
39123956
** already uses the largest possible [ROWID]. The PRNG is also used for
3913
-** the build-in random() and randomblob() SQL functions. This interface allows
3957
+** the built-in random() and randomblob() SQL functions. This interface allows
39143958
** applications to access the same PRNG for other purposes.
39153959
**
39163960
** ^A call to this routine stores N bytes of randomness into buffer P.
39173961
** ^The P parameter can be a NULL pointer.
39183962
**
@@ -4282,14 +4326,12 @@
42824326
** passing it to [sqlite3_close()] when it is no longer required.
42834327
**
42844328
** The sqlite3_open_v2() interface works like sqlite3_open()
42854329
** except that it accepts two additional parameters for additional control
42864330
** over the new database connection. ^(The flags parameter to
4287
-** sqlite3_open_v2() can take one of
4288
-** the following three values, optionally combined with the
4289
-** [SQLITE_OPEN_NOMUTEX], [SQLITE_OPEN_FULLMUTEX], [SQLITE_OPEN_SHAREDCACHE],
4290
-** [SQLITE_OPEN_PRIVATECACHE], and/or [SQLITE_OPEN_URI] flags:)^
4331
+** sqlite3_open_v2() must include, at a minimum, one of the following
4332
+** three flag combinations:)^
42914333
**
42924334
** <dl>
42934335
** ^(<dt>[SQLITE_OPEN_READONLY]</dt>
42944336
** <dd>The database is opened in read-only mode. If the database does not
42954337
** already exist, an error is returned.</dd>)^
@@ -4302,28 +4344,56 @@
43024344
** ^(<dt>[SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]</dt>
43034345
** <dd>The database is opened for reading and writing, and is created if
43044346
** it does not already exist. This is the behavior that is always used for
43054347
** sqlite3_open() and sqlite3_open16().</dd>)^
43064348
** </dl>
4349
+**
4350
+** In addition to the required flags, the following optional flags are
4351
+** also supported:
4352
+**
4353
+** <dl>
4354
+** ^(<dt>[SQLITE_OPEN_URI]</dt>
4355
+** <dd>The filename can be interpreted as a URI if this flag is set.</dd>)^
4356
+**
4357
+** ^(<dt>[SQLITE_OPEN_MEMORY]</dt>
4358
+** <dd>The database will be opened as an in-memory database. The database
4359
+** is named by the "filename" argument for the purposes of cache-sharing,
4360
+** if shared cache mode is enabled, but the "filename" is otherwise ignored.
4361
+** </dd>)^
4362
+**
4363
+** ^(<dt>[SQLITE_OPEN_NOMUTEX]</dt>
4364
+** <dd>The new database connection will use the "multi-thread"
4365
+** [threading mode].)^ This means that separate threads are allowed
4366
+** to use SQLite at the same time, as long as each thread is using
4367
+** a different [database connection].
4368
+**
4369
+** ^(<dt>[SQLITE_OPEN_FULLMUTEX]</dt>
4370
+** <dd>The new database connection will use the "serialized"
4371
+** [threading mode].)^ This means the multiple threads can safely
4372
+** attempt to use the same database connection at the same time.
4373
+** (Mutexes will block any actual concurrency, but in this mode
4374
+** there is no harm in trying.)
4375
+**
4376
+** ^(<dt>[SQLITE_OPEN_SHAREDCACHE]</dt>
4377
+** <dd>The database is opened [shared cache] enabled, overriding
4378
+** the default shared cache setting provided by
4379
+** [sqlite3_enable_shared_cache()].)^
4380
+**
4381
+** ^(<dt>[SQLITE_OPEN_PRIVATECACHE]</dt>
4382
+** <dd>The database is opened [shared cache] disabled, overriding
4383
+** the default shared cache setting provided by
4384
+** [sqlite3_enable_shared_cache()].)^
4385
+**
4386
+** [[OPEN_NOFOLLOW]] ^(<dt>[SQLITE_OPEN_NOFOLLOW]</dt>
4387
+** <dd>The database filename is not allowed to be a symbolic link</dd>
4388
+** </dl>)^
43074389
**
43084390
** If the 3rd parameter to sqlite3_open_v2() is not one of the
4309
-** combinations shown above optionally combined with other
4391
+** required combinations shown above optionally combined with other
43104392
** [SQLITE_OPEN_READONLY | SQLITE_OPEN_* bits]
43114393
** then the behavior is undefined.
43124394
**
4313
-** ^If the [SQLITE_OPEN_NOMUTEX] flag is set, then the database connection
4314
-** opens in the multi-thread [threading mode] as long as the single-thread
4315
-** mode has not been set at compile-time or start-time. ^If the
4316
-** [SQLITE_OPEN_FULLMUTEX] flag is set then the database connection opens
4317
-** in the serialized [threading mode] unless single-thread was
4318
-** previously selected at compile-time or start-time.
4319
-** ^The [SQLITE_OPEN_SHAREDCACHE] flag causes the database connection to be
4320
-** eligible to use [shared cache mode], regardless of whether or not shared
4321
-** cache is enabled using [sqlite3_enable_shared_cache()]. ^The
4322
-** [SQLITE_OPEN_PRIVATECACHE] flag causes the database connection to not
4323
-** participate in [shared cache mode] even if it is enabled.
4324
-**
43254395
** ^The fourth parameter to sqlite3_open_v2() is the name of the
43264396
** [sqlite3_vfs] object that defines the operating system interface that
43274397
** the new database connection should use. ^If the fourth parameter is
43284398
** a NULL pointer then the default [sqlite3_vfs] object is used.
43294399
**
@@ -4499,21 +4569,20 @@
44994569
);
45004570
45014571
/*
45024572
** CAPI3REF: Obtain Values For URI Parameters
45034573
**
4504
-** These are utility routines, useful to VFS implementations, that check
4505
-** to see if a database file was a URI that contained a specific query
4574
+** These are utility routines, useful to [VFS|custom VFS implementations],
4575
+** that check if a database file was a URI that contained a specific query
45064576
** parameter, and if so obtains the value of that query parameter.
45074577
**
45084578
** If F is the database filename pointer passed into the xOpen() method of
4509
-** a VFS implementation when the flags parameter to xOpen() has one or
4510
-** more of the [SQLITE_OPEN_URI] or [SQLITE_OPEN_MAIN_DB] bits set and
4511
-** P is the name of the query parameter, then
4579
+** a VFS implementation or it is the return value of [sqlite3_db_filename()]
4580
+** and if P is the name of the query parameter, then
45124581
** sqlite3_uri_parameter(F,P) returns the value of the P
45134582
** parameter if it exists or a NULL pointer if P does not appear as a
4514
-** query parameter on F. If P is a query parameter of F
4583
+** query parameter on F. If P is a query parameter of F and it
45154584
** has no explicit value, then sqlite3_uri_parameter(F,P) returns
45164585
** a pointer to an empty string.
45174586
**
45184587
** The sqlite3_uri_boolean(F,P,B) routine assumes that P is a boolean
45194588
** parameter and returns true (1) or false (0) according to the value
@@ -4521,29 +4590,76 @@
45214590
** value of query parameter P is one of "yes", "true", or "on" in any
45224591
** case or if the value begins with a non-zero number. The
45234592
** sqlite3_uri_boolean(F,P,B) routines returns false (0) if the value of
45244593
** query parameter P is one of "no", "false", or "off" in any case or
45254594
** if the value begins with a numeric zero. If P is not a query
4526
-** parameter on F or if the value of P is does not match any of the
4595
+** parameter on F or if the value of P does not match any of the
45274596
** above, then sqlite3_uri_boolean(F,P,B) returns (B!=0).
45284597
**
45294598
** The sqlite3_uri_int64(F,P,D) routine converts the value of P into a
45304599
** 64-bit signed integer and returns that integer, or D if P does not
45314600
** exist. If the value of P is something other than an integer, then
45324601
** zero is returned.
4602
+**
4603
+** The sqlite3_uri_key(F,N) returns a pointer to the name (not
4604
+** the value) of the N-th query parameter for filename F, or a NULL
4605
+** pointer if N is less than zero or greater than the number of query
4606
+** parameters minus 1. The N value is zero-based so N should be 0 to obtain
4607
+** the name of the first query parameter, 1 for the second parameter, and
4608
+** so forth.
45334609
**
45344610
** If F is a NULL pointer, then sqlite3_uri_parameter(F,P) returns NULL and
45354611
** sqlite3_uri_boolean(F,P,B) returns B. If F is not a NULL pointer and
4536
-** is not a database file pathname pointer that SQLite passed into the xOpen
4537
-** VFS method, then the behavior of this routine is undefined and probably
4538
-** undesirable.
4612
+** is not a database file pathname pointer that the SQLite core passed
4613
+** into the xOpen VFS method, then the behavior of this routine is undefined
4614
+** and probably undesirable.
4615
+**
4616
+** Beginning with SQLite [version 3.31.0] ([dateof:3.31.0]) the input F
4617
+** parameter can also be the name of a rollback journal file or WAL file
4618
+** in addition to the main database file. Prior to version 3.31.0, these
4619
+** routines would only work if F was the name of the main database file.
4620
+** When the F parameter is the name of the rollback journal or WAL file,
4621
+** it has access to all the same query parameters as were found on the
4622
+** main database file.
45394623
**
45404624
** See the [URI filename] documentation for additional information.
45414625
*/
45424626
SQLITE_API const char *sqlite3_uri_parameter(const char *zFilename, const char *zParam);
45434627
SQLITE_API int sqlite3_uri_boolean(const char *zFile, const char *zParam, int bDefault);
45444628
SQLITE_API sqlite3_int64 sqlite3_uri_int64(const char*, const char*, sqlite3_int64);
4629
+SQLITE_API const char *sqlite3_uri_key(const char *zFilename, int N);
4630
+
4631
+/*
4632
+** CAPI3REF: Translate filenames
4633
+**
4634
+** These routines are available to [VFS|custom VFS implementations] for
4635
+** translating filenames between the main database file, the journal file,
4636
+** and the WAL file.
4637
+**
4638
+** If F is the name of an sqlite database file, journal file, or WAL file
4639
+** passed by the SQLite core into the VFS, then sqlite3_filename_database(F)
4640
+** returns the name of the corresponding database file.
4641
+**
4642
+** If F is the name of an sqlite database file, journal file, or WAL file
4643
+** passed by the SQLite core into the VFS, or if F is a database filename
4644
+** obtained from [sqlite3_db_filename()], then sqlite3_filename_journal(F)
4645
+** returns the name of the corresponding rollback journal file.
4646
+**
4647
+** If F is the name of an sqlite database file, journal file, or WAL file
4648
+** that was passed by the SQLite core into the VFS, or if F is a database
4649
+** filename obtained from [sqlite3_db_filename()], then
4650
+** sqlite3_filename_wal(F) returns the name of the corresponding
4651
+** WAL file.
4652
+**
4653
+** In all of the above, if F is not the name of a database, journal or WAL
4654
+** filename passed into the VFS from the SQLite core and F is not the
4655
+** return value from [sqlite3_db_filename()], then the result is
4656
+** undefined and is likely a memory access violation.
4657
+*/
4658
+SQLITE_API const char *sqlite3_filename_database(const char*);
4659
+SQLITE_API const char *sqlite3_filename_journal(const char*);
4660
+SQLITE_API const char *sqlite3_filename_wal(const char*);
45454661
45464662
45474663
/*
45484664
** CAPI3REF: Error Codes And Messages
45494665
** METHOD: sqlite3
@@ -4858,16 +4974,16 @@
48584974
** in order to find the underlying cause of the problem. With the "v2" prepare
48594975
** interfaces, the underlying reason for the error is returned immediately.
48604976
** </li>
48614977
**
48624978
** <li>
4863
-** ^If the specific value bound to [parameter | host parameter] in the
4979
+** ^If the specific value bound to a [parameter | host parameter] in the
48644980
** WHERE clause might influence the choice of query plan for a statement,
48654981
** then the statement will be automatically recompiled, as if there had been
4866
-** a schema change, on the first [sqlite3_step()] call following any change
4982
+** a schema change, on the first [sqlite3_step()] call following any change
48674983
** to the [sqlite3_bind_text | bindings] of that [parameter].
4868
-** ^The specific value of WHERE-clause [parameter] might influence the
4984
+** ^The specific value of a WHERE-clause [parameter] might influence the
48694985
** choice of query plan if the parameter is the left-hand side of a [LIKE]
48704986
** or [GLOB] operator or if the parameter is compared to an indexed column
48714987
** and the [SQLITE_ENABLE_STAT4] compile-time option is enabled.
48724988
** </li>
48734989
** </ol>
@@ -5372,24 +5488,20 @@
53725488
** the statement, where N is the second function argument.
53735489
** ^The left-most column is column 0 for these routines.
53745490
**
53755491
** ^If the Nth column returned by the statement is an expression or
53765492
** subquery and is not a column value, then all of these functions return
5377
-** NULL. ^These routine might also return NULL if a memory allocation error
5493
+** NULL. ^These routines might also return NULL if a memory allocation error
53785494
** occurs. ^Otherwise, they return the name of the attached database, table,
53795495
** or column that query result column was extracted from.
53805496
**
53815497
** ^As with all other SQLite APIs, those whose names end with "16" return
53825498
** UTF-16 encoded strings and the other functions return UTF-8.
53835499
**
53845500
** ^These APIs are only available if the library was compiled with the
53855501
** [SQLITE_ENABLE_COLUMN_METADATA] C-preprocessor symbol.
53865502
**
5387
-** If two or more threads call one or more of these routines against the same
5388
-** prepared statement and column at the same time then the results are
5389
-** undefined.
5390
-**
53915503
** If two or more threads call one or more
53925504
** [sqlite3_column_database_name | column metadata interfaces]
53935505
** for the same [prepared statement] and result column
53945506
** at the same time then the results are undefined.
53955507
*/
@@ -5522,11 +5634,11 @@
55225634
** METHOD: sqlite3_stmt
55235635
**
55245636
** ^The sqlite3_data_count(P) interface returns the number of columns in the
55255637
** current row of the result set of [prepared statement] P.
55265638
** ^If prepared statement P does not have results ready to return
5527
-** (via calls to the [sqlite3_column_int | sqlite3_column_*()] of
5639
+** (via calls to the [sqlite3_column_int | sqlite3_column()] family of
55285640
** interfaces) then sqlite3_data_count(P) returns 0.
55295641
** ^The sqlite3_data_count(P) routine also returns 0 if P is a NULL pointer.
55305642
** ^The sqlite3_data_count(P) routine returns 0 if the previous call to
55315643
** [sqlite3_step](P) returned [SQLITE_DONE]. ^The sqlite3_data_count(P)
55325644
** will return non-zero if previous call to [sqlite3_step](P) returned
@@ -5846,12 +5958,10 @@
58465958
SQLITE_API int sqlite3_reset(sqlite3_stmt *pStmt);
58475959
58485960
/*
58495961
** CAPI3REF: Create Or Redefine SQL Functions
58505962
** KEYWORDS: {function creation routines}
5851
-** KEYWORDS: {application-defined SQL function}
5852
-** KEYWORDS: {application-defined SQL functions}
58535963
** METHOD: sqlite3
58545964
**
58555965
** ^These functions (collectively known as "function creation routines")
58565966
** are used to add SQL functions or aggregates or to redefine the behavior
58575967
** of existing SQL functions or aggregates. The only differences between
@@ -5903,13 +6013,24 @@
59036013
** perform additional optimizations on deterministic functions, so use
59046014
** of the [SQLITE_DETERMINISTIC] flag is recommended where possible.
59056015
**
59066016
** ^The fourth parameter may also optionally include the [SQLITE_DIRECTONLY]
59076017
** flag, which if present prevents the function from being invoked from
5908
-** within VIEWs or TRIGGERs. For security reasons, the [SQLITE_DIRECTONLY]
5909
-** flag is recommended for any application-defined SQL function that has
5910
-** side-effects.
6018
+** within VIEWs, TRIGGERs, CHECK constraints, generated column expressions,
6019
+** index expressions, or the WHERE clause of partial indexes.
6020
+**
6021
+** <span style="background-color:#ffff90;">
6022
+** For best security, the [SQLITE_DIRECTONLY] flag is recommended for
6023
+** all application-defined SQL functions that do not need to be
6024
+** used inside of triggers, view, CHECK constraints, or other elements of
6025
+** the database schema. This flags is especially recommended for SQL
6026
+** functions that have side effects or reveal internal application state.
6027
+** Without this flag, an attacker might be able to modify the schema of
6028
+** a database file to include invocations of the function with parameters
6029
+** chosen by the attacker, which the application will then execute when
6030
+** the database file is opened and read.
6031
+** </span>
59116032
**
59126033
** ^(The fifth parameter is an arbitrary pointer. The implementation of the
59136034
** function can gain access to this pointer using [sqlite3_user_data()].)^
59146035
**
59156036
** ^The sixth, seventh and eighth parameters passed to the three
@@ -6024,33 +6145,71 @@
60246145
** These constants may be ORed together with the
60256146
** [SQLITE_UTF8 | preferred text encoding] as the fourth argument
60266147
** to [sqlite3_create_function()], [sqlite3_create_function16()], or
60276148
** [sqlite3_create_function_v2()].
60286149
**
6029
-** The SQLITE_DETERMINISTIC flag means that the new function will always
6030
-** maps the same inputs into the same output. The abs() function is
6031
-** deterministic, for example, but randomblob() is not.
6032
-**
6150
+** <dl>
6151
+** [[SQLITE_DETERMINISTIC]] <dt>SQLITE_DETERMINISTIC</dt><dd>
6152
+** The SQLITE_DETERMINISTIC flag means that the new function always gives
6153
+** the same output when the input parameters are the same.
6154
+** The [abs|abs() function] is deterministic, for example, but
6155
+** [randomblob|randomblob()] is not. Functions must
6156
+** be deterministic in order to be used in certain contexts such as
6157
+** with the WHERE clause of [partial indexes] or in [generated columns].
6158
+** SQLite might also optimize deterministic functions by factoring them
6159
+** out of inner loops.
6160
+** </dd>
6161
+**
6162
+** [[SQLITE_DIRECTONLY]] <dt>SQLITE_DIRECTONLY</dt><dd>
60336163
** The SQLITE_DIRECTONLY flag means that the function may only be invoked
6034
-** from top-level SQL, and cannot be used in VIEWs or TRIGGERs. This is
6035
-** a security feature which is recommended for all
6036
-** [application-defined SQL functions] that have side-effects. This flag
6037
-** prevents an attacker from adding triggers and views to a schema then
6038
-** tricking a high-privilege application into causing unintended side-effects
6039
-** while performing ordinary queries.
6164
+** from top-level SQL, and cannot be used in VIEWs or TRIGGERs nor in
6165
+** schema structures such as [CHECK constraints], [DEFAULT clauses],
6166
+** [expression indexes], [partial indexes], or [generated columns].
6167
+** The SQLITE_DIRECTONLY flags is a security feature which is recommended
6168
+** for all [application-defined SQL functions], and especially for functions
6169
+** that have side-effects or that could potentially leak sensitive
6170
+** information.
6171
+** </dd>
60406172
**
6173
+** [[SQLITE_INNOCUOUS]] <dt>SQLITE_INNOCUOUS</dt><dd>
6174
+** The SQLITE_INNOCUOUS flag means that the function is unlikely
6175
+** to cause problems even if misused. An innocuous function should have
6176
+** no side effects and should not depend on any values other than its
6177
+** input parameters. The [abs|abs() function] is an example of an
6178
+** innocuous function.
6179
+** The [load_extension() SQL function] is not innocuous because of its
6180
+** side effects.
6181
+** <p> SQLITE_INNOCUOUS is similar to SQLITE_DETERMINISTIC, but is not
6182
+** exactly the same. The [random|random() function] is an example of a
6183
+** function that is innocuous but not deterministic.
6184
+** <p>Some heightened security settings
6185
+** ([SQLITE_DBCONFIG_TRUSTED_SCHEMA] and [PRAGMA trusted_schema=OFF])
6186
+** disable the use of SQL functions inside views and triggers and in
6187
+** schema structures such as [CHECK constraints], [DEFAULT clauses],
6188
+** [expression indexes], [partial indexes], and [generated columns] unless
6189
+** the function is tagged with SQLITE_INNOCUOUS. Most built-in functions
6190
+** are innocuous. Developers are advised to avoid using the
6191
+** SQLITE_INNOCUOUS flag for application-defined functions unless the
6192
+** function has been carefully audited and found to be free of potentially
6193
+** security-adverse side-effects and information-leaks.
6194
+** </dd>
6195
+**
6196
+** [[SQLITE_SUBTYPE]] <dt>SQLITE_SUBTYPE</dt><dd>
60416197
** The SQLITE_SUBTYPE flag indicates to SQLite that a function may call
60426198
** [sqlite3_value_subtype()] to inspect the sub-types of its arguments.
60436199
** Specifying this flag makes no difference for scalar or aggregate user
60446200
** functions. However, if it is not specified for a user-defined window
60456201
** function, then any sub-types belonging to arguments passed to the window
60466202
** function may be discarded before the window function is called (i.e.
60476203
** sqlite3_value_subtype() will always return 0).
6204
+** </dd>
6205
+** </dl>
60486206
*/
60496207
#define SQLITE_DETERMINISTIC 0x000000800
60506208
#define SQLITE_DIRECTONLY 0x000080000
60516209
#define SQLITE_SUBTYPE 0x000100000
6210
+#define SQLITE_INNOCUOUS 0x000200000
60526211
60536212
/*
60546213
** CAPI3REF: Deprecated Functions
60556214
** DEPRECATED
60566215
**
@@ -6105,12 +6264,12 @@
61056264
**
61066265
** <b>Details:</b>
61076266
**
61086267
** These routines extract type, size, and content information from
61096268
** [protected sqlite3_value] objects. Protected sqlite3_value objects
6110
-** are used to pass parameter information into implementation of
6111
-** [application-defined SQL functions] and [virtual tables].
6269
+** are used to pass parameter information into the functions that
6270
+** implement [application-defined SQL functions] and [virtual tables].
61126271
**
61136272
** These routines work only with [protected sqlite3_value] objects.
61146273
** Any attempt to use these routines on an [unprotected sqlite3_value]
61156274
** is not threadsafe.
61166275
**
@@ -6163,11 +6322,11 @@
61636322
** the return value is arbitrary and meaningless.
61646323
**
61656324
** ^The sqlite3_value_frombind(X) interface returns non-zero if the
61666325
** value X originated from one of the [sqlite3_bind_int|sqlite3_bind()]
61676326
** interfaces. ^If X comes from an SQL literal value, or a table column,
6168
-** and expression, then sqlite3_value_frombind(X) returns zero.
6327
+** or an expression, then sqlite3_value_frombind(X) returns zero.
61696328
**
61706329
** Please pay particular attention to the fact that the pointer returned
61716330
** from [sqlite3_value_blob()], [sqlite3_value_text()], or
61726331
** [sqlite3_value_text16()] can be invalidated by a subsequent call to
61736332
** [sqlite3_value_bytes()], [sqlite3_value_bytes16()], [sqlite3_value_text()],
@@ -6249,12 +6408,12 @@
62496408
**
62506409
** Implementations of aggregate SQL functions use this
62516410
** routine to allocate memory for storing their state.
62526411
**
62536412
** ^The first time the sqlite3_aggregate_context(C,N) routine is called
6254
-** for a particular aggregate function, SQLite
6255
-** allocates N of memory, zeroes out that memory, and returns a pointer
6413
+** for a particular aggregate function, SQLite allocates
6414
+** N bytes of memory, zeroes out that memory, and returns a pointer
62566415
** to the new memory. ^On second and subsequent calls to
62576416
** sqlite3_aggregate_context() for the same aggregate function instance,
62586417
** the same buffer is returned. Sqlite3_aggregate_context() is normally
62596418
** called once for each invocation of the xStep callback and then one
62606419
** last time when the xFinal callback is invoked. ^(When no rows match
@@ -6267,11 +6426,11 @@
62676426
** when first called if N is less than or equal to zero or if a memory
62686427
** allocate error occurs.
62696428
**
62706429
** ^(The amount of space allocated by sqlite3_aggregate_context(C,N) is
62716430
** determined by the N parameter on first successful call. Changing the
6272
-** value of N in subsequent call to sqlite3_aggregate_context() within
6431
+** value of N in any subsequents call to sqlite3_aggregate_context() within
62736432
** the same aggregate function instance will not resize the memory
62746433
** allocation.)^ Within the xFinal callback, it is customary to set
62756434
** N=0 in calls to sqlite3_aggregate_context(C,N) so that no
62766435
** pointless memory allocations occur.
62776436
**
@@ -6578,31 +6737,32 @@
65786737
** <li> [SQLITE_UTF16BE],
65796738
** <li> [SQLITE_UTF16], or
65806739
** <li> [SQLITE_UTF16_ALIGNED].
65816740
** </ul>)^
65826741
** ^The eTextRep argument determines the encoding of strings passed
6583
-** to the collating function callback, xCallback.
6742
+** to the collating function callback, xCompare.
65846743
** ^The [SQLITE_UTF16] and [SQLITE_UTF16_ALIGNED] values for eTextRep
65856744
** force strings to be UTF16 with native byte order.
65866745
** ^The [SQLITE_UTF16_ALIGNED] value for eTextRep forces strings to begin
65876746
** on an even byte address.
65886747
**
65896748
** ^The fourth argument, pArg, is an application data pointer that is passed
65906749
** through as the first argument to the collating function callback.
65916750
**
6592
-** ^The fifth argument, xCallback, is a pointer to the collating function.
6751
+** ^The fifth argument, xCompare, is a pointer to the collating function.
65936752
** ^Multiple collating functions can be registered using the same name but
65946753
** with different eTextRep parameters and SQLite will use whichever
65956754
** function requires the least amount of data transformation.
6596
-** ^If the xCallback argument is NULL then the collating function is
6755
+** ^If the xCompare argument is NULL then the collating function is
65976756
** deleted. ^When all collating functions having the same name are deleted,
65986757
** that collation is no longer usable.
65996758
**
66006759
** ^The collating function callback is invoked with a copy of the pArg
66016760
** application data pointer and with two strings in the encoding specified
6602
-** by the eTextRep argument. The collating function must return an
6603
-** integer that is negative, zero, or positive
6761
+** by the eTextRep argument. The two integer parameters to the collating
6762
+** function callback are the length of the two strings, in bytes. The collating
6763
+** function must return an integer that is negative, zero, or positive
66046764
** if the first string is less than, equal to, or greater than the second,
66056765
** respectively. A collating function must always return the same answer
66066766
** given the same inputs. If two or more collating functions are registered
66076767
** to the same collation name (using different eTextRep values) then all
66086768
** must give an equivalent answer when invoked with equivalent strings.
@@ -6615,11 +6775,11 @@
66156775
** <li> If A&lt;B THEN B&gt;A.
66166776
** <li> If A&lt;B and B&lt;C then A&lt;C.
66176777
** </ol>
66186778
**
66196779
** If a collating function fails any of the above constraints and that
6620
-** collating function is registered and used, then the behavior of SQLite
6780
+** collating function is registered and used, then the behavior of SQLite
66216781
** is undefined.
66226782
**
66236783
** ^The sqlite3_create_collation_v2() works like sqlite3_create_collation()
66246784
** with the addition that the xDestroy callback is invoked on pArg when
66256785
** the collating function is deleted.
@@ -6942,20 +7102,35 @@
69427102
69437103
/*
69447104
** CAPI3REF: Return The Filename For A Database Connection
69457105
** METHOD: sqlite3
69467106
**
6947
-** ^The sqlite3_db_filename(D,N) interface returns a pointer to a filename
6948
-** associated with database N of connection D. ^The main database file
6949
-** has the name "main". If there is no attached database N on the database
7107
+** ^The sqlite3_db_filename(D,N) interface returns a pointer to the filename
7108
+** associated with database N of connection D.
7109
+** ^If there is no attached database N on the database
69507110
** connection D, or if database N is a temporary or in-memory database, then
69517111
** this function will return either a NULL pointer or an empty string.
7112
+**
7113
+** ^The string value returned by this routine is owned and managed by
7114
+** the database connection. ^The value will be valid until the database N
7115
+** is [DETACH]-ed or until the database connection closes.
69527116
**
69537117
** ^The filename returned by this function is the output of the
69547118
** xFullPathname method of the [VFS]. ^In other words, the filename
69557119
** will be an absolute pathname, even if the filename used
69567120
** to open the database originally was a URI or relative pathname.
7121
+**
7122
+** If the filename pointer returned by this routine is not NULL, then it
7123
+** can be used as the filename input parameter to these routines:
7124
+** <ul>
7125
+** <li> [sqlite3_uri_parameter()]
7126
+** <li> [sqlite3_uri_boolean()]
7127
+** <li> [sqlite3_uri_int64()]
7128
+** <li> [sqlite3_filename_database()]
7129
+** <li> [sqlite3_filename_journal()]
7130
+** <li> [sqlite3_filename_wal()]
7131
+** </ul>
69577132
*/
69587133
SQLITE_API const char *sqlite3_db_filename(sqlite3 *db, const char *zDbName);
69597134
69607135
/*
69617136
** CAPI3REF: Determine if a database is read-only
@@ -7101,19 +7276,23 @@
71017276
** In prior versions of SQLite,
71027277
** sharing was enabled or disabled for each thread separately.
71037278
**
71047279
** ^(The cache sharing mode set by this interface effects all subsequent
71057280
** calls to [sqlite3_open()], [sqlite3_open_v2()], and [sqlite3_open16()].
7106
-** Existing database connections continue use the sharing mode
7281
+** Existing database connections continue to use the sharing mode
71077282
** that was in effect at the time they were opened.)^
71087283
**
71097284
** ^(This routine returns [SQLITE_OK] if shared cache was enabled or disabled
71107285
** successfully. An [error code] is returned otherwise.)^
71117286
**
7112
-** ^Shared cache is disabled by default. But this might change in
7113
-** future releases of SQLite. Applications that care about shared
7114
-** cache setting should set it explicitly.
7287
+** ^Shared cache is disabled by default. It is recommended that it stay
7288
+** that way. In other words, do not use this routine. This interface
7289
+** continues to be provided for historical compatibility, but its use is
7290
+** discouraged. Any use of shared cache is discouraged. If shared cache
7291
+** must be used, it is recommended that shared cache only be enabled for
7292
+** individual database connections using the [sqlite3_open_v2()] interface
7293
+** with the [SQLITE_OPEN_SHAREDCACHE] flag.
71157294
**
71167295
** Note: This method is disabled on MacOS X 10.7 and iOS version 5.0
71177296
** and will always return SQLITE_MISUSE. On those systems,
71187297
** shared cache mode should be enabled per-database connection via
71197298
** [sqlite3_open_v2()] with [SQLITE_OPEN_SHAREDCACHE].
@@ -7155,10 +7334,13 @@
71557334
*/
71567335
SQLITE_API int sqlite3_db_release_memory(sqlite3*);
71577336
71587337
/*
71597338
** CAPI3REF: Impose A Limit On Heap Size
7339
+**
7340
+** These interfaces impose limits on the amount of heap memory that will be
7341
+** by all database connections within a single process.
71607342
**
71617343
** ^The sqlite3_soft_heap_limit64() interface sets and/or queries the
71627344
** soft limit on the amount of heap memory that may be allocated by SQLite.
71637345
** ^SQLite strives to keep heap memory utilization below the soft heap
71647346
** limit by reducing the number of pages held in the page cache
@@ -7166,24 +7348,45 @@
71667348
** ^The soft heap limit is "soft" because even though SQLite strives to stay
71677349
** below the limit, it will exceed the limit rather than generate
71687350
** an [SQLITE_NOMEM] error. In other words, the soft heap limit
71697351
** is advisory only.
71707352
**
7171
-** ^The return value from sqlite3_soft_heap_limit64() is the size of
7172
-** the soft heap limit prior to the call, or negative in the case of an
7353
+** ^The sqlite3_hard_heap_limit64(N) interface sets a hard upper bound of
7354
+** N bytes on the amount of memory that will be allocated. ^The
7355
+** sqlite3_hard_heap_limit64(N) interface is similar to
7356
+** sqlite3_soft_heap_limit64(N) except that memory allocations will fail
7357
+** when the hard heap limit is reached.
7358
+**
7359
+** ^The return value from both sqlite3_soft_heap_limit64() and
7360
+** sqlite3_hard_heap_limit64() is the size of
7361
+** the heap limit prior to the call, or negative in the case of an
71737362
** error. ^If the argument N is negative
7174
-** then no change is made to the soft heap limit. Hence, the current
7175
-** size of the soft heap limit can be determined by invoking
7176
-** sqlite3_soft_heap_limit64() with a negative argument.
7363
+** then no change is made to the heap limit. Hence, the current
7364
+** size of heap limits can be determined by invoking
7365
+** sqlite3_soft_heap_limit64(-1) or sqlite3_hard_heap_limit(-1).
71777366
**
7178
-** ^If the argument N is zero then the soft heap limit is disabled.
7367
+** ^Setting the heap limits to zero disables the heap limiter mechanism.
71797368
**
7180
-** ^(The soft heap limit is not enforced in the current implementation
7369
+** ^The soft heap limit may not be greater than the hard heap limit.
7370
+** ^If the hard heap limit is enabled and if sqlite3_soft_heap_limit(N)
7371
+** is invoked with a value of N that is greater than the hard heap limit,
7372
+** the the soft heap limit is set to the value of the hard heap limit.
7373
+** ^The soft heap limit is automatically enabled whenever the hard heap
7374
+** limit is enabled. ^When sqlite3_hard_heap_limit64(N) is invoked and
7375
+** the soft heap limit is outside the range of 1..N, then the soft heap
7376
+** limit is set to N. ^Invoking sqlite3_soft_heap_limit64(0) when the
7377
+** hard heap limit is enabled makes the soft heap limit equal to the
7378
+** hard heap limit.
7379
+**
7380
+** The memory allocation limits can also be adjusted using
7381
+** [PRAGMA soft_heap_limit] and [PRAGMA hard_heap_limit].
7382
+**
7383
+** ^(The heap limits are not enforced in the current implementation
71817384
** if one or more of following conditions are true:
71827385
**
71837386
** <ul>
7184
-** <li> The soft heap limit is set to zero.
7387
+** <li> The limit value is set to zero.
71857388
** <li> Memory accounting is disabled using a combination of the
71867389
** [sqlite3_config]([SQLITE_CONFIG_MEMSTATUS],...) start-time option and
71877390
** the [SQLITE_DEFAULT_MEMSTATUS] compile-time option.
71887391
** <li> An alternative page cache implementation is specified using
71897392
** [sqlite3_config]([SQLITE_CONFIG_PCACHE2],...).
@@ -7190,25 +7393,15 @@
71907393
** <li> The page cache allocates from its own memory pool supplied
71917394
** by [sqlite3_config]([SQLITE_CONFIG_PAGECACHE],...) rather than
71927395
** from the heap.
71937396
** </ul>)^
71947397
**
7195
-** Beginning with SQLite [version 3.7.3] ([dateof:3.7.3]),
7196
-** the soft heap limit is enforced
7197
-** regardless of whether or not the [SQLITE_ENABLE_MEMORY_MANAGEMENT]
7198
-** compile-time option is invoked. With [SQLITE_ENABLE_MEMORY_MANAGEMENT],
7199
-** the soft heap limit is enforced on every memory allocation. Without
7200
-** [SQLITE_ENABLE_MEMORY_MANAGEMENT], the soft heap limit is only enforced
7201
-** when memory is allocated by the page cache. Testing suggests that because
7202
-** the page cache is the predominate memory user in SQLite, most
7203
-** applications will achieve adequate soft heap limit enforcement without
7204
-** the use of [SQLITE_ENABLE_MEMORY_MANAGEMENT].
7205
-**
7206
-** The circumstances under which SQLite will enforce the soft heap limit may
7398
+** The circumstances under which SQLite will enforce the heap limits may
72077399
** changes in future releases of SQLite.
72087400
*/
72097401
SQLITE_API sqlite3_int64 sqlite3_soft_heap_limit64(sqlite3_int64 N);
7402
+SQLITE_API sqlite3_int64 sqlite3_hard_heap_limit64(sqlite3_int64 N);
72107403
72117404
/*
72127405
** CAPI3REF: Deprecated Soft Heap Limit Interface
72137406
** DEPRECATED
72147407
**
@@ -7228,11 +7421,11 @@
72287421
** information about column C of table T in database D
72297422
** on [database connection] X.)^ ^The sqlite3_table_column_metadata()
72307423
** interface returns SQLITE_OK and fills in the non-NULL pointers in
72317424
** the final five arguments with appropriate values if the specified
72327425
** column exists. ^The sqlite3_table_column_metadata() interface returns
7233
-** SQLITE_ERROR and if the specified column does not exist.
7426
+** SQLITE_ERROR if the specified column does not exist.
72347427
** ^If the column-name parameter to sqlite3_table_column_metadata() is a
72357428
** NULL pointer, then this routine simply checks for the existence of the
72367429
** table and returns SQLITE_OK if the table exists and SQLITE_ERROR if it
72377430
** does not. If the table name parameter T in a call to
72387431
** sqlite3_table_column_metadata(X,D,T,C,...) is NULL then the result is
@@ -7370,11 +7563,11 @@
73707563
** [sqlite3_load_extension()] and the SQL function [load_extension()].
73717564
** ^(Use [sqlite3_db_config](db,[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION],..)
73727565
** to enable or disable only the C-API.)^
73737566
**
73747567
** <b>Security warning:</b> It is recommended that extension loading
7375
-** be disabled using the [SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION] method
7568
+** be enabled using the [SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION] method
73767569
** rather than this interface, so the [load_extension()] SQL function
73777570
** remains disabled. This will prevent SQL injections from giving attackers
73787571
** access to extension loading capabilities.
73797572
*/
73807573
SQLITE_API int sqlite3_enable_load_extension(sqlite3 *db, int onoff);
@@ -7457,11 +7650,11 @@
74577650
/*
74587651
** CAPI3REF: Virtual Table Object
74597652
** KEYWORDS: sqlite3_module {virtual table module}
74607653
**
74617654
** This structure, sometimes called a "virtual table module",
7462
-** defines the implementation of a [virtual tables].
7655
+** defines the implementation of a [virtual table].
74637656
** This structure consists mostly of methods for the module.
74647657
**
74657658
** ^A virtual table module is created by filling in a persistent
74667659
** instance of this structure and passing a pointer to that instance
74677660
** to [sqlite3_create_module()] or [sqlite3_create_module_v2()].
@@ -7554,11 +7747,17 @@
75547747
** The [xBestIndex] method must fill aConstraintUsage[] with information
75557748
** about what parameters to pass to xFilter. ^If argvIndex>0 then
75567749
** the right-hand side of the corresponding aConstraint[] is evaluated
75577750
** and becomes the argvIndex-th entry in argv. ^(If aConstraintUsage[].omit
75587751
** is true, then the constraint is assumed to be fully handled by the
7559
-** virtual table and is not checked again by SQLite.)^
7752
+** virtual table and might not be checked again by the byte code.)^ ^(The
7753
+** aConstraintUsage[].omit flag is an optimization hint. When the omit flag
7754
+** is left in its default setting of false, the constraint will always be
7755
+** checked separately in byte code. If the omit flag is change to true, then
7756
+** the constraint may or may not be checked in byte code. In other words,
7757
+** when the omit flag is true there is no guarantee that the constraint will
7758
+** not be checked again using byte code.)^
75607759
**
75617760
** ^The idxNum and idxPtr values are recorded and passed into the
75627761
** [xFilter] method.
75637762
** ^[sqlite3_free()] is used to free idxPtr if and only if
75647763
** needToFreeIdxPtr is true.
@@ -7594,11 +7793,11 @@
75947793
** IMPORTANT: The estimatedRows field was added to the sqlite3_index_info
75957794
** structure for SQLite [version 3.8.2] ([dateof:3.8.2]).
75967795
** If a virtual table extension is
75977796
** used with an SQLite version earlier than 3.8.2, the results of attempting
75987797
** to read or write the estimatedRows field are undefined (but are likely
7599
-** to included crashing the application). The estimatedRows field should
7798
+** to include crashing the application). The estimatedRows field should
76007799
** therefore only be used if [sqlite3_libversion_number()] returns a
76017800
** value greater than or equal to 3008002. Similarly, the idxFlags field
76027801
** was added for [version 3.9.0] ([dateof:3.9.0]).
76037802
** It may therefore only be used if
76047803
** sqlite3_libversion_number() returns a value greater than or equal to
@@ -7646,11 +7845,11 @@
76467845
#define SQLITE_INDEX_SCAN_UNIQUE 1 /* Scan visits at most 1 row */
76477846
76487847
/*
76497848
** CAPI3REF: Virtual Table Constraint Operator Codes
76507849
**
7651
-** These macros defined the allowed values for the
7850
+** These macros define the allowed values for the
76527851
** [sqlite3_index_info].aConstraint[].op field. Each value represents
76537852
** an operator that is part of a constraint term in the wHERE clause of
76547853
** a query that uses a [virtual table].
76557854
*/
76567855
#define SQLITE_INDEX_CONSTRAINT_EQ 2
@@ -8256,11 +8455,11 @@
82568455
** </ul>)^
82578456
**
82588457
** The only difference is that the public sqlite3_XXX functions enumerated
82598458
** above silently ignore any invocations that pass a NULL pointer instead
82608459
** of a valid mutex handle. The implementations of the methods defined
8261
-** by this structure are not required to handle this case, the results
8460
+** by this structure are not required to handle this case. The results
82628461
** of passing a NULL pointer instead of a valid mutex handle are undefined
82638462
** (i.e. it is acceptable to provide an implementation that segfaults if
82648463
** it is passed a NULL pointer).
82658464
**
82668465
** The xMutexInit() method must be threadsafe. It must be harmless to
@@ -8729,11 +8928,11 @@
87298928
** [SQLITE_CONFIG_PAGECACHE]) and allocations that overflowed because
87308929
** no space was left in the page cache.</dd>)^
87318930
**
87328931
** [[SQLITE_STATUS_PAGECACHE_SIZE]] ^(<dt>SQLITE_STATUS_PAGECACHE_SIZE</dt>
87338932
** <dd>This parameter records the largest memory allocation request
8734
-** handed to [pagecache memory allocator]. Only the value returned in the
8933
+** handed to the [pagecache memory allocator]. Only the value returned in the
87358934
** *pHighwater parameter to [sqlite3_status()] is of interest.
87368935
** The value written into the *pCurrent parameter is undefined.</dd>)^
87378936
**
87388937
** [[SQLITE_STATUS_SCRATCH_USED]] <dt>SQLITE_STATUS_SCRATCH_USED</dt>
87398938
** <dd>No longer used.</dd>
@@ -8805,11 +9004,11 @@
88059004
** [[SQLITE_DBSTATUS_LOOKASIDE_USED]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
88069005
** <dd>This parameter returns the number of lookaside memory slots currently
88079006
** checked out.</dd>)^
88089007
**
88099008
** [[SQLITE_DBSTATUS_LOOKASIDE_HIT]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_HIT</dt>
8810
-** <dd>This parameter returns the number malloc attempts that were
9009
+** <dd>This parameter returns the number of malloc attempts that were
88119010
** satisfied using lookaside memory. Only the high-water value is meaningful;
88129011
** the current value is always zero.)^
88139012
**
88149013
** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE]]
88159014
** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE</dt>
@@ -8887,11 +9086,11 @@
88879086
** <dd>This parameter returns the number of dirty cache entries that have
88889087
** been written to disk in the middle of a transaction due to the page
88899088
** cache overflowing. Transactions are more efficient if they are written
88909089
** to disk all at once. When pages spill mid-transaction, that introduces
88919090
** additional overhead. This parameter can be used help identify
8892
-** inefficiencies that can be resolve by increasing the cache size.
9091
+** inefficiencies that can be resolved by increasing the cache size.
88939092
** </dd>
88949093
**
88959094
** [[SQLITE_DBSTATUS_DEFERRED_FKS]] ^(<dt>SQLITE_DBSTATUS_DEFERRED_FKS</dt>
88969095
** <dd>This parameter returns zero for the current value if and only if
88979096
** all foreign key constraints (deferred or immediate) have been
@@ -8976,11 +9175,11 @@
89769175
** If the number of virtual machine operations exceeds 2147483647
89779176
** then the value returned by this statement status code is undefined.
89789177
**
89799178
** [[SQLITE_STMTSTATUS_REPREPARE]] <dt>SQLITE_STMTSTATUS_REPREPARE</dt>
89809179
** <dd>^This is the number of times that the prepare statement has been
8981
-** automatically regenerated due to schema changes or change to
9180
+** automatically regenerated due to schema changes or changes to
89829181
** [bound parameters] that might affect the query plan.
89839182
**
89849183
** [[SQLITE_STMTSTATUS_RUN]] <dt>SQLITE_STMTSTATUS_RUN</dt>
89859184
** <dd>^This is the number of times that the prepared statement has
89869185
** been run. A single "run" for the purposes of this counter is one
@@ -9147,11 +9346,11 @@
91479346
** NULL if allocating a new page is effectively impossible.
91489347
** </table>
91499348
**
91509349
** ^(SQLite will normally invoke xFetch() with a createFlag of 0 or 1. SQLite
91519350
** will only use a createFlag of 2 after a prior call with a createFlag of 1
9152
-** failed.)^ In between the to xFetch() calls, SQLite may
9351
+** failed.)^ In between the xFetch() calls, SQLite may
91539352
** attempt to unpin one or more cache pages by spilling the content of
91549353
** pinned pages to disk and synching the operating system disk cache.
91559354
**
91569355
** [[the xUnpin() page cache method]]
91579356
** ^xUnpin() is called by SQLite with a pointer to a currently pinned page
@@ -9465,11 +9664,11 @@
94659664
** application receives an SQLITE_LOCKED error, it may call the
94669665
** sqlite3_unlock_notify() method with the blocked connection handle as
94679666
** the first argument to register for a callback that will be invoked
94689667
** when the blocking connections current transaction is concluded. ^The
94699668
** callback is invoked from within the [sqlite3_step] or [sqlite3_close]
9470
-** call that concludes the blocking connections transaction.
9669
+** call that concludes the blocking connection's transaction.
94719670
**
94729671
** ^(If sqlite3_unlock_notify() is called in a multi-threaded application,
94739672
** there is a chance that the blocking connection will have already
94749673
** concluded its transaction by the time sqlite3_unlock_notify() is invoked.
94759674
** If this happens, then the specified callback is invoked immediately,
@@ -9503,11 +9702,11 @@
95039702
** However, the signature of the callback function allows SQLite to pass
95049703
** it an array of void* context pointers. The first argument passed to
95059704
** an unlock-notify callback is a pointer to an array of void* pointers,
95069705
** and the second is the number of entries in the array.
95079706
**
9508
-** When a blocking connections transaction is concluded, there may be
9707
+** When a blocking connection's transaction is concluded, there may be
95099708
** more than one blocked connection that has registered for an unlock-notify
95109709
** callback. ^If two or more such blocked connections have specified the
95119710
** same callback function, then instead of invoking the callback function
95129711
** multiple times, it is invoked once with the set of void* context pointers
95139712
** specified by the blocked connections bundled together into an array.
@@ -9851,26 +10050,32 @@
985110050
** various facets of the virtual table interface.
985210051
**
985310052
** If this interface is invoked outside the context of an xConnect or
985410053
** xCreate virtual table method then the behavior is undefined.
985510054
**
9856
-** At present, there is only one option that may be configured using
9857
-** this function. (See [SQLITE_VTAB_CONSTRAINT_SUPPORT].) Further options
9858
-** may be added in the future.
10055
+** In the call sqlite3_vtab_config(D,C,...) the D parameter is the
10056
+** [database connection] in which the virtual table is being created and
10057
+** which is passed in as the first argument to the [xConnect] or [xCreate]
10058
+** method that is invoking sqlite3_vtab_config(). The C parameter is one
10059
+** of the [virtual table configuration options]. The presence and meaning
10060
+** of parameters after C depend on which [virtual table configuration option]
10061
+** is used.
985910062
*/
986010063
SQLITE_API int sqlite3_vtab_config(sqlite3*, int op, ...);
986110064
986210065
/*
986310066
** CAPI3REF: Virtual Table Configuration Options
10067
+** KEYWORDS: {virtual table configuration options}
10068
+** KEYWORDS: {virtual table configuration option}
986410069
**
986510070
** These macros define the various options to the
986610071
** [sqlite3_vtab_config()] interface that [virtual table] implementations
986710072
** can use to customize and optimize their behavior.
986810073
**
986910074
** <dl>
987010075
** [[SQLITE_VTAB_CONSTRAINT_SUPPORT]]
9871
-** <dt>SQLITE_VTAB_CONSTRAINT_SUPPORT
10076
+** <dt>SQLITE_VTAB_CONSTRAINT_SUPPORT</dt>
987210077
** <dd>Calls of the form
987310078
** [sqlite3_vtab_config](db,SQLITE_VTAB_CONSTRAINT_SUPPORT,X) are supported,
987410079
** where X is an integer. If X is zero, then the [virtual table] whose
987510080
** [xCreate] or [xConnect] method invoked [sqlite3_vtab_config()] does not
987610081
** support constraints. In this configuration (which is the default) if
@@ -9895,13 +10100,35 @@
989510100
** CONFLICT policy is REPLACE, the virtual table implementation should
989610101
** silently replace the appropriate rows within the xUpdate callback and
989710102
** return SQLITE_OK. Or, if this is not possible, it may return
989810103
** SQLITE_CONSTRAINT, in which case SQLite falls back to OR ABORT
989910104
** constraint handling.
10105
+** </dd>
10106
+**
10107
+** [[SQLITE_VTAB_DIRECTONLY]]<dt>SQLITE_VTAB_DIRECTONLY</dt>
10108
+** <dd>Calls of the form
10109
+** [sqlite3_vtab_config](db,SQLITE_VTAB_DIRECTONLY) from within the
10110
+** the [xConnect] or [xCreate] methods of a [virtual table] implmentation
10111
+** prohibits that virtual table from being used from within triggers and
10112
+** views.
10113
+** </dd>
10114
+**
10115
+** [[SQLITE_VTAB_INNOCUOUS]]<dt>SQLITE_VTAB_INNOCUOUS</dt>
10116
+** <dd>Calls of the form
10117
+** [sqlite3_vtab_config](db,SQLITE_VTAB_INNOCUOUS) from within the
10118
+** the [xConnect] or [xCreate] methods of a [virtual table] implmentation
10119
+** identify that virtual table as being safe to use from within triggers
10120
+** and views. Conceptually, the SQLITE_VTAB_INNOCUOUS tag means that the
10121
+** virtual table can do no serious harm even if it is controlled by a
10122
+** malicious hacker. Developers should avoid setting the SQLITE_VTAB_INNOCUOUS
10123
+** flag unless absolutely necessary.
10124
+** </dd>
990010125
** </dl>
990110126
*/
990210127
#define SQLITE_VTAB_CONSTRAINT_SUPPORT 1
10128
+#define SQLITE_VTAB_INNOCUOUS 2
10129
+#define SQLITE_VTAB_DIRECTONLY 3
990310130
990410131
/*
990510132
** CAPI3REF: Determine The Virtual Table Conflict Policy
990610133
**
990710134
** This function may only be called from within a call to the [xUpdate] method
@@ -9977,37 +10204,37 @@
997710204
** managed by the prepared statement S and will be automatically freed when
997810205
** S is finalized.
997910206
**
998010207
** <dl>
998110208
** [[SQLITE_SCANSTAT_NLOOP]] <dt>SQLITE_SCANSTAT_NLOOP</dt>
9982
-** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be
10209
+** <dd>^The [sqlite3_int64] variable pointed to by the V parameter will be
998310210
** set to the total number of times that the X-th loop has run.</dd>
998410211
**
998510212
** [[SQLITE_SCANSTAT_NVISIT]] <dt>SQLITE_SCANSTAT_NVISIT</dt>
9986
-** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be set
10213
+** <dd>^The [sqlite3_int64] variable pointed to by the V parameter will be set
998710214
** to the total number of rows examined by all iterations of the X-th loop.</dd>
998810215
**
998910216
** [[SQLITE_SCANSTAT_EST]] <dt>SQLITE_SCANSTAT_EST</dt>
9990
-** <dd>^The "double" variable pointed to by the T parameter will be set to the
10217
+** <dd>^The "double" variable pointed to by the V parameter will be set to the
999110218
** query planner's estimate for the average number of rows output from each
999210219
** iteration of the X-th loop. If the query planner's estimates was accurate,
999310220
** then this value will approximate the quotient NVISIT/NLOOP and the
999410221
** product of this value for all prior loops with the same SELECTID will
999510222
** be the NLOOP value for the current loop.
999610223
**
999710224
** [[SQLITE_SCANSTAT_NAME]] <dt>SQLITE_SCANSTAT_NAME</dt>
9998
-** <dd>^The "const char *" variable pointed to by the T parameter will be set
10225
+** <dd>^The "const char *" variable pointed to by the V parameter will be set
999910226
** to a zero-terminated UTF-8 string containing the name of the index or table
1000010227
** used for the X-th loop.
1000110228
**
1000210229
** [[SQLITE_SCANSTAT_EXPLAIN]] <dt>SQLITE_SCANSTAT_EXPLAIN</dt>
10003
-** <dd>^The "const char *" variable pointed to by the T parameter will be set
10230
+** <dd>^The "const char *" variable pointed to by the V parameter will be set
1000410231
** to a zero-terminated UTF-8 string containing the [EXPLAIN QUERY PLAN]
1000510232
** description for the X-th loop.
1000610233
**
1000710234
** [[SQLITE_SCANSTAT_SELECTID]] <dt>SQLITE_SCANSTAT_SELECT</dt>
10008
-** <dd>^The "int" variable pointed to by the T parameter will be set to the
10235
+** <dd>^The "int" variable pointed to by the V parameter will be set to the
1000910236
** "select-id" for the X-th loop. The select-id identifies which query or
1001010237
** subquery the loop is part of. The main query has a select-id of zero.
1001110238
** The select-id is the same value as is output in the first column
1001210239
** of an [EXPLAIN QUERY PLAN] query.
1001310240
** </dl>
@@ -10858,11 +11085,11 @@
1085811085
** METHOD: sqlite3_session
1085911086
**
1086011087
** The second argument (xFilter) is the "filter callback". For changes to rows
1086111088
** in tables that are not attached to the Session object, the filter is called
1086211089
** to determine whether changes to the table's rows should be tracked or not.
10863
-** If xFilter returns 0, changes is not tracked. Note that once a table is
11090
+** If xFilter returns 0, changes are not tracked. Note that once a table is
1086411091
** attached, xFilter will not be called again.
1086511092
*/
1086611093
SQLITE_API void sqlite3session_table_filter(
1086711094
sqlite3_session *pSession, /* Session object */
1086811095
int(*xFilter)(
@@ -11032,11 +11259,11 @@
1103211259
** identical.
1103311260
**
1103411261
** It an error if database zFrom does not exist or does not contain the
1103511262
** required compatible table.
1103611263
**
11037
-** If the operation successful, SQLITE_OK is returned. Otherwise, an SQLite
11264
+** If the operation is successful, SQLITE_OK is returned. Otherwise, an SQLite
1103811265
** error code. In this case, if argument pzErrMsg is not NULL, *pzErrMsg
1103911266
** may be set to point to a buffer containing an English language error
1104011267
** message. It is the responsibility of the caller to free this buffer using
1104111268
** sqlite3_free().
1104211269
*/
@@ -11169,11 +11396,11 @@
1116911396
1117011397
/*
1117111398
** CAPI3REF: Advance A Changeset Iterator
1117211399
** METHOD: sqlite3_changeset_iter
1117311400
**
11174
-** This function may only be used with iterators created by function
11401
+** This function may only be used with iterators created by the function
1117511402
** [sqlite3changeset_start()]. If it is called on an iterator passed to
1117611403
** a conflict-handler callback by [sqlite3changeset_apply()], SQLITE_MISUSE
1117711404
** is returned and the call has no effect.
1117811405
**
1117911406
** Immediately after an iterator is created by sqlite3changeset_start(), it
@@ -11585,12 +11812,12 @@
1158511812
** in the changegroup, then the number of columns and the position of the
1158611813
** primary key columns for the table must be consistent. If this is not the
1158711814
** case, this function fails with SQLITE_SCHEMA. If the input changeset
1158811815
** appears to be corrupt and the corruption is detected, SQLITE_CORRUPT is
1158911816
** returned. Or, if an out-of-memory condition occurs during processing, this
11590
-** function returns SQLITE_NOMEM. In all cases, if an error occurs the
11591
-** final contents of the changegroup is undefined.
11817
+** function returns SQLITE_NOMEM. In all cases, if an error occurs the state
11818
+** of the final contents of the changegroup is undefined.
1159211819
**
1159311820
** If no error occurs, SQLITE_OK is returned.
1159411821
*/
1159511822
SQLITE_API int sqlite3changegroup_add(sqlite3_changegroup*, int nData, void *pData);
1159611823
@@ -11761,11 +11988,11 @@
1176111988
** [SQLITE_CHANGESET_REPLACE].
1176211989
** </dl>
1176311990
**
1176411991
** It is safe to execute SQL statements, including those that write to the
1176511992
** table that the callback related to, from within the xConflict callback.
11766
-** This can be used to further customize the applications conflict
11993
+** This can be used to further customize the application's conflict
1176711994
** resolution strategy.
1176811995
**
1176911996
** All changes made by these functions are enclosed in a savepoint transaction.
1177011997
** If any other error (aside from a constraint failure when attempting to
1177111998
** write to the target database) occurs, then the savepoint transaction is
@@ -12071,11 +12298,11 @@
1207112298
** CAPI3REF: Rebase a changeset
1207212299
** EXPERIMENTAL
1207312300
**
1207412301
** Argument pIn must point to a buffer containing a changeset nIn bytes
1207512302
** in size. This function allocates and populates a buffer with a copy
12076
-** of the changeset rebased rebased according to the configuration of the
12303
+** of the changeset rebased according to the configuration of the
1207712304
** rebaser object passed as the first argument. If successful, (*ppOut)
1207812305
** is set to point to the new buffer containing the rebased changeset and
1207912306
** (*pnOut) to its size in bytes and SQLITE_OK returned. It is the
1208012307
** responsibility of the caller to eventually free the new buffer using
1208112308
** sqlite3_free(). Otherwise, if an error occurs, (*ppOut) and (*pnOut)
@@ -12479,11 +12706,11 @@
1247912706
** the callback, an SQLite error code is returned.
1248012707
**
1248112708
**
1248212709
** xSetAuxdata(pFts5, pAux, xDelete)
1248312710
**
12484
-** Save the pointer passed as the second argument as the extension functions
12711
+** Save the pointer passed as the second argument as the extension function's
1248512712
** "auxiliary data". The pointer may then be retrieved by the current or any
1248612713
** future invocation of the same fts5 extension function made as part of
1248712714
** the same MATCH query using the xGetAuxdata() API.
1248812715
**
1248912716
** Each extension function is allocated a single auxiliary data slot for
@@ -12721,12 +12948,12 @@
1272112948
** all instances of "first place" or "1st place" regardless of which form
1272212949
** the user specified in the MATCH query text.
1272312950
**
1272412951
** There are several ways to approach this in FTS5:
1272512952
**
12726
-** <ol><li> By mapping all synonyms to a single token. In this case, the
12727
-** In the above example, this means that the tokenizer returns the
12953
+** <ol><li> By mapping all synonyms to a single token. In this case, using
12954
+** the above example, this means that the tokenizer returns the
1272812955
** same token for inputs "first" and "1st". Say that token is in
1272912956
** fact "first", so that when the user inserts the document "I won
1273012957
** 1st place" entries are added to the index for tokens "i", "won",
1273112958
** "first" and "place". If the user then queries for '1st + place',
1273212959
** the tokenizer substitutes "first" for "1st" and the query works
@@ -13394,10 +13621,30 @@
1339413621
#else
1339513622
# define ALWAYS(X) (X)
1339613623
# define NEVER(X) (X)
1339713624
#endif
1339813625
13626
+/*
13627
+** The harmless(X) macro indicates that expression X is usually false
13628
+** but can be true without causing any problems, but we don't know of
13629
+** any way to cause X to be true.
13630
+**
13631
+** In debugging and testing builds, this macro will abort if X is ever
13632
+** true. In this way, developers are alerted to a possible test case
13633
+** that causes X to be true. If a harmless macro ever fails, that is
13634
+** an opportunity to change the macro into a testcase() and add a new
13635
+** test case to the test suite.
13636
+**
13637
+** For normal production builds, harmless(X) is a no-op, since it does
13638
+** not matter whether expression X is true or false.
13639
+*/
13640
+#ifdef SQLITE_DEBUG
13641
+# define harmless(X) assert(!(X));
13642
+#else
13643
+# define harmless(X)
13644
+#endif
13645
+
1339913646
/*
1340013647
** Some conditionals are optimizations only. In other words, if the
1340113648
** conditionals are replaced with a constant 1 (true) or 0 (false) then
1340213649
** the correct answer is still obtained, though perhaps not as quickly.
1340313650
**
@@ -13671,94 +13918,96 @@
1367113918
#define TK_UNBOUNDED 90
1367213919
#define TK_EXCLUDE 91
1367313920
#define TK_GROUPS 92
1367413921
#define TK_OTHERS 93
1367513922
#define TK_TIES 94
13676
-#define TK_REINDEX 95
13677
-#define TK_RENAME 96
13678
-#define TK_CTIME_KW 97
13679
-#define TK_ANY 98
13680
-#define TK_BITAND 99
13681
-#define TK_BITOR 100
13682
-#define TK_LSHIFT 101
13683
-#define TK_RSHIFT 102
13684
-#define TK_PLUS 103
13685
-#define TK_MINUS 104
13686
-#define TK_STAR 105
13687
-#define TK_SLASH 106
13688
-#define TK_REM 107
13689
-#define TK_CONCAT 108
13690
-#define TK_COLLATE 109
13691
-#define TK_BITNOT 110
13692
-#define TK_ON 111
13693
-#define TK_INDEXED 112
13694
-#define TK_STRING 113
13695
-#define TK_JOIN_KW 114
13696
-#define TK_CONSTRAINT 115
13697
-#define TK_DEFAULT 116
13698
-#define TK_NULL 117
13699
-#define TK_PRIMARY 118
13700
-#define TK_UNIQUE 119
13701
-#define TK_CHECK 120
13702
-#define TK_REFERENCES 121
13703
-#define TK_AUTOINCR 122
13704
-#define TK_INSERT 123
13705
-#define TK_DELETE 124
13706
-#define TK_UPDATE 125
13707
-#define TK_SET 126
13708
-#define TK_DEFERRABLE 127
13709
-#define TK_FOREIGN 128
13710
-#define TK_DROP 129
13711
-#define TK_UNION 130
13712
-#define TK_ALL 131
13713
-#define TK_EXCEPT 132
13714
-#define TK_INTERSECT 133
13715
-#define TK_SELECT 134
13716
-#define TK_VALUES 135
13717
-#define TK_DISTINCT 136
13718
-#define TK_DOT 137
13719
-#define TK_FROM 138
13720
-#define TK_JOIN 139
13721
-#define TK_USING 140
13722
-#define TK_ORDER 141
13723
-#define TK_GROUP 142
13724
-#define TK_HAVING 143
13725
-#define TK_LIMIT 144
13726
-#define TK_WHERE 145
13727
-#define TK_INTO 146
13728
-#define TK_NOTHING 147
13729
-#define TK_FLOAT 148
13730
-#define TK_BLOB 149
13731
-#define TK_INTEGER 150
13732
-#define TK_VARIABLE 151
13733
-#define TK_CASE 152
13734
-#define TK_WHEN 153
13735
-#define TK_THEN 154
13736
-#define TK_ELSE 155
13737
-#define TK_INDEX 156
13738
-#define TK_ALTER 157
13739
-#define TK_ADD 158
13740
-#define TK_WINDOW 159
13741
-#define TK_OVER 160
13742
-#define TK_FILTER 161
13743
-#define TK_COLUMN 162
13744
-#define TK_AGG_FUNCTION 163
13745
-#define TK_AGG_COLUMN 164
13746
-#define TK_TRUEFALSE 165
13747
-#define TK_ISNOT 166
13748
-#define TK_FUNCTION 167
13749
-#define TK_UMINUS 168
13750
-#define TK_UPLUS 169
13751
-#define TK_TRUTH 170
13752
-#define TK_REGISTER 171
13753
-#define TK_VECTOR 172
13754
-#define TK_SELECT_COLUMN 173
13755
-#define TK_IF_NULL_ROW 174
13756
-#define TK_ASTERISK 175
13757
-#define TK_SPAN 176
13758
-#define TK_SPACE 177
13759
-#define TK_ILLEGAL 178
13923
+#define TK_GENERATED 95
13924
+#define TK_ALWAYS 96
13925
+#define TK_REINDEX 97
13926
+#define TK_RENAME 98
13927
+#define TK_CTIME_KW 99
13928
+#define TK_ANY 100
13929
+#define TK_BITAND 101
13930
+#define TK_BITOR 102
13931
+#define TK_LSHIFT 103
13932
+#define TK_RSHIFT 104
13933
+#define TK_PLUS 105
13934
+#define TK_MINUS 106
13935
+#define TK_STAR 107
13936
+#define TK_SLASH 108
13937
+#define TK_REM 109
13938
+#define TK_CONCAT 110
13939
+#define TK_COLLATE 111
13940
+#define TK_BITNOT 112
13941
+#define TK_ON 113
13942
+#define TK_INDEXED 114
13943
+#define TK_STRING 115
13944
+#define TK_JOIN_KW 116
13945
+#define TK_CONSTRAINT 117
13946
+#define TK_DEFAULT 118
13947
+#define TK_NULL 119
13948
+#define TK_PRIMARY 120
13949
+#define TK_UNIQUE 121
13950
+#define TK_CHECK 122
13951
+#define TK_REFERENCES 123
13952
+#define TK_AUTOINCR 124
13953
+#define TK_INSERT 125
13954
+#define TK_DELETE 126
13955
+#define TK_UPDATE 127
13956
+#define TK_SET 128
13957
+#define TK_DEFERRABLE 129
13958
+#define TK_FOREIGN 130
13959
+#define TK_DROP 131
13960
+#define TK_UNION 132
13961
+#define TK_ALL 133
13962
+#define TK_EXCEPT 134
13963
+#define TK_INTERSECT 135
13964
+#define TK_SELECT 136
13965
+#define TK_VALUES 137
13966
+#define TK_DISTINCT 138
13967
+#define TK_DOT 139
13968
+#define TK_FROM 140
13969
+#define TK_JOIN 141
13970
+#define TK_USING 142
13971
+#define TK_ORDER 143
13972
+#define TK_GROUP 144
13973
+#define TK_HAVING 145
13974
+#define TK_LIMIT 146
13975
+#define TK_WHERE 147
13976
+#define TK_INTO 148
13977
+#define TK_NOTHING 149
13978
+#define TK_FLOAT 150
13979
+#define TK_BLOB 151
13980
+#define TK_INTEGER 152
13981
+#define TK_VARIABLE 153
13982
+#define TK_CASE 154
13983
+#define TK_WHEN 155
13984
+#define TK_THEN 156
13985
+#define TK_ELSE 157
13986
+#define TK_INDEX 158
13987
+#define TK_ALTER 159
13988
+#define TK_ADD 160
13989
+#define TK_WINDOW 161
13990
+#define TK_OVER 162
13991
+#define TK_FILTER 163
13992
+#define TK_COLUMN 164
13993
+#define TK_AGG_FUNCTION 165
13994
+#define TK_AGG_COLUMN 166
13995
+#define TK_TRUEFALSE 167
13996
+#define TK_ISNOT 168
13997
+#define TK_FUNCTION 169
13998
+#define TK_UMINUS 170
13999
+#define TK_UPLUS 171
14000
+#define TK_TRUTH 172
14001
+#define TK_REGISTER 173
14002
+#define TK_VECTOR 174
14003
+#define TK_SELECT_COLUMN 175
14004
+#define TK_IF_NULL_ROW 176
14005
+#define TK_ASTERISK 177
14006
+#define TK_SPAN 178
14007
+#define TK_SPACE 179
14008
+#define TK_ILLEGAL 180
1376014009
1376114010
/************** End of parse.h ***********************************************/
1376214011
/************** Continuing where we left off in sqliteInt.h ******************/
1376314012
#include <stdio.h>
1376414013
#include <stdlib.h>
@@ -14352,10 +14601,11 @@
1435214601
1435314602
/*
1435414603
** A bit in a Bitmask
1435514604
*/
1435614605
#define MASKBIT(n) (((Bitmask)1)<<(n))
14606
+#define MASKBIT64(n) (((u64)1)<<(n))
1435714607
#define MASKBIT32(n) (((unsigned int)1)<<(n))
1435814608
#define ALLBITS ((Bitmask)-1)
1435914609
1436014610
/* A VList object records a mapping between parameters/variables/wildcards
1436114611
** in the SQL statement (such as $abc, @pqr, or :xyz) and the integer
@@ -14678,19 +14928,21 @@
1467814928
SQLITE_PRIVATE int sqlite3BtreeLast(BtCursor*, int *pRes);
1467914929
SQLITE_PRIVATE int sqlite3BtreeNext(BtCursor*, int flags);
1468014930
SQLITE_PRIVATE int sqlite3BtreeEof(BtCursor*);
1468114931
SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor*, int flags);
1468214932
SQLITE_PRIVATE i64 sqlite3BtreeIntegerKey(BtCursor*);
14933
+SQLITE_PRIVATE void sqlite3BtreeCursorPin(BtCursor*);
14934
+SQLITE_PRIVATE void sqlite3BtreeCursorUnpin(BtCursor*);
1468314935
#ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
1468414936
SQLITE_PRIVATE i64 sqlite3BtreeOffset(BtCursor*);
1468514937
#endif
1468614938
SQLITE_PRIVATE int sqlite3BtreePayload(BtCursor*, u32 offset, u32 amt, void*);
1468714939
SQLITE_PRIVATE const void *sqlite3BtreePayloadFetch(BtCursor*, u32 *pAmt);
1468814940
SQLITE_PRIVATE u32 sqlite3BtreePayloadSize(BtCursor*);
1468914941
SQLITE_PRIVATE sqlite3_int64 sqlite3BtreeMaxRecordSize(BtCursor*);
1469014942
14691
-SQLITE_PRIVATE char *sqlite3BtreeIntegrityCheck(Btree*, int *aRoot, int nRoot, int, int*);
14943
+SQLITE_PRIVATE char *sqlite3BtreeIntegrityCheck(sqlite3*,Btree*,int*aRoot,int nRoot,int,int*);
1469214944
SQLITE_PRIVATE struct Pager *sqlite3BtreePager(Btree*);
1469314945
SQLITE_PRIVATE i64 sqlite3BtreeRowCountEst(BtCursor*);
1469414946
1469514947
#ifndef SQLITE_OMIT_INCRBLOB
1469614948
SQLITE_PRIVATE int sqlite3BtreePayloadChecked(BtCursor*, u32 offset, u32 amt, void*);
@@ -14707,11 +14959,11 @@
1470714959
SQLITE_PRIVATE int sqlite3BtreeCursorIsValid(BtCursor*);
1470814960
#endif
1470914961
SQLITE_PRIVATE int sqlite3BtreeCursorIsValidNN(BtCursor*);
1471014962
1471114963
#ifndef SQLITE_OMIT_BTREECOUNT
14712
-SQLITE_PRIVATE int sqlite3BtreeCount(BtCursor *, i64 *);
14964
+SQLITE_PRIVATE int sqlite3BtreeCount(sqlite3*, BtCursor*, i64*);
1471314965
#endif
1471414966
1471514967
#ifdef SQLITE_TEST
1471614968
SQLITE_PRIVATE int sqlite3BtreeCursorInfo(BtCursor*, int*, int);
1471714969
SQLITE_PRIVATE void sqlite3BtreeCursorList(Btree*);
@@ -14964,120 +15216,120 @@
1496415216
#define OP_IfNullRow 21 /* jump, synopsis: if P1.nullRow then r[P3]=NULL, goto P2 */
1496515217
#define OP_SeekLT 22 /* jump, synopsis: key=r[P3@P4] */
1496615218
#define OP_SeekLE 23 /* jump, synopsis: key=r[P3@P4] */
1496715219
#define OP_SeekGE 24 /* jump, synopsis: key=r[P3@P4] */
1496815220
#define OP_SeekGT 25 /* jump, synopsis: key=r[P3@P4] */
14969
-#define OP_IfNoHope 26 /* jump, synopsis: key=r[P3@P4] */
14970
-#define OP_NoConflict 27 /* jump, synopsis: key=r[P3@P4] */
14971
-#define OP_NotFound 28 /* jump, synopsis: key=r[P3@P4] */
14972
-#define OP_Found 29 /* jump, synopsis: key=r[P3@P4] */
14973
-#define OP_SeekRowid 30 /* jump, synopsis: intkey=r[P3] */
14974
-#define OP_NotExists 31 /* jump, synopsis: intkey=r[P3] */
14975
-#define OP_Last 32 /* jump */
14976
-#define OP_IfSmaller 33 /* jump */
14977
-#define OP_SorterSort 34 /* jump */
14978
-#define OP_Sort 35 /* jump */
14979
-#define OP_Rewind 36 /* jump */
14980
-#define OP_IdxLE 37 /* jump, synopsis: key=r[P3@P4] */
14981
-#define OP_IdxGT 38 /* jump, synopsis: key=r[P3@P4] */
14982
-#define OP_IdxLT 39 /* jump, synopsis: key=r[P3@P4] */
14983
-#define OP_IdxGE 40 /* jump, synopsis: key=r[P3@P4] */
14984
-#define OP_RowSetRead 41 /* jump, synopsis: r[P3]=rowset(P1) */
14985
-#define OP_RowSetTest 42 /* jump, synopsis: if r[P3] in rowset(P1) goto P2 */
15221
+#define OP_IfNotOpen 26 /* jump, synopsis: if( !csr[P1] ) goto P2 */
15222
+#define OP_IfNoHope 27 /* jump, synopsis: key=r[P3@P4] */
15223
+#define OP_NoConflict 28 /* jump, synopsis: key=r[P3@P4] */
15224
+#define OP_NotFound 29 /* jump, synopsis: key=r[P3@P4] */
15225
+#define OP_Found 30 /* jump, synopsis: key=r[P3@P4] */
15226
+#define OP_SeekRowid 31 /* jump, synopsis: intkey=r[P3] */
15227
+#define OP_NotExists 32 /* jump, synopsis: intkey=r[P3] */
15228
+#define OP_Last 33 /* jump */
15229
+#define OP_IfSmaller 34 /* jump */
15230
+#define OP_SorterSort 35 /* jump */
15231
+#define OP_Sort 36 /* jump */
15232
+#define OP_Rewind 37 /* jump */
15233
+#define OP_IdxLE 38 /* jump, synopsis: key=r[P3@P4] */
15234
+#define OP_IdxGT 39 /* jump, synopsis: key=r[P3@P4] */
15235
+#define OP_IdxLT 40 /* jump, synopsis: key=r[P3@P4] */
15236
+#define OP_IdxGE 41 /* jump, synopsis: key=r[P3@P4] */
15237
+#define OP_RowSetRead 42 /* jump, synopsis: r[P3]=rowset(P1) */
1498615238
#define OP_Or 43 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
1498715239
#define OP_And 44 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */
14988
-#define OP_Program 45 /* jump */
14989
-#define OP_FkIfZero 46 /* jump, synopsis: if fkctr[P1]==0 goto P2 */
14990
-#define OP_IfPos 47 /* jump, synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */
14991
-#define OP_IfNotZero 48 /* jump, synopsis: if r[P1]!=0 then r[P1]--, goto P2 */
14992
-#define OP_DecrJumpZero 49 /* jump, synopsis: if (--r[P1])==0 goto P2 */
15240
+#define OP_RowSetTest 45 /* jump, synopsis: if r[P3] in rowset(P1) goto P2 */
15241
+#define OP_Program 46 /* jump */
15242
+#define OP_FkIfZero 47 /* jump, synopsis: if fkctr[P1]==0 goto P2 */
15243
+#define OP_IfPos 48 /* jump, synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */
15244
+#define OP_IfNotZero 49 /* jump, synopsis: if r[P1]!=0 then r[P1]--, goto P2 */
1499315245
#define OP_IsNull 50 /* jump, same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
1499415246
#define OP_NotNull 51 /* jump, same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
1499515247
#define OP_Ne 52 /* jump, same as TK_NE, synopsis: IF r[P3]!=r[P1] */
1499615248
#define OP_Eq 53 /* jump, same as TK_EQ, synopsis: IF r[P3]==r[P1] */
1499715249
#define OP_Gt 54 /* jump, same as TK_GT, synopsis: IF r[P3]>r[P1] */
1499815250
#define OP_Le 55 /* jump, same as TK_LE, synopsis: IF r[P3]<=r[P1] */
1499915251
#define OP_Lt 56 /* jump, same as TK_LT, synopsis: IF r[P3]<r[P1] */
1500015252
#define OP_Ge 57 /* jump, same as TK_GE, synopsis: IF r[P3]>=r[P1] */
1500115253
#define OP_ElseNotEq 58 /* jump, same as TK_ESCAPE */
15002
-#define OP_IncrVacuum 59 /* jump */
15003
-#define OP_VNext 60 /* jump */
15004
-#define OP_Init 61 /* jump, synopsis: Start at P2 */
15005
-#define OP_PureFunc0 62
15006
-#define OP_Function0 63 /* synopsis: r[P3]=func(r[P2@P5]) */
15007
-#define OP_PureFunc 64
15008
-#define OP_Function 65 /* synopsis: r[P3]=func(r[P2@P5]) */
15009
-#define OP_Return 66
15010
-#define OP_EndCoroutine 67
15011
-#define OP_HaltIfNull 68 /* synopsis: if r[P3]=null halt */
15012
-#define OP_Halt 69
15013
-#define OP_Integer 70 /* synopsis: r[P2]=P1 */
15014
-#define OP_Int64 71 /* synopsis: r[P2]=P4 */
15015
-#define OP_String 72 /* synopsis: r[P2]='P4' (len=P1) */
15016
-#define OP_Null 73 /* synopsis: r[P2..P3]=NULL */
15017
-#define OP_SoftNull 74 /* synopsis: r[P1]=NULL */
15018
-#define OP_Blob 75 /* synopsis: r[P2]=P4 (len=P1) */
15019
-#define OP_Variable 76 /* synopsis: r[P2]=parameter(P1,P4) */
15020
-#define OP_Move 77 /* synopsis: r[P2@P3]=r[P1@P3] */
15021
-#define OP_Copy 78 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */
15022
-#define OP_SCopy 79 /* synopsis: r[P2]=r[P1] */
15023
-#define OP_IntCopy 80 /* synopsis: r[P2]=r[P1] */
15024
-#define OP_ResultRow 81 /* synopsis: output=r[P1@P2] */
15025
-#define OP_CollSeq 82
15026
-#define OP_AddImm 83 /* synopsis: r[P1]=r[P1]+P2 */
15027
-#define OP_RealAffinity 84
15028
-#define OP_Cast 85 /* synopsis: affinity(r[P1]) */
15029
-#define OP_Permutation 86
15030
-#define OP_Compare 87 /* synopsis: r[P1@P3] <-> r[P2@P3] */
15031
-#define OP_IsTrue 88 /* synopsis: r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4 */
15032
-#define OP_Offset 89 /* synopsis: r[P3] = sqlite_offset(P1) */
15033
-#define OP_Column 90 /* synopsis: r[P3]=PX */
15034
-#define OP_Affinity 91 /* synopsis: affinity(r[P1@P2]) */
15035
-#define OP_MakeRecord 92 /* synopsis: r[P3]=mkrec(r[P1@P2]) */
15036
-#define OP_Count 93 /* synopsis: r[P2]=count() */
15037
-#define OP_ReadCookie 94
15038
-#define OP_SetCookie 95
15039
-#define OP_ReopenIdx 96 /* synopsis: root=P2 iDb=P3 */
15040
-#define OP_OpenRead 97 /* synopsis: root=P2 iDb=P3 */
15041
-#define OP_OpenWrite 98 /* synopsis: root=P2 iDb=P3 */
15042
-#define OP_BitAnd 99 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
15043
-#define OP_BitOr 100 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
15044
-#define OP_ShiftLeft 101 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
15045
-#define OP_ShiftRight 102 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
15046
-#define OP_Add 103 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
15047
-#define OP_Subtract 104 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
15048
-#define OP_Multiply 105 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
15049
-#define OP_Divide 106 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
15050
-#define OP_Remainder 107 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
15051
-#define OP_Concat 108 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
15052
-#define OP_OpenDup 109
15053
-#define OP_BitNot 110 /* same as TK_BITNOT, synopsis: r[P2]= ~r[P1] */
15054
-#define OP_OpenAutoindex 111 /* synopsis: nColumn=P2 */
15055
-#define OP_OpenEphemeral 112 /* synopsis: nColumn=P2 */
15056
-#define OP_String8 113 /* same as TK_STRING, synopsis: r[P2]='P4' */
15057
-#define OP_SorterOpen 114
15058
-#define OP_SequenceTest 115 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */
15059
-#define OP_OpenPseudo 116 /* synopsis: P3 columns in r[P2] */
15060
-#define OP_Close 117
15061
-#define OP_ColumnsUsed 118
15062
-#define OP_SeekHit 119 /* synopsis: seekHit=P2 */
15063
-#define OP_Sequence 120 /* synopsis: r[P2]=cursor[P1].ctr++ */
15064
-#define OP_NewRowid 121 /* synopsis: r[P2]=rowid */
15065
-#define OP_Insert 122 /* synopsis: intkey=r[P3] data=r[P2] */
15066
-#define OP_Delete 123
15067
-#define OP_ResetCount 124
15068
-#define OP_SorterCompare 125 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
15069
-#define OP_SorterData 126 /* synopsis: r[P2]=data */
15070
-#define OP_RowData 127 /* synopsis: r[P2]=data */
15071
-#define OP_Rowid 128 /* synopsis: r[P2]=rowid */
15072
-#define OP_NullRow 129
15073
-#define OP_SeekEnd 130
15074
-#define OP_SorterInsert 131 /* synopsis: key=r[P2] */
15075
-#define OP_IdxInsert 132 /* synopsis: key=r[P2] */
15076
-#define OP_IdxDelete 133 /* synopsis: key=r[P2@P3] */
15077
-#define OP_DeferredSeek 134 /* synopsis: Move P3 to P1.rowid if needed */
15078
-#define OP_IdxRowid 135 /* synopsis: r[P2]=rowid */
15254
+#define OP_DecrJumpZero 59 /* jump, synopsis: if (--r[P1])==0 goto P2 */
15255
+#define OP_IncrVacuum 60 /* jump */
15256
+#define OP_VNext 61 /* jump */
15257
+#define OP_Init 62 /* jump, synopsis: Start at P2 */
15258
+#define OP_PureFunc 63 /* synopsis: r[P3]=func(r[P2@P5]) */
15259
+#define OP_Function 64 /* synopsis: r[P3]=func(r[P2@P5]) */
15260
+#define OP_Return 65
15261
+#define OP_EndCoroutine 66
15262
+#define OP_HaltIfNull 67 /* synopsis: if r[P3]=null halt */
15263
+#define OP_Halt 68
15264
+#define OP_Integer 69 /* synopsis: r[P2]=P1 */
15265
+#define OP_Int64 70 /* synopsis: r[P2]=P4 */
15266
+#define OP_String 71 /* synopsis: r[P2]='P4' (len=P1) */
15267
+#define OP_Null 72 /* synopsis: r[P2..P3]=NULL */
15268
+#define OP_SoftNull 73 /* synopsis: r[P1]=NULL */
15269
+#define OP_Blob 74 /* synopsis: r[P2]=P4 (len=P1) */
15270
+#define OP_Variable 75 /* synopsis: r[P2]=parameter(P1,P4) */
15271
+#define OP_Move 76 /* synopsis: r[P2@P3]=r[P1@P3] */
15272
+#define OP_Copy 77 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */
15273
+#define OP_SCopy 78 /* synopsis: r[P2]=r[P1] */
15274
+#define OP_IntCopy 79 /* synopsis: r[P2]=r[P1] */
15275
+#define OP_ResultRow 80 /* synopsis: output=r[P1@P2] */
15276
+#define OP_CollSeq 81
15277
+#define OP_AddImm 82 /* synopsis: r[P1]=r[P1]+P2 */
15278
+#define OP_RealAffinity 83
15279
+#define OP_Cast 84 /* synopsis: affinity(r[P1]) */
15280
+#define OP_Permutation 85
15281
+#define OP_Compare 86 /* synopsis: r[P1@P3] <-> r[P2@P3] */
15282
+#define OP_IsTrue 87 /* synopsis: r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4 */
15283
+#define OP_Offset 88 /* synopsis: r[P3] = sqlite_offset(P1) */
15284
+#define OP_Column 89 /* synopsis: r[P3]=PX */
15285
+#define OP_Affinity 90 /* synopsis: affinity(r[P1@P2]) */
15286
+#define OP_MakeRecord 91 /* synopsis: r[P3]=mkrec(r[P1@P2]) */
15287
+#define OP_Count 92 /* synopsis: r[P2]=count() */
15288
+#define OP_ReadCookie 93
15289
+#define OP_SetCookie 94
15290
+#define OP_ReopenIdx 95 /* synopsis: root=P2 iDb=P3 */
15291
+#define OP_OpenRead 96 /* synopsis: root=P2 iDb=P3 */
15292
+#define OP_OpenWrite 97 /* synopsis: root=P2 iDb=P3 */
15293
+#define OP_OpenDup 98
15294
+#define OP_OpenAutoindex 99 /* synopsis: nColumn=P2 */
15295
+#define OP_OpenEphemeral 100 /* synopsis: nColumn=P2 */
15296
+#define OP_BitAnd 101 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
15297
+#define OP_BitOr 102 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
15298
+#define OP_ShiftLeft 103 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
15299
+#define OP_ShiftRight 104 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
15300
+#define OP_Add 105 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
15301
+#define OP_Subtract 106 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
15302
+#define OP_Multiply 107 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
15303
+#define OP_Divide 108 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
15304
+#define OP_Remainder 109 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
15305
+#define OP_Concat 110 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
15306
+#define OP_SorterOpen 111
15307
+#define OP_BitNot 112 /* same as TK_BITNOT, synopsis: r[P2]= ~r[P1] */
15308
+#define OP_SequenceTest 113 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */
15309
+#define OP_OpenPseudo 114 /* synopsis: P3 columns in r[P2] */
15310
+#define OP_String8 115 /* same as TK_STRING, synopsis: r[P2]='P4' */
15311
+#define OP_Close 116
15312
+#define OP_ColumnsUsed 117
15313
+#define OP_SeekHit 118 /* synopsis: seekHit=P2 */
15314
+#define OP_Sequence 119 /* synopsis: r[P2]=cursor[P1].ctr++ */
15315
+#define OP_NewRowid 120 /* synopsis: r[P2]=rowid */
15316
+#define OP_Insert 121 /* synopsis: intkey=r[P3] data=r[P2] */
15317
+#define OP_Delete 122
15318
+#define OP_ResetCount 123
15319
+#define OP_SorterCompare 124 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
15320
+#define OP_SorterData 125 /* synopsis: r[P2]=data */
15321
+#define OP_RowData 126 /* synopsis: r[P2]=data */
15322
+#define OP_Rowid 127 /* synopsis: r[P2]=rowid */
15323
+#define OP_NullRow 128
15324
+#define OP_SeekEnd 129
15325
+#define OP_SorterInsert 130 /* synopsis: key=r[P2] */
15326
+#define OP_IdxInsert 131 /* synopsis: key=r[P2] */
15327
+#define OP_IdxDelete 132 /* synopsis: key=r[P2@P3] */
15328
+#define OP_DeferredSeek 133 /* synopsis: Move P3 to P1.rowid if needed */
15329
+#define OP_IdxRowid 134 /* synopsis: r[P2]=rowid */
15330
+#define OP_FinishSeek 135
1507915331
#define OP_Destroy 136
1508015332
#define OP_Clear 137
1508115333
#define OP_ResetSorter 138
1508215334
#define OP_CreateBtree 139 /* synopsis: r[P2]=root iDb=P1 flags=P3 */
1508315335
#define OP_SqlExec 140
@@ -15086,35 +15338,38 @@
1508615338
#define OP_DropTable 143
1508715339
#define OP_DropIndex 144
1508815340
#define OP_DropTrigger 145
1508915341
#define OP_IntegrityCk 146
1509015342
#define OP_RowSetAdd 147 /* synopsis: rowset(P1)=r[P2] */
15091
-#define OP_Real 148 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
15092
-#define OP_Param 149
15093
-#define OP_FkCounter 150 /* synopsis: fkctr[P1]+=P2 */
15343
+#define OP_Param 148
15344
+#define OP_FkCounter 149 /* synopsis: fkctr[P1]+=P2 */
15345
+#define OP_Real 150 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
1509415346
#define OP_MemMax 151 /* synopsis: r[P1]=max(r[P1],r[P2]) */
1509515347
#define OP_OffsetLimit 152 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */
1509615348
#define OP_AggInverse 153 /* synopsis: accum=r[P3] inverse(r[P2@P5]) */
1509715349
#define OP_AggStep 154 /* synopsis: accum=r[P3] step(r[P2@P5]) */
1509815350
#define OP_AggStep1 155 /* synopsis: accum=r[P3] step(r[P2@P5]) */
1509915351
#define OP_AggValue 156 /* synopsis: r[P3]=value N=P2 */
1510015352
#define OP_AggFinal 157 /* synopsis: accum=r[P1] N=P2 */
1510115353
#define OP_Expire 158
15102
-#define OP_TableLock 159 /* synopsis: iDb=P1 root=P2 write=P3 */
15103
-#define OP_VBegin 160
15104
-#define OP_VCreate 161
15105
-#define OP_VDestroy 162
15106
-#define OP_VOpen 163
15107
-#define OP_VColumn 164 /* synopsis: r[P3]=vcolumn(P2) */
15108
-#define OP_VRename 165
15109
-#define OP_Pagecount 166
15110
-#define OP_MaxPgcnt 167
15111
-#define OP_Trace 168
15112
-#define OP_CursorHint 169
15113
-#define OP_Noop 170
15114
-#define OP_Explain 171
15115
-#define OP_Abortable 172
15354
+#define OP_CursorLock 159
15355
+#define OP_CursorUnlock 160
15356
+#define OP_TableLock 161 /* synopsis: iDb=P1 root=P2 write=P3 */
15357
+#define OP_VBegin 162
15358
+#define OP_VCreate 163
15359
+#define OP_VDestroy 164
15360
+#define OP_VOpen 165
15361
+#define OP_VColumn 166 /* synopsis: r[P3]=vcolumn(P2) */
15362
+#define OP_VRename 167
15363
+#define OP_Pagecount 168
15364
+#define OP_MaxPgcnt 169
15365
+#define OP_Trace 170
15366
+#define OP_CursorHint 171
15367
+#define OP_ReleaseReg 172 /* synopsis: release r[P1@P2] mask P3 */
15368
+#define OP_Noop 173
15369
+#define OP_Explain 174
15370
+#define OP_Abortable 175
1511615371
1511715372
/* Properties such as "out2" or "jump" that are specified in
1511815373
** comments following the "case" for each opcode in the vdbe.c
1511915374
** are encoded into bitvectors as follows:
1512015375
*/
@@ -15126,37 +15381,38 @@
1512615381
#define OPFLG_OUT3 0x20 /* out3: P3 is an output */
1512715382
#define OPFLG_INITIALIZER {\
1512815383
/* 0 */ 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x10,\
1512915384
/* 8 */ 0x00, 0x01, 0x00, 0x01, 0x01, 0x01, 0x03, 0x03,\
1513015385
/* 16 */ 0x01, 0x01, 0x03, 0x12, 0x03, 0x01, 0x09, 0x09,\
15131
-/* 24 */ 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09,\
15132
-/* 32 */ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\
15133
-/* 40 */ 0x01, 0x23, 0x0b, 0x26, 0x26, 0x01, 0x01, 0x03,\
15386
+/* 24 */ 0x09, 0x09, 0x01, 0x09, 0x09, 0x09, 0x09, 0x09,\
15387
+/* 32 */ 0x09, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\
15388
+/* 40 */ 0x01, 0x01, 0x23, 0x26, 0x26, 0x0b, 0x01, 0x01,\
1513415389
/* 48 */ 0x03, 0x03, 0x03, 0x03, 0x0b, 0x0b, 0x0b, 0x0b,\
15135
-/* 56 */ 0x0b, 0x0b, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00,\
15136
-/* 64 */ 0x00, 0x00, 0x02, 0x02, 0x08, 0x00, 0x10, 0x10,\
15137
-/* 72 */ 0x10, 0x10, 0x00, 0x10, 0x10, 0x00, 0x00, 0x10,\
15138
-/* 80 */ 0x10, 0x00, 0x00, 0x02, 0x02, 0x02, 0x00, 0x00,\
15139
-/* 88 */ 0x12, 0x20, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00,\
15140
-/* 96 */ 0x00, 0x00, 0x00, 0x26, 0x26, 0x26, 0x26, 0x26,\
15141
-/* 104 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x00, 0x12, 0x00,\
15142
-/* 112 */ 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
15143
-/* 120 */ 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
15144
-/* 128 */ 0x10, 0x00, 0x00, 0x04, 0x04, 0x00, 0x00, 0x10,\
15390
+/* 56 */ 0x0b, 0x0b, 0x01, 0x03, 0x01, 0x01, 0x01, 0x00,\
15391
+/* 64 */ 0x00, 0x02, 0x02, 0x08, 0x00, 0x10, 0x10, 0x10,\
15392
+/* 72 */ 0x10, 0x00, 0x10, 0x10, 0x00, 0x00, 0x10, 0x10,\
15393
+/* 80 */ 0x00, 0x00, 0x02, 0x02, 0x02, 0x00, 0x00, 0x12,\
15394
+/* 88 */ 0x20, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\
15395
+/* 96 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x26, 0x26, 0x26,\
15396
+/* 104 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x00,\
15397
+/* 112 */ 0x12, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x10,\
15398
+/* 120 */ 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,\
15399
+/* 128 */ 0x00, 0x00, 0x04, 0x04, 0x00, 0x00, 0x10, 0x00,\
1514515400
/* 136 */ 0x10, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00,\
15146
-/* 144 */ 0x00, 0x00, 0x00, 0x06, 0x10, 0x10, 0x00, 0x04,\
15401
+/* 144 */ 0x00, 0x00, 0x00, 0x06, 0x10, 0x00, 0x10, 0x04,\
1514715402
/* 152 */ 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
15148
-/* 160 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10,\
15149
-/* 168 */ 0x00, 0x00, 0x00, 0x00, 0x00,}
15403
+/* 160 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
15404
+/* 168 */ 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
15405
+}
1515015406
1515115407
/* The sqlite3P2Values() routine is able to run faster if it knows
1515215408
** the value of the largest JUMP opcode. The smaller the maximum
1515315409
** JUMP opcode the better, so the mkopcodeh.tcl script that
1515415410
** generated this include file strives to group all JUMP opcodes
1515515411
** together near the beginning of the list.
1515615412
*/
15157
-#define SQLITE_MX_JUMP_OPCODE 61 /* Maximum JUMP opcode */
15413
+#define SQLITE_MX_JUMP_OPCODE 62 /* Maximum JUMP opcode */
1515815414
1515915415
/************** End of opcodes.h *********************************************/
1516015416
/************** Continuing where we left off in vdbe.h ***********************/
1516115417
1516215418
/*
@@ -15168,10 +15424,11 @@
1516815424
/*
1516915425
** Prototypes for the VDBE interface. See comments on the implementation
1517015426
** for a description of what each of these routines does.
1517115427
*/
1517215428
SQLITE_PRIVATE Vdbe *sqlite3VdbeCreate(Parse*);
15429
+SQLITE_PRIVATE Parse *sqlite3VdbeParser(Vdbe*);
1517315430
SQLITE_PRIVATE int sqlite3VdbeAddOp0(Vdbe*,int);
1517415431
SQLITE_PRIVATE int sqlite3VdbeAddOp1(Vdbe*,int,int);
1517515432
SQLITE_PRIVATE int sqlite3VdbeAddOp2(Vdbe*,int,int,int);
1517615433
SQLITE_PRIVATE int sqlite3VdbeGoto(Vdbe*,int);
1517715434
SQLITE_PRIVATE int sqlite3VdbeLoadString(Vdbe*,int,const char*);
@@ -15178,10 +15435,11 @@
1517815435
SQLITE_PRIVATE void sqlite3VdbeMultiLoad(Vdbe*,int,const char*,...);
1517915436
SQLITE_PRIVATE int sqlite3VdbeAddOp3(Vdbe*,int,int,int,int);
1518015437
SQLITE_PRIVATE int sqlite3VdbeAddOp4(Vdbe*,int,int,int,int,const char *zP4,int);
1518115438
SQLITE_PRIVATE int sqlite3VdbeAddOp4Dup8(Vdbe*,int,int,int,int,const u8*,int);
1518215439
SQLITE_PRIVATE int sqlite3VdbeAddOp4Int(Vdbe*,int,int,int,int,int);
15440
+SQLITE_PRIVATE int sqlite3VdbeAddFunctionCall(Parse*,int,int,int,int,const FuncDef*,int);
1518315441
SQLITE_PRIVATE void sqlite3VdbeEndCoroutine(Vdbe*,int);
1518415442
#if defined(SQLITE_DEBUG) && !defined(SQLITE_TEST_REALLOC_STRESS)
1518515443
SQLITE_PRIVATE void sqlite3VdbeVerifyNoMallocRequired(Vdbe *p, int N);
1518615444
SQLITE_PRIVATE void sqlite3VdbeVerifyNoResultRow(Vdbe *p);
1518715445
#else
@@ -15219,10 +15477,15 @@
1521915477
SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe*, int addr, int P3);
1522015478
SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe*, u16 P5);
1522115479
SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe*, int addr);
1522215480
SQLITE_PRIVATE int sqlite3VdbeChangeToNoop(Vdbe*, int addr);
1522315481
SQLITE_PRIVATE int sqlite3VdbeDeletePriorOpcode(Vdbe*, u8 op);
15482
+#ifdef SQLITE_DEBUG
15483
+SQLITE_PRIVATE void sqlite3VdbeReleaseRegisters(Parse*,int addr, int n, u32 mask, int);
15484
+#else
15485
+# define sqlite3VdbeReleaseRegisters(P,A,N,M,F)
15486
+#endif
1522415487
SQLITE_PRIVATE void sqlite3VdbeChangeP4(Vdbe*, int addr, const char *zP4, int N);
1522515488
SQLITE_PRIVATE void sqlite3VdbeAppendP4(Vdbe*, void *pP4, int p4type);
1522615489
SQLITE_PRIVATE void sqlite3VdbeSetP4KeyInfo(Parse*, Index*);
1522715490
SQLITE_PRIVATE void sqlite3VdbeUsesBtree(Vdbe*, int);
1522815491
SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe*, int);
@@ -15267,13 +15530,12 @@
1526715530
SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(KeyInfo*);
1526815531
1526915532
typedef int (*RecordCompare)(int,const void*,UnpackedRecord*);
1527015533
SQLITE_PRIVATE RecordCompare sqlite3VdbeFindCompare(UnpackedRecord*);
1527115534
15272
-#ifndef SQLITE_OMIT_TRIGGER
1527315535
SQLITE_PRIVATE void sqlite3VdbeLinkSubProgram(Vdbe *, SubProgram *);
15274
-#endif
15536
+SQLITE_PRIVATE int sqlite3VdbeHasSubProgram(Vdbe*);
1527515537
1527615538
SQLITE_PRIVATE int sqlite3NotPureFunc(sqlite3_context*);
1527715539
1527815540
/* Use SQLITE_ENABLE_COMMENTS to enable generation of extra comments on
1527915541
** each VDBE opcode.
@@ -15583,11 +15845,11 @@
1558315845
SQLITE_PRIVATE u32 sqlite3PagerDataVersion(Pager*);
1558415846
#ifdef SQLITE_DEBUG
1558515847
SQLITE_PRIVATE int sqlite3PagerRefcount(Pager*);
1558615848
#endif
1558715849
SQLITE_PRIVATE int sqlite3PagerMemUsed(Pager*);
15588
-SQLITE_PRIVATE const char *sqlite3PagerFilename(Pager*, int);
15850
+SQLITE_PRIVATE const char *sqlite3PagerFilename(const Pager*, int);
1558915851
SQLITE_PRIVATE sqlite3_vfs *sqlite3PagerVfs(Pager*);
1559015852
SQLITE_PRIVATE sqlite3_file *sqlite3PagerFile(Pager*);
1559115853
SQLITE_PRIVATE sqlite3_file *sqlite3PagerJrnlFile(Pager*);
1559215854
SQLITE_PRIVATE const char *sqlite3PagerJournalname(Pager*);
1559315855
SQLITE_PRIVATE void *sqlite3PagerTempSpace(Pager*);
@@ -16303,25 +16565,68 @@
1630316565
** with a particular database connection. Hence, schema information cannot
1630416566
** be stored in lookaside because in shared cache mode the schema information
1630516567
** is shared by multiple database connections. Therefore, while parsing
1630616568
** schema information, the Lookaside.bEnabled flag is cleared so that
1630716569
** lookaside allocations are not used to construct the schema objects.
16570
+**
16571
+** New lookaside allocations are only allowed if bDisable==0. When
16572
+** bDisable is greater than zero, sz is set to zero which effectively
16573
+** disables lookaside without adding a new test for the bDisable flag
16574
+** in a performance-critical path. sz should be set by to szTrue whenever
16575
+** bDisable changes back to zero.
16576
+**
16577
+** Lookaside buffers are initially held on the pInit list. As they are
16578
+** used and freed, they are added back to the pFree list. New allocations
16579
+** come off of pFree first, then pInit as a fallback. This dual-list
16580
+** allows use to compute a high-water mark - the maximum number of allocations
16581
+** outstanding at any point in the past - by subtracting the number of
16582
+** allocations on the pInit list from the total number of allocations.
16583
+**
16584
+** Enhancement on 2019-12-12: Two-size-lookaside
16585
+** The default lookaside configuration is 100 slots of 1200 bytes each.
16586
+** The larger slot sizes are important for performance, but they waste
16587
+** a lot of space, as most lookaside allocations are less than 128 bytes.
16588
+** The two-size-lookaside enhancement breaks up the lookaside allocation
16589
+** into two pools: One of 128-byte slots and the other of the default size
16590
+** (1200-byte) slots. Allocations are filled from the small-pool first,
16591
+** failing over to the full-size pool if that does not work. Thus more
16592
+** lookaside slots are available while also using less memory.
16593
+** This enhancement can be omitted by compiling with
16594
+** SQLITE_OMIT_TWOSIZE_LOOKASIDE.
1630816595
*/
1630916596
struct Lookaside {
1631016597
u32 bDisable; /* Only operate the lookaside when zero */
1631116598
u16 sz; /* Size of each buffer in bytes */
16599
+ u16 szTrue; /* True value of sz, even if disabled */
1631216600
u8 bMalloced; /* True if pStart obtained from sqlite3_malloc() */
1631316601
u32 nSlot; /* Number of lookaside slots allocated */
1631416602
u32 anStat[3]; /* 0: hits. 1: size misses. 2: full misses */
1631516603
LookasideSlot *pInit; /* List of buffers not previously used */
1631616604
LookasideSlot *pFree; /* List of available buffers */
16605
+#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
16606
+ LookasideSlot *pSmallInit; /* List of small buffers not prediously used */
16607
+ LookasideSlot *pSmallFree; /* List of available small buffers */
16608
+ void *pMiddle; /* First byte past end of full-size buffers and
16609
+ ** the first byte of LOOKASIDE_SMALL buffers */
16610
+#endif /* SQLITE_OMIT_TWOSIZE_LOOKASIDE */
1631716611
void *pStart; /* First byte of available memory space */
1631816612
void *pEnd; /* First byte past end of available space */
1631916613
};
1632016614
struct LookasideSlot {
1632116615
LookasideSlot *pNext; /* Next buffer in the list of free buffers */
1632216616
};
16617
+
16618
+#define DisableLookaside db->lookaside.bDisable++;db->lookaside.sz=0
16619
+#define EnableLookaside db->lookaside.bDisable--;\
16620
+ db->lookaside.sz=db->lookaside.bDisable?0:db->lookaside.szTrue
16621
+
16622
+/* Size of the smaller allocations in two-size lookside */
16623
+#ifdef SQLITE_OMIT_TWOSIZE_LOOKASIDE
16624
+# define LOOKASIDE_SMALL 0
16625
+#else
16626
+# define LOOKASIDE_SMALL 128
16627
+#endif
1632316628
1632416629
/*
1632516630
** A hash table for built-in function definitions. (Application-defined
1632616631
** functions use a regular table table from hash.h.)
1632716632
**
@@ -16527,10 +16832,17 @@
1652716832
** A macro to discover the encoding of a database.
1652816833
*/
1652916834
#define SCHEMA_ENC(db) ((db)->aDb[0].pSchema->enc)
1653016835
#define ENC(db) ((db)->enc)
1653116836
16837
+/*
16838
+** A u64 constant where the lower 32 bits are all zeros. Only the
16839
+** upper 32 bits are included in the argument. Necessary because some
16840
+** C-compilers still do not accept LL integer literals.
16841
+*/
16842
+#define HI(X) ((u64)(X)<<32)
16843
+
1653216844
/*
1653316845
** Possible values for the sqlite3.flags.
1653416846
**
1653516847
** Value constraints (enforced via assert()):
1653616848
** SQLITE_FullFSync == PAGER_FULLFSYNC
@@ -16542,13 +16854,12 @@
1654216854
#define SQLITE_FullColNames 0x00000004 /* Show full column names on SELECT */
1654316855
#define SQLITE_FullFSync 0x00000008 /* Use full fsync on the backend */
1654416856
#define SQLITE_CkptFullFSync 0x00000010 /* Use full fsync for checkpoint */
1654516857
#define SQLITE_CacheSpill 0x00000020 /* OK to spill pager cache */
1654616858
#define SQLITE_ShortColNames 0x00000040 /* Show short columns names */
16547
-#define SQLITE_CountRows 0x00000080 /* Count rows changed by INSERT, */
16548
- /* DELETE, or UPDATE and return */
16549
- /* the count using a callback. */
16859
+#define SQLITE_TrustedSchema 0x00000080 /* Allow unsafe functions and
16860
+ ** vtabs in the schema definition */
1655016861
#define SQLITE_NullCallback 0x00000100 /* Invoke the callback once if the */
1655116862
/* result set is empty */
1655216863
#define SQLITE_IgnoreChecks 0x00000200 /* Do not enforce check constraints */
1655316864
#define SQLITE_ReadUncommit 0x00000400 /* READ UNCOMMITTED in shared-cache */
1655416865
#define SQLITE_NoCkptOnClose 0x00000800 /* No checkpoint on close()/DETACH */
@@ -16570,13 +16881,15 @@
1657016881
#define SQLITE_NoSchemaError 0x08000000 /* Do not report schema parse errors*/
1657116882
#define SQLITE_Defensive 0x10000000 /* Input SQL is likely hostile */
1657216883
#define SQLITE_DqsDDL 0x20000000 /* dbl-quoted strings allowed in DDL*/
1657316884
#define SQLITE_DqsDML 0x40000000 /* dbl-quoted strings allowed in DML*/
1657416885
#define SQLITE_EnableView 0x80000000 /* Enable the use of views */
16886
+#define SQLITE_CountRows HI(0x00001) /* Count rows changed by INSERT, */
16887
+ /* DELETE, or UPDATE and return */
16888
+ /* the count using a callback. */
1657516889
1657616890
/* Flags used only if debugging */
16577
-#define HI(X) ((u64)(X)<<32)
1657816891
#ifdef SQLITE_DEBUG
1657916892
#define SQLITE_SqlTrace HI(0x0100000) /* Debug print SQL as it executes */
1658016893
#define SQLITE_VdbeListing HI(0x0200000) /* Debug listings of VDBE progs */
1658116894
#define SQLITE_VdbeTrace HI(0x0400000) /* True to trace VDBE execution */
1658216895
#define SQLITE_VdbeAddopTrace HI(0x0800000) /* Trace sqlite3VdbeAddOp() calls */
@@ -16590,10 +16903,11 @@
1659016903
#define DBFLAG_SchemaChange 0x0001 /* Uncommitted Hash table changes */
1659116904
#define DBFLAG_PreferBuiltin 0x0002 /* Preference to built-in funcs */
1659216905
#define DBFLAG_Vacuum 0x0004 /* Currently in a VACUUM */
1659316906
#define DBFLAG_VacuumInto 0x0008 /* Currently running VACUUM INTO */
1659416907
#define DBFLAG_SchemaKnownOk 0x0010 /* Schema is known to be valid */
16908
+#define DBFLAG_InternalFunc 0x0020 /* Allow use of internal functions */
1659516909
1659616910
/*
1659716911
** Bits of the sqlite3.dbOptFlags field that are used by the
1659816912
** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface to
1659916913
** selectively disable various optimizations.
@@ -16697,10 +17011,11 @@
1669717011
** SQLITE_FUNC_MINMAX == NC_MinMaxAgg == SF_MinMaxAgg
1669817012
** SQLITE_FUNC_LENGTH == OPFLAG_LENGTHARG
1669917013
** SQLITE_FUNC_TYPEOF == OPFLAG_TYPEOFARG
1670017014
** SQLITE_FUNC_CONSTANT == SQLITE_DETERMINISTIC from the API
1670117015
** SQLITE_FUNC_DIRECT == SQLITE_DIRECTONLY from the API
17016
+** SQLITE_FUNC_UNSAFE == SQLITE_INNOCUOUS
1670217017
** SQLITE_FUNC_ENCMASK depends on SQLITE_UTF* macros in the API
1670317018
*/
1670417019
#define SQLITE_FUNC_ENCMASK 0x0003 /* SQLITE_UTF8, SQLITE_UTF16BE or UTF16LE */
1670517020
#define SQLITE_FUNC_LIKE 0x0004 /* Candidate for the LIKE optimization */
1670617021
#define SQLITE_FUNC_CASE 0x0008 /* Case-sensitive LIKE-type function */
@@ -16713,16 +17028,26 @@
1671317028
#define SQLITE_FUNC_UNLIKELY 0x0400 /* Built-in unlikely() function */
1671417029
#define SQLITE_FUNC_CONSTANT 0x0800 /* Constant inputs give a constant output */
1671517030
#define SQLITE_FUNC_MINMAX 0x1000 /* True for min() and max() aggregates */
1671617031
#define SQLITE_FUNC_SLOCHNG 0x2000 /* "Slow Change". Value constant during a
1671717032
** single query - might change over time */
16718
-#define SQLITE_FUNC_AFFINITY 0x4000 /* Built-in affinity() function */
17033
+#define SQLITE_FUNC_TEST 0x4000 /* Built-in testing functions */
1671917034
#define SQLITE_FUNC_OFFSET 0x8000 /* Built-in sqlite_offset() function */
1672017035
#define SQLITE_FUNC_WINDOW 0x00010000 /* Built-in window-only function */
1672117036
#define SQLITE_FUNC_INTERNAL 0x00040000 /* For use by NestedParse() only */
1672217037
#define SQLITE_FUNC_DIRECT 0x00080000 /* Not for use in TRIGGERs or VIEWs */
1672317038
#define SQLITE_FUNC_SUBTYPE 0x00100000 /* Result likely to have sub-type */
17039
+#define SQLITE_FUNC_UNSAFE 0x00200000 /* Function has side effects */
17040
+#define SQLITE_FUNC_INLINE 0x00400000 /* Functions implemented in-line */
17041
+
17042
+/* Identifier numbers for each in-line function */
17043
+#define INLINEFUNC_coalesce 0
17044
+#define INLINEFUNC_implies_nonnull_row 1
17045
+#define INLINEFUNC_expr_implies_expr 2
17046
+#define INLINEFUNC_expr_compare 3
17047
+#define INLINEFUNC_affinity 4
17048
+#define INLINEFUNC_unlikely 99 /* Default case */
1672417049
1672517050
/*
1672617051
** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are
1672717052
** used to create the initializers for the FuncDef structures.
1672817053
**
@@ -16734,10 +17059,26 @@
1673417059
** argument bNC is true, then the SQLITE_FUNC_NEEDCOLL flag is set.
1673517060
**
1673617061
** VFUNCTION(zName, nArg, iArg, bNC, xFunc)
1673717062
** Like FUNCTION except it omits the SQLITE_FUNC_CONSTANT flag.
1673817063
**
17064
+** SFUNCTION(zName, nArg, iArg, bNC, xFunc)
17065
+** Like FUNCTION except it omits the SQLITE_FUNC_CONSTANT flag and
17066
+** adds the SQLITE_DIRECTONLY flag.
17067
+**
17068
+** INLINE_FUNC(zName, nArg, iFuncId, mFlags)
17069
+** zName is the name of a function that is implemented by in-line
17070
+** byte code rather than by the usual callbacks. The iFuncId
17071
+** parameter determines the function id. The mFlags parameter is
17072
+** optional SQLITE_FUNC_ flags for this function.
17073
+**
17074
+** TEST_FUNC(zName, nArg, iFuncId, mFlags)
17075
+** zName is the name of a test-only function implemented by in-line
17076
+** byte code rather than by the usual callbacks. The iFuncId
17077
+** parameter determines the function id. The mFlags parameter is
17078
+** optional SQLITE_FUNC_ flags for this function.
17079
+**
1673917080
** DFUNCTION(zName, nArg, iArg, bNC, xFunc)
1674017081
** Like FUNCTION except it omits the SQLITE_FUNC_CONSTANT flag and
1674117082
** adds the SQLITE_FUNC_SLOCHNG flag. Used for date & time functions
1674217083
** and functions like sqlite_version() that can change, but not during
1674317084
** a single query. The iArg is ignored. The user-data is always set
@@ -16773,10 +17114,20 @@
1677317114
{nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
1677417115
SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} }
1677517116
#define VFUNCTION(zName, nArg, iArg, bNC, xFunc) \
1677617117
{nArg, SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
1677717118
SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} }
17119
+#define SFUNCTION(zName, nArg, iArg, bNC, xFunc) \
17120
+ {nArg, SQLITE_UTF8|SQLITE_DIRECTONLY|SQLITE_FUNC_UNSAFE, \
17121
+ SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} }
17122
+#define INLINE_FUNC(zName, nArg, iArg, mFlags) \
17123
+ {nArg, SQLITE_UTF8|SQLITE_FUNC_INLINE|SQLITE_FUNC_CONSTANT|(mFlags), \
17124
+ SQLITE_INT_TO_PTR(iArg), 0, noopFunc, 0, 0, 0, #zName, {0} }
17125
+#define TEST_FUNC(zName, nArg, iArg, mFlags) \
17126
+ {nArg, SQLITE_UTF8|SQLITE_FUNC_INTERNAL|SQLITE_FUNC_TEST| \
17127
+ SQLITE_FUNC_INLINE|SQLITE_FUNC_CONSTANT|(mFlags), \
17128
+ SQLITE_INT_TO_PTR(iArg), 0, noopFunc, 0, 0, 0, #zName, {0} }
1677817129
#define DFUNCTION(zName, nArg, iArg, bNC, xFunc) \
1677917130
{nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8, \
1678017131
0, 0, xFunc, 0, 0, 0, #zName, {0} }
1678117132
#define PURE_DATE(zName, nArg, iArg, bNC, xFunc) \
1678217133
{nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|SQLITE_FUNC_CONSTANT, \
@@ -16788,16 +17139,10 @@
1678817139
{nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
1678917140
pArg, 0, xFunc, 0, 0, 0, #zName, }
1679017141
#define LIKEFUNC(zName, nArg, arg, flags) \
1679117142
{nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|flags, \
1679217143
(void *)arg, 0, likeFunc, 0, 0, 0, #zName, {0} }
16793
-#define AGGREGATE(zName, nArg, arg, nc, xStep, xFinal, xValue) \
16794
- {nArg, SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL), \
16795
- SQLITE_INT_TO_PTR(arg), 0, xStep,xFinal,xValue,0,#zName, {0}}
16796
-#define AGGREGATE2(zName, nArg, arg, nc, xStep, xFinal, extraFlags) \
16797
- {nArg, SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL)|extraFlags, \
16798
- SQLITE_INT_TO_PTR(arg), 0, xStep,xFinal,xFinal,0,#zName, {0}}
1679917144
#define WAGGREGATE(zName, nArg, arg, nc, xStep, xFinal, xValue, xInverse, f) \
1680017145
{nArg, SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL)|f, \
1680117146
SQLITE_INT_TO_PTR(arg), 0, xStep,xFinal,xValue,xInverse,#zName, {0}}
1680217147
#define INTERNAL_FUNCTION(zName, nArg, xFunc) \
1680317148
{nArg, SQLITE_FUNC_INTERNAL|SQLITE_UTF8|SQLITE_FUNC_CONSTANT, \
@@ -16839,30 +17184,49 @@
1683917184
void (*xDestroy)(void *); /* Module destructor function */
1684017185
Table *pEpoTab; /* Eponymous table for this module */
1684117186
};
1684217187
1684317188
/*
16844
-** information about each column of an SQL table is held in an instance
16845
-** of this structure.
17189
+** Information about each column of an SQL table is held in an instance
17190
+** of the Column structure, in the Table.aCol[] array.
17191
+**
17192
+** Definitions:
17193
+**
17194
+** "table column index" This is the index of the column in the
17195
+** Table.aCol[] array, and also the index of
17196
+** the column in the original CREATE TABLE stmt.
17197
+**
17198
+** "storage column index" This is the index of the column in the
17199
+** record BLOB generated by the OP_MakeRecord
17200
+** opcode. The storage column index is less than
17201
+** or equal to the table column index. It is
17202
+** equal if and only if there are no VIRTUAL
17203
+** columns to the left.
1684617204
*/
1684717205
struct Column {
1684817206
char *zName; /* Name of this column, \000, then the type */
16849
- Expr *pDflt; /* Default value of this column */
17207
+ Expr *pDflt; /* Default value or GENERATED ALWAYS AS value */
1685017208
char *zColl; /* Collating sequence. If NULL, use the default */
1685117209
u8 notNull; /* An OE_ code for handling a NOT NULL constraint */
1685217210
char affinity; /* One of the SQLITE_AFF_... values */
1685317211
u8 szEst; /* Estimated size of value in this column. sizeof(INT)==1 */
16854
- u8 colFlags; /* Boolean properties. See COLFLAG_ defines below */
17212
+ u16 colFlags; /* Boolean properties. See COLFLAG_ defines below */
1685517213
};
1685617214
1685717215
/* Allowed values for Column.colFlags:
1685817216
*/
16859
-#define COLFLAG_PRIMKEY 0x0001 /* Column is part of the primary key */
16860
-#define COLFLAG_HIDDEN 0x0002 /* A hidden column in a virtual table */
16861
-#define COLFLAG_HASTYPE 0x0004 /* Type name follows column name */
16862
-#define COLFLAG_UNIQUE 0x0008 /* Column def contains "UNIQUE" or "PK" */
17217
+#define COLFLAG_PRIMKEY 0x0001 /* Column is part of the primary key */
17218
+#define COLFLAG_HIDDEN 0x0002 /* A hidden column in a virtual table */
17219
+#define COLFLAG_HASTYPE 0x0004 /* Type name follows column name */
17220
+#define COLFLAG_UNIQUE 0x0008 /* Column def contains "UNIQUE" or "PK" */
1686317221
#define COLFLAG_SORTERREF 0x0010 /* Use sorter-refs with this column */
17222
+#define COLFLAG_VIRTUAL 0x0020 /* GENERATED ALWAYS AS ... VIRTUAL */
17223
+#define COLFLAG_STORED 0x0040 /* GENERATED ALWAYS AS ... STORED */
17224
+#define COLFLAG_NOTAVAIL 0x0080 /* STORED column not yet calculated */
17225
+#define COLFLAG_BUSY 0x0100 /* Blocks recursion on GENERATED columns */
17226
+#define COLFLAG_GENERATED 0x0060 /* Combo: _STORED, _VIRTUAL */
17227
+#define COLFLAG_NOINSERT 0x0062 /* Combo: _HIDDEN, _STORED, _VIRTUAL */
1686417228
1686517229
/*
1686617230
** A "Collating Sequence" is defined by an instance of the following
1686717231
** structure. Conceptually, a collating sequence consists of a name and
1686817232
** a comparison routine that defines the order of that sequence.
@@ -16976,13 +17340,20 @@
1697617340
sqlite3 *db; /* Database connection associated with this table */
1697717341
Module *pMod; /* Pointer to module implementation */
1697817342
sqlite3_vtab *pVtab; /* Pointer to vtab instance */
1697917343
int nRef; /* Number of pointers to this structure */
1698017344
u8 bConstraint; /* True if constraints are supported */
17345
+ u8 eVtabRisk; /* Riskiness of allowing hacker access */
1698117346
int iSavepoint; /* Depth of the SAVEPOINT stack */
1698217347
VTable *pNext; /* Next in linked list (see above) */
1698317348
};
17349
+
17350
+/* Allowed values for VTable.eVtabRisk
17351
+*/
17352
+#define SQLITE_VTABRISK_Low 0
17353
+#define SQLITE_VTABRISK_Normal 1
17354
+#define SQLITE_VTABRISK_High 2
1698417355
1698517356
/*
1698617357
** The schema for each SQL table and view is represented in memory
1698717358
** by an instance of the following structure.
1698817359
*/
@@ -16998,10 +17369,11 @@
1699817369
int tnum; /* Root BTree page for this table */
1699917370
u32 nTabRef; /* Number of pointers to this Table */
1700017371
u32 tabFlags; /* Mask of TF_* values */
1700117372
i16 iPKey; /* If not negative, use aCol[iPKey] as the rowid */
1700217373
i16 nCol; /* Number of columns in this table */
17374
+ i16 nNVCol; /* Number of columns that are not VIRTUAL */
1700317375
LogEst nRowLogEst; /* Estimated rows in table - from sqlite_stat1 table */
1700417376
LogEst szTabRow; /* Estimated size of each table row in bytes */
1700517377
#ifdef SQLITE_ENABLE_COSTMULT
1700617378
LogEst costMult; /* Cost multiplier for using this table */
1700717379
#endif
@@ -17024,24 +17396,32 @@
1702417396
**
1702517397
** TF_OOOHidden applies to tables or view that have hidden columns that are
1702617398
** followed by non-hidden columns. Example: "CREATE VIRTUAL TABLE x USING
1702717399
** vtab1(a HIDDEN, b);". Since "b" is a non-hidden column but "a" is hidden,
1702817400
** the TF_OOOHidden attribute would apply in this case. Such tables require
17029
-** special handling during INSERT processing.
17401
+** special handling during INSERT processing. The "OOO" means "Out Of Order".
17402
+**
17403
+** Constraints:
17404
+**
17405
+** TF_HasVirtual == COLFLAG_Virtual
17406
+** TF_HasStored == COLFLAG_Stored
1703017407
*/
1703117408
#define TF_Readonly 0x0001 /* Read-only system table */
1703217409
#define TF_Ephemeral 0x0002 /* An ephemeral table */
1703317410
#define TF_HasPrimaryKey 0x0004 /* Table has a primary key */
1703417411
#define TF_Autoincrement 0x0008 /* Integer primary key is autoincrement */
1703517412
#define TF_HasStat1 0x0010 /* nRowLogEst set from sqlite_stat1 */
17036
-#define TF_WithoutRowid 0x0020 /* No rowid. PRIMARY KEY is the key */
17037
-#define TF_NoVisibleRowid 0x0040 /* No user-visible "rowid" column */
17038
-#define TF_OOOHidden 0x0080 /* Out-of-Order hidden columns */
17413
+#define TF_HasVirtual 0x0020 /* Has one or more VIRTUAL columns */
17414
+#define TF_HasStored 0x0040 /* Has one or more STORED columns */
17415
+#define TF_HasGenerated 0x0060 /* Combo: HasVirtual + HasStored */
17416
+#define TF_WithoutRowid 0x0080 /* No rowid. PRIMARY KEY is the key */
1703917417
#define TF_StatsUsed 0x0100 /* Query planner decisions affected by
1704017418
** Index.aiRowLogEst[] values */
17041
-#define TF_HasNotNull 0x0200 /* Contains NOT NULL constraints */
17042
-#define TF_Shadow 0x0400 /* True for a shadow table */
17419
+#define TF_NoVisibleRowid 0x0200 /* No user-visible "rowid" column */
17420
+#define TF_OOOHidden 0x0400 /* Out-of-Order hidden columns */
17421
+#define TF_HasNotNull 0x0800 /* Contains NOT NULL constraints */
17422
+#define TF_Shadow 0x1000 /* True for a shadow table */
1704317423
1704417424
/*
1704517425
** Test to see whether or not a table is a virtual table. This is
1704617426
** done as a macro so that it will be optimized out when virtual
1704717427
** table support is omitted from the build.
@@ -17288,10 +17668,11 @@
1728817668
unsigned isCovering:1; /* True if this is a covering index */
1728917669
unsigned noSkipScan:1; /* Do not try to use skip-scan if true */
1729017670
unsigned hasStat1:1; /* aiRowLogEst values come from sqlite_stat1 */
1729117671
unsigned bNoQuery:1; /* Do not use this index to optimize queries */
1729217672
unsigned bAscKeyBug:1; /* True if the bba7b69f9849b5bf bug applies */
17673
+ unsigned bHasVCol:1; /* Index references one or more VIRTUAL columns */
1729317674
#ifdef SQLITE_ENABLE_STAT4
1729417675
int nSample; /* Number of elements in aSample[] */
1729517676
int nSampleCol; /* Size of IndexSample.anEq[] and so on */
1729617677
tRowcnt *aAvgEq; /* Average nEq values for keys not in aSample */
1729717678
IndexSample *aSample; /* Samples of the left-most key */
@@ -17479,10 +17860,14 @@
1747917860
** allocated, regardless of whether or not EP_Reduced is set.
1748017861
*/
1748117862
struct Expr {
1748217863
u8 op; /* Operation performed by this node */
1748317864
char affExpr; /* affinity, or RAISE type */
17865
+ u8 op2; /* TK_REGISTER/TK_TRUTH: original value of Expr.op
17866
+ ** TK_COLUMN: the value of p5 for OP_Column
17867
+ ** TK_AGG_FUNCTION: nesting depth
17868
+ ** TK_FUNCTION: NC_SelfRef flag if needs OP_PureFunc */
1748417869
u32 flags; /* Various flags. EP_* See below */
1748517870
union {
1748617871
char *zToken; /* Token value. Zero terminated and dequoted */
1748717872
int iValue; /* Non-negative integer value if EP_IntValue */
1748817873
} u;
@@ -17517,13 +17902,10 @@
1751717902
ynVar iColumn; /* TK_COLUMN: column index. -1 for rowid.
1751817903
** TK_VARIABLE: variable number (always >= 1).
1751917904
** TK_SELECT_COLUMN: column of the result vector */
1752017905
i16 iAgg; /* Which entry in pAggInfo->aCol[] or ->aFunc[] */
1752117906
i16 iRightJoinTable; /* If EP_FromJoin, the right table of the join */
17522
- u8 op2; /* TK_REGISTER/TK_TRUTH: original value of Expr.op
17523
- ** TK_COLUMN: the value of p5 for OP_Column
17524
- ** TK_AGG_FUNCTION: nesting depth */
1752517907
AggInfo *pAggInfo; /* Used by TK_AGG_COLUMN and TK_AGG_FUNCTION */
1752617908
union {
1752717909
Table *pTab; /* TK_COLUMN: Table containing column. Can be NULL
1752817910
** for a column of an index on an expression */
1752917911
Window *pWin; /* EP_WinFunc: Window/Filter defn for a function */
@@ -17548,11 +17930,11 @@
1754817930
#define EP_Agg 0x000010 /* Contains one or more aggregate functions */
1754917931
#define EP_VarSelect 0x000020 /* pSelect is correlated, not constant */
1755017932
#define EP_DblQuoted 0x000040 /* token.z was originally in "..." */
1755117933
#define EP_InfixFunc 0x000080 /* True for an infix function: LIKE, GLOB, etc */
1755217934
#define EP_Collate 0x000100 /* Tree contains a TK_COLLATE operator */
17553
- /* 0x000200 Available for reuse */
17935
+#define EP_Commuted 0x000200 /* Comparison operator has been commuted */
1755417936
#define EP_IntValue 0x000400 /* Integer value contained in u.iValue */
1755517937
#define EP_xIsSelect 0x000800 /* x.pSelect is valid (otherwise x.pList is) */
1755617938
#define EP_Skip 0x001000 /* Operator does not contribute to affinity */
1755717939
#define EP_Reduced 0x002000 /* Expr struct EXPR_REDUCEDSIZE bytes only */
1755817940
#define EP_TokenOnly 0x004000 /* Expr struct EXPR_TOKENONLYSIZE bytes only */
@@ -17569,11 +17951,11 @@
1756917951
#define EP_Subrtn 0x2000000 /* Uses Expr.y.sub. TK_IN, _SELECT, or _EXISTS */
1757017952
#define EP_Quoted 0x4000000 /* TK_ID was originally quoted */
1757117953
#define EP_Static 0x8000000 /* Held in memory not obtained from malloc() */
1757217954
#define EP_IsTrue 0x10000000 /* Always has boolean value of TRUE */
1757317955
#define EP_IsFalse 0x20000000 /* Always has boolean value of FALSE */
17574
-#define EP_Indirect 0x40000000 /* Contained within a TRIGGER or a VIEW */
17956
+#define EP_FromDDL 0x40000000 /* Originates from sqlite_master */
1757517957
1757617958
/*
1757717959
** The EP_Propagate mask is a set of properties that automatically propagate
1757817960
** upwards into parent nodes.
1757917961
*/
@@ -17617,39 +17999,48 @@
1761717999
1761818000
/*
1761918001
** True if the expression passed as an argument was a function with
1762018002
** an OVER() clause (a window function).
1762118003
*/
17622
-#define IsWindowFunc(p) ( \
18004
+#ifdef SQLITE_OMIT_WINDOWFUNC
18005
+# define IsWindowFunc(p) 0
18006
+#else
18007
+# define IsWindowFunc(p) ( \
1762318008
ExprHasProperty((p), EP_WinFunc) && p->y.pWin->eFrmType!=TK_FILTER \
17624
-)
18009
+ )
18010
+#endif
1762518011
1762618012
/*
1762718013
** A list of expressions. Each expression may optionally have a
1762818014
** name. An expr/name combination can be used in several ways, such
1762918015
** as the list of "expr AS ID" fields following a "SELECT" or in the
1763018016
** list of "ID = expr" items in an UPDATE. A list of expressions can
1763118017
** also be used as the argument to a function, in which case the a.zName
1763218018
** field is not used.
1763318019
**
17634
-** By default the Expr.zSpan field holds a human-readable description of
17635
-** the expression that is used in the generation of error messages and
17636
-** column labels. In this case, Expr.zSpan is typically the text of a
17637
-** column expression as it exists in a SELECT statement. However, if
17638
-** the bSpanIsTab flag is set, then zSpan is overloaded to mean the name
17639
-** of the result column in the form: DATABASE.TABLE.COLUMN. This later
17640
-** form is used for name resolution with nested FROM clauses.
18020
+** In order to try to keep memory usage down, the Expr.a.zEName field
18021
+** is used for multiple purposes:
18022
+**
18023
+** eEName Usage
18024
+** ---------- -------------------------
18025
+** ENAME_NAME (1) the AS of result set column
18026
+** (2) COLUMN= of an UPDATE
18027
+**
18028
+** ENAME_TAB DB.TABLE.NAME used to resolve names
18029
+** of subqueries
18030
+**
18031
+** ENAME_SPAN Text of the original result set
18032
+** expression.
1764118033
*/
1764218034
struct ExprList {
1764318035
int nExpr; /* Number of expressions on the list */
1764418036
struct ExprList_item { /* For each expression in the list */
1764518037
Expr *pExpr; /* The parse tree for this expression */
17646
- char *zName; /* Token associated with this expression */
17647
- char *zSpan; /* Original text of the expression */
18038
+ char *zEName; /* Token associated with this expression */
1764818039
u8 sortFlags; /* Mask of KEYINFO_ORDER_* flags */
18040
+ unsigned eEName :2; /* Meaning of zEName */
1764918041
unsigned done :1; /* A flag to indicate when processing is finished */
17650
- unsigned bSpanIsTab :1; /* zSpan holds DB.TABLE.COLUMN */
1765118042
unsigned reusable :1; /* Constant expression is reusable */
1765218043
unsigned bSorterRef :1; /* Defer evaluation until after sorting */
1765318044
unsigned bNulls: 1; /* True if explicit "NULLS FIRST/LAST" */
1765418045
union {
1765518046
struct {
@@ -17659,10 +18050,17 @@
1765918050
int iConstExprReg; /* Register in which Expr value is cached */
1766018051
} u;
1766118052
} a[1]; /* One slot for each expression in the list */
1766218053
};
1766318054
18055
+/*
18056
+** Allowed values for Expr.a.eEName
18057
+*/
18058
+#define ENAME_NAME 0 /* The AS clause of a result set */
18059
+#define ENAME_SPAN 1 /* Complete text of the result set expression */
18060
+#define ENAME_TAB 2 /* "DB.TABLE.NAME" for the result set */
18061
+
1766418062
/*
1766518063
** An instance of this structure can hold a simple list of identifiers,
1766618064
** such as the list "a,b,c" in the following statements:
1766718065
**
1766818066
** INSERT INTO t(a,b,c) VALUES ...;
@@ -17722,10 +18120,11 @@
1772218120
unsigned isIndexedBy :1; /* True if there is an INDEXED BY clause */
1772318121
unsigned isTabFunc :1; /* True if table-valued-function syntax */
1772418122
unsigned isCorrelated :1; /* True if sub-query is correlated */
1772518123
unsigned viaCoroutine :1; /* Implemented as a co-routine */
1772618124
unsigned isRecursive :1; /* True for recursive reference in WITH */
18125
+ unsigned fromDDL :1; /* Comes from sqlite_master */
1772718126
} fg;
1772818127
int iCursor; /* The VDBE cursor number used to access this table */
1772918128
Expr *pOn; /* The ON clause of a join */
1773018129
IdList *pUsing; /* The USING clause of a join */
1773118130
Bitmask colUsed; /* Bit N (1<<N) set if column N of pTab is used */
@@ -17825,25 +18224,28 @@
1782518224
** NC_HasAgg == SF_HasAgg == EP_Agg
1782618225
** NC_MinMaxAgg == SF_MinMaxAgg == SQLITE_FUNC_MINMAX
1782718226
** NC_HasWin == EP_Win
1782818227
**
1782918228
*/
17830
-#define NC_AllowAgg 0x0001 /* Aggregate functions are allowed here */
17831
-#define NC_PartIdx 0x0002 /* True if resolving a partial index WHERE */
17832
-#define NC_IsCheck 0x0004 /* True if resolving names in a CHECK constraint */
17833
-#define NC_InAggFunc 0x0008 /* True if analyzing arguments to an agg func */
17834
-#define NC_HasAgg 0x0010 /* One or more aggregate functions seen */
17835
-#define NC_IdxExpr 0x0020 /* True if resolving columns of CREATE INDEX */
17836
-#define NC_VarSelect 0x0040 /* A correlated subquery has been seen */
17837
-#define NC_UEList 0x0080 /* True if uNC.pEList is used */
17838
-#define NC_UAggInfo 0x0100 /* True if uNC.pAggInfo is used */
17839
-#define NC_UUpsert 0x0200 /* True if uNC.pUpsert is used */
17840
-#define NC_MinMaxAgg 0x1000 /* min/max aggregates seen. See note above */
17841
-#define NC_Complex 0x2000 /* True if a function or subquery seen */
17842
-#define NC_AllowWin 0x4000 /* Window functions are allowed here */
17843
-#define NC_HasWin 0x8000 /* One or more window functions seen */
17844
-#define NC_IsDDL 0x10000 /* Resolving names in a CREATE statement */
18229
+#define NC_AllowAgg 0x00001 /* Aggregate functions are allowed here */
18230
+#define NC_PartIdx 0x00002 /* True if resolving a partial index WHERE */
18231
+#define NC_IsCheck 0x00004 /* True if resolving a CHECK constraint */
18232
+#define NC_GenCol 0x00008 /* True for a GENERATED ALWAYS AS clause */
18233
+#define NC_HasAgg 0x00010 /* One or more aggregate functions seen */
18234
+#define NC_IdxExpr 0x00020 /* True if resolving columns of CREATE INDEX */
18235
+#define NC_SelfRef 0x0002e /* Combo: PartIdx, isCheck, GenCol, and IdxExpr */
18236
+#define NC_VarSelect 0x00040 /* A correlated subquery has been seen */
18237
+#define NC_UEList 0x00080 /* True if uNC.pEList is used */
18238
+#define NC_UAggInfo 0x00100 /* True if uNC.pAggInfo is used */
18239
+#define NC_UUpsert 0x00200 /* True if uNC.pUpsert is used */
18240
+#define NC_MinMaxAgg 0x01000 /* min/max aggregates seen. See note above */
18241
+#define NC_Complex 0x02000 /* True if a function or subquery seen */
18242
+#define NC_AllowWin 0x04000 /* Window functions are allowed here */
18243
+#define NC_HasWin 0x08000 /* One or more window functions seen */
18244
+#define NC_IsDDL 0x10000 /* Resolving names in a CREATE statement */
18245
+#define NC_InAggFunc 0x20000 /* True if analyzing arguments to an agg func */
18246
+#define NC_FromDDL 0x40000 /* SQL text comes from sqlite_master */
1784518247
1784618248
/*
1784718249
** An instance of the following object describes a single ON CONFLICT
1784818250
** clause in an upsert.
1784918251
**
@@ -17889,17 +18291,17 @@
1788918291
** The KeyInfo for addrOpenTran[0] and [1] contains collating sequences
1789018292
** for the result set. The KeyInfo for addrOpenEphm[2] contains collating
1789118293
** sequences for the ORDER BY clause.
1789218294
*/
1789318295
struct Select {
17894
- ExprList *pEList; /* The fields of the result */
1789518296
u8 op; /* One of: TK_UNION TK_ALL TK_INTERSECT TK_EXCEPT */
1789618297
LogEst nSelectRow; /* Estimated number of result rows */
1789718298
u32 selFlags; /* Various SF_* values */
1789818299
int iLimit, iOffset; /* Memory registers holding LIMIT & OFFSET counters */
1789918300
u32 selId; /* Unique identifier number for this SELECT */
1790018301
int addrOpenEphm[2]; /* OP_OpenEphem opcodes related to this select */
18302
+ ExprList *pEList; /* The fields of the result */
1790118303
SrcList *pSrc; /* The FROM clause */
1790218304
Expr *pWhere; /* The WHERE clause */
1790318305
ExprList *pGroupBy; /* The GROUP BY clause */
1790418306
Expr *pHaving; /* The HAVING clause */
1790518307
ExprList *pOrderBy; /* The ORDER BY clause */
@@ -17920,30 +18322,32 @@
1792018322
** Value constraints (all checked via assert())
1792118323
** SF_HasAgg == NC_HasAgg
1792218324
** SF_MinMaxAgg == NC_MinMaxAgg == SQLITE_FUNC_MINMAX
1792318325
** SF_FixedLimit == WHERE_USE_LIMIT
1792418326
*/
17925
-#define SF_Distinct 0x00001 /* Output should be DISTINCT */
17926
-#define SF_All 0x00002 /* Includes the ALL keyword */
17927
-#define SF_Resolved 0x00004 /* Identifiers have been resolved */
17928
-#define SF_Aggregate 0x00008 /* Contains agg functions or a GROUP BY */
17929
-#define SF_HasAgg 0x00010 /* Contains aggregate functions */
17930
-#define SF_UsesEphemeral 0x00020 /* Uses the OpenEphemeral opcode */
17931
-#define SF_Expanded 0x00040 /* sqlite3SelectExpand() called on this */
17932
-#define SF_HasTypeInfo 0x00080 /* FROM subqueries have Table metadata */
17933
-#define SF_Compound 0x00100 /* Part of a compound query */
17934
-#define SF_Values 0x00200 /* Synthesized from VALUES clause */
17935
-#define SF_MultiValue 0x00400 /* Single VALUES term with multiple rows */
17936
-#define SF_NestedFrom 0x00800 /* Part of a parenthesized FROM clause */
17937
-#define SF_MinMaxAgg 0x01000 /* Aggregate containing min() or max() */
17938
-#define SF_Recursive 0x02000 /* The recursive part of a recursive CTE */
17939
-#define SF_FixedLimit 0x04000 /* nSelectRow set by a constant LIMIT */
17940
-#define SF_MaybeConvert 0x08000 /* Need convertCompoundSelectToSubquery() */
17941
-#define SF_Converted 0x10000 /* By convertCompoundSelectToSubquery() */
17942
-#define SF_IncludeHidden 0x20000 /* Include hidden columns in output */
17943
-#define SF_ComplexResult 0x40000 /* Result contains subquery or function */
17944
-#define SF_WhereBegin 0x80000 /* Really a WhereBegin() call. Debug Only */
18327
+#define SF_Distinct 0x0000001 /* Output should be DISTINCT */
18328
+#define SF_All 0x0000002 /* Includes the ALL keyword */
18329
+#define SF_Resolved 0x0000004 /* Identifiers have been resolved */
18330
+#define SF_Aggregate 0x0000008 /* Contains agg functions or a GROUP BY */
18331
+#define SF_HasAgg 0x0000010 /* Contains aggregate functions */
18332
+#define SF_UsesEphemeral 0x0000020 /* Uses the OpenEphemeral opcode */
18333
+#define SF_Expanded 0x0000040 /* sqlite3SelectExpand() called on this */
18334
+#define SF_HasTypeInfo 0x0000080 /* FROM subqueries have Table metadata */
18335
+#define SF_Compound 0x0000100 /* Part of a compound query */
18336
+#define SF_Values 0x0000200 /* Synthesized from VALUES clause */
18337
+#define SF_MultiValue 0x0000400 /* Single VALUES term with multiple rows */
18338
+#define SF_NestedFrom 0x0000800 /* Part of a parenthesized FROM clause */
18339
+#define SF_MinMaxAgg 0x0001000 /* Aggregate containing min() or max() */
18340
+#define SF_Recursive 0x0002000 /* The recursive part of a recursive CTE */
18341
+#define SF_FixedLimit 0x0004000 /* nSelectRow set by a constant LIMIT */
18342
+#define SF_MaybeConvert 0x0008000 /* Need convertCompoundSelectToSubquery() */
18343
+#define SF_Converted 0x0010000 /* By convertCompoundSelectToSubquery() */
18344
+#define SF_IncludeHidden 0x0020000 /* Include hidden columns in output */
18345
+#define SF_ComplexResult 0x0040000 /* Result contains subquery or function */
18346
+#define SF_WhereBegin 0x0080000 /* Really a WhereBegin() call. Debug Only */
18347
+#define SF_WinRewrite 0x0100000 /* Window function rewrite accomplished */
18348
+#define SF_View 0x0200000 /* SELECT statement is a view */
1794518349
1794618350
/*
1794718351
** The results of a SELECT can be distributed in several ways, as defined
1794818352
** by one of the following macros. The "SRT" prefix means "SELECT Result
1794918353
** Type".
@@ -18219,12 +18623,12 @@
1821918623
#endif
1822018624
};
1822118625
1822218626
#define PARSE_MODE_NORMAL 0
1822318627
#define PARSE_MODE_DECLARE_VTAB 1
18224
-#define PARSE_MODE_RENAME_COLUMN 2
18225
-#define PARSE_MODE_RENAME_TABLE 3
18628
+#define PARSE_MODE_RENAME 2
18629
+#define PARSE_MODE_UNMAP 3
1822618630
1822718631
/*
1822818632
** Sizes and pointers of various parts of the Parse object.
1822918633
*/
1823018634
#define PARSE_HDR_SZ offsetof(Parse,aTempReg) /* Recursive part w/o aColCache*/
@@ -18242,11 +18646,11 @@
1824218646
#endif
1824318647
1824418648
#if defined(SQLITE_OMIT_ALTERTABLE)
1824518649
#define IN_RENAME_OBJECT 0
1824618650
#else
18247
- #define IN_RENAME_OBJECT (pParse->eParseMode>=PARSE_MODE_RENAME_COLUMN)
18651
+ #define IN_RENAME_OBJECT (pParse->eParseMode>=PARSE_MODE_RENAME)
1824818652
#endif
1824918653
1825018654
#if defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_OMIT_ALTERTABLE)
1825118655
#define IN_SPECIAL_PARSE 0
1825218656
#else
@@ -18393,11 +18797,11 @@
1839318797
*/
1839418798
typedef struct DbFixer DbFixer;
1839518799
struct DbFixer {
1839618800
Parse *pParse; /* The parsing context. Error messages written here */
1839718801
Schema *pSchema; /* Fix items to this schema */
18398
- int bVarOnly; /* Check for variable references only */
18802
+ u8 bTemp; /* True for TEMP schema entries */
1839918803
const char *zDb; /* Make sure all objects are contained in this database */
1840018804
const char *zType; /* Type of the container - used for error messages */
1840118805
const Token *pName; /* Name of the container - used for error messages */
1840218806
};
1840318807
@@ -18498,11 +18902,10 @@
1849818902
#endif
1849918903
#ifndef SQLITE_UNTESTABLE
1850018904
int (*xTestCallback)(int); /* Invoked by sqlite3FaultSim() */
1850118905
#endif
1850218906
int bLocaltimeFault; /* True to fail localtime() calls */
18503
- int bInternalFunctions; /* Internal SQL functions are visible */
1850418907
int iOnceResetThreshold; /* When to reset OP_Once counters */
1850518908
u32 szSorterRef; /* Min size in bytes to use sorter-refs */
1850618909
unsigned int iPrngSeed; /* Alternative fixed seed for the PRNG */
1850718910
};
1850818911
@@ -18531,11 +18934,11 @@
1853118934
Parse *pParse; /* Parser context. */
1853218935
int (*xExprCallback)(Walker*, Expr*); /* Callback for expressions */
1853318936
int (*xSelectCallback)(Walker*,Select*); /* Callback for SELECTs */
1853418937
void (*xSelectCallback2)(Walker*,Select*);/* Second callback for SELECTs */
1853518938
int walkerDepth; /* Number of subqueries */
18536
- u8 eCode; /* A small processing code */
18939
+ u16 eCode; /* A small processing code */
1853718940
union { /* Extra data for callback */
1853818941
NameContext *pNC; /* Naming context */
1853918942
int n; /* A counter */
1854018943
int iCur; /* A cursor number */
1854118944
SrcList *pSrcList; /* FROM clause */
@@ -18547,10 +18950,11 @@
1854718950
ExprList *pGroupBy; /* GROUP BY clause */
1854818951
Select *pSelect; /* HAVING to WHERE clause ctx */
1854918952
struct WindowRewrite *pRewrite; /* Window rewrite context */
1855018953
struct WhereConst *pConst; /* WHERE clause constants */
1855118954
struct RenameCtx *pRename; /* RENAME COLUMN context */
18955
+ struct Table *pTab; /* Table of generated column */
1855218956
} u;
1855318957
};
1855418958
1855518959
/* Forward declarations */
1855618960
SQLITE_PRIVATE int sqlite3WalkExpr(Walker*, Expr*);
@@ -18660,11 +19064,11 @@
1866019064
SQLITE_PRIVATE void sqlite3WindowListDelete(sqlite3 *db, Window *p);
1866119065
SQLITE_PRIVATE Window *sqlite3WindowAlloc(Parse*, int, int, Expr*, int , Expr*, u8);
1866219066
SQLITE_PRIVATE void sqlite3WindowAttach(Parse*, Expr*, Window*);
1866319067
SQLITE_PRIVATE void sqlite3WindowLink(Select *pSel, Window *pWin);
1866419068
SQLITE_PRIVATE int sqlite3WindowCompare(Parse*, Window*, Window*, int);
18665
-SQLITE_PRIVATE void sqlite3WindowCodeInit(Parse*, Window*);
19069
+SQLITE_PRIVATE void sqlite3WindowCodeInit(Parse*, Select*);
1866619070
SQLITE_PRIVATE void sqlite3WindowCodeStep(Parse*, Select*, WhereInfo*, int, int);
1866719071
SQLITE_PRIVATE int sqlite3WindowRewrite(Parse*, Select*);
1866819072
SQLITE_PRIVATE int sqlite3ExpandSubquery(Parse*, struct SrcList_item*);
1866919073
SQLITE_PRIVATE void sqlite3WindowUpdate(Parse*, Window*, Window*, FuncDef*);
1867019074
SQLITE_PRIVATE Window *sqlite3WindowDup(sqlite3 *db, Expr *pOwner, Window *p);
@@ -18926,10 +19330,11 @@
1892619330
SQLITE_PRIVATE Expr *sqlite3PExpr(Parse*, int, Expr*, Expr*);
1892719331
SQLITE_PRIVATE void sqlite3PExprAddSelect(Parse*, Expr*, Select*);
1892819332
SQLITE_PRIVATE Expr *sqlite3ExprAnd(Parse*,Expr*, Expr*);
1892919333
SQLITE_PRIVATE Expr *sqlite3ExprSimplifiedAndOr(Expr*);
1893019334
SQLITE_PRIVATE Expr *sqlite3ExprFunction(Parse*,ExprList*, Token*, int);
19335
+SQLITE_PRIVATE void sqlite3ExprFunctionUsable(Parse*,Expr*,FuncDef*);
1893119336
SQLITE_PRIVATE void sqlite3ExprAssignVarNumber(Parse*, Expr*, u32);
1893219337
SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3*, Expr*);
1893319338
SQLITE_PRIVATE void sqlite3ExprUnmapAndDelete(Parse*, Expr*);
1893419339
SQLITE_PRIVATE ExprList *sqlite3ExprListAppend(Parse*,ExprList*,Expr*);
1893519340
SQLITE_PRIVATE ExprList *sqlite3ExprListAppendVector(Parse*,ExprList*,IdList*,Expr*);
@@ -18954,11 +19359,18 @@
1895419359
SQLITE_PRIVATE int sqlite3ColumnsFromExprList(Parse*,ExprList*,i16*,Column**);
1895519360
SQLITE_PRIVATE void sqlite3SelectAddColumnTypeAndCollation(Parse*,Table*,Select*,char);
1895619361
SQLITE_PRIVATE Table *sqlite3ResultSetOfSelect(Parse*,Select*,char);
1895719362
SQLITE_PRIVATE void sqlite3OpenMasterTable(Parse *, int);
1895819363
SQLITE_PRIVATE Index *sqlite3PrimaryKeyIndex(Table*);
18959
-SQLITE_PRIVATE i16 sqlite3ColumnOfIndex(Index*, i16);
19364
+SQLITE_PRIVATE i16 sqlite3TableColumnToIndex(Index*, i16);
19365
+#ifdef SQLITE_OMIT_GENERATED_COLUMNS
19366
+# define sqlite3TableColumnToStorage(T,X) (X) /* No-op pass-through */
19367
+# define sqlite3StorageColumnToTable(T,X) (X) /* No-op pass-through */
19368
+#else
19369
+SQLITE_PRIVATE i16 sqlite3TableColumnToStorage(Table*, i16);
19370
+SQLITE_PRIVATE i16 sqlite3StorageColumnToTable(Table*, i16);
19371
+#endif
1896019372
SQLITE_PRIVATE void sqlite3StartTable(Parse*,Token*,Token*,int,int,int,int);
1896119373
#if SQLITE_ENABLE_HIDDEN_COLUMNS
1896219374
SQLITE_PRIVATE void sqlite3ColumnPropertiesFromName(Table*, Column*);
1896319375
#else
1896419376
# define sqlite3ColumnPropertiesFromName(T,C) /* no-op */
@@ -18967,10 +19379,11 @@
1896719379
SQLITE_PRIVATE void sqlite3AddNotNull(Parse*, int);
1896819380
SQLITE_PRIVATE void sqlite3AddPrimaryKey(Parse*, ExprList*, int, int, int);
1896919381
SQLITE_PRIVATE void sqlite3AddCheckConstraint(Parse*, Expr*);
1897019382
SQLITE_PRIVATE void sqlite3AddDefaultValue(Parse*,Expr*,const char*,const char*);
1897119383
SQLITE_PRIVATE void sqlite3AddCollateType(Parse*, Token*);
19384
+SQLITE_PRIVATE void sqlite3AddGenerated(Parse*,Expr*,Token*);
1897219385
SQLITE_PRIVATE void sqlite3EndTable(Parse*,Token*,Token*,u8,Select*);
1897319386
SQLITE_PRIVATE int sqlite3ParseUri(const char*,const char*,unsigned int*,
1897419387
sqlite3_vfs**,char**,char **);
1897519388
#ifdef SQLITE_HAS_CODEC
1897619389
SQLITE_PRIVATE int sqlite3CodecQueryParameters(sqlite3*,const char*,const char*);
@@ -19024,10 +19437,13 @@
1902419437
#else
1902519438
# define sqlite3AutoincrementBegin(X)
1902619439
# define sqlite3AutoincrementEnd(X)
1902719440
#endif
1902819441
SQLITE_PRIVATE void sqlite3Insert(Parse*, SrcList*, Select*, IdList*, int, Upsert*);
19442
+#ifndef SQLITE_OMIT_GENERATED_COLUMNS
19443
+SQLITE_PRIVATE void sqlite3ComputeGeneratedColumns(Parse*, int, Table*);
19444
+#endif
1902919445
SQLITE_PRIVATE void *sqlite3ArrayAllocate(sqlite3*,void*,int,int*,int*);
1903019446
SQLITE_PRIVATE IdList *sqlite3IdListAppend(Parse*, IdList*, Token*);
1903119447
SQLITE_PRIVATE int sqlite3IdListIndex(IdList*,const char*);
1903219448
SQLITE_PRIVATE SrcList *sqlite3SrcListEnlarge(Parse*, SrcList*, int, int);
1903319449
SQLITE_PRIVATE SrcList *sqlite3SrcListAppend(Parse*, SrcList*, Token*, Token*);
@@ -19046,10 +19462,11 @@
1904619462
SQLITE_PRIVATE void sqlite3DropIndex(Parse*, SrcList*, int);
1904719463
SQLITE_PRIVATE int sqlite3Select(Parse*, Select*, SelectDest*);
1904819464
SQLITE_PRIVATE Select *sqlite3SelectNew(Parse*,ExprList*,SrcList*,Expr*,ExprList*,
1904919465
Expr*,ExprList*,u32,Expr*);
1905019466
SQLITE_PRIVATE void sqlite3SelectDelete(sqlite3*, Select*);
19467
+SQLITE_PRIVATE void sqlite3SelectReset(Parse*, Select*);
1905119468
SQLITE_PRIVATE Table *sqlite3SrcListLookup(Parse*, SrcList*);
1905219469
SQLITE_PRIVATE int sqlite3IsReadOnly(Parse*, Table*, int);
1905319470
SQLITE_PRIVATE void sqlite3OpenTable(Parse*, int iCur, int iDb, Table*, int);
1905419471
#if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) && !defined(SQLITE_OMIT_SUBQUERY)
1905519472
SQLITE_PRIVATE Expr *sqlite3LimitWhere(Parse*,SrcList*,Expr*,ExprList*,Expr*,char*);
@@ -19068,21 +19485,24 @@
1906819485
SQLITE_PRIVATE int sqlite3WhereBreakLabel(WhereInfo*);
1906919486
SQLITE_PRIVATE int sqlite3WhereOkOnePass(WhereInfo*, int*);
1907019487
#define ONEPASS_OFF 0 /* Use of ONEPASS not allowed */
1907119488
#define ONEPASS_SINGLE 1 /* ONEPASS valid for a single row update */
1907219489
#define ONEPASS_MULTI 2 /* ONEPASS is valid for multiple rows */
19490
+SQLITE_PRIVATE int sqlite3WhereUsesDeferredSeek(WhereInfo*);
1907319491
SQLITE_PRIVATE void sqlite3ExprCodeLoadIndexColumn(Parse*, Index*, int, int, int);
1907419492
SQLITE_PRIVATE int sqlite3ExprCodeGetColumn(Parse*, Table*, int, int, int, u8);
1907519493
SQLITE_PRIVATE void sqlite3ExprCodeGetColumnOfTable(Vdbe*, Table*, int, int, int);
1907619494
SQLITE_PRIVATE void sqlite3ExprCodeMove(Parse*, int, int, int);
1907719495
SQLITE_PRIVATE void sqlite3ExprCode(Parse*, Expr*, int);
19496
+#ifndef SQLITE_OMIT_GENERATED_COLUMNS
19497
+SQLITE_PRIVATE void sqlite3ExprCodeGeneratedColumn(Parse*, Column*, int);
19498
+#endif
1907819499
SQLITE_PRIVATE void sqlite3ExprCodeCopy(Parse*, Expr*, int);
1907919500
SQLITE_PRIVATE void sqlite3ExprCodeFactorable(Parse*, Expr*, int);
1908019501
SQLITE_PRIVATE int sqlite3ExprCodeAtInit(Parse*, Expr*, int);
1908119502
SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse*, Expr*, int*);
1908219503
SQLITE_PRIVATE int sqlite3ExprCodeTarget(Parse*, Expr*, int);
19083
-SQLITE_PRIVATE void sqlite3ExprCodeAndCache(Parse*, Expr*, int);
1908419504
SQLITE_PRIVATE int sqlite3ExprCodeExprList(Parse*, ExprList*, int, int, u8);
1908519505
#define SQLITE_ECEL_DUP 0x01 /* Deep, not shallow copies */
1908619506
#define SQLITE_ECEL_FACTOR 0x02 /* Factor out constant terms */
1908719507
#define SQLITE_ECEL_REF 0x04 /* Use ExprList.u.x.iOrderByCol */
1908819508
#define SQLITE_ECEL_OMITREF 0x08 /* Omit if ExprList.u.x.iOrderByCol */
@@ -19120,10 +19540,11 @@
1912019540
SQLITE_PRIVATE void sqlite3BeginTransaction(Parse*, int);
1912119541
SQLITE_PRIVATE void sqlite3EndTransaction(Parse*,int);
1912219542
SQLITE_PRIVATE void sqlite3Savepoint(Parse*, int, Token*);
1912319543
SQLITE_PRIVATE void sqlite3CloseSavepoints(sqlite3 *);
1912419544
SQLITE_PRIVATE void sqlite3LeaveMutexAndCloseZombie(sqlite3*);
19545
+SQLITE_PRIVATE u32 sqlite3IsTrueOrFalse(const char*);
1912519546
SQLITE_PRIVATE int sqlite3ExprIdToTrueFalse(Expr*);
1912619547
SQLITE_PRIVATE int sqlite3ExprTruthValue(const Expr*);
1912719548
SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr*);
1912819549
SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr*);
1912919550
SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*, u8);
@@ -19215,10 +19636,11 @@
1921519636
# define sqlite3IsToplevel(p) 1
1921619637
# define sqlite3TriggerColmask(A,B,C,D,E,F,G) 0
1921719638
#endif
1921819639
1921919640
SQLITE_PRIVATE int sqlite3JoinType(Parse*, Token*, Token*, Token*);
19641
+SQLITE_PRIVATE void sqlite3SetJoinExpr(Expr*,int);
1922019642
SQLITE_PRIVATE void sqlite3CreateForeignKey(Parse*, ExprList*, Token*, ExprList*, int);
1922119643
SQLITE_PRIVATE void sqlite3DeferForeignKey(Parse*, int);
1922219644
#ifndef SQLITE_OMIT_AUTHORIZATION
1922319645
SQLITE_PRIVATE void sqlite3AuthRead(Parse*,Expr*,Schema*,SrcList*);
1922419646
SQLITE_PRIVATE int sqlite3AuthCheck(Parse*,int, const char*, const char*, const char*);
@@ -19375,11 +19797,16 @@
1937519797
SQLITE_PRIVATE void sqlite3ExpirePreparedStatements(sqlite3*, int);
1937619798
SQLITE_PRIVATE void sqlite3CodeRhsOfIN(Parse*, Expr*, int);
1937719799
SQLITE_PRIVATE int sqlite3CodeSubselect(Parse*, Expr*);
1937819800
SQLITE_PRIVATE void sqlite3SelectPrep(Parse*, Select*, NameContext*);
1937919801
SQLITE_PRIVATE void sqlite3SelectWrongNumTermsError(Parse *pParse, Select *p);
19380
-SQLITE_PRIVATE int sqlite3MatchSpanName(const char*, const char*, const char*, const char*);
19802
+SQLITE_PRIVATE int sqlite3MatchEName(
19803
+ const struct ExprList_item*,
19804
+ const char*,
19805
+ const char*,
19806
+ const char*
19807
+);
1938119808
SQLITE_PRIVATE int sqlite3ResolveExprNames(NameContext*, Expr*);
1938219809
SQLITE_PRIVATE int sqlite3ResolveExprListNames(NameContext*, ExprList*);
1938319810
SQLITE_PRIVATE void sqlite3ResolveSelectNames(Parse*, Select*, NameContext*);
1938419811
SQLITE_PRIVATE int sqlite3ResolveSelfReference(Parse*,Table*,int,Expr*,ExprList*);
1938519812
SQLITE_PRIVATE int sqlite3ResolveOrderGroupBy(Parse*, Select*, ExprList*, const char*);
@@ -19512,10 +19939,16 @@
1951219939
const sqlite3_module*,
1951319940
void*,
1951419941
void(*)(void*)
1951519942
);
1951619943
# define sqlite3VtabInSync(db) ((db)->nVTrans>0 && (db)->aVTrans==0)
19944
+#endif
19945
+SQLITE_PRIVATE int sqlite3ReadOnlyShadowTables(sqlite3 *db);
19946
+#ifndef SQLITE_OMIT_VIRTUALTABLE
19947
+SQLITE_PRIVATE int sqlite3ShadowTableName(sqlite3 *db, const char *zName);
19948
+#else
19949
+# define sqlite3ShadowTableName(A,B) 0
1951719950
#endif
1951819951
SQLITE_PRIVATE int sqlite3VtabEponymousTableInit(Parse*,Module*);
1951919952
SQLITE_PRIVATE void sqlite3VtabEponymousTableClear(sqlite3*,Module*);
1952019953
SQLITE_PRIVATE void sqlite3VtabMakeWritable(Parse*,Table*);
1952119954
SQLITE_PRIVATE void sqlite3VtabBeginParse(Parse*, Token*, Token*, Token*, int);
@@ -19534,10 +19967,11 @@
1953419967
#ifdef SQLITE_ENABLE_NORMALIZE
1953519968
SQLITE_PRIVATE char *sqlite3Normalize(Vdbe*, const char*);
1953619969
#endif
1953719970
SQLITE_PRIVATE int sqlite3Reprepare(Vdbe*);
1953819971
SQLITE_PRIVATE void sqlite3ExprListCheckLength(Parse*, ExprList*, const char*);
19972
+SQLITE_PRIVATE CollSeq *sqlite3ExprCompareCollSeq(Parse*,Expr*);
1953919973
SQLITE_PRIVATE CollSeq *sqlite3BinaryCompareCollSeq(Parse *, Expr *, Expr *);
1954019974
SQLITE_PRIVATE int sqlite3TempInMemory(const sqlite3*);
1954119975
SQLITE_PRIVATE const char *sqlite3JournalModename(int);
1954219976
#ifndef SQLITE_OMIT_WAL
1954319977
SQLITE_PRIVATE int sqlite3Checkpoint(sqlite3*, int, int, int*, int*);
@@ -19840,11 +20274,10 @@
1984020274
** Bit 0x40 is set if the character is non-alphanumeric and can be used in an
1984120275
** SQLite identifier. Identifiers are alphanumerics, "_", "$", and any
1984220276
** non-ASCII UTF character. Hence the test for whether or not a character is
1984320277
** part of an identifier is 0x46.
1984420278
*/
19845
-#ifdef SQLITE_ASCII
1984620279
SQLITE_PRIVATE const unsigned char sqlite3CtypeMap[256] = {
1984720280
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 00..07 ........ */
1984820281
0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, /* 08..0f ........ */
1984920282
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 10..17 ........ */
1985020283
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 18..1f ........ */
@@ -19878,11 +20311,10 @@
1987820311
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* e0..e7 ........ */
1987920312
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* e8..ef ........ */
1988020313
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* f0..f7 ........ */
1988120314
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40 /* f8..ff ........ */
1988220315
};
19883
-#endif
1988420316
1988520317
/* EVIDENCE-OF: R-02982-34736 In order to maintain full backwards
1988620318
** compatibility for legacy applications, the URI filename capability is
1988720319
** disabled by default.
1988820320
**
@@ -19943,13 +20375,22 @@
1994320375
** number of bytes in each lookaside slot (should be a multiple of 8)
1994420376
** and N is the number of slots. The lookaside-configuration can be
1994520377
** changed as start-time using sqlite3_config(SQLITE_CONFIG_LOOKASIDE)
1994620378
** or at run-time for an individual database connection using
1994720379
** sqlite3_db_config(db, SQLITE_DBCONFIG_LOOKASIDE);
20380
+**
20381
+** With the two-size-lookaside enhancement, less lookaside is required.
20382
+** The default configuration of 1200,40 actually provides 30 1200-byte slots
20383
+** and 93 128-byte slots, which is more lookaside than is available
20384
+** using the older 1200,100 configuration without two-size-lookaside.
1994820385
*/
1994920386
#ifndef SQLITE_DEFAULT_LOOKASIDE
19950
-# define SQLITE_DEFAULT_LOOKASIDE 1200,100
20387
+# ifdef SQLITE_OMIT_TWOSIZE_LOOKASIDE
20388
+# define SQLITE_DEFAULT_LOOKASIDE 1200,100 /* 120KB of memory */
20389
+# else
20390
+# define SQLITE_DEFAULT_LOOKASIDE 1200,40 /* 48KB of memory */
20391
+# endif
1995120392
#endif
1995220393
1995320394
1995420395
/* The default maximum size of an in-memory database created using
1995520396
** sqlite3_deserialize()
@@ -20011,11 +20452,10 @@
2001120452
#endif
2001220453
#ifndef SQLITE_UNTESTABLE
2001320454
0, /* xTestCallback */
2001420455
#endif
2001520456
0, /* bLocaltimeFault */
20016
- 0, /* bInternalFunctions */
2001720457
0x7ffffffe, /* iOnceResetThreshold */
2001820458
SQLITE_DEFAULT_SORTERREF_SIZE, /* szSorterRef */
2001920459
0, /* iPrngSeed */
2002020460
};
2002120461
@@ -20376,11 +20816,12 @@
2037620816
2037720817
/*
2037820818
** True if Mem X is a NULL-nochng type.
2037920819
*/
2038020820
#define MemNullNochng(X) \
20381
- ((X)->flags==(MEM_Null|MEM_Zero) && (X)->n==0 && (X)->u.nZero==0)
20821
+ (((X)->flags&MEM_TypeMask)==(MEM_Null|MEM_Zero) \
20822
+ && (X)->n==0 && (X)->u.nZero==0)
2038220823
2038320824
/*
2038420825
** Return true if a memory cell is not marked as invalid. This macro
2038520826
** is for use inside assert() statements only.
2038620827
*/
@@ -20572,10 +21013,11 @@
2057221013
** Function prototypes
2057321014
*/
2057421015
SQLITE_PRIVATE void sqlite3VdbeError(Vdbe*, const char *, ...);
2057521016
SQLITE_PRIVATE void sqlite3VdbeFreeCursor(Vdbe *, VdbeCursor*);
2057621017
void sqliteVdbePopStack(Vdbe*,int);
21018
+SQLITE_PRIVATE int SQLITE_NOINLINE sqlite3VdbeFinishMoveto(VdbeCursor*);
2057721019
SQLITE_PRIVATE int sqlite3VdbeCursorMoveto(VdbeCursor**, int*);
2057821020
SQLITE_PRIVATE int sqlite3VdbeCursorRestore(VdbeCursor*);
2057921021
SQLITE_PRIVATE u32 sqlite3VdbeSerialTypeLen(u32);
2058021022
SQLITE_PRIVATE u8 sqlite3VdbeOneByteSerialTypeLen(u8);
2058121023
SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(unsigned char*, Mem*, u32);
@@ -20618,11 +21060,11 @@
2061821060
SQLITE_PRIVATE double sqlite3VdbeRealValue(Mem*);
2061921061
SQLITE_PRIVATE int sqlite3VdbeBooleanValue(Mem*, int ifNull);
2062021062
SQLITE_PRIVATE void sqlite3VdbeIntegerAffinity(Mem*);
2062121063
SQLITE_PRIVATE int sqlite3VdbeMemRealify(Mem*);
2062221064
SQLITE_PRIVATE int sqlite3VdbeMemNumerify(Mem*);
20623
-SQLITE_PRIVATE void sqlite3VdbeMemCast(Mem*,u8,u8);
21065
+SQLITE_PRIVATE int sqlite3VdbeMemCast(Mem*,u8,u8);
2062421066
SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(BtCursor*,u32,u32,Mem*);
2062521067
SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p);
2062621068
SQLITE_PRIVATE int sqlite3VdbeMemFinalize(Mem*, FuncDef*);
2062721069
#ifndef SQLITE_OMIT_WINDOWFUNC
2062821070
SQLITE_PRIVATE int sqlite3VdbeMemAggValue(Mem*, Mem*, FuncDef*);
@@ -20684,11 +21126,11 @@
2068421126
# define sqlite3VdbeCheckFk(p,i) 0
2068521127
#endif
2068621128
2068721129
#ifdef SQLITE_DEBUG
2068821130
SQLITE_PRIVATE void sqlite3VdbePrintSql(Vdbe*);
20689
-SQLITE_PRIVATE void sqlite3VdbeMemPrettyPrint(Mem *pMem, char *zBuf);
21131
+SQLITE_PRIVATE void sqlite3VdbeMemPrettyPrint(Mem *pMem, StrAccum *pStr);
2069021132
#endif
2069121133
#ifndef SQLITE_OMIT_UTF16
2069221134
SQLITE_PRIVATE int sqlite3VdbeMemTranslate(Mem*, u8);
2069321135
SQLITE_PRIVATE int sqlite3VdbeMemHandleBom(Mem *pMem);
2069421136
#endif
@@ -20876,10 +21318,14 @@
2087621318
** Count the number of slots of lookaside memory that are outstanding
2087721319
*/
2087821320
SQLITE_PRIVATE int sqlite3LookasideUsed(sqlite3 *db, int *pHighwater){
2087921321
u32 nInit = countLookasideSlots(db->lookaside.pInit);
2088021322
u32 nFree = countLookasideSlots(db->lookaside.pFree);
21323
+#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
21324
+ nInit += countLookasideSlots(db->lookaside.pSmallInit);
21325
+ nFree += countLookasideSlots(db->lookaside.pSmallFree);
21326
+#endif /* SQLITE_OMIT_TWOSIZE_LOOKASIDE */
2088121327
if( pHighwater ) *pHighwater = db->lookaside.nSlot - nInit;
2088221328
return db->lookaside.nSlot - (nInit+nFree);
2088321329
}
2088421330
2088521331
/*
@@ -20908,10 +21354,19 @@
2090821354
while( p->pNext ) p = p->pNext;
2090921355
p->pNext = db->lookaside.pInit;
2091021356
db->lookaside.pInit = db->lookaside.pFree;
2091121357
db->lookaside.pFree = 0;
2091221358
}
21359
+#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
21360
+ p = db->lookaside.pSmallFree;
21361
+ if( p ){
21362
+ while( p->pNext ) p = p->pNext;
21363
+ p->pNext = db->lookaside.pSmallInit;
21364
+ db->lookaside.pSmallInit = db->lookaside.pSmallFree;
21365
+ db->lookaside.pSmallFree = 0;
21366
+ }
21367
+#endif
2091321368
}
2091421369
break;
2091521370
}
2091621371
2091721372
case SQLITE_DBSTATUS_LOOKASIDE_HIT:
@@ -21759,11 +22214,11 @@
2175922214
*/
2176022215
if( sqlite3_stricmp(z, "unixepoch")==0 && p->rawS ){
2176122216
r = p->s*1000.0 + 210866760000000.0;
2176222217
if( r>=0.0 && r<464269060800000.0 ){
2176322218
clearYMD_HMS_TZ(p);
21764
- p->iJD = (sqlite3_int64)r;
22219
+ p->iJD = (sqlite3_int64)(r + 0.5);
2176522220
p->validJD = 1;
2176622221
p->rawS = 0;
2176722222
rc = 0;
2176822223
}
2176922224
}
@@ -22538,11 +22993,11 @@
2253822993
DO_OS_MALLOC_TEST(0);
2253922994
/* 0x87f7f is a mask of SQLITE_OPEN_ flags that are valid to be passed
2254022995
** down into the VFS layer. Some SQLITE_OPEN_ flags (for example,
2254122996
** SQLITE_OPEN_FULLMUTEX or SQLITE_OPEN_SHAREDCACHE) are blocked before
2254222997
** reaching the VFS. */
22543
- rc = pVfs->xOpen(pVfs, zPath, pFile, flags & 0x87f7f, pFlagsOut);
22998
+ rc = pVfs->xOpen(pVfs, zPath, pFile, flags & 0x1087f7f, pFlagsOut);
2254422999
assert( rc==SQLITE_OK || pFile->pMethods==0 );
2254523000
return rc;
2254623001
}
2254723002
SQLITE_PRIVATE int sqlite3OsDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){
2254823003
DO_OS_MALLOC_TEST(0);
@@ -26056,11 +26511,11 @@
2605626511
** May you share freely, never taking more than you give.
2605726512
**
2605826513
******************************************************************************
2605926514
**
2606026515
** This file contains inline asm code for retrieving "high-performance"
26061
-** counters for x86 class CPUs.
26516
+** counters for x86 and x86_64 class CPUs.
2606226517
*/
2606326518
#ifndef SQLITE_HWTIME_H
2606426519
#define SQLITE_HWTIME_H
2606526520
2606626521
/*
@@ -26067,12 +26522,13 @@
2606726522
** The following routine only works on pentium-class (or newer) processors.
2606826523
** It uses the RDTSC opcode to read the cycle count value out of the
2606926524
** processor and returns that value. This can be used for high-res
2607026525
** profiling.
2607126526
*/
26072
-#if (defined(__GNUC__) || defined(_MSC_VER)) && \
26073
- (defined(i386) || defined(__i386__) || defined(_M_IX86))
26527
+#if !defined(__STRICT_ANSI__) && \
26528
+ (defined(__GNUC__) || defined(_MSC_VER)) && \
26529
+ (defined(i386) || defined(__i386__) || defined(_M_IX86))
2607426530
2607526531
#if defined(__GNUC__)
2607626532
2607726533
__inline__ sqlite_uint64 sqlite3Hwtime(void){
2607826534
unsigned int lo, hi;
@@ -26089,19 +26545,19 @@
2608926545
}
2609026546
}
2609126547
2609226548
#endif
2609326549
26094
-#elif (defined(__GNUC__) && defined(__x86_64__))
26550
+#elif !defined(__STRICT_ANSI__) && (defined(__GNUC__) && defined(__x86_64__))
2609526551
2609626552
__inline__ sqlite_uint64 sqlite3Hwtime(void){
2609726553
unsigned long val;
2609826554
__asm__ __volatile__ ("rdtsc" : "=A" (val));
2609926555
return val;
2610026556
}
2610126557
26102
-#elif (defined(__GNUC__) && defined(__ppc__))
26558
+#elif !defined(__STRICT_ANSI__) && (defined(__GNUC__) && defined(__ppc__))
2610326559
2610426560
__inline__ sqlite_uint64 sqlite3Hwtime(void){
2610526561
unsigned long long retval;
2610626562
unsigned long junk;
2610726563
__asm__ __volatile__ ("\n\
@@ -26114,18 +26570,17 @@
2611426570
return retval;
2611526571
}
2611626572
2611726573
#else
2611826574
26119
- #error Need implementation of sqlite3Hwtime() for your platform.
26120
-
2612126575
/*
26122
- ** To compile without implementing sqlite3Hwtime() for your platform,
26123
- ** you can remove the above #error and use the following
26124
- ** stub function. You will lose timing support for many
26125
- ** of the debugging and testing utilities, but it should at
26126
- ** least compile and run.
26576
+ ** asm() is needed for hardware timing support. Without asm(),
26577
+ ** disable the sqlite3Hwtime() routine.
26578
+ **
26579
+ ** sqlite3Hwtime() is only used for some obscure debugging
26580
+ ** and analysis configurations, not in any deliverable, so this
26581
+ ** should not be a great loss.
2612726582
*/
2612826583
SQLITE_PRIVATE sqlite_uint64 sqlite3Hwtime(void){ return ((sqlite_uint64)0); }
2612926584
2613026585
#endif
2613126586
@@ -26705,23 +27160,31 @@
2670527160
UNUSED_PARAMETER(n);
2670627161
return 0;
2670727162
#endif
2670827163
}
2670927164
27165
+/*
27166
+** Default value of the hard heap limit. 0 means "no limit".
27167
+*/
27168
+#ifndef SQLITE_MAX_MEMORY
27169
+# define SQLITE_MAX_MEMORY 0
27170
+#endif
27171
+
2671027172
/*
2671127173
** State information local to the memory allocation subsystem.
2671227174
*/
2671327175
static SQLITE_WSD struct Mem0Global {
2671427176
sqlite3_mutex *mutex; /* Mutex to serialize access */
2671527177
sqlite3_int64 alarmThreshold; /* The soft heap limit */
27178
+ sqlite3_int64 hardLimit; /* The hard upper bound on memory */
2671627179
2671727180
/*
2671827181
** True if heap is nearly "full" where "full" is defined by the
2671927182
** sqlite3_soft_heap_limit() setting.
2672027183
*/
2672127184
int nearlyFull;
26722
-} mem0 = { 0, 0, 0 };
27185
+} mem0 = { 0, SQLITE_MAX_MEMORY, SQLITE_MAX_MEMORY, 0 };
2672327186
2672427187
#define mem0 GLOBAL(struct Mem0Global, mem0)
2672527188
2672627189
/*
2672727190
** Return the memory allocator mutex. sqlite3_status() needs it.
@@ -26747,12 +27210,19 @@
2674727210
return SQLITE_OK;
2674827211
}
2674927212
#endif
2675027213
2675127214
/*
26752
-** Set the soft heap-size limit for the library. Passing a zero or
26753
-** negative value indicates no limit.
27215
+** Set the soft heap-size limit for the library. An argument of
27216
+** zero disables the limit. A negative argument is a no-op used to
27217
+** obtain the return value.
27218
+**
27219
+** The return value is the value of the heap limit just before this
27220
+** interface was called.
27221
+**
27222
+** If the hard heap limit is enabled, then the soft heap limit cannot
27223
+** be disabled nor raised above the hard heap limit.
2675427224
*/
2675527225
SQLITE_API sqlite3_int64 sqlite3_soft_heap_limit64(sqlite3_int64 n){
2675627226
sqlite3_int64 priorLimit;
2675727227
sqlite3_int64 excess;
2675827228
sqlite3_int64 nUsed;
@@ -26763,10 +27233,13 @@
2676327233
sqlite3_mutex_enter(mem0.mutex);
2676427234
priorLimit = mem0.alarmThreshold;
2676527235
if( n<0 ){
2676627236
sqlite3_mutex_leave(mem0.mutex);
2676727237
return priorLimit;
27238
+ }
27239
+ if( mem0.hardLimit>0 && (n>mem0.hardLimit || n==0) ){
27240
+ n = mem0.hardLimit;
2676827241
}
2676927242
mem0.alarmThreshold = n;
2677027243
nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED);
2677127244
mem0.nearlyFull = (n>0 && n<=nUsed);
2677227245
sqlite3_mutex_leave(mem0.mutex);
@@ -26776,10 +27249,41 @@
2677627249
}
2677727250
SQLITE_API void sqlite3_soft_heap_limit(int n){
2677827251
if( n<0 ) n = 0;
2677927252
sqlite3_soft_heap_limit64(n);
2678027253
}
27254
+
27255
+/*
27256
+** Set the hard heap-size limit for the library. An argument of zero
27257
+** disables the hard heap limit. A negative argument is a no-op used
27258
+** to obtain the return value without affecting the hard heap limit.
27259
+**
27260
+** The return value is the value of the hard heap limit just prior to
27261
+** calling this interface.
27262
+**
27263
+** Setting the hard heap limit will also activate the soft heap limit
27264
+** and constrain the soft heap limit to be no more than the hard heap
27265
+** limit.
27266
+*/
27267
+SQLITE_API sqlite3_int64 sqlite3_hard_heap_limit64(sqlite3_int64 n){
27268
+ sqlite3_int64 priorLimit;
27269
+#ifndef SQLITE_OMIT_AUTOINIT
27270
+ int rc = sqlite3_initialize();
27271
+ if( rc ) return -1;
27272
+#endif
27273
+ sqlite3_mutex_enter(mem0.mutex);
27274
+ priorLimit = mem0.hardLimit;
27275
+ if( n>=0 ){
27276
+ mem0.hardLimit = n;
27277
+ if( n<mem0.alarmThreshold || mem0.alarmThreshold==0 ){
27278
+ mem0.alarmThreshold = n;
27279
+ }
27280
+ }
27281
+ sqlite3_mutex_leave(mem0.mutex);
27282
+ return priorLimit;
27283
+}
27284
+
2678127285
2678227286
/*
2678327287
** Initialize the memory allocation subsystem.
2678427288
*/
2678527289
SQLITE_PRIVATE int sqlite3MallocInit(void){
@@ -26863,23 +27367,23 @@
2686327367
** mode and specifically when the DMD "Dark Matter Detector" is enabled
2686427368
** or else a crash results. Hence, do not attempt to optimize out the
2686527369
** following xRoundup() call. */
2686627370
nFull = sqlite3GlobalConfig.m.xRoundup(n);
2686727371
26868
-#ifdef SQLITE_MAX_MEMORY
26869
- if( sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED)+nFull>SQLITE_MAX_MEMORY ){
26870
- *pp = 0;
26871
- return;
26872
- }
26873
-#endif
26874
-
2687527372
sqlite3StatusHighwater(SQLITE_STATUS_MALLOC_SIZE, n);
2687627373
if( mem0.alarmThreshold>0 ){
2687727374
sqlite3_int64 nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED);
2687827375
if( nUsed >= mem0.alarmThreshold - nFull ){
2687927376
mem0.nearlyFull = 1;
2688027377
sqlite3MallocAlarm(nFull);
27378
+ if( mem0.hardLimit ){
27379
+ nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED);
27380
+ if( nUsed >= mem0.hardLimit - nFull ){
27381
+ *pp = 0;
27382
+ return;
27383
+ }
27384
+ }
2688127385
}else{
2688227386
mem0.nearlyFull = 0;
2688327387
}
2688427388
}
2688527389
p = sqlite3GlobalConfig.m.xMalloc(nFull);
@@ -26955,28 +27459,46 @@
2695527459
** sqlite3Malloc() or sqlite3_malloc().
2695627460
*/
2695727461
SQLITE_PRIVATE int sqlite3MallocSize(void *p){
2695827462
assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
2695927463
return sqlite3GlobalConfig.m.xSize(p);
27464
+}
27465
+static int lookasideMallocSize(sqlite3 *db, void *p){
27466
+#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
27467
+ return p<db->lookaside.pMiddle ? db->lookaside.szTrue : LOOKASIDE_SMALL;
27468
+#else
27469
+ return db->lookaside.szTrue;
27470
+#endif
2696027471
}
2696127472
SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, void *p){
2696227473
assert( p!=0 );
27474
+#ifdef SQLITE_DEBUG
2696327475
if( db==0 || !isLookaside(db,p) ){
26964
-#ifdef SQLITE_DEBUG
2696527476
if( db==0 ){
2696627477
assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) );
2696727478
assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
2696827479
}else{
2696927480
assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
2697027481
assert( sqlite3MemdebugNoType(p, (u8)~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
2697127482
}
27483
+ }
2697227484
#endif
26973
- return sqlite3GlobalConfig.m.xSize(p);
26974
- }else{
26975
- assert( sqlite3_mutex_held(db->mutex) );
26976
- return db->lookaside.sz;
27485
+ if( db ){
27486
+ if( ((uptr)p)<(uptr)(db->lookaside.pEnd) ){
27487
+#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
27488
+ if( ((uptr)p)>=(uptr)(db->lookaside.pMiddle) ){
27489
+ assert( sqlite3_mutex_held(db->mutex) );
27490
+ return LOOKASIDE_SMALL;
27491
+ }
27492
+#endif
27493
+ if( ((uptr)p)>=(uptr)(db->lookaside.pStart) ){
27494
+ assert( sqlite3_mutex_held(db->mutex) );
27495
+ return db->lookaside.szTrue;
27496
+ }
27497
+ }
2697727498
}
27499
+ return sqlite3GlobalConfig.m.xSize(p);
2697827500
}
2697927501
SQLITE_API sqlite3_uint64 sqlite3_msize(void *p){
2698027502
assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) );
2698127503
assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
2698227504
return p ? sqlite3GlobalConfig.m.xSize(p) : 0;
@@ -27019,19 +27541,31 @@
2701927541
if( db ){
2702027542
if( db->pnBytesFreed ){
2702127543
measureAllocationSize(db, p);
2702227544
return;
2702327545
}
27024
- if( isLookaside(db, p) ){
27025
- LookasideSlot *pBuf = (LookasideSlot*)p;
27546
+ if( ((uptr)p)<(uptr)(db->lookaside.pEnd) ){
27547
+#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
27548
+ if( ((uptr)p)>=(uptr)(db->lookaside.pMiddle) ){
27549
+ LookasideSlot *pBuf = (LookasideSlot*)p;
2702627550
#ifdef SQLITE_DEBUG
27027
- /* Trash all content in the buffer being freed */
27028
- memset(p, 0xaa, db->lookaside.sz);
27551
+ memset(p, 0xaa, LOOKASIDE_SMALL); /* Trash freed content */
2702927552
#endif
27030
- pBuf->pNext = db->lookaside.pFree;
27031
- db->lookaside.pFree = pBuf;
27032
- return;
27553
+ pBuf->pNext = db->lookaside.pSmallFree;
27554
+ db->lookaside.pSmallFree = pBuf;
27555
+ return;
27556
+ }
27557
+#endif /* SQLITE_OMIT_TWOSIZE_LOOKASIDE */
27558
+ if( ((uptr)p)>=(uptr)(db->lookaside.pStart) ){
27559
+ LookasideSlot *pBuf = (LookasideSlot*)p;
27560
+#ifdef SQLITE_DEBUG
27561
+ memset(p, 0xaa, db->lookaside.szTrue); /* Trash freed content */
27562
+#endif
27563
+ pBuf->pNext = db->lookaside.pFree;
27564
+ db->lookaside.pFree = pBuf;
27565
+ return;
27566
+ }
2703327567
}
2703427568
}
2703527569
assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
2703627570
assert( sqlite3MemdebugNoType(p, (u8)~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
2703727571
assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
@@ -27183,27 +27717,41 @@
2718327717
#ifndef SQLITE_OMIT_LOOKASIDE
2718427718
LookasideSlot *pBuf;
2718527719
assert( db!=0 );
2718627720
assert( sqlite3_mutex_held(db->mutex) );
2718727721
assert( db->pnBytesFreed==0 );
27188
- if( db->lookaside.bDisable==0 ){
27189
- assert( db->mallocFailed==0 );
27190
- if( n>db->lookaside.sz ){
27191
- db->lookaside.anStat[1]++;
27192
- }else if( (pBuf = db->lookaside.pFree)!=0 ){
27193
- db->lookaside.pFree = pBuf->pNext;
27194
- db->lookaside.anStat[0]++;
27195
- return (void*)pBuf;
27196
- }else if( (pBuf = db->lookaside.pInit)!=0 ){
27197
- db->lookaside.pInit = pBuf->pNext;
27198
- db->lookaside.anStat[0]++;
27199
- return (void*)pBuf;
27200
- }else{
27201
- db->lookaside.anStat[2]++;
27202
- }
27203
- }else if( db->mallocFailed ){
27204
- return 0;
27722
+ if( n>db->lookaside.sz ){
27723
+ if( !db->lookaside.bDisable ){
27724
+ db->lookaside.anStat[1]++;
27725
+ }else if( db->mallocFailed ){
27726
+ return 0;
27727
+ }
27728
+ return dbMallocRawFinish(db, n);
27729
+ }
27730
+#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
27731
+ if( n<=LOOKASIDE_SMALL ){
27732
+ if( (pBuf = db->lookaside.pSmallFree)!=0 ){
27733
+ db->lookaside.pSmallFree = pBuf->pNext;
27734
+ db->lookaside.anStat[0]++;
27735
+ return (void*)pBuf;
27736
+ }else if( (pBuf = db->lookaside.pSmallInit)!=0 ){
27737
+ db->lookaside.pSmallInit = pBuf->pNext;
27738
+ db->lookaside.anStat[0]++;
27739
+ return (void*)pBuf;
27740
+ }
27741
+ }
27742
+#endif
27743
+ if( (pBuf = db->lookaside.pFree)!=0 ){
27744
+ db->lookaside.pFree = pBuf->pNext;
27745
+ db->lookaside.anStat[0]++;
27746
+ return (void*)pBuf;
27747
+ }else if( (pBuf = db->lookaside.pInit)!=0 ){
27748
+ db->lookaside.pInit = pBuf->pNext;
27749
+ db->lookaside.anStat[0]++;
27750
+ return (void*)pBuf;
27751
+ }else{
27752
+ db->lookaside.anStat[2]++;
2720527753
}
2720627754
#else
2720727755
assert( db!=0 );
2720827756
assert( sqlite3_mutex_held(db->mutex) );
2720927757
assert( db->pnBytesFreed==0 );
@@ -27223,11 +27771,20 @@
2722327771
*/
2722427772
SQLITE_PRIVATE void *sqlite3DbRealloc(sqlite3 *db, void *p, u64 n){
2722527773
assert( db!=0 );
2722627774
if( p==0 ) return sqlite3DbMallocRawNN(db, n);
2722727775
assert( sqlite3_mutex_held(db->mutex) );
27228
- if( isLookaside(db,p) && n<=db->lookaside.sz ) return p;
27776
+ if( ((uptr)p)<(uptr)db->lookaside.pEnd ){
27777
+#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
27778
+ if( ((uptr)p)>=(uptr)db->lookaside.pMiddle ){
27779
+ if( n<=LOOKASIDE_SMALL ) return p;
27780
+ }else
27781
+#endif
27782
+ if( ((uptr)p)>=(uptr)db->lookaside.pStart ){
27783
+ if( n<=db->lookaside.szTrue ) return p;
27784
+ }
27785
+ }
2722927786
return dbReallocFinish(db, p, n);
2723027787
}
2723127788
static SQLITE_NOINLINE void *dbReallocFinish(sqlite3 *db, void *p, u64 n){
2723227789
void *pNew = 0;
2723327790
assert( db!=0 );
@@ -27234,11 +27791,11 @@
2723427791
assert( p!=0 );
2723527792
if( db->mallocFailed==0 ){
2723627793
if( isLookaside(db, p) ){
2723727794
pNew = sqlite3DbMallocRawNN(db, n);
2723827795
if( pNew ){
27239
- memcpy(pNew, p, db->lookaside.sz);
27796
+ memcpy(pNew, p, lookasideMallocSize(db, p));
2724027797
sqlite3DbFree(db, p);
2724127798
}
2724227799
}else{
2724327800
assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
2724427801
assert( sqlite3MemdebugNoType(p, (u8)~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
@@ -27333,11 +27890,11 @@
2733327890
if( db->mallocFailed==0 && db->bBenignMalloc==0 ){
2733427891
db->mallocFailed = 1;
2733527892
if( db->nVdbeExec>0 ){
2733627893
db->u1.isInterrupted = 1;
2733727894
}
27338
- db->lookaside.bDisable++;
27895
+ DisableLookaside;
2733927896
if( db->pParse ){
2734027897
db->pParse->rc = SQLITE_NOMEM_BKPT;
2734127898
}
2734227899
}
2734327900
}
@@ -27352,11 +27909,11 @@
2735227909
SQLITE_PRIVATE void sqlite3OomClear(sqlite3 *db){
2735327910
if( db->mallocFailed && db->nVdbeExec==0 ){
2735427911
db->mallocFailed = 0;
2735527912
db->u1.isInterrupted = 0;
2735627913
assert( db->lookaside.bDisable>0 );
27357
- db->lookaside.bDisable--;
27914
+ EnableLookaside;
2735827915
}
2735927916
}
2736027917
2736127918
/*
2736227919
** Take actions at the end of an API call to indicate an OOM error
@@ -28760,11 +29317,11 @@
2876029317
}
2876129318
if( zFormat!=0 ){
2876229319
va_start(ap, zFormat);
2876329320
sqlite3_str_vappendf(&acc, zFormat, ap);
2876429321
va_end(ap);
28765
- assert( acc.nChar>0 );
29322
+ assert( acc.nChar>0 || acc.accError );
2876629323
sqlite3_str_append(&acc, "\n", 1);
2876729324
}
2876829325
sqlite3StrAccumFinish(&acc);
2876929326
fprintf(stdout,"%s", zBuf);
2877029327
fflush(stdout);
@@ -28800,11 +29357,11 @@
2880029357
sqlite3_str_appendf(&x, "%s", pCte->zName);
2880129358
if( pCte->pCols && pCte->pCols->nExpr>0 ){
2880229359
char cSep = '(';
2880329360
int j;
2880429361
for(j=0; j<pCte->pCols->nExpr; j++){
28805
- sqlite3_str_appendf(&x, "%c%s", cSep, pCte->pCols->a[j].zName);
29362
+ sqlite3_str_appendf(&x, "%c%s", cSep, pCte->pCols->a[j].zEName);
2880629363
cSep = ',';
2880729364
}
2880829365
sqlite3_str_appendf(&x, ")");
2880929366
}
2881029367
sqlite3_str_appendf(&x, " AS");
@@ -28825,11 +29382,11 @@
2882529382
for(i=0; i<pSrc->nSrc; i++){
2882629383
const struct SrcList_item *pItem = &pSrc->a[i];
2882729384
StrAccum x;
2882829385
char zLine[100];
2882929386
sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0);
28830
- sqlite3_str_appendf(&x, "{%d,*}", pItem->iCursor);
29387
+ sqlite3_str_appendf(&x, "{%d:*}", pItem->iCursor);
2883129388
if( pItem->zDatabase ){
2883229389
sqlite3_str_appendf(&x, " %s.%s", pItem->zDatabase, pItem->zName);
2883329390
}else if( pItem->zName ){
2883429391
sqlite3_str_appendf(&x, " %s", pItem->zName);
2883529392
}
@@ -28841,10 +29398,13 @@
2884129398
sqlite3_str_appendf(&x, " (AS %s)", pItem->zAlias);
2884229399
}
2884329400
if( pItem->fg.jointype & JT_LEFT ){
2884429401
sqlite3_str_appendf(&x, " LEFT-JOIN");
2884529402
}
29403
+ if( pItem->fg.fromDDL ){
29404
+ sqlite3_str_appendf(&x, " DDL");
29405
+ }
2884629406
sqlite3StrAccumFinish(&x);
2884729407
sqlite3TreeViewItem(pView, zLine, i<pSrc->nSrc-1);
2884829408
if( pItem->pSelect ){
2884929409
sqlite3TreeViewSelect(pView, pItem->pSelect, 0);
2885029410
}
@@ -29097,18 +29657,21 @@
2909729657
sqlite3TreeViewLine(pView, "nil");
2909829658
sqlite3TreeViewPop(pView);
2909929659
return;
2910029660
}
2910129661
if( pExpr->flags || pExpr->affExpr ){
29662
+ StrAccum x;
29663
+ sqlite3StrAccumInit(&x, 0, zFlgs, sizeof(zFlgs), 0);
29664
+ sqlite3_str_appendf(&x, " fg.af=%x.%c",
29665
+ pExpr->flags, pExpr->affExpr ? pExpr->affExpr : 'n');
2910229666
if( ExprHasProperty(pExpr, EP_FromJoin) ){
29103
- sqlite3_snprintf(sizeof(zFlgs),zFlgs," fg.af=%x.%c iRJT=%d",
29104
- pExpr->flags, pExpr->affExpr ? pExpr->affExpr : 'n',
29105
- pExpr->iRightJoinTable);
29106
- }else{
29107
- sqlite3_snprintf(sizeof(zFlgs),zFlgs," fg.af=%x.%c",
29108
- pExpr->flags, pExpr->affExpr ? pExpr->affExpr : 'n');
29667
+ sqlite3_str_appendf(&x, " iRJT=%d", pExpr->iRightJoinTable);
2910929668
}
29669
+ if( ExprHasProperty(pExpr, EP_FromDDL) ){
29670
+ sqlite3_str_appendf(&x, " DDL");
29671
+ }
29672
+ sqlite3StrAccumFinish(&x);
2911029673
}else{
2911129674
zFlgs[0] = 0;
2911229675
}
2911329676
switch( pExpr->op ){
2911429677
case TK_AGG_COLUMN: {
@@ -29117,14 +29680,22 @@
2911729680
break;
2911829681
}
2911929682
case TK_COLUMN: {
2912029683
if( pExpr->iTable<0 ){
2912129684
/* This only happens when coding check constraints */
29122
- sqlite3TreeViewLine(pView, "COLUMN(%d)%s", pExpr->iColumn, zFlgs);
29685
+ char zOp2[16];
29686
+ if( pExpr->op2 ){
29687
+ sqlite3_snprintf(sizeof(zOp2),zOp2," op2=0x%02x",pExpr->op2);
29688
+ }else{
29689
+ zOp2[0] = 0;
29690
+ }
29691
+ sqlite3TreeViewLine(pView, "COLUMN(%d)%s%s",
29692
+ pExpr->iColumn, zFlgs, zOp2);
2912329693
}else{
29124
- sqlite3TreeViewLine(pView, "{%d:%d}%s",
29125
- pExpr->iTable, pExpr->iColumn, zFlgs);
29694
+ sqlite3TreeViewLine(pView, "{%d:%d} pTab=%p%s",
29695
+ pExpr->iTable, pExpr->iColumn,
29696
+ pExpr->y.pTab, zFlgs);
2912629697
}
2912729698
if( ExprHasProperty(pExpr, EP_FixedCol) ){
2912829699
sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
2912929700
}
2913029701
break;
@@ -29252,18 +29823,29 @@
2925229823
pFarg = 0;
2925329824
pWin = 0;
2925429825
}else{
2925529826
pFarg = pExpr->x.pList;
2925629827
#ifndef SQLITE_OMIT_WINDOWFUNC
29257
- pWin = pExpr->y.pWin;
29828
+ pWin = ExprHasProperty(pExpr, EP_WinFunc) ? pExpr->y.pWin : 0;
2925829829
#else
2925929830
pWin = 0;
2926029831
#endif
2926129832
}
2926229833
if( pExpr->op==TK_AGG_FUNCTION ){
2926329834
sqlite3TreeViewLine(pView, "AGG_FUNCTION%d %Q%s",
2926429835
pExpr->op2, pExpr->u.zToken, zFlgs);
29836
+ }else if( pExpr->op2!=0 ){
29837
+ const char *zOp2;
29838
+ char zBuf[8];
29839
+ sqlite3_snprintf(sizeof(zBuf),zBuf,"0x%02x",pExpr->op2);
29840
+ zOp2 = zBuf;
29841
+ if( pExpr->op2==NC_IsCheck ) zOp2 = "NC_IsCheck";
29842
+ if( pExpr->op2==NC_IdxExpr ) zOp2 = "NC_IdxExpr";
29843
+ if( pExpr->op2==NC_PartIdx ) zOp2 = "NC_PartIdx";
29844
+ if( pExpr->op2==NC_GenCol ) zOp2 = "NC_GenCol";
29845
+ sqlite3TreeViewLine(pView, "FUNCTION %Q%s op2=%s",
29846
+ pExpr->u.zToken, zFlgs, zOp2);
2926529847
}else{
2926629848
sqlite3TreeViewLine(pView, "FUNCTION %Q%s", pExpr->u.zToken, zFlgs);
2926729849
}
2926829850
if( pFarg ){
2926929851
sqlite3TreeViewExprList(pView, pFarg, pWin!=0, 0);
@@ -29355,11 +29937,13 @@
2935529937
pExpr->iTable, pExpr->iColumn, zFlgs);
2935629938
sqlite3TreeViewExpr(pView, pExpr->pRight, 0);
2935729939
break;
2935829940
}
2935929941
case TK_VECTOR: {
29360
- sqlite3TreeViewBareExprList(pView, pExpr->x.pList, "VECTOR");
29942
+ char *z = sqlite3_mprintf("VECTOR%s",zFlgs);
29943
+ sqlite3TreeViewBareExprList(pView, pExpr->x.pList, z);
29944
+ sqlite3_free(z);
2936129945
break;
2936229946
}
2936329947
case TK_SELECT_COLUMN: {
2936429948
sqlite3TreeViewLine(pView, "SELECT-COLUMN %d", pExpr->iColumn);
2936529949
sqlite3TreeViewSelect(pView, pExpr->pLeft->x.pSelect, 0);
@@ -29401,12 +29985,13 @@
2940129985
}else{
2940229986
int i;
2940329987
sqlite3TreeViewLine(pView, "%s", zLabel);
2940429988
for(i=0; i<pList->nExpr; i++){
2940529989
int j = pList->a[i].u.x.iOrderByCol;
29406
- char *zName = pList->a[i].zName;
29990
+ char *zName = pList->a[i].zEName;
2940729991
int moreToFollow = i<pList->nExpr - 1;
29992
+ if( pList->a[i].eEName!=ENAME_NAME ) zName = 0;
2940829993
if( j || zName ){
2940929994
sqlite3TreeViewPush(pView, moreToFollow);
2941029995
moreToFollow = 0;
2941129996
sqlite3TreeViewLine(pView, 0);
2941229997
if( zName ){
@@ -30069,13 +30654,15 @@
3006930654
assert( pMem->enc!=0 );
3007030655
assert( pMem->n>=0 );
3007130656
3007230657
#if defined(TRANSLATE_TRACE) && defined(SQLITE_DEBUG)
3007330658
{
30074
- char zBuf[100];
30075
- sqlite3VdbeMemPrettyPrint(pMem, zBuf);
30076
- fprintf(stderr, "INPUT: %s\n", zBuf);
30659
+ StrAccum acc;
30660
+ char zBuf[1000];
30661
+ sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0);
30662
+ sqlite3VdbeMemPrettyPrint(pMem, &acc);
30663
+ fprintf(stderr, "INPUT: %s\n", sqlite3StrAccumFinish(&acc));
3007730664
}
3007830665
#endif
3007930666
3008030667
/* If the translation is between UTF-16 little and big endian, then
3008130668
** all that is required is to swap the byte order. This case is handled
@@ -30179,13 +30766,15 @@
3017930766
pMem->szMalloc = sqlite3DbMallocSize(pMem->db, pMem->z);
3018030767
3018130768
translate_out:
3018230769
#if defined(TRANSLATE_TRACE) && defined(SQLITE_DEBUG)
3018330770
{
30184
- char zBuf[100];
30185
- sqlite3VdbeMemPrettyPrint(pMem, zBuf);
30186
- fprintf(stderr, "OUTPUT: %s\n", zBuf);
30771
+ StrAccum acc;
30772
+ char zBuf[1000];
30773
+ sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0);
30774
+ sqlite3VdbeMemPrettyPrint(pMem, &acc);
30775
+ fprintf(stderr, "OUTPUT: %s\n", sqlite3StrAccumFinish(&acc));
3018730776
}
3018830777
#endif
3018930778
return SQLITE_OK;
3019030779
}
3019130780
#endif /* SQLITE_OMIT_UTF16 */
@@ -30406,11 +30995,13 @@
3040630995
** strings, and stuff like that.
3040730996
**
3040830997
*/
3040930998
/* #include "sqliteInt.h" */
3041030999
/* #include <stdarg.h> */
31000
+#ifndef SQLITE_OMIT_FLOATING_POINT
3041131001
#include <math.h>
31002
+#endif
3041231003
3041331004
/*
3041431005
** Routine needed to support the testcase() macro.
3041531006
*/
3041631007
#ifdef SQLITE_COVERAGE_TEST
@@ -30581,10 +31172,11 @@
3058131172
}else{
3058231173
pParse->nErr++;
3058331174
sqlite3DbFree(db, pParse->zErrMsg);
3058431175
pParse->zErrMsg = zMsg;
3058531176
pParse->rc = SQLITE_ERROR;
31177
+ pParse->pWith = 0;
3058631178
}
3058731179
}
3058831180
3058931181
/*
3059031182
** If database connection db is currently parsing SQL, then transfer
@@ -30771,14 +31363,17 @@
3077131363
**
3077231364
** If some prefix of the input string is a valid number, this routine
3077331365
** returns FALSE but it still converts the prefix and writes the result
3077431366
** into *pResult.
3077531367
*/
31368
+#if defined(_MSC_VER)
31369
+#pragma warning(disable : 4756)
31370
+#endif
3077631371
SQLITE_PRIVATE int sqlite3AtoF(const char *z, double *pResult, int length, u8 enc){
3077731372
#ifndef SQLITE_OMIT_FLOATING_POINT
3077831373
int incr;
30779
- const char *zEnd = z + length;
31374
+ const char *zEnd;
3078031375
/* sign * significand * (10 ^ (esign * exponent)) */
3078131376
int sign = 1; /* sign of significand */
3078231377
i64 s = 0; /* significand */
3078331378
int d = 0; /* adjust exponent for shifting decimal point */
3078431379
int esign = 1; /* sign of exponent */
@@ -30788,16 +31383,19 @@
3078831383
int nDigit = 0; /* Number of digits processed */
3078931384
int eType = 1; /* 1: pure integer, 2+: fractional -1 or less: bad UTF16 */
3079031385
3079131386
assert( enc==SQLITE_UTF8 || enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE );
3079231387
*pResult = 0.0; /* Default return value, in case of an error */
31388
+ if( length==0 ) return 0;
3079331389
3079431390
if( enc==SQLITE_UTF8 ){
3079531391
incr = 1;
31392
+ zEnd = z + length;
3079631393
}else{
3079731394
int i;
3079831395
incr = 2;
31396
+ length &= ~1;
3079931397
assert( SQLITE_UTF16LE==2 && SQLITE_UTF16BE==3 );
3080031398
testcase( enc==SQLITE_UTF16LE );
3080131399
testcase( enc==SQLITE_UTF16BE );
3080231400
for(i=3-enc; i<length && z[i]==0; i+=2){}
3080331401
if( i<length ) eType = -100;
@@ -30958,10 +31556,13 @@
3095831556
}
3095931557
#else
3096031558
return !sqlite3Atoi64(z, pResult, length, enc);
3096131559
#endif /* SQLITE_OMIT_FLOATING_POINT */
3096231560
}
31561
+#if defined(_MSC_VER)
31562
+#pragma warning(default : 4756)
31563
+#endif
3096331564
3096431565
/*
3096531566
** Compare the 19-character string zNum against the text representation
3096631567
** value 2^63: 9223372036854775808. Return negative, zero, or positive
3096731568
** if zNum is less than, equal to, or greater than the string.
@@ -32328,120 +32929,120 @@
3232832929
/* 21 */ "IfNullRow" OpHelp("if P1.nullRow then r[P3]=NULL, goto P2"),
3232932930
/* 22 */ "SeekLT" OpHelp("key=r[P3@P4]"),
3233032931
/* 23 */ "SeekLE" OpHelp("key=r[P3@P4]"),
3233132932
/* 24 */ "SeekGE" OpHelp("key=r[P3@P4]"),
3233232933
/* 25 */ "SeekGT" OpHelp("key=r[P3@P4]"),
32333
- /* 26 */ "IfNoHope" OpHelp("key=r[P3@P4]"),
32334
- /* 27 */ "NoConflict" OpHelp("key=r[P3@P4]"),
32335
- /* 28 */ "NotFound" OpHelp("key=r[P3@P4]"),
32336
- /* 29 */ "Found" OpHelp("key=r[P3@P4]"),
32337
- /* 30 */ "SeekRowid" OpHelp("intkey=r[P3]"),
32338
- /* 31 */ "NotExists" OpHelp("intkey=r[P3]"),
32339
- /* 32 */ "Last" OpHelp(""),
32340
- /* 33 */ "IfSmaller" OpHelp(""),
32341
- /* 34 */ "SorterSort" OpHelp(""),
32342
- /* 35 */ "Sort" OpHelp(""),
32343
- /* 36 */ "Rewind" OpHelp(""),
32344
- /* 37 */ "IdxLE" OpHelp("key=r[P3@P4]"),
32345
- /* 38 */ "IdxGT" OpHelp("key=r[P3@P4]"),
32346
- /* 39 */ "IdxLT" OpHelp("key=r[P3@P4]"),
32347
- /* 40 */ "IdxGE" OpHelp("key=r[P3@P4]"),
32348
- /* 41 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"),
32349
- /* 42 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
32934
+ /* 26 */ "IfNotOpen" OpHelp("if( !csr[P1] ) goto P2"),
32935
+ /* 27 */ "IfNoHope" OpHelp("key=r[P3@P4]"),
32936
+ /* 28 */ "NoConflict" OpHelp("key=r[P3@P4]"),
32937
+ /* 29 */ "NotFound" OpHelp("key=r[P3@P4]"),
32938
+ /* 30 */ "Found" OpHelp("key=r[P3@P4]"),
32939
+ /* 31 */ "SeekRowid" OpHelp("intkey=r[P3]"),
32940
+ /* 32 */ "NotExists" OpHelp("intkey=r[P3]"),
32941
+ /* 33 */ "Last" OpHelp(""),
32942
+ /* 34 */ "IfSmaller" OpHelp(""),
32943
+ /* 35 */ "SorterSort" OpHelp(""),
32944
+ /* 36 */ "Sort" OpHelp(""),
32945
+ /* 37 */ "Rewind" OpHelp(""),
32946
+ /* 38 */ "IdxLE" OpHelp("key=r[P3@P4]"),
32947
+ /* 39 */ "IdxGT" OpHelp("key=r[P3@P4]"),
32948
+ /* 40 */ "IdxLT" OpHelp("key=r[P3@P4]"),
32949
+ /* 41 */ "IdxGE" OpHelp("key=r[P3@P4]"),
32950
+ /* 42 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"),
3235032951
/* 43 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"),
3235132952
/* 44 */ "And" OpHelp("r[P3]=(r[P1] && r[P2])"),
32352
- /* 45 */ "Program" OpHelp(""),
32353
- /* 46 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
32354
- /* 47 */ "IfPos" OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"),
32355
- /* 48 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]--, goto P2"),
32356
- /* 49 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"),
32953
+ /* 45 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
32954
+ /* 46 */ "Program" OpHelp(""),
32955
+ /* 47 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
32956
+ /* 48 */ "IfPos" OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"),
32957
+ /* 49 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]--, goto P2"),
3235732958
/* 50 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"),
3235832959
/* 51 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"),
3235932960
/* 52 */ "Ne" OpHelp("IF r[P3]!=r[P1]"),
3236032961
/* 53 */ "Eq" OpHelp("IF r[P3]==r[P1]"),
3236132962
/* 54 */ "Gt" OpHelp("IF r[P3]>r[P1]"),
3236232963
/* 55 */ "Le" OpHelp("IF r[P3]<=r[P1]"),
3236332964
/* 56 */ "Lt" OpHelp("IF r[P3]<r[P1]"),
3236432965
/* 57 */ "Ge" OpHelp("IF r[P3]>=r[P1]"),
3236532966
/* 58 */ "ElseNotEq" OpHelp(""),
32366
- /* 59 */ "IncrVacuum" OpHelp(""),
32367
- /* 60 */ "VNext" OpHelp(""),
32368
- /* 61 */ "Init" OpHelp("Start at P2"),
32369
- /* 62 */ "PureFunc0" OpHelp(""),
32370
- /* 63 */ "Function0" OpHelp("r[P3]=func(r[P2@P5])"),
32371
- /* 64 */ "PureFunc" OpHelp(""),
32372
- /* 65 */ "Function" OpHelp("r[P3]=func(r[P2@P5])"),
32373
- /* 66 */ "Return" OpHelp(""),
32374
- /* 67 */ "EndCoroutine" OpHelp(""),
32375
- /* 68 */ "HaltIfNull" OpHelp("if r[P3]=null halt"),
32376
- /* 69 */ "Halt" OpHelp(""),
32377
- /* 70 */ "Integer" OpHelp("r[P2]=P1"),
32378
- /* 71 */ "Int64" OpHelp("r[P2]=P4"),
32379
- /* 72 */ "String" OpHelp("r[P2]='P4' (len=P1)"),
32380
- /* 73 */ "Null" OpHelp("r[P2..P3]=NULL"),
32381
- /* 74 */ "SoftNull" OpHelp("r[P1]=NULL"),
32382
- /* 75 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"),
32383
- /* 76 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"),
32384
- /* 77 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"),
32385
- /* 78 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"),
32386
- /* 79 */ "SCopy" OpHelp("r[P2]=r[P1]"),
32387
- /* 80 */ "IntCopy" OpHelp("r[P2]=r[P1]"),
32388
- /* 81 */ "ResultRow" OpHelp("output=r[P1@P2]"),
32389
- /* 82 */ "CollSeq" OpHelp(""),
32390
- /* 83 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"),
32391
- /* 84 */ "RealAffinity" OpHelp(""),
32392
- /* 85 */ "Cast" OpHelp("affinity(r[P1])"),
32393
- /* 86 */ "Permutation" OpHelp(""),
32394
- /* 87 */ "Compare" OpHelp("r[P1@P3] <-> r[P2@P3]"),
32395
- /* 88 */ "IsTrue" OpHelp("r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4"),
32396
- /* 89 */ "Offset" OpHelp("r[P3] = sqlite_offset(P1)"),
32397
- /* 90 */ "Column" OpHelp("r[P3]=PX"),
32398
- /* 91 */ "Affinity" OpHelp("affinity(r[P1@P2])"),
32399
- /* 92 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"),
32400
- /* 93 */ "Count" OpHelp("r[P2]=count()"),
32401
- /* 94 */ "ReadCookie" OpHelp(""),
32402
- /* 95 */ "SetCookie" OpHelp(""),
32403
- /* 96 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"),
32404
- /* 97 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
32405
- /* 98 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
32406
- /* 99 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"),
32407
- /* 100 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"),
32408
- /* 101 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"),
32409
- /* 102 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"),
32410
- /* 103 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"),
32411
- /* 104 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"),
32412
- /* 105 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"),
32413
- /* 106 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"),
32414
- /* 107 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"),
32415
- /* 108 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
32416
- /* 109 */ "OpenDup" OpHelp(""),
32417
- /* 110 */ "BitNot" OpHelp("r[P2]= ~r[P1]"),
32418
- /* 111 */ "OpenAutoindex" OpHelp("nColumn=P2"),
32419
- /* 112 */ "OpenEphemeral" OpHelp("nColumn=P2"),
32420
- /* 113 */ "String8" OpHelp("r[P2]='P4'"),
32421
- /* 114 */ "SorterOpen" OpHelp(""),
32422
- /* 115 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"),
32423
- /* 116 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"),
32424
- /* 117 */ "Close" OpHelp(""),
32425
- /* 118 */ "ColumnsUsed" OpHelp(""),
32426
- /* 119 */ "SeekHit" OpHelp("seekHit=P2"),
32427
- /* 120 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"),
32428
- /* 121 */ "NewRowid" OpHelp("r[P2]=rowid"),
32429
- /* 122 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
32430
- /* 123 */ "Delete" OpHelp(""),
32431
- /* 124 */ "ResetCount" OpHelp(""),
32432
- /* 125 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
32433
- /* 126 */ "SorterData" OpHelp("r[P2]=data"),
32434
- /* 127 */ "RowData" OpHelp("r[P2]=data"),
32435
- /* 128 */ "Rowid" OpHelp("r[P2]=rowid"),
32436
- /* 129 */ "NullRow" OpHelp(""),
32437
- /* 130 */ "SeekEnd" OpHelp(""),
32438
- /* 131 */ "SorterInsert" OpHelp("key=r[P2]"),
32439
- /* 132 */ "IdxInsert" OpHelp("key=r[P2]"),
32440
- /* 133 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
32441
- /* 134 */ "DeferredSeek" OpHelp("Move P3 to P1.rowid if needed"),
32442
- /* 135 */ "IdxRowid" OpHelp("r[P2]=rowid"),
32967
+ /* 59 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"),
32968
+ /* 60 */ "IncrVacuum" OpHelp(""),
32969
+ /* 61 */ "VNext" OpHelp(""),
32970
+ /* 62 */ "Init" OpHelp("Start at P2"),
32971
+ /* 63 */ "PureFunc" OpHelp("r[P3]=func(r[P2@P5])"),
32972
+ /* 64 */ "Function" OpHelp("r[P3]=func(r[P2@P5])"),
32973
+ /* 65 */ "Return" OpHelp(""),
32974
+ /* 66 */ "EndCoroutine" OpHelp(""),
32975
+ /* 67 */ "HaltIfNull" OpHelp("if r[P3]=null halt"),
32976
+ /* 68 */ "Halt" OpHelp(""),
32977
+ /* 69 */ "Integer" OpHelp("r[P2]=P1"),
32978
+ /* 70 */ "Int64" OpHelp("r[P2]=P4"),
32979
+ /* 71 */ "String" OpHelp("r[P2]='P4' (len=P1)"),
32980
+ /* 72 */ "Null" OpHelp("r[P2..P3]=NULL"),
32981
+ /* 73 */ "SoftNull" OpHelp("r[P1]=NULL"),
32982
+ /* 74 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"),
32983
+ /* 75 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"),
32984
+ /* 76 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"),
32985
+ /* 77 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"),
32986
+ /* 78 */ "SCopy" OpHelp("r[P2]=r[P1]"),
32987
+ /* 79 */ "IntCopy" OpHelp("r[P2]=r[P1]"),
32988
+ /* 80 */ "ResultRow" OpHelp("output=r[P1@P2]"),
32989
+ /* 81 */ "CollSeq" OpHelp(""),
32990
+ /* 82 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"),
32991
+ /* 83 */ "RealAffinity" OpHelp(""),
32992
+ /* 84 */ "Cast" OpHelp("affinity(r[P1])"),
32993
+ /* 85 */ "Permutation" OpHelp(""),
32994
+ /* 86 */ "Compare" OpHelp("r[P1@P3] <-> r[P2@P3]"),
32995
+ /* 87 */ "IsTrue" OpHelp("r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4"),
32996
+ /* 88 */ "Offset" OpHelp("r[P3] = sqlite_offset(P1)"),
32997
+ /* 89 */ "Column" OpHelp("r[P3]=PX"),
32998
+ /* 90 */ "Affinity" OpHelp("affinity(r[P1@P2])"),
32999
+ /* 91 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"),
33000
+ /* 92 */ "Count" OpHelp("r[P2]=count()"),
33001
+ /* 93 */ "ReadCookie" OpHelp(""),
33002
+ /* 94 */ "SetCookie" OpHelp(""),
33003
+ /* 95 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"),
33004
+ /* 96 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
33005
+ /* 97 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
33006
+ /* 98 */ "OpenDup" OpHelp(""),
33007
+ /* 99 */ "OpenAutoindex" OpHelp("nColumn=P2"),
33008
+ /* 100 */ "OpenEphemeral" OpHelp("nColumn=P2"),
33009
+ /* 101 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"),
33010
+ /* 102 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"),
33011
+ /* 103 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"),
33012
+ /* 104 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"),
33013
+ /* 105 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"),
33014
+ /* 106 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"),
33015
+ /* 107 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"),
33016
+ /* 108 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"),
33017
+ /* 109 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"),
33018
+ /* 110 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
33019
+ /* 111 */ "SorterOpen" OpHelp(""),
33020
+ /* 112 */ "BitNot" OpHelp("r[P2]= ~r[P1]"),
33021
+ /* 113 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"),
33022
+ /* 114 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"),
33023
+ /* 115 */ "String8" OpHelp("r[P2]='P4'"),
33024
+ /* 116 */ "Close" OpHelp(""),
33025
+ /* 117 */ "ColumnsUsed" OpHelp(""),
33026
+ /* 118 */ "SeekHit" OpHelp("seekHit=P2"),
33027
+ /* 119 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"),
33028
+ /* 120 */ "NewRowid" OpHelp("r[P2]=rowid"),
33029
+ /* 121 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
33030
+ /* 122 */ "Delete" OpHelp(""),
33031
+ /* 123 */ "ResetCount" OpHelp(""),
33032
+ /* 124 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
33033
+ /* 125 */ "SorterData" OpHelp("r[P2]=data"),
33034
+ /* 126 */ "RowData" OpHelp("r[P2]=data"),
33035
+ /* 127 */ "Rowid" OpHelp("r[P2]=rowid"),
33036
+ /* 128 */ "NullRow" OpHelp(""),
33037
+ /* 129 */ "SeekEnd" OpHelp(""),
33038
+ /* 130 */ "SorterInsert" OpHelp("key=r[P2]"),
33039
+ /* 131 */ "IdxInsert" OpHelp("key=r[P2]"),
33040
+ /* 132 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
33041
+ /* 133 */ "DeferredSeek" OpHelp("Move P3 to P1.rowid if needed"),
33042
+ /* 134 */ "IdxRowid" OpHelp("r[P2]=rowid"),
33043
+ /* 135 */ "FinishSeek" OpHelp(""),
3244333044
/* 136 */ "Destroy" OpHelp(""),
3244433045
/* 137 */ "Clear" OpHelp(""),
3244533046
/* 138 */ "ResetSorter" OpHelp(""),
3244633047
/* 139 */ "CreateBtree" OpHelp("r[P2]=root iDb=P1 flags=P3"),
3244733048
/* 140 */ "SqlExec" OpHelp(""),
@@ -32450,35 +33051,38 @@
3245033051
/* 143 */ "DropTable" OpHelp(""),
3245133052
/* 144 */ "DropIndex" OpHelp(""),
3245233053
/* 145 */ "DropTrigger" OpHelp(""),
3245333054
/* 146 */ "IntegrityCk" OpHelp(""),
3245433055
/* 147 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
32455
- /* 148 */ "Real" OpHelp("r[P2]=P4"),
32456
- /* 149 */ "Param" OpHelp(""),
32457
- /* 150 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
33056
+ /* 148 */ "Param" OpHelp(""),
33057
+ /* 149 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
33058
+ /* 150 */ "Real" OpHelp("r[P2]=P4"),
3245833059
/* 151 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
3245933060
/* 152 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"),
3246033061
/* 153 */ "AggInverse" OpHelp("accum=r[P3] inverse(r[P2@P5])"),
3246133062
/* 154 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"),
3246233063
/* 155 */ "AggStep1" OpHelp("accum=r[P3] step(r[P2@P5])"),
3246333064
/* 156 */ "AggValue" OpHelp("r[P3]=value N=P2"),
3246433065
/* 157 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
3246533066
/* 158 */ "Expire" OpHelp(""),
32466
- /* 159 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
32467
- /* 160 */ "VBegin" OpHelp(""),
32468
- /* 161 */ "VCreate" OpHelp(""),
32469
- /* 162 */ "VDestroy" OpHelp(""),
32470
- /* 163 */ "VOpen" OpHelp(""),
32471
- /* 164 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
32472
- /* 165 */ "VRename" OpHelp(""),
32473
- /* 166 */ "Pagecount" OpHelp(""),
32474
- /* 167 */ "MaxPgcnt" OpHelp(""),
32475
- /* 168 */ "Trace" OpHelp(""),
32476
- /* 169 */ "CursorHint" OpHelp(""),
32477
- /* 170 */ "Noop" OpHelp(""),
32478
- /* 171 */ "Explain" OpHelp(""),
32479
- /* 172 */ "Abortable" OpHelp(""),
33067
+ /* 159 */ "CursorLock" OpHelp(""),
33068
+ /* 160 */ "CursorUnlock" OpHelp(""),
33069
+ /* 161 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
33070
+ /* 162 */ "VBegin" OpHelp(""),
33071
+ /* 163 */ "VCreate" OpHelp(""),
33072
+ /* 164 */ "VDestroy" OpHelp(""),
33073
+ /* 165 */ "VOpen" OpHelp(""),
33074
+ /* 166 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
33075
+ /* 167 */ "VRename" OpHelp(""),
33076
+ /* 168 */ "Pagecount" OpHelp(""),
33077
+ /* 169 */ "MaxPgcnt" OpHelp(""),
33078
+ /* 170 */ "Trace" OpHelp(""),
33079
+ /* 171 */ "CursorHint" OpHelp(""),
33080
+ /* 172 */ "ReleaseReg" OpHelp("release r[P1@P2] mask P3"),
33081
+ /* 173 */ "Noop" OpHelp(""),
33082
+ /* 174 */ "Explain" OpHelp(""),
33083
+ /* 175 */ "Abortable" OpHelp(""),
3248033084
};
3248133085
return azName[i];
3248233086
}
3248333087
#endif
3248433088
@@ -32838,11 +33442,11 @@
3283833442
** May you share freely, never taking more than you give.
3283933443
**
3284033444
******************************************************************************
3284133445
**
3284233446
** This file contains inline asm code for retrieving "high-performance"
32843
-** counters for x86 class CPUs.
33447
+** counters for x86 and x86_64 class CPUs.
3284433448
*/
3284533449
#ifndef SQLITE_HWTIME_H
3284633450
#define SQLITE_HWTIME_H
3284733451
3284833452
/*
@@ -32849,12 +33453,13 @@
3284933453
** The following routine only works on pentium-class (or newer) processors.
3285033454
** It uses the RDTSC opcode to read the cycle count value out of the
3285133455
** processor and returns that value. This can be used for high-res
3285233456
** profiling.
3285333457
*/
32854
-#if (defined(__GNUC__) || defined(_MSC_VER)) && \
32855
- (defined(i386) || defined(__i386__) || defined(_M_IX86))
33458
+#if !defined(__STRICT_ANSI__) && \
33459
+ (defined(__GNUC__) || defined(_MSC_VER)) && \
33460
+ (defined(i386) || defined(__i386__) || defined(_M_IX86))
3285633461
3285733462
#if defined(__GNUC__)
3285833463
3285933464
__inline__ sqlite_uint64 sqlite3Hwtime(void){
3286033465
unsigned int lo, hi;
@@ -32871,19 +33476,19 @@
3287133476
}
3287233477
}
3287333478
3287433479
#endif
3287533480
32876
-#elif (defined(__GNUC__) && defined(__x86_64__))
33481
+#elif !defined(__STRICT_ANSI__) && (defined(__GNUC__) && defined(__x86_64__))
3287733482
3287833483
__inline__ sqlite_uint64 sqlite3Hwtime(void){
3287933484
unsigned long val;
3288033485
__asm__ __volatile__ ("rdtsc" : "=A" (val));
3288133486
return val;
3288233487
}
3288333488
32884
-#elif (defined(__GNUC__) && defined(__ppc__))
33489
+#elif !defined(__STRICT_ANSI__) && (defined(__GNUC__) && defined(__ppc__))
3288533490
3288633491
__inline__ sqlite_uint64 sqlite3Hwtime(void){
3288733492
unsigned long long retval;
3288833493
unsigned long junk;
3288933494
__asm__ __volatile__ ("\n\
@@ -32896,18 +33501,17 @@
3289633501
return retval;
3289733502
}
3289833503
3289933504
#else
3290033505
32901
- #error Need implementation of sqlite3Hwtime() for your platform.
32902
-
3290333506
/*
32904
- ** To compile without implementing sqlite3Hwtime() for your platform,
32905
- ** you can remove the above #error and use the following
32906
- ** stub function. You will lose timing support for many
32907
- ** of the debugging and testing utilities, but it should at
32908
- ** least compile and run.
33507
+ ** asm() is needed for hardware timing support. Without asm(),
33508
+ ** disable the sqlite3Hwtime() routine.
33509
+ **
33510
+ ** sqlite3Hwtime() is only used for some obscure debugging
33511
+ ** and analysis configurations, not in any deliverable, so this
33512
+ ** should not be a great loss.
3290933513
*/
3291033514
SQLITE_PRIVATE sqlite_uint64 sqlite3Hwtime(void){ return ((sqlite_uint64)0); }
3291133515
3291233516
#endif
3291333517
@@ -36367,11 +36971,11 @@
3636736971
zDirname[ii] = '\0';
3636836972
}else{
3636936973
if( zDirname[0]!='/' ) zDirname[0] = '.';
3637036974
zDirname[1] = 0;
3637136975
}
36372
- fd = robust_open(zDirname, O_RDONLY|O_BINARY, 0);
36976
+ fd = robust_open(zDirname, O_RDONLY|O_BINARY|O_NOFOLLOW, 0);
3637336977
if( fd>=0 ){
3637436978
OSTRACE(("OPENDIR %-3d %s\n", fd, zDirname));
3637536979
}
3637636980
*pFd = fd;
3637736981
if( fd>=0 ) return SQLITE_OK;
@@ -37258,14 +37862,16 @@
3725837862
}
3725937863
}
3726037864
3726137865
if( pInode->bProcessLock==0 ){
3726237866
if( 0==sqlite3_uri_boolean(pDbFd->zPath, "readonly_shm", 0) ){
37263
- pShmNode->hShm = robust_open(zShm, O_RDWR|O_CREAT,(sStat.st_mode&0777));
37867
+ pShmNode->hShm = robust_open(zShm, O_RDWR|O_CREAT|O_NOFOLLOW,
37868
+ (sStat.st_mode&0777));
3726437869
}
3726537870
if( pShmNode->hShm<0 ){
37266
- pShmNode->hShm = robust_open(zShm, O_RDONLY, (sStat.st_mode&0777));
37871
+ pShmNode->hShm = robust_open(zShm, O_RDONLY|O_NOFOLLOW,
37872
+ (sStat.st_mode&0777));
3726737873
if( pShmNode->hShm<0 ){
3726837874
rc = unixLogError(SQLITE_CANTOPEN_BKPT, "open", zShm);
3726937875
goto shm_open_err;
3727037876
}
3727137877
pShmNode->isReadonly = 1;
@@ -38611,11 +39217,11 @@
3861139217
int *pOutFlags /* Output flags returned to SQLite core */
3861239218
){
3861339219
unixFile *p = (unixFile *)pFile;
3861439220
int fd = -1; /* File descriptor returned by open() */
3861539221
int openFlags = 0; /* Flags to pass to open() */
38616
- int eType = flags&0xFFFFFF00; /* Type of file to open */
39222
+ int eType = flags&0x0FFF00; /* Type of file to open */
3861739223
int noLock; /* True to omit locking primitives */
3861839224
int rc = SQLITE_OK; /* Function Return Code */
3861939225
int ctrlFlags = 0; /* UNIXFILE_* flags */
3862039226
3862139227
int isExclusive = (flags & SQLITE_OPEN_EXCLUSIVE);
@@ -38721,11 +39327,11 @@
3872139327
** 'conch file' locking functions later on. */
3872239328
if( isReadonly ) openFlags |= O_RDONLY;
3872339329
if( isReadWrite ) openFlags |= O_RDWR;
3872439330
if( isCreate ) openFlags |= O_CREAT;
3872539331
if( isExclusive ) openFlags |= (O_EXCL|O_NOFOLLOW);
38726
- openFlags |= (O_LARGEFILE|O_BINARY);
39332
+ openFlags |= (O_LARGEFILE|O_BINARY|O_NOFOLLOW);
3872739333
3872839334
if( fd<0 ){
3872939335
mode_t openMode; /* Permissions to create file with */
3873039336
uid_t uid; /* Userid for the file */
3873139337
gid_t gid; /* Groupid for the file */
@@ -38939,11 +39545,12 @@
3893939545
** two of them are actually used */
3894039546
assert( flags==SQLITE_ACCESS_EXISTS || flags==SQLITE_ACCESS_READWRITE );
3894139547
3894239548
if( flags==SQLITE_ACCESS_EXISTS ){
3894339549
struct stat buf;
38944
- *pResOut = (0==osStat(zPath, &buf) && buf.st_size>0);
39550
+ *pResOut = 0==osStat(zPath, &buf) &&
39551
+ (!S_ISREG(buf.st_mode) || buf.st_size>0);
3894539552
}else{
3894639553
*pResOut = osAccess(zPath, W_OK|R_OK)==0;
3894739554
}
3894839555
return SQLITE_OK;
3894939556
}
@@ -38993,11 +39600,11 @@
3899339600
#if !defined(HAVE_READLINK) || !defined(HAVE_LSTAT)
3899439601
return mkFullPathname(zPath, zOut, nOut);
3899539602
#else
3899639603
int rc = SQLITE_OK;
3899739604
int nByte;
38998
- int nLink = 1; /* Number of symbolic links followed so far */
39605
+ int nLink = 0; /* Number of symbolic links followed so far */
3899939606
const char *zIn = zPath; /* Input path for each iteration of loop */
3900039607
char *zDel = 0;
3900139608
3900239609
assert( pVfs->mxPathname==MAX_PATHNAME );
3900339610
UNUSED_PARAMETER(pVfs);
@@ -39022,14 +39629,15 @@
3902239629
}else{
3902339630
bLink = S_ISLNK(buf.st_mode);
3902439631
}
3902539632
3902639633
if( bLink ){
39634
+ nLink++;
3902739635
if( zDel==0 ){
3902839636
zDel = sqlite3_malloc(nOut);
3902939637
if( zDel==0 ) rc = SQLITE_NOMEM_BKPT;
39030
- }else if( ++nLink>SQLITE_MAX_SYMLINKS ){
39638
+ }else if( nLink>=SQLITE_MAX_SYMLINKS ){
3903139639
rc = SQLITE_CANTOPEN_BKPT;
3903239640
}
3903339641
3903439642
if( rc==SQLITE_OK ){
3903539643
nByte = osReadlink(zIn, zDel, nOut-1);
@@ -39061,10 +39669,11 @@
3906139669
if( bLink==0 ) break;
3906239670
zIn = zOut;
3906339671
}while( rc==SQLITE_OK );
3906439672
3906539673
sqlite3_free(zDel);
39674
+ if( rc==SQLITE_OK && nLink ) rc = SQLITE_OK_SYMLINK;
3906639675
return rc;
3906739676
#endif /* HAVE_READLINK && HAVE_LSTAT */
3906839677
}
3906939678
3907039679
@@ -39546,11 +40155,11 @@
3954640155
int islockfile /* if non zero missing dirs will be created */
3954740156
) {
3954840157
int fd = -1;
3954940158
unixFile *pNew;
3955040159
int rc = SQLITE_OK;
39551
- int openFlags = O_RDWR | O_CREAT;
40160
+ int openFlags = O_RDWR | O_CREAT | O_NOFOLLOW;
3955240161
sqlite3_vfs dummyVfs;
3955340162
int terrno = 0;
3955440163
UnixUnusedFd *pUnused = NULL;
3955540164
3955640165
/* 1. first try to open/create the file
@@ -39576,11 +40185,11 @@
3957640185
fd = robust_open(path, openFlags, 0);
3957740186
}
3957840187
}
3957940188
}
3958040189
if( fd<0 ){
39581
- openFlags = O_RDONLY;
40190
+ openFlags = O_RDONLY | O_NOFOLLOW;
3958240191
fd = robust_open(path, openFlags, 0);
3958340192
terrno = errno;
3958440193
}
3958540194
if( fd<0 ){
3958640195
if( islockfile ){
@@ -39702,11 +40311,11 @@
3970240311
if( readLen<PROXY_PATHINDEX ){
3970340312
sqlite3_snprintf(sizeof(errmsg),errmsg,"read error (len %d)",(int)readLen);
3970440313
goto end_breaklock;
3970540314
}
3970640315
/* write it out to the temporary break file */
39707
- fd = robust_open(tPath, (O_RDWR|O_CREAT|O_EXCL), 0);
40316
+ fd = robust_open(tPath, (O_RDWR|O_CREAT|O_EXCL|O_NOFOLLOW), 0);
3970840317
if( fd<0 ){
3970940318
sqlite3_snprintf(sizeof(errmsg), errmsg, "create failed (%d)", errno);
3971040319
goto end_breaklock;
3971140320
}
3971240321
if( osPwrite(fd, buf, readLen, 0) != (ssize_t)readLen ){
@@ -40660,11 +41269,11 @@
4066041269
** May you share freely, never taking more than you give.
4066141270
**
4066241271
******************************************************************************
4066341272
**
4066441273
** This file contains inline asm code for retrieving "high-performance"
40665
-** counters for x86 class CPUs.
41274
+** counters for x86 and x86_64 class CPUs.
4066641275
*/
4066741276
#ifndef SQLITE_HWTIME_H
4066841277
#define SQLITE_HWTIME_H
4066941278
4067041279
/*
@@ -40671,12 +41280,13 @@
4067141280
** The following routine only works on pentium-class (or newer) processors.
4067241281
** It uses the RDTSC opcode to read the cycle count value out of the
4067341282
** processor and returns that value. This can be used for high-res
4067441283
** profiling.
4067541284
*/
40676
-#if (defined(__GNUC__) || defined(_MSC_VER)) && \
40677
- (defined(i386) || defined(__i386__) || defined(_M_IX86))
41285
+#if !defined(__STRICT_ANSI__) && \
41286
+ (defined(__GNUC__) || defined(_MSC_VER)) && \
41287
+ (defined(i386) || defined(__i386__) || defined(_M_IX86))
4067841288
4067941289
#if defined(__GNUC__)
4068041290
4068141291
__inline__ sqlite_uint64 sqlite3Hwtime(void){
4068241292
unsigned int lo, hi;
@@ -40693,19 +41303,19 @@
4069341303
}
4069441304
}
4069541305
4069641306
#endif
4069741307
40698
-#elif (defined(__GNUC__) && defined(__x86_64__))
41308
+#elif !defined(__STRICT_ANSI__) && (defined(__GNUC__) && defined(__x86_64__))
4069941309
4070041310
__inline__ sqlite_uint64 sqlite3Hwtime(void){
4070141311
unsigned long val;
4070241312
__asm__ __volatile__ ("rdtsc" : "=A" (val));
4070341313
return val;
4070441314
}
4070541315
40706
-#elif (defined(__GNUC__) && defined(__ppc__))
41316
+#elif !defined(__STRICT_ANSI__) && (defined(__GNUC__) && defined(__ppc__))
4070741317
4070841318
__inline__ sqlite_uint64 sqlite3Hwtime(void){
4070941319
unsigned long long retval;
4071041320
unsigned long junk;
4071141321
__asm__ __volatile__ ("\n\
@@ -40718,18 +41328,17 @@
4071841328
return retval;
4071941329
}
4072041330
4072141331
#else
4072241332
40723
- #error Need implementation of sqlite3Hwtime() for your platform.
40724
-
4072541333
/*
40726
- ** To compile without implementing sqlite3Hwtime() for your platform,
40727
- ** you can remove the above #error and use the following
40728
- ** stub function. You will lose timing support for many
40729
- ** of the debugging and testing utilities, but it should at
40730
- ** least compile and run.
41334
+ ** asm() is needed for hardware timing support. Without asm(),
41335
+ ** disable the sqlite3Hwtime() routine.
41336
+ **
41337
+ ** sqlite3Hwtime() is only used for some obscure debugging
41338
+ ** and analysis configurations, not in any deliverable, so this
41339
+ ** should not be a great loss.
4073141340
*/
4073241341
SQLITE_PRIVATE sqlite_uint64 sqlite3Hwtime(void){ return ((sqlite_uint64)0); }
4073341342
4073441343
#endif
4073541344
@@ -49293,17 +49902,19 @@
4929349902
sqlite3_free(p);
4929449903
pPg = 0;
4929549904
}
4929649905
#else
4929749906
pPg = pcache1Alloc(pCache->szAlloc);
49298
- p = (PgHdr1 *)&((u8 *)pPg)[pCache->szPage];
4929949907
#endif
4930049908
if( benignMalloc ){ sqlite3EndBenignMalloc(); }
4930149909
#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
4930249910
pcache1EnterMutex(pCache->pGroup);
4930349911
#endif
4930449912
if( pPg==0 ) return 0;
49913
+#ifndef SQLITE_PCACHE_SEPARATE_HEADER
49914
+ p = (PgHdr1 *)&((u8 *)pPg)[pCache->szPage];
49915
+#endif
4930549916
p->page.pBuf = pPg;
4930649917
p->page.pExtra = &p[1];
4930749918
p->isBulkLocal = 0;
4930849919
p->isAnchor = 0;
4930949920
}
@@ -51954,10 +52565,11 @@
5195452565
if( pPager->eLock!=UNKNOWN_LOCK ){
5195552566
pPager->eLock = (u8)eLock;
5195652567
}
5195752568
IOTRACE(("UNLOCK %p %d\n", pPager, eLock))
5195852569
}
52570
+ pPager->changeCountDone = pPager->tempFile; /* ticket fb3b3024ea238d5c */
5195952571
return rc;
5196052572
}
5196152573
5196252574
/*
5196352575
** Lock the database file to level eLock, which must be either SHARED_LOCK,
@@ -52141,10 +52753,11 @@
5214152753
** master-journal filename.
5214252754
*/
5214352755
len = 0;
5214452756
}
5214552757
zMaster[len] = '\0';
52758
+ zMaster[len+1] = '\0';
5214652759
5214752760
return SQLITE_OK;
5214852761
}
5214952762
5215052763
/*
@@ -52674,11 +53287,10 @@
5267453287
/* The pager state may be changed from PAGER_ERROR to PAGER_OPEN here
5267553288
** without clearing the error code. This is intentional - the error
5267653289
** code is cleared and the cache reset in the block below.
5267753290
*/
5267853291
assert( pPager->errCode || pPager->eState!=PAGER_ERROR );
52679
- pPager->changeCountDone = 0;
5268053292
pPager->eState = PAGER_OPEN;
5268153293
}
5268253294
5268353295
/* If Pager.errCode is set, the contents of the pager cache cannot be
5268453296
** trusted. Now that there are no outstanding references to the pager,
@@ -52938,11 +53550,10 @@
5293853550
5293953551
if( !pPager->exclusiveMode
5294053552
&& (!pagerUseWal(pPager) || sqlite3WalExclusiveMode(pPager->pWal, 0))
5294153553
){
5294253554
rc2 = pagerUnlockDb(pPager, SHARED_LOCK);
52943
- pPager->changeCountDone = 0;
5294453555
}
5294553556
pPager->eState = PAGER_READER;
5294653557
pPager->setMaster = 0;
5294753558
5294853559
return (rc==SQLITE_OK?rc2:rc);
@@ -53377,19 +53988,20 @@
5337753988
** journal files extracted from regular rollback-journals.
5337853989
*/
5337953990
rc = sqlite3OsFileSize(pMaster, &nMasterJournal);
5338053991
if( rc!=SQLITE_OK ) goto delmaster_out;
5338153992
nMasterPtr = pVfs->mxPathname+1;
53382
- zMasterJournal = sqlite3Malloc(nMasterJournal + nMasterPtr + 1);
53993
+ zMasterJournal = sqlite3Malloc(nMasterJournal + nMasterPtr + 2);
5338353994
if( !zMasterJournal ){
5338453995
rc = SQLITE_NOMEM_BKPT;
5338553996
goto delmaster_out;
5338653997
}
53387
- zMasterPtr = &zMasterJournal[nMasterJournal+1];
53998
+ zMasterPtr = &zMasterJournal[nMasterJournal+2];
5338853999
rc = sqlite3OsRead(pMaster, zMasterJournal, (int)nMasterJournal, 0);
5338954000
if( rc!=SQLITE_OK ) goto delmaster_out;
5339054001
zMasterJournal[nMasterJournal] = 0;
54002
+ zMasterJournal[nMasterJournal+1] = 0;
5339154003
5339254004
zJournal = zMasterJournal;
5339354005
while( (zJournal-zMasterJournal)<nMasterJournal ){
5339454006
int exists;
5339554007
rc = sqlite3OsAccess(pVfs, zJournal, SQLITE_ACCESS_EXISTS, &exists);
@@ -55542,11 +56154,12 @@
5554256154
int nPathname = 0; /* Number of bytes in zPathname */
5554356155
int useJournal = (flags & PAGER_OMIT_JOURNAL)==0; /* False to omit journal */
5554456156
int pcacheSize = sqlite3PcacheSize(); /* Bytes to allocate for PCache */
5554556157
u32 szPageDflt = SQLITE_DEFAULT_PAGE_SIZE; /* Default page size */
5554656158
const char *zUri = 0; /* URI args to copy */
55547
- int nUri = 0; /* Number of bytes of URI args at *zUri */
56159
+ int nUriByte = 1; /* Number of bytes of URI args at *zUri */
56160
+ int nUri = 0; /* Number of URI parameters */
5554856161
5554956162
/* Figure out how much space is required for each journal file-handle
5555056163
** (there are two of them, the main journal and the sub-journal). */
5555156164
journalFileSize = ROUND8(sqlite3JournalSize(pVfs));
5555256165
@@ -55576,18 +56189,28 @@
5557656189
if( zPathname==0 ){
5557756190
return SQLITE_NOMEM_BKPT;
5557856191
}
5557956192
zPathname[0] = 0; /* Make sure initialized even if FullPathname() fails */
5558056193
rc = sqlite3OsFullPathname(pVfs, zFilename, nPathname, zPathname);
56194
+ if( rc!=SQLITE_OK ){
56195
+ if( rc==SQLITE_OK_SYMLINK ){
56196
+ if( vfsFlags & SQLITE_OPEN_NOFOLLOW ){
56197
+ rc = SQLITE_CANTOPEN_SYMLINK;
56198
+ }else{
56199
+ rc = SQLITE_OK;
56200
+ }
56201
+ }
56202
+ }
5558156203
nPathname = sqlite3Strlen30(zPathname);
5558256204
z = zUri = &zFilename[sqlite3Strlen30(zFilename)+1];
5558356205
while( *z ){
55584
- z += sqlite3Strlen30(z)+1;
55585
- z += sqlite3Strlen30(z)+1;
56206
+ z += strlen(z)+1;
56207
+ z += strlen(z)+1;
56208
+ nUri++;
5558656209
}
55587
- nUri = (int)(&z[1] - zUri);
55588
- assert( nUri>=0 );
56210
+ nUriByte = (int)(&z[1] - zUri);
56211
+ assert( nUriByte>=1 );
5558956212
if( rc==SQLITE_OK && nPathname+8>pVfs->mxPathname ){
5559056213
/* This branch is taken when the journal path required by
5559156214
** the database being opened will be more than pVfs->mxPathname
5559256215
** bytes in length. This means the database cannot be opened,
5559356216
** as it will not be possible to open the journal file or even
@@ -55608,54 +56231,107 @@
5560856231
** Pager object (sizeof(Pager) bytes)
5560956232
** PCache object (sqlite3PcacheSize() bytes)
5561056233
** Database file handle (pVfs->szOsFile bytes)
5561156234
** Sub-journal file handle (journalFileSize bytes)
5561256235
** Main journal file handle (journalFileSize bytes)
56236
+ ** \0\0\0\0 database prefix (4 bytes)
5561356237
** Database file name (nPathname+1 bytes)
55614
- ** Journal file name (nPathname+8+1 bytes)
56238
+ ** URI query parameters (nUriByte bytes)
56239
+ ** Journal filename (nPathname+8+1 bytes)
56240
+ ** WAL filename (nPathname+4+1 bytes)
56241
+ ** \0\0\0 terminator (3 bytes)
56242
+ **
56243
+ ** Some 3rd-party software, over which we have no control, depends on
56244
+ ** the specific order of the filenames and the \0 separators between them
56245
+ ** so that it can (for example) find the database filename given the WAL
56246
+ ** filename without using the sqlite3_filename_database() API. This is a
56247
+ ** misuse of SQLite and a bug in the 3rd-party software, but the 3rd-party
56248
+ ** software is in widespread use, so we try to avoid changing the filename
56249
+ ** order and formatting if possible. In particular, the details of the
56250
+ ** filename format expected by 3rd-party software should be as follows:
56251
+ **
56252
+ ** - Main Database Path
56253
+ ** - \0
56254
+ ** - Multiple URI components consisting of:
56255
+ ** - Key
56256
+ ** - \0
56257
+ ** - Value
56258
+ ** - \0
56259
+ ** - \0
56260
+ ** - Journal Path
56261
+ ** - \0
56262
+ ** - WAL Path (zWALName)
56263
+ ** - \0
5561556264
*/
5561656265
pPtr = (u8 *)sqlite3MallocZero(
55617
- ROUND8(sizeof(*pPager)) + /* Pager structure */
55618
- ROUND8(pcacheSize) + /* PCache object */
55619
- ROUND8(pVfs->szOsFile) + /* The main db file */
55620
- journalFileSize * 2 + /* The two journal files */
55621
- nPathname + 1 + nUri + /* zFilename */
55622
- nPathname + 8 + 2 /* zJournal */
56266
+ ROUND8(sizeof(*pPager)) + /* Pager structure */
56267
+ ROUND8(pcacheSize) + /* PCache object */
56268
+ ROUND8(pVfs->szOsFile) + /* The main db file */
56269
+ journalFileSize * 2 + /* The two journal files */
56270
+ 4 + /* Database prefix */
56271
+ nPathname + 1 + /* database filename */
56272
+ nUriByte + /* query parameters */
56273
+ nPathname + 8 + 1 + /* Journal filename */
5562356274
#ifndef SQLITE_OMIT_WAL
55624
- + nPathname + 4 + 2 /* zWal */
56275
+ nPathname + 4 + 1 + /* WAL filename */
5562556276
#endif
56277
+ 3 /* Terminator */
5562656278
);
5562756279
assert( EIGHT_BYTE_ALIGNMENT(SQLITE_INT_TO_PTR(journalFileSize)) );
5562856280
if( !pPtr ){
5562956281
sqlite3DbFree(0, zPathname);
5563056282
return SQLITE_NOMEM_BKPT;
5563156283
}
55632
- pPager = (Pager*)(pPtr);
55633
- pPager->pPCache = (PCache*)(pPtr += ROUND8(sizeof(*pPager)));
55634
- pPager->fd = (sqlite3_file*)(pPtr += ROUND8(pcacheSize));
55635
- pPager->sjfd = (sqlite3_file*)(pPtr += ROUND8(pVfs->szOsFile));
55636
- pPager->jfd = (sqlite3_file*)(pPtr += journalFileSize);
55637
- pPager->zFilename = (char*)(pPtr += journalFileSize);
56284
+ pPager = (Pager*)pPtr; pPtr += ROUND8(sizeof(*pPager));
56285
+ pPager->pPCache = (PCache*)pPtr; pPtr += ROUND8(pcacheSize);
56286
+ pPager->fd = (sqlite3_file*)pPtr; pPtr += ROUND8(pVfs->szOsFile);
56287
+ pPager->sjfd = (sqlite3_file*)pPtr; pPtr += journalFileSize;
56288
+ pPager->jfd = (sqlite3_file*)pPtr; pPtr += journalFileSize;
5563856289
assert( EIGHT_BYTE_ALIGNMENT(pPager->jfd) );
5563956290
55640
- /* Fill in the Pager.zFilename and Pager.zJournal buffers, if required. */
55641
- if( zPathname ){
55642
- assert( nPathname>0 );
55643
- pPager->zJournal = (char*)(pPtr += nPathname + 1 + nUri);
55644
- memcpy(pPager->zFilename, zPathname, nPathname);
55645
- if( nUri ) memcpy(&pPager->zFilename[nPathname+1], zUri, nUri);
55646
- memcpy(pPager->zJournal, zPathname, nPathname);
55647
- memcpy(&pPager->zJournal[nPathname], "-journal\000", 8+2);
55648
- sqlite3FileSuffix3(pPager->zFilename, pPager->zJournal);
56291
+ /* Fill in the Pager.zFilename and pPager.zQueryParam fields */
56292
+ pPtr += 4; /* Skip zero prefix */
56293
+ pPager->zFilename = (char*)pPtr;
56294
+ if( nPathname>0 ){
56295
+ memcpy(pPtr, zPathname, nPathname); pPtr += nPathname + 1;
56296
+ if( zUri ){
56297
+ memcpy(pPtr, zUri, nUriByte); pPtr += nUriByte;
56298
+ }else{
56299
+ pPtr++;
56300
+ }
56301
+ }
56302
+
56303
+
56304
+ /* Fill in Pager.zJournal */
56305
+ if( nPathname>0 ){
56306