Fossil SCM

Remove the db_name() function. In its place, the SQLITE_DBCONFIG_MAINDBNAME feature of SQLite is used to ensure that the three attached databases are always exactly named "repository", "configdb" and "localdb", regardless of which is opened first or the order in which they are attached. Update to the latest 3.15 alpha of SQLite which is now required for correct operation, since SQLITE_DBCONFIG_MAINDBNAME is required.

drh 2016-08-22 20:12 trunk merge
Commit 06aec61111d5e2f77df755ee8a244ab26a8bc392
+4 -5
--- src/add.c
+++ src/add.c
@@ -385,11 +385,11 @@
385385
*/
386386
static void process_files_to_remove(
387387
int dryRunFlag /* Zero to actually operate on the file-system. */
388388
){
389389
Stmt remove;
390
- if( db_table_exists(db_name("temp"), "fremove") ){
390
+ if( db_table_exists("temp", "fremove") ){
391391
db_prepare(&remove, "SELECT x FROM fremove ORDER BY x;");
392392
while( db_step(&remove)==SQLITE_ROW ){
393393
const char *zOldName = db_column_text(&remove, 0);
394394
if( !dryRunFlag ){
395395
file_delete(zOldName);
@@ -550,13 +550,12 @@
550550
#endif
551551
caseSensitive = db_get_boolean("case-sensitive",caseSensitive);
552552
}
553553
if( !caseSensitive && g.localOpen ){
554554
db_multi_exec(
555
- "CREATE INDEX IF NOT EXISTS %s.vfile_nocase"
556
- " ON vfile(pathname COLLATE nocase)",
557
- db_name("localdb")
555
+ "CREATE INDEX IF NOT EXISTS localdb.vfile_nocase"
556
+ " ON vfile(pathname COLLATE nocase)"
558557
);
559558
}
560559
}
561560
return caseSensitive;
562561
}
@@ -779,11 +778,11 @@
779778
*/
780779
static void process_files_to_move(
781780
int dryRunFlag /* Zero to actually operate on the file-system. */
782781
){
783782
Stmt move;
784
- if( db_table_exists(db_name("temp"), "fmove") ){
783
+ if( db_table_exists("temp", "fmove") ){
785784
db_prepare(&move, "SELECT x, y FROM fmove ORDER BY x;");
786785
while( db_step(&move)==SQLITE_ROW ){
787786
const char *zOldName = db_column_text(&move, 0);
788787
const char *zNewName = db_column_text(&move, 1);
789788
if( !dryRunFlag ){
790789
--- src/add.c
+++ src/add.c
@@ -385,11 +385,11 @@
385 */
386 static void process_files_to_remove(
387 int dryRunFlag /* Zero to actually operate on the file-system. */
388 ){
389 Stmt remove;
390 if( db_table_exists(db_name("temp"), "fremove") ){
391 db_prepare(&remove, "SELECT x FROM fremove ORDER BY x;");
392 while( db_step(&remove)==SQLITE_ROW ){
393 const char *zOldName = db_column_text(&remove, 0);
394 if( !dryRunFlag ){
395 file_delete(zOldName);
@@ -550,13 +550,12 @@
550 #endif
551 caseSensitive = db_get_boolean("case-sensitive",caseSensitive);
552 }
553 if( !caseSensitive && g.localOpen ){
554 db_multi_exec(
555 "CREATE INDEX IF NOT EXISTS %s.vfile_nocase"
556 " ON vfile(pathname COLLATE nocase)",
557 db_name("localdb")
558 );
559 }
560 }
561 return caseSensitive;
562 }
@@ -779,11 +778,11 @@
779 */
780 static void process_files_to_move(
781 int dryRunFlag /* Zero to actually operate on the file-system. */
782 ){
783 Stmt move;
784 if( db_table_exists(db_name("temp"), "fmove") ){
785 db_prepare(&move, "SELECT x, y FROM fmove ORDER BY x;");
786 while( db_step(&move)==SQLITE_ROW ){
787 const char *zOldName = db_column_text(&move, 0);
788 const char *zNewName = db_column_text(&move, 1);
789 if( !dryRunFlag ){
790
--- src/add.c
+++ src/add.c
@@ -385,11 +385,11 @@
385 */
386 static void process_files_to_remove(
387 int dryRunFlag /* Zero to actually operate on the file-system. */
388 ){
389 Stmt remove;
390 if( db_table_exists("temp", "fremove") ){
391 db_prepare(&remove, "SELECT x FROM fremove ORDER BY x;");
392 while( db_step(&remove)==SQLITE_ROW ){
393 const char *zOldName = db_column_text(&remove, 0);
394 if( !dryRunFlag ){
395 file_delete(zOldName);
@@ -550,13 +550,12 @@
550 #endif
551 caseSensitive = db_get_boolean("case-sensitive",caseSensitive);
552 }
553 if( !caseSensitive && g.localOpen ){
554 db_multi_exec(
555 "CREATE INDEX IF NOT EXISTS localdb.vfile_nocase"
556 " ON vfile(pathname COLLATE nocase)"
 
557 );
558 }
559 }
560 return caseSensitive;
561 }
@@ -779,11 +778,11 @@
778 */
779 static void process_files_to_move(
780 int dryRunFlag /* Zero to actually operate on the file-system. */
781 ){
782 Stmt move;
783 if( db_table_exists("temp", "fmove") ){
784 db_prepare(&move, "SELECT x, y FROM fmove ORDER BY x;");
785 while( db_step(&move)==SQLITE_ROW ){
786 const char *zOldName = db_column_text(&move, 0);
787 const char *zNewName = db_column_text(&move, 1);
788 if( !dryRunFlag ){
789
+2 -2
--- src/checkin.c
+++ src/checkin.c
@@ -2229,12 +2229,12 @@
22292229
/* Clear the undo/redo stack */
22302230
undo_reset();
22312231
22322232
/* Commit */
22332233
db_multi_exec("DELETE FROM vvar WHERE name='ci-comment'");
2234
- db_multi_exec("PRAGMA %s.application_id=252006673;", db_name("repository"));
2235
- db_multi_exec("PRAGMA %s.application_id=252006674;", db_name("localdb"));
2234
+ db_multi_exec("PRAGMA repository.application_id=252006673;");
2235
+ db_multi_exec("PRAGMA localdb.application_id=252006674;");
22362236
if( dryRunFlag ){
22372237
db_end_transaction(1);
22382238
exit(1);
22392239
}
22402240
db_end_transaction(0);
22412241
--- src/checkin.c
+++ src/checkin.c
@@ -2229,12 +2229,12 @@
2229 /* Clear the undo/redo stack */
2230 undo_reset();
2231
2232 /* Commit */
2233 db_multi_exec("DELETE FROM vvar WHERE name='ci-comment'");
2234 db_multi_exec("PRAGMA %s.application_id=252006673;", db_name("repository"));
2235 db_multi_exec("PRAGMA %s.application_id=252006674;", db_name("localdb"));
2236 if( dryRunFlag ){
2237 db_end_transaction(1);
2238 exit(1);
2239 }
2240 db_end_transaction(0);
2241
--- src/checkin.c
+++ src/checkin.c
@@ -2229,12 +2229,12 @@
2229 /* Clear the undo/redo stack */
2230 undo_reset();
2231
2232 /* Commit */
2233 db_multi_exec("DELETE FROM vvar WHERE name='ci-comment'");
2234 db_multi_exec("PRAGMA repository.application_id=252006673;");
2235 db_multi_exec("PRAGMA localdb.application_id=252006674;");
2236 if( dryRunFlag ){
2237 db_end_transaction(1);
2238 exit(1);
2239 }
2240 db_end_transaction(0);
2241
+1 -1
--- src/checkout.c
+++ src/checkout.c
@@ -306,11 +306,11 @@
306306
if( !forceFlag && unsaved_changes(0) ){
307307
fossil_fatal("there are unsaved changes in the current checkout");
308308
}
309309
if( !forceFlag
310310
&& db_table_exists("localdb","stash")
311
- && db_exists("SELECT 1 FROM %s.stash", db_name("localdb"))
311
+ && db_exists("SELECT 1 FROM localdb.stash")
312312
){
313313
fossil_fatal("closing the checkout will delete your stash");
314314
}
315315
if( db_is_writeable("repository") ){
316316
char *zUnset = mprintf("ckout:%q", g.zLocalRoot);
317317
--- src/checkout.c
+++ src/checkout.c
@@ -306,11 +306,11 @@
306 if( !forceFlag && unsaved_changes(0) ){
307 fossil_fatal("there are unsaved changes in the current checkout");
308 }
309 if( !forceFlag
310 && db_table_exists("localdb","stash")
311 && db_exists("SELECT 1 FROM %s.stash", db_name("localdb"))
312 ){
313 fossil_fatal("closing the checkout will delete your stash");
314 }
315 if( db_is_writeable("repository") ){
316 char *zUnset = mprintf("ckout:%q", g.zLocalRoot);
317
--- src/checkout.c
+++ src/checkout.c
@@ -306,11 +306,11 @@
306 if( !forceFlag && unsaved_changes(0) ){
307 fossil_fatal("there are unsaved changes in the current checkout");
308 }
309 if( !forceFlag
310 && db_table_exists("localdb","stash")
311 && db_exists("SELECT 1 FROM localdb.stash")
312 ){
313 fossil_fatal("closing the checkout will delete your stash");
314 }
315 if( db_is_writeable("repository") ){
316 char *zUnset = mprintf("ckout:%q", g.zLocalRoot);
317
--- src/codecheck1.c
+++ src/codecheck1.c
@@ -249,11 +249,10 @@
249249
** A list of functions that return strings that are safe to insert into
250250
** SQL using %s.
251251
*/
252252
static const char *azSafeFunc[] = {
253253
"filename_collation",
254
- "db_name",
255254
"leaf_is_closed_sql",
256255
"timeline_query_for_www",
257256
"timeline_query_for_tty",
258257
"blob_sql_text",
259258
"glob_expr",
260259
--- src/codecheck1.c
+++ src/codecheck1.c
@@ -249,11 +249,10 @@
249 ** A list of functions that return strings that are safe to insert into
250 ** SQL using %s.
251 */
252 static const char *azSafeFunc[] = {
253 "filename_collation",
254 "db_name",
255 "leaf_is_closed_sql",
256 "timeline_query_for_www",
257 "timeline_query_for_tty",
258 "blob_sql_text",
259 "glob_expr",
260
--- src/codecheck1.c
+++ src/codecheck1.c
@@ -249,11 +249,10 @@
249 ** A list of functions that return strings that are safe to insert into
250 ** SQL using %s.
251 */
252 static const char *azSafeFunc[] = {
253 "filename_collation",
 
254 "leaf_is_closed_sql",
255 "timeline_query_for_www",
256 "timeline_query_for_tty",
257 "blob_sql_text",
258 "glob_expr",
259
+71 -66
--- src/db.c
+++ src/db.c
@@ -961,52 +961,79 @@
961961
db_encryption_key(zDbName, &key);
962962
db_multi_exec("ATTACH DATABASE %Q AS %Q KEY %Q",
963963
zDbName, zLabel, blob_str(&key));
964964
blob_reset(&key);
965965
}
966
+
967
+/*
968
+** Change the schema name of the "main" database to zLabel.
969
+** zLabel must be a static string that is unchanged for the life of
970
+** the database connection.
971
+**
972
+** After calling this routine, db_database_slot(zLabel) should
973
+** return 0.
974
+*/
975
+void db_set_main_schemaname(sqlite3 *db, const char *zLabel){
976
+ if( sqlite3_db_config(db, SQLITE_DBCONFIG_MAINDBNAME, zLabel) ){
977
+ fossil_fatal("Fossil requires a version of SQLite that supports the "
978
+ "SQLITE_DBCONFIG_MAINDBNAME interface.");
979
+ }
980
+}
981
+
982
+/*
983
+** Return the slot number for database zLabel. The first database
984
+** opened is slot 0. The "temp" database is slot 1. Attached databases
985
+** are slots 2 and higher.
986
+**
987
+** Return -1 if zLabel does not match any open database.
988
+*/
989
+int db_database_slot(const char *zLabel){
990
+ int iSlot = -1;
991
+ Stmt q;
992
+ if( g.db==0 ) return iSlot;
993
+ db_prepare(&q, "PRAGMA database_list");
994
+ while( db_step(&q)==SQLITE_ROW ){
995
+ if( fossil_strcmp(db_column_text(&q,1),zLabel)==0 ){
996
+ iSlot = db_column_int(&q, 0);
997
+ break;
998
+ }
999
+ }
1000
+ db_finalize(&q);
1001
+ return iSlot;
1002
+}
9661003
9671004
/*
9681005
** zDbName is the name of a database file. If no other database
9691006
** file is open, then open this one. If another database file is
9701007
** already open, then attach zDbName using the name zLabel.
9711008
*/
972
-void db_open_or_attach(
973
- const char *zDbName,
974
- const char *zLabel,
975
- int *pWasAttached
976
-){
1009
+void db_open_or_attach(const char *zDbName, const char *zLabel){
9771010
if( !g.db ){
978
- assert( g.zMainDbType==0 );
9791011
g.db = db_open(zDbName);
980
- g.zMainDbType = zLabel;
981
- if( pWasAttached ) *pWasAttached = 0;
1012
+ db_set_main_schemaname(g.db, zLabel);
9821013
}else{
983
- assert( g.zMainDbType!=0 );
9841014
db_attach(zDbName, zLabel);
985
- if( pWasAttached ) *pWasAttached = 1;
9861015
}
9871016
}
9881017
9891018
/*
990
-** Close the user database.
1019
+** Close the per-user database file in ~/.fossil
9911020
*/
9921021
void db_close_config(){
993
- if( g.useAttach ){
1022
+ int iSlot = db_database_slot("configdb");
1023
+ if( iSlot>0 ){
9941024
db_detach("configdb");
995
- g.useAttach = 0;
9961025
g.zConfigDbName = 0;
9971026
}else if( g.dbConfig ){
9981027
sqlite3_wal_checkpoint(g.dbConfig, 0);
9991028
sqlite3_close(g.dbConfig);
10001029
g.dbConfig = 0;
1001
- g.zConfigDbType = 0;
10021030
g.zConfigDbName = 0;
1003
- }else if( g.db && fossil_strcmp(g.zMainDbType, "configdb")==0 ){
1031
+ }else if( g.db && 0==iSlot ){
10041032
sqlite3_wal_checkpoint(g.db, 0);
10051033
sqlite3_close(g.db);
10061034
g.db = 0;
1007
- g.zMainDbType = 0;
10081035
g.zConfigDbName = 0;
10091036
}
10101037
}
10111038
10121039
/*
@@ -1023,11 +1050,12 @@
10231050
*/
10241051
int db_open_config(int useAttach, int isOptional){
10251052
char *zDbName;
10261053
char *zHome;
10271054
if( g.zConfigDbName ){
1028
- if( useAttach==g.useAttach ) return 1; /* Already open. */
1055
+ int alreadyAttached = db_database_slot("configdb")>0;
1056
+ if( useAttach==alreadyAttached ) return 1; /* Already open. */
10291057
db_close_config();
10301058
}
10311059
zHome = fossil_getenv("FOSSIL_HOME");
10321060
#if defined(_WIN32) || defined(__CYGWIN__)
10331061
if( zHome==0 ){
@@ -1077,17 +1105,15 @@
10771105
if( file_access(zDbName, W_OK) ){
10781106
if( isOptional ) return 0;
10791107
fossil_fatal("configuration file %s must be writeable", zDbName);
10801108
}
10811109
if( useAttach ){
1082
- db_open_or_attach(zDbName, "configdb", &g.useAttach);
1110
+ db_open_or_attach(zDbName, "configdb");
10831111
g.dbConfig = 0;
1084
- g.zConfigDbType = 0;
10851112
}else{
1086
- g.useAttach = 0;
10871113
g.dbConfig = db_open(zDbName);
1088
- g.zConfigDbType = "configdb";
1114
+ db_set_main_schemaname(g.dbConfig, "configdb");
10891115
}
10901116
g.zConfigDbName = zDbName;
10911117
return 1;
10921118
}
10931119
@@ -1096,13 +1122,12 @@
10961122
*/
10971123
int db_table_exists(
10981124
const char *zDb, /* One of: NULL, "configdb", "localdb", "repository" */
10991125
const char *zTable /* Name of table */
11001126
){
1101
- return sqlite3_table_column_metadata(g.db,
1102
- zDb ? db_name(zDb) : 0, zTable, 0,
1103
- 0, 0, 0, 0, 0)==SQLITE_OK;
1127
+ return sqlite3_table_column_metadata(g.db, zDb, zTable, 0,
1128
+ 0, 0, 0, 0, 0)==SQLITE_OK;
11041129
}
11051130
11061131
/*
11071132
** Return TRUE if zTable exists and contains column zColumn.
11081133
** Return FALSE if zTable does not exist or if zTable exists
@@ -1111,13 +1136,12 @@
11111136
int db_table_has_column(
11121137
const char *zDb, /* One of: NULL, "config", "localdb", "repository" */
11131138
const char *zTable, /* Name of table */
11141139
const char *zColumn /* Name of column in table */
11151140
){
1116
- return sqlite3_table_column_metadata(g.db,
1117
- zDb ? db_name(zDb) : 0, zTable, zColumn,
1118
- 0, 0, 0, 0, 0)==SQLITE_OK;
1141
+ return sqlite3_table_column_metadata(g.db, zDb, zTable, zColumn,
1142
+ 0, 0, 0, 0, 0)==SQLITE_OK;
11191143
}
11201144
11211145
/*
11221146
** Returns TRUE if zTable exists in the local database but lacks column
11231147
** zColumn
@@ -1124,12 +1148,12 @@
11241148
*/
11251149
static int db_local_table_exists_but_lacks_column(
11261150
const char *zTable,
11271151
const char *zColumn
11281152
){
1129
- return db_table_exists(db_name("localdb"), zTable)
1130
- && !db_table_has_column(db_name("localdb"), zTable, zColumn);
1153
+ return db_table_exists("localdb", zTable)
1154
+ && !db_table_has_column("localdb", zTable, zColumn);
11311155
}
11321156
11331157
/*
11341158
** If zDbName is a valid local database file, open it and return
11351159
** true. If it is not a valid local database file, return 0.
@@ -1139,13 +1163,13 @@
11391163
char *zVFileDef;
11401164
11411165
if( file_access(zDbName, F_OK) ) return 0;
11421166
lsize = file_size(zDbName);
11431167
if( lsize%1024!=0 || lsize<4096 ) return 0;
1144
- db_open_or_attach(zDbName, "localdb", 0);
1145
- zVFileDef = db_text(0, "SELECT sql FROM %s.sqlite_master"
1146
- " WHERE name=='vfile'", db_name("localdb"));
1168
+ db_open_or_attach(zDbName, "localdb");
1169
+ zVFileDef = db_text(0, "SELECT sql FROM localdb.sqlite_master"
1170
+ " WHERE name=='vfile'");
11471171
if( zVFileDef==0 ) return 0;
11481172
11491173
/* If the "isexe" column is missing from the vfile table, then
11501174
** add it now. This code added on 2010-03-06. After all users have
11511175
** upgraded, this code can be safely deleted.
@@ -1290,11 +1314,11 @@
12901314
#endif
12911315
fossil_panic("not a valid repository: %s", zDbName);
12921316
}
12931317
}
12941318
g.zRepositoryName = mprintf("%s", zDbName);
1295
- db_open_or_attach(g.zRepositoryName, "repository", 0);
1319
+ db_open_or_attach(g.zRepositoryName, "repository");
12961320
g.repositoryOpen = 1;
12971321
/* Cache "allow-symlinks" option, because we'll need it on every stat call */
12981322
g.allowSymlinks = db_get_boolean("allow-symlinks",
12991323
db_allow_symlinks_by_default());
13001324
g.zAuxSchema = db_get("aux-schema","");
@@ -1304,11 +1328,11 @@
13041328
** can be removed in the future, once all users have upgraded to the
13051329
** 2014-11-28 or later schema.
13061330
*/
13071331
if( !db_table_has_column("repository","plink","baseid") ){
13081332
db_multi_exec(
1309
- "ALTER TABLE %s.plink ADD COLUMN baseid;", db_name("repository")
1333
+ "ALTER TABLE repository.plink ADD COLUMN baseid;"
13101334
);
13111335
}
13121336
13131337
/* Verify that the MLINK table has the newer columns added by the
13141338
** 2015-01-24 schema change. Create them if necessary. This code
@@ -1316,13 +1340,12 @@
13161340
** 2015-01-24 or later schema.
13171341
*/
13181342
if( !db_table_has_column("repository","mlink","isaux") ){
13191343
db_begin_transaction();
13201344
db_multi_exec(
1321
- "ALTER TABLE %s.mlink ADD COLUMN pmid INTEGER DEFAULT 0;"
1322
- "ALTER TABLE %s.mlink ADD COLUMN isaux BOOLEAN DEFAULT 0;",
1323
- db_name("repository"), db_name("repository")
1345
+ "ALTER TABLE repository.mlink ADD COLUMN pmid INTEGER DEFAULT 0;"
1346
+ "ALTER TABLE repository.mlink ADD COLUMN isaux BOOLEAN DEFAULT 0;"
13241347
);
13251348
db_end_transaction(0);
13261349
}
13271350
}
13281351
@@ -1374,22 +1397,10 @@
13741397
fossil_fatal("specify the repository name as a command-line argument");
13751398
}
13761399
}
13771400
}
13781401
1379
-/*
1380
-** Return the name of the database "localdb", "configdb", or "repository".
1381
-*/
1382
-const char *db_name(const char *zDb){
1383
- assert( fossil_strcmp(zDb,"localdb")==0
1384
- || fossil_strcmp(zDb,"configdb")==0
1385
- || fossil_strcmp(zDb,"repository")==0
1386
- || fossil_strcmp(zDb,"temp")==0 );
1387
- if( fossil_strcmp(zDb, g.zMainDbType)==0 ) zDb = "main";
1388
- return zDb;
1389
-}
1390
-
13911402
/*
13921403
** Return TRUE if the schema is out-of-date
13931404
*/
13941405
int db_schema_is_outofdate(void){
13951406
return strcmp(g.zAuxSchema,AUX_SCHEMA_MIN)<0
@@ -1398,11 +1409,11 @@
13981409
13991410
/*
14001411
** Return true if the database is writeable
14011412
*/
14021413
int db_is_writeable(const char *zName){
1403
- return g.db!=0 && !sqlite3_db_readonly(g.db, db_name(zName));
1414
+ return g.db!=0 && !sqlite3_db_readonly(g.db, zName);
14041415
}
14051416
14061417
/*
14071418
** Verify that the repository schema is correct. If it is not correct,
14081419
** issue a fatal error and die.
@@ -1443,11 +1454,11 @@
14431454
}
14441455
if( db_open_local(zRepo)==0 ){
14451456
fossil_fatal("not in a local checkout");
14461457
return;
14471458
}
1448
- db_open_or_attach(zRepo, "test_repo", 0);
1459
+ db_open_or_attach(zRepo, "test_repo");
14491460
db_lset("repository", blob_str(&repo));
14501461
db_record_repository_filename(blob_str(&repo));
14511462
db_close(1);
14521463
}
14531464
@@ -1503,18 +1514,18 @@
15031514
}
15041515
db_end_transaction(1);
15051516
pStmt = 0;
15061517
db_close_config();
15071518
1508
- /* If the localdb (the check-out database) is open and if it has
1509
- ** a lot of unused free space, then VACUUM it as we shut down.
1519
+ /* If the localdb has a lot of unused free space,
1520
+ ** then VACUUM it as we shut down.
15101521
*/
1511
- if( g.localOpen && strcmp(db_name("localdb"),"main")==0 ){
1512
- int nFree = db_int(0, "PRAGMA main.freelist_count");
1513
- int nTotal = db_int(0, "PRAGMA main.page_count");
1522
+ if( db_database_slot("localdb")>=0 ){
1523
+ int nFree = db_int(0, "PRAGMA localdb.freelist_count");
1524
+ int nTotal = db_int(0, "PRAGMA localdb.page_count");
15141525
if( nFree>nTotal/4 ){
1515
- db_multi_exec("VACUUM;");
1526
+ db_multi_exec("VACUUM localdb;");
15161527
}
15171528
}
15181529
15191530
if( g.db ){
15201531
int rc;
@@ -1524,18 +1535,15 @@
15241535
while( (pStmt = sqlite3_next_stmt(g.db, pStmt))!=0 ){
15251536
fossil_warning("unfinalized SQL statement: [%s]", sqlite3_sql(pStmt));
15261537
}
15271538
}
15281539
g.db = 0;
1529
- g.zMainDbType = 0;
15301540
}
15311541
g.repositoryOpen = 0;
15321542
g.localOpen = 0;
15331543
assert( g.dbConfig==0 );
1534
- assert( g.useAttach==0 );
15351544
assert( g.zConfigDbName==0 );
1536
- assert( g.zConfigDbType==0 );
15371545
}
15381546
15391547
15401548
/*
15411549
** Create a new empty repository database with the given name.
@@ -2008,15 +2016,12 @@
20082016
** because the main database connection was already pointing to the config
20092017
** database.
20102018
*/
20112019
if( g.dbConfig ){
20122020
sqlite3 *dbTemp = g.db;
2013
- const char *zTempDbType = g.zMainDbType;
20142021
g.db = g.dbConfig;
2015
- g.zMainDbType = g.zConfigDbType;
20162022
g.dbConfig = dbTemp;
2017
- g.zConfigDbType = zTempDbType;
20182023
}
20192024
}
20202025
20212026
/*
20222027
** Try to read a versioned setting string from .fossil-settings/<name>.
@@ -3019,11 +3024,11 @@
30193024
int i, j;
30203025
Stmt q;
30213026
Blob allSql;
30223027
int dryRun = find_option("dry-run", "n", 0)!=0;
30233028
for(i=2; i<g.argc; i++){
3024
- db_open_or_attach(g.argv[i], "main", 0);
3029
+ db_open_or_attach(g.argv[i], "main");
30253030
blob_init(&allSql, "BEGIN;\n", -1);
30263031
db_prepare(&q,
30273032
"SELECT name, sql FROM main.sqlite_master "
30283033
" WHERE type='table' AND sql NOT LIKE '%%WITHOUT ROWID%%'"
30293034
" AND name IN ('global_config','shun','concealed','config',"
@@ -3074,17 +3079,17 @@
30743079
void create_admin_log_table(void){
30753080
static int once = 0;
30763081
if( once ) return;
30773082
once = 1;
30783083
db_multi_exec(
3079
- "CREATE TABLE IF NOT EXISTS \"%w\".admin_log(\n"
3084
+ "CREATE TABLE IF NOT EXISTS repository.admin_log(\n"
30803085
" id INTEGER PRIMARY KEY,\n"
30813086
" time INTEGER, -- Seconds since 1970\n"
30823087
" page TEXT, -- path of page\n"
30833088
" who TEXT, -- User who made the change\n "
30843089
" what TEXT -- What changed\n"
3085
- ")", db_name("repository")
3090
+ ")"
30863091
);
30873092
}
30883093
30893094
/*
30903095
** Write a message into the admin_event table, if admin logging is
30913096
--- src/db.c
+++ src/db.c
@@ -961,52 +961,79 @@
961 db_encryption_key(zDbName, &key);
962 db_multi_exec("ATTACH DATABASE %Q AS %Q KEY %Q",
963 zDbName, zLabel, blob_str(&key));
964 blob_reset(&key);
965 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
966
967 /*
968 ** zDbName is the name of a database file. If no other database
969 ** file is open, then open this one. If another database file is
970 ** already open, then attach zDbName using the name zLabel.
971 */
972 void db_open_or_attach(
973 const char *zDbName,
974 const char *zLabel,
975 int *pWasAttached
976 ){
977 if( !g.db ){
978 assert( g.zMainDbType==0 );
979 g.db = db_open(zDbName);
980 g.zMainDbType = zLabel;
981 if( pWasAttached ) *pWasAttached = 0;
982 }else{
983 assert( g.zMainDbType!=0 );
984 db_attach(zDbName, zLabel);
985 if( pWasAttached ) *pWasAttached = 1;
986 }
987 }
988
989 /*
990 ** Close the user database.
991 */
992 void db_close_config(){
993 if( g.useAttach ){
 
994 db_detach("configdb");
995 g.useAttach = 0;
996 g.zConfigDbName = 0;
997 }else if( g.dbConfig ){
998 sqlite3_wal_checkpoint(g.dbConfig, 0);
999 sqlite3_close(g.dbConfig);
1000 g.dbConfig = 0;
1001 g.zConfigDbType = 0;
1002 g.zConfigDbName = 0;
1003 }else if( g.db && fossil_strcmp(g.zMainDbType, "configdb")==0 ){
1004 sqlite3_wal_checkpoint(g.db, 0);
1005 sqlite3_close(g.db);
1006 g.db = 0;
1007 g.zMainDbType = 0;
1008 g.zConfigDbName = 0;
1009 }
1010 }
1011
1012 /*
@@ -1023,11 +1050,12 @@
1023 */
1024 int db_open_config(int useAttach, int isOptional){
1025 char *zDbName;
1026 char *zHome;
1027 if( g.zConfigDbName ){
1028 if( useAttach==g.useAttach ) return 1; /* Already open. */
 
1029 db_close_config();
1030 }
1031 zHome = fossil_getenv("FOSSIL_HOME");
1032 #if defined(_WIN32) || defined(__CYGWIN__)
1033 if( zHome==0 ){
@@ -1077,17 +1105,15 @@
1077 if( file_access(zDbName, W_OK) ){
1078 if( isOptional ) return 0;
1079 fossil_fatal("configuration file %s must be writeable", zDbName);
1080 }
1081 if( useAttach ){
1082 db_open_or_attach(zDbName, "configdb", &g.useAttach);
1083 g.dbConfig = 0;
1084 g.zConfigDbType = 0;
1085 }else{
1086 g.useAttach = 0;
1087 g.dbConfig = db_open(zDbName);
1088 g.zConfigDbType = "configdb";
1089 }
1090 g.zConfigDbName = zDbName;
1091 return 1;
1092 }
1093
@@ -1096,13 +1122,12 @@
1096 */
1097 int db_table_exists(
1098 const char *zDb, /* One of: NULL, "configdb", "localdb", "repository" */
1099 const char *zTable /* Name of table */
1100 ){
1101 return sqlite3_table_column_metadata(g.db,
1102 zDb ? db_name(zDb) : 0, zTable, 0,
1103 0, 0, 0, 0, 0)==SQLITE_OK;
1104 }
1105
1106 /*
1107 ** Return TRUE if zTable exists and contains column zColumn.
1108 ** Return FALSE if zTable does not exist or if zTable exists
@@ -1111,13 +1136,12 @@
1111 int db_table_has_column(
1112 const char *zDb, /* One of: NULL, "config", "localdb", "repository" */
1113 const char *zTable, /* Name of table */
1114 const char *zColumn /* Name of column in table */
1115 ){
1116 return sqlite3_table_column_metadata(g.db,
1117 zDb ? db_name(zDb) : 0, zTable, zColumn,
1118 0, 0, 0, 0, 0)==SQLITE_OK;
1119 }
1120
1121 /*
1122 ** Returns TRUE if zTable exists in the local database but lacks column
1123 ** zColumn
@@ -1124,12 +1148,12 @@
1124 */
1125 static int db_local_table_exists_but_lacks_column(
1126 const char *zTable,
1127 const char *zColumn
1128 ){
1129 return db_table_exists(db_name("localdb"), zTable)
1130 && !db_table_has_column(db_name("localdb"), zTable, zColumn);
1131 }
1132
1133 /*
1134 ** If zDbName is a valid local database file, open it and return
1135 ** true. If it is not a valid local database file, return 0.
@@ -1139,13 +1163,13 @@
1139 char *zVFileDef;
1140
1141 if( file_access(zDbName, F_OK) ) return 0;
1142 lsize = file_size(zDbName);
1143 if( lsize%1024!=0 || lsize<4096 ) return 0;
1144 db_open_or_attach(zDbName, "localdb", 0);
1145 zVFileDef = db_text(0, "SELECT sql FROM %s.sqlite_master"
1146 " WHERE name=='vfile'", db_name("localdb"));
1147 if( zVFileDef==0 ) return 0;
1148
1149 /* If the "isexe" column is missing from the vfile table, then
1150 ** add it now. This code added on 2010-03-06. After all users have
1151 ** upgraded, this code can be safely deleted.
@@ -1290,11 +1314,11 @@
1290 #endif
1291 fossil_panic("not a valid repository: %s", zDbName);
1292 }
1293 }
1294 g.zRepositoryName = mprintf("%s", zDbName);
1295 db_open_or_attach(g.zRepositoryName, "repository", 0);
1296 g.repositoryOpen = 1;
1297 /* Cache "allow-symlinks" option, because we'll need it on every stat call */
1298 g.allowSymlinks = db_get_boolean("allow-symlinks",
1299 db_allow_symlinks_by_default());
1300 g.zAuxSchema = db_get("aux-schema","");
@@ -1304,11 +1328,11 @@
1304 ** can be removed in the future, once all users have upgraded to the
1305 ** 2014-11-28 or later schema.
1306 */
1307 if( !db_table_has_column("repository","plink","baseid") ){
1308 db_multi_exec(
1309 "ALTER TABLE %s.plink ADD COLUMN baseid;", db_name("repository")
1310 );
1311 }
1312
1313 /* Verify that the MLINK table has the newer columns added by the
1314 ** 2015-01-24 schema change. Create them if necessary. This code
@@ -1316,13 +1340,12 @@
1316 ** 2015-01-24 or later schema.
1317 */
1318 if( !db_table_has_column("repository","mlink","isaux") ){
1319 db_begin_transaction();
1320 db_multi_exec(
1321 "ALTER TABLE %s.mlink ADD COLUMN pmid INTEGER DEFAULT 0;"
1322 "ALTER TABLE %s.mlink ADD COLUMN isaux BOOLEAN DEFAULT 0;",
1323 db_name("repository"), db_name("repository")
1324 );
1325 db_end_transaction(0);
1326 }
1327 }
1328
@@ -1374,22 +1397,10 @@
1374 fossil_fatal("specify the repository name as a command-line argument");
1375 }
1376 }
1377 }
1378
1379 /*
1380 ** Return the name of the database "localdb", "configdb", or "repository".
1381 */
1382 const char *db_name(const char *zDb){
1383 assert( fossil_strcmp(zDb,"localdb")==0
1384 || fossil_strcmp(zDb,"configdb")==0
1385 || fossil_strcmp(zDb,"repository")==0
1386 || fossil_strcmp(zDb,"temp")==0 );
1387 if( fossil_strcmp(zDb, g.zMainDbType)==0 ) zDb = "main";
1388 return zDb;
1389 }
1390
1391 /*
1392 ** Return TRUE if the schema is out-of-date
1393 */
1394 int db_schema_is_outofdate(void){
1395 return strcmp(g.zAuxSchema,AUX_SCHEMA_MIN)<0
@@ -1398,11 +1409,11 @@
1398
1399 /*
1400 ** Return true if the database is writeable
1401 */
1402 int db_is_writeable(const char *zName){
1403 return g.db!=0 && !sqlite3_db_readonly(g.db, db_name(zName));
1404 }
1405
1406 /*
1407 ** Verify that the repository schema is correct. If it is not correct,
1408 ** issue a fatal error and die.
@@ -1443,11 +1454,11 @@
1443 }
1444 if( db_open_local(zRepo)==0 ){
1445 fossil_fatal("not in a local checkout");
1446 return;
1447 }
1448 db_open_or_attach(zRepo, "test_repo", 0);
1449 db_lset("repository", blob_str(&repo));
1450 db_record_repository_filename(blob_str(&repo));
1451 db_close(1);
1452 }
1453
@@ -1503,18 +1514,18 @@
1503 }
1504 db_end_transaction(1);
1505 pStmt = 0;
1506 db_close_config();
1507
1508 /* If the localdb (the check-out database) is open and if it has
1509 ** a lot of unused free space, then VACUUM it as we shut down.
1510 */
1511 if( g.localOpen && strcmp(db_name("localdb"),"main")==0 ){
1512 int nFree = db_int(0, "PRAGMA main.freelist_count");
1513 int nTotal = db_int(0, "PRAGMA main.page_count");
1514 if( nFree>nTotal/4 ){
1515 db_multi_exec("VACUUM;");
1516 }
1517 }
1518
1519 if( g.db ){
1520 int rc;
@@ -1524,18 +1535,15 @@
1524 while( (pStmt = sqlite3_next_stmt(g.db, pStmt))!=0 ){
1525 fossil_warning("unfinalized SQL statement: [%s]", sqlite3_sql(pStmt));
1526 }
1527 }
1528 g.db = 0;
1529 g.zMainDbType = 0;
1530 }
1531 g.repositoryOpen = 0;
1532 g.localOpen = 0;
1533 assert( g.dbConfig==0 );
1534 assert( g.useAttach==0 );
1535 assert( g.zConfigDbName==0 );
1536 assert( g.zConfigDbType==0 );
1537 }
1538
1539
1540 /*
1541 ** Create a new empty repository database with the given name.
@@ -2008,15 +2016,12 @@
2008 ** because the main database connection was already pointing to the config
2009 ** database.
2010 */
2011 if( g.dbConfig ){
2012 sqlite3 *dbTemp = g.db;
2013 const char *zTempDbType = g.zMainDbType;
2014 g.db = g.dbConfig;
2015 g.zMainDbType = g.zConfigDbType;
2016 g.dbConfig = dbTemp;
2017 g.zConfigDbType = zTempDbType;
2018 }
2019 }
2020
2021 /*
2022 ** Try to read a versioned setting string from .fossil-settings/<name>.
@@ -3019,11 +3024,11 @@
3019 int i, j;
3020 Stmt q;
3021 Blob allSql;
3022 int dryRun = find_option("dry-run", "n", 0)!=0;
3023 for(i=2; i<g.argc; i++){
3024 db_open_or_attach(g.argv[i], "main", 0);
3025 blob_init(&allSql, "BEGIN;\n", -1);
3026 db_prepare(&q,
3027 "SELECT name, sql FROM main.sqlite_master "
3028 " WHERE type='table' AND sql NOT LIKE '%%WITHOUT ROWID%%'"
3029 " AND name IN ('global_config','shun','concealed','config',"
@@ -3074,17 +3079,17 @@
3074 void create_admin_log_table(void){
3075 static int once = 0;
3076 if( once ) return;
3077 once = 1;
3078 db_multi_exec(
3079 "CREATE TABLE IF NOT EXISTS \"%w\".admin_log(\n"
3080 " id INTEGER PRIMARY KEY,\n"
3081 " time INTEGER, -- Seconds since 1970\n"
3082 " page TEXT, -- path of page\n"
3083 " who TEXT, -- User who made the change\n "
3084 " what TEXT -- What changed\n"
3085 ")", db_name("repository")
3086 );
3087 }
3088
3089 /*
3090 ** Write a message into the admin_event table, if admin logging is
3091
--- src/db.c
+++ src/db.c
@@ -961,52 +961,79 @@
961 db_encryption_key(zDbName, &key);
962 db_multi_exec("ATTACH DATABASE %Q AS %Q KEY %Q",
963 zDbName, zLabel, blob_str(&key));
964 blob_reset(&key);
965 }
966
967 /*
968 ** Change the schema name of the "main" database to zLabel.
969 ** zLabel must be a static string that is unchanged for the life of
970 ** the database connection.
971 **
972 ** After calling this routine, db_database_slot(zLabel) should
973 ** return 0.
974 */
975 void db_set_main_schemaname(sqlite3 *db, const char *zLabel){
976 if( sqlite3_db_config(db, SQLITE_DBCONFIG_MAINDBNAME, zLabel) ){
977 fossil_fatal("Fossil requires a version of SQLite that supports the "
978 "SQLITE_DBCONFIG_MAINDBNAME interface.");
979 }
980 }
981
982 /*
983 ** Return the slot number for database zLabel. The first database
984 ** opened is slot 0. The "temp" database is slot 1. Attached databases
985 ** are slots 2 and higher.
986 **
987 ** Return -1 if zLabel does not match any open database.
988 */
989 int db_database_slot(const char *zLabel){
990 int iSlot = -1;
991 Stmt q;
992 if( g.db==0 ) return iSlot;
993 db_prepare(&q, "PRAGMA database_list");
994 while( db_step(&q)==SQLITE_ROW ){
995 if( fossil_strcmp(db_column_text(&q,1),zLabel)==0 ){
996 iSlot = db_column_int(&q, 0);
997 break;
998 }
999 }
1000 db_finalize(&q);
1001 return iSlot;
1002 }
1003
1004 /*
1005 ** zDbName is the name of a database file. If no other database
1006 ** file is open, then open this one. If another database file is
1007 ** already open, then attach zDbName using the name zLabel.
1008 */
1009 void db_open_or_attach(const char *zDbName, const char *zLabel){
 
 
 
 
1010 if( !g.db ){
 
1011 g.db = db_open(zDbName);
1012 db_set_main_schemaname(g.db, zLabel);
 
1013 }else{
 
1014 db_attach(zDbName, zLabel);
 
1015 }
1016 }
1017
1018 /*
1019 ** Close the per-user database file in ~/.fossil
1020 */
1021 void db_close_config(){
1022 int iSlot = db_database_slot("configdb");
1023 if( iSlot>0 ){
1024 db_detach("configdb");
 
1025 g.zConfigDbName = 0;
1026 }else if( g.dbConfig ){
1027 sqlite3_wal_checkpoint(g.dbConfig, 0);
1028 sqlite3_close(g.dbConfig);
1029 g.dbConfig = 0;
 
1030 g.zConfigDbName = 0;
1031 }else if( g.db && 0==iSlot ){
1032 sqlite3_wal_checkpoint(g.db, 0);
1033 sqlite3_close(g.db);
1034 g.db = 0;
 
1035 g.zConfigDbName = 0;
1036 }
1037 }
1038
1039 /*
@@ -1023,11 +1050,12 @@
1050 */
1051 int db_open_config(int useAttach, int isOptional){
1052 char *zDbName;
1053 char *zHome;
1054 if( g.zConfigDbName ){
1055 int alreadyAttached = db_database_slot("configdb")>0;
1056 if( useAttach==alreadyAttached ) return 1; /* Already open. */
1057 db_close_config();
1058 }
1059 zHome = fossil_getenv("FOSSIL_HOME");
1060 #if defined(_WIN32) || defined(__CYGWIN__)
1061 if( zHome==0 ){
@@ -1077,17 +1105,15 @@
1105 if( file_access(zDbName, W_OK) ){
1106 if( isOptional ) return 0;
1107 fossil_fatal("configuration file %s must be writeable", zDbName);
1108 }
1109 if( useAttach ){
1110 db_open_or_attach(zDbName, "configdb");
1111 g.dbConfig = 0;
 
1112 }else{
 
1113 g.dbConfig = db_open(zDbName);
1114 db_set_main_schemaname(g.dbConfig, "configdb");
1115 }
1116 g.zConfigDbName = zDbName;
1117 return 1;
1118 }
1119
@@ -1096,13 +1122,12 @@
1122 */
1123 int db_table_exists(
1124 const char *zDb, /* One of: NULL, "configdb", "localdb", "repository" */
1125 const char *zTable /* Name of table */
1126 ){
1127 return sqlite3_table_column_metadata(g.db, zDb, zTable, 0,
1128 0, 0, 0, 0, 0)==SQLITE_OK;
 
1129 }
1130
1131 /*
1132 ** Return TRUE if zTable exists and contains column zColumn.
1133 ** Return FALSE if zTable does not exist or if zTable exists
@@ -1111,13 +1136,12 @@
1136 int db_table_has_column(
1137 const char *zDb, /* One of: NULL, "config", "localdb", "repository" */
1138 const char *zTable, /* Name of table */
1139 const char *zColumn /* Name of column in table */
1140 ){
1141 return sqlite3_table_column_metadata(g.db, zDb, zTable, zColumn,
1142 0, 0, 0, 0, 0)==SQLITE_OK;
 
1143 }
1144
1145 /*
1146 ** Returns TRUE if zTable exists in the local database but lacks column
1147 ** zColumn
@@ -1124,12 +1148,12 @@
1148 */
1149 static int db_local_table_exists_but_lacks_column(
1150 const char *zTable,
1151 const char *zColumn
1152 ){
1153 return db_table_exists("localdb", zTable)
1154 && !db_table_has_column("localdb", zTable, zColumn);
1155 }
1156
1157 /*
1158 ** If zDbName is a valid local database file, open it and return
1159 ** true. If it is not a valid local database file, return 0.
@@ -1139,13 +1163,13 @@
1163 char *zVFileDef;
1164
1165 if( file_access(zDbName, F_OK) ) return 0;
1166 lsize = file_size(zDbName);
1167 if( lsize%1024!=0 || lsize<4096 ) return 0;
1168 db_open_or_attach(zDbName, "localdb");
1169 zVFileDef = db_text(0, "SELECT sql FROM localdb.sqlite_master"
1170 " WHERE name=='vfile'");
1171 if( zVFileDef==0 ) return 0;
1172
1173 /* If the "isexe" column is missing from the vfile table, then
1174 ** add it now. This code added on 2010-03-06. After all users have
1175 ** upgraded, this code can be safely deleted.
@@ -1290,11 +1314,11 @@
1314 #endif
1315 fossil_panic("not a valid repository: %s", zDbName);
1316 }
1317 }
1318 g.zRepositoryName = mprintf("%s", zDbName);
1319 db_open_or_attach(g.zRepositoryName, "repository");
1320 g.repositoryOpen = 1;
1321 /* Cache "allow-symlinks" option, because we'll need it on every stat call */
1322 g.allowSymlinks = db_get_boolean("allow-symlinks",
1323 db_allow_symlinks_by_default());
1324 g.zAuxSchema = db_get("aux-schema","");
@@ -1304,11 +1328,11 @@
1328 ** can be removed in the future, once all users have upgraded to the
1329 ** 2014-11-28 or later schema.
1330 */
1331 if( !db_table_has_column("repository","plink","baseid") ){
1332 db_multi_exec(
1333 "ALTER TABLE repository.plink ADD COLUMN baseid;"
1334 );
1335 }
1336
1337 /* Verify that the MLINK table has the newer columns added by the
1338 ** 2015-01-24 schema change. Create them if necessary. This code
@@ -1316,13 +1340,12 @@
1340 ** 2015-01-24 or later schema.
1341 */
1342 if( !db_table_has_column("repository","mlink","isaux") ){
1343 db_begin_transaction();
1344 db_multi_exec(
1345 "ALTER TABLE repository.mlink ADD COLUMN pmid INTEGER DEFAULT 0;"
1346 "ALTER TABLE repository.mlink ADD COLUMN isaux BOOLEAN DEFAULT 0;"
 
1347 );
1348 db_end_transaction(0);
1349 }
1350 }
1351
@@ -1374,22 +1397,10 @@
1397 fossil_fatal("specify the repository name as a command-line argument");
1398 }
1399 }
1400 }
1401
 
 
 
 
 
 
 
 
 
 
 
 
1402 /*
1403 ** Return TRUE if the schema is out-of-date
1404 */
1405 int db_schema_is_outofdate(void){
1406 return strcmp(g.zAuxSchema,AUX_SCHEMA_MIN)<0
@@ -1398,11 +1409,11 @@
1409
1410 /*
1411 ** Return true if the database is writeable
1412 */
1413 int db_is_writeable(const char *zName){
1414 return g.db!=0 && !sqlite3_db_readonly(g.db, zName);
1415 }
1416
1417 /*
1418 ** Verify that the repository schema is correct. If it is not correct,
1419 ** issue a fatal error and die.
@@ -1443,11 +1454,11 @@
1454 }
1455 if( db_open_local(zRepo)==0 ){
1456 fossil_fatal("not in a local checkout");
1457 return;
1458 }
1459 db_open_or_attach(zRepo, "test_repo");
1460 db_lset("repository", blob_str(&repo));
1461 db_record_repository_filename(blob_str(&repo));
1462 db_close(1);
1463 }
1464
@@ -1503,18 +1514,18 @@
1514 }
1515 db_end_transaction(1);
1516 pStmt = 0;
1517 db_close_config();
1518
1519 /* If the localdb has a lot of unused free space,
1520 ** then VACUUM it as we shut down.
1521 */
1522 if( db_database_slot("localdb")>=0 ){
1523 int nFree = db_int(0, "PRAGMA localdb.freelist_count");
1524 int nTotal = db_int(0, "PRAGMA localdb.page_count");
1525 if( nFree>nTotal/4 ){
1526 db_multi_exec("VACUUM localdb;");
1527 }
1528 }
1529
1530 if( g.db ){
1531 int rc;
@@ -1524,18 +1535,15 @@
1535 while( (pStmt = sqlite3_next_stmt(g.db, pStmt))!=0 ){
1536 fossil_warning("unfinalized SQL statement: [%s]", sqlite3_sql(pStmt));
1537 }
1538 }
1539 g.db = 0;
 
1540 }
1541 g.repositoryOpen = 0;
1542 g.localOpen = 0;
1543 assert( g.dbConfig==0 );
 
1544 assert( g.zConfigDbName==0 );
 
1545 }
1546
1547
1548 /*
1549 ** Create a new empty repository database with the given name.
@@ -2008,15 +2016,12 @@
2016 ** because the main database connection was already pointing to the config
2017 ** database.
2018 */
2019 if( g.dbConfig ){
2020 sqlite3 *dbTemp = g.db;
 
2021 g.db = g.dbConfig;
 
2022 g.dbConfig = dbTemp;
 
2023 }
2024 }
2025
2026 /*
2027 ** Try to read a versioned setting string from .fossil-settings/<name>.
@@ -3019,11 +3024,11 @@
3024 int i, j;
3025 Stmt q;
3026 Blob allSql;
3027 int dryRun = find_option("dry-run", "n", 0)!=0;
3028 for(i=2; i<g.argc; i++){
3029 db_open_or_attach(g.argv[i], "main");
3030 blob_init(&allSql, "BEGIN;\n", -1);
3031 db_prepare(&q,
3032 "SELECT name, sql FROM main.sqlite_master "
3033 " WHERE type='table' AND sql NOT LIKE '%%WITHOUT ROWID%%'"
3034 " AND name IN ('global_config','shun','concealed','config',"
@@ -3074,17 +3079,17 @@
3079 void create_admin_log_table(void){
3080 static int once = 0;
3081 if( once ) return;
3082 once = 1;
3083 db_multi_exec(
3084 "CREATE TABLE IF NOT EXISTS repository.admin_log(\n"
3085 " id INTEGER PRIMARY KEY,\n"
3086 " time INTEGER, -- Seconds since 1970\n"
3087 " page TEXT, -- path of page\n"
3088 " who TEXT, -- User who made the change\n "
3089 " what TEXT -- What changed\n"
3090 ")"
3091 );
3092 }
3093
3094 /*
3095 ** Write a message into the admin_event table, if admin logging is
3096
+1 -1
--- src/file.c
+++ src/file.c
@@ -521,11 +521,11 @@
521521
char *zDate;
522522
i64 iMTime;
523523
if( g.argc!=4 ){
524524
usage("FILENAME DATE/TIME");
525525
}
526
- db_open_or_attach(":memory:", "mem", 0);
526
+ db_open_or_attach(":memory:", "mem");
527527
iMTime = db_int64(0, "SELECT strftime('%%s',%Q)", g.argv[3]);
528528
zFile = g.argv[2];
529529
file_set_mtime(zFile, iMTime);
530530
iMTime = file_wd_mtime(zFile);
531531
zDate = db_text(0, "SELECT datetime(%lld, 'unixepoch')", iMTime);
532532
--- src/file.c
+++ src/file.c
@@ -521,11 +521,11 @@
521 char *zDate;
522 i64 iMTime;
523 if( g.argc!=4 ){
524 usage("FILENAME DATE/TIME");
525 }
526 db_open_or_attach(":memory:", "mem", 0);
527 iMTime = db_int64(0, "SELECT strftime('%%s',%Q)", g.argv[3]);
528 zFile = g.argv[2];
529 file_set_mtime(zFile, iMTime);
530 iMTime = file_wd_mtime(zFile);
531 zDate = db_text(0, "SELECT datetime(%lld, 'unixepoch')", iMTime);
532
--- src/file.c
+++ src/file.c
@@ -521,11 +521,11 @@
521 char *zDate;
522 i64 iMTime;
523 if( g.argc!=4 ){
524 usage("FILENAME DATE/TIME");
525 }
526 db_open_or_attach(":memory:", "mem");
527 iMTime = db_int64(0, "SELECT strftime('%%s',%Q)", g.argv[3]);
528 zFile = g.argv[2];
529 file_set_mtime(zFile, iMTime);
530 iMTime = file_wd_mtime(zFile);
531 zDate = db_text(0, "SELECT datetime(%lld, 'unixepoch')", iMTime);
532
+5 -10
--- src/json.c
+++ src/json.c
@@ -1259,11 +1259,10 @@
12591259
#define CSTR(OBJ,K) cson_object_set(o, #K, OBJ.K ? json_new_string(OBJ.K) : cson_value_null())
12601260
#define VAL(K,V) cson_object_set(o, #K, (V) ? (V) : cson_value_null())
12611261
VAL(capabilities, json_cap_value());
12621262
INT(g, argc);
12631263
INT(g, isConst);
1264
- INT(g, useAttach);
12651264
CSTR(g, zConfigDbName);
12661265
INT(g, repositoryOpen);
12671266
INT(g, localOpen);
12681267
INT(g, minPrefix);
12691268
INT(g, fSqlTrace);
@@ -1296,12 +1295,10 @@
12961295
INT(g, thTrace);
12971296
INT(g, isHome);
12981297
INT(g, nAux);
12991298
INT(g, allowSymlinks);
13001299
1301
- CSTR(g, zMainDbType);
1302
- CSTR(g, zConfigDbType);
13031300
CSTR(g, zOpenRevision);
13041301
CSTR(g, zLocalRoot);
13051302
CSTR(g, zPath);
13061303
CSTR(g, zExtra);
13071304
CSTR(g, zBaseURL);
@@ -1905,11 +1902,10 @@
19051902
*/
19061903
cson_value * json_page_stat(){
19071904
i64 t, fsize;
19081905
int n, m;
19091906
int full;
1910
- const char *zDb;
19111907
enum { BufLen = 1000 };
19121908
char zBuf[BufLen];
19131909
cson_value * jv = NULL;
19141910
cson_object * jo = NULL;
19151911
cson_value * jv2 = NULL;
@@ -1989,17 +1985,16 @@
19891985
jo2 = cson_value_get_object(jv2);
19901986
cson_object_set(jo, "sqlite", jv2);
19911987
sqlite3_snprintf(BufLen, zBuf, "%.19s [%.10s] (%s)",
19921988
sqlite3_sourceid(), &sqlite3_sourceid()[20], sqlite3_libversion());
19931989
SETBUF(jo2, "version");
1994
- zDb = db_name("repository");
1995
- cson_object_set(jo2, "pageCount", cson_value_new_integer((cson_int_t)db_int(0, "PRAGMA \"%w\".page_count", zDb)));
1996
- cson_object_set(jo2, "pageSize", cson_value_new_integer((cson_int_t)db_int(0, "PRAGMA \"%w\".page_size", zDb)));
1997
- cson_object_set(jo2, "freeList", cson_value_new_integer((cson_int_t)db_int(0, "PRAGMA \"%w\".freelist_count", zDb)));
1998
- sqlite3_snprintf(BufLen, zBuf, "%s", db_text(0, "PRAGMA \"%w\".encoding", zDb));
1990
+ cson_object_set(jo2, "pageCount", cson_value_new_integer((cson_int_t)db_int(0, "PRAGMA repository.page_count")));
1991
+ cson_object_set(jo2, "pageSize", cson_value_new_integer((cson_int_t)db_int(0, "PRAGMA repository.page_size")));
1992
+ cson_object_set(jo2, "freeList", cson_value_new_integer((cson_int_t)db_int(0, "PRAGMA repository.freelist_count")));
1993
+ sqlite3_snprintf(BufLen, zBuf, "%s", db_text(0, "PRAGMA repository.encoding"));
19991994
SETBUF(jo2, "encoding");
2000
- sqlite3_snprintf(BufLen, zBuf, "%s", db_text(0, "PRAGMA \"%w\".journal_mode", zDb));
1995
+ sqlite3_snprintf(BufLen, zBuf, "%s", db_text(0, "PRAGMA repository.journal_mode"));
20011996
cson_object_set(jo2, "journalMode", *zBuf ? cson_value_new_string(zBuf, strlen(zBuf)) : cson_value_null());
20021997
return jv;
20031998
#undef SETBUF
20041999
}
20052000
20062001
--- src/json.c
+++ src/json.c
@@ -1259,11 +1259,10 @@
1259 #define CSTR(OBJ,K) cson_object_set(o, #K, OBJ.K ? json_new_string(OBJ.K) : cson_value_null())
1260 #define VAL(K,V) cson_object_set(o, #K, (V) ? (V) : cson_value_null())
1261 VAL(capabilities, json_cap_value());
1262 INT(g, argc);
1263 INT(g, isConst);
1264 INT(g, useAttach);
1265 CSTR(g, zConfigDbName);
1266 INT(g, repositoryOpen);
1267 INT(g, localOpen);
1268 INT(g, minPrefix);
1269 INT(g, fSqlTrace);
@@ -1296,12 +1295,10 @@
1296 INT(g, thTrace);
1297 INT(g, isHome);
1298 INT(g, nAux);
1299 INT(g, allowSymlinks);
1300
1301 CSTR(g, zMainDbType);
1302 CSTR(g, zConfigDbType);
1303 CSTR(g, zOpenRevision);
1304 CSTR(g, zLocalRoot);
1305 CSTR(g, zPath);
1306 CSTR(g, zExtra);
1307 CSTR(g, zBaseURL);
@@ -1905,11 +1902,10 @@
1905 */
1906 cson_value * json_page_stat(){
1907 i64 t, fsize;
1908 int n, m;
1909 int full;
1910 const char *zDb;
1911 enum { BufLen = 1000 };
1912 char zBuf[BufLen];
1913 cson_value * jv = NULL;
1914 cson_object * jo = NULL;
1915 cson_value * jv2 = NULL;
@@ -1989,17 +1985,16 @@
1989 jo2 = cson_value_get_object(jv2);
1990 cson_object_set(jo, "sqlite", jv2);
1991 sqlite3_snprintf(BufLen, zBuf, "%.19s [%.10s] (%s)",
1992 sqlite3_sourceid(), &sqlite3_sourceid()[20], sqlite3_libversion());
1993 SETBUF(jo2, "version");
1994 zDb = db_name("repository");
1995 cson_object_set(jo2, "pageCount", cson_value_new_integer((cson_int_t)db_int(0, "PRAGMA \"%w\".page_count", zDb)));
1996 cson_object_set(jo2, "pageSize", cson_value_new_integer((cson_int_t)db_int(0, "PRAGMA \"%w\".page_size", zDb)));
1997 cson_object_set(jo2, "freeList", cson_value_new_integer((cson_int_t)db_int(0, "PRAGMA \"%w\".freelist_count", zDb)));
1998 sqlite3_snprintf(BufLen, zBuf, "%s", db_text(0, "PRAGMA \"%w\".encoding", zDb));
1999 SETBUF(jo2, "encoding");
2000 sqlite3_snprintf(BufLen, zBuf, "%s", db_text(0, "PRAGMA \"%w\".journal_mode", zDb));
2001 cson_object_set(jo2, "journalMode", *zBuf ? cson_value_new_string(zBuf, strlen(zBuf)) : cson_value_null());
2002 return jv;
2003 #undef SETBUF
2004 }
2005
2006
--- src/json.c
+++ src/json.c
@@ -1259,11 +1259,10 @@
1259 #define CSTR(OBJ,K) cson_object_set(o, #K, OBJ.K ? json_new_string(OBJ.K) : cson_value_null())
1260 #define VAL(K,V) cson_object_set(o, #K, (V) ? (V) : cson_value_null())
1261 VAL(capabilities, json_cap_value());
1262 INT(g, argc);
1263 INT(g, isConst);
 
1264 CSTR(g, zConfigDbName);
1265 INT(g, repositoryOpen);
1266 INT(g, localOpen);
1267 INT(g, minPrefix);
1268 INT(g, fSqlTrace);
@@ -1296,12 +1295,10 @@
1295 INT(g, thTrace);
1296 INT(g, isHome);
1297 INT(g, nAux);
1298 INT(g, allowSymlinks);
1299
 
 
1300 CSTR(g, zOpenRevision);
1301 CSTR(g, zLocalRoot);
1302 CSTR(g, zPath);
1303 CSTR(g, zExtra);
1304 CSTR(g, zBaseURL);
@@ -1905,11 +1902,10 @@
1902 */
1903 cson_value * json_page_stat(){
1904 i64 t, fsize;
1905 int n, m;
1906 int full;
 
1907 enum { BufLen = 1000 };
1908 char zBuf[BufLen];
1909 cson_value * jv = NULL;
1910 cson_object * jo = NULL;
1911 cson_value * jv2 = NULL;
@@ -1989,17 +1985,16 @@
1985 jo2 = cson_value_get_object(jv2);
1986 cson_object_set(jo, "sqlite", jv2);
1987 sqlite3_snprintf(BufLen, zBuf, "%.19s [%.10s] (%s)",
1988 sqlite3_sourceid(), &sqlite3_sourceid()[20], sqlite3_libversion());
1989 SETBUF(jo2, "version");
1990 cson_object_set(jo2, "pageCount", cson_value_new_integer((cson_int_t)db_int(0, "PRAGMA repository.page_count")));
1991 cson_object_set(jo2, "pageSize", cson_value_new_integer((cson_int_t)db_int(0, "PRAGMA repository.page_size")));
1992 cson_object_set(jo2, "freeList", cson_value_new_integer((cson_int_t)db_int(0, "PRAGMA repository.freelist_count")));
1993 sqlite3_snprintf(BufLen, zBuf, "%s", db_text(0, "PRAGMA repository.encoding"));
 
1994 SETBUF(jo2, "encoding");
1995 sqlite3_snprintf(BufLen, zBuf, "%s", db_text(0, "PRAGMA repository.journal_mode"));
1996 cson_object_set(jo2, "journalMode", *zBuf ? cson_value_new_string(zBuf, strlen(zBuf)) : cson_value_null());
1997 return jv;
1998 #undef SETBUF
1999 }
2000
2001
+3 -3
--- src/login.c
+++ src/login.c
@@ -174,16 +174,16 @@
174174
/*
175175
** Make sure the accesslog table exists. Create it if it does not
176176
*/
177177
void create_accesslog_table(void){
178178
db_multi_exec(
179
- "CREATE TABLE IF NOT EXISTS %s.accesslog("
179
+ "CREATE TABLE IF NOT EXISTS repository.accesslog("
180180
" uname TEXT,"
181181
" ipaddr TEXT,"
182182
" success BOOLEAN,"
183183
" mtime TIMESTAMP"
184
- ");", db_name("repository")
184
+ ");"
185185
);
186186
}
187187
188188
/*
189189
** Make a record of a login attempt, if login record keeping is enabled.
@@ -1566,11 +1566,11 @@
15661566
char *zSelfProjCode; /* Our project-code */
15671567
char *zSql; /* SQL to run on all peers */
15681568
const char *zSelf; /* The ATTACH name of our repository */
15691569
15701570
*pzErrMsg = 0; /* Default to no errors */
1571
- zSelf = db_name("repository");
1571
+ zSelf = "repository";
15721572
15731573
/* Get the full pathname of the other repository */
15741574
file_canonical_name(zRepo, &fullName, 0);
15751575
zRepo = fossil_strdup(blob_str(&fullName));
15761576
blob_reset(&fullName);
15771577
--- src/login.c
+++ src/login.c
@@ -174,16 +174,16 @@
174 /*
175 ** Make sure the accesslog table exists. Create it if it does not
176 */
177 void create_accesslog_table(void){
178 db_multi_exec(
179 "CREATE TABLE IF NOT EXISTS %s.accesslog("
180 " uname TEXT,"
181 " ipaddr TEXT,"
182 " success BOOLEAN,"
183 " mtime TIMESTAMP"
184 ");", db_name("repository")
185 );
186 }
187
188 /*
189 ** Make a record of a login attempt, if login record keeping is enabled.
@@ -1566,11 +1566,11 @@
1566 char *zSelfProjCode; /* Our project-code */
1567 char *zSql; /* SQL to run on all peers */
1568 const char *zSelf; /* The ATTACH name of our repository */
1569
1570 *pzErrMsg = 0; /* Default to no errors */
1571 zSelf = db_name("repository");
1572
1573 /* Get the full pathname of the other repository */
1574 file_canonical_name(zRepo, &fullName, 0);
1575 zRepo = fossil_strdup(blob_str(&fullName));
1576 blob_reset(&fullName);
1577
--- src/login.c
+++ src/login.c
@@ -174,16 +174,16 @@
174 /*
175 ** Make sure the accesslog table exists. Create it if it does not
176 */
177 void create_accesslog_table(void){
178 db_multi_exec(
179 "CREATE TABLE IF NOT EXISTS repository.accesslog("
180 " uname TEXT,"
181 " ipaddr TEXT,"
182 " success BOOLEAN,"
183 " mtime TIMESTAMP"
184 ");"
185 );
186 }
187
188 /*
189 ** Make a record of a login attempt, if login record keeping is enabled.
@@ -1566,11 +1566,11 @@
1566 char *zSelfProjCode; /* Our project-code */
1567 char *zSql; /* SQL to run on all peers */
1568 const char *zSelf; /* The ATTACH name of our repository */
1569
1570 *pzErrMsg = 0; /* Default to no errors */
1571 zSelf = "repository";
1572
1573 /* Get the full pathname of the other repository */
1574 file_canonical_name(zRepo, &fullName, 0);
1575 zRepo = fossil_strdup(blob_str(&fullName));
1576 blob_reset(&fullName);
1577
+2 -5
--- src/main.c
+++ src/main.c
@@ -128,20 +128,17 @@
128128
int isConst; /* True if the output is unchanging & cacheable */
129129
const char *zVfsName; /* The VFS to use for database connections */
130130
sqlite3 *db; /* The connection to the databases */
131131
sqlite3 *dbConfig; /* Separate connection for global_config table */
132132
char *zAuxSchema; /* Main repository aux-schema */
133
- int useAttach; /* True if global_config is attached to repository */
134133
int dbIgnoreErrors; /* Ignore database errors if true */
135134
const char *zConfigDbName;/* Path of the config database. NULL if not open */
136135
sqlite3_int64 now; /* Seconds since 1970 */
137136
int repositoryOpen; /* True if the main repository database is open */
138137
char *zRepositoryOption; /* Most recent cached repository option value */
139
- char *zRepositoryName; /* Name of the repository database */
140
- char *zLocalDbName; /* Name of the local database */
141
- const char *zMainDbType;/* "configdb", "localdb", or "repository" */
142
- const char *zConfigDbType; /* "configdb", "localdb", or "repository" */
138
+ char *zRepositoryName; /* Name of the repository database file */
139
+ char *zLocalDbName; /* Name of the local database file */
143140
char *zOpenRevision; /* Check-in version to use during database open */
144141
int localOpen; /* True if the local database is open */
145142
char *zLocalRoot; /* The directory holding the local database */
146143
int minPrefix; /* Number of digits needed for a distinct UUID */
147144
int fSqlTrace; /* True if --sqltrace flag is present */
148145
--- src/main.c
+++ src/main.c
@@ -128,20 +128,17 @@
128 int isConst; /* True if the output is unchanging & cacheable */
129 const char *zVfsName; /* The VFS to use for database connections */
130 sqlite3 *db; /* The connection to the databases */
131 sqlite3 *dbConfig; /* Separate connection for global_config table */
132 char *zAuxSchema; /* Main repository aux-schema */
133 int useAttach; /* True if global_config is attached to repository */
134 int dbIgnoreErrors; /* Ignore database errors if true */
135 const char *zConfigDbName;/* Path of the config database. NULL if not open */
136 sqlite3_int64 now; /* Seconds since 1970 */
137 int repositoryOpen; /* True if the main repository database is open */
138 char *zRepositoryOption; /* Most recent cached repository option value */
139 char *zRepositoryName; /* Name of the repository database */
140 char *zLocalDbName; /* Name of the local database */
141 const char *zMainDbType;/* "configdb", "localdb", or "repository" */
142 const char *zConfigDbType; /* "configdb", "localdb", or "repository" */
143 char *zOpenRevision; /* Check-in version to use during database open */
144 int localOpen; /* True if the local database is open */
145 char *zLocalRoot; /* The directory holding the local database */
146 int minPrefix; /* Number of digits needed for a distinct UUID */
147 int fSqlTrace; /* True if --sqltrace flag is present */
148
--- src/main.c
+++ src/main.c
@@ -128,20 +128,17 @@
128 int isConst; /* True if the output is unchanging & cacheable */
129 const char *zVfsName; /* The VFS to use for database connections */
130 sqlite3 *db; /* The connection to the databases */
131 sqlite3 *dbConfig; /* Separate connection for global_config table */
132 char *zAuxSchema; /* Main repository aux-schema */
 
133 int dbIgnoreErrors; /* Ignore database errors if true */
134 const char *zConfigDbName;/* Path of the config database. NULL if not open */
135 sqlite3_int64 now; /* Seconds since 1970 */
136 int repositoryOpen; /* True if the main repository database is open */
137 char *zRepositoryOption; /* Most recent cached repository option value */
138 char *zRepositoryName; /* Name of the repository database file */
139 char *zLocalDbName; /* Name of the local database file */
 
 
140 char *zOpenRevision; /* Check-in version to use during database open */
141 int localOpen; /* True if the local database is open */
142 char *zLocalRoot; /* The directory holding the local database */
143 int minPrefix; /* Number of digits needed for a distinct UUID */
144 int fSqlTrace; /* True if --sqltrace flag is present */
145
+2 -2
--- src/moderate.c
+++ src/moderate.c
@@ -26,15 +26,15 @@
2626
** Create a table to represent pending moderation requests, if the
2727
** table does not already exist.
2828
*/
2929
void moderation_table_create(void){
3030
db_multi_exec(
31
- "CREATE TABLE IF NOT EXISTS %s.modreq(\n"
31
+ "CREATE TABLE IF NOT EXISTS repository.modreq(\n"
3232
" objid INTEGER PRIMARY KEY,\n" /* Record pending approval */
3333
" attachRid INT,\n" /* Object attached */
3434
" tktid TEXT\n" /* Associated ticket id */
35
- ");\n", db_name("repository")
35
+ ");\n"
3636
);
3737
}
3838
3939
/*
4040
** Return TRUE if the modreq table exists
4141
--- src/moderate.c
+++ src/moderate.c
@@ -26,15 +26,15 @@
26 ** Create a table to represent pending moderation requests, if the
27 ** table does not already exist.
28 */
29 void moderation_table_create(void){
30 db_multi_exec(
31 "CREATE TABLE IF NOT EXISTS %s.modreq(\n"
32 " objid INTEGER PRIMARY KEY,\n" /* Record pending approval */
33 " attachRid INT,\n" /* Object attached */
34 " tktid TEXT\n" /* Associated ticket id */
35 ");\n", db_name("repository")
36 );
37 }
38
39 /*
40 ** Return TRUE if the modreq table exists
41
--- src/moderate.c
+++ src/moderate.c
@@ -26,15 +26,15 @@
26 ** Create a table to represent pending moderation requests, if the
27 ** table does not already exist.
28 */
29 void moderation_table_create(void){
30 db_multi_exec(
31 "CREATE TABLE IF NOT EXISTS repository.modreq(\n"
32 " objid INTEGER PRIMARY KEY,\n" /* Record pending approval */
33 " attachRid INT,\n" /* Object attached */
34 " tktid TEXT\n" /* Associated ticket id */
35 ");\n"
36 );
37 }
38
39 /*
40 ** Return TRUE if the modreq table exists
41
+1 -1
--- src/purge.c
+++ src/purge.c
@@ -142,11 +142,11 @@
142142
143143
/* Construct the graveyard and copy the artifacts to be purged into the
144144
** graveyard */
145145
if( purgeFlags & PURGE_MOVETO_GRAVEYARD ){
146146
db_multi_exec(zPurgeInit /*works-like:"%w%w"*/,
147
- db_name("repository"), db_name("repository"));
147
+ "repository", "repository");
148148
db_multi_exec(
149149
"INSERT INTO purgeevent(ctime,pnotes) VALUES(now(),%Q)", zNote
150150
);
151151
peid = db_last_insert_rowid();
152152
db_prepare(&q, "SELECT rid FROM delta WHERE rid IN \"%w\""
153153
--- src/purge.c
+++ src/purge.c
@@ -142,11 +142,11 @@
142
143 /* Construct the graveyard and copy the artifacts to be purged into the
144 ** graveyard */
145 if( purgeFlags & PURGE_MOVETO_GRAVEYARD ){
146 db_multi_exec(zPurgeInit /*works-like:"%w%w"*/,
147 db_name("repository"), db_name("repository"));
148 db_multi_exec(
149 "INSERT INTO purgeevent(ctime,pnotes) VALUES(now(),%Q)", zNote
150 );
151 peid = db_last_insert_rowid();
152 db_prepare(&q, "SELECT rid FROM delta WHERE rid IN \"%w\""
153
--- src/purge.c
+++ src/purge.c
@@ -142,11 +142,11 @@
142
143 /* Construct the graveyard and copy the artifacts to be purged into the
144 ** graveyard */
145 if( purgeFlags & PURGE_MOVETO_GRAVEYARD ){
146 db_multi_exec(zPurgeInit /*works-like:"%w%w"*/,
147 "repository", "repository");
148 db_multi_exec(
149 "INSERT INTO purgeevent(ctime,pnotes) VALUES(now(),%Q)", zNote
150 );
151 peid = db_last_insert_rowid();
152 db_prepare(&q, "SELECT rid FROM delta WHERE rid IN \"%w\""
153
+10 -13
--- src/search.c
+++ src/search.c
@@ -1343,11 +1343,11 @@
13431343
13441344
/* The schema for the full-text index
13451345
*/
13461346
static const char zFtsSchema[] =
13471347
@ -- One entry for each possible search result
1348
-@ CREATE TABLE IF NOT EXISTS "%w".ftsdocs(
1348
+@ CREATE TABLE IF NOT EXISTS repository.ftsdocs(
13491349
@ rowid INTEGER PRIMARY KEY, -- Maps to the ftsidx.docid
13501350
@ type CHAR(1), -- Type of document
13511351
@ rid INTEGER, -- BLOB.RID or TAG.TAGID for the document
13521352
@ name TEXT, -- Additional document description
13531353
@ idxed BOOLEAN, -- True if currently in the index
@@ -1355,41 +1355,38 @@
13551355
@ url TEXT, -- URL to access this document
13561356
@ mtime DATE, -- Date when document created
13571357
@ bx TEXT, -- Temporary "body" content cache
13581358
@ UNIQUE(type,rid)
13591359
@ );
1360
-@ CREATE INDEX "%w".ftsdocIdxed ON ftsdocs(type,rid,name) WHERE idxed==0;
1361
-@ CREATE INDEX "%w".ftsdocName ON ftsdocs(name) WHERE type='w';
1362
-@ CREATE VIEW IF NOT EXISTS "%w".ftscontent AS
1360
+@ CREATE INDEX repository.ftsdocIdxed ON ftsdocs(type,rid,name) WHERE idxed==0;
1361
+@ CREATE INDEX repository.ftsdocName ON ftsdocs(name) WHERE type='w';
1362
+@ CREATE VIEW IF NOT EXISTS repository.ftscontent AS
13631363
@ SELECT rowid, type, rid, name, idxed, label, url, mtime,
13641364
@ title(type,rid,name) AS 'title', body(type,rid,name) AS 'body'
13651365
@ FROM ftsdocs;
1366
-@ CREATE VIRTUAL TABLE IF NOT EXISTS "%w".ftsidx
1366
+@ CREATE VIRTUAL TABLE IF NOT EXISTS repository.ftsidx
13671367
@ USING fts4(content="ftscontent", title, body%s);
13681368
;
13691369
static const char zFtsDrop[] =
1370
-@ DROP TABLE IF EXISTS "%w".ftsidx;
1371
-@ DROP VIEW IF EXISTS "%w".ftscontent;
1372
-@ DROP TABLE IF EXISTS "%w".ftsdocs;
1370
+@ DROP TABLE IF EXISTS repository.ftsidx;
1371
+@ DROP VIEW IF EXISTS repository.ftscontent;
1372
+@ DROP TABLE IF EXISTS repository.ftsdocs;
13731373
;
13741374
13751375
/*
13761376
** Create or drop the tables associated with a full-text index.
13771377
*/
13781378
static int searchIdxExists = -1;
13791379
void search_create_index(void){
1380
- const char *zDb = db_name("repository");
13811380
int useStemmer = db_get_boolean("search-stemmer",0);
13821381
const char *zExtra = useStemmer ? ",tokenize=porter" : "";
13831382
search_sql_setup(g.db);
1384
- db_multi_exec(zFtsSchema/*works-like:"%w%w%w%w%w%s"*/,
1385
- zDb, zDb, zDb, zDb, zDb, zExtra/*safe-for-%s*/);
1383
+ db_multi_exec(zFtsSchema/*works-like:"%s"*/, zExtra/*safe-for-%s*/);
13861384
searchIdxExists = 1;
13871385
}
13881386
void search_drop_index(void){
1389
- const char *zDb = db_name("repository");
1390
- db_multi_exec(zFtsDrop/*works-like:"%w%w%w"*/, zDb, zDb, zDb);
1387
+ db_multi_exec(zFtsDrop/*works-like:""*/);
13911388
searchIdxExists = 0;
13921389
}
13931390
13941391
/*
13951392
** Return true if the full-text search index exists
13961393
--- src/search.c
+++ src/search.c
@@ -1343,11 +1343,11 @@
1343
1344 /* The schema for the full-text index
1345 */
1346 static const char zFtsSchema[] =
1347 @ -- One entry for each possible search result
1348 @ CREATE TABLE IF NOT EXISTS "%w".ftsdocs(
1349 @ rowid INTEGER PRIMARY KEY, -- Maps to the ftsidx.docid
1350 @ type CHAR(1), -- Type of document
1351 @ rid INTEGER, -- BLOB.RID or TAG.TAGID for the document
1352 @ name TEXT, -- Additional document description
1353 @ idxed BOOLEAN, -- True if currently in the index
@@ -1355,41 +1355,38 @@
1355 @ url TEXT, -- URL to access this document
1356 @ mtime DATE, -- Date when document created
1357 @ bx TEXT, -- Temporary "body" content cache
1358 @ UNIQUE(type,rid)
1359 @ );
1360 @ CREATE INDEX "%w".ftsdocIdxed ON ftsdocs(type,rid,name) WHERE idxed==0;
1361 @ CREATE INDEX "%w".ftsdocName ON ftsdocs(name) WHERE type='w';
1362 @ CREATE VIEW IF NOT EXISTS "%w".ftscontent AS
1363 @ SELECT rowid, type, rid, name, idxed, label, url, mtime,
1364 @ title(type,rid,name) AS 'title', body(type,rid,name) AS 'body'
1365 @ FROM ftsdocs;
1366 @ CREATE VIRTUAL TABLE IF NOT EXISTS "%w".ftsidx
1367 @ USING fts4(content="ftscontent", title, body%s);
1368 ;
1369 static const char zFtsDrop[] =
1370 @ DROP TABLE IF EXISTS "%w".ftsidx;
1371 @ DROP VIEW IF EXISTS "%w".ftscontent;
1372 @ DROP TABLE IF EXISTS "%w".ftsdocs;
1373 ;
1374
1375 /*
1376 ** Create or drop the tables associated with a full-text index.
1377 */
1378 static int searchIdxExists = -1;
1379 void search_create_index(void){
1380 const char *zDb = db_name("repository");
1381 int useStemmer = db_get_boolean("search-stemmer",0);
1382 const char *zExtra = useStemmer ? ",tokenize=porter" : "";
1383 search_sql_setup(g.db);
1384 db_multi_exec(zFtsSchema/*works-like:"%w%w%w%w%w%s"*/,
1385 zDb, zDb, zDb, zDb, zDb, zExtra/*safe-for-%s*/);
1386 searchIdxExists = 1;
1387 }
1388 void search_drop_index(void){
1389 const char *zDb = db_name("repository");
1390 db_multi_exec(zFtsDrop/*works-like:"%w%w%w"*/, zDb, zDb, zDb);
1391 searchIdxExists = 0;
1392 }
1393
1394 /*
1395 ** Return true if the full-text search index exists
1396
--- src/search.c
+++ src/search.c
@@ -1343,11 +1343,11 @@
1343
1344 /* The schema for the full-text index
1345 */
1346 static const char zFtsSchema[] =
1347 @ -- One entry for each possible search result
1348 @ CREATE TABLE IF NOT EXISTS repository.ftsdocs(
1349 @ rowid INTEGER PRIMARY KEY, -- Maps to the ftsidx.docid
1350 @ type CHAR(1), -- Type of document
1351 @ rid INTEGER, -- BLOB.RID or TAG.TAGID for the document
1352 @ name TEXT, -- Additional document description
1353 @ idxed BOOLEAN, -- True if currently in the index
@@ -1355,41 +1355,38 @@
1355 @ url TEXT, -- URL to access this document
1356 @ mtime DATE, -- Date when document created
1357 @ bx TEXT, -- Temporary "body" content cache
1358 @ UNIQUE(type,rid)
1359 @ );
1360 @ CREATE INDEX repository.ftsdocIdxed ON ftsdocs(type,rid,name) WHERE idxed==0;
1361 @ CREATE INDEX repository.ftsdocName ON ftsdocs(name) WHERE type='w';
1362 @ CREATE VIEW IF NOT EXISTS repository.ftscontent AS
1363 @ SELECT rowid, type, rid, name, idxed, label, url, mtime,
1364 @ title(type,rid,name) AS 'title', body(type,rid,name) AS 'body'
1365 @ FROM ftsdocs;
1366 @ CREATE VIRTUAL TABLE IF NOT EXISTS repository.ftsidx
1367 @ USING fts4(content="ftscontent", title, body%s);
1368 ;
1369 static const char zFtsDrop[] =
1370 @ DROP TABLE IF EXISTS repository.ftsidx;
1371 @ DROP VIEW IF EXISTS repository.ftscontent;
1372 @ DROP TABLE IF EXISTS repository.ftsdocs;
1373 ;
1374
1375 /*
1376 ** Create or drop the tables associated with a full-text index.
1377 */
1378 static int searchIdxExists = -1;
1379 void search_create_index(void){
 
1380 int useStemmer = db_get_boolean("search-stemmer",0);
1381 const char *zExtra = useStemmer ? ",tokenize=porter" : "";
1382 search_sql_setup(g.db);
1383 db_multi_exec(zFtsSchema/*works-like:"%s"*/, zExtra/*safe-for-%s*/);
 
1384 searchIdxExists = 1;
1385 }
1386 void search_drop_index(void){
1387 db_multi_exec(zFtsDrop/*works-like:""*/);
 
1388 searchIdxExists = 0;
1389 }
1390
1391 /*
1392 ** Return true if the full-text search index exists
1393
+6 -8
--- src/setup.c
+++ src/setup.c
@@ -1926,16 +1926,16 @@
19261926
@ repository. Proceed with extreme caution.</p>
19271927
@
19281928
@ <p>Only the first statement in the entry box will be run.
19291929
@ Any subsequent statements will be silently ignored.</p>
19301930
@
1931
- @ <p>Database names:<ul><li>repository &rarr; %s(db_name("repository"))
1931
+ @ <p>Database names:<ul><li>repository
19321932
if( g.zConfigDbName ){
1933
- @ <li>config &rarr; %s(db_name("configdb"))
1933
+ @ <li>configdb
19341934
}
19351935
if( g.localOpen ){
1936
- @ <li>local-checkout &rarr; %s(db_name("localdb"))
1936
+ @ <li>localdb
19371937
}
19381938
@ </ul></p>
19391939
@
19401940
@ <form method="post" action="%s(g.zTop)/admin_sql">
19411941
login_insert_csrf_secret();
@@ -1945,18 +1945,16 @@
19451945
@ <input type="submit" name="schema" value="Show Schema">
19461946
@ <input type="submit" name="tablelist" value="List Tables">
19471947
@ </form>
19481948
if( P("schema") ){
19491949
zQ = sqlite3_mprintf(
1950
- "SELECT sql FROM %s.sqlite_master WHERE sql IS NOT NULL",
1951
- db_name("repository"));
1950
+ "SELECT sql FROM repository.sqlite_master WHERE sql IS NOT NULL");
19521951
go = 1;
19531952
}else if( P("tablelist") ){
19541953
zQ = sqlite3_mprintf(
1955
- "SELECT name FROM %s.sqlite_master WHERE type='table'"
1956
- " ORDER BY name",
1957
- db_name("repository"));
1954
+ "SELECT name FROM repository.sqlite_master WHERE type='table'"
1955
+ " ORDER BY name");
19581956
go = 1;
19591957
}
19601958
if( go ){
19611959
sqlite3_stmt *pStmt;
19621960
int rc;
19631961
--- src/setup.c
+++ src/setup.c
@@ -1926,16 +1926,16 @@
1926 @ repository. Proceed with extreme caution.</p>
1927 @
1928 @ <p>Only the first statement in the entry box will be run.
1929 @ Any subsequent statements will be silently ignored.</p>
1930 @
1931 @ <p>Database names:<ul><li>repository &rarr; %s(db_name("repository"))
1932 if( g.zConfigDbName ){
1933 @ <li>config &rarr; %s(db_name("configdb"))
1934 }
1935 if( g.localOpen ){
1936 @ <li>local-checkout &rarr; %s(db_name("localdb"))
1937 }
1938 @ </ul></p>
1939 @
1940 @ <form method="post" action="%s(g.zTop)/admin_sql">
1941 login_insert_csrf_secret();
@@ -1945,18 +1945,16 @@
1945 @ <input type="submit" name="schema" value="Show Schema">
1946 @ <input type="submit" name="tablelist" value="List Tables">
1947 @ </form>
1948 if( P("schema") ){
1949 zQ = sqlite3_mprintf(
1950 "SELECT sql FROM %s.sqlite_master WHERE sql IS NOT NULL",
1951 db_name("repository"));
1952 go = 1;
1953 }else if( P("tablelist") ){
1954 zQ = sqlite3_mprintf(
1955 "SELECT name FROM %s.sqlite_master WHERE type='table'"
1956 " ORDER BY name",
1957 db_name("repository"));
1958 go = 1;
1959 }
1960 if( go ){
1961 sqlite3_stmt *pStmt;
1962 int rc;
1963
--- src/setup.c
+++ src/setup.c
@@ -1926,16 +1926,16 @@
1926 @ repository. Proceed with extreme caution.</p>
1927 @
1928 @ <p>Only the first statement in the entry box will be run.
1929 @ Any subsequent statements will be silently ignored.</p>
1930 @
1931 @ <p>Database names:<ul><li>repository
1932 if( g.zConfigDbName ){
1933 @ <li>configdb
1934 }
1935 if( g.localOpen ){
1936 @ <li>localdb
1937 }
1938 @ </ul></p>
1939 @
1940 @ <form method="post" action="%s(g.zTop)/admin_sql">
1941 login_insert_csrf_secret();
@@ -1945,18 +1945,16 @@
1945 @ <input type="submit" name="schema" value="Show Schema">
1946 @ <input type="submit" name="tablelist" value="List Tables">
1947 @ </form>
1948 if( P("schema") ){
1949 zQ = sqlite3_mprintf(
1950 "SELECT sql FROM repository.sqlite_master WHERE sql IS NOT NULL");
 
1951 go = 1;
1952 }else if( P("tablelist") ){
1953 zQ = sqlite3_mprintf(
1954 "SELECT name FROM repository.sqlite_master WHERE type='table'"
1955 " ORDER BY name");
 
1956 go = 1;
1957 }
1958 if( go ){
1959 sqlite3_stmt *pStmt;
1960 int rc;
1961
+1 -2
--- src/sqlcmd.c
+++ src/sqlcmd.c
@@ -138,15 +138,15 @@
138138
static int sqlcmd_autoinit(
139139
sqlite3 *db,
140140
const char **pzErrMsg,
141141
const void *notUsed
142142
){
143
+ /* db_set_main_schemaname(db, "repository"); */
143144
add_content_sql_commands(db);
144145
db_add_aux_functions(db);
145146
re_add_sql_func(db);
146147
search_sql_setup(db);
147
- g.zMainDbType = "repository";
148148
foci_register(db);
149149
g.repositoryOpen = 1;
150150
g.db = db;
151151
return SQLITE_OK;
152152
}
@@ -223,9 +223,8 @@
223223
*/
224224
void fossil_close(int bDb, int noRepository){
225225
if( bDb ) db_close(1);
226226
if( noRepository ) g.zRepositoryName = 0;
227227
g.db = 0;
228
- g.zMainDbType = 0;
229228
g.repositoryOpen = 0;
230229
g.localOpen = 0;
231230
}
232231
--- src/sqlcmd.c
+++ src/sqlcmd.c
@@ -138,15 +138,15 @@
138 static int sqlcmd_autoinit(
139 sqlite3 *db,
140 const char **pzErrMsg,
141 const void *notUsed
142 ){
 
143 add_content_sql_commands(db);
144 db_add_aux_functions(db);
145 re_add_sql_func(db);
146 search_sql_setup(db);
147 g.zMainDbType = "repository";
148 foci_register(db);
149 g.repositoryOpen = 1;
150 g.db = db;
151 return SQLITE_OK;
152 }
@@ -223,9 +223,8 @@
223 */
224 void fossil_close(int bDb, int noRepository){
225 if( bDb ) db_close(1);
226 if( noRepository ) g.zRepositoryName = 0;
227 g.db = 0;
228 g.zMainDbType = 0;
229 g.repositoryOpen = 0;
230 g.localOpen = 0;
231 }
232
--- src/sqlcmd.c
+++ src/sqlcmd.c
@@ -138,15 +138,15 @@
138 static int sqlcmd_autoinit(
139 sqlite3 *db,
140 const char **pzErrMsg,
141 const void *notUsed
142 ){
143 /* db_set_main_schemaname(db, "repository"); */
144 add_content_sql_commands(db);
145 db_add_aux_functions(db);
146 re_add_sql_func(db);
147 search_sql_setup(db);
 
148 foci_register(db);
149 g.repositoryOpen = 1;
150 g.db = db;
151 return SQLITE_OK;
152 }
@@ -223,9 +223,8 @@
223 */
224 void fossil_close(int bDb, int noRepository){
225 if( bDb ) db_close(1);
226 if( noRepository ) g.zRepositoryName = 0;
227 g.db = 0;
 
228 g.repositoryOpen = 0;
229 g.localOpen = 0;
230 }
231
+691 -556
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
11
/******************************************************************************
22
** This file is an amalgamation of many separate C source files from SQLite
3
-** version 3.14.1. By combining all the individual C code files into this
3
+** version 3.15.0. By combining all the individual C code files into this
44
** single large file, the entire code can be compiled as a single translation
55
** unit. This allows many compilers to do optimizations that would not be
66
** possible if the files were compiled separately. Performance improvements
77
** of 5% or more are commonly seen when SQLite is compiled as a single
88
** translation unit.
@@ -378,13 +378,13 @@
378378
**
379379
** See also: [sqlite3_libversion()],
380380
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
381381
** [sqlite_version()] and [sqlite_source_id()].
382382
*/
383
-#define SQLITE_VERSION "3.14.1"
384
-#define SQLITE_VERSION_NUMBER 3014001
385
-#define SQLITE_SOURCE_ID "2016-08-11 18:53:32 a12d8059770df4bca59e321c266410344242bf7b"
383
+#define SQLITE_VERSION "3.15.0"
384
+#define SQLITE_VERSION_NUMBER 3015000
385
+#define SQLITE_SOURCE_ID "2016-08-22 20:10:01 7839519349c7371cdb4e16a215eacd27004cbc62"
386386
387387
/*
388388
** CAPI3REF: Run-Time Library Version Numbers
389389
** KEYWORDS: sqlite3_version, sqlite3_sourceid
390390
**
@@ -2227,12 +2227,22 @@
22272227
** is written 0 or 1 to indicate whether [sqlite3_load_extension()] interface
22282228
** is disabled or enabled following this call. The second parameter may
22292229
** be a NULL pointer, in which case the new setting is not reported back.
22302230
** </dd>
22312231
**
2232
+** <dt>SQLITE_DBCONFIG_MAINDBNAME</dt>
2233
+** <dd> ^This option is used to change the name of the "main" database
2234
+** schema. ^The sole argument is a pointer to a constant UTF8 string
2235
+** which will become the new schema name in place of "main". ^SQLite
2236
+** does not make a copy of the new main schema name string, so the application
2237
+** must ensure that the argument passed into this DBCONFIG option is unchanged
2238
+** until after the database connection closes.
2239
+** </dd>
2240
+**
22322241
** </dl>
22332242
*/
2243
+#define SQLITE_DBCONFIG_MAINDBNAME 1000 /* const char* */
22342244
#define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
22352245
#define SQLITE_DBCONFIG_ENABLE_FKEY 1002 /* int int* */
22362246
#define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */
22372247
#define SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1004 /* int int* */
22382248
#define SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION 1005 /* int int* */
@@ -13694,11 +13704,11 @@
1369413704
** in the sqlite.aDb[] array. aDb[0] is the main database file and
1369513705
** aDb[1] is the database file used to hold temporary tables. Additional
1369613706
** databases may be attached.
1369713707
*/
1369813708
struct Db {
13699
- char *zName; /* Name of this database */
13709
+ char *zDbSName; /* Name of this database. (schema name, not filename) */
1370013710
Btree *pBt; /* The B*Tree structure for this database file */
1370113711
u8 safety_level; /* How aggressive at syncing data to disk */
1370213712
u8 bSyncSet; /* True if "PRAGMA synchronous=N" has been run */
1370313713
Schema *pSchema; /* Pointer to database schema (possibly shared) */
1370413714
};
@@ -16298,12 +16308,12 @@
1629816308
SQLITE_PRIVATE Table *sqlite3LocateTable(Parse*,u32 flags,const char*, const char*);
1629916309
SQLITE_PRIVATE Table *sqlite3LocateTableItem(Parse*,u32 flags,struct SrcList_item *);
1630016310
SQLITE_PRIVATE Index *sqlite3FindIndex(sqlite3*,const char*, const char*);
1630116311
SQLITE_PRIVATE void sqlite3UnlinkAndDeleteTable(sqlite3*,int,const char*);
1630216312
SQLITE_PRIVATE void sqlite3UnlinkAndDeleteIndex(sqlite3*,int,const char*);
16303
-SQLITE_PRIVATE void sqlite3Vacuum(Parse*);
16304
-SQLITE_PRIVATE int sqlite3RunVacuum(char**, sqlite3*);
16313
+SQLITE_PRIVATE void sqlite3Vacuum(Parse*,Token*);
16314
+SQLITE_PRIVATE int sqlite3RunVacuum(char**, sqlite3*, int);
1630516315
SQLITE_PRIVATE char *sqlite3NameFromToken(sqlite3*, Token*);
1630616316
SQLITE_PRIVATE int sqlite3ExprCompare(Expr*, Expr*, int);
1630716317
SQLITE_PRIVATE int sqlite3ExprListCompare(ExprList*, ExprList*, int);
1630816318
SQLITE_PRIVATE int sqlite3ExprImpliesExpr(Expr*, Expr*, int);
1630916319
SQLITE_PRIVATE void sqlite3ExprAnalyzeAggregates(NameContext*, Expr*);
@@ -34851,10 +34861,31 @@
3485134861
unixLeaveMutex();
3485234862
}
3485334863
#endif /* if !OS_VXWORKS */
3485434864
return pUnused;
3485534865
}
34866
+
34867
+/*
34868
+** Find the mode, uid and gid of file zFile.
34869
+*/
34870
+static int getFileMode(
34871
+ const char *zFile, /* File name */
34872
+ mode_t *pMode, /* OUT: Permissions of zFile */
34873
+ uid_t *pUid, /* OUT: uid of zFile. */
34874
+ gid_t *pGid /* OUT: gid of zFile. */
34875
+){
34876
+ struct stat sStat; /* Output of stat() on database file */
34877
+ int rc = SQLITE_OK;
34878
+ if( 0==osStat(zFile, &sStat) ){
34879
+ *pMode = sStat.st_mode & 0777;
34880
+ *pUid = sStat.st_uid;
34881
+ *pGid = sStat.st_gid;
34882
+ }else{
34883
+ rc = SQLITE_IOERR_FSTAT;
34884
+ }
34885
+ return rc;
34886
+}
3485634887
3485734888
/*
3485834889
** This function is called by unixOpen() to determine the unix permissions
3485934890
** to create new files with. If no error occurs, then SQLITE_OK is returned
3486034891
** and a value suitable for passing as the third argument to open(2) is
@@ -34887,11 +34918,10 @@
3488734918
*pUid = 0;
3488834919
*pGid = 0;
3488934920
if( flags & (SQLITE_OPEN_WAL|SQLITE_OPEN_MAIN_JOURNAL) ){
3489034921
char zDb[MAX_PATHNAME+1]; /* Database file path */
3489134922
int nDb; /* Number of valid bytes in zDb */
34892
- struct stat sStat; /* Output of stat() on database file */
3489334923
3489434924
/* zPath is a path to a WAL or journal file. The following block derives
3489534925
** the path to the associated database file from zPath. This block handles
3489634926
** the following naming conventions:
3489734927
**
@@ -34918,19 +34948,22 @@
3491834948
nDb--;
3491934949
}
3492034950
memcpy(zDb, zPath, nDb);
3492134951
zDb[nDb] = '\0';
3492234952
34923
- if( 0==osStat(zDb, &sStat) ){
34924
- *pMode = sStat.st_mode & 0777;
34925
- *pUid = sStat.st_uid;
34926
- *pGid = sStat.st_gid;
34927
- }else{
34928
- rc = SQLITE_IOERR_FSTAT;
34929
- }
34953
+ rc = getFileMode(zDb, pMode, pUid, pGid);
3493034954
}else if( flags & SQLITE_OPEN_DELETEONCLOSE ){
3493134955
*pMode = 0600;
34956
+ }else if( flags & SQLITE_OPEN_URI ){
34957
+ /* If this is a main database file and the file was opened using a URI
34958
+ ** filename, check for the "modeof" parameter. If present, interpret
34959
+ ** its value as a filename and try to copy the mode, uid and gid from
34960
+ ** that file. */
34961
+ const char *z = sqlite3_uri_parameter(zPath, "modeof");
34962
+ if( z ){
34963
+ rc = getFileMode(z, pMode, pUid, pGid);
34964
+ }
3493234965
}
3493334966
return rc;
3493434967
}
3493534968
3493634969
/*
@@ -75441,11 +75474,11 @@
7544175474
int nEntry;
7544275475
sqlite3BtreeEnter(pBt);
7544375476
nEntry = sqlite3PagerWalCallback(sqlite3BtreePager(pBt));
7544475477
sqlite3BtreeLeave(pBt);
7544575478
if( db->xWalCallback && nEntry>0 && rc==SQLITE_OK ){
75446
- rc = db->xWalCallback(db->pWalArg, db, db->aDb[i].zName, nEntry);
75479
+ rc = db->xWalCallback(db->pWalArg, db, db->aDb[i].zDbSName, nEntry);
7544775480
}
7544875481
}
7544975482
}
7545075483
#endif
7545175484
return rc;
@@ -81472,11 +81505,11 @@
8147281505
}
8147381506
8147481507
if( pOp->p4type==P4_TABLE && HAS_UPDATE_HOOK(db) ){
8147581508
assert( pC->isTable );
8147681509
assert( pC->iDb>=0 );
81477
- zDb = db->aDb[pC->iDb].zName;
81510
+ zDb = db->aDb[pC->iDb].zDbSName;
8147881511
pTab = pOp->p4.pTab;
8147981512
assert( HasRowid(pTab) );
8148081513
op = ((pOp->p5 & OPFLAG_ISUPDATE) ? SQLITE_UPDATE : SQLITE_INSERT);
8148181514
}else{
8148281515
pTab = 0; /* Not needed. Silence a comiler warning. */
@@ -81589,11 +81622,11 @@
8158981622
** last moved with OP_Next or OP_Prev, not Seek or NotFound, set
8159081623
** VdbeCursor.movetoTarget to the current rowid. */
8159181624
if( pOp->p4type==P4_TABLE && HAS_UPDATE_HOOK(db) ){
8159281625
assert( pC->iDb>=0 );
8159381626
assert( pOp->p4.pTab!=0 );
81594
- zDb = db->aDb[pC->iDb].zName;
81627
+ zDb = db->aDb[pC->iDb].zDbSName;
8159581628
pTab = pOp->p4.pTab;
8159681629
if( (pOp->p5 & OPFLAG_SAVEPOSITION)!=0 && pC->isTable ){
8159781630
pC->movetoTarget = sqlite3BtreeIntegerKey(pC->uc.pCursor);
8159881631
}
8159981632
}else{
@@ -82559,11 +82592,11 @@
8255982592
initData.db = db;
8256082593
initData.iDb = pOp->p1;
8256182594
initData.pzErrMsg = &p->zErrMsg;
8256282595
zSql = sqlite3MPrintf(db,
8256382596
"SELECT name, rootpage, sql FROM '%q'.%s WHERE %s ORDER BY rowid",
82564
- db->aDb[iDb].zName, zMaster, pOp->p4.z);
82597
+ db->aDb[iDb].zDbSName, zMaster, pOp->p4.z);
8256582598
if( zSql==0 ){
8256682599
rc = SQLITE_NOMEM_BKPT;
8256782600
}else{
8256882601
assert( db->init.busy==0 );
8256982602
db->init.busy = 1;
@@ -83388,19 +83421,18 @@
8338883421
break;
8338983422
};
8339083423
#endif /* SQLITE_OMIT_PRAGMA */
8339183424
8339283425
#if !defined(SQLITE_OMIT_VACUUM) && !defined(SQLITE_OMIT_ATTACH)
83393
-/* Opcode: Vacuum * * * * *
83426
+/* Opcode: Vacuum P1 * * * *
8339483427
**
83395
-** Vacuum the entire database. This opcode will cause other virtual
83396
-** machines to be created and run. It may not be called from within
83397
-** a transaction.
83428
+** Vacuum the entire database P1. P1 is 0 for "main", and 2 or more
83429
+** for an attached database. The "temp" database may not be vacuumed.
8339883430
*/
8339983431
case OP_Vacuum: {
8340083432
assert( p->readOnly==0 );
83401
- rc = sqlite3RunVacuum(&p->zErrMsg, db);
83433
+ rc = sqlite3RunVacuum(&p->zErrMsg, db, pOp->p1);
8340283434
if( rc ) goto abort_due_to_error;
8340383435
break;
8340483436
}
8340583437
#endif
8340683438
@@ -83943,11 +83975,11 @@
8394383975
zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql);
8394483976
if( zTrace ){
8394583977
int i;
8394683978
for(i=0; i<db->nDb; i++){
8394783979
if( DbMaskTest(p->btreeMask, i)==0 ) continue;
83948
- sqlite3_file_control(db, db->aDb[i].zName, SQLITE_FCNTL_TRACE, zTrace);
83980
+ sqlite3_file_control(db, db->aDb[i].zDbSName, SQLITE_FCNTL_TRACE, zTrace);
8394983981
}
8395083982
}
8395183983
#endif /* SQLITE_USE_FCNTL_TRACE */
8395283984
#ifdef SQLITE_DEBUG
8395383985
if( (db->flags & SQLITE_SqlTrace)!=0
@@ -84279,11 +84311,11 @@
8427984311
rc = SQLITE_ERROR;
8428084312
sqlite3BtreeLeaveAll(db);
8428184313
goto blob_open_out;
8428284314
}
8428384315
pBlob->pTab = pTab;
84284
- pBlob->zDb = db->aDb[sqlite3SchemaToIndex(db, pTab->pSchema)].zName;
84316
+ pBlob->zDb = db->aDb[sqlite3SchemaToIndex(db, pTab->pSchema)].zDbSName;
8428584317
8428684318
/* Now search pTab for the exact column. */
8428784319
for(iCol=0; iCol<pTab->nCol; iCol++) {
8428884320
if( sqlite3StrICmp(pTab->aCol[iCol].zName, zColumn)==0 ){
8428984321
break;
@@ -87831,21 +87863,19 @@
8783187863
static SQLITE_NOINLINE int walkExpr(Walker *pWalker, Expr *pExpr){
8783287864
int rc;
8783387865
testcase( ExprHasProperty(pExpr, EP_TokenOnly) );
8783487866
testcase( ExprHasProperty(pExpr, EP_Reduced) );
8783587867
rc = pWalker->xExprCallback(pWalker, pExpr);
87836
- if( rc==WRC_Continue
87837
- && !ExprHasProperty(pExpr,EP_TokenOnly) ){
87838
- if( sqlite3WalkExpr(pWalker, pExpr->pLeft) ) return WRC_Abort;
87839
- if( sqlite3WalkExpr(pWalker, pExpr->pRight) ) return WRC_Abort;
87840
- if( ExprHasProperty(pExpr, EP_xIsSelect) ){
87841
- if( sqlite3WalkSelect(pWalker, pExpr->x.pSelect) ) return WRC_Abort;
87842
- }else{
87843
- if( sqlite3WalkExprList(pWalker, pExpr->x.pList) ) return WRC_Abort;
87844
- }
87845
- }
87846
- return rc & WRC_Abort;
87868
+ if( rc || ExprHasProperty(pExpr,EP_TokenOnly) ) return rc & WRC_Abort;
87869
+ if( pExpr->pLeft && walkExpr(pWalker, pExpr->pLeft) ) return WRC_Abort;
87870
+ if( pExpr->pRight && walkExpr(pWalker, pExpr->pRight) ) return WRC_Abort;
87871
+ if( ExprHasProperty(pExpr, EP_xIsSelect) ){
87872
+ if( sqlite3WalkSelect(pWalker, pExpr->x.pSelect) ) return WRC_Abort;
87873
+ }else{
87874
+ if( sqlite3WalkExprList(pWalker, pExpr->x.pList) ) return WRC_Abort;
87875
+ }
87876
+ return WRC_Continue;
8784787877
}
8784887878
SQLITE_PRIVATE int sqlite3WalkExpr(Walker *pWalker, Expr *pExpr){
8784987879
return pExpr ? walkExpr(pWalker,pExpr) : WRC_Continue;
8785087880
}
8785187881
@@ -88175,12 +88205,12 @@
8817588205
** legacy and because it does not hurt anything to just ignore the
8817688206
** database name. */
8817788207
zDb = 0;
8817888208
}else{
8817988209
for(i=0; i<db->nDb; i++){
88180
- assert( db->aDb[i].zName );
88181
- if( sqlite3StrICmp(db->aDb[i].zName,zDb)==0 ){
88210
+ assert( db->aDb[i].zDbSName );
88211
+ if( sqlite3StrICmp(db->aDb[i].zDbSName,zDb)==0 ){
8818288212
pSchema = db->aDb[i].pSchema;
8818388213
break;
8818488214
}
8818588215
}
8818688216
}
@@ -94249,11 +94279,11 @@
9424994279
assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );
9425094280
9425194281
pTab = sqlite3LocateTableItem(pParse, 0, &pSrc->a[0]);
9425294282
if( !pTab ) goto exit_rename_table;
9425394283
iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
94254
- zDb = db->aDb[iDb].zName;
94284
+ zDb = db->aDb[iDb].zDbSName;
9425594285
db->flags |= SQLITE_PreferBuiltin;
9425694286
9425794287
/* Get a NULL terminated version of the new table name. */
9425894288
zName = sqlite3NameFromToken(db, pName);
9425994289
if( !zName ) goto exit_rename_table;
@@ -94447,11 +94477,11 @@
9444794477
pNew = pParse->pNewTable;
9444894478
assert( pNew );
9444994479
9445094480
assert( sqlite3BtreeHoldsAllMutexes(db) );
9445194481
iDb = sqlite3SchemaToIndex(db, pNew->pSchema);
94452
- zDb = db->aDb[iDb].zName;
94482
+ zDb = db->aDb[iDb].zDbSName;
9445394483
zTab = &pNew->zName[16]; /* Skip the "sqlite_altertab_" prefix on the name */
9445494484
pCol = &pNew->aCol[pNew->nCol-1];
9445594485
pDflt = pCol->pDflt;
9445694486
pTab = sqlite3FindTable(db, zTab, zDb);
9445794487
assert( pTab );
@@ -94857,18 +94887,18 @@
9485794887
** if they do already exist.
9485894888
*/
9485994889
for(i=0; i<ArraySize(aTable); i++){
9486094890
const char *zTab = aTable[i].zName;
9486194891
Table *pStat;
94862
- if( (pStat = sqlite3FindTable(db, zTab, pDb->zName))==0 ){
94892
+ if( (pStat = sqlite3FindTable(db, zTab, pDb->zDbSName))==0 ){
9486394893
if( aTable[i].zCols ){
9486494894
/* The sqlite_statN table does not exist. Create it. Note that a
9486594895
** side-effect of the CREATE TABLE statement is to leave the rootpage
9486694896
** of the new table in register pParse->regRoot. This is important
9486794897
** because the OpenWrite opcode below will be needing it. */
9486894898
sqlite3NestedParse(pParse,
94869
- "CREATE TABLE %Q.%s(%s)", pDb->zName, zTab, aTable[i].zCols
94899
+ "CREATE TABLE %Q.%s(%s)", pDb->zDbSName, zTab, aTable[i].zCols
9487094900
);
9487194901
aRoot[i] = pParse->regRoot;
9487294902
aCreateTbl[i] = OPFLAG_P2ISREG;
9487394903
}
9487494904
}else{
@@ -94879,11 +94909,11 @@
9487994909
aCreateTbl[i] = 0;
9488094910
sqlite3TableLock(pParse, iDb, aRoot[i], 1, zTab);
9488194911
if( zWhere ){
9488294912
sqlite3NestedParse(pParse,
9488394913
"DELETE FROM %Q.%s WHERE %s=%Q",
94884
- pDb->zName, zTab, zWhereType, zWhere
94914
+ pDb->zDbSName, zTab, zWhereType, zWhere
9488594915
);
9488694916
}else{
9488794917
/* The sqlite_stat[134] table already exists. Delete all rows. */
9488894918
sqlite3VdbeAddOp2(v, OP_Clear, aRoot[i], iDb);
9488994919
}
@@ -95641,11 +95671,11 @@
9564195671
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
9564295672
assert( iDb>=0 );
9564395673
assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
9564495674
#ifndef SQLITE_OMIT_AUTHORIZATION
9564595675
if( sqlite3AuthCheck(pParse, SQLITE_ANALYZE, pTab->zName, 0,
95646
- db->aDb[iDb].zName ) ){
95676
+ db->aDb[iDb].zDbSName ) ){
9564795677
return;
9564895678
}
9564995679
#endif
9565095680
9565195681
/* Establish a read-lock on the table at the shared-cache level.
@@ -96031,11 +96061,11 @@
9603196061
}
9603296062
}else{
9603396063
/* Form 3: Analyze the fully qualified table name */
9603496064
iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pTableName);
9603596065
if( iDb>=0 ){
96036
- zDb = db->aDb[iDb].zName;
96066
+ zDb = db->aDb[iDb].zDbSName;
9603796067
z = sqlite3NameFromToken(db, pTableName);
9603896068
if( z ){
9603996069
if( (pIdx = sqlite3FindIndex(db, z, zDb))!=0 ){
9604096070
analyzeTable(pParse, pIdx->pTable, pIdx);
9604196071
}else if( (pTab = sqlite3LocateTable(pParse, 0, z, zDb))!=0 ){
@@ -96491,11 +96521,11 @@
9649196521
#endif
9649296522
}
9649396523
9649496524
/* Load new statistics out of the sqlite_stat1 table */
9649596525
sInfo.db = db;
96496
- sInfo.zDatabase = db->aDb[iDb].zName;
96526
+ sInfo.zDatabase = db->aDb[iDb].zDbSName;
9649796527
if( sqlite3FindTable(db, "sqlite_stat1", sInfo.zDatabase)!=0 ){
9649896528
zSql = sqlite3MPrintf(db,
9649996529
"SELECT tbl,idx,stat FROM %Q.sqlite_stat1", sInfo.zDatabase);
9650096530
if( zSql==0 ){
9650196531
rc = SQLITE_NOMEM_BKPT;
@@ -96634,11 +96664,11 @@
9663496664
if( !db->autoCommit ){
9663596665
zErrDyn = sqlite3MPrintf(db, "cannot ATTACH database within transaction");
9663696666
goto attach_error;
9663796667
}
9663896668
for(i=0; i<db->nDb; i++){
96639
- char *z = db->aDb[i].zName;
96669
+ char *z = db->aDb[i].zDbSName;
9664096670
assert( z && zName );
9664196671
if( sqlite3StrICmp(z, zName)==0 ){
9664296672
zErrDyn = sqlite3MPrintf(db, "database %s is already in use", zName);
9664396673
goto attach_error;
9664496674
}
@@ -96699,12 +96729,12 @@
9669996729
PAGER_SYNCHRONOUS_FULL | (db->flags & PAGER_FLAGS_MASK));
9670096730
#endif
9670196731
sqlite3BtreeLeave(aNew->pBt);
9670296732
}
9670396733
aNew->safety_level = SQLITE_DEFAULT_SYNCHRONOUS+1;
96704
- aNew->zName = sqlite3DbStrDup(db, zName);
96705
- if( rc==SQLITE_OK && aNew->zName==0 ){
96734
+ aNew->zDbSName = sqlite3DbStrDup(db, zName);
96735
+ if( rc==SQLITE_OK && aNew->zDbSName==0 ){
9670696736
rc = SQLITE_NOMEM_BKPT;
9670796737
}
9670896738
9670996739
9671096740
#ifdef SQLITE_HAS_CODEC
@@ -96812,11 +96842,11 @@
9681296842
9681396843
if( zName==0 ) zName = "";
9681496844
for(i=0; i<db->nDb; i++){
9681596845
pDb = &db->aDb[i];
9681696846
if( pDb->pBt==0 ) continue;
96817
- if( sqlite3StrICmp(pDb->zName, zName)==0 ) break;
96847
+ if( sqlite3StrICmp(pDb->zDbSName, zName)==0 ) break;
9681896848
}
9681996849
9682096850
if( i>=db->nDb ){
9682196851
sqlite3_snprintf(sizeof(zErr),zErr, "no such database: %s", zName);
9682296852
goto detach_error;
@@ -96970,11 +97000,11 @@
9697097000
sqlite3 *db;
9697197001
9697297002
db = pParse->db;
9697397003
assert( db->nDb>iDb );
9697497004
pFix->pParse = pParse;
96975
- pFix->zDb = db->aDb[iDb].zName;
97005
+ pFix->zDb = db->aDb[iDb].zDbSName;
9697697006
pFix->pSchema = db->aDb[iDb].pSchema;
9697797007
pFix->zType = zType;
9697897008
pFix->pName = pName;
9697997009
pFix->bVarOnly = (iDb==1);
9698097010
}
@@ -97228,13 +97258,13 @@
9722897258
Parse *pParse, /* The parser context */
9722997259
const char *zTab, /* Table name */
9723097260
const char *zCol, /* Column name */
9723197261
int iDb /* Index of containing database. */
9723297262
){
97233
- sqlite3 *db = pParse->db; /* Database handle */
97234
- char *zDb = db->aDb[iDb].zName; /* Name of attached database */
97235
- int rc; /* Auth callback return code */
97263
+ sqlite3 *db = pParse->db; /* Database handle */
97264
+ char *zDb = db->aDb[iDb].zDbSName; /* Schema name of attached database */
97265
+ int rc; /* Auth callback return code */
9723697266
9723797267
if( db->init.busy ) return SQLITE_OK;
9723897268
rc = db->xAuth(db->pAuthArg, SQLITE_READ, zTab,zCol,zDb,pParse->zAuthContext
9723997269
#ifdef SQLITE_USER_AUTHENTICATION
9724097270
,db->auth.zAuthUser
@@ -97703,14 +97733,15 @@
9770397733
return 0;
9770497734
}
9770597735
#endif
9770697736
for(i=OMIT_TEMPDB; i<db->nDb; i++){
9770797737
int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */
97708
- if( zDatabase!=0 && sqlite3StrICmp(zDatabase, db->aDb[j].zName) ) continue;
97709
- assert( sqlite3SchemaMutexHeld(db, j, 0) );
97710
- p = sqlite3HashFind(&db->aDb[j].pSchema->tblHash, zName);
97711
- if( p ) break;
97738
+ if( zDatabase==0 || sqlite3StrICmp(zDatabase, db->aDb[j].zDbSName)==0 ){
97739
+ assert( sqlite3SchemaMutexHeld(db, j, 0) );
97740
+ p = sqlite3HashFind(&db->aDb[j].pSchema->tblHash, zName);
97741
+ if( p ) break;
97742
+ }
9771297743
}
9771397744
return p;
9771497745
}
9771597746
9771697747
/*
@@ -97780,11 +97811,11 @@
9778097811
){
9778197812
const char *zDb;
9778297813
assert( p->pSchema==0 || p->zDatabase==0 );
9778397814
if( p->pSchema ){
9778497815
int iDb = sqlite3SchemaToIndex(pParse->db, p->pSchema);
97785
- zDb = pParse->db->aDb[iDb].zName;
97816
+ zDb = pParse->db->aDb[iDb].zDbSName;
9778697817
}else{
9778797818
zDb = p->zDatabase;
9778897819
}
9778997820
return sqlite3LocateTable(pParse, flags, p->zName, zDb);
9779097821
}
@@ -97808,11 +97839,11 @@
9780897839
assert( zDb!=0 || sqlite3BtreeHoldsAllMutexes(db) );
9780997840
for(i=OMIT_TEMPDB; i<db->nDb; i++){
9781097841
int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */
9781197842
Schema *pSchema = db->aDb[j].pSchema;
9781297843
assert( pSchema );
97813
- if( zDb && sqlite3StrICmp(zDb, db->aDb[j].zName) ) continue;
97844
+ if( zDb && sqlite3StrICmp(zDb, db->aDb[j].zDbSName) ) continue;
9781497845
assert( sqlite3SchemaMutexHeld(db, j, 0) );
9781597846
p = sqlite3HashFind(&pSchema->idxHash, zName);
9781697847
if( p ) break;
9781797848
}
9781897849
return p;
@@ -97877,12 +97908,12 @@
9787797908
SQLITE_PRIVATE void sqlite3CollapseDatabaseArray(sqlite3 *db){
9787897909
int i, j;
9787997910
for(i=j=2; i<db->nDb; i++){
9788097911
struct Db *pDb = &db->aDb[i];
9788197912
if( pDb->pBt==0 ){
97882
- sqlite3DbFree(db, pDb->zName);
97883
- pDb->zName = 0;
97913
+ sqlite3DbFree(db, pDb->zDbSName);
97914
+ pDb->zDbSName = 0;
9788497915
continue;
9788597916
}
9788697917
if( j<i ){
9788797918
db->aDb[j] = db->aDb[i];
9788897919
}
@@ -98098,11 +98129,11 @@
9809898129
SQLITE_PRIVATE int sqlite3FindDbName(sqlite3 *db, const char *zName){
9809998130
int i = -1; /* Database number */
9810098131
if( zName ){
9810198132
Db *pDb;
9810298133
for(i=(db->nDb-1), pDb=&db->aDb[i]; i>=0; i--, pDb--){
98103
- if( 0==sqlite3StrICmp(pDb->zName, zName) ) break;
98134
+ if( 0==sqlite3StrICmp(pDb->zDbSName, zName) ) break;
9810498135
}
9810598136
}
9810698137
return i;
9810798138
}
9810898139
@@ -98157,11 +98188,11 @@
9815798188
if( iDb<0 ){
9815898189
sqlite3ErrorMsg(pParse, "unknown database %T", pName1);
9815998190
return -1;
9816098191
}
9816198192
}else{
98162
- assert( db->init.iDb==0 || db->init.busy );
98193
+ assert( db->init.iDb==0 || db->init.busy || (db->flags & SQLITE_Vacuum)!=0);
9816398194
iDb = db->init.iDb;
9816498195
*pUnqual = pName1;
9816598196
}
9816698197
return iDb;
9816798198
}
@@ -98268,11 +98299,11 @@
9826898299
SQLITE_CREATE_TABLE,
9826998300
SQLITE_CREATE_TEMP_TABLE,
9827098301
SQLITE_CREATE_VIEW,
9827198302
SQLITE_CREATE_TEMP_VIEW
9827298303
};
98273
- char *zDb = db->aDb[iDb].zName;
98304
+ char *zDb = db->aDb[iDb].zDbSName;
9827498305
if( sqlite3AuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(isTemp), 0, zDb) ){
9827598306
goto begin_table_error;
9827698307
}
9827798308
if( !isVirtual && sqlite3AuthCheck(pParse, (int)aCode[isTemp+2*isView],
9827898309
zName, 0, zDb) ){
@@ -98287,11 +98318,11 @@
9828798318
** to an sqlite3_declare_vtab() call. In that case only the column names
9828898319
** and types will be used, so there is no need to test for namespace
9828998320
** collisions.
9829098321
*/
9829198322
if( !IN_DECLARE_VTAB ){
98292
- char *zDb = db->aDb[iDb].zName;
98323
+ char *zDb = db->aDb[iDb].zDbSName;
9829398324
if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){
9829498325
goto begin_table_error;
9829598326
}
9829698327
pTable = sqlite3FindTable(db, zName, zDb);
9829798328
if( pTable ){
@@ -99380,11 +99411,11 @@
9938099411
*/
9938199412
sqlite3NestedParse(pParse,
9938299413
"UPDATE %Q.%s "
9938399414
"SET type='%s', name=%Q, tbl_name=%Q, rootpage=#%d, sql=%Q "
9938499415
"WHERE rowid=#%d",
99385
- db->aDb[iDb].zName, SCHEMA_TABLE(iDb),
99416
+ db->aDb[iDb].zDbSName, SCHEMA_TABLE(iDb),
9938699417
zType,
9938799418
p->zName,
9938899419
p->zName,
9938999420
pParse->regRoot,
9939099421
zStmt,
@@ -99395,17 +99426,17 @@
9939599426
9939699427
#ifndef SQLITE_OMIT_AUTOINCREMENT
9939799428
/* Check to see if we need to create an sqlite_sequence table for
9939899429
** keeping track of autoincrement keys.
9939999430
*/
99400
- if( p->tabFlags & TF_Autoincrement ){
99431
+ if( (p->tabFlags & TF_Autoincrement)!=0 ){
9940199432
Db *pDb = &db->aDb[iDb];
9940299433
assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
9940399434
if( pDb->pSchema->pSeqTab==0 ){
9940499435
sqlite3NestedParse(pParse,
9940599436
"CREATE TABLE %Q.sqlite_sequence(name,seq)",
99406
- pDb->zName
99437
+ pDb->zDbSName
9940799438
);
9940899439
}
9940999440
}
9941099441
#endif
9941199442
@@ -99715,11 +99746,11 @@
9971599746
** is in register NNN. See grammar rules associated with the TK_REGISTER
9971699747
** token for additional information.
9971799748
*/
9971899749
sqlite3NestedParse(pParse,
9971999750
"UPDATE %Q.%s SET rootpage=%d WHERE #%d AND rootpage=#%d",
99720
- pParse->db->aDb[iDb].zName, SCHEMA_TABLE(iDb), iTable, r1, r1);
99751
+ pParse->db->aDb[iDb].zDbSName, SCHEMA_TABLE(iDb), iTable, r1, r1);
9972199752
#endif
9972299753
sqlite3ReleaseTempReg(pParse, r1);
9972399754
}
9972499755
9972599756
/*
@@ -99791,11 +99822,11 @@
9979199822
int iDb, /* The database number */
9979299823
const char *zType, /* "idx" or "tbl" */
9979399824
const char *zName /* Name of index or table */
9979499825
){
9979599826
int i;
99796
- const char *zDbName = pParse->db->aDb[iDb].zName;
99827
+ const char *zDbName = pParse->db->aDb[iDb].zDbSName;
9979799828
for(i=1; i<=4; i++){
9979899829
char zTab[24];
9979999830
sqlite3_snprintf(sizeof(zTab),zTab,"sqlite_stat%d",i);
9980099831
if( sqlite3FindTable(pParse->db, zTab, zDbName) ){
9980199832
sqlite3NestedParse(pParse,
@@ -99844,11 +99875,11 @@
9984499875
** move as a result of the drop (can happen in auto-vacuum mode).
9984599876
*/
9984699877
if( pTab->tabFlags & TF_Autoincrement ){
9984799878
sqlite3NestedParse(pParse,
9984899879
"DELETE FROM %Q.sqlite_sequence WHERE name=%Q",
99849
- pDb->zName, pTab->zName
99880
+ pDb->zDbSName, pTab->zName
9985099881
);
9985199882
}
9985299883
#endif
9985399884
9985499885
/* Drop all SQLITE_MASTER table and index entries that refer to the
@@ -99858,11 +99889,11 @@
9985899889
** created in the temp database that refers to a table in another
9985999890
** database.
9986099891
*/
9986199892
sqlite3NestedParse(pParse,
9986299893
"DELETE FROM %Q.%s WHERE tbl_name=%Q and type!='trigger'",
99863
- pDb->zName, SCHEMA_TABLE(iDb), pTab->zName);
99894
+ pDb->zDbSName, SCHEMA_TABLE(iDb), pTab->zName);
9986499895
if( !isView && !IsVirtual(pTab) ){
9986599896
destroyTable(pParse, pTab);
9986699897
}
9986799898
9986899899
/* Remove the table entry from SQLite's internal schema and modify
@@ -99912,11 +99943,11 @@
9991299943
}
9991399944
#ifndef SQLITE_OMIT_AUTHORIZATION
9991499945
{
9991599946
int code;
9991699947
const char *zTab = SCHEMA_TABLE(iDb);
99917
- const char *zDb = db->aDb[iDb].zName;
99948
+ const char *zDb = db->aDb[iDb].zDbSName;
9991899949
const char *zArg2 = 0;
9991999950
if( sqlite3AuthCheck(pParse, SQLITE_DELETE, zTab, 0, zDb)){
9992099951
goto exit_drop_table;
9992199952
}
9992299953
if( isView ){
@@ -100153,11 +100184,11 @@
100153100184
sqlite3 *db = pParse->db; /* The database connection */
100154100185
int iDb = sqlite3SchemaToIndex(db, pIndex->pSchema);
100155100186
100156100187
#ifndef SQLITE_OMIT_AUTHORIZATION
100157100188
if( sqlite3AuthCheck(pParse, SQLITE_REINDEX, pIndex->zName, 0,
100158
- db->aDb[iDb].zName ) ){
100189
+ db->aDb[iDb].zDbSName ) ){
100159100190
return;
100160100191
}
100161100192
#endif
100162100193
100163100194
/* Require a write-lock on the table to perform this operation */
@@ -100405,11 +100436,11 @@
100405100436
if( sqlite3FindTable(db, zName, 0)!=0 ){
100406100437
sqlite3ErrorMsg(pParse, "there is already a table named %s", zName);
100407100438
goto exit_create_index;
100408100439
}
100409100440
}
100410
- if( sqlite3FindIndex(db, zName, pDb->zName)!=0 ){
100441
+ if( sqlite3FindIndex(db, zName, pDb->zDbSName)!=0 ){
100411100442
if( !ifNotExist ){
100412100443
sqlite3ErrorMsg(pParse, "index %s already exists", zName);
100413100444
}else{
100414100445
assert( !db->init.busy );
100415100446
sqlite3CodeVerifySchema(pParse, iDb);
@@ -100435,11 +100466,11 @@
100435100466
100436100467
/* Check for authorization to create an index.
100437100468
*/
100438100469
#ifndef SQLITE_OMIT_AUTHORIZATION
100439100470
{
100440
- const char *zDb = pDb->zName;
100471
+ const char *zDb = pDb->zDbSName;
100441100472
if( sqlite3AuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(iDb), 0, zDb) ){
100442100473
goto exit_create_index;
100443100474
}
100444100475
i = SQLITE_CREATE_INDEX;
100445100476
if( !OMIT_TEMPDB && iDb==1 ) i = SQLITE_CREATE_TEMP_INDEX;
@@ -100750,11 +100781,11 @@
100750100781
100751100782
/* Add an entry in sqlite_master for this index
100752100783
*/
100753100784
sqlite3NestedParse(pParse,
100754100785
"INSERT INTO %Q.%s VALUES('index',%Q,%Q,#%d,%Q);",
100755
- db->aDb[iDb].zName, SCHEMA_TABLE(iDb),
100786
+ db->aDb[iDb].zDbSName, SCHEMA_TABLE(iDb),
100756100787
pIndex->zName,
100757100788
pTab->zName,
100758100789
iMem,
100759100790
zStmt
100760100791
);
@@ -100884,11 +100915,11 @@
100884100915
iDb = sqlite3SchemaToIndex(db, pIndex->pSchema);
100885100916
#ifndef SQLITE_OMIT_AUTHORIZATION
100886100917
{
100887100918
int code = SQLITE_DROP_INDEX;
100888100919
Table *pTab = pIndex->pTable;
100889
- const char *zDb = db->aDb[iDb].zName;
100920
+ const char *zDb = db->aDb[iDb].zDbSName;
100890100921
const char *zTab = SCHEMA_TABLE(iDb);
100891100922
if( sqlite3AuthCheck(pParse, SQLITE_DELETE, zTab, 0, zDb) ){
100892100923
goto exit_drop_index;
100893100924
}
100894100925
if( !OMIT_TEMPDB && iDb ) code = SQLITE_DROP_TEMP_INDEX;
@@ -100902,11 +100933,11 @@
100902100933
v = sqlite3GetVdbe(pParse);
100903100934
if( v ){
100904100935
sqlite3BeginWriteOperation(pParse, 1, iDb);
100905100936
sqlite3NestedParse(pParse,
100906100937
"DELETE FROM %Q.%s WHERE name=%Q AND type='index'",
100907
- db->aDb[iDb].zName, SCHEMA_TABLE(iDb), pIndex->zName
100938
+ db->aDb[iDb].zDbSName, SCHEMA_TABLE(iDb), pIndex->zName
100908100939
);
100909100940
sqlite3ClearStatTables(pParse, iDb, "idx", pIndex->zName);
100910100941
sqlite3ChangeCookie(pParse, iDb);
100911100942
destroyRootPage(pParse, pIndex->tnum, iDb);
100912100943
sqlite3VdbeAddOp4(v, OP_DropIndex, iDb, 0, 0, pIndex->zName, 0);
@@ -101447,11 +101478,11 @@
101447101478
SQLITE_PRIVATE void sqlite3CodeVerifyNamedSchema(Parse *pParse, const char *zDb){
101448101479
sqlite3 *db = pParse->db;
101449101480
int i;
101450101481
for(i=0; i<db->nDb; i++){
101451101482
Db *pDb = &db->aDb[i];
101452
- if( pDb->pBt && (!zDb || 0==sqlite3StrICmp(zDb, pDb->zName)) ){
101483
+ if( pDb->pBt && (!zDb || 0==sqlite3StrICmp(zDb, pDb->zDbSName)) ){
101453101484
sqlite3CodeVerifySchema(pParse, i);
101454101485
}
101455101486
}
101456101487
}
101457101488
@@ -101694,11 +101725,11 @@
101694101725
}
101695101726
iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pObjName);
101696101727
if( iDb<0 ) return;
101697101728
z = sqlite3NameFromToken(db, pObjName);
101698101729
if( z==0 ) return;
101699
- zDb = db->aDb[iDb].zName;
101730
+ zDb = db->aDb[iDb].zDbSName;
101700101731
pTab = sqlite3FindTable(db, z, zDb);
101701101732
if( pTab ){
101702101733
reindexTable(pParse, pTab, 0);
101703101734
sqlite3DbFree(db, z);
101704101735
return;
@@ -102408,11 +102439,11 @@
102408102439
pWhere = sqlite3ExprDup(db, pWhere, 0);
102409102440
pFrom = sqlite3SrcListAppend(db, 0, 0, 0);
102410102441
if( pFrom ){
102411102442
assert( pFrom->nSrc==1 );
102412102443
pFrom->a[0].zName = sqlite3DbStrDup(db, pView->zName);
102413
- pFrom->a[0].zDatabase = sqlite3DbStrDup(db, db->aDb[iDb].zName);
102444
+ pFrom->a[0].zDatabase = sqlite3DbStrDup(db, db->aDb[iDb].zDbSName);
102414102445
assert( pFrom->a[0].pOn==0 );
102415102446
assert( pFrom->a[0].pUsing==0 );
102416102447
}
102417102448
pSel = sqlite3SelectNew(pParse, 0, pFrom, pWhere, 0, 0, 0,
102418102449
SF_IncludeHidden, 0, 0);
@@ -102595,11 +102626,11 @@
102595102626
if( sqlite3IsReadOnly(pParse, pTab, (pTrigger?1:0)) ){
102596102627
goto delete_from_cleanup;
102597102628
}
102598102629
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
102599102630
assert( iDb<db->nDb );
102600
- zDb = db->aDb[iDb].zName;
102631
+ zDb = db->aDb[iDb].zDbSName;
102601102632
rcauth = sqlite3AuthCheck(pParse, SQLITE_DELETE, pTab->zName, 0, zDb);
102602102633
assert( rcauth==SQLITE_OK || rcauth==SQLITE_DENY || rcauth==SQLITE_IGNORE );
102603102634
if( rcauth==SQLITE_DENY ){
102604102635
goto delete_from_cleanup;
102605102636
}
@@ -105927,11 +105958,11 @@
105927105958
105928105959
/* If foreign-keys are disabled, this function is a no-op. */
105929105960
if( (db->flags&SQLITE_ForeignKeys)==0 ) return;
105930105961
105931105962
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
105932
- zDb = db->aDb[iDb].zName;
105963
+ zDb = db->aDb[iDb].zDbSName;
105933105964
105934105965
/* Loop through all the foreign key constraints for which pTab is the
105935105966
** child table (the table that the foreign key definition is part of). */
105936105967
for(pFKey=pTab->pFKey; pFKey; pFKey=pFKey->pNextFrom){
105937105968
Table *pTo; /* Parent table of foreign key pFKey */
@@ -106667,11 +106698,13 @@
106667106698
106668106699
#ifndef SQLITE_OMIT_AUTOINCREMENT
106669106700
/*
106670106701
** Locate or create an AutoincInfo structure associated with table pTab
106671106702
** which is in database iDb. Return the register number for the register
106672
-** that holds the maximum rowid.
106703
+** that holds the maximum rowid. Return zero if pTab is not an AUTOINCREMENT
106704
+** table. (Also return zero when doing a VACUUM since we do not want to
106705
+** update the AUTOINCREMENT counters during a VACUUM.)
106673106706
**
106674106707
** There is at most one AutoincInfo structure per table even if the
106675106708
** same table is autoincremented multiple times due to inserts within
106676106709
** triggers. A new AutoincInfo structure is created if this is the
106677106710
** first use of table pTab. On 2nd and subsequent uses, the original
@@ -106690,11 +106723,13 @@
106690106723
Parse *pParse, /* Parsing context */
106691106724
int iDb, /* Index of the database holding pTab */
106692106725
Table *pTab /* The table we are writing to */
106693106726
){
106694106727
int memId = 0; /* Register holding maximum rowid */
106695
- if( pTab->tabFlags & TF_Autoincrement ){
106728
+ if( (pTab->tabFlags & TF_Autoincrement)!=0
106729
+ && (pParse->db->flags & SQLITE_Vacuum)==0
106730
+ ){
106696106731
Parse *pToplevel = sqlite3ParseToplevel(pParse);
106697106732
AutoincInfo *pInfo;
106698106733
106699106734
pInfo = pToplevel->pAinc;
106700106735
while( pInfo && pInfo->pTab!=pTab ){ pInfo = pInfo->pNext; }
@@ -107014,11 +107049,11 @@
107014107049
goto insert_cleanup;
107015107050
}
107016107051
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
107017107052
assert( iDb<db->nDb );
107018107053
pDb = &db->aDb[iDb];
107019
- zDb = pDb->zName;
107054
+ zDb = pDb->zDbSName;
107020107055
if( sqlite3AuthCheck(pParse, SQLITE_INSERT, pTab->zName, 0, zDb) ){
107021107056
goto insert_cleanup;
107022107057
}
107023107058
withoutRowid = !HasRowid(pTab);
107024107059
@@ -110972,11 +111007,11 @@
110972111007
}else{
110973111008
zRight = sqlite3NameFromToken(db, pValue);
110974111009
}
110975111010
110976111011
assert( pId2 );
110977
- zDb = pId2->n>0 ? pDb->zName : 0;
111012
+ zDb = pId2->n>0 ? pDb->zDbSName : 0;
110978111013
if( sqlite3AuthCheck(pParse, SQLITE_PRAGMA, zLeft, zRight, zDb) ){
110979111014
goto pragma_out;
110980111015
}
110981111016
110982111017
/* Send an SQLITE_FCNTL_PRAGMA file-control to the underlying VFS
@@ -111825,14 +111860,14 @@
111825111860
int i;
111826111861
pParse->nMem = 3;
111827111862
setAllColumnNames(v, 3, azCol); assert( 3==ArraySize(azCol) );
111828111863
for(i=0; i<db->nDb; i++){
111829111864
if( db->aDb[i].pBt==0 ) continue;
111830
- assert( db->aDb[i].zName!=0 );
111865
+ assert( db->aDb[i].zDbSName!=0 );
111831111866
sqlite3VdbeMultiLoad(v, 1, "iss",
111832111867
i,
111833
- db->aDb[i].zName,
111868
+ db->aDb[i].zDbSName,
111834111869
sqlite3BtreeGetFilename(db->aDb[i].pBt));
111835111870
sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3);
111836111871
}
111837111872
}
111838111873
break;
@@ -112117,11 +112152,11 @@
112117112152
/* Do the b-tree integrity checks */
112118112153
sqlite3VdbeAddOp4(v, OP_IntegrityCk, 2, cnt, 1, (char*)aRoot,P4_INTARRAY);
112119112154
sqlite3VdbeChangeP5(v, (u8)i);
112120112155
addr = sqlite3VdbeAddOp1(v, OP_IsNull, 2); VdbeCoverage(v);
112121112156
sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0,
112122
- sqlite3MPrintf(db, "*** in database %s ***\n", db->aDb[i].zName),
112157
+ sqlite3MPrintf(db, "*** in database %s ***\n", db->aDb[i].zDbSName),
112123112158
P4_DYNAMIC);
112124112159
sqlite3VdbeAddOp3(v, OP_Move, 2, 4, 1);
112125112160
sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 2);
112126112161
sqlite3VdbeAddOp2(v, OP_ResultRow, 2, 1);
112127112162
sqlite3VdbeJumpHere(v, addr);
@@ -112556,19 +112591,19 @@
112556112591
pParse->nMem = 2;
112557112592
for(i=0; i<db->nDb; i++){
112558112593
Btree *pBt;
112559112594
const char *zState = "unknown";
112560112595
int j;
112561
- if( db->aDb[i].zName==0 ) continue;
112596
+ if( db->aDb[i].zDbSName==0 ) continue;
112562112597
pBt = db->aDb[i].pBt;
112563112598
if( pBt==0 || sqlite3BtreePager(pBt)==0 ){
112564112599
zState = "closed";
112565
- }else if( sqlite3_file_control(db, i ? db->aDb[i].zName : 0,
112600
+ }else if( sqlite3_file_control(db, i ? db->aDb[i].zDbSName : 0,
112566112601
SQLITE_FCNTL_LOCKSTATE, &j)==SQLITE_OK ){
112567112602
zState = azLockName[j];
112568112603
}
112569
- sqlite3VdbeMultiLoad(v, 1, "ss", db->aDb[i].zName, zState);
112604
+ sqlite3VdbeMultiLoad(v, 1, "ss", db->aDb[i].zDbSName, zState);
112570112605
sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 2);
112571112606
}
112572112607
break;
112573112608
}
112574112609
#endif
@@ -112700,10 +112735,11 @@
112700112735
** But because db->init.busy is set to 1, no VDBE code is generated
112701112736
** or executed. All the parser does is build the internal data
112702112737
** structures that describe the table, index, or view.
112703112738
*/
112704112739
int rc;
112740
+ u8 saved_iDb = db->init.iDb;
112705112741
sqlite3_stmt *pStmt;
112706112742
TESTONLY(int rcp); /* Return code from sqlite3_prepare() */
112707112743
112708112744
assert( db->init.busy );
112709112745
db->init.iDb = iDb;
@@ -112710,11 +112746,12 @@
112710112746
db->init.newTnum = sqlite3Atoi(argv[1]);
112711112747
db->init.orphanTrigger = 0;
112712112748
TESTONLY(rcp = ) sqlite3_prepare(db, argv[2], -1, &pStmt, 0);
112713112749
rc = db->errCode;
112714112750
assert( (rc&0xFF)==(rcp&0xFF) );
112715
- db->init.iDb = 0;
112751
+ db->init.iDb = saved_iDb;
112752
+ assert( saved_iDb==0 || (db->flags & SQLITE_Vacuum)!=0 );
112716112753
if( SQLITE_OK!=rc ){
112717112754
if( db->init.orphanTrigger ){
112718112755
assert( iDb==1 );
112719112756
}else{
112720112757
pData->rc = rc;
@@ -112734,11 +112771,11 @@
112734112771
** constraint for a CREATE TABLE. The index should have already
112735112772
** been created when we processed the CREATE TABLE. All we have
112736112773
** to do here is record the root page number for that index.
112737112774
*/
112738112775
Index *pIndex;
112739
- pIndex = sqlite3FindIndex(db, argv[0], db->aDb[iDb].zName);
112776
+ pIndex = sqlite3FindIndex(db, argv[0], db->aDb[iDb].zDbSName);
112740112777
if( pIndex==0 ){
112741112778
/* This can occur if there exists an index on a TEMP table which
112742112779
** has the same name as another index on a permanent index. Since
112743112780
** the permanent table is hidden by the TEMP table, we can also
112744112781
** safely ignore the index on the permanent table.
@@ -112913,11 +112950,11 @@
112913112950
assert( db->init.busy );
112914112951
{
112915112952
char *zSql;
112916112953
zSql = sqlite3MPrintf(db,
112917112954
"SELECT name, rootpage, sql FROM \"%w\".%s ORDER BY rowid",
112918
- db->aDb[iDb].zName, zMasterName);
112955
+ db->aDb[iDb].zDbSName, zMasterName);
112919112956
#ifndef SQLITE_OMIT_AUTHORIZATION
112920112957
{
112921112958
sqlite3_xauth xAuth;
112922112959
xAuth = db->xAuth;
112923112960
db->xAuth = 0;
@@ -113188,11 +113225,11 @@
113188113225
Btree *pBt = db->aDb[i].pBt;
113189113226
if( pBt ){
113190113227
assert( sqlite3BtreeHoldsMutex(pBt) );
113191113228
rc = sqlite3BtreeSchemaLocked(pBt);
113192113229
if( rc ){
113193
- const char *zDb = db->aDb[i].zName;
113230
+ const char *zDb = db->aDb[i].zDbSName;
113194113231
sqlite3ErrorWithMsg(db, rc, "database schema is locked: %s", zDb);
113195113232
testcase( db->flags & SQLITE_ReadUncommitted );
113196113233
goto end_prepare;
113197113234
}
113198113235
}
@@ -114944,11 +114981,11 @@
114944114981
estWidth = pTab->aCol[iCol].szEst;
114945114982
}
114946114983
zOrigTab = pTab->zName;
114947114984
if( pNC->pParse ){
114948114985
int iDb = sqlite3SchemaToIndex(pNC->pParse->db, pTab->pSchema);
114949
- zOrigDb = pNC->pParse->db->aDb[iDb].zName;
114986
+ zOrigDb = pNC->pParse->db->aDb[iDb].zDbSName;
114950114987
}
114951114988
#else
114952114989
if( iCol<0 ){
114953114990
zType = "INTEGER";
114954114991
}else{
@@ -117900,11 +117937,11 @@
117900117937
pSub = 0;
117901117938
if( zTName && sqlite3StrICmp(zTName, zTabName)!=0 ){
117902117939
continue;
117903117940
}
117904117941
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
117905
- zSchemaName = iDb>=0 ? db->aDb[iDb].zName : "*";
117942
+ zSchemaName = iDb>=0 ? db->aDb[iDb].zDbSName : "*";
117906117943
}
117907117944
for(j=0; j<pTab->nCol; j++){
117908117945
char *zName = pTab->aCol[j].zName;
117909117946
char *zColname; /* The computed column name */
117910117947
char *zToFree; /* Malloced string that needs to be freed */
@@ -119612,12 +119649,12 @@
119612119649
iTabDb = sqlite3SchemaToIndex(db, pTab->pSchema);
119613119650
119614119651
#ifndef SQLITE_OMIT_AUTHORIZATION
119615119652
{
119616119653
int code = SQLITE_CREATE_TRIGGER;
119617
- const char *zDb = db->aDb[iTabDb].zName;
119618
- const char *zDbTrig = isTemp ? db->aDb[1].zName : zDb;
119654
+ const char *zDb = db->aDb[iTabDb].zDbSName;
119655
+ const char *zDbTrig = isTemp ? db->aDb[1].zDbSName : zDb;
119619119656
if( iTabDb==1 || isTemp ) code = SQLITE_CREATE_TEMP_TRIGGER;
119620119657
if( sqlite3AuthCheck(pParse, code, zName, pTab->zName, zDbTrig) ){
119621119658
goto trigger_cleanup;
119622119659
}
119623119660
if( sqlite3AuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(iTabDb),0,zDb)){
@@ -119707,11 +119744,11 @@
119707119744
if( v==0 ) goto triggerfinish_cleanup;
119708119745
sqlite3BeginWriteOperation(pParse, 0, iDb);
119709119746
z = sqlite3DbStrNDup(db, (char*)pAll->z, pAll->n);
119710119747
sqlite3NestedParse(pParse,
119711119748
"INSERT INTO %Q.%s VALUES('trigger',%Q,%Q,0,'CREATE TRIGGER %q')",
119712
- db->aDb[iDb].zName, SCHEMA_TABLE(iDb), zName,
119749
+ db->aDb[iDb].zDbSName, SCHEMA_TABLE(iDb), zName,
119713119750
pTrig->table, z);
119714119751
sqlite3DbFree(db, z);
119715119752
sqlite3ChangeCookie(pParse, iDb);
119716119753
sqlite3VdbeAddParseSchemaOp(v, iDb,
119717119754
sqlite3MPrintf(db, "type='trigger' AND name='%q'", zName));
@@ -119896,11 +119933,11 @@
119896119933
zDb = pName->a[0].zDatabase;
119897119934
zName = pName->a[0].zName;
119898119935
assert( zDb!=0 || sqlite3BtreeHoldsAllMutexes(db) );
119899119936
for(i=OMIT_TEMPDB; i<db->nDb; i++){
119900119937
int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */
119901
- if( zDb && sqlite3StrICmp(db->aDb[j].zName, zDb) ) continue;
119938
+ if( zDb && sqlite3StrICmp(db->aDb[j].zDbSName, zDb) ) continue;
119902119939
assert( sqlite3SchemaMutexHeld(db, j, 0) );
119903119940
pTrigger = sqlite3HashFind(&(db->aDb[j].pSchema->trigHash), zName);
119904119941
if( pTrigger ) break;
119905119942
}
119906119943
if( !pTrigger ){
@@ -119942,11 +119979,11 @@
119942119979
assert( pTable );
119943119980
assert( pTable->pSchema==pTrigger->pSchema || iDb==1 );
119944119981
#ifndef SQLITE_OMIT_AUTHORIZATION
119945119982
{
119946119983
int code = SQLITE_DROP_TRIGGER;
119947
- const char *zDb = db->aDb[iDb].zName;
119984
+ const char *zDb = db->aDb[iDb].zDbSName;
119948119985
const char *zTab = SCHEMA_TABLE(iDb);
119949119986
if( iDb==1 ) code = SQLITE_DROP_TEMP_TRIGGER;
119950119987
if( sqlite3AuthCheck(pParse, code, pTrigger->zName, pTable->zName, zDb) ||
119951119988
sqlite3AuthCheck(pParse, SQLITE_DELETE, zTab, 0, zDb) ){
119952119989
return;
@@ -119958,11 +119995,11 @@
119958119995
*/
119959119996
assert( pTable!=0 );
119960119997
if( (v = sqlite3GetVdbe(pParse))!=0 ){
119961119998
sqlite3NestedParse(pParse,
119962119999
"DELETE FROM %Q.%s WHERE name=%Q AND type='trigger'",
119963
- db->aDb[iDb].zName, SCHEMA_TABLE(iDb), pTrigger->zName
120000
+ db->aDb[iDb].zDbSName, SCHEMA_TABLE(iDb), pTrigger->zName
119964120001
);
119965120002
sqlite3ChangeCookie(pParse, iDb);
119966120003
sqlite3VdbeAddOp4(v, OP_DropTrigger, iDb, 0, 0, pTrigger->zName, 0);
119967120004
}
119968120005
}
@@ -120061,12 +120098,14 @@
120061120098
if( pSrc ){
120062120099
assert( pSrc->nSrc>0 );
120063120100
pSrc->a[pSrc->nSrc-1].zName = sqlite3DbStrDup(db, pStep->zTarget);
120064120101
iDb = sqlite3SchemaToIndex(db, pStep->pTrig->pSchema);
120065120102
if( iDb==0 || iDb>=2 ){
120103
+ const char *zDb;
120066120104
assert( iDb<db->nDb );
120067
- pSrc->a[pSrc->nSrc-1].zDatabase = sqlite3DbStrDup(db, db->aDb[iDb].zName);
120105
+ zDb = db->aDb[iDb].zDbSName;
120106
+ pSrc->a[pSrc->nSrc-1].zDatabase = sqlite3DbStrDup(db, zDb);
120068120107
}
120069120108
}
120070120109
return pSrc;
120071120110
}
120072120111
@@ -120749,11 +120788,11 @@
120749120788
#ifndef SQLITE_OMIT_AUTHORIZATION
120750120789
{
120751120790
int rc;
120752120791
rc = sqlite3AuthCheck(pParse, SQLITE_UPDATE, pTab->zName,
120753120792
j<0 ? "ROWID" : pTab->aCol[j].zName,
120754
- db->aDb[iDb].zName);
120793
+ db->aDb[iDb].zDbSName);
120755120794
if( rc==SQLITE_DENY ){
120756120795
goto update_cleanup;
120757120796
}else if( rc==SQLITE_IGNORE ){
120758120797
aXRef[j] = -1;
120759120798
}
@@ -121351,61 +121390,56 @@
121351121390
*/
121352121391
/* #include "sqliteInt.h" */
121353121392
/* #include "vdbeInt.h" */
121354121393
121355121394
#if !defined(SQLITE_OMIT_VACUUM) && !defined(SQLITE_OMIT_ATTACH)
121356
-/*
121357
-** Finalize a prepared statement. If there was an error, store the
121358
-** text of the error message in *pzErrMsg. Return the result code.
121359
-*/
121360
-static int vacuumFinalize(sqlite3 *db, sqlite3_stmt *pStmt, char **pzErrMsg){
121361
- int rc;
121362
- rc = sqlite3VdbeFinalize((Vdbe*)pStmt);
121363
- if( rc ){
121364
- sqlite3SetString(pzErrMsg, db, sqlite3_errmsg(db));
121365
- }
121366
- return rc;
121367
-}
121368
-
121369
-/*
121370
-** Execute zSql on database db. Return an error code.
121395
+
121396
+/*
121397
+** Execute zSql on database db.
121398
+**
121399
+** If zSql returns rows, then each row will have exactly one
121400
+** column. (This will only happen if zSql begins with "SELECT".)
121401
+** Take each row of result and call execSql() again recursively.
121402
+**
121403
+** The execSqlF() routine does the same thing, except it accepts
121404
+** a format string as its third argument
121371121405
*/
121372121406
static int execSql(sqlite3 *db, char **pzErrMsg, const char *zSql){
121373121407
sqlite3_stmt *pStmt;
121374
- VVA_ONLY( int rc; )
121375
- if( !zSql ){
121376
- return SQLITE_NOMEM_BKPT;
121408
+ int rc;
121409
+
121410
+ /* printf("SQL: [%s]\n", zSql); fflush(stdout); */
121411
+ rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
121412
+ if( rc!=SQLITE_OK ) return rc;
121413
+ while( SQLITE_ROW==(rc = sqlite3_step(pStmt)) ){
121414
+ const char *zSubSql = (const char*)sqlite3_column_text(pStmt,0);
121415
+ assert( sqlite3_strnicmp(zSql,"SELECT",6)==0 );
121416
+ if( zSubSql ){
121417
+ assert( zSubSql[0]!='S' );
121418
+ rc = execSql(db, pzErrMsg, zSubSql);
121419
+ if( rc!=SQLITE_OK ) break;
121420
+ }
121377121421
}
121378
- if( SQLITE_OK!=sqlite3_prepare(db, zSql, -1, &pStmt, 0) ){
121422
+ assert( rc!=SQLITE_ROW );
121423
+ if( rc==SQLITE_DONE ) rc = SQLITE_OK;
121424
+ if( rc ){
121379121425
sqlite3SetString(pzErrMsg, db, sqlite3_errmsg(db));
121380
- return sqlite3_errcode(db);
121381
- }
121382
- VVA_ONLY( rc = ) sqlite3_step(pStmt);
121383
- assert( rc!=SQLITE_ROW || (db->flags&SQLITE_CountRows) );
121384
- return vacuumFinalize(db, pStmt, pzErrMsg);
121385
-}
121386
-
121387
-/*
121388
-** Execute zSql on database db. The statement returns exactly
121389
-** one column. Execute this as SQL on the same database.
121390
-*/
121391
-static int execExecSql(sqlite3 *db, char **pzErrMsg, const char *zSql){
121392
- sqlite3_stmt *pStmt;
121393
- int rc;
121394
-
121395
- rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
121396
- if( rc!=SQLITE_OK ) return rc;
121397
-
121398
- while( SQLITE_ROW==sqlite3_step(pStmt) ){
121399
- rc = execSql(db, pzErrMsg, (char*)sqlite3_column_text(pStmt, 0));
121400
- if( rc!=SQLITE_OK ){
121401
- vacuumFinalize(db, pStmt, pzErrMsg);
121402
- return rc;
121403
- }
121404
- }
121405
-
121406
- return vacuumFinalize(db, pStmt, pzErrMsg);
121426
+ }
121427
+ (void)sqlite3_finalize(pStmt);
121428
+ return rc;
121429
+}
121430
+static int execSqlF(sqlite3 *db, char **pzErrMsg, const char *zSql, ...){
121431
+ char *z;
121432
+ va_list ap;
121433
+ int rc;
121434
+ va_start(ap, zSql);
121435
+ z = sqlite3VMPrintf(db, zSql, ap);
121436
+ va_end(ap);
121437
+ if( z==0 ) return SQLITE_NOMEM;
121438
+ rc = execSql(db, pzErrMsg, z);
121439
+ sqlite3DbFree(db, z);
121440
+ return rc;
121407121441
}
121408121442
121409121443
/*
121410121444
** The VACUUM command is used to clean up the database,
121411121445
** collapse free space, etc. It is modelled after the VACUUM command
@@ -121434,35 +121468,36 @@
121434121468
** not work if other processes are attached to the original database.
121435121469
** And a power loss in between deleting the original and renaming the
121436121470
** transient would cause the database file to appear to be deleted
121437121471
** following reboot.
121438121472
*/
121439
-SQLITE_PRIVATE void sqlite3Vacuum(Parse *pParse){
121473
+SQLITE_PRIVATE void sqlite3Vacuum(Parse *pParse, Token *pNm){
121440121474
Vdbe *v = sqlite3GetVdbe(pParse);
121441
- if( v ){
121442
- sqlite3VdbeAddOp2(v, OP_Vacuum, 0, 0);
121443
- sqlite3VdbeUsesBtree(v, 0);
121475
+ int iDb = pNm ? sqlite3TwoPartName(pParse, pNm, pNm, &pNm) : 0;
121476
+ if( v && (iDb>=2 || iDb==0) ){
121477
+ sqlite3VdbeAddOp1(v, OP_Vacuum, iDb);
121478
+ sqlite3VdbeUsesBtree(v, iDb);
121444121479
}
121445121480
return;
121446121481
}
121447121482
121448121483
/*
121449121484
** This routine implements the OP_Vacuum opcode of the VDBE.
121450121485
*/
121451
-SQLITE_PRIVATE int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){
121486
+SQLITE_PRIVATE int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db, int iDb){
121452121487
int rc = SQLITE_OK; /* Return code from service routines */
121453121488
Btree *pMain; /* The database being vacuumed */
121454121489
Btree *pTemp; /* The temporary database we vacuum into */
121455
- char *zSql = 0; /* SQL statements */
121456121490
int saved_flags; /* Saved value of the db->flags */
121457121491
int saved_nChange; /* Saved value of db->nChange */
121458121492
int saved_nTotalChange; /* Saved value of db->nTotalChange */
121459121493
u8 saved_mTrace; /* Saved trace settings */
121460121494
Db *pDb = 0; /* Database to detach at end of vacuum */
121461121495
int isMemDb; /* True if vacuuming a :memory: database */
121462121496
int nRes; /* Bytes of reserved space at the end of each page */
121463121497
int nDb; /* Number of attached databases */
121498
+ const char *zDbMain; /* Schema name of database to vacuum */
121464121499
121465121500
if( !db->autoCommit ){
121466121501
sqlite3SetString(pzErrMsg, db, "cannot VACUUM from within a transaction");
121467121502
return SQLITE_ERROR;
121468121503
}
@@ -121476,15 +121511,17 @@
121476121511
** disable CHECK and foreign key constraints. */
121477121512
saved_flags = db->flags;
121478121513
saved_nChange = db->nChange;
121479121514
saved_nTotalChange = db->nTotalChange;
121480121515
saved_mTrace = db->mTrace;
121481
- db->flags |= SQLITE_WriteSchema | SQLITE_IgnoreChecks | SQLITE_PreferBuiltin;
121482
- db->flags &= ~(SQLITE_ForeignKeys | SQLITE_ReverseOrder);
121516
+ db->flags |= (SQLITE_WriteSchema | SQLITE_IgnoreChecks
121517
+ | SQLITE_PreferBuiltin | SQLITE_Vacuum);
121518
+ db->flags &= ~(SQLITE_ForeignKeys | SQLITE_ReverseOrder | SQLITE_CountRows);
121483121519
db->mTrace = 0;
121484121520
121485
- pMain = db->aDb[0].pBt;
121521
+ zDbMain = db->aDb[iDb].zDbSName;
121522
+ pMain = db->aDb[iDb].pBt;
121486121523
isMemDb = sqlite3PagerIsMemdb(sqlite3BtreePager(pMain));
121487121524
121488121525
/* Attach the temporary database as 'vacuum_db'. The synchronous pragma
121489121526
** can be set to 'off' for this file, as it is not recovered if a crash
121490121527
** occurs anyway. The integrity of the database is maintained by a
@@ -121498,22 +121535,16 @@
121498121535
** empty. Only the journal header is written. Apparently it takes more
121499121536
** time to parse and run the PRAGMA to turn journalling off than it does
121500121537
** to write the journal header file.
121501121538
*/
121502121539
nDb = db->nDb;
121503
- if( sqlite3TempInMemory(db) ){
121504
- zSql = "ATTACH ':memory:' AS vacuum_db;";
121505
- }else{
121506
- zSql = "ATTACH '' AS vacuum_db;";
121507
- }
121508
- rc = execSql(db, pzErrMsg, zSql);
121509
- if( db->nDb>nDb ){
121510
- pDb = &db->aDb[db->nDb-1];
121511
- assert( strcmp(pDb->zName,"vacuum_db")==0 );
121512
- }
121540
+ rc = execSql(db, pzErrMsg, "ATTACH''AS vacuum_db");
121513121541
if( rc!=SQLITE_OK ) goto end_of_vacuum;
121514
- pTemp = db->aDb[db->nDb-1].pBt;
121542
+ assert( (db->nDb-1)==nDb );
121543
+ pDb = &db->aDb[nDb];
121544
+ assert( strcmp(pDb->zDbSName,"vacuum_db")==0 );
121545
+ pTemp = pDb->pBt;
121515121546
121516121547
/* The call to execSql() to attach the temp database has left the file
121517121548
** locked (as there was more than one active statement when the transaction
121518121549
** to read the schema was concluded. Unlock it here so that this doesn't
121519121550
** cause problems for the call to BtreeSetPageSize() below. */
@@ -121530,20 +121561,19 @@
121530121561
sqlite3CodecGetKey(db, 0, (void**)&zKey, &nKey);
121531121562
if( nKey ) db->nextPagesize = 0;
121532121563
}
121533121564
#endif
121534121565
121535
- sqlite3BtreeSetCacheSize(pTemp, db->aDb[0].pSchema->cache_size);
121566
+ sqlite3BtreeSetCacheSize(pTemp, db->aDb[iDb].pSchema->cache_size);
121536121567
sqlite3BtreeSetSpillSize(pTemp, sqlite3BtreeSetSpillSize(pMain,0));
121537
- rc = execSql(db, pzErrMsg, "PRAGMA vacuum_db.synchronous=OFF");
121538
- if( rc!=SQLITE_OK ) goto end_of_vacuum;
121568
+ sqlite3BtreeSetPagerFlags(pTemp, PAGER_SYNCHRONOUS_OFF);
121539121569
121540121570
/* Begin a transaction and take an exclusive lock on the main database
121541121571
** file. This is done before the sqlite3BtreeGetPageSize(pMain) call below,
121542121572
** to ensure that we do not try to change the page-size on a WAL database.
121543121573
*/
121544
- rc = execSql(db, pzErrMsg, "BEGIN;");
121574
+ rc = execSql(db, pzErrMsg, "BEGIN");
121545121575
if( rc!=SQLITE_OK ) goto end_of_vacuum;
121546121576
rc = sqlite3BtreeBeginTrans(pMain, 2);
121547121577
if( rc!=SQLITE_OK ) goto end_of_vacuum;
121548121578
121549121579
/* Do not attempt to change the page size for a WAL database */
@@ -121566,68 +121596,52 @@
121566121596
#endif
121567121597
121568121598
/* Query the schema of the main database. Create a mirror schema
121569121599
** in the temporary database.
121570121600
*/
121571
- rc = execExecSql(db, pzErrMsg,
121572
- "SELECT 'CREATE TABLE vacuum_db.' || substr(sql,14) "
121573
- " FROM sqlite_master WHERE type='table' AND name!='sqlite_sequence'"
121574
- " AND coalesce(rootpage,1)>0"
121601
+ db->init.iDb = nDb; /* force new CREATE statements into vacuum_db */
121602
+ rc = execSqlF(db, pzErrMsg,
121603
+ "SELECT sql FROM \"%w\".sqlite_master"
121604
+ " WHERE type='table'AND name<>'sqlite_sequence'"
121605
+ " AND coalesce(rootpage,1)>0",
121606
+ zDbMain
121607
+ );
121608
+ if( rc!=SQLITE_OK ) goto end_of_vacuum;
121609
+ rc = execSqlF(db, pzErrMsg,
121610
+ "SELECT sql FROM \"%w\".sqlite_master"
121611
+ " WHERE type='index' AND length(sql)>10",
121612
+ zDbMain
121575121613
);
121576121614
if( rc!=SQLITE_OK ) goto end_of_vacuum;
121577
- rc = execExecSql(db, pzErrMsg,
121578
- "SELECT 'CREATE INDEX vacuum_db.' || substr(sql,14)"
121579
- " FROM sqlite_master WHERE sql LIKE 'CREATE INDEX %' ");
121580
- if( rc!=SQLITE_OK ) goto end_of_vacuum;
121581
- rc = execExecSql(db, pzErrMsg,
121582
- "SELECT 'CREATE UNIQUE INDEX vacuum_db.' || substr(sql,21) "
121583
- " FROM sqlite_master WHERE sql LIKE 'CREATE UNIQUE INDEX %'");
121584
- if( rc!=SQLITE_OK ) goto end_of_vacuum;
121615
+ db->init.iDb = 0;
121585121616
121586121617
/* Loop through the tables in the main database. For each, do
121587121618
** an "INSERT INTO vacuum_db.xxx SELECT * FROM main.xxx;" to copy
121588121619
** the contents to the temporary database.
121589121620
*/
121590
- assert( (db->flags & SQLITE_Vacuum)==0 );
121591
- db->flags |= SQLITE_Vacuum;
121592
- rc = execExecSql(db, pzErrMsg,
121593
- "SELECT 'INSERT INTO vacuum_db.' || quote(name) "
121594
- "|| ' SELECT * FROM main.' || quote(name) || ';'"
121595
- "FROM main.sqlite_master "
121596
- "WHERE type = 'table' AND name!='sqlite_sequence' "
121597
- " AND coalesce(rootpage,1)>0"
121621
+ rc = execSqlF(db, pzErrMsg,
121622
+ "SELECT'INSERT INTO vacuum_db.'||quote(name)"
121623
+ "||' SELECT*FROM\"%w\".'||quote(name)"
121624
+ "FROM vacuum_db.sqlite_master "
121625
+ "WHERE type='table'AND coalesce(rootpage,1)>0",
121626
+ zDbMain
121598121627
);
121599121628
assert( (db->flags & SQLITE_Vacuum)!=0 );
121600121629
db->flags &= ~SQLITE_Vacuum;
121601121630
if( rc!=SQLITE_OK ) goto end_of_vacuum;
121602
-
121603
- /* Copy over the sequence table
121604
- */
121605
- rc = execExecSql(db, pzErrMsg,
121606
- "SELECT 'DELETE FROM vacuum_db.' || quote(name) || ';' "
121607
- "FROM vacuum_db.sqlite_master WHERE name='sqlite_sequence' "
121608
- );
121609
- if( rc!=SQLITE_OK ) goto end_of_vacuum;
121610
- rc = execExecSql(db, pzErrMsg,
121611
- "SELECT 'INSERT INTO vacuum_db.' || quote(name) "
121612
- "|| ' SELECT * FROM main.' || quote(name) || ';' "
121613
- "FROM vacuum_db.sqlite_master WHERE name=='sqlite_sequence';"
121614
- );
121615
- if( rc!=SQLITE_OK ) goto end_of_vacuum;
121616
-
121617121631
121618121632
/* Copy the triggers, views, and virtual tables from the main database
121619121633
** over to the temporary database. None of these objects has any
121620121634
** associated storage, so all we have to do is copy their entries
121621121635
** from the SQLITE_MASTER table.
121622121636
*/
121623
- rc = execSql(db, pzErrMsg,
121624
- "INSERT INTO vacuum_db.sqlite_master "
121625
- " SELECT type, name, tbl_name, rootpage, sql"
121626
- " FROM main.sqlite_master"
121627
- " WHERE type='view' OR type='trigger'"
121628
- " OR (type='table' AND rootpage=0)"
121637
+ rc = execSqlF(db, pzErrMsg,
121638
+ "INSERT INTO vacuum_db.sqlite_master"
121639
+ " SELECT*FROM \"%w\".sqlite_master"
121640
+ " WHERE type IN('view','trigger')"
121641
+ " OR(type='table'AND rootpage=0)",
121642
+ zDbMain
121629121643
);
121630121644
if( rc ) goto end_of_vacuum;
121631121645
121632121646
/* At this point, there is a write transaction open on both the
121633121647
** vacuum database and the main database. Assuming no error occurs,
@@ -121677,10 +121691,11 @@
121677121691
assert( rc==SQLITE_OK );
121678121692
rc = sqlite3BtreeSetPageSize(pMain, sqlite3BtreeGetPageSize(pTemp), nRes,1);
121679121693
121680121694
end_of_vacuum:
121681121695
/* Restore the original value of db->flags */
121696
+ db->init.iDb = 0;
121682121697
db->flags = saved_flags;
121683121698
db->nChange = saved_nChange;
121684121699
db->nTotalChange = saved_nTotalChange;
121685121700
db->mTrace = saved_mTrace;
121686121701
sqlite3BtreeSetPageSize(pMain, -1, -1, 1);
@@ -122055,11 +122070,11 @@
122055122070
** sqlite_master table, has already been made by sqlite3StartTable().
122056122071
** The second call, to obtain permission to create the table, is made now.
122057122072
*/
122058122073
if( pTable->azModuleArg ){
122059122074
sqlite3AuthCheck(pParse, SQLITE_CREATE_VTABLE, pTable->zName,
122060
- pTable->azModuleArg[0], pParse->db->aDb[iDb].zName);
122075
+ pTable->azModuleArg[0], pParse->db->aDb[iDb].zDbSName);
122061122076
}
122062122077
#endif
122063122078
}
122064122079
122065122080
/*
@@ -122119,11 +122134,11 @@
122119122134
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
122120122135
sqlite3NestedParse(pParse,
122121122136
"UPDATE %Q.%s "
122122122137
"SET type='table', name=%Q, tbl_name=%Q, rootpage=0, sql=%Q "
122123122138
"WHERE rowid=#%d",
122124
- db->aDb[iDb].zName, SCHEMA_TABLE(iDb),
122139
+ db->aDb[iDb].zDbSName, SCHEMA_TABLE(iDb),
122125122140
pTab->zName,
122126122141
pTab->zName,
122127122142
zStmt,
122128122143
pParse->regRowid
122129122144
);
@@ -122229,11 +122244,11 @@
122229122244
}
122230122245
pVTable->db = db;
122231122246
pVTable->pMod = pMod;
122232122247
122233122248
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
122234
- pTab->azModuleArg[1] = db->aDb[iDb].zName;
122249
+ pTab->azModuleArg[1] = db->aDb[iDb].zDbSName;
122235122250
122236122251
/* Invoke the virtual table constructor */
122237122252
assert( &db->pVtabCtx );
122238122253
assert( xConstruct );
122239122254
sCtx.pTab = pTab;
@@ -122393,11 +122408,11 @@
122393122408
int rc = SQLITE_OK;
122394122409
Table *pTab;
122395122410
Module *pMod;
122396122411
const char *zMod;
122397122412
122398
- pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zName);
122413
+ pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zDbSName);
122399122414
assert( pTab && (pTab->tabFlags & TF_Virtual)!=0 && !pTab->pVTable );
122400122415
122401122416
/* Locate the required virtual table module */
122402122417
zMod = pTab->azModuleArg[0];
122403122418
pMod = (Module*)sqlite3HashFind(&db->aModule, zMod);
@@ -122517,11 +122532,11 @@
122517122532
*/
122518122533
SQLITE_PRIVATE int sqlite3VtabCallDestroy(sqlite3 *db, int iDb, const char *zTab){
122519122534
int rc = SQLITE_OK;
122520122535
Table *pTab;
122521122536
122522
- pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zName);
122537
+ pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zDbSName);
122523122538
if( pTab!=0 && ALWAYS(pTab->pVTable!=0) ){
122524122539
VTable *p;
122525122540
int (*xDestroy)(sqlite3_vtab *);
122526122541
for(p=pTab->pVTable; p; p=p->pNext){
122527122542
assert( p->pVtab );
@@ -125630,11 +125645,11 @@
125630125645
*/
125631125646
static int isMatchOfColumn(
125632125647
Expr *pExpr, /* Test this expression */
125633125648
unsigned char *peOp2 /* OUT: 0 for MATCH, or else an op2 value */
125634125649
){
125635
- struct Op2 {
125650
+ static const struct Op2 {
125636125651
const char *zOp;
125637125652
unsigned char eOp2;
125638125653
} aOp[] = {
125639125654
{ "match", SQLITE_INDEX_CONSTRAINT_MATCH },
125640125655
{ "glob", SQLITE_INDEX_CONSTRAINT_GLOB },
@@ -126615,17 +126630,18 @@
126615126630
** These routines walk (recursively) an expression tree and generate
126616126631
** a bitmask indicating which tables are used in that expression
126617126632
** tree.
126618126633
*/
126619126634
SQLITE_PRIVATE Bitmask sqlite3WhereExprUsage(WhereMaskSet *pMaskSet, Expr *p){
126620
- Bitmask mask = 0;
126635
+ Bitmask mask;
126621126636
if( p==0 ) return 0;
126622126637
if( p->op==TK_COLUMN ){
126623126638
mask = sqlite3WhereGetMask(pMaskSet, p->iTable);
126624126639
return mask;
126625126640
}
126626
- mask = sqlite3WhereExprUsage(pMaskSet, p->pRight);
126641
+ assert( !ExprHasProperty(p, EP_TokenOnly) );
126642
+ mask = p->pRight ? sqlite3WhereExprUsage(pMaskSet, p->pRight) : 0;
126627126643
if( p->pLeft ) mask |= sqlite3WhereExprUsage(pMaskSet, p->pLeft);
126628126644
if( ExprHasProperty(p, EP_xIsSelect) ){
126629126645
mask |= exprSelectUsage(pMaskSet, p->x.pSelect);
126630126646
}else if( p->x.pList ){
126631126647
mask |= sqlite3WhereExprListUsage(pMaskSet, p->x.pList);
@@ -131868,29 +131884,33 @@
131868131884
** N between YY_MIN_SHIFTREDUCE Shift to an arbitrary state then
131869131885
** and YY_MAX_SHIFTREDUCE reduce by rule N-YY_MIN_SHIFTREDUCE.
131870131886
**
131871131887
** N between YY_MIN_REDUCE Reduce by rule N-YY_MIN_REDUCE
131872131888
** and YY_MAX_REDUCE
131873
-
131889
+**
131874131890
** N == YY_ERROR_ACTION A syntax error has occurred.
131875131891
**
131876131892
** N == YY_ACCEPT_ACTION The parser accepts its input.
131877131893
**
131878131894
** N == YY_NO_ACTION No such action. Denotes unused
131879131895
** slots in the yy_action[] table.
131880131896
**
131881131897
** The action table is constructed as a single large table named yy_action[].
131882
-** Given state S and lookahead X, the action is computed as
131883
-**
131884
-** yy_action[ yy_shift_ofst[S] + X ]
131885
-**
131886
-** If the index value yy_shift_ofst[S]+X is out of range or if the value
131887
-** yy_lookahead[yy_shift_ofst[S]+X] is not equal to X or if yy_shift_ofst[S]
131888
-** is equal to YY_SHIFT_USE_DFLT, it means that the action is not in the table
131889
-** and that yy_default[S] should be used instead.
131890
-**
131891
-** The formula above is for computing the action when the lookahead is
131898
+** Given state S and lookahead X, the action is computed as either:
131899
+**
131900
+** (A) N = yy_action[ yy_shift_ofst[S] + X ]
131901
+** (B) N = yy_default[S]
131902
+**
131903
+** The (A) formula is preferred. The B formula is used instead if:
131904
+** (1) The yy_shift_ofst[S]+X value is out of range, or
131905
+** (2) yy_lookahead[yy_shift_ofst[S]+X] is not equal to X, or
131906
+** (3) yy_shift_ofst[S] equal YY_SHIFT_USE_DFLT.
131907
+** (Implementation note: YY_SHIFT_USE_DFLT is chosen so that
131908
+** YY_SHIFT_USE_DFLT+X will be out of range for all possible lookaheads X.
131909
+** Hence only tests (1) and (2) need to be evaluated.)
131910
+**
131911
+** The formulas above are for computing the action when the lookahead is
131892131912
** a terminal symbol. If the lookahead is a non-terminal (as occurs after
131893131913
** a reduce action) then the yy_reduce_ofst[] array is used in place of
131894131914
** the yy_shift_ofst[] array and YY_REDUCE_USE_DFLT is used in place of
131895131915
** YY_SHIFT_USE_DFLT.
131896131916
**
@@ -132211,14 +132231,14 @@
132211132231
/* 1470 */ 122, 23, 23, 64, 22, 124, 26, 26, 64, 64,
132212132232
/* 1480 */ 23, 23, 23, 23, 11, 23, 22, 26, 23, 22,
132213132233
/* 1490 */ 24, 1, 23, 22, 26, 122, 24, 23, 22, 122,
132214132234
/* 1500 */ 23, 23, 22, 122, 122, 23, 15,
132215132235
};
132216
-#define YY_SHIFT_USE_DFLT (-95)
132217
-#define YY_SHIFT_COUNT (442)
132218
-#define YY_SHIFT_MIN (-94)
132219
-#define YY_SHIFT_MAX (1491)
132236
+#define YY_SHIFT_USE_DFLT (1507)
132237
+#define YY_SHIFT_COUNT (442)
132238
+#define YY_SHIFT_MIN (-94)
132239
+#define YY_SHIFT_MAX (1491)
132220132240
static const short yy_shift_ofst[] = {
132221132241
/* 0 */ 40, 564, 869, 577, 725, 725, 725, 725, 690, -19,
132222132242
/* 10 */ 16, 16, 100, 725, 725, 725, 725, 725, 725, 725,
132223132243
/* 20 */ 841, 841, 538, 507, 684, 565, 61, 137, 172, 207,
132224132244
/* 30 */ 242, 277, 312, 347, 382, 424, 424, 424, 424, 424,
@@ -132227,16 +132247,16 @@
132227132247
/* 60 */ 725, 725, 725, 725, 725, 725, 725, 725, 725, 725,
132228132248
/* 70 */ 725, 725, 725, 725, 725, 725, 725, 725, 725, 725,
132229132249
/* 80 */ 725, 725, 725, 725, 821, 725, 725, 725, 725, 725,
132230132250
/* 90 */ 725, 725, 725, 725, 725, 725, 725, 725, 952, 711,
132231132251
/* 100 */ 711, 711, 711, 711, 766, 23, 32, 924, 637, 825,
132232
- /* 110 */ 837, 837, 924, 73, 183, -51, -95, -95, -95, 501,
132252
+ /* 110 */ 837, 837, 924, 73, 183, -51, 1507, 1507, 1507, 501,
132233132253
/* 120 */ 501, 501, 903, 903, 632, 205, 241, 924, 924, 924,
132234132254
/* 130 */ 924, 924, 924, 924, 924, 924, 924, 924, 924, 924,
132235132255
/* 140 */ 924, 924, 924, 924, 924, 924, 924, 192, 1027, 1106,
132236
- /* 150 */ 1106, 183, 176, 176, 176, 176, 176, 176, -95, -95,
132237
- /* 160 */ -95, 880, -94, -94, 578, 734, 99, 730, 769, 349,
132256
+ /* 150 */ 1106, 183, 176, 176, 176, 176, 176, 176, 1507, 1507,
132257
+ /* 160 */ 1507, 880, -94, -94, 578, 734, 99, 730, 769, 349,
132238132258
/* 170 */ 924, 924, 924, 924, 924, 924, 924, 924, 924, 924,
132239132259
/* 180 */ 924, 924, 924, 924, 924, 924, 924, 954, 954, 954,
132240132260
/* 190 */ 924, 924, 622, 924, 924, 924, -18, 924, 924, 914,
132241132261
/* 200 */ 924, 924, 924, 924, 924, 924, 924, 924, 924, 924,
132242132262
/* 210 */ 441, 1020, 1107, 1107, 1107, 569, 45, 217, 510, 423,
@@ -132246,12 +132266,12 @@
132246132266
/* 250 */ 1297, 1183, 1277, 1285, 1285, 1183, 1176, 1297, 1182, 1250,
132247132267
/* 260 */ 1176, 1176, 1297, 1311, 1176, 1297, 1176, 1297, 1311, 1234,
132248132268
/* 270 */ 1234, 1234, 1267, 1311, 1234, 1244, 1234, 1267, 1234, 1234,
132249132269
/* 280 */ 1232, 1247, 1232, 1247, 1232, 1247, 1232, 1247, 1176, 1334,
132250132270
/* 290 */ 1176, 1235, 1311, 1318, 1318, 1311, 1248, 1253, 1245, 1249,
132251
- /* 300 */ 1183, 1355, 1357, 1368, 1368, 1378, 1378, 1378, 1378, -95,
132252
- /* 310 */ -95, -95, -95, -95, -95, -95, -95, 451, 936, 816,
132271
+ /* 300 */ 1183, 1355, 1357, 1368, 1368, 1378, 1378, 1378, 1378, 1507,
132272
+ /* 310 */ 1507, 1507, 1507, 1507, 1507, 1507, 1507, 451, 936, 816,
132253132273
/* 320 */ 888, 1069, 799, 1111, 1197, 1193, 1201, 1202, 1203, 1213,
132254132274
/* 330 */ 1134, 1117, 1230, 497, 1218, 1219, 1154, 1223, 1115, 1120,
132255132275
/* 340 */ 1231, 1164, 1160, 1392, 1394, 1376, 1257, 1385, 1307, 1386,
132256132276
/* 350 */ 1383, 1388, 1292, 1282, 1303, 1294, 1395, 1293, 1403, 1419,
132257132277
/* 360 */ 1298, 1291, 1389, 1390, 1314, 1372, 1365, 1308, 1430, 1427,
@@ -133200,54 +133220,51 @@
133200133220
133201133221
if( stateno>=YY_MIN_REDUCE ) return stateno;
133202133222
assert( stateno <= YY_SHIFT_COUNT );
133203133223
do{
133204133224
i = yy_shift_ofst[stateno];
133205
- if( i==YY_SHIFT_USE_DFLT ) return yy_default[stateno];
133206133225
assert( iLookAhead!=YYNOCODE );
133207133226
i += iLookAhead;
133208133227
if( i<0 || i>=YY_ACTTAB_COUNT || yy_lookahead[i]!=iLookAhead ){
133209
- if( iLookAhead>0 ){
133210133228
#ifdef YYFALLBACK
133211
- YYCODETYPE iFallback; /* Fallback token */
133212
- if( iLookAhead<sizeof(yyFallback)/sizeof(yyFallback[0])
133213
- && (iFallback = yyFallback[iLookAhead])!=0 ){
133229
+ YYCODETYPE iFallback; /* Fallback token */
133230
+ if( iLookAhead<sizeof(yyFallback)/sizeof(yyFallback[0])
133231
+ && (iFallback = yyFallback[iLookAhead])!=0 ){
133214133232
#ifndef NDEBUG
133215
- if( yyTraceFILE ){
133216
- fprintf(yyTraceFILE, "%sFALLBACK %s => %s\n",
133217
- yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]);
133218
- }
133233
+ if( yyTraceFILE ){
133234
+ fprintf(yyTraceFILE, "%sFALLBACK %s => %s\n",
133235
+ yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]);
133236
+ }
133219133237
#endif
133220
- assert( yyFallback[iFallback]==0 ); /* Fallback loop must terminate */
133221
- iLookAhead = iFallback;
133222
- continue;
133223
- }
133238
+ assert( yyFallback[iFallback]==0 ); /* Fallback loop must terminate */
133239
+ iLookAhead = iFallback;
133240
+ continue;
133241
+ }
133224133242
#endif
133225133243
#ifdef YYWILDCARD
133226
- {
133227
- int j = i - iLookAhead + YYWILDCARD;
133228
- if(
133244
+ {
133245
+ int j = i - iLookAhead + YYWILDCARD;
133246
+ if(
133229133247
#if YY_SHIFT_MIN+YYWILDCARD<0
133230
- j>=0 &&
133248
+ j>=0 &&
133231133249
#endif
133232133250
#if YY_SHIFT_MAX+YYWILDCARD>=YY_ACTTAB_COUNT
133233
- j<YY_ACTTAB_COUNT &&
133251
+ j<YY_ACTTAB_COUNT &&
133234133252
#endif
133235
- yy_lookahead[j]==YYWILDCARD
133236
- ){
133253
+ yy_lookahead[j]==YYWILDCARD && iLookAhead>0
133254
+ ){
133237133255
#ifndef NDEBUG
133238
- if( yyTraceFILE ){
133239
- fprintf(yyTraceFILE, "%sWILDCARD %s => %s\n",
133240
- yyTracePrompt, yyTokenName[iLookAhead],
133241
- yyTokenName[YYWILDCARD]);
133242
- }
133256
+ if( yyTraceFILE ){
133257
+ fprintf(yyTraceFILE, "%sWILDCARD %s => %s\n",
133258
+ yyTracePrompt, yyTokenName[iLookAhead],
133259
+ yyTokenName[YYWILDCARD]);
133260
+ }
133243133261
#endif /* NDEBUG */
133244
- return yy_action[j];
133245
- }
133262
+ return yy_action[j];
133246133263
}
133264
+ }
133247133265
#endif /* YYWILDCARD */
133248
- }
133249133266
return yy_default[stateno];
133250133267
}else{
133251133268
return yy_action[i];
133252133269
}
133253133270
}while(1);
@@ -134679,12 +134696,14 @@
134679134696
break;
134680134697
case 213: /* cmd ::= DROP INDEX ifexists fullname */
134681134698
{sqlite3DropIndex(pParse, yymsp[0].minor.yy185, yymsp[-1].minor.yy194);}
134682134699
break;
134683134700
case 214: /* cmd ::= VACUUM */
134684
- case 215: /* cmd ::= VACUUM nm */ yytestcase(yyruleno==215);
134685
-{sqlite3Vacuum(pParse);}
134701
+{sqlite3Vacuum(pParse,0);}
134702
+ break;
134703
+ case 215: /* cmd ::= VACUUM nm */
134704
+{sqlite3Vacuum(pParse,&yymsp[0].minor.yy0);}
134686134705
break;
134687134706
case 216: /* cmd ::= PRAGMA nm dbnm */
134688134707
{sqlite3Pragma(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,0,0);}
134689134708
break;
134690134709
case 217: /* cmd ::= PRAGMA nm dbnm EQ nmnum */
@@ -136006,18 +136025,30 @@
136006136025
assert( pParse->pNewTable==0 );
136007136026
assert( pParse->pNewTrigger==0 );
136008136027
assert( pParse->nVar==0 );
136009136028
assert( pParse->nzVar==0 );
136010136029
assert( pParse->azVar==0 );
136011
- while( zSql[i]!=0 ){
136030
+ while( 1 ){
136012136031
assert( i>=0 );
136013
- pParse->sLastToken.z = &zSql[i];
136014
- pParse->sLastToken.n = sqlite3GetToken((unsigned char*)&zSql[i],&tokenType);
136015
- i += pParse->sLastToken.n;
136016
- if( i>mxSqlLen ){
136017
- pParse->rc = SQLITE_TOOBIG;
136018
- break;
136032
+ if( zSql[i]!=0 ){
136033
+ pParse->sLastToken.z = &zSql[i];
136034
+ pParse->sLastToken.n = sqlite3GetToken((u8*)&zSql[i],&tokenType);
136035
+ i += pParse->sLastToken.n;
136036
+ if( i>mxSqlLen ){
136037
+ pParse->rc = SQLITE_TOOBIG;
136038
+ break;
136039
+ }
136040
+ }else{
136041
+ /* Upon reaching the end of input, call the parser two more times
136042
+ ** with tokens TK_SEMI and 0, in that order. */
136043
+ if( lastTokenParsed==TK_SEMI ){
136044
+ tokenType = 0;
136045
+ }else if( lastTokenParsed==0 ){
136046
+ break;
136047
+ }else{
136048
+ tokenType = TK_SEMI;
136049
+ }
136019136050
}
136020136051
if( tokenType>=TK_SPACE ){
136021136052
assert( tokenType==TK_SPACE || tokenType==TK_ILLEGAL );
136022136053
if( db->u1.isInterrupted ){
136023136054
pParse->rc = SQLITE_INTERRUPT;
@@ -136034,19 +136065,10 @@
136034136065
if( pParse->rc!=SQLITE_OK || db->mallocFailed ) break;
136035136066
}
136036136067
}
136037136068
assert( nErr==0 );
136038136069
pParse->zTail = &zSql[i];
136039
- if( pParse->rc==SQLITE_OK && db->mallocFailed==0 ){
136040
- assert( zSql[i]==0 );
136041
- if( lastTokenParsed!=TK_SEMI ){
136042
- sqlite3Parser(pEngine, TK_SEMI, pParse->sLastToken, pParse);
136043
- }
136044
- if( pParse->rc==SQLITE_OK && db->mallocFailed==0 ){
136045
- sqlite3Parser(pEngine, 0, pParse->sLastToken, pParse);
136046
- }
136047
- }
136048136070
#ifdef YYTRACKMAXSTACKDEPTH
136049136071
sqlite3_mutex_enter(sqlite3MallocMutex());
136050136072
sqlite3StatusHighwater(SQLITE_STATUS_PARSER_STACK,
136051136073
sqlite3ParserStackPeak(pEngine)
136052136074
);
@@ -137282,10 +137304,15 @@
137282137304
SQLITE_API int SQLITE_CDECL sqlite3_db_config(sqlite3 *db, int op, ...){
137283137305
va_list ap;
137284137306
int rc;
137285137307
va_start(ap, op);
137286137308
switch( op ){
137309
+ case SQLITE_DBCONFIG_MAINDBNAME: {
137310
+ db->aDb[0].zDbSName = va_arg(ap,char*);
137311
+ rc = SQLITE_OK;
137312
+ break;
137313
+ }
137287137314
case SQLITE_DBCONFIG_LOOKASIDE: {
137288137315
void *pBuf = va_arg(ap, void*); /* IMP: R-26835-10964 */
137289137316
int sz = va_arg(ap, int); /* IMP: R-47871-25994 */
137290137317
int cnt = va_arg(ap, int); /* IMP: R-04460-53386 */
137291137318
rc = setupLookaside(db, pBuf, sz, cnt);
@@ -139425,13 +139452,13 @@
139425139452
db->aDb[1].pSchema = sqlite3SchemaGet(db, 0);
139426139453
139427139454
/* The default safety_level for the main database is FULL; for the temp
139428139455
** database it is OFF. This matches the pager layer defaults.
139429139456
*/
139430
- db->aDb[0].zName = "main";
139457
+ db->aDb[0].zDbSName = "main";
139431139458
db->aDb[0].safety_level = SQLITE_DEFAULT_SYNCHRONOUS+1;
139432
- db->aDb[1].zName = "temp";
139459
+ db->aDb[1].zDbSName = "temp";
139433139460
db->aDb[1].safety_level = PAGER_SYNCHRONOUS_OFF;
139434139461
139435139462
db->magic = SQLITE_MAGIC_OPEN;
139436139463
if( db->mallocFailed ){
139437139464
goto opendb_out;
@@ -140388,11 +140415,11 @@
140388140415
*/
140389140416
SQLITE_PRIVATE Btree *sqlite3DbNameToBtree(sqlite3 *db, const char *zDbName){
140390140417
int i;
140391140418
for(i=0; i<db->nDb; i++){
140392140419
if( db->aDb[i].pBt
140393
- && (zDbName==0 || sqlite3StrICmp(zDbName, db->aDb[i].zName)==0)
140420
+ && (zDbName==0 || sqlite3StrICmp(zDbName, db->aDb[i].zDbSName)==0)
140394140421
){
140395140422
return db->aDb[i].pBt;
140396140423
}
140397140424
}
140398140425
return 0;
@@ -164754,19 +164781,25 @@
164754164781
/*
164755164782
** Open an RBU handle to perform an RBU vacuum on database file zTarget.
164756164783
** An RBU vacuum is similar to SQLite's built-in VACUUM command, except
164757164784
** that it can be suspended and resumed like an RBU update.
164758164785
**
164759
-** The second argument to this function, which may not be NULL, identifies
164760
-** a database in which to store the state of the RBU vacuum operation if
164761
-** it is suspended. The first time sqlite3rbu_vacuum() is called, to start
164762
-** an RBU vacuum operation, the state database should either not exist or
164763
-** be empty (contain no tables). If an RBU vacuum is suspended by calling
164786
+** The second argument to this function identifies a database in which
164787
+** to store the state of the RBU vacuum operation if it is suspended. The
164788
+** first time sqlite3rbu_vacuum() is called, to start an RBU vacuum
164789
+** operation, the state database should either not exist or be empty
164790
+** (contain no tables). If an RBU vacuum is suspended by calling
164764164791
** sqlite3rbu_close() on the RBU handle before sqlite3rbu_step() has
164765164792
** returned SQLITE_DONE, the vacuum state is stored in the state database.
164766164793
** The vacuum can be resumed by calling this function to open a new RBU
164767164794
** handle specifying the same target and state databases.
164795
+**
164796
+** If the second argument passed to this function is NULL, then the
164797
+** name of the state database is "<database>-vacuum", where <database>
164798
+** is the name of the target database file. In this case, on UNIX, if the
164799
+** state database is not already present in the file-system, it is created
164800
+** with the same permissions as the target db is made.
164768164801
**
164769164802
** This function does not delete the state database after an RBU vacuum
164770164803
** is completed, even if it created it. However, if the call to
164771164804
** sqlite3rbu_close() returns any value other than SQLITE_OK, the contents
164772164805
** of the state tables within the state database are zeroed. This way,
@@ -167255,19 +167288,22 @@
167255167288
/*
167256167289
** Open the database handle and attach the RBU database as "rbu". If an
167257167290
** error occurs, leave an error code and message in the RBU handle.
167258167291
*/
167259167292
static void rbuOpenDatabase(sqlite3rbu *p){
167260
- assert( p->rc==SQLITE_OK );
167261
- assert( p->dbMain==0 && p->dbRbu==0 );
167262
- assert( rbuIsVacuum(p) || p->zTarget!=0 );
167293
+ assert( p->rc || (p->dbMain==0 && p->dbRbu==0) );
167294
+ assert( p->rc || rbuIsVacuum(p) || p->zTarget!=0 );
167263167295
167264167296
/* Open the RBU database */
167265167297
p->dbRbu = rbuOpenDbhandle(p, p->zRbu, 1);
167266167298
167267167299
if( p->rc==SQLITE_OK && rbuIsVacuum(p) ){
167268167300
sqlite3_file_control(p->dbRbu, "main", SQLITE_FCNTL_RBUCNT, (void*)p);
167301
+ if( p->zState==0 ){
167302
+ const char *zFile = sqlite3_db_filename(p->dbRbu, "main");
167303
+ p->zState = rbuMPrintf(p, "file://%s-vacuum?modeof=%s", zFile, zFile);
167304
+ }
167269167305
}
167270167306
167271167307
/* If using separate RBU and state databases, attach the state database to
167272167308
** the RBU db handle now. */
167273167309
if( p->zState ){
@@ -168398,12 +168434,11 @@
168398168434
const char *zState
168399168435
){
168400168436
sqlite3rbu *p;
168401168437
size_t nTarget = zTarget ? strlen(zTarget) : 0;
168402168438
size_t nRbu = strlen(zRbu);
168403
- size_t nState = zState ? strlen(zState) : 0;
168404
- size_t nByte = sizeof(sqlite3rbu) + nTarget+1 + nRbu+1+ nState+1;
168439
+ size_t nByte = sizeof(sqlite3rbu) + nTarget+1 + nRbu+1;
168405168440
168406168441
p = (sqlite3rbu*)sqlite3_malloc64(nByte);
168407168442
if( p ){
168408168443
RbuState *pState = 0;
168409168444
@@ -168421,12 +168456,11 @@
168421168456
}
168422168457
p->zRbu = pCsr;
168423168458
memcpy(p->zRbu, zRbu, nRbu+1);
168424168459
pCsr += nRbu+1;
168425168460
if( zState ){
168426
- p->zState = pCsr;
168427
- memcpy(p->zState, zState, nState+1);
168461
+ p->zState = rbuMPrintf(p, "%s", zState);
168428168462
}
168429168463
rbuOpenDatabase(p);
168430168464
}
168431168465
168432168466
if( p->rc==SQLITE_OK ){
@@ -168531,19 +168565,34 @@
168531168565
rbuFreeState(pState);
168532168566
}
168533168567
168534168568
return p;
168535168569
}
168570
+
168571
+/*
168572
+** Allocate and return an RBU handle with all fields zeroed except for the
168573
+** error code, which is set to SQLITE_MISUSE.
168574
+*/
168575
+static sqlite3rbu *rbuMisuseError(void){
168576
+ sqlite3rbu *pRet;
168577
+ pRet = sqlite3_malloc64(sizeof(sqlite3rbu));
168578
+ if( pRet ){
168579
+ memset(pRet, 0, sizeof(sqlite3rbu));
168580
+ pRet->rc = SQLITE_MISUSE;
168581
+ }
168582
+ return pRet;
168583
+}
168536168584
168537168585
/*
168538168586
** Open and return a new RBU handle.
168539168587
*/
168540168588
SQLITE_API sqlite3rbu *SQLITE_STDCALL sqlite3rbu_open(
168541168589
const char *zTarget,
168542168590
const char *zRbu,
168543168591
const char *zState
168544168592
){
168593
+ if( zTarget==0 || zRbu==0 ){ return rbuMisuseError(); }
168545168594
/* TODO: Check that zTarget and zRbu are non-NULL */
168546168595
return openRbuHandle(zTarget, zRbu, zState);
168547168596
}
168548168597
168549168598
/*
@@ -168551,10 +168600,11 @@
168551168600
*/
168552168601
SQLITE_API sqlite3rbu *SQLITE_STDCALL sqlite3rbu_vacuum(
168553168602
const char *zTarget,
168554168603
const char *zState
168555168604
){
168605
+ if( zTarget==0 ){ return rbuMisuseError(); }
168556168606
/* TODO: Check that both arguments are non-NULL */
168557168607
return openRbuHandle(0, zTarget, zState);
168558168608
}
168559168609
168560168610
/*
@@ -168628,10 +168678,11 @@
168628168678
sqlite3_free(p->aFrame);
168629168679
168630168680
rbuEditErrmsg(p);
168631168681
rc = p->rc;
168632168682
*pzErrmsg = p->zErrmsg;
168683
+ sqlite3_free(p->zState);
168633168684
sqlite3_free(p);
168634168685
}else{
168635168686
rc = SQLITE_NOMEM;
168636168687
*pzErrmsg = 0;
168637168688
}
@@ -170239,11 +170290,11 @@
170239170290
zSql = sqlite3_mprintf(
170240170291
"SELECT 'sqlite_master' AS name, 1 AS rootpage, 'table' AS type"
170241170292
" UNION ALL "
170242170293
"SELECT name, rootpage, type"
170243170294
" FROM \"%w\".%s WHERE rootpage!=0"
170244
- " ORDER BY name", pTab->db->aDb[pCsr->iDb].zName, zMaster);
170295
+ " ORDER BY name", pTab->db->aDb[pCsr->iDb].zDbSName, zMaster);
170245170296
if( zSql==0 ){
170246170297
return SQLITE_NOMEM_BKPT;
170247170298
}else{
170248170299
rc = sqlite3_prepare_v2(pTab->db, zSql, -1, &pCsr->pStmt, 0);
170249170300
sqlite3_free(zSql);
@@ -170293,11 +170344,11 @@
170293170344
sqlite3_result_int(ctx, pCsr->szPage);
170294170345
break;
170295170346
default: { /* schema */
170296170347
sqlite3 *db = sqlite3_context_db_handle(ctx);
170297170348
int iDb = pCsr->iDb;
170298
- sqlite3_result_text(ctx, db->aDb[iDb].zName, -1, SQLITE_STATIC);
170349
+ sqlite3_result_text(ctx, db->aDb[iDb].zDbSName, -1, SQLITE_STATIC);
170299170350
break;
170300170351
}
170301170352
}
170302170353
return SQLITE_OK;
170303170354
}
@@ -178530,10 +178581,11 @@
178530178581
static void sqlite3Fts5ParseNearsetFree(Fts5ExprNearset*);
178531178582
static void sqlite3Fts5ParseNodeFree(Fts5ExprNode*);
178532178583
178533178584
static void sqlite3Fts5ParseSetDistance(Fts5Parse*, Fts5ExprNearset*, Fts5Token*);
178534178585
static void sqlite3Fts5ParseSetColset(Fts5Parse*, Fts5ExprNearset*, Fts5Colset*);
178586
+static Fts5Colset *sqlite3Fts5ParseColsetInvert(Fts5Parse*, Fts5Colset*);
178535178587
static void sqlite3Fts5ParseFinished(Fts5Parse *pParse, Fts5ExprNode *p);
178536178588
static void sqlite3Fts5ParseNear(Fts5Parse *pParse, Fts5Token*);
178537178589
178538178590
/*
178539178591
** End of interface to code in fts5_expr.c.
@@ -178587,16 +178639,17 @@
178587178639
#define FTS5_NOT 3
178588178640
#define FTS5_TERM 4
178589178641
#define FTS5_COLON 5
178590178642
#define FTS5_LP 6
178591178643
#define FTS5_RP 7
178592
-#define FTS5_LCP 8
178593
-#define FTS5_RCP 9
178594
-#define FTS5_STRING 10
178595
-#define FTS5_COMMA 11
178596
-#define FTS5_PLUS 12
178597
-#define FTS5_STAR 13
178644
+#define FTS5_MINUS 8
178645
+#define FTS5_LCP 9
178646
+#define FTS5_RCP 10
178647
+#define FTS5_STRING 11
178648
+#define FTS5_COMMA 12
178649
+#define FTS5_PLUS 13
178650
+#define FTS5_STAR 14
178598178651
178599178652
/*
178600178653
** 2000-05-29
178601178654
**
178602178655
** The author disclaims copyright to this source code. In place of
@@ -178706,39 +178759,39 @@
178706178759
#ifndef INTERFACE
178707178760
# define INTERFACE 1
178708178761
#endif
178709178762
/************* Begin control #defines *****************************************/
178710178763
#define fts5YYCODETYPE unsigned char
178711
-#define fts5YYNOCODE 27
178764
+#define fts5YYNOCODE 28
178712178765
#define fts5YYACTIONTYPE unsigned char
178713178766
#define sqlite3Fts5ParserFTS5TOKENTYPE Fts5Token
178714178767
typedef union {
178715178768
int fts5yyinit;
178716178769
sqlite3Fts5ParserFTS5TOKENTYPE fts5yy0;
178717
- Fts5Colset* fts5yy3;
178718
- Fts5ExprPhrase* fts5yy11;
178719
- Fts5ExprNode* fts5yy18;
178720
- int fts5yy20;
178721
- Fts5ExprNearset* fts5yy26;
178770
+ int fts5yy4;
178771
+ Fts5Colset* fts5yy11;
178772
+ Fts5ExprNode* fts5yy24;
178773
+ Fts5ExprNearset* fts5yy46;
178774
+ Fts5ExprPhrase* fts5yy53;
178722178775
} fts5YYMINORTYPE;
178723178776
#ifndef fts5YYSTACKDEPTH
178724178777
#define fts5YYSTACKDEPTH 100
178725178778
#endif
178726178779
#define sqlite3Fts5ParserARG_SDECL Fts5Parse *pParse;
178727178780
#define sqlite3Fts5ParserARG_PDECL ,Fts5Parse *pParse
178728178781
#define sqlite3Fts5ParserARG_FETCH Fts5Parse *pParse = fts5yypParser->pParse
178729178782
#define sqlite3Fts5ParserARG_STORE fts5yypParser->pParse = pParse
178730
-#define fts5YYNSTATE 26
178731
-#define fts5YYNRULE 24
178732
-#define fts5YY_MAX_SHIFT 25
178733
-#define fts5YY_MIN_SHIFTREDUCE 40
178734
-#define fts5YY_MAX_SHIFTREDUCE 63
178735
-#define fts5YY_MIN_REDUCE 64
178736
-#define fts5YY_MAX_REDUCE 87
178737
-#define fts5YY_ERROR_ACTION 88
178738
-#define fts5YY_ACCEPT_ACTION 89
178739
-#define fts5YY_NO_ACTION 90
178783
+#define fts5YYNSTATE 29
178784
+#define fts5YYNRULE 26
178785
+#define fts5YY_MAX_SHIFT 28
178786
+#define fts5YY_MIN_SHIFTREDUCE 45
178787
+#define fts5YY_MAX_SHIFTREDUCE 70
178788
+#define fts5YY_MIN_REDUCE 71
178789
+#define fts5YY_MAX_REDUCE 96
178790
+#define fts5YY_ERROR_ACTION 97
178791
+#define fts5YY_ACCEPT_ACTION 98
178792
+#define fts5YY_NO_ACTION 99
178740178793
/************* End control #defines *******************************************/
178741178794
178742178795
/* Define the fts5yytestcase() macro to be a no-op if is not already defined
178743178796
** otherwise.
178744178797
**
@@ -178766,29 +178819,33 @@
178766178819
** N between fts5YY_MIN_SHIFTREDUCE Shift to an arbitrary state then
178767178820
** and fts5YY_MAX_SHIFTREDUCE reduce by rule N-fts5YY_MIN_SHIFTREDUCE.
178768178821
**
178769178822
** N between fts5YY_MIN_REDUCE Reduce by rule N-fts5YY_MIN_REDUCE
178770178823
** and fts5YY_MAX_REDUCE
178771
-
178824
+**
178772178825
** N == fts5YY_ERROR_ACTION A syntax error has occurred.
178773178826
**
178774178827
** N == fts5YY_ACCEPT_ACTION The parser accepts its input.
178775178828
**
178776178829
** N == fts5YY_NO_ACTION No such action. Denotes unused
178777178830
** slots in the fts5yy_action[] table.
178778178831
**
178779178832
** The action table is constructed as a single large table named fts5yy_action[].
178780
-** Given state S and lookahead X, the action is computed as
178781
-**
178782
-** fts5yy_action[ fts5yy_shift_ofst[S] + X ]
178783
-**
178784
-** If the index value fts5yy_shift_ofst[S]+X is out of range or if the value
178785
-** fts5yy_lookahead[fts5yy_shift_ofst[S]+X] is not equal to X or if fts5yy_shift_ofst[S]
178786
-** is equal to fts5YY_SHIFT_USE_DFLT, it means that the action is not in the table
178787
-** and that fts5yy_default[S] should be used instead.
178788
-**
178789
-** The formula above is for computing the action when the lookahead is
178833
+** Given state S and lookahead X, the action is computed as either:
178834
+**
178835
+** (A) N = fts5yy_action[ fts5yy_shift_ofst[S] + X ]
178836
+** (B) N = fts5yy_default[S]
178837
+**
178838
+** The (A) formula is preferred. The B formula is used instead if:
178839
+** (1) The fts5yy_shift_ofst[S]+X value is out of range, or
178840
+** (2) fts5yy_lookahead[fts5yy_shift_ofst[S]+X] is not equal to X, or
178841
+** (3) fts5yy_shift_ofst[S] equal fts5YY_SHIFT_USE_DFLT.
178842
+** (Implementation note: fts5YY_SHIFT_USE_DFLT is chosen so that
178843
+** fts5YY_SHIFT_USE_DFLT+X will be out of range for all possible lookaheads X.
178844
+** Hence only tests (1) and (2) need to be evaluated.)
178845
+**
178846
+** The formulas above are for computing the action when the lookahead is
178790178847
** a terminal symbol. If the lookahead is a non-terminal (as occurs after
178791178848
** a reduce action) then the fts5yy_reduce_ofst[] array is used in place of
178792178849
** the fts5yy_shift_ofst[] array and fts5YY_REDUCE_USE_DFLT is used in place of
178793178850
** fts5YY_SHIFT_USE_DFLT.
178794178851
**
@@ -178802,52 +178859,54 @@
178802178859
** fts5yy_reduce_ofst[] For each state, the offset into fts5yy_action for
178803178860
** shifting non-terminals after a reduce.
178804178861
** fts5yy_default[] Default action for each state.
178805178862
**
178806178863
*********** Begin parsing tables **********************************************/
178807
-#define fts5YY_ACTTAB_COUNT (78)
178864
+#define fts5YY_ACTTAB_COUNT (85)
178808178865
static const fts5YYACTIONTYPE fts5yy_action[] = {
178809
- /* 0 */ 89, 15, 46, 5, 48, 24, 12, 19, 23, 14,
178810
- /* 10 */ 46, 5, 48, 24, 20, 21, 23, 43, 46, 5,
178811
- /* 20 */ 48, 24, 6, 18, 23, 17, 46, 5, 48, 24,
178812
- /* 30 */ 75, 7, 23, 25, 46, 5, 48, 24, 62, 47,
178813
- /* 40 */ 23, 48, 24, 7, 11, 23, 9, 3, 4, 2,
178814
- /* 50 */ 62, 50, 52, 44, 64, 3, 4, 2, 49, 4,
178815
- /* 60 */ 2, 1, 23, 11, 16, 9, 12, 2, 10, 61,
178816
- /* 70 */ 53, 59, 62, 60, 22, 13, 55, 8,
178866
+ /* 0 */ 98, 16, 51, 5, 53, 27, 83, 7, 26, 15,
178867
+ /* 10 */ 51, 5, 53, 27, 13, 69, 26, 48, 51, 5,
178868
+ /* 20 */ 53, 27, 19, 11, 26, 9, 20, 51, 5, 53,
178869
+ /* 30 */ 27, 13, 22, 26, 28, 51, 5, 53, 27, 68,
178870
+ /* 40 */ 1, 26, 19, 11, 17, 9, 52, 10, 53, 27,
178871
+ /* 50 */ 23, 24, 26, 54, 3, 4, 2, 26, 6, 21,
178872
+ /* 60 */ 49, 71, 3, 4, 2, 7, 56, 59, 55, 59,
178873
+ /* 70 */ 4, 2, 12, 69, 58, 60, 18, 67, 62, 69,
178874
+ /* 80 */ 25, 66, 8, 14, 2,
178817178875
};
178818178876
static const fts5YYCODETYPE fts5yy_lookahead[] = {
178819
- /* 0 */ 15, 16, 17, 18, 19, 20, 10, 11, 23, 16,
178820
- /* 10 */ 17, 18, 19, 20, 23, 24, 23, 16, 17, 18,
178821
- /* 20 */ 19, 20, 22, 23, 23, 16, 17, 18, 19, 20,
178822
- /* 30 */ 5, 6, 23, 16, 17, 18, 19, 20, 13, 17,
178823
- /* 40 */ 23, 19, 20, 6, 8, 23, 10, 1, 2, 3,
178824
- /* 50 */ 13, 9, 10, 7, 0, 1, 2, 3, 19, 2,
178825
- /* 60 */ 3, 6, 23, 8, 21, 10, 10, 3, 10, 25,
178826
- /* 70 */ 10, 10, 13, 25, 12, 10, 7, 5,
178827
-};
178828
-#define fts5YY_SHIFT_USE_DFLT (-5)
178829
-#define fts5YY_SHIFT_COUNT (25)
178830
-#define fts5YY_SHIFT_MIN (-4)
178831
-#define fts5YY_SHIFT_MAX (72)
178832
-static const signed char fts5yy_shift_ofst[] = {
178833
- /* 0 */ 55, 55, 55, 55, 55, 36, -4, 56, 58, 25,
178834
- /* 10 */ 37, 60, 59, 59, 46, 54, 42, 57, 62, 61,
178835
- /* 20 */ 62, 69, 65, 62, 72, 64,
178836
-};
178837
-#define fts5YY_REDUCE_USE_DFLT (-16)
178838
-#define fts5YY_REDUCE_COUNT (13)
178839
-#define fts5YY_REDUCE_MIN (-15)
178840
-#define fts5YY_REDUCE_MAX (48)
178877
+ /* 0 */ 16, 17, 18, 19, 20, 21, 5, 6, 24, 17,
178878
+ /* 10 */ 18, 19, 20, 21, 11, 14, 24, 17, 18, 19,
178879
+ /* 20 */ 20, 21, 8, 9, 24, 11, 17, 18, 19, 20,
178880
+ /* 30 */ 21, 11, 12, 24, 17, 18, 19, 20, 21, 26,
178881
+ /* 40 */ 6, 24, 8, 9, 22, 11, 18, 11, 20, 21,
178882
+ /* 50 */ 24, 25, 24, 20, 1, 2, 3, 24, 23, 24,
178883
+ /* 60 */ 7, 0, 1, 2, 3, 6, 10, 11, 10, 11,
178884
+ /* 70 */ 2, 3, 9, 14, 11, 11, 22, 26, 7, 14,
178885
+ /* 80 */ 13, 11, 5, 11, 3,
178886
+};
178887
+#define fts5YY_SHIFT_USE_DFLT (85)
178888
+#define fts5YY_SHIFT_COUNT (28)
178889
+#define fts5YY_SHIFT_MIN (0)
178890
+#define fts5YY_SHIFT_MAX (81)
178891
+static const unsigned char fts5yy_shift_ofst[] = {
178892
+ /* 0 */ 34, 34, 34, 34, 34, 14, 20, 3, 36, 1,
178893
+ /* 10 */ 59, 64, 64, 65, 65, 53, 61, 56, 58, 63,
178894
+ /* 20 */ 68, 67, 70, 67, 71, 72, 67, 77, 81,
178895
+};
178896
+#define fts5YY_REDUCE_USE_DFLT (-17)
178897
+#define fts5YY_REDUCE_COUNT (14)
178898
+#define fts5YY_REDUCE_MIN (-16)
178899
+#define fts5YY_REDUCE_MAX (54)
178841178900
static const signed char fts5yy_reduce_ofst[] = {
178842
- /* 0 */ -15, -7, 1, 9, 17, 22, -9, 0, 39, 44,
178843
- /* 10 */ 44, 43, 44, 48,
178901
+ /* 0 */ -16, -8, 0, 9, 17, 28, 26, 35, 33, 13,
178902
+ /* 10 */ 13, 22, 54, 13, 51,
178844178903
};
178845178904
static const fts5YYACTIONTYPE fts5yy_default[] = {
178846
- /* 0 */ 88, 88, 88, 88, 88, 69, 82, 88, 88, 87,
178847
- /* 10 */ 87, 88, 87, 87, 88, 88, 88, 66, 80, 88,
178848
- /* 20 */ 81, 88, 88, 78, 88, 65,
178905
+ /* 0 */ 97, 97, 97, 97, 97, 76, 91, 97, 97, 96,
178906
+ /* 10 */ 96, 97, 97, 96, 96, 97, 97, 97, 97, 97,
178907
+ /* 20 */ 73, 89, 97, 90, 97, 97, 87, 97, 72,
178849178908
};
178850178909
/********** End of lemon-generated parsing tables *****************************/
178851178910
178852178911
/* The next table maps tokens (terminal symbols) into fallback tokens.
178853178912
** If a construct like the following:
@@ -178950,15 +179009,15 @@
178950179009
/* For tracing shifts, the names of all terminals and nonterminals
178951179010
** are required. The following table supplies these names */
178952179011
static const char *const fts5yyTokenName[] = {
178953179012
"$", "OR", "AND", "NOT",
178954179013
"TERM", "COLON", "LP", "RP",
178955
- "LCP", "RCP", "STRING", "COMMA",
178956
- "PLUS", "STAR", "error", "input",
178957
- "expr", "cnearset", "exprlist", "nearset",
178958
- "colset", "colsetlist", "nearphrases", "phrase",
178959
- "neardist_opt", "star_opt",
179014
+ "MINUS", "LCP", "RCP", "STRING",
179015
+ "COMMA", "PLUS", "STAR", "error",
179016
+ "input", "expr", "cnearset", "exprlist",
179017
+ "nearset", "colset", "colsetlist", "nearphrases",
179018
+ "phrase", "neardist_opt", "star_opt",
178960179019
};
178961179020
#endif /* NDEBUG */
178962179021
178963179022
#ifndef NDEBUG
178964179023
/* For tracing reduce actions, the names of all rules are required.
@@ -178972,24 +179031,26 @@
178972179031
/* 5 */ "expr ::= exprlist",
178973179032
/* 6 */ "exprlist ::= cnearset",
178974179033
/* 7 */ "exprlist ::= exprlist cnearset",
178975179034
/* 8 */ "cnearset ::= nearset",
178976179035
/* 9 */ "cnearset ::= colset COLON nearset",
178977
- /* 10 */ "colset ::= LCP colsetlist RCP",
178978
- /* 11 */ "colset ::= STRING",
178979
- /* 12 */ "colsetlist ::= colsetlist STRING",
178980
- /* 13 */ "colsetlist ::= STRING",
178981
- /* 14 */ "nearset ::= phrase",
178982
- /* 15 */ "nearset ::= STRING LP nearphrases neardist_opt RP",
178983
- /* 16 */ "nearphrases ::= phrase",
178984
- /* 17 */ "nearphrases ::= nearphrases phrase",
178985
- /* 18 */ "neardist_opt ::=",
178986
- /* 19 */ "neardist_opt ::= COMMA STRING",
178987
- /* 20 */ "phrase ::= phrase PLUS STRING star_opt",
178988
- /* 21 */ "phrase ::= STRING star_opt",
178989
- /* 22 */ "star_opt ::= STAR",
178990
- /* 23 */ "star_opt ::=",
179036
+ /* 10 */ "colset ::= MINUS LCP colsetlist RCP",
179037
+ /* 11 */ "colset ::= LCP colsetlist RCP",
179038
+ /* 12 */ "colset ::= STRING",
179039
+ /* 13 */ "colset ::= MINUS STRING",
179040
+ /* 14 */ "colsetlist ::= colsetlist STRING",
179041
+ /* 15 */ "colsetlist ::= STRING",
179042
+ /* 16 */ "nearset ::= phrase",
179043
+ /* 17 */ "nearset ::= STRING LP nearphrases neardist_opt RP",
179044
+ /* 18 */ "nearphrases ::= phrase",
179045
+ /* 19 */ "nearphrases ::= nearphrases phrase",
179046
+ /* 20 */ "neardist_opt ::=",
179047
+ /* 21 */ "neardist_opt ::= COMMA STRING",
179048
+ /* 22 */ "phrase ::= phrase PLUS STRING star_opt",
179049
+ /* 23 */ "phrase ::= STRING star_opt",
179050
+ /* 24 */ "star_opt ::= STAR",
179051
+ /* 25 */ "star_opt ::=",
178991179052
};
178992179053
#endif /* NDEBUG */
178993179054
178994179055
178995179056
#if fts5YYSTACKDEPTH<=0
@@ -179095,37 +179156,37 @@
179095179156
** Note: during a reduce, the only symbols destroyed are those
179096179157
** which appear on the RHS of the rule, but which are *not* used
179097179158
** inside the C code.
179098179159
*/
179099179160
/********* Begin destructor definitions ***************************************/
179100
- case 15: /* input */
179161
+ case 16: /* input */
179101179162
{
179102179163
(void)pParse;
179103179164
}
179104179165
break;
179105
- case 16: /* expr */
179106
- case 17: /* cnearset */
179107
- case 18: /* exprlist */
179108
-{
179109
- sqlite3Fts5ParseNodeFree((fts5yypminor->fts5yy18));
179110
-}
179111
- break;
179112
- case 19: /* nearset */
179113
- case 22: /* nearphrases */
179114
-{
179115
- sqlite3Fts5ParseNearsetFree((fts5yypminor->fts5yy26));
179116
-}
179117
- break;
179118
- case 20: /* colset */
179119
- case 21: /* colsetlist */
179120
-{
179121
- sqlite3_free((fts5yypminor->fts5yy3));
179122
-}
179123
- break;
179124
- case 23: /* phrase */
179125
-{
179126
- sqlite3Fts5ParsePhraseFree((fts5yypminor->fts5yy11));
179166
+ case 17: /* expr */
179167
+ case 18: /* cnearset */
179168
+ case 19: /* exprlist */
179169
+{
179170
+ sqlite3Fts5ParseNodeFree((fts5yypminor->fts5yy24));
179171
+}
179172
+ break;
179173
+ case 20: /* nearset */
179174
+ case 23: /* nearphrases */
179175
+{
179176
+ sqlite3Fts5ParseNearsetFree((fts5yypminor->fts5yy46));
179177
+}
179178
+ break;
179179
+ case 21: /* colset */
179180
+ case 22: /* colsetlist */
179181
+{
179182
+ sqlite3_free((fts5yypminor->fts5yy11));
179183
+}
179184
+ break;
179185
+ case 24: /* phrase */
179186
+{
179187
+ sqlite3Fts5ParsePhraseFree((fts5yypminor->fts5yy53));
179127179188
}
179128179189
break;
179129179190
/********* End destructor definitions *****************************************/
179130179191
default: break; /* If no destructor action specified: do nothing */
179131179192
}
@@ -179198,54 +179259,51 @@
179198179259
179199179260
if( stateno>=fts5YY_MIN_REDUCE ) return stateno;
179200179261
assert( stateno <= fts5YY_SHIFT_COUNT );
179201179262
do{
179202179263
i = fts5yy_shift_ofst[stateno];
179203
- if( i==fts5YY_SHIFT_USE_DFLT ) return fts5yy_default[stateno];
179204179264
assert( iLookAhead!=fts5YYNOCODE );
179205179265
i += iLookAhead;
179206179266
if( i<0 || i>=fts5YY_ACTTAB_COUNT || fts5yy_lookahead[i]!=iLookAhead ){
179207
- if( iLookAhead>0 ){
179208179267
#ifdef fts5YYFALLBACK
179209
- fts5YYCODETYPE iFallback; /* Fallback token */
179210
- if( iLookAhead<sizeof(fts5yyFallback)/sizeof(fts5yyFallback[0])
179211
- && (iFallback = fts5yyFallback[iLookAhead])!=0 ){
179268
+ fts5YYCODETYPE iFallback; /* Fallback token */
179269
+ if( iLookAhead<sizeof(fts5yyFallback)/sizeof(fts5yyFallback[0])
179270
+ && (iFallback = fts5yyFallback[iLookAhead])!=0 ){
179212179271
#ifndef NDEBUG
179213
- if( fts5yyTraceFILE ){
179214
- fprintf(fts5yyTraceFILE, "%sFALLBACK %s => %s\n",
179215
- fts5yyTracePrompt, fts5yyTokenName[iLookAhead], fts5yyTokenName[iFallback]);
179216
- }
179272
+ if( fts5yyTraceFILE ){
179273
+ fprintf(fts5yyTraceFILE, "%sFALLBACK %s => %s\n",
179274
+ fts5yyTracePrompt, fts5yyTokenName[iLookAhead], fts5yyTokenName[iFallback]);
179275
+ }
179217179276
#endif
179218
- assert( fts5yyFallback[iFallback]==0 ); /* Fallback loop must terminate */
179219
- iLookAhead = iFallback;
179220
- continue;
179221
- }
179277
+ assert( fts5yyFallback[iFallback]==0 ); /* Fallback loop must terminate */
179278
+ iLookAhead = iFallback;
179279
+ continue;
179280
+ }
179222179281
#endif
179223179282
#ifdef fts5YYWILDCARD
179224
- {
179225
- int j = i - iLookAhead + fts5YYWILDCARD;
179226
- if(
179283
+ {
179284
+ int j = i - iLookAhead + fts5YYWILDCARD;
179285
+ if(
179227179286
#if fts5YY_SHIFT_MIN+fts5YYWILDCARD<0
179228
- j>=0 &&
179287
+ j>=0 &&
179229179288
#endif
179230179289
#if fts5YY_SHIFT_MAX+fts5YYWILDCARD>=fts5YY_ACTTAB_COUNT
179231
- j<fts5YY_ACTTAB_COUNT &&
179290
+ j<fts5YY_ACTTAB_COUNT &&
179232179291
#endif
179233
- fts5yy_lookahead[j]==fts5YYWILDCARD
179234
- ){
179292
+ fts5yy_lookahead[j]==fts5YYWILDCARD && iLookAhead>0
179293
+ ){
179235179294
#ifndef NDEBUG
179236
- if( fts5yyTraceFILE ){
179237
- fprintf(fts5yyTraceFILE, "%sWILDCARD %s => %s\n",
179238
- fts5yyTracePrompt, fts5yyTokenName[iLookAhead],
179239
- fts5yyTokenName[fts5YYWILDCARD]);
179240
- }
179295
+ if( fts5yyTraceFILE ){
179296
+ fprintf(fts5yyTraceFILE, "%sWILDCARD %s => %s\n",
179297
+ fts5yyTracePrompt, fts5yyTokenName[iLookAhead],
179298
+ fts5yyTokenName[fts5YYWILDCARD]);
179299
+ }
179241179300
#endif /* NDEBUG */
179242
- return fts5yy_action[j];
179243
- }
179301
+ return fts5yy_action[j];
179244179302
}
179303
+ }
179245179304
#endif /* fts5YYWILDCARD */
179246
- }
179247179305
return fts5yy_default[stateno];
179248179306
}else{
179249179307
return fts5yy_action[i];
179250179308
}
179251179309
}while(1);
@@ -179368,34 +179426,36 @@
179368179426
*/
179369179427
static const struct {
179370179428
fts5YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */
179371179429
unsigned char nrhs; /* Number of right-hand side symbols in the rule */
179372179430
} fts5yyRuleInfo[] = {
179373
- { 15, 1 },
179374
- { 16, 3 },
179375
- { 16, 3 },
179376
- { 16, 3 },
179377
- { 16, 3 },
179378179431
{ 16, 1 },
179432
+ { 17, 3 },
179433
+ { 17, 3 },
179434
+ { 17, 3 },
179435
+ { 17, 3 },
179436
+ { 17, 1 },
179437
+ { 19, 1 },
179438
+ { 19, 2 },
179379179439
{ 18, 1 },
179380
- { 18, 2 },
179381
- { 17, 1 },
179382
- { 17, 3 },
179383
- { 20, 3 },
179384
- { 20, 1 },
179440
+ { 18, 3 },
179441
+ { 21, 4 },
179442
+ { 21, 3 },
179443
+ { 21, 1 },
179385179444
{ 21, 2 },
179386
- { 21, 1 },
179387
- { 19, 1 },
179388
- { 19, 5 },
179445
+ { 22, 2 },
179389179446
{ 22, 1 },
179390
- { 22, 2 },
179391
- { 24, 0 },
179392
- { 24, 2 },
179393
- { 23, 4 },
179447
+ { 20, 1 },
179448
+ { 20, 5 },
179449
+ { 23, 1 },
179394179450
{ 23, 2 },
179395
- { 25, 1 },
179396179451
{ 25, 0 },
179452
+ { 25, 2 },
179453
+ { 24, 4 },
179454
+ { 24, 2 },
179455
+ { 26, 1 },
179456
+ { 26, 0 },
179397179457
};
179398179458
179399179459
static void fts5yy_accept(fts5yyParser*); /* Forward Declaration */
179400179460
179401179461
/*
@@ -179456,124 +179516,135 @@
179456179516
** break;
179457179517
*/
179458179518
/********** Begin reduce actions **********************************************/
179459179519
fts5YYMINORTYPE fts5yylhsminor;
179460179520
case 0: /* input ::= expr */
179461
-{ sqlite3Fts5ParseFinished(pParse, fts5yymsp[0].minor.fts5yy18); }
179521
+{ sqlite3Fts5ParseFinished(pParse, fts5yymsp[0].minor.fts5yy24); }
179462179522
break;
179463179523
case 1: /* expr ::= expr AND expr */
179464179524
{
179465
- fts5yylhsminor.fts5yy18 = sqlite3Fts5ParseNode(pParse, FTS5_AND, fts5yymsp[-2].minor.fts5yy18, fts5yymsp[0].minor.fts5yy18, 0);
179525
+ fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_AND, fts5yymsp[-2].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24, 0);
179466179526
}
179467
- fts5yymsp[-2].minor.fts5yy18 = fts5yylhsminor.fts5yy18;
179527
+ fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
179468179528
break;
179469179529
case 2: /* expr ::= expr OR expr */
179470179530
{
179471
- fts5yylhsminor.fts5yy18 = sqlite3Fts5ParseNode(pParse, FTS5_OR, fts5yymsp[-2].minor.fts5yy18, fts5yymsp[0].minor.fts5yy18, 0);
179531
+ fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_OR, fts5yymsp[-2].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24, 0);
179472179532
}
179473
- fts5yymsp[-2].minor.fts5yy18 = fts5yylhsminor.fts5yy18;
179533
+ fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
179474179534
break;
179475179535
case 3: /* expr ::= expr NOT expr */
179476179536
{
179477
- fts5yylhsminor.fts5yy18 = sqlite3Fts5ParseNode(pParse, FTS5_NOT, fts5yymsp[-2].minor.fts5yy18, fts5yymsp[0].minor.fts5yy18, 0);
179537
+ fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_NOT, fts5yymsp[-2].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24, 0);
179478179538
}
179479
- fts5yymsp[-2].minor.fts5yy18 = fts5yylhsminor.fts5yy18;
179539
+ fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
179480179540
break;
179481179541
case 4: /* expr ::= LP expr RP */
179482
-{fts5yymsp[-2].minor.fts5yy18 = fts5yymsp[-1].minor.fts5yy18;}
179542
+{fts5yymsp[-2].minor.fts5yy24 = fts5yymsp[-1].minor.fts5yy24;}
179483179543
break;
179484179544
case 5: /* expr ::= exprlist */
179485179545
case 6: /* exprlist ::= cnearset */ fts5yytestcase(fts5yyruleno==6);
179486
-{fts5yylhsminor.fts5yy18 = fts5yymsp[0].minor.fts5yy18;}
179487
- fts5yymsp[0].minor.fts5yy18 = fts5yylhsminor.fts5yy18;
179546
+{fts5yylhsminor.fts5yy24 = fts5yymsp[0].minor.fts5yy24;}
179547
+ fts5yymsp[0].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
179488179548
break;
179489179549
case 7: /* exprlist ::= exprlist cnearset */
179490179550
{
179491
- fts5yylhsminor.fts5yy18 = sqlite3Fts5ParseImplicitAnd(pParse, fts5yymsp[-1].minor.fts5yy18, fts5yymsp[0].minor.fts5yy18);
179551
+ fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseImplicitAnd(pParse, fts5yymsp[-1].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24);
179492179552
}
179493
- fts5yymsp[-1].minor.fts5yy18 = fts5yylhsminor.fts5yy18;
179553
+ fts5yymsp[-1].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
179494179554
break;
179495179555
case 8: /* cnearset ::= nearset */
179496179556
{
179497
- fts5yylhsminor.fts5yy18 = sqlite3Fts5ParseNode(pParse, FTS5_STRING, 0, 0, fts5yymsp[0].minor.fts5yy26);
179557
+ fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_STRING, 0, 0, fts5yymsp[0].minor.fts5yy46);
179498179558
}
179499
- fts5yymsp[0].minor.fts5yy18 = fts5yylhsminor.fts5yy18;
179559
+ fts5yymsp[0].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
179500179560
break;
179501179561
case 9: /* cnearset ::= colset COLON nearset */
179502179562
{
179503
- sqlite3Fts5ParseSetColset(pParse, fts5yymsp[0].minor.fts5yy26, fts5yymsp[-2].minor.fts5yy3);
179504
- fts5yylhsminor.fts5yy18 = sqlite3Fts5ParseNode(pParse, FTS5_STRING, 0, 0, fts5yymsp[0].minor.fts5yy26);
179505
-}
179506
- fts5yymsp[-2].minor.fts5yy18 = fts5yylhsminor.fts5yy18;
179507
- break;
179508
- case 10: /* colset ::= LCP colsetlist RCP */
179509
-{ fts5yymsp[-2].minor.fts5yy3 = fts5yymsp[-1].minor.fts5yy3; }
179510
- break;
179511
- case 11: /* colset ::= STRING */
179512
-{
179513
- fts5yylhsminor.fts5yy3 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
179514
-}
179515
- fts5yymsp[0].minor.fts5yy3 = fts5yylhsminor.fts5yy3;
179516
- break;
179517
- case 12: /* colsetlist ::= colsetlist STRING */
179518
-{
179519
- fts5yylhsminor.fts5yy3 = sqlite3Fts5ParseColset(pParse, fts5yymsp[-1].minor.fts5yy3, &fts5yymsp[0].minor.fts5yy0); }
179520
- fts5yymsp[-1].minor.fts5yy3 = fts5yylhsminor.fts5yy3;
179521
- break;
179522
- case 13: /* colsetlist ::= STRING */
179523
-{
179524
- fts5yylhsminor.fts5yy3 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
179525
-}
179526
- fts5yymsp[0].minor.fts5yy3 = fts5yylhsminor.fts5yy3;
179527
- break;
179528
- case 14: /* nearset ::= phrase */
179529
-{ fts5yylhsminor.fts5yy26 = sqlite3Fts5ParseNearset(pParse, 0, fts5yymsp[0].minor.fts5yy11); }
179530
- fts5yymsp[0].minor.fts5yy26 = fts5yylhsminor.fts5yy26;
179531
- break;
179532
- case 15: /* nearset ::= STRING LP nearphrases neardist_opt RP */
179563
+ sqlite3Fts5ParseSetColset(pParse, fts5yymsp[0].minor.fts5yy46, fts5yymsp[-2].minor.fts5yy11);
179564
+ fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_STRING, 0, 0, fts5yymsp[0].minor.fts5yy46);
179565
+}
179566
+ fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
179567
+ break;
179568
+ case 10: /* colset ::= MINUS LCP colsetlist RCP */
179569
+{
179570
+ fts5yymsp[-3].minor.fts5yy11 = sqlite3Fts5ParseColsetInvert(pParse, fts5yymsp[-1].minor.fts5yy11);
179571
+}
179572
+ break;
179573
+ case 11: /* colset ::= LCP colsetlist RCP */
179574
+{ fts5yymsp[-2].minor.fts5yy11 = fts5yymsp[-1].minor.fts5yy11; }
179575
+ break;
179576
+ case 12: /* colset ::= STRING */
179577
+{
179578
+ fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
179579
+}
179580
+ fts5yymsp[0].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
179581
+ break;
179582
+ case 13: /* colset ::= MINUS STRING */
179583
+{
179584
+ fts5yymsp[-1].minor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
179585
+ fts5yymsp[-1].minor.fts5yy11 = sqlite3Fts5ParseColsetInvert(pParse, fts5yymsp[-1].minor.fts5yy11);
179586
+}
179587
+ break;
179588
+ case 14: /* colsetlist ::= colsetlist STRING */
179589
+{
179590
+ fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseColset(pParse, fts5yymsp[-1].minor.fts5yy11, &fts5yymsp[0].minor.fts5yy0); }
179591
+ fts5yymsp[-1].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
179592
+ break;
179593
+ case 15: /* colsetlist ::= STRING */
179594
+{
179595
+ fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
179596
+}
179597
+ fts5yymsp[0].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
179598
+ break;
179599
+ case 16: /* nearset ::= phrase */
179600
+{ fts5yylhsminor.fts5yy46 = sqlite3Fts5ParseNearset(pParse, 0, fts5yymsp[0].minor.fts5yy53); }
179601
+ fts5yymsp[0].minor.fts5yy46 = fts5yylhsminor.fts5yy46;
179602
+ break;
179603
+ case 17: /* nearset ::= STRING LP nearphrases neardist_opt RP */
179533179604
{
179534179605
sqlite3Fts5ParseNear(pParse, &fts5yymsp[-4].minor.fts5yy0);
179535
- sqlite3Fts5ParseSetDistance(pParse, fts5yymsp[-2].minor.fts5yy26, &fts5yymsp[-1].minor.fts5yy0);
179536
- fts5yylhsminor.fts5yy26 = fts5yymsp[-2].minor.fts5yy26;
179537
-}
179538
- fts5yymsp[-4].minor.fts5yy26 = fts5yylhsminor.fts5yy26;
179539
- break;
179540
- case 16: /* nearphrases ::= phrase */
179541
-{
179542
- fts5yylhsminor.fts5yy26 = sqlite3Fts5ParseNearset(pParse, 0, fts5yymsp[0].minor.fts5yy11);
179543
-}
179544
- fts5yymsp[0].minor.fts5yy26 = fts5yylhsminor.fts5yy26;
179545
- break;
179546
- case 17: /* nearphrases ::= nearphrases phrase */
179547
-{
179548
- fts5yylhsminor.fts5yy26 = sqlite3Fts5ParseNearset(pParse, fts5yymsp[-1].minor.fts5yy26, fts5yymsp[0].minor.fts5yy11);
179549
-}
179550
- fts5yymsp[-1].minor.fts5yy26 = fts5yylhsminor.fts5yy26;
179551
- break;
179552
- case 18: /* neardist_opt ::= */
179606
+ sqlite3Fts5ParseSetDistance(pParse, fts5yymsp[-2].minor.fts5yy46, &fts5yymsp[-1].minor.fts5yy0);
179607
+ fts5yylhsminor.fts5yy46 = fts5yymsp[-2].minor.fts5yy46;
179608
+}
179609
+ fts5yymsp[-4].minor.fts5yy46 = fts5yylhsminor.fts5yy46;
179610
+ break;
179611
+ case 18: /* nearphrases ::= phrase */
179612
+{
179613
+ fts5yylhsminor.fts5yy46 = sqlite3Fts5ParseNearset(pParse, 0, fts5yymsp[0].minor.fts5yy53);
179614
+}
179615
+ fts5yymsp[0].minor.fts5yy46 = fts5yylhsminor.fts5yy46;
179616
+ break;
179617
+ case 19: /* nearphrases ::= nearphrases phrase */
179618
+{
179619
+ fts5yylhsminor.fts5yy46 = sqlite3Fts5ParseNearset(pParse, fts5yymsp[-1].minor.fts5yy46, fts5yymsp[0].minor.fts5yy53);
179620
+}
179621
+ fts5yymsp[-1].minor.fts5yy46 = fts5yylhsminor.fts5yy46;
179622
+ break;
179623
+ case 20: /* neardist_opt ::= */
179553179624
{ fts5yymsp[1].minor.fts5yy0.p = 0; fts5yymsp[1].minor.fts5yy0.n = 0; }
179554179625
break;
179555
- case 19: /* neardist_opt ::= COMMA STRING */
179626
+ case 21: /* neardist_opt ::= COMMA STRING */
179556179627
{ fts5yymsp[-1].minor.fts5yy0 = fts5yymsp[0].minor.fts5yy0; }
179557179628
break;
179558
- case 20: /* phrase ::= phrase PLUS STRING star_opt */
179559
-{
179560
- fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseTerm(pParse, fts5yymsp[-3].minor.fts5yy11, &fts5yymsp[-1].minor.fts5yy0, fts5yymsp[0].minor.fts5yy20);
179561
-}
179562
- fts5yymsp[-3].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
179563
- break;
179564
- case 21: /* phrase ::= STRING star_opt */
179565
-{
179566
- fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseTerm(pParse, 0, &fts5yymsp[-1].minor.fts5yy0, fts5yymsp[0].minor.fts5yy20);
179567
-}
179568
- fts5yymsp[-1].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
179569
- break;
179570
- case 22: /* star_opt ::= STAR */
179571
-{ fts5yymsp[0].minor.fts5yy20 = 1; }
179572
- break;
179573
- case 23: /* star_opt ::= */
179574
-{ fts5yymsp[1].minor.fts5yy20 = 0; }
179629
+ case 22: /* phrase ::= phrase PLUS STRING star_opt */
179630
+{
179631
+ fts5yylhsminor.fts5yy53 = sqlite3Fts5ParseTerm(pParse, fts5yymsp[-3].minor.fts5yy53, &fts5yymsp[-1].minor.fts5yy0, fts5yymsp[0].minor.fts5yy4);
179632
+}
179633
+ fts5yymsp[-3].minor.fts5yy53 = fts5yylhsminor.fts5yy53;
179634
+ break;
179635
+ case 23: /* phrase ::= STRING star_opt */
179636
+{
179637
+ fts5yylhsminor.fts5yy53 = sqlite3Fts5ParseTerm(pParse, 0, &fts5yymsp[-1].minor.fts5yy0, fts5yymsp[0].minor.fts5yy4);
179638
+}
179639
+ fts5yymsp[-1].minor.fts5yy53 = fts5yylhsminor.fts5yy53;
179640
+ break;
179641
+ case 24: /* star_opt ::= STAR */
179642
+{ fts5yymsp[0].minor.fts5yy4 = 1; }
179643
+ break;
179644
+ case 25: /* star_opt ::= */
179645
+{ fts5yymsp[1].minor.fts5yy4 = 0; }
179575179646
break;
179576179647
default:
179577179648
break;
179578179649
/********** End reduce actions ************************************************/
179579179650
};
@@ -180027,11 +180098,11 @@
180027180098
}
180028180099
180029180100
if( p->iRangeEnd>0 && iPos==p->iRangeEnd ){
180030180101
fts5HighlightAppend(&rc, p, &p->zIn[p->iOff], iEndOff - p->iOff);
180031180102
p->iOff = iEndOff;
180032
- if( iPos<p->iter.iEnd ){
180103
+ if( iPos>=p->iter.iStart && iPos<p->iter.iEnd ){
180033180104
fts5HighlightAppend(&rc, p, p->zClose, -1);
180034180105
}
180035180106
}
180036180107
180037180108
return rc;
@@ -180188,10 +180259,17 @@
180188180259
ctx.iRangeEnd = iBestStart + nToken - 1;
180189180260
180190180261
if( iBestStart>0 ){
180191180262
fts5HighlightAppend(&rc, &ctx, zEllips, -1);
180192180263
}
180264
+
180265
+ /* Advance iterator ctx.iter so that it points to the first coalesced
180266
+ ** phrase instance at or following position iBestStart. */
180267
+ while( ctx.iter.iStart>=0 && ctx.iter.iStart<iBestStart && rc==SQLITE_OK ){
180268
+ rc = fts5CInstIterNext(&ctx.iter);
180269
+ }
180270
+
180193180271
if( rc==SQLITE_OK ){
180194180272
rc = pApi->xTokenize(pFts, ctx.zIn, ctx.nIn, (void*)&ctx,fts5HighlightCb);
180195180273
}
180196180274
if( ctx.iRangeEnd>=(nColSize-1) ){
180197180275
fts5HighlightAppend(&rc, &ctx, &ctx.zIn[ctx.iOff], ctx.nIn - ctx.iOff);
@@ -181923,10 +182001,11 @@
181923182001
case '}': tok = FTS5_RCP; break;
181924182002
case ':': tok = FTS5_COLON; break;
181925182003
case ',': tok = FTS5_COMMA; break;
181926182004
case '+': tok = FTS5_PLUS; break;
181927182005
case '*': tok = FTS5_STAR; break;
182006
+ case '-': tok = FTS5_MINUS; break;
181928182007
case '\0': tok = FTS5_EOF; break;
181929182008
181930182009
case '"': {
181931182010
const char *z2;
181932182011
tok = FTS5_STRING;
@@ -183414,11 +183493,11 @@
183414183493
sizeof(Fts5ExprNearset) + sizeof(Fts5ExprPhrase*));
183415183494
}
183416183495
if( rc==SQLITE_OK ){
183417183496
Fts5Colset *pColsetOrig = pOrig->pNode->pNear->pColset;
183418183497
if( pColsetOrig ){
183419
- int nByte = sizeof(Fts5Colset) + pColsetOrig->nCol * sizeof(int);
183498
+ int nByte = sizeof(Fts5Colset) + (pColsetOrig->nCol-1) * sizeof(int);
183420183499
Fts5Colset *pColset = (Fts5Colset*)sqlite3Fts5MallocZero(&rc, nByte);
183421183500
if( pColset ){
183422183501
memcpy(pColset, pColsetOrig, nByte);
183423183502
}
183424183503
pNew->pRoot->pNear->pColset = pColset;
@@ -183548,10 +183627,38 @@
183548183627
#endif
183549183628
}
183550183629
183551183630
return pNew;
183552183631
}
183632
+
183633
+/*
183634
+** Allocate and return an Fts5Colset object specifying the inverse of
183635
+** the colset passed as the second argument. Free the colset passed
183636
+** as the second argument before returning.
183637
+*/
183638
+static Fts5Colset *sqlite3Fts5ParseColsetInvert(Fts5Parse *pParse, Fts5Colset *p){
183639
+ Fts5Colset *pRet;
183640
+ int nCol = pParse->pConfig->nCol;
183641
+
183642
+ pRet = (Fts5Colset*)sqlite3Fts5MallocZero(&pParse->rc,
183643
+ sizeof(Fts5Colset) + sizeof(int)*nCol
183644
+ );
183645
+ if( pRet ){
183646
+ int i;
183647
+ int iOld = 0;
183648
+ for(i=0; i<nCol; i++){
183649
+ if( iOld>=p->nCol || p->aiCol[iOld]!=i ){
183650
+ pRet->aiCol[pRet->nCol++] = i;
183651
+ }else{
183652
+ iOld++;
183653
+ }
183654
+ }
183655
+ }
183656
+
183657
+ sqlite3_free(p);
183658
+ return pRet;
183659
+}
183553183660
183554183661
static Fts5Colset *sqlite3Fts5ParseColset(
183555183662
Fts5Parse *pParse, /* Store SQLITE_NOMEM here if required */
183556183663
Fts5Colset *pColset, /* Existing colset object */
183557183664
Fts5Token *p
@@ -185644,18 +185751,29 @@
185644185751
185645185752
assert( (pRet==0)==(p->rc!=SQLITE_OK) );
185646185753
return pRet;
185647185754
}
185648185755
185649
-
185650185756
/*
185651185757
** Release a reference to data record returned by an earlier call to
185652185758
** fts5DataRead().
185653185759
*/
185654185760
static void fts5DataRelease(Fts5Data *pData){
185655185761
sqlite3_free(pData);
185656185762
}
185763
+
185764
+static Fts5Data *fts5LeafRead(Fts5Index *p, i64 iRowid){
185765
+ Fts5Data *pRet = fts5DataRead(p, iRowid);
185766
+ if( pRet ){
185767
+ if( pRet->szLeaf>pRet->nn ){
185768
+ p->rc = FTS5_CORRUPT;
185769
+ fts5DataRelease(pRet);
185770
+ pRet = 0;
185771
+ }
185772
+ }
185773
+ return pRet;
185774
+}
185657185775
185658185776
static int fts5IndexPrepareStmt(
185659185777
Fts5Index *p,
185660185778
sqlite3_stmt **ppStmt,
185661185779
char *zSql
@@ -186461,11 +186579,11 @@
186461186579
pIter->iLeafPgno++;
186462186580
if( pIter->pNextLeaf ){
186463186581
pIter->pLeaf = pIter->pNextLeaf;
186464186582
pIter->pNextLeaf = 0;
186465186583
}else if( pIter->iLeafPgno<=pSeg->pgnoLast ){
186466
- pIter->pLeaf = fts5DataRead(p,
186584
+ pIter->pLeaf = fts5LeafRead(p,
186467186585
FTS5_SEGMENT_ROWID(pSeg->iSegid, pIter->iLeafPgno)
186468186586
);
186469186587
}else{
186470186588
pIter->pLeaf = 0;
186471186589
}
@@ -186964,13 +187082,12 @@
186964187082
pIter->iLeafOffset = iOff;
186965187083
186966187084
if( pLeaf->nn>pLeaf->szLeaf ){
186967187085
pIter->iPgidxOff = pLeaf->szLeaf + fts5GetVarint32(
186968187086
&pLeaf->p[pLeaf->szLeaf], pIter->iEndofDoclist
186969
- );
187087
+ );
186970187088
}
186971
-
186972187089
}
186973187090
else if( pLeaf->nn>pLeaf->szLeaf ){
186974187091
pIter->iPgidxOff = pLeaf->szLeaf + fts5GetVarint32(
186975187092
&pLeaf->p[pLeaf->szLeaf], iOff
186976187093
);
@@ -187210,10 +187327,15 @@
187210187327
}
187211187328
187212187329
iPgidx += fts5GetVarint32(&a[iPgidx], nKeep);
187213187330
iTermOff += nKeep;
187214187331
iOff = iTermOff;
187332
+
187333
+ if( iOff>=n ){
187334
+ p->rc = FTS5_CORRUPT;
187335
+ return;
187336
+ }
187215187337
187216187338
/* Read the nKeep field of the next term. */
187217187339
fts5FastGetVarint32(a, iOff, nKeep);
187218187340
}
187219187341
@@ -188136,10 +188258,19 @@
188136188258
fts5BufferZero(&pIter->poslist);
188137188259
fts5SegiterPoslist(pIter->pIndex, pSeg, 0, &pIter->poslist);
188138188260
pIter->base.pData = pIter->poslist.p;
188139188261
}
188140188262
}
188263
+
188264
+/*
188265
+** xSetOutputs callback used when the Fts5Colset object has nCol==0 (match
188266
+** against no columns at all).
188267
+*/
188268
+static void fts5IterSetOutputs_ZeroColset(Fts5Iter *pIter, Fts5SegIter *pSeg){
188269
+ UNUSED_PARAM(pSeg);
188270
+ pIter->base.nData = 0;
188271
+}
188141188272
188142188273
/*
188143188274
** xSetOutputs callback used by detail=col when there is a column filter
188144188275
** and there are 100 or more columns. Also called as a fallback from
188145188276
** fts5IterSetOutputs_Col100 if the column-list spans more than one page.
@@ -188241,10 +188372,14 @@
188241188372
}
188242188373
188243188374
else if( pIter->pColset==0 ){
188244188375
pIter->xSetOutputs = fts5IterSetOutputs_Nocolset;
188245188376
}
188377
+
188378
+ else if( pIter->pColset->nCol==0 ){
188379
+ pIter->xSetOutputs = fts5IterSetOutputs_ZeroColset;
188380
+ }
188246188381
188247188382
else if( pConfig->eDetail==FTS5_DETAIL_FULL ){
188248188383
pIter->xSetOutputs = fts5IterSetOutputs_Full;
188249188384
}
188250188385
@@ -194018,11 +194153,11 @@
194018194153
int nArg, /* Number of args */
194019194154
sqlite3_value **apUnused /* Function arguments */
194020194155
){
194021194156
assert( nArg==0 );
194022194157
UNUSED_PARAM2(nArg, apUnused);
194023
- sqlite3_result_text(pCtx, "fts5: 2016-08-11 18:53:32 a12d8059770df4bca59e321c266410344242bf7b", -1, SQLITE_TRANSIENT);
194158
+ sqlite3_result_text(pCtx, "fts5: 2016-08-20 18:06:14 9041ee4a6f0e8389297f887f1431ab5cfe783390", -1, SQLITE_TRANSIENT);
194024194159
}
194025194160
194026194161
static int fts5Init(sqlite3 *db){
194027194162
static const sqlite3_module fts5Mod = {
194028194163
/* iVersion */ 2,
194029194164
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.14.1. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a single translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% or more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -378,13 +378,13 @@
378 **
379 ** See also: [sqlite3_libversion()],
380 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
381 ** [sqlite_version()] and [sqlite_source_id()].
382 */
383 #define SQLITE_VERSION "3.14.1"
384 #define SQLITE_VERSION_NUMBER 3014001
385 #define SQLITE_SOURCE_ID "2016-08-11 18:53:32 a12d8059770df4bca59e321c266410344242bf7b"
386
387 /*
388 ** CAPI3REF: Run-Time Library Version Numbers
389 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
390 **
@@ -2227,12 +2227,22 @@
2227 ** is written 0 or 1 to indicate whether [sqlite3_load_extension()] interface
2228 ** is disabled or enabled following this call. The second parameter may
2229 ** be a NULL pointer, in which case the new setting is not reported back.
2230 ** </dd>
2231 **
 
 
 
 
 
 
 
 
 
2232 ** </dl>
2233 */
 
2234 #define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
2235 #define SQLITE_DBCONFIG_ENABLE_FKEY 1002 /* int int* */
2236 #define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */
2237 #define SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1004 /* int int* */
2238 #define SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION 1005 /* int int* */
@@ -13694,11 +13704,11 @@
13694 ** in the sqlite.aDb[] array. aDb[0] is the main database file and
13695 ** aDb[1] is the database file used to hold temporary tables. Additional
13696 ** databases may be attached.
13697 */
13698 struct Db {
13699 char *zName; /* Name of this database */
13700 Btree *pBt; /* The B*Tree structure for this database file */
13701 u8 safety_level; /* How aggressive at syncing data to disk */
13702 u8 bSyncSet; /* True if "PRAGMA synchronous=N" has been run */
13703 Schema *pSchema; /* Pointer to database schema (possibly shared) */
13704 };
@@ -16298,12 +16308,12 @@
16298 SQLITE_PRIVATE Table *sqlite3LocateTable(Parse*,u32 flags,const char*, const char*);
16299 SQLITE_PRIVATE Table *sqlite3LocateTableItem(Parse*,u32 flags,struct SrcList_item *);
16300 SQLITE_PRIVATE Index *sqlite3FindIndex(sqlite3*,const char*, const char*);
16301 SQLITE_PRIVATE void sqlite3UnlinkAndDeleteTable(sqlite3*,int,const char*);
16302 SQLITE_PRIVATE void sqlite3UnlinkAndDeleteIndex(sqlite3*,int,const char*);
16303 SQLITE_PRIVATE void sqlite3Vacuum(Parse*);
16304 SQLITE_PRIVATE int sqlite3RunVacuum(char**, sqlite3*);
16305 SQLITE_PRIVATE char *sqlite3NameFromToken(sqlite3*, Token*);
16306 SQLITE_PRIVATE int sqlite3ExprCompare(Expr*, Expr*, int);
16307 SQLITE_PRIVATE int sqlite3ExprListCompare(ExprList*, ExprList*, int);
16308 SQLITE_PRIVATE int sqlite3ExprImpliesExpr(Expr*, Expr*, int);
16309 SQLITE_PRIVATE void sqlite3ExprAnalyzeAggregates(NameContext*, Expr*);
@@ -34851,10 +34861,31 @@
34851 unixLeaveMutex();
34852 }
34853 #endif /* if !OS_VXWORKS */
34854 return pUnused;
34855 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34856
34857 /*
34858 ** This function is called by unixOpen() to determine the unix permissions
34859 ** to create new files with. If no error occurs, then SQLITE_OK is returned
34860 ** and a value suitable for passing as the third argument to open(2) is
@@ -34887,11 +34918,10 @@
34887 *pUid = 0;
34888 *pGid = 0;
34889 if( flags & (SQLITE_OPEN_WAL|SQLITE_OPEN_MAIN_JOURNAL) ){
34890 char zDb[MAX_PATHNAME+1]; /* Database file path */
34891 int nDb; /* Number of valid bytes in zDb */
34892 struct stat sStat; /* Output of stat() on database file */
34893
34894 /* zPath is a path to a WAL or journal file. The following block derives
34895 ** the path to the associated database file from zPath. This block handles
34896 ** the following naming conventions:
34897 **
@@ -34918,19 +34948,22 @@
34918 nDb--;
34919 }
34920 memcpy(zDb, zPath, nDb);
34921 zDb[nDb] = '\0';
34922
34923 if( 0==osStat(zDb, &sStat) ){
34924 *pMode = sStat.st_mode & 0777;
34925 *pUid = sStat.st_uid;
34926 *pGid = sStat.st_gid;
34927 }else{
34928 rc = SQLITE_IOERR_FSTAT;
34929 }
34930 }else if( flags & SQLITE_OPEN_DELETEONCLOSE ){
34931 *pMode = 0600;
 
 
 
 
 
 
 
 
 
34932 }
34933 return rc;
34934 }
34935
34936 /*
@@ -75441,11 +75474,11 @@
75441 int nEntry;
75442 sqlite3BtreeEnter(pBt);
75443 nEntry = sqlite3PagerWalCallback(sqlite3BtreePager(pBt));
75444 sqlite3BtreeLeave(pBt);
75445 if( db->xWalCallback && nEntry>0 && rc==SQLITE_OK ){
75446 rc = db->xWalCallback(db->pWalArg, db, db->aDb[i].zName, nEntry);
75447 }
75448 }
75449 }
75450 #endif
75451 return rc;
@@ -81472,11 +81505,11 @@
81472 }
81473
81474 if( pOp->p4type==P4_TABLE && HAS_UPDATE_HOOK(db) ){
81475 assert( pC->isTable );
81476 assert( pC->iDb>=0 );
81477 zDb = db->aDb[pC->iDb].zName;
81478 pTab = pOp->p4.pTab;
81479 assert( HasRowid(pTab) );
81480 op = ((pOp->p5 & OPFLAG_ISUPDATE) ? SQLITE_UPDATE : SQLITE_INSERT);
81481 }else{
81482 pTab = 0; /* Not needed. Silence a comiler warning. */
@@ -81589,11 +81622,11 @@
81589 ** last moved with OP_Next or OP_Prev, not Seek or NotFound, set
81590 ** VdbeCursor.movetoTarget to the current rowid. */
81591 if( pOp->p4type==P4_TABLE && HAS_UPDATE_HOOK(db) ){
81592 assert( pC->iDb>=0 );
81593 assert( pOp->p4.pTab!=0 );
81594 zDb = db->aDb[pC->iDb].zName;
81595 pTab = pOp->p4.pTab;
81596 if( (pOp->p5 & OPFLAG_SAVEPOSITION)!=0 && pC->isTable ){
81597 pC->movetoTarget = sqlite3BtreeIntegerKey(pC->uc.pCursor);
81598 }
81599 }else{
@@ -82559,11 +82592,11 @@
82559 initData.db = db;
82560 initData.iDb = pOp->p1;
82561 initData.pzErrMsg = &p->zErrMsg;
82562 zSql = sqlite3MPrintf(db,
82563 "SELECT name, rootpage, sql FROM '%q'.%s WHERE %s ORDER BY rowid",
82564 db->aDb[iDb].zName, zMaster, pOp->p4.z);
82565 if( zSql==0 ){
82566 rc = SQLITE_NOMEM_BKPT;
82567 }else{
82568 assert( db->init.busy==0 );
82569 db->init.busy = 1;
@@ -83388,19 +83421,18 @@
83388 break;
83389 };
83390 #endif /* SQLITE_OMIT_PRAGMA */
83391
83392 #if !defined(SQLITE_OMIT_VACUUM) && !defined(SQLITE_OMIT_ATTACH)
83393 /* Opcode: Vacuum * * * * *
83394 **
83395 ** Vacuum the entire database. This opcode will cause other virtual
83396 ** machines to be created and run. It may not be called from within
83397 ** a transaction.
83398 */
83399 case OP_Vacuum: {
83400 assert( p->readOnly==0 );
83401 rc = sqlite3RunVacuum(&p->zErrMsg, db);
83402 if( rc ) goto abort_due_to_error;
83403 break;
83404 }
83405 #endif
83406
@@ -83943,11 +83975,11 @@
83943 zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql);
83944 if( zTrace ){
83945 int i;
83946 for(i=0; i<db->nDb; i++){
83947 if( DbMaskTest(p->btreeMask, i)==0 ) continue;
83948 sqlite3_file_control(db, db->aDb[i].zName, SQLITE_FCNTL_TRACE, zTrace);
83949 }
83950 }
83951 #endif /* SQLITE_USE_FCNTL_TRACE */
83952 #ifdef SQLITE_DEBUG
83953 if( (db->flags & SQLITE_SqlTrace)!=0
@@ -84279,11 +84311,11 @@
84279 rc = SQLITE_ERROR;
84280 sqlite3BtreeLeaveAll(db);
84281 goto blob_open_out;
84282 }
84283 pBlob->pTab = pTab;
84284 pBlob->zDb = db->aDb[sqlite3SchemaToIndex(db, pTab->pSchema)].zName;
84285
84286 /* Now search pTab for the exact column. */
84287 for(iCol=0; iCol<pTab->nCol; iCol++) {
84288 if( sqlite3StrICmp(pTab->aCol[iCol].zName, zColumn)==0 ){
84289 break;
@@ -87831,21 +87863,19 @@
87831 static SQLITE_NOINLINE int walkExpr(Walker *pWalker, Expr *pExpr){
87832 int rc;
87833 testcase( ExprHasProperty(pExpr, EP_TokenOnly) );
87834 testcase( ExprHasProperty(pExpr, EP_Reduced) );
87835 rc = pWalker->xExprCallback(pWalker, pExpr);
87836 if( rc==WRC_Continue
87837 && !ExprHasProperty(pExpr,EP_TokenOnly) ){
87838 if( sqlite3WalkExpr(pWalker, pExpr->pLeft) ) return WRC_Abort;
87839 if( sqlite3WalkExpr(pWalker, pExpr->pRight) ) return WRC_Abort;
87840 if( ExprHasProperty(pExpr, EP_xIsSelect) ){
87841 if( sqlite3WalkSelect(pWalker, pExpr->x.pSelect) ) return WRC_Abort;
87842 }else{
87843 if( sqlite3WalkExprList(pWalker, pExpr->x.pList) ) return WRC_Abort;
87844 }
87845 }
87846 return rc & WRC_Abort;
87847 }
87848 SQLITE_PRIVATE int sqlite3WalkExpr(Walker *pWalker, Expr *pExpr){
87849 return pExpr ? walkExpr(pWalker,pExpr) : WRC_Continue;
87850 }
87851
@@ -88175,12 +88205,12 @@
88175 ** legacy and because it does not hurt anything to just ignore the
88176 ** database name. */
88177 zDb = 0;
88178 }else{
88179 for(i=0; i<db->nDb; i++){
88180 assert( db->aDb[i].zName );
88181 if( sqlite3StrICmp(db->aDb[i].zName,zDb)==0 ){
88182 pSchema = db->aDb[i].pSchema;
88183 break;
88184 }
88185 }
88186 }
@@ -94249,11 +94279,11 @@
94249 assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );
94250
94251 pTab = sqlite3LocateTableItem(pParse, 0, &pSrc->a[0]);
94252 if( !pTab ) goto exit_rename_table;
94253 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
94254 zDb = db->aDb[iDb].zName;
94255 db->flags |= SQLITE_PreferBuiltin;
94256
94257 /* Get a NULL terminated version of the new table name. */
94258 zName = sqlite3NameFromToken(db, pName);
94259 if( !zName ) goto exit_rename_table;
@@ -94447,11 +94477,11 @@
94447 pNew = pParse->pNewTable;
94448 assert( pNew );
94449
94450 assert( sqlite3BtreeHoldsAllMutexes(db) );
94451 iDb = sqlite3SchemaToIndex(db, pNew->pSchema);
94452 zDb = db->aDb[iDb].zName;
94453 zTab = &pNew->zName[16]; /* Skip the "sqlite_altertab_" prefix on the name */
94454 pCol = &pNew->aCol[pNew->nCol-1];
94455 pDflt = pCol->pDflt;
94456 pTab = sqlite3FindTable(db, zTab, zDb);
94457 assert( pTab );
@@ -94857,18 +94887,18 @@
94857 ** if they do already exist.
94858 */
94859 for(i=0; i<ArraySize(aTable); i++){
94860 const char *zTab = aTable[i].zName;
94861 Table *pStat;
94862 if( (pStat = sqlite3FindTable(db, zTab, pDb->zName))==0 ){
94863 if( aTable[i].zCols ){
94864 /* The sqlite_statN table does not exist. Create it. Note that a
94865 ** side-effect of the CREATE TABLE statement is to leave the rootpage
94866 ** of the new table in register pParse->regRoot. This is important
94867 ** because the OpenWrite opcode below will be needing it. */
94868 sqlite3NestedParse(pParse,
94869 "CREATE TABLE %Q.%s(%s)", pDb->zName, zTab, aTable[i].zCols
94870 );
94871 aRoot[i] = pParse->regRoot;
94872 aCreateTbl[i] = OPFLAG_P2ISREG;
94873 }
94874 }else{
@@ -94879,11 +94909,11 @@
94879 aCreateTbl[i] = 0;
94880 sqlite3TableLock(pParse, iDb, aRoot[i], 1, zTab);
94881 if( zWhere ){
94882 sqlite3NestedParse(pParse,
94883 "DELETE FROM %Q.%s WHERE %s=%Q",
94884 pDb->zName, zTab, zWhereType, zWhere
94885 );
94886 }else{
94887 /* The sqlite_stat[134] table already exists. Delete all rows. */
94888 sqlite3VdbeAddOp2(v, OP_Clear, aRoot[i], iDb);
94889 }
@@ -95641,11 +95671,11 @@
95641 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
95642 assert( iDb>=0 );
95643 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
95644 #ifndef SQLITE_OMIT_AUTHORIZATION
95645 if( sqlite3AuthCheck(pParse, SQLITE_ANALYZE, pTab->zName, 0,
95646 db->aDb[iDb].zName ) ){
95647 return;
95648 }
95649 #endif
95650
95651 /* Establish a read-lock on the table at the shared-cache level.
@@ -96031,11 +96061,11 @@
96031 }
96032 }else{
96033 /* Form 3: Analyze the fully qualified table name */
96034 iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pTableName);
96035 if( iDb>=0 ){
96036 zDb = db->aDb[iDb].zName;
96037 z = sqlite3NameFromToken(db, pTableName);
96038 if( z ){
96039 if( (pIdx = sqlite3FindIndex(db, z, zDb))!=0 ){
96040 analyzeTable(pParse, pIdx->pTable, pIdx);
96041 }else if( (pTab = sqlite3LocateTable(pParse, 0, z, zDb))!=0 ){
@@ -96491,11 +96521,11 @@
96491 #endif
96492 }
96493
96494 /* Load new statistics out of the sqlite_stat1 table */
96495 sInfo.db = db;
96496 sInfo.zDatabase = db->aDb[iDb].zName;
96497 if( sqlite3FindTable(db, "sqlite_stat1", sInfo.zDatabase)!=0 ){
96498 zSql = sqlite3MPrintf(db,
96499 "SELECT tbl,idx,stat FROM %Q.sqlite_stat1", sInfo.zDatabase);
96500 if( zSql==0 ){
96501 rc = SQLITE_NOMEM_BKPT;
@@ -96634,11 +96664,11 @@
96634 if( !db->autoCommit ){
96635 zErrDyn = sqlite3MPrintf(db, "cannot ATTACH database within transaction");
96636 goto attach_error;
96637 }
96638 for(i=0; i<db->nDb; i++){
96639 char *z = db->aDb[i].zName;
96640 assert( z && zName );
96641 if( sqlite3StrICmp(z, zName)==0 ){
96642 zErrDyn = sqlite3MPrintf(db, "database %s is already in use", zName);
96643 goto attach_error;
96644 }
@@ -96699,12 +96729,12 @@
96699 PAGER_SYNCHRONOUS_FULL | (db->flags & PAGER_FLAGS_MASK));
96700 #endif
96701 sqlite3BtreeLeave(aNew->pBt);
96702 }
96703 aNew->safety_level = SQLITE_DEFAULT_SYNCHRONOUS+1;
96704 aNew->zName = sqlite3DbStrDup(db, zName);
96705 if( rc==SQLITE_OK && aNew->zName==0 ){
96706 rc = SQLITE_NOMEM_BKPT;
96707 }
96708
96709
96710 #ifdef SQLITE_HAS_CODEC
@@ -96812,11 +96842,11 @@
96812
96813 if( zName==0 ) zName = "";
96814 for(i=0; i<db->nDb; i++){
96815 pDb = &db->aDb[i];
96816 if( pDb->pBt==0 ) continue;
96817 if( sqlite3StrICmp(pDb->zName, zName)==0 ) break;
96818 }
96819
96820 if( i>=db->nDb ){
96821 sqlite3_snprintf(sizeof(zErr),zErr, "no such database: %s", zName);
96822 goto detach_error;
@@ -96970,11 +97000,11 @@
96970 sqlite3 *db;
96971
96972 db = pParse->db;
96973 assert( db->nDb>iDb );
96974 pFix->pParse = pParse;
96975 pFix->zDb = db->aDb[iDb].zName;
96976 pFix->pSchema = db->aDb[iDb].pSchema;
96977 pFix->zType = zType;
96978 pFix->pName = pName;
96979 pFix->bVarOnly = (iDb==1);
96980 }
@@ -97228,13 +97258,13 @@
97228 Parse *pParse, /* The parser context */
97229 const char *zTab, /* Table name */
97230 const char *zCol, /* Column name */
97231 int iDb /* Index of containing database. */
97232 ){
97233 sqlite3 *db = pParse->db; /* Database handle */
97234 char *zDb = db->aDb[iDb].zName; /* Name of attached database */
97235 int rc; /* Auth callback return code */
97236
97237 if( db->init.busy ) return SQLITE_OK;
97238 rc = db->xAuth(db->pAuthArg, SQLITE_READ, zTab,zCol,zDb,pParse->zAuthContext
97239 #ifdef SQLITE_USER_AUTHENTICATION
97240 ,db->auth.zAuthUser
@@ -97703,14 +97733,15 @@
97703 return 0;
97704 }
97705 #endif
97706 for(i=OMIT_TEMPDB; i<db->nDb; i++){
97707 int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */
97708 if( zDatabase!=0 && sqlite3StrICmp(zDatabase, db->aDb[j].zName) ) continue;
97709 assert( sqlite3SchemaMutexHeld(db, j, 0) );
97710 p = sqlite3HashFind(&db->aDb[j].pSchema->tblHash, zName);
97711 if( p ) break;
 
97712 }
97713 return p;
97714 }
97715
97716 /*
@@ -97780,11 +97811,11 @@
97780 ){
97781 const char *zDb;
97782 assert( p->pSchema==0 || p->zDatabase==0 );
97783 if( p->pSchema ){
97784 int iDb = sqlite3SchemaToIndex(pParse->db, p->pSchema);
97785 zDb = pParse->db->aDb[iDb].zName;
97786 }else{
97787 zDb = p->zDatabase;
97788 }
97789 return sqlite3LocateTable(pParse, flags, p->zName, zDb);
97790 }
@@ -97808,11 +97839,11 @@
97808 assert( zDb!=0 || sqlite3BtreeHoldsAllMutexes(db) );
97809 for(i=OMIT_TEMPDB; i<db->nDb; i++){
97810 int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */
97811 Schema *pSchema = db->aDb[j].pSchema;
97812 assert( pSchema );
97813 if( zDb && sqlite3StrICmp(zDb, db->aDb[j].zName) ) continue;
97814 assert( sqlite3SchemaMutexHeld(db, j, 0) );
97815 p = sqlite3HashFind(&pSchema->idxHash, zName);
97816 if( p ) break;
97817 }
97818 return p;
@@ -97877,12 +97908,12 @@
97877 SQLITE_PRIVATE void sqlite3CollapseDatabaseArray(sqlite3 *db){
97878 int i, j;
97879 for(i=j=2; i<db->nDb; i++){
97880 struct Db *pDb = &db->aDb[i];
97881 if( pDb->pBt==0 ){
97882 sqlite3DbFree(db, pDb->zName);
97883 pDb->zName = 0;
97884 continue;
97885 }
97886 if( j<i ){
97887 db->aDb[j] = db->aDb[i];
97888 }
@@ -98098,11 +98129,11 @@
98098 SQLITE_PRIVATE int sqlite3FindDbName(sqlite3 *db, const char *zName){
98099 int i = -1; /* Database number */
98100 if( zName ){
98101 Db *pDb;
98102 for(i=(db->nDb-1), pDb=&db->aDb[i]; i>=0; i--, pDb--){
98103 if( 0==sqlite3StrICmp(pDb->zName, zName) ) break;
98104 }
98105 }
98106 return i;
98107 }
98108
@@ -98157,11 +98188,11 @@
98157 if( iDb<0 ){
98158 sqlite3ErrorMsg(pParse, "unknown database %T", pName1);
98159 return -1;
98160 }
98161 }else{
98162 assert( db->init.iDb==0 || db->init.busy );
98163 iDb = db->init.iDb;
98164 *pUnqual = pName1;
98165 }
98166 return iDb;
98167 }
@@ -98268,11 +98299,11 @@
98268 SQLITE_CREATE_TABLE,
98269 SQLITE_CREATE_TEMP_TABLE,
98270 SQLITE_CREATE_VIEW,
98271 SQLITE_CREATE_TEMP_VIEW
98272 };
98273 char *zDb = db->aDb[iDb].zName;
98274 if( sqlite3AuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(isTemp), 0, zDb) ){
98275 goto begin_table_error;
98276 }
98277 if( !isVirtual && sqlite3AuthCheck(pParse, (int)aCode[isTemp+2*isView],
98278 zName, 0, zDb) ){
@@ -98287,11 +98318,11 @@
98287 ** to an sqlite3_declare_vtab() call. In that case only the column names
98288 ** and types will be used, so there is no need to test for namespace
98289 ** collisions.
98290 */
98291 if( !IN_DECLARE_VTAB ){
98292 char *zDb = db->aDb[iDb].zName;
98293 if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){
98294 goto begin_table_error;
98295 }
98296 pTable = sqlite3FindTable(db, zName, zDb);
98297 if( pTable ){
@@ -99380,11 +99411,11 @@
99380 */
99381 sqlite3NestedParse(pParse,
99382 "UPDATE %Q.%s "
99383 "SET type='%s', name=%Q, tbl_name=%Q, rootpage=#%d, sql=%Q "
99384 "WHERE rowid=#%d",
99385 db->aDb[iDb].zName, SCHEMA_TABLE(iDb),
99386 zType,
99387 p->zName,
99388 p->zName,
99389 pParse->regRoot,
99390 zStmt,
@@ -99395,17 +99426,17 @@
99395
99396 #ifndef SQLITE_OMIT_AUTOINCREMENT
99397 /* Check to see if we need to create an sqlite_sequence table for
99398 ** keeping track of autoincrement keys.
99399 */
99400 if( p->tabFlags & TF_Autoincrement ){
99401 Db *pDb = &db->aDb[iDb];
99402 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
99403 if( pDb->pSchema->pSeqTab==0 ){
99404 sqlite3NestedParse(pParse,
99405 "CREATE TABLE %Q.sqlite_sequence(name,seq)",
99406 pDb->zName
99407 );
99408 }
99409 }
99410 #endif
99411
@@ -99715,11 +99746,11 @@
99715 ** is in register NNN. See grammar rules associated with the TK_REGISTER
99716 ** token for additional information.
99717 */
99718 sqlite3NestedParse(pParse,
99719 "UPDATE %Q.%s SET rootpage=%d WHERE #%d AND rootpage=#%d",
99720 pParse->db->aDb[iDb].zName, SCHEMA_TABLE(iDb), iTable, r1, r1);
99721 #endif
99722 sqlite3ReleaseTempReg(pParse, r1);
99723 }
99724
99725 /*
@@ -99791,11 +99822,11 @@
99791 int iDb, /* The database number */
99792 const char *zType, /* "idx" or "tbl" */
99793 const char *zName /* Name of index or table */
99794 ){
99795 int i;
99796 const char *zDbName = pParse->db->aDb[iDb].zName;
99797 for(i=1; i<=4; i++){
99798 char zTab[24];
99799 sqlite3_snprintf(sizeof(zTab),zTab,"sqlite_stat%d",i);
99800 if( sqlite3FindTable(pParse->db, zTab, zDbName) ){
99801 sqlite3NestedParse(pParse,
@@ -99844,11 +99875,11 @@
99844 ** move as a result of the drop (can happen in auto-vacuum mode).
99845 */
99846 if( pTab->tabFlags & TF_Autoincrement ){
99847 sqlite3NestedParse(pParse,
99848 "DELETE FROM %Q.sqlite_sequence WHERE name=%Q",
99849 pDb->zName, pTab->zName
99850 );
99851 }
99852 #endif
99853
99854 /* Drop all SQLITE_MASTER table and index entries that refer to the
@@ -99858,11 +99889,11 @@
99858 ** created in the temp database that refers to a table in another
99859 ** database.
99860 */
99861 sqlite3NestedParse(pParse,
99862 "DELETE FROM %Q.%s WHERE tbl_name=%Q and type!='trigger'",
99863 pDb->zName, SCHEMA_TABLE(iDb), pTab->zName);
99864 if( !isView && !IsVirtual(pTab) ){
99865 destroyTable(pParse, pTab);
99866 }
99867
99868 /* Remove the table entry from SQLite's internal schema and modify
@@ -99912,11 +99943,11 @@
99912 }
99913 #ifndef SQLITE_OMIT_AUTHORIZATION
99914 {
99915 int code;
99916 const char *zTab = SCHEMA_TABLE(iDb);
99917 const char *zDb = db->aDb[iDb].zName;
99918 const char *zArg2 = 0;
99919 if( sqlite3AuthCheck(pParse, SQLITE_DELETE, zTab, 0, zDb)){
99920 goto exit_drop_table;
99921 }
99922 if( isView ){
@@ -100153,11 +100184,11 @@
100153 sqlite3 *db = pParse->db; /* The database connection */
100154 int iDb = sqlite3SchemaToIndex(db, pIndex->pSchema);
100155
100156 #ifndef SQLITE_OMIT_AUTHORIZATION
100157 if( sqlite3AuthCheck(pParse, SQLITE_REINDEX, pIndex->zName, 0,
100158 db->aDb[iDb].zName ) ){
100159 return;
100160 }
100161 #endif
100162
100163 /* Require a write-lock on the table to perform this operation */
@@ -100405,11 +100436,11 @@
100405 if( sqlite3FindTable(db, zName, 0)!=0 ){
100406 sqlite3ErrorMsg(pParse, "there is already a table named %s", zName);
100407 goto exit_create_index;
100408 }
100409 }
100410 if( sqlite3FindIndex(db, zName, pDb->zName)!=0 ){
100411 if( !ifNotExist ){
100412 sqlite3ErrorMsg(pParse, "index %s already exists", zName);
100413 }else{
100414 assert( !db->init.busy );
100415 sqlite3CodeVerifySchema(pParse, iDb);
@@ -100435,11 +100466,11 @@
100435
100436 /* Check for authorization to create an index.
100437 */
100438 #ifndef SQLITE_OMIT_AUTHORIZATION
100439 {
100440 const char *zDb = pDb->zName;
100441 if( sqlite3AuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(iDb), 0, zDb) ){
100442 goto exit_create_index;
100443 }
100444 i = SQLITE_CREATE_INDEX;
100445 if( !OMIT_TEMPDB && iDb==1 ) i = SQLITE_CREATE_TEMP_INDEX;
@@ -100750,11 +100781,11 @@
100750
100751 /* Add an entry in sqlite_master for this index
100752 */
100753 sqlite3NestedParse(pParse,
100754 "INSERT INTO %Q.%s VALUES('index',%Q,%Q,#%d,%Q);",
100755 db->aDb[iDb].zName, SCHEMA_TABLE(iDb),
100756 pIndex->zName,
100757 pTab->zName,
100758 iMem,
100759 zStmt
100760 );
@@ -100884,11 +100915,11 @@
100884 iDb = sqlite3SchemaToIndex(db, pIndex->pSchema);
100885 #ifndef SQLITE_OMIT_AUTHORIZATION
100886 {
100887 int code = SQLITE_DROP_INDEX;
100888 Table *pTab = pIndex->pTable;
100889 const char *zDb = db->aDb[iDb].zName;
100890 const char *zTab = SCHEMA_TABLE(iDb);
100891 if( sqlite3AuthCheck(pParse, SQLITE_DELETE, zTab, 0, zDb) ){
100892 goto exit_drop_index;
100893 }
100894 if( !OMIT_TEMPDB && iDb ) code = SQLITE_DROP_TEMP_INDEX;
@@ -100902,11 +100933,11 @@
100902 v = sqlite3GetVdbe(pParse);
100903 if( v ){
100904 sqlite3BeginWriteOperation(pParse, 1, iDb);
100905 sqlite3NestedParse(pParse,
100906 "DELETE FROM %Q.%s WHERE name=%Q AND type='index'",
100907 db->aDb[iDb].zName, SCHEMA_TABLE(iDb), pIndex->zName
100908 );
100909 sqlite3ClearStatTables(pParse, iDb, "idx", pIndex->zName);
100910 sqlite3ChangeCookie(pParse, iDb);
100911 destroyRootPage(pParse, pIndex->tnum, iDb);
100912 sqlite3VdbeAddOp4(v, OP_DropIndex, iDb, 0, 0, pIndex->zName, 0);
@@ -101447,11 +101478,11 @@
101447 SQLITE_PRIVATE void sqlite3CodeVerifyNamedSchema(Parse *pParse, const char *zDb){
101448 sqlite3 *db = pParse->db;
101449 int i;
101450 for(i=0; i<db->nDb; i++){
101451 Db *pDb = &db->aDb[i];
101452 if( pDb->pBt && (!zDb || 0==sqlite3StrICmp(zDb, pDb->zName)) ){
101453 sqlite3CodeVerifySchema(pParse, i);
101454 }
101455 }
101456 }
101457
@@ -101694,11 +101725,11 @@
101694 }
101695 iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pObjName);
101696 if( iDb<0 ) return;
101697 z = sqlite3NameFromToken(db, pObjName);
101698 if( z==0 ) return;
101699 zDb = db->aDb[iDb].zName;
101700 pTab = sqlite3FindTable(db, z, zDb);
101701 if( pTab ){
101702 reindexTable(pParse, pTab, 0);
101703 sqlite3DbFree(db, z);
101704 return;
@@ -102408,11 +102439,11 @@
102408 pWhere = sqlite3ExprDup(db, pWhere, 0);
102409 pFrom = sqlite3SrcListAppend(db, 0, 0, 0);
102410 if( pFrom ){
102411 assert( pFrom->nSrc==1 );
102412 pFrom->a[0].zName = sqlite3DbStrDup(db, pView->zName);
102413 pFrom->a[0].zDatabase = sqlite3DbStrDup(db, db->aDb[iDb].zName);
102414 assert( pFrom->a[0].pOn==0 );
102415 assert( pFrom->a[0].pUsing==0 );
102416 }
102417 pSel = sqlite3SelectNew(pParse, 0, pFrom, pWhere, 0, 0, 0,
102418 SF_IncludeHidden, 0, 0);
@@ -102595,11 +102626,11 @@
102595 if( sqlite3IsReadOnly(pParse, pTab, (pTrigger?1:0)) ){
102596 goto delete_from_cleanup;
102597 }
102598 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
102599 assert( iDb<db->nDb );
102600 zDb = db->aDb[iDb].zName;
102601 rcauth = sqlite3AuthCheck(pParse, SQLITE_DELETE, pTab->zName, 0, zDb);
102602 assert( rcauth==SQLITE_OK || rcauth==SQLITE_DENY || rcauth==SQLITE_IGNORE );
102603 if( rcauth==SQLITE_DENY ){
102604 goto delete_from_cleanup;
102605 }
@@ -105927,11 +105958,11 @@
105927
105928 /* If foreign-keys are disabled, this function is a no-op. */
105929 if( (db->flags&SQLITE_ForeignKeys)==0 ) return;
105930
105931 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
105932 zDb = db->aDb[iDb].zName;
105933
105934 /* Loop through all the foreign key constraints for which pTab is the
105935 ** child table (the table that the foreign key definition is part of). */
105936 for(pFKey=pTab->pFKey; pFKey; pFKey=pFKey->pNextFrom){
105937 Table *pTo; /* Parent table of foreign key pFKey */
@@ -106667,11 +106698,13 @@
106667
106668 #ifndef SQLITE_OMIT_AUTOINCREMENT
106669 /*
106670 ** Locate or create an AutoincInfo structure associated with table pTab
106671 ** which is in database iDb. Return the register number for the register
106672 ** that holds the maximum rowid.
 
 
106673 **
106674 ** There is at most one AutoincInfo structure per table even if the
106675 ** same table is autoincremented multiple times due to inserts within
106676 ** triggers. A new AutoincInfo structure is created if this is the
106677 ** first use of table pTab. On 2nd and subsequent uses, the original
@@ -106690,11 +106723,13 @@
106690 Parse *pParse, /* Parsing context */
106691 int iDb, /* Index of the database holding pTab */
106692 Table *pTab /* The table we are writing to */
106693 ){
106694 int memId = 0; /* Register holding maximum rowid */
106695 if( pTab->tabFlags & TF_Autoincrement ){
 
 
106696 Parse *pToplevel = sqlite3ParseToplevel(pParse);
106697 AutoincInfo *pInfo;
106698
106699 pInfo = pToplevel->pAinc;
106700 while( pInfo && pInfo->pTab!=pTab ){ pInfo = pInfo->pNext; }
@@ -107014,11 +107049,11 @@
107014 goto insert_cleanup;
107015 }
107016 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
107017 assert( iDb<db->nDb );
107018 pDb = &db->aDb[iDb];
107019 zDb = pDb->zName;
107020 if( sqlite3AuthCheck(pParse, SQLITE_INSERT, pTab->zName, 0, zDb) ){
107021 goto insert_cleanup;
107022 }
107023 withoutRowid = !HasRowid(pTab);
107024
@@ -110972,11 +111007,11 @@
110972 }else{
110973 zRight = sqlite3NameFromToken(db, pValue);
110974 }
110975
110976 assert( pId2 );
110977 zDb = pId2->n>0 ? pDb->zName : 0;
110978 if( sqlite3AuthCheck(pParse, SQLITE_PRAGMA, zLeft, zRight, zDb) ){
110979 goto pragma_out;
110980 }
110981
110982 /* Send an SQLITE_FCNTL_PRAGMA file-control to the underlying VFS
@@ -111825,14 +111860,14 @@
111825 int i;
111826 pParse->nMem = 3;
111827 setAllColumnNames(v, 3, azCol); assert( 3==ArraySize(azCol) );
111828 for(i=0; i<db->nDb; i++){
111829 if( db->aDb[i].pBt==0 ) continue;
111830 assert( db->aDb[i].zName!=0 );
111831 sqlite3VdbeMultiLoad(v, 1, "iss",
111832 i,
111833 db->aDb[i].zName,
111834 sqlite3BtreeGetFilename(db->aDb[i].pBt));
111835 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3);
111836 }
111837 }
111838 break;
@@ -112117,11 +112152,11 @@
112117 /* Do the b-tree integrity checks */
112118 sqlite3VdbeAddOp4(v, OP_IntegrityCk, 2, cnt, 1, (char*)aRoot,P4_INTARRAY);
112119 sqlite3VdbeChangeP5(v, (u8)i);
112120 addr = sqlite3VdbeAddOp1(v, OP_IsNull, 2); VdbeCoverage(v);
112121 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0,
112122 sqlite3MPrintf(db, "*** in database %s ***\n", db->aDb[i].zName),
112123 P4_DYNAMIC);
112124 sqlite3VdbeAddOp3(v, OP_Move, 2, 4, 1);
112125 sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 2);
112126 sqlite3VdbeAddOp2(v, OP_ResultRow, 2, 1);
112127 sqlite3VdbeJumpHere(v, addr);
@@ -112556,19 +112591,19 @@
112556 pParse->nMem = 2;
112557 for(i=0; i<db->nDb; i++){
112558 Btree *pBt;
112559 const char *zState = "unknown";
112560 int j;
112561 if( db->aDb[i].zName==0 ) continue;
112562 pBt = db->aDb[i].pBt;
112563 if( pBt==0 || sqlite3BtreePager(pBt)==0 ){
112564 zState = "closed";
112565 }else if( sqlite3_file_control(db, i ? db->aDb[i].zName : 0,
112566 SQLITE_FCNTL_LOCKSTATE, &j)==SQLITE_OK ){
112567 zState = azLockName[j];
112568 }
112569 sqlite3VdbeMultiLoad(v, 1, "ss", db->aDb[i].zName, zState);
112570 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 2);
112571 }
112572 break;
112573 }
112574 #endif
@@ -112700,10 +112735,11 @@
112700 ** But because db->init.busy is set to 1, no VDBE code is generated
112701 ** or executed. All the parser does is build the internal data
112702 ** structures that describe the table, index, or view.
112703 */
112704 int rc;
 
112705 sqlite3_stmt *pStmt;
112706 TESTONLY(int rcp); /* Return code from sqlite3_prepare() */
112707
112708 assert( db->init.busy );
112709 db->init.iDb = iDb;
@@ -112710,11 +112746,12 @@
112710 db->init.newTnum = sqlite3Atoi(argv[1]);
112711 db->init.orphanTrigger = 0;
112712 TESTONLY(rcp = ) sqlite3_prepare(db, argv[2], -1, &pStmt, 0);
112713 rc = db->errCode;
112714 assert( (rc&0xFF)==(rcp&0xFF) );
112715 db->init.iDb = 0;
 
112716 if( SQLITE_OK!=rc ){
112717 if( db->init.orphanTrigger ){
112718 assert( iDb==1 );
112719 }else{
112720 pData->rc = rc;
@@ -112734,11 +112771,11 @@
112734 ** constraint for a CREATE TABLE. The index should have already
112735 ** been created when we processed the CREATE TABLE. All we have
112736 ** to do here is record the root page number for that index.
112737 */
112738 Index *pIndex;
112739 pIndex = sqlite3FindIndex(db, argv[0], db->aDb[iDb].zName);
112740 if( pIndex==0 ){
112741 /* This can occur if there exists an index on a TEMP table which
112742 ** has the same name as another index on a permanent index. Since
112743 ** the permanent table is hidden by the TEMP table, we can also
112744 ** safely ignore the index on the permanent table.
@@ -112913,11 +112950,11 @@
112913 assert( db->init.busy );
112914 {
112915 char *zSql;
112916 zSql = sqlite3MPrintf(db,
112917 "SELECT name, rootpage, sql FROM \"%w\".%s ORDER BY rowid",
112918 db->aDb[iDb].zName, zMasterName);
112919 #ifndef SQLITE_OMIT_AUTHORIZATION
112920 {
112921 sqlite3_xauth xAuth;
112922 xAuth = db->xAuth;
112923 db->xAuth = 0;
@@ -113188,11 +113225,11 @@
113188 Btree *pBt = db->aDb[i].pBt;
113189 if( pBt ){
113190 assert( sqlite3BtreeHoldsMutex(pBt) );
113191 rc = sqlite3BtreeSchemaLocked(pBt);
113192 if( rc ){
113193 const char *zDb = db->aDb[i].zName;
113194 sqlite3ErrorWithMsg(db, rc, "database schema is locked: %s", zDb);
113195 testcase( db->flags & SQLITE_ReadUncommitted );
113196 goto end_prepare;
113197 }
113198 }
@@ -114944,11 +114981,11 @@
114944 estWidth = pTab->aCol[iCol].szEst;
114945 }
114946 zOrigTab = pTab->zName;
114947 if( pNC->pParse ){
114948 int iDb = sqlite3SchemaToIndex(pNC->pParse->db, pTab->pSchema);
114949 zOrigDb = pNC->pParse->db->aDb[iDb].zName;
114950 }
114951 #else
114952 if( iCol<0 ){
114953 zType = "INTEGER";
114954 }else{
@@ -117900,11 +117937,11 @@
117900 pSub = 0;
117901 if( zTName && sqlite3StrICmp(zTName, zTabName)!=0 ){
117902 continue;
117903 }
117904 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
117905 zSchemaName = iDb>=0 ? db->aDb[iDb].zName : "*";
117906 }
117907 for(j=0; j<pTab->nCol; j++){
117908 char *zName = pTab->aCol[j].zName;
117909 char *zColname; /* The computed column name */
117910 char *zToFree; /* Malloced string that needs to be freed */
@@ -119612,12 +119649,12 @@
119612 iTabDb = sqlite3SchemaToIndex(db, pTab->pSchema);
119613
119614 #ifndef SQLITE_OMIT_AUTHORIZATION
119615 {
119616 int code = SQLITE_CREATE_TRIGGER;
119617 const char *zDb = db->aDb[iTabDb].zName;
119618 const char *zDbTrig = isTemp ? db->aDb[1].zName : zDb;
119619 if( iTabDb==1 || isTemp ) code = SQLITE_CREATE_TEMP_TRIGGER;
119620 if( sqlite3AuthCheck(pParse, code, zName, pTab->zName, zDbTrig) ){
119621 goto trigger_cleanup;
119622 }
119623 if( sqlite3AuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(iTabDb),0,zDb)){
@@ -119707,11 +119744,11 @@
119707 if( v==0 ) goto triggerfinish_cleanup;
119708 sqlite3BeginWriteOperation(pParse, 0, iDb);
119709 z = sqlite3DbStrNDup(db, (char*)pAll->z, pAll->n);
119710 sqlite3NestedParse(pParse,
119711 "INSERT INTO %Q.%s VALUES('trigger',%Q,%Q,0,'CREATE TRIGGER %q')",
119712 db->aDb[iDb].zName, SCHEMA_TABLE(iDb), zName,
119713 pTrig->table, z);
119714 sqlite3DbFree(db, z);
119715 sqlite3ChangeCookie(pParse, iDb);
119716 sqlite3VdbeAddParseSchemaOp(v, iDb,
119717 sqlite3MPrintf(db, "type='trigger' AND name='%q'", zName));
@@ -119896,11 +119933,11 @@
119896 zDb = pName->a[0].zDatabase;
119897 zName = pName->a[0].zName;
119898 assert( zDb!=0 || sqlite3BtreeHoldsAllMutexes(db) );
119899 for(i=OMIT_TEMPDB; i<db->nDb; i++){
119900 int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */
119901 if( zDb && sqlite3StrICmp(db->aDb[j].zName, zDb) ) continue;
119902 assert( sqlite3SchemaMutexHeld(db, j, 0) );
119903 pTrigger = sqlite3HashFind(&(db->aDb[j].pSchema->trigHash), zName);
119904 if( pTrigger ) break;
119905 }
119906 if( !pTrigger ){
@@ -119942,11 +119979,11 @@
119942 assert( pTable );
119943 assert( pTable->pSchema==pTrigger->pSchema || iDb==1 );
119944 #ifndef SQLITE_OMIT_AUTHORIZATION
119945 {
119946 int code = SQLITE_DROP_TRIGGER;
119947 const char *zDb = db->aDb[iDb].zName;
119948 const char *zTab = SCHEMA_TABLE(iDb);
119949 if( iDb==1 ) code = SQLITE_DROP_TEMP_TRIGGER;
119950 if( sqlite3AuthCheck(pParse, code, pTrigger->zName, pTable->zName, zDb) ||
119951 sqlite3AuthCheck(pParse, SQLITE_DELETE, zTab, 0, zDb) ){
119952 return;
@@ -119958,11 +119995,11 @@
119958 */
119959 assert( pTable!=0 );
119960 if( (v = sqlite3GetVdbe(pParse))!=0 ){
119961 sqlite3NestedParse(pParse,
119962 "DELETE FROM %Q.%s WHERE name=%Q AND type='trigger'",
119963 db->aDb[iDb].zName, SCHEMA_TABLE(iDb), pTrigger->zName
119964 );
119965 sqlite3ChangeCookie(pParse, iDb);
119966 sqlite3VdbeAddOp4(v, OP_DropTrigger, iDb, 0, 0, pTrigger->zName, 0);
119967 }
119968 }
@@ -120061,12 +120098,14 @@
120061 if( pSrc ){
120062 assert( pSrc->nSrc>0 );
120063 pSrc->a[pSrc->nSrc-1].zName = sqlite3DbStrDup(db, pStep->zTarget);
120064 iDb = sqlite3SchemaToIndex(db, pStep->pTrig->pSchema);
120065 if( iDb==0 || iDb>=2 ){
 
120066 assert( iDb<db->nDb );
120067 pSrc->a[pSrc->nSrc-1].zDatabase = sqlite3DbStrDup(db, db->aDb[iDb].zName);
 
120068 }
120069 }
120070 return pSrc;
120071 }
120072
@@ -120749,11 +120788,11 @@
120749 #ifndef SQLITE_OMIT_AUTHORIZATION
120750 {
120751 int rc;
120752 rc = sqlite3AuthCheck(pParse, SQLITE_UPDATE, pTab->zName,
120753 j<0 ? "ROWID" : pTab->aCol[j].zName,
120754 db->aDb[iDb].zName);
120755 if( rc==SQLITE_DENY ){
120756 goto update_cleanup;
120757 }else if( rc==SQLITE_IGNORE ){
120758 aXRef[j] = -1;
120759 }
@@ -121351,61 +121390,56 @@
121351 */
121352 /* #include "sqliteInt.h" */
121353 /* #include "vdbeInt.h" */
121354
121355 #if !defined(SQLITE_OMIT_VACUUM) && !defined(SQLITE_OMIT_ATTACH)
121356 /*
121357 ** Finalize a prepared statement. If there was an error, store the
121358 ** text of the error message in *pzErrMsg. Return the result code.
121359 */
121360 static int vacuumFinalize(sqlite3 *db, sqlite3_stmt *pStmt, char **pzErrMsg){
121361 int rc;
121362 rc = sqlite3VdbeFinalize((Vdbe*)pStmt);
121363 if( rc ){
121364 sqlite3SetString(pzErrMsg, db, sqlite3_errmsg(db));
121365 }
121366 return rc;
121367 }
121368
121369 /*
121370 ** Execute zSql on database db. Return an error code.
121371 */
121372 static int execSql(sqlite3 *db, char **pzErrMsg, const char *zSql){
121373 sqlite3_stmt *pStmt;
121374 VVA_ONLY( int rc; )
121375 if( !zSql ){
121376 return SQLITE_NOMEM_BKPT;
 
 
 
 
 
 
 
 
 
 
121377 }
121378 if( SQLITE_OK!=sqlite3_prepare(db, zSql, -1, &pStmt, 0) ){
 
 
121379 sqlite3SetString(pzErrMsg, db, sqlite3_errmsg(db));
121380 return sqlite3_errcode(db);
121381 }
121382 VVA_ONLY( rc = ) sqlite3_step(pStmt);
121383 assert( rc!=SQLITE_ROW || (db->flags&SQLITE_CountRows) );
121384 return vacuumFinalize(db, pStmt, pzErrMsg);
121385 }
121386
121387 /*
121388 ** Execute zSql on database db. The statement returns exactly
121389 ** one column. Execute this as SQL on the same database.
121390 */
121391 static int execExecSql(sqlite3 *db, char **pzErrMsg, const char *zSql){
121392 sqlite3_stmt *pStmt;
121393 int rc;
121394
121395 rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
121396 if( rc!=SQLITE_OK ) return rc;
121397
121398 while( SQLITE_ROW==sqlite3_step(pStmt) ){
121399 rc = execSql(db, pzErrMsg, (char*)sqlite3_column_text(pStmt, 0));
121400 if( rc!=SQLITE_OK ){
121401 vacuumFinalize(db, pStmt, pzErrMsg);
121402 return rc;
121403 }
121404 }
121405
121406 return vacuumFinalize(db, pStmt, pzErrMsg);
121407 }
121408
121409 /*
121410 ** The VACUUM command is used to clean up the database,
121411 ** collapse free space, etc. It is modelled after the VACUUM command
@@ -121434,35 +121468,36 @@
121434 ** not work if other processes are attached to the original database.
121435 ** And a power loss in between deleting the original and renaming the
121436 ** transient would cause the database file to appear to be deleted
121437 ** following reboot.
121438 */
121439 SQLITE_PRIVATE void sqlite3Vacuum(Parse *pParse){
121440 Vdbe *v = sqlite3GetVdbe(pParse);
121441 if( v ){
121442 sqlite3VdbeAddOp2(v, OP_Vacuum, 0, 0);
121443 sqlite3VdbeUsesBtree(v, 0);
 
121444 }
121445 return;
121446 }
121447
121448 /*
121449 ** This routine implements the OP_Vacuum opcode of the VDBE.
121450 */
121451 SQLITE_PRIVATE int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){
121452 int rc = SQLITE_OK; /* Return code from service routines */
121453 Btree *pMain; /* The database being vacuumed */
121454 Btree *pTemp; /* The temporary database we vacuum into */
121455 char *zSql = 0; /* SQL statements */
121456 int saved_flags; /* Saved value of the db->flags */
121457 int saved_nChange; /* Saved value of db->nChange */
121458 int saved_nTotalChange; /* Saved value of db->nTotalChange */
121459 u8 saved_mTrace; /* Saved trace settings */
121460 Db *pDb = 0; /* Database to detach at end of vacuum */
121461 int isMemDb; /* True if vacuuming a :memory: database */
121462 int nRes; /* Bytes of reserved space at the end of each page */
121463 int nDb; /* Number of attached databases */
 
121464
121465 if( !db->autoCommit ){
121466 sqlite3SetString(pzErrMsg, db, "cannot VACUUM from within a transaction");
121467 return SQLITE_ERROR;
121468 }
@@ -121476,15 +121511,17 @@
121476 ** disable CHECK and foreign key constraints. */
121477 saved_flags = db->flags;
121478 saved_nChange = db->nChange;
121479 saved_nTotalChange = db->nTotalChange;
121480 saved_mTrace = db->mTrace;
121481 db->flags |= SQLITE_WriteSchema | SQLITE_IgnoreChecks | SQLITE_PreferBuiltin;
121482 db->flags &= ~(SQLITE_ForeignKeys | SQLITE_ReverseOrder);
 
121483 db->mTrace = 0;
121484
121485 pMain = db->aDb[0].pBt;
 
121486 isMemDb = sqlite3PagerIsMemdb(sqlite3BtreePager(pMain));
121487
121488 /* Attach the temporary database as 'vacuum_db'. The synchronous pragma
121489 ** can be set to 'off' for this file, as it is not recovered if a crash
121490 ** occurs anyway. The integrity of the database is maintained by a
@@ -121498,22 +121535,16 @@
121498 ** empty. Only the journal header is written. Apparently it takes more
121499 ** time to parse and run the PRAGMA to turn journalling off than it does
121500 ** to write the journal header file.
121501 */
121502 nDb = db->nDb;
121503 if( sqlite3TempInMemory(db) ){
121504 zSql = "ATTACH ':memory:' AS vacuum_db;";
121505 }else{
121506 zSql = "ATTACH '' AS vacuum_db;";
121507 }
121508 rc = execSql(db, pzErrMsg, zSql);
121509 if( db->nDb>nDb ){
121510 pDb = &db->aDb[db->nDb-1];
121511 assert( strcmp(pDb->zName,"vacuum_db")==0 );
121512 }
121513 if( rc!=SQLITE_OK ) goto end_of_vacuum;
121514 pTemp = db->aDb[db->nDb-1].pBt;
 
 
 
121515
121516 /* The call to execSql() to attach the temp database has left the file
121517 ** locked (as there was more than one active statement when the transaction
121518 ** to read the schema was concluded. Unlock it here so that this doesn't
121519 ** cause problems for the call to BtreeSetPageSize() below. */
@@ -121530,20 +121561,19 @@
121530 sqlite3CodecGetKey(db, 0, (void**)&zKey, &nKey);
121531 if( nKey ) db->nextPagesize = 0;
121532 }
121533 #endif
121534
121535 sqlite3BtreeSetCacheSize(pTemp, db->aDb[0].pSchema->cache_size);
121536 sqlite3BtreeSetSpillSize(pTemp, sqlite3BtreeSetSpillSize(pMain,0));
121537 rc = execSql(db, pzErrMsg, "PRAGMA vacuum_db.synchronous=OFF");
121538 if( rc!=SQLITE_OK ) goto end_of_vacuum;
121539
121540 /* Begin a transaction and take an exclusive lock on the main database
121541 ** file. This is done before the sqlite3BtreeGetPageSize(pMain) call below,
121542 ** to ensure that we do not try to change the page-size on a WAL database.
121543 */
121544 rc = execSql(db, pzErrMsg, "BEGIN;");
121545 if( rc!=SQLITE_OK ) goto end_of_vacuum;
121546 rc = sqlite3BtreeBeginTrans(pMain, 2);
121547 if( rc!=SQLITE_OK ) goto end_of_vacuum;
121548
121549 /* Do not attempt to change the page size for a WAL database */
@@ -121566,68 +121596,52 @@
121566 #endif
121567
121568 /* Query the schema of the main database. Create a mirror schema
121569 ** in the temporary database.
121570 */
121571 rc = execExecSql(db, pzErrMsg,
121572 "SELECT 'CREATE TABLE vacuum_db.' || substr(sql,14) "
121573 " FROM sqlite_master WHERE type='table' AND name!='sqlite_sequence'"
121574 " AND coalesce(rootpage,1)>0"
 
 
 
 
 
 
 
 
121575 );
121576 if( rc!=SQLITE_OK ) goto end_of_vacuum;
121577 rc = execExecSql(db, pzErrMsg,
121578 "SELECT 'CREATE INDEX vacuum_db.' || substr(sql,14)"
121579 " FROM sqlite_master WHERE sql LIKE 'CREATE INDEX %' ");
121580 if( rc!=SQLITE_OK ) goto end_of_vacuum;
121581 rc = execExecSql(db, pzErrMsg,
121582 "SELECT 'CREATE UNIQUE INDEX vacuum_db.' || substr(sql,21) "
121583 " FROM sqlite_master WHERE sql LIKE 'CREATE UNIQUE INDEX %'");
121584 if( rc!=SQLITE_OK ) goto end_of_vacuum;
121585
121586 /* Loop through the tables in the main database. For each, do
121587 ** an "INSERT INTO vacuum_db.xxx SELECT * FROM main.xxx;" to copy
121588 ** the contents to the temporary database.
121589 */
121590 assert( (db->flags & SQLITE_Vacuum)==0 );
121591 db->flags |= SQLITE_Vacuum;
121592 rc = execExecSql(db, pzErrMsg,
121593 "SELECT 'INSERT INTO vacuum_db.' || quote(name) "
121594 "|| ' SELECT * FROM main.' || quote(name) || ';'"
121595 "FROM main.sqlite_master "
121596 "WHERE type = 'table' AND name!='sqlite_sequence' "
121597 " AND coalesce(rootpage,1)>0"
121598 );
121599 assert( (db->flags & SQLITE_Vacuum)!=0 );
121600 db->flags &= ~SQLITE_Vacuum;
121601 if( rc!=SQLITE_OK ) goto end_of_vacuum;
121602
121603 /* Copy over the sequence table
121604 */
121605 rc = execExecSql(db, pzErrMsg,
121606 "SELECT 'DELETE FROM vacuum_db.' || quote(name) || ';' "
121607 "FROM vacuum_db.sqlite_master WHERE name='sqlite_sequence' "
121608 );
121609 if( rc!=SQLITE_OK ) goto end_of_vacuum;
121610 rc = execExecSql(db, pzErrMsg,
121611 "SELECT 'INSERT INTO vacuum_db.' || quote(name) "
121612 "|| ' SELECT * FROM main.' || quote(name) || ';' "
121613 "FROM vacuum_db.sqlite_master WHERE name=='sqlite_sequence';"
121614 );
121615 if( rc!=SQLITE_OK ) goto end_of_vacuum;
121616
121617
121618 /* Copy the triggers, views, and virtual tables from the main database
121619 ** over to the temporary database. None of these objects has any
121620 ** associated storage, so all we have to do is copy their entries
121621 ** from the SQLITE_MASTER table.
121622 */
121623 rc = execSql(db, pzErrMsg,
121624 "INSERT INTO vacuum_db.sqlite_master "
121625 " SELECT type, name, tbl_name, rootpage, sql"
121626 " FROM main.sqlite_master"
121627 " WHERE type='view' OR type='trigger'"
121628 " OR (type='table' AND rootpage=0)"
121629 );
121630 if( rc ) goto end_of_vacuum;
121631
121632 /* At this point, there is a write transaction open on both the
121633 ** vacuum database and the main database. Assuming no error occurs,
@@ -121677,10 +121691,11 @@
121677 assert( rc==SQLITE_OK );
121678 rc = sqlite3BtreeSetPageSize(pMain, sqlite3BtreeGetPageSize(pTemp), nRes,1);
121679
121680 end_of_vacuum:
121681 /* Restore the original value of db->flags */
 
121682 db->flags = saved_flags;
121683 db->nChange = saved_nChange;
121684 db->nTotalChange = saved_nTotalChange;
121685 db->mTrace = saved_mTrace;
121686 sqlite3BtreeSetPageSize(pMain, -1, -1, 1);
@@ -122055,11 +122070,11 @@
122055 ** sqlite_master table, has already been made by sqlite3StartTable().
122056 ** The second call, to obtain permission to create the table, is made now.
122057 */
122058 if( pTable->azModuleArg ){
122059 sqlite3AuthCheck(pParse, SQLITE_CREATE_VTABLE, pTable->zName,
122060 pTable->azModuleArg[0], pParse->db->aDb[iDb].zName);
122061 }
122062 #endif
122063 }
122064
122065 /*
@@ -122119,11 +122134,11 @@
122119 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
122120 sqlite3NestedParse(pParse,
122121 "UPDATE %Q.%s "
122122 "SET type='table', name=%Q, tbl_name=%Q, rootpage=0, sql=%Q "
122123 "WHERE rowid=#%d",
122124 db->aDb[iDb].zName, SCHEMA_TABLE(iDb),
122125 pTab->zName,
122126 pTab->zName,
122127 zStmt,
122128 pParse->regRowid
122129 );
@@ -122229,11 +122244,11 @@
122229 }
122230 pVTable->db = db;
122231 pVTable->pMod = pMod;
122232
122233 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
122234 pTab->azModuleArg[1] = db->aDb[iDb].zName;
122235
122236 /* Invoke the virtual table constructor */
122237 assert( &db->pVtabCtx );
122238 assert( xConstruct );
122239 sCtx.pTab = pTab;
@@ -122393,11 +122408,11 @@
122393 int rc = SQLITE_OK;
122394 Table *pTab;
122395 Module *pMod;
122396 const char *zMod;
122397
122398 pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zName);
122399 assert( pTab && (pTab->tabFlags & TF_Virtual)!=0 && !pTab->pVTable );
122400
122401 /* Locate the required virtual table module */
122402 zMod = pTab->azModuleArg[0];
122403 pMod = (Module*)sqlite3HashFind(&db->aModule, zMod);
@@ -122517,11 +122532,11 @@
122517 */
122518 SQLITE_PRIVATE int sqlite3VtabCallDestroy(sqlite3 *db, int iDb, const char *zTab){
122519 int rc = SQLITE_OK;
122520 Table *pTab;
122521
122522 pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zName);
122523 if( pTab!=0 && ALWAYS(pTab->pVTable!=0) ){
122524 VTable *p;
122525 int (*xDestroy)(sqlite3_vtab *);
122526 for(p=pTab->pVTable; p; p=p->pNext){
122527 assert( p->pVtab );
@@ -125630,11 +125645,11 @@
125630 */
125631 static int isMatchOfColumn(
125632 Expr *pExpr, /* Test this expression */
125633 unsigned char *peOp2 /* OUT: 0 for MATCH, or else an op2 value */
125634 ){
125635 struct Op2 {
125636 const char *zOp;
125637 unsigned char eOp2;
125638 } aOp[] = {
125639 { "match", SQLITE_INDEX_CONSTRAINT_MATCH },
125640 { "glob", SQLITE_INDEX_CONSTRAINT_GLOB },
@@ -126615,17 +126630,18 @@
126615 ** These routines walk (recursively) an expression tree and generate
126616 ** a bitmask indicating which tables are used in that expression
126617 ** tree.
126618 */
126619 SQLITE_PRIVATE Bitmask sqlite3WhereExprUsage(WhereMaskSet *pMaskSet, Expr *p){
126620 Bitmask mask = 0;
126621 if( p==0 ) return 0;
126622 if( p->op==TK_COLUMN ){
126623 mask = sqlite3WhereGetMask(pMaskSet, p->iTable);
126624 return mask;
126625 }
126626 mask = sqlite3WhereExprUsage(pMaskSet, p->pRight);
 
126627 if( p->pLeft ) mask |= sqlite3WhereExprUsage(pMaskSet, p->pLeft);
126628 if( ExprHasProperty(p, EP_xIsSelect) ){
126629 mask |= exprSelectUsage(pMaskSet, p->x.pSelect);
126630 }else if( p->x.pList ){
126631 mask |= sqlite3WhereExprListUsage(pMaskSet, p->x.pList);
@@ -131868,29 +131884,33 @@
131868 ** N between YY_MIN_SHIFTREDUCE Shift to an arbitrary state then
131869 ** and YY_MAX_SHIFTREDUCE reduce by rule N-YY_MIN_SHIFTREDUCE.
131870 **
131871 ** N between YY_MIN_REDUCE Reduce by rule N-YY_MIN_REDUCE
131872 ** and YY_MAX_REDUCE
131873
131874 ** N == YY_ERROR_ACTION A syntax error has occurred.
131875 **
131876 ** N == YY_ACCEPT_ACTION The parser accepts its input.
131877 **
131878 ** N == YY_NO_ACTION No such action. Denotes unused
131879 ** slots in the yy_action[] table.
131880 **
131881 ** The action table is constructed as a single large table named yy_action[].
131882 ** Given state S and lookahead X, the action is computed as
131883 **
131884 ** yy_action[ yy_shift_ofst[S] + X ]
131885 **
131886 ** If the index value yy_shift_ofst[S]+X is out of range or if the value
131887 ** yy_lookahead[yy_shift_ofst[S]+X] is not equal to X or if yy_shift_ofst[S]
131888 ** is equal to YY_SHIFT_USE_DFLT, it means that the action is not in the table
131889 ** and that yy_default[S] should be used instead.
131890 **
131891 ** The formula above is for computing the action when the lookahead is
 
 
 
 
131892 ** a terminal symbol. If the lookahead is a non-terminal (as occurs after
131893 ** a reduce action) then the yy_reduce_ofst[] array is used in place of
131894 ** the yy_shift_ofst[] array and YY_REDUCE_USE_DFLT is used in place of
131895 ** YY_SHIFT_USE_DFLT.
131896 **
@@ -132211,14 +132231,14 @@
132211 /* 1470 */ 122, 23, 23, 64, 22, 124, 26, 26, 64, 64,
132212 /* 1480 */ 23, 23, 23, 23, 11, 23, 22, 26, 23, 22,
132213 /* 1490 */ 24, 1, 23, 22, 26, 122, 24, 23, 22, 122,
132214 /* 1500 */ 23, 23, 22, 122, 122, 23, 15,
132215 };
132216 #define YY_SHIFT_USE_DFLT (-95)
132217 #define YY_SHIFT_COUNT (442)
132218 #define YY_SHIFT_MIN (-94)
132219 #define YY_SHIFT_MAX (1491)
132220 static const short yy_shift_ofst[] = {
132221 /* 0 */ 40, 564, 869, 577, 725, 725, 725, 725, 690, -19,
132222 /* 10 */ 16, 16, 100, 725, 725, 725, 725, 725, 725, 725,
132223 /* 20 */ 841, 841, 538, 507, 684, 565, 61, 137, 172, 207,
132224 /* 30 */ 242, 277, 312, 347, 382, 424, 424, 424, 424, 424,
@@ -132227,16 +132247,16 @@
132227 /* 60 */ 725, 725, 725, 725, 725, 725, 725, 725, 725, 725,
132228 /* 70 */ 725, 725, 725, 725, 725, 725, 725, 725, 725, 725,
132229 /* 80 */ 725, 725, 725, 725, 821, 725, 725, 725, 725, 725,
132230 /* 90 */ 725, 725, 725, 725, 725, 725, 725, 725, 952, 711,
132231 /* 100 */ 711, 711, 711, 711, 766, 23, 32, 924, 637, 825,
132232 /* 110 */ 837, 837, 924, 73, 183, -51, -95, -95, -95, 501,
132233 /* 120 */ 501, 501, 903, 903, 632, 205, 241, 924, 924, 924,
132234 /* 130 */ 924, 924, 924, 924, 924, 924, 924, 924, 924, 924,
132235 /* 140 */ 924, 924, 924, 924, 924, 924, 924, 192, 1027, 1106,
132236 /* 150 */ 1106, 183, 176, 176, 176, 176, 176, 176, -95, -95,
132237 /* 160 */ -95, 880, -94, -94, 578, 734, 99, 730, 769, 349,
132238 /* 170 */ 924, 924, 924, 924, 924, 924, 924, 924, 924, 924,
132239 /* 180 */ 924, 924, 924, 924, 924, 924, 924, 954, 954, 954,
132240 /* 190 */ 924, 924, 622, 924, 924, 924, -18, 924, 924, 914,
132241 /* 200 */ 924, 924, 924, 924, 924, 924, 924, 924, 924, 924,
132242 /* 210 */ 441, 1020, 1107, 1107, 1107, 569, 45, 217, 510, 423,
@@ -132246,12 +132266,12 @@
132246 /* 250 */ 1297, 1183, 1277, 1285, 1285, 1183, 1176, 1297, 1182, 1250,
132247 /* 260 */ 1176, 1176, 1297, 1311, 1176, 1297, 1176, 1297, 1311, 1234,
132248 /* 270 */ 1234, 1234, 1267, 1311, 1234, 1244, 1234, 1267, 1234, 1234,
132249 /* 280 */ 1232, 1247, 1232, 1247, 1232, 1247, 1232, 1247, 1176, 1334,
132250 /* 290 */ 1176, 1235, 1311, 1318, 1318, 1311, 1248, 1253, 1245, 1249,
132251 /* 300 */ 1183, 1355, 1357, 1368, 1368, 1378, 1378, 1378, 1378, -95,
132252 /* 310 */ -95, -95, -95, -95, -95, -95, -95, 451, 936, 816,
132253 /* 320 */ 888, 1069, 799, 1111, 1197, 1193, 1201, 1202, 1203, 1213,
132254 /* 330 */ 1134, 1117, 1230, 497, 1218, 1219, 1154, 1223, 1115, 1120,
132255 /* 340 */ 1231, 1164, 1160, 1392, 1394, 1376, 1257, 1385, 1307, 1386,
132256 /* 350 */ 1383, 1388, 1292, 1282, 1303, 1294, 1395, 1293, 1403, 1419,
132257 /* 360 */ 1298, 1291, 1389, 1390, 1314, 1372, 1365, 1308, 1430, 1427,
@@ -133200,54 +133220,51 @@
133200
133201 if( stateno>=YY_MIN_REDUCE ) return stateno;
133202 assert( stateno <= YY_SHIFT_COUNT );
133203 do{
133204 i = yy_shift_ofst[stateno];
133205 if( i==YY_SHIFT_USE_DFLT ) return yy_default[stateno];
133206 assert( iLookAhead!=YYNOCODE );
133207 i += iLookAhead;
133208 if( i<0 || i>=YY_ACTTAB_COUNT || yy_lookahead[i]!=iLookAhead ){
133209 if( iLookAhead>0 ){
133210 #ifdef YYFALLBACK
133211 YYCODETYPE iFallback; /* Fallback token */
133212 if( iLookAhead<sizeof(yyFallback)/sizeof(yyFallback[0])
133213 && (iFallback = yyFallback[iLookAhead])!=0 ){
133214 #ifndef NDEBUG
133215 if( yyTraceFILE ){
133216 fprintf(yyTraceFILE, "%sFALLBACK %s => %s\n",
133217 yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]);
133218 }
133219 #endif
133220 assert( yyFallback[iFallback]==0 ); /* Fallback loop must terminate */
133221 iLookAhead = iFallback;
133222 continue;
133223 }
133224 #endif
133225 #ifdef YYWILDCARD
133226 {
133227 int j = i - iLookAhead + YYWILDCARD;
133228 if(
133229 #if YY_SHIFT_MIN+YYWILDCARD<0
133230 j>=0 &&
133231 #endif
133232 #if YY_SHIFT_MAX+YYWILDCARD>=YY_ACTTAB_COUNT
133233 j<YY_ACTTAB_COUNT &&
133234 #endif
133235 yy_lookahead[j]==YYWILDCARD
133236 ){
133237 #ifndef NDEBUG
133238 if( yyTraceFILE ){
133239 fprintf(yyTraceFILE, "%sWILDCARD %s => %s\n",
133240 yyTracePrompt, yyTokenName[iLookAhead],
133241 yyTokenName[YYWILDCARD]);
133242 }
133243 #endif /* NDEBUG */
133244 return yy_action[j];
133245 }
133246 }
 
133247 #endif /* YYWILDCARD */
133248 }
133249 return yy_default[stateno];
133250 }else{
133251 return yy_action[i];
133252 }
133253 }while(1);
@@ -134679,12 +134696,14 @@
134679 break;
134680 case 213: /* cmd ::= DROP INDEX ifexists fullname */
134681 {sqlite3DropIndex(pParse, yymsp[0].minor.yy185, yymsp[-1].minor.yy194);}
134682 break;
134683 case 214: /* cmd ::= VACUUM */
134684 case 215: /* cmd ::= VACUUM nm */ yytestcase(yyruleno==215);
134685 {sqlite3Vacuum(pParse);}
 
 
134686 break;
134687 case 216: /* cmd ::= PRAGMA nm dbnm */
134688 {sqlite3Pragma(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,0,0);}
134689 break;
134690 case 217: /* cmd ::= PRAGMA nm dbnm EQ nmnum */
@@ -136006,18 +136025,30 @@
136006 assert( pParse->pNewTable==0 );
136007 assert( pParse->pNewTrigger==0 );
136008 assert( pParse->nVar==0 );
136009 assert( pParse->nzVar==0 );
136010 assert( pParse->azVar==0 );
136011 while( zSql[i]!=0 ){
136012 assert( i>=0 );
136013 pParse->sLastToken.z = &zSql[i];
136014 pParse->sLastToken.n = sqlite3GetToken((unsigned char*)&zSql[i],&tokenType);
136015 i += pParse->sLastToken.n;
136016 if( i>mxSqlLen ){
136017 pParse->rc = SQLITE_TOOBIG;
136018 break;
 
 
 
 
 
 
 
 
 
 
 
 
136019 }
136020 if( tokenType>=TK_SPACE ){
136021 assert( tokenType==TK_SPACE || tokenType==TK_ILLEGAL );
136022 if( db->u1.isInterrupted ){
136023 pParse->rc = SQLITE_INTERRUPT;
@@ -136034,19 +136065,10 @@
136034 if( pParse->rc!=SQLITE_OK || db->mallocFailed ) break;
136035 }
136036 }
136037 assert( nErr==0 );
136038 pParse->zTail = &zSql[i];
136039 if( pParse->rc==SQLITE_OK && db->mallocFailed==0 ){
136040 assert( zSql[i]==0 );
136041 if( lastTokenParsed!=TK_SEMI ){
136042 sqlite3Parser(pEngine, TK_SEMI, pParse->sLastToken, pParse);
136043 }
136044 if( pParse->rc==SQLITE_OK && db->mallocFailed==0 ){
136045 sqlite3Parser(pEngine, 0, pParse->sLastToken, pParse);
136046 }
136047 }
136048 #ifdef YYTRACKMAXSTACKDEPTH
136049 sqlite3_mutex_enter(sqlite3MallocMutex());
136050 sqlite3StatusHighwater(SQLITE_STATUS_PARSER_STACK,
136051 sqlite3ParserStackPeak(pEngine)
136052 );
@@ -137282,10 +137304,15 @@
137282 SQLITE_API int SQLITE_CDECL sqlite3_db_config(sqlite3 *db, int op, ...){
137283 va_list ap;
137284 int rc;
137285 va_start(ap, op);
137286 switch( op ){
 
 
 
 
 
137287 case SQLITE_DBCONFIG_LOOKASIDE: {
137288 void *pBuf = va_arg(ap, void*); /* IMP: R-26835-10964 */
137289 int sz = va_arg(ap, int); /* IMP: R-47871-25994 */
137290 int cnt = va_arg(ap, int); /* IMP: R-04460-53386 */
137291 rc = setupLookaside(db, pBuf, sz, cnt);
@@ -139425,13 +139452,13 @@
139425 db->aDb[1].pSchema = sqlite3SchemaGet(db, 0);
139426
139427 /* The default safety_level for the main database is FULL; for the temp
139428 ** database it is OFF. This matches the pager layer defaults.
139429 */
139430 db->aDb[0].zName = "main";
139431 db->aDb[0].safety_level = SQLITE_DEFAULT_SYNCHRONOUS+1;
139432 db->aDb[1].zName = "temp";
139433 db->aDb[1].safety_level = PAGER_SYNCHRONOUS_OFF;
139434
139435 db->magic = SQLITE_MAGIC_OPEN;
139436 if( db->mallocFailed ){
139437 goto opendb_out;
@@ -140388,11 +140415,11 @@
140388 */
140389 SQLITE_PRIVATE Btree *sqlite3DbNameToBtree(sqlite3 *db, const char *zDbName){
140390 int i;
140391 for(i=0; i<db->nDb; i++){
140392 if( db->aDb[i].pBt
140393 && (zDbName==0 || sqlite3StrICmp(zDbName, db->aDb[i].zName)==0)
140394 ){
140395 return db->aDb[i].pBt;
140396 }
140397 }
140398 return 0;
@@ -164754,19 +164781,25 @@
164754 /*
164755 ** Open an RBU handle to perform an RBU vacuum on database file zTarget.
164756 ** An RBU vacuum is similar to SQLite's built-in VACUUM command, except
164757 ** that it can be suspended and resumed like an RBU update.
164758 **
164759 ** The second argument to this function, which may not be NULL, identifies
164760 ** a database in which to store the state of the RBU vacuum operation if
164761 ** it is suspended. The first time sqlite3rbu_vacuum() is called, to start
164762 ** an RBU vacuum operation, the state database should either not exist or
164763 ** be empty (contain no tables). If an RBU vacuum is suspended by calling
164764 ** sqlite3rbu_close() on the RBU handle before sqlite3rbu_step() has
164765 ** returned SQLITE_DONE, the vacuum state is stored in the state database.
164766 ** The vacuum can be resumed by calling this function to open a new RBU
164767 ** handle specifying the same target and state databases.
 
 
 
 
 
 
164768 **
164769 ** This function does not delete the state database after an RBU vacuum
164770 ** is completed, even if it created it. However, if the call to
164771 ** sqlite3rbu_close() returns any value other than SQLITE_OK, the contents
164772 ** of the state tables within the state database are zeroed. This way,
@@ -167255,19 +167288,22 @@
167255 /*
167256 ** Open the database handle and attach the RBU database as "rbu". If an
167257 ** error occurs, leave an error code and message in the RBU handle.
167258 */
167259 static void rbuOpenDatabase(sqlite3rbu *p){
167260 assert( p->rc==SQLITE_OK );
167261 assert( p->dbMain==0 && p->dbRbu==0 );
167262 assert( rbuIsVacuum(p) || p->zTarget!=0 );
167263
167264 /* Open the RBU database */
167265 p->dbRbu = rbuOpenDbhandle(p, p->zRbu, 1);
167266
167267 if( p->rc==SQLITE_OK && rbuIsVacuum(p) ){
167268 sqlite3_file_control(p->dbRbu, "main", SQLITE_FCNTL_RBUCNT, (void*)p);
 
 
 
 
167269 }
167270
167271 /* If using separate RBU and state databases, attach the state database to
167272 ** the RBU db handle now. */
167273 if( p->zState ){
@@ -168398,12 +168434,11 @@
168398 const char *zState
168399 ){
168400 sqlite3rbu *p;
168401 size_t nTarget = zTarget ? strlen(zTarget) : 0;
168402 size_t nRbu = strlen(zRbu);
168403 size_t nState = zState ? strlen(zState) : 0;
168404 size_t nByte = sizeof(sqlite3rbu) + nTarget+1 + nRbu+1+ nState+1;
168405
168406 p = (sqlite3rbu*)sqlite3_malloc64(nByte);
168407 if( p ){
168408 RbuState *pState = 0;
168409
@@ -168421,12 +168456,11 @@
168421 }
168422 p->zRbu = pCsr;
168423 memcpy(p->zRbu, zRbu, nRbu+1);
168424 pCsr += nRbu+1;
168425 if( zState ){
168426 p->zState = pCsr;
168427 memcpy(p->zState, zState, nState+1);
168428 }
168429 rbuOpenDatabase(p);
168430 }
168431
168432 if( p->rc==SQLITE_OK ){
@@ -168531,19 +168565,34 @@
168531 rbuFreeState(pState);
168532 }
168533
168534 return p;
168535 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
168536
168537 /*
168538 ** Open and return a new RBU handle.
168539 */
168540 SQLITE_API sqlite3rbu *SQLITE_STDCALL sqlite3rbu_open(
168541 const char *zTarget,
168542 const char *zRbu,
168543 const char *zState
168544 ){
 
168545 /* TODO: Check that zTarget and zRbu are non-NULL */
168546 return openRbuHandle(zTarget, zRbu, zState);
168547 }
168548
168549 /*
@@ -168551,10 +168600,11 @@
168551 */
168552 SQLITE_API sqlite3rbu *SQLITE_STDCALL sqlite3rbu_vacuum(
168553 const char *zTarget,
168554 const char *zState
168555 ){
 
168556 /* TODO: Check that both arguments are non-NULL */
168557 return openRbuHandle(0, zTarget, zState);
168558 }
168559
168560 /*
@@ -168628,10 +168678,11 @@
168628 sqlite3_free(p->aFrame);
168629
168630 rbuEditErrmsg(p);
168631 rc = p->rc;
168632 *pzErrmsg = p->zErrmsg;
 
168633 sqlite3_free(p);
168634 }else{
168635 rc = SQLITE_NOMEM;
168636 *pzErrmsg = 0;
168637 }
@@ -170239,11 +170290,11 @@
170239 zSql = sqlite3_mprintf(
170240 "SELECT 'sqlite_master' AS name, 1 AS rootpage, 'table' AS type"
170241 " UNION ALL "
170242 "SELECT name, rootpage, type"
170243 " FROM \"%w\".%s WHERE rootpage!=0"
170244 " ORDER BY name", pTab->db->aDb[pCsr->iDb].zName, zMaster);
170245 if( zSql==0 ){
170246 return SQLITE_NOMEM_BKPT;
170247 }else{
170248 rc = sqlite3_prepare_v2(pTab->db, zSql, -1, &pCsr->pStmt, 0);
170249 sqlite3_free(zSql);
@@ -170293,11 +170344,11 @@
170293 sqlite3_result_int(ctx, pCsr->szPage);
170294 break;
170295 default: { /* schema */
170296 sqlite3 *db = sqlite3_context_db_handle(ctx);
170297 int iDb = pCsr->iDb;
170298 sqlite3_result_text(ctx, db->aDb[iDb].zName, -1, SQLITE_STATIC);
170299 break;
170300 }
170301 }
170302 return SQLITE_OK;
170303 }
@@ -178530,10 +178581,11 @@
178530 static void sqlite3Fts5ParseNearsetFree(Fts5ExprNearset*);
178531 static void sqlite3Fts5ParseNodeFree(Fts5ExprNode*);
178532
178533 static void sqlite3Fts5ParseSetDistance(Fts5Parse*, Fts5ExprNearset*, Fts5Token*);
178534 static void sqlite3Fts5ParseSetColset(Fts5Parse*, Fts5ExprNearset*, Fts5Colset*);
 
178535 static void sqlite3Fts5ParseFinished(Fts5Parse *pParse, Fts5ExprNode *p);
178536 static void sqlite3Fts5ParseNear(Fts5Parse *pParse, Fts5Token*);
178537
178538 /*
178539 ** End of interface to code in fts5_expr.c.
@@ -178587,16 +178639,17 @@
178587 #define FTS5_NOT 3
178588 #define FTS5_TERM 4
178589 #define FTS5_COLON 5
178590 #define FTS5_LP 6
178591 #define FTS5_RP 7
178592 #define FTS5_LCP 8
178593 #define FTS5_RCP 9
178594 #define FTS5_STRING 10
178595 #define FTS5_COMMA 11
178596 #define FTS5_PLUS 12
178597 #define FTS5_STAR 13
 
178598
178599 /*
178600 ** 2000-05-29
178601 **
178602 ** The author disclaims copyright to this source code. In place of
@@ -178706,39 +178759,39 @@
178706 #ifndef INTERFACE
178707 # define INTERFACE 1
178708 #endif
178709 /************* Begin control #defines *****************************************/
178710 #define fts5YYCODETYPE unsigned char
178711 #define fts5YYNOCODE 27
178712 #define fts5YYACTIONTYPE unsigned char
178713 #define sqlite3Fts5ParserFTS5TOKENTYPE Fts5Token
178714 typedef union {
178715 int fts5yyinit;
178716 sqlite3Fts5ParserFTS5TOKENTYPE fts5yy0;
178717 Fts5Colset* fts5yy3;
178718 Fts5ExprPhrase* fts5yy11;
178719 Fts5ExprNode* fts5yy18;
178720 int fts5yy20;
178721 Fts5ExprNearset* fts5yy26;
178722 } fts5YYMINORTYPE;
178723 #ifndef fts5YYSTACKDEPTH
178724 #define fts5YYSTACKDEPTH 100
178725 #endif
178726 #define sqlite3Fts5ParserARG_SDECL Fts5Parse *pParse;
178727 #define sqlite3Fts5ParserARG_PDECL ,Fts5Parse *pParse
178728 #define sqlite3Fts5ParserARG_FETCH Fts5Parse *pParse = fts5yypParser->pParse
178729 #define sqlite3Fts5ParserARG_STORE fts5yypParser->pParse = pParse
178730 #define fts5YYNSTATE 26
178731 #define fts5YYNRULE 24
178732 #define fts5YY_MAX_SHIFT 25
178733 #define fts5YY_MIN_SHIFTREDUCE 40
178734 #define fts5YY_MAX_SHIFTREDUCE 63
178735 #define fts5YY_MIN_REDUCE 64
178736 #define fts5YY_MAX_REDUCE 87
178737 #define fts5YY_ERROR_ACTION 88
178738 #define fts5YY_ACCEPT_ACTION 89
178739 #define fts5YY_NO_ACTION 90
178740 /************* End control #defines *******************************************/
178741
178742 /* Define the fts5yytestcase() macro to be a no-op if is not already defined
178743 ** otherwise.
178744 **
@@ -178766,29 +178819,33 @@
178766 ** N between fts5YY_MIN_SHIFTREDUCE Shift to an arbitrary state then
178767 ** and fts5YY_MAX_SHIFTREDUCE reduce by rule N-fts5YY_MIN_SHIFTREDUCE.
178768 **
178769 ** N between fts5YY_MIN_REDUCE Reduce by rule N-fts5YY_MIN_REDUCE
178770 ** and fts5YY_MAX_REDUCE
178771
178772 ** N == fts5YY_ERROR_ACTION A syntax error has occurred.
178773 **
178774 ** N == fts5YY_ACCEPT_ACTION The parser accepts its input.
178775 **
178776 ** N == fts5YY_NO_ACTION No such action. Denotes unused
178777 ** slots in the fts5yy_action[] table.
178778 **
178779 ** The action table is constructed as a single large table named fts5yy_action[].
178780 ** Given state S and lookahead X, the action is computed as
178781 **
178782 ** fts5yy_action[ fts5yy_shift_ofst[S] + X ]
178783 **
178784 ** If the index value fts5yy_shift_ofst[S]+X is out of range or if the value
178785 ** fts5yy_lookahead[fts5yy_shift_ofst[S]+X] is not equal to X or if fts5yy_shift_ofst[S]
178786 ** is equal to fts5YY_SHIFT_USE_DFLT, it means that the action is not in the table
178787 ** and that fts5yy_default[S] should be used instead.
178788 **
178789 ** The formula above is for computing the action when the lookahead is
 
 
 
 
178790 ** a terminal symbol. If the lookahead is a non-terminal (as occurs after
178791 ** a reduce action) then the fts5yy_reduce_ofst[] array is used in place of
178792 ** the fts5yy_shift_ofst[] array and fts5YY_REDUCE_USE_DFLT is used in place of
178793 ** fts5YY_SHIFT_USE_DFLT.
178794 **
@@ -178802,52 +178859,54 @@
178802 ** fts5yy_reduce_ofst[] For each state, the offset into fts5yy_action for
178803 ** shifting non-terminals after a reduce.
178804 ** fts5yy_default[] Default action for each state.
178805 **
178806 *********** Begin parsing tables **********************************************/
178807 #define fts5YY_ACTTAB_COUNT (78)
178808 static const fts5YYACTIONTYPE fts5yy_action[] = {
178809 /* 0 */ 89, 15, 46, 5, 48, 24, 12, 19, 23, 14,
178810 /* 10 */ 46, 5, 48, 24, 20, 21, 23, 43, 46, 5,
178811 /* 20 */ 48, 24, 6, 18, 23, 17, 46, 5, 48, 24,
178812 /* 30 */ 75, 7, 23, 25, 46, 5, 48, 24, 62, 47,
178813 /* 40 */ 23, 48, 24, 7, 11, 23, 9, 3, 4, 2,
178814 /* 50 */ 62, 50, 52, 44, 64, 3, 4, 2, 49, 4,
178815 /* 60 */ 2, 1, 23, 11, 16, 9, 12, 2, 10, 61,
178816 /* 70 */ 53, 59, 62, 60, 22, 13, 55, 8,
 
178817 };
178818 static const fts5YYCODETYPE fts5yy_lookahead[] = {
178819 /* 0 */ 15, 16, 17, 18, 19, 20, 10, 11, 23, 16,
178820 /* 10 */ 17, 18, 19, 20, 23, 24, 23, 16, 17, 18,
178821 /* 20 */ 19, 20, 22, 23, 23, 16, 17, 18, 19, 20,
178822 /* 30 */ 5, 6, 23, 16, 17, 18, 19, 20, 13, 17,
178823 /* 40 */ 23, 19, 20, 6, 8, 23, 10, 1, 2, 3,
178824 /* 50 */ 13, 9, 10, 7, 0, 1, 2, 3, 19, 2,
178825 /* 60 */ 3, 6, 23, 8, 21, 10, 10, 3, 10, 25,
178826 /* 70 */ 10, 10, 13, 25, 12, 10, 7, 5,
178827 };
178828 #define fts5YY_SHIFT_USE_DFLT (-5)
178829 #define fts5YY_SHIFT_COUNT (25)
178830 #define fts5YY_SHIFT_MIN (-4)
178831 #define fts5YY_SHIFT_MAX (72)
178832 static const signed char fts5yy_shift_ofst[] = {
178833 /* 0 */ 55, 55, 55, 55, 55, 36, -4, 56, 58, 25,
178834 /* 10 */ 37, 60, 59, 59, 46, 54, 42, 57, 62, 61,
178835 /* 20 */ 62, 69, 65, 62, 72, 64,
178836 };
178837 #define fts5YY_REDUCE_USE_DFLT (-16)
178838 #define fts5YY_REDUCE_COUNT (13)
178839 #define fts5YY_REDUCE_MIN (-15)
178840 #define fts5YY_REDUCE_MAX (48)
 
178841 static const signed char fts5yy_reduce_ofst[] = {
178842 /* 0 */ -15, -7, 1, 9, 17, 22, -9, 0, 39, 44,
178843 /* 10 */ 44, 43, 44, 48,
178844 };
178845 static const fts5YYACTIONTYPE fts5yy_default[] = {
178846 /* 0 */ 88, 88, 88, 88, 88, 69, 82, 88, 88, 87,
178847 /* 10 */ 87, 88, 87, 87, 88, 88, 88, 66, 80, 88,
178848 /* 20 */ 81, 88, 88, 78, 88, 65,
178849 };
178850 /********** End of lemon-generated parsing tables *****************************/
178851
178852 /* The next table maps tokens (terminal symbols) into fallback tokens.
178853 ** If a construct like the following:
@@ -178950,15 +179009,15 @@
178950 /* For tracing shifts, the names of all terminals and nonterminals
178951 ** are required. The following table supplies these names */
178952 static const char *const fts5yyTokenName[] = {
178953 "$", "OR", "AND", "NOT",
178954 "TERM", "COLON", "LP", "RP",
178955 "LCP", "RCP", "STRING", "COMMA",
178956 "PLUS", "STAR", "error", "input",
178957 "expr", "cnearset", "exprlist", "nearset",
178958 "colset", "colsetlist", "nearphrases", "phrase",
178959 "neardist_opt", "star_opt",
178960 };
178961 #endif /* NDEBUG */
178962
178963 #ifndef NDEBUG
178964 /* For tracing reduce actions, the names of all rules are required.
@@ -178972,24 +179031,26 @@
178972 /* 5 */ "expr ::= exprlist",
178973 /* 6 */ "exprlist ::= cnearset",
178974 /* 7 */ "exprlist ::= exprlist cnearset",
178975 /* 8 */ "cnearset ::= nearset",
178976 /* 9 */ "cnearset ::= colset COLON nearset",
178977 /* 10 */ "colset ::= LCP colsetlist RCP",
178978 /* 11 */ "colset ::= STRING",
178979 /* 12 */ "colsetlist ::= colsetlist STRING",
178980 /* 13 */ "colsetlist ::= STRING",
178981 /* 14 */ "nearset ::= phrase",
178982 /* 15 */ "nearset ::= STRING LP nearphrases neardist_opt RP",
178983 /* 16 */ "nearphrases ::= phrase",
178984 /* 17 */ "nearphrases ::= nearphrases phrase",
178985 /* 18 */ "neardist_opt ::=",
178986 /* 19 */ "neardist_opt ::= COMMA STRING",
178987 /* 20 */ "phrase ::= phrase PLUS STRING star_opt",
178988 /* 21 */ "phrase ::= STRING star_opt",
178989 /* 22 */ "star_opt ::= STAR",
178990 /* 23 */ "star_opt ::=",
 
 
178991 };
178992 #endif /* NDEBUG */
178993
178994
178995 #if fts5YYSTACKDEPTH<=0
@@ -179095,37 +179156,37 @@
179095 ** Note: during a reduce, the only symbols destroyed are those
179096 ** which appear on the RHS of the rule, but which are *not* used
179097 ** inside the C code.
179098 */
179099 /********* Begin destructor definitions ***************************************/
179100 case 15: /* input */
179101 {
179102 (void)pParse;
179103 }
179104 break;
179105 case 16: /* expr */
179106 case 17: /* cnearset */
179107 case 18: /* exprlist */
179108 {
179109 sqlite3Fts5ParseNodeFree((fts5yypminor->fts5yy18));
179110 }
179111 break;
179112 case 19: /* nearset */
179113 case 22: /* nearphrases */
179114 {
179115 sqlite3Fts5ParseNearsetFree((fts5yypminor->fts5yy26));
179116 }
179117 break;
179118 case 20: /* colset */
179119 case 21: /* colsetlist */
179120 {
179121 sqlite3_free((fts5yypminor->fts5yy3));
179122 }
179123 break;
179124 case 23: /* phrase */
179125 {
179126 sqlite3Fts5ParsePhraseFree((fts5yypminor->fts5yy11));
179127 }
179128 break;
179129 /********* End destructor definitions *****************************************/
179130 default: break; /* If no destructor action specified: do nothing */
179131 }
@@ -179198,54 +179259,51 @@
179198
179199 if( stateno>=fts5YY_MIN_REDUCE ) return stateno;
179200 assert( stateno <= fts5YY_SHIFT_COUNT );
179201 do{
179202 i = fts5yy_shift_ofst[stateno];
179203 if( i==fts5YY_SHIFT_USE_DFLT ) return fts5yy_default[stateno];
179204 assert( iLookAhead!=fts5YYNOCODE );
179205 i += iLookAhead;
179206 if( i<0 || i>=fts5YY_ACTTAB_COUNT || fts5yy_lookahead[i]!=iLookAhead ){
179207 if( iLookAhead>0 ){
179208 #ifdef fts5YYFALLBACK
179209 fts5YYCODETYPE iFallback; /* Fallback token */
179210 if( iLookAhead<sizeof(fts5yyFallback)/sizeof(fts5yyFallback[0])
179211 && (iFallback = fts5yyFallback[iLookAhead])!=0 ){
179212 #ifndef NDEBUG
179213 if( fts5yyTraceFILE ){
179214 fprintf(fts5yyTraceFILE, "%sFALLBACK %s => %s\n",
179215 fts5yyTracePrompt, fts5yyTokenName[iLookAhead], fts5yyTokenName[iFallback]);
179216 }
179217 #endif
179218 assert( fts5yyFallback[iFallback]==0 ); /* Fallback loop must terminate */
179219 iLookAhead = iFallback;
179220 continue;
179221 }
179222 #endif
179223 #ifdef fts5YYWILDCARD
179224 {
179225 int j = i - iLookAhead + fts5YYWILDCARD;
179226 if(
179227 #if fts5YY_SHIFT_MIN+fts5YYWILDCARD<0
179228 j>=0 &&
179229 #endif
179230 #if fts5YY_SHIFT_MAX+fts5YYWILDCARD>=fts5YY_ACTTAB_COUNT
179231 j<fts5YY_ACTTAB_COUNT &&
179232 #endif
179233 fts5yy_lookahead[j]==fts5YYWILDCARD
179234 ){
179235 #ifndef NDEBUG
179236 if( fts5yyTraceFILE ){
179237 fprintf(fts5yyTraceFILE, "%sWILDCARD %s => %s\n",
179238 fts5yyTracePrompt, fts5yyTokenName[iLookAhead],
179239 fts5yyTokenName[fts5YYWILDCARD]);
179240 }
179241 #endif /* NDEBUG */
179242 return fts5yy_action[j];
179243 }
179244 }
 
179245 #endif /* fts5YYWILDCARD */
179246 }
179247 return fts5yy_default[stateno];
179248 }else{
179249 return fts5yy_action[i];
179250 }
179251 }while(1);
@@ -179368,34 +179426,36 @@
179368 */
179369 static const struct {
179370 fts5YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */
179371 unsigned char nrhs; /* Number of right-hand side symbols in the rule */
179372 } fts5yyRuleInfo[] = {
179373 { 15, 1 },
179374 { 16, 3 },
179375 { 16, 3 },
179376 { 16, 3 },
179377 { 16, 3 },
179378 { 16, 1 },
 
 
 
 
 
 
 
179379 { 18, 1 },
179380 { 18, 2 },
179381 { 17, 1 },
179382 { 17, 3 },
179383 { 20, 3 },
179384 { 20, 1 },
179385 { 21, 2 },
179386 { 21, 1 },
179387 { 19, 1 },
179388 { 19, 5 },
179389 { 22, 1 },
179390 { 22, 2 },
179391 { 24, 0 },
179392 { 24, 2 },
179393 { 23, 4 },
179394 { 23, 2 },
179395 { 25, 1 },
179396 { 25, 0 },
 
 
 
 
 
179397 };
179398
179399 static void fts5yy_accept(fts5yyParser*); /* Forward Declaration */
179400
179401 /*
@@ -179456,124 +179516,135 @@
179456 ** break;
179457 */
179458 /********** Begin reduce actions **********************************************/
179459 fts5YYMINORTYPE fts5yylhsminor;
179460 case 0: /* input ::= expr */
179461 { sqlite3Fts5ParseFinished(pParse, fts5yymsp[0].minor.fts5yy18); }
179462 break;
179463 case 1: /* expr ::= expr AND expr */
179464 {
179465 fts5yylhsminor.fts5yy18 = sqlite3Fts5ParseNode(pParse, FTS5_AND, fts5yymsp[-2].minor.fts5yy18, fts5yymsp[0].minor.fts5yy18, 0);
179466 }
179467 fts5yymsp[-2].minor.fts5yy18 = fts5yylhsminor.fts5yy18;
179468 break;
179469 case 2: /* expr ::= expr OR expr */
179470 {
179471 fts5yylhsminor.fts5yy18 = sqlite3Fts5ParseNode(pParse, FTS5_OR, fts5yymsp[-2].minor.fts5yy18, fts5yymsp[0].minor.fts5yy18, 0);
179472 }
179473 fts5yymsp[-2].minor.fts5yy18 = fts5yylhsminor.fts5yy18;
179474 break;
179475 case 3: /* expr ::= expr NOT expr */
179476 {
179477 fts5yylhsminor.fts5yy18 = sqlite3Fts5ParseNode(pParse, FTS5_NOT, fts5yymsp[-2].minor.fts5yy18, fts5yymsp[0].minor.fts5yy18, 0);
179478 }
179479 fts5yymsp[-2].minor.fts5yy18 = fts5yylhsminor.fts5yy18;
179480 break;
179481 case 4: /* expr ::= LP expr RP */
179482 {fts5yymsp[-2].minor.fts5yy18 = fts5yymsp[-1].minor.fts5yy18;}
179483 break;
179484 case 5: /* expr ::= exprlist */
179485 case 6: /* exprlist ::= cnearset */ fts5yytestcase(fts5yyruleno==6);
179486 {fts5yylhsminor.fts5yy18 = fts5yymsp[0].minor.fts5yy18;}
179487 fts5yymsp[0].minor.fts5yy18 = fts5yylhsminor.fts5yy18;
179488 break;
179489 case 7: /* exprlist ::= exprlist cnearset */
179490 {
179491 fts5yylhsminor.fts5yy18 = sqlite3Fts5ParseImplicitAnd(pParse, fts5yymsp[-1].minor.fts5yy18, fts5yymsp[0].minor.fts5yy18);
179492 }
179493 fts5yymsp[-1].minor.fts5yy18 = fts5yylhsminor.fts5yy18;
179494 break;
179495 case 8: /* cnearset ::= nearset */
179496 {
179497 fts5yylhsminor.fts5yy18 = sqlite3Fts5ParseNode(pParse, FTS5_STRING, 0, 0, fts5yymsp[0].minor.fts5yy26);
179498 }
179499 fts5yymsp[0].minor.fts5yy18 = fts5yylhsminor.fts5yy18;
179500 break;
179501 case 9: /* cnearset ::= colset COLON nearset */
179502 {
179503 sqlite3Fts5ParseSetColset(pParse, fts5yymsp[0].minor.fts5yy26, fts5yymsp[-2].minor.fts5yy3);
179504 fts5yylhsminor.fts5yy18 = sqlite3Fts5ParseNode(pParse, FTS5_STRING, 0, 0, fts5yymsp[0].minor.fts5yy26);
179505 }
179506 fts5yymsp[-2].minor.fts5yy18 = fts5yylhsminor.fts5yy18;
179507 break;
179508 case 10: /* colset ::= LCP colsetlist RCP */
179509 { fts5yymsp[-2].minor.fts5yy3 = fts5yymsp[-1].minor.fts5yy3; }
179510 break;
179511 case 11: /* colset ::= STRING */
179512 {
179513 fts5yylhsminor.fts5yy3 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
179514 }
179515 fts5yymsp[0].minor.fts5yy3 = fts5yylhsminor.fts5yy3;
179516 break;
179517 case 12: /* colsetlist ::= colsetlist STRING */
179518 {
179519 fts5yylhsminor.fts5yy3 = sqlite3Fts5ParseColset(pParse, fts5yymsp[-1].minor.fts5yy3, &fts5yymsp[0].minor.fts5yy0); }
179520 fts5yymsp[-1].minor.fts5yy3 = fts5yylhsminor.fts5yy3;
179521 break;
179522 case 13: /* colsetlist ::= STRING */
179523 {
179524 fts5yylhsminor.fts5yy3 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
179525 }
179526 fts5yymsp[0].minor.fts5yy3 = fts5yylhsminor.fts5yy3;
179527 break;
179528 case 14: /* nearset ::= phrase */
179529 { fts5yylhsminor.fts5yy26 = sqlite3Fts5ParseNearset(pParse, 0, fts5yymsp[0].minor.fts5yy11); }
179530 fts5yymsp[0].minor.fts5yy26 = fts5yylhsminor.fts5yy26;
179531 break;
179532 case 15: /* nearset ::= STRING LP nearphrases neardist_opt RP */
 
 
 
 
 
 
 
 
 
 
 
179533 {
179534 sqlite3Fts5ParseNear(pParse, &fts5yymsp[-4].minor.fts5yy0);
179535 sqlite3Fts5ParseSetDistance(pParse, fts5yymsp[-2].minor.fts5yy26, &fts5yymsp[-1].minor.fts5yy0);
179536 fts5yylhsminor.fts5yy26 = fts5yymsp[-2].minor.fts5yy26;
179537 }
179538 fts5yymsp[-4].minor.fts5yy26 = fts5yylhsminor.fts5yy26;
179539 break;
179540 case 16: /* nearphrases ::= phrase */
179541 {
179542 fts5yylhsminor.fts5yy26 = sqlite3Fts5ParseNearset(pParse, 0, fts5yymsp[0].minor.fts5yy11);
179543 }
179544 fts5yymsp[0].minor.fts5yy26 = fts5yylhsminor.fts5yy26;
179545 break;
179546 case 17: /* nearphrases ::= nearphrases phrase */
179547 {
179548 fts5yylhsminor.fts5yy26 = sqlite3Fts5ParseNearset(pParse, fts5yymsp[-1].minor.fts5yy26, fts5yymsp[0].minor.fts5yy11);
179549 }
179550 fts5yymsp[-1].minor.fts5yy26 = fts5yylhsminor.fts5yy26;
179551 break;
179552 case 18: /* neardist_opt ::= */
179553 { fts5yymsp[1].minor.fts5yy0.p = 0; fts5yymsp[1].minor.fts5yy0.n = 0; }
179554 break;
179555 case 19: /* neardist_opt ::= COMMA STRING */
179556 { fts5yymsp[-1].minor.fts5yy0 = fts5yymsp[0].minor.fts5yy0; }
179557 break;
179558 case 20: /* phrase ::= phrase PLUS STRING star_opt */
179559 {
179560 fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseTerm(pParse, fts5yymsp[-3].minor.fts5yy11, &fts5yymsp[-1].minor.fts5yy0, fts5yymsp[0].minor.fts5yy20);
179561 }
179562 fts5yymsp[-3].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
179563 break;
179564 case 21: /* phrase ::= STRING star_opt */
179565 {
179566 fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseTerm(pParse, 0, &fts5yymsp[-1].minor.fts5yy0, fts5yymsp[0].minor.fts5yy20);
179567 }
179568 fts5yymsp[-1].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
179569 break;
179570 case 22: /* star_opt ::= STAR */
179571 { fts5yymsp[0].minor.fts5yy20 = 1; }
179572 break;
179573 case 23: /* star_opt ::= */
179574 { fts5yymsp[1].minor.fts5yy20 = 0; }
179575 break;
179576 default:
179577 break;
179578 /********** End reduce actions ************************************************/
179579 };
@@ -180027,11 +180098,11 @@
180027 }
180028
180029 if( p->iRangeEnd>0 && iPos==p->iRangeEnd ){
180030 fts5HighlightAppend(&rc, p, &p->zIn[p->iOff], iEndOff - p->iOff);
180031 p->iOff = iEndOff;
180032 if( iPos<p->iter.iEnd ){
180033 fts5HighlightAppend(&rc, p, p->zClose, -1);
180034 }
180035 }
180036
180037 return rc;
@@ -180188,10 +180259,17 @@
180188 ctx.iRangeEnd = iBestStart + nToken - 1;
180189
180190 if( iBestStart>0 ){
180191 fts5HighlightAppend(&rc, &ctx, zEllips, -1);
180192 }
 
 
 
 
 
 
 
180193 if( rc==SQLITE_OK ){
180194 rc = pApi->xTokenize(pFts, ctx.zIn, ctx.nIn, (void*)&ctx,fts5HighlightCb);
180195 }
180196 if( ctx.iRangeEnd>=(nColSize-1) ){
180197 fts5HighlightAppend(&rc, &ctx, &ctx.zIn[ctx.iOff], ctx.nIn - ctx.iOff);
@@ -181923,10 +182001,11 @@
181923 case '}': tok = FTS5_RCP; break;
181924 case ':': tok = FTS5_COLON; break;
181925 case ',': tok = FTS5_COMMA; break;
181926 case '+': tok = FTS5_PLUS; break;
181927 case '*': tok = FTS5_STAR; break;
 
181928 case '\0': tok = FTS5_EOF; break;
181929
181930 case '"': {
181931 const char *z2;
181932 tok = FTS5_STRING;
@@ -183414,11 +183493,11 @@
183414 sizeof(Fts5ExprNearset) + sizeof(Fts5ExprPhrase*));
183415 }
183416 if( rc==SQLITE_OK ){
183417 Fts5Colset *pColsetOrig = pOrig->pNode->pNear->pColset;
183418 if( pColsetOrig ){
183419 int nByte = sizeof(Fts5Colset) + pColsetOrig->nCol * sizeof(int);
183420 Fts5Colset *pColset = (Fts5Colset*)sqlite3Fts5MallocZero(&rc, nByte);
183421 if( pColset ){
183422 memcpy(pColset, pColsetOrig, nByte);
183423 }
183424 pNew->pRoot->pNear->pColset = pColset;
@@ -183548,10 +183627,38 @@
183548 #endif
183549 }
183550
183551 return pNew;
183552 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
183553
183554 static Fts5Colset *sqlite3Fts5ParseColset(
183555 Fts5Parse *pParse, /* Store SQLITE_NOMEM here if required */
183556 Fts5Colset *pColset, /* Existing colset object */
183557 Fts5Token *p
@@ -185644,18 +185751,29 @@
185644
185645 assert( (pRet==0)==(p->rc!=SQLITE_OK) );
185646 return pRet;
185647 }
185648
185649
185650 /*
185651 ** Release a reference to data record returned by an earlier call to
185652 ** fts5DataRead().
185653 */
185654 static void fts5DataRelease(Fts5Data *pData){
185655 sqlite3_free(pData);
185656 }
 
 
 
 
 
 
 
 
 
 
 
 
185657
185658 static int fts5IndexPrepareStmt(
185659 Fts5Index *p,
185660 sqlite3_stmt **ppStmt,
185661 char *zSql
@@ -186461,11 +186579,11 @@
186461 pIter->iLeafPgno++;
186462 if( pIter->pNextLeaf ){
186463 pIter->pLeaf = pIter->pNextLeaf;
186464 pIter->pNextLeaf = 0;
186465 }else if( pIter->iLeafPgno<=pSeg->pgnoLast ){
186466 pIter->pLeaf = fts5DataRead(p,
186467 FTS5_SEGMENT_ROWID(pSeg->iSegid, pIter->iLeafPgno)
186468 );
186469 }else{
186470 pIter->pLeaf = 0;
186471 }
@@ -186964,13 +187082,12 @@
186964 pIter->iLeafOffset = iOff;
186965
186966 if( pLeaf->nn>pLeaf->szLeaf ){
186967 pIter->iPgidxOff = pLeaf->szLeaf + fts5GetVarint32(
186968 &pLeaf->p[pLeaf->szLeaf], pIter->iEndofDoclist
186969 );
186970 }
186971
186972 }
186973 else if( pLeaf->nn>pLeaf->szLeaf ){
186974 pIter->iPgidxOff = pLeaf->szLeaf + fts5GetVarint32(
186975 &pLeaf->p[pLeaf->szLeaf], iOff
186976 );
@@ -187210,10 +187327,15 @@
187210 }
187211
187212 iPgidx += fts5GetVarint32(&a[iPgidx], nKeep);
187213 iTermOff += nKeep;
187214 iOff = iTermOff;
 
 
 
 
 
187215
187216 /* Read the nKeep field of the next term. */
187217 fts5FastGetVarint32(a, iOff, nKeep);
187218 }
187219
@@ -188136,10 +188258,19 @@
188136 fts5BufferZero(&pIter->poslist);
188137 fts5SegiterPoslist(pIter->pIndex, pSeg, 0, &pIter->poslist);
188138 pIter->base.pData = pIter->poslist.p;
188139 }
188140 }
 
 
 
 
 
 
 
 
 
188141
188142 /*
188143 ** xSetOutputs callback used by detail=col when there is a column filter
188144 ** and there are 100 or more columns. Also called as a fallback from
188145 ** fts5IterSetOutputs_Col100 if the column-list spans more than one page.
@@ -188241,10 +188372,14 @@
188241 }
188242
188243 else if( pIter->pColset==0 ){
188244 pIter->xSetOutputs = fts5IterSetOutputs_Nocolset;
188245 }
 
 
 
 
188246
188247 else if( pConfig->eDetail==FTS5_DETAIL_FULL ){
188248 pIter->xSetOutputs = fts5IterSetOutputs_Full;
188249 }
188250
@@ -194018,11 +194153,11 @@
194018 int nArg, /* Number of args */
194019 sqlite3_value **apUnused /* Function arguments */
194020 ){
194021 assert( nArg==0 );
194022 UNUSED_PARAM2(nArg, apUnused);
194023 sqlite3_result_text(pCtx, "fts5: 2016-08-11 18:53:32 a12d8059770df4bca59e321c266410344242bf7b", -1, SQLITE_TRANSIENT);
194024 }
194025
194026 static int fts5Init(sqlite3 *db){
194027 static const sqlite3_module fts5Mod = {
194028 /* iVersion */ 2,
194029
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.15.0. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a single translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% or more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -378,13 +378,13 @@
378 **
379 ** See also: [sqlite3_libversion()],
380 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
381 ** [sqlite_version()] and [sqlite_source_id()].
382 */
383 #define SQLITE_VERSION "3.15.0"
384 #define SQLITE_VERSION_NUMBER 3015000
385 #define SQLITE_SOURCE_ID "2016-08-22 20:10:01 7839519349c7371cdb4e16a215eacd27004cbc62"
386
387 /*
388 ** CAPI3REF: Run-Time Library Version Numbers
389 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
390 **
@@ -2227,12 +2227,22 @@
2227 ** is written 0 or 1 to indicate whether [sqlite3_load_extension()] interface
2228 ** is disabled or enabled following this call. The second parameter may
2229 ** be a NULL pointer, in which case the new setting is not reported back.
2230 ** </dd>
2231 **
2232 ** <dt>SQLITE_DBCONFIG_MAINDBNAME</dt>
2233 ** <dd> ^This option is used to change the name of the "main" database
2234 ** schema. ^The sole argument is a pointer to a constant UTF8 string
2235 ** which will become the new schema name in place of "main". ^SQLite
2236 ** does not make a copy of the new main schema name string, so the application
2237 ** must ensure that the argument passed into this DBCONFIG option is unchanged
2238 ** until after the database connection closes.
2239 ** </dd>
2240 **
2241 ** </dl>
2242 */
2243 #define SQLITE_DBCONFIG_MAINDBNAME 1000 /* const char* */
2244 #define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
2245 #define SQLITE_DBCONFIG_ENABLE_FKEY 1002 /* int int* */
2246 #define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */
2247 #define SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1004 /* int int* */
2248 #define SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION 1005 /* int int* */
@@ -13694,11 +13704,11 @@
13704 ** in the sqlite.aDb[] array. aDb[0] is the main database file and
13705 ** aDb[1] is the database file used to hold temporary tables. Additional
13706 ** databases may be attached.
13707 */
13708 struct Db {
13709 char *zDbSName; /* Name of this database. (schema name, not filename) */
13710 Btree *pBt; /* The B*Tree structure for this database file */
13711 u8 safety_level; /* How aggressive at syncing data to disk */
13712 u8 bSyncSet; /* True if "PRAGMA synchronous=N" has been run */
13713 Schema *pSchema; /* Pointer to database schema (possibly shared) */
13714 };
@@ -16298,12 +16308,12 @@
16308 SQLITE_PRIVATE Table *sqlite3LocateTable(Parse*,u32 flags,const char*, const char*);
16309 SQLITE_PRIVATE Table *sqlite3LocateTableItem(Parse*,u32 flags,struct SrcList_item *);
16310 SQLITE_PRIVATE Index *sqlite3FindIndex(sqlite3*,const char*, const char*);
16311 SQLITE_PRIVATE void sqlite3UnlinkAndDeleteTable(sqlite3*,int,const char*);
16312 SQLITE_PRIVATE void sqlite3UnlinkAndDeleteIndex(sqlite3*,int,const char*);
16313 SQLITE_PRIVATE void sqlite3Vacuum(Parse*,Token*);
16314 SQLITE_PRIVATE int sqlite3RunVacuum(char**, sqlite3*, int);
16315 SQLITE_PRIVATE char *sqlite3NameFromToken(sqlite3*, Token*);
16316 SQLITE_PRIVATE int sqlite3ExprCompare(Expr*, Expr*, int);
16317 SQLITE_PRIVATE int sqlite3ExprListCompare(ExprList*, ExprList*, int);
16318 SQLITE_PRIVATE int sqlite3ExprImpliesExpr(Expr*, Expr*, int);
16319 SQLITE_PRIVATE void sqlite3ExprAnalyzeAggregates(NameContext*, Expr*);
@@ -34851,10 +34861,31 @@
34861 unixLeaveMutex();
34862 }
34863 #endif /* if !OS_VXWORKS */
34864 return pUnused;
34865 }
34866
34867 /*
34868 ** Find the mode, uid and gid of file zFile.
34869 */
34870 static int getFileMode(
34871 const char *zFile, /* File name */
34872 mode_t *pMode, /* OUT: Permissions of zFile */
34873 uid_t *pUid, /* OUT: uid of zFile. */
34874 gid_t *pGid /* OUT: gid of zFile. */
34875 ){
34876 struct stat sStat; /* Output of stat() on database file */
34877 int rc = SQLITE_OK;
34878 if( 0==osStat(zFile, &sStat) ){
34879 *pMode = sStat.st_mode & 0777;
34880 *pUid = sStat.st_uid;
34881 *pGid = sStat.st_gid;
34882 }else{
34883 rc = SQLITE_IOERR_FSTAT;
34884 }
34885 return rc;
34886 }
34887
34888 /*
34889 ** This function is called by unixOpen() to determine the unix permissions
34890 ** to create new files with. If no error occurs, then SQLITE_OK is returned
34891 ** and a value suitable for passing as the third argument to open(2) is
@@ -34887,11 +34918,10 @@
34918 *pUid = 0;
34919 *pGid = 0;
34920 if( flags & (SQLITE_OPEN_WAL|SQLITE_OPEN_MAIN_JOURNAL) ){
34921 char zDb[MAX_PATHNAME+1]; /* Database file path */
34922 int nDb; /* Number of valid bytes in zDb */
 
34923
34924 /* zPath is a path to a WAL or journal file. The following block derives
34925 ** the path to the associated database file from zPath. This block handles
34926 ** the following naming conventions:
34927 **
@@ -34918,19 +34948,22 @@
34948 nDb--;
34949 }
34950 memcpy(zDb, zPath, nDb);
34951 zDb[nDb] = '\0';
34952
34953 rc = getFileMode(zDb, pMode, pUid, pGid);
 
 
 
 
 
 
34954 }else if( flags & SQLITE_OPEN_DELETEONCLOSE ){
34955 *pMode = 0600;
34956 }else if( flags & SQLITE_OPEN_URI ){
34957 /* If this is a main database file and the file was opened using a URI
34958 ** filename, check for the "modeof" parameter. If present, interpret
34959 ** its value as a filename and try to copy the mode, uid and gid from
34960 ** that file. */
34961 const char *z = sqlite3_uri_parameter(zPath, "modeof");
34962 if( z ){
34963 rc = getFileMode(z, pMode, pUid, pGid);
34964 }
34965 }
34966 return rc;
34967 }
34968
34969 /*
@@ -75441,11 +75474,11 @@
75474 int nEntry;
75475 sqlite3BtreeEnter(pBt);
75476 nEntry = sqlite3PagerWalCallback(sqlite3BtreePager(pBt));
75477 sqlite3BtreeLeave(pBt);
75478 if( db->xWalCallback && nEntry>0 && rc==SQLITE_OK ){
75479 rc = db->xWalCallback(db->pWalArg, db, db->aDb[i].zDbSName, nEntry);
75480 }
75481 }
75482 }
75483 #endif
75484 return rc;
@@ -81472,11 +81505,11 @@
81505 }
81506
81507 if( pOp->p4type==P4_TABLE && HAS_UPDATE_HOOK(db) ){
81508 assert( pC->isTable );
81509 assert( pC->iDb>=0 );
81510 zDb = db->aDb[pC->iDb].zDbSName;
81511 pTab = pOp->p4.pTab;
81512 assert( HasRowid(pTab) );
81513 op = ((pOp->p5 & OPFLAG_ISUPDATE) ? SQLITE_UPDATE : SQLITE_INSERT);
81514 }else{
81515 pTab = 0; /* Not needed. Silence a comiler warning. */
@@ -81589,11 +81622,11 @@
81622 ** last moved with OP_Next or OP_Prev, not Seek or NotFound, set
81623 ** VdbeCursor.movetoTarget to the current rowid. */
81624 if( pOp->p4type==P4_TABLE && HAS_UPDATE_HOOK(db) ){
81625 assert( pC->iDb>=0 );
81626 assert( pOp->p4.pTab!=0 );
81627 zDb = db->aDb[pC->iDb].zDbSName;
81628 pTab = pOp->p4.pTab;
81629 if( (pOp->p5 & OPFLAG_SAVEPOSITION)!=0 && pC->isTable ){
81630 pC->movetoTarget = sqlite3BtreeIntegerKey(pC->uc.pCursor);
81631 }
81632 }else{
@@ -82559,11 +82592,11 @@
82592 initData.db = db;
82593 initData.iDb = pOp->p1;
82594 initData.pzErrMsg = &p->zErrMsg;
82595 zSql = sqlite3MPrintf(db,
82596 "SELECT name, rootpage, sql FROM '%q'.%s WHERE %s ORDER BY rowid",
82597 db->aDb[iDb].zDbSName, zMaster, pOp->p4.z);
82598 if( zSql==0 ){
82599 rc = SQLITE_NOMEM_BKPT;
82600 }else{
82601 assert( db->init.busy==0 );
82602 db->init.busy = 1;
@@ -83388,19 +83421,18 @@
83421 break;
83422 };
83423 #endif /* SQLITE_OMIT_PRAGMA */
83424
83425 #if !defined(SQLITE_OMIT_VACUUM) && !defined(SQLITE_OMIT_ATTACH)
83426 /* Opcode: Vacuum P1 * * * *
83427 **
83428 ** Vacuum the entire database P1. P1 is 0 for "main", and 2 or more
83429 ** for an attached database. The "temp" database may not be vacuumed.
 
83430 */
83431 case OP_Vacuum: {
83432 assert( p->readOnly==0 );
83433 rc = sqlite3RunVacuum(&p->zErrMsg, db, pOp->p1);
83434 if( rc ) goto abort_due_to_error;
83435 break;
83436 }
83437 #endif
83438
@@ -83943,11 +83975,11 @@
83975 zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql);
83976 if( zTrace ){
83977 int i;
83978 for(i=0; i<db->nDb; i++){
83979 if( DbMaskTest(p->btreeMask, i)==0 ) continue;
83980 sqlite3_file_control(db, db->aDb[i].zDbSName, SQLITE_FCNTL_TRACE, zTrace);
83981 }
83982 }
83983 #endif /* SQLITE_USE_FCNTL_TRACE */
83984 #ifdef SQLITE_DEBUG
83985 if( (db->flags & SQLITE_SqlTrace)!=0
@@ -84279,11 +84311,11 @@
84311 rc = SQLITE_ERROR;
84312 sqlite3BtreeLeaveAll(db);
84313 goto blob_open_out;
84314 }
84315 pBlob->pTab = pTab;
84316 pBlob->zDb = db->aDb[sqlite3SchemaToIndex(db, pTab->pSchema)].zDbSName;
84317
84318 /* Now search pTab for the exact column. */
84319 for(iCol=0; iCol<pTab->nCol; iCol++) {
84320 if( sqlite3StrICmp(pTab->aCol[iCol].zName, zColumn)==0 ){
84321 break;
@@ -87831,21 +87863,19 @@
87863 static SQLITE_NOINLINE int walkExpr(Walker *pWalker, Expr *pExpr){
87864 int rc;
87865 testcase( ExprHasProperty(pExpr, EP_TokenOnly) );
87866 testcase( ExprHasProperty(pExpr, EP_Reduced) );
87867 rc = pWalker->xExprCallback(pWalker, pExpr);
87868 if( rc || ExprHasProperty(pExpr,EP_TokenOnly) ) return rc & WRC_Abort;
87869 if( pExpr->pLeft && walkExpr(pWalker, pExpr->pLeft) ) return WRC_Abort;
87870 if( pExpr->pRight && walkExpr(pWalker, pExpr->pRight) ) return WRC_Abort;
87871 if( ExprHasProperty(pExpr, EP_xIsSelect) ){
87872 if( sqlite3WalkSelect(pWalker, pExpr->x.pSelect) ) return WRC_Abort;
87873 }else{
87874 if( sqlite3WalkExprList(pWalker, pExpr->x.pList) ) return WRC_Abort;
87875 }
87876 return WRC_Continue;
 
 
87877 }
87878 SQLITE_PRIVATE int sqlite3WalkExpr(Walker *pWalker, Expr *pExpr){
87879 return pExpr ? walkExpr(pWalker,pExpr) : WRC_Continue;
87880 }
87881
@@ -88175,12 +88205,12 @@
88205 ** legacy and because it does not hurt anything to just ignore the
88206 ** database name. */
88207 zDb = 0;
88208 }else{
88209 for(i=0; i<db->nDb; i++){
88210 assert( db->aDb[i].zDbSName );
88211 if( sqlite3StrICmp(db->aDb[i].zDbSName,zDb)==0 ){
88212 pSchema = db->aDb[i].pSchema;
88213 break;
88214 }
88215 }
88216 }
@@ -94249,11 +94279,11 @@
94279 assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );
94280
94281 pTab = sqlite3LocateTableItem(pParse, 0, &pSrc->a[0]);
94282 if( !pTab ) goto exit_rename_table;
94283 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
94284 zDb = db->aDb[iDb].zDbSName;
94285 db->flags |= SQLITE_PreferBuiltin;
94286
94287 /* Get a NULL terminated version of the new table name. */
94288 zName = sqlite3NameFromToken(db, pName);
94289 if( !zName ) goto exit_rename_table;
@@ -94447,11 +94477,11 @@
94477 pNew = pParse->pNewTable;
94478 assert( pNew );
94479
94480 assert( sqlite3BtreeHoldsAllMutexes(db) );
94481 iDb = sqlite3SchemaToIndex(db, pNew->pSchema);
94482 zDb = db->aDb[iDb].zDbSName;
94483 zTab = &pNew->zName[16]; /* Skip the "sqlite_altertab_" prefix on the name */
94484 pCol = &pNew->aCol[pNew->nCol-1];
94485 pDflt = pCol->pDflt;
94486 pTab = sqlite3FindTable(db, zTab, zDb);
94487 assert( pTab );
@@ -94857,18 +94887,18 @@
94887 ** if they do already exist.
94888 */
94889 for(i=0; i<ArraySize(aTable); i++){
94890 const char *zTab = aTable[i].zName;
94891 Table *pStat;
94892 if( (pStat = sqlite3FindTable(db, zTab, pDb->zDbSName))==0 ){
94893 if( aTable[i].zCols ){
94894 /* The sqlite_statN table does not exist. Create it. Note that a
94895 ** side-effect of the CREATE TABLE statement is to leave the rootpage
94896 ** of the new table in register pParse->regRoot. This is important
94897 ** because the OpenWrite opcode below will be needing it. */
94898 sqlite3NestedParse(pParse,
94899 "CREATE TABLE %Q.%s(%s)", pDb->zDbSName, zTab, aTable[i].zCols
94900 );
94901 aRoot[i] = pParse->regRoot;
94902 aCreateTbl[i] = OPFLAG_P2ISREG;
94903 }
94904 }else{
@@ -94879,11 +94909,11 @@
94909 aCreateTbl[i] = 0;
94910 sqlite3TableLock(pParse, iDb, aRoot[i], 1, zTab);
94911 if( zWhere ){
94912 sqlite3NestedParse(pParse,
94913 "DELETE FROM %Q.%s WHERE %s=%Q",
94914 pDb->zDbSName, zTab, zWhereType, zWhere
94915 );
94916 }else{
94917 /* The sqlite_stat[134] table already exists. Delete all rows. */
94918 sqlite3VdbeAddOp2(v, OP_Clear, aRoot[i], iDb);
94919 }
@@ -95641,11 +95671,11 @@
95671 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
95672 assert( iDb>=0 );
95673 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
95674 #ifndef SQLITE_OMIT_AUTHORIZATION
95675 if( sqlite3AuthCheck(pParse, SQLITE_ANALYZE, pTab->zName, 0,
95676 db->aDb[iDb].zDbSName ) ){
95677 return;
95678 }
95679 #endif
95680
95681 /* Establish a read-lock on the table at the shared-cache level.
@@ -96031,11 +96061,11 @@
96061 }
96062 }else{
96063 /* Form 3: Analyze the fully qualified table name */
96064 iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pTableName);
96065 if( iDb>=0 ){
96066 zDb = db->aDb[iDb].zDbSName;
96067 z = sqlite3NameFromToken(db, pTableName);
96068 if( z ){
96069 if( (pIdx = sqlite3FindIndex(db, z, zDb))!=0 ){
96070 analyzeTable(pParse, pIdx->pTable, pIdx);
96071 }else if( (pTab = sqlite3LocateTable(pParse, 0, z, zDb))!=0 ){
@@ -96491,11 +96521,11 @@
96521 #endif
96522 }
96523
96524 /* Load new statistics out of the sqlite_stat1 table */
96525 sInfo.db = db;
96526 sInfo.zDatabase = db->aDb[iDb].zDbSName;
96527 if( sqlite3FindTable(db, "sqlite_stat1", sInfo.zDatabase)!=0 ){
96528 zSql = sqlite3MPrintf(db,
96529 "SELECT tbl,idx,stat FROM %Q.sqlite_stat1", sInfo.zDatabase);
96530 if( zSql==0 ){
96531 rc = SQLITE_NOMEM_BKPT;
@@ -96634,11 +96664,11 @@
96664 if( !db->autoCommit ){
96665 zErrDyn = sqlite3MPrintf(db, "cannot ATTACH database within transaction");
96666 goto attach_error;
96667 }
96668 for(i=0; i<db->nDb; i++){
96669 char *z = db->aDb[i].zDbSName;
96670 assert( z && zName );
96671 if( sqlite3StrICmp(z, zName)==0 ){
96672 zErrDyn = sqlite3MPrintf(db, "database %s is already in use", zName);
96673 goto attach_error;
96674 }
@@ -96699,12 +96729,12 @@
96729 PAGER_SYNCHRONOUS_FULL | (db->flags & PAGER_FLAGS_MASK));
96730 #endif
96731 sqlite3BtreeLeave(aNew->pBt);
96732 }
96733 aNew->safety_level = SQLITE_DEFAULT_SYNCHRONOUS+1;
96734 aNew->zDbSName = sqlite3DbStrDup(db, zName);
96735 if( rc==SQLITE_OK && aNew->zDbSName==0 ){
96736 rc = SQLITE_NOMEM_BKPT;
96737 }
96738
96739
96740 #ifdef SQLITE_HAS_CODEC
@@ -96812,11 +96842,11 @@
96842
96843 if( zName==0 ) zName = "";
96844 for(i=0; i<db->nDb; i++){
96845 pDb = &db->aDb[i];
96846 if( pDb->pBt==0 ) continue;
96847 if( sqlite3StrICmp(pDb->zDbSName, zName)==0 ) break;
96848 }
96849
96850 if( i>=db->nDb ){
96851 sqlite3_snprintf(sizeof(zErr),zErr, "no such database: %s", zName);
96852 goto detach_error;
@@ -96970,11 +97000,11 @@
97000 sqlite3 *db;
97001
97002 db = pParse->db;
97003 assert( db->nDb>iDb );
97004 pFix->pParse = pParse;
97005 pFix->zDb = db->aDb[iDb].zDbSName;
97006 pFix->pSchema = db->aDb[iDb].pSchema;
97007 pFix->zType = zType;
97008 pFix->pName = pName;
97009 pFix->bVarOnly = (iDb==1);
97010 }
@@ -97228,13 +97258,13 @@
97258 Parse *pParse, /* The parser context */
97259 const char *zTab, /* Table name */
97260 const char *zCol, /* Column name */
97261 int iDb /* Index of containing database. */
97262 ){
97263 sqlite3 *db = pParse->db; /* Database handle */
97264 char *zDb = db->aDb[iDb].zDbSName; /* Schema name of attached database */
97265 int rc; /* Auth callback return code */
97266
97267 if( db->init.busy ) return SQLITE_OK;
97268 rc = db->xAuth(db->pAuthArg, SQLITE_READ, zTab,zCol,zDb,pParse->zAuthContext
97269 #ifdef SQLITE_USER_AUTHENTICATION
97270 ,db->auth.zAuthUser
@@ -97703,14 +97733,15 @@
97733 return 0;
97734 }
97735 #endif
97736 for(i=OMIT_TEMPDB; i<db->nDb; i++){
97737 int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */
97738 if( zDatabase==0 || sqlite3StrICmp(zDatabase, db->aDb[j].zDbSName)==0 ){
97739 assert( sqlite3SchemaMutexHeld(db, j, 0) );
97740 p = sqlite3HashFind(&db->aDb[j].pSchema->tblHash, zName);
97741 if( p ) break;
97742 }
97743 }
97744 return p;
97745 }
97746
97747 /*
@@ -97780,11 +97811,11 @@
97811 ){
97812 const char *zDb;
97813 assert( p->pSchema==0 || p->zDatabase==0 );
97814 if( p->pSchema ){
97815 int iDb = sqlite3SchemaToIndex(pParse->db, p->pSchema);
97816 zDb = pParse->db->aDb[iDb].zDbSName;
97817 }else{
97818 zDb = p->zDatabase;
97819 }
97820 return sqlite3LocateTable(pParse, flags, p->zName, zDb);
97821 }
@@ -97808,11 +97839,11 @@
97839 assert( zDb!=0 || sqlite3BtreeHoldsAllMutexes(db) );
97840 for(i=OMIT_TEMPDB; i<db->nDb; i++){
97841 int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */
97842 Schema *pSchema = db->aDb[j].pSchema;
97843 assert( pSchema );
97844 if( zDb && sqlite3StrICmp(zDb, db->aDb[j].zDbSName) ) continue;
97845 assert( sqlite3SchemaMutexHeld(db, j, 0) );
97846 p = sqlite3HashFind(&pSchema->idxHash, zName);
97847 if( p ) break;
97848 }
97849 return p;
@@ -97877,12 +97908,12 @@
97908 SQLITE_PRIVATE void sqlite3CollapseDatabaseArray(sqlite3 *db){
97909 int i, j;
97910 for(i=j=2; i<db->nDb; i++){
97911 struct Db *pDb = &db->aDb[i];
97912 if( pDb->pBt==0 ){
97913 sqlite3DbFree(db, pDb->zDbSName);
97914 pDb->zDbSName = 0;
97915 continue;
97916 }
97917 if( j<i ){
97918 db->aDb[j] = db->aDb[i];
97919 }
@@ -98098,11 +98129,11 @@
98129 SQLITE_PRIVATE int sqlite3FindDbName(sqlite3 *db, const char *zName){
98130 int i = -1; /* Database number */
98131 if( zName ){
98132 Db *pDb;
98133 for(i=(db->nDb-1), pDb=&db->aDb[i]; i>=0; i--, pDb--){
98134 if( 0==sqlite3StrICmp(pDb->zDbSName, zName) ) break;
98135 }
98136 }
98137 return i;
98138 }
98139
@@ -98157,11 +98188,11 @@
98188 if( iDb<0 ){
98189 sqlite3ErrorMsg(pParse, "unknown database %T", pName1);
98190 return -1;
98191 }
98192 }else{
98193 assert( db->init.iDb==0 || db->init.busy || (db->flags & SQLITE_Vacuum)!=0);
98194 iDb = db->init.iDb;
98195 *pUnqual = pName1;
98196 }
98197 return iDb;
98198 }
@@ -98268,11 +98299,11 @@
98299 SQLITE_CREATE_TABLE,
98300 SQLITE_CREATE_TEMP_TABLE,
98301 SQLITE_CREATE_VIEW,
98302 SQLITE_CREATE_TEMP_VIEW
98303 };
98304 char *zDb = db->aDb[iDb].zDbSName;
98305 if( sqlite3AuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(isTemp), 0, zDb) ){
98306 goto begin_table_error;
98307 }
98308 if( !isVirtual && sqlite3AuthCheck(pParse, (int)aCode[isTemp+2*isView],
98309 zName, 0, zDb) ){
@@ -98287,11 +98318,11 @@
98318 ** to an sqlite3_declare_vtab() call. In that case only the column names
98319 ** and types will be used, so there is no need to test for namespace
98320 ** collisions.
98321 */
98322 if( !IN_DECLARE_VTAB ){
98323 char *zDb = db->aDb[iDb].zDbSName;
98324 if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){
98325 goto begin_table_error;
98326 }
98327 pTable = sqlite3FindTable(db, zName, zDb);
98328 if( pTable ){
@@ -99380,11 +99411,11 @@
99411 */
99412 sqlite3NestedParse(pParse,
99413 "UPDATE %Q.%s "
99414 "SET type='%s', name=%Q, tbl_name=%Q, rootpage=#%d, sql=%Q "
99415 "WHERE rowid=#%d",
99416 db->aDb[iDb].zDbSName, SCHEMA_TABLE(iDb),
99417 zType,
99418 p->zName,
99419 p->zName,
99420 pParse->regRoot,
99421 zStmt,
@@ -99395,17 +99426,17 @@
99426
99427 #ifndef SQLITE_OMIT_AUTOINCREMENT
99428 /* Check to see if we need to create an sqlite_sequence table for
99429 ** keeping track of autoincrement keys.
99430 */
99431 if( (p->tabFlags & TF_Autoincrement)!=0 ){
99432 Db *pDb = &db->aDb[iDb];
99433 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
99434 if( pDb->pSchema->pSeqTab==0 ){
99435 sqlite3NestedParse(pParse,
99436 "CREATE TABLE %Q.sqlite_sequence(name,seq)",
99437 pDb->zDbSName
99438 );
99439 }
99440 }
99441 #endif
99442
@@ -99715,11 +99746,11 @@
99746 ** is in register NNN. See grammar rules associated with the TK_REGISTER
99747 ** token for additional information.
99748 */
99749 sqlite3NestedParse(pParse,
99750 "UPDATE %Q.%s SET rootpage=%d WHERE #%d AND rootpage=#%d",
99751 pParse->db->aDb[iDb].zDbSName, SCHEMA_TABLE(iDb), iTable, r1, r1);
99752 #endif
99753 sqlite3ReleaseTempReg(pParse, r1);
99754 }
99755
99756 /*
@@ -99791,11 +99822,11 @@
99822 int iDb, /* The database number */
99823 const char *zType, /* "idx" or "tbl" */
99824 const char *zName /* Name of index or table */
99825 ){
99826 int i;
99827 const char *zDbName = pParse->db->aDb[iDb].zDbSName;
99828 for(i=1; i<=4; i++){
99829 char zTab[24];
99830 sqlite3_snprintf(sizeof(zTab),zTab,"sqlite_stat%d",i);
99831 if( sqlite3FindTable(pParse->db, zTab, zDbName) ){
99832 sqlite3NestedParse(pParse,
@@ -99844,11 +99875,11 @@
99875 ** move as a result of the drop (can happen in auto-vacuum mode).
99876 */
99877 if( pTab->tabFlags & TF_Autoincrement ){
99878 sqlite3NestedParse(pParse,
99879 "DELETE FROM %Q.sqlite_sequence WHERE name=%Q",
99880 pDb->zDbSName, pTab->zName
99881 );
99882 }
99883 #endif
99884
99885 /* Drop all SQLITE_MASTER table and index entries that refer to the
@@ -99858,11 +99889,11 @@
99889 ** created in the temp database that refers to a table in another
99890 ** database.
99891 */
99892 sqlite3NestedParse(pParse,
99893 "DELETE FROM %Q.%s WHERE tbl_name=%Q and type!='trigger'",
99894 pDb->zDbSName, SCHEMA_TABLE(iDb), pTab->zName);
99895 if( !isView && !IsVirtual(pTab) ){
99896 destroyTable(pParse, pTab);
99897 }
99898
99899 /* Remove the table entry from SQLite's internal schema and modify
@@ -99912,11 +99943,11 @@
99943 }
99944 #ifndef SQLITE_OMIT_AUTHORIZATION
99945 {
99946 int code;
99947 const char *zTab = SCHEMA_TABLE(iDb);
99948 const char *zDb = db->aDb[iDb].zDbSName;
99949 const char *zArg2 = 0;
99950 if( sqlite3AuthCheck(pParse, SQLITE_DELETE, zTab, 0, zDb)){
99951 goto exit_drop_table;
99952 }
99953 if( isView ){
@@ -100153,11 +100184,11 @@
100184 sqlite3 *db = pParse->db; /* The database connection */
100185 int iDb = sqlite3SchemaToIndex(db, pIndex->pSchema);
100186
100187 #ifndef SQLITE_OMIT_AUTHORIZATION
100188 if( sqlite3AuthCheck(pParse, SQLITE_REINDEX, pIndex->zName, 0,
100189 db->aDb[iDb].zDbSName ) ){
100190 return;
100191 }
100192 #endif
100193
100194 /* Require a write-lock on the table to perform this operation */
@@ -100405,11 +100436,11 @@
100436 if( sqlite3FindTable(db, zName, 0)!=0 ){
100437 sqlite3ErrorMsg(pParse, "there is already a table named %s", zName);
100438 goto exit_create_index;
100439 }
100440 }
100441 if( sqlite3FindIndex(db, zName, pDb->zDbSName)!=0 ){
100442 if( !ifNotExist ){
100443 sqlite3ErrorMsg(pParse, "index %s already exists", zName);
100444 }else{
100445 assert( !db->init.busy );
100446 sqlite3CodeVerifySchema(pParse, iDb);
@@ -100435,11 +100466,11 @@
100466
100467 /* Check for authorization to create an index.
100468 */
100469 #ifndef SQLITE_OMIT_AUTHORIZATION
100470 {
100471 const char *zDb = pDb->zDbSName;
100472 if( sqlite3AuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(iDb), 0, zDb) ){
100473 goto exit_create_index;
100474 }
100475 i = SQLITE_CREATE_INDEX;
100476 if( !OMIT_TEMPDB && iDb==1 ) i = SQLITE_CREATE_TEMP_INDEX;
@@ -100750,11 +100781,11 @@
100781
100782 /* Add an entry in sqlite_master for this index
100783 */
100784 sqlite3NestedParse(pParse,
100785 "INSERT INTO %Q.%s VALUES('index',%Q,%Q,#%d,%Q);",
100786 db->aDb[iDb].zDbSName, SCHEMA_TABLE(iDb),
100787 pIndex->zName,
100788 pTab->zName,
100789 iMem,
100790 zStmt
100791 );
@@ -100884,11 +100915,11 @@
100915 iDb = sqlite3SchemaToIndex(db, pIndex->pSchema);
100916 #ifndef SQLITE_OMIT_AUTHORIZATION
100917 {
100918 int code = SQLITE_DROP_INDEX;
100919 Table *pTab = pIndex->pTable;
100920 const char *zDb = db->aDb[iDb].zDbSName;
100921 const char *zTab = SCHEMA_TABLE(iDb);
100922 if( sqlite3AuthCheck(pParse, SQLITE_DELETE, zTab, 0, zDb) ){
100923 goto exit_drop_index;
100924 }
100925 if( !OMIT_TEMPDB && iDb ) code = SQLITE_DROP_TEMP_INDEX;
@@ -100902,11 +100933,11 @@
100933 v = sqlite3GetVdbe(pParse);
100934 if( v ){
100935 sqlite3BeginWriteOperation(pParse, 1, iDb);
100936 sqlite3NestedParse(pParse,
100937 "DELETE FROM %Q.%s WHERE name=%Q AND type='index'",
100938 db->aDb[iDb].zDbSName, SCHEMA_TABLE(iDb), pIndex->zName
100939 );
100940 sqlite3ClearStatTables(pParse, iDb, "idx", pIndex->zName);
100941 sqlite3ChangeCookie(pParse, iDb);
100942 destroyRootPage(pParse, pIndex->tnum, iDb);
100943 sqlite3VdbeAddOp4(v, OP_DropIndex, iDb, 0, 0, pIndex->zName, 0);
@@ -101447,11 +101478,11 @@
101478 SQLITE_PRIVATE void sqlite3CodeVerifyNamedSchema(Parse *pParse, const char *zDb){
101479 sqlite3 *db = pParse->db;
101480 int i;
101481 for(i=0; i<db->nDb; i++){
101482 Db *pDb = &db->aDb[i];
101483 if( pDb->pBt && (!zDb || 0==sqlite3StrICmp(zDb, pDb->zDbSName)) ){
101484 sqlite3CodeVerifySchema(pParse, i);
101485 }
101486 }
101487 }
101488
@@ -101694,11 +101725,11 @@
101725 }
101726 iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pObjName);
101727 if( iDb<0 ) return;
101728 z = sqlite3NameFromToken(db, pObjName);
101729 if( z==0 ) return;
101730 zDb = db->aDb[iDb].zDbSName;
101731 pTab = sqlite3FindTable(db, z, zDb);
101732 if( pTab ){
101733 reindexTable(pParse, pTab, 0);
101734 sqlite3DbFree(db, z);
101735 return;
@@ -102408,11 +102439,11 @@
102439 pWhere = sqlite3ExprDup(db, pWhere, 0);
102440 pFrom = sqlite3SrcListAppend(db, 0, 0, 0);
102441 if( pFrom ){
102442 assert( pFrom->nSrc==1 );
102443 pFrom->a[0].zName = sqlite3DbStrDup(db, pView->zName);
102444 pFrom->a[0].zDatabase = sqlite3DbStrDup(db, db->aDb[iDb].zDbSName);
102445 assert( pFrom->a[0].pOn==0 );
102446 assert( pFrom->a[0].pUsing==0 );
102447 }
102448 pSel = sqlite3SelectNew(pParse, 0, pFrom, pWhere, 0, 0, 0,
102449 SF_IncludeHidden, 0, 0);
@@ -102595,11 +102626,11 @@
102626 if( sqlite3IsReadOnly(pParse, pTab, (pTrigger?1:0)) ){
102627 goto delete_from_cleanup;
102628 }
102629 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
102630 assert( iDb<db->nDb );
102631 zDb = db->aDb[iDb].zDbSName;
102632 rcauth = sqlite3AuthCheck(pParse, SQLITE_DELETE, pTab->zName, 0, zDb);
102633 assert( rcauth==SQLITE_OK || rcauth==SQLITE_DENY || rcauth==SQLITE_IGNORE );
102634 if( rcauth==SQLITE_DENY ){
102635 goto delete_from_cleanup;
102636 }
@@ -105927,11 +105958,11 @@
105958
105959 /* If foreign-keys are disabled, this function is a no-op. */
105960 if( (db->flags&SQLITE_ForeignKeys)==0 ) return;
105961
105962 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
105963 zDb = db->aDb[iDb].zDbSName;
105964
105965 /* Loop through all the foreign key constraints for which pTab is the
105966 ** child table (the table that the foreign key definition is part of). */
105967 for(pFKey=pTab->pFKey; pFKey; pFKey=pFKey->pNextFrom){
105968 Table *pTo; /* Parent table of foreign key pFKey */
@@ -106667,11 +106698,13 @@
106698
106699 #ifndef SQLITE_OMIT_AUTOINCREMENT
106700 /*
106701 ** Locate or create an AutoincInfo structure associated with table pTab
106702 ** which is in database iDb. Return the register number for the register
106703 ** that holds the maximum rowid. Return zero if pTab is not an AUTOINCREMENT
106704 ** table. (Also return zero when doing a VACUUM since we do not want to
106705 ** update the AUTOINCREMENT counters during a VACUUM.)
106706 **
106707 ** There is at most one AutoincInfo structure per table even if the
106708 ** same table is autoincremented multiple times due to inserts within
106709 ** triggers. A new AutoincInfo structure is created if this is the
106710 ** first use of table pTab. On 2nd and subsequent uses, the original
@@ -106690,11 +106723,13 @@
106723 Parse *pParse, /* Parsing context */
106724 int iDb, /* Index of the database holding pTab */
106725 Table *pTab /* The table we are writing to */
106726 ){
106727 int memId = 0; /* Register holding maximum rowid */
106728 if( (pTab->tabFlags & TF_Autoincrement)!=0
106729 && (pParse->db->flags & SQLITE_Vacuum)==0
106730 ){
106731 Parse *pToplevel = sqlite3ParseToplevel(pParse);
106732 AutoincInfo *pInfo;
106733
106734 pInfo = pToplevel->pAinc;
106735 while( pInfo && pInfo->pTab!=pTab ){ pInfo = pInfo->pNext; }
@@ -107014,11 +107049,11 @@
107049 goto insert_cleanup;
107050 }
107051 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
107052 assert( iDb<db->nDb );
107053 pDb = &db->aDb[iDb];
107054 zDb = pDb->zDbSName;
107055 if( sqlite3AuthCheck(pParse, SQLITE_INSERT, pTab->zName, 0, zDb) ){
107056 goto insert_cleanup;
107057 }
107058 withoutRowid = !HasRowid(pTab);
107059
@@ -110972,11 +111007,11 @@
111007 }else{
111008 zRight = sqlite3NameFromToken(db, pValue);
111009 }
111010
111011 assert( pId2 );
111012 zDb = pId2->n>0 ? pDb->zDbSName : 0;
111013 if( sqlite3AuthCheck(pParse, SQLITE_PRAGMA, zLeft, zRight, zDb) ){
111014 goto pragma_out;
111015 }
111016
111017 /* Send an SQLITE_FCNTL_PRAGMA file-control to the underlying VFS
@@ -111825,14 +111860,14 @@
111860 int i;
111861 pParse->nMem = 3;
111862 setAllColumnNames(v, 3, azCol); assert( 3==ArraySize(azCol) );
111863 for(i=0; i<db->nDb; i++){
111864 if( db->aDb[i].pBt==0 ) continue;
111865 assert( db->aDb[i].zDbSName!=0 );
111866 sqlite3VdbeMultiLoad(v, 1, "iss",
111867 i,
111868 db->aDb[i].zDbSName,
111869 sqlite3BtreeGetFilename(db->aDb[i].pBt));
111870 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3);
111871 }
111872 }
111873 break;
@@ -112117,11 +112152,11 @@
112152 /* Do the b-tree integrity checks */
112153 sqlite3VdbeAddOp4(v, OP_IntegrityCk, 2, cnt, 1, (char*)aRoot,P4_INTARRAY);
112154 sqlite3VdbeChangeP5(v, (u8)i);
112155 addr = sqlite3VdbeAddOp1(v, OP_IsNull, 2); VdbeCoverage(v);
112156 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0,
112157 sqlite3MPrintf(db, "*** in database %s ***\n", db->aDb[i].zDbSName),
112158 P4_DYNAMIC);
112159 sqlite3VdbeAddOp3(v, OP_Move, 2, 4, 1);
112160 sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 2);
112161 sqlite3VdbeAddOp2(v, OP_ResultRow, 2, 1);
112162 sqlite3VdbeJumpHere(v, addr);
@@ -112556,19 +112591,19 @@
112591 pParse->nMem = 2;
112592 for(i=0; i<db->nDb; i++){
112593 Btree *pBt;
112594 const char *zState = "unknown";
112595 int j;
112596 if( db->aDb[i].zDbSName==0 ) continue;
112597 pBt = db->aDb[i].pBt;
112598 if( pBt==0 || sqlite3BtreePager(pBt)==0 ){
112599 zState = "closed";
112600 }else if( sqlite3_file_control(db, i ? db->aDb[i].zDbSName : 0,
112601 SQLITE_FCNTL_LOCKSTATE, &j)==SQLITE_OK ){
112602 zState = azLockName[j];
112603 }
112604 sqlite3VdbeMultiLoad(v, 1, "ss", db->aDb[i].zDbSName, zState);
112605 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 2);
112606 }
112607 break;
112608 }
112609 #endif
@@ -112700,10 +112735,11 @@
112735 ** But because db->init.busy is set to 1, no VDBE code is generated
112736 ** or executed. All the parser does is build the internal data
112737 ** structures that describe the table, index, or view.
112738 */
112739 int rc;
112740 u8 saved_iDb = db->init.iDb;
112741 sqlite3_stmt *pStmt;
112742 TESTONLY(int rcp); /* Return code from sqlite3_prepare() */
112743
112744 assert( db->init.busy );
112745 db->init.iDb = iDb;
@@ -112710,11 +112746,12 @@
112746 db->init.newTnum = sqlite3Atoi(argv[1]);
112747 db->init.orphanTrigger = 0;
112748 TESTONLY(rcp = ) sqlite3_prepare(db, argv[2], -1, &pStmt, 0);
112749 rc = db->errCode;
112750 assert( (rc&0xFF)==(rcp&0xFF) );
112751 db->init.iDb = saved_iDb;
112752 assert( saved_iDb==0 || (db->flags & SQLITE_Vacuum)!=0 );
112753 if( SQLITE_OK!=rc ){
112754 if( db->init.orphanTrigger ){
112755 assert( iDb==1 );
112756 }else{
112757 pData->rc = rc;
@@ -112734,11 +112771,11 @@
112771 ** constraint for a CREATE TABLE. The index should have already
112772 ** been created when we processed the CREATE TABLE. All we have
112773 ** to do here is record the root page number for that index.
112774 */
112775 Index *pIndex;
112776 pIndex = sqlite3FindIndex(db, argv[0], db->aDb[iDb].zDbSName);
112777 if( pIndex==0 ){
112778 /* This can occur if there exists an index on a TEMP table which
112779 ** has the same name as another index on a permanent index. Since
112780 ** the permanent table is hidden by the TEMP table, we can also
112781 ** safely ignore the index on the permanent table.
@@ -112913,11 +112950,11 @@
112950 assert( db->init.busy );
112951 {
112952 char *zSql;
112953 zSql = sqlite3MPrintf(db,
112954 "SELECT name, rootpage, sql FROM \"%w\".%s ORDER BY rowid",
112955 db->aDb[iDb].zDbSName, zMasterName);
112956 #ifndef SQLITE_OMIT_AUTHORIZATION
112957 {
112958 sqlite3_xauth xAuth;
112959 xAuth = db->xAuth;
112960 db->xAuth = 0;
@@ -113188,11 +113225,11 @@
113225 Btree *pBt = db->aDb[i].pBt;
113226 if( pBt ){
113227 assert( sqlite3BtreeHoldsMutex(pBt) );
113228 rc = sqlite3BtreeSchemaLocked(pBt);
113229 if( rc ){
113230 const char *zDb = db->aDb[i].zDbSName;
113231 sqlite3ErrorWithMsg(db, rc, "database schema is locked: %s", zDb);
113232 testcase( db->flags & SQLITE_ReadUncommitted );
113233 goto end_prepare;
113234 }
113235 }
@@ -114944,11 +114981,11 @@
114981 estWidth = pTab->aCol[iCol].szEst;
114982 }
114983 zOrigTab = pTab->zName;
114984 if( pNC->pParse ){
114985 int iDb = sqlite3SchemaToIndex(pNC->pParse->db, pTab->pSchema);
114986 zOrigDb = pNC->pParse->db->aDb[iDb].zDbSName;
114987 }
114988 #else
114989 if( iCol<0 ){
114990 zType = "INTEGER";
114991 }else{
@@ -117900,11 +117937,11 @@
117937 pSub = 0;
117938 if( zTName && sqlite3StrICmp(zTName, zTabName)!=0 ){
117939 continue;
117940 }
117941 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
117942 zSchemaName = iDb>=0 ? db->aDb[iDb].zDbSName : "*";
117943 }
117944 for(j=0; j<pTab->nCol; j++){
117945 char *zName = pTab->aCol[j].zName;
117946 char *zColname; /* The computed column name */
117947 char *zToFree; /* Malloced string that needs to be freed */
@@ -119612,12 +119649,12 @@
119649 iTabDb = sqlite3SchemaToIndex(db, pTab->pSchema);
119650
119651 #ifndef SQLITE_OMIT_AUTHORIZATION
119652 {
119653 int code = SQLITE_CREATE_TRIGGER;
119654 const char *zDb = db->aDb[iTabDb].zDbSName;
119655 const char *zDbTrig = isTemp ? db->aDb[1].zDbSName : zDb;
119656 if( iTabDb==1 || isTemp ) code = SQLITE_CREATE_TEMP_TRIGGER;
119657 if( sqlite3AuthCheck(pParse, code, zName, pTab->zName, zDbTrig) ){
119658 goto trigger_cleanup;
119659 }
119660 if( sqlite3AuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(iTabDb),0,zDb)){
@@ -119707,11 +119744,11 @@
119744 if( v==0 ) goto triggerfinish_cleanup;
119745 sqlite3BeginWriteOperation(pParse, 0, iDb);
119746 z = sqlite3DbStrNDup(db, (char*)pAll->z, pAll->n);
119747 sqlite3NestedParse(pParse,
119748 "INSERT INTO %Q.%s VALUES('trigger',%Q,%Q,0,'CREATE TRIGGER %q')",
119749 db->aDb[iDb].zDbSName, SCHEMA_TABLE(iDb), zName,
119750 pTrig->table, z);
119751 sqlite3DbFree(db, z);
119752 sqlite3ChangeCookie(pParse, iDb);
119753 sqlite3VdbeAddParseSchemaOp(v, iDb,
119754 sqlite3MPrintf(db, "type='trigger' AND name='%q'", zName));
@@ -119896,11 +119933,11 @@
119933 zDb = pName->a[0].zDatabase;
119934 zName = pName->a[0].zName;
119935 assert( zDb!=0 || sqlite3BtreeHoldsAllMutexes(db) );
119936 for(i=OMIT_TEMPDB; i<db->nDb; i++){
119937 int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */
119938 if( zDb && sqlite3StrICmp(db->aDb[j].zDbSName, zDb) ) continue;
119939 assert( sqlite3SchemaMutexHeld(db, j, 0) );
119940 pTrigger = sqlite3HashFind(&(db->aDb[j].pSchema->trigHash), zName);
119941 if( pTrigger ) break;
119942 }
119943 if( !pTrigger ){
@@ -119942,11 +119979,11 @@
119979 assert( pTable );
119980 assert( pTable->pSchema==pTrigger->pSchema || iDb==1 );
119981 #ifndef SQLITE_OMIT_AUTHORIZATION
119982 {
119983 int code = SQLITE_DROP_TRIGGER;
119984 const char *zDb = db->aDb[iDb].zDbSName;
119985 const char *zTab = SCHEMA_TABLE(iDb);
119986 if( iDb==1 ) code = SQLITE_DROP_TEMP_TRIGGER;
119987 if( sqlite3AuthCheck(pParse, code, pTrigger->zName, pTable->zName, zDb) ||
119988 sqlite3AuthCheck(pParse, SQLITE_DELETE, zTab, 0, zDb) ){
119989 return;
@@ -119958,11 +119995,11 @@
119995 */
119996 assert( pTable!=0 );
119997 if( (v = sqlite3GetVdbe(pParse))!=0 ){
119998 sqlite3NestedParse(pParse,
119999 "DELETE FROM %Q.%s WHERE name=%Q AND type='trigger'",
120000 db->aDb[iDb].zDbSName, SCHEMA_TABLE(iDb), pTrigger->zName
120001 );
120002 sqlite3ChangeCookie(pParse, iDb);
120003 sqlite3VdbeAddOp4(v, OP_DropTrigger, iDb, 0, 0, pTrigger->zName, 0);
120004 }
120005 }
@@ -120061,12 +120098,14 @@
120098 if( pSrc ){
120099 assert( pSrc->nSrc>0 );
120100 pSrc->a[pSrc->nSrc-1].zName = sqlite3DbStrDup(db, pStep->zTarget);
120101 iDb = sqlite3SchemaToIndex(db, pStep->pTrig->pSchema);
120102 if( iDb==0 || iDb>=2 ){
120103 const char *zDb;
120104 assert( iDb<db->nDb );
120105 zDb = db->aDb[iDb].zDbSName;
120106 pSrc->a[pSrc->nSrc-1].zDatabase = sqlite3DbStrDup(db, zDb);
120107 }
120108 }
120109 return pSrc;
120110 }
120111
@@ -120749,11 +120788,11 @@
120788 #ifndef SQLITE_OMIT_AUTHORIZATION
120789 {
120790 int rc;
120791 rc = sqlite3AuthCheck(pParse, SQLITE_UPDATE, pTab->zName,
120792 j<0 ? "ROWID" : pTab->aCol[j].zName,
120793 db->aDb[iDb].zDbSName);
120794 if( rc==SQLITE_DENY ){
120795 goto update_cleanup;
120796 }else if( rc==SQLITE_IGNORE ){
120797 aXRef[j] = -1;
120798 }
@@ -121351,61 +121390,56 @@
121390 */
121391 /* #include "sqliteInt.h" */
121392 /* #include "vdbeInt.h" */
121393
121394 #if !defined(SQLITE_OMIT_VACUUM) && !defined(SQLITE_OMIT_ATTACH)
121395
121396 /*
121397 ** Execute zSql on database db.
121398 **
121399 ** If zSql returns rows, then each row will have exactly one
121400 ** column. (This will only happen if zSql begins with "SELECT".)
121401 ** Take each row of result and call execSql() again recursively.
121402 **
121403 ** The execSqlF() routine does the same thing, except it accepts
121404 ** a format string as its third argument
 
 
 
 
 
121405 */
121406 static int execSql(sqlite3 *db, char **pzErrMsg, const char *zSql){
121407 sqlite3_stmt *pStmt;
121408 int rc;
121409
121410 /* printf("SQL: [%s]\n", zSql); fflush(stdout); */
121411 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
121412 if( rc!=SQLITE_OK ) return rc;
121413 while( SQLITE_ROW==(rc = sqlite3_step(pStmt)) ){
121414 const char *zSubSql = (const char*)sqlite3_column_text(pStmt,0);
121415 assert( sqlite3_strnicmp(zSql,"SELECT",6)==0 );
121416 if( zSubSql ){
121417 assert( zSubSql[0]!='S' );
121418 rc = execSql(db, pzErrMsg, zSubSql);
121419 if( rc!=SQLITE_OK ) break;
121420 }
121421 }
121422 assert( rc!=SQLITE_ROW );
121423 if( rc==SQLITE_DONE ) rc = SQLITE_OK;
121424 if( rc ){
121425 sqlite3SetString(pzErrMsg, db, sqlite3_errmsg(db));
121426 }
121427 (void)sqlite3_finalize(pStmt);
121428 return rc;
121429 }
121430 static int execSqlF(sqlite3 *db, char **pzErrMsg, const char *zSql, ...){
121431 char *z;
121432 va_list ap;
121433 int rc;
121434 va_start(ap, zSql);
121435 z = sqlite3VMPrintf(db, zSql, ap);
121436 va_end(ap);
121437 if( z==0 ) return SQLITE_NOMEM;
121438 rc = execSql(db, pzErrMsg, z);
121439 sqlite3DbFree(db, z);
121440 return rc;
 
 
 
 
 
 
 
 
 
 
 
 
121441 }
121442
121443 /*
121444 ** The VACUUM command is used to clean up the database,
121445 ** collapse free space, etc. It is modelled after the VACUUM command
@@ -121434,35 +121468,36 @@
121468 ** not work if other processes are attached to the original database.
121469 ** And a power loss in between deleting the original and renaming the
121470 ** transient would cause the database file to appear to be deleted
121471 ** following reboot.
121472 */
121473 SQLITE_PRIVATE void sqlite3Vacuum(Parse *pParse, Token *pNm){
121474 Vdbe *v = sqlite3GetVdbe(pParse);
121475 int iDb = pNm ? sqlite3TwoPartName(pParse, pNm, pNm, &pNm) : 0;
121476 if( v && (iDb>=2 || iDb==0) ){
121477 sqlite3VdbeAddOp1(v, OP_Vacuum, iDb);
121478 sqlite3VdbeUsesBtree(v, iDb);
121479 }
121480 return;
121481 }
121482
121483 /*
121484 ** This routine implements the OP_Vacuum opcode of the VDBE.
121485 */
121486 SQLITE_PRIVATE int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db, int iDb){
121487 int rc = SQLITE_OK; /* Return code from service routines */
121488 Btree *pMain; /* The database being vacuumed */
121489 Btree *pTemp; /* The temporary database we vacuum into */
 
121490 int saved_flags; /* Saved value of the db->flags */
121491 int saved_nChange; /* Saved value of db->nChange */
121492 int saved_nTotalChange; /* Saved value of db->nTotalChange */
121493 u8 saved_mTrace; /* Saved trace settings */
121494 Db *pDb = 0; /* Database to detach at end of vacuum */
121495 int isMemDb; /* True if vacuuming a :memory: database */
121496 int nRes; /* Bytes of reserved space at the end of each page */
121497 int nDb; /* Number of attached databases */
121498 const char *zDbMain; /* Schema name of database to vacuum */
121499
121500 if( !db->autoCommit ){
121501 sqlite3SetString(pzErrMsg, db, "cannot VACUUM from within a transaction");
121502 return SQLITE_ERROR;
121503 }
@@ -121476,15 +121511,17 @@
121511 ** disable CHECK and foreign key constraints. */
121512 saved_flags = db->flags;
121513 saved_nChange = db->nChange;
121514 saved_nTotalChange = db->nTotalChange;
121515 saved_mTrace = db->mTrace;
121516 db->flags |= (SQLITE_WriteSchema | SQLITE_IgnoreChecks
121517 | SQLITE_PreferBuiltin | SQLITE_Vacuum);
121518 db->flags &= ~(SQLITE_ForeignKeys | SQLITE_ReverseOrder | SQLITE_CountRows);
121519 db->mTrace = 0;
121520
121521 zDbMain = db->aDb[iDb].zDbSName;
121522 pMain = db->aDb[iDb].pBt;
121523 isMemDb = sqlite3PagerIsMemdb(sqlite3BtreePager(pMain));
121524
121525 /* Attach the temporary database as 'vacuum_db'. The synchronous pragma
121526 ** can be set to 'off' for this file, as it is not recovered if a crash
121527 ** occurs anyway. The integrity of the database is maintained by a
@@ -121498,22 +121535,16 @@
121535 ** empty. Only the journal header is written. Apparently it takes more
121536 ** time to parse and run the PRAGMA to turn journalling off than it does
121537 ** to write the journal header file.
121538 */
121539 nDb = db->nDb;
121540 rc = execSql(db, pzErrMsg, "ATTACH''AS vacuum_db");
 
 
 
 
 
 
 
 
 
121541 if( rc!=SQLITE_OK ) goto end_of_vacuum;
121542 assert( (db->nDb-1)==nDb );
121543 pDb = &db->aDb[nDb];
121544 assert( strcmp(pDb->zDbSName,"vacuum_db")==0 );
121545 pTemp = pDb->pBt;
121546
121547 /* The call to execSql() to attach the temp database has left the file
121548 ** locked (as there was more than one active statement when the transaction
121549 ** to read the schema was concluded. Unlock it here so that this doesn't
121550 ** cause problems for the call to BtreeSetPageSize() below. */
@@ -121530,20 +121561,19 @@
121561 sqlite3CodecGetKey(db, 0, (void**)&zKey, &nKey);
121562 if( nKey ) db->nextPagesize = 0;
121563 }
121564 #endif
121565
121566 sqlite3BtreeSetCacheSize(pTemp, db->aDb[iDb].pSchema->cache_size);
121567 sqlite3BtreeSetSpillSize(pTemp, sqlite3BtreeSetSpillSize(pMain,0));
121568 sqlite3BtreeSetPagerFlags(pTemp, PAGER_SYNCHRONOUS_OFF);
 
121569
121570 /* Begin a transaction and take an exclusive lock on the main database
121571 ** file. This is done before the sqlite3BtreeGetPageSize(pMain) call below,
121572 ** to ensure that we do not try to change the page-size on a WAL database.
121573 */
121574 rc = execSql(db, pzErrMsg, "BEGIN");
121575 if( rc!=SQLITE_OK ) goto end_of_vacuum;
121576 rc = sqlite3BtreeBeginTrans(pMain, 2);
121577 if( rc!=SQLITE_OK ) goto end_of_vacuum;
121578
121579 /* Do not attempt to change the page size for a WAL database */
@@ -121566,68 +121596,52 @@
121596 #endif
121597
121598 /* Query the schema of the main database. Create a mirror schema
121599 ** in the temporary database.
121600 */
121601 db->init.iDb = nDb; /* force new CREATE statements into vacuum_db */
121602 rc = execSqlF(db, pzErrMsg,
121603 "SELECT sql FROM \"%w\".sqlite_master"
121604 " WHERE type='table'AND name<>'sqlite_sequence'"
121605 " AND coalesce(rootpage,1)>0",
121606 zDbMain
121607 );
121608 if( rc!=SQLITE_OK ) goto end_of_vacuum;
121609 rc = execSqlF(db, pzErrMsg,
121610 "SELECT sql FROM \"%w\".sqlite_master"
121611 " WHERE type='index' AND length(sql)>10",
121612 zDbMain
121613 );
121614 if( rc!=SQLITE_OK ) goto end_of_vacuum;
121615 db->init.iDb = 0;
 
 
 
 
 
 
 
121616
121617 /* Loop through the tables in the main database. For each, do
121618 ** an "INSERT INTO vacuum_db.xxx SELECT * FROM main.xxx;" to copy
121619 ** the contents to the temporary database.
121620 */
121621 rc = execSqlF(db, pzErrMsg,
121622 "SELECT'INSERT INTO vacuum_db.'||quote(name)"
121623 "||' SELECT*FROM\"%w\".'||quote(name)"
121624 "FROM vacuum_db.sqlite_master "
121625 "WHERE type='table'AND coalesce(rootpage,1)>0",
121626 zDbMain
 
 
121627 );
121628 assert( (db->flags & SQLITE_Vacuum)!=0 );
121629 db->flags &= ~SQLITE_Vacuum;
121630 if( rc!=SQLITE_OK ) goto end_of_vacuum;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
121631
121632 /* Copy the triggers, views, and virtual tables from the main database
121633 ** over to the temporary database. None of these objects has any
121634 ** associated storage, so all we have to do is copy their entries
121635 ** from the SQLITE_MASTER table.
121636 */
121637 rc = execSqlF(db, pzErrMsg,
121638 "INSERT INTO vacuum_db.sqlite_master"
121639 " SELECT*FROM \"%w\".sqlite_master"
121640 " WHERE type IN('view','trigger')"
121641 " OR(type='table'AND rootpage=0)",
121642 zDbMain
121643 );
121644 if( rc ) goto end_of_vacuum;
121645
121646 /* At this point, there is a write transaction open on both the
121647 ** vacuum database and the main database. Assuming no error occurs,
@@ -121677,10 +121691,11 @@
121691 assert( rc==SQLITE_OK );
121692 rc = sqlite3BtreeSetPageSize(pMain, sqlite3BtreeGetPageSize(pTemp), nRes,1);
121693
121694 end_of_vacuum:
121695 /* Restore the original value of db->flags */
121696 db->init.iDb = 0;
121697 db->flags = saved_flags;
121698 db->nChange = saved_nChange;
121699 db->nTotalChange = saved_nTotalChange;
121700 db->mTrace = saved_mTrace;
121701 sqlite3BtreeSetPageSize(pMain, -1, -1, 1);
@@ -122055,11 +122070,11 @@
122070 ** sqlite_master table, has already been made by sqlite3StartTable().
122071 ** The second call, to obtain permission to create the table, is made now.
122072 */
122073 if( pTable->azModuleArg ){
122074 sqlite3AuthCheck(pParse, SQLITE_CREATE_VTABLE, pTable->zName,
122075 pTable->azModuleArg[0], pParse->db->aDb[iDb].zDbSName);
122076 }
122077 #endif
122078 }
122079
122080 /*
@@ -122119,11 +122134,11 @@
122134 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
122135 sqlite3NestedParse(pParse,
122136 "UPDATE %Q.%s "
122137 "SET type='table', name=%Q, tbl_name=%Q, rootpage=0, sql=%Q "
122138 "WHERE rowid=#%d",
122139 db->aDb[iDb].zDbSName, SCHEMA_TABLE(iDb),
122140 pTab->zName,
122141 pTab->zName,
122142 zStmt,
122143 pParse->regRowid
122144 );
@@ -122229,11 +122244,11 @@
122244 }
122245 pVTable->db = db;
122246 pVTable->pMod = pMod;
122247
122248 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
122249 pTab->azModuleArg[1] = db->aDb[iDb].zDbSName;
122250
122251 /* Invoke the virtual table constructor */
122252 assert( &db->pVtabCtx );
122253 assert( xConstruct );
122254 sCtx.pTab = pTab;
@@ -122393,11 +122408,11 @@
122408 int rc = SQLITE_OK;
122409 Table *pTab;
122410 Module *pMod;
122411 const char *zMod;
122412
122413 pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zDbSName);
122414 assert( pTab && (pTab->tabFlags & TF_Virtual)!=0 && !pTab->pVTable );
122415
122416 /* Locate the required virtual table module */
122417 zMod = pTab->azModuleArg[0];
122418 pMod = (Module*)sqlite3HashFind(&db->aModule, zMod);
@@ -122517,11 +122532,11 @@
122532 */
122533 SQLITE_PRIVATE int sqlite3VtabCallDestroy(sqlite3 *db, int iDb, const char *zTab){
122534 int rc = SQLITE_OK;
122535 Table *pTab;
122536
122537 pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zDbSName);
122538 if( pTab!=0 && ALWAYS(pTab->pVTable!=0) ){
122539 VTable *p;
122540 int (*xDestroy)(sqlite3_vtab *);
122541 for(p=pTab->pVTable; p; p=p->pNext){
122542 assert( p->pVtab );
@@ -125630,11 +125645,11 @@
125645 */
125646 static int isMatchOfColumn(
125647 Expr *pExpr, /* Test this expression */
125648 unsigned char *peOp2 /* OUT: 0 for MATCH, or else an op2 value */
125649 ){
125650 static const struct Op2 {
125651 const char *zOp;
125652 unsigned char eOp2;
125653 } aOp[] = {
125654 { "match", SQLITE_INDEX_CONSTRAINT_MATCH },
125655 { "glob", SQLITE_INDEX_CONSTRAINT_GLOB },
@@ -126615,17 +126630,18 @@
126630 ** These routines walk (recursively) an expression tree and generate
126631 ** a bitmask indicating which tables are used in that expression
126632 ** tree.
126633 */
126634 SQLITE_PRIVATE Bitmask sqlite3WhereExprUsage(WhereMaskSet *pMaskSet, Expr *p){
126635 Bitmask mask;
126636 if( p==0 ) return 0;
126637 if( p->op==TK_COLUMN ){
126638 mask = sqlite3WhereGetMask(pMaskSet, p->iTable);
126639 return mask;
126640 }
126641 assert( !ExprHasProperty(p, EP_TokenOnly) );
126642 mask = p->pRight ? sqlite3WhereExprUsage(pMaskSet, p->pRight) : 0;
126643 if( p->pLeft ) mask |= sqlite3WhereExprUsage(pMaskSet, p->pLeft);
126644 if( ExprHasProperty(p, EP_xIsSelect) ){
126645 mask |= exprSelectUsage(pMaskSet, p->x.pSelect);
126646 }else if( p->x.pList ){
126647 mask |= sqlite3WhereExprListUsage(pMaskSet, p->x.pList);
@@ -131868,29 +131884,33 @@
131884 ** N between YY_MIN_SHIFTREDUCE Shift to an arbitrary state then
131885 ** and YY_MAX_SHIFTREDUCE reduce by rule N-YY_MIN_SHIFTREDUCE.
131886 **
131887 ** N between YY_MIN_REDUCE Reduce by rule N-YY_MIN_REDUCE
131888 ** and YY_MAX_REDUCE
131889 **
131890 ** N == YY_ERROR_ACTION A syntax error has occurred.
131891 **
131892 ** N == YY_ACCEPT_ACTION The parser accepts its input.
131893 **
131894 ** N == YY_NO_ACTION No such action. Denotes unused
131895 ** slots in the yy_action[] table.
131896 **
131897 ** The action table is constructed as a single large table named yy_action[].
131898 ** Given state S and lookahead X, the action is computed as either:
131899 **
131900 ** (A) N = yy_action[ yy_shift_ofst[S] + X ]
131901 ** (B) N = yy_default[S]
131902 **
131903 ** The (A) formula is preferred. The B formula is used instead if:
131904 ** (1) The yy_shift_ofst[S]+X value is out of range, or
131905 ** (2) yy_lookahead[yy_shift_ofst[S]+X] is not equal to X, or
131906 ** (3) yy_shift_ofst[S] equal YY_SHIFT_USE_DFLT.
131907 ** (Implementation note: YY_SHIFT_USE_DFLT is chosen so that
131908 ** YY_SHIFT_USE_DFLT+X will be out of range for all possible lookaheads X.
131909 ** Hence only tests (1) and (2) need to be evaluated.)
131910 **
131911 ** The formulas above are for computing the action when the lookahead is
131912 ** a terminal symbol. If the lookahead is a non-terminal (as occurs after
131913 ** a reduce action) then the yy_reduce_ofst[] array is used in place of
131914 ** the yy_shift_ofst[] array and YY_REDUCE_USE_DFLT is used in place of
131915 ** YY_SHIFT_USE_DFLT.
131916 **
@@ -132211,14 +132231,14 @@
132231 /* 1470 */ 122, 23, 23, 64, 22, 124, 26, 26, 64, 64,
132232 /* 1480 */ 23, 23, 23, 23, 11, 23, 22, 26, 23, 22,
132233 /* 1490 */ 24, 1, 23, 22, 26, 122, 24, 23, 22, 122,
132234 /* 1500 */ 23, 23, 22, 122, 122, 23, 15,
132235 };
132236 #define YY_SHIFT_USE_DFLT (1507)
132237 #define YY_SHIFT_COUNT (442)
132238 #define YY_SHIFT_MIN (-94)
132239 #define YY_SHIFT_MAX (1491)
132240 static const short yy_shift_ofst[] = {
132241 /* 0 */ 40, 564, 869, 577, 725, 725, 725, 725, 690, -19,
132242 /* 10 */ 16, 16, 100, 725, 725, 725, 725, 725, 725, 725,
132243 /* 20 */ 841, 841, 538, 507, 684, 565, 61, 137, 172, 207,
132244 /* 30 */ 242, 277, 312, 347, 382, 424, 424, 424, 424, 424,
@@ -132227,16 +132247,16 @@
132247 /* 60 */ 725, 725, 725, 725, 725, 725, 725, 725, 725, 725,
132248 /* 70 */ 725, 725, 725, 725, 725, 725, 725, 725, 725, 725,
132249 /* 80 */ 725, 725, 725, 725, 821, 725, 725, 725, 725, 725,
132250 /* 90 */ 725, 725, 725, 725, 725, 725, 725, 725, 952, 711,
132251 /* 100 */ 711, 711, 711, 711, 766, 23, 32, 924, 637, 825,
132252 /* 110 */ 837, 837, 924, 73, 183, -51, 1507, 1507, 1507, 501,
132253 /* 120 */ 501, 501, 903, 903, 632, 205, 241, 924, 924, 924,
132254 /* 130 */ 924, 924, 924, 924, 924, 924, 924, 924, 924, 924,
132255 /* 140 */ 924, 924, 924, 924, 924, 924, 924, 192, 1027, 1106,
132256 /* 150 */ 1106, 183, 176, 176, 176, 176, 176, 176, 1507, 1507,
132257 /* 160 */ 1507, 880, -94, -94, 578, 734, 99, 730, 769, 349,
132258 /* 170 */ 924, 924, 924, 924, 924, 924, 924, 924, 924, 924,
132259 /* 180 */ 924, 924, 924, 924, 924, 924, 924, 954, 954, 954,
132260 /* 190 */ 924, 924, 622, 924, 924, 924, -18, 924, 924, 914,
132261 /* 200 */ 924, 924, 924, 924, 924, 924, 924, 924, 924, 924,
132262 /* 210 */ 441, 1020, 1107, 1107, 1107, 569, 45, 217, 510, 423,
@@ -132246,12 +132266,12 @@
132266 /* 250 */ 1297, 1183, 1277, 1285, 1285, 1183, 1176, 1297, 1182, 1250,
132267 /* 260 */ 1176, 1176, 1297, 1311, 1176, 1297, 1176, 1297, 1311, 1234,
132268 /* 270 */ 1234, 1234, 1267, 1311, 1234, 1244, 1234, 1267, 1234, 1234,
132269 /* 280 */ 1232, 1247, 1232, 1247, 1232, 1247, 1232, 1247, 1176, 1334,
132270 /* 290 */ 1176, 1235, 1311, 1318, 1318, 1311, 1248, 1253, 1245, 1249,
132271 /* 300 */ 1183, 1355, 1357, 1368, 1368, 1378, 1378, 1378, 1378, 1507,
132272 /* 310 */ 1507, 1507, 1507, 1507, 1507, 1507, 1507, 451, 936, 816,
132273 /* 320 */ 888, 1069, 799, 1111, 1197, 1193, 1201, 1202, 1203, 1213,
132274 /* 330 */ 1134, 1117, 1230, 497, 1218, 1219, 1154, 1223, 1115, 1120,
132275 /* 340 */ 1231, 1164, 1160, 1392, 1394, 1376, 1257, 1385, 1307, 1386,
132276 /* 350 */ 1383, 1388, 1292, 1282, 1303, 1294, 1395, 1293, 1403, 1419,
132277 /* 360 */ 1298, 1291, 1389, 1390, 1314, 1372, 1365, 1308, 1430, 1427,
@@ -133200,54 +133220,51 @@
133220
133221 if( stateno>=YY_MIN_REDUCE ) return stateno;
133222 assert( stateno <= YY_SHIFT_COUNT );
133223 do{
133224 i = yy_shift_ofst[stateno];
 
133225 assert( iLookAhead!=YYNOCODE );
133226 i += iLookAhead;
133227 if( i<0 || i>=YY_ACTTAB_COUNT || yy_lookahead[i]!=iLookAhead ){
 
133228 #ifdef YYFALLBACK
133229 YYCODETYPE iFallback; /* Fallback token */
133230 if( iLookAhead<sizeof(yyFallback)/sizeof(yyFallback[0])
133231 && (iFallback = yyFallback[iLookAhead])!=0 ){
133232 #ifndef NDEBUG
133233 if( yyTraceFILE ){
133234 fprintf(yyTraceFILE, "%sFALLBACK %s => %s\n",
133235 yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]);
133236 }
133237 #endif
133238 assert( yyFallback[iFallback]==0 ); /* Fallback loop must terminate */
133239 iLookAhead = iFallback;
133240 continue;
133241 }
133242 #endif
133243 #ifdef YYWILDCARD
133244 {
133245 int j = i - iLookAhead + YYWILDCARD;
133246 if(
133247 #if YY_SHIFT_MIN+YYWILDCARD<0
133248 j>=0 &&
133249 #endif
133250 #if YY_SHIFT_MAX+YYWILDCARD>=YY_ACTTAB_COUNT
133251 j<YY_ACTTAB_COUNT &&
133252 #endif
133253 yy_lookahead[j]==YYWILDCARD && iLookAhead>0
133254 ){
133255 #ifndef NDEBUG
133256 if( yyTraceFILE ){
133257 fprintf(yyTraceFILE, "%sWILDCARD %s => %s\n",
133258 yyTracePrompt, yyTokenName[iLookAhead],
133259 yyTokenName[YYWILDCARD]);
133260 }
133261 #endif /* NDEBUG */
133262 return yy_action[j];
 
133263 }
133264 }
133265 #endif /* YYWILDCARD */
 
133266 return yy_default[stateno];
133267 }else{
133268 return yy_action[i];
133269 }
133270 }while(1);
@@ -134679,12 +134696,14 @@
134696 break;
134697 case 213: /* cmd ::= DROP INDEX ifexists fullname */
134698 {sqlite3DropIndex(pParse, yymsp[0].minor.yy185, yymsp[-1].minor.yy194);}
134699 break;
134700 case 214: /* cmd ::= VACUUM */
134701 {sqlite3Vacuum(pParse,0);}
134702 break;
134703 case 215: /* cmd ::= VACUUM nm */
134704 {sqlite3Vacuum(pParse,&yymsp[0].minor.yy0);}
134705 break;
134706 case 216: /* cmd ::= PRAGMA nm dbnm */
134707 {sqlite3Pragma(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,0,0);}
134708 break;
134709 case 217: /* cmd ::= PRAGMA nm dbnm EQ nmnum */
@@ -136006,18 +136025,30 @@
136025 assert( pParse->pNewTable==0 );
136026 assert( pParse->pNewTrigger==0 );
136027 assert( pParse->nVar==0 );
136028 assert( pParse->nzVar==0 );
136029 assert( pParse->azVar==0 );
136030 while( 1 ){
136031 assert( i>=0 );
136032 if( zSql[i]!=0 ){
136033 pParse->sLastToken.z = &zSql[i];
136034 pParse->sLastToken.n = sqlite3GetToken((u8*)&zSql[i],&tokenType);
136035 i += pParse->sLastToken.n;
136036 if( i>mxSqlLen ){
136037 pParse->rc = SQLITE_TOOBIG;
136038 break;
136039 }
136040 }else{
136041 /* Upon reaching the end of input, call the parser two more times
136042 ** with tokens TK_SEMI and 0, in that order. */
136043 if( lastTokenParsed==TK_SEMI ){
136044 tokenType = 0;
136045 }else if( lastTokenParsed==0 ){
136046 break;
136047 }else{
136048 tokenType = TK_SEMI;
136049 }
136050 }
136051 if( tokenType>=TK_SPACE ){
136052 assert( tokenType==TK_SPACE || tokenType==TK_ILLEGAL );
136053 if( db->u1.isInterrupted ){
136054 pParse->rc = SQLITE_INTERRUPT;
@@ -136034,19 +136065,10 @@
136065 if( pParse->rc!=SQLITE_OK || db->mallocFailed ) break;
136066 }
136067 }
136068 assert( nErr==0 );
136069 pParse->zTail = &zSql[i];
 
 
 
 
 
 
 
 
 
136070 #ifdef YYTRACKMAXSTACKDEPTH
136071 sqlite3_mutex_enter(sqlite3MallocMutex());
136072 sqlite3StatusHighwater(SQLITE_STATUS_PARSER_STACK,
136073 sqlite3ParserStackPeak(pEngine)
136074 );
@@ -137282,10 +137304,15 @@
137304 SQLITE_API int SQLITE_CDECL sqlite3_db_config(sqlite3 *db, int op, ...){
137305 va_list ap;
137306 int rc;
137307 va_start(ap, op);
137308 switch( op ){
137309 case SQLITE_DBCONFIG_MAINDBNAME: {
137310 db->aDb[0].zDbSName = va_arg(ap,char*);
137311 rc = SQLITE_OK;
137312 break;
137313 }
137314 case SQLITE_DBCONFIG_LOOKASIDE: {
137315 void *pBuf = va_arg(ap, void*); /* IMP: R-26835-10964 */
137316 int sz = va_arg(ap, int); /* IMP: R-47871-25994 */
137317 int cnt = va_arg(ap, int); /* IMP: R-04460-53386 */
137318 rc = setupLookaside(db, pBuf, sz, cnt);
@@ -139425,13 +139452,13 @@
139452 db->aDb[1].pSchema = sqlite3SchemaGet(db, 0);
139453
139454 /* The default safety_level for the main database is FULL; for the temp
139455 ** database it is OFF. This matches the pager layer defaults.
139456 */
139457 db->aDb[0].zDbSName = "main";
139458 db->aDb[0].safety_level = SQLITE_DEFAULT_SYNCHRONOUS+1;
139459 db->aDb[1].zDbSName = "temp";
139460 db->aDb[1].safety_level = PAGER_SYNCHRONOUS_OFF;
139461
139462 db->magic = SQLITE_MAGIC_OPEN;
139463 if( db->mallocFailed ){
139464 goto opendb_out;
@@ -140388,11 +140415,11 @@
140415 */
140416 SQLITE_PRIVATE Btree *sqlite3DbNameToBtree(sqlite3 *db, const char *zDbName){
140417 int i;
140418 for(i=0; i<db->nDb; i++){
140419 if( db->aDb[i].pBt
140420 && (zDbName==0 || sqlite3StrICmp(zDbName, db->aDb[i].zDbSName)==0)
140421 ){
140422 return db->aDb[i].pBt;
140423 }
140424 }
140425 return 0;
@@ -164754,19 +164781,25 @@
164781 /*
164782 ** Open an RBU handle to perform an RBU vacuum on database file zTarget.
164783 ** An RBU vacuum is similar to SQLite's built-in VACUUM command, except
164784 ** that it can be suspended and resumed like an RBU update.
164785 **
164786 ** The second argument to this function identifies a database in which
164787 ** to store the state of the RBU vacuum operation if it is suspended. The
164788 ** first time sqlite3rbu_vacuum() is called, to start an RBU vacuum
164789 ** operation, the state database should either not exist or be empty
164790 ** (contain no tables). If an RBU vacuum is suspended by calling
164791 ** sqlite3rbu_close() on the RBU handle before sqlite3rbu_step() has
164792 ** returned SQLITE_DONE, the vacuum state is stored in the state database.
164793 ** The vacuum can be resumed by calling this function to open a new RBU
164794 ** handle specifying the same target and state databases.
164795 **
164796 ** If the second argument passed to this function is NULL, then the
164797 ** name of the state database is "<database>-vacuum", where <database>
164798 ** is the name of the target database file. In this case, on UNIX, if the
164799 ** state database is not already present in the file-system, it is created
164800 ** with the same permissions as the target db is made.
164801 **
164802 ** This function does not delete the state database after an RBU vacuum
164803 ** is completed, even if it created it. However, if the call to
164804 ** sqlite3rbu_close() returns any value other than SQLITE_OK, the contents
164805 ** of the state tables within the state database are zeroed. This way,
@@ -167255,19 +167288,22 @@
167288 /*
167289 ** Open the database handle and attach the RBU database as "rbu". If an
167290 ** error occurs, leave an error code and message in the RBU handle.
167291 */
167292 static void rbuOpenDatabase(sqlite3rbu *p){
167293 assert( p->rc || (p->dbMain==0 && p->dbRbu==0) );
167294 assert( p->rc || rbuIsVacuum(p) || p->zTarget!=0 );
 
167295
167296 /* Open the RBU database */
167297 p->dbRbu = rbuOpenDbhandle(p, p->zRbu, 1);
167298
167299 if( p->rc==SQLITE_OK && rbuIsVacuum(p) ){
167300 sqlite3_file_control(p->dbRbu, "main", SQLITE_FCNTL_RBUCNT, (void*)p);
167301 if( p->zState==0 ){
167302 const char *zFile = sqlite3_db_filename(p->dbRbu, "main");
167303 p->zState = rbuMPrintf(p, "file://%s-vacuum?modeof=%s", zFile, zFile);
167304 }
167305 }
167306
167307 /* If using separate RBU and state databases, attach the state database to
167308 ** the RBU db handle now. */
167309 if( p->zState ){
@@ -168398,12 +168434,11 @@
168434 const char *zState
168435 ){
168436 sqlite3rbu *p;
168437 size_t nTarget = zTarget ? strlen(zTarget) : 0;
168438 size_t nRbu = strlen(zRbu);
168439 size_t nByte = sizeof(sqlite3rbu) + nTarget+1 + nRbu+1;
 
168440
168441 p = (sqlite3rbu*)sqlite3_malloc64(nByte);
168442 if( p ){
168443 RbuState *pState = 0;
168444
@@ -168421,12 +168456,11 @@
168456 }
168457 p->zRbu = pCsr;
168458 memcpy(p->zRbu, zRbu, nRbu+1);
168459 pCsr += nRbu+1;
168460 if( zState ){
168461 p->zState = rbuMPrintf(p, "%s", zState);
 
168462 }
168463 rbuOpenDatabase(p);
168464 }
168465
168466 if( p->rc==SQLITE_OK ){
@@ -168531,19 +168565,34 @@
168565 rbuFreeState(pState);
168566 }
168567
168568 return p;
168569 }
168570
168571 /*
168572 ** Allocate and return an RBU handle with all fields zeroed except for the
168573 ** error code, which is set to SQLITE_MISUSE.
168574 */
168575 static sqlite3rbu *rbuMisuseError(void){
168576 sqlite3rbu *pRet;
168577 pRet = sqlite3_malloc64(sizeof(sqlite3rbu));
168578 if( pRet ){
168579 memset(pRet, 0, sizeof(sqlite3rbu));
168580 pRet->rc = SQLITE_MISUSE;
168581 }
168582 return pRet;
168583 }
168584
168585 /*
168586 ** Open and return a new RBU handle.
168587 */
168588 SQLITE_API sqlite3rbu *SQLITE_STDCALL sqlite3rbu_open(
168589 const char *zTarget,
168590 const char *zRbu,
168591 const char *zState
168592 ){
168593 if( zTarget==0 || zRbu==0 ){ return rbuMisuseError(); }
168594 /* TODO: Check that zTarget and zRbu are non-NULL */
168595 return openRbuHandle(zTarget, zRbu, zState);
168596 }
168597
168598 /*
@@ -168551,10 +168600,11 @@
168600 */
168601 SQLITE_API sqlite3rbu *SQLITE_STDCALL sqlite3rbu_vacuum(
168602 const char *zTarget,
168603 const char *zState
168604 ){
168605 if( zTarget==0 ){ return rbuMisuseError(); }
168606 /* TODO: Check that both arguments are non-NULL */
168607 return openRbuHandle(0, zTarget, zState);
168608 }
168609
168610 /*
@@ -168628,10 +168678,11 @@
168678 sqlite3_free(p->aFrame);
168679
168680 rbuEditErrmsg(p);
168681 rc = p->rc;
168682 *pzErrmsg = p->zErrmsg;
168683 sqlite3_free(p->zState);
168684 sqlite3_free(p);
168685 }else{
168686 rc = SQLITE_NOMEM;
168687 *pzErrmsg = 0;
168688 }
@@ -170239,11 +170290,11 @@
170290 zSql = sqlite3_mprintf(
170291 "SELECT 'sqlite_master' AS name, 1 AS rootpage, 'table' AS type"
170292 " UNION ALL "
170293 "SELECT name, rootpage, type"
170294 " FROM \"%w\".%s WHERE rootpage!=0"
170295 " ORDER BY name", pTab->db->aDb[pCsr->iDb].zDbSName, zMaster);
170296 if( zSql==0 ){
170297 return SQLITE_NOMEM_BKPT;
170298 }else{
170299 rc = sqlite3_prepare_v2(pTab->db, zSql, -1, &pCsr->pStmt, 0);
170300 sqlite3_free(zSql);
@@ -170293,11 +170344,11 @@
170344 sqlite3_result_int(ctx, pCsr->szPage);
170345 break;
170346 default: { /* schema */
170347 sqlite3 *db = sqlite3_context_db_handle(ctx);
170348 int iDb = pCsr->iDb;
170349 sqlite3_result_text(ctx, db->aDb[iDb].zDbSName, -1, SQLITE_STATIC);
170350 break;
170351 }
170352 }
170353 return SQLITE_OK;
170354 }
@@ -178530,10 +178581,11 @@
178581 static void sqlite3Fts5ParseNearsetFree(Fts5ExprNearset*);
178582 static void sqlite3Fts5ParseNodeFree(Fts5ExprNode*);
178583
178584 static void sqlite3Fts5ParseSetDistance(Fts5Parse*, Fts5ExprNearset*, Fts5Token*);
178585 static void sqlite3Fts5ParseSetColset(Fts5Parse*, Fts5ExprNearset*, Fts5Colset*);
178586 static Fts5Colset *sqlite3Fts5ParseColsetInvert(Fts5Parse*, Fts5Colset*);
178587 static void sqlite3Fts5ParseFinished(Fts5Parse *pParse, Fts5ExprNode *p);
178588 static void sqlite3Fts5ParseNear(Fts5Parse *pParse, Fts5Token*);
178589
178590 /*
178591 ** End of interface to code in fts5_expr.c.
@@ -178587,16 +178639,17 @@
178639 #define FTS5_NOT 3
178640 #define FTS5_TERM 4
178641 #define FTS5_COLON 5
178642 #define FTS5_LP 6
178643 #define FTS5_RP 7
178644 #define FTS5_MINUS 8
178645 #define FTS5_LCP 9
178646 #define FTS5_RCP 10
178647 #define FTS5_STRING 11
178648 #define FTS5_COMMA 12
178649 #define FTS5_PLUS 13
178650 #define FTS5_STAR 14
178651
178652 /*
178653 ** 2000-05-29
178654 **
178655 ** The author disclaims copyright to this source code. In place of
@@ -178706,39 +178759,39 @@
178759 #ifndef INTERFACE
178760 # define INTERFACE 1
178761 #endif
178762 /************* Begin control #defines *****************************************/
178763 #define fts5YYCODETYPE unsigned char
178764 #define fts5YYNOCODE 28
178765 #define fts5YYACTIONTYPE unsigned char
178766 #define sqlite3Fts5ParserFTS5TOKENTYPE Fts5Token
178767 typedef union {
178768 int fts5yyinit;
178769 sqlite3Fts5ParserFTS5TOKENTYPE fts5yy0;
178770 int fts5yy4;
178771 Fts5Colset* fts5yy11;
178772 Fts5ExprNode* fts5yy24;
178773 Fts5ExprNearset* fts5yy46;
178774 Fts5ExprPhrase* fts5yy53;
178775 } fts5YYMINORTYPE;
178776 #ifndef fts5YYSTACKDEPTH
178777 #define fts5YYSTACKDEPTH 100
178778 #endif
178779 #define sqlite3Fts5ParserARG_SDECL Fts5Parse *pParse;
178780 #define sqlite3Fts5ParserARG_PDECL ,Fts5Parse *pParse
178781 #define sqlite3Fts5ParserARG_FETCH Fts5Parse *pParse = fts5yypParser->pParse
178782 #define sqlite3Fts5ParserARG_STORE fts5yypParser->pParse = pParse
178783 #define fts5YYNSTATE 29
178784 #define fts5YYNRULE 26
178785 #define fts5YY_MAX_SHIFT 28
178786 #define fts5YY_MIN_SHIFTREDUCE 45
178787 #define fts5YY_MAX_SHIFTREDUCE 70
178788 #define fts5YY_MIN_REDUCE 71
178789 #define fts5YY_MAX_REDUCE 96
178790 #define fts5YY_ERROR_ACTION 97
178791 #define fts5YY_ACCEPT_ACTION 98
178792 #define fts5YY_NO_ACTION 99
178793 /************* End control #defines *******************************************/
178794
178795 /* Define the fts5yytestcase() macro to be a no-op if is not already defined
178796 ** otherwise.
178797 **
@@ -178766,29 +178819,33 @@
178819 ** N between fts5YY_MIN_SHIFTREDUCE Shift to an arbitrary state then
178820 ** and fts5YY_MAX_SHIFTREDUCE reduce by rule N-fts5YY_MIN_SHIFTREDUCE.
178821 **
178822 ** N between fts5YY_MIN_REDUCE Reduce by rule N-fts5YY_MIN_REDUCE
178823 ** and fts5YY_MAX_REDUCE
178824 **
178825 ** N == fts5YY_ERROR_ACTION A syntax error has occurred.
178826 **
178827 ** N == fts5YY_ACCEPT_ACTION The parser accepts its input.
178828 **
178829 ** N == fts5YY_NO_ACTION No such action. Denotes unused
178830 ** slots in the fts5yy_action[] table.
178831 **
178832 ** The action table is constructed as a single large table named fts5yy_action[].
178833 ** Given state S and lookahead X, the action is computed as either:
178834 **
178835 ** (A) N = fts5yy_action[ fts5yy_shift_ofst[S] + X ]
178836 ** (B) N = fts5yy_default[S]
178837 **
178838 ** The (A) formula is preferred. The B formula is used instead if:
178839 ** (1) The fts5yy_shift_ofst[S]+X value is out of range, or
178840 ** (2) fts5yy_lookahead[fts5yy_shift_ofst[S]+X] is not equal to X, or
178841 ** (3) fts5yy_shift_ofst[S] equal fts5YY_SHIFT_USE_DFLT.
178842 ** (Implementation note: fts5YY_SHIFT_USE_DFLT is chosen so that
178843 ** fts5YY_SHIFT_USE_DFLT+X will be out of range for all possible lookaheads X.
178844 ** Hence only tests (1) and (2) need to be evaluated.)
178845 **
178846 ** The formulas above are for computing the action when the lookahead is
178847 ** a terminal symbol. If the lookahead is a non-terminal (as occurs after
178848 ** a reduce action) then the fts5yy_reduce_ofst[] array is used in place of
178849 ** the fts5yy_shift_ofst[] array and fts5YY_REDUCE_USE_DFLT is used in place of
178850 ** fts5YY_SHIFT_USE_DFLT.
178851 **
@@ -178802,52 +178859,54 @@
178859 ** fts5yy_reduce_ofst[] For each state, the offset into fts5yy_action for
178860 ** shifting non-terminals after a reduce.
178861 ** fts5yy_default[] Default action for each state.
178862 **
178863 *********** Begin parsing tables **********************************************/
178864 #define fts5YY_ACTTAB_COUNT (85)
178865 static const fts5YYACTIONTYPE fts5yy_action[] = {
178866 /* 0 */ 98, 16, 51, 5, 53, 27, 83, 7, 26, 15,
178867 /* 10 */ 51, 5, 53, 27, 13, 69, 26, 48, 51, 5,
178868 /* 20 */ 53, 27, 19, 11, 26, 9, 20, 51, 5, 53,
178869 /* 30 */ 27, 13, 22, 26, 28, 51, 5, 53, 27, 68,
178870 /* 40 */ 1, 26, 19, 11, 17, 9, 52, 10, 53, 27,
178871 /* 50 */ 23, 24, 26, 54, 3, 4, 2, 26, 6, 21,
178872 /* 60 */ 49, 71, 3, 4, 2, 7, 56, 59, 55, 59,
178873 /* 70 */ 4, 2, 12, 69, 58, 60, 18, 67, 62, 69,
178874 /* 80 */ 25, 66, 8, 14, 2,
178875 };
178876 static const fts5YYCODETYPE fts5yy_lookahead[] = {
178877 /* 0 */ 16, 17, 18, 19, 20, 21, 5, 6, 24, 17,
178878 /* 10 */ 18, 19, 20, 21, 11, 14, 24, 17, 18, 19,
178879 /* 20 */ 20, 21, 8, 9, 24, 11, 17, 18, 19, 20,
178880 /* 30 */ 21, 11, 12, 24, 17, 18, 19, 20, 21, 26,
178881 /* 40 */ 6, 24, 8, 9, 22, 11, 18, 11, 20, 21,
178882 /* 50 */ 24, 25, 24, 20, 1, 2, 3, 24, 23, 24,
178883 /* 60 */ 7, 0, 1, 2, 3, 6, 10, 11, 10, 11,
178884 /* 70 */ 2, 3, 9, 14, 11, 11, 22, 26, 7, 14,
178885 /* 80 */ 13, 11, 5, 11, 3,
178886 };
178887 #define fts5YY_SHIFT_USE_DFLT (85)
178888 #define fts5YY_SHIFT_COUNT (28)
178889 #define fts5YY_SHIFT_MIN (0)
178890 #define fts5YY_SHIFT_MAX (81)
178891 static const unsigned char fts5yy_shift_ofst[] = {
178892 /* 0 */ 34, 34, 34, 34, 34, 14, 20, 3, 36, 1,
178893 /* 10 */ 59, 64, 64, 65, 65, 53, 61, 56, 58, 63,
178894 /* 20 */ 68, 67, 70, 67, 71, 72, 67, 77, 81,
178895 };
178896 #define fts5YY_REDUCE_USE_DFLT (-17)
178897 #define fts5YY_REDUCE_COUNT (14)
178898 #define fts5YY_REDUCE_MIN (-16)
178899 #define fts5YY_REDUCE_MAX (54)
178900 static const signed char fts5yy_reduce_ofst[] = {
178901 /* 0 */ -16, -8, 0, 9, 17, 28, 26, 35, 33, 13,
178902 /* 10 */ 13, 22, 54, 13, 51,
178903 };
178904 static const fts5YYACTIONTYPE fts5yy_default[] = {
178905 /* 0 */ 97, 97, 97, 97, 97, 76, 91, 97, 97, 96,
178906 /* 10 */ 96, 97, 97, 96, 96, 97, 97, 97, 97, 97,
178907 /* 20 */ 73, 89, 97, 90, 97, 97, 87, 97, 72,
178908 };
178909 /********** End of lemon-generated parsing tables *****************************/
178910
178911 /* The next table maps tokens (terminal symbols) into fallback tokens.
178912 ** If a construct like the following:
@@ -178950,15 +179009,15 @@
179009 /* For tracing shifts, the names of all terminals and nonterminals
179010 ** are required. The following table supplies these names */
179011 static const char *const fts5yyTokenName[] = {
179012 "$", "OR", "AND", "NOT",
179013 "TERM", "COLON", "LP", "RP",
179014 "MINUS", "LCP", "RCP", "STRING",
179015 "COMMA", "PLUS", "STAR", "error",
179016 "input", "expr", "cnearset", "exprlist",
179017 "nearset", "colset", "colsetlist", "nearphrases",
179018 "phrase", "neardist_opt", "star_opt",
179019 };
179020 #endif /* NDEBUG */
179021
179022 #ifndef NDEBUG
179023 /* For tracing reduce actions, the names of all rules are required.
@@ -178972,24 +179031,26 @@
179031 /* 5 */ "expr ::= exprlist",
179032 /* 6 */ "exprlist ::= cnearset",
179033 /* 7 */ "exprlist ::= exprlist cnearset",
179034 /* 8 */ "cnearset ::= nearset",
179035 /* 9 */ "cnearset ::= colset COLON nearset",
179036 /* 10 */ "colset ::= MINUS LCP colsetlist RCP",
179037 /* 11 */ "colset ::= LCP colsetlist RCP",
179038 /* 12 */ "colset ::= STRING",
179039 /* 13 */ "colset ::= MINUS STRING",
179040 /* 14 */ "colsetlist ::= colsetlist STRING",
179041 /* 15 */ "colsetlist ::= STRING",
179042 /* 16 */ "nearset ::= phrase",
179043 /* 17 */ "nearset ::= STRING LP nearphrases neardist_opt RP",
179044 /* 18 */ "nearphrases ::= phrase",
179045 /* 19 */ "nearphrases ::= nearphrases phrase",
179046 /* 20 */ "neardist_opt ::=",
179047 /* 21 */ "neardist_opt ::= COMMA STRING",
179048 /* 22 */ "phrase ::= phrase PLUS STRING star_opt",
179049 /* 23 */ "phrase ::= STRING star_opt",
179050 /* 24 */ "star_opt ::= STAR",
179051 /* 25 */ "star_opt ::=",
179052 };
179053 #endif /* NDEBUG */
179054
179055
179056 #if fts5YYSTACKDEPTH<=0
@@ -179095,37 +179156,37 @@
179156 ** Note: during a reduce, the only symbols destroyed are those
179157 ** which appear on the RHS of the rule, but which are *not* used
179158 ** inside the C code.
179159 */
179160 /********* Begin destructor definitions ***************************************/
179161 case 16: /* input */
179162 {
179163 (void)pParse;
179164 }
179165 break;
179166 case 17: /* expr */
179167 case 18: /* cnearset */
179168 case 19: /* exprlist */
179169 {
179170 sqlite3Fts5ParseNodeFree((fts5yypminor->fts5yy24));
179171 }
179172 break;
179173 case 20: /* nearset */
179174 case 23: /* nearphrases */
179175 {
179176 sqlite3Fts5ParseNearsetFree((fts5yypminor->fts5yy46));
179177 }
179178 break;
179179 case 21: /* colset */
179180 case 22: /* colsetlist */
179181 {
179182 sqlite3_free((fts5yypminor->fts5yy11));
179183 }
179184 break;
179185 case 24: /* phrase */
179186 {
179187 sqlite3Fts5ParsePhraseFree((fts5yypminor->fts5yy53));
179188 }
179189 break;
179190 /********* End destructor definitions *****************************************/
179191 default: break; /* If no destructor action specified: do nothing */
179192 }
@@ -179198,54 +179259,51 @@
179259
179260 if( stateno>=fts5YY_MIN_REDUCE ) return stateno;
179261 assert( stateno <= fts5YY_SHIFT_COUNT );
179262 do{
179263 i = fts5yy_shift_ofst[stateno];
 
179264 assert( iLookAhead!=fts5YYNOCODE );
179265 i += iLookAhead;
179266 if( i<0 || i>=fts5YY_ACTTAB_COUNT || fts5yy_lookahead[i]!=iLookAhead ){
 
179267 #ifdef fts5YYFALLBACK
179268 fts5YYCODETYPE iFallback; /* Fallback token */
179269 if( iLookAhead<sizeof(fts5yyFallback)/sizeof(fts5yyFallback[0])
179270 && (iFallback = fts5yyFallback[iLookAhead])!=0 ){
179271 #ifndef NDEBUG
179272 if( fts5yyTraceFILE ){
179273 fprintf(fts5yyTraceFILE, "%sFALLBACK %s => %s\n",
179274 fts5yyTracePrompt, fts5yyTokenName[iLookAhead], fts5yyTokenName[iFallback]);
179275 }
179276 #endif
179277 assert( fts5yyFallback[iFallback]==0 ); /* Fallback loop must terminate */
179278 iLookAhead = iFallback;
179279 continue;
179280 }
179281 #endif
179282 #ifdef fts5YYWILDCARD
179283 {
179284 int j = i - iLookAhead + fts5YYWILDCARD;
179285 if(
179286 #if fts5YY_SHIFT_MIN+fts5YYWILDCARD<0
179287 j>=0 &&
179288 #endif
179289 #if fts5YY_SHIFT_MAX+fts5YYWILDCARD>=fts5YY_ACTTAB_COUNT
179290 j<fts5YY_ACTTAB_COUNT &&
179291 #endif
179292 fts5yy_lookahead[j]==fts5YYWILDCARD && iLookAhead>0
179293 ){
179294 #ifndef NDEBUG
179295 if( fts5yyTraceFILE ){
179296 fprintf(fts5yyTraceFILE, "%sWILDCARD %s => %s\n",
179297 fts5yyTracePrompt, fts5yyTokenName[iLookAhead],
179298 fts5yyTokenName[fts5YYWILDCARD]);
179299 }
179300 #endif /* NDEBUG */
179301 return fts5yy_action[j];
 
179302 }
179303 }
179304 #endif /* fts5YYWILDCARD */
 
179305 return fts5yy_default[stateno];
179306 }else{
179307 return fts5yy_action[i];
179308 }
179309 }while(1);
@@ -179368,34 +179426,36 @@
179426 */
179427 static const struct {
179428 fts5YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */
179429 unsigned char nrhs; /* Number of right-hand side symbols in the rule */
179430 } fts5yyRuleInfo[] = {
 
 
 
 
 
179431 { 16, 1 },
179432 { 17, 3 },
179433 { 17, 3 },
179434 { 17, 3 },
179435 { 17, 3 },
179436 { 17, 1 },
179437 { 19, 1 },
179438 { 19, 2 },
179439 { 18, 1 },
179440 { 18, 3 },
179441 { 21, 4 },
179442 { 21, 3 },
179443 { 21, 1 },
 
179444 { 21, 2 },
179445 { 22, 2 },
 
 
179446 { 22, 1 },
179447 { 20, 1 },
179448 { 20, 5 },
179449 { 23, 1 },
 
179450 { 23, 2 },
 
179451 { 25, 0 },
179452 { 25, 2 },
179453 { 24, 4 },
179454 { 24, 2 },
179455 { 26, 1 },
179456 { 26, 0 },
179457 };
179458
179459 static void fts5yy_accept(fts5yyParser*); /* Forward Declaration */
179460
179461 /*
@@ -179456,124 +179516,135 @@
179516 ** break;
179517 */
179518 /********** Begin reduce actions **********************************************/
179519 fts5YYMINORTYPE fts5yylhsminor;
179520 case 0: /* input ::= expr */
179521 { sqlite3Fts5ParseFinished(pParse, fts5yymsp[0].minor.fts5yy24); }
179522 break;
179523 case 1: /* expr ::= expr AND expr */
179524 {
179525 fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_AND, fts5yymsp[-2].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24, 0);
179526 }
179527 fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
179528 break;
179529 case 2: /* expr ::= expr OR expr */
179530 {
179531 fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_OR, fts5yymsp[-2].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24, 0);
179532 }
179533 fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
179534 break;
179535 case 3: /* expr ::= expr NOT expr */
179536 {
179537 fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_NOT, fts5yymsp[-2].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24, 0);
179538 }
179539 fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
179540 break;
179541 case 4: /* expr ::= LP expr RP */
179542 {fts5yymsp[-2].minor.fts5yy24 = fts5yymsp[-1].minor.fts5yy24;}
179543 break;
179544 case 5: /* expr ::= exprlist */
179545 case 6: /* exprlist ::= cnearset */ fts5yytestcase(fts5yyruleno==6);
179546 {fts5yylhsminor.fts5yy24 = fts5yymsp[0].minor.fts5yy24;}
179547 fts5yymsp[0].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
179548 break;
179549 case 7: /* exprlist ::= exprlist cnearset */
179550 {
179551 fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseImplicitAnd(pParse, fts5yymsp[-1].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24);
179552 }
179553 fts5yymsp[-1].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
179554 break;
179555 case 8: /* cnearset ::= nearset */
179556 {
179557 fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_STRING, 0, 0, fts5yymsp[0].minor.fts5yy46);
179558 }
179559 fts5yymsp[0].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
179560 break;
179561 case 9: /* cnearset ::= colset COLON nearset */
179562 {
179563 sqlite3Fts5ParseSetColset(pParse, fts5yymsp[0].minor.fts5yy46, fts5yymsp[-2].minor.fts5yy11);
179564 fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_STRING, 0, 0, fts5yymsp[0].minor.fts5yy46);
179565 }
179566 fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
179567 break;
179568 case 10: /* colset ::= MINUS LCP colsetlist RCP */
179569 {
179570 fts5yymsp[-3].minor.fts5yy11 = sqlite3Fts5ParseColsetInvert(pParse, fts5yymsp[-1].minor.fts5yy11);
179571 }
179572 break;
179573 case 11: /* colset ::= LCP colsetlist RCP */
179574 { fts5yymsp[-2].minor.fts5yy11 = fts5yymsp[-1].minor.fts5yy11; }
179575 break;
179576 case 12: /* colset ::= STRING */
179577 {
179578 fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
179579 }
179580 fts5yymsp[0].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
179581 break;
179582 case 13: /* colset ::= MINUS STRING */
179583 {
179584 fts5yymsp[-1].minor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
179585 fts5yymsp[-1].minor.fts5yy11 = sqlite3Fts5ParseColsetInvert(pParse, fts5yymsp[-1].minor.fts5yy11);
179586 }
179587 break;
179588 case 14: /* colsetlist ::= colsetlist STRING */
179589 {
179590 fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseColset(pParse, fts5yymsp[-1].minor.fts5yy11, &fts5yymsp[0].minor.fts5yy0); }
179591 fts5yymsp[-1].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
179592 break;
179593 case 15: /* colsetlist ::= STRING */
179594 {
179595 fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
179596 }
179597 fts5yymsp[0].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
179598 break;
179599 case 16: /* nearset ::= phrase */
179600 { fts5yylhsminor.fts5yy46 = sqlite3Fts5ParseNearset(pParse, 0, fts5yymsp[0].minor.fts5yy53); }
179601 fts5yymsp[0].minor.fts5yy46 = fts5yylhsminor.fts5yy46;
179602 break;
179603 case 17: /* nearset ::= STRING LP nearphrases neardist_opt RP */
179604 {
179605 sqlite3Fts5ParseNear(pParse, &fts5yymsp[-4].minor.fts5yy0);
179606 sqlite3Fts5ParseSetDistance(pParse, fts5yymsp[-2].minor.fts5yy46, &fts5yymsp[-1].minor.fts5yy0);
179607 fts5yylhsminor.fts5yy46 = fts5yymsp[-2].minor.fts5yy46;
179608 }
179609 fts5yymsp[-4].minor.fts5yy46 = fts5yylhsminor.fts5yy46;
179610 break;
179611 case 18: /* nearphrases ::= phrase */
179612 {
179613 fts5yylhsminor.fts5yy46 = sqlite3Fts5ParseNearset(pParse, 0, fts5yymsp[0].minor.fts5yy53);
179614 }
179615 fts5yymsp[0].minor.fts5yy46 = fts5yylhsminor.fts5yy46;
179616 break;
179617 case 19: /* nearphrases ::= nearphrases phrase */
179618 {
179619 fts5yylhsminor.fts5yy46 = sqlite3Fts5ParseNearset(pParse, fts5yymsp[-1].minor.fts5yy46, fts5yymsp[0].minor.fts5yy53);
179620 }
179621 fts5yymsp[-1].minor.fts5yy46 = fts5yylhsminor.fts5yy46;
179622 break;
179623 case 20: /* neardist_opt ::= */
179624 { fts5yymsp[1].minor.fts5yy0.p = 0; fts5yymsp[1].minor.fts5yy0.n = 0; }
179625 break;
179626 case 21: /* neardist_opt ::= COMMA STRING */
179627 { fts5yymsp[-1].minor.fts5yy0 = fts5yymsp[0].minor.fts5yy0; }
179628 break;
179629 case 22: /* phrase ::= phrase PLUS STRING star_opt */
179630 {
179631 fts5yylhsminor.fts5yy53 = sqlite3Fts5ParseTerm(pParse, fts5yymsp[-3].minor.fts5yy53, &fts5yymsp[-1].minor.fts5yy0, fts5yymsp[0].minor.fts5yy4);
179632 }
179633 fts5yymsp[-3].minor.fts5yy53 = fts5yylhsminor.fts5yy53;
179634 break;
179635 case 23: /* phrase ::= STRING star_opt */
179636 {
179637 fts5yylhsminor.fts5yy53 = sqlite3Fts5ParseTerm(pParse, 0, &fts5yymsp[-1].minor.fts5yy0, fts5yymsp[0].minor.fts5yy4);
179638 }
179639 fts5yymsp[-1].minor.fts5yy53 = fts5yylhsminor.fts5yy53;
179640 break;
179641 case 24: /* star_opt ::= STAR */
179642 { fts5yymsp[0].minor.fts5yy4 = 1; }
179643 break;
179644 case 25: /* star_opt ::= */
179645 { fts5yymsp[1].minor.fts5yy4 = 0; }
179646 break;
179647 default:
179648 break;
179649 /********** End reduce actions ************************************************/
179650 };
@@ -180027,11 +180098,11 @@
180098 }
180099
180100 if( p->iRangeEnd>0 && iPos==p->iRangeEnd ){
180101 fts5HighlightAppend(&rc, p, &p->zIn[p->iOff], iEndOff - p->iOff);
180102 p->iOff = iEndOff;
180103 if( iPos>=p->iter.iStart && iPos<p->iter.iEnd ){
180104 fts5HighlightAppend(&rc, p, p->zClose, -1);
180105 }
180106 }
180107
180108 return rc;
@@ -180188,10 +180259,17 @@
180259 ctx.iRangeEnd = iBestStart + nToken - 1;
180260
180261 if( iBestStart>0 ){
180262 fts5HighlightAppend(&rc, &ctx, zEllips, -1);
180263 }
180264
180265 /* Advance iterator ctx.iter so that it points to the first coalesced
180266 ** phrase instance at or following position iBestStart. */
180267 while( ctx.iter.iStart>=0 && ctx.iter.iStart<iBestStart && rc==SQLITE_OK ){
180268 rc = fts5CInstIterNext(&ctx.iter);
180269 }
180270
180271 if( rc==SQLITE_OK ){
180272 rc = pApi->xTokenize(pFts, ctx.zIn, ctx.nIn, (void*)&ctx,fts5HighlightCb);
180273 }
180274 if( ctx.iRangeEnd>=(nColSize-1) ){
180275 fts5HighlightAppend(&rc, &ctx, &ctx.zIn[ctx.iOff], ctx.nIn - ctx.iOff);
@@ -181923,10 +182001,11 @@
182001 case '}': tok = FTS5_RCP; break;
182002 case ':': tok = FTS5_COLON; break;
182003 case ',': tok = FTS5_COMMA; break;
182004 case '+': tok = FTS5_PLUS; break;
182005 case '*': tok = FTS5_STAR; break;
182006 case '-': tok = FTS5_MINUS; break;
182007 case '\0': tok = FTS5_EOF; break;
182008
182009 case '"': {
182010 const char *z2;
182011 tok = FTS5_STRING;
@@ -183414,11 +183493,11 @@
183493 sizeof(Fts5ExprNearset) + sizeof(Fts5ExprPhrase*));
183494 }
183495 if( rc==SQLITE_OK ){
183496 Fts5Colset *pColsetOrig = pOrig->pNode->pNear->pColset;
183497 if( pColsetOrig ){
183498 int nByte = sizeof(Fts5Colset) + (pColsetOrig->nCol-1) * sizeof(int);
183499 Fts5Colset *pColset = (Fts5Colset*)sqlite3Fts5MallocZero(&rc, nByte);
183500 if( pColset ){
183501 memcpy(pColset, pColsetOrig, nByte);
183502 }
183503 pNew->pRoot->pNear->pColset = pColset;
@@ -183548,10 +183627,38 @@
183627 #endif
183628 }
183629
183630 return pNew;
183631 }
183632
183633 /*
183634 ** Allocate and return an Fts5Colset object specifying the inverse of
183635 ** the colset passed as the second argument. Free the colset passed
183636 ** as the second argument before returning.
183637 */
183638 static Fts5Colset *sqlite3Fts5ParseColsetInvert(Fts5Parse *pParse, Fts5Colset *p){
183639 Fts5Colset *pRet;
183640 int nCol = pParse->pConfig->nCol;
183641
183642 pRet = (Fts5Colset*)sqlite3Fts5MallocZero(&pParse->rc,
183643 sizeof(Fts5Colset) + sizeof(int)*nCol
183644 );
183645 if( pRet ){
183646 int i;
183647 int iOld = 0;
183648 for(i=0; i<nCol; i++){
183649 if( iOld>=p->nCol || p->aiCol[iOld]!=i ){
183650 pRet->aiCol[pRet->nCol++] = i;
183651 }else{
183652 iOld++;
183653 }
183654 }
183655 }
183656
183657 sqlite3_free(p);
183658 return pRet;
183659 }
183660
183661 static Fts5Colset *sqlite3Fts5ParseColset(
183662 Fts5Parse *pParse, /* Store SQLITE_NOMEM here if required */
183663 Fts5Colset *pColset, /* Existing colset object */
183664 Fts5Token *p
@@ -185644,18 +185751,29 @@
185751
185752 assert( (pRet==0)==(p->rc!=SQLITE_OK) );
185753 return pRet;
185754 }
185755
 
185756 /*
185757 ** Release a reference to data record returned by an earlier call to
185758 ** fts5DataRead().
185759 */
185760 static void fts5DataRelease(Fts5Data *pData){
185761 sqlite3_free(pData);
185762 }
185763
185764 static Fts5Data *fts5LeafRead(Fts5Index *p, i64 iRowid){
185765 Fts5Data *pRet = fts5DataRead(p, iRowid);
185766 if( pRet ){
185767 if( pRet->szLeaf>pRet->nn ){
185768 p->rc = FTS5_CORRUPT;
185769 fts5DataRelease(pRet);
185770 pRet = 0;
185771 }
185772 }
185773 return pRet;
185774 }
185775
185776 static int fts5IndexPrepareStmt(
185777 Fts5Index *p,
185778 sqlite3_stmt **ppStmt,
185779 char *zSql
@@ -186461,11 +186579,11 @@
186579 pIter->iLeafPgno++;
186580 if( pIter->pNextLeaf ){
186581 pIter->pLeaf = pIter->pNextLeaf;
186582 pIter->pNextLeaf = 0;
186583 }else if( pIter->iLeafPgno<=pSeg->pgnoLast ){
186584 pIter->pLeaf = fts5LeafRead(p,
186585 FTS5_SEGMENT_ROWID(pSeg->iSegid, pIter->iLeafPgno)
186586 );
186587 }else{
186588 pIter->pLeaf = 0;
186589 }
@@ -186964,13 +187082,12 @@
187082 pIter->iLeafOffset = iOff;
187083
187084 if( pLeaf->nn>pLeaf->szLeaf ){
187085 pIter->iPgidxOff = pLeaf->szLeaf + fts5GetVarint32(
187086 &pLeaf->p[pLeaf->szLeaf], pIter->iEndofDoclist
187087 );
187088 }
 
187089 }
187090 else if( pLeaf->nn>pLeaf->szLeaf ){
187091 pIter->iPgidxOff = pLeaf->szLeaf + fts5GetVarint32(
187092 &pLeaf->p[pLeaf->szLeaf], iOff
187093 );
@@ -187210,10 +187327,15 @@
187327 }
187328
187329 iPgidx += fts5GetVarint32(&a[iPgidx], nKeep);
187330 iTermOff += nKeep;
187331 iOff = iTermOff;
187332
187333 if( iOff>=n ){
187334 p->rc = FTS5_CORRUPT;
187335 return;
187336 }
187337
187338 /* Read the nKeep field of the next term. */
187339 fts5FastGetVarint32(a, iOff, nKeep);
187340 }
187341
@@ -188136,10 +188258,19 @@
188258 fts5BufferZero(&pIter->poslist);
188259 fts5SegiterPoslist(pIter->pIndex, pSeg, 0, &pIter->poslist);
188260 pIter->base.pData = pIter->poslist.p;
188261 }
188262 }
188263
188264 /*
188265 ** xSetOutputs callback used when the Fts5Colset object has nCol==0 (match
188266 ** against no columns at all).
188267 */
188268 static void fts5IterSetOutputs_ZeroColset(Fts5Iter *pIter, Fts5SegIter *pSeg){
188269 UNUSED_PARAM(pSeg);
188270 pIter->base.nData = 0;
188271 }
188272
188273 /*
188274 ** xSetOutputs callback used by detail=col when there is a column filter
188275 ** and there are 100 or more columns. Also called as a fallback from
188276 ** fts5IterSetOutputs_Col100 if the column-list spans more than one page.
@@ -188241,10 +188372,14 @@
188372 }
188373
188374 else if( pIter->pColset==0 ){
188375 pIter->xSetOutputs = fts5IterSetOutputs_Nocolset;
188376 }
188377
188378 else if( pIter->pColset->nCol==0 ){
188379 pIter->xSetOutputs = fts5IterSetOutputs_ZeroColset;
188380 }
188381
188382 else if( pConfig->eDetail==FTS5_DETAIL_FULL ){
188383 pIter->xSetOutputs = fts5IterSetOutputs_Full;
188384 }
188385
@@ -194018,11 +194153,11 @@
194153 int nArg, /* Number of args */
194154 sqlite3_value **apUnused /* Function arguments */
194155 ){
194156 assert( nArg==0 );
194157 UNUSED_PARAM2(nArg, apUnused);
194158 sqlite3_result_text(pCtx, "fts5: 2016-08-20 18:06:14 9041ee4a6f0e8389297f887f1431ab5cfe783390", -1, SQLITE_TRANSIENT);
194159 }
194160
194161 static int fts5Init(sqlite3 *db){
194162 static const sqlite3_module fts5Mod = {
194163 /* iVersion */ 2,
194164
+691 -556
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
11
/******************************************************************************
22
** This file is an amalgamation of many separate C source files from SQLite
3
-** version 3.14.1. By combining all the individual C code files into this
3
+** version 3.15.0. By combining all the individual C code files into this
44
** single large file, the entire code can be compiled as a single translation
55
** unit. This allows many compilers to do optimizations that would not be
66
** possible if the files were compiled separately. Performance improvements
77
** of 5% or more are commonly seen when SQLite is compiled as a single
88
** translation unit.
@@ -378,13 +378,13 @@
378378
**
379379
** See also: [sqlite3_libversion()],
380380
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
381381
** [sqlite_version()] and [sqlite_source_id()].
382382
*/
383
-#define SQLITE_VERSION "3.14.1"
384
-#define SQLITE_VERSION_NUMBER 3014001
385
-#define SQLITE_SOURCE_ID "2016-08-11 18:53:32 a12d8059770df4bca59e321c266410344242bf7b"
383
+#define SQLITE_VERSION "3.15.0"
384
+#define SQLITE_VERSION_NUMBER 3015000
385
+#define SQLITE_SOURCE_ID "2016-08-22 20:10:01 7839519349c7371cdb4e16a215eacd27004cbc62"
386386
387387
/*
388388
** CAPI3REF: Run-Time Library Version Numbers
389389
** KEYWORDS: sqlite3_version, sqlite3_sourceid
390390
**
@@ -2227,12 +2227,22 @@
22272227
** is written 0 or 1 to indicate whether [sqlite3_load_extension()] interface
22282228
** is disabled or enabled following this call. The second parameter may
22292229
** be a NULL pointer, in which case the new setting is not reported back.
22302230
** </dd>
22312231
**
2232
+** <dt>SQLITE_DBCONFIG_MAINDBNAME</dt>
2233
+** <dd> ^This option is used to change the name of the "main" database
2234
+** schema. ^The sole argument is a pointer to a constant UTF8 string
2235
+** which will become the new schema name in place of "main". ^SQLite
2236
+** does not make a copy of the new main schema name string, so the application
2237
+** must ensure that the argument passed into this DBCONFIG option is unchanged
2238
+** until after the database connection closes.
2239
+** </dd>
2240
+**
22322241
** </dl>
22332242
*/
2243
+#define SQLITE_DBCONFIG_MAINDBNAME 1000 /* const char* */
22342244
#define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
22352245
#define SQLITE_DBCONFIG_ENABLE_FKEY 1002 /* int int* */
22362246
#define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */
22372247
#define SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1004 /* int int* */
22382248
#define SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION 1005 /* int int* */
@@ -13694,11 +13704,11 @@
1369413704
** in the sqlite.aDb[] array. aDb[0] is the main database file and
1369513705
** aDb[1] is the database file used to hold temporary tables. Additional
1369613706
** databases may be attached.
1369713707
*/
1369813708
struct Db {
13699
- char *zName; /* Name of this database */
13709
+ char *zDbSName; /* Name of this database. (schema name, not filename) */
1370013710
Btree *pBt; /* The B*Tree structure for this database file */
1370113711
u8 safety_level; /* How aggressive at syncing data to disk */
1370213712
u8 bSyncSet; /* True if "PRAGMA synchronous=N" has been run */
1370313713
Schema *pSchema; /* Pointer to database schema (possibly shared) */
1370413714
};
@@ -16298,12 +16308,12 @@
1629816308
SQLITE_PRIVATE Table *sqlite3LocateTable(Parse*,u32 flags,const char*, const char*);
1629916309
SQLITE_PRIVATE Table *sqlite3LocateTableItem(Parse*,u32 flags,struct SrcList_item *);
1630016310
SQLITE_PRIVATE Index *sqlite3FindIndex(sqlite3*,const char*, const char*);
1630116311
SQLITE_PRIVATE void sqlite3UnlinkAndDeleteTable(sqlite3*,int,const char*);
1630216312
SQLITE_PRIVATE void sqlite3UnlinkAndDeleteIndex(sqlite3*,int,const char*);
16303
-SQLITE_PRIVATE void sqlite3Vacuum(Parse*);
16304
-SQLITE_PRIVATE int sqlite3RunVacuum(char**, sqlite3*);
16313
+SQLITE_PRIVATE void sqlite3Vacuum(Parse*,Token*);
16314
+SQLITE_PRIVATE int sqlite3RunVacuum(char**, sqlite3*, int);
1630516315
SQLITE_PRIVATE char *sqlite3NameFromToken(sqlite3*, Token*);
1630616316
SQLITE_PRIVATE int sqlite3ExprCompare(Expr*, Expr*, int);
1630716317
SQLITE_PRIVATE int sqlite3ExprListCompare(ExprList*, ExprList*, int);
1630816318
SQLITE_PRIVATE int sqlite3ExprImpliesExpr(Expr*, Expr*, int);
1630916319
SQLITE_PRIVATE void sqlite3ExprAnalyzeAggregates(NameContext*, Expr*);
@@ -34851,10 +34861,31 @@
3485134861
unixLeaveMutex();
3485234862
}
3485334863
#endif /* if !OS_VXWORKS */
3485434864
return pUnused;
3485534865
}
34866
+
34867
+/*
34868
+** Find the mode, uid and gid of file zFile.
34869
+*/
34870
+static int getFileMode(
34871
+ const char *zFile, /* File name */
34872
+ mode_t *pMode, /* OUT: Permissions of zFile */
34873
+ uid_t *pUid, /* OUT: uid of zFile. */
34874
+ gid_t *pGid /* OUT: gid of zFile. */
34875
+){
34876
+ struct stat sStat; /* Output of stat() on database file */
34877
+ int rc = SQLITE_OK;
34878
+ if( 0==osStat(zFile, &sStat) ){
34879
+ *pMode = sStat.st_mode & 0777;
34880
+ *pUid = sStat.st_uid;
34881
+ *pGid = sStat.st_gid;
34882
+ }else{
34883
+ rc = SQLITE_IOERR_FSTAT;
34884
+ }
34885
+ return rc;
34886
+}
3485634887
3485734888
/*
3485834889
** This function is called by unixOpen() to determine the unix permissions
3485934890
** to create new files with. If no error occurs, then SQLITE_OK is returned
3486034891
** and a value suitable for passing as the third argument to open(2) is
@@ -34887,11 +34918,10 @@
3488734918
*pUid = 0;
3488834919
*pGid = 0;
3488934920
if( flags & (SQLITE_OPEN_WAL|SQLITE_OPEN_MAIN_JOURNAL) ){
3489034921
char zDb[MAX_PATHNAME+1]; /* Database file path */
3489134922
int nDb; /* Number of valid bytes in zDb */
34892
- struct stat sStat; /* Output of stat() on database file */
3489334923
3489434924
/* zPath is a path to a WAL or journal file. The following block derives
3489534925
** the path to the associated database file from zPath. This block handles
3489634926
** the following naming conventions:
3489734927
**
@@ -34918,19 +34948,22 @@
3491834948
nDb--;
3491934949
}
3492034950
memcpy(zDb, zPath, nDb);
3492134951
zDb[nDb] = '\0';
3492234952
34923
- if( 0==osStat(zDb, &sStat) ){
34924
- *pMode = sStat.st_mode & 0777;
34925
- *pUid = sStat.st_uid;
34926
- *pGid = sStat.st_gid;
34927
- }else{
34928
- rc = SQLITE_IOERR_FSTAT;
34929
- }
34953
+ rc = getFileMode(zDb, pMode, pUid, pGid);
3493034954
}else if( flags & SQLITE_OPEN_DELETEONCLOSE ){
3493134955
*pMode = 0600;
34956
+ }else if( flags & SQLITE_OPEN_URI ){
34957
+ /* If this is a main database file and the file was opened using a URI
34958
+ ** filename, check for the "modeof" parameter. If present, interpret
34959
+ ** its value as a filename and try to copy the mode, uid and gid from
34960
+ ** that file. */
34961
+ const char *z = sqlite3_uri_parameter(zPath, "modeof");
34962
+ if( z ){
34963
+ rc = getFileMode(z, pMode, pUid, pGid);
34964
+ }
3493234965
}
3493334966
return rc;
3493434967
}
3493534968
3493634969
/*
@@ -75441,11 +75474,11 @@
7544175474
int nEntry;
7544275475
sqlite3BtreeEnter(pBt);
7544375476
nEntry = sqlite3PagerWalCallback(sqlite3BtreePager(pBt));
7544475477
sqlite3BtreeLeave(pBt);
7544575478
if( db->xWalCallback && nEntry>0 && rc==SQLITE_OK ){
75446
- rc = db->xWalCallback(db->pWalArg, db, db->aDb[i].zName, nEntry);
75479
+ rc = db->xWalCallback(db->pWalArg, db, db->aDb[i].zDbSName, nEntry);
7544775480
}
7544875481
}
7544975482
}
7545075483
#endif
7545175484
return rc;
@@ -81472,11 +81505,11 @@
8147281505
}
8147381506
8147481507
if( pOp->p4type==P4_TABLE && HAS_UPDATE_HOOK(db) ){
8147581508
assert( pC->isTable );
8147681509
assert( pC->iDb>=0 );
81477
- zDb = db->aDb[pC->iDb].zName;
81510
+ zDb = db->aDb[pC->iDb].zDbSName;
8147881511
pTab = pOp->p4.pTab;
8147981512
assert( HasRowid(pTab) );
8148081513
op = ((pOp->p5 & OPFLAG_ISUPDATE) ? SQLITE_UPDATE : SQLITE_INSERT);
8148181514
}else{
8148281515
pTab = 0; /* Not needed. Silence a comiler warning. */
@@ -81589,11 +81622,11 @@
8158981622
** last moved with OP_Next or OP_Prev, not Seek or NotFound, set
8159081623
** VdbeCursor.movetoTarget to the current rowid. */
8159181624
if( pOp->p4type==P4_TABLE && HAS_UPDATE_HOOK(db) ){
8159281625
assert( pC->iDb>=0 );
8159381626
assert( pOp->p4.pTab!=0 );
81594
- zDb = db->aDb[pC->iDb].zName;
81627
+ zDb = db->aDb[pC->iDb].zDbSName;
8159581628
pTab = pOp->p4.pTab;
8159681629
if( (pOp->p5 & OPFLAG_SAVEPOSITION)!=0 && pC->isTable ){
8159781630
pC->movetoTarget = sqlite3BtreeIntegerKey(pC->uc.pCursor);
8159881631
}
8159981632
}else{
@@ -82559,11 +82592,11 @@
8255982592
initData.db = db;
8256082593
initData.iDb = pOp->p1;
8256182594
initData.pzErrMsg = &p->zErrMsg;
8256282595
zSql = sqlite3MPrintf(db,
8256382596
"SELECT name, rootpage, sql FROM '%q'.%s WHERE %s ORDER BY rowid",
82564
- db->aDb[iDb].zName, zMaster, pOp->p4.z);
82597
+ db->aDb[iDb].zDbSName, zMaster, pOp->p4.z);
8256582598
if( zSql==0 ){
8256682599
rc = SQLITE_NOMEM_BKPT;
8256782600
}else{
8256882601
assert( db->init.busy==0 );
8256982602
db->init.busy = 1;
@@ -83388,19 +83421,18 @@
8338883421
break;
8338983422
};
8339083423
#endif /* SQLITE_OMIT_PRAGMA */
8339183424
8339283425
#if !defined(SQLITE_OMIT_VACUUM) && !defined(SQLITE_OMIT_ATTACH)
83393
-/* Opcode: Vacuum * * * * *
83426
+/* Opcode: Vacuum P1 * * * *
8339483427
**
83395
-** Vacuum the entire database. This opcode will cause other virtual
83396
-** machines to be created and run. It may not be called from within
83397
-** a transaction.
83428
+** Vacuum the entire database P1. P1 is 0 for "main", and 2 or more
83429
+** for an attached database. The "temp" database may not be vacuumed.
8339883430
*/
8339983431
case OP_Vacuum: {
8340083432
assert( p->readOnly==0 );
83401
- rc = sqlite3RunVacuum(&p->zErrMsg, db);
83433
+ rc = sqlite3RunVacuum(&p->zErrMsg, db, pOp->p1);
8340283434
if( rc ) goto abort_due_to_error;
8340383435
break;
8340483436
}
8340583437
#endif
8340683438
@@ -83943,11 +83975,11 @@
8394383975
zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql);
8394483976
if( zTrace ){
8394583977
int i;
8394683978
for(i=0; i<db->nDb; i++){
8394783979
if( DbMaskTest(p->btreeMask, i)==0 ) continue;
83948
- sqlite3_file_control(db, db->aDb[i].zName, SQLITE_FCNTL_TRACE, zTrace);
83980
+ sqlite3_file_control(db, db->aDb[i].zDbSName, SQLITE_FCNTL_TRACE, zTrace);
8394983981
}
8395083982
}
8395183983
#endif /* SQLITE_USE_FCNTL_TRACE */
8395283984
#ifdef SQLITE_DEBUG
8395383985
if( (db->flags & SQLITE_SqlTrace)!=0
@@ -84279,11 +84311,11 @@
8427984311
rc = SQLITE_ERROR;
8428084312
sqlite3BtreeLeaveAll(db);
8428184313
goto blob_open_out;
8428284314
}
8428384315
pBlob->pTab = pTab;
84284
- pBlob->zDb = db->aDb[sqlite3SchemaToIndex(db, pTab->pSchema)].zName;
84316
+ pBlob->zDb = db->aDb[sqlite3SchemaToIndex(db, pTab->pSchema)].zDbSName;
8428584317
8428684318
/* Now search pTab for the exact column. */
8428784319
for(iCol=0; iCol<pTab->nCol; iCol++) {
8428884320
if( sqlite3StrICmp(pTab->aCol[iCol].zName, zColumn)==0 ){
8428984321
break;
@@ -87831,21 +87863,19 @@
8783187863
static SQLITE_NOINLINE int walkExpr(Walker *pWalker, Expr *pExpr){
8783287864
int rc;
8783387865
testcase( ExprHasProperty(pExpr, EP_TokenOnly) );
8783487866
testcase( ExprHasProperty(pExpr, EP_Reduced) );
8783587867
rc = pWalker->xExprCallback(pWalker, pExpr);
87836
- if( rc==WRC_Continue
87837
- && !ExprHasProperty(pExpr,EP_TokenOnly) ){
87838
- if( sqlite3WalkExpr(pWalker, pExpr->pLeft) ) return WRC_Abort;
87839
- if( sqlite3WalkExpr(pWalker, pExpr->pRight) ) return WRC_Abort;
87840
- if( ExprHasProperty(pExpr, EP_xIsSelect) ){
87841
- if( sqlite3WalkSelect(pWalker, pExpr->x.pSelect) ) return WRC_Abort;
87842
- }else{
87843
- if( sqlite3WalkExprList(pWalker, pExpr->x.pList) ) return WRC_Abort;
87844
- }
87845
- }
87846
- return rc & WRC_Abort;
87868
+ if( rc || ExprHasProperty(pExpr,EP_TokenOnly) ) return rc & WRC_Abort;
87869
+ if( pExpr->pLeft && walkExpr(pWalker, pExpr->pLeft) ) return WRC_Abort;
87870
+ if( pExpr->pRight && walkExpr(pWalker, pExpr->pRight) ) return WRC_Abort;
87871
+ if( ExprHasProperty(pExpr, EP_xIsSelect) ){
87872
+ if( sqlite3WalkSelect(pWalker, pExpr->x.pSelect) ) return WRC_Abort;
87873
+ }else{
87874
+ if( sqlite3WalkExprList(pWalker, pExpr->x.pList) ) return WRC_Abort;
87875
+ }
87876
+ return WRC_Continue;
8784787877
}
8784887878
SQLITE_PRIVATE int sqlite3WalkExpr(Walker *pWalker, Expr *pExpr){
8784987879
return pExpr ? walkExpr(pWalker,pExpr) : WRC_Continue;
8785087880
}
8785187881
@@ -88175,12 +88205,12 @@
8817588205
** legacy and because it does not hurt anything to just ignore the
8817688206
** database name. */
8817788207
zDb = 0;
8817888208
}else{
8817988209
for(i=0; i<db->nDb; i++){
88180
- assert( db->aDb[i].zName );
88181
- if( sqlite3StrICmp(db->aDb[i].zName,zDb)==0 ){
88210
+ assert( db->aDb[i].zDbSName );
88211
+ if( sqlite3StrICmp(db->aDb[i].zDbSName,zDb)==0 ){
8818288212
pSchema = db->aDb[i].pSchema;
8818388213
break;
8818488214
}
8818588215
}
8818688216
}
@@ -94249,11 +94279,11 @@
9424994279
assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );
9425094280
9425194281
pTab = sqlite3LocateTableItem(pParse, 0, &pSrc->a[0]);
9425294282
if( !pTab ) goto exit_rename_table;
9425394283
iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
94254
- zDb = db->aDb[iDb].zName;
94284
+ zDb = db->aDb[iDb].zDbSName;
9425594285
db->flags |= SQLITE_PreferBuiltin;
9425694286
9425794287
/* Get a NULL terminated version of the new table name. */
9425894288
zName = sqlite3NameFromToken(db, pName);
9425994289
if( !zName ) goto exit_rename_table;
@@ -94447,11 +94477,11 @@
9444794477
pNew = pParse->pNewTable;
9444894478
assert( pNew );
9444994479
9445094480
assert( sqlite3BtreeHoldsAllMutexes(db) );
9445194481
iDb = sqlite3SchemaToIndex(db, pNew->pSchema);
94452
- zDb = db->aDb[iDb].zName;
94482
+ zDb = db->aDb[iDb].zDbSName;
9445394483
zTab = &pNew->zName[16]; /* Skip the "sqlite_altertab_" prefix on the name */
9445494484
pCol = &pNew->aCol[pNew->nCol-1];
9445594485
pDflt = pCol->pDflt;
9445694486
pTab = sqlite3FindTable(db, zTab, zDb);
9445794487
assert( pTab );
@@ -94857,18 +94887,18 @@
9485794887
** if they do already exist.
9485894888
*/
9485994889
for(i=0; i<ArraySize(aTable); i++){
9486094890
const char *zTab = aTable[i].zName;
9486194891
Table *pStat;
94862
- if( (pStat = sqlite3FindTable(db, zTab, pDb->zName))==0 ){
94892
+ if( (pStat = sqlite3FindTable(db, zTab, pDb->zDbSName))==0 ){
9486394893
if( aTable[i].zCols ){
9486494894
/* The sqlite_statN table does not exist. Create it. Note that a
9486594895
** side-effect of the CREATE TABLE statement is to leave the rootpage
9486694896
** of the new table in register pParse->regRoot. This is important
9486794897
** because the OpenWrite opcode below will be needing it. */
9486894898
sqlite3NestedParse(pParse,
94869
- "CREATE TABLE %Q.%s(%s)", pDb->zName, zTab, aTable[i].zCols
94899
+ "CREATE TABLE %Q.%s(%s)", pDb->zDbSName, zTab, aTable[i].zCols
9487094900
);
9487194901
aRoot[i] = pParse->regRoot;
9487294902
aCreateTbl[i] = OPFLAG_P2ISREG;
9487394903
}
9487494904
}else{
@@ -94879,11 +94909,11 @@
9487994909
aCreateTbl[i] = 0;
9488094910
sqlite3TableLock(pParse, iDb, aRoot[i], 1, zTab);
9488194911
if( zWhere ){
9488294912
sqlite3NestedParse(pParse,
9488394913
"DELETE FROM %Q.%s WHERE %s=%Q",
94884
- pDb->zName, zTab, zWhereType, zWhere
94914
+ pDb->zDbSName, zTab, zWhereType, zWhere
9488594915
);
9488694916
}else{
9488794917
/* The sqlite_stat[134] table already exists. Delete all rows. */
9488894918
sqlite3VdbeAddOp2(v, OP_Clear, aRoot[i], iDb);
9488994919
}
@@ -95641,11 +95671,11 @@
9564195671
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
9564295672
assert( iDb>=0 );
9564395673
assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
9564495674
#ifndef SQLITE_OMIT_AUTHORIZATION
9564595675
if( sqlite3AuthCheck(pParse, SQLITE_ANALYZE, pTab->zName, 0,
95646
- db->aDb[iDb].zName ) ){
95676
+ db->aDb[iDb].zDbSName ) ){
9564795677
return;
9564895678
}
9564995679
#endif
9565095680
9565195681
/* Establish a read-lock on the table at the shared-cache level.
@@ -96031,11 +96061,11 @@
9603196061
}
9603296062
}else{
9603396063
/* Form 3: Analyze the fully qualified table name */
9603496064
iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pTableName);
9603596065
if( iDb>=0 ){
96036
- zDb = db->aDb[iDb].zName;
96066
+ zDb = db->aDb[iDb].zDbSName;
9603796067
z = sqlite3NameFromToken(db, pTableName);
9603896068
if( z ){
9603996069
if( (pIdx = sqlite3FindIndex(db, z, zDb))!=0 ){
9604096070
analyzeTable(pParse, pIdx->pTable, pIdx);
9604196071
}else if( (pTab = sqlite3LocateTable(pParse, 0, z, zDb))!=0 ){
@@ -96491,11 +96521,11 @@
9649196521
#endif
9649296522
}
9649396523
9649496524
/* Load new statistics out of the sqlite_stat1 table */
9649596525
sInfo.db = db;
96496
- sInfo.zDatabase = db->aDb[iDb].zName;
96526
+ sInfo.zDatabase = db->aDb[iDb].zDbSName;
9649796527
if( sqlite3FindTable(db, "sqlite_stat1", sInfo.zDatabase)!=0 ){
9649896528
zSql = sqlite3MPrintf(db,
9649996529
"SELECT tbl,idx,stat FROM %Q.sqlite_stat1", sInfo.zDatabase);
9650096530
if( zSql==0 ){
9650196531
rc = SQLITE_NOMEM_BKPT;
@@ -96634,11 +96664,11 @@
9663496664
if( !db->autoCommit ){
9663596665
zErrDyn = sqlite3MPrintf(db, "cannot ATTACH database within transaction");
9663696666
goto attach_error;
9663796667
}
9663896668
for(i=0; i<db->nDb; i++){
96639
- char *z = db->aDb[i].zName;
96669
+ char *z = db->aDb[i].zDbSName;
9664096670
assert( z && zName );
9664196671
if( sqlite3StrICmp(z, zName)==0 ){
9664296672
zErrDyn = sqlite3MPrintf(db, "database %s is already in use", zName);
9664396673
goto attach_error;
9664496674
}
@@ -96699,12 +96729,12 @@
9669996729
PAGER_SYNCHRONOUS_FULL | (db->flags & PAGER_FLAGS_MASK));
9670096730
#endif
9670196731
sqlite3BtreeLeave(aNew->pBt);
9670296732
}
9670396733
aNew->safety_level = SQLITE_DEFAULT_SYNCHRONOUS+1;
96704
- aNew->zName = sqlite3DbStrDup(db, zName);
96705
- if( rc==SQLITE_OK && aNew->zName==0 ){
96734
+ aNew->zDbSName = sqlite3DbStrDup(db, zName);
96735
+ if( rc==SQLITE_OK && aNew->zDbSName==0 ){
9670696736
rc = SQLITE_NOMEM_BKPT;
9670796737
}
9670896738
9670996739
9671096740
#ifdef SQLITE_HAS_CODEC
@@ -96812,11 +96842,11 @@
9681296842
9681396843
if( zName==0 ) zName = "";
9681496844
for(i=0; i<db->nDb; i++){
9681596845
pDb = &db->aDb[i];
9681696846
if( pDb->pBt==0 ) continue;
96817
- if( sqlite3StrICmp(pDb->zName, zName)==0 ) break;
96847
+ if( sqlite3StrICmp(pDb->zDbSName, zName)==0 ) break;
9681896848
}
9681996849
9682096850
if( i>=db->nDb ){
9682196851
sqlite3_snprintf(sizeof(zErr),zErr, "no such database: %s", zName);
9682296852
goto detach_error;
@@ -96970,11 +97000,11 @@
9697097000
sqlite3 *db;
9697197001
9697297002
db = pParse->db;
9697397003
assert( db->nDb>iDb );
9697497004
pFix->pParse = pParse;
96975
- pFix->zDb = db->aDb[iDb].zName;
97005
+ pFix->zDb = db->aDb[iDb].zDbSName;
9697697006
pFix->pSchema = db->aDb[iDb].pSchema;
9697797007
pFix->zType = zType;
9697897008
pFix->pName = pName;
9697997009
pFix->bVarOnly = (iDb==1);
9698097010
}
@@ -97228,13 +97258,13 @@
9722897258
Parse *pParse, /* The parser context */
9722997259
const char *zTab, /* Table name */
9723097260
const char *zCol, /* Column name */
9723197261
int iDb /* Index of containing database. */
9723297262
){
97233
- sqlite3 *db = pParse->db; /* Database handle */
97234
- char *zDb = db->aDb[iDb].zName; /* Name of attached database */
97235
- int rc; /* Auth callback return code */
97263
+ sqlite3 *db = pParse->db; /* Database handle */
97264
+ char *zDb = db->aDb[iDb].zDbSName; /* Schema name of attached database */
97265
+ int rc; /* Auth callback return code */
9723697266
9723797267
if( db->init.busy ) return SQLITE_OK;
9723897268
rc = db->xAuth(db->pAuthArg, SQLITE_READ, zTab,zCol,zDb,pParse->zAuthContext
9723997269
#ifdef SQLITE_USER_AUTHENTICATION
9724097270
,db->auth.zAuthUser
@@ -97703,14 +97733,15 @@
9770397733
return 0;
9770497734
}
9770597735
#endif
9770697736
for(i=OMIT_TEMPDB; i<db->nDb; i++){
9770797737
int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */
97708
- if( zDatabase!=0 && sqlite3StrICmp(zDatabase, db->aDb[j].zName) ) continue;
97709
- assert( sqlite3SchemaMutexHeld(db, j, 0) );
97710
- p = sqlite3HashFind(&db->aDb[j].pSchema->tblHash, zName);
97711
- if( p ) break;
97738
+ if( zDatabase==0 || sqlite3StrICmp(zDatabase, db->aDb[j].zDbSName)==0 ){
97739
+ assert( sqlite3SchemaMutexHeld(db, j, 0) );
97740
+ p = sqlite3HashFind(&db->aDb[j].pSchema->tblHash, zName);
97741
+ if( p ) break;
97742
+ }
9771297743
}
9771397744
return p;
9771497745
}
9771597746
9771697747
/*
@@ -97780,11 +97811,11 @@
9778097811
){
9778197812
const char *zDb;
9778297813
assert( p->pSchema==0 || p->zDatabase==0 );
9778397814
if( p->pSchema ){
9778497815
int iDb = sqlite3SchemaToIndex(pParse->db, p->pSchema);
97785
- zDb = pParse->db->aDb[iDb].zName;
97816
+ zDb = pParse->db->aDb[iDb].zDbSName;
9778697817
}else{
9778797818
zDb = p->zDatabase;
9778897819
}
9778997820
return sqlite3LocateTable(pParse, flags, p->zName, zDb);
9779097821
}
@@ -97808,11 +97839,11 @@
9780897839
assert( zDb!=0 || sqlite3BtreeHoldsAllMutexes(db) );
9780997840
for(i=OMIT_TEMPDB; i<db->nDb; i++){
9781097841
int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */
9781197842
Schema *pSchema = db->aDb[j].pSchema;
9781297843
assert( pSchema );
97813
- if( zDb && sqlite3StrICmp(zDb, db->aDb[j].zName) ) continue;
97844
+ if( zDb && sqlite3StrICmp(zDb, db->aDb[j].zDbSName) ) continue;
9781497845
assert( sqlite3SchemaMutexHeld(db, j, 0) );
9781597846
p = sqlite3HashFind(&pSchema->idxHash, zName);
9781697847
if( p ) break;
9781797848
}
9781897849
return p;
@@ -97877,12 +97908,12 @@
9787797908
SQLITE_PRIVATE void sqlite3CollapseDatabaseArray(sqlite3 *db){
9787897909
int i, j;
9787997910
for(i=j=2; i<db->nDb; i++){
9788097911
struct Db *pDb = &db->aDb[i];
9788197912
if( pDb->pBt==0 ){
97882
- sqlite3DbFree(db, pDb->zName);
97883
- pDb->zName = 0;
97913
+ sqlite3DbFree(db, pDb->zDbSName);
97914
+ pDb->zDbSName = 0;
9788497915
continue;
9788597916
}
9788697917
if( j<i ){
9788797918
db->aDb[j] = db->aDb[i];
9788897919
}
@@ -98098,11 +98129,11 @@
9809898129
SQLITE_PRIVATE int sqlite3FindDbName(sqlite3 *db, const char *zName){
9809998130
int i = -1; /* Database number */
9810098131
if( zName ){
9810198132
Db *pDb;
9810298133
for(i=(db->nDb-1), pDb=&db->aDb[i]; i>=0; i--, pDb--){
98103
- if( 0==sqlite3StrICmp(pDb->zName, zName) ) break;
98134
+ if( 0==sqlite3StrICmp(pDb->zDbSName, zName) ) break;
9810498135
}
9810598136
}
9810698137
return i;
9810798138
}
9810898139
@@ -98157,11 +98188,11 @@
9815798188
if( iDb<0 ){
9815898189
sqlite3ErrorMsg(pParse, "unknown database %T", pName1);
9815998190
return -1;
9816098191
}
9816198192
}else{
98162
- assert( db->init.iDb==0 || db->init.busy );
98193
+ assert( db->init.iDb==0 || db->init.busy || (db->flags & SQLITE_Vacuum)!=0);
9816398194
iDb = db->init.iDb;
9816498195
*pUnqual = pName1;
9816598196
}
9816698197
return iDb;
9816798198
}
@@ -98268,11 +98299,11 @@
9826898299
SQLITE_CREATE_TABLE,
9826998300
SQLITE_CREATE_TEMP_TABLE,
9827098301
SQLITE_CREATE_VIEW,
9827198302
SQLITE_CREATE_TEMP_VIEW
9827298303
};
98273
- char *zDb = db->aDb[iDb].zName;
98304
+ char *zDb = db->aDb[iDb].zDbSName;
9827498305
if( sqlite3AuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(isTemp), 0, zDb) ){
9827598306
goto begin_table_error;
9827698307
}
9827798308
if( !isVirtual && sqlite3AuthCheck(pParse, (int)aCode[isTemp+2*isView],
9827898309
zName, 0, zDb) ){
@@ -98287,11 +98318,11 @@
9828798318
** to an sqlite3_declare_vtab() call. In that case only the column names
9828898319
** and types will be used, so there is no need to test for namespace
9828998320
** collisions.
9829098321
*/
9829198322
if( !IN_DECLARE_VTAB ){
98292
- char *zDb = db->aDb[iDb].zName;
98323
+ char *zDb = db->aDb[iDb].zDbSName;
9829398324
if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){
9829498325
goto begin_table_error;
9829598326
}
9829698327
pTable = sqlite3FindTable(db, zName, zDb);
9829798328
if( pTable ){
@@ -99380,11 +99411,11 @@
9938099411
*/
9938199412
sqlite3NestedParse(pParse,
9938299413
"UPDATE %Q.%s "
9938399414
"SET type='%s', name=%Q, tbl_name=%Q, rootpage=#%d, sql=%Q "
9938499415
"WHERE rowid=#%d",
99385
- db->aDb[iDb].zName, SCHEMA_TABLE(iDb),
99416
+ db->aDb[iDb].zDbSName, SCHEMA_TABLE(iDb),
9938699417
zType,
9938799418
p->zName,
9938899419
p->zName,
9938999420
pParse->regRoot,
9939099421
zStmt,
@@ -99395,17 +99426,17 @@
9939599426
9939699427
#ifndef SQLITE_OMIT_AUTOINCREMENT
9939799428
/* Check to see if we need to create an sqlite_sequence table for
9939899429
** keeping track of autoincrement keys.
9939999430
*/
99400
- if( p->tabFlags & TF_Autoincrement ){
99431
+ if( (p->tabFlags & TF_Autoincrement)!=0 ){
9940199432
Db *pDb = &db->aDb[iDb];
9940299433
assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
9940399434
if( pDb->pSchema->pSeqTab==0 ){
9940499435
sqlite3NestedParse(pParse,
9940599436
"CREATE TABLE %Q.sqlite_sequence(name,seq)",
99406
- pDb->zName
99437
+ pDb->zDbSName
9940799438
);
9940899439
}
9940999440
}
9941099441
#endif
9941199442
@@ -99715,11 +99746,11 @@
9971599746
** is in register NNN. See grammar rules associated with the TK_REGISTER
9971699747
** token for additional information.
9971799748
*/
9971899749
sqlite3NestedParse(pParse,
9971999750
"UPDATE %Q.%s SET rootpage=%d WHERE #%d AND rootpage=#%d",
99720
- pParse->db->aDb[iDb].zName, SCHEMA_TABLE(iDb), iTable, r1, r1);
99751
+ pParse->db->aDb[iDb].zDbSName, SCHEMA_TABLE(iDb), iTable, r1, r1);
9972199752
#endif
9972299753
sqlite3ReleaseTempReg(pParse, r1);
9972399754
}
9972499755
9972599756
/*
@@ -99791,11 +99822,11 @@
9979199822
int iDb, /* The database number */
9979299823
const char *zType, /* "idx" or "tbl" */
9979399824
const char *zName /* Name of index or table */
9979499825
){
9979599826
int i;
99796
- const char *zDbName = pParse->db->aDb[iDb].zName;
99827
+ const char *zDbName = pParse->db->aDb[iDb].zDbSName;
9979799828
for(i=1; i<=4; i++){
9979899829
char zTab[24];
9979999830
sqlite3_snprintf(sizeof(zTab),zTab,"sqlite_stat%d",i);
9980099831
if( sqlite3FindTable(pParse->db, zTab, zDbName) ){
9980199832
sqlite3NestedParse(pParse,
@@ -99844,11 +99875,11 @@
9984499875
** move as a result of the drop (can happen in auto-vacuum mode).
9984599876
*/
9984699877
if( pTab->tabFlags & TF_Autoincrement ){
9984799878
sqlite3NestedParse(pParse,
9984899879
"DELETE FROM %Q.sqlite_sequence WHERE name=%Q",
99849
- pDb->zName, pTab->zName
99880
+ pDb->zDbSName, pTab->zName
9985099881
);
9985199882
}
9985299883
#endif
9985399884
9985499885
/* Drop all SQLITE_MASTER table and index entries that refer to the
@@ -99858,11 +99889,11 @@
9985899889
** created in the temp database that refers to a table in another
9985999890
** database.
9986099891
*/
9986199892
sqlite3NestedParse(pParse,
9986299893
"DELETE FROM %Q.%s WHERE tbl_name=%Q and type!='trigger'",
99863
- pDb->zName, SCHEMA_TABLE(iDb), pTab->zName);
99894
+ pDb->zDbSName, SCHEMA_TABLE(iDb), pTab->zName);
9986499895
if( !isView && !IsVirtual(pTab) ){
9986599896
destroyTable(pParse, pTab);
9986699897
}
9986799898
9986899899
/* Remove the table entry from SQLite's internal schema and modify
@@ -99912,11 +99943,11 @@
9991299943
}
9991399944
#ifndef SQLITE_OMIT_AUTHORIZATION
9991499945
{
9991599946
int code;
9991699947
const char *zTab = SCHEMA_TABLE(iDb);
99917
- const char *zDb = db->aDb[iDb].zName;
99948
+ const char *zDb = db->aDb[iDb].zDbSName;
9991899949
const char *zArg2 = 0;
9991999950
if( sqlite3AuthCheck(pParse, SQLITE_DELETE, zTab, 0, zDb)){
9992099951
goto exit_drop_table;
9992199952
}
9992299953
if( isView ){
@@ -100153,11 +100184,11 @@
100153100184
sqlite3 *db = pParse->db; /* The database connection */
100154100185
int iDb = sqlite3SchemaToIndex(db, pIndex->pSchema);
100155100186
100156100187
#ifndef SQLITE_OMIT_AUTHORIZATION
100157100188
if( sqlite3AuthCheck(pParse, SQLITE_REINDEX, pIndex->zName, 0,
100158
- db->aDb[iDb].zName ) ){
100189
+ db->aDb[iDb].zDbSName ) ){
100159100190
return;
100160100191
}
100161100192
#endif
100162100193
100163100194
/* Require a write-lock on the table to perform this operation */
@@ -100405,11 +100436,11 @@
100405100436
if( sqlite3FindTable(db, zName, 0)!=0 ){
100406100437
sqlite3ErrorMsg(pParse, "there is already a table named %s", zName);
100407100438
goto exit_create_index;
100408100439
}
100409100440
}
100410
- if( sqlite3FindIndex(db, zName, pDb->zName)!=0 ){
100441
+ if( sqlite3FindIndex(db, zName, pDb->zDbSName)!=0 ){
100411100442
if( !ifNotExist ){
100412100443
sqlite3ErrorMsg(pParse, "index %s already exists", zName);
100413100444
}else{
100414100445
assert( !db->init.busy );
100415100446
sqlite3CodeVerifySchema(pParse, iDb);
@@ -100435,11 +100466,11 @@
100435100466
100436100467
/* Check for authorization to create an index.
100437100468
*/
100438100469
#ifndef SQLITE_OMIT_AUTHORIZATION
100439100470
{
100440
- const char *zDb = pDb->zName;
100471
+ const char *zDb = pDb->zDbSName;
100441100472
if( sqlite3AuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(iDb), 0, zDb) ){
100442100473
goto exit_create_index;
100443100474
}
100444100475
i = SQLITE_CREATE_INDEX;
100445100476
if( !OMIT_TEMPDB && iDb==1 ) i = SQLITE_CREATE_TEMP_INDEX;
@@ -100750,11 +100781,11 @@
100750100781
100751100782
/* Add an entry in sqlite_master for this index
100752100783
*/
100753100784
sqlite3NestedParse(pParse,
100754100785
"INSERT INTO %Q.%s VALUES('index',%Q,%Q,#%d,%Q);",
100755
- db->aDb[iDb].zName, SCHEMA_TABLE(iDb),
100786
+ db->aDb[iDb].zDbSName, SCHEMA_TABLE(iDb),
100756100787
pIndex->zName,
100757100788
pTab->zName,
100758100789
iMem,
100759100790
zStmt
100760100791
);
@@ -100884,11 +100915,11 @@
100884100915
iDb = sqlite3SchemaToIndex(db, pIndex->pSchema);
100885100916
#ifndef SQLITE_OMIT_AUTHORIZATION
100886100917
{
100887100918
int code = SQLITE_DROP_INDEX;
100888100919
Table *pTab = pIndex->pTable;
100889
- const char *zDb = db->aDb[iDb].zName;
100920
+ const char *zDb = db->aDb[iDb].zDbSName;
100890100921
const char *zTab = SCHEMA_TABLE(iDb);
100891100922
if( sqlite3AuthCheck(pParse, SQLITE_DELETE, zTab, 0, zDb) ){
100892100923
goto exit_drop_index;
100893100924
}
100894100925
if( !OMIT_TEMPDB && iDb ) code = SQLITE_DROP_TEMP_INDEX;
@@ -100902,11 +100933,11 @@
100902100933
v = sqlite3GetVdbe(pParse);
100903100934
if( v ){
100904100935
sqlite3BeginWriteOperation(pParse, 1, iDb);
100905100936
sqlite3NestedParse(pParse,
100906100937
"DELETE FROM %Q.%s WHERE name=%Q AND type='index'",
100907
- db->aDb[iDb].zName, SCHEMA_TABLE(iDb), pIndex->zName
100938
+ db->aDb[iDb].zDbSName, SCHEMA_TABLE(iDb), pIndex->zName
100908100939
);
100909100940
sqlite3ClearStatTables(pParse, iDb, "idx", pIndex->zName);
100910100941
sqlite3ChangeCookie(pParse, iDb);
100911100942
destroyRootPage(pParse, pIndex->tnum, iDb);
100912100943
sqlite3VdbeAddOp4(v, OP_DropIndex, iDb, 0, 0, pIndex->zName, 0);
@@ -101447,11 +101478,11 @@
101447101478
SQLITE_PRIVATE void sqlite3CodeVerifyNamedSchema(Parse *pParse, const char *zDb){
101448101479
sqlite3 *db = pParse->db;
101449101480
int i;
101450101481
for(i=0; i<db->nDb; i++){
101451101482
Db *pDb = &db->aDb[i];
101452
- if( pDb->pBt && (!zDb || 0==sqlite3StrICmp(zDb, pDb->zName)) ){
101483
+ if( pDb->pBt && (!zDb || 0==sqlite3StrICmp(zDb, pDb->zDbSName)) ){
101453101484
sqlite3CodeVerifySchema(pParse, i);
101454101485
}
101455101486
}
101456101487
}
101457101488
@@ -101694,11 +101725,11 @@
101694101725
}
101695101726
iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pObjName);
101696101727
if( iDb<0 ) return;
101697101728
z = sqlite3NameFromToken(db, pObjName);
101698101729
if( z==0 ) return;
101699
- zDb = db->aDb[iDb].zName;
101730
+ zDb = db->aDb[iDb].zDbSName;
101700101731
pTab = sqlite3FindTable(db, z, zDb);
101701101732
if( pTab ){
101702101733
reindexTable(pParse, pTab, 0);
101703101734
sqlite3DbFree(db, z);
101704101735
return;
@@ -102408,11 +102439,11 @@
102408102439
pWhere = sqlite3ExprDup(db, pWhere, 0);
102409102440
pFrom = sqlite3SrcListAppend(db, 0, 0, 0);
102410102441
if( pFrom ){
102411102442
assert( pFrom->nSrc==1 );
102412102443
pFrom->a[0].zName = sqlite3DbStrDup(db, pView->zName);
102413
- pFrom->a[0].zDatabase = sqlite3DbStrDup(db, db->aDb[iDb].zName);
102444
+ pFrom->a[0].zDatabase = sqlite3DbStrDup(db, db->aDb[iDb].zDbSName);
102414102445
assert( pFrom->a[0].pOn==0 );
102415102446
assert( pFrom->a[0].pUsing==0 );
102416102447
}
102417102448
pSel = sqlite3SelectNew(pParse, 0, pFrom, pWhere, 0, 0, 0,
102418102449
SF_IncludeHidden, 0, 0);
@@ -102595,11 +102626,11 @@
102595102626
if( sqlite3IsReadOnly(pParse, pTab, (pTrigger?1:0)) ){
102596102627
goto delete_from_cleanup;
102597102628
}
102598102629
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
102599102630
assert( iDb<db->nDb );
102600
- zDb = db->aDb[iDb].zName;
102631
+ zDb = db->aDb[iDb].zDbSName;
102601102632
rcauth = sqlite3AuthCheck(pParse, SQLITE_DELETE, pTab->zName, 0, zDb);
102602102633
assert( rcauth==SQLITE_OK || rcauth==SQLITE_DENY || rcauth==SQLITE_IGNORE );
102603102634
if( rcauth==SQLITE_DENY ){
102604102635
goto delete_from_cleanup;
102605102636
}
@@ -105927,11 +105958,11 @@
105927105958
105928105959
/* If foreign-keys are disabled, this function is a no-op. */
105929105960
if( (db->flags&SQLITE_ForeignKeys)==0 ) return;
105930105961
105931105962
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
105932
- zDb = db->aDb[iDb].zName;
105963
+ zDb = db->aDb[iDb].zDbSName;
105933105964
105934105965
/* Loop through all the foreign key constraints for which pTab is the
105935105966
** child table (the table that the foreign key definition is part of). */
105936105967
for(pFKey=pTab->pFKey; pFKey; pFKey=pFKey->pNextFrom){
105937105968
Table *pTo; /* Parent table of foreign key pFKey */
@@ -106667,11 +106698,13 @@
106667106698
106668106699
#ifndef SQLITE_OMIT_AUTOINCREMENT
106669106700
/*
106670106701
** Locate or create an AutoincInfo structure associated with table pTab
106671106702
** which is in database iDb. Return the register number for the register
106672
-** that holds the maximum rowid.
106703
+** that holds the maximum rowid. Return zero if pTab is not an AUTOINCREMENT
106704
+** table. (Also return zero when doing a VACUUM since we do not want to
106705
+** update the AUTOINCREMENT counters during a VACUUM.)
106673106706
**
106674106707
** There is at most one AutoincInfo structure per table even if the
106675106708
** same table is autoincremented multiple times due to inserts within
106676106709
** triggers. A new AutoincInfo structure is created if this is the
106677106710
** first use of table pTab. On 2nd and subsequent uses, the original
@@ -106690,11 +106723,13 @@
106690106723
Parse *pParse, /* Parsing context */
106691106724
int iDb, /* Index of the database holding pTab */
106692106725
Table *pTab /* The table we are writing to */
106693106726
){
106694106727
int memId = 0; /* Register holding maximum rowid */
106695
- if( pTab->tabFlags & TF_Autoincrement ){
106728
+ if( (pTab->tabFlags & TF_Autoincrement)!=0
106729
+ && (pParse->db->flags & SQLITE_Vacuum)==0
106730
+ ){
106696106731
Parse *pToplevel = sqlite3ParseToplevel(pParse);
106697106732
AutoincInfo *pInfo;
106698106733
106699106734
pInfo = pToplevel->pAinc;
106700106735
while( pInfo && pInfo->pTab!=pTab ){ pInfo = pInfo->pNext; }
@@ -107014,11 +107049,11 @@
107014107049
goto insert_cleanup;
107015107050
}
107016107051
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
107017107052
assert( iDb<db->nDb );
107018107053
pDb = &db->aDb[iDb];
107019
- zDb = pDb->zName;
107054
+ zDb = pDb->zDbSName;
107020107055
if( sqlite3AuthCheck(pParse, SQLITE_INSERT, pTab->zName, 0, zDb) ){
107021107056
goto insert_cleanup;
107022107057
}
107023107058
withoutRowid = !HasRowid(pTab);
107024107059
@@ -110972,11 +111007,11 @@
110972111007
}else{
110973111008
zRight = sqlite3NameFromToken(db, pValue);
110974111009
}
110975111010
110976111011
assert( pId2 );
110977
- zDb = pId2->n>0 ? pDb->zName : 0;
111012
+ zDb = pId2->n>0 ? pDb->zDbSName : 0;
110978111013
if( sqlite3AuthCheck(pParse, SQLITE_PRAGMA, zLeft, zRight, zDb) ){
110979111014
goto pragma_out;
110980111015
}
110981111016
110982111017
/* Send an SQLITE_FCNTL_PRAGMA file-control to the underlying VFS
@@ -111825,14 +111860,14 @@
111825111860
int i;
111826111861
pParse->nMem = 3;
111827111862
setAllColumnNames(v, 3, azCol); assert( 3==ArraySize(azCol) );
111828111863
for(i=0; i<db->nDb; i++){
111829111864
if( db->aDb[i].pBt==0 ) continue;
111830
- assert( db->aDb[i].zName!=0 );
111865
+ assert( db->aDb[i].zDbSName!=0 );
111831111866
sqlite3VdbeMultiLoad(v, 1, "iss",
111832111867
i,
111833
- db->aDb[i].zName,
111868
+ db->aDb[i].zDbSName,
111834111869
sqlite3BtreeGetFilename(db->aDb[i].pBt));
111835111870
sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3);
111836111871
}
111837111872
}
111838111873
break;
@@ -112117,11 +112152,11 @@
112117112152
/* Do the b-tree integrity checks */
112118112153
sqlite3VdbeAddOp4(v, OP_IntegrityCk, 2, cnt, 1, (char*)aRoot,P4_INTARRAY);
112119112154
sqlite3VdbeChangeP5(v, (u8)i);
112120112155
addr = sqlite3VdbeAddOp1(v, OP_IsNull, 2); VdbeCoverage(v);
112121112156
sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0,
112122
- sqlite3MPrintf(db, "*** in database %s ***\n", db->aDb[i].zName),
112157
+ sqlite3MPrintf(db, "*** in database %s ***\n", db->aDb[i].zDbSName),
112123112158
P4_DYNAMIC);
112124112159
sqlite3VdbeAddOp3(v, OP_Move, 2, 4, 1);
112125112160
sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 2);
112126112161
sqlite3VdbeAddOp2(v, OP_ResultRow, 2, 1);
112127112162
sqlite3VdbeJumpHere(v, addr);
@@ -112556,19 +112591,19 @@
112556112591
pParse->nMem = 2;
112557112592
for(i=0; i<db->nDb; i++){
112558112593
Btree *pBt;
112559112594
const char *zState = "unknown";
112560112595
int j;
112561
- if( db->aDb[i].zName==0 ) continue;
112596
+ if( db->aDb[i].zDbSName==0 ) continue;
112562112597
pBt = db->aDb[i].pBt;
112563112598
if( pBt==0 || sqlite3BtreePager(pBt)==0 ){
112564112599
zState = "closed";
112565
- }else if( sqlite3_file_control(db, i ? db->aDb[i].zName : 0,
112600
+ }else if( sqlite3_file_control(db, i ? db->aDb[i].zDbSName : 0,
112566112601
SQLITE_FCNTL_LOCKSTATE, &j)==SQLITE_OK ){
112567112602
zState = azLockName[j];
112568112603
}
112569
- sqlite3VdbeMultiLoad(v, 1, "ss", db->aDb[i].zName, zState);
112604
+ sqlite3VdbeMultiLoad(v, 1, "ss", db->aDb[i].zDbSName, zState);
112570112605
sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 2);
112571112606
}
112572112607
break;
112573112608
}
112574112609
#endif
@@ -112700,10 +112735,11 @@
112700112735
** But because db->init.busy is set to 1, no VDBE code is generated
112701112736
** or executed. All the parser does is build the internal data
112702112737
** structures that describe the table, index, or view.
112703112738
*/
112704112739
int rc;
112740
+ u8 saved_iDb = db->init.iDb;
112705112741
sqlite3_stmt *pStmt;
112706112742
TESTONLY(int rcp); /* Return code from sqlite3_prepare() */
112707112743
112708112744
assert( db->init.busy );
112709112745
db->init.iDb = iDb;
@@ -112710,11 +112746,12 @@
112710112746
db->init.newTnum = sqlite3Atoi(argv[1]);
112711112747
db->init.orphanTrigger = 0;
112712112748
TESTONLY(rcp = ) sqlite3_prepare(db, argv[2], -1, &pStmt, 0);
112713112749
rc = db->errCode;
112714112750
assert( (rc&0xFF)==(rcp&0xFF) );
112715
- db->init.iDb = 0;
112751
+ db->init.iDb = saved_iDb;
112752
+ assert( saved_iDb==0 || (db->flags & SQLITE_Vacuum)!=0 );
112716112753
if( SQLITE_OK!=rc ){
112717112754
if( db->init.orphanTrigger ){
112718112755
assert( iDb==1 );
112719112756
}else{
112720112757
pData->rc = rc;
@@ -112734,11 +112771,11 @@
112734112771
** constraint for a CREATE TABLE. The index should have already
112735112772
** been created when we processed the CREATE TABLE. All we have
112736112773
** to do here is record the root page number for that index.
112737112774
*/
112738112775
Index *pIndex;
112739
- pIndex = sqlite3FindIndex(db, argv[0], db->aDb[iDb].zName);
112776
+ pIndex = sqlite3FindIndex(db, argv[0], db->aDb[iDb].zDbSName);
112740112777
if( pIndex==0 ){
112741112778
/* This can occur if there exists an index on a TEMP table which
112742112779
** has the same name as another index on a permanent index. Since
112743112780
** the permanent table is hidden by the TEMP table, we can also
112744112781
** safely ignore the index on the permanent table.
@@ -112913,11 +112950,11 @@
112913112950
assert( db->init.busy );
112914112951
{
112915112952
char *zSql;
112916112953
zSql = sqlite3MPrintf(db,
112917112954
"SELECT name, rootpage, sql FROM \"%w\".%s ORDER BY rowid",
112918
- db->aDb[iDb].zName, zMasterName);
112955
+ db->aDb[iDb].zDbSName, zMasterName);
112919112956
#ifndef SQLITE_OMIT_AUTHORIZATION
112920112957
{
112921112958
sqlite3_xauth xAuth;
112922112959
xAuth = db->xAuth;
112923112960
db->xAuth = 0;
@@ -113188,11 +113225,11 @@
113188113225
Btree *pBt = db->aDb[i].pBt;
113189113226
if( pBt ){
113190113227
assert( sqlite3BtreeHoldsMutex(pBt) );
113191113228
rc = sqlite3BtreeSchemaLocked(pBt);
113192113229
if( rc ){
113193
- const char *zDb = db->aDb[i].zName;
113230
+ const char *zDb = db->aDb[i].zDbSName;
113194113231
sqlite3ErrorWithMsg(db, rc, "database schema is locked: %s", zDb);
113195113232
testcase( db->flags & SQLITE_ReadUncommitted );
113196113233
goto end_prepare;
113197113234
}
113198113235
}
@@ -114944,11 +114981,11 @@
114944114981
estWidth = pTab->aCol[iCol].szEst;
114945114982
}
114946114983
zOrigTab = pTab->zName;
114947114984
if( pNC->pParse ){
114948114985
int iDb = sqlite3SchemaToIndex(pNC->pParse->db, pTab->pSchema);
114949
- zOrigDb = pNC->pParse->db->aDb[iDb].zName;
114986
+ zOrigDb = pNC->pParse->db->aDb[iDb].zDbSName;
114950114987
}
114951114988
#else
114952114989
if( iCol<0 ){
114953114990
zType = "INTEGER";
114954114991
}else{
@@ -117900,11 +117937,11 @@
117900117937
pSub = 0;
117901117938
if( zTName && sqlite3StrICmp(zTName, zTabName)!=0 ){
117902117939
continue;
117903117940
}
117904117941
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
117905
- zSchemaName = iDb>=0 ? db->aDb[iDb].zName : "*";
117942
+ zSchemaName = iDb>=0 ? db->aDb[iDb].zDbSName : "*";
117906117943
}
117907117944
for(j=0; j<pTab->nCol; j++){
117908117945
char *zName = pTab->aCol[j].zName;
117909117946
char *zColname; /* The computed column name */
117910117947
char *zToFree; /* Malloced string that needs to be freed */
@@ -119612,12 +119649,12 @@
119612119649
iTabDb = sqlite3SchemaToIndex(db, pTab->pSchema);
119613119650
119614119651
#ifndef SQLITE_OMIT_AUTHORIZATION
119615119652
{
119616119653
int code = SQLITE_CREATE_TRIGGER;
119617
- const char *zDb = db->aDb[iTabDb].zName;
119618
- const char *zDbTrig = isTemp ? db->aDb[1].zName : zDb;
119654
+ const char *zDb = db->aDb[iTabDb].zDbSName;
119655
+ const char *zDbTrig = isTemp ? db->aDb[1].zDbSName : zDb;
119619119656
if( iTabDb==1 || isTemp ) code = SQLITE_CREATE_TEMP_TRIGGER;
119620119657
if( sqlite3AuthCheck(pParse, code, zName, pTab->zName, zDbTrig) ){
119621119658
goto trigger_cleanup;
119622119659
}
119623119660
if( sqlite3AuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(iTabDb),0,zDb)){
@@ -119707,11 +119744,11 @@
119707119744
if( v==0 ) goto triggerfinish_cleanup;
119708119745
sqlite3BeginWriteOperation(pParse, 0, iDb);
119709119746
z = sqlite3DbStrNDup(db, (char*)pAll->z, pAll->n);
119710119747
sqlite3NestedParse(pParse,
119711119748
"INSERT INTO %Q.%s VALUES('trigger',%Q,%Q,0,'CREATE TRIGGER %q')",
119712
- db->aDb[iDb].zName, SCHEMA_TABLE(iDb), zName,
119749
+ db->aDb[iDb].zDbSName, SCHEMA_TABLE(iDb), zName,
119713119750
pTrig->table, z);
119714119751
sqlite3DbFree(db, z);
119715119752
sqlite3ChangeCookie(pParse, iDb);
119716119753
sqlite3VdbeAddParseSchemaOp(v, iDb,
119717119754
sqlite3MPrintf(db, "type='trigger' AND name='%q'", zName));
@@ -119896,11 +119933,11 @@
119896119933
zDb = pName->a[0].zDatabase;
119897119934
zName = pName->a[0].zName;
119898119935
assert( zDb!=0 || sqlite3BtreeHoldsAllMutexes(db) );
119899119936
for(i=OMIT_TEMPDB; i<db->nDb; i++){
119900119937
int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */
119901
- if( zDb && sqlite3StrICmp(db->aDb[j].zName, zDb) ) continue;
119938
+ if( zDb && sqlite3StrICmp(db->aDb[j].zDbSName, zDb) ) continue;
119902119939
assert( sqlite3SchemaMutexHeld(db, j, 0) );
119903119940
pTrigger = sqlite3HashFind(&(db->aDb[j].pSchema->trigHash), zName);
119904119941
if( pTrigger ) break;
119905119942
}
119906119943
if( !pTrigger ){
@@ -119942,11 +119979,11 @@
119942119979
assert( pTable );
119943119980
assert( pTable->pSchema==pTrigger->pSchema || iDb==1 );
119944119981
#ifndef SQLITE_OMIT_AUTHORIZATION
119945119982
{
119946119983
int code = SQLITE_DROP_TRIGGER;
119947
- const char *zDb = db->aDb[iDb].zName;
119984
+ const char *zDb = db->aDb[iDb].zDbSName;
119948119985
const char *zTab = SCHEMA_TABLE(iDb);
119949119986
if( iDb==1 ) code = SQLITE_DROP_TEMP_TRIGGER;
119950119987
if( sqlite3AuthCheck(pParse, code, pTrigger->zName, pTable->zName, zDb) ||
119951119988
sqlite3AuthCheck(pParse, SQLITE_DELETE, zTab, 0, zDb) ){
119952119989
return;
@@ -119958,11 +119995,11 @@
119958119995
*/
119959119996
assert( pTable!=0 );
119960119997
if( (v = sqlite3GetVdbe(pParse))!=0 ){
119961119998
sqlite3NestedParse(pParse,
119962119999
"DELETE FROM %Q.%s WHERE name=%Q AND type='trigger'",
119963
- db->aDb[iDb].zName, SCHEMA_TABLE(iDb), pTrigger->zName
120000
+ db->aDb[iDb].zDbSName, SCHEMA_TABLE(iDb), pTrigger->zName
119964120001
);
119965120002
sqlite3ChangeCookie(pParse, iDb);
119966120003
sqlite3VdbeAddOp4(v, OP_DropTrigger, iDb, 0, 0, pTrigger->zName, 0);
119967120004
}
119968120005
}
@@ -120061,12 +120098,14 @@
120061120098
if( pSrc ){
120062120099
assert( pSrc->nSrc>0 );
120063120100
pSrc->a[pSrc->nSrc-1].zName = sqlite3DbStrDup(db, pStep->zTarget);
120064120101
iDb = sqlite3SchemaToIndex(db, pStep->pTrig->pSchema);
120065120102
if( iDb==0 || iDb>=2 ){
120103
+ const char *zDb;
120066120104
assert( iDb<db->nDb );
120067
- pSrc->a[pSrc->nSrc-1].zDatabase = sqlite3DbStrDup(db, db->aDb[iDb].zName);
120105
+ zDb = db->aDb[iDb].zDbSName;
120106
+ pSrc->a[pSrc->nSrc-1].zDatabase = sqlite3DbStrDup(db, zDb);
120068120107
}
120069120108
}
120070120109
return pSrc;
120071120110
}
120072120111
@@ -120749,11 +120788,11 @@
120749120788
#ifndef SQLITE_OMIT_AUTHORIZATION
120750120789
{
120751120790
int rc;
120752120791
rc = sqlite3AuthCheck(pParse, SQLITE_UPDATE, pTab->zName,
120753120792
j<0 ? "ROWID" : pTab->aCol[j].zName,
120754
- db->aDb[iDb].zName);
120793
+ db->aDb[iDb].zDbSName);
120755120794
if( rc==SQLITE_DENY ){
120756120795
goto update_cleanup;
120757120796
}else if( rc==SQLITE_IGNORE ){
120758120797
aXRef[j] = -1;
120759120798
}
@@ -121351,61 +121390,56 @@
121351121390
*/
121352121391
/* #include "sqliteInt.h" */
121353121392
/* #include "vdbeInt.h" */
121354121393
121355121394
#if !defined(SQLITE_OMIT_VACUUM) && !defined(SQLITE_OMIT_ATTACH)
121356
-/*
121357
-** Finalize a prepared statement. If there was an error, store the
121358
-** text of the error message in *pzErrMsg. Return the result code.
121359
-*/
121360
-static int vacuumFinalize(sqlite3 *db, sqlite3_stmt *pStmt, char **pzErrMsg){
121361
- int rc;
121362
- rc = sqlite3VdbeFinalize((Vdbe*)pStmt);
121363
- if( rc ){
121364
- sqlite3SetString(pzErrMsg, db, sqlite3_errmsg(db));
121365
- }
121366
- return rc;
121367
-}
121368
-
121369
-/*
121370
-** Execute zSql on database db. Return an error code.
121395
+
121396
+/*
121397
+** Execute zSql on database db.
121398
+**
121399
+** If zSql returns rows, then each row will have exactly one
121400
+** column. (This will only happen if zSql begins with "SELECT".)
121401
+** Take each row of result and call execSql() again recursively.
121402
+**
121403
+** The execSqlF() routine does the same thing, except it accepts
121404
+** a format string as its third argument
121371121405
*/
121372121406
static int execSql(sqlite3 *db, char **pzErrMsg, const char *zSql){
121373121407
sqlite3_stmt *pStmt;
121374
- VVA_ONLY( int rc; )
121375
- if( !zSql ){
121376
- return SQLITE_NOMEM_BKPT;
121408
+ int rc;
121409
+
121410
+ /* printf("SQL: [%s]\n", zSql); fflush(stdout); */
121411
+ rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
121412
+ if( rc!=SQLITE_OK ) return rc;
121413
+ while( SQLITE_ROW==(rc = sqlite3_step(pStmt)) ){
121414
+ const char *zSubSql = (const char*)sqlite3_column_text(pStmt,0);
121415
+ assert( sqlite3_strnicmp(zSql,"SELECT",6)==0 );
121416
+ if( zSubSql ){
121417
+ assert( zSubSql[0]!='S' );
121418
+ rc = execSql(db, pzErrMsg, zSubSql);
121419
+ if( rc!=SQLITE_OK ) break;
121420
+ }
121377121421
}
121378
- if( SQLITE_OK!=sqlite3_prepare(db, zSql, -1, &pStmt, 0) ){
121422
+ assert( rc!=SQLITE_ROW );
121423
+ if( rc==SQLITE_DONE ) rc = SQLITE_OK;
121424
+ if( rc ){
121379121425
sqlite3SetString(pzErrMsg, db, sqlite3_errmsg(db));
121380
- return sqlite3_errcode(db);
121381
- }
121382
- VVA_ONLY( rc = ) sqlite3_step(pStmt);
121383
- assert( rc!=SQLITE_ROW || (db->flags&SQLITE_CountRows) );
121384
- return vacuumFinalize(db, pStmt, pzErrMsg);
121385
-}
121386
-
121387
-/*
121388
-** Execute zSql on database db. The statement returns exactly
121389
-** one column. Execute this as SQL on the same database.
121390
-*/
121391
-static int execExecSql(sqlite3 *db, char **pzErrMsg, const char *zSql){
121392
- sqlite3_stmt *pStmt;
121393
- int rc;
121394
-
121395
- rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
121396
- if( rc!=SQLITE_OK ) return rc;
121397
-
121398
- while( SQLITE_ROW==sqlite3_step(pStmt) ){
121399
- rc = execSql(db, pzErrMsg, (char*)sqlite3_column_text(pStmt, 0));
121400
- if( rc!=SQLITE_OK ){
121401
- vacuumFinalize(db, pStmt, pzErrMsg);
121402
- return rc;
121403
- }
121404
- }
121405
-
121406
- return vacuumFinalize(db, pStmt, pzErrMsg);
121426
+ }
121427
+ (void)sqlite3_finalize(pStmt);
121428
+ return rc;
121429
+}
121430
+static int execSqlF(sqlite3 *db, char **pzErrMsg, const char *zSql, ...){
121431
+ char *z;
121432
+ va_list ap;
121433
+ int rc;
121434
+ va_start(ap, zSql);
121435
+ z = sqlite3VMPrintf(db, zSql, ap);
121436
+ va_end(ap);
121437
+ if( z==0 ) return SQLITE_NOMEM;
121438
+ rc = execSql(db, pzErrMsg, z);
121439
+ sqlite3DbFree(db, z);
121440
+ return rc;
121407121441
}
121408121442
121409121443
/*
121410121444
** The VACUUM command is used to clean up the database,
121411121445
** collapse free space, etc. It is modelled after the VACUUM command
@@ -121434,35 +121468,36 @@
121434121468
** not work if other processes are attached to the original database.
121435121469
** And a power loss in between deleting the original and renaming the
121436121470
** transient would cause the database file to appear to be deleted
121437121471
** following reboot.
121438121472
*/
121439
-SQLITE_PRIVATE void sqlite3Vacuum(Parse *pParse){
121473
+SQLITE_PRIVATE void sqlite3Vacuum(Parse *pParse, Token *pNm){
121440121474
Vdbe *v = sqlite3GetVdbe(pParse);
121441
- if( v ){
121442
- sqlite3VdbeAddOp2(v, OP_Vacuum, 0, 0);
121443
- sqlite3VdbeUsesBtree(v, 0);
121475
+ int iDb = pNm ? sqlite3TwoPartName(pParse, pNm, pNm, &pNm) : 0;
121476
+ if( v && (iDb>=2 || iDb==0) ){
121477
+ sqlite3VdbeAddOp1(v, OP_Vacuum, iDb);
121478
+ sqlite3VdbeUsesBtree(v, iDb);
121444121479
}
121445121480
return;
121446121481
}
121447121482
121448121483
/*
121449121484
** This routine implements the OP_Vacuum opcode of the VDBE.
121450121485
*/
121451
-SQLITE_PRIVATE int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){
121486
+SQLITE_PRIVATE int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db, int iDb){
121452121487
int rc = SQLITE_OK; /* Return code from service routines */
121453121488
Btree *pMain; /* The database being vacuumed */
121454121489
Btree *pTemp; /* The temporary database we vacuum into */
121455
- char *zSql = 0; /* SQL statements */
121456121490
int saved_flags; /* Saved value of the db->flags */
121457121491
int saved_nChange; /* Saved value of db->nChange */
121458121492
int saved_nTotalChange; /* Saved value of db->nTotalChange */
121459121493
u8 saved_mTrace; /* Saved trace settings */
121460121494
Db *pDb = 0; /* Database to detach at end of vacuum */
121461121495
int isMemDb; /* True if vacuuming a :memory: database */
121462121496
int nRes; /* Bytes of reserved space at the end of each page */
121463121497
int nDb; /* Number of attached databases */
121498
+ const char *zDbMain; /* Schema name of database to vacuum */
121464121499
121465121500
if( !db->autoCommit ){
121466121501
sqlite3SetString(pzErrMsg, db, "cannot VACUUM from within a transaction");
121467121502
return SQLITE_ERROR;
121468121503
}
@@ -121476,15 +121511,17 @@
121476121511
** disable CHECK and foreign key constraints. */
121477121512
saved_flags = db->flags;
121478121513
saved_nChange = db->nChange;
121479121514
saved_nTotalChange = db->nTotalChange;
121480121515
saved_mTrace = db->mTrace;
121481
- db->flags |= SQLITE_WriteSchema | SQLITE_IgnoreChecks | SQLITE_PreferBuiltin;
121482
- db->flags &= ~(SQLITE_ForeignKeys | SQLITE_ReverseOrder);
121516
+ db->flags |= (SQLITE_WriteSchema | SQLITE_IgnoreChecks
121517
+ | SQLITE_PreferBuiltin | SQLITE_Vacuum);
121518
+ db->flags &= ~(SQLITE_ForeignKeys | SQLITE_ReverseOrder | SQLITE_CountRows);
121483121519
db->mTrace = 0;
121484121520
121485
- pMain = db->aDb[0].pBt;
121521
+ zDbMain = db->aDb[iDb].zDbSName;
121522
+ pMain = db->aDb[iDb].pBt;
121486121523
isMemDb = sqlite3PagerIsMemdb(sqlite3BtreePager(pMain));
121487121524
121488121525
/* Attach the temporary database as 'vacuum_db'. The synchronous pragma
121489121526
** can be set to 'off' for this file, as it is not recovered if a crash
121490121527
** occurs anyway. The integrity of the database is maintained by a
@@ -121498,22 +121535,16 @@
121498121535
** empty. Only the journal header is written. Apparently it takes more
121499121536
** time to parse and run the PRAGMA to turn journalling off than it does
121500121537
** to write the journal header file.
121501121538
*/
121502121539
nDb = db->nDb;
121503
- if( sqlite3TempInMemory(db) ){
121504
- zSql = "ATTACH ':memory:' AS vacuum_db;";
121505
- }else{
121506
- zSql = "ATTACH '' AS vacuum_db;";
121507
- }
121508
- rc = execSql(db, pzErrMsg, zSql);
121509
- if( db->nDb>nDb ){
121510
- pDb = &db->aDb[db->nDb-1];
121511
- assert( strcmp(pDb->zName,"vacuum_db")==0 );
121512
- }
121540
+ rc = execSql(db, pzErrMsg, "ATTACH''AS vacuum_db");
121513121541
if( rc!=SQLITE_OK ) goto end_of_vacuum;
121514
- pTemp = db->aDb[db->nDb-1].pBt;
121542
+ assert( (db->nDb-1)==nDb );
121543
+ pDb = &db->aDb[nDb];
121544
+ assert( strcmp(pDb->zDbSName,"vacuum_db")==0 );
121545
+ pTemp = pDb->pBt;
121515121546
121516121547
/* The call to execSql() to attach the temp database has left the file
121517121548
** locked (as there was more than one active statement when the transaction
121518121549
** to read the schema was concluded. Unlock it here so that this doesn't
121519121550
** cause problems for the call to BtreeSetPageSize() below. */
@@ -121530,20 +121561,19 @@
121530121561
sqlite3CodecGetKey(db, 0, (void**)&zKey, &nKey);
121531121562
if( nKey ) db->nextPagesize = 0;
121532121563
}
121533121564
#endif
121534121565
121535
- sqlite3BtreeSetCacheSize(pTemp, db->aDb[0].pSchema->cache_size);
121566
+ sqlite3BtreeSetCacheSize(pTemp, db->aDb[iDb].pSchema->cache_size);
121536121567
sqlite3BtreeSetSpillSize(pTemp, sqlite3BtreeSetSpillSize(pMain,0));
121537
- rc = execSql(db, pzErrMsg, "PRAGMA vacuum_db.synchronous=OFF");
121538
- if( rc!=SQLITE_OK ) goto end_of_vacuum;
121568
+ sqlite3BtreeSetPagerFlags(pTemp, PAGER_SYNCHRONOUS_OFF);
121539121569
121540121570
/* Begin a transaction and take an exclusive lock on the main database
121541121571
** file. This is done before the sqlite3BtreeGetPageSize(pMain) call below,
121542121572
** to ensure that we do not try to change the page-size on a WAL database.
121543121573
*/
121544
- rc = execSql(db, pzErrMsg, "BEGIN;");
121574
+ rc = execSql(db, pzErrMsg, "BEGIN");
121545121575
if( rc!=SQLITE_OK ) goto end_of_vacuum;
121546121576
rc = sqlite3BtreeBeginTrans(pMain, 2);
121547121577
if( rc!=SQLITE_OK ) goto end_of_vacuum;
121548121578
121549121579
/* Do not attempt to change the page size for a WAL database */
@@ -121566,68 +121596,52 @@
121566121596
#endif
121567121597
121568121598
/* Query the schema of the main database. Create a mirror schema
121569121599
** in the temporary database.
121570121600
*/
121571
- rc = execExecSql(db, pzErrMsg,
121572
- "SELECT 'CREATE TABLE vacuum_db.' || substr(sql,14) "
121573
- " FROM sqlite_master WHERE type='table' AND name!='sqlite_sequence'"
121574
- " AND coalesce(rootpage,1)>0"
121601
+ db->init.iDb = nDb; /* force new CREATE statements into vacuum_db */
121602
+ rc = execSqlF(db, pzErrMsg,
121603
+ "SELECT sql FROM \"%w\".sqlite_master"
121604
+ " WHERE type='table'AND name<>'sqlite_sequence'"
121605
+ " AND coalesce(rootpage,1)>0",
121606
+ zDbMain
121607
+ );
121608
+ if( rc!=SQLITE_OK ) goto end_of_vacuum;
121609
+ rc = execSqlF(db, pzErrMsg,
121610
+ "SELECT sql FROM \"%w\".sqlite_master"
121611
+ " WHERE type='index' AND length(sql)>10",
121612
+ zDbMain
121575121613
);
121576121614
if( rc!=SQLITE_OK ) goto end_of_vacuum;
121577
- rc = execExecSql(db, pzErrMsg,
121578
- "SELECT 'CREATE INDEX vacuum_db.' || substr(sql,14)"
121579
- " FROM sqlite_master WHERE sql LIKE 'CREATE INDEX %' ");
121580
- if( rc!=SQLITE_OK ) goto end_of_vacuum;
121581
- rc = execExecSql(db, pzErrMsg,
121582
- "SELECT 'CREATE UNIQUE INDEX vacuum_db.' || substr(sql,21) "
121583
- " FROM sqlite_master WHERE sql LIKE 'CREATE UNIQUE INDEX %'");
121584
- if( rc!=SQLITE_OK ) goto end_of_vacuum;
121615
+ db->init.iDb = 0;
121585121616
121586121617
/* Loop through the tables in the main database. For each, do
121587121618
** an "INSERT INTO vacuum_db.xxx SELECT * FROM main.xxx;" to copy
121588121619
** the contents to the temporary database.
121589121620
*/
121590
- assert( (db->flags & SQLITE_Vacuum)==0 );
121591
- db->flags |= SQLITE_Vacuum;
121592
- rc = execExecSql(db, pzErrMsg,
121593
- "SELECT 'INSERT INTO vacuum_db.' || quote(name) "
121594
- "|| ' SELECT * FROM main.' || quote(name) || ';'"
121595
- "FROM main.sqlite_master "
121596
- "WHERE type = 'table' AND name!='sqlite_sequence' "
121597
- " AND coalesce(rootpage,1)>0"
121621
+ rc = execSqlF(db, pzErrMsg,
121622
+ "SELECT'INSERT INTO vacuum_db.'||quote(name)"
121623
+ "||' SELECT*FROM\"%w\".'||quote(name)"
121624
+ "FROM vacuum_db.sqlite_master "
121625
+ "WHERE type='table'AND coalesce(rootpage,1)>0",
121626
+ zDbMain
121598121627
);
121599121628
assert( (db->flags & SQLITE_Vacuum)!=0 );
121600121629
db->flags &= ~SQLITE_Vacuum;
121601121630
if( rc!=SQLITE_OK ) goto end_of_vacuum;
121602
-
121603
- /* Copy over the sequence table
121604
- */
121605
- rc = execExecSql(db, pzErrMsg,
121606
- "SELECT 'DELETE FROM vacuum_db.' || quote(name) || ';' "
121607
- "FROM vacuum_db.sqlite_master WHERE name='sqlite_sequence' "
121608
- );
121609
- if( rc!=SQLITE_OK ) goto end_of_vacuum;
121610
- rc = execExecSql(db, pzErrMsg,
121611
- "SELECT 'INSERT INTO vacuum_db.' || quote(name) "
121612
- "|| ' SELECT * FROM main.' || quote(name) || ';' "
121613
- "FROM vacuum_db.sqlite_master WHERE name=='sqlite_sequence';"
121614
- );
121615
- if( rc!=SQLITE_OK ) goto end_of_vacuum;
121616
-
121617121631
121618121632
/* Copy the triggers, views, and virtual tables from the main database
121619121633
** over to the temporary database. None of these objects has any
121620121634
** associated storage, so all we have to do is copy their entries
121621121635
** from the SQLITE_MASTER table.
121622121636
*/
121623
- rc = execSql(db, pzErrMsg,
121624
- "INSERT INTO vacuum_db.sqlite_master "
121625
- " SELECT type, name, tbl_name, rootpage, sql"
121626
- " FROM main.sqlite_master"
121627
- " WHERE type='view' OR type='trigger'"
121628
- " OR (type='table' AND rootpage=0)"
121637
+ rc = execSqlF(db, pzErrMsg,
121638
+ "INSERT INTO vacuum_db.sqlite_master"
121639
+ " SELECT*FROM \"%w\".sqlite_master"
121640
+ " WHERE type IN('view','trigger')"
121641
+ " OR(type='table'AND rootpage=0)",
121642
+ zDbMain
121629121643
);
121630121644
if( rc ) goto end_of_vacuum;
121631121645
121632121646
/* At this point, there is a write transaction open on both the
121633121647
** vacuum database and the main database. Assuming no error occurs,
@@ -121677,10 +121691,11 @@
121677121691
assert( rc==SQLITE_OK );
121678121692
rc = sqlite3BtreeSetPageSize(pMain, sqlite3BtreeGetPageSize(pTemp), nRes,1);
121679121693
121680121694
end_of_vacuum:
121681121695
/* Restore the original value of db->flags */
121696
+ db->init.iDb = 0;
121682121697
db->flags = saved_flags;
121683121698
db->nChange = saved_nChange;
121684121699
db->nTotalChange = saved_nTotalChange;
121685121700
db->mTrace = saved_mTrace;
121686121701
sqlite3BtreeSetPageSize(pMain, -1, -1, 1);
@@ -122055,11 +122070,11 @@
122055122070
** sqlite_master table, has already been made by sqlite3StartTable().
122056122071
** The second call, to obtain permission to create the table, is made now.
122057122072
*/
122058122073
if( pTable->azModuleArg ){
122059122074
sqlite3AuthCheck(pParse, SQLITE_CREATE_VTABLE, pTable->zName,
122060
- pTable->azModuleArg[0], pParse->db->aDb[iDb].zName);
122075
+ pTable->azModuleArg[0], pParse->db->aDb[iDb].zDbSName);
122061122076
}
122062122077
#endif
122063122078
}
122064122079
122065122080
/*
@@ -122119,11 +122134,11 @@
122119122134
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
122120122135
sqlite3NestedParse(pParse,
122121122136
"UPDATE %Q.%s "
122122122137
"SET type='table', name=%Q, tbl_name=%Q, rootpage=0, sql=%Q "
122123122138
"WHERE rowid=#%d",
122124
- db->aDb[iDb].zName, SCHEMA_TABLE(iDb),
122139
+ db->aDb[iDb].zDbSName, SCHEMA_TABLE(iDb),
122125122140
pTab->zName,
122126122141
pTab->zName,
122127122142
zStmt,
122128122143
pParse->regRowid
122129122144
);
@@ -122229,11 +122244,11 @@
122229122244
}
122230122245
pVTable->db = db;
122231122246
pVTable->pMod = pMod;
122232122247
122233122248
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
122234
- pTab->azModuleArg[1] = db->aDb[iDb].zName;
122249
+ pTab->azModuleArg[1] = db->aDb[iDb].zDbSName;
122235122250
122236122251
/* Invoke the virtual table constructor */
122237122252
assert( &db->pVtabCtx );
122238122253
assert( xConstruct );
122239122254
sCtx.pTab = pTab;
@@ -122393,11 +122408,11 @@
122393122408
int rc = SQLITE_OK;
122394122409
Table *pTab;
122395122410
Module *pMod;
122396122411
const char *zMod;
122397122412
122398
- pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zName);
122413
+ pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zDbSName);
122399122414
assert( pTab && (pTab->tabFlags & TF_Virtual)!=0 && !pTab->pVTable );
122400122415
122401122416
/* Locate the required virtual table module */
122402122417
zMod = pTab->azModuleArg[0];
122403122418
pMod = (Module*)sqlite3HashFind(&db->aModule, zMod);
@@ -122517,11 +122532,11 @@
122517122532
*/
122518122533
SQLITE_PRIVATE int sqlite3VtabCallDestroy(sqlite3 *db, int iDb, const char *zTab){
122519122534
int rc = SQLITE_OK;
122520122535
Table *pTab;
122521122536
122522
- pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zName);
122537
+ pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zDbSName);
122523122538
if( pTab!=0 && ALWAYS(pTab->pVTable!=0) ){
122524122539
VTable *p;
122525122540
int (*xDestroy)(sqlite3_vtab *);
122526122541
for(p=pTab->pVTable; p; p=p->pNext){
122527122542
assert( p->pVtab );
@@ -125630,11 +125645,11 @@
125630125645
*/
125631125646
static int isMatchOfColumn(
125632125647
Expr *pExpr, /* Test this expression */
125633125648
unsigned char *peOp2 /* OUT: 0 for MATCH, or else an op2 value */
125634125649
){
125635
- struct Op2 {
125650
+ static const struct Op2 {
125636125651
const char *zOp;
125637125652
unsigned char eOp2;
125638125653
} aOp[] = {
125639125654
{ "match", SQLITE_INDEX_CONSTRAINT_MATCH },
125640125655
{ "glob", SQLITE_INDEX_CONSTRAINT_GLOB },
@@ -126615,17 +126630,18 @@
126615126630
** These routines walk (recursively) an expression tree and generate
126616126631
** a bitmask indicating which tables are used in that expression
126617126632
** tree.
126618126633
*/
126619126634
SQLITE_PRIVATE Bitmask sqlite3WhereExprUsage(WhereMaskSet *pMaskSet, Expr *p){
126620
- Bitmask mask = 0;
126635
+ Bitmask mask;
126621126636
if( p==0 ) return 0;
126622126637
if( p->op==TK_COLUMN ){
126623126638
mask = sqlite3WhereGetMask(pMaskSet, p->iTable);
126624126639
return mask;
126625126640
}
126626
- mask = sqlite3WhereExprUsage(pMaskSet, p->pRight);
126641
+ assert( !ExprHasProperty(p, EP_TokenOnly) );
126642
+ mask = p->pRight ? sqlite3WhereExprUsage(pMaskSet, p->pRight) : 0;
126627126643
if( p->pLeft ) mask |= sqlite3WhereExprUsage(pMaskSet, p->pLeft);
126628126644
if( ExprHasProperty(p, EP_xIsSelect) ){
126629126645
mask |= exprSelectUsage(pMaskSet, p->x.pSelect);
126630126646
}else if( p->x.pList ){
126631126647
mask |= sqlite3WhereExprListUsage(pMaskSet, p->x.pList);
@@ -131868,29 +131884,33 @@
131868131884
** N between YY_MIN_SHIFTREDUCE Shift to an arbitrary state then
131869131885
** and YY_MAX_SHIFTREDUCE reduce by rule N-YY_MIN_SHIFTREDUCE.
131870131886
**
131871131887
** N between YY_MIN_REDUCE Reduce by rule N-YY_MIN_REDUCE
131872131888
** and YY_MAX_REDUCE
131873
-
131889
+**
131874131890
** N == YY_ERROR_ACTION A syntax error has occurred.
131875131891
**
131876131892
** N == YY_ACCEPT_ACTION The parser accepts its input.
131877131893
**
131878131894
** N == YY_NO_ACTION No such action. Denotes unused
131879131895
** slots in the yy_action[] table.
131880131896
**
131881131897
** The action table is constructed as a single large table named yy_action[].
131882
-** Given state S and lookahead X, the action is computed as
131883
-**
131884
-** yy_action[ yy_shift_ofst[S] + X ]
131885
-**
131886
-** If the index value yy_shift_ofst[S]+X is out of range or if the value
131887
-** yy_lookahead[yy_shift_ofst[S]+X] is not equal to X or if yy_shift_ofst[S]
131888
-** is equal to YY_SHIFT_USE_DFLT, it means that the action is not in the table
131889
-** and that yy_default[S] should be used instead.
131890
-**
131891
-** The formula above is for computing the action when the lookahead is
131898
+** Given state S and lookahead X, the action is computed as either:
131899
+**
131900
+** (A) N = yy_action[ yy_shift_ofst[S] + X ]
131901
+** (B) N = yy_default[S]
131902
+**
131903
+** The (A) formula is preferred. The B formula is used instead if:
131904
+** (1) The yy_shift_ofst[S]+X value is out of range, or
131905
+** (2) yy_lookahead[yy_shift_ofst[S]+X] is not equal to X, or
131906
+** (3) yy_shift_ofst[S] equal YY_SHIFT_USE_DFLT.
131907
+** (Implementation note: YY_SHIFT_USE_DFLT is chosen so that
131908
+** YY_SHIFT_USE_DFLT+X will be out of range for all possible lookaheads X.
131909
+** Hence only tests (1) and (2) need to be evaluated.)
131910
+**
131911
+** The formulas above are for computing the action when the lookahead is
131892131912
** a terminal symbol. If the lookahead is a non-terminal (as occurs after
131893131913
** a reduce action) then the yy_reduce_ofst[] array is used in place of
131894131914
** the yy_shift_ofst[] array and YY_REDUCE_USE_DFLT is used in place of
131895131915
** YY_SHIFT_USE_DFLT.
131896131916
**
@@ -132211,14 +132231,14 @@
132211132231
/* 1470 */ 122, 23, 23, 64, 22, 124, 26, 26, 64, 64,
132212132232
/* 1480 */ 23, 23, 23, 23, 11, 23, 22, 26, 23, 22,
132213132233
/* 1490 */ 24, 1, 23, 22, 26, 122, 24, 23, 22, 122,
132214132234
/* 1500 */ 23, 23, 22, 122, 122, 23, 15,
132215132235
};
132216
-#define YY_SHIFT_USE_DFLT (-95)
132217
-#define YY_SHIFT_COUNT (442)
132218
-#define YY_SHIFT_MIN (-94)
132219
-#define YY_SHIFT_MAX (1491)
132236
+#define YY_SHIFT_USE_DFLT (1507)
132237
+#define YY_SHIFT_COUNT (442)
132238
+#define YY_SHIFT_MIN (-94)
132239
+#define YY_SHIFT_MAX (1491)
132220132240
static const short yy_shift_ofst[] = {
132221132241
/* 0 */ 40, 564, 869, 577, 725, 725, 725, 725, 690, -19,
132222132242
/* 10 */ 16, 16, 100, 725, 725, 725, 725, 725, 725, 725,
132223132243
/* 20 */ 841, 841, 538, 507, 684, 565, 61, 137, 172, 207,
132224132244
/* 30 */ 242, 277, 312, 347, 382, 424, 424, 424, 424, 424,
@@ -132227,16 +132247,16 @@
132227132247
/* 60 */ 725, 725, 725, 725, 725, 725, 725, 725, 725, 725,
132228132248
/* 70 */ 725, 725, 725, 725, 725, 725, 725, 725, 725, 725,
132229132249
/* 80 */ 725, 725, 725, 725, 821, 725, 725, 725, 725, 725,
132230132250
/* 90 */ 725, 725, 725, 725, 725, 725, 725, 725, 952, 711,
132231132251
/* 100 */ 711, 711, 711, 711, 766, 23, 32, 924, 637, 825,
132232
- /* 110 */ 837, 837, 924, 73, 183, -51, -95, -95, -95, 501,
132252
+ /* 110 */ 837, 837, 924, 73, 183, -51, 1507, 1507, 1507, 501,
132233132253
/* 120 */ 501, 501, 903, 903, 632, 205, 241, 924, 924, 924,
132234132254
/* 130 */ 924, 924, 924, 924, 924, 924, 924, 924, 924, 924,
132235132255
/* 140 */ 924, 924, 924, 924, 924, 924, 924, 192, 1027, 1106,
132236
- /* 150 */ 1106, 183, 176, 176, 176, 176, 176, 176, -95, -95,
132237
- /* 160 */ -95, 880, -94, -94, 578, 734, 99, 730, 769, 349,
132256
+ /* 150 */ 1106, 183, 176, 176, 176, 176, 176, 176, 1507, 1507,
132257
+ /* 160 */ 1507, 880, -94, -94, 578, 734, 99, 730, 769, 349,
132238132258
/* 170 */ 924, 924, 924, 924, 924, 924, 924, 924, 924, 924,
132239132259
/* 180 */ 924, 924, 924, 924, 924, 924, 924, 954, 954, 954,
132240132260
/* 190 */ 924, 924, 622, 924, 924, 924, -18, 924, 924, 914,
132241132261
/* 200 */ 924, 924, 924, 924, 924, 924, 924, 924, 924, 924,
132242132262
/* 210 */ 441, 1020, 1107, 1107, 1107, 569, 45, 217, 510, 423,
@@ -132246,12 +132266,12 @@
132246132266
/* 250 */ 1297, 1183, 1277, 1285, 1285, 1183, 1176, 1297, 1182, 1250,
132247132267
/* 260 */ 1176, 1176, 1297, 1311, 1176, 1297, 1176, 1297, 1311, 1234,
132248132268
/* 270 */ 1234, 1234, 1267, 1311, 1234, 1244, 1234, 1267, 1234, 1234,
132249132269
/* 280 */ 1232, 1247, 1232, 1247, 1232, 1247, 1232, 1247, 1176, 1334,
132250132270
/* 290 */ 1176, 1235, 1311, 1318, 1318, 1311, 1248, 1253, 1245, 1249,
132251
- /* 300 */ 1183, 1355, 1357, 1368, 1368, 1378, 1378, 1378, 1378, -95,
132252
- /* 310 */ -95, -95, -95, -95, -95, -95, -95, 451, 936, 816,
132271
+ /* 300 */ 1183, 1355, 1357, 1368, 1368, 1378, 1378, 1378, 1378, 1507,
132272
+ /* 310 */ 1507, 1507, 1507, 1507, 1507, 1507, 1507, 451, 936, 816,
132253132273
/* 320 */ 888, 1069, 799, 1111, 1197, 1193, 1201, 1202, 1203, 1213,
132254132274
/* 330 */ 1134, 1117, 1230, 497, 1218, 1219, 1154, 1223, 1115, 1120,
132255132275
/* 340 */ 1231, 1164, 1160, 1392, 1394, 1376, 1257, 1385, 1307, 1386,
132256132276
/* 350 */ 1383, 1388, 1292, 1282, 1303, 1294, 1395, 1293, 1403, 1419,
132257132277
/* 360 */ 1298, 1291, 1389, 1390, 1314, 1372, 1365, 1308, 1430, 1427,
@@ -133200,54 +133220,51 @@
133200133220
133201133221
if( stateno>=YY_MIN_REDUCE ) return stateno;
133202133222
assert( stateno <= YY_SHIFT_COUNT );
133203133223
do{
133204133224
i = yy_shift_ofst[stateno];
133205
- if( i==YY_SHIFT_USE_DFLT ) return yy_default[stateno];
133206133225
assert( iLookAhead!=YYNOCODE );
133207133226
i += iLookAhead;
133208133227
if( i<0 || i>=YY_ACTTAB_COUNT || yy_lookahead[i]!=iLookAhead ){
133209
- if( iLookAhead>0 ){
133210133228
#ifdef YYFALLBACK
133211
- YYCODETYPE iFallback; /* Fallback token */
133212
- if( iLookAhead<sizeof(yyFallback)/sizeof(yyFallback[0])
133213
- && (iFallback = yyFallback[iLookAhead])!=0 ){
133229
+ YYCODETYPE iFallback; /* Fallback token */
133230
+ if( iLookAhead<sizeof(yyFallback)/sizeof(yyFallback[0])
133231
+ && (iFallback = yyFallback[iLookAhead])!=0 ){
133214133232
#ifndef NDEBUG
133215
- if( yyTraceFILE ){
133216
- fprintf(yyTraceFILE, "%sFALLBACK %s => %s\n",
133217
- yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]);
133218
- }
133233
+ if( yyTraceFILE ){
133234
+ fprintf(yyTraceFILE, "%sFALLBACK %s => %s\n",
133235
+ yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]);
133236
+ }
133219133237
#endif
133220
- assert( yyFallback[iFallback]==0 ); /* Fallback loop must terminate */
133221
- iLookAhead = iFallback;
133222
- continue;
133223
- }
133238
+ assert( yyFallback[iFallback]==0 ); /* Fallback loop must terminate */
133239
+ iLookAhead = iFallback;
133240
+ continue;
133241
+ }
133224133242
#endif
133225133243
#ifdef YYWILDCARD
133226
- {
133227
- int j = i - iLookAhead + YYWILDCARD;
133228
- if(
133244
+ {
133245
+ int j = i - iLookAhead + YYWILDCARD;
133246
+ if(
133229133247
#if YY_SHIFT_MIN+YYWILDCARD<0
133230
- j>=0 &&
133248
+ j>=0 &&
133231133249
#endif
133232133250
#if YY_SHIFT_MAX+YYWILDCARD>=YY_ACTTAB_COUNT
133233
- j<YY_ACTTAB_COUNT &&
133251
+ j<YY_ACTTAB_COUNT &&
133234133252
#endif
133235
- yy_lookahead[j]==YYWILDCARD
133236
- ){
133253
+ yy_lookahead[j]==YYWILDCARD && iLookAhead>0
133254
+ ){
133237133255
#ifndef NDEBUG
133238
- if( yyTraceFILE ){
133239
- fprintf(yyTraceFILE, "%sWILDCARD %s => %s\n",
133240
- yyTracePrompt, yyTokenName[iLookAhead],
133241
- yyTokenName[YYWILDCARD]);
133242
- }
133256
+ if( yyTraceFILE ){
133257
+ fprintf(yyTraceFILE, "%sWILDCARD %s => %s\n",
133258
+ yyTracePrompt, yyTokenName[iLookAhead],
133259
+ yyTokenName[YYWILDCARD]);
133260
+ }
133243133261
#endif /* NDEBUG */
133244
- return yy_action[j];
133245
- }
133262
+ return yy_action[j];
133246133263
}
133264
+ }
133247133265
#endif /* YYWILDCARD */
133248
- }
133249133266
return yy_default[stateno];
133250133267
}else{
133251133268
return yy_action[i];
133252133269
}
133253133270
}while(1);
@@ -134679,12 +134696,14 @@
134679134696
break;
134680134697
case 213: /* cmd ::= DROP INDEX ifexists fullname */
134681134698
{sqlite3DropIndex(pParse, yymsp[0].minor.yy185, yymsp[-1].minor.yy194);}
134682134699
break;
134683134700
case 214: /* cmd ::= VACUUM */
134684
- case 215: /* cmd ::= VACUUM nm */ yytestcase(yyruleno==215);
134685
-{sqlite3Vacuum(pParse);}
134701
+{sqlite3Vacuum(pParse,0);}
134702
+ break;
134703
+ case 215: /* cmd ::= VACUUM nm */
134704
+{sqlite3Vacuum(pParse,&yymsp[0].minor.yy0);}
134686134705
break;
134687134706
case 216: /* cmd ::= PRAGMA nm dbnm */
134688134707
{sqlite3Pragma(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,0,0);}
134689134708
break;
134690134709
case 217: /* cmd ::= PRAGMA nm dbnm EQ nmnum */
@@ -136006,18 +136025,30 @@
136006136025
assert( pParse->pNewTable==0 );
136007136026
assert( pParse->pNewTrigger==0 );
136008136027
assert( pParse->nVar==0 );
136009136028
assert( pParse->nzVar==0 );
136010136029
assert( pParse->azVar==0 );
136011
- while( zSql[i]!=0 ){
136030
+ while( 1 ){
136012136031
assert( i>=0 );
136013
- pParse->sLastToken.z = &zSql[i];
136014
- pParse->sLastToken.n = sqlite3GetToken((unsigned char*)&zSql[i],&tokenType);
136015
- i += pParse->sLastToken.n;
136016
- if( i>mxSqlLen ){
136017
- pParse->rc = SQLITE_TOOBIG;
136018
- break;
136032
+ if( zSql[i]!=0 ){
136033
+ pParse->sLastToken.z = &zSql[i];
136034
+ pParse->sLastToken.n = sqlite3GetToken((u8*)&zSql[i],&tokenType);
136035
+ i += pParse->sLastToken.n;
136036
+ if( i>mxSqlLen ){
136037
+ pParse->rc = SQLITE_TOOBIG;
136038
+ break;
136039
+ }
136040
+ }else{
136041
+ /* Upon reaching the end of input, call the parser two more times
136042
+ ** with tokens TK_SEMI and 0, in that order. */
136043
+ if( lastTokenParsed==TK_SEMI ){
136044
+ tokenType = 0;
136045
+ }else if( lastTokenParsed==0 ){
136046
+ break;
136047
+ }else{
136048
+ tokenType = TK_SEMI;
136049
+ }
136019136050
}
136020136051
if( tokenType>=TK_SPACE ){
136021136052
assert( tokenType==TK_SPACE || tokenType==TK_ILLEGAL );
136022136053
if( db->u1.isInterrupted ){
136023136054
pParse->rc = SQLITE_INTERRUPT;
@@ -136034,19 +136065,10 @@
136034136065
if( pParse->rc!=SQLITE_OK || db->mallocFailed ) break;
136035136066
}
136036136067
}
136037136068
assert( nErr==0 );
136038136069
pParse->zTail = &zSql[i];
136039
- if( pParse->rc==SQLITE_OK && db->mallocFailed==0 ){
136040
- assert( zSql[i]==0 );
136041
- if( lastTokenParsed!=TK_SEMI ){
136042
- sqlite3Parser(pEngine, TK_SEMI, pParse->sLastToken, pParse);
136043
- }
136044
- if( pParse->rc==SQLITE_OK && db->mallocFailed==0 ){
136045
- sqlite3Parser(pEngine, 0, pParse->sLastToken, pParse);
136046
- }
136047
- }
136048136070
#ifdef YYTRACKMAXSTACKDEPTH
136049136071
sqlite3_mutex_enter(sqlite3MallocMutex());
136050136072
sqlite3StatusHighwater(SQLITE_STATUS_PARSER_STACK,
136051136073
sqlite3ParserStackPeak(pEngine)
136052136074
);
@@ -137282,10 +137304,15 @@
137282137304
SQLITE_API int SQLITE_CDECL sqlite3_db_config(sqlite3 *db, int op, ...){
137283137305
va_list ap;
137284137306
int rc;
137285137307
va_start(ap, op);
137286137308
switch( op ){
137309
+ case SQLITE_DBCONFIG_MAINDBNAME: {
137310
+ db->aDb[0].zDbSName = va_arg(ap,char*);
137311
+ rc = SQLITE_OK;
137312
+ break;
137313
+ }
137287137314
case SQLITE_DBCONFIG_LOOKASIDE: {
137288137315
void *pBuf = va_arg(ap, void*); /* IMP: R-26835-10964 */
137289137316
int sz = va_arg(ap, int); /* IMP: R-47871-25994 */
137290137317
int cnt = va_arg(ap, int); /* IMP: R-04460-53386 */
137291137318
rc = setupLookaside(db, pBuf, sz, cnt);
@@ -139425,13 +139452,13 @@
139425139452
db->aDb[1].pSchema = sqlite3SchemaGet(db, 0);
139426139453
139427139454
/* The default safety_level for the main database is FULL; for the temp
139428139455
** database it is OFF. This matches the pager layer defaults.
139429139456
*/
139430
- db->aDb[0].zName = "main";
139457
+ db->aDb[0].zDbSName = "main";
139431139458
db->aDb[0].safety_level = SQLITE_DEFAULT_SYNCHRONOUS+1;
139432
- db->aDb[1].zName = "temp";
139459
+ db->aDb[1].zDbSName = "temp";
139433139460
db->aDb[1].safety_level = PAGER_SYNCHRONOUS_OFF;
139434139461
139435139462
db->magic = SQLITE_MAGIC_OPEN;
139436139463
if( db->mallocFailed ){
139437139464
goto opendb_out;
@@ -140388,11 +140415,11 @@
140388140415
*/
140389140416
SQLITE_PRIVATE Btree *sqlite3DbNameToBtree(sqlite3 *db, const char *zDbName){
140390140417
int i;
140391140418
for(i=0; i<db->nDb; i++){
140392140419
if( db->aDb[i].pBt
140393
- && (zDbName==0 || sqlite3StrICmp(zDbName, db->aDb[i].zName)==0)
140420
+ && (zDbName==0 || sqlite3StrICmp(zDbName, db->aDb[i].zDbSName)==0)
140394140421
){
140395140422
return db->aDb[i].pBt;
140396140423
}
140397140424
}
140398140425
return 0;
@@ -164754,19 +164781,25 @@
164754164781
/*
164755164782
** Open an RBU handle to perform an RBU vacuum on database file zTarget.
164756164783
** An RBU vacuum is similar to SQLite's built-in VACUUM command, except
164757164784
** that it can be suspended and resumed like an RBU update.
164758164785
**
164759
-** The second argument to this function, which may not be NULL, identifies
164760
-** a database in which to store the state of the RBU vacuum operation if
164761
-** it is suspended. The first time sqlite3rbu_vacuum() is called, to start
164762
-** an RBU vacuum operation, the state database should either not exist or
164763
-** be empty (contain no tables). If an RBU vacuum is suspended by calling
164786
+** The second argument to this function identifies a database in which
164787
+** to store the state of the RBU vacuum operation if it is suspended. The
164788
+** first time sqlite3rbu_vacuum() is called, to start an RBU vacuum
164789
+** operation, the state database should either not exist or be empty
164790
+** (contain no tables). If an RBU vacuum is suspended by calling
164764164791
** sqlite3rbu_close() on the RBU handle before sqlite3rbu_step() has
164765164792
** returned SQLITE_DONE, the vacuum state is stored in the state database.
164766164793
** The vacuum can be resumed by calling this function to open a new RBU
164767164794
** handle specifying the same target and state databases.
164795
+**
164796
+** If the second argument passed to this function is NULL, then the
164797
+** name of the state database is "<database>-vacuum", where <database>
164798
+** is the name of the target database file. In this case, on UNIX, if the
164799
+** state database is not already present in the file-system, it is created
164800
+** with the same permissions as the target db is made.
164768164801
**
164769164802
** This function does not delete the state database after an RBU vacuum
164770164803
** is completed, even if it created it. However, if the call to
164771164804
** sqlite3rbu_close() returns any value other than SQLITE_OK, the contents
164772164805
** of the state tables within the state database are zeroed. This way,
@@ -167255,19 +167288,22 @@
167255167288
/*
167256167289
** Open the database handle and attach the RBU database as "rbu". If an
167257167290
** error occurs, leave an error code and message in the RBU handle.
167258167291
*/
167259167292
static void rbuOpenDatabase(sqlite3rbu *p){
167260
- assert( p->rc==SQLITE_OK );
167261
- assert( p->dbMain==0 && p->dbRbu==0 );
167262
- assert( rbuIsVacuum(p) || p->zTarget!=0 );
167293
+ assert( p->rc || (p->dbMain==0 && p->dbRbu==0) );
167294
+ assert( p->rc || rbuIsVacuum(p) || p->zTarget!=0 );
167263167295
167264167296
/* Open the RBU database */
167265167297
p->dbRbu = rbuOpenDbhandle(p, p->zRbu, 1);
167266167298
167267167299
if( p->rc==SQLITE_OK && rbuIsVacuum(p) ){
167268167300
sqlite3_file_control(p->dbRbu, "main", SQLITE_FCNTL_RBUCNT, (void*)p);
167301
+ if( p->zState==0 ){
167302
+ const char *zFile = sqlite3_db_filename(p->dbRbu, "main");
167303
+ p->zState = rbuMPrintf(p, "file://%s-vacuum?modeof=%s", zFile, zFile);
167304
+ }
167269167305
}
167270167306
167271167307
/* If using separate RBU and state databases, attach the state database to
167272167308
** the RBU db handle now. */
167273167309
if( p->zState ){
@@ -168398,12 +168434,11 @@
168398168434
const char *zState
168399168435
){
168400168436
sqlite3rbu *p;
168401168437
size_t nTarget = zTarget ? strlen(zTarget) : 0;
168402168438
size_t nRbu = strlen(zRbu);
168403
- size_t nState = zState ? strlen(zState) : 0;
168404
- size_t nByte = sizeof(sqlite3rbu) + nTarget+1 + nRbu+1+ nState+1;
168439
+ size_t nByte = sizeof(sqlite3rbu) + nTarget+1 + nRbu+1;
168405168440
168406168441
p = (sqlite3rbu*)sqlite3_malloc64(nByte);
168407168442
if( p ){
168408168443
RbuState *pState = 0;
168409168444
@@ -168421,12 +168456,11 @@
168421168456
}
168422168457
p->zRbu = pCsr;
168423168458
memcpy(p->zRbu, zRbu, nRbu+1);
168424168459
pCsr += nRbu+1;
168425168460
if( zState ){
168426
- p->zState = pCsr;
168427
- memcpy(p->zState, zState, nState+1);
168461
+ p->zState = rbuMPrintf(p, "%s", zState);
168428168462
}
168429168463
rbuOpenDatabase(p);
168430168464
}
168431168465
168432168466
if( p->rc==SQLITE_OK ){
@@ -168531,19 +168565,34 @@
168531168565
rbuFreeState(pState);
168532168566
}
168533168567
168534168568
return p;
168535168569
}
168570
+
168571
+/*
168572
+** Allocate and return an RBU handle with all fields zeroed except for the
168573
+** error code, which is set to SQLITE_MISUSE.
168574
+*/
168575
+static sqlite3rbu *rbuMisuseError(void){
168576
+ sqlite3rbu *pRet;
168577
+ pRet = sqlite3_malloc64(sizeof(sqlite3rbu));
168578
+ if( pRet ){
168579
+ memset(pRet, 0, sizeof(sqlite3rbu));
168580
+ pRet->rc = SQLITE_MISUSE;
168581
+ }
168582
+ return pRet;
168583
+}
168536168584
168537168585
/*
168538168586
** Open and return a new RBU handle.
168539168587
*/
168540168588
SQLITE_API sqlite3rbu *SQLITE_STDCALL sqlite3rbu_open(
168541168589
const char *zTarget,
168542168590
const char *zRbu,
168543168591
const char *zState
168544168592
){
168593
+ if( zTarget==0 || zRbu==0 ){ return rbuMisuseError(); }
168545168594
/* TODO: Check that zTarget and zRbu are non-NULL */
168546168595
return openRbuHandle(zTarget, zRbu, zState);
168547168596
}
168548168597
168549168598
/*
@@ -168551,10 +168600,11 @@
168551168600
*/
168552168601
SQLITE_API sqlite3rbu *SQLITE_STDCALL sqlite3rbu_vacuum(
168553168602
const char *zTarget,
168554168603
const char *zState
168555168604
){
168605
+ if( zTarget==0 ){ return rbuMisuseError(); }
168556168606
/* TODO: Check that both arguments are non-NULL */
168557168607
return openRbuHandle(0, zTarget, zState);
168558168608
}
168559168609
168560168610
/*
@@ -168628,10 +168678,11 @@
168628168678
sqlite3_free(p->aFrame);
168629168679
168630168680
rbuEditErrmsg(p);
168631168681
rc = p->rc;
168632168682
*pzErrmsg = p->zErrmsg;
168683
+ sqlite3_free(p->zState);
168633168684
sqlite3_free(p);
168634168685
}else{
168635168686
rc = SQLITE_NOMEM;
168636168687
*pzErrmsg = 0;
168637168688
}
@@ -170239,11 +170290,11 @@
170239170290
zSql = sqlite3_mprintf(
170240170291
"SELECT 'sqlite_master' AS name, 1 AS rootpage, 'table' AS type"
170241170292
" UNION ALL "
170242170293
"SELECT name, rootpage, type"
170243170294
" FROM \"%w\".%s WHERE rootpage!=0"
170244
- " ORDER BY name", pTab->db->aDb[pCsr->iDb].zName, zMaster);
170295
+ " ORDER BY name", pTab->db->aDb[pCsr->iDb].zDbSName, zMaster);
170245170296
if( zSql==0 ){
170246170297
return SQLITE_NOMEM_BKPT;
170247170298
}else{
170248170299
rc = sqlite3_prepare_v2(pTab->db, zSql, -1, &pCsr->pStmt, 0);
170249170300
sqlite3_free(zSql);
@@ -170293,11 +170344,11 @@
170293170344
sqlite3_result_int(ctx, pCsr->szPage);
170294170345
break;
170295170346
default: { /* schema */
170296170347
sqlite3 *db = sqlite3_context_db_handle(ctx);
170297170348
int iDb = pCsr->iDb;
170298
- sqlite3_result_text(ctx, db->aDb[iDb].zName, -1, SQLITE_STATIC);
170349
+ sqlite3_result_text(ctx, db->aDb[iDb].zDbSName, -1, SQLITE_STATIC);
170299170350
break;
170300170351
}
170301170352
}
170302170353
return SQLITE_OK;
170303170354
}
@@ -178530,10 +178581,11 @@
178530178581
static void sqlite3Fts5ParseNearsetFree(Fts5ExprNearset*);
178531178582
static void sqlite3Fts5ParseNodeFree(Fts5ExprNode*);
178532178583
178533178584
static void sqlite3Fts5ParseSetDistance(Fts5Parse*, Fts5ExprNearset*, Fts5Token*);
178534178585
static void sqlite3Fts5ParseSetColset(Fts5Parse*, Fts5ExprNearset*, Fts5Colset*);
178586
+static Fts5Colset *sqlite3Fts5ParseColsetInvert(Fts5Parse*, Fts5Colset*);
178535178587
static void sqlite3Fts5ParseFinished(Fts5Parse *pParse, Fts5ExprNode *p);
178536178588
static void sqlite3Fts5ParseNear(Fts5Parse *pParse, Fts5Token*);
178537178589
178538178590
/*
178539178591
** End of interface to code in fts5_expr.c.
@@ -178587,16 +178639,17 @@
178587178639
#define FTS5_NOT 3
178588178640
#define FTS5_TERM 4
178589178641
#define FTS5_COLON 5
178590178642
#define FTS5_LP 6
178591178643
#define FTS5_RP 7
178592
-#define FTS5_LCP 8
178593
-#define FTS5_RCP 9
178594
-#define FTS5_STRING 10
178595
-#define FTS5_COMMA 11
178596
-#define FTS5_PLUS 12
178597
-#define FTS5_STAR 13
178644
+#define FTS5_MINUS 8
178645
+#define FTS5_LCP 9
178646
+#define FTS5_RCP 10
178647
+#define FTS5_STRING 11
178648
+#define FTS5_COMMA 12
178649
+#define FTS5_PLUS 13
178650
+#define FTS5_STAR 14
178598178651
178599178652
/*
178600178653
** 2000-05-29
178601178654
**
178602178655
** The author disclaims copyright to this source code. In place of
@@ -178706,39 +178759,39 @@
178706178759
#ifndef INTERFACE
178707178760
# define INTERFACE 1
178708178761
#endif
178709178762
/************* Begin control #defines *****************************************/
178710178763
#define fts5YYCODETYPE unsigned char
178711
-#define fts5YYNOCODE 27
178764
+#define fts5YYNOCODE 28
178712178765
#define fts5YYACTIONTYPE unsigned char
178713178766
#define sqlite3Fts5ParserFTS5TOKENTYPE Fts5Token
178714178767
typedef union {
178715178768
int fts5yyinit;
178716178769
sqlite3Fts5ParserFTS5TOKENTYPE fts5yy0;
178717
- Fts5Colset* fts5yy3;
178718
- Fts5ExprPhrase* fts5yy11;
178719
- Fts5ExprNode* fts5yy18;
178720
- int fts5yy20;
178721
- Fts5ExprNearset* fts5yy26;
178770
+ int fts5yy4;
178771
+ Fts5Colset* fts5yy11;
178772
+ Fts5ExprNode* fts5yy24;
178773
+ Fts5ExprNearset* fts5yy46;
178774
+ Fts5ExprPhrase* fts5yy53;
178722178775
} fts5YYMINORTYPE;
178723178776
#ifndef fts5YYSTACKDEPTH
178724178777
#define fts5YYSTACKDEPTH 100
178725178778
#endif
178726178779
#define sqlite3Fts5ParserARG_SDECL Fts5Parse *pParse;
178727178780
#define sqlite3Fts5ParserARG_PDECL ,Fts5Parse *pParse
178728178781
#define sqlite3Fts5ParserARG_FETCH Fts5Parse *pParse = fts5yypParser->pParse
178729178782
#define sqlite3Fts5ParserARG_STORE fts5yypParser->pParse = pParse
178730
-#define fts5YYNSTATE 26
178731
-#define fts5YYNRULE 24
178732
-#define fts5YY_MAX_SHIFT 25
178733
-#define fts5YY_MIN_SHIFTREDUCE 40
178734
-#define fts5YY_MAX_SHIFTREDUCE 63
178735
-#define fts5YY_MIN_REDUCE 64
178736
-#define fts5YY_MAX_REDUCE 87
178737
-#define fts5YY_ERROR_ACTION 88
178738
-#define fts5YY_ACCEPT_ACTION 89
178739
-#define fts5YY_NO_ACTION 90
178783
+#define fts5YYNSTATE 29
178784
+#define fts5YYNRULE 26
178785
+#define fts5YY_MAX_SHIFT 28
178786
+#define fts5YY_MIN_SHIFTREDUCE 45
178787
+#define fts5YY_MAX_SHIFTREDUCE 70
178788
+#define fts5YY_MIN_REDUCE 71
178789
+#define fts5YY_MAX_REDUCE 96
178790
+#define fts5YY_ERROR_ACTION 97
178791
+#define fts5YY_ACCEPT_ACTION 98
178792
+#define fts5YY_NO_ACTION 99
178740178793
/************* End control #defines *******************************************/
178741178794
178742178795
/* Define the fts5yytestcase() macro to be a no-op if is not already defined
178743178796
** otherwise.
178744178797
**
@@ -178766,29 +178819,33 @@
178766178819
** N between fts5YY_MIN_SHIFTREDUCE Shift to an arbitrary state then
178767178820
** and fts5YY_MAX_SHIFTREDUCE reduce by rule N-fts5YY_MIN_SHIFTREDUCE.
178768178821
**
178769178822
** N between fts5YY_MIN_REDUCE Reduce by rule N-fts5YY_MIN_REDUCE
178770178823
** and fts5YY_MAX_REDUCE
178771
-
178824
+**
178772178825
** N == fts5YY_ERROR_ACTION A syntax error has occurred.
178773178826
**
178774178827
** N == fts5YY_ACCEPT_ACTION The parser accepts its input.
178775178828
**
178776178829
** N == fts5YY_NO_ACTION No such action. Denotes unused
178777178830
** slots in the fts5yy_action[] table.
178778178831
**
178779178832
** The action table is constructed as a single large table named fts5yy_action[].
178780
-** Given state S and lookahead X, the action is computed as
178781
-**
178782
-** fts5yy_action[ fts5yy_shift_ofst[S] + X ]
178783
-**
178784
-** If the index value fts5yy_shift_ofst[S]+X is out of range or if the value
178785
-** fts5yy_lookahead[fts5yy_shift_ofst[S]+X] is not equal to X or if fts5yy_shift_ofst[S]
178786
-** is equal to fts5YY_SHIFT_USE_DFLT, it means that the action is not in the table
178787
-** and that fts5yy_default[S] should be used instead.
178788
-**
178789
-** The formula above is for computing the action when the lookahead is
178833
+** Given state S and lookahead X, the action is computed as either:
178834
+**
178835
+** (A) N = fts5yy_action[ fts5yy_shift_ofst[S] + X ]
178836
+** (B) N = fts5yy_default[S]
178837
+**
178838
+** The (A) formula is preferred. The B formula is used instead if:
178839
+** (1) The fts5yy_shift_ofst[S]+X value is out of range, or
178840
+** (2) fts5yy_lookahead[fts5yy_shift_ofst[S]+X] is not equal to X, or
178841
+** (3) fts5yy_shift_ofst[S] equal fts5YY_SHIFT_USE_DFLT.
178842
+** (Implementation note: fts5YY_SHIFT_USE_DFLT is chosen so that
178843
+** fts5YY_SHIFT_USE_DFLT+X will be out of range for all possible lookaheads X.
178844
+** Hence only tests (1) and (2) need to be evaluated.)
178845
+**
178846
+** The formulas above are for computing the action when the lookahead is
178790178847
** a terminal symbol. If the lookahead is a non-terminal (as occurs after
178791178848
** a reduce action) then the fts5yy_reduce_ofst[] array is used in place of
178792178849
** the fts5yy_shift_ofst[] array and fts5YY_REDUCE_USE_DFLT is used in place of
178793178850
** fts5YY_SHIFT_USE_DFLT.
178794178851
**
@@ -178802,52 +178859,54 @@
178802178859
** fts5yy_reduce_ofst[] For each state, the offset into fts5yy_action for
178803178860
** shifting non-terminals after a reduce.
178804178861
** fts5yy_default[] Default action for each state.
178805178862
**
178806178863
*********** Begin parsing tables **********************************************/
178807
-#define fts5YY_ACTTAB_COUNT (78)
178864
+#define fts5YY_ACTTAB_COUNT (85)
178808178865
static const fts5YYACTIONTYPE fts5yy_action[] = {
178809
- /* 0 */ 89, 15, 46, 5, 48, 24, 12, 19, 23, 14,
178810
- /* 10 */ 46, 5, 48, 24, 20, 21, 23, 43, 46, 5,
178811
- /* 20 */ 48, 24, 6, 18, 23, 17, 46, 5, 48, 24,
178812
- /* 30 */ 75, 7, 23, 25, 46, 5, 48, 24, 62, 47,
178813
- /* 40 */ 23, 48, 24, 7, 11, 23, 9, 3, 4, 2,
178814
- /* 50 */ 62, 50, 52, 44, 64, 3, 4, 2, 49, 4,
178815
- /* 60 */ 2, 1, 23, 11, 16, 9, 12, 2, 10, 61,
178816
- /* 70 */ 53, 59, 62, 60, 22, 13, 55, 8,
178866
+ /* 0 */ 98, 16, 51, 5, 53, 27, 83, 7, 26, 15,
178867
+ /* 10 */ 51, 5, 53, 27, 13, 69, 26, 48, 51, 5,
178868
+ /* 20 */ 53, 27, 19, 11, 26, 9, 20, 51, 5, 53,
178869
+ /* 30 */ 27, 13, 22, 26, 28, 51, 5, 53, 27, 68,
178870
+ /* 40 */ 1, 26, 19, 11, 17, 9, 52, 10, 53, 27,
178871
+ /* 50 */ 23, 24, 26, 54, 3, 4, 2, 26, 6, 21,
178872
+ /* 60 */ 49, 71, 3, 4, 2, 7, 56, 59, 55, 59,
178873
+ /* 70 */ 4, 2, 12, 69, 58, 60, 18, 67, 62, 69,
178874
+ /* 80 */ 25, 66, 8, 14, 2,
178817178875
};
178818178876
static const fts5YYCODETYPE fts5yy_lookahead[] = {
178819
- /* 0 */ 15, 16, 17, 18, 19, 20, 10, 11, 23, 16,
178820
- /* 10 */ 17, 18, 19, 20, 23, 24, 23, 16, 17, 18,
178821
- /* 20 */ 19, 20, 22, 23, 23, 16, 17, 18, 19, 20,
178822
- /* 30 */ 5, 6, 23, 16, 17, 18, 19, 20, 13, 17,
178823
- /* 40 */ 23, 19, 20, 6, 8, 23, 10, 1, 2, 3,
178824
- /* 50 */ 13, 9, 10, 7, 0, 1, 2, 3, 19, 2,
178825
- /* 60 */ 3, 6, 23, 8, 21, 10, 10, 3, 10, 25,
178826
- /* 70 */ 10, 10, 13, 25, 12, 10, 7, 5,
178827
-};
178828
-#define fts5YY_SHIFT_USE_DFLT (-5)
178829
-#define fts5YY_SHIFT_COUNT (25)
178830
-#define fts5YY_SHIFT_MIN (-4)
178831
-#define fts5YY_SHIFT_MAX (72)
178832
-static const signed char fts5yy_shift_ofst[] = {
178833
- /* 0 */ 55, 55, 55, 55, 55, 36, -4, 56, 58, 25,
178834
- /* 10 */ 37, 60, 59, 59, 46, 54, 42, 57, 62, 61,
178835
- /* 20 */ 62, 69, 65, 62, 72, 64,
178836
-};
178837
-#define fts5YY_REDUCE_USE_DFLT (-16)
178838
-#define fts5YY_REDUCE_COUNT (13)
178839
-#define fts5YY_REDUCE_MIN (-15)
178840
-#define fts5YY_REDUCE_MAX (48)
178877
+ /* 0 */ 16, 17, 18, 19, 20, 21, 5, 6, 24, 17,
178878
+ /* 10 */ 18, 19, 20, 21, 11, 14, 24, 17, 18, 19,
178879
+ /* 20 */ 20, 21, 8, 9, 24, 11, 17, 18, 19, 20,
178880
+ /* 30 */ 21, 11, 12, 24, 17, 18, 19, 20, 21, 26,
178881
+ /* 40 */ 6, 24, 8, 9, 22, 11, 18, 11, 20, 21,
178882
+ /* 50 */ 24, 25, 24, 20, 1, 2, 3, 24, 23, 24,
178883
+ /* 60 */ 7, 0, 1, 2, 3, 6, 10, 11, 10, 11,
178884
+ /* 70 */ 2, 3, 9, 14, 11, 11, 22, 26, 7, 14,
178885
+ /* 80 */ 13, 11, 5, 11, 3,
178886
+};
178887
+#define fts5YY_SHIFT_USE_DFLT (85)
178888
+#define fts5YY_SHIFT_COUNT (28)
178889
+#define fts5YY_SHIFT_MIN (0)
178890
+#define fts5YY_SHIFT_MAX (81)
178891
+static const unsigned char fts5yy_shift_ofst[] = {
178892
+ /* 0 */ 34, 34, 34, 34, 34, 14, 20, 3, 36, 1,
178893
+ /* 10 */ 59, 64, 64, 65, 65, 53, 61, 56, 58, 63,
178894
+ /* 20 */ 68, 67, 70, 67, 71, 72, 67, 77, 81,
178895
+};
178896
+#define fts5YY_REDUCE_USE_DFLT (-17)
178897
+#define fts5YY_REDUCE_COUNT (14)
178898
+#define fts5YY_REDUCE_MIN (-16)
178899
+#define fts5YY_REDUCE_MAX (54)
178841178900
static const signed char fts5yy_reduce_ofst[] = {
178842
- /* 0 */ -15, -7, 1, 9, 17, 22, -9, 0, 39, 44,
178843
- /* 10 */ 44, 43, 44, 48,
178901
+ /* 0 */ -16, -8, 0, 9, 17, 28, 26, 35, 33, 13,
178902
+ /* 10 */ 13, 22, 54, 13, 51,
178844178903
};
178845178904
static const fts5YYACTIONTYPE fts5yy_default[] = {
178846
- /* 0 */ 88, 88, 88, 88, 88, 69, 82, 88, 88, 87,
178847
- /* 10 */ 87, 88, 87, 87, 88, 88, 88, 66, 80, 88,
178848
- /* 20 */ 81, 88, 88, 78, 88, 65,
178905
+ /* 0 */ 97, 97, 97, 97, 97, 76, 91, 97, 97, 96,
178906
+ /* 10 */ 96, 97, 97, 96, 96, 97, 97, 97, 97, 97,
178907
+ /* 20 */ 73, 89, 97, 90, 97, 97, 87, 97, 72,
178849178908
};
178850178909
/********** End of lemon-generated parsing tables *****************************/
178851178910
178852178911
/* The next table maps tokens (terminal symbols) into fallback tokens.
178853178912
** If a construct like the following:
@@ -178950,15 +179009,15 @@
178950179009
/* For tracing shifts, the names of all terminals and nonterminals
178951179010
** are required. The following table supplies these names */
178952179011
static const char *const fts5yyTokenName[] = {
178953179012
"$", "OR", "AND", "NOT",
178954179013
"TERM", "COLON", "LP", "RP",
178955
- "LCP", "RCP", "STRING", "COMMA",
178956
- "PLUS", "STAR", "error", "input",
178957
- "expr", "cnearset", "exprlist", "nearset",
178958
- "colset", "colsetlist", "nearphrases", "phrase",
178959
- "neardist_opt", "star_opt",
179014
+ "MINUS", "LCP", "RCP", "STRING",
179015
+ "COMMA", "PLUS", "STAR", "error",
179016
+ "input", "expr", "cnearset", "exprlist",
179017
+ "nearset", "colset", "colsetlist", "nearphrases",
179018
+ "phrase", "neardist_opt", "star_opt",
178960179019
};
178961179020
#endif /* NDEBUG */
178962179021
178963179022
#ifndef NDEBUG
178964179023
/* For tracing reduce actions, the names of all rules are required.
@@ -178972,24 +179031,26 @@
178972179031
/* 5 */ "expr ::= exprlist",
178973179032
/* 6 */ "exprlist ::= cnearset",
178974179033
/* 7 */ "exprlist ::= exprlist cnearset",
178975179034
/* 8 */ "cnearset ::= nearset",
178976179035
/* 9 */ "cnearset ::= colset COLON nearset",
178977
- /* 10 */ "colset ::= LCP colsetlist RCP",
178978
- /* 11 */ "colset ::= STRING",
178979
- /* 12 */ "colsetlist ::= colsetlist STRING",
178980
- /* 13 */ "colsetlist ::= STRING",
178981
- /* 14 */ "nearset ::= phrase",
178982
- /* 15 */ "nearset ::= STRING LP nearphrases neardist_opt RP",
178983
- /* 16 */ "nearphrases ::= phrase",
178984
- /* 17 */ "nearphrases ::= nearphrases phrase",
178985
- /* 18 */ "neardist_opt ::=",
178986
- /* 19 */ "neardist_opt ::= COMMA STRING",
178987
- /* 20 */ "phrase ::= phrase PLUS STRING star_opt",
178988
- /* 21 */ "phrase ::= STRING star_opt",
178989
- /* 22 */ "star_opt ::= STAR",
178990
- /* 23 */ "star_opt ::=",
179036
+ /* 10 */ "colset ::= MINUS LCP colsetlist RCP",
179037
+ /* 11 */ "colset ::= LCP colsetlist RCP",
179038
+ /* 12 */ "colset ::= STRING",
179039
+ /* 13 */ "colset ::= MINUS STRING",
179040
+ /* 14 */ "colsetlist ::= colsetlist STRING",
179041
+ /* 15 */ "colsetlist ::= STRING",
179042
+ /* 16 */ "nearset ::= phrase",
179043
+ /* 17 */ "nearset ::= STRING LP nearphrases neardist_opt RP",
179044
+ /* 18 */ "nearphrases ::= phrase",
179045
+ /* 19 */ "nearphrases ::= nearphrases phrase",
179046
+ /* 20 */ "neardist_opt ::=",
179047
+ /* 21 */ "neardist_opt ::= COMMA STRING",
179048
+ /* 22 */ "phrase ::= phrase PLUS STRING star_opt",
179049
+ /* 23 */ "phrase ::= STRING star_opt",
179050
+ /* 24 */ "star_opt ::= STAR",
179051
+ /* 25 */ "star_opt ::=",
178991179052
};
178992179053
#endif /* NDEBUG */
178993179054
178994179055
178995179056
#if fts5YYSTACKDEPTH<=0
@@ -179095,37 +179156,37 @@
179095179156
** Note: during a reduce, the only symbols destroyed are those
179096179157
** which appear on the RHS of the rule, but which are *not* used
179097179158
** inside the C code.
179098179159
*/
179099179160
/********* Begin destructor definitions ***************************************/
179100
- case 15: /* input */
179161
+ case 16: /* input */
179101179162
{
179102179163
(void)pParse;
179103179164
}
179104179165
break;
179105
- case 16: /* expr */
179106
- case 17: /* cnearset */
179107
- case 18: /* exprlist */
179108
-{
179109
- sqlite3Fts5ParseNodeFree((fts5yypminor->fts5yy18));
179110
-}
179111
- break;
179112
- case 19: /* nearset */
179113
- case 22: /* nearphrases */
179114
-{
179115
- sqlite3Fts5ParseNearsetFree((fts5yypminor->fts5yy26));
179116
-}
179117
- break;
179118
- case 20: /* colset */
179119
- case 21: /* colsetlist */
179120
-{
179121
- sqlite3_free((fts5yypminor->fts5yy3));
179122
-}
179123
- break;
179124
- case 23: /* phrase */
179125
-{
179126
- sqlite3Fts5ParsePhraseFree((fts5yypminor->fts5yy11));
179166
+ case 17: /* expr */
179167
+ case 18: /* cnearset */
179168
+ case 19: /* exprlist */
179169
+{
179170
+ sqlite3Fts5ParseNodeFree((fts5yypminor->fts5yy24));
179171
+}
179172
+ break;
179173
+ case 20: /* nearset */
179174
+ case 23: /* nearphrases */
179175
+{
179176
+ sqlite3Fts5ParseNearsetFree((fts5yypminor->fts5yy46));
179177
+}
179178
+ break;
179179
+ case 21: /* colset */
179180
+ case 22: /* colsetlist */
179181
+{
179182
+ sqlite3_free((fts5yypminor->fts5yy11));
179183
+}
179184
+ break;
179185
+ case 24: /* phrase */
179186
+{
179187
+ sqlite3Fts5ParsePhraseFree((fts5yypminor->fts5yy53));
179127179188
}
179128179189
break;
179129179190
/********* End destructor definitions *****************************************/
179130179191
default: break; /* If no destructor action specified: do nothing */
179131179192
}
@@ -179198,54 +179259,51 @@
179198179259
179199179260
if( stateno>=fts5YY_MIN_REDUCE ) return stateno;
179200179261
assert( stateno <= fts5YY_SHIFT_COUNT );
179201179262
do{
179202179263
i = fts5yy_shift_ofst[stateno];
179203
- if( i==fts5YY_SHIFT_USE_DFLT ) return fts5yy_default[stateno];
179204179264
assert( iLookAhead!=fts5YYNOCODE );
179205179265
i += iLookAhead;
179206179266
if( i<0 || i>=fts5YY_ACTTAB_COUNT || fts5yy_lookahead[i]!=iLookAhead ){
179207
- if( iLookAhead>0 ){
179208179267
#ifdef fts5YYFALLBACK
179209
- fts5YYCODETYPE iFallback; /* Fallback token */
179210
- if( iLookAhead<sizeof(fts5yyFallback)/sizeof(fts5yyFallback[0])
179211
- && (iFallback = fts5yyFallback[iLookAhead])!=0 ){
179268
+ fts5YYCODETYPE iFallback; /* Fallback token */
179269
+ if( iLookAhead<sizeof(fts5yyFallback)/sizeof(fts5yyFallback[0])
179270
+ && (iFallback = fts5yyFallback[iLookAhead])!=0 ){
179212179271
#ifndef NDEBUG
179213
- if( fts5yyTraceFILE ){
179214
- fprintf(fts5yyTraceFILE, "%sFALLBACK %s => %s\n",
179215
- fts5yyTracePrompt, fts5yyTokenName[iLookAhead], fts5yyTokenName[iFallback]);
179216
- }
179272
+ if( fts5yyTraceFILE ){
179273
+ fprintf(fts5yyTraceFILE, "%sFALLBACK %s => %s\n",
179274
+ fts5yyTracePrompt, fts5yyTokenName[iLookAhead], fts5yyTokenName[iFallback]);
179275
+ }
179217179276
#endif
179218
- assert( fts5yyFallback[iFallback]==0 ); /* Fallback loop must terminate */
179219
- iLookAhead = iFallback;
179220
- continue;
179221
- }
179277
+ assert( fts5yyFallback[iFallback]==0 ); /* Fallback loop must terminate */
179278
+ iLookAhead = iFallback;
179279
+ continue;
179280
+ }
179222179281
#endif
179223179282
#ifdef fts5YYWILDCARD
179224
- {
179225
- int j = i - iLookAhead + fts5YYWILDCARD;
179226
- if(
179283
+ {
179284
+ int j = i - iLookAhead + fts5YYWILDCARD;
179285
+ if(
179227179286
#if fts5YY_SHIFT_MIN+fts5YYWILDCARD<0
179228
- j>=0 &&
179287
+ j>=0 &&
179229179288
#endif
179230179289
#if fts5YY_SHIFT_MAX+fts5YYWILDCARD>=fts5YY_ACTTAB_COUNT
179231
- j<fts5YY_ACTTAB_COUNT &&
179290
+ j<fts5YY_ACTTAB_COUNT &&
179232179291
#endif
179233
- fts5yy_lookahead[j]==fts5YYWILDCARD
179234
- ){
179292
+ fts5yy_lookahead[j]==fts5YYWILDCARD && iLookAhead>0
179293
+ ){
179235179294
#ifndef NDEBUG
179236
- if( fts5yyTraceFILE ){
179237
- fprintf(fts5yyTraceFILE, "%sWILDCARD %s => %s\n",
179238
- fts5yyTracePrompt, fts5yyTokenName[iLookAhead],
179239
- fts5yyTokenName[fts5YYWILDCARD]);
179240
- }
179295
+ if( fts5yyTraceFILE ){
179296
+ fprintf(fts5yyTraceFILE, "%sWILDCARD %s => %s\n",
179297
+ fts5yyTracePrompt, fts5yyTokenName[iLookAhead],
179298
+ fts5yyTokenName[fts5YYWILDCARD]);
179299
+ }
179241179300
#endif /* NDEBUG */
179242
- return fts5yy_action[j];
179243
- }
179301
+ return fts5yy_action[j];
179244179302
}
179303
+ }
179245179304
#endif /* fts5YYWILDCARD */
179246
- }
179247179305
return fts5yy_default[stateno];
179248179306
}else{
179249179307
return fts5yy_action[i];
179250179308
}
179251179309
}while(1);
@@ -179368,34 +179426,36 @@
179368179426
*/
179369179427
static const struct {
179370179428
fts5YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */
179371179429
unsigned char nrhs; /* Number of right-hand side symbols in the rule */
179372179430
} fts5yyRuleInfo[] = {
179373
- { 15, 1 },
179374
- { 16, 3 },
179375
- { 16, 3 },
179376
- { 16, 3 },
179377
- { 16, 3 },
179378179431
{ 16, 1 },
179432
+ { 17, 3 },
179433
+ { 17, 3 },
179434
+ { 17, 3 },
179435
+ { 17, 3 },
179436
+ { 17, 1 },
179437
+ { 19, 1 },
179438
+ { 19, 2 },
179379179439
{ 18, 1 },
179380
- { 18, 2 },
179381
- { 17, 1 },
179382
- { 17, 3 },
179383
- { 20, 3 },
179384
- { 20, 1 },
179440
+ { 18, 3 },
179441
+ { 21, 4 },
179442
+ { 21, 3 },
179443
+ { 21, 1 },
179385179444
{ 21, 2 },
179386
- { 21, 1 },
179387
- { 19, 1 },
179388
- { 19, 5 },
179445
+ { 22, 2 },
179389179446
{ 22, 1 },
179390
- { 22, 2 },
179391
- { 24, 0 },
179392
- { 24, 2 },
179393
- { 23, 4 },
179447
+ { 20, 1 },
179448
+ { 20, 5 },
179449
+ { 23, 1 },
179394179450
{ 23, 2 },
179395
- { 25, 1 },
179396179451
{ 25, 0 },
179452
+ { 25, 2 },
179453
+ { 24, 4 },
179454
+ { 24, 2 },
179455
+ { 26, 1 },
179456
+ { 26, 0 },
179397179457
};
179398179458
179399179459
static void fts5yy_accept(fts5yyParser*); /* Forward Declaration */
179400179460
179401179461
/*
@@ -179456,124 +179516,135 @@
179456179516
** break;
179457179517
*/
179458179518
/********** Begin reduce actions **********************************************/
179459179519
fts5YYMINORTYPE fts5yylhsminor;
179460179520
case 0: /* input ::= expr */
179461
-{ sqlite3Fts5ParseFinished(pParse, fts5yymsp[0].minor.fts5yy18); }
179521
+{ sqlite3Fts5ParseFinished(pParse, fts5yymsp[0].minor.fts5yy24); }
179462179522
break;
179463179523
case 1: /* expr ::= expr AND expr */
179464179524
{
179465
- fts5yylhsminor.fts5yy18 = sqlite3Fts5ParseNode(pParse, FTS5_AND, fts5yymsp[-2].minor.fts5yy18, fts5yymsp[0].minor.fts5yy18, 0);
179525
+ fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_AND, fts5yymsp[-2].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24, 0);
179466179526
}
179467
- fts5yymsp[-2].minor.fts5yy18 = fts5yylhsminor.fts5yy18;
179527
+ fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
179468179528
break;
179469179529
case 2: /* expr ::= expr OR expr */
179470179530
{
179471
- fts5yylhsminor.fts5yy18 = sqlite3Fts5ParseNode(pParse, FTS5_OR, fts5yymsp[-2].minor.fts5yy18, fts5yymsp[0].minor.fts5yy18, 0);
179531
+ fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_OR, fts5yymsp[-2].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24, 0);
179472179532
}
179473
- fts5yymsp[-2].minor.fts5yy18 = fts5yylhsminor.fts5yy18;
179533
+ fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
179474179534
break;
179475179535
case 3: /* expr ::= expr NOT expr */
179476179536
{
179477
- fts5yylhsminor.fts5yy18 = sqlite3Fts5ParseNode(pParse, FTS5_NOT, fts5yymsp[-2].minor.fts5yy18, fts5yymsp[0].minor.fts5yy18, 0);
179537
+ fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_NOT, fts5yymsp[-2].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24, 0);
179478179538
}
179479
- fts5yymsp[-2].minor.fts5yy18 = fts5yylhsminor.fts5yy18;
179539
+ fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
179480179540
break;
179481179541
case 4: /* expr ::= LP expr RP */
179482
-{fts5yymsp[-2].minor.fts5yy18 = fts5yymsp[-1].minor.fts5yy18;}
179542
+{fts5yymsp[-2].minor.fts5yy24 = fts5yymsp[-1].minor.fts5yy24;}
179483179543
break;
179484179544
case 5: /* expr ::= exprlist */
179485179545
case 6: /* exprlist ::= cnearset */ fts5yytestcase(fts5yyruleno==6);
179486
-{fts5yylhsminor.fts5yy18 = fts5yymsp[0].minor.fts5yy18;}
179487
- fts5yymsp[0].minor.fts5yy18 = fts5yylhsminor.fts5yy18;
179546
+{fts5yylhsminor.fts5yy24 = fts5yymsp[0].minor.fts5yy24;}
179547
+ fts5yymsp[0].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
179488179548
break;
179489179549
case 7: /* exprlist ::= exprlist cnearset */
179490179550
{
179491
- fts5yylhsminor.fts5yy18 = sqlite3Fts5ParseImplicitAnd(pParse, fts5yymsp[-1].minor.fts5yy18, fts5yymsp[0].minor.fts5yy18);
179551
+ fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseImplicitAnd(pParse, fts5yymsp[-1].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24);
179492179552
}
179493
- fts5yymsp[-1].minor.fts5yy18 = fts5yylhsminor.fts5yy18;
179553
+ fts5yymsp[-1].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
179494179554
break;
179495179555
case 8: /* cnearset ::= nearset */
179496179556
{
179497
- fts5yylhsminor.fts5yy18 = sqlite3Fts5ParseNode(pParse, FTS5_STRING, 0, 0, fts5yymsp[0].minor.fts5yy26);
179557
+ fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_STRING, 0, 0, fts5yymsp[0].minor.fts5yy46);
179498179558
}
179499
- fts5yymsp[0].minor.fts5yy18 = fts5yylhsminor.fts5yy18;
179559
+ fts5yymsp[0].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
179500179560
break;
179501179561
case 9: /* cnearset ::= colset COLON nearset */
179502179562
{
179503
- sqlite3Fts5ParseSetColset(pParse, fts5yymsp[0].minor.fts5yy26, fts5yymsp[-2].minor.fts5yy3);
179504
- fts5yylhsminor.fts5yy18 = sqlite3Fts5ParseNode(pParse, FTS5_STRING, 0, 0, fts5yymsp[0].minor.fts5yy26);
179505
-}
179506
- fts5yymsp[-2].minor.fts5yy18 = fts5yylhsminor.fts5yy18;
179507
- break;
179508
- case 10: /* colset ::= LCP colsetlist RCP */
179509
-{ fts5yymsp[-2].minor.fts5yy3 = fts5yymsp[-1].minor.fts5yy3; }
179510
- break;
179511
- case 11: /* colset ::= STRING */
179512
-{
179513
- fts5yylhsminor.fts5yy3 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
179514
-}
179515
- fts5yymsp[0].minor.fts5yy3 = fts5yylhsminor.fts5yy3;
179516
- break;
179517
- case 12: /* colsetlist ::= colsetlist STRING */
179518
-{
179519
- fts5yylhsminor.fts5yy3 = sqlite3Fts5ParseColset(pParse, fts5yymsp[-1].minor.fts5yy3, &fts5yymsp[0].minor.fts5yy0); }
179520
- fts5yymsp[-1].minor.fts5yy3 = fts5yylhsminor.fts5yy3;
179521
- break;
179522
- case 13: /* colsetlist ::= STRING */
179523
-{
179524
- fts5yylhsminor.fts5yy3 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
179525
-}
179526
- fts5yymsp[0].minor.fts5yy3 = fts5yylhsminor.fts5yy3;
179527
- break;
179528
- case 14: /* nearset ::= phrase */
179529
-{ fts5yylhsminor.fts5yy26 = sqlite3Fts5ParseNearset(pParse, 0, fts5yymsp[0].minor.fts5yy11); }
179530
- fts5yymsp[0].minor.fts5yy26 = fts5yylhsminor.fts5yy26;
179531
- break;
179532
- case 15: /* nearset ::= STRING LP nearphrases neardist_opt RP */
179563
+ sqlite3Fts5ParseSetColset(pParse, fts5yymsp[0].minor.fts5yy46, fts5yymsp[-2].minor.fts5yy11);
179564
+ fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_STRING, 0, 0, fts5yymsp[0].minor.fts5yy46);
179565
+}
179566
+ fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
179567
+ break;
179568
+ case 10: /* colset ::= MINUS LCP colsetlist RCP */
179569
+{
179570
+ fts5yymsp[-3].minor.fts5yy11 = sqlite3Fts5ParseColsetInvert(pParse, fts5yymsp[-1].minor.fts5yy11);
179571
+}
179572
+ break;
179573
+ case 11: /* colset ::= LCP colsetlist RCP */
179574
+{ fts5yymsp[-2].minor.fts5yy11 = fts5yymsp[-1].minor.fts5yy11; }
179575
+ break;
179576
+ case 12: /* colset ::= STRING */
179577
+{
179578
+ fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
179579
+}
179580
+ fts5yymsp[0].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
179581
+ break;
179582
+ case 13: /* colset ::= MINUS STRING */
179583
+{
179584
+ fts5yymsp[-1].minor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
179585
+ fts5yymsp[-1].minor.fts5yy11 = sqlite3Fts5ParseColsetInvert(pParse, fts5yymsp[-1].minor.fts5yy11);
179586
+}
179587
+ break;
179588
+ case 14: /* colsetlist ::= colsetlist STRING */
179589
+{
179590
+ fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseColset(pParse, fts5yymsp[-1].minor.fts5yy11, &fts5yymsp[0].minor.fts5yy0); }
179591
+ fts5yymsp[-1].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
179592
+ break;
179593
+ case 15: /* colsetlist ::= STRING */
179594
+{
179595
+ fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
179596
+}
179597
+ fts5yymsp[0].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
179598
+ break;
179599
+ case 16: /* nearset ::= phrase */
179600
+{ fts5yylhsminor.fts5yy46 = sqlite3Fts5ParseNearset(pParse, 0, fts5yymsp[0].minor.fts5yy53); }
179601
+ fts5yymsp[0].minor.fts5yy46 = fts5yylhsminor.fts5yy46;
179602
+ break;
179603
+ case 17: /* nearset ::= STRING LP nearphrases neardist_opt RP */
179533179604
{
179534179605
sqlite3Fts5ParseNear(pParse, &fts5yymsp[-4].minor.fts5yy0);
179535
- sqlite3Fts5ParseSetDistance(pParse, fts5yymsp[-2].minor.fts5yy26, &fts5yymsp[-1].minor.fts5yy0);
179536
- fts5yylhsminor.fts5yy26 = fts5yymsp[-2].minor.fts5yy26;
179537
-}
179538
- fts5yymsp[-4].minor.fts5yy26 = fts5yylhsminor.fts5yy26;
179539
- break;
179540
- case 16: /* nearphrases ::= phrase */
179541
-{
179542
- fts5yylhsminor.fts5yy26 = sqlite3Fts5ParseNearset(pParse, 0, fts5yymsp[0].minor.fts5yy11);
179543
-}
179544
- fts5yymsp[0].minor.fts5yy26 = fts5yylhsminor.fts5yy26;
179545
- break;
179546
- case 17: /* nearphrases ::= nearphrases phrase */
179547
-{
179548
- fts5yylhsminor.fts5yy26 = sqlite3Fts5ParseNearset(pParse, fts5yymsp[-1].minor.fts5yy26, fts5yymsp[0].minor.fts5yy11);
179549
-}
179550
- fts5yymsp[-1].minor.fts5yy26 = fts5yylhsminor.fts5yy26;
179551
- break;
179552
- case 18: /* neardist_opt ::= */
179606
+ sqlite3Fts5ParseSetDistance(pParse, fts5yymsp[-2].minor.fts5yy46, &fts5yymsp[-1].minor.fts5yy0);
179607
+ fts5yylhsminor.fts5yy46 = fts5yymsp[-2].minor.fts5yy46;
179608
+}
179609
+ fts5yymsp[-4].minor.fts5yy46 = fts5yylhsminor.fts5yy46;
179610
+ break;
179611
+ case 18: /* nearphrases ::= phrase */
179612
+{
179613
+ fts5yylhsminor.fts5yy46 = sqlite3Fts5ParseNearset(pParse, 0, fts5yymsp[0].minor.fts5yy53);
179614
+}
179615
+ fts5yymsp[0].minor.fts5yy46 = fts5yylhsminor.fts5yy46;
179616
+ break;
179617
+ case 19: /* nearphrases ::= nearphrases phrase */
179618
+{
179619
+ fts5yylhsminor.fts5yy46 = sqlite3Fts5ParseNearset(pParse, fts5yymsp[-1].minor.fts5yy46, fts5yymsp[0].minor.fts5yy53);
179620
+}
179621
+ fts5yymsp[-1].minor.fts5yy46 = fts5yylhsminor.fts5yy46;
179622
+ break;
179623
+ case 20: /* neardist_opt ::= */
179553179624
{ fts5yymsp[1].minor.fts5yy0.p = 0; fts5yymsp[1].minor.fts5yy0.n = 0; }
179554179625
break;
179555
- case 19: /* neardist_opt ::= COMMA STRING */
179626
+ case 21: /* neardist_opt ::= COMMA STRING */
179556179627
{ fts5yymsp[-1].minor.fts5yy0 = fts5yymsp[0].minor.fts5yy0; }
179557179628
break;
179558
- case 20: /* phrase ::= phrase PLUS STRING star_opt */
179559
-{
179560
- fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseTerm(pParse, fts5yymsp[-3].minor.fts5yy11, &fts5yymsp[-1].minor.fts5yy0, fts5yymsp[0].minor.fts5yy20);
179561
-}
179562
- fts5yymsp[-3].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
179563
- break;
179564
- case 21: /* phrase ::= STRING star_opt */
179565
-{
179566
- fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseTerm(pParse, 0, &fts5yymsp[-1].minor.fts5yy0, fts5yymsp[0].minor.fts5yy20);
179567
-}
179568
- fts5yymsp[-1].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
179569
- break;
179570
- case 22: /* star_opt ::= STAR */
179571
-{ fts5yymsp[0].minor.fts5yy20 = 1; }
179572
- break;
179573
- case 23: /* star_opt ::= */
179574
-{ fts5yymsp[1].minor.fts5yy20 = 0; }
179629
+ case 22: /* phrase ::= phrase PLUS STRING star_opt */
179630
+{
179631
+ fts5yylhsminor.fts5yy53 = sqlite3Fts5ParseTerm(pParse, fts5yymsp[-3].minor.fts5yy53, &fts5yymsp[-1].minor.fts5yy0, fts5yymsp[0].minor.fts5yy4);
179632
+}
179633
+ fts5yymsp[-3].minor.fts5yy53 = fts5yylhsminor.fts5yy53;
179634
+ break;
179635
+ case 23: /* phrase ::= STRING star_opt */
179636
+{
179637
+ fts5yylhsminor.fts5yy53 = sqlite3Fts5ParseTerm(pParse, 0, &fts5yymsp[-1].minor.fts5yy0, fts5yymsp[0].minor.fts5yy4);
179638
+}
179639
+ fts5yymsp[-1].minor.fts5yy53 = fts5yylhsminor.fts5yy53;
179640
+ break;
179641
+ case 24: /* star_opt ::= STAR */
179642
+{ fts5yymsp[0].minor.fts5yy4 = 1; }
179643
+ break;
179644
+ case 25: /* star_opt ::= */
179645
+{ fts5yymsp[1].minor.fts5yy4 = 0; }
179575179646
break;
179576179647
default:
179577179648
break;
179578179649
/********** End reduce actions ************************************************/
179579179650
};
@@ -180027,11 +180098,11 @@
180027180098
}
180028180099
180029180100
if( p->iRangeEnd>0 && iPos==p->iRangeEnd ){
180030180101
fts5HighlightAppend(&rc, p, &p->zIn[p->iOff], iEndOff - p->iOff);
180031180102
p->iOff = iEndOff;
180032
- if( iPos<p->iter.iEnd ){
180103
+ if( iPos>=p->iter.iStart && iPos<p->iter.iEnd ){
180033180104
fts5HighlightAppend(&rc, p, p->zClose, -1);
180034180105
}
180035180106
}
180036180107
180037180108
return rc;
@@ -180188,10 +180259,17 @@
180188180259
ctx.iRangeEnd = iBestStart + nToken - 1;
180189180260
180190180261
if( iBestStart>0 ){
180191180262
fts5HighlightAppend(&rc, &ctx, zEllips, -1);
180192180263
}
180264
+
180265
+ /* Advance iterator ctx.iter so that it points to the first coalesced
180266
+ ** phrase instance at or following position iBestStart. */
180267
+ while( ctx.iter.iStart>=0 && ctx.iter.iStart<iBestStart && rc==SQLITE_OK ){
180268
+ rc = fts5CInstIterNext(&ctx.iter);
180269
+ }
180270
+
180193180271
if( rc==SQLITE_OK ){
180194180272
rc = pApi->xTokenize(pFts, ctx.zIn, ctx.nIn, (void*)&ctx,fts5HighlightCb);
180195180273
}
180196180274
if( ctx.iRangeEnd>=(nColSize-1) ){
180197180275
fts5HighlightAppend(&rc, &ctx, &ctx.zIn[ctx.iOff], ctx.nIn - ctx.iOff);
@@ -181923,10 +182001,11 @@
181923182001
case '}': tok = FTS5_RCP; break;
181924182002
case ':': tok = FTS5_COLON; break;
181925182003
case ',': tok = FTS5_COMMA; break;
181926182004
case '+': tok = FTS5_PLUS; break;
181927182005
case '*': tok = FTS5_STAR; break;
182006
+ case '-': tok = FTS5_MINUS; break;
181928182007
case '\0': tok = FTS5_EOF; break;
181929182008
181930182009
case '"': {
181931182010
const char *z2;
181932182011
tok = FTS5_STRING;
@@ -183414,11 +183493,11 @@
183414183493
sizeof(Fts5ExprNearset) + sizeof(Fts5ExprPhrase*));
183415183494
}
183416183495
if( rc==SQLITE_OK ){
183417183496
Fts5Colset *pColsetOrig = pOrig->pNode->pNear->pColset;
183418183497
if( pColsetOrig ){
183419
- int nByte = sizeof(Fts5Colset) + pColsetOrig->nCol * sizeof(int);
183498
+ int nByte = sizeof(Fts5Colset) + (pColsetOrig->nCol-1) * sizeof(int);
183420183499
Fts5Colset *pColset = (Fts5Colset*)sqlite3Fts5MallocZero(&rc, nByte);
183421183500
if( pColset ){
183422183501
memcpy(pColset, pColsetOrig, nByte);
183423183502
}
183424183503
pNew->pRoot->pNear->pColset = pColset;
@@ -183548,10 +183627,38 @@
183548183627
#endif
183549183628
}
183550183629
183551183630
return pNew;
183552183631
}
183632
+
183633
+/*
183634
+** Allocate and return an Fts5Colset object specifying the inverse of
183635
+** the colset passed as the second argument. Free the colset passed
183636
+** as the second argument before returning.
183637
+*/
183638
+static Fts5Colset *sqlite3Fts5ParseColsetInvert(Fts5Parse *pParse, Fts5Colset *p){
183639
+ Fts5Colset *pRet;
183640
+ int nCol = pParse->pConfig->nCol;
183641
+
183642
+ pRet = (Fts5Colset*)sqlite3Fts5MallocZero(&pParse->rc,
183643
+ sizeof(Fts5Colset) + sizeof(int)*nCol
183644
+ );
183645
+ if( pRet ){
183646
+ int i;
183647
+ int iOld = 0;
183648
+ for(i=0; i<nCol; i++){
183649
+ if( iOld>=p->nCol || p->aiCol[iOld]!=i ){
183650
+ pRet->aiCol[pRet->nCol++] = i;
183651
+ }else{
183652
+ iOld++;
183653
+ }
183654
+ }
183655
+ }
183656
+
183657
+ sqlite3_free(p);
183658
+ return pRet;
183659
+}
183553183660
183554183661
static Fts5Colset *sqlite3Fts5ParseColset(
183555183662
Fts5Parse *pParse, /* Store SQLITE_NOMEM here if required */
183556183663
Fts5Colset *pColset, /* Existing colset object */
183557183664
Fts5Token *p
@@ -185644,18 +185751,29 @@
185644185751
185645185752
assert( (pRet==0)==(p->rc!=SQLITE_OK) );
185646185753
return pRet;
185647185754
}
185648185755
185649
-
185650185756
/*
185651185757
** Release a reference to data record returned by an earlier call to
185652185758
** fts5DataRead().
185653185759
*/
185654185760
static void fts5DataRelease(Fts5Data *pData){
185655185761
sqlite3_free(pData);
185656185762
}
185763
+
185764
+static Fts5Data *fts5LeafRead(Fts5Index *p, i64 iRowid){
185765
+ Fts5Data *pRet = fts5DataRead(p, iRowid);
185766
+ if( pRet ){
185767
+ if( pRet->szLeaf>pRet->nn ){
185768
+ p->rc = FTS5_CORRUPT;
185769
+ fts5DataRelease(pRet);
185770
+ pRet = 0;
185771
+ }
185772
+ }
185773
+ return pRet;
185774
+}
185657185775
185658185776
static int fts5IndexPrepareStmt(
185659185777
Fts5Index *p,
185660185778
sqlite3_stmt **ppStmt,
185661185779
char *zSql
@@ -186461,11 +186579,11 @@
186461186579
pIter->iLeafPgno++;
186462186580
if( pIter->pNextLeaf ){
186463186581
pIter->pLeaf = pIter->pNextLeaf;
186464186582
pIter->pNextLeaf = 0;
186465186583
}else if( pIter->iLeafPgno<=pSeg->pgnoLast ){
186466
- pIter->pLeaf = fts5DataRead(p,
186584
+ pIter->pLeaf = fts5LeafRead(p,
186467186585
FTS5_SEGMENT_ROWID(pSeg->iSegid, pIter->iLeafPgno)
186468186586
);
186469186587
}else{
186470186588
pIter->pLeaf = 0;
186471186589
}
@@ -186964,13 +187082,12 @@
186964187082
pIter->iLeafOffset = iOff;
186965187083
186966187084
if( pLeaf->nn>pLeaf->szLeaf ){
186967187085
pIter->iPgidxOff = pLeaf->szLeaf + fts5GetVarint32(
186968187086
&pLeaf->p[pLeaf->szLeaf], pIter->iEndofDoclist
186969
- );
187087
+ );
186970187088
}
186971
-
186972187089
}
186973187090
else if( pLeaf->nn>pLeaf->szLeaf ){
186974187091
pIter->iPgidxOff = pLeaf->szLeaf + fts5GetVarint32(
186975187092
&pLeaf->p[pLeaf->szLeaf], iOff
186976187093
);
@@ -187210,10 +187327,15 @@
187210187327
}
187211187328
187212187329
iPgidx += fts5GetVarint32(&a[iPgidx], nKeep);
187213187330
iTermOff += nKeep;
187214187331
iOff = iTermOff;
187332
+
187333
+ if( iOff>=n ){
187334
+ p->rc = FTS5_CORRUPT;
187335
+ return;
187336
+ }
187215187337
187216187338
/* Read the nKeep field of the next term. */
187217187339
fts5FastGetVarint32(a, iOff, nKeep);
187218187340
}
187219187341
@@ -188136,10 +188258,19 @@
188136188258
fts5BufferZero(&pIter->poslist);
188137188259
fts5SegiterPoslist(pIter->pIndex, pSeg, 0, &pIter->poslist);
188138188260
pIter->base.pData = pIter->poslist.p;
188139188261
}
188140188262
}
188263
+
188264
+/*
188265
+** xSetOutputs callback used when the Fts5Colset object has nCol==0 (match
188266
+** against no columns at all).
188267
+*/
188268
+static void fts5IterSetOutputs_ZeroColset(Fts5Iter *pIter, Fts5SegIter *pSeg){
188269
+ UNUSED_PARAM(pSeg);
188270
+ pIter->base.nData = 0;
188271
+}
188141188272
188142188273
/*
188143188274
** xSetOutputs callback used by detail=col when there is a column filter
188144188275
** and there are 100 or more columns. Also called as a fallback from
188145188276
** fts5IterSetOutputs_Col100 if the column-list spans more than one page.
@@ -188241,10 +188372,14 @@
188241188372
}
188242188373
188243188374
else if( pIter->pColset==0 ){
188244188375
pIter->xSetOutputs = fts5IterSetOutputs_Nocolset;
188245188376
}
188377
+
188378
+ else if( pIter->pColset->nCol==0 ){
188379
+ pIter->xSetOutputs = fts5IterSetOutputs_ZeroColset;
188380
+ }
188246188381
188247188382
else if( pConfig->eDetail==FTS5_DETAIL_FULL ){
188248188383
pIter->xSetOutputs = fts5IterSetOutputs_Full;
188249188384
}
188250188385
@@ -194018,11 +194153,11 @@
194018194153
int nArg, /* Number of args */
194019194154
sqlite3_value **apUnused /* Function arguments */
194020194155
){
194021194156
assert( nArg==0 );
194022194157
UNUSED_PARAM2(nArg, apUnused);
194023
- sqlite3_result_text(pCtx, "fts5: 2016-08-11 18:53:32 a12d8059770df4bca59e321c266410344242bf7b", -1, SQLITE_TRANSIENT);
194158
+ sqlite3_result_text(pCtx, "fts5: 2016-08-20 18:06:14 9041ee4a6f0e8389297f887f1431ab5cfe783390", -1, SQLITE_TRANSIENT);
194024194159
}
194025194160
194026194161
static int fts5Init(sqlite3 *db){
194027194162
static const sqlite3_module fts5Mod = {
194028194163
/* iVersion */ 2,
194029194164
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.14.1. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a single translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% or more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -378,13 +378,13 @@
378 **
379 ** See also: [sqlite3_libversion()],
380 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
381 ** [sqlite_version()] and [sqlite_source_id()].
382 */
383 #define SQLITE_VERSION "3.14.1"
384 #define SQLITE_VERSION_NUMBER 3014001
385 #define SQLITE_SOURCE_ID "2016-08-11 18:53:32 a12d8059770df4bca59e321c266410344242bf7b"
386
387 /*
388 ** CAPI3REF: Run-Time Library Version Numbers
389 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
390 **
@@ -2227,12 +2227,22 @@
2227 ** is written 0 or 1 to indicate whether [sqlite3_load_extension()] interface
2228 ** is disabled or enabled following this call. The second parameter may
2229 ** be a NULL pointer, in which case the new setting is not reported back.
2230 ** </dd>
2231 **
 
 
 
 
 
 
 
 
 
2232 ** </dl>
2233 */
 
2234 #define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
2235 #define SQLITE_DBCONFIG_ENABLE_FKEY 1002 /* int int* */
2236 #define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */
2237 #define SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1004 /* int int* */
2238 #define SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION 1005 /* int int* */
@@ -13694,11 +13704,11 @@
13694 ** in the sqlite.aDb[] array. aDb[0] is the main database file and
13695 ** aDb[1] is the database file used to hold temporary tables. Additional
13696 ** databases may be attached.
13697 */
13698 struct Db {
13699 char *zName; /* Name of this database */
13700 Btree *pBt; /* The B*Tree structure for this database file */
13701 u8 safety_level; /* How aggressive at syncing data to disk */
13702 u8 bSyncSet; /* True if "PRAGMA synchronous=N" has been run */
13703 Schema *pSchema; /* Pointer to database schema (possibly shared) */
13704 };
@@ -16298,12 +16308,12 @@
16298 SQLITE_PRIVATE Table *sqlite3LocateTable(Parse*,u32 flags,const char*, const char*);
16299 SQLITE_PRIVATE Table *sqlite3LocateTableItem(Parse*,u32 flags,struct SrcList_item *);
16300 SQLITE_PRIVATE Index *sqlite3FindIndex(sqlite3*,const char*, const char*);
16301 SQLITE_PRIVATE void sqlite3UnlinkAndDeleteTable(sqlite3*,int,const char*);
16302 SQLITE_PRIVATE void sqlite3UnlinkAndDeleteIndex(sqlite3*,int,const char*);
16303 SQLITE_PRIVATE void sqlite3Vacuum(Parse*);
16304 SQLITE_PRIVATE int sqlite3RunVacuum(char**, sqlite3*);
16305 SQLITE_PRIVATE char *sqlite3NameFromToken(sqlite3*, Token*);
16306 SQLITE_PRIVATE int sqlite3ExprCompare(Expr*, Expr*, int);
16307 SQLITE_PRIVATE int sqlite3ExprListCompare(ExprList*, ExprList*, int);
16308 SQLITE_PRIVATE int sqlite3ExprImpliesExpr(Expr*, Expr*, int);
16309 SQLITE_PRIVATE void sqlite3ExprAnalyzeAggregates(NameContext*, Expr*);
@@ -34851,10 +34861,31 @@
34851 unixLeaveMutex();
34852 }
34853 #endif /* if !OS_VXWORKS */
34854 return pUnused;
34855 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34856
34857 /*
34858 ** This function is called by unixOpen() to determine the unix permissions
34859 ** to create new files with. If no error occurs, then SQLITE_OK is returned
34860 ** and a value suitable for passing as the third argument to open(2) is
@@ -34887,11 +34918,10 @@
34887 *pUid = 0;
34888 *pGid = 0;
34889 if( flags & (SQLITE_OPEN_WAL|SQLITE_OPEN_MAIN_JOURNAL) ){
34890 char zDb[MAX_PATHNAME+1]; /* Database file path */
34891 int nDb; /* Number of valid bytes in zDb */
34892 struct stat sStat; /* Output of stat() on database file */
34893
34894 /* zPath is a path to a WAL or journal file. The following block derives
34895 ** the path to the associated database file from zPath. This block handles
34896 ** the following naming conventions:
34897 **
@@ -34918,19 +34948,22 @@
34918 nDb--;
34919 }
34920 memcpy(zDb, zPath, nDb);
34921 zDb[nDb] = '\0';
34922
34923 if( 0==osStat(zDb, &sStat) ){
34924 *pMode = sStat.st_mode & 0777;
34925 *pUid = sStat.st_uid;
34926 *pGid = sStat.st_gid;
34927 }else{
34928 rc = SQLITE_IOERR_FSTAT;
34929 }
34930 }else if( flags & SQLITE_OPEN_DELETEONCLOSE ){
34931 *pMode = 0600;
 
 
 
 
 
 
 
 
 
34932 }
34933 return rc;
34934 }
34935
34936 /*
@@ -75441,11 +75474,11 @@
75441 int nEntry;
75442 sqlite3BtreeEnter(pBt);
75443 nEntry = sqlite3PagerWalCallback(sqlite3BtreePager(pBt));
75444 sqlite3BtreeLeave(pBt);
75445 if( db->xWalCallback && nEntry>0 && rc==SQLITE_OK ){
75446 rc = db->xWalCallback(db->pWalArg, db, db->aDb[i].zName, nEntry);
75447 }
75448 }
75449 }
75450 #endif
75451 return rc;
@@ -81472,11 +81505,11 @@
81472 }
81473
81474 if( pOp->p4type==P4_TABLE && HAS_UPDATE_HOOK(db) ){
81475 assert( pC->isTable );
81476 assert( pC->iDb>=0 );
81477 zDb = db->aDb[pC->iDb].zName;
81478 pTab = pOp->p4.pTab;
81479 assert( HasRowid(pTab) );
81480 op = ((pOp->p5 & OPFLAG_ISUPDATE) ? SQLITE_UPDATE : SQLITE_INSERT);
81481 }else{
81482 pTab = 0; /* Not needed. Silence a comiler warning. */
@@ -81589,11 +81622,11 @@
81589 ** last moved with OP_Next or OP_Prev, not Seek or NotFound, set
81590 ** VdbeCursor.movetoTarget to the current rowid. */
81591 if( pOp->p4type==P4_TABLE && HAS_UPDATE_HOOK(db) ){
81592 assert( pC->iDb>=0 );
81593 assert( pOp->p4.pTab!=0 );
81594 zDb = db->aDb[pC->iDb].zName;
81595 pTab = pOp->p4.pTab;
81596 if( (pOp->p5 & OPFLAG_SAVEPOSITION)!=0 && pC->isTable ){
81597 pC->movetoTarget = sqlite3BtreeIntegerKey(pC->uc.pCursor);
81598 }
81599 }else{
@@ -82559,11 +82592,11 @@
82559 initData.db = db;
82560 initData.iDb = pOp->p1;
82561 initData.pzErrMsg = &p->zErrMsg;
82562 zSql = sqlite3MPrintf(db,
82563 "SELECT name, rootpage, sql FROM '%q'.%s WHERE %s ORDER BY rowid",
82564 db->aDb[iDb].zName, zMaster, pOp->p4.z);
82565 if( zSql==0 ){
82566 rc = SQLITE_NOMEM_BKPT;
82567 }else{
82568 assert( db->init.busy==0 );
82569 db->init.busy = 1;
@@ -83388,19 +83421,18 @@
83388 break;
83389 };
83390 #endif /* SQLITE_OMIT_PRAGMA */
83391
83392 #if !defined(SQLITE_OMIT_VACUUM) && !defined(SQLITE_OMIT_ATTACH)
83393 /* Opcode: Vacuum * * * * *
83394 **
83395 ** Vacuum the entire database. This opcode will cause other virtual
83396 ** machines to be created and run. It may not be called from within
83397 ** a transaction.
83398 */
83399 case OP_Vacuum: {
83400 assert( p->readOnly==0 );
83401 rc = sqlite3RunVacuum(&p->zErrMsg, db);
83402 if( rc ) goto abort_due_to_error;
83403 break;
83404 }
83405 #endif
83406
@@ -83943,11 +83975,11 @@
83943 zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql);
83944 if( zTrace ){
83945 int i;
83946 for(i=0; i<db->nDb; i++){
83947 if( DbMaskTest(p->btreeMask, i)==0 ) continue;
83948 sqlite3_file_control(db, db->aDb[i].zName, SQLITE_FCNTL_TRACE, zTrace);
83949 }
83950 }
83951 #endif /* SQLITE_USE_FCNTL_TRACE */
83952 #ifdef SQLITE_DEBUG
83953 if( (db->flags & SQLITE_SqlTrace)!=0
@@ -84279,11 +84311,11 @@
84279 rc = SQLITE_ERROR;
84280 sqlite3BtreeLeaveAll(db);
84281 goto blob_open_out;
84282 }
84283 pBlob->pTab = pTab;
84284 pBlob->zDb = db->aDb[sqlite3SchemaToIndex(db, pTab->pSchema)].zName;
84285
84286 /* Now search pTab for the exact column. */
84287 for(iCol=0; iCol<pTab->nCol; iCol++) {
84288 if( sqlite3StrICmp(pTab->aCol[iCol].zName, zColumn)==0 ){
84289 break;
@@ -87831,21 +87863,19 @@
87831 static SQLITE_NOINLINE int walkExpr(Walker *pWalker, Expr *pExpr){
87832 int rc;
87833 testcase( ExprHasProperty(pExpr, EP_TokenOnly) );
87834 testcase( ExprHasProperty(pExpr, EP_Reduced) );
87835 rc = pWalker->xExprCallback(pWalker, pExpr);
87836 if( rc==WRC_Continue
87837 && !ExprHasProperty(pExpr,EP_TokenOnly) ){
87838 if( sqlite3WalkExpr(pWalker, pExpr->pLeft) ) return WRC_Abort;
87839 if( sqlite3WalkExpr(pWalker, pExpr->pRight) ) return WRC_Abort;
87840 if( ExprHasProperty(pExpr, EP_xIsSelect) ){
87841 if( sqlite3WalkSelect(pWalker, pExpr->x.pSelect) ) return WRC_Abort;
87842 }else{
87843 if( sqlite3WalkExprList(pWalker, pExpr->x.pList) ) return WRC_Abort;
87844 }
87845 }
87846 return rc & WRC_Abort;
87847 }
87848 SQLITE_PRIVATE int sqlite3WalkExpr(Walker *pWalker, Expr *pExpr){
87849 return pExpr ? walkExpr(pWalker,pExpr) : WRC_Continue;
87850 }
87851
@@ -88175,12 +88205,12 @@
88175 ** legacy and because it does not hurt anything to just ignore the
88176 ** database name. */
88177 zDb = 0;
88178 }else{
88179 for(i=0; i<db->nDb; i++){
88180 assert( db->aDb[i].zName );
88181 if( sqlite3StrICmp(db->aDb[i].zName,zDb)==0 ){
88182 pSchema = db->aDb[i].pSchema;
88183 break;
88184 }
88185 }
88186 }
@@ -94249,11 +94279,11 @@
94249 assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );
94250
94251 pTab = sqlite3LocateTableItem(pParse, 0, &pSrc->a[0]);
94252 if( !pTab ) goto exit_rename_table;
94253 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
94254 zDb = db->aDb[iDb].zName;
94255 db->flags |= SQLITE_PreferBuiltin;
94256
94257 /* Get a NULL terminated version of the new table name. */
94258 zName = sqlite3NameFromToken(db, pName);
94259 if( !zName ) goto exit_rename_table;
@@ -94447,11 +94477,11 @@
94447 pNew = pParse->pNewTable;
94448 assert( pNew );
94449
94450 assert( sqlite3BtreeHoldsAllMutexes(db) );
94451 iDb = sqlite3SchemaToIndex(db, pNew->pSchema);
94452 zDb = db->aDb[iDb].zName;
94453 zTab = &pNew->zName[16]; /* Skip the "sqlite_altertab_" prefix on the name */
94454 pCol = &pNew->aCol[pNew->nCol-1];
94455 pDflt = pCol->pDflt;
94456 pTab = sqlite3FindTable(db, zTab, zDb);
94457 assert( pTab );
@@ -94857,18 +94887,18 @@
94857 ** if they do already exist.
94858 */
94859 for(i=0; i<ArraySize(aTable); i++){
94860 const char *zTab = aTable[i].zName;
94861 Table *pStat;
94862 if( (pStat = sqlite3FindTable(db, zTab, pDb->zName))==0 ){
94863 if( aTable[i].zCols ){
94864 /* The sqlite_statN table does not exist. Create it. Note that a
94865 ** side-effect of the CREATE TABLE statement is to leave the rootpage
94866 ** of the new table in register pParse->regRoot. This is important
94867 ** because the OpenWrite opcode below will be needing it. */
94868 sqlite3NestedParse(pParse,
94869 "CREATE TABLE %Q.%s(%s)", pDb->zName, zTab, aTable[i].zCols
94870 );
94871 aRoot[i] = pParse->regRoot;
94872 aCreateTbl[i] = OPFLAG_P2ISREG;
94873 }
94874 }else{
@@ -94879,11 +94909,11 @@
94879 aCreateTbl[i] = 0;
94880 sqlite3TableLock(pParse, iDb, aRoot[i], 1, zTab);
94881 if( zWhere ){
94882 sqlite3NestedParse(pParse,
94883 "DELETE FROM %Q.%s WHERE %s=%Q",
94884 pDb->zName, zTab, zWhereType, zWhere
94885 );
94886 }else{
94887 /* The sqlite_stat[134] table already exists. Delete all rows. */
94888 sqlite3VdbeAddOp2(v, OP_Clear, aRoot[i], iDb);
94889 }
@@ -95641,11 +95671,11 @@
95641 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
95642 assert( iDb>=0 );
95643 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
95644 #ifndef SQLITE_OMIT_AUTHORIZATION
95645 if( sqlite3AuthCheck(pParse, SQLITE_ANALYZE, pTab->zName, 0,
95646 db->aDb[iDb].zName ) ){
95647 return;
95648 }
95649 #endif
95650
95651 /* Establish a read-lock on the table at the shared-cache level.
@@ -96031,11 +96061,11 @@
96031 }
96032 }else{
96033 /* Form 3: Analyze the fully qualified table name */
96034 iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pTableName);
96035 if( iDb>=0 ){
96036 zDb = db->aDb[iDb].zName;
96037 z = sqlite3NameFromToken(db, pTableName);
96038 if( z ){
96039 if( (pIdx = sqlite3FindIndex(db, z, zDb))!=0 ){
96040 analyzeTable(pParse, pIdx->pTable, pIdx);
96041 }else if( (pTab = sqlite3LocateTable(pParse, 0, z, zDb))!=0 ){
@@ -96491,11 +96521,11 @@
96491 #endif
96492 }
96493
96494 /* Load new statistics out of the sqlite_stat1 table */
96495 sInfo.db = db;
96496 sInfo.zDatabase = db->aDb[iDb].zName;
96497 if( sqlite3FindTable(db, "sqlite_stat1", sInfo.zDatabase)!=0 ){
96498 zSql = sqlite3MPrintf(db,
96499 "SELECT tbl,idx,stat FROM %Q.sqlite_stat1", sInfo.zDatabase);
96500 if( zSql==0 ){
96501 rc = SQLITE_NOMEM_BKPT;
@@ -96634,11 +96664,11 @@
96634 if( !db->autoCommit ){
96635 zErrDyn = sqlite3MPrintf(db, "cannot ATTACH database within transaction");
96636 goto attach_error;
96637 }
96638 for(i=0; i<db->nDb; i++){
96639 char *z = db->aDb[i].zName;
96640 assert( z && zName );
96641 if( sqlite3StrICmp(z, zName)==0 ){
96642 zErrDyn = sqlite3MPrintf(db, "database %s is already in use", zName);
96643 goto attach_error;
96644 }
@@ -96699,12 +96729,12 @@
96699 PAGER_SYNCHRONOUS_FULL | (db->flags & PAGER_FLAGS_MASK));
96700 #endif
96701 sqlite3BtreeLeave(aNew->pBt);
96702 }
96703 aNew->safety_level = SQLITE_DEFAULT_SYNCHRONOUS+1;
96704 aNew->zName = sqlite3DbStrDup(db, zName);
96705 if( rc==SQLITE_OK && aNew->zName==0 ){
96706 rc = SQLITE_NOMEM_BKPT;
96707 }
96708
96709
96710 #ifdef SQLITE_HAS_CODEC
@@ -96812,11 +96842,11 @@
96812
96813 if( zName==0 ) zName = "";
96814 for(i=0; i<db->nDb; i++){
96815 pDb = &db->aDb[i];
96816 if( pDb->pBt==0 ) continue;
96817 if( sqlite3StrICmp(pDb->zName, zName)==0 ) break;
96818 }
96819
96820 if( i>=db->nDb ){
96821 sqlite3_snprintf(sizeof(zErr),zErr, "no such database: %s", zName);
96822 goto detach_error;
@@ -96970,11 +97000,11 @@
96970 sqlite3 *db;
96971
96972 db = pParse->db;
96973 assert( db->nDb>iDb );
96974 pFix->pParse = pParse;
96975 pFix->zDb = db->aDb[iDb].zName;
96976 pFix->pSchema = db->aDb[iDb].pSchema;
96977 pFix->zType = zType;
96978 pFix->pName = pName;
96979 pFix->bVarOnly = (iDb==1);
96980 }
@@ -97228,13 +97258,13 @@
97228 Parse *pParse, /* The parser context */
97229 const char *zTab, /* Table name */
97230 const char *zCol, /* Column name */
97231 int iDb /* Index of containing database. */
97232 ){
97233 sqlite3 *db = pParse->db; /* Database handle */
97234 char *zDb = db->aDb[iDb].zName; /* Name of attached database */
97235 int rc; /* Auth callback return code */
97236
97237 if( db->init.busy ) return SQLITE_OK;
97238 rc = db->xAuth(db->pAuthArg, SQLITE_READ, zTab,zCol,zDb,pParse->zAuthContext
97239 #ifdef SQLITE_USER_AUTHENTICATION
97240 ,db->auth.zAuthUser
@@ -97703,14 +97733,15 @@
97703 return 0;
97704 }
97705 #endif
97706 for(i=OMIT_TEMPDB; i<db->nDb; i++){
97707 int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */
97708 if( zDatabase!=0 && sqlite3StrICmp(zDatabase, db->aDb[j].zName) ) continue;
97709 assert( sqlite3SchemaMutexHeld(db, j, 0) );
97710 p = sqlite3HashFind(&db->aDb[j].pSchema->tblHash, zName);
97711 if( p ) break;
 
97712 }
97713 return p;
97714 }
97715
97716 /*
@@ -97780,11 +97811,11 @@
97780 ){
97781 const char *zDb;
97782 assert( p->pSchema==0 || p->zDatabase==0 );
97783 if( p->pSchema ){
97784 int iDb = sqlite3SchemaToIndex(pParse->db, p->pSchema);
97785 zDb = pParse->db->aDb[iDb].zName;
97786 }else{
97787 zDb = p->zDatabase;
97788 }
97789 return sqlite3LocateTable(pParse, flags, p->zName, zDb);
97790 }
@@ -97808,11 +97839,11 @@
97808 assert( zDb!=0 || sqlite3BtreeHoldsAllMutexes(db) );
97809 for(i=OMIT_TEMPDB; i<db->nDb; i++){
97810 int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */
97811 Schema *pSchema = db->aDb[j].pSchema;
97812 assert( pSchema );
97813 if( zDb && sqlite3StrICmp(zDb, db->aDb[j].zName) ) continue;
97814 assert( sqlite3SchemaMutexHeld(db, j, 0) );
97815 p = sqlite3HashFind(&pSchema->idxHash, zName);
97816 if( p ) break;
97817 }
97818 return p;
@@ -97877,12 +97908,12 @@
97877 SQLITE_PRIVATE void sqlite3CollapseDatabaseArray(sqlite3 *db){
97878 int i, j;
97879 for(i=j=2; i<db->nDb; i++){
97880 struct Db *pDb = &db->aDb[i];
97881 if( pDb->pBt==0 ){
97882 sqlite3DbFree(db, pDb->zName);
97883 pDb->zName = 0;
97884 continue;
97885 }
97886 if( j<i ){
97887 db->aDb[j] = db->aDb[i];
97888 }
@@ -98098,11 +98129,11 @@
98098 SQLITE_PRIVATE int sqlite3FindDbName(sqlite3 *db, const char *zName){
98099 int i = -1; /* Database number */
98100 if( zName ){
98101 Db *pDb;
98102 for(i=(db->nDb-1), pDb=&db->aDb[i]; i>=0; i--, pDb--){
98103 if( 0==sqlite3StrICmp(pDb->zName, zName) ) break;
98104 }
98105 }
98106 return i;
98107 }
98108
@@ -98157,11 +98188,11 @@
98157 if( iDb<0 ){
98158 sqlite3ErrorMsg(pParse, "unknown database %T", pName1);
98159 return -1;
98160 }
98161 }else{
98162 assert( db->init.iDb==0 || db->init.busy );
98163 iDb = db->init.iDb;
98164 *pUnqual = pName1;
98165 }
98166 return iDb;
98167 }
@@ -98268,11 +98299,11 @@
98268 SQLITE_CREATE_TABLE,
98269 SQLITE_CREATE_TEMP_TABLE,
98270 SQLITE_CREATE_VIEW,
98271 SQLITE_CREATE_TEMP_VIEW
98272 };
98273 char *zDb = db->aDb[iDb].zName;
98274 if( sqlite3AuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(isTemp), 0, zDb) ){
98275 goto begin_table_error;
98276 }
98277 if( !isVirtual && sqlite3AuthCheck(pParse, (int)aCode[isTemp+2*isView],
98278 zName, 0, zDb) ){
@@ -98287,11 +98318,11 @@
98287 ** to an sqlite3_declare_vtab() call. In that case only the column names
98288 ** and types will be used, so there is no need to test for namespace
98289 ** collisions.
98290 */
98291 if( !IN_DECLARE_VTAB ){
98292 char *zDb = db->aDb[iDb].zName;
98293 if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){
98294 goto begin_table_error;
98295 }
98296 pTable = sqlite3FindTable(db, zName, zDb);
98297 if( pTable ){
@@ -99380,11 +99411,11 @@
99380 */
99381 sqlite3NestedParse(pParse,
99382 "UPDATE %Q.%s "
99383 "SET type='%s', name=%Q, tbl_name=%Q, rootpage=#%d, sql=%Q "
99384 "WHERE rowid=#%d",
99385 db->aDb[iDb].zName, SCHEMA_TABLE(iDb),
99386 zType,
99387 p->zName,
99388 p->zName,
99389 pParse->regRoot,
99390 zStmt,
@@ -99395,17 +99426,17 @@
99395
99396 #ifndef SQLITE_OMIT_AUTOINCREMENT
99397 /* Check to see if we need to create an sqlite_sequence table for
99398 ** keeping track of autoincrement keys.
99399 */
99400 if( p->tabFlags & TF_Autoincrement ){
99401 Db *pDb = &db->aDb[iDb];
99402 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
99403 if( pDb->pSchema->pSeqTab==0 ){
99404 sqlite3NestedParse(pParse,
99405 "CREATE TABLE %Q.sqlite_sequence(name,seq)",
99406 pDb->zName
99407 );
99408 }
99409 }
99410 #endif
99411
@@ -99715,11 +99746,11 @@
99715 ** is in register NNN. See grammar rules associated with the TK_REGISTER
99716 ** token for additional information.
99717 */
99718 sqlite3NestedParse(pParse,
99719 "UPDATE %Q.%s SET rootpage=%d WHERE #%d AND rootpage=#%d",
99720 pParse->db->aDb[iDb].zName, SCHEMA_TABLE(iDb), iTable, r1, r1);
99721 #endif
99722 sqlite3ReleaseTempReg(pParse, r1);
99723 }
99724
99725 /*
@@ -99791,11 +99822,11 @@
99791 int iDb, /* The database number */
99792 const char *zType, /* "idx" or "tbl" */
99793 const char *zName /* Name of index or table */
99794 ){
99795 int i;
99796 const char *zDbName = pParse->db->aDb[iDb].zName;
99797 for(i=1; i<=4; i++){
99798 char zTab[24];
99799 sqlite3_snprintf(sizeof(zTab),zTab,"sqlite_stat%d",i);
99800 if( sqlite3FindTable(pParse->db, zTab, zDbName) ){
99801 sqlite3NestedParse(pParse,
@@ -99844,11 +99875,11 @@
99844 ** move as a result of the drop (can happen in auto-vacuum mode).
99845 */
99846 if( pTab->tabFlags & TF_Autoincrement ){
99847 sqlite3NestedParse(pParse,
99848 "DELETE FROM %Q.sqlite_sequence WHERE name=%Q",
99849 pDb->zName, pTab->zName
99850 );
99851 }
99852 #endif
99853
99854 /* Drop all SQLITE_MASTER table and index entries that refer to the
@@ -99858,11 +99889,11 @@
99858 ** created in the temp database that refers to a table in another
99859 ** database.
99860 */
99861 sqlite3NestedParse(pParse,
99862 "DELETE FROM %Q.%s WHERE tbl_name=%Q and type!='trigger'",
99863 pDb->zName, SCHEMA_TABLE(iDb), pTab->zName);
99864 if( !isView && !IsVirtual(pTab) ){
99865 destroyTable(pParse, pTab);
99866 }
99867
99868 /* Remove the table entry from SQLite's internal schema and modify
@@ -99912,11 +99943,11 @@
99912 }
99913 #ifndef SQLITE_OMIT_AUTHORIZATION
99914 {
99915 int code;
99916 const char *zTab = SCHEMA_TABLE(iDb);
99917 const char *zDb = db->aDb[iDb].zName;
99918 const char *zArg2 = 0;
99919 if( sqlite3AuthCheck(pParse, SQLITE_DELETE, zTab, 0, zDb)){
99920 goto exit_drop_table;
99921 }
99922 if( isView ){
@@ -100153,11 +100184,11 @@
100153 sqlite3 *db = pParse->db; /* The database connection */
100154 int iDb = sqlite3SchemaToIndex(db, pIndex->pSchema);
100155
100156 #ifndef SQLITE_OMIT_AUTHORIZATION
100157 if( sqlite3AuthCheck(pParse, SQLITE_REINDEX, pIndex->zName, 0,
100158 db->aDb[iDb].zName ) ){
100159 return;
100160 }
100161 #endif
100162
100163 /* Require a write-lock on the table to perform this operation */
@@ -100405,11 +100436,11 @@
100405 if( sqlite3FindTable(db, zName, 0)!=0 ){
100406 sqlite3ErrorMsg(pParse, "there is already a table named %s", zName);
100407 goto exit_create_index;
100408 }
100409 }
100410 if( sqlite3FindIndex(db, zName, pDb->zName)!=0 ){
100411 if( !ifNotExist ){
100412 sqlite3ErrorMsg(pParse, "index %s already exists", zName);
100413 }else{
100414 assert( !db->init.busy );
100415 sqlite3CodeVerifySchema(pParse, iDb);
@@ -100435,11 +100466,11 @@
100435
100436 /* Check for authorization to create an index.
100437 */
100438 #ifndef SQLITE_OMIT_AUTHORIZATION
100439 {
100440 const char *zDb = pDb->zName;
100441 if( sqlite3AuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(iDb), 0, zDb) ){
100442 goto exit_create_index;
100443 }
100444 i = SQLITE_CREATE_INDEX;
100445 if( !OMIT_TEMPDB && iDb==1 ) i = SQLITE_CREATE_TEMP_INDEX;
@@ -100750,11 +100781,11 @@
100750
100751 /* Add an entry in sqlite_master for this index
100752 */
100753 sqlite3NestedParse(pParse,
100754 "INSERT INTO %Q.%s VALUES('index',%Q,%Q,#%d,%Q);",
100755 db->aDb[iDb].zName, SCHEMA_TABLE(iDb),
100756 pIndex->zName,
100757 pTab->zName,
100758 iMem,
100759 zStmt
100760 );
@@ -100884,11 +100915,11 @@
100884 iDb = sqlite3SchemaToIndex(db, pIndex->pSchema);
100885 #ifndef SQLITE_OMIT_AUTHORIZATION
100886 {
100887 int code = SQLITE_DROP_INDEX;
100888 Table *pTab = pIndex->pTable;
100889 const char *zDb = db->aDb[iDb].zName;
100890 const char *zTab = SCHEMA_TABLE(iDb);
100891 if( sqlite3AuthCheck(pParse, SQLITE_DELETE, zTab, 0, zDb) ){
100892 goto exit_drop_index;
100893 }
100894 if( !OMIT_TEMPDB && iDb ) code = SQLITE_DROP_TEMP_INDEX;
@@ -100902,11 +100933,11 @@
100902 v = sqlite3GetVdbe(pParse);
100903 if( v ){
100904 sqlite3BeginWriteOperation(pParse, 1, iDb);
100905 sqlite3NestedParse(pParse,
100906 "DELETE FROM %Q.%s WHERE name=%Q AND type='index'",
100907 db->aDb[iDb].zName, SCHEMA_TABLE(iDb), pIndex->zName
100908 );
100909 sqlite3ClearStatTables(pParse, iDb, "idx", pIndex->zName);
100910 sqlite3ChangeCookie(pParse, iDb);
100911 destroyRootPage(pParse, pIndex->tnum, iDb);
100912 sqlite3VdbeAddOp4(v, OP_DropIndex, iDb, 0, 0, pIndex->zName, 0);
@@ -101447,11 +101478,11 @@
101447 SQLITE_PRIVATE void sqlite3CodeVerifyNamedSchema(Parse *pParse, const char *zDb){
101448 sqlite3 *db = pParse->db;
101449 int i;
101450 for(i=0; i<db->nDb; i++){
101451 Db *pDb = &db->aDb[i];
101452 if( pDb->pBt && (!zDb || 0==sqlite3StrICmp(zDb, pDb->zName)) ){
101453 sqlite3CodeVerifySchema(pParse, i);
101454 }
101455 }
101456 }
101457
@@ -101694,11 +101725,11 @@
101694 }
101695 iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pObjName);
101696 if( iDb<0 ) return;
101697 z = sqlite3NameFromToken(db, pObjName);
101698 if( z==0 ) return;
101699 zDb = db->aDb[iDb].zName;
101700 pTab = sqlite3FindTable(db, z, zDb);
101701 if( pTab ){
101702 reindexTable(pParse, pTab, 0);
101703 sqlite3DbFree(db, z);
101704 return;
@@ -102408,11 +102439,11 @@
102408 pWhere = sqlite3ExprDup(db, pWhere, 0);
102409 pFrom = sqlite3SrcListAppend(db, 0, 0, 0);
102410 if( pFrom ){
102411 assert( pFrom->nSrc==1 );
102412 pFrom->a[0].zName = sqlite3DbStrDup(db, pView->zName);
102413 pFrom->a[0].zDatabase = sqlite3DbStrDup(db, db->aDb[iDb].zName);
102414 assert( pFrom->a[0].pOn==0 );
102415 assert( pFrom->a[0].pUsing==0 );
102416 }
102417 pSel = sqlite3SelectNew(pParse, 0, pFrom, pWhere, 0, 0, 0,
102418 SF_IncludeHidden, 0, 0);
@@ -102595,11 +102626,11 @@
102595 if( sqlite3IsReadOnly(pParse, pTab, (pTrigger?1:0)) ){
102596 goto delete_from_cleanup;
102597 }
102598 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
102599 assert( iDb<db->nDb );
102600 zDb = db->aDb[iDb].zName;
102601 rcauth = sqlite3AuthCheck(pParse, SQLITE_DELETE, pTab->zName, 0, zDb);
102602 assert( rcauth==SQLITE_OK || rcauth==SQLITE_DENY || rcauth==SQLITE_IGNORE );
102603 if( rcauth==SQLITE_DENY ){
102604 goto delete_from_cleanup;
102605 }
@@ -105927,11 +105958,11 @@
105927
105928 /* If foreign-keys are disabled, this function is a no-op. */
105929 if( (db->flags&SQLITE_ForeignKeys)==0 ) return;
105930
105931 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
105932 zDb = db->aDb[iDb].zName;
105933
105934 /* Loop through all the foreign key constraints for which pTab is the
105935 ** child table (the table that the foreign key definition is part of). */
105936 for(pFKey=pTab->pFKey; pFKey; pFKey=pFKey->pNextFrom){
105937 Table *pTo; /* Parent table of foreign key pFKey */
@@ -106667,11 +106698,13 @@
106667
106668 #ifndef SQLITE_OMIT_AUTOINCREMENT
106669 /*
106670 ** Locate or create an AutoincInfo structure associated with table pTab
106671 ** which is in database iDb. Return the register number for the register
106672 ** that holds the maximum rowid.
 
 
106673 **
106674 ** There is at most one AutoincInfo structure per table even if the
106675 ** same table is autoincremented multiple times due to inserts within
106676 ** triggers. A new AutoincInfo structure is created if this is the
106677 ** first use of table pTab. On 2nd and subsequent uses, the original
@@ -106690,11 +106723,13 @@
106690 Parse *pParse, /* Parsing context */
106691 int iDb, /* Index of the database holding pTab */
106692 Table *pTab /* The table we are writing to */
106693 ){
106694 int memId = 0; /* Register holding maximum rowid */
106695 if( pTab->tabFlags & TF_Autoincrement ){
 
 
106696 Parse *pToplevel = sqlite3ParseToplevel(pParse);
106697 AutoincInfo *pInfo;
106698
106699 pInfo = pToplevel->pAinc;
106700 while( pInfo && pInfo->pTab!=pTab ){ pInfo = pInfo->pNext; }
@@ -107014,11 +107049,11 @@
107014 goto insert_cleanup;
107015 }
107016 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
107017 assert( iDb<db->nDb );
107018 pDb = &db->aDb[iDb];
107019 zDb = pDb->zName;
107020 if( sqlite3AuthCheck(pParse, SQLITE_INSERT, pTab->zName, 0, zDb) ){
107021 goto insert_cleanup;
107022 }
107023 withoutRowid = !HasRowid(pTab);
107024
@@ -110972,11 +111007,11 @@
110972 }else{
110973 zRight = sqlite3NameFromToken(db, pValue);
110974 }
110975
110976 assert( pId2 );
110977 zDb = pId2->n>0 ? pDb->zName : 0;
110978 if( sqlite3AuthCheck(pParse, SQLITE_PRAGMA, zLeft, zRight, zDb) ){
110979 goto pragma_out;
110980 }
110981
110982 /* Send an SQLITE_FCNTL_PRAGMA file-control to the underlying VFS
@@ -111825,14 +111860,14 @@
111825 int i;
111826 pParse->nMem = 3;
111827 setAllColumnNames(v, 3, azCol); assert( 3==ArraySize(azCol) );
111828 for(i=0; i<db->nDb; i++){
111829 if( db->aDb[i].pBt==0 ) continue;
111830 assert( db->aDb[i].zName!=0 );
111831 sqlite3VdbeMultiLoad(v, 1, "iss",
111832 i,
111833 db->aDb[i].zName,
111834 sqlite3BtreeGetFilename(db->aDb[i].pBt));
111835 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3);
111836 }
111837 }
111838 break;
@@ -112117,11 +112152,11 @@
112117 /* Do the b-tree integrity checks */
112118 sqlite3VdbeAddOp4(v, OP_IntegrityCk, 2, cnt, 1, (char*)aRoot,P4_INTARRAY);
112119 sqlite3VdbeChangeP5(v, (u8)i);
112120 addr = sqlite3VdbeAddOp1(v, OP_IsNull, 2); VdbeCoverage(v);
112121 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0,
112122 sqlite3MPrintf(db, "*** in database %s ***\n", db->aDb[i].zName),
112123 P4_DYNAMIC);
112124 sqlite3VdbeAddOp3(v, OP_Move, 2, 4, 1);
112125 sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 2);
112126 sqlite3VdbeAddOp2(v, OP_ResultRow, 2, 1);
112127 sqlite3VdbeJumpHere(v, addr);
@@ -112556,19 +112591,19 @@
112556 pParse->nMem = 2;
112557 for(i=0; i<db->nDb; i++){
112558 Btree *pBt;
112559 const char *zState = "unknown";
112560 int j;
112561 if( db->aDb[i].zName==0 ) continue;
112562 pBt = db->aDb[i].pBt;
112563 if( pBt==0 || sqlite3BtreePager(pBt)==0 ){
112564 zState = "closed";
112565 }else if( sqlite3_file_control(db, i ? db->aDb[i].zName : 0,
112566 SQLITE_FCNTL_LOCKSTATE, &j)==SQLITE_OK ){
112567 zState = azLockName[j];
112568 }
112569 sqlite3VdbeMultiLoad(v, 1, "ss", db->aDb[i].zName, zState);
112570 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 2);
112571 }
112572 break;
112573 }
112574 #endif
@@ -112700,10 +112735,11 @@
112700 ** But because db->init.busy is set to 1, no VDBE code is generated
112701 ** or executed. All the parser does is build the internal data
112702 ** structures that describe the table, index, or view.
112703 */
112704 int rc;
 
112705 sqlite3_stmt *pStmt;
112706 TESTONLY(int rcp); /* Return code from sqlite3_prepare() */
112707
112708 assert( db->init.busy );
112709 db->init.iDb = iDb;
@@ -112710,11 +112746,12 @@
112710 db->init.newTnum = sqlite3Atoi(argv[1]);
112711 db->init.orphanTrigger = 0;
112712 TESTONLY(rcp = ) sqlite3_prepare(db, argv[2], -1, &pStmt, 0);
112713 rc = db->errCode;
112714 assert( (rc&0xFF)==(rcp&0xFF) );
112715 db->init.iDb = 0;
 
112716 if( SQLITE_OK!=rc ){
112717 if( db->init.orphanTrigger ){
112718 assert( iDb==1 );
112719 }else{
112720 pData->rc = rc;
@@ -112734,11 +112771,11 @@
112734 ** constraint for a CREATE TABLE. The index should have already
112735 ** been created when we processed the CREATE TABLE. All we have
112736 ** to do here is record the root page number for that index.
112737 */
112738 Index *pIndex;
112739 pIndex = sqlite3FindIndex(db, argv[0], db->aDb[iDb].zName);
112740 if( pIndex==0 ){
112741 /* This can occur if there exists an index on a TEMP table which
112742 ** has the same name as another index on a permanent index. Since
112743 ** the permanent table is hidden by the TEMP table, we can also
112744 ** safely ignore the index on the permanent table.
@@ -112913,11 +112950,11 @@
112913 assert( db->init.busy );
112914 {
112915 char *zSql;
112916 zSql = sqlite3MPrintf(db,
112917 "SELECT name, rootpage, sql FROM \"%w\".%s ORDER BY rowid",
112918 db->aDb[iDb].zName, zMasterName);
112919 #ifndef SQLITE_OMIT_AUTHORIZATION
112920 {
112921 sqlite3_xauth xAuth;
112922 xAuth = db->xAuth;
112923 db->xAuth = 0;
@@ -113188,11 +113225,11 @@
113188 Btree *pBt = db->aDb[i].pBt;
113189 if( pBt ){
113190 assert( sqlite3BtreeHoldsMutex(pBt) );
113191 rc = sqlite3BtreeSchemaLocked(pBt);
113192 if( rc ){
113193 const char *zDb = db->aDb[i].zName;
113194 sqlite3ErrorWithMsg(db, rc, "database schema is locked: %s", zDb);
113195 testcase( db->flags & SQLITE_ReadUncommitted );
113196 goto end_prepare;
113197 }
113198 }
@@ -114944,11 +114981,11 @@
114944 estWidth = pTab->aCol[iCol].szEst;
114945 }
114946 zOrigTab = pTab->zName;
114947 if( pNC->pParse ){
114948 int iDb = sqlite3SchemaToIndex(pNC->pParse->db, pTab->pSchema);
114949 zOrigDb = pNC->pParse->db->aDb[iDb].zName;
114950 }
114951 #else
114952 if( iCol<0 ){
114953 zType = "INTEGER";
114954 }else{
@@ -117900,11 +117937,11 @@
117900 pSub = 0;
117901 if( zTName && sqlite3StrICmp(zTName, zTabName)!=0 ){
117902 continue;
117903 }
117904 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
117905 zSchemaName = iDb>=0 ? db->aDb[iDb].zName : "*";
117906 }
117907 for(j=0; j<pTab->nCol; j++){
117908 char *zName = pTab->aCol[j].zName;
117909 char *zColname; /* The computed column name */
117910 char *zToFree; /* Malloced string that needs to be freed */
@@ -119612,12 +119649,12 @@
119612 iTabDb = sqlite3SchemaToIndex(db, pTab->pSchema);
119613
119614 #ifndef SQLITE_OMIT_AUTHORIZATION
119615 {
119616 int code = SQLITE_CREATE_TRIGGER;
119617 const char *zDb = db->aDb[iTabDb].zName;
119618 const char *zDbTrig = isTemp ? db->aDb[1].zName : zDb;
119619 if( iTabDb==1 || isTemp ) code = SQLITE_CREATE_TEMP_TRIGGER;
119620 if( sqlite3AuthCheck(pParse, code, zName, pTab->zName, zDbTrig) ){
119621 goto trigger_cleanup;
119622 }
119623 if( sqlite3AuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(iTabDb),0,zDb)){
@@ -119707,11 +119744,11 @@
119707 if( v==0 ) goto triggerfinish_cleanup;
119708 sqlite3BeginWriteOperation(pParse, 0, iDb);
119709 z = sqlite3DbStrNDup(db, (char*)pAll->z, pAll->n);
119710 sqlite3NestedParse(pParse,
119711 "INSERT INTO %Q.%s VALUES('trigger',%Q,%Q,0,'CREATE TRIGGER %q')",
119712 db->aDb[iDb].zName, SCHEMA_TABLE(iDb), zName,
119713 pTrig->table, z);
119714 sqlite3DbFree(db, z);
119715 sqlite3ChangeCookie(pParse, iDb);
119716 sqlite3VdbeAddParseSchemaOp(v, iDb,
119717 sqlite3MPrintf(db, "type='trigger' AND name='%q'", zName));
@@ -119896,11 +119933,11 @@
119896 zDb = pName->a[0].zDatabase;
119897 zName = pName->a[0].zName;
119898 assert( zDb!=0 || sqlite3BtreeHoldsAllMutexes(db) );
119899 for(i=OMIT_TEMPDB; i<db->nDb; i++){
119900 int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */
119901 if( zDb && sqlite3StrICmp(db->aDb[j].zName, zDb) ) continue;
119902 assert( sqlite3SchemaMutexHeld(db, j, 0) );
119903 pTrigger = sqlite3HashFind(&(db->aDb[j].pSchema->trigHash), zName);
119904 if( pTrigger ) break;
119905 }
119906 if( !pTrigger ){
@@ -119942,11 +119979,11 @@
119942 assert( pTable );
119943 assert( pTable->pSchema==pTrigger->pSchema || iDb==1 );
119944 #ifndef SQLITE_OMIT_AUTHORIZATION
119945 {
119946 int code = SQLITE_DROP_TRIGGER;
119947 const char *zDb = db->aDb[iDb].zName;
119948 const char *zTab = SCHEMA_TABLE(iDb);
119949 if( iDb==1 ) code = SQLITE_DROP_TEMP_TRIGGER;
119950 if( sqlite3AuthCheck(pParse, code, pTrigger->zName, pTable->zName, zDb) ||
119951 sqlite3AuthCheck(pParse, SQLITE_DELETE, zTab, 0, zDb) ){
119952 return;
@@ -119958,11 +119995,11 @@
119958 */
119959 assert( pTable!=0 );
119960 if( (v = sqlite3GetVdbe(pParse))!=0 ){
119961 sqlite3NestedParse(pParse,
119962 "DELETE FROM %Q.%s WHERE name=%Q AND type='trigger'",
119963 db->aDb[iDb].zName, SCHEMA_TABLE(iDb), pTrigger->zName
119964 );
119965 sqlite3ChangeCookie(pParse, iDb);
119966 sqlite3VdbeAddOp4(v, OP_DropTrigger, iDb, 0, 0, pTrigger->zName, 0);
119967 }
119968 }
@@ -120061,12 +120098,14 @@
120061 if( pSrc ){
120062 assert( pSrc->nSrc>0 );
120063 pSrc->a[pSrc->nSrc-1].zName = sqlite3DbStrDup(db, pStep->zTarget);
120064 iDb = sqlite3SchemaToIndex(db, pStep->pTrig->pSchema);
120065 if( iDb==0 || iDb>=2 ){
 
120066 assert( iDb<db->nDb );
120067 pSrc->a[pSrc->nSrc-1].zDatabase = sqlite3DbStrDup(db, db->aDb[iDb].zName);
 
120068 }
120069 }
120070 return pSrc;
120071 }
120072
@@ -120749,11 +120788,11 @@
120749 #ifndef SQLITE_OMIT_AUTHORIZATION
120750 {
120751 int rc;
120752 rc = sqlite3AuthCheck(pParse, SQLITE_UPDATE, pTab->zName,
120753 j<0 ? "ROWID" : pTab->aCol[j].zName,
120754 db->aDb[iDb].zName);
120755 if( rc==SQLITE_DENY ){
120756 goto update_cleanup;
120757 }else if( rc==SQLITE_IGNORE ){
120758 aXRef[j] = -1;
120759 }
@@ -121351,61 +121390,56 @@
121351 */
121352 /* #include "sqliteInt.h" */
121353 /* #include "vdbeInt.h" */
121354
121355 #if !defined(SQLITE_OMIT_VACUUM) && !defined(SQLITE_OMIT_ATTACH)
121356 /*
121357 ** Finalize a prepared statement. If there was an error, store the
121358 ** text of the error message in *pzErrMsg. Return the result code.
121359 */
121360 static int vacuumFinalize(sqlite3 *db, sqlite3_stmt *pStmt, char **pzErrMsg){
121361 int rc;
121362 rc = sqlite3VdbeFinalize((Vdbe*)pStmt);
121363 if( rc ){
121364 sqlite3SetString(pzErrMsg, db, sqlite3_errmsg(db));
121365 }
121366 return rc;
121367 }
121368
121369 /*
121370 ** Execute zSql on database db. Return an error code.
121371 */
121372 static int execSql(sqlite3 *db, char **pzErrMsg, const char *zSql){
121373 sqlite3_stmt *pStmt;
121374 VVA_ONLY( int rc; )
121375 if( !zSql ){
121376 return SQLITE_NOMEM_BKPT;
 
 
 
 
 
 
 
 
 
 
121377 }
121378 if( SQLITE_OK!=sqlite3_prepare(db, zSql, -1, &pStmt, 0) ){
 
 
121379 sqlite3SetString(pzErrMsg, db, sqlite3_errmsg(db));
121380 return sqlite3_errcode(db);
121381 }
121382 VVA_ONLY( rc = ) sqlite3_step(pStmt);
121383 assert( rc!=SQLITE_ROW || (db->flags&SQLITE_CountRows) );
121384 return vacuumFinalize(db, pStmt, pzErrMsg);
121385 }
121386
121387 /*
121388 ** Execute zSql on database db. The statement returns exactly
121389 ** one column. Execute this as SQL on the same database.
121390 */
121391 static int execExecSql(sqlite3 *db, char **pzErrMsg, const char *zSql){
121392 sqlite3_stmt *pStmt;
121393 int rc;
121394
121395 rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
121396 if( rc!=SQLITE_OK ) return rc;
121397
121398 while( SQLITE_ROW==sqlite3_step(pStmt) ){
121399 rc = execSql(db, pzErrMsg, (char*)sqlite3_column_text(pStmt, 0));
121400 if( rc!=SQLITE_OK ){
121401 vacuumFinalize(db, pStmt, pzErrMsg);
121402 return rc;
121403 }
121404 }
121405
121406 return vacuumFinalize(db, pStmt, pzErrMsg);
121407 }
121408
121409 /*
121410 ** The VACUUM command is used to clean up the database,
121411 ** collapse free space, etc. It is modelled after the VACUUM command
@@ -121434,35 +121468,36 @@
121434 ** not work if other processes are attached to the original database.
121435 ** And a power loss in between deleting the original and renaming the
121436 ** transient would cause the database file to appear to be deleted
121437 ** following reboot.
121438 */
121439 SQLITE_PRIVATE void sqlite3Vacuum(Parse *pParse){
121440 Vdbe *v = sqlite3GetVdbe(pParse);
121441 if( v ){
121442 sqlite3VdbeAddOp2(v, OP_Vacuum, 0, 0);
121443 sqlite3VdbeUsesBtree(v, 0);
 
121444 }
121445 return;
121446 }
121447
121448 /*
121449 ** This routine implements the OP_Vacuum opcode of the VDBE.
121450 */
121451 SQLITE_PRIVATE int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){
121452 int rc = SQLITE_OK; /* Return code from service routines */
121453 Btree *pMain; /* The database being vacuumed */
121454 Btree *pTemp; /* The temporary database we vacuum into */
121455 char *zSql = 0; /* SQL statements */
121456 int saved_flags; /* Saved value of the db->flags */
121457 int saved_nChange; /* Saved value of db->nChange */
121458 int saved_nTotalChange; /* Saved value of db->nTotalChange */
121459 u8 saved_mTrace; /* Saved trace settings */
121460 Db *pDb = 0; /* Database to detach at end of vacuum */
121461 int isMemDb; /* True if vacuuming a :memory: database */
121462 int nRes; /* Bytes of reserved space at the end of each page */
121463 int nDb; /* Number of attached databases */
 
121464
121465 if( !db->autoCommit ){
121466 sqlite3SetString(pzErrMsg, db, "cannot VACUUM from within a transaction");
121467 return SQLITE_ERROR;
121468 }
@@ -121476,15 +121511,17 @@
121476 ** disable CHECK and foreign key constraints. */
121477 saved_flags = db->flags;
121478 saved_nChange = db->nChange;
121479 saved_nTotalChange = db->nTotalChange;
121480 saved_mTrace = db->mTrace;
121481 db->flags |= SQLITE_WriteSchema | SQLITE_IgnoreChecks | SQLITE_PreferBuiltin;
121482 db->flags &= ~(SQLITE_ForeignKeys | SQLITE_ReverseOrder);
 
121483 db->mTrace = 0;
121484
121485 pMain = db->aDb[0].pBt;
 
121486 isMemDb = sqlite3PagerIsMemdb(sqlite3BtreePager(pMain));
121487
121488 /* Attach the temporary database as 'vacuum_db'. The synchronous pragma
121489 ** can be set to 'off' for this file, as it is not recovered if a crash
121490 ** occurs anyway. The integrity of the database is maintained by a
@@ -121498,22 +121535,16 @@
121498 ** empty. Only the journal header is written. Apparently it takes more
121499 ** time to parse and run the PRAGMA to turn journalling off than it does
121500 ** to write the journal header file.
121501 */
121502 nDb = db->nDb;
121503 if( sqlite3TempInMemory(db) ){
121504 zSql = "ATTACH ':memory:' AS vacuum_db;";
121505 }else{
121506 zSql = "ATTACH '' AS vacuum_db;";
121507 }
121508 rc = execSql(db, pzErrMsg, zSql);
121509 if( db->nDb>nDb ){
121510 pDb = &db->aDb[db->nDb-1];
121511 assert( strcmp(pDb->zName,"vacuum_db")==0 );
121512 }
121513 if( rc!=SQLITE_OK ) goto end_of_vacuum;
121514 pTemp = db->aDb[db->nDb-1].pBt;
 
 
 
121515
121516 /* The call to execSql() to attach the temp database has left the file
121517 ** locked (as there was more than one active statement when the transaction
121518 ** to read the schema was concluded. Unlock it here so that this doesn't
121519 ** cause problems for the call to BtreeSetPageSize() below. */
@@ -121530,20 +121561,19 @@
121530 sqlite3CodecGetKey(db, 0, (void**)&zKey, &nKey);
121531 if( nKey ) db->nextPagesize = 0;
121532 }
121533 #endif
121534
121535 sqlite3BtreeSetCacheSize(pTemp, db->aDb[0].pSchema->cache_size);
121536 sqlite3BtreeSetSpillSize(pTemp, sqlite3BtreeSetSpillSize(pMain,0));
121537 rc = execSql(db, pzErrMsg, "PRAGMA vacuum_db.synchronous=OFF");
121538 if( rc!=SQLITE_OK ) goto end_of_vacuum;
121539
121540 /* Begin a transaction and take an exclusive lock on the main database
121541 ** file. This is done before the sqlite3BtreeGetPageSize(pMain) call below,
121542 ** to ensure that we do not try to change the page-size on a WAL database.
121543 */
121544 rc = execSql(db, pzErrMsg, "BEGIN;");
121545 if( rc!=SQLITE_OK ) goto end_of_vacuum;
121546 rc = sqlite3BtreeBeginTrans(pMain, 2);
121547 if( rc!=SQLITE_OK ) goto end_of_vacuum;
121548
121549 /* Do not attempt to change the page size for a WAL database */
@@ -121566,68 +121596,52 @@
121566 #endif
121567
121568 /* Query the schema of the main database. Create a mirror schema
121569 ** in the temporary database.
121570 */
121571 rc = execExecSql(db, pzErrMsg,
121572 "SELECT 'CREATE TABLE vacuum_db.' || substr(sql,14) "
121573 " FROM sqlite_master WHERE type='table' AND name!='sqlite_sequence'"
121574 " AND coalesce(rootpage,1)>0"
 
 
 
 
 
 
 
 
121575 );
121576 if( rc!=SQLITE_OK ) goto end_of_vacuum;
121577 rc = execExecSql(db, pzErrMsg,
121578 "SELECT 'CREATE INDEX vacuum_db.' || substr(sql,14)"
121579 " FROM sqlite_master WHERE sql LIKE 'CREATE INDEX %' ");
121580 if( rc!=SQLITE_OK ) goto end_of_vacuum;
121581 rc = execExecSql(db, pzErrMsg,
121582 "SELECT 'CREATE UNIQUE INDEX vacuum_db.' || substr(sql,21) "
121583 " FROM sqlite_master WHERE sql LIKE 'CREATE UNIQUE INDEX %'");
121584 if( rc!=SQLITE_OK ) goto end_of_vacuum;
121585
121586 /* Loop through the tables in the main database. For each, do
121587 ** an "INSERT INTO vacuum_db.xxx SELECT * FROM main.xxx;" to copy
121588 ** the contents to the temporary database.
121589 */
121590 assert( (db->flags & SQLITE_Vacuum)==0 );
121591 db->flags |= SQLITE_Vacuum;
121592 rc = execExecSql(db, pzErrMsg,
121593 "SELECT 'INSERT INTO vacuum_db.' || quote(name) "
121594 "|| ' SELECT * FROM main.' || quote(name) || ';'"
121595 "FROM main.sqlite_master "
121596 "WHERE type = 'table' AND name!='sqlite_sequence' "
121597 " AND coalesce(rootpage,1)>0"
121598 );
121599 assert( (db->flags & SQLITE_Vacuum)!=0 );
121600 db->flags &= ~SQLITE_Vacuum;
121601 if( rc!=SQLITE_OK ) goto end_of_vacuum;
121602
121603 /* Copy over the sequence table
121604 */
121605 rc = execExecSql(db, pzErrMsg,
121606 "SELECT 'DELETE FROM vacuum_db.' || quote(name) || ';' "
121607 "FROM vacuum_db.sqlite_master WHERE name='sqlite_sequence' "
121608 );
121609 if( rc!=SQLITE_OK ) goto end_of_vacuum;
121610 rc = execExecSql(db, pzErrMsg,
121611 "SELECT 'INSERT INTO vacuum_db.' || quote(name) "
121612 "|| ' SELECT * FROM main.' || quote(name) || ';' "
121613 "FROM vacuum_db.sqlite_master WHERE name=='sqlite_sequence';"
121614 );
121615 if( rc!=SQLITE_OK ) goto end_of_vacuum;
121616
121617
121618 /* Copy the triggers, views, and virtual tables from the main database
121619 ** over to the temporary database. None of these objects has any
121620 ** associated storage, so all we have to do is copy their entries
121621 ** from the SQLITE_MASTER table.
121622 */
121623 rc = execSql(db, pzErrMsg,
121624 "INSERT INTO vacuum_db.sqlite_master "
121625 " SELECT type, name, tbl_name, rootpage, sql"
121626 " FROM main.sqlite_master"
121627 " WHERE type='view' OR type='trigger'"
121628 " OR (type='table' AND rootpage=0)"
121629 );
121630 if( rc ) goto end_of_vacuum;
121631
121632 /* At this point, there is a write transaction open on both the
121633 ** vacuum database and the main database. Assuming no error occurs,
@@ -121677,10 +121691,11 @@
121677 assert( rc==SQLITE_OK );
121678 rc = sqlite3BtreeSetPageSize(pMain, sqlite3BtreeGetPageSize(pTemp), nRes,1);
121679
121680 end_of_vacuum:
121681 /* Restore the original value of db->flags */
 
121682 db->flags = saved_flags;
121683 db->nChange = saved_nChange;
121684 db->nTotalChange = saved_nTotalChange;
121685 db->mTrace = saved_mTrace;
121686 sqlite3BtreeSetPageSize(pMain, -1, -1, 1);
@@ -122055,11 +122070,11 @@
122055 ** sqlite_master table, has already been made by sqlite3StartTable().
122056 ** The second call, to obtain permission to create the table, is made now.
122057 */
122058 if( pTable->azModuleArg ){
122059 sqlite3AuthCheck(pParse, SQLITE_CREATE_VTABLE, pTable->zName,
122060 pTable->azModuleArg[0], pParse->db->aDb[iDb].zName);
122061 }
122062 #endif
122063 }
122064
122065 /*
@@ -122119,11 +122134,11 @@
122119 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
122120 sqlite3NestedParse(pParse,
122121 "UPDATE %Q.%s "
122122 "SET type='table', name=%Q, tbl_name=%Q, rootpage=0, sql=%Q "
122123 "WHERE rowid=#%d",
122124 db->aDb[iDb].zName, SCHEMA_TABLE(iDb),
122125 pTab->zName,
122126 pTab->zName,
122127 zStmt,
122128 pParse->regRowid
122129 );
@@ -122229,11 +122244,11 @@
122229 }
122230 pVTable->db = db;
122231 pVTable->pMod = pMod;
122232
122233 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
122234 pTab->azModuleArg[1] = db->aDb[iDb].zName;
122235
122236 /* Invoke the virtual table constructor */
122237 assert( &db->pVtabCtx );
122238 assert( xConstruct );
122239 sCtx.pTab = pTab;
@@ -122393,11 +122408,11 @@
122393 int rc = SQLITE_OK;
122394 Table *pTab;
122395 Module *pMod;
122396 const char *zMod;
122397
122398 pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zName);
122399 assert( pTab && (pTab->tabFlags & TF_Virtual)!=0 && !pTab->pVTable );
122400
122401 /* Locate the required virtual table module */
122402 zMod = pTab->azModuleArg[0];
122403 pMod = (Module*)sqlite3HashFind(&db->aModule, zMod);
@@ -122517,11 +122532,11 @@
122517 */
122518 SQLITE_PRIVATE int sqlite3VtabCallDestroy(sqlite3 *db, int iDb, const char *zTab){
122519 int rc = SQLITE_OK;
122520 Table *pTab;
122521
122522 pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zName);
122523 if( pTab!=0 && ALWAYS(pTab->pVTable!=0) ){
122524 VTable *p;
122525 int (*xDestroy)(sqlite3_vtab *);
122526 for(p=pTab->pVTable; p; p=p->pNext){
122527 assert( p->pVtab );
@@ -125630,11 +125645,11 @@
125630 */
125631 static int isMatchOfColumn(
125632 Expr *pExpr, /* Test this expression */
125633 unsigned char *peOp2 /* OUT: 0 for MATCH, or else an op2 value */
125634 ){
125635 struct Op2 {
125636 const char *zOp;
125637 unsigned char eOp2;
125638 } aOp[] = {
125639 { "match", SQLITE_INDEX_CONSTRAINT_MATCH },
125640 { "glob", SQLITE_INDEX_CONSTRAINT_GLOB },
@@ -126615,17 +126630,18 @@
126615 ** These routines walk (recursively) an expression tree and generate
126616 ** a bitmask indicating which tables are used in that expression
126617 ** tree.
126618 */
126619 SQLITE_PRIVATE Bitmask sqlite3WhereExprUsage(WhereMaskSet *pMaskSet, Expr *p){
126620 Bitmask mask = 0;
126621 if( p==0 ) return 0;
126622 if( p->op==TK_COLUMN ){
126623 mask = sqlite3WhereGetMask(pMaskSet, p->iTable);
126624 return mask;
126625 }
126626 mask = sqlite3WhereExprUsage(pMaskSet, p->pRight);
 
126627 if( p->pLeft ) mask |= sqlite3WhereExprUsage(pMaskSet, p->pLeft);
126628 if( ExprHasProperty(p, EP_xIsSelect) ){
126629 mask |= exprSelectUsage(pMaskSet, p->x.pSelect);
126630 }else if( p->x.pList ){
126631 mask |= sqlite3WhereExprListUsage(pMaskSet, p->x.pList);
@@ -131868,29 +131884,33 @@
131868 ** N between YY_MIN_SHIFTREDUCE Shift to an arbitrary state then
131869 ** and YY_MAX_SHIFTREDUCE reduce by rule N-YY_MIN_SHIFTREDUCE.
131870 **
131871 ** N between YY_MIN_REDUCE Reduce by rule N-YY_MIN_REDUCE
131872 ** and YY_MAX_REDUCE
131873
131874 ** N == YY_ERROR_ACTION A syntax error has occurred.
131875 **
131876 ** N == YY_ACCEPT_ACTION The parser accepts its input.
131877 **
131878 ** N == YY_NO_ACTION No such action. Denotes unused
131879 ** slots in the yy_action[] table.
131880 **
131881 ** The action table is constructed as a single large table named yy_action[].
131882 ** Given state S and lookahead X, the action is computed as
131883 **
131884 ** yy_action[ yy_shift_ofst[S] + X ]
131885 **
131886 ** If the index value yy_shift_ofst[S]+X is out of range or if the value
131887 ** yy_lookahead[yy_shift_ofst[S]+X] is not equal to X or if yy_shift_ofst[S]
131888 ** is equal to YY_SHIFT_USE_DFLT, it means that the action is not in the table
131889 ** and that yy_default[S] should be used instead.
131890 **
131891 ** The formula above is for computing the action when the lookahead is
 
 
 
 
131892 ** a terminal symbol. If the lookahead is a non-terminal (as occurs after
131893 ** a reduce action) then the yy_reduce_ofst[] array is used in place of
131894 ** the yy_shift_ofst[] array and YY_REDUCE_USE_DFLT is used in place of
131895 ** YY_SHIFT_USE_DFLT.
131896 **
@@ -132211,14 +132231,14 @@
132211 /* 1470 */ 122, 23, 23, 64, 22, 124, 26, 26, 64, 64,
132212 /* 1480 */ 23, 23, 23, 23, 11, 23, 22, 26, 23, 22,
132213 /* 1490 */ 24, 1, 23, 22, 26, 122, 24, 23, 22, 122,
132214 /* 1500 */ 23, 23, 22, 122, 122, 23, 15,
132215 };
132216 #define YY_SHIFT_USE_DFLT (-95)
132217 #define YY_SHIFT_COUNT (442)
132218 #define YY_SHIFT_MIN (-94)
132219 #define YY_SHIFT_MAX (1491)
132220 static const short yy_shift_ofst[] = {
132221 /* 0 */ 40, 564, 869, 577, 725, 725, 725, 725, 690, -19,
132222 /* 10 */ 16, 16, 100, 725, 725, 725, 725, 725, 725, 725,
132223 /* 20 */ 841, 841, 538, 507, 684, 565, 61, 137, 172, 207,
132224 /* 30 */ 242, 277, 312, 347, 382, 424, 424, 424, 424, 424,
@@ -132227,16 +132247,16 @@
132227 /* 60 */ 725, 725, 725, 725, 725, 725, 725, 725, 725, 725,
132228 /* 70 */ 725, 725, 725, 725, 725, 725, 725, 725, 725, 725,
132229 /* 80 */ 725, 725, 725, 725, 821, 725, 725, 725, 725, 725,
132230 /* 90 */ 725, 725, 725, 725, 725, 725, 725, 725, 952, 711,
132231 /* 100 */ 711, 711, 711, 711, 766, 23, 32, 924, 637, 825,
132232 /* 110 */ 837, 837, 924, 73, 183, -51, -95, -95, -95, 501,
132233 /* 120 */ 501, 501, 903, 903, 632, 205, 241, 924, 924, 924,
132234 /* 130 */ 924, 924, 924, 924, 924, 924, 924, 924, 924, 924,
132235 /* 140 */ 924, 924, 924, 924, 924, 924, 924, 192, 1027, 1106,
132236 /* 150 */ 1106, 183, 176, 176, 176, 176, 176, 176, -95, -95,
132237 /* 160 */ -95, 880, -94, -94, 578, 734, 99, 730, 769, 349,
132238 /* 170 */ 924, 924, 924, 924, 924, 924, 924, 924, 924, 924,
132239 /* 180 */ 924, 924, 924, 924, 924, 924, 924, 954, 954, 954,
132240 /* 190 */ 924, 924, 622, 924, 924, 924, -18, 924, 924, 914,
132241 /* 200 */ 924, 924, 924, 924, 924, 924, 924, 924, 924, 924,
132242 /* 210 */ 441, 1020, 1107, 1107, 1107, 569, 45, 217, 510, 423,
@@ -132246,12 +132266,12 @@
132246 /* 250 */ 1297, 1183, 1277, 1285, 1285, 1183, 1176, 1297, 1182, 1250,
132247 /* 260 */ 1176, 1176, 1297, 1311, 1176, 1297, 1176, 1297, 1311, 1234,
132248 /* 270 */ 1234, 1234, 1267, 1311, 1234, 1244, 1234, 1267, 1234, 1234,
132249 /* 280 */ 1232, 1247, 1232, 1247, 1232, 1247, 1232, 1247, 1176, 1334,
132250 /* 290 */ 1176, 1235, 1311, 1318, 1318, 1311, 1248, 1253, 1245, 1249,
132251 /* 300 */ 1183, 1355, 1357, 1368, 1368, 1378, 1378, 1378, 1378, -95,
132252 /* 310 */ -95, -95, -95, -95, -95, -95, -95, 451, 936, 816,
132253 /* 320 */ 888, 1069, 799, 1111, 1197, 1193, 1201, 1202, 1203, 1213,
132254 /* 330 */ 1134, 1117, 1230, 497, 1218, 1219, 1154, 1223, 1115, 1120,
132255 /* 340 */ 1231, 1164, 1160, 1392, 1394, 1376, 1257, 1385, 1307, 1386,
132256 /* 350 */ 1383, 1388, 1292, 1282, 1303, 1294, 1395, 1293, 1403, 1419,
132257 /* 360 */ 1298, 1291, 1389, 1390, 1314, 1372, 1365, 1308, 1430, 1427,
@@ -133200,54 +133220,51 @@
133200
133201 if( stateno>=YY_MIN_REDUCE ) return stateno;
133202 assert( stateno <= YY_SHIFT_COUNT );
133203 do{
133204 i = yy_shift_ofst[stateno];
133205 if( i==YY_SHIFT_USE_DFLT ) return yy_default[stateno];
133206 assert( iLookAhead!=YYNOCODE );
133207 i += iLookAhead;
133208 if( i<0 || i>=YY_ACTTAB_COUNT || yy_lookahead[i]!=iLookAhead ){
133209 if( iLookAhead>0 ){
133210 #ifdef YYFALLBACK
133211 YYCODETYPE iFallback; /* Fallback token */
133212 if( iLookAhead<sizeof(yyFallback)/sizeof(yyFallback[0])
133213 && (iFallback = yyFallback[iLookAhead])!=0 ){
133214 #ifndef NDEBUG
133215 if( yyTraceFILE ){
133216 fprintf(yyTraceFILE, "%sFALLBACK %s => %s\n",
133217 yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]);
133218 }
133219 #endif
133220 assert( yyFallback[iFallback]==0 ); /* Fallback loop must terminate */
133221 iLookAhead = iFallback;
133222 continue;
133223 }
133224 #endif
133225 #ifdef YYWILDCARD
133226 {
133227 int j = i - iLookAhead + YYWILDCARD;
133228 if(
133229 #if YY_SHIFT_MIN+YYWILDCARD<0
133230 j>=0 &&
133231 #endif
133232 #if YY_SHIFT_MAX+YYWILDCARD>=YY_ACTTAB_COUNT
133233 j<YY_ACTTAB_COUNT &&
133234 #endif
133235 yy_lookahead[j]==YYWILDCARD
133236 ){
133237 #ifndef NDEBUG
133238 if( yyTraceFILE ){
133239 fprintf(yyTraceFILE, "%sWILDCARD %s => %s\n",
133240 yyTracePrompt, yyTokenName[iLookAhead],
133241 yyTokenName[YYWILDCARD]);
133242 }
133243 #endif /* NDEBUG */
133244 return yy_action[j];
133245 }
133246 }
 
133247 #endif /* YYWILDCARD */
133248 }
133249 return yy_default[stateno];
133250 }else{
133251 return yy_action[i];
133252 }
133253 }while(1);
@@ -134679,12 +134696,14 @@
134679 break;
134680 case 213: /* cmd ::= DROP INDEX ifexists fullname */
134681 {sqlite3DropIndex(pParse, yymsp[0].minor.yy185, yymsp[-1].minor.yy194);}
134682 break;
134683 case 214: /* cmd ::= VACUUM */
134684 case 215: /* cmd ::= VACUUM nm */ yytestcase(yyruleno==215);
134685 {sqlite3Vacuum(pParse);}
 
 
134686 break;
134687 case 216: /* cmd ::= PRAGMA nm dbnm */
134688 {sqlite3Pragma(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,0,0);}
134689 break;
134690 case 217: /* cmd ::= PRAGMA nm dbnm EQ nmnum */
@@ -136006,18 +136025,30 @@
136006 assert( pParse->pNewTable==0 );
136007 assert( pParse->pNewTrigger==0 );
136008 assert( pParse->nVar==0 );
136009 assert( pParse->nzVar==0 );
136010 assert( pParse->azVar==0 );
136011 while( zSql[i]!=0 ){
136012 assert( i>=0 );
136013 pParse->sLastToken.z = &zSql[i];
136014 pParse->sLastToken.n = sqlite3GetToken((unsigned char*)&zSql[i],&tokenType);
136015 i += pParse->sLastToken.n;
136016 if( i>mxSqlLen ){
136017 pParse->rc = SQLITE_TOOBIG;
136018 break;
 
 
 
 
 
 
 
 
 
 
 
 
136019 }
136020 if( tokenType>=TK_SPACE ){
136021 assert( tokenType==TK_SPACE || tokenType==TK_ILLEGAL );
136022 if( db->u1.isInterrupted ){
136023 pParse->rc = SQLITE_INTERRUPT;
@@ -136034,19 +136065,10 @@
136034 if( pParse->rc!=SQLITE_OK || db->mallocFailed ) break;
136035 }
136036 }
136037 assert( nErr==0 );
136038 pParse->zTail = &zSql[i];
136039 if( pParse->rc==SQLITE_OK && db->mallocFailed==0 ){
136040 assert( zSql[i]==0 );
136041 if( lastTokenParsed!=TK_SEMI ){
136042 sqlite3Parser(pEngine, TK_SEMI, pParse->sLastToken, pParse);
136043 }
136044 if( pParse->rc==SQLITE_OK && db->mallocFailed==0 ){
136045 sqlite3Parser(pEngine, 0, pParse->sLastToken, pParse);
136046 }
136047 }
136048 #ifdef YYTRACKMAXSTACKDEPTH
136049 sqlite3_mutex_enter(sqlite3MallocMutex());
136050 sqlite3StatusHighwater(SQLITE_STATUS_PARSER_STACK,
136051 sqlite3ParserStackPeak(pEngine)
136052 );
@@ -137282,10 +137304,15 @@
137282 SQLITE_API int SQLITE_CDECL sqlite3_db_config(sqlite3 *db, int op, ...){
137283 va_list ap;
137284 int rc;
137285 va_start(ap, op);
137286 switch( op ){
 
 
 
 
 
137287 case SQLITE_DBCONFIG_LOOKASIDE: {
137288 void *pBuf = va_arg(ap, void*); /* IMP: R-26835-10964 */
137289 int sz = va_arg(ap, int); /* IMP: R-47871-25994 */
137290 int cnt = va_arg(ap, int); /* IMP: R-04460-53386 */
137291 rc = setupLookaside(db, pBuf, sz, cnt);
@@ -139425,13 +139452,13 @@
139425 db->aDb[1].pSchema = sqlite3SchemaGet(db, 0);
139426
139427 /* The default safety_level for the main database is FULL; for the temp
139428 ** database it is OFF. This matches the pager layer defaults.
139429 */
139430 db->aDb[0].zName = "main";
139431 db->aDb[0].safety_level = SQLITE_DEFAULT_SYNCHRONOUS+1;
139432 db->aDb[1].zName = "temp";
139433 db->aDb[1].safety_level = PAGER_SYNCHRONOUS_OFF;
139434
139435 db->magic = SQLITE_MAGIC_OPEN;
139436 if( db->mallocFailed ){
139437 goto opendb_out;
@@ -140388,11 +140415,11 @@
140388 */
140389 SQLITE_PRIVATE Btree *sqlite3DbNameToBtree(sqlite3 *db, const char *zDbName){
140390 int i;
140391 for(i=0; i<db->nDb; i++){
140392 if( db->aDb[i].pBt
140393 && (zDbName==0 || sqlite3StrICmp(zDbName, db->aDb[i].zName)==0)
140394 ){
140395 return db->aDb[i].pBt;
140396 }
140397 }
140398 return 0;
@@ -164754,19 +164781,25 @@
164754 /*
164755 ** Open an RBU handle to perform an RBU vacuum on database file zTarget.
164756 ** An RBU vacuum is similar to SQLite's built-in VACUUM command, except
164757 ** that it can be suspended and resumed like an RBU update.
164758 **
164759 ** The second argument to this function, which may not be NULL, identifies
164760 ** a database in which to store the state of the RBU vacuum operation if
164761 ** it is suspended. The first time sqlite3rbu_vacuum() is called, to start
164762 ** an RBU vacuum operation, the state database should either not exist or
164763 ** be empty (contain no tables). If an RBU vacuum is suspended by calling
164764 ** sqlite3rbu_close() on the RBU handle before sqlite3rbu_step() has
164765 ** returned SQLITE_DONE, the vacuum state is stored in the state database.
164766 ** The vacuum can be resumed by calling this function to open a new RBU
164767 ** handle specifying the same target and state databases.
 
 
 
 
 
 
164768 **
164769 ** This function does not delete the state database after an RBU vacuum
164770 ** is completed, even if it created it. However, if the call to
164771 ** sqlite3rbu_close() returns any value other than SQLITE_OK, the contents
164772 ** of the state tables within the state database are zeroed. This way,
@@ -167255,19 +167288,22 @@
167255 /*
167256 ** Open the database handle and attach the RBU database as "rbu". If an
167257 ** error occurs, leave an error code and message in the RBU handle.
167258 */
167259 static void rbuOpenDatabase(sqlite3rbu *p){
167260 assert( p->rc==SQLITE_OK );
167261 assert( p->dbMain==0 && p->dbRbu==0 );
167262 assert( rbuIsVacuum(p) || p->zTarget!=0 );
167263
167264 /* Open the RBU database */
167265 p->dbRbu = rbuOpenDbhandle(p, p->zRbu, 1);
167266
167267 if( p->rc==SQLITE_OK && rbuIsVacuum(p) ){
167268 sqlite3_file_control(p->dbRbu, "main", SQLITE_FCNTL_RBUCNT, (void*)p);
 
 
 
 
167269 }
167270
167271 /* If using separate RBU and state databases, attach the state database to
167272 ** the RBU db handle now. */
167273 if( p->zState ){
@@ -168398,12 +168434,11 @@
168398 const char *zState
168399 ){
168400 sqlite3rbu *p;
168401 size_t nTarget = zTarget ? strlen(zTarget) : 0;
168402 size_t nRbu = strlen(zRbu);
168403 size_t nState = zState ? strlen(zState) : 0;
168404 size_t nByte = sizeof(sqlite3rbu) + nTarget+1 + nRbu+1+ nState+1;
168405
168406 p = (sqlite3rbu*)sqlite3_malloc64(nByte);
168407 if( p ){
168408 RbuState *pState = 0;
168409
@@ -168421,12 +168456,11 @@
168421 }
168422 p->zRbu = pCsr;
168423 memcpy(p->zRbu, zRbu, nRbu+1);
168424 pCsr += nRbu+1;
168425 if( zState ){
168426 p->zState = pCsr;
168427 memcpy(p->zState, zState, nState+1);
168428 }
168429 rbuOpenDatabase(p);
168430 }
168431
168432 if( p->rc==SQLITE_OK ){
@@ -168531,19 +168565,34 @@
168531 rbuFreeState(pState);
168532 }
168533
168534 return p;
168535 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
168536
168537 /*
168538 ** Open and return a new RBU handle.
168539 */
168540 SQLITE_API sqlite3rbu *SQLITE_STDCALL sqlite3rbu_open(
168541 const char *zTarget,
168542 const char *zRbu,
168543 const char *zState
168544 ){
 
168545 /* TODO: Check that zTarget and zRbu are non-NULL */
168546 return openRbuHandle(zTarget, zRbu, zState);
168547 }
168548
168549 /*
@@ -168551,10 +168600,11 @@
168551 */
168552 SQLITE_API sqlite3rbu *SQLITE_STDCALL sqlite3rbu_vacuum(
168553 const char *zTarget,
168554 const char *zState
168555 ){
 
168556 /* TODO: Check that both arguments are non-NULL */
168557 return openRbuHandle(0, zTarget, zState);
168558 }
168559
168560 /*
@@ -168628,10 +168678,11 @@
168628 sqlite3_free(p->aFrame);
168629
168630 rbuEditErrmsg(p);
168631 rc = p->rc;
168632 *pzErrmsg = p->zErrmsg;
 
168633 sqlite3_free(p);
168634 }else{
168635 rc = SQLITE_NOMEM;
168636 *pzErrmsg = 0;
168637 }
@@ -170239,11 +170290,11 @@
170239 zSql = sqlite3_mprintf(
170240 "SELECT 'sqlite_master' AS name, 1 AS rootpage, 'table' AS type"
170241 " UNION ALL "
170242 "SELECT name, rootpage, type"
170243 " FROM \"%w\".%s WHERE rootpage!=0"
170244 " ORDER BY name", pTab->db->aDb[pCsr->iDb].zName, zMaster);
170245 if( zSql==0 ){
170246 return SQLITE_NOMEM_BKPT;
170247 }else{
170248 rc = sqlite3_prepare_v2(pTab->db, zSql, -1, &pCsr->pStmt, 0);
170249 sqlite3_free(zSql);
@@ -170293,11 +170344,11 @@
170293 sqlite3_result_int(ctx, pCsr->szPage);
170294 break;
170295 default: { /* schema */
170296 sqlite3 *db = sqlite3_context_db_handle(ctx);
170297 int iDb = pCsr->iDb;
170298 sqlite3_result_text(ctx, db->aDb[iDb].zName, -1, SQLITE_STATIC);
170299 break;
170300 }
170301 }
170302 return SQLITE_OK;
170303 }
@@ -178530,10 +178581,11 @@
178530 static void sqlite3Fts5ParseNearsetFree(Fts5ExprNearset*);
178531 static void sqlite3Fts5ParseNodeFree(Fts5ExprNode*);
178532
178533 static void sqlite3Fts5ParseSetDistance(Fts5Parse*, Fts5ExprNearset*, Fts5Token*);
178534 static void sqlite3Fts5ParseSetColset(Fts5Parse*, Fts5ExprNearset*, Fts5Colset*);
 
178535 static void sqlite3Fts5ParseFinished(Fts5Parse *pParse, Fts5ExprNode *p);
178536 static void sqlite3Fts5ParseNear(Fts5Parse *pParse, Fts5Token*);
178537
178538 /*
178539 ** End of interface to code in fts5_expr.c.
@@ -178587,16 +178639,17 @@
178587 #define FTS5_NOT 3
178588 #define FTS5_TERM 4
178589 #define FTS5_COLON 5
178590 #define FTS5_LP 6
178591 #define FTS5_RP 7
178592 #define FTS5_LCP 8
178593 #define FTS5_RCP 9
178594 #define FTS5_STRING 10
178595 #define FTS5_COMMA 11
178596 #define FTS5_PLUS 12
178597 #define FTS5_STAR 13
 
178598
178599 /*
178600 ** 2000-05-29
178601 **
178602 ** The author disclaims copyright to this source code. In place of
@@ -178706,39 +178759,39 @@
178706 #ifndef INTERFACE
178707 # define INTERFACE 1
178708 #endif
178709 /************* Begin control #defines *****************************************/
178710 #define fts5YYCODETYPE unsigned char
178711 #define fts5YYNOCODE 27
178712 #define fts5YYACTIONTYPE unsigned char
178713 #define sqlite3Fts5ParserFTS5TOKENTYPE Fts5Token
178714 typedef union {
178715 int fts5yyinit;
178716 sqlite3Fts5ParserFTS5TOKENTYPE fts5yy0;
178717 Fts5Colset* fts5yy3;
178718 Fts5ExprPhrase* fts5yy11;
178719 Fts5ExprNode* fts5yy18;
178720 int fts5yy20;
178721 Fts5ExprNearset* fts5yy26;
178722 } fts5YYMINORTYPE;
178723 #ifndef fts5YYSTACKDEPTH
178724 #define fts5YYSTACKDEPTH 100
178725 #endif
178726 #define sqlite3Fts5ParserARG_SDECL Fts5Parse *pParse;
178727 #define sqlite3Fts5ParserARG_PDECL ,Fts5Parse *pParse
178728 #define sqlite3Fts5ParserARG_FETCH Fts5Parse *pParse = fts5yypParser->pParse
178729 #define sqlite3Fts5ParserARG_STORE fts5yypParser->pParse = pParse
178730 #define fts5YYNSTATE 26
178731 #define fts5YYNRULE 24
178732 #define fts5YY_MAX_SHIFT 25
178733 #define fts5YY_MIN_SHIFTREDUCE 40
178734 #define fts5YY_MAX_SHIFTREDUCE 63
178735 #define fts5YY_MIN_REDUCE 64
178736 #define fts5YY_MAX_REDUCE 87
178737 #define fts5YY_ERROR_ACTION 88
178738 #define fts5YY_ACCEPT_ACTION 89
178739 #define fts5YY_NO_ACTION 90
178740 /************* End control #defines *******************************************/
178741
178742 /* Define the fts5yytestcase() macro to be a no-op if is not already defined
178743 ** otherwise.
178744 **
@@ -178766,29 +178819,33 @@
178766 ** N between fts5YY_MIN_SHIFTREDUCE Shift to an arbitrary state then
178767 ** and fts5YY_MAX_SHIFTREDUCE reduce by rule N-fts5YY_MIN_SHIFTREDUCE.
178768 **
178769 ** N between fts5YY_MIN_REDUCE Reduce by rule N-fts5YY_MIN_REDUCE
178770 ** and fts5YY_MAX_REDUCE
178771
178772 ** N == fts5YY_ERROR_ACTION A syntax error has occurred.
178773 **
178774 ** N == fts5YY_ACCEPT_ACTION The parser accepts its input.
178775 **
178776 ** N == fts5YY_NO_ACTION No such action. Denotes unused
178777 ** slots in the fts5yy_action[] table.
178778 **
178779 ** The action table is constructed as a single large table named fts5yy_action[].
178780 ** Given state S and lookahead X, the action is computed as
178781 **
178782 ** fts5yy_action[ fts5yy_shift_ofst[S] + X ]
178783 **
178784 ** If the index value fts5yy_shift_ofst[S]+X is out of range or if the value
178785 ** fts5yy_lookahead[fts5yy_shift_ofst[S]+X] is not equal to X or if fts5yy_shift_ofst[S]
178786 ** is equal to fts5YY_SHIFT_USE_DFLT, it means that the action is not in the table
178787 ** and that fts5yy_default[S] should be used instead.
178788 **
178789 ** The formula above is for computing the action when the lookahead is
 
 
 
 
178790 ** a terminal symbol. If the lookahead is a non-terminal (as occurs after
178791 ** a reduce action) then the fts5yy_reduce_ofst[] array is used in place of
178792 ** the fts5yy_shift_ofst[] array and fts5YY_REDUCE_USE_DFLT is used in place of
178793 ** fts5YY_SHIFT_USE_DFLT.
178794 **
@@ -178802,52 +178859,54 @@
178802 ** fts5yy_reduce_ofst[] For each state, the offset into fts5yy_action for
178803 ** shifting non-terminals after a reduce.
178804 ** fts5yy_default[] Default action for each state.
178805 **
178806 *********** Begin parsing tables **********************************************/
178807 #define fts5YY_ACTTAB_COUNT (78)
178808 static const fts5YYACTIONTYPE fts5yy_action[] = {
178809 /* 0 */ 89, 15, 46, 5, 48, 24, 12, 19, 23, 14,
178810 /* 10 */ 46, 5, 48, 24, 20, 21, 23, 43, 46, 5,
178811 /* 20 */ 48, 24, 6, 18, 23, 17, 46, 5, 48, 24,
178812 /* 30 */ 75, 7, 23, 25, 46, 5, 48, 24, 62, 47,
178813 /* 40 */ 23, 48, 24, 7, 11, 23, 9, 3, 4, 2,
178814 /* 50 */ 62, 50, 52, 44, 64, 3, 4, 2, 49, 4,
178815 /* 60 */ 2, 1, 23, 11, 16, 9, 12, 2, 10, 61,
178816 /* 70 */ 53, 59, 62, 60, 22, 13, 55, 8,
 
178817 };
178818 static const fts5YYCODETYPE fts5yy_lookahead[] = {
178819 /* 0 */ 15, 16, 17, 18, 19, 20, 10, 11, 23, 16,
178820 /* 10 */ 17, 18, 19, 20, 23, 24, 23, 16, 17, 18,
178821 /* 20 */ 19, 20, 22, 23, 23, 16, 17, 18, 19, 20,
178822 /* 30 */ 5, 6, 23, 16, 17, 18, 19, 20, 13, 17,
178823 /* 40 */ 23, 19, 20, 6, 8, 23, 10, 1, 2, 3,
178824 /* 50 */ 13, 9, 10, 7, 0, 1, 2, 3, 19, 2,
178825 /* 60 */ 3, 6, 23, 8, 21, 10, 10, 3, 10, 25,
178826 /* 70 */ 10, 10, 13, 25, 12, 10, 7, 5,
178827 };
178828 #define fts5YY_SHIFT_USE_DFLT (-5)
178829 #define fts5YY_SHIFT_COUNT (25)
178830 #define fts5YY_SHIFT_MIN (-4)
178831 #define fts5YY_SHIFT_MAX (72)
178832 static const signed char fts5yy_shift_ofst[] = {
178833 /* 0 */ 55, 55, 55, 55, 55, 36, -4, 56, 58, 25,
178834 /* 10 */ 37, 60, 59, 59, 46, 54, 42, 57, 62, 61,
178835 /* 20 */ 62, 69, 65, 62, 72, 64,
178836 };
178837 #define fts5YY_REDUCE_USE_DFLT (-16)
178838 #define fts5YY_REDUCE_COUNT (13)
178839 #define fts5YY_REDUCE_MIN (-15)
178840 #define fts5YY_REDUCE_MAX (48)
 
178841 static const signed char fts5yy_reduce_ofst[] = {
178842 /* 0 */ -15, -7, 1, 9, 17, 22, -9, 0, 39, 44,
178843 /* 10 */ 44, 43, 44, 48,
178844 };
178845 static const fts5YYACTIONTYPE fts5yy_default[] = {
178846 /* 0 */ 88, 88, 88, 88, 88, 69, 82, 88, 88, 87,
178847 /* 10 */ 87, 88, 87, 87, 88, 88, 88, 66, 80, 88,
178848 /* 20 */ 81, 88, 88, 78, 88, 65,
178849 };
178850 /********** End of lemon-generated parsing tables *****************************/
178851
178852 /* The next table maps tokens (terminal symbols) into fallback tokens.
178853 ** If a construct like the following:
@@ -178950,15 +179009,15 @@
178950 /* For tracing shifts, the names of all terminals and nonterminals
178951 ** are required. The following table supplies these names */
178952 static const char *const fts5yyTokenName[] = {
178953 "$", "OR", "AND", "NOT",
178954 "TERM", "COLON", "LP", "RP",
178955 "LCP", "RCP", "STRING", "COMMA",
178956 "PLUS", "STAR", "error", "input",
178957 "expr", "cnearset", "exprlist", "nearset",
178958 "colset", "colsetlist", "nearphrases", "phrase",
178959 "neardist_opt", "star_opt",
178960 };
178961 #endif /* NDEBUG */
178962
178963 #ifndef NDEBUG
178964 /* For tracing reduce actions, the names of all rules are required.
@@ -178972,24 +179031,26 @@
178972 /* 5 */ "expr ::= exprlist",
178973 /* 6 */ "exprlist ::= cnearset",
178974 /* 7 */ "exprlist ::= exprlist cnearset",
178975 /* 8 */ "cnearset ::= nearset",
178976 /* 9 */ "cnearset ::= colset COLON nearset",
178977 /* 10 */ "colset ::= LCP colsetlist RCP",
178978 /* 11 */ "colset ::= STRING",
178979 /* 12 */ "colsetlist ::= colsetlist STRING",
178980 /* 13 */ "colsetlist ::= STRING",
178981 /* 14 */ "nearset ::= phrase",
178982 /* 15 */ "nearset ::= STRING LP nearphrases neardist_opt RP",
178983 /* 16 */ "nearphrases ::= phrase",
178984 /* 17 */ "nearphrases ::= nearphrases phrase",
178985 /* 18 */ "neardist_opt ::=",
178986 /* 19 */ "neardist_opt ::= COMMA STRING",
178987 /* 20 */ "phrase ::= phrase PLUS STRING star_opt",
178988 /* 21 */ "phrase ::= STRING star_opt",
178989 /* 22 */ "star_opt ::= STAR",
178990 /* 23 */ "star_opt ::=",
 
 
178991 };
178992 #endif /* NDEBUG */
178993
178994
178995 #if fts5YYSTACKDEPTH<=0
@@ -179095,37 +179156,37 @@
179095 ** Note: during a reduce, the only symbols destroyed are those
179096 ** which appear on the RHS of the rule, but which are *not* used
179097 ** inside the C code.
179098 */
179099 /********* Begin destructor definitions ***************************************/
179100 case 15: /* input */
179101 {
179102 (void)pParse;
179103 }
179104 break;
179105 case 16: /* expr */
179106 case 17: /* cnearset */
179107 case 18: /* exprlist */
179108 {
179109 sqlite3Fts5ParseNodeFree((fts5yypminor->fts5yy18));
179110 }
179111 break;
179112 case 19: /* nearset */
179113 case 22: /* nearphrases */
179114 {
179115 sqlite3Fts5ParseNearsetFree((fts5yypminor->fts5yy26));
179116 }
179117 break;
179118 case 20: /* colset */
179119 case 21: /* colsetlist */
179120 {
179121 sqlite3_free((fts5yypminor->fts5yy3));
179122 }
179123 break;
179124 case 23: /* phrase */
179125 {
179126 sqlite3Fts5ParsePhraseFree((fts5yypminor->fts5yy11));
179127 }
179128 break;
179129 /********* End destructor definitions *****************************************/
179130 default: break; /* If no destructor action specified: do nothing */
179131 }
@@ -179198,54 +179259,51 @@
179198
179199 if( stateno>=fts5YY_MIN_REDUCE ) return stateno;
179200 assert( stateno <= fts5YY_SHIFT_COUNT );
179201 do{
179202 i = fts5yy_shift_ofst[stateno];
179203 if( i==fts5YY_SHIFT_USE_DFLT ) return fts5yy_default[stateno];
179204 assert( iLookAhead!=fts5YYNOCODE );
179205 i += iLookAhead;
179206 if( i<0 || i>=fts5YY_ACTTAB_COUNT || fts5yy_lookahead[i]!=iLookAhead ){
179207 if( iLookAhead>0 ){
179208 #ifdef fts5YYFALLBACK
179209 fts5YYCODETYPE iFallback; /* Fallback token */
179210 if( iLookAhead<sizeof(fts5yyFallback)/sizeof(fts5yyFallback[0])
179211 && (iFallback = fts5yyFallback[iLookAhead])!=0 ){
179212 #ifndef NDEBUG
179213 if( fts5yyTraceFILE ){
179214 fprintf(fts5yyTraceFILE, "%sFALLBACK %s => %s\n",
179215 fts5yyTracePrompt, fts5yyTokenName[iLookAhead], fts5yyTokenName[iFallback]);
179216 }
179217 #endif
179218 assert( fts5yyFallback[iFallback]==0 ); /* Fallback loop must terminate */
179219 iLookAhead = iFallback;
179220 continue;
179221 }
179222 #endif
179223 #ifdef fts5YYWILDCARD
179224 {
179225 int j = i - iLookAhead + fts5YYWILDCARD;
179226 if(
179227 #if fts5YY_SHIFT_MIN+fts5YYWILDCARD<0
179228 j>=0 &&
179229 #endif
179230 #if fts5YY_SHIFT_MAX+fts5YYWILDCARD>=fts5YY_ACTTAB_COUNT
179231 j<fts5YY_ACTTAB_COUNT &&
179232 #endif
179233 fts5yy_lookahead[j]==fts5YYWILDCARD
179234 ){
179235 #ifndef NDEBUG
179236 if( fts5yyTraceFILE ){
179237 fprintf(fts5yyTraceFILE, "%sWILDCARD %s => %s\n",
179238 fts5yyTracePrompt, fts5yyTokenName[iLookAhead],
179239 fts5yyTokenName[fts5YYWILDCARD]);
179240 }
179241 #endif /* NDEBUG */
179242 return fts5yy_action[j];
179243 }
179244 }
 
179245 #endif /* fts5YYWILDCARD */
179246 }
179247 return fts5yy_default[stateno];
179248 }else{
179249 return fts5yy_action[i];
179250 }
179251 }while(1);
@@ -179368,34 +179426,36 @@
179368 */
179369 static const struct {
179370 fts5YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */
179371 unsigned char nrhs; /* Number of right-hand side symbols in the rule */
179372 } fts5yyRuleInfo[] = {
179373 { 15, 1 },
179374 { 16, 3 },
179375 { 16, 3 },
179376 { 16, 3 },
179377 { 16, 3 },
179378 { 16, 1 },
 
 
 
 
 
 
 
179379 { 18, 1 },
179380 { 18, 2 },
179381 { 17, 1 },
179382 { 17, 3 },
179383 { 20, 3 },
179384 { 20, 1 },
179385 { 21, 2 },
179386 { 21, 1 },
179387 { 19, 1 },
179388 { 19, 5 },
179389 { 22, 1 },
179390 { 22, 2 },
179391 { 24, 0 },
179392 { 24, 2 },
179393 { 23, 4 },
179394 { 23, 2 },
179395 { 25, 1 },
179396 { 25, 0 },
 
 
 
 
 
179397 };
179398
179399 static void fts5yy_accept(fts5yyParser*); /* Forward Declaration */
179400
179401 /*
@@ -179456,124 +179516,135 @@
179456 ** break;
179457 */
179458 /********** Begin reduce actions **********************************************/
179459 fts5YYMINORTYPE fts5yylhsminor;
179460 case 0: /* input ::= expr */
179461 { sqlite3Fts5ParseFinished(pParse, fts5yymsp[0].minor.fts5yy18); }
179462 break;
179463 case 1: /* expr ::= expr AND expr */
179464 {
179465 fts5yylhsminor.fts5yy18 = sqlite3Fts5ParseNode(pParse, FTS5_AND, fts5yymsp[-2].minor.fts5yy18, fts5yymsp[0].minor.fts5yy18, 0);
179466 }
179467 fts5yymsp[-2].minor.fts5yy18 = fts5yylhsminor.fts5yy18;
179468 break;
179469 case 2: /* expr ::= expr OR expr */
179470 {
179471 fts5yylhsminor.fts5yy18 = sqlite3Fts5ParseNode(pParse, FTS5_OR, fts5yymsp[-2].minor.fts5yy18, fts5yymsp[0].minor.fts5yy18, 0);
179472 }
179473 fts5yymsp[-2].minor.fts5yy18 = fts5yylhsminor.fts5yy18;
179474 break;
179475 case 3: /* expr ::= expr NOT expr */
179476 {
179477 fts5yylhsminor.fts5yy18 = sqlite3Fts5ParseNode(pParse, FTS5_NOT, fts5yymsp[-2].minor.fts5yy18, fts5yymsp[0].minor.fts5yy18, 0);
179478 }
179479 fts5yymsp[-2].minor.fts5yy18 = fts5yylhsminor.fts5yy18;
179480 break;
179481 case 4: /* expr ::= LP expr RP */
179482 {fts5yymsp[-2].minor.fts5yy18 = fts5yymsp[-1].minor.fts5yy18;}
179483 break;
179484 case 5: /* expr ::= exprlist */
179485 case 6: /* exprlist ::= cnearset */ fts5yytestcase(fts5yyruleno==6);
179486 {fts5yylhsminor.fts5yy18 = fts5yymsp[0].minor.fts5yy18;}
179487 fts5yymsp[0].minor.fts5yy18 = fts5yylhsminor.fts5yy18;
179488 break;
179489 case 7: /* exprlist ::= exprlist cnearset */
179490 {
179491 fts5yylhsminor.fts5yy18 = sqlite3Fts5ParseImplicitAnd(pParse, fts5yymsp[-1].minor.fts5yy18, fts5yymsp[0].minor.fts5yy18);
179492 }
179493 fts5yymsp[-1].minor.fts5yy18 = fts5yylhsminor.fts5yy18;
179494 break;
179495 case 8: /* cnearset ::= nearset */
179496 {
179497 fts5yylhsminor.fts5yy18 = sqlite3Fts5ParseNode(pParse, FTS5_STRING, 0, 0, fts5yymsp[0].minor.fts5yy26);
179498 }
179499 fts5yymsp[0].minor.fts5yy18 = fts5yylhsminor.fts5yy18;
179500 break;
179501 case 9: /* cnearset ::= colset COLON nearset */
179502 {
179503 sqlite3Fts5ParseSetColset(pParse, fts5yymsp[0].minor.fts5yy26, fts5yymsp[-2].minor.fts5yy3);
179504 fts5yylhsminor.fts5yy18 = sqlite3Fts5ParseNode(pParse, FTS5_STRING, 0, 0, fts5yymsp[0].minor.fts5yy26);
179505 }
179506 fts5yymsp[-2].minor.fts5yy18 = fts5yylhsminor.fts5yy18;
179507 break;
179508 case 10: /* colset ::= LCP colsetlist RCP */
179509 { fts5yymsp[-2].minor.fts5yy3 = fts5yymsp[-1].minor.fts5yy3; }
179510 break;
179511 case 11: /* colset ::= STRING */
179512 {
179513 fts5yylhsminor.fts5yy3 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
179514 }
179515 fts5yymsp[0].minor.fts5yy3 = fts5yylhsminor.fts5yy3;
179516 break;
179517 case 12: /* colsetlist ::= colsetlist STRING */
179518 {
179519 fts5yylhsminor.fts5yy3 = sqlite3Fts5ParseColset(pParse, fts5yymsp[-1].minor.fts5yy3, &fts5yymsp[0].minor.fts5yy0); }
179520 fts5yymsp[-1].minor.fts5yy3 = fts5yylhsminor.fts5yy3;
179521 break;
179522 case 13: /* colsetlist ::= STRING */
179523 {
179524 fts5yylhsminor.fts5yy3 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
179525 }
179526 fts5yymsp[0].minor.fts5yy3 = fts5yylhsminor.fts5yy3;
179527 break;
179528 case 14: /* nearset ::= phrase */
179529 { fts5yylhsminor.fts5yy26 = sqlite3Fts5ParseNearset(pParse, 0, fts5yymsp[0].minor.fts5yy11); }
179530 fts5yymsp[0].minor.fts5yy26 = fts5yylhsminor.fts5yy26;
179531 break;
179532 case 15: /* nearset ::= STRING LP nearphrases neardist_opt RP */
 
 
 
 
 
 
 
 
 
 
 
179533 {
179534 sqlite3Fts5ParseNear(pParse, &fts5yymsp[-4].minor.fts5yy0);
179535 sqlite3Fts5ParseSetDistance(pParse, fts5yymsp[-2].minor.fts5yy26, &fts5yymsp[-1].minor.fts5yy0);
179536 fts5yylhsminor.fts5yy26 = fts5yymsp[-2].minor.fts5yy26;
179537 }
179538 fts5yymsp[-4].minor.fts5yy26 = fts5yylhsminor.fts5yy26;
179539 break;
179540 case 16: /* nearphrases ::= phrase */
179541 {
179542 fts5yylhsminor.fts5yy26 = sqlite3Fts5ParseNearset(pParse, 0, fts5yymsp[0].minor.fts5yy11);
179543 }
179544 fts5yymsp[0].minor.fts5yy26 = fts5yylhsminor.fts5yy26;
179545 break;
179546 case 17: /* nearphrases ::= nearphrases phrase */
179547 {
179548 fts5yylhsminor.fts5yy26 = sqlite3Fts5ParseNearset(pParse, fts5yymsp[-1].minor.fts5yy26, fts5yymsp[0].minor.fts5yy11);
179549 }
179550 fts5yymsp[-1].minor.fts5yy26 = fts5yylhsminor.fts5yy26;
179551 break;
179552 case 18: /* neardist_opt ::= */
179553 { fts5yymsp[1].minor.fts5yy0.p = 0; fts5yymsp[1].minor.fts5yy0.n = 0; }
179554 break;
179555 case 19: /* neardist_opt ::= COMMA STRING */
179556 { fts5yymsp[-1].minor.fts5yy0 = fts5yymsp[0].minor.fts5yy0; }
179557 break;
179558 case 20: /* phrase ::= phrase PLUS STRING star_opt */
179559 {
179560 fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseTerm(pParse, fts5yymsp[-3].minor.fts5yy11, &fts5yymsp[-1].minor.fts5yy0, fts5yymsp[0].minor.fts5yy20);
179561 }
179562 fts5yymsp[-3].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
179563 break;
179564 case 21: /* phrase ::= STRING star_opt */
179565 {
179566 fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseTerm(pParse, 0, &fts5yymsp[-1].minor.fts5yy0, fts5yymsp[0].minor.fts5yy20);
179567 }
179568 fts5yymsp[-1].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
179569 break;
179570 case 22: /* star_opt ::= STAR */
179571 { fts5yymsp[0].minor.fts5yy20 = 1; }
179572 break;
179573 case 23: /* star_opt ::= */
179574 { fts5yymsp[1].minor.fts5yy20 = 0; }
179575 break;
179576 default:
179577 break;
179578 /********** End reduce actions ************************************************/
179579 };
@@ -180027,11 +180098,11 @@
180027 }
180028
180029 if( p->iRangeEnd>0 && iPos==p->iRangeEnd ){
180030 fts5HighlightAppend(&rc, p, &p->zIn[p->iOff], iEndOff - p->iOff);
180031 p->iOff = iEndOff;
180032 if( iPos<p->iter.iEnd ){
180033 fts5HighlightAppend(&rc, p, p->zClose, -1);
180034 }
180035 }
180036
180037 return rc;
@@ -180188,10 +180259,17 @@
180188 ctx.iRangeEnd = iBestStart + nToken - 1;
180189
180190 if( iBestStart>0 ){
180191 fts5HighlightAppend(&rc, &ctx, zEllips, -1);
180192 }
 
 
 
 
 
 
 
180193 if( rc==SQLITE_OK ){
180194 rc = pApi->xTokenize(pFts, ctx.zIn, ctx.nIn, (void*)&ctx,fts5HighlightCb);
180195 }
180196 if( ctx.iRangeEnd>=(nColSize-1) ){
180197 fts5HighlightAppend(&rc, &ctx, &ctx.zIn[ctx.iOff], ctx.nIn - ctx.iOff);
@@ -181923,10 +182001,11 @@
181923 case '}': tok = FTS5_RCP; break;
181924 case ':': tok = FTS5_COLON; break;
181925 case ',': tok = FTS5_COMMA; break;
181926 case '+': tok = FTS5_PLUS; break;
181927 case '*': tok = FTS5_STAR; break;
 
181928 case '\0': tok = FTS5_EOF; break;
181929
181930 case '"': {
181931 const char *z2;
181932 tok = FTS5_STRING;
@@ -183414,11 +183493,11 @@
183414 sizeof(Fts5ExprNearset) + sizeof(Fts5ExprPhrase*));
183415 }
183416 if( rc==SQLITE_OK ){
183417 Fts5Colset *pColsetOrig = pOrig->pNode->pNear->pColset;
183418 if( pColsetOrig ){
183419 int nByte = sizeof(Fts5Colset) + pColsetOrig->nCol * sizeof(int);
183420 Fts5Colset *pColset = (Fts5Colset*)sqlite3Fts5MallocZero(&rc, nByte);
183421 if( pColset ){
183422 memcpy(pColset, pColsetOrig, nByte);
183423 }
183424 pNew->pRoot->pNear->pColset = pColset;
@@ -183548,10 +183627,38 @@
183548 #endif
183549 }
183550
183551 return pNew;
183552 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
183553
183554 static Fts5Colset *sqlite3Fts5ParseColset(
183555 Fts5Parse *pParse, /* Store SQLITE_NOMEM here if required */
183556 Fts5Colset *pColset, /* Existing colset object */
183557 Fts5Token *p
@@ -185644,18 +185751,29 @@
185644
185645 assert( (pRet==0)==(p->rc!=SQLITE_OK) );
185646 return pRet;
185647 }
185648
185649
185650 /*
185651 ** Release a reference to data record returned by an earlier call to
185652 ** fts5DataRead().
185653 */
185654 static void fts5DataRelease(Fts5Data *pData){
185655 sqlite3_free(pData);
185656 }
 
 
 
 
 
 
 
 
 
 
 
 
185657
185658 static int fts5IndexPrepareStmt(
185659 Fts5Index *p,
185660 sqlite3_stmt **ppStmt,
185661 char *zSql
@@ -186461,11 +186579,11 @@
186461 pIter->iLeafPgno++;
186462 if( pIter->pNextLeaf ){
186463 pIter->pLeaf = pIter->pNextLeaf;
186464 pIter->pNextLeaf = 0;
186465 }else if( pIter->iLeafPgno<=pSeg->pgnoLast ){
186466 pIter->pLeaf = fts5DataRead(p,
186467 FTS5_SEGMENT_ROWID(pSeg->iSegid, pIter->iLeafPgno)
186468 );
186469 }else{
186470 pIter->pLeaf = 0;
186471 }
@@ -186964,13 +187082,12 @@
186964 pIter->iLeafOffset = iOff;
186965
186966 if( pLeaf->nn>pLeaf->szLeaf ){
186967 pIter->iPgidxOff = pLeaf->szLeaf + fts5GetVarint32(
186968 &pLeaf->p[pLeaf->szLeaf], pIter->iEndofDoclist
186969 );
186970 }
186971
186972 }
186973 else if( pLeaf->nn>pLeaf->szLeaf ){
186974 pIter->iPgidxOff = pLeaf->szLeaf + fts5GetVarint32(
186975 &pLeaf->p[pLeaf->szLeaf], iOff
186976 );
@@ -187210,10 +187327,15 @@
187210 }
187211
187212 iPgidx += fts5GetVarint32(&a[iPgidx], nKeep);
187213 iTermOff += nKeep;
187214 iOff = iTermOff;
 
 
 
 
 
187215
187216 /* Read the nKeep field of the next term. */
187217 fts5FastGetVarint32(a, iOff, nKeep);
187218 }
187219
@@ -188136,10 +188258,19 @@
188136 fts5BufferZero(&pIter->poslist);
188137 fts5SegiterPoslist(pIter->pIndex, pSeg, 0, &pIter->poslist);
188138 pIter->base.pData = pIter->poslist.p;
188139 }
188140 }
 
 
 
 
 
 
 
 
 
188141
188142 /*
188143 ** xSetOutputs callback used by detail=col when there is a column filter
188144 ** and there are 100 or more columns. Also called as a fallback from
188145 ** fts5IterSetOutputs_Col100 if the column-list spans more than one page.
@@ -188241,10 +188372,14 @@
188241 }
188242
188243 else if( pIter->pColset==0 ){
188244 pIter->xSetOutputs = fts5IterSetOutputs_Nocolset;
188245 }
 
 
 
 
188246
188247 else if( pConfig->eDetail==FTS5_DETAIL_FULL ){
188248 pIter->xSetOutputs = fts5IterSetOutputs_Full;
188249 }
188250
@@ -194018,11 +194153,11 @@
194018 int nArg, /* Number of args */
194019 sqlite3_value **apUnused /* Function arguments */
194020 ){
194021 assert( nArg==0 );
194022 UNUSED_PARAM2(nArg, apUnused);
194023 sqlite3_result_text(pCtx, "fts5: 2016-08-11 18:53:32 a12d8059770df4bca59e321c266410344242bf7b", -1, SQLITE_TRANSIENT);
194024 }
194025
194026 static int fts5Init(sqlite3 *db){
194027 static const sqlite3_module fts5Mod = {
194028 /* iVersion */ 2,
194029
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.15.0. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a single translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% or more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -378,13 +378,13 @@
378 **
379 ** See also: [sqlite3_libversion()],
380 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
381 ** [sqlite_version()] and [sqlite_source_id()].
382 */
383 #define SQLITE_VERSION "3.15.0"
384 #define SQLITE_VERSION_NUMBER 3015000
385 #define SQLITE_SOURCE_ID "2016-08-22 20:10:01 7839519349c7371cdb4e16a215eacd27004cbc62"
386
387 /*
388 ** CAPI3REF: Run-Time Library Version Numbers
389 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
390 **
@@ -2227,12 +2227,22 @@
2227 ** is written 0 or 1 to indicate whether [sqlite3_load_extension()] interface
2228 ** is disabled or enabled following this call. The second parameter may
2229 ** be a NULL pointer, in which case the new setting is not reported back.
2230 ** </dd>
2231 **
2232 ** <dt>SQLITE_DBCONFIG_MAINDBNAME</dt>
2233 ** <dd> ^This option is used to change the name of the "main" database
2234 ** schema. ^The sole argument is a pointer to a constant UTF8 string
2235 ** which will become the new schema name in place of "main". ^SQLite
2236 ** does not make a copy of the new main schema name string, so the application
2237 ** must ensure that the argument passed into this DBCONFIG option is unchanged
2238 ** until after the database connection closes.
2239 ** </dd>
2240 **
2241 ** </dl>
2242 */
2243 #define SQLITE_DBCONFIG_MAINDBNAME 1000 /* const char* */
2244 #define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
2245 #define SQLITE_DBCONFIG_ENABLE_FKEY 1002 /* int int* */
2246 #define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */
2247 #define SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1004 /* int int* */
2248 #define SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION 1005 /* int int* */
@@ -13694,11 +13704,11 @@
13704 ** in the sqlite.aDb[] array. aDb[0] is the main database file and
13705 ** aDb[1] is the database file used to hold temporary tables. Additional
13706 ** databases may be attached.
13707 */
13708 struct Db {
13709 char *zDbSName; /* Name of this database. (schema name, not filename) */
13710 Btree *pBt; /* The B*Tree structure for this database file */
13711 u8 safety_level; /* How aggressive at syncing data to disk */
13712 u8 bSyncSet; /* True if "PRAGMA synchronous=N" has been run */
13713 Schema *pSchema; /* Pointer to database schema (possibly shared) */
13714 };
@@ -16298,12 +16308,12 @@
16308 SQLITE_PRIVATE Table *sqlite3LocateTable(Parse*,u32 flags,const char*, const char*);
16309 SQLITE_PRIVATE Table *sqlite3LocateTableItem(Parse*,u32 flags,struct SrcList_item *);
16310 SQLITE_PRIVATE Index *sqlite3FindIndex(sqlite3*,const char*, const char*);
16311 SQLITE_PRIVATE void sqlite3UnlinkAndDeleteTable(sqlite3*,int,const char*);
16312 SQLITE_PRIVATE void sqlite3UnlinkAndDeleteIndex(sqlite3*,int,const char*);
16313 SQLITE_PRIVATE void sqlite3Vacuum(Parse*,Token*);
16314 SQLITE_PRIVATE int sqlite3RunVacuum(char**, sqlite3*, int);
16315 SQLITE_PRIVATE char *sqlite3NameFromToken(sqlite3*, Token*);
16316 SQLITE_PRIVATE int sqlite3ExprCompare(Expr*, Expr*, int);
16317 SQLITE_PRIVATE int sqlite3ExprListCompare(ExprList*, ExprList*, int);
16318 SQLITE_PRIVATE int sqlite3ExprImpliesExpr(Expr*, Expr*, int);
16319 SQLITE_PRIVATE void sqlite3ExprAnalyzeAggregates(NameContext*, Expr*);
@@ -34851,10 +34861,31 @@
34861 unixLeaveMutex();
34862 }
34863 #endif /* if !OS_VXWORKS */
34864 return pUnused;
34865 }
34866
34867 /*
34868 ** Find the mode, uid and gid of file zFile.
34869 */
34870 static int getFileMode(
34871 const char *zFile, /* File name */
34872 mode_t *pMode, /* OUT: Permissions of zFile */
34873 uid_t *pUid, /* OUT: uid of zFile. */
34874 gid_t *pGid /* OUT: gid of zFile. */
34875 ){
34876 struct stat sStat; /* Output of stat() on database file */
34877 int rc = SQLITE_OK;
34878 if( 0==osStat(zFile, &sStat) ){
34879 *pMode = sStat.st_mode & 0777;
34880 *pUid = sStat.st_uid;
34881 *pGid = sStat.st_gid;
34882 }else{
34883 rc = SQLITE_IOERR_FSTAT;
34884 }
34885 return rc;
34886 }
34887
34888 /*
34889 ** This function is called by unixOpen() to determine the unix permissions
34890 ** to create new files with. If no error occurs, then SQLITE_OK is returned
34891 ** and a value suitable for passing as the third argument to open(2) is
@@ -34887,11 +34918,10 @@
34918 *pUid = 0;
34919 *pGid = 0;
34920 if( flags & (SQLITE_OPEN_WAL|SQLITE_OPEN_MAIN_JOURNAL) ){
34921 char zDb[MAX_PATHNAME+1]; /* Database file path */
34922 int nDb; /* Number of valid bytes in zDb */
 
34923
34924 /* zPath is a path to a WAL or journal file. The following block derives
34925 ** the path to the associated database file from zPath. This block handles
34926 ** the following naming conventions:
34927 **
@@ -34918,19 +34948,22 @@
34948 nDb--;
34949 }
34950 memcpy(zDb, zPath, nDb);
34951 zDb[nDb] = '\0';
34952
34953 rc = getFileMode(zDb, pMode, pUid, pGid);
 
 
 
 
 
 
34954 }else if( flags & SQLITE_OPEN_DELETEONCLOSE ){
34955 *pMode = 0600;
34956 }else if( flags & SQLITE_OPEN_URI ){
34957 /* If this is a main database file and the file was opened using a URI
34958 ** filename, check for the "modeof" parameter. If present, interpret
34959 ** its value as a filename and try to copy the mode, uid and gid from
34960 ** that file. */
34961 const char *z = sqlite3_uri_parameter(zPath, "modeof");
34962 if( z ){
34963 rc = getFileMode(z, pMode, pUid, pGid);
34964 }
34965 }
34966 return rc;
34967 }
34968
34969 /*
@@ -75441,11 +75474,11 @@
75474 int nEntry;
75475 sqlite3BtreeEnter(pBt);
75476 nEntry = sqlite3PagerWalCallback(sqlite3BtreePager(pBt));
75477 sqlite3BtreeLeave(pBt);
75478 if( db->xWalCallback && nEntry>0 && rc==SQLITE_OK ){
75479 rc = db->xWalCallback(db->pWalArg, db, db->aDb[i].zDbSName, nEntry);
75480 }
75481 }
75482 }
75483 #endif
75484 return rc;
@@ -81472,11 +81505,11 @@
81505 }
81506
81507 if( pOp->p4type==P4_TABLE && HAS_UPDATE_HOOK(db) ){
81508 assert( pC->isTable );
81509 assert( pC->iDb>=0 );
81510 zDb = db->aDb[pC->iDb].zDbSName;
81511 pTab = pOp->p4.pTab;
81512 assert( HasRowid(pTab) );
81513 op = ((pOp->p5 & OPFLAG_ISUPDATE) ? SQLITE_UPDATE : SQLITE_INSERT);
81514 }else{
81515 pTab = 0; /* Not needed. Silence a comiler warning. */
@@ -81589,11 +81622,11 @@
81622 ** last moved with OP_Next or OP_Prev, not Seek or NotFound, set
81623 ** VdbeCursor.movetoTarget to the current rowid. */
81624 if( pOp->p4type==P4_TABLE && HAS_UPDATE_HOOK(db) ){
81625 assert( pC->iDb>=0 );
81626 assert( pOp->p4.pTab!=0 );
81627 zDb = db->aDb[pC->iDb].zDbSName;
81628 pTab = pOp->p4.pTab;
81629 if( (pOp->p5 & OPFLAG_SAVEPOSITION)!=0 && pC->isTable ){
81630 pC->movetoTarget = sqlite3BtreeIntegerKey(pC->uc.pCursor);
81631 }
81632 }else{
@@ -82559,11 +82592,11 @@
82592 initData.db = db;
82593 initData.iDb = pOp->p1;
82594 initData.pzErrMsg = &p->zErrMsg;
82595 zSql = sqlite3MPrintf(db,
82596 "SELECT name, rootpage, sql FROM '%q'.%s WHERE %s ORDER BY rowid",
82597 db->aDb[iDb].zDbSName, zMaster, pOp->p4.z);
82598 if( zSql==0 ){
82599 rc = SQLITE_NOMEM_BKPT;
82600 }else{
82601 assert( db->init.busy==0 );
82602 db->init.busy = 1;
@@ -83388,19 +83421,18 @@
83421 break;
83422 };
83423 #endif /* SQLITE_OMIT_PRAGMA */
83424
83425 #if !defined(SQLITE_OMIT_VACUUM) && !defined(SQLITE_OMIT_ATTACH)
83426 /* Opcode: Vacuum P1 * * * *
83427 **
83428 ** Vacuum the entire database P1. P1 is 0 for "main", and 2 or more
83429 ** for an attached database. The "temp" database may not be vacuumed.
 
83430 */
83431 case OP_Vacuum: {
83432 assert( p->readOnly==0 );
83433 rc = sqlite3RunVacuum(&p->zErrMsg, db, pOp->p1);
83434 if( rc ) goto abort_due_to_error;
83435 break;
83436 }
83437 #endif
83438
@@ -83943,11 +83975,11 @@
83975 zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql);
83976 if( zTrace ){
83977 int i;
83978 for(i=0; i<db->nDb; i++){
83979 if( DbMaskTest(p->btreeMask, i)==0 ) continue;
83980 sqlite3_file_control(db, db->aDb[i].zDbSName, SQLITE_FCNTL_TRACE, zTrace);
83981 }
83982 }
83983 #endif /* SQLITE_USE_FCNTL_TRACE */
83984 #ifdef SQLITE_DEBUG
83985 if( (db->flags & SQLITE_SqlTrace)!=0
@@ -84279,11 +84311,11 @@
84311 rc = SQLITE_ERROR;
84312 sqlite3BtreeLeaveAll(db);
84313 goto blob_open_out;
84314 }
84315 pBlob->pTab = pTab;
84316 pBlob->zDb = db->aDb[sqlite3SchemaToIndex(db, pTab->pSchema)].zDbSName;
84317
84318 /* Now search pTab for the exact column. */
84319 for(iCol=0; iCol<pTab->nCol; iCol++) {
84320 if( sqlite3StrICmp(pTab->aCol[iCol].zName, zColumn)==0 ){
84321 break;
@@ -87831,21 +87863,19 @@
87863 static SQLITE_NOINLINE int walkExpr(Walker *pWalker, Expr *pExpr){
87864 int rc;
87865 testcase( ExprHasProperty(pExpr, EP_TokenOnly) );
87866 testcase( ExprHasProperty(pExpr, EP_Reduced) );
87867 rc = pWalker->xExprCallback(pWalker, pExpr);
87868 if( rc || ExprHasProperty(pExpr,EP_TokenOnly) ) return rc & WRC_Abort;
87869 if( pExpr->pLeft && walkExpr(pWalker, pExpr->pLeft) ) return WRC_Abort;
87870 if( pExpr->pRight && walkExpr(pWalker, pExpr->pRight) ) return WRC_Abort;
87871 if( ExprHasProperty(pExpr, EP_xIsSelect) ){
87872 if( sqlite3WalkSelect(pWalker, pExpr->x.pSelect) ) return WRC_Abort;
87873 }else{
87874 if( sqlite3WalkExprList(pWalker, pExpr->x.pList) ) return WRC_Abort;
87875 }
87876 return WRC_Continue;
 
 
87877 }
87878 SQLITE_PRIVATE int sqlite3WalkExpr(Walker *pWalker, Expr *pExpr){
87879 return pExpr ? walkExpr(pWalker,pExpr) : WRC_Continue;
87880 }
87881
@@ -88175,12 +88205,12 @@
88205 ** legacy and because it does not hurt anything to just ignore the
88206 ** database name. */
88207 zDb = 0;
88208 }else{
88209 for(i=0; i<db->nDb; i++){
88210 assert( db->aDb[i].zDbSName );
88211 if( sqlite3StrICmp(db->aDb[i].zDbSName,zDb)==0 ){
88212 pSchema = db->aDb[i].pSchema;
88213 break;
88214 }
88215 }
88216 }
@@ -94249,11 +94279,11 @@
94279 assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );
94280
94281 pTab = sqlite3LocateTableItem(pParse, 0, &pSrc->a[0]);
94282 if( !pTab ) goto exit_rename_table;
94283 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
94284 zDb = db->aDb[iDb].zDbSName;
94285 db->flags |= SQLITE_PreferBuiltin;
94286
94287 /* Get a NULL terminated version of the new table name. */
94288 zName = sqlite3NameFromToken(db, pName);
94289 if( !zName ) goto exit_rename_table;
@@ -94447,11 +94477,11 @@
94477 pNew = pParse->pNewTable;
94478 assert( pNew );
94479
94480 assert( sqlite3BtreeHoldsAllMutexes(db) );
94481 iDb = sqlite3SchemaToIndex(db, pNew->pSchema);
94482 zDb = db->aDb[iDb].zDbSName;
94483 zTab = &pNew->zName[16]; /* Skip the "sqlite_altertab_" prefix on the name */
94484 pCol = &pNew->aCol[pNew->nCol-1];
94485 pDflt = pCol->pDflt;
94486 pTab = sqlite3FindTable(db, zTab, zDb);
94487 assert( pTab );
@@ -94857,18 +94887,18 @@
94887 ** if they do already exist.
94888 */
94889 for(i=0; i<ArraySize(aTable); i++){
94890 const char *zTab = aTable[i].zName;
94891 Table *pStat;
94892 if( (pStat = sqlite3FindTable(db, zTab, pDb->zDbSName))==0 ){
94893 if( aTable[i].zCols ){
94894 /* The sqlite_statN table does not exist. Create it. Note that a
94895 ** side-effect of the CREATE TABLE statement is to leave the rootpage
94896 ** of the new table in register pParse->regRoot. This is important
94897 ** because the OpenWrite opcode below will be needing it. */
94898 sqlite3NestedParse(pParse,
94899 "CREATE TABLE %Q.%s(%s)", pDb->zDbSName, zTab, aTable[i].zCols
94900 );
94901 aRoot[i] = pParse->regRoot;
94902 aCreateTbl[i] = OPFLAG_P2ISREG;
94903 }
94904 }else{
@@ -94879,11 +94909,11 @@
94909 aCreateTbl[i] = 0;
94910 sqlite3TableLock(pParse, iDb, aRoot[i], 1, zTab);
94911 if( zWhere ){
94912 sqlite3NestedParse(pParse,
94913 "DELETE FROM %Q.%s WHERE %s=%Q",
94914 pDb->zDbSName, zTab, zWhereType, zWhere
94915 );
94916 }else{
94917 /* The sqlite_stat[134] table already exists. Delete all rows. */
94918 sqlite3VdbeAddOp2(v, OP_Clear, aRoot[i], iDb);
94919 }
@@ -95641,11 +95671,11 @@
95671 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
95672 assert( iDb>=0 );
95673 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
95674 #ifndef SQLITE_OMIT_AUTHORIZATION
95675 if( sqlite3AuthCheck(pParse, SQLITE_ANALYZE, pTab->zName, 0,
95676 db->aDb[iDb].zDbSName ) ){
95677 return;
95678 }
95679 #endif
95680
95681 /* Establish a read-lock on the table at the shared-cache level.
@@ -96031,11 +96061,11 @@
96061 }
96062 }else{
96063 /* Form 3: Analyze the fully qualified table name */
96064 iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pTableName);
96065 if( iDb>=0 ){
96066 zDb = db->aDb[iDb].zDbSName;
96067 z = sqlite3NameFromToken(db, pTableName);
96068 if( z ){
96069 if( (pIdx = sqlite3FindIndex(db, z, zDb))!=0 ){
96070 analyzeTable(pParse, pIdx->pTable, pIdx);
96071 }else if( (pTab = sqlite3LocateTable(pParse, 0, z, zDb))!=0 ){
@@ -96491,11 +96521,11 @@
96521 #endif
96522 }
96523
96524 /* Load new statistics out of the sqlite_stat1 table */
96525 sInfo.db = db;
96526 sInfo.zDatabase = db->aDb[iDb].zDbSName;
96527 if( sqlite3FindTable(db, "sqlite_stat1", sInfo.zDatabase)!=0 ){
96528 zSql = sqlite3MPrintf(db,
96529 "SELECT tbl,idx,stat FROM %Q.sqlite_stat1", sInfo.zDatabase);
96530 if( zSql==0 ){
96531 rc = SQLITE_NOMEM_BKPT;
@@ -96634,11 +96664,11 @@
96664 if( !db->autoCommit ){
96665 zErrDyn = sqlite3MPrintf(db, "cannot ATTACH database within transaction");
96666 goto attach_error;
96667 }
96668 for(i=0; i<db->nDb; i++){
96669 char *z = db->aDb[i].zDbSName;
96670 assert( z && zName );
96671 if( sqlite3StrICmp(z, zName)==0 ){
96672 zErrDyn = sqlite3MPrintf(db, "database %s is already in use", zName);
96673 goto attach_error;
96674 }
@@ -96699,12 +96729,12 @@
96729 PAGER_SYNCHRONOUS_FULL | (db->flags & PAGER_FLAGS_MASK));
96730 #endif
96731 sqlite3BtreeLeave(aNew->pBt);
96732 }
96733 aNew->safety_level = SQLITE_DEFAULT_SYNCHRONOUS+1;
96734 aNew->zDbSName = sqlite3DbStrDup(db, zName);
96735 if( rc==SQLITE_OK && aNew->zDbSName==0 ){
96736 rc = SQLITE_NOMEM_BKPT;
96737 }
96738
96739
96740 #ifdef SQLITE_HAS_CODEC
@@ -96812,11 +96842,11 @@
96842
96843 if( zName==0 ) zName = "";
96844 for(i=0; i<db->nDb; i++){
96845 pDb = &db->aDb[i];
96846 if( pDb->pBt==0 ) continue;
96847 if( sqlite3StrICmp(pDb->zDbSName, zName)==0 ) break;
96848 }
96849
96850 if( i>=db->nDb ){
96851 sqlite3_snprintf(sizeof(zErr),zErr, "no such database: %s", zName);
96852 goto detach_error;
@@ -96970,11 +97000,11 @@
97000 sqlite3 *db;
97001
97002 db = pParse->db;
97003 assert( db->nDb>iDb );
97004 pFix->pParse = pParse;
97005 pFix->zDb = db->aDb[iDb].zDbSName;
97006 pFix->pSchema = db->aDb[iDb].pSchema;
97007 pFix->zType = zType;
97008 pFix->pName = pName;
97009 pFix->bVarOnly = (iDb==1);
97010 }
@@ -97228,13 +97258,13 @@
97258 Parse *pParse, /* The parser context */
97259 const char *zTab, /* Table name */
97260 const char *zCol, /* Column name */
97261 int iDb /* Index of containing database. */
97262 ){
97263 sqlite3 *db = pParse->db; /* Database handle */
97264 char *zDb = db->aDb[iDb].zDbSName; /* Schema name of attached database */
97265 int rc; /* Auth callback return code */
97266
97267 if( db->init.busy ) return SQLITE_OK;
97268 rc = db->xAuth(db->pAuthArg, SQLITE_READ, zTab,zCol,zDb,pParse->zAuthContext
97269 #ifdef SQLITE_USER_AUTHENTICATION
97270 ,db->auth.zAuthUser
@@ -97703,14 +97733,15 @@
97733 return 0;
97734 }
97735 #endif
97736 for(i=OMIT_TEMPDB; i<db->nDb; i++){
97737 int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */
97738 if( zDatabase==0 || sqlite3StrICmp(zDatabase, db->aDb[j].zDbSName)==0 ){
97739 assert( sqlite3SchemaMutexHeld(db, j, 0) );
97740 p = sqlite3HashFind(&db->aDb[j].pSchema->tblHash, zName);
97741 if( p ) break;
97742 }
97743 }
97744 return p;
97745 }
97746
97747 /*
@@ -97780,11 +97811,11 @@
97811 ){
97812 const char *zDb;
97813 assert( p->pSchema==0 || p->zDatabase==0 );
97814 if( p->pSchema ){
97815 int iDb = sqlite3SchemaToIndex(pParse->db, p->pSchema);
97816 zDb = pParse->db->aDb[iDb].zDbSName;
97817 }else{
97818 zDb = p->zDatabase;
97819 }
97820 return sqlite3LocateTable(pParse, flags, p->zName, zDb);
97821 }
@@ -97808,11 +97839,11 @@
97839 assert( zDb!=0 || sqlite3BtreeHoldsAllMutexes(db) );
97840 for(i=OMIT_TEMPDB; i<db->nDb; i++){
97841 int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */
97842 Schema *pSchema = db->aDb[j].pSchema;
97843 assert( pSchema );
97844 if( zDb && sqlite3StrICmp(zDb, db->aDb[j].zDbSName) ) continue;
97845 assert( sqlite3SchemaMutexHeld(db, j, 0) );
97846 p = sqlite3HashFind(&pSchema->idxHash, zName);
97847 if( p ) break;
97848 }
97849 return p;
@@ -97877,12 +97908,12 @@
97908 SQLITE_PRIVATE void sqlite3CollapseDatabaseArray(sqlite3 *db){
97909 int i, j;
97910 for(i=j=2; i<db->nDb; i++){
97911 struct Db *pDb = &db->aDb[i];
97912 if( pDb->pBt==0 ){
97913 sqlite3DbFree(db, pDb->zDbSName);
97914 pDb->zDbSName = 0;
97915 continue;
97916 }
97917 if( j<i ){
97918 db->aDb[j] = db->aDb[i];
97919 }
@@ -98098,11 +98129,11 @@
98129 SQLITE_PRIVATE int sqlite3FindDbName(sqlite3 *db, const char *zName){
98130 int i = -1; /* Database number */
98131 if( zName ){
98132 Db *pDb;
98133 for(i=(db->nDb-1), pDb=&db->aDb[i]; i>=0; i--, pDb--){
98134 if( 0==sqlite3StrICmp(pDb->zDbSName, zName) ) break;
98135 }
98136 }
98137 return i;
98138 }
98139
@@ -98157,11 +98188,11 @@
98188 if( iDb<0 ){
98189 sqlite3ErrorMsg(pParse, "unknown database %T", pName1);
98190 return -1;
98191 }
98192 }else{
98193 assert( db->init.iDb==0 || db->init.busy || (db->flags & SQLITE_Vacuum)!=0);
98194 iDb = db->init.iDb;
98195 *pUnqual = pName1;
98196 }
98197 return iDb;
98198 }
@@ -98268,11 +98299,11 @@
98299 SQLITE_CREATE_TABLE,
98300 SQLITE_CREATE_TEMP_TABLE,
98301 SQLITE_CREATE_VIEW,
98302 SQLITE_CREATE_TEMP_VIEW
98303 };
98304 char *zDb = db->aDb[iDb].zDbSName;
98305 if( sqlite3AuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(isTemp), 0, zDb) ){
98306 goto begin_table_error;
98307 }
98308 if( !isVirtual && sqlite3AuthCheck(pParse, (int)aCode[isTemp+2*isView],
98309 zName, 0, zDb) ){
@@ -98287,11 +98318,11 @@
98318 ** to an sqlite3_declare_vtab() call. In that case only the column names
98319 ** and types will be used, so there is no need to test for namespace
98320 ** collisions.
98321 */
98322 if( !IN_DECLARE_VTAB ){
98323 char *zDb = db->aDb[iDb].zDbSName;
98324 if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){
98325 goto begin_table_error;
98326 }
98327 pTable = sqlite3FindTable(db, zName, zDb);
98328 if( pTable ){
@@ -99380,11 +99411,11 @@
99411 */
99412 sqlite3NestedParse(pParse,
99413 "UPDATE %Q.%s "
99414 "SET type='%s', name=%Q, tbl_name=%Q, rootpage=#%d, sql=%Q "
99415 "WHERE rowid=#%d",
99416 db->aDb[iDb].zDbSName, SCHEMA_TABLE(iDb),
99417 zType,
99418 p->zName,
99419 p->zName,
99420 pParse->regRoot,
99421 zStmt,
@@ -99395,17 +99426,17 @@
99426
99427 #ifndef SQLITE_OMIT_AUTOINCREMENT
99428 /* Check to see if we need to create an sqlite_sequence table for
99429 ** keeping track of autoincrement keys.
99430 */
99431 if( (p->tabFlags & TF_Autoincrement)!=0 ){
99432 Db *pDb = &db->aDb[iDb];
99433 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
99434 if( pDb->pSchema->pSeqTab==0 ){
99435 sqlite3NestedParse(pParse,
99436 "CREATE TABLE %Q.sqlite_sequence(name,seq)",
99437 pDb->zDbSName
99438 );
99439 }
99440 }
99441 #endif
99442
@@ -99715,11 +99746,11 @@
99746 ** is in register NNN. See grammar rules associated with the TK_REGISTER
99747 ** token for additional information.
99748 */
99749 sqlite3NestedParse(pParse,
99750 "UPDATE %Q.%s SET rootpage=%d WHERE #%d AND rootpage=#%d",
99751 pParse->db->aDb[iDb].zDbSName, SCHEMA_TABLE(iDb), iTable, r1, r1);
99752 #endif
99753 sqlite3ReleaseTempReg(pParse, r1);
99754 }
99755
99756 /*
@@ -99791,11 +99822,11 @@
99822 int iDb, /* The database number */
99823 const char *zType, /* "idx" or "tbl" */
99824 const char *zName /* Name of index or table */
99825 ){
99826 int i;
99827 const char *zDbName = pParse->db->aDb[iDb].zDbSName;
99828 for(i=1; i<=4; i++){
99829 char zTab[24];
99830 sqlite3_snprintf(sizeof(zTab),zTab,"sqlite_stat%d",i);
99831 if( sqlite3FindTable(pParse->db, zTab, zDbName) ){
99832 sqlite3NestedParse(pParse,
@@ -99844,11 +99875,11 @@
99875 ** move as a result of the drop (can happen in auto-vacuum mode).
99876 */
99877 if( pTab->tabFlags & TF_Autoincrement ){
99878 sqlite3NestedParse(pParse,
99879 "DELETE FROM %Q.sqlite_sequence WHERE name=%Q",
99880 pDb->zDbSName, pTab->zName
99881 );
99882 }
99883 #endif
99884
99885 /* Drop all SQLITE_MASTER table and index entries that refer to the
@@ -99858,11 +99889,11 @@
99889 ** created in the temp database that refers to a table in another
99890 ** database.
99891 */
99892 sqlite3NestedParse(pParse,
99893 "DELETE FROM %Q.%s WHERE tbl_name=%Q and type!='trigger'",
99894 pDb->zDbSName, SCHEMA_TABLE(iDb), pTab->zName);
99895 if( !isView && !IsVirtual(pTab) ){
99896 destroyTable(pParse, pTab);
99897 }
99898
99899 /* Remove the table entry from SQLite's internal schema and modify
@@ -99912,11 +99943,11 @@
99943 }
99944 #ifndef SQLITE_OMIT_AUTHORIZATION
99945 {
99946 int code;
99947 const char *zTab = SCHEMA_TABLE(iDb);
99948 const char *zDb = db->aDb[iDb].zDbSName;
99949 const char *zArg2 = 0;
99950 if( sqlite3AuthCheck(pParse, SQLITE_DELETE, zTab, 0, zDb)){
99951 goto exit_drop_table;
99952 }
99953 if( isView ){
@@ -100153,11 +100184,11 @@
100184 sqlite3 *db = pParse->db; /* The database connection */
100185 int iDb = sqlite3SchemaToIndex(db, pIndex->pSchema);
100186
100187 #ifndef SQLITE_OMIT_AUTHORIZATION
100188 if( sqlite3AuthCheck(pParse, SQLITE_REINDEX, pIndex->zName, 0,
100189 db->aDb[iDb].zDbSName ) ){
100190 return;
100191 }
100192 #endif
100193
100194 /* Require a write-lock on the table to perform this operation */
@@ -100405,11 +100436,11 @@
100436 if( sqlite3FindTable(db, zName, 0)!=0 ){
100437 sqlite3ErrorMsg(pParse, "there is already a table named %s", zName);
100438 goto exit_create_index;
100439 }
100440 }
100441 if( sqlite3FindIndex(db, zName, pDb->zDbSName)!=0 ){
100442 if( !ifNotExist ){
100443 sqlite3ErrorMsg(pParse, "index %s already exists", zName);
100444 }else{
100445 assert( !db->init.busy );
100446 sqlite3CodeVerifySchema(pParse, iDb);
@@ -100435,11 +100466,11 @@
100466
100467 /* Check for authorization to create an index.
100468 */
100469 #ifndef SQLITE_OMIT_AUTHORIZATION
100470 {
100471 const char *zDb = pDb->zDbSName;
100472 if( sqlite3AuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(iDb), 0, zDb) ){
100473 goto exit_create_index;
100474 }
100475 i = SQLITE_CREATE_INDEX;
100476 if( !OMIT_TEMPDB && iDb==1 ) i = SQLITE_CREATE_TEMP_INDEX;
@@ -100750,11 +100781,11 @@
100781
100782 /* Add an entry in sqlite_master for this index
100783 */
100784 sqlite3NestedParse(pParse,
100785 "INSERT INTO %Q.%s VALUES('index',%Q,%Q,#%d,%Q);",
100786 db->aDb[iDb].zDbSName, SCHEMA_TABLE(iDb),
100787 pIndex->zName,
100788 pTab->zName,
100789 iMem,
100790 zStmt
100791 );
@@ -100884,11 +100915,11 @@
100915 iDb = sqlite3SchemaToIndex(db, pIndex->pSchema);
100916 #ifndef SQLITE_OMIT_AUTHORIZATION
100917 {
100918 int code = SQLITE_DROP_INDEX;
100919 Table *pTab = pIndex->pTable;
100920 const char *zDb = db->aDb[iDb].zDbSName;
100921 const char *zTab = SCHEMA_TABLE(iDb);
100922 if( sqlite3AuthCheck(pParse, SQLITE_DELETE, zTab, 0, zDb) ){
100923 goto exit_drop_index;
100924 }
100925 if( !OMIT_TEMPDB && iDb ) code = SQLITE_DROP_TEMP_INDEX;
@@ -100902,11 +100933,11 @@
100933 v = sqlite3GetVdbe(pParse);
100934 if( v ){
100935 sqlite3BeginWriteOperation(pParse, 1, iDb);
100936 sqlite3NestedParse(pParse,
100937 "DELETE FROM %Q.%s WHERE name=%Q AND type='index'",
100938 db->aDb[iDb].zDbSName, SCHEMA_TABLE(iDb), pIndex->zName
100939 );
100940 sqlite3ClearStatTables(pParse, iDb, "idx", pIndex->zName);
100941 sqlite3ChangeCookie(pParse, iDb);
100942 destroyRootPage(pParse, pIndex->tnum, iDb);
100943 sqlite3VdbeAddOp4(v, OP_DropIndex, iDb, 0, 0, pIndex->zName, 0);
@@ -101447,11 +101478,11 @@
101478 SQLITE_PRIVATE void sqlite3CodeVerifyNamedSchema(Parse *pParse, const char *zDb){
101479 sqlite3 *db = pParse->db;
101480 int i;
101481 for(i=0; i<db->nDb; i++){
101482 Db *pDb = &db->aDb[i];
101483 if( pDb->pBt && (!zDb || 0==sqlite3StrICmp(zDb, pDb->zDbSName)) ){
101484 sqlite3CodeVerifySchema(pParse, i);
101485 }
101486 }
101487 }
101488
@@ -101694,11 +101725,11 @@
101725 }
101726 iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pObjName);
101727 if( iDb<0 ) return;
101728 z = sqlite3NameFromToken(db, pObjName);
101729 if( z==0 ) return;
101730 zDb = db->aDb[iDb].zDbSName;
101731 pTab = sqlite3FindTable(db, z, zDb);
101732 if( pTab ){
101733 reindexTable(pParse, pTab, 0);
101734 sqlite3DbFree(db, z);
101735 return;
@@ -102408,11 +102439,11 @@
102439 pWhere = sqlite3ExprDup(db, pWhere, 0);
102440 pFrom = sqlite3SrcListAppend(db, 0, 0, 0);
102441 if( pFrom ){
102442 assert( pFrom->nSrc==1 );
102443 pFrom->a[0].zName = sqlite3DbStrDup(db, pView->zName);
102444 pFrom->a[0].zDatabase = sqlite3DbStrDup(db, db->aDb[iDb].zDbSName);
102445 assert( pFrom->a[0].pOn==0 );
102446 assert( pFrom->a[0].pUsing==0 );
102447 }
102448 pSel = sqlite3SelectNew(pParse, 0, pFrom, pWhere, 0, 0, 0,
102449 SF_IncludeHidden, 0, 0);
@@ -102595,11 +102626,11 @@
102626 if( sqlite3IsReadOnly(pParse, pTab, (pTrigger?1:0)) ){
102627 goto delete_from_cleanup;
102628 }
102629 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
102630 assert( iDb<db->nDb );
102631 zDb = db->aDb[iDb].zDbSName;
102632 rcauth = sqlite3AuthCheck(pParse, SQLITE_DELETE, pTab->zName, 0, zDb);
102633 assert( rcauth==SQLITE_OK || rcauth==SQLITE_DENY || rcauth==SQLITE_IGNORE );
102634 if( rcauth==SQLITE_DENY ){
102635 goto delete_from_cleanup;
102636 }
@@ -105927,11 +105958,11 @@
105958
105959 /* If foreign-keys are disabled, this function is a no-op. */
105960 if( (db->flags&SQLITE_ForeignKeys)==0 ) return;
105961
105962 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
105963 zDb = db->aDb[iDb].zDbSName;
105964
105965 /* Loop through all the foreign key constraints for which pTab is the
105966 ** child table (the table that the foreign key definition is part of). */
105967 for(pFKey=pTab->pFKey; pFKey; pFKey=pFKey->pNextFrom){
105968 Table *pTo; /* Parent table of foreign key pFKey */
@@ -106667,11 +106698,13 @@
106698
106699 #ifndef SQLITE_OMIT_AUTOINCREMENT
106700 /*
106701 ** Locate or create an AutoincInfo structure associated with table pTab
106702 ** which is in database iDb. Return the register number for the register
106703 ** that holds the maximum rowid. Return zero if pTab is not an AUTOINCREMENT
106704 ** table. (Also return zero when doing a VACUUM since we do not want to
106705 ** update the AUTOINCREMENT counters during a VACUUM.)
106706 **
106707 ** There is at most one AutoincInfo structure per table even if the
106708 ** same table is autoincremented multiple times due to inserts within
106709 ** triggers. A new AutoincInfo structure is created if this is the
106710 ** first use of table pTab. On 2nd and subsequent uses, the original
@@ -106690,11 +106723,13 @@
106723 Parse *pParse, /* Parsing context */
106724 int iDb, /* Index of the database holding pTab */
106725 Table *pTab /* The table we are writing to */
106726 ){
106727 int memId = 0; /* Register holding maximum rowid */
106728 if( (pTab->tabFlags & TF_Autoincrement)!=0
106729 && (pParse->db->flags & SQLITE_Vacuum)==0
106730 ){
106731 Parse *pToplevel = sqlite3ParseToplevel(pParse);
106732 AutoincInfo *pInfo;
106733
106734 pInfo = pToplevel->pAinc;
106735 while( pInfo && pInfo->pTab!=pTab ){ pInfo = pInfo->pNext; }
@@ -107014,11 +107049,11 @@
107049 goto insert_cleanup;
107050 }
107051 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
107052 assert( iDb<db->nDb );
107053 pDb = &db->aDb[iDb];
107054 zDb = pDb->zDbSName;
107055 if( sqlite3AuthCheck(pParse, SQLITE_INSERT, pTab->zName, 0, zDb) ){
107056 goto insert_cleanup;
107057 }
107058 withoutRowid = !HasRowid(pTab);
107059
@@ -110972,11 +111007,11 @@
111007 }else{
111008 zRight = sqlite3NameFromToken(db, pValue);
111009 }
111010
111011 assert( pId2 );
111012 zDb = pId2->n>0 ? pDb->zDbSName : 0;
111013 if( sqlite3AuthCheck(pParse, SQLITE_PRAGMA, zLeft, zRight, zDb) ){
111014 goto pragma_out;
111015 }
111016
111017 /* Send an SQLITE_FCNTL_PRAGMA file-control to the underlying VFS
@@ -111825,14 +111860,14 @@
111860 int i;
111861 pParse->nMem = 3;
111862 setAllColumnNames(v, 3, azCol); assert( 3==ArraySize(azCol) );
111863 for(i=0; i<db->nDb; i++){
111864 if( db->aDb[i].pBt==0 ) continue;
111865 assert( db->aDb[i].zDbSName!=0 );
111866 sqlite3VdbeMultiLoad(v, 1, "iss",
111867 i,
111868 db->aDb[i].zDbSName,
111869 sqlite3BtreeGetFilename(db->aDb[i].pBt));
111870 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3);
111871 }
111872 }
111873 break;
@@ -112117,11 +112152,11 @@
112152 /* Do the b-tree integrity checks */
112153 sqlite3VdbeAddOp4(v, OP_IntegrityCk, 2, cnt, 1, (char*)aRoot,P4_INTARRAY);
112154 sqlite3VdbeChangeP5(v, (u8)i);
112155 addr = sqlite3VdbeAddOp1(v, OP_IsNull, 2); VdbeCoverage(v);
112156 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0,
112157 sqlite3MPrintf(db, "*** in database %s ***\n", db->aDb[i].zDbSName),
112158 P4_DYNAMIC);
112159 sqlite3VdbeAddOp3(v, OP_Move, 2, 4, 1);
112160 sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 2);
112161 sqlite3VdbeAddOp2(v, OP_ResultRow, 2, 1);
112162 sqlite3VdbeJumpHere(v, addr);
@@ -112556,19 +112591,19 @@
112591 pParse->nMem = 2;
112592 for(i=0; i<db->nDb; i++){
112593 Btree *pBt;
112594 const char *zState = "unknown";
112595 int j;
112596 if( db->aDb[i].zDbSName==0 ) continue;
112597 pBt = db->aDb[i].pBt;
112598 if( pBt==0 || sqlite3BtreePager(pBt)==0 ){
112599 zState = "closed";
112600 }else if( sqlite3_file_control(db, i ? db->aDb[i].zDbSName : 0,
112601 SQLITE_FCNTL_LOCKSTATE, &j)==SQLITE_OK ){
112602 zState = azLockName[j];
112603 }
112604 sqlite3VdbeMultiLoad(v, 1, "ss", db->aDb[i].zDbSName, zState);
112605 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 2);
112606 }
112607 break;
112608 }
112609 #endif
@@ -112700,10 +112735,11 @@
112735 ** But because db->init.busy is set to 1, no VDBE code is generated
112736 ** or executed. All the parser does is build the internal data
112737 ** structures that describe the table, index, or view.
112738 */
112739 int rc;
112740 u8 saved_iDb = db->init.iDb;
112741 sqlite3_stmt *pStmt;
112742 TESTONLY(int rcp); /* Return code from sqlite3_prepare() */
112743
112744 assert( db->init.busy );
112745 db->init.iDb = iDb;
@@ -112710,11 +112746,12 @@
112746 db->init.newTnum = sqlite3Atoi(argv[1]);
112747 db->init.orphanTrigger = 0;
112748 TESTONLY(rcp = ) sqlite3_prepare(db, argv[2], -1, &pStmt, 0);
112749 rc = db->errCode;
112750 assert( (rc&0xFF)==(rcp&0xFF) );
112751 db->init.iDb = saved_iDb;
112752 assert( saved_iDb==0 || (db->flags & SQLITE_Vacuum)!=0 );
112753 if( SQLITE_OK!=rc ){
112754 if( db->init.orphanTrigger ){
112755 assert( iDb==1 );
112756 }else{
112757 pData->rc = rc;
@@ -112734,11 +112771,11 @@
112771 ** constraint for a CREATE TABLE. The index should have already
112772 ** been created when we processed the CREATE TABLE. All we have
112773 ** to do here is record the root page number for that index.
112774 */
112775 Index *pIndex;
112776 pIndex = sqlite3FindIndex(db, argv[0], db->aDb[iDb].zDbSName);
112777 if( pIndex==0 ){
112778 /* This can occur if there exists an index on a TEMP table which
112779 ** has the same name as another index on a permanent index. Since
112780 ** the permanent table is hidden by the TEMP table, we can also
112781 ** safely ignore the index on the permanent table.
@@ -112913,11 +112950,11 @@
112950 assert( db->init.busy );
112951 {
112952 char *zSql;
112953 zSql = sqlite3MPrintf(db,
112954 "SELECT name, rootpage, sql FROM \"%w\".%s ORDER BY rowid",
112955 db->aDb[iDb].zDbSName, zMasterName);
112956 #ifndef SQLITE_OMIT_AUTHORIZATION
112957 {
112958 sqlite3_xauth xAuth;
112959 xAuth = db->xAuth;
112960 db->xAuth = 0;
@@ -113188,11 +113225,11 @@
113225 Btree *pBt = db->aDb[i].pBt;
113226 if( pBt ){
113227 assert( sqlite3BtreeHoldsMutex(pBt) );
113228 rc = sqlite3BtreeSchemaLocked(pBt);
113229 if( rc ){
113230 const char *zDb = db->aDb[i].zDbSName;
113231 sqlite3ErrorWithMsg(db, rc, "database schema is locked: %s", zDb);
113232 testcase( db->flags & SQLITE_ReadUncommitted );
113233 goto end_prepare;
113234 }
113235 }
@@ -114944,11 +114981,11 @@
114981 estWidth = pTab->aCol[iCol].szEst;
114982 }
114983 zOrigTab = pTab->zName;
114984 if( pNC->pParse ){
114985 int iDb = sqlite3SchemaToIndex(pNC->pParse->db, pTab->pSchema);
114986 zOrigDb = pNC->pParse->db->aDb[iDb].zDbSName;
114987 }
114988 #else
114989 if( iCol<0 ){
114990 zType = "INTEGER";
114991 }else{
@@ -117900,11 +117937,11 @@
117937 pSub = 0;
117938 if( zTName && sqlite3StrICmp(zTName, zTabName)!=0 ){
117939 continue;
117940 }
117941 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
117942 zSchemaName = iDb>=0 ? db->aDb[iDb].zDbSName : "*";
117943 }
117944 for(j=0; j<pTab->nCol; j++){
117945 char *zName = pTab->aCol[j].zName;
117946 char *zColname; /* The computed column name */
117947 char *zToFree; /* Malloced string that needs to be freed */
@@ -119612,12 +119649,12 @@
119649 iTabDb = sqlite3SchemaToIndex(db, pTab->pSchema);
119650
119651 #ifndef SQLITE_OMIT_AUTHORIZATION
119652 {
119653 int code = SQLITE_CREATE_TRIGGER;
119654 const char *zDb = db->aDb[iTabDb].zDbSName;
119655 const char *zDbTrig = isTemp ? db->aDb[1].zDbSName : zDb;
119656 if( iTabDb==1 || isTemp ) code = SQLITE_CREATE_TEMP_TRIGGER;
119657 if( sqlite3AuthCheck(pParse, code, zName, pTab->zName, zDbTrig) ){
119658 goto trigger_cleanup;
119659 }
119660 if( sqlite3AuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(iTabDb),0,zDb)){
@@ -119707,11 +119744,11 @@
119744 if( v==0 ) goto triggerfinish_cleanup;
119745 sqlite3BeginWriteOperation(pParse, 0, iDb);
119746 z = sqlite3DbStrNDup(db, (char*)pAll->z, pAll->n);
119747 sqlite3NestedParse(pParse,
119748 "INSERT INTO %Q.%s VALUES('trigger',%Q,%Q,0,'CREATE TRIGGER %q')",
119749 db->aDb[iDb].zDbSName, SCHEMA_TABLE(iDb), zName,
119750 pTrig->table, z);
119751 sqlite3DbFree(db, z);
119752 sqlite3ChangeCookie(pParse, iDb);
119753 sqlite3VdbeAddParseSchemaOp(v, iDb,
119754 sqlite3MPrintf(db, "type='trigger' AND name='%q'", zName));
@@ -119896,11 +119933,11 @@
119933 zDb = pName->a[0].zDatabase;
119934 zName = pName->a[0].zName;
119935 assert( zDb!=0 || sqlite3BtreeHoldsAllMutexes(db) );
119936 for(i=OMIT_TEMPDB; i<db->nDb; i++){
119937 int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */
119938 if( zDb && sqlite3StrICmp(db->aDb[j].zDbSName, zDb) ) continue;
119939 assert( sqlite3SchemaMutexHeld(db, j, 0) );
119940 pTrigger = sqlite3HashFind(&(db->aDb[j].pSchema->trigHash), zName);
119941 if( pTrigger ) break;
119942 }
119943 if( !pTrigger ){
@@ -119942,11 +119979,11 @@
119979 assert( pTable );
119980 assert( pTable->pSchema==pTrigger->pSchema || iDb==1 );
119981 #ifndef SQLITE_OMIT_AUTHORIZATION
119982 {
119983 int code = SQLITE_DROP_TRIGGER;
119984 const char *zDb = db->aDb[iDb].zDbSName;
119985 const char *zTab = SCHEMA_TABLE(iDb);
119986 if( iDb==1 ) code = SQLITE_DROP_TEMP_TRIGGER;
119987 if( sqlite3AuthCheck(pParse, code, pTrigger->zName, pTable->zName, zDb) ||
119988 sqlite3AuthCheck(pParse, SQLITE_DELETE, zTab, 0, zDb) ){
119989 return;
@@ -119958,11 +119995,11 @@
119995 */
119996 assert( pTable!=0 );
119997 if( (v = sqlite3GetVdbe(pParse))!=0 ){
119998 sqlite3NestedParse(pParse,
119999 "DELETE FROM %Q.%s WHERE name=%Q AND type='trigger'",
120000 db->aDb[iDb].zDbSName, SCHEMA_TABLE(iDb), pTrigger->zName
120001 );
120002 sqlite3ChangeCookie(pParse, iDb);
120003 sqlite3VdbeAddOp4(v, OP_DropTrigger, iDb, 0, 0, pTrigger->zName, 0);
120004 }
120005 }
@@ -120061,12 +120098,14 @@
120098 if( pSrc ){
120099 assert( pSrc->nSrc>0 );
120100 pSrc->a[pSrc->nSrc-1].zName = sqlite3DbStrDup(db, pStep->zTarget);
120101 iDb = sqlite3SchemaToIndex(db, pStep->pTrig->pSchema);
120102 if( iDb==0 || iDb>=2 ){
120103 const char *zDb;
120104 assert( iDb<db->nDb );
120105 zDb = db->aDb[iDb].zDbSName;
120106 pSrc->a[pSrc->nSrc-1].zDatabase = sqlite3DbStrDup(db, zDb);
120107 }
120108 }
120109 return pSrc;
120110 }
120111
@@ -120749,11 +120788,11 @@
120788 #ifndef SQLITE_OMIT_AUTHORIZATION
120789 {
120790 int rc;
120791 rc = sqlite3AuthCheck(pParse, SQLITE_UPDATE, pTab->zName,
120792 j<0 ? "ROWID" : pTab->aCol[j].zName,
120793 db->aDb[iDb].zDbSName);
120794 if( rc==SQLITE_DENY ){
120795 goto update_cleanup;
120796 }else if( rc==SQLITE_IGNORE ){
120797 aXRef[j] = -1;
120798 }
@@ -121351,61 +121390,56 @@
121390 */
121391 /* #include "sqliteInt.h" */
121392 /* #include "vdbeInt.h" */
121393
121394 #if !defined(SQLITE_OMIT_VACUUM) && !defined(SQLITE_OMIT_ATTACH)
121395
121396 /*
121397 ** Execute zSql on database db.
121398 **
121399 ** If zSql returns rows, then each row will have exactly one
121400 ** column. (This will only happen if zSql begins with "SELECT".)
121401 ** Take each row of result and call execSql() again recursively.
121402 **
121403 ** The execSqlF() routine does the same thing, except it accepts
121404 ** a format string as its third argument
 
 
 
 
 
121405 */
121406 static int execSql(sqlite3 *db, char **pzErrMsg, const char *zSql){
121407 sqlite3_stmt *pStmt;
121408 int rc;
121409
121410 /* printf("SQL: [%s]\n", zSql); fflush(stdout); */
121411 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
121412 if( rc!=SQLITE_OK ) return rc;
121413 while( SQLITE_ROW==(rc = sqlite3_step(pStmt)) ){
121414 const char *zSubSql = (const char*)sqlite3_column_text(pStmt,0);
121415 assert( sqlite3_strnicmp(zSql,"SELECT",6)==0 );
121416 if( zSubSql ){
121417 assert( zSubSql[0]!='S' );
121418 rc = execSql(db, pzErrMsg, zSubSql);
121419 if( rc!=SQLITE_OK ) break;
121420 }
121421 }
121422 assert( rc!=SQLITE_ROW );
121423 if( rc==SQLITE_DONE ) rc = SQLITE_OK;
121424 if( rc ){
121425 sqlite3SetString(pzErrMsg, db, sqlite3_errmsg(db));
121426 }
121427 (void)sqlite3_finalize(pStmt);
121428 return rc;
121429 }
121430 static int execSqlF(sqlite3 *db, char **pzErrMsg, const char *zSql, ...){
121431 char *z;
121432 va_list ap;
121433 int rc;
121434 va_start(ap, zSql);
121435 z = sqlite3VMPrintf(db, zSql, ap);
121436 va_end(ap);
121437 if( z==0 ) return SQLITE_NOMEM;
121438 rc = execSql(db, pzErrMsg, z);
121439 sqlite3DbFree(db, z);
121440 return rc;
 
 
 
 
 
 
 
 
 
 
 
 
121441 }
121442
121443 /*
121444 ** The VACUUM command is used to clean up the database,
121445 ** collapse free space, etc. It is modelled after the VACUUM command
@@ -121434,35 +121468,36 @@
121468 ** not work if other processes are attached to the original database.
121469 ** And a power loss in between deleting the original and renaming the
121470 ** transient would cause the database file to appear to be deleted
121471 ** following reboot.
121472 */
121473 SQLITE_PRIVATE void sqlite3Vacuum(Parse *pParse, Token *pNm){
121474 Vdbe *v = sqlite3GetVdbe(pParse);
121475 int iDb = pNm ? sqlite3TwoPartName(pParse, pNm, pNm, &pNm) : 0;
121476 if( v && (iDb>=2 || iDb==0) ){
121477 sqlite3VdbeAddOp1(v, OP_Vacuum, iDb);
121478 sqlite3VdbeUsesBtree(v, iDb);
121479 }
121480 return;
121481 }
121482
121483 /*
121484 ** This routine implements the OP_Vacuum opcode of the VDBE.
121485 */
121486 SQLITE_PRIVATE int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db, int iDb){
121487 int rc = SQLITE_OK; /* Return code from service routines */
121488 Btree *pMain; /* The database being vacuumed */
121489 Btree *pTemp; /* The temporary database we vacuum into */
 
121490 int saved_flags; /* Saved value of the db->flags */
121491 int saved_nChange; /* Saved value of db->nChange */
121492 int saved_nTotalChange; /* Saved value of db->nTotalChange */
121493 u8 saved_mTrace; /* Saved trace settings */
121494 Db *pDb = 0; /* Database to detach at end of vacuum */
121495 int isMemDb; /* True if vacuuming a :memory: database */
121496 int nRes; /* Bytes of reserved space at the end of each page */
121497 int nDb; /* Number of attached databases */
121498 const char *zDbMain; /* Schema name of database to vacuum */
121499
121500 if( !db->autoCommit ){
121501 sqlite3SetString(pzErrMsg, db, "cannot VACUUM from within a transaction");
121502 return SQLITE_ERROR;
121503 }
@@ -121476,15 +121511,17 @@
121511 ** disable CHECK and foreign key constraints. */
121512 saved_flags = db->flags;
121513 saved_nChange = db->nChange;
121514 saved_nTotalChange = db->nTotalChange;
121515 saved_mTrace = db->mTrace;
121516 db->flags |= (SQLITE_WriteSchema | SQLITE_IgnoreChecks
121517 | SQLITE_PreferBuiltin | SQLITE_Vacuum);
121518 db->flags &= ~(SQLITE_ForeignKeys | SQLITE_ReverseOrder | SQLITE_CountRows);
121519 db->mTrace = 0;
121520
121521 zDbMain = db->aDb[iDb].zDbSName;
121522 pMain = db->aDb[iDb].pBt;
121523 isMemDb = sqlite3PagerIsMemdb(sqlite3BtreePager(pMain));
121524
121525 /* Attach the temporary database as 'vacuum_db'. The synchronous pragma
121526 ** can be set to 'off' for this file, as it is not recovered if a crash
121527 ** occurs anyway. The integrity of the database is maintained by a
@@ -121498,22 +121535,16 @@
121535 ** empty. Only the journal header is written. Apparently it takes more
121536 ** time to parse and run the PRAGMA to turn journalling off than it does
121537 ** to write the journal header file.
121538 */
121539 nDb = db->nDb;
121540 rc = execSql(db, pzErrMsg, "ATTACH''AS vacuum_db");
 
 
 
 
 
 
 
 
 
121541 if( rc!=SQLITE_OK ) goto end_of_vacuum;
121542 assert( (db->nDb-1)==nDb );
121543 pDb = &db->aDb[nDb];
121544 assert( strcmp(pDb->zDbSName,"vacuum_db")==0 );
121545 pTemp = pDb->pBt;
121546
121547 /* The call to execSql() to attach the temp database has left the file
121548 ** locked (as there was more than one active statement when the transaction
121549 ** to read the schema was concluded. Unlock it here so that this doesn't
121550 ** cause problems for the call to BtreeSetPageSize() below. */
@@ -121530,20 +121561,19 @@
121561 sqlite3CodecGetKey(db, 0, (void**)&zKey, &nKey);
121562 if( nKey ) db->nextPagesize = 0;
121563 }
121564 #endif
121565
121566 sqlite3BtreeSetCacheSize(pTemp, db->aDb[iDb].pSchema->cache_size);
121567 sqlite3BtreeSetSpillSize(pTemp, sqlite3BtreeSetSpillSize(pMain,0));
121568 sqlite3BtreeSetPagerFlags(pTemp, PAGER_SYNCHRONOUS_OFF);
 
121569
121570 /* Begin a transaction and take an exclusive lock on the main database
121571 ** file. This is done before the sqlite3BtreeGetPageSize(pMain) call below,
121572 ** to ensure that we do not try to change the page-size on a WAL database.
121573 */
121574 rc = execSql(db, pzErrMsg, "BEGIN");
121575 if( rc!=SQLITE_OK ) goto end_of_vacuum;
121576 rc = sqlite3BtreeBeginTrans(pMain, 2);
121577 if( rc!=SQLITE_OK ) goto end_of_vacuum;
121578
121579 /* Do not attempt to change the page size for a WAL database */
@@ -121566,68 +121596,52 @@
121596 #endif
121597
121598 /* Query the schema of the main database. Create a mirror schema
121599 ** in the temporary database.
121600 */
121601 db->init.iDb = nDb; /* force new CREATE statements into vacuum_db */
121602 rc = execSqlF(db, pzErrMsg,
121603 "SELECT sql FROM \"%w\".sqlite_master"
121604 " WHERE type='table'AND name<>'sqlite_sequence'"
121605 " AND coalesce(rootpage,1)>0",
121606 zDbMain
121607 );
121608 if( rc!=SQLITE_OK ) goto end_of_vacuum;
121609 rc = execSqlF(db, pzErrMsg,
121610 "SELECT sql FROM \"%w\".sqlite_master"
121611 " WHERE type='index' AND length(sql)>10",
121612 zDbMain
121613 );
121614 if( rc!=SQLITE_OK ) goto end_of_vacuum;
121615 db->init.iDb = 0;
 
 
 
 
 
 
 
121616
121617 /* Loop through the tables in the main database. For each, do
121618 ** an "INSERT INTO vacuum_db.xxx SELECT * FROM main.xxx;" to copy
121619 ** the contents to the temporary database.
121620 */
121621 rc = execSqlF(db, pzErrMsg,
121622 "SELECT'INSERT INTO vacuum_db.'||quote(name)"
121623 "||' SELECT*FROM\"%w\".'||quote(name)"
121624 "FROM vacuum_db.sqlite_master "
121625 "WHERE type='table'AND coalesce(rootpage,1)>0",
121626 zDbMain
 
 
121627 );
121628 assert( (db->flags & SQLITE_Vacuum)!=0 );
121629 db->flags &= ~SQLITE_Vacuum;
121630 if( rc!=SQLITE_OK ) goto end_of_vacuum;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
121631
121632 /* Copy the triggers, views, and virtual tables from the main database
121633 ** over to the temporary database. None of these objects has any
121634 ** associated storage, so all we have to do is copy their entries
121635 ** from the SQLITE_MASTER table.
121636 */
121637 rc = execSqlF(db, pzErrMsg,
121638 "INSERT INTO vacuum_db.sqlite_master"
121639 " SELECT*FROM \"%w\".sqlite_master"
121640 " WHERE type IN('view','trigger')"
121641 " OR(type='table'AND rootpage=0)",
121642 zDbMain
121643 );
121644 if( rc ) goto end_of_vacuum;
121645
121646 /* At this point, there is a write transaction open on both the
121647 ** vacuum database and the main database. Assuming no error occurs,
@@ -121677,10 +121691,11 @@
121691 assert( rc==SQLITE_OK );
121692 rc = sqlite3BtreeSetPageSize(pMain, sqlite3BtreeGetPageSize(pTemp), nRes,1);
121693
121694 end_of_vacuum:
121695 /* Restore the original value of db->flags */
121696 db->init.iDb = 0;
121697 db->flags = saved_flags;
121698 db->nChange = saved_nChange;
121699 db->nTotalChange = saved_nTotalChange;
121700 db->mTrace = saved_mTrace;
121701 sqlite3BtreeSetPageSize(pMain, -1, -1, 1);
@@ -122055,11 +122070,11 @@
122070 ** sqlite_master table, has already been made by sqlite3StartTable().
122071 ** The second call, to obtain permission to create the table, is made now.
122072 */
122073 if( pTable->azModuleArg ){
122074 sqlite3AuthCheck(pParse, SQLITE_CREATE_VTABLE, pTable->zName,
122075 pTable->azModuleArg[0], pParse->db->aDb[iDb].zDbSName);
122076 }
122077 #endif
122078 }
122079
122080 /*
@@ -122119,11 +122134,11 @@
122134 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
122135 sqlite3NestedParse(pParse,
122136 "UPDATE %Q.%s "
122137 "SET type='table', name=%Q, tbl_name=%Q, rootpage=0, sql=%Q "
122138 "WHERE rowid=#%d",
122139 db->aDb[iDb].zDbSName, SCHEMA_TABLE(iDb),
122140 pTab->zName,
122141 pTab->zName,
122142 zStmt,
122143 pParse->regRowid
122144 );
@@ -122229,11 +122244,11 @@
122244 }
122245 pVTable->db = db;
122246 pVTable->pMod = pMod;
122247
122248 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
122249 pTab->azModuleArg[1] = db->aDb[iDb].zDbSName;
122250
122251 /* Invoke the virtual table constructor */
122252 assert( &db->pVtabCtx );
122253 assert( xConstruct );
122254 sCtx.pTab = pTab;
@@ -122393,11 +122408,11 @@
122408 int rc = SQLITE_OK;
122409 Table *pTab;
122410 Module *pMod;
122411 const char *zMod;
122412
122413 pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zDbSName);
122414 assert( pTab && (pTab->tabFlags & TF_Virtual)!=0 && !pTab->pVTable );
122415
122416 /* Locate the required virtual table module */
122417 zMod = pTab->azModuleArg[0];
122418 pMod = (Module*)sqlite3HashFind(&db->aModule, zMod);
@@ -122517,11 +122532,11 @@
122532 */
122533 SQLITE_PRIVATE int sqlite3VtabCallDestroy(sqlite3 *db, int iDb, const char *zTab){
122534 int rc = SQLITE_OK;
122535 Table *pTab;
122536
122537 pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zDbSName);
122538 if( pTab!=0 && ALWAYS(pTab->pVTable!=0) ){
122539 VTable *p;
122540 int (*xDestroy)(sqlite3_vtab *);
122541 for(p=pTab->pVTable; p; p=p->pNext){
122542 assert( p->pVtab );
@@ -125630,11 +125645,11 @@
125645 */
125646 static int isMatchOfColumn(
125647 Expr *pExpr, /* Test this expression */
125648 unsigned char *peOp2 /* OUT: 0 for MATCH, or else an op2 value */
125649 ){
125650 static const struct Op2 {
125651 const char *zOp;
125652 unsigned char eOp2;
125653 } aOp[] = {
125654 { "match", SQLITE_INDEX_CONSTRAINT_MATCH },
125655 { "glob", SQLITE_INDEX_CONSTRAINT_GLOB },
@@ -126615,17 +126630,18 @@
126630 ** These routines walk (recursively) an expression tree and generate
126631 ** a bitmask indicating which tables are used in that expression
126632 ** tree.
126633 */
126634 SQLITE_PRIVATE Bitmask sqlite3WhereExprUsage(WhereMaskSet *pMaskSet, Expr *p){
126635 Bitmask mask;
126636 if( p==0 ) return 0;
126637 if( p->op==TK_COLUMN ){
126638 mask = sqlite3WhereGetMask(pMaskSet, p->iTable);
126639 return mask;
126640 }
126641 assert( !ExprHasProperty(p, EP_TokenOnly) );
126642 mask = p->pRight ? sqlite3WhereExprUsage(pMaskSet, p->pRight) : 0;
126643 if( p->pLeft ) mask |= sqlite3WhereExprUsage(pMaskSet, p->pLeft);
126644 if( ExprHasProperty(p, EP_xIsSelect) ){
126645 mask |= exprSelectUsage(pMaskSet, p->x.pSelect);
126646 }else if( p->x.pList ){
126647 mask |= sqlite3WhereExprListUsage(pMaskSet, p->x.pList);
@@ -131868,29 +131884,33 @@
131884 ** N between YY_MIN_SHIFTREDUCE Shift to an arbitrary state then
131885 ** and YY_MAX_SHIFTREDUCE reduce by rule N-YY_MIN_SHIFTREDUCE.
131886 **
131887 ** N between YY_MIN_REDUCE Reduce by rule N-YY_MIN_REDUCE
131888 ** and YY_MAX_REDUCE
131889 **
131890 ** N == YY_ERROR_ACTION A syntax error has occurred.
131891 **
131892 ** N == YY_ACCEPT_ACTION The parser accepts its input.
131893 **
131894 ** N == YY_NO_ACTION No such action. Denotes unused
131895 ** slots in the yy_action[] table.
131896 **
131897 ** The action table is constructed as a single large table named yy_action[].
131898 ** Given state S and lookahead X, the action is computed as either:
131899 **
131900 ** (A) N = yy_action[ yy_shift_ofst[S] + X ]
131901 ** (B) N = yy_default[S]
131902 **
131903 ** The (A) formula is preferred. The B formula is used instead if:
131904 ** (1) The yy_shift_ofst[S]+X value is out of range, or
131905 ** (2) yy_lookahead[yy_shift_ofst[S]+X] is not equal to X, or
131906 ** (3) yy_shift_ofst[S] equal YY_SHIFT_USE_DFLT.
131907 ** (Implementation note: YY_SHIFT_USE_DFLT is chosen so that
131908 ** YY_SHIFT_USE_DFLT+X will be out of range for all possible lookaheads X.
131909 ** Hence only tests (1) and (2) need to be evaluated.)
131910 **
131911 ** The formulas above are for computing the action when the lookahead is
131912 ** a terminal symbol. If the lookahead is a non-terminal (as occurs after
131913 ** a reduce action) then the yy_reduce_ofst[] array is used in place of
131914 ** the yy_shift_ofst[] array and YY_REDUCE_USE_DFLT is used in place of
131915 ** YY_SHIFT_USE_DFLT.
131916 **
@@ -132211,14 +132231,14 @@
132231 /* 1470 */ 122, 23, 23, 64, 22, 124, 26, 26, 64, 64,
132232 /* 1480 */ 23, 23, 23, 23, 11, 23, 22, 26, 23, 22,
132233 /* 1490 */ 24, 1, 23, 22, 26, 122, 24, 23, 22, 122,
132234 /* 1500 */ 23, 23, 22, 122, 122, 23, 15,
132235 };
132236 #define YY_SHIFT_USE_DFLT (1507)
132237 #define YY_SHIFT_COUNT (442)
132238 #define YY_SHIFT_MIN (-94)
132239 #define YY_SHIFT_MAX (1491)
132240 static const short yy_shift_ofst[] = {
132241 /* 0 */ 40, 564, 869, 577, 725, 725, 725, 725, 690, -19,
132242 /* 10 */ 16, 16, 100, 725, 725, 725, 725, 725, 725, 725,
132243 /* 20 */ 841, 841, 538, 507, 684, 565, 61, 137, 172, 207,
132244 /* 30 */ 242, 277, 312, 347, 382, 424, 424, 424, 424, 424,
@@ -132227,16 +132247,16 @@
132247 /* 60 */ 725, 725, 725, 725, 725, 725, 725, 725, 725, 725,
132248 /* 70 */ 725, 725, 725, 725, 725, 725, 725, 725, 725, 725,
132249 /* 80 */ 725, 725, 725, 725, 821, 725, 725, 725, 725, 725,
132250 /* 90 */ 725, 725, 725, 725, 725, 725, 725, 725, 952, 711,
132251 /* 100 */ 711, 711, 711, 711, 766, 23, 32, 924, 637, 825,
132252 /* 110 */ 837, 837, 924, 73, 183, -51, 1507, 1507, 1507, 501,
132253 /* 120 */ 501, 501, 903, 903, 632, 205, 241, 924, 924, 924,
132254 /* 130 */ 924, 924, 924, 924, 924, 924, 924, 924, 924, 924,
132255 /* 140 */ 924, 924, 924, 924, 924, 924, 924, 192, 1027, 1106,
132256 /* 150 */ 1106, 183, 176, 176, 176, 176, 176, 176, 1507, 1507,
132257 /* 160 */ 1507, 880, -94, -94, 578, 734, 99, 730, 769, 349,
132258 /* 170 */ 924, 924, 924, 924, 924, 924, 924, 924, 924, 924,
132259 /* 180 */ 924, 924, 924, 924, 924, 924, 924, 954, 954, 954,
132260 /* 190 */ 924, 924, 622, 924, 924, 924, -18, 924, 924, 914,
132261 /* 200 */ 924, 924, 924, 924, 924, 924, 924, 924, 924, 924,
132262 /* 210 */ 441, 1020, 1107, 1107, 1107, 569, 45, 217, 510, 423,
@@ -132246,12 +132266,12 @@
132266 /* 250 */ 1297, 1183, 1277, 1285, 1285, 1183, 1176, 1297, 1182, 1250,
132267 /* 260 */ 1176, 1176, 1297, 1311, 1176, 1297, 1176, 1297, 1311, 1234,
132268 /* 270 */ 1234, 1234, 1267, 1311, 1234, 1244, 1234, 1267, 1234, 1234,
132269 /* 280 */ 1232, 1247, 1232, 1247, 1232, 1247, 1232, 1247, 1176, 1334,
132270 /* 290 */ 1176, 1235, 1311, 1318, 1318, 1311, 1248, 1253, 1245, 1249,
132271 /* 300 */ 1183, 1355, 1357, 1368, 1368, 1378, 1378, 1378, 1378, 1507,
132272 /* 310 */ 1507, 1507, 1507, 1507, 1507, 1507, 1507, 451, 936, 816,
132273 /* 320 */ 888, 1069, 799, 1111, 1197, 1193, 1201, 1202, 1203, 1213,
132274 /* 330 */ 1134, 1117, 1230, 497, 1218, 1219, 1154, 1223, 1115, 1120,
132275 /* 340 */ 1231, 1164, 1160, 1392, 1394, 1376, 1257, 1385, 1307, 1386,
132276 /* 350 */ 1383, 1388, 1292, 1282, 1303, 1294, 1395, 1293, 1403, 1419,
132277 /* 360 */ 1298, 1291, 1389, 1390, 1314, 1372, 1365, 1308, 1430, 1427,
@@ -133200,54 +133220,51 @@
133220
133221 if( stateno>=YY_MIN_REDUCE ) return stateno;
133222 assert( stateno <= YY_SHIFT_COUNT );
133223 do{
133224 i = yy_shift_ofst[stateno];
 
133225 assert( iLookAhead!=YYNOCODE );
133226 i += iLookAhead;
133227 if( i<0 || i>=YY_ACTTAB_COUNT || yy_lookahead[i]!=iLookAhead ){
 
133228 #ifdef YYFALLBACK
133229 YYCODETYPE iFallback; /* Fallback token */
133230 if( iLookAhead<sizeof(yyFallback)/sizeof(yyFallback[0])
133231 && (iFallback = yyFallback[iLookAhead])!=0 ){
133232 #ifndef NDEBUG
133233 if( yyTraceFILE ){
133234 fprintf(yyTraceFILE, "%sFALLBACK %s => %s\n",
133235 yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]);
133236 }
133237 #endif
133238 assert( yyFallback[iFallback]==0 ); /* Fallback loop must terminate */
133239 iLookAhead = iFallback;
133240 continue;
133241 }
133242 #endif
133243 #ifdef YYWILDCARD
133244 {
133245 int j = i - iLookAhead + YYWILDCARD;
133246 if(
133247 #if YY_SHIFT_MIN+YYWILDCARD<0
133248 j>=0 &&
133249 #endif
133250 #if YY_SHIFT_MAX+YYWILDCARD>=YY_ACTTAB_COUNT
133251 j<YY_ACTTAB_COUNT &&
133252 #endif
133253 yy_lookahead[j]==YYWILDCARD && iLookAhead>0
133254 ){
133255 #ifndef NDEBUG
133256 if( yyTraceFILE ){
133257 fprintf(yyTraceFILE, "%sWILDCARD %s => %s\n",
133258 yyTracePrompt, yyTokenName[iLookAhead],
133259 yyTokenName[YYWILDCARD]);
133260 }
133261 #endif /* NDEBUG */
133262 return yy_action[j];
 
133263 }
133264 }
133265 #endif /* YYWILDCARD */
 
133266 return yy_default[stateno];
133267 }else{
133268 return yy_action[i];
133269 }
133270 }while(1);
@@ -134679,12 +134696,14 @@
134696 break;
134697 case 213: /* cmd ::= DROP INDEX ifexists fullname */
134698 {sqlite3DropIndex(pParse, yymsp[0].minor.yy185, yymsp[-1].minor.yy194);}
134699 break;
134700 case 214: /* cmd ::= VACUUM */
134701 {sqlite3Vacuum(pParse,0);}
134702 break;
134703 case 215: /* cmd ::= VACUUM nm */
134704 {sqlite3Vacuum(pParse,&yymsp[0].minor.yy0);}
134705 break;
134706 case 216: /* cmd ::= PRAGMA nm dbnm */
134707 {sqlite3Pragma(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,0,0);}
134708 break;
134709 case 217: /* cmd ::= PRAGMA nm dbnm EQ nmnum */
@@ -136006,18 +136025,30 @@
136025 assert( pParse->pNewTable==0 );
136026 assert( pParse->pNewTrigger==0 );
136027 assert( pParse->nVar==0 );
136028 assert( pParse->nzVar==0 );
136029 assert( pParse->azVar==0 );
136030 while( 1 ){
136031 assert( i>=0 );
136032 if( zSql[i]!=0 ){
136033 pParse->sLastToken.z = &zSql[i];
136034 pParse->sLastToken.n = sqlite3GetToken((u8*)&zSql[i],&tokenType);
136035 i += pParse->sLastToken.n;
136036 if( i>mxSqlLen ){
136037 pParse->rc = SQLITE_TOOBIG;
136038 break;
136039 }
136040 }else{
136041 /* Upon reaching the end of input, call the parser two more times
136042 ** with tokens TK_SEMI and 0, in that order. */
136043 if( lastTokenParsed==TK_SEMI ){
136044 tokenType = 0;
136045 }else if( lastTokenParsed==0 ){
136046 break;
136047 }else{
136048 tokenType = TK_SEMI;
136049 }
136050 }
136051 if( tokenType>=TK_SPACE ){
136052 assert( tokenType==TK_SPACE || tokenType==TK_ILLEGAL );
136053 if( db->u1.isInterrupted ){
136054 pParse->rc = SQLITE_INTERRUPT;
@@ -136034,19 +136065,10 @@
136065 if( pParse->rc!=SQLITE_OK || db->mallocFailed ) break;
136066 }
136067 }
136068 assert( nErr==0 );
136069 pParse->zTail = &zSql[i];
 
 
 
 
 
 
 
 
 
136070 #ifdef YYTRACKMAXSTACKDEPTH
136071 sqlite3_mutex_enter(sqlite3MallocMutex());
136072 sqlite3StatusHighwater(SQLITE_STATUS_PARSER_STACK,
136073 sqlite3ParserStackPeak(pEngine)
136074 );
@@ -137282,10 +137304,15 @@
137304 SQLITE_API int SQLITE_CDECL sqlite3_db_config(sqlite3 *db, int op, ...){
137305 va_list ap;
137306 int rc;
137307 va_start(ap, op);
137308 switch( op ){
137309 case SQLITE_DBCONFIG_MAINDBNAME: {
137310 db->aDb[0].zDbSName = va_arg(ap,char*);
137311 rc = SQLITE_OK;
137312 break;
137313 }
137314 case SQLITE_DBCONFIG_LOOKASIDE: {
137315 void *pBuf = va_arg(ap, void*); /* IMP: R-26835-10964 */
137316 int sz = va_arg(ap, int); /* IMP: R-47871-25994 */
137317 int cnt = va_arg(ap, int); /* IMP: R-04460-53386 */
137318 rc = setupLookaside(db, pBuf, sz, cnt);
@@ -139425,13 +139452,13 @@
139452 db->aDb[1].pSchema = sqlite3SchemaGet(db, 0);
139453
139454 /* The default safety_level for the main database is FULL; for the temp
139455 ** database it is OFF. This matches the pager layer defaults.
139456 */
139457 db->aDb[0].zDbSName = "main";
139458 db->aDb[0].safety_level = SQLITE_DEFAULT_SYNCHRONOUS+1;
139459 db->aDb[1].zDbSName = "temp";
139460 db->aDb[1].safety_level = PAGER_SYNCHRONOUS_OFF;
139461
139462 db->magic = SQLITE_MAGIC_OPEN;
139463 if( db->mallocFailed ){
139464 goto opendb_out;
@@ -140388,11 +140415,11 @@
140415 */
140416 SQLITE_PRIVATE Btree *sqlite3DbNameToBtree(sqlite3 *db, const char *zDbName){
140417 int i;
140418 for(i=0; i<db->nDb; i++){
140419 if( db->aDb[i].pBt
140420 && (zDbName==0 || sqlite3StrICmp(zDbName, db->aDb[i].zDbSName)==0)
140421 ){
140422 return db->aDb[i].pBt;
140423 }
140424 }
140425 return 0;
@@ -164754,19 +164781,25 @@
164781 /*
164782 ** Open an RBU handle to perform an RBU vacuum on database file zTarget.
164783 ** An RBU vacuum is similar to SQLite's built-in VACUUM command, except
164784 ** that it can be suspended and resumed like an RBU update.
164785 **
164786 ** The second argument to this function identifies a database in which
164787 ** to store the state of the RBU vacuum operation if it is suspended. The
164788 ** first time sqlite3rbu_vacuum() is called, to start an RBU vacuum
164789 ** operation, the state database should either not exist or be empty
164790 ** (contain no tables). If an RBU vacuum is suspended by calling
164791 ** sqlite3rbu_close() on the RBU handle before sqlite3rbu_step() has
164792 ** returned SQLITE_DONE, the vacuum state is stored in the state database.
164793 ** The vacuum can be resumed by calling this function to open a new RBU
164794 ** handle specifying the same target and state databases.
164795 **
164796 ** If the second argument passed to this function is NULL, then the
164797 ** name of the state database is "<database>-vacuum", where <database>
164798 ** is the name of the target database file. In this case, on UNIX, if the
164799 ** state database is not already present in the file-system, it is created
164800 ** with the same permissions as the target db is made.
164801 **
164802 ** This function does not delete the state database after an RBU vacuum
164803 ** is completed, even if it created it. However, if the call to
164804 ** sqlite3rbu_close() returns any value other than SQLITE_OK, the contents
164805 ** of the state tables within the state database are zeroed. This way,
@@ -167255,19 +167288,22 @@
167288 /*
167289 ** Open the database handle and attach the RBU database as "rbu". If an
167290 ** error occurs, leave an error code and message in the RBU handle.
167291 */
167292 static void rbuOpenDatabase(sqlite3rbu *p){
167293 assert( p->rc || (p->dbMain==0 && p->dbRbu==0) );
167294 assert( p->rc || rbuIsVacuum(p) || p->zTarget!=0 );
 
167295
167296 /* Open the RBU database */
167297 p->dbRbu = rbuOpenDbhandle(p, p->zRbu, 1);
167298
167299 if( p->rc==SQLITE_OK && rbuIsVacuum(p) ){
167300 sqlite3_file_control(p->dbRbu, "main", SQLITE_FCNTL_RBUCNT, (void*)p);
167301 if( p->zState==0 ){
167302 const char *zFile = sqlite3_db_filename(p->dbRbu, "main");
167303 p->zState = rbuMPrintf(p, "file://%s-vacuum?modeof=%s", zFile, zFile);
167304 }
167305 }
167306
167307 /* If using separate RBU and state databases, attach the state database to
167308 ** the RBU db handle now. */
167309 if( p->zState ){
@@ -168398,12 +168434,11 @@
168434 const char *zState
168435 ){
168436 sqlite3rbu *p;
168437 size_t nTarget = zTarget ? strlen(zTarget) : 0;
168438 size_t nRbu = strlen(zRbu);
168439 size_t nByte = sizeof(sqlite3rbu) + nTarget+1 + nRbu+1;
 
168440
168441 p = (sqlite3rbu*)sqlite3_malloc64(nByte);
168442 if( p ){
168443 RbuState *pState = 0;
168444
@@ -168421,12 +168456,11 @@
168456 }
168457 p->zRbu = pCsr;
168458 memcpy(p->zRbu, zRbu, nRbu+1);
168459 pCsr += nRbu+1;
168460 if( zState ){
168461 p->zState = rbuMPrintf(p, "%s", zState);
 
168462 }
168463 rbuOpenDatabase(p);
168464 }
168465
168466 if( p->rc==SQLITE_OK ){
@@ -168531,19 +168565,34 @@
168565 rbuFreeState(pState);
168566 }
168567
168568 return p;
168569 }
168570
168571 /*
168572 ** Allocate and return an RBU handle with all fields zeroed except for the
168573 ** error code, which is set to SQLITE_MISUSE.
168574 */
168575 static sqlite3rbu *rbuMisuseError(void){
168576 sqlite3rbu *pRet;
168577 pRet = sqlite3_malloc64(sizeof(sqlite3rbu));
168578 if( pRet ){
168579 memset(pRet, 0, sizeof(sqlite3rbu));
168580 pRet->rc = SQLITE_MISUSE;
168581 }
168582 return pRet;
168583 }
168584
168585 /*
168586 ** Open and return a new RBU handle.
168587 */
168588 SQLITE_API sqlite3rbu *SQLITE_STDCALL sqlite3rbu_open(
168589 const char *zTarget,
168590 const char *zRbu,
168591 const char *zState
168592 ){
168593 if( zTarget==0 || zRbu==0 ){ return rbuMisuseError(); }
168594 /* TODO: Check that zTarget and zRbu are non-NULL */
168595 return openRbuHandle(zTarget, zRbu, zState);
168596 }
168597
168598 /*
@@ -168551,10 +168600,11 @@
168600 */
168601 SQLITE_API sqlite3rbu *SQLITE_STDCALL sqlite3rbu_vacuum(
168602 const char *zTarget,
168603 const char *zState
168604 ){
168605 if( zTarget==0 ){ return rbuMisuseError(); }
168606 /* TODO: Check that both arguments are non-NULL */
168607 return openRbuHandle(0, zTarget, zState);
168608 }
168609
168610 /*
@@ -168628,10 +168678,11 @@
168678 sqlite3_free(p->aFrame);
168679
168680 rbuEditErrmsg(p);
168681 rc = p->rc;
168682 *pzErrmsg = p->zErrmsg;
168683 sqlite3_free(p->zState);
168684 sqlite3_free(p);
168685 }else{
168686 rc = SQLITE_NOMEM;
168687 *pzErrmsg = 0;
168688 }
@@ -170239,11 +170290,11 @@
170290 zSql = sqlite3_mprintf(
170291 "SELECT 'sqlite_master' AS name, 1 AS rootpage, 'table' AS type"
170292 " UNION ALL "
170293 "SELECT name, rootpage, type"
170294 " FROM \"%w\".%s WHERE rootpage!=0"
170295 " ORDER BY name", pTab->db->aDb[pCsr->iDb].zDbSName, zMaster);
170296 if( zSql==0 ){
170297 return SQLITE_NOMEM_BKPT;
170298 }else{
170299 rc = sqlite3_prepare_v2(pTab->db, zSql, -1, &pCsr->pStmt, 0);
170300 sqlite3_free(zSql);
@@ -170293,11 +170344,11 @@
170344 sqlite3_result_int(ctx, pCsr->szPage);
170345 break;
170346 default: { /* schema */
170347 sqlite3 *db = sqlite3_context_db_handle(ctx);
170348 int iDb = pCsr->iDb;
170349 sqlite3_result_text(ctx, db->aDb[iDb].zDbSName, -1, SQLITE_STATIC);
170350 break;
170351 }
170352 }
170353 return SQLITE_OK;
170354 }
@@ -178530,10 +178581,11 @@
178581 static void sqlite3Fts5ParseNearsetFree(Fts5ExprNearset*);
178582 static void sqlite3Fts5ParseNodeFree(Fts5ExprNode*);
178583
178584 static void sqlite3Fts5ParseSetDistance(Fts5Parse*, Fts5ExprNearset*, Fts5Token*);
178585 static void sqlite3Fts5ParseSetColset(Fts5Parse*, Fts5ExprNearset*, Fts5Colset*);
178586 static Fts5Colset *sqlite3Fts5ParseColsetInvert(Fts5Parse*, Fts5Colset*);
178587 static void sqlite3Fts5ParseFinished(Fts5Parse *pParse, Fts5ExprNode *p);
178588 static void sqlite3Fts5ParseNear(Fts5Parse *pParse, Fts5Token*);
178589
178590 /*
178591 ** End of interface to code in fts5_expr.c.
@@ -178587,16 +178639,17 @@
178639 #define FTS5_NOT 3
178640 #define FTS5_TERM 4
178641 #define FTS5_COLON 5
178642 #define FTS5_LP 6
178643 #define FTS5_RP 7
178644 #define FTS5_MINUS 8
178645 #define FTS5_LCP 9
178646 #define FTS5_RCP 10
178647 #define FTS5_STRING 11
178648 #define FTS5_COMMA 12
178649 #define FTS5_PLUS 13
178650 #define FTS5_STAR 14
178651
178652 /*
178653 ** 2000-05-29
178654 **
178655 ** The author disclaims copyright to this source code. In place of
@@ -178706,39 +178759,39 @@
178759 #ifndef INTERFACE
178760 # define INTERFACE 1
178761 #endif
178762 /************* Begin control #defines *****************************************/
178763 #define fts5YYCODETYPE unsigned char
178764 #define fts5YYNOCODE 28
178765 #define fts5YYACTIONTYPE unsigned char
178766 #define sqlite3Fts5ParserFTS5TOKENTYPE Fts5Token
178767 typedef union {
178768 int fts5yyinit;
178769 sqlite3Fts5ParserFTS5TOKENTYPE fts5yy0;
178770 int fts5yy4;
178771 Fts5Colset* fts5yy11;
178772 Fts5ExprNode* fts5yy24;
178773 Fts5ExprNearset* fts5yy46;
178774 Fts5ExprPhrase* fts5yy53;
178775 } fts5YYMINORTYPE;
178776 #ifndef fts5YYSTACKDEPTH
178777 #define fts5YYSTACKDEPTH 100
178778 #endif
178779 #define sqlite3Fts5ParserARG_SDECL Fts5Parse *pParse;
178780 #define sqlite3Fts5ParserARG_PDECL ,Fts5Parse *pParse
178781 #define sqlite3Fts5ParserARG_FETCH Fts5Parse *pParse = fts5yypParser->pParse
178782 #define sqlite3Fts5ParserARG_STORE fts5yypParser->pParse = pParse
178783 #define fts5YYNSTATE 29
178784 #define fts5YYNRULE 26
178785 #define fts5YY_MAX_SHIFT 28
178786 #define fts5YY_MIN_SHIFTREDUCE 45
178787 #define fts5YY_MAX_SHIFTREDUCE 70
178788 #define fts5YY_MIN_REDUCE 71
178789 #define fts5YY_MAX_REDUCE 96
178790 #define fts5YY_ERROR_ACTION 97
178791 #define fts5YY_ACCEPT_ACTION 98
178792 #define fts5YY_NO_ACTION 99
178793 /************* End control #defines *******************************************/
178794
178795 /* Define the fts5yytestcase() macro to be a no-op if is not already defined
178796 ** otherwise.
178797 **
@@ -178766,29 +178819,33 @@
178819 ** N between fts5YY_MIN_SHIFTREDUCE Shift to an arbitrary state then
178820 ** and fts5YY_MAX_SHIFTREDUCE reduce by rule N-fts5YY_MIN_SHIFTREDUCE.
178821 **
178822 ** N between fts5YY_MIN_REDUCE Reduce by rule N-fts5YY_MIN_REDUCE
178823 ** and fts5YY_MAX_REDUCE
178824 **
178825 ** N == fts5YY_ERROR_ACTION A syntax error has occurred.
178826 **
178827 ** N == fts5YY_ACCEPT_ACTION The parser accepts its input.
178828 **
178829 ** N == fts5YY_NO_ACTION No such action. Denotes unused
178830 ** slots in the fts5yy_action[] table.
178831 **
178832 ** The action table is constructed as a single large table named fts5yy_action[].
178833 ** Given state S and lookahead X, the action is computed as either:
178834 **
178835 ** (A) N = fts5yy_action[ fts5yy_shift_ofst[S] + X ]
178836 ** (B) N = fts5yy_default[S]
178837 **
178838 ** The (A) formula is preferred. The B formula is used instead if:
178839 ** (1) The fts5yy_shift_ofst[S]+X value is out of range, or
178840 ** (2) fts5yy_lookahead[fts5yy_shift_ofst[S]+X] is not equal to X, or
178841 ** (3) fts5yy_shift_ofst[S] equal fts5YY_SHIFT_USE_DFLT.
178842 ** (Implementation note: fts5YY_SHIFT_USE_DFLT is chosen so that
178843 ** fts5YY_SHIFT_USE_DFLT+X will be out of range for all possible lookaheads X.
178844 ** Hence only tests (1) and (2) need to be evaluated.)
178845 **
178846 ** The formulas above are for computing the action when the lookahead is
178847 ** a terminal symbol. If the lookahead is a non-terminal (as occurs after
178848 ** a reduce action) then the fts5yy_reduce_ofst[] array is used in place of
178849 ** the fts5yy_shift_ofst[] array and fts5YY_REDUCE_USE_DFLT is used in place of
178850 ** fts5YY_SHIFT_USE_DFLT.
178851 **
@@ -178802,52 +178859,54 @@
178859 ** fts5yy_reduce_ofst[] For each state, the offset into fts5yy_action for
178860 ** shifting non-terminals after a reduce.
178861 ** fts5yy_default[] Default action for each state.
178862 **
178863 *********** Begin parsing tables **********************************************/
178864 #define fts5YY_ACTTAB_COUNT (85)
178865 static const fts5YYACTIONTYPE fts5yy_action[] = {
178866 /* 0 */ 98, 16, 51, 5, 53, 27, 83, 7, 26, 15,
178867 /* 10 */ 51, 5, 53, 27, 13, 69, 26, 48, 51, 5,
178868 /* 20 */ 53, 27, 19, 11, 26, 9, 20, 51, 5, 53,
178869 /* 30 */ 27, 13, 22, 26, 28, 51, 5, 53, 27, 68,
178870 /* 40 */ 1, 26, 19, 11, 17, 9, 52, 10, 53, 27,
178871 /* 50 */ 23, 24, 26, 54, 3, 4, 2, 26, 6, 21,
178872 /* 60 */ 49, 71, 3, 4, 2, 7, 56, 59, 55, 59,
178873 /* 70 */ 4, 2, 12, 69, 58, 60, 18, 67, 62, 69,
178874 /* 80 */ 25, 66, 8, 14, 2,
178875 };
178876 static const fts5YYCODETYPE fts5yy_lookahead[] = {
178877 /* 0 */ 16, 17, 18, 19, 20, 21, 5, 6, 24, 17,
178878 /* 10 */ 18, 19, 20, 21, 11, 14, 24, 17, 18, 19,
178879 /* 20 */ 20, 21, 8, 9, 24, 11, 17, 18, 19, 20,
178880 /* 30 */ 21, 11, 12, 24, 17, 18, 19, 20, 21, 26,
178881 /* 40 */ 6, 24, 8, 9, 22, 11, 18, 11, 20, 21,
178882 /* 50 */ 24, 25, 24, 20, 1, 2, 3, 24, 23, 24,
178883 /* 60 */ 7, 0, 1, 2, 3, 6, 10, 11, 10, 11,
178884 /* 70 */ 2, 3, 9, 14, 11, 11, 22, 26, 7, 14,
178885 /* 80 */ 13, 11, 5, 11, 3,
178886 };
178887 #define fts5YY_SHIFT_USE_DFLT (85)
178888 #define fts5YY_SHIFT_COUNT (28)
178889 #define fts5YY_SHIFT_MIN (0)
178890 #define fts5YY_SHIFT_MAX (81)
178891 static const unsigned char fts5yy_shift_ofst[] = {
178892 /* 0 */ 34, 34, 34, 34, 34, 14, 20, 3, 36, 1,
178893 /* 10 */ 59, 64, 64, 65, 65, 53, 61, 56, 58, 63,
178894 /* 20 */ 68, 67, 70, 67, 71, 72, 67, 77, 81,
178895 };
178896 #define fts5YY_REDUCE_USE_DFLT (-17)
178897 #define fts5YY_REDUCE_COUNT (14)
178898 #define fts5YY_REDUCE_MIN (-16)
178899 #define fts5YY_REDUCE_MAX (54)
178900 static const signed char fts5yy_reduce_ofst[] = {
178901 /* 0 */ -16, -8, 0, 9, 17, 28, 26, 35, 33, 13,
178902 /* 10 */ 13, 22, 54, 13, 51,
178903 };
178904 static const fts5YYACTIONTYPE fts5yy_default[] = {
178905 /* 0 */ 97, 97, 97, 97, 97, 76, 91, 97, 97, 96,
178906 /* 10 */ 96, 97, 97, 96, 96, 97, 97, 97, 97, 97,
178907 /* 20 */ 73, 89, 97, 90, 97, 97, 87, 97, 72,
178908 };
178909 /********** End of lemon-generated parsing tables *****************************/
178910
178911 /* The next table maps tokens (terminal symbols) into fallback tokens.
178912 ** If a construct like the following:
@@ -178950,15 +179009,15 @@
179009 /* For tracing shifts, the names of all terminals and nonterminals
179010 ** are required. The following table supplies these names */
179011 static const char *const fts5yyTokenName[] = {
179012 "$", "OR", "AND", "NOT",
179013 "TERM", "COLON", "LP", "RP",
179014 "MINUS", "LCP", "RCP", "STRING",
179015 "COMMA", "PLUS", "STAR", "error",
179016 "input", "expr", "cnearset", "exprlist",
179017 "nearset", "colset", "colsetlist", "nearphrases",
179018 "phrase", "neardist_opt", "star_opt",
179019 };
179020 #endif /* NDEBUG */
179021
179022 #ifndef NDEBUG
179023 /* For tracing reduce actions, the names of all rules are required.
@@ -178972,24 +179031,26 @@
179031 /* 5 */ "expr ::= exprlist",
179032 /* 6 */ "exprlist ::= cnearset",
179033 /* 7 */ "exprlist ::= exprlist cnearset",
179034 /* 8 */ "cnearset ::= nearset",
179035 /* 9 */ "cnearset ::= colset COLON nearset",
179036 /* 10 */ "colset ::= MINUS LCP colsetlist RCP",
179037 /* 11 */ "colset ::= LCP colsetlist RCP",
179038 /* 12 */ "colset ::= STRING",
179039 /* 13 */ "colset ::= MINUS STRING",
179040 /* 14 */ "colsetlist ::= colsetlist STRING",
179041 /* 15 */ "colsetlist ::= STRING",
179042 /* 16 */ "nearset ::= phrase",
179043 /* 17 */ "nearset ::= STRING LP nearphrases neardist_opt RP",
179044 /* 18 */ "nearphrases ::= phrase",
179045 /* 19 */ "nearphrases ::= nearphrases phrase",
179046 /* 20 */ "neardist_opt ::=",
179047 /* 21 */ "neardist_opt ::= COMMA STRING",
179048 /* 22 */ "phrase ::= phrase PLUS STRING star_opt",
179049 /* 23 */ "phrase ::= STRING star_opt",
179050 /* 24 */ "star_opt ::= STAR",
179051 /* 25 */ "star_opt ::=",
179052 };
179053 #endif /* NDEBUG */
179054
179055
179056 #if fts5YYSTACKDEPTH<=0
@@ -179095,37 +179156,37 @@
179156 ** Note: during a reduce, the only symbols destroyed are those
179157 ** which appear on the RHS of the rule, but which are *not* used
179158 ** inside the C code.
179159 */
179160 /********* Begin destructor definitions ***************************************/
179161 case 16: /* input */
179162 {
179163 (void)pParse;
179164 }
179165 break;
179166 case 17: /* expr */
179167 case 18: /* cnearset */
179168 case 19: /* exprlist */
179169 {
179170 sqlite3Fts5ParseNodeFree((fts5yypminor->fts5yy24));
179171 }
179172 break;
179173 case 20: /* nearset */
179174 case 23: /* nearphrases */
179175 {
179176 sqlite3Fts5ParseNearsetFree((fts5yypminor->fts5yy46));
179177 }
179178 break;
179179 case 21: /* colset */
179180 case 22: /* colsetlist */
179181 {
179182 sqlite3_free((fts5yypminor->fts5yy11));
179183 }
179184 break;
179185 case 24: /* phrase */
179186 {
179187 sqlite3Fts5ParsePhraseFree((fts5yypminor->fts5yy53));
179188 }
179189 break;
179190 /********* End destructor definitions *****************************************/
179191 default: break; /* If no destructor action specified: do nothing */
179192 }
@@ -179198,54 +179259,51 @@
179259
179260 if( stateno>=fts5YY_MIN_REDUCE ) return stateno;
179261 assert( stateno <= fts5YY_SHIFT_COUNT );
179262 do{
179263 i = fts5yy_shift_ofst[stateno];
 
179264 assert( iLookAhead!=fts5YYNOCODE );
179265 i += iLookAhead;
179266 if( i<0 || i>=fts5YY_ACTTAB_COUNT || fts5yy_lookahead[i]!=iLookAhead ){
 
179267 #ifdef fts5YYFALLBACK
179268 fts5YYCODETYPE iFallback; /* Fallback token */
179269 if( iLookAhead<sizeof(fts5yyFallback)/sizeof(fts5yyFallback[0])
179270 && (iFallback = fts5yyFallback[iLookAhead])!=0 ){
179271 #ifndef NDEBUG
179272 if( fts5yyTraceFILE ){
179273 fprintf(fts5yyTraceFILE, "%sFALLBACK %s => %s\n",
179274 fts5yyTracePrompt, fts5yyTokenName[iLookAhead], fts5yyTokenName[iFallback]);
179275 }
179276 #endif
179277 assert( fts5yyFallback[iFallback]==0 ); /* Fallback loop must terminate */
179278 iLookAhead = iFallback;
179279 continue;
179280 }
179281 #endif
179282 #ifdef fts5YYWILDCARD
179283 {
179284 int j = i - iLookAhead + fts5YYWILDCARD;
179285 if(
179286 #if fts5YY_SHIFT_MIN+fts5YYWILDCARD<0
179287 j>=0 &&
179288 #endif
179289 #if fts5YY_SHIFT_MAX+fts5YYWILDCARD>=fts5YY_ACTTAB_COUNT
179290 j<fts5YY_ACTTAB_COUNT &&
179291 #endif
179292 fts5yy_lookahead[j]==fts5YYWILDCARD && iLookAhead>0
179293 ){
179294 #ifndef NDEBUG
179295 if( fts5yyTraceFILE ){
179296 fprintf(fts5yyTraceFILE, "%sWILDCARD %s => %s\n",
179297 fts5yyTracePrompt, fts5yyTokenName[iLookAhead],
179298 fts5yyTokenName[fts5YYWILDCARD]);
179299 }
179300 #endif /* NDEBUG */
179301 return fts5yy_action[j];
 
179302 }
179303 }
179304 #endif /* fts5YYWILDCARD */
 
179305 return fts5yy_default[stateno];
179306 }else{
179307 return fts5yy_action[i];
179308 }
179309 }while(1);
@@ -179368,34 +179426,36 @@
179426 */
179427 static const struct {
179428 fts5YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */
179429 unsigned char nrhs; /* Number of right-hand side symbols in the rule */
179430 } fts5yyRuleInfo[] = {
 
 
 
 
 
179431 { 16, 1 },
179432 { 17, 3 },
179433 { 17, 3 },
179434 { 17, 3 },
179435 { 17, 3 },
179436 { 17, 1 },
179437 { 19, 1 },
179438 { 19, 2 },
179439 { 18, 1 },
179440 { 18, 3 },
179441 { 21, 4 },
179442 { 21, 3 },
179443 { 21, 1 },
 
179444 { 21, 2 },
179445 { 22, 2 },
 
 
179446 { 22, 1 },
179447 { 20, 1 },
179448 { 20, 5 },
179449 { 23, 1 },
 
179450 { 23, 2 },
 
179451 { 25, 0 },
179452 { 25, 2 },
179453 { 24, 4 },
179454 { 24, 2 },
179455 { 26, 1 },
179456 { 26, 0 },
179457 };
179458
179459 static void fts5yy_accept(fts5yyParser*); /* Forward Declaration */
179460
179461 /*
@@ -179456,124 +179516,135 @@
179516 ** break;
179517 */
179518 /********** Begin reduce actions **********************************************/
179519 fts5YYMINORTYPE fts5yylhsminor;
179520 case 0: /* input ::= expr */
179521 { sqlite3Fts5ParseFinished(pParse, fts5yymsp[0].minor.fts5yy24); }
179522 break;
179523 case 1: /* expr ::= expr AND expr */
179524 {
179525 fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_AND, fts5yymsp[-2].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24, 0);
179526 }
179527 fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
179528 break;
179529 case 2: /* expr ::= expr OR expr */
179530 {
179531 fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_OR, fts5yymsp[-2].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24, 0);
179532 }
179533 fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
179534 break;
179535 case 3: /* expr ::= expr NOT expr */
179536 {
179537 fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_NOT, fts5yymsp[-2].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24, 0);
179538 }
179539 fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
179540 break;
179541 case 4: /* expr ::= LP expr RP */
179542 {fts5yymsp[-2].minor.fts5yy24 = fts5yymsp[-1].minor.fts5yy24;}
179543 break;
179544 case 5: /* expr ::= exprlist */
179545 case 6: /* exprlist ::= cnearset */ fts5yytestcase(fts5yyruleno==6);
179546 {fts5yylhsminor.fts5yy24 = fts5yymsp[0].minor.fts5yy24;}
179547 fts5yymsp[0].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
179548 break;
179549 case 7: /* exprlist ::= exprlist cnearset */
179550 {
179551 fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseImplicitAnd(pParse, fts5yymsp[-1].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24);
179552 }
179553 fts5yymsp[-1].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
179554 break;
179555 case 8: /* cnearset ::= nearset */
179556 {
179557 fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_STRING, 0, 0, fts5yymsp[0].minor.fts5yy46);
179558 }
179559 fts5yymsp[0].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
179560 break;
179561 case 9: /* cnearset ::= colset COLON nearset */
179562 {
179563 sqlite3Fts5ParseSetColset(pParse, fts5yymsp[0].minor.fts5yy46, fts5yymsp[-2].minor.fts5yy11);
179564 fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_STRING, 0, 0, fts5yymsp[0].minor.fts5yy46);
179565 }
179566 fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
179567 break;
179568 case 10: /* colset ::= MINUS LCP colsetlist RCP */
179569 {
179570 fts5yymsp[-3].minor.fts5yy11 = sqlite3Fts5ParseColsetInvert(pParse, fts5yymsp[-1].minor.fts5yy11);
179571 }
179572 break;
179573 case 11: /* colset ::= LCP colsetlist RCP */
179574 { fts5yymsp[-2].minor.fts5yy11 = fts5yymsp[-1].minor.fts5yy11; }
179575 break;
179576 case 12: /* colset ::= STRING */
179577 {
179578 fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
179579 }
179580 fts5yymsp[0].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
179581 break;
179582 case 13: /* colset ::= MINUS STRING */
179583 {
179584 fts5yymsp[-1].minor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
179585 fts5yymsp[-1].minor.fts5yy11 = sqlite3Fts5ParseColsetInvert(pParse, fts5yymsp[-1].minor.fts5yy11);
179586 }
179587 break;
179588 case 14: /* colsetlist ::= colsetlist STRING */
179589 {
179590 fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseColset(pParse, fts5yymsp[-1].minor.fts5yy11, &fts5yymsp[0].minor.fts5yy0); }
179591 fts5yymsp[-1].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
179592 break;
179593 case 15: /* colsetlist ::= STRING */
179594 {
179595 fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
179596 }
179597 fts5yymsp[0].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
179598 break;
179599 case 16: /* nearset ::= phrase */
179600 { fts5yylhsminor.fts5yy46 = sqlite3Fts5ParseNearset(pParse, 0, fts5yymsp[0].minor.fts5yy53); }
179601 fts5yymsp[0].minor.fts5yy46 = fts5yylhsminor.fts5yy46;
179602 break;
179603 case 17: /* nearset ::= STRING LP nearphrases neardist_opt RP */
179604 {
179605 sqlite3Fts5ParseNear(pParse, &fts5yymsp[-4].minor.fts5yy0);
179606 sqlite3Fts5ParseSetDistance(pParse, fts5yymsp[-2].minor.fts5yy46, &fts5yymsp[-1].minor.fts5yy0);
179607 fts5yylhsminor.fts5yy46 = fts5yymsp[-2].minor.fts5yy46;
179608 }
179609 fts5yymsp[-4].minor.fts5yy46 = fts5yylhsminor.fts5yy46;
179610 break;
179611 case 18: /* nearphrases ::= phrase */
179612 {
179613 fts5yylhsminor.fts5yy46 = sqlite3Fts5ParseNearset(pParse, 0, fts5yymsp[0].minor.fts5yy53);
179614 }
179615 fts5yymsp[0].minor.fts5yy46 = fts5yylhsminor.fts5yy46;
179616 break;
179617 case 19: /* nearphrases ::= nearphrases phrase */
179618 {
179619 fts5yylhsminor.fts5yy46 = sqlite3Fts5ParseNearset(pParse, fts5yymsp[-1].minor.fts5yy46, fts5yymsp[0].minor.fts5yy53);
179620 }
179621 fts5yymsp[-1].minor.fts5yy46 = fts5yylhsminor.fts5yy46;
179622 break;
179623 case 20: /* neardist_opt ::= */
179624 { fts5yymsp[1].minor.fts5yy0.p = 0; fts5yymsp[1].minor.fts5yy0.n = 0; }
179625 break;
179626 case 21: /* neardist_opt ::= COMMA STRING */
179627 { fts5yymsp[-1].minor.fts5yy0 = fts5yymsp[0].minor.fts5yy0; }
179628 break;
179629 case 22: /* phrase ::= phrase PLUS STRING star_opt */
179630 {
179631 fts5yylhsminor.fts5yy53 = sqlite3Fts5ParseTerm(pParse, fts5yymsp[-3].minor.fts5yy53, &fts5yymsp[-1].minor.fts5yy0, fts5yymsp[0].minor.fts5yy4);
179632 }
179633 fts5yymsp[-3].minor.fts5yy53 = fts5yylhsminor.fts5yy53;
179634 break;
179635 case 23: /* phrase ::= STRING star_opt */
179636 {
179637 fts5yylhsminor.fts5yy53 = sqlite3Fts5ParseTerm(pParse, 0, &fts5yymsp[-1].minor.fts5yy0, fts5yymsp[0].minor.fts5yy4);
179638 }
179639 fts5yymsp[-1].minor.fts5yy53 = fts5yylhsminor.fts5yy53;
179640 break;
179641 case 24: /* star_opt ::= STAR */
179642 { fts5yymsp[0].minor.fts5yy4 = 1; }
179643 break;
179644 case 25: /* star_opt ::= */
179645 { fts5yymsp[1].minor.fts5yy4 = 0; }
179646 break;
179647 default:
179648 break;
179649 /********** End reduce actions ************************************************/
179650 };
@@ -180027,11 +180098,11 @@
180098 }
180099
180100 if( p->iRangeEnd>0 && iPos==p->iRangeEnd ){
180101 fts5HighlightAppend(&rc, p, &p->zIn[p->iOff], iEndOff - p->iOff);
180102 p->iOff = iEndOff;
180103 if( iPos>=p->iter.iStart && iPos<p->iter.iEnd ){
180104 fts5HighlightAppend(&rc, p, p->zClose, -1);
180105 }
180106 }
180107
180108 return rc;
@@ -180188,10 +180259,17 @@
180259 ctx.iRangeEnd = iBestStart + nToken - 1;
180260
180261 if( iBestStart>0 ){
180262 fts5HighlightAppend(&rc, &ctx, zEllips, -1);
180263 }
180264
180265 /* Advance iterator ctx.iter so that it points to the first coalesced
180266 ** phrase instance at or following position iBestStart. */
180267 while( ctx.iter.iStart>=0 && ctx.iter.iStart<iBestStart && rc==SQLITE_OK ){
180268 rc = fts5CInstIterNext(&ctx.iter);
180269 }
180270
180271 if( rc==SQLITE_OK ){
180272 rc = pApi->xTokenize(pFts, ctx.zIn, ctx.nIn, (void*)&ctx,fts5HighlightCb);
180273 }
180274 if( ctx.iRangeEnd>=(nColSize-1) ){
180275 fts5HighlightAppend(&rc, &ctx, &ctx.zIn[ctx.iOff], ctx.nIn - ctx.iOff);
@@ -181923,10 +182001,11 @@
182001 case '}': tok = FTS5_RCP; break;
182002 case ':': tok = FTS5_COLON; break;
182003 case ',': tok = FTS5_COMMA; break;
182004 case '+': tok = FTS5_PLUS; break;
182005 case '*': tok = FTS5_STAR; break;
182006 case '-': tok = FTS5_MINUS; break;
182007 case '\0': tok = FTS5_EOF; break;
182008
182009 case '"': {
182010 const char *z2;
182011 tok = FTS5_STRING;
@@ -183414,11 +183493,11 @@
183493 sizeof(Fts5ExprNearset) + sizeof(Fts5ExprPhrase*));
183494 }
183495 if( rc==SQLITE_OK ){
183496 Fts5Colset *pColsetOrig = pOrig->pNode->pNear->pColset;
183497 if( pColsetOrig ){
183498 int nByte = sizeof(Fts5Colset) + (pColsetOrig->nCol-1) * sizeof(int);
183499 Fts5Colset *pColset = (Fts5Colset*)sqlite3Fts5MallocZero(&rc, nByte);
183500 if( pColset ){
183501 memcpy(pColset, pColsetOrig, nByte);
183502 }
183503 pNew->pRoot->pNear->pColset = pColset;
@@ -183548,10 +183627,38 @@
183627 #endif
183628 }
183629
183630 return pNew;
183631 }
183632
183633 /*
183634 ** Allocate and return an Fts5Colset object specifying the inverse of
183635 ** the colset passed as the second argument. Free the colset passed
183636 ** as the second argument before returning.
183637 */
183638 static Fts5Colset *sqlite3Fts5ParseColsetInvert(Fts5Parse *pParse, Fts5Colset *p){
183639 Fts5Colset *pRet;
183640 int nCol = pParse->pConfig->nCol;
183641
183642 pRet = (Fts5Colset*)sqlite3Fts5MallocZero(&pParse->rc,
183643 sizeof(Fts5Colset) + sizeof(int)*nCol
183644 );
183645 if( pRet ){
183646 int i;
183647 int iOld = 0;
183648 for(i=0; i<nCol; i++){
183649 if( iOld>=p->nCol || p->aiCol[iOld]!=i ){
183650 pRet->aiCol[pRet->nCol++] = i;
183651 }else{
183652 iOld++;
183653 }
183654 }
183655 }
183656
183657 sqlite3_free(p);
183658 return pRet;
183659 }
183660
183661 static Fts5Colset *sqlite3Fts5ParseColset(
183662 Fts5Parse *pParse, /* Store SQLITE_NOMEM here if required */
183663 Fts5Colset *pColset, /* Existing colset object */
183664 Fts5Token *p
@@ -185644,18 +185751,29 @@
185751
185752 assert( (pRet==0)==(p->rc!=SQLITE_OK) );
185753 return pRet;
185754 }
185755
 
185756 /*
185757 ** Release a reference to data record returned by an earlier call to
185758 ** fts5DataRead().
185759 */
185760 static void fts5DataRelease(Fts5Data *pData){
185761 sqlite3_free(pData);
185762 }
185763
185764 static Fts5Data *fts5LeafRead(Fts5Index *p, i64 iRowid){
185765 Fts5Data *pRet = fts5DataRead(p, iRowid);
185766 if( pRet ){
185767 if( pRet->szLeaf>pRet->nn ){
185768 p->rc = FTS5_CORRUPT;
185769 fts5DataRelease(pRet);
185770 pRet = 0;
185771 }
185772 }
185773 return pRet;
185774 }
185775
185776 static int fts5IndexPrepareStmt(
185777 Fts5Index *p,
185778 sqlite3_stmt **ppStmt,
185779 char *zSql
@@ -186461,11 +186579,11 @@
186579 pIter->iLeafPgno++;
186580 if( pIter->pNextLeaf ){
186581 pIter->pLeaf = pIter->pNextLeaf;
186582 pIter->pNextLeaf = 0;
186583 }else if( pIter->iLeafPgno<=pSeg->pgnoLast ){
186584 pIter->pLeaf = fts5LeafRead(p,
186585 FTS5_SEGMENT_ROWID(pSeg->iSegid, pIter->iLeafPgno)
186586 );
186587 }else{
186588 pIter->pLeaf = 0;
186589 }
@@ -186964,13 +187082,12 @@
187082 pIter->iLeafOffset = iOff;
187083
187084 if( pLeaf->nn>pLeaf->szLeaf ){
187085 pIter->iPgidxOff = pLeaf->szLeaf + fts5GetVarint32(
187086 &pLeaf->p[pLeaf->szLeaf], pIter->iEndofDoclist
187087 );
187088 }
 
187089 }
187090 else if( pLeaf->nn>pLeaf->szLeaf ){
187091 pIter->iPgidxOff = pLeaf->szLeaf + fts5GetVarint32(
187092 &pLeaf->p[pLeaf->szLeaf], iOff
187093 );
@@ -187210,10 +187327,15 @@
187327 }
187328
187329 iPgidx += fts5GetVarint32(&a[iPgidx], nKeep);
187330 iTermOff += nKeep;
187331 iOff = iTermOff;
187332
187333 if( iOff>=n ){
187334 p->rc = FTS5_CORRUPT;
187335 return;
187336 }
187337
187338 /* Read the nKeep field of the next term. */
187339 fts5FastGetVarint32(a, iOff, nKeep);
187340 }
187341
@@ -188136,10 +188258,19 @@
188258 fts5BufferZero(&pIter->poslist);
188259 fts5SegiterPoslist(pIter->pIndex, pSeg, 0, &pIter->poslist);
188260 pIter->base.pData = pIter->poslist.p;
188261 }
188262 }
188263
188264 /*
188265 ** xSetOutputs callback used when the Fts5Colset object has nCol==0 (match
188266 ** against no columns at all).
188267 */
188268 static void fts5IterSetOutputs_ZeroColset(Fts5Iter *pIter, Fts5SegIter *pSeg){
188269 UNUSED_PARAM(pSeg);
188270 pIter->base.nData = 0;
188271 }
188272
188273 /*
188274 ** xSetOutputs callback used by detail=col when there is a column filter
188275 ** and there are 100 or more columns. Also called as a fallback from
188276 ** fts5IterSetOutputs_Col100 if the column-list spans more than one page.
@@ -188241,10 +188372,14 @@
188372 }
188373
188374 else if( pIter->pColset==0 ){
188375 pIter->xSetOutputs = fts5IterSetOutputs_Nocolset;
188376 }
188377
188378 else if( pIter->pColset->nCol==0 ){
188379 pIter->xSetOutputs = fts5IterSetOutputs_ZeroColset;
188380 }
188381
188382 else if( pConfig->eDetail==FTS5_DETAIL_FULL ){
188383 pIter->xSetOutputs = fts5IterSetOutputs_Full;
188384 }
188385
@@ -194018,11 +194153,11 @@
194153 int nArg, /* Number of args */
194154 sqlite3_value **apUnused /* Function arguments */
194155 ){
194156 assert( nArg==0 );
194157 UNUSED_PARAM2(nArg, apUnused);
194158 sqlite3_result_text(pCtx, "fts5: 2016-08-20 18:06:14 9041ee4a6f0e8389297f887f1431ab5cfe783390", -1, SQLITE_TRANSIENT);
194159 }
194160
194161 static int fts5Init(sqlite3 *db){
194162 static const sqlite3_module fts5Mod = {
194163 /* iVersion */ 2,
194164
+13 -3
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -118,13 +118,13 @@
118118
**
119119
** See also: [sqlite3_libversion()],
120120
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
121121
** [sqlite_version()] and [sqlite_source_id()].
122122
*/
123
-#define SQLITE_VERSION "3.14.1"
124
-#define SQLITE_VERSION_NUMBER 3014001
125
-#define SQLITE_SOURCE_ID "2016-08-11 18:53:32 a12d8059770df4bca59e321c266410344242bf7b"
123
+#define SQLITE_VERSION "3.15.0"
124
+#define SQLITE_VERSION_NUMBER 3015000
125
+#define SQLITE_SOURCE_ID "2016-08-22 20:10:01 7839519349c7371cdb4e16a215eacd27004cbc62"
126126
127127
/*
128128
** CAPI3REF: Run-Time Library Version Numbers
129129
** KEYWORDS: sqlite3_version, sqlite3_sourceid
130130
**
@@ -1967,12 +1967,22 @@
19671967
** is written 0 or 1 to indicate whether [sqlite3_load_extension()] interface
19681968
** is disabled or enabled following this call. The second parameter may
19691969
** be a NULL pointer, in which case the new setting is not reported back.
19701970
** </dd>
19711971
**
1972
+** <dt>SQLITE_DBCONFIG_MAINDBNAME</dt>
1973
+** <dd> ^This option is used to change the name of the "main" database
1974
+** schema. ^The sole argument is a pointer to a constant UTF8 string
1975
+** which will become the new schema name in place of "main". ^SQLite
1976
+** does not make a copy of the new main schema name string, so the application
1977
+** must ensure that the argument passed into this DBCONFIG option is unchanged
1978
+** until after the database connection closes.
1979
+** </dd>
1980
+**
19721981
** </dl>
19731982
*/
1983
+#define SQLITE_DBCONFIG_MAINDBNAME 1000 /* const char* */
19741984
#define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
19751985
#define SQLITE_DBCONFIG_ENABLE_FKEY 1002 /* int int* */
19761986
#define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */
19771987
#define SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1004 /* int int* */
19781988
#define SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION 1005 /* int int* */
19791989
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -118,13 +118,13 @@
118 **
119 ** See also: [sqlite3_libversion()],
120 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
121 ** [sqlite_version()] and [sqlite_source_id()].
122 */
123 #define SQLITE_VERSION "3.14.1"
124 #define SQLITE_VERSION_NUMBER 3014001
125 #define SQLITE_SOURCE_ID "2016-08-11 18:53:32 a12d8059770df4bca59e321c266410344242bf7b"
126
127 /*
128 ** CAPI3REF: Run-Time Library Version Numbers
129 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
130 **
@@ -1967,12 +1967,22 @@
1967 ** is written 0 or 1 to indicate whether [sqlite3_load_extension()] interface
1968 ** is disabled or enabled following this call. The second parameter may
1969 ** be a NULL pointer, in which case the new setting is not reported back.
1970 ** </dd>
1971 **
 
 
 
 
 
 
 
 
 
1972 ** </dl>
1973 */
 
1974 #define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
1975 #define SQLITE_DBCONFIG_ENABLE_FKEY 1002 /* int int* */
1976 #define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */
1977 #define SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1004 /* int int* */
1978 #define SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION 1005 /* int int* */
1979
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -118,13 +118,13 @@
118 **
119 ** See also: [sqlite3_libversion()],
120 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
121 ** [sqlite_version()] and [sqlite_source_id()].
122 */
123 #define SQLITE_VERSION "3.15.0"
124 #define SQLITE_VERSION_NUMBER 3015000
125 #define SQLITE_SOURCE_ID "2016-08-22 20:10:01 7839519349c7371cdb4e16a215eacd27004cbc62"
126
127 /*
128 ** CAPI3REF: Run-Time Library Version Numbers
129 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
130 **
@@ -1967,12 +1967,22 @@
1967 ** is written 0 or 1 to indicate whether [sqlite3_load_extension()] interface
1968 ** is disabled or enabled following this call. The second parameter may
1969 ** be a NULL pointer, in which case the new setting is not reported back.
1970 ** </dd>
1971 **
1972 ** <dt>SQLITE_DBCONFIG_MAINDBNAME</dt>
1973 ** <dd> ^This option is used to change the name of the "main" database
1974 ** schema. ^The sole argument is a pointer to a constant UTF8 string
1975 ** which will become the new schema name in place of "main". ^SQLite
1976 ** does not make a copy of the new main schema name string, so the application
1977 ** must ensure that the argument passed into this DBCONFIG option is unchanged
1978 ** until after the database connection closes.
1979 ** </dd>
1980 **
1981 ** </dl>
1982 */
1983 #define SQLITE_DBCONFIG_MAINDBNAME 1000 /* const char* */
1984 #define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
1985 #define SQLITE_DBCONFIG_ENABLE_FKEY 1002 /* int int* */
1986 #define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */
1987 #define SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1004 /* int int* */
1988 #define SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION 1005 /* int int* */
1989
+13 -3
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -118,13 +118,13 @@
118118
**
119119
** See also: [sqlite3_libversion()],
120120
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
121121
** [sqlite_version()] and [sqlite_source_id()].
122122
*/
123
-#define SQLITE_VERSION "3.14.1"
124
-#define SQLITE_VERSION_NUMBER 3014001
125
-#define SQLITE_SOURCE_ID "2016-08-11 18:53:32 a12d8059770df4bca59e321c266410344242bf7b"
123
+#define SQLITE_VERSION "3.15.0"
124
+#define SQLITE_VERSION_NUMBER 3015000
125
+#define SQLITE_SOURCE_ID "2016-08-22 20:10:01 7839519349c7371cdb4e16a215eacd27004cbc62"
126126
127127
/*
128128
** CAPI3REF: Run-Time Library Version Numbers
129129
** KEYWORDS: sqlite3_version, sqlite3_sourceid
130130
**
@@ -1967,12 +1967,22 @@
19671967
** is written 0 or 1 to indicate whether [sqlite3_load_extension()] interface
19681968
** is disabled or enabled following this call. The second parameter may
19691969
** be a NULL pointer, in which case the new setting is not reported back.
19701970
** </dd>
19711971
**
1972
+** <dt>SQLITE_DBCONFIG_MAINDBNAME</dt>
1973
+** <dd> ^This option is used to change the name of the "main" database
1974
+** schema. ^The sole argument is a pointer to a constant UTF8 string
1975
+** which will become the new schema name in place of "main". ^SQLite
1976
+** does not make a copy of the new main schema name string, so the application
1977
+** must ensure that the argument passed into this DBCONFIG option is unchanged
1978
+** until after the database connection closes.
1979
+** </dd>
1980
+**
19721981
** </dl>
19731982
*/
1983
+#define SQLITE_DBCONFIG_MAINDBNAME 1000 /* const char* */
19741984
#define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
19751985
#define SQLITE_DBCONFIG_ENABLE_FKEY 1002 /* int int* */
19761986
#define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */
19771987
#define SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1004 /* int int* */
19781988
#define SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION 1005 /* int int* */
19791989
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -118,13 +118,13 @@
118 **
119 ** See also: [sqlite3_libversion()],
120 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
121 ** [sqlite_version()] and [sqlite_source_id()].
122 */
123 #define SQLITE_VERSION "3.14.1"
124 #define SQLITE_VERSION_NUMBER 3014001
125 #define SQLITE_SOURCE_ID "2016-08-11 18:53:32 a12d8059770df4bca59e321c266410344242bf7b"
126
127 /*
128 ** CAPI3REF: Run-Time Library Version Numbers
129 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
130 **
@@ -1967,12 +1967,22 @@
1967 ** is written 0 or 1 to indicate whether [sqlite3_load_extension()] interface
1968 ** is disabled or enabled following this call. The second parameter may
1969 ** be a NULL pointer, in which case the new setting is not reported back.
1970 ** </dd>
1971 **
 
 
 
 
 
 
 
 
 
1972 ** </dl>
1973 */
 
1974 #define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
1975 #define SQLITE_DBCONFIG_ENABLE_FKEY 1002 /* int int* */
1976 #define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */
1977 #define SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1004 /* int int* */
1978 #define SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION 1005 /* int int* */
1979
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -118,13 +118,13 @@
118 **
119 ** See also: [sqlite3_libversion()],
120 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
121 ** [sqlite_version()] and [sqlite_source_id()].
122 */
123 #define SQLITE_VERSION "3.15.0"
124 #define SQLITE_VERSION_NUMBER 3015000
125 #define SQLITE_SOURCE_ID "2016-08-22 20:10:01 7839519349c7371cdb4e16a215eacd27004cbc62"
126
127 /*
128 ** CAPI3REF: Run-Time Library Version Numbers
129 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
130 **
@@ -1967,12 +1967,22 @@
1967 ** is written 0 or 1 to indicate whether [sqlite3_load_extension()] interface
1968 ** is disabled or enabled following this call. The second parameter may
1969 ** be a NULL pointer, in which case the new setting is not reported back.
1970 ** </dd>
1971 **
1972 ** <dt>SQLITE_DBCONFIG_MAINDBNAME</dt>
1973 ** <dd> ^This option is used to change the name of the "main" database
1974 ** schema. ^The sole argument is a pointer to a constant UTF8 string
1975 ** which will become the new schema name in place of "main". ^SQLite
1976 ** does not make a copy of the new main schema name string, so the application
1977 ** must ensure that the argument passed into this DBCONFIG option is unchanged
1978 ** until after the database connection closes.
1979 ** </dd>
1980 **
1981 ** </dl>
1982 */
1983 #define SQLITE_DBCONFIG_MAINDBNAME 1000 /* const char* */
1984 #define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
1985 #define SQLITE_DBCONFIG_ENABLE_FKEY 1002 /* int int* */
1986 #define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */
1987 #define SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1004 /* int int* */
1988 #define SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION 1005 /* int int* */
1989
+3 -5
--- src/stash.c
+++ src/stash.c
@@ -23,17 +23,17 @@
2323
2424
/*
2525
** SQL code to implement the tables needed by the stash.
2626
*/
2727
static const char zStashInit[] =
28
-@ CREATE TABLE IF NOT EXISTS "%w".stash(
28
+@ CREATE TABLE IF NOT EXISTS localdb.stash(
2929
@ stashid INTEGER PRIMARY KEY, -- Unique stash identifier
3030
@ vid INTEGER, -- The baseline check-out for this stash
3131
@ comment TEXT, -- Comment for this stash. Or NULL
3232
@ ctime TIMESTAMP -- When the stash was created
3333
@ );
34
-@ CREATE TABLE IF NOT EXISTS "%w".stashfile(
34
+@ CREATE TABLE IF NOT EXISTS localdb.stashfile(
3535
@ stashid INTEGER REFERENCES stash, -- Stash that contains this file
3636
@ rid INTEGER, -- Baseline content in BLOB table or 0.
3737
@ isAdded BOOLEAN, -- True if this is an added file
3838
@ isRemoved BOOLEAN, -- True if this file is deleted
3939
@ isExec BOOLEAN, -- True if file is executable
@@ -472,20 +472,18 @@
472472
** fossil stash goto ?STASHID?
473473
** fossil stash rm|drop ?STASHID? ?-a|--all?
474474
** fossil stash [g]diff ?STASHID? ?DIFF-OPTIONS?
475475
*/
476476
void stash_cmd(void){
477
- const char *zDb;
478477
const char *zCmd;
479478
int nCmd;
480479
int stashid = 0;
481480
undo_capture_command_line();
482481
db_must_be_within_tree();
483482
db_open_config(0, 0);
484483
db_begin_transaction();
485
- zDb = db_name("localdb");
486
- db_multi_exec(zStashInit /*works-like:"%w,%w"*/, zDb, zDb);
484
+ db_multi_exec(zStashInit /*works-like:""*/);
487485
if( g.argc<=2 ){
488486
zCmd = "save";
489487
}else{
490488
zCmd = g.argv[2];
491489
}
492490
--- src/stash.c
+++ src/stash.c
@@ -23,17 +23,17 @@
23
24 /*
25 ** SQL code to implement the tables needed by the stash.
26 */
27 static const char zStashInit[] =
28 @ CREATE TABLE IF NOT EXISTS "%w".stash(
29 @ stashid INTEGER PRIMARY KEY, -- Unique stash identifier
30 @ vid INTEGER, -- The baseline check-out for this stash
31 @ comment TEXT, -- Comment for this stash. Or NULL
32 @ ctime TIMESTAMP -- When the stash was created
33 @ );
34 @ CREATE TABLE IF NOT EXISTS "%w".stashfile(
35 @ stashid INTEGER REFERENCES stash, -- Stash that contains this file
36 @ rid INTEGER, -- Baseline content in BLOB table or 0.
37 @ isAdded BOOLEAN, -- True if this is an added file
38 @ isRemoved BOOLEAN, -- True if this file is deleted
39 @ isExec BOOLEAN, -- True if file is executable
@@ -472,20 +472,18 @@
472 ** fossil stash goto ?STASHID?
473 ** fossil stash rm|drop ?STASHID? ?-a|--all?
474 ** fossil stash [g]diff ?STASHID? ?DIFF-OPTIONS?
475 */
476 void stash_cmd(void){
477 const char *zDb;
478 const char *zCmd;
479 int nCmd;
480 int stashid = 0;
481 undo_capture_command_line();
482 db_must_be_within_tree();
483 db_open_config(0, 0);
484 db_begin_transaction();
485 zDb = db_name("localdb");
486 db_multi_exec(zStashInit /*works-like:"%w,%w"*/, zDb, zDb);
487 if( g.argc<=2 ){
488 zCmd = "save";
489 }else{
490 zCmd = g.argv[2];
491 }
492
--- src/stash.c
+++ src/stash.c
@@ -23,17 +23,17 @@
23
24 /*
25 ** SQL code to implement the tables needed by the stash.
26 */
27 static const char zStashInit[] =
28 @ CREATE TABLE IF NOT EXISTS localdb.stash(
29 @ stashid INTEGER PRIMARY KEY, -- Unique stash identifier
30 @ vid INTEGER, -- The baseline check-out for this stash
31 @ comment TEXT, -- Comment for this stash. Or NULL
32 @ ctime TIMESTAMP -- When the stash was created
33 @ );
34 @ CREATE TABLE IF NOT EXISTS localdb.stashfile(
35 @ stashid INTEGER REFERENCES stash, -- Stash that contains this file
36 @ rid INTEGER, -- Baseline content in BLOB table or 0.
37 @ isAdded BOOLEAN, -- True if this is an added file
38 @ isRemoved BOOLEAN, -- True if this file is deleted
39 @ isExec BOOLEAN, -- True if file is executable
@@ -472,20 +472,18 @@
472 ** fossil stash goto ?STASHID?
473 ** fossil stash rm|drop ?STASHID? ?-a|--all?
474 ** fossil stash [g]diff ?STASHID? ?DIFF-OPTIONS?
475 */
476 void stash_cmd(void){
 
477 const char *zCmd;
478 int nCmd;
479 int stashid = 0;
480 undo_capture_command_line();
481 db_must_be_within_tree();
482 db_open_config(0, 0);
483 db_begin_transaction();
484 db_multi_exec(zStashInit /*works-like:""*/);
 
485 if( g.argc<=2 ){
486 zCmd = "save";
487 }else{
488 zCmd = g.argv[2];
489 }
490
+20 -26
--- src/stat.c
+++ src/stat.c
@@ -61,11 +61,10 @@
6161
*/
6262
void stat_page(void){
6363
i64 t, fsize;
6464
int n, m;
6565
int szMax, szAvg;
66
- const char *zDb;
6766
int brief;
6867
char zBuf[100];
6968
const char *p;
7069
7170
login_check_credentials();
@@ -188,16 +187,15 @@
188187
@ <tr><th>Schema&nbsp;Version:</th><td>%h(g.zAuxSchema)</td></tr>
189188
@ <tr><th>Repository Rebuilt:</th><td>
190189
@ %h(db_get_mtime("rebuilt","%Y-%m-%d %H:%M:%S","Never"))
191190
@ By Fossil %h(db_get("rebuilt","Unknown"))</td></tr>
192191
@ <tr><th>Database&nbsp;Stats:</th><td>
193
- zDb = db_name("repository");
194
- @ %d(db_int(0, "PRAGMA \"%w\".page_count", zDb)) pages,
195
- @ %d(db_int(0, "PRAGMA \"%w\".page_size", zDb)) bytes/page,
196
- @ %d(db_int(0, "PRAGMA \"%w\".freelist_count", zDb)) free pages,
197
- @ %s(db_text(0, "PRAGMA \"%w\".encoding", zDb)),
198
- @ %s(db_text(0, "PRAGMA \"%w\".journal_mode", zDb)) mode
192
+ @ %d(db_int(0, "PRAGMA repository.page_count")) pages,
193
+ @ %d(db_int(0, "PRAGMA repository.page_size")) bytes/page,
194
+ @ %d(db_int(0, "PRAGMA repository.freelist_count")) free pages,
195
+ @ %s(db_text(0, "PRAGMA repository.encoding")),
196
+ @ %s(db_text(0, "PRAGMA repository.journal_mode")) mode
199197
@ </td></tr>
200198
201199
@ </table>
202200
style_footer();
203201
}
@@ -217,11 +215,10 @@
217215
*/
218216
void dbstat_cmd(void){
219217
i64 t, fsize;
220218
int n, m;
221219
int szMax, szAvg;
222
- const char *zDb;
223220
int brief;
224221
int omitVers; /* Omit Fossil and SQLite version information */
225222
int dbCheck; /* True for the --db-check option */
226223
char zBuf[100];
227224
const int colWidth = -19 /* printf alignment/width for left column */;
@@ -316,19 +313,18 @@
316313
fossil_print("%*s%.19s [%.10s] (%s)\n",
317314
colWidth, "sqlite-version:",
318315
sqlite3_sourceid(), &sqlite3_sourceid()[20],
319316
sqlite3_libversion());
320317
}
321
- zDb = db_name("repository");
322318
fossil_print("%*s%d pages, %d bytes/pg, %d free pages, "
323319
"%s, %s mode\n",
324320
colWidth, "database-stats:",
325
- db_int(0, "PRAGMA \"%w\".page_count", zDb),
326
- db_int(0, "PRAGMA \"%w\".page_size", zDb),
327
- db_int(0, "PRAGMA \"%w\".freelist_count", zDb),
328
- db_text(0, "PRAGMA \"%w\".encoding", zDb),
329
- db_text(0, "PRAGMA \"%w\".journal_mode", zDb));
321
+ db_int(0, "PRAGMA repository.page_count"),
322
+ db_int(0, "PRAGMA repository.page_size"),
323
+ db_int(0, "PRAGMA repository.freelist_count"),
324
+ db_text(0, "PRAGMA repository.encoding"),
325
+ db_text(0, "PRAGMA repository.journal_mode"));
330326
if( dbCheck ){
331327
fossil_print("%*s%s\n", colWidth, "database-check:",
332328
db_text(0, "PRAGMA quick_check(1)"));
333329
}
334330
}
@@ -396,12 +392,12 @@
396392
style_submenu_element("Stat", "Repository Stats", "stat");
397393
style_submenu_element("URLs", "URLs and Checkouts", "urllist");
398394
if( sqlite3_compileoption_used("ENABLE_DBSTAT_VTAB") ){
399395
style_submenu_element("Table Sizes", 0, "repo-tabsize");
400396
}
401
- db_prepare(&q, "SELECT sql FROM %s.sqlite_master WHERE sql IS NOT NULL",
402
- db_name("repository"));
397
+ db_prepare(&q,
398
+ "SELECT sql FROM repository.sqlite_master WHERE sql IS NOT NULL");
403399
@ <pre>
404400
while( db_step(&q)==SQLITE_ROW ){
405401
@ %h(db_column_text(&q, 0));
406402
}
407403
@ </pre>
@@ -426,23 +422,22 @@
426422
style_submenu_element("Stat", "Repository Stats", "stat");
427423
if( g.perm.Admin ){
428424
style_submenu_element("Schema", "Repository Schema", "repo_schema");
429425
}
430426
db_multi_exec(
431
- "CREATE VIRTUAL TABLE temp.dbx USING dbstat(%s);"
427
+ "CREATE VIRTUAL TABLE temp.dbx USING dbstat(repository);"
432428
"CREATE TEMP TABLE trans(name TEXT PRIMARY KEY,tabname TEXT)WITHOUT ROWID;"
433429
"INSERT INTO trans(name,tabname)"
434
- " SELECT name, tbl_name FROM %s.sqlite_master;"
430
+ " SELECT name, tbl_name FROM repository.sqlite_master;"
435431
"CREATE TEMP TABLE piechart(amt REAL, label TEXT);"
436432
"INSERT INTO piechart(amt,label)"
437433
" SELECT count(*), "
438434
" coalesce((SELECT tabname FROM trans WHERE trans.name=dbx.name),name)"
439435
" FROM dbx"
440
- " GROUP BY 2 ORDER BY 2;",
441
- db_name("repository"), db_name("repository")
436
+ " GROUP BY 2 ORDER BY 2;"
442437
);
443
- nPageFree = db_int(0, "PRAGMA \"%w\".freelist_count", db_name("repository"));
438
+ nPageFree = db_int(0, "PRAGMA repository.freelist_count");
444439
if( nPageFree>0 ){
445440
db_multi_exec(
446441
"INSERT INTO piechart(amt,label) VALUES(%d,'freelist')",
447442
nPageFree
448443
);
@@ -455,23 +450,22 @@
455450
@ </svg></center>
456451
457452
if( g.localOpen ){
458453
db_multi_exec(
459454
"DROP TABLE temp.dbx;"
460
- "CREATE VIRTUAL TABLE temp.dbx USING dbstat(%s);"
455
+ "CREATE VIRTUAL TABLE temp.dbx USING dbstat(localdb);"
461456
"DELETE FROM trans;"
462457
"INSERT INTO trans(name,tabname)"
463
- " SELECT name, tbl_name FROM %s.sqlite_master;"
458
+ " SELECT name, tbl_name FROM localdb.sqlite_master;"
464459
"DELETE FROM piechart;"
465460
"INSERT INTO piechart(amt,label)"
466461
" SELECT count(*), "
467462
" coalesce((SELECT tabname FROM trans WHERE trans.name=dbx.name),name)"
468463
" FROM dbx"
469
- " GROUP BY 2 ORDER BY 2;",
470
- db_name("localdb"), db_name("localdb")
464
+ " GROUP BY 2 ORDER BY 2;"
471465
);
472
- nPageFree = db_int(0, "PRAGMA \"%s\".freelist_count", db_name("localdb"));
466
+ nPageFree = db_int(0, "PRAGMA localdb.freelist_count");
473467
if( nPageFree>0 ){
474468
db_multi_exec(
475469
"INSERT INTO piechart(amt,label) VALUES(%d,'freelist')",
476470
nPageFree
477471
);
478472
--- src/stat.c
+++ src/stat.c
@@ -61,11 +61,10 @@
61 */
62 void stat_page(void){
63 i64 t, fsize;
64 int n, m;
65 int szMax, szAvg;
66 const char *zDb;
67 int brief;
68 char zBuf[100];
69 const char *p;
70
71 login_check_credentials();
@@ -188,16 +187,15 @@
188 @ <tr><th>Schema&nbsp;Version:</th><td>%h(g.zAuxSchema)</td></tr>
189 @ <tr><th>Repository Rebuilt:</th><td>
190 @ %h(db_get_mtime("rebuilt","%Y-%m-%d %H:%M:%S","Never"))
191 @ By Fossil %h(db_get("rebuilt","Unknown"))</td></tr>
192 @ <tr><th>Database&nbsp;Stats:</th><td>
193 zDb = db_name("repository");
194 @ %d(db_int(0, "PRAGMA \"%w\".page_count", zDb)) pages,
195 @ %d(db_int(0, "PRAGMA \"%w\".page_size", zDb)) bytes/page,
196 @ %d(db_int(0, "PRAGMA \"%w\".freelist_count", zDb)) free pages,
197 @ %s(db_text(0, "PRAGMA \"%w\".encoding", zDb)),
198 @ %s(db_text(0, "PRAGMA \"%w\".journal_mode", zDb)) mode
199 @ </td></tr>
200
201 @ </table>
202 style_footer();
203 }
@@ -217,11 +215,10 @@
217 */
218 void dbstat_cmd(void){
219 i64 t, fsize;
220 int n, m;
221 int szMax, szAvg;
222 const char *zDb;
223 int brief;
224 int omitVers; /* Omit Fossil and SQLite version information */
225 int dbCheck; /* True for the --db-check option */
226 char zBuf[100];
227 const int colWidth = -19 /* printf alignment/width for left column */;
@@ -316,19 +313,18 @@
316 fossil_print("%*s%.19s [%.10s] (%s)\n",
317 colWidth, "sqlite-version:",
318 sqlite3_sourceid(), &sqlite3_sourceid()[20],
319 sqlite3_libversion());
320 }
321 zDb = db_name("repository");
322 fossil_print("%*s%d pages, %d bytes/pg, %d free pages, "
323 "%s, %s mode\n",
324 colWidth, "database-stats:",
325 db_int(0, "PRAGMA \"%w\".page_count", zDb),
326 db_int(0, "PRAGMA \"%w\".page_size", zDb),
327 db_int(0, "PRAGMA \"%w\".freelist_count", zDb),
328 db_text(0, "PRAGMA \"%w\".encoding", zDb),
329 db_text(0, "PRAGMA \"%w\".journal_mode", zDb));
330 if( dbCheck ){
331 fossil_print("%*s%s\n", colWidth, "database-check:",
332 db_text(0, "PRAGMA quick_check(1)"));
333 }
334 }
@@ -396,12 +392,12 @@
396 style_submenu_element("Stat", "Repository Stats", "stat");
397 style_submenu_element("URLs", "URLs and Checkouts", "urllist");
398 if( sqlite3_compileoption_used("ENABLE_DBSTAT_VTAB") ){
399 style_submenu_element("Table Sizes", 0, "repo-tabsize");
400 }
401 db_prepare(&q, "SELECT sql FROM %s.sqlite_master WHERE sql IS NOT NULL",
402 db_name("repository"));
403 @ <pre>
404 while( db_step(&q)==SQLITE_ROW ){
405 @ %h(db_column_text(&q, 0));
406 }
407 @ </pre>
@@ -426,23 +422,22 @@
426 style_submenu_element("Stat", "Repository Stats", "stat");
427 if( g.perm.Admin ){
428 style_submenu_element("Schema", "Repository Schema", "repo_schema");
429 }
430 db_multi_exec(
431 "CREATE VIRTUAL TABLE temp.dbx USING dbstat(%s);"
432 "CREATE TEMP TABLE trans(name TEXT PRIMARY KEY,tabname TEXT)WITHOUT ROWID;"
433 "INSERT INTO trans(name,tabname)"
434 " SELECT name, tbl_name FROM %s.sqlite_master;"
435 "CREATE TEMP TABLE piechart(amt REAL, label TEXT);"
436 "INSERT INTO piechart(amt,label)"
437 " SELECT count(*), "
438 " coalesce((SELECT tabname FROM trans WHERE trans.name=dbx.name),name)"
439 " FROM dbx"
440 " GROUP BY 2 ORDER BY 2;",
441 db_name("repository"), db_name("repository")
442 );
443 nPageFree = db_int(0, "PRAGMA \"%w\".freelist_count", db_name("repository"));
444 if( nPageFree>0 ){
445 db_multi_exec(
446 "INSERT INTO piechart(amt,label) VALUES(%d,'freelist')",
447 nPageFree
448 );
@@ -455,23 +450,22 @@
455 @ </svg></center>
456
457 if( g.localOpen ){
458 db_multi_exec(
459 "DROP TABLE temp.dbx;"
460 "CREATE VIRTUAL TABLE temp.dbx USING dbstat(%s);"
461 "DELETE FROM trans;"
462 "INSERT INTO trans(name,tabname)"
463 " SELECT name, tbl_name FROM %s.sqlite_master;"
464 "DELETE FROM piechart;"
465 "INSERT INTO piechart(amt,label)"
466 " SELECT count(*), "
467 " coalesce((SELECT tabname FROM trans WHERE trans.name=dbx.name),name)"
468 " FROM dbx"
469 " GROUP BY 2 ORDER BY 2;",
470 db_name("localdb"), db_name("localdb")
471 );
472 nPageFree = db_int(0, "PRAGMA \"%s\".freelist_count", db_name("localdb"));
473 if( nPageFree>0 ){
474 db_multi_exec(
475 "INSERT INTO piechart(amt,label) VALUES(%d,'freelist')",
476 nPageFree
477 );
478
--- src/stat.c
+++ src/stat.c
@@ -61,11 +61,10 @@
61 */
62 void stat_page(void){
63 i64 t, fsize;
64 int n, m;
65 int szMax, szAvg;
 
66 int brief;
67 char zBuf[100];
68 const char *p;
69
70 login_check_credentials();
@@ -188,16 +187,15 @@
187 @ <tr><th>Schema&nbsp;Version:</th><td>%h(g.zAuxSchema)</td></tr>
188 @ <tr><th>Repository Rebuilt:</th><td>
189 @ %h(db_get_mtime("rebuilt","%Y-%m-%d %H:%M:%S","Never"))
190 @ By Fossil %h(db_get("rebuilt","Unknown"))</td></tr>
191 @ <tr><th>Database&nbsp;Stats:</th><td>
192 @ %d(db_int(0, "PRAGMA repository.page_count")) pages,
193 @ %d(db_int(0, "PRAGMA repository.page_size")) bytes/page,
194 @ %d(db_int(0, "PRAGMA repository.freelist_count")) free pages,
195 @ %s(db_text(0, "PRAGMA repository.encoding")),
196 @ %s(db_text(0, "PRAGMA repository.journal_mode")) mode
 
197 @ </td></tr>
198
199 @ </table>
200 style_footer();
201 }
@@ -217,11 +215,10 @@
215 */
216 void dbstat_cmd(void){
217 i64 t, fsize;
218 int n, m;
219 int szMax, szAvg;
 
220 int brief;
221 int omitVers; /* Omit Fossil and SQLite version information */
222 int dbCheck; /* True for the --db-check option */
223 char zBuf[100];
224 const int colWidth = -19 /* printf alignment/width for left column */;
@@ -316,19 +313,18 @@
313 fossil_print("%*s%.19s [%.10s] (%s)\n",
314 colWidth, "sqlite-version:",
315 sqlite3_sourceid(), &sqlite3_sourceid()[20],
316 sqlite3_libversion());
317 }
 
318 fossil_print("%*s%d pages, %d bytes/pg, %d free pages, "
319 "%s, %s mode\n",
320 colWidth, "database-stats:",
321 db_int(0, "PRAGMA repository.page_count"),
322 db_int(0, "PRAGMA repository.page_size"),
323 db_int(0, "PRAGMA repository.freelist_count"),
324 db_text(0, "PRAGMA repository.encoding"),
325 db_text(0, "PRAGMA repository.journal_mode"));
326 if( dbCheck ){
327 fossil_print("%*s%s\n", colWidth, "database-check:",
328 db_text(0, "PRAGMA quick_check(1)"));
329 }
330 }
@@ -396,12 +392,12 @@
392 style_submenu_element("Stat", "Repository Stats", "stat");
393 style_submenu_element("URLs", "URLs and Checkouts", "urllist");
394 if( sqlite3_compileoption_used("ENABLE_DBSTAT_VTAB") ){
395 style_submenu_element("Table Sizes", 0, "repo-tabsize");
396 }
397 db_prepare(&q,
398 "SELECT sql FROM repository.sqlite_master WHERE sql IS NOT NULL");
399 @ <pre>
400 while( db_step(&q)==SQLITE_ROW ){
401 @ %h(db_column_text(&q, 0));
402 }
403 @ </pre>
@@ -426,23 +422,22 @@
422 style_submenu_element("Stat", "Repository Stats", "stat");
423 if( g.perm.Admin ){
424 style_submenu_element("Schema", "Repository Schema", "repo_schema");
425 }
426 db_multi_exec(
427 "CREATE VIRTUAL TABLE temp.dbx USING dbstat(repository);"
428 "CREATE TEMP TABLE trans(name TEXT PRIMARY KEY,tabname TEXT)WITHOUT ROWID;"
429 "INSERT INTO trans(name,tabname)"
430 " SELECT name, tbl_name FROM repository.sqlite_master;"
431 "CREATE TEMP TABLE piechart(amt REAL, label TEXT);"
432 "INSERT INTO piechart(amt,label)"
433 " SELECT count(*), "
434 " coalesce((SELECT tabname FROM trans WHERE trans.name=dbx.name),name)"
435 " FROM dbx"
436 " GROUP BY 2 ORDER BY 2;"
 
437 );
438 nPageFree = db_int(0, "PRAGMA repository.freelist_count");
439 if( nPageFree>0 ){
440 db_multi_exec(
441 "INSERT INTO piechart(amt,label) VALUES(%d,'freelist')",
442 nPageFree
443 );
@@ -455,23 +450,22 @@
450 @ </svg></center>
451
452 if( g.localOpen ){
453 db_multi_exec(
454 "DROP TABLE temp.dbx;"
455 "CREATE VIRTUAL TABLE temp.dbx USING dbstat(localdb);"
456 "DELETE FROM trans;"
457 "INSERT INTO trans(name,tabname)"
458 " SELECT name, tbl_name FROM localdb.sqlite_master;"
459 "DELETE FROM piechart;"
460 "INSERT INTO piechart(amt,label)"
461 " SELECT count(*), "
462 " coalesce((SELECT tabname FROM trans WHERE trans.name=dbx.name),name)"
463 " FROM dbx"
464 " GROUP BY 2 ORDER BY 2;"
 
465 );
466 nPageFree = db_int(0, "PRAGMA localdb.freelist_count");
467 if( nPageFree>0 ){
468 db_multi_exec(
469 "INSERT INTO piechart(amt,label) VALUES(%d,'freelist')",
470 nPageFree
471 );
472
+8 -10
--- src/undo.c
+++ src/undo.c
@@ -225,26 +225,25 @@
225225
/*
226226
** Begin capturing a snapshot that can be undone.
227227
*/
228228
void undo_begin(void){
229229
int cid;
230
- const char *zDb = db_name("localdb");
231230
static const char zSql[] =
232
- @ CREATE TABLE "%w".undo(
231
+ @ CREATE TABLE localdb.undo(
233232
@ pathname TEXT UNIQUE, -- Name of the file
234233
@ redoflag BOOLEAN, -- 0 for undoable. 1 for redoable
235234
@ existsflag BOOLEAN, -- True if the file exists
236235
@ isExe BOOLEAN, -- True if the file is executable
237236
@ isLink BOOLEAN, -- True if the file is symlink
238237
@ content BLOB -- Saved content
239238
@ );
240
- @ CREATE TABLE "%w".undo_vfile AS SELECT * FROM vfile;
241
- @ CREATE TABLE "%w".undo_vmerge AS SELECT * FROM vmerge;
239
+ @ CREATE TABLE localdb.undo_vfile AS SELECT * FROM vfile;
240
+ @ CREATE TABLE localdb.undo_vmerge AS SELECT * FROM vmerge;
242241
;
243242
if( undoDisable ) return;
244243
undo_reset();
245
- db_multi_exec(zSql/*works-like:"%w,%w,%w"*/, zDb, zDb, zDb);
244
+ db_multi_exec(zSql/*works-like:""*/);
246245
cid = db_lget_int("checkout", 0);
247246
db_lset_int("undo_checkout", cid);
248247
db_lset_int("undo_available", 1);
249248
db_lset("undo_cmdline", undoCmd);
250249
undoActive = 1;
@@ -377,24 +376,23 @@
377376
378377
/*
379378
** Make the current state of stashid undoable.
380379
*/
381380
void undo_save_stash(int stashid){
382
- const char *zDb = db_name("localdb");
383381
db_multi_exec(
384
- "CREATE TABLE IF NOT EXISTS \"%w\".undo_stash"
382
+ "CREATE TABLE IF NOT EXISTS localdb.undo_stash"
385383
" AS SELECT * FROM stash WHERE 0;"
386384
"INSERT INTO undo_stash"
387385
" SELECT * FROM stash WHERE stashid=%d;",
388
- zDb, stashid
386
+ stashid
389387
);
390388
db_multi_exec(
391
- "CREATE TABLE IF NOT EXISTS \"%w\".undo_stashfile"
389
+ "CREATE TABLE IF NOT EXISTS localdb.undo_stashfile"
392390
" AS SELECT * FROM stashfile WHERE 0;"
393391
"INSERT INTO undo_stashfile"
394392
" SELECT * FROM stashfile WHERE stashid=%d;",
395
- zDb, stashid
393
+ stashid
396394
);
397395
}
398396
399397
/*
400398
** Complete the undo process is one is currently in process.
401399
--- src/undo.c
+++ src/undo.c
@@ -225,26 +225,25 @@
225 /*
226 ** Begin capturing a snapshot that can be undone.
227 */
228 void undo_begin(void){
229 int cid;
230 const char *zDb = db_name("localdb");
231 static const char zSql[] =
232 @ CREATE TABLE "%w".undo(
233 @ pathname TEXT UNIQUE, -- Name of the file
234 @ redoflag BOOLEAN, -- 0 for undoable. 1 for redoable
235 @ existsflag BOOLEAN, -- True if the file exists
236 @ isExe BOOLEAN, -- True if the file is executable
237 @ isLink BOOLEAN, -- True if the file is symlink
238 @ content BLOB -- Saved content
239 @ );
240 @ CREATE TABLE "%w".undo_vfile AS SELECT * FROM vfile;
241 @ CREATE TABLE "%w".undo_vmerge AS SELECT * FROM vmerge;
242 ;
243 if( undoDisable ) return;
244 undo_reset();
245 db_multi_exec(zSql/*works-like:"%w,%w,%w"*/, zDb, zDb, zDb);
246 cid = db_lget_int("checkout", 0);
247 db_lset_int("undo_checkout", cid);
248 db_lset_int("undo_available", 1);
249 db_lset("undo_cmdline", undoCmd);
250 undoActive = 1;
@@ -377,24 +376,23 @@
377
378 /*
379 ** Make the current state of stashid undoable.
380 */
381 void undo_save_stash(int stashid){
382 const char *zDb = db_name("localdb");
383 db_multi_exec(
384 "CREATE TABLE IF NOT EXISTS \"%w\".undo_stash"
385 " AS SELECT * FROM stash WHERE 0;"
386 "INSERT INTO undo_stash"
387 " SELECT * FROM stash WHERE stashid=%d;",
388 zDb, stashid
389 );
390 db_multi_exec(
391 "CREATE TABLE IF NOT EXISTS \"%w\".undo_stashfile"
392 " AS SELECT * FROM stashfile WHERE 0;"
393 "INSERT INTO undo_stashfile"
394 " SELECT * FROM stashfile WHERE stashid=%d;",
395 zDb, stashid
396 );
397 }
398
399 /*
400 ** Complete the undo process is one is currently in process.
401
--- src/undo.c
+++ src/undo.c
@@ -225,26 +225,25 @@
225 /*
226 ** Begin capturing a snapshot that can be undone.
227 */
228 void undo_begin(void){
229 int cid;
 
230 static const char zSql[] =
231 @ CREATE TABLE localdb.undo(
232 @ pathname TEXT UNIQUE, -- Name of the file
233 @ redoflag BOOLEAN, -- 0 for undoable. 1 for redoable
234 @ existsflag BOOLEAN, -- True if the file exists
235 @ isExe BOOLEAN, -- True if the file is executable
236 @ isLink BOOLEAN, -- True if the file is symlink
237 @ content BLOB -- Saved content
238 @ );
239 @ CREATE TABLE localdb.undo_vfile AS SELECT * FROM vfile;
240 @ CREATE TABLE localdb.undo_vmerge AS SELECT * FROM vmerge;
241 ;
242 if( undoDisable ) return;
243 undo_reset();
244 db_multi_exec(zSql/*works-like:""*/);
245 cid = db_lget_int("checkout", 0);
246 db_lset_int("undo_checkout", cid);
247 db_lset_int("undo_available", 1);
248 db_lset("undo_cmdline", undoCmd);
249 undoActive = 1;
@@ -377,24 +376,23 @@
376
377 /*
378 ** Make the current state of stashid undoable.
379 */
380 void undo_save_stash(int stashid){
 
381 db_multi_exec(
382 "CREATE TABLE IF NOT EXISTS localdb.undo_stash"
383 " AS SELECT * FROM stash WHERE 0;"
384 "INSERT INTO undo_stash"
385 " SELECT * FROM stash WHERE stashid=%d;",
386 stashid
387 );
388 db_multi_exec(
389 "CREATE TABLE IF NOT EXISTS localdb.undo_stashfile"
390 " AS SELECT * FROM stashfile WHERE 0;"
391 "INSERT INTO undo_stashfile"
392 " SELECT * FROM stashfile WHERE stashid=%d;",
393 stashid
394 );
395 }
396
397 /*
398 ** Complete the undo process is one is currently in process.
399
--- src/unversioned.c
+++ src/unversioned.c
@@ -30,11 +30,11 @@
3030
3131
/*
3232
** SQL code to implement the tables needed by the unversioned.
3333
*/
3434
static const char zUnversionedInit[] =
35
-@ CREATE TABLE IF NOT EXISTS "%w".unversioned(
35
+@ CREATE TABLE IF NOT EXISTS repository.unversioned(
3636
@ name TEXT PRIMARY KEY, -- Name of the uv file
3737
@ rcvid INTEGER, -- Where received from
3838
@ mtime DATETIME, -- timestamp. Seconds since 1970.
3939
@ hash TEXT, -- Content hash. NULL if a delete marker
4040
@ sz INTEGER, -- size of content after decompression
@@ -46,11 +46,11 @@
4646
/*
4747
** Make sure the unversioned table exists in the repository.
4848
*/
4949
void unversioned_schema(void){
5050
if( !db_table_exists("repository", "unversioned") ){
51
- db_multi_exec(zUnversionedInit /*works-like:"%w"*/, db_name("repository"));
51
+ db_multi_exec(zUnversionedInit/*works-like:""*/);
5252
}
5353
}
5454
5555
/*
5656
** Return a string which is the hash of the unversioned content.
5757
--- src/unversioned.c
+++ src/unversioned.c
@@ -30,11 +30,11 @@
30
31 /*
32 ** SQL code to implement the tables needed by the unversioned.
33 */
34 static const char zUnversionedInit[] =
35 @ CREATE TABLE IF NOT EXISTS "%w".unversioned(
36 @ name TEXT PRIMARY KEY, -- Name of the uv file
37 @ rcvid INTEGER, -- Where received from
38 @ mtime DATETIME, -- timestamp. Seconds since 1970.
39 @ hash TEXT, -- Content hash. NULL if a delete marker
40 @ sz INTEGER, -- size of content after decompression
@@ -46,11 +46,11 @@
46 /*
47 ** Make sure the unversioned table exists in the repository.
48 */
49 void unversioned_schema(void){
50 if( !db_table_exists("repository", "unversioned") ){
51 db_multi_exec(zUnversionedInit /*works-like:"%w"*/, db_name("repository"));
52 }
53 }
54
55 /*
56 ** Return a string which is the hash of the unversioned content.
57
--- src/unversioned.c
+++ src/unversioned.c
@@ -30,11 +30,11 @@
30
31 /*
32 ** SQL code to implement the tables needed by the unversioned.
33 */
34 static const char zUnversionedInit[] =
35 @ CREATE TABLE IF NOT EXISTS repository.unversioned(
36 @ name TEXT PRIMARY KEY, -- Name of the uv file
37 @ rcvid INTEGER, -- Where received from
38 @ mtime DATETIME, -- timestamp. Seconds since 1970.
39 @ hash TEXT, -- Content hash. NULL if a delete marker
40 @ sz INTEGER, -- size of content after decompression
@@ -46,11 +46,11 @@
46 /*
47 ** Make sure the unversioned table exists in the repository.
48 */
49 void unversioned_schema(void){
50 if( !db_table_exists("repository", "unversioned") ){
51 db_multi_exec(zUnversionedInit/*works-like:""*/);
52 }
53 }
54
55 /*
56 ** Return a string which is the hash of the unversioned content.
57

Keyboard Shortcuts

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