Fossil SCM

Merge the latest SQLite 3.31.0 alpha sources for testing.

drh 2020-01-09 20:57 trunk
Commit 5c48142dd31165968010643cfbe54c8e71d0ca86e59d21433350125426906e95
3 files changed +54 -29 +1808 -850 +69 -10
+54 -29
--- 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
/*
@@ -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. */
@@ -5835,15 +5848,19 @@
58355848
if( rc==SQLITE_OK && bIsDir ){
58365849
/* For a directory, check that the last character in the path is a
58375850
** '/'. This appears to be required for compatibility with info-zip
58385851
** (the unzip command on unix). It does not create directories
58395852
** otherwise. */
5840
- if( zPath[nPath-1]!='/' ){
5853
+ if( nPath<=0 || zPath[nPath-1]!='/' ){
58415854
zFree = sqlite3_mprintf("%s/", zPath);
5842
- if( zFree==0 ){ rc = SQLITE_NOMEM; }
58435855
zPath = (const char*)zFree;
5844
- nPath = (int)strlen(zPath);
5856
+ if( zFree==0 ){
5857
+ rc = SQLITE_NOMEM;
5858
+ nPath = 0;
5859
+ }else{
5860
+ nPath = (int)strlen(zPath);
5861
+ }
58455862
}
58465863
}
58475864
58485865
/* Check that we're not inserting a duplicate entry -OR- updating an
58495866
** entry with a path, thereby making it into a duplicate. */
@@ -6500,14 +6517,16 @@
65006517
const sqlite3_api_routines *pApi
65016518
){
65026519
int rc = SQLITE_OK;
65036520
SQLITE_EXTENSION_INIT2(pApi);
65046521
(void)pzErrMsg; /* Unused parameter */
6505
- 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,
65066524
sqlarCompressFunc, 0, 0);
65076525
if( rc==SQLITE_OK ){
6508
- 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,
65096528
sqlarUncompressFunc, 0, 0);
65106529
}
65116530
return rc;
65126531
}
65136532
@@ -15703,35 +15722,36 @@
1570315722
if( c=='d' && n>=3 && strncmp(azArg[0], "dbconfig", n)==0 ){
1570415723
static const struct DbConfigChoices {
1570515724
const char *zName;
1570615725
int op;
1570715726
} aDbConfig[] = {
15727
+ { "defensive", SQLITE_DBCONFIG_DEFENSIVE },
15728
+ { "dqs_ddl", SQLITE_DBCONFIG_DQS_DDL },
15729
+ { "dqs_dml", SQLITE_DBCONFIG_DQS_DML },
1570815730
{ "enable_fkey", SQLITE_DBCONFIG_ENABLE_FKEY },
15731
+ { "enable_qpsg", SQLITE_DBCONFIG_ENABLE_QPSG },
1570915732
{ "enable_trigger", SQLITE_DBCONFIG_ENABLE_TRIGGER },
1571015733
{ "enable_view", SQLITE_DBCONFIG_ENABLE_VIEW },
1571115734
{ "fts3_tokenizer", SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER },
15735
+ { "legacy_alter_table", SQLITE_DBCONFIG_LEGACY_ALTER_TABLE },
15736
+ { "legacy_file_format", SQLITE_DBCONFIG_LEGACY_FILE_FORMAT },
1571215737
{ "load_extension", SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION },
1571315738
{ "no_ckpt_on_close", SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE },
15714
- { "enable_qpsg", SQLITE_DBCONFIG_ENABLE_QPSG },
15739
+ { "reset_database", SQLITE_DBCONFIG_RESET_DATABASE },
1571515740
{ "trigger_eqp", SQLITE_DBCONFIG_TRIGGER_EQP },
15716
- { "reset_database", SQLITE_DBCONFIG_RESET_DATABASE },
15717
- { "defensive", SQLITE_DBCONFIG_DEFENSIVE },
15741
+ { "trusted_schema", SQLITE_DBCONFIG_TRUSTED_SCHEMA },
1571815742
{ "writable_schema", SQLITE_DBCONFIG_WRITABLE_SCHEMA },
15719
- { "legacy_alter_table", SQLITE_DBCONFIG_LEGACY_ALTER_TABLE },
15720
- { "dqs_dml", SQLITE_DBCONFIG_DQS_DML },
15721
- { "dqs_ddl", SQLITE_DBCONFIG_DQS_DDL },
15722
- { "legacy_file_format", SQLITE_DBCONFIG_LEGACY_FILE_FORMAT },
1572315743
};
1572415744
int ii, v;
1572515745
open_db(p, 0);
1572615746
for(ii=0; ii<ArraySize(aDbConfig); ii++){
1572715747
if( nArg>1 && strcmp(azArg[1], aDbConfig[ii].zName)!=0 ) continue;
1572815748
if( nArg>=3 ){
1572915749
sqlite3_db_config(p->db, aDbConfig[ii].op, booleanValue(azArg[2]), 0);
1573015750
}
1573115751
sqlite3_db_config(p->db, aDbConfig[ii].op, -1, &v);
15732
- utf8_printf(p->out, "%18s %s\n", aDbConfig[ii].zName, v ? "on" : "off");
15752
+ utf8_printf(p->out, "%19s %s\n", aDbConfig[ii].zName, v ? "on" : "off");
1573315753
if( nArg>1 ) break;
1573415754
}
1573515755
if( nArg>1 && ii==ArraySize(aDbConfig) ){
1573615756
utf8_printf(stderr, "Error: unknown dbconfig \"%s\"\n", azArg[1]);
1573715757
utf8_printf(stderr, "Enter \".dbconfig\" with no arguments for a list\n");
@@ -17763,11 +17783,11 @@
1776317783
/*{ "bitvec_test", SQLITE_TESTCTRL_BITVEC_TEST, "" },*/
1776417784
{ "byteorder", SQLITE_TESTCTRL_BYTEORDER, "" },
1776517785
{ "extra_schema_checks",SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS,"BOOLEAN" },
1776617786
/*{ "fault_install", SQLITE_TESTCTRL_FAULT_INSTALL, "" },*/
1776717787
{ "imposter", SQLITE_TESTCTRL_IMPOSTER, "SCHEMA ON/OFF ROOTPAGE"},
17768
- { "internal_functions", SQLITE_TESTCTRL_INTERNAL_FUNCTIONS, "BOOLEAN" },
17788
+ { "internal_functions", SQLITE_TESTCTRL_INTERNAL_FUNCTIONS, "" },
1776917789
{ "localtime_fault", SQLITE_TESTCTRL_LOCALTIME_FAULT,"BOOLEAN" },
1777017790
{ "never_corrupt", SQLITE_TESTCTRL_NEVER_CORRUPT, "BOOLEAN" },
1777117791
{ "optimizations", SQLITE_TESTCTRL_OPTIMIZATIONS, "DISABLE-MASK" },
1777217792
#ifdef YYCOVERAGE
1777317793
{ "parser_coverage", SQLITE_TESTCTRL_PARSER_COVERAGE, "" },
@@ -17879,11 +17899,10 @@
1787917899
break;
1788017900
1788117901
/* sqlite3_test_control(int, int) */
1788217902
case SQLITE_TESTCTRL_ASSERT:
1788317903
case SQLITE_TESTCTRL_ALWAYS:
17884
- case SQLITE_TESTCTRL_INTERNAL_FUNCTIONS:
1788517904
if( nArg==3 ){
1788617905
int opt = booleanValue(azArg[2]);
1788717906
rc2 = sqlite3_test_control(testctrl, opt);
1788817907
isOk = 1;
1788917908
}
@@ -17896,10 +17915,16 @@
1789617915
int opt = booleanValue(azArg[2]);
1789717916
rc2 = sqlite3_test_control(testctrl, opt);
1789817917
isOk = 3;
1789917918
}
1790017919
break;
17920
+
17921
+ /* sqlite3_test_control(sqlite3*) */
17922
+ case SQLITE_TESTCTRL_INTERNAL_FUNCTIONS:
17923
+ rc2 = sqlite3_test_control(testctrl, p->db);
17924
+ isOk = 3;
17925
+ break;
1790117926
1790217927
case SQLITE_TESTCTRL_IMPOSTER:
1790317928
if( nArg==5 ){
1790417929
rc2 = sqlite3_test_control(testctrl, p->db,
1790517930
azArg[2],
1790617931
--- 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 /*
@@ -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. */
@@ -5835,15 +5848,19 @@
5835 if( rc==SQLITE_OK && bIsDir ){
5836 /* For a directory, check that the last character in the path is a
5837 ** '/'. This appears to be required for compatibility with info-zip
5838 ** (the unzip command on unix). It does not create directories
5839 ** otherwise. */
5840 if( zPath[nPath-1]!='/' ){
5841 zFree = sqlite3_mprintf("%s/", zPath);
5842 if( zFree==0 ){ rc = SQLITE_NOMEM; }
5843 zPath = (const char*)zFree;
5844 nPath = (int)strlen(zPath);
 
 
 
 
 
5845 }
5846 }
5847
5848 /* Check that we're not inserting a duplicate entry -OR- updating an
5849 ** entry with a path, thereby making it into a duplicate. */
@@ -6500,14 +6517,16 @@
6500 const sqlite3_api_routines *pApi
6501 ){
6502 int rc = SQLITE_OK;
6503 SQLITE_EXTENSION_INIT2(pApi);
6504 (void)pzErrMsg; /* Unused parameter */
6505 rc = sqlite3_create_function(db, "sqlar_compress", 1, SQLITE_UTF8, 0,
 
6506 sqlarCompressFunc, 0, 0);
6507 if( rc==SQLITE_OK ){
6508 rc = sqlite3_create_function(db, "sqlar_uncompress", 2, SQLITE_UTF8, 0,
 
6509 sqlarUncompressFunc, 0, 0);
6510 }
6511 return rc;
6512 }
6513
@@ -15703,35 +15722,36 @@
15703 if( c=='d' && n>=3 && strncmp(azArg[0], "dbconfig", n)==0 ){
15704 static const struct DbConfigChoices {
15705 const char *zName;
15706 int op;
15707 } aDbConfig[] = {
 
 
 
15708 { "enable_fkey", SQLITE_DBCONFIG_ENABLE_FKEY },
 
15709 { "enable_trigger", SQLITE_DBCONFIG_ENABLE_TRIGGER },
15710 { "enable_view", SQLITE_DBCONFIG_ENABLE_VIEW },
15711 { "fts3_tokenizer", SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER },
 
 
15712 { "load_extension", SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION },
15713 { "no_ckpt_on_close", SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE },
15714 { "enable_qpsg", SQLITE_DBCONFIG_ENABLE_QPSG },
15715 { "trigger_eqp", SQLITE_DBCONFIG_TRIGGER_EQP },
15716 { "reset_database", SQLITE_DBCONFIG_RESET_DATABASE },
15717 { "defensive", SQLITE_DBCONFIG_DEFENSIVE },
15718 { "writable_schema", SQLITE_DBCONFIG_WRITABLE_SCHEMA },
15719 { "legacy_alter_table", SQLITE_DBCONFIG_LEGACY_ALTER_TABLE },
15720 { "dqs_dml", SQLITE_DBCONFIG_DQS_DML },
15721 { "dqs_ddl", SQLITE_DBCONFIG_DQS_DDL },
15722 { "legacy_file_format", SQLITE_DBCONFIG_LEGACY_FILE_FORMAT },
15723 };
15724 int ii, v;
15725 open_db(p, 0);
15726 for(ii=0; ii<ArraySize(aDbConfig); ii++){
15727 if( nArg>1 && strcmp(azArg[1], aDbConfig[ii].zName)!=0 ) continue;
15728 if( nArg>=3 ){
15729 sqlite3_db_config(p->db, aDbConfig[ii].op, booleanValue(azArg[2]), 0);
15730 }
15731 sqlite3_db_config(p->db, aDbConfig[ii].op, -1, &v);
15732 utf8_printf(p->out, "%18s %s\n", aDbConfig[ii].zName, v ? "on" : "off");
15733 if( nArg>1 ) break;
15734 }
15735 if( nArg>1 && ii==ArraySize(aDbConfig) ){
15736 utf8_printf(stderr, "Error: unknown dbconfig \"%s\"\n", azArg[1]);
15737 utf8_printf(stderr, "Enter \".dbconfig\" with no arguments for a list\n");
@@ -17763,11 +17783,11 @@
17763 /*{ "bitvec_test", SQLITE_TESTCTRL_BITVEC_TEST, "" },*/
17764 { "byteorder", SQLITE_TESTCTRL_BYTEORDER, "" },
17765 { "extra_schema_checks",SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS,"BOOLEAN" },
17766 /*{ "fault_install", SQLITE_TESTCTRL_FAULT_INSTALL, "" },*/
17767 { "imposter", SQLITE_TESTCTRL_IMPOSTER, "SCHEMA ON/OFF ROOTPAGE"},
17768 { "internal_functions", SQLITE_TESTCTRL_INTERNAL_FUNCTIONS, "BOOLEAN" },
17769 { "localtime_fault", SQLITE_TESTCTRL_LOCALTIME_FAULT,"BOOLEAN" },
17770 { "never_corrupt", SQLITE_TESTCTRL_NEVER_CORRUPT, "BOOLEAN" },
17771 { "optimizations", SQLITE_TESTCTRL_OPTIMIZATIONS, "DISABLE-MASK" },
17772 #ifdef YYCOVERAGE
17773 { "parser_coverage", SQLITE_TESTCTRL_PARSER_COVERAGE, "" },
@@ -17879,11 +17899,10 @@
17879 break;
17880
17881 /* sqlite3_test_control(int, int) */
17882 case SQLITE_TESTCTRL_ASSERT:
17883 case SQLITE_TESTCTRL_ALWAYS:
17884 case SQLITE_TESTCTRL_INTERNAL_FUNCTIONS:
17885 if( nArg==3 ){
17886 int opt = booleanValue(azArg[2]);
17887 rc2 = sqlite3_test_control(testctrl, opt);
17888 isOk = 1;
17889 }
@@ -17896,10 +17915,16 @@
17896 int opt = booleanValue(azArg[2]);
17897 rc2 = sqlite3_test_control(testctrl, opt);
17898 isOk = 3;
17899 }
17900 break;
 
 
 
 
 
 
17901
17902 case SQLITE_TESTCTRL_IMPOSTER:
17903 if( nArg==5 ){
17904 rc2 = sqlite3_test_control(testctrl, p->db,
17905 azArg[2],
17906
--- 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 /*
@@ -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. */
@@ -5835,15 +5848,19 @@
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. */
@@ -6500,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
@@ -15703,35 +15722,36 @@
15722 if( c=='d' && n>=3 && strncmp(azArg[0], "dbconfig", n)==0 ){
15723 static const struct DbConfigChoices {
15724 const char *zName;
15725 int op;
15726 } aDbConfig[] = {
15727 { "defensive", SQLITE_DBCONFIG_DEFENSIVE },
15728 { "dqs_ddl", SQLITE_DBCONFIG_DQS_DDL },
15729 { "dqs_dml", SQLITE_DBCONFIG_DQS_DML },
15730 { "enable_fkey", SQLITE_DBCONFIG_ENABLE_FKEY },
15731 { "enable_qpsg", SQLITE_DBCONFIG_ENABLE_QPSG },
15732 { "enable_trigger", SQLITE_DBCONFIG_ENABLE_TRIGGER },
15733 { "enable_view", SQLITE_DBCONFIG_ENABLE_VIEW },
15734 { "fts3_tokenizer", SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER },
15735 { "legacy_alter_table", SQLITE_DBCONFIG_LEGACY_ALTER_TABLE },
15736 { "legacy_file_format", SQLITE_DBCONFIG_LEGACY_FILE_FORMAT },
15737 { "load_extension", SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION },
15738 { "no_ckpt_on_close", SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE },
15739 { "reset_database", SQLITE_DBCONFIG_RESET_DATABASE },
15740 { "trigger_eqp", SQLITE_DBCONFIG_TRIGGER_EQP },
15741 { "trusted_schema", SQLITE_DBCONFIG_TRUSTED_SCHEMA },
 
15742 { "writable_schema", SQLITE_DBCONFIG_WRITABLE_SCHEMA },
 
 
 
 
15743 };
15744 int ii, v;
15745 open_db(p, 0);
15746 for(ii=0; ii<ArraySize(aDbConfig); ii++){
15747 if( nArg>1 && strcmp(azArg[1], aDbConfig[ii].zName)!=0 ) continue;
15748 if( nArg>=3 ){
15749 sqlite3_db_config(p->db, aDbConfig[ii].op, booleanValue(azArg[2]), 0);
15750 }
15751 sqlite3_db_config(p->db, aDbConfig[ii].op, -1, &v);
15752 utf8_printf(p->out, "%19s %s\n", aDbConfig[ii].zName, v ? "on" : "off");
15753 if( nArg>1 ) break;
15754 }
15755 if( nArg>1 && ii==ArraySize(aDbConfig) ){
15756 utf8_printf(stderr, "Error: unknown dbconfig \"%s\"\n", azArg[1]);
15757 utf8_printf(stderr, "Enter \".dbconfig\" with no arguments for a list\n");
@@ -17763,11 +17783,11 @@
17783 /*{ "bitvec_test", SQLITE_TESTCTRL_BITVEC_TEST, "" },*/
17784 { "byteorder", SQLITE_TESTCTRL_BYTEORDER, "" },
17785 { "extra_schema_checks",SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS,"BOOLEAN" },
17786 /*{ "fault_install", SQLITE_TESTCTRL_FAULT_INSTALL, "" },*/
17787 { "imposter", SQLITE_TESTCTRL_IMPOSTER, "SCHEMA ON/OFF ROOTPAGE"},
17788 { "internal_functions", SQLITE_TESTCTRL_INTERNAL_FUNCTIONS, "" },
17789 { "localtime_fault", SQLITE_TESTCTRL_LOCALTIME_FAULT,"BOOLEAN" },
17790 { "never_corrupt", SQLITE_TESTCTRL_NEVER_CORRUPT, "BOOLEAN" },
17791 { "optimizations", SQLITE_TESTCTRL_OPTIMIZATIONS, "DISABLE-MASK" },
17792 #ifdef YYCOVERAGE
17793 { "parser_coverage", SQLITE_TESTCTRL_PARSER_COVERAGE, "" },
@@ -17879,11 +17899,10 @@
17899 break;
17900
17901 /* sqlite3_test_control(int, int) */
17902 case SQLITE_TESTCTRL_ASSERT:
17903 case SQLITE_TESTCTRL_ALWAYS:
 
17904 if( nArg==3 ){
17905 int opt = booleanValue(azArg[2]);
17906 rc2 = sqlite3_test_control(testctrl, opt);
17907 isOk = 1;
17908 }
@@ -17896,10 +17915,16 @@
17915 int opt = booleanValue(azArg[2]);
17916 rc2 = sqlite3_test_control(testctrl, opt);
17917 isOk = 3;
17918 }
17919 break;
17920
17921 /* sqlite3_test_control(sqlite3*) */
17922 case SQLITE_TESTCTRL_INTERNAL_FUNCTIONS:
17923 rc2 = sqlite3_test_control(testctrl, p->db);
17924 isOk = 3;
17925 break;
17926
17927 case SQLITE_TESTCTRL_IMPOSTER:
17928 if( nArg==5 ){
17929 rc2 = sqlite3_test_control(testctrl, p->db,
17930 azArg[2],
17931
+1808 -850
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1165,11 +1165,11 @@
11651165
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
11661166
** [sqlite_version()] and [sqlite_source_id()].
11671167
*/
11681168
#define SQLITE_VERSION "3.31.0"
11691169
#define SQLITE_VERSION_NUMBER 3031000
1170
-#define SQLITE_SOURCE_ID "2019-12-26 01:10:17 f482a4cdfa768941e22c399de8ec29a55e729529eeae86d3832077ad1bef22f3"
1170
+#define SQLITE_SOURCE_ID "2020-01-09 20:44:37 5720924cb07766cd54fb042da58f4b4acf12b60029fba86a23a606ad0d0f7c68"
11711171
11721172
/*
11731173
** CAPI3REF: Run-Time Library Version Numbers
11741174
** KEYWORDS: sqlite3_version sqlite3_sourceid
11751175
**
@@ -1576,10 +1576,11 @@
15761576
#define SQLITE_CONSTRAINT_PRIMARYKEY (SQLITE_CONSTRAINT | (6<<8))
15771577
#define SQLITE_CONSTRAINT_TRIGGER (SQLITE_CONSTRAINT | (7<<8))
15781578
#define SQLITE_CONSTRAINT_UNIQUE (SQLITE_CONSTRAINT | (8<<8))
15791579
#define SQLITE_CONSTRAINT_VTAB (SQLITE_CONSTRAINT | (9<<8))
15801580
#define SQLITE_CONSTRAINT_ROWID (SQLITE_CONSTRAINT |(10<<8))
1581
+#define SQLITE_CONSTRAINT_PINNED (SQLITE_CONSTRAINT |(11<<8))
15811582
#define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8))
15821583
#define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8))
15831584
#define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8))
15841585
#define SQLITE_AUTH_USER (SQLITE_AUTH | (1<<8))
15851586
#define SQLITE_OK_LOAD_PERMANENTLY (SQLITE_OK | (1<<8))
@@ -3303,10 +3304,29 @@
33033304
** the legacy [double-quoted string literal] misfeature for DDL statements,
33043305
** such as CREATE TABLE and CREATE INDEX. The
33053306
** default value of this setting is determined by the [-DSQLITE_DQS]
33063307
** compile-time option.
33073308
** </dd>
3309
+**
3310
+** [[SQLITE_DBCONFIG_TRUSTED_SCHEMA]]
3311
+** <dt>SQLITE_DBCONFIG_TRUSTED_SCHEMA</td>
3312
+** <dd>The SQLITE_DBCONFIG_TRUSTED_SCHEMA option tells the SQLite to
3313
+** assume that database schemas are untainted by malicious content.
3314
+** When the SQLITE_DBCONFIG_TRUSTED_SCHEMA option is disabled, SQLite
3315
+** takes additional defensive steps to protect the application from harm
3316
+** including, but not limited to, the following:
3317
+** <ul>
3318
+** <li> Prohibit the use of SQL functions inside triggers, views,
3319
+** CHECK constraints, DEFAULT VALUEs, index definitions, and/or
3320
+** generated columns unless those functions are tagged
3321
+** with [SQLITE_INNOCUOUS].
3322
+** <li> Pohibit the use of virtual tables inside of triggers and/or views
3323
+** unless those virtual tables are tagged with [SQLITE_VTAB_INNOCUOUS].
3324
+** </ul>
3325
+** This setting defaults to "on" for legacy compatibility, however
3326
+** all applications are advised to turn it off if possible.
3327
+** </dd>
33083328
**
33093329
** [[SQLITE_DBCONFIG_LEGACY_FILE_FORMAT]]
33103330
** <dt>SQLITE_DBCONFIG_LEGACY_FILE_FORMAT</td>
33113331
** <dd>The SQLITE_DBCONFIG_LEGACY_FILE_FORMAT option activates or deactivates
33123332
** the legacy file format flag. When activated, this flag causes all newly
@@ -3344,11 +3364,12 @@
33443364
#define SQLITE_DBCONFIG_LEGACY_ALTER_TABLE 1012 /* int int* */
33453365
#define SQLITE_DBCONFIG_DQS_DML 1013 /* int int* */
33463366
#define SQLITE_DBCONFIG_DQS_DDL 1014 /* int int* */
33473367
#define SQLITE_DBCONFIG_ENABLE_VIEW 1015 /* int int* */
33483368
#define SQLITE_DBCONFIG_LEGACY_FILE_FORMAT 1016 /* int int* */
3349
-#define SQLITE_DBCONFIG_MAX 1016 /* Largest DBCONFIG */
3369
+#define SQLITE_DBCONFIG_TRUSTED_SCHEMA 1017 /* int int* */
3370
+#define SQLITE_DBCONFIG_MAX 1017 /* Largest DBCONFIG */
33503371
33513372
/*
33523373
** CAPI3REF: Enable Or Disable Extended Result Codes
33533374
** METHOD: sqlite3
33543375
**
@@ -6035,16 +6056,30 @@
60356056
** [SQLITE_UTF8 | preferred text encoding] as the fourth argument
60366057
** to [sqlite3_create_function()], [sqlite3_create_function16()], or
60376058
** [sqlite3_create_function_v2()].
60386059
**
60396060
** The SQLITE_DETERMINISTIC flag means that the new function always gives
6040
-** the same output when the input parameters are the same. The abs() function
6041
-** is deterministic, for example, but randomblob() is not. Functions must
6061
+** the same output when the input parameters are the same.
6062
+** The [abs|abs() function] is deterministic, for example, but
6063
+** [randomblob|randomblob()] is not. Functions must
60426064
** be deterministic in order to be used in certain contexts such as
60436065
** [CHECK constraints] or [generated columns]. SQLite might also optimize
60446066
** deterministic functions by factoring them out of inner loops.
60456067
**
6068
+** The SQLITE_INNOCUOUS flag means that the new function is unlikely
6069
+** to cause problems even if misused. An innocuous function should have
6070
+** no side effects and consume few resources. The [abs|abs() function]
6071
+** is an example of an innocuous function.
6072
+** The [load_extension() SQL function] is not innocuous because of its
6073
+** side effects. Some heightened security settings
6074
+** ([SQLITE_DBCONFIG_UNSAFE_FUNC_IN_VIEW])
6075
+** disable the use of SQLlfunctions inside views and triggers unless
6076
+** the function is tagged with SQLITE_INNOCUOUS. Most built-in functions
6077
+** are innocuous. Developers are advised to avoid using the
6078
+** SQLITE_INNOCUOUS flag for application-defined functions unless the
6079
+** function is specifically intended for use inside of views and triggers.
6080
+**
60466081
** The SQLITE_DIRECTONLY flag means that the function may only be invoked
60476082
** from top-level SQL, and cannot be used in VIEWs or TRIGGERs. This is
60486083
** a security feature which is recommended for all
60496084
** [application-defined SQL functions] that have side-effects. This flag
60506085
** prevents an attacker from adding triggers and views to a schema then
@@ -6060,10 +6095,11 @@
60606095
** sqlite3_value_subtype() will always return 0).
60616096
*/
60626097
#define SQLITE_DETERMINISTIC 0x000000800
60636098
#define SQLITE_DIRECTONLY 0x000080000
60646099
#define SQLITE_SUBTYPE 0x000100000
6100
+#define SQLITE_INNOCUOUS 0x000200000
60656101
60666102
/*
60676103
** CAPI3REF: Deprecated Functions
60686104
** DEPRECATED
60696105
**
@@ -6591,31 +6627,32 @@
65916627
** <li> [SQLITE_UTF16BE],
65926628
** <li> [SQLITE_UTF16], or
65936629
** <li> [SQLITE_UTF16_ALIGNED].
65946630
** </ul>)^
65956631
** ^The eTextRep argument determines the encoding of strings passed
6596
-** to the collating function callback, xCallback.
6632
+** to the collating function callback, xCompare.
65976633
** ^The [SQLITE_UTF16] and [SQLITE_UTF16_ALIGNED] values for eTextRep
65986634
** force strings to be UTF16 with native byte order.
65996635
** ^The [SQLITE_UTF16_ALIGNED] value for eTextRep forces strings to begin
66006636
** on an even byte address.
66016637
**
66026638
** ^The fourth argument, pArg, is an application data pointer that is passed
66036639
** through as the first argument to the collating function callback.
66046640
**
6605
-** ^The fifth argument, xCallback, is a pointer to the collating function.
6641
+** ^The fifth argument, xCompare, is a pointer to the collating function.
66066642
** ^Multiple collating functions can be registered using the same name but
66076643
** with different eTextRep parameters and SQLite will use whichever
66086644
** function requires the least amount of data transformation.
6609
-** ^If the xCallback argument is NULL then the collating function is
6645
+** ^If the xCompare argument is NULL then the collating function is
66106646
** deleted. ^When all collating functions having the same name are deleted,
66116647
** that collation is no longer usable.
66126648
**
66136649
** ^The collating function callback is invoked with a copy of the pArg
66146650
** application data pointer and with two strings in the encoding specified
6615
-** by the eTextRep argument. The collating function must return an
6616
-** integer that is negative, zero, or positive
6651
+** by the eTextRep argument. The two integer parameters to the collating
6652
+** function callback are the length of the two strings, in bytes. The collating
6653
+** function must return an integer that is negative, zero, or positive
66176654
** if the first string is less than, equal to, or greater than the second,
66186655
** respectively. A collating function must always return the same answer
66196656
** given the same inputs. If two or more collating functions are registered
66206657
** to the same collation name (using different eTextRep values) then all
66216658
** must give an equivalent answer when invoked with equivalent strings.
@@ -9907,11 +9944,11 @@
99079944
** [sqlite3_vtab_config()] interface that [virtual table] implementations
99089945
** can use to customize and optimize their behavior.
99099946
**
99109947
** <dl>
99119948
** [[SQLITE_VTAB_CONSTRAINT_SUPPORT]]
9912
-** <dt>SQLITE_VTAB_CONSTRAINT_SUPPORT
9949
+** <dt>SQLITE_VTAB_CONSTRAINT_SUPPORT</dt>
99139950
** <dd>Calls of the form
99149951
** [sqlite3_vtab_config](db,SQLITE_VTAB_CONSTRAINT_SUPPORT,X) are supported,
99159952
** where X is an integer. If X is zero, then the [virtual table] whose
99169953
** [xCreate] or [xConnect] method invoked [sqlite3_vtab_config()] does not
99179954
** support constraints. In this configuration (which is the default) if
@@ -9936,13 +9973,35 @@
99369973
** CONFLICT policy is REPLACE, the virtual table implementation should
99379974
** silently replace the appropriate rows within the xUpdate callback and
99389975
** return SQLITE_OK. Or, if this is not possible, it may return
99399976
** SQLITE_CONSTRAINT, in which case SQLite falls back to OR ABORT
99409977
** constraint handling.
9978
+** </dd>
9979
+**
9980
+** [[SQLITE_VTAB_INNOCUOUS]]<dt>SQLITE_VTAB_INNOCUOUS</dt>
9981
+** <dd>Calls of the form
9982
+** [sqlite3_vtab_config](db,SQLITE_VTAB_INNOCUOUS) from within the
9983
+** the [xConnect] or [xCreate] methods of a [virtual table] implmentation
9984
+** identify that virtual table as being safe to use from within triggers
9985
+** and views. Conceptually, the SQLITE_VTAB_INNOCUOUS tag means that the
9986
+** virtual table can do no serious harm even if it is controlled by a
9987
+** malicious hacker. Developers should avoid setting the SQLITE_VTAB_INNOCUOUS
9988
+** flag unless absolutely necessary.
9989
+** </dd>
9990
+**
9991
+** [[SQLITE_VTAB_DIRECTONLY]]<dt>SQLITE_VTAB_DIRECTONLY</dt>
9992
+** <dd>Calls of the form
9993
+** [sqlite3_vtab_config](db,SQLITE_VTAB_DIRECTONLY) from within the
9994
+** the [xConnect] or [xCreate] methods of a [virtual table] implmentation
9995
+** prohibits that virtual table from being used from within triggers and
9996
+** views.
9997
+** </dd>
99419998
** </dl>
99429999
*/
994310000
#define SQLITE_VTAB_CONSTRAINT_SUPPORT 1
10001
+#define SQLITE_VTAB_INNOCUOUS 2
10002
+#define SQLITE_VTAB_DIRECTONLY 3
994410003
994510004
/*
994610005
** CAPI3REF: Determine The Virtual Table Conflict Policy
994710006
**
994810007
** This function may only be called from within a call to the [xUpdate] method
@@ -14415,10 +14474,11 @@
1441514474
1441614475
/*
1441714476
** A bit in a Bitmask
1441814477
*/
1441914478
#define MASKBIT(n) (((Bitmask)1)<<(n))
14479
+#define MASKBIT64(n) (((u64)1)<<(n))
1442014480
#define MASKBIT32(n) (((unsigned int)1)<<(n))
1442114481
#define ALLBITS ((Bitmask)-1)
1442214482
1442314483
/* A VList object records a mapping between parameters/variables/wildcards
1442414484
** in the SQL statement (such as $abc, @pqr, or :xyz) and the integer
@@ -14741,10 +14801,12 @@
1474114801
SQLITE_PRIVATE int sqlite3BtreeLast(BtCursor*, int *pRes);
1474214802
SQLITE_PRIVATE int sqlite3BtreeNext(BtCursor*, int flags);
1474314803
SQLITE_PRIVATE int sqlite3BtreeEof(BtCursor*);
1474414804
SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor*, int flags);
1474514805
SQLITE_PRIVATE i64 sqlite3BtreeIntegerKey(BtCursor*);
14806
+SQLITE_PRIVATE void sqlite3BtreeCursorPin(BtCursor*);
14807
+SQLITE_PRIVATE void sqlite3BtreeCursorUnpin(BtCursor*);
1474614808
#ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
1474714809
SQLITE_PRIVATE i64 sqlite3BtreeOffset(BtCursor*);
1474814810
#endif
1474914811
SQLITE_PRIVATE int sqlite3BtreePayload(BtCursor*, u32 offset, u32 amt, void*);
1475014812
SQLITE_PRIVATE const void *sqlite3BtreePayloadFetch(BtCursor*, u32 *pAmt);
@@ -15027,85 +15089,85 @@
1502715089
#define OP_IfNullRow 21 /* jump, synopsis: if P1.nullRow then r[P3]=NULL, goto P2 */
1502815090
#define OP_SeekLT 22 /* jump, synopsis: key=r[P3@P4] */
1502915091
#define OP_SeekLE 23 /* jump, synopsis: key=r[P3@P4] */
1503015092
#define OP_SeekGE 24 /* jump, synopsis: key=r[P3@P4] */
1503115093
#define OP_SeekGT 25 /* jump, synopsis: key=r[P3@P4] */
15032
-#define OP_IfNoHope 26 /* jump, synopsis: key=r[P3@P4] */
15033
-#define OP_NoConflict 27 /* jump, synopsis: key=r[P3@P4] */
15034
-#define OP_NotFound 28 /* jump, synopsis: key=r[P3@P4] */
15035
-#define OP_Found 29 /* jump, synopsis: key=r[P3@P4] */
15036
-#define OP_SeekRowid 30 /* jump, synopsis: intkey=r[P3] */
15037
-#define OP_NotExists 31 /* jump, synopsis: intkey=r[P3] */
15038
-#define OP_Last 32 /* jump */
15039
-#define OP_IfSmaller 33 /* jump */
15040
-#define OP_SorterSort 34 /* jump */
15041
-#define OP_Sort 35 /* jump */
15042
-#define OP_Rewind 36 /* jump */
15043
-#define OP_IdxLE 37 /* jump, synopsis: key=r[P3@P4] */
15044
-#define OP_IdxGT 38 /* jump, synopsis: key=r[P3@P4] */
15045
-#define OP_IdxLT 39 /* jump, synopsis: key=r[P3@P4] */
15046
-#define OP_IdxGE 40 /* jump, synopsis: key=r[P3@P4] */
15047
-#define OP_RowSetRead 41 /* jump, synopsis: r[P3]=rowset(P1) */
15048
-#define OP_RowSetTest 42 /* jump, synopsis: if r[P3] in rowset(P1) goto P2 */
15094
+#define OP_IfNotOpen 26 /* jump, synopsis: if( !csr[P1] ) goto P2 */
15095
+#define OP_IfNoHope 27 /* jump, synopsis: key=r[P3@P4] */
15096
+#define OP_NoConflict 28 /* jump, synopsis: key=r[P3@P4] */
15097
+#define OP_NotFound 29 /* jump, synopsis: key=r[P3@P4] */
15098
+#define OP_Found 30 /* jump, synopsis: key=r[P3@P4] */
15099
+#define OP_SeekRowid 31 /* jump, synopsis: intkey=r[P3] */
15100
+#define OP_NotExists 32 /* jump, synopsis: intkey=r[P3] */
15101
+#define OP_Last 33 /* jump */
15102
+#define OP_IfSmaller 34 /* jump */
15103
+#define OP_SorterSort 35 /* jump */
15104
+#define OP_Sort 36 /* jump */
15105
+#define OP_Rewind 37 /* jump */
15106
+#define OP_IdxLE 38 /* jump, synopsis: key=r[P3@P4] */
15107
+#define OP_IdxGT 39 /* jump, synopsis: key=r[P3@P4] */
15108
+#define OP_IdxLT 40 /* jump, synopsis: key=r[P3@P4] */
15109
+#define OP_IdxGE 41 /* jump, synopsis: key=r[P3@P4] */
15110
+#define OP_RowSetRead 42 /* jump, synopsis: r[P3]=rowset(P1) */
1504915111
#define OP_Or 43 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
1505015112
#define OP_And 44 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */
15051
-#define OP_Program 45 /* jump */
15052
-#define OP_FkIfZero 46 /* jump, synopsis: if fkctr[P1]==0 goto P2 */
15053
-#define OP_IfPos 47 /* jump, synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */
15054
-#define OP_IfNotZero 48 /* jump, synopsis: if r[P1]!=0 then r[P1]--, goto P2 */
15055
-#define OP_DecrJumpZero 49 /* jump, synopsis: if (--r[P1])==0 goto P2 */
15113
+#define OP_RowSetTest 45 /* jump, synopsis: if r[P3] in rowset(P1) goto P2 */
15114
+#define OP_Program 46 /* jump */
15115
+#define OP_FkIfZero 47 /* jump, synopsis: if fkctr[P1]==0 goto P2 */
15116
+#define OP_IfPos 48 /* jump, synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */
15117
+#define OP_IfNotZero 49 /* jump, synopsis: if r[P1]!=0 then r[P1]--, goto P2 */
1505615118
#define OP_IsNull 50 /* jump, same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
1505715119
#define OP_NotNull 51 /* jump, same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
1505815120
#define OP_Ne 52 /* jump, same as TK_NE, synopsis: IF r[P3]!=r[P1] */
1505915121
#define OP_Eq 53 /* jump, same as TK_EQ, synopsis: IF r[P3]==r[P1] */
1506015122
#define OP_Gt 54 /* jump, same as TK_GT, synopsis: IF r[P3]>r[P1] */
1506115123
#define OP_Le 55 /* jump, same as TK_LE, synopsis: IF r[P3]<=r[P1] */
1506215124
#define OP_Lt 56 /* jump, same as TK_LT, synopsis: IF r[P3]<r[P1] */
1506315125
#define OP_Ge 57 /* jump, same as TK_GE, synopsis: IF r[P3]>=r[P1] */
1506415126
#define OP_ElseNotEq 58 /* jump, same as TK_ESCAPE */
15065
-#define OP_IncrVacuum 59 /* jump */
15066
-#define OP_VNext 60 /* jump */
15067
-#define OP_Init 61 /* jump, synopsis: Start at P2 */
15068
-#define OP_PureFunc 62 /* synopsis: r[P3]=func(r[P2@P5]) */
15069
-#define OP_Function 63 /* synopsis: r[P3]=func(r[P2@P5]) */
15070
-#define OP_Return 64
15071
-#define OP_EndCoroutine 65
15072
-#define OP_HaltIfNull 66 /* synopsis: if r[P3]=null halt */
15073
-#define OP_Halt 67
15074
-#define OP_Integer 68 /* synopsis: r[P2]=P1 */
15075
-#define OP_Int64 69 /* synopsis: r[P2]=P4 */
15076
-#define OP_String 70 /* synopsis: r[P2]='P4' (len=P1) */
15077
-#define OP_Null 71 /* synopsis: r[P2..P3]=NULL */
15078
-#define OP_SoftNull 72 /* synopsis: r[P1]=NULL */
15079
-#define OP_Blob 73 /* synopsis: r[P2]=P4 (len=P1) */
15080
-#define OP_Variable 74 /* synopsis: r[P2]=parameter(P1,P4) */
15081
-#define OP_Move 75 /* synopsis: r[P2@P3]=r[P1@P3] */
15082
-#define OP_Copy 76 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */
15083
-#define OP_SCopy 77 /* synopsis: r[P2]=r[P1] */
15084
-#define OP_IntCopy 78 /* synopsis: r[P2]=r[P1] */
15085
-#define OP_ResultRow 79 /* synopsis: output=r[P1@P2] */
15086
-#define OP_CollSeq 80
15087
-#define OP_AddImm 81 /* synopsis: r[P1]=r[P1]+P2 */
15088
-#define OP_RealAffinity 82
15089
-#define OP_Cast 83 /* synopsis: affinity(r[P1]) */
15090
-#define OP_Permutation 84
15091
-#define OP_Compare 85 /* synopsis: r[P1@P3] <-> r[P2@P3] */
15092
-#define OP_IsTrue 86 /* synopsis: r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4 */
15093
-#define OP_Offset 87 /* synopsis: r[P3] = sqlite_offset(P1) */
15094
-#define OP_Column 88 /* synopsis: r[P3]=PX */
15095
-#define OP_Affinity 89 /* synopsis: affinity(r[P1@P2]) */
15096
-#define OP_MakeRecord 90 /* synopsis: r[P3]=mkrec(r[P1@P2]) */
15097
-#define OP_Count 91 /* synopsis: r[P2]=count() */
15098
-#define OP_ReadCookie 92
15099
-#define OP_SetCookie 93
15100
-#define OP_ReopenIdx 94 /* synopsis: root=P2 iDb=P3 */
15101
-#define OP_OpenRead 95 /* synopsis: root=P2 iDb=P3 */
15102
-#define OP_OpenWrite 96 /* synopsis: root=P2 iDb=P3 */
15103
-#define OP_OpenDup 97
15104
-#define OP_OpenAutoindex 98 /* synopsis: nColumn=P2 */
15105
-#define OP_OpenEphemeral 99 /* synopsis: nColumn=P2 */
15106
-#define OP_SorterOpen 100
15127
+#define OP_DecrJumpZero 59 /* jump, synopsis: if (--r[P1])==0 goto P2 */
15128
+#define OP_IncrVacuum 60 /* jump */
15129
+#define OP_VNext 61 /* jump */
15130
+#define OP_Init 62 /* jump, synopsis: Start at P2 */
15131
+#define OP_PureFunc 63 /* synopsis: r[P3]=func(r[P2@P5]) */
15132
+#define OP_Function 64 /* synopsis: r[P3]=func(r[P2@P5]) */
15133
+#define OP_Return 65
15134
+#define OP_EndCoroutine 66
15135
+#define OP_HaltIfNull 67 /* synopsis: if r[P3]=null halt */
15136
+#define OP_Halt 68
15137
+#define OP_Integer 69 /* synopsis: r[P2]=P1 */
15138
+#define OP_Int64 70 /* synopsis: r[P2]=P4 */
15139
+#define OP_String 71 /* synopsis: r[P2]='P4' (len=P1) */
15140
+#define OP_Null 72 /* synopsis: r[P2..P3]=NULL */
15141
+#define OP_SoftNull 73 /* synopsis: r[P1]=NULL */
15142
+#define OP_Blob 74 /* synopsis: r[P2]=P4 (len=P1) */
15143
+#define OP_Variable 75 /* synopsis: r[P2]=parameter(P1,P4) */
15144
+#define OP_Move 76 /* synopsis: r[P2@P3]=r[P1@P3] */
15145
+#define OP_Copy 77 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */
15146
+#define OP_SCopy 78 /* synopsis: r[P2]=r[P1] */
15147
+#define OP_IntCopy 79 /* synopsis: r[P2]=r[P1] */
15148
+#define OP_ResultRow 80 /* synopsis: output=r[P1@P2] */
15149
+#define OP_CollSeq 81
15150
+#define OP_AddImm 82 /* synopsis: r[P1]=r[P1]+P2 */
15151
+#define OP_RealAffinity 83
15152
+#define OP_Cast 84 /* synopsis: affinity(r[P1]) */
15153
+#define OP_Permutation 85
15154
+#define OP_Compare 86 /* synopsis: r[P1@P3] <-> r[P2@P3] */
15155
+#define OP_IsTrue 87 /* synopsis: r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4 */
15156
+#define OP_Offset 88 /* synopsis: r[P3] = sqlite_offset(P1) */
15157
+#define OP_Column 89 /* synopsis: r[P3]=PX */
15158
+#define OP_Affinity 90 /* synopsis: affinity(r[P1@P2]) */
15159
+#define OP_MakeRecord 91 /* synopsis: r[P3]=mkrec(r[P1@P2]) */
15160
+#define OP_Count 92 /* synopsis: r[P2]=count() */
15161
+#define OP_ReadCookie 93
15162
+#define OP_SetCookie 94
15163
+#define OP_ReopenIdx 95 /* synopsis: root=P2 iDb=P3 */
15164
+#define OP_OpenRead 96 /* synopsis: root=P2 iDb=P3 */
15165
+#define OP_OpenWrite 97 /* synopsis: root=P2 iDb=P3 */
15166
+#define OP_OpenDup 98
15167
+#define OP_OpenAutoindex 99 /* synopsis: nColumn=P2 */
15168
+#define OP_OpenEphemeral 100 /* synopsis: nColumn=P2 */
1510715169
#define OP_BitAnd 101 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
1510815170
#define OP_BitOr 102 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
1510915171
#define OP_ShiftLeft 103 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
1511015172
#define OP_ShiftRight 104 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
1511115173
#define OP_Add 105 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
@@ -15112,71 +15174,75 @@
1511215174
#define OP_Subtract 106 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
1511315175
#define OP_Multiply 107 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
1511415176
#define OP_Divide 108 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
1511515177
#define OP_Remainder 109 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
1511615178
#define OP_Concat 110 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
15117
-#define OP_SequenceTest 111 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */
15179
+#define OP_SorterOpen 111
1511815180
#define OP_BitNot 112 /* same as TK_BITNOT, synopsis: r[P2]= ~r[P1] */
15119
-#define OP_OpenPseudo 113 /* synopsis: P3 columns in r[P2] */
15120
-#define OP_Close 114
15181
+#define OP_SequenceTest 113 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */
15182
+#define OP_OpenPseudo 114 /* synopsis: P3 columns in r[P2] */
1512115183
#define OP_String8 115 /* same as TK_STRING, synopsis: r[P2]='P4' */
15122
-#define OP_ColumnsUsed 116
15123
-#define OP_SeekHit 117 /* synopsis: seekHit=P2 */
15124
-#define OP_Sequence 118 /* synopsis: r[P2]=cursor[P1].ctr++ */
15125
-#define OP_NewRowid 119 /* synopsis: r[P2]=rowid */
15126
-#define OP_Insert 120 /* synopsis: intkey=r[P3] data=r[P2] */
15127
-#define OP_Delete 121
15128
-#define OP_ResetCount 122
15129
-#define OP_SorterCompare 123 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
15130
-#define OP_SorterData 124 /* synopsis: r[P2]=data */
15131
-#define OP_RowData 125 /* synopsis: r[P2]=data */
15132
-#define OP_Rowid 126 /* synopsis: r[P2]=rowid */
15133
-#define OP_NullRow 127
15134
-#define OP_SeekEnd 128
15135
-#define OP_SorterInsert 129 /* synopsis: key=r[P2] */
15136
-#define OP_IdxInsert 130 /* synopsis: key=r[P2] */
15137
-#define OP_IdxDelete 131 /* synopsis: key=r[P2@P3] */
15138
-#define OP_DeferredSeek 132 /* synopsis: Move P3 to P1.rowid if needed */
15139
-#define OP_IdxRowid 133 /* synopsis: r[P2]=rowid */
15140
-#define OP_Destroy 134
15141
-#define OP_Clear 135
15142
-#define OP_ResetSorter 136
15143
-#define OP_CreateBtree 137 /* synopsis: r[P2]=root iDb=P1 flags=P3 */
15144
-#define OP_SqlExec 138
15145
-#define OP_ParseSchema 139
15146
-#define OP_LoadAnalysis 140
15147
-#define OP_DropTable 141
15148
-#define OP_DropIndex 142
15149
-#define OP_DropTrigger 143
15150
-#define OP_IntegrityCk 144
15151
-#define OP_RowSetAdd 145 /* synopsis: rowset(P1)=r[P2] */
15152
-#define OP_Param 146
15153
-#define OP_FkCounter 147 /* synopsis: fkctr[P1]+=P2 */
15154
-#define OP_MemMax 148 /* synopsis: r[P1]=max(r[P1],r[P2]) */
15155
-#define OP_OffsetLimit 149 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */
15184
+#define OP_Close 116
15185
+#define OP_ColumnsUsed 117
15186
+#define OP_SeekHit 118 /* synopsis: seekHit=P2 */
15187
+#define OP_Sequence 119 /* synopsis: r[P2]=cursor[P1].ctr++ */
15188
+#define OP_NewRowid 120 /* synopsis: r[P2]=rowid */
15189
+#define OP_Insert 121 /* synopsis: intkey=r[P3] data=r[P2] */
15190
+#define OP_Delete 122
15191
+#define OP_ResetCount 123
15192
+#define OP_SorterCompare 124 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
15193
+#define OP_SorterData 125 /* synopsis: r[P2]=data */
15194
+#define OP_RowData 126 /* synopsis: r[P2]=data */
15195
+#define OP_Rowid 127 /* synopsis: r[P2]=rowid */
15196
+#define OP_NullRow 128
15197
+#define OP_SeekEnd 129
15198
+#define OP_SorterInsert 130 /* synopsis: key=r[P2] */
15199
+#define OP_IdxInsert 131 /* synopsis: key=r[P2] */
15200
+#define OP_IdxDelete 132 /* synopsis: key=r[P2@P3] */
15201
+#define OP_DeferredSeek 133 /* synopsis: Move P3 to P1.rowid if needed */
15202
+#define OP_IdxRowid 134 /* synopsis: r[P2]=rowid */
15203
+#define OP_FinishSeek 135
15204
+#define OP_Destroy 136
15205
+#define OP_Clear 137
15206
+#define OP_ResetSorter 138
15207
+#define OP_CreateBtree 139 /* synopsis: r[P2]=root iDb=P1 flags=P3 */
15208
+#define OP_SqlExec 140
15209
+#define OP_ParseSchema 141
15210
+#define OP_LoadAnalysis 142
15211
+#define OP_DropTable 143
15212
+#define OP_DropIndex 144
15213
+#define OP_DropTrigger 145
15214
+#define OP_IntegrityCk 146
15215
+#define OP_RowSetAdd 147 /* synopsis: rowset(P1)=r[P2] */
15216
+#define OP_Param 148
15217
+#define OP_FkCounter 149 /* synopsis: fkctr[P1]+=P2 */
1515615218
#define OP_Real 150 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
15157
-#define OP_AggInverse 151 /* synopsis: accum=r[P3] inverse(r[P2@P5]) */
15158
-#define OP_AggStep 152 /* synopsis: accum=r[P3] step(r[P2@P5]) */
15159
-#define OP_AggStep1 153 /* synopsis: accum=r[P3] step(r[P2@P5]) */
15160
-#define OP_AggValue 154 /* synopsis: r[P3]=value N=P2 */
15161
-#define OP_AggFinal 155 /* synopsis: accum=r[P1] N=P2 */
15162
-#define OP_Expire 156
15163
-#define OP_TableLock 157 /* synopsis: iDb=P1 root=P2 write=P3 */
15164
-#define OP_VBegin 158
15165
-#define OP_VCreate 159
15166
-#define OP_VDestroy 160
15167
-#define OP_VOpen 161
15168
-#define OP_VColumn 162 /* synopsis: r[P3]=vcolumn(P2) */
15169
-#define OP_VRename 163
15170
-#define OP_Pagecount 164
15171
-#define OP_MaxPgcnt 165
15172
-#define OP_Trace 166
15173
-#define OP_CursorHint 167
15174
-#define OP_ReleaseReg 168 /* synopsis: release r[P1@P2] mask P3 */
15175
-#define OP_Noop 169
15176
-#define OP_Explain 170
15177
-#define OP_Abortable 171
15219
+#define OP_MemMax 151 /* synopsis: r[P1]=max(r[P1],r[P2]) */
15220
+#define OP_OffsetLimit 152 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */
15221
+#define OP_AggInverse 153 /* synopsis: accum=r[P3] inverse(r[P2@P5]) */
15222
+#define OP_AggStep 154 /* synopsis: accum=r[P3] step(r[P2@P5]) */
15223
+#define OP_AggStep1 155 /* synopsis: accum=r[P3] step(r[P2@P5]) */
15224
+#define OP_AggValue 156 /* synopsis: r[P3]=value N=P2 */
15225
+#define OP_AggFinal 157 /* synopsis: accum=r[P1] N=P2 */
15226
+#define OP_Expire 158
15227
+#define OP_CursorLock 159
15228
+#define OP_CursorUnlock 160
15229
+#define OP_TableLock 161 /* synopsis: iDb=P1 root=P2 write=P3 */
15230
+#define OP_VBegin 162
15231
+#define OP_VCreate 163
15232
+#define OP_VDestroy 164
15233
+#define OP_VOpen 165
15234
+#define OP_VColumn 166 /* synopsis: r[P3]=vcolumn(P2) */
15235
+#define OP_VRename 167
15236
+#define OP_Pagecount 168
15237
+#define OP_MaxPgcnt 169
15238
+#define OP_Trace 170
15239
+#define OP_CursorHint 171
15240
+#define OP_ReleaseReg 172 /* synopsis: release r[P1@P2] mask P3 */
15241
+#define OP_Noop 173
15242
+#define OP_Explain 174
15243
+#define OP_Abortable 175
1517815244
1517915245
/* Properties such as "out2" or "jump" that are specified in
1518015246
** comments following the "case" for each opcode in the vdbe.c
1518115247
** are encoded into bitvectors as follows:
1518215248
*/
@@ -15188,37 +15254,38 @@
1518815254
#define OPFLG_OUT3 0x20 /* out3: P3 is an output */
1518915255
#define OPFLG_INITIALIZER {\
1519015256
/* 0 */ 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x10,\
1519115257
/* 8 */ 0x00, 0x01, 0x00, 0x01, 0x01, 0x01, 0x03, 0x03,\
1519215258
/* 16 */ 0x01, 0x01, 0x03, 0x12, 0x03, 0x01, 0x09, 0x09,\
15193
-/* 24 */ 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09,\
15194
-/* 32 */ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\
15195
-/* 40 */ 0x01, 0x23, 0x0b, 0x26, 0x26, 0x01, 0x01, 0x03,\
15259
+/* 24 */ 0x09, 0x09, 0x01, 0x09, 0x09, 0x09, 0x09, 0x09,\
15260
+/* 32 */ 0x09, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\
15261
+/* 40 */ 0x01, 0x01, 0x23, 0x26, 0x26, 0x0b, 0x01, 0x01,\
1519615262
/* 48 */ 0x03, 0x03, 0x03, 0x03, 0x0b, 0x0b, 0x0b, 0x0b,\
15197
-/* 56 */ 0x0b, 0x0b, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00,\
15198
-/* 64 */ 0x02, 0x02, 0x08, 0x00, 0x10, 0x10, 0x10, 0x10,\
15199
-/* 72 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x10, 0x10, 0x00,\
15200
-/* 80 */ 0x00, 0x02, 0x02, 0x02, 0x00, 0x00, 0x12, 0x20,\
15201
-/* 88 */ 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00,\
15263
+/* 56 */ 0x0b, 0x0b, 0x01, 0x03, 0x01, 0x01, 0x01, 0x00,\
15264
+/* 64 */ 0x00, 0x02, 0x02, 0x08, 0x00, 0x10, 0x10, 0x10,\
15265
+/* 72 */ 0x10, 0x00, 0x10, 0x10, 0x00, 0x00, 0x10, 0x10,\
15266
+/* 80 */ 0x00, 0x00, 0x02, 0x02, 0x02, 0x00, 0x00, 0x12,\
15267
+/* 88 */ 0x20, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\
1520215268
/* 96 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x26, 0x26, 0x26,\
1520315269
/* 104 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x00,\
15204
-/* 112 */ 0x12, 0x00, 0x00, 0x10, 0x00, 0x00, 0x10, 0x10,\
15205
-/* 120 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,\
15206
-/* 128 */ 0x00, 0x04, 0x04, 0x00, 0x00, 0x10, 0x10, 0x00,\
15207
-/* 136 */ 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
15208
-/* 144 */ 0x00, 0x06, 0x10, 0x00, 0x04, 0x1a, 0x10, 0x00,\
15209
-/* 152 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
15210
-/* 160 */ 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\
15211
-/* 168 */ 0x00, 0x00, 0x00, 0x00,}
15270
+/* 112 */ 0x12, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x10,\
15271
+/* 120 */ 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,\
15272
+/* 128 */ 0x00, 0x00, 0x04, 0x04, 0x00, 0x00, 0x10, 0x00,\
15273
+/* 136 */ 0x10, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00,\
15274
+/* 144 */ 0x00, 0x00, 0x00, 0x06, 0x10, 0x00, 0x10, 0x04,\
15275
+/* 152 */ 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
15276
+/* 160 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
15277
+/* 168 */ 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
15278
+}
1521215279
1521315280
/* The sqlite3P2Values() routine is able to run faster if it knows
1521415281
** the value of the largest JUMP opcode. The smaller the maximum
1521515282
** JUMP opcode the better, so the mkopcodeh.tcl script that
1521615283
** generated this include file strives to group all JUMP opcodes
1521715284
** together near the beginning of the list.
1521815285
*/
15219
-#define SQLITE_MX_JUMP_OPCODE 61 /* Maximum JUMP opcode */
15286
+#define SQLITE_MX_JUMP_OPCODE 62 /* Maximum JUMP opcode */
1522015287
1522115288
/************** End of opcodes.h *********************************************/
1522215289
/************** Continuing where we left off in vdbe.h ***********************/
1522315290
1522415291
/*
@@ -15284,13 +15351,13 @@
1528415351
SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe*, u16 P5);
1528515352
SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe*, int addr);
1528615353
SQLITE_PRIVATE int sqlite3VdbeChangeToNoop(Vdbe*, int addr);
1528715354
SQLITE_PRIVATE int sqlite3VdbeDeletePriorOpcode(Vdbe*, u8 op);
1528815355
#ifdef SQLITE_DEBUG
15289
-SQLITE_PRIVATE void sqlite3VdbeReleaseRegisters(Parse*,int addr, int n, u32 mask);
15356
+SQLITE_PRIVATE void sqlite3VdbeReleaseRegisters(Parse*,int addr, int n, u32 mask, int);
1529015357
#else
15291
-# define sqlite3VdbeReleaseRegisters(P,A,N,M)
15358
+# define sqlite3VdbeReleaseRegisters(P,A,N,M,F)
1529215359
#endif
1529315360
SQLITE_PRIVATE void sqlite3VdbeChangeP4(Vdbe*, int addr, const char *zP4, int N);
1529415361
SQLITE_PRIVATE void sqlite3VdbeAppendP4(Vdbe*, void *pP4, int p4type);
1529515362
SQLITE_PRIVATE void sqlite3VdbeSetP4KeyInfo(Parse*, Index*);
1529615363
SQLITE_PRIVATE void sqlite3VdbeUsesBtree(Vdbe*, int);
@@ -16377,10 +16444,29 @@
1637716444
** New lookaside allocations are only allowed if bDisable==0. When
1637816445
** bDisable is greater than zero, sz is set to zero which effectively
1637916446
** disables lookaside without adding a new test for the bDisable flag
1638016447
** in a performance-critical path. sz should be set by to szTrue whenever
1638116448
** bDisable changes back to zero.
16449
+**
16450
+** Lookaside buffers are initially held on the pInit list. As they are
16451
+** used and freed, they are added back to the pFree list. New allocations
16452
+** come off of pFree first, then pInit as a fallback. This dual-list
16453
+** allows use to compute a high-water mark - the maximum number of allocations
16454
+** outstanding at any point in the past - by subtracting the number of
16455
+** allocations on the pInit list from the total number of allocations.
16456
+**
16457
+** Enhancement on 2019-12-12: Two-size-lookaside
16458
+** The default lookaside configuration is 100 slots of 1200 bytes each.
16459
+** The larger slot sizes are important for performance, but they waste
16460
+** a lot of space, as most lookaside allocations are less than 128 bytes.
16461
+** The two-size-lookaside enhancement breaks up the lookaside allocation
16462
+** into two pools: One of 128-byte slots and the other of the default size
16463
+** (1200-byte) slots. Allocations are filled from the small-pool first,
16464
+** failing over to the full-size pool if that does not work. Thus more
16465
+** lookaside slots are available while also using less memory.
16466
+** This enhancement can be omitted by compiling with
16467
+** SQLITE_OMIT_TWOSIZE_LOOKASIDE.
1638216468
*/
1638316469
struct Lookaside {
1638416470
u32 bDisable; /* Only operate the lookaside when zero */
1638516471
u16 sz; /* Size of each buffer in bytes */
1638616472
u16 szTrue; /* True value of sz, even if disabled */
@@ -16387,10 +16473,16 @@
1638716473
u8 bMalloced; /* True if pStart obtained from sqlite3_malloc() */
1638816474
u32 nSlot; /* Number of lookaside slots allocated */
1638916475
u32 anStat[3]; /* 0: hits. 1: size misses. 2: full misses */
1639016476
LookasideSlot *pInit; /* List of buffers not previously used */
1639116477
LookasideSlot *pFree; /* List of available buffers */
16478
+#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
16479
+ LookasideSlot *pSmallInit; /* List of small buffers not prediously used */
16480
+ LookasideSlot *pSmallFree; /* List of available small buffers */
16481
+ void *pMiddle; /* First byte past end of full-size buffers and
16482
+ ** the first byte of LOOKASIDE_SMALL buffers */
16483
+#endif /* SQLITE_OMIT_TWOSIZE_LOOKASIDE */
1639216484
void *pStart; /* First byte of available memory space */
1639316485
void *pEnd; /* First byte past end of available space */
1639416486
};
1639516487
struct LookasideSlot {
1639616488
LookasideSlot *pNext; /* Next buffer in the list of free buffers */
@@ -16397,10 +16489,17 @@
1639716489
};
1639816490
1639916491
#define DisableLookaside db->lookaside.bDisable++;db->lookaside.sz=0
1640016492
#define EnableLookaside db->lookaside.bDisable--;\
1640116493
db->lookaside.sz=db->lookaside.bDisable?0:db->lookaside.szTrue
16494
+
16495
+/* Size of the smaller allocations in two-size lookside */
16496
+#ifdef SQLITE_OMIT_TWOSIZE_LOOKASIDE
16497
+# define LOOKASIDE_SMALL 0
16498
+#else
16499
+# define LOOKASIDE_SMALL 128
16500
+#endif
1640216501
1640316502
/*
1640416503
** A hash table for built-in function definitions. (Application-defined
1640516504
** functions use a regular table table from hash.h.)
1640616505
**
@@ -16606,10 +16705,17 @@
1660616705
** A macro to discover the encoding of a database.
1660716706
*/
1660816707
#define SCHEMA_ENC(db) ((db)->aDb[0].pSchema->enc)
1660916708
#define ENC(db) ((db)->enc)
1661016709
16710
+/*
16711
+** A u64 constant where the lower 32 bits are all zeros. Only the
16712
+** upper 32 bits are included in the argument. Necessary because some
16713
+** C-compilers still do not accept LL integer literals.
16714
+*/
16715
+#define HI(X) ((u64)(X)<<32)
16716
+
1661116717
/*
1661216718
** Possible values for the sqlite3.flags.
1661316719
**
1661416720
** Value constraints (enforced via assert()):
1661516721
** SQLITE_FullFSync == PAGER_FULLFSYNC
@@ -16621,13 +16727,12 @@
1662116727
#define SQLITE_FullColNames 0x00000004 /* Show full column names on SELECT */
1662216728
#define SQLITE_FullFSync 0x00000008 /* Use full fsync on the backend */
1662316729
#define SQLITE_CkptFullFSync 0x00000010 /* Use full fsync for checkpoint */
1662416730
#define SQLITE_CacheSpill 0x00000020 /* OK to spill pager cache */
1662516731
#define SQLITE_ShortColNames 0x00000040 /* Show short columns names */
16626
-#define SQLITE_CountRows 0x00000080 /* Count rows changed by INSERT, */
16627
- /* DELETE, or UPDATE and return */
16628
- /* the count using a callback. */
16732
+#define SQLITE_TrustedSchema 0x00000080 /* Allow unsafe functions and
16733
+ ** vtabs in the schema definition */
1662916734
#define SQLITE_NullCallback 0x00000100 /* Invoke the callback once if the */
1663016735
/* result set is empty */
1663116736
#define SQLITE_IgnoreChecks 0x00000200 /* Do not enforce check constraints */
1663216737
#define SQLITE_ReadUncommit 0x00000400 /* READ UNCOMMITTED in shared-cache */
1663316738
#define SQLITE_NoCkptOnClose 0x00000800 /* No checkpoint on close()/DETACH */
@@ -16649,13 +16754,15 @@
1664916754
#define SQLITE_NoSchemaError 0x08000000 /* Do not report schema parse errors*/
1665016755
#define SQLITE_Defensive 0x10000000 /* Input SQL is likely hostile */
1665116756
#define SQLITE_DqsDDL 0x20000000 /* dbl-quoted strings allowed in DDL*/
1665216757
#define SQLITE_DqsDML 0x40000000 /* dbl-quoted strings allowed in DML*/
1665316758
#define SQLITE_EnableView 0x80000000 /* Enable the use of views */
16759
+#define SQLITE_CountRows HI(0x00001) /* Count rows changed by INSERT, */
16760
+ /* DELETE, or UPDATE and return */
16761
+ /* the count using a callback. */
1665416762
1665516763
/* Flags used only if debugging */
16656
-#define HI(X) ((u64)(X)<<32)
1665716764
#ifdef SQLITE_DEBUG
1665816765
#define SQLITE_SqlTrace HI(0x0100000) /* Debug print SQL as it executes */
1665916766
#define SQLITE_VdbeListing HI(0x0200000) /* Debug listings of VDBE progs */
1666016767
#define SQLITE_VdbeTrace HI(0x0400000) /* True to trace VDBE execution */
1666116768
#define SQLITE_VdbeAddopTrace HI(0x0800000) /* Trace sqlite3VdbeAddOp() calls */
@@ -16669,10 +16776,11 @@
1666916776
#define DBFLAG_SchemaChange 0x0001 /* Uncommitted Hash table changes */
1667016777
#define DBFLAG_PreferBuiltin 0x0002 /* Preference to built-in funcs */
1667116778
#define DBFLAG_Vacuum 0x0004 /* Currently in a VACUUM */
1667216779
#define DBFLAG_VacuumInto 0x0008 /* Currently running VACUUM INTO */
1667316780
#define DBFLAG_SchemaKnownOk 0x0010 /* Schema is known to be valid */
16781
+#define DBFLAG_InternalFunc 0x0020 /* Allow use of internal functions */
1667416782
1667516783
/*
1667616784
** Bits of the sqlite3.dbOptFlags field that are used by the
1667716785
** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface to
1667816786
** selectively disable various optimizations.
@@ -16776,10 +16884,11 @@
1677616884
** SQLITE_FUNC_MINMAX == NC_MinMaxAgg == SF_MinMaxAgg
1677716885
** SQLITE_FUNC_LENGTH == OPFLAG_LENGTHARG
1677816886
** SQLITE_FUNC_TYPEOF == OPFLAG_TYPEOFARG
1677916887
** SQLITE_FUNC_CONSTANT == SQLITE_DETERMINISTIC from the API
1678016888
** SQLITE_FUNC_DIRECT == SQLITE_DIRECTONLY from the API
16889
+** SQLITE_FUNC_UNSAFE == SQLITE_INNOCUOUS
1678116890
** SQLITE_FUNC_ENCMASK depends on SQLITE_UTF* macros in the API
1678216891
*/
1678316892
#define SQLITE_FUNC_ENCMASK 0x0003 /* SQLITE_UTF8, SQLITE_UTF16BE or UTF16LE */
1678416893
#define SQLITE_FUNC_LIKE 0x0004 /* Candidate for the LIKE optimization */
1678516894
#define SQLITE_FUNC_CASE 0x0008 /* Case-sensitive LIKE-type function */
@@ -16792,16 +16901,26 @@
1679216901
#define SQLITE_FUNC_UNLIKELY 0x0400 /* Built-in unlikely() function */
1679316902
#define SQLITE_FUNC_CONSTANT 0x0800 /* Constant inputs give a constant output */
1679416903
#define SQLITE_FUNC_MINMAX 0x1000 /* True for min() and max() aggregates */
1679516904
#define SQLITE_FUNC_SLOCHNG 0x2000 /* "Slow Change". Value constant during a
1679616905
** single query - might change over time */
16797
-#define SQLITE_FUNC_AFFINITY 0x4000 /* Built-in affinity() function */
16906
+#define SQLITE_FUNC_TEST 0x4000 /* Built-in testing functions */
1679816907
#define SQLITE_FUNC_OFFSET 0x8000 /* Built-in sqlite_offset() function */
1679916908
#define SQLITE_FUNC_WINDOW 0x00010000 /* Built-in window-only function */
1680016909
#define SQLITE_FUNC_INTERNAL 0x00040000 /* For use by NestedParse() only */
1680116910
#define SQLITE_FUNC_DIRECT 0x00080000 /* Not for use in TRIGGERs or VIEWs */
1680216911
#define SQLITE_FUNC_SUBTYPE 0x00100000 /* Result likely to have sub-type */
16912
+#define SQLITE_FUNC_UNSAFE 0x00200000 /* Function has side effects */
16913
+#define SQLITE_FUNC_INLINE 0x00400000 /* Functions implemented in-line */
16914
+
16915
+/* Identifier numbers for each in-line function */
16916
+#define INLINEFUNC_coalesce 0
16917
+#define INLINEFUNC_implies_nonnull_row 1
16918
+#define INLINEFUNC_expr_implies_expr 2
16919
+#define INLINEFUNC_expr_compare 3
16920
+#define INLINEFUNC_affinity 4
16921
+#define INLINEFUNC_unlikely 99 /* Default case */
1680316922
1680416923
/*
1680516924
** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are
1680616925
** used to create the initializers for the FuncDef structures.
1680716926
**
@@ -16813,10 +16932,26 @@
1681316932
** argument bNC is true, then the SQLITE_FUNC_NEEDCOLL flag is set.
1681416933
**
1681516934
** VFUNCTION(zName, nArg, iArg, bNC, xFunc)
1681616935
** Like FUNCTION except it omits the SQLITE_FUNC_CONSTANT flag.
1681716936
**
16937
+** SFUNCTION(zName, nArg, iArg, bNC, xFunc)
16938
+** Like FUNCTION except it omits the SQLITE_FUNC_CONSTANT flag and
16939
+** adds the SQLITE_DIRECTONLY flag.
16940
+**
16941
+** INLINE_FUNC(zName, nArg, iFuncId, mFlags)
16942
+** zName is the name of a function that is implemented by in-line
16943
+** byte code rather than by the usual callbacks. The iFuncId
16944
+** parameter determines the function id. The mFlags parameter is
16945
+** optional SQLITE_FUNC_ flags for this function.
16946
+**
16947
+** TEST_FUNC(zName, nArg, iFuncId, mFlags)
16948
+** zName is the name of a test-only function implemented by in-line
16949
+** byte code rather than by the usual callbacks. The iFuncId
16950
+** parameter determines the function id. The mFlags parameter is
16951
+** optional SQLITE_FUNC_ flags for this function.
16952
+**
1681816953
** DFUNCTION(zName, nArg, iArg, bNC, xFunc)
1681916954
** Like FUNCTION except it omits the SQLITE_FUNC_CONSTANT flag and
1682016955
** adds the SQLITE_FUNC_SLOCHNG flag. Used for date & time functions
1682116956
** and functions like sqlite_version() that can change, but not during
1682216957
** a single query. The iArg is ignored. The user-data is always set
@@ -16852,10 +16987,20 @@
1685216987
{nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
1685316988
SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} }
1685416989
#define VFUNCTION(zName, nArg, iArg, bNC, xFunc) \
1685516990
{nArg, SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
1685616991
SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} }
16992
+#define SFUNCTION(zName, nArg, iArg, bNC, xFunc) \
16993
+ {nArg, SQLITE_UTF8|SQLITE_DIRECTONLY|SQLITE_FUNC_UNSAFE, \
16994
+ SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} }
16995
+#define INLINE_FUNC(zName, nArg, iArg, mFlags) \
16996
+ {nArg, SQLITE_UTF8|SQLITE_FUNC_INLINE|SQLITE_FUNC_CONSTANT|(mFlags), \
16997
+ SQLITE_INT_TO_PTR(iArg), 0, noopFunc, 0, 0, 0, #zName, {0} }
16998
+#define TEST_FUNC(zName, nArg, iArg, mFlags) \
16999
+ {nArg, SQLITE_UTF8|SQLITE_FUNC_INTERNAL|SQLITE_FUNC_TEST| \
17000
+ SQLITE_FUNC_INLINE|SQLITE_FUNC_CONSTANT|(mFlags), \
17001
+ SQLITE_INT_TO_PTR(iArg), 0, noopFunc, 0, 0, 0, #zName, {0} }
1685717002
#define DFUNCTION(zName, nArg, iArg, bNC, xFunc) \
1685817003
{nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8, \
1685917004
0, 0, xFunc, 0, 0, 0, #zName, {0} }
1686017005
#define PURE_DATE(zName, nArg, iArg, bNC, xFunc) \
1686117006
{nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|SQLITE_FUNC_CONSTANT, \
@@ -17068,13 +17213,20 @@
1706817213
sqlite3 *db; /* Database connection associated with this table */
1706917214
Module *pMod; /* Pointer to module implementation */
1707017215
sqlite3_vtab *pVtab; /* Pointer to vtab instance */
1707117216
int nRef; /* Number of pointers to this structure */
1707217217
u8 bConstraint; /* True if constraints are supported */
17218
+ u8 eVtabRisk; /* Riskiness of allowing hacker access */
1707317219
int iSavepoint; /* Depth of the SAVEPOINT stack */
1707417220
VTable *pNext; /* Next in linked list (see above) */
1707517221
};
17222
+
17223
+/* Allowed values for VTable.eVtabRisk
17224
+*/
17225
+#define SQLITE_VTABRISK_Low 0
17226
+#define SQLITE_VTABRISK_Normal 1
17227
+#define SQLITE_VTABRISK_High 2
1707617228
1707717229
/*
1707817230
** The schema for each SQL table and view is represented in memory
1707917231
** by an instance of the following structure.
1708017232
*/
@@ -17672,11 +17824,11 @@
1767217824
#define EP_Subrtn 0x2000000 /* Uses Expr.y.sub. TK_IN, _SELECT, or _EXISTS */
1767317825
#define EP_Quoted 0x4000000 /* TK_ID was originally quoted */
1767417826
#define EP_Static 0x8000000 /* Held in memory not obtained from malloc() */
1767517827
#define EP_IsTrue 0x10000000 /* Always has boolean value of TRUE */
1767617828
#define EP_IsFalse 0x20000000 /* Always has boolean value of FALSE */
17677
-#define EP_Indirect 0x40000000 /* Contained within a TRIGGER or a VIEW */
17829
+#define EP_FromDDL 0x40000000 /* Originates from sqlite_master */
1767817830
1767917831
/*
1768017832
** The EP_Propagate mask is a set of properties that automatically propagate
1768117833
** upwards into parent nodes.
1768217834
*/
@@ -17736,27 +17888,32 @@
1773617888
** as the list of "expr AS ID" fields following a "SELECT" or in the
1773717889
** list of "ID = expr" items in an UPDATE. A list of expressions can
1773817890
** also be used as the argument to a function, in which case the a.zName
1773917891
** field is not used.
1774017892
**
17741
-** By default the Expr.zSpan field holds a human-readable description of
17742
-** the expression that is used in the generation of error messages and
17743
-** column labels. In this case, Expr.zSpan is typically the text of a
17744
-** column expression as it exists in a SELECT statement. However, if
17745
-** the bSpanIsTab flag is set, then zSpan is overloaded to mean the name
17746
-** of the result column in the form: DATABASE.TABLE.COLUMN. This later
17747
-** form is used for name resolution with nested FROM clauses.
17893
+** In order to try to keep memory usage down, the Expr.a.zEName field
17894
+** is used for multiple purposes:
17895
+**
17896
+** eEName Usage
17897
+** ---------- -------------------------
17898
+** ENAME_NAME (1) the AS of result set column
17899
+** (2) COLUMN= of an UPDATE
17900
+**
17901
+** ENAME_TAB DB.TABLE.NAME used to resolve names
17902
+** of subqueries
17903
+**
17904
+** ENAME_SPAN Text of the original result set
17905
+** expression.
1774817906
*/
1774917907
struct ExprList {
1775017908
int nExpr; /* Number of expressions on the list */
1775117909
struct ExprList_item { /* For each expression in the list */
1775217910
Expr *pExpr; /* The parse tree for this expression */
17753
- char *zName; /* Token associated with this expression */
17754
- char *zSpan; /* Original text of the expression */
17911
+ char *zEName; /* Token associated with this expression */
1775517912
u8 sortFlags; /* Mask of KEYINFO_ORDER_* flags */
17913
+ unsigned eEName :2; /* Meaning of zEName */
1775617914
unsigned done :1; /* A flag to indicate when processing is finished */
17757
- unsigned bSpanIsTab :1; /* zSpan holds DB.TABLE.COLUMN */
1775817915
unsigned reusable :1; /* Constant expression is reusable */
1775917916
unsigned bSorterRef :1; /* Defer evaluation until after sorting */
1776017917
unsigned bNulls: 1; /* True if explicit "NULLS FIRST/LAST" */
1776117918
union {
1776217919
struct {
@@ -17766,10 +17923,17 @@
1776617923
int iConstExprReg; /* Register in which Expr value is cached */
1776717924
} u;
1776817925
} a[1]; /* One slot for each expression in the list */
1776917926
};
1777017927
17928
+/*
17929
+** Allowed values for Expr.a.eEName
17930
+*/
17931
+#define ENAME_NAME 0 /* The AS clause of a result set */
17932
+#define ENAME_SPAN 1 /* Complete text of the result set expression */
17933
+#define ENAME_TAB 2 /* "DB.TABLE.NAME" for the result set */
17934
+
1777117935
/*
1777217936
** An instance of this structure can hold a simple list of identifiers,
1777317937
** such as the list "a,b,c" in the following statements:
1777417938
**
1777517939
** INSERT INTO t(a,b,c) VALUES ...;
@@ -17829,10 +17993,11 @@
1782917993
unsigned isIndexedBy :1; /* True if there is an INDEXED BY clause */
1783017994
unsigned isTabFunc :1; /* True if table-valued-function syntax */
1783117995
unsigned isCorrelated :1; /* True if sub-query is correlated */
1783217996
unsigned viaCoroutine :1; /* Implemented as a co-routine */
1783317997
unsigned isRecursive :1; /* True for recursive reference in WITH */
17998
+ unsigned fromDDL :1; /* Comes from sqlite_master */
1783417999
} fg;
1783518000
int iCursor; /* The VDBE cursor number used to access this table */
1783618001
Expr *pOn; /* The ON clause of a join */
1783718002
IdList *pUsing; /* The USING clause of a join */
1783818003
Bitmask colUsed; /* Bit N (1<<N) set if column N of pTab is used */
@@ -17949,10 +18114,11 @@
1794918114
#define NC_Complex 0x02000 /* True if a function or subquery seen */
1795018115
#define NC_AllowWin 0x04000 /* Window functions are allowed here */
1795118116
#define NC_HasWin 0x08000 /* One or more window functions seen */
1795218117
#define NC_IsDDL 0x10000 /* Resolving names in a CREATE statement */
1795318118
#define NC_InAggFunc 0x20000 /* True if analyzing arguments to an agg func */
18119
+#define NC_FromDDL 0x40000 /* SQL text comes from sqlite_master */
1795418120
1795518121
/*
1795618122
** An instance of the following object describes a single ON CONFLICT
1795718123
** clause in an upsert.
1795818124
**
@@ -18504,11 +18670,11 @@
1850418670
*/
1850518671
typedef struct DbFixer DbFixer;
1850618672
struct DbFixer {
1850718673
Parse *pParse; /* The parsing context. Error messages written here */
1850818674
Schema *pSchema; /* Fix items to this schema */
18509
- int bVarOnly; /* Check for variable references only */
18675
+ u8 bTemp; /* True for TEMP schema entries */
1851018676
const char *zDb; /* Make sure all objects are contained in this database */
1851118677
const char *zType; /* Type of the container - used for error messages */
1851218678
const Token *pName; /* Name of the container - used for error messages */
1851318679
};
1851418680
@@ -18609,11 +18775,10 @@
1860918775
#endif
1861018776
#ifndef SQLITE_UNTESTABLE
1861118777
int (*xTestCallback)(int); /* Invoked by sqlite3FaultSim() */
1861218778
#endif
1861318779
int bLocaltimeFault; /* True to fail localtime() calls */
18614
- int bInternalFunctions; /* Internal SQL functions are visible */
1861518780
int iOnceResetThreshold; /* When to reset OP_Once counters */
1861618781
u32 szSorterRef; /* Min size in bytes to use sorter-refs */
1861718782
unsigned int iPrngSeed; /* Alternative fixed seed for the PRNG */
1861818783
};
1861918784
@@ -18772,11 +18937,11 @@
1877218937
SQLITE_PRIVATE void sqlite3WindowListDelete(sqlite3 *db, Window *p);
1877318938
SQLITE_PRIVATE Window *sqlite3WindowAlloc(Parse*, int, int, Expr*, int , Expr*, u8);
1877418939
SQLITE_PRIVATE void sqlite3WindowAttach(Parse*, Expr*, Window*);
1877518940
SQLITE_PRIVATE void sqlite3WindowLink(Select *pSel, Window *pWin);
1877618941
SQLITE_PRIVATE int sqlite3WindowCompare(Parse*, Window*, Window*, int);
18777
-SQLITE_PRIVATE void sqlite3WindowCodeInit(Parse*, Window*);
18942
+SQLITE_PRIVATE void sqlite3WindowCodeInit(Parse*, Select*);
1877818943
SQLITE_PRIVATE void sqlite3WindowCodeStep(Parse*, Select*, WhereInfo*, int, int);
1877918944
SQLITE_PRIVATE int sqlite3WindowRewrite(Parse*, Select*);
1878018945
SQLITE_PRIVATE int sqlite3ExpandSubquery(Parse*, struct SrcList_item*);
1878118946
SQLITE_PRIVATE void sqlite3WindowUpdate(Parse*, Window*, Window*, FuncDef*);
1878218947
SQLITE_PRIVATE Window *sqlite3WindowDup(sqlite3 *db, Expr *pOwner, Window *p);
@@ -19038,10 +19203,11 @@
1903819203
SQLITE_PRIVATE Expr *sqlite3PExpr(Parse*, int, Expr*, Expr*);
1903919204
SQLITE_PRIVATE void sqlite3PExprAddSelect(Parse*, Expr*, Select*);
1904019205
SQLITE_PRIVATE Expr *sqlite3ExprAnd(Parse*,Expr*, Expr*);
1904119206
SQLITE_PRIVATE Expr *sqlite3ExprSimplifiedAndOr(Expr*);
1904219207
SQLITE_PRIVATE Expr *sqlite3ExprFunction(Parse*,ExprList*, Token*, int);
19208
+SQLITE_PRIVATE void sqlite3ExprFunctionUsable(Parse*,Expr*,FuncDef*);
1904319209
SQLITE_PRIVATE void sqlite3ExprAssignVarNumber(Parse*, Expr*, u32);
1904419210
SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3*, Expr*);
1904519211
SQLITE_PRIVATE void sqlite3ExprUnmapAndDelete(Parse*, Expr*);
1904619212
SQLITE_PRIVATE ExprList *sqlite3ExprListAppend(Parse*,ExprList*,Expr*);
1904719213
SQLITE_PRIVATE ExprList *sqlite3ExprListAppendVector(Parse*,ExprList*,IdList*,Expr*);
@@ -19195,10 +19361,11 @@
1919519361
SQLITE_PRIVATE int sqlite3WhereBreakLabel(WhereInfo*);
1919619362
SQLITE_PRIVATE int sqlite3WhereOkOnePass(WhereInfo*, int*);
1919719363
#define ONEPASS_OFF 0 /* Use of ONEPASS not allowed */
1919819364
#define ONEPASS_SINGLE 1 /* ONEPASS valid for a single row update */
1919919365
#define ONEPASS_MULTI 2 /* ONEPASS is valid for multiple rows */
19366
+SQLITE_PRIVATE int sqlite3WhereUsesDeferredSeek(WhereInfo*);
1920019367
SQLITE_PRIVATE void sqlite3ExprCodeLoadIndexColumn(Parse*, Index*, int, int, int);
1920119368
SQLITE_PRIVATE int sqlite3ExprCodeGetColumn(Parse*, Table*, int, int, int, u8);
1920219369
SQLITE_PRIVATE void sqlite3ExprCodeGetColumnOfTable(Vdbe*, Table*, int, int, int);
1920319370
SQLITE_PRIVATE void sqlite3ExprCodeMove(Parse*, int, int, int);
1920419371
SQLITE_PRIVATE void sqlite3ExprCode(Parse*, Expr*, int);
@@ -19249,10 +19416,11 @@
1924919416
SQLITE_PRIVATE void sqlite3BeginTransaction(Parse*, int);
1925019417
SQLITE_PRIVATE void sqlite3EndTransaction(Parse*,int);
1925119418
SQLITE_PRIVATE void sqlite3Savepoint(Parse*, int, Token*);
1925219419
SQLITE_PRIVATE void sqlite3CloseSavepoints(sqlite3 *);
1925319420
SQLITE_PRIVATE void sqlite3LeaveMutexAndCloseZombie(sqlite3*);
19421
+SQLITE_PRIVATE u32 sqlite3IsTrueOrFalse(const char*);
1925419422
SQLITE_PRIVATE int sqlite3ExprIdToTrueFalse(Expr*);
1925519423
SQLITE_PRIVATE int sqlite3ExprTruthValue(const Expr*);
1925619424
SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr*);
1925719425
SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr*);
1925819426
SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*, u8);
@@ -19505,11 +19673,16 @@
1950519673
SQLITE_PRIVATE void sqlite3ExpirePreparedStatements(sqlite3*, int);
1950619674
SQLITE_PRIVATE void sqlite3CodeRhsOfIN(Parse*, Expr*, int);
1950719675
SQLITE_PRIVATE int sqlite3CodeSubselect(Parse*, Expr*);
1950819676
SQLITE_PRIVATE void sqlite3SelectPrep(Parse*, Select*, NameContext*);
1950919677
SQLITE_PRIVATE void sqlite3SelectWrongNumTermsError(Parse *pParse, Select *p);
19510
-SQLITE_PRIVATE int sqlite3MatchSpanName(const char*, const char*, const char*, const char*);
19678
+SQLITE_PRIVATE int sqlite3MatchEName(
19679
+ const struct ExprList_item*,
19680
+ const char*,
19681
+ const char*,
19682
+ const char*
19683
+);
1951119684
SQLITE_PRIVATE int sqlite3ResolveExprNames(NameContext*, Expr*);
1951219685
SQLITE_PRIVATE int sqlite3ResolveExprListNames(NameContext*, ExprList*);
1951319686
SQLITE_PRIVATE void sqlite3ResolveSelectNames(Parse*, Select*, NameContext*);
1951419687
SQLITE_PRIVATE int sqlite3ResolveSelfReference(Parse*,Table*,int,Expr*,ExprList*);
1951519688
SQLITE_PRIVATE int sqlite3ResolveOrderGroupBy(Parse*, Select*, ExprList*, const char*);
@@ -19977,11 +20150,10 @@
1997720150
** Bit 0x40 is set if the character is non-alphanumeric and can be used in an
1997820151
** SQLite identifier. Identifiers are alphanumerics, "_", "$", and any
1997920152
** non-ASCII UTF character. Hence the test for whether or not a character is
1998020153
** part of an identifier is 0x46.
1998120154
*/
19982
-#ifdef SQLITE_ASCII
1998320155
SQLITE_PRIVATE const unsigned char sqlite3CtypeMap[256] = {
1998420156
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 00..07 ........ */
1998520157
0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, /* 08..0f ........ */
1998620158
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 10..17 ........ */
1998720159
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 18..1f ........ */
@@ -20015,11 +20187,10 @@
2001520187
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* e0..e7 ........ */
2001620188
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* e8..ef ........ */
2001720189
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* f0..f7 ........ */
2001820190
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40 /* f8..ff ........ */
2001920191
};
20020
-#endif
2002120192
2002220193
/* EVIDENCE-OF: R-02982-34736 In order to maintain full backwards
2002320194
** compatibility for legacy applications, the URI filename capability is
2002420195
** disabled by default.
2002520196
**
@@ -20080,13 +20251,22 @@
2008020251
** number of bytes in each lookaside slot (should be a multiple of 8)
2008120252
** and N is the number of slots. The lookaside-configuration can be
2008220253
** changed as start-time using sqlite3_config(SQLITE_CONFIG_LOOKASIDE)
2008320254
** or at run-time for an individual database connection using
2008420255
** sqlite3_db_config(db, SQLITE_DBCONFIG_LOOKASIDE);
20256
+**
20257
+** With the two-size-lookaside enhancement, less lookaside is required.
20258
+** The default configuration of 1200,40 actually provides 30 1200-byte slots
20259
+** and 93 128-byte slots, which is more lookaside than is available
20260
+** using the older 1200,100 configuration without two-size-lookaside.
2008520261
*/
2008620262
#ifndef SQLITE_DEFAULT_LOOKASIDE
20087
-# define SQLITE_DEFAULT_LOOKASIDE 1200,100
20263
+# ifdef SQLITE_OMIT_TWOSIZE_LOOKASIDE
20264
+# define SQLITE_DEFAULT_LOOKASIDE 1200,100 /* 120KB of memory */
20265
+# else
20266
+# define SQLITE_DEFAULT_LOOKASIDE 1200,40 /* 48KB of memory */
20267
+# endif
2008820268
#endif
2008920269
2009020270
2009120271
/* The default maximum size of an in-memory database created using
2009220272
** sqlite3_deserialize()
@@ -20148,11 +20328,10 @@
2014820328
#endif
2014920329
#ifndef SQLITE_UNTESTABLE
2015020330
0, /* xTestCallback */
2015120331
#endif
2015220332
0, /* bLocaltimeFault */
20153
- 0, /* bInternalFunctions */
2015420333
0x7ffffffe, /* iOnceResetThreshold */
2015520334
SQLITE_DEFAULT_SORTERREF_SIZE, /* szSorterRef */
2015620335
0, /* iPrngSeed */
2015720336
};
2015820337
@@ -20710,10 +20889,11 @@
2071020889
** Function prototypes
2071120890
*/
2071220891
SQLITE_PRIVATE void sqlite3VdbeError(Vdbe*, const char *, ...);
2071320892
SQLITE_PRIVATE void sqlite3VdbeFreeCursor(Vdbe *, VdbeCursor*);
2071420893
void sqliteVdbePopStack(Vdbe*,int);
20894
+SQLITE_PRIVATE int SQLITE_NOINLINE sqlite3VdbeFinishMoveto(VdbeCursor*);
2071520895
SQLITE_PRIVATE int sqlite3VdbeCursorMoveto(VdbeCursor**, int*);
2071620896
SQLITE_PRIVATE int sqlite3VdbeCursorRestore(VdbeCursor*);
2071720897
SQLITE_PRIVATE u32 sqlite3VdbeSerialTypeLen(u32);
2071820898
SQLITE_PRIVATE u8 sqlite3VdbeOneByteSerialTypeLen(u8);
2071920899
SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(unsigned char*, Mem*, u32);
@@ -20822,11 +21002,11 @@
2082221002
# define sqlite3VdbeCheckFk(p,i) 0
2082321003
#endif
2082421004
2082521005
#ifdef SQLITE_DEBUG
2082621006
SQLITE_PRIVATE void sqlite3VdbePrintSql(Vdbe*);
20827
-SQLITE_PRIVATE void sqlite3VdbeMemPrettyPrint(Mem *pMem, char *zBuf);
21007
+SQLITE_PRIVATE void sqlite3VdbeMemPrettyPrint(Mem *pMem, StrAccum *pStr);
2082821008
#endif
2082921009
#ifndef SQLITE_OMIT_UTF16
2083021010
SQLITE_PRIVATE int sqlite3VdbeMemTranslate(Mem*, u8);
2083121011
SQLITE_PRIVATE int sqlite3VdbeMemHandleBom(Mem *pMem);
2083221012
#endif
@@ -21014,10 +21194,14 @@
2101421194
** Count the number of slots of lookaside memory that are outstanding
2101521195
*/
2101621196
SQLITE_PRIVATE int sqlite3LookasideUsed(sqlite3 *db, int *pHighwater){
2101721197
u32 nInit = countLookasideSlots(db->lookaside.pInit);
2101821198
u32 nFree = countLookasideSlots(db->lookaside.pFree);
21199
+#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
21200
+ nInit += countLookasideSlots(db->lookaside.pSmallInit);
21201
+ nFree += countLookasideSlots(db->lookaside.pSmallFree);
21202
+#endif /* SQLITE_OMIT_TWOSIZE_LOOKASIDE */
2101921203
if( pHighwater ) *pHighwater = db->lookaside.nSlot - nInit;
2102021204
return db->lookaside.nSlot - (nInit+nFree);
2102121205
}
2102221206
2102321207
/*
@@ -21046,10 +21230,19 @@
2104621230
while( p->pNext ) p = p->pNext;
2104721231
p->pNext = db->lookaside.pInit;
2104821232
db->lookaside.pInit = db->lookaside.pFree;
2104921233
db->lookaside.pFree = 0;
2105021234
}
21235
+#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
21236
+ p = db->lookaside.pSmallFree;
21237
+ if( p ){
21238
+ while( p->pNext ) p = p->pNext;
21239
+ p->pNext = db->lookaside.pSmallInit;
21240
+ db->lookaside.pSmallInit = db->lookaside.pSmallFree;
21241
+ db->lookaside.pSmallFree = 0;
21242
+ }
21243
+#endif
2105121244
}
2105221245
break;
2105321246
}
2105421247
2105521248
case SQLITE_DBSTATUS_LOOKASIDE_HIT:
@@ -27142,28 +27335,46 @@
2714227335
** sqlite3Malloc() or sqlite3_malloc().
2714327336
*/
2714427337
SQLITE_PRIVATE int sqlite3MallocSize(void *p){
2714527338
assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
2714627339
return sqlite3GlobalConfig.m.xSize(p);
27340
+}
27341
+static int lookasideMallocSize(sqlite3 *db, void *p){
27342
+#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
27343
+ return p<db->lookaside.pMiddle ? db->lookaside.szTrue : LOOKASIDE_SMALL;
27344
+#else
27345
+ return db->lookaside.szTrue;
27346
+#endif
2714727347
}
2714827348
SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, void *p){
2714927349
assert( p!=0 );
27350
+#ifdef SQLITE_DEBUG
2715027351
if( db==0 || !isLookaside(db,p) ){
27151
-#ifdef SQLITE_DEBUG
2715227352
if( db==0 ){
2715327353
assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) );
2715427354
assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
2715527355
}else{
2715627356
assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
2715727357
assert( sqlite3MemdebugNoType(p, (u8)~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
2715827358
}
27359
+ }
2715927360
#endif
27160
- return sqlite3GlobalConfig.m.xSize(p);
27161
- }else{
27162
- assert( sqlite3_mutex_held(db->mutex) );
27163
- return db->lookaside.szTrue;
27361
+ if( db ){
27362
+ if( ((uptr)p)<(uptr)(db->lookaside.pEnd) ){
27363
+#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
27364
+ if( ((uptr)p)>=(uptr)(db->lookaside.pMiddle) ){
27365
+ assert( sqlite3_mutex_held(db->mutex) );
27366
+ return LOOKASIDE_SMALL;
27367
+ }
27368
+#endif
27369
+ if( ((uptr)p)>=(uptr)(db->lookaside.pStart) ){
27370
+ assert( sqlite3_mutex_held(db->mutex) );
27371
+ return db->lookaside.szTrue;
27372
+ }
27373
+ }
2716427374
}
27375
+ return sqlite3GlobalConfig.m.xSize(p);
2716527376
}
2716627377
SQLITE_API sqlite3_uint64 sqlite3_msize(void *p){
2716727378
assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) );
2716827379
assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
2716927380
return p ? sqlite3GlobalConfig.m.xSize(p) : 0;
@@ -27206,19 +27417,31 @@
2720627417
if( db ){
2720727418
if( db->pnBytesFreed ){
2720827419
measureAllocationSize(db, p);
2720927420
return;
2721027421
}
27211
- if( isLookaside(db, p) ){
27212
- LookasideSlot *pBuf = (LookasideSlot*)p;
27422
+ if( ((uptr)p)<(uptr)(db->lookaside.pEnd) ){
27423
+#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
27424
+ if( ((uptr)p)>=(uptr)(db->lookaside.pMiddle) ){
27425
+ LookasideSlot *pBuf = (LookasideSlot*)p;
2721327426
#ifdef SQLITE_DEBUG
27214
- /* Trash all content in the buffer being freed */
27215
- memset(p, 0xaa, db->lookaside.szTrue);
27427
+ memset(p, 0xaa, LOOKASIDE_SMALL); /* Trash freed content */
2721627428
#endif
27217
- pBuf->pNext = db->lookaside.pFree;
27218
- db->lookaside.pFree = pBuf;
27219
- return;
27429
+ pBuf->pNext = db->lookaside.pSmallFree;
27430
+ db->lookaside.pSmallFree = pBuf;
27431
+ return;
27432
+ }
27433
+#endif /* SQLITE_OMIT_TWOSIZE_LOOKASIDE */
27434
+ if( ((uptr)p)>=(uptr)(db->lookaside.pStart) ){
27435
+ LookasideSlot *pBuf = (LookasideSlot*)p;
27436
+#ifdef SQLITE_DEBUG
27437
+ memset(p, 0xaa, db->lookaside.szTrue); /* Trash freed content */
27438
+#endif
27439
+ pBuf->pNext = db->lookaside.pFree;
27440
+ db->lookaside.pFree = pBuf;
27441
+ return;
27442
+ }
2722027443
}
2722127444
}
2722227445
assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
2722327446
assert( sqlite3MemdebugNoType(p, (u8)~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
2722427447
assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
@@ -27371,15 +27594,31 @@
2737127594
LookasideSlot *pBuf;
2737227595
assert( db!=0 );
2737327596
assert( sqlite3_mutex_held(db->mutex) );
2737427597
assert( db->pnBytesFreed==0 );
2737527598
if( n>db->lookaside.sz ){
27376
- if( db->lookaside.bDisable ){
27377
- return db->mallocFailed ? 0 : dbMallocRawFinish(db, n);
27599
+ if( !db->lookaside.bDisable ){
27600
+ db->lookaside.anStat[1]++;
27601
+ }else if( db->mallocFailed ){
27602
+ return 0;
2737827603
}
27379
- db->lookaside.anStat[1]++;
27380
- }else if( (pBuf = db->lookaside.pFree)!=0 ){
27604
+ return dbMallocRawFinish(db, n);
27605
+ }
27606
+#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
27607
+ if( n<=LOOKASIDE_SMALL ){
27608
+ if( (pBuf = db->lookaside.pSmallFree)!=0 ){
27609
+ db->lookaside.pSmallFree = pBuf->pNext;
27610
+ db->lookaside.anStat[0]++;
27611
+ return (void*)pBuf;
27612
+ }else if( (pBuf = db->lookaside.pSmallInit)!=0 ){
27613
+ db->lookaside.pSmallInit = pBuf->pNext;
27614
+ db->lookaside.anStat[0]++;
27615
+ return (void*)pBuf;
27616
+ }
27617
+ }
27618
+#endif
27619
+ if( (pBuf = db->lookaside.pFree)!=0 ){
2738127620
db->lookaside.pFree = pBuf->pNext;
2738227621
db->lookaside.anStat[0]++;
2738327622
return (void*)pBuf;
2738427623
}else if( (pBuf = db->lookaside.pInit)!=0 ){
2738527624
db->lookaside.pInit = pBuf->pNext;
@@ -27408,11 +27647,20 @@
2740827647
*/
2740927648
SQLITE_PRIVATE void *sqlite3DbRealloc(sqlite3 *db, void *p, u64 n){
2741027649
assert( db!=0 );
2741127650
if( p==0 ) return sqlite3DbMallocRawNN(db, n);
2741227651
assert( sqlite3_mutex_held(db->mutex) );
27413
- if( isLookaside(db,p) && n<=db->lookaside.szTrue ) return p;
27652
+ if( ((uptr)p)<(uptr)db->lookaside.pEnd ){
27653
+#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
27654
+ if( ((uptr)p)>=(uptr)db->lookaside.pMiddle ){
27655
+ if( n<=LOOKASIDE_SMALL ) return p;
27656
+ }else
27657
+#endif
27658
+ if( ((uptr)p)>=(uptr)db->lookaside.pStart ){
27659
+ if( n<=db->lookaside.szTrue ) return p;
27660
+ }
27661
+ }
2741427662
return dbReallocFinish(db, p, n);
2741527663
}
2741627664
static SQLITE_NOINLINE void *dbReallocFinish(sqlite3 *db, void *p, u64 n){
2741727665
void *pNew = 0;
2741827666
assert( db!=0 );
@@ -27419,11 +27667,11 @@
2741927667
assert( p!=0 );
2742027668
if( db->mallocFailed==0 ){
2742127669
if( isLookaside(db, p) ){
2742227670
pNew = sqlite3DbMallocRawNN(db, n);
2742327671
if( pNew ){
27424
- memcpy(pNew, p, db->lookaside.szTrue);
27672
+ memcpy(pNew, p, lookasideMallocSize(db, p));
2742527673
sqlite3DbFree(db, p);
2742627674
}
2742727675
}else{
2742827676
assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
2742927677
assert( sqlite3MemdebugNoType(p, (u8)~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
@@ -28985,11 +29233,11 @@
2898529233
sqlite3_str_appendf(&x, "%s", pCte->zName);
2898629234
if( pCte->pCols && pCte->pCols->nExpr>0 ){
2898729235
char cSep = '(';
2898829236
int j;
2898929237
for(j=0; j<pCte->pCols->nExpr; j++){
28990
- sqlite3_str_appendf(&x, "%c%s", cSep, pCte->pCols->a[j].zName);
29238
+ sqlite3_str_appendf(&x, "%c%s", cSep, pCte->pCols->a[j].zEName);
2899129239
cSep = ',';
2899229240
}
2899329241
sqlite3_str_appendf(&x, ")");
2899429242
}
2899529243
sqlite3_str_appendf(&x, " AS");
@@ -29026,10 +29274,13 @@
2902629274
sqlite3_str_appendf(&x, " (AS %s)", pItem->zAlias);
2902729275
}
2902829276
if( pItem->fg.jointype & JT_LEFT ){
2902929277
sqlite3_str_appendf(&x, " LEFT-JOIN");
2903029278
}
29279
+ if( pItem->fg.fromDDL ){
29280
+ sqlite3_str_appendf(&x, " DDL");
29281
+ }
2903129282
sqlite3StrAccumFinish(&x);
2903229283
sqlite3TreeViewItem(pView, zLine, i<pSrc->nSrc-1);
2903329284
if( pItem->pSelect ){
2903429285
sqlite3TreeViewSelect(pView, pItem->pSelect, 0);
2903529286
}
@@ -29282,18 +29533,21 @@
2928229533
sqlite3TreeViewLine(pView, "nil");
2928329534
sqlite3TreeViewPop(pView);
2928429535
return;
2928529536
}
2928629537
if( pExpr->flags || pExpr->affExpr ){
29538
+ StrAccum x;
29539
+ sqlite3StrAccumInit(&x, 0, zFlgs, sizeof(zFlgs), 0);
29540
+ sqlite3_str_appendf(&x, " fg.af=%x.%c",
29541
+ pExpr->flags, pExpr->affExpr ? pExpr->affExpr : 'n');
2928729542
if( ExprHasProperty(pExpr, EP_FromJoin) ){
29288
- sqlite3_snprintf(sizeof(zFlgs),zFlgs," fg.af=%x.%c iRJT=%d",
29289
- pExpr->flags, pExpr->affExpr ? pExpr->affExpr : 'n',
29290
- pExpr->iRightJoinTable);
29291
- }else{
29292
- sqlite3_snprintf(sizeof(zFlgs),zFlgs," fg.af=%x.%c",
29293
- pExpr->flags, pExpr->affExpr ? pExpr->affExpr : 'n');
29543
+ sqlite3_str_appendf(&x, " iRJT=%d", pExpr->iRightJoinTable);
2929429544
}
29545
+ if( ExprHasProperty(pExpr, EP_FromDDL) ){
29546
+ sqlite3_str_appendf(&x, " DDL");
29547
+ }
29548
+ sqlite3StrAccumFinish(&x);
2929529549
}else{
2929629550
zFlgs[0] = 0;
2929729551
}
2929829552
switch( pExpr->op ){
2929929553
case TK_AGG_COLUMN: {
@@ -29445,11 +29699,11 @@
2944529699
pFarg = 0;
2944629700
pWin = 0;
2944729701
}else{
2944829702
pFarg = pExpr->x.pList;
2944929703
#ifndef SQLITE_OMIT_WINDOWFUNC
29450
- pWin = pExpr->y.pWin;
29704
+ pWin = ExprHasProperty(pExpr, EP_WinFunc) ? pExpr->y.pWin : 0;
2945129705
#else
2945229706
pWin = 0;
2945329707
#endif
2945429708
}
2945529709
if( pExpr->op==TK_AGG_FUNCTION ){
@@ -29607,12 +29861,13 @@
2960729861
}else{
2960829862
int i;
2960929863
sqlite3TreeViewLine(pView, "%s", zLabel);
2961029864
for(i=0; i<pList->nExpr; i++){
2961129865
int j = pList->a[i].u.x.iOrderByCol;
29612
- char *zName = pList->a[i].zName;
29866
+ char *zName = pList->a[i].zEName;
2961329867
int moreToFollow = i<pList->nExpr - 1;
29868
+ if( pList->a[i].eEName!=ENAME_NAME ) zName = 0;
2961429869
if( j || zName ){
2961529870
sqlite3TreeViewPush(pView, moreToFollow);
2961629871
moreToFollow = 0;
2961729872
sqlite3TreeViewLine(pView, 0);
2961829873
if( zName ){
@@ -30275,13 +30530,15 @@
3027530530
assert( pMem->enc!=0 );
3027630531
assert( pMem->n>=0 );
3027730532
3027830533
#if defined(TRANSLATE_TRACE) && defined(SQLITE_DEBUG)
3027930534
{
30280
- char zBuf[100];
30281
- sqlite3VdbeMemPrettyPrint(pMem, zBuf);
30282
- fprintf(stderr, "INPUT: %s\n", zBuf);
30535
+ StrAccum acc;
30536
+ char zBuf[1000];
30537
+ sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0);
30538
+ sqlite3VdbeMemPrettyPrint(pMem, &acc);
30539
+ fprintf(stderr, "INPUT: %s\n", sqlite3StrAccumFinish(&acc));
3028330540
}
3028430541
#endif
3028530542
3028630543
/* If the translation is between UTF-16 little and big endian, then
3028730544
** all that is required is to swap the byte order. This case is handled
@@ -30385,13 +30642,15 @@
3038530642
pMem->szMalloc = sqlite3DbMallocSize(pMem->db, pMem->z);
3038630643
3038730644
translate_out:
3038830645
#if defined(TRANSLATE_TRACE) && defined(SQLITE_DEBUG)
3038930646
{
30390
- char zBuf[100];
30391
- sqlite3VdbeMemPrettyPrint(pMem, zBuf);
30392
- fprintf(stderr, "OUTPUT: %s\n", zBuf);
30647
+ StrAccum acc;
30648
+ char zBuf[1000];
30649
+ sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0);
30650
+ sqlite3VdbeMemPrettyPrint(pMem, &acc);
30651
+ fprintf(stderr, "OUTPUT: %s\n", sqlite3StrAccumFinish(&acc));
3039330652
}
3039430653
#endif
3039530654
return SQLITE_OK;
3039630655
}
3039730656
#endif /* SQLITE_OMIT_UTF16 */
@@ -31006,10 +31265,11 @@
3100631265
incr = 1;
3100731266
zEnd = z + length;
3100831267
}else{
3100931268
int i;
3101031269
incr = 2;
31270
+ length &= ~1;
3101131271
assert( SQLITE_UTF16LE==2 && SQLITE_UTF16BE==3 );
3101231272
testcase( enc==SQLITE_UTF16LE );
3101331273
testcase( enc==SQLITE_UTF16BE );
3101431274
for(i=3-enc; i<length && z[i]==0; i+=2){}
3101531275
if( i<length ) eType = -100;
@@ -32543,85 +32803,85 @@
3254332803
/* 21 */ "IfNullRow" OpHelp("if P1.nullRow then r[P3]=NULL, goto P2"),
3254432804
/* 22 */ "SeekLT" OpHelp("key=r[P3@P4]"),
3254532805
/* 23 */ "SeekLE" OpHelp("key=r[P3@P4]"),
3254632806
/* 24 */ "SeekGE" OpHelp("key=r[P3@P4]"),
3254732807
/* 25 */ "SeekGT" OpHelp("key=r[P3@P4]"),
32548
- /* 26 */ "IfNoHope" OpHelp("key=r[P3@P4]"),
32549
- /* 27 */ "NoConflict" OpHelp("key=r[P3@P4]"),
32550
- /* 28 */ "NotFound" OpHelp("key=r[P3@P4]"),
32551
- /* 29 */ "Found" OpHelp("key=r[P3@P4]"),
32552
- /* 30 */ "SeekRowid" OpHelp("intkey=r[P3]"),
32553
- /* 31 */ "NotExists" OpHelp("intkey=r[P3]"),
32554
- /* 32 */ "Last" OpHelp(""),
32555
- /* 33 */ "IfSmaller" OpHelp(""),
32556
- /* 34 */ "SorterSort" OpHelp(""),
32557
- /* 35 */ "Sort" OpHelp(""),
32558
- /* 36 */ "Rewind" OpHelp(""),
32559
- /* 37 */ "IdxLE" OpHelp("key=r[P3@P4]"),
32560
- /* 38 */ "IdxGT" OpHelp("key=r[P3@P4]"),
32561
- /* 39 */ "IdxLT" OpHelp("key=r[P3@P4]"),
32562
- /* 40 */ "IdxGE" OpHelp("key=r[P3@P4]"),
32563
- /* 41 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"),
32564
- /* 42 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
32808
+ /* 26 */ "IfNotOpen" OpHelp("if( !csr[P1] ) goto P2"),
32809
+ /* 27 */ "IfNoHope" OpHelp("key=r[P3@P4]"),
32810
+ /* 28 */ "NoConflict" OpHelp("key=r[P3@P4]"),
32811
+ /* 29 */ "NotFound" OpHelp("key=r[P3@P4]"),
32812
+ /* 30 */ "Found" OpHelp("key=r[P3@P4]"),
32813
+ /* 31 */ "SeekRowid" OpHelp("intkey=r[P3]"),
32814
+ /* 32 */ "NotExists" OpHelp("intkey=r[P3]"),
32815
+ /* 33 */ "Last" OpHelp(""),
32816
+ /* 34 */ "IfSmaller" OpHelp(""),
32817
+ /* 35 */ "SorterSort" OpHelp(""),
32818
+ /* 36 */ "Sort" OpHelp(""),
32819
+ /* 37 */ "Rewind" OpHelp(""),
32820
+ /* 38 */ "IdxLE" OpHelp("key=r[P3@P4]"),
32821
+ /* 39 */ "IdxGT" OpHelp("key=r[P3@P4]"),
32822
+ /* 40 */ "IdxLT" OpHelp("key=r[P3@P4]"),
32823
+ /* 41 */ "IdxGE" OpHelp("key=r[P3@P4]"),
32824
+ /* 42 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"),
3256532825
/* 43 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"),
3256632826
/* 44 */ "And" OpHelp("r[P3]=(r[P1] && r[P2])"),
32567
- /* 45 */ "Program" OpHelp(""),
32568
- /* 46 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
32569
- /* 47 */ "IfPos" OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"),
32570
- /* 48 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]--, goto P2"),
32571
- /* 49 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"),
32827
+ /* 45 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
32828
+ /* 46 */ "Program" OpHelp(""),
32829
+ /* 47 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
32830
+ /* 48 */ "IfPos" OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"),
32831
+ /* 49 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]--, goto P2"),
3257232832
/* 50 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"),
3257332833
/* 51 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"),
3257432834
/* 52 */ "Ne" OpHelp("IF r[P3]!=r[P1]"),
3257532835
/* 53 */ "Eq" OpHelp("IF r[P3]==r[P1]"),
3257632836
/* 54 */ "Gt" OpHelp("IF r[P3]>r[P1]"),
3257732837
/* 55 */ "Le" OpHelp("IF r[P3]<=r[P1]"),
3257832838
/* 56 */ "Lt" OpHelp("IF r[P3]<r[P1]"),
3257932839
/* 57 */ "Ge" OpHelp("IF r[P3]>=r[P1]"),
3258032840
/* 58 */ "ElseNotEq" OpHelp(""),
32581
- /* 59 */ "IncrVacuum" OpHelp(""),
32582
- /* 60 */ "VNext" OpHelp(""),
32583
- /* 61 */ "Init" OpHelp("Start at P2"),
32584
- /* 62 */ "PureFunc" OpHelp("r[P3]=func(r[P2@P5])"),
32585
- /* 63 */ "Function" OpHelp("r[P3]=func(r[P2@P5])"),
32586
- /* 64 */ "Return" OpHelp(""),
32587
- /* 65 */ "EndCoroutine" OpHelp(""),
32588
- /* 66 */ "HaltIfNull" OpHelp("if r[P3]=null halt"),
32589
- /* 67 */ "Halt" OpHelp(""),
32590
- /* 68 */ "Integer" OpHelp("r[P2]=P1"),
32591
- /* 69 */ "Int64" OpHelp("r[P2]=P4"),
32592
- /* 70 */ "String" OpHelp("r[P2]='P4' (len=P1)"),
32593
- /* 71 */ "Null" OpHelp("r[P2..P3]=NULL"),
32594
- /* 72 */ "SoftNull" OpHelp("r[P1]=NULL"),
32595
- /* 73 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"),
32596
- /* 74 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"),
32597
- /* 75 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"),
32598
- /* 76 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"),
32599
- /* 77 */ "SCopy" OpHelp("r[P2]=r[P1]"),
32600
- /* 78 */ "IntCopy" OpHelp("r[P2]=r[P1]"),
32601
- /* 79 */ "ResultRow" OpHelp("output=r[P1@P2]"),
32602
- /* 80 */ "CollSeq" OpHelp(""),
32603
- /* 81 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"),
32604
- /* 82 */ "RealAffinity" OpHelp(""),
32605
- /* 83 */ "Cast" OpHelp("affinity(r[P1])"),
32606
- /* 84 */ "Permutation" OpHelp(""),
32607
- /* 85 */ "Compare" OpHelp("r[P1@P3] <-> r[P2@P3]"),
32608
- /* 86 */ "IsTrue" OpHelp("r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4"),
32609
- /* 87 */ "Offset" OpHelp("r[P3] = sqlite_offset(P1)"),
32610
- /* 88 */ "Column" OpHelp("r[P3]=PX"),
32611
- /* 89 */ "Affinity" OpHelp("affinity(r[P1@P2])"),
32612
- /* 90 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"),
32613
- /* 91 */ "Count" OpHelp("r[P2]=count()"),
32614
- /* 92 */ "ReadCookie" OpHelp(""),
32615
- /* 93 */ "SetCookie" OpHelp(""),
32616
- /* 94 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"),
32617
- /* 95 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
32618
- /* 96 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
32619
- /* 97 */ "OpenDup" OpHelp(""),
32620
- /* 98 */ "OpenAutoindex" OpHelp("nColumn=P2"),
32621
- /* 99 */ "OpenEphemeral" OpHelp("nColumn=P2"),
32622
- /* 100 */ "SorterOpen" OpHelp(""),
32841
+ /* 59 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"),
32842
+ /* 60 */ "IncrVacuum" OpHelp(""),
32843
+ /* 61 */ "VNext" OpHelp(""),
32844
+ /* 62 */ "Init" OpHelp("Start at P2"),
32845
+ /* 63 */ "PureFunc" OpHelp("r[P3]=func(r[P2@P5])"),
32846
+ /* 64 */ "Function" OpHelp("r[P3]=func(r[P2@P5])"),
32847
+ /* 65 */ "Return" OpHelp(""),
32848
+ /* 66 */ "EndCoroutine" OpHelp(""),
32849
+ /* 67 */ "HaltIfNull" OpHelp("if r[P3]=null halt"),
32850
+ /* 68 */ "Halt" OpHelp(""),
32851
+ /* 69 */ "Integer" OpHelp("r[P2]=P1"),
32852
+ /* 70 */ "Int64" OpHelp("r[P2]=P4"),
32853
+ /* 71 */ "String" OpHelp("r[P2]='P4' (len=P1)"),
32854
+ /* 72 */ "Null" OpHelp("r[P2..P3]=NULL"),
32855
+ /* 73 */ "SoftNull" OpHelp("r[P1]=NULL"),
32856
+ /* 74 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"),
32857
+ /* 75 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"),
32858
+ /* 76 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"),
32859
+ /* 77 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"),
32860
+ /* 78 */ "SCopy" OpHelp("r[P2]=r[P1]"),
32861
+ /* 79 */ "IntCopy" OpHelp("r[P2]=r[P1]"),
32862
+ /* 80 */ "ResultRow" OpHelp("output=r[P1@P2]"),
32863
+ /* 81 */ "CollSeq" OpHelp(""),
32864
+ /* 82 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"),
32865
+ /* 83 */ "RealAffinity" OpHelp(""),
32866
+ /* 84 */ "Cast" OpHelp("affinity(r[P1])"),
32867
+ /* 85 */ "Permutation" OpHelp(""),
32868
+ /* 86 */ "Compare" OpHelp("r[P1@P3] <-> r[P2@P3]"),
32869
+ /* 87 */ "IsTrue" OpHelp("r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4"),
32870
+ /* 88 */ "Offset" OpHelp("r[P3] = sqlite_offset(P1)"),
32871
+ /* 89 */ "Column" OpHelp("r[P3]=PX"),
32872
+ /* 90 */ "Affinity" OpHelp("affinity(r[P1@P2])"),
32873
+ /* 91 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"),
32874
+ /* 92 */ "Count" OpHelp("r[P2]=count()"),
32875
+ /* 93 */ "ReadCookie" OpHelp(""),
32876
+ /* 94 */ "SetCookie" OpHelp(""),
32877
+ /* 95 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"),
32878
+ /* 96 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
32879
+ /* 97 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
32880
+ /* 98 */ "OpenDup" OpHelp(""),
32881
+ /* 99 */ "OpenAutoindex" OpHelp("nColumn=P2"),
32882
+ /* 100 */ "OpenEphemeral" OpHelp("nColumn=P2"),
3262332883
/* 101 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"),
3262432884
/* 102 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"),
3262532885
/* 103 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"),
3262632886
/* 104 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"),
3262732887
/* 105 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"),
@@ -32628,71 +32888,75 @@
3262832888
/* 106 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"),
3262932889
/* 107 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"),
3263032890
/* 108 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"),
3263132891
/* 109 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"),
3263232892
/* 110 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
32633
- /* 111 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"),
32893
+ /* 111 */ "SorterOpen" OpHelp(""),
3263432894
/* 112 */ "BitNot" OpHelp("r[P2]= ~r[P1]"),
32635
- /* 113 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"),
32636
- /* 114 */ "Close" OpHelp(""),
32895
+ /* 113 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"),
32896
+ /* 114 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"),
3263732897
/* 115 */ "String8" OpHelp("r[P2]='P4'"),
32638
- /* 116 */ "ColumnsUsed" OpHelp(""),
32639
- /* 117 */ "SeekHit" OpHelp("seekHit=P2"),
32640
- /* 118 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"),
32641
- /* 119 */ "NewRowid" OpHelp("r[P2]=rowid"),
32642
- /* 120 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
32643
- /* 121 */ "Delete" OpHelp(""),
32644
- /* 122 */ "ResetCount" OpHelp(""),
32645
- /* 123 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
32646
- /* 124 */ "SorterData" OpHelp("r[P2]=data"),
32647
- /* 125 */ "RowData" OpHelp("r[P2]=data"),
32648
- /* 126 */ "Rowid" OpHelp("r[P2]=rowid"),
32649
- /* 127 */ "NullRow" OpHelp(""),
32650
- /* 128 */ "SeekEnd" OpHelp(""),
32651
- /* 129 */ "SorterInsert" OpHelp("key=r[P2]"),
32652
- /* 130 */ "IdxInsert" OpHelp("key=r[P2]"),
32653
- /* 131 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
32654
- /* 132 */ "DeferredSeek" OpHelp("Move P3 to P1.rowid if needed"),
32655
- /* 133 */ "IdxRowid" OpHelp("r[P2]=rowid"),
32656
- /* 134 */ "Destroy" OpHelp(""),
32657
- /* 135 */ "Clear" OpHelp(""),
32658
- /* 136 */ "ResetSorter" OpHelp(""),
32659
- /* 137 */ "CreateBtree" OpHelp("r[P2]=root iDb=P1 flags=P3"),
32660
- /* 138 */ "SqlExec" OpHelp(""),
32661
- /* 139 */ "ParseSchema" OpHelp(""),
32662
- /* 140 */ "LoadAnalysis" OpHelp(""),
32663
- /* 141 */ "DropTable" OpHelp(""),
32664
- /* 142 */ "DropIndex" OpHelp(""),
32665
- /* 143 */ "DropTrigger" OpHelp(""),
32666
- /* 144 */ "IntegrityCk" OpHelp(""),
32667
- /* 145 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
32668
- /* 146 */ "Param" OpHelp(""),
32669
- /* 147 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
32670
- /* 148 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
32671
- /* 149 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"),
32898
+ /* 116 */ "Close" OpHelp(""),
32899
+ /* 117 */ "ColumnsUsed" OpHelp(""),
32900
+ /* 118 */ "SeekHit" OpHelp("seekHit=P2"),
32901
+ /* 119 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"),
32902
+ /* 120 */ "NewRowid" OpHelp("r[P2]=rowid"),
32903
+ /* 121 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
32904
+ /* 122 */ "Delete" OpHelp(""),
32905
+ /* 123 */ "ResetCount" OpHelp(""),
32906
+ /* 124 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
32907
+ /* 125 */ "SorterData" OpHelp("r[P2]=data"),
32908
+ /* 126 */ "RowData" OpHelp("r[P2]=data"),
32909
+ /* 127 */ "Rowid" OpHelp("r[P2]=rowid"),
32910
+ /* 128 */ "NullRow" OpHelp(""),
32911
+ /* 129 */ "SeekEnd" OpHelp(""),
32912
+ /* 130 */ "SorterInsert" OpHelp("key=r[P2]"),
32913
+ /* 131 */ "IdxInsert" OpHelp("key=r[P2]"),
32914
+ /* 132 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
32915
+ /* 133 */ "DeferredSeek" OpHelp("Move P3 to P1.rowid if needed"),
32916
+ /* 134 */ "IdxRowid" OpHelp("r[P2]=rowid"),
32917
+ /* 135 */ "FinishSeek" OpHelp(""),
32918
+ /* 136 */ "Destroy" OpHelp(""),
32919
+ /* 137 */ "Clear" OpHelp(""),
32920
+ /* 138 */ "ResetSorter" OpHelp(""),
32921
+ /* 139 */ "CreateBtree" OpHelp("r[P2]=root iDb=P1 flags=P3"),
32922
+ /* 140 */ "SqlExec" OpHelp(""),
32923
+ /* 141 */ "ParseSchema" OpHelp(""),
32924
+ /* 142 */ "LoadAnalysis" OpHelp(""),
32925
+ /* 143 */ "DropTable" OpHelp(""),
32926
+ /* 144 */ "DropIndex" OpHelp(""),
32927
+ /* 145 */ "DropTrigger" OpHelp(""),
32928
+ /* 146 */ "IntegrityCk" OpHelp(""),
32929
+ /* 147 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
32930
+ /* 148 */ "Param" OpHelp(""),
32931
+ /* 149 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
3267232932
/* 150 */ "Real" OpHelp("r[P2]=P4"),
32673
- /* 151 */ "AggInverse" OpHelp("accum=r[P3] inverse(r[P2@P5])"),
32674
- /* 152 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"),
32675
- /* 153 */ "AggStep1" OpHelp("accum=r[P3] step(r[P2@P5])"),
32676
- /* 154 */ "AggValue" OpHelp("r[P3]=value N=P2"),
32677
- /* 155 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
32678
- /* 156 */ "Expire" OpHelp(""),
32679
- /* 157 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
32680
- /* 158 */ "VBegin" OpHelp(""),
32681
- /* 159 */ "VCreate" OpHelp(""),
32682
- /* 160 */ "VDestroy" OpHelp(""),
32683
- /* 161 */ "VOpen" OpHelp(""),
32684
- /* 162 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
32685
- /* 163 */ "VRename" OpHelp(""),
32686
- /* 164 */ "Pagecount" OpHelp(""),
32687
- /* 165 */ "MaxPgcnt" OpHelp(""),
32688
- /* 166 */ "Trace" OpHelp(""),
32689
- /* 167 */ "CursorHint" OpHelp(""),
32690
- /* 168 */ "ReleaseReg" OpHelp("release r[P1@P2] mask P3"),
32691
- /* 169 */ "Noop" OpHelp(""),
32692
- /* 170 */ "Explain" OpHelp(""),
32693
- /* 171 */ "Abortable" OpHelp(""),
32933
+ /* 151 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
32934
+ /* 152 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"),
32935
+ /* 153 */ "AggInverse" OpHelp("accum=r[P3] inverse(r[P2@P5])"),
32936
+ /* 154 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"),
32937
+ /* 155 */ "AggStep1" OpHelp("accum=r[P3] step(r[P2@P5])"),
32938
+ /* 156 */ "AggValue" OpHelp("r[P3]=value N=P2"),
32939
+ /* 157 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
32940
+ /* 158 */ "Expire" OpHelp(""),
32941
+ /* 159 */ "CursorLock" OpHelp(""),
32942
+ /* 160 */ "CursorUnlock" OpHelp(""),
32943
+ /* 161 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
32944
+ /* 162 */ "VBegin" OpHelp(""),
32945
+ /* 163 */ "VCreate" OpHelp(""),
32946
+ /* 164 */ "VDestroy" OpHelp(""),
32947
+ /* 165 */ "VOpen" OpHelp(""),
32948
+ /* 166 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
32949
+ /* 167 */ "VRename" OpHelp(""),
32950
+ /* 168 */ "Pagecount" OpHelp(""),
32951
+ /* 169 */ "MaxPgcnt" OpHelp(""),
32952
+ /* 170 */ "Trace" OpHelp(""),
32953
+ /* 171 */ "CursorHint" OpHelp(""),
32954
+ /* 172 */ "ReleaseReg" OpHelp("release r[P1@P2] mask P3"),
32955
+ /* 173 */ "Noop" OpHelp(""),
32956
+ /* 174 */ "Explain" OpHelp(""),
32957
+ /* 175 */ "Abortable" OpHelp(""),
3269432958
};
3269532959
return azName[i];
3269632960
}
3269732961
#endif
3269832962
@@ -39156,11 +39420,11 @@
3915639420
assert( flags==SQLITE_ACCESS_EXISTS || flags==SQLITE_ACCESS_READWRITE );
3915739421
3915839422
if( flags==SQLITE_ACCESS_EXISTS ){
3915939423
struct stat buf;
3916039424
*pResOut = 0==osStat(zPath, &buf) &&
39161
- (S_ISDIR(buf.st_mode) || buf.st_size>0);
39425
+ (!S_ISREG(buf.st_mode) || buf.st_size>0);
3916239426
}else{
3916339427
*pResOut = osAccess(zPath, W_OK|R_OK)==0;
3916439428
}
3916539429
return SQLITE_OK;
3916639430
}
@@ -52175,10 +52439,11 @@
5217552439
if( pPager->eLock!=UNKNOWN_LOCK ){
5217652440
pPager->eLock = (u8)eLock;
5217752441
}
5217852442
IOTRACE(("UNLOCK %p %d\n", pPager, eLock))
5217952443
}
52444
+ pPager->changeCountDone = pPager->tempFile; /* ticket fb3b3024ea238d5c */
5218052445
return rc;
5218152446
}
5218252447
5218352448
/*
5218452449
** Lock the database file to level eLock, which must be either SHARED_LOCK,
@@ -52896,11 +53161,10 @@
5289653161
/* The pager state may be changed from PAGER_ERROR to PAGER_OPEN here
5289753162
** without clearing the error code. This is intentional - the error
5289853163
** code is cleared and the cache reset in the block below.
5289953164
*/
5290053165
assert( pPager->errCode || pPager->eState!=PAGER_ERROR );
52901
- pPager->changeCountDone = 0;
5290253166
pPager->eState = PAGER_OPEN;
5290353167
}
5290453168
5290553169
/* If Pager.errCode is set, the contents of the pager cache cannot be
5290653170
** trusted. Now that there are no outstanding references to the pager,
@@ -53160,11 +53424,10 @@
5316053424
5316153425
if( !pPager->exclusiveMode
5316253426
&& (!pagerUseWal(pPager) || sqlite3WalExclusiveMode(pPager->pWal, 0))
5316353427
){
5316453428
rc2 = pagerUnlockDb(pPager, SHARED_LOCK);
53165
- pPager->changeCountDone = 0;
5316653429
}
5316753430
pPager->eState = PAGER_READER;
5316853431
pPager->setMaster = 0;
5316953432
5317053433
return (rc==SQLITE_OK?rc2:rc);
@@ -63178,10 +63441,11 @@
6317863441
#define BTCF_ValidNKey 0x02 /* True if info.nKey is valid */
6317963442
#define BTCF_ValidOvfl 0x04 /* True if aOverflow is valid */
6318063443
#define BTCF_AtLast 0x08 /* Cursor is pointing ot the last entry */
6318163444
#define BTCF_Incrblob 0x10 /* True if an incremental I/O handle */
6318263445
#define BTCF_Multiple 0x20 /* Maybe another cursor on the same btree */
63446
+#define BTCF_Pinned 0x40 /* Cursor is busy and cannot be moved */
6318363447
6318463448
/*
6318563449
** Potential values for BtCursor.eState.
6318663450
**
6318763451
** CURSOR_INVALID:
@@ -64343,10 +64607,13 @@
6434364607
6434464608
assert( CURSOR_VALID==pCur->eState || CURSOR_SKIPNEXT==pCur->eState );
6434564609
assert( 0==pCur->pKey );
6434664610
assert( cursorHoldsMutex(pCur) );
6434764611
64612
+ if( pCur->curFlags & BTCF_Pinned ){
64613
+ return SQLITE_CONSTRAINT_PINNED;
64614
+ }
6434864615
if( pCur->eState==CURSOR_SKIPNEXT ){
6434964616
pCur->eState = CURSOR_VALID;
6435064617
}else{
6435164618
pCur->skipNext = 0;
6435264619
}
@@ -65090,20 +65357,20 @@
6509065357
u8 *pEnd = &data[cellOffset + nCell*2];
6509165358
u8 *pAddr;
6509265359
int sz2 = 0;
6509365360
int sz = get2byte(&data[iFree+2]);
6509465361
int top = get2byte(&data[hdr+5]);
65095
- if( top>=iFree ){
65362
+ if( NEVER(top>=iFree) ){
6509665363
return SQLITE_CORRUPT_PAGE(pPage);
6509765364
}
6509865365
if( iFree2 ){
6509965366
if( iFree+sz>iFree2 ) return SQLITE_CORRUPT_PAGE(pPage);
6510065367
sz2 = get2byte(&data[iFree2+2]);
6510165368
if( iFree2+sz2 > usableSize ) return SQLITE_CORRUPT_PAGE(pPage);
6510265369
memmove(&data[iFree+sz+sz2], &data[iFree+sz], iFree2-(iFree+sz));
6510365370
sz += sz2;
65104
- }else if( iFree+sz>usableSize ){
65371
+ }else if( NEVER(iFree+sz>usableSize) ){
6510565372
return SQLITE_CORRUPT_PAGE(pPage);
6510665373
}
6510765374
6510865375
cbrk = top+sz;
6510965376
assert( cbrk+(iFree-top) <= usableSize );
@@ -65291,12 +65558,14 @@
6529165558
testcase( gap+1==top );
6529265559
testcase( gap==top );
6529365560
if( (data[hdr+2] || data[hdr+1]) && gap+2<=top ){
6529465561
u8 *pSpace = pageFindSlot(pPage, nByte, &rc);
6529565562
if( pSpace ){
65563
+ int g2;
6529665564
assert( pSpace+nByte<=data+pPage->pBt->usableSize );
65297
- if( (*pIdx = (int)(pSpace-data))<=gap ){
65565
+ *pIdx = g2 = (int)(pSpace-data);
65566
+ if( NEVER(g2<=gap) ){
6529865567
return SQLITE_CORRUPT_PAGE(pPage);
6529965568
}else{
6530065569
return SQLITE_OK;
6530165570
}
6530265571
}else if( rc ){
@@ -65370,16 +65639,16 @@
6537065639
if( data[iPtr+1]==0 && data[iPtr]==0 ){
6537165640
iFreeBlk = 0; /* Shortcut for the case when the freelist is empty */
6537265641
}else{
6537365642
while( (iFreeBlk = get2byte(&data[iPtr]))<iStart ){
6537465643
if( iFreeBlk<iPtr+4 ){
65375
- if( iFreeBlk==0 ) break;
65644
+ if( ALWAYS(iFreeBlk==0) ) break;
6537665645
return SQLITE_CORRUPT_PAGE(pPage);
6537765646
}
6537865647
iPtr = iFreeBlk;
6537965648
}
65380
- if( iFreeBlk>pPage->pBt->usableSize-4 ){
65649
+ if( iFreeBlk>pPage->pBt->usableSize-4 ){ /* TH3: corrupt081.100 */
6538165650
return SQLITE_CORRUPT_PAGE(pPage);
6538265651
}
6538365652
assert( iFreeBlk>iPtr || iFreeBlk==0 );
6538465653
6538565654
/* At this point:
@@ -65390,11 +65659,11 @@
6539065659
*/
6539165660
if( iFreeBlk && iEnd+3>=iFreeBlk ){
6539265661
nFrag = iFreeBlk - iEnd;
6539365662
if( iEnd>iFreeBlk ) return SQLITE_CORRUPT_PAGE(pPage);
6539465663
iEnd = iFreeBlk + get2byte(&data[iFreeBlk+2]);
65395
- if( iEnd > pPage->pBt->usableSize ){
65664
+ if( NEVER(iEnd > pPage->pBt->usableSize) ){
6539665665
return SQLITE_CORRUPT_PAGE(pPage);
6539765666
}
6539865667
iSize = iEnd - iStart;
6539965668
iFreeBlk = get2byte(&data[iFreeBlk]);
6540065669
}
@@ -65418,11 +65687,12 @@
6541865687
x = get2byte(&data[hdr+5]);
6541965688
if( iStart<=x ){
6542065689
/* The new freeblock is at the beginning of the cell content area,
6542165690
** so just extend the cell content area rather than create another
6542265691
** freelist entry */
65423
- if( iStart<x || iPtr!=hdr+1 ) return SQLITE_CORRUPT_PAGE(pPage);
65692
+ if( iStart<x ) return SQLITE_CORRUPT_PAGE(pPage);
65693
+ if( NEVER(iPtr!=hdr+1) ) return SQLITE_CORRUPT_PAGE(pPage);
6542465694
put2byte(&data[hdr+1], iFreeBlk);
6542565695
put2byte(&data[hdr+5], iEnd);
6542665696
}else{
6542765697
/* Insert the new freeblock into the freelist */
6542865698
put2byte(&data[iPtr], iStart);
@@ -65538,11 +65808,11 @@
6553865808
** freeblocks. */
6553965809
pc = get2byte(&data[hdr+1]);
6554065810
nFree = data[hdr+7] + top; /* Init nFree to non-freeblock free space */
6554165811
if( pc>0 ){
6554265812
u32 next, size;
65543
- if( pc<iCellFirst ){
65813
+ if( pc<top ){
6554465814
/* EVIDENCE-OF: R-55530-52930 In a well-formed b-tree page, there will
6554565815
** always be at least one cell before the first freeblock.
6554665816
*/
6554765817
return SQLITE_CORRUPT_PAGE(pPage);
6554865818
}
@@ -65775,16 +66045,16 @@
6577566045
/*
6577666046
** Return the size of the database file in pages. If there is any kind of
6577766047
** error, return ((unsigned int)-1).
6577866048
*/
6577966049
static Pgno btreePagecount(BtShared *pBt){
66050
+ assert( (pBt->nPage & 0x80000000)==0 || CORRUPT_DB );
6578066051
return pBt->nPage;
6578166052
}
6578266053
SQLITE_PRIVATE u32 sqlite3BtreeLastPage(Btree *p){
6578366054
assert( sqlite3BtreeHoldsMutex(p) );
65784
- assert( ((p->pBt->nPage)&0x80000000)==0 );
65785
- return btreePagecount(p->pBt);
66055
+ return btreePagecount(p->pBt) & 0x7fffffff;
6578666056
}
6578766057
6578866058
/*
6578966059
** Get a page from the pager and initialize it.
6579066060
**
@@ -68205,10 +68475,22 @@
6820568475
assert( pCur->eState==CURSOR_VALID );
6820668476
assert( pCur->curIntKey );
6820768477
getCellInfo(pCur);
6820868478
return pCur->info.nKey;
6820968479
}
68480
+
68481
+/*
68482
+** Pin or unpin a cursor.
68483
+*/
68484
+SQLITE_PRIVATE void sqlite3BtreeCursorPin(BtCursor *pCur){
68485
+ assert( (pCur->curFlags & BTCF_Pinned)==0 );
68486
+ pCur->curFlags |= BTCF_Pinned;
68487
+}
68488
+SQLITE_PRIVATE void sqlite3BtreeCursorUnpin(BtCursor *pCur){
68489
+ assert( (pCur->curFlags & BTCF_Pinned)!=0 );
68490
+ pCur->curFlags &= ~BTCF_Pinned;
68491
+}
6821068492
6821168493
#ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
6821268494
/*
6821368495
** Return the offset into the database file for the start of the
6821468496
** payload to which the cursor is pointing.
@@ -70565,11 +70847,11 @@
7056570847
int k; /* Current slot in pCArray->apEnd[] */
7056670848
u8 *pSrcEnd; /* Current pCArray->apEnd[k] value */
7056770849
7056870850
assert( i<iEnd );
7056970851
j = get2byte(&aData[hdr+5]);
70570
- if( j>(u32)usableSize ){ j = 0; }
70852
+ if( NEVER(j>(u32)usableSize) ){ j = 0; }
7057170853
memcpy(&pTmp[j], &aData[j], usableSize - j);
7057270854
7057370855
for(k=0; pCArray->ixNx[k]<=i && ALWAYS(k<NB*2); k++){}
7057470856
pSrcEnd = pCArray->apEnd[k];
7057570857
@@ -70591,11 +70873,11 @@
7059170873
put2byte(pCellptr, (pData - aData));
7059270874
pCellptr += 2;
7059370875
if( pData < pCellptr ) return SQLITE_CORRUPT_BKPT;
7059470876
memcpy(pData, pCell, sz);
7059570877
assert( sz==pPg->xCellSize(pPg, pCell) || CORRUPT_DB );
70596
- testcase( sz!=pPg->xCellSize(pPg,pCell) );
70878
+ testcase( sz!=pPg->xCellSize(pPg,pCell) )
7059770879
i++;
7059870880
if( i>=iEnd ) break;
7059970881
if( pCArray->ixNx[k]<=i ){
7060070882
k++;
7060170883
pSrcEnd = pCArray->apEnd[k];
@@ -72302,11 +72584,10 @@
7230272584
*/
7230372585
#ifdef SQLITE_DEBUG
7230472586
if( flags & BTREE_SAVEPOSITION ){
7230572587
assert( pCur->curFlags & BTCF_ValidNKey );
7230672588
assert( pX->nKey==pCur->info.nKey );
72307
- assert( pCur->info.nSize!=0 );
7230872589
assert( loc==0 );
7230972590
}
7231072591
#endif
7231172592
7231272593
/* On the other hand, BTREE_SAVEPOSITION==0 does not imply
@@ -75906,27 +76187,34 @@
7590676187
/*
7590776188
** This routine prepares a memory cell for modification by breaking
7590876189
** its link to a shallow copy and by marking any current shallow
7590976190
** copies of this cell as invalid.
7591076191
**
75911
-** This is used for testing and debugging only - to make sure shallow
75912
-** copies are not misused.
76192
+** This is used for testing and debugging only - to help ensure that shallow
76193
+** copies (created by OP_SCopy) are not misused.
7591376194
*/
7591476195
SQLITE_PRIVATE void sqlite3VdbeMemAboutToChange(Vdbe *pVdbe, Mem *pMem){
7591576196
int i;
7591676197
Mem *pX;
75917
- for(i=0, pX=pVdbe->aMem; i<pVdbe->nMem; i++, pX++){
76198
+ for(i=1, pX=pVdbe->aMem+1; i<pVdbe->nMem; i++, pX++){
7591876199
if( pX->pScopyFrom==pMem ){
76200
+ u16 mFlags;
76201
+ if( pVdbe->db->flags & SQLITE_VdbeTrace ){
76202
+ sqlite3DebugPrintf("Invalidate R[%d] due to change in R[%d]\n",
76203
+ (int)(pX - pVdbe->aMem), (int)(pMem - pVdbe->aMem));
76204
+ }
7591976205
/* If pX is marked as a shallow copy of pMem, then verify that
7592076206
** no significant changes have been made to pX since the OP_SCopy.
7592176207
** A significant change would indicated a missed call to this
7592276208
** function for pX. Minor changes, such as adding or removing a
7592376209
** dual type, are allowed, as long as the underlying value is the
7592476210
** same. */
75925
- u16 mFlags = pMem->flags & pX->flags & pX->mScopyFlags;
76211
+ mFlags = pMem->flags & pX->flags & pX->mScopyFlags;
7592676212
assert( (mFlags&(MEM_Int|MEM_IntReal))==0 || pMem->u.i==pX->u.i );
75927
- assert( (mFlags&MEM_Real)==0 || pMem->u.r==pX->u.r );
76213
+ /* assert( (mFlags&MEM_Real)==0 || pMem->u.r==pX->u.r ); */
76214
+ /* ^^ */
76215
+ /* Cannot reliably compare doubles for equality */
7592876216
assert( (mFlags&MEM_Str)==0 || (pMem->n==pX->n && pMem->z==pX->z) );
7592976217
assert( (mFlags&MEM_Blob)==0 || sqlite3BlobCompare(pMem,pX)==0 );
7593076218
7593176219
/* pMem is the register that is changing. But also mark pX as
7593276220
** undefined so that we can quickly detect the shallow-copy error */
@@ -75935,11 +76223,10 @@
7593576223
}
7593676224
}
7593776225
pMem->pScopyFrom = 0;
7593876226
}
7593976227
#endif /* SQLITE_DEBUG */
75940
-
7594176228
7594276229
/*
7594376230
** Make an shallow copy of pFrom into pTo. Prior contents of
7594476231
** pTo are freed. The pFrom->z field is not duplicated. If
7594576232
** pFrom->z is used, then pTo->z points to the same thing as pFrom->z
@@ -76082,14 +76369,23 @@
7608276369
}
7608376370
}
7608476371
7608576372
pMem->n = nByte;
7608676373
pMem->flags = flags;
76087
- pMem->enc = (enc==0 ? SQLITE_UTF8 : enc);
76374
+ if( enc ){
76375
+ pMem->enc = enc;
76376
+#ifdef SQLITE_ENABLE_SESSION
76377
+ }else if( pMem->db==0 ){
76378
+ pMem->enc = SQLITE_UTF8;
76379
+#endif
76380
+ }else{
76381
+ assert( pMem->db!=0 );
76382
+ pMem->enc = ENC(pMem->db);
76383
+ }
7608876384
7608976385
#ifndef SQLITE_OMIT_UTF16
76090
- if( pMem->enc!=SQLITE_UTF8 && sqlite3VdbeMemHandleBom(pMem) ){
76386
+ if( enc>SQLITE_UTF8 && sqlite3VdbeMemHandleBom(pMem) ){
7609176387
return SQLITE_NOMEM_BKPT;
7609276388
}
7609376389
#endif
7609476390
7609576391
if( nByte>iLimit ){
@@ -77040,13 +77336,20 @@
7704077336
}
7704177337
7704277338
#ifdef SQLITE_DEBUG
7704377339
/* This routine is just a convenient place to set a breakpoint that will
7704477340
** fire after each opcode is inserted and displayed using
77045
-** "PRAGMA vdbe_addoptrace=on".
77341
+** "PRAGMA vdbe_addoptrace=on". Parameters "pc" (program counter) and
77342
+** pOp are available to make the breakpoint conditional.
77343
+**
77344
+** Other useful labels for breakpoints include:
77345
+** test_trace_breakpoint(pc,pOp)
77346
+** sqlite3CorruptError(lineno)
77347
+** sqlite3MisuseError(lineno)
77348
+** sqlite3CantopenError(lineno)
7704677349
*/
77047
-static void test_addop_breakpoint(void){
77350
+static void test_addop_breakpoint(int pc, Op *pOp){
7704877351
static int n = 0;
7704977352
n++;
7705077353
}
7705177354
#endif
7705277355
@@ -77095,11 +77398,11 @@
7709577398
pOp->zComment = 0;
7709677399
#endif
7709777400
#ifdef SQLITE_DEBUG
7709877401
if( p->db->flags & SQLITE_VdbeAddopTrace ){
7709977402
sqlite3VdbePrintOp(0, i, &p->aOp[i]);
77100
- test_addop_breakpoint();
77403
+ test_addop_breakpoint(i, &p->aOp[i]);
7710177404
}
7710277405
#endif
7710377406
#ifdef VDBE_PROFILE
7710477407
pOp->cycles = 0;
7710577408
pOp->cnt = 0;
@@ -78037,12 +78340,21 @@
7803778340
#ifdef SQLITE_DEBUG
7803878341
/*
7803978342
** Generate an OP_ReleaseReg opcode to indicate that a range of
7804078343
** registers, except any identified by mask, are no longer in use.
7804178344
*/
78042
-SQLITE_PRIVATE void sqlite3VdbeReleaseRegisters(Parse *pParse, int iFirst, int N, u32 mask){
78345
+SQLITE_PRIVATE void sqlite3VdbeReleaseRegisters(
78346
+ Parse *pParse, /* Parsing context */
78347
+ int iFirst, /* Index of first register to be released */
78348
+ int N, /* Number of registers to release */
78349
+ u32 mask, /* Mask of registers to NOT release */
78350
+ int bUndefine /* If true, mark registers as undefined */
78351
+){
78352
+ if( N==0 ) return;
7804378353
assert( pParse->pVdbe );
78354
+ assert( iFirst>=1 );
78355
+ assert( iFirst+N-1<=pParse->nMem );
7804478356
while( N>0 && (mask&1)!=0 ){
7804578357
mask >>= 1;
7804678358
iFirst++;
7804778359
N--;
7804878360
}
@@ -78050,10 +78362,11 @@
7805078362
mask &= ~MASKBIT32(N-1);
7805178363
N--;
7805278364
}
7805378365
if( N>0 ){
7805478366
sqlite3VdbeAddOp3(pParse->pVdbe, OP_ReleaseReg, iFirst, N, *(int*)&mask);
78367
+ if( bUndefine ) sqlite3VdbeChangeP5(pParse->pVdbe, 1);
7805578368
}
7805678369
}
7805778370
#endif /* SQLITE_DEBUG */
7805878371
7805978372
@@ -80260,11 +80573,11 @@
8026080573
/*
8026180574
** The cursor "p" has a pending seek operation that has not yet been
8026280575
** carried out. Seek the cursor now. If an error occurs, return
8026380576
** the appropriate error code.
8026480577
*/
80265
-static int SQLITE_NOINLINE handleDeferredMoveto(VdbeCursor *p){
80578
+SQLITE_PRIVATE int SQLITE_NOINLINE sqlite3VdbeFinishMoveto(VdbeCursor *p){
8026680579
int res, rc;
8026780580
#ifdef SQLITE_TEST
8026880581
extern int sqlite3_search_count;
8026980582
#endif
8027080583
assert( p->deferredMoveto );
@@ -80332,11 +80645,11 @@
8033280645
if( p->aAltMap && (iMap = p->aAltMap[1+*piCol])>0 ){
8033380646
*pp = p->pAltCursor;
8033480647
*piCol = iMap - 1;
8033580648
return SQLITE_OK;
8033680649
}
80337
- return handleDeferredMoveto(p);
80650
+ return sqlite3VdbeFinishMoveto(p);
8033880651
}
8033980652
if( sqlite3BtreeCursorHasMoved(p->uc.pCursor) ){
8034080653
return handleMovedCursor(p);
8034180654
}
8034280655
return SQLITE_OK;
@@ -84375,10 +84688,30 @@
8437584688
# define UPDATE_MAX_BLOBSIZE(P) updateMaxBlobsize(P)
8437684689
#else
8437784690
# define UPDATE_MAX_BLOBSIZE(P)
8437884691
#endif
8437984692
84693
+#ifdef SQLITE_DEBUG
84694
+/* This routine provides a convenient place to set a breakpoint during
84695
+** tracing with PRAGMA vdbe_trace=on. The breakpoint fires right after
84696
+** each opcode is printed. Variables "pc" (program counter) and pOp are
84697
+** available to add conditionals to the breakpoint. GDB example:
84698
+**
84699
+** break test_trace_breakpoint if pc=22
84700
+**
84701
+** Other useful labels for breakpoints include:
84702
+** test_addop_breakpoint(pc,pOp)
84703
+** sqlite3CorruptError(lineno)
84704
+** sqlite3MisuseError(lineno)
84705
+** sqlite3CantopenError(lineno)
84706
+*/
84707
+static void test_trace_breakpoint(int pc, Op *pOp, Vdbe *v){
84708
+ static int n = 0;
84709
+ n++;
84710
+}
84711
+#endif
84712
+
8438084713
/*
8438184714
** Invoke the VDBE coverage callback, if that callback is defined. This
8438284715
** feature is used for test suite validation only and does not appear an
8438384716
** production builds.
8438484717
**
@@ -84719,16 +85052,13 @@
8471985052
#ifdef SQLITE_DEBUG
8472085053
/*
8472185054
** Write a nice string representation of the contents of cell pMem
8472285055
** into buffer zBuf, length nBuf.
8472385056
*/
84724
-SQLITE_PRIVATE void sqlite3VdbeMemPrettyPrint(Mem *pMem, char *zBuf){
84725
- char *zCsr = zBuf;
85057
+SQLITE_PRIVATE void sqlite3VdbeMemPrettyPrint(Mem *pMem, StrAccum *pStr){
8472685058
int f = pMem->flags;
84727
-
8472885059
static const char *const encnames[] = {"(X)", "(8)", "(16LE)", "(16BE)"};
84729
-
8473085060
if( f&MEM_Blob ){
8473185061
int i;
8473285062
char c;
8473385063
if( f & MEM_Dyn ){
8473485064
c = 'z';
@@ -84740,61 +85070,44 @@
8474085070
c = 'e';
8474185071
assert( (f & (MEM_Static|MEM_Dyn))==0 );
8474285072
}else{
8474385073
c = 's';
8474485074
}
84745
- *(zCsr++) = c;
84746
- *(zCsr++) = 'x';
84747
- sqlite3_snprintf(100, zCsr, "%d[", pMem->n);
84748
- zCsr += sqlite3Strlen30(zCsr);
85075
+ sqlite3_str_appendf(pStr, "%cx[", c);
8474985076
for(i=0; i<25 && i<pMem->n; i++){
84750
- sqlite3_snprintf(100, zCsr, "%02X", ((int)pMem->z[i] & 0xFF));
84751
- zCsr += sqlite3Strlen30(zCsr);
85077
+ sqlite3_str_appendf(pStr, "%02X", ((int)pMem->z[i] & 0xFF));
8475285078
}
84753
- *zCsr++ = '|';
85079
+ sqlite3_str_appendf(pStr, "|");
8475485080
for(i=0; i<25 && i<pMem->n; i++){
8475585081
char z = pMem->z[i];
84756
- if( z<32 || z>126 ) *zCsr++ = '.';
84757
- else *zCsr++ = z;
85082
+ sqlite3_str_appendchar(pStr, 1, (z<32||z>126)?'.':z);
8475885083
}
84759
- *(zCsr++) = ']';
85084
+ sqlite3_str_appendf(pStr,"]");
8476085085
if( f & MEM_Zero ){
84761
- sqlite3_snprintf(100, zCsr,"+%dz",pMem->u.nZero);
84762
- zCsr += sqlite3Strlen30(zCsr);
85086
+ sqlite3_str_appendf(pStr, "+%dz",pMem->u.nZero);
8476385087
}
84764
- *zCsr = '\0';
8476585088
}else if( f & MEM_Str ){
84766
- int j, k;
84767
- zBuf[0] = ' ';
85089
+ int j;
85090
+ int c;
8476885091
if( f & MEM_Dyn ){
84769
- zBuf[1] = 'z';
85092
+ c = 'z';
8477085093
assert( (f & (MEM_Static|MEM_Ephem))==0 );
8477185094
}else if( f & MEM_Static ){
84772
- zBuf[1] = 't';
85095
+ c = 't';
8477385096
assert( (f & (MEM_Dyn|MEM_Ephem))==0 );
8477485097
}else if( f & MEM_Ephem ){
84775
- zBuf[1] = 'e';
85098
+ c = 'e';
8477685099
assert( (f & (MEM_Static|MEM_Dyn))==0 );
8477785100
}else{
84778
- zBuf[1] = 's';
85101
+ c = 's';
8477985102
}
84780
- k = 2;
84781
- sqlite3_snprintf(100, &zBuf[k], "%d", pMem->n);
84782
- k += sqlite3Strlen30(&zBuf[k]);
84783
- zBuf[k++] = '[';
85103
+ sqlite3_str_appendf(pStr, " %c%d[", c, pMem->n);
8478485104
for(j=0; j<25 && j<pMem->n; j++){
8478585105
u8 c = pMem->z[j];
84786
- if( c>=0x20 && c<0x7f ){
84787
- zBuf[k++] = c;
84788
- }else{
84789
- zBuf[k++] = '.';
84790
- }
84791
- }
84792
- zBuf[k++] = ']';
84793
- sqlite3_snprintf(100,&zBuf[k], encnames[pMem->enc]);
84794
- k += sqlite3Strlen30(&zBuf[k]);
84795
- zBuf[k++] = 0;
85106
+ sqlite3_str_appendchar(pStr, 1, (c>=0x20&&c<=0x7f) ? c : '.');
85107
+ }
85108
+ sqlite3_str_appendf(pStr, "]%s", encnames[pMem->enc]);
8479685109
}
8479785110
}
8479885111
#endif
8479985112
8480085113
#ifdef SQLITE_DEBUG
@@ -84817,23 +85130,40 @@
8481785130
printf(" r:%.17g", p->u.r);
8481885131
#endif
8481985132
}else if( sqlite3VdbeMemIsRowSet(p) ){
8482085133
printf(" (rowset)");
8482185134
}else{
84822
- char zBuf[200];
84823
- sqlite3VdbeMemPrettyPrint(p, zBuf);
84824
- printf(" %s", zBuf);
85135
+ StrAccum acc;
85136
+ char zBuf[1000];
85137
+ sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0);
85138
+ sqlite3VdbeMemPrettyPrint(p, &acc);
85139
+ printf(" %s", sqlite3StrAccumFinish(&acc));
8482585140
}
8482685141
if( p->flags & MEM_Subtype ) printf(" subtype=0x%02x", p->eSubtype);
8482785142
}
8482885143
static void registerTrace(int iReg, Mem *p){
84829
- printf("REG[%d] = ", iReg);
85144
+ printf("R[%d] = ", iReg);
8483085145
memTracePrint(p);
85146
+ if( p->pScopyFrom ){
85147
+ printf(" <== R[%d]", (int)(p->pScopyFrom - &p[-iReg]));
85148
+ }
8483185149
printf("\n");
8483285150
sqlite3VdbeCheckMemInvariants(p);
8483385151
}
8483485152
#endif
85153
+
85154
+#ifdef SQLITE_DEBUG
85155
+/*
85156
+** Show the values of all registers in the virtual machine. Used for
85157
+** interactive debugging.
85158
+*/
85159
+SQLITE_PRIVATE void sqlite3VdbeRegisterDump(Vdbe *v){
85160
+ int i;
85161
+ for(i=1; i<v->nMem; i++) registerTrace(i, v->aMem+i);
85162
+}
85163
+#endif /* SQLITE_DEBUG */
85164
+
8483585165
8483685166
#ifdef SQLITE_DEBUG
8483785167
# define REGISTER_TRACE(R,M) if(db->flags&SQLITE_VdbeTrace)registerTrace(R,M)
8483885168
#else
8483985169
# define REGISTER_TRACE(R,M)
@@ -85085,10 +85415,11 @@
8508585415
/* Only allow tracing if SQLITE_DEBUG is defined.
8508685416
*/
8508785417
#ifdef SQLITE_DEBUG
8508885418
if( db->flags & SQLITE_VdbeTrace ){
8508985419
sqlite3VdbePrintOp(stdout, (int)(pOp - aOp), pOp);
85420
+ test_trace_breakpoint((int)(pOp - aOp),pOp,p);
8509085421
}
8509185422
#endif
8509285423
8509385424
8509485425
/* Check to see if we need to simulate an interrupt. This only happens
@@ -85192,10 +85523,24 @@
8519285523
** is sometimes set to 1 instead of 0 as a hint to the command-line shell
8519385524
** that this Goto is the bottom of a loop and that the lines from P2 down
8519485525
** to the current line should be indented for EXPLAIN output.
8519585526
*/
8519685527
case OP_Goto: { /* jump */
85528
+
85529
+#ifdef SQLITE_DEBUG
85530
+ /* In debuggging mode, when the p5 flags is set on an OP_Goto, that
85531
+ ** means we should really jump back to the preceeding OP_ReleaseReg
85532
+ ** instruction. */
85533
+ if( pOp->p5 ){
85534
+ assert( pOp->p2 < (int)(pOp - aOp) );
85535
+ assert( pOp->p2 > 1 );
85536
+ pOp = &aOp[pOp->p2 - 2];
85537
+ assert( pOp[1].opcode==OP_ReleaseReg );
85538
+ goto check_for_interrupt;
85539
+ }
85540
+#endif
85541
+
8519785542
jump_to_p2_and_check_for_interrupt:
8519885543
pOp = &aOp[pOp->p2 - 1];
8519985544
8520085545
/* Opcodes that are used as the bottom of a loop (OP_Next, OP_Prev,
8520185546
** OP_VNext, or OP_SorterNext) all jump here upon
@@ -85668,12 +86013,17 @@
8566886013
assert( pIn1<=&aMem[(p->nMem+1 - p->nCursor)] );
8566986014
assert( memIsValid(pIn1) );
8567086015
memAboutToChange(p, pOut);
8567186016
sqlite3VdbeMemMove(pOut, pIn1);
8567286017
#ifdef SQLITE_DEBUG
85673
- if( pOut->pScopyFrom>=&aMem[p1] && pOut->pScopyFrom<pOut ){
85674
- pOut->pScopyFrom += pOp->p2 - p1;
86018
+ pIn1->pScopyFrom = 0;
86019
+ { int i;
86020
+ for(i=1; i<p->nMem; i++){
86021
+ if( aMem[i].pScopyFrom==pIn1 ){
86022
+ aMem[i].pScopyFrom = pOut;
86023
+ }
86024
+ }
8567586025
}
8567686026
#endif
8567786027
Deephemeralize(pOut);
8567886028
REGISTER_TRACE(p2++, pOut);
8567986029
pIn1++;
@@ -85810,16 +86160,25 @@
8581086160
Deephemeralize(&pMem[i]);
8581186161
assert( (pMem[i].flags & MEM_Ephem)==0
8581286162
|| (pMem[i].flags & (MEM_Str|MEM_Blob))==0 );
8581386163
sqlite3VdbeMemNulTerminate(&pMem[i]);
8581486164
REGISTER_TRACE(pOp->p1+i, &pMem[i]);
86165
+#ifdef SQLITE_DEBUG
86166
+ /* The registers in the result will not be used again when the
86167
+ ** prepared statement restarts. This is because sqlite3_column()
86168
+ ** APIs might have caused type conversions of made other changes to
86169
+ ** the register values. Therefore, we can go ahead and break any
86170
+ ** OP_SCopy dependencies. */
86171
+ pMem[i].pScopyFrom = 0;
86172
+#endif
8581586173
}
8581686174
if( db->mallocFailed ) goto no_mem;
8581786175
8581886176
if( db->mTrace & SQLITE_TRACE_ROW ){
8581986177
db->xTrace(SQLITE_TRACE_ROW, db->pTraceArg, p, 0);
8582086178
}
86179
+
8582186180
8582286181
/* Return SQLITE_ROW
8582386182
*/
8582486183
p->pc = (int)(pOp - aOp) + 1;
8582586184
rc = SQLITE_ROW;
@@ -87132,14 +87491,15 @@
8713287491
** So we might as well use bogus content rather than reading
8713387492
** content from disk.
8713487493
**
8713587494
** Although sqlite3VdbeSerialGet() may read at most 8 bytes from the
8713687495
** buffer passed to it, debugging function VdbeMemPrettyPrint() may
87137
- ** read up to 16. So 16 bytes of bogus content is supplied.
87496
+ ** read more. Use the global constant sqlite3CtypeMap[] as the array,
87497
+ ** as that array is 256 bytes long (plenty for VdbeMemPrettyPrint())
87498
+ ** and it begins with a bunch of zeros.
8713887499
*/
87139
- static u8 aZero[16]; /* This is the bogus content */
87140
- sqlite3VdbeSerialGet(aZero, t, pDest);
87500
+ sqlite3VdbeSerialGet((u8*)sqlite3CtypeMap, t, pDest);
8714187501
}else{
8714287502
rc = sqlite3VdbeMemFromBtree(pC->uc.pCursor, aOffset[p2], len, pDest);
8714387503
if( rc!=SQLITE_OK ) goto abort_due_to_error;
8714487504
sqlite3VdbeSerialGet((const u8*)pDest->z, t, pDest);
8714587505
pDest->flags &= ~MEM_Ephem;
@@ -88657,11 +89017,11 @@
8865789017
8865889018
/* Opcode: SeekHit P1 P2 * * *
8865989019
** Synopsis: seekHit=P2
8866089020
**
8866189021
** Set the seekHit flag on cursor P1 to the value in P2.
88662
-** The seekHit flag is used by the IfNoHope opcode.
89022
+* The seekHit flag is used by the IfNoHope opcode.
8866389023
**
8866489024
** P1 must be a valid b-tree cursor. P2 must be a boolean value,
8866589025
** either 0 or 1.
8866689026
*/
8866789027
case OP_SeekHit: {
@@ -88671,10 +89031,24 @@
8867189031
assert( pC!=0 );
8867289032
assert( pOp->p2==0 || pOp->p2==1 );
8867389033
pC->seekHit = pOp->p2 & 1;
8867489034
break;
8867589035
}
89036
+
89037
+/* Opcode: IfNotOpen P1 P2 * * *
89038
+** Synopsis: if( !csr[P1] ) goto P2
89039
+**
89040
+** If cursor P1 is not open, jump to instruction P2. Otherwise, fall through.
89041
+*/
89042
+case OP_IfNotOpen: { /* jump */
89043
+ assert( pOp->p1>=0 && pOp->p1<p->nCursor );
89044
+ VdbeBranchTaken(p->apCsr[pOp->p1]==0, 2);
89045
+ if( !p->apCsr[pOp->p1] ){
89046
+ goto jump_to_p2_and_check_for_interrupt;
89047
+ }
89048
+ break;
89049
+}
8867689050
8867789051
/* Opcode: Found P1 P2 P3 P4 *
8867889052
** Synopsis: key=r[P3@P4]
8867989053
**
8868089054
** If P4==0 then register P3 holds a blob constructed by MakeRecord. If
@@ -89160,10 +89534,11 @@
8916089534
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
8916189535
assert( memIsValid(pData) );
8916289536
pC = p->apCsr[pOp->p1];
8916389537
assert( pC!=0 );
8916489538
assert( pC->eCurType==CURTYPE_BTREE );
89539
+ assert( pC->deferredMoveto==0 );
8916589540
assert( pC->uc.pCursor!=0 );
8916689541
assert( (pOp->p5 & OPFLAG_ISNOOP) || pC->isTable );
8916789542
assert( pOp->p4type==P4_TABLE || pOp->p4type>=P4_STATIC );
8916889543
REGISTER_TRACE(pOp->p2, pData);
8916989544
sqlite3VdbeIncrWriteCounter(p, pC);
@@ -89277,11 +89652,15 @@
8927789652
assert( pC->uc.pCursor!=0 );
8927889653
assert( pC->deferredMoveto==0 );
8927989654
sqlite3VdbeIncrWriteCounter(p, pC);
8928089655
8928189656
#ifdef SQLITE_DEBUG
89282
- if( pOp->p4type==P4_TABLE && HasRowid(pOp->p4.pTab) && pOp->p5==0 ){
89657
+ if( pOp->p4type==P4_TABLE
89658
+ && HasRowid(pOp->p4.pTab)
89659
+ && pOp->p5==0
89660
+ && sqlite3BtreeCursorIsValidNN(pC->uc.pCursor)
89661
+ ){
8928389662
/* If p5 is zero, the seek operation that positioned the cursor prior to
8928489663
** OP_Delete will have also set the pC->movetoTarget field to the rowid of
8928589664
** the row that is being deleted */
8928689665
i64 iKey = sqlite3BtreeIntegerKey(pC->uc.pCursor);
8928789666
assert( CORRUPT_DB || pC->movetoTarget==iKey );
@@ -90032,10 +90411,28 @@
9003290411
assert( pOp->opcode==OP_IdxRowid );
9003390412
sqlite3VdbeMemSetNull(&aMem[pOp->p2]);
9003490413
}
9003590414
break;
9003690415
}
90416
+
90417
+/* Opcode: FinishSeek P1 * * * *
90418
+**
90419
+** If cursor P1 was previously moved via OP_DeferredSeek, complete that
90420
+** seek operation now, without further delay. If the cursor seek has
90421
+** already occurred, this instruction is a no-op.
90422
+*/
90423
+case OP_FinishSeek: {
90424
+ VdbeCursor *pC; /* The P1 index cursor */
90425
+
90426
+ assert( pOp->p1>=0 && pOp->p1<p->nCursor );
90427
+ pC = p->apCsr[pOp->p1];
90428
+ if( pC->deferredMoveto ){
90429
+ rc = sqlite3VdbeFinishMoveto(pC);
90430
+ if( rc ) goto abort_due_to_error;
90431
+ }
90432
+ break;
90433
+}
9003790434
9003890435
/* Opcode: IdxGE P1 P2 P3 P4 P5
9003990436
** Synopsis: key=r[P3@P4]
9004090437
**
9004190438
** The P4 register values beginning with P3 form an unpacked index
@@ -91338,10 +91735,40 @@
9133891735
}else{
9133991736
p->expired = pOp->p2+1;
9134091737
}
9134191738
break;
9134291739
}
91740
+
91741
+/* Opcode: CursorLock P1 * * * *
91742
+**
91743
+** Lock the btree to which cursor P1 is pointing so that the btree cannot be
91744
+** written by an other cursor.
91745
+*/
91746
+case OP_CursorLock: {
91747
+ VdbeCursor *pC;
91748
+ assert( pOp->p1>=0 && pOp->p1<p->nCursor );
91749
+ pC = p->apCsr[pOp->p1];
91750
+ assert( pC!=0 );
91751
+ assert( pC->eCurType==CURTYPE_BTREE );
91752
+ sqlite3BtreeCursorPin(pC->uc.pCursor);
91753
+ break;
91754
+}
91755
+
91756
+/* Opcode: CursorUnlock P1 * * * *
91757
+**
91758
+** Unlock the btree to which cursor P1 is pointing so that it can be
91759
+** written by other cursors.
91760
+*/
91761
+case OP_CursorUnlock: {
91762
+ VdbeCursor *pC;
91763
+ assert( pOp->p1>=0 && pOp->p1<p->nCursor );
91764
+ pC = p->apCsr[pOp->p1];
91765
+ assert( pC!=0 );
91766
+ assert( pC->eCurType==CURTYPE_BTREE );
91767
+ sqlite3BtreeCursorUnpin(pC->uc.pCursor);
91768
+ break;
91769
+}
9134391770
9134491771
#ifndef SQLITE_OMIT_SHARED_CACHE
9134591772
/* Opcode: TableLock P1 P2 P3 P4 *
9134691773
** Synopsis: iDb=P1 root=P2 write=P3
9134791774
**
@@ -92045,11 +92472,11 @@
9204592472
break;
9204692473
}
9204792474
#endif
9204892475
9204992476
#ifdef SQLITE_DEBUG
92050
-/* Opcode: ReleaseReg P1 P2 P3 * *
92477
+/* Opcode: ReleaseReg P1 P2 P3 * P5
9205192478
** Synopsis: release r[P1@P2] mask P3
9205292479
**
9205392480
** Release registers from service. Any content that was in the
9205492481
** the registers is unreliable after this opcode completes.
9205592482
**
@@ -92060,14 +92487,16 @@
9206092487
** Releasing a register clears the Mem.pScopyFrom pointer. That means
9206192488
** that if the content of the released register was set using OP_SCopy,
9206292489
** a change to the value of the source register for the OP_SCopy will no longer
9206392490
** generate an assertion fault in sqlite3VdbeMemAboutToChange().
9206492491
**
92065
-** TODO: Released registers ought to also have their datatype set to
92066
-** MEM_Undefined so that any subsequent attempt to read the released
92492
+** If P5 is set, then all released registers have their type set
92493
+** to MEM_Undefined so that any subsequent attempt to read the released
9206792494
** register (before it is reinitialized) will generate an assertion fault.
92068
-** However, there are places in the code generator which release registers
92495
+**
92496
+** P5 ought to be set on every call to this opcode.
92497
+** However, there are places in the code generator will release registers
9206992498
** before their are used, under the (valid) assumption that the registers
9207092499
** will not be reallocated for some other purpose before they are used and
9207192500
** hence are safe to release.
9207292501
**
9207392502
** This opcode is only available in testing and debugging builds. It is
@@ -92084,11 +92513,11 @@
9208492513
pMem = &aMem[pOp->p1];
9208592514
constMask = pOp->p3;
9208692515
for(i=0; i<pOp->p2; i++, pMem++){
9208792516
if( i>=32 || (constMask & MASKBIT32(i))==0 ){
9208892517
pMem->pScopyFrom = 0;
92089
- /* MemSetTypeFlag(pMem, MEM_Undefined); // See the TODO */
92518
+ if( i<32 && pOp->p5 ) MemSetTypeFlag(pMem, MEM_Undefined);
9209092519
}
9209192520
}
9209292521
break;
9209392522
}
9209492523
#endif
@@ -92142,10 +92571,16 @@
9214292571
registerTrace(pOrigOp->p2, &aMem[pOrigOp->p2]);
9214392572
}
9214492573
if( opProperty & OPFLG_OUT3 ){
9214592574
registerTrace(pOrigOp->p3, &aMem[pOrigOp->p3]);
9214692575
}
92576
+ if( opProperty==0xff ){
92577
+ /* Never happens. This code exists to avoid a harmless linkage
92578
+ ** warning aboud sqlite3VdbeRegisterDump() being defined but not
92579
+ ** used. */
92580
+ sqlite3VdbeRegisterDump(p);
92581
+ }
9214792582
}
9214892583
#endif /* SQLITE_DEBUG */
9214992584
#endif /* NDEBUG */
9215092585
} /* The end of the for(;;) loop the loops through opcodes */
9215192586
@@ -96270,17 +96705,20 @@
9627096705
** result sets in ExprList.a[].zSpan, in the form "DATABASE.TABLE.COLUMN".
9627196706
** Check to see if the zSpan given to this routine matches the zDb, zTab,
9627296707
** and zCol. If any of zDb, zTab, and zCol are NULL then those fields will
9627396708
** match anything.
9627496709
*/
96275
-SQLITE_PRIVATE int sqlite3MatchSpanName(
96276
- const char *zSpan,
96710
+SQLITE_PRIVATE int sqlite3MatchEName(
96711
+ const struct ExprList_item *pItem,
9627796712
const char *zCol,
9627896713
const char *zTab,
9627996714
const char *zDb
9628096715
){
9628196716
int n;
96717
+ const char *zSpan;
96718
+ if( NEVER(pItem->eEName!=ENAME_TAB) ) return 0;
96719
+ zSpan = pItem->zEName;
9628296720
for(n=0; ALWAYS(zSpan[n]) && zSpan[n]!='.'; n++){}
9628396721
if( zDb && (sqlite3StrNICmp(zSpan, zDb, n)!=0 || zDb[n]!=0) ){
9628496722
return 0;
9628596723
}
9628696724
zSpan += n+1;
@@ -96405,11 +96843,11 @@
9640596843
assert( pTab->nCol>0 );
9640696844
if( pItem->pSelect && (pItem->pSelect->selFlags & SF_NestedFrom)!=0 ){
9640796845
int hit = 0;
9640896846
pEList = pItem->pSelect->pEList;
9640996847
for(j=0; j<pEList->nExpr; j++){
96410
- if( sqlite3MatchSpanName(pEList->a[j].zSpan, zCol, zTab, zDb) ){
96848
+ if( sqlite3MatchEName(&pEList->a[j], zCol, zTab, zDb) ){
9641196849
cnt++;
9641296850
cntTab = 2;
9641396851
pMatch = pItem;
9641496852
pExpr->iColumn = j;
9641596853
hit = 1;
@@ -96586,22 +97024,26 @@
9658697024
&& zTab==0
9658797025
){
9658897026
pEList = pNC->uNC.pEList;
9658997027
assert( pEList!=0 );
9659097028
for(j=0; j<pEList->nExpr; j++){
96591
- char *zAs = pEList->a[j].zName;
96592
- if( zAs!=0 && sqlite3StrICmp(zAs, zCol)==0 ){
97029
+ char *zAs = pEList->a[j].zEName;
97030
+ if( pEList->a[j].eEName==ENAME_NAME
97031
+ && sqlite3_stricmp(zAs, zCol)==0
97032
+ ){
9659397033
Expr *pOrig;
9659497034
assert( pExpr->pLeft==0 && pExpr->pRight==0 );
9659597035
assert( pExpr->x.pList==0 );
9659697036
assert( pExpr->x.pSelect==0 );
9659797037
pOrig = pEList->a[j].pExpr;
9659897038
if( (pNC->ncFlags&NC_AllowAgg)==0 && ExprHasProperty(pOrig, EP_Agg) ){
9659997039
sqlite3ErrorMsg(pParse, "misuse of aliased aggregate %s", zAs);
9660097040
return WRC_Abort;
9660197041
}
96602
- if( (pNC->ncFlags&NC_AllowWin)==0 && ExprHasProperty(pOrig, EP_Win) ){
97042
+ if( ExprHasProperty(pOrig, EP_Win)
97043
+ && ((pNC->ncFlags&NC_AllowWin)==0 || pNC!=pTopNC )
97044
+ ){
9660397045
sqlite3ErrorMsg(pParse, "misuse of aliased window function %s",zAs);
9660497046
return WRC_Abort;
9660597047
}
9660697048
if( sqlite3ExprVectorSize(pOrig)!=1 ){
9660797049
sqlite3ErrorMsg(pParse, "row value misused");
@@ -97007,28 +97449,27 @@
9700797449
sqlite3ResolveNotValid(pParse, pNC, "non-deterministic functions",
9700897450
NC_SelfRef, 0);
9700997451
}else{
9701097452
assert( (NC_SelfRef & 0xff)==NC_SelfRef ); /* Must fit in 8 bits */
9701197453
pExpr->op2 = pNC->ncFlags & NC_SelfRef;
97454
+ if( pNC->ncFlags & NC_FromDDL ) ExprSetProperty(pExpr, EP_FromDDL);
9701297455
}
9701397456
if( (pDef->funcFlags & SQLITE_FUNC_INTERNAL)!=0
9701497457
&& pParse->nested==0
97015
- && sqlite3Config.bInternalFunctions==0
97458
+ && (pParse->db->mDbFlags & DBFLAG_InternalFunc)==0
9701697459
){
9701797460
/* Internal-use-only functions are disallowed unless the
97018
- ** SQL is being compiled using sqlite3NestedParse() */
97461
+ ** SQL is being compiled using sqlite3NestedParse() or
97462
+ ** the SQLITE_TESTCTRL_INTERNAL_FUNCTIONS test-control has be
97463
+ ** used to activate internal functionsn for testing purposes */
9701997464
no_such_func = 1;
9702097465
pDef = 0;
9702197466
}else
97022
- if( (pDef->funcFlags & SQLITE_FUNC_DIRECT)!=0
97023
- && ExprHasProperty(pExpr, EP_Indirect)
97467
+ if( (pDef->funcFlags & (SQLITE_FUNC_DIRECT|SQLITE_FUNC_UNSAFE))!=0
9702497468
&& !IN_RENAME_OBJECT
9702597469
){
97026
- /* Functions tagged with SQLITE_DIRECTONLY may not be used
97027
- ** inside of triggers and views */
97028
- sqlite3ErrorMsg(pParse, "%s() prohibited in triggers and views",
97029
- pDef->zName);
97470
+ sqlite3ExprFunctionUsable(pParse, pExpr, pDef);
9703097471
}
9703197472
}
9703297473
9703397474
if( 0==IN_RENAME_OBJECT ){
9703497475
#ifndef SQLITE_OMIT_WINDOWFUNC
@@ -97253,12 +97694,13 @@
9725397694
UNUSED_PARAMETER(pParse);
9725497695
9725597696
if( pE->op==TK_ID ){
9725697697
char *zCol = pE->u.zToken;
9725797698
for(i=0; i<pEList->nExpr; i++){
97258
- char *zAs = pEList->a[i].zName;
97259
- if( zAs!=0 && sqlite3StrICmp(zAs, zCol)==0 ){
97699
+ if( pEList->a[i].eEName==ENAME_NAME
97700
+ && sqlite3_stricmp(pEList->a[i].zEName, zCol)==0
97701
+ ){
9726097702
return i+1;
9726197703
}
9726297704
}
9726397705
}
9726497706
return 0;
@@ -98015,10 +98457,15 @@
9801598457
if( pTab ){
9801698458
sSrc.nSrc = 1;
9801798459
sSrc.a[0].zName = pTab->zName;
9801898460
sSrc.a[0].pTab = pTab;
9801998461
sSrc.a[0].iCursor = -1;
98462
+ if( pTab->pSchema!=pParse->db->aDb[1].pSchema ){
98463
+ /* Cause EP_FromDDL to be set on TK_FUNCTION nodes of non-TEMP
98464
+ ** schema elements */
98465
+ type |= NC_FromDDL;
98466
+ }
9802098467
}
9802198468
sNC.pParse = pParse;
9802298469
sNC.pSrcList = &sSrc;
9802398470
sNC.ncFlags = type | NC_IsDDL;
9802498471
if( (rc = sqlite3ResolveExprNames(&sNC, pExpr))!=SQLITE_OK ) return rc;
@@ -98961,13 +99408,15 @@
9896199408
sqlite3 *db = pParse->db;
9896299409
if( pLeft==0 ){
9896399410
return pRight;
9896499411
}else if( pRight==0 ){
9896599412
return pLeft;
98966
- }else if( ExprAlwaysFalse(pLeft) || ExprAlwaysFalse(pRight) ){
98967
- sqlite3ExprUnmapAndDelete(pParse, pLeft);
98968
- sqlite3ExprUnmapAndDelete(pParse, pRight);
99413
+ }else if( (ExprAlwaysFalse(pLeft) || ExprAlwaysFalse(pRight))
99414
+ && !IN_RENAME_OBJECT
99415
+ ){
99416
+ sqlite3ExprDelete(db, pLeft);
99417
+ sqlite3ExprDelete(db, pRight);
9896999418
return sqlite3Expr(db, TK_INTEGER, "0");
9897099419
}else{
9897199420
return sqlite3PExpr(pParse, TK_AND, pLeft, pRight);
9897299421
}
9897399422
}
@@ -98998,10 +99447,44 @@
9899899447
assert( !ExprHasProperty(pNew, EP_xIsSelect) );
9899999448
sqlite3ExprSetHeightAndFlags(pParse, pNew);
9900099449
if( eDistinct==SF_Distinct ) ExprSetProperty(pNew, EP_Distinct);
9900199450
return pNew;
9900299451
}
99452
+
99453
+/*
99454
+** Check to see if a function is usable according to current access
99455
+** rules:
99456
+**
99457
+** SQLITE_FUNC_DIRECT - Only usable from top-level SQL
99458
+**
99459
+** SQLITE_FUNC_UNSAFE - Usable if TRUSTED_SCHEMA or from
99460
+** top-level SQL
99461
+**
99462
+** If the function is not usable, create an error.
99463
+*/
99464
+SQLITE_PRIVATE void sqlite3ExprFunctionUsable(
99465
+ Parse *pParse, /* Parsing and code generating context */
99466
+ Expr *pExpr, /* The function invocation */
99467
+ FuncDef *pDef /* The function being invoked */
99468
+){
99469
+ assert( !IN_RENAME_OBJECT );
99470
+ assert( (pDef->funcFlags & (SQLITE_FUNC_DIRECT|SQLITE_FUNC_UNSAFE))!=0 );
99471
+ if( ExprHasProperty(pExpr, EP_FromDDL) ){
99472
+ if( (pDef->funcFlags & SQLITE_FUNC_DIRECT)!=0
99473
+ || (pParse->db->flags & SQLITE_TrustedSchema)==0
99474
+ ){
99475
+ /* Functions prohibited in triggers and views if:
99476
+ ** (1) tagged with SQLITE_DIRECTONLY
99477
+ ** (2) not tagged with SQLITE_INNOCUOUS (which means it
99478
+ ** is tagged with SQLITE_FUNC_UNSAFE) and
99479
+ ** SQLITE_DBCONFIG_TRUSTED_SCHEMA is off (meaning
99480
+ ** that the schema is possibly tainted).
99481
+ */
99482
+ sqlite3ErrorMsg(pParse, "unsafe use of %s()", pDef->zName);
99483
+ }
99484
+ }
99485
+}
9900399486
9900499487
/*
9900599488
** Assign a variable number to an expression that encodes a wildcard
9900699489
** in the original SQL statement.
9900799490
**
@@ -99466,16 +99949,15 @@
9946699949
assert( pNewExpr->iColumn==pItem[-1].pExpr->iColumn+1 );
9946799950
assert( pPriorSelectCol==pItem[-1].pExpr->pLeft );
9946899951
pNewExpr->pLeft = pPriorSelectCol;
9946999952
}
9947099953
}
99471
- pItem->zName = sqlite3DbStrDup(db, pOldItem->zName);
99472
- pItem->zSpan = sqlite3DbStrDup(db, pOldItem->zSpan);
99954
+ pItem->zEName = sqlite3DbStrDup(db, pOldItem->zEName);
9947399955
pItem->sortFlags = pOldItem->sortFlags;
99956
+ pItem->eEName = pOldItem->eEName;
9947499957
pItem->done = 0;
9947599958
pItem->bNulls = pOldItem->bNulls;
99476
- pItem->bSpanIsTab = pOldItem->bSpanIsTab;
9947799959
pItem->bSorterRef = pOldItem->bSorterRef;
9947899960
pItem->u = pOldItem->u;
9947999961
}
9948099962
return pNew;
9948199963
}
@@ -99638,13 +100120,13 @@
99638100120
goto no_mem;
99639100121
}
99640100122
pList = pNew;
99641100123
}
99642100124
pItem = &pList->a[pList->nExpr++];
99643
- assert( offsetof(struct ExprList_item,zName)==sizeof(pItem->pExpr) );
100125
+ assert( offsetof(struct ExprList_item,zEName)==sizeof(pItem->pExpr) );
99644100126
assert( offsetof(struct ExprList_item,pExpr)==0 );
99645
- memset(&pItem->zName,0,sizeof(*pItem)-offsetof(struct ExprList_item,zName));
100127
+ memset(&pItem->zEName,0,sizeof(*pItem)-offsetof(struct ExprList_item,zEName));
99646100128
pItem->pExpr = pExpr;
99647100129
return pList;
99648100130
99649100131
no_mem:
99650100132
/* Avoid leaking memory if malloc has failed. */
@@ -99697,11 +100179,11 @@
99697100179
if( pSubExpr==0 ) continue;
99698100180
pSubExpr->iTable = pColumns->nId;
99699100181
pList = sqlite3ExprListAppend(pParse, pList, pSubExpr);
99700100182
if( pList ){
99701100183
assert( pList->nExpr==iFirst+i+1 );
99702
- pList->a[pList->nExpr-1].zName = pColumns->a[i].zName;
100184
+ pList->a[pList->nExpr-1].zEName = pColumns->a[i].zName;
99703100185
pColumns->a[i].zName = 0;
99704100186
}
99705100187
}
99706100188
99707100189
if( !db->mallocFailed && pExpr->op==TK_SELECT && ALWAYS(pList!=0) ){
@@ -99757,11 +100239,11 @@
99757100239
}
99758100240
}
99759100241
}
99760100242
99761100243
/*
99762
-** Set the ExprList.a[].zName element of the most recently added item
100244
+** Set the ExprList.a[].zEName element of the most recently added item
99763100245
** on the expression list.
99764100246
**
99765100247
** pList might be NULL following an OOM error. But pName should never be
99766100248
** NULL. If a memory allocation fails, the pParse->db->mallocFailed flag
99767100249
** is set.
@@ -99775,15 +100257,16 @@
99775100257
assert( pList!=0 || pParse->db->mallocFailed!=0 );
99776100258
if( pList ){
99777100259
struct ExprList_item *pItem;
99778100260
assert( pList->nExpr>0 );
99779100261
pItem = &pList->a[pList->nExpr-1];
99780
- assert( pItem->zName==0 );
99781
- pItem->zName = sqlite3DbStrNDup(pParse->db, pName->z, pName->n);
99782
- if( dequote ) sqlite3Dequote(pItem->zName);
100262
+ assert( pItem->zEName==0 );
100263
+ assert( pItem->eEName==ENAME_NAME );
100264
+ pItem->zEName = sqlite3DbStrNDup(pParse->db, pName->z, pName->n);
100265
+ if( dequote ) sqlite3Dequote(pItem->zEName);
99783100266
if( IN_RENAME_OBJECT ){
99784
- sqlite3RenameTokenMap(pParse, (void*)pItem->zName, pName);
100267
+ sqlite3RenameTokenMap(pParse, (void*)pItem->zEName, pName);
99785100268
}
99786100269
}
99787100270
}
99788100271
99789100272
/*
@@ -99803,12 +100286,14 @@
99803100286
sqlite3 *db = pParse->db;
99804100287
assert( pList!=0 || db->mallocFailed!=0 );
99805100288
if( pList ){
99806100289
struct ExprList_item *pItem = &pList->a[pList->nExpr-1];
99807100290
assert( pList->nExpr>0 );
99808
- sqlite3DbFree(db, pItem->zSpan);
99809
- pItem->zSpan = sqlite3DbSpanDup(db, zStart, zEnd);
100291
+ if( pItem->zEName==0 ){
100292
+ pItem->zEName = sqlite3DbSpanDup(db, zStart, zEnd);
100293
+ pItem->eEName = ENAME_SPAN;
100294
+ }
99810100295
}
99811100296
}
99812100297
99813100298
/*
99814100299
** If the expression list pEList contains more than iLimit elements,
@@ -99834,12 +100319,11 @@
99834100319
int i = pList->nExpr;
99835100320
struct ExprList_item *pItem = pList->a;
99836100321
assert( pList->nExpr>0 );
99837100322
do{
99838100323
sqlite3ExprDelete(db, pItem->pExpr);
99839
- sqlite3DbFree(db, pItem->zName);
99840
- sqlite3DbFree(db, pItem->zSpan);
100324
+ sqlite3DbFree(db, pItem->zEName);
99841100325
pItem++;
99842100326
}while( --i>0 );
99843100327
sqlite3DbFreeNN(db, pList);
99844100328
}
99845100329
SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3 *db, ExprList *pList){
@@ -99872,24 +100356,39 @@
99872100356
SQLITE_PRIVATE int sqlite3SelectWalkFail(Walker *pWalker, Select *NotUsed){
99873100357
UNUSED_PARAMETER(NotUsed);
99874100358
pWalker->eCode = 0;
99875100359
return WRC_Abort;
99876100360
}
100361
+
100362
+/*
100363
+** Check the input string to see if it is "true" or "false" (in any case).
100364
+**
100365
+** If the string is.... Return
100366
+** "true" EP_IsTrue
100367
+** "false" EP_IsFalse
100368
+** anything else 0
100369
+*/
100370
+SQLITE_PRIVATE u32 sqlite3IsTrueOrFalse(const char *zIn){
100371
+ if( sqlite3StrICmp(zIn, "true")==0 ) return EP_IsTrue;
100372
+ if( sqlite3StrICmp(zIn, "false")==0 ) return EP_IsFalse;
100373
+ return 0;
100374
+}
100375
+
99877100376
99878100377
/*
99879100378
** If the input expression is an ID with the name "true" or "false"
99880100379
** then convert it into an TK_TRUEFALSE term. Return non-zero if
99881100380
** the conversion happened, and zero if the expression is unaltered.
99882100381
*/
99883100382
SQLITE_PRIVATE int sqlite3ExprIdToTrueFalse(Expr *pExpr){
100383
+ u32 v;
99884100384
assert( pExpr->op==TK_ID || pExpr->op==TK_STRING );
99885100385
if( !ExprHasProperty(pExpr, EP_Quoted)
99886
- && (sqlite3StrICmp(pExpr->u.zToken, "true")==0
99887
- || sqlite3StrICmp(pExpr->u.zToken, "false")==0)
100386
+ && (v = sqlite3IsTrueOrFalse(pExpr->u.zToken))!=0
99888100387
){
99889100388
pExpr->op = TK_TRUEFALSE;
99890
- ExprSetProperty(pExpr, pExpr->u.zToken[4]==0 ? EP_IsTrue : EP_IsFalse);
100389
+ ExprSetProperty(pExpr, v);
99891100390
return 1;
99892100391
}
99893100392
return 0;
99894100393
}
99895100394
@@ -99947,14 +100446,15 @@
99947100446
** sqlite3ExprIsConstantOrFunction() pWalker->eCode==4 or 5
99948100447
**
99949100448
** In all cases, the callbacks set Walker.eCode=0 and abort if the expression
99950100449
** is found to not be a constant.
99951100450
**
99952
-** The sqlite3ExprIsConstantOrFunction() is used for evaluating expressions
99953
-** in a CREATE TABLE statement. The Walker.eCode value is 5 when parsing
99954
-** an existing schema and 4 when processing a new statement. A bound
99955
-** parameter raises an error for new statements, but is silently converted
100451
+** The sqlite3ExprIsConstantOrFunction() is used for evaluating DEFAULT
100452
+** expressions in a CREATE TABLE statement. The Walker.eCode value is 5
100453
+** when parsing an existing schema out of the sqlite_master table and 4
100454
+** when processing a new CREATE TABLE statement. A bound parameter raises
100455
+** an error for new statements, but is silently converted
99956100456
** to NULL for existing schemas. This allows sqlite_master tables that
99957100457
** contain a bound parameter because they were generated by older versions
99958100458
** of SQLite to be parsed by newer versions of SQLite without raising a
99959100459
** malformed schema error.
99960100460
*/
@@ -99974,10 +100474,11 @@
99974100474
** SQLITE_FUNC_CONST flag. */
99975100475
case TK_FUNCTION:
99976100476
if( (pWalker->eCode>=4 || ExprHasProperty(pExpr,EP_ConstFunc))
99977100477
&& !ExprHasProperty(pExpr, EP_WinFunc)
99978100478
){
100479
+ if( pWalker->eCode==5 ) ExprSetProperty(pExpr, EP_FromDDL);
99979100480
return WRC_Continue;
99980100481
}else{
99981100482
pWalker->eCode = 0;
99982100483
return WRC_Abort;
99983100484
}
@@ -100137,13 +100638,25 @@
100137100638
sqlite3WalkExpr(&w, p);
100138100639
return w.eCode;
100139100640
}
100140100641
100141100642
/*
100142
-** Walk an expression tree. Return non-zero if the expression is constant
100143
-** or a function call with constant arguments. Return and 0 if there
100144
-** are any variables.
100643
+** Walk an expression tree for the DEFAULT field of a column definition
100644
+** in a CREATE TABLE statement. Return non-zero if the expression is
100645
+** acceptable for use as a DEFAULT. That is to say, return non-zero if
100646
+** the expression is constant or a function call with constant arguments.
100647
+** Return and 0 if there are any variables.
100648
+**
100649
+** isInit is true when parsing from sqlite_master. isInit is false when
100650
+** processing a new CREATE TABLE statement. When isInit is true, parameters
100651
+** (such as ? or $abc) in the expression are converted into NULL. When
100652
+** isInit is false, parameters raise an error. Parameters should not be
100653
+** allowed in a CREATE TABLE statement, but some legacy versions of SQLite
100654
+** allowed it, so we need to support it when reading sqlite_master for
100655
+** backwards compatibility.
100656
+**
100657
+** If isInit is true, set EP_FromDDL on every TK_FUNCTION node.
100145100658
**
100146100659
** For the purposes of this function, a double-quoted string (ex: "abc")
100147100660
** is considered a variable but a single-quoted string (ex: 'abc') is
100148100661
** a constant.
100149100662
*/
@@ -101219,10 +101732,11 @@
101219101732
r2 = sqlite3ExprCodeTemp(pParse, pList->a[ii].pExpr, &regToFree);
101220101733
}
101221101734
if( regCkNull && sqlite3ExprCanBeNull(pList->a[ii].pExpr) ){
101222101735
sqlite3VdbeAddOp3(v, OP_BitAnd, regCkNull, r2, regCkNull);
101223101736
}
101737
+ sqlite3ReleaseTempReg(pParse, regToFree);
101224101738
if( ii<pList->nExpr-1 || destIfNull!=destIfFalse ){
101225101739
int op = rLhs!=r2 ? OP_Eq : OP_NotNull;
101226101740
sqlite3VdbeAddOp4(v, op, rLhs, labelOk, r2,
101227101741
(void*)pColl, P4_COLLSEQ);
101228101742
VdbeCoverageIf(v, ii<pList->nExpr-1 && op==OP_Eq);
@@ -101237,11 +101751,10 @@
101237101751
(void*)pColl, P4_COLLSEQ);
101238101752
VdbeCoverageIf(v, op==OP_Ne);
101239101753
VdbeCoverageIf(v, op==OP_IsNull);
101240101754
sqlite3VdbeChangeP5(v, zAff[0] | SQLITE_JUMPIFNULL);
101241101755
}
101242
- sqlite3ReleaseTempReg(pParse, regToFree);
101243101756
}
101244101757
if( regCkNull ){
101245101758
sqlite3VdbeAddOp2(v, OP_IsNull, regCkNull, destIfNull); VdbeCoverage(v);
101246101759
sqlite3VdbeGoto(v, destIfFalse);
101247101760
}
@@ -101598,10 +102111,113 @@
101598102111
}
101599102112
}
101600102113
}
101601102114
return iResult;
101602102115
}
102116
+
102117
+/*
102118
+** Generate code to implement special SQL functions that are implemented
102119
+** in-line rather than by using the usual callbacks.
102120
+*/
102121
+static int exprCodeInlineFunction(
102122
+ Parse *pParse, /* Parsing context */
102123
+ ExprList *pFarg, /* List of function arguments */
102124
+ int iFuncId, /* Function ID. One of the INTFUNC_... values */
102125
+ int target /* Store function result in this register */
102126
+){
102127
+ int nFarg;
102128
+ Vdbe *v = pParse->pVdbe;
102129
+ assert( v!=0 );
102130
+ assert( pFarg!=0 );
102131
+ nFarg = pFarg->nExpr;
102132
+ assert( nFarg>0 ); /* All in-line functions have at least one argument */
102133
+ switch( iFuncId ){
102134
+ case INLINEFUNC_coalesce: {
102135
+ /* Attempt a direct implementation of the built-in COALESCE() and
102136
+ ** IFNULL() functions. This avoids unnecessary evaluation of
102137
+ ** arguments past the first non-NULL argument.
102138
+ */
102139
+ int endCoalesce = sqlite3VdbeMakeLabel(pParse);
102140
+ int i;
102141
+ assert( nFarg>=2 );
102142
+ sqlite3ExprCode(pParse, pFarg->a[0].pExpr, target);
102143
+ for(i=1; i<nFarg; i++){
102144
+ sqlite3VdbeAddOp2(v, OP_NotNull, target, endCoalesce);
102145
+ VdbeCoverage(v);
102146
+ sqlite3ExprCode(pParse, pFarg->a[i].pExpr, target);
102147
+ }
102148
+ if( sqlite3VdbeGetOp(v, -1)->opcode==OP_Copy ){
102149
+ sqlite3VdbeChangeP5(v, 1); /* Tag trailing OP_Copy as not mergable */
102150
+ }
102151
+ sqlite3VdbeResolveLabel(v, endCoalesce);
102152
+ break;
102153
+ }
102154
+
102155
+ default: {
102156
+ /* The UNLIKELY() function is a no-op. The result is the value
102157
+ ** of the first argument.
102158
+ */
102159
+ assert( nFarg==1 || nFarg==2 );
102160
+ target = sqlite3ExprCodeTarget(pParse, pFarg->a[0].pExpr, target);
102161
+ break;
102162
+ }
102163
+
102164
+ /***********************************************************************
102165
+ ** Test-only SQL functions that are only usable if enabled
102166
+ ** via SQLITE_TESTCTRL_INTERNAL_FUNCTIONS
102167
+ */
102168
+ case INLINEFUNC_expr_compare: {
102169
+ /* Compare two expressions using sqlite3ExprCompare() */
102170
+ assert( nFarg==2 );
102171
+ sqlite3VdbeAddOp2(v, OP_Integer,
102172
+ sqlite3ExprCompare(0,pFarg->a[0].pExpr, pFarg->a[1].pExpr,-1),
102173
+ target);
102174
+ break;
102175
+ }
102176
+
102177
+ case INLINEFUNC_expr_implies_expr: {
102178
+ /* Compare two expressions using sqlite3ExprImpliesExpr() */
102179
+ assert( nFarg==2 );
102180
+ sqlite3VdbeAddOp2(v, OP_Integer,
102181
+ sqlite3ExprImpliesExpr(pParse,pFarg->a[0].pExpr, pFarg->a[1].pExpr,-1),
102182
+ target);
102183
+ break;
102184
+ }
102185
+
102186
+ case INLINEFUNC_implies_nonnull_row: {
102187
+ /* REsult of sqlite3ExprImpliesNonNullRow() */
102188
+ Expr *pA1;
102189
+ assert( nFarg==2 );
102190
+ pA1 = pFarg->a[1].pExpr;
102191
+ if( pA1->op==TK_COLUMN ){
102192
+ sqlite3VdbeAddOp2(v, OP_Integer,
102193
+ sqlite3ExprImpliesNonNullRow(pFarg->a[0].pExpr,pA1->iTable),
102194
+ target);
102195
+ }else{
102196
+ sqlite3VdbeAddOp2(v, OP_Null, 0, target);
102197
+ }
102198
+ break;
102199
+ }
102200
+
102201
+#ifdef SQLITE_DEBUG
102202
+ case INLINEFUNC_affinity: {
102203
+ /* The AFFINITY() function evaluates to a string that describes
102204
+ ** the type affinity of the argument. This is used for testing of
102205
+ ** the SQLite type logic.
102206
+ */
102207
+ const char *azAff[] = { "blob", "text", "numeric", "integer", "real" };
102208
+ char aff;
102209
+ assert( nFarg==1 );
102210
+ aff = sqlite3ExprAffinity(pFarg->a[0].pExpr);
102211
+ sqlite3VdbeLoadString(v, target,
102212
+ (aff<=SQLITE_AFF_NONE) ? "none" : azAff[aff-SQLITE_AFF_BLOB]);
102213
+ break;
102214
+ }
102215
+#endif
102216
+ }
102217
+ return target;
102218
+}
101603102219
101604102220
101605102221
/*
101606102222
** Generate code into the current Vdbe to evaluate the given
101607102223
** expression. Attempt to store the results in register "target".
@@ -101979,51 +102595,18 @@
101979102595
#endif
101980102596
if( pDef==0 || pDef->xFinalize!=0 ){
101981102597
sqlite3ErrorMsg(pParse, "unknown function: %s()", zId);
101982102598
break;
101983102599
}
101984
-
101985
- /* Attempt a direct implementation of the built-in COALESCE() and
101986
- ** IFNULL() functions. This avoids unnecessary evaluation of
101987
- ** arguments past the first non-NULL argument.
101988
- */
101989
- if( pDef->funcFlags & SQLITE_FUNC_COALESCE ){
101990
- int endCoalesce = sqlite3VdbeMakeLabel(pParse);
101991
- assert( nFarg>=2 );
101992
- sqlite3ExprCode(pParse, pFarg->a[0].pExpr, target);
101993
- for(i=1; i<nFarg; i++){
101994
- sqlite3VdbeAddOp2(v, OP_NotNull, target, endCoalesce);
101995
- VdbeCoverage(v);
101996
- sqlite3ExprCode(pParse, pFarg->a[i].pExpr, target);
101997
- }
101998
- sqlite3VdbeResolveLabel(v, endCoalesce);
101999
- break;
102000
- }
102001
-
102002
- /* The UNLIKELY() function is a no-op. The result is the value
102003
- ** of the first argument.
102004
- */
102005
- if( pDef->funcFlags & SQLITE_FUNC_UNLIKELY ){
102006
- assert( nFarg>=1 );
102007
- return sqlite3ExprCodeTarget(pParse, pFarg->a[0].pExpr, target);
102008
- }
102009
-
102010
-#ifdef SQLITE_DEBUG
102011
- /* The AFFINITY() function evaluates to a string that describes
102012
- ** the type affinity of the argument. This is used for testing of
102013
- ** the SQLite type logic.
102014
- */
102015
- if( pDef->funcFlags & SQLITE_FUNC_AFFINITY ){
102016
- const char *azAff[] = { "blob", "text", "numeric", "integer", "real" };
102017
- char aff;
102018
- assert( nFarg==1 );
102019
- aff = sqlite3ExprAffinity(pFarg->a[0].pExpr);
102020
- sqlite3VdbeLoadString(v, target,
102021
- (aff<=SQLITE_AFF_NONE) ? "none" : azAff[aff-SQLITE_AFF_BLOB]);
102022
- return target;
102023
- }
102024
-#endif
102600
+ if( pDef->funcFlags & SQLITE_FUNC_INLINE ){
102601
+ assert( (pDef->funcFlags & SQLITE_FUNC_UNSAFE)==0 );
102602
+ assert( (pDef->funcFlags & SQLITE_FUNC_DIRECT)==0 );
102603
+ return exprCodeInlineFunction(pParse, pFarg,
102604
+ SQLITE_PTR_TO_INT(pDef->pUserData), target);
102605
+ }else if( pDef->funcFlags & (SQLITE_FUNC_DIRECT|SQLITE_FUNC_UNSAFE) ){
102606
+ sqlite3ExprFunctionUsable(pParse, pExpr, pDef);
102607
+ }
102025102608
102026102609
for(i=0; i<nFarg; i++){
102027102610
if( i<32 && sqlite3ExprIsConstant(pFarg->a[i].pExpr) ){
102028102611
testcase( i==31 );
102029102612
constMask |= MASKBIT32(i);
@@ -102103,11 +102686,11 @@
102103102686
}
102104102687
if( nFarg ){
102105102688
if( constMask==0 ){
102106102689
sqlite3ReleaseTempRange(pParse, r1, nFarg);
102107102690
}else{
102108
- sqlite3VdbeReleaseRegisters(pParse, r1, nFarg, constMask);
102691
+ sqlite3VdbeReleaseRegisters(pParse, r1, nFarg, constMask, 1);
102109102692
}
102110102693
}
102111102694
return target;
102112102695
}
102113102696
#ifndef SQLITE_OMIT_SUBQUERY
@@ -102455,11 +103038,17 @@
102455103038
102456103039
assert( target>0 && target<=pParse->nMem );
102457103040
inReg = sqlite3ExprCodeTarget(pParse, pExpr, target);
102458103041
assert( pParse->pVdbe!=0 || pParse->db->mallocFailed );
102459103042
if( inReg!=target && pParse->pVdbe ){
102460
- sqlite3VdbeAddOp2(pParse->pVdbe, OP_SCopy, inReg, target);
103043
+ u8 op;
103044
+ if( ExprHasProperty(pExpr,EP_Subquery) ){
103045
+ op = OP_Copy;
103046
+ }else{
103047
+ op = OP_SCopy;
103048
+ }
103049
+ sqlite3VdbeAddOp2(pParse->pVdbe, op, inReg, target);
102461103050
}
102462103051
}
102463103052
102464103053
/*
102465103054
** Make a transient copy of expression pExpr and then code it using
@@ -102548,10 +103137,11 @@
102548103137
VdbeOp *pOp;
102549103138
if( copyOp==OP_Copy
102550103139
&& (pOp=sqlite3VdbeGetOp(v, -1))->opcode==OP_Copy
102551103140
&& pOp->p1+pOp->p3+1==inReg
102552103141
&& pOp->p2+pOp->p3+1==target+i
103142
+ && pOp->p5==0 /* The do-not-merge flag must be clear */
102553103143
){
102554103144
pOp->p3++;
102555103145
}else{
102556103146
sqlite3VdbeAddOp2(v, copyOp, inReg, target+i);
102557103147
}
@@ -103120,12 +103710,13 @@
103120103710
}
103121103711
return 0;
103122103712
}
103123103713
103124103714
/*
103125
-** Compare two ExprList objects. Return 0 if they are identical and
103126
-** non-zero if they differ in any way.
103715
+** Compare two ExprList objects. Return 0 if they are identical, 1
103716
+** if they are certainly different, or 2 if it is not possible to
103717
+** determine if they are identical or not.
103127103718
**
103128103719
** If any subelement of pB has Expr.iTable==(-1) then it is allowed
103129103720
** to compare equal to an equivalent element in pA with Expr.iTable==iTab.
103130103721
**
103131103722
** This routine might return non-zero for equivalent ExprLists. The
@@ -103140,14 +103731,15 @@
103140103731
int i;
103141103732
if( pA==0 && pB==0 ) return 0;
103142103733
if( pA==0 || pB==0 ) return 1;
103143103734
if( pA->nExpr!=pB->nExpr ) return 1;
103144103735
for(i=0; i<pA->nExpr; i++){
103736
+ int res;
103145103737
Expr *pExprA = pA->a[i].pExpr;
103146103738
Expr *pExprB = pB->a[i].pExpr;
103147103739
if( pA->a[i].sortFlags!=pB->a[i].sortFlags ) return 1;
103148
- if( sqlite3ExprCompare(0, pExprA, pExprB, iTab) ) return 1;
103740
+ if( (res = sqlite3ExprCompare(0, pExprA, pExprB, iTab)) ) return res;
103149103741
}
103150103742
return 0;
103151103743
}
103152103744
103153103745
/*
@@ -103322,15 +103914,16 @@
103322103914
return WRC_Abort;
103323103915
}
103324103916
return WRC_Prune;
103325103917
103326103918
case TK_AND:
103327
- assert( pWalker->eCode==0 );
103328
- sqlite3WalkExpr(pWalker, pExpr->pLeft);
103329
- if( pWalker->eCode ){
103330
- pWalker->eCode = 0;
103331
- sqlite3WalkExpr(pWalker, pExpr->pRight);
103919
+ if( pWalker->eCode==0 ){
103920
+ sqlite3WalkExpr(pWalker, pExpr->pLeft);
103921
+ if( pWalker->eCode ){
103922
+ pWalker->eCode = 0;
103923
+ sqlite3WalkExpr(pWalker, pExpr->pRight);
103924
+ }
103332103925
}
103333103926
return WRC_Prune;
103334103927
103335103928
case TK_BETWEEN:
103336103929
if( sqlite3WalkExpr(pWalker, pExpr->pLeft)==WRC_Abort ){
@@ -103477,16 +104070,17 @@
103477104070
103478104071
/*
103479104072
** Count the number of references to columns.
103480104073
*/
103481104074
static int exprSrcCount(Walker *pWalker, Expr *pExpr){
103482
- /* The NEVER() on the second term is because sqlite3FunctionUsesThisSrc()
103483
- ** is always called before sqlite3ExprAnalyzeAggregates() and so the
103484
- ** TK_COLUMNs have not yet been converted into TK_AGG_COLUMN. If
103485
- ** sqlite3FunctionUsesThisSrc() is used differently in the future, the
103486
- ** NEVER() will need to be removed. */
103487
- if( pExpr->op==TK_COLUMN || NEVER(pExpr->op==TK_AGG_COLUMN) ){
104075
+ /* There was once a NEVER() on the second term on the grounds that
104076
+ ** sqlite3FunctionUsesThisSrc() was always called before
104077
+ ** sqlite3ExprAnalyzeAggregates() and so the TK_COLUMNs have not yet
104078
+ ** been converted into TK_AGG_COLUMN. But this is no longer true due
104079
+ ** to window functions - sqlite3WindowRewrite() may now indirectly call
104080
+ ** FunctionUsesThisSrc() when creating a new sub-select. */
104081
+ if( pExpr->op==TK_COLUMN || pExpr->op==TK_AGG_COLUMN ){
103488104082
int i;
103489104083
struct SrcCount *p = pWalker->u.pSrcCount;
103490104084
SrcList *pSrc = p->pSrc;
103491104085
int nSrc = pSrc ? pSrc->nSrc : 0;
103492104086
for(i=0; i<nSrc; i++){
@@ -103520,10 +104114,15 @@
103520104114
w.u.pSrcCount = &cnt;
103521104115
cnt.pSrc = pSrcList;
103522104116
cnt.nThis = 0;
103523104117
cnt.nOther = 0;
103524104118
sqlite3WalkExprList(&w, pExpr->x.pList);
104119
+#ifndef SQLITE_OMIT_WINDOWFUNC
104120
+ if( ExprHasProperty(pExpr, EP_WinFunc) ){
104121
+ sqlite3WalkExpr(&w, pExpr->y.pWin->pFilter);
104122
+ }
104123
+#endif
103525104124
return cnt.nThis>0 || cnt.nOther==0;
103526104125
}
103527104126
103528104127
/*
103529104128
** Add a new element to the pAggInfo->aCol[] array. Return the index of
@@ -103749,11 +104348,11 @@
103749104348
** Deallocate a register, making available for reuse for some other
103750104349
** purpose.
103751104350
*/
103752104351
SQLITE_PRIVATE void sqlite3ReleaseTempReg(Parse *pParse, int iReg){
103753104352
if( iReg ){
103754
- sqlite3VdbeReleaseRegisters(pParse, iReg, 1, 0);
104353
+ sqlite3VdbeReleaseRegisters(pParse, iReg, 1, 0, 0);
103755104354
if( pParse->nTempReg<ArraySize(pParse->aTempReg) ){
103756104355
pParse->aTempReg[pParse->nTempReg++] = iReg;
103757104356
}
103758104357
}
103759104358
}
@@ -103778,11 +104377,11 @@
103778104377
SQLITE_PRIVATE void sqlite3ReleaseTempRange(Parse *pParse, int iReg, int nReg){
103779104378
if( nReg==1 ){
103780104379
sqlite3ReleaseTempReg(pParse, iReg);
103781104380
return;
103782104381
}
103783
- sqlite3VdbeReleaseRegisters(pParse, iReg, nReg, 0);
104382
+ sqlite3VdbeReleaseRegisters(pParse, iReg, nReg, 0, 0);
103784104383
if( nReg>pParse->nRangeReg ){
103785104384
pParse->nRangeReg = nReg;
103786104385
pParse->iRangeReg = iReg;
103787104386
}
103788104387
}
@@ -104591,12 +105190,12 @@
104591105190
if( pParse->nErr ) return WRC_Abort;
104592105191
if( NEVER(p->selFlags & SF_View) ) return WRC_Prune;
104593105192
if( ALWAYS(p->pEList) ){
104594105193
ExprList *pList = p->pEList;
104595105194
for(i=0; i<pList->nExpr; i++){
104596
- if( pList->a[i].zName ){
104597
- sqlite3RenameTokenRemap(pParse, 0, (void*)pList->a[i].zName);
105195
+ if( pList->a[i].zEName && pList->a[i].eEName==ENAME_NAME ){
105196
+ sqlite3RenameTokenRemap(pParse, 0, (void*)pList->a[i].zEName);
104598105197
}
104599105198
}
104600105199
}
104601105200
if( ALWAYS(p->pSrc) ){ /* Every Select as a SrcList, even if it is empty */
104602105201
SrcList *pSrc = p->pSrc;
@@ -104636,11 +105235,13 @@
104636105235
memset(&sWalker, 0, sizeof(Walker));
104637105236
sWalker.pParse = pParse;
104638105237
sWalker.xExprCallback = renameUnmapExprCb;
104639105238
sqlite3WalkExprList(&sWalker, pEList);
104640105239
for(i=0; i<pEList->nExpr; i++){
104641
- sqlite3RenameTokenRemap(pParse, 0, (void*)pEList->a[i].zName);
105240
+ if( ALWAYS(pEList->a[i].eEName==ENAME_NAME) ){
105241
+ sqlite3RenameTokenRemap(pParse, 0, (void*)pEList->a[i].zEName);
105242
+ }
104642105243
}
104643105244
}
104644105245
}
104645105246
104646105247
/*
@@ -104774,12 +105375,15 @@
104774105375
const char *zOld
104775105376
){
104776105377
if( pEList ){
104777105378
int i;
104778105379
for(i=0; i<pEList->nExpr; i++){
104779
- char *zName = pEList->a[i].zName;
104780
- if( 0==sqlite3_stricmp(zName, zOld) ){
105380
+ char *zName = pEList->a[i].zEName;
105381
+ if( ALWAYS(pEList->a[i].eEName==ENAME_NAME)
105382
+ && ALWAYS(zName!=0)
105383
+ && 0==sqlite3_stricmp(zName, zOld)
105384
+ ){
104781105385
renameTokenFind(pParse, pCtx, (void*)zName);
104782105386
}
104783105387
}
104784105388
}
104785105389
}
@@ -107879,11 +108483,11 @@
107879108483
pFix->pParse = pParse;
107880108484
pFix->zDb = db->aDb[iDb].zDbSName;
107881108485
pFix->pSchema = db->aDb[iDb].pSchema;
107882108486
pFix->zType = zType;
107883108487
pFix->pName = pName;
107884
- pFix->bVarOnly = (iDb==1);
108488
+ pFix->bTemp = (iDb==1);
107885108489
}
107886108490
107887108491
/*
107888108492
** The following set of routines walk through the parse tree and assign
107889108493
** a specific database to all table references where the database name
@@ -107907,20 +108511,21 @@
107907108511
struct SrcList_item *pItem;
107908108512
107909108513
if( NEVER(pList==0) ) return 0;
107910108514
zDb = pFix->zDb;
107911108515
for(i=0, pItem=pList->a; i<pList->nSrc; i++, pItem++){
107912
- if( pFix->bVarOnly==0 ){
108516
+ if( pFix->bTemp==0 ){
107913108517
if( pItem->zDatabase && sqlite3StrICmp(pItem->zDatabase, zDb) ){
107914108518
sqlite3ErrorMsg(pFix->pParse,
107915108519
"%s %T cannot reference objects in database %s",
107916108520
pFix->zType, pFix->pName, pItem->zDatabase);
107917108521
return 1;
107918108522
}
107919108523
sqlite3DbFree(pFix->pParse->db, pItem->zDatabase);
107920108524
pItem->zDatabase = 0;
107921108525
pItem->pSchema = pFix->pSchema;
108526
+ pItem->fg.fromDDL = 1;
107922108527
}
107923108528
#if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_TRIGGER)
107924108529
if( sqlite3FixSelect(pFix, pItem->pSelect) ) return 1;
107925108530
if( sqlite3FixExpr(pFix, pItem->pOn) ) return 1;
107926108531
#endif
@@ -107972,11 +108577,11 @@
107972108577
SQLITE_PRIVATE int sqlite3FixExpr(
107973108578
DbFixer *pFix, /* Context of the fixation */
107974108579
Expr *pExpr /* The expression to be fixed to one database */
107975108580
){
107976108581
while( pExpr ){
107977
- ExprSetProperty(pExpr, EP_Indirect);
108582
+ if( !pFix->bTemp ) ExprSetProperty(pExpr, EP_FromDDL);
107978108583
if( pExpr->op==TK_VARIABLE ){
107979108584
if( pFix->pParse->db->init.busy ){
107980108585
pExpr->op = TK_NULL;
107981108586
}else{
107982108587
sqlite3ErrorMsg(pFix->pParse, "%s cannot use variables", pFix->zType);
@@ -109727,12 +110332,13 @@
109727110332
Table *p;
109728110333
Column *pCol;
109729110334
sqlite3 *db = pParse->db;
109730110335
p = pParse->pNewTable;
109731110336
if( p!=0 ){
110337
+ int isInit = db->init.busy && db->init.iDb!=1;
109732110338
pCol = &(p->aCol[p->nCol-1]);
109733
- if( !sqlite3ExprIsConstantOrFunction(pExpr, db->init.busy) ){
110339
+ if( !sqlite3ExprIsConstantOrFunction(pExpr, isInit) ){
109734110340
sqlite3ErrorMsg(pParse, "default value of column [%s] is not constant",
109735110341
pCol->zName);
109736110342
#ifndef SQLITE_OMIT_GENERATED_COLUMNS
109737110343
}else if( pCol->colFlags & COLFLAG_GENERATED ){
109738110344
testcase( pCol->colFlags & COLFLAG_VIRTUAL );
@@ -110948,11 +111554,14 @@
110948111554
db->xAuth = xAuth;
110949111555
#else
110950111556
pSelTab = sqlite3ResultSetOfSelect(pParse, pSel, SQLITE_AFF_NONE);
110951111557
#endif
110952111558
pParse->nTab = n;
110953
- if( pTable->pCheck ){
111559
+ if( pSelTab==0 ){
111560
+ pTable->nCol = 0;
111561
+ nErr++;
111562
+ }else if( pTable->pCheck ){
110954111563
/* CREATE VIEW name(arglist) AS ...
110955111564
** The names of the columns in the table are taken from
110956111565
** arglist which is stored in pTable->pCheck. The pCheck field
110957111566
** normally holds CHECK constraints on an ordinary table, but for
110958111567
** a VIEW it holds the list of column names.
@@ -110964,23 +111573,20 @@
110964111573
&& pTable->nCol==pSel->pEList->nExpr
110965111574
){
110966111575
sqlite3SelectAddColumnTypeAndCollation(pParse, pTable, pSel,
110967111576
SQLITE_AFF_NONE);
110968111577
}
110969
- }else if( pSelTab ){
111578
+ }else{
110970111579
/* CREATE VIEW name AS... without an argument list. Construct
110971111580
** the column names from the SELECT statement that defines the view.
110972111581
*/
110973111582
assert( pTable->aCol==0 );
110974111583
pTable->nCol = pSelTab->nCol;
110975111584
pTable->aCol = pSelTab->aCol;
110976111585
pSelTab->nCol = 0;
110977111586
pSelTab->aCol = 0;
110978111587
assert( sqlite3SchemaMutexHeld(db, 0, pTable->pSchema) );
110979
- }else{
110980
- pTable->nCol = 0;
110981
- nErr++;
110982111588
}
110983111589
pTable->nNVCol = pTable->nCol;
110984111590
sqlite3DeleteTable(db, pSelTab);
110985111591
sqlite3SelectDelete(db, pSel);
110986111592
EnableLookaside;
@@ -111430,11 +112036,11 @@
111430112036
nCol = pFromCol->nExpr;
111431112037
}
111432112038
nByte = sizeof(*pFKey) + (nCol-1)*sizeof(pFKey->aCol[0]) + pTo->n + 1;
111433112039
if( pToCol ){
111434112040
for(i=0; i<pToCol->nExpr; i++){
111435
- nByte += sqlite3Strlen30(pToCol->a[i].zName) + 1;
112041
+ nByte += sqlite3Strlen30(pToCol->a[i].zEName) + 1;
111436112042
}
111437112043
}
111438112044
pFKey = sqlite3DbMallocZero(db, nByte );
111439112045
if( pFKey==0 ){
111440112046
goto fk_end;
@@ -111455,34 +112061,34 @@
111455112061
pFKey->aCol[0].iFrom = p->nCol-1;
111456112062
}else{
111457112063
for(i=0; i<nCol; i++){
111458112064
int j;
111459112065
for(j=0; j<p->nCol; j++){
111460
- if( sqlite3StrICmp(p->aCol[j].zName, pFromCol->a[i].zName)==0 ){
112066
+ if( sqlite3StrICmp(p->aCol[j].zName, pFromCol->a[i].zEName)==0 ){
111461112067
pFKey->aCol[i].iFrom = j;
111462112068
break;
111463112069
}
111464112070
}
111465112071
if( j>=p->nCol ){
111466112072
sqlite3ErrorMsg(pParse,
111467112073
"unknown column \"%s\" in foreign key definition",
111468
- pFromCol->a[i].zName);
112074
+ pFromCol->a[i].zEName);
111469112075
goto fk_end;
111470112076
}
111471112077
if( IN_RENAME_OBJECT ){
111472
- sqlite3RenameTokenRemap(pParse, &pFKey->aCol[i], pFromCol->a[i].zName);
112078
+ sqlite3RenameTokenRemap(pParse, &pFKey->aCol[i], pFromCol->a[i].zEName);
111473112079
}
111474112080
}
111475112081
}
111476112082
if( pToCol ){
111477112083
for(i=0; i<nCol; i++){
111478
- int n = sqlite3Strlen30(pToCol->a[i].zName);
112084
+ int n = sqlite3Strlen30(pToCol->a[i].zEName);
111479112085
pFKey->aCol[i].zCol = z;
111480112086
if( IN_RENAME_OBJECT ){
111481
- sqlite3RenameTokenRemap(pParse, z, pToCol->a[i].zName);
112087
+ sqlite3RenameTokenRemap(pParse, z, pToCol->a[i].zEName);
111482112088
}
111483
- memcpy(z, pToCol->a[i].zName, n);
112089
+ memcpy(z, pToCol->a[i].zEName, n);
111484112090
z[n] = 0;
111485112091
z += n+1;
111486112092
}
111487112093
}
111488112094
pFKey->isDeferred = 0;
@@ -113637,16 +114243,17 @@
113637114243
FuncDef *p, /* The function we are evaluating for match quality */
113638114244
int nArg, /* Desired number of arguments. (-1)==any */
113639114245
u8 enc /* Desired text encoding */
113640114246
){
113641114247
int match;
113642
-
113643
- /* nArg of -2 is a special case */
113644
- if( nArg==(-2) ) return (p->xSFunc==0) ? 0 : FUNC_PERFECT_MATCH;
114248
+ assert( p->nArg>=-1 );
113645114249
113646114250
/* Wrong number of arguments means "no match" */
113647
- if( p->nArg!=nArg && p->nArg>=0 ) return 0;
114251
+ if( p->nArg!=nArg ){
114252
+ if( nArg==(-2) ) return (p->xSFunc==0) ? 0 : FUNC_PERFECT_MATCH;
114253
+ if( p->nArg>=0 ) return 0;
114254
+ }
113648114255
113649114256
/* Give a better score to a function with a specific number of arguments
113650114257
** than to function that accepts any number of arguments. */
113651114258
if( p->nArg==nArg ){
113652114259
match = 4;
@@ -116747,30 +117354,35 @@
116747117354
** are read-only after initialization is complete.
116748117355
**
116749117356
** For peak efficiency, put the most frequently used function last.
116750117357
*/
116751117358
static FuncDef aBuiltinFunc[] = {
117359
+/***** Functions only available with SQLITE_TESTCTRL_INTERNAL_FUNCTIONS *****/
117360
+ TEST_FUNC(implies_nonnull_row, 2, INLINEFUNC_implies_nonnull_row, 0),
117361
+ TEST_FUNC(expr_compare, 2, INLINEFUNC_expr_compare, 0),
117362
+ TEST_FUNC(expr_implies_expr, 2, INLINEFUNC_expr_implies_expr, 0),
117363
+#ifdef SQLITE_DEBUG
117364
+ TEST_FUNC(affinity, 1, INLINEFUNC_affinity, 0),
117365
+#endif
117366
+/***** Regular functions *****/
116752117367
#ifdef SQLITE_SOUNDEX
116753117368
FUNCTION(soundex, 1, 0, 0, soundexFunc ),
116754117369
#endif
116755117370
#ifndef SQLITE_OMIT_LOAD_EXTENSION
116756
- VFUNCTION(load_extension, 1, 0, 0, loadExt ),
116757
- VFUNCTION(load_extension, 2, 0, 0, loadExt ),
117371
+ SFUNCTION(load_extension, 1, 0, 0, loadExt ),
117372
+ SFUNCTION(load_extension, 2, 0, 0, loadExt ),
116758117373
#endif
116759117374
#if SQLITE_USER_AUTHENTICATION
116760117375
FUNCTION(sqlite_crypt, 2, 0, 0, sqlite3CryptFunc ),
116761117376
#endif
116762117377
#ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
116763117378
DFUNCTION(sqlite_compileoption_used,1, 0, 0, compileoptionusedFunc ),
116764117379
DFUNCTION(sqlite_compileoption_get, 1, 0, 0, compileoptiongetFunc ),
116765117380
#endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
116766
- FUNCTION2(unlikely, 1, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY),
116767
- FUNCTION2(likelihood, 2, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY),
116768
- FUNCTION2(likely, 1, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY),
116769
-#ifdef SQLITE_DEBUG
116770
- FUNCTION2(affinity, 1, 0, 0, noopFunc, SQLITE_FUNC_AFFINITY),
116771
-#endif
117381
+ INLINE_FUNC(unlikely, 1, INLINEFUNC_unlikely, SQLITE_FUNC_UNLIKELY),
117382
+ INLINE_FUNC(likelihood, 2, INLINEFUNC_unlikely, SQLITE_FUNC_UNLIKELY),
117383
+ INLINE_FUNC(likely, 1, INLINEFUNC_unlikely, SQLITE_FUNC_UNLIKELY),
116772117384
#ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
116773117385
FUNCTION2(sqlite_offset, 1, 0, 0, noopFunc, SQLITE_FUNC_OFFSET|
116774117386
SQLITE_FUNC_TYPEOF),
116775117387
#endif
116776117388
FUNCTION(ltrim, 1, 1, 0, trimFunc ),
@@ -116799,11 +117411,11 @@
116799117411
FUNCTION(round, 2, 0, 0, roundFunc ),
116800117412
#endif
116801117413
FUNCTION(upper, 1, 0, 0, upperFunc ),
116802117414
FUNCTION(lower, 1, 0, 0, lowerFunc ),
116803117415
FUNCTION(hex, 1, 0, 0, hexFunc ),
116804
- FUNCTION2(ifnull, 2, 0, 0, noopFunc, SQLITE_FUNC_COALESCE),
117416
+ INLINE_FUNC(ifnull, 2, INLINEFUNC_coalesce, SQLITE_FUNC_COALESCE),
116805117417
VFUNCTION(random, 0, 0, 0, randomFunc ),
116806117418
VFUNCTION(randomblob, 1, 0, 0, randomBlob ),
116807117419
FUNCTION(nullif, 2, 0, 1, nullifFunc ),
116808117420
DFUNCTION(sqlite_version, 0, 0, 0, versionFunc ),
116809117421
DFUNCTION(sqlite_source_id, 0, 0, 0, sourceidFunc ),
@@ -116839,11 +117451,11 @@
116839117451
#ifdef SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION
116840117452
FUNCTION(unknown, -1, 0, 0, unknownFunc ),
116841117453
#endif
116842117454
FUNCTION(coalesce, 1, 0, 0, 0 ),
116843117455
FUNCTION(coalesce, 0, 0, 0, 0 ),
116844
- FUNCTION2(coalesce, -1, 0, 0, noopFunc, SQLITE_FUNC_COALESCE),
117456
+ INLINE_FUNC(coalesce, -1, INLINEFUNC_coalesce, SQLITE_FUNC_COALESCE),
116845117457
};
116846117458
#ifndef SQLITE_OMIT_ALTERTABLE
116847117459
sqlite3AlterFunctions();
116848117460
#endif
116849117461
sqlite3WindowFunctions();
@@ -119340,10 +119952,11 @@
119340119952
** C: yield X, at EOF goto D
119341119953
** insert the select result into <table> from R..R+n
119342119954
** goto C
119343119955
** D: ...
119344119956
*/
119957
+ sqlite3VdbeReleaseRegisters(pParse, regData, pTab->nCol, 0, 0);
119345119958
addrInsTop = addrCont = sqlite3VdbeAddOp1(v, OP_Yield, dest.iSDParm);
119346119959
VdbeCoverage(v);
119347119960
if( ipkColumn>=0 ){
119348119961
/* tag-20191021-001: If the INTEGER PRIMARY KEY is being generated by the
119349119962
** SELECT, go ahead and copy the value into the rowid slot now, so that
@@ -119600,10 +120213,19 @@
119600120213
sqlite3VdbeAddOp2(v, OP_Next, srcTab, addrCont); VdbeCoverage(v);
119601120214
sqlite3VdbeJumpHere(v, addrInsTop);
119602120215
sqlite3VdbeAddOp1(v, OP_Close, srcTab);
119603120216
}else if( pSelect ){
119604120217
sqlite3VdbeGoto(v, addrCont);
120218
+#ifdef SQLITE_DEBUG
120219
+ /* If we are jumping back to an OP_Yield that is preceded by an
120220
+ ** OP_ReleaseReg, set the p5 flag on the OP_Goto so that the
120221
+ ** OP_ReleaseReg will be included in the loop. */
120222
+ if( sqlite3VdbeGetOp(v, addrCont-1)->opcode==OP_ReleaseReg ){
120223
+ assert( sqlite3VdbeGetOp(v, addrCont)->opcode==OP_Yield );
120224
+ sqlite3VdbeChangeP5(v, 1);
120225
+ }
120226
+#endif
119605120227
sqlite3VdbeJumpHere(v, addrInsTop);
119606120228
}
119607120229
119608120230
insert_end:
119609120231
/* Update the sqlite_sequence table by storing the content of the
@@ -119822,11 +120444,10 @@
119822120444
sqlite3 *db; /* Database connection */
119823120445
int i; /* loop counter */
119824120446
int ix; /* Index loop counter */
119825120447
int nCol; /* Number of columns */
119826120448
int onError; /* Conflict resolution strategy */
119827
- int addr1; /* Address of jump instruction */
119828120449
int seenReplace = 0; /* True if REPLACE is used to resolve INT PK conflict */
119829120450
int nPkField; /* Number of fields in PRIMARY KEY. 1 for ROWID tables */
119830120451
Index *pUpIdx = 0; /* Index to which to apply the upsert */
119831120452
u8 isUpdate; /* True if this is an UPDATE operation */
119832120453
u8 bAffinityDone = 0; /* True if the OP_Affinity operation has been run */
@@ -119866,75 +120487,104 @@
119866120487
iDataCur, iIdxCur, regNewData, regOldData, pkChng));
119867120488
119868120489
/* Test all NOT NULL constraints.
119869120490
*/
119870120491
if( pTab->tabFlags & TF_HasNotNull ){
119871
- for(i=0; i<nCol; i++){
119872
- int iReg;
119873
- onError = pTab->aCol[i].notNull;
119874
- if( onError==OE_None ) continue; /* No NOT NULL on this column */
119875
- if( i==pTab->iPKey ){
119876
- continue; /* ROWID is never NULL */
119877
- }
119878
- if( aiChng && aiChng[i]<0 ){
119879
- /* Don't bother checking for NOT NULL on columns that do not change */
119880
- continue;
119881
- }
119882
- if( overrideError!=OE_Default ){
119883
- onError = overrideError;
119884
- }else if( onError==OE_Default ){
119885
- onError = OE_Abort;
119886
- }
119887
- if( onError==OE_Replace && pTab->aCol[i].pDflt==0 ){
119888
- onError = OE_Abort;
119889
- }
119890
- assert( onError==OE_Rollback || onError==OE_Abort || onError==OE_Fail
119891
- || onError==OE_Ignore || onError==OE_Replace );
119892
- addr1 = 0;
119893
- testcase( i!=sqlite3TableColumnToStorage(pTab, i) );
119894
- testcase( pTab->aCol[i].colFlags & COLFLAG_VIRTUAL );
119895
- testcase( pTab->aCol[i].colFlags & COLFLAG_STORED );
119896
- iReg = sqlite3TableColumnToStorage(pTab, i) + regNewData + 1;
119897
- switch( onError ){
119898
- case OE_Replace: {
119899
- assert( onError==OE_Replace );
119900
- addr1 = sqlite3VdbeMakeLabel(pParse);
119901
- sqlite3VdbeAddOp2(v, OP_NotNull, iReg, addr1);
119902
- VdbeCoverage(v);
119903
- if( (pTab->aCol[i].colFlags & COLFLAG_GENERATED)==0 ){
119904
- sqlite3ExprCode(pParse, pTab->aCol[i].pDflt, regNewData+1+i);
119905
- sqlite3VdbeAddOp2(v, OP_NotNull, iReg, addr1);
119906
- VdbeCoverage(v);
119907
- }
119908
- onError = OE_Abort;
119909
- /* Fall through into the OE_Abort case to generate code that runs
119910
- ** if both the input and the default value are NULL */
119911
- }
119912
- case OE_Abort:
119913
- sqlite3MayAbort(pParse);
119914
- /* Fall through */
119915
- case OE_Rollback:
119916
- case OE_Fail: {
119917
- char *zMsg = sqlite3MPrintf(db, "%s.%s", pTab->zName,
119918
- pTab->aCol[i].zName);
119919
- sqlite3VdbeAddOp3(v, OP_HaltIfNull, SQLITE_CONSTRAINT_NOTNULL,
119920
- onError, iReg);
119921
- sqlite3VdbeAppendP4(v, zMsg, P4_DYNAMIC);
119922
- sqlite3VdbeChangeP5(v, P5_ConstraintNotNull);
119923
- VdbeCoverage(v);
119924
- if( addr1 ) sqlite3VdbeResolveLabel(v, addr1);
119925
- break;
119926
- }
119927
- default: {
119928
- assert( onError==OE_Ignore );
119929
- sqlite3VdbeAddOp2(v, OP_IsNull, iReg, ignoreDest);
119930
- VdbeCoverage(v);
119931
- break;
119932
- }
119933
- }
119934
- }
119935
- }
120492
+ int b2ndPass = 0; /* True if currently running 2nd pass */
120493
+ int nSeenReplace = 0; /* Number of ON CONFLICT REPLACE operations */
120494
+ int nGenerated = 0; /* Number of generated columns with NOT NULL */
120495
+ while(1){ /* Make 2 passes over columns. Exit loop via "break" */
120496
+ for(i=0; i<nCol; i++){
120497
+ int iReg; /* Register holding column value */
120498
+ Column *pCol = &pTab->aCol[i]; /* The column to check for NOT NULL */
120499
+ int isGenerated; /* non-zero if column is generated */
120500
+ onError = pCol->notNull;
120501
+ if( onError==OE_None ) continue; /* No NOT NULL on this column */
120502
+ if( i==pTab->iPKey ){
120503
+ continue; /* ROWID is never NULL */
120504
+ }
120505
+ isGenerated = pCol->colFlags & COLFLAG_GENERATED;
120506
+ if( isGenerated && !b2ndPass ){
120507
+ nGenerated++;
120508
+ continue; /* Generated columns processed on 2nd pass */
120509
+ }
120510
+ if( aiChng && aiChng[i]<0 && !isGenerated ){
120511
+ /* Do not check NOT NULL on columns that do not change */
120512
+ continue;
120513
+ }
120514
+ if( overrideError!=OE_Default ){
120515
+ onError = overrideError;
120516
+ }else if( onError==OE_Default ){
120517
+ onError = OE_Abort;
120518
+ }
120519
+ if( onError==OE_Replace ){
120520
+ if( b2ndPass /* REPLACE becomes ABORT on the 2nd pass */
120521
+ || pCol->pDflt==0 /* REPLACE is ABORT if no DEFAULT value */
120522
+ ){
120523
+ testcase( pCol->colFlags & COLFLAG_VIRTUAL );
120524
+ testcase( pCol->colFlags & COLFLAG_STORED );
120525
+ testcase( pCol->colFlags & COLFLAG_GENERATED );
120526
+ onError = OE_Abort;
120527
+ }else{
120528
+ assert( !isGenerated );
120529
+ }
120530
+ }else if( b2ndPass && !isGenerated ){
120531
+ continue;
120532
+ }
120533
+ assert( onError==OE_Rollback || onError==OE_Abort || onError==OE_Fail
120534
+ || onError==OE_Ignore || onError==OE_Replace );
120535
+ testcase( i!=sqlite3TableColumnToStorage(pTab, i) );
120536
+ iReg = sqlite3TableColumnToStorage(pTab, i) + regNewData + 1;
120537
+ switch( onError ){
120538
+ case OE_Replace: {
120539
+ int addr1 = sqlite3VdbeAddOp1(v, OP_NotNull, iReg);
120540
+ VdbeCoverage(v);
120541
+ assert( (pCol->colFlags & COLFLAG_GENERATED)==0 );
120542
+ nSeenReplace++;
120543
+ sqlite3ExprCode(pParse, pCol->pDflt, iReg);
120544
+ sqlite3VdbeJumpHere(v, addr1);
120545
+ break;
120546
+ }
120547
+ case OE_Abort:
120548
+ sqlite3MayAbort(pParse);
120549
+ /* Fall through */
120550
+ case OE_Rollback:
120551
+ case OE_Fail: {
120552
+ char *zMsg = sqlite3MPrintf(db, "%s.%s", pTab->zName,
120553
+ pCol->zName);
120554
+ sqlite3VdbeAddOp3(v, OP_HaltIfNull, SQLITE_CONSTRAINT_NOTNULL,
120555
+ onError, iReg);
120556
+ sqlite3VdbeAppendP4(v, zMsg, P4_DYNAMIC);
120557
+ sqlite3VdbeChangeP5(v, P5_ConstraintNotNull);
120558
+ VdbeCoverage(v);
120559
+ break;
120560
+ }
120561
+ default: {
120562
+ assert( onError==OE_Ignore );
120563
+ sqlite3VdbeAddOp2(v, OP_IsNull, iReg, ignoreDest);
120564
+ VdbeCoverage(v);
120565
+ break;
120566
+ }
120567
+ } /* end switch(onError) */
120568
+ } /* end loop i over columns */
120569
+ if( nGenerated==0 && nSeenReplace==0 ){
120570
+ /* If there are no generated columns with NOT NULL constraints
120571
+ ** and no NOT NULL ON CONFLICT REPLACE constraints, then a single
120572
+ ** pass is sufficient */
120573
+ break;
120574
+ }
120575
+ if( b2ndPass ) break; /* Never need more than 2 passes */
120576
+ b2ndPass = 1;
120577
+ if( nSeenReplace>0 && (pTab->tabFlags & TF_HasGenerated)!=0 ){
120578
+ /* If any NOT NULL ON CONFLICT REPLACE constraints fired on the
120579
+ ** first pass, recomputed values for all generated columns, as
120580
+ ** those values might depend on columns affected by the REPLACE.
120581
+ */
120582
+ sqlite3ComputeGeneratedColumns(pParse, regNewData+1, pTab);
120583
+ }
120584
+ } /* end of 2-pass loop */
120585
+ } /* end if( has-not-null-constraints ) */
119936120586
119937120587
/* Test all CHECK constraints
119938120588
*/
119939120589
#ifndef SQLITE_OMIT_CHECK
119940120590
if( pTab->pCheck && (db->flags & SQLITE_IgnoreChecks)==0 ){
@@ -119955,11 +120605,11 @@
119955120605
sqlite3VdbeVerifyAbortable(v, onError);
119956120606
sqlite3ExprIfTrue(pParse, pExpr, allOk, SQLITE_JUMPIFNULL);
119957120607
if( onError==OE_Ignore ){
119958120608
sqlite3VdbeGoto(v, ignoreDest);
119959120609
}else{
119960
- char *zName = pCheck->a[i].zName;
120610
+ char *zName = pCheck->a[i].zEName;
119961120611
if( zName==0 ) zName = pTab->zName;
119962120612
if( onError==OE_Replace ) onError = OE_Abort; /* IMP: R-26383-51744 */
119963120613
sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_CHECK,
119964120614
onError, zName, P4_TRANSIENT,
119965120615
P5_ConstraintCheck);
@@ -120258,10 +120908,11 @@
120258120908
#ifdef SQLITE_ENABLE_NULL_TRIM
120259120909
if( pIdx->idxType==SQLITE_IDXTYPE_PRIMARYKEY ){
120260120910
sqlite3SetMakeRecordP5(v, pIdx->pTable);
120261120911
}
120262120912
#endif
120913
+ sqlite3VdbeReleaseRegisters(pParse, regIdx, pIdx->nColumn, 0, 0);
120263120914
120264120915
/* In an UPDATE operation, if this index is the PRIMARY KEY index
120265120916
** of a WITHOUT ROWID table and there has been no change the
120266120917
** primary key, then no collision is possible. The collision detection
120267120918
** logic below can all be skipped. */
@@ -120411,13 +121062,19 @@
120411121062
testcase( nConflictCk>1 );
120412121063
if( regTrigCnt ){
120413121064
sqlite3MultiWrite(pParse);
120414121065
nReplaceTrig++;
120415121066
}
121067
+ if( pTrigger && isUpdate ){
121068
+ sqlite3VdbeAddOp1(v, OP_CursorLock, iDataCur);
121069
+ }
120416121070
sqlite3GenerateRowDelete(pParse, pTab, pTrigger, iDataCur, iIdxCur,
120417121071
regR, nPkField, 0, OE_Replace,
120418121072
(pIdx==pPk ? ONEPASS_SINGLE : ONEPASS_OFF), iThisCur);
121073
+ if( pTrigger && isUpdate ){
121074
+ sqlite3VdbeAddOp1(v, OP_CursorUnlock, iDataCur);
121075
+ }
120419121076
if( regTrigCnt ){
120420121077
int addrBypass; /* Jump destination to bypass recheck logic */
120421121078
120422121079
sqlite3VdbeAddOp2(v, OP_AddImm, regTrigCnt, 1); /* incr trigger cnt */
120423121080
addrBypass = sqlite3VdbeAddOp0(v, OP_Goto); /* Bypass recheck */
@@ -122889,39 +123546,43 @@
122889123546
/* 16 */ "cid",
122890123547
/* 17 */ "name",
122891123548
/* 18 */ "desc",
122892123549
/* 19 */ "coll",
122893123550
/* 20 */ "key",
122894
- /* 21 */ "tbl", /* Used by: stats */
122895
- /* 22 */ "idx",
122896
- /* 23 */ "wdth",
122897
- /* 24 */ "hght",
122898
- /* 25 */ "flgs",
122899
- /* 26 */ "seq", /* Used by: index_list */
122900
- /* 27 */ "name",
122901
- /* 28 */ "unique",
122902
- /* 29 */ "origin",
122903
- /* 30 */ "partial",
122904
- /* 31 */ "table", /* Used by: foreign_key_check */
122905
- /* 32 */ "rowid",
122906
- /* 33 */ "parent",
122907
- /* 34 */ "fkid",
123551
+ /* 21 */ "name", /* Used by: function_list */
123552
+ /* 22 */ "builtin",
123553
+ /* 23 */ "type",
123554
+ /* 24 */ "enc",
123555
+ /* 25 */ "narg",
123556
+ /* 26 */ "flags",
123557
+ /* 27 */ "tbl", /* Used by: stats */
123558
+ /* 28 */ "idx",
123559
+ /* 29 */ "wdth",
123560
+ /* 30 */ "hght",
123561
+ /* 31 */ "flgs",
123562
+ /* 32 */ "seq", /* Used by: index_list */
123563
+ /* 33 */ "name",
123564
+ /* 34 */ "unique",
123565
+ /* 35 */ "origin",
123566
+ /* 36 */ "partial",
123567
+ /* 37 */ "table", /* Used by: foreign_key_check */
123568
+ /* 38 */ "rowid",
123569
+ /* 39 */ "parent",
123570
+ /* 40 */ "fkid",
122908123571
/* index_info reuses 15 */
122909
- /* 35 */ "seq", /* Used by: database_list */
122910
- /* 36 */ "name",
122911
- /* 37 */ "file",
122912
- /* 38 */ "busy", /* Used by: wal_checkpoint */
122913
- /* 39 */ "log",
122914
- /* 40 */ "checkpointed",
122915
- /* 41 */ "name", /* Used by: function_list */
122916
- /* 42 */ "builtin",
122917
- /* collation_list reuses 26 */
122918
- /* 43 */ "database", /* Used by: lock_status */
122919
- /* 44 */ "status",
122920
- /* 45 */ "cache_size", /* Used by: default_cache_size */
123572
+ /* 41 */ "seq", /* Used by: database_list */
123573
+ /* 42 */ "name",
123574
+ /* 43 */ "file",
123575
+ /* 44 */ "busy", /* Used by: wal_checkpoint */
123576
+ /* 45 */ "log",
123577
+ /* 46 */ "checkpointed",
123578
+ /* collation_list reuses 32 */
123579
+ /* 47 */ "database", /* Used by: lock_status */
123580
+ /* 48 */ "status",
123581
+ /* 49 */ "cache_size", /* Used by: default_cache_size */
122921123582
/* module_list pragma_list reuses 9 */
122922
- /* 46 */ "timeout", /* Used by: busy_timeout */
123583
+ /* 50 */ "timeout", /* Used by: busy_timeout */
122923123584
};
122924123585
122925123586
/* Definitions of all built-in pragmas */
122926123587
typedef struct PragmaName {
122927123588
const char *const zName; /* Name of pragma */
@@ -122963,11 +123624,11 @@
122963123624
#endif
122964123625
#endif
122965123626
{/* zName: */ "busy_timeout",
122966123627
/* ePragTyp: */ PragTyp_BUSY_TIMEOUT,
122967123628
/* ePragFlg: */ PragFlg_Result0,
122968
- /* ColNames: */ 46, 1,
123629
+ /* ColNames: */ 50, 1,
122969123630
/* iArg: */ 0 },
122970123631
#if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
122971123632
{/* zName: */ "cache_size",
122972123633
/* ePragTyp: */ PragTyp_CACHE_SIZE,
122973123634
/* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq|PragFlg_NoColumns1,
@@ -123002,11 +123663,11 @@
123002123663
#endif
123003123664
#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
123004123665
{/* zName: */ "collation_list",
123005123666
/* ePragTyp: */ PragTyp_COLLATION_LIST,
123006123667
/* ePragFlg: */ PragFlg_Result0,
123007
- /* ColNames: */ 26, 2,
123668
+ /* ColNames: */ 32, 2,
123008123669
/* iArg: */ 0 },
123009123670
#endif
123010123671
#if !defined(SQLITE_OMIT_COMPILEOPTION_DIAGS)
123011123672
{/* zName: */ "compile_options",
123012123673
/* ePragTyp: */ PragTyp_COMPILE_OPTIONS,
@@ -123037,18 +123698,18 @@
123037123698
#endif
123038123699
#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
123039123700
{/* zName: */ "database_list",
123040123701
/* ePragTyp: */ PragTyp_DATABASE_LIST,
123041123702
/* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0,
123042
- /* ColNames: */ 35, 3,
123703
+ /* ColNames: */ 41, 3,
123043123704
/* iArg: */ 0 },
123044123705
#endif
123045123706
#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED)
123046123707
{/* zName: */ "default_cache_size",
123047123708
/* ePragTyp: */ PragTyp_DEFAULT_CACHE_SIZE,
123048123709
/* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq|PragFlg_NoColumns1,
123049
- /* ColNames: */ 45, 1,
123710
+ /* ColNames: */ 49, 1,
123050123711
/* iArg: */ 0 },
123051123712
#endif
123052123713
#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
123053123714
#if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
123054123715
{/* zName: */ "defer_foreign_keys",
@@ -123074,11 +123735,11 @@
123074123735
#endif
123075123736
#if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
123076123737
{/* zName: */ "foreign_key_check",
123077123738
/* ePragTyp: */ PragTyp_FOREIGN_KEY_CHECK,
123078123739
/* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0,
123079
- /* ColNames: */ 31, 4,
123740
+ /* ColNames: */ 37, 4,
123080123741
/* iArg: */ 0 },
123081123742
#endif
123082123743
#if !defined(SQLITE_OMIT_FOREIGN_KEY)
123083123744
{/* zName: */ "foreign_key_list",
123084123745
/* ePragTyp: */ PragTyp_FOREIGN_KEY_LIST,
@@ -123117,11 +123778,11 @@
123117123778
#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
123118123779
#if !defined(SQLITE_OMIT_INTROSPECTION_PRAGMAS)
123119123780
{/* zName: */ "function_list",
123120123781
/* ePragTyp: */ PragTyp_FUNCTION_LIST,
123121123782
/* ePragFlg: */ PragFlg_Result0,
123122
- /* ColNames: */ 41, 2,
123783
+ /* ColNames: */ 21, 6,
123123123784
/* iArg: */ 0 },
123124123785
#endif
123125123786
#endif
123126123787
{/* zName: */ "hard_heap_limit",
123127123788
/* ePragTyp: */ PragTyp_HARD_HEAP_LIMIT,
@@ -123163,11 +123824,11 @@
123163123824
/* ColNames: */ 15, 3,
123164123825
/* iArg: */ 0 },
123165123826
{/* zName: */ "index_list",
123166123827
/* ePragTyp: */ PragTyp_INDEX_LIST,
123167123828
/* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result1|PragFlg_SchemaOpt,
123168
- /* ColNames: */ 26, 5,
123829
+ /* ColNames: */ 32, 5,
123169123830
/* iArg: */ 0 },
123170123831
{/* zName: */ "index_xinfo",
123171123832
/* ePragTyp: */ PragTyp_INDEX_INFO,
123172123833
/* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result1|PragFlg_SchemaOpt,
123173123834
/* ColNames: */ 15, 6,
@@ -123215,11 +123876,11 @@
123215123876
#endif
123216123877
#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
123217123878
{/* zName: */ "lock_status",
123218123879
/* ePragTyp: */ PragTyp_LOCK_STATUS,
123219123880
/* ePragFlg: */ PragFlg_Result0,
123220
- /* ColNames: */ 43, 2,
123881
+ /* ColNames: */ 47, 2,
123221123882
/* iArg: */ 0 },
123222123883
#endif
123223123884
#if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
123224123885
{/* zName: */ "locking_mode",
123225123886
/* ePragTyp: */ PragTyp_LOCKING_MODE,
@@ -123363,11 +124024,11 @@
123363124024
#endif
123364124025
#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) && defined(SQLITE_DEBUG)
123365124026
{/* zName: */ "stats",
123366124027
/* ePragTyp: */ PragTyp_STATS,
123367124028
/* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq,
123368
- /* ColNames: */ 21, 5,
124029
+ /* ColNames: */ 27, 5,
123369124030
/* iArg: */ 0 },
123370124031
#endif
123371124032
#if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
123372124033
{/* zName: */ "synchronous",
123373124034
/* ePragTyp: */ PragTyp_SYNCHRONOUS,
@@ -123414,10 +124075,17 @@
123414124075
{/* zName: */ "threads",
123415124076
/* ePragTyp: */ PragTyp_THREADS,
123416124077
/* ePragFlg: */ PragFlg_Result0,
123417124078
/* ColNames: */ 0, 0,
123418124079
/* iArg: */ 0 },
124080
+#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
124081
+ {/* zName: */ "trusted_schema",
124082
+ /* ePragTyp: */ PragTyp_FLAG,
124083
+ /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
124084
+ /* ColNames: */ 0, 0,
124085
+ /* iArg: */ SQLITE_TrustedSchema },
124086
+#endif
123419124087
#if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
123420124088
{/* zName: */ "user_version",
123421124089
/* ePragTyp: */ PragTyp_HEADER_VALUE,
123422124090
/* ePragFlg: */ PragFlg_NoColumns1|PragFlg_Result0,
123423124091
/* ColNames: */ 0, 0,
@@ -123459,11 +124127,11 @@
123459124127
/* ColNames: */ 0, 0,
123460124128
/* iArg: */ 0 },
123461124129
{/* zName: */ "wal_checkpoint",
123462124130
/* ePragTyp: */ PragTyp_WAL_CHECKPOINT,
123463124131
/* ePragFlg: */ PragFlg_NeedSchema,
123464
- /* ColNames: */ 38, 3,
124132
+ /* ColNames: */ 44, 3,
123465124133
/* iArg: */ 0 },
123466124134
#endif
123467124135
#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
123468124136
{/* zName: */ "writable_schema",
123469124137
/* ePragTyp: */ PragTyp_FLAG,
@@ -123470,11 +124138,11 @@
123470124138
/* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
123471124139
/* ColNames: */ 0, 0,
123472124140
/* iArg: */ SQLITE_WriteSchema|SQLITE_NoSchemaError },
123473124141
#endif
123474124142
};
123475
-/* Number of pragmas: 65 on by default, 81 total. */
124143
+/* Number of pragmas: 66 on by default, 82 total. */
123476124144
123477124145
/************** End of pragma.h **********************************************/
123478124146
/************** Continuing where we left off in pragma.c *********************/
123479124147
123480124148
/*
@@ -123739,10 +124407,59 @@
123739124407
lwr = mid + 1;
123740124408
}
123741124409
}
123742124410
return lwr>upr ? 0 : &aPragmaName[mid];
123743124411
}
124412
+
124413
+/*
124414
+** Create zero or more entries in the output for the SQL functions
124415
+** defined by FuncDef p.
124416
+*/
124417
+static void pragmaFunclistLine(
124418
+ Vdbe *v, /* The prepared statement being created */
124419
+ FuncDef *p, /* A particular function definition */
124420
+ int isBuiltin, /* True if this is a built-in function */
124421
+ int showInternFuncs /* True if showing internal functions */
124422
+){
124423
+ for(; p; p=p->pNext){
124424
+ const char *zType;
124425
+ static const u32 mask =
124426
+ SQLITE_DETERMINISTIC |
124427
+ SQLITE_DIRECTONLY |
124428
+ SQLITE_SUBTYPE |
124429
+ SQLITE_INNOCUOUS |
124430
+ SQLITE_FUNC_INTERNAL
124431
+ ;
124432
+ static const char *azEnc[] = { 0, "utf8", "utf16le", "utf16be" };
124433
+
124434
+ assert( SQLITE_FUNC_ENCMASK==0x3 );
124435
+ assert( strcmp(azEnc[SQLITE_UTF8],"utf8")==0 );
124436
+ assert( strcmp(azEnc[SQLITE_UTF16LE],"utf16le")==0 );
124437
+ assert( strcmp(azEnc[SQLITE_UTF16BE],"utf16be")==0 );
124438
+
124439
+ if( p->xSFunc==0 ) continue;
124440
+ if( (p->funcFlags & SQLITE_FUNC_INTERNAL)!=0
124441
+ && showInternFuncs==0
124442
+ ){
124443
+ continue;
124444
+ }
124445
+ if( p->xValue!=0 ){
124446
+ zType = "w";
124447
+ }else if( p->xFinalize!=0 ){
124448
+ zType = "a";
124449
+ }else{
124450
+ zType = "s";
124451
+ }
124452
+ sqlite3VdbeMultiLoad(v, 1, "sissii",
124453
+ p->zName, isBuiltin,
124454
+ zType, azEnc[p->funcFlags&SQLITE_FUNC_ENCMASK],
124455
+ p->nArg,
124456
+ (p->funcFlags & mask) ^ SQLITE_INNOCUOUS
124457
+ );
124458
+ }
124459
+}
124460
+
123744124461
123745124462
/*
123746124463
** Helper subroutine for PRAGMA integrity_check:
123747124464
**
123748124465
** Generate code to output a single-column result row with a value of the
@@ -124704,20 +125421,20 @@
124704125421
#ifndef SQLITE_OMIT_INTROSPECTION_PRAGMAS
124705125422
case PragTyp_FUNCTION_LIST: {
124706125423
int i;
124707125424
HashElem *j;
124708125425
FuncDef *p;
124709
- pParse->nMem = 2;
125426
+ int showInternFunc = (db->mDbFlags & DBFLAG_InternalFunc)!=0;
125427
+ pParse->nMem = 6;
124710125428
for(i=0; i<SQLITE_FUNC_HASH_SZ; i++){
124711125429
for(p=sqlite3BuiltinFunctions.a[i]; p; p=p->u.pHash ){
124712
- if( p->funcFlags & SQLITE_FUNC_INTERNAL ) continue;
124713
- sqlite3VdbeMultiLoad(v, 1, "si", p->zName, 1);
125430
+ pragmaFunclistLine(v, p, 1, showInternFunc);
124714125431
}
124715125432
}
124716125433
for(j=sqliteHashFirst(&db->aFunc); j; j=sqliteHashNext(j)){
124717125434
p = (FuncDef*)sqliteHashData(j);
124718
- sqlite3VdbeMultiLoad(v, 1, "si", p->zName, 0);
125435
+ pragmaFunclistLine(v, p, 0, showInternFunc);
124719125436
}
124720125437
}
124721125438
break;
124722125439
124723125440
#ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -127127,10 +127844,11 @@
127127127844
if( ALWAYS(p) ){
127128127845
clearSelect(pParse->db, p, 0);
127129127846
memset(&p->iLimit, 0, sizeof(Select) - offsetof(Select,iLimit));
127130127847
p->pEList = sqlite3ExprListAppend(pParse, 0,
127131127848
sqlite3ExprAlloc(pParse->db,TK_NULL,0,0));
127849
+ p->pSrc = sqlite3DbMallocZero(pParse->db, sizeof(SrcList));
127132127850
}
127133127851
}
127134127852
127135127853
/*
127136127854
** Return a pointer to the right-most SELECT statement in a compound.
@@ -127238,19 +127956,22 @@
127238127956
static int tableAndColumnIndex(
127239127957
SrcList *pSrc, /* Array of tables to search */
127240127958
int N, /* Number of tables in pSrc->a[] to search */
127241127959
const char *zCol, /* Name of the column we are looking for */
127242127960
int *piTab, /* Write index of pSrc->a[] here */
127243
- int *piCol /* Write index of pSrc->a[*piTab].pTab->aCol[] here */
127961
+ int *piCol, /* Write index of pSrc->a[*piTab].pTab->aCol[] here */
127962
+ int bIgnoreHidden /* True to ignore hidden columns */
127244127963
){
127245127964
int i; /* For looping over tables in pSrc */
127246127965
int iCol; /* Index of column matching zCol */
127247127966
127248127967
assert( (piTab==0)==(piCol==0) ); /* Both or neither are NULL */
127249127968
for(i=0; i<N; i++){
127250127969
iCol = columnIndex(pSrc->a[i].pTab, zCol);
127251
- if( iCol>=0 ){
127970
+ if( iCol>=0
127971
+ && (bIgnoreHidden==0 || IsHiddenColumn(&pSrc->a[i].pTab->aCol[iCol])==0)
127972
+ ){
127252127973
if( piTab ){
127253127974
*piTab = i;
127254127975
*piCol = iCol;
127255127976
}
127256127977
return 1;
@@ -127411,14 +128132,15 @@
127411128132
for(j=0; j<pRightTab->nCol; j++){
127412128133
char *zName; /* Name of column in the right table */
127413128134
int iLeft; /* Matching left table */
127414128135
int iLeftCol; /* Matching column in the left table */
127415128136
128137
+ if( IsHiddenColumn(&pRightTab->aCol[j]) ) continue;
127416128138
zName = pRightTab->aCol[j].zName;
127417
- if( tableAndColumnIndex(pSrc, i+1, zName, &iLeft, &iLeftCol) ){
128139
+ if( tableAndColumnIndex(pSrc, i+1, zName, &iLeft, &iLeftCol, 1) ){
127418128140
addWhereTerm(pParse, pSrc, iLeft, iLeftCol, i+1, j,
127419
- isOuter, &p->pWhere);
128141
+ isOuter, &p->pWhere);
127420128142
}
127421128143
}
127422128144
}
127423128145
127424128146
/* Disallow both ON and USING clauses in the same join
@@ -127454,11 +128176,11 @@
127454128176
int iRightCol; /* Column number of matching column on the right */
127455128177
127456128178
zName = pList->a[j].zName;
127457128179
iRightCol = columnIndex(pRightTab, zName);
127458128180
if( iRightCol<0
127459
- || !tableAndColumnIndex(pSrc, i+1, zName, &iLeft, &iLeftCol)
128181
+ || !tableAndColumnIndex(pSrc, i+1, zName, &iLeft, &iLeftCol, 0)
127460128182
){
127461128183
sqlite3ErrorMsg(pParse, "cannot join using column %s - column "
127462128184
"not present in both tables", zName);
127463128185
return 1;
127464128186
}
@@ -127860,11 +128582,11 @@
127860128582
pDest->nSdst = nResultCol;
127861128583
regOrig = regResult = pDest->iSdst;
127862128584
if( srcTab>=0 ){
127863128585
for(i=0; i<nResultCol; i++){
127864128586
sqlite3VdbeAddOp3(v, OP_Column, srcTab, i, regResult+i);
127865
- VdbeComment((v, "%s", p->pEList->a[i].zName));
128587
+ VdbeComment((v, "%s", p->pEList->a[i].zEName));
127866128588
}
127867128589
}else if( eDest!=SRT_Exists ){
127868128590
#ifdef SQLITE_ENABLE_SORTER_REFERENCES
127869128591
ExprList *pExtra = 0;
127870128592
#endif
@@ -128481,11 +129203,11 @@
128481129203
iRead = aOutEx[i].u.x.iOrderByCol-1;
128482129204
}else{
128483129205
iRead = iCol--;
128484129206
}
128485129207
sqlite3VdbeAddOp3(v, OP_Column, iSortTab, iRead, regRow+i);
128486
- VdbeComment((v, "%s", aOutEx[i].zName?aOutEx[i].zName : aOutEx[i].zSpan));
129208
+ VdbeComment((v, "%s", aOutEx[i].zEName));
128487129209
}
128488129210
}
128489129211
switch( eDest ){
128490129212
case SRT_Table:
128491129213
case SRT_EphemTab: {
@@ -128815,13 +129537,13 @@
128815129537
Expr *p = pEList->a[i].pExpr;
128816129538
128817129539
assert( p!=0 );
128818129540
assert( p->op!=TK_AGG_COLUMN ); /* Agg processing has not run yet */
128819129541
assert( p->op!=TK_COLUMN || p->y.pTab!=0 ); /* Covering idx not yet coded */
128820
- if( pEList->a[i].zName ){
129542
+ if( pEList->a[i].zEName && pEList->a[i].eEName==ENAME_NAME ){
128821129543
/* An AS clause always takes first priority */
128822
- char *zName = pEList->a[i].zName;
129544
+ char *zName = pEList->a[i].zEName;
128823129545
sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, SQLITE_TRANSIENT);
128824129546
}else if( srcName && p->op==TK_COLUMN ){
128825129547
char *zCol;
128826129548
int iCol = p->iColumn;
128827129549
pTab = p->y.pTab;
@@ -128839,11 +129561,11 @@
128839129561
sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, SQLITE_DYNAMIC);
128840129562
}else{
128841129563
sqlite3VdbeSetColName(v, i, COLNAME_NAME, zCol, SQLITE_TRANSIENT);
128842129564
}
128843129565
}else{
128844
- const char *z = pEList->a[i].zSpan;
129566
+ const char *z = pEList->a[i].zEName;
128845129567
z = z==0 ? sqlite3MPrintf(db, "column%d", i+1) : sqlite3DbStrDup(db, z);
128846129568
sqlite3VdbeSetColName(v, i, COLNAME_NAME, z, SQLITE_DYNAMIC);
128847129569
}
128848129570
}
128849129571
generateColumnTypes(pParse, pTabList, pEList);
@@ -128901,11 +129623,11 @@
128901129623
*paCol = aCol;
128902129624
128903129625
for(i=0, pCol=aCol; i<nCol && !db->mallocFailed; i++, pCol++){
128904129626
/* Get an appropriate name for the column
128905129627
*/
128906
- if( (zName = pEList->a[i].zName)!=0 ){
129628
+ if( (zName = pEList->a[i].zEName)!=0 && pEList->a[i].eEName==ENAME_NAME ){
128907129629
/* If the column contains an "AS <name>" phrase, use <name> as the name */
128908129630
}else{
128909129631
Expr *pColExpr = sqlite3ExprSkipCollateAndLikely(pEList->a[i].pExpr);
128910129632
while( pColExpr->op==TK_DOT ){
128911129633
pColExpr = pColExpr->pRight;
@@ -128921,14 +129643,14 @@
128921129643
}else if( pColExpr->op==TK_ID ){
128922129644
assert( !ExprHasProperty(pColExpr, EP_IntValue) );
128923129645
zName = pColExpr->u.zToken;
128924129646
}else{
128925129647
/* Use the original text of the column expression as its name */
128926
- zName = pEList->a[i].zSpan;
129648
+ zName = pEList->a[i].zEName;
128927129649
}
128928129650
}
128929
- if( zName ){
129651
+ if( zName && !sqlite3IsTrueOrFalse(zName) ){
128930129652
zName = sqlite3DbStrDup(db, zName);
128931129653
}else{
128932129654
zName = sqlite3MPrintf(db,"column%d",i+1);
128933129655
}
128934129656
@@ -130594,10 +131316,11 @@
130594131316
** (17c) every term within the subquery compound must have a FROM clause
130595131317
** (17d) the outer query may not be
130596131318
** (17d1) aggregate, or
130597131319
** (17d2) DISTINCT, or
130598131320
** (17d3) a join.
131321
+** (17e) the subquery may not contain window functions
130599131322
**
130600131323
** The parent and sub-query may contain WHERE clauses. Subject to
130601131324
** rules (11), (13) and (14), they may also contain ORDER BY,
130602131325
** LIMIT and OFFSET clauses. The subquery cannot use any compound
130603131326
** operator other than UNION ALL because all the other compound
@@ -130778,10 +131501,11 @@
130778131501
assert( pSub->pSrc!=0 );
130779131502
assert( pSub->pEList->nExpr==pSub1->pEList->nExpr );
130780131503
if( (pSub1->selFlags & (SF_Distinct|SF_Aggregate))!=0 /* (17b) */
130781131504
|| (pSub1->pPrior && pSub1->op!=TK_ALL) /* (17a) */
130782131505
|| pSub1->pSrc->nSrc<1 /* (17c) */
131506
+ || pSub1->pWin /* (17e) */
130783131507
){
130784131508
return 0;
130785131509
}
130786131510
testcase( pSub1->pSrc->nSrc>1 );
130787131511
}
@@ -131064,27 +131788,40 @@
131064131788
Expr **apExpr; /* [i*2] is COLUMN and [i*2+1] is VALUE */
131065131789
};
131066131790
131067131791
/*
131068131792
** Add a new entry to the pConst object. Except, do not add duplicate
131069
-** pColumn entires.
131793
+** pColumn entires. Also, do not add if doing so would not be appropriate.
131794
+**
131795
+** The caller guarantees the pColumn is a column and pValue is a constant.
131796
+** This routine has to do some additional checks before completing the
131797
+** insert.
131070131798
*/
131071131799
static void constInsert(
131072
- WhereConst *pConst, /* The WhereConst into which we are inserting */
131073
- Expr *pColumn, /* The COLUMN part of the constraint */
131074
- Expr *pValue /* The VALUE part of the constraint */
131800
+ WhereConst *pConst, /* The WhereConst into which we are inserting */
131801
+ Expr *pColumn, /* The COLUMN part of the constraint */
131802
+ Expr *pValue, /* The VALUE part of the constraint */
131803
+ Expr *pExpr /* Overall expression: COLUMN=VALUE or VALUE=COLUMN */
131075131804
){
131076131805
int i;
131077131806
assert( pColumn->op==TK_COLUMN );
131807
+ assert( sqlite3ExprIsConstant(pValue) );
131808
+
131809
+ if( !ExprHasProperty(pValue, EP_FixedCol) && sqlite3ExprAffinity(pValue)!=0 ){
131810
+ return;
131811
+ }
131812
+ if( !sqlite3IsBinary(sqlite3ExprCompareCollSeq(pConst->pParse,pExpr)) ){
131813
+ return;
131814
+ }
131078131815
131079131816
/* 2018-10-25 ticket [cf5ed20f]
131080131817
** Make sure the same pColumn is not inserted more than once */
131081131818
for(i=0; i<pConst->nConst; i++){
131082
- const Expr *pExpr = pConst->apExpr[i*2];
131083
- assert( pExpr->op==TK_COLUMN );
131084
- if( pExpr->iTable==pColumn->iTable
131085
- && pExpr->iColumn==pColumn->iColumn
131819
+ const Expr *pE2 = pConst->apExpr[i*2];
131820
+ assert( pE2->op==TK_COLUMN );
131821
+ if( pE2->iTable==pColumn->iTable
131822
+ && pE2->iColumn==pColumn->iColumn
131086131823
){
131087131824
return; /* Already present. Return without doing anything. */
131088131825
}
131089131826
}
131090131827
@@ -131092,11 +131829,13 @@
131092131829
pConst->apExpr = sqlite3DbReallocOrFree(pConst->pParse->db, pConst->apExpr,
131093131830
pConst->nConst*2*sizeof(Expr*));
131094131831
if( pConst->apExpr==0 ){
131095131832
pConst->nConst = 0;
131096131833
}else{
131097
- if( ExprHasProperty(pValue, EP_FixedCol) ) pValue = pValue->pLeft;
131834
+ if( ExprHasProperty(pValue, EP_FixedCol) ){
131835
+ pValue = pValue->pLeft;
131836
+ }
131098131837
pConst->apExpr[pConst->nConst*2-2] = pColumn;
131099131838
pConst->apExpr[pConst->nConst*2-1] = pValue;
131100131839
}
131101131840
}
131102131841
@@ -131118,23 +131857,15 @@
131118131857
if( pExpr->op!=TK_EQ ) return;
131119131858
pRight = pExpr->pRight;
131120131859
pLeft = pExpr->pLeft;
131121131860
assert( pRight!=0 );
131122131861
assert( pLeft!=0 );
131123
- if( pRight->op==TK_COLUMN
131124
- && !ExprHasProperty(pRight, EP_FixedCol)
131125
- && sqlite3ExprIsConstant(pLeft)
131126
- && sqlite3IsBinary(sqlite3ExprCompareCollSeq(pConst->pParse,pExpr))
131127
- ){
131128
- constInsert(pConst, pRight, pLeft);
131129
- }else
131130
- if( pLeft->op==TK_COLUMN
131131
- && !ExprHasProperty(pLeft, EP_FixedCol)
131132
- && sqlite3ExprIsConstant(pRight)
131133
- && sqlite3IsBinary(sqlite3ExprCompareCollSeq(pConst->pParse,pExpr))
131134
- ){
131135
- constInsert(pConst, pLeft, pRight);
131862
+ if( pRight->op==TK_COLUMN && sqlite3ExprIsConstant(pLeft) ){
131863
+ constInsert(pConst,pRight,pLeft,pExpr);
131864
+ }
131865
+ if( pLeft->op==TK_COLUMN && sqlite3ExprIsConstant(pRight) ){
131866
+ constInsert(pConst,pLeft,pRight,pExpr);
131136131867
}
131137131868
}
131138131869
131139131870
/*
131140131871
** This is a Walker expression callback. pExpr is a candidate expression
@@ -131166,14 +131897,13 @@
131166131897
131167131898
/*
131168131899
** The WHERE-clause constant propagation optimization.
131169131900
**
131170131901
** If the WHERE clause contains terms of the form COLUMN=CONSTANT or
131171
-** CONSTANT=COLUMN that must be tree (in other words, if the terms top-level
131172
-** AND-connected terms that are not part of a ON clause from a LEFT JOIN)
131173
-** then throughout the query replace all other occurrences of COLUMN
131174
-** with CONSTANT within the WHERE clause.
131902
+** CONSTANT=COLUMN that are top-level AND-connected terms that are not
131903
+** part of a ON clause from a LEFT JOIN, then throughout the query
131904
+** replace all other occurrences of COLUMN with CONSTANT.
131175131905
**
131176131906
** For example, the query:
131177131907
**
131178131908
** SELECT * FROM t1, t2, t3 WHERE t1.a=39 AND t2.b=t1.a AND t3.c=t2.b
131179131909
**
@@ -131882,11 +132612,19 @@
131882132612
u8 eCodeOrig = pWalker->eCode;
131883132613
if( sqlite3ViewGetColumnNames(pParse, pTab) ) return WRC_Abort;
131884132614
assert( pFrom->pSelect==0 );
131885132615
if( pTab->pSelect && (db->flags & SQLITE_EnableView)==0 ){
131886132616
sqlite3ErrorMsg(pParse, "access to view \"%s\" prohibited",
131887
- pTab->zName);
132617
+ pTab->zName);
132618
+ }
132619
+ if( IsVirtual(pTab)
132620
+ && pFrom->fg.fromDDL
132621
+ && ALWAYS(pTab->pVTable!=0)
132622
+ && pTab->pVTable->eVtabRisk > ((db->flags & SQLITE_TrustedSchema)!=0)
132623
+ ){
132624
+ sqlite3ErrorMsg(pParse, "unsafe use of virtual table \"%s\"",
132625
+ pTab->zName);
131888132626
}
131889132627
pFrom->pSelect = sqlite3SelectDup(db, pTab->pSelect, 0);
131890132628
nCol = pTab->nCol;
131891132629
pTab->nCol = -1;
131892132630
pWalker->eCode = 1; /* Turn on Select.selId renumbering */
@@ -131903,11 +132641,11 @@
131903132641
}
131904132642
}
131905132643
131906132644
/* Process NATURAL keywords, and ON and USING clauses of joins.
131907132645
*/
131908
- if( db->mallocFailed || sqliteProcessJoin(pParse, p) ){
132646
+ if( pParse->nErr || db->mallocFailed || sqliteProcessJoin(pParse, p) ){
131909132647
return WRC_Abort;
131910132648
}
131911132649
131912132650
/* For every "*" that occurs in the column list, insert the names of
131913132651
** all columns in all tables. And for every TABLE.* insert the names
@@ -131950,14 +132688,13 @@
131950132688
){
131951132689
/* This particular expression does not need to be expanded.
131952132690
*/
131953132691
pNew = sqlite3ExprListAppend(pParse, pNew, a[k].pExpr);
131954132692
if( pNew ){
131955
- pNew->a[pNew->nExpr-1].zName = a[k].zName;
131956
- pNew->a[pNew->nExpr-1].zSpan = a[k].zSpan;
131957
- a[k].zName = 0;
131958
- a[k].zSpan = 0;
132693
+ pNew->a[pNew->nExpr-1].zEName = a[k].zEName;
132694
+ pNew->a[pNew->nExpr-1].eEName = a[k].eEName;
132695
+ a[k].zEName = 0;
131959132696
}
131960132697
a[k].pExpr = 0;
131961132698
}else{
131962132699
/* This expression is a "*" or a "TABLE.*" and needs to be
131963132700
** expanded. */
@@ -131992,11 +132729,11 @@
131992132729
char *zToFree; /* Malloced string that needs to be freed */
131993132730
Token sColname; /* Computed column name as a token */
131994132731
131995132732
assert( zName );
131996132733
if( zTName && pSub
131997
- && sqlite3MatchSpanName(pSub->pEList->a[j].zSpan, 0, zTName, 0)==0
132734
+ && sqlite3MatchEName(&pSub->pEList->a[j], 0, zTName, 0)==0
131998132735
){
131999132736
continue;
132000132737
}
132001132738
132002132739
/* If a column is marked as 'hidden', omit it from the expanded
@@ -132010,11 +132747,11 @@
132010132747
}
132011132748
tableSeen = 1;
132012132749
132013132750
if( i>0 && zTName==0 ){
132014132751
if( (pFrom->fg.jointype & JT_NATURAL)!=0
132015
- && tableAndColumnIndex(pTabList, i, zName, 0, 0)
132752
+ && tableAndColumnIndex(pTabList, i, zName, 0, 0, 1)
132016132753
){
132017132754
/* In a NATURAL join, omit the join columns from the
132018132755
** table to the right of the join */
132019132756
continue;
132020132757
}
@@ -132045,19 +132782,20 @@
132045132782
pNew = sqlite3ExprListAppend(pParse, pNew, pExpr);
132046132783
sqlite3TokenInit(&sColname, zColname);
132047132784
sqlite3ExprListSetName(pParse, pNew, &sColname, 0);
132048132785
if( pNew && (p->selFlags & SF_NestedFrom)!=0 ){
132049132786
struct ExprList_item *pX = &pNew->a[pNew->nExpr-1];
132787
+ sqlite3DbFree(db, pX->zEName);
132050132788
if( pSub ){
132051
- pX->zSpan = sqlite3DbStrDup(db, pSub->pEList->a[j].zSpan);
132052
- testcase( pX->zSpan==0 );
132789
+ pX->zEName = sqlite3DbStrDup(db, pSub->pEList->a[j].zEName);
132790
+ testcase( pX->zEName==0 );
132053132791
}else{
132054
- pX->zSpan = sqlite3MPrintf(db, "%s.%s.%s",
132792
+ pX->zEName = sqlite3MPrintf(db, "%s.%s.%s",
132055132793
zSchemaName, zTabName, zColname);
132056
- testcase( pX->zSpan==0 );
132794
+ testcase( pX->zEName==0 );
132057132795
}
132058
- pX->bSpanIsTab = 1;
132796
+ pX->eEName = ENAME_TAB;
132059132797
}
132060132798
sqlite3DbFree(db, zToFree);
132061132799
}
132062132800
}
132063132801
if( !tableSeen ){
@@ -133022,10 +133760,11 @@
133022133760
&& sqlite3ExprListCompare(sSort.pOrderBy, pEList, -1)==0
133023133761
&& p->pWin==0
133024133762
){
133025133763
p->selFlags &= ~SF_Distinct;
133026133764
pGroupBy = p->pGroupBy = sqlite3ExprListDup(db, pEList, 0);
133765
+ p->selFlags |= SF_Aggregate;
133027133766
/* Notice that even thought SF_Distinct has been cleared from p->selFlags,
133028133767
** the sDistinct.isTnct is still set. Hence, isTnct represents the
133029133768
** original setting of the SF_Distinct flag, not the current setting */
133030133769
assert( sDistinct.isTnct );
133031133770
@@ -133096,11 +133835,11 @@
133096133835
u16 wctrlFlags = (sDistinct.isTnct ? WHERE_WANT_DISTINCT : 0)
133097133836
| (p->selFlags & SF_FixedLimit);
133098133837
#ifndef SQLITE_OMIT_WINDOWFUNC
133099133838
Window *pWin = p->pWin; /* Master window object (or NULL) */
133100133839
if( pWin ){
133101
- sqlite3WindowCodeInit(pParse, pWin);
133840
+ sqlite3WindowCodeInit(pParse, p);
133102133841
}
133103133842
#endif
133104133843
assert( WHERE_USE_LIMIT==SF_FixedLimit );
133105133844
133106133845
@@ -134568,11 +135307,11 @@
134568135307
*/
134569135308
static int checkColumnOverlap(IdList *pIdList, ExprList *pEList){
134570135309
int e;
134571135310
if( pIdList==0 || NEVER(pEList==0) ) return 1;
134572135311
for(e=0; e<pEList->nExpr; e++){
134573
- if( sqlite3IdListIndex(pIdList, pEList->a[e].zName)>=0 ) return 1;
135312
+ if( sqlite3IdListIndex(pIdList, pEList->a[e].zEName)>=0 ) return 1;
134574135313
}
134575135314
return 0;
134576135315
}
134577135316
134578135317
/*
@@ -135272,10 +136011,11 @@
135272136011
int aiCurOnePass[2]; /* The write cursors opened by WHERE_ONEPASS */
135273136012
int addrOpen = 0; /* Address of OP_OpenEphemeral */
135274136013
int iPk = 0; /* First of nPk cells holding PRIMARY KEY value */
135275136014
i16 nPk = 0; /* Number of components of the PRIMARY KEY */
135276136015
int bReplace = 0; /* True if REPLACE conflict resolution might happen */
136016
+ int bFinishSeek = 1; /* The OP_FinishSeek opcode is needed */
135277136017
135278136018
/* Register Allocations */
135279136019
int regRowCount = 0; /* A count of rows changed */
135280136020
int regOldRowid = 0; /* The old rowid */
135281136021
int regNewRowid = 0; /* The new rowid */
@@ -135386,11 +136126,11 @@
135386136126
for(i=0; i<pChanges->nExpr; i++){
135387136127
if( sqlite3ResolveExprNames(&sNC, pChanges->a[i].pExpr) ){
135388136128
goto update_cleanup;
135389136129
}
135390136130
for(j=0; j<pTab->nCol; j++){
135391
- if( sqlite3StrICmp(pTab->aCol[j].zName, pChanges->a[i].zName)==0 ){
136131
+ if( sqlite3StrICmp(pTab->aCol[j].zName, pChanges->a[i].zEName)==0 ){
135392136132
if( j==pTab->iPKey ){
135393136133
chngRowid = 1;
135394136134
pRowidExpr = pChanges->a[i].pExpr;
135395136135
}else if( pPk && (pTab->aCol[j].colFlags & COLFLAG_PRIMKEY)!=0 ){
135396136136
chngPk = 1;
@@ -135408,16 +136148,16 @@
135408136148
aXRef[j] = i;
135409136149
break;
135410136150
}
135411136151
}
135412136152
if( j>=pTab->nCol ){
135413
- if( pPk==0 && sqlite3IsRowid(pChanges->a[i].zName) ){
136153
+ if( pPk==0 && sqlite3IsRowid(pChanges->a[i].zEName) ){
135414136154
j = -1;
135415136155
chngRowid = 1;
135416136156
pRowidExpr = pChanges->a[i].pExpr;
135417136157
}else{
135418
- sqlite3ErrorMsg(pParse, "no such column: %s", pChanges->a[i].zName);
136158
+ sqlite3ErrorMsg(pParse, "no such column: %s", pChanges->a[i].zEName);
135419136159
pParse->checkSchema = 1;
135420136160
goto update_cleanup;
135421136161
}
135422136162
}
135423136163
#ifndef SQLITE_OMIT_AUTHORIZATION
@@ -135605,10 +136345,11 @@
135605136345
** row(s) to be updated.
135606136346
*/
135607136347
pWInfo = 0;
135608136348
eOnePass = ONEPASS_SINGLE;
135609136349
sqlite3ExprIfFalse(pParse, pWhere, labelBreak, SQLITE_JUMPIFNULL);
136350
+ bFinishSeek = 0;
135610136351
}else{
135611136352
/* Begin the database scan.
135612136353
**
135613136354
** Do not consider a single-pass strategy for a multi-row update if
135614136355
** there are any triggers or foreign keys to process, or rows may
@@ -135631,10 +136372,11 @@
135631136372
**
135632136373
** Fall back to ONEPASS_OFF if where.c has selected a ONEPASS_MULTI
135633136374
** strategy that uses an index for which one or more columns are being
135634136375
** updated. */
135635136376
eOnePass = sqlite3WhereOkOnePass(pWInfo, aiCurOnePass);
136377
+ bFinishSeek = sqlite3WhereUsesDeferredSeek(pWInfo);
135636136378
if( eOnePass!=ONEPASS_SINGLE ){
135637136379
sqlite3MultiWrite(pParse);
135638136380
if( eOnePass==ONEPASS_MULTI ){
135639136381
int iCur = aiCurOnePass[1];
135640136382
if( iCur>=0 && iCur!=iDataCur && aToOpen[iCur-iBaseCur] ){
@@ -135794,10 +136536,11 @@
135794136536
** a new.* reference in a trigger program.
135795136537
*/
135796136538
testcase( i==31 );
135797136539
testcase( i==32 );
135798136540
sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, i, k);
136541
+ bFinishSeek = 0;
135799136542
}else{
135800136543
sqlite3VdbeAddOp2(v, OP_Null, 0, k);
135801136544
}
135802136545
}
135803136546
}
@@ -135880,10 +136623,19 @@
135880136623
sqlite3FkCheck(pParse, pTab, regOldRowid, 0, aXRef, chngKey);
135881136624
}
135882136625
135883136626
/* Delete the index entries associated with the current record. */
135884136627
sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur, aRegIdx, -1);
136628
+
136629
+ /* We must run the OP_FinishSeek opcode to resolve a prior
136630
+ ** OP_DeferredSeek if there is any possibility that there have been
136631
+ ** no OP_Column opcodes since the OP_DeferredSeek was issued. But
136632
+ ** we want to avoid the OP_FinishSeek if possible, as running it
136633
+ ** costs CPU cycles. */
136634
+ if( bFinishSeek ){
136635
+ sqlite3VdbeAddOp1(v, OP_FinishSeek, iDataCur);
136636
+ }
135885136637
135886136638
/* If changing the rowid value, or if there are foreign key constraints
135887136639
** to process, delete the old record. Otherwise, add a noop OP_Delete
135888136640
** to invoke the pre-update hook.
135889136641
**
@@ -136378,10 +137130,11 @@
136378137130
sqlite3VdbeVerifyAbortable(v, OE_Abort);
136379137131
i = sqlite3VdbeAddOp4Int(v, OP_Found, iDataCur, 0, iPk, nPk);
136380137132
VdbeCoverage(v);
136381137133
sqlite3VdbeAddOp4(v, OP_Halt, SQLITE_CORRUPT, OE_Abort, 0,
136382137134
"corrupt database", P4_STATIC);
137135
+ sqlite3MayAbort(pParse);
136383137136
sqlite3VdbeJumpHere(v, i);
136384137137
}
136385137138
}
136386137139
/* pUpsert does not own pUpsertSrc - the outer INSERT statement does. So
136387137140
** we have to make a copy before passing it down into sqlite3Update() */
@@ -137408,10 +138161,11 @@
137408138161
sqlite3DbFree(db, zModuleName);
137409138162
return SQLITE_NOMEM_BKPT;
137410138163
}
137411138164
pVTable->db = db;
137412138165
pVTable->pMod = pMod;
138166
+ pVTable->eVtabRisk = SQLITE_VTABRISK_Normal;
137413138167
137414138168
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
137415138169
pTab->azModuleArg[1] = db->aDb[iDb].zDbSName;
137416138170
137417138171
/* Invoke the virtual table constructor */
@@ -138097,32 +138851,42 @@
138097138851
** of the virtual table being implemented.
138098138852
*/
138099138853
SQLITE_API int sqlite3_vtab_config(sqlite3 *db, int op, ...){
138100138854
va_list ap;
138101138855
int rc = SQLITE_OK;
138856
+ VtabCtx *p;
138102138857
138103138858
#ifdef SQLITE_ENABLE_API_ARMOR
138104138859
if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
138105138860
#endif
138106138861
sqlite3_mutex_enter(db->mutex);
138107
- va_start(ap, op);
138108
- switch( op ){
138109
- case SQLITE_VTAB_CONSTRAINT_SUPPORT: {
138110
- VtabCtx *p = db->pVtabCtx;
138111
- if( !p ){
138112
- rc = SQLITE_MISUSE_BKPT;
138113
- }else{
138114
- assert( p->pTab==0 || IsVirtual(p->pTab) );
138862
+ p = db->pVtabCtx;
138863
+ if( !p ){
138864
+ rc = SQLITE_MISUSE_BKPT;
138865
+ }else{
138866
+ assert( p->pTab==0 || IsVirtual(p->pTab) );
138867
+ va_start(ap, op);
138868
+ switch( op ){
138869
+ case SQLITE_VTAB_CONSTRAINT_SUPPORT: {
138115138870
p->pVTable->bConstraint = (u8)va_arg(ap, int);
138116
- }
138117
- break;
138118
- }
138119
- default:
138120
- rc = SQLITE_MISUSE_BKPT;
138121
- break;
138122
- }
138123
- va_end(ap);
138871
+ break;
138872
+ }
138873
+ case SQLITE_VTAB_INNOCUOUS: {
138874
+ p->pVTable->eVtabRisk = SQLITE_VTABRISK_Low;
138875
+ break;
138876
+ }
138877
+ case SQLITE_VTAB_DIRECTONLY: {
138878
+ p->pVTable->eVtabRisk = SQLITE_VTABRISK_High;
138879
+ break;
138880
+ }
138881
+ default: {
138882
+ rc = SQLITE_MISUSE_BKPT;
138883
+ break;
138884
+ }
138885
+ }
138886
+ va_end(ap);
138887
+ }
138124138888
138125138889
if( rc!=SQLITE_OK ) sqlite3Error(db, rc);
138126138890
sqlite3_mutex_leave(db->mutex);
138127138891
return rc;
138128138892
}
@@ -138586,10 +139350,24 @@
138586139350
#endif
138587139351
#ifndef SQLITE_QUERY_PLANNER_LIMIT_INCR
138588139352
# define SQLITE_QUERY_PLANNER_LIMIT_INCR 1000
138589139353
#endif
138590139354
139355
+/*
139356
+** Each instance of this object records a change to a single node
139357
+** in an expression tree to cause that node to point to a column
139358
+** of an index rather than an expression or a virtual column. All
139359
+** such transformations need to be undone at the end of WHERE clause
139360
+** processing.
139361
+*/
139362
+typedef struct WhereExprMod WhereExprMod;
139363
+struct WhereExprMod {
139364
+ WhereExprMod *pNext; /* Next translation on a list of them all */
139365
+ Expr *pExpr; /* The Expr node that was transformed */
139366
+ Expr orig; /* Original value of the Expr node */
139367
+};
139368
+
138591139369
/*
138592139370
** The WHERE clause processing routine has two halves. The
138593139371
** first part does the start of the WHERE loop and the second
138594139372
** half does the tail of the WHERE loop. An instance of
138595139373
** this structure is returned by the first half and passed
@@ -138602,27 +139380,29 @@
138602139380
Parse *pParse; /* Parsing and code generating context */
138603139381
SrcList *pTabList; /* List of tables in the join */
138604139382
ExprList *pOrderBy; /* The ORDER BY clause or NULL */
138605139383
ExprList *pResultSet; /* Result set of the query */
138606139384
Expr *pWhere; /* The complete WHERE clause */
138607
- LogEst iLimit; /* LIMIT if wctrlFlags has WHERE_USE_LIMIT */
138608139385
int aiCurOnePass[2]; /* OP_OpenWrite cursors for the ONEPASS opt */
138609139386
int iContinue; /* Jump here to continue with next record */
138610139387
int iBreak; /* Jump here to break out of the loop */
138611139388
int savedNQueryLoop; /* pParse->nQueryLoop outside the WHERE loop */
138612139389
u16 wctrlFlags; /* Flags originally passed to sqlite3WhereBegin() */
139390
+ LogEst iLimit; /* LIMIT if wctrlFlags has WHERE_USE_LIMIT */
138613139391
u8 nLevel; /* Number of nested loop */
138614139392
i8 nOBSat; /* Number of ORDER BY terms satisfied by indices */
138615
- u8 sorted; /* True if really sorted (not just grouped) */
138616139393
u8 eOnePass; /* ONEPASS_OFF, or _SINGLE, or _MULTI */
138617
- u8 untestedTerms; /* Not all WHERE terms resolved by outer loop */
138618139394
u8 eDistinct; /* One of the WHERE_DISTINCT_* values */
138619
- u8 bOrderedInnerLoop; /* True if only the inner-most loop is ordered */
139395
+ unsigned bDeferredSeek :1; /* Uses OP_DeferredSeek */
139396
+ unsigned untestedTerms :1; /* Not all WHERE terms resolved by outer loop */
139397
+ unsigned bOrderedInnerLoop:1;/* True if only the inner-most loop is ordered */
139398
+ unsigned sorted :1; /* True if really sorted (not just grouped) */
139399
+ LogEst nRowOut; /* Estimated number of output rows */
138620139400
int iTop; /* The very beginning of the WHERE loop */
138621139401
WhereLoop *pLoops; /* List of all WhereLoop objects */
139402
+ WhereExprMod *pExprMods; /* Expression modifications */
138622139403
Bitmask revMask; /* Mask of ORDER BY terms that need reversing */
138623
- LogEst nRowOut; /* Estimated number of output rows */
138624139404
WhereClause sWC; /* Decomposition of the WHERE clause */
138625139405
WhereMaskSet sMaskSet; /* Map cursor numbers to bitmasks */
138626139406
WhereLevel a[1]; /* Information about each nest loop in WHERE */
138627139407
};
138628139408
@@ -138632,10 +139412,12 @@
138632139412
** where.c:
138633139413
*/
138634139414
SQLITE_PRIVATE Bitmask sqlite3WhereGetMask(WhereMaskSet*,int);
138635139415
#ifdef WHERETRACE_ENABLED
138636139416
SQLITE_PRIVATE void sqlite3WhereClausePrint(WhereClause *pWC);
139417
+SQLITE_PRIVATE void sqlite3WhereTermPrint(WhereTerm *pTerm, int iTerm);
139418
+SQLITE_PRIVATE void sqlite3WhereLoopPrint(WhereLoop *p, WhereClause *pWC);
138637139419
#endif
138638139420
SQLITE_PRIVATE WhereTerm *sqlite3WhereFindTerm(
138639139421
WhereClause *pWC, /* The WHERE clause to be searched */
138640139422
int iCur, /* Cursor number of LHS */
138641139423
int iColumn, /* Column number of LHS */
@@ -139321,11 +140103,11 @@
139321140103
}
139322140104
sqlite3VdbeAddOp1(v, OP_IsNull, iOut); VdbeCoverage(v);
139323140105
if( i==iEq ){
139324140106
pIn->iCur = iTab;
139325140107
pIn->eEndLoopOp = bRev ? OP_Prev : OP_Next;
139326
- if( iEq>0 && (pLoop->wsFlags & WHERE_VIRTUALTABLE)==0 ){
140108
+ if( iEq>0 ){
139327140109
pIn->iBase = iReg - i;
139328140110
pIn->nPrefix = i;
139329140111
pLoop->wsFlags |= WHERE_IN_EARLYOUT;
139330140112
}else{
139331140113
pIn->nPrefix = 0;
@@ -139773,10 +140555,11 @@
139773140555
Vdbe *v = pParse->pVdbe; /* Vdbe to generate code within */
139774140556
139775140557
assert( iIdxCur>0 );
139776140558
assert( pIdx->aiColumn[pIdx->nColumn-1]==-1 );
139777140559
140560
+ pWInfo->bDeferredSeek = 1;
139778140561
sqlite3VdbeAddOp3(v, OP_DeferredSeek, iIdxCur, 0, iCur);
139779140562
if( (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)
139780140563
&& DbMaskAllZero(sqlite3ParseToplevel(pParse)->writeMask)
139781140564
){
139782140565
int i;
@@ -139840,11 +140623,26 @@
139840140623
Expr *pIdxExpr; /* The index expression */
139841140624
int iTabCur; /* The cursor of the corresponding table */
139842140625
int iIdxCur; /* The cursor for the index */
139843140626
int iIdxCol; /* The column for the index */
139844140627
int iTabCol; /* The column for the table */
140628
+ WhereInfo *pWInfo; /* Complete WHERE clause information */
140629
+ sqlite3 *db; /* Database connection (for malloc()) */
139845140630
} IdxExprTrans;
140631
+
140632
+/*
140633
+** Preserve pExpr on the WhereETrans list of the WhereInfo.
140634
+*/
140635
+static void preserveExpr(IdxExprTrans *pTrans, Expr *pExpr){
140636
+ WhereExprMod *pNew;
140637
+ pNew = sqlite3DbMallocRaw(pTrans->db, sizeof(*pNew));
140638
+ if( pNew==0 ) return;
140639
+ pNew->pNext = pTrans->pWInfo->pExprMods;
140640
+ pTrans->pWInfo->pExprMods = pNew;
140641
+ pNew->pExpr = pExpr;
140642
+ memcpy(&pNew->orig, pExpr, sizeof(*pExpr));
140643
+}
139846140644
139847140645
/* The walker node callback used to transform matching expressions into
139848140646
** a reference to an index column for an index on an expression.
139849140647
**
139850140648
** If pExpr matches, then transform it into a reference to the index column
@@ -139851,10 +140649,11 @@
139851140649
** that contains the value of pExpr.
139852140650
*/
139853140651
static int whereIndexExprTransNode(Walker *p, Expr *pExpr){
139854140652
IdxExprTrans *pX = p->u.pIdxTrans;
139855140653
if( sqlite3ExprCompare(0, pExpr, pX->pIdxExpr, pX->iTabCur)==0 ){
140654
+ preserveExpr(pX, pExpr);
139856140655
pExpr->affExpr = sqlite3ExprAffinity(pExpr);
139857140656
pExpr->op = TK_COLUMN;
139858140657
pExpr->iTable = pX->iIdxCur;
139859140658
pExpr->iColumn = pX->iIdxCol;
139860140659
pExpr->y.pTab = 0;
@@ -139874,10 +140673,11 @@
139874140673
static int whereIndexExprTransColumn(Walker *p, Expr *pExpr){
139875140674
if( pExpr->op==TK_COLUMN ){
139876140675
IdxExprTrans *pX = p->u.pIdxTrans;
139877140676
if( pExpr->iTable==pX->iTabCur && pExpr->iColumn==pX->iTabCol ){
139878140677
assert( pExpr->y.pTab!=0 );
140678
+ preserveExpr(pX, pExpr);
139879140679
pExpr->affExpr = sqlite3TableColumnAffinity(pExpr->y.pTab,pExpr->iColumn);
139880140680
pExpr->iTable = pX->iIdxCur;
139881140681
pExpr->iColumn = pX->iIdxCol;
139882140682
pExpr->y.pTab = 0;
139883140683
}
@@ -139915,10 +140715,12 @@
139915140715
pTab = pIdx->pTable;
139916140716
memset(&w, 0, sizeof(w));
139917140717
w.u.pIdxTrans = &x;
139918140718
x.iTabCur = iTabCur;
139919140719
x.iIdxCur = iIdxCur;
140720
+ x.pWInfo = pWInfo;
140721
+ x.db = pWInfo->pParse->db;
139920140722
for(iIdxCol=0; iIdxCol<pIdx->nColumn; iIdxCol++){
139921140723
i16 iRef = pIdx->aiColumn[iIdxCol];
139922140724
if( iRef==XN_EXPR ){
139923140725
assert( aColExpr->a[iIdxCol].pExpr!=0 );
139924140726
x.pIdxExpr = aColExpr->a[iIdxCol].pExpr;
@@ -140012,10 +140814,25 @@
140012140814
pTabItem = &pWInfo->pTabList->a[pLevel->iFrom];
140013140815
iCur = pTabItem->iCursor;
140014140816
pLevel->notReady = notReady & ~sqlite3WhereGetMask(&pWInfo->sMaskSet, iCur);
140015140817
bRev = (pWInfo->revMask>>iLevel)&1;
140016140818
VdbeModuleComment((v, "Begin WHERE-loop%d: %s",iLevel,pTabItem->pTab->zName));
140819
+#if WHERETRACE_ENABLED /* 0x20800 */
140820
+ if( sqlite3WhereTrace & 0x800 ){
140821
+ sqlite3DebugPrintf("Coding level %d of %d: notReady=%llx iFrom=%d\n",
140822
+ iLevel, pWInfo->nLevel, (u64)notReady, pLevel->iFrom);
140823
+ sqlite3WhereLoopPrint(pLoop, pWC);
140824
+ }
140825
+ if( sqlite3WhereTrace & 0x20000 ){
140826
+ if( iLevel==0 ){
140827
+ sqlite3DebugPrintf("WHERE clause being coded:\n");
140828
+ sqlite3TreeViewExpr(0, pWInfo->pWhere, 0);
140829
+ }
140830
+ sqlite3DebugPrintf("All WHERE-clause terms before coding:\n");
140831
+ sqlite3WhereClausePrint(pWC);
140832
+ }
140833
+#endif
140017140834
140018140835
/* Create labels for the "break" and "continue" instructions
140019140836
** for the current loop. Jump to addrBrk to break out of a loop.
140020140837
** Jump to cont to go immediately to the next iteration of the
140021140838
** loop.
@@ -140398,11 +141215,11 @@
140398141215
if( (pLoop->wsFlags & (WHERE_TOP_LIMIT|WHERE_BTM_LIMIT))==0
140399141216
&& (pLoop->wsFlags & WHERE_BIGNULL_SORT)!=0
140400141217
){
140401141218
assert( bSeekPastNull==0 && nExtraReg==0 && nBtm==0 && nTop==0 );
140402141219
assert( pRangeEnd==0 && pRangeStart==0 );
140403
- assert( pLoop->nSkip==0 );
141220
+ testcase( pLoop->nSkip>0 );
140404141221
nExtraReg = 1;
140405141222
bSeekPastNull = 1;
140406141223
pLevel->regBignull = regBignull = ++pParse->nMem;
140407141224
pLevel->addrBignull = sqlite3VdbeMakeLabel(pParse);
140408141225
}
@@ -141067,10 +141884,14 @@
141067141884
#ifdef WHERETRACE_ENABLED /* 0xffff */
141068141885
if( sqlite3WhereTrace ){
141069141886
VdbeNoopComment((v, "WhereTerm[%d] (%p) priority=%d",
141070141887
pWC->nTerm-j, pTerm, iLoop));
141071141888
}
141889
+ if( sqlite3WhereTrace & 0x800 ){
141890
+ sqlite3DebugPrintf("Coding auxiliary constraint:\n");
141891
+ sqlite3WhereTermPrint(pTerm, pWC->nTerm-j);
141892
+ }
141072141893
#endif
141073141894
sqlite3ExprIfFalse(pParse, pE, addrCont, SQLITE_JUMPIFNULL);
141074141895
if( skipLikeAddr ) sqlite3VdbeJumpHere(v, skipLikeAddr);
141075141896
pTerm->wtFlags |= TERM_CODED;
141076141897
}
@@ -141090,12 +141911,18 @@
141090141911
WhereTerm *pAlt;
141091141912
if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue;
141092141913
if( (pTerm->eOperator & (WO_EQ|WO_IS))==0 ) continue;
141093141914
if( (pTerm->eOperator & WO_EQUIV)==0 ) continue;
141094141915
if( pTerm->leftCursor!=iCur ) continue;
141095
- if( pLevel->iLeftJoin ) continue;
141916
+ if( pTabItem->fg.jointype & JT_LEFT ) continue;
141096141917
pE = pTerm->pExpr;
141918
+#ifdef WHERETRACE_ENABLED /* 0x800 */
141919
+ if( sqlite3WhereTrace & 0x800 ){
141920
+ sqlite3DebugPrintf("Coding transitive constraint:\n");
141921
+ sqlite3WhereTermPrint(pTerm, pWC->nTerm-j);
141922
+ }
141923
+#endif
141097141924
assert( !ExprHasProperty(pE, EP_FromJoin) );
141098141925
assert( (pTerm->prereqRight & pLevel->notReady)!=0 );
141099141926
pAlt = sqlite3WhereFindTerm(pWC, iCur, pTerm->u.leftColumn, notReady,
141100141927
WO_EQ|WO_IN|WO_IS, 0);
141101141928
if( pAlt==0 ) continue;
@@ -141134,10 +141961,21 @@
141134141961
sqlite3ExprIfFalse(pParse, pTerm->pExpr, addrCont, SQLITE_JUMPIFNULL);
141135141962
pTerm->wtFlags |= TERM_CODED;
141136141963
}
141137141964
}
141138141965
141966
+#if WHERETRACE_ENABLED /* 0x20800 */
141967
+ if( sqlite3WhereTrace & 0x20000 ){
141968
+ sqlite3DebugPrintf("All WHERE-clause terms after coding level %d:\n",
141969
+ iLevel);
141970
+ sqlite3WhereClausePrint(pWC);
141971
+ }
141972
+ if( sqlite3WhereTrace & 0x800 ){
141973
+ sqlite3DebugPrintf("End Coding level %d: notReady=%llx\n",
141974
+ iLevel, (u64)pLevel->notReady);
141975
+ }
141976
+#endif
141139141977
return pLevel->notReady;
141140141978
}
141141141979
141142141980
/************** End of wherecode.c *******************************************/
141143141981
/************** Begin file whereexpr.c ***************************************/
@@ -142872,11 +143710,11 @@
142872143710
return pWInfo->iBreak;
142873143711
}
142874143712
142875143713
/*
142876143714
** Return ONEPASS_OFF (0) if an UPDATE or DELETE statement is unable to
142877
-** operate directly on the rowis returned by a WHERE clause. Return
143715
+** operate directly on the rowids returned by a WHERE clause. Return
142878143716
** ONEPASS_SINGLE (1) if the statement can operation directly because only
142879143717
** a single row is to be changed. Return ONEPASS_MULTI (2) if the one-pass
142880143718
** optimization can be used on multiple
142881143719
**
142882143720
** If the ONEPASS optimization is used (if this routine returns true)
@@ -142898,10 +143736,18 @@
142898143736
aiCur[0], aiCur[1]);
142899143737
}
142900143738
#endif
142901143739
return pWInfo->eOnePass;
142902143740
}
143741
+
143742
+/*
143743
+** Return TRUE if the WHERE loop uses the OP_DeferredSeek opcode to move
143744
+** the data cursor to the row selected by the index cursor.
143745
+*/
143746
+SQLITE_PRIVATE int sqlite3WhereUsesDeferredSeek(WhereInfo *pWInfo){
143747
+ return pWInfo->bDeferredSeek;
143748
+}
142903143749
142904143750
/*
142905143751
** Move the content of pSrc into pDest
142906143752
*/
142907143753
static void whereOrMove(WhereOrSet *pDest, WhereOrSet *pSrc){
@@ -143357,11 +144203,11 @@
143357144203
** structure. Used for testing and debugging only. If neither
143358144204
** SQLITE_TEST or SQLITE_DEBUG are defined, then these routines
143359144205
** are no-ops.
143360144206
*/
143361144207
#if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(WHERETRACE_ENABLED)
143362
-static void TRACE_IDX_INPUTS(sqlite3_index_info *p){
144208
+static void whereTraceIndexInfoInputs(sqlite3_index_info *p){
143363144209
int i;
143364144210
if( !sqlite3WhereTrace ) return;
143365144211
for(i=0; i<p->nConstraint; i++){
143366144212
sqlite3DebugPrintf(" constraint[%d]: col=%d termid=%d op=%d usabled=%d\n",
143367144213
i,
@@ -143375,11 +144221,11 @@
143375144221
i,
143376144222
p->aOrderBy[i].iColumn,
143377144223
p->aOrderBy[i].desc);
143378144224
}
143379144225
}
143380
-static void TRACE_IDX_OUTPUTS(sqlite3_index_info *p){
144226
+static void whereTraceIndexInfoOutputs(sqlite3_index_info *p){
143381144227
int i;
143382144228
if( !sqlite3WhereTrace ) return;
143383144229
for(i=0; i<p->nConstraint; i++){
143384144230
sqlite3DebugPrintf(" usage[%d]: argvIdx=%d omit=%d\n",
143385144231
i,
@@ -143391,12 +144237,12 @@
143391144237
sqlite3DebugPrintf(" orderByConsumed=%d\n", p->orderByConsumed);
143392144238
sqlite3DebugPrintf(" estimatedCost=%g\n", p->estimatedCost);
143393144239
sqlite3DebugPrintf(" estimatedRows=%lld\n", p->estimatedRows);
143394144240
}
143395144241
#else
143396
-#define TRACE_IDX_INPUTS(A)
143397
-#define TRACE_IDX_OUTPUTS(A)
144242
+#define whereTraceIndexInfoInputs(A)
144243
+#define whereTraceIndexInfoOutputs(A)
143398144244
#endif
143399144245
143400144246
#ifndef SQLITE_OMIT_AUTOMATIC_INDEX
143401144247
/*
143402144248
** Return TRUE if the WHERE clause term pTerm is of a form where it
@@ -143622,12 +144468,12 @@
143622144468
pTabItem->regResult, pLevel->iIdxCur);
143623144469
sqlite3VdbeGoto(v, addrTop);
143624144470
pTabItem->fg.viaCoroutine = 0;
143625144471
}else{
143626144472
sqlite3VdbeAddOp2(v, OP_Next, pLevel->iTabCur, addrTop+1); VdbeCoverage(v);
144473
+ sqlite3VdbeChangeP5(v, SQLITE_STMTSTATUS_AUTOINDEX);
143627144474
}
143628
- sqlite3VdbeChangeP5(v, SQLITE_STMTSTATUS_AUTOINDEX);
143629144475
sqlite3VdbeJumpHere(v, addrTop);
143630144476
sqlite3ReleaseTempReg(pParse, regRecord);
143631144477
143632144478
/* Jump here when skipping the initialization */
143633144479
sqlite3VdbeJumpHere(v, addrInit);
@@ -143702,27 +144548,18 @@
143702144548
+ sizeof(*pIdxOrderBy)*nOrderBy + sizeof(*pHidden) );
143703144549
if( pIdxInfo==0 ){
143704144550
sqlite3ErrorMsg(pParse, "out of memory");
143705144551
return 0;
143706144552
}
143707
-
143708
- /* Initialize the structure. The sqlite3_index_info structure contains
143709
- ** many fields that are declared "const" to prevent xBestIndex from
143710
- ** changing them. We have to do some funky casting in order to
143711
- ** initialize those fields.
143712
- */
143713144553
pHidden = (struct HiddenIndexInfo*)&pIdxInfo[1];
143714144554
pIdxCons = (struct sqlite3_index_constraint*)&pHidden[1];
143715144555
pIdxOrderBy = (struct sqlite3_index_orderby*)&pIdxCons[nTerm];
143716144556
pUsage = (struct sqlite3_index_constraint_usage*)&pIdxOrderBy[nOrderBy];
143717
- *(int*)&pIdxInfo->nConstraint = nTerm;
143718
- *(int*)&pIdxInfo->nOrderBy = nOrderBy;
143719
- *(struct sqlite3_index_constraint**)&pIdxInfo->aConstraint = pIdxCons;
143720
- *(struct sqlite3_index_orderby**)&pIdxInfo->aOrderBy = pIdxOrderBy;
143721
- *(struct sqlite3_index_constraint_usage**)&pIdxInfo->aConstraintUsage =
143722
- pUsage;
143723
-
144557
+ pIdxInfo->nOrderBy = nOrderBy;
144558
+ pIdxInfo->aConstraint = pIdxCons;
144559
+ pIdxInfo->aOrderBy = pIdxOrderBy;
144560
+ pIdxInfo->aConstraintUsage = pUsage;
143724144561
pHidden->pWC = pWC;
143725144562
pHidden->pParse = pParse;
143726144563
for(i=j=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
143727144564
u16 op;
143728144565
if( pTerm->leftCursor != pSrc->iCursor ) continue;
@@ -143778,10 +144615,11 @@
143778144615
}
143779144616
}
143780144617
143781144618
j++;
143782144619
}
144620
+ pIdxInfo->nConstraint = j;
143783144621
for(i=0; i<nOrderBy; i++){
143784144622
Expr *pExpr = pOrderBy->a[i].pExpr;
143785144623
pIdxOrderBy[i].iColumn = pExpr->iColumn;
143786144624
pIdxOrderBy[i].desc = pOrderBy->a[i].sortFlags & KEYINFO_ORDER_DESC;
143787144625
}
@@ -143808,13 +144646,13 @@
143808144646
*/
143809144647
static int vtabBestIndex(Parse *pParse, Table *pTab, sqlite3_index_info *p){
143810144648
sqlite3_vtab *pVtab = sqlite3GetVTable(pParse->db, pTab)->pVtab;
143811144649
int rc;
143812144650
143813
- TRACE_IDX_INPUTS(p);
144651
+ whereTraceIndexInfoInputs(p);
143814144652
rc = pVtab->pModule->xBestIndex(pVtab, p);
143815
- TRACE_IDX_OUTPUTS(p);
144653
+ whereTraceIndexInfoOutputs(p);
143816144654
143817144655
if( rc!=SQLITE_OK && rc!=SQLITE_CONSTRAINT ){
143818144656
if( rc==SQLITE_NOMEM ){
143819144657
sqlite3OomFault(pParse->db);
143820144658
}else if( !pVtab->zErrMsg ){
@@ -144491,20 +145329,21 @@
144491145329
144492145330
#ifdef WHERETRACE_ENABLED
144493145331
/*
144494145332
** Print the content of a WhereTerm object
144495145333
*/
144496
-static void whereTermPrint(WhereTerm *pTerm, int iTerm){
145334
+SQLITE_PRIVATE void sqlite3WhereTermPrint(WhereTerm *pTerm, int iTerm){
144497145335
if( pTerm==0 ){
144498145336
sqlite3DebugPrintf("TERM-%-3d NULL\n", iTerm);
144499145337
}else{
144500
- char zType[4];
145338
+ char zType[8];
144501145339
char zLeft[50];
144502
- memcpy(zType, "...", 4);
145340
+ memcpy(zType, "....", 5);
144503145341
if( pTerm->wtFlags & TERM_VIRTUAL ) zType[0] = 'V';
144504145342
if( pTerm->eOperator & WO_EQUIV ) zType[1] = 'E';
144505145343
if( ExprHasProperty(pTerm->pExpr, EP_FromJoin) ) zType[2] = 'L';
145344
+ if( pTerm->wtFlags & TERM_CODED ) zType[3] = 'C';
144506145345
if( pTerm->eOperator & WO_SINGLE ){
144507145346
sqlite3_snprintf(sizeof(zLeft),zLeft,"left={%d:%d}",
144508145347
pTerm->leftCursor, pTerm->u.leftColumn);
144509145348
}else if( (pTerm->eOperator & WO_OR)!=0 && pTerm->u.pOrInfo!=0 ){
144510145349
sqlite3_snprintf(sizeof(zLeft),zLeft,"indexable=0x%lld",
@@ -144511,13 +145350,18 @@
144511145350
pTerm->u.pOrInfo->indexable);
144512145351
}else{
144513145352
sqlite3_snprintf(sizeof(zLeft),zLeft,"left=%d", pTerm->leftCursor);
144514145353
}
144515145354
sqlite3DebugPrintf(
144516
- "TERM-%-3d %p %s %-12s prob=%-3d op=0x%03x wtFlags=0x%04x",
144517
- iTerm, pTerm, zType, zLeft, pTerm->truthProb,
144518
- pTerm->eOperator, pTerm->wtFlags);
145355
+ "TERM-%-3d %p %s %-12s op=%03x wtFlags=%04x",
145356
+ iTerm, pTerm, zType, zLeft, pTerm->eOperator, pTerm->wtFlags);
145357
+ /* The 0x10000 .wheretrace flag causes extra information to be
145358
+ ** shown about each Term */
145359
+ if( sqlite3WhereTrace & 0x10000 ){
145360
+ sqlite3DebugPrintf(" prob=%-3d prereq=%llx,%llx",
145361
+ pTerm->truthProb, (u64)pTerm->prereqAll, (u64)pTerm->prereqRight);
145362
+ }
144519145363
if( pTerm->iField ){
144520145364
sqlite3DebugPrintf(" iField=%d", pTerm->iField);
144521145365
}
144522145366
if( pTerm->iParent>=0 ){
144523145367
sqlite3DebugPrintf(" iParent=%d", pTerm->iParent);
@@ -144533,20 +145377,20 @@
144533145377
** Show the complete content of a WhereClause
144534145378
*/
144535145379
SQLITE_PRIVATE void sqlite3WhereClausePrint(WhereClause *pWC){
144536145380
int i;
144537145381
for(i=0; i<pWC->nTerm; i++){
144538
- whereTermPrint(&pWC->a[i], i);
145382
+ sqlite3WhereTermPrint(&pWC->a[i], i);
144539145383
}
144540145384
}
144541145385
#endif
144542145386
144543145387
#ifdef WHERETRACE_ENABLED
144544145388
/*
144545145389
** Print a WhereLoop object for debugging purposes
144546145390
*/
144547
-static void whereLoopPrint(WhereLoop *p, WhereClause *pWC){
145391
+SQLITE_PRIVATE void sqlite3WhereLoopPrint(WhereLoop *p, WhereClause *pWC){
144548145392
WhereInfo *pWInfo = pWC->pWInfo;
144549145393
int nb = 1+(pWInfo->pTabList->nSrc+3)/4;
144550145394
struct SrcList_item *pItem = pWInfo->pTabList->a + p->iTab;
144551145395
Table *pTab = pItem->pTab;
144552145396
Bitmask mAll = (((Bitmask)1)<<(nb*4)) - 1;
@@ -144584,11 +145428,11 @@
144584145428
}
144585145429
sqlite3DebugPrintf(" cost %d,%d,%d\n", p->rSetup, p->rRun, p->nOut);
144586145430
if( p->nLTerm && (sqlite3WhereTrace & 0x100)!=0 ){
144587145431
int i;
144588145432
for(i=0; i<p->nLTerm; i++){
144589
- whereTermPrint(p->aLTerm[i], i);
145433
+ sqlite3WhereTermPrint(p->aLTerm[i], i);
144590145434
}
144591145435
}
144592145436
}
144593145437
#endif
144594145438
@@ -144688,10 +145532,11 @@
144688145532
while( pWInfo->pLoops ){
144689145533
WhereLoop *p = pWInfo->pLoops;
144690145534
pWInfo->pLoops = p->pNextLoop;
144691145535
whereLoopDelete(db, p);
144692145536
}
145537
+ assert( pWInfo->pExprMods==0 );
144693145538
sqlite3DbFreeNN(db, pWInfo);
144694145539
}
144695145540
144696145541
/*
144697145542
** Return TRUE if all of the following are true:
@@ -144888,10 +145733,12 @@
144888145733
WHERETRACE(0xffffffff,("=== query planner search limit reached ===\n"));
144889145734
if( pBuilder->pOrSet ) pBuilder->pOrSet->n = 0;
144890145735
return SQLITE_DONE;
144891145736
}
144892145737
pBuilder->iPlanLimit--;
145738
+
145739
+ whereLoopAdjustCost(pWInfo->pLoops, pTemplate);
144893145740
144894145741
/* If pBuilder->pOrSet is defined, then only keep track of the costs
144895145742
** and prereqs.
144896145743
*/
144897145744
if( pBuilder->pOrSet!=0 ){
@@ -144903,29 +145750,28 @@
144903145750
whereOrInsert(pBuilder->pOrSet, pTemplate->prereq, pTemplate->rRun,
144904145751
pTemplate->nOut);
144905145752
#if WHERETRACE_ENABLED /* 0x8 */
144906145753
if( sqlite3WhereTrace & 0x8 ){
144907145754
sqlite3DebugPrintf(x?" or-%d: ":" or-X: ", n);
144908
- whereLoopPrint(pTemplate, pBuilder->pWC);
145755
+ sqlite3WhereLoopPrint(pTemplate, pBuilder->pWC);
144909145756
}
144910145757
#endif
144911145758
}
144912145759
return SQLITE_OK;
144913145760
}
144914145761
144915145762
/* Look for an existing WhereLoop to replace with pTemplate
144916145763
*/
144917
- whereLoopAdjustCost(pWInfo->pLoops, pTemplate);
144918145764
ppPrev = whereLoopFindLesser(&pWInfo->pLoops, pTemplate);
144919145765
144920145766
if( ppPrev==0 ){
144921145767
/* There already exists a WhereLoop on the list that is better
144922145768
** than pTemplate, so just ignore pTemplate */
144923145769
#if WHERETRACE_ENABLED /* 0x8 */
144924145770
if( sqlite3WhereTrace & 0x8 ){
144925145771
sqlite3DebugPrintf(" skip: ");
144926
- whereLoopPrint(pTemplate, pBuilder->pWC);
145772
+ sqlite3WhereLoopPrint(pTemplate, pBuilder->pWC);
144927145773
}
144928145774
#endif
144929145775
return SQLITE_OK;
144930145776
}else{
144931145777
p = *ppPrev;
@@ -144937,16 +145783,16 @@
144937145783
*/
144938145784
#if WHERETRACE_ENABLED /* 0x8 */
144939145785
if( sqlite3WhereTrace & 0x8 ){
144940145786
if( p!=0 ){
144941145787
sqlite3DebugPrintf("replace: ");
144942
- whereLoopPrint(p, pBuilder->pWC);
145788
+ sqlite3WhereLoopPrint(p, pBuilder->pWC);
144943145789
sqlite3DebugPrintf(" with: ");
144944145790
}else{
144945145791
sqlite3DebugPrintf(" add: ");
144946145792
}
144947
- whereLoopPrint(pTemplate, pBuilder->pWC);
145793
+ sqlite3WhereLoopPrint(pTemplate, pBuilder->pWC);
144948145794
}
144949145795
#endif
144950145796
if( p==0 ){
144951145797
/* Allocate a new WhereLoop to add to the end of the list */
144952145798
*ppPrev = p = sqlite3DbMallocRawNN(db, sizeof(WhereLoop));
@@ -144966,11 +145812,11 @@
144966145812
if( pToDel==0 ) break;
144967145813
*ppTail = pToDel->pNextLoop;
144968145814
#if WHERETRACE_ENABLED /* 0x8 */
144969145815
if( sqlite3WhereTrace & 0x8 ){
144970145816
sqlite3DebugPrintf(" delete: ");
144971
- whereLoopPrint(pToDel, pBuilder->pWC);
145817
+ sqlite3WhereLoopPrint(pToDel, pBuilder->pWC);
144972145818
}
144973145819
#endif
144974145820
whereLoopDelete(db, pToDel);
144975145821
}
144976145822
}
@@ -145175,12 +146021,13 @@
145175146021
LogEst rLogSize; /* Logarithm of table size */
145176146022
WhereTerm *pTop = 0, *pBtm = 0; /* Top and bottom range constraints */
145177146023
145178146024
pNew = pBuilder->pNew;
145179146025
if( db->mallocFailed ) return SQLITE_NOMEM_BKPT;
145180
- WHERETRACE(0x800, ("BEGIN %s.addBtreeIdx(%s), nEq=%d\n",
145181
- pProbe->pTable->zName,pProbe->zName, pNew->u.btree.nEq));
146026
+ WHERETRACE(0x800, ("BEGIN %s.addBtreeIdx(%s), nEq=%d, nSkip=%d\n",
146027
+ pProbe->pTable->zName,pProbe->zName,
146028
+ pNew->u.btree.nEq, pNew->nSkip));
145182146029
145183146030
assert( (pNew->wsFlags & WHERE_VIRTUALTABLE)==0 );
145184146031
assert( (pNew->wsFlags & WHERE_TOP_LIMIT)==0 );
145185146032
if( pNew->wsFlags & WHERE_BTM_LIMIT ){
145186146033
opMask = WO_LT|WO_LE;
@@ -145473,10 +146320,11 @@
145473146320
** On the other hand, the extra seeks could end up being significantly
145474146321
** more expensive. */
145475146322
assert( 42==sqlite3LogEst(18) );
145476146323
if( saved_nEq==saved_nSkip
145477146324
&& saved_nEq+1<pProbe->nKeyCol
146325
+ && saved_nEq==pNew->nLTerm
145478146326
&& pProbe->noSkipScan==0
145479146327
&& OptimizationEnabled(db, SQLITE_SkipScan)
145480146328
&& pProbe->aiRowLogEst[saved_nEq+1]>=42 /* TUNING: Minimum for skip-scan */
145481146329
&& (rc = whereLoopResize(db, pNew, pNew->nLTerm+1))==SQLITE_OK
145482146330
){
@@ -146254,11 +147102,12 @@
146254147102
rc = whereLoopAddBtree(&sSubBuild, mPrereq);
146255147103
}
146256147104
if( rc==SQLITE_OK ){
146257147105
rc = whereLoopAddOr(&sSubBuild, mPrereq, mUnusable);
146258147106
}
146259
- assert( rc==SQLITE_OK || sCur.n==0 );
147107
+ assert( rc==SQLITE_OK || rc==SQLITE_DONE || sCur.n==0 );
147108
+ testcase( rc==SQLITE_DONE );
146260147109
if( sCur.n==0 ){
146261147110
sSum.n = 0;
146262147111
break;
146263147112
}else if( once ){
146264147113
whereOrMove(&sSum, &sCur);
@@ -147584,11 +148433,11 @@
147584148433
int i;
147585148434
static const char zLabel[] = "0123456789abcdefghijklmnopqrstuvwyxz"
147586148435
"ABCDEFGHIJKLMNOPQRSTUVWYXZ";
147587148436
for(p=pWInfo->pLoops, i=0; p; p=p->pNextLoop, i++){
147588148437
p->cId = zLabel[i%(sizeof(zLabel)-1)];
147589
- whereLoopPrint(p, sWLB.pWC);
148438
+ sqlite3WhereLoopPrint(p, sWLB.pWC);
147590148439
}
147591148440
}
147592148441
#endif
147593148442
147594148443
wherePathSolver(pWInfo, 0);
@@ -147624,11 +148473,11 @@
147624148473
break;
147625148474
}
147626148475
}
147627148476
sqlite3DebugPrintf("\n");
147628148477
for(ii=0; ii<pWInfo->nLevel; ii++){
147629
- whereLoopPrint(pWInfo->a[ii].pWLoop, sWLB.pWC);
148478
+ sqlite3WhereLoopPrint(pWInfo->a[ii].pWLoop, sWLB.pWC);
147630148479
}
147631148480
}
147632148481
#endif
147633148482
147634148483
/* Attempt to omit tables from the join that do not affect the result.
@@ -148016,14 +148865,30 @@
148016148865
for(j=pLevel->u.in.nIn, pIn=&pLevel->u.in.aInLoop[j-1]; j>0; j--, pIn--){
148017148866
sqlite3VdbeJumpHere(v, pIn->addrInTop+1);
148018148867
if( pIn->eEndLoopOp!=OP_Noop ){
148019148868
if( pIn->nPrefix ){
148020148869
assert( pLoop->wsFlags & WHERE_IN_EARLYOUT );
148021
- sqlite3VdbeAddOp4Int(v, OP_IfNoHope, pLevel->iIdxCur,
148022
- sqlite3VdbeCurrentAddr(v)+2,
148023
- pIn->iBase, pIn->nPrefix);
148024
- VdbeCoverage(v);
148870
+ if( (pLoop->wsFlags & WHERE_VIRTUALTABLE)==0 ){
148871
+ sqlite3VdbeAddOp4Int(v, OP_IfNoHope, pLevel->iIdxCur,
148872
+ sqlite3VdbeCurrentAddr(v)+2+(pLevel->iLeftJoin!=0),
148873
+ pIn->iBase, pIn->nPrefix);
148874
+ VdbeCoverage(v);
148875
+ }
148876
+ if( pLevel->iLeftJoin ){
148877
+ /* For LEFT JOIN queries, cursor pIn->iCur may not have been
148878
+ ** opened yet. This occurs for WHERE clauses such as
148879
+ ** "a = ? AND b IN (...)", where the index is on (a, b). If
148880
+ ** the RHS of the (a=?) is NULL, then the "b IN (...)" may
148881
+ ** never have been coded, but the body of the loop run to
148882
+ ** return the null-row. So, if the cursor is not open yet,
148883
+ ** jump over the OP_Next or OP_Prev instruction about to
148884
+ ** be coded. */
148885
+ sqlite3VdbeAddOp2(v, OP_IfNotOpen, pIn->iCur,
148886
+ sqlite3VdbeCurrentAddr(v) + 2
148887
+ );
148888
+ VdbeCoverage(v);
148889
+ }
148025148890
}
148026148891
sqlite3VdbeAddOp2(v, pIn->eEndLoopOp, pIn->iCur, pIn->addrInTop);
148027148892
VdbeCoverage(v);
148028148893
VdbeCoverageIf(v, pIn->eEndLoopOp==OP_Prev);
148029148894
VdbeCoverageIf(v, pIn->eEndLoopOp==OP_Next);
@@ -148183,10 +149048,18 @@
148183149048
#ifdef SQLITE_DEBUG
148184149049
if( db->flags & SQLITE_VdbeAddopTrace ) printf("TRANSLATE complete\n");
148185149050
#endif
148186149051
}
148187149052
}
149053
+
149054
+ /* Undo all Expr node modifications */
149055
+ while( pWInfo->pExprMods ){
149056
+ WhereExprMod *p = pWInfo->pExprMods;
149057
+ pWInfo->pExprMods = p->pNext;
149058
+ memcpy(p->pExpr, &p->orig, sizeof(p->orig));
149059
+ sqlite3DbFree(db, p);
149060
+ }
148188149061
148189149062
/* Final cleanup
148190149063
*/
148191149064
pParse->nQueryLoop = pWInfo->savedNQueryLoop;
148192149065
whereInfoFree(db, pWInfo);
@@ -148994,10 +149867,11 @@
148994149867
}
148995149868
}
148996149869
}
148997149870
if( iCol<0 ){
148998149871
Expr *pDup = sqlite3ExprDup(pParse->db, pExpr, 0);
149872
+ if( pDup && pDup->op==TK_AGG_FUNCTION ) pDup->op = TK_FUNCTION;
148999149873
p->pSub = sqlite3ExprListAppend(pParse, p->pSub, pDup);
149000149874
}
149001149875
if( p->pSub ){
149002149876
assert( ExprHasProperty(pExpr, EP_Static)==0 );
149003149877
ExprSetProperty(pExpr, EP_Static);
@@ -149089,13 +149963,14 @@
149089149963
){
149090149964
if( pAppend ){
149091149965
int i;
149092149966
int nInit = pList ? pList->nExpr : 0;
149093149967
for(i=0; i<pAppend->nExpr; i++){
149968
+ int iDummy;
149094149969
Expr *pDup = sqlite3ExprDup(pParse->db, pAppend->a[i].pExpr, 0);
149095149970
assert( pDup==0 || !ExprHasProperty(pDup, EP_MemToken) );
149096
- if( bIntToNull && pDup && pDup->op==TK_INTEGER ){
149971
+ if( bIntToNull && pDup && sqlite3ExprIsInteger(pDup, &iDummy) ){
149097149972
pDup->op = TK_NULL;
149098149973
pDup->flags &= ~(EP_IntValue|EP_IsTrue|EP_IsFalse);
149099149974
pDup->u.zToken = 0;
149100149975
}
149101149976
pList = sqlite3ExprListAppend(pParse, pList, pDup);
@@ -149142,11 +150017,11 @@
149142150017
p->selFlags |= SF_WinRewrite;
149143150018
149144150019
/* Create the ORDER BY clause for the sub-select. This is the concatenation
149145150020
** of the window PARTITION and ORDER BY clauses. Then, if this makes it
149146150021
** redundant, remove the ORDER BY from the parent SELECT. */
149147
- pSort = sqlite3ExprListDup(db, pMWin->pPartition, 0);
150022
+ pSort = exprListAppendList(pParse, 0, pMWin->pPartition, 1);
149148150023
pSort = exprListAppendList(pParse, pSort, pMWin->pOrderBy, 1);
149149150024
if( pSort && p->pOrderBy && p->pOrderBy->nExpr<=pSort->nExpr ){
149150150025
int nSave = pSort->nExpr;
149151150026
pSort->nExpr = p->pOrderBy->nExpr;
149152150027
if( sqlite3ExprListCompare(pSort, p->pOrderBy, -1)==0 ){
@@ -149226,14 +150101,10 @@
149226150101
memcpy(pTab, pTab2, sizeof(Table));
149227150102
pTab->tabFlags |= TF_Ephemeral;
149228150103
p->pSrc->a[0].pTab = pTab;
149229150104
pTab = pTab2;
149230150105
}
149231
- sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pMWin->iEphCsr, pSublist->nExpr);
149232
- sqlite3VdbeAddOp2(v, OP_OpenDup, pMWin->iEphCsr+1, pMWin->iEphCsr);
149233
- sqlite3VdbeAddOp2(v, OP_OpenDup, pMWin->iEphCsr+2, pMWin->iEphCsr);
149234
- sqlite3VdbeAddOp2(v, OP_OpenDup, pMWin->iEphCsr+3, pMWin->iEphCsr);
149235150106
}else{
149236150107
sqlite3SelectDelete(db, pSub);
149237150108
}
149238150109
if( db->mallocFailed ) rc = SQLITE_NOMEM;
149239150110
sqlite3DbFree(db, pTab);
@@ -149476,25 +150347,33 @@
149476150347
pWin->ppThis = &pSel->pWin;
149477150348
}
149478150349
}
149479150350
149480150351
/*
149481
-** Return 0 if the two window objects are identical, or non-zero otherwise.
149482
-** Identical window objects can be processed in a single scan.
150352
+** Return 0 if the two window objects are identical, 1 if they are
150353
+** different, or 2 if it cannot be determined if the objects are identical
150354
+** or not. Identical window objects can be processed in a single scan.
149483150355
*/
149484150356
SQLITE_PRIVATE int sqlite3WindowCompare(Parse *pParse, Window *p1, Window *p2, int bFilter){
150357
+ int res;
149485150358
if( NEVER(p1==0) || NEVER(p2==0) ) return 1;
149486150359
if( p1->eFrmType!=p2->eFrmType ) return 1;
149487150360
if( p1->eStart!=p2->eStart ) return 1;
149488150361
if( p1->eEnd!=p2->eEnd ) return 1;
149489150362
if( p1->eExclude!=p2->eExclude ) return 1;
149490150363
if( sqlite3ExprCompare(pParse, p1->pStart, p2->pStart, -1) ) return 1;
149491150364
if( sqlite3ExprCompare(pParse, p1->pEnd, p2->pEnd, -1) ) return 1;
149492
- if( sqlite3ExprListCompare(p1->pPartition, p2->pPartition, -1) ) return 1;
149493
- if( sqlite3ExprListCompare(p1->pOrderBy, p2->pOrderBy, -1) ) return 1;
150365
+ if( (res = sqlite3ExprListCompare(p1->pPartition, p2->pPartition, -1)) ){
150366
+ return res;
150367
+ }
150368
+ if( (res = sqlite3ExprListCompare(p1->pOrderBy, p2->pOrderBy, -1)) ){
150369
+ return res;
150370
+ }
149494150371
if( bFilter ){
149495
- if( sqlite3ExprCompare(pParse, p1->pFilter, p2->pFilter, -1) ) return 1;
150372
+ if( (res = sqlite3ExprCompare(pParse, p1->pFilter, p2->pFilter, -1)) ){
150373
+ return res;
150374
+ }
149496150375
}
149497150376
return 0;
149498150377
}
149499150378
149500150379
@@ -149501,14 +150380,21 @@
149501150380
/*
149502150381
** This is called by code in select.c before it calls sqlite3WhereBegin()
149503150382
** to begin iterating through the sub-query results. It is used to allocate
149504150383
** and initialize registers and cursors used by sqlite3WindowCodeStep().
149505150384
*/
149506
-SQLITE_PRIVATE void sqlite3WindowCodeInit(Parse *pParse, Window *pMWin){
150385
+SQLITE_PRIVATE void sqlite3WindowCodeInit(Parse *pParse, Select *pSelect){
150386
+ int nEphExpr = pSelect->pSrc->a[0].pSelect->pEList->nExpr;
150387
+ Window *pMWin = pSelect->pWin;
149507150388
Window *pWin;
149508150389
Vdbe *v = sqlite3GetVdbe(pParse);
149509150390
150391
+ sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pMWin->iEphCsr, nEphExpr);
150392
+ sqlite3VdbeAddOp2(v, OP_OpenDup, pMWin->iEphCsr+1, pMWin->iEphCsr);
150393
+ sqlite3VdbeAddOp2(v, OP_OpenDup, pMWin->iEphCsr+2, pMWin->iEphCsr);
150394
+ sqlite3VdbeAddOp2(v, OP_OpenDup, pMWin->iEphCsr+3, pMWin->iEphCsr);
150395
+
149510150396
/* Allocate registers to use for PARTITION BY values, if any. Initialize
149511150397
** said registers to NULL. */
149512150398
if( pMWin->pPartition ){
149513150399
int nExpr = pMWin->pPartition->nExpr;
149514150400
pMWin->regPart = pParse->nMem+1;
@@ -149770,11 +150656,11 @@
149770150656
149771150657
assert( bInverse==0 || pWin->eStart!=TK_UNBOUNDED );
149772150658
149773150659
/* All OVER clauses in the same window function aggregate step must
149774150660
** be the same. */
149775
- assert( pWin==pMWin || sqlite3WindowCompare(pParse,pWin,pMWin,0)==0 );
150661
+ assert( pWin==pMWin || sqlite3WindowCompare(pParse,pWin,pMWin,0)!=1 );
149776150662
149777150663
for(i=0; i<nArg; i++){
149778150664
if( i!=1 || pFunc->zName!=nth_valueName ){
149779150665
sqlite3VdbeAddOp3(v, OP_Column, csr, pWin->iArgCol+i, reg+i);
149780150666
}else{
@@ -158619,10 +159505,13 @@
158619159505
** the lookaside memory.
158620159506
*/
158621159507
static int setupLookaside(sqlite3 *db, void *pBuf, int sz, int cnt){
158622159508
#ifndef SQLITE_OMIT_LOOKASIDE
158623159509
void *pStart;
159510
+ sqlite3_int64 szAlloc = sz*(sqlite3_int64)cnt;
159511
+ int nBig; /* Number of full-size slots */
159512
+ int nSm; /* Number smaller LOOKASIDE_SMALL-byte slots */
158624159513
158625159514
if( sqlite3LookasideUsed(db,0)>0 ){
158626159515
return SQLITE_BUSY;
158627159516
}
158628159517
/* Free any existing lookaside buffer for this handle before
@@ -158641,15 +159530,30 @@
158641159530
if( sz==0 || cnt==0 ){
158642159531
sz = 0;
158643159532
pStart = 0;
158644159533
}else if( pBuf==0 ){
158645159534
sqlite3BeginBenignMalloc();
158646
- pStart = sqlite3Malloc( sz*(sqlite3_int64)cnt ); /* IMP: R-61949-35727 */
159535
+ pStart = sqlite3Malloc( szAlloc ); /* IMP: R-61949-35727 */
158647159536
sqlite3EndBenignMalloc();
158648
- if( pStart ) cnt = sqlite3MallocSize(pStart)/sz;
159537
+ if( pStart ) szAlloc = sqlite3MallocSize(pStart);
158649159538
}else{
158650159539
pStart = pBuf;
159540
+ }
159541
+#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
159542
+ if( sz>=LOOKASIDE_SMALL*3 ){
159543
+ nBig = szAlloc/(3*LOOKASIDE_SMALL+sz);
159544
+ nSm = (szAlloc - sz*nBig)/LOOKASIDE_SMALL;
159545
+ }else if( sz>=LOOKASIDE_SMALL*2 ){
159546
+ nBig = szAlloc/(LOOKASIDE_SMALL+sz);
159547
+ nSm = (szAlloc - sz*nBig)/LOOKASIDE_SMALL;
159548
+ }else
159549
+#endif /* SQLITE_OMIT_TWOSIZE_LOOKASIDE */
159550
+ if( sz>0 ){
159551
+ nBig = szAlloc/sz;
159552
+ nSm = 0;
159553
+ }else{
159554
+ nBig = nSm = 0;
158651159555
}
158652159556
db->lookaside.pStart = pStart;
158653159557
db->lookaside.pInit = 0;
158654159558
db->lookaside.pFree = 0;
158655159559
db->lookaside.sz = (u16)sz;
@@ -158656,28 +159560,45 @@
158656159560
db->lookaside.szTrue = (u16)sz;
158657159561
if( pStart ){
158658159562
int i;
158659159563
LookasideSlot *p;
158660159564
assert( sz > (int)sizeof(LookasideSlot*) );
158661
- db->lookaside.nSlot = cnt;
158662159565
p = (LookasideSlot*)pStart;
158663
- for(i=cnt-1; i>=0; i--){
159566
+ for(i=0; i<nBig; i++){
158664159567
p->pNext = db->lookaside.pInit;
158665159568
db->lookaside.pInit = p;
158666159569
p = (LookasideSlot*)&((u8*)p)[sz];
158667159570
}
159571
+#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
159572
+ db->lookaside.pSmallInit = 0;
159573
+ db->lookaside.pSmallFree = 0;
159574
+ db->lookaside.pMiddle = p;
159575
+ for(i=0; i<nSm; i++){
159576
+ p->pNext = db->lookaside.pSmallInit;
159577
+ db->lookaside.pSmallInit = p;
159578
+ p = (LookasideSlot*)&((u8*)p)[LOOKASIDE_SMALL];
159579
+ }
159580
+#endif /* SQLITE_OMIT_TWOSIZE_LOOKASIDE */
159581
+ assert( ((uptr)p)<=szAlloc + (uptr)pStart );
158668159582
db->lookaside.pEnd = p;
158669159583
db->lookaside.bDisable = 0;
158670159584
db->lookaside.bMalloced = pBuf==0 ?1:0;
159585
+ db->lookaside.nSlot = nBig+nSm;
158671159586
}else{
158672159587
db->lookaside.pStart = db;
159588
+#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
159589
+ db->lookaside.pSmallInit = 0;
159590
+ db->lookaside.pSmallFree = 0;
159591
+ db->lookaside.pMiddle = db;
159592
+#endif /* SQLITE_OMIT_TWOSIZE_LOOKASIDE */
158673159593
db->lookaside.pEnd = db;
158674159594
db->lookaside.bDisable = 1;
158675159595
db->lookaside.sz = 0;
158676159596
db->lookaside.bMalloced = 0;
158677159597
db->lookaside.nSlot = 0;
158678159598
}
159599
+ assert( sqlite3LookasideUsed(db,0)==0 );
158679159600
#endif /* SQLITE_OMIT_LOOKASIDE */
158680159601
return SQLITE_OK;
158681159602
}
158682159603
158683159604
/*
@@ -158788,10 +159709,11 @@
158788159709
SQLITE_NoSchemaError },
158789159710
{ SQLITE_DBCONFIG_LEGACY_ALTER_TABLE, SQLITE_LegacyAlter },
158790159711
{ SQLITE_DBCONFIG_DQS_DDL, SQLITE_DqsDDL },
158791159712
{ SQLITE_DBCONFIG_DQS_DML, SQLITE_DqsDML },
158792159713
{ SQLITE_DBCONFIG_LEGACY_FILE_FORMAT, SQLITE_LegacyFileFmt },
159714
+ { SQLITE_DBCONFIG_TRUSTED_SCHEMA, SQLITE_TrustedSchema },
158793159715
};
158794159716
unsigned int i;
158795159717
rc = SQLITE_ERROR; /* IMP: R-42790-23372 */
158796159718
for(i=0; i<ArraySize(aFlagOp); i++){
158797159719
if( aFlagOp[i].op==op ){
@@ -159659,12 +160581,19 @@
159659160581
return SQLITE_MISUSE_BKPT;
159660160582
}
159661160583
159662160584
assert( SQLITE_FUNC_CONSTANT==SQLITE_DETERMINISTIC );
159663160585
assert( SQLITE_FUNC_DIRECT==SQLITE_DIRECTONLY );
159664
- extraFlags = enc & (SQLITE_DETERMINISTIC|SQLITE_DIRECTONLY|SQLITE_SUBTYPE);
160586
+ extraFlags = enc & (SQLITE_DETERMINISTIC|SQLITE_DIRECTONLY|
160587
+ SQLITE_SUBTYPE|SQLITE_INNOCUOUS);
159665160588
enc &= (SQLITE_FUNC_ENCMASK|SQLITE_ANY);
160589
+
160590
+ /* The SQLITE_INNOCUOUS flag is the same bit as SQLITE_FUNC_UNSAFE. But
160591
+ ** the meaning is inverted. So flip the bit. */
160592
+ assert( SQLITE_FUNC_UNSAFE==SQLITE_INNOCUOUS );
160593
+ extraFlags ^= SQLITE_FUNC_UNSAFE;
160594
+
159666160595
159667160596
#ifndef SQLITE_OMIT_UTF16
159668160597
/* If SQLITE_UTF16 is specified as the encoding type, transform this
159669160598
** to one of SQLITE_UTF16LE or SQLITE_UTF16BE using the
159670160599
** SQLITE_UTF16NATIVE macro. SQLITE_UTF16 is not used internally.
@@ -159674,15 +160603,17 @@
159674160603
*/
159675160604
if( enc==SQLITE_UTF16 ){
159676160605
enc = SQLITE_UTF16NATIVE;
159677160606
}else if( enc==SQLITE_ANY ){
159678160607
int rc;
159679
- rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF8|extraFlags,
160608
+ rc = sqlite3CreateFunc(db, zFunctionName, nArg,
160609
+ (SQLITE_UTF8|extraFlags)^SQLITE_FUNC_UNSAFE,
159680160610
pUserData, xSFunc, xStep, xFinal, xValue, xInverse, pDestructor);
159681160611
if( rc==SQLITE_OK ){
159682
- rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF16LE|extraFlags,
159683
- pUserData, xSFunc, xStep, xFinal, xValue, xInverse, pDestructor);
160612
+ rc = sqlite3CreateFunc(db, zFunctionName, nArg,
160613
+ (SQLITE_UTF16LE|extraFlags)^SQLITE_FUNC_UNSAFE,
160614
+ pUserData, xSFunc, xStep, xFinal, xValue, xInverse, pDestructor);
159684160615
}
159685160616
if( rc!=SQLITE_OK ){
159686160617
return rc;
159687160618
}
159688160619
enc = SQLITE_UTF16BE;
@@ -161018,11 +161949,13 @@
161018161949
db->nMaxSorterMmap = 0x7FFFFFFF;
161019161950
db->flags |= SQLITE_ShortColNames
161020161951
| SQLITE_EnableTrigger
161021161952
| SQLITE_EnableView
161022161953
| SQLITE_CacheSpill
161023
-
161954
+#if !defined(SQLITE_TRUSTED_SCHEMA) || SQLITE_TRUSTED_SCHEMA+0!=0
161955
+ | SQLITE_TrustedSchema
161956
+#endif
161024161957
/* The SQLITE_DQS compile-time option determines the default settings
161025161958
** for SQLITE_DBCONFIG_DQS_DDL and SQLITE_DBCONFIG_DQS_DML.
161026161959
**
161027161960
** SQLITE_DQS SQLITE_DBCONFIG_DQS_DDL SQLITE_DBCONFIG_DQS_DML
161028161961
** ---------- ----------------------- -----------------------
@@ -161247,10 +162180,17 @@
161247162180
#ifdef SQLITE_ENABLE_STMTVTAB
161248162181
if( !db->mallocFailed && rc==SQLITE_OK){
161249162182
rc = sqlite3StmtVtabInit(db);
161250162183
}
161251162184
#endif
162185
+
162186
+#ifdef SQLITE_ENABLE_INTERNAL_FUNCTIONS
162187
+ /* Testing use only!!! The -DSQLITE_ENABLE_INTERNAL_FUNCTIONS=1 compile-time
162188
+ ** option gives access to internal functions by default.
162189
+ ** Testing use only!!! */
162190
+ db->mDbFlags |= DBFLAG_InternalFunc;
162191
+#endif
161252162192
161253162193
/* -DSQLITE_DEFAULT_LOCKING_MODE=1 makes EXCLUSIVE the default locking
161254162194
** mode. -DSQLITE_DEFAULT_LOCKING_MODE=0 make NORMAL the default locking
161255162195
** mode. Doing nothing at all also makes NORMAL the default.
161256162196
*/
@@ -161980,19 +162920,18 @@
161980162920
case SQLITE_TESTCTRL_LOCALTIME_FAULT: {
161981162921
sqlite3GlobalConfig.bLocaltimeFault = va_arg(ap, int);
161982162922
break;
161983162923
}
161984162924
161985
- /* sqlite3_test_control(SQLITE_TESTCTRL_INTERNAL_FUNCS, int onoff);
162925
+ /* sqlite3_test_control(SQLITE_TESTCTRL_INTERNAL_FUNCTIONS, sqlite3*);
161986162926
**
161987
- ** If parameter onoff is non-zero, internal-use-only SQL functions
161988
- ** are visible to ordinary SQL. This is useful for testing but is
161989
- ** unsafe because invalid parameters to those internal-use-only functions
161990
- ** can result in crashes or segfaults.
162927
+ ** Toggle the ability to use internal functions on or off for
162928
+ ** the database connection given in the argument.
161991162929
*/
161992162930
case SQLITE_TESTCTRL_INTERNAL_FUNCTIONS: {
161993
- sqlite3GlobalConfig.bInternalFunctions = va_arg(ap, int);
162931
+ sqlite3 *db = va_arg(ap, sqlite3*);
162932
+ db->mDbFlags ^= DBFLAG_InternalFunc;
161994162933
break;
161995162934
}
161996162935
161997162936
/* sqlite3_test_control(SQLITE_TESTCTRL_NEVER_CORRUPT, int);
161998162937
**
@@ -173136,11 +174075,11 @@
173136174075
Fts3Hash *pHash,
173137174076
const char *zName
173138174077
){
173139174078
int rc = SQLITE_OK;
173140174079
void *p = (void *)pHash;
173141
- const int any = SQLITE_ANY;
174080
+ const int any = SQLITE_UTF8|SQLITE_DIRECTONLY;
173142174081
173143174082
#ifdef SQLITE_TEST
173144174083
char *zTest = 0;
173145174084
char *zTest2 = 0;
173146174085
void *pdb = (void *)db;
@@ -174208,11 +175147,11 @@
174208175147
** of the oldest level in the db that contains at least ? segments. Or,
174209175148
** if no level in the FTS index contains more than ? segments, the statement
174210175149
** returns zero rows. */
174211175150
/* 28 */ "SELECT level, count(*) AS cnt FROM %Q.'%q_segdir' "
174212175151
" GROUP BY level HAVING cnt>=?"
174213
- " ORDER BY (level %% 1024) ASC LIMIT 1",
175152
+ " ORDER BY (level %% 1024) ASC, 2 DESC LIMIT 1",
174214175153
174215175154
/* Estimate the upper limit on the number of leaf nodes in a new segment
174216175155
** created by merging the oldest :2 segments from absolute level :1. See
174217175156
** function sqlite3Fts3Incrmerge() for details. */
174218175157
/* 29 */ "SELECT 2 * total(1 + leaves_end_block - start_block) "
@@ -178804,12 +179743,18 @@
178804179743
sqlite3_int64 iHintAbsLevel = 0; /* Hint level */
178805179744
int nHintSeg = 0; /* Hint number of segments */
178806179745
178807179746
rc = fts3IncrmergeHintPop(&hint, &iHintAbsLevel, &nHintSeg);
178808179747
if( nSeg<0 || (iAbsLevel % nMod) >= (iHintAbsLevel % nMod) ){
179748
+ /* Based on the scan in the block above, it is known that there
179749
+ ** are no levels with a relative level smaller than that of
179750
+ ** iAbsLevel with more than nSeg segments, or if nSeg is -1,
179751
+ ** no levels with more than nMin segments. Use this to limit the
179752
+ ** value of nHintSeg to avoid a large memory allocation in case the
179753
+ ** merge-hint is corrupt*/
178809179754
iAbsLevel = iHintAbsLevel;
178810
- nSeg = nHintSeg;
179755
+ nSeg = MIN(MAX(nMin,nSeg), nHintSeg);
178811179756
bUseHint = 1;
178812179757
bDirtyHint = 1;
178813179758
}else{
178814179759
/* This undoes the effect of the HintPop() above - so that no entry
178815179760
** is removed from the hint blob. */
@@ -178818,11 +179763,11 @@
178818179763
}
178819179764
178820179765
/* If nSeg is less that zero, then there is no level with at least
178821179766
** nMin segments and no hint in the %_stat table. No work to do.
178822179767
** Exit early in this case. */
178823
- if( nSeg<0 ) break;
179768
+ if( nSeg<=0 ) break;
178824179769
178825179770
/* Open a cursor to iterate through the contents of the oldest nSeg
178826179771
** indexes of absolute level iAbsLevel. If this cursor is opened using
178827179772
** the 'hint' parameters, it is possible that there are less than nSeg
178828179773
** segments available in level iAbsLevel. In this case, no work is
@@ -180205,11 +181150,11 @@
180205181150
if( rc==SQLITE_OK ){
180206181151
180207181152
/* Set the *pmSeen output variable. */
180208181153
for(i=0; i<nList; i++){
180209181154
if( sIter.aPhrase[i].pHead ){
180210
- *pmSeen |= (u64)1 << i;
181155
+ *pmSeen |= (u64)1 << (i%64);
180211181156
}
180212181157
}
180213181158
180214181159
/* Loop through all candidate snippets. Store the best snippet in
180215181160
** *pFragment. Store its associated 'score' in iBestScore.
@@ -184272,10 +185217,11 @@
184272185217
"json HIDDEN,root HIDDEN)");
184273185218
if( rc==SQLITE_OK ){
184274185219
pNew = *ppVtab = sqlite3_malloc( sizeof(*pNew) );
184275185220
if( pNew==0 ) return SQLITE_NOMEM;
184276185221
memset(pNew, 0, sizeof(*pNew));
185222
+ sqlite3_vtab_config(db, SQLITE_VTAB_INNOCUOUS);
184277185223
}
184278185224
return rc;
184279185225
}
184280185226
184281185227
/* destructor for json_each virtual table */
@@ -184762,20 +185708,23 @@
184762185708
} aMod[] = {
184763185709
{ "json_each", &jsonEachModule },
184764185710
{ "json_tree", &jsonTreeModule },
184765185711
};
184766185712
#endif
185713
+ static const int enc =
185714
+ SQLITE_UTF8 |
185715
+ SQLITE_DETERMINISTIC |
185716
+ SQLITE_INNOCUOUS;
184767185717
for(i=0; i<sizeof(aFunc)/sizeof(aFunc[0]) && rc==SQLITE_OK; i++){
184768
- rc = sqlite3_create_function(db, aFunc[i].zName, aFunc[i].nArg,
184769
- SQLITE_UTF8 | SQLITE_DETERMINISTIC,
185718
+ rc = sqlite3_create_function(db, aFunc[i].zName, aFunc[i].nArg, enc,
184770185719
(void*)&aFunc[i].flag,
184771185720
aFunc[i].xFunc, 0, 0);
184772185721
}
184773185722
#ifndef SQLITE_OMIT_WINDOWFUNC
184774185723
for(i=0; i<sizeof(aAgg)/sizeof(aAgg[0]) && rc==SQLITE_OK; i++){
184775185724
rc = sqlite3_create_window_function(db, aAgg[i].zName, aAgg[i].nArg,
184776
- SQLITE_SUBTYPE | SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0,
185725
+ SQLITE_SUBTYPE | enc, 0,
184777185726
aAgg[i].xStep, aAgg[i].xFinal,
184778185727
aAgg[i].xValue, jsonGroupInverse, 0);
184779185728
}
184780185729
#endif
184781185730
#ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -190941,18 +191890,24 @@
190941191890
} aAgg[] = {
190942191891
{ geopolyBBoxStep, geopolyBBoxFinal, "geopoly_group_bbox" },
190943191892
};
190944191893
int i;
190945191894
for(i=0; i<sizeof(aFunc)/sizeof(aFunc[0]) && rc==SQLITE_OK; i++){
190946
- int enc = aFunc[i].bPure ? SQLITE_UTF8|SQLITE_DETERMINISTIC : SQLITE_UTF8;
191895
+ int enc;
191896
+ if( aFunc[i].bPure ){
191897
+ enc = SQLITE_UTF8|SQLITE_DETERMINISTIC|SQLITE_INNOCUOUS;
191898
+ }else{
191899
+ enc = SQLITE_UTF8|SQLITE_DIRECTONLY;
191900
+ }
190947191901
rc = sqlite3_create_function(db, aFunc[i].zName, aFunc[i].nArg,
190948191902
enc, 0,
190949191903
aFunc[i].xFunc, 0, 0);
190950191904
}
190951191905
for(i=0; i<sizeof(aAgg)/sizeof(aAgg[0]) && rc==SQLITE_OK; i++){
190952
- rc = sqlite3_create_function(db, aAgg[i].zName, 1, SQLITE_UTF8, 0,
190953
- 0, aAgg[i].xStep, aAgg[i].xFinal);
191906
+ rc = sqlite3_create_function(db, aAgg[i].zName, 1,
191907
+ SQLITE_UTF8|SQLITE_DETERMINISTIC|SQLITE_INNOCUOUS, 0,
191908
+ 0, aAgg[i].xStep, aAgg[i].xFinal);
190954191909
}
190955191910
if( rc==SQLITE_OK ){
190956191911
rc = sqlite3_create_module_v2(db, "geopoly", &geopolyModule, 0, 0);
190957191912
}
190958191913
return rc;
@@ -191638,30 +192593,31 @@
191638192593
191639192594
/*
191640192595
** Register the ICU extension functions with database db.
191641192596
*/
191642192597
SQLITE_PRIVATE int sqlite3IcuInit(sqlite3 *db){
192598
+# define SQLITEICU_EXTRAFLAGS (SQLITE_DETERMINISTIC|SQLITE_INNOCUOUS)
191643192599
static const struct IcuScalar {
191644192600
const char *zName; /* Function name */
191645192601
unsigned char nArg; /* Number of arguments */
191646
- unsigned short enc; /* Optimal text encoding */
192602
+ unsigned int enc; /* Optimal text encoding */
191647192603
unsigned char iContext; /* sqlite3_user_data() context */
191648192604
void (*xFunc)(sqlite3_context*,int,sqlite3_value**);
191649192605
} scalars[] = {
191650
- {"icu_load_collation", 2, SQLITE_UTF8, 1, icuLoadCollation},
192606
+ {"icu_load_collation",2,SQLITE_UTF8|SQLITE_DIRECTONLY,1, icuLoadCollation},
191651192607
#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_ICU)
191652
- {"regexp", 2, SQLITE_ANY|SQLITE_DETERMINISTIC, 0, icuRegexpFunc},
191653
- {"lower", 1, SQLITE_UTF16|SQLITE_DETERMINISTIC, 0, icuCaseFunc16},
191654
- {"lower", 2, SQLITE_UTF16|SQLITE_DETERMINISTIC, 0, icuCaseFunc16},
191655
- {"upper", 1, SQLITE_UTF16|SQLITE_DETERMINISTIC, 1, icuCaseFunc16},
191656
- {"upper", 2, SQLITE_UTF16|SQLITE_DETERMINISTIC, 1, icuCaseFunc16},
191657
- {"lower", 1, SQLITE_UTF8|SQLITE_DETERMINISTIC, 0, icuCaseFunc16},
191658
- {"lower", 2, SQLITE_UTF8|SQLITE_DETERMINISTIC, 0, icuCaseFunc16},
191659
- {"upper", 1, SQLITE_UTF8|SQLITE_DETERMINISTIC, 1, icuCaseFunc16},
191660
- {"upper", 2, SQLITE_UTF8|SQLITE_DETERMINISTIC, 1, icuCaseFunc16},
191661
- {"like", 2, SQLITE_UTF8|SQLITE_DETERMINISTIC, 0, icuLikeFunc},
191662
- {"like", 3, SQLITE_UTF8|SQLITE_DETERMINISTIC, 0, icuLikeFunc},
192608
+ {"regexp", 2, SQLITE_ANY|SQLITEICU_EXTRAFLAGS, 0, icuRegexpFunc},
192609
+ {"lower", 1, SQLITE_UTF16|SQLITEICU_EXTRAFLAGS, 0, icuCaseFunc16},
192610
+ {"lower", 2, SQLITE_UTF16|SQLITEICU_EXTRAFLAGS, 0, icuCaseFunc16},
192611
+ {"upper", 1, SQLITE_UTF16|SQLITEICU_EXTRAFLAGS, 1, icuCaseFunc16},
192612
+ {"upper", 2, SQLITE_UTF16|SQLITEICU_EXTRAFLAGS, 1, icuCaseFunc16},
192613
+ {"lower", 1, SQLITE_UTF8|SQLITEICU_EXTRAFLAGS, 0, icuCaseFunc16},
192614
+ {"lower", 2, SQLITE_UTF8|SQLITEICU_EXTRAFLAGS, 0, icuCaseFunc16},
192615
+ {"upper", 1, SQLITE_UTF8|SQLITEICU_EXTRAFLAGS, 1, icuCaseFunc16},
192616
+ {"upper", 2, SQLITE_UTF8|SQLITEICU_EXTRAFLAGS, 1, icuCaseFunc16},
192617
+ {"like", 2, SQLITE_UTF8|SQLITEICU_EXTRAFLAGS, 0, icuLikeFunc},
192618
+ {"like", 3, SQLITE_UTF8|SQLITEICU_EXTRAFLAGS, 0, icuLikeFunc},
191663192619
#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_ICU) */
191664192620
};
191665192621
int rc = SQLITE_OK;
191666192622
int i;
191667192623
@@ -198070,10 +199026,11 @@
198070199026
return SQLITE_ERROR;
198071199027
}
198072199028
}else{
198073199029
iDb = 0;
198074199030
}
199031
+ sqlite3_vtab_config(db, SQLITE_VTAB_DIRECTONLY);
198075199032
rc = sqlite3_declare_vtab(db, zDbstatSchema);
198076199033
if( rc==SQLITE_OK ){
198077199034
pTab = (StatTable *)sqlite3_malloc64(sizeof(StatTable));
198078199035
if( pTab==0 ) rc = SQLITE_NOMEM_BKPT;
198079199036
}
@@ -198140,21 +199097,18 @@
198140199097
}
198141199098
}
198142199099
i = 0;
198143199100
if( iSchema>=0 ){
198144199101
pIdxInfo->aConstraintUsage[iSchema].argvIndex = ++i;
198145
- pIdxInfo->aConstraintUsage[iSchema].omit = 1;
198146199102
pIdxInfo->idxNum |= 0x01;
198147199103
}
198148199104
if( iName>=0 ){
198149199105
pIdxInfo->aConstraintUsage[iName].argvIndex = ++i;
198150
- pIdxInfo->aConstraintUsage[iName].omit = 1;
198151199106
pIdxInfo->idxNum |= 0x02;
198152199107
}
198153199108
if( iAgg>=0 ){
198154199109
pIdxInfo->aConstraintUsage[iAgg].argvIndex = ++i;
198155
- pIdxInfo->aConstraintUsage[iAgg].omit = 1;
198156199110
pIdxInfo->idxNum |= 0x04;
198157199111
}
198158199112
pIdxInfo->estimatedCost = 1.0;
198159199113
198160199114
/* Records are always returned in ascending order of (name, path).
@@ -198606,13 +199560,13 @@
198606199560
if( idxNum & 0x01 ){
198607199561
/* schema=? constraint is present. Get its value */
198608199562
const char *zDbase = (const char*)sqlite3_value_text(argv[iArg++]);
198609199563
pCsr->iDb = sqlite3FindDbName(pTab->db, zDbase);
198610199564
if( pCsr->iDb<0 ){
198611
- sqlite3_free(pCursor->pVtab->zErrMsg);
198612
- pCursor->pVtab->zErrMsg = sqlite3_mprintf("no such schema: %s", zDbase);
198613
- return pCursor->pVtab->zErrMsg ? SQLITE_ERROR : SQLITE_NOMEM_BKPT;
199565
+ pCsr->iDb = 0;
199566
+ pCsr->isEof = 1;
199567
+ return SQLITE_OK;
198614199568
}
198615199569
}else{
198616199570
pCsr->iDb = pTab->iDb;
198617199571
}
198618199572
if( idxNum & 0x02 ){
@@ -198831,10 +199785,11 @@
198831199785
char **pzErr
198832199786
){
198833199787
DbpageTable *pTab = 0;
198834199788
int rc = SQLITE_OK;
198835199789
199790
+ sqlite3_vtab_config(db, SQLITE_VTAB_DIRECTONLY);
198836199791
rc = sqlite3_declare_vtab(db,
198837199792
"CREATE TABLE x(pgno INTEGER PRIMARY KEY, data BLOB, schema HIDDEN)");
198838199793
if( rc==SQLITE_OK ){
198839199794
pTab = (DbpageTable *)sqlite3_malloc64(sizeof(DbpageTable));
198840199795
if( pTab==0 ) rc = SQLITE_NOMEM_BKPT;
@@ -220005,11 +220960,14 @@
220005220960
break;
220006220961
220007220962
case FTS5_ROLLBACKTO:
220008220963
assert( p->ts.eState==1 );
220009220964
assert( iSavepoint>=-1 );
220010
- assert( iSavepoint<=p->ts.iSavepoint );
220965
+ /* The following assert() can fail if another vtab strikes an error
220966
+ ** within an xSavepoint() call then SQLite calls xRollbackTo() - without
220967
+ ** having called xSavepoint() on this vtab. */
220968
+ /* assert( iSavepoint<=p->ts.iSavepoint ); */
220011220969
p->ts.iSavepoint = iSavepoint;
220012220970
break;
220013220971
}
220014220972
}
220015220973
#else
@@ -222455,11 +223413,11 @@
222455223413
int nArg, /* Number of args */
222456223414
sqlite3_value **apUnused /* Function arguments */
222457223415
){
222458223416
assert( nArg==0 );
222459223417
UNUSED_PARAM2(nArg, apUnused);
222460
- sqlite3_result_text(pCtx, "fts5: 2019-12-26 01:10:17 f482a4cdfa768941e22c399de8ec29a55e729529eeae86d3832077ad1bef22f3", -1, SQLITE_TRANSIENT);
223418
+ sqlite3_result_text(pCtx, "fts5: 2020-01-09 20:44:37 5720924cb07766cd54fb042da58f4b4acf12b60029fba86a23a606ad0d0f7c68", -1, SQLITE_TRANSIENT);
222461223419
}
222462223420
222463223421
/*
222464223422
** Return true if zName is the extension on one of the shadow tables used
222465223423
** by this module.
@@ -227228,12 +228186,12 @@
227228228186
}
227229228187
#endif /* SQLITE_CORE */
227230228188
#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
227231228189
227232228190
/************** End of stmt.c ************************************************/
227233
-#if __LINE__!=227233
228191
+#if __LINE__!=228191
227234228192
#undef SQLITE_SOURCE_ID
227235
-#define SQLITE_SOURCE_ID "2019-12-26 01:10:17 f482a4cdfa768941e22c399de8ec29a55e729529eeae86d3832077ad1befalt2"
228193
+#define SQLITE_SOURCE_ID "2020-01-09 20:44:37 5720924cb07766cd54fb042da58f4b4acf12b60029fba86a23a606ad0d0falt2"
227236228194
#endif
227237228195
/* Return the source-id for this library */
227238228196
SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
227239228197
/************************** End of sqlite3.c ******************************/
227240228198
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1165,11 +1165,11 @@
1165 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
1166 ** [sqlite_version()] and [sqlite_source_id()].
1167 */
1168 #define SQLITE_VERSION "3.31.0"
1169 #define SQLITE_VERSION_NUMBER 3031000
1170 #define SQLITE_SOURCE_ID "2019-12-26 01:10:17 f482a4cdfa768941e22c399de8ec29a55e729529eeae86d3832077ad1bef22f3"
1171
1172 /*
1173 ** CAPI3REF: Run-Time Library Version Numbers
1174 ** KEYWORDS: sqlite3_version sqlite3_sourceid
1175 **
@@ -1576,10 +1576,11 @@
1576 #define SQLITE_CONSTRAINT_PRIMARYKEY (SQLITE_CONSTRAINT | (6<<8))
1577 #define SQLITE_CONSTRAINT_TRIGGER (SQLITE_CONSTRAINT | (7<<8))
1578 #define SQLITE_CONSTRAINT_UNIQUE (SQLITE_CONSTRAINT | (8<<8))
1579 #define SQLITE_CONSTRAINT_VTAB (SQLITE_CONSTRAINT | (9<<8))
1580 #define SQLITE_CONSTRAINT_ROWID (SQLITE_CONSTRAINT |(10<<8))
 
1581 #define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8))
1582 #define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8))
1583 #define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8))
1584 #define SQLITE_AUTH_USER (SQLITE_AUTH | (1<<8))
1585 #define SQLITE_OK_LOAD_PERMANENTLY (SQLITE_OK | (1<<8))
@@ -3303,10 +3304,29 @@
3303 ** the legacy [double-quoted string literal] misfeature for DDL statements,
3304 ** such as CREATE TABLE and CREATE INDEX. The
3305 ** default value of this setting is determined by the [-DSQLITE_DQS]
3306 ** compile-time option.
3307 ** </dd>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3308 **
3309 ** [[SQLITE_DBCONFIG_LEGACY_FILE_FORMAT]]
3310 ** <dt>SQLITE_DBCONFIG_LEGACY_FILE_FORMAT</td>
3311 ** <dd>The SQLITE_DBCONFIG_LEGACY_FILE_FORMAT option activates or deactivates
3312 ** the legacy file format flag. When activated, this flag causes all newly
@@ -3344,11 +3364,12 @@
3344 #define SQLITE_DBCONFIG_LEGACY_ALTER_TABLE 1012 /* int int* */
3345 #define SQLITE_DBCONFIG_DQS_DML 1013 /* int int* */
3346 #define SQLITE_DBCONFIG_DQS_DDL 1014 /* int int* */
3347 #define SQLITE_DBCONFIG_ENABLE_VIEW 1015 /* int int* */
3348 #define SQLITE_DBCONFIG_LEGACY_FILE_FORMAT 1016 /* int int* */
3349 #define SQLITE_DBCONFIG_MAX 1016 /* Largest DBCONFIG */
 
3350
3351 /*
3352 ** CAPI3REF: Enable Or Disable Extended Result Codes
3353 ** METHOD: sqlite3
3354 **
@@ -6035,16 +6056,30 @@
6035 ** [SQLITE_UTF8 | preferred text encoding] as the fourth argument
6036 ** to [sqlite3_create_function()], [sqlite3_create_function16()], or
6037 ** [sqlite3_create_function_v2()].
6038 **
6039 ** The SQLITE_DETERMINISTIC flag means that the new function always gives
6040 ** the same output when the input parameters are the same. The abs() function
6041 ** is deterministic, for example, but randomblob() is not. Functions must
 
6042 ** be deterministic in order to be used in certain contexts such as
6043 ** [CHECK constraints] or [generated columns]. SQLite might also optimize
6044 ** deterministic functions by factoring them out of inner loops.
6045 **
 
 
 
 
 
 
 
 
 
 
 
 
 
6046 ** The SQLITE_DIRECTONLY flag means that the function may only be invoked
6047 ** from top-level SQL, and cannot be used in VIEWs or TRIGGERs. This is
6048 ** a security feature which is recommended for all
6049 ** [application-defined SQL functions] that have side-effects. This flag
6050 ** prevents an attacker from adding triggers and views to a schema then
@@ -6060,10 +6095,11 @@
6060 ** sqlite3_value_subtype() will always return 0).
6061 */
6062 #define SQLITE_DETERMINISTIC 0x000000800
6063 #define SQLITE_DIRECTONLY 0x000080000
6064 #define SQLITE_SUBTYPE 0x000100000
 
6065
6066 /*
6067 ** CAPI3REF: Deprecated Functions
6068 ** DEPRECATED
6069 **
@@ -6591,31 +6627,32 @@
6591 ** <li> [SQLITE_UTF16BE],
6592 ** <li> [SQLITE_UTF16], or
6593 ** <li> [SQLITE_UTF16_ALIGNED].
6594 ** </ul>)^
6595 ** ^The eTextRep argument determines the encoding of strings passed
6596 ** to the collating function callback, xCallback.
6597 ** ^The [SQLITE_UTF16] and [SQLITE_UTF16_ALIGNED] values for eTextRep
6598 ** force strings to be UTF16 with native byte order.
6599 ** ^The [SQLITE_UTF16_ALIGNED] value for eTextRep forces strings to begin
6600 ** on an even byte address.
6601 **
6602 ** ^The fourth argument, pArg, is an application data pointer that is passed
6603 ** through as the first argument to the collating function callback.
6604 **
6605 ** ^The fifth argument, xCallback, is a pointer to the collating function.
6606 ** ^Multiple collating functions can be registered using the same name but
6607 ** with different eTextRep parameters and SQLite will use whichever
6608 ** function requires the least amount of data transformation.
6609 ** ^If the xCallback argument is NULL then the collating function is
6610 ** deleted. ^When all collating functions having the same name are deleted,
6611 ** that collation is no longer usable.
6612 **
6613 ** ^The collating function callback is invoked with a copy of the pArg
6614 ** application data pointer and with two strings in the encoding specified
6615 ** by the eTextRep argument. The collating function must return an
6616 ** integer that is negative, zero, or positive
 
6617 ** if the first string is less than, equal to, or greater than the second,
6618 ** respectively. A collating function must always return the same answer
6619 ** given the same inputs. If two or more collating functions are registered
6620 ** to the same collation name (using different eTextRep values) then all
6621 ** must give an equivalent answer when invoked with equivalent strings.
@@ -9907,11 +9944,11 @@
9907 ** [sqlite3_vtab_config()] interface that [virtual table] implementations
9908 ** can use to customize and optimize their behavior.
9909 **
9910 ** <dl>
9911 ** [[SQLITE_VTAB_CONSTRAINT_SUPPORT]]
9912 ** <dt>SQLITE_VTAB_CONSTRAINT_SUPPORT
9913 ** <dd>Calls of the form
9914 ** [sqlite3_vtab_config](db,SQLITE_VTAB_CONSTRAINT_SUPPORT,X) are supported,
9915 ** where X is an integer. If X is zero, then the [virtual table] whose
9916 ** [xCreate] or [xConnect] method invoked [sqlite3_vtab_config()] does not
9917 ** support constraints. In this configuration (which is the default) if
@@ -9936,13 +9973,35 @@
9936 ** CONFLICT policy is REPLACE, the virtual table implementation should
9937 ** silently replace the appropriate rows within the xUpdate callback and
9938 ** return SQLITE_OK. Or, if this is not possible, it may return
9939 ** SQLITE_CONSTRAINT, in which case SQLite falls back to OR ABORT
9940 ** constraint handling.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9941 ** </dl>
9942 */
9943 #define SQLITE_VTAB_CONSTRAINT_SUPPORT 1
 
 
9944
9945 /*
9946 ** CAPI3REF: Determine The Virtual Table Conflict Policy
9947 **
9948 ** This function may only be called from within a call to the [xUpdate] method
@@ -14415,10 +14474,11 @@
14415
14416 /*
14417 ** A bit in a Bitmask
14418 */
14419 #define MASKBIT(n) (((Bitmask)1)<<(n))
 
14420 #define MASKBIT32(n) (((unsigned int)1)<<(n))
14421 #define ALLBITS ((Bitmask)-1)
14422
14423 /* A VList object records a mapping between parameters/variables/wildcards
14424 ** in the SQL statement (such as $abc, @pqr, or :xyz) and the integer
@@ -14741,10 +14801,12 @@
14741 SQLITE_PRIVATE int sqlite3BtreeLast(BtCursor*, int *pRes);
14742 SQLITE_PRIVATE int sqlite3BtreeNext(BtCursor*, int flags);
14743 SQLITE_PRIVATE int sqlite3BtreeEof(BtCursor*);
14744 SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor*, int flags);
14745 SQLITE_PRIVATE i64 sqlite3BtreeIntegerKey(BtCursor*);
 
 
14746 #ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
14747 SQLITE_PRIVATE i64 sqlite3BtreeOffset(BtCursor*);
14748 #endif
14749 SQLITE_PRIVATE int sqlite3BtreePayload(BtCursor*, u32 offset, u32 amt, void*);
14750 SQLITE_PRIVATE const void *sqlite3BtreePayloadFetch(BtCursor*, u32 *pAmt);
@@ -15027,85 +15089,85 @@
15027 #define OP_IfNullRow 21 /* jump, synopsis: if P1.nullRow then r[P3]=NULL, goto P2 */
15028 #define OP_SeekLT 22 /* jump, synopsis: key=r[P3@P4] */
15029 #define OP_SeekLE 23 /* jump, synopsis: key=r[P3@P4] */
15030 #define OP_SeekGE 24 /* jump, synopsis: key=r[P3@P4] */
15031 #define OP_SeekGT 25 /* jump, synopsis: key=r[P3@P4] */
15032 #define OP_IfNoHope 26 /* jump, synopsis: key=r[P3@P4] */
15033 #define OP_NoConflict 27 /* jump, synopsis: key=r[P3@P4] */
15034 #define OP_NotFound 28 /* jump, synopsis: key=r[P3@P4] */
15035 #define OP_Found 29 /* jump, synopsis: key=r[P3@P4] */
15036 #define OP_SeekRowid 30 /* jump, synopsis: intkey=r[P3] */
15037 #define OP_NotExists 31 /* jump, synopsis: intkey=r[P3] */
15038 #define OP_Last 32 /* jump */
15039 #define OP_IfSmaller 33 /* jump */
15040 #define OP_SorterSort 34 /* jump */
15041 #define OP_Sort 35 /* jump */
15042 #define OP_Rewind 36 /* jump */
15043 #define OP_IdxLE 37 /* jump, synopsis: key=r[P3@P4] */
15044 #define OP_IdxGT 38 /* jump, synopsis: key=r[P3@P4] */
15045 #define OP_IdxLT 39 /* jump, synopsis: key=r[P3@P4] */
15046 #define OP_IdxGE 40 /* jump, synopsis: key=r[P3@P4] */
15047 #define OP_RowSetRead 41 /* jump, synopsis: r[P3]=rowset(P1) */
15048 #define OP_RowSetTest 42 /* jump, synopsis: if r[P3] in rowset(P1) goto P2 */
15049 #define OP_Or 43 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
15050 #define OP_And 44 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */
15051 #define OP_Program 45 /* jump */
15052 #define OP_FkIfZero 46 /* jump, synopsis: if fkctr[P1]==0 goto P2 */
15053 #define OP_IfPos 47 /* jump, synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */
15054 #define OP_IfNotZero 48 /* jump, synopsis: if r[P1]!=0 then r[P1]--, goto P2 */
15055 #define OP_DecrJumpZero 49 /* jump, synopsis: if (--r[P1])==0 goto P2 */
15056 #define OP_IsNull 50 /* jump, same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
15057 #define OP_NotNull 51 /* jump, same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
15058 #define OP_Ne 52 /* jump, same as TK_NE, synopsis: IF r[P3]!=r[P1] */
15059 #define OP_Eq 53 /* jump, same as TK_EQ, synopsis: IF r[P3]==r[P1] */
15060 #define OP_Gt 54 /* jump, same as TK_GT, synopsis: IF r[P3]>r[P1] */
15061 #define OP_Le 55 /* jump, same as TK_LE, synopsis: IF r[P3]<=r[P1] */
15062 #define OP_Lt 56 /* jump, same as TK_LT, synopsis: IF r[P3]<r[P1] */
15063 #define OP_Ge 57 /* jump, same as TK_GE, synopsis: IF r[P3]>=r[P1] */
15064 #define OP_ElseNotEq 58 /* jump, same as TK_ESCAPE */
15065 #define OP_IncrVacuum 59 /* jump */
15066 #define OP_VNext 60 /* jump */
15067 #define OP_Init 61 /* jump, synopsis: Start at P2 */
15068 #define OP_PureFunc 62 /* synopsis: r[P3]=func(r[P2@P5]) */
15069 #define OP_Function 63 /* synopsis: r[P3]=func(r[P2@P5]) */
15070 #define OP_Return 64
15071 #define OP_EndCoroutine 65
15072 #define OP_HaltIfNull 66 /* synopsis: if r[P3]=null halt */
15073 #define OP_Halt 67
15074 #define OP_Integer 68 /* synopsis: r[P2]=P1 */
15075 #define OP_Int64 69 /* synopsis: r[P2]=P4 */
15076 #define OP_String 70 /* synopsis: r[P2]='P4' (len=P1) */
15077 #define OP_Null 71 /* synopsis: r[P2..P3]=NULL */
15078 #define OP_SoftNull 72 /* synopsis: r[P1]=NULL */
15079 #define OP_Blob 73 /* synopsis: r[P2]=P4 (len=P1) */
15080 #define OP_Variable 74 /* synopsis: r[P2]=parameter(P1,P4) */
15081 #define OP_Move 75 /* synopsis: r[P2@P3]=r[P1@P3] */
15082 #define OP_Copy 76 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */
15083 #define OP_SCopy 77 /* synopsis: r[P2]=r[P1] */
15084 #define OP_IntCopy 78 /* synopsis: r[P2]=r[P1] */
15085 #define OP_ResultRow 79 /* synopsis: output=r[P1@P2] */
15086 #define OP_CollSeq 80
15087 #define OP_AddImm 81 /* synopsis: r[P1]=r[P1]+P2 */
15088 #define OP_RealAffinity 82
15089 #define OP_Cast 83 /* synopsis: affinity(r[P1]) */
15090 #define OP_Permutation 84
15091 #define OP_Compare 85 /* synopsis: r[P1@P3] <-> r[P2@P3] */
15092 #define OP_IsTrue 86 /* synopsis: r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4 */
15093 #define OP_Offset 87 /* synopsis: r[P3] = sqlite_offset(P1) */
15094 #define OP_Column 88 /* synopsis: r[P3]=PX */
15095 #define OP_Affinity 89 /* synopsis: affinity(r[P1@P2]) */
15096 #define OP_MakeRecord 90 /* synopsis: r[P3]=mkrec(r[P1@P2]) */
15097 #define OP_Count 91 /* synopsis: r[P2]=count() */
15098 #define OP_ReadCookie 92
15099 #define OP_SetCookie 93
15100 #define OP_ReopenIdx 94 /* synopsis: root=P2 iDb=P3 */
15101 #define OP_OpenRead 95 /* synopsis: root=P2 iDb=P3 */
15102 #define OP_OpenWrite 96 /* synopsis: root=P2 iDb=P3 */
15103 #define OP_OpenDup 97
15104 #define OP_OpenAutoindex 98 /* synopsis: nColumn=P2 */
15105 #define OP_OpenEphemeral 99 /* synopsis: nColumn=P2 */
15106 #define OP_SorterOpen 100
15107 #define OP_BitAnd 101 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
15108 #define OP_BitOr 102 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
15109 #define OP_ShiftLeft 103 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
15110 #define OP_ShiftRight 104 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
15111 #define OP_Add 105 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
@@ -15112,71 +15174,75 @@
15112 #define OP_Subtract 106 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
15113 #define OP_Multiply 107 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
15114 #define OP_Divide 108 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
15115 #define OP_Remainder 109 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
15116 #define OP_Concat 110 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
15117 #define OP_SequenceTest 111 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */
15118 #define OP_BitNot 112 /* same as TK_BITNOT, synopsis: r[P2]= ~r[P1] */
15119 #define OP_OpenPseudo 113 /* synopsis: P3 columns in r[P2] */
15120 #define OP_Close 114
15121 #define OP_String8 115 /* same as TK_STRING, synopsis: r[P2]='P4' */
15122 #define OP_ColumnsUsed 116
15123 #define OP_SeekHit 117 /* synopsis: seekHit=P2 */
15124 #define OP_Sequence 118 /* synopsis: r[P2]=cursor[P1].ctr++ */
15125 #define OP_NewRowid 119 /* synopsis: r[P2]=rowid */
15126 #define OP_Insert 120 /* synopsis: intkey=r[P3] data=r[P2] */
15127 #define OP_Delete 121
15128 #define OP_ResetCount 122
15129 #define OP_SorterCompare 123 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
15130 #define OP_SorterData 124 /* synopsis: r[P2]=data */
15131 #define OP_RowData 125 /* synopsis: r[P2]=data */
15132 #define OP_Rowid 126 /* synopsis: r[P2]=rowid */
15133 #define OP_NullRow 127
15134 #define OP_SeekEnd 128
15135 #define OP_SorterInsert 129 /* synopsis: key=r[P2] */
15136 #define OP_IdxInsert 130 /* synopsis: key=r[P2] */
15137 #define OP_IdxDelete 131 /* synopsis: key=r[P2@P3] */
15138 #define OP_DeferredSeek 132 /* synopsis: Move P3 to P1.rowid if needed */
15139 #define OP_IdxRowid 133 /* synopsis: r[P2]=rowid */
15140 #define OP_Destroy 134
15141 #define OP_Clear 135
15142 #define OP_ResetSorter 136
15143 #define OP_CreateBtree 137 /* synopsis: r[P2]=root iDb=P1 flags=P3 */
15144 #define OP_SqlExec 138
15145 #define OP_ParseSchema 139
15146 #define OP_LoadAnalysis 140
15147 #define OP_DropTable 141
15148 #define OP_DropIndex 142
15149 #define OP_DropTrigger 143
15150 #define OP_IntegrityCk 144
15151 #define OP_RowSetAdd 145 /* synopsis: rowset(P1)=r[P2] */
15152 #define OP_Param 146
15153 #define OP_FkCounter 147 /* synopsis: fkctr[P1]+=P2 */
15154 #define OP_MemMax 148 /* synopsis: r[P1]=max(r[P1],r[P2]) */
15155 #define OP_OffsetLimit 149 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */
15156 #define OP_Real 150 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
15157 #define OP_AggInverse 151 /* synopsis: accum=r[P3] inverse(r[P2@P5]) */
15158 #define OP_AggStep 152 /* synopsis: accum=r[P3] step(r[P2@P5]) */
15159 #define OP_AggStep1 153 /* synopsis: accum=r[P3] step(r[P2@P5]) */
15160 #define OP_AggValue 154 /* synopsis: r[P3]=value N=P2 */
15161 #define OP_AggFinal 155 /* synopsis: accum=r[P1] N=P2 */
15162 #define OP_Expire 156
15163 #define OP_TableLock 157 /* synopsis: iDb=P1 root=P2 write=P3 */
15164 #define OP_VBegin 158
15165 #define OP_VCreate 159
15166 #define OP_VDestroy 160
15167 #define OP_VOpen 161
15168 #define OP_VColumn 162 /* synopsis: r[P3]=vcolumn(P2) */
15169 #define OP_VRename 163
15170 #define OP_Pagecount 164
15171 #define OP_MaxPgcnt 165
15172 #define OP_Trace 166
15173 #define OP_CursorHint 167
15174 #define OP_ReleaseReg 168 /* synopsis: release r[P1@P2] mask P3 */
15175 #define OP_Noop 169
15176 #define OP_Explain 170
15177 #define OP_Abortable 171
 
 
 
 
15178
15179 /* Properties such as "out2" or "jump" that are specified in
15180 ** comments following the "case" for each opcode in the vdbe.c
15181 ** are encoded into bitvectors as follows:
15182 */
@@ -15188,37 +15254,38 @@
15188 #define OPFLG_OUT3 0x20 /* out3: P3 is an output */
15189 #define OPFLG_INITIALIZER {\
15190 /* 0 */ 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x10,\
15191 /* 8 */ 0x00, 0x01, 0x00, 0x01, 0x01, 0x01, 0x03, 0x03,\
15192 /* 16 */ 0x01, 0x01, 0x03, 0x12, 0x03, 0x01, 0x09, 0x09,\
15193 /* 24 */ 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09,\
15194 /* 32 */ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\
15195 /* 40 */ 0x01, 0x23, 0x0b, 0x26, 0x26, 0x01, 0x01, 0x03,\
15196 /* 48 */ 0x03, 0x03, 0x03, 0x03, 0x0b, 0x0b, 0x0b, 0x0b,\
15197 /* 56 */ 0x0b, 0x0b, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00,\
15198 /* 64 */ 0x02, 0x02, 0x08, 0x00, 0x10, 0x10, 0x10, 0x10,\
15199 /* 72 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x10, 0x10, 0x00,\
15200 /* 80 */ 0x00, 0x02, 0x02, 0x02, 0x00, 0x00, 0x12, 0x20,\
15201 /* 88 */ 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00,\
15202 /* 96 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x26, 0x26, 0x26,\
15203 /* 104 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x00,\
15204 /* 112 */ 0x12, 0x00, 0x00, 0x10, 0x00, 0x00, 0x10, 0x10,\
15205 /* 120 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,\
15206 /* 128 */ 0x00, 0x04, 0x04, 0x00, 0x00, 0x10, 0x10, 0x00,\
15207 /* 136 */ 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
15208 /* 144 */ 0x00, 0x06, 0x10, 0x00, 0x04, 0x1a, 0x10, 0x00,\
15209 /* 152 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
15210 /* 160 */ 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\
15211 /* 168 */ 0x00, 0x00, 0x00, 0x00,}
 
15212
15213 /* The sqlite3P2Values() routine is able to run faster if it knows
15214 ** the value of the largest JUMP opcode. The smaller the maximum
15215 ** JUMP opcode the better, so the mkopcodeh.tcl script that
15216 ** generated this include file strives to group all JUMP opcodes
15217 ** together near the beginning of the list.
15218 */
15219 #define SQLITE_MX_JUMP_OPCODE 61 /* Maximum JUMP opcode */
15220
15221 /************** End of opcodes.h *********************************************/
15222 /************** Continuing where we left off in vdbe.h ***********************/
15223
15224 /*
@@ -15284,13 +15351,13 @@
15284 SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe*, u16 P5);
15285 SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe*, int addr);
15286 SQLITE_PRIVATE int sqlite3VdbeChangeToNoop(Vdbe*, int addr);
15287 SQLITE_PRIVATE int sqlite3VdbeDeletePriorOpcode(Vdbe*, u8 op);
15288 #ifdef SQLITE_DEBUG
15289 SQLITE_PRIVATE void sqlite3VdbeReleaseRegisters(Parse*,int addr, int n, u32 mask);
15290 #else
15291 # define sqlite3VdbeReleaseRegisters(P,A,N,M)
15292 #endif
15293 SQLITE_PRIVATE void sqlite3VdbeChangeP4(Vdbe*, int addr, const char *zP4, int N);
15294 SQLITE_PRIVATE void sqlite3VdbeAppendP4(Vdbe*, void *pP4, int p4type);
15295 SQLITE_PRIVATE void sqlite3VdbeSetP4KeyInfo(Parse*, Index*);
15296 SQLITE_PRIVATE void sqlite3VdbeUsesBtree(Vdbe*, int);
@@ -16377,10 +16444,29 @@
16377 ** New lookaside allocations are only allowed if bDisable==0. When
16378 ** bDisable is greater than zero, sz is set to zero which effectively
16379 ** disables lookaside without adding a new test for the bDisable flag
16380 ** in a performance-critical path. sz should be set by to szTrue whenever
16381 ** bDisable changes back to zero.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16382 */
16383 struct Lookaside {
16384 u32 bDisable; /* Only operate the lookaside when zero */
16385 u16 sz; /* Size of each buffer in bytes */
16386 u16 szTrue; /* True value of sz, even if disabled */
@@ -16387,10 +16473,16 @@
16387 u8 bMalloced; /* True if pStart obtained from sqlite3_malloc() */
16388 u32 nSlot; /* Number of lookaside slots allocated */
16389 u32 anStat[3]; /* 0: hits. 1: size misses. 2: full misses */
16390 LookasideSlot *pInit; /* List of buffers not previously used */
16391 LookasideSlot *pFree; /* List of available buffers */
 
 
 
 
 
 
16392 void *pStart; /* First byte of available memory space */
16393 void *pEnd; /* First byte past end of available space */
16394 };
16395 struct LookasideSlot {
16396 LookasideSlot *pNext; /* Next buffer in the list of free buffers */
@@ -16397,10 +16489,17 @@
16397 };
16398
16399 #define DisableLookaside db->lookaside.bDisable++;db->lookaside.sz=0
16400 #define EnableLookaside db->lookaside.bDisable--;\
16401 db->lookaside.sz=db->lookaside.bDisable?0:db->lookaside.szTrue
 
 
 
 
 
 
 
16402
16403 /*
16404 ** A hash table for built-in function definitions. (Application-defined
16405 ** functions use a regular table table from hash.h.)
16406 **
@@ -16606,10 +16705,17 @@
16606 ** A macro to discover the encoding of a database.
16607 */
16608 #define SCHEMA_ENC(db) ((db)->aDb[0].pSchema->enc)
16609 #define ENC(db) ((db)->enc)
16610
 
 
 
 
 
 
 
16611 /*
16612 ** Possible values for the sqlite3.flags.
16613 **
16614 ** Value constraints (enforced via assert()):
16615 ** SQLITE_FullFSync == PAGER_FULLFSYNC
@@ -16621,13 +16727,12 @@
16621 #define SQLITE_FullColNames 0x00000004 /* Show full column names on SELECT */
16622 #define SQLITE_FullFSync 0x00000008 /* Use full fsync on the backend */
16623 #define SQLITE_CkptFullFSync 0x00000010 /* Use full fsync for checkpoint */
16624 #define SQLITE_CacheSpill 0x00000020 /* OK to spill pager cache */
16625 #define SQLITE_ShortColNames 0x00000040 /* Show short columns names */
16626 #define SQLITE_CountRows 0x00000080 /* Count rows changed by INSERT, */
16627 /* DELETE, or UPDATE and return */
16628 /* the count using a callback. */
16629 #define SQLITE_NullCallback 0x00000100 /* Invoke the callback once if the */
16630 /* result set is empty */
16631 #define SQLITE_IgnoreChecks 0x00000200 /* Do not enforce check constraints */
16632 #define SQLITE_ReadUncommit 0x00000400 /* READ UNCOMMITTED in shared-cache */
16633 #define SQLITE_NoCkptOnClose 0x00000800 /* No checkpoint on close()/DETACH */
@@ -16649,13 +16754,15 @@
16649 #define SQLITE_NoSchemaError 0x08000000 /* Do not report schema parse errors*/
16650 #define SQLITE_Defensive 0x10000000 /* Input SQL is likely hostile */
16651 #define SQLITE_DqsDDL 0x20000000 /* dbl-quoted strings allowed in DDL*/
16652 #define SQLITE_DqsDML 0x40000000 /* dbl-quoted strings allowed in DML*/
16653 #define SQLITE_EnableView 0x80000000 /* Enable the use of views */
 
 
 
16654
16655 /* Flags used only if debugging */
16656 #define HI(X) ((u64)(X)<<32)
16657 #ifdef SQLITE_DEBUG
16658 #define SQLITE_SqlTrace HI(0x0100000) /* Debug print SQL as it executes */
16659 #define SQLITE_VdbeListing HI(0x0200000) /* Debug listings of VDBE progs */
16660 #define SQLITE_VdbeTrace HI(0x0400000) /* True to trace VDBE execution */
16661 #define SQLITE_VdbeAddopTrace HI(0x0800000) /* Trace sqlite3VdbeAddOp() calls */
@@ -16669,10 +16776,11 @@
16669 #define DBFLAG_SchemaChange 0x0001 /* Uncommitted Hash table changes */
16670 #define DBFLAG_PreferBuiltin 0x0002 /* Preference to built-in funcs */
16671 #define DBFLAG_Vacuum 0x0004 /* Currently in a VACUUM */
16672 #define DBFLAG_VacuumInto 0x0008 /* Currently running VACUUM INTO */
16673 #define DBFLAG_SchemaKnownOk 0x0010 /* Schema is known to be valid */
 
16674
16675 /*
16676 ** Bits of the sqlite3.dbOptFlags field that are used by the
16677 ** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface to
16678 ** selectively disable various optimizations.
@@ -16776,10 +16884,11 @@
16776 ** SQLITE_FUNC_MINMAX == NC_MinMaxAgg == SF_MinMaxAgg
16777 ** SQLITE_FUNC_LENGTH == OPFLAG_LENGTHARG
16778 ** SQLITE_FUNC_TYPEOF == OPFLAG_TYPEOFARG
16779 ** SQLITE_FUNC_CONSTANT == SQLITE_DETERMINISTIC from the API
16780 ** SQLITE_FUNC_DIRECT == SQLITE_DIRECTONLY from the API
 
16781 ** SQLITE_FUNC_ENCMASK depends on SQLITE_UTF* macros in the API
16782 */
16783 #define SQLITE_FUNC_ENCMASK 0x0003 /* SQLITE_UTF8, SQLITE_UTF16BE or UTF16LE */
16784 #define SQLITE_FUNC_LIKE 0x0004 /* Candidate for the LIKE optimization */
16785 #define SQLITE_FUNC_CASE 0x0008 /* Case-sensitive LIKE-type function */
@@ -16792,16 +16901,26 @@
16792 #define SQLITE_FUNC_UNLIKELY 0x0400 /* Built-in unlikely() function */
16793 #define SQLITE_FUNC_CONSTANT 0x0800 /* Constant inputs give a constant output */
16794 #define SQLITE_FUNC_MINMAX 0x1000 /* True for min() and max() aggregates */
16795 #define SQLITE_FUNC_SLOCHNG 0x2000 /* "Slow Change". Value constant during a
16796 ** single query - might change over time */
16797 #define SQLITE_FUNC_AFFINITY 0x4000 /* Built-in affinity() function */
16798 #define SQLITE_FUNC_OFFSET 0x8000 /* Built-in sqlite_offset() function */
16799 #define SQLITE_FUNC_WINDOW 0x00010000 /* Built-in window-only function */
16800 #define SQLITE_FUNC_INTERNAL 0x00040000 /* For use by NestedParse() only */
16801 #define SQLITE_FUNC_DIRECT 0x00080000 /* Not for use in TRIGGERs or VIEWs */
16802 #define SQLITE_FUNC_SUBTYPE 0x00100000 /* Result likely to have sub-type */
 
 
 
 
 
 
 
 
 
 
16803
16804 /*
16805 ** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are
16806 ** used to create the initializers for the FuncDef structures.
16807 **
@@ -16813,10 +16932,26 @@
16813 ** argument bNC is true, then the SQLITE_FUNC_NEEDCOLL flag is set.
16814 **
16815 ** VFUNCTION(zName, nArg, iArg, bNC, xFunc)
16816 ** Like FUNCTION except it omits the SQLITE_FUNC_CONSTANT flag.
16817 **
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16818 ** DFUNCTION(zName, nArg, iArg, bNC, xFunc)
16819 ** Like FUNCTION except it omits the SQLITE_FUNC_CONSTANT flag and
16820 ** adds the SQLITE_FUNC_SLOCHNG flag. Used for date & time functions
16821 ** and functions like sqlite_version() that can change, but not during
16822 ** a single query. The iArg is ignored. The user-data is always set
@@ -16852,10 +16987,20 @@
16852 {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
16853 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} }
16854 #define VFUNCTION(zName, nArg, iArg, bNC, xFunc) \
16855 {nArg, SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
16856 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} }
 
 
 
 
 
 
 
 
 
 
16857 #define DFUNCTION(zName, nArg, iArg, bNC, xFunc) \
16858 {nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8, \
16859 0, 0, xFunc, 0, 0, 0, #zName, {0} }
16860 #define PURE_DATE(zName, nArg, iArg, bNC, xFunc) \
16861 {nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|SQLITE_FUNC_CONSTANT, \
@@ -17068,13 +17213,20 @@
17068 sqlite3 *db; /* Database connection associated with this table */
17069 Module *pMod; /* Pointer to module implementation */
17070 sqlite3_vtab *pVtab; /* Pointer to vtab instance */
17071 int nRef; /* Number of pointers to this structure */
17072 u8 bConstraint; /* True if constraints are supported */
 
17073 int iSavepoint; /* Depth of the SAVEPOINT stack */
17074 VTable *pNext; /* Next in linked list (see above) */
17075 };
 
 
 
 
 
 
17076
17077 /*
17078 ** The schema for each SQL table and view is represented in memory
17079 ** by an instance of the following structure.
17080 */
@@ -17672,11 +17824,11 @@
17672 #define EP_Subrtn 0x2000000 /* Uses Expr.y.sub. TK_IN, _SELECT, or _EXISTS */
17673 #define EP_Quoted 0x4000000 /* TK_ID was originally quoted */
17674 #define EP_Static 0x8000000 /* Held in memory not obtained from malloc() */
17675 #define EP_IsTrue 0x10000000 /* Always has boolean value of TRUE */
17676 #define EP_IsFalse 0x20000000 /* Always has boolean value of FALSE */
17677 #define EP_Indirect 0x40000000 /* Contained within a TRIGGER or a VIEW */
17678
17679 /*
17680 ** The EP_Propagate mask is a set of properties that automatically propagate
17681 ** upwards into parent nodes.
17682 */
@@ -17736,27 +17888,32 @@
17736 ** as the list of "expr AS ID" fields following a "SELECT" or in the
17737 ** list of "ID = expr" items in an UPDATE. A list of expressions can
17738 ** also be used as the argument to a function, in which case the a.zName
17739 ** field is not used.
17740 **
17741 ** By default the Expr.zSpan field holds a human-readable description of
17742 ** the expression that is used in the generation of error messages and
17743 ** column labels. In this case, Expr.zSpan is typically the text of a
17744 ** column expression as it exists in a SELECT statement. However, if
17745 ** the bSpanIsTab flag is set, then zSpan is overloaded to mean the name
17746 ** of the result column in the form: DATABASE.TABLE.COLUMN. This later
17747 ** form is used for name resolution with nested FROM clauses.
 
 
 
 
 
 
17748 */
17749 struct ExprList {
17750 int nExpr; /* Number of expressions on the list */
17751 struct ExprList_item { /* For each expression in the list */
17752 Expr *pExpr; /* The parse tree for this expression */
17753 char *zName; /* Token associated with this expression */
17754 char *zSpan; /* Original text of the expression */
17755 u8 sortFlags; /* Mask of KEYINFO_ORDER_* flags */
 
17756 unsigned done :1; /* A flag to indicate when processing is finished */
17757 unsigned bSpanIsTab :1; /* zSpan holds DB.TABLE.COLUMN */
17758 unsigned reusable :1; /* Constant expression is reusable */
17759 unsigned bSorterRef :1; /* Defer evaluation until after sorting */
17760 unsigned bNulls: 1; /* True if explicit "NULLS FIRST/LAST" */
17761 union {
17762 struct {
@@ -17766,10 +17923,17 @@
17766 int iConstExprReg; /* Register in which Expr value is cached */
17767 } u;
17768 } a[1]; /* One slot for each expression in the list */
17769 };
17770
 
 
 
 
 
 
 
17771 /*
17772 ** An instance of this structure can hold a simple list of identifiers,
17773 ** such as the list "a,b,c" in the following statements:
17774 **
17775 ** INSERT INTO t(a,b,c) VALUES ...;
@@ -17829,10 +17993,11 @@
17829 unsigned isIndexedBy :1; /* True if there is an INDEXED BY clause */
17830 unsigned isTabFunc :1; /* True if table-valued-function syntax */
17831 unsigned isCorrelated :1; /* True if sub-query is correlated */
17832 unsigned viaCoroutine :1; /* Implemented as a co-routine */
17833 unsigned isRecursive :1; /* True for recursive reference in WITH */
 
17834 } fg;
17835 int iCursor; /* The VDBE cursor number used to access this table */
17836 Expr *pOn; /* The ON clause of a join */
17837 IdList *pUsing; /* The USING clause of a join */
17838 Bitmask colUsed; /* Bit N (1<<N) set if column N of pTab is used */
@@ -17949,10 +18114,11 @@
17949 #define NC_Complex 0x02000 /* True if a function or subquery seen */
17950 #define NC_AllowWin 0x04000 /* Window functions are allowed here */
17951 #define NC_HasWin 0x08000 /* One or more window functions seen */
17952 #define NC_IsDDL 0x10000 /* Resolving names in a CREATE statement */
17953 #define NC_InAggFunc 0x20000 /* True if analyzing arguments to an agg func */
 
17954
17955 /*
17956 ** An instance of the following object describes a single ON CONFLICT
17957 ** clause in an upsert.
17958 **
@@ -18504,11 +18670,11 @@
18504 */
18505 typedef struct DbFixer DbFixer;
18506 struct DbFixer {
18507 Parse *pParse; /* The parsing context. Error messages written here */
18508 Schema *pSchema; /* Fix items to this schema */
18509 int bVarOnly; /* Check for variable references only */
18510 const char *zDb; /* Make sure all objects are contained in this database */
18511 const char *zType; /* Type of the container - used for error messages */
18512 const Token *pName; /* Name of the container - used for error messages */
18513 };
18514
@@ -18609,11 +18775,10 @@
18609 #endif
18610 #ifndef SQLITE_UNTESTABLE
18611 int (*xTestCallback)(int); /* Invoked by sqlite3FaultSim() */
18612 #endif
18613 int bLocaltimeFault; /* True to fail localtime() calls */
18614 int bInternalFunctions; /* Internal SQL functions are visible */
18615 int iOnceResetThreshold; /* When to reset OP_Once counters */
18616 u32 szSorterRef; /* Min size in bytes to use sorter-refs */
18617 unsigned int iPrngSeed; /* Alternative fixed seed for the PRNG */
18618 };
18619
@@ -18772,11 +18937,11 @@
18772 SQLITE_PRIVATE void sqlite3WindowListDelete(sqlite3 *db, Window *p);
18773 SQLITE_PRIVATE Window *sqlite3WindowAlloc(Parse*, int, int, Expr*, int , Expr*, u8);
18774 SQLITE_PRIVATE void sqlite3WindowAttach(Parse*, Expr*, Window*);
18775 SQLITE_PRIVATE void sqlite3WindowLink(Select *pSel, Window *pWin);
18776 SQLITE_PRIVATE int sqlite3WindowCompare(Parse*, Window*, Window*, int);
18777 SQLITE_PRIVATE void sqlite3WindowCodeInit(Parse*, Window*);
18778 SQLITE_PRIVATE void sqlite3WindowCodeStep(Parse*, Select*, WhereInfo*, int, int);
18779 SQLITE_PRIVATE int sqlite3WindowRewrite(Parse*, Select*);
18780 SQLITE_PRIVATE int sqlite3ExpandSubquery(Parse*, struct SrcList_item*);
18781 SQLITE_PRIVATE void sqlite3WindowUpdate(Parse*, Window*, Window*, FuncDef*);
18782 SQLITE_PRIVATE Window *sqlite3WindowDup(sqlite3 *db, Expr *pOwner, Window *p);
@@ -19038,10 +19203,11 @@
19038 SQLITE_PRIVATE Expr *sqlite3PExpr(Parse*, int, Expr*, Expr*);
19039 SQLITE_PRIVATE void sqlite3PExprAddSelect(Parse*, Expr*, Select*);
19040 SQLITE_PRIVATE Expr *sqlite3ExprAnd(Parse*,Expr*, Expr*);
19041 SQLITE_PRIVATE Expr *sqlite3ExprSimplifiedAndOr(Expr*);
19042 SQLITE_PRIVATE Expr *sqlite3ExprFunction(Parse*,ExprList*, Token*, int);
 
19043 SQLITE_PRIVATE void sqlite3ExprAssignVarNumber(Parse*, Expr*, u32);
19044 SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3*, Expr*);
19045 SQLITE_PRIVATE void sqlite3ExprUnmapAndDelete(Parse*, Expr*);
19046 SQLITE_PRIVATE ExprList *sqlite3ExprListAppend(Parse*,ExprList*,Expr*);
19047 SQLITE_PRIVATE ExprList *sqlite3ExprListAppendVector(Parse*,ExprList*,IdList*,Expr*);
@@ -19195,10 +19361,11 @@
19195 SQLITE_PRIVATE int sqlite3WhereBreakLabel(WhereInfo*);
19196 SQLITE_PRIVATE int sqlite3WhereOkOnePass(WhereInfo*, int*);
19197 #define ONEPASS_OFF 0 /* Use of ONEPASS not allowed */
19198 #define ONEPASS_SINGLE 1 /* ONEPASS valid for a single row update */
19199 #define ONEPASS_MULTI 2 /* ONEPASS is valid for multiple rows */
 
19200 SQLITE_PRIVATE void sqlite3ExprCodeLoadIndexColumn(Parse*, Index*, int, int, int);
19201 SQLITE_PRIVATE int sqlite3ExprCodeGetColumn(Parse*, Table*, int, int, int, u8);
19202 SQLITE_PRIVATE void sqlite3ExprCodeGetColumnOfTable(Vdbe*, Table*, int, int, int);
19203 SQLITE_PRIVATE void sqlite3ExprCodeMove(Parse*, int, int, int);
19204 SQLITE_PRIVATE void sqlite3ExprCode(Parse*, Expr*, int);
@@ -19249,10 +19416,11 @@
19249 SQLITE_PRIVATE void sqlite3BeginTransaction(Parse*, int);
19250 SQLITE_PRIVATE void sqlite3EndTransaction(Parse*,int);
19251 SQLITE_PRIVATE void sqlite3Savepoint(Parse*, int, Token*);
19252 SQLITE_PRIVATE void sqlite3CloseSavepoints(sqlite3 *);
19253 SQLITE_PRIVATE void sqlite3LeaveMutexAndCloseZombie(sqlite3*);
 
19254 SQLITE_PRIVATE int sqlite3ExprIdToTrueFalse(Expr*);
19255 SQLITE_PRIVATE int sqlite3ExprTruthValue(const Expr*);
19256 SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr*);
19257 SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr*);
19258 SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*, u8);
@@ -19505,11 +19673,16 @@
19505 SQLITE_PRIVATE void sqlite3ExpirePreparedStatements(sqlite3*, int);
19506 SQLITE_PRIVATE void sqlite3CodeRhsOfIN(Parse*, Expr*, int);
19507 SQLITE_PRIVATE int sqlite3CodeSubselect(Parse*, Expr*);
19508 SQLITE_PRIVATE void sqlite3SelectPrep(Parse*, Select*, NameContext*);
19509 SQLITE_PRIVATE void sqlite3SelectWrongNumTermsError(Parse *pParse, Select *p);
19510 SQLITE_PRIVATE int sqlite3MatchSpanName(const char*, const char*, const char*, const char*);
 
 
 
 
 
19511 SQLITE_PRIVATE int sqlite3ResolveExprNames(NameContext*, Expr*);
19512 SQLITE_PRIVATE int sqlite3ResolveExprListNames(NameContext*, ExprList*);
19513 SQLITE_PRIVATE void sqlite3ResolveSelectNames(Parse*, Select*, NameContext*);
19514 SQLITE_PRIVATE int sqlite3ResolveSelfReference(Parse*,Table*,int,Expr*,ExprList*);
19515 SQLITE_PRIVATE int sqlite3ResolveOrderGroupBy(Parse*, Select*, ExprList*, const char*);
@@ -19977,11 +20150,10 @@
19977 ** Bit 0x40 is set if the character is non-alphanumeric and can be used in an
19978 ** SQLite identifier. Identifiers are alphanumerics, "_", "$", and any
19979 ** non-ASCII UTF character. Hence the test for whether or not a character is
19980 ** part of an identifier is 0x46.
19981 */
19982 #ifdef SQLITE_ASCII
19983 SQLITE_PRIVATE const unsigned char sqlite3CtypeMap[256] = {
19984 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 00..07 ........ */
19985 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, /* 08..0f ........ */
19986 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 10..17 ........ */
19987 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 18..1f ........ */
@@ -20015,11 +20187,10 @@
20015 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* e0..e7 ........ */
20016 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* e8..ef ........ */
20017 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* f0..f7 ........ */
20018 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40 /* f8..ff ........ */
20019 };
20020 #endif
20021
20022 /* EVIDENCE-OF: R-02982-34736 In order to maintain full backwards
20023 ** compatibility for legacy applications, the URI filename capability is
20024 ** disabled by default.
20025 **
@@ -20080,13 +20251,22 @@
20080 ** number of bytes in each lookaside slot (should be a multiple of 8)
20081 ** and N is the number of slots. The lookaside-configuration can be
20082 ** changed as start-time using sqlite3_config(SQLITE_CONFIG_LOOKASIDE)
20083 ** or at run-time for an individual database connection using
20084 ** sqlite3_db_config(db, SQLITE_DBCONFIG_LOOKASIDE);
 
 
 
 
 
20085 */
20086 #ifndef SQLITE_DEFAULT_LOOKASIDE
20087 # define SQLITE_DEFAULT_LOOKASIDE 1200,100
 
 
 
 
20088 #endif
20089
20090
20091 /* The default maximum size of an in-memory database created using
20092 ** sqlite3_deserialize()
@@ -20148,11 +20328,10 @@
20148 #endif
20149 #ifndef SQLITE_UNTESTABLE
20150 0, /* xTestCallback */
20151 #endif
20152 0, /* bLocaltimeFault */
20153 0, /* bInternalFunctions */
20154 0x7ffffffe, /* iOnceResetThreshold */
20155 SQLITE_DEFAULT_SORTERREF_SIZE, /* szSorterRef */
20156 0, /* iPrngSeed */
20157 };
20158
@@ -20710,10 +20889,11 @@
20710 ** Function prototypes
20711 */
20712 SQLITE_PRIVATE void sqlite3VdbeError(Vdbe*, const char *, ...);
20713 SQLITE_PRIVATE void sqlite3VdbeFreeCursor(Vdbe *, VdbeCursor*);
20714 void sqliteVdbePopStack(Vdbe*,int);
 
20715 SQLITE_PRIVATE int sqlite3VdbeCursorMoveto(VdbeCursor**, int*);
20716 SQLITE_PRIVATE int sqlite3VdbeCursorRestore(VdbeCursor*);
20717 SQLITE_PRIVATE u32 sqlite3VdbeSerialTypeLen(u32);
20718 SQLITE_PRIVATE u8 sqlite3VdbeOneByteSerialTypeLen(u8);
20719 SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(unsigned char*, Mem*, u32);
@@ -20822,11 +21002,11 @@
20822 # define sqlite3VdbeCheckFk(p,i) 0
20823 #endif
20824
20825 #ifdef SQLITE_DEBUG
20826 SQLITE_PRIVATE void sqlite3VdbePrintSql(Vdbe*);
20827 SQLITE_PRIVATE void sqlite3VdbeMemPrettyPrint(Mem *pMem, char *zBuf);
20828 #endif
20829 #ifndef SQLITE_OMIT_UTF16
20830 SQLITE_PRIVATE int sqlite3VdbeMemTranslate(Mem*, u8);
20831 SQLITE_PRIVATE int sqlite3VdbeMemHandleBom(Mem *pMem);
20832 #endif
@@ -21014,10 +21194,14 @@
21014 ** Count the number of slots of lookaside memory that are outstanding
21015 */
21016 SQLITE_PRIVATE int sqlite3LookasideUsed(sqlite3 *db, int *pHighwater){
21017 u32 nInit = countLookasideSlots(db->lookaside.pInit);
21018 u32 nFree = countLookasideSlots(db->lookaside.pFree);
 
 
 
 
21019 if( pHighwater ) *pHighwater = db->lookaside.nSlot - nInit;
21020 return db->lookaside.nSlot - (nInit+nFree);
21021 }
21022
21023 /*
@@ -21046,10 +21230,19 @@
21046 while( p->pNext ) p = p->pNext;
21047 p->pNext = db->lookaside.pInit;
21048 db->lookaside.pInit = db->lookaside.pFree;
21049 db->lookaside.pFree = 0;
21050 }
 
 
 
 
 
 
 
 
 
21051 }
21052 break;
21053 }
21054
21055 case SQLITE_DBSTATUS_LOOKASIDE_HIT:
@@ -27142,28 +27335,46 @@
27142 ** sqlite3Malloc() or sqlite3_malloc().
27143 */
27144 SQLITE_PRIVATE int sqlite3MallocSize(void *p){
27145 assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
27146 return sqlite3GlobalConfig.m.xSize(p);
 
 
 
 
 
 
 
27147 }
27148 SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, void *p){
27149 assert( p!=0 );
 
27150 if( db==0 || !isLookaside(db,p) ){
27151 #ifdef SQLITE_DEBUG
27152 if( db==0 ){
27153 assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) );
27154 assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
27155 }else{
27156 assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
27157 assert( sqlite3MemdebugNoType(p, (u8)~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
27158 }
 
27159 #endif
27160 return sqlite3GlobalConfig.m.xSize(p);
27161 }else{
27162 assert( sqlite3_mutex_held(db->mutex) );
27163 return db->lookaside.szTrue;
 
 
 
 
 
 
 
 
 
27164 }
 
27165 }
27166 SQLITE_API sqlite3_uint64 sqlite3_msize(void *p){
27167 assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) );
27168 assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
27169 return p ? sqlite3GlobalConfig.m.xSize(p) : 0;
@@ -27206,19 +27417,31 @@
27206 if( db ){
27207 if( db->pnBytesFreed ){
27208 measureAllocationSize(db, p);
27209 return;
27210 }
27211 if( isLookaside(db, p) ){
27212 LookasideSlot *pBuf = (LookasideSlot*)p;
 
 
27213 #ifdef SQLITE_DEBUG
27214 /* Trash all content in the buffer being freed */
27215 memset(p, 0xaa, db->lookaside.szTrue);
27216 #endif
27217 pBuf->pNext = db->lookaside.pFree;
27218 db->lookaside.pFree = pBuf;
27219 return;
 
 
 
 
 
 
 
 
 
 
 
27220 }
27221 }
27222 assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
27223 assert( sqlite3MemdebugNoType(p, (u8)~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
27224 assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
@@ -27371,15 +27594,31 @@
27371 LookasideSlot *pBuf;
27372 assert( db!=0 );
27373 assert( sqlite3_mutex_held(db->mutex) );
27374 assert( db->pnBytesFreed==0 );
27375 if( n>db->lookaside.sz ){
27376 if( db->lookaside.bDisable ){
27377 return db->mallocFailed ? 0 : dbMallocRawFinish(db, n);
 
 
27378 }
27379 db->lookaside.anStat[1]++;
27380 }else if( (pBuf = db->lookaside.pFree)!=0 ){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27381 db->lookaside.pFree = pBuf->pNext;
27382 db->lookaside.anStat[0]++;
27383 return (void*)pBuf;
27384 }else if( (pBuf = db->lookaside.pInit)!=0 ){
27385 db->lookaside.pInit = pBuf->pNext;
@@ -27408,11 +27647,20 @@
27408 */
27409 SQLITE_PRIVATE void *sqlite3DbRealloc(sqlite3 *db, void *p, u64 n){
27410 assert( db!=0 );
27411 if( p==0 ) return sqlite3DbMallocRawNN(db, n);
27412 assert( sqlite3_mutex_held(db->mutex) );
27413 if( isLookaside(db,p) && n<=db->lookaside.szTrue ) return p;
 
 
 
 
 
 
 
 
 
27414 return dbReallocFinish(db, p, n);
27415 }
27416 static SQLITE_NOINLINE void *dbReallocFinish(sqlite3 *db, void *p, u64 n){
27417 void *pNew = 0;
27418 assert( db!=0 );
@@ -27419,11 +27667,11 @@
27419 assert( p!=0 );
27420 if( db->mallocFailed==0 ){
27421 if( isLookaside(db, p) ){
27422 pNew = sqlite3DbMallocRawNN(db, n);
27423 if( pNew ){
27424 memcpy(pNew, p, db->lookaside.szTrue);
27425 sqlite3DbFree(db, p);
27426 }
27427 }else{
27428 assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
27429 assert( sqlite3MemdebugNoType(p, (u8)~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
@@ -28985,11 +29233,11 @@
28985 sqlite3_str_appendf(&x, "%s", pCte->zName);
28986 if( pCte->pCols && pCte->pCols->nExpr>0 ){
28987 char cSep = '(';
28988 int j;
28989 for(j=0; j<pCte->pCols->nExpr; j++){
28990 sqlite3_str_appendf(&x, "%c%s", cSep, pCte->pCols->a[j].zName);
28991 cSep = ',';
28992 }
28993 sqlite3_str_appendf(&x, ")");
28994 }
28995 sqlite3_str_appendf(&x, " AS");
@@ -29026,10 +29274,13 @@
29026 sqlite3_str_appendf(&x, " (AS %s)", pItem->zAlias);
29027 }
29028 if( pItem->fg.jointype & JT_LEFT ){
29029 sqlite3_str_appendf(&x, " LEFT-JOIN");
29030 }
 
 
 
29031 sqlite3StrAccumFinish(&x);
29032 sqlite3TreeViewItem(pView, zLine, i<pSrc->nSrc-1);
29033 if( pItem->pSelect ){
29034 sqlite3TreeViewSelect(pView, pItem->pSelect, 0);
29035 }
@@ -29282,18 +29533,21 @@
29282 sqlite3TreeViewLine(pView, "nil");
29283 sqlite3TreeViewPop(pView);
29284 return;
29285 }
29286 if( pExpr->flags || pExpr->affExpr ){
 
 
 
 
29287 if( ExprHasProperty(pExpr, EP_FromJoin) ){
29288 sqlite3_snprintf(sizeof(zFlgs),zFlgs," fg.af=%x.%c iRJT=%d",
29289 pExpr->flags, pExpr->affExpr ? pExpr->affExpr : 'n',
29290 pExpr->iRightJoinTable);
29291 }else{
29292 sqlite3_snprintf(sizeof(zFlgs),zFlgs," fg.af=%x.%c",
29293 pExpr->flags, pExpr->affExpr ? pExpr->affExpr : 'n');
29294 }
 
 
 
 
29295 }else{
29296 zFlgs[0] = 0;
29297 }
29298 switch( pExpr->op ){
29299 case TK_AGG_COLUMN: {
@@ -29445,11 +29699,11 @@
29445 pFarg = 0;
29446 pWin = 0;
29447 }else{
29448 pFarg = pExpr->x.pList;
29449 #ifndef SQLITE_OMIT_WINDOWFUNC
29450 pWin = pExpr->y.pWin;
29451 #else
29452 pWin = 0;
29453 #endif
29454 }
29455 if( pExpr->op==TK_AGG_FUNCTION ){
@@ -29607,12 +29861,13 @@
29607 }else{
29608 int i;
29609 sqlite3TreeViewLine(pView, "%s", zLabel);
29610 for(i=0; i<pList->nExpr; i++){
29611 int j = pList->a[i].u.x.iOrderByCol;
29612 char *zName = pList->a[i].zName;
29613 int moreToFollow = i<pList->nExpr - 1;
 
29614 if( j || zName ){
29615 sqlite3TreeViewPush(pView, moreToFollow);
29616 moreToFollow = 0;
29617 sqlite3TreeViewLine(pView, 0);
29618 if( zName ){
@@ -30275,13 +30530,15 @@
30275 assert( pMem->enc!=0 );
30276 assert( pMem->n>=0 );
30277
30278 #if defined(TRANSLATE_TRACE) && defined(SQLITE_DEBUG)
30279 {
30280 char zBuf[100];
30281 sqlite3VdbeMemPrettyPrint(pMem, zBuf);
30282 fprintf(stderr, "INPUT: %s\n", zBuf);
 
 
30283 }
30284 #endif
30285
30286 /* If the translation is between UTF-16 little and big endian, then
30287 ** all that is required is to swap the byte order. This case is handled
@@ -30385,13 +30642,15 @@
30385 pMem->szMalloc = sqlite3DbMallocSize(pMem->db, pMem->z);
30386
30387 translate_out:
30388 #if defined(TRANSLATE_TRACE) && defined(SQLITE_DEBUG)
30389 {
30390 char zBuf[100];
30391 sqlite3VdbeMemPrettyPrint(pMem, zBuf);
30392 fprintf(stderr, "OUTPUT: %s\n", zBuf);
 
 
30393 }
30394 #endif
30395 return SQLITE_OK;
30396 }
30397 #endif /* SQLITE_OMIT_UTF16 */
@@ -31006,10 +31265,11 @@
31006 incr = 1;
31007 zEnd = z + length;
31008 }else{
31009 int i;
31010 incr = 2;
 
31011 assert( SQLITE_UTF16LE==2 && SQLITE_UTF16BE==3 );
31012 testcase( enc==SQLITE_UTF16LE );
31013 testcase( enc==SQLITE_UTF16BE );
31014 for(i=3-enc; i<length && z[i]==0; i+=2){}
31015 if( i<length ) eType = -100;
@@ -32543,85 +32803,85 @@
32543 /* 21 */ "IfNullRow" OpHelp("if P1.nullRow then r[P3]=NULL, goto P2"),
32544 /* 22 */ "SeekLT" OpHelp("key=r[P3@P4]"),
32545 /* 23 */ "SeekLE" OpHelp("key=r[P3@P4]"),
32546 /* 24 */ "SeekGE" OpHelp("key=r[P3@P4]"),
32547 /* 25 */ "SeekGT" OpHelp("key=r[P3@P4]"),
32548 /* 26 */ "IfNoHope" OpHelp("key=r[P3@P4]"),
32549 /* 27 */ "NoConflict" OpHelp("key=r[P3@P4]"),
32550 /* 28 */ "NotFound" OpHelp("key=r[P3@P4]"),
32551 /* 29 */ "Found" OpHelp("key=r[P3@P4]"),
32552 /* 30 */ "SeekRowid" OpHelp("intkey=r[P3]"),
32553 /* 31 */ "NotExists" OpHelp("intkey=r[P3]"),
32554 /* 32 */ "Last" OpHelp(""),
32555 /* 33 */ "IfSmaller" OpHelp(""),
32556 /* 34 */ "SorterSort" OpHelp(""),
32557 /* 35 */ "Sort" OpHelp(""),
32558 /* 36 */ "Rewind" OpHelp(""),
32559 /* 37 */ "IdxLE" OpHelp("key=r[P3@P4]"),
32560 /* 38 */ "IdxGT" OpHelp("key=r[P3@P4]"),
32561 /* 39 */ "IdxLT" OpHelp("key=r[P3@P4]"),
32562 /* 40 */ "IdxGE" OpHelp("key=r[P3@P4]"),
32563 /* 41 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"),
32564 /* 42 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
32565 /* 43 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"),
32566 /* 44 */ "And" OpHelp("r[P3]=(r[P1] && r[P2])"),
32567 /* 45 */ "Program" OpHelp(""),
32568 /* 46 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
32569 /* 47 */ "IfPos" OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"),
32570 /* 48 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]--, goto P2"),
32571 /* 49 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"),
32572 /* 50 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"),
32573 /* 51 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"),
32574 /* 52 */ "Ne" OpHelp("IF r[P3]!=r[P1]"),
32575 /* 53 */ "Eq" OpHelp("IF r[P3]==r[P1]"),
32576 /* 54 */ "Gt" OpHelp("IF r[P3]>r[P1]"),
32577 /* 55 */ "Le" OpHelp("IF r[P3]<=r[P1]"),
32578 /* 56 */ "Lt" OpHelp("IF r[P3]<r[P1]"),
32579 /* 57 */ "Ge" OpHelp("IF r[P3]>=r[P1]"),
32580 /* 58 */ "ElseNotEq" OpHelp(""),
32581 /* 59 */ "IncrVacuum" OpHelp(""),
32582 /* 60 */ "VNext" OpHelp(""),
32583 /* 61 */ "Init" OpHelp("Start at P2"),
32584 /* 62 */ "PureFunc" OpHelp("r[P3]=func(r[P2@P5])"),
32585 /* 63 */ "Function" OpHelp("r[P3]=func(r[P2@P5])"),
32586 /* 64 */ "Return" OpHelp(""),
32587 /* 65 */ "EndCoroutine" OpHelp(""),
32588 /* 66 */ "HaltIfNull" OpHelp("if r[P3]=null halt"),
32589 /* 67 */ "Halt" OpHelp(""),
32590 /* 68 */ "Integer" OpHelp("r[P2]=P1"),
32591 /* 69 */ "Int64" OpHelp("r[P2]=P4"),
32592 /* 70 */ "String" OpHelp("r[P2]='P4' (len=P1)"),
32593 /* 71 */ "Null" OpHelp("r[P2..P3]=NULL"),
32594 /* 72 */ "SoftNull" OpHelp("r[P1]=NULL"),
32595 /* 73 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"),
32596 /* 74 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"),
32597 /* 75 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"),
32598 /* 76 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"),
32599 /* 77 */ "SCopy" OpHelp("r[P2]=r[P1]"),
32600 /* 78 */ "IntCopy" OpHelp("r[P2]=r[P1]"),
32601 /* 79 */ "ResultRow" OpHelp("output=r[P1@P2]"),
32602 /* 80 */ "CollSeq" OpHelp(""),
32603 /* 81 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"),
32604 /* 82 */ "RealAffinity" OpHelp(""),
32605 /* 83 */ "Cast" OpHelp("affinity(r[P1])"),
32606 /* 84 */ "Permutation" OpHelp(""),
32607 /* 85 */ "Compare" OpHelp("r[P1@P3] <-> r[P2@P3]"),
32608 /* 86 */ "IsTrue" OpHelp("r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4"),
32609 /* 87 */ "Offset" OpHelp("r[P3] = sqlite_offset(P1)"),
32610 /* 88 */ "Column" OpHelp("r[P3]=PX"),
32611 /* 89 */ "Affinity" OpHelp("affinity(r[P1@P2])"),
32612 /* 90 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"),
32613 /* 91 */ "Count" OpHelp("r[P2]=count()"),
32614 /* 92 */ "ReadCookie" OpHelp(""),
32615 /* 93 */ "SetCookie" OpHelp(""),
32616 /* 94 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"),
32617 /* 95 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
32618 /* 96 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
32619 /* 97 */ "OpenDup" OpHelp(""),
32620 /* 98 */ "OpenAutoindex" OpHelp("nColumn=P2"),
32621 /* 99 */ "OpenEphemeral" OpHelp("nColumn=P2"),
32622 /* 100 */ "SorterOpen" OpHelp(""),
32623 /* 101 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"),
32624 /* 102 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"),
32625 /* 103 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"),
32626 /* 104 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"),
32627 /* 105 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"),
@@ -32628,71 +32888,75 @@
32628 /* 106 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"),
32629 /* 107 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"),
32630 /* 108 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"),
32631 /* 109 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"),
32632 /* 110 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
32633 /* 111 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"),
32634 /* 112 */ "BitNot" OpHelp("r[P2]= ~r[P1]"),
32635 /* 113 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"),
32636 /* 114 */ "Close" OpHelp(""),
32637 /* 115 */ "String8" OpHelp("r[P2]='P4'"),
32638 /* 116 */ "ColumnsUsed" OpHelp(""),
32639 /* 117 */ "SeekHit" OpHelp("seekHit=P2"),
32640 /* 118 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"),
32641 /* 119 */ "NewRowid" OpHelp("r[P2]=rowid"),
32642 /* 120 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
32643 /* 121 */ "Delete" OpHelp(""),
32644 /* 122 */ "ResetCount" OpHelp(""),
32645 /* 123 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
32646 /* 124 */ "SorterData" OpHelp("r[P2]=data"),
32647 /* 125 */ "RowData" OpHelp("r[P2]=data"),
32648 /* 126 */ "Rowid" OpHelp("r[P2]=rowid"),
32649 /* 127 */ "NullRow" OpHelp(""),
32650 /* 128 */ "SeekEnd" OpHelp(""),
32651 /* 129 */ "SorterInsert" OpHelp("key=r[P2]"),
32652 /* 130 */ "IdxInsert" OpHelp("key=r[P2]"),
32653 /* 131 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
32654 /* 132 */ "DeferredSeek" OpHelp("Move P3 to P1.rowid if needed"),
32655 /* 133 */ "IdxRowid" OpHelp("r[P2]=rowid"),
32656 /* 134 */ "Destroy" OpHelp(""),
32657 /* 135 */ "Clear" OpHelp(""),
32658 /* 136 */ "ResetSorter" OpHelp(""),
32659 /* 137 */ "CreateBtree" OpHelp("r[P2]=root iDb=P1 flags=P3"),
32660 /* 138 */ "SqlExec" OpHelp(""),
32661 /* 139 */ "ParseSchema" OpHelp(""),
32662 /* 140 */ "LoadAnalysis" OpHelp(""),
32663 /* 141 */ "DropTable" OpHelp(""),
32664 /* 142 */ "DropIndex" OpHelp(""),
32665 /* 143 */ "DropTrigger" OpHelp(""),
32666 /* 144 */ "IntegrityCk" OpHelp(""),
32667 /* 145 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
32668 /* 146 */ "Param" OpHelp(""),
32669 /* 147 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
32670 /* 148 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
32671 /* 149 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"),
32672 /* 150 */ "Real" OpHelp("r[P2]=P4"),
32673 /* 151 */ "AggInverse" OpHelp("accum=r[P3] inverse(r[P2@P5])"),
32674 /* 152 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"),
32675 /* 153 */ "AggStep1" OpHelp("accum=r[P3] step(r[P2@P5])"),
32676 /* 154 */ "AggValue" OpHelp("r[P3]=value N=P2"),
32677 /* 155 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
32678 /* 156 */ "Expire" OpHelp(""),
32679 /* 157 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
32680 /* 158 */ "VBegin" OpHelp(""),
32681 /* 159 */ "VCreate" OpHelp(""),
32682 /* 160 */ "VDestroy" OpHelp(""),
32683 /* 161 */ "VOpen" OpHelp(""),
32684 /* 162 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
32685 /* 163 */ "VRename" OpHelp(""),
32686 /* 164 */ "Pagecount" OpHelp(""),
32687 /* 165 */ "MaxPgcnt" OpHelp(""),
32688 /* 166 */ "Trace" OpHelp(""),
32689 /* 167 */ "CursorHint" OpHelp(""),
32690 /* 168 */ "ReleaseReg" OpHelp("release r[P1@P2] mask P3"),
32691 /* 169 */ "Noop" OpHelp(""),
32692 /* 170 */ "Explain" OpHelp(""),
32693 /* 171 */ "Abortable" OpHelp(""),
 
 
 
 
32694 };
32695 return azName[i];
32696 }
32697 #endif
32698
@@ -39156,11 +39420,11 @@
39156 assert( flags==SQLITE_ACCESS_EXISTS || flags==SQLITE_ACCESS_READWRITE );
39157
39158 if( flags==SQLITE_ACCESS_EXISTS ){
39159 struct stat buf;
39160 *pResOut = 0==osStat(zPath, &buf) &&
39161 (S_ISDIR(buf.st_mode) || buf.st_size>0);
39162 }else{
39163 *pResOut = osAccess(zPath, W_OK|R_OK)==0;
39164 }
39165 return SQLITE_OK;
39166 }
@@ -52175,10 +52439,11 @@
52175 if( pPager->eLock!=UNKNOWN_LOCK ){
52176 pPager->eLock = (u8)eLock;
52177 }
52178 IOTRACE(("UNLOCK %p %d\n", pPager, eLock))
52179 }
 
52180 return rc;
52181 }
52182
52183 /*
52184 ** Lock the database file to level eLock, which must be either SHARED_LOCK,
@@ -52896,11 +53161,10 @@
52896 /* The pager state may be changed from PAGER_ERROR to PAGER_OPEN here
52897 ** without clearing the error code. This is intentional - the error
52898 ** code is cleared and the cache reset in the block below.
52899 */
52900 assert( pPager->errCode || pPager->eState!=PAGER_ERROR );
52901 pPager->changeCountDone = 0;
52902 pPager->eState = PAGER_OPEN;
52903 }
52904
52905 /* If Pager.errCode is set, the contents of the pager cache cannot be
52906 ** trusted. Now that there are no outstanding references to the pager,
@@ -53160,11 +53424,10 @@
53160
53161 if( !pPager->exclusiveMode
53162 && (!pagerUseWal(pPager) || sqlite3WalExclusiveMode(pPager->pWal, 0))
53163 ){
53164 rc2 = pagerUnlockDb(pPager, SHARED_LOCK);
53165 pPager->changeCountDone = 0;
53166 }
53167 pPager->eState = PAGER_READER;
53168 pPager->setMaster = 0;
53169
53170 return (rc==SQLITE_OK?rc2:rc);
@@ -63178,10 +63441,11 @@
63178 #define BTCF_ValidNKey 0x02 /* True if info.nKey is valid */
63179 #define BTCF_ValidOvfl 0x04 /* True if aOverflow is valid */
63180 #define BTCF_AtLast 0x08 /* Cursor is pointing ot the last entry */
63181 #define BTCF_Incrblob 0x10 /* True if an incremental I/O handle */
63182 #define BTCF_Multiple 0x20 /* Maybe another cursor on the same btree */
 
63183
63184 /*
63185 ** Potential values for BtCursor.eState.
63186 **
63187 ** CURSOR_INVALID:
@@ -64343,10 +64607,13 @@
64343
64344 assert( CURSOR_VALID==pCur->eState || CURSOR_SKIPNEXT==pCur->eState );
64345 assert( 0==pCur->pKey );
64346 assert( cursorHoldsMutex(pCur) );
64347
 
 
 
64348 if( pCur->eState==CURSOR_SKIPNEXT ){
64349 pCur->eState = CURSOR_VALID;
64350 }else{
64351 pCur->skipNext = 0;
64352 }
@@ -65090,20 +65357,20 @@
65090 u8 *pEnd = &data[cellOffset + nCell*2];
65091 u8 *pAddr;
65092 int sz2 = 0;
65093 int sz = get2byte(&data[iFree+2]);
65094 int top = get2byte(&data[hdr+5]);
65095 if( top>=iFree ){
65096 return SQLITE_CORRUPT_PAGE(pPage);
65097 }
65098 if( iFree2 ){
65099 if( iFree+sz>iFree2 ) return SQLITE_CORRUPT_PAGE(pPage);
65100 sz2 = get2byte(&data[iFree2+2]);
65101 if( iFree2+sz2 > usableSize ) return SQLITE_CORRUPT_PAGE(pPage);
65102 memmove(&data[iFree+sz+sz2], &data[iFree+sz], iFree2-(iFree+sz));
65103 sz += sz2;
65104 }else if( iFree+sz>usableSize ){
65105 return SQLITE_CORRUPT_PAGE(pPage);
65106 }
65107
65108 cbrk = top+sz;
65109 assert( cbrk+(iFree-top) <= usableSize );
@@ -65291,12 +65558,14 @@
65291 testcase( gap+1==top );
65292 testcase( gap==top );
65293 if( (data[hdr+2] || data[hdr+1]) && gap+2<=top ){
65294 u8 *pSpace = pageFindSlot(pPage, nByte, &rc);
65295 if( pSpace ){
 
65296 assert( pSpace+nByte<=data+pPage->pBt->usableSize );
65297 if( (*pIdx = (int)(pSpace-data))<=gap ){
 
65298 return SQLITE_CORRUPT_PAGE(pPage);
65299 }else{
65300 return SQLITE_OK;
65301 }
65302 }else if( rc ){
@@ -65370,16 +65639,16 @@
65370 if( data[iPtr+1]==0 && data[iPtr]==0 ){
65371 iFreeBlk = 0; /* Shortcut for the case when the freelist is empty */
65372 }else{
65373 while( (iFreeBlk = get2byte(&data[iPtr]))<iStart ){
65374 if( iFreeBlk<iPtr+4 ){
65375 if( iFreeBlk==0 ) break;
65376 return SQLITE_CORRUPT_PAGE(pPage);
65377 }
65378 iPtr = iFreeBlk;
65379 }
65380 if( iFreeBlk>pPage->pBt->usableSize-4 ){
65381 return SQLITE_CORRUPT_PAGE(pPage);
65382 }
65383 assert( iFreeBlk>iPtr || iFreeBlk==0 );
65384
65385 /* At this point:
@@ -65390,11 +65659,11 @@
65390 */
65391 if( iFreeBlk && iEnd+3>=iFreeBlk ){
65392 nFrag = iFreeBlk - iEnd;
65393 if( iEnd>iFreeBlk ) return SQLITE_CORRUPT_PAGE(pPage);
65394 iEnd = iFreeBlk + get2byte(&data[iFreeBlk+2]);
65395 if( iEnd > pPage->pBt->usableSize ){
65396 return SQLITE_CORRUPT_PAGE(pPage);
65397 }
65398 iSize = iEnd - iStart;
65399 iFreeBlk = get2byte(&data[iFreeBlk]);
65400 }
@@ -65418,11 +65687,12 @@
65418 x = get2byte(&data[hdr+5]);
65419 if( iStart<=x ){
65420 /* The new freeblock is at the beginning of the cell content area,
65421 ** so just extend the cell content area rather than create another
65422 ** freelist entry */
65423 if( iStart<x || iPtr!=hdr+1 ) return SQLITE_CORRUPT_PAGE(pPage);
 
65424 put2byte(&data[hdr+1], iFreeBlk);
65425 put2byte(&data[hdr+5], iEnd);
65426 }else{
65427 /* Insert the new freeblock into the freelist */
65428 put2byte(&data[iPtr], iStart);
@@ -65538,11 +65808,11 @@
65538 ** freeblocks. */
65539 pc = get2byte(&data[hdr+1]);
65540 nFree = data[hdr+7] + top; /* Init nFree to non-freeblock free space */
65541 if( pc>0 ){
65542 u32 next, size;
65543 if( pc<iCellFirst ){
65544 /* EVIDENCE-OF: R-55530-52930 In a well-formed b-tree page, there will
65545 ** always be at least one cell before the first freeblock.
65546 */
65547 return SQLITE_CORRUPT_PAGE(pPage);
65548 }
@@ -65775,16 +66045,16 @@
65775 /*
65776 ** Return the size of the database file in pages. If there is any kind of
65777 ** error, return ((unsigned int)-1).
65778 */
65779 static Pgno btreePagecount(BtShared *pBt){
 
65780 return pBt->nPage;
65781 }
65782 SQLITE_PRIVATE u32 sqlite3BtreeLastPage(Btree *p){
65783 assert( sqlite3BtreeHoldsMutex(p) );
65784 assert( ((p->pBt->nPage)&0x80000000)==0 );
65785 return btreePagecount(p->pBt);
65786 }
65787
65788 /*
65789 ** Get a page from the pager and initialize it.
65790 **
@@ -68205,10 +68475,22 @@
68205 assert( pCur->eState==CURSOR_VALID );
68206 assert( pCur->curIntKey );
68207 getCellInfo(pCur);
68208 return pCur->info.nKey;
68209 }
 
 
 
 
 
 
 
 
 
 
 
 
68210
68211 #ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
68212 /*
68213 ** Return the offset into the database file for the start of the
68214 ** payload to which the cursor is pointing.
@@ -70565,11 +70847,11 @@
70565 int k; /* Current slot in pCArray->apEnd[] */
70566 u8 *pSrcEnd; /* Current pCArray->apEnd[k] value */
70567
70568 assert( i<iEnd );
70569 j = get2byte(&aData[hdr+5]);
70570 if( j>(u32)usableSize ){ j = 0; }
70571 memcpy(&pTmp[j], &aData[j], usableSize - j);
70572
70573 for(k=0; pCArray->ixNx[k]<=i && ALWAYS(k<NB*2); k++){}
70574 pSrcEnd = pCArray->apEnd[k];
70575
@@ -70591,11 +70873,11 @@
70591 put2byte(pCellptr, (pData - aData));
70592 pCellptr += 2;
70593 if( pData < pCellptr ) return SQLITE_CORRUPT_BKPT;
70594 memcpy(pData, pCell, sz);
70595 assert( sz==pPg->xCellSize(pPg, pCell) || CORRUPT_DB );
70596 testcase( sz!=pPg->xCellSize(pPg,pCell) );
70597 i++;
70598 if( i>=iEnd ) break;
70599 if( pCArray->ixNx[k]<=i ){
70600 k++;
70601 pSrcEnd = pCArray->apEnd[k];
@@ -72302,11 +72584,10 @@
72302 */
72303 #ifdef SQLITE_DEBUG
72304 if( flags & BTREE_SAVEPOSITION ){
72305 assert( pCur->curFlags & BTCF_ValidNKey );
72306 assert( pX->nKey==pCur->info.nKey );
72307 assert( pCur->info.nSize!=0 );
72308 assert( loc==0 );
72309 }
72310 #endif
72311
72312 /* On the other hand, BTREE_SAVEPOSITION==0 does not imply
@@ -75906,27 +76187,34 @@
75906 /*
75907 ** This routine prepares a memory cell for modification by breaking
75908 ** its link to a shallow copy and by marking any current shallow
75909 ** copies of this cell as invalid.
75910 **
75911 ** This is used for testing and debugging only - to make sure shallow
75912 ** copies are not misused.
75913 */
75914 SQLITE_PRIVATE void sqlite3VdbeMemAboutToChange(Vdbe *pVdbe, Mem *pMem){
75915 int i;
75916 Mem *pX;
75917 for(i=0, pX=pVdbe->aMem; i<pVdbe->nMem; i++, pX++){
75918 if( pX->pScopyFrom==pMem ){
 
 
 
 
 
75919 /* If pX is marked as a shallow copy of pMem, then verify that
75920 ** no significant changes have been made to pX since the OP_SCopy.
75921 ** A significant change would indicated a missed call to this
75922 ** function for pX. Minor changes, such as adding or removing a
75923 ** dual type, are allowed, as long as the underlying value is the
75924 ** same. */
75925 u16 mFlags = pMem->flags & pX->flags & pX->mScopyFlags;
75926 assert( (mFlags&(MEM_Int|MEM_IntReal))==0 || pMem->u.i==pX->u.i );
75927 assert( (mFlags&MEM_Real)==0 || pMem->u.r==pX->u.r );
 
 
75928 assert( (mFlags&MEM_Str)==0 || (pMem->n==pX->n && pMem->z==pX->z) );
75929 assert( (mFlags&MEM_Blob)==0 || sqlite3BlobCompare(pMem,pX)==0 );
75930
75931 /* pMem is the register that is changing. But also mark pX as
75932 ** undefined so that we can quickly detect the shallow-copy error */
@@ -75935,11 +76223,10 @@
75935 }
75936 }
75937 pMem->pScopyFrom = 0;
75938 }
75939 #endif /* SQLITE_DEBUG */
75940
75941
75942 /*
75943 ** Make an shallow copy of pFrom into pTo. Prior contents of
75944 ** pTo are freed. The pFrom->z field is not duplicated. If
75945 ** pFrom->z is used, then pTo->z points to the same thing as pFrom->z
@@ -76082,14 +76369,23 @@
76082 }
76083 }
76084
76085 pMem->n = nByte;
76086 pMem->flags = flags;
76087 pMem->enc = (enc==0 ? SQLITE_UTF8 : enc);
 
 
 
 
 
 
 
 
 
76088
76089 #ifndef SQLITE_OMIT_UTF16
76090 if( pMem->enc!=SQLITE_UTF8 && sqlite3VdbeMemHandleBom(pMem) ){
76091 return SQLITE_NOMEM_BKPT;
76092 }
76093 #endif
76094
76095 if( nByte>iLimit ){
@@ -77040,13 +77336,20 @@
77040 }
77041
77042 #ifdef SQLITE_DEBUG
77043 /* This routine is just a convenient place to set a breakpoint that will
77044 ** fire after each opcode is inserted and displayed using
77045 ** "PRAGMA vdbe_addoptrace=on".
 
 
 
 
 
 
 
77046 */
77047 static void test_addop_breakpoint(void){
77048 static int n = 0;
77049 n++;
77050 }
77051 #endif
77052
@@ -77095,11 +77398,11 @@
77095 pOp->zComment = 0;
77096 #endif
77097 #ifdef SQLITE_DEBUG
77098 if( p->db->flags & SQLITE_VdbeAddopTrace ){
77099 sqlite3VdbePrintOp(0, i, &p->aOp[i]);
77100 test_addop_breakpoint();
77101 }
77102 #endif
77103 #ifdef VDBE_PROFILE
77104 pOp->cycles = 0;
77105 pOp->cnt = 0;
@@ -78037,12 +78340,21 @@
78037 #ifdef SQLITE_DEBUG
78038 /*
78039 ** Generate an OP_ReleaseReg opcode to indicate that a range of
78040 ** registers, except any identified by mask, are no longer in use.
78041 */
78042 SQLITE_PRIVATE void sqlite3VdbeReleaseRegisters(Parse *pParse, int iFirst, int N, u32 mask){
 
 
 
 
 
 
 
78043 assert( pParse->pVdbe );
 
 
78044 while( N>0 && (mask&1)!=0 ){
78045 mask >>= 1;
78046 iFirst++;
78047 N--;
78048 }
@@ -78050,10 +78362,11 @@
78050 mask &= ~MASKBIT32(N-1);
78051 N--;
78052 }
78053 if( N>0 ){
78054 sqlite3VdbeAddOp3(pParse->pVdbe, OP_ReleaseReg, iFirst, N, *(int*)&mask);
 
78055 }
78056 }
78057 #endif /* SQLITE_DEBUG */
78058
78059
@@ -80260,11 +80573,11 @@
80260 /*
80261 ** The cursor "p" has a pending seek operation that has not yet been
80262 ** carried out. Seek the cursor now. If an error occurs, return
80263 ** the appropriate error code.
80264 */
80265 static int SQLITE_NOINLINE handleDeferredMoveto(VdbeCursor *p){
80266 int res, rc;
80267 #ifdef SQLITE_TEST
80268 extern int sqlite3_search_count;
80269 #endif
80270 assert( p->deferredMoveto );
@@ -80332,11 +80645,11 @@
80332 if( p->aAltMap && (iMap = p->aAltMap[1+*piCol])>0 ){
80333 *pp = p->pAltCursor;
80334 *piCol = iMap - 1;
80335 return SQLITE_OK;
80336 }
80337 return handleDeferredMoveto(p);
80338 }
80339 if( sqlite3BtreeCursorHasMoved(p->uc.pCursor) ){
80340 return handleMovedCursor(p);
80341 }
80342 return SQLITE_OK;
@@ -84375,10 +84688,30 @@
84375 # define UPDATE_MAX_BLOBSIZE(P) updateMaxBlobsize(P)
84376 #else
84377 # define UPDATE_MAX_BLOBSIZE(P)
84378 #endif
84379
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84380 /*
84381 ** Invoke the VDBE coverage callback, if that callback is defined. This
84382 ** feature is used for test suite validation only and does not appear an
84383 ** production builds.
84384 **
@@ -84719,16 +85052,13 @@
84719 #ifdef SQLITE_DEBUG
84720 /*
84721 ** Write a nice string representation of the contents of cell pMem
84722 ** into buffer zBuf, length nBuf.
84723 */
84724 SQLITE_PRIVATE void sqlite3VdbeMemPrettyPrint(Mem *pMem, char *zBuf){
84725 char *zCsr = zBuf;
84726 int f = pMem->flags;
84727
84728 static const char *const encnames[] = {"(X)", "(8)", "(16LE)", "(16BE)"};
84729
84730 if( f&MEM_Blob ){
84731 int i;
84732 char c;
84733 if( f & MEM_Dyn ){
84734 c = 'z';
@@ -84740,61 +85070,44 @@
84740 c = 'e';
84741 assert( (f & (MEM_Static|MEM_Dyn))==0 );
84742 }else{
84743 c = 's';
84744 }
84745 *(zCsr++) = c;
84746 *(zCsr++) = 'x';
84747 sqlite3_snprintf(100, zCsr, "%d[", pMem->n);
84748 zCsr += sqlite3Strlen30(zCsr);
84749 for(i=0; i<25 && i<pMem->n; i++){
84750 sqlite3_snprintf(100, zCsr, "%02X", ((int)pMem->z[i] & 0xFF));
84751 zCsr += sqlite3Strlen30(zCsr);
84752 }
84753 *zCsr++ = '|';
84754 for(i=0; i<25 && i<pMem->n; i++){
84755 char z = pMem->z[i];
84756 if( z<32 || z>126 ) *zCsr++ = '.';
84757 else *zCsr++ = z;
84758 }
84759 *(zCsr++) = ']';
84760 if( f & MEM_Zero ){
84761 sqlite3_snprintf(100, zCsr,"+%dz",pMem->u.nZero);
84762 zCsr += sqlite3Strlen30(zCsr);
84763 }
84764 *zCsr = '\0';
84765 }else if( f & MEM_Str ){
84766 int j, k;
84767 zBuf[0] = ' ';
84768 if( f & MEM_Dyn ){
84769 zBuf[1] = 'z';
84770 assert( (f & (MEM_Static|MEM_Ephem))==0 );
84771 }else if( f & MEM_Static ){
84772 zBuf[1] = 't';
84773 assert( (f & (MEM_Dyn|MEM_Ephem))==0 );
84774 }else if( f & MEM_Ephem ){
84775 zBuf[1] = 'e';
84776 assert( (f & (MEM_Static|MEM_Dyn))==0 );
84777 }else{
84778 zBuf[1] = 's';
84779 }
84780 k = 2;
84781 sqlite3_snprintf(100, &zBuf[k], "%d", pMem->n);
84782 k += sqlite3Strlen30(&zBuf[k]);
84783 zBuf[k++] = '[';
84784 for(j=0; j<25 && j<pMem->n; j++){
84785 u8 c = pMem->z[j];
84786 if( c>=0x20 && c<0x7f ){
84787 zBuf[k++] = c;
84788 }else{
84789 zBuf[k++] = '.';
84790 }
84791 }
84792 zBuf[k++] = ']';
84793 sqlite3_snprintf(100,&zBuf[k], encnames[pMem->enc]);
84794 k += sqlite3Strlen30(&zBuf[k]);
84795 zBuf[k++] = 0;
84796 }
84797 }
84798 #endif
84799
84800 #ifdef SQLITE_DEBUG
@@ -84817,23 +85130,40 @@
84817 printf(" r:%.17g", p->u.r);
84818 #endif
84819 }else if( sqlite3VdbeMemIsRowSet(p) ){
84820 printf(" (rowset)");
84821 }else{
84822 char zBuf[200];
84823 sqlite3VdbeMemPrettyPrint(p, zBuf);
84824 printf(" %s", zBuf);
 
 
84825 }
84826 if( p->flags & MEM_Subtype ) printf(" subtype=0x%02x", p->eSubtype);
84827 }
84828 static void registerTrace(int iReg, Mem *p){
84829 printf("REG[%d] = ", iReg);
84830 memTracePrint(p);
 
 
 
84831 printf("\n");
84832 sqlite3VdbeCheckMemInvariants(p);
84833 }
84834 #endif
 
 
 
 
 
 
 
 
 
 
 
 
84835
84836 #ifdef SQLITE_DEBUG
84837 # define REGISTER_TRACE(R,M) if(db->flags&SQLITE_VdbeTrace)registerTrace(R,M)
84838 #else
84839 # define REGISTER_TRACE(R,M)
@@ -85085,10 +85415,11 @@
85085 /* Only allow tracing if SQLITE_DEBUG is defined.
85086 */
85087 #ifdef SQLITE_DEBUG
85088 if( db->flags & SQLITE_VdbeTrace ){
85089 sqlite3VdbePrintOp(stdout, (int)(pOp - aOp), pOp);
 
85090 }
85091 #endif
85092
85093
85094 /* Check to see if we need to simulate an interrupt. This only happens
@@ -85192,10 +85523,24 @@
85192 ** is sometimes set to 1 instead of 0 as a hint to the command-line shell
85193 ** that this Goto is the bottom of a loop and that the lines from P2 down
85194 ** to the current line should be indented for EXPLAIN output.
85195 */
85196 case OP_Goto: { /* jump */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85197 jump_to_p2_and_check_for_interrupt:
85198 pOp = &aOp[pOp->p2 - 1];
85199
85200 /* Opcodes that are used as the bottom of a loop (OP_Next, OP_Prev,
85201 ** OP_VNext, or OP_SorterNext) all jump here upon
@@ -85668,12 +86013,17 @@
85668 assert( pIn1<=&aMem[(p->nMem+1 - p->nCursor)] );
85669 assert( memIsValid(pIn1) );
85670 memAboutToChange(p, pOut);
85671 sqlite3VdbeMemMove(pOut, pIn1);
85672 #ifdef SQLITE_DEBUG
85673 if( pOut->pScopyFrom>=&aMem[p1] && pOut->pScopyFrom<pOut ){
85674 pOut->pScopyFrom += pOp->p2 - p1;
 
 
 
 
 
85675 }
85676 #endif
85677 Deephemeralize(pOut);
85678 REGISTER_TRACE(p2++, pOut);
85679 pIn1++;
@@ -85810,16 +86160,25 @@
85810 Deephemeralize(&pMem[i]);
85811 assert( (pMem[i].flags & MEM_Ephem)==0
85812 || (pMem[i].flags & (MEM_Str|MEM_Blob))==0 );
85813 sqlite3VdbeMemNulTerminate(&pMem[i]);
85814 REGISTER_TRACE(pOp->p1+i, &pMem[i]);
 
 
 
 
 
 
 
 
85815 }
85816 if( db->mallocFailed ) goto no_mem;
85817
85818 if( db->mTrace & SQLITE_TRACE_ROW ){
85819 db->xTrace(SQLITE_TRACE_ROW, db->pTraceArg, p, 0);
85820 }
 
85821
85822 /* Return SQLITE_ROW
85823 */
85824 p->pc = (int)(pOp - aOp) + 1;
85825 rc = SQLITE_ROW;
@@ -87132,14 +87491,15 @@
87132 ** So we might as well use bogus content rather than reading
87133 ** content from disk.
87134 **
87135 ** Although sqlite3VdbeSerialGet() may read at most 8 bytes from the
87136 ** buffer passed to it, debugging function VdbeMemPrettyPrint() may
87137 ** read up to 16. So 16 bytes of bogus content is supplied.
 
 
87138 */
87139 static u8 aZero[16]; /* This is the bogus content */
87140 sqlite3VdbeSerialGet(aZero, t, pDest);
87141 }else{
87142 rc = sqlite3VdbeMemFromBtree(pC->uc.pCursor, aOffset[p2], len, pDest);
87143 if( rc!=SQLITE_OK ) goto abort_due_to_error;
87144 sqlite3VdbeSerialGet((const u8*)pDest->z, t, pDest);
87145 pDest->flags &= ~MEM_Ephem;
@@ -88657,11 +89017,11 @@
88657
88658 /* Opcode: SeekHit P1 P2 * * *
88659 ** Synopsis: seekHit=P2
88660 **
88661 ** Set the seekHit flag on cursor P1 to the value in P2.
88662 ** The seekHit flag is used by the IfNoHope opcode.
88663 **
88664 ** P1 must be a valid b-tree cursor. P2 must be a boolean value,
88665 ** either 0 or 1.
88666 */
88667 case OP_SeekHit: {
@@ -88671,10 +89031,24 @@
88671 assert( pC!=0 );
88672 assert( pOp->p2==0 || pOp->p2==1 );
88673 pC->seekHit = pOp->p2 & 1;
88674 break;
88675 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88676
88677 /* Opcode: Found P1 P2 P3 P4 *
88678 ** Synopsis: key=r[P3@P4]
88679 **
88680 ** If P4==0 then register P3 holds a blob constructed by MakeRecord. If
@@ -89160,10 +89534,11 @@
89160 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
89161 assert( memIsValid(pData) );
89162 pC = p->apCsr[pOp->p1];
89163 assert( pC!=0 );
89164 assert( pC->eCurType==CURTYPE_BTREE );
 
89165 assert( pC->uc.pCursor!=0 );
89166 assert( (pOp->p5 & OPFLAG_ISNOOP) || pC->isTable );
89167 assert( pOp->p4type==P4_TABLE || pOp->p4type>=P4_STATIC );
89168 REGISTER_TRACE(pOp->p2, pData);
89169 sqlite3VdbeIncrWriteCounter(p, pC);
@@ -89277,11 +89652,15 @@
89277 assert( pC->uc.pCursor!=0 );
89278 assert( pC->deferredMoveto==0 );
89279 sqlite3VdbeIncrWriteCounter(p, pC);
89280
89281 #ifdef SQLITE_DEBUG
89282 if( pOp->p4type==P4_TABLE && HasRowid(pOp->p4.pTab) && pOp->p5==0 ){
 
 
 
 
89283 /* If p5 is zero, the seek operation that positioned the cursor prior to
89284 ** OP_Delete will have also set the pC->movetoTarget field to the rowid of
89285 ** the row that is being deleted */
89286 i64 iKey = sqlite3BtreeIntegerKey(pC->uc.pCursor);
89287 assert( CORRUPT_DB || pC->movetoTarget==iKey );
@@ -90032,10 +90411,28 @@
90032 assert( pOp->opcode==OP_IdxRowid );
90033 sqlite3VdbeMemSetNull(&aMem[pOp->p2]);
90034 }
90035 break;
90036 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90037
90038 /* Opcode: IdxGE P1 P2 P3 P4 P5
90039 ** Synopsis: key=r[P3@P4]
90040 **
90041 ** The P4 register values beginning with P3 form an unpacked index
@@ -91338,10 +91735,40 @@
91338 }else{
91339 p->expired = pOp->p2+1;
91340 }
91341 break;
91342 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91343
91344 #ifndef SQLITE_OMIT_SHARED_CACHE
91345 /* Opcode: TableLock P1 P2 P3 P4 *
91346 ** Synopsis: iDb=P1 root=P2 write=P3
91347 **
@@ -92045,11 +92472,11 @@
92045 break;
92046 }
92047 #endif
92048
92049 #ifdef SQLITE_DEBUG
92050 /* Opcode: ReleaseReg P1 P2 P3 * *
92051 ** Synopsis: release r[P1@P2] mask P3
92052 **
92053 ** Release registers from service. Any content that was in the
92054 ** the registers is unreliable after this opcode completes.
92055 **
@@ -92060,14 +92487,16 @@
92060 ** Releasing a register clears the Mem.pScopyFrom pointer. That means
92061 ** that if the content of the released register was set using OP_SCopy,
92062 ** a change to the value of the source register for the OP_SCopy will no longer
92063 ** generate an assertion fault in sqlite3VdbeMemAboutToChange().
92064 **
92065 ** TODO: Released registers ought to also have their datatype set to
92066 ** MEM_Undefined so that any subsequent attempt to read the released
92067 ** register (before it is reinitialized) will generate an assertion fault.
92068 ** However, there are places in the code generator which release registers
 
 
92069 ** before their are used, under the (valid) assumption that the registers
92070 ** will not be reallocated for some other purpose before they are used and
92071 ** hence are safe to release.
92072 **
92073 ** This opcode is only available in testing and debugging builds. It is
@@ -92084,11 +92513,11 @@
92084 pMem = &aMem[pOp->p1];
92085 constMask = pOp->p3;
92086 for(i=0; i<pOp->p2; i++, pMem++){
92087 if( i>=32 || (constMask & MASKBIT32(i))==0 ){
92088 pMem->pScopyFrom = 0;
92089 /* MemSetTypeFlag(pMem, MEM_Undefined); // See the TODO */
92090 }
92091 }
92092 break;
92093 }
92094 #endif
@@ -92142,10 +92571,16 @@
92142 registerTrace(pOrigOp->p2, &aMem[pOrigOp->p2]);
92143 }
92144 if( opProperty & OPFLG_OUT3 ){
92145 registerTrace(pOrigOp->p3, &aMem[pOrigOp->p3]);
92146 }
 
 
 
 
 
 
92147 }
92148 #endif /* SQLITE_DEBUG */
92149 #endif /* NDEBUG */
92150 } /* The end of the for(;;) loop the loops through opcodes */
92151
@@ -96270,17 +96705,20 @@
96270 ** result sets in ExprList.a[].zSpan, in the form "DATABASE.TABLE.COLUMN".
96271 ** Check to see if the zSpan given to this routine matches the zDb, zTab,
96272 ** and zCol. If any of zDb, zTab, and zCol are NULL then those fields will
96273 ** match anything.
96274 */
96275 SQLITE_PRIVATE int sqlite3MatchSpanName(
96276 const char *zSpan,
96277 const char *zCol,
96278 const char *zTab,
96279 const char *zDb
96280 ){
96281 int n;
 
 
 
96282 for(n=0; ALWAYS(zSpan[n]) && zSpan[n]!='.'; n++){}
96283 if( zDb && (sqlite3StrNICmp(zSpan, zDb, n)!=0 || zDb[n]!=0) ){
96284 return 0;
96285 }
96286 zSpan += n+1;
@@ -96405,11 +96843,11 @@
96405 assert( pTab->nCol>0 );
96406 if( pItem->pSelect && (pItem->pSelect->selFlags & SF_NestedFrom)!=0 ){
96407 int hit = 0;
96408 pEList = pItem->pSelect->pEList;
96409 for(j=0; j<pEList->nExpr; j++){
96410 if( sqlite3MatchSpanName(pEList->a[j].zSpan, zCol, zTab, zDb) ){
96411 cnt++;
96412 cntTab = 2;
96413 pMatch = pItem;
96414 pExpr->iColumn = j;
96415 hit = 1;
@@ -96586,22 +97024,26 @@
96586 && zTab==0
96587 ){
96588 pEList = pNC->uNC.pEList;
96589 assert( pEList!=0 );
96590 for(j=0; j<pEList->nExpr; j++){
96591 char *zAs = pEList->a[j].zName;
96592 if( zAs!=0 && sqlite3StrICmp(zAs, zCol)==0 ){
 
 
96593 Expr *pOrig;
96594 assert( pExpr->pLeft==0 && pExpr->pRight==0 );
96595 assert( pExpr->x.pList==0 );
96596 assert( pExpr->x.pSelect==0 );
96597 pOrig = pEList->a[j].pExpr;
96598 if( (pNC->ncFlags&NC_AllowAgg)==0 && ExprHasProperty(pOrig, EP_Agg) ){
96599 sqlite3ErrorMsg(pParse, "misuse of aliased aggregate %s", zAs);
96600 return WRC_Abort;
96601 }
96602 if( (pNC->ncFlags&NC_AllowWin)==0 && ExprHasProperty(pOrig, EP_Win) ){
 
 
96603 sqlite3ErrorMsg(pParse, "misuse of aliased window function %s",zAs);
96604 return WRC_Abort;
96605 }
96606 if( sqlite3ExprVectorSize(pOrig)!=1 ){
96607 sqlite3ErrorMsg(pParse, "row value misused");
@@ -97007,28 +97449,27 @@
97007 sqlite3ResolveNotValid(pParse, pNC, "non-deterministic functions",
97008 NC_SelfRef, 0);
97009 }else{
97010 assert( (NC_SelfRef & 0xff)==NC_SelfRef ); /* Must fit in 8 bits */
97011 pExpr->op2 = pNC->ncFlags & NC_SelfRef;
 
97012 }
97013 if( (pDef->funcFlags & SQLITE_FUNC_INTERNAL)!=0
97014 && pParse->nested==0
97015 && sqlite3Config.bInternalFunctions==0
97016 ){
97017 /* Internal-use-only functions are disallowed unless the
97018 ** SQL is being compiled using sqlite3NestedParse() */
 
 
97019 no_such_func = 1;
97020 pDef = 0;
97021 }else
97022 if( (pDef->funcFlags & SQLITE_FUNC_DIRECT)!=0
97023 && ExprHasProperty(pExpr, EP_Indirect)
97024 && !IN_RENAME_OBJECT
97025 ){
97026 /* Functions tagged with SQLITE_DIRECTONLY may not be used
97027 ** inside of triggers and views */
97028 sqlite3ErrorMsg(pParse, "%s() prohibited in triggers and views",
97029 pDef->zName);
97030 }
97031 }
97032
97033 if( 0==IN_RENAME_OBJECT ){
97034 #ifndef SQLITE_OMIT_WINDOWFUNC
@@ -97253,12 +97694,13 @@
97253 UNUSED_PARAMETER(pParse);
97254
97255 if( pE->op==TK_ID ){
97256 char *zCol = pE->u.zToken;
97257 for(i=0; i<pEList->nExpr; i++){
97258 char *zAs = pEList->a[i].zName;
97259 if( zAs!=0 && sqlite3StrICmp(zAs, zCol)==0 ){
 
97260 return i+1;
97261 }
97262 }
97263 }
97264 return 0;
@@ -98015,10 +98457,15 @@
98015 if( pTab ){
98016 sSrc.nSrc = 1;
98017 sSrc.a[0].zName = pTab->zName;
98018 sSrc.a[0].pTab = pTab;
98019 sSrc.a[0].iCursor = -1;
 
 
 
 
 
98020 }
98021 sNC.pParse = pParse;
98022 sNC.pSrcList = &sSrc;
98023 sNC.ncFlags = type | NC_IsDDL;
98024 if( (rc = sqlite3ResolveExprNames(&sNC, pExpr))!=SQLITE_OK ) return rc;
@@ -98961,13 +99408,15 @@
98961 sqlite3 *db = pParse->db;
98962 if( pLeft==0 ){
98963 return pRight;
98964 }else if( pRight==0 ){
98965 return pLeft;
98966 }else if( ExprAlwaysFalse(pLeft) || ExprAlwaysFalse(pRight) ){
98967 sqlite3ExprUnmapAndDelete(pParse, pLeft);
98968 sqlite3ExprUnmapAndDelete(pParse, pRight);
 
 
98969 return sqlite3Expr(db, TK_INTEGER, "0");
98970 }else{
98971 return sqlite3PExpr(pParse, TK_AND, pLeft, pRight);
98972 }
98973 }
@@ -98998,10 +99447,44 @@
98998 assert( !ExprHasProperty(pNew, EP_xIsSelect) );
98999 sqlite3ExprSetHeightAndFlags(pParse, pNew);
99000 if( eDistinct==SF_Distinct ) ExprSetProperty(pNew, EP_Distinct);
99001 return pNew;
99002 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99003
99004 /*
99005 ** Assign a variable number to an expression that encodes a wildcard
99006 ** in the original SQL statement.
99007 **
@@ -99466,16 +99949,15 @@
99466 assert( pNewExpr->iColumn==pItem[-1].pExpr->iColumn+1 );
99467 assert( pPriorSelectCol==pItem[-1].pExpr->pLeft );
99468 pNewExpr->pLeft = pPriorSelectCol;
99469 }
99470 }
99471 pItem->zName = sqlite3DbStrDup(db, pOldItem->zName);
99472 pItem->zSpan = sqlite3DbStrDup(db, pOldItem->zSpan);
99473 pItem->sortFlags = pOldItem->sortFlags;
 
99474 pItem->done = 0;
99475 pItem->bNulls = pOldItem->bNulls;
99476 pItem->bSpanIsTab = pOldItem->bSpanIsTab;
99477 pItem->bSorterRef = pOldItem->bSorterRef;
99478 pItem->u = pOldItem->u;
99479 }
99480 return pNew;
99481 }
@@ -99638,13 +100120,13 @@
99638 goto no_mem;
99639 }
99640 pList = pNew;
99641 }
99642 pItem = &pList->a[pList->nExpr++];
99643 assert( offsetof(struct ExprList_item,zName)==sizeof(pItem->pExpr) );
99644 assert( offsetof(struct ExprList_item,pExpr)==0 );
99645 memset(&pItem->zName,0,sizeof(*pItem)-offsetof(struct ExprList_item,zName));
99646 pItem->pExpr = pExpr;
99647 return pList;
99648
99649 no_mem:
99650 /* Avoid leaking memory if malloc has failed. */
@@ -99697,11 +100179,11 @@
99697 if( pSubExpr==0 ) continue;
99698 pSubExpr->iTable = pColumns->nId;
99699 pList = sqlite3ExprListAppend(pParse, pList, pSubExpr);
99700 if( pList ){
99701 assert( pList->nExpr==iFirst+i+1 );
99702 pList->a[pList->nExpr-1].zName = pColumns->a[i].zName;
99703 pColumns->a[i].zName = 0;
99704 }
99705 }
99706
99707 if( !db->mallocFailed && pExpr->op==TK_SELECT && ALWAYS(pList!=0) ){
@@ -99757,11 +100239,11 @@
99757 }
99758 }
99759 }
99760
99761 /*
99762 ** Set the ExprList.a[].zName element of the most recently added item
99763 ** on the expression list.
99764 **
99765 ** pList might be NULL following an OOM error. But pName should never be
99766 ** NULL. If a memory allocation fails, the pParse->db->mallocFailed flag
99767 ** is set.
@@ -99775,15 +100257,16 @@
99775 assert( pList!=0 || pParse->db->mallocFailed!=0 );
99776 if( pList ){
99777 struct ExprList_item *pItem;
99778 assert( pList->nExpr>0 );
99779 pItem = &pList->a[pList->nExpr-1];
99780 assert( pItem->zName==0 );
99781 pItem->zName = sqlite3DbStrNDup(pParse->db, pName->z, pName->n);
99782 if( dequote ) sqlite3Dequote(pItem->zName);
 
99783 if( IN_RENAME_OBJECT ){
99784 sqlite3RenameTokenMap(pParse, (void*)pItem->zName, pName);
99785 }
99786 }
99787 }
99788
99789 /*
@@ -99803,12 +100286,14 @@
99803 sqlite3 *db = pParse->db;
99804 assert( pList!=0 || db->mallocFailed!=0 );
99805 if( pList ){
99806 struct ExprList_item *pItem = &pList->a[pList->nExpr-1];
99807 assert( pList->nExpr>0 );
99808 sqlite3DbFree(db, pItem->zSpan);
99809 pItem->zSpan = sqlite3DbSpanDup(db, zStart, zEnd);
 
 
99810 }
99811 }
99812
99813 /*
99814 ** If the expression list pEList contains more than iLimit elements,
@@ -99834,12 +100319,11 @@
99834 int i = pList->nExpr;
99835 struct ExprList_item *pItem = pList->a;
99836 assert( pList->nExpr>0 );
99837 do{
99838 sqlite3ExprDelete(db, pItem->pExpr);
99839 sqlite3DbFree(db, pItem->zName);
99840 sqlite3DbFree(db, pItem->zSpan);
99841 pItem++;
99842 }while( --i>0 );
99843 sqlite3DbFreeNN(db, pList);
99844 }
99845 SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3 *db, ExprList *pList){
@@ -99872,24 +100356,39 @@
99872 SQLITE_PRIVATE int sqlite3SelectWalkFail(Walker *pWalker, Select *NotUsed){
99873 UNUSED_PARAMETER(NotUsed);
99874 pWalker->eCode = 0;
99875 return WRC_Abort;
99876 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99877
99878 /*
99879 ** If the input expression is an ID with the name "true" or "false"
99880 ** then convert it into an TK_TRUEFALSE term. Return non-zero if
99881 ** the conversion happened, and zero if the expression is unaltered.
99882 */
99883 SQLITE_PRIVATE int sqlite3ExprIdToTrueFalse(Expr *pExpr){
 
99884 assert( pExpr->op==TK_ID || pExpr->op==TK_STRING );
99885 if( !ExprHasProperty(pExpr, EP_Quoted)
99886 && (sqlite3StrICmp(pExpr->u.zToken, "true")==0
99887 || sqlite3StrICmp(pExpr->u.zToken, "false")==0)
99888 ){
99889 pExpr->op = TK_TRUEFALSE;
99890 ExprSetProperty(pExpr, pExpr->u.zToken[4]==0 ? EP_IsTrue : EP_IsFalse);
99891 return 1;
99892 }
99893 return 0;
99894 }
99895
@@ -99947,14 +100446,15 @@
99947 ** sqlite3ExprIsConstantOrFunction() pWalker->eCode==4 or 5
99948 **
99949 ** In all cases, the callbacks set Walker.eCode=0 and abort if the expression
99950 ** is found to not be a constant.
99951 **
99952 ** The sqlite3ExprIsConstantOrFunction() is used for evaluating expressions
99953 ** in a CREATE TABLE statement. The Walker.eCode value is 5 when parsing
99954 ** an existing schema and 4 when processing a new statement. A bound
99955 ** parameter raises an error for new statements, but is silently converted
 
99956 ** to NULL for existing schemas. This allows sqlite_master tables that
99957 ** contain a bound parameter because they were generated by older versions
99958 ** of SQLite to be parsed by newer versions of SQLite without raising a
99959 ** malformed schema error.
99960 */
@@ -99974,10 +100474,11 @@
99974 ** SQLITE_FUNC_CONST flag. */
99975 case TK_FUNCTION:
99976 if( (pWalker->eCode>=4 || ExprHasProperty(pExpr,EP_ConstFunc))
99977 && !ExprHasProperty(pExpr, EP_WinFunc)
99978 ){
 
99979 return WRC_Continue;
99980 }else{
99981 pWalker->eCode = 0;
99982 return WRC_Abort;
99983 }
@@ -100137,13 +100638,25 @@
100137 sqlite3WalkExpr(&w, p);
100138 return w.eCode;
100139 }
100140
100141 /*
100142 ** Walk an expression tree. Return non-zero if the expression is constant
100143 ** or a function call with constant arguments. Return and 0 if there
100144 ** are any variables.
 
 
 
 
 
 
 
 
 
 
 
 
100145 **
100146 ** For the purposes of this function, a double-quoted string (ex: "abc")
100147 ** is considered a variable but a single-quoted string (ex: 'abc') is
100148 ** a constant.
100149 */
@@ -101219,10 +101732,11 @@
101219 r2 = sqlite3ExprCodeTemp(pParse, pList->a[ii].pExpr, &regToFree);
101220 }
101221 if( regCkNull && sqlite3ExprCanBeNull(pList->a[ii].pExpr) ){
101222 sqlite3VdbeAddOp3(v, OP_BitAnd, regCkNull, r2, regCkNull);
101223 }
 
101224 if( ii<pList->nExpr-1 || destIfNull!=destIfFalse ){
101225 int op = rLhs!=r2 ? OP_Eq : OP_NotNull;
101226 sqlite3VdbeAddOp4(v, op, rLhs, labelOk, r2,
101227 (void*)pColl, P4_COLLSEQ);
101228 VdbeCoverageIf(v, ii<pList->nExpr-1 && op==OP_Eq);
@@ -101237,11 +101751,10 @@
101237 (void*)pColl, P4_COLLSEQ);
101238 VdbeCoverageIf(v, op==OP_Ne);
101239 VdbeCoverageIf(v, op==OP_IsNull);
101240 sqlite3VdbeChangeP5(v, zAff[0] | SQLITE_JUMPIFNULL);
101241 }
101242 sqlite3ReleaseTempReg(pParse, regToFree);
101243 }
101244 if( regCkNull ){
101245 sqlite3VdbeAddOp2(v, OP_IsNull, regCkNull, destIfNull); VdbeCoverage(v);
101246 sqlite3VdbeGoto(v, destIfFalse);
101247 }
@@ -101598,10 +102111,113 @@
101598 }
101599 }
101600 }
101601 return iResult;
101602 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
101603
101604
101605 /*
101606 ** Generate code into the current Vdbe to evaluate the given
101607 ** expression. Attempt to store the results in register "target".
@@ -101979,51 +102595,18 @@
101979 #endif
101980 if( pDef==0 || pDef->xFinalize!=0 ){
101981 sqlite3ErrorMsg(pParse, "unknown function: %s()", zId);
101982 break;
101983 }
101984
101985 /* Attempt a direct implementation of the built-in COALESCE() and
101986 ** IFNULL() functions. This avoids unnecessary evaluation of
101987 ** arguments past the first non-NULL argument.
101988 */
101989 if( pDef->funcFlags & SQLITE_FUNC_COALESCE ){
101990 int endCoalesce = sqlite3VdbeMakeLabel(pParse);
101991 assert( nFarg>=2 );
101992 sqlite3ExprCode(pParse, pFarg->a[0].pExpr, target);
101993 for(i=1; i<nFarg; i++){
101994 sqlite3VdbeAddOp2(v, OP_NotNull, target, endCoalesce);
101995 VdbeCoverage(v);
101996 sqlite3ExprCode(pParse, pFarg->a[i].pExpr, target);
101997 }
101998 sqlite3VdbeResolveLabel(v, endCoalesce);
101999 break;
102000 }
102001
102002 /* The UNLIKELY() function is a no-op. The result is the value
102003 ** of the first argument.
102004 */
102005 if( pDef->funcFlags & SQLITE_FUNC_UNLIKELY ){
102006 assert( nFarg>=1 );
102007 return sqlite3ExprCodeTarget(pParse, pFarg->a[0].pExpr, target);
102008 }
102009
102010 #ifdef SQLITE_DEBUG
102011 /* The AFFINITY() function evaluates to a string that describes
102012 ** the type affinity of the argument. This is used for testing of
102013 ** the SQLite type logic.
102014 */
102015 if( pDef->funcFlags & SQLITE_FUNC_AFFINITY ){
102016 const char *azAff[] = { "blob", "text", "numeric", "integer", "real" };
102017 char aff;
102018 assert( nFarg==1 );
102019 aff = sqlite3ExprAffinity(pFarg->a[0].pExpr);
102020 sqlite3VdbeLoadString(v, target,
102021 (aff<=SQLITE_AFF_NONE) ? "none" : azAff[aff-SQLITE_AFF_BLOB]);
102022 return target;
102023 }
102024 #endif
102025
102026 for(i=0; i<nFarg; i++){
102027 if( i<32 && sqlite3ExprIsConstant(pFarg->a[i].pExpr) ){
102028 testcase( i==31 );
102029 constMask |= MASKBIT32(i);
@@ -102103,11 +102686,11 @@
102103 }
102104 if( nFarg ){
102105 if( constMask==0 ){
102106 sqlite3ReleaseTempRange(pParse, r1, nFarg);
102107 }else{
102108 sqlite3VdbeReleaseRegisters(pParse, r1, nFarg, constMask);
102109 }
102110 }
102111 return target;
102112 }
102113 #ifndef SQLITE_OMIT_SUBQUERY
@@ -102455,11 +103038,17 @@
102455
102456 assert( target>0 && target<=pParse->nMem );
102457 inReg = sqlite3ExprCodeTarget(pParse, pExpr, target);
102458 assert( pParse->pVdbe!=0 || pParse->db->mallocFailed );
102459 if( inReg!=target && pParse->pVdbe ){
102460 sqlite3VdbeAddOp2(pParse->pVdbe, OP_SCopy, inReg, target);
 
 
 
 
 
 
102461 }
102462 }
102463
102464 /*
102465 ** Make a transient copy of expression pExpr and then code it using
@@ -102548,10 +103137,11 @@
102548 VdbeOp *pOp;
102549 if( copyOp==OP_Copy
102550 && (pOp=sqlite3VdbeGetOp(v, -1))->opcode==OP_Copy
102551 && pOp->p1+pOp->p3+1==inReg
102552 && pOp->p2+pOp->p3+1==target+i
 
102553 ){
102554 pOp->p3++;
102555 }else{
102556 sqlite3VdbeAddOp2(v, copyOp, inReg, target+i);
102557 }
@@ -103120,12 +103710,13 @@
103120 }
103121 return 0;
103122 }
103123
103124 /*
103125 ** Compare two ExprList objects. Return 0 if they are identical and
103126 ** non-zero if they differ in any way.
 
103127 **
103128 ** If any subelement of pB has Expr.iTable==(-1) then it is allowed
103129 ** to compare equal to an equivalent element in pA with Expr.iTable==iTab.
103130 **
103131 ** This routine might return non-zero for equivalent ExprLists. The
@@ -103140,14 +103731,15 @@
103140 int i;
103141 if( pA==0 && pB==0 ) return 0;
103142 if( pA==0 || pB==0 ) return 1;
103143 if( pA->nExpr!=pB->nExpr ) return 1;
103144 for(i=0; i<pA->nExpr; i++){
 
103145 Expr *pExprA = pA->a[i].pExpr;
103146 Expr *pExprB = pB->a[i].pExpr;
103147 if( pA->a[i].sortFlags!=pB->a[i].sortFlags ) return 1;
103148 if( sqlite3ExprCompare(0, pExprA, pExprB, iTab) ) return 1;
103149 }
103150 return 0;
103151 }
103152
103153 /*
@@ -103322,15 +103914,16 @@
103322 return WRC_Abort;
103323 }
103324 return WRC_Prune;
103325
103326 case TK_AND:
103327 assert( pWalker->eCode==0 );
103328 sqlite3WalkExpr(pWalker, pExpr->pLeft);
103329 if( pWalker->eCode ){
103330 pWalker->eCode = 0;
103331 sqlite3WalkExpr(pWalker, pExpr->pRight);
 
103332 }
103333 return WRC_Prune;
103334
103335 case TK_BETWEEN:
103336 if( sqlite3WalkExpr(pWalker, pExpr->pLeft)==WRC_Abort ){
@@ -103477,16 +104070,17 @@
103477
103478 /*
103479 ** Count the number of references to columns.
103480 */
103481 static int exprSrcCount(Walker *pWalker, Expr *pExpr){
103482 /* The NEVER() on the second term is because sqlite3FunctionUsesThisSrc()
103483 ** is always called before sqlite3ExprAnalyzeAggregates() and so the
103484 ** TK_COLUMNs have not yet been converted into TK_AGG_COLUMN. If
103485 ** sqlite3FunctionUsesThisSrc() is used differently in the future, the
103486 ** NEVER() will need to be removed. */
103487 if( pExpr->op==TK_COLUMN || NEVER(pExpr->op==TK_AGG_COLUMN) ){
 
103488 int i;
103489 struct SrcCount *p = pWalker->u.pSrcCount;
103490 SrcList *pSrc = p->pSrc;
103491 int nSrc = pSrc ? pSrc->nSrc : 0;
103492 for(i=0; i<nSrc; i++){
@@ -103520,10 +104114,15 @@
103520 w.u.pSrcCount = &cnt;
103521 cnt.pSrc = pSrcList;
103522 cnt.nThis = 0;
103523 cnt.nOther = 0;
103524 sqlite3WalkExprList(&w, pExpr->x.pList);
 
 
 
 
 
103525 return cnt.nThis>0 || cnt.nOther==0;
103526 }
103527
103528 /*
103529 ** Add a new element to the pAggInfo->aCol[] array. Return the index of
@@ -103749,11 +104348,11 @@
103749 ** Deallocate a register, making available for reuse for some other
103750 ** purpose.
103751 */
103752 SQLITE_PRIVATE void sqlite3ReleaseTempReg(Parse *pParse, int iReg){
103753 if( iReg ){
103754 sqlite3VdbeReleaseRegisters(pParse, iReg, 1, 0);
103755 if( pParse->nTempReg<ArraySize(pParse->aTempReg) ){
103756 pParse->aTempReg[pParse->nTempReg++] = iReg;
103757 }
103758 }
103759 }
@@ -103778,11 +104377,11 @@
103778 SQLITE_PRIVATE void sqlite3ReleaseTempRange(Parse *pParse, int iReg, int nReg){
103779 if( nReg==1 ){
103780 sqlite3ReleaseTempReg(pParse, iReg);
103781 return;
103782 }
103783 sqlite3VdbeReleaseRegisters(pParse, iReg, nReg, 0);
103784 if( nReg>pParse->nRangeReg ){
103785 pParse->nRangeReg = nReg;
103786 pParse->iRangeReg = iReg;
103787 }
103788 }
@@ -104591,12 +105190,12 @@
104591 if( pParse->nErr ) return WRC_Abort;
104592 if( NEVER(p->selFlags & SF_View) ) return WRC_Prune;
104593 if( ALWAYS(p->pEList) ){
104594 ExprList *pList = p->pEList;
104595 for(i=0; i<pList->nExpr; i++){
104596 if( pList->a[i].zName ){
104597 sqlite3RenameTokenRemap(pParse, 0, (void*)pList->a[i].zName);
104598 }
104599 }
104600 }
104601 if( ALWAYS(p->pSrc) ){ /* Every Select as a SrcList, even if it is empty */
104602 SrcList *pSrc = p->pSrc;
@@ -104636,11 +105235,13 @@
104636 memset(&sWalker, 0, sizeof(Walker));
104637 sWalker.pParse = pParse;
104638 sWalker.xExprCallback = renameUnmapExprCb;
104639 sqlite3WalkExprList(&sWalker, pEList);
104640 for(i=0; i<pEList->nExpr; i++){
104641 sqlite3RenameTokenRemap(pParse, 0, (void*)pEList->a[i].zName);
 
 
104642 }
104643 }
104644 }
104645
104646 /*
@@ -104774,12 +105375,15 @@
104774 const char *zOld
104775 ){
104776 if( pEList ){
104777 int i;
104778 for(i=0; i<pEList->nExpr; i++){
104779 char *zName = pEList->a[i].zName;
104780 if( 0==sqlite3_stricmp(zName, zOld) ){
 
 
 
104781 renameTokenFind(pParse, pCtx, (void*)zName);
104782 }
104783 }
104784 }
104785 }
@@ -107879,11 +108483,11 @@
107879 pFix->pParse = pParse;
107880 pFix->zDb = db->aDb[iDb].zDbSName;
107881 pFix->pSchema = db->aDb[iDb].pSchema;
107882 pFix->zType = zType;
107883 pFix->pName = pName;
107884 pFix->bVarOnly = (iDb==1);
107885 }
107886
107887 /*
107888 ** The following set of routines walk through the parse tree and assign
107889 ** a specific database to all table references where the database name
@@ -107907,20 +108511,21 @@
107907 struct SrcList_item *pItem;
107908
107909 if( NEVER(pList==0) ) return 0;
107910 zDb = pFix->zDb;
107911 for(i=0, pItem=pList->a; i<pList->nSrc; i++, pItem++){
107912 if( pFix->bVarOnly==0 ){
107913 if( pItem->zDatabase && sqlite3StrICmp(pItem->zDatabase, zDb) ){
107914 sqlite3ErrorMsg(pFix->pParse,
107915 "%s %T cannot reference objects in database %s",
107916 pFix->zType, pFix->pName, pItem->zDatabase);
107917 return 1;
107918 }
107919 sqlite3DbFree(pFix->pParse->db, pItem->zDatabase);
107920 pItem->zDatabase = 0;
107921 pItem->pSchema = pFix->pSchema;
 
107922 }
107923 #if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_TRIGGER)
107924 if( sqlite3FixSelect(pFix, pItem->pSelect) ) return 1;
107925 if( sqlite3FixExpr(pFix, pItem->pOn) ) return 1;
107926 #endif
@@ -107972,11 +108577,11 @@
107972 SQLITE_PRIVATE int sqlite3FixExpr(
107973 DbFixer *pFix, /* Context of the fixation */
107974 Expr *pExpr /* The expression to be fixed to one database */
107975 ){
107976 while( pExpr ){
107977 ExprSetProperty(pExpr, EP_Indirect);
107978 if( pExpr->op==TK_VARIABLE ){
107979 if( pFix->pParse->db->init.busy ){
107980 pExpr->op = TK_NULL;
107981 }else{
107982 sqlite3ErrorMsg(pFix->pParse, "%s cannot use variables", pFix->zType);
@@ -109727,12 +110332,13 @@
109727 Table *p;
109728 Column *pCol;
109729 sqlite3 *db = pParse->db;
109730 p = pParse->pNewTable;
109731 if( p!=0 ){
 
109732 pCol = &(p->aCol[p->nCol-1]);
109733 if( !sqlite3ExprIsConstantOrFunction(pExpr, db->init.busy) ){
109734 sqlite3ErrorMsg(pParse, "default value of column [%s] is not constant",
109735 pCol->zName);
109736 #ifndef SQLITE_OMIT_GENERATED_COLUMNS
109737 }else if( pCol->colFlags & COLFLAG_GENERATED ){
109738 testcase( pCol->colFlags & COLFLAG_VIRTUAL );
@@ -110948,11 +111554,14 @@
110948 db->xAuth = xAuth;
110949 #else
110950 pSelTab = sqlite3ResultSetOfSelect(pParse, pSel, SQLITE_AFF_NONE);
110951 #endif
110952 pParse->nTab = n;
110953 if( pTable->pCheck ){
 
 
 
110954 /* CREATE VIEW name(arglist) AS ...
110955 ** The names of the columns in the table are taken from
110956 ** arglist which is stored in pTable->pCheck. The pCheck field
110957 ** normally holds CHECK constraints on an ordinary table, but for
110958 ** a VIEW it holds the list of column names.
@@ -110964,23 +111573,20 @@
110964 && pTable->nCol==pSel->pEList->nExpr
110965 ){
110966 sqlite3SelectAddColumnTypeAndCollation(pParse, pTable, pSel,
110967 SQLITE_AFF_NONE);
110968 }
110969 }else if( pSelTab ){
110970 /* CREATE VIEW name AS... without an argument list. Construct
110971 ** the column names from the SELECT statement that defines the view.
110972 */
110973 assert( pTable->aCol==0 );
110974 pTable->nCol = pSelTab->nCol;
110975 pTable->aCol = pSelTab->aCol;
110976 pSelTab->nCol = 0;
110977 pSelTab->aCol = 0;
110978 assert( sqlite3SchemaMutexHeld(db, 0, pTable->pSchema) );
110979 }else{
110980 pTable->nCol = 0;
110981 nErr++;
110982 }
110983 pTable->nNVCol = pTable->nCol;
110984 sqlite3DeleteTable(db, pSelTab);
110985 sqlite3SelectDelete(db, pSel);
110986 EnableLookaside;
@@ -111430,11 +112036,11 @@
111430 nCol = pFromCol->nExpr;
111431 }
111432 nByte = sizeof(*pFKey) + (nCol-1)*sizeof(pFKey->aCol[0]) + pTo->n + 1;
111433 if( pToCol ){
111434 for(i=0; i<pToCol->nExpr; i++){
111435 nByte += sqlite3Strlen30(pToCol->a[i].zName) + 1;
111436 }
111437 }
111438 pFKey = sqlite3DbMallocZero(db, nByte );
111439 if( pFKey==0 ){
111440 goto fk_end;
@@ -111455,34 +112061,34 @@
111455 pFKey->aCol[0].iFrom = p->nCol-1;
111456 }else{
111457 for(i=0; i<nCol; i++){
111458 int j;
111459 for(j=0; j<p->nCol; j++){
111460 if( sqlite3StrICmp(p->aCol[j].zName, pFromCol->a[i].zName)==0 ){
111461 pFKey->aCol[i].iFrom = j;
111462 break;
111463 }
111464 }
111465 if( j>=p->nCol ){
111466 sqlite3ErrorMsg(pParse,
111467 "unknown column \"%s\" in foreign key definition",
111468 pFromCol->a[i].zName);
111469 goto fk_end;
111470 }
111471 if( IN_RENAME_OBJECT ){
111472 sqlite3RenameTokenRemap(pParse, &pFKey->aCol[i], pFromCol->a[i].zName);
111473 }
111474 }
111475 }
111476 if( pToCol ){
111477 for(i=0; i<nCol; i++){
111478 int n = sqlite3Strlen30(pToCol->a[i].zName);
111479 pFKey->aCol[i].zCol = z;
111480 if( IN_RENAME_OBJECT ){
111481 sqlite3RenameTokenRemap(pParse, z, pToCol->a[i].zName);
111482 }
111483 memcpy(z, pToCol->a[i].zName, n);
111484 z[n] = 0;
111485 z += n+1;
111486 }
111487 }
111488 pFKey->isDeferred = 0;
@@ -113637,16 +114243,17 @@
113637 FuncDef *p, /* The function we are evaluating for match quality */
113638 int nArg, /* Desired number of arguments. (-1)==any */
113639 u8 enc /* Desired text encoding */
113640 ){
113641 int match;
113642
113643 /* nArg of -2 is a special case */
113644 if( nArg==(-2) ) return (p->xSFunc==0) ? 0 : FUNC_PERFECT_MATCH;
113645
113646 /* Wrong number of arguments means "no match" */
113647 if( p->nArg!=nArg && p->nArg>=0 ) return 0;
 
 
 
113648
113649 /* Give a better score to a function with a specific number of arguments
113650 ** than to function that accepts any number of arguments. */
113651 if( p->nArg==nArg ){
113652 match = 4;
@@ -116747,30 +117354,35 @@
116747 ** are read-only after initialization is complete.
116748 **
116749 ** For peak efficiency, put the most frequently used function last.
116750 */
116751 static FuncDef aBuiltinFunc[] = {
 
 
 
 
 
 
 
 
116752 #ifdef SQLITE_SOUNDEX
116753 FUNCTION(soundex, 1, 0, 0, soundexFunc ),
116754 #endif
116755 #ifndef SQLITE_OMIT_LOAD_EXTENSION
116756 VFUNCTION(load_extension, 1, 0, 0, loadExt ),
116757 VFUNCTION(load_extension, 2, 0, 0, loadExt ),
116758 #endif
116759 #if SQLITE_USER_AUTHENTICATION
116760 FUNCTION(sqlite_crypt, 2, 0, 0, sqlite3CryptFunc ),
116761 #endif
116762 #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
116763 DFUNCTION(sqlite_compileoption_used,1, 0, 0, compileoptionusedFunc ),
116764 DFUNCTION(sqlite_compileoption_get, 1, 0, 0, compileoptiongetFunc ),
116765 #endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
116766 FUNCTION2(unlikely, 1, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY),
116767 FUNCTION2(likelihood, 2, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY),
116768 FUNCTION2(likely, 1, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY),
116769 #ifdef SQLITE_DEBUG
116770 FUNCTION2(affinity, 1, 0, 0, noopFunc, SQLITE_FUNC_AFFINITY),
116771 #endif
116772 #ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
116773 FUNCTION2(sqlite_offset, 1, 0, 0, noopFunc, SQLITE_FUNC_OFFSET|
116774 SQLITE_FUNC_TYPEOF),
116775 #endif
116776 FUNCTION(ltrim, 1, 1, 0, trimFunc ),
@@ -116799,11 +117411,11 @@
116799 FUNCTION(round, 2, 0, 0, roundFunc ),
116800 #endif
116801 FUNCTION(upper, 1, 0, 0, upperFunc ),
116802 FUNCTION(lower, 1, 0, 0, lowerFunc ),
116803 FUNCTION(hex, 1, 0, 0, hexFunc ),
116804 FUNCTION2(ifnull, 2, 0, 0, noopFunc, SQLITE_FUNC_COALESCE),
116805 VFUNCTION(random, 0, 0, 0, randomFunc ),
116806 VFUNCTION(randomblob, 1, 0, 0, randomBlob ),
116807 FUNCTION(nullif, 2, 0, 1, nullifFunc ),
116808 DFUNCTION(sqlite_version, 0, 0, 0, versionFunc ),
116809 DFUNCTION(sqlite_source_id, 0, 0, 0, sourceidFunc ),
@@ -116839,11 +117451,11 @@
116839 #ifdef SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION
116840 FUNCTION(unknown, -1, 0, 0, unknownFunc ),
116841 #endif
116842 FUNCTION(coalesce, 1, 0, 0, 0 ),
116843 FUNCTION(coalesce, 0, 0, 0, 0 ),
116844 FUNCTION2(coalesce, -1, 0, 0, noopFunc, SQLITE_FUNC_COALESCE),
116845 };
116846 #ifndef SQLITE_OMIT_ALTERTABLE
116847 sqlite3AlterFunctions();
116848 #endif
116849 sqlite3WindowFunctions();
@@ -119340,10 +119952,11 @@
119340 ** C: yield X, at EOF goto D
119341 ** insert the select result into <table> from R..R+n
119342 ** goto C
119343 ** D: ...
119344 */
 
119345 addrInsTop = addrCont = sqlite3VdbeAddOp1(v, OP_Yield, dest.iSDParm);
119346 VdbeCoverage(v);
119347 if( ipkColumn>=0 ){
119348 /* tag-20191021-001: If the INTEGER PRIMARY KEY is being generated by the
119349 ** SELECT, go ahead and copy the value into the rowid slot now, so that
@@ -119600,10 +120213,19 @@
119600 sqlite3VdbeAddOp2(v, OP_Next, srcTab, addrCont); VdbeCoverage(v);
119601 sqlite3VdbeJumpHere(v, addrInsTop);
119602 sqlite3VdbeAddOp1(v, OP_Close, srcTab);
119603 }else if( pSelect ){
119604 sqlite3VdbeGoto(v, addrCont);
 
 
 
 
 
 
 
 
 
119605 sqlite3VdbeJumpHere(v, addrInsTop);
119606 }
119607
119608 insert_end:
119609 /* Update the sqlite_sequence table by storing the content of the
@@ -119822,11 +120444,10 @@
119822 sqlite3 *db; /* Database connection */
119823 int i; /* loop counter */
119824 int ix; /* Index loop counter */
119825 int nCol; /* Number of columns */
119826 int onError; /* Conflict resolution strategy */
119827 int addr1; /* Address of jump instruction */
119828 int seenReplace = 0; /* True if REPLACE is used to resolve INT PK conflict */
119829 int nPkField; /* Number of fields in PRIMARY KEY. 1 for ROWID tables */
119830 Index *pUpIdx = 0; /* Index to which to apply the upsert */
119831 u8 isUpdate; /* True if this is an UPDATE operation */
119832 u8 bAffinityDone = 0; /* True if the OP_Affinity operation has been run */
@@ -119866,75 +120487,104 @@
119866 iDataCur, iIdxCur, regNewData, regOldData, pkChng));
119867
119868 /* Test all NOT NULL constraints.
119869 */
119870 if( pTab->tabFlags & TF_HasNotNull ){
119871 for(i=0; i<nCol; i++){
119872 int iReg;
119873 onError = pTab->aCol[i].notNull;
119874 if( onError==OE_None ) continue; /* No NOT NULL on this column */
119875 if( i==pTab->iPKey ){
119876 continue; /* ROWID is never NULL */
119877 }
119878 if( aiChng && aiChng[i]<0 ){
119879 /* Don't bother checking for NOT NULL on columns that do not change */
119880 continue;
119881 }
119882 if( overrideError!=OE_Default ){
119883 onError = overrideError;
119884 }else if( onError==OE_Default ){
119885 onError = OE_Abort;
119886 }
119887 if( onError==OE_Replace && pTab->aCol[i].pDflt==0 ){
119888 onError = OE_Abort;
119889 }
119890 assert( onError==OE_Rollback || onError==OE_Abort || onError==OE_Fail
119891 || onError==OE_Ignore || onError==OE_Replace );
119892 addr1 = 0;
119893 testcase( i!=sqlite3TableColumnToStorage(pTab, i) );
119894 testcase( pTab->aCol[i].colFlags & COLFLAG_VIRTUAL );
119895 testcase( pTab->aCol[i].colFlags & COLFLAG_STORED );
119896 iReg = sqlite3TableColumnToStorage(pTab, i) + regNewData + 1;
119897 switch( onError ){
119898 case OE_Replace: {
119899 assert( onError==OE_Replace );
119900 addr1 = sqlite3VdbeMakeLabel(pParse);
119901 sqlite3VdbeAddOp2(v, OP_NotNull, iReg, addr1);
119902 VdbeCoverage(v);
119903 if( (pTab->aCol[i].colFlags & COLFLAG_GENERATED)==0 ){
119904 sqlite3ExprCode(pParse, pTab->aCol[i].pDflt, regNewData+1+i);
119905 sqlite3VdbeAddOp2(v, OP_NotNull, iReg, addr1);
119906 VdbeCoverage(v);
119907 }
119908 onError = OE_Abort;
119909 /* Fall through into the OE_Abort case to generate code that runs
119910 ** if both the input and the default value are NULL */
119911 }
119912 case OE_Abort:
119913 sqlite3MayAbort(pParse);
119914 /* Fall through */
119915 case OE_Rollback:
119916 case OE_Fail: {
119917 char *zMsg = sqlite3MPrintf(db, "%s.%s", pTab->zName,
119918 pTab->aCol[i].zName);
119919 sqlite3VdbeAddOp3(v, OP_HaltIfNull, SQLITE_CONSTRAINT_NOTNULL,
119920 onError, iReg);
119921 sqlite3VdbeAppendP4(v, zMsg, P4_DYNAMIC);
119922 sqlite3VdbeChangeP5(v, P5_ConstraintNotNull);
119923 VdbeCoverage(v);
119924 if( addr1 ) sqlite3VdbeResolveLabel(v, addr1);
119925 break;
119926 }
119927 default: {
119928 assert( onError==OE_Ignore );
119929 sqlite3VdbeAddOp2(v, OP_IsNull, iReg, ignoreDest);
119930 VdbeCoverage(v);
119931 break;
119932 }
119933 }
119934 }
119935 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119936
119937 /* Test all CHECK constraints
119938 */
119939 #ifndef SQLITE_OMIT_CHECK
119940 if( pTab->pCheck && (db->flags & SQLITE_IgnoreChecks)==0 ){
@@ -119955,11 +120605,11 @@
119955 sqlite3VdbeVerifyAbortable(v, onError);
119956 sqlite3ExprIfTrue(pParse, pExpr, allOk, SQLITE_JUMPIFNULL);
119957 if( onError==OE_Ignore ){
119958 sqlite3VdbeGoto(v, ignoreDest);
119959 }else{
119960 char *zName = pCheck->a[i].zName;
119961 if( zName==0 ) zName = pTab->zName;
119962 if( onError==OE_Replace ) onError = OE_Abort; /* IMP: R-26383-51744 */
119963 sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_CHECK,
119964 onError, zName, P4_TRANSIENT,
119965 P5_ConstraintCheck);
@@ -120258,10 +120908,11 @@
120258 #ifdef SQLITE_ENABLE_NULL_TRIM
120259 if( pIdx->idxType==SQLITE_IDXTYPE_PRIMARYKEY ){
120260 sqlite3SetMakeRecordP5(v, pIdx->pTable);
120261 }
120262 #endif
 
120263
120264 /* In an UPDATE operation, if this index is the PRIMARY KEY index
120265 ** of a WITHOUT ROWID table and there has been no change the
120266 ** primary key, then no collision is possible. The collision detection
120267 ** logic below can all be skipped. */
@@ -120411,13 +121062,19 @@
120411 testcase( nConflictCk>1 );
120412 if( regTrigCnt ){
120413 sqlite3MultiWrite(pParse);
120414 nReplaceTrig++;
120415 }
 
 
 
120416 sqlite3GenerateRowDelete(pParse, pTab, pTrigger, iDataCur, iIdxCur,
120417 regR, nPkField, 0, OE_Replace,
120418 (pIdx==pPk ? ONEPASS_SINGLE : ONEPASS_OFF), iThisCur);
 
 
 
120419 if( regTrigCnt ){
120420 int addrBypass; /* Jump destination to bypass recheck logic */
120421
120422 sqlite3VdbeAddOp2(v, OP_AddImm, regTrigCnt, 1); /* incr trigger cnt */
120423 addrBypass = sqlite3VdbeAddOp0(v, OP_Goto); /* Bypass recheck */
@@ -122889,39 +123546,43 @@
122889 /* 16 */ "cid",
122890 /* 17 */ "name",
122891 /* 18 */ "desc",
122892 /* 19 */ "coll",
122893 /* 20 */ "key",
122894 /* 21 */ "tbl", /* Used by: stats */
122895 /* 22 */ "idx",
122896 /* 23 */ "wdth",
122897 /* 24 */ "hght",
122898 /* 25 */ "flgs",
122899 /* 26 */ "seq", /* Used by: index_list */
122900 /* 27 */ "name",
122901 /* 28 */ "unique",
122902 /* 29 */ "origin",
122903 /* 30 */ "partial",
122904 /* 31 */ "table", /* Used by: foreign_key_check */
122905 /* 32 */ "rowid",
122906 /* 33 */ "parent",
122907 /* 34 */ "fkid",
 
 
 
 
 
 
122908 /* index_info reuses 15 */
122909 /* 35 */ "seq", /* Used by: database_list */
122910 /* 36 */ "name",
122911 /* 37 */ "file",
122912 /* 38 */ "busy", /* Used by: wal_checkpoint */
122913 /* 39 */ "log",
122914 /* 40 */ "checkpointed",
122915 /* 41 */ "name", /* Used by: function_list */
122916 /* 42 */ "builtin",
122917 /* collation_list reuses 26 */
122918 /* 43 */ "database", /* Used by: lock_status */
122919 /* 44 */ "status",
122920 /* 45 */ "cache_size", /* Used by: default_cache_size */
122921 /* module_list pragma_list reuses 9 */
122922 /* 46 */ "timeout", /* Used by: busy_timeout */
122923 };
122924
122925 /* Definitions of all built-in pragmas */
122926 typedef struct PragmaName {
122927 const char *const zName; /* Name of pragma */
@@ -122963,11 +123624,11 @@
122963 #endif
122964 #endif
122965 {/* zName: */ "busy_timeout",
122966 /* ePragTyp: */ PragTyp_BUSY_TIMEOUT,
122967 /* ePragFlg: */ PragFlg_Result0,
122968 /* ColNames: */ 46, 1,
122969 /* iArg: */ 0 },
122970 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
122971 {/* zName: */ "cache_size",
122972 /* ePragTyp: */ PragTyp_CACHE_SIZE,
122973 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq|PragFlg_NoColumns1,
@@ -123002,11 +123663,11 @@
123002 #endif
123003 #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
123004 {/* zName: */ "collation_list",
123005 /* ePragTyp: */ PragTyp_COLLATION_LIST,
123006 /* ePragFlg: */ PragFlg_Result0,
123007 /* ColNames: */ 26, 2,
123008 /* iArg: */ 0 },
123009 #endif
123010 #if !defined(SQLITE_OMIT_COMPILEOPTION_DIAGS)
123011 {/* zName: */ "compile_options",
123012 /* ePragTyp: */ PragTyp_COMPILE_OPTIONS,
@@ -123037,18 +123698,18 @@
123037 #endif
123038 #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
123039 {/* zName: */ "database_list",
123040 /* ePragTyp: */ PragTyp_DATABASE_LIST,
123041 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0,
123042 /* ColNames: */ 35, 3,
123043 /* iArg: */ 0 },
123044 #endif
123045 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED)
123046 {/* zName: */ "default_cache_size",
123047 /* ePragTyp: */ PragTyp_DEFAULT_CACHE_SIZE,
123048 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq|PragFlg_NoColumns1,
123049 /* ColNames: */ 45, 1,
123050 /* iArg: */ 0 },
123051 #endif
123052 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
123053 #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
123054 {/* zName: */ "defer_foreign_keys",
@@ -123074,11 +123735,11 @@
123074 #endif
123075 #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
123076 {/* zName: */ "foreign_key_check",
123077 /* ePragTyp: */ PragTyp_FOREIGN_KEY_CHECK,
123078 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0,
123079 /* ColNames: */ 31, 4,
123080 /* iArg: */ 0 },
123081 #endif
123082 #if !defined(SQLITE_OMIT_FOREIGN_KEY)
123083 {/* zName: */ "foreign_key_list",
123084 /* ePragTyp: */ PragTyp_FOREIGN_KEY_LIST,
@@ -123117,11 +123778,11 @@
123117 #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
123118 #if !defined(SQLITE_OMIT_INTROSPECTION_PRAGMAS)
123119 {/* zName: */ "function_list",
123120 /* ePragTyp: */ PragTyp_FUNCTION_LIST,
123121 /* ePragFlg: */ PragFlg_Result0,
123122 /* ColNames: */ 41, 2,
123123 /* iArg: */ 0 },
123124 #endif
123125 #endif
123126 {/* zName: */ "hard_heap_limit",
123127 /* ePragTyp: */ PragTyp_HARD_HEAP_LIMIT,
@@ -123163,11 +123824,11 @@
123163 /* ColNames: */ 15, 3,
123164 /* iArg: */ 0 },
123165 {/* zName: */ "index_list",
123166 /* ePragTyp: */ PragTyp_INDEX_LIST,
123167 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result1|PragFlg_SchemaOpt,
123168 /* ColNames: */ 26, 5,
123169 /* iArg: */ 0 },
123170 {/* zName: */ "index_xinfo",
123171 /* ePragTyp: */ PragTyp_INDEX_INFO,
123172 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result1|PragFlg_SchemaOpt,
123173 /* ColNames: */ 15, 6,
@@ -123215,11 +123876,11 @@
123215 #endif
123216 #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
123217 {/* zName: */ "lock_status",
123218 /* ePragTyp: */ PragTyp_LOCK_STATUS,
123219 /* ePragFlg: */ PragFlg_Result0,
123220 /* ColNames: */ 43, 2,
123221 /* iArg: */ 0 },
123222 #endif
123223 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
123224 {/* zName: */ "locking_mode",
123225 /* ePragTyp: */ PragTyp_LOCKING_MODE,
@@ -123363,11 +124024,11 @@
123363 #endif
123364 #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) && defined(SQLITE_DEBUG)
123365 {/* zName: */ "stats",
123366 /* ePragTyp: */ PragTyp_STATS,
123367 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq,
123368 /* ColNames: */ 21, 5,
123369 /* iArg: */ 0 },
123370 #endif
123371 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
123372 {/* zName: */ "synchronous",
123373 /* ePragTyp: */ PragTyp_SYNCHRONOUS,
@@ -123414,10 +124075,17 @@
123414 {/* zName: */ "threads",
123415 /* ePragTyp: */ PragTyp_THREADS,
123416 /* ePragFlg: */ PragFlg_Result0,
123417 /* ColNames: */ 0, 0,
123418 /* iArg: */ 0 },
 
 
 
 
 
 
 
123419 #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
123420 {/* zName: */ "user_version",
123421 /* ePragTyp: */ PragTyp_HEADER_VALUE,
123422 /* ePragFlg: */ PragFlg_NoColumns1|PragFlg_Result0,
123423 /* ColNames: */ 0, 0,
@@ -123459,11 +124127,11 @@
123459 /* ColNames: */ 0, 0,
123460 /* iArg: */ 0 },
123461 {/* zName: */ "wal_checkpoint",
123462 /* ePragTyp: */ PragTyp_WAL_CHECKPOINT,
123463 /* ePragFlg: */ PragFlg_NeedSchema,
123464 /* ColNames: */ 38, 3,
123465 /* iArg: */ 0 },
123466 #endif
123467 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
123468 {/* zName: */ "writable_schema",
123469 /* ePragTyp: */ PragTyp_FLAG,
@@ -123470,11 +124138,11 @@
123470 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
123471 /* ColNames: */ 0, 0,
123472 /* iArg: */ SQLITE_WriteSchema|SQLITE_NoSchemaError },
123473 #endif
123474 };
123475 /* Number of pragmas: 65 on by default, 81 total. */
123476
123477 /************** End of pragma.h **********************************************/
123478 /************** Continuing where we left off in pragma.c *********************/
123479
123480 /*
@@ -123739,10 +124407,59 @@
123739 lwr = mid + 1;
123740 }
123741 }
123742 return lwr>upr ? 0 : &aPragmaName[mid];
123743 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
123744
123745 /*
123746 ** Helper subroutine for PRAGMA integrity_check:
123747 **
123748 ** Generate code to output a single-column result row with a value of the
@@ -124704,20 +125421,20 @@
124704 #ifndef SQLITE_OMIT_INTROSPECTION_PRAGMAS
124705 case PragTyp_FUNCTION_LIST: {
124706 int i;
124707 HashElem *j;
124708 FuncDef *p;
124709 pParse->nMem = 2;
 
124710 for(i=0; i<SQLITE_FUNC_HASH_SZ; i++){
124711 for(p=sqlite3BuiltinFunctions.a[i]; p; p=p->u.pHash ){
124712 if( p->funcFlags & SQLITE_FUNC_INTERNAL ) continue;
124713 sqlite3VdbeMultiLoad(v, 1, "si", p->zName, 1);
124714 }
124715 }
124716 for(j=sqliteHashFirst(&db->aFunc); j; j=sqliteHashNext(j)){
124717 p = (FuncDef*)sqliteHashData(j);
124718 sqlite3VdbeMultiLoad(v, 1, "si", p->zName, 0);
124719 }
124720 }
124721 break;
124722
124723 #ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -127127,10 +127844,11 @@
127127 if( ALWAYS(p) ){
127128 clearSelect(pParse->db, p, 0);
127129 memset(&p->iLimit, 0, sizeof(Select) - offsetof(Select,iLimit));
127130 p->pEList = sqlite3ExprListAppend(pParse, 0,
127131 sqlite3ExprAlloc(pParse->db,TK_NULL,0,0));
 
127132 }
127133 }
127134
127135 /*
127136 ** Return a pointer to the right-most SELECT statement in a compound.
@@ -127238,19 +127956,22 @@
127238 static int tableAndColumnIndex(
127239 SrcList *pSrc, /* Array of tables to search */
127240 int N, /* Number of tables in pSrc->a[] to search */
127241 const char *zCol, /* Name of the column we are looking for */
127242 int *piTab, /* Write index of pSrc->a[] here */
127243 int *piCol /* Write index of pSrc->a[*piTab].pTab->aCol[] here */
 
127244 ){
127245 int i; /* For looping over tables in pSrc */
127246 int iCol; /* Index of column matching zCol */
127247
127248 assert( (piTab==0)==(piCol==0) ); /* Both or neither are NULL */
127249 for(i=0; i<N; i++){
127250 iCol = columnIndex(pSrc->a[i].pTab, zCol);
127251 if( iCol>=0 ){
 
 
127252 if( piTab ){
127253 *piTab = i;
127254 *piCol = iCol;
127255 }
127256 return 1;
@@ -127411,14 +128132,15 @@
127411 for(j=0; j<pRightTab->nCol; j++){
127412 char *zName; /* Name of column in the right table */
127413 int iLeft; /* Matching left table */
127414 int iLeftCol; /* Matching column in the left table */
127415
 
127416 zName = pRightTab->aCol[j].zName;
127417 if( tableAndColumnIndex(pSrc, i+1, zName, &iLeft, &iLeftCol) ){
127418 addWhereTerm(pParse, pSrc, iLeft, iLeftCol, i+1, j,
127419 isOuter, &p->pWhere);
127420 }
127421 }
127422 }
127423
127424 /* Disallow both ON and USING clauses in the same join
@@ -127454,11 +128176,11 @@
127454 int iRightCol; /* Column number of matching column on the right */
127455
127456 zName = pList->a[j].zName;
127457 iRightCol = columnIndex(pRightTab, zName);
127458 if( iRightCol<0
127459 || !tableAndColumnIndex(pSrc, i+1, zName, &iLeft, &iLeftCol)
127460 ){
127461 sqlite3ErrorMsg(pParse, "cannot join using column %s - column "
127462 "not present in both tables", zName);
127463 return 1;
127464 }
@@ -127860,11 +128582,11 @@
127860 pDest->nSdst = nResultCol;
127861 regOrig = regResult = pDest->iSdst;
127862 if( srcTab>=0 ){
127863 for(i=0; i<nResultCol; i++){
127864 sqlite3VdbeAddOp3(v, OP_Column, srcTab, i, regResult+i);
127865 VdbeComment((v, "%s", p->pEList->a[i].zName));
127866 }
127867 }else if( eDest!=SRT_Exists ){
127868 #ifdef SQLITE_ENABLE_SORTER_REFERENCES
127869 ExprList *pExtra = 0;
127870 #endif
@@ -128481,11 +129203,11 @@
128481 iRead = aOutEx[i].u.x.iOrderByCol-1;
128482 }else{
128483 iRead = iCol--;
128484 }
128485 sqlite3VdbeAddOp3(v, OP_Column, iSortTab, iRead, regRow+i);
128486 VdbeComment((v, "%s", aOutEx[i].zName?aOutEx[i].zName : aOutEx[i].zSpan));
128487 }
128488 }
128489 switch( eDest ){
128490 case SRT_Table:
128491 case SRT_EphemTab: {
@@ -128815,13 +129537,13 @@
128815 Expr *p = pEList->a[i].pExpr;
128816
128817 assert( p!=0 );
128818 assert( p->op!=TK_AGG_COLUMN ); /* Agg processing has not run yet */
128819 assert( p->op!=TK_COLUMN || p->y.pTab!=0 ); /* Covering idx not yet coded */
128820 if( pEList->a[i].zName ){
128821 /* An AS clause always takes first priority */
128822 char *zName = pEList->a[i].zName;
128823 sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, SQLITE_TRANSIENT);
128824 }else if( srcName && p->op==TK_COLUMN ){
128825 char *zCol;
128826 int iCol = p->iColumn;
128827 pTab = p->y.pTab;
@@ -128839,11 +129561,11 @@
128839 sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, SQLITE_DYNAMIC);
128840 }else{
128841 sqlite3VdbeSetColName(v, i, COLNAME_NAME, zCol, SQLITE_TRANSIENT);
128842 }
128843 }else{
128844 const char *z = pEList->a[i].zSpan;
128845 z = z==0 ? sqlite3MPrintf(db, "column%d", i+1) : sqlite3DbStrDup(db, z);
128846 sqlite3VdbeSetColName(v, i, COLNAME_NAME, z, SQLITE_DYNAMIC);
128847 }
128848 }
128849 generateColumnTypes(pParse, pTabList, pEList);
@@ -128901,11 +129623,11 @@
128901 *paCol = aCol;
128902
128903 for(i=0, pCol=aCol; i<nCol && !db->mallocFailed; i++, pCol++){
128904 /* Get an appropriate name for the column
128905 */
128906 if( (zName = pEList->a[i].zName)!=0 ){
128907 /* If the column contains an "AS <name>" phrase, use <name> as the name */
128908 }else{
128909 Expr *pColExpr = sqlite3ExprSkipCollateAndLikely(pEList->a[i].pExpr);
128910 while( pColExpr->op==TK_DOT ){
128911 pColExpr = pColExpr->pRight;
@@ -128921,14 +129643,14 @@
128921 }else if( pColExpr->op==TK_ID ){
128922 assert( !ExprHasProperty(pColExpr, EP_IntValue) );
128923 zName = pColExpr->u.zToken;
128924 }else{
128925 /* Use the original text of the column expression as its name */
128926 zName = pEList->a[i].zSpan;
128927 }
128928 }
128929 if( zName ){
128930 zName = sqlite3DbStrDup(db, zName);
128931 }else{
128932 zName = sqlite3MPrintf(db,"column%d",i+1);
128933 }
128934
@@ -130594,10 +131316,11 @@
130594 ** (17c) every term within the subquery compound must have a FROM clause
130595 ** (17d) the outer query may not be
130596 ** (17d1) aggregate, or
130597 ** (17d2) DISTINCT, or
130598 ** (17d3) a join.
 
130599 **
130600 ** The parent and sub-query may contain WHERE clauses. Subject to
130601 ** rules (11), (13) and (14), they may also contain ORDER BY,
130602 ** LIMIT and OFFSET clauses. The subquery cannot use any compound
130603 ** operator other than UNION ALL because all the other compound
@@ -130778,10 +131501,11 @@
130778 assert( pSub->pSrc!=0 );
130779 assert( pSub->pEList->nExpr==pSub1->pEList->nExpr );
130780 if( (pSub1->selFlags & (SF_Distinct|SF_Aggregate))!=0 /* (17b) */
130781 || (pSub1->pPrior && pSub1->op!=TK_ALL) /* (17a) */
130782 || pSub1->pSrc->nSrc<1 /* (17c) */
 
130783 ){
130784 return 0;
130785 }
130786 testcase( pSub1->pSrc->nSrc>1 );
130787 }
@@ -131064,27 +131788,40 @@
131064 Expr **apExpr; /* [i*2] is COLUMN and [i*2+1] is VALUE */
131065 };
131066
131067 /*
131068 ** Add a new entry to the pConst object. Except, do not add duplicate
131069 ** pColumn entires.
 
 
 
 
131070 */
131071 static void constInsert(
131072 WhereConst *pConst, /* The WhereConst into which we are inserting */
131073 Expr *pColumn, /* The COLUMN part of the constraint */
131074 Expr *pValue /* The VALUE part of the constraint */
 
131075 ){
131076 int i;
131077 assert( pColumn->op==TK_COLUMN );
 
 
 
 
 
 
 
 
131078
131079 /* 2018-10-25 ticket [cf5ed20f]
131080 ** Make sure the same pColumn is not inserted more than once */
131081 for(i=0; i<pConst->nConst; i++){
131082 const Expr *pExpr = pConst->apExpr[i*2];
131083 assert( pExpr->op==TK_COLUMN );
131084 if( pExpr->iTable==pColumn->iTable
131085 && pExpr->iColumn==pColumn->iColumn
131086 ){
131087 return; /* Already present. Return without doing anything. */
131088 }
131089 }
131090
@@ -131092,11 +131829,13 @@
131092 pConst->apExpr = sqlite3DbReallocOrFree(pConst->pParse->db, pConst->apExpr,
131093 pConst->nConst*2*sizeof(Expr*));
131094 if( pConst->apExpr==0 ){
131095 pConst->nConst = 0;
131096 }else{
131097 if( ExprHasProperty(pValue, EP_FixedCol) ) pValue = pValue->pLeft;
 
 
131098 pConst->apExpr[pConst->nConst*2-2] = pColumn;
131099 pConst->apExpr[pConst->nConst*2-1] = pValue;
131100 }
131101 }
131102
@@ -131118,23 +131857,15 @@
131118 if( pExpr->op!=TK_EQ ) return;
131119 pRight = pExpr->pRight;
131120 pLeft = pExpr->pLeft;
131121 assert( pRight!=0 );
131122 assert( pLeft!=0 );
131123 if( pRight->op==TK_COLUMN
131124 && !ExprHasProperty(pRight, EP_FixedCol)
131125 && sqlite3ExprIsConstant(pLeft)
131126 && sqlite3IsBinary(sqlite3ExprCompareCollSeq(pConst->pParse,pExpr))
131127 ){
131128 constInsert(pConst, pRight, pLeft);
131129 }else
131130 if( pLeft->op==TK_COLUMN
131131 && !ExprHasProperty(pLeft, EP_FixedCol)
131132 && sqlite3ExprIsConstant(pRight)
131133 && sqlite3IsBinary(sqlite3ExprCompareCollSeq(pConst->pParse,pExpr))
131134 ){
131135 constInsert(pConst, pLeft, pRight);
131136 }
131137 }
131138
131139 /*
131140 ** This is a Walker expression callback. pExpr is a candidate expression
@@ -131166,14 +131897,13 @@
131166
131167 /*
131168 ** The WHERE-clause constant propagation optimization.
131169 **
131170 ** If the WHERE clause contains terms of the form COLUMN=CONSTANT or
131171 ** CONSTANT=COLUMN that must be tree (in other words, if the terms top-level
131172 ** AND-connected terms that are not part of a ON clause from a LEFT JOIN)
131173 ** then throughout the query replace all other occurrences of COLUMN
131174 ** with CONSTANT within the WHERE clause.
131175 **
131176 ** For example, the query:
131177 **
131178 ** SELECT * FROM t1, t2, t3 WHERE t1.a=39 AND t2.b=t1.a AND t3.c=t2.b
131179 **
@@ -131882,11 +132612,19 @@
131882 u8 eCodeOrig = pWalker->eCode;
131883 if( sqlite3ViewGetColumnNames(pParse, pTab) ) return WRC_Abort;
131884 assert( pFrom->pSelect==0 );
131885 if( pTab->pSelect && (db->flags & SQLITE_EnableView)==0 ){
131886 sqlite3ErrorMsg(pParse, "access to view \"%s\" prohibited",
131887 pTab->zName);
 
 
 
 
 
 
 
 
131888 }
131889 pFrom->pSelect = sqlite3SelectDup(db, pTab->pSelect, 0);
131890 nCol = pTab->nCol;
131891 pTab->nCol = -1;
131892 pWalker->eCode = 1; /* Turn on Select.selId renumbering */
@@ -131903,11 +132641,11 @@
131903 }
131904 }
131905
131906 /* Process NATURAL keywords, and ON and USING clauses of joins.
131907 */
131908 if( db->mallocFailed || sqliteProcessJoin(pParse, p) ){
131909 return WRC_Abort;
131910 }
131911
131912 /* For every "*" that occurs in the column list, insert the names of
131913 ** all columns in all tables. And for every TABLE.* insert the names
@@ -131950,14 +132688,13 @@
131950 ){
131951 /* This particular expression does not need to be expanded.
131952 */
131953 pNew = sqlite3ExprListAppend(pParse, pNew, a[k].pExpr);
131954 if( pNew ){
131955 pNew->a[pNew->nExpr-1].zName = a[k].zName;
131956 pNew->a[pNew->nExpr-1].zSpan = a[k].zSpan;
131957 a[k].zName = 0;
131958 a[k].zSpan = 0;
131959 }
131960 a[k].pExpr = 0;
131961 }else{
131962 /* This expression is a "*" or a "TABLE.*" and needs to be
131963 ** expanded. */
@@ -131992,11 +132729,11 @@
131992 char *zToFree; /* Malloced string that needs to be freed */
131993 Token sColname; /* Computed column name as a token */
131994
131995 assert( zName );
131996 if( zTName && pSub
131997 && sqlite3MatchSpanName(pSub->pEList->a[j].zSpan, 0, zTName, 0)==0
131998 ){
131999 continue;
132000 }
132001
132002 /* If a column is marked as 'hidden', omit it from the expanded
@@ -132010,11 +132747,11 @@
132010 }
132011 tableSeen = 1;
132012
132013 if( i>0 && zTName==0 ){
132014 if( (pFrom->fg.jointype & JT_NATURAL)!=0
132015 && tableAndColumnIndex(pTabList, i, zName, 0, 0)
132016 ){
132017 /* In a NATURAL join, omit the join columns from the
132018 ** table to the right of the join */
132019 continue;
132020 }
@@ -132045,19 +132782,20 @@
132045 pNew = sqlite3ExprListAppend(pParse, pNew, pExpr);
132046 sqlite3TokenInit(&sColname, zColname);
132047 sqlite3ExprListSetName(pParse, pNew, &sColname, 0);
132048 if( pNew && (p->selFlags & SF_NestedFrom)!=0 ){
132049 struct ExprList_item *pX = &pNew->a[pNew->nExpr-1];
 
132050 if( pSub ){
132051 pX->zSpan = sqlite3DbStrDup(db, pSub->pEList->a[j].zSpan);
132052 testcase( pX->zSpan==0 );
132053 }else{
132054 pX->zSpan = sqlite3MPrintf(db, "%s.%s.%s",
132055 zSchemaName, zTabName, zColname);
132056 testcase( pX->zSpan==0 );
132057 }
132058 pX->bSpanIsTab = 1;
132059 }
132060 sqlite3DbFree(db, zToFree);
132061 }
132062 }
132063 if( !tableSeen ){
@@ -133022,10 +133760,11 @@
133022 && sqlite3ExprListCompare(sSort.pOrderBy, pEList, -1)==0
133023 && p->pWin==0
133024 ){
133025 p->selFlags &= ~SF_Distinct;
133026 pGroupBy = p->pGroupBy = sqlite3ExprListDup(db, pEList, 0);
 
133027 /* Notice that even thought SF_Distinct has been cleared from p->selFlags,
133028 ** the sDistinct.isTnct is still set. Hence, isTnct represents the
133029 ** original setting of the SF_Distinct flag, not the current setting */
133030 assert( sDistinct.isTnct );
133031
@@ -133096,11 +133835,11 @@
133096 u16 wctrlFlags = (sDistinct.isTnct ? WHERE_WANT_DISTINCT : 0)
133097 | (p->selFlags & SF_FixedLimit);
133098 #ifndef SQLITE_OMIT_WINDOWFUNC
133099 Window *pWin = p->pWin; /* Master window object (or NULL) */
133100 if( pWin ){
133101 sqlite3WindowCodeInit(pParse, pWin);
133102 }
133103 #endif
133104 assert( WHERE_USE_LIMIT==SF_FixedLimit );
133105
133106
@@ -134568,11 +135307,11 @@
134568 */
134569 static int checkColumnOverlap(IdList *pIdList, ExprList *pEList){
134570 int e;
134571 if( pIdList==0 || NEVER(pEList==0) ) return 1;
134572 for(e=0; e<pEList->nExpr; e++){
134573 if( sqlite3IdListIndex(pIdList, pEList->a[e].zName)>=0 ) return 1;
134574 }
134575 return 0;
134576 }
134577
134578 /*
@@ -135272,10 +136011,11 @@
135272 int aiCurOnePass[2]; /* The write cursors opened by WHERE_ONEPASS */
135273 int addrOpen = 0; /* Address of OP_OpenEphemeral */
135274 int iPk = 0; /* First of nPk cells holding PRIMARY KEY value */
135275 i16 nPk = 0; /* Number of components of the PRIMARY KEY */
135276 int bReplace = 0; /* True if REPLACE conflict resolution might happen */
 
135277
135278 /* Register Allocations */
135279 int regRowCount = 0; /* A count of rows changed */
135280 int regOldRowid = 0; /* The old rowid */
135281 int regNewRowid = 0; /* The new rowid */
@@ -135386,11 +136126,11 @@
135386 for(i=0; i<pChanges->nExpr; i++){
135387 if( sqlite3ResolveExprNames(&sNC, pChanges->a[i].pExpr) ){
135388 goto update_cleanup;
135389 }
135390 for(j=0; j<pTab->nCol; j++){
135391 if( sqlite3StrICmp(pTab->aCol[j].zName, pChanges->a[i].zName)==0 ){
135392 if( j==pTab->iPKey ){
135393 chngRowid = 1;
135394 pRowidExpr = pChanges->a[i].pExpr;
135395 }else if( pPk && (pTab->aCol[j].colFlags & COLFLAG_PRIMKEY)!=0 ){
135396 chngPk = 1;
@@ -135408,16 +136148,16 @@
135408 aXRef[j] = i;
135409 break;
135410 }
135411 }
135412 if( j>=pTab->nCol ){
135413 if( pPk==0 && sqlite3IsRowid(pChanges->a[i].zName) ){
135414 j = -1;
135415 chngRowid = 1;
135416 pRowidExpr = pChanges->a[i].pExpr;
135417 }else{
135418 sqlite3ErrorMsg(pParse, "no such column: %s", pChanges->a[i].zName);
135419 pParse->checkSchema = 1;
135420 goto update_cleanup;
135421 }
135422 }
135423 #ifndef SQLITE_OMIT_AUTHORIZATION
@@ -135605,10 +136345,11 @@
135605 ** row(s) to be updated.
135606 */
135607 pWInfo = 0;
135608 eOnePass = ONEPASS_SINGLE;
135609 sqlite3ExprIfFalse(pParse, pWhere, labelBreak, SQLITE_JUMPIFNULL);
 
135610 }else{
135611 /* Begin the database scan.
135612 **
135613 ** Do not consider a single-pass strategy for a multi-row update if
135614 ** there are any triggers or foreign keys to process, or rows may
@@ -135631,10 +136372,11 @@
135631 **
135632 ** Fall back to ONEPASS_OFF if where.c has selected a ONEPASS_MULTI
135633 ** strategy that uses an index for which one or more columns are being
135634 ** updated. */
135635 eOnePass = sqlite3WhereOkOnePass(pWInfo, aiCurOnePass);
 
135636 if( eOnePass!=ONEPASS_SINGLE ){
135637 sqlite3MultiWrite(pParse);
135638 if( eOnePass==ONEPASS_MULTI ){
135639 int iCur = aiCurOnePass[1];
135640 if( iCur>=0 && iCur!=iDataCur && aToOpen[iCur-iBaseCur] ){
@@ -135794,10 +136536,11 @@
135794 ** a new.* reference in a trigger program.
135795 */
135796 testcase( i==31 );
135797 testcase( i==32 );
135798 sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, i, k);
 
135799 }else{
135800 sqlite3VdbeAddOp2(v, OP_Null, 0, k);
135801 }
135802 }
135803 }
@@ -135880,10 +136623,19 @@
135880 sqlite3FkCheck(pParse, pTab, regOldRowid, 0, aXRef, chngKey);
135881 }
135882
135883 /* Delete the index entries associated with the current record. */
135884 sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur, aRegIdx, -1);
 
 
 
 
 
 
 
 
 
135885
135886 /* If changing the rowid value, or if there are foreign key constraints
135887 ** to process, delete the old record. Otherwise, add a noop OP_Delete
135888 ** to invoke the pre-update hook.
135889 **
@@ -136378,10 +137130,11 @@
136378 sqlite3VdbeVerifyAbortable(v, OE_Abort);
136379 i = sqlite3VdbeAddOp4Int(v, OP_Found, iDataCur, 0, iPk, nPk);
136380 VdbeCoverage(v);
136381 sqlite3VdbeAddOp4(v, OP_Halt, SQLITE_CORRUPT, OE_Abort, 0,
136382 "corrupt database", P4_STATIC);
 
136383 sqlite3VdbeJumpHere(v, i);
136384 }
136385 }
136386 /* pUpsert does not own pUpsertSrc - the outer INSERT statement does. So
136387 ** we have to make a copy before passing it down into sqlite3Update() */
@@ -137408,10 +138161,11 @@
137408 sqlite3DbFree(db, zModuleName);
137409 return SQLITE_NOMEM_BKPT;
137410 }
137411 pVTable->db = db;
137412 pVTable->pMod = pMod;
 
137413
137414 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
137415 pTab->azModuleArg[1] = db->aDb[iDb].zDbSName;
137416
137417 /* Invoke the virtual table constructor */
@@ -138097,32 +138851,42 @@
138097 ** of the virtual table being implemented.
138098 */
138099 SQLITE_API int sqlite3_vtab_config(sqlite3 *db, int op, ...){
138100 va_list ap;
138101 int rc = SQLITE_OK;
 
138102
138103 #ifdef SQLITE_ENABLE_API_ARMOR
138104 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
138105 #endif
138106 sqlite3_mutex_enter(db->mutex);
138107 va_start(ap, op);
138108 switch( op ){
138109 case SQLITE_VTAB_CONSTRAINT_SUPPORT: {
138110 VtabCtx *p = db->pVtabCtx;
138111 if( !p ){
138112 rc = SQLITE_MISUSE_BKPT;
138113 }else{
138114 assert( p->pTab==0 || IsVirtual(p->pTab) );
138115 p->pVTable->bConstraint = (u8)va_arg(ap, int);
138116 }
138117 break;
138118 }
138119 default:
138120 rc = SQLITE_MISUSE_BKPT;
138121 break;
138122 }
138123 va_end(ap);
 
 
 
 
 
 
 
 
 
138124
138125 if( rc!=SQLITE_OK ) sqlite3Error(db, rc);
138126 sqlite3_mutex_leave(db->mutex);
138127 return rc;
138128 }
@@ -138586,10 +139350,24 @@
138586 #endif
138587 #ifndef SQLITE_QUERY_PLANNER_LIMIT_INCR
138588 # define SQLITE_QUERY_PLANNER_LIMIT_INCR 1000
138589 #endif
138590
 
 
 
 
 
 
 
 
 
 
 
 
 
 
138591 /*
138592 ** The WHERE clause processing routine has two halves. The
138593 ** first part does the start of the WHERE loop and the second
138594 ** half does the tail of the WHERE loop. An instance of
138595 ** this structure is returned by the first half and passed
@@ -138602,27 +139380,29 @@
138602 Parse *pParse; /* Parsing and code generating context */
138603 SrcList *pTabList; /* List of tables in the join */
138604 ExprList *pOrderBy; /* The ORDER BY clause or NULL */
138605 ExprList *pResultSet; /* Result set of the query */
138606 Expr *pWhere; /* The complete WHERE clause */
138607 LogEst iLimit; /* LIMIT if wctrlFlags has WHERE_USE_LIMIT */
138608 int aiCurOnePass[2]; /* OP_OpenWrite cursors for the ONEPASS opt */
138609 int iContinue; /* Jump here to continue with next record */
138610 int iBreak; /* Jump here to break out of the loop */
138611 int savedNQueryLoop; /* pParse->nQueryLoop outside the WHERE loop */
138612 u16 wctrlFlags; /* Flags originally passed to sqlite3WhereBegin() */
 
138613 u8 nLevel; /* Number of nested loop */
138614 i8 nOBSat; /* Number of ORDER BY terms satisfied by indices */
138615 u8 sorted; /* True if really sorted (not just grouped) */
138616 u8 eOnePass; /* ONEPASS_OFF, or _SINGLE, or _MULTI */
138617 u8 untestedTerms; /* Not all WHERE terms resolved by outer loop */
138618 u8 eDistinct; /* One of the WHERE_DISTINCT_* values */
138619 u8 bOrderedInnerLoop; /* True if only the inner-most loop is ordered */
 
 
 
 
138620 int iTop; /* The very beginning of the WHERE loop */
138621 WhereLoop *pLoops; /* List of all WhereLoop objects */
 
138622 Bitmask revMask; /* Mask of ORDER BY terms that need reversing */
138623 LogEst nRowOut; /* Estimated number of output rows */
138624 WhereClause sWC; /* Decomposition of the WHERE clause */
138625 WhereMaskSet sMaskSet; /* Map cursor numbers to bitmasks */
138626 WhereLevel a[1]; /* Information about each nest loop in WHERE */
138627 };
138628
@@ -138632,10 +139412,12 @@
138632 ** where.c:
138633 */
138634 SQLITE_PRIVATE Bitmask sqlite3WhereGetMask(WhereMaskSet*,int);
138635 #ifdef WHERETRACE_ENABLED
138636 SQLITE_PRIVATE void sqlite3WhereClausePrint(WhereClause *pWC);
 
 
138637 #endif
138638 SQLITE_PRIVATE WhereTerm *sqlite3WhereFindTerm(
138639 WhereClause *pWC, /* The WHERE clause to be searched */
138640 int iCur, /* Cursor number of LHS */
138641 int iColumn, /* Column number of LHS */
@@ -139321,11 +140103,11 @@
139321 }
139322 sqlite3VdbeAddOp1(v, OP_IsNull, iOut); VdbeCoverage(v);
139323 if( i==iEq ){
139324 pIn->iCur = iTab;
139325 pIn->eEndLoopOp = bRev ? OP_Prev : OP_Next;
139326 if( iEq>0 && (pLoop->wsFlags & WHERE_VIRTUALTABLE)==0 ){
139327 pIn->iBase = iReg - i;
139328 pIn->nPrefix = i;
139329 pLoop->wsFlags |= WHERE_IN_EARLYOUT;
139330 }else{
139331 pIn->nPrefix = 0;
@@ -139773,10 +140555,11 @@
139773 Vdbe *v = pParse->pVdbe; /* Vdbe to generate code within */
139774
139775 assert( iIdxCur>0 );
139776 assert( pIdx->aiColumn[pIdx->nColumn-1]==-1 );
139777
 
139778 sqlite3VdbeAddOp3(v, OP_DeferredSeek, iIdxCur, 0, iCur);
139779 if( (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)
139780 && DbMaskAllZero(sqlite3ParseToplevel(pParse)->writeMask)
139781 ){
139782 int i;
@@ -139840,11 +140623,26 @@
139840 Expr *pIdxExpr; /* The index expression */
139841 int iTabCur; /* The cursor of the corresponding table */
139842 int iIdxCur; /* The cursor for the index */
139843 int iIdxCol; /* The column for the index */
139844 int iTabCol; /* The column for the table */
 
 
139845 } IdxExprTrans;
 
 
 
 
 
 
 
 
 
 
 
 
 
139846
139847 /* The walker node callback used to transform matching expressions into
139848 ** a reference to an index column for an index on an expression.
139849 **
139850 ** If pExpr matches, then transform it into a reference to the index column
@@ -139851,10 +140649,11 @@
139851 ** that contains the value of pExpr.
139852 */
139853 static int whereIndexExprTransNode(Walker *p, Expr *pExpr){
139854 IdxExprTrans *pX = p->u.pIdxTrans;
139855 if( sqlite3ExprCompare(0, pExpr, pX->pIdxExpr, pX->iTabCur)==0 ){
 
139856 pExpr->affExpr = sqlite3ExprAffinity(pExpr);
139857 pExpr->op = TK_COLUMN;
139858 pExpr->iTable = pX->iIdxCur;
139859 pExpr->iColumn = pX->iIdxCol;
139860 pExpr->y.pTab = 0;
@@ -139874,10 +140673,11 @@
139874 static int whereIndexExprTransColumn(Walker *p, Expr *pExpr){
139875 if( pExpr->op==TK_COLUMN ){
139876 IdxExprTrans *pX = p->u.pIdxTrans;
139877 if( pExpr->iTable==pX->iTabCur && pExpr->iColumn==pX->iTabCol ){
139878 assert( pExpr->y.pTab!=0 );
 
139879 pExpr->affExpr = sqlite3TableColumnAffinity(pExpr->y.pTab,pExpr->iColumn);
139880 pExpr->iTable = pX->iIdxCur;
139881 pExpr->iColumn = pX->iIdxCol;
139882 pExpr->y.pTab = 0;
139883 }
@@ -139915,10 +140715,12 @@
139915 pTab = pIdx->pTable;
139916 memset(&w, 0, sizeof(w));
139917 w.u.pIdxTrans = &x;
139918 x.iTabCur = iTabCur;
139919 x.iIdxCur = iIdxCur;
 
 
139920 for(iIdxCol=0; iIdxCol<pIdx->nColumn; iIdxCol++){
139921 i16 iRef = pIdx->aiColumn[iIdxCol];
139922 if( iRef==XN_EXPR ){
139923 assert( aColExpr->a[iIdxCol].pExpr!=0 );
139924 x.pIdxExpr = aColExpr->a[iIdxCol].pExpr;
@@ -140012,10 +140814,25 @@
140012 pTabItem = &pWInfo->pTabList->a[pLevel->iFrom];
140013 iCur = pTabItem->iCursor;
140014 pLevel->notReady = notReady & ~sqlite3WhereGetMask(&pWInfo->sMaskSet, iCur);
140015 bRev = (pWInfo->revMask>>iLevel)&1;
140016 VdbeModuleComment((v, "Begin WHERE-loop%d: %s",iLevel,pTabItem->pTab->zName));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140017
140018 /* Create labels for the "break" and "continue" instructions
140019 ** for the current loop. Jump to addrBrk to break out of a loop.
140020 ** Jump to cont to go immediately to the next iteration of the
140021 ** loop.
@@ -140398,11 +141215,11 @@
140398 if( (pLoop->wsFlags & (WHERE_TOP_LIMIT|WHERE_BTM_LIMIT))==0
140399 && (pLoop->wsFlags & WHERE_BIGNULL_SORT)!=0
140400 ){
140401 assert( bSeekPastNull==0 && nExtraReg==0 && nBtm==0 && nTop==0 );
140402 assert( pRangeEnd==0 && pRangeStart==0 );
140403 assert( pLoop->nSkip==0 );
140404 nExtraReg = 1;
140405 bSeekPastNull = 1;
140406 pLevel->regBignull = regBignull = ++pParse->nMem;
140407 pLevel->addrBignull = sqlite3VdbeMakeLabel(pParse);
140408 }
@@ -141067,10 +141884,14 @@
141067 #ifdef WHERETRACE_ENABLED /* 0xffff */
141068 if( sqlite3WhereTrace ){
141069 VdbeNoopComment((v, "WhereTerm[%d] (%p) priority=%d",
141070 pWC->nTerm-j, pTerm, iLoop));
141071 }
 
 
 
 
141072 #endif
141073 sqlite3ExprIfFalse(pParse, pE, addrCont, SQLITE_JUMPIFNULL);
141074 if( skipLikeAddr ) sqlite3VdbeJumpHere(v, skipLikeAddr);
141075 pTerm->wtFlags |= TERM_CODED;
141076 }
@@ -141090,12 +141911,18 @@
141090 WhereTerm *pAlt;
141091 if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue;
141092 if( (pTerm->eOperator & (WO_EQ|WO_IS))==0 ) continue;
141093 if( (pTerm->eOperator & WO_EQUIV)==0 ) continue;
141094 if( pTerm->leftCursor!=iCur ) continue;
141095 if( pLevel->iLeftJoin ) continue;
141096 pE = pTerm->pExpr;
 
 
 
 
 
 
141097 assert( !ExprHasProperty(pE, EP_FromJoin) );
141098 assert( (pTerm->prereqRight & pLevel->notReady)!=0 );
141099 pAlt = sqlite3WhereFindTerm(pWC, iCur, pTerm->u.leftColumn, notReady,
141100 WO_EQ|WO_IN|WO_IS, 0);
141101 if( pAlt==0 ) continue;
@@ -141134,10 +141961,21 @@
141134 sqlite3ExprIfFalse(pParse, pTerm->pExpr, addrCont, SQLITE_JUMPIFNULL);
141135 pTerm->wtFlags |= TERM_CODED;
141136 }
141137 }
141138
 
 
 
 
 
 
 
 
 
 
 
141139 return pLevel->notReady;
141140 }
141141
141142 /************** End of wherecode.c *******************************************/
141143 /************** Begin file whereexpr.c ***************************************/
@@ -142872,11 +143710,11 @@
142872 return pWInfo->iBreak;
142873 }
142874
142875 /*
142876 ** Return ONEPASS_OFF (0) if an UPDATE or DELETE statement is unable to
142877 ** operate directly on the rowis returned by a WHERE clause. Return
142878 ** ONEPASS_SINGLE (1) if the statement can operation directly because only
142879 ** a single row is to be changed. Return ONEPASS_MULTI (2) if the one-pass
142880 ** optimization can be used on multiple
142881 **
142882 ** If the ONEPASS optimization is used (if this routine returns true)
@@ -142898,10 +143736,18 @@
142898 aiCur[0], aiCur[1]);
142899 }
142900 #endif
142901 return pWInfo->eOnePass;
142902 }
 
 
 
 
 
 
 
 
142903
142904 /*
142905 ** Move the content of pSrc into pDest
142906 */
142907 static void whereOrMove(WhereOrSet *pDest, WhereOrSet *pSrc){
@@ -143357,11 +144203,11 @@
143357 ** structure. Used for testing and debugging only. If neither
143358 ** SQLITE_TEST or SQLITE_DEBUG are defined, then these routines
143359 ** are no-ops.
143360 */
143361 #if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(WHERETRACE_ENABLED)
143362 static void TRACE_IDX_INPUTS(sqlite3_index_info *p){
143363 int i;
143364 if( !sqlite3WhereTrace ) return;
143365 for(i=0; i<p->nConstraint; i++){
143366 sqlite3DebugPrintf(" constraint[%d]: col=%d termid=%d op=%d usabled=%d\n",
143367 i,
@@ -143375,11 +144221,11 @@
143375 i,
143376 p->aOrderBy[i].iColumn,
143377 p->aOrderBy[i].desc);
143378 }
143379 }
143380 static void TRACE_IDX_OUTPUTS(sqlite3_index_info *p){
143381 int i;
143382 if( !sqlite3WhereTrace ) return;
143383 for(i=0; i<p->nConstraint; i++){
143384 sqlite3DebugPrintf(" usage[%d]: argvIdx=%d omit=%d\n",
143385 i,
@@ -143391,12 +144237,12 @@
143391 sqlite3DebugPrintf(" orderByConsumed=%d\n", p->orderByConsumed);
143392 sqlite3DebugPrintf(" estimatedCost=%g\n", p->estimatedCost);
143393 sqlite3DebugPrintf(" estimatedRows=%lld\n", p->estimatedRows);
143394 }
143395 #else
143396 #define TRACE_IDX_INPUTS(A)
143397 #define TRACE_IDX_OUTPUTS(A)
143398 #endif
143399
143400 #ifndef SQLITE_OMIT_AUTOMATIC_INDEX
143401 /*
143402 ** Return TRUE if the WHERE clause term pTerm is of a form where it
@@ -143622,12 +144468,12 @@
143622 pTabItem->regResult, pLevel->iIdxCur);
143623 sqlite3VdbeGoto(v, addrTop);
143624 pTabItem->fg.viaCoroutine = 0;
143625 }else{
143626 sqlite3VdbeAddOp2(v, OP_Next, pLevel->iTabCur, addrTop+1); VdbeCoverage(v);
 
143627 }
143628 sqlite3VdbeChangeP5(v, SQLITE_STMTSTATUS_AUTOINDEX);
143629 sqlite3VdbeJumpHere(v, addrTop);
143630 sqlite3ReleaseTempReg(pParse, regRecord);
143631
143632 /* Jump here when skipping the initialization */
143633 sqlite3VdbeJumpHere(v, addrInit);
@@ -143702,27 +144548,18 @@
143702 + sizeof(*pIdxOrderBy)*nOrderBy + sizeof(*pHidden) );
143703 if( pIdxInfo==0 ){
143704 sqlite3ErrorMsg(pParse, "out of memory");
143705 return 0;
143706 }
143707
143708 /* Initialize the structure. The sqlite3_index_info structure contains
143709 ** many fields that are declared "const" to prevent xBestIndex from
143710 ** changing them. We have to do some funky casting in order to
143711 ** initialize those fields.
143712 */
143713 pHidden = (struct HiddenIndexInfo*)&pIdxInfo[1];
143714 pIdxCons = (struct sqlite3_index_constraint*)&pHidden[1];
143715 pIdxOrderBy = (struct sqlite3_index_orderby*)&pIdxCons[nTerm];
143716 pUsage = (struct sqlite3_index_constraint_usage*)&pIdxOrderBy[nOrderBy];
143717 *(int*)&pIdxInfo->nConstraint = nTerm;
143718 *(int*)&pIdxInfo->nOrderBy = nOrderBy;
143719 *(struct sqlite3_index_constraint**)&pIdxInfo->aConstraint = pIdxCons;
143720 *(struct sqlite3_index_orderby**)&pIdxInfo->aOrderBy = pIdxOrderBy;
143721 *(struct sqlite3_index_constraint_usage**)&pIdxInfo->aConstraintUsage =
143722 pUsage;
143723
143724 pHidden->pWC = pWC;
143725 pHidden->pParse = pParse;
143726 for(i=j=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
143727 u16 op;
143728 if( pTerm->leftCursor != pSrc->iCursor ) continue;
@@ -143778,10 +144615,11 @@
143778 }
143779 }
143780
143781 j++;
143782 }
 
143783 for(i=0; i<nOrderBy; i++){
143784 Expr *pExpr = pOrderBy->a[i].pExpr;
143785 pIdxOrderBy[i].iColumn = pExpr->iColumn;
143786 pIdxOrderBy[i].desc = pOrderBy->a[i].sortFlags & KEYINFO_ORDER_DESC;
143787 }
@@ -143808,13 +144646,13 @@
143808 */
143809 static int vtabBestIndex(Parse *pParse, Table *pTab, sqlite3_index_info *p){
143810 sqlite3_vtab *pVtab = sqlite3GetVTable(pParse->db, pTab)->pVtab;
143811 int rc;
143812
143813 TRACE_IDX_INPUTS(p);
143814 rc = pVtab->pModule->xBestIndex(pVtab, p);
143815 TRACE_IDX_OUTPUTS(p);
143816
143817 if( rc!=SQLITE_OK && rc!=SQLITE_CONSTRAINT ){
143818 if( rc==SQLITE_NOMEM ){
143819 sqlite3OomFault(pParse->db);
143820 }else if( !pVtab->zErrMsg ){
@@ -144491,20 +145329,21 @@
144491
144492 #ifdef WHERETRACE_ENABLED
144493 /*
144494 ** Print the content of a WhereTerm object
144495 */
144496 static void whereTermPrint(WhereTerm *pTerm, int iTerm){
144497 if( pTerm==0 ){
144498 sqlite3DebugPrintf("TERM-%-3d NULL\n", iTerm);
144499 }else{
144500 char zType[4];
144501 char zLeft[50];
144502 memcpy(zType, "...", 4);
144503 if( pTerm->wtFlags & TERM_VIRTUAL ) zType[0] = 'V';
144504 if( pTerm->eOperator & WO_EQUIV ) zType[1] = 'E';
144505 if( ExprHasProperty(pTerm->pExpr, EP_FromJoin) ) zType[2] = 'L';
 
144506 if( pTerm->eOperator & WO_SINGLE ){
144507 sqlite3_snprintf(sizeof(zLeft),zLeft,"left={%d:%d}",
144508 pTerm->leftCursor, pTerm->u.leftColumn);
144509 }else if( (pTerm->eOperator & WO_OR)!=0 && pTerm->u.pOrInfo!=0 ){
144510 sqlite3_snprintf(sizeof(zLeft),zLeft,"indexable=0x%lld",
@@ -144511,13 +145350,18 @@
144511 pTerm->u.pOrInfo->indexable);
144512 }else{
144513 sqlite3_snprintf(sizeof(zLeft),zLeft,"left=%d", pTerm->leftCursor);
144514 }
144515 sqlite3DebugPrintf(
144516 "TERM-%-3d %p %s %-12s prob=%-3d op=0x%03x wtFlags=0x%04x",
144517 iTerm, pTerm, zType, zLeft, pTerm->truthProb,
144518 pTerm->eOperator, pTerm->wtFlags);
 
 
 
 
 
144519 if( pTerm->iField ){
144520 sqlite3DebugPrintf(" iField=%d", pTerm->iField);
144521 }
144522 if( pTerm->iParent>=0 ){
144523 sqlite3DebugPrintf(" iParent=%d", pTerm->iParent);
@@ -144533,20 +145377,20 @@
144533 ** Show the complete content of a WhereClause
144534 */
144535 SQLITE_PRIVATE void sqlite3WhereClausePrint(WhereClause *pWC){
144536 int i;
144537 for(i=0; i<pWC->nTerm; i++){
144538 whereTermPrint(&pWC->a[i], i);
144539 }
144540 }
144541 #endif
144542
144543 #ifdef WHERETRACE_ENABLED
144544 /*
144545 ** Print a WhereLoop object for debugging purposes
144546 */
144547 static void whereLoopPrint(WhereLoop *p, WhereClause *pWC){
144548 WhereInfo *pWInfo = pWC->pWInfo;
144549 int nb = 1+(pWInfo->pTabList->nSrc+3)/4;
144550 struct SrcList_item *pItem = pWInfo->pTabList->a + p->iTab;
144551 Table *pTab = pItem->pTab;
144552 Bitmask mAll = (((Bitmask)1)<<(nb*4)) - 1;
@@ -144584,11 +145428,11 @@
144584 }
144585 sqlite3DebugPrintf(" cost %d,%d,%d\n", p->rSetup, p->rRun, p->nOut);
144586 if( p->nLTerm && (sqlite3WhereTrace & 0x100)!=0 ){
144587 int i;
144588 for(i=0; i<p->nLTerm; i++){
144589 whereTermPrint(p->aLTerm[i], i);
144590 }
144591 }
144592 }
144593 #endif
144594
@@ -144688,10 +145532,11 @@
144688 while( pWInfo->pLoops ){
144689 WhereLoop *p = pWInfo->pLoops;
144690 pWInfo->pLoops = p->pNextLoop;
144691 whereLoopDelete(db, p);
144692 }
 
144693 sqlite3DbFreeNN(db, pWInfo);
144694 }
144695
144696 /*
144697 ** Return TRUE if all of the following are true:
@@ -144888,10 +145733,12 @@
144888 WHERETRACE(0xffffffff,("=== query planner search limit reached ===\n"));
144889 if( pBuilder->pOrSet ) pBuilder->pOrSet->n = 0;
144890 return SQLITE_DONE;
144891 }
144892 pBuilder->iPlanLimit--;
 
 
144893
144894 /* If pBuilder->pOrSet is defined, then only keep track of the costs
144895 ** and prereqs.
144896 */
144897 if( pBuilder->pOrSet!=0 ){
@@ -144903,29 +145750,28 @@
144903 whereOrInsert(pBuilder->pOrSet, pTemplate->prereq, pTemplate->rRun,
144904 pTemplate->nOut);
144905 #if WHERETRACE_ENABLED /* 0x8 */
144906 if( sqlite3WhereTrace & 0x8 ){
144907 sqlite3DebugPrintf(x?" or-%d: ":" or-X: ", n);
144908 whereLoopPrint(pTemplate, pBuilder->pWC);
144909 }
144910 #endif
144911 }
144912 return SQLITE_OK;
144913 }
144914
144915 /* Look for an existing WhereLoop to replace with pTemplate
144916 */
144917 whereLoopAdjustCost(pWInfo->pLoops, pTemplate);
144918 ppPrev = whereLoopFindLesser(&pWInfo->pLoops, pTemplate);
144919
144920 if( ppPrev==0 ){
144921 /* There already exists a WhereLoop on the list that is better
144922 ** than pTemplate, so just ignore pTemplate */
144923 #if WHERETRACE_ENABLED /* 0x8 */
144924 if( sqlite3WhereTrace & 0x8 ){
144925 sqlite3DebugPrintf(" skip: ");
144926 whereLoopPrint(pTemplate, pBuilder->pWC);
144927 }
144928 #endif
144929 return SQLITE_OK;
144930 }else{
144931 p = *ppPrev;
@@ -144937,16 +145783,16 @@
144937 */
144938 #if WHERETRACE_ENABLED /* 0x8 */
144939 if( sqlite3WhereTrace & 0x8 ){
144940 if( p!=0 ){
144941 sqlite3DebugPrintf("replace: ");
144942 whereLoopPrint(p, pBuilder->pWC);
144943 sqlite3DebugPrintf(" with: ");
144944 }else{
144945 sqlite3DebugPrintf(" add: ");
144946 }
144947 whereLoopPrint(pTemplate, pBuilder->pWC);
144948 }
144949 #endif
144950 if( p==0 ){
144951 /* Allocate a new WhereLoop to add to the end of the list */
144952 *ppPrev = p = sqlite3DbMallocRawNN(db, sizeof(WhereLoop));
@@ -144966,11 +145812,11 @@
144966 if( pToDel==0 ) break;
144967 *ppTail = pToDel->pNextLoop;
144968 #if WHERETRACE_ENABLED /* 0x8 */
144969 if( sqlite3WhereTrace & 0x8 ){
144970 sqlite3DebugPrintf(" delete: ");
144971 whereLoopPrint(pToDel, pBuilder->pWC);
144972 }
144973 #endif
144974 whereLoopDelete(db, pToDel);
144975 }
144976 }
@@ -145175,12 +146021,13 @@
145175 LogEst rLogSize; /* Logarithm of table size */
145176 WhereTerm *pTop = 0, *pBtm = 0; /* Top and bottom range constraints */
145177
145178 pNew = pBuilder->pNew;
145179 if( db->mallocFailed ) return SQLITE_NOMEM_BKPT;
145180 WHERETRACE(0x800, ("BEGIN %s.addBtreeIdx(%s), nEq=%d\n",
145181 pProbe->pTable->zName,pProbe->zName, pNew->u.btree.nEq));
 
145182
145183 assert( (pNew->wsFlags & WHERE_VIRTUALTABLE)==0 );
145184 assert( (pNew->wsFlags & WHERE_TOP_LIMIT)==0 );
145185 if( pNew->wsFlags & WHERE_BTM_LIMIT ){
145186 opMask = WO_LT|WO_LE;
@@ -145473,10 +146320,11 @@
145473 ** On the other hand, the extra seeks could end up being significantly
145474 ** more expensive. */
145475 assert( 42==sqlite3LogEst(18) );
145476 if( saved_nEq==saved_nSkip
145477 && saved_nEq+1<pProbe->nKeyCol
 
145478 && pProbe->noSkipScan==0
145479 && OptimizationEnabled(db, SQLITE_SkipScan)
145480 && pProbe->aiRowLogEst[saved_nEq+1]>=42 /* TUNING: Minimum for skip-scan */
145481 && (rc = whereLoopResize(db, pNew, pNew->nLTerm+1))==SQLITE_OK
145482 ){
@@ -146254,11 +147102,12 @@
146254 rc = whereLoopAddBtree(&sSubBuild, mPrereq);
146255 }
146256 if( rc==SQLITE_OK ){
146257 rc = whereLoopAddOr(&sSubBuild, mPrereq, mUnusable);
146258 }
146259 assert( rc==SQLITE_OK || sCur.n==0 );
 
146260 if( sCur.n==0 ){
146261 sSum.n = 0;
146262 break;
146263 }else if( once ){
146264 whereOrMove(&sSum, &sCur);
@@ -147584,11 +148433,11 @@
147584 int i;
147585 static const char zLabel[] = "0123456789abcdefghijklmnopqrstuvwyxz"
147586 "ABCDEFGHIJKLMNOPQRSTUVWYXZ";
147587 for(p=pWInfo->pLoops, i=0; p; p=p->pNextLoop, i++){
147588 p->cId = zLabel[i%(sizeof(zLabel)-1)];
147589 whereLoopPrint(p, sWLB.pWC);
147590 }
147591 }
147592 #endif
147593
147594 wherePathSolver(pWInfo, 0);
@@ -147624,11 +148473,11 @@
147624 break;
147625 }
147626 }
147627 sqlite3DebugPrintf("\n");
147628 for(ii=0; ii<pWInfo->nLevel; ii++){
147629 whereLoopPrint(pWInfo->a[ii].pWLoop, sWLB.pWC);
147630 }
147631 }
147632 #endif
147633
147634 /* Attempt to omit tables from the join that do not affect the result.
@@ -148016,14 +148865,30 @@
148016 for(j=pLevel->u.in.nIn, pIn=&pLevel->u.in.aInLoop[j-1]; j>0; j--, pIn--){
148017 sqlite3VdbeJumpHere(v, pIn->addrInTop+1);
148018 if( pIn->eEndLoopOp!=OP_Noop ){
148019 if( pIn->nPrefix ){
148020 assert( pLoop->wsFlags & WHERE_IN_EARLYOUT );
148021 sqlite3VdbeAddOp4Int(v, OP_IfNoHope, pLevel->iIdxCur,
148022 sqlite3VdbeCurrentAddr(v)+2,
148023 pIn->iBase, pIn->nPrefix);
148024 VdbeCoverage(v);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
148025 }
148026 sqlite3VdbeAddOp2(v, pIn->eEndLoopOp, pIn->iCur, pIn->addrInTop);
148027 VdbeCoverage(v);
148028 VdbeCoverageIf(v, pIn->eEndLoopOp==OP_Prev);
148029 VdbeCoverageIf(v, pIn->eEndLoopOp==OP_Next);
@@ -148183,10 +149048,18 @@
148183 #ifdef SQLITE_DEBUG
148184 if( db->flags & SQLITE_VdbeAddopTrace ) printf("TRANSLATE complete\n");
148185 #endif
148186 }
148187 }
 
 
 
 
 
 
 
 
148188
148189 /* Final cleanup
148190 */
148191 pParse->nQueryLoop = pWInfo->savedNQueryLoop;
148192 whereInfoFree(db, pWInfo);
@@ -148994,10 +149867,11 @@
148994 }
148995 }
148996 }
148997 if( iCol<0 ){
148998 Expr *pDup = sqlite3ExprDup(pParse->db, pExpr, 0);
 
148999 p->pSub = sqlite3ExprListAppend(pParse, p->pSub, pDup);
149000 }
149001 if( p->pSub ){
149002 assert( ExprHasProperty(pExpr, EP_Static)==0 );
149003 ExprSetProperty(pExpr, EP_Static);
@@ -149089,13 +149963,14 @@
149089 ){
149090 if( pAppend ){
149091 int i;
149092 int nInit = pList ? pList->nExpr : 0;
149093 for(i=0; i<pAppend->nExpr; i++){
 
149094 Expr *pDup = sqlite3ExprDup(pParse->db, pAppend->a[i].pExpr, 0);
149095 assert( pDup==0 || !ExprHasProperty(pDup, EP_MemToken) );
149096 if( bIntToNull && pDup && pDup->op==TK_INTEGER ){
149097 pDup->op = TK_NULL;
149098 pDup->flags &= ~(EP_IntValue|EP_IsTrue|EP_IsFalse);
149099 pDup->u.zToken = 0;
149100 }
149101 pList = sqlite3ExprListAppend(pParse, pList, pDup);
@@ -149142,11 +150017,11 @@
149142 p->selFlags |= SF_WinRewrite;
149143
149144 /* Create the ORDER BY clause for the sub-select. This is the concatenation
149145 ** of the window PARTITION and ORDER BY clauses. Then, if this makes it
149146 ** redundant, remove the ORDER BY from the parent SELECT. */
149147 pSort = sqlite3ExprListDup(db, pMWin->pPartition, 0);
149148 pSort = exprListAppendList(pParse, pSort, pMWin->pOrderBy, 1);
149149 if( pSort && p->pOrderBy && p->pOrderBy->nExpr<=pSort->nExpr ){
149150 int nSave = pSort->nExpr;
149151 pSort->nExpr = p->pOrderBy->nExpr;
149152 if( sqlite3ExprListCompare(pSort, p->pOrderBy, -1)==0 ){
@@ -149226,14 +150101,10 @@
149226 memcpy(pTab, pTab2, sizeof(Table));
149227 pTab->tabFlags |= TF_Ephemeral;
149228 p->pSrc->a[0].pTab = pTab;
149229 pTab = pTab2;
149230 }
149231 sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pMWin->iEphCsr, pSublist->nExpr);
149232 sqlite3VdbeAddOp2(v, OP_OpenDup, pMWin->iEphCsr+1, pMWin->iEphCsr);
149233 sqlite3VdbeAddOp2(v, OP_OpenDup, pMWin->iEphCsr+2, pMWin->iEphCsr);
149234 sqlite3VdbeAddOp2(v, OP_OpenDup, pMWin->iEphCsr+3, pMWin->iEphCsr);
149235 }else{
149236 sqlite3SelectDelete(db, pSub);
149237 }
149238 if( db->mallocFailed ) rc = SQLITE_NOMEM;
149239 sqlite3DbFree(db, pTab);
@@ -149476,25 +150347,33 @@
149476 pWin->ppThis = &pSel->pWin;
149477 }
149478 }
149479
149480 /*
149481 ** Return 0 if the two window objects are identical, or non-zero otherwise.
149482 ** Identical window objects can be processed in a single scan.
 
149483 */
149484 SQLITE_PRIVATE int sqlite3WindowCompare(Parse *pParse, Window *p1, Window *p2, int bFilter){
 
149485 if( NEVER(p1==0) || NEVER(p2==0) ) return 1;
149486 if( p1->eFrmType!=p2->eFrmType ) return 1;
149487 if( p1->eStart!=p2->eStart ) return 1;
149488 if( p1->eEnd!=p2->eEnd ) return 1;
149489 if( p1->eExclude!=p2->eExclude ) return 1;
149490 if( sqlite3ExprCompare(pParse, p1->pStart, p2->pStart, -1) ) return 1;
149491 if( sqlite3ExprCompare(pParse, p1->pEnd, p2->pEnd, -1) ) return 1;
149492 if( sqlite3ExprListCompare(p1->pPartition, p2->pPartition, -1) ) return 1;
149493 if( sqlite3ExprListCompare(p1->pOrderBy, p2->pOrderBy, -1) ) return 1;
 
 
 
 
149494 if( bFilter ){
149495 if( sqlite3ExprCompare(pParse, p1->pFilter, p2->pFilter, -1) ) return 1;
 
 
149496 }
149497 return 0;
149498 }
149499
149500
@@ -149501,14 +150380,21 @@
149501 /*
149502 ** This is called by code in select.c before it calls sqlite3WhereBegin()
149503 ** to begin iterating through the sub-query results. It is used to allocate
149504 ** and initialize registers and cursors used by sqlite3WindowCodeStep().
149505 */
149506 SQLITE_PRIVATE void sqlite3WindowCodeInit(Parse *pParse, Window *pMWin){
 
 
149507 Window *pWin;
149508 Vdbe *v = sqlite3GetVdbe(pParse);
149509
 
 
 
 
 
149510 /* Allocate registers to use for PARTITION BY values, if any. Initialize
149511 ** said registers to NULL. */
149512 if( pMWin->pPartition ){
149513 int nExpr = pMWin->pPartition->nExpr;
149514 pMWin->regPart = pParse->nMem+1;
@@ -149770,11 +150656,11 @@
149770
149771 assert( bInverse==0 || pWin->eStart!=TK_UNBOUNDED );
149772
149773 /* All OVER clauses in the same window function aggregate step must
149774 ** be the same. */
149775 assert( pWin==pMWin || sqlite3WindowCompare(pParse,pWin,pMWin,0)==0 );
149776
149777 for(i=0; i<nArg; i++){
149778 if( i!=1 || pFunc->zName!=nth_valueName ){
149779 sqlite3VdbeAddOp3(v, OP_Column, csr, pWin->iArgCol+i, reg+i);
149780 }else{
@@ -158619,10 +159505,13 @@
158619 ** the lookaside memory.
158620 */
158621 static int setupLookaside(sqlite3 *db, void *pBuf, int sz, int cnt){
158622 #ifndef SQLITE_OMIT_LOOKASIDE
158623 void *pStart;
 
 
 
158624
158625 if( sqlite3LookasideUsed(db,0)>0 ){
158626 return SQLITE_BUSY;
158627 }
158628 /* Free any existing lookaside buffer for this handle before
@@ -158641,15 +159530,30 @@
158641 if( sz==0 || cnt==0 ){
158642 sz = 0;
158643 pStart = 0;
158644 }else if( pBuf==0 ){
158645 sqlite3BeginBenignMalloc();
158646 pStart = sqlite3Malloc( sz*(sqlite3_int64)cnt ); /* IMP: R-61949-35727 */
158647 sqlite3EndBenignMalloc();
158648 if( pStart ) cnt = sqlite3MallocSize(pStart)/sz;
158649 }else{
158650 pStart = pBuf;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
158651 }
158652 db->lookaside.pStart = pStart;
158653 db->lookaside.pInit = 0;
158654 db->lookaside.pFree = 0;
158655 db->lookaside.sz = (u16)sz;
@@ -158656,28 +159560,45 @@
158656 db->lookaside.szTrue = (u16)sz;
158657 if( pStart ){
158658 int i;
158659 LookasideSlot *p;
158660 assert( sz > (int)sizeof(LookasideSlot*) );
158661 db->lookaside.nSlot = cnt;
158662 p = (LookasideSlot*)pStart;
158663 for(i=cnt-1; i>=0; i--){
158664 p->pNext = db->lookaside.pInit;
158665 db->lookaside.pInit = p;
158666 p = (LookasideSlot*)&((u8*)p)[sz];
158667 }
 
 
 
 
 
 
 
 
 
 
 
158668 db->lookaside.pEnd = p;
158669 db->lookaside.bDisable = 0;
158670 db->lookaside.bMalloced = pBuf==0 ?1:0;
 
158671 }else{
158672 db->lookaside.pStart = db;
 
 
 
 
 
158673 db->lookaside.pEnd = db;
158674 db->lookaside.bDisable = 1;
158675 db->lookaside.sz = 0;
158676 db->lookaside.bMalloced = 0;
158677 db->lookaside.nSlot = 0;
158678 }
 
158679 #endif /* SQLITE_OMIT_LOOKASIDE */
158680 return SQLITE_OK;
158681 }
158682
158683 /*
@@ -158788,10 +159709,11 @@
158788 SQLITE_NoSchemaError },
158789 { SQLITE_DBCONFIG_LEGACY_ALTER_TABLE, SQLITE_LegacyAlter },
158790 { SQLITE_DBCONFIG_DQS_DDL, SQLITE_DqsDDL },
158791 { SQLITE_DBCONFIG_DQS_DML, SQLITE_DqsDML },
158792 { SQLITE_DBCONFIG_LEGACY_FILE_FORMAT, SQLITE_LegacyFileFmt },
 
158793 };
158794 unsigned int i;
158795 rc = SQLITE_ERROR; /* IMP: R-42790-23372 */
158796 for(i=0; i<ArraySize(aFlagOp); i++){
158797 if( aFlagOp[i].op==op ){
@@ -159659,12 +160581,19 @@
159659 return SQLITE_MISUSE_BKPT;
159660 }
159661
159662 assert( SQLITE_FUNC_CONSTANT==SQLITE_DETERMINISTIC );
159663 assert( SQLITE_FUNC_DIRECT==SQLITE_DIRECTONLY );
159664 extraFlags = enc & (SQLITE_DETERMINISTIC|SQLITE_DIRECTONLY|SQLITE_SUBTYPE);
 
159665 enc &= (SQLITE_FUNC_ENCMASK|SQLITE_ANY);
 
 
 
 
 
 
159666
159667 #ifndef SQLITE_OMIT_UTF16
159668 /* If SQLITE_UTF16 is specified as the encoding type, transform this
159669 ** to one of SQLITE_UTF16LE or SQLITE_UTF16BE using the
159670 ** SQLITE_UTF16NATIVE macro. SQLITE_UTF16 is not used internally.
@@ -159674,15 +160603,17 @@
159674 */
159675 if( enc==SQLITE_UTF16 ){
159676 enc = SQLITE_UTF16NATIVE;
159677 }else if( enc==SQLITE_ANY ){
159678 int rc;
159679 rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF8|extraFlags,
 
159680 pUserData, xSFunc, xStep, xFinal, xValue, xInverse, pDestructor);
159681 if( rc==SQLITE_OK ){
159682 rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF16LE|extraFlags,
159683 pUserData, xSFunc, xStep, xFinal, xValue, xInverse, pDestructor);
 
159684 }
159685 if( rc!=SQLITE_OK ){
159686 return rc;
159687 }
159688 enc = SQLITE_UTF16BE;
@@ -161018,11 +161949,13 @@
161018 db->nMaxSorterMmap = 0x7FFFFFFF;
161019 db->flags |= SQLITE_ShortColNames
161020 | SQLITE_EnableTrigger
161021 | SQLITE_EnableView
161022 | SQLITE_CacheSpill
161023
 
 
161024 /* The SQLITE_DQS compile-time option determines the default settings
161025 ** for SQLITE_DBCONFIG_DQS_DDL and SQLITE_DBCONFIG_DQS_DML.
161026 **
161027 ** SQLITE_DQS SQLITE_DBCONFIG_DQS_DDL SQLITE_DBCONFIG_DQS_DML
161028 ** ---------- ----------------------- -----------------------
@@ -161247,10 +162180,17 @@
161247 #ifdef SQLITE_ENABLE_STMTVTAB
161248 if( !db->mallocFailed && rc==SQLITE_OK){
161249 rc = sqlite3StmtVtabInit(db);
161250 }
161251 #endif
 
 
 
 
 
 
 
161252
161253 /* -DSQLITE_DEFAULT_LOCKING_MODE=1 makes EXCLUSIVE the default locking
161254 ** mode. -DSQLITE_DEFAULT_LOCKING_MODE=0 make NORMAL the default locking
161255 ** mode. Doing nothing at all also makes NORMAL the default.
161256 */
@@ -161980,19 +162920,18 @@
161980 case SQLITE_TESTCTRL_LOCALTIME_FAULT: {
161981 sqlite3GlobalConfig.bLocaltimeFault = va_arg(ap, int);
161982 break;
161983 }
161984
161985 /* sqlite3_test_control(SQLITE_TESTCTRL_INTERNAL_FUNCS, int onoff);
161986 **
161987 ** If parameter onoff is non-zero, internal-use-only SQL functions
161988 ** are visible to ordinary SQL. This is useful for testing but is
161989 ** unsafe because invalid parameters to those internal-use-only functions
161990 ** can result in crashes or segfaults.
161991 */
161992 case SQLITE_TESTCTRL_INTERNAL_FUNCTIONS: {
161993 sqlite3GlobalConfig.bInternalFunctions = va_arg(ap, int);
 
161994 break;
161995 }
161996
161997 /* sqlite3_test_control(SQLITE_TESTCTRL_NEVER_CORRUPT, int);
161998 **
@@ -173136,11 +174075,11 @@
173136 Fts3Hash *pHash,
173137 const char *zName
173138 ){
173139 int rc = SQLITE_OK;
173140 void *p = (void *)pHash;
173141 const int any = SQLITE_ANY;
173142
173143 #ifdef SQLITE_TEST
173144 char *zTest = 0;
173145 char *zTest2 = 0;
173146 void *pdb = (void *)db;
@@ -174208,11 +175147,11 @@
174208 ** of the oldest level in the db that contains at least ? segments. Or,
174209 ** if no level in the FTS index contains more than ? segments, the statement
174210 ** returns zero rows. */
174211 /* 28 */ "SELECT level, count(*) AS cnt FROM %Q.'%q_segdir' "
174212 " GROUP BY level HAVING cnt>=?"
174213 " ORDER BY (level %% 1024) ASC LIMIT 1",
174214
174215 /* Estimate the upper limit on the number of leaf nodes in a new segment
174216 ** created by merging the oldest :2 segments from absolute level :1. See
174217 ** function sqlite3Fts3Incrmerge() for details. */
174218 /* 29 */ "SELECT 2 * total(1 + leaves_end_block - start_block) "
@@ -178804,12 +179743,18 @@
178804 sqlite3_int64 iHintAbsLevel = 0; /* Hint level */
178805 int nHintSeg = 0; /* Hint number of segments */
178806
178807 rc = fts3IncrmergeHintPop(&hint, &iHintAbsLevel, &nHintSeg);
178808 if( nSeg<0 || (iAbsLevel % nMod) >= (iHintAbsLevel % nMod) ){
 
 
 
 
 
 
178809 iAbsLevel = iHintAbsLevel;
178810 nSeg = nHintSeg;
178811 bUseHint = 1;
178812 bDirtyHint = 1;
178813 }else{
178814 /* This undoes the effect of the HintPop() above - so that no entry
178815 ** is removed from the hint blob. */
@@ -178818,11 +179763,11 @@
178818 }
178819
178820 /* If nSeg is less that zero, then there is no level with at least
178821 ** nMin segments and no hint in the %_stat table. No work to do.
178822 ** Exit early in this case. */
178823 if( nSeg<0 ) break;
178824
178825 /* Open a cursor to iterate through the contents of the oldest nSeg
178826 ** indexes of absolute level iAbsLevel. If this cursor is opened using
178827 ** the 'hint' parameters, it is possible that there are less than nSeg
178828 ** segments available in level iAbsLevel. In this case, no work is
@@ -180205,11 +181150,11 @@
180205 if( rc==SQLITE_OK ){
180206
180207 /* Set the *pmSeen output variable. */
180208 for(i=0; i<nList; i++){
180209 if( sIter.aPhrase[i].pHead ){
180210 *pmSeen |= (u64)1 << i;
180211 }
180212 }
180213
180214 /* Loop through all candidate snippets. Store the best snippet in
180215 ** *pFragment. Store its associated 'score' in iBestScore.
@@ -184272,10 +185217,11 @@
184272 "json HIDDEN,root HIDDEN)");
184273 if( rc==SQLITE_OK ){
184274 pNew = *ppVtab = sqlite3_malloc( sizeof(*pNew) );
184275 if( pNew==0 ) return SQLITE_NOMEM;
184276 memset(pNew, 0, sizeof(*pNew));
 
184277 }
184278 return rc;
184279 }
184280
184281 /* destructor for json_each virtual table */
@@ -184762,20 +185708,23 @@
184762 } aMod[] = {
184763 { "json_each", &jsonEachModule },
184764 { "json_tree", &jsonTreeModule },
184765 };
184766 #endif
 
 
 
 
184767 for(i=0; i<sizeof(aFunc)/sizeof(aFunc[0]) && rc==SQLITE_OK; i++){
184768 rc = sqlite3_create_function(db, aFunc[i].zName, aFunc[i].nArg,
184769 SQLITE_UTF8 | SQLITE_DETERMINISTIC,
184770 (void*)&aFunc[i].flag,
184771 aFunc[i].xFunc, 0, 0);
184772 }
184773 #ifndef SQLITE_OMIT_WINDOWFUNC
184774 for(i=0; i<sizeof(aAgg)/sizeof(aAgg[0]) && rc==SQLITE_OK; i++){
184775 rc = sqlite3_create_window_function(db, aAgg[i].zName, aAgg[i].nArg,
184776 SQLITE_SUBTYPE | SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0,
184777 aAgg[i].xStep, aAgg[i].xFinal,
184778 aAgg[i].xValue, jsonGroupInverse, 0);
184779 }
184780 #endif
184781 #ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -190941,18 +191890,24 @@
190941 } aAgg[] = {
190942 { geopolyBBoxStep, geopolyBBoxFinal, "geopoly_group_bbox" },
190943 };
190944 int i;
190945 for(i=0; i<sizeof(aFunc)/sizeof(aFunc[0]) && rc==SQLITE_OK; i++){
190946 int enc = aFunc[i].bPure ? SQLITE_UTF8|SQLITE_DETERMINISTIC : SQLITE_UTF8;
 
 
 
 
 
190947 rc = sqlite3_create_function(db, aFunc[i].zName, aFunc[i].nArg,
190948 enc, 0,
190949 aFunc[i].xFunc, 0, 0);
190950 }
190951 for(i=0; i<sizeof(aAgg)/sizeof(aAgg[0]) && rc==SQLITE_OK; i++){
190952 rc = sqlite3_create_function(db, aAgg[i].zName, 1, SQLITE_UTF8, 0,
190953 0, aAgg[i].xStep, aAgg[i].xFinal);
 
190954 }
190955 if( rc==SQLITE_OK ){
190956 rc = sqlite3_create_module_v2(db, "geopoly", &geopolyModule, 0, 0);
190957 }
190958 return rc;
@@ -191638,30 +192593,31 @@
191638
191639 /*
191640 ** Register the ICU extension functions with database db.
191641 */
191642 SQLITE_PRIVATE int sqlite3IcuInit(sqlite3 *db){
 
191643 static const struct IcuScalar {
191644 const char *zName; /* Function name */
191645 unsigned char nArg; /* Number of arguments */
191646 unsigned short enc; /* Optimal text encoding */
191647 unsigned char iContext; /* sqlite3_user_data() context */
191648 void (*xFunc)(sqlite3_context*,int,sqlite3_value**);
191649 } scalars[] = {
191650 {"icu_load_collation", 2, SQLITE_UTF8, 1, icuLoadCollation},
191651 #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_ICU)
191652 {"regexp", 2, SQLITE_ANY|SQLITE_DETERMINISTIC, 0, icuRegexpFunc},
191653 {"lower", 1, SQLITE_UTF16|SQLITE_DETERMINISTIC, 0, icuCaseFunc16},
191654 {"lower", 2, SQLITE_UTF16|SQLITE_DETERMINISTIC, 0, icuCaseFunc16},
191655 {"upper", 1, SQLITE_UTF16|SQLITE_DETERMINISTIC, 1, icuCaseFunc16},
191656 {"upper", 2, SQLITE_UTF16|SQLITE_DETERMINISTIC, 1, icuCaseFunc16},
191657 {"lower", 1, SQLITE_UTF8|SQLITE_DETERMINISTIC, 0, icuCaseFunc16},
191658 {"lower", 2, SQLITE_UTF8|SQLITE_DETERMINISTIC, 0, icuCaseFunc16},
191659 {"upper", 1, SQLITE_UTF8|SQLITE_DETERMINISTIC, 1, icuCaseFunc16},
191660 {"upper", 2, SQLITE_UTF8|SQLITE_DETERMINISTIC, 1, icuCaseFunc16},
191661 {"like", 2, SQLITE_UTF8|SQLITE_DETERMINISTIC, 0, icuLikeFunc},
191662 {"like", 3, SQLITE_UTF8|SQLITE_DETERMINISTIC, 0, icuLikeFunc},
191663 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_ICU) */
191664 };
191665 int rc = SQLITE_OK;
191666 int i;
191667
@@ -198070,10 +199026,11 @@
198070 return SQLITE_ERROR;
198071 }
198072 }else{
198073 iDb = 0;
198074 }
 
198075 rc = sqlite3_declare_vtab(db, zDbstatSchema);
198076 if( rc==SQLITE_OK ){
198077 pTab = (StatTable *)sqlite3_malloc64(sizeof(StatTable));
198078 if( pTab==0 ) rc = SQLITE_NOMEM_BKPT;
198079 }
@@ -198140,21 +199097,18 @@
198140 }
198141 }
198142 i = 0;
198143 if( iSchema>=0 ){
198144 pIdxInfo->aConstraintUsage[iSchema].argvIndex = ++i;
198145 pIdxInfo->aConstraintUsage[iSchema].omit = 1;
198146 pIdxInfo->idxNum |= 0x01;
198147 }
198148 if( iName>=0 ){
198149 pIdxInfo->aConstraintUsage[iName].argvIndex = ++i;
198150 pIdxInfo->aConstraintUsage[iName].omit = 1;
198151 pIdxInfo->idxNum |= 0x02;
198152 }
198153 if( iAgg>=0 ){
198154 pIdxInfo->aConstraintUsage[iAgg].argvIndex = ++i;
198155 pIdxInfo->aConstraintUsage[iAgg].omit = 1;
198156 pIdxInfo->idxNum |= 0x04;
198157 }
198158 pIdxInfo->estimatedCost = 1.0;
198159
198160 /* Records are always returned in ascending order of (name, path).
@@ -198606,13 +199560,13 @@
198606 if( idxNum & 0x01 ){
198607 /* schema=? constraint is present. Get its value */
198608 const char *zDbase = (const char*)sqlite3_value_text(argv[iArg++]);
198609 pCsr->iDb = sqlite3FindDbName(pTab->db, zDbase);
198610 if( pCsr->iDb<0 ){
198611 sqlite3_free(pCursor->pVtab->zErrMsg);
198612 pCursor->pVtab->zErrMsg = sqlite3_mprintf("no such schema: %s", zDbase);
198613 return pCursor->pVtab->zErrMsg ? SQLITE_ERROR : SQLITE_NOMEM_BKPT;
198614 }
198615 }else{
198616 pCsr->iDb = pTab->iDb;
198617 }
198618 if( idxNum & 0x02 ){
@@ -198831,10 +199785,11 @@
198831 char **pzErr
198832 ){
198833 DbpageTable *pTab = 0;
198834 int rc = SQLITE_OK;
198835
 
198836 rc = sqlite3_declare_vtab(db,
198837 "CREATE TABLE x(pgno INTEGER PRIMARY KEY, data BLOB, schema HIDDEN)");
198838 if( rc==SQLITE_OK ){
198839 pTab = (DbpageTable *)sqlite3_malloc64(sizeof(DbpageTable));
198840 if( pTab==0 ) rc = SQLITE_NOMEM_BKPT;
@@ -220005,11 +220960,14 @@
220005 break;
220006
220007 case FTS5_ROLLBACKTO:
220008 assert( p->ts.eState==1 );
220009 assert( iSavepoint>=-1 );
220010 assert( iSavepoint<=p->ts.iSavepoint );
 
 
 
220011 p->ts.iSavepoint = iSavepoint;
220012 break;
220013 }
220014 }
220015 #else
@@ -222455,11 +223413,11 @@
222455 int nArg, /* Number of args */
222456 sqlite3_value **apUnused /* Function arguments */
222457 ){
222458 assert( nArg==0 );
222459 UNUSED_PARAM2(nArg, apUnused);
222460 sqlite3_result_text(pCtx, "fts5: 2019-12-26 01:10:17 f482a4cdfa768941e22c399de8ec29a55e729529eeae86d3832077ad1bef22f3", -1, SQLITE_TRANSIENT);
222461 }
222462
222463 /*
222464 ** Return true if zName is the extension on one of the shadow tables used
222465 ** by this module.
@@ -227228,12 +228186,12 @@
227228 }
227229 #endif /* SQLITE_CORE */
227230 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
227231
227232 /************** End of stmt.c ************************************************/
227233 #if __LINE__!=227233
227234 #undef SQLITE_SOURCE_ID
227235 #define SQLITE_SOURCE_ID "2019-12-26 01:10:17 f482a4cdfa768941e22c399de8ec29a55e729529eeae86d3832077ad1befalt2"
227236 #endif
227237 /* Return the source-id for this library */
227238 SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
227239 /************************** End of sqlite3.c ******************************/
227240
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1165,11 +1165,11 @@
1165 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
1166 ** [sqlite_version()] and [sqlite_source_id()].
1167 */
1168 #define SQLITE_VERSION "3.31.0"
1169 #define SQLITE_VERSION_NUMBER 3031000
1170 #define SQLITE_SOURCE_ID "2020-01-09 20:44:37 5720924cb07766cd54fb042da58f4b4acf12b60029fba86a23a606ad0d0f7c68"
1171
1172 /*
1173 ** CAPI3REF: Run-Time Library Version Numbers
1174 ** KEYWORDS: sqlite3_version sqlite3_sourceid
1175 **
@@ -1576,10 +1576,11 @@
1576 #define SQLITE_CONSTRAINT_PRIMARYKEY (SQLITE_CONSTRAINT | (6<<8))
1577 #define SQLITE_CONSTRAINT_TRIGGER (SQLITE_CONSTRAINT | (7<<8))
1578 #define SQLITE_CONSTRAINT_UNIQUE (SQLITE_CONSTRAINT | (8<<8))
1579 #define SQLITE_CONSTRAINT_VTAB (SQLITE_CONSTRAINT | (9<<8))
1580 #define SQLITE_CONSTRAINT_ROWID (SQLITE_CONSTRAINT |(10<<8))
1581 #define SQLITE_CONSTRAINT_PINNED (SQLITE_CONSTRAINT |(11<<8))
1582 #define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8))
1583 #define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8))
1584 #define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8))
1585 #define SQLITE_AUTH_USER (SQLITE_AUTH | (1<<8))
1586 #define SQLITE_OK_LOAD_PERMANENTLY (SQLITE_OK | (1<<8))
@@ -3303,10 +3304,29 @@
3304 ** the legacy [double-quoted string literal] misfeature for DDL statements,
3305 ** such as CREATE TABLE and CREATE INDEX. The
3306 ** default value of this setting is determined by the [-DSQLITE_DQS]
3307 ** compile-time option.
3308 ** </dd>
3309 **
3310 ** [[SQLITE_DBCONFIG_TRUSTED_SCHEMA]]
3311 ** <dt>SQLITE_DBCONFIG_TRUSTED_SCHEMA</td>
3312 ** <dd>The SQLITE_DBCONFIG_TRUSTED_SCHEMA option tells the SQLite to
3313 ** assume that database schemas are untainted by malicious content.
3314 ** When the SQLITE_DBCONFIG_TRUSTED_SCHEMA option is disabled, SQLite
3315 ** takes additional defensive steps to protect the application from harm
3316 ** including, but not limited to, the following:
3317 ** <ul>
3318 ** <li> Prohibit the use of SQL functions inside triggers, views,
3319 ** CHECK constraints, DEFAULT VALUEs, index definitions, and/or
3320 ** generated columns unless those functions are tagged
3321 ** with [SQLITE_INNOCUOUS].
3322 ** <li> Pohibit the use of virtual tables inside of triggers and/or views
3323 ** unless those virtual tables are tagged with [SQLITE_VTAB_INNOCUOUS].
3324 ** </ul>
3325 ** This setting defaults to "on" for legacy compatibility, however
3326 ** all applications are advised to turn it off if possible.
3327 ** </dd>
3328 **
3329 ** [[SQLITE_DBCONFIG_LEGACY_FILE_FORMAT]]
3330 ** <dt>SQLITE_DBCONFIG_LEGACY_FILE_FORMAT</td>
3331 ** <dd>The SQLITE_DBCONFIG_LEGACY_FILE_FORMAT option activates or deactivates
3332 ** the legacy file format flag. When activated, this flag causes all newly
@@ -3344,11 +3364,12 @@
3364 #define SQLITE_DBCONFIG_LEGACY_ALTER_TABLE 1012 /* int int* */
3365 #define SQLITE_DBCONFIG_DQS_DML 1013 /* int int* */
3366 #define SQLITE_DBCONFIG_DQS_DDL 1014 /* int int* */
3367 #define SQLITE_DBCONFIG_ENABLE_VIEW 1015 /* int int* */
3368 #define SQLITE_DBCONFIG_LEGACY_FILE_FORMAT 1016 /* int int* */
3369 #define SQLITE_DBCONFIG_TRUSTED_SCHEMA 1017 /* int int* */
3370 #define SQLITE_DBCONFIG_MAX 1017 /* Largest DBCONFIG */
3371
3372 /*
3373 ** CAPI3REF: Enable Or Disable Extended Result Codes
3374 ** METHOD: sqlite3
3375 **
@@ -6035,16 +6056,30 @@
6056 ** [SQLITE_UTF8 | preferred text encoding] as the fourth argument
6057 ** to [sqlite3_create_function()], [sqlite3_create_function16()], or
6058 ** [sqlite3_create_function_v2()].
6059 **
6060 ** The SQLITE_DETERMINISTIC flag means that the new function always gives
6061 ** the same output when the input parameters are the same.
6062 ** The [abs|abs() function] is deterministic, for example, but
6063 ** [randomblob|randomblob()] is not. Functions must
6064 ** be deterministic in order to be used in certain contexts such as
6065 ** [CHECK constraints] or [generated columns]. SQLite might also optimize
6066 ** deterministic functions by factoring them out of inner loops.
6067 **
6068 ** The SQLITE_INNOCUOUS flag means that the new function is unlikely
6069 ** to cause problems even if misused. An innocuous function should have
6070 ** no side effects and consume few resources. The [abs|abs() function]
6071 ** is an example of an innocuous function.
6072 ** The [load_extension() SQL function] is not innocuous because of its
6073 ** side effects. Some heightened security settings
6074 ** ([SQLITE_DBCONFIG_UNSAFE_FUNC_IN_VIEW])
6075 ** disable the use of SQLlfunctions inside views and triggers unless
6076 ** the function is tagged with SQLITE_INNOCUOUS. Most built-in functions
6077 ** are innocuous. Developers are advised to avoid using the
6078 ** SQLITE_INNOCUOUS flag for application-defined functions unless the
6079 ** function is specifically intended for use inside of views and triggers.
6080 **
6081 ** The SQLITE_DIRECTONLY flag means that the function may only be invoked
6082 ** from top-level SQL, and cannot be used in VIEWs or TRIGGERs. This is
6083 ** a security feature which is recommended for all
6084 ** [application-defined SQL functions] that have side-effects. This flag
6085 ** prevents an attacker from adding triggers and views to a schema then
@@ -6060,10 +6095,11 @@
6095 ** sqlite3_value_subtype() will always return 0).
6096 */
6097 #define SQLITE_DETERMINISTIC 0x000000800
6098 #define SQLITE_DIRECTONLY 0x000080000
6099 #define SQLITE_SUBTYPE 0x000100000
6100 #define SQLITE_INNOCUOUS 0x000200000
6101
6102 /*
6103 ** CAPI3REF: Deprecated Functions
6104 ** DEPRECATED
6105 **
@@ -6591,31 +6627,32 @@
6627 ** <li> [SQLITE_UTF16BE],
6628 ** <li> [SQLITE_UTF16], or
6629 ** <li> [SQLITE_UTF16_ALIGNED].
6630 ** </ul>)^
6631 ** ^The eTextRep argument determines the encoding of strings passed
6632 ** to the collating function callback, xCompare.
6633 ** ^The [SQLITE_UTF16] and [SQLITE_UTF16_ALIGNED] values for eTextRep
6634 ** force strings to be UTF16 with native byte order.
6635 ** ^The [SQLITE_UTF16_ALIGNED] value for eTextRep forces strings to begin
6636 ** on an even byte address.
6637 **
6638 ** ^The fourth argument, pArg, is an application data pointer that is passed
6639 ** through as the first argument to the collating function callback.
6640 **
6641 ** ^The fifth argument, xCompare, is a pointer to the collating function.
6642 ** ^Multiple collating functions can be registered using the same name but
6643 ** with different eTextRep parameters and SQLite will use whichever
6644 ** function requires the least amount of data transformation.
6645 ** ^If the xCompare argument is NULL then the collating function is
6646 ** deleted. ^When all collating functions having the same name are deleted,
6647 ** that collation is no longer usable.
6648 **
6649 ** ^The collating function callback is invoked with a copy of the pArg
6650 ** application data pointer and with two strings in the encoding specified
6651 ** by the eTextRep argument. The two integer parameters to the collating
6652 ** function callback are the length of the two strings, in bytes. The collating
6653 ** function must return an integer that is negative, zero, or positive
6654 ** if the first string is less than, equal to, or greater than the second,
6655 ** respectively. A collating function must always return the same answer
6656 ** given the same inputs. If two or more collating functions are registered
6657 ** to the same collation name (using different eTextRep values) then all
6658 ** must give an equivalent answer when invoked with equivalent strings.
@@ -9907,11 +9944,11 @@
9944 ** [sqlite3_vtab_config()] interface that [virtual table] implementations
9945 ** can use to customize and optimize their behavior.
9946 **
9947 ** <dl>
9948 ** [[SQLITE_VTAB_CONSTRAINT_SUPPORT]]
9949 ** <dt>SQLITE_VTAB_CONSTRAINT_SUPPORT</dt>
9950 ** <dd>Calls of the form
9951 ** [sqlite3_vtab_config](db,SQLITE_VTAB_CONSTRAINT_SUPPORT,X) are supported,
9952 ** where X is an integer. If X is zero, then the [virtual table] whose
9953 ** [xCreate] or [xConnect] method invoked [sqlite3_vtab_config()] does not
9954 ** support constraints. In this configuration (which is the default) if
@@ -9936,13 +9973,35 @@
9973 ** CONFLICT policy is REPLACE, the virtual table implementation should
9974 ** silently replace the appropriate rows within the xUpdate callback and
9975 ** return SQLITE_OK. Or, if this is not possible, it may return
9976 ** SQLITE_CONSTRAINT, in which case SQLite falls back to OR ABORT
9977 ** constraint handling.
9978 ** </dd>
9979 **
9980 ** [[SQLITE_VTAB_INNOCUOUS]]<dt>SQLITE_VTAB_INNOCUOUS</dt>
9981 ** <dd>Calls of the form
9982 ** [sqlite3_vtab_config](db,SQLITE_VTAB_INNOCUOUS) from within the
9983 ** the [xConnect] or [xCreate] methods of a [virtual table] implmentation
9984 ** identify that virtual table as being safe to use from within triggers
9985 ** and views. Conceptually, the SQLITE_VTAB_INNOCUOUS tag means that the
9986 ** virtual table can do no serious harm even if it is controlled by a
9987 ** malicious hacker. Developers should avoid setting the SQLITE_VTAB_INNOCUOUS
9988 ** flag unless absolutely necessary.
9989 ** </dd>
9990 **
9991 ** [[SQLITE_VTAB_DIRECTONLY]]<dt>SQLITE_VTAB_DIRECTONLY</dt>
9992 ** <dd>Calls of the form
9993 ** [sqlite3_vtab_config](db,SQLITE_VTAB_DIRECTONLY) from within the
9994 ** the [xConnect] or [xCreate] methods of a [virtual table] implmentation
9995 ** prohibits that virtual table from being used from within triggers and
9996 ** views.
9997 ** </dd>
9998 ** </dl>
9999 */
10000 #define SQLITE_VTAB_CONSTRAINT_SUPPORT 1
10001 #define SQLITE_VTAB_INNOCUOUS 2
10002 #define SQLITE_VTAB_DIRECTONLY 3
10003
10004 /*
10005 ** CAPI3REF: Determine The Virtual Table Conflict Policy
10006 **
10007 ** This function may only be called from within a call to the [xUpdate] method
@@ -14415,10 +14474,11 @@
14474
14475 /*
14476 ** A bit in a Bitmask
14477 */
14478 #define MASKBIT(n) (((Bitmask)1)<<(n))
14479 #define MASKBIT64(n) (((u64)1)<<(n))
14480 #define MASKBIT32(n) (((unsigned int)1)<<(n))
14481 #define ALLBITS ((Bitmask)-1)
14482
14483 /* A VList object records a mapping between parameters/variables/wildcards
14484 ** in the SQL statement (such as $abc, @pqr, or :xyz) and the integer
@@ -14741,10 +14801,12 @@
14801 SQLITE_PRIVATE int sqlite3BtreeLast(BtCursor*, int *pRes);
14802 SQLITE_PRIVATE int sqlite3BtreeNext(BtCursor*, int flags);
14803 SQLITE_PRIVATE int sqlite3BtreeEof(BtCursor*);
14804 SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor*, int flags);
14805 SQLITE_PRIVATE i64 sqlite3BtreeIntegerKey(BtCursor*);
14806 SQLITE_PRIVATE void sqlite3BtreeCursorPin(BtCursor*);
14807 SQLITE_PRIVATE void sqlite3BtreeCursorUnpin(BtCursor*);
14808 #ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
14809 SQLITE_PRIVATE i64 sqlite3BtreeOffset(BtCursor*);
14810 #endif
14811 SQLITE_PRIVATE int sqlite3BtreePayload(BtCursor*, u32 offset, u32 amt, void*);
14812 SQLITE_PRIVATE const void *sqlite3BtreePayloadFetch(BtCursor*, u32 *pAmt);
@@ -15027,85 +15089,85 @@
15089 #define OP_IfNullRow 21 /* jump, synopsis: if P1.nullRow then r[P3]=NULL, goto P2 */
15090 #define OP_SeekLT 22 /* jump, synopsis: key=r[P3@P4] */
15091 #define OP_SeekLE 23 /* jump, synopsis: key=r[P3@P4] */
15092 #define OP_SeekGE 24 /* jump, synopsis: key=r[P3@P4] */
15093 #define OP_SeekGT 25 /* jump, synopsis: key=r[P3@P4] */
15094 #define OP_IfNotOpen 26 /* jump, synopsis: if( !csr[P1] ) goto P2 */
15095 #define OP_IfNoHope 27 /* jump, synopsis: key=r[P3@P4] */
15096 #define OP_NoConflict 28 /* jump, synopsis: key=r[P3@P4] */
15097 #define OP_NotFound 29 /* jump, synopsis: key=r[P3@P4] */
15098 #define OP_Found 30 /* jump, synopsis: key=r[P3@P4] */
15099 #define OP_SeekRowid 31 /* jump, synopsis: intkey=r[P3] */
15100 #define OP_NotExists 32 /* jump, synopsis: intkey=r[P3] */
15101 #define OP_Last 33 /* jump */
15102 #define OP_IfSmaller 34 /* jump */
15103 #define OP_SorterSort 35 /* jump */
15104 #define OP_Sort 36 /* jump */
15105 #define OP_Rewind 37 /* jump */
15106 #define OP_IdxLE 38 /* jump, synopsis: key=r[P3@P4] */
15107 #define OP_IdxGT 39 /* jump, synopsis: key=r[P3@P4] */
15108 #define OP_IdxLT 40 /* jump, synopsis: key=r[P3@P4] */
15109 #define OP_IdxGE 41 /* jump, synopsis: key=r[P3@P4] */
15110 #define OP_RowSetRead 42 /* jump, synopsis: r[P3]=rowset(P1) */
15111 #define OP_Or 43 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
15112 #define OP_And 44 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */
15113 #define OP_RowSetTest 45 /* jump, synopsis: if r[P3] in rowset(P1) goto P2 */
15114 #define OP_Program 46 /* jump */
15115 #define OP_FkIfZero 47 /* jump, synopsis: if fkctr[P1]==0 goto P2 */
15116 #define OP_IfPos 48 /* jump, synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */
15117 #define OP_IfNotZero 49 /* jump, synopsis: if r[P1]!=0 then r[P1]--, goto P2 */
15118 #define OP_IsNull 50 /* jump, same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
15119 #define OP_NotNull 51 /* jump, same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
15120 #define OP_Ne 52 /* jump, same as TK_NE, synopsis: IF r[P3]!=r[P1] */
15121 #define OP_Eq 53 /* jump, same as TK_EQ, synopsis: IF r[P3]==r[P1] */
15122 #define OP_Gt 54 /* jump, same as TK_GT, synopsis: IF r[P3]>r[P1] */
15123 #define OP_Le 55 /* jump, same as TK_LE, synopsis: IF r[P3]<=r[P1] */
15124 #define OP_Lt 56 /* jump, same as TK_LT, synopsis: IF r[P3]<r[P1] */
15125 #define OP_Ge 57 /* jump, same as TK_GE, synopsis: IF r[P3]>=r[P1] */
15126 #define OP_ElseNotEq 58 /* jump, same as TK_ESCAPE */
15127 #define OP_DecrJumpZero 59 /* jump, synopsis: if (--r[P1])==0 goto P2 */
15128 #define OP_IncrVacuum 60 /* jump */
15129 #define OP_VNext 61 /* jump */
15130 #define OP_Init 62 /* jump, synopsis: Start at P2 */
15131 #define OP_PureFunc 63 /* synopsis: r[P3]=func(r[P2@P5]) */
15132 #define OP_Function 64 /* synopsis: r[P3]=func(r[P2@P5]) */
15133 #define OP_Return 65
15134 #define OP_EndCoroutine 66
15135 #define OP_HaltIfNull 67 /* synopsis: if r[P3]=null halt */
15136 #define OP_Halt 68
15137 #define OP_Integer 69 /* synopsis: r[P2]=P1 */
15138 #define OP_Int64 70 /* synopsis: r[P2]=P4 */
15139 #define OP_String 71 /* synopsis: r[P2]='P4' (len=P1) */
15140 #define OP_Null 72 /* synopsis: r[P2..P3]=NULL */
15141 #define OP_SoftNull 73 /* synopsis: r[P1]=NULL */
15142 #define OP_Blob 74 /* synopsis: r[P2]=P4 (len=P1) */
15143 #define OP_Variable 75 /* synopsis: r[P2]=parameter(P1,P4) */
15144 #define OP_Move 76 /* synopsis: r[P2@P3]=r[P1@P3] */
15145 #define OP_Copy 77 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */
15146 #define OP_SCopy 78 /* synopsis: r[P2]=r[P1] */
15147 #define OP_IntCopy 79 /* synopsis: r[P2]=r[P1] */
15148 #define OP_ResultRow 80 /* synopsis: output=r[P1@P2] */
15149 #define OP_CollSeq 81
15150 #define OP_AddImm 82 /* synopsis: r[P1]=r[P1]+P2 */
15151 #define OP_RealAffinity 83
15152 #define OP_Cast 84 /* synopsis: affinity(r[P1]) */
15153 #define OP_Permutation 85
15154 #define OP_Compare 86 /* synopsis: r[P1@P3] <-> r[P2@P3] */
15155 #define OP_IsTrue 87 /* synopsis: r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4 */
15156 #define OP_Offset 88 /* synopsis: r[P3] = sqlite_offset(P1) */
15157 #define OP_Column 89 /* synopsis: r[P3]=PX */
15158 #define OP_Affinity 90 /* synopsis: affinity(r[P1@P2]) */
15159 #define OP_MakeRecord 91 /* synopsis: r[P3]=mkrec(r[P1@P2]) */
15160 #define OP_Count 92 /* synopsis: r[P2]=count() */
15161 #define OP_ReadCookie 93
15162 #define OP_SetCookie 94
15163 #define OP_ReopenIdx 95 /* synopsis: root=P2 iDb=P3 */
15164 #define OP_OpenRead 96 /* synopsis: root=P2 iDb=P3 */
15165 #define OP_OpenWrite 97 /* synopsis: root=P2 iDb=P3 */
15166 #define OP_OpenDup 98
15167 #define OP_OpenAutoindex 99 /* synopsis: nColumn=P2 */
15168 #define OP_OpenEphemeral 100 /* synopsis: nColumn=P2 */
15169 #define OP_BitAnd 101 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
15170 #define OP_BitOr 102 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
15171 #define OP_ShiftLeft 103 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
15172 #define OP_ShiftRight 104 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
15173 #define OP_Add 105 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
@@ -15112,71 +15174,75 @@
15174 #define OP_Subtract 106 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
15175 #define OP_Multiply 107 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
15176 #define OP_Divide 108 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
15177 #define OP_Remainder 109 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
15178 #define OP_Concat 110 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
15179 #define OP_SorterOpen 111
15180 #define OP_BitNot 112 /* same as TK_BITNOT, synopsis: r[P2]= ~r[P1] */
15181 #define OP_SequenceTest 113 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */
15182 #define OP_OpenPseudo 114 /* synopsis: P3 columns in r[P2] */
15183 #define OP_String8 115 /* same as TK_STRING, synopsis: r[P2]='P4' */
15184 #define OP_Close 116
15185 #define OP_ColumnsUsed 117
15186 #define OP_SeekHit 118 /* synopsis: seekHit=P2 */
15187 #define OP_Sequence 119 /* synopsis: r[P2]=cursor[P1].ctr++ */
15188 #define OP_NewRowid 120 /* synopsis: r[P2]=rowid */
15189 #define OP_Insert 121 /* synopsis: intkey=r[P3] data=r[P2] */
15190 #define OP_Delete 122
15191 #define OP_ResetCount 123
15192 #define OP_SorterCompare 124 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
15193 #define OP_SorterData 125 /* synopsis: r[P2]=data */
15194 #define OP_RowData 126 /* synopsis: r[P2]=data */
15195 #define OP_Rowid 127 /* synopsis: r[P2]=rowid */
15196 #define OP_NullRow 128
15197 #define OP_SeekEnd 129
15198 #define OP_SorterInsert 130 /* synopsis: key=r[P2] */
15199 #define OP_IdxInsert 131 /* synopsis: key=r[P2] */
15200 #define OP_IdxDelete 132 /* synopsis: key=r[P2@P3] */
15201 #define OP_DeferredSeek 133 /* synopsis: Move P3 to P1.rowid if needed */
15202 #define OP_IdxRowid 134 /* synopsis: r[P2]=rowid */
15203 #define OP_FinishSeek 135
15204 #define OP_Destroy 136
15205 #define OP_Clear 137
15206 #define OP_ResetSorter 138
15207 #define OP_CreateBtree 139 /* synopsis: r[P2]=root iDb=P1 flags=P3 */
15208 #define OP_SqlExec 140
15209 #define OP_ParseSchema 141
15210 #define OP_LoadAnalysis 142
15211 #define OP_DropTable 143
15212 #define OP_DropIndex 144
15213 #define OP_DropTrigger 145
15214 #define OP_IntegrityCk 146
15215 #define OP_RowSetAdd 147 /* synopsis: rowset(P1)=r[P2] */
15216 #define OP_Param 148
15217 #define OP_FkCounter 149 /* synopsis: fkctr[P1]+=P2 */
15218 #define OP_Real 150 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
15219 #define OP_MemMax 151 /* synopsis: r[P1]=max(r[P1],r[P2]) */
15220 #define OP_OffsetLimit 152 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */
15221 #define OP_AggInverse 153 /* synopsis: accum=r[P3] inverse(r[P2@P5]) */
15222 #define OP_AggStep 154 /* synopsis: accum=r[P3] step(r[P2@P5]) */
15223 #define OP_AggStep1 155 /* synopsis: accum=r[P3] step(r[P2@P5]) */
15224 #define OP_AggValue 156 /* synopsis: r[P3]=value N=P2 */
15225 #define OP_AggFinal 157 /* synopsis: accum=r[P1] N=P2 */
15226 #define OP_Expire 158
15227 #define OP_CursorLock 159
15228 #define OP_CursorUnlock 160
15229 #define OP_TableLock 161 /* synopsis: iDb=P1 root=P2 write=P3 */
15230 #define OP_VBegin 162
15231 #define OP_VCreate 163
15232 #define OP_VDestroy 164
15233 #define OP_VOpen 165
15234 #define OP_VColumn 166 /* synopsis: r[P3]=vcolumn(P2) */
15235 #define OP_VRename 167
15236 #define OP_Pagecount 168
15237 #define OP_MaxPgcnt 169
15238 #define OP_Trace 170
15239 #define OP_CursorHint 171
15240 #define OP_ReleaseReg 172 /* synopsis: release r[P1@P2] mask P3 */
15241 #define OP_Noop 173
15242 #define OP_Explain 174
15243 #define OP_Abortable 175
15244
15245 /* Properties such as "out2" or "jump" that are specified in
15246 ** comments following the "case" for each opcode in the vdbe.c
15247 ** are encoded into bitvectors as follows:
15248 */
@@ -15188,37 +15254,38 @@
15254 #define OPFLG_OUT3 0x20 /* out3: P3 is an output */
15255 #define OPFLG_INITIALIZER {\
15256 /* 0 */ 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x10,\
15257 /* 8 */ 0x00, 0x01, 0x00, 0x01, 0x01, 0x01, 0x03, 0x03,\
15258 /* 16 */ 0x01, 0x01, 0x03, 0x12, 0x03, 0x01, 0x09, 0x09,\
15259 /* 24 */ 0x09, 0x09, 0x01, 0x09, 0x09, 0x09, 0x09, 0x09,\
15260 /* 32 */ 0x09, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\
15261 /* 40 */ 0x01, 0x01, 0x23, 0x26, 0x26, 0x0b, 0x01, 0x01,\
15262 /* 48 */ 0x03, 0x03, 0x03, 0x03, 0x0b, 0x0b, 0x0b, 0x0b,\
15263 /* 56 */ 0x0b, 0x0b, 0x01, 0x03, 0x01, 0x01, 0x01, 0x00,\
15264 /* 64 */ 0x00, 0x02, 0x02, 0x08, 0x00, 0x10, 0x10, 0x10,\
15265 /* 72 */ 0x10, 0x00, 0x10, 0x10, 0x00, 0x00, 0x10, 0x10,\
15266 /* 80 */ 0x00, 0x00, 0x02, 0x02, 0x02, 0x00, 0x00, 0x12,\
15267 /* 88 */ 0x20, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\
15268 /* 96 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x26, 0x26, 0x26,\
15269 /* 104 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x00,\
15270 /* 112 */ 0x12, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x10,\
15271 /* 120 */ 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,\
15272 /* 128 */ 0x00, 0x00, 0x04, 0x04, 0x00, 0x00, 0x10, 0x00,\
15273 /* 136 */ 0x10, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00,\
15274 /* 144 */ 0x00, 0x00, 0x00, 0x06, 0x10, 0x00, 0x10, 0x04,\
15275 /* 152 */ 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
15276 /* 160 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
15277 /* 168 */ 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
15278 }
15279
15280 /* The sqlite3P2Values() routine is able to run faster if it knows
15281 ** the value of the largest JUMP opcode. The smaller the maximum
15282 ** JUMP opcode the better, so the mkopcodeh.tcl script that
15283 ** generated this include file strives to group all JUMP opcodes
15284 ** together near the beginning of the list.
15285 */
15286 #define SQLITE_MX_JUMP_OPCODE 62 /* Maximum JUMP opcode */
15287
15288 /************** End of opcodes.h *********************************************/
15289 /************** Continuing where we left off in vdbe.h ***********************/
15290
15291 /*
@@ -15284,13 +15351,13 @@
15351 SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe*, u16 P5);
15352 SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe*, int addr);
15353 SQLITE_PRIVATE int sqlite3VdbeChangeToNoop(Vdbe*, int addr);
15354 SQLITE_PRIVATE int sqlite3VdbeDeletePriorOpcode(Vdbe*, u8 op);
15355 #ifdef SQLITE_DEBUG
15356 SQLITE_PRIVATE void sqlite3VdbeReleaseRegisters(Parse*,int addr, int n, u32 mask, int);
15357 #else
15358 # define sqlite3VdbeReleaseRegisters(P,A,N,M,F)
15359 #endif
15360 SQLITE_PRIVATE void sqlite3VdbeChangeP4(Vdbe*, int addr, const char *zP4, int N);
15361 SQLITE_PRIVATE void sqlite3VdbeAppendP4(Vdbe*, void *pP4, int p4type);
15362 SQLITE_PRIVATE void sqlite3VdbeSetP4KeyInfo(Parse*, Index*);
15363 SQLITE_PRIVATE void sqlite3VdbeUsesBtree(Vdbe*, int);
@@ -16377,10 +16444,29 @@
16444 ** New lookaside allocations are only allowed if bDisable==0. When
16445 ** bDisable is greater than zero, sz is set to zero which effectively
16446 ** disables lookaside without adding a new test for the bDisable flag
16447 ** in a performance-critical path. sz should be set by to szTrue whenever
16448 ** bDisable changes back to zero.
16449 **
16450 ** Lookaside buffers are initially held on the pInit list. As they are
16451 ** used and freed, they are added back to the pFree list. New allocations
16452 ** come off of pFree first, then pInit as a fallback. This dual-list
16453 ** allows use to compute a high-water mark - the maximum number of allocations
16454 ** outstanding at any point in the past - by subtracting the number of
16455 ** allocations on the pInit list from the total number of allocations.
16456 **
16457 ** Enhancement on 2019-12-12: Two-size-lookaside
16458 ** The default lookaside configuration is 100 slots of 1200 bytes each.
16459 ** The larger slot sizes are important for performance, but they waste
16460 ** a lot of space, as most lookaside allocations are less than 128 bytes.
16461 ** The two-size-lookaside enhancement breaks up the lookaside allocation
16462 ** into two pools: One of 128-byte slots and the other of the default size
16463 ** (1200-byte) slots. Allocations are filled from the small-pool first,
16464 ** failing over to the full-size pool if that does not work. Thus more
16465 ** lookaside slots are available while also using less memory.
16466 ** This enhancement can be omitted by compiling with
16467 ** SQLITE_OMIT_TWOSIZE_LOOKASIDE.
16468 */
16469 struct Lookaside {
16470 u32 bDisable; /* Only operate the lookaside when zero */
16471 u16 sz; /* Size of each buffer in bytes */
16472 u16 szTrue; /* True value of sz, even if disabled */
@@ -16387,10 +16473,16 @@
16473 u8 bMalloced; /* True if pStart obtained from sqlite3_malloc() */
16474 u32 nSlot; /* Number of lookaside slots allocated */
16475 u32 anStat[3]; /* 0: hits. 1: size misses. 2: full misses */
16476 LookasideSlot *pInit; /* List of buffers not previously used */
16477 LookasideSlot *pFree; /* List of available buffers */
16478 #ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
16479 LookasideSlot *pSmallInit; /* List of small buffers not prediously used */
16480 LookasideSlot *pSmallFree; /* List of available small buffers */
16481 void *pMiddle; /* First byte past end of full-size buffers and
16482 ** the first byte of LOOKASIDE_SMALL buffers */
16483 #endif /* SQLITE_OMIT_TWOSIZE_LOOKASIDE */
16484 void *pStart; /* First byte of available memory space */
16485 void *pEnd; /* First byte past end of available space */
16486 };
16487 struct LookasideSlot {
16488 LookasideSlot *pNext; /* Next buffer in the list of free buffers */
@@ -16397,10 +16489,17 @@
16489 };
16490
16491 #define DisableLookaside db->lookaside.bDisable++;db->lookaside.sz=0
16492 #define EnableLookaside db->lookaside.bDisable--;\
16493 db->lookaside.sz=db->lookaside.bDisable?0:db->lookaside.szTrue
16494
16495 /* Size of the smaller allocations in two-size lookside */
16496 #ifdef SQLITE_OMIT_TWOSIZE_LOOKASIDE
16497 # define LOOKASIDE_SMALL 0
16498 #else
16499 # define LOOKASIDE_SMALL 128
16500 #endif
16501
16502 /*
16503 ** A hash table for built-in function definitions. (Application-defined
16504 ** functions use a regular table table from hash.h.)
16505 **
@@ -16606,10 +16705,17 @@
16705 ** A macro to discover the encoding of a database.
16706 */
16707 #define SCHEMA_ENC(db) ((db)->aDb[0].pSchema->enc)
16708 #define ENC(db) ((db)->enc)
16709
16710 /*
16711 ** A u64 constant where the lower 32 bits are all zeros. Only the
16712 ** upper 32 bits are included in the argument. Necessary because some
16713 ** C-compilers still do not accept LL integer literals.
16714 */
16715 #define HI(X) ((u64)(X)<<32)
16716
16717 /*
16718 ** Possible values for the sqlite3.flags.
16719 **
16720 ** Value constraints (enforced via assert()):
16721 ** SQLITE_FullFSync == PAGER_FULLFSYNC
@@ -16621,13 +16727,12 @@
16727 #define SQLITE_FullColNames 0x00000004 /* Show full column names on SELECT */
16728 #define SQLITE_FullFSync 0x00000008 /* Use full fsync on the backend */
16729 #define SQLITE_CkptFullFSync 0x00000010 /* Use full fsync for checkpoint */
16730 #define SQLITE_CacheSpill 0x00000020 /* OK to spill pager cache */
16731 #define SQLITE_ShortColNames 0x00000040 /* Show short columns names */
16732 #define SQLITE_TrustedSchema 0x00000080 /* Allow unsafe functions and
16733 ** vtabs in the schema definition */
 
16734 #define SQLITE_NullCallback 0x00000100 /* Invoke the callback once if the */
16735 /* result set is empty */
16736 #define SQLITE_IgnoreChecks 0x00000200 /* Do not enforce check constraints */
16737 #define SQLITE_ReadUncommit 0x00000400 /* READ UNCOMMITTED in shared-cache */
16738 #define SQLITE_NoCkptOnClose 0x00000800 /* No checkpoint on close()/DETACH */
@@ -16649,13 +16754,15 @@
16754 #define SQLITE_NoSchemaError 0x08000000 /* Do not report schema parse errors*/
16755 #define SQLITE_Defensive 0x10000000 /* Input SQL is likely hostile */
16756 #define SQLITE_DqsDDL 0x20000000 /* dbl-quoted strings allowed in DDL*/
16757 #define SQLITE_DqsDML 0x40000000 /* dbl-quoted strings allowed in DML*/
16758 #define SQLITE_EnableView 0x80000000 /* Enable the use of views */
16759 #define SQLITE_CountRows HI(0x00001) /* Count rows changed by INSERT, */
16760 /* DELETE, or UPDATE and return */
16761 /* the count using a callback. */
16762
16763 /* Flags used only if debugging */
 
16764 #ifdef SQLITE_DEBUG
16765 #define SQLITE_SqlTrace HI(0x0100000) /* Debug print SQL as it executes */
16766 #define SQLITE_VdbeListing HI(0x0200000) /* Debug listings of VDBE progs */
16767 #define SQLITE_VdbeTrace HI(0x0400000) /* True to trace VDBE execution */
16768 #define SQLITE_VdbeAddopTrace HI(0x0800000) /* Trace sqlite3VdbeAddOp() calls */
@@ -16669,10 +16776,11 @@
16776 #define DBFLAG_SchemaChange 0x0001 /* Uncommitted Hash table changes */
16777 #define DBFLAG_PreferBuiltin 0x0002 /* Preference to built-in funcs */
16778 #define DBFLAG_Vacuum 0x0004 /* Currently in a VACUUM */
16779 #define DBFLAG_VacuumInto 0x0008 /* Currently running VACUUM INTO */
16780 #define DBFLAG_SchemaKnownOk 0x0010 /* Schema is known to be valid */
16781 #define DBFLAG_InternalFunc 0x0020 /* Allow use of internal functions */
16782
16783 /*
16784 ** Bits of the sqlite3.dbOptFlags field that are used by the
16785 ** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface to
16786 ** selectively disable various optimizations.
@@ -16776,10 +16884,11 @@
16884 ** SQLITE_FUNC_MINMAX == NC_MinMaxAgg == SF_MinMaxAgg
16885 ** SQLITE_FUNC_LENGTH == OPFLAG_LENGTHARG
16886 ** SQLITE_FUNC_TYPEOF == OPFLAG_TYPEOFARG
16887 ** SQLITE_FUNC_CONSTANT == SQLITE_DETERMINISTIC from the API
16888 ** SQLITE_FUNC_DIRECT == SQLITE_DIRECTONLY from the API
16889 ** SQLITE_FUNC_UNSAFE == SQLITE_INNOCUOUS
16890 ** SQLITE_FUNC_ENCMASK depends on SQLITE_UTF* macros in the API
16891 */
16892 #define SQLITE_FUNC_ENCMASK 0x0003 /* SQLITE_UTF8, SQLITE_UTF16BE or UTF16LE */
16893 #define SQLITE_FUNC_LIKE 0x0004 /* Candidate for the LIKE optimization */
16894 #define SQLITE_FUNC_CASE 0x0008 /* Case-sensitive LIKE-type function */
@@ -16792,16 +16901,26 @@
16901 #define SQLITE_FUNC_UNLIKELY 0x0400 /* Built-in unlikely() function */
16902 #define SQLITE_FUNC_CONSTANT 0x0800 /* Constant inputs give a constant output */
16903 #define SQLITE_FUNC_MINMAX 0x1000 /* True for min() and max() aggregates */
16904 #define SQLITE_FUNC_SLOCHNG 0x2000 /* "Slow Change". Value constant during a
16905 ** single query - might change over time */
16906 #define SQLITE_FUNC_TEST 0x4000 /* Built-in testing functions */
16907 #define SQLITE_FUNC_OFFSET 0x8000 /* Built-in sqlite_offset() function */
16908 #define SQLITE_FUNC_WINDOW 0x00010000 /* Built-in window-only function */
16909 #define SQLITE_FUNC_INTERNAL 0x00040000 /* For use by NestedParse() only */
16910 #define SQLITE_FUNC_DIRECT 0x00080000 /* Not for use in TRIGGERs or VIEWs */
16911 #define SQLITE_FUNC_SUBTYPE 0x00100000 /* Result likely to have sub-type */
16912 #define SQLITE_FUNC_UNSAFE 0x00200000 /* Function has side effects */
16913 #define SQLITE_FUNC_INLINE 0x00400000 /* Functions implemented in-line */
16914
16915 /* Identifier numbers for each in-line function */
16916 #define INLINEFUNC_coalesce 0
16917 #define INLINEFUNC_implies_nonnull_row 1
16918 #define INLINEFUNC_expr_implies_expr 2
16919 #define INLINEFUNC_expr_compare 3
16920 #define INLINEFUNC_affinity 4
16921 #define INLINEFUNC_unlikely 99 /* Default case */
16922
16923 /*
16924 ** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are
16925 ** used to create the initializers for the FuncDef structures.
16926 **
@@ -16813,10 +16932,26 @@
16932 ** argument bNC is true, then the SQLITE_FUNC_NEEDCOLL flag is set.
16933 **
16934 ** VFUNCTION(zName, nArg, iArg, bNC, xFunc)
16935 ** Like FUNCTION except it omits the SQLITE_FUNC_CONSTANT flag.
16936 **
16937 ** SFUNCTION(zName, nArg, iArg, bNC, xFunc)
16938 ** Like FUNCTION except it omits the SQLITE_FUNC_CONSTANT flag and
16939 ** adds the SQLITE_DIRECTONLY flag.
16940 **
16941 ** INLINE_FUNC(zName, nArg, iFuncId, mFlags)
16942 ** zName is the name of a function that is implemented by in-line
16943 ** byte code rather than by the usual callbacks. The iFuncId
16944 ** parameter determines the function id. The mFlags parameter is
16945 ** optional SQLITE_FUNC_ flags for this function.
16946 **
16947 ** TEST_FUNC(zName, nArg, iFuncId, mFlags)
16948 ** zName is the name of a test-only function implemented by in-line
16949 ** byte code rather than by the usual callbacks. The iFuncId
16950 ** parameter determines the function id. The mFlags parameter is
16951 ** optional SQLITE_FUNC_ flags for this function.
16952 **
16953 ** DFUNCTION(zName, nArg, iArg, bNC, xFunc)
16954 ** Like FUNCTION except it omits the SQLITE_FUNC_CONSTANT flag and
16955 ** adds the SQLITE_FUNC_SLOCHNG flag. Used for date & time functions
16956 ** and functions like sqlite_version() that can change, but not during
16957 ** a single query. The iArg is ignored. The user-data is always set
@@ -16852,10 +16987,20 @@
16987 {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
16988 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} }
16989 #define VFUNCTION(zName, nArg, iArg, bNC, xFunc) \
16990 {nArg, SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
16991 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} }
16992 #define SFUNCTION(zName, nArg, iArg, bNC, xFunc) \
16993 {nArg, SQLITE_UTF8|SQLITE_DIRECTONLY|SQLITE_FUNC_UNSAFE, \
16994 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} }
16995 #define INLINE_FUNC(zName, nArg, iArg, mFlags) \
16996 {nArg, SQLITE_UTF8|SQLITE_FUNC_INLINE|SQLITE_FUNC_CONSTANT|(mFlags), \
16997 SQLITE_INT_TO_PTR(iArg), 0, noopFunc, 0, 0, 0, #zName, {0} }
16998 #define TEST_FUNC(zName, nArg, iArg, mFlags) \
16999 {nArg, SQLITE_UTF8|SQLITE_FUNC_INTERNAL|SQLITE_FUNC_TEST| \
17000 SQLITE_FUNC_INLINE|SQLITE_FUNC_CONSTANT|(mFlags), \
17001 SQLITE_INT_TO_PTR(iArg), 0, noopFunc, 0, 0, 0, #zName, {0} }
17002 #define DFUNCTION(zName, nArg, iArg, bNC, xFunc) \
17003 {nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8, \
17004 0, 0, xFunc, 0, 0, 0, #zName, {0} }
17005 #define PURE_DATE(zName, nArg, iArg, bNC, xFunc) \
17006 {nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|SQLITE_FUNC_CONSTANT, \
@@ -17068,13 +17213,20 @@
17213 sqlite3 *db; /* Database connection associated with this table */
17214 Module *pMod; /* Pointer to module implementation */
17215 sqlite3_vtab *pVtab; /* Pointer to vtab instance */
17216 int nRef; /* Number of pointers to this structure */
17217 u8 bConstraint; /* True if constraints are supported */
17218 u8 eVtabRisk; /* Riskiness of allowing hacker access */
17219 int iSavepoint; /* Depth of the SAVEPOINT stack */
17220 VTable *pNext; /* Next in linked list (see above) */
17221 };
17222
17223 /* Allowed values for VTable.eVtabRisk
17224 */
17225 #define SQLITE_VTABRISK_Low 0
17226 #define SQLITE_VTABRISK_Normal 1
17227 #define SQLITE_VTABRISK_High 2
17228
17229 /*
17230 ** The schema for each SQL table and view is represented in memory
17231 ** by an instance of the following structure.
17232 */
@@ -17672,11 +17824,11 @@
17824 #define EP_Subrtn 0x2000000 /* Uses Expr.y.sub. TK_IN, _SELECT, or _EXISTS */
17825 #define EP_Quoted 0x4000000 /* TK_ID was originally quoted */
17826 #define EP_Static 0x8000000 /* Held in memory not obtained from malloc() */
17827 #define EP_IsTrue 0x10000000 /* Always has boolean value of TRUE */
17828 #define EP_IsFalse 0x20000000 /* Always has boolean value of FALSE */
17829 #define EP_FromDDL 0x40000000 /* Originates from sqlite_master */
17830
17831 /*
17832 ** The EP_Propagate mask is a set of properties that automatically propagate
17833 ** upwards into parent nodes.
17834 */
@@ -17736,27 +17888,32 @@
17888 ** as the list of "expr AS ID" fields following a "SELECT" or in the
17889 ** list of "ID = expr" items in an UPDATE. A list of expressions can
17890 ** also be used as the argument to a function, in which case the a.zName
17891 ** field is not used.
17892 **
17893 ** In order to try to keep memory usage down, the Expr.a.zEName field
17894 ** is used for multiple purposes:
17895 **
17896 ** eEName Usage
17897 ** ---------- -------------------------
17898 ** ENAME_NAME (1) the AS of result set column
17899 ** (2) COLUMN= of an UPDATE
17900 **
17901 ** ENAME_TAB DB.TABLE.NAME used to resolve names
17902 ** of subqueries
17903 **
17904 ** ENAME_SPAN Text of the original result set
17905 ** expression.
17906 */
17907 struct ExprList {
17908 int nExpr; /* Number of expressions on the list */
17909 struct ExprList_item { /* For each expression in the list */
17910 Expr *pExpr; /* The parse tree for this expression */
17911 char *zEName; /* Token associated with this expression */
 
17912 u8 sortFlags; /* Mask of KEYINFO_ORDER_* flags */
17913 unsigned eEName :2; /* Meaning of zEName */
17914 unsigned done :1; /* A flag to indicate when processing is finished */
 
17915 unsigned reusable :1; /* Constant expression is reusable */
17916 unsigned bSorterRef :1; /* Defer evaluation until after sorting */
17917 unsigned bNulls: 1; /* True if explicit "NULLS FIRST/LAST" */
17918 union {
17919 struct {
@@ -17766,10 +17923,17 @@
17923 int iConstExprReg; /* Register in which Expr value is cached */
17924 } u;
17925 } a[1]; /* One slot for each expression in the list */
17926 };
17927
17928 /*
17929 ** Allowed values for Expr.a.eEName
17930 */
17931 #define ENAME_NAME 0 /* The AS clause of a result set */
17932 #define ENAME_SPAN 1 /* Complete text of the result set expression */
17933 #define ENAME_TAB 2 /* "DB.TABLE.NAME" for the result set */
17934
17935 /*
17936 ** An instance of this structure can hold a simple list of identifiers,
17937 ** such as the list "a,b,c" in the following statements:
17938 **
17939 ** INSERT INTO t(a,b,c) VALUES ...;
@@ -17829,10 +17993,11 @@
17993 unsigned isIndexedBy :1; /* True if there is an INDEXED BY clause */
17994 unsigned isTabFunc :1; /* True if table-valued-function syntax */
17995 unsigned isCorrelated :1; /* True if sub-query is correlated */
17996 unsigned viaCoroutine :1; /* Implemented as a co-routine */
17997 unsigned isRecursive :1; /* True for recursive reference in WITH */
17998 unsigned fromDDL :1; /* Comes from sqlite_master */
17999 } fg;
18000 int iCursor; /* The VDBE cursor number used to access this table */
18001 Expr *pOn; /* The ON clause of a join */
18002 IdList *pUsing; /* The USING clause of a join */
18003 Bitmask colUsed; /* Bit N (1<<N) set if column N of pTab is used */
@@ -17949,10 +18114,11 @@
18114 #define NC_Complex 0x02000 /* True if a function or subquery seen */
18115 #define NC_AllowWin 0x04000 /* Window functions are allowed here */
18116 #define NC_HasWin 0x08000 /* One or more window functions seen */
18117 #define NC_IsDDL 0x10000 /* Resolving names in a CREATE statement */
18118 #define NC_InAggFunc 0x20000 /* True if analyzing arguments to an agg func */
18119 #define NC_FromDDL 0x40000 /* SQL text comes from sqlite_master */
18120
18121 /*
18122 ** An instance of the following object describes a single ON CONFLICT
18123 ** clause in an upsert.
18124 **
@@ -18504,11 +18670,11 @@
18670 */
18671 typedef struct DbFixer DbFixer;
18672 struct DbFixer {
18673 Parse *pParse; /* The parsing context. Error messages written here */
18674 Schema *pSchema; /* Fix items to this schema */
18675 u8 bTemp; /* True for TEMP schema entries */
18676 const char *zDb; /* Make sure all objects are contained in this database */
18677 const char *zType; /* Type of the container - used for error messages */
18678 const Token *pName; /* Name of the container - used for error messages */
18679 };
18680
@@ -18609,11 +18775,10 @@
18775 #endif
18776 #ifndef SQLITE_UNTESTABLE
18777 int (*xTestCallback)(int); /* Invoked by sqlite3FaultSim() */
18778 #endif
18779 int bLocaltimeFault; /* True to fail localtime() calls */
 
18780 int iOnceResetThreshold; /* When to reset OP_Once counters */
18781 u32 szSorterRef; /* Min size in bytes to use sorter-refs */
18782 unsigned int iPrngSeed; /* Alternative fixed seed for the PRNG */
18783 };
18784
@@ -18772,11 +18937,11 @@
18937 SQLITE_PRIVATE void sqlite3WindowListDelete(sqlite3 *db, Window *p);
18938 SQLITE_PRIVATE Window *sqlite3WindowAlloc(Parse*, int, int, Expr*, int , Expr*, u8);
18939 SQLITE_PRIVATE void sqlite3WindowAttach(Parse*, Expr*, Window*);
18940 SQLITE_PRIVATE void sqlite3WindowLink(Select *pSel, Window *pWin);
18941 SQLITE_PRIVATE int sqlite3WindowCompare(Parse*, Window*, Window*, int);
18942 SQLITE_PRIVATE void sqlite3WindowCodeInit(Parse*, Select*);
18943 SQLITE_PRIVATE void sqlite3WindowCodeStep(Parse*, Select*, WhereInfo*, int, int);
18944 SQLITE_PRIVATE int sqlite3WindowRewrite(Parse*, Select*);
18945 SQLITE_PRIVATE int sqlite3ExpandSubquery(Parse*, struct SrcList_item*);
18946 SQLITE_PRIVATE void sqlite3WindowUpdate(Parse*, Window*, Window*, FuncDef*);
18947 SQLITE_PRIVATE Window *sqlite3WindowDup(sqlite3 *db, Expr *pOwner, Window *p);
@@ -19038,10 +19203,11 @@
19203 SQLITE_PRIVATE Expr *sqlite3PExpr(Parse*, int, Expr*, Expr*);
19204 SQLITE_PRIVATE void sqlite3PExprAddSelect(Parse*, Expr*, Select*);
19205 SQLITE_PRIVATE Expr *sqlite3ExprAnd(Parse*,Expr*, Expr*);
19206 SQLITE_PRIVATE Expr *sqlite3ExprSimplifiedAndOr(Expr*);
19207 SQLITE_PRIVATE Expr *sqlite3ExprFunction(Parse*,ExprList*, Token*, int);
19208 SQLITE_PRIVATE void sqlite3ExprFunctionUsable(Parse*,Expr*,FuncDef*);
19209 SQLITE_PRIVATE void sqlite3ExprAssignVarNumber(Parse*, Expr*, u32);
19210 SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3*, Expr*);
19211 SQLITE_PRIVATE void sqlite3ExprUnmapAndDelete(Parse*, Expr*);
19212 SQLITE_PRIVATE ExprList *sqlite3ExprListAppend(Parse*,ExprList*,Expr*);
19213 SQLITE_PRIVATE ExprList *sqlite3ExprListAppendVector(Parse*,ExprList*,IdList*,Expr*);
@@ -19195,10 +19361,11 @@
19361 SQLITE_PRIVATE int sqlite3WhereBreakLabel(WhereInfo*);
19362 SQLITE_PRIVATE int sqlite3WhereOkOnePass(WhereInfo*, int*);
19363 #define ONEPASS_OFF 0 /* Use of ONEPASS not allowed */
19364 #define ONEPASS_SINGLE 1 /* ONEPASS valid for a single row update */
19365 #define ONEPASS_MULTI 2 /* ONEPASS is valid for multiple rows */
19366 SQLITE_PRIVATE int sqlite3WhereUsesDeferredSeek(WhereInfo*);
19367 SQLITE_PRIVATE void sqlite3ExprCodeLoadIndexColumn(Parse*, Index*, int, int, int);
19368 SQLITE_PRIVATE int sqlite3ExprCodeGetColumn(Parse*, Table*, int, int, int, u8);
19369 SQLITE_PRIVATE void sqlite3ExprCodeGetColumnOfTable(Vdbe*, Table*, int, int, int);
19370 SQLITE_PRIVATE void sqlite3ExprCodeMove(Parse*, int, int, int);
19371 SQLITE_PRIVATE void sqlite3ExprCode(Parse*, Expr*, int);
@@ -19249,10 +19416,11 @@
19416 SQLITE_PRIVATE void sqlite3BeginTransaction(Parse*, int);
19417 SQLITE_PRIVATE void sqlite3EndTransaction(Parse*,int);
19418 SQLITE_PRIVATE void sqlite3Savepoint(Parse*, int, Token*);
19419 SQLITE_PRIVATE void sqlite3CloseSavepoints(sqlite3 *);
19420 SQLITE_PRIVATE void sqlite3LeaveMutexAndCloseZombie(sqlite3*);
19421 SQLITE_PRIVATE u32 sqlite3IsTrueOrFalse(const char*);
19422 SQLITE_PRIVATE int sqlite3ExprIdToTrueFalse(Expr*);
19423 SQLITE_PRIVATE int sqlite3ExprTruthValue(const Expr*);
19424 SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr*);
19425 SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr*);
19426 SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*, u8);
@@ -19505,11 +19673,16 @@
19673 SQLITE_PRIVATE void sqlite3ExpirePreparedStatements(sqlite3*, int);
19674 SQLITE_PRIVATE void sqlite3CodeRhsOfIN(Parse*, Expr*, int);
19675 SQLITE_PRIVATE int sqlite3CodeSubselect(Parse*, Expr*);
19676 SQLITE_PRIVATE void sqlite3SelectPrep(Parse*, Select*, NameContext*);
19677 SQLITE_PRIVATE void sqlite3SelectWrongNumTermsError(Parse *pParse, Select *p);
19678 SQLITE_PRIVATE int sqlite3MatchEName(
19679 const struct ExprList_item*,
19680 const char*,
19681 const char*,
19682 const char*
19683 );
19684 SQLITE_PRIVATE int sqlite3ResolveExprNames(NameContext*, Expr*);
19685 SQLITE_PRIVATE int sqlite3ResolveExprListNames(NameContext*, ExprList*);
19686 SQLITE_PRIVATE void sqlite3ResolveSelectNames(Parse*, Select*, NameContext*);
19687 SQLITE_PRIVATE int sqlite3ResolveSelfReference(Parse*,Table*,int,Expr*,ExprList*);
19688 SQLITE_PRIVATE int sqlite3ResolveOrderGroupBy(Parse*, Select*, ExprList*, const char*);
@@ -19977,11 +20150,10 @@
20150 ** Bit 0x40 is set if the character is non-alphanumeric and can be used in an
20151 ** SQLite identifier. Identifiers are alphanumerics, "_", "$", and any
20152 ** non-ASCII UTF character. Hence the test for whether or not a character is
20153 ** part of an identifier is 0x46.
20154 */
 
20155 SQLITE_PRIVATE const unsigned char sqlite3CtypeMap[256] = {
20156 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 00..07 ........ */
20157 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, /* 08..0f ........ */
20158 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 10..17 ........ */
20159 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 18..1f ........ */
@@ -20015,11 +20187,10 @@
20187 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* e0..e7 ........ */
20188 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* e8..ef ........ */
20189 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* f0..f7 ........ */
20190 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40 /* f8..ff ........ */
20191 };
 
20192
20193 /* EVIDENCE-OF: R-02982-34736 In order to maintain full backwards
20194 ** compatibility for legacy applications, the URI filename capability is
20195 ** disabled by default.
20196 **
@@ -20080,13 +20251,22 @@
20251 ** number of bytes in each lookaside slot (should be a multiple of 8)
20252 ** and N is the number of slots. The lookaside-configuration can be
20253 ** changed as start-time using sqlite3_config(SQLITE_CONFIG_LOOKASIDE)
20254 ** or at run-time for an individual database connection using
20255 ** sqlite3_db_config(db, SQLITE_DBCONFIG_LOOKASIDE);
20256 **
20257 ** With the two-size-lookaside enhancement, less lookaside is required.
20258 ** The default configuration of 1200,40 actually provides 30 1200-byte slots
20259 ** and 93 128-byte slots, which is more lookaside than is available
20260 ** using the older 1200,100 configuration without two-size-lookaside.
20261 */
20262 #ifndef SQLITE_DEFAULT_LOOKASIDE
20263 # ifdef SQLITE_OMIT_TWOSIZE_LOOKASIDE
20264 # define SQLITE_DEFAULT_LOOKASIDE 1200,100 /* 120KB of memory */
20265 # else
20266 # define SQLITE_DEFAULT_LOOKASIDE 1200,40 /* 48KB of memory */
20267 # endif
20268 #endif
20269
20270
20271 /* The default maximum size of an in-memory database created using
20272 ** sqlite3_deserialize()
@@ -20148,11 +20328,10 @@
20328 #endif
20329 #ifndef SQLITE_UNTESTABLE
20330 0, /* xTestCallback */
20331 #endif
20332 0, /* bLocaltimeFault */
 
20333 0x7ffffffe, /* iOnceResetThreshold */
20334 SQLITE_DEFAULT_SORTERREF_SIZE, /* szSorterRef */
20335 0, /* iPrngSeed */
20336 };
20337
@@ -20710,10 +20889,11 @@
20889 ** Function prototypes
20890 */
20891 SQLITE_PRIVATE void sqlite3VdbeError(Vdbe*, const char *, ...);
20892 SQLITE_PRIVATE void sqlite3VdbeFreeCursor(Vdbe *, VdbeCursor*);
20893 void sqliteVdbePopStack(Vdbe*,int);
20894 SQLITE_PRIVATE int SQLITE_NOINLINE sqlite3VdbeFinishMoveto(VdbeCursor*);
20895 SQLITE_PRIVATE int sqlite3VdbeCursorMoveto(VdbeCursor**, int*);
20896 SQLITE_PRIVATE int sqlite3VdbeCursorRestore(VdbeCursor*);
20897 SQLITE_PRIVATE u32 sqlite3VdbeSerialTypeLen(u32);
20898 SQLITE_PRIVATE u8 sqlite3VdbeOneByteSerialTypeLen(u8);
20899 SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(unsigned char*, Mem*, u32);
@@ -20822,11 +21002,11 @@
21002 # define sqlite3VdbeCheckFk(p,i) 0
21003 #endif
21004
21005 #ifdef SQLITE_DEBUG
21006 SQLITE_PRIVATE void sqlite3VdbePrintSql(Vdbe*);
21007 SQLITE_PRIVATE void sqlite3VdbeMemPrettyPrint(Mem *pMem, StrAccum *pStr);
21008 #endif
21009 #ifndef SQLITE_OMIT_UTF16
21010 SQLITE_PRIVATE int sqlite3VdbeMemTranslate(Mem*, u8);
21011 SQLITE_PRIVATE int sqlite3VdbeMemHandleBom(Mem *pMem);
21012 #endif
@@ -21014,10 +21194,14 @@
21194 ** Count the number of slots of lookaside memory that are outstanding
21195 */
21196 SQLITE_PRIVATE int sqlite3LookasideUsed(sqlite3 *db, int *pHighwater){
21197 u32 nInit = countLookasideSlots(db->lookaside.pInit);
21198 u32 nFree = countLookasideSlots(db->lookaside.pFree);
21199 #ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
21200 nInit += countLookasideSlots(db->lookaside.pSmallInit);
21201 nFree += countLookasideSlots(db->lookaside.pSmallFree);
21202 #endif /* SQLITE_OMIT_TWOSIZE_LOOKASIDE */
21203 if( pHighwater ) *pHighwater = db->lookaside.nSlot - nInit;
21204 return db->lookaside.nSlot - (nInit+nFree);
21205 }
21206
21207 /*
@@ -21046,10 +21230,19 @@
21230 while( p->pNext ) p = p->pNext;
21231 p->pNext = db->lookaside.pInit;
21232 db->lookaside.pInit = db->lookaside.pFree;
21233 db->lookaside.pFree = 0;
21234 }
21235 #ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
21236 p = db->lookaside.pSmallFree;
21237 if( p ){
21238 while( p->pNext ) p = p->pNext;
21239 p->pNext = db->lookaside.pSmallInit;
21240 db->lookaside.pSmallInit = db->lookaside.pSmallFree;
21241 db->lookaside.pSmallFree = 0;
21242 }
21243 #endif
21244 }
21245 break;
21246 }
21247
21248 case SQLITE_DBSTATUS_LOOKASIDE_HIT:
@@ -27142,28 +27335,46 @@
27335 ** sqlite3Malloc() or sqlite3_malloc().
27336 */
27337 SQLITE_PRIVATE int sqlite3MallocSize(void *p){
27338 assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
27339 return sqlite3GlobalConfig.m.xSize(p);
27340 }
27341 static int lookasideMallocSize(sqlite3 *db, void *p){
27342 #ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
27343 return p<db->lookaside.pMiddle ? db->lookaside.szTrue : LOOKASIDE_SMALL;
27344 #else
27345 return db->lookaside.szTrue;
27346 #endif
27347 }
27348 SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, void *p){
27349 assert( p!=0 );
27350 #ifdef SQLITE_DEBUG
27351 if( db==0 || !isLookaside(db,p) ){
 
27352 if( db==0 ){
27353 assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) );
27354 assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
27355 }else{
27356 assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
27357 assert( sqlite3MemdebugNoType(p, (u8)~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
27358 }
27359 }
27360 #endif
27361 if( db ){
27362 if( ((uptr)p)<(uptr)(db->lookaside.pEnd) ){
27363 #ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
27364 if( ((uptr)p)>=(uptr)(db->lookaside.pMiddle) ){
27365 assert( sqlite3_mutex_held(db->mutex) );
27366 return LOOKASIDE_SMALL;
27367 }
27368 #endif
27369 if( ((uptr)p)>=(uptr)(db->lookaside.pStart) ){
27370 assert( sqlite3_mutex_held(db->mutex) );
27371 return db->lookaside.szTrue;
27372 }
27373 }
27374 }
27375 return sqlite3GlobalConfig.m.xSize(p);
27376 }
27377 SQLITE_API sqlite3_uint64 sqlite3_msize(void *p){
27378 assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) );
27379 assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
27380 return p ? sqlite3GlobalConfig.m.xSize(p) : 0;
@@ -27206,19 +27417,31 @@
27417 if( db ){
27418 if( db->pnBytesFreed ){
27419 measureAllocationSize(db, p);
27420 return;
27421 }
27422 if( ((uptr)p)<(uptr)(db->lookaside.pEnd) ){
27423 #ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
27424 if( ((uptr)p)>=(uptr)(db->lookaside.pMiddle) ){
27425 LookasideSlot *pBuf = (LookasideSlot*)p;
27426 #ifdef SQLITE_DEBUG
27427 memset(p, 0xaa, LOOKASIDE_SMALL); /* Trash freed content */
 
27428 #endif
27429 pBuf->pNext = db->lookaside.pSmallFree;
27430 db->lookaside.pSmallFree = pBuf;
27431 return;
27432 }
27433 #endif /* SQLITE_OMIT_TWOSIZE_LOOKASIDE */
27434 if( ((uptr)p)>=(uptr)(db->lookaside.pStart) ){
27435 LookasideSlot *pBuf = (LookasideSlot*)p;
27436 #ifdef SQLITE_DEBUG
27437 memset(p, 0xaa, db->lookaside.szTrue); /* Trash freed content */
27438 #endif
27439 pBuf->pNext = db->lookaside.pFree;
27440 db->lookaside.pFree = pBuf;
27441 return;
27442 }
27443 }
27444 }
27445 assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
27446 assert( sqlite3MemdebugNoType(p, (u8)~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
27447 assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
@@ -27371,15 +27594,31 @@
27594 LookasideSlot *pBuf;
27595 assert( db!=0 );
27596 assert( sqlite3_mutex_held(db->mutex) );
27597 assert( db->pnBytesFreed==0 );
27598 if( n>db->lookaside.sz ){
27599 if( !db->lookaside.bDisable ){
27600 db->lookaside.anStat[1]++;
27601 }else if( db->mallocFailed ){
27602 return 0;
27603 }
27604 return dbMallocRawFinish(db, n);
27605 }
27606 #ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
27607 if( n<=LOOKASIDE_SMALL ){
27608 if( (pBuf = db->lookaside.pSmallFree)!=0 ){
27609 db->lookaside.pSmallFree = pBuf->pNext;
27610 db->lookaside.anStat[0]++;
27611 return (void*)pBuf;
27612 }else if( (pBuf = db->lookaside.pSmallInit)!=0 ){
27613 db->lookaside.pSmallInit = pBuf->pNext;
27614 db->lookaside.anStat[0]++;
27615 return (void*)pBuf;
27616 }
27617 }
27618 #endif
27619 if( (pBuf = db->lookaside.pFree)!=0 ){
27620 db->lookaside.pFree = pBuf->pNext;
27621 db->lookaside.anStat[0]++;
27622 return (void*)pBuf;
27623 }else if( (pBuf = db->lookaside.pInit)!=0 ){
27624 db->lookaside.pInit = pBuf->pNext;
@@ -27408,11 +27647,20 @@
27647 */
27648 SQLITE_PRIVATE void *sqlite3DbRealloc(sqlite3 *db, void *p, u64 n){
27649 assert( db!=0 );
27650 if( p==0 ) return sqlite3DbMallocRawNN(db, n);
27651 assert( sqlite3_mutex_held(db->mutex) );
27652 if( ((uptr)p)<(uptr)db->lookaside.pEnd ){
27653 #ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
27654 if( ((uptr)p)>=(uptr)db->lookaside.pMiddle ){
27655 if( n<=LOOKASIDE_SMALL ) return p;
27656 }else
27657 #endif
27658 if( ((uptr)p)>=(uptr)db->lookaside.pStart ){
27659 if( n<=db->lookaside.szTrue ) return p;
27660 }
27661 }
27662 return dbReallocFinish(db, p, n);
27663 }
27664 static SQLITE_NOINLINE void *dbReallocFinish(sqlite3 *db, void *p, u64 n){
27665 void *pNew = 0;
27666 assert( db!=0 );
@@ -27419,11 +27667,11 @@
27667 assert( p!=0 );
27668 if( db->mallocFailed==0 ){
27669 if( isLookaside(db, p) ){
27670 pNew = sqlite3DbMallocRawNN(db, n);
27671 if( pNew ){
27672 memcpy(pNew, p, lookasideMallocSize(db, p));
27673 sqlite3DbFree(db, p);
27674 }
27675 }else{
27676 assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
27677 assert( sqlite3MemdebugNoType(p, (u8)~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
@@ -28985,11 +29233,11 @@
29233 sqlite3_str_appendf(&x, "%s", pCte->zName);
29234 if( pCte->pCols && pCte->pCols->nExpr>0 ){
29235 char cSep = '(';
29236 int j;
29237 for(j=0; j<pCte->pCols->nExpr; j++){
29238 sqlite3_str_appendf(&x, "%c%s", cSep, pCte->pCols->a[j].zEName);
29239 cSep = ',';
29240 }
29241 sqlite3_str_appendf(&x, ")");
29242 }
29243 sqlite3_str_appendf(&x, " AS");
@@ -29026,10 +29274,13 @@
29274 sqlite3_str_appendf(&x, " (AS %s)", pItem->zAlias);
29275 }
29276 if( pItem->fg.jointype & JT_LEFT ){
29277 sqlite3_str_appendf(&x, " LEFT-JOIN");
29278 }
29279 if( pItem->fg.fromDDL ){
29280 sqlite3_str_appendf(&x, " DDL");
29281 }
29282 sqlite3StrAccumFinish(&x);
29283 sqlite3TreeViewItem(pView, zLine, i<pSrc->nSrc-1);
29284 if( pItem->pSelect ){
29285 sqlite3TreeViewSelect(pView, pItem->pSelect, 0);
29286 }
@@ -29282,18 +29533,21 @@
29533 sqlite3TreeViewLine(pView, "nil");
29534 sqlite3TreeViewPop(pView);
29535 return;
29536 }
29537 if( pExpr->flags || pExpr->affExpr ){
29538 StrAccum x;
29539 sqlite3StrAccumInit(&x, 0, zFlgs, sizeof(zFlgs), 0);
29540 sqlite3_str_appendf(&x, " fg.af=%x.%c",
29541 pExpr->flags, pExpr->affExpr ? pExpr->affExpr : 'n');
29542 if( ExprHasProperty(pExpr, EP_FromJoin) ){
29543 sqlite3_str_appendf(&x, " iRJT=%d", pExpr->iRightJoinTable);
 
 
 
 
 
29544 }
29545 if( ExprHasProperty(pExpr, EP_FromDDL) ){
29546 sqlite3_str_appendf(&x, " DDL");
29547 }
29548 sqlite3StrAccumFinish(&x);
29549 }else{
29550 zFlgs[0] = 0;
29551 }
29552 switch( pExpr->op ){
29553 case TK_AGG_COLUMN: {
@@ -29445,11 +29699,11 @@
29699 pFarg = 0;
29700 pWin = 0;
29701 }else{
29702 pFarg = pExpr->x.pList;
29703 #ifndef SQLITE_OMIT_WINDOWFUNC
29704 pWin = ExprHasProperty(pExpr, EP_WinFunc) ? pExpr->y.pWin : 0;
29705 #else
29706 pWin = 0;
29707 #endif
29708 }
29709 if( pExpr->op==TK_AGG_FUNCTION ){
@@ -29607,12 +29861,13 @@
29861 }else{
29862 int i;
29863 sqlite3TreeViewLine(pView, "%s", zLabel);
29864 for(i=0; i<pList->nExpr; i++){
29865 int j = pList->a[i].u.x.iOrderByCol;
29866 char *zName = pList->a[i].zEName;
29867 int moreToFollow = i<pList->nExpr - 1;
29868 if( pList->a[i].eEName!=ENAME_NAME ) zName = 0;
29869 if( j || zName ){
29870 sqlite3TreeViewPush(pView, moreToFollow);
29871 moreToFollow = 0;
29872 sqlite3TreeViewLine(pView, 0);
29873 if( zName ){
@@ -30275,13 +30530,15 @@
30530 assert( pMem->enc!=0 );
30531 assert( pMem->n>=0 );
30532
30533 #if defined(TRANSLATE_TRACE) && defined(SQLITE_DEBUG)
30534 {
30535 StrAccum acc;
30536 char zBuf[1000];
30537 sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0);
30538 sqlite3VdbeMemPrettyPrint(pMem, &acc);
30539 fprintf(stderr, "INPUT: %s\n", sqlite3StrAccumFinish(&acc));
30540 }
30541 #endif
30542
30543 /* If the translation is between UTF-16 little and big endian, then
30544 ** all that is required is to swap the byte order. This case is handled
@@ -30385,13 +30642,15 @@
30642 pMem->szMalloc = sqlite3DbMallocSize(pMem->db, pMem->z);
30643
30644 translate_out:
30645 #if defined(TRANSLATE_TRACE) && defined(SQLITE_DEBUG)
30646 {
30647 StrAccum acc;
30648 char zBuf[1000];
30649 sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0);
30650 sqlite3VdbeMemPrettyPrint(pMem, &acc);
30651 fprintf(stderr, "OUTPUT: %s\n", sqlite3StrAccumFinish(&acc));
30652 }
30653 #endif
30654 return SQLITE_OK;
30655 }
30656 #endif /* SQLITE_OMIT_UTF16 */
@@ -31006,10 +31265,11 @@
31265 incr = 1;
31266 zEnd = z + length;
31267 }else{
31268 int i;
31269 incr = 2;
31270 length &= ~1;
31271 assert( SQLITE_UTF16LE==2 && SQLITE_UTF16BE==3 );
31272 testcase( enc==SQLITE_UTF16LE );
31273 testcase( enc==SQLITE_UTF16BE );
31274 for(i=3-enc; i<length && z[i]==0; i+=2){}
31275 if( i<length ) eType = -100;
@@ -32543,85 +32803,85 @@
32803 /* 21 */ "IfNullRow" OpHelp("if P1.nullRow then r[P3]=NULL, goto P2"),
32804 /* 22 */ "SeekLT" OpHelp("key=r[P3@P4]"),
32805 /* 23 */ "SeekLE" OpHelp("key=r[P3@P4]"),
32806 /* 24 */ "SeekGE" OpHelp("key=r[P3@P4]"),
32807 /* 25 */ "SeekGT" OpHelp("key=r[P3@P4]"),
32808 /* 26 */ "IfNotOpen" OpHelp("if( !csr[P1] ) goto P2"),
32809 /* 27 */ "IfNoHope" OpHelp("key=r[P3@P4]"),
32810 /* 28 */ "NoConflict" OpHelp("key=r[P3@P4]"),
32811 /* 29 */ "NotFound" OpHelp("key=r[P3@P4]"),
32812 /* 30 */ "Found" OpHelp("key=r[P3@P4]"),
32813 /* 31 */ "SeekRowid" OpHelp("intkey=r[P3]"),
32814 /* 32 */ "NotExists" OpHelp("intkey=r[P3]"),
32815 /* 33 */ "Last" OpHelp(""),
32816 /* 34 */ "IfSmaller" OpHelp(""),
32817 /* 35 */ "SorterSort" OpHelp(""),
32818 /* 36 */ "Sort" OpHelp(""),
32819 /* 37 */ "Rewind" OpHelp(""),
32820 /* 38 */ "IdxLE" OpHelp("key=r[P3@P4]"),
32821 /* 39 */ "IdxGT" OpHelp("key=r[P3@P4]"),
32822 /* 40 */ "IdxLT" OpHelp("key=r[P3@P4]"),
32823 /* 41 */ "IdxGE" OpHelp("key=r[P3@P4]"),
32824 /* 42 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"),
32825 /* 43 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"),
32826 /* 44 */ "And" OpHelp("r[P3]=(r[P1] && r[P2])"),
32827 /* 45 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
32828 /* 46 */ "Program" OpHelp(""),
32829 /* 47 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
32830 /* 48 */ "IfPos" OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"),
32831 /* 49 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]--, goto P2"),
32832 /* 50 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"),
32833 /* 51 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"),
32834 /* 52 */ "Ne" OpHelp("IF r[P3]!=r[P1]"),
32835 /* 53 */ "Eq" OpHelp("IF r[P3]==r[P1]"),
32836 /* 54 */ "Gt" OpHelp("IF r[P3]>r[P1]"),
32837 /* 55 */ "Le" OpHelp("IF r[P3]<=r[P1]"),
32838 /* 56 */ "Lt" OpHelp("IF r[P3]<r[P1]"),
32839 /* 57 */ "Ge" OpHelp("IF r[P3]>=r[P1]"),
32840 /* 58 */ "ElseNotEq" OpHelp(""),
32841 /* 59 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"),
32842 /* 60 */ "IncrVacuum" OpHelp(""),
32843 /* 61 */ "VNext" OpHelp(""),
32844 /* 62 */ "Init" OpHelp("Start at P2"),
32845 /* 63 */ "PureFunc" OpHelp("r[P3]=func(r[P2@P5])"),
32846 /* 64 */ "Function" OpHelp("r[P3]=func(r[P2@P5])"),
32847 /* 65 */ "Return" OpHelp(""),
32848 /* 66 */ "EndCoroutine" OpHelp(""),
32849 /* 67 */ "HaltIfNull" OpHelp("if r[P3]=null halt"),
32850 /* 68 */ "Halt" OpHelp(""),
32851 /* 69 */ "Integer" OpHelp("r[P2]=P1"),
32852 /* 70 */ "Int64" OpHelp("r[P2]=P4"),
32853 /* 71 */ "String" OpHelp("r[P2]='P4' (len=P1)"),
32854 /* 72 */ "Null" OpHelp("r[P2..P3]=NULL"),
32855 /* 73 */ "SoftNull" OpHelp("r[P1]=NULL"),
32856 /* 74 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"),
32857 /* 75 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"),
32858 /* 76 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"),
32859 /* 77 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"),
32860 /* 78 */ "SCopy" OpHelp("r[P2]=r[P1]"),
32861 /* 79 */ "IntCopy" OpHelp("r[P2]=r[P1]"),
32862 /* 80 */ "ResultRow" OpHelp("output=r[P1@P2]"),
32863 /* 81 */ "CollSeq" OpHelp(""),
32864 /* 82 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"),
32865 /* 83 */ "RealAffinity" OpHelp(""),
32866 /* 84 */ "Cast" OpHelp("affinity(r[P1])"),
32867 /* 85 */ "Permutation" OpHelp(""),
32868 /* 86 */ "Compare" OpHelp("r[P1@P3] <-> r[P2@P3]"),
32869 /* 87 */ "IsTrue" OpHelp("r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4"),
32870 /* 88 */ "Offset" OpHelp("r[P3] = sqlite_offset(P1)"),
32871 /* 89 */ "Column" OpHelp("r[P3]=PX"),
32872 /* 90 */ "Affinity" OpHelp("affinity(r[P1@P2])"),
32873 /* 91 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"),
32874 /* 92 */ "Count" OpHelp("r[P2]=count()"),
32875 /* 93 */ "ReadCookie" OpHelp(""),
32876 /* 94 */ "SetCookie" OpHelp(""),
32877 /* 95 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"),
32878 /* 96 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
32879 /* 97 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
32880 /* 98 */ "OpenDup" OpHelp(""),
32881 /* 99 */ "OpenAutoindex" OpHelp("nColumn=P2"),
32882 /* 100 */ "OpenEphemeral" OpHelp("nColumn=P2"),
32883 /* 101 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"),
32884 /* 102 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"),
32885 /* 103 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"),
32886 /* 104 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"),
32887 /* 105 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"),
@@ -32628,71 +32888,75 @@
32888 /* 106 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"),
32889 /* 107 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"),
32890 /* 108 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"),
32891 /* 109 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"),
32892 /* 110 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
32893 /* 111 */ "SorterOpen" OpHelp(""),
32894 /* 112 */ "BitNot" OpHelp("r[P2]= ~r[P1]"),
32895 /* 113 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"),
32896 /* 114 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"),
32897 /* 115 */ "String8" OpHelp("r[P2]='P4'"),
32898 /* 116 */ "Close" OpHelp(""),
32899 /* 117 */ "ColumnsUsed" OpHelp(""),
32900 /* 118 */ "SeekHit" OpHelp("seekHit=P2"),
32901 /* 119 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"),
32902 /* 120 */ "NewRowid" OpHelp("r[P2]=rowid"),
32903 /* 121 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
32904 /* 122 */ "Delete" OpHelp(""),
32905 /* 123 */ "ResetCount" OpHelp(""),
32906 /* 124 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
32907 /* 125 */ "SorterData" OpHelp("r[P2]=data"),
32908 /* 126 */ "RowData" OpHelp("r[P2]=data"),
32909 /* 127 */ "Rowid" OpHelp("r[P2]=rowid"),
32910 /* 128 */ "NullRow" OpHelp(""),
32911 /* 129 */ "SeekEnd" OpHelp(""),
32912 /* 130 */ "SorterInsert" OpHelp("key=r[P2]"),
32913 /* 131 */ "IdxInsert" OpHelp("key=r[P2]"),
32914 /* 132 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
32915 /* 133 */ "DeferredSeek" OpHelp("Move P3 to P1.rowid if needed"),
32916 /* 134 */ "IdxRowid" OpHelp("r[P2]=rowid"),
32917 /* 135 */ "FinishSeek" OpHelp(""),
32918 /* 136 */ "Destroy" OpHelp(""),
32919 /* 137 */ "Clear" OpHelp(""),
32920 /* 138 */ "ResetSorter" OpHelp(""),
32921 /* 139 */ "CreateBtree" OpHelp("r[P2]=root iDb=P1 flags=P3"),
32922 /* 140 */ "SqlExec" OpHelp(""),
32923 /* 141 */ "ParseSchema" OpHelp(""),
32924 /* 142 */ "LoadAnalysis" OpHelp(""),
32925 /* 143 */ "DropTable" OpHelp(""),
32926 /* 144 */ "DropIndex" OpHelp(""),
32927 /* 145 */ "DropTrigger" OpHelp(""),
32928 /* 146 */ "IntegrityCk" OpHelp(""),
32929 /* 147 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
32930 /* 148 */ "Param" OpHelp(""),
32931 /* 149 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
32932 /* 150 */ "Real" OpHelp("r[P2]=P4"),
32933 /* 151 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
32934 /* 152 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"),
32935 /* 153 */ "AggInverse" OpHelp("accum=r[P3] inverse(r[P2@P5])"),
32936 /* 154 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"),
32937 /* 155 */ "AggStep1" OpHelp("accum=r[P3] step(r[P2@P5])"),
32938 /* 156 */ "AggValue" OpHelp("r[P3]=value N=P2"),
32939 /* 157 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
32940 /* 158 */ "Expire" OpHelp(""),
32941 /* 159 */ "CursorLock" OpHelp(""),
32942 /* 160 */ "CursorUnlock" OpHelp(""),
32943 /* 161 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
32944 /* 162 */ "VBegin" OpHelp(""),
32945 /* 163 */ "VCreate" OpHelp(""),
32946 /* 164 */ "VDestroy" OpHelp(""),
32947 /* 165 */ "VOpen" OpHelp(""),
32948 /* 166 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
32949 /* 167 */ "VRename" OpHelp(""),
32950 /* 168 */ "Pagecount" OpHelp(""),
32951 /* 169 */ "MaxPgcnt" OpHelp(""),
32952 /* 170 */ "Trace" OpHelp(""),
32953 /* 171 */ "CursorHint" OpHelp(""),
32954 /* 172 */ "ReleaseReg" OpHelp("release r[P1@P2] mask P3"),
32955 /* 173 */ "Noop" OpHelp(""),
32956 /* 174 */ "Explain" OpHelp(""),
32957 /* 175 */ "Abortable" OpHelp(""),
32958 };
32959 return azName[i];
32960 }
32961 #endif
32962
@@ -39156,11 +39420,11 @@
39420 assert( flags==SQLITE_ACCESS_EXISTS || flags==SQLITE_ACCESS_READWRITE );
39421
39422 if( flags==SQLITE_ACCESS_EXISTS ){
39423 struct stat buf;
39424 *pResOut = 0==osStat(zPath, &buf) &&
39425 (!S_ISREG(buf.st_mode) || buf.st_size>0);
39426 }else{
39427 *pResOut = osAccess(zPath, W_OK|R_OK)==0;
39428 }
39429 return SQLITE_OK;
39430 }
@@ -52175,10 +52439,11 @@
52439 if( pPager->eLock!=UNKNOWN_LOCK ){
52440 pPager->eLock = (u8)eLock;
52441 }
52442 IOTRACE(("UNLOCK %p %d\n", pPager, eLock))
52443 }
52444 pPager->changeCountDone = pPager->tempFile; /* ticket fb3b3024ea238d5c */
52445 return rc;
52446 }
52447
52448 /*
52449 ** Lock the database file to level eLock, which must be either SHARED_LOCK,
@@ -52896,11 +53161,10 @@
53161 /* The pager state may be changed from PAGER_ERROR to PAGER_OPEN here
53162 ** without clearing the error code. This is intentional - the error
53163 ** code is cleared and the cache reset in the block below.
53164 */
53165 assert( pPager->errCode || pPager->eState!=PAGER_ERROR );
 
53166 pPager->eState = PAGER_OPEN;
53167 }
53168
53169 /* If Pager.errCode is set, the contents of the pager cache cannot be
53170 ** trusted. Now that there are no outstanding references to the pager,
@@ -53160,11 +53424,10 @@
53424
53425 if( !pPager->exclusiveMode
53426 && (!pagerUseWal(pPager) || sqlite3WalExclusiveMode(pPager->pWal, 0))
53427 ){
53428 rc2 = pagerUnlockDb(pPager, SHARED_LOCK);
 
53429 }
53430 pPager->eState = PAGER_READER;
53431 pPager->setMaster = 0;
53432
53433 return (rc==SQLITE_OK?rc2:rc);
@@ -63178,10 +63441,11 @@
63441 #define BTCF_ValidNKey 0x02 /* True if info.nKey is valid */
63442 #define BTCF_ValidOvfl 0x04 /* True if aOverflow is valid */
63443 #define BTCF_AtLast 0x08 /* Cursor is pointing ot the last entry */
63444 #define BTCF_Incrblob 0x10 /* True if an incremental I/O handle */
63445 #define BTCF_Multiple 0x20 /* Maybe another cursor on the same btree */
63446 #define BTCF_Pinned 0x40 /* Cursor is busy and cannot be moved */
63447
63448 /*
63449 ** Potential values for BtCursor.eState.
63450 **
63451 ** CURSOR_INVALID:
@@ -64343,10 +64607,13 @@
64607
64608 assert( CURSOR_VALID==pCur->eState || CURSOR_SKIPNEXT==pCur->eState );
64609 assert( 0==pCur->pKey );
64610 assert( cursorHoldsMutex(pCur) );
64611
64612 if( pCur->curFlags & BTCF_Pinned ){
64613 return SQLITE_CONSTRAINT_PINNED;
64614 }
64615 if( pCur->eState==CURSOR_SKIPNEXT ){
64616 pCur->eState = CURSOR_VALID;
64617 }else{
64618 pCur->skipNext = 0;
64619 }
@@ -65090,20 +65357,20 @@
65357 u8 *pEnd = &data[cellOffset + nCell*2];
65358 u8 *pAddr;
65359 int sz2 = 0;
65360 int sz = get2byte(&data[iFree+2]);
65361 int top = get2byte(&data[hdr+5]);
65362 if( NEVER(top>=iFree) ){
65363 return SQLITE_CORRUPT_PAGE(pPage);
65364 }
65365 if( iFree2 ){
65366 if( iFree+sz>iFree2 ) return SQLITE_CORRUPT_PAGE(pPage);
65367 sz2 = get2byte(&data[iFree2+2]);
65368 if( iFree2+sz2 > usableSize ) return SQLITE_CORRUPT_PAGE(pPage);
65369 memmove(&data[iFree+sz+sz2], &data[iFree+sz], iFree2-(iFree+sz));
65370 sz += sz2;
65371 }else if( NEVER(iFree+sz>usableSize) ){
65372 return SQLITE_CORRUPT_PAGE(pPage);
65373 }
65374
65375 cbrk = top+sz;
65376 assert( cbrk+(iFree-top) <= usableSize );
@@ -65291,12 +65558,14 @@
65558 testcase( gap+1==top );
65559 testcase( gap==top );
65560 if( (data[hdr+2] || data[hdr+1]) && gap+2<=top ){
65561 u8 *pSpace = pageFindSlot(pPage, nByte, &rc);
65562 if( pSpace ){
65563 int g2;
65564 assert( pSpace+nByte<=data+pPage->pBt->usableSize );
65565 *pIdx = g2 = (int)(pSpace-data);
65566 if( NEVER(g2<=gap) ){
65567 return SQLITE_CORRUPT_PAGE(pPage);
65568 }else{
65569 return SQLITE_OK;
65570 }
65571 }else if( rc ){
@@ -65370,16 +65639,16 @@
65639 if( data[iPtr+1]==0 && data[iPtr]==0 ){
65640 iFreeBlk = 0; /* Shortcut for the case when the freelist is empty */
65641 }else{
65642 while( (iFreeBlk = get2byte(&data[iPtr]))<iStart ){
65643 if( iFreeBlk<iPtr+4 ){
65644 if( ALWAYS(iFreeBlk==0) ) break;
65645 return SQLITE_CORRUPT_PAGE(pPage);
65646 }
65647 iPtr = iFreeBlk;
65648 }
65649 if( iFreeBlk>pPage->pBt->usableSize-4 ){ /* TH3: corrupt081.100 */
65650 return SQLITE_CORRUPT_PAGE(pPage);
65651 }
65652 assert( iFreeBlk>iPtr || iFreeBlk==0 );
65653
65654 /* At this point:
@@ -65390,11 +65659,11 @@
65659 */
65660 if( iFreeBlk && iEnd+3>=iFreeBlk ){
65661 nFrag = iFreeBlk - iEnd;
65662 if( iEnd>iFreeBlk ) return SQLITE_CORRUPT_PAGE(pPage);
65663 iEnd = iFreeBlk + get2byte(&data[iFreeBlk+2]);
65664 if( NEVER(iEnd > pPage->pBt->usableSize) ){
65665 return SQLITE_CORRUPT_PAGE(pPage);
65666 }
65667 iSize = iEnd - iStart;
65668 iFreeBlk = get2byte(&data[iFreeBlk]);
65669 }
@@ -65418,11 +65687,12 @@
65687 x = get2byte(&data[hdr+5]);
65688 if( iStart<=x ){
65689 /* The new freeblock is at the beginning of the cell content area,
65690 ** so just extend the cell content area rather than create another
65691 ** freelist entry */
65692 if( iStart<x ) return SQLITE_CORRUPT_PAGE(pPage);
65693 if( NEVER(iPtr!=hdr+1) ) return SQLITE_CORRUPT_PAGE(pPage);
65694 put2byte(&data[hdr+1], iFreeBlk);
65695 put2byte(&data[hdr+5], iEnd);
65696 }else{
65697 /* Insert the new freeblock into the freelist */
65698 put2byte(&data[iPtr], iStart);
@@ -65538,11 +65808,11 @@
65808 ** freeblocks. */
65809 pc = get2byte(&data[hdr+1]);
65810 nFree = data[hdr+7] + top; /* Init nFree to non-freeblock free space */
65811 if( pc>0 ){
65812 u32 next, size;
65813 if( pc<top ){
65814 /* EVIDENCE-OF: R-55530-52930 In a well-formed b-tree page, there will
65815 ** always be at least one cell before the first freeblock.
65816 */
65817 return SQLITE_CORRUPT_PAGE(pPage);
65818 }
@@ -65775,16 +66045,16 @@
66045 /*
66046 ** Return the size of the database file in pages. If there is any kind of
66047 ** error, return ((unsigned int)-1).
66048 */
66049 static Pgno btreePagecount(BtShared *pBt){
66050 assert( (pBt->nPage & 0x80000000)==0 || CORRUPT_DB );
66051 return pBt->nPage;
66052 }
66053 SQLITE_PRIVATE u32 sqlite3BtreeLastPage(Btree *p){
66054 assert( sqlite3BtreeHoldsMutex(p) );
66055 return btreePagecount(p->pBt) & 0x7fffffff;
 
66056 }
66057
66058 /*
66059 ** Get a page from the pager and initialize it.
66060 **
@@ -68205,10 +68475,22 @@
68475 assert( pCur->eState==CURSOR_VALID );
68476 assert( pCur->curIntKey );
68477 getCellInfo(pCur);
68478 return pCur->info.nKey;
68479 }
68480
68481 /*
68482 ** Pin or unpin a cursor.
68483 */
68484 SQLITE_PRIVATE void sqlite3BtreeCursorPin(BtCursor *pCur){
68485 assert( (pCur->curFlags & BTCF_Pinned)==0 );
68486 pCur->curFlags |= BTCF_Pinned;
68487 }
68488 SQLITE_PRIVATE void sqlite3BtreeCursorUnpin(BtCursor *pCur){
68489 assert( (pCur->curFlags & BTCF_Pinned)!=0 );
68490 pCur->curFlags &= ~BTCF_Pinned;
68491 }
68492
68493 #ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
68494 /*
68495 ** Return the offset into the database file for the start of the
68496 ** payload to which the cursor is pointing.
@@ -70565,11 +70847,11 @@
70847 int k; /* Current slot in pCArray->apEnd[] */
70848 u8 *pSrcEnd; /* Current pCArray->apEnd[k] value */
70849
70850 assert( i<iEnd );
70851 j = get2byte(&aData[hdr+5]);
70852 if( NEVER(j>(u32)usableSize) ){ j = 0; }
70853 memcpy(&pTmp[j], &aData[j], usableSize - j);
70854
70855 for(k=0; pCArray->ixNx[k]<=i && ALWAYS(k<NB*2); k++){}
70856 pSrcEnd = pCArray->apEnd[k];
70857
@@ -70591,11 +70873,11 @@
70873 put2byte(pCellptr, (pData - aData));
70874 pCellptr += 2;
70875 if( pData < pCellptr ) return SQLITE_CORRUPT_BKPT;
70876 memcpy(pData, pCell, sz);
70877 assert( sz==pPg->xCellSize(pPg, pCell) || CORRUPT_DB );
70878 testcase( sz!=pPg->xCellSize(pPg,pCell) )
70879 i++;
70880 if( i>=iEnd ) break;
70881 if( pCArray->ixNx[k]<=i ){
70882 k++;
70883 pSrcEnd = pCArray->apEnd[k];
@@ -72302,11 +72584,10 @@
72584 */
72585 #ifdef SQLITE_DEBUG
72586 if( flags & BTREE_SAVEPOSITION ){
72587 assert( pCur->curFlags & BTCF_ValidNKey );
72588 assert( pX->nKey==pCur->info.nKey );
 
72589 assert( loc==0 );
72590 }
72591 #endif
72592
72593 /* On the other hand, BTREE_SAVEPOSITION==0 does not imply
@@ -75906,27 +76187,34 @@
76187 /*
76188 ** This routine prepares a memory cell for modification by breaking
76189 ** its link to a shallow copy and by marking any current shallow
76190 ** copies of this cell as invalid.
76191 **
76192 ** This is used for testing and debugging only - to help ensure that shallow
76193 ** copies (created by OP_SCopy) are not misused.
76194 */
76195 SQLITE_PRIVATE void sqlite3VdbeMemAboutToChange(Vdbe *pVdbe, Mem *pMem){
76196 int i;
76197 Mem *pX;
76198 for(i=1, pX=pVdbe->aMem+1; i<pVdbe->nMem; i++, pX++){
76199 if( pX->pScopyFrom==pMem ){
76200 u16 mFlags;
76201 if( pVdbe->db->flags & SQLITE_VdbeTrace ){
76202 sqlite3DebugPrintf("Invalidate R[%d] due to change in R[%d]\n",
76203 (int)(pX - pVdbe->aMem), (int)(pMem - pVdbe->aMem));
76204 }
76205 /* If pX is marked as a shallow copy of pMem, then verify that
76206 ** no significant changes have been made to pX since the OP_SCopy.
76207 ** A significant change would indicated a missed call to this
76208 ** function for pX. Minor changes, such as adding or removing a
76209 ** dual type, are allowed, as long as the underlying value is the
76210 ** same. */
76211 mFlags = pMem->flags & pX->flags & pX->mScopyFlags;
76212 assert( (mFlags&(MEM_Int|MEM_IntReal))==0 || pMem->u.i==pX->u.i );
76213 /* assert( (mFlags&MEM_Real)==0 || pMem->u.r==pX->u.r ); */
76214 /* ^^ */
76215 /* Cannot reliably compare doubles for equality */
76216 assert( (mFlags&MEM_Str)==0 || (pMem->n==pX->n && pMem->z==pX->z) );
76217 assert( (mFlags&MEM_Blob)==0 || sqlite3BlobCompare(pMem,pX)==0 );
76218
76219 /* pMem is the register that is changing. But also mark pX as
76220 ** undefined so that we can quickly detect the shallow-copy error */
@@ -75935,11 +76223,10 @@
76223 }
76224 }
76225 pMem->pScopyFrom = 0;
76226 }
76227 #endif /* SQLITE_DEBUG */
 
76228
76229 /*
76230 ** Make an shallow copy of pFrom into pTo. Prior contents of
76231 ** pTo are freed. The pFrom->z field is not duplicated. If
76232 ** pFrom->z is used, then pTo->z points to the same thing as pFrom->z
@@ -76082,14 +76369,23 @@
76369 }
76370 }
76371
76372 pMem->n = nByte;
76373 pMem->flags = flags;
76374 if( enc ){
76375 pMem->enc = enc;
76376 #ifdef SQLITE_ENABLE_SESSION
76377 }else if( pMem->db==0 ){
76378 pMem->enc = SQLITE_UTF8;
76379 #endif
76380 }else{
76381 assert( pMem->db!=0 );
76382 pMem->enc = ENC(pMem->db);
76383 }
76384
76385 #ifndef SQLITE_OMIT_UTF16
76386 if( enc>SQLITE_UTF8 && sqlite3VdbeMemHandleBom(pMem) ){
76387 return SQLITE_NOMEM_BKPT;
76388 }
76389 #endif
76390
76391 if( nByte>iLimit ){
@@ -77040,13 +77336,20 @@
77336 }
77337
77338 #ifdef SQLITE_DEBUG
77339 /* This routine is just a convenient place to set a breakpoint that will
77340 ** fire after each opcode is inserted and displayed using
77341 ** "PRAGMA vdbe_addoptrace=on". Parameters "pc" (program counter) and
77342 ** pOp are available to make the breakpoint conditional.
77343 **
77344 ** Other useful labels for breakpoints include:
77345 ** test_trace_breakpoint(pc,pOp)
77346 ** sqlite3CorruptError(lineno)
77347 ** sqlite3MisuseError(lineno)
77348 ** sqlite3CantopenError(lineno)
77349 */
77350 static void test_addop_breakpoint(int pc, Op *pOp){
77351 static int n = 0;
77352 n++;
77353 }
77354 #endif
77355
@@ -77095,11 +77398,11 @@
77398 pOp->zComment = 0;
77399 #endif
77400 #ifdef SQLITE_DEBUG
77401 if( p->db->flags & SQLITE_VdbeAddopTrace ){
77402 sqlite3VdbePrintOp(0, i, &p->aOp[i]);
77403 test_addop_breakpoint(i, &p->aOp[i]);
77404 }
77405 #endif
77406 #ifdef VDBE_PROFILE
77407 pOp->cycles = 0;
77408 pOp->cnt = 0;
@@ -78037,12 +78340,21 @@
78340 #ifdef SQLITE_DEBUG
78341 /*
78342 ** Generate an OP_ReleaseReg opcode to indicate that a range of
78343 ** registers, except any identified by mask, are no longer in use.
78344 */
78345 SQLITE_PRIVATE void sqlite3VdbeReleaseRegisters(
78346 Parse *pParse, /* Parsing context */
78347 int iFirst, /* Index of first register to be released */
78348 int N, /* Number of registers to release */
78349 u32 mask, /* Mask of registers to NOT release */
78350 int bUndefine /* If true, mark registers as undefined */
78351 ){
78352 if( N==0 ) return;
78353 assert( pParse->pVdbe );
78354 assert( iFirst>=1 );
78355 assert( iFirst+N-1<=pParse->nMem );
78356 while( N>0 && (mask&1)!=0 ){
78357 mask >>= 1;
78358 iFirst++;
78359 N--;
78360 }
@@ -78050,10 +78362,11 @@
78362 mask &= ~MASKBIT32(N-1);
78363 N--;
78364 }
78365 if( N>0 ){
78366 sqlite3VdbeAddOp3(pParse->pVdbe, OP_ReleaseReg, iFirst, N, *(int*)&mask);
78367 if( bUndefine ) sqlite3VdbeChangeP5(pParse->pVdbe, 1);
78368 }
78369 }
78370 #endif /* SQLITE_DEBUG */
78371
78372
@@ -80260,11 +80573,11 @@
80573 /*
80574 ** The cursor "p" has a pending seek operation that has not yet been
80575 ** carried out. Seek the cursor now. If an error occurs, return
80576 ** the appropriate error code.
80577 */
80578 SQLITE_PRIVATE int SQLITE_NOINLINE sqlite3VdbeFinishMoveto(VdbeCursor *p){
80579 int res, rc;
80580 #ifdef SQLITE_TEST
80581 extern int sqlite3_search_count;
80582 #endif
80583 assert( p->deferredMoveto );
@@ -80332,11 +80645,11 @@
80645 if( p->aAltMap && (iMap = p->aAltMap[1+*piCol])>0 ){
80646 *pp = p->pAltCursor;
80647 *piCol = iMap - 1;
80648 return SQLITE_OK;
80649 }
80650 return sqlite3VdbeFinishMoveto(p);
80651 }
80652 if( sqlite3BtreeCursorHasMoved(p->uc.pCursor) ){
80653 return handleMovedCursor(p);
80654 }
80655 return SQLITE_OK;
@@ -84375,10 +84688,30 @@
84688 # define UPDATE_MAX_BLOBSIZE(P) updateMaxBlobsize(P)
84689 #else
84690 # define UPDATE_MAX_BLOBSIZE(P)
84691 #endif
84692
84693 #ifdef SQLITE_DEBUG
84694 /* This routine provides a convenient place to set a breakpoint during
84695 ** tracing with PRAGMA vdbe_trace=on. The breakpoint fires right after
84696 ** each opcode is printed. Variables "pc" (program counter) and pOp are
84697 ** available to add conditionals to the breakpoint. GDB example:
84698 **
84699 ** break test_trace_breakpoint if pc=22
84700 **
84701 ** Other useful labels for breakpoints include:
84702 ** test_addop_breakpoint(pc,pOp)
84703 ** sqlite3CorruptError(lineno)
84704 ** sqlite3MisuseError(lineno)
84705 ** sqlite3CantopenError(lineno)
84706 */
84707 static void test_trace_breakpoint(int pc, Op *pOp, Vdbe *v){
84708 static int n = 0;
84709 n++;
84710 }
84711 #endif
84712
84713 /*
84714 ** Invoke the VDBE coverage callback, if that callback is defined. This
84715 ** feature is used for test suite validation only and does not appear an
84716 ** production builds.
84717 **
@@ -84719,16 +85052,13 @@
85052 #ifdef SQLITE_DEBUG
85053 /*
85054 ** Write a nice string representation of the contents of cell pMem
85055 ** into buffer zBuf, length nBuf.
85056 */
85057 SQLITE_PRIVATE void sqlite3VdbeMemPrettyPrint(Mem *pMem, StrAccum *pStr){
 
85058 int f = pMem->flags;
 
85059 static const char *const encnames[] = {"(X)", "(8)", "(16LE)", "(16BE)"};
 
85060 if( f&MEM_Blob ){
85061 int i;
85062 char c;
85063 if( f & MEM_Dyn ){
85064 c = 'z';
@@ -84740,61 +85070,44 @@
85070 c = 'e';
85071 assert( (f & (MEM_Static|MEM_Dyn))==0 );
85072 }else{
85073 c = 's';
85074 }
85075 sqlite3_str_appendf(pStr, "%cx[", c);
 
 
 
85076 for(i=0; i<25 && i<pMem->n; i++){
85077 sqlite3_str_appendf(pStr, "%02X", ((int)pMem->z[i] & 0xFF));
 
85078 }
85079 sqlite3_str_appendf(pStr, "|");
85080 for(i=0; i<25 && i<pMem->n; i++){
85081 char z = pMem->z[i];
85082 sqlite3_str_appendchar(pStr, 1, (z<32||z>126)?'.':z);
 
85083 }
85084 sqlite3_str_appendf(pStr,"]");
85085 if( f & MEM_Zero ){
85086 sqlite3_str_appendf(pStr, "+%dz",pMem->u.nZero);
 
85087 }
 
85088 }else if( f & MEM_Str ){
85089 int j;
85090 int c;
85091 if( f & MEM_Dyn ){
85092 c = 'z';
85093 assert( (f & (MEM_Static|MEM_Ephem))==0 );
85094 }else if( f & MEM_Static ){
85095 c = 't';
85096 assert( (f & (MEM_Dyn|MEM_Ephem))==0 );
85097 }else if( f & MEM_Ephem ){
85098 c = 'e';
85099 assert( (f & (MEM_Static|MEM_Dyn))==0 );
85100 }else{
85101 c = 's';
85102 }
85103 sqlite3_str_appendf(pStr, " %c%d[", c, pMem->n);
 
 
 
85104 for(j=0; j<25 && j<pMem->n; j++){
85105 u8 c = pMem->z[j];
85106 sqlite3_str_appendchar(pStr, 1, (c>=0x20&&c<=0x7f) ? c : '.');
85107 }
85108 sqlite3_str_appendf(pStr, "]%s", encnames[pMem->enc]);
 
 
 
 
 
 
 
85109 }
85110 }
85111 #endif
85112
85113 #ifdef SQLITE_DEBUG
@@ -84817,23 +85130,40 @@
85130 printf(" r:%.17g", p->u.r);
85131 #endif
85132 }else if( sqlite3VdbeMemIsRowSet(p) ){
85133 printf(" (rowset)");
85134 }else{
85135 StrAccum acc;
85136 char zBuf[1000];
85137 sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0);
85138 sqlite3VdbeMemPrettyPrint(p, &acc);
85139 printf(" %s", sqlite3StrAccumFinish(&acc));
85140 }
85141 if( p->flags & MEM_Subtype ) printf(" subtype=0x%02x", p->eSubtype);
85142 }
85143 static void registerTrace(int iReg, Mem *p){
85144 printf("R[%d] = ", iReg);
85145 memTracePrint(p);
85146 if( p->pScopyFrom ){
85147 printf(" <== R[%d]", (int)(p->pScopyFrom - &p[-iReg]));
85148 }
85149 printf("\n");
85150 sqlite3VdbeCheckMemInvariants(p);
85151 }
85152 #endif
85153
85154 #ifdef SQLITE_DEBUG
85155 /*
85156 ** Show the values of all registers in the virtual machine. Used for
85157 ** interactive debugging.
85158 */
85159 SQLITE_PRIVATE void sqlite3VdbeRegisterDump(Vdbe *v){
85160 int i;
85161 for(i=1; i<v->nMem; i++) registerTrace(i, v->aMem+i);
85162 }
85163 #endif /* SQLITE_DEBUG */
85164
85165
85166 #ifdef SQLITE_DEBUG
85167 # define REGISTER_TRACE(R,M) if(db->flags&SQLITE_VdbeTrace)registerTrace(R,M)
85168 #else
85169 # define REGISTER_TRACE(R,M)
@@ -85085,10 +85415,11 @@
85415 /* Only allow tracing if SQLITE_DEBUG is defined.
85416 */
85417 #ifdef SQLITE_DEBUG
85418 if( db->flags & SQLITE_VdbeTrace ){
85419 sqlite3VdbePrintOp(stdout, (int)(pOp - aOp), pOp);
85420 test_trace_breakpoint((int)(pOp - aOp),pOp,p);
85421 }
85422 #endif
85423
85424
85425 /* Check to see if we need to simulate an interrupt. This only happens
@@ -85192,10 +85523,24 @@
85523 ** is sometimes set to 1 instead of 0 as a hint to the command-line shell
85524 ** that this Goto is the bottom of a loop and that the lines from P2 down
85525 ** to the current line should be indented for EXPLAIN output.
85526 */
85527 case OP_Goto: { /* jump */
85528
85529 #ifdef SQLITE_DEBUG
85530 /* In debuggging mode, when the p5 flags is set on an OP_Goto, that
85531 ** means we should really jump back to the preceeding OP_ReleaseReg
85532 ** instruction. */
85533 if( pOp->p5 ){
85534 assert( pOp->p2 < (int)(pOp - aOp) );
85535 assert( pOp->p2 > 1 );
85536 pOp = &aOp[pOp->p2 - 2];
85537 assert( pOp[1].opcode==OP_ReleaseReg );
85538 goto check_for_interrupt;
85539 }
85540 #endif
85541
85542 jump_to_p2_and_check_for_interrupt:
85543 pOp = &aOp[pOp->p2 - 1];
85544
85545 /* Opcodes that are used as the bottom of a loop (OP_Next, OP_Prev,
85546 ** OP_VNext, or OP_SorterNext) all jump here upon
@@ -85668,12 +86013,17 @@
86013 assert( pIn1<=&aMem[(p->nMem+1 - p->nCursor)] );
86014 assert( memIsValid(pIn1) );
86015 memAboutToChange(p, pOut);
86016 sqlite3VdbeMemMove(pOut, pIn1);
86017 #ifdef SQLITE_DEBUG
86018 pIn1->pScopyFrom = 0;
86019 { int i;
86020 for(i=1; i<p->nMem; i++){
86021 if( aMem[i].pScopyFrom==pIn1 ){
86022 aMem[i].pScopyFrom = pOut;
86023 }
86024 }
86025 }
86026 #endif
86027 Deephemeralize(pOut);
86028 REGISTER_TRACE(p2++, pOut);
86029 pIn1++;
@@ -85810,16 +86160,25 @@
86160 Deephemeralize(&pMem[i]);
86161 assert( (pMem[i].flags & MEM_Ephem)==0
86162 || (pMem[i].flags & (MEM_Str|MEM_Blob))==0 );
86163 sqlite3VdbeMemNulTerminate(&pMem[i]);
86164 REGISTER_TRACE(pOp->p1+i, &pMem[i]);
86165 #ifdef SQLITE_DEBUG
86166 /* The registers in the result will not be used again when the
86167 ** prepared statement restarts. This is because sqlite3_column()
86168 ** APIs might have caused type conversions of made other changes to
86169 ** the register values. Therefore, we can go ahead and break any
86170 ** OP_SCopy dependencies. */
86171 pMem[i].pScopyFrom = 0;
86172 #endif
86173 }
86174 if( db->mallocFailed ) goto no_mem;
86175
86176 if( db->mTrace & SQLITE_TRACE_ROW ){
86177 db->xTrace(SQLITE_TRACE_ROW, db->pTraceArg, p, 0);
86178 }
86179
86180
86181 /* Return SQLITE_ROW
86182 */
86183 p->pc = (int)(pOp - aOp) + 1;
86184 rc = SQLITE_ROW;
@@ -87132,14 +87491,15 @@
87491 ** So we might as well use bogus content rather than reading
87492 ** content from disk.
87493 **
87494 ** Although sqlite3VdbeSerialGet() may read at most 8 bytes from the
87495 ** buffer passed to it, debugging function VdbeMemPrettyPrint() may
87496 ** read more. Use the global constant sqlite3CtypeMap[] as the array,
87497 ** as that array is 256 bytes long (plenty for VdbeMemPrettyPrint())
87498 ** and it begins with a bunch of zeros.
87499 */
87500 sqlite3VdbeSerialGet((u8*)sqlite3CtypeMap, t, pDest);
 
87501 }else{
87502 rc = sqlite3VdbeMemFromBtree(pC->uc.pCursor, aOffset[p2], len, pDest);
87503 if( rc!=SQLITE_OK ) goto abort_due_to_error;
87504 sqlite3VdbeSerialGet((const u8*)pDest->z, t, pDest);
87505 pDest->flags &= ~MEM_Ephem;
@@ -88657,11 +89017,11 @@
89017
89018 /* Opcode: SeekHit P1 P2 * * *
89019 ** Synopsis: seekHit=P2
89020 **
89021 ** Set the seekHit flag on cursor P1 to the value in P2.
89022 * The seekHit flag is used by the IfNoHope opcode.
89023 **
89024 ** P1 must be a valid b-tree cursor. P2 must be a boolean value,
89025 ** either 0 or 1.
89026 */
89027 case OP_SeekHit: {
@@ -88671,10 +89031,24 @@
89031 assert( pC!=0 );
89032 assert( pOp->p2==0 || pOp->p2==1 );
89033 pC->seekHit = pOp->p2 & 1;
89034 break;
89035 }
89036
89037 /* Opcode: IfNotOpen P1 P2 * * *
89038 ** Synopsis: if( !csr[P1] ) goto P2
89039 **
89040 ** If cursor P1 is not open, jump to instruction P2. Otherwise, fall through.
89041 */
89042 case OP_IfNotOpen: { /* jump */
89043 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
89044 VdbeBranchTaken(p->apCsr[pOp->p1]==0, 2);
89045 if( !p->apCsr[pOp->p1] ){
89046 goto jump_to_p2_and_check_for_interrupt;
89047 }
89048 break;
89049 }
89050
89051 /* Opcode: Found P1 P2 P3 P4 *
89052 ** Synopsis: key=r[P3@P4]
89053 **
89054 ** If P4==0 then register P3 holds a blob constructed by MakeRecord. If
@@ -89160,10 +89534,11 @@
89534 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
89535 assert( memIsValid(pData) );
89536 pC = p->apCsr[pOp->p1];
89537 assert( pC!=0 );
89538 assert( pC->eCurType==CURTYPE_BTREE );
89539 assert( pC->deferredMoveto==0 );
89540 assert( pC->uc.pCursor!=0 );
89541 assert( (pOp->p5 & OPFLAG_ISNOOP) || pC->isTable );
89542 assert( pOp->p4type==P4_TABLE || pOp->p4type>=P4_STATIC );
89543 REGISTER_TRACE(pOp->p2, pData);
89544 sqlite3VdbeIncrWriteCounter(p, pC);
@@ -89277,11 +89652,15 @@
89652 assert( pC->uc.pCursor!=0 );
89653 assert( pC->deferredMoveto==0 );
89654 sqlite3VdbeIncrWriteCounter(p, pC);
89655
89656 #ifdef SQLITE_DEBUG
89657 if( pOp->p4type==P4_TABLE
89658 && HasRowid(pOp->p4.pTab)
89659 && pOp->p5==0
89660 && sqlite3BtreeCursorIsValidNN(pC->uc.pCursor)
89661 ){
89662 /* If p5 is zero, the seek operation that positioned the cursor prior to
89663 ** OP_Delete will have also set the pC->movetoTarget field to the rowid of
89664 ** the row that is being deleted */
89665 i64 iKey = sqlite3BtreeIntegerKey(pC->uc.pCursor);
89666 assert( CORRUPT_DB || pC->movetoTarget==iKey );
@@ -90032,10 +90411,28 @@
90411 assert( pOp->opcode==OP_IdxRowid );
90412 sqlite3VdbeMemSetNull(&aMem[pOp->p2]);
90413 }
90414 break;
90415 }
90416
90417 /* Opcode: FinishSeek P1 * * * *
90418 **
90419 ** If cursor P1 was previously moved via OP_DeferredSeek, complete that
90420 ** seek operation now, without further delay. If the cursor seek has
90421 ** already occurred, this instruction is a no-op.
90422 */
90423 case OP_FinishSeek: {
90424 VdbeCursor *pC; /* The P1 index cursor */
90425
90426 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
90427 pC = p->apCsr[pOp->p1];
90428 if( pC->deferredMoveto ){
90429 rc = sqlite3VdbeFinishMoveto(pC);
90430 if( rc ) goto abort_due_to_error;
90431 }
90432 break;
90433 }
90434
90435 /* Opcode: IdxGE P1 P2 P3 P4 P5
90436 ** Synopsis: key=r[P3@P4]
90437 **
90438 ** The P4 register values beginning with P3 form an unpacked index
@@ -91338,10 +91735,40 @@
91735 }else{
91736 p->expired = pOp->p2+1;
91737 }
91738 break;
91739 }
91740
91741 /* Opcode: CursorLock P1 * * * *
91742 **
91743 ** Lock the btree to which cursor P1 is pointing so that the btree cannot be
91744 ** written by an other cursor.
91745 */
91746 case OP_CursorLock: {
91747 VdbeCursor *pC;
91748 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
91749 pC = p->apCsr[pOp->p1];
91750 assert( pC!=0 );
91751 assert( pC->eCurType==CURTYPE_BTREE );
91752 sqlite3BtreeCursorPin(pC->uc.pCursor);
91753 break;
91754 }
91755
91756 /* Opcode: CursorUnlock P1 * * * *
91757 **
91758 ** Unlock the btree to which cursor P1 is pointing so that it can be
91759 ** written by other cursors.
91760 */
91761 case OP_CursorUnlock: {
91762 VdbeCursor *pC;
91763 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
91764 pC = p->apCsr[pOp->p1];
91765 assert( pC!=0 );
91766 assert( pC->eCurType==CURTYPE_BTREE );
91767 sqlite3BtreeCursorUnpin(pC->uc.pCursor);
91768 break;
91769 }
91770
91771 #ifndef SQLITE_OMIT_SHARED_CACHE
91772 /* Opcode: TableLock P1 P2 P3 P4 *
91773 ** Synopsis: iDb=P1 root=P2 write=P3
91774 **
@@ -92045,11 +92472,11 @@
92472 break;
92473 }
92474 #endif
92475
92476 #ifdef SQLITE_DEBUG
92477 /* Opcode: ReleaseReg P1 P2 P3 * P5
92478 ** Synopsis: release r[P1@P2] mask P3
92479 **
92480 ** Release registers from service. Any content that was in the
92481 ** the registers is unreliable after this opcode completes.
92482 **
@@ -92060,14 +92487,16 @@
92487 ** Releasing a register clears the Mem.pScopyFrom pointer. That means
92488 ** that if the content of the released register was set using OP_SCopy,
92489 ** a change to the value of the source register for the OP_SCopy will no longer
92490 ** generate an assertion fault in sqlite3VdbeMemAboutToChange().
92491 **
92492 ** If P5 is set, then all released registers have their type set
92493 ** to MEM_Undefined so that any subsequent attempt to read the released
92494 ** register (before it is reinitialized) will generate an assertion fault.
92495 **
92496 ** P5 ought to be set on every call to this opcode.
92497 ** However, there are places in the code generator will release registers
92498 ** before their are used, under the (valid) assumption that the registers
92499 ** will not be reallocated for some other purpose before they are used and
92500 ** hence are safe to release.
92501 **
92502 ** This opcode is only available in testing and debugging builds. It is
@@ -92084,11 +92513,11 @@
92513 pMem = &aMem[pOp->p1];
92514 constMask = pOp->p3;
92515 for(i=0; i<pOp->p2; i++, pMem++){
92516 if( i>=32 || (constMask & MASKBIT32(i))==0 ){
92517 pMem->pScopyFrom = 0;
92518 if( i<32 && pOp->p5 ) MemSetTypeFlag(pMem, MEM_Undefined);
92519 }
92520 }
92521 break;
92522 }
92523 #endif
@@ -92142,10 +92571,16 @@
92571 registerTrace(pOrigOp->p2, &aMem[pOrigOp->p2]);
92572 }
92573 if( opProperty & OPFLG_OUT3 ){
92574 registerTrace(pOrigOp->p3, &aMem[pOrigOp->p3]);
92575 }
92576 if( opProperty==0xff ){
92577 /* Never happens. This code exists to avoid a harmless linkage
92578 ** warning aboud sqlite3VdbeRegisterDump() being defined but not
92579 ** used. */
92580 sqlite3VdbeRegisterDump(p);
92581 }
92582 }
92583 #endif /* SQLITE_DEBUG */
92584 #endif /* NDEBUG */
92585 } /* The end of the for(;;) loop the loops through opcodes */
92586
@@ -96270,17 +96705,20 @@
96705 ** result sets in ExprList.a[].zSpan, in the form "DATABASE.TABLE.COLUMN".
96706 ** Check to see if the zSpan given to this routine matches the zDb, zTab,
96707 ** and zCol. If any of zDb, zTab, and zCol are NULL then those fields will
96708 ** match anything.
96709 */
96710 SQLITE_PRIVATE int sqlite3MatchEName(
96711 const struct ExprList_item *pItem,
96712 const char *zCol,
96713 const char *zTab,
96714 const char *zDb
96715 ){
96716 int n;
96717 const char *zSpan;
96718 if( NEVER(pItem->eEName!=ENAME_TAB) ) return 0;
96719 zSpan = pItem->zEName;
96720 for(n=0; ALWAYS(zSpan[n]) && zSpan[n]!='.'; n++){}
96721 if( zDb && (sqlite3StrNICmp(zSpan, zDb, n)!=0 || zDb[n]!=0) ){
96722 return 0;
96723 }
96724 zSpan += n+1;
@@ -96405,11 +96843,11 @@
96843 assert( pTab->nCol>0 );
96844 if( pItem->pSelect && (pItem->pSelect->selFlags & SF_NestedFrom)!=0 ){
96845 int hit = 0;
96846 pEList = pItem->pSelect->pEList;
96847 for(j=0; j<pEList->nExpr; j++){
96848 if( sqlite3MatchEName(&pEList->a[j], zCol, zTab, zDb) ){
96849 cnt++;
96850 cntTab = 2;
96851 pMatch = pItem;
96852 pExpr->iColumn = j;
96853 hit = 1;
@@ -96586,22 +97024,26 @@
97024 && zTab==0
97025 ){
97026 pEList = pNC->uNC.pEList;
97027 assert( pEList!=0 );
97028 for(j=0; j<pEList->nExpr; j++){
97029 char *zAs = pEList->a[j].zEName;
97030 if( pEList->a[j].eEName==ENAME_NAME
97031 && sqlite3_stricmp(zAs, zCol)==0
97032 ){
97033 Expr *pOrig;
97034 assert( pExpr->pLeft==0 && pExpr->pRight==0 );
97035 assert( pExpr->x.pList==0 );
97036 assert( pExpr->x.pSelect==0 );
97037 pOrig = pEList->a[j].pExpr;
97038 if( (pNC->ncFlags&NC_AllowAgg)==0 && ExprHasProperty(pOrig, EP_Agg) ){
97039 sqlite3ErrorMsg(pParse, "misuse of aliased aggregate %s", zAs);
97040 return WRC_Abort;
97041 }
97042 if( ExprHasProperty(pOrig, EP_Win)
97043 && ((pNC->ncFlags&NC_AllowWin)==0 || pNC!=pTopNC )
97044 ){
97045 sqlite3ErrorMsg(pParse, "misuse of aliased window function %s",zAs);
97046 return WRC_Abort;
97047 }
97048 if( sqlite3ExprVectorSize(pOrig)!=1 ){
97049 sqlite3ErrorMsg(pParse, "row value misused");
@@ -97007,28 +97449,27 @@
97449 sqlite3ResolveNotValid(pParse, pNC, "non-deterministic functions",
97450 NC_SelfRef, 0);
97451 }else{
97452 assert( (NC_SelfRef & 0xff)==NC_SelfRef ); /* Must fit in 8 bits */
97453 pExpr->op2 = pNC->ncFlags & NC_SelfRef;
97454 if( pNC->ncFlags & NC_FromDDL ) ExprSetProperty(pExpr, EP_FromDDL);
97455 }
97456 if( (pDef->funcFlags & SQLITE_FUNC_INTERNAL)!=0
97457 && pParse->nested==0
97458 && (pParse->db->mDbFlags & DBFLAG_InternalFunc)==0
97459 ){
97460 /* Internal-use-only functions are disallowed unless the
97461 ** SQL is being compiled using sqlite3NestedParse() or
97462 ** the SQLITE_TESTCTRL_INTERNAL_FUNCTIONS test-control has be
97463 ** used to activate internal functionsn for testing purposes */
97464 no_such_func = 1;
97465 pDef = 0;
97466 }else
97467 if( (pDef->funcFlags & (SQLITE_FUNC_DIRECT|SQLITE_FUNC_UNSAFE))!=0
 
97468 && !IN_RENAME_OBJECT
97469 ){
97470 sqlite3ExprFunctionUsable(pParse, pExpr, pDef);
 
 
 
97471 }
97472 }
97473
97474 if( 0==IN_RENAME_OBJECT ){
97475 #ifndef SQLITE_OMIT_WINDOWFUNC
@@ -97253,12 +97694,13 @@
97694 UNUSED_PARAMETER(pParse);
97695
97696 if( pE->op==TK_ID ){
97697 char *zCol = pE->u.zToken;
97698 for(i=0; i<pEList->nExpr; i++){
97699 if( pEList->a[i].eEName==ENAME_NAME
97700 && sqlite3_stricmp(pEList->a[i].zEName, zCol)==0
97701 ){
97702 return i+1;
97703 }
97704 }
97705 }
97706 return 0;
@@ -98015,10 +98457,15 @@
98457 if( pTab ){
98458 sSrc.nSrc = 1;
98459 sSrc.a[0].zName = pTab->zName;
98460 sSrc.a[0].pTab = pTab;
98461 sSrc.a[0].iCursor = -1;
98462 if( pTab->pSchema!=pParse->db->aDb[1].pSchema ){
98463 /* Cause EP_FromDDL to be set on TK_FUNCTION nodes of non-TEMP
98464 ** schema elements */
98465 type |= NC_FromDDL;
98466 }
98467 }
98468 sNC.pParse = pParse;
98469 sNC.pSrcList = &sSrc;
98470 sNC.ncFlags = type | NC_IsDDL;
98471 if( (rc = sqlite3ResolveExprNames(&sNC, pExpr))!=SQLITE_OK ) return rc;
@@ -98961,13 +99408,15 @@
99408 sqlite3 *db = pParse->db;
99409 if( pLeft==0 ){
99410 return pRight;
99411 }else if( pRight==0 ){
99412 return pLeft;
99413 }else if( (ExprAlwaysFalse(pLeft) || ExprAlwaysFalse(pRight))
99414 && !IN_RENAME_OBJECT
99415 ){
99416 sqlite3ExprDelete(db, pLeft);
99417 sqlite3ExprDelete(db, pRight);
99418 return sqlite3Expr(db, TK_INTEGER, "0");
99419 }else{
99420 return sqlite3PExpr(pParse, TK_AND, pLeft, pRight);
99421 }
99422 }
@@ -98998,10 +99447,44 @@
99447 assert( !ExprHasProperty(pNew, EP_xIsSelect) );
99448 sqlite3ExprSetHeightAndFlags(pParse, pNew);
99449 if( eDistinct==SF_Distinct ) ExprSetProperty(pNew, EP_Distinct);
99450 return pNew;
99451 }
99452
99453 /*
99454 ** Check to see if a function is usable according to current access
99455 ** rules:
99456 **
99457 ** SQLITE_FUNC_DIRECT - Only usable from top-level SQL
99458 **
99459 ** SQLITE_FUNC_UNSAFE - Usable if TRUSTED_SCHEMA or from
99460 ** top-level SQL
99461 **
99462 ** If the function is not usable, create an error.
99463 */
99464 SQLITE_PRIVATE void sqlite3ExprFunctionUsable(
99465 Parse *pParse, /* Parsing and code generating context */
99466 Expr *pExpr, /* The function invocation */
99467 FuncDef *pDef /* The function being invoked */
99468 ){
99469 assert( !IN_RENAME_OBJECT );
99470 assert( (pDef->funcFlags & (SQLITE_FUNC_DIRECT|SQLITE_FUNC_UNSAFE))!=0 );
99471 if( ExprHasProperty(pExpr, EP_FromDDL) ){
99472 if( (pDef->funcFlags & SQLITE_FUNC_DIRECT)!=0
99473 || (pParse->db->flags & SQLITE_TrustedSchema)==0
99474 ){
99475 /* Functions prohibited in triggers and views if:
99476 ** (1) tagged with SQLITE_DIRECTONLY
99477 ** (2) not tagged with SQLITE_INNOCUOUS (which means it
99478 ** is tagged with SQLITE_FUNC_UNSAFE) and
99479 ** SQLITE_DBCONFIG_TRUSTED_SCHEMA is off (meaning
99480 ** that the schema is possibly tainted).
99481 */
99482 sqlite3ErrorMsg(pParse, "unsafe use of %s()", pDef->zName);
99483 }
99484 }
99485 }
99486
99487 /*
99488 ** Assign a variable number to an expression that encodes a wildcard
99489 ** in the original SQL statement.
99490 **
@@ -99466,16 +99949,15 @@
99949 assert( pNewExpr->iColumn==pItem[-1].pExpr->iColumn+1 );
99950 assert( pPriorSelectCol==pItem[-1].pExpr->pLeft );
99951 pNewExpr->pLeft = pPriorSelectCol;
99952 }
99953 }
99954 pItem->zEName = sqlite3DbStrDup(db, pOldItem->zEName);
 
99955 pItem->sortFlags = pOldItem->sortFlags;
99956 pItem->eEName = pOldItem->eEName;
99957 pItem->done = 0;
99958 pItem->bNulls = pOldItem->bNulls;
 
99959 pItem->bSorterRef = pOldItem->bSorterRef;
99960 pItem->u = pOldItem->u;
99961 }
99962 return pNew;
99963 }
@@ -99638,13 +100120,13 @@
100120 goto no_mem;
100121 }
100122 pList = pNew;
100123 }
100124 pItem = &pList->a[pList->nExpr++];
100125 assert( offsetof(struct ExprList_item,zEName)==sizeof(pItem->pExpr) );
100126 assert( offsetof(struct ExprList_item,pExpr)==0 );
100127 memset(&pItem->zEName,0,sizeof(*pItem)-offsetof(struct ExprList_item,zEName));
100128 pItem->pExpr = pExpr;
100129 return pList;
100130
100131 no_mem:
100132 /* Avoid leaking memory if malloc has failed. */
@@ -99697,11 +100179,11 @@
100179 if( pSubExpr==0 ) continue;
100180 pSubExpr->iTable = pColumns->nId;
100181 pList = sqlite3ExprListAppend(pParse, pList, pSubExpr);
100182 if( pList ){
100183 assert( pList->nExpr==iFirst+i+1 );
100184 pList->a[pList->nExpr-1].zEName = pColumns->a[i].zName;
100185 pColumns->a[i].zName = 0;
100186 }
100187 }
100188
100189 if( !db->mallocFailed && pExpr->op==TK_SELECT && ALWAYS(pList!=0) ){
@@ -99757,11 +100239,11 @@
100239 }
100240 }
100241 }
100242
100243 /*
100244 ** Set the ExprList.a[].zEName element of the most recently added item
100245 ** on the expression list.
100246 **
100247 ** pList might be NULL following an OOM error. But pName should never be
100248 ** NULL. If a memory allocation fails, the pParse->db->mallocFailed flag
100249 ** is set.
@@ -99775,15 +100257,16 @@
100257 assert( pList!=0 || pParse->db->mallocFailed!=0 );
100258 if( pList ){
100259 struct ExprList_item *pItem;
100260 assert( pList->nExpr>0 );
100261 pItem = &pList->a[pList->nExpr-1];
100262 assert( pItem->zEName==0 );
100263 assert( pItem->eEName==ENAME_NAME );
100264 pItem->zEName = sqlite3DbStrNDup(pParse->db, pName->z, pName->n);
100265 if( dequote ) sqlite3Dequote(pItem->zEName);
100266 if( IN_RENAME_OBJECT ){
100267 sqlite3RenameTokenMap(pParse, (void*)pItem->zEName, pName);
100268 }
100269 }
100270 }
100271
100272 /*
@@ -99803,12 +100286,14 @@
100286 sqlite3 *db = pParse->db;
100287 assert( pList!=0 || db->mallocFailed!=0 );
100288 if( pList ){
100289 struct ExprList_item *pItem = &pList->a[pList->nExpr-1];
100290 assert( pList->nExpr>0 );
100291 if( pItem->zEName==0 ){
100292 pItem->zEName = sqlite3DbSpanDup(db, zStart, zEnd);
100293 pItem->eEName = ENAME_SPAN;
100294 }
100295 }
100296 }
100297
100298 /*
100299 ** If the expression list pEList contains more than iLimit elements,
@@ -99834,12 +100319,11 @@
100319 int i = pList->nExpr;
100320 struct ExprList_item *pItem = pList->a;
100321 assert( pList->nExpr>0 );
100322 do{
100323 sqlite3ExprDelete(db, pItem->pExpr);
100324 sqlite3DbFree(db, pItem->zEName);
 
100325 pItem++;
100326 }while( --i>0 );
100327 sqlite3DbFreeNN(db, pList);
100328 }
100329 SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3 *db, ExprList *pList){
@@ -99872,24 +100356,39 @@
100356 SQLITE_PRIVATE int sqlite3SelectWalkFail(Walker *pWalker, Select *NotUsed){
100357 UNUSED_PARAMETER(NotUsed);
100358 pWalker->eCode = 0;
100359 return WRC_Abort;
100360 }
100361
100362 /*
100363 ** Check the input string to see if it is "true" or "false" (in any case).
100364 **
100365 ** If the string is.... Return
100366 ** "true" EP_IsTrue
100367 ** "false" EP_IsFalse
100368 ** anything else 0
100369 */
100370 SQLITE_PRIVATE u32 sqlite3IsTrueOrFalse(const char *zIn){
100371 if( sqlite3StrICmp(zIn, "true")==0 ) return EP_IsTrue;
100372 if( sqlite3StrICmp(zIn, "false")==0 ) return EP_IsFalse;
100373 return 0;
100374 }
100375
100376
100377 /*
100378 ** If the input expression is an ID with the name "true" or "false"
100379 ** then convert it into an TK_TRUEFALSE term. Return non-zero if
100380 ** the conversion happened, and zero if the expression is unaltered.
100381 */
100382 SQLITE_PRIVATE int sqlite3ExprIdToTrueFalse(Expr *pExpr){
100383 u32 v;
100384 assert( pExpr->op==TK_ID || pExpr->op==TK_STRING );
100385 if( !ExprHasProperty(pExpr, EP_Quoted)
100386 && (v = sqlite3IsTrueOrFalse(pExpr->u.zToken))!=0
 
100387 ){
100388 pExpr->op = TK_TRUEFALSE;
100389 ExprSetProperty(pExpr, v);
100390 return 1;
100391 }
100392 return 0;
100393 }
100394
@@ -99947,14 +100446,15 @@
100446 ** sqlite3ExprIsConstantOrFunction() pWalker->eCode==4 or 5
100447 **
100448 ** In all cases, the callbacks set Walker.eCode=0 and abort if the expression
100449 ** is found to not be a constant.
100450 **
100451 ** The sqlite3ExprIsConstantOrFunction() is used for evaluating DEFAULT
100452 ** expressions in a CREATE TABLE statement. The Walker.eCode value is 5
100453 ** when parsing an existing schema out of the sqlite_master table and 4
100454 ** when processing a new CREATE TABLE statement. A bound parameter raises
100455 ** an error for new statements, but is silently converted
100456 ** to NULL for existing schemas. This allows sqlite_master tables that
100457 ** contain a bound parameter because they were generated by older versions
100458 ** of SQLite to be parsed by newer versions of SQLite without raising a
100459 ** malformed schema error.
100460 */
@@ -99974,10 +100474,11 @@
100474 ** SQLITE_FUNC_CONST flag. */
100475 case TK_FUNCTION:
100476 if( (pWalker->eCode>=4 || ExprHasProperty(pExpr,EP_ConstFunc))
100477 && !ExprHasProperty(pExpr, EP_WinFunc)
100478 ){
100479 if( pWalker->eCode==5 ) ExprSetProperty(pExpr, EP_FromDDL);
100480 return WRC_Continue;
100481 }else{
100482 pWalker->eCode = 0;
100483 return WRC_Abort;
100484 }
@@ -100137,13 +100638,25 @@
100638 sqlite3WalkExpr(&w, p);
100639 return w.eCode;
100640 }
100641
100642 /*
100643 ** Walk an expression tree for the DEFAULT field of a column definition
100644 ** in a CREATE TABLE statement. Return non-zero if the expression is
100645 ** acceptable for use as a DEFAULT. That is to say, return non-zero if
100646 ** the expression is constant or a function call with constant arguments.
100647 ** Return and 0 if there are any variables.
100648 **
100649 ** isInit is true when parsing from sqlite_master. isInit is false when
100650 ** processing a new CREATE TABLE statement. When isInit is true, parameters
100651 ** (such as ? or $abc) in the expression are converted into NULL. When
100652 ** isInit is false, parameters raise an error. Parameters should not be
100653 ** allowed in a CREATE TABLE statement, but some legacy versions of SQLite
100654 ** allowed it, so we need to support it when reading sqlite_master for
100655 ** backwards compatibility.
100656 **
100657 ** If isInit is true, set EP_FromDDL on every TK_FUNCTION node.
100658 **
100659 ** For the purposes of this function, a double-quoted string (ex: "abc")
100660 ** is considered a variable but a single-quoted string (ex: 'abc') is
100661 ** a constant.
100662 */
@@ -101219,10 +101732,11 @@
101732 r2 = sqlite3ExprCodeTemp(pParse, pList->a[ii].pExpr, &regToFree);
101733 }
101734 if( regCkNull && sqlite3ExprCanBeNull(pList->a[ii].pExpr) ){
101735 sqlite3VdbeAddOp3(v, OP_BitAnd, regCkNull, r2, regCkNull);
101736 }
101737 sqlite3ReleaseTempReg(pParse, regToFree);
101738 if( ii<pList->nExpr-1 || destIfNull!=destIfFalse ){
101739 int op = rLhs!=r2 ? OP_Eq : OP_NotNull;
101740 sqlite3VdbeAddOp4(v, op, rLhs, labelOk, r2,
101741 (void*)pColl, P4_COLLSEQ);
101742 VdbeCoverageIf(v, ii<pList->nExpr-1 && op==OP_Eq);
@@ -101237,11 +101751,10 @@
101751 (void*)pColl, P4_COLLSEQ);
101752 VdbeCoverageIf(v, op==OP_Ne);
101753 VdbeCoverageIf(v, op==OP_IsNull);
101754 sqlite3VdbeChangeP5(v, zAff[0] | SQLITE_JUMPIFNULL);
101755 }
 
101756 }
101757 if( regCkNull ){
101758 sqlite3VdbeAddOp2(v, OP_IsNull, regCkNull, destIfNull); VdbeCoverage(v);
101759 sqlite3VdbeGoto(v, destIfFalse);
101760 }
@@ -101598,10 +102111,113 @@
102111 }
102112 }
102113 }
102114 return iResult;
102115 }
102116
102117 /*
102118 ** Generate code to implement special SQL functions that are implemented
102119 ** in-line rather than by using the usual callbacks.
102120 */
102121 static int exprCodeInlineFunction(
102122 Parse *pParse, /* Parsing context */
102123 ExprList *pFarg, /* List of function arguments */
102124 int iFuncId, /* Function ID. One of the INTFUNC_... values */
102125 int target /* Store function result in this register */
102126 ){
102127 int nFarg;
102128 Vdbe *v = pParse->pVdbe;
102129 assert( v!=0 );
102130 assert( pFarg!=0 );
102131 nFarg = pFarg->nExpr;
102132 assert( nFarg>0 ); /* All in-line functions have at least one argument */
102133 switch( iFuncId ){
102134 case INLINEFUNC_coalesce: {
102135 /* Attempt a direct implementation of the built-in COALESCE() and
102136 ** IFNULL() functions. This avoids unnecessary evaluation of
102137 ** arguments past the first non-NULL argument.
102138 */
102139 int endCoalesce = sqlite3VdbeMakeLabel(pParse);
102140 int i;
102141 assert( nFarg>=2 );
102142 sqlite3ExprCode(pParse, pFarg->a[0].pExpr, target);
102143 for(i=1; i<nFarg; i++){
102144 sqlite3VdbeAddOp2(v, OP_NotNull, target, endCoalesce);
102145 VdbeCoverage(v);
102146 sqlite3ExprCode(pParse, pFarg->a[i].pExpr, target);
102147 }
102148 if( sqlite3VdbeGetOp(v, -1)->opcode==OP_Copy ){
102149 sqlite3VdbeChangeP5(v, 1); /* Tag trailing OP_Copy as not mergable */
102150 }
102151 sqlite3VdbeResolveLabel(v, endCoalesce);
102152 break;
102153 }
102154
102155 default: {
102156 /* The UNLIKELY() function is a no-op. The result is the value
102157 ** of the first argument.
102158 */
102159 assert( nFarg==1 || nFarg==2 );
102160 target = sqlite3ExprCodeTarget(pParse, pFarg->a[0].pExpr, target);
102161 break;
102162 }
102163
102164 /***********************************************************************
102165 ** Test-only SQL functions that are only usable if enabled
102166 ** via SQLITE_TESTCTRL_INTERNAL_FUNCTIONS
102167 */
102168 case INLINEFUNC_expr_compare: {
102169 /* Compare two expressions using sqlite3ExprCompare() */
102170 assert( nFarg==2 );
102171 sqlite3VdbeAddOp2(v, OP_Integer,
102172 sqlite3ExprCompare(0,pFarg->a[0].pExpr, pFarg->a[1].pExpr,-1),
102173 target);
102174 break;
102175 }
102176
102177 case INLINEFUNC_expr_implies_expr: {
102178 /* Compare two expressions using sqlite3ExprImpliesExpr() */
102179 assert( nFarg==2 );
102180 sqlite3VdbeAddOp2(v, OP_Integer,
102181 sqlite3ExprImpliesExpr(pParse,pFarg->a[0].pExpr, pFarg->a[1].pExpr,-1),
102182 target);
102183 break;
102184 }
102185
102186 case INLINEFUNC_implies_nonnull_row: {
102187 /* REsult of sqlite3ExprImpliesNonNullRow() */
102188 Expr *pA1;
102189 assert( nFarg==2 );
102190 pA1 = pFarg->a[1].pExpr;
102191 if( pA1->op==TK_COLUMN ){
102192 sqlite3VdbeAddOp2(v, OP_Integer,
102193 sqlite3ExprImpliesNonNullRow(pFarg->a[0].pExpr,pA1->iTable),
102194 target);
102195 }else{
102196 sqlite3VdbeAddOp2(v, OP_Null, 0, target);
102197 }
102198 break;
102199 }
102200
102201 #ifdef SQLITE_DEBUG
102202 case INLINEFUNC_affinity: {
102203 /* The AFFINITY() function evaluates to a string that describes
102204 ** the type affinity of the argument. This is used for testing of
102205 ** the SQLite type logic.
102206 */
102207 const char *azAff[] = { "blob", "text", "numeric", "integer", "real" };
102208 char aff;
102209 assert( nFarg==1 );
102210 aff = sqlite3ExprAffinity(pFarg->a[0].pExpr);
102211 sqlite3VdbeLoadString(v, target,
102212 (aff<=SQLITE_AFF_NONE) ? "none" : azAff[aff-SQLITE_AFF_BLOB]);
102213 break;
102214 }
102215 #endif
102216 }
102217 return target;
102218 }
102219
102220
102221 /*
102222 ** Generate code into the current Vdbe to evaluate the given
102223 ** expression. Attempt to store the results in register "target".
@@ -101979,51 +102595,18 @@
102595 #endif
102596 if( pDef==0 || pDef->xFinalize!=0 ){
102597 sqlite3ErrorMsg(pParse, "unknown function: %s()", zId);
102598 break;
102599 }
102600 if( pDef->funcFlags & SQLITE_FUNC_INLINE ){
102601 assert( (pDef->funcFlags & SQLITE_FUNC_UNSAFE)==0 );
102602 assert( (pDef->funcFlags & SQLITE_FUNC_DIRECT)==0 );
102603 return exprCodeInlineFunction(pParse, pFarg,
102604 SQLITE_PTR_TO_INT(pDef->pUserData), target);
102605 }else if( pDef->funcFlags & (SQLITE_FUNC_DIRECT|SQLITE_FUNC_UNSAFE) ){
102606 sqlite3ExprFunctionUsable(pParse, pExpr, pDef);
102607 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102608
102609 for(i=0; i<nFarg; i++){
102610 if( i<32 && sqlite3ExprIsConstant(pFarg->a[i].pExpr) ){
102611 testcase( i==31 );
102612 constMask |= MASKBIT32(i);
@@ -102103,11 +102686,11 @@
102686 }
102687 if( nFarg ){
102688 if( constMask==0 ){
102689 sqlite3ReleaseTempRange(pParse, r1, nFarg);
102690 }else{
102691 sqlite3VdbeReleaseRegisters(pParse, r1, nFarg, constMask, 1);
102692 }
102693 }
102694 return target;
102695 }
102696 #ifndef SQLITE_OMIT_SUBQUERY
@@ -102455,11 +103038,17 @@
103038
103039 assert( target>0 && target<=pParse->nMem );
103040 inReg = sqlite3ExprCodeTarget(pParse, pExpr, target);
103041 assert( pParse->pVdbe!=0 || pParse->db->mallocFailed );
103042 if( inReg!=target && pParse->pVdbe ){
103043 u8 op;
103044 if( ExprHasProperty(pExpr,EP_Subquery) ){
103045 op = OP_Copy;
103046 }else{
103047 op = OP_SCopy;
103048 }
103049 sqlite3VdbeAddOp2(pParse->pVdbe, op, inReg, target);
103050 }
103051 }
103052
103053 /*
103054 ** Make a transient copy of expression pExpr and then code it using
@@ -102548,10 +103137,11 @@
103137 VdbeOp *pOp;
103138 if( copyOp==OP_Copy
103139 && (pOp=sqlite3VdbeGetOp(v, -1))->opcode==OP_Copy
103140 && pOp->p1+pOp->p3+1==inReg
103141 && pOp->p2+pOp->p3+1==target+i
103142 && pOp->p5==0 /* The do-not-merge flag must be clear */
103143 ){
103144 pOp->p3++;
103145 }else{
103146 sqlite3VdbeAddOp2(v, copyOp, inReg, target+i);
103147 }
@@ -103120,12 +103710,13 @@
103710 }
103711 return 0;
103712 }
103713
103714 /*
103715 ** Compare two ExprList objects. Return 0 if they are identical, 1
103716 ** if they are certainly different, or 2 if it is not possible to
103717 ** determine if they are identical or not.
103718 **
103719 ** If any subelement of pB has Expr.iTable==(-1) then it is allowed
103720 ** to compare equal to an equivalent element in pA with Expr.iTable==iTab.
103721 **
103722 ** This routine might return non-zero for equivalent ExprLists. The
@@ -103140,14 +103731,15 @@
103731 int i;
103732 if( pA==0 && pB==0 ) return 0;
103733 if( pA==0 || pB==0 ) return 1;
103734 if( pA->nExpr!=pB->nExpr ) return 1;
103735 for(i=0; i<pA->nExpr; i++){
103736 int res;
103737 Expr *pExprA = pA->a[i].pExpr;
103738 Expr *pExprB = pB->a[i].pExpr;
103739 if( pA->a[i].sortFlags!=pB->a[i].sortFlags ) return 1;
103740 if( (res = sqlite3ExprCompare(0, pExprA, pExprB, iTab)) ) return res;
103741 }
103742 return 0;
103743 }
103744
103745 /*
@@ -103322,15 +103914,16 @@
103914 return WRC_Abort;
103915 }
103916 return WRC_Prune;
103917
103918 case TK_AND:
103919 if( pWalker->eCode==0 ){
103920 sqlite3WalkExpr(pWalker, pExpr->pLeft);
103921 if( pWalker->eCode ){
103922 pWalker->eCode = 0;
103923 sqlite3WalkExpr(pWalker, pExpr->pRight);
103924 }
103925 }
103926 return WRC_Prune;
103927
103928 case TK_BETWEEN:
103929 if( sqlite3WalkExpr(pWalker, pExpr->pLeft)==WRC_Abort ){
@@ -103477,16 +104070,17 @@
104070
104071 /*
104072 ** Count the number of references to columns.
104073 */
104074 static int exprSrcCount(Walker *pWalker, Expr *pExpr){
104075 /* There was once a NEVER() on the second term on the grounds that
104076 ** sqlite3FunctionUsesThisSrc() was always called before
104077 ** sqlite3ExprAnalyzeAggregates() and so the TK_COLUMNs have not yet
104078 ** been converted into TK_AGG_COLUMN. But this is no longer true due
104079 ** to window functions - sqlite3WindowRewrite() may now indirectly call
104080 ** FunctionUsesThisSrc() when creating a new sub-select. */
104081 if( pExpr->op==TK_COLUMN || pExpr->op==TK_AGG_COLUMN ){
104082 int i;
104083 struct SrcCount *p = pWalker->u.pSrcCount;
104084 SrcList *pSrc = p->pSrc;
104085 int nSrc = pSrc ? pSrc->nSrc : 0;
104086 for(i=0; i<nSrc; i++){
@@ -103520,10 +104114,15 @@
104114 w.u.pSrcCount = &cnt;
104115 cnt.pSrc = pSrcList;
104116 cnt.nThis = 0;
104117 cnt.nOther = 0;
104118 sqlite3WalkExprList(&w, pExpr->x.pList);
104119 #ifndef SQLITE_OMIT_WINDOWFUNC
104120 if( ExprHasProperty(pExpr, EP_WinFunc) ){
104121 sqlite3WalkExpr(&w, pExpr->y.pWin->pFilter);
104122 }
104123 #endif
104124 return cnt.nThis>0 || cnt.nOther==0;
104125 }
104126
104127 /*
104128 ** Add a new element to the pAggInfo->aCol[] array. Return the index of
@@ -103749,11 +104348,11 @@
104348 ** Deallocate a register, making available for reuse for some other
104349 ** purpose.
104350 */
104351 SQLITE_PRIVATE void sqlite3ReleaseTempReg(Parse *pParse, int iReg){
104352 if( iReg ){
104353 sqlite3VdbeReleaseRegisters(pParse, iReg, 1, 0, 0);
104354 if( pParse->nTempReg<ArraySize(pParse->aTempReg) ){
104355 pParse->aTempReg[pParse->nTempReg++] = iReg;
104356 }
104357 }
104358 }
@@ -103778,11 +104377,11 @@
104377 SQLITE_PRIVATE void sqlite3ReleaseTempRange(Parse *pParse, int iReg, int nReg){
104378 if( nReg==1 ){
104379 sqlite3ReleaseTempReg(pParse, iReg);
104380 return;
104381 }
104382 sqlite3VdbeReleaseRegisters(pParse, iReg, nReg, 0, 0);
104383 if( nReg>pParse->nRangeReg ){
104384 pParse->nRangeReg = nReg;
104385 pParse->iRangeReg = iReg;
104386 }
104387 }
@@ -104591,12 +105190,12 @@
105190 if( pParse->nErr ) return WRC_Abort;
105191 if( NEVER(p->selFlags & SF_View) ) return WRC_Prune;
105192 if( ALWAYS(p->pEList) ){
105193 ExprList *pList = p->pEList;
105194 for(i=0; i<pList->nExpr; i++){
105195 if( pList->a[i].zEName && pList->a[i].eEName==ENAME_NAME ){
105196 sqlite3RenameTokenRemap(pParse, 0, (void*)pList->a[i].zEName);
105197 }
105198 }
105199 }
105200 if( ALWAYS(p->pSrc) ){ /* Every Select as a SrcList, even if it is empty */
105201 SrcList *pSrc = p->pSrc;
@@ -104636,11 +105235,13 @@
105235 memset(&sWalker, 0, sizeof(Walker));
105236 sWalker.pParse = pParse;
105237 sWalker.xExprCallback = renameUnmapExprCb;
105238 sqlite3WalkExprList(&sWalker, pEList);
105239 for(i=0; i<pEList->nExpr; i++){
105240 if( ALWAYS(pEList->a[i].eEName==ENAME_NAME) ){
105241 sqlite3RenameTokenRemap(pParse, 0, (void*)pEList->a[i].zEName);
105242 }
105243 }
105244 }
105245 }
105246
105247 /*
@@ -104774,12 +105375,15 @@
105375 const char *zOld
105376 ){
105377 if( pEList ){
105378 int i;
105379 for(i=0; i<pEList->nExpr; i++){
105380 char *zName = pEList->a[i].zEName;
105381 if( ALWAYS(pEList->a[i].eEName==ENAME_NAME)
105382 && ALWAYS(zName!=0)
105383 && 0==sqlite3_stricmp(zName, zOld)
105384 ){
105385 renameTokenFind(pParse, pCtx, (void*)zName);
105386 }
105387 }
105388 }
105389 }
@@ -107879,11 +108483,11 @@
108483 pFix->pParse = pParse;
108484 pFix->zDb = db->aDb[iDb].zDbSName;
108485 pFix->pSchema = db->aDb[iDb].pSchema;
108486 pFix->zType = zType;
108487 pFix->pName = pName;
108488 pFix->bTemp = (iDb==1);
108489 }
108490
108491 /*
108492 ** The following set of routines walk through the parse tree and assign
108493 ** a specific database to all table references where the database name
@@ -107907,20 +108511,21 @@
108511 struct SrcList_item *pItem;
108512
108513 if( NEVER(pList==0) ) return 0;
108514 zDb = pFix->zDb;
108515 for(i=0, pItem=pList->a; i<pList->nSrc; i++, pItem++){
108516 if( pFix->bTemp==0 ){
108517 if( pItem->zDatabase && sqlite3StrICmp(pItem->zDatabase, zDb) ){
108518 sqlite3ErrorMsg(pFix->pParse,
108519 "%s %T cannot reference objects in database %s",
108520 pFix->zType, pFix->pName, pItem->zDatabase);
108521 return 1;
108522 }
108523 sqlite3DbFree(pFix->pParse->db, pItem->zDatabase);
108524 pItem->zDatabase = 0;
108525 pItem->pSchema = pFix->pSchema;
108526 pItem->fg.fromDDL = 1;
108527 }
108528 #if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_TRIGGER)
108529 if( sqlite3FixSelect(pFix, pItem->pSelect) ) return 1;
108530 if( sqlite3FixExpr(pFix, pItem->pOn) ) return 1;
108531 #endif
@@ -107972,11 +108577,11 @@
108577 SQLITE_PRIVATE int sqlite3FixExpr(
108578 DbFixer *pFix, /* Context of the fixation */
108579 Expr *pExpr /* The expression to be fixed to one database */
108580 ){
108581 while( pExpr ){
108582 if( !pFix->bTemp ) ExprSetProperty(pExpr, EP_FromDDL);
108583 if( pExpr->op==TK_VARIABLE ){
108584 if( pFix->pParse->db->init.busy ){
108585 pExpr->op = TK_NULL;
108586 }else{
108587 sqlite3ErrorMsg(pFix->pParse, "%s cannot use variables", pFix->zType);
@@ -109727,12 +110332,13 @@
110332 Table *p;
110333 Column *pCol;
110334 sqlite3 *db = pParse->db;
110335 p = pParse->pNewTable;
110336 if( p!=0 ){
110337 int isInit = db->init.busy && db->init.iDb!=1;
110338 pCol = &(p->aCol[p->nCol-1]);
110339 if( !sqlite3ExprIsConstantOrFunction(pExpr, isInit) ){
110340 sqlite3ErrorMsg(pParse, "default value of column [%s] is not constant",
110341 pCol->zName);
110342 #ifndef SQLITE_OMIT_GENERATED_COLUMNS
110343 }else if( pCol->colFlags & COLFLAG_GENERATED ){
110344 testcase( pCol->colFlags & COLFLAG_VIRTUAL );
@@ -110948,11 +111554,14 @@
111554 db->xAuth = xAuth;
111555 #else
111556 pSelTab = sqlite3ResultSetOfSelect(pParse, pSel, SQLITE_AFF_NONE);
111557 #endif
111558 pParse->nTab = n;
111559 if( pSelTab==0 ){
111560 pTable->nCol = 0;
111561 nErr++;
111562 }else if( pTable->pCheck ){
111563 /* CREATE VIEW name(arglist) AS ...
111564 ** The names of the columns in the table are taken from
111565 ** arglist which is stored in pTable->pCheck. The pCheck field
111566 ** normally holds CHECK constraints on an ordinary table, but for
111567 ** a VIEW it holds the list of column names.
@@ -110964,23 +111573,20 @@
111573 && pTable->nCol==pSel->pEList->nExpr
111574 ){
111575 sqlite3SelectAddColumnTypeAndCollation(pParse, pTable, pSel,
111576 SQLITE_AFF_NONE);
111577 }
111578 }else{
111579 /* CREATE VIEW name AS... without an argument list. Construct
111580 ** the column names from the SELECT statement that defines the view.
111581 */
111582 assert( pTable->aCol==0 );
111583 pTable->nCol = pSelTab->nCol;
111584 pTable->aCol = pSelTab->aCol;
111585 pSelTab->nCol = 0;
111586 pSelTab->aCol = 0;
111587 assert( sqlite3SchemaMutexHeld(db, 0, pTable->pSchema) );
 
 
 
111588 }
111589 pTable->nNVCol = pTable->nCol;
111590 sqlite3DeleteTable(db, pSelTab);
111591 sqlite3SelectDelete(db, pSel);
111592 EnableLookaside;
@@ -111430,11 +112036,11 @@
112036 nCol = pFromCol->nExpr;
112037 }
112038 nByte = sizeof(*pFKey) + (nCol-1)*sizeof(pFKey->aCol[0]) + pTo->n + 1;
112039 if( pToCol ){
112040 for(i=0; i<pToCol->nExpr; i++){
112041 nByte += sqlite3Strlen30(pToCol->a[i].zEName) + 1;
112042 }
112043 }
112044 pFKey = sqlite3DbMallocZero(db, nByte );
112045 if( pFKey==0 ){
112046 goto fk_end;
@@ -111455,34 +112061,34 @@
112061 pFKey->aCol[0].iFrom = p->nCol-1;
112062 }else{
112063 for(i=0; i<nCol; i++){
112064 int j;
112065 for(j=0; j<p->nCol; j++){
112066 if( sqlite3StrICmp(p->aCol[j].zName, pFromCol->a[i].zEName)==0 ){
112067 pFKey->aCol[i].iFrom = j;
112068 break;
112069 }
112070 }
112071 if( j>=p->nCol ){
112072 sqlite3ErrorMsg(pParse,
112073 "unknown column \"%s\" in foreign key definition",
112074 pFromCol->a[i].zEName);
112075 goto fk_end;
112076 }
112077 if( IN_RENAME_OBJECT ){
112078 sqlite3RenameTokenRemap(pParse, &pFKey->aCol[i], pFromCol->a[i].zEName);
112079 }
112080 }
112081 }
112082 if( pToCol ){
112083 for(i=0; i<nCol; i++){
112084 int n = sqlite3Strlen30(pToCol->a[i].zEName);
112085 pFKey->aCol[i].zCol = z;
112086 if( IN_RENAME_OBJECT ){
112087 sqlite3RenameTokenRemap(pParse, z, pToCol->a[i].zEName);
112088 }
112089 memcpy(z, pToCol->a[i].zEName, n);
112090 z[n] = 0;
112091 z += n+1;
112092 }
112093 }
112094 pFKey->isDeferred = 0;
@@ -113637,16 +114243,17 @@
114243 FuncDef *p, /* The function we are evaluating for match quality */
114244 int nArg, /* Desired number of arguments. (-1)==any */
114245 u8 enc /* Desired text encoding */
114246 ){
114247 int match;
114248 assert( p->nArg>=-1 );
 
 
114249
114250 /* Wrong number of arguments means "no match" */
114251 if( p->nArg!=nArg ){
114252 if( nArg==(-2) ) return (p->xSFunc==0) ? 0 : FUNC_PERFECT_MATCH;
114253 if( p->nArg>=0 ) return 0;
114254 }
114255
114256 /* Give a better score to a function with a specific number of arguments
114257 ** than to function that accepts any number of arguments. */
114258 if( p->nArg==nArg ){
114259 match = 4;
@@ -116747,30 +117354,35 @@
117354 ** are read-only after initialization is complete.
117355 **
117356 ** For peak efficiency, put the most frequently used function last.
117357 */
117358 static FuncDef aBuiltinFunc[] = {
117359 /***** Functions only available with SQLITE_TESTCTRL_INTERNAL_FUNCTIONS *****/
117360 TEST_FUNC(implies_nonnull_row, 2, INLINEFUNC_implies_nonnull_row, 0),
117361 TEST_FUNC(expr_compare, 2, INLINEFUNC_expr_compare, 0),
117362 TEST_FUNC(expr_implies_expr, 2, INLINEFUNC_expr_implies_expr, 0),
117363 #ifdef SQLITE_DEBUG
117364 TEST_FUNC(affinity, 1, INLINEFUNC_affinity, 0),
117365 #endif
117366 /***** Regular functions *****/
117367 #ifdef SQLITE_SOUNDEX
117368 FUNCTION(soundex, 1, 0, 0, soundexFunc ),
117369 #endif
117370 #ifndef SQLITE_OMIT_LOAD_EXTENSION
117371 SFUNCTION(load_extension, 1, 0, 0, loadExt ),
117372 SFUNCTION(load_extension, 2, 0, 0, loadExt ),
117373 #endif
117374 #if SQLITE_USER_AUTHENTICATION
117375 FUNCTION(sqlite_crypt, 2, 0, 0, sqlite3CryptFunc ),
117376 #endif
117377 #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
117378 DFUNCTION(sqlite_compileoption_used,1, 0, 0, compileoptionusedFunc ),
117379 DFUNCTION(sqlite_compileoption_get, 1, 0, 0, compileoptiongetFunc ),
117380 #endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
117381 INLINE_FUNC(unlikely, 1, INLINEFUNC_unlikely, SQLITE_FUNC_UNLIKELY),
117382 INLINE_FUNC(likelihood, 2, INLINEFUNC_unlikely, SQLITE_FUNC_UNLIKELY),
117383 INLINE_FUNC(likely, 1, INLINEFUNC_unlikely, SQLITE_FUNC_UNLIKELY),
 
 
 
117384 #ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
117385 FUNCTION2(sqlite_offset, 1, 0, 0, noopFunc, SQLITE_FUNC_OFFSET|
117386 SQLITE_FUNC_TYPEOF),
117387 #endif
117388 FUNCTION(ltrim, 1, 1, 0, trimFunc ),
@@ -116799,11 +117411,11 @@
117411 FUNCTION(round, 2, 0, 0, roundFunc ),
117412 #endif
117413 FUNCTION(upper, 1, 0, 0, upperFunc ),
117414 FUNCTION(lower, 1, 0, 0, lowerFunc ),
117415 FUNCTION(hex, 1, 0, 0, hexFunc ),
117416 INLINE_FUNC(ifnull, 2, INLINEFUNC_coalesce, SQLITE_FUNC_COALESCE),
117417 VFUNCTION(random, 0, 0, 0, randomFunc ),
117418 VFUNCTION(randomblob, 1, 0, 0, randomBlob ),
117419 FUNCTION(nullif, 2, 0, 1, nullifFunc ),
117420 DFUNCTION(sqlite_version, 0, 0, 0, versionFunc ),
117421 DFUNCTION(sqlite_source_id, 0, 0, 0, sourceidFunc ),
@@ -116839,11 +117451,11 @@
117451 #ifdef SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION
117452 FUNCTION(unknown, -1, 0, 0, unknownFunc ),
117453 #endif
117454 FUNCTION(coalesce, 1, 0, 0, 0 ),
117455 FUNCTION(coalesce, 0, 0, 0, 0 ),
117456 INLINE_FUNC(coalesce, -1, INLINEFUNC_coalesce, SQLITE_FUNC_COALESCE),
117457 };
117458 #ifndef SQLITE_OMIT_ALTERTABLE
117459 sqlite3AlterFunctions();
117460 #endif
117461 sqlite3WindowFunctions();
@@ -119340,10 +119952,11 @@
119952 ** C: yield X, at EOF goto D
119953 ** insert the select result into <table> from R..R+n
119954 ** goto C
119955 ** D: ...
119956 */
119957 sqlite3VdbeReleaseRegisters(pParse, regData, pTab->nCol, 0, 0);
119958 addrInsTop = addrCont = sqlite3VdbeAddOp1(v, OP_Yield, dest.iSDParm);
119959 VdbeCoverage(v);
119960 if( ipkColumn>=0 ){
119961 /* tag-20191021-001: If the INTEGER PRIMARY KEY is being generated by the
119962 ** SELECT, go ahead and copy the value into the rowid slot now, so that
@@ -119600,10 +120213,19 @@
120213 sqlite3VdbeAddOp2(v, OP_Next, srcTab, addrCont); VdbeCoverage(v);
120214 sqlite3VdbeJumpHere(v, addrInsTop);
120215 sqlite3VdbeAddOp1(v, OP_Close, srcTab);
120216 }else if( pSelect ){
120217 sqlite3VdbeGoto(v, addrCont);
120218 #ifdef SQLITE_DEBUG
120219 /* If we are jumping back to an OP_Yield that is preceded by an
120220 ** OP_ReleaseReg, set the p5 flag on the OP_Goto so that the
120221 ** OP_ReleaseReg will be included in the loop. */
120222 if( sqlite3VdbeGetOp(v, addrCont-1)->opcode==OP_ReleaseReg ){
120223 assert( sqlite3VdbeGetOp(v, addrCont)->opcode==OP_Yield );
120224 sqlite3VdbeChangeP5(v, 1);
120225 }
120226 #endif
120227 sqlite3VdbeJumpHere(v, addrInsTop);
120228 }
120229
120230 insert_end:
120231 /* Update the sqlite_sequence table by storing the content of the
@@ -119822,11 +120444,10 @@
120444 sqlite3 *db; /* Database connection */
120445 int i; /* loop counter */
120446 int ix; /* Index loop counter */
120447 int nCol; /* Number of columns */
120448 int onError; /* Conflict resolution strategy */
 
120449 int seenReplace = 0; /* True if REPLACE is used to resolve INT PK conflict */
120450 int nPkField; /* Number of fields in PRIMARY KEY. 1 for ROWID tables */
120451 Index *pUpIdx = 0; /* Index to which to apply the upsert */
120452 u8 isUpdate; /* True if this is an UPDATE operation */
120453 u8 bAffinityDone = 0; /* True if the OP_Affinity operation has been run */
@@ -119866,75 +120487,104 @@
120487 iDataCur, iIdxCur, regNewData, regOldData, pkChng));
120488
120489 /* Test all NOT NULL constraints.
120490 */
120491 if( pTab->tabFlags & TF_HasNotNull ){
120492 int b2ndPass = 0; /* True if currently running 2nd pass */
120493 int nSeenReplace = 0; /* Number of ON CONFLICT REPLACE operations */
120494 int nGenerated = 0; /* Number of generated columns with NOT NULL */
120495 while(1){ /* Make 2 passes over columns. Exit loop via "break" */
120496 for(i=0; i<nCol; i++){
120497 int iReg; /* Register holding column value */
120498 Column *pCol = &pTab->aCol[i]; /* The column to check for NOT NULL */
120499 int isGenerated; /* non-zero if column is generated */
120500 onError = pCol->notNull;
120501 if( onError==OE_None ) continue; /* No NOT NULL on this column */
120502 if( i==pTab->iPKey ){
120503 continue; /* ROWID is never NULL */
120504 }
120505 isGenerated = pCol->colFlags & COLFLAG_GENERATED;
120506 if( isGenerated && !b2ndPass ){
120507 nGenerated++;
120508 continue; /* Generated columns processed on 2nd pass */
120509 }
120510 if( aiChng && aiChng[i]<0 && !isGenerated ){
120511 /* Do not check NOT NULL on columns that do not change */
120512 continue;
120513 }
120514 if( overrideError!=OE_Default ){
120515 onError = overrideError;
120516 }else if( onError==OE_Default ){
120517 onError = OE_Abort;
120518 }
120519 if( onError==OE_Replace ){
120520 if( b2ndPass /* REPLACE becomes ABORT on the 2nd pass */
120521 || pCol->pDflt==0 /* REPLACE is ABORT if no DEFAULT value */
120522 ){
120523 testcase( pCol->colFlags & COLFLAG_VIRTUAL );
120524 testcase( pCol->colFlags & COLFLAG_STORED );
120525 testcase( pCol->colFlags & COLFLAG_GENERATED );
120526 onError = OE_Abort;
120527 }else{
120528 assert( !isGenerated );
120529 }
120530 }else if( b2ndPass && !isGenerated ){
120531 continue;
120532 }
120533 assert( onError==OE_Rollback || onError==OE_Abort || onError==OE_Fail
120534 || onError==OE_Ignore || onError==OE_Replace );
120535 testcase( i!=sqlite3TableColumnToStorage(pTab, i) );
120536 iReg = sqlite3TableColumnToStorage(pTab, i) + regNewData + 1;
120537 switch( onError ){
120538 case OE_Replace: {
120539 int addr1 = sqlite3VdbeAddOp1(v, OP_NotNull, iReg);
120540 VdbeCoverage(v);
120541 assert( (pCol->colFlags & COLFLAG_GENERATED)==0 );
120542 nSeenReplace++;
120543 sqlite3ExprCode(pParse, pCol->pDflt, iReg);
120544 sqlite3VdbeJumpHere(v, addr1);
120545 break;
120546 }
120547 case OE_Abort:
120548 sqlite3MayAbort(pParse);
120549 /* Fall through */
120550 case OE_Rollback:
120551 case OE_Fail: {
120552 char *zMsg = sqlite3MPrintf(db, "%s.%s", pTab->zName,
120553 pCol->zName);
120554 sqlite3VdbeAddOp3(v, OP_HaltIfNull, SQLITE_CONSTRAINT_NOTNULL,
120555 onError, iReg);
120556 sqlite3VdbeAppendP4(v, zMsg, P4_DYNAMIC);
120557 sqlite3VdbeChangeP5(v, P5_ConstraintNotNull);
120558 VdbeCoverage(v);
120559 break;
120560 }
120561 default: {
120562 assert( onError==OE_Ignore );
120563 sqlite3VdbeAddOp2(v, OP_IsNull, iReg, ignoreDest);
120564 VdbeCoverage(v);
120565 break;
120566 }
120567 } /* end switch(onError) */
120568 } /* end loop i over columns */
120569 if( nGenerated==0 && nSeenReplace==0 ){
120570 /* If there are no generated columns with NOT NULL constraints
120571 ** and no NOT NULL ON CONFLICT REPLACE constraints, then a single
120572 ** pass is sufficient */
120573 break;
120574 }
120575 if( b2ndPass ) break; /* Never need more than 2 passes */
120576 b2ndPass = 1;
120577 if( nSeenReplace>0 && (pTab->tabFlags & TF_HasGenerated)!=0 ){
120578 /* If any NOT NULL ON CONFLICT REPLACE constraints fired on the
120579 ** first pass, recomputed values for all generated columns, as
120580 ** those values might depend on columns affected by the REPLACE.
120581 */
120582 sqlite3ComputeGeneratedColumns(pParse, regNewData+1, pTab);
120583 }
120584 } /* end of 2-pass loop */
120585 } /* end if( has-not-null-constraints ) */
120586
120587 /* Test all CHECK constraints
120588 */
120589 #ifndef SQLITE_OMIT_CHECK
120590 if( pTab->pCheck && (db->flags & SQLITE_IgnoreChecks)==0 ){
@@ -119955,11 +120605,11 @@
120605 sqlite3VdbeVerifyAbortable(v, onError);
120606 sqlite3ExprIfTrue(pParse, pExpr, allOk, SQLITE_JUMPIFNULL);
120607 if( onError==OE_Ignore ){
120608 sqlite3VdbeGoto(v, ignoreDest);
120609 }else{
120610 char *zName = pCheck->a[i].zEName;
120611 if( zName==0 ) zName = pTab->zName;
120612 if( onError==OE_Replace ) onError = OE_Abort; /* IMP: R-26383-51744 */
120613 sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_CHECK,
120614 onError, zName, P4_TRANSIENT,
120615 P5_ConstraintCheck);
@@ -120258,10 +120908,11 @@
120908 #ifdef SQLITE_ENABLE_NULL_TRIM
120909 if( pIdx->idxType==SQLITE_IDXTYPE_PRIMARYKEY ){
120910 sqlite3SetMakeRecordP5(v, pIdx->pTable);
120911 }
120912 #endif
120913 sqlite3VdbeReleaseRegisters(pParse, regIdx, pIdx->nColumn, 0, 0);
120914
120915 /* In an UPDATE operation, if this index is the PRIMARY KEY index
120916 ** of a WITHOUT ROWID table and there has been no change the
120917 ** primary key, then no collision is possible. The collision detection
120918 ** logic below can all be skipped. */
@@ -120411,13 +121062,19 @@
121062 testcase( nConflictCk>1 );
121063 if( regTrigCnt ){
121064 sqlite3MultiWrite(pParse);
121065 nReplaceTrig++;
121066 }
121067 if( pTrigger && isUpdate ){
121068 sqlite3VdbeAddOp1(v, OP_CursorLock, iDataCur);
121069 }
121070 sqlite3GenerateRowDelete(pParse, pTab, pTrigger, iDataCur, iIdxCur,
121071 regR, nPkField, 0, OE_Replace,
121072 (pIdx==pPk ? ONEPASS_SINGLE : ONEPASS_OFF), iThisCur);
121073 if( pTrigger && isUpdate ){
121074 sqlite3VdbeAddOp1(v, OP_CursorUnlock, iDataCur);
121075 }
121076 if( regTrigCnt ){
121077 int addrBypass; /* Jump destination to bypass recheck logic */
121078
121079 sqlite3VdbeAddOp2(v, OP_AddImm, regTrigCnt, 1); /* incr trigger cnt */
121080 addrBypass = sqlite3VdbeAddOp0(v, OP_Goto); /* Bypass recheck */
@@ -122889,39 +123546,43 @@
123546 /* 16 */ "cid",
123547 /* 17 */ "name",
123548 /* 18 */ "desc",
123549 /* 19 */ "coll",
123550 /* 20 */ "key",
123551 /* 21 */ "name", /* Used by: function_list */
123552 /* 22 */ "builtin",
123553 /* 23 */ "type",
123554 /* 24 */ "enc",
123555 /* 25 */ "narg",
123556 /* 26 */ "flags",
123557 /* 27 */ "tbl", /* Used by: stats */
123558 /* 28 */ "idx",
123559 /* 29 */ "wdth",
123560 /* 30 */ "hght",
123561 /* 31 */ "flgs",
123562 /* 32 */ "seq", /* Used by: index_list */
123563 /* 33 */ "name",
123564 /* 34 */ "unique",
123565 /* 35 */ "origin",
123566 /* 36 */ "partial",
123567 /* 37 */ "table", /* Used by: foreign_key_check */
123568 /* 38 */ "rowid",
123569 /* 39 */ "parent",
123570 /* 40 */ "fkid",
123571 /* index_info reuses 15 */
123572 /* 41 */ "seq", /* Used by: database_list */
123573 /* 42 */ "name",
123574 /* 43 */ "file",
123575 /* 44 */ "busy", /* Used by: wal_checkpoint */
123576 /* 45 */ "log",
123577 /* 46 */ "checkpointed",
123578 /* collation_list reuses 32 */
123579 /* 47 */ "database", /* Used by: lock_status */
123580 /* 48 */ "status",
123581 /* 49 */ "cache_size", /* Used by: default_cache_size */
 
 
123582 /* module_list pragma_list reuses 9 */
123583 /* 50 */ "timeout", /* Used by: busy_timeout */
123584 };
123585
123586 /* Definitions of all built-in pragmas */
123587 typedef struct PragmaName {
123588 const char *const zName; /* Name of pragma */
@@ -122963,11 +123624,11 @@
123624 #endif
123625 #endif
123626 {/* zName: */ "busy_timeout",
123627 /* ePragTyp: */ PragTyp_BUSY_TIMEOUT,
123628 /* ePragFlg: */ PragFlg_Result0,
123629 /* ColNames: */ 50, 1,
123630 /* iArg: */ 0 },
123631 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
123632 {/* zName: */ "cache_size",
123633 /* ePragTyp: */ PragTyp_CACHE_SIZE,
123634 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq|PragFlg_NoColumns1,
@@ -123002,11 +123663,11 @@
123663 #endif
123664 #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
123665 {/* zName: */ "collation_list",
123666 /* ePragTyp: */ PragTyp_COLLATION_LIST,
123667 /* ePragFlg: */ PragFlg_Result0,
123668 /* ColNames: */ 32, 2,
123669 /* iArg: */ 0 },
123670 #endif
123671 #if !defined(SQLITE_OMIT_COMPILEOPTION_DIAGS)
123672 {/* zName: */ "compile_options",
123673 /* ePragTyp: */ PragTyp_COMPILE_OPTIONS,
@@ -123037,18 +123698,18 @@
123698 #endif
123699 #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
123700 {/* zName: */ "database_list",
123701 /* ePragTyp: */ PragTyp_DATABASE_LIST,
123702 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0,
123703 /* ColNames: */ 41, 3,
123704 /* iArg: */ 0 },
123705 #endif
123706 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED)
123707 {/* zName: */ "default_cache_size",
123708 /* ePragTyp: */ PragTyp_DEFAULT_CACHE_SIZE,
123709 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq|PragFlg_NoColumns1,
123710 /* ColNames: */ 49, 1,
123711 /* iArg: */ 0 },
123712 #endif
123713 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
123714 #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
123715 {/* zName: */ "defer_foreign_keys",
@@ -123074,11 +123735,11 @@
123735 #endif
123736 #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
123737 {/* zName: */ "foreign_key_check",
123738 /* ePragTyp: */ PragTyp_FOREIGN_KEY_CHECK,
123739 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0,
123740 /* ColNames: */ 37, 4,
123741 /* iArg: */ 0 },
123742 #endif
123743 #if !defined(SQLITE_OMIT_FOREIGN_KEY)
123744 {/* zName: */ "foreign_key_list",
123745 /* ePragTyp: */ PragTyp_FOREIGN_KEY_LIST,
@@ -123117,11 +123778,11 @@
123778 #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
123779 #if !defined(SQLITE_OMIT_INTROSPECTION_PRAGMAS)
123780 {/* zName: */ "function_list",
123781 /* ePragTyp: */ PragTyp_FUNCTION_LIST,
123782 /* ePragFlg: */ PragFlg_Result0,
123783 /* ColNames: */ 21, 6,
123784 /* iArg: */ 0 },
123785 #endif
123786 #endif
123787 {/* zName: */ "hard_heap_limit",
123788 /* ePragTyp: */ PragTyp_HARD_HEAP_LIMIT,
@@ -123163,11 +123824,11 @@
123824 /* ColNames: */ 15, 3,
123825 /* iArg: */ 0 },
123826 {/* zName: */ "index_list",
123827 /* ePragTyp: */ PragTyp_INDEX_LIST,
123828 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result1|PragFlg_SchemaOpt,
123829 /* ColNames: */ 32, 5,
123830 /* iArg: */ 0 },
123831 {/* zName: */ "index_xinfo",
123832 /* ePragTyp: */ PragTyp_INDEX_INFO,
123833 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result1|PragFlg_SchemaOpt,
123834 /* ColNames: */ 15, 6,
@@ -123215,11 +123876,11 @@
123876 #endif
123877 #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
123878 {/* zName: */ "lock_status",
123879 /* ePragTyp: */ PragTyp_LOCK_STATUS,
123880 /* ePragFlg: */ PragFlg_Result0,
123881 /* ColNames: */ 47, 2,
123882 /* iArg: */ 0 },
123883 #endif
123884 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
123885 {/* zName: */ "locking_mode",
123886 /* ePragTyp: */ PragTyp_LOCKING_MODE,
@@ -123363,11 +124024,11 @@
124024 #endif
124025 #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) && defined(SQLITE_DEBUG)
124026 {/* zName: */ "stats",
124027 /* ePragTyp: */ PragTyp_STATS,
124028 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq,
124029 /* ColNames: */ 27, 5,
124030 /* iArg: */ 0 },
124031 #endif
124032 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
124033 {/* zName: */ "synchronous",
124034 /* ePragTyp: */ PragTyp_SYNCHRONOUS,
@@ -123414,10 +124075,17 @@
124075 {/* zName: */ "threads",
124076 /* ePragTyp: */ PragTyp_THREADS,
124077 /* ePragFlg: */ PragFlg_Result0,
124078 /* ColNames: */ 0, 0,
124079 /* iArg: */ 0 },
124080 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
124081 {/* zName: */ "trusted_schema",
124082 /* ePragTyp: */ PragTyp_FLAG,
124083 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
124084 /* ColNames: */ 0, 0,
124085 /* iArg: */ SQLITE_TrustedSchema },
124086 #endif
124087 #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
124088 {/* zName: */ "user_version",
124089 /* ePragTyp: */ PragTyp_HEADER_VALUE,
124090 /* ePragFlg: */ PragFlg_NoColumns1|PragFlg_Result0,
124091 /* ColNames: */ 0, 0,
@@ -123459,11 +124127,11 @@
124127 /* ColNames: */ 0, 0,
124128 /* iArg: */ 0 },
124129 {/* zName: */ "wal_checkpoint",
124130 /* ePragTyp: */ PragTyp_WAL_CHECKPOINT,
124131 /* ePragFlg: */ PragFlg_NeedSchema,
124132 /* ColNames: */ 44, 3,
124133 /* iArg: */ 0 },
124134 #endif
124135 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
124136 {/* zName: */ "writable_schema",
124137 /* ePragTyp: */ PragTyp_FLAG,
@@ -123470,11 +124138,11 @@
124138 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
124139 /* ColNames: */ 0, 0,
124140 /* iArg: */ SQLITE_WriteSchema|SQLITE_NoSchemaError },
124141 #endif
124142 };
124143 /* Number of pragmas: 66 on by default, 82 total. */
124144
124145 /************** End of pragma.h **********************************************/
124146 /************** Continuing where we left off in pragma.c *********************/
124147
124148 /*
@@ -123739,10 +124407,59 @@
124407 lwr = mid + 1;
124408 }
124409 }
124410 return lwr>upr ? 0 : &aPragmaName[mid];
124411 }
124412
124413 /*
124414 ** Create zero or more entries in the output for the SQL functions
124415 ** defined by FuncDef p.
124416 */
124417 static void pragmaFunclistLine(
124418 Vdbe *v, /* The prepared statement being created */
124419 FuncDef *p, /* A particular function definition */
124420 int isBuiltin, /* True if this is a built-in function */
124421 int showInternFuncs /* True if showing internal functions */
124422 ){
124423 for(; p; p=p->pNext){
124424 const char *zType;
124425 static const u32 mask =
124426 SQLITE_DETERMINISTIC |
124427 SQLITE_DIRECTONLY |
124428 SQLITE_SUBTYPE |
124429 SQLITE_INNOCUOUS |
124430 SQLITE_FUNC_INTERNAL
124431 ;
124432 static const char *azEnc[] = { 0, "utf8", "utf16le", "utf16be" };
124433
124434 assert( SQLITE_FUNC_ENCMASK==0x3 );
124435 assert( strcmp(azEnc[SQLITE_UTF8],"utf8")==0 );
124436 assert( strcmp(azEnc[SQLITE_UTF16LE],"utf16le")==0 );
124437 assert( strcmp(azEnc[SQLITE_UTF16BE],"utf16be")==0 );
124438
124439 if( p->xSFunc==0 ) continue;
124440 if( (p->funcFlags & SQLITE_FUNC_INTERNAL)!=0
124441 && showInternFuncs==0
124442 ){
124443 continue;
124444 }
124445 if( p->xValue!=0 ){
124446 zType = "w";
124447 }else if( p->xFinalize!=0 ){
124448 zType = "a";
124449 }else{
124450 zType = "s";
124451 }
124452 sqlite3VdbeMultiLoad(v, 1, "sissii",
124453 p->zName, isBuiltin,
124454 zType, azEnc[p->funcFlags&SQLITE_FUNC_ENCMASK],
124455 p->nArg,
124456 (p->funcFlags & mask) ^ SQLITE_INNOCUOUS
124457 );
124458 }
124459 }
124460
124461
124462 /*
124463 ** Helper subroutine for PRAGMA integrity_check:
124464 **
124465 ** Generate code to output a single-column result row with a value of the
@@ -124704,20 +125421,20 @@
125421 #ifndef SQLITE_OMIT_INTROSPECTION_PRAGMAS
125422 case PragTyp_FUNCTION_LIST: {
125423 int i;
125424 HashElem *j;
125425 FuncDef *p;
125426 int showInternFunc = (db->mDbFlags & DBFLAG_InternalFunc)!=0;
125427 pParse->nMem = 6;
125428 for(i=0; i<SQLITE_FUNC_HASH_SZ; i++){
125429 for(p=sqlite3BuiltinFunctions.a[i]; p; p=p->u.pHash ){
125430 pragmaFunclistLine(v, p, 1, showInternFunc);
 
125431 }
125432 }
125433 for(j=sqliteHashFirst(&db->aFunc); j; j=sqliteHashNext(j)){
125434 p = (FuncDef*)sqliteHashData(j);
125435 pragmaFunclistLine(v, p, 0, showInternFunc);
125436 }
125437 }
125438 break;
125439
125440 #ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -127127,10 +127844,11 @@
127844 if( ALWAYS(p) ){
127845 clearSelect(pParse->db, p, 0);
127846 memset(&p->iLimit, 0, sizeof(Select) - offsetof(Select,iLimit));
127847 p->pEList = sqlite3ExprListAppend(pParse, 0,
127848 sqlite3ExprAlloc(pParse->db,TK_NULL,0,0));
127849 p->pSrc = sqlite3DbMallocZero(pParse->db, sizeof(SrcList));
127850 }
127851 }
127852
127853 /*
127854 ** Return a pointer to the right-most SELECT statement in a compound.
@@ -127238,19 +127956,22 @@
127956 static int tableAndColumnIndex(
127957 SrcList *pSrc, /* Array of tables to search */
127958 int N, /* Number of tables in pSrc->a[] to search */
127959 const char *zCol, /* Name of the column we are looking for */
127960 int *piTab, /* Write index of pSrc->a[] here */
127961 int *piCol, /* Write index of pSrc->a[*piTab].pTab->aCol[] here */
127962 int bIgnoreHidden /* True to ignore hidden columns */
127963 ){
127964 int i; /* For looping over tables in pSrc */
127965 int iCol; /* Index of column matching zCol */
127966
127967 assert( (piTab==0)==(piCol==0) ); /* Both or neither are NULL */
127968 for(i=0; i<N; i++){
127969 iCol = columnIndex(pSrc->a[i].pTab, zCol);
127970 if( iCol>=0
127971 && (bIgnoreHidden==0 || IsHiddenColumn(&pSrc->a[i].pTab->aCol[iCol])==0)
127972 ){
127973 if( piTab ){
127974 *piTab = i;
127975 *piCol = iCol;
127976 }
127977 return 1;
@@ -127411,14 +128132,15 @@
128132 for(j=0; j<pRightTab->nCol; j++){
128133 char *zName; /* Name of column in the right table */
128134 int iLeft; /* Matching left table */
128135 int iLeftCol; /* Matching column in the left table */
128136
128137 if( IsHiddenColumn(&pRightTab->aCol[j]) ) continue;
128138 zName = pRightTab->aCol[j].zName;
128139 if( tableAndColumnIndex(pSrc, i+1, zName, &iLeft, &iLeftCol, 1) ){
128140 addWhereTerm(pParse, pSrc, iLeft, iLeftCol, i+1, j,
128141 isOuter, &p->pWhere);
128142 }
128143 }
128144 }
128145
128146 /* Disallow both ON and USING clauses in the same join
@@ -127454,11 +128176,11 @@
128176 int iRightCol; /* Column number of matching column on the right */
128177
128178 zName = pList->a[j].zName;
128179 iRightCol = columnIndex(pRightTab, zName);
128180 if( iRightCol<0
128181 || !tableAndColumnIndex(pSrc, i+1, zName, &iLeft, &iLeftCol, 0)
128182 ){
128183 sqlite3ErrorMsg(pParse, "cannot join using column %s - column "
128184 "not present in both tables", zName);
128185 return 1;
128186 }
@@ -127860,11 +128582,11 @@
128582 pDest->nSdst = nResultCol;
128583 regOrig = regResult = pDest->iSdst;
128584 if( srcTab>=0 ){
128585 for(i=0; i<nResultCol; i++){
128586 sqlite3VdbeAddOp3(v, OP_Column, srcTab, i, regResult+i);
128587 VdbeComment((v, "%s", p->pEList->a[i].zEName));
128588 }
128589 }else if( eDest!=SRT_Exists ){
128590 #ifdef SQLITE_ENABLE_SORTER_REFERENCES
128591 ExprList *pExtra = 0;
128592 #endif
@@ -128481,11 +129203,11 @@
129203 iRead = aOutEx[i].u.x.iOrderByCol-1;
129204 }else{
129205 iRead = iCol--;
129206 }
129207 sqlite3VdbeAddOp3(v, OP_Column, iSortTab, iRead, regRow+i);
129208 VdbeComment((v, "%s", aOutEx[i].zEName));
129209 }
129210 }
129211 switch( eDest ){
129212 case SRT_Table:
129213 case SRT_EphemTab: {
@@ -128815,13 +129537,13 @@
129537 Expr *p = pEList->a[i].pExpr;
129538
129539 assert( p!=0 );
129540 assert( p->op!=TK_AGG_COLUMN ); /* Agg processing has not run yet */
129541 assert( p->op!=TK_COLUMN || p->y.pTab!=0 ); /* Covering idx not yet coded */
129542 if( pEList->a[i].zEName && pEList->a[i].eEName==ENAME_NAME ){
129543 /* An AS clause always takes first priority */
129544 char *zName = pEList->a[i].zEName;
129545 sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, SQLITE_TRANSIENT);
129546 }else if( srcName && p->op==TK_COLUMN ){
129547 char *zCol;
129548 int iCol = p->iColumn;
129549 pTab = p->y.pTab;
@@ -128839,11 +129561,11 @@
129561 sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, SQLITE_DYNAMIC);
129562 }else{
129563 sqlite3VdbeSetColName(v, i, COLNAME_NAME, zCol, SQLITE_TRANSIENT);
129564 }
129565 }else{
129566 const char *z = pEList->a[i].zEName;
129567 z = z==0 ? sqlite3MPrintf(db, "column%d", i+1) : sqlite3DbStrDup(db, z);
129568 sqlite3VdbeSetColName(v, i, COLNAME_NAME, z, SQLITE_DYNAMIC);
129569 }
129570 }
129571 generateColumnTypes(pParse, pTabList, pEList);
@@ -128901,11 +129623,11 @@
129623 *paCol = aCol;
129624
129625 for(i=0, pCol=aCol; i<nCol && !db->mallocFailed; i++, pCol++){
129626 /* Get an appropriate name for the column
129627 */
129628 if( (zName = pEList->a[i].zEName)!=0 && pEList->a[i].eEName==ENAME_NAME ){
129629 /* If the column contains an "AS <name>" phrase, use <name> as the name */
129630 }else{
129631 Expr *pColExpr = sqlite3ExprSkipCollateAndLikely(pEList->a[i].pExpr);
129632 while( pColExpr->op==TK_DOT ){
129633 pColExpr = pColExpr->pRight;
@@ -128921,14 +129643,14 @@
129643 }else if( pColExpr->op==TK_ID ){
129644 assert( !ExprHasProperty(pColExpr, EP_IntValue) );
129645 zName = pColExpr->u.zToken;
129646 }else{
129647 /* Use the original text of the column expression as its name */
129648 zName = pEList->a[i].zEName;
129649 }
129650 }
129651 if( zName && !sqlite3IsTrueOrFalse(zName) ){
129652 zName = sqlite3DbStrDup(db, zName);
129653 }else{
129654 zName = sqlite3MPrintf(db,"column%d",i+1);
129655 }
129656
@@ -130594,10 +131316,11 @@
131316 ** (17c) every term within the subquery compound must have a FROM clause
131317 ** (17d) the outer query may not be
131318 ** (17d1) aggregate, or
131319 ** (17d2) DISTINCT, or
131320 ** (17d3) a join.
131321 ** (17e) the subquery may not contain window functions
131322 **
131323 ** The parent and sub-query may contain WHERE clauses. Subject to
131324 ** rules (11), (13) and (14), they may also contain ORDER BY,
131325 ** LIMIT and OFFSET clauses. The subquery cannot use any compound
131326 ** operator other than UNION ALL because all the other compound
@@ -130778,10 +131501,11 @@
131501 assert( pSub->pSrc!=0 );
131502 assert( pSub->pEList->nExpr==pSub1->pEList->nExpr );
131503 if( (pSub1->selFlags & (SF_Distinct|SF_Aggregate))!=0 /* (17b) */
131504 || (pSub1->pPrior && pSub1->op!=TK_ALL) /* (17a) */
131505 || pSub1->pSrc->nSrc<1 /* (17c) */
131506 || pSub1->pWin /* (17e) */
131507 ){
131508 return 0;
131509 }
131510 testcase( pSub1->pSrc->nSrc>1 );
131511 }
@@ -131064,27 +131788,40 @@
131788 Expr **apExpr; /* [i*2] is COLUMN and [i*2+1] is VALUE */
131789 };
131790
131791 /*
131792 ** Add a new entry to the pConst object. Except, do not add duplicate
131793 ** pColumn entires. Also, do not add if doing so would not be appropriate.
131794 **
131795 ** The caller guarantees the pColumn is a column and pValue is a constant.
131796 ** This routine has to do some additional checks before completing the
131797 ** insert.
131798 */
131799 static void constInsert(
131800 WhereConst *pConst, /* The WhereConst into which we are inserting */
131801 Expr *pColumn, /* The COLUMN part of the constraint */
131802 Expr *pValue, /* The VALUE part of the constraint */
131803 Expr *pExpr /* Overall expression: COLUMN=VALUE or VALUE=COLUMN */
131804 ){
131805 int i;
131806 assert( pColumn->op==TK_COLUMN );
131807 assert( sqlite3ExprIsConstant(pValue) );
131808
131809 if( !ExprHasProperty(pValue, EP_FixedCol) && sqlite3ExprAffinity(pValue)!=0 ){
131810 return;
131811 }
131812 if( !sqlite3IsBinary(sqlite3ExprCompareCollSeq(pConst->pParse,pExpr)) ){
131813 return;
131814 }
131815
131816 /* 2018-10-25 ticket [cf5ed20f]
131817 ** Make sure the same pColumn is not inserted more than once */
131818 for(i=0; i<pConst->nConst; i++){
131819 const Expr *pE2 = pConst->apExpr[i*2];
131820 assert( pE2->op==TK_COLUMN );
131821 if( pE2->iTable==pColumn->iTable
131822 && pE2->iColumn==pColumn->iColumn
131823 ){
131824 return; /* Already present. Return without doing anything. */
131825 }
131826 }
131827
@@ -131092,11 +131829,13 @@
131829 pConst->apExpr = sqlite3DbReallocOrFree(pConst->pParse->db, pConst->apExpr,
131830 pConst->nConst*2*sizeof(Expr*));
131831 if( pConst->apExpr==0 ){
131832 pConst->nConst = 0;
131833 }else{
131834 if( ExprHasProperty(pValue, EP_FixedCol) ){
131835 pValue = pValue->pLeft;
131836 }
131837 pConst->apExpr[pConst->nConst*2-2] = pColumn;
131838 pConst->apExpr[pConst->nConst*2-1] = pValue;
131839 }
131840 }
131841
@@ -131118,23 +131857,15 @@
131857 if( pExpr->op!=TK_EQ ) return;
131858 pRight = pExpr->pRight;
131859 pLeft = pExpr->pLeft;
131860 assert( pRight!=0 );
131861 assert( pLeft!=0 );
131862 if( pRight->op==TK_COLUMN && sqlite3ExprIsConstant(pLeft) ){
131863 constInsert(pConst,pRight,pLeft,pExpr);
131864 }
131865 if( pLeft->op==TK_COLUMN && sqlite3ExprIsConstant(pRight) ){
131866 constInsert(pConst,pLeft,pRight,pExpr);
 
 
 
 
 
 
 
 
131867 }
131868 }
131869
131870 /*
131871 ** This is a Walker expression callback. pExpr is a candidate expression
@@ -131166,14 +131897,13 @@
131897
131898 /*
131899 ** The WHERE-clause constant propagation optimization.
131900 **
131901 ** If the WHERE clause contains terms of the form COLUMN=CONSTANT or
131902 ** CONSTANT=COLUMN that are top-level AND-connected terms that are not
131903 ** part of a ON clause from a LEFT JOIN, then throughout the query
131904 ** replace all other occurrences of COLUMN with CONSTANT.
 
131905 **
131906 ** For example, the query:
131907 **
131908 ** SELECT * FROM t1, t2, t3 WHERE t1.a=39 AND t2.b=t1.a AND t3.c=t2.b
131909 **
@@ -131882,11 +132612,19 @@
132612 u8 eCodeOrig = pWalker->eCode;
132613 if( sqlite3ViewGetColumnNames(pParse, pTab) ) return WRC_Abort;
132614 assert( pFrom->pSelect==0 );
132615 if( pTab->pSelect && (db->flags & SQLITE_EnableView)==0 ){
132616 sqlite3ErrorMsg(pParse, "access to view \"%s\" prohibited",
132617 pTab->zName);
132618 }
132619 if( IsVirtual(pTab)
132620 && pFrom->fg.fromDDL
132621 && ALWAYS(pTab->pVTable!=0)
132622 && pTab->pVTable->eVtabRisk > ((db->flags & SQLITE_TrustedSchema)!=0)
132623 ){
132624 sqlite3ErrorMsg(pParse, "unsafe use of virtual table \"%s\"",
132625 pTab->zName);
132626 }
132627 pFrom->pSelect = sqlite3SelectDup(db, pTab->pSelect, 0);
132628 nCol = pTab->nCol;
132629 pTab->nCol = -1;
132630 pWalker->eCode = 1; /* Turn on Select.selId renumbering */
@@ -131903,11 +132641,11 @@
132641 }
132642 }
132643
132644 /* Process NATURAL keywords, and ON and USING clauses of joins.
132645 */
132646 if( pParse->nErr || db->mallocFailed || sqliteProcessJoin(pParse, p) ){
132647 return WRC_Abort;
132648 }
132649
132650 /* For every "*" that occurs in the column list, insert the names of
132651 ** all columns in all tables. And for every TABLE.* insert the names
@@ -131950,14 +132688,13 @@
132688 ){
132689 /* This particular expression does not need to be expanded.
132690 */
132691 pNew = sqlite3ExprListAppend(pParse, pNew, a[k].pExpr);
132692 if( pNew ){
132693 pNew->a[pNew->nExpr-1].zEName = a[k].zEName;
132694 pNew->a[pNew->nExpr-1].eEName = a[k].eEName;
132695 a[k].zEName = 0;
 
132696 }
132697 a[k].pExpr = 0;
132698 }else{
132699 /* This expression is a "*" or a "TABLE.*" and needs to be
132700 ** expanded. */
@@ -131992,11 +132729,11 @@
132729 char *zToFree; /* Malloced string that needs to be freed */
132730 Token sColname; /* Computed column name as a token */
132731
132732 assert( zName );
132733 if( zTName && pSub
132734 && sqlite3MatchEName(&pSub->pEList->a[j], 0, zTName, 0)==0
132735 ){
132736 continue;
132737 }
132738
132739 /* If a column is marked as 'hidden', omit it from the expanded
@@ -132010,11 +132747,11 @@
132747 }
132748 tableSeen = 1;
132749
132750 if( i>0 && zTName==0 ){
132751 if( (pFrom->fg.jointype & JT_NATURAL)!=0
132752 && tableAndColumnIndex(pTabList, i, zName, 0, 0, 1)
132753 ){
132754 /* In a NATURAL join, omit the join columns from the
132755 ** table to the right of the join */
132756 continue;
132757 }
@@ -132045,19 +132782,20 @@
132782 pNew = sqlite3ExprListAppend(pParse, pNew, pExpr);
132783 sqlite3TokenInit(&sColname, zColname);
132784 sqlite3ExprListSetName(pParse, pNew, &sColname, 0);
132785 if( pNew && (p->selFlags & SF_NestedFrom)!=0 ){
132786 struct ExprList_item *pX = &pNew->a[pNew->nExpr-1];
132787 sqlite3DbFree(db, pX->zEName);
132788 if( pSub ){
132789 pX->zEName = sqlite3DbStrDup(db, pSub->pEList->a[j].zEName);
132790 testcase( pX->zEName==0 );
132791 }else{
132792 pX->zEName = sqlite3MPrintf(db, "%s.%s.%s",
132793 zSchemaName, zTabName, zColname);
132794 testcase( pX->zEName==0 );
132795 }
132796 pX->eEName = ENAME_TAB;
132797 }
132798 sqlite3DbFree(db, zToFree);
132799 }
132800 }
132801 if( !tableSeen ){
@@ -133022,10 +133760,11 @@
133760 && sqlite3ExprListCompare(sSort.pOrderBy, pEList, -1)==0
133761 && p->pWin==0
133762 ){
133763 p->selFlags &= ~SF_Distinct;
133764 pGroupBy = p->pGroupBy = sqlite3ExprListDup(db, pEList, 0);
133765 p->selFlags |= SF_Aggregate;
133766 /* Notice that even thought SF_Distinct has been cleared from p->selFlags,
133767 ** the sDistinct.isTnct is still set. Hence, isTnct represents the
133768 ** original setting of the SF_Distinct flag, not the current setting */
133769 assert( sDistinct.isTnct );
133770
@@ -133096,11 +133835,11 @@
133835 u16 wctrlFlags = (sDistinct.isTnct ? WHERE_WANT_DISTINCT : 0)
133836 | (p->selFlags & SF_FixedLimit);
133837 #ifndef SQLITE_OMIT_WINDOWFUNC
133838 Window *pWin = p->pWin; /* Master window object (or NULL) */
133839 if( pWin ){
133840 sqlite3WindowCodeInit(pParse, p);
133841 }
133842 #endif
133843 assert( WHERE_USE_LIMIT==SF_FixedLimit );
133844
133845
@@ -134568,11 +135307,11 @@
135307 */
135308 static int checkColumnOverlap(IdList *pIdList, ExprList *pEList){
135309 int e;
135310 if( pIdList==0 || NEVER(pEList==0) ) return 1;
135311 for(e=0; e<pEList->nExpr; e++){
135312 if( sqlite3IdListIndex(pIdList, pEList->a[e].zEName)>=0 ) return 1;
135313 }
135314 return 0;
135315 }
135316
135317 /*
@@ -135272,10 +136011,11 @@
136011 int aiCurOnePass[2]; /* The write cursors opened by WHERE_ONEPASS */
136012 int addrOpen = 0; /* Address of OP_OpenEphemeral */
136013 int iPk = 0; /* First of nPk cells holding PRIMARY KEY value */
136014 i16 nPk = 0; /* Number of components of the PRIMARY KEY */
136015 int bReplace = 0; /* True if REPLACE conflict resolution might happen */
136016 int bFinishSeek = 1; /* The OP_FinishSeek opcode is needed */
136017
136018 /* Register Allocations */
136019 int regRowCount = 0; /* A count of rows changed */
136020 int regOldRowid = 0; /* The old rowid */
136021 int regNewRowid = 0; /* The new rowid */
@@ -135386,11 +136126,11 @@
136126 for(i=0; i<pChanges->nExpr; i++){
136127 if( sqlite3ResolveExprNames(&sNC, pChanges->a[i].pExpr) ){
136128 goto update_cleanup;
136129 }
136130 for(j=0; j<pTab->nCol; j++){
136131 if( sqlite3StrICmp(pTab->aCol[j].zName, pChanges->a[i].zEName)==0 ){
136132 if( j==pTab->iPKey ){
136133 chngRowid = 1;
136134 pRowidExpr = pChanges->a[i].pExpr;
136135 }else if( pPk && (pTab->aCol[j].colFlags & COLFLAG_PRIMKEY)!=0 ){
136136 chngPk = 1;
@@ -135408,16 +136148,16 @@
136148 aXRef[j] = i;
136149 break;
136150 }
136151 }
136152 if( j>=pTab->nCol ){
136153 if( pPk==0 && sqlite3IsRowid(pChanges->a[i].zEName) ){
136154 j = -1;
136155 chngRowid = 1;
136156 pRowidExpr = pChanges->a[i].pExpr;
136157 }else{
136158 sqlite3ErrorMsg(pParse, "no such column: %s", pChanges->a[i].zEName);
136159 pParse->checkSchema = 1;
136160 goto update_cleanup;
136161 }
136162 }
136163 #ifndef SQLITE_OMIT_AUTHORIZATION
@@ -135605,10 +136345,11 @@
136345 ** row(s) to be updated.
136346 */
136347 pWInfo = 0;
136348 eOnePass = ONEPASS_SINGLE;
136349 sqlite3ExprIfFalse(pParse, pWhere, labelBreak, SQLITE_JUMPIFNULL);
136350 bFinishSeek = 0;
136351 }else{
136352 /* Begin the database scan.
136353 **
136354 ** Do not consider a single-pass strategy for a multi-row update if
136355 ** there are any triggers or foreign keys to process, or rows may
@@ -135631,10 +136372,11 @@
136372 **
136373 ** Fall back to ONEPASS_OFF if where.c has selected a ONEPASS_MULTI
136374 ** strategy that uses an index for which one or more columns are being
136375 ** updated. */
136376 eOnePass = sqlite3WhereOkOnePass(pWInfo, aiCurOnePass);
136377 bFinishSeek = sqlite3WhereUsesDeferredSeek(pWInfo);
136378 if( eOnePass!=ONEPASS_SINGLE ){
136379 sqlite3MultiWrite(pParse);
136380 if( eOnePass==ONEPASS_MULTI ){
136381 int iCur = aiCurOnePass[1];
136382 if( iCur>=0 && iCur!=iDataCur && aToOpen[iCur-iBaseCur] ){
@@ -135794,10 +136536,11 @@
136536 ** a new.* reference in a trigger program.
136537 */
136538 testcase( i==31 );
136539 testcase( i==32 );
136540 sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, i, k);
136541 bFinishSeek = 0;
136542 }else{
136543 sqlite3VdbeAddOp2(v, OP_Null, 0, k);
136544 }
136545 }
136546 }
@@ -135880,10 +136623,19 @@
136623 sqlite3FkCheck(pParse, pTab, regOldRowid, 0, aXRef, chngKey);
136624 }
136625
136626 /* Delete the index entries associated with the current record. */
136627 sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur, aRegIdx, -1);
136628
136629 /* We must run the OP_FinishSeek opcode to resolve a prior
136630 ** OP_DeferredSeek if there is any possibility that there have been
136631 ** no OP_Column opcodes since the OP_DeferredSeek was issued. But
136632 ** we want to avoid the OP_FinishSeek if possible, as running it
136633 ** costs CPU cycles. */
136634 if( bFinishSeek ){
136635 sqlite3VdbeAddOp1(v, OP_FinishSeek, iDataCur);
136636 }
136637
136638 /* If changing the rowid value, or if there are foreign key constraints
136639 ** to process, delete the old record. Otherwise, add a noop OP_Delete
136640 ** to invoke the pre-update hook.
136641 **
@@ -136378,10 +137130,11 @@
137130 sqlite3VdbeVerifyAbortable(v, OE_Abort);
137131 i = sqlite3VdbeAddOp4Int(v, OP_Found, iDataCur, 0, iPk, nPk);
137132 VdbeCoverage(v);
137133 sqlite3VdbeAddOp4(v, OP_Halt, SQLITE_CORRUPT, OE_Abort, 0,
137134 "corrupt database", P4_STATIC);
137135 sqlite3MayAbort(pParse);
137136 sqlite3VdbeJumpHere(v, i);
137137 }
137138 }
137139 /* pUpsert does not own pUpsertSrc - the outer INSERT statement does. So
137140 ** we have to make a copy before passing it down into sqlite3Update() */
@@ -137408,10 +138161,11 @@
138161 sqlite3DbFree(db, zModuleName);
138162 return SQLITE_NOMEM_BKPT;
138163 }
138164 pVTable->db = db;
138165 pVTable->pMod = pMod;
138166 pVTable->eVtabRisk = SQLITE_VTABRISK_Normal;
138167
138168 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
138169 pTab->azModuleArg[1] = db->aDb[iDb].zDbSName;
138170
138171 /* Invoke the virtual table constructor */
@@ -138097,32 +138851,42 @@
138851 ** of the virtual table being implemented.
138852 */
138853 SQLITE_API int sqlite3_vtab_config(sqlite3 *db, int op, ...){
138854 va_list ap;
138855 int rc = SQLITE_OK;
138856 VtabCtx *p;
138857
138858 #ifdef SQLITE_ENABLE_API_ARMOR
138859 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
138860 #endif
138861 sqlite3_mutex_enter(db->mutex);
138862 p = db->pVtabCtx;
138863 if( !p ){
138864 rc = SQLITE_MISUSE_BKPT;
138865 }else{
138866 assert( p->pTab==0 || IsVirtual(p->pTab) );
138867 va_start(ap, op);
138868 switch( op ){
138869 case SQLITE_VTAB_CONSTRAINT_SUPPORT: {
138870 p->pVTable->bConstraint = (u8)va_arg(ap, int);
138871 break;
138872 }
138873 case SQLITE_VTAB_INNOCUOUS: {
138874 p->pVTable->eVtabRisk = SQLITE_VTABRISK_Low;
138875 break;
138876 }
138877 case SQLITE_VTAB_DIRECTONLY: {
138878 p->pVTable->eVtabRisk = SQLITE_VTABRISK_High;
138879 break;
138880 }
138881 default: {
138882 rc = SQLITE_MISUSE_BKPT;
138883 break;
138884 }
138885 }
138886 va_end(ap);
138887 }
138888
138889 if( rc!=SQLITE_OK ) sqlite3Error(db, rc);
138890 sqlite3_mutex_leave(db->mutex);
138891 return rc;
138892 }
@@ -138586,10 +139350,24 @@
139350 #endif
139351 #ifndef SQLITE_QUERY_PLANNER_LIMIT_INCR
139352 # define SQLITE_QUERY_PLANNER_LIMIT_INCR 1000
139353 #endif
139354
139355 /*
139356 ** Each instance of this object records a change to a single node
139357 ** in an expression tree to cause that node to point to a column
139358 ** of an index rather than an expression or a virtual column. All
139359 ** such transformations need to be undone at the end of WHERE clause
139360 ** processing.
139361 */
139362 typedef struct WhereExprMod WhereExprMod;
139363 struct WhereExprMod {
139364 WhereExprMod *pNext; /* Next translation on a list of them all */
139365 Expr *pExpr; /* The Expr node that was transformed */
139366 Expr orig; /* Original value of the Expr node */
139367 };
139368
139369 /*
139370 ** The WHERE clause processing routine has two halves. The
139371 ** first part does the start of the WHERE loop and the second
139372 ** half does the tail of the WHERE loop. An instance of
139373 ** this structure is returned by the first half and passed
@@ -138602,27 +139380,29 @@
139380 Parse *pParse; /* Parsing and code generating context */
139381 SrcList *pTabList; /* List of tables in the join */
139382 ExprList *pOrderBy; /* The ORDER BY clause or NULL */
139383 ExprList *pResultSet; /* Result set of the query */
139384 Expr *pWhere; /* The complete WHERE clause */
 
139385 int aiCurOnePass[2]; /* OP_OpenWrite cursors for the ONEPASS opt */
139386 int iContinue; /* Jump here to continue with next record */
139387 int iBreak; /* Jump here to break out of the loop */
139388 int savedNQueryLoop; /* pParse->nQueryLoop outside the WHERE loop */
139389 u16 wctrlFlags; /* Flags originally passed to sqlite3WhereBegin() */
139390 LogEst iLimit; /* LIMIT if wctrlFlags has WHERE_USE_LIMIT */
139391 u8 nLevel; /* Number of nested loop */
139392 i8 nOBSat; /* Number of ORDER BY terms satisfied by indices */
 
139393 u8 eOnePass; /* ONEPASS_OFF, or _SINGLE, or _MULTI */
 
139394 u8 eDistinct; /* One of the WHERE_DISTINCT_* values */
139395 unsigned bDeferredSeek :1; /* Uses OP_DeferredSeek */
139396 unsigned untestedTerms :1; /* Not all WHERE terms resolved by outer loop */
139397 unsigned bOrderedInnerLoop:1;/* True if only the inner-most loop is ordered */
139398 unsigned sorted :1; /* True if really sorted (not just grouped) */
139399 LogEst nRowOut; /* Estimated number of output rows */
139400 int iTop; /* The very beginning of the WHERE loop */
139401 WhereLoop *pLoops; /* List of all WhereLoop objects */
139402 WhereExprMod *pExprMods; /* Expression modifications */
139403 Bitmask revMask; /* Mask of ORDER BY terms that need reversing */
 
139404 WhereClause sWC; /* Decomposition of the WHERE clause */
139405 WhereMaskSet sMaskSet; /* Map cursor numbers to bitmasks */
139406 WhereLevel a[1]; /* Information about each nest loop in WHERE */
139407 };
139408
@@ -138632,10 +139412,12 @@
139412 ** where.c:
139413 */
139414 SQLITE_PRIVATE Bitmask sqlite3WhereGetMask(WhereMaskSet*,int);
139415 #ifdef WHERETRACE_ENABLED
139416 SQLITE_PRIVATE void sqlite3WhereClausePrint(WhereClause *pWC);
139417 SQLITE_PRIVATE void sqlite3WhereTermPrint(WhereTerm *pTerm, int iTerm);
139418 SQLITE_PRIVATE void sqlite3WhereLoopPrint(WhereLoop *p, WhereClause *pWC);
139419 #endif
139420 SQLITE_PRIVATE WhereTerm *sqlite3WhereFindTerm(
139421 WhereClause *pWC, /* The WHERE clause to be searched */
139422 int iCur, /* Cursor number of LHS */
139423 int iColumn, /* Column number of LHS */
@@ -139321,11 +140103,11 @@
140103 }
140104 sqlite3VdbeAddOp1(v, OP_IsNull, iOut); VdbeCoverage(v);
140105 if( i==iEq ){
140106 pIn->iCur = iTab;
140107 pIn->eEndLoopOp = bRev ? OP_Prev : OP_Next;
140108 if( iEq>0 ){
140109 pIn->iBase = iReg - i;
140110 pIn->nPrefix = i;
140111 pLoop->wsFlags |= WHERE_IN_EARLYOUT;
140112 }else{
140113 pIn->nPrefix = 0;
@@ -139773,10 +140555,11 @@
140555 Vdbe *v = pParse->pVdbe; /* Vdbe to generate code within */
140556
140557 assert( iIdxCur>0 );
140558 assert( pIdx->aiColumn[pIdx->nColumn-1]==-1 );
140559
140560 pWInfo->bDeferredSeek = 1;
140561 sqlite3VdbeAddOp3(v, OP_DeferredSeek, iIdxCur, 0, iCur);
140562 if( (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)
140563 && DbMaskAllZero(sqlite3ParseToplevel(pParse)->writeMask)
140564 ){
140565 int i;
@@ -139840,11 +140623,26 @@
140623 Expr *pIdxExpr; /* The index expression */
140624 int iTabCur; /* The cursor of the corresponding table */
140625 int iIdxCur; /* The cursor for the index */
140626 int iIdxCol; /* The column for the index */
140627 int iTabCol; /* The column for the table */
140628 WhereInfo *pWInfo; /* Complete WHERE clause information */
140629 sqlite3 *db; /* Database connection (for malloc()) */
140630 } IdxExprTrans;
140631
140632 /*
140633 ** Preserve pExpr on the WhereETrans list of the WhereInfo.
140634 */
140635 static void preserveExpr(IdxExprTrans *pTrans, Expr *pExpr){
140636 WhereExprMod *pNew;
140637 pNew = sqlite3DbMallocRaw(pTrans->db, sizeof(*pNew));
140638 if( pNew==0 ) return;
140639 pNew->pNext = pTrans->pWInfo->pExprMods;
140640 pTrans->pWInfo->pExprMods = pNew;
140641 pNew->pExpr = pExpr;
140642 memcpy(&pNew->orig, pExpr, sizeof(*pExpr));
140643 }
140644
140645 /* The walker node callback used to transform matching expressions into
140646 ** a reference to an index column for an index on an expression.
140647 **
140648 ** If pExpr matches, then transform it into a reference to the index column
@@ -139851,10 +140649,11 @@
140649 ** that contains the value of pExpr.
140650 */
140651 static int whereIndexExprTransNode(Walker *p, Expr *pExpr){
140652 IdxExprTrans *pX = p->u.pIdxTrans;
140653 if( sqlite3ExprCompare(0, pExpr, pX->pIdxExpr, pX->iTabCur)==0 ){
140654 preserveExpr(pX, pExpr);
140655 pExpr->affExpr = sqlite3ExprAffinity(pExpr);
140656 pExpr->op = TK_COLUMN;
140657 pExpr->iTable = pX->iIdxCur;
140658 pExpr->iColumn = pX->iIdxCol;
140659 pExpr->y.pTab = 0;
@@ -139874,10 +140673,11 @@
140673 static int whereIndexExprTransColumn(Walker *p, Expr *pExpr){
140674 if( pExpr->op==TK_COLUMN ){
140675 IdxExprTrans *pX = p->u.pIdxTrans;
140676 if( pExpr->iTable==pX->iTabCur && pExpr->iColumn==pX->iTabCol ){
140677 assert( pExpr->y.pTab!=0 );
140678 preserveExpr(pX, pExpr);
140679 pExpr->affExpr = sqlite3TableColumnAffinity(pExpr->y.pTab,pExpr->iColumn);
140680 pExpr->iTable = pX->iIdxCur;
140681 pExpr->iColumn = pX->iIdxCol;
140682 pExpr->y.pTab = 0;
140683 }
@@ -139915,10 +140715,12 @@
140715 pTab = pIdx->pTable;
140716 memset(&w, 0, sizeof(w));
140717 w.u.pIdxTrans = &x;
140718 x.iTabCur = iTabCur;
140719 x.iIdxCur = iIdxCur;
140720 x.pWInfo = pWInfo;
140721 x.db = pWInfo->pParse->db;
140722 for(iIdxCol=0; iIdxCol<pIdx->nColumn; iIdxCol++){
140723 i16 iRef = pIdx->aiColumn[iIdxCol];
140724 if( iRef==XN_EXPR ){
140725 assert( aColExpr->a[iIdxCol].pExpr!=0 );
140726 x.pIdxExpr = aColExpr->a[iIdxCol].pExpr;
@@ -140012,10 +140814,25 @@
140814 pTabItem = &pWInfo->pTabList->a[pLevel->iFrom];
140815 iCur = pTabItem->iCursor;
140816 pLevel->notReady = notReady & ~sqlite3WhereGetMask(&pWInfo->sMaskSet, iCur);
140817 bRev = (pWInfo->revMask>>iLevel)&1;
140818 VdbeModuleComment((v, "Begin WHERE-loop%d: %s",iLevel,pTabItem->pTab->zName));
140819 #if WHERETRACE_ENABLED /* 0x20800 */
140820 if( sqlite3WhereTrace & 0x800 ){
140821 sqlite3DebugPrintf("Coding level %d of %d: notReady=%llx iFrom=%d\n",
140822 iLevel, pWInfo->nLevel, (u64)notReady, pLevel->iFrom);
140823 sqlite3WhereLoopPrint(pLoop, pWC);
140824 }
140825 if( sqlite3WhereTrace & 0x20000 ){
140826 if( iLevel==0 ){
140827 sqlite3DebugPrintf("WHERE clause being coded:\n");
140828 sqlite3TreeViewExpr(0, pWInfo->pWhere, 0);
140829 }
140830 sqlite3DebugPrintf("All WHERE-clause terms before coding:\n");
140831 sqlite3WhereClausePrint(pWC);
140832 }
140833 #endif
140834
140835 /* Create labels for the "break" and "continue" instructions
140836 ** for the current loop. Jump to addrBrk to break out of a loop.
140837 ** Jump to cont to go immediately to the next iteration of the
140838 ** loop.
@@ -140398,11 +141215,11 @@
141215 if( (pLoop->wsFlags & (WHERE_TOP_LIMIT|WHERE_BTM_LIMIT))==0
141216 && (pLoop->wsFlags & WHERE_BIGNULL_SORT)!=0
141217 ){
141218 assert( bSeekPastNull==0 && nExtraReg==0 && nBtm==0 && nTop==0 );
141219 assert( pRangeEnd==0 && pRangeStart==0 );
141220 testcase( pLoop->nSkip>0 );
141221 nExtraReg = 1;
141222 bSeekPastNull = 1;
141223 pLevel->regBignull = regBignull = ++pParse->nMem;
141224 pLevel->addrBignull = sqlite3VdbeMakeLabel(pParse);
141225 }
@@ -141067,10 +141884,14 @@
141884 #ifdef WHERETRACE_ENABLED /* 0xffff */
141885 if( sqlite3WhereTrace ){
141886 VdbeNoopComment((v, "WhereTerm[%d] (%p) priority=%d",
141887 pWC->nTerm-j, pTerm, iLoop));
141888 }
141889 if( sqlite3WhereTrace & 0x800 ){
141890 sqlite3DebugPrintf("Coding auxiliary constraint:\n");
141891 sqlite3WhereTermPrint(pTerm, pWC->nTerm-j);
141892 }
141893 #endif
141894 sqlite3ExprIfFalse(pParse, pE, addrCont, SQLITE_JUMPIFNULL);
141895 if( skipLikeAddr ) sqlite3VdbeJumpHere(v, skipLikeAddr);
141896 pTerm->wtFlags |= TERM_CODED;
141897 }
@@ -141090,12 +141911,18 @@
141911 WhereTerm *pAlt;
141912 if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue;
141913 if( (pTerm->eOperator & (WO_EQ|WO_IS))==0 ) continue;
141914 if( (pTerm->eOperator & WO_EQUIV)==0 ) continue;
141915 if( pTerm->leftCursor!=iCur ) continue;
141916 if( pTabItem->fg.jointype & JT_LEFT ) continue;
141917 pE = pTerm->pExpr;
141918 #ifdef WHERETRACE_ENABLED /* 0x800 */
141919 if( sqlite3WhereTrace & 0x800 ){
141920 sqlite3DebugPrintf("Coding transitive constraint:\n");
141921 sqlite3WhereTermPrint(pTerm, pWC->nTerm-j);
141922 }
141923 #endif
141924 assert( !ExprHasProperty(pE, EP_FromJoin) );
141925 assert( (pTerm->prereqRight & pLevel->notReady)!=0 );
141926 pAlt = sqlite3WhereFindTerm(pWC, iCur, pTerm->u.leftColumn, notReady,
141927 WO_EQ|WO_IN|WO_IS, 0);
141928 if( pAlt==0 ) continue;
@@ -141134,10 +141961,21 @@
141961 sqlite3ExprIfFalse(pParse, pTerm->pExpr, addrCont, SQLITE_JUMPIFNULL);
141962 pTerm->wtFlags |= TERM_CODED;
141963 }
141964 }
141965
141966 #if WHERETRACE_ENABLED /* 0x20800 */
141967 if( sqlite3WhereTrace & 0x20000 ){
141968 sqlite3DebugPrintf("All WHERE-clause terms after coding level %d:\n",
141969 iLevel);
141970 sqlite3WhereClausePrint(pWC);
141971 }
141972 if( sqlite3WhereTrace & 0x800 ){
141973 sqlite3DebugPrintf("End Coding level %d: notReady=%llx\n",
141974 iLevel, (u64)pLevel->notReady);
141975 }
141976 #endif
141977 return pLevel->notReady;
141978 }
141979
141980 /************** End of wherecode.c *******************************************/
141981 /************** Begin file whereexpr.c ***************************************/
@@ -142872,11 +143710,11 @@
143710 return pWInfo->iBreak;
143711 }
143712
143713 /*
143714 ** Return ONEPASS_OFF (0) if an UPDATE or DELETE statement is unable to
143715 ** operate directly on the rowids returned by a WHERE clause. Return
143716 ** ONEPASS_SINGLE (1) if the statement can operation directly because only
143717 ** a single row is to be changed. Return ONEPASS_MULTI (2) if the one-pass
143718 ** optimization can be used on multiple
143719 **
143720 ** If the ONEPASS optimization is used (if this routine returns true)
@@ -142898,10 +143736,18 @@
143736 aiCur[0], aiCur[1]);
143737 }
143738 #endif
143739 return pWInfo->eOnePass;
143740 }
143741
143742 /*
143743 ** Return TRUE if the WHERE loop uses the OP_DeferredSeek opcode to move
143744 ** the data cursor to the row selected by the index cursor.
143745 */
143746 SQLITE_PRIVATE int sqlite3WhereUsesDeferredSeek(WhereInfo *pWInfo){
143747 return pWInfo->bDeferredSeek;
143748 }
143749
143750 /*
143751 ** Move the content of pSrc into pDest
143752 */
143753 static void whereOrMove(WhereOrSet *pDest, WhereOrSet *pSrc){
@@ -143357,11 +144203,11 @@
144203 ** structure. Used for testing and debugging only. If neither
144204 ** SQLITE_TEST or SQLITE_DEBUG are defined, then these routines
144205 ** are no-ops.
144206 */
144207 #if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(WHERETRACE_ENABLED)
144208 static void whereTraceIndexInfoInputs(sqlite3_index_info *p){
144209 int i;
144210 if( !sqlite3WhereTrace ) return;
144211 for(i=0; i<p->nConstraint; i++){
144212 sqlite3DebugPrintf(" constraint[%d]: col=%d termid=%d op=%d usabled=%d\n",
144213 i,
@@ -143375,11 +144221,11 @@
144221 i,
144222 p->aOrderBy[i].iColumn,
144223 p->aOrderBy[i].desc);
144224 }
144225 }
144226 static void whereTraceIndexInfoOutputs(sqlite3_index_info *p){
144227 int i;
144228 if( !sqlite3WhereTrace ) return;
144229 for(i=0; i<p->nConstraint; i++){
144230 sqlite3DebugPrintf(" usage[%d]: argvIdx=%d omit=%d\n",
144231 i,
@@ -143391,12 +144237,12 @@
144237 sqlite3DebugPrintf(" orderByConsumed=%d\n", p->orderByConsumed);
144238 sqlite3DebugPrintf(" estimatedCost=%g\n", p->estimatedCost);
144239 sqlite3DebugPrintf(" estimatedRows=%lld\n", p->estimatedRows);
144240 }
144241 #else
144242 #define whereTraceIndexInfoInputs(A)
144243 #define whereTraceIndexInfoOutputs(A)
144244 #endif
144245
144246 #ifndef SQLITE_OMIT_AUTOMATIC_INDEX
144247 /*
144248 ** Return TRUE if the WHERE clause term pTerm is of a form where it
@@ -143622,12 +144468,12 @@
144468 pTabItem->regResult, pLevel->iIdxCur);
144469 sqlite3VdbeGoto(v, addrTop);
144470 pTabItem->fg.viaCoroutine = 0;
144471 }else{
144472 sqlite3VdbeAddOp2(v, OP_Next, pLevel->iTabCur, addrTop+1); VdbeCoverage(v);
144473 sqlite3VdbeChangeP5(v, SQLITE_STMTSTATUS_AUTOINDEX);
144474 }
 
144475 sqlite3VdbeJumpHere(v, addrTop);
144476 sqlite3ReleaseTempReg(pParse, regRecord);
144477
144478 /* Jump here when skipping the initialization */
144479 sqlite3VdbeJumpHere(v, addrInit);
@@ -143702,27 +144548,18 @@
144548 + sizeof(*pIdxOrderBy)*nOrderBy + sizeof(*pHidden) );
144549 if( pIdxInfo==0 ){
144550 sqlite3ErrorMsg(pParse, "out of memory");
144551 return 0;
144552 }
 
 
 
 
 
 
144553 pHidden = (struct HiddenIndexInfo*)&pIdxInfo[1];
144554 pIdxCons = (struct sqlite3_index_constraint*)&pHidden[1];
144555 pIdxOrderBy = (struct sqlite3_index_orderby*)&pIdxCons[nTerm];
144556 pUsage = (struct sqlite3_index_constraint_usage*)&pIdxOrderBy[nOrderBy];
144557 pIdxInfo->nOrderBy = nOrderBy;
144558 pIdxInfo->aConstraint = pIdxCons;
144559 pIdxInfo->aOrderBy = pIdxOrderBy;
144560 pIdxInfo->aConstraintUsage = pUsage;
 
 
 
144561 pHidden->pWC = pWC;
144562 pHidden->pParse = pParse;
144563 for(i=j=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
144564 u16 op;
144565 if( pTerm->leftCursor != pSrc->iCursor ) continue;
@@ -143778,10 +144615,11 @@
144615 }
144616 }
144617
144618 j++;
144619 }
144620 pIdxInfo->nConstraint = j;
144621 for(i=0; i<nOrderBy; i++){
144622 Expr *pExpr = pOrderBy->a[i].pExpr;
144623 pIdxOrderBy[i].iColumn = pExpr->iColumn;
144624 pIdxOrderBy[i].desc = pOrderBy->a[i].sortFlags & KEYINFO_ORDER_DESC;
144625 }
@@ -143808,13 +144646,13 @@
144646 */
144647 static int vtabBestIndex(Parse *pParse, Table *pTab, sqlite3_index_info *p){
144648 sqlite3_vtab *pVtab = sqlite3GetVTable(pParse->db, pTab)->pVtab;
144649 int rc;
144650
144651 whereTraceIndexInfoInputs(p);
144652 rc = pVtab->pModule->xBestIndex(pVtab, p);
144653 whereTraceIndexInfoOutputs(p);
144654
144655 if( rc!=SQLITE_OK && rc!=SQLITE_CONSTRAINT ){
144656 if( rc==SQLITE_NOMEM ){
144657 sqlite3OomFault(pParse->db);
144658 }else if( !pVtab->zErrMsg ){
@@ -144491,20 +145329,21 @@
145329
145330 #ifdef WHERETRACE_ENABLED
145331 /*
145332 ** Print the content of a WhereTerm object
145333 */
145334 SQLITE_PRIVATE void sqlite3WhereTermPrint(WhereTerm *pTerm, int iTerm){
145335 if( pTerm==0 ){
145336 sqlite3DebugPrintf("TERM-%-3d NULL\n", iTerm);
145337 }else{
145338 char zType[8];
145339 char zLeft[50];
145340 memcpy(zType, "....", 5);
145341 if( pTerm->wtFlags & TERM_VIRTUAL ) zType[0] = 'V';
145342 if( pTerm->eOperator & WO_EQUIV ) zType[1] = 'E';
145343 if( ExprHasProperty(pTerm->pExpr, EP_FromJoin) ) zType[2] = 'L';
145344 if( pTerm->wtFlags & TERM_CODED ) zType[3] = 'C';
145345 if( pTerm->eOperator & WO_SINGLE ){
145346 sqlite3_snprintf(sizeof(zLeft),zLeft,"left={%d:%d}",
145347 pTerm->leftCursor, pTerm->u.leftColumn);
145348 }else if( (pTerm->eOperator & WO_OR)!=0 && pTerm->u.pOrInfo!=0 ){
145349 sqlite3_snprintf(sizeof(zLeft),zLeft,"indexable=0x%lld",
@@ -144511,13 +145350,18 @@
145350 pTerm->u.pOrInfo->indexable);
145351 }else{
145352 sqlite3_snprintf(sizeof(zLeft),zLeft,"left=%d", pTerm->leftCursor);
145353 }
145354 sqlite3DebugPrintf(
145355 "TERM-%-3d %p %s %-12s op=%03x wtFlags=%04x",
145356 iTerm, pTerm, zType, zLeft, pTerm->eOperator, pTerm->wtFlags);
145357 /* The 0x10000 .wheretrace flag causes extra information to be
145358 ** shown about each Term */
145359 if( sqlite3WhereTrace & 0x10000 ){
145360 sqlite3DebugPrintf(" prob=%-3d prereq=%llx,%llx",
145361 pTerm->truthProb, (u64)pTerm->prereqAll, (u64)pTerm->prereqRight);
145362 }
145363 if( pTerm->iField ){
145364 sqlite3DebugPrintf(" iField=%d", pTerm->iField);
145365 }
145366 if( pTerm->iParent>=0 ){
145367 sqlite3DebugPrintf(" iParent=%d", pTerm->iParent);
@@ -144533,20 +145377,20 @@
145377 ** Show the complete content of a WhereClause
145378 */
145379 SQLITE_PRIVATE void sqlite3WhereClausePrint(WhereClause *pWC){
145380 int i;
145381 for(i=0; i<pWC->nTerm; i++){
145382 sqlite3WhereTermPrint(&pWC->a[i], i);
145383 }
145384 }
145385 #endif
145386
145387 #ifdef WHERETRACE_ENABLED
145388 /*
145389 ** Print a WhereLoop object for debugging purposes
145390 */
145391 SQLITE_PRIVATE void sqlite3WhereLoopPrint(WhereLoop *p, WhereClause *pWC){
145392 WhereInfo *pWInfo = pWC->pWInfo;
145393 int nb = 1+(pWInfo->pTabList->nSrc+3)/4;
145394 struct SrcList_item *pItem = pWInfo->pTabList->a + p->iTab;
145395 Table *pTab = pItem->pTab;
145396 Bitmask mAll = (((Bitmask)1)<<(nb*4)) - 1;
@@ -144584,11 +145428,11 @@
145428 }
145429 sqlite3DebugPrintf(" cost %d,%d,%d\n", p->rSetup, p->rRun, p->nOut);
145430 if( p->nLTerm && (sqlite3WhereTrace & 0x100)!=0 ){
145431 int i;
145432 for(i=0; i<p->nLTerm; i++){
145433 sqlite3WhereTermPrint(p->aLTerm[i], i);
145434 }
145435 }
145436 }
145437 #endif
145438
@@ -144688,10 +145532,11 @@
145532 while( pWInfo->pLoops ){
145533 WhereLoop *p = pWInfo->pLoops;
145534 pWInfo->pLoops = p->pNextLoop;
145535 whereLoopDelete(db, p);
145536 }
145537 assert( pWInfo->pExprMods==0 );
145538 sqlite3DbFreeNN(db, pWInfo);
145539 }
145540
145541 /*
145542 ** Return TRUE if all of the following are true:
@@ -144888,10 +145733,12 @@
145733 WHERETRACE(0xffffffff,("=== query planner search limit reached ===\n"));
145734 if( pBuilder->pOrSet ) pBuilder->pOrSet->n = 0;
145735 return SQLITE_DONE;
145736 }
145737 pBuilder->iPlanLimit--;
145738
145739 whereLoopAdjustCost(pWInfo->pLoops, pTemplate);
145740
145741 /* If pBuilder->pOrSet is defined, then only keep track of the costs
145742 ** and prereqs.
145743 */
145744 if( pBuilder->pOrSet!=0 ){
@@ -144903,29 +145750,28 @@
145750 whereOrInsert(pBuilder->pOrSet, pTemplate->prereq, pTemplate->rRun,
145751 pTemplate->nOut);
145752 #if WHERETRACE_ENABLED /* 0x8 */
145753 if( sqlite3WhereTrace & 0x8 ){
145754 sqlite3DebugPrintf(x?" or-%d: ":" or-X: ", n);
145755 sqlite3WhereLoopPrint(pTemplate, pBuilder->pWC);
145756 }
145757 #endif
145758 }
145759 return SQLITE_OK;
145760 }
145761
145762 /* Look for an existing WhereLoop to replace with pTemplate
145763 */
 
145764 ppPrev = whereLoopFindLesser(&pWInfo->pLoops, pTemplate);
145765
145766 if( ppPrev==0 ){
145767 /* There already exists a WhereLoop on the list that is better
145768 ** than pTemplate, so just ignore pTemplate */
145769 #if WHERETRACE_ENABLED /* 0x8 */
145770 if( sqlite3WhereTrace & 0x8 ){
145771 sqlite3DebugPrintf(" skip: ");
145772 sqlite3WhereLoopPrint(pTemplate, pBuilder->pWC);
145773 }
145774 #endif
145775 return SQLITE_OK;
145776 }else{
145777 p = *ppPrev;
@@ -144937,16 +145783,16 @@
145783 */
145784 #if WHERETRACE_ENABLED /* 0x8 */
145785 if( sqlite3WhereTrace & 0x8 ){
145786 if( p!=0 ){
145787 sqlite3DebugPrintf("replace: ");
145788 sqlite3WhereLoopPrint(p, pBuilder->pWC);
145789 sqlite3DebugPrintf(" with: ");
145790 }else{
145791 sqlite3DebugPrintf(" add: ");
145792 }
145793 sqlite3WhereLoopPrint(pTemplate, pBuilder->pWC);
145794 }
145795 #endif
145796 if( p==0 ){
145797 /* Allocate a new WhereLoop to add to the end of the list */
145798 *ppPrev = p = sqlite3DbMallocRawNN(db, sizeof(WhereLoop));
@@ -144966,11 +145812,11 @@
145812 if( pToDel==0 ) break;
145813 *ppTail = pToDel->pNextLoop;
145814 #if WHERETRACE_ENABLED /* 0x8 */
145815 if( sqlite3WhereTrace & 0x8 ){
145816 sqlite3DebugPrintf(" delete: ");
145817 sqlite3WhereLoopPrint(pToDel, pBuilder->pWC);
145818 }
145819 #endif
145820 whereLoopDelete(db, pToDel);
145821 }
145822 }
@@ -145175,12 +146021,13 @@
146021 LogEst rLogSize; /* Logarithm of table size */
146022 WhereTerm *pTop = 0, *pBtm = 0; /* Top and bottom range constraints */
146023
146024 pNew = pBuilder->pNew;
146025 if( db->mallocFailed ) return SQLITE_NOMEM_BKPT;
146026 WHERETRACE(0x800, ("BEGIN %s.addBtreeIdx(%s), nEq=%d, nSkip=%d\n",
146027 pProbe->pTable->zName,pProbe->zName,
146028 pNew->u.btree.nEq, pNew->nSkip));
146029
146030 assert( (pNew->wsFlags & WHERE_VIRTUALTABLE)==0 );
146031 assert( (pNew->wsFlags & WHERE_TOP_LIMIT)==0 );
146032 if( pNew->wsFlags & WHERE_BTM_LIMIT ){
146033 opMask = WO_LT|WO_LE;
@@ -145473,10 +146320,11 @@
146320 ** On the other hand, the extra seeks could end up being significantly
146321 ** more expensive. */
146322 assert( 42==sqlite3LogEst(18) );
146323 if( saved_nEq==saved_nSkip
146324 && saved_nEq+1<pProbe->nKeyCol
146325 && saved_nEq==pNew->nLTerm
146326 && pProbe->noSkipScan==0
146327 && OptimizationEnabled(db, SQLITE_SkipScan)
146328 && pProbe->aiRowLogEst[saved_nEq+1]>=42 /* TUNING: Minimum for skip-scan */
146329 && (rc = whereLoopResize(db, pNew, pNew->nLTerm+1))==SQLITE_OK
146330 ){
@@ -146254,11 +147102,12 @@
147102 rc = whereLoopAddBtree(&sSubBuild, mPrereq);
147103 }
147104 if( rc==SQLITE_OK ){
147105 rc = whereLoopAddOr(&sSubBuild, mPrereq, mUnusable);
147106 }
147107 assert( rc==SQLITE_OK || rc==SQLITE_DONE || sCur.n==0 );
147108 testcase( rc==SQLITE_DONE );
147109 if( sCur.n==0 ){
147110 sSum.n = 0;
147111 break;
147112 }else if( once ){
147113 whereOrMove(&sSum, &sCur);
@@ -147584,11 +148433,11 @@
148433 int i;
148434 static const char zLabel[] = "0123456789abcdefghijklmnopqrstuvwyxz"
148435 "ABCDEFGHIJKLMNOPQRSTUVWYXZ";
148436 for(p=pWInfo->pLoops, i=0; p; p=p->pNextLoop, i++){
148437 p->cId = zLabel[i%(sizeof(zLabel)-1)];
148438 sqlite3WhereLoopPrint(p, sWLB.pWC);
148439 }
148440 }
148441 #endif
148442
148443 wherePathSolver(pWInfo, 0);
@@ -147624,11 +148473,11 @@
148473 break;
148474 }
148475 }
148476 sqlite3DebugPrintf("\n");
148477 for(ii=0; ii<pWInfo->nLevel; ii++){
148478 sqlite3WhereLoopPrint(pWInfo->a[ii].pWLoop, sWLB.pWC);
148479 }
148480 }
148481 #endif
148482
148483 /* Attempt to omit tables from the join that do not affect the result.
@@ -148016,14 +148865,30 @@
148865 for(j=pLevel->u.in.nIn, pIn=&pLevel->u.in.aInLoop[j-1]; j>0; j--, pIn--){
148866 sqlite3VdbeJumpHere(v, pIn->addrInTop+1);
148867 if( pIn->eEndLoopOp!=OP_Noop ){
148868 if( pIn->nPrefix ){
148869 assert( pLoop->wsFlags & WHERE_IN_EARLYOUT );
148870 if( (pLoop->wsFlags & WHERE_VIRTUALTABLE)==0 ){
148871 sqlite3VdbeAddOp4Int(v, OP_IfNoHope, pLevel->iIdxCur,
148872 sqlite3VdbeCurrentAddr(v)+2+(pLevel->iLeftJoin!=0),
148873 pIn->iBase, pIn->nPrefix);
148874 VdbeCoverage(v);
148875 }
148876 if( pLevel->iLeftJoin ){
148877 /* For LEFT JOIN queries, cursor pIn->iCur may not have been
148878 ** opened yet. This occurs for WHERE clauses such as
148879 ** "a = ? AND b IN (...)", where the index is on (a, b). If
148880 ** the RHS of the (a=?) is NULL, then the "b IN (...)" may
148881 ** never have been coded, but the body of the loop run to
148882 ** return the null-row. So, if the cursor is not open yet,
148883 ** jump over the OP_Next or OP_Prev instruction about to
148884 ** be coded. */
148885 sqlite3VdbeAddOp2(v, OP_IfNotOpen, pIn->iCur,
148886 sqlite3VdbeCurrentAddr(v) + 2
148887 );
148888 VdbeCoverage(v);
148889 }
148890 }
148891 sqlite3VdbeAddOp2(v, pIn->eEndLoopOp, pIn->iCur, pIn->addrInTop);
148892 VdbeCoverage(v);
148893 VdbeCoverageIf(v, pIn->eEndLoopOp==OP_Prev);
148894 VdbeCoverageIf(v, pIn->eEndLoopOp==OP_Next);
@@ -148183,10 +149048,18 @@
149048 #ifdef SQLITE_DEBUG
149049 if( db->flags & SQLITE_VdbeAddopTrace ) printf("TRANSLATE complete\n");
149050 #endif
149051 }
149052 }
149053
149054 /* Undo all Expr node modifications */
149055 while( pWInfo->pExprMods ){
149056 WhereExprMod *p = pWInfo->pExprMods;
149057 pWInfo->pExprMods = p->pNext;
149058 memcpy(p->pExpr, &p->orig, sizeof(p->orig));
149059 sqlite3DbFree(db, p);
149060 }
149061
149062 /* Final cleanup
149063 */
149064 pParse->nQueryLoop = pWInfo->savedNQueryLoop;
149065 whereInfoFree(db, pWInfo);
@@ -148994,10 +149867,11 @@
149867 }
149868 }
149869 }
149870 if( iCol<0 ){
149871 Expr *pDup = sqlite3ExprDup(pParse->db, pExpr, 0);
149872 if( pDup && pDup->op==TK_AGG_FUNCTION ) pDup->op = TK_FUNCTION;
149873 p->pSub = sqlite3ExprListAppend(pParse, p->pSub, pDup);
149874 }
149875 if( p->pSub ){
149876 assert( ExprHasProperty(pExpr, EP_Static)==0 );
149877 ExprSetProperty(pExpr, EP_Static);
@@ -149089,13 +149963,14 @@
149963 ){
149964 if( pAppend ){
149965 int i;
149966 int nInit = pList ? pList->nExpr : 0;
149967 for(i=0; i<pAppend->nExpr; i++){
149968 int iDummy;
149969 Expr *pDup = sqlite3ExprDup(pParse->db, pAppend->a[i].pExpr, 0);
149970 assert( pDup==0 || !ExprHasProperty(pDup, EP_MemToken) );
149971 if( bIntToNull && pDup && sqlite3ExprIsInteger(pDup, &iDummy) ){
149972 pDup->op = TK_NULL;
149973 pDup->flags &= ~(EP_IntValue|EP_IsTrue|EP_IsFalse);
149974 pDup->u.zToken = 0;
149975 }
149976 pList = sqlite3ExprListAppend(pParse, pList, pDup);
@@ -149142,11 +150017,11 @@
150017 p->selFlags |= SF_WinRewrite;
150018
150019 /* Create the ORDER BY clause for the sub-select. This is the concatenation
150020 ** of the window PARTITION and ORDER BY clauses. Then, if this makes it
150021 ** redundant, remove the ORDER BY from the parent SELECT. */
150022 pSort = exprListAppendList(pParse, 0, pMWin->pPartition, 1);
150023 pSort = exprListAppendList(pParse, pSort, pMWin->pOrderBy, 1);
150024 if( pSort && p->pOrderBy && p->pOrderBy->nExpr<=pSort->nExpr ){
150025 int nSave = pSort->nExpr;
150026 pSort->nExpr = p->pOrderBy->nExpr;
150027 if( sqlite3ExprListCompare(pSort, p->pOrderBy, -1)==0 ){
@@ -149226,14 +150101,10 @@
150101 memcpy(pTab, pTab2, sizeof(Table));
150102 pTab->tabFlags |= TF_Ephemeral;
150103 p->pSrc->a[0].pTab = pTab;
150104 pTab = pTab2;
150105 }
 
 
 
 
150106 }else{
150107 sqlite3SelectDelete(db, pSub);
150108 }
150109 if( db->mallocFailed ) rc = SQLITE_NOMEM;
150110 sqlite3DbFree(db, pTab);
@@ -149476,25 +150347,33 @@
150347 pWin->ppThis = &pSel->pWin;
150348 }
150349 }
150350
150351 /*
150352 ** Return 0 if the two window objects are identical, 1 if they are
150353 ** different, or 2 if it cannot be determined if the objects are identical
150354 ** or not. Identical window objects can be processed in a single scan.
150355 */
150356 SQLITE_PRIVATE int sqlite3WindowCompare(Parse *pParse, Window *p1, Window *p2, int bFilter){
150357 int res;
150358 if( NEVER(p1==0) || NEVER(p2==0) ) return 1;
150359 if( p1->eFrmType!=p2->eFrmType ) return 1;
150360 if( p1->eStart!=p2->eStart ) return 1;
150361 if( p1->eEnd!=p2->eEnd ) return 1;
150362 if( p1->eExclude!=p2->eExclude ) return 1;
150363 if( sqlite3ExprCompare(pParse, p1->pStart, p2->pStart, -1) ) return 1;
150364 if( sqlite3ExprCompare(pParse, p1->pEnd, p2->pEnd, -1) ) return 1;
150365 if( (res = sqlite3ExprListCompare(p1->pPartition, p2->pPartition, -1)) ){
150366 return res;
150367 }
150368 if( (res = sqlite3ExprListCompare(p1->pOrderBy, p2->pOrderBy, -1)) ){
150369 return res;
150370 }
150371 if( bFilter ){
150372 if( (res = sqlite3ExprCompare(pParse, p1->pFilter, p2->pFilter, -1)) ){
150373 return res;
150374 }
150375 }
150376 return 0;
150377 }
150378
150379
@@ -149501,14 +150380,21 @@
150380 /*
150381 ** This is called by code in select.c before it calls sqlite3WhereBegin()
150382 ** to begin iterating through the sub-query results. It is used to allocate
150383 ** and initialize registers and cursors used by sqlite3WindowCodeStep().
150384 */
150385 SQLITE_PRIVATE void sqlite3WindowCodeInit(Parse *pParse, Select *pSelect){
150386 int nEphExpr = pSelect->pSrc->a[0].pSelect->pEList->nExpr;
150387 Window *pMWin = pSelect->pWin;
150388 Window *pWin;
150389 Vdbe *v = sqlite3GetVdbe(pParse);
150390
150391 sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pMWin->iEphCsr, nEphExpr);
150392 sqlite3VdbeAddOp2(v, OP_OpenDup, pMWin->iEphCsr+1, pMWin->iEphCsr);
150393 sqlite3VdbeAddOp2(v, OP_OpenDup, pMWin->iEphCsr+2, pMWin->iEphCsr);
150394 sqlite3VdbeAddOp2(v, OP_OpenDup, pMWin->iEphCsr+3, pMWin->iEphCsr);
150395
150396 /* Allocate registers to use for PARTITION BY values, if any. Initialize
150397 ** said registers to NULL. */
150398 if( pMWin->pPartition ){
150399 int nExpr = pMWin->pPartition->nExpr;
150400 pMWin->regPart = pParse->nMem+1;
@@ -149770,11 +150656,11 @@
150656
150657 assert( bInverse==0 || pWin->eStart!=TK_UNBOUNDED );
150658
150659 /* All OVER clauses in the same window function aggregate step must
150660 ** be the same. */
150661 assert( pWin==pMWin || sqlite3WindowCompare(pParse,pWin,pMWin,0)!=1 );
150662
150663 for(i=0; i<nArg; i++){
150664 if( i!=1 || pFunc->zName!=nth_valueName ){
150665 sqlite3VdbeAddOp3(v, OP_Column, csr, pWin->iArgCol+i, reg+i);
150666 }else{
@@ -158619,10 +159505,13 @@
159505 ** the lookaside memory.
159506 */
159507 static int setupLookaside(sqlite3 *db, void *pBuf, int sz, int cnt){
159508 #ifndef SQLITE_OMIT_LOOKASIDE
159509 void *pStart;
159510 sqlite3_int64 szAlloc = sz*(sqlite3_int64)cnt;
159511 int nBig; /* Number of full-size slots */
159512 int nSm; /* Number smaller LOOKASIDE_SMALL-byte slots */
159513
159514 if( sqlite3LookasideUsed(db,0)>0 ){
159515 return SQLITE_BUSY;
159516 }
159517 /* Free any existing lookaside buffer for this handle before
@@ -158641,15 +159530,30 @@
159530 if( sz==0 || cnt==0 ){
159531 sz = 0;
159532 pStart = 0;
159533 }else if( pBuf==0 ){
159534 sqlite3BeginBenignMalloc();
159535 pStart = sqlite3Malloc( szAlloc ); /* IMP: R-61949-35727 */
159536 sqlite3EndBenignMalloc();
159537 if( pStart ) szAlloc = sqlite3MallocSize(pStart);
159538 }else{
159539 pStart = pBuf;
159540 }
159541 #ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
159542 if( sz>=LOOKASIDE_SMALL*3 ){
159543 nBig = szAlloc/(3*LOOKASIDE_SMALL+sz);
159544 nSm = (szAlloc - sz*nBig)/LOOKASIDE_SMALL;
159545 }else if( sz>=LOOKASIDE_SMALL*2 ){
159546 nBig = szAlloc/(LOOKASIDE_SMALL+sz);
159547 nSm = (szAlloc - sz*nBig)/LOOKASIDE_SMALL;
159548 }else
159549 #endif /* SQLITE_OMIT_TWOSIZE_LOOKASIDE */
159550 if( sz>0 ){
159551 nBig = szAlloc/sz;
159552 nSm = 0;
159553 }else{
159554 nBig = nSm = 0;
159555 }
159556 db->lookaside.pStart = pStart;
159557 db->lookaside.pInit = 0;
159558 db->lookaside.pFree = 0;
159559 db->lookaside.sz = (u16)sz;
@@ -158656,28 +159560,45 @@
159560 db->lookaside.szTrue = (u16)sz;
159561 if( pStart ){
159562 int i;
159563 LookasideSlot *p;
159564 assert( sz > (int)sizeof(LookasideSlot*) );
 
159565 p = (LookasideSlot*)pStart;
159566 for(i=0; i<nBig; i++){
159567 p->pNext = db->lookaside.pInit;
159568 db->lookaside.pInit = p;
159569 p = (LookasideSlot*)&((u8*)p)[sz];
159570 }
159571 #ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
159572 db->lookaside.pSmallInit = 0;
159573 db->lookaside.pSmallFree = 0;
159574 db->lookaside.pMiddle = p;
159575 for(i=0; i<nSm; i++){
159576 p->pNext = db->lookaside.pSmallInit;
159577 db->lookaside.pSmallInit = p;
159578 p = (LookasideSlot*)&((u8*)p)[LOOKASIDE_SMALL];
159579 }
159580 #endif /* SQLITE_OMIT_TWOSIZE_LOOKASIDE */
159581 assert( ((uptr)p)<=szAlloc + (uptr)pStart );
159582 db->lookaside.pEnd = p;
159583 db->lookaside.bDisable = 0;
159584 db->lookaside.bMalloced = pBuf==0 ?1:0;
159585 db->lookaside.nSlot = nBig+nSm;
159586 }else{
159587 db->lookaside.pStart = db;
159588 #ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
159589 db->lookaside.pSmallInit = 0;
159590 db->lookaside.pSmallFree = 0;
159591 db->lookaside.pMiddle = db;
159592 #endif /* SQLITE_OMIT_TWOSIZE_LOOKASIDE */
159593 db->lookaside.pEnd = db;
159594 db->lookaside.bDisable = 1;
159595 db->lookaside.sz = 0;
159596 db->lookaside.bMalloced = 0;
159597 db->lookaside.nSlot = 0;
159598 }
159599 assert( sqlite3LookasideUsed(db,0)==0 );
159600 #endif /* SQLITE_OMIT_LOOKASIDE */
159601 return SQLITE_OK;
159602 }
159603
159604 /*
@@ -158788,10 +159709,11 @@
159709 SQLITE_NoSchemaError },
159710 { SQLITE_DBCONFIG_LEGACY_ALTER_TABLE, SQLITE_LegacyAlter },
159711 { SQLITE_DBCONFIG_DQS_DDL, SQLITE_DqsDDL },
159712 { SQLITE_DBCONFIG_DQS_DML, SQLITE_DqsDML },
159713 { SQLITE_DBCONFIG_LEGACY_FILE_FORMAT, SQLITE_LegacyFileFmt },
159714 { SQLITE_DBCONFIG_TRUSTED_SCHEMA, SQLITE_TrustedSchema },
159715 };
159716 unsigned int i;
159717 rc = SQLITE_ERROR; /* IMP: R-42790-23372 */
159718 for(i=0; i<ArraySize(aFlagOp); i++){
159719 if( aFlagOp[i].op==op ){
@@ -159659,12 +160581,19 @@
160581 return SQLITE_MISUSE_BKPT;
160582 }
160583
160584 assert( SQLITE_FUNC_CONSTANT==SQLITE_DETERMINISTIC );
160585 assert( SQLITE_FUNC_DIRECT==SQLITE_DIRECTONLY );
160586 extraFlags = enc & (SQLITE_DETERMINISTIC|SQLITE_DIRECTONLY|
160587 SQLITE_SUBTYPE|SQLITE_INNOCUOUS);
160588 enc &= (SQLITE_FUNC_ENCMASK|SQLITE_ANY);
160589
160590 /* The SQLITE_INNOCUOUS flag is the same bit as SQLITE_FUNC_UNSAFE. But
160591 ** the meaning is inverted. So flip the bit. */
160592 assert( SQLITE_FUNC_UNSAFE==SQLITE_INNOCUOUS );
160593 extraFlags ^= SQLITE_FUNC_UNSAFE;
160594
160595
160596 #ifndef SQLITE_OMIT_UTF16
160597 /* If SQLITE_UTF16 is specified as the encoding type, transform this
160598 ** to one of SQLITE_UTF16LE or SQLITE_UTF16BE using the
160599 ** SQLITE_UTF16NATIVE macro. SQLITE_UTF16 is not used internally.
@@ -159674,15 +160603,17 @@
160603 */
160604 if( enc==SQLITE_UTF16 ){
160605 enc = SQLITE_UTF16NATIVE;
160606 }else if( enc==SQLITE_ANY ){
160607 int rc;
160608 rc = sqlite3CreateFunc(db, zFunctionName, nArg,
160609 (SQLITE_UTF8|extraFlags)^SQLITE_FUNC_UNSAFE,
160610 pUserData, xSFunc, xStep, xFinal, xValue, xInverse, pDestructor);
160611 if( rc==SQLITE_OK ){
160612 rc = sqlite3CreateFunc(db, zFunctionName, nArg,
160613 (SQLITE_UTF16LE|extraFlags)^SQLITE_FUNC_UNSAFE,
160614 pUserData, xSFunc, xStep, xFinal, xValue, xInverse, pDestructor);
160615 }
160616 if( rc!=SQLITE_OK ){
160617 return rc;
160618 }
160619 enc = SQLITE_UTF16BE;
@@ -161018,11 +161949,13 @@
161949 db->nMaxSorterMmap = 0x7FFFFFFF;
161950 db->flags |= SQLITE_ShortColNames
161951 | SQLITE_EnableTrigger
161952 | SQLITE_EnableView
161953 | SQLITE_CacheSpill
161954 #if !defined(SQLITE_TRUSTED_SCHEMA) || SQLITE_TRUSTED_SCHEMA+0!=0
161955 | SQLITE_TrustedSchema
161956 #endif
161957 /* The SQLITE_DQS compile-time option determines the default settings
161958 ** for SQLITE_DBCONFIG_DQS_DDL and SQLITE_DBCONFIG_DQS_DML.
161959 **
161960 ** SQLITE_DQS SQLITE_DBCONFIG_DQS_DDL SQLITE_DBCONFIG_DQS_DML
161961 ** ---------- ----------------------- -----------------------
@@ -161247,10 +162180,17 @@
162180 #ifdef SQLITE_ENABLE_STMTVTAB
162181 if( !db->mallocFailed && rc==SQLITE_OK){
162182 rc = sqlite3StmtVtabInit(db);
162183 }
162184 #endif
162185
162186 #ifdef SQLITE_ENABLE_INTERNAL_FUNCTIONS
162187 /* Testing use only!!! The -DSQLITE_ENABLE_INTERNAL_FUNCTIONS=1 compile-time
162188 ** option gives access to internal functions by default.
162189 ** Testing use only!!! */
162190 db->mDbFlags |= DBFLAG_InternalFunc;
162191 #endif
162192
162193 /* -DSQLITE_DEFAULT_LOCKING_MODE=1 makes EXCLUSIVE the default locking
162194 ** mode. -DSQLITE_DEFAULT_LOCKING_MODE=0 make NORMAL the default locking
162195 ** mode. Doing nothing at all also makes NORMAL the default.
162196 */
@@ -161980,19 +162920,18 @@
162920 case SQLITE_TESTCTRL_LOCALTIME_FAULT: {
162921 sqlite3GlobalConfig.bLocaltimeFault = va_arg(ap, int);
162922 break;
162923 }
162924
162925 /* sqlite3_test_control(SQLITE_TESTCTRL_INTERNAL_FUNCTIONS, sqlite3*);
162926 **
162927 ** Toggle the ability to use internal functions on or off for
162928 ** the database connection given in the argument.
 
 
162929 */
162930 case SQLITE_TESTCTRL_INTERNAL_FUNCTIONS: {
162931 sqlite3 *db = va_arg(ap, sqlite3*);
162932 db->mDbFlags ^= DBFLAG_InternalFunc;
162933 break;
162934 }
162935
162936 /* sqlite3_test_control(SQLITE_TESTCTRL_NEVER_CORRUPT, int);
162937 **
@@ -173136,11 +174075,11 @@
174075 Fts3Hash *pHash,
174076 const char *zName
174077 ){
174078 int rc = SQLITE_OK;
174079 void *p = (void *)pHash;
174080 const int any = SQLITE_UTF8|SQLITE_DIRECTONLY;
174081
174082 #ifdef SQLITE_TEST
174083 char *zTest = 0;
174084 char *zTest2 = 0;
174085 void *pdb = (void *)db;
@@ -174208,11 +175147,11 @@
175147 ** of the oldest level in the db that contains at least ? segments. Or,
175148 ** if no level in the FTS index contains more than ? segments, the statement
175149 ** returns zero rows. */
175150 /* 28 */ "SELECT level, count(*) AS cnt FROM %Q.'%q_segdir' "
175151 " GROUP BY level HAVING cnt>=?"
175152 " ORDER BY (level %% 1024) ASC, 2 DESC LIMIT 1",
175153
175154 /* Estimate the upper limit on the number of leaf nodes in a new segment
175155 ** created by merging the oldest :2 segments from absolute level :1. See
175156 ** function sqlite3Fts3Incrmerge() for details. */
175157 /* 29 */ "SELECT 2 * total(1 + leaves_end_block - start_block) "
@@ -178804,12 +179743,18 @@
179743 sqlite3_int64 iHintAbsLevel = 0; /* Hint level */
179744 int nHintSeg = 0; /* Hint number of segments */
179745
179746 rc = fts3IncrmergeHintPop(&hint, &iHintAbsLevel, &nHintSeg);
179747 if( nSeg<0 || (iAbsLevel % nMod) >= (iHintAbsLevel % nMod) ){
179748 /* Based on the scan in the block above, it is known that there
179749 ** are no levels with a relative level smaller than that of
179750 ** iAbsLevel with more than nSeg segments, or if nSeg is -1,
179751 ** no levels with more than nMin segments. Use this to limit the
179752 ** value of nHintSeg to avoid a large memory allocation in case the
179753 ** merge-hint is corrupt*/
179754 iAbsLevel = iHintAbsLevel;
179755 nSeg = MIN(MAX(nMin,nSeg), nHintSeg);
179756 bUseHint = 1;
179757 bDirtyHint = 1;
179758 }else{
179759 /* This undoes the effect of the HintPop() above - so that no entry
179760 ** is removed from the hint blob. */
@@ -178818,11 +179763,11 @@
179763 }
179764
179765 /* If nSeg is less that zero, then there is no level with at least
179766 ** nMin segments and no hint in the %_stat table. No work to do.
179767 ** Exit early in this case. */
179768 if( nSeg<=0 ) break;
179769
179770 /* Open a cursor to iterate through the contents of the oldest nSeg
179771 ** indexes of absolute level iAbsLevel. If this cursor is opened using
179772 ** the 'hint' parameters, it is possible that there are less than nSeg
179773 ** segments available in level iAbsLevel. In this case, no work is
@@ -180205,11 +181150,11 @@
181150 if( rc==SQLITE_OK ){
181151
181152 /* Set the *pmSeen output variable. */
181153 for(i=0; i<nList; i++){
181154 if( sIter.aPhrase[i].pHead ){
181155 *pmSeen |= (u64)1 << (i%64);
181156 }
181157 }
181158
181159 /* Loop through all candidate snippets. Store the best snippet in
181160 ** *pFragment. Store its associated 'score' in iBestScore.
@@ -184272,10 +185217,11 @@
185217 "json HIDDEN,root HIDDEN)");
185218 if( rc==SQLITE_OK ){
185219 pNew = *ppVtab = sqlite3_malloc( sizeof(*pNew) );
185220 if( pNew==0 ) return SQLITE_NOMEM;
185221 memset(pNew, 0, sizeof(*pNew));
185222 sqlite3_vtab_config(db, SQLITE_VTAB_INNOCUOUS);
185223 }
185224 return rc;
185225 }
185226
185227 /* destructor for json_each virtual table */
@@ -184762,20 +185708,23 @@
185708 } aMod[] = {
185709 { "json_each", &jsonEachModule },
185710 { "json_tree", &jsonTreeModule },
185711 };
185712 #endif
185713 static const int enc =
185714 SQLITE_UTF8 |
185715 SQLITE_DETERMINISTIC |
185716 SQLITE_INNOCUOUS;
185717 for(i=0; i<sizeof(aFunc)/sizeof(aFunc[0]) && rc==SQLITE_OK; i++){
185718 rc = sqlite3_create_function(db, aFunc[i].zName, aFunc[i].nArg, enc,
 
185719 (void*)&aFunc[i].flag,
185720 aFunc[i].xFunc, 0, 0);
185721 }
185722 #ifndef SQLITE_OMIT_WINDOWFUNC
185723 for(i=0; i<sizeof(aAgg)/sizeof(aAgg[0]) && rc==SQLITE_OK; i++){
185724 rc = sqlite3_create_window_function(db, aAgg[i].zName, aAgg[i].nArg,
185725 SQLITE_SUBTYPE | enc, 0,
185726 aAgg[i].xStep, aAgg[i].xFinal,
185727 aAgg[i].xValue, jsonGroupInverse, 0);
185728 }
185729 #endif
185730 #ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -190941,18 +191890,24 @@
191890 } aAgg[] = {
191891 { geopolyBBoxStep, geopolyBBoxFinal, "geopoly_group_bbox" },
191892 };
191893 int i;
191894 for(i=0; i<sizeof(aFunc)/sizeof(aFunc[0]) && rc==SQLITE_OK; i++){
191895 int enc;
191896 if( aFunc[i].bPure ){
191897 enc = SQLITE_UTF8|SQLITE_DETERMINISTIC|SQLITE_INNOCUOUS;
191898 }else{
191899 enc = SQLITE_UTF8|SQLITE_DIRECTONLY;
191900 }
191901 rc = sqlite3_create_function(db, aFunc[i].zName, aFunc[i].nArg,
191902 enc, 0,
191903 aFunc[i].xFunc, 0, 0);
191904 }
191905 for(i=0; i<sizeof(aAgg)/sizeof(aAgg[0]) && rc==SQLITE_OK; i++){
191906 rc = sqlite3_create_function(db, aAgg[i].zName, 1,
191907 SQLITE_UTF8|SQLITE_DETERMINISTIC|SQLITE_INNOCUOUS, 0,
191908 0, aAgg[i].xStep, aAgg[i].xFinal);
191909 }
191910 if( rc==SQLITE_OK ){
191911 rc = sqlite3_create_module_v2(db, "geopoly", &geopolyModule, 0, 0);
191912 }
191913 return rc;
@@ -191638,30 +192593,31 @@
192593
192594 /*
192595 ** Register the ICU extension functions with database db.
192596 */
192597 SQLITE_PRIVATE int sqlite3IcuInit(sqlite3 *db){
192598 # define SQLITEICU_EXTRAFLAGS (SQLITE_DETERMINISTIC|SQLITE_INNOCUOUS)
192599 static const struct IcuScalar {
192600 const char *zName; /* Function name */
192601 unsigned char nArg; /* Number of arguments */
192602 unsigned int enc; /* Optimal text encoding */
192603 unsigned char iContext; /* sqlite3_user_data() context */
192604 void (*xFunc)(sqlite3_context*,int,sqlite3_value**);
192605 } scalars[] = {
192606 {"icu_load_collation",2,SQLITE_UTF8|SQLITE_DIRECTONLY,1, icuLoadCollation},
192607 #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_ICU)
192608 {"regexp", 2, SQLITE_ANY|SQLITEICU_EXTRAFLAGS, 0, icuRegexpFunc},
192609 {"lower", 1, SQLITE_UTF16|SQLITEICU_EXTRAFLAGS, 0, icuCaseFunc16},
192610 {"lower", 2, SQLITE_UTF16|SQLITEICU_EXTRAFLAGS, 0, icuCaseFunc16},
192611 {"upper", 1, SQLITE_UTF16|SQLITEICU_EXTRAFLAGS, 1, icuCaseFunc16},
192612 {"upper", 2, SQLITE_UTF16|SQLITEICU_EXTRAFLAGS, 1, icuCaseFunc16},
192613 {"lower", 1, SQLITE_UTF8|SQLITEICU_EXTRAFLAGS, 0, icuCaseFunc16},
192614 {"lower", 2, SQLITE_UTF8|SQLITEICU_EXTRAFLAGS, 0, icuCaseFunc16},
192615 {"upper", 1, SQLITE_UTF8|SQLITEICU_EXTRAFLAGS, 1, icuCaseFunc16},
192616 {"upper", 2, SQLITE_UTF8|SQLITEICU_EXTRAFLAGS, 1, icuCaseFunc16},
192617 {"like", 2, SQLITE_UTF8|SQLITEICU_EXTRAFLAGS, 0, icuLikeFunc},
192618 {"like", 3, SQLITE_UTF8|SQLITEICU_EXTRAFLAGS, 0, icuLikeFunc},
192619 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_ICU) */
192620 };
192621 int rc = SQLITE_OK;
192622 int i;
192623
@@ -198070,10 +199026,11 @@
199026 return SQLITE_ERROR;
199027 }
199028 }else{
199029 iDb = 0;
199030 }
199031 sqlite3_vtab_config(db, SQLITE_VTAB_DIRECTONLY);
199032 rc = sqlite3_declare_vtab(db, zDbstatSchema);
199033 if( rc==SQLITE_OK ){
199034 pTab = (StatTable *)sqlite3_malloc64(sizeof(StatTable));
199035 if( pTab==0 ) rc = SQLITE_NOMEM_BKPT;
199036 }
@@ -198140,21 +199097,18 @@
199097 }
199098 }
199099 i = 0;
199100 if( iSchema>=0 ){
199101 pIdxInfo->aConstraintUsage[iSchema].argvIndex = ++i;
 
199102 pIdxInfo->idxNum |= 0x01;
199103 }
199104 if( iName>=0 ){
199105 pIdxInfo->aConstraintUsage[iName].argvIndex = ++i;
 
199106 pIdxInfo->idxNum |= 0x02;
199107 }
199108 if( iAgg>=0 ){
199109 pIdxInfo->aConstraintUsage[iAgg].argvIndex = ++i;
 
199110 pIdxInfo->idxNum |= 0x04;
199111 }
199112 pIdxInfo->estimatedCost = 1.0;
199113
199114 /* Records are always returned in ascending order of (name, path).
@@ -198606,13 +199560,13 @@
199560 if( idxNum & 0x01 ){
199561 /* schema=? constraint is present. Get its value */
199562 const char *zDbase = (const char*)sqlite3_value_text(argv[iArg++]);
199563 pCsr->iDb = sqlite3FindDbName(pTab->db, zDbase);
199564 if( pCsr->iDb<0 ){
199565 pCsr->iDb = 0;
199566 pCsr->isEof = 1;
199567 return SQLITE_OK;
199568 }
199569 }else{
199570 pCsr->iDb = pTab->iDb;
199571 }
199572 if( idxNum & 0x02 ){
@@ -198831,10 +199785,11 @@
199785 char **pzErr
199786 ){
199787 DbpageTable *pTab = 0;
199788 int rc = SQLITE_OK;
199789
199790 sqlite3_vtab_config(db, SQLITE_VTAB_DIRECTONLY);
199791 rc = sqlite3_declare_vtab(db,
199792 "CREATE TABLE x(pgno INTEGER PRIMARY KEY, data BLOB, schema HIDDEN)");
199793 if( rc==SQLITE_OK ){
199794 pTab = (DbpageTable *)sqlite3_malloc64(sizeof(DbpageTable));
199795 if( pTab==0 ) rc = SQLITE_NOMEM_BKPT;
@@ -220005,11 +220960,14 @@
220960 break;
220961
220962 case FTS5_ROLLBACKTO:
220963 assert( p->ts.eState==1 );
220964 assert( iSavepoint>=-1 );
220965 /* The following assert() can fail if another vtab strikes an error
220966 ** within an xSavepoint() call then SQLite calls xRollbackTo() - without
220967 ** having called xSavepoint() on this vtab. */
220968 /* assert( iSavepoint<=p->ts.iSavepoint ); */
220969 p->ts.iSavepoint = iSavepoint;
220970 break;
220971 }
220972 }
220973 #else
@@ -222455,11 +223413,11 @@
223413 int nArg, /* Number of args */
223414 sqlite3_value **apUnused /* Function arguments */
223415 ){
223416 assert( nArg==0 );
223417 UNUSED_PARAM2(nArg, apUnused);
223418 sqlite3_result_text(pCtx, "fts5: 2020-01-09 20:44:37 5720924cb07766cd54fb042da58f4b4acf12b60029fba86a23a606ad0d0f7c68", -1, SQLITE_TRANSIENT);
223419 }
223420
223421 /*
223422 ** Return true if zName is the extension on one of the shadow tables used
223423 ** by this module.
@@ -227228,12 +228186,12 @@
228186 }
228187 #endif /* SQLITE_CORE */
228188 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
228189
228190 /************** End of stmt.c ************************************************/
228191 #if __LINE__!=228191
228192 #undef SQLITE_SOURCE_ID
228193 #define SQLITE_SOURCE_ID "2020-01-09 20:44:37 5720924cb07766cd54fb042da58f4b4acf12b60029fba86a23a606ad0d0falt2"
228194 #endif
228195 /* Return the source-id for this library */
228196 SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
228197 /************************** End of sqlite3.c ******************************/
228198
+69 -10
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -123,11 +123,11 @@
123123
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124124
** [sqlite_version()] and [sqlite_source_id()].
125125
*/
126126
#define SQLITE_VERSION "3.31.0"
127127
#define SQLITE_VERSION_NUMBER 3031000
128
-#define SQLITE_SOURCE_ID "2019-12-26 01:10:17 f482a4cdfa768941e22c399de8ec29a55e729529eeae86d3832077ad1bef22f3"
128
+#define SQLITE_SOURCE_ID "2020-01-09 20:44:37 5720924cb07766cd54fb042da58f4b4acf12b60029fba86a23a606ad0d0f7c68"
129129
130130
/*
131131
** CAPI3REF: Run-Time Library Version Numbers
132132
** KEYWORDS: sqlite3_version sqlite3_sourceid
133133
**
@@ -534,10 +534,11 @@
534534
#define SQLITE_CONSTRAINT_PRIMARYKEY (SQLITE_CONSTRAINT | (6<<8))
535535
#define SQLITE_CONSTRAINT_TRIGGER (SQLITE_CONSTRAINT | (7<<8))
536536
#define SQLITE_CONSTRAINT_UNIQUE (SQLITE_CONSTRAINT | (8<<8))
537537
#define SQLITE_CONSTRAINT_VTAB (SQLITE_CONSTRAINT | (9<<8))
538538
#define SQLITE_CONSTRAINT_ROWID (SQLITE_CONSTRAINT |(10<<8))
539
+#define SQLITE_CONSTRAINT_PINNED (SQLITE_CONSTRAINT |(11<<8))
539540
#define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8))
540541
#define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8))
541542
#define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8))
542543
#define SQLITE_AUTH_USER (SQLITE_AUTH | (1<<8))
543544
#define SQLITE_OK_LOAD_PERMANENTLY (SQLITE_OK | (1<<8))
@@ -2261,10 +2262,29 @@
22612262
** the legacy [double-quoted string literal] misfeature for DDL statements,
22622263
** such as CREATE TABLE and CREATE INDEX. The
22632264
** default value of this setting is determined by the [-DSQLITE_DQS]
22642265
** compile-time option.
22652266
** </dd>
2267
+**
2268
+** [[SQLITE_DBCONFIG_TRUSTED_SCHEMA]]
2269
+** <dt>SQLITE_DBCONFIG_TRUSTED_SCHEMA</td>
2270
+** <dd>The SQLITE_DBCONFIG_TRUSTED_SCHEMA option tells the SQLite to
2271
+** assume that database schemas are untainted by malicious content.
2272
+** When the SQLITE_DBCONFIG_TRUSTED_SCHEMA option is disabled, SQLite
2273
+** takes additional defensive steps to protect the application from harm
2274
+** including, but not limited to, the following:
2275
+** <ul>
2276
+** <li> Prohibit the use of SQL functions inside triggers, views,
2277
+** CHECK constraints, DEFAULT VALUEs, index definitions, and/or
2278
+** generated columns unless those functions are tagged
2279
+** with [SQLITE_INNOCUOUS].
2280
+** <li> Pohibit the use of virtual tables inside of triggers and/or views
2281
+** unless those virtual tables are tagged with [SQLITE_VTAB_INNOCUOUS].
2282
+** </ul>
2283
+** This setting defaults to "on" for legacy compatibility, however
2284
+** all applications are advised to turn it off if possible.
2285
+** </dd>
22662286
**
22672287
** [[SQLITE_DBCONFIG_LEGACY_FILE_FORMAT]]
22682288
** <dt>SQLITE_DBCONFIG_LEGACY_FILE_FORMAT</td>
22692289
** <dd>The SQLITE_DBCONFIG_LEGACY_FILE_FORMAT option activates or deactivates
22702290
** the legacy file format flag. When activated, this flag causes all newly
@@ -2302,11 +2322,12 @@
23022322
#define SQLITE_DBCONFIG_LEGACY_ALTER_TABLE 1012 /* int int* */
23032323
#define SQLITE_DBCONFIG_DQS_DML 1013 /* int int* */
23042324
#define SQLITE_DBCONFIG_DQS_DDL 1014 /* int int* */
23052325
#define SQLITE_DBCONFIG_ENABLE_VIEW 1015 /* int int* */
23062326
#define SQLITE_DBCONFIG_LEGACY_FILE_FORMAT 1016 /* int int* */
2307
-#define SQLITE_DBCONFIG_MAX 1016 /* Largest DBCONFIG */
2327
+#define SQLITE_DBCONFIG_TRUSTED_SCHEMA 1017 /* int int* */
2328
+#define SQLITE_DBCONFIG_MAX 1017 /* Largest DBCONFIG */
23082329
23092330
/*
23102331
** CAPI3REF: Enable Or Disable Extended Result Codes
23112332
** METHOD: sqlite3
23122333
**
@@ -4993,16 +5014,30 @@
49935014
** [SQLITE_UTF8 | preferred text encoding] as the fourth argument
49945015
** to [sqlite3_create_function()], [sqlite3_create_function16()], or
49955016
** [sqlite3_create_function_v2()].
49965017
**
49975018
** The SQLITE_DETERMINISTIC flag means that the new function always gives
4998
-** the same output when the input parameters are the same. The abs() function
4999
-** is deterministic, for example, but randomblob() is not. Functions must
5019
+** the same output when the input parameters are the same.
5020
+** The [abs|abs() function] is deterministic, for example, but
5021
+** [randomblob|randomblob()] is not. Functions must
50005022
** be deterministic in order to be used in certain contexts such as
50015023
** [CHECK constraints] or [generated columns]. SQLite might also optimize
50025024
** deterministic functions by factoring them out of inner loops.
50035025
**
5026
+** The SQLITE_INNOCUOUS flag means that the new function is unlikely
5027
+** to cause problems even if misused. An innocuous function should have
5028
+** no side effects and consume few resources. The [abs|abs() function]
5029
+** is an example of an innocuous function.
5030
+** The [load_extension() SQL function] is not innocuous because of its
5031
+** side effects. Some heightened security settings
5032
+** ([SQLITE_DBCONFIG_UNSAFE_FUNC_IN_VIEW])
5033
+** disable the use of SQLlfunctions inside views and triggers unless
5034
+** the function is tagged with SQLITE_INNOCUOUS. Most built-in functions
5035
+** are innocuous. Developers are advised to avoid using the
5036
+** SQLITE_INNOCUOUS flag for application-defined functions unless the
5037
+** function is specifically intended for use inside of views and triggers.
5038
+**
50045039
** The SQLITE_DIRECTONLY flag means that the function may only be invoked
50055040
** from top-level SQL, and cannot be used in VIEWs or TRIGGERs. This is
50065041
** a security feature which is recommended for all
50075042
** [application-defined SQL functions] that have side-effects. This flag
50085043
** prevents an attacker from adding triggers and views to a schema then
@@ -5018,10 +5053,11 @@
50185053
** sqlite3_value_subtype() will always return 0).
50195054
*/
50205055
#define SQLITE_DETERMINISTIC 0x000000800
50215056
#define SQLITE_DIRECTONLY 0x000080000
50225057
#define SQLITE_SUBTYPE 0x000100000
5058
+#define SQLITE_INNOCUOUS 0x000200000
50235059
50245060
/*
50255061
** CAPI3REF: Deprecated Functions
50265062
** DEPRECATED
50275063
**
@@ -5549,31 +5585,32 @@
55495585
** <li> [SQLITE_UTF16BE],
55505586
** <li> [SQLITE_UTF16], or
55515587
** <li> [SQLITE_UTF16_ALIGNED].
55525588
** </ul>)^
55535589
** ^The eTextRep argument determines the encoding of strings passed
5554
-** to the collating function callback, xCallback.
5590
+** to the collating function callback, xCompare.
55555591
** ^The [SQLITE_UTF16] and [SQLITE_UTF16_ALIGNED] values for eTextRep
55565592
** force strings to be UTF16 with native byte order.
55575593
** ^The [SQLITE_UTF16_ALIGNED] value for eTextRep forces strings to begin
55585594
** on an even byte address.
55595595
**
55605596
** ^The fourth argument, pArg, is an application data pointer that is passed
55615597
** through as the first argument to the collating function callback.
55625598
**
5563
-** ^The fifth argument, xCallback, is a pointer to the collating function.
5599
+** ^The fifth argument, xCompare, is a pointer to the collating function.
55645600
** ^Multiple collating functions can be registered using the same name but
55655601
** with different eTextRep parameters and SQLite will use whichever
55665602
** function requires the least amount of data transformation.
5567
-** ^If the xCallback argument is NULL then the collating function is
5603
+** ^If the xCompare argument is NULL then the collating function is
55685604
** deleted. ^When all collating functions having the same name are deleted,
55695605
** that collation is no longer usable.
55705606
**
55715607
** ^The collating function callback is invoked with a copy of the pArg
55725608
** application data pointer and with two strings in the encoding specified
5573
-** by the eTextRep argument. The collating function must return an
5574
-** integer that is negative, zero, or positive
5609
+** by the eTextRep argument. The two integer parameters to the collating
5610
+** function callback are the length of the two strings, in bytes. The collating
5611
+** function must return an integer that is negative, zero, or positive
55755612
** if the first string is less than, equal to, or greater than the second,
55765613
** respectively. A collating function must always return the same answer
55775614
** given the same inputs. If two or more collating functions are registered
55785615
** to the same collation name (using different eTextRep values) then all
55795616
** must give an equivalent answer when invoked with equivalent strings.
@@ -8865,11 +8902,11 @@
88658902
** [sqlite3_vtab_config()] interface that [virtual table] implementations
88668903
** can use to customize and optimize their behavior.
88678904
**
88688905
** <dl>
88698906
** [[SQLITE_VTAB_CONSTRAINT_SUPPORT]]
8870
-** <dt>SQLITE_VTAB_CONSTRAINT_SUPPORT
8907
+** <dt>SQLITE_VTAB_CONSTRAINT_SUPPORT</dt>
88718908
** <dd>Calls of the form
88728909
** [sqlite3_vtab_config](db,SQLITE_VTAB_CONSTRAINT_SUPPORT,X) are supported,
88738910
** where X is an integer. If X is zero, then the [virtual table] whose
88748911
** [xCreate] or [xConnect] method invoked [sqlite3_vtab_config()] does not
88758912
** support constraints. In this configuration (which is the default) if
@@ -8894,13 +8931,35 @@
88948931
** CONFLICT policy is REPLACE, the virtual table implementation should
88958932
** silently replace the appropriate rows within the xUpdate callback and
88968933
** return SQLITE_OK. Or, if this is not possible, it may return
88978934
** SQLITE_CONSTRAINT, in which case SQLite falls back to OR ABORT
88988935
** constraint handling.
8936
+** </dd>
8937
+**
8938
+** [[SQLITE_VTAB_INNOCUOUS]]<dt>SQLITE_VTAB_INNOCUOUS</dt>
8939
+** <dd>Calls of the form
8940
+** [sqlite3_vtab_config](db,SQLITE_VTAB_INNOCUOUS) from within the
8941
+** the [xConnect] or [xCreate] methods of a [virtual table] implmentation
8942
+** identify that virtual table as being safe to use from within triggers
8943
+** and views. Conceptually, the SQLITE_VTAB_INNOCUOUS tag means that the
8944
+** virtual table can do no serious harm even if it is controlled by a
8945
+** malicious hacker. Developers should avoid setting the SQLITE_VTAB_INNOCUOUS
8946
+** flag unless absolutely necessary.
8947
+** </dd>
8948
+**
8949
+** [[SQLITE_VTAB_DIRECTONLY]]<dt>SQLITE_VTAB_DIRECTONLY</dt>
8950
+** <dd>Calls of the form
8951
+** [sqlite3_vtab_config](db,SQLITE_VTAB_DIRECTONLY) from within the
8952
+** the [xConnect] or [xCreate] methods of a [virtual table] implmentation
8953
+** prohibits that virtual table from being used from within triggers and
8954
+** views.
8955
+** </dd>
88998956
** </dl>
89008957
*/
89018958
#define SQLITE_VTAB_CONSTRAINT_SUPPORT 1
8959
+#define SQLITE_VTAB_INNOCUOUS 2
8960
+#define SQLITE_VTAB_DIRECTONLY 3
89028961
89038962
/*
89048963
** CAPI3REF: Determine The Virtual Table Conflict Policy
89058964
**
89068965
** This function may only be called from within a call to the [xUpdate] method
89078966
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -123,11 +123,11 @@
123 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124 ** [sqlite_version()] and [sqlite_source_id()].
125 */
126 #define SQLITE_VERSION "3.31.0"
127 #define SQLITE_VERSION_NUMBER 3031000
128 #define SQLITE_SOURCE_ID "2019-12-26 01:10:17 f482a4cdfa768941e22c399de8ec29a55e729529eeae86d3832077ad1bef22f3"
129
130 /*
131 ** CAPI3REF: Run-Time Library Version Numbers
132 ** KEYWORDS: sqlite3_version sqlite3_sourceid
133 **
@@ -534,10 +534,11 @@
534 #define SQLITE_CONSTRAINT_PRIMARYKEY (SQLITE_CONSTRAINT | (6<<8))
535 #define SQLITE_CONSTRAINT_TRIGGER (SQLITE_CONSTRAINT | (7<<8))
536 #define SQLITE_CONSTRAINT_UNIQUE (SQLITE_CONSTRAINT | (8<<8))
537 #define SQLITE_CONSTRAINT_VTAB (SQLITE_CONSTRAINT | (9<<8))
538 #define SQLITE_CONSTRAINT_ROWID (SQLITE_CONSTRAINT |(10<<8))
 
539 #define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8))
540 #define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8))
541 #define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8))
542 #define SQLITE_AUTH_USER (SQLITE_AUTH | (1<<8))
543 #define SQLITE_OK_LOAD_PERMANENTLY (SQLITE_OK | (1<<8))
@@ -2261,10 +2262,29 @@
2261 ** the legacy [double-quoted string literal] misfeature for DDL statements,
2262 ** such as CREATE TABLE and CREATE INDEX. The
2263 ** default value of this setting is determined by the [-DSQLITE_DQS]
2264 ** compile-time option.
2265 ** </dd>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2266 **
2267 ** [[SQLITE_DBCONFIG_LEGACY_FILE_FORMAT]]
2268 ** <dt>SQLITE_DBCONFIG_LEGACY_FILE_FORMAT</td>
2269 ** <dd>The SQLITE_DBCONFIG_LEGACY_FILE_FORMAT option activates or deactivates
2270 ** the legacy file format flag. When activated, this flag causes all newly
@@ -2302,11 +2322,12 @@
2302 #define SQLITE_DBCONFIG_LEGACY_ALTER_TABLE 1012 /* int int* */
2303 #define SQLITE_DBCONFIG_DQS_DML 1013 /* int int* */
2304 #define SQLITE_DBCONFIG_DQS_DDL 1014 /* int int* */
2305 #define SQLITE_DBCONFIG_ENABLE_VIEW 1015 /* int int* */
2306 #define SQLITE_DBCONFIG_LEGACY_FILE_FORMAT 1016 /* int int* */
2307 #define SQLITE_DBCONFIG_MAX 1016 /* Largest DBCONFIG */
 
2308
2309 /*
2310 ** CAPI3REF: Enable Or Disable Extended Result Codes
2311 ** METHOD: sqlite3
2312 **
@@ -4993,16 +5014,30 @@
4993 ** [SQLITE_UTF8 | preferred text encoding] as the fourth argument
4994 ** to [sqlite3_create_function()], [sqlite3_create_function16()], or
4995 ** [sqlite3_create_function_v2()].
4996 **
4997 ** The SQLITE_DETERMINISTIC flag means that the new function always gives
4998 ** the same output when the input parameters are the same. The abs() function
4999 ** is deterministic, for example, but randomblob() is not. Functions must
 
5000 ** be deterministic in order to be used in certain contexts such as
5001 ** [CHECK constraints] or [generated columns]. SQLite might also optimize
5002 ** deterministic functions by factoring them out of inner loops.
5003 **
 
 
 
 
 
 
 
 
 
 
 
 
 
5004 ** The SQLITE_DIRECTONLY flag means that the function may only be invoked
5005 ** from top-level SQL, and cannot be used in VIEWs or TRIGGERs. This is
5006 ** a security feature which is recommended for all
5007 ** [application-defined SQL functions] that have side-effects. This flag
5008 ** prevents an attacker from adding triggers and views to a schema then
@@ -5018,10 +5053,11 @@
5018 ** sqlite3_value_subtype() will always return 0).
5019 */
5020 #define SQLITE_DETERMINISTIC 0x000000800
5021 #define SQLITE_DIRECTONLY 0x000080000
5022 #define SQLITE_SUBTYPE 0x000100000
 
5023
5024 /*
5025 ** CAPI3REF: Deprecated Functions
5026 ** DEPRECATED
5027 **
@@ -5549,31 +5585,32 @@
5549 ** <li> [SQLITE_UTF16BE],
5550 ** <li> [SQLITE_UTF16], or
5551 ** <li> [SQLITE_UTF16_ALIGNED].
5552 ** </ul>)^
5553 ** ^The eTextRep argument determines the encoding of strings passed
5554 ** to the collating function callback, xCallback.
5555 ** ^The [SQLITE_UTF16] and [SQLITE_UTF16_ALIGNED] values for eTextRep
5556 ** force strings to be UTF16 with native byte order.
5557 ** ^The [SQLITE_UTF16_ALIGNED] value for eTextRep forces strings to begin
5558 ** on an even byte address.
5559 **
5560 ** ^The fourth argument, pArg, is an application data pointer that is passed
5561 ** through as the first argument to the collating function callback.
5562 **
5563 ** ^The fifth argument, xCallback, is a pointer to the collating function.
5564 ** ^Multiple collating functions can be registered using the same name but
5565 ** with different eTextRep parameters and SQLite will use whichever
5566 ** function requires the least amount of data transformation.
5567 ** ^If the xCallback argument is NULL then the collating function is
5568 ** deleted. ^When all collating functions having the same name are deleted,
5569 ** that collation is no longer usable.
5570 **
5571 ** ^The collating function callback is invoked with a copy of the pArg
5572 ** application data pointer and with two strings in the encoding specified
5573 ** by the eTextRep argument. The collating function must return an
5574 ** integer that is negative, zero, or positive
 
5575 ** if the first string is less than, equal to, or greater than the second,
5576 ** respectively. A collating function must always return the same answer
5577 ** given the same inputs. If two or more collating functions are registered
5578 ** to the same collation name (using different eTextRep values) then all
5579 ** must give an equivalent answer when invoked with equivalent strings.
@@ -8865,11 +8902,11 @@
8865 ** [sqlite3_vtab_config()] interface that [virtual table] implementations
8866 ** can use to customize and optimize their behavior.
8867 **
8868 ** <dl>
8869 ** [[SQLITE_VTAB_CONSTRAINT_SUPPORT]]
8870 ** <dt>SQLITE_VTAB_CONSTRAINT_SUPPORT
8871 ** <dd>Calls of the form
8872 ** [sqlite3_vtab_config](db,SQLITE_VTAB_CONSTRAINT_SUPPORT,X) are supported,
8873 ** where X is an integer. If X is zero, then the [virtual table] whose
8874 ** [xCreate] or [xConnect] method invoked [sqlite3_vtab_config()] does not
8875 ** support constraints. In this configuration (which is the default) if
@@ -8894,13 +8931,35 @@
8894 ** CONFLICT policy is REPLACE, the virtual table implementation should
8895 ** silently replace the appropriate rows within the xUpdate callback and
8896 ** return SQLITE_OK. Or, if this is not possible, it may return
8897 ** SQLITE_CONSTRAINT, in which case SQLite falls back to OR ABORT
8898 ** constraint handling.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8899 ** </dl>
8900 */
8901 #define SQLITE_VTAB_CONSTRAINT_SUPPORT 1
 
 
8902
8903 /*
8904 ** CAPI3REF: Determine The Virtual Table Conflict Policy
8905 **
8906 ** This function may only be called from within a call to the [xUpdate] method
8907
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -123,11 +123,11 @@
123 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124 ** [sqlite_version()] and [sqlite_source_id()].
125 */
126 #define SQLITE_VERSION "3.31.0"
127 #define SQLITE_VERSION_NUMBER 3031000
128 #define SQLITE_SOURCE_ID "2020-01-09 20:44:37 5720924cb07766cd54fb042da58f4b4acf12b60029fba86a23a606ad0d0f7c68"
129
130 /*
131 ** CAPI3REF: Run-Time Library Version Numbers
132 ** KEYWORDS: sqlite3_version sqlite3_sourceid
133 **
@@ -534,10 +534,11 @@
534 #define SQLITE_CONSTRAINT_PRIMARYKEY (SQLITE_CONSTRAINT | (6<<8))
535 #define SQLITE_CONSTRAINT_TRIGGER (SQLITE_CONSTRAINT | (7<<8))
536 #define SQLITE_CONSTRAINT_UNIQUE (SQLITE_CONSTRAINT | (8<<8))
537 #define SQLITE_CONSTRAINT_VTAB (SQLITE_CONSTRAINT | (9<<8))
538 #define SQLITE_CONSTRAINT_ROWID (SQLITE_CONSTRAINT |(10<<8))
539 #define SQLITE_CONSTRAINT_PINNED (SQLITE_CONSTRAINT |(11<<8))
540 #define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8))
541 #define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8))
542 #define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8))
543 #define SQLITE_AUTH_USER (SQLITE_AUTH | (1<<8))
544 #define SQLITE_OK_LOAD_PERMANENTLY (SQLITE_OK | (1<<8))
@@ -2261,10 +2262,29 @@
2262 ** the legacy [double-quoted string literal] misfeature for DDL statements,
2263 ** such as CREATE TABLE and CREATE INDEX. The
2264 ** default value of this setting is determined by the [-DSQLITE_DQS]
2265 ** compile-time option.
2266 ** </dd>
2267 **
2268 ** [[SQLITE_DBCONFIG_TRUSTED_SCHEMA]]
2269 ** <dt>SQLITE_DBCONFIG_TRUSTED_SCHEMA</td>
2270 ** <dd>The SQLITE_DBCONFIG_TRUSTED_SCHEMA option tells the SQLite to
2271 ** assume that database schemas are untainted by malicious content.
2272 ** When the SQLITE_DBCONFIG_TRUSTED_SCHEMA option is disabled, SQLite
2273 ** takes additional defensive steps to protect the application from harm
2274 ** including, but not limited to, the following:
2275 ** <ul>
2276 ** <li> Prohibit the use of SQL functions inside triggers, views,
2277 ** CHECK constraints, DEFAULT VALUEs, index definitions, and/or
2278 ** generated columns unless those functions are tagged
2279 ** with [SQLITE_INNOCUOUS].
2280 ** <li> Pohibit the use of virtual tables inside of triggers and/or views
2281 ** unless those virtual tables are tagged with [SQLITE_VTAB_INNOCUOUS].
2282 ** </ul>
2283 ** This setting defaults to "on" for legacy compatibility, however
2284 ** all applications are advised to turn it off if possible.
2285 ** </dd>
2286 **
2287 ** [[SQLITE_DBCONFIG_LEGACY_FILE_FORMAT]]
2288 ** <dt>SQLITE_DBCONFIG_LEGACY_FILE_FORMAT</td>
2289 ** <dd>The SQLITE_DBCONFIG_LEGACY_FILE_FORMAT option activates or deactivates
2290 ** the legacy file format flag. When activated, this flag causes all newly
@@ -2302,11 +2322,12 @@
2322 #define SQLITE_DBCONFIG_LEGACY_ALTER_TABLE 1012 /* int int* */
2323 #define SQLITE_DBCONFIG_DQS_DML 1013 /* int int* */
2324 #define SQLITE_DBCONFIG_DQS_DDL 1014 /* int int* */
2325 #define SQLITE_DBCONFIG_ENABLE_VIEW 1015 /* int int* */
2326 #define SQLITE_DBCONFIG_LEGACY_FILE_FORMAT 1016 /* int int* */
2327 #define SQLITE_DBCONFIG_TRUSTED_SCHEMA 1017 /* int int* */
2328 #define SQLITE_DBCONFIG_MAX 1017 /* Largest DBCONFIG */
2329
2330 /*
2331 ** CAPI3REF: Enable Or Disable Extended Result Codes
2332 ** METHOD: sqlite3
2333 **
@@ -4993,16 +5014,30 @@
5014 ** [SQLITE_UTF8 | preferred text encoding] as the fourth argument
5015 ** to [sqlite3_create_function()], [sqlite3_create_function16()], or
5016 ** [sqlite3_create_function_v2()].
5017 **
5018 ** The SQLITE_DETERMINISTIC flag means that the new function always gives
5019 ** the same output when the input parameters are the same.
5020 ** The [abs|abs() function] is deterministic, for example, but
5021 ** [randomblob|randomblob()] is not. Functions must
5022 ** be deterministic in order to be used in certain contexts such as
5023 ** [CHECK constraints] or [generated columns]. SQLite might also optimize
5024 ** deterministic functions by factoring them out of inner loops.
5025 **
5026 ** The SQLITE_INNOCUOUS flag means that the new function is unlikely
5027 ** to cause problems even if misused. An innocuous function should have
5028 ** no side effects and consume few resources. The [abs|abs() function]
5029 ** is an example of an innocuous function.
5030 ** The [load_extension() SQL function] is not innocuous because of its
5031 ** side effects. Some heightened security settings
5032 ** ([SQLITE_DBCONFIG_UNSAFE_FUNC_IN_VIEW])
5033 ** disable the use of SQLlfunctions inside views and triggers unless
5034 ** the function is tagged with SQLITE_INNOCUOUS. Most built-in functions
5035 ** are innocuous. Developers are advised to avoid using the
5036 ** SQLITE_INNOCUOUS flag for application-defined functions unless the
5037 ** function is specifically intended for use inside of views and triggers.
5038 **
5039 ** The SQLITE_DIRECTONLY flag means that the function may only be invoked
5040 ** from top-level SQL, and cannot be used in VIEWs or TRIGGERs. This is
5041 ** a security feature which is recommended for all
5042 ** [application-defined SQL functions] that have side-effects. This flag
5043 ** prevents an attacker from adding triggers and views to a schema then
@@ -5018,10 +5053,11 @@
5053 ** sqlite3_value_subtype() will always return 0).
5054 */
5055 #define SQLITE_DETERMINISTIC 0x000000800
5056 #define SQLITE_DIRECTONLY 0x000080000
5057 #define SQLITE_SUBTYPE 0x000100000
5058 #define SQLITE_INNOCUOUS 0x000200000
5059
5060 /*
5061 ** CAPI3REF: Deprecated Functions
5062 ** DEPRECATED
5063 **
@@ -5549,31 +5585,32 @@
5585 ** <li> [SQLITE_UTF16BE],
5586 ** <li> [SQLITE_UTF16], or
5587 ** <li> [SQLITE_UTF16_ALIGNED].
5588 ** </ul>)^
5589 ** ^The eTextRep argument determines the encoding of strings passed
5590 ** to the collating function callback, xCompare.
5591 ** ^The [SQLITE_UTF16] and [SQLITE_UTF16_ALIGNED] values for eTextRep
5592 ** force strings to be UTF16 with native byte order.
5593 ** ^The [SQLITE_UTF16_ALIGNED] value for eTextRep forces strings to begin
5594 ** on an even byte address.
5595 **
5596 ** ^The fourth argument, pArg, is an application data pointer that is passed
5597 ** through as the first argument to the collating function callback.
5598 **
5599 ** ^The fifth argument, xCompare, is a pointer to the collating function.
5600 ** ^Multiple collating functions can be registered using the same name but
5601 ** with different eTextRep parameters and SQLite will use whichever
5602 ** function requires the least amount of data transformation.
5603 ** ^If the xCompare argument is NULL then the collating function is
5604 ** deleted. ^When all collating functions having the same name are deleted,
5605 ** that collation is no longer usable.
5606 **
5607 ** ^The collating function callback is invoked with a copy of the pArg
5608 ** application data pointer and with two strings in the encoding specified
5609 ** by the eTextRep argument. The two integer parameters to the collating
5610 ** function callback are the length of the two strings, in bytes. The collating
5611 ** function must return an integer that is negative, zero, or positive
5612 ** if the first string is less than, equal to, or greater than the second,
5613 ** respectively. A collating function must always return the same answer
5614 ** given the same inputs. If two or more collating functions are registered
5615 ** to the same collation name (using different eTextRep values) then all
5616 ** must give an equivalent answer when invoked with equivalent strings.
@@ -8865,11 +8902,11 @@
8902 ** [sqlite3_vtab_config()] interface that [virtual table] implementations
8903 ** can use to customize and optimize their behavior.
8904 **
8905 ** <dl>
8906 ** [[SQLITE_VTAB_CONSTRAINT_SUPPORT]]
8907 ** <dt>SQLITE_VTAB_CONSTRAINT_SUPPORT</dt>
8908 ** <dd>Calls of the form
8909 ** [sqlite3_vtab_config](db,SQLITE_VTAB_CONSTRAINT_SUPPORT,X) are supported,
8910 ** where X is an integer. If X is zero, then the [virtual table] whose
8911 ** [xCreate] or [xConnect] method invoked [sqlite3_vtab_config()] does not
8912 ** support constraints. In this configuration (which is the default) if
@@ -8894,13 +8931,35 @@
8931 ** CONFLICT policy is REPLACE, the virtual table implementation should
8932 ** silently replace the appropriate rows within the xUpdate callback and
8933 ** return SQLITE_OK. Or, if this is not possible, it may return
8934 ** SQLITE_CONSTRAINT, in which case SQLite falls back to OR ABORT
8935 ** constraint handling.
8936 ** </dd>
8937 **
8938 ** [[SQLITE_VTAB_INNOCUOUS]]<dt>SQLITE_VTAB_INNOCUOUS</dt>
8939 ** <dd>Calls of the form
8940 ** [sqlite3_vtab_config](db,SQLITE_VTAB_INNOCUOUS) from within the
8941 ** the [xConnect] or [xCreate] methods of a [virtual table] implmentation
8942 ** identify that virtual table as being safe to use from within triggers
8943 ** and views. Conceptually, the SQLITE_VTAB_INNOCUOUS tag means that the
8944 ** virtual table can do no serious harm even if it is controlled by a
8945 ** malicious hacker. Developers should avoid setting the SQLITE_VTAB_INNOCUOUS
8946 ** flag unless absolutely necessary.
8947 ** </dd>
8948 **
8949 ** [[SQLITE_VTAB_DIRECTONLY]]<dt>SQLITE_VTAB_DIRECTONLY</dt>
8950 ** <dd>Calls of the form
8951 ** [sqlite3_vtab_config](db,SQLITE_VTAB_DIRECTONLY) from within the
8952 ** the [xConnect] or [xCreate] methods of a [virtual table] implmentation
8953 ** prohibits that virtual table from being used from within triggers and
8954 ** views.
8955 ** </dd>
8956 ** </dl>
8957 */
8958 #define SQLITE_VTAB_CONSTRAINT_SUPPORT 1
8959 #define SQLITE_VTAB_INNOCUOUS 2
8960 #define SQLITE_VTAB_DIRECTONLY 3
8961
8962 /*
8963 ** CAPI3REF: Determine The Virtual Table Conflict Policy
8964 **
8965 ** This function may only be called from within a call to the [xUpdate] method
8966

Keyboard Shortcuts

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