Fossil SCM

Use the new SQLITE_DBCONFIG_MAINDBNAME feature of SQLite to eliminate the need for the db_name() hack.

drh 2016-08-19 00:13 trunk
Commit d858f3da52969aab1f881d517519ffe6d4561432
+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
+65 -63
--- src/db.c
+++ src/db.c
@@ -961,52 +961,75 @@
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 from "main" to zLabel.
969
+** zLabel must be a static string that is unchanged for the life of
970
+** the database connection.
971
+*/
972
+void db_set_main_schemaname(sqlite3 *db, const char *zLabel){
973
+ if( sqlite3_db_config(db, SQLITE_DBCONFIG_MAINDBNAME, zLabel) ){
974
+ fossil_fatal("Fossil requires a version of SQLite that supports the "
975
+ "SQLITE_DBCONFIG_MAINDBNAME interface.");
976
+ }
977
+}
966978
967979
/*
968980
** zDbName is the name of a database file. If no other database
969981
** file is open, then open this one. If another database file is
970982
** already open, then attach zDbName using the name zLabel.
971983
*/
972
-void db_open_or_attach(
973
- const char *zDbName,
974
- const char *zLabel,
975
- int *pWasAttached
976
-){
984
+void db_open_or_attach(const char *zDbName, const char *zLabel){
977985
if( !g.db ){
978
- assert( g.zMainDbType==0 );
979986
g.db = db_open(zDbName);
980
- g.zMainDbType = zLabel;
981
- if( pWasAttached ) *pWasAttached = 0;
987
+ db_set_main_schemaname(g.db, zLabel);
982988
}else{
983
- assert( g.zMainDbType!=0 );
984989
db_attach(zDbName, zLabel);
985
- if( pWasAttached ) *pWasAttached = 1;
986990
}
987991
}
992
+
993
+/*
994
+** Return the slot number for database zLabel. The first database
995
+** opened is slot 0. The "temp" database is slot 1. Attached databases
996
+** are slots 2 and higher.
997
+**
998
+** Return -1 if zLabel does not match any open database.
999
+*/
1000
+int db_database_slot(const char *zLabel){
1001
+ int iSlot = -1;
1002
+ Stmt q;
1003
+ db_prepare(&q, "PRAGMA database_list");
1004
+ while( db_step(&q)==SQLITE_ROW ){
1005
+ if( fossil_strcmp(db_column_text(&q,1),zLabel)==0 ){
1006
+ iSlot = db_column_int(&q, 0);
1007
+ break;
1008
+ }
1009
+ }
1010
+ db_finalize(&q);
1011
+ return iSlot;
1012
+}
9881013
9891014
/*
990
-** Close the user database.
1015
+** Close the per-user database file in ~/.fossil
9911016
*/
9921017
void db_close_config(){
993
- if( g.useAttach ){
1018
+ int iSlot = db_database_slot("configdb");
1019
+ if( iSlot>0 ){
9941020
db_detach("configdb");
995
- g.useAttach = 0;
9961021
g.zConfigDbName = 0;
9971022
}else if( g.dbConfig ){
9981023
sqlite3_wal_checkpoint(g.dbConfig, 0);
9991024
sqlite3_close(g.dbConfig);
10001025
g.dbConfig = 0;
1001
- g.zConfigDbType = 0;
10021026
g.zConfigDbName = 0;
1003
- }else if( g.db && fossil_strcmp(g.zMainDbType, "configdb")==0 ){
1027
+ }else if( g.db && 0==iSlot ){
10041028
sqlite3_wal_checkpoint(g.db, 0);
10051029
sqlite3_close(g.db);
10061030
g.db = 0;
1007
- g.zMainDbType = 0;
10081031
g.zConfigDbName = 0;
10091032
}
10101033
}
10111034
10121035
/*
@@ -1023,11 +1046,12 @@
10231046
*/
10241047
int db_open_config(int useAttach, int isOptional){
10251048
char *zDbName;
10261049
char *zHome;
10271050
if( g.zConfigDbName ){
1028
- if( useAttach==g.useAttach ) return 1; /* Already open. */
1051
+ int alreadyAttached = db_database_slot("configdb")>=0;
1052
+ if( useAttach==alreadyAttached ) return 1; /* Already open. */
10291053
db_close_config();
10301054
}
10311055
zHome = fossil_getenv("FOSSIL_HOME");
10321056
#if defined(_WIN32) || defined(__CYGWIN__)
10331057
if( zHome==0 ){
@@ -1077,17 +1101,15 @@
10771101
if( file_access(zDbName, W_OK) ){
10781102
if( isOptional ) return 0;
10791103
fossil_fatal("configuration file %s must be writeable", zDbName);
10801104
}
10811105
if( useAttach ){
1082
- db_open_or_attach(zDbName, "configdb", &g.useAttach);
1106
+ db_open_or_attach(zDbName, "configdb");
10831107
g.dbConfig = 0;
1084
- g.zConfigDbType = 0;
10851108
}else{
1086
- g.useAttach = 0;
10871109
g.dbConfig = db_open(zDbName);
1088
- g.zConfigDbType = "configdb";
1110
+ db_set_main_schemaname(g.dbConfig, "configdb");
10891111
}
10901112
g.zConfigDbName = zDbName;
10911113
return 1;
10921114
}
10931115
@@ -1096,13 +1118,12 @@
10961118
*/
10971119
int db_table_exists(
10981120
const char *zDb, /* One of: NULL, "configdb", "localdb", "repository" */
10991121
const char *zTable /* Name of table */
11001122
){
1101
- return sqlite3_table_column_metadata(g.db,
1102
- zDb ? db_name(zDb) : 0, zTable, 0,
1103
- 0, 0, 0, 0, 0)==SQLITE_OK;
1123
+ return sqlite3_table_column_metadata(g.db, zDb, zTable, 0,
1124
+ 0, 0, 0, 0, 0)==SQLITE_OK;
11041125
}
11051126
11061127
/*
11071128
** Return TRUE if zTable exists and contains column zColumn.
11081129
** Return FALSE if zTable does not exist or if zTable exists
@@ -1111,13 +1132,12 @@
11111132
int db_table_has_column(
11121133
const char *zDb, /* One of: NULL, "config", "localdb", "repository" */
11131134
const char *zTable, /* Name of table */
11141135
const char *zColumn /* Name of column in table */
11151136
){
1116
- return sqlite3_table_column_metadata(g.db,
1117
- zDb ? db_name(zDb) : 0, zTable, zColumn,
1118
- 0, 0, 0, 0, 0)==SQLITE_OK;
1137
+ return sqlite3_table_column_metadata(g.db, zDb, zTable, zColumn,
1138
+ 0, 0, 0, 0, 0)==SQLITE_OK;
11191139
}
11201140
11211141
/*
11221142
** Returns TRUE if zTable exists in the local database but lacks column
11231143
** zColumn
@@ -1124,12 +1144,12 @@
11241144
*/
11251145
static int db_local_table_exists_but_lacks_column(
11261146
const char *zTable,
11271147
const char *zColumn
11281148
){
1129
- return db_table_exists(db_name("localdb"), zTable)
1130
- && !db_table_has_column(db_name("localdb"), zTable, zColumn);
1149
+ return db_table_exists("localdb", zTable)
1150
+ && !db_table_has_column("localdb", zTable, zColumn);
11311151
}
11321152
11331153
/*
11341154
** If zDbName is a valid local database file, open it and return
11351155
** true. If it is not a valid local database file, return 0.
@@ -1139,13 +1159,13 @@
11391159
char *zVFileDef;
11401160
11411161
if( file_access(zDbName, F_OK) ) return 0;
11421162
lsize = file_size(zDbName);
11431163
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"));
1164
+ db_open_or_attach(zDbName, "localdb");
1165
+ zVFileDef = db_text(0, "SELECT sql FROM localdb.sqlite_master"
1166
+ " WHERE name=='vfile'");
11471167
if( zVFileDef==0 ) return 0;
11481168
11491169
/* If the "isexe" column is missing from the vfile table, then
11501170
** add it now. This code added on 2010-03-06. After all users have
11511171
** upgraded, this code can be safely deleted.
@@ -1290,11 +1310,11 @@
12901310
#endif
12911311
fossil_panic("not a valid repository: %s", zDbName);
12921312
}
12931313
}
12941314
g.zRepositoryName = mprintf("%s", zDbName);
1295
- db_open_or_attach(g.zRepositoryName, "repository", 0);
1315
+ db_open_or_attach(g.zRepositoryName, "repository");
12961316
g.repositoryOpen = 1;
12971317
/* Cache "allow-symlinks" option, because we'll need it on every stat call */
12981318
g.allowSymlinks = db_get_boolean("allow-symlinks",
12991319
db_allow_symlinks_by_default());
13001320
g.zAuxSchema = db_get("aux-schema","");
@@ -1304,11 +1324,11 @@
13041324
** can be removed in the future, once all users have upgraded to the
13051325
** 2014-11-28 or later schema.
13061326
*/
13071327
if( !db_table_has_column("repository","plink","baseid") ){
13081328
db_multi_exec(
1309
- "ALTER TABLE %s.plink ADD COLUMN baseid;", db_name("repository")
1329
+ "ALTER TABLE repository.plink ADD COLUMN baseid;"
13101330
);
13111331
}
13121332
13131333
/* Verify that the MLINK table has the newer columns added by the
13141334
** 2015-01-24 schema change. Create them if necessary. This code
@@ -1316,13 +1336,12 @@
13161336
** 2015-01-24 or later schema.
13171337
*/
13181338
if( !db_table_has_column("repository","mlink","isaux") ){
13191339
db_begin_transaction();
13201340
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")
1341
+ "ALTER TABLE repository.mlink ADD COLUMN pmid INTEGER DEFAULT 0;"
1342
+ "ALTER TABLE repository.mlink ADD COLUMN isaux BOOLEAN DEFAULT 0;"
13241343
);
13251344
db_end_transaction(0);
13261345
}
13271346
}
13281347
@@ -1374,22 +1393,10 @@
13741393
fossil_fatal("specify the repository name as a command-line argument");
13751394
}
13761395
}
13771396
}
13781397
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
-
13911398
/*
13921399
** Return TRUE if the schema is out-of-date
13931400
*/
13941401
int db_schema_is_outofdate(void){
13951402
return strcmp(g.zAuxSchema,AUX_SCHEMA_MIN)<0
@@ -1398,11 +1405,11 @@
13981405
13991406
/*
14001407
** Return true if the database is writeable
14011408
*/
14021409
int db_is_writeable(const char *zName){
1403
- return g.db!=0 && !sqlite3_db_readonly(g.db, db_name(zName));
1410
+ return g.db!=0 && !sqlite3_db_readonly(g.db, zName);
14041411
}
14051412
14061413
/*
14071414
** Verify that the repository schema is correct. If it is not correct,
14081415
** issue a fatal error and die.
@@ -1443,11 +1450,11 @@
14431450
}
14441451
if( db_open_local(zRepo)==0 ){
14451452
fossil_fatal("not in a local checkout");
14461453
return;
14471454
}
1448
- db_open_or_attach(zRepo, "test_repo", 0);
1455
+ db_open_or_attach(zRepo, "test_repo");
14491456
db_lset("repository", blob_str(&repo));
14501457
db_record_repository_filename(blob_str(&repo));
14511458
db_close(1);
14521459
}
14531460
@@ -1506,14 +1513,15 @@
15061513
db_close_config();
15071514
15081515
/* If the localdb (the check-out database) is open and if it has
15091516
** a lot of unused free space, then VACUUM it as we shut down.
15101517
*/
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");
1518
+ if( db_database_slot("localdb")==0 ){
1519
+ int nFree = db_int(0, "PRAGMA localdb.freelist_count");
1520
+ int nTotal = db_int(0, "PRAGMA localdb.page_count");
15141521
if( nFree>nTotal/4 ){
1522
+ sqlite3_db_config(g.db, SQLITE_DBCONFIG_MAINDBNAME, "main");
15151523
db_multi_exec("VACUUM;");
15161524
}
15171525
}
15181526
15191527
if( g.db ){
@@ -1524,18 +1532,15 @@
15241532
while( (pStmt = sqlite3_next_stmt(g.db, pStmt))!=0 ){
15251533
fossil_warning("unfinalized SQL statement: [%s]", sqlite3_sql(pStmt));
15261534
}
15271535
}
15281536
g.db = 0;
1529
- g.zMainDbType = 0;
15301537
}
15311538
g.repositoryOpen = 0;
15321539
g.localOpen = 0;
15331540
assert( g.dbConfig==0 );
1534
- assert( g.useAttach==0 );
15351541
assert( g.zConfigDbName==0 );
1536
- assert( g.zConfigDbType==0 );
15371542
}
15381543
15391544
15401545
/*
15411546
** Create a new empty repository database with the given name.
@@ -2008,15 +2013,12 @@
20082013
** because the main database connection was already pointing to the config
20092014
** database.
20102015
*/
20112016
if( g.dbConfig ){
20122017
sqlite3 *dbTemp = g.db;
2013
- const char *zTempDbType = g.zMainDbType;
20142018
g.db = g.dbConfig;
2015
- g.zMainDbType = g.zConfigDbType;
20162019
g.dbConfig = dbTemp;
2017
- g.zConfigDbType = zTempDbType;
20182020
}
20192021
}
20202022
20212023
/*
20222024
** Try to read a versioned setting string from .fossil-settings/<name>.
@@ -3019,11 +3021,11 @@
30193021
int i, j;
30203022
Stmt q;
30213023
Blob allSql;
30223024
int dryRun = find_option("dry-run", "n", 0)!=0;
30233025
for(i=2; i<g.argc; i++){
3024
- db_open_or_attach(g.argv[i], "main", 0);
3026
+ db_open_or_attach(g.argv[i], "main");
30253027
blob_init(&allSql, "BEGIN;\n", -1);
30263028
db_prepare(&q,
30273029
"SELECT name, sql FROM main.sqlite_master "
30283030
" WHERE type='table' AND sql NOT LIKE '%%WITHOUT ROWID%%'"
30293031
" AND name IN ('global_config','shun','concealed','config',"
@@ -3074,17 +3076,17 @@
30743076
void create_admin_log_table(void){
30753077
static int once = 0;
30763078
if( once ) return;
30773079
once = 1;
30783080
db_multi_exec(
3079
- "CREATE TABLE IF NOT EXISTS \"%w\".admin_log(\n"
3081
+ "CREATE TABLE IF NOT EXISTS repository.admin_log(\n"
30803082
" id INTEGER PRIMARY KEY,\n"
30813083
" time INTEGER, -- Seconds since 1970\n"
30823084
" page TEXT, -- path of page\n"
30833085
" who TEXT, -- User who made the change\n "
30843086
" what TEXT -- What changed\n"
3085
- ")", db_name("repository")
3087
+ ")"
30863088
);
30873089
}
30883090
30893091
/*
30903092
** Write a message into the admin_event table, if admin logging is
30913093
--- src/db.c
+++ src/db.c
@@ -961,52 +961,75 @@
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 +1046,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 +1101,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 +1118,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 +1132,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 +1144,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 +1159,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 +1310,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 +1324,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 +1336,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 +1393,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 +1405,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 +1450,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
@@ -1506,14 +1513,15 @@
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 ){
@@ -1524,18 +1532,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 +2013,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 +3021,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 +3076,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,75 @@
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 from "main" to zLabel.
969 ** zLabel must be a static string that is unchanged for the life of
970 ** the database connection.
971 */
972 void db_set_main_schemaname(sqlite3 *db, const char *zLabel){
973 if( sqlite3_db_config(db, SQLITE_DBCONFIG_MAINDBNAME, zLabel) ){
974 fossil_fatal("Fossil requires a version of SQLite that supports the "
975 "SQLITE_DBCONFIG_MAINDBNAME interface.");
976 }
977 }
978
979 /*
980 ** zDbName is the name of a database file. If no other database
981 ** file is open, then open this one. If another database file is
982 ** already open, then attach zDbName using the name zLabel.
983 */
984 void db_open_or_attach(const char *zDbName, const char *zLabel){
 
 
 
 
985 if( !g.db ){
 
986 g.db = db_open(zDbName);
987 db_set_main_schemaname(g.db, zLabel);
 
988 }else{
 
989 db_attach(zDbName, zLabel);
 
990 }
991 }
992
993 /*
994 ** Return the slot number for database zLabel. The first database
995 ** opened is slot 0. The "temp" database is slot 1. Attached databases
996 ** are slots 2 and higher.
997 **
998 ** Return -1 if zLabel does not match any open database.
999 */
1000 int db_database_slot(const char *zLabel){
1001 int iSlot = -1;
1002 Stmt q;
1003 db_prepare(&q, "PRAGMA database_list");
1004 while( db_step(&q)==SQLITE_ROW ){
1005 if( fossil_strcmp(db_column_text(&q,1),zLabel)==0 ){
1006 iSlot = db_column_int(&q, 0);
1007 break;
1008 }
1009 }
1010 db_finalize(&q);
1011 return iSlot;
1012 }
1013
1014 /*
1015 ** Close the per-user database file in ~/.fossil
1016 */
1017 void db_close_config(){
1018 int iSlot = db_database_slot("configdb");
1019 if( iSlot>0 ){
1020 db_detach("configdb");
 
1021 g.zConfigDbName = 0;
1022 }else if( g.dbConfig ){
1023 sqlite3_wal_checkpoint(g.dbConfig, 0);
1024 sqlite3_close(g.dbConfig);
1025 g.dbConfig = 0;
 
1026 g.zConfigDbName = 0;
1027 }else if( g.db && 0==iSlot ){
1028 sqlite3_wal_checkpoint(g.db, 0);
1029 sqlite3_close(g.db);
1030 g.db = 0;
 
1031 g.zConfigDbName = 0;
1032 }
1033 }
1034
1035 /*
@@ -1023,11 +1046,12 @@
1046 */
1047 int db_open_config(int useAttach, int isOptional){
1048 char *zDbName;
1049 char *zHome;
1050 if( g.zConfigDbName ){
1051 int alreadyAttached = db_database_slot("configdb")>=0;
1052 if( useAttach==alreadyAttached ) return 1; /* Already open. */
1053 db_close_config();
1054 }
1055 zHome = fossil_getenv("FOSSIL_HOME");
1056 #if defined(_WIN32) || defined(__CYGWIN__)
1057 if( zHome==0 ){
@@ -1077,17 +1101,15 @@
1101 if( file_access(zDbName, W_OK) ){
1102 if( isOptional ) return 0;
1103 fossil_fatal("configuration file %s must be writeable", zDbName);
1104 }
1105 if( useAttach ){
1106 db_open_or_attach(zDbName, "configdb");
1107 g.dbConfig = 0;
 
1108 }else{
 
1109 g.dbConfig = db_open(zDbName);
1110 db_set_main_schemaname(g.dbConfig, "configdb");
1111 }
1112 g.zConfigDbName = zDbName;
1113 return 1;
1114 }
1115
@@ -1096,13 +1118,12 @@
1118 */
1119 int db_table_exists(
1120 const char *zDb, /* One of: NULL, "configdb", "localdb", "repository" */
1121 const char *zTable /* Name of table */
1122 ){
1123 return sqlite3_table_column_metadata(g.db, zDb, zTable, 0,
1124 0, 0, 0, 0, 0)==SQLITE_OK;
 
1125 }
1126
1127 /*
1128 ** Return TRUE if zTable exists and contains column zColumn.
1129 ** Return FALSE if zTable does not exist or if zTable exists
@@ -1111,13 +1132,12 @@
1132 int db_table_has_column(
1133 const char *zDb, /* One of: NULL, "config", "localdb", "repository" */
1134 const char *zTable, /* Name of table */
1135 const char *zColumn /* Name of column in table */
1136 ){
1137 return sqlite3_table_column_metadata(g.db, zDb, zTable, zColumn,
1138 0, 0, 0, 0, 0)==SQLITE_OK;
 
1139 }
1140
1141 /*
1142 ** Returns TRUE if zTable exists in the local database but lacks column
1143 ** zColumn
@@ -1124,12 +1144,12 @@
1144 */
1145 static int db_local_table_exists_but_lacks_column(
1146 const char *zTable,
1147 const char *zColumn
1148 ){
1149 return db_table_exists("localdb", zTable)
1150 && !db_table_has_column("localdb", zTable, zColumn);
1151 }
1152
1153 /*
1154 ** If zDbName is a valid local database file, open it and return
1155 ** true. If it is not a valid local database file, return 0.
@@ -1139,13 +1159,13 @@
1159 char *zVFileDef;
1160
1161 if( file_access(zDbName, F_OK) ) return 0;
1162 lsize = file_size(zDbName);
1163 if( lsize%1024!=0 || lsize<4096 ) return 0;
1164 db_open_or_attach(zDbName, "localdb");
1165 zVFileDef = db_text(0, "SELECT sql FROM localdb.sqlite_master"
1166 " WHERE name=='vfile'");
1167 if( zVFileDef==0 ) return 0;
1168
1169 /* If the "isexe" column is missing from the vfile table, then
1170 ** add it now. This code added on 2010-03-06. After all users have
1171 ** upgraded, this code can be safely deleted.
@@ -1290,11 +1310,11 @@
1310 #endif
1311 fossil_panic("not a valid repository: %s", zDbName);
1312 }
1313 }
1314 g.zRepositoryName = mprintf("%s", zDbName);
1315 db_open_or_attach(g.zRepositoryName, "repository");
1316 g.repositoryOpen = 1;
1317 /* Cache "allow-symlinks" option, because we'll need it on every stat call */
1318 g.allowSymlinks = db_get_boolean("allow-symlinks",
1319 db_allow_symlinks_by_default());
1320 g.zAuxSchema = db_get("aux-schema","");
@@ -1304,11 +1324,11 @@
1324 ** can be removed in the future, once all users have upgraded to the
1325 ** 2014-11-28 or later schema.
1326 */
1327 if( !db_table_has_column("repository","plink","baseid") ){
1328 db_multi_exec(
1329 "ALTER TABLE repository.plink ADD COLUMN baseid;"
1330 );
1331 }
1332
1333 /* Verify that the MLINK table has the newer columns added by the
1334 ** 2015-01-24 schema change. Create them if necessary. This code
@@ -1316,13 +1336,12 @@
1336 ** 2015-01-24 or later schema.
1337 */
1338 if( !db_table_has_column("repository","mlink","isaux") ){
1339 db_begin_transaction();
1340 db_multi_exec(
1341 "ALTER TABLE repository.mlink ADD COLUMN pmid INTEGER DEFAULT 0;"
1342 "ALTER TABLE repository.mlink ADD COLUMN isaux BOOLEAN DEFAULT 0;"
 
1343 );
1344 db_end_transaction(0);
1345 }
1346 }
1347
@@ -1374,22 +1393,10 @@
1393 fossil_fatal("specify the repository name as a command-line argument");
1394 }
1395 }
1396 }
1397
 
 
 
 
 
 
 
 
 
 
 
 
1398 /*
1399 ** Return TRUE if the schema is out-of-date
1400 */
1401 int db_schema_is_outofdate(void){
1402 return strcmp(g.zAuxSchema,AUX_SCHEMA_MIN)<0
@@ -1398,11 +1405,11 @@
1405
1406 /*
1407 ** Return true if the database is writeable
1408 */
1409 int db_is_writeable(const char *zName){
1410 return g.db!=0 && !sqlite3_db_readonly(g.db, zName);
1411 }
1412
1413 /*
1414 ** Verify that the repository schema is correct. If it is not correct,
1415 ** issue a fatal error and die.
@@ -1443,11 +1450,11 @@
1450 }
1451 if( db_open_local(zRepo)==0 ){
1452 fossil_fatal("not in a local checkout");
1453 return;
1454 }
1455 db_open_or_attach(zRepo, "test_repo");
1456 db_lset("repository", blob_str(&repo));
1457 db_record_repository_filename(blob_str(&repo));
1458 db_close(1);
1459 }
1460
@@ -1506,14 +1513,15 @@
1513 db_close_config();
1514
1515 /* If the localdb (the check-out database) is open and if it has
1516 ** a lot of unused free space, then VACUUM it as we shut down.
1517 */
1518 if( db_database_slot("localdb")==0 ){
1519 int nFree = db_int(0, "PRAGMA localdb.freelist_count");
1520 int nTotal = db_int(0, "PRAGMA localdb.page_count");
1521 if( nFree>nTotal/4 ){
1522 sqlite3_db_config(g.db, SQLITE_DBCONFIG_MAINDBNAME, "main");
1523 db_multi_exec("VACUUM;");
1524 }
1525 }
1526
1527 if( g.db ){
@@ -1524,18 +1532,15 @@
1532 while( (pStmt = sqlite3_next_stmt(g.db, pStmt))!=0 ){
1533 fossil_warning("unfinalized SQL statement: [%s]", sqlite3_sql(pStmt));
1534 }
1535 }
1536 g.db = 0;
 
1537 }
1538 g.repositoryOpen = 0;
1539 g.localOpen = 0;
1540 assert( g.dbConfig==0 );
 
1541 assert( g.zConfigDbName==0 );
 
1542 }
1543
1544
1545 /*
1546 ** Create a new empty repository database with the given name.
@@ -2008,15 +2013,12 @@
2013 ** because the main database connection was already pointing to the config
2014 ** database.
2015 */
2016 if( g.dbConfig ){
2017 sqlite3 *dbTemp = g.db;
 
2018 g.db = g.dbConfig;
 
2019 g.dbConfig = dbTemp;
 
2020 }
2021 }
2022
2023 /*
2024 ** Try to read a versioned setting string from .fossil-settings/<name>.
@@ -3019,11 +3021,11 @@
3021 int i, j;
3022 Stmt q;
3023 Blob allSql;
3024 int dryRun = find_option("dry-run", "n", 0)!=0;
3025 for(i=2; i<g.argc; i++){
3026 db_open_or_attach(g.argv[i], "main");
3027 blob_init(&allSql, "BEGIN;\n", -1);
3028 db_prepare(&q,
3029 "SELECT name, sql FROM main.sqlite_master "
3030 " WHERE type='table' AND sql NOT LIKE '%%WITHOUT ROWID%%'"
3031 " AND name IN ('global_config','shun','concealed','config',"
@@ -3074,17 +3076,17 @@
3076 void create_admin_log_table(void){
3077 static int once = 0;
3078 if( once ) return;
3079 once = 1;
3080 db_multi_exec(
3081 "CREATE TABLE IF NOT EXISTS repository.admin_log(\n"
3082 " id INTEGER PRIMARY KEY,\n"
3083 " time INTEGER, -- Seconds since 1970\n"
3084 " page TEXT, -- path of page\n"
3085 " who TEXT, -- User who made the change\n "
3086 " what TEXT -- What changed\n"
3087 ")"
3088 );
3089 }
3090
3091 /*
3092 ** Write a message into the admin_event table, if admin logging is
3093
+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 -7
--- 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);
@@ -1989,17 +1988,16 @@
19891988
jo2 = cson_value_get_object(jv2);
19901989
cson_object_set(jo, "sqlite", jv2);
19911990
sqlite3_snprintf(BufLen, zBuf, "%.19s [%.10s] (%s)",
19921991
sqlite3_sourceid(), &sqlite3_sourceid()[20], sqlite3_libversion());
19931992
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));
1993
+ cson_object_set(jo2, "pageCount", cson_value_new_integer((cson_int_t)db_int(0, "PRAGMA repository.page_count")));
1994
+ cson_object_set(jo2, "pageSize", cson_value_new_integer((cson_int_t)db_int(0, "PRAGMA repository.page_size")));
1995
+ cson_object_set(jo2, "freeList", cson_value_new_integer((cson_int_t)db_int(0, "PRAGMA repository.freelist_count")));
1996
+ sqlite3_snprintf(BufLen, zBuf, "%s", db_text(0, "PRAGMA repository.encoding"));
19991997
SETBUF(jo2, "encoding");
2000
- sqlite3_snprintf(BufLen, zBuf, "%s", db_text(0, "PRAGMA \"%w\".journal_mode", zDb));
1998
+ sqlite3_snprintf(BufLen, zBuf, "%s", db_text(0, "PRAGMA repository.journal_mode"));
20011999
cson_object_set(jo2, "journalMode", *zBuf ? cson_value_new_string(zBuf, strlen(zBuf)) : cson_value_null());
20022000
return jv;
20032001
#undef SETBUF
20042002
}
20052003
20062004
--- 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);
@@ -1989,17 +1988,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);
@@ -1989,17 +1988,16 @@
1988 jo2 = cson_value_get_object(jv2);
1989 cson_object_set(jo, "sqlite", jv2);
1990 sqlite3_snprintf(BufLen, zBuf, "%.19s [%.10s] (%s)",
1991 sqlite3_sourceid(), &sqlite3_sourceid()[20], sqlite3_libversion());
1992 SETBUF(jo2, "version");
1993 cson_object_set(jo2, "pageCount", cson_value_new_integer((cson_int_t)db_int(0, "PRAGMA repository.page_count")));
1994 cson_object_set(jo2, "pageSize", cson_value_new_integer((cson_int_t)db_int(0, "PRAGMA repository.page_size")));
1995 cson_object_set(jo2, "freeList", cson_value_new_integer((cson_int_t)db_int(0, "PRAGMA repository.freelist_count")));
1996 sqlite3_snprintf(BufLen, zBuf, "%s", db_text(0, "PRAGMA repository.encoding"));
 
1997 SETBUF(jo2, "encoding");
1998 sqlite3_snprintf(BufLen, zBuf, "%s", db_text(0, "PRAGMA repository.journal_mode"));
1999 cson_object_set(jo2, "journalMode", *zBuf ? cson_value_new_string(zBuf, strlen(zBuf)) : cson_value_null());
2000 return jv;
2001 #undef SETBUF
2002 }
2003
2004
+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
+584 -432
--- 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-18 22:44:22 d6e3d5796c9991ca0af45ed92ce36f55efc02348"
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
};
@@ -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;
@@ -83943,11 +83976,11 @@
8394383976
zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql);
8394483977
if( zTrace ){
8394583978
int i;
8394683979
for(i=0; i<db->nDb; i++){
8394783980
if( DbMaskTest(p->btreeMask, i)==0 ) continue;
83948
- sqlite3_file_control(db, db->aDb[i].zName, SQLITE_FCNTL_TRACE, zTrace);
83981
+ sqlite3_file_control(db, db->aDb[i].zDbSName, SQLITE_FCNTL_TRACE, zTrace);
8394983982
}
8395083983
}
8395183984
#endif /* SQLITE_USE_FCNTL_TRACE */
8395283985
#ifdef SQLITE_DEBUG
8395383986
if( (db->flags & SQLITE_SqlTrace)!=0
@@ -84279,11 +84312,11 @@
8427984312
rc = SQLITE_ERROR;
8428084313
sqlite3BtreeLeaveAll(db);
8428184314
goto blob_open_out;
8428284315
}
8428384316
pBlob->pTab = pTab;
84284
- pBlob->zDb = db->aDb[sqlite3SchemaToIndex(db, pTab->pSchema)].zName;
84317
+ pBlob->zDb = db->aDb[sqlite3SchemaToIndex(db, pTab->pSchema)].zDbSName;
8428584318
8428684319
/* Now search pTab for the exact column. */
8428784320
for(iCol=0; iCol<pTab->nCol; iCol++) {
8428884321
if( sqlite3StrICmp(pTab->aCol[iCol].zName, zColumn)==0 ){
8428984322
break;
@@ -87831,21 +87864,19 @@
8783187864
static SQLITE_NOINLINE int walkExpr(Walker *pWalker, Expr *pExpr){
8783287865
int rc;
8783387866
testcase( ExprHasProperty(pExpr, EP_TokenOnly) );
8783487867
testcase( ExprHasProperty(pExpr, EP_Reduced) );
8783587868
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;
87869
+ if( rc || ExprHasProperty(pExpr,EP_TokenOnly) ) return rc & WRC_Abort;
87870
+ if( pExpr->pLeft && walkExpr(pWalker, pExpr->pLeft) ) return WRC_Abort;
87871
+ if( pExpr->pRight && walkExpr(pWalker, pExpr->pRight) ) return WRC_Abort;
87872
+ if( ExprHasProperty(pExpr, EP_xIsSelect) ){
87873
+ if( sqlite3WalkSelect(pWalker, pExpr->x.pSelect) ) return WRC_Abort;
87874
+ }else{
87875
+ if( sqlite3WalkExprList(pWalker, pExpr->x.pList) ) return WRC_Abort;
87876
+ }
87877
+ return WRC_Continue;
8784787878
}
8784887879
SQLITE_PRIVATE int sqlite3WalkExpr(Walker *pWalker, Expr *pExpr){
8784987880
return pExpr ? walkExpr(pWalker,pExpr) : WRC_Continue;
8785087881
}
8785187882
@@ -88175,12 +88206,12 @@
8817588206
** legacy and because it does not hurt anything to just ignore the
8817688207
** database name. */
8817788208
zDb = 0;
8817888209
}else{
8817988210
for(i=0; i<db->nDb; i++){
88180
- assert( db->aDb[i].zName );
88181
- if( sqlite3StrICmp(db->aDb[i].zName,zDb)==0 ){
88211
+ assert( db->aDb[i].zDbSName );
88212
+ if( sqlite3StrICmp(db->aDb[i].zDbSName,zDb)==0 ){
8818288213
pSchema = db->aDb[i].pSchema;
8818388214
break;
8818488215
}
8818588216
}
8818688217
}
@@ -94249,11 +94280,11 @@
9424994280
assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );
9425094281
9425194282
pTab = sqlite3LocateTableItem(pParse, 0, &pSrc->a[0]);
9425294283
if( !pTab ) goto exit_rename_table;
9425394284
iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
94254
- zDb = db->aDb[iDb].zName;
94285
+ zDb = db->aDb[iDb].zDbSName;
9425594286
db->flags |= SQLITE_PreferBuiltin;
9425694287
9425794288
/* Get a NULL terminated version of the new table name. */
9425894289
zName = sqlite3NameFromToken(db, pName);
9425994290
if( !zName ) goto exit_rename_table;
@@ -94447,11 +94478,11 @@
9444794478
pNew = pParse->pNewTable;
9444894479
assert( pNew );
9444994480
9445094481
assert( sqlite3BtreeHoldsAllMutexes(db) );
9445194482
iDb = sqlite3SchemaToIndex(db, pNew->pSchema);
94452
- zDb = db->aDb[iDb].zName;
94483
+ zDb = db->aDb[iDb].zDbSName;
9445394484
zTab = &pNew->zName[16]; /* Skip the "sqlite_altertab_" prefix on the name */
9445494485
pCol = &pNew->aCol[pNew->nCol-1];
9445594486
pDflt = pCol->pDflt;
9445694487
pTab = sqlite3FindTable(db, zTab, zDb);
9445794488
assert( pTab );
@@ -94857,18 +94888,18 @@
9485794888
** if they do already exist.
9485894889
*/
9485994890
for(i=0; i<ArraySize(aTable); i++){
9486094891
const char *zTab = aTable[i].zName;
9486194892
Table *pStat;
94862
- if( (pStat = sqlite3FindTable(db, zTab, pDb->zName))==0 ){
94893
+ if( (pStat = sqlite3FindTable(db, zTab, pDb->zDbSName))==0 ){
9486394894
if( aTable[i].zCols ){
9486494895
/* The sqlite_statN table does not exist. Create it. Note that a
9486594896
** side-effect of the CREATE TABLE statement is to leave the rootpage
9486694897
** of the new table in register pParse->regRoot. This is important
9486794898
** because the OpenWrite opcode below will be needing it. */
9486894899
sqlite3NestedParse(pParse,
94869
- "CREATE TABLE %Q.%s(%s)", pDb->zName, zTab, aTable[i].zCols
94900
+ "CREATE TABLE %Q.%s(%s)", pDb->zDbSName, zTab, aTable[i].zCols
9487094901
);
9487194902
aRoot[i] = pParse->regRoot;
9487294903
aCreateTbl[i] = OPFLAG_P2ISREG;
9487394904
}
9487494905
}else{
@@ -94879,11 +94910,11 @@
9487994910
aCreateTbl[i] = 0;
9488094911
sqlite3TableLock(pParse, iDb, aRoot[i], 1, zTab);
9488194912
if( zWhere ){
9488294913
sqlite3NestedParse(pParse,
9488394914
"DELETE FROM %Q.%s WHERE %s=%Q",
94884
- pDb->zName, zTab, zWhereType, zWhere
94915
+ pDb->zDbSName, zTab, zWhereType, zWhere
9488594916
);
9488694917
}else{
9488794918
/* The sqlite_stat[134] table already exists. Delete all rows. */
9488894919
sqlite3VdbeAddOp2(v, OP_Clear, aRoot[i], iDb);
9488994920
}
@@ -95641,11 +95672,11 @@
9564195672
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
9564295673
assert( iDb>=0 );
9564395674
assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
9564495675
#ifndef SQLITE_OMIT_AUTHORIZATION
9564595676
if( sqlite3AuthCheck(pParse, SQLITE_ANALYZE, pTab->zName, 0,
95646
- db->aDb[iDb].zName ) ){
95677
+ db->aDb[iDb].zDbSName ) ){
9564795678
return;
9564895679
}
9564995680
#endif
9565095681
9565195682
/* Establish a read-lock on the table at the shared-cache level.
@@ -96031,11 +96062,11 @@
9603196062
}
9603296063
}else{
9603396064
/* Form 3: Analyze the fully qualified table name */
9603496065
iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pTableName);
9603596066
if( iDb>=0 ){
96036
- zDb = db->aDb[iDb].zName;
96067
+ zDb = db->aDb[iDb].zDbSName;
9603796068
z = sqlite3NameFromToken(db, pTableName);
9603896069
if( z ){
9603996070
if( (pIdx = sqlite3FindIndex(db, z, zDb))!=0 ){
9604096071
analyzeTable(pParse, pIdx->pTable, pIdx);
9604196072
}else if( (pTab = sqlite3LocateTable(pParse, 0, z, zDb))!=0 ){
@@ -96491,11 +96522,11 @@
9649196522
#endif
9649296523
}
9649396524
9649496525
/* Load new statistics out of the sqlite_stat1 table */
9649596526
sInfo.db = db;
96496
- sInfo.zDatabase = db->aDb[iDb].zName;
96527
+ sInfo.zDatabase = db->aDb[iDb].zDbSName;
9649796528
if( sqlite3FindTable(db, "sqlite_stat1", sInfo.zDatabase)!=0 ){
9649896529
zSql = sqlite3MPrintf(db,
9649996530
"SELECT tbl,idx,stat FROM %Q.sqlite_stat1", sInfo.zDatabase);
9650096531
if( zSql==0 ){
9650196532
rc = SQLITE_NOMEM_BKPT;
@@ -96634,11 +96665,11 @@
9663496665
if( !db->autoCommit ){
9663596666
zErrDyn = sqlite3MPrintf(db, "cannot ATTACH database within transaction");
9663696667
goto attach_error;
9663796668
}
9663896669
for(i=0; i<db->nDb; i++){
96639
- char *z = db->aDb[i].zName;
96670
+ char *z = db->aDb[i].zDbSName;
9664096671
assert( z && zName );
9664196672
if( sqlite3StrICmp(z, zName)==0 ){
9664296673
zErrDyn = sqlite3MPrintf(db, "database %s is already in use", zName);
9664396674
goto attach_error;
9664496675
}
@@ -96699,12 +96730,12 @@
9669996730
PAGER_SYNCHRONOUS_FULL | (db->flags & PAGER_FLAGS_MASK));
9670096731
#endif
9670196732
sqlite3BtreeLeave(aNew->pBt);
9670296733
}
9670396734
aNew->safety_level = SQLITE_DEFAULT_SYNCHRONOUS+1;
96704
- aNew->zName = sqlite3DbStrDup(db, zName);
96705
- if( rc==SQLITE_OK && aNew->zName==0 ){
96735
+ aNew->zDbSName = sqlite3DbStrDup(db, zName);
96736
+ if( rc==SQLITE_OK && aNew->zDbSName==0 ){
9670696737
rc = SQLITE_NOMEM_BKPT;
9670796738
}
9670896739
9670996740
9671096741
#ifdef SQLITE_HAS_CODEC
@@ -96812,11 +96843,11 @@
9681296843
9681396844
if( zName==0 ) zName = "";
9681496845
for(i=0; i<db->nDb; i++){
9681596846
pDb = &db->aDb[i];
9681696847
if( pDb->pBt==0 ) continue;
96817
- if( sqlite3StrICmp(pDb->zName, zName)==0 ) break;
96848
+ if( sqlite3StrICmp(pDb->zDbSName, zName)==0 ) break;
9681896849
}
9681996850
9682096851
if( i>=db->nDb ){
9682196852
sqlite3_snprintf(sizeof(zErr),zErr, "no such database: %s", zName);
9682296853
goto detach_error;
@@ -96970,11 +97001,11 @@
9697097001
sqlite3 *db;
9697197002
9697297003
db = pParse->db;
9697397004
assert( db->nDb>iDb );
9697497005
pFix->pParse = pParse;
96975
- pFix->zDb = db->aDb[iDb].zName;
97006
+ pFix->zDb = db->aDb[iDb].zDbSName;
9697697007
pFix->pSchema = db->aDb[iDb].pSchema;
9697797008
pFix->zType = zType;
9697897009
pFix->pName = pName;
9697997010
pFix->bVarOnly = (iDb==1);
9698097011
}
@@ -97228,13 +97259,13 @@
9722897259
Parse *pParse, /* The parser context */
9722997260
const char *zTab, /* Table name */
9723097261
const char *zCol, /* Column name */
9723197262
int iDb /* Index of containing database. */
9723297263
){
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 */
97264
+ sqlite3 *db = pParse->db; /* Database handle */
97265
+ char *zDb = db->aDb[iDb].zDbSName; /* Schema name of attached database */
97266
+ int rc; /* Auth callback return code */
9723697267
9723797268
if( db->init.busy ) return SQLITE_OK;
9723897269
rc = db->xAuth(db->pAuthArg, SQLITE_READ, zTab,zCol,zDb,pParse->zAuthContext
9723997270
#ifdef SQLITE_USER_AUTHENTICATION
9724097271
,db->auth.zAuthUser
@@ -97703,14 +97734,15 @@
9770397734
return 0;
9770497735
}
9770597736
#endif
9770697737
for(i=OMIT_TEMPDB; i<db->nDb; i++){
9770797738
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;
97739
+ if( zDatabase==0 || sqlite3StrICmp(zDatabase, db->aDb[j].zDbSName)==0 ){
97740
+ assert( sqlite3SchemaMutexHeld(db, j, 0) );
97741
+ p = sqlite3HashFind(&db->aDb[j].pSchema->tblHash, zName);
97742
+ if( p ) break;
97743
+ }
9771297744
}
9771397745
return p;
9771497746
}
9771597747
9771697748
/*
@@ -97780,11 +97812,11 @@
9778097812
){
9778197813
const char *zDb;
9778297814
assert( p->pSchema==0 || p->zDatabase==0 );
9778397815
if( p->pSchema ){
9778497816
int iDb = sqlite3SchemaToIndex(pParse->db, p->pSchema);
97785
- zDb = pParse->db->aDb[iDb].zName;
97817
+ zDb = pParse->db->aDb[iDb].zDbSName;
9778697818
}else{
9778797819
zDb = p->zDatabase;
9778897820
}
9778997821
return sqlite3LocateTable(pParse, flags, p->zName, zDb);
9779097822
}
@@ -97808,11 +97840,11 @@
9780897840
assert( zDb!=0 || sqlite3BtreeHoldsAllMutexes(db) );
9780997841
for(i=OMIT_TEMPDB; i<db->nDb; i++){
9781097842
int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */
9781197843
Schema *pSchema = db->aDb[j].pSchema;
9781297844
assert( pSchema );
97813
- if( zDb && sqlite3StrICmp(zDb, db->aDb[j].zName) ) continue;
97845
+ if( zDb && sqlite3StrICmp(zDb, db->aDb[j].zDbSName) ) continue;
9781497846
assert( sqlite3SchemaMutexHeld(db, j, 0) );
9781597847
p = sqlite3HashFind(&pSchema->idxHash, zName);
9781697848
if( p ) break;
9781797849
}
9781897850
return p;
@@ -97877,12 +97909,12 @@
9787797909
SQLITE_PRIVATE void sqlite3CollapseDatabaseArray(sqlite3 *db){
9787897910
int i, j;
9787997911
for(i=j=2; i<db->nDb; i++){
9788097912
struct Db *pDb = &db->aDb[i];
9788197913
if( pDb->pBt==0 ){
97882
- sqlite3DbFree(db, pDb->zName);
97883
- pDb->zName = 0;
97914
+ sqlite3DbFree(db, pDb->zDbSName);
97915
+ pDb->zDbSName = 0;
9788497916
continue;
9788597917
}
9788697918
if( j<i ){
9788797919
db->aDb[j] = db->aDb[i];
9788897920
}
@@ -98098,11 +98130,11 @@
9809898130
SQLITE_PRIVATE int sqlite3FindDbName(sqlite3 *db, const char *zName){
9809998131
int i = -1; /* Database number */
9810098132
if( zName ){
9810198133
Db *pDb;
9810298134
for(i=(db->nDb-1), pDb=&db->aDb[i]; i>=0; i--, pDb--){
98103
- if( 0==sqlite3StrICmp(pDb->zName, zName) ) break;
98135
+ if( 0==sqlite3StrICmp(pDb->zDbSName, zName) ) break;
9810498136
}
9810598137
}
9810698138
return i;
9810798139
}
9810898140
@@ -98268,11 +98300,11 @@
9826898300
SQLITE_CREATE_TABLE,
9826998301
SQLITE_CREATE_TEMP_TABLE,
9827098302
SQLITE_CREATE_VIEW,
9827198303
SQLITE_CREATE_TEMP_VIEW
9827298304
};
98273
- char *zDb = db->aDb[iDb].zName;
98305
+ char *zDb = db->aDb[iDb].zDbSName;
9827498306
if( sqlite3AuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(isTemp), 0, zDb) ){
9827598307
goto begin_table_error;
9827698308
}
9827798309
if( !isVirtual && sqlite3AuthCheck(pParse, (int)aCode[isTemp+2*isView],
9827898310
zName, 0, zDb) ){
@@ -98287,11 +98319,11 @@
9828798319
** to an sqlite3_declare_vtab() call. In that case only the column names
9828898320
** and types will be used, so there is no need to test for namespace
9828998321
** collisions.
9829098322
*/
9829198323
if( !IN_DECLARE_VTAB ){
98292
- char *zDb = db->aDb[iDb].zName;
98324
+ char *zDb = db->aDb[iDb].zDbSName;
9829398325
if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){
9829498326
goto begin_table_error;
9829598327
}
9829698328
pTable = sqlite3FindTable(db, zName, zDb);
9829798329
if( pTable ){
@@ -99380,11 +99412,11 @@
9938099412
*/
9938199413
sqlite3NestedParse(pParse,
9938299414
"UPDATE %Q.%s "
9938399415
"SET type='%s', name=%Q, tbl_name=%Q, rootpage=#%d, sql=%Q "
9938499416
"WHERE rowid=#%d",
99385
- db->aDb[iDb].zName, SCHEMA_TABLE(iDb),
99417
+ db->aDb[iDb].zDbSName, SCHEMA_TABLE(iDb),
9938699418
zType,
9938799419
p->zName,
9938899420
p->zName,
9938999421
pParse->regRoot,
9939099422
zStmt,
@@ -99401,11 +99433,11 @@
9940199433
Db *pDb = &db->aDb[iDb];
9940299434
assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
9940399435
if( pDb->pSchema->pSeqTab==0 ){
9940499436
sqlite3NestedParse(pParse,
9940599437
"CREATE TABLE %Q.sqlite_sequence(name,seq)",
99406
- pDb->zName
99438
+ pDb->zDbSName
9940799439
);
9940899440
}
9940999441
}
9941099442
#endif
9941199443
@@ -99715,11 +99747,11 @@
9971599747
** is in register NNN. See grammar rules associated with the TK_REGISTER
9971699748
** token for additional information.
9971799749
*/
9971899750
sqlite3NestedParse(pParse,
9971999751
"UPDATE %Q.%s SET rootpage=%d WHERE #%d AND rootpage=#%d",
99720
- pParse->db->aDb[iDb].zName, SCHEMA_TABLE(iDb), iTable, r1, r1);
99752
+ pParse->db->aDb[iDb].zDbSName, SCHEMA_TABLE(iDb), iTable, r1, r1);
9972199753
#endif
9972299754
sqlite3ReleaseTempReg(pParse, r1);
9972399755
}
9972499756
9972599757
/*
@@ -99791,11 +99823,11 @@
9979199823
int iDb, /* The database number */
9979299824
const char *zType, /* "idx" or "tbl" */
9979399825
const char *zName /* Name of index or table */
9979499826
){
9979599827
int i;
99796
- const char *zDbName = pParse->db->aDb[iDb].zName;
99828
+ const char *zDbName = pParse->db->aDb[iDb].zDbSName;
9979799829
for(i=1; i<=4; i++){
9979899830
char zTab[24];
9979999831
sqlite3_snprintf(sizeof(zTab),zTab,"sqlite_stat%d",i);
9980099832
if( sqlite3FindTable(pParse->db, zTab, zDbName) ){
9980199833
sqlite3NestedParse(pParse,
@@ -99844,11 +99876,11 @@
9984499876
** move as a result of the drop (can happen in auto-vacuum mode).
9984599877
*/
9984699878
if( pTab->tabFlags & TF_Autoincrement ){
9984799879
sqlite3NestedParse(pParse,
9984899880
"DELETE FROM %Q.sqlite_sequence WHERE name=%Q",
99849
- pDb->zName, pTab->zName
99881
+ pDb->zDbSName, pTab->zName
9985099882
);
9985199883
}
9985299884
#endif
9985399885
9985499886
/* Drop all SQLITE_MASTER table and index entries that refer to the
@@ -99858,11 +99890,11 @@
9985899890
** created in the temp database that refers to a table in another
9985999891
** database.
9986099892
*/
9986199893
sqlite3NestedParse(pParse,
9986299894
"DELETE FROM %Q.%s WHERE tbl_name=%Q and type!='trigger'",
99863
- pDb->zName, SCHEMA_TABLE(iDb), pTab->zName);
99895
+ pDb->zDbSName, SCHEMA_TABLE(iDb), pTab->zName);
9986499896
if( !isView && !IsVirtual(pTab) ){
9986599897
destroyTable(pParse, pTab);
9986699898
}
9986799899
9986899900
/* Remove the table entry from SQLite's internal schema and modify
@@ -99912,11 +99944,11 @@
9991299944
}
9991399945
#ifndef SQLITE_OMIT_AUTHORIZATION
9991499946
{
9991599947
int code;
9991699948
const char *zTab = SCHEMA_TABLE(iDb);
99917
- const char *zDb = db->aDb[iDb].zName;
99949
+ const char *zDb = db->aDb[iDb].zDbSName;
9991899950
const char *zArg2 = 0;
9991999951
if( sqlite3AuthCheck(pParse, SQLITE_DELETE, zTab, 0, zDb)){
9992099952
goto exit_drop_table;
9992199953
}
9992299954
if( isView ){
@@ -100153,11 +100185,11 @@
100153100185
sqlite3 *db = pParse->db; /* The database connection */
100154100186
int iDb = sqlite3SchemaToIndex(db, pIndex->pSchema);
100155100187
100156100188
#ifndef SQLITE_OMIT_AUTHORIZATION
100157100189
if( sqlite3AuthCheck(pParse, SQLITE_REINDEX, pIndex->zName, 0,
100158
- db->aDb[iDb].zName ) ){
100190
+ db->aDb[iDb].zDbSName ) ){
100159100191
return;
100160100192
}
100161100193
#endif
100162100194
100163100195
/* Require a write-lock on the table to perform this operation */
@@ -100405,11 +100437,11 @@
100405100437
if( sqlite3FindTable(db, zName, 0)!=0 ){
100406100438
sqlite3ErrorMsg(pParse, "there is already a table named %s", zName);
100407100439
goto exit_create_index;
100408100440
}
100409100441
}
100410
- if( sqlite3FindIndex(db, zName, pDb->zName)!=0 ){
100442
+ if( sqlite3FindIndex(db, zName, pDb->zDbSName)!=0 ){
100411100443
if( !ifNotExist ){
100412100444
sqlite3ErrorMsg(pParse, "index %s already exists", zName);
100413100445
}else{
100414100446
assert( !db->init.busy );
100415100447
sqlite3CodeVerifySchema(pParse, iDb);
@@ -100435,11 +100467,11 @@
100435100467
100436100468
/* Check for authorization to create an index.
100437100469
*/
100438100470
#ifndef SQLITE_OMIT_AUTHORIZATION
100439100471
{
100440
- const char *zDb = pDb->zName;
100472
+ const char *zDb = pDb->zDbSName;
100441100473
if( sqlite3AuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(iDb), 0, zDb) ){
100442100474
goto exit_create_index;
100443100475
}
100444100476
i = SQLITE_CREATE_INDEX;
100445100477
if( !OMIT_TEMPDB && iDb==1 ) i = SQLITE_CREATE_TEMP_INDEX;
@@ -100750,11 +100782,11 @@
100750100782
100751100783
/* Add an entry in sqlite_master for this index
100752100784
*/
100753100785
sqlite3NestedParse(pParse,
100754100786
"INSERT INTO %Q.%s VALUES('index',%Q,%Q,#%d,%Q);",
100755
- db->aDb[iDb].zName, SCHEMA_TABLE(iDb),
100787
+ db->aDb[iDb].zDbSName, SCHEMA_TABLE(iDb),
100756100788
pIndex->zName,
100757100789
pTab->zName,
100758100790
iMem,
100759100791
zStmt
100760100792
);
@@ -100884,11 +100916,11 @@
100884100916
iDb = sqlite3SchemaToIndex(db, pIndex->pSchema);
100885100917
#ifndef SQLITE_OMIT_AUTHORIZATION
100886100918
{
100887100919
int code = SQLITE_DROP_INDEX;
100888100920
Table *pTab = pIndex->pTable;
100889
- const char *zDb = db->aDb[iDb].zName;
100921
+ const char *zDb = db->aDb[iDb].zDbSName;
100890100922
const char *zTab = SCHEMA_TABLE(iDb);
100891100923
if( sqlite3AuthCheck(pParse, SQLITE_DELETE, zTab, 0, zDb) ){
100892100924
goto exit_drop_index;
100893100925
}
100894100926
if( !OMIT_TEMPDB && iDb ) code = SQLITE_DROP_TEMP_INDEX;
@@ -100902,11 +100934,11 @@
100902100934
v = sqlite3GetVdbe(pParse);
100903100935
if( v ){
100904100936
sqlite3BeginWriteOperation(pParse, 1, iDb);
100905100937
sqlite3NestedParse(pParse,
100906100938
"DELETE FROM %Q.%s WHERE name=%Q AND type='index'",
100907
- db->aDb[iDb].zName, SCHEMA_TABLE(iDb), pIndex->zName
100939
+ db->aDb[iDb].zDbSName, SCHEMA_TABLE(iDb), pIndex->zName
100908100940
);
100909100941
sqlite3ClearStatTables(pParse, iDb, "idx", pIndex->zName);
100910100942
sqlite3ChangeCookie(pParse, iDb);
100911100943
destroyRootPage(pParse, pIndex->tnum, iDb);
100912100944
sqlite3VdbeAddOp4(v, OP_DropIndex, iDb, 0, 0, pIndex->zName, 0);
@@ -101447,11 +101479,11 @@
101447101479
SQLITE_PRIVATE void sqlite3CodeVerifyNamedSchema(Parse *pParse, const char *zDb){
101448101480
sqlite3 *db = pParse->db;
101449101481
int i;
101450101482
for(i=0; i<db->nDb; i++){
101451101483
Db *pDb = &db->aDb[i];
101452
- if( pDb->pBt && (!zDb || 0==sqlite3StrICmp(zDb, pDb->zName)) ){
101484
+ if( pDb->pBt && (!zDb || 0==sqlite3StrICmp(zDb, pDb->zDbSName)) ){
101453101485
sqlite3CodeVerifySchema(pParse, i);
101454101486
}
101455101487
}
101456101488
}
101457101489
@@ -101694,11 +101726,11 @@
101694101726
}
101695101727
iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pObjName);
101696101728
if( iDb<0 ) return;
101697101729
z = sqlite3NameFromToken(db, pObjName);
101698101730
if( z==0 ) return;
101699
- zDb = db->aDb[iDb].zName;
101731
+ zDb = db->aDb[iDb].zDbSName;
101700101732
pTab = sqlite3FindTable(db, z, zDb);
101701101733
if( pTab ){
101702101734
reindexTable(pParse, pTab, 0);
101703101735
sqlite3DbFree(db, z);
101704101736
return;
@@ -102408,11 +102440,11 @@
102408102440
pWhere = sqlite3ExprDup(db, pWhere, 0);
102409102441
pFrom = sqlite3SrcListAppend(db, 0, 0, 0);
102410102442
if( pFrom ){
102411102443
assert( pFrom->nSrc==1 );
102412102444
pFrom->a[0].zName = sqlite3DbStrDup(db, pView->zName);
102413
- pFrom->a[0].zDatabase = sqlite3DbStrDup(db, db->aDb[iDb].zName);
102445
+ pFrom->a[0].zDatabase = sqlite3DbStrDup(db, db->aDb[iDb].zDbSName);
102414102446
assert( pFrom->a[0].pOn==0 );
102415102447
assert( pFrom->a[0].pUsing==0 );
102416102448
}
102417102449
pSel = sqlite3SelectNew(pParse, 0, pFrom, pWhere, 0, 0, 0,
102418102450
SF_IncludeHidden, 0, 0);
@@ -102595,11 +102627,11 @@
102595102627
if( sqlite3IsReadOnly(pParse, pTab, (pTrigger?1:0)) ){
102596102628
goto delete_from_cleanup;
102597102629
}
102598102630
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
102599102631
assert( iDb<db->nDb );
102600
- zDb = db->aDb[iDb].zName;
102632
+ zDb = db->aDb[iDb].zDbSName;
102601102633
rcauth = sqlite3AuthCheck(pParse, SQLITE_DELETE, pTab->zName, 0, zDb);
102602102634
assert( rcauth==SQLITE_OK || rcauth==SQLITE_DENY || rcauth==SQLITE_IGNORE );
102603102635
if( rcauth==SQLITE_DENY ){
102604102636
goto delete_from_cleanup;
102605102637
}
@@ -105927,11 +105959,11 @@
105927105959
105928105960
/* If foreign-keys are disabled, this function is a no-op. */
105929105961
if( (db->flags&SQLITE_ForeignKeys)==0 ) return;
105930105962
105931105963
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
105932
- zDb = db->aDb[iDb].zName;
105964
+ zDb = db->aDb[iDb].zDbSName;
105933105965
105934105966
/* Loop through all the foreign key constraints for which pTab is the
105935105967
** child table (the table that the foreign key definition is part of). */
105936105968
for(pFKey=pTab->pFKey; pFKey; pFKey=pFKey->pNextFrom){
105937105969
Table *pTo; /* Parent table of foreign key pFKey */
@@ -107014,11 +107046,11 @@
107014107046
goto insert_cleanup;
107015107047
}
107016107048
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
107017107049
assert( iDb<db->nDb );
107018107050
pDb = &db->aDb[iDb];
107019
- zDb = pDb->zName;
107051
+ zDb = pDb->zDbSName;
107020107052
if( sqlite3AuthCheck(pParse, SQLITE_INSERT, pTab->zName, 0, zDb) ){
107021107053
goto insert_cleanup;
107022107054
}
107023107055
withoutRowid = !HasRowid(pTab);
107024107056
@@ -110972,11 +111004,11 @@
110972111004
}else{
110973111005
zRight = sqlite3NameFromToken(db, pValue);
110974111006
}
110975111007
110976111008
assert( pId2 );
110977
- zDb = pId2->n>0 ? pDb->zName : 0;
111009
+ zDb = pId2->n>0 ? pDb->zDbSName : 0;
110978111010
if( sqlite3AuthCheck(pParse, SQLITE_PRAGMA, zLeft, zRight, zDb) ){
110979111011
goto pragma_out;
110980111012
}
110981111013
110982111014
/* Send an SQLITE_FCNTL_PRAGMA file-control to the underlying VFS
@@ -111825,14 +111857,14 @@
111825111857
int i;
111826111858
pParse->nMem = 3;
111827111859
setAllColumnNames(v, 3, azCol); assert( 3==ArraySize(azCol) );
111828111860
for(i=0; i<db->nDb; i++){
111829111861
if( db->aDb[i].pBt==0 ) continue;
111830
- assert( db->aDb[i].zName!=0 );
111862
+ assert( db->aDb[i].zDbSName!=0 );
111831111863
sqlite3VdbeMultiLoad(v, 1, "iss",
111832111864
i,
111833
- db->aDb[i].zName,
111865
+ db->aDb[i].zDbSName,
111834111866
sqlite3BtreeGetFilename(db->aDb[i].pBt));
111835111867
sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3);
111836111868
}
111837111869
}
111838111870
break;
@@ -112117,11 +112149,11 @@
112117112149
/* Do the b-tree integrity checks */
112118112150
sqlite3VdbeAddOp4(v, OP_IntegrityCk, 2, cnt, 1, (char*)aRoot,P4_INTARRAY);
112119112151
sqlite3VdbeChangeP5(v, (u8)i);
112120112152
addr = sqlite3VdbeAddOp1(v, OP_IsNull, 2); VdbeCoverage(v);
112121112153
sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0,
112122
- sqlite3MPrintf(db, "*** in database %s ***\n", db->aDb[i].zName),
112154
+ sqlite3MPrintf(db, "*** in database %s ***\n", db->aDb[i].zDbSName),
112123112155
P4_DYNAMIC);
112124112156
sqlite3VdbeAddOp3(v, OP_Move, 2, 4, 1);
112125112157
sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 2);
112126112158
sqlite3VdbeAddOp2(v, OP_ResultRow, 2, 1);
112127112159
sqlite3VdbeJumpHere(v, addr);
@@ -112556,19 +112588,19 @@
112556112588
pParse->nMem = 2;
112557112589
for(i=0; i<db->nDb; i++){
112558112590
Btree *pBt;
112559112591
const char *zState = "unknown";
112560112592
int j;
112561
- if( db->aDb[i].zName==0 ) continue;
112593
+ if( db->aDb[i].zDbSName==0 ) continue;
112562112594
pBt = db->aDb[i].pBt;
112563112595
if( pBt==0 || sqlite3BtreePager(pBt)==0 ){
112564112596
zState = "closed";
112565
- }else if( sqlite3_file_control(db, i ? db->aDb[i].zName : 0,
112597
+ }else if( sqlite3_file_control(db, i ? db->aDb[i].zDbSName : 0,
112566112598
SQLITE_FCNTL_LOCKSTATE, &j)==SQLITE_OK ){
112567112599
zState = azLockName[j];
112568112600
}
112569
- sqlite3VdbeMultiLoad(v, 1, "ss", db->aDb[i].zName, zState);
112601
+ sqlite3VdbeMultiLoad(v, 1, "ss", db->aDb[i].zDbSName, zState);
112570112602
sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 2);
112571112603
}
112572112604
break;
112573112605
}
112574112606
#endif
@@ -112734,11 +112766,11 @@
112734112766
** constraint for a CREATE TABLE. The index should have already
112735112767
** been created when we processed the CREATE TABLE. All we have
112736112768
** to do here is record the root page number for that index.
112737112769
*/
112738112770
Index *pIndex;
112739
- pIndex = sqlite3FindIndex(db, argv[0], db->aDb[iDb].zName);
112771
+ pIndex = sqlite3FindIndex(db, argv[0], db->aDb[iDb].zDbSName);
112740112772
if( pIndex==0 ){
112741112773
/* This can occur if there exists an index on a TEMP table which
112742112774
** has the same name as another index on a permanent index. Since
112743112775
** the permanent table is hidden by the TEMP table, we can also
112744112776
** safely ignore the index on the permanent table.
@@ -112913,11 +112945,11 @@
112913112945
assert( db->init.busy );
112914112946
{
112915112947
char *zSql;
112916112948
zSql = sqlite3MPrintf(db,
112917112949
"SELECT name, rootpage, sql FROM \"%w\".%s ORDER BY rowid",
112918
- db->aDb[iDb].zName, zMasterName);
112950
+ db->aDb[iDb].zDbSName, zMasterName);
112919112951
#ifndef SQLITE_OMIT_AUTHORIZATION
112920112952
{
112921112953
sqlite3_xauth xAuth;
112922112954
xAuth = db->xAuth;
112923112955
db->xAuth = 0;
@@ -113188,11 +113220,11 @@
113188113220
Btree *pBt = db->aDb[i].pBt;
113189113221
if( pBt ){
113190113222
assert( sqlite3BtreeHoldsMutex(pBt) );
113191113223
rc = sqlite3BtreeSchemaLocked(pBt);
113192113224
if( rc ){
113193
- const char *zDb = db->aDb[i].zName;
113225
+ const char *zDb = db->aDb[i].zDbSName;
113194113226
sqlite3ErrorWithMsg(db, rc, "database schema is locked: %s", zDb);
113195113227
testcase( db->flags & SQLITE_ReadUncommitted );
113196113228
goto end_prepare;
113197113229
}
113198113230
}
@@ -114944,11 +114976,11 @@
114944114976
estWidth = pTab->aCol[iCol].szEst;
114945114977
}
114946114978
zOrigTab = pTab->zName;
114947114979
if( pNC->pParse ){
114948114980
int iDb = sqlite3SchemaToIndex(pNC->pParse->db, pTab->pSchema);
114949
- zOrigDb = pNC->pParse->db->aDb[iDb].zName;
114981
+ zOrigDb = pNC->pParse->db->aDb[iDb].zDbSName;
114950114982
}
114951114983
#else
114952114984
if( iCol<0 ){
114953114985
zType = "INTEGER";
114954114986
}else{
@@ -117900,11 +117932,11 @@
117900117932
pSub = 0;
117901117933
if( zTName && sqlite3StrICmp(zTName, zTabName)!=0 ){
117902117934
continue;
117903117935
}
117904117936
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
117905
- zSchemaName = iDb>=0 ? db->aDb[iDb].zName : "*";
117937
+ zSchemaName = iDb>=0 ? db->aDb[iDb].zDbSName : "*";
117906117938
}
117907117939
for(j=0; j<pTab->nCol; j++){
117908117940
char *zName = pTab->aCol[j].zName;
117909117941
char *zColname; /* The computed column name */
117910117942
char *zToFree; /* Malloced string that needs to be freed */
@@ -119612,12 +119644,12 @@
119612119644
iTabDb = sqlite3SchemaToIndex(db, pTab->pSchema);
119613119645
119614119646
#ifndef SQLITE_OMIT_AUTHORIZATION
119615119647
{
119616119648
int code = SQLITE_CREATE_TRIGGER;
119617
- const char *zDb = db->aDb[iTabDb].zName;
119618
- const char *zDbTrig = isTemp ? db->aDb[1].zName : zDb;
119649
+ const char *zDb = db->aDb[iTabDb].zDbSName;
119650
+ const char *zDbTrig = isTemp ? db->aDb[1].zDbSName : zDb;
119619119651
if( iTabDb==1 || isTemp ) code = SQLITE_CREATE_TEMP_TRIGGER;
119620119652
if( sqlite3AuthCheck(pParse, code, zName, pTab->zName, zDbTrig) ){
119621119653
goto trigger_cleanup;
119622119654
}
119623119655
if( sqlite3AuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(iTabDb),0,zDb)){
@@ -119707,11 +119739,11 @@
119707119739
if( v==0 ) goto triggerfinish_cleanup;
119708119740
sqlite3BeginWriteOperation(pParse, 0, iDb);
119709119741
z = sqlite3DbStrNDup(db, (char*)pAll->z, pAll->n);
119710119742
sqlite3NestedParse(pParse,
119711119743
"INSERT INTO %Q.%s VALUES('trigger',%Q,%Q,0,'CREATE TRIGGER %q')",
119712
- db->aDb[iDb].zName, SCHEMA_TABLE(iDb), zName,
119744
+ db->aDb[iDb].zDbSName, SCHEMA_TABLE(iDb), zName,
119713119745
pTrig->table, z);
119714119746
sqlite3DbFree(db, z);
119715119747
sqlite3ChangeCookie(pParse, iDb);
119716119748
sqlite3VdbeAddParseSchemaOp(v, iDb,
119717119749
sqlite3MPrintf(db, "type='trigger' AND name='%q'", zName));
@@ -119896,11 +119928,11 @@
119896119928
zDb = pName->a[0].zDatabase;
119897119929
zName = pName->a[0].zName;
119898119930
assert( zDb!=0 || sqlite3BtreeHoldsAllMutexes(db) );
119899119931
for(i=OMIT_TEMPDB; i<db->nDb; i++){
119900119932
int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */
119901
- if( zDb && sqlite3StrICmp(db->aDb[j].zName, zDb) ) continue;
119933
+ if( zDb && sqlite3StrICmp(db->aDb[j].zDbSName, zDb) ) continue;
119902119934
assert( sqlite3SchemaMutexHeld(db, j, 0) );
119903119935
pTrigger = sqlite3HashFind(&(db->aDb[j].pSchema->trigHash), zName);
119904119936
if( pTrigger ) break;
119905119937
}
119906119938
if( !pTrigger ){
@@ -119942,11 +119974,11 @@
119942119974
assert( pTable );
119943119975
assert( pTable->pSchema==pTrigger->pSchema || iDb==1 );
119944119976
#ifndef SQLITE_OMIT_AUTHORIZATION
119945119977
{
119946119978
int code = SQLITE_DROP_TRIGGER;
119947
- const char *zDb = db->aDb[iDb].zName;
119979
+ const char *zDb = db->aDb[iDb].zDbSName;
119948119980
const char *zTab = SCHEMA_TABLE(iDb);
119949119981
if( iDb==1 ) code = SQLITE_DROP_TEMP_TRIGGER;
119950119982
if( sqlite3AuthCheck(pParse, code, pTrigger->zName, pTable->zName, zDb) ||
119951119983
sqlite3AuthCheck(pParse, SQLITE_DELETE, zTab, 0, zDb) ){
119952119984
return;
@@ -119958,11 +119990,11 @@
119958119990
*/
119959119991
assert( pTable!=0 );
119960119992
if( (v = sqlite3GetVdbe(pParse))!=0 ){
119961119993
sqlite3NestedParse(pParse,
119962119994
"DELETE FROM %Q.%s WHERE name=%Q AND type='trigger'",
119963
- db->aDb[iDb].zName, SCHEMA_TABLE(iDb), pTrigger->zName
119995
+ db->aDb[iDb].zDbSName, SCHEMA_TABLE(iDb), pTrigger->zName
119964119996
);
119965119997
sqlite3ChangeCookie(pParse, iDb);
119966119998
sqlite3VdbeAddOp4(v, OP_DropTrigger, iDb, 0, 0, pTrigger->zName, 0);
119967119999
}
119968120000
}
@@ -120061,12 +120093,14 @@
120061120093
if( pSrc ){
120062120094
assert( pSrc->nSrc>0 );
120063120095
pSrc->a[pSrc->nSrc-1].zName = sqlite3DbStrDup(db, pStep->zTarget);
120064120096
iDb = sqlite3SchemaToIndex(db, pStep->pTrig->pSchema);
120065120097
if( iDb==0 || iDb>=2 ){
120098
+ const char *zDb;
120066120099
assert( iDb<db->nDb );
120067
- pSrc->a[pSrc->nSrc-1].zDatabase = sqlite3DbStrDup(db, db->aDb[iDb].zName);
120100
+ zDb = db->aDb[iDb].zDbSName;
120101
+ pSrc->a[pSrc->nSrc-1].zDatabase = sqlite3DbStrDup(db, zDb);
120068120102
}
120069120103
}
120070120104
return pSrc;
120071120105
}
120072120106
@@ -120749,11 +120783,11 @@
120749120783
#ifndef SQLITE_OMIT_AUTHORIZATION
120750120784
{
120751120785
int rc;
120752120786
rc = sqlite3AuthCheck(pParse, SQLITE_UPDATE, pTab->zName,
120753120787
j<0 ? "ROWID" : pTab->aCol[j].zName,
120754
- db->aDb[iDb].zName);
120788
+ db->aDb[iDb].zDbSName);
120755120789
if( rc==SQLITE_DENY ){
120756120790
goto update_cleanup;
120757120791
}else if( rc==SQLITE_IGNORE ){
120758120792
aXRef[j] = -1;
120759120793
}
@@ -121506,11 +121540,11 @@
121506121540
zSql = "ATTACH '' AS vacuum_db;";
121507121541
}
121508121542
rc = execSql(db, pzErrMsg, zSql);
121509121543
if( db->nDb>nDb ){
121510121544
pDb = &db->aDb[db->nDb-1];
121511
- assert( strcmp(pDb->zName,"vacuum_db")==0 );
121545
+ assert( strcmp(pDb->zDbSName,"vacuum_db")==0 );
121512121546
}
121513121547
if( rc!=SQLITE_OK ) goto end_of_vacuum;
121514121548
pTemp = db->aDb[db->nDb-1].pBt;
121515121549
121516121550
/* The call to execSql() to attach the temp database has left the file
@@ -122055,11 +122089,11 @@
122055122089
** sqlite_master table, has already been made by sqlite3StartTable().
122056122090
** The second call, to obtain permission to create the table, is made now.
122057122091
*/
122058122092
if( pTable->azModuleArg ){
122059122093
sqlite3AuthCheck(pParse, SQLITE_CREATE_VTABLE, pTable->zName,
122060
- pTable->azModuleArg[0], pParse->db->aDb[iDb].zName);
122094
+ pTable->azModuleArg[0], pParse->db->aDb[iDb].zDbSName);
122061122095
}
122062122096
#endif
122063122097
}
122064122098
122065122099
/*
@@ -122119,11 +122153,11 @@
122119122153
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
122120122154
sqlite3NestedParse(pParse,
122121122155
"UPDATE %Q.%s "
122122122156
"SET type='table', name=%Q, tbl_name=%Q, rootpage=0, sql=%Q "
122123122157
"WHERE rowid=#%d",
122124
- db->aDb[iDb].zName, SCHEMA_TABLE(iDb),
122158
+ db->aDb[iDb].zDbSName, SCHEMA_TABLE(iDb),
122125122159
pTab->zName,
122126122160
pTab->zName,
122127122161
zStmt,
122128122162
pParse->regRowid
122129122163
);
@@ -122229,11 +122263,11 @@
122229122263
}
122230122264
pVTable->db = db;
122231122265
pVTable->pMod = pMod;
122232122266
122233122267
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
122234
- pTab->azModuleArg[1] = db->aDb[iDb].zName;
122268
+ pTab->azModuleArg[1] = db->aDb[iDb].zDbSName;
122235122269
122236122270
/* Invoke the virtual table constructor */
122237122271
assert( &db->pVtabCtx );
122238122272
assert( xConstruct );
122239122273
sCtx.pTab = pTab;
@@ -122393,11 +122427,11 @@
122393122427
int rc = SQLITE_OK;
122394122428
Table *pTab;
122395122429
Module *pMod;
122396122430
const char *zMod;
122397122431
122398
- pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zName);
122432
+ pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zDbSName);
122399122433
assert( pTab && (pTab->tabFlags & TF_Virtual)!=0 && !pTab->pVTable );
122400122434
122401122435
/* Locate the required virtual table module */
122402122436
zMod = pTab->azModuleArg[0];
122403122437
pMod = (Module*)sqlite3HashFind(&db->aModule, zMod);
@@ -122517,11 +122551,11 @@
122517122551
*/
122518122552
SQLITE_PRIVATE int sqlite3VtabCallDestroy(sqlite3 *db, int iDb, const char *zTab){
122519122553
int rc = SQLITE_OK;
122520122554
Table *pTab;
122521122555
122522
- pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zName);
122556
+ pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zDbSName);
122523122557
if( pTab!=0 && ALWAYS(pTab->pVTable!=0) ){
122524122558
VTable *p;
122525122559
int (*xDestroy)(sqlite3_vtab *);
122526122560
for(p=pTab->pVTable; p; p=p->pNext){
122527122561
assert( p->pVtab );
@@ -125630,11 +125664,11 @@
125630125664
*/
125631125665
static int isMatchOfColumn(
125632125666
Expr *pExpr, /* Test this expression */
125633125667
unsigned char *peOp2 /* OUT: 0 for MATCH, or else an op2 value */
125634125668
){
125635
- struct Op2 {
125669
+ static const struct Op2 {
125636125670
const char *zOp;
125637125671
unsigned char eOp2;
125638125672
} aOp[] = {
125639125673
{ "match", SQLITE_INDEX_CONSTRAINT_MATCH },
125640125674
{ "glob", SQLITE_INDEX_CONSTRAINT_GLOB },
@@ -126615,17 +126649,18 @@
126615126649
** These routines walk (recursively) an expression tree and generate
126616126650
** a bitmask indicating which tables are used in that expression
126617126651
** tree.
126618126652
*/
126619126653
SQLITE_PRIVATE Bitmask sqlite3WhereExprUsage(WhereMaskSet *pMaskSet, Expr *p){
126620
- Bitmask mask = 0;
126654
+ Bitmask mask;
126621126655
if( p==0 ) return 0;
126622126656
if( p->op==TK_COLUMN ){
126623126657
mask = sqlite3WhereGetMask(pMaskSet, p->iTable);
126624126658
return mask;
126625126659
}
126626
- mask = sqlite3WhereExprUsage(pMaskSet, p->pRight);
126660
+ assert( !ExprHasProperty(p, EP_TokenOnly) );
126661
+ mask = p->pRight ? sqlite3WhereExprUsage(pMaskSet, p->pRight) : 0;
126627126662
if( p->pLeft ) mask |= sqlite3WhereExprUsage(pMaskSet, p->pLeft);
126628126663
if( ExprHasProperty(p, EP_xIsSelect) ){
126629126664
mask |= exprSelectUsage(pMaskSet, p->x.pSelect);
126630126665
}else if( p->x.pList ){
126631126666
mask |= sqlite3WhereExprListUsage(pMaskSet, p->x.pList);
@@ -131868,29 +131903,33 @@
131868131903
** N between YY_MIN_SHIFTREDUCE Shift to an arbitrary state then
131869131904
** and YY_MAX_SHIFTREDUCE reduce by rule N-YY_MIN_SHIFTREDUCE.
131870131905
**
131871131906
** N between YY_MIN_REDUCE Reduce by rule N-YY_MIN_REDUCE
131872131907
** and YY_MAX_REDUCE
131873
-
131908
+**
131874131909
** N == YY_ERROR_ACTION A syntax error has occurred.
131875131910
**
131876131911
** N == YY_ACCEPT_ACTION The parser accepts its input.
131877131912
**
131878131913
** N == YY_NO_ACTION No such action. Denotes unused
131879131914
** slots in the yy_action[] table.
131880131915
**
131881131916
** 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
131917
+** Given state S and lookahead X, the action is computed as either:
131918
+**
131919
+** (A) N = yy_action[ yy_shift_ofst[S] + X ]
131920
+** (B) N = yy_default[S]
131921
+**
131922
+** The (A) formula is preferred. The B formula is used instead if:
131923
+** (1) The yy_shift_ofst[S]+X value is out of range, or
131924
+** (2) yy_lookahead[yy_shift_ofst[S]+X] is not equal to X, or
131925
+** (3) yy_shift_ofst[S] equal YY_SHIFT_USE_DFLT.
131926
+** (Implementation note: YY_SHIFT_USE_DFLT is chosen so that
131927
+** YY_SHIFT_USE_DFLT+X will be out of range for all possible lookaheads X.
131928
+** Hence only tests (1) and (2) need to be evaluated.)
131929
+**
131930
+** The formulas above are for computing the action when the lookahead is
131892131931
** a terminal symbol. If the lookahead is a non-terminal (as occurs after
131893131932
** a reduce action) then the yy_reduce_ofst[] array is used in place of
131894131933
** the yy_shift_ofst[] array and YY_REDUCE_USE_DFLT is used in place of
131895131934
** YY_SHIFT_USE_DFLT.
131896131935
**
@@ -132211,14 +132250,14 @@
132211132250
/* 1470 */ 122, 23, 23, 64, 22, 124, 26, 26, 64, 64,
132212132251
/* 1480 */ 23, 23, 23, 23, 11, 23, 22, 26, 23, 22,
132213132252
/* 1490 */ 24, 1, 23, 22, 26, 122, 24, 23, 22, 122,
132214132253
/* 1500 */ 23, 23, 22, 122, 122, 23, 15,
132215132254
};
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)
132255
+#define YY_SHIFT_USE_DFLT (1507)
132256
+#define YY_SHIFT_COUNT (442)
132257
+#define YY_SHIFT_MIN (-94)
132258
+#define YY_SHIFT_MAX (1491)
132220132259
static const short yy_shift_ofst[] = {
132221132260
/* 0 */ 40, 564, 869, 577, 725, 725, 725, 725, 690, -19,
132222132261
/* 10 */ 16, 16, 100, 725, 725, 725, 725, 725, 725, 725,
132223132262
/* 20 */ 841, 841, 538, 507, 684, 565, 61, 137, 172, 207,
132224132263
/* 30 */ 242, 277, 312, 347, 382, 424, 424, 424, 424, 424,
@@ -132227,16 +132266,16 @@
132227132266
/* 60 */ 725, 725, 725, 725, 725, 725, 725, 725, 725, 725,
132228132267
/* 70 */ 725, 725, 725, 725, 725, 725, 725, 725, 725, 725,
132229132268
/* 80 */ 725, 725, 725, 725, 821, 725, 725, 725, 725, 725,
132230132269
/* 90 */ 725, 725, 725, 725, 725, 725, 725, 725, 952, 711,
132231132270
/* 100 */ 711, 711, 711, 711, 766, 23, 32, 924, 637, 825,
132232
- /* 110 */ 837, 837, 924, 73, 183, -51, -95, -95, -95, 501,
132271
+ /* 110 */ 837, 837, 924, 73, 183, -51, 1507, 1507, 1507, 501,
132233132272
/* 120 */ 501, 501, 903, 903, 632, 205, 241, 924, 924, 924,
132234132273
/* 130 */ 924, 924, 924, 924, 924, 924, 924, 924, 924, 924,
132235132274
/* 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,
132275
+ /* 150 */ 1106, 183, 176, 176, 176, 176, 176, 176, 1507, 1507,
132276
+ /* 160 */ 1507, 880, -94, -94, 578, 734, 99, 730, 769, 349,
132238132277
/* 170 */ 924, 924, 924, 924, 924, 924, 924, 924, 924, 924,
132239132278
/* 180 */ 924, 924, 924, 924, 924, 924, 924, 954, 954, 954,
132240132279
/* 190 */ 924, 924, 622, 924, 924, 924, -18, 924, 924, 914,
132241132280
/* 200 */ 924, 924, 924, 924, 924, 924, 924, 924, 924, 924,
132242132281
/* 210 */ 441, 1020, 1107, 1107, 1107, 569, 45, 217, 510, 423,
@@ -132246,12 +132285,12 @@
132246132285
/* 250 */ 1297, 1183, 1277, 1285, 1285, 1183, 1176, 1297, 1182, 1250,
132247132286
/* 260 */ 1176, 1176, 1297, 1311, 1176, 1297, 1176, 1297, 1311, 1234,
132248132287
/* 270 */ 1234, 1234, 1267, 1311, 1234, 1244, 1234, 1267, 1234, 1234,
132249132288
/* 280 */ 1232, 1247, 1232, 1247, 1232, 1247, 1232, 1247, 1176, 1334,
132250132289
/* 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,
132290
+ /* 300 */ 1183, 1355, 1357, 1368, 1368, 1378, 1378, 1378, 1378, 1507,
132291
+ /* 310 */ 1507, 1507, 1507, 1507, 1507, 1507, 1507, 451, 936, 816,
132253132292
/* 320 */ 888, 1069, 799, 1111, 1197, 1193, 1201, 1202, 1203, 1213,
132254132293
/* 330 */ 1134, 1117, 1230, 497, 1218, 1219, 1154, 1223, 1115, 1120,
132255132294
/* 340 */ 1231, 1164, 1160, 1392, 1394, 1376, 1257, 1385, 1307, 1386,
132256132295
/* 350 */ 1383, 1388, 1292, 1282, 1303, 1294, 1395, 1293, 1403, 1419,
132257132296
/* 360 */ 1298, 1291, 1389, 1390, 1314, 1372, 1365, 1308, 1430, 1427,
@@ -133200,54 +133239,51 @@
133200133239
133201133240
if( stateno>=YY_MIN_REDUCE ) return stateno;
133202133241
assert( stateno <= YY_SHIFT_COUNT );
133203133242
do{
133204133243
i = yy_shift_ofst[stateno];
133205
- if( i==YY_SHIFT_USE_DFLT ) return yy_default[stateno];
133206133244
assert( iLookAhead!=YYNOCODE );
133207133245
i += iLookAhead;
133208133246
if( i<0 || i>=YY_ACTTAB_COUNT || yy_lookahead[i]!=iLookAhead ){
133209
- if( iLookAhead>0 ){
133210133247
#ifdef YYFALLBACK
133211
- YYCODETYPE iFallback; /* Fallback token */
133212
- if( iLookAhead<sizeof(yyFallback)/sizeof(yyFallback[0])
133213
- && (iFallback = yyFallback[iLookAhead])!=0 ){
133248
+ YYCODETYPE iFallback; /* Fallback token */
133249
+ if( iLookAhead<sizeof(yyFallback)/sizeof(yyFallback[0])
133250
+ && (iFallback = yyFallback[iLookAhead])!=0 ){
133214133251
#ifndef NDEBUG
133215
- if( yyTraceFILE ){
133216
- fprintf(yyTraceFILE, "%sFALLBACK %s => %s\n",
133217
- yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]);
133218
- }
133252
+ if( yyTraceFILE ){
133253
+ fprintf(yyTraceFILE, "%sFALLBACK %s => %s\n",
133254
+ yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]);
133255
+ }
133219133256
#endif
133220
- assert( yyFallback[iFallback]==0 ); /* Fallback loop must terminate */
133221
- iLookAhead = iFallback;
133222
- continue;
133223
- }
133257
+ assert( yyFallback[iFallback]==0 ); /* Fallback loop must terminate */
133258
+ iLookAhead = iFallback;
133259
+ continue;
133260
+ }
133224133261
#endif
133225133262
#ifdef YYWILDCARD
133226
- {
133227
- int j = i - iLookAhead + YYWILDCARD;
133228
- if(
133263
+ {
133264
+ int j = i - iLookAhead + YYWILDCARD;
133265
+ if(
133229133266
#if YY_SHIFT_MIN+YYWILDCARD<0
133230
- j>=0 &&
133267
+ j>=0 &&
133231133268
#endif
133232133269
#if YY_SHIFT_MAX+YYWILDCARD>=YY_ACTTAB_COUNT
133233
- j<YY_ACTTAB_COUNT &&
133270
+ j<YY_ACTTAB_COUNT &&
133234133271
#endif
133235
- yy_lookahead[j]==YYWILDCARD
133236
- ){
133272
+ yy_lookahead[j]==YYWILDCARD && iLookAhead>0
133273
+ ){
133237133274
#ifndef NDEBUG
133238
- if( yyTraceFILE ){
133239
- fprintf(yyTraceFILE, "%sWILDCARD %s => %s\n",
133240
- yyTracePrompt, yyTokenName[iLookAhead],
133241
- yyTokenName[YYWILDCARD]);
133242
- }
133275
+ if( yyTraceFILE ){
133276
+ fprintf(yyTraceFILE, "%sWILDCARD %s => %s\n",
133277
+ yyTracePrompt, yyTokenName[iLookAhead],
133278
+ yyTokenName[YYWILDCARD]);
133279
+ }
133243133280
#endif /* NDEBUG */
133244
- return yy_action[j];
133245
- }
133281
+ return yy_action[j];
133246133282
}
133283
+ }
133247133284
#endif /* YYWILDCARD */
133248
- }
133249133285
return yy_default[stateno];
133250133286
}else{
133251133287
return yy_action[i];
133252133288
}
133253133289
}while(1);
@@ -136006,18 +136042,30 @@
136006136042
assert( pParse->pNewTable==0 );
136007136043
assert( pParse->pNewTrigger==0 );
136008136044
assert( pParse->nVar==0 );
136009136045
assert( pParse->nzVar==0 );
136010136046
assert( pParse->azVar==0 );
136011
- while( zSql[i]!=0 ){
136047
+ while( 1 ){
136012136048
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;
136049
+ if( zSql[i]!=0 ){
136050
+ pParse->sLastToken.z = &zSql[i];
136051
+ pParse->sLastToken.n = sqlite3GetToken((u8*)&zSql[i],&tokenType);
136052
+ i += pParse->sLastToken.n;
136053
+ if( i>mxSqlLen ){
136054
+ pParse->rc = SQLITE_TOOBIG;
136055
+ break;
136056
+ }
136057
+ }else{
136058
+ /* Upon reaching the end of input, call the parser two more times
136059
+ ** with tokens TK_SEMI and 0, in that order. */
136060
+ if( lastTokenParsed==TK_SEMI ){
136061
+ tokenType = 0;
136062
+ }else if( lastTokenParsed==0 ){
136063
+ break;
136064
+ }else{
136065
+ tokenType = TK_SEMI;
136066
+ }
136019136067
}
136020136068
if( tokenType>=TK_SPACE ){
136021136069
assert( tokenType==TK_SPACE || tokenType==TK_ILLEGAL );
136022136070
if( db->u1.isInterrupted ){
136023136071
pParse->rc = SQLITE_INTERRUPT;
@@ -136034,19 +136082,10 @@
136034136082
if( pParse->rc!=SQLITE_OK || db->mallocFailed ) break;
136035136083
}
136036136084
}
136037136085
assert( nErr==0 );
136038136086
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
- }
136048136087
#ifdef YYTRACKMAXSTACKDEPTH
136049136088
sqlite3_mutex_enter(sqlite3MallocMutex());
136050136089
sqlite3StatusHighwater(SQLITE_STATUS_PARSER_STACK,
136051136090
sqlite3ParserStackPeak(pEngine)
136052136091
);
@@ -137282,10 +137321,15 @@
137282137321
SQLITE_API int SQLITE_CDECL sqlite3_db_config(sqlite3 *db, int op, ...){
137283137322
va_list ap;
137284137323
int rc;
137285137324
va_start(ap, op);
137286137325
switch( op ){
137326
+ case SQLITE_DBCONFIG_MAINDBNAME: {
137327
+ db->aDb[0].zDbSName = va_arg(ap,char*);
137328
+ rc = SQLITE_OK;
137329
+ break;
137330
+ }
137287137331
case SQLITE_DBCONFIG_LOOKASIDE: {
137288137332
void *pBuf = va_arg(ap, void*); /* IMP: R-26835-10964 */
137289137333
int sz = va_arg(ap, int); /* IMP: R-47871-25994 */
137290137334
int cnt = va_arg(ap, int); /* IMP: R-04460-53386 */
137291137335
rc = setupLookaside(db, pBuf, sz, cnt);
@@ -139425,13 +139469,13 @@
139425139469
db->aDb[1].pSchema = sqlite3SchemaGet(db, 0);
139426139470
139427139471
/* The default safety_level for the main database is FULL; for the temp
139428139472
** database it is OFF. This matches the pager layer defaults.
139429139473
*/
139430
- db->aDb[0].zName = "main";
139474
+ db->aDb[0].zDbSName = "main";
139431139475
db->aDb[0].safety_level = SQLITE_DEFAULT_SYNCHRONOUS+1;
139432
- db->aDb[1].zName = "temp";
139476
+ db->aDb[1].zDbSName = "temp";
139433139477
db->aDb[1].safety_level = PAGER_SYNCHRONOUS_OFF;
139434139478
139435139479
db->magic = SQLITE_MAGIC_OPEN;
139436139480
if( db->mallocFailed ){
139437139481
goto opendb_out;
@@ -140388,11 +140432,11 @@
140388140432
*/
140389140433
SQLITE_PRIVATE Btree *sqlite3DbNameToBtree(sqlite3 *db, const char *zDbName){
140390140434
int i;
140391140435
for(i=0; i<db->nDb; i++){
140392140436
if( db->aDb[i].pBt
140393
- && (zDbName==0 || sqlite3StrICmp(zDbName, db->aDb[i].zName)==0)
140437
+ && (zDbName==0 || sqlite3StrICmp(zDbName, db->aDb[i].zDbSName)==0)
140394140438
){
140395140439
return db->aDb[i].pBt;
140396140440
}
140397140441
}
140398140442
return 0;
@@ -164754,19 +164798,25 @@
164754164798
/*
164755164799
** Open an RBU handle to perform an RBU vacuum on database file zTarget.
164756164800
** An RBU vacuum is similar to SQLite's built-in VACUUM command, except
164757164801
** that it can be suspended and resumed like an RBU update.
164758164802
**
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
164803
+** The second argument to this function identifies a database in which
164804
+** to store the state of the RBU vacuum operation if it is suspended. The
164805
+** first time sqlite3rbu_vacuum() is called, to start an RBU vacuum
164806
+** operation, the state database should either not exist or be empty
164807
+** (contain no tables). If an RBU vacuum is suspended by calling
164764164808
** sqlite3rbu_close() on the RBU handle before sqlite3rbu_step() has
164765164809
** returned SQLITE_DONE, the vacuum state is stored in the state database.
164766164810
** The vacuum can be resumed by calling this function to open a new RBU
164767164811
** handle specifying the same target and state databases.
164812
+**
164813
+** If the second argument passed to this function is NULL, then the
164814
+** name of the state database is "<database>-vacuum", where <database>
164815
+** is the name of the target database file. In this case, on UNIX, if the
164816
+** state database is not already present in the file-system, it is created
164817
+** with the same permissions as the target db is made.
164768164818
**
164769164819
** This function does not delete the state database after an RBU vacuum
164770164820
** is completed, even if it created it. However, if the call to
164771164821
** sqlite3rbu_close() returns any value other than SQLITE_OK, the contents
164772164822
** of the state tables within the state database are zeroed. This way,
@@ -167255,19 +167305,22 @@
167255167305
/*
167256167306
** Open the database handle and attach the RBU database as "rbu". If an
167257167307
** error occurs, leave an error code and message in the RBU handle.
167258167308
*/
167259167309
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 );
167310
+ assert( p->rc || (p->dbMain==0 && p->dbRbu==0) );
167311
+ assert( p->rc || rbuIsVacuum(p) || p->zTarget!=0 );
167263167312
167264167313
/* Open the RBU database */
167265167314
p->dbRbu = rbuOpenDbhandle(p, p->zRbu, 1);
167266167315
167267167316
if( p->rc==SQLITE_OK && rbuIsVacuum(p) ){
167268167317
sqlite3_file_control(p->dbRbu, "main", SQLITE_FCNTL_RBUCNT, (void*)p);
167318
+ if( p->zState==0 ){
167319
+ const char *zFile = sqlite3_db_filename(p->dbRbu, "main");
167320
+ p->zState = rbuMPrintf(p, "file://%s-vacuum?modeof=%s", zFile, zFile);
167321
+ }
167269167322
}
167270167323
167271167324
/* If using separate RBU and state databases, attach the state database to
167272167325
** the RBU db handle now. */
167273167326
if( p->zState ){
@@ -168398,12 +168451,11 @@
168398168451
const char *zState
168399168452
){
168400168453
sqlite3rbu *p;
168401168454
size_t nTarget = zTarget ? strlen(zTarget) : 0;
168402168455
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;
168456
+ size_t nByte = sizeof(sqlite3rbu) + nTarget+1 + nRbu+1;
168405168457
168406168458
p = (sqlite3rbu*)sqlite3_malloc64(nByte);
168407168459
if( p ){
168408168460
RbuState *pState = 0;
168409168461
@@ -168421,12 +168473,11 @@
168421168473
}
168422168474
p->zRbu = pCsr;
168423168475
memcpy(p->zRbu, zRbu, nRbu+1);
168424168476
pCsr += nRbu+1;
168425168477
if( zState ){
168426
- p->zState = pCsr;
168427
- memcpy(p->zState, zState, nState+1);
168478
+ p->zState = rbuMPrintf(p, "%s", zState);
168428168479
}
168429168480
rbuOpenDatabase(p);
168430168481
}
168431168482
168432168483
if( p->rc==SQLITE_OK ){
@@ -168531,19 +168582,34 @@
168531168582
rbuFreeState(pState);
168532168583
}
168533168584
168534168585
return p;
168535168586
}
168587
+
168588
+/*
168589
+** Allocate and return an RBU handle with all fields zeroed except for the
168590
+** error code, which is set to SQLITE_MISUSE.
168591
+*/
168592
+static sqlite3rbu *rbuMisuseError(void){
168593
+ sqlite3rbu *pRet;
168594
+ pRet = sqlite3_malloc64(sizeof(sqlite3rbu));
168595
+ if( pRet ){
168596
+ memset(pRet, 0, sizeof(sqlite3rbu));
168597
+ pRet->rc = SQLITE_MISUSE;
168598
+ }
168599
+ return pRet;
168600
+}
168536168601
168537168602
/*
168538168603
** Open and return a new RBU handle.
168539168604
*/
168540168605
SQLITE_API sqlite3rbu *SQLITE_STDCALL sqlite3rbu_open(
168541168606
const char *zTarget,
168542168607
const char *zRbu,
168543168608
const char *zState
168544168609
){
168610
+ if( zTarget==0 || zRbu==0 ){ return rbuMisuseError(); }
168545168611
/* TODO: Check that zTarget and zRbu are non-NULL */
168546168612
return openRbuHandle(zTarget, zRbu, zState);
168547168613
}
168548168614
168549168615
/*
@@ -168551,10 +168617,11 @@
168551168617
*/
168552168618
SQLITE_API sqlite3rbu *SQLITE_STDCALL sqlite3rbu_vacuum(
168553168619
const char *zTarget,
168554168620
const char *zState
168555168621
){
168622
+ if( zTarget==0 ){ return rbuMisuseError(); }
168556168623
/* TODO: Check that both arguments are non-NULL */
168557168624
return openRbuHandle(0, zTarget, zState);
168558168625
}
168559168626
168560168627
/*
@@ -168628,10 +168695,11 @@
168628168695
sqlite3_free(p->aFrame);
168629168696
168630168697
rbuEditErrmsg(p);
168631168698
rc = p->rc;
168632168699
*pzErrmsg = p->zErrmsg;
168700
+ sqlite3_free(p->zState);
168633168701
sqlite3_free(p);
168634168702
}else{
168635168703
rc = SQLITE_NOMEM;
168636168704
*pzErrmsg = 0;
168637168705
}
@@ -170239,11 +170307,11 @@
170239170307
zSql = sqlite3_mprintf(
170240170308
"SELECT 'sqlite_master' AS name, 1 AS rootpage, 'table' AS type"
170241170309
" UNION ALL "
170242170310
"SELECT name, rootpage, type"
170243170311
" FROM \"%w\".%s WHERE rootpage!=0"
170244
- " ORDER BY name", pTab->db->aDb[pCsr->iDb].zName, zMaster);
170312
+ " ORDER BY name", pTab->db->aDb[pCsr->iDb].zDbSName, zMaster);
170245170313
if( zSql==0 ){
170246170314
return SQLITE_NOMEM_BKPT;
170247170315
}else{
170248170316
rc = sqlite3_prepare_v2(pTab->db, zSql, -1, &pCsr->pStmt, 0);
170249170317
sqlite3_free(zSql);
@@ -170293,11 +170361,11 @@
170293170361
sqlite3_result_int(ctx, pCsr->szPage);
170294170362
break;
170295170363
default: { /* schema */
170296170364
sqlite3 *db = sqlite3_context_db_handle(ctx);
170297170365
int iDb = pCsr->iDb;
170298
- sqlite3_result_text(ctx, db->aDb[iDb].zName, -1, SQLITE_STATIC);
170366
+ sqlite3_result_text(ctx, db->aDb[iDb].zDbSName, -1, SQLITE_STATIC);
170299170367
break;
170300170368
}
170301170369
}
170302170370
return SQLITE_OK;
170303170371
}
@@ -178530,10 +178598,11 @@
178530178598
static void sqlite3Fts5ParseNearsetFree(Fts5ExprNearset*);
178531178599
static void sqlite3Fts5ParseNodeFree(Fts5ExprNode*);
178532178600
178533178601
static void sqlite3Fts5ParseSetDistance(Fts5Parse*, Fts5ExprNearset*, Fts5Token*);
178534178602
static void sqlite3Fts5ParseSetColset(Fts5Parse*, Fts5ExprNearset*, Fts5Colset*);
178603
+static Fts5Colset *sqlite3Fts5ParseColsetInvert(Fts5Parse*, Fts5Colset*);
178535178604
static void sqlite3Fts5ParseFinished(Fts5Parse *pParse, Fts5ExprNode *p);
178536178605
static void sqlite3Fts5ParseNear(Fts5Parse *pParse, Fts5Token*);
178537178606
178538178607
/*
178539178608
** End of interface to code in fts5_expr.c.
@@ -178587,16 +178656,17 @@
178587178656
#define FTS5_NOT 3
178588178657
#define FTS5_TERM 4
178589178658
#define FTS5_COLON 5
178590178659
#define FTS5_LP 6
178591178660
#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
178661
+#define FTS5_MINUS 8
178662
+#define FTS5_LCP 9
178663
+#define FTS5_RCP 10
178664
+#define FTS5_STRING 11
178665
+#define FTS5_COMMA 12
178666
+#define FTS5_PLUS 13
178667
+#define FTS5_STAR 14
178598178668
178599178669
/*
178600178670
** 2000-05-29
178601178671
**
178602178672
** The author disclaims copyright to this source code. In place of
@@ -178706,39 +178776,39 @@
178706178776
#ifndef INTERFACE
178707178777
# define INTERFACE 1
178708178778
#endif
178709178779
/************* Begin control #defines *****************************************/
178710178780
#define fts5YYCODETYPE unsigned char
178711
-#define fts5YYNOCODE 27
178781
+#define fts5YYNOCODE 28
178712178782
#define fts5YYACTIONTYPE unsigned char
178713178783
#define sqlite3Fts5ParserFTS5TOKENTYPE Fts5Token
178714178784
typedef union {
178715178785
int fts5yyinit;
178716178786
sqlite3Fts5ParserFTS5TOKENTYPE fts5yy0;
178717
- Fts5Colset* fts5yy3;
178718
- Fts5ExprPhrase* fts5yy11;
178719
- Fts5ExprNode* fts5yy18;
178720
- int fts5yy20;
178721
- Fts5ExprNearset* fts5yy26;
178787
+ int fts5yy4;
178788
+ Fts5Colset* fts5yy11;
178789
+ Fts5ExprNode* fts5yy24;
178790
+ Fts5ExprNearset* fts5yy46;
178791
+ Fts5ExprPhrase* fts5yy53;
178722178792
} fts5YYMINORTYPE;
178723178793
#ifndef fts5YYSTACKDEPTH
178724178794
#define fts5YYSTACKDEPTH 100
178725178795
#endif
178726178796
#define sqlite3Fts5ParserARG_SDECL Fts5Parse *pParse;
178727178797
#define sqlite3Fts5ParserARG_PDECL ,Fts5Parse *pParse
178728178798
#define sqlite3Fts5ParserARG_FETCH Fts5Parse *pParse = fts5yypParser->pParse
178729178799
#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
178800
+#define fts5YYNSTATE 29
178801
+#define fts5YYNRULE 26
178802
+#define fts5YY_MAX_SHIFT 28
178803
+#define fts5YY_MIN_SHIFTREDUCE 45
178804
+#define fts5YY_MAX_SHIFTREDUCE 70
178805
+#define fts5YY_MIN_REDUCE 71
178806
+#define fts5YY_MAX_REDUCE 96
178807
+#define fts5YY_ERROR_ACTION 97
178808
+#define fts5YY_ACCEPT_ACTION 98
178809
+#define fts5YY_NO_ACTION 99
178740178810
/************* End control #defines *******************************************/
178741178811
178742178812
/* Define the fts5yytestcase() macro to be a no-op if is not already defined
178743178813
** otherwise.
178744178814
**
@@ -178766,29 +178836,33 @@
178766178836
** N between fts5YY_MIN_SHIFTREDUCE Shift to an arbitrary state then
178767178837
** and fts5YY_MAX_SHIFTREDUCE reduce by rule N-fts5YY_MIN_SHIFTREDUCE.
178768178838
**
178769178839
** N between fts5YY_MIN_REDUCE Reduce by rule N-fts5YY_MIN_REDUCE
178770178840
** and fts5YY_MAX_REDUCE
178771
-
178841
+**
178772178842
** N == fts5YY_ERROR_ACTION A syntax error has occurred.
178773178843
**
178774178844
** N == fts5YY_ACCEPT_ACTION The parser accepts its input.
178775178845
**
178776178846
** N == fts5YY_NO_ACTION No such action. Denotes unused
178777178847
** slots in the fts5yy_action[] table.
178778178848
**
178779178849
** 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
178850
+** Given state S and lookahead X, the action is computed as either:
178851
+**
178852
+** (A) N = fts5yy_action[ fts5yy_shift_ofst[S] + X ]
178853
+** (B) N = fts5yy_default[S]
178854
+**
178855
+** The (A) formula is preferred. The B formula is used instead if:
178856
+** (1) The fts5yy_shift_ofst[S]+X value is out of range, or
178857
+** (2) fts5yy_lookahead[fts5yy_shift_ofst[S]+X] is not equal to X, or
178858
+** (3) fts5yy_shift_ofst[S] equal fts5YY_SHIFT_USE_DFLT.
178859
+** (Implementation note: fts5YY_SHIFT_USE_DFLT is chosen so that
178860
+** fts5YY_SHIFT_USE_DFLT+X will be out of range for all possible lookaheads X.
178861
+** Hence only tests (1) and (2) need to be evaluated.)
178862
+**
178863
+** The formulas above are for computing the action when the lookahead is
178790178864
** a terminal symbol. If the lookahead is a non-terminal (as occurs after
178791178865
** a reduce action) then the fts5yy_reduce_ofst[] array is used in place of
178792178866
** the fts5yy_shift_ofst[] array and fts5YY_REDUCE_USE_DFLT is used in place of
178793178867
** fts5YY_SHIFT_USE_DFLT.
178794178868
**
@@ -178802,52 +178876,54 @@
178802178876
** fts5yy_reduce_ofst[] For each state, the offset into fts5yy_action for
178803178877
** shifting non-terminals after a reduce.
178804178878
** fts5yy_default[] Default action for each state.
178805178879
**
178806178880
*********** Begin parsing tables **********************************************/
178807
-#define fts5YY_ACTTAB_COUNT (78)
178881
+#define fts5YY_ACTTAB_COUNT (85)
178808178882
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,
178883
+ /* 0 */ 98, 16, 51, 5, 53, 27, 83, 7, 26, 15,
178884
+ /* 10 */ 51, 5, 53, 27, 13, 69, 26, 48, 51, 5,
178885
+ /* 20 */ 53, 27, 19, 11, 26, 9, 20, 51, 5, 53,
178886
+ /* 30 */ 27, 13, 22, 26, 28, 51, 5, 53, 27, 68,
178887
+ /* 40 */ 1, 26, 19, 11, 17, 9, 52, 10, 53, 27,
178888
+ /* 50 */ 23, 24, 26, 54, 3, 4, 2, 26, 6, 21,
178889
+ /* 60 */ 49, 71, 3, 4, 2, 7, 56, 59, 55, 59,
178890
+ /* 70 */ 4, 2, 12, 69, 58, 60, 18, 67, 62, 69,
178891
+ /* 80 */ 25, 66, 8, 14, 2,
178817178892
};
178818178893
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)
178894
+ /* 0 */ 16, 17, 18, 19, 20, 21, 5, 6, 24, 17,
178895
+ /* 10 */ 18, 19, 20, 21, 11, 14, 24, 17, 18, 19,
178896
+ /* 20 */ 20, 21, 8, 9, 24, 11, 17, 18, 19, 20,
178897
+ /* 30 */ 21, 11, 12, 24, 17, 18, 19, 20, 21, 26,
178898
+ /* 40 */ 6, 24, 8, 9, 22, 11, 18, 11, 20, 21,
178899
+ /* 50 */ 24, 25, 24, 20, 1, 2, 3, 24, 23, 24,
178900
+ /* 60 */ 7, 0, 1, 2, 3, 6, 10, 11, 10, 11,
178901
+ /* 70 */ 2, 3, 9, 14, 11, 11, 22, 26, 7, 14,
178902
+ /* 80 */ 13, 11, 5, 11, 3,
178903
+};
178904
+#define fts5YY_SHIFT_USE_DFLT (85)
178905
+#define fts5YY_SHIFT_COUNT (28)
178906
+#define fts5YY_SHIFT_MIN (0)
178907
+#define fts5YY_SHIFT_MAX (81)
178908
+static const unsigned char fts5yy_shift_ofst[] = {
178909
+ /* 0 */ 34, 34, 34, 34, 34, 14, 20, 3, 36, 1,
178910
+ /* 10 */ 59, 64, 64, 65, 65, 53, 61, 56, 58, 63,
178911
+ /* 20 */ 68, 67, 70, 67, 71, 72, 67, 77, 81,
178912
+};
178913
+#define fts5YY_REDUCE_USE_DFLT (-17)
178914
+#define fts5YY_REDUCE_COUNT (14)
178915
+#define fts5YY_REDUCE_MIN (-16)
178916
+#define fts5YY_REDUCE_MAX (54)
178841178917
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,
178918
+ /* 0 */ -16, -8, 0, 9, 17, 28, 26, 35, 33, 13,
178919
+ /* 10 */ 13, 22, 54, 13, 51,
178844178920
};
178845178921
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,
178922
+ /* 0 */ 97, 97, 97, 97, 97, 76, 91, 97, 97, 96,
178923
+ /* 10 */ 96, 97, 97, 96, 96, 97, 97, 97, 97, 97,
178924
+ /* 20 */ 73, 89, 97, 90, 97, 97, 87, 97, 72,
178849178925
};
178850178926
/********** End of lemon-generated parsing tables *****************************/
178851178927
178852178928
/* The next table maps tokens (terminal symbols) into fallback tokens.
178853178929
** If a construct like the following:
@@ -178950,15 +179026,15 @@
178950179026
/* For tracing shifts, the names of all terminals and nonterminals
178951179027
** are required. The following table supplies these names */
178952179028
static const char *const fts5yyTokenName[] = {
178953179029
"$", "OR", "AND", "NOT",
178954179030
"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",
179031
+ "MINUS", "LCP", "RCP", "STRING",
179032
+ "COMMA", "PLUS", "STAR", "error",
179033
+ "input", "expr", "cnearset", "exprlist",
179034
+ "nearset", "colset", "colsetlist", "nearphrases",
179035
+ "phrase", "neardist_opt", "star_opt",
178960179036
};
178961179037
#endif /* NDEBUG */
178962179038
178963179039
#ifndef NDEBUG
178964179040
/* For tracing reduce actions, the names of all rules are required.
@@ -178972,24 +179048,26 @@
178972179048
/* 5 */ "expr ::= exprlist",
178973179049
/* 6 */ "exprlist ::= cnearset",
178974179050
/* 7 */ "exprlist ::= exprlist cnearset",
178975179051
/* 8 */ "cnearset ::= nearset",
178976179052
/* 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 ::=",
179053
+ /* 10 */ "colset ::= MINUS LCP colsetlist RCP",
179054
+ /* 11 */ "colset ::= LCP colsetlist RCP",
179055
+ /* 12 */ "colset ::= STRING",
179056
+ /* 13 */ "colset ::= MINUS STRING",
179057
+ /* 14 */ "colsetlist ::= colsetlist STRING",
179058
+ /* 15 */ "colsetlist ::= STRING",
179059
+ /* 16 */ "nearset ::= phrase",
179060
+ /* 17 */ "nearset ::= STRING LP nearphrases neardist_opt RP",
179061
+ /* 18 */ "nearphrases ::= phrase",
179062
+ /* 19 */ "nearphrases ::= nearphrases phrase",
179063
+ /* 20 */ "neardist_opt ::=",
179064
+ /* 21 */ "neardist_opt ::= COMMA STRING",
179065
+ /* 22 */ "phrase ::= phrase PLUS STRING star_opt",
179066
+ /* 23 */ "phrase ::= STRING star_opt",
179067
+ /* 24 */ "star_opt ::= STAR",
179068
+ /* 25 */ "star_opt ::=",
178991179069
};
178992179070
#endif /* NDEBUG */
178993179071
178994179072
178995179073
#if fts5YYSTACKDEPTH<=0
@@ -179095,37 +179173,37 @@
179095179173
** Note: during a reduce, the only symbols destroyed are those
179096179174
** which appear on the RHS of the rule, but which are *not* used
179097179175
** inside the C code.
179098179176
*/
179099179177
/********* Begin destructor definitions ***************************************/
179100
- case 15: /* input */
179178
+ case 16: /* input */
179101179179
{
179102179180
(void)pParse;
179103179181
}
179104179182
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));
179183
+ case 17: /* expr */
179184
+ case 18: /* cnearset */
179185
+ case 19: /* exprlist */
179186
+{
179187
+ sqlite3Fts5ParseNodeFree((fts5yypminor->fts5yy24));
179188
+}
179189
+ break;
179190
+ case 20: /* nearset */
179191
+ case 23: /* nearphrases */
179192
+{
179193
+ sqlite3Fts5ParseNearsetFree((fts5yypminor->fts5yy46));
179194
+}
179195
+ break;
179196
+ case 21: /* colset */
179197
+ case 22: /* colsetlist */
179198
+{
179199
+ sqlite3_free((fts5yypminor->fts5yy11));
179200
+}
179201
+ break;
179202
+ case 24: /* phrase */
179203
+{
179204
+ sqlite3Fts5ParsePhraseFree((fts5yypminor->fts5yy53));
179127179205
}
179128179206
break;
179129179207
/********* End destructor definitions *****************************************/
179130179208
default: break; /* If no destructor action specified: do nothing */
179131179209
}
@@ -179198,54 +179276,51 @@
179198179276
179199179277
if( stateno>=fts5YY_MIN_REDUCE ) return stateno;
179200179278
assert( stateno <= fts5YY_SHIFT_COUNT );
179201179279
do{
179202179280
i = fts5yy_shift_ofst[stateno];
179203
- if( i==fts5YY_SHIFT_USE_DFLT ) return fts5yy_default[stateno];
179204179281
assert( iLookAhead!=fts5YYNOCODE );
179205179282
i += iLookAhead;
179206179283
if( i<0 || i>=fts5YY_ACTTAB_COUNT || fts5yy_lookahead[i]!=iLookAhead ){
179207
- if( iLookAhead>0 ){
179208179284
#ifdef fts5YYFALLBACK
179209
- fts5YYCODETYPE iFallback; /* Fallback token */
179210
- if( iLookAhead<sizeof(fts5yyFallback)/sizeof(fts5yyFallback[0])
179211
- && (iFallback = fts5yyFallback[iLookAhead])!=0 ){
179285
+ fts5YYCODETYPE iFallback; /* Fallback token */
179286
+ if( iLookAhead<sizeof(fts5yyFallback)/sizeof(fts5yyFallback[0])
179287
+ && (iFallback = fts5yyFallback[iLookAhead])!=0 ){
179212179288
#ifndef NDEBUG
179213
- if( fts5yyTraceFILE ){
179214
- fprintf(fts5yyTraceFILE, "%sFALLBACK %s => %s\n",
179215
- fts5yyTracePrompt, fts5yyTokenName[iLookAhead], fts5yyTokenName[iFallback]);
179216
- }
179289
+ if( fts5yyTraceFILE ){
179290
+ fprintf(fts5yyTraceFILE, "%sFALLBACK %s => %s\n",
179291
+ fts5yyTracePrompt, fts5yyTokenName[iLookAhead], fts5yyTokenName[iFallback]);
179292
+ }
179217179293
#endif
179218
- assert( fts5yyFallback[iFallback]==0 ); /* Fallback loop must terminate */
179219
- iLookAhead = iFallback;
179220
- continue;
179221
- }
179294
+ assert( fts5yyFallback[iFallback]==0 ); /* Fallback loop must terminate */
179295
+ iLookAhead = iFallback;
179296
+ continue;
179297
+ }
179222179298
#endif
179223179299
#ifdef fts5YYWILDCARD
179224
- {
179225
- int j = i - iLookAhead + fts5YYWILDCARD;
179226
- if(
179300
+ {
179301
+ int j = i - iLookAhead + fts5YYWILDCARD;
179302
+ if(
179227179303
#if fts5YY_SHIFT_MIN+fts5YYWILDCARD<0
179228
- j>=0 &&
179304
+ j>=0 &&
179229179305
#endif
179230179306
#if fts5YY_SHIFT_MAX+fts5YYWILDCARD>=fts5YY_ACTTAB_COUNT
179231
- j<fts5YY_ACTTAB_COUNT &&
179307
+ j<fts5YY_ACTTAB_COUNT &&
179232179308
#endif
179233
- fts5yy_lookahead[j]==fts5YYWILDCARD
179234
- ){
179309
+ fts5yy_lookahead[j]==fts5YYWILDCARD && iLookAhead>0
179310
+ ){
179235179311
#ifndef NDEBUG
179236
- if( fts5yyTraceFILE ){
179237
- fprintf(fts5yyTraceFILE, "%sWILDCARD %s => %s\n",
179238
- fts5yyTracePrompt, fts5yyTokenName[iLookAhead],
179239
- fts5yyTokenName[fts5YYWILDCARD]);
179240
- }
179312
+ if( fts5yyTraceFILE ){
179313
+ fprintf(fts5yyTraceFILE, "%sWILDCARD %s => %s\n",
179314
+ fts5yyTracePrompt, fts5yyTokenName[iLookAhead],
179315
+ fts5yyTokenName[fts5YYWILDCARD]);
179316
+ }
179241179317
#endif /* NDEBUG */
179242
- return fts5yy_action[j];
179243
- }
179318
+ return fts5yy_action[j];
179244179319
}
179320
+ }
179245179321
#endif /* fts5YYWILDCARD */
179246
- }
179247179322
return fts5yy_default[stateno];
179248179323
}else{
179249179324
return fts5yy_action[i];
179250179325
}
179251179326
}while(1);
@@ -179368,34 +179443,36 @@
179368179443
*/
179369179444
static const struct {
179370179445
fts5YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */
179371179446
unsigned char nrhs; /* Number of right-hand side symbols in the rule */
179372179447
} fts5yyRuleInfo[] = {
179373
- { 15, 1 },
179374
- { 16, 3 },
179375
- { 16, 3 },
179376
- { 16, 3 },
179377
- { 16, 3 },
179378179448
{ 16, 1 },
179449
+ { 17, 3 },
179450
+ { 17, 3 },
179451
+ { 17, 3 },
179452
+ { 17, 3 },
179453
+ { 17, 1 },
179454
+ { 19, 1 },
179455
+ { 19, 2 },
179379179456
{ 18, 1 },
179380
- { 18, 2 },
179381
- { 17, 1 },
179382
- { 17, 3 },
179383
- { 20, 3 },
179384
- { 20, 1 },
179457
+ { 18, 3 },
179458
+ { 21, 4 },
179459
+ { 21, 3 },
179460
+ { 21, 1 },
179385179461
{ 21, 2 },
179386
- { 21, 1 },
179387
- { 19, 1 },
179388
- { 19, 5 },
179462
+ { 22, 2 },
179389179463
{ 22, 1 },
179390
- { 22, 2 },
179391
- { 24, 0 },
179392
- { 24, 2 },
179393
- { 23, 4 },
179464
+ { 20, 1 },
179465
+ { 20, 5 },
179466
+ { 23, 1 },
179394179467
{ 23, 2 },
179395
- { 25, 1 },
179396179468
{ 25, 0 },
179469
+ { 25, 2 },
179470
+ { 24, 4 },
179471
+ { 24, 2 },
179472
+ { 26, 1 },
179473
+ { 26, 0 },
179397179474
};
179398179475
179399179476
static void fts5yy_accept(fts5yyParser*); /* Forward Declaration */
179400179477
179401179478
/*
@@ -179456,124 +179533,135 @@
179456179533
** break;
179457179534
*/
179458179535
/********** Begin reduce actions **********************************************/
179459179536
fts5YYMINORTYPE fts5yylhsminor;
179460179537
case 0: /* input ::= expr */
179461
-{ sqlite3Fts5ParseFinished(pParse, fts5yymsp[0].minor.fts5yy18); }
179538
+{ sqlite3Fts5ParseFinished(pParse, fts5yymsp[0].minor.fts5yy24); }
179462179539
break;
179463179540
case 1: /* expr ::= expr AND expr */
179464179541
{
179465
- fts5yylhsminor.fts5yy18 = sqlite3Fts5ParseNode(pParse, FTS5_AND, fts5yymsp[-2].minor.fts5yy18, fts5yymsp[0].minor.fts5yy18, 0);
179542
+ fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_AND, fts5yymsp[-2].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24, 0);
179466179543
}
179467
- fts5yymsp[-2].minor.fts5yy18 = fts5yylhsminor.fts5yy18;
179544
+ fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
179468179545
break;
179469179546
case 2: /* expr ::= expr OR expr */
179470179547
{
179471
- fts5yylhsminor.fts5yy18 = sqlite3Fts5ParseNode(pParse, FTS5_OR, fts5yymsp[-2].minor.fts5yy18, fts5yymsp[0].minor.fts5yy18, 0);
179548
+ fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_OR, fts5yymsp[-2].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24, 0);
179472179549
}
179473
- fts5yymsp[-2].minor.fts5yy18 = fts5yylhsminor.fts5yy18;
179550
+ fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
179474179551
break;
179475179552
case 3: /* expr ::= expr NOT expr */
179476179553
{
179477
- fts5yylhsminor.fts5yy18 = sqlite3Fts5ParseNode(pParse, FTS5_NOT, fts5yymsp[-2].minor.fts5yy18, fts5yymsp[0].minor.fts5yy18, 0);
179554
+ fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_NOT, fts5yymsp[-2].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24, 0);
179478179555
}
179479
- fts5yymsp[-2].minor.fts5yy18 = fts5yylhsminor.fts5yy18;
179556
+ fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
179480179557
break;
179481179558
case 4: /* expr ::= LP expr RP */
179482
-{fts5yymsp[-2].minor.fts5yy18 = fts5yymsp[-1].minor.fts5yy18;}
179559
+{fts5yymsp[-2].minor.fts5yy24 = fts5yymsp[-1].minor.fts5yy24;}
179483179560
break;
179484179561
case 5: /* expr ::= exprlist */
179485179562
case 6: /* exprlist ::= cnearset */ fts5yytestcase(fts5yyruleno==6);
179486
-{fts5yylhsminor.fts5yy18 = fts5yymsp[0].minor.fts5yy18;}
179487
- fts5yymsp[0].minor.fts5yy18 = fts5yylhsminor.fts5yy18;
179563
+{fts5yylhsminor.fts5yy24 = fts5yymsp[0].minor.fts5yy24;}
179564
+ fts5yymsp[0].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
179488179565
break;
179489179566
case 7: /* exprlist ::= exprlist cnearset */
179490179567
{
179491
- fts5yylhsminor.fts5yy18 = sqlite3Fts5ParseImplicitAnd(pParse, fts5yymsp[-1].minor.fts5yy18, fts5yymsp[0].minor.fts5yy18);
179568
+ fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseImplicitAnd(pParse, fts5yymsp[-1].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24);
179492179569
}
179493
- fts5yymsp[-1].minor.fts5yy18 = fts5yylhsminor.fts5yy18;
179570
+ fts5yymsp[-1].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
179494179571
break;
179495179572
case 8: /* cnearset ::= nearset */
179496179573
{
179497
- fts5yylhsminor.fts5yy18 = sqlite3Fts5ParseNode(pParse, FTS5_STRING, 0, 0, fts5yymsp[0].minor.fts5yy26);
179574
+ fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_STRING, 0, 0, fts5yymsp[0].minor.fts5yy46);
179498179575
}
179499
- fts5yymsp[0].minor.fts5yy18 = fts5yylhsminor.fts5yy18;
179576
+ fts5yymsp[0].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
179500179577
break;
179501179578
case 9: /* cnearset ::= colset COLON nearset */
179502179579
{
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 */
179580
+ sqlite3Fts5ParseSetColset(pParse, fts5yymsp[0].minor.fts5yy46, fts5yymsp[-2].minor.fts5yy11);
179581
+ fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_STRING, 0, 0, fts5yymsp[0].minor.fts5yy46);
179582
+}
179583
+ fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
179584
+ break;
179585
+ case 10: /* colset ::= MINUS LCP colsetlist RCP */
179586
+{
179587
+ fts5yymsp[-3].minor.fts5yy11 = sqlite3Fts5ParseColsetInvert(pParse, fts5yymsp[-1].minor.fts5yy11);
179588
+}
179589
+ break;
179590
+ case 11: /* colset ::= LCP colsetlist RCP */
179591
+{ fts5yymsp[-2].minor.fts5yy11 = fts5yymsp[-1].minor.fts5yy11; }
179592
+ break;
179593
+ case 12: /* colset ::= STRING */
179594
+{
179595
+ fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
179596
+}
179597
+ fts5yymsp[0].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
179598
+ break;
179599
+ case 13: /* colset ::= MINUS STRING */
179600
+{
179601
+ fts5yymsp[-1].minor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
179602
+ fts5yymsp[-1].minor.fts5yy11 = sqlite3Fts5ParseColsetInvert(pParse, fts5yymsp[-1].minor.fts5yy11);
179603
+}
179604
+ break;
179605
+ case 14: /* colsetlist ::= colsetlist STRING */
179606
+{
179607
+ fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseColset(pParse, fts5yymsp[-1].minor.fts5yy11, &fts5yymsp[0].minor.fts5yy0); }
179608
+ fts5yymsp[-1].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
179609
+ break;
179610
+ case 15: /* colsetlist ::= STRING */
179611
+{
179612
+ fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
179613
+}
179614
+ fts5yymsp[0].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
179615
+ break;
179616
+ case 16: /* nearset ::= phrase */
179617
+{ fts5yylhsminor.fts5yy46 = sqlite3Fts5ParseNearset(pParse, 0, fts5yymsp[0].minor.fts5yy53); }
179618
+ fts5yymsp[0].minor.fts5yy46 = fts5yylhsminor.fts5yy46;
179619
+ break;
179620
+ case 17: /* nearset ::= STRING LP nearphrases neardist_opt RP */
179533179621
{
179534179622
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 ::= */
179623
+ sqlite3Fts5ParseSetDistance(pParse, fts5yymsp[-2].minor.fts5yy46, &fts5yymsp[-1].minor.fts5yy0);
179624
+ fts5yylhsminor.fts5yy46 = fts5yymsp[-2].minor.fts5yy46;
179625
+}
179626
+ fts5yymsp[-4].minor.fts5yy46 = fts5yylhsminor.fts5yy46;
179627
+ break;
179628
+ case 18: /* nearphrases ::= phrase */
179629
+{
179630
+ fts5yylhsminor.fts5yy46 = sqlite3Fts5ParseNearset(pParse, 0, fts5yymsp[0].minor.fts5yy53);
179631
+}
179632
+ fts5yymsp[0].minor.fts5yy46 = fts5yylhsminor.fts5yy46;
179633
+ break;
179634
+ case 19: /* nearphrases ::= nearphrases phrase */
179635
+{
179636
+ fts5yylhsminor.fts5yy46 = sqlite3Fts5ParseNearset(pParse, fts5yymsp[-1].minor.fts5yy46, fts5yymsp[0].minor.fts5yy53);
179637
+}
179638
+ fts5yymsp[-1].minor.fts5yy46 = fts5yylhsminor.fts5yy46;
179639
+ break;
179640
+ case 20: /* neardist_opt ::= */
179553179641
{ fts5yymsp[1].minor.fts5yy0.p = 0; fts5yymsp[1].minor.fts5yy0.n = 0; }
179554179642
break;
179555
- case 19: /* neardist_opt ::= COMMA STRING */
179643
+ case 21: /* neardist_opt ::= COMMA STRING */
179556179644
{ fts5yymsp[-1].minor.fts5yy0 = fts5yymsp[0].minor.fts5yy0; }
179557179645
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; }
179646
+ case 22: /* phrase ::= phrase PLUS STRING star_opt */
179647
+{
179648
+ fts5yylhsminor.fts5yy53 = sqlite3Fts5ParseTerm(pParse, fts5yymsp[-3].minor.fts5yy53, &fts5yymsp[-1].minor.fts5yy0, fts5yymsp[0].minor.fts5yy4);
179649
+}
179650
+ fts5yymsp[-3].minor.fts5yy53 = fts5yylhsminor.fts5yy53;
179651
+ break;
179652
+ case 23: /* phrase ::= STRING star_opt */
179653
+{
179654
+ fts5yylhsminor.fts5yy53 = sqlite3Fts5ParseTerm(pParse, 0, &fts5yymsp[-1].minor.fts5yy0, fts5yymsp[0].minor.fts5yy4);
179655
+}
179656
+ fts5yymsp[-1].minor.fts5yy53 = fts5yylhsminor.fts5yy53;
179657
+ break;
179658
+ case 24: /* star_opt ::= STAR */
179659
+{ fts5yymsp[0].minor.fts5yy4 = 1; }
179660
+ break;
179661
+ case 25: /* star_opt ::= */
179662
+{ fts5yymsp[1].minor.fts5yy4 = 0; }
179575179663
break;
179576179664
default:
179577179665
break;
179578179666
/********** End reduce actions ************************************************/
179579179667
};
@@ -180027,11 +180115,11 @@
180027180115
}
180028180116
180029180117
if( p->iRangeEnd>0 && iPos==p->iRangeEnd ){
180030180118
fts5HighlightAppend(&rc, p, &p->zIn[p->iOff], iEndOff - p->iOff);
180031180119
p->iOff = iEndOff;
180032
- if( iPos<p->iter.iEnd ){
180120
+ if( iPos>=p->iter.iStart && iPos<p->iter.iEnd ){
180033180121
fts5HighlightAppend(&rc, p, p->zClose, -1);
180034180122
}
180035180123
}
180036180124
180037180125
return rc;
@@ -180188,10 +180276,17 @@
180188180276
ctx.iRangeEnd = iBestStart + nToken - 1;
180189180277
180190180278
if( iBestStart>0 ){
180191180279
fts5HighlightAppend(&rc, &ctx, zEllips, -1);
180192180280
}
180281
+
180282
+ /* Advance iterator ctx.iter so that it points to the first coalesced
180283
+ ** phrase instance at or following position iBestStart. */
180284
+ while( ctx.iter.iStart>=0 && ctx.iter.iStart<iBestStart && rc==SQLITE_OK ){
180285
+ rc = fts5CInstIterNext(&ctx.iter);
180286
+ }
180287
+
180193180288
if( rc==SQLITE_OK ){
180194180289
rc = pApi->xTokenize(pFts, ctx.zIn, ctx.nIn, (void*)&ctx,fts5HighlightCb);
180195180290
}
180196180291
if( ctx.iRangeEnd>=(nColSize-1) ){
180197180292
fts5HighlightAppend(&rc, &ctx, &ctx.zIn[ctx.iOff], ctx.nIn - ctx.iOff);
@@ -181923,10 +182018,11 @@
181923182018
case '}': tok = FTS5_RCP; break;
181924182019
case ':': tok = FTS5_COLON; break;
181925182020
case ',': tok = FTS5_COMMA; break;
181926182021
case '+': tok = FTS5_PLUS; break;
181927182022
case '*': tok = FTS5_STAR; break;
182023
+ case '-': tok = FTS5_MINUS; break;
181928182024
case '\0': tok = FTS5_EOF; break;
181929182025
181930182026
case '"': {
181931182027
const char *z2;
181932182028
tok = FTS5_STRING;
@@ -183414,11 +183510,11 @@
183414183510
sizeof(Fts5ExprNearset) + sizeof(Fts5ExprPhrase*));
183415183511
}
183416183512
if( rc==SQLITE_OK ){
183417183513
Fts5Colset *pColsetOrig = pOrig->pNode->pNear->pColset;
183418183514
if( pColsetOrig ){
183419
- int nByte = sizeof(Fts5Colset) + pColsetOrig->nCol * sizeof(int);
183515
+ int nByte = sizeof(Fts5Colset) + (pColsetOrig->nCol-1) * sizeof(int);
183420183516
Fts5Colset *pColset = (Fts5Colset*)sqlite3Fts5MallocZero(&rc, nByte);
183421183517
if( pColset ){
183422183518
memcpy(pColset, pColsetOrig, nByte);
183423183519
}
183424183520
pNew->pRoot->pNear->pColset = pColset;
@@ -183548,10 +183644,38 @@
183548183644
#endif
183549183645
}
183550183646
183551183647
return pNew;
183552183648
}
183649
+
183650
+/*
183651
+** Allocate and return an Fts5Colset object specifying the inverse of
183652
+** the colset passed as the second argument. Free the colset passed
183653
+** as the second argument before returning.
183654
+*/
183655
+static Fts5Colset *sqlite3Fts5ParseColsetInvert(Fts5Parse *pParse, Fts5Colset *p){
183656
+ Fts5Colset *pRet;
183657
+ int nCol = pParse->pConfig->nCol;
183658
+
183659
+ pRet = (Fts5Colset*)sqlite3Fts5MallocZero(&pParse->rc,
183660
+ sizeof(Fts5Colset) + sizeof(int)*nCol
183661
+ );
183662
+ if( pRet ){
183663
+ int i;
183664
+ int iOld = 0;
183665
+ for(i=0; i<nCol; i++){
183666
+ if( iOld>=p->nCol || p->aiCol[iOld]!=i ){
183667
+ pRet->aiCol[pRet->nCol++] = i;
183668
+ }else{
183669
+ iOld++;
183670
+ }
183671
+ }
183672
+ }
183673
+
183674
+ sqlite3_free(p);
183675
+ return pRet;
183676
+}
183553183677
183554183678
static Fts5Colset *sqlite3Fts5ParseColset(
183555183679
Fts5Parse *pParse, /* Store SQLITE_NOMEM here if required */
183556183680
Fts5Colset *pColset, /* Existing colset object */
183557183681
Fts5Token *p
@@ -185644,18 +185768,29 @@
185644185768
185645185769
assert( (pRet==0)==(p->rc!=SQLITE_OK) );
185646185770
return pRet;
185647185771
}
185648185772
185649
-
185650185773
/*
185651185774
** Release a reference to data record returned by an earlier call to
185652185775
** fts5DataRead().
185653185776
*/
185654185777
static void fts5DataRelease(Fts5Data *pData){
185655185778
sqlite3_free(pData);
185656185779
}
185780
+
185781
+static Fts5Data *fts5LeafRead(Fts5Index *p, i64 iRowid){
185782
+ Fts5Data *pRet = fts5DataRead(p, iRowid);
185783
+ if( pRet ){
185784
+ if( pRet->szLeaf>pRet->nn ){
185785
+ p->rc = FTS5_CORRUPT;
185786
+ fts5DataRelease(pRet);
185787
+ pRet = 0;
185788
+ }
185789
+ }
185790
+ return pRet;
185791
+}
185657185792
185658185793
static int fts5IndexPrepareStmt(
185659185794
Fts5Index *p,
185660185795
sqlite3_stmt **ppStmt,
185661185796
char *zSql
@@ -186461,11 +186596,11 @@
186461186596
pIter->iLeafPgno++;
186462186597
if( pIter->pNextLeaf ){
186463186598
pIter->pLeaf = pIter->pNextLeaf;
186464186599
pIter->pNextLeaf = 0;
186465186600
}else if( pIter->iLeafPgno<=pSeg->pgnoLast ){
186466
- pIter->pLeaf = fts5DataRead(p,
186601
+ pIter->pLeaf = fts5LeafRead(p,
186467186602
FTS5_SEGMENT_ROWID(pSeg->iSegid, pIter->iLeafPgno)
186468186603
);
186469186604
}else{
186470186605
pIter->pLeaf = 0;
186471186606
}
@@ -186964,13 +187099,12 @@
186964187099
pIter->iLeafOffset = iOff;
186965187100
186966187101
if( pLeaf->nn>pLeaf->szLeaf ){
186967187102
pIter->iPgidxOff = pLeaf->szLeaf + fts5GetVarint32(
186968187103
&pLeaf->p[pLeaf->szLeaf], pIter->iEndofDoclist
186969
- );
187104
+ );
186970187105
}
186971
-
186972187106
}
186973187107
else if( pLeaf->nn>pLeaf->szLeaf ){
186974187108
pIter->iPgidxOff = pLeaf->szLeaf + fts5GetVarint32(
186975187109
&pLeaf->p[pLeaf->szLeaf], iOff
186976187110
);
@@ -187210,10 +187344,15 @@
187210187344
}
187211187345
187212187346
iPgidx += fts5GetVarint32(&a[iPgidx], nKeep);
187213187347
iTermOff += nKeep;
187214187348
iOff = iTermOff;
187349
+
187350
+ if( iOff>=n ){
187351
+ p->rc = FTS5_CORRUPT;
187352
+ return;
187353
+ }
187215187354
187216187355
/* Read the nKeep field of the next term. */
187217187356
fts5FastGetVarint32(a, iOff, nKeep);
187218187357
}
187219187358
@@ -188136,10 +188275,19 @@
188136188275
fts5BufferZero(&pIter->poslist);
188137188276
fts5SegiterPoslist(pIter->pIndex, pSeg, 0, &pIter->poslist);
188138188277
pIter->base.pData = pIter->poslist.p;
188139188278
}
188140188279
}
188280
+
188281
+/*
188282
+** xSetOutputs callback used when the Fts5Colset object has nCol==0 (match
188283
+** against no columns at all).
188284
+*/
188285
+static void fts5IterSetOutputs_ZeroColset(Fts5Iter *pIter, Fts5SegIter *pSeg){
188286
+ UNUSED_PARAM(pSeg);
188287
+ pIter->base.nData = 0;
188288
+}
188141188289
188142188290
/*
188143188291
** xSetOutputs callback used by detail=col when there is a column filter
188144188292
** and there are 100 or more columns. Also called as a fallback from
188145188293
** fts5IterSetOutputs_Col100 if the column-list spans more than one page.
@@ -188241,10 +188389,14 @@
188241188389
}
188242188390
188243188391
else if( pIter->pColset==0 ){
188244188392
pIter->xSetOutputs = fts5IterSetOutputs_Nocolset;
188245188393
}
188394
+
188395
+ else if( pIter->pColset->nCol==0 ){
188396
+ pIter->xSetOutputs = fts5IterSetOutputs_ZeroColset;
188397
+ }
188246188398
188247188399
else if( pConfig->eDetail==FTS5_DETAIL_FULL ){
188248188400
pIter->xSetOutputs = fts5IterSetOutputs_Full;
188249188401
}
188250188402
@@ -194018,11 +194170,11 @@
194018194170
int nArg, /* Number of args */
194019194171
sqlite3_value **apUnused /* Function arguments */
194020194172
){
194021194173
assert( nArg==0 );
194022194174
UNUSED_PARAM2(nArg, apUnused);
194023
- sqlite3_result_text(pCtx, "fts5: 2016-08-11 18:53:32 a12d8059770df4bca59e321c266410344242bf7b", -1, SQLITE_TRANSIENT);
194175
+ sqlite3_result_text(pCtx, "fts5: 2016-08-18 15:21:16 4768a1066cb9c7627064d7efec44188d6755cb03", -1, SQLITE_TRANSIENT);
194024194176
}
194025194177
194026194178
static int fts5Init(sqlite3 *db){
194027194179
static const sqlite3_module fts5Mod = {
194028194180
/* iVersion */ 2,
194029194181
--- 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 };
@@ -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;
@@ -83943,11 +83976,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 +84312,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 +87864,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 +88206,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 +94280,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 +94478,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 +94888,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 +94910,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 +95672,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 +96062,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 +96522,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 +96665,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 +96730,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 +96843,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 +97001,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 +97259,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 +97734,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 +97812,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 +97840,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 +97909,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 +98130,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
@@ -98268,11 +98300,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 +98319,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 +99412,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,
@@ -99401,11 +99433,11 @@
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 +99747,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 +99823,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 +99876,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 +99890,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 +99944,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 +100185,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 +100437,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 +100467,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 +100782,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 +100916,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 +100934,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 +101479,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 +101726,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 +102440,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 +102627,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 +105959,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 */
@@ -107014,11 +107046,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 +111004,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 +111857,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 +112149,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 +112588,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
@@ -112734,11 +112766,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 +112945,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 +113220,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 +114976,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 +117932,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 +119644,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 +119739,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 +119928,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 +119974,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 +119990,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 +120093,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 +120783,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 }
@@ -121506,11 +121540,11 @@
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
@@ -122055,11 +122089,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 +122153,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 +122263,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 +122427,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 +122551,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 +125664,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 +126649,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 +131903,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 +132250,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 +132266,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 +132285,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 +133239,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);
@@ -136006,18 +136042,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 +136082,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 +137321,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 +139469,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 +140432,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 +164798,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 +167305,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 +168451,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 +168473,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 +168582,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 +168617,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 +168695,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 +170307,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 +170361,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 +178598,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 +178656,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 +178776,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 +178836,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 +178876,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 +179026,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 +179048,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 +179173,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 +179276,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 +179443,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 +179533,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 +180115,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 +180276,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 +182018,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 +183510,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 +183644,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 +185768,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 +186596,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 +187099,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 +187344,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 +188275,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 +188389,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 +194170,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-18 22:44:22 d6e3d5796c9991ca0af45ed92ce36f55efc02348"
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 };
@@ -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;
@@ -83943,11 +83976,11 @@
83976 zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql);
83977 if( zTrace ){
83978 int i;
83979 for(i=0; i<db->nDb; i++){
83980 if( DbMaskTest(p->btreeMask, i)==0 ) continue;
83981 sqlite3_file_control(db, db->aDb[i].zDbSName, SQLITE_FCNTL_TRACE, zTrace);
83982 }
83983 }
83984 #endif /* SQLITE_USE_FCNTL_TRACE */
83985 #ifdef SQLITE_DEBUG
83986 if( (db->flags & SQLITE_SqlTrace)!=0
@@ -84279,11 +84312,11 @@
84312 rc = SQLITE_ERROR;
84313 sqlite3BtreeLeaveAll(db);
84314 goto blob_open_out;
84315 }
84316 pBlob->pTab = pTab;
84317 pBlob->zDb = db->aDb[sqlite3SchemaToIndex(db, pTab->pSchema)].zDbSName;
84318
84319 /* Now search pTab for the exact column. */
84320 for(iCol=0; iCol<pTab->nCol; iCol++) {
84321 if( sqlite3StrICmp(pTab->aCol[iCol].zName, zColumn)==0 ){
84322 break;
@@ -87831,21 +87864,19 @@
87864 static SQLITE_NOINLINE int walkExpr(Walker *pWalker, Expr *pExpr){
87865 int rc;
87866 testcase( ExprHasProperty(pExpr, EP_TokenOnly) );
87867 testcase( ExprHasProperty(pExpr, EP_Reduced) );
87868 rc = pWalker->xExprCallback(pWalker, pExpr);
87869 if( rc || ExprHasProperty(pExpr,EP_TokenOnly) ) return rc & WRC_Abort;
87870 if( pExpr->pLeft && walkExpr(pWalker, pExpr->pLeft) ) return WRC_Abort;
87871 if( pExpr->pRight && walkExpr(pWalker, pExpr->pRight) ) return WRC_Abort;
87872 if( ExprHasProperty(pExpr, EP_xIsSelect) ){
87873 if( sqlite3WalkSelect(pWalker, pExpr->x.pSelect) ) return WRC_Abort;
87874 }else{
87875 if( sqlite3WalkExprList(pWalker, pExpr->x.pList) ) return WRC_Abort;
87876 }
87877 return WRC_Continue;
 
 
87878 }
87879 SQLITE_PRIVATE int sqlite3WalkExpr(Walker *pWalker, Expr *pExpr){
87880 return pExpr ? walkExpr(pWalker,pExpr) : WRC_Continue;
87881 }
87882
@@ -88175,12 +88206,12 @@
88206 ** legacy and because it does not hurt anything to just ignore the
88207 ** database name. */
88208 zDb = 0;
88209 }else{
88210 for(i=0; i<db->nDb; i++){
88211 assert( db->aDb[i].zDbSName );
88212 if( sqlite3StrICmp(db->aDb[i].zDbSName,zDb)==0 ){
88213 pSchema = db->aDb[i].pSchema;
88214 break;
88215 }
88216 }
88217 }
@@ -94249,11 +94280,11 @@
94280 assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );
94281
94282 pTab = sqlite3LocateTableItem(pParse, 0, &pSrc->a[0]);
94283 if( !pTab ) goto exit_rename_table;
94284 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
94285 zDb = db->aDb[iDb].zDbSName;
94286 db->flags |= SQLITE_PreferBuiltin;
94287
94288 /* Get a NULL terminated version of the new table name. */
94289 zName = sqlite3NameFromToken(db, pName);
94290 if( !zName ) goto exit_rename_table;
@@ -94447,11 +94478,11 @@
94478 pNew = pParse->pNewTable;
94479 assert( pNew );
94480
94481 assert( sqlite3BtreeHoldsAllMutexes(db) );
94482 iDb = sqlite3SchemaToIndex(db, pNew->pSchema);
94483 zDb = db->aDb[iDb].zDbSName;
94484 zTab = &pNew->zName[16]; /* Skip the "sqlite_altertab_" prefix on the name */
94485 pCol = &pNew->aCol[pNew->nCol-1];
94486 pDflt = pCol->pDflt;
94487 pTab = sqlite3FindTable(db, zTab, zDb);
94488 assert( pTab );
@@ -94857,18 +94888,18 @@
94888 ** if they do already exist.
94889 */
94890 for(i=0; i<ArraySize(aTable); i++){
94891 const char *zTab = aTable[i].zName;
94892 Table *pStat;
94893 if( (pStat = sqlite3FindTable(db, zTab, pDb->zDbSName))==0 ){
94894 if( aTable[i].zCols ){
94895 /* The sqlite_statN table does not exist. Create it. Note that a
94896 ** side-effect of the CREATE TABLE statement is to leave the rootpage
94897 ** of the new table in register pParse->regRoot. This is important
94898 ** because the OpenWrite opcode below will be needing it. */
94899 sqlite3NestedParse(pParse,
94900 "CREATE TABLE %Q.%s(%s)", pDb->zDbSName, zTab, aTable[i].zCols
94901 );
94902 aRoot[i] = pParse->regRoot;
94903 aCreateTbl[i] = OPFLAG_P2ISREG;
94904 }
94905 }else{
@@ -94879,11 +94910,11 @@
94910 aCreateTbl[i] = 0;
94911 sqlite3TableLock(pParse, iDb, aRoot[i], 1, zTab);
94912 if( zWhere ){
94913 sqlite3NestedParse(pParse,
94914 "DELETE FROM %Q.%s WHERE %s=%Q",
94915 pDb->zDbSName, zTab, zWhereType, zWhere
94916 );
94917 }else{
94918 /* The sqlite_stat[134] table already exists. Delete all rows. */
94919 sqlite3VdbeAddOp2(v, OP_Clear, aRoot[i], iDb);
94920 }
@@ -95641,11 +95672,11 @@
95672 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
95673 assert( iDb>=0 );
95674 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
95675 #ifndef SQLITE_OMIT_AUTHORIZATION
95676 if( sqlite3AuthCheck(pParse, SQLITE_ANALYZE, pTab->zName, 0,
95677 db->aDb[iDb].zDbSName ) ){
95678 return;
95679 }
95680 #endif
95681
95682 /* Establish a read-lock on the table at the shared-cache level.
@@ -96031,11 +96062,11 @@
96062 }
96063 }else{
96064 /* Form 3: Analyze the fully qualified table name */
96065 iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pTableName);
96066 if( iDb>=0 ){
96067 zDb = db->aDb[iDb].zDbSName;
96068 z = sqlite3NameFromToken(db, pTableName);
96069 if( z ){
96070 if( (pIdx = sqlite3FindIndex(db, z, zDb))!=0 ){
96071 analyzeTable(pParse, pIdx->pTable, pIdx);
96072 }else if( (pTab = sqlite3LocateTable(pParse, 0, z, zDb))!=0 ){
@@ -96491,11 +96522,11 @@
96522 #endif
96523 }
96524
96525 /* Load new statistics out of the sqlite_stat1 table */
96526 sInfo.db = db;
96527 sInfo.zDatabase = db->aDb[iDb].zDbSName;
96528 if( sqlite3FindTable(db, "sqlite_stat1", sInfo.zDatabase)!=0 ){
96529 zSql = sqlite3MPrintf(db,
96530 "SELECT tbl,idx,stat FROM %Q.sqlite_stat1", sInfo.zDatabase);
96531 if( zSql==0 ){
96532 rc = SQLITE_NOMEM_BKPT;
@@ -96634,11 +96665,11 @@
96665 if( !db->autoCommit ){
96666 zErrDyn = sqlite3MPrintf(db, "cannot ATTACH database within transaction");
96667 goto attach_error;
96668 }
96669 for(i=0; i<db->nDb; i++){
96670 char *z = db->aDb[i].zDbSName;
96671 assert( z && zName );
96672 if( sqlite3StrICmp(z, zName)==0 ){
96673 zErrDyn = sqlite3MPrintf(db, "database %s is already in use", zName);
96674 goto attach_error;
96675 }
@@ -96699,12 +96730,12 @@
96730 PAGER_SYNCHRONOUS_FULL | (db->flags & PAGER_FLAGS_MASK));
96731 #endif
96732 sqlite3BtreeLeave(aNew->pBt);
96733 }
96734 aNew->safety_level = SQLITE_DEFAULT_SYNCHRONOUS+1;
96735 aNew->zDbSName = sqlite3DbStrDup(db, zName);
96736 if( rc==SQLITE_OK && aNew->zDbSName==0 ){
96737 rc = SQLITE_NOMEM_BKPT;
96738 }
96739
96740
96741 #ifdef SQLITE_HAS_CODEC
@@ -96812,11 +96843,11 @@
96843
96844 if( zName==0 ) zName = "";
96845 for(i=0; i<db->nDb; i++){
96846 pDb = &db->aDb[i];
96847 if( pDb->pBt==0 ) continue;
96848 if( sqlite3StrICmp(pDb->zDbSName, zName)==0 ) break;
96849 }
96850
96851 if( i>=db->nDb ){
96852 sqlite3_snprintf(sizeof(zErr),zErr, "no such database: %s", zName);
96853 goto detach_error;
@@ -96970,11 +97001,11 @@
97001 sqlite3 *db;
97002
97003 db = pParse->db;
97004 assert( db->nDb>iDb );
97005 pFix->pParse = pParse;
97006 pFix->zDb = db->aDb[iDb].zDbSName;
97007 pFix->pSchema = db->aDb[iDb].pSchema;
97008 pFix->zType = zType;
97009 pFix->pName = pName;
97010 pFix->bVarOnly = (iDb==1);
97011 }
@@ -97228,13 +97259,13 @@
97259 Parse *pParse, /* The parser context */
97260 const char *zTab, /* Table name */
97261 const char *zCol, /* Column name */
97262 int iDb /* Index of containing database. */
97263 ){
97264 sqlite3 *db = pParse->db; /* Database handle */
97265 char *zDb = db->aDb[iDb].zDbSName; /* Schema name of attached database */
97266 int rc; /* Auth callback return code */
97267
97268 if( db->init.busy ) return SQLITE_OK;
97269 rc = db->xAuth(db->pAuthArg, SQLITE_READ, zTab,zCol,zDb,pParse->zAuthContext
97270 #ifdef SQLITE_USER_AUTHENTICATION
97271 ,db->auth.zAuthUser
@@ -97703,14 +97734,15 @@
97734 return 0;
97735 }
97736 #endif
97737 for(i=OMIT_TEMPDB; i<db->nDb; i++){
97738 int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */
97739 if( zDatabase==0 || sqlite3StrICmp(zDatabase, db->aDb[j].zDbSName)==0 ){
97740 assert( sqlite3SchemaMutexHeld(db, j, 0) );
97741 p = sqlite3HashFind(&db->aDb[j].pSchema->tblHash, zName);
97742 if( p ) break;
97743 }
97744 }
97745 return p;
97746 }
97747
97748 /*
@@ -97780,11 +97812,11 @@
97812 ){
97813 const char *zDb;
97814 assert( p->pSchema==0 || p->zDatabase==0 );
97815 if( p->pSchema ){
97816 int iDb = sqlite3SchemaToIndex(pParse->db, p->pSchema);
97817 zDb = pParse->db->aDb[iDb].zDbSName;
97818 }else{
97819 zDb = p->zDatabase;
97820 }
97821 return sqlite3LocateTable(pParse, flags, p->zName, zDb);
97822 }
@@ -97808,11 +97840,11 @@
97840 assert( zDb!=0 || sqlite3BtreeHoldsAllMutexes(db) );
97841 for(i=OMIT_TEMPDB; i<db->nDb; i++){
97842 int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */
97843 Schema *pSchema = db->aDb[j].pSchema;
97844 assert( pSchema );
97845 if( zDb && sqlite3StrICmp(zDb, db->aDb[j].zDbSName) ) continue;
97846 assert( sqlite3SchemaMutexHeld(db, j, 0) );
97847 p = sqlite3HashFind(&pSchema->idxHash, zName);
97848 if( p ) break;
97849 }
97850 return p;
@@ -97877,12 +97909,12 @@
97909 SQLITE_PRIVATE void sqlite3CollapseDatabaseArray(sqlite3 *db){
97910 int i, j;
97911 for(i=j=2; i<db->nDb; i++){
97912 struct Db *pDb = &db->aDb[i];
97913 if( pDb->pBt==0 ){
97914 sqlite3DbFree(db, pDb->zDbSName);
97915 pDb->zDbSName = 0;
97916 continue;
97917 }
97918 if( j<i ){
97919 db->aDb[j] = db->aDb[i];
97920 }
@@ -98098,11 +98130,11 @@
98130 SQLITE_PRIVATE int sqlite3FindDbName(sqlite3 *db, const char *zName){
98131 int i = -1; /* Database number */
98132 if( zName ){
98133 Db *pDb;
98134 for(i=(db->nDb-1), pDb=&db->aDb[i]; i>=0; i--, pDb--){
98135 if( 0==sqlite3StrICmp(pDb->zDbSName, zName) ) break;
98136 }
98137 }
98138 return i;
98139 }
98140
@@ -98268,11 +98300,11 @@
98300 SQLITE_CREATE_TABLE,
98301 SQLITE_CREATE_TEMP_TABLE,
98302 SQLITE_CREATE_VIEW,
98303 SQLITE_CREATE_TEMP_VIEW
98304 };
98305 char *zDb = db->aDb[iDb].zDbSName;
98306 if( sqlite3AuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(isTemp), 0, zDb) ){
98307 goto begin_table_error;
98308 }
98309 if( !isVirtual && sqlite3AuthCheck(pParse, (int)aCode[isTemp+2*isView],
98310 zName, 0, zDb) ){
@@ -98287,11 +98319,11 @@
98319 ** to an sqlite3_declare_vtab() call. In that case only the column names
98320 ** and types will be used, so there is no need to test for namespace
98321 ** collisions.
98322 */
98323 if( !IN_DECLARE_VTAB ){
98324 char *zDb = db->aDb[iDb].zDbSName;
98325 if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){
98326 goto begin_table_error;
98327 }
98328 pTable = sqlite3FindTable(db, zName, zDb);
98329 if( pTable ){
@@ -99380,11 +99412,11 @@
99412 */
99413 sqlite3NestedParse(pParse,
99414 "UPDATE %Q.%s "
99415 "SET type='%s', name=%Q, tbl_name=%Q, rootpage=#%d, sql=%Q "
99416 "WHERE rowid=#%d",
99417 db->aDb[iDb].zDbSName, SCHEMA_TABLE(iDb),
99418 zType,
99419 p->zName,
99420 p->zName,
99421 pParse->regRoot,
99422 zStmt,
@@ -99401,11 +99433,11 @@
99433 Db *pDb = &db->aDb[iDb];
99434 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
99435 if( pDb->pSchema->pSeqTab==0 ){
99436 sqlite3NestedParse(pParse,
99437 "CREATE TABLE %Q.sqlite_sequence(name,seq)",
99438 pDb->zDbSName
99439 );
99440 }
99441 }
99442 #endif
99443
@@ -99715,11 +99747,11 @@
99747 ** is in register NNN. See grammar rules associated with the TK_REGISTER
99748 ** token for additional information.
99749 */
99750 sqlite3NestedParse(pParse,
99751 "UPDATE %Q.%s SET rootpage=%d WHERE #%d AND rootpage=#%d",
99752 pParse->db->aDb[iDb].zDbSName, SCHEMA_TABLE(iDb), iTable, r1, r1);
99753 #endif
99754 sqlite3ReleaseTempReg(pParse, r1);
99755 }
99756
99757 /*
@@ -99791,11 +99823,11 @@
99823 int iDb, /* The database number */
99824 const char *zType, /* "idx" or "tbl" */
99825 const char *zName /* Name of index or table */
99826 ){
99827 int i;
99828 const char *zDbName = pParse->db->aDb[iDb].zDbSName;
99829 for(i=1; i<=4; i++){
99830 char zTab[24];
99831 sqlite3_snprintf(sizeof(zTab),zTab,"sqlite_stat%d",i);
99832 if( sqlite3FindTable(pParse->db, zTab, zDbName) ){
99833 sqlite3NestedParse(pParse,
@@ -99844,11 +99876,11 @@
99876 ** move as a result of the drop (can happen in auto-vacuum mode).
99877 */
99878 if( pTab->tabFlags & TF_Autoincrement ){
99879 sqlite3NestedParse(pParse,
99880 "DELETE FROM %Q.sqlite_sequence WHERE name=%Q",
99881 pDb->zDbSName, pTab->zName
99882 );
99883 }
99884 #endif
99885
99886 /* Drop all SQLITE_MASTER table and index entries that refer to the
@@ -99858,11 +99890,11 @@
99890 ** created in the temp database that refers to a table in another
99891 ** database.
99892 */
99893 sqlite3NestedParse(pParse,
99894 "DELETE FROM %Q.%s WHERE tbl_name=%Q and type!='trigger'",
99895 pDb->zDbSName, SCHEMA_TABLE(iDb), pTab->zName);
99896 if( !isView && !IsVirtual(pTab) ){
99897 destroyTable(pParse, pTab);
99898 }
99899
99900 /* Remove the table entry from SQLite's internal schema and modify
@@ -99912,11 +99944,11 @@
99944 }
99945 #ifndef SQLITE_OMIT_AUTHORIZATION
99946 {
99947 int code;
99948 const char *zTab = SCHEMA_TABLE(iDb);
99949 const char *zDb = db->aDb[iDb].zDbSName;
99950 const char *zArg2 = 0;
99951 if( sqlite3AuthCheck(pParse, SQLITE_DELETE, zTab, 0, zDb)){
99952 goto exit_drop_table;
99953 }
99954 if( isView ){
@@ -100153,11 +100185,11 @@
100185 sqlite3 *db = pParse->db; /* The database connection */
100186 int iDb = sqlite3SchemaToIndex(db, pIndex->pSchema);
100187
100188 #ifndef SQLITE_OMIT_AUTHORIZATION
100189 if( sqlite3AuthCheck(pParse, SQLITE_REINDEX, pIndex->zName, 0,
100190 db->aDb[iDb].zDbSName ) ){
100191 return;
100192 }
100193 #endif
100194
100195 /* Require a write-lock on the table to perform this operation */
@@ -100405,11 +100437,11 @@
100437 if( sqlite3FindTable(db, zName, 0)!=0 ){
100438 sqlite3ErrorMsg(pParse, "there is already a table named %s", zName);
100439 goto exit_create_index;
100440 }
100441 }
100442 if( sqlite3FindIndex(db, zName, pDb->zDbSName)!=0 ){
100443 if( !ifNotExist ){
100444 sqlite3ErrorMsg(pParse, "index %s already exists", zName);
100445 }else{
100446 assert( !db->init.busy );
100447 sqlite3CodeVerifySchema(pParse, iDb);
@@ -100435,11 +100467,11 @@
100467
100468 /* Check for authorization to create an index.
100469 */
100470 #ifndef SQLITE_OMIT_AUTHORIZATION
100471 {
100472 const char *zDb = pDb->zDbSName;
100473 if( sqlite3AuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(iDb), 0, zDb) ){
100474 goto exit_create_index;
100475 }
100476 i = SQLITE_CREATE_INDEX;
100477 if( !OMIT_TEMPDB && iDb==1 ) i = SQLITE_CREATE_TEMP_INDEX;
@@ -100750,11 +100782,11 @@
100782
100783 /* Add an entry in sqlite_master for this index
100784 */
100785 sqlite3NestedParse(pParse,
100786 "INSERT INTO %Q.%s VALUES('index',%Q,%Q,#%d,%Q);",
100787 db->aDb[iDb].zDbSName, SCHEMA_TABLE(iDb),
100788 pIndex->zName,
100789 pTab->zName,
100790 iMem,
100791 zStmt
100792 );
@@ -100884,11 +100916,11 @@
100916 iDb = sqlite3SchemaToIndex(db, pIndex->pSchema);
100917 #ifndef SQLITE_OMIT_AUTHORIZATION
100918 {
100919 int code = SQLITE_DROP_INDEX;
100920 Table *pTab = pIndex->pTable;
100921 const char *zDb = db->aDb[iDb].zDbSName;
100922 const char *zTab = SCHEMA_TABLE(iDb);
100923 if( sqlite3AuthCheck(pParse, SQLITE_DELETE, zTab, 0, zDb) ){
100924 goto exit_drop_index;
100925 }
100926 if( !OMIT_TEMPDB && iDb ) code = SQLITE_DROP_TEMP_INDEX;
@@ -100902,11 +100934,11 @@
100934 v = sqlite3GetVdbe(pParse);
100935 if( v ){
100936 sqlite3BeginWriteOperation(pParse, 1, iDb);
100937 sqlite3NestedParse(pParse,
100938 "DELETE FROM %Q.%s WHERE name=%Q AND type='index'",
100939 db->aDb[iDb].zDbSName, SCHEMA_TABLE(iDb), pIndex->zName
100940 );
100941 sqlite3ClearStatTables(pParse, iDb, "idx", pIndex->zName);
100942 sqlite3ChangeCookie(pParse, iDb);
100943 destroyRootPage(pParse, pIndex->tnum, iDb);
100944 sqlite3VdbeAddOp4(v, OP_DropIndex, iDb, 0, 0, pIndex->zName, 0);
@@ -101447,11 +101479,11 @@
101479 SQLITE_PRIVATE void sqlite3CodeVerifyNamedSchema(Parse *pParse, const char *zDb){
101480 sqlite3 *db = pParse->db;
101481 int i;
101482 for(i=0; i<db->nDb; i++){
101483 Db *pDb = &db->aDb[i];
101484 if( pDb->pBt && (!zDb || 0==sqlite3StrICmp(zDb, pDb->zDbSName)) ){
101485 sqlite3CodeVerifySchema(pParse, i);
101486 }
101487 }
101488 }
101489
@@ -101694,11 +101726,11 @@
101726 }
101727 iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pObjName);
101728 if( iDb<0 ) return;
101729 z = sqlite3NameFromToken(db, pObjName);
101730 if( z==0 ) return;
101731 zDb = db->aDb[iDb].zDbSName;
101732 pTab = sqlite3FindTable(db, z, zDb);
101733 if( pTab ){
101734 reindexTable(pParse, pTab, 0);
101735 sqlite3DbFree(db, z);
101736 return;
@@ -102408,11 +102440,11 @@
102440 pWhere = sqlite3ExprDup(db, pWhere, 0);
102441 pFrom = sqlite3SrcListAppend(db, 0, 0, 0);
102442 if( pFrom ){
102443 assert( pFrom->nSrc==1 );
102444 pFrom->a[0].zName = sqlite3DbStrDup(db, pView->zName);
102445 pFrom->a[0].zDatabase = sqlite3DbStrDup(db, db->aDb[iDb].zDbSName);
102446 assert( pFrom->a[0].pOn==0 );
102447 assert( pFrom->a[0].pUsing==0 );
102448 }
102449 pSel = sqlite3SelectNew(pParse, 0, pFrom, pWhere, 0, 0, 0,
102450 SF_IncludeHidden, 0, 0);
@@ -102595,11 +102627,11 @@
102627 if( sqlite3IsReadOnly(pParse, pTab, (pTrigger?1:0)) ){
102628 goto delete_from_cleanup;
102629 }
102630 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
102631 assert( iDb<db->nDb );
102632 zDb = db->aDb[iDb].zDbSName;
102633 rcauth = sqlite3AuthCheck(pParse, SQLITE_DELETE, pTab->zName, 0, zDb);
102634 assert( rcauth==SQLITE_OK || rcauth==SQLITE_DENY || rcauth==SQLITE_IGNORE );
102635 if( rcauth==SQLITE_DENY ){
102636 goto delete_from_cleanup;
102637 }
@@ -105927,11 +105959,11 @@
105959
105960 /* If foreign-keys are disabled, this function is a no-op. */
105961 if( (db->flags&SQLITE_ForeignKeys)==0 ) return;
105962
105963 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
105964 zDb = db->aDb[iDb].zDbSName;
105965
105966 /* Loop through all the foreign key constraints for which pTab is the
105967 ** child table (the table that the foreign key definition is part of). */
105968 for(pFKey=pTab->pFKey; pFKey; pFKey=pFKey->pNextFrom){
105969 Table *pTo; /* Parent table of foreign key pFKey */
@@ -107014,11 +107046,11 @@
107046 goto insert_cleanup;
107047 }
107048 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
107049 assert( iDb<db->nDb );
107050 pDb = &db->aDb[iDb];
107051 zDb = pDb->zDbSName;
107052 if( sqlite3AuthCheck(pParse, SQLITE_INSERT, pTab->zName, 0, zDb) ){
107053 goto insert_cleanup;
107054 }
107055 withoutRowid = !HasRowid(pTab);
107056
@@ -110972,11 +111004,11 @@
111004 }else{
111005 zRight = sqlite3NameFromToken(db, pValue);
111006 }
111007
111008 assert( pId2 );
111009 zDb = pId2->n>0 ? pDb->zDbSName : 0;
111010 if( sqlite3AuthCheck(pParse, SQLITE_PRAGMA, zLeft, zRight, zDb) ){
111011 goto pragma_out;
111012 }
111013
111014 /* Send an SQLITE_FCNTL_PRAGMA file-control to the underlying VFS
@@ -111825,14 +111857,14 @@
111857 int i;
111858 pParse->nMem = 3;
111859 setAllColumnNames(v, 3, azCol); assert( 3==ArraySize(azCol) );
111860 for(i=0; i<db->nDb; i++){
111861 if( db->aDb[i].pBt==0 ) continue;
111862 assert( db->aDb[i].zDbSName!=0 );
111863 sqlite3VdbeMultiLoad(v, 1, "iss",
111864 i,
111865 db->aDb[i].zDbSName,
111866 sqlite3BtreeGetFilename(db->aDb[i].pBt));
111867 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3);
111868 }
111869 }
111870 break;
@@ -112117,11 +112149,11 @@
112149 /* Do the b-tree integrity checks */
112150 sqlite3VdbeAddOp4(v, OP_IntegrityCk, 2, cnt, 1, (char*)aRoot,P4_INTARRAY);
112151 sqlite3VdbeChangeP5(v, (u8)i);
112152 addr = sqlite3VdbeAddOp1(v, OP_IsNull, 2); VdbeCoverage(v);
112153 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0,
112154 sqlite3MPrintf(db, "*** in database %s ***\n", db->aDb[i].zDbSName),
112155 P4_DYNAMIC);
112156 sqlite3VdbeAddOp3(v, OP_Move, 2, 4, 1);
112157 sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 2);
112158 sqlite3VdbeAddOp2(v, OP_ResultRow, 2, 1);
112159 sqlite3VdbeJumpHere(v, addr);
@@ -112556,19 +112588,19 @@
112588 pParse->nMem = 2;
112589 for(i=0; i<db->nDb; i++){
112590 Btree *pBt;
112591 const char *zState = "unknown";
112592 int j;
112593 if( db->aDb[i].zDbSName==0 ) continue;
112594 pBt = db->aDb[i].pBt;
112595 if( pBt==0 || sqlite3BtreePager(pBt)==0 ){
112596 zState = "closed";
112597 }else if( sqlite3_file_control(db, i ? db->aDb[i].zDbSName : 0,
112598 SQLITE_FCNTL_LOCKSTATE, &j)==SQLITE_OK ){
112599 zState = azLockName[j];
112600 }
112601 sqlite3VdbeMultiLoad(v, 1, "ss", db->aDb[i].zDbSName, zState);
112602 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 2);
112603 }
112604 break;
112605 }
112606 #endif
@@ -112734,11 +112766,11 @@
112766 ** constraint for a CREATE TABLE. The index should have already
112767 ** been created when we processed the CREATE TABLE. All we have
112768 ** to do here is record the root page number for that index.
112769 */
112770 Index *pIndex;
112771 pIndex = sqlite3FindIndex(db, argv[0], db->aDb[iDb].zDbSName);
112772 if( pIndex==0 ){
112773 /* This can occur if there exists an index on a TEMP table which
112774 ** has the same name as another index on a permanent index. Since
112775 ** the permanent table is hidden by the TEMP table, we can also
112776 ** safely ignore the index on the permanent table.
@@ -112913,11 +112945,11 @@
112945 assert( db->init.busy );
112946 {
112947 char *zSql;
112948 zSql = sqlite3MPrintf(db,
112949 "SELECT name, rootpage, sql FROM \"%w\".%s ORDER BY rowid",
112950 db->aDb[iDb].zDbSName, zMasterName);
112951 #ifndef SQLITE_OMIT_AUTHORIZATION
112952 {
112953 sqlite3_xauth xAuth;
112954 xAuth = db->xAuth;
112955 db->xAuth = 0;
@@ -113188,11 +113220,11 @@
113220 Btree *pBt = db->aDb[i].pBt;
113221 if( pBt ){
113222 assert( sqlite3BtreeHoldsMutex(pBt) );
113223 rc = sqlite3BtreeSchemaLocked(pBt);
113224 if( rc ){
113225 const char *zDb = db->aDb[i].zDbSName;
113226 sqlite3ErrorWithMsg(db, rc, "database schema is locked: %s", zDb);
113227 testcase( db->flags & SQLITE_ReadUncommitted );
113228 goto end_prepare;
113229 }
113230 }
@@ -114944,11 +114976,11 @@
114976 estWidth = pTab->aCol[iCol].szEst;
114977 }
114978 zOrigTab = pTab->zName;
114979 if( pNC->pParse ){
114980 int iDb = sqlite3SchemaToIndex(pNC->pParse->db, pTab->pSchema);
114981 zOrigDb = pNC->pParse->db->aDb[iDb].zDbSName;
114982 }
114983 #else
114984 if( iCol<0 ){
114985 zType = "INTEGER";
114986 }else{
@@ -117900,11 +117932,11 @@
117932 pSub = 0;
117933 if( zTName && sqlite3StrICmp(zTName, zTabName)!=0 ){
117934 continue;
117935 }
117936 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
117937 zSchemaName = iDb>=0 ? db->aDb[iDb].zDbSName : "*";
117938 }
117939 for(j=0; j<pTab->nCol; j++){
117940 char *zName = pTab->aCol[j].zName;
117941 char *zColname; /* The computed column name */
117942 char *zToFree; /* Malloced string that needs to be freed */
@@ -119612,12 +119644,12 @@
119644 iTabDb = sqlite3SchemaToIndex(db, pTab->pSchema);
119645
119646 #ifndef SQLITE_OMIT_AUTHORIZATION
119647 {
119648 int code = SQLITE_CREATE_TRIGGER;
119649 const char *zDb = db->aDb[iTabDb].zDbSName;
119650 const char *zDbTrig = isTemp ? db->aDb[1].zDbSName : zDb;
119651 if( iTabDb==1 || isTemp ) code = SQLITE_CREATE_TEMP_TRIGGER;
119652 if( sqlite3AuthCheck(pParse, code, zName, pTab->zName, zDbTrig) ){
119653 goto trigger_cleanup;
119654 }
119655 if( sqlite3AuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(iTabDb),0,zDb)){
@@ -119707,11 +119739,11 @@
119739 if( v==0 ) goto triggerfinish_cleanup;
119740 sqlite3BeginWriteOperation(pParse, 0, iDb);
119741 z = sqlite3DbStrNDup(db, (char*)pAll->z, pAll->n);
119742 sqlite3NestedParse(pParse,
119743 "INSERT INTO %Q.%s VALUES('trigger',%Q,%Q,0,'CREATE TRIGGER %q')",
119744 db->aDb[iDb].zDbSName, SCHEMA_TABLE(iDb), zName,
119745 pTrig->table, z);
119746 sqlite3DbFree(db, z);
119747 sqlite3ChangeCookie(pParse, iDb);
119748 sqlite3VdbeAddParseSchemaOp(v, iDb,
119749 sqlite3MPrintf(db, "type='trigger' AND name='%q'", zName));
@@ -119896,11 +119928,11 @@
119928 zDb = pName->a[0].zDatabase;
119929 zName = pName->a[0].zName;
119930 assert( zDb!=0 || sqlite3BtreeHoldsAllMutexes(db) );
119931 for(i=OMIT_TEMPDB; i<db->nDb; i++){
119932 int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */
119933 if( zDb && sqlite3StrICmp(db->aDb[j].zDbSName, zDb) ) continue;
119934 assert( sqlite3SchemaMutexHeld(db, j, 0) );
119935 pTrigger = sqlite3HashFind(&(db->aDb[j].pSchema->trigHash), zName);
119936 if( pTrigger ) break;
119937 }
119938 if( !pTrigger ){
@@ -119942,11 +119974,11 @@
119974 assert( pTable );
119975 assert( pTable->pSchema==pTrigger->pSchema || iDb==1 );
119976 #ifndef SQLITE_OMIT_AUTHORIZATION
119977 {
119978 int code = SQLITE_DROP_TRIGGER;
119979 const char *zDb = db->aDb[iDb].zDbSName;
119980 const char *zTab = SCHEMA_TABLE(iDb);
119981 if( iDb==1 ) code = SQLITE_DROP_TEMP_TRIGGER;
119982 if( sqlite3AuthCheck(pParse, code, pTrigger->zName, pTable->zName, zDb) ||
119983 sqlite3AuthCheck(pParse, SQLITE_DELETE, zTab, 0, zDb) ){
119984 return;
@@ -119958,11 +119990,11 @@
119990 */
119991 assert( pTable!=0 );
119992 if( (v = sqlite3GetVdbe(pParse))!=0 ){
119993 sqlite3NestedParse(pParse,
119994 "DELETE FROM %Q.%s WHERE name=%Q AND type='trigger'",
119995 db->aDb[iDb].zDbSName, SCHEMA_TABLE(iDb), pTrigger->zName
119996 );
119997 sqlite3ChangeCookie(pParse, iDb);
119998 sqlite3VdbeAddOp4(v, OP_DropTrigger, iDb, 0, 0, pTrigger->zName, 0);
119999 }
120000 }
@@ -120061,12 +120093,14 @@
120093 if( pSrc ){
120094 assert( pSrc->nSrc>0 );
120095 pSrc->a[pSrc->nSrc-1].zName = sqlite3DbStrDup(db, pStep->zTarget);
120096 iDb = sqlite3SchemaToIndex(db, pStep->pTrig->pSchema);
120097 if( iDb==0 || iDb>=2 ){
120098 const char *zDb;
120099 assert( iDb<db->nDb );
120100 zDb = db->aDb[iDb].zDbSName;
120101 pSrc->a[pSrc->nSrc-1].zDatabase = sqlite3DbStrDup(db, zDb);
120102 }
120103 }
120104 return pSrc;
120105 }
120106
@@ -120749,11 +120783,11 @@
120783 #ifndef SQLITE_OMIT_AUTHORIZATION
120784 {
120785 int rc;
120786 rc = sqlite3AuthCheck(pParse, SQLITE_UPDATE, pTab->zName,
120787 j<0 ? "ROWID" : pTab->aCol[j].zName,
120788 db->aDb[iDb].zDbSName);
120789 if( rc==SQLITE_DENY ){
120790 goto update_cleanup;
120791 }else if( rc==SQLITE_IGNORE ){
120792 aXRef[j] = -1;
120793 }
@@ -121506,11 +121540,11 @@
121540 zSql = "ATTACH '' AS vacuum_db;";
121541 }
121542 rc = execSql(db, pzErrMsg, zSql);
121543 if( db->nDb>nDb ){
121544 pDb = &db->aDb[db->nDb-1];
121545 assert( strcmp(pDb->zDbSName,"vacuum_db")==0 );
121546 }
121547 if( rc!=SQLITE_OK ) goto end_of_vacuum;
121548 pTemp = db->aDb[db->nDb-1].pBt;
121549
121550 /* The call to execSql() to attach the temp database has left the file
@@ -122055,11 +122089,11 @@
122089 ** sqlite_master table, has already been made by sqlite3StartTable().
122090 ** The second call, to obtain permission to create the table, is made now.
122091 */
122092 if( pTable->azModuleArg ){
122093 sqlite3AuthCheck(pParse, SQLITE_CREATE_VTABLE, pTable->zName,
122094 pTable->azModuleArg[0], pParse->db->aDb[iDb].zDbSName);
122095 }
122096 #endif
122097 }
122098
122099 /*
@@ -122119,11 +122153,11 @@
122153 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
122154 sqlite3NestedParse(pParse,
122155 "UPDATE %Q.%s "
122156 "SET type='table', name=%Q, tbl_name=%Q, rootpage=0, sql=%Q "
122157 "WHERE rowid=#%d",
122158 db->aDb[iDb].zDbSName, SCHEMA_TABLE(iDb),
122159 pTab->zName,
122160 pTab->zName,
122161 zStmt,
122162 pParse->regRowid
122163 );
@@ -122229,11 +122263,11 @@
122263 }
122264 pVTable->db = db;
122265 pVTable->pMod = pMod;
122266
122267 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
122268 pTab->azModuleArg[1] = db->aDb[iDb].zDbSName;
122269
122270 /* Invoke the virtual table constructor */
122271 assert( &db->pVtabCtx );
122272 assert( xConstruct );
122273 sCtx.pTab = pTab;
@@ -122393,11 +122427,11 @@
122427 int rc = SQLITE_OK;
122428 Table *pTab;
122429 Module *pMod;
122430 const char *zMod;
122431
122432 pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zDbSName);
122433 assert( pTab && (pTab->tabFlags & TF_Virtual)!=0 && !pTab->pVTable );
122434
122435 /* Locate the required virtual table module */
122436 zMod = pTab->azModuleArg[0];
122437 pMod = (Module*)sqlite3HashFind(&db->aModule, zMod);
@@ -122517,11 +122551,11 @@
122551 */
122552 SQLITE_PRIVATE int sqlite3VtabCallDestroy(sqlite3 *db, int iDb, const char *zTab){
122553 int rc = SQLITE_OK;
122554 Table *pTab;
122555
122556 pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zDbSName);
122557 if( pTab!=0 && ALWAYS(pTab->pVTable!=0) ){
122558 VTable *p;
122559 int (*xDestroy)(sqlite3_vtab *);
122560 for(p=pTab->pVTable; p; p=p->pNext){
122561 assert( p->pVtab );
@@ -125630,11 +125664,11 @@
125664 */
125665 static int isMatchOfColumn(
125666 Expr *pExpr, /* Test this expression */
125667 unsigned char *peOp2 /* OUT: 0 for MATCH, or else an op2 value */
125668 ){
125669 static const struct Op2 {
125670 const char *zOp;
125671 unsigned char eOp2;
125672 } aOp[] = {
125673 { "match", SQLITE_INDEX_CONSTRAINT_MATCH },
125674 { "glob", SQLITE_INDEX_CONSTRAINT_GLOB },
@@ -126615,17 +126649,18 @@
126649 ** These routines walk (recursively) an expression tree and generate
126650 ** a bitmask indicating which tables are used in that expression
126651 ** tree.
126652 */
126653 SQLITE_PRIVATE Bitmask sqlite3WhereExprUsage(WhereMaskSet *pMaskSet, Expr *p){
126654 Bitmask mask;
126655 if( p==0 ) return 0;
126656 if( p->op==TK_COLUMN ){
126657 mask = sqlite3WhereGetMask(pMaskSet, p->iTable);
126658 return mask;
126659 }
126660 assert( !ExprHasProperty(p, EP_TokenOnly) );
126661 mask = p->pRight ? sqlite3WhereExprUsage(pMaskSet, p->pRight) : 0;
126662 if( p->pLeft ) mask |= sqlite3WhereExprUsage(pMaskSet, p->pLeft);
126663 if( ExprHasProperty(p, EP_xIsSelect) ){
126664 mask |= exprSelectUsage(pMaskSet, p->x.pSelect);
126665 }else if( p->x.pList ){
126666 mask |= sqlite3WhereExprListUsage(pMaskSet, p->x.pList);
@@ -131868,29 +131903,33 @@
131903 ** N between YY_MIN_SHIFTREDUCE Shift to an arbitrary state then
131904 ** and YY_MAX_SHIFTREDUCE reduce by rule N-YY_MIN_SHIFTREDUCE.
131905 **
131906 ** N between YY_MIN_REDUCE Reduce by rule N-YY_MIN_REDUCE
131907 ** and YY_MAX_REDUCE
131908 **
131909 ** N == YY_ERROR_ACTION A syntax error has occurred.
131910 **
131911 ** N == YY_ACCEPT_ACTION The parser accepts its input.
131912 **
131913 ** N == YY_NO_ACTION No such action. Denotes unused
131914 ** slots in the yy_action[] table.
131915 **
131916 ** The action table is constructed as a single large table named yy_action[].
131917 ** Given state S and lookahead X, the action is computed as either:
131918 **
131919 ** (A) N = yy_action[ yy_shift_ofst[S] + X ]
131920 ** (B) N = yy_default[S]
131921 **
131922 ** The (A) formula is preferred. The B formula is used instead if:
131923 ** (1) The yy_shift_ofst[S]+X value is out of range, or
131924 ** (2) yy_lookahead[yy_shift_ofst[S]+X] is not equal to X, or
131925 ** (3) yy_shift_ofst[S] equal YY_SHIFT_USE_DFLT.
131926 ** (Implementation note: YY_SHIFT_USE_DFLT is chosen so that
131927 ** YY_SHIFT_USE_DFLT+X will be out of range for all possible lookaheads X.
131928 ** Hence only tests (1) and (2) need to be evaluated.)
131929 **
131930 ** The formulas above are for computing the action when the lookahead is
131931 ** a terminal symbol. If the lookahead is a non-terminal (as occurs after
131932 ** a reduce action) then the yy_reduce_ofst[] array is used in place of
131933 ** the yy_shift_ofst[] array and YY_REDUCE_USE_DFLT is used in place of
131934 ** YY_SHIFT_USE_DFLT.
131935 **
@@ -132211,14 +132250,14 @@
132250 /* 1470 */ 122, 23, 23, 64, 22, 124, 26, 26, 64, 64,
132251 /* 1480 */ 23, 23, 23, 23, 11, 23, 22, 26, 23, 22,
132252 /* 1490 */ 24, 1, 23, 22, 26, 122, 24, 23, 22, 122,
132253 /* 1500 */ 23, 23, 22, 122, 122, 23, 15,
132254 };
132255 #define YY_SHIFT_USE_DFLT (1507)
132256 #define YY_SHIFT_COUNT (442)
132257 #define YY_SHIFT_MIN (-94)
132258 #define YY_SHIFT_MAX (1491)
132259 static const short yy_shift_ofst[] = {
132260 /* 0 */ 40, 564, 869, 577, 725, 725, 725, 725, 690, -19,
132261 /* 10 */ 16, 16, 100, 725, 725, 725, 725, 725, 725, 725,
132262 /* 20 */ 841, 841, 538, 507, 684, 565, 61, 137, 172, 207,
132263 /* 30 */ 242, 277, 312, 347, 382, 424, 424, 424, 424, 424,
@@ -132227,16 +132266,16 @@
132266 /* 60 */ 725, 725, 725, 725, 725, 725, 725, 725, 725, 725,
132267 /* 70 */ 725, 725, 725, 725, 725, 725, 725, 725, 725, 725,
132268 /* 80 */ 725, 725, 725, 725, 821, 725, 725, 725, 725, 725,
132269 /* 90 */ 725, 725, 725, 725, 725, 725, 725, 725, 952, 711,
132270 /* 100 */ 711, 711, 711, 711, 766, 23, 32, 924, 637, 825,
132271 /* 110 */ 837, 837, 924, 73, 183, -51, 1507, 1507, 1507, 501,
132272 /* 120 */ 501, 501, 903, 903, 632, 205, 241, 924, 924, 924,
132273 /* 130 */ 924, 924, 924, 924, 924, 924, 924, 924, 924, 924,
132274 /* 140 */ 924, 924, 924, 924, 924, 924, 924, 192, 1027, 1106,
132275 /* 150 */ 1106, 183, 176, 176, 176, 176, 176, 176, 1507, 1507,
132276 /* 160 */ 1507, 880, -94, -94, 578, 734, 99, 730, 769, 349,
132277 /* 170 */ 924, 924, 924, 924, 924, 924, 924, 924, 924, 924,
132278 /* 180 */ 924, 924, 924, 924, 924, 924, 924, 954, 954, 954,
132279 /* 190 */ 924, 924, 622, 924, 924, 924, -18, 924, 924, 914,
132280 /* 200 */ 924, 924, 924, 924, 924, 924, 924, 924, 924, 924,
132281 /* 210 */ 441, 1020, 1107, 1107, 1107, 569, 45, 217, 510, 423,
@@ -132246,12 +132285,12 @@
132285 /* 250 */ 1297, 1183, 1277, 1285, 1285, 1183, 1176, 1297, 1182, 1250,
132286 /* 260 */ 1176, 1176, 1297, 1311, 1176, 1297, 1176, 1297, 1311, 1234,
132287 /* 270 */ 1234, 1234, 1267, 1311, 1234, 1244, 1234, 1267, 1234, 1234,
132288 /* 280 */ 1232, 1247, 1232, 1247, 1232, 1247, 1232, 1247, 1176, 1334,
132289 /* 290 */ 1176, 1235, 1311, 1318, 1318, 1311, 1248, 1253, 1245, 1249,
132290 /* 300 */ 1183, 1355, 1357, 1368, 1368, 1378, 1378, 1378, 1378, 1507,
132291 /* 310 */ 1507, 1507, 1507, 1507, 1507, 1507, 1507, 451, 936, 816,
132292 /* 320 */ 888, 1069, 799, 1111, 1197, 1193, 1201, 1202, 1203, 1213,
132293 /* 330 */ 1134, 1117, 1230, 497, 1218, 1219, 1154, 1223, 1115, 1120,
132294 /* 340 */ 1231, 1164, 1160, 1392, 1394, 1376, 1257, 1385, 1307, 1386,
132295 /* 350 */ 1383, 1388, 1292, 1282, 1303, 1294, 1395, 1293, 1403, 1419,
132296 /* 360 */ 1298, 1291, 1389, 1390, 1314, 1372, 1365, 1308, 1430, 1427,
@@ -133200,54 +133239,51 @@
133239
133240 if( stateno>=YY_MIN_REDUCE ) return stateno;
133241 assert( stateno <= YY_SHIFT_COUNT );
133242 do{
133243 i = yy_shift_ofst[stateno];
 
133244 assert( iLookAhead!=YYNOCODE );
133245 i += iLookAhead;
133246 if( i<0 || i>=YY_ACTTAB_COUNT || yy_lookahead[i]!=iLookAhead ){
 
133247 #ifdef YYFALLBACK
133248 YYCODETYPE iFallback; /* Fallback token */
133249 if( iLookAhead<sizeof(yyFallback)/sizeof(yyFallback[0])
133250 && (iFallback = yyFallback[iLookAhead])!=0 ){
133251 #ifndef NDEBUG
133252 if( yyTraceFILE ){
133253 fprintf(yyTraceFILE, "%sFALLBACK %s => %s\n",
133254 yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]);
133255 }
133256 #endif
133257 assert( yyFallback[iFallback]==0 ); /* Fallback loop must terminate */
133258 iLookAhead = iFallback;
133259 continue;
133260 }
133261 #endif
133262 #ifdef YYWILDCARD
133263 {
133264 int j = i - iLookAhead + YYWILDCARD;
133265 if(
133266 #if YY_SHIFT_MIN+YYWILDCARD<0
133267 j>=0 &&
133268 #endif
133269 #if YY_SHIFT_MAX+YYWILDCARD>=YY_ACTTAB_COUNT
133270 j<YY_ACTTAB_COUNT &&
133271 #endif
133272 yy_lookahead[j]==YYWILDCARD && iLookAhead>0
133273 ){
133274 #ifndef NDEBUG
133275 if( yyTraceFILE ){
133276 fprintf(yyTraceFILE, "%sWILDCARD %s => %s\n",
133277 yyTracePrompt, yyTokenName[iLookAhead],
133278 yyTokenName[YYWILDCARD]);
133279 }
133280 #endif /* NDEBUG */
133281 return yy_action[j];
 
133282 }
133283 }
133284 #endif /* YYWILDCARD */
 
133285 return yy_default[stateno];
133286 }else{
133287 return yy_action[i];
133288 }
133289 }while(1);
@@ -136006,18 +136042,30 @@
136042 assert( pParse->pNewTable==0 );
136043 assert( pParse->pNewTrigger==0 );
136044 assert( pParse->nVar==0 );
136045 assert( pParse->nzVar==0 );
136046 assert( pParse->azVar==0 );
136047 while( 1 ){
136048 assert( i>=0 );
136049 if( zSql[i]!=0 ){
136050 pParse->sLastToken.z = &zSql[i];
136051 pParse->sLastToken.n = sqlite3GetToken((u8*)&zSql[i],&tokenType);
136052 i += pParse->sLastToken.n;
136053 if( i>mxSqlLen ){
136054 pParse->rc = SQLITE_TOOBIG;
136055 break;
136056 }
136057 }else{
136058 /* Upon reaching the end of input, call the parser two more times
136059 ** with tokens TK_SEMI and 0, in that order. */
136060 if( lastTokenParsed==TK_SEMI ){
136061 tokenType = 0;
136062 }else if( lastTokenParsed==0 ){
136063 break;
136064 }else{
136065 tokenType = TK_SEMI;
136066 }
136067 }
136068 if( tokenType>=TK_SPACE ){
136069 assert( tokenType==TK_SPACE || tokenType==TK_ILLEGAL );
136070 if( db->u1.isInterrupted ){
136071 pParse->rc = SQLITE_INTERRUPT;
@@ -136034,19 +136082,10 @@
136082 if( pParse->rc!=SQLITE_OK || db->mallocFailed ) break;
136083 }
136084 }
136085 assert( nErr==0 );
136086 pParse->zTail = &zSql[i];
 
 
 
 
 
 
 
 
 
136087 #ifdef YYTRACKMAXSTACKDEPTH
136088 sqlite3_mutex_enter(sqlite3MallocMutex());
136089 sqlite3StatusHighwater(SQLITE_STATUS_PARSER_STACK,
136090 sqlite3ParserStackPeak(pEngine)
136091 );
@@ -137282,10 +137321,15 @@
137321 SQLITE_API int SQLITE_CDECL sqlite3_db_config(sqlite3 *db, int op, ...){
137322 va_list ap;
137323 int rc;
137324 va_start(ap, op);
137325 switch( op ){
137326 case SQLITE_DBCONFIG_MAINDBNAME: {
137327 db->aDb[0].zDbSName = va_arg(ap,char*);
137328 rc = SQLITE_OK;
137329 break;
137330 }
137331 case SQLITE_DBCONFIG_LOOKASIDE: {
137332 void *pBuf = va_arg(ap, void*); /* IMP: R-26835-10964 */
137333 int sz = va_arg(ap, int); /* IMP: R-47871-25994 */
137334 int cnt = va_arg(ap, int); /* IMP: R-04460-53386 */
137335 rc = setupLookaside(db, pBuf, sz, cnt);
@@ -139425,13 +139469,13 @@
139469 db->aDb[1].pSchema = sqlite3SchemaGet(db, 0);
139470
139471 /* The default safety_level for the main database is FULL; for the temp
139472 ** database it is OFF. This matches the pager layer defaults.
139473 */
139474 db->aDb[0].zDbSName = "main";
139475 db->aDb[0].safety_level = SQLITE_DEFAULT_SYNCHRONOUS+1;
139476 db->aDb[1].zDbSName = "temp";
139477 db->aDb[1].safety_level = PAGER_SYNCHRONOUS_OFF;
139478
139479 db->magic = SQLITE_MAGIC_OPEN;
139480 if( db->mallocFailed ){
139481 goto opendb_out;
@@ -140388,11 +140432,11 @@
140432 */
140433 SQLITE_PRIVATE Btree *sqlite3DbNameToBtree(sqlite3 *db, const char *zDbName){
140434 int i;
140435 for(i=0; i<db->nDb; i++){
140436 if( db->aDb[i].pBt
140437 && (zDbName==0 || sqlite3StrICmp(zDbName, db->aDb[i].zDbSName)==0)
140438 ){
140439 return db->aDb[i].pBt;
140440 }
140441 }
140442 return 0;
@@ -164754,19 +164798,25 @@
164798 /*
164799 ** Open an RBU handle to perform an RBU vacuum on database file zTarget.
164800 ** An RBU vacuum is similar to SQLite's built-in VACUUM command, except
164801 ** that it can be suspended and resumed like an RBU update.
164802 **
164803 ** The second argument to this function identifies a database in which
164804 ** to store the state of the RBU vacuum operation if it is suspended. The
164805 ** first time sqlite3rbu_vacuum() is called, to start an RBU vacuum
164806 ** operation, the state database should either not exist or be empty
164807 ** (contain no tables). If an RBU vacuum is suspended by calling
164808 ** sqlite3rbu_close() on the RBU handle before sqlite3rbu_step() has
164809 ** returned SQLITE_DONE, the vacuum state is stored in the state database.
164810 ** The vacuum can be resumed by calling this function to open a new RBU
164811 ** handle specifying the same target and state databases.
164812 **
164813 ** If the second argument passed to this function is NULL, then the
164814 ** name of the state database is "<database>-vacuum", where <database>
164815 ** is the name of the target database file. In this case, on UNIX, if the
164816 ** state database is not already present in the file-system, it is created
164817 ** with the same permissions as the target db is made.
164818 **
164819 ** This function does not delete the state database after an RBU vacuum
164820 ** is completed, even if it created it. However, if the call to
164821 ** sqlite3rbu_close() returns any value other than SQLITE_OK, the contents
164822 ** of the state tables within the state database are zeroed. This way,
@@ -167255,19 +167305,22 @@
167305 /*
167306 ** Open the database handle and attach the RBU database as "rbu". If an
167307 ** error occurs, leave an error code and message in the RBU handle.
167308 */
167309 static void rbuOpenDatabase(sqlite3rbu *p){
167310 assert( p->rc || (p->dbMain==0 && p->dbRbu==0) );
167311 assert( p->rc || rbuIsVacuum(p) || p->zTarget!=0 );
 
167312
167313 /* Open the RBU database */
167314 p->dbRbu = rbuOpenDbhandle(p, p->zRbu, 1);
167315
167316 if( p->rc==SQLITE_OK && rbuIsVacuum(p) ){
167317 sqlite3_file_control(p->dbRbu, "main", SQLITE_FCNTL_RBUCNT, (void*)p);
167318 if( p->zState==0 ){
167319 const char *zFile = sqlite3_db_filename(p->dbRbu, "main");
167320 p->zState = rbuMPrintf(p, "file://%s-vacuum?modeof=%s", zFile, zFile);
167321 }
167322 }
167323
167324 /* If using separate RBU and state databases, attach the state database to
167325 ** the RBU db handle now. */
167326 if( p->zState ){
@@ -168398,12 +168451,11 @@
168451 const char *zState
168452 ){
168453 sqlite3rbu *p;
168454 size_t nTarget = zTarget ? strlen(zTarget) : 0;
168455 size_t nRbu = strlen(zRbu);
168456 size_t nByte = sizeof(sqlite3rbu) + nTarget+1 + nRbu+1;
 
168457
168458 p = (sqlite3rbu*)sqlite3_malloc64(nByte);
168459 if( p ){
168460 RbuState *pState = 0;
168461
@@ -168421,12 +168473,11 @@
168473 }
168474 p->zRbu = pCsr;
168475 memcpy(p->zRbu, zRbu, nRbu+1);
168476 pCsr += nRbu+1;
168477 if( zState ){
168478 p->zState = rbuMPrintf(p, "%s", zState);
 
168479 }
168480 rbuOpenDatabase(p);
168481 }
168482
168483 if( p->rc==SQLITE_OK ){
@@ -168531,19 +168582,34 @@
168582 rbuFreeState(pState);
168583 }
168584
168585 return p;
168586 }
168587
168588 /*
168589 ** Allocate and return an RBU handle with all fields zeroed except for the
168590 ** error code, which is set to SQLITE_MISUSE.
168591 */
168592 static sqlite3rbu *rbuMisuseError(void){
168593 sqlite3rbu *pRet;
168594 pRet = sqlite3_malloc64(sizeof(sqlite3rbu));
168595 if( pRet ){
168596 memset(pRet, 0, sizeof(sqlite3rbu));
168597 pRet->rc = SQLITE_MISUSE;
168598 }
168599 return pRet;
168600 }
168601
168602 /*
168603 ** Open and return a new RBU handle.
168604 */
168605 SQLITE_API sqlite3rbu *SQLITE_STDCALL sqlite3rbu_open(
168606 const char *zTarget,
168607 const char *zRbu,
168608 const char *zState
168609 ){
168610 if( zTarget==0 || zRbu==0 ){ return rbuMisuseError(); }
168611 /* TODO: Check that zTarget and zRbu are non-NULL */
168612 return openRbuHandle(zTarget, zRbu, zState);
168613 }
168614
168615 /*
@@ -168551,10 +168617,11 @@
168617 */
168618 SQLITE_API sqlite3rbu *SQLITE_STDCALL sqlite3rbu_vacuum(
168619 const char *zTarget,
168620 const char *zState
168621 ){
168622 if( zTarget==0 ){ return rbuMisuseError(); }
168623 /* TODO: Check that both arguments are non-NULL */
168624 return openRbuHandle(0, zTarget, zState);
168625 }
168626
168627 /*
@@ -168628,10 +168695,11 @@
168695 sqlite3_free(p->aFrame);
168696
168697 rbuEditErrmsg(p);
168698 rc = p->rc;
168699 *pzErrmsg = p->zErrmsg;
168700 sqlite3_free(p->zState);
168701 sqlite3_free(p);
168702 }else{
168703 rc = SQLITE_NOMEM;
168704 *pzErrmsg = 0;
168705 }
@@ -170239,11 +170307,11 @@
170307 zSql = sqlite3_mprintf(
170308 "SELECT 'sqlite_master' AS name, 1 AS rootpage, 'table' AS type"
170309 " UNION ALL "
170310 "SELECT name, rootpage, type"
170311 " FROM \"%w\".%s WHERE rootpage!=0"
170312 " ORDER BY name", pTab->db->aDb[pCsr->iDb].zDbSName, zMaster);
170313 if( zSql==0 ){
170314 return SQLITE_NOMEM_BKPT;
170315 }else{
170316 rc = sqlite3_prepare_v2(pTab->db, zSql, -1, &pCsr->pStmt, 0);
170317 sqlite3_free(zSql);
@@ -170293,11 +170361,11 @@
170361 sqlite3_result_int(ctx, pCsr->szPage);
170362 break;
170363 default: { /* schema */
170364 sqlite3 *db = sqlite3_context_db_handle(ctx);
170365 int iDb = pCsr->iDb;
170366 sqlite3_result_text(ctx, db->aDb[iDb].zDbSName, -1, SQLITE_STATIC);
170367 break;
170368 }
170369 }
170370 return SQLITE_OK;
170371 }
@@ -178530,10 +178598,11 @@
178598 static void sqlite3Fts5ParseNearsetFree(Fts5ExprNearset*);
178599 static void sqlite3Fts5ParseNodeFree(Fts5ExprNode*);
178600
178601 static void sqlite3Fts5ParseSetDistance(Fts5Parse*, Fts5ExprNearset*, Fts5Token*);
178602 static void sqlite3Fts5ParseSetColset(Fts5Parse*, Fts5ExprNearset*, Fts5Colset*);
178603 static Fts5Colset *sqlite3Fts5ParseColsetInvert(Fts5Parse*, Fts5Colset*);
178604 static void sqlite3Fts5ParseFinished(Fts5Parse *pParse, Fts5ExprNode *p);
178605 static void sqlite3Fts5ParseNear(Fts5Parse *pParse, Fts5Token*);
178606
178607 /*
178608 ** End of interface to code in fts5_expr.c.
@@ -178587,16 +178656,17 @@
178656 #define FTS5_NOT 3
178657 #define FTS5_TERM 4
178658 #define FTS5_COLON 5
178659 #define FTS5_LP 6
178660 #define FTS5_RP 7
178661 #define FTS5_MINUS 8
178662 #define FTS5_LCP 9
178663 #define FTS5_RCP 10
178664 #define FTS5_STRING 11
178665 #define FTS5_COMMA 12
178666 #define FTS5_PLUS 13
178667 #define FTS5_STAR 14
178668
178669 /*
178670 ** 2000-05-29
178671 **
178672 ** The author disclaims copyright to this source code. In place of
@@ -178706,39 +178776,39 @@
178776 #ifndef INTERFACE
178777 # define INTERFACE 1
178778 #endif
178779 /************* Begin control #defines *****************************************/
178780 #define fts5YYCODETYPE unsigned char
178781 #define fts5YYNOCODE 28
178782 #define fts5YYACTIONTYPE unsigned char
178783 #define sqlite3Fts5ParserFTS5TOKENTYPE Fts5Token
178784 typedef union {
178785 int fts5yyinit;
178786 sqlite3Fts5ParserFTS5TOKENTYPE fts5yy0;
178787 int fts5yy4;
178788 Fts5Colset* fts5yy11;
178789 Fts5ExprNode* fts5yy24;
178790 Fts5ExprNearset* fts5yy46;
178791 Fts5ExprPhrase* fts5yy53;
178792 } fts5YYMINORTYPE;
178793 #ifndef fts5YYSTACKDEPTH
178794 #define fts5YYSTACKDEPTH 100
178795 #endif
178796 #define sqlite3Fts5ParserARG_SDECL Fts5Parse *pParse;
178797 #define sqlite3Fts5ParserARG_PDECL ,Fts5Parse *pParse
178798 #define sqlite3Fts5ParserARG_FETCH Fts5Parse *pParse = fts5yypParser->pParse
178799 #define sqlite3Fts5ParserARG_STORE fts5yypParser->pParse = pParse
178800 #define fts5YYNSTATE 29
178801 #define fts5YYNRULE 26
178802 #define fts5YY_MAX_SHIFT 28
178803 #define fts5YY_MIN_SHIFTREDUCE 45
178804 #define fts5YY_MAX_SHIFTREDUCE 70
178805 #define fts5YY_MIN_REDUCE 71
178806 #define fts5YY_MAX_REDUCE 96
178807 #define fts5YY_ERROR_ACTION 97
178808 #define fts5YY_ACCEPT_ACTION 98
178809 #define fts5YY_NO_ACTION 99
178810 /************* End control #defines *******************************************/
178811
178812 /* Define the fts5yytestcase() macro to be a no-op if is not already defined
178813 ** otherwise.
178814 **
@@ -178766,29 +178836,33 @@
178836 ** N between fts5YY_MIN_SHIFTREDUCE Shift to an arbitrary state then
178837 ** and fts5YY_MAX_SHIFTREDUCE reduce by rule N-fts5YY_MIN_SHIFTREDUCE.
178838 **
178839 ** N between fts5YY_MIN_REDUCE Reduce by rule N-fts5YY_MIN_REDUCE
178840 ** and fts5YY_MAX_REDUCE
178841 **
178842 ** N == fts5YY_ERROR_ACTION A syntax error has occurred.
178843 **
178844 ** N == fts5YY_ACCEPT_ACTION The parser accepts its input.
178845 **
178846 ** N == fts5YY_NO_ACTION No such action. Denotes unused
178847 ** slots in the fts5yy_action[] table.
178848 **
178849 ** The action table is constructed as a single large table named fts5yy_action[].
178850 ** Given state S and lookahead X, the action is computed as either:
178851 **
178852 ** (A) N = fts5yy_action[ fts5yy_shift_ofst[S] + X ]
178853 ** (B) N = fts5yy_default[S]
178854 **
178855 ** The (A) formula is preferred. The B formula is used instead if:
178856 ** (1) The fts5yy_shift_ofst[S]+X value is out of range, or
178857 ** (2) fts5yy_lookahead[fts5yy_shift_ofst[S]+X] is not equal to X, or
178858 ** (3) fts5yy_shift_ofst[S] equal fts5YY_SHIFT_USE_DFLT.
178859 ** (Implementation note: fts5YY_SHIFT_USE_DFLT is chosen so that
178860 ** fts5YY_SHIFT_USE_DFLT+X will be out of range for all possible lookaheads X.
178861 ** Hence only tests (1) and (2) need to be evaluated.)
178862 **
178863 ** The formulas above are for computing the action when the lookahead is
178864 ** a terminal symbol. If the lookahead is a non-terminal (as occurs after
178865 ** a reduce action) then the fts5yy_reduce_ofst[] array is used in place of
178866 ** the fts5yy_shift_ofst[] array and fts5YY_REDUCE_USE_DFLT is used in place of
178867 ** fts5YY_SHIFT_USE_DFLT.
178868 **
@@ -178802,52 +178876,54 @@
178876 ** fts5yy_reduce_ofst[] For each state, the offset into fts5yy_action for
178877 ** shifting non-terminals after a reduce.
178878 ** fts5yy_default[] Default action for each state.
178879 **
178880 *********** Begin parsing tables **********************************************/
178881 #define fts5YY_ACTTAB_COUNT (85)
178882 static const fts5YYACTIONTYPE fts5yy_action[] = {
178883 /* 0 */ 98, 16, 51, 5, 53, 27, 83, 7, 26, 15,
178884 /* 10 */ 51, 5, 53, 27, 13, 69, 26, 48, 51, 5,
178885 /* 20 */ 53, 27, 19, 11, 26, 9, 20, 51, 5, 53,
178886 /* 30 */ 27, 13, 22, 26, 28, 51, 5, 53, 27, 68,
178887 /* 40 */ 1, 26, 19, 11, 17, 9, 52, 10, 53, 27,
178888 /* 50 */ 23, 24, 26, 54, 3, 4, 2, 26, 6, 21,
178889 /* 60 */ 49, 71, 3, 4, 2, 7, 56, 59, 55, 59,
178890 /* 70 */ 4, 2, 12, 69, 58, 60, 18, 67, 62, 69,
178891 /* 80 */ 25, 66, 8, 14, 2,
178892 };
178893 static const fts5YYCODETYPE fts5yy_lookahead[] = {
178894 /* 0 */ 16, 17, 18, 19, 20, 21, 5, 6, 24, 17,
178895 /* 10 */ 18, 19, 20, 21, 11, 14, 24, 17, 18, 19,
178896 /* 20 */ 20, 21, 8, 9, 24, 11, 17, 18, 19, 20,
178897 /* 30 */ 21, 11, 12, 24, 17, 18, 19, 20, 21, 26,
178898 /* 40 */ 6, 24, 8, 9, 22, 11, 18, 11, 20, 21,
178899 /* 50 */ 24, 25, 24, 20, 1, 2, 3, 24, 23, 24,
178900 /* 60 */ 7, 0, 1, 2, 3, 6, 10, 11, 10, 11,
178901 /* 70 */ 2, 3, 9, 14, 11, 11, 22, 26, 7, 14,
178902 /* 80 */ 13, 11, 5, 11, 3,
178903 };
178904 #define fts5YY_SHIFT_USE_DFLT (85)
178905 #define fts5YY_SHIFT_COUNT (28)
178906 #define fts5YY_SHIFT_MIN (0)
178907 #define fts5YY_SHIFT_MAX (81)
178908 static const unsigned char fts5yy_shift_ofst[] = {
178909 /* 0 */ 34, 34, 34, 34, 34, 14, 20, 3, 36, 1,
178910 /* 10 */ 59, 64, 64, 65, 65, 53, 61, 56, 58, 63,
178911 /* 20 */ 68, 67, 70, 67, 71, 72, 67, 77, 81,
178912 };
178913 #define fts5YY_REDUCE_USE_DFLT (-17)
178914 #define fts5YY_REDUCE_COUNT (14)
178915 #define fts5YY_REDUCE_MIN (-16)
178916 #define fts5YY_REDUCE_MAX (54)
178917 static const signed char fts5yy_reduce_ofst[] = {
178918 /* 0 */ -16, -8, 0, 9, 17, 28, 26, 35, 33, 13,
178919 /* 10 */ 13, 22, 54, 13, 51,
178920 };
178921 static const fts5YYACTIONTYPE fts5yy_default[] = {
178922 /* 0 */ 97, 97, 97, 97, 97, 76, 91, 97, 97, 96,
178923 /* 10 */ 96, 97, 97, 96, 96, 97, 97, 97, 97, 97,
178924 /* 20 */ 73, 89, 97, 90, 97, 97, 87, 97, 72,
178925 };
178926 /********** End of lemon-generated parsing tables *****************************/
178927
178928 /* The next table maps tokens (terminal symbols) into fallback tokens.
178929 ** If a construct like the following:
@@ -178950,15 +179026,15 @@
179026 /* For tracing shifts, the names of all terminals and nonterminals
179027 ** are required. The following table supplies these names */
179028 static const char *const fts5yyTokenName[] = {
179029 "$", "OR", "AND", "NOT",
179030 "TERM", "COLON", "LP", "RP",
179031 "MINUS", "LCP", "RCP", "STRING",
179032 "COMMA", "PLUS", "STAR", "error",
179033 "input", "expr", "cnearset", "exprlist",
179034 "nearset", "colset", "colsetlist", "nearphrases",
179035 "phrase", "neardist_opt", "star_opt",
179036 };
179037 #endif /* NDEBUG */
179038
179039 #ifndef NDEBUG
179040 /* For tracing reduce actions, the names of all rules are required.
@@ -178972,24 +179048,26 @@
179048 /* 5 */ "expr ::= exprlist",
179049 /* 6 */ "exprlist ::= cnearset",
179050 /* 7 */ "exprlist ::= exprlist cnearset",
179051 /* 8 */ "cnearset ::= nearset",
179052 /* 9 */ "cnearset ::= colset COLON nearset",
179053 /* 10 */ "colset ::= MINUS LCP colsetlist RCP",
179054 /* 11 */ "colset ::= LCP colsetlist RCP",
179055 /* 12 */ "colset ::= STRING",
179056 /* 13 */ "colset ::= MINUS STRING",
179057 /* 14 */ "colsetlist ::= colsetlist STRING",
179058 /* 15 */ "colsetlist ::= STRING",
179059 /* 16 */ "nearset ::= phrase",
179060 /* 17 */ "nearset ::= STRING LP nearphrases neardist_opt RP",
179061 /* 18 */ "nearphrases ::= phrase",
179062 /* 19 */ "nearphrases ::= nearphrases phrase",
179063 /* 20 */ "neardist_opt ::=",
179064 /* 21 */ "neardist_opt ::= COMMA STRING",
179065 /* 22 */ "phrase ::= phrase PLUS STRING star_opt",
179066 /* 23 */ "phrase ::= STRING star_opt",
179067 /* 24 */ "star_opt ::= STAR",
179068 /* 25 */ "star_opt ::=",
179069 };
179070 #endif /* NDEBUG */
179071
179072
179073 #if fts5YYSTACKDEPTH<=0
@@ -179095,37 +179173,37 @@
179173 ** Note: during a reduce, the only symbols destroyed are those
179174 ** which appear on the RHS of the rule, but which are *not* used
179175 ** inside the C code.
179176 */
179177 /********* Begin destructor definitions ***************************************/
179178 case 16: /* input */
179179 {
179180 (void)pParse;
179181 }
179182 break;
179183 case 17: /* expr */
179184 case 18: /* cnearset */
179185 case 19: /* exprlist */
179186 {
179187 sqlite3Fts5ParseNodeFree((fts5yypminor->fts5yy24));
179188 }
179189 break;
179190 case 20: /* nearset */
179191 case 23: /* nearphrases */
179192 {
179193 sqlite3Fts5ParseNearsetFree((fts5yypminor->fts5yy46));
179194 }
179195 break;
179196 case 21: /* colset */
179197 case 22: /* colsetlist */
179198 {
179199 sqlite3_free((fts5yypminor->fts5yy11));
179200 }
179201 break;
179202 case 24: /* phrase */
179203 {
179204 sqlite3Fts5ParsePhraseFree((fts5yypminor->fts5yy53));
179205 }
179206 break;
179207 /********* End destructor definitions *****************************************/
179208 default: break; /* If no destructor action specified: do nothing */
179209 }
@@ -179198,54 +179276,51 @@
179276
179277 if( stateno>=fts5YY_MIN_REDUCE ) return stateno;
179278 assert( stateno <= fts5YY_SHIFT_COUNT );
179279 do{
179280 i = fts5yy_shift_ofst[stateno];
 
179281 assert( iLookAhead!=fts5YYNOCODE );
179282 i += iLookAhead;
179283 if( i<0 || i>=fts5YY_ACTTAB_COUNT || fts5yy_lookahead[i]!=iLookAhead ){
 
179284 #ifdef fts5YYFALLBACK
179285 fts5YYCODETYPE iFallback; /* Fallback token */
179286 if( iLookAhead<sizeof(fts5yyFallback)/sizeof(fts5yyFallback[0])
179287 && (iFallback = fts5yyFallback[iLookAhead])!=0 ){
179288 #ifndef NDEBUG
179289 if( fts5yyTraceFILE ){
179290 fprintf(fts5yyTraceFILE, "%sFALLBACK %s => %s\n",
179291 fts5yyTracePrompt, fts5yyTokenName[iLookAhead], fts5yyTokenName[iFallback]);
179292 }
179293 #endif
179294 assert( fts5yyFallback[iFallback]==0 ); /* Fallback loop must terminate */
179295 iLookAhead = iFallback;
179296 continue;
179297 }
179298 #endif
179299 #ifdef fts5YYWILDCARD
179300 {
179301 int j = i - iLookAhead + fts5YYWILDCARD;
179302 if(
179303 #if fts5YY_SHIFT_MIN+fts5YYWILDCARD<0
179304 j>=0 &&
179305 #endif
179306 #if fts5YY_SHIFT_MAX+fts5YYWILDCARD>=fts5YY_ACTTAB_COUNT
179307 j<fts5YY_ACTTAB_COUNT &&
179308 #endif
179309 fts5yy_lookahead[j]==fts5YYWILDCARD && iLookAhead>0
179310 ){
179311 #ifndef NDEBUG
179312 if( fts5yyTraceFILE ){
179313 fprintf(fts5yyTraceFILE, "%sWILDCARD %s => %s\n",
179314 fts5yyTracePrompt, fts5yyTokenName[iLookAhead],
179315 fts5yyTokenName[fts5YYWILDCARD]);
179316 }
179317 #endif /* NDEBUG */
179318 return fts5yy_action[j];
 
179319 }
179320 }
179321 #endif /* fts5YYWILDCARD */
 
179322 return fts5yy_default[stateno];
179323 }else{
179324 return fts5yy_action[i];
179325 }
179326 }while(1);
@@ -179368,34 +179443,36 @@
179443 */
179444 static const struct {
179445 fts5YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */
179446 unsigned char nrhs; /* Number of right-hand side symbols in the rule */
179447 } fts5yyRuleInfo[] = {
 
 
 
 
 
179448 { 16, 1 },
179449 { 17, 3 },
179450 { 17, 3 },
179451 { 17, 3 },
179452 { 17, 3 },
179453 { 17, 1 },
179454 { 19, 1 },
179455 { 19, 2 },
179456 { 18, 1 },
179457 { 18, 3 },
179458 { 21, 4 },
179459 { 21, 3 },
179460 { 21, 1 },
 
179461 { 21, 2 },
179462 { 22, 2 },
 
 
179463 { 22, 1 },
179464 { 20, 1 },
179465 { 20, 5 },
179466 { 23, 1 },
 
179467 { 23, 2 },
 
179468 { 25, 0 },
179469 { 25, 2 },
179470 { 24, 4 },
179471 { 24, 2 },
179472 { 26, 1 },
179473 { 26, 0 },
179474 };
179475
179476 static void fts5yy_accept(fts5yyParser*); /* Forward Declaration */
179477
179478 /*
@@ -179456,124 +179533,135 @@
179533 ** break;
179534 */
179535 /********** Begin reduce actions **********************************************/
179536 fts5YYMINORTYPE fts5yylhsminor;
179537 case 0: /* input ::= expr */
179538 { sqlite3Fts5ParseFinished(pParse, fts5yymsp[0].minor.fts5yy24); }
179539 break;
179540 case 1: /* expr ::= expr AND expr */
179541 {
179542 fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_AND, fts5yymsp[-2].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24, 0);
179543 }
179544 fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
179545 break;
179546 case 2: /* expr ::= expr OR expr */
179547 {
179548 fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_OR, fts5yymsp[-2].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24, 0);
179549 }
179550 fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
179551 break;
179552 case 3: /* expr ::= expr NOT expr */
179553 {
179554 fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_NOT, fts5yymsp[-2].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24, 0);
179555 }
179556 fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
179557 break;
179558 case 4: /* expr ::= LP expr RP */
179559 {fts5yymsp[-2].minor.fts5yy24 = fts5yymsp[-1].minor.fts5yy24;}
179560 break;
179561 case 5: /* expr ::= exprlist */
179562 case 6: /* exprlist ::= cnearset */ fts5yytestcase(fts5yyruleno==6);
179563 {fts5yylhsminor.fts5yy24 = fts5yymsp[0].minor.fts5yy24;}
179564 fts5yymsp[0].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
179565 break;
179566 case 7: /* exprlist ::= exprlist cnearset */
179567 {
179568 fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseImplicitAnd(pParse, fts5yymsp[-1].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24);
179569 }
179570 fts5yymsp[-1].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
179571 break;
179572 case 8: /* cnearset ::= nearset */
179573 {
179574 fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_STRING, 0, 0, fts5yymsp[0].minor.fts5yy46);
179575 }
179576 fts5yymsp[0].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
179577 break;
179578 case 9: /* cnearset ::= colset COLON nearset */
179579 {
179580 sqlite3Fts5ParseSetColset(pParse, fts5yymsp[0].minor.fts5yy46, fts5yymsp[-2].minor.fts5yy11);
179581 fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_STRING, 0, 0, fts5yymsp[0].minor.fts5yy46);
179582 }
179583 fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
179584 break;
179585 case 10: /* colset ::= MINUS LCP colsetlist RCP */
179586 {
179587 fts5yymsp[-3].minor.fts5yy11 = sqlite3Fts5ParseColsetInvert(pParse, fts5yymsp[-1].minor.fts5yy11);
179588 }
179589 break;
179590 case 11: /* colset ::= LCP colsetlist RCP */
179591 { fts5yymsp[-2].minor.fts5yy11 = fts5yymsp[-1].minor.fts5yy11; }
179592 break;
179593 case 12: /* colset ::= STRING */
179594 {
179595 fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
179596 }
179597 fts5yymsp[0].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
179598 break;
179599 case 13: /* colset ::= MINUS STRING */
179600 {
179601 fts5yymsp[-1].minor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
179602 fts5yymsp[-1].minor.fts5yy11 = sqlite3Fts5ParseColsetInvert(pParse, fts5yymsp[-1].minor.fts5yy11);
179603 }
179604 break;
179605 case 14: /* colsetlist ::= colsetlist STRING */
179606 {
179607 fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseColset(pParse, fts5yymsp[-1].minor.fts5yy11, &fts5yymsp[0].minor.fts5yy0); }
179608 fts5yymsp[-1].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
179609 break;
179610 case 15: /* colsetlist ::= STRING */
179611 {
179612 fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
179613 }
179614 fts5yymsp[0].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
179615 break;
179616 case 16: /* nearset ::= phrase */
179617 { fts5yylhsminor.fts5yy46 = sqlite3Fts5ParseNearset(pParse, 0, fts5yymsp[0].minor.fts5yy53); }
179618 fts5yymsp[0].minor.fts5yy46 = fts5yylhsminor.fts5yy46;
179619 break;
179620 case 17: /* nearset ::= STRING LP nearphrases neardist_opt RP */
179621 {
179622 sqlite3Fts5ParseNear(pParse, &fts5yymsp[-4].minor.fts5yy0);
179623 sqlite3Fts5ParseSetDistance(pParse, fts5yymsp[-2].minor.fts5yy46, &fts5yymsp[-1].minor.fts5yy0);
179624 fts5yylhsminor.fts5yy46 = fts5yymsp[-2].minor.fts5yy46;
179625 }
179626 fts5yymsp[-4].minor.fts5yy46 = fts5yylhsminor.fts5yy46;
179627 break;
179628 case 18: /* nearphrases ::= phrase */
179629 {
179630 fts5yylhsminor.fts5yy46 = sqlite3Fts5ParseNearset(pParse, 0, fts5yymsp[0].minor.fts5yy53);
179631 }
179632 fts5yymsp[0].minor.fts5yy46 = fts5yylhsminor.fts5yy46;
179633 break;
179634 case 19: /* nearphrases ::= nearphrases phrase */
179635 {
179636 fts5yylhsminor.fts5yy46 = sqlite3Fts5ParseNearset(pParse, fts5yymsp[-1].minor.fts5yy46, fts5yymsp[0].minor.fts5yy53);
179637 }
179638 fts5yymsp[-1].minor.fts5yy46 = fts5yylhsminor.fts5yy46;
179639 break;
179640 case 20: /* neardist_opt ::= */
179641 { fts5yymsp[1].minor.fts5yy0.p = 0; fts5yymsp[1].minor.fts5yy0.n = 0; }
179642 break;
179643 case 21: /* neardist_opt ::= COMMA STRING */
179644 { fts5yymsp[-1].minor.fts5yy0 = fts5yymsp[0].minor.fts5yy0; }
179645 break;
179646 case 22: /* phrase ::= phrase PLUS STRING star_opt */
179647 {
179648 fts5yylhsminor.fts5yy53 = sqlite3Fts5ParseTerm(pParse, fts5yymsp[-3].minor.fts5yy53, &fts5yymsp[-1].minor.fts5yy0, fts5yymsp[0].minor.fts5yy4);
179649 }
179650 fts5yymsp[-3].minor.fts5yy53 = fts5yylhsminor.fts5yy53;
179651 break;
179652 case 23: /* phrase ::= STRING star_opt */
179653 {
179654 fts5yylhsminor.fts5yy53 = sqlite3Fts5ParseTerm(pParse, 0, &fts5yymsp[-1].minor.fts5yy0, fts5yymsp[0].minor.fts5yy4);
179655 }
179656 fts5yymsp[-1].minor.fts5yy53 = fts5yylhsminor.fts5yy53;
179657 break;
179658 case 24: /* star_opt ::= STAR */
179659 { fts5yymsp[0].minor.fts5yy4 = 1; }
179660 break;
179661 case 25: /* star_opt ::= */
179662 { fts5yymsp[1].minor.fts5yy4 = 0; }
179663 break;
179664 default:
179665 break;
179666 /********** End reduce actions ************************************************/
179667 };
@@ -180027,11 +180115,11 @@
180115 }
180116
180117 if( p->iRangeEnd>0 && iPos==p->iRangeEnd ){
180118 fts5HighlightAppend(&rc, p, &p->zIn[p->iOff], iEndOff - p->iOff);
180119 p->iOff = iEndOff;
180120 if( iPos>=p->iter.iStart && iPos<p->iter.iEnd ){
180121 fts5HighlightAppend(&rc, p, p->zClose, -1);
180122 }
180123 }
180124
180125 return rc;
@@ -180188,10 +180276,17 @@
180276 ctx.iRangeEnd = iBestStart + nToken - 1;
180277
180278 if( iBestStart>0 ){
180279 fts5HighlightAppend(&rc, &ctx, zEllips, -1);
180280 }
180281
180282 /* Advance iterator ctx.iter so that it points to the first coalesced
180283 ** phrase instance at or following position iBestStart. */
180284 while( ctx.iter.iStart>=0 && ctx.iter.iStart<iBestStart && rc==SQLITE_OK ){
180285 rc = fts5CInstIterNext(&ctx.iter);
180286 }
180287
180288 if( rc==SQLITE_OK ){
180289 rc = pApi->xTokenize(pFts, ctx.zIn, ctx.nIn, (void*)&ctx,fts5HighlightCb);
180290 }
180291 if( ctx.iRangeEnd>=(nColSize-1) ){
180292 fts5HighlightAppend(&rc, &ctx, &ctx.zIn[ctx.iOff], ctx.nIn - ctx.iOff);
@@ -181923,10 +182018,11 @@
182018 case '}': tok = FTS5_RCP; break;
182019 case ':': tok = FTS5_COLON; break;
182020 case ',': tok = FTS5_COMMA; break;
182021 case '+': tok = FTS5_PLUS; break;
182022 case '*': tok = FTS5_STAR; break;
182023 case '-': tok = FTS5_MINUS; break;
182024 case '\0': tok = FTS5_EOF; break;
182025
182026 case '"': {
182027 const char *z2;
182028 tok = FTS5_STRING;
@@ -183414,11 +183510,11 @@
183510 sizeof(Fts5ExprNearset) + sizeof(Fts5ExprPhrase*));
183511 }
183512 if( rc==SQLITE_OK ){
183513 Fts5Colset *pColsetOrig = pOrig->pNode->pNear->pColset;
183514 if( pColsetOrig ){
183515 int nByte = sizeof(Fts5Colset) + (pColsetOrig->nCol-1) * sizeof(int);
183516 Fts5Colset *pColset = (Fts5Colset*)sqlite3Fts5MallocZero(&rc, nByte);
183517 if( pColset ){
183518 memcpy(pColset, pColsetOrig, nByte);
183519 }
183520 pNew->pRoot->pNear->pColset = pColset;
@@ -183548,10 +183644,38 @@
183644 #endif
183645 }
183646
183647 return pNew;
183648 }
183649
183650 /*
183651 ** Allocate and return an Fts5Colset object specifying the inverse of
183652 ** the colset passed as the second argument. Free the colset passed
183653 ** as the second argument before returning.
183654 */
183655 static Fts5Colset *sqlite3Fts5ParseColsetInvert(Fts5Parse *pParse, Fts5Colset *p){
183656 Fts5Colset *pRet;
183657 int nCol = pParse->pConfig->nCol;
183658
183659 pRet = (Fts5Colset*)sqlite3Fts5MallocZero(&pParse->rc,
183660 sizeof(Fts5Colset) + sizeof(int)*nCol
183661 );
183662 if( pRet ){
183663 int i;
183664 int iOld = 0;
183665 for(i=0; i<nCol; i++){
183666 if( iOld>=p->nCol || p->aiCol[iOld]!=i ){
183667 pRet->aiCol[pRet->nCol++] = i;
183668 }else{
183669 iOld++;
183670 }
183671 }
183672 }
183673
183674 sqlite3_free(p);
183675 return pRet;
183676 }
183677
183678 static Fts5Colset *sqlite3Fts5ParseColset(
183679 Fts5Parse *pParse, /* Store SQLITE_NOMEM here if required */
183680 Fts5Colset *pColset, /* Existing colset object */
183681 Fts5Token *p
@@ -185644,18 +185768,29 @@
185768
185769 assert( (pRet==0)==(p->rc!=SQLITE_OK) );
185770 return pRet;
185771 }
185772
 
185773 /*
185774 ** Release a reference to data record returned by an earlier call to
185775 ** fts5DataRead().
185776 */
185777 static void fts5DataRelease(Fts5Data *pData){
185778 sqlite3_free(pData);
185779 }
185780
185781 static Fts5Data *fts5LeafRead(Fts5Index *p, i64 iRowid){
185782 Fts5Data *pRet = fts5DataRead(p, iRowid);
185783 if( pRet ){
185784 if( pRet->szLeaf>pRet->nn ){
185785 p->rc = FTS5_CORRUPT;
185786 fts5DataRelease(pRet);
185787 pRet = 0;
185788 }
185789 }
185790 return pRet;
185791 }
185792
185793 static int fts5IndexPrepareStmt(
185794 Fts5Index *p,
185795 sqlite3_stmt **ppStmt,
185796 char *zSql
@@ -186461,11 +186596,11 @@
186596 pIter->iLeafPgno++;
186597 if( pIter->pNextLeaf ){
186598 pIter->pLeaf = pIter->pNextLeaf;
186599 pIter->pNextLeaf = 0;
186600 }else if( pIter->iLeafPgno<=pSeg->pgnoLast ){
186601 pIter->pLeaf = fts5LeafRead(p,
186602 FTS5_SEGMENT_ROWID(pSeg->iSegid, pIter->iLeafPgno)
186603 );
186604 }else{
186605 pIter->pLeaf = 0;
186606 }
@@ -186964,13 +187099,12 @@
187099 pIter->iLeafOffset = iOff;
187100
187101 if( pLeaf->nn>pLeaf->szLeaf ){
187102 pIter->iPgidxOff = pLeaf->szLeaf + fts5GetVarint32(
187103 &pLeaf->p[pLeaf->szLeaf], pIter->iEndofDoclist
187104 );
187105 }
 
187106 }
187107 else if( pLeaf->nn>pLeaf->szLeaf ){
187108 pIter->iPgidxOff = pLeaf->szLeaf + fts5GetVarint32(
187109 &pLeaf->p[pLeaf->szLeaf], iOff
187110 );
@@ -187210,10 +187344,15 @@
187344 }
187345
187346 iPgidx += fts5GetVarint32(&a[iPgidx], nKeep);
187347 iTermOff += nKeep;
187348 iOff = iTermOff;
187349
187350 if( iOff>=n ){
187351 p->rc = FTS5_CORRUPT;
187352 return;
187353 }
187354
187355 /* Read the nKeep field of the next term. */
187356 fts5FastGetVarint32(a, iOff, nKeep);
187357 }
187358
@@ -188136,10 +188275,19 @@
188275 fts5BufferZero(&pIter->poslist);
188276 fts5SegiterPoslist(pIter->pIndex, pSeg, 0, &pIter->poslist);
188277 pIter->base.pData = pIter->poslist.p;
188278 }
188279 }
188280
188281 /*
188282 ** xSetOutputs callback used when the Fts5Colset object has nCol==0 (match
188283 ** against no columns at all).
188284 */
188285 static void fts5IterSetOutputs_ZeroColset(Fts5Iter *pIter, Fts5SegIter *pSeg){
188286 UNUSED_PARAM(pSeg);
188287 pIter->base.nData = 0;
188288 }
188289
188290 /*
188291 ** xSetOutputs callback used by detail=col when there is a column filter
188292 ** and there are 100 or more columns. Also called as a fallback from
188293 ** fts5IterSetOutputs_Col100 if the column-list spans more than one page.
@@ -188241,10 +188389,14 @@
188389 }
188390
188391 else if( pIter->pColset==0 ){
188392 pIter->xSetOutputs = fts5IterSetOutputs_Nocolset;
188393 }
188394
188395 else if( pIter->pColset->nCol==0 ){
188396 pIter->xSetOutputs = fts5IterSetOutputs_ZeroColset;
188397 }
188398
188399 else if( pConfig->eDetail==FTS5_DETAIL_FULL ){
188400 pIter->xSetOutputs = fts5IterSetOutputs_Full;
188401 }
188402
@@ -194018,11 +194170,11 @@
194170 int nArg, /* Number of args */
194171 sqlite3_value **apUnused /* Function arguments */
194172 ){
194173 assert( nArg==0 );
194174 UNUSED_PARAM2(nArg, apUnused);
194175 sqlite3_result_text(pCtx, "fts5: 2016-08-18 15:21:16 4768a1066cb9c7627064d7efec44188d6755cb03", -1, SQLITE_TRANSIENT);
194176 }
194177
194178 static int fts5Init(sqlite3 *db){
194179 static const sqlite3_module fts5Mod = {
194180 /* iVersion */ 2,
194181
+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-18 22:44:22 d6e3d5796c9991ca0af45ed92ce36f55efc02348"
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-18 22:44:22 d6e3d5796c9991ca0af45ed92ce36f55efc02348"
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