Fossil SCM

Update to the latest trunk version of SQLite, for SQLite testing.

drh 2021-08-07 17:28 trunk
Commit 5570a6aae9dec02cb58e9248d544ee2af581cdb4ebddf6534c787ab8ea7703fb
3 files changed +139 -71 +957 -1060 +1 -1
+139 -71
--- src/shell.c
+++ src/shell.c
@@ -999,11 +999,11 @@
999999
const char *zSchema = (const char*)sqlite3_value_text(apVal[1]);
10001000
const char *zName = (const char*)sqlite3_value_text(apVal[2]);
10011001
sqlite3 *db = sqlite3_context_db_handle(pCtx);
10021002
UNUSED_PARAMETER(nVal);
10031003
if( zIn!=0 && strncmp(zIn, "CREATE ", 7)==0 ){
1004
- for(i=0; i<(int)(sizeof(aPrefix)/sizeof(aPrefix[0])); i++){
1004
+ for(i=0; i<ArraySize(aPrefix); i++){
10051005
int n = strlen30(aPrefix[i]);
10061006
if( strncmp(zIn+7, aPrefix[i], n)==0 && zIn[n+7]==' ' ){
10071007
char *z = 0;
10081008
char *zFake = 0;
10091009
if( zSchema ){
@@ -12098,23 +12098,26 @@
1209812098
int *actualWidth; /* Actual width of each column */
1209912099
int nWidth; /* Number of slots in colWidth[] and actualWidth[] */
1210012100
char nullValue[20]; /* The text to print when a NULL comes back from
1210112101
** the database */
1210212102
char outfile[FILENAME_MAX]; /* Filename for *out */
12103
- const char *zDbFilename; /* name of the database file */
12104
- char *zFreeOnClose; /* Filename to free when closing */
12105
- const char *zVfs; /* Name of VFS to use */
1210612103
sqlite3_stmt *pStmt; /* Current statement if any. */
1210712104
FILE *pLog; /* Write log output here */
12105
+ struct AuxDb { /* Storage space for auxiliary database connections */
12106
+ sqlite3 *db; /* Connection pointer */
12107
+ const char *zDbFilename; /* Filename used to open the connection */
12108
+ char *zFreeOnClose; /* Free this memory allocation on close */
12109
+#if defined(SQLITE_ENABLE_SESSION)
12110
+ int nSession; /* Number of active sessions */
12111
+ OpenSession aSession[4]; /* Array of sessions. [0] is in focus. */
12112
+#endif
12113
+ } aAuxDb[5], /* Array of all database connections */
12114
+ *pAuxDb; /* Currently active database connection */
1210812115
int *aiIndent; /* Array of indents used in MODE_Explain */
1210912116
int nIndent; /* Size of array aiIndent[] */
1211012117
int iIndent; /* Index of current op in aiIndent[] */
1211112118
EQPGraph sGraph; /* Information for the graphical EXPLAIN QUERY PLAN */
12112
-#if defined(SQLITE_ENABLE_SESSION)
12113
- int nSession; /* Number of active sessions */
12114
- OpenSession aSession[4]; /* Array of sessions. [0] is in focus. */
12115
-#endif
1211612119
ExpertInfo expert; /* Valid if previous command was ".expert OPT..." */
1211712120
};
1211812121
1211912122
1212012123
/* Allowed values for ShellState.autoEQP
@@ -14862,10 +14865,11 @@
1486214865
".binary on|off Turn binary output on or off. Default OFF",
1486314866
".cd DIRECTORY Change the working directory to DIRECTORY",
1486414867
".changes on|off Show number of rows changed by SQL",
1486514868
".check GLOB Fail if output since .testcase does not match",
1486614869
".clone NEWDB Clone data into NEWDB from the existing database",
14870
+ ".connection [close] [#] Open or close an auxiliary database connection",
1486714871
".databases List names and files of attached databases",
1486814872
".dbconfig ?op? ?val? List or change sqlite3_db_config() options",
1486914873
".dbinfo ?DB? Show status information about the database",
1487014874
".dump ?OBJECTS? Render database content as SQL",
1487114875
" Options:",
@@ -15202,19 +15206,20 @@
1520215206
1520315207
/*
1520415208
** Close all OpenSession objects and release all associated resources.
1520515209
*/
1520615210
#if defined(SQLITE_ENABLE_SESSION)
15207
-static void session_close_all(ShellState *p){
15208
- int i;
15209
- for(i=0; i<p->nSession; i++){
15210
- session_close(&p->aSession[i]);
15211
+static void session_close_all(ShellState *p, int i){
15212
+ int j;
15213
+ struct AuxDb *pAuxDb = i<0 ? p->pAuxDb : &p->aAuxDb[i];
15214
+ for(j=0; j<pAuxDb->nSession; j++){
15215
+ session_close(&pAuxDb->aSession[j]);
1521115216
}
15212
- p->nSession = 0;
15217
+ pAuxDb->nSession = 0;
1521315218
}
1521415219
#else
15215
-# define session_close_all(X)
15220
+# define session_close_all(X,Y)
1521615221
#endif
1521715222
1521815223
/*
1521915224
** Implementation of the xFilter function for an open session. Omit
1522015225
** any tables named by ".session filter" but let all other table through.
@@ -15275,12 +15280,12 @@
1527515280
}
1527615281
1527715282
#ifndef SQLITE_OMIT_DESERIALIZE
1527815283
/*
1527915284
** Reconstruct an in-memory database using the output from the "dbtotxt"
15280
-** program. Read content from the file in p->zDbFilename. If p->zDbFilename
15281
-** is 0, then read from standard input.
15285
+** program. Read content from the file in p->aAuxDb[].zDbFilename.
15286
+** If p->aAuxDb[].zDbFilename is 0, then read from standard input.
1528215287
*/
1528315288
static unsigned char *readHexDb(ShellState *p, int *pnData){
1528415289
unsigned char *a = 0;
1528515290
int nLine;
1528615291
int n = 0;
@@ -15287,16 +15292,17 @@
1528715292
int pgsz = 0;
1528815293
int iOffset = 0;
1528915294
int j, k;
1529015295
int rc;
1529115296
FILE *in;
15297
+ const char *zDbFilename = p->pAuxDb->zDbFilename;
1529215298
unsigned int x[16];
1529315299
char zLine[1000];
15294
- if( p->zDbFilename ){
15295
- in = fopen(p->zDbFilename, "r");
15300
+ if( zDbFilename ){
15301
+ in = fopen(zDbFilename, "r");
1529615302
if( in==0 ){
15297
- utf8_printf(stderr, "cannot open \"%s\" for reading\n", p->zDbFilename);
15303
+ utf8_printf(stderr, "cannot open \"%s\" for reading\n", zDbFilename);
1529815304
return 0;
1529915305
}
1530015306
nLine = 0;
1530115307
}else{
1530215308
in = p->in;
@@ -15534,21 +15540,22 @@
1553415540
** Make sure the database is open. If it is not, then open it. If
1553515541
** the database fails to open, print an error message and exit.
1553615542
*/
1553715543
static void open_db(ShellState *p, int openFlags){
1553815544
if( p->db==0 ){
15545
+ const char *zDbFilename = p->pAuxDb->zDbFilename;
1553915546
if( p->openMode==SHELL_OPEN_UNSPEC ){
15540
- if( p->zDbFilename==0 || p->zDbFilename[0]==0 ){
15547
+ if( zDbFilename==0 || zDbFilename[0]==0 ){
1554115548
p->openMode = SHELL_OPEN_NORMAL;
1554215549
}else{
15543
- p->openMode = (u8)deduceDatabaseType(p->zDbFilename,
15550
+ p->openMode = (u8)deduceDatabaseType(zDbFilename,
1554415551
(openFlags & OPEN_DB_ZIPFILE)!=0);
1554515552
}
1554615553
}
1554715554
switch( p->openMode ){
1554815555
case SHELL_OPEN_APPENDVFS: {
15549
- sqlite3_open_v2(p->zDbFilename, &p->db,
15556
+ sqlite3_open_v2(zDbFilename, &p->db,
1555015557
SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|p->openFlags, "apndvfs");
1555115558
break;
1555215559
}
1555315560
case SHELL_OPEN_HEXDB:
1555415561
case SHELL_OPEN_DESERIALIZE: {
@@ -15558,25 +15565,25 @@
1555815565
case SHELL_OPEN_ZIPFILE: {
1555915566
sqlite3_open(":memory:", &p->db);
1556015567
break;
1556115568
}
1556215569
case SHELL_OPEN_READONLY: {
15563
- sqlite3_open_v2(p->zDbFilename, &p->db,
15570
+ sqlite3_open_v2(zDbFilename, &p->db,
1556415571
SQLITE_OPEN_READONLY|p->openFlags, 0);
1556515572
break;
1556615573
}
1556715574
case SHELL_OPEN_UNSPEC:
1556815575
case SHELL_OPEN_NORMAL: {
15569
- sqlite3_open_v2(p->zDbFilename, &p->db,
15576
+ sqlite3_open_v2(zDbFilename, &p->db,
1557015577
SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|p->openFlags, 0);
1557115578
break;
1557215579
}
1557315580
}
1557415581
globalDb = p->db;
1557515582
if( p->db==0 || SQLITE_OK!=sqlite3_errcode(p->db) ){
1557615583
utf8_printf(stderr,"Error: unable to open database \"%s\": %s\n",
15577
- p->zDbFilename, sqlite3_errmsg(p->db));
15584
+ zDbFilename, sqlite3_errmsg(p->db));
1557815585
if( openFlags & OPEN_DB_KEEPALIVE ){
1557915586
sqlite3_open(":memory:", &p->db);
1558015587
return;
1558115588
}
1558215589
exit(1);
@@ -15619,11 +15626,11 @@
1561915626
sqlite3_create_function(p->db, "edit", 2, SQLITE_UTF8, 0,
1562015627
editFunc, 0, 0);
1562115628
#endif
1562215629
if( p->openMode==SHELL_OPEN_ZIPFILE ){
1562315630
char *zSql = sqlite3_mprintf(
15624
- "CREATE VIRTUAL TABLE zip USING zipfile(%Q);", p->zDbFilename);
15631
+ "CREATE VIRTUAL TABLE zip USING zipfile(%Q);", zDbFilename);
1562515632
sqlite3_exec(p->db, zSql, 0, 0, 0);
1562615633
sqlite3_free(zSql);
1562715634
}
1562815635
#ifndef SQLITE_OMIT_DESERIALIZE
1562915636
else
@@ -15630,11 +15637,11 @@
1563015637
if( p->openMode==SHELL_OPEN_DESERIALIZE || p->openMode==SHELL_OPEN_HEXDB ){
1563115638
int rc;
1563215639
int nData = 0;
1563315640
unsigned char *aData;
1563415641
if( p->openMode==SHELL_OPEN_DESERIALIZE ){
15635
- aData = (unsigned char*)readFile(p->zDbFilename, &nData);
15642
+ aData = (unsigned char*)readFile(zDbFilename, &nData);
1563615643
}else{
1563715644
aData = readHexDb(p, &nData);
1563815645
if( aData==0 ){
1563915646
return;
1564015647
}
@@ -18351,11 +18358,10 @@
1835118358
sqlite3_exec(pState->db, "DETACH recovery", 0, 0, 0);
1835218359
return rc;
1835318360
}
1835418361
#endif /* !(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_ENABLE_DBPAGE_VTAB) */
1835518362
18356
-
1835718363
/*
1835818364
** If an input line begins with "." then invoke this routine to
1835918365
** process that line.
1836018366
**
1836118367
** Return 1 on error, 2 to exit, and 0 otherwise.
@@ -18515,10 +18521,17 @@
1851518521
}else{
1851618522
raw_printf(stderr, "Usage: .binary on|off\n");
1851718523
rc = 1;
1851818524
}
1851918525
}else
18526
+
18527
+ /* The undocumented ".breakpoint" command causes a call to the no-op
18528
+ ** routine named test_breakpoint().
18529
+ */
18530
+ if( c=='b' && n>=3 && strncmp(azArg[0], "breakpoint", n)==0 ){
18531
+ test_breakpoint();
18532
+ }else
1852018533
1852118534
if( c=='c' && strcmp(azArg[0],"cd")==0 ){
1852218535
if( nArg==2 ){
1852318536
#if defined(_WIN32) || defined(WIN32)
1852418537
wchar_t *z = sqlite3_win32_utf8_to_unicode(azArg[1]);
@@ -18535,17 +18548,10 @@
1853518548
raw_printf(stderr, "Usage: .cd DIRECTORY\n");
1853618549
rc = 1;
1853718550
}
1853818551
}else
1853918552
18540
- /* The undocumented ".breakpoint" command causes a call to the no-op
18541
- ** routine named test_breakpoint().
18542
- */
18543
- if( c=='b' && n>=3 && strncmp(azArg[0], "breakpoint", n)==0 ){
18544
- test_breakpoint();
18545
- }else
18546
-
1854718553
if( c=='c' && n>=3 && strncmp(azArg[0], "changes", n)==0 ){
1854818554
if( nArg==2 ){
1854918555
setOrClearFlag(p, SHFLG_CountChanges, azArg[1]);
1855018556
}else{
1855118557
raw_printf(stderr, "Usage: .changes on|off\n");
@@ -18584,10 +18590,56 @@
1858418590
}else{
1858518591
raw_printf(stderr, "Usage: .clone FILENAME\n");
1858618592
rc = 1;
1858718593
}
1858818594
}else
18595
+
18596
+ if( c=='c' && strncmp(azArg[0], "connection", n)==0 ){
18597
+ if( nArg==1 ){
18598
+ /* List available connections */
18599
+ int i;
18600
+ for(i=0; i<ArraySize(p->aAuxDb); i++){
18601
+ const char *zFile = p->aAuxDb[i].zDbFilename;
18602
+ if( p->aAuxDb[i].db==0 && p->pAuxDb!=&p->aAuxDb[i] ){
18603
+ zFile = "(not open)";
18604
+ }else if( zFile==0 ){
18605
+ zFile = "(memory)";
18606
+ }else if( zFile[0]==0 ){
18607
+ zFile = "(temporary-file)";
18608
+ }
18609
+ if( p->pAuxDb == &p->aAuxDb[i] ){
18610
+ utf8_printf(stdout, "ACTIVE %d: %s\n", i, zFile);
18611
+ }else if( p->aAuxDb[i].db!=0 ){
18612
+ utf8_printf(stdout, " %d: %s\n", i, zFile);
18613
+ }
18614
+ }
18615
+ }else if( nArg==2 && IsDigit(azArg[1][0]) && azArg[1][1]==0 ){
18616
+ int i = azArg[1][0] - '0';
18617
+ if( p->pAuxDb != &p->aAuxDb[i] && i>=0 && i<ArraySize(p->aAuxDb) ){
18618
+ p->pAuxDb->db = p->db;
18619
+ p->pAuxDb = &p->aAuxDb[i];
18620
+ globalDb = p->db = p->pAuxDb->db;
18621
+ p->pAuxDb->db = 0;
18622
+ }
18623
+ }else if( nArg==3 && strcmp(azArg[1], "close")==0
18624
+ && IsDigit(azArg[2][0]) && azArg[2][1]==0 ){
18625
+ int i = azArg[2][0] - '0';
18626
+ if( i<0 || i>=ArraySize(p->aAuxDb) ){
18627
+ /* No-op */
18628
+ }else if( p->pAuxDb == &p->aAuxDb[i] ){
18629
+ raw_printf(stderr, "cannot close the active database connection\n");
18630
+ rc = 1;
18631
+ }else if( p->aAuxDb[i].db ){
18632
+ session_close_all(p, i);
18633
+ close_db(p->aAuxDb[i].db);
18634
+ p->aAuxDb[i].db = 0;
18635
+ }
18636
+ }else{
18637
+ raw_printf(stderr, "Usage: .connection [close] [CONNECTION-NUMBER]\n");
18638
+ rc = 1;
18639
+ }
18640
+ }else
1858918641
1859018642
if( c=='d' && n>1 && strncmp(azArg[0], "databases", n)==0 ){
1859118643
char **azName = 0;
1859218644
int nName = 0;
1859318645
sqlite3_stmt *pStmt;
@@ -19674,16 +19726,16 @@
1967419726
if( c=='o' && strncmp(azArg[0], "open", n)==0 && n>=2 ){
1967519727
char *zNewFilename = 0; /* Name of the database file to open */
1967619728
int iName = 1; /* Index in azArg[] of the filename */
1967719729
int newFlag = 0; /* True to delete file before opening */
1967819730
/* Close the existing database */
19679
- session_close_all(p);
19731
+ session_close_all(p, -1);
1968019732
close_db(p->db);
1968119733
p->db = 0;
19682
- p->zDbFilename = 0;
19683
- sqlite3_free(p->zFreeOnClose);
19684
- p->zFreeOnClose = 0;
19734
+ p->pAuxDb->zDbFilename = 0;
19735
+ sqlite3_free(p->pAuxDb->zFreeOnClose);
19736
+ p->pAuxDb->zFreeOnClose = 0;
1968519737
p->openMode = SHELL_OPEN_UNSPEC;
1968619738
p->openFlags = 0;
1968719739
p->szMax = 0;
1968819740
/* Check for command-line arguments */
1968919741
for(iName=1; iName<nArg; iName++){
@@ -19723,22 +19775,22 @@
1972319775
}
1972419776
}
1972519777
/* If a filename is specified, try to open it first */
1972619778
if( zNewFilename || p->openMode==SHELL_OPEN_HEXDB ){
1972719779
if( newFlag ) shellDeleteFile(zNewFilename);
19728
- p->zDbFilename = zNewFilename;
19780
+ p->pAuxDb->zDbFilename = zNewFilename;
1972919781
open_db(p, OPEN_DB_KEEPALIVE);
1973019782
if( p->db==0 ){
1973119783
utf8_printf(stderr, "Error: cannot open '%s'\n", zNewFilename);
1973219784
sqlite3_free(zNewFilename);
1973319785
}else{
19734
- p->zFreeOnClose = zNewFilename;
19786
+ p->pAuxDb->zFreeOnClose = zNewFilename;
1973519787
}
1973619788
}
1973719789
if( p->db==0 ){
1973819790
/* As a fall-back open a TEMP database */
19739
- p->zDbFilename = 0;
19791
+ p->pAuxDb->zDbFilename = 0;
1974019792
open_db(p, 0);
1974119793
}
1974219794
}else
1974319795
1974419796
if( (c=='o'
@@ -20263,27 +20315,28 @@
2026320315
sqlite3_test_control(SQLITE_TESTCTRL_TRACEFLAGS, 1, &x);
2026420316
}else
2026520317
2026620318
#if defined(SQLITE_ENABLE_SESSION)
2026720319
if( c=='s' && strncmp(azArg[0],"session",n)==0 && n>=3 ){
20268
- OpenSession *pSession = &p->aSession[0];
20320
+ struct AuxDb *pAuxDb = p->pAuxDb;
20321
+ OpenSession *pSession = &pAuxDb->aSession[0];
2026920322
char **azCmd = &azArg[1];
2027020323
int iSes = 0;
2027120324
int nCmd = nArg - 1;
2027220325
int i;
2027320326
if( nArg<=1 ) goto session_syntax_error;
2027420327
open_db(p, 0);
2027520328
if( nArg>=3 ){
20276
- for(iSes=0; iSes<p->nSession; iSes++){
20277
- if( strcmp(p->aSession[iSes].zName, azArg[1])==0 ) break;
20329
+ for(iSes=0; iSes<pAuxDb->nSession; iSes++){
20330
+ if( strcmp(pAuxDb->aSession[iSes].zName, azArg[1])==0 ) break;
2027820331
}
20279
- if( iSes<p->nSession ){
20280
- pSession = &p->aSession[iSes];
20332
+ if( iSes<pAuxDb->nSession ){
20333
+ pSession = &pAuxDb->aSession[iSes];
2028120334
azCmd++;
2028220335
nCmd--;
2028320336
}else{
20284
- pSession = &p->aSession[0];
20337
+ pSession = &pAuxDb->aSession[0];
2028520338
iSes = 0;
2028620339
}
2028720340
}
2028820341
2028920342
/* .session attach TABLE
@@ -20341,13 +20394,13 @@
2034120394
/* .session close
2034220395
** Close the identified session
2034320396
*/
2034420397
if( strcmp(azCmd[0], "close")==0 ){
2034520398
if( nCmd!=1 ) goto session_syntax_error;
20346
- if( p->nSession ){
20399
+ if( pAuxDb->nSession ){
2034720400
session_close(pSession);
20348
- p->aSession[iSes] = p->aSession[--p->nSession];
20401
+ pAuxDb->aSession[iSes] = pAuxDb->aSession[--pAuxDb->nSession];
2034920402
}
2035020403
}else
2035120404
2035220405
/* .session enable ?BOOLEAN?
2035320406
** Query or set the enable flag
@@ -20354,11 +20407,11 @@
2035420407
*/
2035520408
if( strcmp(azCmd[0], "enable")==0 ){
2035620409
int ii;
2035720410
if( nCmd>2 ) goto session_syntax_error;
2035820411
ii = nCmd==1 ? -1 : booleanValue(azCmd[1]);
20359
- if( p->nSession ){
20412
+ if( pAuxDb->nSession ){
2036020413
ii = sqlite3session_enable(pSession->p, ii);
2036120414
utf8_printf(p->out, "session %s enable flag = %d\n",
2036220415
pSession->zName, ii);
2036320416
}
2036420417
}else
@@ -20367,11 +20420,11 @@
2036720420
** Set a list of GLOB patterns of table names to be excluded.
2036820421
*/
2036920422
if( strcmp(azCmd[0], "filter")==0 ){
2037020423
int ii, nByte;
2037120424
if( nCmd<2 ) goto session_syntax_error;
20372
- if( p->nSession ){
20425
+ if( pAuxDb->nSession ){
2037320426
for(ii=0; ii<pSession->nFilter; ii++){
2037420427
sqlite3_free(pSession->azFilter[ii]);
2037520428
}
2037620429
sqlite3_free(pSession->azFilter);
2037720430
nByte = sizeof(pSession->azFilter[0])*(nCmd-1);
@@ -20392,11 +20445,11 @@
2039220445
*/
2039320446
if( strcmp(azCmd[0], "indirect")==0 ){
2039420447
int ii;
2039520448
if( nCmd>2 ) goto session_syntax_error;
2039620449
ii = nCmd==1 ? -1 : booleanValue(azCmd[1]);
20397
- if( p->nSession ){
20450
+ if( pAuxDb->nSession ){
2039820451
ii = sqlite3session_indirect(pSession->p, ii);
2039920452
utf8_printf(p->out, "session %s indirect flag = %d\n",
2040020453
pSession->zName, ii);
2040120454
}
2040220455
}else
@@ -20405,11 +20458,11 @@
2040520458
** Determine if the session is empty
2040620459
*/
2040720460
if( strcmp(azCmd[0], "isempty")==0 ){
2040820461
int ii;
2040920462
if( nCmd!=1 ) goto session_syntax_error;
20410
- if( p->nSession ){
20463
+ if( pAuxDb->nSession ){
2041120464
ii = sqlite3session_isempty(pSession->p);
2041220465
utf8_printf(p->out, "session %s isempty flag = %d\n",
2041320466
pSession->zName, ii);
2041420467
}
2041520468
}else
@@ -20416,12 +20469,12 @@
2041620469
2041720470
/* .session list
2041820471
** List all currently open sessions
2041920472
*/
2042020473
if( strcmp(azCmd[0],"list")==0 ){
20421
- for(i=0; i<p->nSession; i++){
20422
- utf8_printf(p->out, "%d %s\n", i, p->aSession[i].zName);
20474
+ for(i=0; i<pAuxDb->nSession; i++){
20475
+ utf8_printf(p->out, "%d %s\n", i, pAuxDb->aSession[i].zName);
2042320476
}
2042420477
}else
2042520478
2042620479
/* .session open DB NAME
2042720480
** Open a new session called NAME on the attached database DB.
@@ -20430,30 +20483,30 @@
2043020483
if( strcmp(azCmd[0],"open")==0 ){
2043120484
char *zName;
2043220485
if( nCmd!=3 ) goto session_syntax_error;
2043320486
zName = azCmd[2];
2043420487
if( zName[0]==0 ) goto session_syntax_error;
20435
- for(i=0; i<p->nSession; i++){
20436
- if( strcmp(p->aSession[i].zName,zName)==0 ){
20488
+ for(i=0; i<pAuxDb->nSession; i++){
20489
+ if( strcmp(pAuxDb->aSession[i].zName,zName)==0 ){
2043720490
utf8_printf(stderr, "Session \"%s\" already exists\n", zName);
2043820491
goto meta_command_exit;
2043920492
}
2044020493
}
20441
- if( p->nSession>=ArraySize(p->aSession) ){
20442
- raw_printf(stderr, "Maximum of %d sessions\n", ArraySize(p->aSession));
20494
+ if( pAuxDb->nSession>=ArraySize(pAuxDb->aSession) ){
20495
+ raw_printf(stderr, "Maximum of %d sessions\n", ArraySize(pAuxDb->aSession));
2044320496
goto meta_command_exit;
2044420497
}
20445
- pSession = &p->aSession[p->nSession];
20498
+ pSession = &pAuxDb->aSession[pAuxDb->nSession];
2044620499
rc = sqlite3session_create(p->db, azCmd[1], &pSession->p);
2044720500
if( rc ){
2044820501
raw_printf(stderr, "Cannot open session: error code=%d\n", rc);
2044920502
rc = 0;
2045020503
goto meta_command_exit;
2045120504
}
2045220505
pSession->nFilter = 0;
2045320506
sqlite3session_table_filter(pSession->p, session_filter, pSession);
20454
- p->nSession++;
20507
+ pAuxDb->nSession++;
2045520508
pSession->zName = sqlite3_mprintf("%s", zName);
2045620509
}else
2045720510
/* If no command name matches, show a syntax error */
2045820511
session_syntax_error:
2045920512
showHelp(p->out, "session");
@@ -20778,11 +20831,11 @@
2077820831
for (i=0;i<p->nWidth;i++) {
2077920832
raw_printf(p->out, "%d ", p->colWidth[i]);
2078020833
}
2078120834
raw_printf(p->out, "\n");
2078220835
utf8_printf(p->out, "%12.12s: %s\n", "filename",
20783
- p->zDbFilename ? p->zDbFilename : "");
20836
+ p->pAuxDb->zDbFilename ? p->pAuxDb->zDbFilename : "");
2078420837
}else
2078520838
2078620839
if( c=='s' && strncmp(azArg[0], "stats", n)==0 ){
2078720840
if( nArg==2 ){
2078820841
if( strcmp(azArg[1],"stmt")==0 ){
@@ -20945,10 +20998,11 @@
2094520998
{ "pending_byte", SQLITE_TESTCTRL_PENDING_BYTE, "OFFSET " },
2094620999
{ "prng_restore", SQLITE_TESTCTRL_PRNG_RESTORE, "" },
2094721000
{ "prng_save", SQLITE_TESTCTRL_PRNG_SAVE, "" },
2094821001
{ "prng_seed", SQLITE_TESTCTRL_PRNG_SEED, "SEED ?db?" },
2094921002
{ "seek_count", SQLITE_TESTCTRL_SEEK_COUNT, "" },
21003
+ { "sorter_mmap", SQLITE_TESTCTRL_SORTER_MMAP, "NMAX" },
2095021004
{ "tune", SQLITE_TESTCTRL_TUNE, "ID VALUE" },
2095121005
};
2095221006
int testctrl = -1;
2095321007
int iCtrl = -1;
2095421008
int rc2 = 0; /* 0: usage. 1: %d 2: %x 3: no-output */
@@ -21125,10 +21179,17 @@
2112521179
isOk = 3;
2112621180
}
2112721181
break;
2112821182
}
2112921183
#endif
21184
+ case SQLITE_TESTCTRL_SORTER_MMAP:
21185
+ if( nArg==3 ){
21186
+ int opt = (unsigned int)integerValue(azArg[2]);
21187
+ rc2 = sqlite3_test_control(testctrl, p->db, opt);
21188
+ isOk = 3;
21189
+ }
21190
+ break;
2113021191
}
2113121192
}
2113221193
if( isOk==0 && iCtrl>=0 ){
2113321194
utf8_printf(p->out, "Usage: .testctrl %s %s\n", zCmd,aCtrl[iCtrl].zUsage);
2113421195
rc = 1;
@@ -21799,10 +21860,11 @@
2179921860
*/
2180021861
static void main_init(ShellState *data) {
2180121862
memset(data, 0, sizeof(*data));
2180221863
data->normalMode = data->cMode = data->mode = MODE_List;
2180321864
data->autoExplain = 1;
21865
+ data->pAuxDb = &data->aAuxDb[0];
2180421866
memcpy(data->colSeparator,SEP_Column, 2);
2180521867
memcpy(data->rowSeparator,SEP_Row, 2);
2180621868
data->showHeader = 0;
2180721869
data->shellFlgs = SHFLG_Lookaside;
2180821870
verify_uninitialized();
@@ -21962,11 +22024,11 @@
2196222024
/* If the SQLITE_SHELL_DBNAME_PROC macro is defined, then it is the name
2196322025
** of a C-function that will provide the name of the database file. Use
2196422026
** this compile-time option to embed this shell program in larger
2196522027
** applications. */
2196622028
extern void SQLITE_SHELL_DBNAME_PROC(const char**);
21967
- SQLITE_SHELL_DBNAME_PROC(&data.zDbFilename);
22029
+ SQLITE_SHELL_DBNAME_PROC(&data.pAuxDb->zDbFilename);
2196822030
warnInmemoryDb = 0;
2196922031
}
2197022032
#endif
2197122033
2197222034
/* Do an initial pass through the command-line argument to locate
@@ -21977,12 +22039,12 @@
2197722039
verify_uninitialized();
2197822040
for(i=1; i<argc; i++){
2197922041
char *z;
2198022042
z = argv[i];
2198122043
if( z[0]!='-' ){
21982
- if( data.zDbFilename==0 ){
21983
- data.zDbFilename = z;
22044
+ if( data.aAuxDb->zDbFilename==0 ){
22045
+ data.aAuxDb->zDbFilename = z;
2198422046
}else{
2198522047
/* Excesss arguments are interpreted as SQL (or dot-commands) and
2198622048
** mean that nothing is read from stdin */
2198722049
readStdin = 0;
2198822050
nCmd++;
@@ -22118,13 +22180,13 @@
2211822180
utf8_printf(stderr, "no such VFS: \"%s\"\n", argv[i]);
2211922181
exit(1);
2212022182
}
2212122183
}
2212222184
22123
- if( data.zDbFilename==0 ){
22185
+ if( data.pAuxDb->zDbFilename==0 ){
2212422186
#ifndef SQLITE_OMIT_MEMORYDB
22125
- data.zDbFilename = ":memory:";
22187
+ data.pAuxDb->zDbFilename = ":memory:";
2212622188
warnInmemoryDb = argc==1;
2212722189
#else
2212822190
utf8_printf(stderr,"%s: Error: no database filename specified\n", Argv0);
2212922191
return 1;
2213022192
#endif
@@ -22135,11 +22197,11 @@
2213522197
/* Go ahead and open the database file if it already exists. If the
2213622198
** file does not exist, delay opening it. This prevents empty database
2213722199
** files from being created if a user mistypes the database name argument
2213822200
** to the sqlite command-line tool.
2213922201
*/
22140
- if( access(data.zDbFilename, 0)==0 ){
22202
+ if( access(data.pAuxDb->zDbFilename, 0)==0 ){
2214122203
open_db(&data, 0);
2214222204
}
2214322205
2214422206
/* Process the initialization file if there is one. If no -init option
2214522207
** is given on the command line, look for a file named ~/.sqliterc and
@@ -22389,14 +22451,20 @@
2238922451
}
2239022452
}
2239122453
free(azCmd);
2239222454
set_table_name(&data, 0);
2239322455
if( data.db ){
22394
- session_close_all(&data);
22456
+ session_close_all(&data, -1);
2239522457
close_db(data.db);
2239622458
}
22397
- sqlite3_free(data.zFreeOnClose);
22459
+ for(i=0; i<ArraySize(data.aAuxDb); i++){
22460
+ sqlite3_free(data.aAuxDb[i].zFreeOnClose);
22461
+ if( data.aAuxDb[i].db ){
22462
+ session_close_all(&data, i);
22463
+ close_db(data.aAuxDb[i].db);
22464
+ }
22465
+ }
2239822466
find_home_dir(1);
2239922467
output_reset(&data);
2240022468
data.doXdgOpen = 0;
2240122469
clearTempFile(&data);
2240222470
#if !SQLITE_SHELL_IS_UTF8
2240322471
--- src/shell.c
+++ src/shell.c
@@ -999,11 +999,11 @@
999 const char *zSchema = (const char*)sqlite3_value_text(apVal[1]);
1000 const char *zName = (const char*)sqlite3_value_text(apVal[2]);
1001 sqlite3 *db = sqlite3_context_db_handle(pCtx);
1002 UNUSED_PARAMETER(nVal);
1003 if( zIn!=0 && strncmp(zIn, "CREATE ", 7)==0 ){
1004 for(i=0; i<(int)(sizeof(aPrefix)/sizeof(aPrefix[0])); i++){
1005 int n = strlen30(aPrefix[i]);
1006 if( strncmp(zIn+7, aPrefix[i], n)==0 && zIn[n+7]==' ' ){
1007 char *z = 0;
1008 char *zFake = 0;
1009 if( zSchema ){
@@ -12098,23 +12098,26 @@
12098 int *actualWidth; /* Actual width of each column */
12099 int nWidth; /* Number of slots in colWidth[] and actualWidth[] */
12100 char nullValue[20]; /* The text to print when a NULL comes back from
12101 ** the database */
12102 char outfile[FILENAME_MAX]; /* Filename for *out */
12103 const char *zDbFilename; /* name of the database file */
12104 char *zFreeOnClose; /* Filename to free when closing */
12105 const char *zVfs; /* Name of VFS to use */
12106 sqlite3_stmt *pStmt; /* Current statement if any. */
12107 FILE *pLog; /* Write log output here */
 
 
 
 
 
 
 
 
 
 
12108 int *aiIndent; /* Array of indents used in MODE_Explain */
12109 int nIndent; /* Size of array aiIndent[] */
12110 int iIndent; /* Index of current op in aiIndent[] */
12111 EQPGraph sGraph; /* Information for the graphical EXPLAIN QUERY PLAN */
12112 #if defined(SQLITE_ENABLE_SESSION)
12113 int nSession; /* Number of active sessions */
12114 OpenSession aSession[4]; /* Array of sessions. [0] is in focus. */
12115 #endif
12116 ExpertInfo expert; /* Valid if previous command was ".expert OPT..." */
12117 };
12118
12119
12120 /* Allowed values for ShellState.autoEQP
@@ -14862,10 +14865,11 @@
14862 ".binary on|off Turn binary output on or off. Default OFF",
14863 ".cd DIRECTORY Change the working directory to DIRECTORY",
14864 ".changes on|off Show number of rows changed by SQL",
14865 ".check GLOB Fail if output since .testcase does not match",
14866 ".clone NEWDB Clone data into NEWDB from the existing database",
 
14867 ".databases List names and files of attached databases",
14868 ".dbconfig ?op? ?val? List or change sqlite3_db_config() options",
14869 ".dbinfo ?DB? Show status information about the database",
14870 ".dump ?OBJECTS? Render database content as SQL",
14871 " Options:",
@@ -15202,19 +15206,20 @@
15202
15203 /*
15204 ** Close all OpenSession objects and release all associated resources.
15205 */
15206 #if defined(SQLITE_ENABLE_SESSION)
15207 static void session_close_all(ShellState *p){
15208 int i;
15209 for(i=0; i<p->nSession; i++){
15210 session_close(&p->aSession[i]);
 
15211 }
15212 p->nSession = 0;
15213 }
15214 #else
15215 # define session_close_all(X)
15216 #endif
15217
15218 /*
15219 ** Implementation of the xFilter function for an open session. Omit
15220 ** any tables named by ".session filter" but let all other table through.
@@ -15275,12 +15280,12 @@
15275 }
15276
15277 #ifndef SQLITE_OMIT_DESERIALIZE
15278 /*
15279 ** Reconstruct an in-memory database using the output from the "dbtotxt"
15280 ** program. Read content from the file in p->zDbFilename. If p->zDbFilename
15281 ** is 0, then read from standard input.
15282 */
15283 static unsigned char *readHexDb(ShellState *p, int *pnData){
15284 unsigned char *a = 0;
15285 int nLine;
15286 int n = 0;
@@ -15287,16 +15292,17 @@
15287 int pgsz = 0;
15288 int iOffset = 0;
15289 int j, k;
15290 int rc;
15291 FILE *in;
 
15292 unsigned int x[16];
15293 char zLine[1000];
15294 if( p->zDbFilename ){
15295 in = fopen(p->zDbFilename, "r");
15296 if( in==0 ){
15297 utf8_printf(stderr, "cannot open \"%s\" for reading\n", p->zDbFilename);
15298 return 0;
15299 }
15300 nLine = 0;
15301 }else{
15302 in = p->in;
@@ -15534,21 +15540,22 @@
15534 ** Make sure the database is open. If it is not, then open it. If
15535 ** the database fails to open, print an error message and exit.
15536 */
15537 static void open_db(ShellState *p, int openFlags){
15538 if( p->db==0 ){
 
15539 if( p->openMode==SHELL_OPEN_UNSPEC ){
15540 if( p->zDbFilename==0 || p->zDbFilename[0]==0 ){
15541 p->openMode = SHELL_OPEN_NORMAL;
15542 }else{
15543 p->openMode = (u8)deduceDatabaseType(p->zDbFilename,
15544 (openFlags & OPEN_DB_ZIPFILE)!=0);
15545 }
15546 }
15547 switch( p->openMode ){
15548 case SHELL_OPEN_APPENDVFS: {
15549 sqlite3_open_v2(p->zDbFilename, &p->db,
15550 SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|p->openFlags, "apndvfs");
15551 break;
15552 }
15553 case SHELL_OPEN_HEXDB:
15554 case SHELL_OPEN_DESERIALIZE: {
@@ -15558,25 +15565,25 @@
15558 case SHELL_OPEN_ZIPFILE: {
15559 sqlite3_open(":memory:", &p->db);
15560 break;
15561 }
15562 case SHELL_OPEN_READONLY: {
15563 sqlite3_open_v2(p->zDbFilename, &p->db,
15564 SQLITE_OPEN_READONLY|p->openFlags, 0);
15565 break;
15566 }
15567 case SHELL_OPEN_UNSPEC:
15568 case SHELL_OPEN_NORMAL: {
15569 sqlite3_open_v2(p->zDbFilename, &p->db,
15570 SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|p->openFlags, 0);
15571 break;
15572 }
15573 }
15574 globalDb = p->db;
15575 if( p->db==0 || SQLITE_OK!=sqlite3_errcode(p->db) ){
15576 utf8_printf(stderr,"Error: unable to open database \"%s\": %s\n",
15577 p->zDbFilename, sqlite3_errmsg(p->db));
15578 if( openFlags & OPEN_DB_KEEPALIVE ){
15579 sqlite3_open(":memory:", &p->db);
15580 return;
15581 }
15582 exit(1);
@@ -15619,11 +15626,11 @@
15619 sqlite3_create_function(p->db, "edit", 2, SQLITE_UTF8, 0,
15620 editFunc, 0, 0);
15621 #endif
15622 if( p->openMode==SHELL_OPEN_ZIPFILE ){
15623 char *zSql = sqlite3_mprintf(
15624 "CREATE VIRTUAL TABLE zip USING zipfile(%Q);", p->zDbFilename);
15625 sqlite3_exec(p->db, zSql, 0, 0, 0);
15626 sqlite3_free(zSql);
15627 }
15628 #ifndef SQLITE_OMIT_DESERIALIZE
15629 else
@@ -15630,11 +15637,11 @@
15630 if( p->openMode==SHELL_OPEN_DESERIALIZE || p->openMode==SHELL_OPEN_HEXDB ){
15631 int rc;
15632 int nData = 0;
15633 unsigned char *aData;
15634 if( p->openMode==SHELL_OPEN_DESERIALIZE ){
15635 aData = (unsigned char*)readFile(p->zDbFilename, &nData);
15636 }else{
15637 aData = readHexDb(p, &nData);
15638 if( aData==0 ){
15639 return;
15640 }
@@ -18351,11 +18358,10 @@
18351 sqlite3_exec(pState->db, "DETACH recovery", 0, 0, 0);
18352 return rc;
18353 }
18354 #endif /* !(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_ENABLE_DBPAGE_VTAB) */
18355
18356
18357 /*
18358 ** If an input line begins with "." then invoke this routine to
18359 ** process that line.
18360 **
18361 ** Return 1 on error, 2 to exit, and 0 otherwise.
@@ -18515,10 +18521,17 @@
18515 }else{
18516 raw_printf(stderr, "Usage: .binary on|off\n");
18517 rc = 1;
18518 }
18519 }else
 
 
 
 
 
 
 
18520
18521 if( c=='c' && strcmp(azArg[0],"cd")==0 ){
18522 if( nArg==2 ){
18523 #if defined(_WIN32) || defined(WIN32)
18524 wchar_t *z = sqlite3_win32_utf8_to_unicode(azArg[1]);
@@ -18535,17 +18548,10 @@
18535 raw_printf(stderr, "Usage: .cd DIRECTORY\n");
18536 rc = 1;
18537 }
18538 }else
18539
18540 /* The undocumented ".breakpoint" command causes a call to the no-op
18541 ** routine named test_breakpoint().
18542 */
18543 if( c=='b' && n>=3 && strncmp(azArg[0], "breakpoint", n)==0 ){
18544 test_breakpoint();
18545 }else
18546
18547 if( c=='c' && n>=3 && strncmp(azArg[0], "changes", n)==0 ){
18548 if( nArg==2 ){
18549 setOrClearFlag(p, SHFLG_CountChanges, azArg[1]);
18550 }else{
18551 raw_printf(stderr, "Usage: .changes on|off\n");
@@ -18584,10 +18590,56 @@
18584 }else{
18585 raw_printf(stderr, "Usage: .clone FILENAME\n");
18586 rc = 1;
18587 }
18588 }else
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18589
18590 if( c=='d' && n>1 && strncmp(azArg[0], "databases", n)==0 ){
18591 char **azName = 0;
18592 int nName = 0;
18593 sqlite3_stmt *pStmt;
@@ -19674,16 +19726,16 @@
19674 if( c=='o' && strncmp(azArg[0], "open", n)==0 && n>=2 ){
19675 char *zNewFilename = 0; /* Name of the database file to open */
19676 int iName = 1; /* Index in azArg[] of the filename */
19677 int newFlag = 0; /* True to delete file before opening */
19678 /* Close the existing database */
19679 session_close_all(p);
19680 close_db(p->db);
19681 p->db = 0;
19682 p->zDbFilename = 0;
19683 sqlite3_free(p->zFreeOnClose);
19684 p->zFreeOnClose = 0;
19685 p->openMode = SHELL_OPEN_UNSPEC;
19686 p->openFlags = 0;
19687 p->szMax = 0;
19688 /* Check for command-line arguments */
19689 for(iName=1; iName<nArg; iName++){
@@ -19723,22 +19775,22 @@
19723 }
19724 }
19725 /* If a filename is specified, try to open it first */
19726 if( zNewFilename || p->openMode==SHELL_OPEN_HEXDB ){
19727 if( newFlag ) shellDeleteFile(zNewFilename);
19728 p->zDbFilename = zNewFilename;
19729 open_db(p, OPEN_DB_KEEPALIVE);
19730 if( p->db==0 ){
19731 utf8_printf(stderr, "Error: cannot open '%s'\n", zNewFilename);
19732 sqlite3_free(zNewFilename);
19733 }else{
19734 p->zFreeOnClose = zNewFilename;
19735 }
19736 }
19737 if( p->db==0 ){
19738 /* As a fall-back open a TEMP database */
19739 p->zDbFilename = 0;
19740 open_db(p, 0);
19741 }
19742 }else
19743
19744 if( (c=='o'
@@ -20263,27 +20315,28 @@
20263 sqlite3_test_control(SQLITE_TESTCTRL_TRACEFLAGS, 1, &x);
20264 }else
20265
20266 #if defined(SQLITE_ENABLE_SESSION)
20267 if( c=='s' && strncmp(azArg[0],"session",n)==0 && n>=3 ){
20268 OpenSession *pSession = &p->aSession[0];
 
20269 char **azCmd = &azArg[1];
20270 int iSes = 0;
20271 int nCmd = nArg - 1;
20272 int i;
20273 if( nArg<=1 ) goto session_syntax_error;
20274 open_db(p, 0);
20275 if( nArg>=3 ){
20276 for(iSes=0; iSes<p->nSession; iSes++){
20277 if( strcmp(p->aSession[iSes].zName, azArg[1])==0 ) break;
20278 }
20279 if( iSes<p->nSession ){
20280 pSession = &p->aSession[iSes];
20281 azCmd++;
20282 nCmd--;
20283 }else{
20284 pSession = &p->aSession[0];
20285 iSes = 0;
20286 }
20287 }
20288
20289 /* .session attach TABLE
@@ -20341,13 +20394,13 @@
20341 /* .session close
20342 ** Close the identified session
20343 */
20344 if( strcmp(azCmd[0], "close")==0 ){
20345 if( nCmd!=1 ) goto session_syntax_error;
20346 if( p->nSession ){
20347 session_close(pSession);
20348 p->aSession[iSes] = p->aSession[--p->nSession];
20349 }
20350 }else
20351
20352 /* .session enable ?BOOLEAN?
20353 ** Query or set the enable flag
@@ -20354,11 +20407,11 @@
20354 */
20355 if( strcmp(azCmd[0], "enable")==0 ){
20356 int ii;
20357 if( nCmd>2 ) goto session_syntax_error;
20358 ii = nCmd==1 ? -1 : booleanValue(azCmd[1]);
20359 if( p->nSession ){
20360 ii = sqlite3session_enable(pSession->p, ii);
20361 utf8_printf(p->out, "session %s enable flag = %d\n",
20362 pSession->zName, ii);
20363 }
20364 }else
@@ -20367,11 +20420,11 @@
20367 ** Set a list of GLOB patterns of table names to be excluded.
20368 */
20369 if( strcmp(azCmd[0], "filter")==0 ){
20370 int ii, nByte;
20371 if( nCmd<2 ) goto session_syntax_error;
20372 if( p->nSession ){
20373 for(ii=0; ii<pSession->nFilter; ii++){
20374 sqlite3_free(pSession->azFilter[ii]);
20375 }
20376 sqlite3_free(pSession->azFilter);
20377 nByte = sizeof(pSession->azFilter[0])*(nCmd-1);
@@ -20392,11 +20445,11 @@
20392 */
20393 if( strcmp(azCmd[0], "indirect")==0 ){
20394 int ii;
20395 if( nCmd>2 ) goto session_syntax_error;
20396 ii = nCmd==1 ? -1 : booleanValue(azCmd[1]);
20397 if( p->nSession ){
20398 ii = sqlite3session_indirect(pSession->p, ii);
20399 utf8_printf(p->out, "session %s indirect flag = %d\n",
20400 pSession->zName, ii);
20401 }
20402 }else
@@ -20405,11 +20458,11 @@
20405 ** Determine if the session is empty
20406 */
20407 if( strcmp(azCmd[0], "isempty")==0 ){
20408 int ii;
20409 if( nCmd!=1 ) goto session_syntax_error;
20410 if( p->nSession ){
20411 ii = sqlite3session_isempty(pSession->p);
20412 utf8_printf(p->out, "session %s isempty flag = %d\n",
20413 pSession->zName, ii);
20414 }
20415 }else
@@ -20416,12 +20469,12 @@
20416
20417 /* .session list
20418 ** List all currently open sessions
20419 */
20420 if( strcmp(azCmd[0],"list")==0 ){
20421 for(i=0; i<p->nSession; i++){
20422 utf8_printf(p->out, "%d %s\n", i, p->aSession[i].zName);
20423 }
20424 }else
20425
20426 /* .session open DB NAME
20427 ** Open a new session called NAME on the attached database DB.
@@ -20430,30 +20483,30 @@
20430 if( strcmp(azCmd[0],"open")==0 ){
20431 char *zName;
20432 if( nCmd!=3 ) goto session_syntax_error;
20433 zName = azCmd[2];
20434 if( zName[0]==0 ) goto session_syntax_error;
20435 for(i=0; i<p->nSession; i++){
20436 if( strcmp(p->aSession[i].zName,zName)==0 ){
20437 utf8_printf(stderr, "Session \"%s\" already exists\n", zName);
20438 goto meta_command_exit;
20439 }
20440 }
20441 if( p->nSession>=ArraySize(p->aSession) ){
20442 raw_printf(stderr, "Maximum of %d sessions\n", ArraySize(p->aSession));
20443 goto meta_command_exit;
20444 }
20445 pSession = &p->aSession[p->nSession];
20446 rc = sqlite3session_create(p->db, azCmd[1], &pSession->p);
20447 if( rc ){
20448 raw_printf(stderr, "Cannot open session: error code=%d\n", rc);
20449 rc = 0;
20450 goto meta_command_exit;
20451 }
20452 pSession->nFilter = 0;
20453 sqlite3session_table_filter(pSession->p, session_filter, pSession);
20454 p->nSession++;
20455 pSession->zName = sqlite3_mprintf("%s", zName);
20456 }else
20457 /* If no command name matches, show a syntax error */
20458 session_syntax_error:
20459 showHelp(p->out, "session");
@@ -20778,11 +20831,11 @@
20778 for (i=0;i<p->nWidth;i++) {
20779 raw_printf(p->out, "%d ", p->colWidth[i]);
20780 }
20781 raw_printf(p->out, "\n");
20782 utf8_printf(p->out, "%12.12s: %s\n", "filename",
20783 p->zDbFilename ? p->zDbFilename : "");
20784 }else
20785
20786 if( c=='s' && strncmp(azArg[0], "stats", n)==0 ){
20787 if( nArg==2 ){
20788 if( strcmp(azArg[1],"stmt")==0 ){
@@ -20945,10 +20998,11 @@
20945 { "pending_byte", SQLITE_TESTCTRL_PENDING_BYTE, "OFFSET " },
20946 { "prng_restore", SQLITE_TESTCTRL_PRNG_RESTORE, "" },
20947 { "prng_save", SQLITE_TESTCTRL_PRNG_SAVE, "" },
20948 { "prng_seed", SQLITE_TESTCTRL_PRNG_SEED, "SEED ?db?" },
20949 { "seek_count", SQLITE_TESTCTRL_SEEK_COUNT, "" },
 
20950 { "tune", SQLITE_TESTCTRL_TUNE, "ID VALUE" },
20951 };
20952 int testctrl = -1;
20953 int iCtrl = -1;
20954 int rc2 = 0; /* 0: usage. 1: %d 2: %x 3: no-output */
@@ -21125,10 +21179,17 @@
21125 isOk = 3;
21126 }
21127 break;
21128 }
21129 #endif
 
 
 
 
 
 
 
21130 }
21131 }
21132 if( isOk==0 && iCtrl>=0 ){
21133 utf8_printf(p->out, "Usage: .testctrl %s %s\n", zCmd,aCtrl[iCtrl].zUsage);
21134 rc = 1;
@@ -21799,10 +21860,11 @@
21799 */
21800 static void main_init(ShellState *data) {
21801 memset(data, 0, sizeof(*data));
21802 data->normalMode = data->cMode = data->mode = MODE_List;
21803 data->autoExplain = 1;
 
21804 memcpy(data->colSeparator,SEP_Column, 2);
21805 memcpy(data->rowSeparator,SEP_Row, 2);
21806 data->showHeader = 0;
21807 data->shellFlgs = SHFLG_Lookaside;
21808 verify_uninitialized();
@@ -21962,11 +22024,11 @@
21962 /* If the SQLITE_SHELL_DBNAME_PROC macro is defined, then it is the name
21963 ** of a C-function that will provide the name of the database file. Use
21964 ** this compile-time option to embed this shell program in larger
21965 ** applications. */
21966 extern void SQLITE_SHELL_DBNAME_PROC(const char**);
21967 SQLITE_SHELL_DBNAME_PROC(&data.zDbFilename);
21968 warnInmemoryDb = 0;
21969 }
21970 #endif
21971
21972 /* Do an initial pass through the command-line argument to locate
@@ -21977,12 +22039,12 @@
21977 verify_uninitialized();
21978 for(i=1; i<argc; i++){
21979 char *z;
21980 z = argv[i];
21981 if( z[0]!='-' ){
21982 if( data.zDbFilename==0 ){
21983 data.zDbFilename = z;
21984 }else{
21985 /* Excesss arguments are interpreted as SQL (or dot-commands) and
21986 ** mean that nothing is read from stdin */
21987 readStdin = 0;
21988 nCmd++;
@@ -22118,13 +22180,13 @@
22118 utf8_printf(stderr, "no such VFS: \"%s\"\n", argv[i]);
22119 exit(1);
22120 }
22121 }
22122
22123 if( data.zDbFilename==0 ){
22124 #ifndef SQLITE_OMIT_MEMORYDB
22125 data.zDbFilename = ":memory:";
22126 warnInmemoryDb = argc==1;
22127 #else
22128 utf8_printf(stderr,"%s: Error: no database filename specified\n", Argv0);
22129 return 1;
22130 #endif
@@ -22135,11 +22197,11 @@
22135 /* Go ahead and open the database file if it already exists. If the
22136 ** file does not exist, delay opening it. This prevents empty database
22137 ** files from being created if a user mistypes the database name argument
22138 ** to the sqlite command-line tool.
22139 */
22140 if( access(data.zDbFilename, 0)==0 ){
22141 open_db(&data, 0);
22142 }
22143
22144 /* Process the initialization file if there is one. If no -init option
22145 ** is given on the command line, look for a file named ~/.sqliterc and
@@ -22389,14 +22451,20 @@
22389 }
22390 }
22391 free(azCmd);
22392 set_table_name(&data, 0);
22393 if( data.db ){
22394 session_close_all(&data);
22395 close_db(data.db);
22396 }
22397 sqlite3_free(data.zFreeOnClose);
 
 
 
 
 
 
22398 find_home_dir(1);
22399 output_reset(&data);
22400 data.doXdgOpen = 0;
22401 clearTempFile(&data);
22402 #if !SQLITE_SHELL_IS_UTF8
22403
--- src/shell.c
+++ src/shell.c
@@ -999,11 +999,11 @@
999 const char *zSchema = (const char*)sqlite3_value_text(apVal[1]);
1000 const char *zName = (const char*)sqlite3_value_text(apVal[2]);
1001 sqlite3 *db = sqlite3_context_db_handle(pCtx);
1002 UNUSED_PARAMETER(nVal);
1003 if( zIn!=0 && strncmp(zIn, "CREATE ", 7)==0 ){
1004 for(i=0; i<ArraySize(aPrefix); i++){
1005 int n = strlen30(aPrefix[i]);
1006 if( strncmp(zIn+7, aPrefix[i], n)==0 && zIn[n+7]==' ' ){
1007 char *z = 0;
1008 char *zFake = 0;
1009 if( zSchema ){
@@ -12098,23 +12098,26 @@
12098 int *actualWidth; /* Actual width of each column */
12099 int nWidth; /* Number of slots in colWidth[] and actualWidth[] */
12100 char nullValue[20]; /* The text to print when a NULL comes back from
12101 ** the database */
12102 char outfile[FILENAME_MAX]; /* Filename for *out */
 
 
 
12103 sqlite3_stmt *pStmt; /* Current statement if any. */
12104 FILE *pLog; /* Write log output here */
12105 struct AuxDb { /* Storage space for auxiliary database connections */
12106 sqlite3 *db; /* Connection pointer */
12107 const char *zDbFilename; /* Filename used to open the connection */
12108 char *zFreeOnClose; /* Free this memory allocation on close */
12109 #if defined(SQLITE_ENABLE_SESSION)
12110 int nSession; /* Number of active sessions */
12111 OpenSession aSession[4]; /* Array of sessions. [0] is in focus. */
12112 #endif
12113 } aAuxDb[5], /* Array of all database connections */
12114 *pAuxDb; /* Currently active database connection */
12115 int *aiIndent; /* Array of indents used in MODE_Explain */
12116 int nIndent; /* Size of array aiIndent[] */
12117 int iIndent; /* Index of current op in aiIndent[] */
12118 EQPGraph sGraph; /* Information for the graphical EXPLAIN QUERY PLAN */
 
 
 
 
12119 ExpertInfo expert; /* Valid if previous command was ".expert OPT..." */
12120 };
12121
12122
12123 /* Allowed values for ShellState.autoEQP
@@ -14862,10 +14865,11 @@
14865 ".binary on|off Turn binary output on or off. Default OFF",
14866 ".cd DIRECTORY Change the working directory to DIRECTORY",
14867 ".changes on|off Show number of rows changed by SQL",
14868 ".check GLOB Fail if output since .testcase does not match",
14869 ".clone NEWDB Clone data into NEWDB from the existing database",
14870 ".connection [close] [#] Open or close an auxiliary database connection",
14871 ".databases List names and files of attached databases",
14872 ".dbconfig ?op? ?val? List or change sqlite3_db_config() options",
14873 ".dbinfo ?DB? Show status information about the database",
14874 ".dump ?OBJECTS? Render database content as SQL",
14875 " Options:",
@@ -15202,19 +15206,20 @@
15206
15207 /*
15208 ** Close all OpenSession objects and release all associated resources.
15209 */
15210 #if defined(SQLITE_ENABLE_SESSION)
15211 static void session_close_all(ShellState *p, int i){
15212 int j;
15213 struct AuxDb *pAuxDb = i<0 ? p->pAuxDb : &p->aAuxDb[i];
15214 for(j=0; j<pAuxDb->nSession; j++){
15215 session_close(&pAuxDb->aSession[j]);
15216 }
15217 pAuxDb->nSession = 0;
15218 }
15219 #else
15220 # define session_close_all(X,Y)
15221 #endif
15222
15223 /*
15224 ** Implementation of the xFilter function for an open session. Omit
15225 ** any tables named by ".session filter" but let all other table through.
@@ -15275,12 +15280,12 @@
15280 }
15281
15282 #ifndef SQLITE_OMIT_DESERIALIZE
15283 /*
15284 ** Reconstruct an in-memory database using the output from the "dbtotxt"
15285 ** program. Read content from the file in p->aAuxDb[].zDbFilename.
15286 ** If p->aAuxDb[].zDbFilename is 0, then read from standard input.
15287 */
15288 static unsigned char *readHexDb(ShellState *p, int *pnData){
15289 unsigned char *a = 0;
15290 int nLine;
15291 int n = 0;
@@ -15287,16 +15292,17 @@
15292 int pgsz = 0;
15293 int iOffset = 0;
15294 int j, k;
15295 int rc;
15296 FILE *in;
15297 const char *zDbFilename = p->pAuxDb->zDbFilename;
15298 unsigned int x[16];
15299 char zLine[1000];
15300 if( zDbFilename ){
15301 in = fopen(zDbFilename, "r");
15302 if( in==0 ){
15303 utf8_printf(stderr, "cannot open \"%s\" for reading\n", zDbFilename);
15304 return 0;
15305 }
15306 nLine = 0;
15307 }else{
15308 in = p->in;
@@ -15534,21 +15540,22 @@
15540 ** Make sure the database is open. If it is not, then open it. If
15541 ** the database fails to open, print an error message and exit.
15542 */
15543 static void open_db(ShellState *p, int openFlags){
15544 if( p->db==0 ){
15545 const char *zDbFilename = p->pAuxDb->zDbFilename;
15546 if( p->openMode==SHELL_OPEN_UNSPEC ){
15547 if( zDbFilename==0 || zDbFilename[0]==0 ){
15548 p->openMode = SHELL_OPEN_NORMAL;
15549 }else{
15550 p->openMode = (u8)deduceDatabaseType(zDbFilename,
15551 (openFlags & OPEN_DB_ZIPFILE)!=0);
15552 }
15553 }
15554 switch( p->openMode ){
15555 case SHELL_OPEN_APPENDVFS: {
15556 sqlite3_open_v2(zDbFilename, &p->db,
15557 SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|p->openFlags, "apndvfs");
15558 break;
15559 }
15560 case SHELL_OPEN_HEXDB:
15561 case SHELL_OPEN_DESERIALIZE: {
@@ -15558,25 +15565,25 @@
15565 case SHELL_OPEN_ZIPFILE: {
15566 sqlite3_open(":memory:", &p->db);
15567 break;
15568 }
15569 case SHELL_OPEN_READONLY: {
15570 sqlite3_open_v2(zDbFilename, &p->db,
15571 SQLITE_OPEN_READONLY|p->openFlags, 0);
15572 break;
15573 }
15574 case SHELL_OPEN_UNSPEC:
15575 case SHELL_OPEN_NORMAL: {
15576 sqlite3_open_v2(zDbFilename, &p->db,
15577 SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|p->openFlags, 0);
15578 break;
15579 }
15580 }
15581 globalDb = p->db;
15582 if( p->db==0 || SQLITE_OK!=sqlite3_errcode(p->db) ){
15583 utf8_printf(stderr,"Error: unable to open database \"%s\": %s\n",
15584 zDbFilename, sqlite3_errmsg(p->db));
15585 if( openFlags & OPEN_DB_KEEPALIVE ){
15586 sqlite3_open(":memory:", &p->db);
15587 return;
15588 }
15589 exit(1);
@@ -15619,11 +15626,11 @@
15626 sqlite3_create_function(p->db, "edit", 2, SQLITE_UTF8, 0,
15627 editFunc, 0, 0);
15628 #endif
15629 if( p->openMode==SHELL_OPEN_ZIPFILE ){
15630 char *zSql = sqlite3_mprintf(
15631 "CREATE VIRTUAL TABLE zip USING zipfile(%Q);", zDbFilename);
15632 sqlite3_exec(p->db, zSql, 0, 0, 0);
15633 sqlite3_free(zSql);
15634 }
15635 #ifndef SQLITE_OMIT_DESERIALIZE
15636 else
@@ -15630,11 +15637,11 @@
15637 if( p->openMode==SHELL_OPEN_DESERIALIZE || p->openMode==SHELL_OPEN_HEXDB ){
15638 int rc;
15639 int nData = 0;
15640 unsigned char *aData;
15641 if( p->openMode==SHELL_OPEN_DESERIALIZE ){
15642 aData = (unsigned char*)readFile(zDbFilename, &nData);
15643 }else{
15644 aData = readHexDb(p, &nData);
15645 if( aData==0 ){
15646 return;
15647 }
@@ -18351,11 +18358,10 @@
18358 sqlite3_exec(pState->db, "DETACH recovery", 0, 0, 0);
18359 return rc;
18360 }
18361 #endif /* !(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_ENABLE_DBPAGE_VTAB) */
18362
 
18363 /*
18364 ** If an input line begins with "." then invoke this routine to
18365 ** process that line.
18366 **
18367 ** Return 1 on error, 2 to exit, and 0 otherwise.
@@ -18515,10 +18521,17 @@
18521 }else{
18522 raw_printf(stderr, "Usage: .binary on|off\n");
18523 rc = 1;
18524 }
18525 }else
18526
18527 /* The undocumented ".breakpoint" command causes a call to the no-op
18528 ** routine named test_breakpoint().
18529 */
18530 if( c=='b' && n>=3 && strncmp(azArg[0], "breakpoint", n)==0 ){
18531 test_breakpoint();
18532 }else
18533
18534 if( c=='c' && strcmp(azArg[0],"cd")==0 ){
18535 if( nArg==2 ){
18536 #if defined(_WIN32) || defined(WIN32)
18537 wchar_t *z = sqlite3_win32_utf8_to_unicode(azArg[1]);
@@ -18535,17 +18548,10 @@
18548 raw_printf(stderr, "Usage: .cd DIRECTORY\n");
18549 rc = 1;
18550 }
18551 }else
18552
 
 
 
 
 
 
 
18553 if( c=='c' && n>=3 && strncmp(azArg[0], "changes", n)==0 ){
18554 if( nArg==2 ){
18555 setOrClearFlag(p, SHFLG_CountChanges, azArg[1]);
18556 }else{
18557 raw_printf(stderr, "Usage: .changes on|off\n");
@@ -18584,10 +18590,56 @@
18590 }else{
18591 raw_printf(stderr, "Usage: .clone FILENAME\n");
18592 rc = 1;
18593 }
18594 }else
18595
18596 if( c=='c' && strncmp(azArg[0], "connection", n)==0 ){
18597 if( nArg==1 ){
18598 /* List available connections */
18599 int i;
18600 for(i=0; i<ArraySize(p->aAuxDb); i++){
18601 const char *zFile = p->aAuxDb[i].zDbFilename;
18602 if( p->aAuxDb[i].db==0 && p->pAuxDb!=&p->aAuxDb[i] ){
18603 zFile = "(not open)";
18604 }else if( zFile==0 ){
18605 zFile = "(memory)";
18606 }else if( zFile[0]==0 ){
18607 zFile = "(temporary-file)";
18608 }
18609 if( p->pAuxDb == &p->aAuxDb[i] ){
18610 utf8_printf(stdout, "ACTIVE %d: %s\n", i, zFile);
18611 }else if( p->aAuxDb[i].db!=0 ){
18612 utf8_printf(stdout, " %d: %s\n", i, zFile);
18613 }
18614 }
18615 }else if( nArg==2 && IsDigit(azArg[1][0]) && azArg[1][1]==0 ){
18616 int i = azArg[1][0] - '0';
18617 if( p->pAuxDb != &p->aAuxDb[i] && i>=0 && i<ArraySize(p->aAuxDb) ){
18618 p->pAuxDb->db = p->db;
18619 p->pAuxDb = &p->aAuxDb[i];
18620 globalDb = p->db = p->pAuxDb->db;
18621 p->pAuxDb->db = 0;
18622 }
18623 }else if( nArg==3 && strcmp(azArg[1], "close")==0
18624 && IsDigit(azArg[2][0]) && azArg[2][1]==0 ){
18625 int i = azArg[2][0] - '0';
18626 if( i<0 || i>=ArraySize(p->aAuxDb) ){
18627 /* No-op */
18628 }else if( p->pAuxDb == &p->aAuxDb[i] ){
18629 raw_printf(stderr, "cannot close the active database connection\n");
18630 rc = 1;
18631 }else if( p->aAuxDb[i].db ){
18632 session_close_all(p, i);
18633 close_db(p->aAuxDb[i].db);
18634 p->aAuxDb[i].db = 0;
18635 }
18636 }else{
18637 raw_printf(stderr, "Usage: .connection [close] [CONNECTION-NUMBER]\n");
18638 rc = 1;
18639 }
18640 }else
18641
18642 if( c=='d' && n>1 && strncmp(azArg[0], "databases", n)==0 ){
18643 char **azName = 0;
18644 int nName = 0;
18645 sqlite3_stmt *pStmt;
@@ -19674,16 +19726,16 @@
19726 if( c=='o' && strncmp(azArg[0], "open", n)==0 && n>=2 ){
19727 char *zNewFilename = 0; /* Name of the database file to open */
19728 int iName = 1; /* Index in azArg[] of the filename */
19729 int newFlag = 0; /* True to delete file before opening */
19730 /* Close the existing database */
19731 session_close_all(p, -1);
19732 close_db(p->db);
19733 p->db = 0;
19734 p->pAuxDb->zDbFilename = 0;
19735 sqlite3_free(p->pAuxDb->zFreeOnClose);
19736 p->pAuxDb->zFreeOnClose = 0;
19737 p->openMode = SHELL_OPEN_UNSPEC;
19738 p->openFlags = 0;
19739 p->szMax = 0;
19740 /* Check for command-line arguments */
19741 for(iName=1; iName<nArg; iName++){
@@ -19723,22 +19775,22 @@
19775 }
19776 }
19777 /* If a filename is specified, try to open it first */
19778 if( zNewFilename || p->openMode==SHELL_OPEN_HEXDB ){
19779 if( newFlag ) shellDeleteFile(zNewFilename);
19780 p->pAuxDb->zDbFilename = zNewFilename;
19781 open_db(p, OPEN_DB_KEEPALIVE);
19782 if( p->db==0 ){
19783 utf8_printf(stderr, "Error: cannot open '%s'\n", zNewFilename);
19784 sqlite3_free(zNewFilename);
19785 }else{
19786 p->pAuxDb->zFreeOnClose = zNewFilename;
19787 }
19788 }
19789 if( p->db==0 ){
19790 /* As a fall-back open a TEMP database */
19791 p->pAuxDb->zDbFilename = 0;
19792 open_db(p, 0);
19793 }
19794 }else
19795
19796 if( (c=='o'
@@ -20263,27 +20315,28 @@
20315 sqlite3_test_control(SQLITE_TESTCTRL_TRACEFLAGS, 1, &x);
20316 }else
20317
20318 #if defined(SQLITE_ENABLE_SESSION)
20319 if( c=='s' && strncmp(azArg[0],"session",n)==0 && n>=3 ){
20320 struct AuxDb *pAuxDb = p->pAuxDb;
20321 OpenSession *pSession = &pAuxDb->aSession[0];
20322 char **azCmd = &azArg[1];
20323 int iSes = 0;
20324 int nCmd = nArg - 1;
20325 int i;
20326 if( nArg<=1 ) goto session_syntax_error;
20327 open_db(p, 0);
20328 if( nArg>=3 ){
20329 for(iSes=0; iSes<pAuxDb->nSession; iSes++){
20330 if( strcmp(pAuxDb->aSession[iSes].zName, azArg[1])==0 ) break;
20331 }
20332 if( iSes<pAuxDb->nSession ){
20333 pSession = &pAuxDb->aSession[iSes];
20334 azCmd++;
20335 nCmd--;
20336 }else{
20337 pSession = &pAuxDb->aSession[0];
20338 iSes = 0;
20339 }
20340 }
20341
20342 /* .session attach TABLE
@@ -20341,13 +20394,13 @@
20394 /* .session close
20395 ** Close the identified session
20396 */
20397 if( strcmp(azCmd[0], "close")==0 ){
20398 if( nCmd!=1 ) goto session_syntax_error;
20399 if( pAuxDb->nSession ){
20400 session_close(pSession);
20401 pAuxDb->aSession[iSes] = pAuxDb->aSession[--pAuxDb->nSession];
20402 }
20403 }else
20404
20405 /* .session enable ?BOOLEAN?
20406 ** Query or set the enable flag
@@ -20354,11 +20407,11 @@
20407 */
20408 if( strcmp(azCmd[0], "enable")==0 ){
20409 int ii;
20410 if( nCmd>2 ) goto session_syntax_error;
20411 ii = nCmd==1 ? -1 : booleanValue(azCmd[1]);
20412 if( pAuxDb->nSession ){
20413 ii = sqlite3session_enable(pSession->p, ii);
20414 utf8_printf(p->out, "session %s enable flag = %d\n",
20415 pSession->zName, ii);
20416 }
20417 }else
@@ -20367,11 +20420,11 @@
20420 ** Set a list of GLOB patterns of table names to be excluded.
20421 */
20422 if( strcmp(azCmd[0], "filter")==0 ){
20423 int ii, nByte;
20424 if( nCmd<2 ) goto session_syntax_error;
20425 if( pAuxDb->nSession ){
20426 for(ii=0; ii<pSession->nFilter; ii++){
20427 sqlite3_free(pSession->azFilter[ii]);
20428 }
20429 sqlite3_free(pSession->azFilter);
20430 nByte = sizeof(pSession->azFilter[0])*(nCmd-1);
@@ -20392,11 +20445,11 @@
20445 */
20446 if( strcmp(azCmd[0], "indirect")==0 ){
20447 int ii;
20448 if( nCmd>2 ) goto session_syntax_error;
20449 ii = nCmd==1 ? -1 : booleanValue(azCmd[1]);
20450 if( pAuxDb->nSession ){
20451 ii = sqlite3session_indirect(pSession->p, ii);
20452 utf8_printf(p->out, "session %s indirect flag = %d\n",
20453 pSession->zName, ii);
20454 }
20455 }else
@@ -20405,11 +20458,11 @@
20458 ** Determine if the session is empty
20459 */
20460 if( strcmp(azCmd[0], "isempty")==0 ){
20461 int ii;
20462 if( nCmd!=1 ) goto session_syntax_error;
20463 if( pAuxDb->nSession ){
20464 ii = sqlite3session_isempty(pSession->p);
20465 utf8_printf(p->out, "session %s isempty flag = %d\n",
20466 pSession->zName, ii);
20467 }
20468 }else
@@ -20416,12 +20469,12 @@
20469
20470 /* .session list
20471 ** List all currently open sessions
20472 */
20473 if( strcmp(azCmd[0],"list")==0 ){
20474 for(i=0; i<pAuxDb->nSession; i++){
20475 utf8_printf(p->out, "%d %s\n", i, pAuxDb->aSession[i].zName);
20476 }
20477 }else
20478
20479 /* .session open DB NAME
20480 ** Open a new session called NAME on the attached database DB.
@@ -20430,30 +20483,30 @@
20483 if( strcmp(azCmd[0],"open")==0 ){
20484 char *zName;
20485 if( nCmd!=3 ) goto session_syntax_error;
20486 zName = azCmd[2];
20487 if( zName[0]==0 ) goto session_syntax_error;
20488 for(i=0; i<pAuxDb->nSession; i++){
20489 if( strcmp(pAuxDb->aSession[i].zName,zName)==0 ){
20490 utf8_printf(stderr, "Session \"%s\" already exists\n", zName);
20491 goto meta_command_exit;
20492 }
20493 }
20494 if( pAuxDb->nSession>=ArraySize(pAuxDb->aSession) ){
20495 raw_printf(stderr, "Maximum of %d sessions\n", ArraySize(pAuxDb->aSession));
20496 goto meta_command_exit;
20497 }
20498 pSession = &pAuxDb->aSession[pAuxDb->nSession];
20499 rc = sqlite3session_create(p->db, azCmd[1], &pSession->p);
20500 if( rc ){
20501 raw_printf(stderr, "Cannot open session: error code=%d\n", rc);
20502 rc = 0;
20503 goto meta_command_exit;
20504 }
20505 pSession->nFilter = 0;
20506 sqlite3session_table_filter(pSession->p, session_filter, pSession);
20507 pAuxDb->nSession++;
20508 pSession->zName = sqlite3_mprintf("%s", zName);
20509 }else
20510 /* If no command name matches, show a syntax error */
20511 session_syntax_error:
20512 showHelp(p->out, "session");
@@ -20778,11 +20831,11 @@
20831 for (i=0;i<p->nWidth;i++) {
20832 raw_printf(p->out, "%d ", p->colWidth[i]);
20833 }
20834 raw_printf(p->out, "\n");
20835 utf8_printf(p->out, "%12.12s: %s\n", "filename",
20836 p->pAuxDb->zDbFilename ? p->pAuxDb->zDbFilename : "");
20837 }else
20838
20839 if( c=='s' && strncmp(azArg[0], "stats", n)==0 ){
20840 if( nArg==2 ){
20841 if( strcmp(azArg[1],"stmt")==0 ){
@@ -20945,10 +20998,11 @@
20998 { "pending_byte", SQLITE_TESTCTRL_PENDING_BYTE, "OFFSET " },
20999 { "prng_restore", SQLITE_TESTCTRL_PRNG_RESTORE, "" },
21000 { "prng_save", SQLITE_TESTCTRL_PRNG_SAVE, "" },
21001 { "prng_seed", SQLITE_TESTCTRL_PRNG_SEED, "SEED ?db?" },
21002 { "seek_count", SQLITE_TESTCTRL_SEEK_COUNT, "" },
21003 { "sorter_mmap", SQLITE_TESTCTRL_SORTER_MMAP, "NMAX" },
21004 { "tune", SQLITE_TESTCTRL_TUNE, "ID VALUE" },
21005 };
21006 int testctrl = -1;
21007 int iCtrl = -1;
21008 int rc2 = 0; /* 0: usage. 1: %d 2: %x 3: no-output */
@@ -21125,10 +21179,17 @@
21179 isOk = 3;
21180 }
21181 break;
21182 }
21183 #endif
21184 case SQLITE_TESTCTRL_SORTER_MMAP:
21185 if( nArg==3 ){
21186 int opt = (unsigned int)integerValue(azArg[2]);
21187 rc2 = sqlite3_test_control(testctrl, p->db, opt);
21188 isOk = 3;
21189 }
21190 break;
21191 }
21192 }
21193 if( isOk==0 && iCtrl>=0 ){
21194 utf8_printf(p->out, "Usage: .testctrl %s %s\n", zCmd,aCtrl[iCtrl].zUsage);
21195 rc = 1;
@@ -21799,10 +21860,11 @@
21860 */
21861 static void main_init(ShellState *data) {
21862 memset(data, 0, sizeof(*data));
21863 data->normalMode = data->cMode = data->mode = MODE_List;
21864 data->autoExplain = 1;
21865 data->pAuxDb = &data->aAuxDb[0];
21866 memcpy(data->colSeparator,SEP_Column, 2);
21867 memcpy(data->rowSeparator,SEP_Row, 2);
21868 data->showHeader = 0;
21869 data->shellFlgs = SHFLG_Lookaside;
21870 verify_uninitialized();
@@ -21962,11 +22024,11 @@
22024 /* If the SQLITE_SHELL_DBNAME_PROC macro is defined, then it is the name
22025 ** of a C-function that will provide the name of the database file. Use
22026 ** this compile-time option to embed this shell program in larger
22027 ** applications. */
22028 extern void SQLITE_SHELL_DBNAME_PROC(const char**);
22029 SQLITE_SHELL_DBNAME_PROC(&data.pAuxDb->zDbFilename);
22030 warnInmemoryDb = 0;
22031 }
22032 #endif
22033
22034 /* Do an initial pass through the command-line argument to locate
@@ -21977,12 +22039,12 @@
22039 verify_uninitialized();
22040 for(i=1; i<argc; i++){
22041 char *z;
22042 z = argv[i];
22043 if( z[0]!='-' ){
22044 if( data.aAuxDb->zDbFilename==0 ){
22045 data.aAuxDb->zDbFilename = z;
22046 }else{
22047 /* Excesss arguments are interpreted as SQL (or dot-commands) and
22048 ** mean that nothing is read from stdin */
22049 readStdin = 0;
22050 nCmd++;
@@ -22118,13 +22180,13 @@
22180 utf8_printf(stderr, "no such VFS: \"%s\"\n", argv[i]);
22181 exit(1);
22182 }
22183 }
22184
22185 if( data.pAuxDb->zDbFilename==0 ){
22186 #ifndef SQLITE_OMIT_MEMORYDB
22187 data.pAuxDb->zDbFilename = ":memory:";
22188 warnInmemoryDb = argc==1;
22189 #else
22190 utf8_printf(stderr,"%s: Error: no database filename specified\n", Argv0);
22191 return 1;
22192 #endif
@@ -22135,11 +22197,11 @@
22197 /* Go ahead and open the database file if it already exists. If the
22198 ** file does not exist, delay opening it. This prevents empty database
22199 ** files from being created if a user mistypes the database name argument
22200 ** to the sqlite command-line tool.
22201 */
22202 if( access(data.pAuxDb->zDbFilename, 0)==0 ){
22203 open_db(&data, 0);
22204 }
22205
22206 /* Process the initialization file if there is one. If no -init option
22207 ** is given on the command line, look for a file named ~/.sqliterc and
@@ -22389,14 +22451,20 @@
22451 }
22452 }
22453 free(azCmd);
22454 set_table_name(&data, 0);
22455 if( data.db ){
22456 session_close_all(&data, -1);
22457 close_db(data.db);
22458 }
22459 for(i=0; i<ArraySize(data.aAuxDb); i++){
22460 sqlite3_free(data.aAuxDb[i].zFreeOnClose);
22461 if( data.aAuxDb[i].db ){
22462 session_close_all(&data, i);
22463 close_db(data.aAuxDb[i].db);
22464 }
22465 }
22466 find_home_dir(1);
22467 output_reset(&data);
22468 data.doXdgOpen = 0;
22469 clearTempFile(&data);
22470 #if !SQLITE_SHELL_IS_UTF8
22471
+957 -1060
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -452,11 +452,11 @@
452452
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453453
** [sqlite_version()] and [sqlite_source_id()].
454454
*/
455455
#define SQLITE_VERSION "3.37.0"
456456
#define SQLITE_VERSION_NUMBER 3037000
457
-#define SQLITE_SOURCE_ID "2021-07-21 15:42:05 60695359dc5d3bcba68a68e1842c40f4a01650eb5af408e02fb856fd8245e16d"
457
+#define SQLITE_SOURCE_ID "2021-08-06 20:17:39 087b8b41c6ed76b55c11315e7e95679d67590be20ae21108b593d00bb7d1c57a"
458458
459459
/*
460460
** CAPI3REF: Run-Time Library Version Numbers
461461
** KEYWORDS: sqlite3_version sqlite3_sourceid
462462
**
@@ -13872,10 +13872,11 @@
1387213872
#ifndef SQLITE_PTRSIZE
1387313873
# if defined(__SIZEOF_POINTER__)
1387413874
# define SQLITE_PTRSIZE __SIZEOF_POINTER__
1387513875
# elif defined(i386) || defined(__i386__) || defined(_M_IX86) || \
1387613876
defined(_M_ARM) || defined(__arm__) || defined(__x86) || \
13877
+ (defined(__APPLE__) && defined(__POWERPC__)) || \
1387713878
(defined(__TOS_AIX__) && !defined(__64BIT__))
1387813879
# define SQLITE_PTRSIZE 4
1387913880
# else
1388013881
# define SQLITE_PTRSIZE 8
1388113882
# endif
@@ -16881,22 +16882,45 @@
1688116882
** record BLOB generated by the OP_MakeRecord
1688216883
** opcode. The storage column index is less than
1688316884
** or equal to the table column index. It is
1688416885
** equal if and only if there are no VIRTUAL
1688516886
** columns to the left.
16887
+**
16888
+** Notes on zCnName:
16889
+** The zCnName field stores the name of the column, the datatype of the
16890
+** column, and the collating sequence for the column, in that order, all in
16891
+** a single allocation. Each string is 0x00 terminated. The datatype
16892
+** is only included if the COLFLAG_HASTYPE bit of colFlags is set and the
16893
+** collating sequence name is only included if the COLFLAG_HASCOLL bit is
16894
+** set.
1688616895
*/
1688716896
struct Column {
16888
- char *zName; /* Name of this column, \000, then the type */
16889
- Expr *pDflt; /* Default value or GENERATED ALWAYS AS value */
16890
- char *zColl; /* Collating sequence. If NULL, use the default */
16891
- u8 notNull; /* An OE_ code for handling a NOT NULL constraint */
16892
- char affinity; /* One of the SQLITE_AFF_... values */
16893
- u8 szEst; /* Estimated size of value in this column. sizeof(INT)==1 */
16894
- u8 hName; /* Column name hash for faster lookup */
16895
- u16 colFlags; /* Boolean properties. See COLFLAG_ defines below */
16897
+ char *zCnName; /* Name of this column */
16898
+ unsigned notNull :4; /* An OE_ code for handling a NOT NULL constraint */
16899
+ unsigned eType :4; /* One of the standard types */
16900
+ char affinity; /* One of the SQLITE_AFF_... values */
16901
+ u8 szEst; /* Est size of value in this column. sizeof(INT)==1 */
16902
+ u8 hName; /* Column name hash for faster lookup */
16903
+ u16 iDflt; /* 1-based index of DEFAULT. 0 means "none" */
16904
+ u16 colFlags; /* Boolean properties. See COLFLAG_ defines below */
1689616905
};
1689716906
16907
+/* Allowed values for Column.eType.
16908
+**
16909
+** Values must match entries in the global constant arrays
16910
+** sqlite3StdTypeLen[] and sqlite3StdType[]. Each value is one more
16911
+** than the offset into these arrays for the corresponding name.
16912
+** Adjust the SQLITE_N_STDTYPE value if adding or removing entries.
16913
+*/
16914
+#define COLTYPE_CUSTOM 0 /* Type appended to zName */
16915
+#define COLTYPE_BLOB 1
16916
+#define COLTYPE_INT 2
16917
+#define COLTYPE_INTEGER 3
16918
+#define COLTYPE_REAL 4
16919
+#define COLTYPE_TEXT 5
16920
+#define SQLITE_N_STDTYPE 5 /* Number of standard types */
16921
+
1689816922
/* Allowed values for Column.colFlags.
1689916923
**
1690016924
** Constraints:
1690116925
** TF_HasVirtual == COLFLAG_VIRTUAL
1690216926
** TF_HasStored == COLFLAG_STORED
@@ -16909,10 +16933,11 @@
1690916933
#define COLFLAG_SORTERREF 0x0010 /* Use sorter-refs with this column */
1691016934
#define COLFLAG_VIRTUAL 0x0020 /* GENERATED ALWAYS AS ... VIRTUAL */
1691116935
#define COLFLAG_STORED 0x0040 /* GENERATED ALWAYS AS ... STORED */
1691216936
#define COLFLAG_NOTAVAIL 0x0080 /* STORED column not yet calculated */
1691316937
#define COLFLAG_BUSY 0x0100 /* Blocks recursion on GENERATED columns */
16938
+#define COLFLAG_HASCOLL 0x0200 /* Has collating sequence name in zCnName */
1691416939
#define COLFLAG_GENERATED 0x0060 /* Combo: _STORED, _VIRTUAL */
1691516940
#define COLFLAG_NOINSERT 0x0062 /* Combo: _HIDDEN, _STORED, _VIRTUAL */
1691616941
1691716942
/*
1691816943
** A "Collating Sequence" is defined by an instance of the following
@@ -17038,19 +17063,17 @@
1703817063
#define SQLITE_VTABRISK_Low 0
1703917064
#define SQLITE_VTABRISK_Normal 1
1704017065
#define SQLITE_VTABRISK_High 2
1704117066
1704217067
/*
17043
-** The schema for each SQL table and view is represented in memory
17044
-** by an instance of the following structure.
17068
+** The schema for each SQL table, virtual table, and view is represented
17069
+** in memory by an instance of the following structure.
1704517070
*/
1704617071
struct Table {
1704717072
char *zName; /* Name of the table or view */
1704817073
Column *aCol; /* Information about each column */
1704917074
Index *pIndex; /* List of SQL indexes on this table. */
17050
- Select *pSelect; /* NULL for tables. Points to definition if a view. */
17051
- FKey *pFKey; /* Linked list of all foreign keys in this table */
1705217075
char *zColAff; /* String defining the affinity of each column */
1705317076
ExprList *pCheck; /* All CHECK constraints */
1705417077
/* ... also used as column name list in a VIEW */
1705517078
Pgno tnum; /* Root BTree page for this table */
1705617079
u32 nTabRef; /* Number of pointers to this Table */
@@ -17062,19 +17085,28 @@
1706217085
LogEst szTabRow; /* Estimated size of each table row in bytes */
1706317086
#ifdef SQLITE_ENABLE_COSTMULT
1706417087
LogEst costMult; /* Cost multiplier for using this table */
1706517088
#endif
1706617089
u8 keyConf; /* What to do in case of uniqueness conflict on iPKey */
17067
-#ifndef SQLITE_OMIT_ALTERTABLE
17068
- int addColOffset; /* Offset in CREATE TABLE stmt to add a new column */
17069
-#endif
17070
-#ifndef SQLITE_OMIT_VIRTUALTABLE
17071
- int nModuleArg; /* Number of arguments to the module */
17072
- char **azModuleArg; /* 0: module 1: schema 2: vtab name 3...: args */
17073
- VTable *pVTable; /* List of VTable objects. */
17074
-#endif
17075
- Trigger *pTrigger; /* List of triggers stored in pSchema */
17090
+ u8 eTabType; /* 0: normal, 1: virtual, 2: view */
17091
+ union {
17092
+ struct { /* Used by ordinary tables: */
17093
+ int addColOffset; /* Offset in CREATE TABLE stmt to add a new column */
17094
+ FKey *pFKey; /* Linked list of all foreign keys in this table */
17095
+ ExprList *pDfltList; /* DEFAULT clauses on various columns.
17096
+ ** Or the AS clause for generated columns. */
17097
+ } tab;
17098
+ struct { /* Used by views: */
17099
+ Select *pSelect; /* View definition */
17100
+ } view;
17101
+ struct { /* Used by virtual tables only: */
17102
+ int nArg; /* Number of arguments to the module */
17103
+ char **azArg; /* 0: module 1: schema 2: vtab name 3...: args */
17104
+ VTable *p; /* List of VTable objects. */
17105
+ } vtab;
17106
+ } u;
17107
+ Trigger *pTrigger; /* List of triggers on this object */
1707617108
Schema *pSchema; /* Schema that contains this table */
1707717109
};
1707817110
1707917111
/*
1708017112
** Allowed values for Table.tabFlags.
@@ -17089,38 +17121,48 @@
1708917121
**
1709017122
** TF_HasVirtual == COLFLAG_VIRTUAL
1709117123
** TF_HasStored == COLFLAG_STORED
1709217124
** TF_HasHidden == COLFLAG_HIDDEN
1709317125
*/
17094
-#define TF_Readonly 0x0001 /* Read-only system table */
17095
-#define TF_HasHidden 0x0002 /* Has one or more hidden columns */
17096
-#define TF_HasPrimaryKey 0x0004 /* Table has a primary key */
17097
-#define TF_Autoincrement 0x0008 /* Integer primary key is autoincrement */
17098
-#define TF_HasStat1 0x0010 /* nRowLogEst set from sqlite_stat1 */
17099
-#define TF_HasVirtual 0x0020 /* Has one or more VIRTUAL columns */
17100
-#define TF_HasStored 0x0040 /* Has one or more STORED columns */
17101
-#define TF_HasGenerated 0x0060 /* Combo: HasVirtual + HasStored */
17102
-#define TF_WithoutRowid 0x0080 /* No rowid. PRIMARY KEY is the key */
17103
-#define TF_StatsUsed 0x0100 /* Query planner decisions affected by
17126
+#define TF_Readonly 0x00000001 /* Read-only system table */
17127
+#define TF_HasHidden 0x00000002 /* Has one or more hidden columns */
17128
+#define TF_HasPrimaryKey 0x00000004 /* Table has a primary key */
17129
+#define TF_Autoincrement 0x00000008 /* Integer primary key is autoincrement */
17130
+#define TF_HasStat1 0x00000010 /* nRowLogEst set from sqlite_stat1 */
17131
+#define TF_HasVirtual 0x00000020 /* Has one or more VIRTUAL columns */
17132
+#define TF_HasStored 0x00000040 /* Has one or more STORED columns */
17133
+#define TF_HasGenerated 0x00000060 /* Combo: HasVirtual + HasStored */
17134
+#define TF_WithoutRowid 0x00000080 /* No rowid. PRIMARY KEY is the key */
17135
+#define TF_StatsUsed 0x00000100 /* Query planner decisions affected by
1710417136
** Index.aiRowLogEst[] values */
17105
-#define TF_NoVisibleRowid 0x0200 /* No user-visible "rowid" column */
17106
-#define TF_OOOHidden 0x0400 /* Out-of-Order hidden columns */
17107
-#define TF_HasNotNull 0x0800 /* Contains NOT NULL constraints */
17108
-#define TF_Shadow 0x1000 /* True for a shadow table */
17109
-#define TF_HasStat4 0x2000 /* STAT4 info available for this table */
17110
-#define TF_Ephemeral 0x4000 /* An ephemeral table */
17111
-#define TF_Eponymous 0x8000 /* An eponymous virtual table */
17137
+#define TF_NoVisibleRowid 0x00000200 /* No user-visible "rowid" column */
17138
+#define TF_OOOHidden 0x00000400 /* Out-of-Order hidden columns */
17139
+#define TF_HasNotNull 0x00000800 /* Contains NOT NULL constraints */
17140
+#define TF_Shadow 0x00001000 /* True for a shadow table */
17141
+#define TF_HasStat4 0x00002000 /* STAT4 info available for this table */
17142
+#define TF_Ephemeral 0x00004000 /* An ephemeral table */
17143
+#define TF_Eponymous 0x00008000 /* An eponymous virtual table */
17144
+
17145
+/*
17146
+** Allowed values for Table.eTabType
17147
+*/
17148
+#define TABTYP_NORM 0 /* Ordinary table */
17149
+#define TABTYP_VTAB 1 /* Virtual table */
17150
+#define TABTYP_VIEW 2 /* A view */
17151
+
17152
+#define IsView(X) ((X)->eTabType==TABTYP_VIEW)
17153
+#define IsOrdinaryTable(X) ((X)->eTabType==TABTYP_NORM)
1711217154
1711317155
/*
1711417156
** Test to see whether or not a table is a virtual table. This is
1711517157
** done as a macro so that it will be optimized out when virtual
1711617158
** table support is omitted from the build.
1711717159
*/
1711817160
#ifndef SQLITE_OMIT_VIRTUALTABLE
17119
-# define IsVirtual(X) ((X)->nModuleArg)
17161
+# define IsVirtual(X) ((X)->eTabType==TABTYP_VTAB)
1712017162
# define ExprIsVtab(X) \
17121
- ((X)->op==TK_COLUMN && (X)->y.pTab!=0 && (X)->y.pTab->nModuleArg)
17163
+ ((X)->op==TK_COLUMN && (X)->y.pTab!=0 && (X)->y.pTab->eTabType==TABTYP_VTAB)
1712217164
#else
1712317165
# define IsVirtual(X) 0
1712417166
# define ExprIsVtab(X) 0
1712517167
#endif
1712617168
@@ -19170,10 +19212,11 @@
1917019212
SQLITE_PRIVATE void sqlite3SetString(char **, sqlite3*, const char*);
1917119213
SQLITE_PRIVATE void sqlite3ErrorMsg(Parse*, const char*, ...);
1917219214
SQLITE_PRIVATE int sqlite3ErrorToParser(sqlite3*,int);
1917319215
SQLITE_PRIVATE void sqlite3Dequote(char*);
1917419216
SQLITE_PRIVATE void sqlite3DequoteExpr(Expr*);
19217
+SQLITE_PRIVATE void sqlite3DequoteToken(Token*);
1917519218
SQLITE_PRIVATE void sqlite3TokenInit(Token*,char*);
1917619219
SQLITE_PRIVATE int sqlite3KeywordCode(const unsigned char*, int);
1917719220
SQLITE_PRIVATE int sqlite3RunParser(Parse*, const char*, char **);
1917819221
SQLITE_PRIVATE void sqlite3FinishCoding(Parse*);
1917919222
SQLITE_PRIVATE int sqlite3GetTempReg(Parse*);
@@ -19215,10 +19258,14 @@
1921519258
#endif
1921619259
SQLITE_PRIVATE void sqlite3ResetAllSchemasOfConnection(sqlite3*);
1921719260
SQLITE_PRIVATE void sqlite3ResetOneSchema(sqlite3*,int);
1921819261
SQLITE_PRIVATE void sqlite3CollapseDatabaseArray(sqlite3*);
1921919262
SQLITE_PRIVATE void sqlite3CommitInternalChanges(sqlite3*);
19263
+SQLITE_PRIVATE void sqlite3ColumnSetExpr(Parse*,Table*,Column*,Expr*);
19264
+SQLITE_PRIVATE Expr *sqlite3ColumnExpr(Table*,Column*);
19265
+SQLITE_PRIVATE void sqlite3ColumnSetColl(sqlite3*,Column*,const char*zColl);
19266
+SQLITE_PRIVATE const char *sqlite3ColumnColl(Column*);
1922019267
SQLITE_PRIVATE void sqlite3DeleteColumnNames(sqlite3*,Table*);
1922119268
SQLITE_PRIVATE void sqlite3GenerateColumnNames(Parse *pParse, Select *pSelect);
1922219269
SQLITE_PRIVATE int sqlite3ColumnsFromExprList(Parse*,ExprList*,i16*,Column**);
1922319270
SQLITE_PRIVATE void sqlite3SelectAddColumnTypeAndCollation(Parse*,Table*,Select*,char);
1922419271
SQLITE_PRIVATE Table *sqlite3ResultSetOfSelect(Parse*,Select*,char);
@@ -19236,11 +19283,11 @@
1923619283
#if SQLITE_ENABLE_HIDDEN_COLUMNS
1923719284
SQLITE_PRIVATE void sqlite3ColumnPropertiesFromName(Table*, Column*);
1923819285
#else
1923919286
# define sqlite3ColumnPropertiesFromName(T,C) /* no-op */
1924019287
#endif
19241
-SQLITE_PRIVATE void sqlite3AddColumn(Parse*,Token*,Token*);
19288
+SQLITE_PRIVATE void sqlite3AddColumn(Parse*,Token,Token);
1924219289
SQLITE_PRIVATE void sqlite3AddNotNull(Parse*, int);
1924319290
SQLITE_PRIVATE void sqlite3AddPrimaryKey(Parse*, ExprList*, int, int, int);
1924419291
SQLITE_PRIVATE void sqlite3AddCheckConstraint(Parse*, Expr*, const char*, const char*);
1924519292
SQLITE_PRIVATE void sqlite3AddDefaultValue(Parse*,Expr*,const char*,const char*);
1924619293
SQLITE_PRIVATE void sqlite3AddCollateType(Parse*, Token*);
@@ -19353,11 +19400,11 @@
1935319400
SQLITE_PRIVATE int sqlite3ExprCodeGetColumn(Parse*, Table*, int, int, int, u8);
1935419401
SQLITE_PRIVATE void sqlite3ExprCodeGetColumnOfTable(Vdbe*, Table*, int, int, int);
1935519402
SQLITE_PRIVATE void sqlite3ExprCodeMove(Parse*, int, int, int);
1935619403
SQLITE_PRIVATE void sqlite3ExprCode(Parse*, Expr*, int);
1935719404
#ifndef SQLITE_OMIT_GENERATED_COLUMNS
19358
-SQLITE_PRIVATE void sqlite3ExprCodeGeneratedColumn(Parse*, Column*, int);
19405
+SQLITE_PRIVATE void sqlite3ExprCodeGeneratedColumn(Parse*, Table*, Column*, int);
1935919406
#endif
1936019407
SQLITE_PRIVATE void sqlite3ExprCodeCopy(Parse*, Expr*, int);
1936119408
SQLITE_PRIVATE void sqlite3ExprCodeFactorable(Parse*, Expr*, int);
1936219409
SQLITE_PRIVATE int sqlite3ExprCodeRunJustOnce(Parse*, Expr*, int);
1936319410
SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse*, Expr*, int*);
@@ -19646,10 +19693,13 @@
1964619693
SQLITE_PRIVATE int sqlite3ValueFromExpr(sqlite3 *, Expr *, u8, u8, sqlite3_value **);
1964719694
SQLITE_PRIVATE void sqlite3ValueApplyAffinity(sqlite3_value *, u8, u8);
1964819695
#ifndef SQLITE_AMALGAMATION
1964919696
SQLITE_PRIVATE const unsigned char sqlite3OpcodeProperty[];
1965019697
SQLITE_PRIVATE const char sqlite3StrBINARY[];
19698
+SQLITE_PRIVATE const unsigned char sqlite3StdTypeLen[];
19699
+SQLITE_PRIVATE const char sqlite3StdTypeAffinity[];
19700
+SQLITE_PRIVATE const char *sqlite3StdType[];
1965119701
SQLITE_PRIVATE const unsigned char sqlite3UpperToLower[];
1965219702
SQLITE_PRIVATE const unsigned char *sqlite3aLTb;
1965319703
SQLITE_PRIVATE const unsigned char *sqlite3aEQb;
1965419704
SQLITE_PRIVATE const unsigned char *sqlite3aGTb;
1965519705
SQLITE_PRIVATE const unsigned char sqlite3CtypeMap[];
@@ -20076,10 +20126,207 @@
2007620126
#endif
2007720127
2007820128
#endif /* SQLITEINT_H */
2007920129
2008020130
/************** End of sqliteInt.h *******************************************/
20131
+/************** Begin file os_common.h ***************************************/
20132
+/*
20133
+** 2004 May 22
20134
+**
20135
+** The author disclaims copyright to this source code. In place of
20136
+** a legal notice, here is a blessing:
20137
+**
20138
+** May you do good and not evil.
20139
+** May you find forgiveness for yourself and forgive others.
20140
+** May you share freely, never taking more than you give.
20141
+**
20142
+******************************************************************************
20143
+**
20144
+** This file contains macros and a little bit of code that is common to
20145
+** all of the platform-specific files (os_*.c) and is #included into those
20146
+** files.
20147
+**
20148
+** This file should be #included by the os_*.c files only. It is not a
20149
+** general purpose header file.
20150
+*/
20151
+#ifndef _OS_COMMON_H_
20152
+#define _OS_COMMON_H_
20153
+
20154
+/*
20155
+** At least two bugs have slipped in because we changed the MEMORY_DEBUG
20156
+** macro to SQLITE_DEBUG and some older makefiles have not yet made the
20157
+** switch. The following code should catch this problem at compile-time.
20158
+*/
20159
+#ifdef MEMORY_DEBUG
20160
+# error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead."
20161
+#endif
20162
+
20163
+/*
20164
+** Macros for performance tracing. Normally turned off. Only works
20165
+** on i486 hardware.
20166
+*/
20167
+#ifdef SQLITE_PERFORMANCE_TRACE
20168
+
20169
+/*
20170
+** hwtime.h contains inline assembler code for implementing
20171
+** high-performance timing routines.
20172
+*/
20173
+/************** Include hwtime.h in the middle of os_common.h ****************/
20174
+/************** Begin file hwtime.h ******************************************/
20175
+/*
20176
+** 2008 May 27
20177
+**
20178
+** The author disclaims copyright to this source code. In place of
20179
+** a legal notice, here is a blessing:
20180
+**
20181
+** May you do good and not evil.
20182
+** May you find forgiveness for yourself and forgive others.
20183
+** May you share freely, never taking more than you give.
20184
+**
20185
+******************************************************************************
20186
+**
20187
+** This file contains inline asm code for retrieving "high-performance"
20188
+** counters for x86 and x86_64 class CPUs.
20189
+*/
20190
+#ifndef SQLITE_HWTIME_H
20191
+#define SQLITE_HWTIME_H
20192
+
20193
+/*
20194
+** The following routine only works on pentium-class (or newer) processors.
20195
+** It uses the RDTSC opcode to read the cycle count value out of the
20196
+** processor and returns that value. This can be used for high-res
20197
+** profiling.
20198
+*/
20199
+#if !defined(__STRICT_ANSI__) && \
20200
+ (defined(__GNUC__) || defined(_MSC_VER)) && \
20201
+ (defined(i386) || defined(__i386__) || defined(_M_IX86))
20202
+
20203
+ #if defined(__GNUC__)
20204
+
20205
+ __inline__ sqlite_uint64 sqlite3Hwtime(void){
20206
+ unsigned int lo, hi;
20207
+ __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi));
20208
+ return (sqlite_uint64)hi << 32 | lo;
20209
+ }
20210
+
20211
+ #elif defined(_MSC_VER)
20212
+
20213
+ __declspec(naked) __inline sqlite_uint64 __cdecl sqlite3Hwtime(void){
20214
+ __asm {
20215
+ rdtsc
20216
+ ret ; return value at EDX:EAX
20217
+ }
20218
+ }
20219
+
20220
+ #endif
20221
+
20222
+#elif !defined(__STRICT_ANSI__) && (defined(__GNUC__) && defined(__x86_64__))
20223
+
20224
+ __inline__ sqlite_uint64 sqlite3Hwtime(void){
20225
+ unsigned long val;
20226
+ __asm__ __volatile__ ("rdtsc" : "=A" (val));
20227
+ return val;
20228
+ }
20229
+
20230
+#elif !defined(__STRICT_ANSI__) && (defined(__GNUC__) && defined(__ppc__))
20231
+
20232
+ __inline__ sqlite_uint64 sqlite3Hwtime(void){
20233
+ unsigned long long retval;
20234
+ unsigned long junk;
20235
+ __asm__ __volatile__ ("\n\
20236
+ 1: mftbu %1\n\
20237
+ mftb %L0\n\
20238
+ mftbu %0\n\
20239
+ cmpw %0,%1\n\
20240
+ bne 1b"
20241
+ : "=r" (retval), "=r" (junk));
20242
+ return retval;
20243
+ }
20244
+
20245
+#else
20246
+
20247
+ /*
20248
+ ** asm() is needed for hardware timing support. Without asm(),
20249
+ ** disable the sqlite3Hwtime() routine.
20250
+ **
20251
+ ** sqlite3Hwtime() is only used for some obscure debugging
20252
+ ** and analysis configurations, not in any deliverable, so this
20253
+ ** should not be a great loss.
20254
+ */
20255
+SQLITE_PRIVATE sqlite_uint64 sqlite3Hwtime(void){ return ((sqlite_uint64)0); }
20256
+
20257
+#endif
20258
+
20259
+#endif /* !defined(SQLITE_HWTIME_H) */
20260
+
20261
+/************** End of hwtime.h **********************************************/
20262
+/************** Continuing where we left off in os_common.h ******************/
20263
+
20264
+static sqlite_uint64 g_start;
20265
+static sqlite_uint64 g_elapsed;
20266
+#define TIMER_START g_start=sqlite3Hwtime()
20267
+#define TIMER_END g_elapsed=sqlite3Hwtime()-g_start
20268
+#define TIMER_ELAPSED g_elapsed
20269
+#else
20270
+#define TIMER_START
20271
+#define TIMER_END
20272
+#define TIMER_ELAPSED ((sqlite_uint64)0)
20273
+#endif
20274
+
20275
+/*
20276
+** If we compile with the SQLITE_TEST macro set, then the following block
20277
+** of code will give us the ability to simulate a disk I/O error. This
20278
+** is used for testing the I/O recovery logic.
20279
+*/
20280
+#if defined(SQLITE_TEST)
20281
+SQLITE_API extern int sqlite3_io_error_hit;
20282
+SQLITE_API extern int sqlite3_io_error_hardhit;
20283
+SQLITE_API extern int sqlite3_io_error_pending;
20284
+SQLITE_API extern int sqlite3_io_error_persist;
20285
+SQLITE_API extern int sqlite3_io_error_benign;
20286
+SQLITE_API extern int sqlite3_diskfull_pending;
20287
+SQLITE_API extern int sqlite3_diskfull;
20288
+#define SimulateIOErrorBenign(X) sqlite3_io_error_benign=(X)
20289
+#define SimulateIOError(CODE) \
20290
+ if( (sqlite3_io_error_persist && sqlite3_io_error_hit) \
20291
+ || sqlite3_io_error_pending-- == 1 ) \
20292
+ { local_ioerr(); CODE; }
20293
+static void local_ioerr(){
20294
+ IOTRACE(("IOERR\n"));
20295
+ sqlite3_io_error_hit++;
20296
+ if( !sqlite3_io_error_benign ) sqlite3_io_error_hardhit++;
20297
+}
20298
+#define SimulateDiskfullError(CODE) \
20299
+ if( sqlite3_diskfull_pending ){ \
20300
+ if( sqlite3_diskfull_pending == 1 ){ \
20301
+ local_ioerr(); \
20302
+ sqlite3_diskfull = 1; \
20303
+ sqlite3_io_error_hit = 1; \
20304
+ CODE; \
20305
+ }else{ \
20306
+ sqlite3_diskfull_pending--; \
20307
+ } \
20308
+ }
20309
+#else
20310
+#define SimulateIOErrorBenign(X)
20311
+#define SimulateIOError(A)
20312
+#define SimulateDiskfullError(A)
20313
+#endif /* defined(SQLITE_TEST) */
20314
+
20315
+/*
20316
+** When testing, keep a count of the number of open files.
20317
+*/
20318
+#if defined(SQLITE_TEST)
20319
+SQLITE_API extern int sqlite3_open_file_count;
20320
+#define OpenCounter(X) sqlite3_open_file_count+=(X)
20321
+#else
20322
+#define OpenCounter(X)
20323
+#endif /* defined(SQLITE_TEST) */
20324
+
20325
+#endif /* !defined(_OS_COMMON_H_) */
20326
+
20327
+/************** End of os_common.h *******************************************/
2008120328
/************** Begin file ctime.c *******************************************/
2008220329
/*
2008320330
** 2010 February 23
2008420331
**
2008520332
** The author disclaims copyright to this source code. In place of
@@ -21213,10 +21460,30 @@
2121321460
2121421461
/*
2121521462
** Name of the default collating sequence
2121621463
*/
2121721464
SQLITE_PRIVATE const char sqlite3StrBINARY[] = "BINARY";
21465
+
21466
+/*
21467
+** Standard typenames. These names must match the COLTYPE_* definitions.
21468
+** Adjust the SQLITE_N_STDTYPE value if adding or removing entries.
21469
+*/
21470
+SQLITE_PRIVATE const unsigned char sqlite3StdTypeLen[] = { 4, 3, 7, 4, 4 };
21471
+SQLITE_PRIVATE const char sqlite3StdTypeAffinity[] = {
21472
+ SQLITE_AFF_BLOB,
21473
+ SQLITE_AFF_INTEGER,
21474
+ SQLITE_AFF_INTEGER,
21475
+ SQLITE_AFF_REAL,
21476
+ SQLITE_AFF_TEXT
21477
+};
21478
+SQLITE_PRIVATE const char *sqlite3StdType[] = {
21479
+ "BLOB",
21480
+ "INT",
21481
+ "INTEGER",
21482
+ "REAL",
21483
+ "TEXT"
21484
+};
2121821485
2121921486
/************** End of global.c **********************************************/
2122021487
/************** Begin file status.c ******************************************/
2122121488
/*
2122221489
** 2008 June 18
@@ -27183,209 +27450,11 @@
2718327450
2718427451
#if SQLITE_OS_WIN
2718527452
/*
2718627453
** Include code that is common to all os_*.c files
2718727454
*/
27188
-/************** Include os_common.h in the middle of mutex_w32.c *************/
27189
-/************** Begin file os_common.h ***************************************/
27190
-/*
27191
-** 2004 May 22
27192
-**
27193
-** The author disclaims copyright to this source code. In place of
27194
-** a legal notice, here is a blessing:
27195
-**
27196
-** May you do good and not evil.
27197
-** May you find forgiveness for yourself and forgive others.
27198
-** May you share freely, never taking more than you give.
27199
-**
27200
-******************************************************************************
27201
-**
27202
-** This file contains macros and a little bit of code that is common to
27203
-** all of the platform-specific files (os_*.c) and is #included into those
27204
-** files.
27205
-**
27206
-** This file should be #included by the os_*.c files only. It is not a
27207
-** general purpose header file.
27208
-*/
27209
-#ifndef _OS_COMMON_H_
27210
-#define _OS_COMMON_H_
27211
-
27212
-/*
27213
-** At least two bugs have slipped in because we changed the MEMORY_DEBUG
27214
-** macro to SQLITE_DEBUG and some older makefiles have not yet made the
27215
-** switch. The following code should catch this problem at compile-time.
27216
-*/
27217
-#ifdef MEMORY_DEBUG
27218
-# error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead."
27219
-#endif
27220
-
27221
-/*
27222
-** Macros for performance tracing. Normally turned off. Only works
27223
-** on i486 hardware.
27224
-*/
27225
-#ifdef SQLITE_PERFORMANCE_TRACE
27226
-
27227
-/*
27228
-** hwtime.h contains inline assembler code for implementing
27229
-** high-performance timing routines.
27230
-*/
27231
-/************** Include hwtime.h in the middle of os_common.h ****************/
27232
-/************** Begin file hwtime.h ******************************************/
27233
-/*
27234
-** 2008 May 27
27235
-**
27236
-** The author disclaims copyright to this source code. In place of
27237
-** a legal notice, here is a blessing:
27238
-**
27239
-** May you do good and not evil.
27240
-** May you find forgiveness for yourself and forgive others.
27241
-** May you share freely, never taking more than you give.
27242
-**
27243
-******************************************************************************
27244
-**
27245
-** This file contains inline asm code for retrieving "high-performance"
27246
-** counters for x86 and x86_64 class CPUs.
27247
-*/
27248
-#ifndef SQLITE_HWTIME_H
27249
-#define SQLITE_HWTIME_H
27250
-
27251
-/*
27252
-** The following routine only works on pentium-class (or newer) processors.
27253
-** It uses the RDTSC opcode to read the cycle count value out of the
27254
-** processor and returns that value. This can be used for high-res
27255
-** profiling.
27256
-*/
27257
-#if !defined(__STRICT_ANSI__) && \
27258
- (defined(__GNUC__) || defined(_MSC_VER)) && \
27259
- (defined(i386) || defined(__i386__) || defined(_M_IX86))
27260
-
27261
- #if defined(__GNUC__)
27262
-
27263
- __inline__ sqlite_uint64 sqlite3Hwtime(void){
27264
- unsigned int lo, hi;
27265
- __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi));
27266
- return (sqlite_uint64)hi << 32 | lo;
27267
- }
27268
-
27269
- #elif defined(_MSC_VER)
27270
-
27271
- __declspec(naked) __inline sqlite_uint64 __cdecl sqlite3Hwtime(void){
27272
- __asm {
27273
- rdtsc
27274
- ret ; return value at EDX:EAX
27275
- }
27276
- }
27277
-
27278
- #endif
27279
-
27280
-#elif !defined(__STRICT_ANSI__) && (defined(__GNUC__) && defined(__x86_64__))
27281
-
27282
- __inline__ sqlite_uint64 sqlite3Hwtime(void){
27283
- unsigned long val;
27284
- __asm__ __volatile__ ("rdtsc" : "=A" (val));
27285
- return val;
27286
- }
27287
-
27288
-#elif !defined(__STRICT_ANSI__) && (defined(__GNUC__) && defined(__ppc__))
27289
-
27290
- __inline__ sqlite_uint64 sqlite3Hwtime(void){
27291
- unsigned long long retval;
27292
- unsigned long junk;
27293
- __asm__ __volatile__ ("\n\
27294
- 1: mftbu %1\n\
27295
- mftb %L0\n\
27296
- mftbu %0\n\
27297
- cmpw %0,%1\n\
27298
- bne 1b"
27299
- : "=r" (retval), "=r" (junk));
27300
- return retval;
27301
- }
27302
-
27303
-#else
27304
-
27305
- /*
27306
- ** asm() is needed for hardware timing support. Without asm(),
27307
- ** disable the sqlite3Hwtime() routine.
27308
- **
27309
- ** sqlite3Hwtime() is only used for some obscure debugging
27310
- ** and analysis configurations, not in any deliverable, so this
27311
- ** should not be a great loss.
27312
- */
27313
-SQLITE_PRIVATE sqlite_uint64 sqlite3Hwtime(void){ return ((sqlite_uint64)0); }
27314
-
27315
-#endif
27316
-
27317
-#endif /* !defined(SQLITE_HWTIME_H) */
27318
-
27319
-/************** End of hwtime.h **********************************************/
27320
-/************** Continuing where we left off in os_common.h ******************/
27321
-
27322
-static sqlite_uint64 g_start;
27323
-static sqlite_uint64 g_elapsed;
27324
-#define TIMER_START g_start=sqlite3Hwtime()
27325
-#define TIMER_END g_elapsed=sqlite3Hwtime()-g_start
27326
-#define TIMER_ELAPSED g_elapsed
27327
-#else
27328
-#define TIMER_START
27329
-#define TIMER_END
27330
-#define TIMER_ELAPSED ((sqlite_uint64)0)
27331
-#endif
27332
-
27333
-/*
27334
-** If we compile with the SQLITE_TEST macro set, then the following block
27335
-** of code will give us the ability to simulate a disk I/O error. This
27336
-** is used for testing the I/O recovery logic.
27337
-*/
27338
-#if defined(SQLITE_TEST)
27339
-SQLITE_API extern int sqlite3_io_error_hit;
27340
-SQLITE_API extern int sqlite3_io_error_hardhit;
27341
-SQLITE_API extern int sqlite3_io_error_pending;
27342
-SQLITE_API extern int sqlite3_io_error_persist;
27343
-SQLITE_API extern int sqlite3_io_error_benign;
27344
-SQLITE_API extern int sqlite3_diskfull_pending;
27345
-SQLITE_API extern int sqlite3_diskfull;
27346
-#define SimulateIOErrorBenign(X) sqlite3_io_error_benign=(X)
27347
-#define SimulateIOError(CODE) \
27348
- if( (sqlite3_io_error_persist && sqlite3_io_error_hit) \
27349
- || sqlite3_io_error_pending-- == 1 ) \
27350
- { local_ioerr(); CODE; }
27351
-static void local_ioerr(){
27352
- IOTRACE(("IOERR\n"));
27353
- sqlite3_io_error_hit++;
27354
- if( !sqlite3_io_error_benign ) sqlite3_io_error_hardhit++;
27355
-}
27356
-#define SimulateDiskfullError(CODE) \
27357
- if( sqlite3_diskfull_pending ){ \
27358
- if( sqlite3_diskfull_pending == 1 ){ \
27359
- local_ioerr(); \
27360
- sqlite3_diskfull = 1; \
27361
- sqlite3_io_error_hit = 1; \
27362
- CODE; \
27363
- }else{ \
27364
- sqlite3_diskfull_pending--; \
27365
- } \
27366
- }
27367
-#else
27368
-#define SimulateIOErrorBenign(X)
27369
-#define SimulateIOError(A)
27370
-#define SimulateDiskfullError(A)
27371
-#endif /* defined(SQLITE_TEST) */
27372
-
27373
-/*
27374
-** When testing, keep a count of the number of open files.
27375
-*/
27376
-#if defined(SQLITE_TEST)
27377
-SQLITE_API extern int sqlite3_open_file_count;
27378
-#define OpenCounter(X) sqlite3_open_file_count+=(X)
27379
-#else
27380
-#define OpenCounter(X)
27381
-#endif /* defined(SQLITE_TEST) */
27382
-
27383
-#endif /* !defined(_OS_COMMON_H_) */
27384
-
27385
-/************** End of os_common.h *******************************************/
27386
-/************** Continuing where we left off in mutex_w32.c ******************/
27455
+/* #include "os_common.h" */
2738727456
2738827457
/*
2738927458
** Include the header file for the Windows VFS.
2739027459
*/
2739127460
/************** Include os_win.h in the middle of mutex_w32.c ****************/
@@ -30484,12 +30553,12 @@
3048430553
case TK_NULL: {
3048530554
sqlite3TreeViewLine(pView,"NULL");
3048630555
break;
3048730556
}
3048830557
case TK_TRUEFALSE: {
30489
- sqlite3TreeViewLine(pView,
30490
- sqlite3ExprTruthValue(pExpr) ? "TRUE" : "FALSE");
30558
+ sqlite3TreeViewLine(pView,"%s%s",
30559
+ sqlite3ExprTruthValue(pExpr) ? "TRUE" : "FALSE", zFlgs);
3049130560
break;
3049230561
}
3049330562
#ifndef SQLITE_OMIT_BLOB_LITERAL
3049430563
case TK_BLOB: {
3049530564
sqlite3TreeViewLine(pView,"%s", pExpr->u.zToken);
@@ -31856,12 +31925,18 @@
3185631925
**
3185731926
** The column type is an extra string stored after the zero-terminator on
3185831927
** the column name if and only if the COLFLAG_HASTYPE flag is set.
3185931928
*/
3186031929
SQLITE_PRIVATE char *sqlite3ColumnType(Column *pCol, char *zDflt){
31861
- if( (pCol->colFlags & COLFLAG_HASTYPE)==0 ) return zDflt;
31862
- return pCol->zName + strlen(pCol->zName) + 1;
31930
+ if( pCol->colFlags & COLFLAG_HASTYPE ){
31931
+ return pCol->zCnName + strlen(pCol->zCnName) + 1;
31932
+ }else if( pCol->eType ){
31933
+ assert( pCol->eType<=SQLITE_N_STDTYPE );
31934
+ return (char*)sqlite3StdType[pCol->eType-1];
31935
+ }else{
31936
+ return zDflt;
31937
+ }
3186331938
}
3186431939
3186531940
/*
3186631941
** Helper function for sqlite3Error() - called rarely. Broken out into
3186731942
** a separate routine to avoid unnecessary register saves on entry to
@@ -32032,10 +32107,32 @@
3203232107
SQLITE_PRIVATE void sqlite3DequoteExpr(Expr *p){
3203332108
assert( sqlite3Isquote(p->u.zToken[0]) );
3203432109
p->flags |= p->u.zToken[0]=='"' ? EP_Quoted|EP_DblQuoted : EP_Quoted;
3203532110
sqlite3Dequote(p->u.zToken);
3203632111
}
32112
+
32113
+/*
32114
+** If the input token p is quoted, try to adjust the token to remove
32115
+** the quotes. This is not always possible:
32116
+**
32117
+** "abc" -> abc
32118
+** "ab""cd" -> (not possible because of the interior "")
32119
+**
32120
+** Remove the quotes if possible. This is a optimization. The overall
32121
+** system should still return the correct answer even if this routine
32122
+** is always a no-op.
32123
+*/
32124
+SQLITE_PRIVATE void sqlite3DequoteToken(Token *p){
32125
+ unsigned int i;
32126
+ if( p->n<2 ) return;
32127
+ if( !sqlite3Isquote(p->z[0]) ) return;
32128
+ for(i=1; i<p->n-1; i++){
32129
+ if( sqlite3Isquote(p->z[i]) ) return;
32130
+ }
32131
+ p->n -= 2;
32132
+ p->z++;
32133
+}
3203732134
3203832135
/*
3203932136
** Generate a Token object from a string
3204032137
*/
3204132138
SQLITE_PRIVATE void sqlite3TokenInit(Token *p, char *z){
@@ -34243,209 +34340,11 @@
3424334340
#define UNIXFILE_NOLOCK 0x80 /* Do no file locking */
3424434341
3424534342
/*
3424634343
** Include code that is common to all os_*.c files
3424734344
*/
34248
-/************** Include os_common.h in the middle of os_unix.c ***************/
34249
-/************** Begin file os_common.h ***************************************/
34250
-/*
34251
-** 2004 May 22
34252
-**
34253
-** The author disclaims copyright to this source code. In place of
34254
-** a legal notice, here is a blessing:
34255
-**
34256
-** May you do good and not evil.
34257
-** May you find forgiveness for yourself and forgive others.
34258
-** May you share freely, never taking more than you give.
34259
-**
34260
-******************************************************************************
34261
-**
34262
-** This file contains macros and a little bit of code that is common to
34263
-** all of the platform-specific files (os_*.c) and is #included into those
34264
-** files.
34265
-**
34266
-** This file should be #included by the os_*.c files only. It is not a
34267
-** general purpose header file.
34268
-*/
34269
-#ifndef _OS_COMMON_H_
34270
-#define _OS_COMMON_H_
34271
-
34272
-/*
34273
-** At least two bugs have slipped in because we changed the MEMORY_DEBUG
34274
-** macro to SQLITE_DEBUG and some older makefiles have not yet made the
34275
-** switch. The following code should catch this problem at compile-time.
34276
-*/
34277
-#ifdef MEMORY_DEBUG
34278
-# error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead."
34279
-#endif
34280
-
34281
-/*
34282
-** Macros for performance tracing. Normally turned off. Only works
34283
-** on i486 hardware.
34284
-*/
34285
-#ifdef SQLITE_PERFORMANCE_TRACE
34286
-
34287
-/*
34288
-** hwtime.h contains inline assembler code for implementing
34289
-** high-performance timing routines.
34290
-*/
34291
-/************** Include hwtime.h in the middle of os_common.h ****************/
34292
-/************** Begin file hwtime.h ******************************************/
34293
-/*
34294
-** 2008 May 27
34295
-**
34296
-** The author disclaims copyright to this source code. In place of
34297
-** a legal notice, here is a blessing:
34298
-**
34299
-** May you do good and not evil.
34300
-** May you find forgiveness for yourself and forgive others.
34301
-** May you share freely, never taking more than you give.
34302
-**
34303
-******************************************************************************
34304
-**
34305
-** This file contains inline asm code for retrieving "high-performance"
34306
-** counters for x86 and x86_64 class CPUs.
34307
-*/
34308
-#ifndef SQLITE_HWTIME_H
34309
-#define SQLITE_HWTIME_H
34310
-
34311
-/*
34312
-** The following routine only works on pentium-class (or newer) processors.
34313
-** It uses the RDTSC opcode to read the cycle count value out of the
34314
-** processor and returns that value. This can be used for high-res
34315
-** profiling.
34316
-*/
34317
-#if !defined(__STRICT_ANSI__) && \
34318
- (defined(__GNUC__) || defined(_MSC_VER)) && \
34319
- (defined(i386) || defined(__i386__) || defined(_M_IX86))
34320
-
34321
- #if defined(__GNUC__)
34322
-
34323
- __inline__ sqlite_uint64 sqlite3Hwtime(void){
34324
- unsigned int lo, hi;
34325
- __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi));
34326
- return (sqlite_uint64)hi << 32 | lo;
34327
- }
34328
-
34329
- #elif defined(_MSC_VER)
34330
-
34331
- __declspec(naked) __inline sqlite_uint64 __cdecl sqlite3Hwtime(void){
34332
- __asm {
34333
- rdtsc
34334
- ret ; return value at EDX:EAX
34335
- }
34336
- }
34337
-
34338
- #endif
34339
-
34340
-#elif !defined(__STRICT_ANSI__) && (defined(__GNUC__) && defined(__x86_64__))
34341
-
34342
- __inline__ sqlite_uint64 sqlite3Hwtime(void){
34343
- unsigned long val;
34344
- __asm__ __volatile__ ("rdtsc" : "=A" (val));
34345
- return val;
34346
- }
34347
-
34348
-#elif !defined(__STRICT_ANSI__) && (defined(__GNUC__) && defined(__ppc__))
34349
-
34350
- __inline__ sqlite_uint64 sqlite3Hwtime(void){
34351
- unsigned long long retval;
34352
- unsigned long junk;
34353
- __asm__ __volatile__ ("\n\
34354
- 1: mftbu %1\n\
34355
- mftb %L0\n\
34356
- mftbu %0\n\
34357
- cmpw %0,%1\n\
34358
- bne 1b"
34359
- : "=r" (retval), "=r" (junk));
34360
- return retval;
34361
- }
34362
-
34363
-#else
34364
-
34365
- /*
34366
- ** asm() is needed for hardware timing support. Without asm(),
34367
- ** disable the sqlite3Hwtime() routine.
34368
- **
34369
- ** sqlite3Hwtime() is only used for some obscure debugging
34370
- ** and analysis configurations, not in any deliverable, so this
34371
- ** should not be a great loss.
34372
- */
34373
-SQLITE_PRIVATE sqlite_uint64 sqlite3Hwtime(void){ return ((sqlite_uint64)0); }
34374
-
34375
-#endif
34376
-
34377
-#endif /* !defined(SQLITE_HWTIME_H) */
34378
-
34379
-/************** End of hwtime.h **********************************************/
34380
-/************** Continuing where we left off in os_common.h ******************/
34381
-
34382
-static sqlite_uint64 g_start;
34383
-static sqlite_uint64 g_elapsed;
34384
-#define TIMER_START g_start=sqlite3Hwtime()
34385
-#define TIMER_END g_elapsed=sqlite3Hwtime()-g_start
34386
-#define TIMER_ELAPSED g_elapsed
34387
-#else
34388
-#define TIMER_START
34389
-#define TIMER_END
34390
-#define TIMER_ELAPSED ((sqlite_uint64)0)
34391
-#endif
34392
-
34393
-/*
34394
-** If we compile with the SQLITE_TEST macro set, then the following block
34395
-** of code will give us the ability to simulate a disk I/O error. This
34396
-** is used for testing the I/O recovery logic.
34397
-*/
34398
-#if defined(SQLITE_TEST)
34399
-SQLITE_API extern int sqlite3_io_error_hit;
34400
-SQLITE_API extern int sqlite3_io_error_hardhit;
34401
-SQLITE_API extern int sqlite3_io_error_pending;
34402
-SQLITE_API extern int sqlite3_io_error_persist;
34403
-SQLITE_API extern int sqlite3_io_error_benign;
34404
-SQLITE_API extern int sqlite3_diskfull_pending;
34405
-SQLITE_API extern int sqlite3_diskfull;
34406
-#define SimulateIOErrorBenign(X) sqlite3_io_error_benign=(X)
34407
-#define SimulateIOError(CODE) \
34408
- if( (sqlite3_io_error_persist && sqlite3_io_error_hit) \
34409
- || sqlite3_io_error_pending-- == 1 ) \
34410
- { local_ioerr(); CODE; }
34411
-static void local_ioerr(){
34412
- IOTRACE(("IOERR\n"));
34413
- sqlite3_io_error_hit++;
34414
- if( !sqlite3_io_error_benign ) sqlite3_io_error_hardhit++;
34415
-}
34416
-#define SimulateDiskfullError(CODE) \
34417
- if( sqlite3_diskfull_pending ){ \
34418
- if( sqlite3_diskfull_pending == 1 ){ \
34419
- local_ioerr(); \
34420
- sqlite3_diskfull = 1; \
34421
- sqlite3_io_error_hit = 1; \
34422
- CODE; \
34423
- }else{ \
34424
- sqlite3_diskfull_pending--; \
34425
- } \
34426
- }
34427
-#else
34428
-#define SimulateIOErrorBenign(X)
34429
-#define SimulateIOError(A)
34430
-#define SimulateDiskfullError(A)
34431
-#endif /* defined(SQLITE_TEST) */
34432
-
34433
-/*
34434
-** When testing, keep a count of the number of open files.
34435
-*/
34436
-#if defined(SQLITE_TEST)
34437
-SQLITE_API extern int sqlite3_open_file_count;
34438
-#define OpenCounter(X) sqlite3_open_file_count+=(X)
34439
-#else
34440
-#define OpenCounter(X)
34441
-#endif /* defined(SQLITE_TEST) */
34442
-
34443
-#endif /* !defined(_OS_COMMON_H_) */
34444
-
34445
-/************** End of os_common.h *******************************************/
34446
-/************** Continuing where we left off in os_unix.c ********************/
34345
+/* #include "os_common.h" */
3444734346
3444834347
/*
3444934348
** Define various macros that are missing from some systems.
3445034349
*/
3445134350
#ifndef O_LARGEFILE
@@ -42271,209 +42170,11 @@
4227142170
#if SQLITE_OS_WIN /* This file is used for Windows only */
4227242171
4227342172
/*
4227442173
** Include code that is common to all os_*.c files
4227542174
*/
42276
-/************** Include os_common.h in the middle of os_win.c ****************/
42277
-/************** Begin file os_common.h ***************************************/
42278
-/*
42279
-** 2004 May 22
42280
-**
42281
-** The author disclaims copyright to this source code. In place of
42282
-** a legal notice, here is a blessing:
42283
-**
42284
-** May you do good and not evil.
42285
-** May you find forgiveness for yourself and forgive others.
42286
-** May you share freely, never taking more than you give.
42287
-**
42288
-******************************************************************************
42289
-**
42290
-** This file contains macros and a little bit of code that is common to
42291
-** all of the platform-specific files (os_*.c) and is #included into those
42292
-** files.
42293
-**
42294
-** This file should be #included by the os_*.c files only. It is not a
42295
-** general purpose header file.
42296
-*/
42297
-#ifndef _OS_COMMON_H_
42298
-#define _OS_COMMON_H_
42299
-
42300
-/*
42301
-** At least two bugs have slipped in because we changed the MEMORY_DEBUG
42302
-** macro to SQLITE_DEBUG and some older makefiles have not yet made the
42303
-** switch. The following code should catch this problem at compile-time.
42304
-*/
42305
-#ifdef MEMORY_DEBUG
42306
-# error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead."
42307
-#endif
42308
-
42309
-/*
42310
-** Macros for performance tracing. Normally turned off. Only works
42311
-** on i486 hardware.
42312
-*/
42313
-#ifdef SQLITE_PERFORMANCE_TRACE
42314
-
42315
-/*
42316
-** hwtime.h contains inline assembler code for implementing
42317
-** high-performance timing routines.
42318
-*/
42319
-/************** Include hwtime.h in the middle of os_common.h ****************/
42320
-/************** Begin file hwtime.h ******************************************/
42321
-/*
42322
-** 2008 May 27
42323
-**
42324
-** The author disclaims copyright to this source code. In place of
42325
-** a legal notice, here is a blessing:
42326
-**
42327
-** May you do good and not evil.
42328
-** May you find forgiveness for yourself and forgive others.
42329
-** May you share freely, never taking more than you give.
42330
-**
42331
-******************************************************************************
42332
-**
42333
-** This file contains inline asm code for retrieving "high-performance"
42334
-** counters for x86 and x86_64 class CPUs.
42335
-*/
42336
-#ifndef SQLITE_HWTIME_H
42337
-#define SQLITE_HWTIME_H
42338
-
42339
-/*
42340
-** The following routine only works on pentium-class (or newer) processors.
42341
-** It uses the RDTSC opcode to read the cycle count value out of the
42342
-** processor and returns that value. This can be used for high-res
42343
-** profiling.
42344
-*/
42345
-#if !defined(__STRICT_ANSI__) && \
42346
- (defined(__GNUC__) || defined(_MSC_VER)) && \
42347
- (defined(i386) || defined(__i386__) || defined(_M_IX86))
42348
-
42349
- #if defined(__GNUC__)
42350
-
42351
- __inline__ sqlite_uint64 sqlite3Hwtime(void){
42352
- unsigned int lo, hi;
42353
- __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi));
42354
- return (sqlite_uint64)hi << 32 | lo;
42355
- }
42356
-
42357
- #elif defined(_MSC_VER)
42358
-
42359
- __declspec(naked) __inline sqlite_uint64 __cdecl sqlite3Hwtime(void){
42360
- __asm {
42361
- rdtsc
42362
- ret ; return value at EDX:EAX
42363
- }
42364
- }
42365
-
42366
- #endif
42367
-
42368
-#elif !defined(__STRICT_ANSI__) && (defined(__GNUC__) && defined(__x86_64__))
42369
-
42370
- __inline__ sqlite_uint64 sqlite3Hwtime(void){
42371
- unsigned long val;
42372
- __asm__ __volatile__ ("rdtsc" : "=A" (val));
42373
- return val;
42374
- }
42375
-
42376
-#elif !defined(__STRICT_ANSI__) && (defined(__GNUC__) && defined(__ppc__))
42377
-
42378
- __inline__ sqlite_uint64 sqlite3Hwtime(void){
42379
- unsigned long long retval;
42380
- unsigned long junk;
42381
- __asm__ __volatile__ ("\n\
42382
- 1: mftbu %1\n\
42383
- mftb %L0\n\
42384
- mftbu %0\n\
42385
- cmpw %0,%1\n\
42386
- bne 1b"
42387
- : "=r" (retval), "=r" (junk));
42388
- return retval;
42389
- }
42390
-
42391
-#else
42392
-
42393
- /*
42394
- ** asm() is needed for hardware timing support. Without asm(),
42395
- ** disable the sqlite3Hwtime() routine.
42396
- **
42397
- ** sqlite3Hwtime() is only used for some obscure debugging
42398
- ** and analysis configurations, not in any deliverable, so this
42399
- ** should not be a great loss.
42400
- */
42401
-SQLITE_PRIVATE sqlite_uint64 sqlite3Hwtime(void){ return ((sqlite_uint64)0); }
42402
-
42403
-#endif
42404
-
42405
-#endif /* !defined(SQLITE_HWTIME_H) */
42406
-
42407
-/************** End of hwtime.h **********************************************/
42408
-/************** Continuing where we left off in os_common.h ******************/
42409
-
42410
-static sqlite_uint64 g_start;
42411
-static sqlite_uint64 g_elapsed;
42412
-#define TIMER_START g_start=sqlite3Hwtime()
42413
-#define TIMER_END g_elapsed=sqlite3Hwtime()-g_start
42414
-#define TIMER_ELAPSED g_elapsed
42415
-#else
42416
-#define TIMER_START
42417
-#define TIMER_END
42418
-#define TIMER_ELAPSED ((sqlite_uint64)0)
42419
-#endif
42420
-
42421
-/*
42422
-** If we compile with the SQLITE_TEST macro set, then the following block
42423
-** of code will give us the ability to simulate a disk I/O error. This
42424
-** is used for testing the I/O recovery logic.
42425
-*/
42426
-#if defined(SQLITE_TEST)
42427
-SQLITE_API extern int sqlite3_io_error_hit;
42428
-SQLITE_API extern int sqlite3_io_error_hardhit;
42429
-SQLITE_API extern int sqlite3_io_error_pending;
42430
-SQLITE_API extern int sqlite3_io_error_persist;
42431
-SQLITE_API extern int sqlite3_io_error_benign;
42432
-SQLITE_API extern int sqlite3_diskfull_pending;
42433
-SQLITE_API extern int sqlite3_diskfull;
42434
-#define SimulateIOErrorBenign(X) sqlite3_io_error_benign=(X)
42435
-#define SimulateIOError(CODE) \
42436
- if( (sqlite3_io_error_persist && sqlite3_io_error_hit) \
42437
- || sqlite3_io_error_pending-- == 1 ) \
42438
- { local_ioerr(); CODE; }
42439
-static void local_ioerr(){
42440
- IOTRACE(("IOERR\n"));
42441
- sqlite3_io_error_hit++;
42442
- if( !sqlite3_io_error_benign ) sqlite3_io_error_hardhit++;
42443
-}
42444
-#define SimulateDiskfullError(CODE) \
42445
- if( sqlite3_diskfull_pending ){ \
42446
- if( sqlite3_diskfull_pending == 1 ){ \
42447
- local_ioerr(); \
42448
- sqlite3_diskfull = 1; \
42449
- sqlite3_io_error_hit = 1; \
42450
- CODE; \
42451
- }else{ \
42452
- sqlite3_diskfull_pending--; \
42453
- } \
42454
- }
42455
-#else
42456
-#define SimulateIOErrorBenign(X)
42457
-#define SimulateIOError(A)
42458
-#define SimulateDiskfullError(A)
42459
-#endif /* defined(SQLITE_TEST) */
42460
-
42461
-/*
42462
-** When testing, keep a count of the number of open files.
42463
-*/
42464
-#if defined(SQLITE_TEST)
42465
-SQLITE_API extern int sqlite3_open_file_count;
42466
-#define OpenCounter(X) sqlite3_open_file_count+=(X)
42467
-#else
42468
-#define OpenCounter(X)
42469
-#endif /* defined(SQLITE_TEST) */
42470
-
42471
-#endif /* !defined(_OS_COMMON_H_) */
42472
-
42473
-/************** End of os_common.h *******************************************/
42474
-/************** Continuing where we left off in os_win.c *********************/
42175
+/* #include "os_common.h" */
4247542176
4247642177
/*
4247742178
** Include the header file for the Windows VFS.
4247842179
*/
4247942180
/* #include "os_win.h" */
@@ -60605,11 +60306,14 @@
6060560306
** Each index block except for the first contains information on
6060660307
** HASHTABLE_NPAGE frames. The first index block contains information on
6060760308
** HASHTABLE_NPAGE_ONE frames. The values of HASHTABLE_NPAGE_ONE and
6060860309
** HASHTABLE_NPAGE are selected so that together the wal-index header and
6060960310
** first index block are the same size as all other index blocks in the
60610
-** wal-index.
60311
+** wal-index. The values are:
60312
+**
60313
+** HASHTABLE_NPAGE 4096
60314
+** HASHTABLE_NPAGE_ONE 4062
6061160315
**
6061260316
** Each index block contains two sections, a page-mapping that contains the
6061360317
** database page number associated with each wal frame, and a hash-table
6061460318
** that allows readers to query an index block for a specific page number.
6061560319
** The page-mapping is an array of HASHTABLE_NPAGE (or HASHTABLE_NPAGE_ONE
@@ -60841,10 +60545,74 @@
6084160545
u32 nBackfillAttempted; /* WAL frames perhaps written, or maybe not */
6084260546
u32 notUsed0; /* Available for future enhancements */
6084360547
};
6084460548
#define READMARK_NOT_USED 0xffffffff
6084560549
60550
+/*
60551
+** This is a schematic view of the complete 136-byte header of the
60552
+** wal-index file (also known as the -shm file):
60553
+**
60554
+** +-----------------------------+
60555
+** 0: | iVersion | \
60556
+** +-----------------------------+ |
60557
+** 4: | (unused padding) | |
60558
+** +-----------------------------+ |
60559
+** 8: | iChange | |
60560
+** +-------+-------+-------------+ |
60561
+** 12: | bInit | bBig | szPage | |
60562
+** +-------+-------+-------------+ |
60563
+** 16: | mxFrame | | First copy of the
60564
+** +-----------------------------+ | WalIndexHdr object
60565
+** 20: | nPage | |
60566
+** +-----------------------------+ |
60567
+** 24: | aFrameCksum | |
60568
+** | | |
60569
+** +-----------------------------+ |
60570
+** 32: | aSalt | |
60571
+** | | |
60572
+** +-----------------------------+ |
60573
+** 40: | aCksum | |
60574
+** | | /
60575
+** +-----------------------------+
60576
+** 48: | iVersion | \
60577
+** +-----------------------------+ |
60578
+** 52: | (unused padding) | |
60579
+** +-----------------------------+ |
60580
+** 56: | iChange | |
60581
+** +-------+-------+-------------+ |
60582
+** 60: | bInit | bBig | szPage | |
60583
+** +-------+-------+-------------+ | Second copy of the
60584
+** 64: | mxFrame | | WalIndexHdr
60585
+** +-----------------------------+ |
60586
+** 68: | nPage | |
60587
+** +-----------------------------+ |
60588
+** 72: | aFrameCksum | |
60589
+** | | |
60590
+** +-----------------------------+ |
60591
+** 80: | aSalt | |
60592
+** | | |
60593
+** +-----------------------------+ |
60594
+** 88: | aCksum | |
60595
+** | | /
60596
+** +-----------------------------+
60597
+** 96: | nBackfill |
60598
+** +-----------------------------+
60599
+** 100: | 5 read marks |
60600
+** | |
60601
+** | |
60602
+** | |
60603
+** | |
60604
+** +-------+-------+------+------+
60605
+** 120: | Write | Ckpt | Rcvr | Rd0 | \
60606
+** +-------+-------+------+------+ ) 8 lock bytes
60607
+** | Read1 | Read2 | Rd3 | Rd4 | /
60608
+** +-------+-------+------+------+
60609
+** 128: | nBackfillAttempted |
60610
+** +-----------------------------+
60611
+** 132: | (unused padding) |
60612
+** +-----------------------------+
60613
+*/
6084660614
6084760615
/* A block of WALINDEX_LOCK_RESERVED bytes beginning at
6084860616
** WALINDEX_LOCK_OFFSET is reserved for locks. Since some systems
6084960617
** only support mandatory file-locks, we do not read or write data
6085060618
** from the region of the file on which locks are applied.
@@ -61853,19 +61621,48 @@
6185361621
Wal *pRet; /* Object to allocate and return */
6185461622
int flags; /* Flags passed to OsOpen() */
6185561623
6185661624
assert( zWalName && zWalName[0] );
6185761625
assert( pDbFd );
61626
+
61627
+ /* Verify the values of various constants. Any changes to the values
61628
+ ** of these constants would result in an incompatible on-disk format
61629
+ ** for the -shm file. Any change that causes one of these asserts to
61630
+ ** fail is a backward compatibility problem, even if the change otherwise
61631
+ ** works.
61632
+ **
61633
+ ** This table also serves as a helpful cross-reference when trying to
61634
+ ** interpret hex dumps of the -shm file.
61635
+ */
61636
+ assert( 48 == sizeof(WalIndexHdr) );
61637
+ assert( 40 == sizeof(WalCkptInfo) );
61638
+ assert( 120 == WALINDEX_LOCK_OFFSET );
61639
+ assert( 136 == WALINDEX_HDR_SIZE );
61640
+ assert( 4096 == HASHTABLE_NPAGE );
61641
+ assert( 4062 == HASHTABLE_NPAGE_ONE );
61642
+ assert( 8192 == HASHTABLE_NSLOT );
61643
+ assert( 383 == HASHTABLE_HASH_1 );
61644
+ assert( 32768 == WALINDEX_PGSZ );
61645
+ assert( 8 == SQLITE_SHM_NLOCK );
61646
+ assert( 5 == WAL_NREADER );
61647
+ assert( 24 == WAL_FRAME_HDRSIZE );
61648
+ assert( 32 == WAL_HDRSIZE );
61649
+ assert( 120 == WALINDEX_LOCK_OFFSET + WAL_WRITE_LOCK );
61650
+ assert( 121 == WALINDEX_LOCK_OFFSET + WAL_CKPT_LOCK );
61651
+ assert( 122 == WALINDEX_LOCK_OFFSET + WAL_RECOVER_LOCK );
61652
+ assert( 123 == WALINDEX_LOCK_OFFSET + WAL_READ_LOCK(0) );
61653
+ assert( 124 == WALINDEX_LOCK_OFFSET + WAL_READ_LOCK(1) );
61654
+ assert( 125 == WALINDEX_LOCK_OFFSET + WAL_READ_LOCK(2) );
61655
+ assert( 126 == WALINDEX_LOCK_OFFSET + WAL_READ_LOCK(3) );
61656
+ assert( 127 == WALINDEX_LOCK_OFFSET + WAL_READ_LOCK(4) );
6185861657
6185961658
/* In the amalgamation, the os_unix.c and os_win.c source files come before
6186061659
** this source file. Verify that the #defines of the locking byte offsets
6186161660
** in os_unix.c and os_win.c agree with the WALINDEX_LOCK_OFFSET value.
6186261661
** For that matter, if the lock offset ever changes from its initial design
6186361662
** value of 120, we need to know that so there is an assert() to check it.
6186461663
*/
61865
- assert( 120==WALINDEX_LOCK_OFFSET );
61866
- assert( 136==WALINDEX_HDR_SIZE );
6186761664
#ifdef WIN_SHM_BASE
6186861665
assert( WIN_SHM_BASE==WALINDEX_LOCK_OFFSET );
6186961666
#endif
6187061667
#ifdef UNIX_SHM_BASE
6187161668
assert( UNIX_SHM_BASE==WALINDEX_LOCK_OFFSET );
@@ -80741,11 +80538,11 @@
8074180538
}
8074280539
#endif
8074380540
case P4_COLLSEQ: {
8074480541
static const char *const encnames[] = {"?", "8", "16LE", "16BE"};
8074580542
CollSeq *pColl = pOp->p4.pColl;
80746
- assert( pColl->enc>=0 && pColl->enc<4 );
80543
+ assert( pColl->enc<4 );
8074780544
sqlite3_str_appendf(&x, "%.18s-%s", pColl->zName,
8074880545
encnames[pColl->enc]);
8074980546
break;
8075080547
}
8075180548
case P4_FUNCDEF: {
@@ -87207,100 +87004,11 @@
8720787004
8720887005
/*
8720987006
** hwtime.h contains inline assembler code for implementing
8721087007
** high-performance timing routines.
8721187008
*/
87212
-/************** Include hwtime.h in the middle of vdbe.c *********************/
87213
-/************** Begin file hwtime.h ******************************************/
87214
-/*
87215
-** 2008 May 27
87216
-**
87217
-** The author disclaims copyright to this source code. In place of
87218
-** a legal notice, here is a blessing:
87219
-**
87220
-** May you do good and not evil.
87221
-** May you find forgiveness for yourself and forgive others.
87222
-** May you share freely, never taking more than you give.
87223
-**
87224
-******************************************************************************
87225
-**
87226
-** This file contains inline asm code for retrieving "high-performance"
87227
-** counters for x86 and x86_64 class CPUs.
87228
-*/
87229
-#ifndef SQLITE_HWTIME_H
87230
-#define SQLITE_HWTIME_H
87231
-
87232
-/*
87233
-** The following routine only works on pentium-class (or newer) processors.
87234
-** It uses the RDTSC opcode to read the cycle count value out of the
87235
-** processor and returns that value. This can be used for high-res
87236
-** profiling.
87237
-*/
87238
-#if !defined(__STRICT_ANSI__) && \
87239
- (defined(__GNUC__) || defined(_MSC_VER)) && \
87240
- (defined(i386) || defined(__i386__) || defined(_M_IX86))
87241
-
87242
- #if defined(__GNUC__)
87243
-
87244
- __inline__ sqlite_uint64 sqlite3Hwtime(void){
87245
- unsigned int lo, hi;
87246
- __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi));
87247
- return (sqlite_uint64)hi << 32 | lo;
87248
- }
87249
-
87250
- #elif defined(_MSC_VER)
87251
-
87252
- __declspec(naked) __inline sqlite_uint64 __cdecl sqlite3Hwtime(void){
87253
- __asm {
87254
- rdtsc
87255
- ret ; return value at EDX:EAX
87256
- }
87257
- }
87258
-
87259
- #endif
87260
-
87261
-#elif !defined(__STRICT_ANSI__) && (defined(__GNUC__) && defined(__x86_64__))
87262
-
87263
- __inline__ sqlite_uint64 sqlite3Hwtime(void){
87264
- unsigned long val;
87265
- __asm__ __volatile__ ("rdtsc" : "=A" (val));
87266
- return val;
87267
- }
87268
-
87269
-#elif !defined(__STRICT_ANSI__) && (defined(__GNUC__) && defined(__ppc__))
87270
-
87271
- __inline__ sqlite_uint64 sqlite3Hwtime(void){
87272
- unsigned long long retval;
87273
- unsigned long junk;
87274
- __asm__ __volatile__ ("\n\
87275
- 1: mftbu %1\n\
87276
- mftb %L0\n\
87277
- mftbu %0\n\
87278
- cmpw %0,%1\n\
87279
- bne 1b"
87280
- : "=r" (retval), "=r" (junk));
87281
- return retval;
87282
- }
87283
-
87284
-#else
87285
-
87286
- /*
87287
- ** asm() is needed for hardware timing support. Without asm(),
87288
- ** disable the sqlite3Hwtime() routine.
87289
- **
87290
- ** sqlite3Hwtime() is only used for some obscure debugging
87291
- ** and analysis configurations, not in any deliverable, so this
87292
- ** should not be a great loss.
87293
- */
87294
-SQLITE_PRIVATE sqlite_uint64 sqlite3Hwtime(void){ return ((sqlite_uint64)0); }
87295
-
87296
-#endif
87297
-
87298
-#endif /* !defined(SQLITE_HWTIME_H) */
87299
-
87300
-/************** End of hwtime.h **********************************************/
87301
-/************** Continuing where we left off in vdbe.c ***********************/
87009
+/* #include "hwtime.h" */
8730287010
8730387011
#endif
8730487012
8730587013
#ifndef NDEBUG
8730687014
/*
@@ -95148,11 +94856,11 @@
9514894856
if( pTab && !HasRowid(pTab) ){
9514994857
pTab = 0;
9515094858
sqlite3ErrorMsg(&sParse, "cannot open table without rowid: %s", zTable);
9515194859
}
9515294860
#ifndef SQLITE_OMIT_VIEW
95153
- if( pTab && pTab->pSelect ){
94861
+ if( pTab && IsView(pTab) ){
9515494862
pTab = 0;
9515594863
sqlite3ErrorMsg(&sParse, "cannot open view: %s", zTable);
9515694864
}
9515794865
#endif
9515894866
if( !pTab ){
@@ -95168,11 +94876,11 @@
9516894876
pBlob->pTab = pTab;
9516994877
pBlob->zDb = db->aDb[sqlite3SchemaToIndex(db, pTab->pSchema)].zDbSName;
9517094878
9517194879
/* Now search pTab for the exact column. */
9517294880
for(iCol=0; iCol<pTab->nCol; iCol++) {
95173
- if( sqlite3StrICmp(pTab->aCol[iCol].zName, zColumn)==0 ){
94881
+ if( sqlite3StrICmp(pTab->aCol[iCol].zCnName, zColumn)==0 ){
9517494882
break;
9517594883
}
9517694884
}
9517794885
if( iCol==pTab->nCol ){
9517894886
sqlite3DbFree(db, zErr);
@@ -95193,11 +94901,12 @@
9519394901
/* Check that the column is not part of an FK child key definition. It
9519494902
** is not necessary to check if it is part of a parent key, as parent
9519594903
** key columns must be indexed. The check below will pick up this
9519694904
** case. */
9519794905
FKey *pFKey;
95198
- for(pFKey=pTab->pFKey; pFKey; pFKey=pFKey->pNextFrom){
94906
+ assert( !IsVirtual(pTab) );
94907
+ for(pFKey=pTab->u.tab.pFKey; pFKey; pFKey=pFKey->pNextFrom){
9519994908
int j;
9520094909
for(j=0; j<pFKey->nCol; j++){
9520194910
if( pFKey->aCol[j].iFrom==iCol ){
9520294911
zFault = "foreign key";
9520394912
}
@@ -99719,11 +99428,13 @@
9971999428
sqlite3RenameTokenRemap(pParse, 0, (void*)&pExpr->y.pTab);
9972099429
}
9972199430
}
9972299431
hCol = sqlite3StrIHash(zCol);
9972399432
for(j=0, pCol=pTab->aCol; j<pTab->nCol; j++, pCol++){
99724
- if( pCol->hName==hCol && sqlite3StrICmp(pCol->zName, zCol)==0 ){
99433
+ if( pCol->hName==hCol
99434
+ && sqlite3StrICmp(pCol->zCnName, zCol)==0
99435
+ ){
9972599436
/* If there has been exactly one prior match and this match
9972699437
** is for the right-hand table of a NATURAL JOIN or is in a
9972799438
** USING clause, then skip this match.
9972899439
*/
9972999440
if( cnt==1 ){
@@ -99796,11 +99507,13 @@
9979699507
int iCol;
9979799508
u8 hCol = sqlite3StrIHash(zCol);
9979899509
pSchema = pTab->pSchema;
9979999510
cntTab++;
9980099511
for(iCol=0, pCol=pTab->aCol; iCol<pTab->nCol; iCol++, pCol++){
99801
- if( pCol->hName==hCol && sqlite3StrICmp(pCol->zName, zCol)==0 ){
99512
+ if( pCol->hName==hCol
99513
+ && sqlite3StrICmp(pCol->zCnName, zCol)==0
99514
+ ){
9980299515
if( iCol==pTab->iPKey ){
9980399516
iCol = -1;
9980499517
}
9980599518
break;
9980699519
}
@@ -100204,10 +99917,11 @@
10020499917
for(i=0, p=pNC; p && i<ArraySize(anRef); p=p->pNext, i++){
10020599918
anRef[i] = p->nRef;
10020699919
}
10020799920
sqlite3WalkExpr(pWalker, pExpr->pLeft);
10020899921
if( 0==sqlite3ExprCanBeNull(pExpr->pLeft) && !IN_RENAME_OBJECT ){
99922
+ testcase( ExprHasProperty(pExpr, EP_FromJoin) );
10020999923
if( pExpr->op==TK_NOTNULL ){
10021099924
pExpr->u.zToken = "true";
10021199925
ExprSetProperty(pExpr, EP_IsTrue);
10021299926
}else{
10021399927
pExpr->u.zToken = "false";
@@ -101582,11 +101296,11 @@
101582101296
){
101583101297
/* op==TK_REGISTER && p->y.pTab!=0 happens when pExpr was originally
101584101298
** a TK_COLUMN but was previously evaluated and cached in a register */
101585101299
int j = p->iColumn;
101586101300
if( j>=0 ){
101587
- const char *zColl = p->y.pTab->aCol[j].zColl;
101301
+ const char *zColl = sqlite3ColumnColl(&p->y.pTab->aCol[j]);
101588101302
pColl = sqlite3FindCollSeq(db, ENC(db), zColl, 0);
101589101303
}
101590101304
break;
101591101305
}
101592101306
if( op==TK_CAST || op==TK_UPLUS ){
@@ -103922,11 +103636,11 @@
103922103636
assert( pSrc!=0 );
103923103637
if( pSrc->nSrc!=1 ) return 0; /* Single term in FROM clause */
103924103638
if( pSrc->a[0].pSelect ) return 0; /* FROM is not a subquery or view */
103925103639
pTab = pSrc->a[0].pTab;
103926103640
assert( pTab!=0 );
103927
- assert( pTab->pSelect==0 ); /* FROM clause is not a view */
103641
+ assert( !IsView(pTab) ); /* FROM clause is not a view */
103928103642
if( IsVirtual(pTab) ) return 0; /* FROM clause not a virtual table */
103929103643
pEList = p->pEList;
103930103644
assert( pEList!=0 );
103931103645
/* All SELECT results must be columns. */
103932103646
for(i=0; i<pEList->nExpr; i++){
@@ -105052,13 +104766,14 @@
105052104766
/*
105053104767
** Generate code that will compute the value of generated column pCol
105054104768
** and store the result in register regOut
105055104769
*/
105056104770
SQLITE_PRIVATE void sqlite3ExprCodeGeneratedColumn(
105057
- Parse *pParse,
105058
- Column *pCol,
105059
- int regOut
104771
+ Parse *pParse, /* Parsing context */
104772
+ Table *pTab, /* Table containing the generated column */
104773
+ Column *pCol, /* The generated column */
104774
+ int regOut /* Put the result in this register */
105060104775
){
105061104776
int iAddr;
105062104777
Vdbe *v = pParse->pVdbe;
105063104778
assert( v!=0 );
105064104779
assert( pParse->iSelfTab!=0 );
@@ -105065,11 +104780,11 @@
105065104780
if( pParse->iSelfTab>0 ){
105066104781
iAddr = sqlite3VdbeAddOp3(v, OP_IfNullRow, pParse->iSelfTab-1, 0, regOut);
105067104782
}else{
105068104783
iAddr = 0;
105069104784
}
105070
- sqlite3ExprCodeCopy(pParse, pCol->pDflt, regOut);
104785
+ sqlite3ExprCodeCopy(pParse, sqlite3ColumnExpr(pTab,pCol), regOut);
105071104786
if( pCol->affinity>=SQLITE_AFF_TEXT ){
105072104787
sqlite3VdbeAddOp4(v, OP_Affinity, regOut, 1, 0, &pCol->affinity, 1);
105073104788
}
105074104789
if( iAddr ) sqlite3VdbeJumpHere(v, iAddr);
105075104790
}
@@ -105101,16 +104816,17 @@
105101104816
x = iCol;
105102104817
#ifndef SQLITE_OMIT_GENERATED_COLUMNS
105103104818
}else if( (pCol = &pTab->aCol[iCol])->colFlags & COLFLAG_VIRTUAL ){
105104104819
Parse *pParse = sqlite3VdbeParser(v);
105105104820
if( pCol->colFlags & COLFLAG_BUSY ){
105106
- sqlite3ErrorMsg(pParse, "generated column loop on \"%s\"", pCol->zName);
104821
+ sqlite3ErrorMsg(pParse, "generated column loop on \"%s\"",
104822
+ pCol->zCnName);
105107104823
}else{
105108104824
int savedSelfTab = pParse->iSelfTab;
105109104825
pCol->colFlags |= COLFLAG_BUSY;
105110104826
pParse->iSelfTab = iTabCur+1;
105111
- sqlite3ExprCodeGeneratedColumn(pParse, pCol, regOut);
104827
+ sqlite3ExprCodeGeneratedColumn(pParse, pTab, pCol, regOut);
105112104828
pParse->iSelfTab = savedSelfTab;
105113104829
pCol->colFlags &= ~COLFLAG_BUSY;
105114104830
}
105115104831
return;
105116104832
#endif
@@ -105374,11 +105090,12 @@
105374105090
sqlite3VdbeAddOp3(v, OP_Column, pAggInfo->sortingIdxPTab,
105375105091
pCol->iSorterColumn, target);
105376105092
if( pCol->iColumn<0 ){
105377105093
VdbeComment((v,"%s.rowid",pTab->zName));
105378105094
}else{
105379
- VdbeComment((v,"%s.%s",pTab->zName,pTab->aCol[pCol->iColumn].zName));
105095
+ VdbeComment((v,"%s.%s",
105096
+ pTab->zName, pTab->aCol[pCol->iColumn].zCnName));
105380105097
if( pTab->aCol[pCol->iColumn].affinity==SQLITE_AFF_REAL ){
105381105098
sqlite3VdbeAddOp1(v, OP_RealAffinity, target);
105382105099
}
105383105100
}
105384105101
return target;
@@ -105435,16 +105152,16 @@
105435105152
iSrc = sqlite3TableColumnToStorage(pTab, iCol) - pParse->iSelfTab;
105436105153
#ifndef SQLITE_OMIT_GENERATED_COLUMNS
105437105154
if( pCol->colFlags & COLFLAG_GENERATED ){
105438105155
if( pCol->colFlags & COLFLAG_BUSY ){
105439105156
sqlite3ErrorMsg(pParse, "generated column loop on \"%s\"",
105440
- pCol->zName);
105157
+ pCol->zCnName);
105441105158
return 0;
105442105159
}
105443105160
pCol->colFlags |= COLFLAG_BUSY;
105444105161
if( pCol->colFlags & COLFLAG_NOTAVAIL ){
105445
- sqlite3ExprCodeGeneratedColumn(pParse, pCol, iSrc);
105162
+ sqlite3ExprCodeGeneratedColumn(pParse, pTab, pCol, iSrc);
105446105163
}
105447105164
pCol->colFlags &= ~(COLFLAG_BUSY|COLFLAG_NOTAVAIL);
105448105165
return iSrc;
105449105166
}else
105450105167
#endif /* SQLITE_OMIT_GENERATED_COLUMNS */
@@ -105918,11 +105635,11 @@
105918105635
assert( p1>=0 && p1<(pTab->nCol*2+2) );
105919105636
105920105637
sqlite3VdbeAddOp2(v, OP_Param, p1, target);
105921105638
VdbeComment((v, "r[%d]=%s.%s", target,
105922105639
(pExpr->iTable ? "new" : "old"),
105923
- (pExpr->iColumn<0 ? "rowid" : pExpr->y.pTab->aCol[iCol].zName)
105640
+ (pExpr->iColumn<0 ? "rowid" : pExpr->y.pTab->aCol[iCol].zCnName)
105924105641
));
105925105642
105926105643
#ifndef SQLITE_OMIT_FLOATING_POINT
105927105644
/* If the column has REAL affinity, it may currently be stored as an
105928105645
** integer. Use OP_RealAffinity to make sure it is really real.
@@ -107090,13 +106807,13 @@
107090106807
testcase( pExpr->op==TK_LE );
107091106808
testcase( pExpr->op==TK_GT );
107092106809
testcase( pExpr->op==TK_GE );
107093106810
/* The y.pTab=0 assignment in wherecode.c always happens after the
107094106811
** impliesNotNullRow() test */
107095
- if( (pLeft->op==TK_COLUMN && ALWAYS(pLeft->y.pTab!=0)
106812
+ if( (pLeft->op==TK_COLUMN && pLeft->y.pTab!=0
107096106813
&& IsVirtual(pLeft->y.pTab))
107097
- || (pRight->op==TK_COLUMN && ALWAYS(pRight->y.pTab!=0)
106814
+ || (pRight->op==TK_COLUMN && pRight->y.pTab!=0
107098106815
&& IsVirtual(pRight->y.pTab))
107099106816
){
107100106817
return WRC_Prune;
107101106818
}
107102106819
/* no break */ deliberate_fall_through
@@ -107771,22 +107488,19 @@
107771107488
sqlite3 *db = pParse->db; /* Database connection */
107772107489
int nTabName; /* Number of UTF-8 characters in zTabName */
107773107490
const char *zTabName; /* Original name of the table */
107774107491
Vdbe *v;
107775107492
VTable *pVTab = 0; /* Non-zero if this is a v-tab with an xRename() */
107776
- u32 savedDbFlags; /* Saved value of db->mDbFlags */
107777107493
107778
- savedDbFlags = db->mDbFlags;
107779107494
if( NEVER(db->mallocFailed) ) goto exit_rename_table;
107780107495
assert( pSrc->nSrc==1 );
107781107496
assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );
107782107497
107783107498
pTab = sqlite3LocateTableItem(pParse, 0, &pSrc->a[0]);
107784107499
if( !pTab ) goto exit_rename_table;
107785107500
iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
107786107501
zDb = db->aDb[iDb].zDbSName;
107787
- db->mDbFlags |= DBFLAG_PreferBuiltin;
107788107502
107789107503
/* Get a NULL terminated version of the new table name. */
107790107504
zName = sqlite3NameFromToken(db, pName);
107791107505
if( !zName ) goto exit_rename_table;
107792107506
@@ -107811,11 +107525,11 @@
107811107525
if( SQLITE_OK!=sqlite3CheckObjectName(pParse,zName,"table",zName) ){
107812107526
goto exit_rename_table;
107813107527
}
107814107528
107815107529
#ifndef SQLITE_OMIT_VIEW
107816
- if( pTab->pSelect ){
107530
+ if( IsView(pTab) ){
107817107531
sqlite3ErrorMsg(pParse, "view %s may not be altered", pTab->zName);
107818107532
goto exit_rename_table;
107819107533
}
107820107534
#endif
107821107535
@@ -107923,11 +107637,10 @@
107923107637
renameTestSchema(pParse, zDb, iDb==1, "after rename", 0);
107924107638
107925107639
exit_rename_table:
107926107640
sqlite3SrcListDelete(db, pSrc);
107927107641
sqlite3DbFree(db, zName);
107928
- db->mDbFlags = savedDbFlags;
107929107642
}
107930107643
107931107644
/*
107932107645
** Write code that will raise an error if the table described by
107933107646
** zDb and zTab is not empty.
@@ -107973,11 +107686,11 @@
107973107686
assert( sqlite3BtreeHoldsAllMutexes(db) );
107974107687
iDb = sqlite3SchemaToIndex(db, pNew->pSchema);
107975107688
zDb = db->aDb[iDb].zDbSName;
107976107689
zTab = &pNew->zName[16]; /* Skip the "sqlite_altertab_" prefix on the name */
107977107690
pCol = &pNew->aCol[pNew->nCol-1];
107978
- pDflt = pCol->pDflt;
107691
+ pDflt = sqlite3ColumnExpr(pNew, pCol);
107979107692
pTab = sqlite3FindTable(db, zTab, zDb);
107980107693
assert( pTab );
107981107694
107982107695
#ifndef SQLITE_OMIT_AUTHORIZATION
107983107696
/* Invoke the authorization callback. */
@@ -108007,11 +107720,11 @@
108007107720
*/
108008107721
assert( pDflt==0 || pDflt->op==TK_SPAN );
108009107722
if( pDflt && pDflt->pLeft->op==TK_NULL ){
108010107723
pDflt = 0;
108011107724
}
108012
- if( (db->flags&SQLITE_ForeignKeys) && pNew->pFKey && pDflt ){
107725
+ if( (db->flags&SQLITE_ForeignKeys) && pNew->u.tab.pFKey && pDflt ){
108013107726
sqlite3ErrorIfNotEmpty(pParse, zDb, zTab,
108014107727
"Cannot add a REFERENCES column with non-NULL default value");
108015107728
}
108016107729
if( pCol->notNull && !pDflt ){
108017107730
sqlite3ErrorIfNotEmpty(pParse, zDb, zTab,
@@ -108044,27 +107757,25 @@
108044107757
108045107758
/* Modify the CREATE TABLE statement. */
108046107759
zCol = sqlite3DbStrNDup(db, (char*)pColDef->z, pColDef->n);
108047107760
if( zCol ){
108048107761
char *zEnd = &zCol[pColDef->n-1];
108049
- u32 savedDbFlags = db->mDbFlags;
108050107762
while( zEnd>zCol && (*zEnd==';' || sqlite3Isspace(*zEnd)) ){
108051107763
*zEnd-- = '\0';
108052107764
}
108053
- db->mDbFlags |= DBFLAG_PreferBuiltin;
108054107765
/* substr() operations on characters, but addColOffset is in bytes. So we
108055107766
** have to use printf() to translate between these units: */
107767
+ assert( !IsVirtual(pTab) );
108056107768
sqlite3NestedParse(pParse,
108057107769
"UPDATE \"%w\"." DFLT_SCHEMA_TABLE " SET "
108058107770
"sql = printf('%%.%ds, ',sql) || %Q"
108059107771
" || substr(sql,1+length(printf('%%.%ds',sql))) "
108060107772
"WHERE type = 'table' AND name = %Q",
108061
- zDb, pNew->addColOffset, zCol, pNew->addColOffset,
107773
+ zDb, pNew->u.tab.addColOffset, zCol, pNew->u.tab.addColOffset,
108062107774
zTab
108063107775
);
108064107776
sqlite3DbFree(db, zCol);
108065
- db->mDbFlags = savedDbFlags;
108066107777
}
108067107778
108068107779
v = sqlite3GetVdbe(pParse);
108069107780
if( v ){
108070107781
/* Make sure the schema version is at least 3. But do not upgrade
@@ -108136,20 +107847,20 @@
108136107847
goto exit_begin_add_column;
108137107848
}
108138107849
#endif
108139107850
108140107851
/* Make sure this is not an attempt to ALTER a view. */
108141
- if( pTab->pSelect ){
107852
+ if( IsView(pTab) ){
108142107853
sqlite3ErrorMsg(pParse, "Cannot add a column to a view");
108143107854
goto exit_begin_add_column;
108144107855
}
108145107856
if( SQLITE_OK!=isAlterableTable(pParse, pTab) ){
108146107857
goto exit_begin_add_column;
108147107858
}
108148107859
108149107860
sqlite3MayAbort(pParse);
108150
- assert( pTab->addColOffset>0 );
107861
+ assert( pTab->u.tab.addColOffset>0 );
108151107862
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
108152107863
108153107864
/* Put a copy of the Table struct in Parse.pNewTable for the
108154107865
** sqlite3AddColumn() function and friends to modify. But modify
108155107866
** the name by adding an "sqlite_altertab_" prefix. By adding this
@@ -108172,17 +107883,17 @@
108172107883
goto exit_begin_add_column;
108173107884
}
108174107885
memcpy(pNew->aCol, pTab->aCol, sizeof(Column)*pNew->nCol);
108175107886
for(i=0; i<pNew->nCol; i++){
108176107887
Column *pCol = &pNew->aCol[i];
108177
- pCol->zName = sqlite3DbStrDup(db, pCol->zName);
108178
- pCol->hName = sqlite3StrIHash(pCol->zName);
108179
- pCol->zColl = 0;
108180
- pCol->pDflt = 0;
107888
+ pCol->zCnName = sqlite3DbStrDup(db, pCol->zCnName);
107889
+ pCol->hName = sqlite3StrIHash(pCol->zCnName);
108181107890
}
107891
+ assert( !IsVirtual(pNew) );
107892
+ pNew->u.tab.pDfltList = sqlite3ExprListDup(db, pTab->u.tab.pDfltList, 0);
108182107893
pNew->pSchema = db->aDb[iDb].pSchema;
108183
- pNew->addColOffset = pTab->addColOffset;
107894
+ pNew->u.tab.addColOffset = pTab->u.tab.addColOffset;
108184107895
pNew->nTabRef = 1;
108185107896
108186107897
exit_begin_add_column:
108187107898
sqlite3SrcListDelete(db, pSrc);
108188107899
return;
@@ -108198,11 +107909,11 @@
108198107909
*/
108199107910
#if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_VIRTUALTABLE)
108200107911
static int isRealTable(Parse *pParse, Table *pTab, int bDrop){
108201107912
const char *zType = 0;
108202107913
#ifndef SQLITE_OMIT_VIEW
108203
- if( pTab->pSelect ){
107914
+ if( IsView(pTab) ){
108204107915
zType = "view";
108205107916
}
108206107917
#endif
108207107918
#ifndef SQLITE_OMIT_VIRTUALTABLE
108208107919
if( IsVirtual(pTab) ){
@@ -108265,11 +107976,11 @@
108265107976
/* Make sure the old name really is a column name in the table to be
108266107977
** altered. Set iCol to be the index of the column being renamed */
108267107978
zOld = sqlite3NameFromToken(db, pOld);
108268107979
if( !zOld ) goto exit_rename_column;
108269107980
for(iCol=0; iCol<pTab->nCol; iCol++){
108270
- if( 0==sqlite3StrICmp(pTab->aCol[iCol].zName, zOld) ) break;
107981
+ if( 0==sqlite3StrICmp(pTab->aCol[iCol].zCnName, zOld) ) break;
108271107982
}
108272107983
if( iCol==pTab->nCol ){
108273107984
sqlite3ErrorMsg(pParse, "no such column: \"%s\"", zOld);
108274107985
goto exit_rename_column;
108275107986
}
@@ -109111,11 +108822,11 @@
109111108822
pTab = sqlite3FindTable(db, zTable, zDb);
109112108823
if( pTab==0 || iCol>=pTab->nCol ){
109113108824
sqlite3BtreeLeaveAll(db);
109114108825
return;
109115108826
}
109116
- zOld = pTab->aCol[iCol].zName;
108827
+ zOld = pTab->aCol[iCol].zCnName;
109117108828
memset(&sCtx, 0, sizeof(sCtx));
109118108829
sCtx.iCol = ((iCol==pTab->iPKey) ? -1 : iCol);
109119108830
109120108831
#ifndef SQLITE_OMIT_AUTHORIZATION
109121108832
db->xAuth = 0;
@@ -109130,30 +108841,29 @@
109130108841
sWalker.u.pRename = &sCtx;
109131108842
109132108843
sCtx.pTab = pTab;
109133108844
if( rc!=SQLITE_OK ) goto renameColumnFunc_done;
109134108845
if( sParse.pNewTable ){
109135
- Select *pSelect = sParse.pNewTable->pSelect;
109136
- if( pSelect ){
108846
+ if( IsView(sParse.pNewTable) ){
108847
+ Select *pSelect = sParse.pNewTable->u.view.pSelect;
109137108848
pSelect->selFlags &= ~SF_View;
109138108849
sParse.rc = SQLITE_OK;
109139108850
sqlite3SelectPrep(&sParse, pSelect, 0);
109140108851
rc = (db->mallocFailed ? SQLITE_NOMEM : sParse.rc);
109141108852
if( rc==SQLITE_OK ){
109142108853
sqlite3WalkSelect(&sWalker, pSelect);
109143108854
}
109144108855
if( rc!=SQLITE_OK ) goto renameColumnFunc_done;
109145
- }else{
108856
+ }else if( ALWAYS(IsOrdinaryTable(sParse.pNewTable)) ){
109146108857
/* A regular table */
109147108858
int bFKOnly = sqlite3_stricmp(zTable, sParse.pNewTable->zName);
109148108859
FKey *pFKey;
109149
- assert( sParse.pNewTable->pSelect==0 );
109150108860
sCtx.pTab = sParse.pNewTable;
109151108861
if( bFKOnly==0 ){
109152108862
if( iCol<sParse.pNewTable->nCol ){
109153108863
renameTokenFind(
109154
- &sParse, &sCtx, (void*)sParse.pNewTable->aCol[iCol].zName
108864
+ &sParse, &sCtx, (void*)sParse.pNewTable->aCol[iCol].zCnName
109155108865
);
109156108866
}
109157108867
if( sCtx.iCol<0 ){
109158108868
renameTokenFind(&sParse, &sCtx, (void*)&sParse.pNewTable->iPKey);
109159108869
}
@@ -109164,16 +108874,19 @@
109164108874
for(pIdx=sParse.pNewIndex; pIdx; pIdx=pIdx->pNext){
109165108875
sqlite3WalkExprList(&sWalker, pIdx->aColExpr);
109166108876
}
109167108877
#ifndef SQLITE_OMIT_GENERATED_COLUMNS
109168108878
for(i=0; i<sParse.pNewTable->nCol; i++){
109169
- sqlite3WalkExpr(&sWalker, sParse.pNewTable->aCol[i].pDflt);
108879
+ Expr *pExpr = sqlite3ColumnExpr(sParse.pNewTable,
108880
+ &sParse.pNewTable->aCol[i]);
108881
+ sqlite3WalkExpr(&sWalker, pExpr);
109170108882
}
109171108883
#endif
109172108884
}
109173108885
109174
- for(pFKey=sParse.pNewTable->pFKey; pFKey; pFKey=pFKey->pNextFrom){
108886
+ assert( !IsVirtual(sParse.pNewTable) );
108887
+ for(pFKey=sParse.pNewTable->u.tab.pFKey; pFKey; pFKey=pFKey->pNextFrom){
109175108888
for(i=0; i<pFKey->nCol; i++){
109176108889
if( bFKOnly==0 && pFKey->aCol[i].iFrom==iCol ){
109177108890
renameTokenFind(&sParse, &sCtx, (void*)&pFKey->aCol[i]);
109178108891
}
109179108892
if( 0==sqlite3_stricmp(pFKey->zTo, zTable)
@@ -109335,32 +109048,35 @@
109335109048
if( rc==SQLITE_OK ){
109336109049
int isLegacy = (db->flags & SQLITE_LegacyAlter);
109337109050
if( sParse.pNewTable ){
109338109051
Table *pTab = sParse.pNewTable;
109339109052
109340
- if( pTab->pSelect ){
109053
+ if( IsView(pTab) ){
109341109054
if( isLegacy==0 ){
109342
- Select *pSelect = pTab->pSelect;
109055
+ Select *pSelect = pTab->u.view.pSelect;
109343109056
NameContext sNC;
109344109057
memset(&sNC, 0, sizeof(sNC));
109345109058
sNC.pParse = &sParse;
109346109059
109347109060
assert( pSelect->selFlags & SF_View );
109348109061
pSelect->selFlags &= ~SF_View;
109349
- sqlite3SelectPrep(&sParse, pTab->pSelect, &sNC);
109062
+ sqlite3SelectPrep(&sParse, pTab->u.view.pSelect, &sNC);
109350109063
if( sParse.nErr ){
109351109064
rc = sParse.rc;
109352109065
}else{
109353
- sqlite3WalkSelect(&sWalker, pTab->pSelect);
109066
+ sqlite3WalkSelect(&sWalker, pTab->u.view.pSelect);
109354109067
}
109355109068
}
109356109069
}else{
109357109070
/* Modify any FK definitions to point to the new table. */
109358109071
#ifndef SQLITE_OMIT_FOREIGN_KEY
109359
- if( isLegacy==0 || (db->flags & SQLITE_ForeignKeys) ){
109072
+ if( (isLegacy==0 || (db->flags & SQLITE_ForeignKeys))
109073
+ && !IsVirtual(pTab)
109074
+ ){
109360109075
FKey *pFKey;
109361
- for(pFKey=pTab->pFKey; pFKey; pFKey=pFKey->pNextFrom){
109076
+ assert( !IsVirtual(pTab) );
109077
+ for(pFKey=pTab->u.tab.pFKey; pFKey; pFKey=pFKey->pNextFrom){
109362109078
if( sqlite3_stricmp(pFKey->zTo, zOld)==0 ){
109363109079
renameTokenFind(&sParse, &sCtx, (void*)pFKey->zTo);
109364109080
}
109365109081
}
109366109082
}
@@ -109496,12 +109212,12 @@
109496109212
sWalker.xExprCallback = renameQuotefixExprCb;
109497109213
sWalker.xSelectCallback = renameColumnSelectCb;
109498109214
sWalker.u.pRename = &sCtx;
109499109215
109500109216
if( sParse.pNewTable ){
109501
- Select *pSelect = sParse.pNewTable->pSelect;
109502
- if( pSelect ){
109217
+ if( IsView(sParse.pNewTable) ){
109218
+ Select *pSelect = sParse.pNewTable->u.view.pSelect;
109503109219
pSelect->selFlags &= ~SF_View;
109504109220
sParse.rc = SQLITE_OK;
109505109221
sqlite3SelectPrep(&sParse, pSelect, 0);
109506109222
rc = (db->mallocFailed ? SQLITE_NOMEM : sParse.rc);
109507109223
if( rc==SQLITE_OK ){
@@ -109510,11 +109226,13 @@
109510109226
}else{
109511109227
int i;
109512109228
sqlite3WalkExprList(&sWalker, sParse.pNewTable->pCheck);
109513109229
#ifndef SQLITE_OMIT_GENERATED_COLUMNS
109514109230
for(i=0; i<sParse.pNewTable->nCol; i++){
109515
- sqlite3WalkExpr(&sWalker, sParse.pNewTable->aCol[i].pDflt);
109231
+ sqlite3WalkExpr(&sWalker,
109232
+ sqlite3ColumnExpr(sParse.pNewTable,
109233
+ &sParse.pNewTable->aCol[i]));
109516109234
}
109517109235
#endif /* SQLITE_OMIT_GENERATED_COLUMNS */
109518109236
}
109519109237
}else if( sParse.pNewIndex ){
109520109238
sqlite3WalkExprList(&sWalker, sParse.pNewIndex->aColExpr);
@@ -109593,15 +109311,15 @@
109593109311
int flags = db->flags;
109594109312
if( bNoDQS ) db->flags &= ~(SQLITE_DqsDML|SQLITE_DqsDDL);
109595109313
rc = renameParseSql(&sParse, zDb, db, zInput, bTemp);
109596109314
db->flags |= (flags & (SQLITE_DqsDML|SQLITE_DqsDDL));
109597109315
if( rc==SQLITE_OK ){
109598
- if( isLegacy==0 && sParse.pNewTable && sParse.pNewTable->pSelect ){
109316
+ if( isLegacy==0 && sParse.pNewTable && IsView(sParse.pNewTable) ){
109599109317
NameContext sNC;
109600109318
memset(&sNC, 0, sizeof(sNC));
109601109319
sNC.pParse = &sParse;
109602
- sqlite3SelectPrep(&sParse, sParse.pNewTable->pSelect, &sNC);
109320
+ sqlite3SelectPrep(&sParse, sParse.pNewTable->u.view.pSelect, &sNC);
109603109321
if( sParse.nErr ) rc = sParse.rc;
109604109322
}
109605109323
109606109324
else if( sParse.pNewTrigger ){
109607109325
if( isLegacy==0 ){
@@ -109668,17 +109386,18 @@
109668109386
/* This can happen if the sqlite_schema table is corrupt */
109669109387
rc = SQLITE_CORRUPT_BKPT;
109670109388
goto drop_column_done;
109671109389
}
109672109390
109673
- pCol = renameTokenFind(&sParse, 0, (void*)pTab->aCol[iCol].zName);
109391
+ pCol = renameTokenFind(&sParse, 0, (void*)pTab->aCol[iCol].zCnName);
109674109392
if( iCol<pTab->nCol-1 ){
109675109393
RenameToken *pEnd;
109676
- pEnd = renameTokenFind(&sParse, 0, (void*)pTab->aCol[iCol+1].zName);
109394
+ pEnd = renameTokenFind(&sParse, 0, (void*)pTab->aCol[iCol+1].zCnName);
109677109395
zEnd = (const char*)pEnd->t.z;
109678109396
}else{
109679
- zEnd = (const char*)&zSql[pTab->addColOffset];
109397
+ assert( !IsVirtual(pTab) );
109398
+ zEnd = (const char*)&zSql[pTab->u.tab.addColOffset];
109680109399
while( ALWAYS(pCol->t.z[0]!=0) && pCol->t.z[0]!=',' ) pCol->t.z--;
109681109400
}
109682109401
109683109402
zNew = sqlite3MPrintf(db, "%.*s%s", pCol->t.z-zSql, zSql, zEnd);
109684109403
sqlite3_result_text(context, zNew, -1, SQLITE_TRANSIENT);
@@ -109809,10 +109528,16 @@
109809109528
}else{
109810109529
sqlite3ExprCodeGetColumnOfTable(v, pTab, iCur, i, regOut);
109811109530
}
109812109531
nField++;
109813109532
}
109533
+ }
109534
+ if( nField==0 ){
109535
+ /* dbsqlfuzz 5f09e7bcc78b4954d06bf9f2400d7715f48d1fef */
109536
+ pParse->nMem++;
109537
+ sqlite3VdbeAddOp2(v, OP_Null, 0, reg+1);
109538
+ nField = 1;
109814109539
}
109815109540
sqlite3VdbeAddOp3(v, OP_MakeRecord, reg+1, nField, regRec);
109816109541
if( pPk ){
109817109542
sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iCur, regRec, reg+1, pPk->nKeyCol);
109818109543
}else{
@@ -110814,11 +110539,11 @@
110814110539
if( NEVER(i==XN_ROWID) ){
110815110540
VdbeComment((v,"%s.rowid",pIdx->zName));
110816110541
}else if( i==XN_EXPR ){
110817110542
VdbeComment((v,"%s.expr(%d)",pIdx->zName, k));
110818110543
}else{
110819
- VdbeComment((v,"%s.%s", pIdx->zName, pIdx->pTable->aCol[i].zName));
110544
+ VdbeComment((v,"%s.%s", pIdx->zName, pIdx->pTable->aCol[i].zCnName));
110820110545
}
110821110546
}
110822110547
#else
110823110548
# define analyzeVdbeCommentIndexWithColumnName(a,b,c)
110824110549
#endif /* SQLITE_DEBUG */
@@ -112567,14 +112292,14 @@
112567112292
iCol = pExpr->iColumn;
112568112293
if( pTab==0 ) return;
112569112294
112570112295
if( iCol>=0 ){
112571112296
assert( iCol<pTab->nCol );
112572
- zCol = pTab->aCol[iCol].zName;
112297
+ zCol = pTab->aCol[iCol].zCnName;
112573112298
}else if( pTab->iPKey>=0 ){
112574112299
assert( pTab->iPKey<pTab->nCol );
112575
- zCol = pTab->aCol[pTab->iPKey].zName;
112300
+ zCol = pTab->aCol[pTab->iPKey].zCnName;
112576112301
}else{
112577112302
zCol = "ROWID";
112578112303
}
112579112304
assert( iDb>=0 && iDb<pParse->db->nDb );
112580112305
if( SQLITE_IGNORE==sqlite3AuthReadCol(pParse, pTab->zName, zCol, iDb) ){
@@ -112948,24 +112673,26 @@
112948112673
}
112949112674
112950112675
/*
112951112676
** Run the parser and code generator recursively in order to generate
112952112677
** code for the SQL statement given onto the end of the pParse context
112953
-** currently under construction. When the parser is run recursively
112954
-** this way, the final OP_Halt is not appended and other initialization
112955
-** and finalization steps are omitted because those are handling by the
112956
-** outermost parser.
112678
+** currently under construction. Notes:
112957112679
**
112958
-** Not everything is nestable. This facility is designed to permit
112959
-** INSERT, UPDATE, and DELETE operations against the schema table. Use
112960
-** care if you decide to try to use this routine for some other purposes.
112680
+** * The final OP_Halt is not appended and other initialization
112681
+** and finalization steps are omitted because those are handling by the
112682
+** outermost parser.
112683
+**
112684
+** * Built-in SQL functions always take precedence over application-defined
112685
+** SQL functions. In other words, it is not possible to override a
112686
+** built-in function.
112961112687
*/
112962112688
SQLITE_PRIVATE void sqlite3NestedParse(Parse *pParse, const char *zFormat, ...){
112963112689
va_list ap;
112964112690
char *zSql;
112965112691
char *zErrMsg = 0;
112966112692
sqlite3 *db = pParse->db;
112693
+ u32 savedDbFlags = db->mDbFlags;
112967112694
char saveBuf[PARSE_TAIL_SZ];
112968112695
112969112696
if( pParse->nErr ) return;
112970112697
assert( pParse->nested<10 ); /* Nesting should only be of limited depth */
112971112698
va_start(ap, zFormat);
@@ -112980,11 +112707,13 @@
112980112707
return;
112981112708
}
112982112709
pParse->nested++;
112983112710
memcpy(saveBuf, PARSE_TAIL(pParse), PARSE_TAIL_SZ);
112984112711
memset(PARSE_TAIL(pParse), 0, PARSE_TAIL_SZ);
112712
+ db->mDbFlags |= DBFLAG_PreferBuiltin;
112985112713
sqlite3RunParser(pParse, zSql, &zErrMsg);
112714
+ db->mDbFlags = savedDbFlags;
112986112715
sqlite3DbFree(db, zErrMsg);
112987112716
sqlite3DbFree(db, zSql);
112988112717
memcpy(PARSE_TAIL(pParse), saveBuf, PARSE_TAIL_SZ);
112989112718
pParse->nested--;
112990112719
}
@@ -113329,10 +113058,88 @@
113329113058
** This routine is called when a commit occurs.
113330113059
*/
113331113060
SQLITE_PRIVATE void sqlite3CommitInternalChanges(sqlite3 *db){
113332113061
db->mDbFlags &= ~DBFLAG_SchemaChange;
113333113062
}
113063
+
113064
+/*
113065
+** Set the expression associated with a column. This is usually
113066
+** the DEFAULT value, but might also be the expression that computes
113067
+** the value for a generated column.
113068
+*/
113069
+SQLITE_PRIVATE void sqlite3ColumnSetExpr(
113070
+ Parse *pParse, /* Parsing context */
113071
+ Table *pTab, /* The table containing the column */
113072
+ Column *pCol, /* The column to receive the new DEFAULT expression */
113073
+ Expr *pExpr /* The new default expression */
113074
+){
113075
+ ExprList *pList;
113076
+ assert( !IsVirtual(pTab) );
113077
+ pList = pTab->u.tab.pDfltList;
113078
+ if( pCol->iDflt==0
113079
+ || NEVER(pList==0)
113080
+ || NEVER(pList->nExpr<pCol->iDflt)
113081
+ ){
113082
+ pCol->iDflt = pList==0 ? 1 : pList->nExpr+1;
113083
+ pTab->u.tab.pDfltList = sqlite3ExprListAppend(pParse, pList, pExpr);
113084
+ }else{
113085
+ sqlite3ExprDelete(pParse->db, pList->a[pCol->iDflt-1].pExpr);
113086
+ pList->a[pCol->iDflt-1].pExpr = pExpr;
113087
+ }
113088
+}
113089
+
113090
+/*
113091
+** Return the expression associated with a column. The expression might be
113092
+** the DEFAULT clause or the AS clause of a generated column.
113093
+** Return NULL if the column has no associated expression.
113094
+*/
113095
+SQLITE_PRIVATE Expr *sqlite3ColumnExpr(Table *pTab, Column *pCol){
113096
+ if( pCol->iDflt==0 ) return 0;
113097
+ if( NEVER(IsVirtual(pTab)) ) return 0;
113098
+ if( NEVER(pTab->u.tab.pDfltList==0) ) return 0;
113099
+ if( NEVER(pTab->u.tab.pDfltList->nExpr<pCol->iDflt) ) return 0;
113100
+ return pTab->u.tab.pDfltList->a[pCol->iDflt-1].pExpr;
113101
+}
113102
+
113103
+/*
113104
+** Set the collating sequence name for a column.
113105
+*/
113106
+SQLITE_PRIVATE void sqlite3ColumnSetColl(
113107
+ sqlite3 *db,
113108
+ Column *pCol,
113109
+ const char *zColl
113110
+){
113111
+ int nColl;
113112
+ int n;
113113
+ char *zNew;
113114
+ assert( zColl!=0 );
113115
+ n = sqlite3Strlen30(pCol->zCnName) + 1;
113116
+ if( pCol->colFlags & COLFLAG_HASTYPE ){
113117
+ n += sqlite3Strlen30(pCol->zCnName+n) + 1;
113118
+ }
113119
+ nColl = sqlite3Strlen30(zColl) + 1;
113120
+ zNew = sqlite3DbRealloc(db, pCol->zCnName, nColl+n);
113121
+ if( zNew ){
113122
+ pCol->zCnName = zNew;
113123
+ memcpy(pCol->zCnName + n, zColl, nColl);
113124
+ pCol->colFlags |= COLFLAG_HASCOLL;
113125
+ }
113126
+}
113127
+
113128
+/*
113129
+** Return the collating squence name for a column
113130
+*/
113131
+SQLITE_PRIVATE const char *sqlite3ColumnColl(Column *pCol){
113132
+ const char *z;
113133
+ if( (pCol->colFlags & COLFLAG_HASCOLL)==0 ) return 0;
113134
+ z = pCol->zCnName;
113135
+ while( *z ){ z++; }
113136
+ if( pCol->colFlags & COLFLAG_HASTYPE ){
113137
+ do{ z++; }while( *z );
113138
+ }
113139
+ return z+1;
113140
+}
113334113141
113335113142
/*
113336113143
** Delete memory allocated for the column names of a table or view (the
113337113144
** Table.aCol[] array).
113338113145
*/
@@ -113340,16 +113147,24 @@
113340113147
int i;
113341113148
Column *pCol;
113342113149
assert( pTable!=0 );
113343113150
if( (pCol = pTable->aCol)!=0 ){
113344113151
for(i=0; i<pTable->nCol; i++, pCol++){
113345
- assert( pCol->zName==0 || pCol->hName==sqlite3StrIHash(pCol->zName) );
113346
- sqlite3DbFree(db, pCol->zName);
113347
- sqlite3ExprDelete(db, pCol->pDflt);
113348
- sqlite3DbFree(db, pCol->zColl);
113152
+ assert( pCol->zCnName==0 || pCol->hName==sqlite3StrIHash(pCol->zCnName) );
113153
+ sqlite3DbFree(db, pCol->zCnName);
113349113154
}
113350113155
sqlite3DbFree(db, pTable->aCol);
113156
+ if( !IsVirtual(pTable) ){
113157
+ sqlite3ExprListDelete(db, pTable->u.tab.pDfltList);
113158
+ }
113159
+ if( db==0 || db->pnBytesFreed==0 ){
113160
+ pTable->aCol = 0;
113161
+ pTable->nCol = 0;
113162
+ if( !IsVirtual(pTable) ){
113163
+ pTable->u.tab.pDfltList = 0;
113164
+ }
113165
+ }
113351113166
}
113352113167
}
113353113168
113354113169
/*
113355113170
** Remove the memory data structures associated with the given
@@ -113397,23 +113212,29 @@
113397113212
assert( pOld==pIndex || pOld==0 );
113398113213
}
113399113214
sqlite3FreeIndex(db, pIndex);
113400113215
}
113401113216
113402
- /* Delete any foreign keys attached to this table. */
113403
- sqlite3FkDelete(db, pTable);
113217
+ if( IsOrdinaryTable(pTable) ){
113218
+ sqlite3FkDelete(db, pTable);
113219
+ }
113220
+#ifndef SQLITE_OMIT_VIRTUAL_TABLE
113221
+ else if( IsVirtual(pTable) ){
113222
+ sqlite3VtabClear(db, pTable);
113223
+ }
113224
+#endif
113225
+ else{
113226
+ assert( IsView(pTable) );
113227
+ sqlite3SelectDelete(db, pTable->u.view.pSelect);
113228
+ }
113404113229
113405113230
/* Delete the Table structure itself.
113406113231
*/
113407113232
sqlite3DeleteColumnNames(db, pTable);
113408113233
sqlite3DbFree(db, pTable->zName);
113409113234
sqlite3DbFree(db, pTable->zColAff);
113410
- sqlite3SelectDelete(db, pTable->pSelect);
113411113235
sqlite3ExprListDelete(db, pTable->pCheck);
113412
-#ifndef SQLITE_OMIT_VIRTUALTABLE
113413
- sqlite3VtabClear(db, pTable);
113414
-#endif
113415113236
sqlite3DbFree(db, pTable);
113416113237
113417113238
/* Verify that no lookaside memory was used by schema tables */
113418113239
assert( nLookaside==0 || nLookaside==sqlite3LookasideUsed(db,0) );
113419113240
}
@@ -113935,20 +113756,21 @@
113935113756
/* Normal (non-error) return. */
113936113757
return;
113937113758
113938113759
/* If an error occurs, we jump here */
113939113760
begin_table_error:
113761
+ pParse->checkSchema = 1;
113940113762
sqlite3DbFree(db, zName);
113941113763
return;
113942113764
}
113943113765
113944113766
/* Set properties of a table column based on the (magical)
113945113767
** name of the column.
113946113768
*/
113947113769
#if SQLITE_ENABLE_HIDDEN_COLUMNS
113948113770
SQLITE_PRIVATE void sqlite3ColumnPropertiesFromName(Table *pTab, Column *pCol){
113949
- if( sqlite3_strnicmp(pCol->zName, "__hidden__", 10)==0 ){
113771
+ if( sqlite3_strnicmp(pCol->zCnName, "__hidden__", 10)==0 ){
113950113772
pCol->colFlags |= COLFLAG_HIDDEN;
113951113773
if( pTab ) pTab->tabFlags |= TF_HasHidden;
113952113774
}else if( pTab && pCol!=pTab->aCol && (pCol[-1].colFlags & COLFLAG_HIDDEN) ){
113953113775
pTab->tabFlags |= TF_OOOHidden;
113954113776
}
@@ -114035,67 +113857,108 @@
114035113857
** The parser calls this routine once for each column declaration
114036113858
** in a CREATE TABLE statement. sqlite3StartTable() gets called
114037113859
** first to get things going. Then this routine is called for each
114038113860
** column.
114039113861
*/
114040
-SQLITE_PRIVATE void sqlite3AddColumn(Parse *pParse, Token *pName, Token *pType){
113862
+SQLITE_PRIVATE void sqlite3AddColumn(Parse *pParse, Token sName, Token sType){
114041113863
Table *p;
114042113864
int i;
114043113865
char *z;
114044113866
char *zType;
114045113867
Column *pCol;
114046113868
sqlite3 *db = pParse->db;
114047113869
u8 hName;
113870
+ Column *aNew;
113871
+ u8 eType = COLTYPE_CUSTOM;
113872
+ u8 szEst = 1;
113873
+ char affinity = SQLITE_AFF_BLOB;
114048113874
114049113875
if( (p = pParse->pNewTable)==0 ) return;
114050113876
if( p->nCol+1>db->aLimit[SQLITE_LIMIT_COLUMN] ){
114051113877
sqlite3ErrorMsg(pParse, "too many columns on %s", p->zName);
114052113878
return;
114053113879
}
114054
- z = sqlite3DbMallocRaw(db, pName->n + pType->n + 2);
113880
+ if( !IN_RENAME_OBJECT ) sqlite3DequoteToken(&sName);
113881
+
113882
+ /* Because keywords GENERATE ALWAYS can be converted into indentifiers
113883
+ ** by the parser, we can sometimes end up with a typename that ends
113884
+ ** with "generated always". Check for this case and omit the surplus
113885
+ ** text. */
113886
+ if( sType.n>=16
113887
+ && sqlite3_strnicmp(sType.z+(sType.n-6),"always",6)==0
113888
+ ){
113889
+ sType.n -= 6;
113890
+ while( ALWAYS(sType.n>0) && sqlite3Isspace(sType.z[sType.n-1]) ) sType.n--;
113891
+ if( sType.n>=9
113892
+ && sqlite3_strnicmp(sType.z+(sType.n-9),"generated",9)==0
113893
+ ){
113894
+ sType.n -= 9;
113895
+ while( sType.n>0 && sqlite3Isspace(sType.z[sType.n-1]) ) sType.n--;
113896
+ }
113897
+ }
113898
+
113899
+ /* Check for standard typenames. For standard typenames we will
113900
+ ** set the Column.eType field rather than storing the typename after
113901
+ ** the column name, in order to save space. */
113902
+ if( sType.n>=3 ){
113903
+ sqlite3DequoteToken(&sType);
113904
+ for(i=0; i<SQLITE_N_STDTYPE; i++){
113905
+ if( sType.n==sqlite3StdTypeLen[i]
113906
+ && sqlite3_strnicmp(sType.z, sqlite3StdType[i], sType.n)==0
113907
+ ){
113908
+ sType.n = 0;
113909
+ eType = i+1;
113910
+ affinity = sqlite3StdTypeAffinity[i];
113911
+ if( affinity<=SQLITE_AFF_TEXT ) szEst = 5;
113912
+ break;
113913
+ }
113914
+ }
113915
+ }
113916
+
113917
+ z = sqlite3DbMallocRaw(db, sName.n + 1 + sType.n + (sType.n>0) );
114055113918
if( z==0 ) return;
114056
- if( IN_RENAME_OBJECT ) sqlite3RenameTokenMap(pParse, (void*)z, pName);
114057
- memcpy(z, pName->z, pName->n);
114058
- z[pName->n] = 0;
113919
+ if( IN_RENAME_OBJECT ) sqlite3RenameTokenMap(pParse, (void*)z, &sName);
113920
+ memcpy(z, sName.z, sName.n);
113921
+ z[sName.n] = 0;
114059113922
sqlite3Dequote(z);
114060113923
hName = sqlite3StrIHash(z);
114061113924
for(i=0; i<p->nCol; i++){
114062
- if( p->aCol[i].hName==hName && sqlite3StrICmp(z, p->aCol[i].zName)==0 ){
113925
+ if( p->aCol[i].hName==hName && sqlite3StrICmp(z, p->aCol[i].zCnName)==0 ){
114063113926
sqlite3ErrorMsg(pParse, "duplicate column name: %s", z);
114064113927
sqlite3DbFree(db, z);
114065113928
return;
114066113929
}
114067113930
}
114068
- if( (p->nCol & 0x7)==0 ){
114069
- Column *aNew;
114070
- aNew = sqlite3DbRealloc(db,p->aCol,(p->nCol+8)*sizeof(p->aCol[0]));
114071
- if( aNew==0 ){
114072
- sqlite3DbFree(db, z);
114073
- return;
114074
- }
114075
- p->aCol = aNew;
114076
- }
113931
+ aNew = sqlite3DbRealloc(db,p->aCol,(p->nCol+1)*sizeof(p->aCol[0]));
113932
+ if( aNew==0 ){
113933
+ sqlite3DbFree(db, z);
113934
+ return;
113935
+ }
113936
+ p->aCol = aNew;
114077113937
pCol = &p->aCol[p->nCol];
114078113938
memset(pCol, 0, sizeof(p->aCol[0]));
114079
- pCol->zName = z;
113939
+ pCol->zCnName = z;
114080113940
pCol->hName = hName;
114081113941
sqlite3ColumnPropertiesFromName(p, pCol);
114082113942
114083
- if( pType->n==0 ){
113943
+ if( sType.n==0 ){
114084113944
/* If there is no type specified, columns have the default affinity
114085113945
** 'BLOB' with a default size of 4 bytes. */
114086
- pCol->affinity = SQLITE_AFF_BLOB;
114087
- pCol->szEst = 1;
113946
+ pCol->affinity = affinity;
113947
+ pCol->eType = eType;
113948
+ pCol->szEst = szEst;
114088113949
#ifdef SQLITE_ENABLE_SORTER_REFERENCES
114089
- if( 4>=sqlite3GlobalConfig.szSorterRef ){
114090
- pCol->colFlags |= COLFLAG_SORTERREF;
113950
+ if( affinity==SQLITE_AFF_BLOB ){
113951
+ if( 4>=sqlite3GlobalConfig.szSorterRef ){
113952
+ pCol->colFlags |= COLFLAG_SORTERREF;
113953
+ }
114091113954
}
114092113955
#endif
114093113956
}else{
114094113957
zType = z + sqlite3Strlen30(z) + 1;
114095
- memcpy(zType, pType->z, pType->n);
114096
- zType[pType->n] = 0;
113958
+ memcpy(zType, sType.z, sType.n);
113959
+ zType[sType.n] = 0;
114097113960
sqlite3Dequote(zType);
114098113961
pCol->affinity = sqlite3AffinityType(zType, pCol);
114099113962
pCol->colFlags |= COLFLAG_HASTYPE;
114100113963
}
114101113964
p->nCol++;
@@ -114246,11 +114109,11 @@
114246114109
if( p!=0 ){
114247114110
int isInit = db->init.busy && db->init.iDb!=1;
114248114111
pCol = &(p->aCol[p->nCol-1]);
114249114112
if( !sqlite3ExprIsConstantOrFunction(pExpr, isInit) ){
114250114113
sqlite3ErrorMsg(pParse, "default value of column [%s] is not constant",
114251
- pCol->zName);
114114
+ pCol->zCnName);
114252114115
#ifndef SQLITE_OMIT_GENERATED_COLUMNS
114253114116
}else if( pCol->colFlags & COLFLAG_GENERATED ){
114254114117
testcase( pCol->colFlags & COLFLAG_VIRTUAL );
114255114118
testcase( pCol->colFlags & COLFLAG_STORED );
114256114119
sqlite3ErrorMsg(pParse, "cannot use DEFAULT on a generated column");
@@ -114257,19 +114120,19 @@
114257114120
#endif
114258114121
}else{
114259114122
/* A copy of pExpr is used instead of the original, as pExpr contains
114260114123
** tokens that point to volatile memory.
114261114124
*/
114262
- Expr x;
114263
- sqlite3ExprDelete(db, pCol->pDflt);
114125
+ Expr x, *pDfltExpr;
114264114126
memset(&x, 0, sizeof(x));
114265114127
x.op = TK_SPAN;
114266114128
x.u.zToken = sqlite3DbSpanDup(db, zStart, zEnd);
114267114129
x.pLeft = pExpr;
114268114130
x.flags = EP_Skip;
114269
- pCol->pDflt = sqlite3ExprDup(db, &x, EXPRDUP_REDUCE);
114131
+ pDfltExpr = sqlite3ExprDup(db, &x, EXPRDUP_REDUCE);
114270114132
sqlite3DbFree(db, x.u.zToken);
114133
+ sqlite3ColumnSetExpr(pParse, p, pCol, pDfltExpr);
114271114134
}
114272114135
}
114273114136
if( IN_RENAME_OBJECT ){
114274114137
sqlite3RenameExprUnmap(pParse, pExpr);
114275114138
}
@@ -114363,11 +114226,11 @@
114363114226
assert( pCExpr!=0 );
114364114227
sqlite3StringToId(pCExpr);
114365114228
if( pCExpr->op==TK_ID ){
114366114229
const char *zCName = pCExpr->u.zToken;
114367114230
for(iCol=0; iCol<pTab->nCol; iCol++){
114368
- if( sqlite3StrICmp(zCName, pTab->aCol[iCol].zName)==0 ){
114231
+ if( sqlite3StrICmp(zCName, pTab->aCol[iCol].zCnName)==0 ){
114369114232
pCol = &pTab->aCol[iCol];
114370114233
makeColumnPartOfPrimaryKey(pParse, pCol);
114371114234
break;
114372114235
}
114373114236
}
@@ -114374,11 +114237,11 @@
114374114237
}
114375114238
}
114376114239
}
114377114240
if( nTerm==1
114378114241
&& pCol
114379
- && sqlite3StrICmp(sqlite3ColumnType(pCol,""), "INTEGER")==0
114242
+ && pCol->eType==COLTYPE_INTEGER
114380114243
&& sortOrder!=SQLITE_SO_DESC
114381114244
){
114382114245
if( IN_RENAME_OBJECT && pList ){
114383114246
Expr *pCExpr = sqlite3ExprSkipCollate(pList->a[0].pExpr);
114384114247
sqlite3RenameTokenRemap(pParse, &pTab->iPKey, pCExpr);
@@ -114454,26 +114317,24 @@
114454114317
zColl = sqlite3NameFromToken(db, pToken);
114455114318
if( !zColl ) return;
114456114319
114457114320
if( sqlite3LocateCollSeq(pParse, zColl) ){
114458114321
Index *pIdx;
114459
- sqlite3DbFree(db, p->aCol[i].zColl);
114460
- p->aCol[i].zColl = zColl;
114322
+ sqlite3ColumnSetColl(db, &p->aCol[i], zColl);
114461114323
114462114324
/* If the column is declared as "<name> PRIMARY KEY COLLATE <type>",
114463114325
** then an index may have been created on this column before the
114464114326
** collation type was added. Correct this if it is the case.
114465114327
*/
114466114328
for(pIdx=p->pIndex; pIdx; pIdx=pIdx->pNext){
114467114329
assert( pIdx->nKeyCol==1 );
114468114330
if( pIdx->aiColumn[0]==i ){
114469
- pIdx->azColl[0] = p->aCol[i].zColl;
114331
+ pIdx->azColl[0] = sqlite3ColumnColl(&p->aCol[i]);
114470114332
}
114471114333
}
114472
- }else{
114473
- sqlite3DbFree(db, zColl);
114474114334
}
114335
+ sqlite3DbFree(db, zColl);
114475114336
}
114476114337
114477114338
/* Change the most recently parsed column to be a GENERATED ALWAYS AS
114478114339
** column.
114479114340
*/
@@ -114489,11 +114350,11 @@
114489114350
pCol = &(pTab->aCol[pTab->nCol-1]);
114490114351
if( IN_DECLARE_VTAB ){
114491114352
sqlite3ErrorMsg(pParse, "virtual tables cannot use computed columns");
114492114353
goto generated_done;
114493114354
}
114494
- if( pCol->pDflt ) goto generated_error;
114355
+ if( pCol->iDflt>0 ) goto generated_error;
114495114356
if( pType ){
114496114357
if( pType->n==7 && sqlite3StrNICmp("virtual",pType->z,7)==0 ){
114497114358
/* no-op */
114498114359
}else if( pType->n==6 && sqlite3StrNICmp("stored",pType->z,6)==0 ){
114499114360
eType = COLFLAG_STORED;
@@ -114507,17 +114368,17 @@
114507114368
assert( TF_HasStored==COLFLAG_STORED );
114508114369
pTab->tabFlags |= eType;
114509114370
if( pCol->colFlags & COLFLAG_PRIMKEY ){
114510114371
makeColumnPartOfPrimaryKey(pParse, pCol); /* For the error message */
114511114372
}
114512
- pCol->pDflt = pExpr;
114373
+ sqlite3ColumnSetExpr(pParse, pTab, pCol, pExpr);
114513114374
pExpr = 0;
114514114375
goto generated_done;
114515114376
114516114377
generated_error:
114517114378
sqlite3ErrorMsg(pParse, "error in generated column \"%s\"",
114518
- pCol->zName);
114379
+ pCol->zCnName);
114519114380
generated_done:
114520114381
sqlite3ExprDelete(pParse->db, pExpr);
114521114382
#else
114522114383
/* Throw and error for the GENERATED ALWAYS AS clause if the
114523114384
** SQLITE_OMIT_GENERATED_COLUMNS compile-time option is used. */
@@ -114615,11 +114476,11 @@
114615114476
char *zStmt;
114616114477
char *zSep, *zSep2, *zEnd;
114617114478
Column *pCol;
114618114479
n = 0;
114619114480
for(pCol = p->aCol, i=0; i<p->nCol; i++, pCol++){
114620
- n += identLength(pCol->zName) + 5;
114481
+ n += identLength(pCol->zCnName) + 5;
114621114482
}
114622114483
n += identLength(p->zName);
114623114484
if( n<50 ){
114624114485
zSep = "";
114625114486
zSep2 = ",";
@@ -114651,11 +114512,11 @@
114651114512
const char *zType;
114652114513
114653114514
sqlite3_snprintf(n-k, &zStmt[k], zSep);
114654114515
k += sqlite3Strlen30(&zStmt[k]);
114655114516
zSep = zSep2;
114656
- identPut(zStmt, &k, pCol->zName);
114517
+ identPut(zStmt, &k, pCol->zCnName);
114657114518
assert( pCol->affinity-SQLITE_AFF_BLOB >= 0 );
114658114519
assert( pCol->affinity-SQLITE_AFF_BLOB < ArraySize(azType) );
114659114520
testcase( pCol->affinity==SQLITE_AFF_BLOB );
114660114521
testcase( pCol->affinity==SQLITE_AFF_TEXT );
114661114522
testcase( pCol->affinity==SQLITE_AFF_NUMERIC );
@@ -114870,11 +114731,11 @@
114870114731
** an INTEGER PRIMARY KEY table, create a new PRIMARY KEY index.
114871114732
*/
114872114733
if( pTab->iPKey>=0 ){
114873114734
ExprList *pList;
114874114735
Token ipkToken;
114875
- sqlite3TokenInit(&ipkToken, pTab->aCol[pTab->iPKey].zName);
114736
+ sqlite3TokenInit(&ipkToken, pTab->aCol[pTab->iPKey].zCnName);
114876114737
pList = sqlite3ExprListAppend(pParse, 0,
114877114738
sqlite3ExprAlloc(db, TK_ID, &ipkToken, 0));
114878114739
if( pList==0 ){
114879114740
pTab->tabFlags &= ~TF_WithoutRowid;
114880114741
return;
@@ -115000,11 +114861,11 @@
115000114861
115001114862
if( !IsVirtual(pTab) ) return 0;
115002114863
nName = sqlite3Strlen30(pTab->zName);
115003114864
if( sqlite3_strnicmp(zName, pTab->zName, nName)!=0 ) return 0;
115004114865
if( zName[nName]!='_' ) return 0;
115005
- pMod = (Module*)sqlite3HashFind(&db->aModule, pTab->azModuleArg[0]);
114866
+ pMod = (Module*)sqlite3HashFind(&db->aModule, pTab->u.vtab.azArg[0]);
115006114867
if( pMod==0 ) return 0;
115007114868
if( pMod->pModule->iVersion<3 ) return 0;
115008114869
if( pMod->pModule->xShadowName==0 ) return 0;
115009114870
return pMod->pModule->xShadowName(zName+nName+1);
115010114871
}
@@ -115161,22 +115022,22 @@
115161115022
testcase( p->tabFlags & TF_HasVirtual );
115162115023
testcase( p->tabFlags & TF_HasStored );
115163115024
for(ii=0; ii<p->nCol; ii++){
115164115025
u32 colFlags = p->aCol[ii].colFlags;
115165115026
if( (colFlags & COLFLAG_GENERATED)!=0 ){
115166
- Expr *pX = p->aCol[ii].pDflt;
115027
+ Expr *pX = sqlite3ColumnExpr(p, &p->aCol[ii]);
115167115028
testcase( colFlags & COLFLAG_VIRTUAL );
115168115029
testcase( colFlags & COLFLAG_STORED );
115169115030
if( sqlite3ResolveSelfReference(pParse, p, NC_GenCol, pX, 0) ){
115170115031
/* If there are errors in resolving the expression, change the
115171115032
** expression to a NULL. This prevents code generators that operate
115172115033
** on the expression from inserting extra parts into the expression
115173115034
** tree that have been allocated from lookaside memory, which is
115174115035
** illegal in a schema and will lead to errors or heap corruption
115175115036
** when the database connection closes. */
115176
- sqlite3ExprDelete(db, pX);
115177
- p->aCol[ii].pDflt = sqlite3ExprAlloc(db, TK_NULL, 0, 0);
115037
+ sqlite3ColumnSetExpr(pParse, p, &p->aCol[ii],
115038
+ sqlite3ExprAlloc(db, TK_NULL, 0, 0));
115178115039
}
115179115040
}else{
115180115041
nNG++;
115181115042
}
115182115043
}
@@ -115212,11 +115073,11 @@
115212115073
sqlite3VdbeAddOp1(v, OP_Close, 0);
115213115074
115214115075
/*
115215115076
** Initialize zType for the new view or table.
115216115077
*/
115217
- if( p->pSelect==0 ){
115078
+ if( IsOrdinaryTable(p) ){
115218115079
/* A regular table */
115219115080
zType = "table";
115220115081
zType2 = "TABLE";
115221115082
#ifndef SQLITE_OMIT_VIEW
115222115083
}else{
@@ -115362,16 +115223,16 @@
115362115223
}
115363115224
#endif
115364115225
}
115365115226
115366115227
#ifndef SQLITE_OMIT_ALTERTABLE
115367
- if( !pSelect && !p->pSelect ){
115228
+ if( !pSelect && IsOrdinaryTable(p) ){
115368115229
assert( pCons && pEnd );
115369115230
if( pCons->z==0 ){
115370115231
pCons = pEnd;
115371115232
}
115372
- p->addColOffset = 13 + (int)(pCons->z - pParse->sNameToken.z);
115233
+ p->u.tab.addColOffset = 13 + (int)(pCons->z - pParse->sNameToken.z);
115373115234
}
115374115235
#endif
115375115236
}
115376115237
115377115238
#ifndef SQLITE_OMIT_VIEW
@@ -115424,16 +115285,17 @@
115424115285
** allocated rather than point to the input string - which means that
115425115286
** they will persist after the current sqlite3_exec() call returns.
115426115287
*/
115427115288
pSelect->selFlags |= SF_View;
115428115289
if( IN_RENAME_OBJECT ){
115429
- p->pSelect = pSelect;
115290
+ p->u.view.pSelect = pSelect;
115430115291
pSelect = 0;
115431115292
}else{
115432
- p->pSelect = sqlite3SelectDup(db, pSelect, EXPRDUP_REDUCE);
115293
+ p->u.view.pSelect = sqlite3SelectDup(db, pSelect, EXPRDUP_REDUCE);
115433115294
}
115434115295
p->pCheck = sqlite3ExprListDup(db, pCNames, EXPRDUP_REDUCE);
115296
+ p->eTabType = TABTYP_VIEW;
115435115297
if( db->mallocFailed ) goto create_view_fail;
115436115298
115437115299
/* Locate the end of the CREATE VIEW statement. Make sEnd point to
115438115300
** the end.
115439115301
*/
@@ -115526,12 +115388,12 @@
115526115388
** "*" elements in the results set of the view and will assign cursors
115527115389
** to the elements of the FROM clause. But we do not want these changes
115528115390
** to be permanent. So the computation is done on a copy of the SELECT
115529115391
** statement that defines the view.
115530115392
*/
115531
- assert( pTable->pSelect );
115532
- pSel = sqlite3SelectDup(db, pTable->pSelect, 0);
115393
+ assert( IsView(pTable) );
115394
+ pSel = sqlite3SelectDup(db, pTable->u.view.pSelect, 0);
115533115395
if( pSel ){
115534115396
u8 eParseMode = pParse->eParseMode;
115535115397
pParse->eParseMode = PARSE_MODE_NORMAL;
115536115398
n = pParse->nTab;
115537115399
sqlite3SrcListAssignCursors(pParse, pSel->pSrc);
@@ -115586,12 +115448,10 @@
115586115448
nErr++;
115587115449
}
115588115450
pTable->pSchema->schemaFlags |= DB_UnresetViews;
115589115451
if( db->mallocFailed ){
115590115452
sqlite3DeleteColumnNames(db, pTable);
115591
- pTable->aCol = 0;
115592
- pTable->nCol = 0;
115593115453
}
115594115454
#endif /* SQLITE_OMIT_VIEW */
115595115455
return nErr;
115596115456
}
115597115457
#endif /* !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_VIRTUALTABLE) */
@@ -115604,14 +115464,12 @@
115604115464
HashElem *i;
115605115465
assert( sqlite3SchemaMutexHeld(db, idx, 0) );
115606115466
if( !DbHasProperty(db, idx, DB_UnresetViews) ) return;
115607115467
for(i=sqliteHashFirst(&db->aDb[idx].pSchema->tblHash); i;i=sqliteHashNext(i)){
115608115468
Table *pTab = sqliteHashData(i);
115609
- if( pTab->pSelect ){
115469
+ if( IsView(pTab) ){
115610115470
sqlite3DeleteColumnNames(db, pTab);
115611
- pTab->aCol = 0;
115612
- pTab->nCol = 0;
115613115471
}
115614115472
}
115615115473
DbClearProperty(db, idx, DB_UnresetViews);
115616115474
}
115617115475
#else
@@ -115948,15 +115806,15 @@
115948115806
115949115807
#ifndef SQLITE_OMIT_VIEW
115950115808
/* Ensure DROP TABLE is not used on a view, and DROP VIEW is not used
115951115809
** on a table.
115952115810
*/
115953
- if( isView && pTab->pSelect==0 ){
115811
+ if( isView && !IsView(pTab) ){
115954115812
sqlite3ErrorMsg(pParse, "use DROP TABLE to delete table %s", pTab->zName);
115955115813
goto exit_drop_table;
115956115814
}
115957
- if( !isView && pTab->pSelect ){
115815
+ if( !isView && IsView(pTab) ){
115958115816
sqlite3ErrorMsg(pParse, "use DROP VIEW to delete view %s", pTab->zName);
115959115817
goto exit_drop_table;
115960115818
}
115961115819
#endif
115962115820
@@ -116016,11 +115874,11 @@
116016115874
int iCol = p->nCol-1;
116017115875
if( NEVER(iCol<0) ) goto fk_end;
116018115876
if( pToCol && pToCol->nExpr!=1 ){
116019115877
sqlite3ErrorMsg(pParse, "foreign key on %s"
116020115878
" should reference only one column of table %T",
116021
- p->aCol[iCol].zName, pTo);
115879
+ p->aCol[iCol].zCnName, pTo);
116022115880
goto fk_end;
116023115881
}
116024115882
nCol = 1;
116025115883
}else if( pToCol && pToCol->nExpr!=pFromCol->nExpr ){
116026115884
sqlite3ErrorMsg(pParse,
@@ -116039,11 +115897,11 @@
116039115897
pFKey = sqlite3DbMallocZero(db, nByte );
116040115898
if( pFKey==0 ){
116041115899
goto fk_end;
116042115900
}
116043115901
pFKey->pFrom = p;
116044
- pFKey->pNextFrom = p->pFKey;
115902
+ pFKey->pNextFrom = p->u.tab.pFKey;
116045115903
z = (char*)&pFKey->aCol[nCol];
116046115904
pFKey->zTo = z;
116047115905
if( IN_RENAME_OBJECT ){
116048115906
sqlite3RenameTokenMap(pParse, (void*)z, pTo);
116049115907
}
@@ -116056,11 +115914,11 @@
116056115914
pFKey->aCol[0].iFrom = p->nCol-1;
116057115915
}else{
116058115916
for(i=0; i<nCol; i++){
116059115917
int j;
116060115918
for(j=0; j<p->nCol; j++){
116061
- if( sqlite3StrICmp(p->aCol[j].zName, pFromCol->a[i].zEName)==0 ){
115919
+ if( sqlite3StrICmp(p->aCol[j].zCnName, pFromCol->a[i].zEName)==0 ){
116062115920
pFKey->aCol[i].iFrom = j;
116063115921
break;
116064115922
}
116065115923
}
116066115924
if( j>=p->nCol ){
@@ -116104,11 +115962,12 @@
116104115962
pNextTo->pPrevTo = pFKey;
116105115963
}
116106115964
116107115965
/* Link the foreign key to the table as the last step.
116108115966
*/
116109
- p->pFKey = pFKey;
115967
+ assert( !IsVirtual(p) );
115968
+ p->u.tab.pFKey = pFKey;
116110115969
pFKey = 0;
116111115970
116112115971
fk_end:
116113115972
sqlite3DbFree(db, pFKey);
116114115973
#endif /* !defined(SQLITE_OMIT_FOREIGN_KEY) */
@@ -116125,11 +115984,13 @@
116125115984
*/
116126115985
SQLITE_PRIVATE void sqlite3DeferForeignKey(Parse *pParse, int isDeferred){
116127115986
#ifndef SQLITE_OMIT_FOREIGN_KEY
116128115987
Table *pTab;
116129115988
FKey *pFKey;
116130
- if( (pTab = pParse->pNewTable)==0 || (pFKey = pTab->pFKey)==0 ) return;
115989
+ if( (pTab = pParse->pNewTable)==0 ) return;
115990
+ if( NEVER(IsVirtual(pTab)) ) return;
115991
+ if( (pFKey = pTab->u.tab.pFKey)==0 ) return;
116131115992
assert( isDeferred==0 || isDeferred==1 ); /* EV: R-30323-21917 */
116132115993
pFKey->isDeferred = (u8)isDeferred;
116133115994
#endif
116134115995
}
116135115996
@@ -116417,11 +116278,11 @@
116417116278
){
116418116279
sqlite3ErrorMsg(pParse, "table %s may not be indexed", pTab->zName);
116419116280
goto exit_create_index;
116420116281
}
116421116282
#ifndef SQLITE_OMIT_VIEW
116422
- if( pTab->pSelect ){
116283
+ if( IsView(pTab) ){
116423116284
sqlite3ErrorMsg(pParse, "views may not be indexed");
116424116285
goto exit_create_index;
116425116286
}
116426116287
#endif
116427116288
#ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -116508,11 +116369,11 @@
116508116369
*/
116509116370
if( pList==0 ){
116510116371
Token prevCol;
116511116372
Column *pCol = &pTab->aCol[pTab->nCol-1];
116512116373
pCol->colFlags |= COLFLAG_UNIQUE;
116513
- sqlite3TokenInit(&prevCol, pCol->zName);
116374
+ sqlite3TokenInit(&prevCol, pCol->zCnName);
116514116375
pList = sqlite3ExprListAppend(pParse, 0,
116515116376
sqlite3ExprAlloc(db, TK_ID, &prevCol, 0));
116516116377
if( pList==0 ) goto exit_create_index;
116517116378
assert( pList->nExpr==1 );
116518116379
sqlite3ExprListSetSortOrder(pList, sortOrder, SQLITE_SO_UNDEFINED);
@@ -116629,11 +116490,11 @@
116629116490
memcpy(zExtra, zColl, nColl);
116630116491
zColl = zExtra;
116631116492
zExtra += nColl;
116632116493
nExtra -= nColl;
116633116494
}else if( j>=0 ){
116634
- zColl = pTab->aCol[j].zColl;
116495
+ zColl = sqlite3ColumnColl(&pTab->aCol[j]);
116635116496
}
116636116497
if( !zColl ) zColl = sqlite3StrBINARY;
116637116498
if( !db->init.busy && !sqlite3LocateCollSeq(pParse, zColl) ){
116638116499
goto exit_create_index;
116639116500
}
@@ -117721,11 +117582,11 @@
117721117582
sqlite3_str_appendf(&errMsg, "index '%q'", pIdx->zName);
117722117583
}else{
117723117584
for(j=0; j<pIdx->nKeyCol; j++){
117724117585
char *zCol;
117725117586
assert( pIdx->aiColumn[j]>=0 );
117726
- zCol = pTab->aCol[pIdx->aiColumn[j]].zName;
117587
+ zCol = pTab->aCol[pIdx->aiColumn[j]].zCnName;
117727117588
if( j ) sqlite3_str_append(&errMsg, ", ", 2);
117728117589
sqlite3_str_appendall(&errMsg, pTab->zName);
117729117590
sqlite3_str_append(&errMsg, ".", 1);
117730117591
sqlite3_str_appendall(&errMsg, zCol);
117731117592
}
@@ -117748,11 +117609,11 @@
117748117609
){
117749117610
char *zMsg;
117750117611
int rc;
117751117612
if( pTab->iPKey>=0 ){
117752117613
zMsg = sqlite3MPrintf(pParse->db, "%s.%s", pTab->zName,
117753
- pTab->aCol[pTab->iPKey].zName);
117614
+ pTab->aCol[pTab->iPKey].zCnName);
117754117615
rc = SQLITE_CONSTRAINT_PRIMARYKEY;
117755117616
}else{
117756117617
zMsg = sqlite3MPrintf(pParse->db, "%s.rowid", pTab->zName);
117757117618
rc = SQLITE_CONSTRAINT_ROWID;
117758117619
}
@@ -118675,11 +118536,11 @@
118675118536
if( tabIsReadOnly(pParse, pTab) ){
118676118537
sqlite3ErrorMsg(pParse, "table %s may not be modified", pTab->zName);
118677118538
return 1;
118678118539
}
118679118540
#ifndef SQLITE_OMIT_VIEW
118680
- if( !viewOk && pTab->pSelect ){
118541
+ if( !viewOk && IsView(pTab) ){
118681118542
sqlite3ErrorMsg(pParse,"cannot modify %s because it is a view",pTab->zName);
118682118543
return 1;
118683118544
}
118684118545
#endif
118685118546
return 0;
@@ -118779,17 +118640,17 @@
118779118640
pParse, 0, sqlite3PExpr(pParse, TK_ROW, 0, 0)
118780118641
);
118781118642
}else{
118782118643
Index *pPk = sqlite3PrimaryKeyIndex(pTab);
118783118644
if( pPk->nKeyCol==1 ){
118784
- const char *zName = pTab->aCol[pPk->aiColumn[0]].zName;
118645
+ const char *zName = pTab->aCol[pPk->aiColumn[0]].zCnName;
118785118646
pLhs = sqlite3Expr(db, TK_ID, zName);
118786118647
pEList = sqlite3ExprListAppend(pParse, 0, sqlite3Expr(db, TK_ID, zName));
118787118648
}else{
118788118649
int i;
118789118650
for(i=0; i<pPk->nKeyCol; i++){
118790
- Expr *p = sqlite3Expr(db, TK_ID, pTab->aCol[pPk->aiColumn[i]].zName);
118651
+ Expr *p = sqlite3Expr(db, TK_ID, pTab->aCol[pPk->aiColumn[i]].zCnName);
118791118652
pEList = sqlite3ExprListAppend(pParse, pEList, p);
118792118653
}
118793118654
pLhs = sqlite3PExpr(pParse, TK_VECTOR, 0, 0);
118794118655
if( pLhs ){
118795118656
pLhs->x.pList = sqlite3ExprListDup(db, pEList, 0);
@@ -118892,11 +118753,11 @@
118892118753
/* Figure out if we have any triggers and if the table being
118893118754
** deleted from is a view
118894118755
*/
118895118756
#ifndef SQLITE_OMIT_TRIGGER
118896118757
pTrigger = sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0, 0);
118897
- isView = pTab->pSelect!=0;
118758
+ isView = IsView(pTab);
118898118759
#else
118899118760
# define pTrigger 0
118900118761
# define isView 0
118901118762
#endif
118902118763
bComplex = pTrigger || sqlite3FkRequired(pParse, pTab, 0, 0);
@@ -119142,11 +119003,11 @@
119142119003
** where-clause loop above.
119143119004
*/
119144119005
if( eOnePass!=ONEPASS_OFF ){
119145119006
assert( nKey==nPk ); /* OP_Found will use an unpacked key */
119146119007
if( !IsVirtual(pTab) && aToOpen[iDataCur-iTabCur] ){
119147
- assert( pPk!=0 || pTab->pSelect!=0 );
119008
+ assert( pPk!=0 || IsView(pTab) );
119148119009
sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, addrBypass, iKey, nKey);
119149119010
VdbeCoverage(v);
119150119011
}
119151119012
}else if( pPk ){
119152119013
addrLoop = sqlite3VdbeAddOp1(v, OP_Rewind, iEphCur); VdbeCoverage(v);
@@ -119376,11 +119237,11 @@
119376119237
** invoke the update-hook. The pre-update-hook, on the other hand should
119377119238
** be invoked unless table pTab is a system table. The difference is that
119378119239
** the update-hook is not invoked for rows removed by REPLACE, but the
119379119240
** pre-update-hook is.
119380119241
*/
119381
- if( pTab->pSelect==0 ){
119242
+ if( !IsView(pTab) ){
119382119243
u8 p5 = 0;
119383119244
sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur,0,iIdxNoSeek);
119384119245
sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, (count?OPFLAG_NCHANGE:0));
119385119246
if( pParse->nested==0 || 0==sqlite3_stricmp(pTab->zName, "sqlite_stat1") ){
119386119247
sqlite3VdbeAppendP4(v, (char*)pTab, P4_TABLE);
@@ -122070,11 +121931,13 @@
122070121931
** 2) The FK is explicitly mapped to a column declared as INTEGER
122071121932
** PRIMARY KEY.
122072121933
*/
122073121934
if( pParent->iPKey>=0 ){
122074121935
if( !zKey ) return 0;
122075
- if( !sqlite3StrICmp(pParent->aCol[pParent->iPKey].zName, zKey) ) return 0;
121936
+ if( !sqlite3StrICmp(pParent->aCol[pParent->iPKey].zCnName, zKey) ){
121937
+ return 0;
121938
+ }
122076121939
}
122077121940
}else if( paiCol ){
122078121941
assert( nCol>1 );
122079121942
aiCol = (int *)sqlite3DbMallocRawNN(pParse->db, nCol*sizeof(int));
122080121943
if( !aiCol ) return 1;
@@ -122112,15 +121975,15 @@
122112121975
if( iCol<0 ) break; /* No foreign keys against expression indexes */
122113121976
122114121977
/* If the index uses a collation sequence that is different from
122115121978
** the default collation sequence for the column, this index is
122116121979
** unusable. Bail out early in this case. */
122117
- zDfltColl = pParent->aCol[iCol].zColl;
121980
+ zDfltColl = sqlite3ColumnColl(&pParent->aCol[iCol]);
122118121981
if( !zDfltColl ) zDfltColl = sqlite3StrBINARY;
122119121982
if( sqlite3StrICmp(pIdx->azColl[i], zDfltColl) ) break;
122120121983
122121
- zIdxCol = pParent->aCol[iCol].zName;
121984
+ zIdxCol = pParent->aCol[iCol].zCnName;
122122121985
for(j=0; j<nCol; j++){
122123121986
if( sqlite3StrICmp(pFKey->aCol[j].zCol, zIdxCol)==0 ){
122124121987
if( aiCol ) aiCol[i] = pFKey->aCol[j].iFrom;
122125121988
break;
122126121989
}
@@ -122340,11 +122203,11 @@
122340122203
if( pExpr ){
122341122204
if( iCol>=0 && iCol!=pTab->iPKey ){
122342122205
pCol = &pTab->aCol[iCol];
122343122206
pExpr->iTable = regBase + sqlite3TableColumnToStorage(pTab,iCol) + 1;
122344122207
pExpr->affExpr = pCol->affinity;
122345
- zColl = pCol->zColl;
122208
+ zColl = sqlite3ColumnColl(pCol);
122346122209
if( zColl==0 ) zColl = db->pDfltColl->zName;
122347122210
pExpr = sqlite3ExprAddCollateString(pParse, pExpr, zColl);
122348122211
}else{
122349122212
pExpr->iTable = regBase;
122350122213
pExpr->affExpr = SQLITE_AFF_INTEGER;
@@ -122449,11 +122312,11 @@
122449122312
122450122313
iCol = pIdx ? pIdx->aiColumn[i] : -1;
122451122314
pLeft = exprTableRegister(pParse, pTab, regData, iCol);
122452122315
iCol = aiCol ? aiCol[i] : pFKey->aCol[0].iFrom;
122453122316
assert( iCol>=0 );
122454
- zCol = pFKey->pFrom->aCol[iCol].zName;
122317
+ zCol = pFKey->pFrom->aCol[iCol].zCnName;
122455122318
pRight = sqlite3Expr(db, TK_ID, zCol);
122456122319
pEq = sqlite3PExpr(pParse, TK_EQ, pLeft, pRight);
122457122320
pWhere = sqlite3ExprAnd(pParse, pWhere, pEq);
122458122321
}
122459122322
@@ -122484,11 +122347,11 @@
122484122347
assert( pIdx!=0 );
122485122348
for(i=0; i<pIdx->nKeyCol; i++){
122486122349
i16 iCol = pIdx->aiColumn[i];
122487122350
assert( iCol>=0 );
122488122351
pLeft = exprTableRegister(pParse, pTab, regData, iCol);
122489
- pRight = sqlite3Expr(db, TK_ID, pTab->aCol[iCol].zName);
122352
+ pRight = sqlite3Expr(db, TK_ID, pTab->aCol[iCol].zCnName);
122490122353
pEq = sqlite3PExpr(pParse, TK_IS, pLeft, pRight);
122491122354
pAll = sqlite3ExprAnd(pParse, pAll, pEq);
122492122355
}
122493122356
pNe = sqlite3PExpr(pParse, TK_NOT, pAll, 0);
122494122357
}
@@ -122578,19 +122441,20 @@
122578122441
if( (db->flags&SQLITE_ForeignKeys) && !IsVirtual(pTab) ){
122579122442
int iSkip = 0;
122580122443
Vdbe *v = sqlite3GetVdbe(pParse);
122581122444
122582122445
assert( v ); /* VDBE has already been allocated */
122583
- assert( pTab->pSelect==0 ); /* Not a view */
122446
+ assert( !IsView(pTab) ); /* Not a view */
122447
+ assert( !IsVirtual(pTab) );
122584122448
if( sqlite3FkReferences(pTab)==0 ){
122585122449
/* Search for a deferred foreign key constraint for which this table
122586122450
** is the child table. If one cannot be found, return without
122587122451
** generating any VDBE code. If one can be found, then jump over
122588122452
** the entire DELETE if there are no outstanding deferred constraints
122589122453
** when this statement is run. */
122590122454
FKey *p;
122591
- for(p=pTab->pFKey; p; p=p->pNextFrom){
122455
+ for(p=pTab->u.tab.pFKey; p; p=p->pNextFrom){
122592122456
if( p->isDeferred || (db->flags & SQLITE_DeferFKs) ) break;
122593122457
}
122594122458
if( !p ) return;
122595122459
iSkip = sqlite3VdbeMakeLabel(pParse);
122596122460
sqlite3VdbeAddOp2(v, OP_FkIfZero, 1, iSkip); VdbeCoverage(v);
@@ -122675,11 +122539,11 @@
122675122539
int iKey;
122676122540
for(iKey=0; iKey<pTab->nCol; iKey++){
122677122541
if( aChange[iKey]>=0 || (iKey==pTab->iPKey && bChngRowid) ){
122678122542
Column *pCol = &pTab->aCol[iKey];
122679122543
if( zKey ){
122680
- if( 0==sqlite3StrICmp(pCol->zName, zKey) ) return 1;
122544
+ if( 0==sqlite3StrICmp(pCol->zCnName, zKey) ) return 1;
122681122545
}else if( pCol->colFlags & COLFLAG_PRIMKEY ){
122682122546
return 1;
122683122547
}
122684122548
}
122685122549
}
@@ -122748,11 +122612,12 @@
122748122612
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
122749122613
zDb = db->aDb[iDb].zDbSName;
122750122614
122751122615
/* Loop through all the foreign key constraints for which pTab is the
122752122616
** child table (the table that the foreign key definition is part of). */
122753
- for(pFKey=pTab->pFKey; pFKey; pFKey=pFKey->pNextFrom){
122617
+ assert( !IsVirtual(pTab) );
122618
+ for(pFKey=pTab->u.tab.pFKey; pFKey; pFKey=pFKey->pNextFrom){
122754122619
Table *pTo; /* Parent table of foreign key pFKey */
122755122620
Index *pIdx = 0; /* Index on key columns in pTo */
122756122621
int *aiFree = 0;
122757122622
int *aiCol;
122758122623
int iCol;
@@ -122815,11 +122680,11 @@
122815122680
/* Request permission to read the parent key columns. If the
122816122681
** authorization callback returns SQLITE_IGNORE, behave as if any
122817122682
** values read from the parent table are NULL. */
122818122683
if( db->xAuth ){
122819122684
int rcauth;
122820
- char *zCol = pTo->aCol[pIdx ? pIdx->aiColumn[i] : pTo->iPKey].zName;
122685
+ char *zCol = pTo->aCol[pIdx ? pIdx->aiColumn[i] : pTo->iPKey].zCnName;
122821122686
rcauth = sqlite3AuthReadCol(pParse, pTo->zName, zCol, iDb);
122822122687
bIgnore = (rcauth==SQLITE_IGNORE);
122823122688
}
122824122689
#endif
122825122690
}
@@ -122933,11 +122798,12 @@
122933122798
){
122934122799
u32 mask = 0;
122935122800
if( pParse->db->flags&SQLITE_ForeignKeys ){
122936122801
FKey *p;
122937122802
int i;
122938
- for(p=pTab->pFKey; p; p=p->pNextFrom){
122803
+ assert( !IsVirtual(pTab) );
122804
+ for(p=pTab->u.tab.pFKey; p; p=p->pNextFrom){
122939122805
for(i=0; i<p->nCol; i++) mask |= COLUMN_MASK(p->aCol[i].iFrom);
122940122806
}
122941122807
for(p=sqlite3FkReferences(pTab); p; p=p->pNextTo){
122942122808
Index *pIdx = 0;
122943122809
sqlite3FkLocateIndex(pParse, pTab, p, &pIdx, 0);
@@ -122983,23 +122849,23 @@
122983122849
int *aChange, /* Non-NULL for UPDATE operations */
122984122850
int chngRowid /* True for UPDATE that affects rowid */
122985122851
){
122986122852
int eRet = 1; /* Value to return if bHaveFK is true */
122987122853
int bHaveFK = 0; /* If FK processing is required */
122988
- if( pParse->db->flags&SQLITE_ForeignKeys ){
122854
+ if( pParse->db->flags&SQLITE_ForeignKeys && !IsVirtual(pTab) ){
122989122855
if( !aChange ){
122990122856
/* A DELETE operation. Foreign key processing is required if the
122991122857
** table in question is either the child or parent table for any
122992122858
** foreign key constraint. */
122993
- bHaveFK = (sqlite3FkReferences(pTab) || pTab->pFKey);
122859
+ bHaveFK = (sqlite3FkReferences(pTab) || pTab->u.tab.pFKey);
122994122860
}else{
122995122861
/* This is an UPDATE. Foreign key processing is only required if the
122996122862
** operation modifies one or more child or parent key columns. */
122997122863
FKey *p;
122998122864
122999122865
/* Check if any child key columns are being modified. */
123000
- for(p=pTab->pFKey; p; p=p->pNextFrom){
122866
+ for(p=pTab->u.tab.pFKey; p; p=p->pNextFrom){
123001122867
if( fkChildIsModified(pTab, p, aChange, chngRowid) ){
123002122868
if( 0==sqlite3_stricmp(pTab->zName, p->zTo) ) eRet = 2;
123003122869
bHaveFK = 1;
123004122870
}
123005122871
}
@@ -123088,12 +122954,12 @@
123088122954
iFromCol = aiCol ? aiCol[i] : pFKey->aCol[0].iFrom;
123089122955
assert( iFromCol>=0 );
123090122956
assert( pIdx!=0 || (pTab->iPKey>=0 && pTab->iPKey<pTab->nCol) );
123091122957
assert( pIdx==0 || pIdx->aiColumn[i]>=0 );
123092122958
sqlite3TokenInit(&tToCol,
123093
- pTab->aCol[pIdx ? pIdx->aiColumn[i] : pTab->iPKey].zName);
123094
- sqlite3TokenInit(&tFromCol, pFKey->pFrom->aCol[iFromCol].zName);
122959
+ pTab->aCol[pIdx ? pIdx->aiColumn[i] : pTab->iPKey].zCnName);
122960
+ sqlite3TokenInit(&tFromCol, pFKey->pFrom->aCol[iFromCol].zCnName);
123095122961
123096122962
/* Create the expression "OLD.zToCol = zFromCol". It is important
123097122963
** that the "OLD.zToCol" term is on the LHS of the = operator, so
123098122964
** that the affinity and collation sequence associated with the
123099122965
** parent table are used for the comparison. */
@@ -123134,11 +123000,11 @@
123134123000
if( pCol->colFlags & COLFLAG_GENERATED ){
123135123001
testcase( pCol->colFlags & COLFLAG_VIRTUAL );
123136123002
testcase( pCol->colFlags & COLFLAG_STORED );
123137123003
pDflt = 0;
123138123004
}else{
123139
- pDflt = pCol->pDflt;
123005
+ pDflt = sqlite3ColumnExpr(pFKey->pFrom, pCol);
123140123006
}
123141123007
if( pDflt ){
123142123008
pNew = sqlite3ExprDup(db, pDflt, 0);
123143123009
}else{
123144123010
pNew = sqlite3ExprAlloc(db, TK_NULL, 0, 0);
@@ -123271,13 +123137,13 @@
123271123137
*/
123272123138
SQLITE_PRIVATE void sqlite3FkDelete(sqlite3 *db, Table *pTab){
123273123139
FKey *pFKey; /* Iterator variable */
123274123140
FKey *pNext; /* Copy of pFKey->pNextFrom */
123275123141
123276
- assert( db==0 || IsVirtual(pTab)
123277
- || sqlite3SchemaMutexHeld(db, 0, pTab->pSchema) );
123278
- for(pFKey=pTab->pFKey; pFKey; pFKey=pNext){
123142
+ assert( !IsVirtual(pTab) );
123143
+ for(pFKey=pTab->u.tab.pFKey; pFKey; pFKey=pNext){
123144
+ assert( db==0 || sqlite3SchemaMutexHeld(db, 0, pTab->pSchema) );
123279123145
123280123146
/* Remove the FK from the fkeyHash hash table. */
123281123147
if( !db || db->pnBytesFreed==0 ){
123282123148
if( pFKey->pPrevTo ){
123283123149
pFKey->pPrevTo->pNextTo = pFKey->pNextTo;
@@ -123603,26 +123469,26 @@
123603123469
Column *pCol = pTab->aCol + i;
123604123470
if( (pCol->colFlags & COLFLAG_NOTAVAIL)!=0 ){
123605123471
int x;
123606123472
pCol->colFlags |= COLFLAG_BUSY;
123607123473
w.eCode = 0;
123608
- sqlite3WalkExpr(&w, pCol->pDflt);
123474
+ sqlite3WalkExpr(&w, sqlite3ColumnExpr(pTab, pCol));
123609123475
pCol->colFlags &= ~COLFLAG_BUSY;
123610123476
if( w.eCode & COLFLAG_NOTAVAIL ){
123611123477
pRedo = pCol;
123612123478
continue;
123613123479
}
123614123480
eProgress = 1;
123615123481
assert( pCol->colFlags & COLFLAG_GENERATED );
123616123482
x = sqlite3TableColumnToStorage(pTab, i) + iRegStore;
123617
- sqlite3ExprCodeGeneratedColumn(pParse, pCol, x);
123483
+ sqlite3ExprCodeGeneratedColumn(pParse, pTab, pCol, x);
123618123484
pCol->colFlags &= ~COLFLAG_NOTAVAIL;
123619123485
}
123620123486
}
123621123487
}while( pRedo && eProgress );
123622123488
if( pRedo ){
123623
- sqlite3ErrorMsg(pParse, "generated column loop on \"%s\"", pRedo->zName);
123489
+ sqlite3ErrorMsg(pParse, "generated column loop on \"%s\"", pRedo->zCnName);
123624123490
}
123625123491
pParse->iSelfTab = 0;
123626123492
}
123627123493
#endif /* SQLITE_OMIT_GENERATED_COLUMNS */
123628123494
@@ -124013,11 +123879,11 @@
124013123879
/* Figure out if we have any triggers and if the table being
124014123880
** inserted into is a view
124015123881
*/
124016123882
#ifndef SQLITE_OMIT_TRIGGER
124017123883
pTrigger = sqlite3TriggersExist(pParse, pTab, TK_INSERT, 0, &tmask);
124018
- isView = pTab->pSelect!=0;
123884
+ isView = IsView(pTab);
124019123885
#else
124020123886
# define pTrigger 0
124021123887
# define tmask 0
124022123888
# define isView 0
124023123889
#endif
@@ -124104,21 +123970,21 @@
124104123970
for(i=0; i<pColumn->nId; i++){
124105123971
pColumn->a[i].idx = -1;
124106123972
}
124107123973
for(i=0; i<pColumn->nId; i++){
124108123974
for(j=0; j<pTab->nCol; j++){
124109
- if( sqlite3StrICmp(pColumn->a[i].zName, pTab->aCol[j].zName)==0 ){
123975
+ if( sqlite3StrICmp(pColumn->a[i].zName, pTab->aCol[j].zCnName)==0 ){
124110123976
pColumn->a[i].idx = j;
124111123977
if( i!=j ) bIdListInOrder = 0;
124112123978
if( j==pTab->iPKey ){
124113123979
ipkColumn = i; assert( !withoutRowid );
124114123980
}
124115123981
#ifndef SQLITE_OMIT_GENERATED_COLUMNS
124116123982
if( pTab->aCol[j].colFlags & (COLFLAG_STORED|COLFLAG_VIRTUAL) ){
124117123983
sqlite3ErrorMsg(pParse,
124118123984
"cannot INSERT into generated column \"%s\"",
124119
- pTab->aCol[j].zName);
123985
+ pTab->aCol[j].zCnName);
124120123986
goto insert_cleanup;
124121123987
}
124122123988
#endif
124123123989
break;
124124123990
}
@@ -124299,11 +124165,11 @@
124299124165
if( IsVirtual(pTab) ){
124300124166
sqlite3ErrorMsg(pParse, "UPSERT not implemented for virtual table \"%s\"",
124301124167
pTab->zName);
124302124168
goto insert_cleanup;
124303124169
}
124304
- if( pTab->pSelect ){
124170
+ if( IsView(pTab) ){
124305124171
sqlite3ErrorMsg(pParse, "cannot UPSERT a view");
124306124172
goto insert_cleanup;
124307124173
}
124308124174
if( sqlite3HasExplicitNulls(pParse, pUpsert->pUpsertTarget) ){
124309124175
goto insert_cleanup;
@@ -124398,26 +124264,32 @@
124398124264
}
124399124265
continue;
124400124266
}else if( pColumn==0 ){
124401124267
/* Hidden columns that are not explicitly named in the INSERT
124402124268
** get there default value */
124403
- sqlite3ExprCodeFactorable(pParse, pTab->aCol[i].pDflt, iRegStore);
124269
+ sqlite3ExprCodeFactorable(pParse,
124270
+ sqlite3ColumnExpr(pTab, &pTab->aCol[i]),
124271
+ iRegStore);
124404124272
continue;
124405124273
}
124406124274
}
124407124275
if( pColumn ){
124408124276
for(j=0; j<pColumn->nId && pColumn->a[j].idx!=i; j++){}
124409124277
if( j>=pColumn->nId ){
124410124278
/* A column not named in the insert column list gets its
124411124279
** default value */
124412
- sqlite3ExprCodeFactorable(pParse, pTab->aCol[i].pDflt, iRegStore);
124280
+ sqlite3ExprCodeFactorable(pParse,
124281
+ sqlite3ColumnExpr(pTab, &pTab->aCol[i]),
124282
+ iRegStore);
124413124283
continue;
124414124284
}
124415124285
k = j;
124416124286
}else if( nColumn==0 ){
124417124287
/* This is INSERT INTO ... DEFAULT VALUES. Load the default value. */
124418
- sqlite3ExprCodeFactorable(pParse, pTab->aCol[i].pDflt, iRegStore);
124288
+ sqlite3ExprCodeFactorable(pParse,
124289
+ sqlite3ColumnExpr(pTab, &pTab->aCol[i]),
124290
+ iRegStore);
124419124291
continue;
124420124292
}else{
124421124293
k = i - nHidden;
124422124294
}
124423124295
@@ -124928,11 +124800,11 @@
124928124800
124929124801
isUpdate = regOldData!=0;
124930124802
db = pParse->db;
124931124803
v = pParse->pVdbe;
124932124804
assert( v!=0 );
124933
- assert( pTab->pSelect==0 ); /* This table is not a VIEW */
124805
+ assert( !IsView(pTab) ); /* This table is not a VIEW */
124934124806
nCol = pTab->nCol;
124935124807
124936124808
/* pPk is the PRIMARY KEY index for WITHOUT ROWID tables and NULL for
124937124809
** normal rowid tables. nPkField is the number of key fields in the
124938124810
** pPk index or 1 for a rowid table. In other words, nPkField is the
@@ -124979,11 +124851,11 @@
124979124851
}else if( onError==OE_Default ){
124980124852
onError = OE_Abort;
124981124853
}
124982124854
if( onError==OE_Replace ){
124983124855
if( b2ndPass /* REPLACE becomes ABORT on the 2nd pass */
124984
- || pCol->pDflt==0 /* REPLACE is ABORT if no DEFAULT value */
124856
+ || pCol->iDflt==0 /* REPLACE is ABORT if no DEFAULT value */
124985124857
){
124986124858
testcase( pCol->colFlags & COLFLAG_VIRTUAL );
124987124859
testcase( pCol->colFlags & COLFLAG_STORED );
124988124860
testcase( pCol->colFlags & COLFLAG_GENERATED );
124989124861
onError = OE_Abort;
@@ -125001,21 +124873,22 @@
125001124873
case OE_Replace: {
125002124874
int addr1 = sqlite3VdbeAddOp1(v, OP_NotNull, iReg);
125003124875
VdbeCoverage(v);
125004124876
assert( (pCol->colFlags & COLFLAG_GENERATED)==0 );
125005124877
nSeenReplace++;
125006
- sqlite3ExprCodeCopy(pParse, pCol->pDflt, iReg);
124878
+ sqlite3ExprCodeCopy(pParse,
124879
+ sqlite3ColumnExpr(pTab, pCol), iReg);
125007124880
sqlite3VdbeJumpHere(v, addr1);
125008124881
break;
125009124882
}
125010124883
case OE_Abort:
125011124884
sqlite3MayAbort(pParse);
125012124885
/* no break */ deliberate_fall_through
125013124886
case OE_Rollback:
125014124887
case OE_Fail: {
125015124888
char *zMsg = sqlite3MPrintf(db, "%s.%s", pTab->zName,
125016
- pCol->zName);
124889
+ pCol->zCnName);
125017124890
sqlite3VdbeAddOp3(v, OP_HaltIfNull, SQLITE_CONSTRAINT_NOTNULL,
125018124891
onError, iReg);
125019124892
sqlite3VdbeAppendP4(v, zMsg, P4_DYNAMIC);
125020124893
sqlite3VdbeChangeP5(v, P5_ConstraintNotNull);
125021124894
VdbeCoverage(v);
@@ -125429,11 +125302,11 @@
125429125302
VdbeComment((v, "rowid"));
125430125303
}else{
125431125304
testcase( sqlite3TableColumnToStorage(pTab, iField)!=iField );
125432125305
x = sqlite3TableColumnToStorage(pTab, iField) + regNewData + 1;
125433125306
sqlite3VdbeAddOp2(v, OP_SCopy, x, regIdx+i);
125434
- VdbeComment((v, "%s", pTab->aCol[iField].zName));
125307
+ VdbeComment((v, "%s", pTab->aCol[iField].zCnName));
125435125308
}
125436125309
}
125437125310
sqlite3VdbeAddOp3(v, OP_MakeRecord, regIdx, pIdx->nColumn, aRegIdx[ix]);
125438125311
VdbeComment((v, "for %s", pIdx->zName));
125439125312
#ifdef SQLITE_ENABLE_NULL_TRIM
@@ -125488,11 +125361,11 @@
125488125361
&& pPk==pIdx /* Condition 2 */
125489125362
&& onError==OE_Replace /* Condition 1 */
125490125363
&& ( 0==(db->flags&SQLITE_RecTriggers) || /* Condition 4 */
125491125364
0==sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0, 0))
125492125365
&& ( 0==(db->flags&SQLITE_ForeignKeys) || /* Condition 5 */
125493
- (0==pTab->pFKey && 0==sqlite3FkReferences(pTab)))
125366
+ (0==pTab->u.tab.pFKey && 0==sqlite3FkReferences(pTab)))
125494125367
){
125495125368
sqlite3VdbeResolveLabel(v, addrUniqueOk);
125496125369
continue;
125497125370
}
125498125371
#endif /* ifndef SQLITE_ENABLE_PREUPDATE_HOOK */
@@ -125523,11 +125396,11 @@
125523125396
for(i=0; i<pPk->nKeyCol; i++){
125524125397
assert( pPk->aiColumn[i]>=0 );
125525125398
x = sqlite3TableColumnToIndex(pIdx, pPk->aiColumn[i]);
125526125399
sqlite3VdbeAddOp3(v, OP_Column, iThisCur, x, regR+i);
125527125400
VdbeComment((v, "%s.%s", pTab->zName,
125528
- pTab->aCol[pPk->aiColumn[i]].zName));
125401
+ pTab->aCol[pPk->aiColumn[i]].zCnName));
125529125402
}
125530125403
}
125531125404
if( isUpdate ){
125532125405
/* If currently processing the PRIMARY KEY of a WITHOUT ROWID
125533125406
** table, only conflict if the new PRIMARY KEY values are actually
@@ -125722,11 +125595,11 @@
125722125595
/* Records with omitted columns are only allowed for schema format
125723125596
** version 2 and later (SQLite version 3.1.4, 2005-02-20). */
125724125597
if( pTab->pSchema->file_format<2 ) return;
125725125598
125726125599
for(i=pTab->nCol-1; i>0; i--){
125727
- if( pTab->aCol[i].pDflt!=0 ) break;
125600
+ if( pTab->aCol[i].iDflt!=0 ) break;
125728125601
if( pTab->aCol[i].colFlags & COLFLAG_PRIMKEY ) break;
125729125602
}
125730125603
sqlite3VdbeChangeP5(v, i+1);
125731125604
}
125732125605
#endif
@@ -125787,11 +125660,11 @@
125787125660
|| update_flags==(OPFLAG_ISUPDATE|OPFLAG_SAVEPOSITION)
125788125661
);
125789125662
125790125663
v = pParse->pVdbe;
125791125664
assert( v!=0 );
125792
- assert( pTab->pSelect==0 ); /* This table is not a VIEW */
125665
+ assert( !IsView(pTab) ); /* This table is not a VIEW */
125793125666
for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
125794125667
/* All REPLACE indexes are at the end of the list */
125795125668
assert( pIdx->onError!=OE_Replace
125796125669
|| pIdx->pNext==0
125797125670
|| pIdx->pNext->onError==OE_Replace );
@@ -126089,17 +125962,12 @@
126089125962
return 0; /* tab1 and tab2 may not be the same table */
126090125963
}
126091125964
if( HasRowid(pDest)!=HasRowid(pSrc) ){
126092125965
return 0; /* source and destination must both be WITHOUT ROWID or not */
126093125966
}
126094
-#ifndef SQLITE_OMIT_VIRTUALTABLE
126095
- if( IsVirtual(pSrc) ){
126096
- return 0; /* tab2 must not be a virtual table */
126097
- }
126098
-#endif
126099
- if( pSrc->pSelect ){
126100
- return 0; /* tab2 may not be a view */
125967
+ if( !IsOrdinaryTable(pSrc) ){
125968
+ return 0; /* tab2 may not be a view or virtual table */
126101125969
}
126102125970
if( pDest->nCol!=pSrc->nCol ){
126103125971
return 0; /* Number of columns must be the same in tab1 and tab2 */
126104125972
}
126105125973
if( pDest->iPKey!=pSrc->iPKey ){
@@ -126139,33 +126007,38 @@
126139126007
/* But the transfer is only allowed if both the source and destination
126140126008
** tables have the exact same expressions for generated columns.
126141126009
** This requirement could be relaxed for VIRTUAL columns, I suppose.
126142126010
*/
126143126011
if( (pDestCol->colFlags & COLFLAG_GENERATED)!=0 ){
126144
- if( sqlite3ExprCompare(0, pSrcCol->pDflt, pDestCol->pDflt, -1)!=0 ){
126012
+ if( sqlite3ExprCompare(0,
126013
+ sqlite3ColumnExpr(pSrc, pSrcCol),
126014
+ sqlite3ColumnExpr(pDest, pDestCol), -1)!=0 ){
126145126015
testcase( pDestCol->colFlags & COLFLAG_VIRTUAL );
126146126016
testcase( pDestCol->colFlags & COLFLAG_STORED );
126147126017
return 0; /* Different generator expressions */
126148126018
}
126149126019
}
126150126020
#endif
126151126021
if( pDestCol->affinity!=pSrcCol->affinity ){
126152126022
return 0; /* Affinity must be the same on all columns */
126153126023
}
126154
- if( sqlite3_stricmp(pDestCol->zColl, pSrcCol->zColl)!=0 ){
126024
+ if( sqlite3_stricmp(sqlite3ColumnColl(pDestCol),
126025
+ sqlite3ColumnColl(pSrcCol))!=0 ){
126155126026
return 0; /* Collating sequence must be the same on all columns */
126156126027
}
126157126028
if( pDestCol->notNull && !pSrcCol->notNull ){
126158126029
return 0; /* tab2 must be NOT NULL if tab1 is */
126159126030
}
126160126031
/* Default values for second and subsequent columns need to match. */
126161126032
if( (pDestCol->colFlags & COLFLAG_GENERATED)==0 && i>0 ){
126162
- assert( pDestCol->pDflt==0 || pDestCol->pDflt->op==TK_SPAN );
126163
- assert( pSrcCol->pDflt==0 || pSrcCol->pDflt->op==TK_SPAN );
126164
- if( (pDestCol->pDflt==0)!=(pSrcCol->pDflt==0)
126165
- || (pDestCol->pDflt && strcmp(pDestCol->pDflt->u.zToken,
126166
- pSrcCol->pDflt->u.zToken)!=0)
126033
+ Expr *pDestExpr = sqlite3ColumnExpr(pDest, pDestCol);
126034
+ Expr *pSrcExpr = sqlite3ColumnExpr(pSrc, pSrcCol);
126035
+ assert( pDestExpr==0 || pDestExpr->op==TK_SPAN );
126036
+ assert( pSrcExpr==0 || pSrcExpr->op==TK_SPAN );
126037
+ if( (pDestExpr==0)!=(pSrcExpr==0)
126038
+ || (pDestExpr!=0 && strcmp(pDestExpr->u.zToken,
126039
+ pSrcExpr->u.zToken)!=0)
126167126040
){
126168126041
return 0; /* Default values must be the same for all columns */
126169126042
}
126170126043
}
126171126044
}
@@ -126198,11 +126071,11 @@
126198126071
** But the main beneficiary of the transfer optimization is the VACUUM
126199126072
** command, and the VACUUM command disables foreign key constraints. So
126200126073
** the extra complication to make this rule less restrictive is probably
126201126074
** not worth the effort. Ticket [6284df89debdfa61db8073e062908af0c9b6118e]
126202126075
*/
126203
- if( (db->flags & SQLITE_ForeignKeys)!=0 && pDest->pFKey!=0 ){
126076
+ if( (db->flags & SQLITE_ForeignKeys)!=0 && pDest->u.tab.pFKey!=0 ){
126204126077
return 0;
126205126078
}
126206126079
#endif
126207126080
if( (db->flags & SQLITE_CountRows)!=0 ){
126208126081
return 0; /* xfer opt does not play well with PRAGMA count_changes */
@@ -129888,17 +129761,20 @@
129888129761
}else if( pPk==0 ){
129889129762
k = 1;
129890129763
}else{
129891129764
for(k=1; k<=pTab->nCol && pPk->aiColumn[k-1]!=i; k++){}
129892129765
}
129893
- assert( pCol->pDflt==0 || pCol->pDflt->op==TK_SPAN || isHidden>=2 );
129766
+ assert( sqlite3ColumnExpr(pTab,pCol)==0
129767
+ || sqlite3ColumnExpr(pTab,pCol)->op==TK_SPAN
129768
+ || isHidden>=2 );
129894129769
sqlite3VdbeMultiLoad(v, 1, pPragma->iArg ? "issisii" : "issisi",
129895129770
i-nHidden,
129896
- pCol->zName,
129771
+ pCol->zCnName,
129897129772
sqlite3ColumnType(pCol,""),
129898129773
pCol->notNull ? 1 : 0,
129899
- pCol->pDflt && isHidden<2 ? pCol->pDflt->u.zToken : 0,
129774
+ isHidden>=2 || sqlite3ColumnExpr(pTab,pCol)==0 ? 0 :
129775
+ sqlite3ColumnExpr(pTab,pCol)->u.zToken,
129900129776
k,
129901129777
isHidden);
129902129778
}
129903129779
}
129904129780
}
@@ -129961,11 +129837,11 @@
129961129837
sqlite3CodeVerifySchema(pParse, iIdxDb);
129962129838
assert( pParse->nMem<=pPragma->nPragCName );
129963129839
for(i=0; i<mx; i++){
129964129840
i16 cnum = pIdx->aiColumn[i];
129965129841
sqlite3VdbeMultiLoad(v, 1, "iisX", i, cnum,
129966
- cnum<0 ? 0 : pTab->aCol[cnum].zName);
129842
+ cnum<0 ? 0 : pTab->aCol[cnum].zCnName);
129967129843
if( pPragma->iArg ){
129968129844
sqlite3VdbeMultiLoad(v, 4, "isiX",
129969129845
pIdx->aSortOrder[i],
129970129846
pIdx->azColl[i],
129971129847
i<pIdx->nKeyCol);
@@ -130068,12 +129944,12 @@
130068129944
#ifndef SQLITE_OMIT_FOREIGN_KEY
130069129945
case PragTyp_FOREIGN_KEY_LIST: if( zRight ){
130070129946
FKey *pFK;
130071129947
Table *pTab;
130072129948
pTab = sqlite3FindTable(db, zRight, zDb);
130073
- if( pTab ){
130074
- pFK = pTab->pFKey;
129949
+ if( pTab && !IsVirtual(pTab) ){
129950
+ pFK = pTab->u.tab.pFKey;
130075129951
if( pFK ){
130076129952
int iTabDb = sqlite3SchemaToIndex(db, pTab->pSchema);
130077129953
int i = 0;
130078129954
pParse->nMem = 8;
130079129955
sqlite3CodeVerifySchema(pParse, iTabDb);
@@ -130082,11 +129958,11 @@
130082129958
for(j=0; j<pFK->nCol; j++){
130083129959
sqlite3VdbeMultiLoad(v, 1, "iissssss",
130084129960
i,
130085129961
j,
130086129962
pFK->zTo,
130087
- pTab->aCol[pFK->aCol[j].iFrom].zName,
129963
+ pTab->aCol[pFK->aCol[j].iFrom].zCnName,
130088129964
pFK->aCol[j].zCol,
130089129965
actionName(pFK->aAction[1]), /* ON UPDATE */
130090129966
actionName(pFK->aAction[0]), /* ON DELETE */
130091129967
"NONE");
130092129968
}
@@ -130128,19 +130004,20 @@
130128130004
k = 0;
130129130005
}else{
130130130006
pTab = (Table*)sqliteHashData(k);
130131130007
k = sqliteHashNext(k);
130132130008
}
130133
- if( pTab==0 || pTab->pFKey==0 ) continue;
130009
+ if( pTab==0 || IsVirtual(pTab) || pTab->u.tab.pFKey==0 ) continue;
130134130010
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
130135130011
zDb = db->aDb[iDb].zDbSName;
130136130012
sqlite3CodeVerifySchema(pParse, iDb);
130137130013
sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
130138130014
if( pTab->nCol+regRow>pParse->nMem ) pParse->nMem = pTab->nCol + regRow;
130139130015
sqlite3OpenTable(pParse, 0, iDb, pTab, OP_OpenRead);
130140130016
sqlite3VdbeLoadString(v, regResult, pTab->zName);
130141
- for(i=1, pFK=pTab->pFKey; pFK; i++, pFK=pFK->pNextFrom){
130017
+ assert( !IsVirtual(pTab) );
130018
+ for(i=1, pFK=pTab->u.tab.pFKey; pFK; i++, pFK=pFK->pNextFrom){
130142130019
pParent = sqlite3FindTable(db, pFK->zTo, zDb);
130143130020
if( pParent==0 ) continue;
130144130021
pIdx = 0;
130145130022
sqlite3TableLock(pParse, iDb, pParent->tnum, 0, pParent->zName);
130146130023
x = sqlite3FkLocateIndex(pParse, pParent, pFK, &pIdx, 0);
@@ -130158,11 +130035,12 @@
130158130035
}
130159130036
assert( pParse->nErr>0 || pFK==0 );
130160130037
if( pFK ) break;
130161130038
if( pParse->nTab<i ) pParse->nTab = i;
130162130039
addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, 0); VdbeCoverage(v);
130163
- for(i=1, pFK=pTab->pFKey; pFK; i++, pFK=pFK->pNextFrom){
130040
+ assert( !IsVirtual(pTab) );
130041
+ for(i=1, pFK=pTab->u.tab.pFKey; pFK; i++, pFK=pFK->pNextFrom){
130164130042
pParent = sqlite3FindTable(db, pFK->zTo, zDb);
130165130043
pIdx = 0;
130166130044
aiCols = 0;
130167130045
if( pParent ){
130168130046
x = sqlite3FkLocateIndex(pParse, pParent, pFK, &pIdx, &aiCols);
@@ -130393,11 +130271,11 @@
130393130271
if( sqlite3VdbeGetOp(v,-1)->opcode==OP_Column ){
130394130272
sqlite3VdbeChangeP5(v, OPFLAG_TYPEOFARG);
130395130273
}
130396130274
jmp2 = sqlite3VdbeAddOp1(v, OP_NotNull, 3); VdbeCoverage(v);
130397130275
zErr = sqlite3MPrintf(db, "NULL value in %s.%s", pTab->zName,
130398
- pTab->aCol[j].zName);
130276
+ pTab->aCol[j].zCnName);
130399130277
sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC);
130400130278
integrityCheckResultRow(v);
130401130279
sqlite3VdbeJumpHere(v, jmp2);
130402130280
}
130403130281
/* Verify CHECK constraints */
@@ -132601,11 +132479,11 @@
132601132479
SQLITE_PRIVATE int sqlite3ColumnIndex(Table *pTab, const char *zCol){
132602132480
int i;
132603132481
u8 h = sqlite3StrIHash(zCol);
132604132482
Column *pCol;
132605132483
for(pCol=pTab->aCol, i=0; i<pTab->nCol; pCol++, i++){
132606
- if( pCol->hName==h && sqlite3StrICmp(pCol->zName, zCol)==0 ) return i;
132484
+ if( pCol->hName==h && sqlite3StrICmp(pCol->zCnName, zCol)==0 ) return i;
132607132485
}
132608132486
return -1;
132609132487
}
132610132488
132611132489
/*
@@ -132800,11 +132678,11 @@
132800132678
char *zName; /* Name of column in the right table */
132801132679
int iLeft; /* Matching left table */
132802132680
int iLeftCol; /* Matching column in the left table */
132803132681
132804132682
if( IsHiddenColumn(&pRightTab->aCol[j]) ) continue;
132805
- zName = pRightTab->aCol[j].zName;
132683
+ zName = pRightTab->aCol[j].zCnName;
132806132684
if( tableAndColumnIndex(pSrc, i+1, zName, &iLeft, &iLeftCol, 1) ){
132807132685
addWhereTerm(pParse, pSrc, iLeft, iLeftCol, i+1, j,
132808132686
isOuter, &p->pWhere);
132809132687
}
132810132688
}
@@ -133203,11 +133081,13 @@
133203133081
Parse *pParse, /* Parsing and code generating context */
133204133082
int eTnctType, /* WHERE_DISTINCT_* value */
133205133083
int iVal, /* Value returned by codeDistinct() */
133206133084
int iOpenEphAddr /* Address of OP_OpenEphemeral instruction for iTab */
133207133085
){
133208
- if( eTnctType==WHERE_DISTINCT_UNIQUE || eTnctType==WHERE_DISTINCT_ORDERED ){
133086
+ if( pParse->nErr==0
133087
+ && (eTnctType==WHERE_DISTINCT_UNIQUE || eTnctType==WHERE_DISTINCT_ORDERED)
133088
+ ){
133209133089
Vdbe *v = pParse->pVdbe;
133210133090
sqlite3VdbeChangeToNoop(v, iOpenEphAddr);
133211133091
if( sqlite3VdbeGetOp(v, iOpenEphAddr+1)->opcode==OP_Explain ){
133212133092
sqlite3VdbeChangeToNoop(v, iOpenEphAddr+1);
133213133093
}
@@ -134165,11 +134045,11 @@
134165134045
assert( iCol==XN_ROWID || (iCol>=0 && iCol<pTab->nCol) );
134166134046
if( iCol<0 ){
134167134047
zType = "INTEGER";
134168134048
zOrigCol = "rowid";
134169134049
}else{
134170
- zOrigCol = pTab->aCol[iCol].zName;
134050
+ zOrigCol = pTab->aCol[iCol].zCnName;
134171134051
zType = sqlite3ColumnType(&pTab->aCol[iCol],0);
134172134052
}
134173134053
zOrigTab = pTab->zName;
134174134054
if( pNC->pParse && pTab->pSchema ){
134175134055
int iDb = sqlite3SchemaToIndex(pNC->pParse->db, pTab->pSchema);
@@ -134337,11 +134217,11 @@
134337134217
if( iCol<0 ) iCol = pTab->iPKey;
134338134218
assert( iCol==-1 || (iCol>=0 && iCol<pTab->nCol) );
134339134219
if( iCol<0 ){
134340134220
zCol = "rowid";
134341134221
}else{
134342
- zCol = pTab->aCol[iCol].zName;
134222
+ zCol = pTab->aCol[iCol].zCnName;
134343134223
}
134344134224
if( fullName ){
134345134225
char *zName = 0;
134346134226
zName = sqlite3MPrintf(db, "%s.%s", pTab->zName, zCol);
134347134227
sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, SQLITE_DYNAMIC);
@@ -134422,11 +134302,11 @@
134422134302
}
134423134303
if( pColExpr->op==TK_COLUMN && (pTab = pColExpr->y.pTab)!=0 ){
134424134304
/* For columns use the column name name */
134425134305
int iCol = pColExpr->iColumn;
134426134306
if( iCol<0 ) iCol = pTab->iPKey;
134427
- zName = iCol>=0 ? pTab->aCol[iCol].zName : "rowid";
134307
+ zName = iCol>=0 ? pTab->aCol[iCol].zCnName : "rowid";
134428134308
}else if( pColExpr->op==TK_ID ){
134429134309
assert( !ExprHasProperty(pColExpr, EP_IntValue) );
134430134310
zName = pColExpr->u.zToken;
134431134311
}else{
134432134312
/* Use the original text of the column expression as its name */
@@ -134450,21 +134330,21 @@
134450134330
if( zName[j]==':' ) nName = j;
134451134331
}
134452134332
zName = sqlite3MPrintf(db, "%.*z:%u", nName, zName, ++cnt);
134453134333
if( cnt>3 ) sqlite3_randomness(sizeof(cnt), &cnt);
134454134334
}
134455
- pCol->zName = zName;
134335
+ pCol->zCnName = zName;
134456134336
pCol->hName = sqlite3StrIHash(zName);
134457134337
sqlite3ColumnPropertiesFromName(0, pCol);
134458134338
if( zName && sqlite3HashInsert(&ht, zName, pCol)==pCol ){
134459134339
sqlite3OomFault(db);
134460134340
}
134461134341
}
134462134342
sqlite3HashClear(&ht);
134463134343
if( db->mallocFailed ){
134464134344
for(j=0; j<i; j++){
134465
- sqlite3DbFree(db, aCol[j].zName);
134345
+ sqlite3DbFree(db, aCol[j].zCnName);
134466134346
}
134467134347
sqlite3DbFree(db, aCol);
134468134348
*paCol = 0;
134469134349
*pnCol = 0;
134470134350
return SQLITE_NOMEM_BKPT;
@@ -134512,21 +134392,22 @@
134512134392
zType = columnType(&sNC, p, 0, 0, 0);
134513134393
/* pCol->szEst = ... // Column size est for SELECT tables never used */
134514134394
pCol->affinity = sqlite3ExprAffinity(p);
134515134395
if( zType ){
134516134396
m = sqlite3Strlen30(zType);
134517
- n = sqlite3Strlen30(pCol->zName);
134518
- pCol->zName = sqlite3DbReallocOrFree(db, pCol->zName, n+m+2);
134519
- if( pCol->zName ){
134520
- memcpy(&pCol->zName[n+1], zType, m+1);
134397
+ n = sqlite3Strlen30(pCol->zCnName);
134398
+ pCol->zCnName = sqlite3DbReallocOrFree(db, pCol->zCnName, n+m+2);
134399
+ if( pCol->zCnName ){
134400
+ memcpy(&pCol->zCnName[n+1], zType, m+1);
134521134401
pCol->colFlags |= COLFLAG_HASTYPE;
134522134402
}
134523134403
}
134524134404
if( pCol->affinity<=SQLITE_AFF_NONE ) pCol->affinity = aff;
134525134405
pColl = sqlite3ExprCollSeq(pParse, p);
134526
- if( pColl && pCol->zColl==0 ){
134527
- pCol->zColl = sqlite3DbStrDup(db, pColl->zName);
134406
+ if( pColl && (pCol->colFlags & COLFLAG_HASCOLL)==0 ){
134407
+ assert( pTab->pIndex==0 );
134408
+ sqlite3ColumnSetColl(db, pCol, pColl->zName);
134528134409
}
134529134410
}
134530134411
pTab->szTabRow = 1; /* Any non-zero value works */
134531134412
}
134532134413
@@ -137261,11 +137142,11 @@
137261137142
){
137262137143
return 0;
137263137144
}
137264137145
pTab = p->pSrc->a[0].pTab;
137265137146
pExpr = p->pEList->a[0].pExpr;
137266
- assert( pTab && !pTab->pSelect && pExpr );
137147
+ assert( pTab && !IsView(pTab) && pExpr );
137267137148
137268137149
if( IsVirtual(pTab) ) return 0;
137269137150
if( pExpr->op!=TK_AGG_FUNCTION ) return 0;
137270137151
if( NEVER(pAggInfo->nFunc==0) ) return 0;
137271137152
if( (pAggInfo->aFunc[0].pFunc->funcFlags&SQLITE_FUNC_COUNT)==0 ) return 0;
@@ -137806,34 +137687,35 @@
137806137687
pTab->nTabRef++;
137807137688
if( !IsVirtual(pTab) && cannotBeFunction(pParse, pFrom) ){
137808137689
return WRC_Abort;
137809137690
}
137810137691
#if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_VIRTUALTABLE)
137811
- if( IsVirtual(pTab) || pTab->pSelect ){
137692
+ if( !IsOrdinaryTable(pTab) ){
137812137693
i16 nCol;
137813137694
u8 eCodeOrig = pWalker->eCode;
137814137695
if( sqlite3ViewGetColumnNames(pParse, pTab) ) return WRC_Abort;
137815137696
assert( pFrom->pSelect==0 );
137816
- if( pTab->pSelect
137817
- && (db->flags & SQLITE_EnableView)==0
137818
- && pTab->pSchema!=db->aDb[1].pSchema
137819
- ){
137820
- sqlite3ErrorMsg(pParse, "access to view \"%s\" prohibited",
137821
- pTab->zName);
137822
- }
137697
+ if( IsView(pTab) ){
137698
+ if( (db->flags & SQLITE_EnableView)==0
137699
+ && pTab->pSchema!=db->aDb[1].pSchema
137700
+ ){
137701
+ sqlite3ErrorMsg(pParse, "access to view \"%s\" prohibited",
137702
+ pTab->zName);
137703
+ }
137704
+ pFrom->pSelect = sqlite3SelectDup(db, pTab->u.view.pSelect, 0);
137705
+ }else
137823137706
#ifndef SQLITE_OMIT_VIRTUALTABLE
137824
- assert( SQLITE_VTABRISK_Normal==1 && SQLITE_VTABRISK_High==2 );
137825
- if( IsVirtual(pTab)
137707
+ if( ALWAYS(IsVirtual(pTab))
137826137708
&& pFrom->fg.fromDDL
137827
- && ALWAYS(pTab->pVTable!=0)
137828
- && pTab->pVTable->eVtabRisk > ((db->flags & SQLITE_TrustedSchema)!=0)
137709
+ && ALWAYS(pTab->u.vtab.p!=0)
137710
+ && pTab->u.vtab.p->eVtabRisk > ((db->flags & SQLITE_TrustedSchema)!=0)
137829137711
){
137830137712
sqlite3ErrorMsg(pParse, "unsafe use of virtual table \"%s\"",
137831137713
pTab->zName);
137832137714
}
137715
+ assert( SQLITE_VTABRISK_Normal==1 && SQLITE_VTABRISK_High==2 );
137833137716
#endif
137834
- pFrom->pSelect = sqlite3SelectDup(db, pTab->pSelect, 0);
137835137717
nCol = pTab->nCol;
137836137718
pTab->nCol = -1;
137837137719
pWalker->eCode = 1; /* Turn on Select.selId renumbering */
137838137720
sqlite3WalkSelect(pWalker, pFrom->pSelect);
137839137721
pWalker->eCode = eCodeOrig;
@@ -137929,11 +137811,11 @@
137929137811
}
137930137812
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
137931137813
zSchemaName = iDb>=0 ? db->aDb[iDb].zDbSName : "*";
137932137814
}
137933137815
for(j=0; j<pTab->nCol; j++){
137934
- char *zName = pTab->aCol[j].zName;
137816
+ char *zName = pTab->aCol[j].zCnName;
137935137817
char *zColname; /* The computed column name */
137936137818
char *zToFree; /* Malloced string that needs to be freed */
137937137819
Token sColname; /* Computed column name as a token */
137938137820
137939137821
assert( zName );
@@ -140214,16 +140096,16 @@
140214140096
}
140215140097
140216140098
/* INSTEAD of triggers are only for views and views only support INSTEAD
140217140099
** of triggers.
140218140100
*/
140219
- if( pTab->pSelect && tr_tm!=TK_INSTEAD ){
140101
+ if( IsView(pTab) && tr_tm!=TK_INSTEAD ){
140220140102
sqlite3ErrorMsg(pParse, "cannot create %s trigger on view: %S",
140221140103
(tr_tm == TK_BEFORE)?"BEFORE":"AFTER", pTableName->a);
140222140104
goto trigger_orphan_error;
140223140105
}
140224
- if( !pTab->pSelect && tr_tm==TK_INSTEAD ){
140106
+ if( !IsView(pTab) && tr_tm==TK_INSTEAD ){
140225140107
sqlite3ErrorMsg(pParse, "cannot create INSTEAD OF"
140226140108
" trigger on table: %S", pTableName->a);
140227140109
goto trigger_orphan_error;
140228140110
}
140229140111
@@ -140872,15 +140754,15 @@
140872140754
if( isAsteriskTerm(pParse, pOldExpr) ){
140873140755
int jj;
140874140756
for(jj=0; jj<pTab->nCol; jj++){
140875140757
Expr *pNewExpr;
140876140758
if( IsHiddenColumn(pTab->aCol+jj) ) continue;
140877
- pNewExpr = sqlite3Expr(db, TK_ID, pTab->aCol[jj].zName);
140759
+ pNewExpr = sqlite3Expr(db, TK_ID, pTab->aCol[jj].zCnName);
140878140760
pNew = sqlite3ExprListAppend(pParse, pNew, pNewExpr);
140879140761
if( !db->mallocFailed ){
140880140762
struct ExprList_item *pItem = &pNew->a[pNew->nExpr-1];
140881
- pItem->zEName = sqlite3DbStrDup(db, pTab->aCol[jj].zName);
140763
+ pItem->zEName = sqlite3DbStrDup(db, pTab->aCol[jj].zCnName);
140882140764
pItem->eEName = ENAME_NAME;
140883140765
}
140884140766
}
140885140767
}else{
140886140768
Expr *pNewExpr = sqlite3ExprDup(db, pOldExpr, 0);
@@ -141477,17 +141359,18 @@
141477141359
** integer. In that case, add an OP_RealAffinity opcode to make sure
141478141360
** it has been converted into REAL.
141479141361
*/
141480141362
SQLITE_PRIVATE void sqlite3ColumnDefault(Vdbe *v, Table *pTab, int i, int iReg){
141481141363
assert( pTab!=0 );
141482
- if( !pTab->pSelect ){
141364
+ if( !IsView(pTab) ){
141483141365
sqlite3_value *pValue = 0;
141484141366
u8 enc = ENC(sqlite3VdbeDb(v));
141485141367
Column *pCol = &pTab->aCol[i];
141486
- VdbeComment((v, "%s.%s", pTab->zName, pCol->zName));
141368
+ VdbeComment((v, "%s.%s", pTab->zName, pCol->zCnName));
141487141369
assert( i<pTab->nCol );
141488
- sqlite3ValueFromExpr(sqlite3VdbeDb(v), pCol->pDflt, enc,
141370
+ sqlite3ValueFromExpr(sqlite3VdbeDb(v),
141371
+ sqlite3ColumnExpr(pTab,pCol), enc,
141489141372
pCol->affinity, &pValue);
141490141373
if( pValue ){
141491141374
sqlite3VdbeAppendP4(v, pValue, P4_MEM);
141492141375
}
141493141376
}
@@ -141653,11 +141536,11 @@
141653141536
}
141654141537
#endif
141655141538
pList = sqlite3ExprListAppend(pParse, pList, pNew);
141656141539
}
141657141540
eDest = IsVirtual(pTab) ? SRT_Table : SRT_Upfrom;
141658
- }else if( pTab->pSelect ){
141541
+ }else if( IsView(pTab) ){
141659141542
for(i=0; i<pTab->nCol; i++){
141660141543
pList = sqlite3ExprListAppend(pParse, pList, exprRowColumn(pParse, i));
141661141544
}
141662141545
eDest = SRT_Table;
141663141546
}else{
@@ -141778,11 +141661,11 @@
141778141661
/* Figure out if we have any triggers and if the table being
141779141662
** updated is a view.
141780141663
*/
141781141664
#ifndef SQLITE_OMIT_TRIGGER
141782141665
pTrigger = sqlite3TriggersExist(pParse, pTab, TK_UPDATE, pChanges, &tmask);
141783
- isView = pTab->pSelect!=0;
141666
+ isView = IsView(pTab);
141784141667
assert( pTrigger || tmask==0 );
141785141668
#else
141786141669
# define pTrigger 0
141787141670
# define isView 0
141788141671
# define tmask 0
@@ -141867,17 +141750,20 @@
141867141750
** column to be updated, make sure we have authorization to change
141868141751
** that column.
141869141752
*/
141870141753
chngRowid = chngPk = 0;
141871141754
for(i=0; i<pChanges->nExpr; i++){
141755
+ u8 hCol = sqlite3StrIHash(pChanges->a[i].zEName);
141872141756
/* If this is an UPDATE with a FROM clause, do not resolve expressions
141873141757
** here. The call to sqlite3Select() below will do that. */
141874141758
if( nChangeFrom==0 && sqlite3ResolveExprNames(&sNC, pChanges->a[i].pExpr) ){
141875141759
goto update_cleanup;
141876141760
}
141877141761
for(j=0; j<pTab->nCol; j++){
141878
- if( sqlite3StrICmp(pTab->aCol[j].zName, pChanges->a[i].zEName)==0 ){
141762
+ if( pTab->aCol[j].hName==hCol
141763
+ && sqlite3StrICmp(pTab->aCol[j].zCnName, pChanges->a[i].zEName)==0
141764
+ ){
141879141765
if( j==pTab->iPKey ){
141880141766
chngRowid = 1;
141881141767
pRowidExpr = pChanges->a[i].pExpr;
141882141768
iRowidExpr = i;
141883141769
}else if( pPk && (pTab->aCol[j].colFlags & COLFLAG_PRIMKEY)!=0 ){
@@ -141887,11 +141773,11 @@
141887141773
else if( pTab->aCol[j].colFlags & COLFLAG_GENERATED ){
141888141774
testcase( pTab->aCol[j].colFlags & COLFLAG_VIRTUAL );
141889141775
testcase( pTab->aCol[j].colFlags & COLFLAG_STORED );
141890141776
sqlite3ErrorMsg(pParse,
141891141777
"cannot UPDATE generated column \"%s\"",
141892
- pTab->aCol[j].zName);
141778
+ pTab->aCol[j].zCnName);
141893141779
goto update_cleanup;
141894141780
}
141895141781
#endif
141896141782
aXRef[j] = i;
141897141783
break;
@@ -141911,11 +141797,11 @@
141911141797
}
141912141798
#ifndef SQLITE_OMIT_AUTHORIZATION
141913141799
{
141914141800
int rc;
141915141801
rc = sqlite3AuthCheck(pParse, SQLITE_UPDATE, pTab->zName,
141916
- j<0 ? "ROWID" : pTab->aCol[j].zName,
141802
+ j<0 ? "ROWID" : pTab->aCol[j].zCnName,
141917141803
db->aDb[iDb].zDbSName);
141918141804
if( rc==SQLITE_DENY ){
141919141805
goto update_cleanup;
141920141806
}else if( rc==SQLITE_IGNORE ){
141921141807
aXRef[j] = -1;
@@ -141943,12 +141829,14 @@
141943141829
do{
141944141830
bProgress = 0;
141945141831
for(i=0; i<pTab->nCol; i++){
141946141832
if( aXRef[i]>=0 ) continue;
141947141833
if( (pTab->aCol[i].colFlags & COLFLAG_GENERATED)==0 ) continue;
141948
- if( sqlite3ExprReferencesUpdatedColumn(pTab->aCol[i].pDflt,
141949
- aXRef, chngRowid) ){
141834
+ if( sqlite3ExprReferencesUpdatedColumn(
141835
+ sqlite3ColumnExpr(pTab, &pTab->aCol[i]),
141836
+ aXRef, chngRowid)
141837
+ ){
141950141838
aXRef[i] = 99999;
141951141839
bProgress = 1;
141952141840
}
141953141841
}
141954141842
}while( bProgress );
@@ -143036,11 +142924,11 @@
143036142924
int k;
143037142925
assert( pPk->aiColumn[i]>=0 );
143038142926
k = sqlite3TableColumnToIndex(pIdx, pPk->aiColumn[i]);
143039142927
sqlite3VdbeAddOp3(v, OP_Column, iCur, k, iPk+i);
143040142928
VdbeComment((v, "%s.%s", pIdx->zName,
143041
- pTab->aCol[pPk->aiColumn[i]].zName));
142929
+ pTab->aCol[pPk->aiColumn[i]].zCnName));
143042142930
}
143043142931
sqlite3VdbeVerifyAbortable(v, OE_Abort);
143044142932
i = sqlite3VdbeAddOp4Int(v, OP_Found, iDataCur, 0, iPk, nPk);
143045142933
VdbeCoverage(v);
143046142934
sqlite3VdbeAddOp4(v, OP_Halt, SQLITE_CORRUPT, OE_Abort, 0,
@@ -143666,11 +143554,11 @@
143666143554
** this virtual-table, if one has been created, or NULL otherwise.
143667143555
*/
143668143556
SQLITE_PRIVATE VTable *sqlite3GetVTable(sqlite3 *db, Table *pTab){
143669143557
VTable *pVtab;
143670143558
assert( IsVirtual(pTab) );
143671
- for(pVtab=pTab->pVTable; pVtab && pVtab->db!=db; pVtab=pVtab->pNext);
143559
+ for(pVtab=pTab->u.vtab.p; pVtab && pVtab->db!=db; pVtab=pVtab->pNext);
143672143560
return pVtab;
143673143561
}
143674143562
143675143563
/*
143676143564
** Decrement the ref-count on a virtual table object. When the ref-count
@@ -143694,35 +143582,35 @@
143694143582
}
143695143583
}
143696143584
143697143585
/*
143698143586
** Table p is a virtual table. This function moves all elements in the
143699
-** p->pVTable list to the sqlite3.pDisconnect lists of their associated
143587
+** p->u.vtab.p list to the sqlite3.pDisconnect lists of their associated
143700143588
** database connections to be disconnected at the next opportunity.
143701143589
** Except, if argument db is not NULL, then the entry associated with
143702
-** connection db is left in the p->pVTable list.
143590
+** connection db is left in the p->u.vtab.p list.
143703143591
*/
143704143592
static VTable *vtabDisconnectAll(sqlite3 *db, Table *p){
143705143593
VTable *pRet = 0;
143706
- VTable *pVTable = p->pVTable;
143707
- p->pVTable = 0;
143594
+ VTable *pVTable = p->u.vtab.p;
143595
+ p->u.vtab.p = 0;
143708143596
143709143597
/* Assert that the mutex (if any) associated with the BtShared database
143710143598
** that contains table p is held by the caller. See header comments
143711143599
** above function sqlite3VtabUnlockList() for an explanation of why
143712143600
** this makes it safe to access the sqlite3.pDisconnect list of any
143713
- ** database connection that may have an entry in the p->pVTable list.
143601
+ ** database connection that may have an entry in the p->u.vtab.p list.
143714143602
*/
143715143603
assert( db==0 || sqlite3SchemaMutexHeld(db, 0, p->pSchema) );
143716143604
143717143605
while( pVTable ){
143718143606
sqlite3 *db2 = pVTable->db;
143719143607
VTable *pNext = pVTable->pNext;
143720143608
assert( db2 );
143721143609
if( db2==db ){
143722143610
pRet = pVTable;
143723
- p->pVTable = pRet;
143611
+ p->u.vtab.p = pRet;
143724143612
pRet->pNext = 0;
143725143613
}else{
143726143614
pVTable->pNext = db2->pDisconnect;
143727143615
db2->pDisconnect = pVTable;
143728143616
}
@@ -143746,11 +143634,11 @@
143746143634
143747143635
assert( IsVirtual(p) );
143748143636
assert( sqlite3BtreeHoldsAllMutexes(db) );
143749143637
assert( sqlite3_mutex_held(db->mutex) );
143750143638
143751
- for(ppVTab=&p->pVTable; *ppVTab; ppVTab=&(*ppVTab)->pNext){
143639
+ for(ppVTab=&p->u.vtab.p; *ppVTab; ppVTab=&(*ppVTab)->pNext){
143752143640
if( (*ppVTab)->db==db ){
143753143641
VTable *pVTab = *ppVTab;
143754143642
*ppVTab = pVTab->pNext;
143755143643
sqlite3VtabUnlock(pVTab);
143756143644
break;
@@ -143810,40 +143698,40 @@
143810143698
** in the list are moved to the sqlite3.pDisconnect list of the associated
143811143699
** database connection.
143812143700
*/
143813143701
SQLITE_PRIVATE void sqlite3VtabClear(sqlite3 *db, Table *p){
143814143702
if( !db || db->pnBytesFreed==0 ) vtabDisconnectAll(0, p);
143815
- if( p->azModuleArg ){
143703
+ if( p->u.vtab.azArg ){
143816143704
int i;
143817
- for(i=0; i<p->nModuleArg; i++){
143818
- if( i!=1 ) sqlite3DbFree(db, p->azModuleArg[i]);
143705
+ for(i=0; i<p->u.vtab.nArg; i++){
143706
+ if( i!=1 ) sqlite3DbFree(db, p->u.vtab.azArg[i]);
143819143707
}
143820
- sqlite3DbFree(db, p->azModuleArg);
143708
+ sqlite3DbFree(db, p->u.vtab.azArg);
143821143709
}
143822143710
}
143823143711
143824143712
/*
143825
-** Add a new module argument to pTable->azModuleArg[].
143713
+** Add a new module argument to pTable->u.vtab.azArg[].
143826143714
** The string is not copied - the pointer is stored. The
143827143715
** string will be freed automatically when the table is
143828143716
** deleted.
143829143717
*/
143830143718
static void addModuleArgument(Parse *pParse, Table *pTable, char *zArg){
143831
- sqlite3_int64 nBytes = sizeof(char *)*(2+pTable->nModuleArg);
143719
+ sqlite3_int64 nBytes = sizeof(char *)*(2+pTable->u.vtab.nArg);
143832143720
char **azModuleArg;
143833143721
sqlite3 *db = pParse->db;
143834
- if( pTable->nModuleArg+3>=db->aLimit[SQLITE_LIMIT_COLUMN] ){
143722
+ if( pTable->u.vtab.nArg+3>=db->aLimit[SQLITE_LIMIT_COLUMN] ){
143835143723
sqlite3ErrorMsg(pParse, "too many columns on %s", pTable->zName);
143836143724
}
143837
- azModuleArg = sqlite3DbRealloc(db, pTable->azModuleArg, nBytes);
143725
+ azModuleArg = sqlite3DbRealloc(db, pTable->u.vtab.azArg, nBytes);
143838143726
if( azModuleArg==0 ){
143839143727
sqlite3DbFree(db, zArg);
143840143728
}else{
143841
- int i = pTable->nModuleArg++;
143729
+ int i = pTable->u.vtab.nArg++;
143842143730
azModuleArg[i] = zArg;
143843143731
azModuleArg[i+1] = 0;
143844
- pTable->azModuleArg = azModuleArg;
143732
+ pTable->u.vtab.azArg = azModuleArg;
143845143733
}
143846143734
}
143847143735
143848143736
/*
143849143737
** The parser calls this routine when it first sees a CREATE VIRTUAL TABLE
@@ -143862,14 +143750,15 @@
143862143750
143863143751
sqlite3StartTable(pParse, pName1, pName2, 0, 0, 1, ifNotExists);
143864143752
pTable = pParse->pNewTable;
143865143753
if( pTable==0 ) return;
143866143754
assert( 0==pTable->pIndex );
143755
+ pTable->eTabType = TABTYP_VTAB;
143867143756
143868143757
db = pParse->db;
143869143758
143870
- assert( pTable->nModuleArg==0 );
143759
+ assert( pTable->u.vtab.nArg==0 );
143871143760
addModuleArgument(pParse, pTable, sqlite3NameFromToken(db, pModuleName));
143872143761
addModuleArgument(pParse, pTable, 0);
143873143762
addModuleArgument(pParse, pTable, sqlite3DbStrDup(db, pTable->zName));
143874143763
assert( (pParse->sNameToken.z==pName2->z && pName2->z!=0)
143875143764
|| (pParse->sNameToken.z==pName1->z && pName2->z==0)
@@ -143882,15 +143771,15 @@
143882143771
/* Creating a virtual table invokes the authorization callback twice.
143883143772
** The first invocation, to obtain permission to INSERT a row into the
143884143773
** sqlite_schema table, has already been made by sqlite3StartTable().
143885143774
** The second call, to obtain permission to create the table, is made now.
143886143775
*/
143887
- if( pTable->azModuleArg ){
143776
+ if( pTable->u.vtab.azArg ){
143888143777
int iDb = sqlite3SchemaToIndex(db, pTable->pSchema);
143889143778
assert( iDb>=0 ); /* The database the table is being created in */
143890143779
sqlite3AuthCheck(pParse, SQLITE_CREATE_VTABLE, pTable->zName,
143891
- pTable->azModuleArg[0], pParse->db->aDb[iDb].zDbSName);
143780
+ pTable->u.vtab.azArg[0], pParse->db->aDb[iDb].zDbSName);
143892143781
}
143893143782
#endif
143894143783
}
143895143784
143896143785
/*
@@ -143916,11 +143805,11 @@
143916143805
sqlite3 *db = pParse->db; /* The database connection */
143917143806
143918143807
if( pTab==0 ) return;
143919143808
addArgumentToVtab(pParse);
143920143809
pParse->sArg.z = 0;
143921
- if( pTab->nModuleArg<1 ) return;
143810
+ if( pTab->u.vtab.nArg<1 ) return;
143922143811
143923143812
/* If the CREATE VIRTUAL TABLE statement is being entered for the
143924143813
** first time (in other words if the virtual table is actually being
143925143814
** created now instead of just being read out of sqlite_schema) then
143926143815
** do additional initialization work and store the statement text
@@ -144031,12 +143920,12 @@
144031143920
char **pzErr
144032143921
){
144033143922
VtabCtx sCtx;
144034143923
VTable *pVTable;
144035143924
int rc;
144036
- const char *const*azArg = (const char *const*)pTab->azModuleArg;
144037
- int nArg = pTab->nModuleArg;
143925
+ const char *const*azArg = (const char *const*)pTab->u.vtab.azArg;
143926
+ int nArg = pTab->u.vtab.nArg;
144038143927
char *zErr = 0;
144039143928
char *zModuleName;
144040143929
int iDb;
144041143930
VtabCtx *pCtx;
144042143931
@@ -144064,11 +143953,11 @@
144064143953
pVTable->db = db;
144065143954
pVTable->pMod = pMod;
144066143955
pVTable->eVtabRisk = SQLITE_VTABRISK_Normal;
144067143956
144068143957
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
144069
- pTab->azModuleArg[1] = db->aDb[iDb].zDbSName;
143958
+ pTab->u.vtab.azArg[1] = db->aDb[iDb].zDbSName;
144070143959
144071143960
/* Invoke the virtual table constructor */
144072143961
assert( &db->pVtabCtx );
144073143962
assert( xConstruct );
144074143963
sCtx.pTab = pTab;
@@ -144103,16 +143992,16 @@
144103143992
rc = SQLITE_ERROR;
144104143993
}else{
144105143994
int iCol;
144106143995
u16 oooHidden = 0;
144107143996
/* If everything went according to plan, link the new VTable structure
144108
- ** into the linked list headed by pTab->pVTable. Then loop through the
143997
+ ** into the linked list headed by pTab->u.vtab.p. Then loop through the
144109143998
** columns of the table to see if any of them contain the token "hidden".
144110143999
** If so, set the Column COLFLAG_HIDDEN flag and remove the token from
144111144000
** the type string. */
144112
- pVTable->pNext = pTab->pVTable;
144113
- pTab->pVTable = pVTable;
144001
+ pVTable->pNext = pTab->u.vtab.p;
144002
+ pTab->u.vtab.p = pVTable;
144114144003
144115144004
for(iCol=0; iCol<pTab->nCol; iCol++){
144116144005
char *zType = sqlite3ColumnType(&pTab->aCol[iCol], "");
144117144006
int nType;
144118144007
int i = 0;
@@ -144166,15 +144055,15 @@
144166144055
if( !IsVirtual(pTab) || sqlite3GetVTable(db, pTab) ){
144167144056
return SQLITE_OK;
144168144057
}
144169144058
144170144059
/* Locate the required virtual table module */
144171
- zMod = pTab->azModuleArg[0];
144060
+ zMod = pTab->u.vtab.azArg[0];
144172144061
pMod = (Module*)sqlite3HashFind(&db->aModule, zMod);
144173144062
144174144063
if( !pMod ){
144175
- const char *zModule = pTab->azModuleArg[0];
144064
+ const char *zModule = pTab->u.vtab.azArg[0];
144176144065
sqlite3ErrorMsg(pParse, "no such module: %s", zModule);
144177144066
rc = SQLITE_ERROR;
144178144067
}else{
144179144068
char *zErr = 0;
144180144069
rc = vtabCallConstructor(db, pTab, pMod, pMod->pModule->xConnect, &zErr);
@@ -144233,14 +144122,14 @@
144233144122
Table *pTab;
144234144123
Module *pMod;
144235144124
const char *zMod;
144236144125
144237144126
pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zDbSName);
144238
- assert( pTab && IsVirtual(pTab) && !pTab->pVTable );
144127
+ assert( pTab && IsVirtual(pTab) && !pTab->u.vtab.p );
144239144128
144240144129
/* Locate the required virtual table module */
144241
- zMod = pTab->azModuleArg[0];
144130
+ zMod = pTab->u.vtab.azArg[0];
144242144131
pMod = (Module*)sqlite3HashFind(&db->aModule, zMod);
144243144132
144244144133
/* If the module has been registered and includes a Create method,
144245144134
** invoke it now. If the module has not been registered, return an
144246144135
** error. Otherwise, do nothing.
@@ -144296,17 +144185,17 @@
144296144185
sParse.db = db;
144297144186
sParse.nQueryLoop = 1;
144298144187
if( SQLITE_OK==sqlite3RunParser(&sParse, zCreateTable, &zErr)
144299144188
&& sParse.pNewTable
144300144189
&& !db->mallocFailed
144301
- && !sParse.pNewTable->pSelect
144302
- && !IsVirtual(sParse.pNewTable)
144190
+ && IsOrdinaryTable(sParse.pNewTable)
144303144191
){
144304144192
if( !pTab->aCol ){
144305144193
Table *pNew = sParse.pNewTable;
144306144194
Index *pIdx;
144307144195
pTab->aCol = pNew->aCol;
144196
+ sqlite3ExprListDelete(db, pNew->u.tab.pDfltList);
144308144197
pTab->nNVCol = pTab->nCol = pNew->nCol;
144309144198
pTab->tabFlags |= pNew->tabFlags & (TF_WithoutRowid|TF_NoVisibleRowid);
144310144199
pNew->nCol = 0;
144311144200
pNew->aCol = 0;
144312144201
assert( pTab->pIndex==0 );
@@ -144357,14 +144246,14 @@
144357144246
SQLITE_PRIVATE int sqlite3VtabCallDestroy(sqlite3 *db, int iDb, const char *zTab){
144358144247
int rc = SQLITE_OK;
144359144248
Table *pTab;
144360144249
144361144250
pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zDbSName);
144362
- if( pTab!=0 && ALWAYS(pTab->pVTable!=0) ){
144251
+ if( pTab!=0 && ALWAYS(pTab->u.vtab.p!=0) ){
144363144252
VTable *p;
144364144253
int (*xDestroy)(sqlite3_vtab *);
144365
- for(p=pTab->pVTable; p; p=p->pNext){
144254
+ for(p=pTab->u.vtab.p; p; p=p->pNext){
144366144255
assert( p->pVtab );
144367144256
if( p->pVtab->nRef>0 ){
144368144257
return SQLITE_LOCKED;
144369144258
}
144370144259
}
@@ -144374,13 +144263,13 @@
144374144263
assert( xDestroy!=0 );
144375144264
pTab->nTabRef++;
144376144265
rc = xDestroy(p->pVtab);
144377144266
/* Remove the sqlite3_vtab* from the aVTrans[] array, if applicable */
144378144267
if( rc==SQLITE_OK ){
144379
- assert( pTab->pVTable==p && p->pNext==0 );
144268
+ assert( pTab->u.vtab.p==p && p->pNext==0 );
144380144269
p->pVtab = 0;
144381
- pTab->pVTable = 0;
144270
+ pTab->u.vtab.p = 0;
144382144271
sqlite3VtabUnlock(p);
144383144272
}
144384144273
sqlite3DeleteTable(db, pTab);
144385144274
}
144386144275
@@ -144693,12 +144582,13 @@
144693144582
sqlite3DbFree(db, pTab);
144694144583
return 0;
144695144584
}
144696144585
pMod->pEpoTab = pTab;
144697144586
pTab->nTabRef = 1;
144587
+ pTab->eTabType = TABTYP_VTAB;
144698144588
pTab->pSchema = db->aDb[0].pSchema;
144699
- assert( pTab->nModuleArg==0 );
144589
+ assert( pTab->u.vtab.nArg==0 );
144700144590
pTab->iPKey = -1;
144701144591
pTab->tabFlags |= TF_Eponymous;
144702144592
addModuleArgument(pParse, pTab, sqlite3DbStrDup(db, pTab->zName));
144703144593
addModuleArgument(pParse, pTab, 0);
144704144594
addModuleArgument(pParse, pTab, sqlite3DbStrDup(db, pTab->zName));
@@ -145438,11 +145328,11 @@
145438145328
*/
145439145329
static const char *explainIndexColumnName(Index *pIdx, int i){
145440145330
i = pIdx->aiColumn[i];
145441145331
if( i==XN_EXPR ) return "<expr>";
145442145332
if( i==XN_ROWID ) return "rowid";
145443
- return pIdx->pTable->aCol[i].zName;
145333
+ return pIdx->pTable->aCol[i].zCnName;
145444145334
}
145445145335
145446145336
/*
145447145337
** This routine is a helper for explainIndexRange() below
145448145338
**
@@ -146650,12 +146540,13 @@
146650146540
if( sqlite3ExprIsConstant(x.pIdxExpr) ) continue;
146651146541
w.xExprCallback = whereIndexExprTransNode;
146652146542
#ifndef SQLITE_OMIT_GENERATED_COLUMNS
146653146543
}else if( iRef>=0
146654146544
&& (pTab->aCol[iRef].colFlags & COLFLAG_VIRTUAL)!=0
146655
- && (pTab->aCol[iRef].zColl==0
146656
- || sqlite3StrICmp(pTab->aCol[iRef].zColl, sqlite3StrBINARY)==0)
146545
+ && ((pTab->aCol[iRef].colFlags & COLFLAG_HASCOLL)==0
146546
+ || sqlite3StrICmp(sqlite3ColumnColl(&pTab->aCol[iRef]),
146547
+ sqlite3StrBINARY)==0)
146657146548
){
146658146549
/* Check to see if there are direct references to generated columns
146659146550
** that are contained in the index. Pulling the generated column
146660146551
** out of the index is an optimization only - the main table is always
146661146552
** available if the index cannot be used. To avoid unnecessary
@@ -149070,11 +148961,15 @@
149070148961
pNew->u.x.leftColumn = aiCurCol[1];
149071148962
testcase( (prereqLeft | extraRight) != prereqLeft );
149072148963
pNew->prereqRight = prereqLeft | extraRight;
149073148964
pNew->prereqAll = prereqAll;
149074148965
pNew->eOperator = (operatorMask(pDup->op) + eExtraOp) & opMask;
149075
- }else if( op==TK_ISNULL && 0==sqlite3ExprCanBeNull(pLeft) ){
148966
+ }else
148967
+ if( op==TK_ISNULL
148968
+ && !ExprHasProperty(pExpr,EP_FromJoin)
148969
+ && 0==sqlite3ExprCanBeNull(pLeft)
148970
+ ){
149076148971
pExpr->op = TK_TRUEFALSE;
149077148972
pExpr->u.zToken = "false";
149078148973
ExprSetProperty(pExpr, EP_IsFalse);
149079148974
pTerm->prereqAll = 0;
149080148975
pTerm->eOperator = 0;
@@ -150357,11 +150252,11 @@
150357150252
testcase( iCol==BMS );
150358150253
testcase( iCol==BMS-1 );
150359150254
if( !sentWarning ){
150360150255
sqlite3_log(SQLITE_WARNING_AUTOINDEX,
150361150256
"automatic index on %s(%s)", pTable->zName,
150362
- pTable->aCol[iCol].zName);
150257
+ pTable->aCol[iCol].zCnName);
150363150258
sentWarning = 1;
150364150259
}
150365150260
if( (idxCols & cMask)==0 ){
150366150261
if( whereLoopResize(pParse->db, pLoop, nKeyCol+1) ){
150367150262
goto end_auto_index_create;
@@ -152536,11 +152431,10 @@
152536152431
WhereLoop *pNew; /* Template WhereLoop object */
152537152432
int rc = SQLITE_OK; /* Return code */
152538152433
int iSortIdx = 1; /* Index number */
152539152434
int b; /* A boolean value */
152540152435
LogEst rSize; /* number of rows in the table */
152541
- LogEst rLogSize; /* Logarithm of the number of rows in the table */
152542152436
WhereClause *pWC; /* The parsed WHERE clause */
152543152437
Table *pTab; /* Table being queried */
152544152438
152545152439
pNew = pBuilder->pNew;
152546152440
pWInfo = pBuilder->pWInfo;
@@ -152579,11 +152473,10 @@
152579152473
sPk.pNext = pFirst;
152580152474
}
152581152475
pProbe = &sPk;
152582152476
}
152583152477
rSize = pTab->nRowLogEst;
152584
- rLogSize = estLog(rSize);
152585152478
152586152479
#ifndef SQLITE_OMIT_AUTOMATIC_INDEX
152587152480
/* Automatic indexes */
152588152481
if( !pBuilder->pOrSet /* Not part of an OR optimization */
152589152482
&& (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)==0
@@ -152593,12 +152486,14 @@
152593152486
&& HasRowid(pTab) /* Not WITHOUT ROWID table. (FIXME: Why not?) */
152594152487
&& !pSrc->fg.isCorrelated /* Not a correlated subquery */
152595152488
&& !pSrc->fg.isRecursive /* Not a recursive common table expression. */
152596152489
){
152597152490
/* Generate auto-index WhereLoops */
152491
+ LogEst rLogSize; /* Logarithm of the number of rows in the table */
152598152492
WhereTerm *pTerm;
152599152493
WhereTerm *pWCEnd = pWC->a + pWC->nTerm;
152494
+ rLogSize = estLog(rSize);
152600152495
for(pTerm=pWC->a; rc==SQLITE_OK && pTerm<pWCEnd; pTerm++){
152601152496
if( pTerm->prereqRight & pNew->maskSelf ) continue;
152602152497
if( termCanDriveIndex(pTerm, pSrc, 0) ){
152603152498
pNew->u.btree.nEq = 1;
152604152499
pNew->nSkip = 0;
@@ -152612,11 +152507,11 @@
152612152507
** of X is smaller for views and subqueries so that the query planner
152613152508
** will be more aggressive about generating automatic indexes for
152614152509
** those objects, since there is no opportunity to add schema
152615152510
** indexes on subqueries and views. */
152616152511
pNew->rSetup = rLogSize + rSize;
152617
- if( pTab->pSelect==0 && (pTab->tabFlags & TF_Ephemeral)==0 ){
152512
+ if( !IsView(pTab) && (pTab->tabFlags & TF_Ephemeral)==0 ){
152618152513
pNew->rSetup += 28;
152619152514
}else{
152620152515
pNew->rSetup -= 10;
152621152516
}
152622152517
ApplyCostMultiplier(pNew->rSetup, pTab->costMult);
@@ -154763,11 +154658,11 @@
154763154658
154764154659
pTabItem = &pTabList->a[pLevel->iFrom];
154765154660
pTab = pTabItem->pTab;
154766154661
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
154767154662
pLoop = pLevel->pWLoop;
154768
- if( (pTab->tabFlags & TF_Ephemeral)!=0 || pTab->pSelect ){
154663
+ if( (pTab->tabFlags & TF_Ephemeral)!=0 || IsView(pTab) ){
154769154664
/* Do nothing */
154770154665
}else
154771154666
#ifndef SQLITE_OMIT_VIRTUALTABLE
154772154667
if( (pLoop->wsFlags & WHERE_VIRTUALTABLE)!=0 ){
154773154668
const char *pVTab = (const char *)sqlite3GetVTable(db, pTab);
@@ -155132,11 +155027,11 @@
155132155027
** Except, do not close cursors that will be reused by the OR optimization
155133155028
** (WHERE_OR_SUBCLAUSE). And do not close the OP_OpenWrite cursors
155134155029
** created for the ONEPASS optimization.
155135155030
*/
155136155031
if( (pTab->tabFlags & TF_Ephemeral)==0
155137
- && pTab->pSelect==0
155032
+ && !IsView(pTab)
155138155033
&& (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)==0
155139155034
){
155140155035
int ws = pLoop->wsFlags;
155141155036
if( pWInfo->eOnePass==ONEPASS_OFF && (ws & WHERE_IDX_ONLY)==0 ){
155142155037
sqlite3VdbeAddOp1(v, OP_Close, pTabItem->iCursor);
@@ -161958,11 +161853,11 @@
161958161853
sqlite3ErrorMsg(pParse, "unknown table option: %.*s", yymsp[0].minor.yy0.n, yymsp[0].minor.yy0.z);
161959161854
}
161960161855
}
161961161856
break;
161962161857
case 23: /* columnname ::= nm typetoken */
161963
-{sqlite3AddColumn(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0);}
161858
+{sqlite3AddColumn(pParse,yymsp[-1].minor.yy0,yymsp[0].minor.yy0);}
161964161859
break;
161965161860
case 24: /* typetoken ::= */
161966161861
case 63: /* conslist_opt ::= */ yytestcase(yyruleno==63);
161967161862
case 102: /* as ::= */ yytestcase(yyruleno==102);
161968161863
{yymsp[1].minor.yy0.n = 0; yymsp[1].minor.yy0.z = 0;}
@@ -169147,11 +169042,11 @@
169147169042
goto error_out;
169148169043
}
169149169044
169150169045
/* Locate the table in question */
169151169046
pTab = sqlite3FindTable(db, zTableName, zDbName);
169152
- if( !pTab || pTab->pSelect ){
169047
+ if( !pTab || IsView(pTab) ){
169153169048
pTab = 0;
169154169049
goto error_out;
169155169050
}
169156169051
169157169052
/* Find the column for which info is requested */
@@ -169158,11 +169053,11 @@
169158169053
if( zColumnName==0 ){
169159169054
/* Query for existance of table only */
169160169055
}else{
169161169056
for(iCol=0; iCol<pTab->nCol; iCol++){
169162169057
pCol = &pTab->aCol[iCol];
169163
- if( 0==sqlite3StrICmp(pCol->zName, zColumnName) ){
169058
+ if( 0==sqlite3StrICmp(pCol->zCnName, zColumnName) ){
169164169059
break;
169165169060
}
169166169061
}
169167169062
if( iCol==pTab->nCol ){
169168169063
if( HasRowid(pTab) && sqlite3IsRowid(zColumnName) ){
@@ -169185,11 +169080,11 @@
169185169080
** 2. The table is not a view and the column name identified an
169186169081
** explicitly declared column. Copy meta information from *pCol.
169187169082
*/
169188169083
if( pCol ){
169189169084
zDataType = sqlite3ColumnType(pCol,0);
169190
- zCollSeq = pCol->zColl;
169085
+ zCollSeq = sqlite3ColumnColl(pCol);
169191169086
notnull = pCol->notNull!=0;
169192169087
primarykey = (pCol->colFlags & COLFLAG_PRIMKEY)!=0;
169193169088
autoinc = pTab->iPKey==iCol && (pTab->tabFlags & TF_Autoincrement)!=0;
169194169089
}else{
169195169090
zDataType = "INTEGER";
@@ -201618,11 +201513,13 @@
201618201513
*piPk = 0;
201619201514
201620201515
assert( p->rc==SQLITE_OK );
201621201516
p->rc = prepareFreeAndCollectError(p->dbMain, &aStmt[0], &p->zErrmsg,
201622201517
sqlite3_mprintf(
201623
- "SELECT (sql LIKE 'create virtual%%'), rootpage"
201518
+ "SELECT "
201519
+ " (sql COLLATE nocase BETWEEN 'CREATE VIRTUAL' AND 'CREATE VIRTUAM'),"
201520
+ " rootpage"
201624201521
" FROM sqlite_schema"
201625201522
" WHERE name=%Q", zTab
201626201523
));
201627201524
if( p->rc!=SQLITE_OK || sqlite3_step(aStmt[0])!=SQLITE_ROW ){
201628201525
/* Either an error, or no such table. */
@@ -203151,11 +203048,11 @@
203151203048
case RBU_STATE_COOKIE:
203152203049
pRet->iCookie = (u32)sqlite3_column_int64(pStmt, 1);
203153203050
break;
203154203051
203155203052
case RBU_STATE_OALSZ:
203156
- pRet->iOalSz = (u32)sqlite3_column_int64(pStmt, 1);
203053
+ pRet->iOalSz = sqlite3_column_int64(pStmt, 1);
203157203054
break;
203158203055
203159203056
case RBU_STATE_PHASEONESTEP:
203160203057
pRet->nPhaseOneStep = sqlite3_column_int64(pStmt, 1);
203161203058
break;
@@ -230952,11 +230849,11 @@
230952230849
int nArg, /* Number of args */
230953230850
sqlite3_value **apUnused /* Function arguments */
230954230851
){
230955230852
assert( nArg==0 );
230956230853
UNUSED_PARAM2(nArg, apUnused);
230957
- sqlite3_result_text(pCtx, "fts5: 2021-07-20 14:57:49 1e35cc6d5c2f563c6bb163bb150d7bc6ede4c993efa828af1face3261bf65a2c", -1, SQLITE_TRANSIENT);
230854
+ sqlite3_result_text(pCtx, "fts5: 2021-08-06 20:17:39 087b8b41c6ed76b55c11315e7e95679d67590be20ae21108b593d00bb7d1c57a", -1, SQLITE_TRANSIENT);
230958230855
}
230959230856
230960230857
/*
230961230858
** Return true if zName is the extension on one of the shadow tables used
230962230859
** by this module.
230963230860
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -452,11 +452,11 @@
452 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453 ** [sqlite_version()] and [sqlite_source_id()].
454 */
455 #define SQLITE_VERSION "3.37.0"
456 #define SQLITE_VERSION_NUMBER 3037000
457 #define SQLITE_SOURCE_ID "2021-07-21 15:42:05 60695359dc5d3bcba68a68e1842c40f4a01650eb5af408e02fb856fd8245e16d"
458
459 /*
460 ** CAPI3REF: Run-Time Library Version Numbers
461 ** KEYWORDS: sqlite3_version sqlite3_sourceid
462 **
@@ -13872,10 +13872,11 @@
13872 #ifndef SQLITE_PTRSIZE
13873 # if defined(__SIZEOF_POINTER__)
13874 # define SQLITE_PTRSIZE __SIZEOF_POINTER__
13875 # elif defined(i386) || defined(__i386__) || defined(_M_IX86) || \
13876 defined(_M_ARM) || defined(__arm__) || defined(__x86) || \
 
13877 (defined(__TOS_AIX__) && !defined(__64BIT__))
13878 # define SQLITE_PTRSIZE 4
13879 # else
13880 # define SQLITE_PTRSIZE 8
13881 # endif
@@ -16881,22 +16882,45 @@
16881 ** record BLOB generated by the OP_MakeRecord
16882 ** opcode. The storage column index is less than
16883 ** or equal to the table column index. It is
16884 ** equal if and only if there are no VIRTUAL
16885 ** columns to the left.
 
 
 
 
 
 
 
 
16886 */
16887 struct Column {
16888 char *zName; /* Name of this column, \000, then the type */
16889 Expr *pDflt; /* Default value or GENERATED ALWAYS AS value */
16890 char *zColl; /* Collating sequence. If NULL, use the default */
16891 u8 notNull; /* An OE_ code for handling a NOT NULL constraint */
16892 char affinity; /* One of the SQLITE_AFF_... values */
16893 u8 szEst; /* Estimated size of value in this column. sizeof(INT)==1 */
16894 u8 hName; /* Column name hash for faster lookup */
16895 u16 colFlags; /* Boolean properties. See COLFLAG_ defines below */
16896 };
16897
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16898 /* Allowed values for Column.colFlags.
16899 **
16900 ** Constraints:
16901 ** TF_HasVirtual == COLFLAG_VIRTUAL
16902 ** TF_HasStored == COLFLAG_STORED
@@ -16909,10 +16933,11 @@
16909 #define COLFLAG_SORTERREF 0x0010 /* Use sorter-refs with this column */
16910 #define COLFLAG_VIRTUAL 0x0020 /* GENERATED ALWAYS AS ... VIRTUAL */
16911 #define COLFLAG_STORED 0x0040 /* GENERATED ALWAYS AS ... STORED */
16912 #define COLFLAG_NOTAVAIL 0x0080 /* STORED column not yet calculated */
16913 #define COLFLAG_BUSY 0x0100 /* Blocks recursion on GENERATED columns */
 
16914 #define COLFLAG_GENERATED 0x0060 /* Combo: _STORED, _VIRTUAL */
16915 #define COLFLAG_NOINSERT 0x0062 /* Combo: _HIDDEN, _STORED, _VIRTUAL */
16916
16917 /*
16918 ** A "Collating Sequence" is defined by an instance of the following
@@ -17038,19 +17063,17 @@
17038 #define SQLITE_VTABRISK_Low 0
17039 #define SQLITE_VTABRISK_Normal 1
17040 #define SQLITE_VTABRISK_High 2
17041
17042 /*
17043 ** The schema for each SQL table and view is represented in memory
17044 ** by an instance of the following structure.
17045 */
17046 struct Table {
17047 char *zName; /* Name of the table or view */
17048 Column *aCol; /* Information about each column */
17049 Index *pIndex; /* List of SQL indexes on this table. */
17050 Select *pSelect; /* NULL for tables. Points to definition if a view. */
17051 FKey *pFKey; /* Linked list of all foreign keys in this table */
17052 char *zColAff; /* String defining the affinity of each column */
17053 ExprList *pCheck; /* All CHECK constraints */
17054 /* ... also used as column name list in a VIEW */
17055 Pgno tnum; /* Root BTree page for this table */
17056 u32 nTabRef; /* Number of pointers to this Table */
@@ -17062,19 +17085,28 @@
17062 LogEst szTabRow; /* Estimated size of each table row in bytes */
17063 #ifdef SQLITE_ENABLE_COSTMULT
17064 LogEst costMult; /* Cost multiplier for using this table */
17065 #endif
17066 u8 keyConf; /* What to do in case of uniqueness conflict on iPKey */
17067 #ifndef SQLITE_OMIT_ALTERTABLE
17068 int addColOffset; /* Offset in CREATE TABLE stmt to add a new column */
17069 #endif
17070 #ifndef SQLITE_OMIT_VIRTUALTABLE
17071 int nModuleArg; /* Number of arguments to the module */
17072 char **azModuleArg; /* 0: module 1: schema 2: vtab name 3...: args */
17073 VTable *pVTable; /* List of VTable objects. */
17074 #endif
17075 Trigger *pTrigger; /* List of triggers stored in pSchema */
 
 
 
 
 
 
 
 
 
17076 Schema *pSchema; /* Schema that contains this table */
17077 };
17078
17079 /*
17080 ** Allowed values for Table.tabFlags.
@@ -17089,38 +17121,48 @@
17089 **
17090 ** TF_HasVirtual == COLFLAG_VIRTUAL
17091 ** TF_HasStored == COLFLAG_STORED
17092 ** TF_HasHidden == COLFLAG_HIDDEN
17093 */
17094 #define TF_Readonly 0x0001 /* Read-only system table */
17095 #define TF_HasHidden 0x0002 /* Has one or more hidden columns */
17096 #define TF_HasPrimaryKey 0x0004 /* Table has a primary key */
17097 #define TF_Autoincrement 0x0008 /* Integer primary key is autoincrement */
17098 #define TF_HasStat1 0x0010 /* nRowLogEst set from sqlite_stat1 */
17099 #define TF_HasVirtual 0x0020 /* Has one or more VIRTUAL columns */
17100 #define TF_HasStored 0x0040 /* Has one or more STORED columns */
17101 #define TF_HasGenerated 0x0060 /* Combo: HasVirtual + HasStored */
17102 #define TF_WithoutRowid 0x0080 /* No rowid. PRIMARY KEY is the key */
17103 #define TF_StatsUsed 0x0100 /* Query planner decisions affected by
17104 ** Index.aiRowLogEst[] values */
17105 #define TF_NoVisibleRowid 0x0200 /* No user-visible "rowid" column */
17106 #define TF_OOOHidden 0x0400 /* Out-of-Order hidden columns */
17107 #define TF_HasNotNull 0x0800 /* Contains NOT NULL constraints */
17108 #define TF_Shadow 0x1000 /* True for a shadow table */
17109 #define TF_HasStat4 0x2000 /* STAT4 info available for this table */
17110 #define TF_Ephemeral 0x4000 /* An ephemeral table */
17111 #define TF_Eponymous 0x8000 /* An eponymous virtual table */
 
 
 
 
 
 
 
 
 
 
17112
17113 /*
17114 ** Test to see whether or not a table is a virtual table. This is
17115 ** done as a macro so that it will be optimized out when virtual
17116 ** table support is omitted from the build.
17117 */
17118 #ifndef SQLITE_OMIT_VIRTUALTABLE
17119 # define IsVirtual(X) ((X)->nModuleArg)
17120 # define ExprIsVtab(X) \
17121 ((X)->op==TK_COLUMN && (X)->y.pTab!=0 && (X)->y.pTab->nModuleArg)
17122 #else
17123 # define IsVirtual(X) 0
17124 # define ExprIsVtab(X) 0
17125 #endif
17126
@@ -19170,10 +19212,11 @@
19170 SQLITE_PRIVATE void sqlite3SetString(char **, sqlite3*, const char*);
19171 SQLITE_PRIVATE void sqlite3ErrorMsg(Parse*, const char*, ...);
19172 SQLITE_PRIVATE int sqlite3ErrorToParser(sqlite3*,int);
19173 SQLITE_PRIVATE void sqlite3Dequote(char*);
19174 SQLITE_PRIVATE void sqlite3DequoteExpr(Expr*);
 
19175 SQLITE_PRIVATE void sqlite3TokenInit(Token*,char*);
19176 SQLITE_PRIVATE int sqlite3KeywordCode(const unsigned char*, int);
19177 SQLITE_PRIVATE int sqlite3RunParser(Parse*, const char*, char **);
19178 SQLITE_PRIVATE void sqlite3FinishCoding(Parse*);
19179 SQLITE_PRIVATE int sqlite3GetTempReg(Parse*);
@@ -19215,10 +19258,14 @@
19215 #endif
19216 SQLITE_PRIVATE void sqlite3ResetAllSchemasOfConnection(sqlite3*);
19217 SQLITE_PRIVATE void sqlite3ResetOneSchema(sqlite3*,int);
19218 SQLITE_PRIVATE void sqlite3CollapseDatabaseArray(sqlite3*);
19219 SQLITE_PRIVATE void sqlite3CommitInternalChanges(sqlite3*);
 
 
 
 
19220 SQLITE_PRIVATE void sqlite3DeleteColumnNames(sqlite3*,Table*);
19221 SQLITE_PRIVATE void sqlite3GenerateColumnNames(Parse *pParse, Select *pSelect);
19222 SQLITE_PRIVATE int sqlite3ColumnsFromExprList(Parse*,ExprList*,i16*,Column**);
19223 SQLITE_PRIVATE void sqlite3SelectAddColumnTypeAndCollation(Parse*,Table*,Select*,char);
19224 SQLITE_PRIVATE Table *sqlite3ResultSetOfSelect(Parse*,Select*,char);
@@ -19236,11 +19283,11 @@
19236 #if SQLITE_ENABLE_HIDDEN_COLUMNS
19237 SQLITE_PRIVATE void sqlite3ColumnPropertiesFromName(Table*, Column*);
19238 #else
19239 # define sqlite3ColumnPropertiesFromName(T,C) /* no-op */
19240 #endif
19241 SQLITE_PRIVATE void sqlite3AddColumn(Parse*,Token*,Token*);
19242 SQLITE_PRIVATE void sqlite3AddNotNull(Parse*, int);
19243 SQLITE_PRIVATE void sqlite3AddPrimaryKey(Parse*, ExprList*, int, int, int);
19244 SQLITE_PRIVATE void sqlite3AddCheckConstraint(Parse*, Expr*, const char*, const char*);
19245 SQLITE_PRIVATE void sqlite3AddDefaultValue(Parse*,Expr*,const char*,const char*);
19246 SQLITE_PRIVATE void sqlite3AddCollateType(Parse*, Token*);
@@ -19353,11 +19400,11 @@
19353 SQLITE_PRIVATE int sqlite3ExprCodeGetColumn(Parse*, Table*, int, int, int, u8);
19354 SQLITE_PRIVATE void sqlite3ExprCodeGetColumnOfTable(Vdbe*, Table*, int, int, int);
19355 SQLITE_PRIVATE void sqlite3ExprCodeMove(Parse*, int, int, int);
19356 SQLITE_PRIVATE void sqlite3ExprCode(Parse*, Expr*, int);
19357 #ifndef SQLITE_OMIT_GENERATED_COLUMNS
19358 SQLITE_PRIVATE void sqlite3ExprCodeGeneratedColumn(Parse*, Column*, int);
19359 #endif
19360 SQLITE_PRIVATE void sqlite3ExprCodeCopy(Parse*, Expr*, int);
19361 SQLITE_PRIVATE void sqlite3ExprCodeFactorable(Parse*, Expr*, int);
19362 SQLITE_PRIVATE int sqlite3ExprCodeRunJustOnce(Parse*, Expr*, int);
19363 SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse*, Expr*, int*);
@@ -19646,10 +19693,13 @@
19646 SQLITE_PRIVATE int sqlite3ValueFromExpr(sqlite3 *, Expr *, u8, u8, sqlite3_value **);
19647 SQLITE_PRIVATE void sqlite3ValueApplyAffinity(sqlite3_value *, u8, u8);
19648 #ifndef SQLITE_AMALGAMATION
19649 SQLITE_PRIVATE const unsigned char sqlite3OpcodeProperty[];
19650 SQLITE_PRIVATE const char sqlite3StrBINARY[];
 
 
 
19651 SQLITE_PRIVATE const unsigned char sqlite3UpperToLower[];
19652 SQLITE_PRIVATE const unsigned char *sqlite3aLTb;
19653 SQLITE_PRIVATE const unsigned char *sqlite3aEQb;
19654 SQLITE_PRIVATE const unsigned char *sqlite3aGTb;
19655 SQLITE_PRIVATE const unsigned char sqlite3CtypeMap[];
@@ -20076,10 +20126,207 @@
20076 #endif
20077
20078 #endif /* SQLITEINT_H */
20079
20080 /************** End of sqliteInt.h *******************************************/
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20081 /************** Begin file ctime.c *******************************************/
20082 /*
20083 ** 2010 February 23
20084 **
20085 ** The author disclaims copyright to this source code. In place of
@@ -21213,10 +21460,30 @@
21213
21214 /*
21215 ** Name of the default collating sequence
21216 */
21217 SQLITE_PRIVATE const char sqlite3StrBINARY[] = "BINARY";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21218
21219 /************** End of global.c **********************************************/
21220 /************** Begin file status.c ******************************************/
21221 /*
21222 ** 2008 June 18
@@ -27183,209 +27450,11 @@
27183
27184 #if SQLITE_OS_WIN
27185 /*
27186 ** Include code that is common to all os_*.c files
27187 */
27188 /************** Include os_common.h in the middle of mutex_w32.c *************/
27189 /************** Begin file os_common.h ***************************************/
27190 /*
27191 ** 2004 May 22
27192 **
27193 ** The author disclaims copyright to this source code. In place of
27194 ** a legal notice, here is a blessing:
27195 **
27196 ** May you do good and not evil.
27197 ** May you find forgiveness for yourself and forgive others.
27198 ** May you share freely, never taking more than you give.
27199 **
27200 ******************************************************************************
27201 **
27202 ** This file contains macros and a little bit of code that is common to
27203 ** all of the platform-specific files (os_*.c) and is #included into those
27204 ** files.
27205 **
27206 ** This file should be #included by the os_*.c files only. It is not a
27207 ** general purpose header file.
27208 */
27209 #ifndef _OS_COMMON_H_
27210 #define _OS_COMMON_H_
27211
27212 /*
27213 ** At least two bugs have slipped in because we changed the MEMORY_DEBUG
27214 ** macro to SQLITE_DEBUG and some older makefiles have not yet made the
27215 ** switch. The following code should catch this problem at compile-time.
27216 */
27217 #ifdef MEMORY_DEBUG
27218 # error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead."
27219 #endif
27220
27221 /*
27222 ** Macros for performance tracing. Normally turned off. Only works
27223 ** on i486 hardware.
27224 */
27225 #ifdef SQLITE_PERFORMANCE_TRACE
27226
27227 /*
27228 ** hwtime.h contains inline assembler code for implementing
27229 ** high-performance timing routines.
27230 */
27231 /************** Include hwtime.h in the middle of os_common.h ****************/
27232 /************** Begin file hwtime.h ******************************************/
27233 /*
27234 ** 2008 May 27
27235 **
27236 ** The author disclaims copyright to this source code. In place of
27237 ** a legal notice, here is a blessing:
27238 **
27239 ** May you do good and not evil.
27240 ** May you find forgiveness for yourself and forgive others.
27241 ** May you share freely, never taking more than you give.
27242 **
27243 ******************************************************************************
27244 **
27245 ** This file contains inline asm code for retrieving "high-performance"
27246 ** counters for x86 and x86_64 class CPUs.
27247 */
27248 #ifndef SQLITE_HWTIME_H
27249 #define SQLITE_HWTIME_H
27250
27251 /*
27252 ** The following routine only works on pentium-class (or newer) processors.
27253 ** It uses the RDTSC opcode to read the cycle count value out of the
27254 ** processor and returns that value. This can be used for high-res
27255 ** profiling.
27256 */
27257 #if !defined(__STRICT_ANSI__) && \
27258 (defined(__GNUC__) || defined(_MSC_VER)) && \
27259 (defined(i386) || defined(__i386__) || defined(_M_IX86))
27260
27261 #if defined(__GNUC__)
27262
27263 __inline__ sqlite_uint64 sqlite3Hwtime(void){
27264 unsigned int lo, hi;
27265 __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi));
27266 return (sqlite_uint64)hi << 32 | lo;
27267 }
27268
27269 #elif defined(_MSC_VER)
27270
27271 __declspec(naked) __inline sqlite_uint64 __cdecl sqlite3Hwtime(void){
27272 __asm {
27273 rdtsc
27274 ret ; return value at EDX:EAX
27275 }
27276 }
27277
27278 #endif
27279
27280 #elif !defined(__STRICT_ANSI__) && (defined(__GNUC__) && defined(__x86_64__))
27281
27282 __inline__ sqlite_uint64 sqlite3Hwtime(void){
27283 unsigned long val;
27284 __asm__ __volatile__ ("rdtsc" : "=A" (val));
27285 return val;
27286 }
27287
27288 #elif !defined(__STRICT_ANSI__) && (defined(__GNUC__) && defined(__ppc__))
27289
27290 __inline__ sqlite_uint64 sqlite3Hwtime(void){
27291 unsigned long long retval;
27292 unsigned long junk;
27293 __asm__ __volatile__ ("\n\
27294 1: mftbu %1\n\
27295 mftb %L0\n\
27296 mftbu %0\n\
27297 cmpw %0,%1\n\
27298 bne 1b"
27299 : "=r" (retval), "=r" (junk));
27300 return retval;
27301 }
27302
27303 #else
27304
27305 /*
27306 ** asm() is needed for hardware timing support. Without asm(),
27307 ** disable the sqlite3Hwtime() routine.
27308 **
27309 ** sqlite3Hwtime() is only used for some obscure debugging
27310 ** and analysis configurations, not in any deliverable, so this
27311 ** should not be a great loss.
27312 */
27313 SQLITE_PRIVATE sqlite_uint64 sqlite3Hwtime(void){ return ((sqlite_uint64)0); }
27314
27315 #endif
27316
27317 #endif /* !defined(SQLITE_HWTIME_H) */
27318
27319 /************** End of hwtime.h **********************************************/
27320 /************** Continuing where we left off in os_common.h ******************/
27321
27322 static sqlite_uint64 g_start;
27323 static sqlite_uint64 g_elapsed;
27324 #define TIMER_START g_start=sqlite3Hwtime()
27325 #define TIMER_END g_elapsed=sqlite3Hwtime()-g_start
27326 #define TIMER_ELAPSED g_elapsed
27327 #else
27328 #define TIMER_START
27329 #define TIMER_END
27330 #define TIMER_ELAPSED ((sqlite_uint64)0)
27331 #endif
27332
27333 /*
27334 ** If we compile with the SQLITE_TEST macro set, then the following block
27335 ** of code will give us the ability to simulate a disk I/O error. This
27336 ** is used for testing the I/O recovery logic.
27337 */
27338 #if defined(SQLITE_TEST)
27339 SQLITE_API extern int sqlite3_io_error_hit;
27340 SQLITE_API extern int sqlite3_io_error_hardhit;
27341 SQLITE_API extern int sqlite3_io_error_pending;
27342 SQLITE_API extern int sqlite3_io_error_persist;
27343 SQLITE_API extern int sqlite3_io_error_benign;
27344 SQLITE_API extern int sqlite3_diskfull_pending;
27345 SQLITE_API extern int sqlite3_diskfull;
27346 #define SimulateIOErrorBenign(X) sqlite3_io_error_benign=(X)
27347 #define SimulateIOError(CODE) \
27348 if( (sqlite3_io_error_persist && sqlite3_io_error_hit) \
27349 || sqlite3_io_error_pending-- == 1 ) \
27350 { local_ioerr(); CODE; }
27351 static void local_ioerr(){
27352 IOTRACE(("IOERR\n"));
27353 sqlite3_io_error_hit++;
27354 if( !sqlite3_io_error_benign ) sqlite3_io_error_hardhit++;
27355 }
27356 #define SimulateDiskfullError(CODE) \
27357 if( sqlite3_diskfull_pending ){ \
27358 if( sqlite3_diskfull_pending == 1 ){ \
27359 local_ioerr(); \
27360 sqlite3_diskfull = 1; \
27361 sqlite3_io_error_hit = 1; \
27362 CODE; \
27363 }else{ \
27364 sqlite3_diskfull_pending--; \
27365 } \
27366 }
27367 #else
27368 #define SimulateIOErrorBenign(X)
27369 #define SimulateIOError(A)
27370 #define SimulateDiskfullError(A)
27371 #endif /* defined(SQLITE_TEST) */
27372
27373 /*
27374 ** When testing, keep a count of the number of open files.
27375 */
27376 #if defined(SQLITE_TEST)
27377 SQLITE_API extern int sqlite3_open_file_count;
27378 #define OpenCounter(X) sqlite3_open_file_count+=(X)
27379 #else
27380 #define OpenCounter(X)
27381 #endif /* defined(SQLITE_TEST) */
27382
27383 #endif /* !defined(_OS_COMMON_H_) */
27384
27385 /************** End of os_common.h *******************************************/
27386 /************** Continuing where we left off in mutex_w32.c ******************/
27387
27388 /*
27389 ** Include the header file for the Windows VFS.
27390 */
27391 /************** Include os_win.h in the middle of mutex_w32.c ****************/
@@ -30484,12 +30553,12 @@
30484 case TK_NULL: {
30485 sqlite3TreeViewLine(pView,"NULL");
30486 break;
30487 }
30488 case TK_TRUEFALSE: {
30489 sqlite3TreeViewLine(pView,
30490 sqlite3ExprTruthValue(pExpr) ? "TRUE" : "FALSE");
30491 break;
30492 }
30493 #ifndef SQLITE_OMIT_BLOB_LITERAL
30494 case TK_BLOB: {
30495 sqlite3TreeViewLine(pView,"%s", pExpr->u.zToken);
@@ -31856,12 +31925,18 @@
31856 **
31857 ** The column type is an extra string stored after the zero-terminator on
31858 ** the column name if and only if the COLFLAG_HASTYPE flag is set.
31859 */
31860 SQLITE_PRIVATE char *sqlite3ColumnType(Column *pCol, char *zDflt){
31861 if( (pCol->colFlags & COLFLAG_HASTYPE)==0 ) return zDflt;
31862 return pCol->zName + strlen(pCol->zName) + 1;
 
 
 
 
 
 
31863 }
31864
31865 /*
31866 ** Helper function for sqlite3Error() - called rarely. Broken out into
31867 ** a separate routine to avoid unnecessary register saves on entry to
@@ -32032,10 +32107,32 @@
32032 SQLITE_PRIVATE void sqlite3DequoteExpr(Expr *p){
32033 assert( sqlite3Isquote(p->u.zToken[0]) );
32034 p->flags |= p->u.zToken[0]=='"' ? EP_Quoted|EP_DblQuoted : EP_Quoted;
32035 sqlite3Dequote(p->u.zToken);
32036 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32037
32038 /*
32039 ** Generate a Token object from a string
32040 */
32041 SQLITE_PRIVATE void sqlite3TokenInit(Token *p, char *z){
@@ -34243,209 +34340,11 @@
34243 #define UNIXFILE_NOLOCK 0x80 /* Do no file locking */
34244
34245 /*
34246 ** Include code that is common to all os_*.c files
34247 */
34248 /************** Include os_common.h in the middle of os_unix.c ***************/
34249 /************** Begin file os_common.h ***************************************/
34250 /*
34251 ** 2004 May 22
34252 **
34253 ** The author disclaims copyright to this source code. In place of
34254 ** a legal notice, here is a blessing:
34255 **
34256 ** May you do good and not evil.
34257 ** May you find forgiveness for yourself and forgive others.
34258 ** May you share freely, never taking more than you give.
34259 **
34260 ******************************************************************************
34261 **
34262 ** This file contains macros and a little bit of code that is common to
34263 ** all of the platform-specific files (os_*.c) and is #included into those
34264 ** files.
34265 **
34266 ** This file should be #included by the os_*.c files only. It is not a
34267 ** general purpose header file.
34268 */
34269 #ifndef _OS_COMMON_H_
34270 #define _OS_COMMON_H_
34271
34272 /*
34273 ** At least two bugs have slipped in because we changed the MEMORY_DEBUG
34274 ** macro to SQLITE_DEBUG and some older makefiles have not yet made the
34275 ** switch. The following code should catch this problem at compile-time.
34276 */
34277 #ifdef MEMORY_DEBUG
34278 # error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead."
34279 #endif
34280
34281 /*
34282 ** Macros for performance tracing. Normally turned off. Only works
34283 ** on i486 hardware.
34284 */
34285 #ifdef SQLITE_PERFORMANCE_TRACE
34286
34287 /*
34288 ** hwtime.h contains inline assembler code for implementing
34289 ** high-performance timing routines.
34290 */
34291 /************** Include hwtime.h in the middle of os_common.h ****************/
34292 /************** Begin file hwtime.h ******************************************/
34293 /*
34294 ** 2008 May 27
34295 **
34296 ** The author disclaims copyright to this source code. In place of
34297 ** a legal notice, here is a blessing:
34298 **
34299 ** May you do good and not evil.
34300 ** May you find forgiveness for yourself and forgive others.
34301 ** May you share freely, never taking more than you give.
34302 **
34303 ******************************************************************************
34304 **
34305 ** This file contains inline asm code for retrieving "high-performance"
34306 ** counters for x86 and x86_64 class CPUs.
34307 */
34308 #ifndef SQLITE_HWTIME_H
34309 #define SQLITE_HWTIME_H
34310
34311 /*
34312 ** The following routine only works on pentium-class (or newer) processors.
34313 ** It uses the RDTSC opcode to read the cycle count value out of the
34314 ** processor and returns that value. This can be used for high-res
34315 ** profiling.
34316 */
34317 #if !defined(__STRICT_ANSI__) && \
34318 (defined(__GNUC__) || defined(_MSC_VER)) && \
34319 (defined(i386) || defined(__i386__) || defined(_M_IX86))
34320
34321 #if defined(__GNUC__)
34322
34323 __inline__ sqlite_uint64 sqlite3Hwtime(void){
34324 unsigned int lo, hi;
34325 __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi));
34326 return (sqlite_uint64)hi << 32 | lo;
34327 }
34328
34329 #elif defined(_MSC_VER)
34330
34331 __declspec(naked) __inline sqlite_uint64 __cdecl sqlite3Hwtime(void){
34332 __asm {
34333 rdtsc
34334 ret ; return value at EDX:EAX
34335 }
34336 }
34337
34338 #endif
34339
34340 #elif !defined(__STRICT_ANSI__) && (defined(__GNUC__) && defined(__x86_64__))
34341
34342 __inline__ sqlite_uint64 sqlite3Hwtime(void){
34343 unsigned long val;
34344 __asm__ __volatile__ ("rdtsc" : "=A" (val));
34345 return val;
34346 }
34347
34348 #elif !defined(__STRICT_ANSI__) && (defined(__GNUC__) && defined(__ppc__))
34349
34350 __inline__ sqlite_uint64 sqlite3Hwtime(void){
34351 unsigned long long retval;
34352 unsigned long junk;
34353 __asm__ __volatile__ ("\n\
34354 1: mftbu %1\n\
34355 mftb %L0\n\
34356 mftbu %0\n\
34357 cmpw %0,%1\n\
34358 bne 1b"
34359 : "=r" (retval), "=r" (junk));
34360 return retval;
34361 }
34362
34363 #else
34364
34365 /*
34366 ** asm() is needed for hardware timing support. Without asm(),
34367 ** disable the sqlite3Hwtime() routine.
34368 **
34369 ** sqlite3Hwtime() is only used for some obscure debugging
34370 ** and analysis configurations, not in any deliverable, so this
34371 ** should not be a great loss.
34372 */
34373 SQLITE_PRIVATE sqlite_uint64 sqlite3Hwtime(void){ return ((sqlite_uint64)0); }
34374
34375 #endif
34376
34377 #endif /* !defined(SQLITE_HWTIME_H) */
34378
34379 /************** End of hwtime.h **********************************************/
34380 /************** Continuing where we left off in os_common.h ******************/
34381
34382 static sqlite_uint64 g_start;
34383 static sqlite_uint64 g_elapsed;
34384 #define TIMER_START g_start=sqlite3Hwtime()
34385 #define TIMER_END g_elapsed=sqlite3Hwtime()-g_start
34386 #define TIMER_ELAPSED g_elapsed
34387 #else
34388 #define TIMER_START
34389 #define TIMER_END
34390 #define TIMER_ELAPSED ((sqlite_uint64)0)
34391 #endif
34392
34393 /*
34394 ** If we compile with the SQLITE_TEST macro set, then the following block
34395 ** of code will give us the ability to simulate a disk I/O error. This
34396 ** is used for testing the I/O recovery logic.
34397 */
34398 #if defined(SQLITE_TEST)
34399 SQLITE_API extern int sqlite3_io_error_hit;
34400 SQLITE_API extern int sqlite3_io_error_hardhit;
34401 SQLITE_API extern int sqlite3_io_error_pending;
34402 SQLITE_API extern int sqlite3_io_error_persist;
34403 SQLITE_API extern int sqlite3_io_error_benign;
34404 SQLITE_API extern int sqlite3_diskfull_pending;
34405 SQLITE_API extern int sqlite3_diskfull;
34406 #define SimulateIOErrorBenign(X) sqlite3_io_error_benign=(X)
34407 #define SimulateIOError(CODE) \
34408 if( (sqlite3_io_error_persist && sqlite3_io_error_hit) \
34409 || sqlite3_io_error_pending-- == 1 ) \
34410 { local_ioerr(); CODE; }
34411 static void local_ioerr(){
34412 IOTRACE(("IOERR\n"));
34413 sqlite3_io_error_hit++;
34414 if( !sqlite3_io_error_benign ) sqlite3_io_error_hardhit++;
34415 }
34416 #define SimulateDiskfullError(CODE) \
34417 if( sqlite3_diskfull_pending ){ \
34418 if( sqlite3_diskfull_pending == 1 ){ \
34419 local_ioerr(); \
34420 sqlite3_diskfull = 1; \
34421 sqlite3_io_error_hit = 1; \
34422 CODE; \
34423 }else{ \
34424 sqlite3_diskfull_pending--; \
34425 } \
34426 }
34427 #else
34428 #define SimulateIOErrorBenign(X)
34429 #define SimulateIOError(A)
34430 #define SimulateDiskfullError(A)
34431 #endif /* defined(SQLITE_TEST) */
34432
34433 /*
34434 ** When testing, keep a count of the number of open files.
34435 */
34436 #if defined(SQLITE_TEST)
34437 SQLITE_API extern int sqlite3_open_file_count;
34438 #define OpenCounter(X) sqlite3_open_file_count+=(X)
34439 #else
34440 #define OpenCounter(X)
34441 #endif /* defined(SQLITE_TEST) */
34442
34443 #endif /* !defined(_OS_COMMON_H_) */
34444
34445 /************** End of os_common.h *******************************************/
34446 /************** Continuing where we left off in os_unix.c ********************/
34447
34448 /*
34449 ** Define various macros that are missing from some systems.
34450 */
34451 #ifndef O_LARGEFILE
@@ -42271,209 +42170,11 @@
42271 #if SQLITE_OS_WIN /* This file is used for Windows only */
42272
42273 /*
42274 ** Include code that is common to all os_*.c files
42275 */
42276 /************** Include os_common.h in the middle of os_win.c ****************/
42277 /************** Begin file os_common.h ***************************************/
42278 /*
42279 ** 2004 May 22
42280 **
42281 ** The author disclaims copyright to this source code. In place of
42282 ** a legal notice, here is a blessing:
42283 **
42284 ** May you do good and not evil.
42285 ** May you find forgiveness for yourself and forgive others.
42286 ** May you share freely, never taking more than you give.
42287 **
42288 ******************************************************************************
42289 **
42290 ** This file contains macros and a little bit of code that is common to
42291 ** all of the platform-specific files (os_*.c) and is #included into those
42292 ** files.
42293 **
42294 ** This file should be #included by the os_*.c files only. It is not a
42295 ** general purpose header file.
42296 */
42297 #ifndef _OS_COMMON_H_
42298 #define _OS_COMMON_H_
42299
42300 /*
42301 ** At least two bugs have slipped in because we changed the MEMORY_DEBUG
42302 ** macro to SQLITE_DEBUG and some older makefiles have not yet made the
42303 ** switch. The following code should catch this problem at compile-time.
42304 */
42305 #ifdef MEMORY_DEBUG
42306 # error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead."
42307 #endif
42308
42309 /*
42310 ** Macros for performance tracing. Normally turned off. Only works
42311 ** on i486 hardware.
42312 */
42313 #ifdef SQLITE_PERFORMANCE_TRACE
42314
42315 /*
42316 ** hwtime.h contains inline assembler code for implementing
42317 ** high-performance timing routines.
42318 */
42319 /************** Include hwtime.h in the middle of os_common.h ****************/
42320 /************** Begin file hwtime.h ******************************************/
42321 /*
42322 ** 2008 May 27
42323 **
42324 ** The author disclaims copyright to this source code. In place of
42325 ** a legal notice, here is a blessing:
42326 **
42327 ** May you do good and not evil.
42328 ** May you find forgiveness for yourself and forgive others.
42329 ** May you share freely, never taking more than you give.
42330 **
42331 ******************************************************************************
42332 **
42333 ** This file contains inline asm code for retrieving "high-performance"
42334 ** counters for x86 and x86_64 class CPUs.
42335 */
42336 #ifndef SQLITE_HWTIME_H
42337 #define SQLITE_HWTIME_H
42338
42339 /*
42340 ** The following routine only works on pentium-class (or newer) processors.
42341 ** It uses the RDTSC opcode to read the cycle count value out of the
42342 ** processor and returns that value. This can be used for high-res
42343 ** profiling.
42344 */
42345 #if !defined(__STRICT_ANSI__) && \
42346 (defined(__GNUC__) || defined(_MSC_VER)) && \
42347 (defined(i386) || defined(__i386__) || defined(_M_IX86))
42348
42349 #if defined(__GNUC__)
42350
42351 __inline__ sqlite_uint64 sqlite3Hwtime(void){
42352 unsigned int lo, hi;
42353 __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi));
42354 return (sqlite_uint64)hi << 32 | lo;
42355 }
42356
42357 #elif defined(_MSC_VER)
42358
42359 __declspec(naked) __inline sqlite_uint64 __cdecl sqlite3Hwtime(void){
42360 __asm {
42361 rdtsc
42362 ret ; return value at EDX:EAX
42363 }
42364 }
42365
42366 #endif
42367
42368 #elif !defined(__STRICT_ANSI__) && (defined(__GNUC__) && defined(__x86_64__))
42369
42370 __inline__ sqlite_uint64 sqlite3Hwtime(void){
42371 unsigned long val;
42372 __asm__ __volatile__ ("rdtsc" : "=A" (val));
42373 return val;
42374 }
42375
42376 #elif !defined(__STRICT_ANSI__) && (defined(__GNUC__) && defined(__ppc__))
42377
42378 __inline__ sqlite_uint64 sqlite3Hwtime(void){
42379 unsigned long long retval;
42380 unsigned long junk;
42381 __asm__ __volatile__ ("\n\
42382 1: mftbu %1\n\
42383 mftb %L0\n\
42384 mftbu %0\n\
42385 cmpw %0,%1\n\
42386 bne 1b"
42387 : "=r" (retval), "=r" (junk));
42388 return retval;
42389 }
42390
42391 #else
42392
42393 /*
42394 ** asm() is needed for hardware timing support. Without asm(),
42395 ** disable the sqlite3Hwtime() routine.
42396 **
42397 ** sqlite3Hwtime() is only used for some obscure debugging
42398 ** and analysis configurations, not in any deliverable, so this
42399 ** should not be a great loss.
42400 */
42401 SQLITE_PRIVATE sqlite_uint64 sqlite3Hwtime(void){ return ((sqlite_uint64)0); }
42402
42403 #endif
42404
42405 #endif /* !defined(SQLITE_HWTIME_H) */
42406
42407 /************** End of hwtime.h **********************************************/
42408 /************** Continuing where we left off in os_common.h ******************/
42409
42410 static sqlite_uint64 g_start;
42411 static sqlite_uint64 g_elapsed;
42412 #define TIMER_START g_start=sqlite3Hwtime()
42413 #define TIMER_END g_elapsed=sqlite3Hwtime()-g_start
42414 #define TIMER_ELAPSED g_elapsed
42415 #else
42416 #define TIMER_START
42417 #define TIMER_END
42418 #define TIMER_ELAPSED ((sqlite_uint64)0)
42419 #endif
42420
42421 /*
42422 ** If we compile with the SQLITE_TEST macro set, then the following block
42423 ** of code will give us the ability to simulate a disk I/O error. This
42424 ** is used for testing the I/O recovery logic.
42425 */
42426 #if defined(SQLITE_TEST)
42427 SQLITE_API extern int sqlite3_io_error_hit;
42428 SQLITE_API extern int sqlite3_io_error_hardhit;
42429 SQLITE_API extern int sqlite3_io_error_pending;
42430 SQLITE_API extern int sqlite3_io_error_persist;
42431 SQLITE_API extern int sqlite3_io_error_benign;
42432 SQLITE_API extern int sqlite3_diskfull_pending;
42433 SQLITE_API extern int sqlite3_diskfull;
42434 #define SimulateIOErrorBenign(X) sqlite3_io_error_benign=(X)
42435 #define SimulateIOError(CODE) \
42436 if( (sqlite3_io_error_persist && sqlite3_io_error_hit) \
42437 || sqlite3_io_error_pending-- == 1 ) \
42438 { local_ioerr(); CODE; }
42439 static void local_ioerr(){
42440 IOTRACE(("IOERR\n"));
42441 sqlite3_io_error_hit++;
42442 if( !sqlite3_io_error_benign ) sqlite3_io_error_hardhit++;
42443 }
42444 #define SimulateDiskfullError(CODE) \
42445 if( sqlite3_diskfull_pending ){ \
42446 if( sqlite3_diskfull_pending == 1 ){ \
42447 local_ioerr(); \
42448 sqlite3_diskfull = 1; \
42449 sqlite3_io_error_hit = 1; \
42450 CODE; \
42451 }else{ \
42452 sqlite3_diskfull_pending--; \
42453 } \
42454 }
42455 #else
42456 #define SimulateIOErrorBenign(X)
42457 #define SimulateIOError(A)
42458 #define SimulateDiskfullError(A)
42459 #endif /* defined(SQLITE_TEST) */
42460
42461 /*
42462 ** When testing, keep a count of the number of open files.
42463 */
42464 #if defined(SQLITE_TEST)
42465 SQLITE_API extern int sqlite3_open_file_count;
42466 #define OpenCounter(X) sqlite3_open_file_count+=(X)
42467 #else
42468 #define OpenCounter(X)
42469 #endif /* defined(SQLITE_TEST) */
42470
42471 #endif /* !defined(_OS_COMMON_H_) */
42472
42473 /************** End of os_common.h *******************************************/
42474 /************** Continuing where we left off in os_win.c *********************/
42475
42476 /*
42477 ** Include the header file for the Windows VFS.
42478 */
42479 /* #include "os_win.h" */
@@ -60605,11 +60306,14 @@
60605 ** Each index block except for the first contains information on
60606 ** HASHTABLE_NPAGE frames. The first index block contains information on
60607 ** HASHTABLE_NPAGE_ONE frames. The values of HASHTABLE_NPAGE_ONE and
60608 ** HASHTABLE_NPAGE are selected so that together the wal-index header and
60609 ** first index block are the same size as all other index blocks in the
60610 ** wal-index.
 
 
 
60611 **
60612 ** Each index block contains two sections, a page-mapping that contains the
60613 ** database page number associated with each wal frame, and a hash-table
60614 ** that allows readers to query an index block for a specific page number.
60615 ** The page-mapping is an array of HASHTABLE_NPAGE (or HASHTABLE_NPAGE_ONE
@@ -60841,10 +60545,74 @@
60841 u32 nBackfillAttempted; /* WAL frames perhaps written, or maybe not */
60842 u32 notUsed0; /* Available for future enhancements */
60843 };
60844 #define READMARK_NOT_USED 0xffffffff
60845
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60846
60847 /* A block of WALINDEX_LOCK_RESERVED bytes beginning at
60848 ** WALINDEX_LOCK_OFFSET is reserved for locks. Since some systems
60849 ** only support mandatory file-locks, we do not read or write data
60850 ** from the region of the file on which locks are applied.
@@ -61853,19 +61621,48 @@
61853 Wal *pRet; /* Object to allocate and return */
61854 int flags; /* Flags passed to OsOpen() */
61855
61856 assert( zWalName && zWalName[0] );
61857 assert( pDbFd );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61858
61859 /* In the amalgamation, the os_unix.c and os_win.c source files come before
61860 ** this source file. Verify that the #defines of the locking byte offsets
61861 ** in os_unix.c and os_win.c agree with the WALINDEX_LOCK_OFFSET value.
61862 ** For that matter, if the lock offset ever changes from its initial design
61863 ** value of 120, we need to know that so there is an assert() to check it.
61864 */
61865 assert( 120==WALINDEX_LOCK_OFFSET );
61866 assert( 136==WALINDEX_HDR_SIZE );
61867 #ifdef WIN_SHM_BASE
61868 assert( WIN_SHM_BASE==WALINDEX_LOCK_OFFSET );
61869 #endif
61870 #ifdef UNIX_SHM_BASE
61871 assert( UNIX_SHM_BASE==WALINDEX_LOCK_OFFSET );
@@ -80741,11 +80538,11 @@
80741 }
80742 #endif
80743 case P4_COLLSEQ: {
80744 static const char *const encnames[] = {"?", "8", "16LE", "16BE"};
80745 CollSeq *pColl = pOp->p4.pColl;
80746 assert( pColl->enc>=0 && pColl->enc<4 );
80747 sqlite3_str_appendf(&x, "%.18s-%s", pColl->zName,
80748 encnames[pColl->enc]);
80749 break;
80750 }
80751 case P4_FUNCDEF: {
@@ -87207,100 +87004,11 @@
87207
87208 /*
87209 ** hwtime.h contains inline assembler code for implementing
87210 ** high-performance timing routines.
87211 */
87212 /************** Include hwtime.h in the middle of vdbe.c *********************/
87213 /************** Begin file hwtime.h ******************************************/
87214 /*
87215 ** 2008 May 27
87216 **
87217 ** The author disclaims copyright to this source code. In place of
87218 ** a legal notice, here is a blessing:
87219 **
87220 ** May you do good and not evil.
87221 ** May you find forgiveness for yourself and forgive others.
87222 ** May you share freely, never taking more than you give.
87223 **
87224 ******************************************************************************
87225 **
87226 ** This file contains inline asm code for retrieving "high-performance"
87227 ** counters for x86 and x86_64 class CPUs.
87228 */
87229 #ifndef SQLITE_HWTIME_H
87230 #define SQLITE_HWTIME_H
87231
87232 /*
87233 ** The following routine only works on pentium-class (or newer) processors.
87234 ** It uses the RDTSC opcode to read the cycle count value out of the
87235 ** processor and returns that value. This can be used for high-res
87236 ** profiling.
87237 */
87238 #if !defined(__STRICT_ANSI__) && \
87239 (defined(__GNUC__) || defined(_MSC_VER)) && \
87240 (defined(i386) || defined(__i386__) || defined(_M_IX86))
87241
87242 #if defined(__GNUC__)
87243
87244 __inline__ sqlite_uint64 sqlite3Hwtime(void){
87245 unsigned int lo, hi;
87246 __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi));
87247 return (sqlite_uint64)hi << 32 | lo;
87248 }
87249
87250 #elif defined(_MSC_VER)
87251
87252 __declspec(naked) __inline sqlite_uint64 __cdecl sqlite3Hwtime(void){
87253 __asm {
87254 rdtsc
87255 ret ; return value at EDX:EAX
87256 }
87257 }
87258
87259 #endif
87260
87261 #elif !defined(__STRICT_ANSI__) && (defined(__GNUC__) && defined(__x86_64__))
87262
87263 __inline__ sqlite_uint64 sqlite3Hwtime(void){
87264 unsigned long val;
87265 __asm__ __volatile__ ("rdtsc" : "=A" (val));
87266 return val;
87267 }
87268
87269 #elif !defined(__STRICT_ANSI__) && (defined(__GNUC__) && defined(__ppc__))
87270
87271 __inline__ sqlite_uint64 sqlite3Hwtime(void){
87272 unsigned long long retval;
87273 unsigned long junk;
87274 __asm__ __volatile__ ("\n\
87275 1: mftbu %1\n\
87276 mftb %L0\n\
87277 mftbu %0\n\
87278 cmpw %0,%1\n\
87279 bne 1b"
87280 : "=r" (retval), "=r" (junk));
87281 return retval;
87282 }
87283
87284 #else
87285
87286 /*
87287 ** asm() is needed for hardware timing support. Without asm(),
87288 ** disable the sqlite3Hwtime() routine.
87289 **
87290 ** sqlite3Hwtime() is only used for some obscure debugging
87291 ** and analysis configurations, not in any deliverable, so this
87292 ** should not be a great loss.
87293 */
87294 SQLITE_PRIVATE sqlite_uint64 sqlite3Hwtime(void){ return ((sqlite_uint64)0); }
87295
87296 #endif
87297
87298 #endif /* !defined(SQLITE_HWTIME_H) */
87299
87300 /************** End of hwtime.h **********************************************/
87301 /************** Continuing where we left off in vdbe.c ***********************/
87302
87303 #endif
87304
87305 #ifndef NDEBUG
87306 /*
@@ -95148,11 +94856,11 @@
95148 if( pTab && !HasRowid(pTab) ){
95149 pTab = 0;
95150 sqlite3ErrorMsg(&sParse, "cannot open table without rowid: %s", zTable);
95151 }
95152 #ifndef SQLITE_OMIT_VIEW
95153 if( pTab && pTab->pSelect ){
95154 pTab = 0;
95155 sqlite3ErrorMsg(&sParse, "cannot open view: %s", zTable);
95156 }
95157 #endif
95158 if( !pTab ){
@@ -95168,11 +94876,11 @@
95168 pBlob->pTab = pTab;
95169 pBlob->zDb = db->aDb[sqlite3SchemaToIndex(db, pTab->pSchema)].zDbSName;
95170
95171 /* Now search pTab for the exact column. */
95172 for(iCol=0; iCol<pTab->nCol; iCol++) {
95173 if( sqlite3StrICmp(pTab->aCol[iCol].zName, zColumn)==0 ){
95174 break;
95175 }
95176 }
95177 if( iCol==pTab->nCol ){
95178 sqlite3DbFree(db, zErr);
@@ -95193,11 +94901,12 @@
95193 /* Check that the column is not part of an FK child key definition. It
95194 ** is not necessary to check if it is part of a parent key, as parent
95195 ** key columns must be indexed. The check below will pick up this
95196 ** case. */
95197 FKey *pFKey;
95198 for(pFKey=pTab->pFKey; pFKey; pFKey=pFKey->pNextFrom){
 
95199 int j;
95200 for(j=0; j<pFKey->nCol; j++){
95201 if( pFKey->aCol[j].iFrom==iCol ){
95202 zFault = "foreign key";
95203 }
@@ -99719,11 +99428,13 @@
99719 sqlite3RenameTokenRemap(pParse, 0, (void*)&pExpr->y.pTab);
99720 }
99721 }
99722 hCol = sqlite3StrIHash(zCol);
99723 for(j=0, pCol=pTab->aCol; j<pTab->nCol; j++, pCol++){
99724 if( pCol->hName==hCol && sqlite3StrICmp(pCol->zName, zCol)==0 ){
 
 
99725 /* If there has been exactly one prior match and this match
99726 ** is for the right-hand table of a NATURAL JOIN or is in a
99727 ** USING clause, then skip this match.
99728 */
99729 if( cnt==1 ){
@@ -99796,11 +99507,13 @@
99796 int iCol;
99797 u8 hCol = sqlite3StrIHash(zCol);
99798 pSchema = pTab->pSchema;
99799 cntTab++;
99800 for(iCol=0, pCol=pTab->aCol; iCol<pTab->nCol; iCol++, pCol++){
99801 if( pCol->hName==hCol && sqlite3StrICmp(pCol->zName, zCol)==0 ){
 
 
99802 if( iCol==pTab->iPKey ){
99803 iCol = -1;
99804 }
99805 break;
99806 }
@@ -100204,10 +99917,11 @@
100204 for(i=0, p=pNC; p && i<ArraySize(anRef); p=p->pNext, i++){
100205 anRef[i] = p->nRef;
100206 }
100207 sqlite3WalkExpr(pWalker, pExpr->pLeft);
100208 if( 0==sqlite3ExprCanBeNull(pExpr->pLeft) && !IN_RENAME_OBJECT ){
 
100209 if( pExpr->op==TK_NOTNULL ){
100210 pExpr->u.zToken = "true";
100211 ExprSetProperty(pExpr, EP_IsTrue);
100212 }else{
100213 pExpr->u.zToken = "false";
@@ -101582,11 +101296,11 @@
101582 ){
101583 /* op==TK_REGISTER && p->y.pTab!=0 happens when pExpr was originally
101584 ** a TK_COLUMN but was previously evaluated and cached in a register */
101585 int j = p->iColumn;
101586 if( j>=0 ){
101587 const char *zColl = p->y.pTab->aCol[j].zColl;
101588 pColl = sqlite3FindCollSeq(db, ENC(db), zColl, 0);
101589 }
101590 break;
101591 }
101592 if( op==TK_CAST || op==TK_UPLUS ){
@@ -103922,11 +103636,11 @@
103922 assert( pSrc!=0 );
103923 if( pSrc->nSrc!=1 ) return 0; /* Single term in FROM clause */
103924 if( pSrc->a[0].pSelect ) return 0; /* FROM is not a subquery or view */
103925 pTab = pSrc->a[0].pTab;
103926 assert( pTab!=0 );
103927 assert( pTab->pSelect==0 ); /* FROM clause is not a view */
103928 if( IsVirtual(pTab) ) return 0; /* FROM clause not a virtual table */
103929 pEList = p->pEList;
103930 assert( pEList!=0 );
103931 /* All SELECT results must be columns. */
103932 for(i=0; i<pEList->nExpr; i++){
@@ -105052,13 +104766,14 @@
105052 /*
105053 ** Generate code that will compute the value of generated column pCol
105054 ** and store the result in register regOut
105055 */
105056 SQLITE_PRIVATE void sqlite3ExprCodeGeneratedColumn(
105057 Parse *pParse,
105058 Column *pCol,
105059 int regOut
 
105060 ){
105061 int iAddr;
105062 Vdbe *v = pParse->pVdbe;
105063 assert( v!=0 );
105064 assert( pParse->iSelfTab!=0 );
@@ -105065,11 +104780,11 @@
105065 if( pParse->iSelfTab>0 ){
105066 iAddr = sqlite3VdbeAddOp3(v, OP_IfNullRow, pParse->iSelfTab-1, 0, regOut);
105067 }else{
105068 iAddr = 0;
105069 }
105070 sqlite3ExprCodeCopy(pParse, pCol->pDflt, regOut);
105071 if( pCol->affinity>=SQLITE_AFF_TEXT ){
105072 sqlite3VdbeAddOp4(v, OP_Affinity, regOut, 1, 0, &pCol->affinity, 1);
105073 }
105074 if( iAddr ) sqlite3VdbeJumpHere(v, iAddr);
105075 }
@@ -105101,16 +104816,17 @@
105101 x = iCol;
105102 #ifndef SQLITE_OMIT_GENERATED_COLUMNS
105103 }else if( (pCol = &pTab->aCol[iCol])->colFlags & COLFLAG_VIRTUAL ){
105104 Parse *pParse = sqlite3VdbeParser(v);
105105 if( pCol->colFlags & COLFLAG_BUSY ){
105106 sqlite3ErrorMsg(pParse, "generated column loop on \"%s\"", pCol->zName);
 
105107 }else{
105108 int savedSelfTab = pParse->iSelfTab;
105109 pCol->colFlags |= COLFLAG_BUSY;
105110 pParse->iSelfTab = iTabCur+1;
105111 sqlite3ExprCodeGeneratedColumn(pParse, pCol, regOut);
105112 pParse->iSelfTab = savedSelfTab;
105113 pCol->colFlags &= ~COLFLAG_BUSY;
105114 }
105115 return;
105116 #endif
@@ -105374,11 +105090,12 @@
105374 sqlite3VdbeAddOp3(v, OP_Column, pAggInfo->sortingIdxPTab,
105375 pCol->iSorterColumn, target);
105376 if( pCol->iColumn<0 ){
105377 VdbeComment((v,"%s.rowid",pTab->zName));
105378 }else{
105379 VdbeComment((v,"%s.%s",pTab->zName,pTab->aCol[pCol->iColumn].zName));
 
105380 if( pTab->aCol[pCol->iColumn].affinity==SQLITE_AFF_REAL ){
105381 sqlite3VdbeAddOp1(v, OP_RealAffinity, target);
105382 }
105383 }
105384 return target;
@@ -105435,16 +105152,16 @@
105435 iSrc = sqlite3TableColumnToStorage(pTab, iCol) - pParse->iSelfTab;
105436 #ifndef SQLITE_OMIT_GENERATED_COLUMNS
105437 if( pCol->colFlags & COLFLAG_GENERATED ){
105438 if( pCol->colFlags & COLFLAG_BUSY ){
105439 sqlite3ErrorMsg(pParse, "generated column loop on \"%s\"",
105440 pCol->zName);
105441 return 0;
105442 }
105443 pCol->colFlags |= COLFLAG_BUSY;
105444 if( pCol->colFlags & COLFLAG_NOTAVAIL ){
105445 sqlite3ExprCodeGeneratedColumn(pParse, pCol, iSrc);
105446 }
105447 pCol->colFlags &= ~(COLFLAG_BUSY|COLFLAG_NOTAVAIL);
105448 return iSrc;
105449 }else
105450 #endif /* SQLITE_OMIT_GENERATED_COLUMNS */
@@ -105918,11 +105635,11 @@
105918 assert( p1>=0 && p1<(pTab->nCol*2+2) );
105919
105920 sqlite3VdbeAddOp2(v, OP_Param, p1, target);
105921 VdbeComment((v, "r[%d]=%s.%s", target,
105922 (pExpr->iTable ? "new" : "old"),
105923 (pExpr->iColumn<0 ? "rowid" : pExpr->y.pTab->aCol[iCol].zName)
105924 ));
105925
105926 #ifndef SQLITE_OMIT_FLOATING_POINT
105927 /* If the column has REAL affinity, it may currently be stored as an
105928 ** integer. Use OP_RealAffinity to make sure it is really real.
@@ -107090,13 +106807,13 @@
107090 testcase( pExpr->op==TK_LE );
107091 testcase( pExpr->op==TK_GT );
107092 testcase( pExpr->op==TK_GE );
107093 /* The y.pTab=0 assignment in wherecode.c always happens after the
107094 ** impliesNotNullRow() test */
107095 if( (pLeft->op==TK_COLUMN && ALWAYS(pLeft->y.pTab!=0)
107096 && IsVirtual(pLeft->y.pTab))
107097 || (pRight->op==TK_COLUMN && ALWAYS(pRight->y.pTab!=0)
107098 && IsVirtual(pRight->y.pTab))
107099 ){
107100 return WRC_Prune;
107101 }
107102 /* no break */ deliberate_fall_through
@@ -107771,22 +107488,19 @@
107771 sqlite3 *db = pParse->db; /* Database connection */
107772 int nTabName; /* Number of UTF-8 characters in zTabName */
107773 const char *zTabName; /* Original name of the table */
107774 Vdbe *v;
107775 VTable *pVTab = 0; /* Non-zero if this is a v-tab with an xRename() */
107776 u32 savedDbFlags; /* Saved value of db->mDbFlags */
107777
107778 savedDbFlags = db->mDbFlags;
107779 if( NEVER(db->mallocFailed) ) goto exit_rename_table;
107780 assert( pSrc->nSrc==1 );
107781 assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );
107782
107783 pTab = sqlite3LocateTableItem(pParse, 0, &pSrc->a[0]);
107784 if( !pTab ) goto exit_rename_table;
107785 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
107786 zDb = db->aDb[iDb].zDbSName;
107787 db->mDbFlags |= DBFLAG_PreferBuiltin;
107788
107789 /* Get a NULL terminated version of the new table name. */
107790 zName = sqlite3NameFromToken(db, pName);
107791 if( !zName ) goto exit_rename_table;
107792
@@ -107811,11 +107525,11 @@
107811 if( SQLITE_OK!=sqlite3CheckObjectName(pParse,zName,"table",zName) ){
107812 goto exit_rename_table;
107813 }
107814
107815 #ifndef SQLITE_OMIT_VIEW
107816 if( pTab->pSelect ){
107817 sqlite3ErrorMsg(pParse, "view %s may not be altered", pTab->zName);
107818 goto exit_rename_table;
107819 }
107820 #endif
107821
@@ -107923,11 +107637,10 @@
107923 renameTestSchema(pParse, zDb, iDb==1, "after rename", 0);
107924
107925 exit_rename_table:
107926 sqlite3SrcListDelete(db, pSrc);
107927 sqlite3DbFree(db, zName);
107928 db->mDbFlags = savedDbFlags;
107929 }
107930
107931 /*
107932 ** Write code that will raise an error if the table described by
107933 ** zDb and zTab is not empty.
@@ -107973,11 +107686,11 @@
107973 assert( sqlite3BtreeHoldsAllMutexes(db) );
107974 iDb = sqlite3SchemaToIndex(db, pNew->pSchema);
107975 zDb = db->aDb[iDb].zDbSName;
107976 zTab = &pNew->zName[16]; /* Skip the "sqlite_altertab_" prefix on the name */
107977 pCol = &pNew->aCol[pNew->nCol-1];
107978 pDflt = pCol->pDflt;
107979 pTab = sqlite3FindTable(db, zTab, zDb);
107980 assert( pTab );
107981
107982 #ifndef SQLITE_OMIT_AUTHORIZATION
107983 /* Invoke the authorization callback. */
@@ -108007,11 +107720,11 @@
108007 */
108008 assert( pDflt==0 || pDflt->op==TK_SPAN );
108009 if( pDflt && pDflt->pLeft->op==TK_NULL ){
108010 pDflt = 0;
108011 }
108012 if( (db->flags&SQLITE_ForeignKeys) && pNew->pFKey && pDflt ){
108013 sqlite3ErrorIfNotEmpty(pParse, zDb, zTab,
108014 "Cannot add a REFERENCES column with non-NULL default value");
108015 }
108016 if( pCol->notNull && !pDflt ){
108017 sqlite3ErrorIfNotEmpty(pParse, zDb, zTab,
@@ -108044,27 +107757,25 @@
108044
108045 /* Modify the CREATE TABLE statement. */
108046 zCol = sqlite3DbStrNDup(db, (char*)pColDef->z, pColDef->n);
108047 if( zCol ){
108048 char *zEnd = &zCol[pColDef->n-1];
108049 u32 savedDbFlags = db->mDbFlags;
108050 while( zEnd>zCol && (*zEnd==';' || sqlite3Isspace(*zEnd)) ){
108051 *zEnd-- = '\0';
108052 }
108053 db->mDbFlags |= DBFLAG_PreferBuiltin;
108054 /* substr() operations on characters, but addColOffset is in bytes. So we
108055 ** have to use printf() to translate between these units: */
 
108056 sqlite3NestedParse(pParse,
108057 "UPDATE \"%w\"." DFLT_SCHEMA_TABLE " SET "
108058 "sql = printf('%%.%ds, ',sql) || %Q"
108059 " || substr(sql,1+length(printf('%%.%ds',sql))) "
108060 "WHERE type = 'table' AND name = %Q",
108061 zDb, pNew->addColOffset, zCol, pNew->addColOffset,
108062 zTab
108063 );
108064 sqlite3DbFree(db, zCol);
108065 db->mDbFlags = savedDbFlags;
108066 }
108067
108068 v = sqlite3GetVdbe(pParse);
108069 if( v ){
108070 /* Make sure the schema version is at least 3. But do not upgrade
@@ -108136,20 +107847,20 @@
108136 goto exit_begin_add_column;
108137 }
108138 #endif
108139
108140 /* Make sure this is not an attempt to ALTER a view. */
108141 if( pTab->pSelect ){
108142 sqlite3ErrorMsg(pParse, "Cannot add a column to a view");
108143 goto exit_begin_add_column;
108144 }
108145 if( SQLITE_OK!=isAlterableTable(pParse, pTab) ){
108146 goto exit_begin_add_column;
108147 }
108148
108149 sqlite3MayAbort(pParse);
108150 assert( pTab->addColOffset>0 );
108151 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
108152
108153 /* Put a copy of the Table struct in Parse.pNewTable for the
108154 ** sqlite3AddColumn() function and friends to modify. But modify
108155 ** the name by adding an "sqlite_altertab_" prefix. By adding this
@@ -108172,17 +107883,17 @@
108172 goto exit_begin_add_column;
108173 }
108174 memcpy(pNew->aCol, pTab->aCol, sizeof(Column)*pNew->nCol);
108175 for(i=0; i<pNew->nCol; i++){
108176 Column *pCol = &pNew->aCol[i];
108177 pCol->zName = sqlite3DbStrDup(db, pCol->zName);
108178 pCol->hName = sqlite3StrIHash(pCol->zName);
108179 pCol->zColl = 0;
108180 pCol->pDflt = 0;
108181 }
 
 
108182 pNew->pSchema = db->aDb[iDb].pSchema;
108183 pNew->addColOffset = pTab->addColOffset;
108184 pNew->nTabRef = 1;
108185
108186 exit_begin_add_column:
108187 sqlite3SrcListDelete(db, pSrc);
108188 return;
@@ -108198,11 +107909,11 @@
108198 */
108199 #if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_VIRTUALTABLE)
108200 static int isRealTable(Parse *pParse, Table *pTab, int bDrop){
108201 const char *zType = 0;
108202 #ifndef SQLITE_OMIT_VIEW
108203 if( pTab->pSelect ){
108204 zType = "view";
108205 }
108206 #endif
108207 #ifndef SQLITE_OMIT_VIRTUALTABLE
108208 if( IsVirtual(pTab) ){
@@ -108265,11 +107976,11 @@
108265 /* Make sure the old name really is a column name in the table to be
108266 ** altered. Set iCol to be the index of the column being renamed */
108267 zOld = sqlite3NameFromToken(db, pOld);
108268 if( !zOld ) goto exit_rename_column;
108269 for(iCol=0; iCol<pTab->nCol; iCol++){
108270 if( 0==sqlite3StrICmp(pTab->aCol[iCol].zName, zOld) ) break;
108271 }
108272 if( iCol==pTab->nCol ){
108273 sqlite3ErrorMsg(pParse, "no such column: \"%s\"", zOld);
108274 goto exit_rename_column;
108275 }
@@ -109111,11 +108822,11 @@
109111 pTab = sqlite3FindTable(db, zTable, zDb);
109112 if( pTab==0 || iCol>=pTab->nCol ){
109113 sqlite3BtreeLeaveAll(db);
109114 return;
109115 }
109116 zOld = pTab->aCol[iCol].zName;
109117 memset(&sCtx, 0, sizeof(sCtx));
109118 sCtx.iCol = ((iCol==pTab->iPKey) ? -1 : iCol);
109119
109120 #ifndef SQLITE_OMIT_AUTHORIZATION
109121 db->xAuth = 0;
@@ -109130,30 +108841,29 @@
109130 sWalker.u.pRename = &sCtx;
109131
109132 sCtx.pTab = pTab;
109133 if( rc!=SQLITE_OK ) goto renameColumnFunc_done;
109134 if( sParse.pNewTable ){
109135 Select *pSelect = sParse.pNewTable->pSelect;
109136 if( pSelect ){
109137 pSelect->selFlags &= ~SF_View;
109138 sParse.rc = SQLITE_OK;
109139 sqlite3SelectPrep(&sParse, pSelect, 0);
109140 rc = (db->mallocFailed ? SQLITE_NOMEM : sParse.rc);
109141 if( rc==SQLITE_OK ){
109142 sqlite3WalkSelect(&sWalker, pSelect);
109143 }
109144 if( rc!=SQLITE_OK ) goto renameColumnFunc_done;
109145 }else{
109146 /* A regular table */
109147 int bFKOnly = sqlite3_stricmp(zTable, sParse.pNewTable->zName);
109148 FKey *pFKey;
109149 assert( sParse.pNewTable->pSelect==0 );
109150 sCtx.pTab = sParse.pNewTable;
109151 if( bFKOnly==0 ){
109152 if( iCol<sParse.pNewTable->nCol ){
109153 renameTokenFind(
109154 &sParse, &sCtx, (void*)sParse.pNewTable->aCol[iCol].zName
109155 );
109156 }
109157 if( sCtx.iCol<0 ){
109158 renameTokenFind(&sParse, &sCtx, (void*)&sParse.pNewTable->iPKey);
109159 }
@@ -109164,16 +108874,19 @@
109164 for(pIdx=sParse.pNewIndex; pIdx; pIdx=pIdx->pNext){
109165 sqlite3WalkExprList(&sWalker, pIdx->aColExpr);
109166 }
109167 #ifndef SQLITE_OMIT_GENERATED_COLUMNS
109168 for(i=0; i<sParse.pNewTable->nCol; i++){
109169 sqlite3WalkExpr(&sWalker, sParse.pNewTable->aCol[i].pDflt);
 
 
109170 }
109171 #endif
109172 }
109173
109174 for(pFKey=sParse.pNewTable->pFKey; pFKey; pFKey=pFKey->pNextFrom){
 
109175 for(i=0; i<pFKey->nCol; i++){
109176 if( bFKOnly==0 && pFKey->aCol[i].iFrom==iCol ){
109177 renameTokenFind(&sParse, &sCtx, (void*)&pFKey->aCol[i]);
109178 }
109179 if( 0==sqlite3_stricmp(pFKey->zTo, zTable)
@@ -109335,32 +109048,35 @@
109335 if( rc==SQLITE_OK ){
109336 int isLegacy = (db->flags & SQLITE_LegacyAlter);
109337 if( sParse.pNewTable ){
109338 Table *pTab = sParse.pNewTable;
109339
109340 if( pTab->pSelect ){
109341 if( isLegacy==0 ){
109342 Select *pSelect = pTab->pSelect;
109343 NameContext sNC;
109344 memset(&sNC, 0, sizeof(sNC));
109345 sNC.pParse = &sParse;
109346
109347 assert( pSelect->selFlags & SF_View );
109348 pSelect->selFlags &= ~SF_View;
109349 sqlite3SelectPrep(&sParse, pTab->pSelect, &sNC);
109350 if( sParse.nErr ){
109351 rc = sParse.rc;
109352 }else{
109353 sqlite3WalkSelect(&sWalker, pTab->pSelect);
109354 }
109355 }
109356 }else{
109357 /* Modify any FK definitions to point to the new table. */
109358 #ifndef SQLITE_OMIT_FOREIGN_KEY
109359 if( isLegacy==0 || (db->flags & SQLITE_ForeignKeys) ){
 
 
109360 FKey *pFKey;
109361 for(pFKey=pTab->pFKey; pFKey; pFKey=pFKey->pNextFrom){
 
109362 if( sqlite3_stricmp(pFKey->zTo, zOld)==0 ){
109363 renameTokenFind(&sParse, &sCtx, (void*)pFKey->zTo);
109364 }
109365 }
109366 }
@@ -109496,12 +109212,12 @@
109496 sWalker.xExprCallback = renameQuotefixExprCb;
109497 sWalker.xSelectCallback = renameColumnSelectCb;
109498 sWalker.u.pRename = &sCtx;
109499
109500 if( sParse.pNewTable ){
109501 Select *pSelect = sParse.pNewTable->pSelect;
109502 if( pSelect ){
109503 pSelect->selFlags &= ~SF_View;
109504 sParse.rc = SQLITE_OK;
109505 sqlite3SelectPrep(&sParse, pSelect, 0);
109506 rc = (db->mallocFailed ? SQLITE_NOMEM : sParse.rc);
109507 if( rc==SQLITE_OK ){
@@ -109510,11 +109226,13 @@
109510 }else{
109511 int i;
109512 sqlite3WalkExprList(&sWalker, sParse.pNewTable->pCheck);
109513 #ifndef SQLITE_OMIT_GENERATED_COLUMNS
109514 for(i=0; i<sParse.pNewTable->nCol; i++){
109515 sqlite3WalkExpr(&sWalker, sParse.pNewTable->aCol[i].pDflt);
 
 
109516 }
109517 #endif /* SQLITE_OMIT_GENERATED_COLUMNS */
109518 }
109519 }else if( sParse.pNewIndex ){
109520 sqlite3WalkExprList(&sWalker, sParse.pNewIndex->aColExpr);
@@ -109593,15 +109311,15 @@
109593 int flags = db->flags;
109594 if( bNoDQS ) db->flags &= ~(SQLITE_DqsDML|SQLITE_DqsDDL);
109595 rc = renameParseSql(&sParse, zDb, db, zInput, bTemp);
109596 db->flags |= (flags & (SQLITE_DqsDML|SQLITE_DqsDDL));
109597 if( rc==SQLITE_OK ){
109598 if( isLegacy==0 && sParse.pNewTable && sParse.pNewTable->pSelect ){
109599 NameContext sNC;
109600 memset(&sNC, 0, sizeof(sNC));
109601 sNC.pParse = &sParse;
109602 sqlite3SelectPrep(&sParse, sParse.pNewTable->pSelect, &sNC);
109603 if( sParse.nErr ) rc = sParse.rc;
109604 }
109605
109606 else if( sParse.pNewTrigger ){
109607 if( isLegacy==0 ){
@@ -109668,17 +109386,18 @@
109668 /* This can happen if the sqlite_schema table is corrupt */
109669 rc = SQLITE_CORRUPT_BKPT;
109670 goto drop_column_done;
109671 }
109672
109673 pCol = renameTokenFind(&sParse, 0, (void*)pTab->aCol[iCol].zName);
109674 if( iCol<pTab->nCol-1 ){
109675 RenameToken *pEnd;
109676 pEnd = renameTokenFind(&sParse, 0, (void*)pTab->aCol[iCol+1].zName);
109677 zEnd = (const char*)pEnd->t.z;
109678 }else{
109679 zEnd = (const char*)&zSql[pTab->addColOffset];
 
109680 while( ALWAYS(pCol->t.z[0]!=0) && pCol->t.z[0]!=',' ) pCol->t.z--;
109681 }
109682
109683 zNew = sqlite3MPrintf(db, "%.*s%s", pCol->t.z-zSql, zSql, zEnd);
109684 sqlite3_result_text(context, zNew, -1, SQLITE_TRANSIENT);
@@ -109809,10 +109528,16 @@
109809 }else{
109810 sqlite3ExprCodeGetColumnOfTable(v, pTab, iCur, i, regOut);
109811 }
109812 nField++;
109813 }
 
 
 
 
 
 
109814 }
109815 sqlite3VdbeAddOp3(v, OP_MakeRecord, reg+1, nField, regRec);
109816 if( pPk ){
109817 sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iCur, regRec, reg+1, pPk->nKeyCol);
109818 }else{
@@ -110814,11 +110539,11 @@
110814 if( NEVER(i==XN_ROWID) ){
110815 VdbeComment((v,"%s.rowid",pIdx->zName));
110816 }else if( i==XN_EXPR ){
110817 VdbeComment((v,"%s.expr(%d)",pIdx->zName, k));
110818 }else{
110819 VdbeComment((v,"%s.%s", pIdx->zName, pIdx->pTable->aCol[i].zName));
110820 }
110821 }
110822 #else
110823 # define analyzeVdbeCommentIndexWithColumnName(a,b,c)
110824 #endif /* SQLITE_DEBUG */
@@ -112567,14 +112292,14 @@
112567 iCol = pExpr->iColumn;
112568 if( pTab==0 ) return;
112569
112570 if( iCol>=0 ){
112571 assert( iCol<pTab->nCol );
112572 zCol = pTab->aCol[iCol].zName;
112573 }else if( pTab->iPKey>=0 ){
112574 assert( pTab->iPKey<pTab->nCol );
112575 zCol = pTab->aCol[pTab->iPKey].zName;
112576 }else{
112577 zCol = "ROWID";
112578 }
112579 assert( iDb>=0 && iDb<pParse->db->nDb );
112580 if( SQLITE_IGNORE==sqlite3AuthReadCol(pParse, pTab->zName, zCol, iDb) ){
@@ -112948,24 +112673,26 @@
112948 }
112949
112950 /*
112951 ** Run the parser and code generator recursively in order to generate
112952 ** code for the SQL statement given onto the end of the pParse context
112953 ** currently under construction. When the parser is run recursively
112954 ** this way, the final OP_Halt is not appended and other initialization
112955 ** and finalization steps are omitted because those are handling by the
112956 ** outermost parser.
112957 **
112958 ** Not everything is nestable. This facility is designed to permit
112959 ** INSERT, UPDATE, and DELETE operations against the schema table. Use
112960 ** care if you decide to try to use this routine for some other purposes.
 
 
 
 
112961 */
112962 SQLITE_PRIVATE void sqlite3NestedParse(Parse *pParse, const char *zFormat, ...){
112963 va_list ap;
112964 char *zSql;
112965 char *zErrMsg = 0;
112966 sqlite3 *db = pParse->db;
 
112967 char saveBuf[PARSE_TAIL_SZ];
112968
112969 if( pParse->nErr ) return;
112970 assert( pParse->nested<10 ); /* Nesting should only be of limited depth */
112971 va_start(ap, zFormat);
@@ -112980,11 +112707,13 @@
112980 return;
112981 }
112982 pParse->nested++;
112983 memcpy(saveBuf, PARSE_TAIL(pParse), PARSE_TAIL_SZ);
112984 memset(PARSE_TAIL(pParse), 0, PARSE_TAIL_SZ);
 
112985 sqlite3RunParser(pParse, zSql, &zErrMsg);
 
112986 sqlite3DbFree(db, zErrMsg);
112987 sqlite3DbFree(db, zSql);
112988 memcpy(PARSE_TAIL(pParse), saveBuf, PARSE_TAIL_SZ);
112989 pParse->nested--;
112990 }
@@ -113329,10 +113058,88 @@
113329 ** This routine is called when a commit occurs.
113330 */
113331 SQLITE_PRIVATE void sqlite3CommitInternalChanges(sqlite3 *db){
113332 db->mDbFlags &= ~DBFLAG_SchemaChange;
113333 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113334
113335 /*
113336 ** Delete memory allocated for the column names of a table or view (the
113337 ** Table.aCol[] array).
113338 */
@@ -113340,16 +113147,24 @@
113340 int i;
113341 Column *pCol;
113342 assert( pTable!=0 );
113343 if( (pCol = pTable->aCol)!=0 ){
113344 for(i=0; i<pTable->nCol; i++, pCol++){
113345 assert( pCol->zName==0 || pCol->hName==sqlite3StrIHash(pCol->zName) );
113346 sqlite3DbFree(db, pCol->zName);
113347 sqlite3ExprDelete(db, pCol->pDflt);
113348 sqlite3DbFree(db, pCol->zColl);
113349 }
113350 sqlite3DbFree(db, pTable->aCol);
 
 
 
 
 
 
 
 
 
 
113351 }
113352 }
113353
113354 /*
113355 ** Remove the memory data structures associated with the given
@@ -113397,23 +113212,29 @@
113397 assert( pOld==pIndex || pOld==0 );
113398 }
113399 sqlite3FreeIndex(db, pIndex);
113400 }
113401
113402 /* Delete any foreign keys attached to this table. */
113403 sqlite3FkDelete(db, pTable);
 
 
 
 
 
 
 
 
 
 
113404
113405 /* Delete the Table structure itself.
113406 */
113407 sqlite3DeleteColumnNames(db, pTable);
113408 sqlite3DbFree(db, pTable->zName);
113409 sqlite3DbFree(db, pTable->zColAff);
113410 sqlite3SelectDelete(db, pTable->pSelect);
113411 sqlite3ExprListDelete(db, pTable->pCheck);
113412 #ifndef SQLITE_OMIT_VIRTUALTABLE
113413 sqlite3VtabClear(db, pTable);
113414 #endif
113415 sqlite3DbFree(db, pTable);
113416
113417 /* Verify that no lookaside memory was used by schema tables */
113418 assert( nLookaside==0 || nLookaside==sqlite3LookasideUsed(db,0) );
113419 }
@@ -113935,20 +113756,21 @@
113935 /* Normal (non-error) return. */
113936 return;
113937
113938 /* If an error occurs, we jump here */
113939 begin_table_error:
 
113940 sqlite3DbFree(db, zName);
113941 return;
113942 }
113943
113944 /* Set properties of a table column based on the (magical)
113945 ** name of the column.
113946 */
113947 #if SQLITE_ENABLE_HIDDEN_COLUMNS
113948 SQLITE_PRIVATE void sqlite3ColumnPropertiesFromName(Table *pTab, Column *pCol){
113949 if( sqlite3_strnicmp(pCol->zName, "__hidden__", 10)==0 ){
113950 pCol->colFlags |= COLFLAG_HIDDEN;
113951 if( pTab ) pTab->tabFlags |= TF_HasHidden;
113952 }else if( pTab && pCol!=pTab->aCol && (pCol[-1].colFlags & COLFLAG_HIDDEN) ){
113953 pTab->tabFlags |= TF_OOOHidden;
113954 }
@@ -114035,67 +113857,108 @@
114035 ** The parser calls this routine once for each column declaration
114036 ** in a CREATE TABLE statement. sqlite3StartTable() gets called
114037 ** first to get things going. Then this routine is called for each
114038 ** column.
114039 */
114040 SQLITE_PRIVATE void sqlite3AddColumn(Parse *pParse, Token *pName, Token *pType){
114041 Table *p;
114042 int i;
114043 char *z;
114044 char *zType;
114045 Column *pCol;
114046 sqlite3 *db = pParse->db;
114047 u8 hName;
 
 
 
 
114048
114049 if( (p = pParse->pNewTable)==0 ) return;
114050 if( p->nCol+1>db->aLimit[SQLITE_LIMIT_COLUMN] ){
114051 sqlite3ErrorMsg(pParse, "too many columns on %s", p->zName);
114052 return;
114053 }
114054 z = sqlite3DbMallocRaw(db, pName->n + pType->n + 2);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
114055 if( z==0 ) return;
114056 if( IN_RENAME_OBJECT ) sqlite3RenameTokenMap(pParse, (void*)z, pName);
114057 memcpy(z, pName->z, pName->n);
114058 z[pName->n] = 0;
114059 sqlite3Dequote(z);
114060 hName = sqlite3StrIHash(z);
114061 for(i=0; i<p->nCol; i++){
114062 if( p->aCol[i].hName==hName && sqlite3StrICmp(z, p->aCol[i].zName)==0 ){
114063 sqlite3ErrorMsg(pParse, "duplicate column name: %s", z);
114064 sqlite3DbFree(db, z);
114065 return;
114066 }
114067 }
114068 if( (p->nCol & 0x7)==0 ){
114069 Column *aNew;
114070 aNew = sqlite3DbRealloc(db,p->aCol,(p->nCol+8)*sizeof(p->aCol[0]));
114071 if( aNew==0 ){
114072 sqlite3DbFree(db, z);
114073 return;
114074 }
114075 p->aCol = aNew;
114076 }
114077 pCol = &p->aCol[p->nCol];
114078 memset(pCol, 0, sizeof(p->aCol[0]));
114079 pCol->zName = z;
114080 pCol->hName = hName;
114081 sqlite3ColumnPropertiesFromName(p, pCol);
114082
114083 if( pType->n==0 ){
114084 /* If there is no type specified, columns have the default affinity
114085 ** 'BLOB' with a default size of 4 bytes. */
114086 pCol->affinity = SQLITE_AFF_BLOB;
114087 pCol->szEst = 1;
 
114088 #ifdef SQLITE_ENABLE_SORTER_REFERENCES
114089 if( 4>=sqlite3GlobalConfig.szSorterRef ){
114090 pCol->colFlags |= COLFLAG_SORTERREF;
 
 
114091 }
114092 #endif
114093 }else{
114094 zType = z + sqlite3Strlen30(z) + 1;
114095 memcpy(zType, pType->z, pType->n);
114096 zType[pType->n] = 0;
114097 sqlite3Dequote(zType);
114098 pCol->affinity = sqlite3AffinityType(zType, pCol);
114099 pCol->colFlags |= COLFLAG_HASTYPE;
114100 }
114101 p->nCol++;
@@ -114246,11 +114109,11 @@
114246 if( p!=0 ){
114247 int isInit = db->init.busy && db->init.iDb!=1;
114248 pCol = &(p->aCol[p->nCol-1]);
114249 if( !sqlite3ExprIsConstantOrFunction(pExpr, isInit) ){
114250 sqlite3ErrorMsg(pParse, "default value of column [%s] is not constant",
114251 pCol->zName);
114252 #ifndef SQLITE_OMIT_GENERATED_COLUMNS
114253 }else if( pCol->colFlags & COLFLAG_GENERATED ){
114254 testcase( pCol->colFlags & COLFLAG_VIRTUAL );
114255 testcase( pCol->colFlags & COLFLAG_STORED );
114256 sqlite3ErrorMsg(pParse, "cannot use DEFAULT on a generated column");
@@ -114257,19 +114120,19 @@
114257 #endif
114258 }else{
114259 /* A copy of pExpr is used instead of the original, as pExpr contains
114260 ** tokens that point to volatile memory.
114261 */
114262 Expr x;
114263 sqlite3ExprDelete(db, pCol->pDflt);
114264 memset(&x, 0, sizeof(x));
114265 x.op = TK_SPAN;
114266 x.u.zToken = sqlite3DbSpanDup(db, zStart, zEnd);
114267 x.pLeft = pExpr;
114268 x.flags = EP_Skip;
114269 pCol->pDflt = sqlite3ExprDup(db, &x, EXPRDUP_REDUCE);
114270 sqlite3DbFree(db, x.u.zToken);
 
114271 }
114272 }
114273 if( IN_RENAME_OBJECT ){
114274 sqlite3RenameExprUnmap(pParse, pExpr);
114275 }
@@ -114363,11 +114226,11 @@
114363 assert( pCExpr!=0 );
114364 sqlite3StringToId(pCExpr);
114365 if( pCExpr->op==TK_ID ){
114366 const char *zCName = pCExpr->u.zToken;
114367 for(iCol=0; iCol<pTab->nCol; iCol++){
114368 if( sqlite3StrICmp(zCName, pTab->aCol[iCol].zName)==0 ){
114369 pCol = &pTab->aCol[iCol];
114370 makeColumnPartOfPrimaryKey(pParse, pCol);
114371 break;
114372 }
114373 }
@@ -114374,11 +114237,11 @@
114374 }
114375 }
114376 }
114377 if( nTerm==1
114378 && pCol
114379 && sqlite3StrICmp(sqlite3ColumnType(pCol,""), "INTEGER")==0
114380 && sortOrder!=SQLITE_SO_DESC
114381 ){
114382 if( IN_RENAME_OBJECT && pList ){
114383 Expr *pCExpr = sqlite3ExprSkipCollate(pList->a[0].pExpr);
114384 sqlite3RenameTokenRemap(pParse, &pTab->iPKey, pCExpr);
@@ -114454,26 +114317,24 @@
114454 zColl = sqlite3NameFromToken(db, pToken);
114455 if( !zColl ) return;
114456
114457 if( sqlite3LocateCollSeq(pParse, zColl) ){
114458 Index *pIdx;
114459 sqlite3DbFree(db, p->aCol[i].zColl);
114460 p->aCol[i].zColl = zColl;
114461
114462 /* If the column is declared as "<name> PRIMARY KEY COLLATE <type>",
114463 ** then an index may have been created on this column before the
114464 ** collation type was added. Correct this if it is the case.
114465 */
114466 for(pIdx=p->pIndex; pIdx; pIdx=pIdx->pNext){
114467 assert( pIdx->nKeyCol==1 );
114468 if( pIdx->aiColumn[0]==i ){
114469 pIdx->azColl[0] = p->aCol[i].zColl;
114470 }
114471 }
114472 }else{
114473 sqlite3DbFree(db, zColl);
114474 }
 
114475 }
114476
114477 /* Change the most recently parsed column to be a GENERATED ALWAYS AS
114478 ** column.
114479 */
@@ -114489,11 +114350,11 @@
114489 pCol = &(pTab->aCol[pTab->nCol-1]);
114490 if( IN_DECLARE_VTAB ){
114491 sqlite3ErrorMsg(pParse, "virtual tables cannot use computed columns");
114492 goto generated_done;
114493 }
114494 if( pCol->pDflt ) goto generated_error;
114495 if( pType ){
114496 if( pType->n==7 && sqlite3StrNICmp("virtual",pType->z,7)==0 ){
114497 /* no-op */
114498 }else if( pType->n==6 && sqlite3StrNICmp("stored",pType->z,6)==0 ){
114499 eType = COLFLAG_STORED;
@@ -114507,17 +114368,17 @@
114507 assert( TF_HasStored==COLFLAG_STORED );
114508 pTab->tabFlags |= eType;
114509 if( pCol->colFlags & COLFLAG_PRIMKEY ){
114510 makeColumnPartOfPrimaryKey(pParse, pCol); /* For the error message */
114511 }
114512 pCol->pDflt = pExpr;
114513 pExpr = 0;
114514 goto generated_done;
114515
114516 generated_error:
114517 sqlite3ErrorMsg(pParse, "error in generated column \"%s\"",
114518 pCol->zName);
114519 generated_done:
114520 sqlite3ExprDelete(pParse->db, pExpr);
114521 #else
114522 /* Throw and error for the GENERATED ALWAYS AS clause if the
114523 ** SQLITE_OMIT_GENERATED_COLUMNS compile-time option is used. */
@@ -114615,11 +114476,11 @@
114615 char *zStmt;
114616 char *zSep, *zSep2, *zEnd;
114617 Column *pCol;
114618 n = 0;
114619 for(pCol = p->aCol, i=0; i<p->nCol; i++, pCol++){
114620 n += identLength(pCol->zName) + 5;
114621 }
114622 n += identLength(p->zName);
114623 if( n<50 ){
114624 zSep = "";
114625 zSep2 = ",";
@@ -114651,11 +114512,11 @@
114651 const char *zType;
114652
114653 sqlite3_snprintf(n-k, &zStmt[k], zSep);
114654 k += sqlite3Strlen30(&zStmt[k]);
114655 zSep = zSep2;
114656 identPut(zStmt, &k, pCol->zName);
114657 assert( pCol->affinity-SQLITE_AFF_BLOB >= 0 );
114658 assert( pCol->affinity-SQLITE_AFF_BLOB < ArraySize(azType) );
114659 testcase( pCol->affinity==SQLITE_AFF_BLOB );
114660 testcase( pCol->affinity==SQLITE_AFF_TEXT );
114661 testcase( pCol->affinity==SQLITE_AFF_NUMERIC );
@@ -114870,11 +114731,11 @@
114870 ** an INTEGER PRIMARY KEY table, create a new PRIMARY KEY index.
114871 */
114872 if( pTab->iPKey>=0 ){
114873 ExprList *pList;
114874 Token ipkToken;
114875 sqlite3TokenInit(&ipkToken, pTab->aCol[pTab->iPKey].zName);
114876 pList = sqlite3ExprListAppend(pParse, 0,
114877 sqlite3ExprAlloc(db, TK_ID, &ipkToken, 0));
114878 if( pList==0 ){
114879 pTab->tabFlags &= ~TF_WithoutRowid;
114880 return;
@@ -115000,11 +114861,11 @@
115000
115001 if( !IsVirtual(pTab) ) return 0;
115002 nName = sqlite3Strlen30(pTab->zName);
115003 if( sqlite3_strnicmp(zName, pTab->zName, nName)!=0 ) return 0;
115004 if( zName[nName]!='_' ) return 0;
115005 pMod = (Module*)sqlite3HashFind(&db->aModule, pTab->azModuleArg[0]);
115006 if( pMod==0 ) return 0;
115007 if( pMod->pModule->iVersion<3 ) return 0;
115008 if( pMod->pModule->xShadowName==0 ) return 0;
115009 return pMod->pModule->xShadowName(zName+nName+1);
115010 }
@@ -115161,22 +115022,22 @@
115161 testcase( p->tabFlags & TF_HasVirtual );
115162 testcase( p->tabFlags & TF_HasStored );
115163 for(ii=0; ii<p->nCol; ii++){
115164 u32 colFlags = p->aCol[ii].colFlags;
115165 if( (colFlags & COLFLAG_GENERATED)!=0 ){
115166 Expr *pX = p->aCol[ii].pDflt;
115167 testcase( colFlags & COLFLAG_VIRTUAL );
115168 testcase( colFlags & COLFLAG_STORED );
115169 if( sqlite3ResolveSelfReference(pParse, p, NC_GenCol, pX, 0) ){
115170 /* If there are errors in resolving the expression, change the
115171 ** expression to a NULL. This prevents code generators that operate
115172 ** on the expression from inserting extra parts into the expression
115173 ** tree that have been allocated from lookaside memory, which is
115174 ** illegal in a schema and will lead to errors or heap corruption
115175 ** when the database connection closes. */
115176 sqlite3ExprDelete(db, pX);
115177 p->aCol[ii].pDflt = sqlite3ExprAlloc(db, TK_NULL, 0, 0);
115178 }
115179 }else{
115180 nNG++;
115181 }
115182 }
@@ -115212,11 +115073,11 @@
115212 sqlite3VdbeAddOp1(v, OP_Close, 0);
115213
115214 /*
115215 ** Initialize zType for the new view or table.
115216 */
115217 if( p->pSelect==0 ){
115218 /* A regular table */
115219 zType = "table";
115220 zType2 = "TABLE";
115221 #ifndef SQLITE_OMIT_VIEW
115222 }else{
@@ -115362,16 +115223,16 @@
115362 }
115363 #endif
115364 }
115365
115366 #ifndef SQLITE_OMIT_ALTERTABLE
115367 if( !pSelect && !p->pSelect ){
115368 assert( pCons && pEnd );
115369 if( pCons->z==0 ){
115370 pCons = pEnd;
115371 }
115372 p->addColOffset = 13 + (int)(pCons->z - pParse->sNameToken.z);
115373 }
115374 #endif
115375 }
115376
115377 #ifndef SQLITE_OMIT_VIEW
@@ -115424,16 +115285,17 @@
115424 ** allocated rather than point to the input string - which means that
115425 ** they will persist after the current sqlite3_exec() call returns.
115426 */
115427 pSelect->selFlags |= SF_View;
115428 if( IN_RENAME_OBJECT ){
115429 p->pSelect = pSelect;
115430 pSelect = 0;
115431 }else{
115432 p->pSelect = sqlite3SelectDup(db, pSelect, EXPRDUP_REDUCE);
115433 }
115434 p->pCheck = sqlite3ExprListDup(db, pCNames, EXPRDUP_REDUCE);
 
115435 if( db->mallocFailed ) goto create_view_fail;
115436
115437 /* Locate the end of the CREATE VIEW statement. Make sEnd point to
115438 ** the end.
115439 */
@@ -115526,12 +115388,12 @@
115526 ** "*" elements in the results set of the view and will assign cursors
115527 ** to the elements of the FROM clause. But we do not want these changes
115528 ** to be permanent. So the computation is done on a copy of the SELECT
115529 ** statement that defines the view.
115530 */
115531 assert( pTable->pSelect );
115532 pSel = sqlite3SelectDup(db, pTable->pSelect, 0);
115533 if( pSel ){
115534 u8 eParseMode = pParse->eParseMode;
115535 pParse->eParseMode = PARSE_MODE_NORMAL;
115536 n = pParse->nTab;
115537 sqlite3SrcListAssignCursors(pParse, pSel->pSrc);
@@ -115586,12 +115448,10 @@
115586 nErr++;
115587 }
115588 pTable->pSchema->schemaFlags |= DB_UnresetViews;
115589 if( db->mallocFailed ){
115590 sqlite3DeleteColumnNames(db, pTable);
115591 pTable->aCol = 0;
115592 pTable->nCol = 0;
115593 }
115594 #endif /* SQLITE_OMIT_VIEW */
115595 return nErr;
115596 }
115597 #endif /* !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_VIRTUALTABLE) */
@@ -115604,14 +115464,12 @@
115604 HashElem *i;
115605 assert( sqlite3SchemaMutexHeld(db, idx, 0) );
115606 if( !DbHasProperty(db, idx, DB_UnresetViews) ) return;
115607 for(i=sqliteHashFirst(&db->aDb[idx].pSchema->tblHash); i;i=sqliteHashNext(i)){
115608 Table *pTab = sqliteHashData(i);
115609 if( pTab->pSelect ){
115610 sqlite3DeleteColumnNames(db, pTab);
115611 pTab->aCol = 0;
115612 pTab->nCol = 0;
115613 }
115614 }
115615 DbClearProperty(db, idx, DB_UnresetViews);
115616 }
115617 #else
@@ -115948,15 +115806,15 @@
115948
115949 #ifndef SQLITE_OMIT_VIEW
115950 /* Ensure DROP TABLE is not used on a view, and DROP VIEW is not used
115951 ** on a table.
115952 */
115953 if( isView && pTab->pSelect==0 ){
115954 sqlite3ErrorMsg(pParse, "use DROP TABLE to delete table %s", pTab->zName);
115955 goto exit_drop_table;
115956 }
115957 if( !isView && pTab->pSelect ){
115958 sqlite3ErrorMsg(pParse, "use DROP VIEW to delete view %s", pTab->zName);
115959 goto exit_drop_table;
115960 }
115961 #endif
115962
@@ -116016,11 +115874,11 @@
116016 int iCol = p->nCol-1;
116017 if( NEVER(iCol<0) ) goto fk_end;
116018 if( pToCol && pToCol->nExpr!=1 ){
116019 sqlite3ErrorMsg(pParse, "foreign key on %s"
116020 " should reference only one column of table %T",
116021 p->aCol[iCol].zName, pTo);
116022 goto fk_end;
116023 }
116024 nCol = 1;
116025 }else if( pToCol && pToCol->nExpr!=pFromCol->nExpr ){
116026 sqlite3ErrorMsg(pParse,
@@ -116039,11 +115897,11 @@
116039 pFKey = sqlite3DbMallocZero(db, nByte );
116040 if( pFKey==0 ){
116041 goto fk_end;
116042 }
116043 pFKey->pFrom = p;
116044 pFKey->pNextFrom = p->pFKey;
116045 z = (char*)&pFKey->aCol[nCol];
116046 pFKey->zTo = z;
116047 if( IN_RENAME_OBJECT ){
116048 sqlite3RenameTokenMap(pParse, (void*)z, pTo);
116049 }
@@ -116056,11 +115914,11 @@
116056 pFKey->aCol[0].iFrom = p->nCol-1;
116057 }else{
116058 for(i=0; i<nCol; i++){
116059 int j;
116060 for(j=0; j<p->nCol; j++){
116061 if( sqlite3StrICmp(p->aCol[j].zName, pFromCol->a[i].zEName)==0 ){
116062 pFKey->aCol[i].iFrom = j;
116063 break;
116064 }
116065 }
116066 if( j>=p->nCol ){
@@ -116104,11 +115962,12 @@
116104 pNextTo->pPrevTo = pFKey;
116105 }
116106
116107 /* Link the foreign key to the table as the last step.
116108 */
116109 p->pFKey = pFKey;
 
116110 pFKey = 0;
116111
116112 fk_end:
116113 sqlite3DbFree(db, pFKey);
116114 #endif /* !defined(SQLITE_OMIT_FOREIGN_KEY) */
@@ -116125,11 +115984,13 @@
116125 */
116126 SQLITE_PRIVATE void sqlite3DeferForeignKey(Parse *pParse, int isDeferred){
116127 #ifndef SQLITE_OMIT_FOREIGN_KEY
116128 Table *pTab;
116129 FKey *pFKey;
116130 if( (pTab = pParse->pNewTable)==0 || (pFKey = pTab->pFKey)==0 ) return;
 
 
116131 assert( isDeferred==0 || isDeferred==1 ); /* EV: R-30323-21917 */
116132 pFKey->isDeferred = (u8)isDeferred;
116133 #endif
116134 }
116135
@@ -116417,11 +116278,11 @@
116417 ){
116418 sqlite3ErrorMsg(pParse, "table %s may not be indexed", pTab->zName);
116419 goto exit_create_index;
116420 }
116421 #ifndef SQLITE_OMIT_VIEW
116422 if( pTab->pSelect ){
116423 sqlite3ErrorMsg(pParse, "views may not be indexed");
116424 goto exit_create_index;
116425 }
116426 #endif
116427 #ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -116508,11 +116369,11 @@
116508 */
116509 if( pList==0 ){
116510 Token prevCol;
116511 Column *pCol = &pTab->aCol[pTab->nCol-1];
116512 pCol->colFlags |= COLFLAG_UNIQUE;
116513 sqlite3TokenInit(&prevCol, pCol->zName);
116514 pList = sqlite3ExprListAppend(pParse, 0,
116515 sqlite3ExprAlloc(db, TK_ID, &prevCol, 0));
116516 if( pList==0 ) goto exit_create_index;
116517 assert( pList->nExpr==1 );
116518 sqlite3ExprListSetSortOrder(pList, sortOrder, SQLITE_SO_UNDEFINED);
@@ -116629,11 +116490,11 @@
116629 memcpy(zExtra, zColl, nColl);
116630 zColl = zExtra;
116631 zExtra += nColl;
116632 nExtra -= nColl;
116633 }else if( j>=0 ){
116634 zColl = pTab->aCol[j].zColl;
116635 }
116636 if( !zColl ) zColl = sqlite3StrBINARY;
116637 if( !db->init.busy && !sqlite3LocateCollSeq(pParse, zColl) ){
116638 goto exit_create_index;
116639 }
@@ -117721,11 +117582,11 @@
117721 sqlite3_str_appendf(&errMsg, "index '%q'", pIdx->zName);
117722 }else{
117723 for(j=0; j<pIdx->nKeyCol; j++){
117724 char *zCol;
117725 assert( pIdx->aiColumn[j]>=0 );
117726 zCol = pTab->aCol[pIdx->aiColumn[j]].zName;
117727 if( j ) sqlite3_str_append(&errMsg, ", ", 2);
117728 sqlite3_str_appendall(&errMsg, pTab->zName);
117729 sqlite3_str_append(&errMsg, ".", 1);
117730 sqlite3_str_appendall(&errMsg, zCol);
117731 }
@@ -117748,11 +117609,11 @@
117748 ){
117749 char *zMsg;
117750 int rc;
117751 if( pTab->iPKey>=0 ){
117752 zMsg = sqlite3MPrintf(pParse->db, "%s.%s", pTab->zName,
117753 pTab->aCol[pTab->iPKey].zName);
117754 rc = SQLITE_CONSTRAINT_PRIMARYKEY;
117755 }else{
117756 zMsg = sqlite3MPrintf(pParse->db, "%s.rowid", pTab->zName);
117757 rc = SQLITE_CONSTRAINT_ROWID;
117758 }
@@ -118675,11 +118536,11 @@
118675 if( tabIsReadOnly(pParse, pTab) ){
118676 sqlite3ErrorMsg(pParse, "table %s may not be modified", pTab->zName);
118677 return 1;
118678 }
118679 #ifndef SQLITE_OMIT_VIEW
118680 if( !viewOk && pTab->pSelect ){
118681 sqlite3ErrorMsg(pParse,"cannot modify %s because it is a view",pTab->zName);
118682 return 1;
118683 }
118684 #endif
118685 return 0;
@@ -118779,17 +118640,17 @@
118779 pParse, 0, sqlite3PExpr(pParse, TK_ROW, 0, 0)
118780 );
118781 }else{
118782 Index *pPk = sqlite3PrimaryKeyIndex(pTab);
118783 if( pPk->nKeyCol==1 ){
118784 const char *zName = pTab->aCol[pPk->aiColumn[0]].zName;
118785 pLhs = sqlite3Expr(db, TK_ID, zName);
118786 pEList = sqlite3ExprListAppend(pParse, 0, sqlite3Expr(db, TK_ID, zName));
118787 }else{
118788 int i;
118789 for(i=0; i<pPk->nKeyCol; i++){
118790 Expr *p = sqlite3Expr(db, TK_ID, pTab->aCol[pPk->aiColumn[i]].zName);
118791 pEList = sqlite3ExprListAppend(pParse, pEList, p);
118792 }
118793 pLhs = sqlite3PExpr(pParse, TK_VECTOR, 0, 0);
118794 if( pLhs ){
118795 pLhs->x.pList = sqlite3ExprListDup(db, pEList, 0);
@@ -118892,11 +118753,11 @@
118892 /* Figure out if we have any triggers and if the table being
118893 ** deleted from is a view
118894 */
118895 #ifndef SQLITE_OMIT_TRIGGER
118896 pTrigger = sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0, 0);
118897 isView = pTab->pSelect!=0;
118898 #else
118899 # define pTrigger 0
118900 # define isView 0
118901 #endif
118902 bComplex = pTrigger || sqlite3FkRequired(pParse, pTab, 0, 0);
@@ -119142,11 +119003,11 @@
119142 ** where-clause loop above.
119143 */
119144 if( eOnePass!=ONEPASS_OFF ){
119145 assert( nKey==nPk ); /* OP_Found will use an unpacked key */
119146 if( !IsVirtual(pTab) && aToOpen[iDataCur-iTabCur] ){
119147 assert( pPk!=0 || pTab->pSelect!=0 );
119148 sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, addrBypass, iKey, nKey);
119149 VdbeCoverage(v);
119150 }
119151 }else if( pPk ){
119152 addrLoop = sqlite3VdbeAddOp1(v, OP_Rewind, iEphCur); VdbeCoverage(v);
@@ -119376,11 +119237,11 @@
119376 ** invoke the update-hook. The pre-update-hook, on the other hand should
119377 ** be invoked unless table pTab is a system table. The difference is that
119378 ** the update-hook is not invoked for rows removed by REPLACE, but the
119379 ** pre-update-hook is.
119380 */
119381 if( pTab->pSelect==0 ){
119382 u8 p5 = 0;
119383 sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur,0,iIdxNoSeek);
119384 sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, (count?OPFLAG_NCHANGE:0));
119385 if( pParse->nested==0 || 0==sqlite3_stricmp(pTab->zName, "sqlite_stat1") ){
119386 sqlite3VdbeAppendP4(v, (char*)pTab, P4_TABLE);
@@ -122070,11 +121931,13 @@
122070 ** 2) The FK is explicitly mapped to a column declared as INTEGER
122071 ** PRIMARY KEY.
122072 */
122073 if( pParent->iPKey>=0 ){
122074 if( !zKey ) return 0;
122075 if( !sqlite3StrICmp(pParent->aCol[pParent->iPKey].zName, zKey) ) return 0;
 
 
122076 }
122077 }else if( paiCol ){
122078 assert( nCol>1 );
122079 aiCol = (int *)sqlite3DbMallocRawNN(pParse->db, nCol*sizeof(int));
122080 if( !aiCol ) return 1;
@@ -122112,15 +121975,15 @@
122112 if( iCol<0 ) break; /* No foreign keys against expression indexes */
122113
122114 /* If the index uses a collation sequence that is different from
122115 ** the default collation sequence for the column, this index is
122116 ** unusable. Bail out early in this case. */
122117 zDfltColl = pParent->aCol[iCol].zColl;
122118 if( !zDfltColl ) zDfltColl = sqlite3StrBINARY;
122119 if( sqlite3StrICmp(pIdx->azColl[i], zDfltColl) ) break;
122120
122121 zIdxCol = pParent->aCol[iCol].zName;
122122 for(j=0; j<nCol; j++){
122123 if( sqlite3StrICmp(pFKey->aCol[j].zCol, zIdxCol)==0 ){
122124 if( aiCol ) aiCol[i] = pFKey->aCol[j].iFrom;
122125 break;
122126 }
@@ -122340,11 +122203,11 @@
122340 if( pExpr ){
122341 if( iCol>=0 && iCol!=pTab->iPKey ){
122342 pCol = &pTab->aCol[iCol];
122343 pExpr->iTable = regBase + sqlite3TableColumnToStorage(pTab,iCol) + 1;
122344 pExpr->affExpr = pCol->affinity;
122345 zColl = pCol->zColl;
122346 if( zColl==0 ) zColl = db->pDfltColl->zName;
122347 pExpr = sqlite3ExprAddCollateString(pParse, pExpr, zColl);
122348 }else{
122349 pExpr->iTable = regBase;
122350 pExpr->affExpr = SQLITE_AFF_INTEGER;
@@ -122449,11 +122312,11 @@
122449
122450 iCol = pIdx ? pIdx->aiColumn[i] : -1;
122451 pLeft = exprTableRegister(pParse, pTab, regData, iCol);
122452 iCol = aiCol ? aiCol[i] : pFKey->aCol[0].iFrom;
122453 assert( iCol>=0 );
122454 zCol = pFKey->pFrom->aCol[iCol].zName;
122455 pRight = sqlite3Expr(db, TK_ID, zCol);
122456 pEq = sqlite3PExpr(pParse, TK_EQ, pLeft, pRight);
122457 pWhere = sqlite3ExprAnd(pParse, pWhere, pEq);
122458 }
122459
@@ -122484,11 +122347,11 @@
122484 assert( pIdx!=0 );
122485 for(i=0; i<pIdx->nKeyCol; i++){
122486 i16 iCol = pIdx->aiColumn[i];
122487 assert( iCol>=0 );
122488 pLeft = exprTableRegister(pParse, pTab, regData, iCol);
122489 pRight = sqlite3Expr(db, TK_ID, pTab->aCol[iCol].zName);
122490 pEq = sqlite3PExpr(pParse, TK_IS, pLeft, pRight);
122491 pAll = sqlite3ExprAnd(pParse, pAll, pEq);
122492 }
122493 pNe = sqlite3PExpr(pParse, TK_NOT, pAll, 0);
122494 }
@@ -122578,19 +122441,20 @@
122578 if( (db->flags&SQLITE_ForeignKeys) && !IsVirtual(pTab) ){
122579 int iSkip = 0;
122580 Vdbe *v = sqlite3GetVdbe(pParse);
122581
122582 assert( v ); /* VDBE has already been allocated */
122583 assert( pTab->pSelect==0 ); /* Not a view */
 
122584 if( sqlite3FkReferences(pTab)==0 ){
122585 /* Search for a deferred foreign key constraint for which this table
122586 ** is the child table. If one cannot be found, return without
122587 ** generating any VDBE code. If one can be found, then jump over
122588 ** the entire DELETE if there are no outstanding deferred constraints
122589 ** when this statement is run. */
122590 FKey *p;
122591 for(p=pTab->pFKey; p; p=p->pNextFrom){
122592 if( p->isDeferred || (db->flags & SQLITE_DeferFKs) ) break;
122593 }
122594 if( !p ) return;
122595 iSkip = sqlite3VdbeMakeLabel(pParse);
122596 sqlite3VdbeAddOp2(v, OP_FkIfZero, 1, iSkip); VdbeCoverage(v);
@@ -122675,11 +122539,11 @@
122675 int iKey;
122676 for(iKey=0; iKey<pTab->nCol; iKey++){
122677 if( aChange[iKey]>=0 || (iKey==pTab->iPKey && bChngRowid) ){
122678 Column *pCol = &pTab->aCol[iKey];
122679 if( zKey ){
122680 if( 0==sqlite3StrICmp(pCol->zName, zKey) ) return 1;
122681 }else if( pCol->colFlags & COLFLAG_PRIMKEY ){
122682 return 1;
122683 }
122684 }
122685 }
@@ -122748,11 +122612,12 @@
122748 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
122749 zDb = db->aDb[iDb].zDbSName;
122750
122751 /* Loop through all the foreign key constraints for which pTab is the
122752 ** child table (the table that the foreign key definition is part of). */
122753 for(pFKey=pTab->pFKey; pFKey; pFKey=pFKey->pNextFrom){
 
122754 Table *pTo; /* Parent table of foreign key pFKey */
122755 Index *pIdx = 0; /* Index on key columns in pTo */
122756 int *aiFree = 0;
122757 int *aiCol;
122758 int iCol;
@@ -122815,11 +122680,11 @@
122815 /* Request permission to read the parent key columns. If the
122816 ** authorization callback returns SQLITE_IGNORE, behave as if any
122817 ** values read from the parent table are NULL. */
122818 if( db->xAuth ){
122819 int rcauth;
122820 char *zCol = pTo->aCol[pIdx ? pIdx->aiColumn[i] : pTo->iPKey].zName;
122821 rcauth = sqlite3AuthReadCol(pParse, pTo->zName, zCol, iDb);
122822 bIgnore = (rcauth==SQLITE_IGNORE);
122823 }
122824 #endif
122825 }
@@ -122933,11 +122798,12 @@
122933 ){
122934 u32 mask = 0;
122935 if( pParse->db->flags&SQLITE_ForeignKeys ){
122936 FKey *p;
122937 int i;
122938 for(p=pTab->pFKey; p; p=p->pNextFrom){
 
122939 for(i=0; i<p->nCol; i++) mask |= COLUMN_MASK(p->aCol[i].iFrom);
122940 }
122941 for(p=sqlite3FkReferences(pTab); p; p=p->pNextTo){
122942 Index *pIdx = 0;
122943 sqlite3FkLocateIndex(pParse, pTab, p, &pIdx, 0);
@@ -122983,23 +122849,23 @@
122983 int *aChange, /* Non-NULL for UPDATE operations */
122984 int chngRowid /* True for UPDATE that affects rowid */
122985 ){
122986 int eRet = 1; /* Value to return if bHaveFK is true */
122987 int bHaveFK = 0; /* If FK processing is required */
122988 if( pParse->db->flags&SQLITE_ForeignKeys ){
122989 if( !aChange ){
122990 /* A DELETE operation. Foreign key processing is required if the
122991 ** table in question is either the child or parent table for any
122992 ** foreign key constraint. */
122993 bHaveFK = (sqlite3FkReferences(pTab) || pTab->pFKey);
122994 }else{
122995 /* This is an UPDATE. Foreign key processing is only required if the
122996 ** operation modifies one or more child or parent key columns. */
122997 FKey *p;
122998
122999 /* Check if any child key columns are being modified. */
123000 for(p=pTab->pFKey; p; p=p->pNextFrom){
123001 if( fkChildIsModified(pTab, p, aChange, chngRowid) ){
123002 if( 0==sqlite3_stricmp(pTab->zName, p->zTo) ) eRet = 2;
123003 bHaveFK = 1;
123004 }
123005 }
@@ -123088,12 +122954,12 @@
123088 iFromCol = aiCol ? aiCol[i] : pFKey->aCol[0].iFrom;
123089 assert( iFromCol>=0 );
123090 assert( pIdx!=0 || (pTab->iPKey>=0 && pTab->iPKey<pTab->nCol) );
123091 assert( pIdx==0 || pIdx->aiColumn[i]>=0 );
123092 sqlite3TokenInit(&tToCol,
123093 pTab->aCol[pIdx ? pIdx->aiColumn[i] : pTab->iPKey].zName);
123094 sqlite3TokenInit(&tFromCol, pFKey->pFrom->aCol[iFromCol].zName);
123095
123096 /* Create the expression "OLD.zToCol = zFromCol". It is important
123097 ** that the "OLD.zToCol" term is on the LHS of the = operator, so
123098 ** that the affinity and collation sequence associated with the
123099 ** parent table are used for the comparison. */
@@ -123134,11 +123000,11 @@
123134 if( pCol->colFlags & COLFLAG_GENERATED ){
123135 testcase( pCol->colFlags & COLFLAG_VIRTUAL );
123136 testcase( pCol->colFlags & COLFLAG_STORED );
123137 pDflt = 0;
123138 }else{
123139 pDflt = pCol->pDflt;
123140 }
123141 if( pDflt ){
123142 pNew = sqlite3ExprDup(db, pDflt, 0);
123143 }else{
123144 pNew = sqlite3ExprAlloc(db, TK_NULL, 0, 0);
@@ -123271,13 +123137,13 @@
123271 */
123272 SQLITE_PRIVATE void sqlite3FkDelete(sqlite3 *db, Table *pTab){
123273 FKey *pFKey; /* Iterator variable */
123274 FKey *pNext; /* Copy of pFKey->pNextFrom */
123275
123276 assert( db==0 || IsVirtual(pTab)
123277 || sqlite3SchemaMutexHeld(db, 0, pTab->pSchema) );
123278 for(pFKey=pTab->pFKey; pFKey; pFKey=pNext){
123279
123280 /* Remove the FK from the fkeyHash hash table. */
123281 if( !db || db->pnBytesFreed==0 ){
123282 if( pFKey->pPrevTo ){
123283 pFKey->pPrevTo->pNextTo = pFKey->pNextTo;
@@ -123603,26 +123469,26 @@
123603 Column *pCol = pTab->aCol + i;
123604 if( (pCol->colFlags & COLFLAG_NOTAVAIL)!=0 ){
123605 int x;
123606 pCol->colFlags |= COLFLAG_BUSY;
123607 w.eCode = 0;
123608 sqlite3WalkExpr(&w, pCol->pDflt);
123609 pCol->colFlags &= ~COLFLAG_BUSY;
123610 if( w.eCode & COLFLAG_NOTAVAIL ){
123611 pRedo = pCol;
123612 continue;
123613 }
123614 eProgress = 1;
123615 assert( pCol->colFlags & COLFLAG_GENERATED );
123616 x = sqlite3TableColumnToStorage(pTab, i) + iRegStore;
123617 sqlite3ExprCodeGeneratedColumn(pParse, pCol, x);
123618 pCol->colFlags &= ~COLFLAG_NOTAVAIL;
123619 }
123620 }
123621 }while( pRedo && eProgress );
123622 if( pRedo ){
123623 sqlite3ErrorMsg(pParse, "generated column loop on \"%s\"", pRedo->zName);
123624 }
123625 pParse->iSelfTab = 0;
123626 }
123627 #endif /* SQLITE_OMIT_GENERATED_COLUMNS */
123628
@@ -124013,11 +123879,11 @@
124013 /* Figure out if we have any triggers and if the table being
124014 ** inserted into is a view
124015 */
124016 #ifndef SQLITE_OMIT_TRIGGER
124017 pTrigger = sqlite3TriggersExist(pParse, pTab, TK_INSERT, 0, &tmask);
124018 isView = pTab->pSelect!=0;
124019 #else
124020 # define pTrigger 0
124021 # define tmask 0
124022 # define isView 0
124023 #endif
@@ -124104,21 +123970,21 @@
124104 for(i=0; i<pColumn->nId; i++){
124105 pColumn->a[i].idx = -1;
124106 }
124107 for(i=0; i<pColumn->nId; i++){
124108 for(j=0; j<pTab->nCol; j++){
124109 if( sqlite3StrICmp(pColumn->a[i].zName, pTab->aCol[j].zName)==0 ){
124110 pColumn->a[i].idx = j;
124111 if( i!=j ) bIdListInOrder = 0;
124112 if( j==pTab->iPKey ){
124113 ipkColumn = i; assert( !withoutRowid );
124114 }
124115 #ifndef SQLITE_OMIT_GENERATED_COLUMNS
124116 if( pTab->aCol[j].colFlags & (COLFLAG_STORED|COLFLAG_VIRTUAL) ){
124117 sqlite3ErrorMsg(pParse,
124118 "cannot INSERT into generated column \"%s\"",
124119 pTab->aCol[j].zName);
124120 goto insert_cleanup;
124121 }
124122 #endif
124123 break;
124124 }
@@ -124299,11 +124165,11 @@
124299 if( IsVirtual(pTab) ){
124300 sqlite3ErrorMsg(pParse, "UPSERT not implemented for virtual table \"%s\"",
124301 pTab->zName);
124302 goto insert_cleanup;
124303 }
124304 if( pTab->pSelect ){
124305 sqlite3ErrorMsg(pParse, "cannot UPSERT a view");
124306 goto insert_cleanup;
124307 }
124308 if( sqlite3HasExplicitNulls(pParse, pUpsert->pUpsertTarget) ){
124309 goto insert_cleanup;
@@ -124398,26 +124264,32 @@
124398 }
124399 continue;
124400 }else if( pColumn==0 ){
124401 /* Hidden columns that are not explicitly named in the INSERT
124402 ** get there default value */
124403 sqlite3ExprCodeFactorable(pParse, pTab->aCol[i].pDflt, iRegStore);
 
 
124404 continue;
124405 }
124406 }
124407 if( pColumn ){
124408 for(j=0; j<pColumn->nId && pColumn->a[j].idx!=i; j++){}
124409 if( j>=pColumn->nId ){
124410 /* A column not named in the insert column list gets its
124411 ** default value */
124412 sqlite3ExprCodeFactorable(pParse, pTab->aCol[i].pDflt, iRegStore);
 
 
124413 continue;
124414 }
124415 k = j;
124416 }else if( nColumn==0 ){
124417 /* This is INSERT INTO ... DEFAULT VALUES. Load the default value. */
124418 sqlite3ExprCodeFactorable(pParse, pTab->aCol[i].pDflt, iRegStore);
 
 
124419 continue;
124420 }else{
124421 k = i - nHidden;
124422 }
124423
@@ -124928,11 +124800,11 @@
124928
124929 isUpdate = regOldData!=0;
124930 db = pParse->db;
124931 v = pParse->pVdbe;
124932 assert( v!=0 );
124933 assert( pTab->pSelect==0 ); /* This table is not a VIEW */
124934 nCol = pTab->nCol;
124935
124936 /* pPk is the PRIMARY KEY index for WITHOUT ROWID tables and NULL for
124937 ** normal rowid tables. nPkField is the number of key fields in the
124938 ** pPk index or 1 for a rowid table. In other words, nPkField is the
@@ -124979,11 +124851,11 @@
124979 }else if( onError==OE_Default ){
124980 onError = OE_Abort;
124981 }
124982 if( onError==OE_Replace ){
124983 if( b2ndPass /* REPLACE becomes ABORT on the 2nd pass */
124984 || pCol->pDflt==0 /* REPLACE is ABORT if no DEFAULT value */
124985 ){
124986 testcase( pCol->colFlags & COLFLAG_VIRTUAL );
124987 testcase( pCol->colFlags & COLFLAG_STORED );
124988 testcase( pCol->colFlags & COLFLAG_GENERATED );
124989 onError = OE_Abort;
@@ -125001,21 +124873,22 @@
125001 case OE_Replace: {
125002 int addr1 = sqlite3VdbeAddOp1(v, OP_NotNull, iReg);
125003 VdbeCoverage(v);
125004 assert( (pCol->colFlags & COLFLAG_GENERATED)==0 );
125005 nSeenReplace++;
125006 sqlite3ExprCodeCopy(pParse, pCol->pDflt, iReg);
 
125007 sqlite3VdbeJumpHere(v, addr1);
125008 break;
125009 }
125010 case OE_Abort:
125011 sqlite3MayAbort(pParse);
125012 /* no break */ deliberate_fall_through
125013 case OE_Rollback:
125014 case OE_Fail: {
125015 char *zMsg = sqlite3MPrintf(db, "%s.%s", pTab->zName,
125016 pCol->zName);
125017 sqlite3VdbeAddOp3(v, OP_HaltIfNull, SQLITE_CONSTRAINT_NOTNULL,
125018 onError, iReg);
125019 sqlite3VdbeAppendP4(v, zMsg, P4_DYNAMIC);
125020 sqlite3VdbeChangeP5(v, P5_ConstraintNotNull);
125021 VdbeCoverage(v);
@@ -125429,11 +125302,11 @@
125429 VdbeComment((v, "rowid"));
125430 }else{
125431 testcase( sqlite3TableColumnToStorage(pTab, iField)!=iField );
125432 x = sqlite3TableColumnToStorage(pTab, iField) + regNewData + 1;
125433 sqlite3VdbeAddOp2(v, OP_SCopy, x, regIdx+i);
125434 VdbeComment((v, "%s", pTab->aCol[iField].zName));
125435 }
125436 }
125437 sqlite3VdbeAddOp3(v, OP_MakeRecord, regIdx, pIdx->nColumn, aRegIdx[ix]);
125438 VdbeComment((v, "for %s", pIdx->zName));
125439 #ifdef SQLITE_ENABLE_NULL_TRIM
@@ -125488,11 +125361,11 @@
125488 && pPk==pIdx /* Condition 2 */
125489 && onError==OE_Replace /* Condition 1 */
125490 && ( 0==(db->flags&SQLITE_RecTriggers) || /* Condition 4 */
125491 0==sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0, 0))
125492 && ( 0==(db->flags&SQLITE_ForeignKeys) || /* Condition 5 */
125493 (0==pTab->pFKey && 0==sqlite3FkReferences(pTab)))
125494 ){
125495 sqlite3VdbeResolveLabel(v, addrUniqueOk);
125496 continue;
125497 }
125498 #endif /* ifndef SQLITE_ENABLE_PREUPDATE_HOOK */
@@ -125523,11 +125396,11 @@
125523 for(i=0; i<pPk->nKeyCol; i++){
125524 assert( pPk->aiColumn[i]>=0 );
125525 x = sqlite3TableColumnToIndex(pIdx, pPk->aiColumn[i]);
125526 sqlite3VdbeAddOp3(v, OP_Column, iThisCur, x, regR+i);
125527 VdbeComment((v, "%s.%s", pTab->zName,
125528 pTab->aCol[pPk->aiColumn[i]].zName));
125529 }
125530 }
125531 if( isUpdate ){
125532 /* If currently processing the PRIMARY KEY of a WITHOUT ROWID
125533 ** table, only conflict if the new PRIMARY KEY values are actually
@@ -125722,11 +125595,11 @@
125722 /* Records with omitted columns are only allowed for schema format
125723 ** version 2 and later (SQLite version 3.1.4, 2005-02-20). */
125724 if( pTab->pSchema->file_format<2 ) return;
125725
125726 for(i=pTab->nCol-1; i>0; i--){
125727 if( pTab->aCol[i].pDflt!=0 ) break;
125728 if( pTab->aCol[i].colFlags & COLFLAG_PRIMKEY ) break;
125729 }
125730 sqlite3VdbeChangeP5(v, i+1);
125731 }
125732 #endif
@@ -125787,11 +125660,11 @@
125787 || update_flags==(OPFLAG_ISUPDATE|OPFLAG_SAVEPOSITION)
125788 );
125789
125790 v = pParse->pVdbe;
125791 assert( v!=0 );
125792 assert( pTab->pSelect==0 ); /* This table is not a VIEW */
125793 for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
125794 /* All REPLACE indexes are at the end of the list */
125795 assert( pIdx->onError!=OE_Replace
125796 || pIdx->pNext==0
125797 || pIdx->pNext->onError==OE_Replace );
@@ -126089,17 +125962,12 @@
126089 return 0; /* tab1 and tab2 may not be the same table */
126090 }
126091 if( HasRowid(pDest)!=HasRowid(pSrc) ){
126092 return 0; /* source and destination must both be WITHOUT ROWID or not */
126093 }
126094 #ifndef SQLITE_OMIT_VIRTUALTABLE
126095 if( IsVirtual(pSrc) ){
126096 return 0; /* tab2 must not be a virtual table */
126097 }
126098 #endif
126099 if( pSrc->pSelect ){
126100 return 0; /* tab2 may not be a view */
126101 }
126102 if( pDest->nCol!=pSrc->nCol ){
126103 return 0; /* Number of columns must be the same in tab1 and tab2 */
126104 }
126105 if( pDest->iPKey!=pSrc->iPKey ){
@@ -126139,33 +126007,38 @@
126139 /* But the transfer is only allowed if both the source and destination
126140 ** tables have the exact same expressions for generated columns.
126141 ** This requirement could be relaxed for VIRTUAL columns, I suppose.
126142 */
126143 if( (pDestCol->colFlags & COLFLAG_GENERATED)!=0 ){
126144 if( sqlite3ExprCompare(0, pSrcCol->pDflt, pDestCol->pDflt, -1)!=0 ){
 
 
126145 testcase( pDestCol->colFlags & COLFLAG_VIRTUAL );
126146 testcase( pDestCol->colFlags & COLFLAG_STORED );
126147 return 0; /* Different generator expressions */
126148 }
126149 }
126150 #endif
126151 if( pDestCol->affinity!=pSrcCol->affinity ){
126152 return 0; /* Affinity must be the same on all columns */
126153 }
126154 if( sqlite3_stricmp(pDestCol->zColl, pSrcCol->zColl)!=0 ){
 
126155 return 0; /* Collating sequence must be the same on all columns */
126156 }
126157 if( pDestCol->notNull && !pSrcCol->notNull ){
126158 return 0; /* tab2 must be NOT NULL if tab1 is */
126159 }
126160 /* Default values for second and subsequent columns need to match. */
126161 if( (pDestCol->colFlags & COLFLAG_GENERATED)==0 && i>0 ){
126162 assert( pDestCol->pDflt==0 || pDestCol->pDflt->op==TK_SPAN );
126163 assert( pSrcCol->pDflt==0 || pSrcCol->pDflt->op==TK_SPAN );
126164 if( (pDestCol->pDflt==0)!=(pSrcCol->pDflt==0)
126165 || (pDestCol->pDflt && strcmp(pDestCol->pDflt->u.zToken,
126166 pSrcCol->pDflt->u.zToken)!=0)
 
 
126167 ){
126168 return 0; /* Default values must be the same for all columns */
126169 }
126170 }
126171 }
@@ -126198,11 +126071,11 @@
126198 ** But the main beneficiary of the transfer optimization is the VACUUM
126199 ** command, and the VACUUM command disables foreign key constraints. So
126200 ** the extra complication to make this rule less restrictive is probably
126201 ** not worth the effort. Ticket [6284df89debdfa61db8073e062908af0c9b6118e]
126202 */
126203 if( (db->flags & SQLITE_ForeignKeys)!=0 && pDest->pFKey!=0 ){
126204 return 0;
126205 }
126206 #endif
126207 if( (db->flags & SQLITE_CountRows)!=0 ){
126208 return 0; /* xfer opt does not play well with PRAGMA count_changes */
@@ -129888,17 +129761,20 @@
129888 }else if( pPk==0 ){
129889 k = 1;
129890 }else{
129891 for(k=1; k<=pTab->nCol && pPk->aiColumn[k-1]!=i; k++){}
129892 }
129893 assert( pCol->pDflt==0 || pCol->pDflt->op==TK_SPAN || isHidden>=2 );
 
 
129894 sqlite3VdbeMultiLoad(v, 1, pPragma->iArg ? "issisii" : "issisi",
129895 i-nHidden,
129896 pCol->zName,
129897 sqlite3ColumnType(pCol,""),
129898 pCol->notNull ? 1 : 0,
129899 pCol->pDflt && isHidden<2 ? pCol->pDflt->u.zToken : 0,
 
129900 k,
129901 isHidden);
129902 }
129903 }
129904 }
@@ -129961,11 +129837,11 @@
129961 sqlite3CodeVerifySchema(pParse, iIdxDb);
129962 assert( pParse->nMem<=pPragma->nPragCName );
129963 for(i=0; i<mx; i++){
129964 i16 cnum = pIdx->aiColumn[i];
129965 sqlite3VdbeMultiLoad(v, 1, "iisX", i, cnum,
129966 cnum<0 ? 0 : pTab->aCol[cnum].zName);
129967 if( pPragma->iArg ){
129968 sqlite3VdbeMultiLoad(v, 4, "isiX",
129969 pIdx->aSortOrder[i],
129970 pIdx->azColl[i],
129971 i<pIdx->nKeyCol);
@@ -130068,12 +129944,12 @@
130068 #ifndef SQLITE_OMIT_FOREIGN_KEY
130069 case PragTyp_FOREIGN_KEY_LIST: if( zRight ){
130070 FKey *pFK;
130071 Table *pTab;
130072 pTab = sqlite3FindTable(db, zRight, zDb);
130073 if( pTab ){
130074 pFK = pTab->pFKey;
130075 if( pFK ){
130076 int iTabDb = sqlite3SchemaToIndex(db, pTab->pSchema);
130077 int i = 0;
130078 pParse->nMem = 8;
130079 sqlite3CodeVerifySchema(pParse, iTabDb);
@@ -130082,11 +129958,11 @@
130082 for(j=0; j<pFK->nCol; j++){
130083 sqlite3VdbeMultiLoad(v, 1, "iissssss",
130084 i,
130085 j,
130086 pFK->zTo,
130087 pTab->aCol[pFK->aCol[j].iFrom].zName,
130088 pFK->aCol[j].zCol,
130089 actionName(pFK->aAction[1]), /* ON UPDATE */
130090 actionName(pFK->aAction[0]), /* ON DELETE */
130091 "NONE");
130092 }
@@ -130128,19 +130004,20 @@
130128 k = 0;
130129 }else{
130130 pTab = (Table*)sqliteHashData(k);
130131 k = sqliteHashNext(k);
130132 }
130133 if( pTab==0 || pTab->pFKey==0 ) continue;
130134 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
130135 zDb = db->aDb[iDb].zDbSName;
130136 sqlite3CodeVerifySchema(pParse, iDb);
130137 sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
130138 if( pTab->nCol+regRow>pParse->nMem ) pParse->nMem = pTab->nCol + regRow;
130139 sqlite3OpenTable(pParse, 0, iDb, pTab, OP_OpenRead);
130140 sqlite3VdbeLoadString(v, regResult, pTab->zName);
130141 for(i=1, pFK=pTab->pFKey; pFK; i++, pFK=pFK->pNextFrom){
 
130142 pParent = sqlite3FindTable(db, pFK->zTo, zDb);
130143 if( pParent==0 ) continue;
130144 pIdx = 0;
130145 sqlite3TableLock(pParse, iDb, pParent->tnum, 0, pParent->zName);
130146 x = sqlite3FkLocateIndex(pParse, pParent, pFK, &pIdx, 0);
@@ -130158,11 +130035,12 @@
130158 }
130159 assert( pParse->nErr>0 || pFK==0 );
130160 if( pFK ) break;
130161 if( pParse->nTab<i ) pParse->nTab = i;
130162 addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, 0); VdbeCoverage(v);
130163 for(i=1, pFK=pTab->pFKey; pFK; i++, pFK=pFK->pNextFrom){
 
130164 pParent = sqlite3FindTable(db, pFK->zTo, zDb);
130165 pIdx = 0;
130166 aiCols = 0;
130167 if( pParent ){
130168 x = sqlite3FkLocateIndex(pParse, pParent, pFK, &pIdx, &aiCols);
@@ -130393,11 +130271,11 @@
130393 if( sqlite3VdbeGetOp(v,-1)->opcode==OP_Column ){
130394 sqlite3VdbeChangeP5(v, OPFLAG_TYPEOFARG);
130395 }
130396 jmp2 = sqlite3VdbeAddOp1(v, OP_NotNull, 3); VdbeCoverage(v);
130397 zErr = sqlite3MPrintf(db, "NULL value in %s.%s", pTab->zName,
130398 pTab->aCol[j].zName);
130399 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC);
130400 integrityCheckResultRow(v);
130401 sqlite3VdbeJumpHere(v, jmp2);
130402 }
130403 /* Verify CHECK constraints */
@@ -132601,11 +132479,11 @@
132601 SQLITE_PRIVATE int sqlite3ColumnIndex(Table *pTab, const char *zCol){
132602 int i;
132603 u8 h = sqlite3StrIHash(zCol);
132604 Column *pCol;
132605 for(pCol=pTab->aCol, i=0; i<pTab->nCol; pCol++, i++){
132606 if( pCol->hName==h && sqlite3StrICmp(pCol->zName, zCol)==0 ) return i;
132607 }
132608 return -1;
132609 }
132610
132611 /*
@@ -132800,11 +132678,11 @@
132800 char *zName; /* Name of column in the right table */
132801 int iLeft; /* Matching left table */
132802 int iLeftCol; /* Matching column in the left table */
132803
132804 if( IsHiddenColumn(&pRightTab->aCol[j]) ) continue;
132805 zName = pRightTab->aCol[j].zName;
132806 if( tableAndColumnIndex(pSrc, i+1, zName, &iLeft, &iLeftCol, 1) ){
132807 addWhereTerm(pParse, pSrc, iLeft, iLeftCol, i+1, j,
132808 isOuter, &p->pWhere);
132809 }
132810 }
@@ -133203,11 +133081,13 @@
133203 Parse *pParse, /* Parsing and code generating context */
133204 int eTnctType, /* WHERE_DISTINCT_* value */
133205 int iVal, /* Value returned by codeDistinct() */
133206 int iOpenEphAddr /* Address of OP_OpenEphemeral instruction for iTab */
133207 ){
133208 if( eTnctType==WHERE_DISTINCT_UNIQUE || eTnctType==WHERE_DISTINCT_ORDERED ){
 
 
133209 Vdbe *v = pParse->pVdbe;
133210 sqlite3VdbeChangeToNoop(v, iOpenEphAddr);
133211 if( sqlite3VdbeGetOp(v, iOpenEphAddr+1)->opcode==OP_Explain ){
133212 sqlite3VdbeChangeToNoop(v, iOpenEphAddr+1);
133213 }
@@ -134165,11 +134045,11 @@
134165 assert( iCol==XN_ROWID || (iCol>=0 && iCol<pTab->nCol) );
134166 if( iCol<0 ){
134167 zType = "INTEGER";
134168 zOrigCol = "rowid";
134169 }else{
134170 zOrigCol = pTab->aCol[iCol].zName;
134171 zType = sqlite3ColumnType(&pTab->aCol[iCol],0);
134172 }
134173 zOrigTab = pTab->zName;
134174 if( pNC->pParse && pTab->pSchema ){
134175 int iDb = sqlite3SchemaToIndex(pNC->pParse->db, pTab->pSchema);
@@ -134337,11 +134217,11 @@
134337 if( iCol<0 ) iCol = pTab->iPKey;
134338 assert( iCol==-1 || (iCol>=0 && iCol<pTab->nCol) );
134339 if( iCol<0 ){
134340 zCol = "rowid";
134341 }else{
134342 zCol = pTab->aCol[iCol].zName;
134343 }
134344 if( fullName ){
134345 char *zName = 0;
134346 zName = sqlite3MPrintf(db, "%s.%s", pTab->zName, zCol);
134347 sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, SQLITE_DYNAMIC);
@@ -134422,11 +134302,11 @@
134422 }
134423 if( pColExpr->op==TK_COLUMN && (pTab = pColExpr->y.pTab)!=0 ){
134424 /* For columns use the column name name */
134425 int iCol = pColExpr->iColumn;
134426 if( iCol<0 ) iCol = pTab->iPKey;
134427 zName = iCol>=0 ? pTab->aCol[iCol].zName : "rowid";
134428 }else if( pColExpr->op==TK_ID ){
134429 assert( !ExprHasProperty(pColExpr, EP_IntValue) );
134430 zName = pColExpr->u.zToken;
134431 }else{
134432 /* Use the original text of the column expression as its name */
@@ -134450,21 +134330,21 @@
134450 if( zName[j]==':' ) nName = j;
134451 }
134452 zName = sqlite3MPrintf(db, "%.*z:%u", nName, zName, ++cnt);
134453 if( cnt>3 ) sqlite3_randomness(sizeof(cnt), &cnt);
134454 }
134455 pCol->zName = zName;
134456 pCol->hName = sqlite3StrIHash(zName);
134457 sqlite3ColumnPropertiesFromName(0, pCol);
134458 if( zName && sqlite3HashInsert(&ht, zName, pCol)==pCol ){
134459 sqlite3OomFault(db);
134460 }
134461 }
134462 sqlite3HashClear(&ht);
134463 if( db->mallocFailed ){
134464 for(j=0; j<i; j++){
134465 sqlite3DbFree(db, aCol[j].zName);
134466 }
134467 sqlite3DbFree(db, aCol);
134468 *paCol = 0;
134469 *pnCol = 0;
134470 return SQLITE_NOMEM_BKPT;
@@ -134512,21 +134392,22 @@
134512 zType = columnType(&sNC, p, 0, 0, 0);
134513 /* pCol->szEst = ... // Column size est for SELECT tables never used */
134514 pCol->affinity = sqlite3ExprAffinity(p);
134515 if( zType ){
134516 m = sqlite3Strlen30(zType);
134517 n = sqlite3Strlen30(pCol->zName);
134518 pCol->zName = sqlite3DbReallocOrFree(db, pCol->zName, n+m+2);
134519 if( pCol->zName ){
134520 memcpy(&pCol->zName[n+1], zType, m+1);
134521 pCol->colFlags |= COLFLAG_HASTYPE;
134522 }
134523 }
134524 if( pCol->affinity<=SQLITE_AFF_NONE ) pCol->affinity = aff;
134525 pColl = sqlite3ExprCollSeq(pParse, p);
134526 if( pColl && pCol->zColl==0 ){
134527 pCol->zColl = sqlite3DbStrDup(db, pColl->zName);
 
134528 }
134529 }
134530 pTab->szTabRow = 1; /* Any non-zero value works */
134531 }
134532
@@ -137261,11 +137142,11 @@
137261 ){
137262 return 0;
137263 }
137264 pTab = p->pSrc->a[0].pTab;
137265 pExpr = p->pEList->a[0].pExpr;
137266 assert( pTab && !pTab->pSelect && pExpr );
137267
137268 if( IsVirtual(pTab) ) return 0;
137269 if( pExpr->op!=TK_AGG_FUNCTION ) return 0;
137270 if( NEVER(pAggInfo->nFunc==0) ) return 0;
137271 if( (pAggInfo->aFunc[0].pFunc->funcFlags&SQLITE_FUNC_COUNT)==0 ) return 0;
@@ -137806,34 +137687,35 @@
137806 pTab->nTabRef++;
137807 if( !IsVirtual(pTab) && cannotBeFunction(pParse, pFrom) ){
137808 return WRC_Abort;
137809 }
137810 #if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_VIRTUALTABLE)
137811 if( IsVirtual(pTab) || pTab->pSelect ){
137812 i16 nCol;
137813 u8 eCodeOrig = pWalker->eCode;
137814 if( sqlite3ViewGetColumnNames(pParse, pTab) ) return WRC_Abort;
137815 assert( pFrom->pSelect==0 );
137816 if( pTab->pSelect
137817 && (db->flags & SQLITE_EnableView)==0
137818 && pTab->pSchema!=db->aDb[1].pSchema
137819 ){
137820 sqlite3ErrorMsg(pParse, "access to view \"%s\" prohibited",
137821 pTab->zName);
137822 }
 
 
137823 #ifndef SQLITE_OMIT_VIRTUALTABLE
137824 assert( SQLITE_VTABRISK_Normal==1 && SQLITE_VTABRISK_High==2 );
137825 if( IsVirtual(pTab)
137826 && pFrom->fg.fromDDL
137827 && ALWAYS(pTab->pVTable!=0)
137828 && pTab->pVTable->eVtabRisk > ((db->flags & SQLITE_TrustedSchema)!=0)
137829 ){
137830 sqlite3ErrorMsg(pParse, "unsafe use of virtual table \"%s\"",
137831 pTab->zName);
137832 }
 
137833 #endif
137834 pFrom->pSelect = sqlite3SelectDup(db, pTab->pSelect, 0);
137835 nCol = pTab->nCol;
137836 pTab->nCol = -1;
137837 pWalker->eCode = 1; /* Turn on Select.selId renumbering */
137838 sqlite3WalkSelect(pWalker, pFrom->pSelect);
137839 pWalker->eCode = eCodeOrig;
@@ -137929,11 +137811,11 @@
137929 }
137930 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
137931 zSchemaName = iDb>=0 ? db->aDb[iDb].zDbSName : "*";
137932 }
137933 for(j=0; j<pTab->nCol; j++){
137934 char *zName = pTab->aCol[j].zName;
137935 char *zColname; /* The computed column name */
137936 char *zToFree; /* Malloced string that needs to be freed */
137937 Token sColname; /* Computed column name as a token */
137938
137939 assert( zName );
@@ -140214,16 +140096,16 @@
140214 }
140215
140216 /* INSTEAD of triggers are only for views and views only support INSTEAD
140217 ** of triggers.
140218 */
140219 if( pTab->pSelect && tr_tm!=TK_INSTEAD ){
140220 sqlite3ErrorMsg(pParse, "cannot create %s trigger on view: %S",
140221 (tr_tm == TK_BEFORE)?"BEFORE":"AFTER", pTableName->a);
140222 goto trigger_orphan_error;
140223 }
140224 if( !pTab->pSelect && tr_tm==TK_INSTEAD ){
140225 sqlite3ErrorMsg(pParse, "cannot create INSTEAD OF"
140226 " trigger on table: %S", pTableName->a);
140227 goto trigger_orphan_error;
140228 }
140229
@@ -140872,15 +140754,15 @@
140872 if( isAsteriskTerm(pParse, pOldExpr) ){
140873 int jj;
140874 for(jj=0; jj<pTab->nCol; jj++){
140875 Expr *pNewExpr;
140876 if( IsHiddenColumn(pTab->aCol+jj) ) continue;
140877 pNewExpr = sqlite3Expr(db, TK_ID, pTab->aCol[jj].zName);
140878 pNew = sqlite3ExprListAppend(pParse, pNew, pNewExpr);
140879 if( !db->mallocFailed ){
140880 struct ExprList_item *pItem = &pNew->a[pNew->nExpr-1];
140881 pItem->zEName = sqlite3DbStrDup(db, pTab->aCol[jj].zName);
140882 pItem->eEName = ENAME_NAME;
140883 }
140884 }
140885 }else{
140886 Expr *pNewExpr = sqlite3ExprDup(db, pOldExpr, 0);
@@ -141477,17 +141359,18 @@
141477 ** integer. In that case, add an OP_RealAffinity opcode to make sure
141478 ** it has been converted into REAL.
141479 */
141480 SQLITE_PRIVATE void sqlite3ColumnDefault(Vdbe *v, Table *pTab, int i, int iReg){
141481 assert( pTab!=0 );
141482 if( !pTab->pSelect ){
141483 sqlite3_value *pValue = 0;
141484 u8 enc = ENC(sqlite3VdbeDb(v));
141485 Column *pCol = &pTab->aCol[i];
141486 VdbeComment((v, "%s.%s", pTab->zName, pCol->zName));
141487 assert( i<pTab->nCol );
141488 sqlite3ValueFromExpr(sqlite3VdbeDb(v), pCol->pDflt, enc,
 
141489 pCol->affinity, &pValue);
141490 if( pValue ){
141491 sqlite3VdbeAppendP4(v, pValue, P4_MEM);
141492 }
141493 }
@@ -141653,11 +141536,11 @@
141653 }
141654 #endif
141655 pList = sqlite3ExprListAppend(pParse, pList, pNew);
141656 }
141657 eDest = IsVirtual(pTab) ? SRT_Table : SRT_Upfrom;
141658 }else if( pTab->pSelect ){
141659 for(i=0; i<pTab->nCol; i++){
141660 pList = sqlite3ExprListAppend(pParse, pList, exprRowColumn(pParse, i));
141661 }
141662 eDest = SRT_Table;
141663 }else{
@@ -141778,11 +141661,11 @@
141778 /* Figure out if we have any triggers and if the table being
141779 ** updated is a view.
141780 */
141781 #ifndef SQLITE_OMIT_TRIGGER
141782 pTrigger = sqlite3TriggersExist(pParse, pTab, TK_UPDATE, pChanges, &tmask);
141783 isView = pTab->pSelect!=0;
141784 assert( pTrigger || tmask==0 );
141785 #else
141786 # define pTrigger 0
141787 # define isView 0
141788 # define tmask 0
@@ -141867,17 +141750,20 @@
141867 ** column to be updated, make sure we have authorization to change
141868 ** that column.
141869 */
141870 chngRowid = chngPk = 0;
141871 for(i=0; i<pChanges->nExpr; i++){
 
141872 /* If this is an UPDATE with a FROM clause, do not resolve expressions
141873 ** here. The call to sqlite3Select() below will do that. */
141874 if( nChangeFrom==0 && sqlite3ResolveExprNames(&sNC, pChanges->a[i].pExpr) ){
141875 goto update_cleanup;
141876 }
141877 for(j=0; j<pTab->nCol; j++){
141878 if( sqlite3StrICmp(pTab->aCol[j].zName, pChanges->a[i].zEName)==0 ){
 
 
141879 if( j==pTab->iPKey ){
141880 chngRowid = 1;
141881 pRowidExpr = pChanges->a[i].pExpr;
141882 iRowidExpr = i;
141883 }else if( pPk && (pTab->aCol[j].colFlags & COLFLAG_PRIMKEY)!=0 ){
@@ -141887,11 +141773,11 @@
141887 else if( pTab->aCol[j].colFlags & COLFLAG_GENERATED ){
141888 testcase( pTab->aCol[j].colFlags & COLFLAG_VIRTUAL );
141889 testcase( pTab->aCol[j].colFlags & COLFLAG_STORED );
141890 sqlite3ErrorMsg(pParse,
141891 "cannot UPDATE generated column \"%s\"",
141892 pTab->aCol[j].zName);
141893 goto update_cleanup;
141894 }
141895 #endif
141896 aXRef[j] = i;
141897 break;
@@ -141911,11 +141797,11 @@
141911 }
141912 #ifndef SQLITE_OMIT_AUTHORIZATION
141913 {
141914 int rc;
141915 rc = sqlite3AuthCheck(pParse, SQLITE_UPDATE, pTab->zName,
141916 j<0 ? "ROWID" : pTab->aCol[j].zName,
141917 db->aDb[iDb].zDbSName);
141918 if( rc==SQLITE_DENY ){
141919 goto update_cleanup;
141920 }else if( rc==SQLITE_IGNORE ){
141921 aXRef[j] = -1;
@@ -141943,12 +141829,14 @@
141943 do{
141944 bProgress = 0;
141945 for(i=0; i<pTab->nCol; i++){
141946 if( aXRef[i]>=0 ) continue;
141947 if( (pTab->aCol[i].colFlags & COLFLAG_GENERATED)==0 ) continue;
141948 if( sqlite3ExprReferencesUpdatedColumn(pTab->aCol[i].pDflt,
141949 aXRef, chngRowid) ){
 
 
141950 aXRef[i] = 99999;
141951 bProgress = 1;
141952 }
141953 }
141954 }while( bProgress );
@@ -143036,11 +142924,11 @@
143036 int k;
143037 assert( pPk->aiColumn[i]>=0 );
143038 k = sqlite3TableColumnToIndex(pIdx, pPk->aiColumn[i]);
143039 sqlite3VdbeAddOp3(v, OP_Column, iCur, k, iPk+i);
143040 VdbeComment((v, "%s.%s", pIdx->zName,
143041 pTab->aCol[pPk->aiColumn[i]].zName));
143042 }
143043 sqlite3VdbeVerifyAbortable(v, OE_Abort);
143044 i = sqlite3VdbeAddOp4Int(v, OP_Found, iDataCur, 0, iPk, nPk);
143045 VdbeCoverage(v);
143046 sqlite3VdbeAddOp4(v, OP_Halt, SQLITE_CORRUPT, OE_Abort, 0,
@@ -143666,11 +143554,11 @@
143666 ** this virtual-table, if one has been created, or NULL otherwise.
143667 */
143668 SQLITE_PRIVATE VTable *sqlite3GetVTable(sqlite3 *db, Table *pTab){
143669 VTable *pVtab;
143670 assert( IsVirtual(pTab) );
143671 for(pVtab=pTab->pVTable; pVtab && pVtab->db!=db; pVtab=pVtab->pNext);
143672 return pVtab;
143673 }
143674
143675 /*
143676 ** Decrement the ref-count on a virtual table object. When the ref-count
@@ -143694,35 +143582,35 @@
143694 }
143695 }
143696
143697 /*
143698 ** Table p is a virtual table. This function moves all elements in the
143699 ** p->pVTable list to the sqlite3.pDisconnect lists of their associated
143700 ** database connections to be disconnected at the next opportunity.
143701 ** Except, if argument db is not NULL, then the entry associated with
143702 ** connection db is left in the p->pVTable list.
143703 */
143704 static VTable *vtabDisconnectAll(sqlite3 *db, Table *p){
143705 VTable *pRet = 0;
143706 VTable *pVTable = p->pVTable;
143707 p->pVTable = 0;
143708
143709 /* Assert that the mutex (if any) associated with the BtShared database
143710 ** that contains table p is held by the caller. See header comments
143711 ** above function sqlite3VtabUnlockList() for an explanation of why
143712 ** this makes it safe to access the sqlite3.pDisconnect list of any
143713 ** database connection that may have an entry in the p->pVTable list.
143714 */
143715 assert( db==0 || sqlite3SchemaMutexHeld(db, 0, p->pSchema) );
143716
143717 while( pVTable ){
143718 sqlite3 *db2 = pVTable->db;
143719 VTable *pNext = pVTable->pNext;
143720 assert( db2 );
143721 if( db2==db ){
143722 pRet = pVTable;
143723 p->pVTable = pRet;
143724 pRet->pNext = 0;
143725 }else{
143726 pVTable->pNext = db2->pDisconnect;
143727 db2->pDisconnect = pVTable;
143728 }
@@ -143746,11 +143634,11 @@
143746
143747 assert( IsVirtual(p) );
143748 assert( sqlite3BtreeHoldsAllMutexes(db) );
143749 assert( sqlite3_mutex_held(db->mutex) );
143750
143751 for(ppVTab=&p->pVTable; *ppVTab; ppVTab=&(*ppVTab)->pNext){
143752 if( (*ppVTab)->db==db ){
143753 VTable *pVTab = *ppVTab;
143754 *ppVTab = pVTab->pNext;
143755 sqlite3VtabUnlock(pVTab);
143756 break;
@@ -143810,40 +143698,40 @@
143810 ** in the list are moved to the sqlite3.pDisconnect list of the associated
143811 ** database connection.
143812 */
143813 SQLITE_PRIVATE void sqlite3VtabClear(sqlite3 *db, Table *p){
143814 if( !db || db->pnBytesFreed==0 ) vtabDisconnectAll(0, p);
143815 if( p->azModuleArg ){
143816 int i;
143817 for(i=0; i<p->nModuleArg; i++){
143818 if( i!=1 ) sqlite3DbFree(db, p->azModuleArg[i]);
143819 }
143820 sqlite3DbFree(db, p->azModuleArg);
143821 }
143822 }
143823
143824 /*
143825 ** Add a new module argument to pTable->azModuleArg[].
143826 ** The string is not copied - the pointer is stored. The
143827 ** string will be freed automatically when the table is
143828 ** deleted.
143829 */
143830 static void addModuleArgument(Parse *pParse, Table *pTable, char *zArg){
143831 sqlite3_int64 nBytes = sizeof(char *)*(2+pTable->nModuleArg);
143832 char **azModuleArg;
143833 sqlite3 *db = pParse->db;
143834 if( pTable->nModuleArg+3>=db->aLimit[SQLITE_LIMIT_COLUMN] ){
143835 sqlite3ErrorMsg(pParse, "too many columns on %s", pTable->zName);
143836 }
143837 azModuleArg = sqlite3DbRealloc(db, pTable->azModuleArg, nBytes);
143838 if( azModuleArg==0 ){
143839 sqlite3DbFree(db, zArg);
143840 }else{
143841 int i = pTable->nModuleArg++;
143842 azModuleArg[i] = zArg;
143843 azModuleArg[i+1] = 0;
143844 pTable->azModuleArg = azModuleArg;
143845 }
143846 }
143847
143848 /*
143849 ** The parser calls this routine when it first sees a CREATE VIRTUAL TABLE
@@ -143862,14 +143750,15 @@
143862
143863 sqlite3StartTable(pParse, pName1, pName2, 0, 0, 1, ifNotExists);
143864 pTable = pParse->pNewTable;
143865 if( pTable==0 ) return;
143866 assert( 0==pTable->pIndex );
 
143867
143868 db = pParse->db;
143869
143870 assert( pTable->nModuleArg==0 );
143871 addModuleArgument(pParse, pTable, sqlite3NameFromToken(db, pModuleName));
143872 addModuleArgument(pParse, pTable, 0);
143873 addModuleArgument(pParse, pTable, sqlite3DbStrDup(db, pTable->zName));
143874 assert( (pParse->sNameToken.z==pName2->z && pName2->z!=0)
143875 || (pParse->sNameToken.z==pName1->z && pName2->z==0)
@@ -143882,15 +143771,15 @@
143882 /* Creating a virtual table invokes the authorization callback twice.
143883 ** The first invocation, to obtain permission to INSERT a row into the
143884 ** sqlite_schema table, has already been made by sqlite3StartTable().
143885 ** The second call, to obtain permission to create the table, is made now.
143886 */
143887 if( pTable->azModuleArg ){
143888 int iDb = sqlite3SchemaToIndex(db, pTable->pSchema);
143889 assert( iDb>=0 ); /* The database the table is being created in */
143890 sqlite3AuthCheck(pParse, SQLITE_CREATE_VTABLE, pTable->zName,
143891 pTable->azModuleArg[0], pParse->db->aDb[iDb].zDbSName);
143892 }
143893 #endif
143894 }
143895
143896 /*
@@ -143916,11 +143805,11 @@
143916 sqlite3 *db = pParse->db; /* The database connection */
143917
143918 if( pTab==0 ) return;
143919 addArgumentToVtab(pParse);
143920 pParse->sArg.z = 0;
143921 if( pTab->nModuleArg<1 ) return;
143922
143923 /* If the CREATE VIRTUAL TABLE statement is being entered for the
143924 ** first time (in other words if the virtual table is actually being
143925 ** created now instead of just being read out of sqlite_schema) then
143926 ** do additional initialization work and store the statement text
@@ -144031,12 +143920,12 @@
144031 char **pzErr
144032 ){
144033 VtabCtx sCtx;
144034 VTable *pVTable;
144035 int rc;
144036 const char *const*azArg = (const char *const*)pTab->azModuleArg;
144037 int nArg = pTab->nModuleArg;
144038 char *zErr = 0;
144039 char *zModuleName;
144040 int iDb;
144041 VtabCtx *pCtx;
144042
@@ -144064,11 +143953,11 @@
144064 pVTable->db = db;
144065 pVTable->pMod = pMod;
144066 pVTable->eVtabRisk = SQLITE_VTABRISK_Normal;
144067
144068 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
144069 pTab->azModuleArg[1] = db->aDb[iDb].zDbSName;
144070
144071 /* Invoke the virtual table constructor */
144072 assert( &db->pVtabCtx );
144073 assert( xConstruct );
144074 sCtx.pTab = pTab;
@@ -144103,16 +143992,16 @@
144103 rc = SQLITE_ERROR;
144104 }else{
144105 int iCol;
144106 u16 oooHidden = 0;
144107 /* If everything went according to plan, link the new VTable structure
144108 ** into the linked list headed by pTab->pVTable. Then loop through the
144109 ** columns of the table to see if any of them contain the token "hidden".
144110 ** If so, set the Column COLFLAG_HIDDEN flag and remove the token from
144111 ** the type string. */
144112 pVTable->pNext = pTab->pVTable;
144113 pTab->pVTable = pVTable;
144114
144115 for(iCol=0; iCol<pTab->nCol; iCol++){
144116 char *zType = sqlite3ColumnType(&pTab->aCol[iCol], "");
144117 int nType;
144118 int i = 0;
@@ -144166,15 +144055,15 @@
144166 if( !IsVirtual(pTab) || sqlite3GetVTable(db, pTab) ){
144167 return SQLITE_OK;
144168 }
144169
144170 /* Locate the required virtual table module */
144171 zMod = pTab->azModuleArg[0];
144172 pMod = (Module*)sqlite3HashFind(&db->aModule, zMod);
144173
144174 if( !pMod ){
144175 const char *zModule = pTab->azModuleArg[0];
144176 sqlite3ErrorMsg(pParse, "no such module: %s", zModule);
144177 rc = SQLITE_ERROR;
144178 }else{
144179 char *zErr = 0;
144180 rc = vtabCallConstructor(db, pTab, pMod, pMod->pModule->xConnect, &zErr);
@@ -144233,14 +144122,14 @@
144233 Table *pTab;
144234 Module *pMod;
144235 const char *zMod;
144236
144237 pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zDbSName);
144238 assert( pTab && IsVirtual(pTab) && !pTab->pVTable );
144239
144240 /* Locate the required virtual table module */
144241 zMod = pTab->azModuleArg[0];
144242 pMod = (Module*)sqlite3HashFind(&db->aModule, zMod);
144243
144244 /* If the module has been registered and includes a Create method,
144245 ** invoke it now. If the module has not been registered, return an
144246 ** error. Otherwise, do nothing.
@@ -144296,17 +144185,17 @@
144296 sParse.db = db;
144297 sParse.nQueryLoop = 1;
144298 if( SQLITE_OK==sqlite3RunParser(&sParse, zCreateTable, &zErr)
144299 && sParse.pNewTable
144300 && !db->mallocFailed
144301 && !sParse.pNewTable->pSelect
144302 && !IsVirtual(sParse.pNewTable)
144303 ){
144304 if( !pTab->aCol ){
144305 Table *pNew = sParse.pNewTable;
144306 Index *pIdx;
144307 pTab->aCol = pNew->aCol;
 
144308 pTab->nNVCol = pTab->nCol = pNew->nCol;
144309 pTab->tabFlags |= pNew->tabFlags & (TF_WithoutRowid|TF_NoVisibleRowid);
144310 pNew->nCol = 0;
144311 pNew->aCol = 0;
144312 assert( pTab->pIndex==0 );
@@ -144357,14 +144246,14 @@
144357 SQLITE_PRIVATE int sqlite3VtabCallDestroy(sqlite3 *db, int iDb, const char *zTab){
144358 int rc = SQLITE_OK;
144359 Table *pTab;
144360
144361 pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zDbSName);
144362 if( pTab!=0 && ALWAYS(pTab->pVTable!=0) ){
144363 VTable *p;
144364 int (*xDestroy)(sqlite3_vtab *);
144365 for(p=pTab->pVTable; p; p=p->pNext){
144366 assert( p->pVtab );
144367 if( p->pVtab->nRef>0 ){
144368 return SQLITE_LOCKED;
144369 }
144370 }
@@ -144374,13 +144263,13 @@
144374 assert( xDestroy!=0 );
144375 pTab->nTabRef++;
144376 rc = xDestroy(p->pVtab);
144377 /* Remove the sqlite3_vtab* from the aVTrans[] array, if applicable */
144378 if( rc==SQLITE_OK ){
144379 assert( pTab->pVTable==p && p->pNext==0 );
144380 p->pVtab = 0;
144381 pTab->pVTable = 0;
144382 sqlite3VtabUnlock(p);
144383 }
144384 sqlite3DeleteTable(db, pTab);
144385 }
144386
@@ -144693,12 +144582,13 @@
144693 sqlite3DbFree(db, pTab);
144694 return 0;
144695 }
144696 pMod->pEpoTab = pTab;
144697 pTab->nTabRef = 1;
 
144698 pTab->pSchema = db->aDb[0].pSchema;
144699 assert( pTab->nModuleArg==0 );
144700 pTab->iPKey = -1;
144701 pTab->tabFlags |= TF_Eponymous;
144702 addModuleArgument(pParse, pTab, sqlite3DbStrDup(db, pTab->zName));
144703 addModuleArgument(pParse, pTab, 0);
144704 addModuleArgument(pParse, pTab, sqlite3DbStrDup(db, pTab->zName));
@@ -145438,11 +145328,11 @@
145438 */
145439 static const char *explainIndexColumnName(Index *pIdx, int i){
145440 i = pIdx->aiColumn[i];
145441 if( i==XN_EXPR ) return "<expr>";
145442 if( i==XN_ROWID ) return "rowid";
145443 return pIdx->pTable->aCol[i].zName;
145444 }
145445
145446 /*
145447 ** This routine is a helper for explainIndexRange() below
145448 **
@@ -146650,12 +146540,13 @@
146650 if( sqlite3ExprIsConstant(x.pIdxExpr) ) continue;
146651 w.xExprCallback = whereIndexExprTransNode;
146652 #ifndef SQLITE_OMIT_GENERATED_COLUMNS
146653 }else if( iRef>=0
146654 && (pTab->aCol[iRef].colFlags & COLFLAG_VIRTUAL)!=0
146655 && (pTab->aCol[iRef].zColl==0
146656 || sqlite3StrICmp(pTab->aCol[iRef].zColl, sqlite3StrBINARY)==0)
 
146657 ){
146658 /* Check to see if there are direct references to generated columns
146659 ** that are contained in the index. Pulling the generated column
146660 ** out of the index is an optimization only - the main table is always
146661 ** available if the index cannot be used. To avoid unnecessary
@@ -149070,11 +148961,15 @@
149070 pNew->u.x.leftColumn = aiCurCol[1];
149071 testcase( (prereqLeft | extraRight) != prereqLeft );
149072 pNew->prereqRight = prereqLeft | extraRight;
149073 pNew->prereqAll = prereqAll;
149074 pNew->eOperator = (operatorMask(pDup->op) + eExtraOp) & opMask;
149075 }else if( op==TK_ISNULL && 0==sqlite3ExprCanBeNull(pLeft) ){
 
 
 
 
149076 pExpr->op = TK_TRUEFALSE;
149077 pExpr->u.zToken = "false";
149078 ExprSetProperty(pExpr, EP_IsFalse);
149079 pTerm->prereqAll = 0;
149080 pTerm->eOperator = 0;
@@ -150357,11 +150252,11 @@
150357 testcase( iCol==BMS );
150358 testcase( iCol==BMS-1 );
150359 if( !sentWarning ){
150360 sqlite3_log(SQLITE_WARNING_AUTOINDEX,
150361 "automatic index on %s(%s)", pTable->zName,
150362 pTable->aCol[iCol].zName);
150363 sentWarning = 1;
150364 }
150365 if( (idxCols & cMask)==0 ){
150366 if( whereLoopResize(pParse->db, pLoop, nKeyCol+1) ){
150367 goto end_auto_index_create;
@@ -152536,11 +152431,10 @@
152536 WhereLoop *pNew; /* Template WhereLoop object */
152537 int rc = SQLITE_OK; /* Return code */
152538 int iSortIdx = 1; /* Index number */
152539 int b; /* A boolean value */
152540 LogEst rSize; /* number of rows in the table */
152541 LogEst rLogSize; /* Logarithm of the number of rows in the table */
152542 WhereClause *pWC; /* The parsed WHERE clause */
152543 Table *pTab; /* Table being queried */
152544
152545 pNew = pBuilder->pNew;
152546 pWInfo = pBuilder->pWInfo;
@@ -152579,11 +152473,10 @@
152579 sPk.pNext = pFirst;
152580 }
152581 pProbe = &sPk;
152582 }
152583 rSize = pTab->nRowLogEst;
152584 rLogSize = estLog(rSize);
152585
152586 #ifndef SQLITE_OMIT_AUTOMATIC_INDEX
152587 /* Automatic indexes */
152588 if( !pBuilder->pOrSet /* Not part of an OR optimization */
152589 && (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)==0
@@ -152593,12 +152486,14 @@
152593 && HasRowid(pTab) /* Not WITHOUT ROWID table. (FIXME: Why not?) */
152594 && !pSrc->fg.isCorrelated /* Not a correlated subquery */
152595 && !pSrc->fg.isRecursive /* Not a recursive common table expression. */
152596 ){
152597 /* Generate auto-index WhereLoops */
 
152598 WhereTerm *pTerm;
152599 WhereTerm *pWCEnd = pWC->a + pWC->nTerm;
 
152600 for(pTerm=pWC->a; rc==SQLITE_OK && pTerm<pWCEnd; pTerm++){
152601 if( pTerm->prereqRight & pNew->maskSelf ) continue;
152602 if( termCanDriveIndex(pTerm, pSrc, 0) ){
152603 pNew->u.btree.nEq = 1;
152604 pNew->nSkip = 0;
@@ -152612,11 +152507,11 @@
152612 ** of X is smaller for views and subqueries so that the query planner
152613 ** will be more aggressive about generating automatic indexes for
152614 ** those objects, since there is no opportunity to add schema
152615 ** indexes on subqueries and views. */
152616 pNew->rSetup = rLogSize + rSize;
152617 if( pTab->pSelect==0 && (pTab->tabFlags & TF_Ephemeral)==0 ){
152618 pNew->rSetup += 28;
152619 }else{
152620 pNew->rSetup -= 10;
152621 }
152622 ApplyCostMultiplier(pNew->rSetup, pTab->costMult);
@@ -154763,11 +154658,11 @@
154763
154764 pTabItem = &pTabList->a[pLevel->iFrom];
154765 pTab = pTabItem->pTab;
154766 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
154767 pLoop = pLevel->pWLoop;
154768 if( (pTab->tabFlags & TF_Ephemeral)!=0 || pTab->pSelect ){
154769 /* Do nothing */
154770 }else
154771 #ifndef SQLITE_OMIT_VIRTUALTABLE
154772 if( (pLoop->wsFlags & WHERE_VIRTUALTABLE)!=0 ){
154773 const char *pVTab = (const char *)sqlite3GetVTable(db, pTab);
@@ -155132,11 +155027,11 @@
155132 ** Except, do not close cursors that will be reused by the OR optimization
155133 ** (WHERE_OR_SUBCLAUSE). And do not close the OP_OpenWrite cursors
155134 ** created for the ONEPASS optimization.
155135 */
155136 if( (pTab->tabFlags & TF_Ephemeral)==0
155137 && pTab->pSelect==0
155138 && (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)==0
155139 ){
155140 int ws = pLoop->wsFlags;
155141 if( pWInfo->eOnePass==ONEPASS_OFF && (ws & WHERE_IDX_ONLY)==0 ){
155142 sqlite3VdbeAddOp1(v, OP_Close, pTabItem->iCursor);
@@ -161958,11 +161853,11 @@
161958 sqlite3ErrorMsg(pParse, "unknown table option: %.*s", yymsp[0].minor.yy0.n, yymsp[0].minor.yy0.z);
161959 }
161960 }
161961 break;
161962 case 23: /* columnname ::= nm typetoken */
161963 {sqlite3AddColumn(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0);}
161964 break;
161965 case 24: /* typetoken ::= */
161966 case 63: /* conslist_opt ::= */ yytestcase(yyruleno==63);
161967 case 102: /* as ::= */ yytestcase(yyruleno==102);
161968 {yymsp[1].minor.yy0.n = 0; yymsp[1].minor.yy0.z = 0;}
@@ -169147,11 +169042,11 @@
169147 goto error_out;
169148 }
169149
169150 /* Locate the table in question */
169151 pTab = sqlite3FindTable(db, zTableName, zDbName);
169152 if( !pTab || pTab->pSelect ){
169153 pTab = 0;
169154 goto error_out;
169155 }
169156
169157 /* Find the column for which info is requested */
@@ -169158,11 +169053,11 @@
169158 if( zColumnName==0 ){
169159 /* Query for existance of table only */
169160 }else{
169161 for(iCol=0; iCol<pTab->nCol; iCol++){
169162 pCol = &pTab->aCol[iCol];
169163 if( 0==sqlite3StrICmp(pCol->zName, zColumnName) ){
169164 break;
169165 }
169166 }
169167 if( iCol==pTab->nCol ){
169168 if( HasRowid(pTab) && sqlite3IsRowid(zColumnName) ){
@@ -169185,11 +169080,11 @@
169185 ** 2. The table is not a view and the column name identified an
169186 ** explicitly declared column. Copy meta information from *pCol.
169187 */
169188 if( pCol ){
169189 zDataType = sqlite3ColumnType(pCol,0);
169190 zCollSeq = pCol->zColl;
169191 notnull = pCol->notNull!=0;
169192 primarykey = (pCol->colFlags & COLFLAG_PRIMKEY)!=0;
169193 autoinc = pTab->iPKey==iCol && (pTab->tabFlags & TF_Autoincrement)!=0;
169194 }else{
169195 zDataType = "INTEGER";
@@ -201618,11 +201513,13 @@
201618 *piPk = 0;
201619
201620 assert( p->rc==SQLITE_OK );
201621 p->rc = prepareFreeAndCollectError(p->dbMain, &aStmt[0], &p->zErrmsg,
201622 sqlite3_mprintf(
201623 "SELECT (sql LIKE 'create virtual%%'), rootpage"
 
 
201624 " FROM sqlite_schema"
201625 " WHERE name=%Q", zTab
201626 ));
201627 if( p->rc!=SQLITE_OK || sqlite3_step(aStmt[0])!=SQLITE_ROW ){
201628 /* Either an error, or no such table. */
@@ -203151,11 +203048,11 @@
203151 case RBU_STATE_COOKIE:
203152 pRet->iCookie = (u32)sqlite3_column_int64(pStmt, 1);
203153 break;
203154
203155 case RBU_STATE_OALSZ:
203156 pRet->iOalSz = (u32)sqlite3_column_int64(pStmt, 1);
203157 break;
203158
203159 case RBU_STATE_PHASEONESTEP:
203160 pRet->nPhaseOneStep = sqlite3_column_int64(pStmt, 1);
203161 break;
@@ -230952,11 +230849,11 @@
230952 int nArg, /* Number of args */
230953 sqlite3_value **apUnused /* Function arguments */
230954 ){
230955 assert( nArg==0 );
230956 UNUSED_PARAM2(nArg, apUnused);
230957 sqlite3_result_text(pCtx, "fts5: 2021-07-20 14:57:49 1e35cc6d5c2f563c6bb163bb150d7bc6ede4c993efa828af1face3261bf65a2c", -1, SQLITE_TRANSIENT);
230958 }
230959
230960 /*
230961 ** Return true if zName is the extension on one of the shadow tables used
230962 ** by this module.
230963
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -452,11 +452,11 @@
452 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453 ** [sqlite_version()] and [sqlite_source_id()].
454 */
455 #define SQLITE_VERSION "3.37.0"
456 #define SQLITE_VERSION_NUMBER 3037000
457 #define SQLITE_SOURCE_ID "2021-08-06 20:17:39 087b8b41c6ed76b55c11315e7e95679d67590be20ae21108b593d00bb7d1c57a"
458
459 /*
460 ** CAPI3REF: Run-Time Library Version Numbers
461 ** KEYWORDS: sqlite3_version sqlite3_sourceid
462 **
@@ -13872,10 +13872,11 @@
13872 #ifndef SQLITE_PTRSIZE
13873 # if defined(__SIZEOF_POINTER__)
13874 # define SQLITE_PTRSIZE __SIZEOF_POINTER__
13875 # elif defined(i386) || defined(__i386__) || defined(_M_IX86) || \
13876 defined(_M_ARM) || defined(__arm__) || defined(__x86) || \
13877 (defined(__APPLE__) && defined(__POWERPC__)) || \
13878 (defined(__TOS_AIX__) && !defined(__64BIT__))
13879 # define SQLITE_PTRSIZE 4
13880 # else
13881 # define SQLITE_PTRSIZE 8
13882 # endif
@@ -16881,22 +16882,45 @@
16882 ** record BLOB generated by the OP_MakeRecord
16883 ** opcode. The storage column index is less than
16884 ** or equal to the table column index. It is
16885 ** equal if and only if there are no VIRTUAL
16886 ** columns to the left.
16887 **
16888 ** Notes on zCnName:
16889 ** The zCnName field stores the name of the column, the datatype of the
16890 ** column, and the collating sequence for the column, in that order, all in
16891 ** a single allocation. Each string is 0x00 terminated. The datatype
16892 ** is only included if the COLFLAG_HASTYPE bit of colFlags is set and the
16893 ** collating sequence name is only included if the COLFLAG_HASCOLL bit is
16894 ** set.
16895 */
16896 struct Column {
16897 char *zCnName; /* Name of this column */
16898 unsigned notNull :4; /* An OE_ code for handling a NOT NULL constraint */
16899 unsigned eType :4; /* One of the standard types */
16900 char affinity; /* One of the SQLITE_AFF_... values */
16901 u8 szEst; /* Est size of value in this column. sizeof(INT)==1 */
16902 u8 hName; /* Column name hash for faster lookup */
16903 u16 iDflt; /* 1-based index of DEFAULT. 0 means "none" */
16904 u16 colFlags; /* Boolean properties. See COLFLAG_ defines below */
16905 };
16906
16907 /* Allowed values for Column.eType.
16908 **
16909 ** Values must match entries in the global constant arrays
16910 ** sqlite3StdTypeLen[] and sqlite3StdType[]. Each value is one more
16911 ** than the offset into these arrays for the corresponding name.
16912 ** Adjust the SQLITE_N_STDTYPE value if adding or removing entries.
16913 */
16914 #define COLTYPE_CUSTOM 0 /* Type appended to zName */
16915 #define COLTYPE_BLOB 1
16916 #define COLTYPE_INT 2
16917 #define COLTYPE_INTEGER 3
16918 #define COLTYPE_REAL 4
16919 #define COLTYPE_TEXT 5
16920 #define SQLITE_N_STDTYPE 5 /* Number of standard types */
16921
16922 /* Allowed values for Column.colFlags.
16923 **
16924 ** Constraints:
16925 ** TF_HasVirtual == COLFLAG_VIRTUAL
16926 ** TF_HasStored == COLFLAG_STORED
@@ -16909,10 +16933,11 @@
16933 #define COLFLAG_SORTERREF 0x0010 /* Use sorter-refs with this column */
16934 #define COLFLAG_VIRTUAL 0x0020 /* GENERATED ALWAYS AS ... VIRTUAL */
16935 #define COLFLAG_STORED 0x0040 /* GENERATED ALWAYS AS ... STORED */
16936 #define COLFLAG_NOTAVAIL 0x0080 /* STORED column not yet calculated */
16937 #define COLFLAG_BUSY 0x0100 /* Blocks recursion on GENERATED columns */
16938 #define COLFLAG_HASCOLL 0x0200 /* Has collating sequence name in zCnName */
16939 #define COLFLAG_GENERATED 0x0060 /* Combo: _STORED, _VIRTUAL */
16940 #define COLFLAG_NOINSERT 0x0062 /* Combo: _HIDDEN, _STORED, _VIRTUAL */
16941
16942 /*
16943 ** A "Collating Sequence" is defined by an instance of the following
@@ -17038,19 +17063,17 @@
17063 #define SQLITE_VTABRISK_Low 0
17064 #define SQLITE_VTABRISK_Normal 1
17065 #define SQLITE_VTABRISK_High 2
17066
17067 /*
17068 ** The schema for each SQL table, virtual table, and view is represented
17069 ** in memory by an instance of the following structure.
17070 */
17071 struct Table {
17072 char *zName; /* Name of the table or view */
17073 Column *aCol; /* Information about each column */
17074 Index *pIndex; /* List of SQL indexes on this table. */
 
 
17075 char *zColAff; /* String defining the affinity of each column */
17076 ExprList *pCheck; /* All CHECK constraints */
17077 /* ... also used as column name list in a VIEW */
17078 Pgno tnum; /* Root BTree page for this table */
17079 u32 nTabRef; /* Number of pointers to this Table */
@@ -17062,19 +17085,28 @@
17085 LogEst szTabRow; /* Estimated size of each table row in bytes */
17086 #ifdef SQLITE_ENABLE_COSTMULT
17087 LogEst costMult; /* Cost multiplier for using this table */
17088 #endif
17089 u8 keyConf; /* What to do in case of uniqueness conflict on iPKey */
17090 u8 eTabType; /* 0: normal, 1: virtual, 2: view */
17091 union {
17092 struct { /* Used by ordinary tables: */
17093 int addColOffset; /* Offset in CREATE TABLE stmt to add a new column */
17094 FKey *pFKey; /* Linked list of all foreign keys in this table */
17095 ExprList *pDfltList; /* DEFAULT clauses on various columns.
17096 ** Or the AS clause for generated columns. */
17097 } tab;
17098 struct { /* Used by views: */
17099 Select *pSelect; /* View definition */
17100 } view;
17101 struct { /* Used by virtual tables only: */
17102 int nArg; /* Number of arguments to the module */
17103 char **azArg; /* 0: module 1: schema 2: vtab name 3...: args */
17104 VTable *p; /* List of VTable objects. */
17105 } vtab;
17106 } u;
17107 Trigger *pTrigger; /* List of triggers on this object */
17108 Schema *pSchema; /* Schema that contains this table */
17109 };
17110
17111 /*
17112 ** Allowed values for Table.tabFlags.
@@ -17089,38 +17121,48 @@
17121 **
17122 ** TF_HasVirtual == COLFLAG_VIRTUAL
17123 ** TF_HasStored == COLFLAG_STORED
17124 ** TF_HasHidden == COLFLAG_HIDDEN
17125 */
17126 #define TF_Readonly 0x00000001 /* Read-only system table */
17127 #define TF_HasHidden 0x00000002 /* Has one or more hidden columns */
17128 #define TF_HasPrimaryKey 0x00000004 /* Table has a primary key */
17129 #define TF_Autoincrement 0x00000008 /* Integer primary key is autoincrement */
17130 #define TF_HasStat1 0x00000010 /* nRowLogEst set from sqlite_stat1 */
17131 #define TF_HasVirtual 0x00000020 /* Has one or more VIRTUAL columns */
17132 #define TF_HasStored 0x00000040 /* Has one or more STORED columns */
17133 #define TF_HasGenerated 0x00000060 /* Combo: HasVirtual + HasStored */
17134 #define TF_WithoutRowid 0x00000080 /* No rowid. PRIMARY KEY is the key */
17135 #define TF_StatsUsed 0x00000100 /* Query planner decisions affected by
17136 ** Index.aiRowLogEst[] values */
17137 #define TF_NoVisibleRowid 0x00000200 /* No user-visible "rowid" column */
17138 #define TF_OOOHidden 0x00000400 /* Out-of-Order hidden columns */
17139 #define TF_HasNotNull 0x00000800 /* Contains NOT NULL constraints */
17140 #define TF_Shadow 0x00001000 /* True for a shadow table */
17141 #define TF_HasStat4 0x00002000 /* STAT4 info available for this table */
17142 #define TF_Ephemeral 0x00004000 /* An ephemeral table */
17143 #define TF_Eponymous 0x00008000 /* An eponymous virtual table */
17144
17145 /*
17146 ** Allowed values for Table.eTabType
17147 */
17148 #define TABTYP_NORM 0 /* Ordinary table */
17149 #define TABTYP_VTAB 1 /* Virtual table */
17150 #define TABTYP_VIEW 2 /* A view */
17151
17152 #define IsView(X) ((X)->eTabType==TABTYP_VIEW)
17153 #define IsOrdinaryTable(X) ((X)->eTabType==TABTYP_NORM)
17154
17155 /*
17156 ** Test to see whether or not a table is a virtual table. This is
17157 ** done as a macro so that it will be optimized out when virtual
17158 ** table support is omitted from the build.
17159 */
17160 #ifndef SQLITE_OMIT_VIRTUALTABLE
17161 # define IsVirtual(X) ((X)->eTabType==TABTYP_VTAB)
17162 # define ExprIsVtab(X) \
17163 ((X)->op==TK_COLUMN && (X)->y.pTab!=0 && (X)->y.pTab->eTabType==TABTYP_VTAB)
17164 #else
17165 # define IsVirtual(X) 0
17166 # define ExprIsVtab(X) 0
17167 #endif
17168
@@ -19170,10 +19212,11 @@
19212 SQLITE_PRIVATE void sqlite3SetString(char **, sqlite3*, const char*);
19213 SQLITE_PRIVATE void sqlite3ErrorMsg(Parse*, const char*, ...);
19214 SQLITE_PRIVATE int sqlite3ErrorToParser(sqlite3*,int);
19215 SQLITE_PRIVATE void sqlite3Dequote(char*);
19216 SQLITE_PRIVATE void sqlite3DequoteExpr(Expr*);
19217 SQLITE_PRIVATE void sqlite3DequoteToken(Token*);
19218 SQLITE_PRIVATE void sqlite3TokenInit(Token*,char*);
19219 SQLITE_PRIVATE int sqlite3KeywordCode(const unsigned char*, int);
19220 SQLITE_PRIVATE int sqlite3RunParser(Parse*, const char*, char **);
19221 SQLITE_PRIVATE void sqlite3FinishCoding(Parse*);
19222 SQLITE_PRIVATE int sqlite3GetTempReg(Parse*);
@@ -19215,10 +19258,14 @@
19258 #endif
19259 SQLITE_PRIVATE void sqlite3ResetAllSchemasOfConnection(sqlite3*);
19260 SQLITE_PRIVATE void sqlite3ResetOneSchema(sqlite3*,int);
19261 SQLITE_PRIVATE void sqlite3CollapseDatabaseArray(sqlite3*);
19262 SQLITE_PRIVATE void sqlite3CommitInternalChanges(sqlite3*);
19263 SQLITE_PRIVATE void sqlite3ColumnSetExpr(Parse*,Table*,Column*,Expr*);
19264 SQLITE_PRIVATE Expr *sqlite3ColumnExpr(Table*,Column*);
19265 SQLITE_PRIVATE void sqlite3ColumnSetColl(sqlite3*,Column*,const char*zColl);
19266 SQLITE_PRIVATE const char *sqlite3ColumnColl(Column*);
19267 SQLITE_PRIVATE void sqlite3DeleteColumnNames(sqlite3*,Table*);
19268 SQLITE_PRIVATE void sqlite3GenerateColumnNames(Parse *pParse, Select *pSelect);
19269 SQLITE_PRIVATE int sqlite3ColumnsFromExprList(Parse*,ExprList*,i16*,Column**);
19270 SQLITE_PRIVATE void sqlite3SelectAddColumnTypeAndCollation(Parse*,Table*,Select*,char);
19271 SQLITE_PRIVATE Table *sqlite3ResultSetOfSelect(Parse*,Select*,char);
@@ -19236,11 +19283,11 @@
19283 #if SQLITE_ENABLE_HIDDEN_COLUMNS
19284 SQLITE_PRIVATE void sqlite3ColumnPropertiesFromName(Table*, Column*);
19285 #else
19286 # define sqlite3ColumnPropertiesFromName(T,C) /* no-op */
19287 #endif
19288 SQLITE_PRIVATE void sqlite3AddColumn(Parse*,Token,Token);
19289 SQLITE_PRIVATE void sqlite3AddNotNull(Parse*, int);
19290 SQLITE_PRIVATE void sqlite3AddPrimaryKey(Parse*, ExprList*, int, int, int);
19291 SQLITE_PRIVATE void sqlite3AddCheckConstraint(Parse*, Expr*, const char*, const char*);
19292 SQLITE_PRIVATE void sqlite3AddDefaultValue(Parse*,Expr*,const char*,const char*);
19293 SQLITE_PRIVATE void sqlite3AddCollateType(Parse*, Token*);
@@ -19353,11 +19400,11 @@
19400 SQLITE_PRIVATE int sqlite3ExprCodeGetColumn(Parse*, Table*, int, int, int, u8);
19401 SQLITE_PRIVATE void sqlite3ExprCodeGetColumnOfTable(Vdbe*, Table*, int, int, int);
19402 SQLITE_PRIVATE void sqlite3ExprCodeMove(Parse*, int, int, int);
19403 SQLITE_PRIVATE void sqlite3ExprCode(Parse*, Expr*, int);
19404 #ifndef SQLITE_OMIT_GENERATED_COLUMNS
19405 SQLITE_PRIVATE void sqlite3ExprCodeGeneratedColumn(Parse*, Table*, Column*, int);
19406 #endif
19407 SQLITE_PRIVATE void sqlite3ExprCodeCopy(Parse*, Expr*, int);
19408 SQLITE_PRIVATE void sqlite3ExprCodeFactorable(Parse*, Expr*, int);
19409 SQLITE_PRIVATE int sqlite3ExprCodeRunJustOnce(Parse*, Expr*, int);
19410 SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse*, Expr*, int*);
@@ -19646,10 +19693,13 @@
19693 SQLITE_PRIVATE int sqlite3ValueFromExpr(sqlite3 *, Expr *, u8, u8, sqlite3_value **);
19694 SQLITE_PRIVATE void sqlite3ValueApplyAffinity(sqlite3_value *, u8, u8);
19695 #ifndef SQLITE_AMALGAMATION
19696 SQLITE_PRIVATE const unsigned char sqlite3OpcodeProperty[];
19697 SQLITE_PRIVATE const char sqlite3StrBINARY[];
19698 SQLITE_PRIVATE const unsigned char sqlite3StdTypeLen[];
19699 SQLITE_PRIVATE const char sqlite3StdTypeAffinity[];
19700 SQLITE_PRIVATE const char *sqlite3StdType[];
19701 SQLITE_PRIVATE const unsigned char sqlite3UpperToLower[];
19702 SQLITE_PRIVATE const unsigned char *sqlite3aLTb;
19703 SQLITE_PRIVATE const unsigned char *sqlite3aEQb;
19704 SQLITE_PRIVATE const unsigned char *sqlite3aGTb;
19705 SQLITE_PRIVATE const unsigned char sqlite3CtypeMap[];
@@ -20076,10 +20126,207 @@
20126 #endif
20127
20128 #endif /* SQLITEINT_H */
20129
20130 /************** End of sqliteInt.h *******************************************/
20131 /************** Begin file os_common.h ***************************************/
20132 /*
20133 ** 2004 May 22
20134 **
20135 ** The author disclaims copyright to this source code. In place of
20136 ** a legal notice, here is a blessing:
20137 **
20138 ** May you do good and not evil.
20139 ** May you find forgiveness for yourself and forgive others.
20140 ** May you share freely, never taking more than you give.
20141 **
20142 ******************************************************************************
20143 **
20144 ** This file contains macros and a little bit of code that is common to
20145 ** all of the platform-specific files (os_*.c) and is #included into those
20146 ** files.
20147 **
20148 ** This file should be #included by the os_*.c files only. It is not a
20149 ** general purpose header file.
20150 */
20151 #ifndef _OS_COMMON_H_
20152 #define _OS_COMMON_H_
20153
20154 /*
20155 ** At least two bugs have slipped in because we changed the MEMORY_DEBUG
20156 ** macro to SQLITE_DEBUG and some older makefiles have not yet made the
20157 ** switch. The following code should catch this problem at compile-time.
20158 */
20159 #ifdef MEMORY_DEBUG
20160 # error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead."
20161 #endif
20162
20163 /*
20164 ** Macros for performance tracing. Normally turned off. Only works
20165 ** on i486 hardware.
20166 */
20167 #ifdef SQLITE_PERFORMANCE_TRACE
20168
20169 /*
20170 ** hwtime.h contains inline assembler code for implementing
20171 ** high-performance timing routines.
20172 */
20173 /************** Include hwtime.h in the middle of os_common.h ****************/
20174 /************** Begin file hwtime.h ******************************************/
20175 /*
20176 ** 2008 May 27
20177 **
20178 ** The author disclaims copyright to this source code. In place of
20179 ** a legal notice, here is a blessing:
20180 **
20181 ** May you do good and not evil.
20182 ** May you find forgiveness for yourself and forgive others.
20183 ** May you share freely, never taking more than you give.
20184 **
20185 ******************************************************************************
20186 **
20187 ** This file contains inline asm code for retrieving "high-performance"
20188 ** counters for x86 and x86_64 class CPUs.
20189 */
20190 #ifndef SQLITE_HWTIME_H
20191 #define SQLITE_HWTIME_H
20192
20193 /*
20194 ** The following routine only works on pentium-class (or newer) processors.
20195 ** It uses the RDTSC opcode to read the cycle count value out of the
20196 ** processor and returns that value. This can be used for high-res
20197 ** profiling.
20198 */
20199 #if !defined(__STRICT_ANSI__) && \
20200 (defined(__GNUC__) || defined(_MSC_VER)) && \
20201 (defined(i386) || defined(__i386__) || defined(_M_IX86))
20202
20203 #if defined(__GNUC__)
20204
20205 __inline__ sqlite_uint64 sqlite3Hwtime(void){
20206 unsigned int lo, hi;
20207 __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi));
20208 return (sqlite_uint64)hi << 32 | lo;
20209 }
20210
20211 #elif defined(_MSC_VER)
20212
20213 __declspec(naked) __inline sqlite_uint64 __cdecl sqlite3Hwtime(void){
20214 __asm {
20215 rdtsc
20216 ret ; return value at EDX:EAX
20217 }
20218 }
20219
20220 #endif
20221
20222 #elif !defined(__STRICT_ANSI__) && (defined(__GNUC__) && defined(__x86_64__))
20223
20224 __inline__ sqlite_uint64 sqlite3Hwtime(void){
20225 unsigned long val;
20226 __asm__ __volatile__ ("rdtsc" : "=A" (val));
20227 return val;
20228 }
20229
20230 #elif !defined(__STRICT_ANSI__) && (defined(__GNUC__) && defined(__ppc__))
20231
20232 __inline__ sqlite_uint64 sqlite3Hwtime(void){
20233 unsigned long long retval;
20234 unsigned long junk;
20235 __asm__ __volatile__ ("\n\
20236 1: mftbu %1\n\
20237 mftb %L0\n\
20238 mftbu %0\n\
20239 cmpw %0,%1\n\
20240 bne 1b"
20241 : "=r" (retval), "=r" (junk));
20242 return retval;
20243 }
20244
20245 #else
20246
20247 /*
20248 ** asm() is needed for hardware timing support. Without asm(),
20249 ** disable the sqlite3Hwtime() routine.
20250 **
20251 ** sqlite3Hwtime() is only used for some obscure debugging
20252 ** and analysis configurations, not in any deliverable, so this
20253 ** should not be a great loss.
20254 */
20255 SQLITE_PRIVATE sqlite_uint64 sqlite3Hwtime(void){ return ((sqlite_uint64)0); }
20256
20257 #endif
20258
20259 #endif /* !defined(SQLITE_HWTIME_H) */
20260
20261 /************** End of hwtime.h **********************************************/
20262 /************** Continuing where we left off in os_common.h ******************/
20263
20264 static sqlite_uint64 g_start;
20265 static sqlite_uint64 g_elapsed;
20266 #define TIMER_START g_start=sqlite3Hwtime()
20267 #define TIMER_END g_elapsed=sqlite3Hwtime()-g_start
20268 #define TIMER_ELAPSED g_elapsed
20269 #else
20270 #define TIMER_START
20271 #define TIMER_END
20272 #define TIMER_ELAPSED ((sqlite_uint64)0)
20273 #endif
20274
20275 /*
20276 ** If we compile with the SQLITE_TEST macro set, then the following block
20277 ** of code will give us the ability to simulate a disk I/O error. This
20278 ** is used for testing the I/O recovery logic.
20279 */
20280 #if defined(SQLITE_TEST)
20281 SQLITE_API extern int sqlite3_io_error_hit;
20282 SQLITE_API extern int sqlite3_io_error_hardhit;
20283 SQLITE_API extern int sqlite3_io_error_pending;
20284 SQLITE_API extern int sqlite3_io_error_persist;
20285 SQLITE_API extern int sqlite3_io_error_benign;
20286 SQLITE_API extern int sqlite3_diskfull_pending;
20287 SQLITE_API extern int sqlite3_diskfull;
20288 #define SimulateIOErrorBenign(X) sqlite3_io_error_benign=(X)
20289 #define SimulateIOError(CODE) \
20290 if( (sqlite3_io_error_persist && sqlite3_io_error_hit) \
20291 || sqlite3_io_error_pending-- == 1 ) \
20292 { local_ioerr(); CODE; }
20293 static void local_ioerr(){
20294 IOTRACE(("IOERR\n"));
20295 sqlite3_io_error_hit++;
20296 if( !sqlite3_io_error_benign ) sqlite3_io_error_hardhit++;
20297 }
20298 #define SimulateDiskfullError(CODE) \
20299 if( sqlite3_diskfull_pending ){ \
20300 if( sqlite3_diskfull_pending == 1 ){ \
20301 local_ioerr(); \
20302 sqlite3_diskfull = 1; \
20303 sqlite3_io_error_hit = 1; \
20304 CODE; \
20305 }else{ \
20306 sqlite3_diskfull_pending--; \
20307 } \
20308 }
20309 #else
20310 #define SimulateIOErrorBenign(X)
20311 #define SimulateIOError(A)
20312 #define SimulateDiskfullError(A)
20313 #endif /* defined(SQLITE_TEST) */
20314
20315 /*
20316 ** When testing, keep a count of the number of open files.
20317 */
20318 #if defined(SQLITE_TEST)
20319 SQLITE_API extern int sqlite3_open_file_count;
20320 #define OpenCounter(X) sqlite3_open_file_count+=(X)
20321 #else
20322 #define OpenCounter(X)
20323 #endif /* defined(SQLITE_TEST) */
20324
20325 #endif /* !defined(_OS_COMMON_H_) */
20326
20327 /************** End of os_common.h *******************************************/
20328 /************** Begin file ctime.c *******************************************/
20329 /*
20330 ** 2010 February 23
20331 **
20332 ** The author disclaims copyright to this source code. In place of
@@ -21213,10 +21460,30 @@
21460
21461 /*
21462 ** Name of the default collating sequence
21463 */
21464 SQLITE_PRIVATE const char sqlite3StrBINARY[] = "BINARY";
21465
21466 /*
21467 ** Standard typenames. These names must match the COLTYPE_* definitions.
21468 ** Adjust the SQLITE_N_STDTYPE value if adding or removing entries.
21469 */
21470 SQLITE_PRIVATE const unsigned char sqlite3StdTypeLen[] = { 4, 3, 7, 4, 4 };
21471 SQLITE_PRIVATE const char sqlite3StdTypeAffinity[] = {
21472 SQLITE_AFF_BLOB,
21473 SQLITE_AFF_INTEGER,
21474 SQLITE_AFF_INTEGER,
21475 SQLITE_AFF_REAL,
21476 SQLITE_AFF_TEXT
21477 };
21478 SQLITE_PRIVATE const char *sqlite3StdType[] = {
21479 "BLOB",
21480 "INT",
21481 "INTEGER",
21482 "REAL",
21483 "TEXT"
21484 };
21485
21486 /************** End of global.c **********************************************/
21487 /************** Begin file status.c ******************************************/
21488 /*
21489 ** 2008 June 18
@@ -27183,209 +27450,11 @@
27450
27451 #if SQLITE_OS_WIN
27452 /*
27453 ** Include code that is common to all os_*.c files
27454 */
27455 /* #include "os_common.h" */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27456
27457 /*
27458 ** Include the header file for the Windows VFS.
27459 */
27460 /************** Include os_win.h in the middle of mutex_w32.c ****************/
@@ -30484,12 +30553,12 @@
30553 case TK_NULL: {
30554 sqlite3TreeViewLine(pView,"NULL");
30555 break;
30556 }
30557 case TK_TRUEFALSE: {
30558 sqlite3TreeViewLine(pView,"%s%s",
30559 sqlite3ExprTruthValue(pExpr) ? "TRUE" : "FALSE", zFlgs);
30560 break;
30561 }
30562 #ifndef SQLITE_OMIT_BLOB_LITERAL
30563 case TK_BLOB: {
30564 sqlite3TreeViewLine(pView,"%s", pExpr->u.zToken);
@@ -31856,12 +31925,18 @@
31925 **
31926 ** The column type is an extra string stored after the zero-terminator on
31927 ** the column name if and only if the COLFLAG_HASTYPE flag is set.
31928 */
31929 SQLITE_PRIVATE char *sqlite3ColumnType(Column *pCol, char *zDflt){
31930 if( pCol->colFlags & COLFLAG_HASTYPE ){
31931 return pCol->zCnName + strlen(pCol->zCnName) + 1;
31932 }else if( pCol->eType ){
31933 assert( pCol->eType<=SQLITE_N_STDTYPE );
31934 return (char*)sqlite3StdType[pCol->eType-1];
31935 }else{
31936 return zDflt;
31937 }
31938 }
31939
31940 /*
31941 ** Helper function for sqlite3Error() - called rarely. Broken out into
31942 ** a separate routine to avoid unnecessary register saves on entry to
@@ -32032,10 +32107,32 @@
32107 SQLITE_PRIVATE void sqlite3DequoteExpr(Expr *p){
32108 assert( sqlite3Isquote(p->u.zToken[0]) );
32109 p->flags |= p->u.zToken[0]=='"' ? EP_Quoted|EP_DblQuoted : EP_Quoted;
32110 sqlite3Dequote(p->u.zToken);
32111 }
32112
32113 /*
32114 ** If the input token p is quoted, try to adjust the token to remove
32115 ** the quotes. This is not always possible:
32116 **
32117 ** "abc" -> abc
32118 ** "ab""cd" -> (not possible because of the interior "")
32119 **
32120 ** Remove the quotes if possible. This is a optimization. The overall
32121 ** system should still return the correct answer even if this routine
32122 ** is always a no-op.
32123 */
32124 SQLITE_PRIVATE void sqlite3DequoteToken(Token *p){
32125 unsigned int i;
32126 if( p->n<2 ) return;
32127 if( !sqlite3Isquote(p->z[0]) ) return;
32128 for(i=1; i<p->n-1; i++){
32129 if( sqlite3Isquote(p->z[i]) ) return;
32130 }
32131 p->n -= 2;
32132 p->z++;
32133 }
32134
32135 /*
32136 ** Generate a Token object from a string
32137 */
32138 SQLITE_PRIVATE void sqlite3TokenInit(Token *p, char *z){
@@ -34243,209 +34340,11 @@
34340 #define UNIXFILE_NOLOCK 0x80 /* Do no file locking */
34341
34342 /*
34343 ** Include code that is common to all os_*.c files
34344 */
34345 /* #include "os_common.h" */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34346
34347 /*
34348 ** Define various macros that are missing from some systems.
34349 */
34350 #ifndef O_LARGEFILE
@@ -42271,209 +42170,11 @@
42170 #if SQLITE_OS_WIN /* This file is used for Windows only */
42171
42172 /*
42173 ** Include code that is common to all os_*.c files
42174 */
42175 /* #include "os_common.h" */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42176
42177 /*
42178 ** Include the header file for the Windows VFS.
42179 */
42180 /* #include "os_win.h" */
@@ -60605,11 +60306,14 @@
60306 ** Each index block except for the first contains information on
60307 ** HASHTABLE_NPAGE frames. The first index block contains information on
60308 ** HASHTABLE_NPAGE_ONE frames. The values of HASHTABLE_NPAGE_ONE and
60309 ** HASHTABLE_NPAGE are selected so that together the wal-index header and
60310 ** first index block are the same size as all other index blocks in the
60311 ** wal-index. The values are:
60312 **
60313 ** HASHTABLE_NPAGE 4096
60314 ** HASHTABLE_NPAGE_ONE 4062
60315 **
60316 ** Each index block contains two sections, a page-mapping that contains the
60317 ** database page number associated with each wal frame, and a hash-table
60318 ** that allows readers to query an index block for a specific page number.
60319 ** The page-mapping is an array of HASHTABLE_NPAGE (or HASHTABLE_NPAGE_ONE
@@ -60841,10 +60545,74 @@
60545 u32 nBackfillAttempted; /* WAL frames perhaps written, or maybe not */
60546 u32 notUsed0; /* Available for future enhancements */
60547 };
60548 #define READMARK_NOT_USED 0xffffffff
60549
60550 /*
60551 ** This is a schematic view of the complete 136-byte header of the
60552 ** wal-index file (also known as the -shm file):
60553 **
60554 ** +-----------------------------+
60555 ** 0: | iVersion | \
60556 ** +-----------------------------+ |
60557 ** 4: | (unused padding) | |
60558 ** +-----------------------------+ |
60559 ** 8: | iChange | |
60560 ** +-------+-------+-------------+ |
60561 ** 12: | bInit | bBig | szPage | |
60562 ** +-------+-------+-------------+ |
60563 ** 16: | mxFrame | | First copy of the
60564 ** +-----------------------------+ | WalIndexHdr object
60565 ** 20: | nPage | |
60566 ** +-----------------------------+ |
60567 ** 24: | aFrameCksum | |
60568 ** | | |
60569 ** +-----------------------------+ |
60570 ** 32: | aSalt | |
60571 ** | | |
60572 ** +-----------------------------+ |
60573 ** 40: | aCksum | |
60574 ** | | /
60575 ** +-----------------------------+
60576 ** 48: | iVersion | \
60577 ** +-----------------------------+ |
60578 ** 52: | (unused padding) | |
60579 ** +-----------------------------+ |
60580 ** 56: | iChange | |
60581 ** +-------+-------+-------------+ |
60582 ** 60: | bInit | bBig | szPage | |
60583 ** +-------+-------+-------------+ | Second copy of the
60584 ** 64: | mxFrame | | WalIndexHdr
60585 ** +-----------------------------+ |
60586 ** 68: | nPage | |
60587 ** +-----------------------------+ |
60588 ** 72: | aFrameCksum | |
60589 ** | | |
60590 ** +-----------------------------+ |
60591 ** 80: | aSalt | |
60592 ** | | |
60593 ** +-----------------------------+ |
60594 ** 88: | aCksum | |
60595 ** | | /
60596 ** +-----------------------------+
60597 ** 96: | nBackfill |
60598 ** +-----------------------------+
60599 ** 100: | 5 read marks |
60600 ** | |
60601 ** | |
60602 ** | |
60603 ** | |
60604 ** +-------+-------+------+------+
60605 ** 120: | Write | Ckpt | Rcvr | Rd0 | \
60606 ** +-------+-------+------+------+ ) 8 lock bytes
60607 ** | Read1 | Read2 | Rd3 | Rd4 | /
60608 ** +-------+-------+------+------+
60609 ** 128: | nBackfillAttempted |
60610 ** +-----------------------------+
60611 ** 132: | (unused padding) |
60612 ** +-----------------------------+
60613 */
60614
60615 /* A block of WALINDEX_LOCK_RESERVED bytes beginning at
60616 ** WALINDEX_LOCK_OFFSET is reserved for locks. Since some systems
60617 ** only support mandatory file-locks, we do not read or write data
60618 ** from the region of the file on which locks are applied.
@@ -61853,19 +61621,48 @@
61621 Wal *pRet; /* Object to allocate and return */
61622 int flags; /* Flags passed to OsOpen() */
61623
61624 assert( zWalName && zWalName[0] );
61625 assert( pDbFd );
61626
61627 /* Verify the values of various constants. Any changes to the values
61628 ** of these constants would result in an incompatible on-disk format
61629 ** for the -shm file. Any change that causes one of these asserts to
61630 ** fail is a backward compatibility problem, even if the change otherwise
61631 ** works.
61632 **
61633 ** This table also serves as a helpful cross-reference when trying to
61634 ** interpret hex dumps of the -shm file.
61635 */
61636 assert( 48 == sizeof(WalIndexHdr) );
61637 assert( 40 == sizeof(WalCkptInfo) );
61638 assert( 120 == WALINDEX_LOCK_OFFSET );
61639 assert( 136 == WALINDEX_HDR_SIZE );
61640 assert( 4096 == HASHTABLE_NPAGE );
61641 assert( 4062 == HASHTABLE_NPAGE_ONE );
61642 assert( 8192 == HASHTABLE_NSLOT );
61643 assert( 383 == HASHTABLE_HASH_1 );
61644 assert( 32768 == WALINDEX_PGSZ );
61645 assert( 8 == SQLITE_SHM_NLOCK );
61646 assert( 5 == WAL_NREADER );
61647 assert( 24 == WAL_FRAME_HDRSIZE );
61648 assert( 32 == WAL_HDRSIZE );
61649 assert( 120 == WALINDEX_LOCK_OFFSET + WAL_WRITE_LOCK );
61650 assert( 121 == WALINDEX_LOCK_OFFSET + WAL_CKPT_LOCK );
61651 assert( 122 == WALINDEX_LOCK_OFFSET + WAL_RECOVER_LOCK );
61652 assert( 123 == WALINDEX_LOCK_OFFSET + WAL_READ_LOCK(0) );
61653 assert( 124 == WALINDEX_LOCK_OFFSET + WAL_READ_LOCK(1) );
61654 assert( 125 == WALINDEX_LOCK_OFFSET + WAL_READ_LOCK(2) );
61655 assert( 126 == WALINDEX_LOCK_OFFSET + WAL_READ_LOCK(3) );
61656 assert( 127 == WALINDEX_LOCK_OFFSET + WAL_READ_LOCK(4) );
61657
61658 /* In the amalgamation, the os_unix.c and os_win.c source files come before
61659 ** this source file. Verify that the #defines of the locking byte offsets
61660 ** in os_unix.c and os_win.c agree with the WALINDEX_LOCK_OFFSET value.
61661 ** For that matter, if the lock offset ever changes from its initial design
61662 ** value of 120, we need to know that so there is an assert() to check it.
61663 */
 
 
61664 #ifdef WIN_SHM_BASE
61665 assert( WIN_SHM_BASE==WALINDEX_LOCK_OFFSET );
61666 #endif
61667 #ifdef UNIX_SHM_BASE
61668 assert( UNIX_SHM_BASE==WALINDEX_LOCK_OFFSET );
@@ -80741,11 +80538,11 @@
80538 }
80539 #endif
80540 case P4_COLLSEQ: {
80541 static const char *const encnames[] = {"?", "8", "16LE", "16BE"};
80542 CollSeq *pColl = pOp->p4.pColl;
80543 assert( pColl->enc<4 );
80544 sqlite3_str_appendf(&x, "%.18s-%s", pColl->zName,
80545 encnames[pColl->enc]);
80546 break;
80547 }
80548 case P4_FUNCDEF: {
@@ -87207,100 +87004,11 @@
87004
87005 /*
87006 ** hwtime.h contains inline assembler code for implementing
87007 ** high-performance timing routines.
87008 */
87009 /* #include "hwtime.h" */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87010
87011 #endif
87012
87013 #ifndef NDEBUG
87014 /*
@@ -95148,11 +94856,11 @@
94856 if( pTab && !HasRowid(pTab) ){
94857 pTab = 0;
94858 sqlite3ErrorMsg(&sParse, "cannot open table without rowid: %s", zTable);
94859 }
94860 #ifndef SQLITE_OMIT_VIEW
94861 if( pTab && IsView(pTab) ){
94862 pTab = 0;
94863 sqlite3ErrorMsg(&sParse, "cannot open view: %s", zTable);
94864 }
94865 #endif
94866 if( !pTab ){
@@ -95168,11 +94876,11 @@
94876 pBlob->pTab = pTab;
94877 pBlob->zDb = db->aDb[sqlite3SchemaToIndex(db, pTab->pSchema)].zDbSName;
94878
94879 /* Now search pTab for the exact column. */
94880 for(iCol=0; iCol<pTab->nCol; iCol++) {
94881 if( sqlite3StrICmp(pTab->aCol[iCol].zCnName, zColumn)==0 ){
94882 break;
94883 }
94884 }
94885 if( iCol==pTab->nCol ){
94886 sqlite3DbFree(db, zErr);
@@ -95193,11 +94901,12 @@
94901 /* Check that the column is not part of an FK child key definition. It
94902 ** is not necessary to check if it is part of a parent key, as parent
94903 ** key columns must be indexed. The check below will pick up this
94904 ** case. */
94905 FKey *pFKey;
94906 assert( !IsVirtual(pTab) );
94907 for(pFKey=pTab->u.tab.pFKey; pFKey; pFKey=pFKey->pNextFrom){
94908 int j;
94909 for(j=0; j<pFKey->nCol; j++){
94910 if( pFKey->aCol[j].iFrom==iCol ){
94911 zFault = "foreign key";
94912 }
@@ -99719,11 +99428,13 @@
99428 sqlite3RenameTokenRemap(pParse, 0, (void*)&pExpr->y.pTab);
99429 }
99430 }
99431 hCol = sqlite3StrIHash(zCol);
99432 for(j=0, pCol=pTab->aCol; j<pTab->nCol; j++, pCol++){
99433 if( pCol->hName==hCol
99434 && sqlite3StrICmp(pCol->zCnName, zCol)==0
99435 ){
99436 /* If there has been exactly one prior match and this match
99437 ** is for the right-hand table of a NATURAL JOIN or is in a
99438 ** USING clause, then skip this match.
99439 */
99440 if( cnt==1 ){
@@ -99796,11 +99507,13 @@
99507 int iCol;
99508 u8 hCol = sqlite3StrIHash(zCol);
99509 pSchema = pTab->pSchema;
99510 cntTab++;
99511 for(iCol=0, pCol=pTab->aCol; iCol<pTab->nCol; iCol++, pCol++){
99512 if( pCol->hName==hCol
99513 && sqlite3StrICmp(pCol->zCnName, zCol)==0
99514 ){
99515 if( iCol==pTab->iPKey ){
99516 iCol = -1;
99517 }
99518 break;
99519 }
@@ -100204,10 +99917,11 @@
99917 for(i=0, p=pNC; p && i<ArraySize(anRef); p=p->pNext, i++){
99918 anRef[i] = p->nRef;
99919 }
99920 sqlite3WalkExpr(pWalker, pExpr->pLeft);
99921 if( 0==sqlite3ExprCanBeNull(pExpr->pLeft) && !IN_RENAME_OBJECT ){
99922 testcase( ExprHasProperty(pExpr, EP_FromJoin) );
99923 if( pExpr->op==TK_NOTNULL ){
99924 pExpr->u.zToken = "true";
99925 ExprSetProperty(pExpr, EP_IsTrue);
99926 }else{
99927 pExpr->u.zToken = "false";
@@ -101582,11 +101296,11 @@
101296 ){
101297 /* op==TK_REGISTER && p->y.pTab!=0 happens when pExpr was originally
101298 ** a TK_COLUMN but was previously evaluated and cached in a register */
101299 int j = p->iColumn;
101300 if( j>=0 ){
101301 const char *zColl = sqlite3ColumnColl(&p->y.pTab->aCol[j]);
101302 pColl = sqlite3FindCollSeq(db, ENC(db), zColl, 0);
101303 }
101304 break;
101305 }
101306 if( op==TK_CAST || op==TK_UPLUS ){
@@ -103922,11 +103636,11 @@
103636 assert( pSrc!=0 );
103637 if( pSrc->nSrc!=1 ) return 0; /* Single term in FROM clause */
103638 if( pSrc->a[0].pSelect ) return 0; /* FROM is not a subquery or view */
103639 pTab = pSrc->a[0].pTab;
103640 assert( pTab!=0 );
103641 assert( !IsView(pTab) ); /* FROM clause is not a view */
103642 if( IsVirtual(pTab) ) return 0; /* FROM clause not a virtual table */
103643 pEList = p->pEList;
103644 assert( pEList!=0 );
103645 /* All SELECT results must be columns. */
103646 for(i=0; i<pEList->nExpr; i++){
@@ -105052,13 +104766,14 @@
104766 /*
104767 ** Generate code that will compute the value of generated column pCol
104768 ** and store the result in register regOut
104769 */
104770 SQLITE_PRIVATE void sqlite3ExprCodeGeneratedColumn(
104771 Parse *pParse, /* Parsing context */
104772 Table *pTab, /* Table containing the generated column */
104773 Column *pCol, /* The generated column */
104774 int regOut /* Put the result in this register */
104775 ){
104776 int iAddr;
104777 Vdbe *v = pParse->pVdbe;
104778 assert( v!=0 );
104779 assert( pParse->iSelfTab!=0 );
@@ -105065,11 +104780,11 @@
104780 if( pParse->iSelfTab>0 ){
104781 iAddr = sqlite3VdbeAddOp3(v, OP_IfNullRow, pParse->iSelfTab-1, 0, regOut);
104782 }else{
104783 iAddr = 0;
104784 }
104785 sqlite3ExprCodeCopy(pParse, sqlite3ColumnExpr(pTab,pCol), regOut);
104786 if( pCol->affinity>=SQLITE_AFF_TEXT ){
104787 sqlite3VdbeAddOp4(v, OP_Affinity, regOut, 1, 0, &pCol->affinity, 1);
104788 }
104789 if( iAddr ) sqlite3VdbeJumpHere(v, iAddr);
104790 }
@@ -105101,16 +104816,17 @@
104816 x = iCol;
104817 #ifndef SQLITE_OMIT_GENERATED_COLUMNS
104818 }else if( (pCol = &pTab->aCol[iCol])->colFlags & COLFLAG_VIRTUAL ){
104819 Parse *pParse = sqlite3VdbeParser(v);
104820 if( pCol->colFlags & COLFLAG_BUSY ){
104821 sqlite3ErrorMsg(pParse, "generated column loop on \"%s\"",
104822 pCol->zCnName);
104823 }else{
104824 int savedSelfTab = pParse->iSelfTab;
104825 pCol->colFlags |= COLFLAG_BUSY;
104826 pParse->iSelfTab = iTabCur+1;
104827 sqlite3ExprCodeGeneratedColumn(pParse, pTab, pCol, regOut);
104828 pParse->iSelfTab = savedSelfTab;
104829 pCol->colFlags &= ~COLFLAG_BUSY;
104830 }
104831 return;
104832 #endif
@@ -105374,11 +105090,12 @@
105090 sqlite3VdbeAddOp3(v, OP_Column, pAggInfo->sortingIdxPTab,
105091 pCol->iSorterColumn, target);
105092 if( pCol->iColumn<0 ){
105093 VdbeComment((v,"%s.rowid",pTab->zName));
105094 }else{
105095 VdbeComment((v,"%s.%s",
105096 pTab->zName, pTab->aCol[pCol->iColumn].zCnName));
105097 if( pTab->aCol[pCol->iColumn].affinity==SQLITE_AFF_REAL ){
105098 sqlite3VdbeAddOp1(v, OP_RealAffinity, target);
105099 }
105100 }
105101 return target;
@@ -105435,16 +105152,16 @@
105152 iSrc = sqlite3TableColumnToStorage(pTab, iCol) - pParse->iSelfTab;
105153 #ifndef SQLITE_OMIT_GENERATED_COLUMNS
105154 if( pCol->colFlags & COLFLAG_GENERATED ){
105155 if( pCol->colFlags & COLFLAG_BUSY ){
105156 sqlite3ErrorMsg(pParse, "generated column loop on \"%s\"",
105157 pCol->zCnName);
105158 return 0;
105159 }
105160 pCol->colFlags |= COLFLAG_BUSY;
105161 if( pCol->colFlags & COLFLAG_NOTAVAIL ){
105162 sqlite3ExprCodeGeneratedColumn(pParse, pTab, pCol, iSrc);
105163 }
105164 pCol->colFlags &= ~(COLFLAG_BUSY|COLFLAG_NOTAVAIL);
105165 return iSrc;
105166 }else
105167 #endif /* SQLITE_OMIT_GENERATED_COLUMNS */
@@ -105918,11 +105635,11 @@
105635 assert( p1>=0 && p1<(pTab->nCol*2+2) );
105636
105637 sqlite3VdbeAddOp2(v, OP_Param, p1, target);
105638 VdbeComment((v, "r[%d]=%s.%s", target,
105639 (pExpr->iTable ? "new" : "old"),
105640 (pExpr->iColumn<0 ? "rowid" : pExpr->y.pTab->aCol[iCol].zCnName)
105641 ));
105642
105643 #ifndef SQLITE_OMIT_FLOATING_POINT
105644 /* If the column has REAL affinity, it may currently be stored as an
105645 ** integer. Use OP_RealAffinity to make sure it is really real.
@@ -107090,13 +106807,13 @@
106807 testcase( pExpr->op==TK_LE );
106808 testcase( pExpr->op==TK_GT );
106809 testcase( pExpr->op==TK_GE );
106810 /* The y.pTab=0 assignment in wherecode.c always happens after the
106811 ** impliesNotNullRow() test */
106812 if( (pLeft->op==TK_COLUMN && pLeft->y.pTab!=0
106813 && IsVirtual(pLeft->y.pTab))
106814 || (pRight->op==TK_COLUMN && pRight->y.pTab!=0
106815 && IsVirtual(pRight->y.pTab))
106816 ){
106817 return WRC_Prune;
106818 }
106819 /* no break */ deliberate_fall_through
@@ -107771,22 +107488,19 @@
107488 sqlite3 *db = pParse->db; /* Database connection */
107489 int nTabName; /* Number of UTF-8 characters in zTabName */
107490 const char *zTabName; /* Original name of the table */
107491 Vdbe *v;
107492 VTable *pVTab = 0; /* Non-zero if this is a v-tab with an xRename() */
 
107493
 
107494 if( NEVER(db->mallocFailed) ) goto exit_rename_table;
107495 assert( pSrc->nSrc==1 );
107496 assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );
107497
107498 pTab = sqlite3LocateTableItem(pParse, 0, &pSrc->a[0]);
107499 if( !pTab ) goto exit_rename_table;
107500 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
107501 zDb = db->aDb[iDb].zDbSName;
 
107502
107503 /* Get a NULL terminated version of the new table name. */
107504 zName = sqlite3NameFromToken(db, pName);
107505 if( !zName ) goto exit_rename_table;
107506
@@ -107811,11 +107525,11 @@
107525 if( SQLITE_OK!=sqlite3CheckObjectName(pParse,zName,"table",zName) ){
107526 goto exit_rename_table;
107527 }
107528
107529 #ifndef SQLITE_OMIT_VIEW
107530 if( IsView(pTab) ){
107531 sqlite3ErrorMsg(pParse, "view %s may not be altered", pTab->zName);
107532 goto exit_rename_table;
107533 }
107534 #endif
107535
@@ -107923,11 +107637,10 @@
107637 renameTestSchema(pParse, zDb, iDb==1, "after rename", 0);
107638
107639 exit_rename_table:
107640 sqlite3SrcListDelete(db, pSrc);
107641 sqlite3DbFree(db, zName);
 
107642 }
107643
107644 /*
107645 ** Write code that will raise an error if the table described by
107646 ** zDb and zTab is not empty.
@@ -107973,11 +107686,11 @@
107686 assert( sqlite3BtreeHoldsAllMutexes(db) );
107687 iDb = sqlite3SchemaToIndex(db, pNew->pSchema);
107688 zDb = db->aDb[iDb].zDbSName;
107689 zTab = &pNew->zName[16]; /* Skip the "sqlite_altertab_" prefix on the name */
107690 pCol = &pNew->aCol[pNew->nCol-1];
107691 pDflt = sqlite3ColumnExpr(pNew, pCol);
107692 pTab = sqlite3FindTable(db, zTab, zDb);
107693 assert( pTab );
107694
107695 #ifndef SQLITE_OMIT_AUTHORIZATION
107696 /* Invoke the authorization callback. */
@@ -108007,11 +107720,11 @@
107720 */
107721 assert( pDflt==0 || pDflt->op==TK_SPAN );
107722 if( pDflt && pDflt->pLeft->op==TK_NULL ){
107723 pDflt = 0;
107724 }
107725 if( (db->flags&SQLITE_ForeignKeys) && pNew->u.tab.pFKey && pDflt ){
107726 sqlite3ErrorIfNotEmpty(pParse, zDb, zTab,
107727 "Cannot add a REFERENCES column with non-NULL default value");
107728 }
107729 if( pCol->notNull && !pDflt ){
107730 sqlite3ErrorIfNotEmpty(pParse, zDb, zTab,
@@ -108044,27 +107757,25 @@
107757
107758 /* Modify the CREATE TABLE statement. */
107759 zCol = sqlite3DbStrNDup(db, (char*)pColDef->z, pColDef->n);
107760 if( zCol ){
107761 char *zEnd = &zCol[pColDef->n-1];
 
107762 while( zEnd>zCol && (*zEnd==';' || sqlite3Isspace(*zEnd)) ){
107763 *zEnd-- = '\0';
107764 }
 
107765 /* substr() operations on characters, but addColOffset is in bytes. So we
107766 ** have to use printf() to translate between these units: */
107767 assert( !IsVirtual(pTab) );
107768 sqlite3NestedParse(pParse,
107769 "UPDATE \"%w\"." DFLT_SCHEMA_TABLE " SET "
107770 "sql = printf('%%.%ds, ',sql) || %Q"
107771 " || substr(sql,1+length(printf('%%.%ds',sql))) "
107772 "WHERE type = 'table' AND name = %Q",
107773 zDb, pNew->u.tab.addColOffset, zCol, pNew->u.tab.addColOffset,
107774 zTab
107775 );
107776 sqlite3DbFree(db, zCol);
 
107777 }
107778
107779 v = sqlite3GetVdbe(pParse);
107780 if( v ){
107781 /* Make sure the schema version is at least 3. But do not upgrade
@@ -108136,20 +107847,20 @@
107847 goto exit_begin_add_column;
107848 }
107849 #endif
107850
107851 /* Make sure this is not an attempt to ALTER a view. */
107852 if( IsView(pTab) ){
107853 sqlite3ErrorMsg(pParse, "Cannot add a column to a view");
107854 goto exit_begin_add_column;
107855 }
107856 if( SQLITE_OK!=isAlterableTable(pParse, pTab) ){
107857 goto exit_begin_add_column;
107858 }
107859
107860 sqlite3MayAbort(pParse);
107861 assert( pTab->u.tab.addColOffset>0 );
107862 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
107863
107864 /* Put a copy of the Table struct in Parse.pNewTable for the
107865 ** sqlite3AddColumn() function and friends to modify. But modify
107866 ** the name by adding an "sqlite_altertab_" prefix. By adding this
@@ -108172,17 +107883,17 @@
107883 goto exit_begin_add_column;
107884 }
107885 memcpy(pNew->aCol, pTab->aCol, sizeof(Column)*pNew->nCol);
107886 for(i=0; i<pNew->nCol; i++){
107887 Column *pCol = &pNew->aCol[i];
107888 pCol->zCnName = sqlite3DbStrDup(db, pCol->zCnName);
107889 pCol->hName = sqlite3StrIHash(pCol->zCnName);
 
 
107890 }
107891 assert( !IsVirtual(pNew) );
107892 pNew->u.tab.pDfltList = sqlite3ExprListDup(db, pTab->u.tab.pDfltList, 0);
107893 pNew->pSchema = db->aDb[iDb].pSchema;
107894 pNew->u.tab.addColOffset = pTab->u.tab.addColOffset;
107895 pNew->nTabRef = 1;
107896
107897 exit_begin_add_column:
107898 sqlite3SrcListDelete(db, pSrc);
107899 return;
@@ -108198,11 +107909,11 @@
107909 */
107910 #if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_VIRTUALTABLE)
107911 static int isRealTable(Parse *pParse, Table *pTab, int bDrop){
107912 const char *zType = 0;
107913 #ifndef SQLITE_OMIT_VIEW
107914 if( IsView(pTab) ){
107915 zType = "view";
107916 }
107917 #endif
107918 #ifndef SQLITE_OMIT_VIRTUALTABLE
107919 if( IsVirtual(pTab) ){
@@ -108265,11 +107976,11 @@
107976 /* Make sure the old name really is a column name in the table to be
107977 ** altered. Set iCol to be the index of the column being renamed */
107978 zOld = sqlite3NameFromToken(db, pOld);
107979 if( !zOld ) goto exit_rename_column;
107980 for(iCol=0; iCol<pTab->nCol; iCol++){
107981 if( 0==sqlite3StrICmp(pTab->aCol[iCol].zCnName, zOld) ) break;
107982 }
107983 if( iCol==pTab->nCol ){
107984 sqlite3ErrorMsg(pParse, "no such column: \"%s\"", zOld);
107985 goto exit_rename_column;
107986 }
@@ -109111,11 +108822,11 @@
108822 pTab = sqlite3FindTable(db, zTable, zDb);
108823 if( pTab==0 || iCol>=pTab->nCol ){
108824 sqlite3BtreeLeaveAll(db);
108825 return;
108826 }
108827 zOld = pTab->aCol[iCol].zCnName;
108828 memset(&sCtx, 0, sizeof(sCtx));
108829 sCtx.iCol = ((iCol==pTab->iPKey) ? -1 : iCol);
108830
108831 #ifndef SQLITE_OMIT_AUTHORIZATION
108832 db->xAuth = 0;
@@ -109130,30 +108841,29 @@
108841 sWalker.u.pRename = &sCtx;
108842
108843 sCtx.pTab = pTab;
108844 if( rc!=SQLITE_OK ) goto renameColumnFunc_done;
108845 if( sParse.pNewTable ){
108846 if( IsView(sParse.pNewTable) ){
108847 Select *pSelect = sParse.pNewTable->u.view.pSelect;
108848 pSelect->selFlags &= ~SF_View;
108849 sParse.rc = SQLITE_OK;
108850 sqlite3SelectPrep(&sParse, pSelect, 0);
108851 rc = (db->mallocFailed ? SQLITE_NOMEM : sParse.rc);
108852 if( rc==SQLITE_OK ){
108853 sqlite3WalkSelect(&sWalker, pSelect);
108854 }
108855 if( rc!=SQLITE_OK ) goto renameColumnFunc_done;
108856 }else if( ALWAYS(IsOrdinaryTable(sParse.pNewTable)) ){
108857 /* A regular table */
108858 int bFKOnly = sqlite3_stricmp(zTable, sParse.pNewTable->zName);
108859 FKey *pFKey;
 
108860 sCtx.pTab = sParse.pNewTable;
108861 if( bFKOnly==0 ){
108862 if( iCol<sParse.pNewTable->nCol ){
108863 renameTokenFind(
108864 &sParse, &sCtx, (void*)sParse.pNewTable->aCol[iCol].zCnName
108865 );
108866 }
108867 if( sCtx.iCol<0 ){
108868 renameTokenFind(&sParse, &sCtx, (void*)&sParse.pNewTable->iPKey);
108869 }
@@ -109164,16 +108874,19 @@
108874 for(pIdx=sParse.pNewIndex; pIdx; pIdx=pIdx->pNext){
108875 sqlite3WalkExprList(&sWalker, pIdx->aColExpr);
108876 }
108877 #ifndef SQLITE_OMIT_GENERATED_COLUMNS
108878 for(i=0; i<sParse.pNewTable->nCol; i++){
108879 Expr *pExpr = sqlite3ColumnExpr(sParse.pNewTable,
108880 &sParse.pNewTable->aCol[i]);
108881 sqlite3WalkExpr(&sWalker, pExpr);
108882 }
108883 #endif
108884 }
108885
108886 assert( !IsVirtual(sParse.pNewTable) );
108887 for(pFKey=sParse.pNewTable->u.tab.pFKey; pFKey; pFKey=pFKey->pNextFrom){
108888 for(i=0; i<pFKey->nCol; i++){
108889 if( bFKOnly==0 && pFKey->aCol[i].iFrom==iCol ){
108890 renameTokenFind(&sParse, &sCtx, (void*)&pFKey->aCol[i]);
108891 }
108892 if( 0==sqlite3_stricmp(pFKey->zTo, zTable)
@@ -109335,32 +109048,35 @@
109048 if( rc==SQLITE_OK ){
109049 int isLegacy = (db->flags & SQLITE_LegacyAlter);
109050 if( sParse.pNewTable ){
109051 Table *pTab = sParse.pNewTable;
109052
109053 if( IsView(pTab) ){
109054 if( isLegacy==0 ){
109055 Select *pSelect = pTab->u.view.pSelect;
109056 NameContext sNC;
109057 memset(&sNC, 0, sizeof(sNC));
109058 sNC.pParse = &sParse;
109059
109060 assert( pSelect->selFlags & SF_View );
109061 pSelect->selFlags &= ~SF_View;
109062 sqlite3SelectPrep(&sParse, pTab->u.view.pSelect, &sNC);
109063 if( sParse.nErr ){
109064 rc = sParse.rc;
109065 }else{
109066 sqlite3WalkSelect(&sWalker, pTab->u.view.pSelect);
109067 }
109068 }
109069 }else{
109070 /* Modify any FK definitions to point to the new table. */
109071 #ifndef SQLITE_OMIT_FOREIGN_KEY
109072 if( (isLegacy==0 || (db->flags & SQLITE_ForeignKeys))
109073 && !IsVirtual(pTab)
109074 ){
109075 FKey *pFKey;
109076 assert( !IsVirtual(pTab) );
109077 for(pFKey=pTab->u.tab.pFKey; pFKey; pFKey=pFKey->pNextFrom){
109078 if( sqlite3_stricmp(pFKey->zTo, zOld)==0 ){
109079 renameTokenFind(&sParse, &sCtx, (void*)pFKey->zTo);
109080 }
109081 }
109082 }
@@ -109496,12 +109212,12 @@
109212 sWalker.xExprCallback = renameQuotefixExprCb;
109213 sWalker.xSelectCallback = renameColumnSelectCb;
109214 sWalker.u.pRename = &sCtx;
109215
109216 if( sParse.pNewTable ){
109217 if( IsView(sParse.pNewTable) ){
109218 Select *pSelect = sParse.pNewTable->u.view.pSelect;
109219 pSelect->selFlags &= ~SF_View;
109220 sParse.rc = SQLITE_OK;
109221 sqlite3SelectPrep(&sParse, pSelect, 0);
109222 rc = (db->mallocFailed ? SQLITE_NOMEM : sParse.rc);
109223 if( rc==SQLITE_OK ){
@@ -109510,11 +109226,13 @@
109226 }else{
109227 int i;
109228 sqlite3WalkExprList(&sWalker, sParse.pNewTable->pCheck);
109229 #ifndef SQLITE_OMIT_GENERATED_COLUMNS
109230 for(i=0; i<sParse.pNewTable->nCol; i++){
109231 sqlite3WalkExpr(&sWalker,
109232 sqlite3ColumnExpr(sParse.pNewTable,
109233 &sParse.pNewTable->aCol[i]));
109234 }
109235 #endif /* SQLITE_OMIT_GENERATED_COLUMNS */
109236 }
109237 }else if( sParse.pNewIndex ){
109238 sqlite3WalkExprList(&sWalker, sParse.pNewIndex->aColExpr);
@@ -109593,15 +109311,15 @@
109311 int flags = db->flags;
109312 if( bNoDQS ) db->flags &= ~(SQLITE_DqsDML|SQLITE_DqsDDL);
109313 rc = renameParseSql(&sParse, zDb, db, zInput, bTemp);
109314 db->flags |= (flags & (SQLITE_DqsDML|SQLITE_DqsDDL));
109315 if( rc==SQLITE_OK ){
109316 if( isLegacy==0 && sParse.pNewTable && IsView(sParse.pNewTable) ){
109317 NameContext sNC;
109318 memset(&sNC, 0, sizeof(sNC));
109319 sNC.pParse = &sParse;
109320 sqlite3SelectPrep(&sParse, sParse.pNewTable->u.view.pSelect, &sNC);
109321 if( sParse.nErr ) rc = sParse.rc;
109322 }
109323
109324 else if( sParse.pNewTrigger ){
109325 if( isLegacy==0 ){
@@ -109668,17 +109386,18 @@
109386 /* This can happen if the sqlite_schema table is corrupt */
109387 rc = SQLITE_CORRUPT_BKPT;
109388 goto drop_column_done;
109389 }
109390
109391 pCol = renameTokenFind(&sParse, 0, (void*)pTab->aCol[iCol].zCnName);
109392 if( iCol<pTab->nCol-1 ){
109393 RenameToken *pEnd;
109394 pEnd = renameTokenFind(&sParse, 0, (void*)pTab->aCol[iCol+1].zCnName);
109395 zEnd = (const char*)pEnd->t.z;
109396 }else{
109397 assert( !IsVirtual(pTab) );
109398 zEnd = (const char*)&zSql[pTab->u.tab.addColOffset];
109399 while( ALWAYS(pCol->t.z[0]!=0) && pCol->t.z[0]!=',' ) pCol->t.z--;
109400 }
109401
109402 zNew = sqlite3MPrintf(db, "%.*s%s", pCol->t.z-zSql, zSql, zEnd);
109403 sqlite3_result_text(context, zNew, -1, SQLITE_TRANSIENT);
@@ -109809,10 +109528,16 @@
109528 }else{
109529 sqlite3ExprCodeGetColumnOfTable(v, pTab, iCur, i, regOut);
109530 }
109531 nField++;
109532 }
109533 }
109534 if( nField==0 ){
109535 /* dbsqlfuzz 5f09e7bcc78b4954d06bf9f2400d7715f48d1fef */
109536 pParse->nMem++;
109537 sqlite3VdbeAddOp2(v, OP_Null, 0, reg+1);
109538 nField = 1;
109539 }
109540 sqlite3VdbeAddOp3(v, OP_MakeRecord, reg+1, nField, regRec);
109541 if( pPk ){
109542 sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iCur, regRec, reg+1, pPk->nKeyCol);
109543 }else{
@@ -110814,11 +110539,11 @@
110539 if( NEVER(i==XN_ROWID) ){
110540 VdbeComment((v,"%s.rowid",pIdx->zName));
110541 }else if( i==XN_EXPR ){
110542 VdbeComment((v,"%s.expr(%d)",pIdx->zName, k));
110543 }else{
110544 VdbeComment((v,"%s.%s", pIdx->zName, pIdx->pTable->aCol[i].zCnName));
110545 }
110546 }
110547 #else
110548 # define analyzeVdbeCommentIndexWithColumnName(a,b,c)
110549 #endif /* SQLITE_DEBUG */
@@ -112567,14 +112292,14 @@
112292 iCol = pExpr->iColumn;
112293 if( pTab==0 ) return;
112294
112295 if( iCol>=0 ){
112296 assert( iCol<pTab->nCol );
112297 zCol = pTab->aCol[iCol].zCnName;
112298 }else if( pTab->iPKey>=0 ){
112299 assert( pTab->iPKey<pTab->nCol );
112300 zCol = pTab->aCol[pTab->iPKey].zCnName;
112301 }else{
112302 zCol = "ROWID";
112303 }
112304 assert( iDb>=0 && iDb<pParse->db->nDb );
112305 if( SQLITE_IGNORE==sqlite3AuthReadCol(pParse, pTab->zName, zCol, iDb) ){
@@ -112948,24 +112673,26 @@
112673 }
112674
112675 /*
112676 ** Run the parser and code generator recursively in order to generate
112677 ** code for the SQL statement given onto the end of the pParse context
112678 ** currently under construction. Notes:
 
 
 
112679 **
112680 ** * The final OP_Halt is not appended and other initialization
112681 ** and finalization steps are omitted because those are handling by the
112682 ** outermost parser.
112683 **
112684 ** * Built-in SQL functions always take precedence over application-defined
112685 ** SQL functions. In other words, it is not possible to override a
112686 ** built-in function.
112687 */
112688 SQLITE_PRIVATE void sqlite3NestedParse(Parse *pParse, const char *zFormat, ...){
112689 va_list ap;
112690 char *zSql;
112691 char *zErrMsg = 0;
112692 sqlite3 *db = pParse->db;
112693 u32 savedDbFlags = db->mDbFlags;
112694 char saveBuf[PARSE_TAIL_SZ];
112695
112696 if( pParse->nErr ) return;
112697 assert( pParse->nested<10 ); /* Nesting should only be of limited depth */
112698 va_start(ap, zFormat);
@@ -112980,11 +112707,13 @@
112707 return;
112708 }
112709 pParse->nested++;
112710 memcpy(saveBuf, PARSE_TAIL(pParse), PARSE_TAIL_SZ);
112711 memset(PARSE_TAIL(pParse), 0, PARSE_TAIL_SZ);
112712 db->mDbFlags |= DBFLAG_PreferBuiltin;
112713 sqlite3RunParser(pParse, zSql, &zErrMsg);
112714 db->mDbFlags = savedDbFlags;
112715 sqlite3DbFree(db, zErrMsg);
112716 sqlite3DbFree(db, zSql);
112717 memcpy(PARSE_TAIL(pParse), saveBuf, PARSE_TAIL_SZ);
112718 pParse->nested--;
112719 }
@@ -113329,10 +113058,88 @@
113058 ** This routine is called when a commit occurs.
113059 */
113060 SQLITE_PRIVATE void sqlite3CommitInternalChanges(sqlite3 *db){
113061 db->mDbFlags &= ~DBFLAG_SchemaChange;
113062 }
113063
113064 /*
113065 ** Set the expression associated with a column. This is usually
113066 ** the DEFAULT value, but might also be the expression that computes
113067 ** the value for a generated column.
113068 */
113069 SQLITE_PRIVATE void sqlite3ColumnSetExpr(
113070 Parse *pParse, /* Parsing context */
113071 Table *pTab, /* The table containing the column */
113072 Column *pCol, /* The column to receive the new DEFAULT expression */
113073 Expr *pExpr /* The new default expression */
113074 ){
113075 ExprList *pList;
113076 assert( !IsVirtual(pTab) );
113077 pList = pTab->u.tab.pDfltList;
113078 if( pCol->iDflt==0
113079 || NEVER(pList==0)
113080 || NEVER(pList->nExpr<pCol->iDflt)
113081 ){
113082 pCol->iDflt = pList==0 ? 1 : pList->nExpr+1;
113083 pTab->u.tab.pDfltList = sqlite3ExprListAppend(pParse, pList, pExpr);
113084 }else{
113085 sqlite3ExprDelete(pParse->db, pList->a[pCol->iDflt-1].pExpr);
113086 pList->a[pCol->iDflt-1].pExpr = pExpr;
113087 }
113088 }
113089
113090 /*
113091 ** Return the expression associated with a column. The expression might be
113092 ** the DEFAULT clause or the AS clause of a generated column.
113093 ** Return NULL if the column has no associated expression.
113094 */
113095 SQLITE_PRIVATE Expr *sqlite3ColumnExpr(Table *pTab, Column *pCol){
113096 if( pCol->iDflt==0 ) return 0;
113097 if( NEVER(IsVirtual(pTab)) ) return 0;
113098 if( NEVER(pTab->u.tab.pDfltList==0) ) return 0;
113099 if( NEVER(pTab->u.tab.pDfltList->nExpr<pCol->iDflt) ) return 0;
113100 return pTab->u.tab.pDfltList->a[pCol->iDflt-1].pExpr;
113101 }
113102
113103 /*
113104 ** Set the collating sequence name for a column.
113105 */
113106 SQLITE_PRIVATE void sqlite3ColumnSetColl(
113107 sqlite3 *db,
113108 Column *pCol,
113109 const char *zColl
113110 ){
113111 int nColl;
113112 int n;
113113 char *zNew;
113114 assert( zColl!=0 );
113115 n = sqlite3Strlen30(pCol->zCnName) + 1;
113116 if( pCol->colFlags & COLFLAG_HASTYPE ){
113117 n += sqlite3Strlen30(pCol->zCnName+n) + 1;
113118 }
113119 nColl = sqlite3Strlen30(zColl) + 1;
113120 zNew = sqlite3DbRealloc(db, pCol->zCnName, nColl+n);
113121 if( zNew ){
113122 pCol->zCnName = zNew;
113123 memcpy(pCol->zCnName + n, zColl, nColl);
113124 pCol->colFlags |= COLFLAG_HASCOLL;
113125 }
113126 }
113127
113128 /*
113129 ** Return the collating squence name for a column
113130 */
113131 SQLITE_PRIVATE const char *sqlite3ColumnColl(Column *pCol){
113132 const char *z;
113133 if( (pCol->colFlags & COLFLAG_HASCOLL)==0 ) return 0;
113134 z = pCol->zCnName;
113135 while( *z ){ z++; }
113136 if( pCol->colFlags & COLFLAG_HASTYPE ){
113137 do{ z++; }while( *z );
113138 }
113139 return z+1;
113140 }
113141
113142 /*
113143 ** Delete memory allocated for the column names of a table or view (the
113144 ** Table.aCol[] array).
113145 */
@@ -113340,16 +113147,24 @@
113147 int i;
113148 Column *pCol;
113149 assert( pTable!=0 );
113150 if( (pCol = pTable->aCol)!=0 ){
113151 for(i=0; i<pTable->nCol; i++, pCol++){
113152 assert( pCol->zCnName==0 || pCol->hName==sqlite3StrIHash(pCol->zCnName) );
113153 sqlite3DbFree(db, pCol->zCnName);
 
 
113154 }
113155 sqlite3DbFree(db, pTable->aCol);
113156 if( !IsVirtual(pTable) ){
113157 sqlite3ExprListDelete(db, pTable->u.tab.pDfltList);
113158 }
113159 if( db==0 || db->pnBytesFreed==0 ){
113160 pTable->aCol = 0;
113161 pTable->nCol = 0;
113162 if( !IsVirtual(pTable) ){
113163 pTable->u.tab.pDfltList = 0;
113164 }
113165 }
113166 }
113167 }
113168
113169 /*
113170 ** Remove the memory data structures associated with the given
@@ -113397,23 +113212,29 @@
113212 assert( pOld==pIndex || pOld==0 );
113213 }
113214 sqlite3FreeIndex(db, pIndex);
113215 }
113216
113217 if( IsOrdinaryTable(pTable) ){
113218 sqlite3FkDelete(db, pTable);
113219 }
113220 #ifndef SQLITE_OMIT_VIRTUAL_TABLE
113221 else if( IsVirtual(pTable) ){
113222 sqlite3VtabClear(db, pTable);
113223 }
113224 #endif
113225 else{
113226 assert( IsView(pTable) );
113227 sqlite3SelectDelete(db, pTable->u.view.pSelect);
113228 }
113229
113230 /* Delete the Table structure itself.
113231 */
113232 sqlite3DeleteColumnNames(db, pTable);
113233 sqlite3DbFree(db, pTable->zName);
113234 sqlite3DbFree(db, pTable->zColAff);
 
113235 sqlite3ExprListDelete(db, pTable->pCheck);
 
 
 
113236 sqlite3DbFree(db, pTable);
113237
113238 /* Verify that no lookaside memory was used by schema tables */
113239 assert( nLookaside==0 || nLookaside==sqlite3LookasideUsed(db,0) );
113240 }
@@ -113935,20 +113756,21 @@
113756 /* Normal (non-error) return. */
113757 return;
113758
113759 /* If an error occurs, we jump here */
113760 begin_table_error:
113761 pParse->checkSchema = 1;
113762 sqlite3DbFree(db, zName);
113763 return;
113764 }
113765
113766 /* Set properties of a table column based on the (magical)
113767 ** name of the column.
113768 */
113769 #if SQLITE_ENABLE_HIDDEN_COLUMNS
113770 SQLITE_PRIVATE void sqlite3ColumnPropertiesFromName(Table *pTab, Column *pCol){
113771 if( sqlite3_strnicmp(pCol->zCnName, "__hidden__", 10)==0 ){
113772 pCol->colFlags |= COLFLAG_HIDDEN;
113773 if( pTab ) pTab->tabFlags |= TF_HasHidden;
113774 }else if( pTab && pCol!=pTab->aCol && (pCol[-1].colFlags & COLFLAG_HIDDEN) ){
113775 pTab->tabFlags |= TF_OOOHidden;
113776 }
@@ -114035,67 +113857,108 @@
113857 ** The parser calls this routine once for each column declaration
113858 ** in a CREATE TABLE statement. sqlite3StartTable() gets called
113859 ** first to get things going. Then this routine is called for each
113860 ** column.
113861 */
113862 SQLITE_PRIVATE void sqlite3AddColumn(Parse *pParse, Token sName, Token sType){
113863 Table *p;
113864 int i;
113865 char *z;
113866 char *zType;
113867 Column *pCol;
113868 sqlite3 *db = pParse->db;
113869 u8 hName;
113870 Column *aNew;
113871 u8 eType = COLTYPE_CUSTOM;
113872 u8 szEst = 1;
113873 char affinity = SQLITE_AFF_BLOB;
113874
113875 if( (p = pParse->pNewTable)==0 ) return;
113876 if( p->nCol+1>db->aLimit[SQLITE_LIMIT_COLUMN] ){
113877 sqlite3ErrorMsg(pParse, "too many columns on %s", p->zName);
113878 return;
113879 }
113880 if( !IN_RENAME_OBJECT ) sqlite3DequoteToken(&sName);
113881
113882 /* Because keywords GENERATE ALWAYS can be converted into indentifiers
113883 ** by the parser, we can sometimes end up with a typename that ends
113884 ** with "generated always". Check for this case and omit the surplus
113885 ** text. */
113886 if( sType.n>=16
113887 && sqlite3_strnicmp(sType.z+(sType.n-6),"always",6)==0
113888 ){
113889 sType.n -= 6;
113890 while( ALWAYS(sType.n>0) && sqlite3Isspace(sType.z[sType.n-1]) ) sType.n--;
113891 if( sType.n>=9
113892 && sqlite3_strnicmp(sType.z+(sType.n-9),"generated",9)==0
113893 ){
113894 sType.n -= 9;
113895 while( sType.n>0 && sqlite3Isspace(sType.z[sType.n-1]) ) sType.n--;
113896 }
113897 }
113898
113899 /* Check for standard typenames. For standard typenames we will
113900 ** set the Column.eType field rather than storing the typename after
113901 ** the column name, in order to save space. */
113902 if( sType.n>=3 ){
113903 sqlite3DequoteToken(&sType);
113904 for(i=0; i<SQLITE_N_STDTYPE; i++){
113905 if( sType.n==sqlite3StdTypeLen[i]
113906 && sqlite3_strnicmp(sType.z, sqlite3StdType[i], sType.n)==0
113907 ){
113908 sType.n = 0;
113909 eType = i+1;
113910 affinity = sqlite3StdTypeAffinity[i];
113911 if( affinity<=SQLITE_AFF_TEXT ) szEst = 5;
113912 break;
113913 }
113914 }
113915 }
113916
113917 z = sqlite3DbMallocRaw(db, sName.n + 1 + sType.n + (sType.n>0) );
113918 if( z==0 ) return;
113919 if( IN_RENAME_OBJECT ) sqlite3RenameTokenMap(pParse, (void*)z, &sName);
113920 memcpy(z, sName.z, sName.n);
113921 z[sName.n] = 0;
113922 sqlite3Dequote(z);
113923 hName = sqlite3StrIHash(z);
113924 for(i=0; i<p->nCol; i++){
113925 if( p->aCol[i].hName==hName && sqlite3StrICmp(z, p->aCol[i].zCnName)==0 ){
113926 sqlite3ErrorMsg(pParse, "duplicate column name: %s", z);
113927 sqlite3DbFree(db, z);
113928 return;
113929 }
113930 }
113931 aNew = sqlite3DbRealloc(db,p->aCol,(p->nCol+1)*sizeof(p->aCol[0]));
113932 if( aNew==0 ){
113933 sqlite3DbFree(db, z);
113934 return;
113935 }
113936 p->aCol = aNew;
 
 
 
113937 pCol = &p->aCol[p->nCol];
113938 memset(pCol, 0, sizeof(p->aCol[0]));
113939 pCol->zCnName = z;
113940 pCol->hName = hName;
113941 sqlite3ColumnPropertiesFromName(p, pCol);
113942
113943 if( sType.n==0 ){
113944 /* If there is no type specified, columns have the default affinity
113945 ** 'BLOB' with a default size of 4 bytes. */
113946 pCol->affinity = affinity;
113947 pCol->eType = eType;
113948 pCol->szEst = szEst;
113949 #ifdef SQLITE_ENABLE_SORTER_REFERENCES
113950 if( affinity==SQLITE_AFF_BLOB ){
113951 if( 4>=sqlite3GlobalConfig.szSorterRef ){
113952 pCol->colFlags |= COLFLAG_SORTERREF;
113953 }
113954 }
113955 #endif
113956 }else{
113957 zType = z + sqlite3Strlen30(z) + 1;
113958 memcpy(zType, sType.z, sType.n);
113959 zType[sType.n] = 0;
113960 sqlite3Dequote(zType);
113961 pCol->affinity = sqlite3AffinityType(zType, pCol);
113962 pCol->colFlags |= COLFLAG_HASTYPE;
113963 }
113964 p->nCol++;
@@ -114246,11 +114109,11 @@
114109 if( p!=0 ){
114110 int isInit = db->init.busy && db->init.iDb!=1;
114111 pCol = &(p->aCol[p->nCol-1]);
114112 if( !sqlite3ExprIsConstantOrFunction(pExpr, isInit) ){
114113 sqlite3ErrorMsg(pParse, "default value of column [%s] is not constant",
114114 pCol->zCnName);
114115 #ifndef SQLITE_OMIT_GENERATED_COLUMNS
114116 }else if( pCol->colFlags & COLFLAG_GENERATED ){
114117 testcase( pCol->colFlags & COLFLAG_VIRTUAL );
114118 testcase( pCol->colFlags & COLFLAG_STORED );
114119 sqlite3ErrorMsg(pParse, "cannot use DEFAULT on a generated column");
@@ -114257,19 +114120,19 @@
114120 #endif
114121 }else{
114122 /* A copy of pExpr is used instead of the original, as pExpr contains
114123 ** tokens that point to volatile memory.
114124 */
114125 Expr x, *pDfltExpr;
 
114126 memset(&x, 0, sizeof(x));
114127 x.op = TK_SPAN;
114128 x.u.zToken = sqlite3DbSpanDup(db, zStart, zEnd);
114129 x.pLeft = pExpr;
114130 x.flags = EP_Skip;
114131 pDfltExpr = sqlite3ExprDup(db, &x, EXPRDUP_REDUCE);
114132 sqlite3DbFree(db, x.u.zToken);
114133 sqlite3ColumnSetExpr(pParse, p, pCol, pDfltExpr);
114134 }
114135 }
114136 if( IN_RENAME_OBJECT ){
114137 sqlite3RenameExprUnmap(pParse, pExpr);
114138 }
@@ -114363,11 +114226,11 @@
114226 assert( pCExpr!=0 );
114227 sqlite3StringToId(pCExpr);
114228 if( pCExpr->op==TK_ID ){
114229 const char *zCName = pCExpr->u.zToken;
114230 for(iCol=0; iCol<pTab->nCol; iCol++){
114231 if( sqlite3StrICmp(zCName, pTab->aCol[iCol].zCnName)==0 ){
114232 pCol = &pTab->aCol[iCol];
114233 makeColumnPartOfPrimaryKey(pParse, pCol);
114234 break;
114235 }
114236 }
@@ -114374,11 +114237,11 @@
114237 }
114238 }
114239 }
114240 if( nTerm==1
114241 && pCol
114242 && pCol->eType==COLTYPE_INTEGER
114243 && sortOrder!=SQLITE_SO_DESC
114244 ){
114245 if( IN_RENAME_OBJECT && pList ){
114246 Expr *pCExpr = sqlite3ExprSkipCollate(pList->a[0].pExpr);
114247 sqlite3RenameTokenRemap(pParse, &pTab->iPKey, pCExpr);
@@ -114454,26 +114317,24 @@
114317 zColl = sqlite3NameFromToken(db, pToken);
114318 if( !zColl ) return;
114319
114320 if( sqlite3LocateCollSeq(pParse, zColl) ){
114321 Index *pIdx;
114322 sqlite3ColumnSetColl(db, &p->aCol[i], zColl);
 
114323
114324 /* If the column is declared as "<name> PRIMARY KEY COLLATE <type>",
114325 ** then an index may have been created on this column before the
114326 ** collation type was added. Correct this if it is the case.
114327 */
114328 for(pIdx=p->pIndex; pIdx; pIdx=pIdx->pNext){
114329 assert( pIdx->nKeyCol==1 );
114330 if( pIdx->aiColumn[0]==i ){
114331 pIdx->azColl[0] = sqlite3ColumnColl(&p->aCol[i]);
114332 }
114333 }
 
 
114334 }
114335 sqlite3DbFree(db, zColl);
114336 }
114337
114338 /* Change the most recently parsed column to be a GENERATED ALWAYS AS
114339 ** column.
114340 */
@@ -114489,11 +114350,11 @@
114350 pCol = &(pTab->aCol[pTab->nCol-1]);
114351 if( IN_DECLARE_VTAB ){
114352 sqlite3ErrorMsg(pParse, "virtual tables cannot use computed columns");
114353 goto generated_done;
114354 }
114355 if( pCol->iDflt>0 ) goto generated_error;
114356 if( pType ){
114357 if( pType->n==7 && sqlite3StrNICmp("virtual",pType->z,7)==0 ){
114358 /* no-op */
114359 }else if( pType->n==6 && sqlite3StrNICmp("stored",pType->z,6)==0 ){
114360 eType = COLFLAG_STORED;
@@ -114507,17 +114368,17 @@
114368 assert( TF_HasStored==COLFLAG_STORED );
114369 pTab->tabFlags |= eType;
114370 if( pCol->colFlags & COLFLAG_PRIMKEY ){
114371 makeColumnPartOfPrimaryKey(pParse, pCol); /* For the error message */
114372 }
114373 sqlite3ColumnSetExpr(pParse, pTab, pCol, pExpr);
114374 pExpr = 0;
114375 goto generated_done;
114376
114377 generated_error:
114378 sqlite3ErrorMsg(pParse, "error in generated column \"%s\"",
114379 pCol->zCnName);
114380 generated_done:
114381 sqlite3ExprDelete(pParse->db, pExpr);
114382 #else
114383 /* Throw and error for the GENERATED ALWAYS AS clause if the
114384 ** SQLITE_OMIT_GENERATED_COLUMNS compile-time option is used. */
@@ -114615,11 +114476,11 @@
114476 char *zStmt;
114477 char *zSep, *zSep2, *zEnd;
114478 Column *pCol;
114479 n = 0;
114480 for(pCol = p->aCol, i=0; i<p->nCol; i++, pCol++){
114481 n += identLength(pCol->zCnName) + 5;
114482 }
114483 n += identLength(p->zName);
114484 if( n<50 ){
114485 zSep = "";
114486 zSep2 = ",";
@@ -114651,11 +114512,11 @@
114512 const char *zType;
114513
114514 sqlite3_snprintf(n-k, &zStmt[k], zSep);
114515 k += sqlite3Strlen30(&zStmt[k]);
114516 zSep = zSep2;
114517 identPut(zStmt, &k, pCol->zCnName);
114518 assert( pCol->affinity-SQLITE_AFF_BLOB >= 0 );
114519 assert( pCol->affinity-SQLITE_AFF_BLOB < ArraySize(azType) );
114520 testcase( pCol->affinity==SQLITE_AFF_BLOB );
114521 testcase( pCol->affinity==SQLITE_AFF_TEXT );
114522 testcase( pCol->affinity==SQLITE_AFF_NUMERIC );
@@ -114870,11 +114731,11 @@
114731 ** an INTEGER PRIMARY KEY table, create a new PRIMARY KEY index.
114732 */
114733 if( pTab->iPKey>=0 ){
114734 ExprList *pList;
114735 Token ipkToken;
114736 sqlite3TokenInit(&ipkToken, pTab->aCol[pTab->iPKey].zCnName);
114737 pList = sqlite3ExprListAppend(pParse, 0,
114738 sqlite3ExprAlloc(db, TK_ID, &ipkToken, 0));
114739 if( pList==0 ){
114740 pTab->tabFlags &= ~TF_WithoutRowid;
114741 return;
@@ -115000,11 +114861,11 @@
114861
114862 if( !IsVirtual(pTab) ) return 0;
114863 nName = sqlite3Strlen30(pTab->zName);
114864 if( sqlite3_strnicmp(zName, pTab->zName, nName)!=0 ) return 0;
114865 if( zName[nName]!='_' ) return 0;
114866 pMod = (Module*)sqlite3HashFind(&db->aModule, pTab->u.vtab.azArg[0]);
114867 if( pMod==0 ) return 0;
114868 if( pMod->pModule->iVersion<3 ) return 0;
114869 if( pMod->pModule->xShadowName==0 ) return 0;
114870 return pMod->pModule->xShadowName(zName+nName+1);
114871 }
@@ -115161,22 +115022,22 @@
115022 testcase( p->tabFlags & TF_HasVirtual );
115023 testcase( p->tabFlags & TF_HasStored );
115024 for(ii=0; ii<p->nCol; ii++){
115025 u32 colFlags = p->aCol[ii].colFlags;
115026 if( (colFlags & COLFLAG_GENERATED)!=0 ){
115027 Expr *pX = sqlite3ColumnExpr(p, &p->aCol[ii]);
115028 testcase( colFlags & COLFLAG_VIRTUAL );
115029 testcase( colFlags & COLFLAG_STORED );
115030 if( sqlite3ResolveSelfReference(pParse, p, NC_GenCol, pX, 0) ){
115031 /* If there are errors in resolving the expression, change the
115032 ** expression to a NULL. This prevents code generators that operate
115033 ** on the expression from inserting extra parts into the expression
115034 ** tree that have been allocated from lookaside memory, which is
115035 ** illegal in a schema and will lead to errors or heap corruption
115036 ** when the database connection closes. */
115037 sqlite3ColumnSetExpr(pParse, p, &p->aCol[ii],
115038 sqlite3ExprAlloc(db, TK_NULL, 0, 0));
115039 }
115040 }else{
115041 nNG++;
115042 }
115043 }
@@ -115212,11 +115073,11 @@
115073 sqlite3VdbeAddOp1(v, OP_Close, 0);
115074
115075 /*
115076 ** Initialize zType for the new view or table.
115077 */
115078 if( IsOrdinaryTable(p) ){
115079 /* A regular table */
115080 zType = "table";
115081 zType2 = "TABLE";
115082 #ifndef SQLITE_OMIT_VIEW
115083 }else{
@@ -115362,16 +115223,16 @@
115223 }
115224 #endif
115225 }
115226
115227 #ifndef SQLITE_OMIT_ALTERTABLE
115228 if( !pSelect && IsOrdinaryTable(p) ){
115229 assert( pCons && pEnd );
115230 if( pCons->z==0 ){
115231 pCons = pEnd;
115232 }
115233 p->u.tab.addColOffset = 13 + (int)(pCons->z - pParse->sNameToken.z);
115234 }
115235 #endif
115236 }
115237
115238 #ifndef SQLITE_OMIT_VIEW
@@ -115424,16 +115285,17 @@
115285 ** allocated rather than point to the input string - which means that
115286 ** they will persist after the current sqlite3_exec() call returns.
115287 */
115288 pSelect->selFlags |= SF_View;
115289 if( IN_RENAME_OBJECT ){
115290 p->u.view.pSelect = pSelect;
115291 pSelect = 0;
115292 }else{
115293 p->u.view.pSelect = sqlite3SelectDup(db, pSelect, EXPRDUP_REDUCE);
115294 }
115295 p->pCheck = sqlite3ExprListDup(db, pCNames, EXPRDUP_REDUCE);
115296 p->eTabType = TABTYP_VIEW;
115297 if( db->mallocFailed ) goto create_view_fail;
115298
115299 /* Locate the end of the CREATE VIEW statement. Make sEnd point to
115300 ** the end.
115301 */
@@ -115526,12 +115388,12 @@
115388 ** "*" elements in the results set of the view and will assign cursors
115389 ** to the elements of the FROM clause. But we do not want these changes
115390 ** to be permanent. So the computation is done on a copy of the SELECT
115391 ** statement that defines the view.
115392 */
115393 assert( IsView(pTable) );
115394 pSel = sqlite3SelectDup(db, pTable->u.view.pSelect, 0);
115395 if( pSel ){
115396 u8 eParseMode = pParse->eParseMode;
115397 pParse->eParseMode = PARSE_MODE_NORMAL;
115398 n = pParse->nTab;
115399 sqlite3SrcListAssignCursors(pParse, pSel->pSrc);
@@ -115586,12 +115448,10 @@
115448 nErr++;
115449 }
115450 pTable->pSchema->schemaFlags |= DB_UnresetViews;
115451 if( db->mallocFailed ){
115452 sqlite3DeleteColumnNames(db, pTable);
 
 
115453 }
115454 #endif /* SQLITE_OMIT_VIEW */
115455 return nErr;
115456 }
115457 #endif /* !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_VIRTUALTABLE) */
@@ -115604,14 +115464,12 @@
115464 HashElem *i;
115465 assert( sqlite3SchemaMutexHeld(db, idx, 0) );
115466 if( !DbHasProperty(db, idx, DB_UnresetViews) ) return;
115467 for(i=sqliteHashFirst(&db->aDb[idx].pSchema->tblHash); i;i=sqliteHashNext(i)){
115468 Table *pTab = sqliteHashData(i);
115469 if( IsView(pTab) ){
115470 sqlite3DeleteColumnNames(db, pTab);
 
 
115471 }
115472 }
115473 DbClearProperty(db, idx, DB_UnresetViews);
115474 }
115475 #else
@@ -115948,15 +115806,15 @@
115806
115807 #ifndef SQLITE_OMIT_VIEW
115808 /* Ensure DROP TABLE is not used on a view, and DROP VIEW is not used
115809 ** on a table.
115810 */
115811 if( isView && !IsView(pTab) ){
115812 sqlite3ErrorMsg(pParse, "use DROP TABLE to delete table %s", pTab->zName);
115813 goto exit_drop_table;
115814 }
115815 if( !isView && IsView(pTab) ){
115816 sqlite3ErrorMsg(pParse, "use DROP VIEW to delete view %s", pTab->zName);
115817 goto exit_drop_table;
115818 }
115819 #endif
115820
@@ -116016,11 +115874,11 @@
115874 int iCol = p->nCol-1;
115875 if( NEVER(iCol<0) ) goto fk_end;
115876 if( pToCol && pToCol->nExpr!=1 ){
115877 sqlite3ErrorMsg(pParse, "foreign key on %s"
115878 " should reference only one column of table %T",
115879 p->aCol[iCol].zCnName, pTo);
115880 goto fk_end;
115881 }
115882 nCol = 1;
115883 }else if( pToCol && pToCol->nExpr!=pFromCol->nExpr ){
115884 sqlite3ErrorMsg(pParse,
@@ -116039,11 +115897,11 @@
115897 pFKey = sqlite3DbMallocZero(db, nByte );
115898 if( pFKey==0 ){
115899 goto fk_end;
115900 }
115901 pFKey->pFrom = p;
115902 pFKey->pNextFrom = p->u.tab.pFKey;
115903 z = (char*)&pFKey->aCol[nCol];
115904 pFKey->zTo = z;
115905 if( IN_RENAME_OBJECT ){
115906 sqlite3RenameTokenMap(pParse, (void*)z, pTo);
115907 }
@@ -116056,11 +115914,11 @@
115914 pFKey->aCol[0].iFrom = p->nCol-1;
115915 }else{
115916 for(i=0; i<nCol; i++){
115917 int j;
115918 for(j=0; j<p->nCol; j++){
115919 if( sqlite3StrICmp(p->aCol[j].zCnName, pFromCol->a[i].zEName)==0 ){
115920 pFKey->aCol[i].iFrom = j;
115921 break;
115922 }
115923 }
115924 if( j>=p->nCol ){
@@ -116104,11 +115962,12 @@
115962 pNextTo->pPrevTo = pFKey;
115963 }
115964
115965 /* Link the foreign key to the table as the last step.
115966 */
115967 assert( !IsVirtual(p) );
115968 p->u.tab.pFKey = pFKey;
115969 pFKey = 0;
115970
115971 fk_end:
115972 sqlite3DbFree(db, pFKey);
115973 #endif /* !defined(SQLITE_OMIT_FOREIGN_KEY) */
@@ -116125,11 +115984,13 @@
115984 */
115985 SQLITE_PRIVATE void sqlite3DeferForeignKey(Parse *pParse, int isDeferred){
115986 #ifndef SQLITE_OMIT_FOREIGN_KEY
115987 Table *pTab;
115988 FKey *pFKey;
115989 if( (pTab = pParse->pNewTable)==0 ) return;
115990 if( NEVER(IsVirtual(pTab)) ) return;
115991 if( (pFKey = pTab->u.tab.pFKey)==0 ) return;
115992 assert( isDeferred==0 || isDeferred==1 ); /* EV: R-30323-21917 */
115993 pFKey->isDeferred = (u8)isDeferred;
115994 #endif
115995 }
115996
@@ -116417,11 +116278,11 @@
116278 ){
116279 sqlite3ErrorMsg(pParse, "table %s may not be indexed", pTab->zName);
116280 goto exit_create_index;
116281 }
116282 #ifndef SQLITE_OMIT_VIEW
116283 if( IsView(pTab) ){
116284 sqlite3ErrorMsg(pParse, "views may not be indexed");
116285 goto exit_create_index;
116286 }
116287 #endif
116288 #ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -116508,11 +116369,11 @@
116369 */
116370 if( pList==0 ){
116371 Token prevCol;
116372 Column *pCol = &pTab->aCol[pTab->nCol-1];
116373 pCol->colFlags |= COLFLAG_UNIQUE;
116374 sqlite3TokenInit(&prevCol, pCol->zCnName);
116375 pList = sqlite3ExprListAppend(pParse, 0,
116376 sqlite3ExprAlloc(db, TK_ID, &prevCol, 0));
116377 if( pList==0 ) goto exit_create_index;
116378 assert( pList->nExpr==1 );
116379 sqlite3ExprListSetSortOrder(pList, sortOrder, SQLITE_SO_UNDEFINED);
@@ -116629,11 +116490,11 @@
116490 memcpy(zExtra, zColl, nColl);
116491 zColl = zExtra;
116492 zExtra += nColl;
116493 nExtra -= nColl;
116494 }else if( j>=0 ){
116495 zColl = sqlite3ColumnColl(&pTab->aCol[j]);
116496 }
116497 if( !zColl ) zColl = sqlite3StrBINARY;
116498 if( !db->init.busy && !sqlite3LocateCollSeq(pParse, zColl) ){
116499 goto exit_create_index;
116500 }
@@ -117721,11 +117582,11 @@
117582 sqlite3_str_appendf(&errMsg, "index '%q'", pIdx->zName);
117583 }else{
117584 for(j=0; j<pIdx->nKeyCol; j++){
117585 char *zCol;
117586 assert( pIdx->aiColumn[j]>=0 );
117587 zCol = pTab->aCol[pIdx->aiColumn[j]].zCnName;
117588 if( j ) sqlite3_str_append(&errMsg, ", ", 2);
117589 sqlite3_str_appendall(&errMsg, pTab->zName);
117590 sqlite3_str_append(&errMsg, ".", 1);
117591 sqlite3_str_appendall(&errMsg, zCol);
117592 }
@@ -117748,11 +117609,11 @@
117609 ){
117610 char *zMsg;
117611 int rc;
117612 if( pTab->iPKey>=0 ){
117613 zMsg = sqlite3MPrintf(pParse->db, "%s.%s", pTab->zName,
117614 pTab->aCol[pTab->iPKey].zCnName);
117615 rc = SQLITE_CONSTRAINT_PRIMARYKEY;
117616 }else{
117617 zMsg = sqlite3MPrintf(pParse->db, "%s.rowid", pTab->zName);
117618 rc = SQLITE_CONSTRAINT_ROWID;
117619 }
@@ -118675,11 +118536,11 @@
118536 if( tabIsReadOnly(pParse, pTab) ){
118537 sqlite3ErrorMsg(pParse, "table %s may not be modified", pTab->zName);
118538 return 1;
118539 }
118540 #ifndef SQLITE_OMIT_VIEW
118541 if( !viewOk && IsView(pTab) ){
118542 sqlite3ErrorMsg(pParse,"cannot modify %s because it is a view",pTab->zName);
118543 return 1;
118544 }
118545 #endif
118546 return 0;
@@ -118779,17 +118640,17 @@
118640 pParse, 0, sqlite3PExpr(pParse, TK_ROW, 0, 0)
118641 );
118642 }else{
118643 Index *pPk = sqlite3PrimaryKeyIndex(pTab);
118644 if( pPk->nKeyCol==1 ){
118645 const char *zName = pTab->aCol[pPk->aiColumn[0]].zCnName;
118646 pLhs = sqlite3Expr(db, TK_ID, zName);
118647 pEList = sqlite3ExprListAppend(pParse, 0, sqlite3Expr(db, TK_ID, zName));
118648 }else{
118649 int i;
118650 for(i=0; i<pPk->nKeyCol; i++){
118651 Expr *p = sqlite3Expr(db, TK_ID, pTab->aCol[pPk->aiColumn[i]].zCnName);
118652 pEList = sqlite3ExprListAppend(pParse, pEList, p);
118653 }
118654 pLhs = sqlite3PExpr(pParse, TK_VECTOR, 0, 0);
118655 if( pLhs ){
118656 pLhs->x.pList = sqlite3ExprListDup(db, pEList, 0);
@@ -118892,11 +118753,11 @@
118753 /* Figure out if we have any triggers and if the table being
118754 ** deleted from is a view
118755 */
118756 #ifndef SQLITE_OMIT_TRIGGER
118757 pTrigger = sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0, 0);
118758 isView = IsView(pTab);
118759 #else
118760 # define pTrigger 0
118761 # define isView 0
118762 #endif
118763 bComplex = pTrigger || sqlite3FkRequired(pParse, pTab, 0, 0);
@@ -119142,11 +119003,11 @@
119003 ** where-clause loop above.
119004 */
119005 if( eOnePass!=ONEPASS_OFF ){
119006 assert( nKey==nPk ); /* OP_Found will use an unpacked key */
119007 if( !IsVirtual(pTab) && aToOpen[iDataCur-iTabCur] ){
119008 assert( pPk!=0 || IsView(pTab) );
119009 sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, addrBypass, iKey, nKey);
119010 VdbeCoverage(v);
119011 }
119012 }else if( pPk ){
119013 addrLoop = sqlite3VdbeAddOp1(v, OP_Rewind, iEphCur); VdbeCoverage(v);
@@ -119376,11 +119237,11 @@
119237 ** invoke the update-hook. The pre-update-hook, on the other hand should
119238 ** be invoked unless table pTab is a system table. The difference is that
119239 ** the update-hook is not invoked for rows removed by REPLACE, but the
119240 ** pre-update-hook is.
119241 */
119242 if( !IsView(pTab) ){
119243 u8 p5 = 0;
119244 sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur,0,iIdxNoSeek);
119245 sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, (count?OPFLAG_NCHANGE:0));
119246 if( pParse->nested==0 || 0==sqlite3_stricmp(pTab->zName, "sqlite_stat1") ){
119247 sqlite3VdbeAppendP4(v, (char*)pTab, P4_TABLE);
@@ -122070,11 +121931,13 @@
121931 ** 2) The FK is explicitly mapped to a column declared as INTEGER
121932 ** PRIMARY KEY.
121933 */
121934 if( pParent->iPKey>=0 ){
121935 if( !zKey ) return 0;
121936 if( !sqlite3StrICmp(pParent->aCol[pParent->iPKey].zCnName, zKey) ){
121937 return 0;
121938 }
121939 }
121940 }else if( paiCol ){
121941 assert( nCol>1 );
121942 aiCol = (int *)sqlite3DbMallocRawNN(pParse->db, nCol*sizeof(int));
121943 if( !aiCol ) return 1;
@@ -122112,15 +121975,15 @@
121975 if( iCol<0 ) break; /* No foreign keys against expression indexes */
121976
121977 /* If the index uses a collation sequence that is different from
121978 ** the default collation sequence for the column, this index is
121979 ** unusable. Bail out early in this case. */
121980 zDfltColl = sqlite3ColumnColl(&pParent->aCol[iCol]);
121981 if( !zDfltColl ) zDfltColl = sqlite3StrBINARY;
121982 if( sqlite3StrICmp(pIdx->azColl[i], zDfltColl) ) break;
121983
121984 zIdxCol = pParent->aCol[iCol].zCnName;
121985 for(j=0; j<nCol; j++){
121986 if( sqlite3StrICmp(pFKey->aCol[j].zCol, zIdxCol)==0 ){
121987 if( aiCol ) aiCol[i] = pFKey->aCol[j].iFrom;
121988 break;
121989 }
@@ -122340,11 +122203,11 @@
122203 if( pExpr ){
122204 if( iCol>=0 && iCol!=pTab->iPKey ){
122205 pCol = &pTab->aCol[iCol];
122206 pExpr->iTable = regBase + sqlite3TableColumnToStorage(pTab,iCol) + 1;
122207 pExpr->affExpr = pCol->affinity;
122208 zColl = sqlite3ColumnColl(pCol);
122209 if( zColl==0 ) zColl = db->pDfltColl->zName;
122210 pExpr = sqlite3ExprAddCollateString(pParse, pExpr, zColl);
122211 }else{
122212 pExpr->iTable = regBase;
122213 pExpr->affExpr = SQLITE_AFF_INTEGER;
@@ -122449,11 +122312,11 @@
122312
122313 iCol = pIdx ? pIdx->aiColumn[i] : -1;
122314 pLeft = exprTableRegister(pParse, pTab, regData, iCol);
122315 iCol = aiCol ? aiCol[i] : pFKey->aCol[0].iFrom;
122316 assert( iCol>=0 );
122317 zCol = pFKey->pFrom->aCol[iCol].zCnName;
122318 pRight = sqlite3Expr(db, TK_ID, zCol);
122319 pEq = sqlite3PExpr(pParse, TK_EQ, pLeft, pRight);
122320 pWhere = sqlite3ExprAnd(pParse, pWhere, pEq);
122321 }
122322
@@ -122484,11 +122347,11 @@
122347 assert( pIdx!=0 );
122348 for(i=0; i<pIdx->nKeyCol; i++){
122349 i16 iCol = pIdx->aiColumn[i];
122350 assert( iCol>=0 );
122351 pLeft = exprTableRegister(pParse, pTab, regData, iCol);
122352 pRight = sqlite3Expr(db, TK_ID, pTab->aCol[iCol].zCnName);
122353 pEq = sqlite3PExpr(pParse, TK_IS, pLeft, pRight);
122354 pAll = sqlite3ExprAnd(pParse, pAll, pEq);
122355 }
122356 pNe = sqlite3PExpr(pParse, TK_NOT, pAll, 0);
122357 }
@@ -122578,19 +122441,20 @@
122441 if( (db->flags&SQLITE_ForeignKeys) && !IsVirtual(pTab) ){
122442 int iSkip = 0;
122443 Vdbe *v = sqlite3GetVdbe(pParse);
122444
122445 assert( v ); /* VDBE has already been allocated */
122446 assert( !IsView(pTab) ); /* Not a view */
122447 assert( !IsVirtual(pTab) );
122448 if( sqlite3FkReferences(pTab)==0 ){
122449 /* Search for a deferred foreign key constraint for which this table
122450 ** is the child table. If one cannot be found, return without
122451 ** generating any VDBE code. If one can be found, then jump over
122452 ** the entire DELETE if there are no outstanding deferred constraints
122453 ** when this statement is run. */
122454 FKey *p;
122455 for(p=pTab->u.tab.pFKey; p; p=p->pNextFrom){
122456 if( p->isDeferred || (db->flags & SQLITE_DeferFKs) ) break;
122457 }
122458 if( !p ) return;
122459 iSkip = sqlite3VdbeMakeLabel(pParse);
122460 sqlite3VdbeAddOp2(v, OP_FkIfZero, 1, iSkip); VdbeCoverage(v);
@@ -122675,11 +122539,11 @@
122539 int iKey;
122540 for(iKey=0; iKey<pTab->nCol; iKey++){
122541 if( aChange[iKey]>=0 || (iKey==pTab->iPKey && bChngRowid) ){
122542 Column *pCol = &pTab->aCol[iKey];
122543 if( zKey ){
122544 if( 0==sqlite3StrICmp(pCol->zCnName, zKey) ) return 1;
122545 }else if( pCol->colFlags & COLFLAG_PRIMKEY ){
122546 return 1;
122547 }
122548 }
122549 }
@@ -122748,11 +122612,12 @@
122612 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
122613 zDb = db->aDb[iDb].zDbSName;
122614
122615 /* Loop through all the foreign key constraints for which pTab is the
122616 ** child table (the table that the foreign key definition is part of). */
122617 assert( !IsVirtual(pTab) );
122618 for(pFKey=pTab->u.tab.pFKey; pFKey; pFKey=pFKey->pNextFrom){
122619 Table *pTo; /* Parent table of foreign key pFKey */
122620 Index *pIdx = 0; /* Index on key columns in pTo */
122621 int *aiFree = 0;
122622 int *aiCol;
122623 int iCol;
@@ -122815,11 +122680,11 @@
122680 /* Request permission to read the parent key columns. If the
122681 ** authorization callback returns SQLITE_IGNORE, behave as if any
122682 ** values read from the parent table are NULL. */
122683 if( db->xAuth ){
122684 int rcauth;
122685 char *zCol = pTo->aCol[pIdx ? pIdx->aiColumn[i] : pTo->iPKey].zCnName;
122686 rcauth = sqlite3AuthReadCol(pParse, pTo->zName, zCol, iDb);
122687 bIgnore = (rcauth==SQLITE_IGNORE);
122688 }
122689 #endif
122690 }
@@ -122933,11 +122798,12 @@
122798 ){
122799 u32 mask = 0;
122800 if( pParse->db->flags&SQLITE_ForeignKeys ){
122801 FKey *p;
122802 int i;
122803 assert( !IsVirtual(pTab) );
122804 for(p=pTab->u.tab.pFKey; p; p=p->pNextFrom){
122805 for(i=0; i<p->nCol; i++) mask |= COLUMN_MASK(p->aCol[i].iFrom);
122806 }
122807 for(p=sqlite3FkReferences(pTab); p; p=p->pNextTo){
122808 Index *pIdx = 0;
122809 sqlite3FkLocateIndex(pParse, pTab, p, &pIdx, 0);
@@ -122983,23 +122849,23 @@
122849 int *aChange, /* Non-NULL for UPDATE operations */
122850 int chngRowid /* True for UPDATE that affects rowid */
122851 ){
122852 int eRet = 1; /* Value to return if bHaveFK is true */
122853 int bHaveFK = 0; /* If FK processing is required */
122854 if( pParse->db->flags&SQLITE_ForeignKeys && !IsVirtual(pTab) ){
122855 if( !aChange ){
122856 /* A DELETE operation. Foreign key processing is required if the
122857 ** table in question is either the child or parent table for any
122858 ** foreign key constraint. */
122859 bHaveFK = (sqlite3FkReferences(pTab) || pTab->u.tab.pFKey);
122860 }else{
122861 /* This is an UPDATE. Foreign key processing is only required if the
122862 ** operation modifies one or more child or parent key columns. */
122863 FKey *p;
122864
122865 /* Check if any child key columns are being modified. */
122866 for(p=pTab->u.tab.pFKey; p; p=p->pNextFrom){
122867 if( fkChildIsModified(pTab, p, aChange, chngRowid) ){
122868 if( 0==sqlite3_stricmp(pTab->zName, p->zTo) ) eRet = 2;
122869 bHaveFK = 1;
122870 }
122871 }
@@ -123088,12 +122954,12 @@
122954 iFromCol = aiCol ? aiCol[i] : pFKey->aCol[0].iFrom;
122955 assert( iFromCol>=0 );
122956 assert( pIdx!=0 || (pTab->iPKey>=0 && pTab->iPKey<pTab->nCol) );
122957 assert( pIdx==0 || pIdx->aiColumn[i]>=0 );
122958 sqlite3TokenInit(&tToCol,
122959 pTab->aCol[pIdx ? pIdx->aiColumn[i] : pTab->iPKey].zCnName);
122960 sqlite3TokenInit(&tFromCol, pFKey->pFrom->aCol[iFromCol].zCnName);
122961
122962 /* Create the expression "OLD.zToCol = zFromCol". It is important
122963 ** that the "OLD.zToCol" term is on the LHS of the = operator, so
122964 ** that the affinity and collation sequence associated with the
122965 ** parent table are used for the comparison. */
@@ -123134,11 +123000,11 @@
123000 if( pCol->colFlags & COLFLAG_GENERATED ){
123001 testcase( pCol->colFlags & COLFLAG_VIRTUAL );
123002 testcase( pCol->colFlags & COLFLAG_STORED );
123003 pDflt = 0;
123004 }else{
123005 pDflt = sqlite3ColumnExpr(pFKey->pFrom, pCol);
123006 }
123007 if( pDflt ){
123008 pNew = sqlite3ExprDup(db, pDflt, 0);
123009 }else{
123010 pNew = sqlite3ExprAlloc(db, TK_NULL, 0, 0);
@@ -123271,13 +123137,13 @@
123137 */
123138 SQLITE_PRIVATE void sqlite3FkDelete(sqlite3 *db, Table *pTab){
123139 FKey *pFKey; /* Iterator variable */
123140 FKey *pNext; /* Copy of pFKey->pNextFrom */
123141
123142 assert( !IsVirtual(pTab) );
123143 for(pFKey=pTab->u.tab.pFKey; pFKey; pFKey=pNext){
123144 assert( db==0 || sqlite3SchemaMutexHeld(db, 0, pTab->pSchema) );
123145
123146 /* Remove the FK from the fkeyHash hash table. */
123147 if( !db || db->pnBytesFreed==0 ){
123148 if( pFKey->pPrevTo ){
123149 pFKey->pPrevTo->pNextTo = pFKey->pNextTo;
@@ -123603,26 +123469,26 @@
123469 Column *pCol = pTab->aCol + i;
123470 if( (pCol->colFlags & COLFLAG_NOTAVAIL)!=0 ){
123471 int x;
123472 pCol->colFlags |= COLFLAG_BUSY;
123473 w.eCode = 0;
123474 sqlite3WalkExpr(&w, sqlite3ColumnExpr(pTab, pCol));
123475 pCol->colFlags &= ~COLFLAG_BUSY;
123476 if( w.eCode & COLFLAG_NOTAVAIL ){
123477 pRedo = pCol;
123478 continue;
123479 }
123480 eProgress = 1;
123481 assert( pCol->colFlags & COLFLAG_GENERATED );
123482 x = sqlite3TableColumnToStorage(pTab, i) + iRegStore;
123483 sqlite3ExprCodeGeneratedColumn(pParse, pTab, pCol, x);
123484 pCol->colFlags &= ~COLFLAG_NOTAVAIL;
123485 }
123486 }
123487 }while( pRedo && eProgress );
123488 if( pRedo ){
123489 sqlite3ErrorMsg(pParse, "generated column loop on \"%s\"", pRedo->zCnName);
123490 }
123491 pParse->iSelfTab = 0;
123492 }
123493 #endif /* SQLITE_OMIT_GENERATED_COLUMNS */
123494
@@ -124013,11 +123879,11 @@
123879 /* Figure out if we have any triggers and if the table being
123880 ** inserted into is a view
123881 */
123882 #ifndef SQLITE_OMIT_TRIGGER
123883 pTrigger = sqlite3TriggersExist(pParse, pTab, TK_INSERT, 0, &tmask);
123884 isView = IsView(pTab);
123885 #else
123886 # define pTrigger 0
123887 # define tmask 0
123888 # define isView 0
123889 #endif
@@ -124104,21 +123970,21 @@
123970 for(i=0; i<pColumn->nId; i++){
123971 pColumn->a[i].idx = -1;
123972 }
123973 for(i=0; i<pColumn->nId; i++){
123974 for(j=0; j<pTab->nCol; j++){
123975 if( sqlite3StrICmp(pColumn->a[i].zName, pTab->aCol[j].zCnName)==0 ){
123976 pColumn->a[i].idx = j;
123977 if( i!=j ) bIdListInOrder = 0;
123978 if( j==pTab->iPKey ){
123979 ipkColumn = i; assert( !withoutRowid );
123980 }
123981 #ifndef SQLITE_OMIT_GENERATED_COLUMNS
123982 if( pTab->aCol[j].colFlags & (COLFLAG_STORED|COLFLAG_VIRTUAL) ){
123983 sqlite3ErrorMsg(pParse,
123984 "cannot INSERT into generated column \"%s\"",
123985 pTab->aCol[j].zCnName);
123986 goto insert_cleanup;
123987 }
123988 #endif
123989 break;
123990 }
@@ -124299,11 +124165,11 @@
124165 if( IsVirtual(pTab) ){
124166 sqlite3ErrorMsg(pParse, "UPSERT not implemented for virtual table \"%s\"",
124167 pTab->zName);
124168 goto insert_cleanup;
124169 }
124170 if( IsView(pTab) ){
124171 sqlite3ErrorMsg(pParse, "cannot UPSERT a view");
124172 goto insert_cleanup;
124173 }
124174 if( sqlite3HasExplicitNulls(pParse, pUpsert->pUpsertTarget) ){
124175 goto insert_cleanup;
@@ -124398,26 +124264,32 @@
124264 }
124265 continue;
124266 }else if( pColumn==0 ){
124267 /* Hidden columns that are not explicitly named in the INSERT
124268 ** get there default value */
124269 sqlite3ExprCodeFactorable(pParse,
124270 sqlite3ColumnExpr(pTab, &pTab->aCol[i]),
124271 iRegStore);
124272 continue;
124273 }
124274 }
124275 if( pColumn ){
124276 for(j=0; j<pColumn->nId && pColumn->a[j].idx!=i; j++){}
124277 if( j>=pColumn->nId ){
124278 /* A column not named in the insert column list gets its
124279 ** default value */
124280 sqlite3ExprCodeFactorable(pParse,
124281 sqlite3ColumnExpr(pTab, &pTab->aCol[i]),
124282 iRegStore);
124283 continue;
124284 }
124285 k = j;
124286 }else if( nColumn==0 ){
124287 /* This is INSERT INTO ... DEFAULT VALUES. Load the default value. */
124288 sqlite3ExprCodeFactorable(pParse,
124289 sqlite3ColumnExpr(pTab, &pTab->aCol[i]),
124290 iRegStore);
124291 continue;
124292 }else{
124293 k = i - nHidden;
124294 }
124295
@@ -124928,11 +124800,11 @@
124800
124801 isUpdate = regOldData!=0;
124802 db = pParse->db;
124803 v = pParse->pVdbe;
124804 assert( v!=0 );
124805 assert( !IsView(pTab) ); /* This table is not a VIEW */
124806 nCol = pTab->nCol;
124807
124808 /* pPk is the PRIMARY KEY index for WITHOUT ROWID tables and NULL for
124809 ** normal rowid tables. nPkField is the number of key fields in the
124810 ** pPk index or 1 for a rowid table. In other words, nPkField is the
@@ -124979,11 +124851,11 @@
124851 }else if( onError==OE_Default ){
124852 onError = OE_Abort;
124853 }
124854 if( onError==OE_Replace ){
124855 if( b2ndPass /* REPLACE becomes ABORT on the 2nd pass */
124856 || pCol->iDflt==0 /* REPLACE is ABORT if no DEFAULT value */
124857 ){
124858 testcase( pCol->colFlags & COLFLAG_VIRTUAL );
124859 testcase( pCol->colFlags & COLFLAG_STORED );
124860 testcase( pCol->colFlags & COLFLAG_GENERATED );
124861 onError = OE_Abort;
@@ -125001,21 +124873,22 @@
124873 case OE_Replace: {
124874 int addr1 = sqlite3VdbeAddOp1(v, OP_NotNull, iReg);
124875 VdbeCoverage(v);
124876 assert( (pCol->colFlags & COLFLAG_GENERATED)==0 );
124877 nSeenReplace++;
124878 sqlite3ExprCodeCopy(pParse,
124879 sqlite3ColumnExpr(pTab, pCol), iReg);
124880 sqlite3VdbeJumpHere(v, addr1);
124881 break;
124882 }
124883 case OE_Abort:
124884 sqlite3MayAbort(pParse);
124885 /* no break */ deliberate_fall_through
124886 case OE_Rollback:
124887 case OE_Fail: {
124888 char *zMsg = sqlite3MPrintf(db, "%s.%s", pTab->zName,
124889 pCol->zCnName);
124890 sqlite3VdbeAddOp3(v, OP_HaltIfNull, SQLITE_CONSTRAINT_NOTNULL,
124891 onError, iReg);
124892 sqlite3VdbeAppendP4(v, zMsg, P4_DYNAMIC);
124893 sqlite3VdbeChangeP5(v, P5_ConstraintNotNull);
124894 VdbeCoverage(v);
@@ -125429,11 +125302,11 @@
125302 VdbeComment((v, "rowid"));
125303 }else{
125304 testcase( sqlite3TableColumnToStorage(pTab, iField)!=iField );
125305 x = sqlite3TableColumnToStorage(pTab, iField) + regNewData + 1;
125306 sqlite3VdbeAddOp2(v, OP_SCopy, x, regIdx+i);
125307 VdbeComment((v, "%s", pTab->aCol[iField].zCnName));
125308 }
125309 }
125310 sqlite3VdbeAddOp3(v, OP_MakeRecord, regIdx, pIdx->nColumn, aRegIdx[ix]);
125311 VdbeComment((v, "for %s", pIdx->zName));
125312 #ifdef SQLITE_ENABLE_NULL_TRIM
@@ -125488,11 +125361,11 @@
125361 && pPk==pIdx /* Condition 2 */
125362 && onError==OE_Replace /* Condition 1 */
125363 && ( 0==(db->flags&SQLITE_RecTriggers) || /* Condition 4 */
125364 0==sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0, 0))
125365 && ( 0==(db->flags&SQLITE_ForeignKeys) || /* Condition 5 */
125366 (0==pTab->u.tab.pFKey && 0==sqlite3FkReferences(pTab)))
125367 ){
125368 sqlite3VdbeResolveLabel(v, addrUniqueOk);
125369 continue;
125370 }
125371 #endif /* ifndef SQLITE_ENABLE_PREUPDATE_HOOK */
@@ -125523,11 +125396,11 @@
125396 for(i=0; i<pPk->nKeyCol; i++){
125397 assert( pPk->aiColumn[i]>=0 );
125398 x = sqlite3TableColumnToIndex(pIdx, pPk->aiColumn[i]);
125399 sqlite3VdbeAddOp3(v, OP_Column, iThisCur, x, regR+i);
125400 VdbeComment((v, "%s.%s", pTab->zName,
125401 pTab->aCol[pPk->aiColumn[i]].zCnName));
125402 }
125403 }
125404 if( isUpdate ){
125405 /* If currently processing the PRIMARY KEY of a WITHOUT ROWID
125406 ** table, only conflict if the new PRIMARY KEY values are actually
@@ -125722,11 +125595,11 @@
125595 /* Records with omitted columns are only allowed for schema format
125596 ** version 2 and later (SQLite version 3.1.4, 2005-02-20). */
125597 if( pTab->pSchema->file_format<2 ) return;
125598
125599 for(i=pTab->nCol-1; i>0; i--){
125600 if( pTab->aCol[i].iDflt!=0 ) break;
125601 if( pTab->aCol[i].colFlags & COLFLAG_PRIMKEY ) break;
125602 }
125603 sqlite3VdbeChangeP5(v, i+1);
125604 }
125605 #endif
@@ -125787,11 +125660,11 @@
125660 || update_flags==(OPFLAG_ISUPDATE|OPFLAG_SAVEPOSITION)
125661 );
125662
125663 v = pParse->pVdbe;
125664 assert( v!=0 );
125665 assert( !IsView(pTab) ); /* This table is not a VIEW */
125666 for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
125667 /* All REPLACE indexes are at the end of the list */
125668 assert( pIdx->onError!=OE_Replace
125669 || pIdx->pNext==0
125670 || pIdx->pNext->onError==OE_Replace );
@@ -126089,17 +125962,12 @@
125962 return 0; /* tab1 and tab2 may not be the same table */
125963 }
125964 if( HasRowid(pDest)!=HasRowid(pSrc) ){
125965 return 0; /* source and destination must both be WITHOUT ROWID or not */
125966 }
125967 if( !IsOrdinaryTable(pSrc) ){
125968 return 0; /* tab2 may not be a view or virtual table */
 
 
 
 
 
125969 }
125970 if( pDest->nCol!=pSrc->nCol ){
125971 return 0; /* Number of columns must be the same in tab1 and tab2 */
125972 }
125973 if( pDest->iPKey!=pSrc->iPKey ){
@@ -126139,33 +126007,38 @@
126007 /* But the transfer is only allowed if both the source and destination
126008 ** tables have the exact same expressions for generated columns.
126009 ** This requirement could be relaxed for VIRTUAL columns, I suppose.
126010 */
126011 if( (pDestCol->colFlags & COLFLAG_GENERATED)!=0 ){
126012 if( sqlite3ExprCompare(0,
126013 sqlite3ColumnExpr(pSrc, pSrcCol),
126014 sqlite3ColumnExpr(pDest, pDestCol), -1)!=0 ){
126015 testcase( pDestCol->colFlags & COLFLAG_VIRTUAL );
126016 testcase( pDestCol->colFlags & COLFLAG_STORED );
126017 return 0; /* Different generator expressions */
126018 }
126019 }
126020 #endif
126021 if( pDestCol->affinity!=pSrcCol->affinity ){
126022 return 0; /* Affinity must be the same on all columns */
126023 }
126024 if( sqlite3_stricmp(sqlite3ColumnColl(pDestCol),
126025 sqlite3ColumnColl(pSrcCol))!=0 ){
126026 return 0; /* Collating sequence must be the same on all columns */
126027 }
126028 if( pDestCol->notNull && !pSrcCol->notNull ){
126029 return 0; /* tab2 must be NOT NULL if tab1 is */
126030 }
126031 /* Default values for second and subsequent columns need to match. */
126032 if( (pDestCol->colFlags & COLFLAG_GENERATED)==0 && i>0 ){
126033 Expr *pDestExpr = sqlite3ColumnExpr(pDest, pDestCol);
126034 Expr *pSrcExpr = sqlite3ColumnExpr(pSrc, pSrcCol);
126035 assert( pDestExpr==0 || pDestExpr->op==TK_SPAN );
126036 assert( pSrcExpr==0 || pSrcExpr->op==TK_SPAN );
126037 if( (pDestExpr==0)!=(pSrcExpr==0)
126038 || (pDestExpr!=0 && strcmp(pDestExpr->u.zToken,
126039 pSrcExpr->u.zToken)!=0)
126040 ){
126041 return 0; /* Default values must be the same for all columns */
126042 }
126043 }
126044 }
@@ -126198,11 +126071,11 @@
126071 ** But the main beneficiary of the transfer optimization is the VACUUM
126072 ** command, and the VACUUM command disables foreign key constraints. So
126073 ** the extra complication to make this rule less restrictive is probably
126074 ** not worth the effort. Ticket [6284df89debdfa61db8073e062908af0c9b6118e]
126075 */
126076 if( (db->flags & SQLITE_ForeignKeys)!=0 && pDest->u.tab.pFKey!=0 ){
126077 return 0;
126078 }
126079 #endif
126080 if( (db->flags & SQLITE_CountRows)!=0 ){
126081 return 0; /* xfer opt does not play well with PRAGMA count_changes */
@@ -129888,17 +129761,20 @@
129761 }else if( pPk==0 ){
129762 k = 1;
129763 }else{
129764 for(k=1; k<=pTab->nCol && pPk->aiColumn[k-1]!=i; k++){}
129765 }
129766 assert( sqlite3ColumnExpr(pTab,pCol)==0
129767 || sqlite3ColumnExpr(pTab,pCol)->op==TK_SPAN
129768 || isHidden>=2 );
129769 sqlite3VdbeMultiLoad(v, 1, pPragma->iArg ? "issisii" : "issisi",
129770 i-nHidden,
129771 pCol->zCnName,
129772 sqlite3ColumnType(pCol,""),
129773 pCol->notNull ? 1 : 0,
129774 isHidden>=2 || sqlite3ColumnExpr(pTab,pCol)==0 ? 0 :
129775 sqlite3ColumnExpr(pTab,pCol)->u.zToken,
129776 k,
129777 isHidden);
129778 }
129779 }
129780 }
@@ -129961,11 +129837,11 @@
129837 sqlite3CodeVerifySchema(pParse, iIdxDb);
129838 assert( pParse->nMem<=pPragma->nPragCName );
129839 for(i=0; i<mx; i++){
129840 i16 cnum = pIdx->aiColumn[i];
129841 sqlite3VdbeMultiLoad(v, 1, "iisX", i, cnum,
129842 cnum<0 ? 0 : pTab->aCol[cnum].zCnName);
129843 if( pPragma->iArg ){
129844 sqlite3VdbeMultiLoad(v, 4, "isiX",
129845 pIdx->aSortOrder[i],
129846 pIdx->azColl[i],
129847 i<pIdx->nKeyCol);
@@ -130068,12 +129944,12 @@
129944 #ifndef SQLITE_OMIT_FOREIGN_KEY
129945 case PragTyp_FOREIGN_KEY_LIST: if( zRight ){
129946 FKey *pFK;
129947 Table *pTab;
129948 pTab = sqlite3FindTable(db, zRight, zDb);
129949 if( pTab && !IsVirtual(pTab) ){
129950 pFK = pTab->u.tab.pFKey;
129951 if( pFK ){
129952 int iTabDb = sqlite3SchemaToIndex(db, pTab->pSchema);
129953 int i = 0;
129954 pParse->nMem = 8;
129955 sqlite3CodeVerifySchema(pParse, iTabDb);
@@ -130082,11 +129958,11 @@
129958 for(j=0; j<pFK->nCol; j++){
129959 sqlite3VdbeMultiLoad(v, 1, "iissssss",
129960 i,
129961 j,
129962 pFK->zTo,
129963 pTab->aCol[pFK->aCol[j].iFrom].zCnName,
129964 pFK->aCol[j].zCol,
129965 actionName(pFK->aAction[1]), /* ON UPDATE */
129966 actionName(pFK->aAction[0]), /* ON DELETE */
129967 "NONE");
129968 }
@@ -130128,19 +130004,20 @@
130004 k = 0;
130005 }else{
130006 pTab = (Table*)sqliteHashData(k);
130007 k = sqliteHashNext(k);
130008 }
130009 if( pTab==0 || IsVirtual(pTab) || pTab->u.tab.pFKey==0 ) continue;
130010 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
130011 zDb = db->aDb[iDb].zDbSName;
130012 sqlite3CodeVerifySchema(pParse, iDb);
130013 sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
130014 if( pTab->nCol+regRow>pParse->nMem ) pParse->nMem = pTab->nCol + regRow;
130015 sqlite3OpenTable(pParse, 0, iDb, pTab, OP_OpenRead);
130016 sqlite3VdbeLoadString(v, regResult, pTab->zName);
130017 assert( !IsVirtual(pTab) );
130018 for(i=1, pFK=pTab->u.tab.pFKey; pFK; i++, pFK=pFK->pNextFrom){
130019 pParent = sqlite3FindTable(db, pFK->zTo, zDb);
130020 if( pParent==0 ) continue;
130021 pIdx = 0;
130022 sqlite3TableLock(pParse, iDb, pParent->tnum, 0, pParent->zName);
130023 x = sqlite3FkLocateIndex(pParse, pParent, pFK, &pIdx, 0);
@@ -130158,11 +130035,12 @@
130035 }
130036 assert( pParse->nErr>0 || pFK==0 );
130037 if( pFK ) break;
130038 if( pParse->nTab<i ) pParse->nTab = i;
130039 addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, 0); VdbeCoverage(v);
130040 assert( !IsVirtual(pTab) );
130041 for(i=1, pFK=pTab->u.tab.pFKey; pFK; i++, pFK=pFK->pNextFrom){
130042 pParent = sqlite3FindTable(db, pFK->zTo, zDb);
130043 pIdx = 0;
130044 aiCols = 0;
130045 if( pParent ){
130046 x = sqlite3FkLocateIndex(pParse, pParent, pFK, &pIdx, &aiCols);
@@ -130393,11 +130271,11 @@
130271 if( sqlite3VdbeGetOp(v,-1)->opcode==OP_Column ){
130272 sqlite3VdbeChangeP5(v, OPFLAG_TYPEOFARG);
130273 }
130274 jmp2 = sqlite3VdbeAddOp1(v, OP_NotNull, 3); VdbeCoverage(v);
130275 zErr = sqlite3MPrintf(db, "NULL value in %s.%s", pTab->zName,
130276 pTab->aCol[j].zCnName);
130277 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC);
130278 integrityCheckResultRow(v);
130279 sqlite3VdbeJumpHere(v, jmp2);
130280 }
130281 /* Verify CHECK constraints */
@@ -132601,11 +132479,11 @@
132479 SQLITE_PRIVATE int sqlite3ColumnIndex(Table *pTab, const char *zCol){
132480 int i;
132481 u8 h = sqlite3StrIHash(zCol);
132482 Column *pCol;
132483 for(pCol=pTab->aCol, i=0; i<pTab->nCol; pCol++, i++){
132484 if( pCol->hName==h && sqlite3StrICmp(pCol->zCnName, zCol)==0 ) return i;
132485 }
132486 return -1;
132487 }
132488
132489 /*
@@ -132800,11 +132678,11 @@
132678 char *zName; /* Name of column in the right table */
132679 int iLeft; /* Matching left table */
132680 int iLeftCol; /* Matching column in the left table */
132681
132682 if( IsHiddenColumn(&pRightTab->aCol[j]) ) continue;
132683 zName = pRightTab->aCol[j].zCnName;
132684 if( tableAndColumnIndex(pSrc, i+1, zName, &iLeft, &iLeftCol, 1) ){
132685 addWhereTerm(pParse, pSrc, iLeft, iLeftCol, i+1, j,
132686 isOuter, &p->pWhere);
132687 }
132688 }
@@ -133203,11 +133081,13 @@
133081 Parse *pParse, /* Parsing and code generating context */
133082 int eTnctType, /* WHERE_DISTINCT_* value */
133083 int iVal, /* Value returned by codeDistinct() */
133084 int iOpenEphAddr /* Address of OP_OpenEphemeral instruction for iTab */
133085 ){
133086 if( pParse->nErr==0
133087 && (eTnctType==WHERE_DISTINCT_UNIQUE || eTnctType==WHERE_DISTINCT_ORDERED)
133088 ){
133089 Vdbe *v = pParse->pVdbe;
133090 sqlite3VdbeChangeToNoop(v, iOpenEphAddr);
133091 if( sqlite3VdbeGetOp(v, iOpenEphAddr+1)->opcode==OP_Explain ){
133092 sqlite3VdbeChangeToNoop(v, iOpenEphAddr+1);
133093 }
@@ -134165,11 +134045,11 @@
134045 assert( iCol==XN_ROWID || (iCol>=0 && iCol<pTab->nCol) );
134046 if( iCol<0 ){
134047 zType = "INTEGER";
134048 zOrigCol = "rowid";
134049 }else{
134050 zOrigCol = pTab->aCol[iCol].zCnName;
134051 zType = sqlite3ColumnType(&pTab->aCol[iCol],0);
134052 }
134053 zOrigTab = pTab->zName;
134054 if( pNC->pParse && pTab->pSchema ){
134055 int iDb = sqlite3SchemaToIndex(pNC->pParse->db, pTab->pSchema);
@@ -134337,11 +134217,11 @@
134217 if( iCol<0 ) iCol = pTab->iPKey;
134218 assert( iCol==-1 || (iCol>=0 && iCol<pTab->nCol) );
134219 if( iCol<0 ){
134220 zCol = "rowid";
134221 }else{
134222 zCol = pTab->aCol[iCol].zCnName;
134223 }
134224 if( fullName ){
134225 char *zName = 0;
134226 zName = sqlite3MPrintf(db, "%s.%s", pTab->zName, zCol);
134227 sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, SQLITE_DYNAMIC);
@@ -134422,11 +134302,11 @@
134302 }
134303 if( pColExpr->op==TK_COLUMN && (pTab = pColExpr->y.pTab)!=0 ){
134304 /* For columns use the column name name */
134305 int iCol = pColExpr->iColumn;
134306 if( iCol<0 ) iCol = pTab->iPKey;
134307 zName = iCol>=0 ? pTab->aCol[iCol].zCnName : "rowid";
134308 }else if( pColExpr->op==TK_ID ){
134309 assert( !ExprHasProperty(pColExpr, EP_IntValue) );
134310 zName = pColExpr->u.zToken;
134311 }else{
134312 /* Use the original text of the column expression as its name */
@@ -134450,21 +134330,21 @@
134330 if( zName[j]==':' ) nName = j;
134331 }
134332 zName = sqlite3MPrintf(db, "%.*z:%u", nName, zName, ++cnt);
134333 if( cnt>3 ) sqlite3_randomness(sizeof(cnt), &cnt);
134334 }
134335 pCol->zCnName = zName;
134336 pCol->hName = sqlite3StrIHash(zName);
134337 sqlite3ColumnPropertiesFromName(0, pCol);
134338 if( zName && sqlite3HashInsert(&ht, zName, pCol)==pCol ){
134339 sqlite3OomFault(db);
134340 }
134341 }
134342 sqlite3HashClear(&ht);
134343 if( db->mallocFailed ){
134344 for(j=0; j<i; j++){
134345 sqlite3DbFree(db, aCol[j].zCnName);
134346 }
134347 sqlite3DbFree(db, aCol);
134348 *paCol = 0;
134349 *pnCol = 0;
134350 return SQLITE_NOMEM_BKPT;
@@ -134512,21 +134392,22 @@
134392 zType = columnType(&sNC, p, 0, 0, 0);
134393 /* pCol->szEst = ... // Column size est for SELECT tables never used */
134394 pCol->affinity = sqlite3ExprAffinity(p);
134395 if( zType ){
134396 m = sqlite3Strlen30(zType);
134397 n = sqlite3Strlen30(pCol->zCnName);
134398 pCol->zCnName = sqlite3DbReallocOrFree(db, pCol->zCnName, n+m+2);
134399 if( pCol->zCnName ){
134400 memcpy(&pCol->zCnName[n+1], zType, m+1);
134401 pCol->colFlags |= COLFLAG_HASTYPE;
134402 }
134403 }
134404 if( pCol->affinity<=SQLITE_AFF_NONE ) pCol->affinity = aff;
134405 pColl = sqlite3ExprCollSeq(pParse, p);
134406 if( pColl && (pCol->colFlags & COLFLAG_HASCOLL)==0 ){
134407 assert( pTab->pIndex==0 );
134408 sqlite3ColumnSetColl(db, pCol, pColl->zName);
134409 }
134410 }
134411 pTab->szTabRow = 1; /* Any non-zero value works */
134412 }
134413
@@ -137261,11 +137142,11 @@
137142 ){
137143 return 0;
137144 }
137145 pTab = p->pSrc->a[0].pTab;
137146 pExpr = p->pEList->a[0].pExpr;
137147 assert( pTab && !IsView(pTab) && pExpr );
137148
137149 if( IsVirtual(pTab) ) return 0;
137150 if( pExpr->op!=TK_AGG_FUNCTION ) return 0;
137151 if( NEVER(pAggInfo->nFunc==0) ) return 0;
137152 if( (pAggInfo->aFunc[0].pFunc->funcFlags&SQLITE_FUNC_COUNT)==0 ) return 0;
@@ -137806,34 +137687,35 @@
137687 pTab->nTabRef++;
137688 if( !IsVirtual(pTab) && cannotBeFunction(pParse, pFrom) ){
137689 return WRC_Abort;
137690 }
137691 #if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_VIRTUALTABLE)
137692 if( !IsOrdinaryTable(pTab) ){
137693 i16 nCol;
137694 u8 eCodeOrig = pWalker->eCode;
137695 if( sqlite3ViewGetColumnNames(pParse, pTab) ) return WRC_Abort;
137696 assert( pFrom->pSelect==0 );
137697 if( IsView(pTab) ){
137698 if( (db->flags & SQLITE_EnableView)==0
137699 && pTab->pSchema!=db->aDb[1].pSchema
137700 ){
137701 sqlite3ErrorMsg(pParse, "access to view \"%s\" prohibited",
137702 pTab->zName);
137703 }
137704 pFrom->pSelect = sqlite3SelectDup(db, pTab->u.view.pSelect, 0);
137705 }else
137706 #ifndef SQLITE_OMIT_VIRTUALTABLE
137707 if( ALWAYS(IsVirtual(pTab))
 
137708 && pFrom->fg.fromDDL
137709 && ALWAYS(pTab->u.vtab.p!=0)
137710 && pTab->u.vtab.p->eVtabRisk > ((db->flags & SQLITE_TrustedSchema)!=0)
137711 ){
137712 sqlite3ErrorMsg(pParse, "unsafe use of virtual table \"%s\"",
137713 pTab->zName);
137714 }
137715 assert( SQLITE_VTABRISK_Normal==1 && SQLITE_VTABRISK_High==2 );
137716 #endif
 
137717 nCol = pTab->nCol;
137718 pTab->nCol = -1;
137719 pWalker->eCode = 1; /* Turn on Select.selId renumbering */
137720 sqlite3WalkSelect(pWalker, pFrom->pSelect);
137721 pWalker->eCode = eCodeOrig;
@@ -137929,11 +137811,11 @@
137811 }
137812 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
137813 zSchemaName = iDb>=0 ? db->aDb[iDb].zDbSName : "*";
137814 }
137815 for(j=0; j<pTab->nCol; j++){
137816 char *zName = pTab->aCol[j].zCnName;
137817 char *zColname; /* The computed column name */
137818 char *zToFree; /* Malloced string that needs to be freed */
137819 Token sColname; /* Computed column name as a token */
137820
137821 assert( zName );
@@ -140214,16 +140096,16 @@
140096 }
140097
140098 /* INSTEAD of triggers are only for views and views only support INSTEAD
140099 ** of triggers.
140100 */
140101 if( IsView(pTab) && tr_tm!=TK_INSTEAD ){
140102 sqlite3ErrorMsg(pParse, "cannot create %s trigger on view: %S",
140103 (tr_tm == TK_BEFORE)?"BEFORE":"AFTER", pTableName->a);
140104 goto trigger_orphan_error;
140105 }
140106 if( !IsView(pTab) && tr_tm==TK_INSTEAD ){
140107 sqlite3ErrorMsg(pParse, "cannot create INSTEAD OF"
140108 " trigger on table: %S", pTableName->a);
140109 goto trigger_orphan_error;
140110 }
140111
@@ -140872,15 +140754,15 @@
140754 if( isAsteriskTerm(pParse, pOldExpr) ){
140755 int jj;
140756 for(jj=0; jj<pTab->nCol; jj++){
140757 Expr *pNewExpr;
140758 if( IsHiddenColumn(pTab->aCol+jj) ) continue;
140759 pNewExpr = sqlite3Expr(db, TK_ID, pTab->aCol[jj].zCnName);
140760 pNew = sqlite3ExprListAppend(pParse, pNew, pNewExpr);
140761 if( !db->mallocFailed ){
140762 struct ExprList_item *pItem = &pNew->a[pNew->nExpr-1];
140763 pItem->zEName = sqlite3DbStrDup(db, pTab->aCol[jj].zCnName);
140764 pItem->eEName = ENAME_NAME;
140765 }
140766 }
140767 }else{
140768 Expr *pNewExpr = sqlite3ExprDup(db, pOldExpr, 0);
@@ -141477,17 +141359,18 @@
141359 ** integer. In that case, add an OP_RealAffinity opcode to make sure
141360 ** it has been converted into REAL.
141361 */
141362 SQLITE_PRIVATE void sqlite3ColumnDefault(Vdbe *v, Table *pTab, int i, int iReg){
141363 assert( pTab!=0 );
141364 if( !IsView(pTab) ){
141365 sqlite3_value *pValue = 0;
141366 u8 enc = ENC(sqlite3VdbeDb(v));
141367 Column *pCol = &pTab->aCol[i];
141368 VdbeComment((v, "%s.%s", pTab->zName, pCol->zCnName));
141369 assert( i<pTab->nCol );
141370 sqlite3ValueFromExpr(sqlite3VdbeDb(v),
141371 sqlite3ColumnExpr(pTab,pCol), enc,
141372 pCol->affinity, &pValue);
141373 if( pValue ){
141374 sqlite3VdbeAppendP4(v, pValue, P4_MEM);
141375 }
141376 }
@@ -141653,11 +141536,11 @@
141536 }
141537 #endif
141538 pList = sqlite3ExprListAppend(pParse, pList, pNew);
141539 }
141540 eDest = IsVirtual(pTab) ? SRT_Table : SRT_Upfrom;
141541 }else if( IsView(pTab) ){
141542 for(i=0; i<pTab->nCol; i++){
141543 pList = sqlite3ExprListAppend(pParse, pList, exprRowColumn(pParse, i));
141544 }
141545 eDest = SRT_Table;
141546 }else{
@@ -141778,11 +141661,11 @@
141661 /* Figure out if we have any triggers and if the table being
141662 ** updated is a view.
141663 */
141664 #ifndef SQLITE_OMIT_TRIGGER
141665 pTrigger = sqlite3TriggersExist(pParse, pTab, TK_UPDATE, pChanges, &tmask);
141666 isView = IsView(pTab);
141667 assert( pTrigger || tmask==0 );
141668 #else
141669 # define pTrigger 0
141670 # define isView 0
141671 # define tmask 0
@@ -141867,17 +141750,20 @@
141750 ** column to be updated, make sure we have authorization to change
141751 ** that column.
141752 */
141753 chngRowid = chngPk = 0;
141754 for(i=0; i<pChanges->nExpr; i++){
141755 u8 hCol = sqlite3StrIHash(pChanges->a[i].zEName);
141756 /* If this is an UPDATE with a FROM clause, do not resolve expressions
141757 ** here. The call to sqlite3Select() below will do that. */
141758 if( nChangeFrom==0 && sqlite3ResolveExprNames(&sNC, pChanges->a[i].pExpr) ){
141759 goto update_cleanup;
141760 }
141761 for(j=0; j<pTab->nCol; j++){
141762 if( pTab->aCol[j].hName==hCol
141763 && sqlite3StrICmp(pTab->aCol[j].zCnName, pChanges->a[i].zEName)==0
141764 ){
141765 if( j==pTab->iPKey ){
141766 chngRowid = 1;
141767 pRowidExpr = pChanges->a[i].pExpr;
141768 iRowidExpr = i;
141769 }else if( pPk && (pTab->aCol[j].colFlags & COLFLAG_PRIMKEY)!=0 ){
@@ -141887,11 +141773,11 @@
141773 else if( pTab->aCol[j].colFlags & COLFLAG_GENERATED ){
141774 testcase( pTab->aCol[j].colFlags & COLFLAG_VIRTUAL );
141775 testcase( pTab->aCol[j].colFlags & COLFLAG_STORED );
141776 sqlite3ErrorMsg(pParse,
141777 "cannot UPDATE generated column \"%s\"",
141778 pTab->aCol[j].zCnName);
141779 goto update_cleanup;
141780 }
141781 #endif
141782 aXRef[j] = i;
141783 break;
@@ -141911,11 +141797,11 @@
141797 }
141798 #ifndef SQLITE_OMIT_AUTHORIZATION
141799 {
141800 int rc;
141801 rc = sqlite3AuthCheck(pParse, SQLITE_UPDATE, pTab->zName,
141802 j<0 ? "ROWID" : pTab->aCol[j].zCnName,
141803 db->aDb[iDb].zDbSName);
141804 if( rc==SQLITE_DENY ){
141805 goto update_cleanup;
141806 }else if( rc==SQLITE_IGNORE ){
141807 aXRef[j] = -1;
@@ -141943,12 +141829,14 @@
141829 do{
141830 bProgress = 0;
141831 for(i=0; i<pTab->nCol; i++){
141832 if( aXRef[i]>=0 ) continue;
141833 if( (pTab->aCol[i].colFlags & COLFLAG_GENERATED)==0 ) continue;
141834 if( sqlite3ExprReferencesUpdatedColumn(
141835 sqlite3ColumnExpr(pTab, &pTab->aCol[i]),
141836 aXRef, chngRowid)
141837 ){
141838 aXRef[i] = 99999;
141839 bProgress = 1;
141840 }
141841 }
141842 }while( bProgress );
@@ -143036,11 +142924,11 @@
142924 int k;
142925 assert( pPk->aiColumn[i]>=0 );
142926 k = sqlite3TableColumnToIndex(pIdx, pPk->aiColumn[i]);
142927 sqlite3VdbeAddOp3(v, OP_Column, iCur, k, iPk+i);
142928 VdbeComment((v, "%s.%s", pIdx->zName,
142929 pTab->aCol[pPk->aiColumn[i]].zCnName));
142930 }
142931 sqlite3VdbeVerifyAbortable(v, OE_Abort);
142932 i = sqlite3VdbeAddOp4Int(v, OP_Found, iDataCur, 0, iPk, nPk);
142933 VdbeCoverage(v);
142934 sqlite3VdbeAddOp4(v, OP_Halt, SQLITE_CORRUPT, OE_Abort, 0,
@@ -143666,11 +143554,11 @@
143554 ** this virtual-table, if one has been created, or NULL otherwise.
143555 */
143556 SQLITE_PRIVATE VTable *sqlite3GetVTable(sqlite3 *db, Table *pTab){
143557 VTable *pVtab;
143558 assert( IsVirtual(pTab) );
143559 for(pVtab=pTab->u.vtab.p; pVtab && pVtab->db!=db; pVtab=pVtab->pNext);
143560 return pVtab;
143561 }
143562
143563 /*
143564 ** Decrement the ref-count on a virtual table object. When the ref-count
@@ -143694,35 +143582,35 @@
143582 }
143583 }
143584
143585 /*
143586 ** Table p is a virtual table. This function moves all elements in the
143587 ** p->u.vtab.p list to the sqlite3.pDisconnect lists of their associated
143588 ** database connections to be disconnected at the next opportunity.
143589 ** Except, if argument db is not NULL, then the entry associated with
143590 ** connection db is left in the p->u.vtab.p list.
143591 */
143592 static VTable *vtabDisconnectAll(sqlite3 *db, Table *p){
143593 VTable *pRet = 0;
143594 VTable *pVTable = p->u.vtab.p;
143595 p->u.vtab.p = 0;
143596
143597 /* Assert that the mutex (if any) associated with the BtShared database
143598 ** that contains table p is held by the caller. See header comments
143599 ** above function sqlite3VtabUnlockList() for an explanation of why
143600 ** this makes it safe to access the sqlite3.pDisconnect list of any
143601 ** database connection that may have an entry in the p->u.vtab.p list.
143602 */
143603 assert( db==0 || sqlite3SchemaMutexHeld(db, 0, p->pSchema) );
143604
143605 while( pVTable ){
143606 sqlite3 *db2 = pVTable->db;
143607 VTable *pNext = pVTable->pNext;
143608 assert( db2 );
143609 if( db2==db ){
143610 pRet = pVTable;
143611 p->u.vtab.p = pRet;
143612 pRet->pNext = 0;
143613 }else{
143614 pVTable->pNext = db2->pDisconnect;
143615 db2->pDisconnect = pVTable;
143616 }
@@ -143746,11 +143634,11 @@
143634
143635 assert( IsVirtual(p) );
143636 assert( sqlite3BtreeHoldsAllMutexes(db) );
143637 assert( sqlite3_mutex_held(db->mutex) );
143638
143639 for(ppVTab=&p->u.vtab.p; *ppVTab; ppVTab=&(*ppVTab)->pNext){
143640 if( (*ppVTab)->db==db ){
143641 VTable *pVTab = *ppVTab;
143642 *ppVTab = pVTab->pNext;
143643 sqlite3VtabUnlock(pVTab);
143644 break;
@@ -143810,40 +143698,40 @@
143698 ** in the list are moved to the sqlite3.pDisconnect list of the associated
143699 ** database connection.
143700 */
143701 SQLITE_PRIVATE void sqlite3VtabClear(sqlite3 *db, Table *p){
143702 if( !db || db->pnBytesFreed==0 ) vtabDisconnectAll(0, p);
143703 if( p->u.vtab.azArg ){
143704 int i;
143705 for(i=0; i<p->u.vtab.nArg; i++){
143706 if( i!=1 ) sqlite3DbFree(db, p->u.vtab.azArg[i]);
143707 }
143708 sqlite3DbFree(db, p->u.vtab.azArg);
143709 }
143710 }
143711
143712 /*
143713 ** Add a new module argument to pTable->u.vtab.azArg[].
143714 ** The string is not copied - the pointer is stored. The
143715 ** string will be freed automatically when the table is
143716 ** deleted.
143717 */
143718 static void addModuleArgument(Parse *pParse, Table *pTable, char *zArg){
143719 sqlite3_int64 nBytes = sizeof(char *)*(2+pTable->u.vtab.nArg);
143720 char **azModuleArg;
143721 sqlite3 *db = pParse->db;
143722 if( pTable->u.vtab.nArg+3>=db->aLimit[SQLITE_LIMIT_COLUMN] ){
143723 sqlite3ErrorMsg(pParse, "too many columns on %s", pTable->zName);
143724 }
143725 azModuleArg = sqlite3DbRealloc(db, pTable->u.vtab.azArg, nBytes);
143726 if( azModuleArg==0 ){
143727 sqlite3DbFree(db, zArg);
143728 }else{
143729 int i = pTable->u.vtab.nArg++;
143730 azModuleArg[i] = zArg;
143731 azModuleArg[i+1] = 0;
143732 pTable->u.vtab.azArg = azModuleArg;
143733 }
143734 }
143735
143736 /*
143737 ** The parser calls this routine when it first sees a CREATE VIRTUAL TABLE
@@ -143862,14 +143750,15 @@
143750
143751 sqlite3StartTable(pParse, pName1, pName2, 0, 0, 1, ifNotExists);
143752 pTable = pParse->pNewTable;
143753 if( pTable==0 ) return;
143754 assert( 0==pTable->pIndex );
143755 pTable->eTabType = TABTYP_VTAB;
143756
143757 db = pParse->db;
143758
143759 assert( pTable->u.vtab.nArg==0 );
143760 addModuleArgument(pParse, pTable, sqlite3NameFromToken(db, pModuleName));
143761 addModuleArgument(pParse, pTable, 0);
143762 addModuleArgument(pParse, pTable, sqlite3DbStrDup(db, pTable->zName));
143763 assert( (pParse->sNameToken.z==pName2->z && pName2->z!=0)
143764 || (pParse->sNameToken.z==pName1->z && pName2->z==0)
@@ -143882,15 +143771,15 @@
143771 /* Creating a virtual table invokes the authorization callback twice.
143772 ** The first invocation, to obtain permission to INSERT a row into the
143773 ** sqlite_schema table, has already been made by sqlite3StartTable().
143774 ** The second call, to obtain permission to create the table, is made now.
143775 */
143776 if( pTable->u.vtab.azArg ){
143777 int iDb = sqlite3SchemaToIndex(db, pTable->pSchema);
143778 assert( iDb>=0 ); /* The database the table is being created in */
143779 sqlite3AuthCheck(pParse, SQLITE_CREATE_VTABLE, pTable->zName,
143780 pTable->u.vtab.azArg[0], pParse->db->aDb[iDb].zDbSName);
143781 }
143782 #endif
143783 }
143784
143785 /*
@@ -143916,11 +143805,11 @@
143805 sqlite3 *db = pParse->db; /* The database connection */
143806
143807 if( pTab==0 ) return;
143808 addArgumentToVtab(pParse);
143809 pParse->sArg.z = 0;
143810 if( pTab->u.vtab.nArg<1 ) return;
143811
143812 /* If the CREATE VIRTUAL TABLE statement is being entered for the
143813 ** first time (in other words if the virtual table is actually being
143814 ** created now instead of just being read out of sqlite_schema) then
143815 ** do additional initialization work and store the statement text
@@ -144031,12 +143920,12 @@
143920 char **pzErr
143921 ){
143922 VtabCtx sCtx;
143923 VTable *pVTable;
143924 int rc;
143925 const char *const*azArg = (const char *const*)pTab->u.vtab.azArg;
143926 int nArg = pTab->u.vtab.nArg;
143927 char *zErr = 0;
143928 char *zModuleName;
143929 int iDb;
143930 VtabCtx *pCtx;
143931
@@ -144064,11 +143953,11 @@
143953 pVTable->db = db;
143954 pVTable->pMod = pMod;
143955 pVTable->eVtabRisk = SQLITE_VTABRISK_Normal;
143956
143957 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
143958 pTab->u.vtab.azArg[1] = db->aDb[iDb].zDbSName;
143959
143960 /* Invoke the virtual table constructor */
143961 assert( &db->pVtabCtx );
143962 assert( xConstruct );
143963 sCtx.pTab = pTab;
@@ -144103,16 +143992,16 @@
143992 rc = SQLITE_ERROR;
143993 }else{
143994 int iCol;
143995 u16 oooHidden = 0;
143996 /* If everything went according to plan, link the new VTable structure
143997 ** into the linked list headed by pTab->u.vtab.p. Then loop through the
143998 ** columns of the table to see if any of them contain the token "hidden".
143999 ** If so, set the Column COLFLAG_HIDDEN flag and remove the token from
144000 ** the type string. */
144001 pVTable->pNext = pTab->u.vtab.p;
144002 pTab->u.vtab.p = pVTable;
144003
144004 for(iCol=0; iCol<pTab->nCol; iCol++){
144005 char *zType = sqlite3ColumnType(&pTab->aCol[iCol], "");
144006 int nType;
144007 int i = 0;
@@ -144166,15 +144055,15 @@
144055 if( !IsVirtual(pTab) || sqlite3GetVTable(db, pTab) ){
144056 return SQLITE_OK;
144057 }
144058
144059 /* Locate the required virtual table module */
144060 zMod = pTab->u.vtab.azArg[0];
144061 pMod = (Module*)sqlite3HashFind(&db->aModule, zMod);
144062
144063 if( !pMod ){
144064 const char *zModule = pTab->u.vtab.azArg[0];
144065 sqlite3ErrorMsg(pParse, "no such module: %s", zModule);
144066 rc = SQLITE_ERROR;
144067 }else{
144068 char *zErr = 0;
144069 rc = vtabCallConstructor(db, pTab, pMod, pMod->pModule->xConnect, &zErr);
@@ -144233,14 +144122,14 @@
144122 Table *pTab;
144123 Module *pMod;
144124 const char *zMod;
144125
144126 pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zDbSName);
144127 assert( pTab && IsVirtual(pTab) && !pTab->u.vtab.p );
144128
144129 /* Locate the required virtual table module */
144130 zMod = pTab->u.vtab.azArg[0];
144131 pMod = (Module*)sqlite3HashFind(&db->aModule, zMod);
144132
144133 /* If the module has been registered and includes a Create method,
144134 ** invoke it now. If the module has not been registered, return an
144135 ** error. Otherwise, do nothing.
@@ -144296,17 +144185,17 @@
144185 sParse.db = db;
144186 sParse.nQueryLoop = 1;
144187 if( SQLITE_OK==sqlite3RunParser(&sParse, zCreateTable, &zErr)
144188 && sParse.pNewTable
144189 && !db->mallocFailed
144190 && IsOrdinaryTable(sParse.pNewTable)
 
144191 ){
144192 if( !pTab->aCol ){
144193 Table *pNew = sParse.pNewTable;
144194 Index *pIdx;
144195 pTab->aCol = pNew->aCol;
144196 sqlite3ExprListDelete(db, pNew->u.tab.pDfltList);
144197 pTab->nNVCol = pTab->nCol = pNew->nCol;
144198 pTab->tabFlags |= pNew->tabFlags & (TF_WithoutRowid|TF_NoVisibleRowid);
144199 pNew->nCol = 0;
144200 pNew->aCol = 0;
144201 assert( pTab->pIndex==0 );
@@ -144357,14 +144246,14 @@
144246 SQLITE_PRIVATE int sqlite3VtabCallDestroy(sqlite3 *db, int iDb, const char *zTab){
144247 int rc = SQLITE_OK;
144248 Table *pTab;
144249
144250 pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zDbSName);
144251 if( pTab!=0 && ALWAYS(pTab->u.vtab.p!=0) ){
144252 VTable *p;
144253 int (*xDestroy)(sqlite3_vtab *);
144254 for(p=pTab->u.vtab.p; p; p=p->pNext){
144255 assert( p->pVtab );
144256 if( p->pVtab->nRef>0 ){
144257 return SQLITE_LOCKED;
144258 }
144259 }
@@ -144374,13 +144263,13 @@
144263 assert( xDestroy!=0 );
144264 pTab->nTabRef++;
144265 rc = xDestroy(p->pVtab);
144266 /* Remove the sqlite3_vtab* from the aVTrans[] array, if applicable */
144267 if( rc==SQLITE_OK ){
144268 assert( pTab->u.vtab.p==p && p->pNext==0 );
144269 p->pVtab = 0;
144270 pTab->u.vtab.p = 0;
144271 sqlite3VtabUnlock(p);
144272 }
144273 sqlite3DeleteTable(db, pTab);
144274 }
144275
@@ -144693,12 +144582,13 @@
144582 sqlite3DbFree(db, pTab);
144583 return 0;
144584 }
144585 pMod->pEpoTab = pTab;
144586 pTab->nTabRef = 1;
144587 pTab->eTabType = TABTYP_VTAB;
144588 pTab->pSchema = db->aDb[0].pSchema;
144589 assert( pTab->u.vtab.nArg==0 );
144590 pTab->iPKey = -1;
144591 pTab->tabFlags |= TF_Eponymous;
144592 addModuleArgument(pParse, pTab, sqlite3DbStrDup(db, pTab->zName));
144593 addModuleArgument(pParse, pTab, 0);
144594 addModuleArgument(pParse, pTab, sqlite3DbStrDup(db, pTab->zName));
@@ -145438,11 +145328,11 @@
145328 */
145329 static const char *explainIndexColumnName(Index *pIdx, int i){
145330 i = pIdx->aiColumn[i];
145331 if( i==XN_EXPR ) return "<expr>";
145332 if( i==XN_ROWID ) return "rowid";
145333 return pIdx->pTable->aCol[i].zCnName;
145334 }
145335
145336 /*
145337 ** This routine is a helper for explainIndexRange() below
145338 **
@@ -146650,12 +146540,13 @@
146540 if( sqlite3ExprIsConstant(x.pIdxExpr) ) continue;
146541 w.xExprCallback = whereIndexExprTransNode;
146542 #ifndef SQLITE_OMIT_GENERATED_COLUMNS
146543 }else if( iRef>=0
146544 && (pTab->aCol[iRef].colFlags & COLFLAG_VIRTUAL)!=0
146545 && ((pTab->aCol[iRef].colFlags & COLFLAG_HASCOLL)==0
146546 || sqlite3StrICmp(sqlite3ColumnColl(&pTab->aCol[iRef]),
146547 sqlite3StrBINARY)==0)
146548 ){
146549 /* Check to see if there are direct references to generated columns
146550 ** that are contained in the index. Pulling the generated column
146551 ** out of the index is an optimization only - the main table is always
146552 ** available if the index cannot be used. To avoid unnecessary
@@ -149070,11 +148961,15 @@
148961 pNew->u.x.leftColumn = aiCurCol[1];
148962 testcase( (prereqLeft | extraRight) != prereqLeft );
148963 pNew->prereqRight = prereqLeft | extraRight;
148964 pNew->prereqAll = prereqAll;
148965 pNew->eOperator = (operatorMask(pDup->op) + eExtraOp) & opMask;
148966 }else
148967 if( op==TK_ISNULL
148968 && !ExprHasProperty(pExpr,EP_FromJoin)
148969 && 0==sqlite3ExprCanBeNull(pLeft)
148970 ){
148971 pExpr->op = TK_TRUEFALSE;
148972 pExpr->u.zToken = "false";
148973 ExprSetProperty(pExpr, EP_IsFalse);
148974 pTerm->prereqAll = 0;
148975 pTerm->eOperator = 0;
@@ -150357,11 +150252,11 @@
150252 testcase( iCol==BMS );
150253 testcase( iCol==BMS-1 );
150254 if( !sentWarning ){
150255 sqlite3_log(SQLITE_WARNING_AUTOINDEX,
150256 "automatic index on %s(%s)", pTable->zName,
150257 pTable->aCol[iCol].zCnName);
150258 sentWarning = 1;
150259 }
150260 if( (idxCols & cMask)==0 ){
150261 if( whereLoopResize(pParse->db, pLoop, nKeyCol+1) ){
150262 goto end_auto_index_create;
@@ -152536,11 +152431,10 @@
152431 WhereLoop *pNew; /* Template WhereLoop object */
152432 int rc = SQLITE_OK; /* Return code */
152433 int iSortIdx = 1; /* Index number */
152434 int b; /* A boolean value */
152435 LogEst rSize; /* number of rows in the table */
 
152436 WhereClause *pWC; /* The parsed WHERE clause */
152437 Table *pTab; /* Table being queried */
152438
152439 pNew = pBuilder->pNew;
152440 pWInfo = pBuilder->pWInfo;
@@ -152579,11 +152473,10 @@
152473 sPk.pNext = pFirst;
152474 }
152475 pProbe = &sPk;
152476 }
152477 rSize = pTab->nRowLogEst;
 
152478
152479 #ifndef SQLITE_OMIT_AUTOMATIC_INDEX
152480 /* Automatic indexes */
152481 if( !pBuilder->pOrSet /* Not part of an OR optimization */
152482 && (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)==0
@@ -152593,12 +152486,14 @@
152486 && HasRowid(pTab) /* Not WITHOUT ROWID table. (FIXME: Why not?) */
152487 && !pSrc->fg.isCorrelated /* Not a correlated subquery */
152488 && !pSrc->fg.isRecursive /* Not a recursive common table expression. */
152489 ){
152490 /* Generate auto-index WhereLoops */
152491 LogEst rLogSize; /* Logarithm of the number of rows in the table */
152492 WhereTerm *pTerm;
152493 WhereTerm *pWCEnd = pWC->a + pWC->nTerm;
152494 rLogSize = estLog(rSize);
152495 for(pTerm=pWC->a; rc==SQLITE_OK && pTerm<pWCEnd; pTerm++){
152496 if( pTerm->prereqRight & pNew->maskSelf ) continue;
152497 if( termCanDriveIndex(pTerm, pSrc, 0) ){
152498 pNew->u.btree.nEq = 1;
152499 pNew->nSkip = 0;
@@ -152612,11 +152507,11 @@
152507 ** of X is smaller for views and subqueries so that the query planner
152508 ** will be more aggressive about generating automatic indexes for
152509 ** those objects, since there is no opportunity to add schema
152510 ** indexes on subqueries and views. */
152511 pNew->rSetup = rLogSize + rSize;
152512 if( !IsView(pTab) && (pTab->tabFlags & TF_Ephemeral)==0 ){
152513 pNew->rSetup += 28;
152514 }else{
152515 pNew->rSetup -= 10;
152516 }
152517 ApplyCostMultiplier(pNew->rSetup, pTab->costMult);
@@ -154763,11 +154658,11 @@
154658
154659 pTabItem = &pTabList->a[pLevel->iFrom];
154660 pTab = pTabItem->pTab;
154661 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
154662 pLoop = pLevel->pWLoop;
154663 if( (pTab->tabFlags & TF_Ephemeral)!=0 || IsView(pTab) ){
154664 /* Do nothing */
154665 }else
154666 #ifndef SQLITE_OMIT_VIRTUALTABLE
154667 if( (pLoop->wsFlags & WHERE_VIRTUALTABLE)!=0 ){
154668 const char *pVTab = (const char *)sqlite3GetVTable(db, pTab);
@@ -155132,11 +155027,11 @@
155027 ** Except, do not close cursors that will be reused by the OR optimization
155028 ** (WHERE_OR_SUBCLAUSE). And do not close the OP_OpenWrite cursors
155029 ** created for the ONEPASS optimization.
155030 */
155031 if( (pTab->tabFlags & TF_Ephemeral)==0
155032 && !IsView(pTab)
155033 && (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)==0
155034 ){
155035 int ws = pLoop->wsFlags;
155036 if( pWInfo->eOnePass==ONEPASS_OFF && (ws & WHERE_IDX_ONLY)==0 ){
155037 sqlite3VdbeAddOp1(v, OP_Close, pTabItem->iCursor);
@@ -161958,11 +161853,11 @@
161853 sqlite3ErrorMsg(pParse, "unknown table option: %.*s", yymsp[0].minor.yy0.n, yymsp[0].minor.yy0.z);
161854 }
161855 }
161856 break;
161857 case 23: /* columnname ::= nm typetoken */
161858 {sqlite3AddColumn(pParse,yymsp[-1].minor.yy0,yymsp[0].minor.yy0);}
161859 break;
161860 case 24: /* typetoken ::= */
161861 case 63: /* conslist_opt ::= */ yytestcase(yyruleno==63);
161862 case 102: /* as ::= */ yytestcase(yyruleno==102);
161863 {yymsp[1].minor.yy0.n = 0; yymsp[1].minor.yy0.z = 0;}
@@ -169147,11 +169042,11 @@
169042 goto error_out;
169043 }
169044
169045 /* Locate the table in question */
169046 pTab = sqlite3FindTable(db, zTableName, zDbName);
169047 if( !pTab || IsView(pTab) ){
169048 pTab = 0;
169049 goto error_out;
169050 }
169051
169052 /* Find the column for which info is requested */
@@ -169158,11 +169053,11 @@
169053 if( zColumnName==0 ){
169054 /* Query for existance of table only */
169055 }else{
169056 for(iCol=0; iCol<pTab->nCol; iCol++){
169057 pCol = &pTab->aCol[iCol];
169058 if( 0==sqlite3StrICmp(pCol->zCnName, zColumnName) ){
169059 break;
169060 }
169061 }
169062 if( iCol==pTab->nCol ){
169063 if( HasRowid(pTab) && sqlite3IsRowid(zColumnName) ){
@@ -169185,11 +169080,11 @@
169080 ** 2. The table is not a view and the column name identified an
169081 ** explicitly declared column. Copy meta information from *pCol.
169082 */
169083 if( pCol ){
169084 zDataType = sqlite3ColumnType(pCol,0);
169085 zCollSeq = sqlite3ColumnColl(pCol);
169086 notnull = pCol->notNull!=0;
169087 primarykey = (pCol->colFlags & COLFLAG_PRIMKEY)!=0;
169088 autoinc = pTab->iPKey==iCol && (pTab->tabFlags & TF_Autoincrement)!=0;
169089 }else{
169090 zDataType = "INTEGER";
@@ -201618,11 +201513,13 @@
201513 *piPk = 0;
201514
201515 assert( p->rc==SQLITE_OK );
201516 p->rc = prepareFreeAndCollectError(p->dbMain, &aStmt[0], &p->zErrmsg,
201517 sqlite3_mprintf(
201518 "SELECT "
201519 " (sql COLLATE nocase BETWEEN 'CREATE VIRTUAL' AND 'CREATE VIRTUAM'),"
201520 " rootpage"
201521 " FROM sqlite_schema"
201522 " WHERE name=%Q", zTab
201523 ));
201524 if( p->rc!=SQLITE_OK || sqlite3_step(aStmt[0])!=SQLITE_ROW ){
201525 /* Either an error, or no such table. */
@@ -203151,11 +203048,11 @@
203048 case RBU_STATE_COOKIE:
203049 pRet->iCookie = (u32)sqlite3_column_int64(pStmt, 1);
203050 break;
203051
203052 case RBU_STATE_OALSZ:
203053 pRet->iOalSz = sqlite3_column_int64(pStmt, 1);
203054 break;
203055
203056 case RBU_STATE_PHASEONESTEP:
203057 pRet->nPhaseOneStep = sqlite3_column_int64(pStmt, 1);
203058 break;
@@ -230952,11 +230849,11 @@
230849 int nArg, /* Number of args */
230850 sqlite3_value **apUnused /* Function arguments */
230851 ){
230852 assert( nArg==0 );
230853 UNUSED_PARAM2(nArg, apUnused);
230854 sqlite3_result_text(pCtx, "fts5: 2021-08-06 20:17:39 087b8b41c6ed76b55c11315e7e95679d67590be20ae21108b593d00bb7d1c57a", -1, SQLITE_TRANSIENT);
230855 }
230856
230857 /*
230858 ** Return true if zName is the extension on one of the shadow tables used
230859 ** by this module.
230860
+1 -1
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -146,11 +146,11 @@
146146
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147147
** [sqlite_version()] and [sqlite_source_id()].
148148
*/
149149
#define SQLITE_VERSION "3.37.0"
150150
#define SQLITE_VERSION_NUMBER 3037000
151
-#define SQLITE_SOURCE_ID "2021-07-21 15:42:05 60695359dc5d3bcba68a68e1842c40f4a01650eb5af408e02fb856fd8245e16d"
151
+#define SQLITE_SOURCE_ID "2021-08-06 20:17:39 087b8b41c6ed76b55c11315e7e95679d67590be20ae21108b593d00bb7d1c57a"
152152
153153
/*
154154
** CAPI3REF: Run-Time Library Version Numbers
155155
** KEYWORDS: sqlite3_version sqlite3_sourceid
156156
**
157157
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -146,11 +146,11 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.37.0"
150 #define SQLITE_VERSION_NUMBER 3037000
151 #define SQLITE_SOURCE_ID "2021-07-21 15:42:05 60695359dc5d3bcba68a68e1842c40f4a01650eb5af408e02fb856fd8245e16d"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
157
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -146,11 +146,11 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.37.0"
150 #define SQLITE_VERSION_NUMBER 3037000
151 #define SQLITE_SOURCE_ID "2021-08-06 20:17:39 087b8b41c6ed76b55c11315e7e95679d67590be20ae21108b593d00bb7d1c57a"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
157

Keyboard Shortcuts

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