| | @@ -1,8 +1,8 @@ |
| 1 | 1 | /****************************************************************************** |
| 2 | 2 | ** This file is an amalgamation of many separate C source files from SQLite |
| 3 | | -** version 3.7.11. By combining all the individual C code files into this |
| 3 | +** version 3.7.12. By combining all the individual C code files into this |
| 4 | 4 | ** single large file, the entire code can be compiled as a single translation |
| 5 | 5 | ** unit. This allows many compilers to do optimizations that would not be |
| 6 | 6 | ** possible if the files were compiled separately. Performance improvements |
| 7 | 7 | ** of 5% or more are commonly seen when SQLite is compiled as a single |
| 8 | 8 | ** translation unit. |
| | @@ -655,13 +655,13 @@ |
| 655 | 655 | ** |
| 656 | 656 | ** See also: [sqlite3_libversion()], |
| 657 | 657 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 658 | 658 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 659 | 659 | */ |
| 660 | | -#define SQLITE_VERSION "3.7.11" |
| 661 | | -#define SQLITE_VERSION_NUMBER 3007011 |
| 662 | | -#define SQLITE_SOURCE_ID "2012-02-13 20:16:37 84b324606adc8437338c086404eb157f30f04130" |
| 660 | +#define SQLITE_VERSION "3.7.12" |
| 661 | +#define SQLITE_VERSION_NUMBER 3007012 |
| 662 | +#define SQLITE_SOURCE_ID "2012-03-31 19:12:23 af602d87736b52802a4e760ffeeaa28112b99d9a" |
| 663 | 663 | |
| 664 | 664 | /* |
| 665 | 665 | ** CAPI3REF: Run-Time Library Version Numbers |
| 666 | 666 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 667 | 667 | ** |
| | @@ -1009,10 +1009,11 @@ |
| 1009 | 1009 | #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8)) |
| 1010 | 1010 | #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8)) |
| 1011 | 1011 | #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8)) |
| 1012 | 1012 | #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8)) |
| 1013 | 1013 | #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8)) |
| 1014 | +#define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2<<8)) |
| 1014 | 1015 | |
| 1015 | 1016 | /* |
| 1016 | 1017 | ** CAPI3REF: Flags For File Open Operations |
| 1017 | 1018 | ** |
| 1018 | 1019 | ** These bit values are intended for use in the |
| | @@ -1264,31 +1265,35 @@ |
| 1264 | 1265 | ** the lock (one of [SQLITE_LOCK_NONE], [SQLITE_LOCK_SHARED], |
| 1265 | 1266 | ** [SQLITE_LOCK_RESERVED], [SQLITE_LOCK_PENDING], or [SQLITE_LOCK_EXCLUSIVE]) |
| 1266 | 1267 | ** into an integer that the pArg argument points to. This capability |
| 1267 | 1268 | ** is used during testing and only needs to be supported when SQLITE_TEST |
| 1268 | 1269 | ** is defined. |
| 1269 | | -** |
| 1270 | +** <ul> |
| 1271 | +** <li>[[SQLITE_FCNTL_SIZE_HINT]] |
| 1270 | 1272 | ** The [SQLITE_FCNTL_SIZE_HINT] opcode is used by SQLite to give the VFS |
| 1271 | 1273 | ** layer a hint of how large the database file will grow to be during the |
| 1272 | 1274 | ** current transaction. This hint is not guaranteed to be accurate but it |
| 1273 | 1275 | ** is often close. The underlying VFS might choose to preallocate database |
| 1274 | 1276 | ** file space based on this hint in order to help writes to the database |
| 1275 | 1277 | ** file run faster. |
| 1276 | 1278 | ** |
| 1279 | +** <li>[[SQLITE_FCNTL_CHUNK_SIZE]] |
| 1277 | 1280 | ** The [SQLITE_FCNTL_CHUNK_SIZE] opcode is used to request that the VFS |
| 1278 | 1281 | ** extends and truncates the database file in chunks of a size specified |
| 1279 | 1282 | ** by the user. The fourth argument to [sqlite3_file_control()] should |
| 1280 | 1283 | ** point to an integer (type int) containing the new chunk-size to use |
| 1281 | 1284 | ** for the nominated database. Allocating database file space in large |
| 1282 | 1285 | ** chunks (say 1MB at a time), may reduce file-system fragmentation and |
| 1283 | 1286 | ** improve performance on some systems. |
| 1284 | 1287 | ** |
| 1288 | +** <li>[[SQLITE_FCNTL_FILE_POINTER]] |
| 1285 | 1289 | ** The [SQLITE_FCNTL_FILE_POINTER] opcode is used to obtain a pointer |
| 1286 | 1290 | ** to the [sqlite3_file] object associated with a particular database |
| 1287 | 1291 | ** connection. See the [sqlite3_file_control()] documentation for |
| 1288 | 1292 | ** additional information. |
| 1289 | 1293 | ** |
| 1294 | +** <li>[[SQLITE_FCNTL_SYNC_OMITTED]] |
| 1290 | 1295 | ** ^(The [SQLITE_FCNTL_SYNC_OMITTED] opcode is generated internally by |
| 1291 | 1296 | ** SQLite and sent to all VFSes in place of a call to the xSync method |
| 1292 | 1297 | ** when the database connection has [PRAGMA synchronous] set to OFF.)^ |
| 1293 | 1298 | ** Some specialized VFSes need this signal in order to operate correctly |
| 1294 | 1299 | ** when [PRAGMA synchronous | PRAGMA synchronous=OFF] is set, but most |
| | @@ -1295,10 +1300,11 @@ |
| 1295 | 1300 | ** VFSes do not need this signal and should silently ignore this opcode. |
| 1296 | 1301 | ** Applications should not call [sqlite3_file_control()] with this |
| 1297 | 1302 | ** opcode as doing so may disrupt the operation of the specialized VFSes |
| 1298 | 1303 | ** that do require it. |
| 1299 | 1304 | ** |
| 1305 | +** <li>[[SQLITE_FCNTL_WIN32_AV_RETRY]] |
| 1300 | 1306 | ** ^The [SQLITE_FCNTL_WIN32_AV_RETRY] opcode is used to configure automatic |
| 1301 | 1307 | ** retry counts and intervals for certain disk I/O operations for the |
| 1302 | 1308 | ** windows [VFS] in order to provide robustness in the presence of |
| 1303 | 1309 | ** anti-virus programs. By default, the windows VFS will retry file read, |
| 1304 | 1310 | ** file write, and file delete operations up to 10 times, with a delay |
| | @@ -1311,10 +1317,11 @@ |
| 1311 | 1317 | ** integer is the delay. If either integer is negative, then the setting |
| 1312 | 1318 | ** is not changed but instead the prior value of that setting is written |
| 1313 | 1319 | ** into the array entry, allowing the current retry settings to be |
| 1314 | 1320 | ** interrogated. The zDbName parameter is ignored. |
| 1315 | 1321 | ** |
| 1322 | +** <li>[[SQLITE_FCNTL_PERSIST_WAL]] |
| 1316 | 1323 | ** ^The [SQLITE_FCNTL_PERSIST_WAL] opcode is used to set or query the |
| 1317 | 1324 | ** persistent [WAL | Write AHead Log] setting. By default, the auxiliary |
| 1318 | 1325 | ** write ahead log and shared memory files used for transaction control |
| 1319 | 1326 | ** are automatically deleted when the latest connection to the database |
| 1320 | 1327 | ** closes. Setting persistent WAL mode causes those files to persist after |
| | @@ -1325,24 +1332,27 @@ |
| 1325 | 1332 | ** [sqlite3_file_control()] for this opcode should be a pointer to an integer. |
| 1326 | 1333 | ** That integer is 0 to disable persistent WAL mode or 1 to enable persistent |
| 1327 | 1334 | ** WAL mode. If the integer is -1, then it is overwritten with the current |
| 1328 | 1335 | ** WAL persistence setting. |
| 1329 | 1336 | ** |
| 1337 | +** <li>[[SQLITE_FCNTL_POWERSAFE_OVERWRITE]] |
| 1330 | 1338 | ** ^The [SQLITE_FCNTL_POWERSAFE_OVERWRITE] opcode is used to set or query the |
| 1331 | 1339 | ** persistent "powersafe-overwrite" or "PSOW" setting. The PSOW setting |
| 1332 | 1340 | ** determines the [SQLITE_IOCAP_POWERSAFE_OVERWRITE] bit of the |
| 1333 | 1341 | ** xDeviceCharacteristics methods. The fourth parameter to |
| 1334 | 1342 | ** [sqlite3_file_control()] for this opcode should be a pointer to an integer. |
| 1335 | 1343 | ** That integer is 0 to disable zero-damage mode or 1 to enable zero-damage |
| 1336 | 1344 | ** mode. If the integer is -1, then it is overwritten with the current |
| 1337 | 1345 | ** zero-damage mode setting. |
| 1338 | 1346 | ** |
| 1347 | +** <li>[[SQLITE_FCNTL_OVERWRITE]] |
| 1339 | 1348 | ** ^The [SQLITE_FCNTL_OVERWRITE] opcode is invoked by SQLite after opening |
| 1340 | 1349 | ** a write transaction to indicate that, unless it is rolled back for some |
| 1341 | 1350 | ** reason, the entire database file will be overwritten by the current |
| 1342 | 1351 | ** transaction. This is used by VACUUM operations. |
| 1343 | 1352 | ** |
| 1353 | +** <li>[[SQLITE_FCNTL_VFSNAME]] |
| 1344 | 1354 | ** ^The [SQLITE_FCNTL_VFSNAME] opcode can be used to obtain the names of |
| 1345 | 1355 | ** all [VFSes] in the VFS stack. The names are of all VFS shims and the |
| 1346 | 1356 | ** final bottom-level VFS are written into memory obtained from |
| 1347 | 1357 | ** [sqlite3_malloc()] and the result is stored in the char* variable |
| 1348 | 1358 | ** that the fourth parameter of [sqlite3_file_control()] points to. |
| | @@ -1349,10 +1359,34 @@ |
| 1349 | 1359 | ** The caller is responsible for freeing the memory when done. As with |
| 1350 | 1360 | ** all file-control actions, there is no guarantee that this will actually |
| 1351 | 1361 | ** do anything. Callers should initialize the char* variable to a NULL |
| 1352 | 1362 | ** pointer in case this file-control is not implemented. This file-control |
| 1353 | 1363 | ** is intended for diagnostic use only. |
| 1364 | +** |
| 1365 | +** <li>[[SQLITE_FCNTL_PRAGMA]] |
| 1366 | +** ^Whenever a [PRAGMA] statement is parsed, an [SQLITE_FCNTL_PRAGMA] |
| 1367 | +** file control is sent to the open [sqlite3_file] object corresponding |
| 1368 | +** to the database file to which the pragma statement refers. ^The argument |
| 1369 | +** to the [SQLITE_FCNTL_PRAGMA] file control is an array of |
| 1370 | +** pointers to strings (char**) in which the second element of the array |
| 1371 | +** is the name of the pragma and the third element is the argument to the |
| 1372 | +** pragma or NULL if the pragma has no argument. ^The handler for an |
| 1373 | +** [SQLITE_FCNTL_PRAGMA] file control can optionally make the first element |
| 1374 | +** of the char** argument point to a string obtained from [sqlite3_mprintf()] |
| 1375 | +** or the equivalent and that string will become the result of the pragma or |
| 1376 | +** the error message if the pragma fails. ^If the |
| 1377 | +** [SQLITE_FCNTL_PRAGMA] file control returns [SQLITE_NOTFOUND], then normal |
| 1378 | +** [PRAGMA] processing continues. ^If the [SQLITE_FCNTL_PRAGMA] |
| 1379 | +** file control returns [SQLITE_OK], then the parser assumes that the |
| 1380 | +** VFS has handled the PRAGMA itself and the parser generates a no-op |
| 1381 | +** prepared statement. ^If the [SQLITE_FCNTL_PRAGMA] file control returns |
| 1382 | +** any result code other than [SQLITE_OK] or [SQLITE_NOTFOUND], that means |
| 1383 | +** that the VFS encountered an error while handling the [PRAGMA] and the |
| 1384 | +** compilation of the PRAGMA fails with an error. ^The [SQLITE_FCNTL_PRAGMA] |
| 1385 | +** file control occurs at the beginning of pragma statement analysis and so |
| 1386 | +** it is able to override built-in [PRAGMA] statements. |
| 1387 | +** </ul> |
| 1354 | 1388 | */ |
| 1355 | 1389 | #define SQLITE_FCNTL_LOCKSTATE 1 |
| 1356 | 1390 | #define SQLITE_GET_LOCKPROXYFILE 2 |
| 1357 | 1391 | #define SQLITE_SET_LOCKPROXYFILE 3 |
| 1358 | 1392 | #define SQLITE_LAST_ERRNO 4 |
| | @@ -1363,10 +1397,11 @@ |
| 1363 | 1397 | #define SQLITE_FCNTL_WIN32_AV_RETRY 9 |
| 1364 | 1398 | #define SQLITE_FCNTL_PERSIST_WAL 10 |
| 1365 | 1399 | #define SQLITE_FCNTL_OVERWRITE 11 |
| 1366 | 1400 | #define SQLITE_FCNTL_VFSNAME 12 |
| 1367 | 1401 | #define SQLITE_FCNTL_POWERSAFE_OVERWRITE 13 |
| 1402 | +#define SQLITE_FCNTL_PRAGMA 14 |
| 1368 | 1403 | |
| 1369 | 1404 | /* |
| 1370 | 1405 | ** CAPI3REF: Mutex Handle |
| 1371 | 1406 | ** |
| 1372 | 1407 | ** The mutex module within SQLite defines [sqlite3_mutex] to be an |
| | @@ -5012,10 +5047,19 @@ |
| 5012 | 5047 | ** will be an absolute pathname, even if the filename used |
| 5013 | 5048 | ** to open the database originally was a URI or relative pathname. |
| 5014 | 5049 | */ |
| 5015 | 5050 | SQLITE_API const char *sqlite3_db_filename(sqlite3 *db, const char *zDbName); |
| 5016 | 5051 | |
| 5052 | +/* |
| 5053 | +** CAPI3REF: Determine if a database is read-only |
| 5054 | +** |
| 5055 | +** ^The sqlite3_db_readonly(D,N) interface returns 1 if the database N |
| 5056 | +** of connection D is read-only, 0 if it is read/write, or -1 if N is not |
| 5057 | +** the name of a database on connection D. |
| 5058 | +*/ |
| 5059 | +SQLITE_API int sqlite3_db_readonly(sqlite3 *db, const char *zDbName); |
| 5060 | + |
| 5017 | 5061 | /* |
| 5018 | 5062 | ** CAPI3REF: Find the next prepared statement |
| 5019 | 5063 | ** |
| 5020 | 5064 | ** ^This interface returns a pointer to the next [prepared statement] after |
| 5021 | 5065 | ** pStmt associated with the [database connection] pDb. ^If pStmt is NULL |
| | @@ -6510,10 +6554,21 @@ |
| 6510 | 6554 | ** [[SQLITE_DBSTATUS_CACHE_MISS]] ^(<dt>SQLITE_DBSTATUS_CACHE_MISS</dt> |
| 6511 | 6555 | ** <dd>This parameter returns the number of pager cache misses that have |
| 6512 | 6556 | ** occurred.)^ ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_MISS |
| 6513 | 6557 | ** is always 0. |
| 6514 | 6558 | ** </dd> |
| 6559 | +** |
| 6560 | +** [[SQLITE_DBSTATUS_CACHE_WRITE]] ^(<dt>SQLITE_DBSTATUS_CACHE_WRITE</dt> |
| 6561 | +** <dd>This parameter returns the number of dirty cache entries that have |
| 6562 | +** been written to disk. Specifically, the number of pages written to the |
| 6563 | +** wal file in wal mode databases, or the number of pages written to the |
| 6564 | +** database file in rollback mode databases. Any pages written as part of |
| 6565 | +** transaction rollback or database recovery operations are not included. |
| 6566 | +** If an IO or other error occurs while writing a page to disk, the effect |
| 6567 | +** on subsequent SQLITE_DBSTATUS_CACHE_WRITE requests is undefined). ^The |
| 6568 | +** highwater mark associated with SQLITE_DBSTATUS_CACHE_WRITE is always 0. |
| 6569 | +** </dd> |
| 6515 | 6570 | ** </dl> |
| 6516 | 6571 | */ |
| 6517 | 6572 | #define SQLITE_DBSTATUS_LOOKASIDE_USED 0 |
| 6518 | 6573 | #define SQLITE_DBSTATUS_CACHE_USED 1 |
| 6519 | 6574 | #define SQLITE_DBSTATUS_SCHEMA_USED 2 |
| | @@ -6521,11 +6576,12 @@ |
| 6521 | 6576 | #define SQLITE_DBSTATUS_LOOKASIDE_HIT 4 |
| 6522 | 6577 | #define SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE 5 |
| 6523 | 6578 | #define SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL 6 |
| 6524 | 6579 | #define SQLITE_DBSTATUS_CACHE_HIT 7 |
| 6525 | 6580 | #define SQLITE_DBSTATUS_CACHE_MISS 8 |
| 6526 | | -#define SQLITE_DBSTATUS_MAX 8 /* Largest defined DBSTATUS */ |
| 6581 | +#define SQLITE_DBSTATUS_CACHE_WRITE 9 |
| 6582 | +#define SQLITE_DBSTATUS_MAX 9 /* Largest defined DBSTATUS */ |
| 6527 | 6583 | |
| 6528 | 6584 | |
| 6529 | 6585 | /* |
| 6530 | 6586 | ** CAPI3REF: Prepared Statement Status |
| 6531 | 6587 | ** |
| | @@ -7137,15 +7193,16 @@ |
| 7137 | 7193 | |
| 7138 | 7194 | |
| 7139 | 7195 | /* |
| 7140 | 7196 | ** CAPI3REF: String Comparison |
| 7141 | 7197 | ** |
| 7142 | | -** ^The [sqlite3_strnicmp()] API allows applications and extensions to |
| 7143 | | -** compare the contents of two buffers containing UTF-8 strings in a |
| 7144 | | -** case-independent fashion, using the same definition of case independence |
| 7145 | | -** that SQLite uses internally when comparing identifiers. |
| 7198 | +** ^The [sqlite3_stricmp()] and [sqlite3_strnicmp()] APIs allow applications |
| 7199 | +** and extensions to compare the contents of two buffers containing UTF-8 |
| 7200 | +** strings in a case-independent fashion, using the same definition of "case |
| 7201 | +** independence" that SQLite uses internally when comparing identifiers. |
| 7146 | 7202 | */ |
| 7203 | +SQLITE_API int sqlite3_stricmp(const char *, const char *); |
| 7147 | 7204 | SQLITE_API int sqlite3_strnicmp(const char *, const char *, int); |
| 7148 | 7205 | |
| 7149 | 7206 | /* |
| 7150 | 7207 | ** CAPI3REF: Error Logging Interface |
| 7151 | 7208 | ** |
| | @@ -8204,11 +8261,11 @@ |
| 8204 | 8261 | SQLITE_PRIVATE int sqlite3BtreeGetAutoVacuum(Btree *); |
| 8205 | 8262 | SQLITE_PRIVATE int sqlite3BtreeBeginTrans(Btree*,int); |
| 8206 | 8263 | SQLITE_PRIVATE int sqlite3BtreeCommitPhaseOne(Btree*, const char *zMaster); |
| 8207 | 8264 | SQLITE_PRIVATE int sqlite3BtreeCommitPhaseTwo(Btree*, int); |
| 8208 | 8265 | SQLITE_PRIVATE int sqlite3BtreeCommit(Btree*); |
| 8209 | | -SQLITE_PRIVATE int sqlite3BtreeRollback(Btree*); |
| 8266 | +SQLITE_PRIVATE int sqlite3BtreeRollback(Btree*,int); |
| 8210 | 8267 | SQLITE_PRIVATE int sqlite3BtreeBeginStmt(Btree*,int); |
| 8211 | 8268 | SQLITE_PRIVATE int sqlite3BtreeCreateTable(Btree*, int*, int flags); |
| 8212 | 8269 | SQLITE_PRIVATE int sqlite3BtreeIsInTrans(Btree*); |
| 8213 | 8270 | SQLITE_PRIVATE int sqlite3BtreeIsInReadTrans(Btree*); |
| 8214 | 8271 | SQLITE_PRIVATE int sqlite3BtreeIsInBackup(Btree*); |
| | @@ -8944,10 +9001,13 @@ |
| 8944 | 9001 | SQLITE_PRIVATE int sqlite3PagerCheckpoint(Pager *pPager, int, int*, int*); |
| 8945 | 9002 | SQLITE_PRIVATE int sqlite3PagerWalSupported(Pager *pPager); |
| 8946 | 9003 | SQLITE_PRIVATE int sqlite3PagerWalCallback(Pager *pPager); |
| 8947 | 9004 | SQLITE_PRIVATE int sqlite3PagerOpenWal(Pager *pPager, int *pisOpen); |
| 8948 | 9005 | SQLITE_PRIVATE int sqlite3PagerCloseWal(Pager *pPager); |
| 9006 | +#ifdef SQLITE_ENABLE_ZIPVFS |
| 9007 | +SQLITE_PRIVATE int sqlite3PagerWalFramesize(Pager *pPager); |
| 9008 | +#endif |
| 8949 | 9009 | |
| 8950 | 9010 | /* Functions used to query pager state and configuration. */ |
| 8951 | 9011 | SQLITE_PRIVATE u8 sqlite3PagerIsreadonly(Pager*); |
| 8952 | 9012 | SQLITE_PRIVATE int sqlite3PagerRefcount(Pager*); |
| 8953 | 9013 | SQLITE_PRIVATE int sqlite3PagerMemUsed(Pager*); |
| | @@ -9871,18 +9931,22 @@ |
| 9871 | 9931 | void (*xDestroy)(void *); |
| 9872 | 9932 | void *pUserData; |
| 9873 | 9933 | }; |
| 9874 | 9934 | |
| 9875 | 9935 | /* |
| 9876 | | -** Possible values for FuncDef.flags |
| 9936 | +** Possible values for FuncDef.flags. Note that the _LENGTH and _TYPEOF |
| 9937 | +** values must correspond to OPFLAG_LENGTHARG and OPFLAG_TYPEOFARG. There |
| 9938 | +** are assert() statements in the code to verify this. |
| 9877 | 9939 | */ |
| 9878 | 9940 | #define SQLITE_FUNC_LIKE 0x01 /* Candidate for the LIKE optimization */ |
| 9879 | 9941 | #define SQLITE_FUNC_CASE 0x02 /* Case-sensitive LIKE-type function */ |
| 9880 | 9942 | #define SQLITE_FUNC_EPHEM 0x04 /* Ephemeral. Delete with VDBE */ |
| 9881 | 9943 | #define SQLITE_FUNC_NEEDCOLL 0x08 /* sqlite3GetFuncCollSeq() might be called */ |
| 9882 | | -#define SQLITE_FUNC_COUNT 0x20 /* Built-in count(*) aggregate */ |
| 9883 | | -#define SQLITE_FUNC_COALESCE 0x40 /* Built-in coalesce() or ifnull() function */ |
| 9944 | +#define SQLITE_FUNC_COUNT 0x10 /* Built-in count(*) aggregate */ |
| 9945 | +#define SQLITE_FUNC_COALESCE 0x20 /* Built-in coalesce() or ifnull() function */ |
| 9946 | +#define SQLITE_FUNC_LENGTH 0x40 /* Built-in length() function */ |
| 9947 | +#define SQLITE_FUNC_TYPEOF 0x80 /* Built-in typeof() function */ |
| 9884 | 9948 | |
| 9885 | 9949 | /* |
| 9886 | 9950 | ** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are |
| 9887 | 9951 | ** used to create the initializers for the FuncDef structures. |
| 9888 | 9952 | ** |
| | @@ -9906,11 +9970,14 @@ |
| 9906 | 9970 | ** available as the function user-data (sqlite3_user_data()). The |
| 9907 | 9971 | ** FuncDef.flags variable is set to the value passed as the flags |
| 9908 | 9972 | ** parameter. |
| 9909 | 9973 | */ |
| 9910 | 9974 | #define FUNCTION(zName, nArg, iArg, bNC, xFunc) \ |
| 9911 | | - {nArg, SQLITE_UTF8, bNC*SQLITE_FUNC_NEEDCOLL, \ |
| 9975 | + {nArg, SQLITE_UTF8, (bNC*SQLITE_FUNC_NEEDCOLL), \ |
| 9976 | + SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0} |
| 9977 | +#define FUNCTION2(zName, nArg, iArg, bNC, xFunc, extraFlags) \ |
| 9978 | + {nArg, SQLITE_UTF8, (bNC*SQLITE_FUNC_NEEDCOLL)|extraFlags, \ |
| 9912 | 9979 | SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0} |
| 9913 | 9980 | #define STR_FUNCTION(zName, nArg, pArg, bNC, xFunc) \ |
| 9914 | 9981 | {nArg, SQLITE_UTF8, bNC*SQLITE_FUNC_NEEDCOLL, \ |
| 9915 | 9982 | pArg, 0, xFunc, 0, 0, #zName, 0, 0} |
| 9916 | 9983 | #define LIKEFUNC(zName, nArg, arg, flags) \ |
| | @@ -10136,11 +10203,11 @@ |
| 10136 | 10203 | u8 tabFlags; /* Mask of TF_* values */ |
| 10137 | 10204 | u8 keyConf; /* What to do in case of uniqueness conflict on iPKey */ |
| 10138 | 10205 | FKey *pFKey; /* Linked list of all foreign keys in this table */ |
| 10139 | 10206 | char *zColAff; /* String defining the affinity of each column */ |
| 10140 | 10207 | #ifndef SQLITE_OMIT_CHECK |
| 10141 | | - Expr *pCheck; /* The AND of all CHECK constraints */ |
| 10208 | + ExprList *pCheck; /* All CHECK constraints */ |
| 10142 | 10209 | #endif |
| 10143 | 10210 | #ifndef SQLITE_OMIT_ALTERTABLE |
| 10144 | 10211 | int addColOffset; /* Offset in CREATE TABLE stmt to add a new column */ |
| 10145 | 10212 | #endif |
| 10146 | 10213 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| | @@ -10529,10 +10596,11 @@ |
| 10529 | 10596 | ** TK_VARIABLE: variable number (always >= 1). */ |
| 10530 | 10597 | i16 iAgg; /* Which entry in pAggInfo->aCol[] or ->aFunc[] */ |
| 10531 | 10598 | i16 iRightJoinTable; /* If EP_FromJoin, the right table of the join */ |
| 10532 | 10599 | u8 flags2; /* Second set of flags. EP2_... */ |
| 10533 | 10600 | u8 op2; /* If a TK_REGISTER, the original value of Expr.op */ |
| 10601 | + /* If TK_COLUMN, the value of p5 for OP_Column */ |
| 10534 | 10602 | AggInfo *pAggInfo; /* Used by TK_AGG_COLUMN and TK_AGG_FUNCTION */ |
| 10535 | 10603 | Table *pTab; /* Table for TK_COLUMN expressions. */ |
| 10536 | 10604 | #if SQLITE_MAX_EXPR_DEPTH>0 |
| 10537 | 10605 | int nHeight; /* Height of the tree headed by this node */ |
| 10538 | 10606 | #endif |
| | @@ -10551,11 +10619,11 @@ |
| 10551 | 10619 | #define EP_InfixFunc 0x0080 /* True for an infix function: LIKE, GLOB, etc */ |
| 10552 | 10620 | #define EP_ExpCollate 0x0100 /* Collating sequence specified explicitly */ |
| 10553 | 10621 | #define EP_FixedDest 0x0200 /* Result needed in a specific register */ |
| 10554 | 10622 | #define EP_IntValue 0x0400 /* Integer value contained in u.iValue */ |
| 10555 | 10623 | #define EP_xIsSelect 0x0800 /* x.pSelect is valid (otherwise x.pList is) */ |
| 10556 | | -#define EP_Hint 0x1000 /* Optimizer hint. Not required for correctness */ |
| 10624 | +#define EP_Hint 0x1000 /* Not used */ |
| 10557 | 10625 | #define EP_Reduced 0x2000 /* Expr struct is EXPR_REDUCEDSIZE bytes only */ |
| 10558 | 10626 | #define EP_TokenOnly 0x4000 /* Expr struct is EXPR_TOKENONLYSIZE bytes only */ |
| 10559 | 10627 | #define EP_Static 0x8000 /* Held in memory not obtained from malloc() */ |
| 10560 | 10628 | |
| 10561 | 10629 | /* |
| | @@ -11070,10 +11138,11 @@ |
| 11070 | 11138 | int cookieGoto; /* Address of OP_Goto to cookie verifier subroutine */ |
| 11071 | 11139 | int cookieValue[SQLITE_MAX_ATTACHED+2]; /* Values of cookies to verify */ |
| 11072 | 11140 | int regRowid; /* Register holding rowid of CREATE TABLE entry */ |
| 11073 | 11141 | int regRoot; /* Register holding root page number for new objects */ |
| 11074 | 11142 | int nMaxArg; /* Max args passed to user function by sub-program */ |
| 11143 | + Token constraintName;/* Name of the constraint currently being parsed */ |
| 11075 | 11144 | #ifndef SQLITE_OMIT_SHARED_CACHE |
| 11076 | 11145 | int nTableLock; /* Number of locks in aTableLock */ |
| 11077 | 11146 | TableLock *aTableLock; /* Required table locks for shared-cache mode */ |
| 11078 | 11147 | #endif |
| 11079 | 11148 | AutoincInfo *pAinc; /* Information about AUTOINCREMENT counters */ |
| | @@ -11138,18 +11207,20 @@ |
| 11138 | 11207 | const char *zAuthContext; /* Put saved Parse.zAuthContext here */ |
| 11139 | 11208 | Parse *pParse; /* The Parse structure */ |
| 11140 | 11209 | }; |
| 11141 | 11210 | |
| 11142 | 11211 | /* |
| 11143 | | -** Bitfield flags for P5 value in OP_Insert and OP_Delete |
| 11212 | +** Bitfield flags for P5 value in various opcodes. |
| 11144 | 11213 | */ |
| 11145 | 11214 | #define OPFLAG_NCHANGE 0x01 /* Set to update db->nChange */ |
| 11146 | 11215 | #define OPFLAG_LASTROWID 0x02 /* Set to update db->lastRowid */ |
| 11147 | 11216 | #define OPFLAG_ISUPDATE 0x04 /* This OP_Insert is an sql UPDATE */ |
| 11148 | 11217 | #define OPFLAG_APPEND 0x08 /* This is likely to be an append */ |
| 11149 | 11218 | #define OPFLAG_USESEEKRESULT 0x10 /* Try to avoid a seek in BtreeInsert() */ |
| 11150 | 11219 | #define OPFLAG_CLEARCACHE 0x20 /* Clear pseudo-table cache in OP_Column */ |
| 11220 | +#define OPFLAG_LENGTHARG 0x40 /* OP_Column only used for length() */ |
| 11221 | +#define OPFLAG_TYPEOFARG 0x80 /* OP_Column only used for typeof() */ |
| 11151 | 11222 | |
| 11152 | 11223 | /* |
| 11153 | 11224 | * Each trigger present in the database schema is stored as an instance of |
| 11154 | 11225 | * struct Trigger. |
| 11155 | 11226 | * |
| | @@ -11415,11 +11486,11 @@ |
| 11415 | 11486 | #endif |
| 11416 | 11487 | |
| 11417 | 11488 | /* |
| 11418 | 11489 | ** Internal function prototypes |
| 11419 | 11490 | */ |
| 11420 | | -SQLITE_PRIVATE int sqlite3StrICmp(const char *, const char *); |
| 11491 | +#define sqlite3StrICmp sqlite3_stricmp |
| 11421 | 11492 | SQLITE_PRIVATE int sqlite3Strlen30(const char*); |
| 11422 | 11493 | #define sqlite3StrNICmp sqlite3_strnicmp |
| 11423 | 11494 | |
| 11424 | 11495 | SQLITE_PRIVATE int sqlite3MallocInit(void); |
| 11425 | 11496 | SQLITE_PRIVATE void sqlite3MallocEnd(void); |
| | @@ -11563,10 +11634,11 @@ |
| 11563 | 11634 | SQLITE_PRIVATE void sqlite3AddDefaultValue(Parse*,ExprSpan*); |
| 11564 | 11635 | SQLITE_PRIVATE void sqlite3AddCollateType(Parse*, Token*); |
| 11565 | 11636 | SQLITE_PRIVATE void sqlite3EndTable(Parse*,Token*,Token*,Select*); |
| 11566 | 11637 | SQLITE_PRIVATE int sqlite3ParseUri(const char*,const char*,unsigned int*, |
| 11567 | 11638 | sqlite3_vfs**,char**,char **); |
| 11639 | +SQLITE_PRIVATE Btree *sqlite3DbNameToBtree(sqlite3*,const char*); |
| 11568 | 11640 | SQLITE_PRIVATE int sqlite3CodeOnce(Parse *); |
| 11569 | 11641 | |
| 11570 | 11642 | SQLITE_PRIVATE Bitvec *sqlite3BitvecCreate(u32); |
| 11571 | 11643 | SQLITE_PRIVATE int sqlite3BitvecTest(Bitvec*, u32); |
| 11572 | 11644 | SQLITE_PRIVATE int sqlite3BitvecSet(Bitvec*, u32); |
| | @@ -11628,11 +11700,11 @@ |
| 11628 | 11700 | #endif |
| 11629 | 11701 | SQLITE_PRIVATE void sqlite3DeleteFrom(Parse*, SrcList*, Expr*); |
| 11630 | 11702 | SQLITE_PRIVATE void sqlite3Update(Parse*, SrcList*, ExprList*, Expr*, int); |
| 11631 | 11703 | SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin(Parse*, SrcList*, Expr*, ExprList**,ExprList*,u16); |
| 11632 | 11704 | SQLITE_PRIVATE void sqlite3WhereEnd(WhereInfo*); |
| 11633 | | -SQLITE_PRIVATE int sqlite3ExprCodeGetColumn(Parse*, Table*, int, int, int); |
| 11705 | +SQLITE_PRIVATE int sqlite3ExprCodeGetColumn(Parse*, Table*, int, int, int, u8); |
| 11634 | 11706 | SQLITE_PRIVATE void sqlite3ExprCodeGetColumnOfTable(Vdbe*, Table*, int, int, int); |
| 11635 | 11707 | SQLITE_PRIVATE void sqlite3ExprCodeMove(Parse*, int, int, int); |
| 11636 | 11708 | SQLITE_PRIVATE void sqlite3ExprCodeCopy(Parse*, int, int, int); |
| 11637 | 11709 | SQLITE_PRIVATE void sqlite3ExprCacheStore(Parse*, int, int, int); |
| 11638 | 11710 | SQLITE_PRIVATE void sqlite3ExprCachePush(Parse*); |
| | @@ -11662,11 +11734,11 @@ |
| 11662 | 11734 | SQLITE_PRIVATE void sqlite3ExprAnalyzeAggList(NameContext*,ExprList*); |
| 11663 | 11735 | SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse*); |
| 11664 | 11736 | SQLITE_PRIVATE void sqlite3PrngSaveState(void); |
| 11665 | 11737 | SQLITE_PRIVATE void sqlite3PrngRestoreState(void); |
| 11666 | 11738 | SQLITE_PRIVATE void sqlite3PrngResetState(void); |
| 11667 | | -SQLITE_PRIVATE void sqlite3RollbackAll(sqlite3*); |
| 11739 | +SQLITE_PRIVATE void sqlite3RollbackAll(sqlite3*,int); |
| 11668 | 11740 | SQLITE_PRIVATE void sqlite3CodeVerifySchema(Parse*, int); |
| 11669 | 11741 | SQLITE_PRIVATE void sqlite3CodeVerifyNamedSchema(Parse*, const char *zDb); |
| 11670 | 11742 | SQLITE_PRIVATE void sqlite3BeginTransaction(Parse*, int); |
| 11671 | 11743 | SQLITE_PRIVATE void sqlite3CommitTransaction(Parse*); |
| 11672 | 11744 | SQLITE_PRIVATE void sqlite3RollbackTransaction(Parse*); |
| | @@ -13460,14 +13532,16 @@ |
| 13460 | 13532 | ** Set *pCurrent to the total cache hits or misses encountered by all |
| 13461 | 13533 | ** pagers the database handle is connected to. *pHighwater is always set |
| 13462 | 13534 | ** to zero. |
| 13463 | 13535 | */ |
| 13464 | 13536 | case SQLITE_DBSTATUS_CACHE_HIT: |
| 13465 | | - case SQLITE_DBSTATUS_CACHE_MISS: { |
| 13537 | + case SQLITE_DBSTATUS_CACHE_MISS: |
| 13538 | + case SQLITE_DBSTATUS_CACHE_WRITE:{ |
| 13466 | 13539 | int i; |
| 13467 | 13540 | int nRet = 0; |
| 13468 | 13541 | assert( SQLITE_DBSTATUS_CACHE_MISS==SQLITE_DBSTATUS_CACHE_HIT+1 ); |
| 13542 | + assert( SQLITE_DBSTATUS_CACHE_WRITE==SQLITE_DBSTATUS_CACHE_HIT+2 ); |
| 13469 | 13543 | |
| 13470 | 13544 | for(i=0; i<db->nDb; i++){ |
| 13471 | 13545 | if( db->aDb[i].pBt ){ |
| 13472 | 13546 | Pager *pPager = sqlite3BtreePager(db->aDb[i].pBt); |
| 13473 | 13547 | sqlite3PagerCacheStat(pPager, op, resetFlag, &nRet); |
| | @@ -21210,17 +21284,17 @@ |
| 21210 | 21284 | |
| 21211 | 21285 | /* |
| 21212 | 21286 | ** Some systems have stricmp(). Others have strcasecmp(). Because |
| 21213 | 21287 | ** there is no consistency, we will define our own. |
| 21214 | 21288 | ** |
| 21215 | | -** IMPLEMENTATION-OF: R-20522-24639 The sqlite3_strnicmp() API allows |
| 21216 | | -** applications and extensions to compare the contents of two buffers |
| 21217 | | -** containing UTF-8 strings in a case-independent fashion, using the same |
| 21218 | | -** definition of case independence that SQLite uses internally when |
| 21219 | | -** comparing identifiers. |
| 21289 | +** IMPLEMENTATION-OF: R-30243-02494 The sqlite3_stricmp() and |
| 21290 | +** sqlite3_strnicmp() APIs allow applications and extensions to compare |
| 21291 | +** the contents of two buffers containing UTF-8 strings in a |
| 21292 | +** case-independent fashion, using the same definition of "case |
| 21293 | +** independence" that SQLite uses internally when comparing identifiers. |
| 21220 | 21294 | */ |
| 21221 | | -SQLITE_PRIVATE int sqlite3StrICmp(const char *zLeft, const char *zRight){ |
| 21295 | +SQLITE_API int sqlite3_stricmp(const char *zLeft, const char *zRight){ |
| 21222 | 21296 | register unsigned char *a, *b; |
| 21223 | 21297 | a = (unsigned char *)zLeft; |
| 21224 | 21298 | b = (unsigned char *)zRight; |
| 21225 | 21299 | while( *a!=0 && UpperToLower[*a]==UpperToLower[*b]){ a++; b++; } |
| 21226 | 21300 | return UpperToLower[*a] - UpperToLower[*b]; |
| | @@ -25494,11 +25568,11 @@ |
| 25494 | 25568 | ** recover the hot journals. |
| 25495 | 25569 | */ |
| 25496 | 25570 | static int robust_open(const char *z, int f, mode_t m){ |
| 25497 | 25571 | int rc; |
| 25498 | 25572 | mode_t m2; |
| 25499 | | - mode_t origM; |
| 25573 | + mode_t origM = 0; |
| 25500 | 25574 | if( m==0 ){ |
| 25501 | 25575 | m2 = SQLITE_DEFAULT_FILE_PERMISSIONS; |
| 25502 | 25576 | }else{ |
| 25503 | 25577 | m2 = m; |
| 25504 | 25578 | origM = osUmask(0); |
| | @@ -33678,10 +33752,13 @@ |
| 33678 | 33752 | } |
| 33679 | 33753 | sqlite3_free(pFile->zDeleteOnClose); |
| 33680 | 33754 | } |
| 33681 | 33755 | #endif |
| 33682 | 33756 | OSTRACE(("CLOSE %d %s\n", pFile->h, rc ? "ok" : "failed")); |
| 33757 | + if( rc ){ |
| 33758 | + pFile->h = NULL; |
| 33759 | + } |
| 33683 | 33760 | OpenCounter(-1); |
| 33684 | 33761 | return rc ? SQLITE_OK |
| 33685 | 33762 | : winLogError(SQLITE_IOERR_CLOSE, osGetLastError(), |
| 33686 | 33763 | "winClose", pFile->zPath); |
| 33687 | 33764 | } |
| | @@ -33695,22 +33772,33 @@ |
| 33695 | 33772 | sqlite3_file *id, /* File to read from */ |
| 33696 | 33773 | void *pBuf, /* Write content into this buffer */ |
| 33697 | 33774 | int amt, /* Number of bytes to read */ |
| 33698 | 33775 | sqlite3_int64 offset /* Begin reading at this offset */ |
| 33699 | 33776 | ){ |
| 33777 | +#if !SQLITE_OS_WINCE |
| 33778 | + OVERLAPPED overlapped; /* The offset for ReadFile. */ |
| 33779 | +#endif |
| 33700 | 33780 | winFile *pFile = (winFile*)id; /* file handle */ |
| 33701 | 33781 | DWORD nRead; /* Number of bytes actually read from file */ |
| 33702 | 33782 | int nRetry = 0; /* Number of retrys */ |
| 33703 | 33783 | |
| 33704 | 33784 | assert( id!=0 ); |
| 33705 | 33785 | SimulateIOError(return SQLITE_IOERR_READ); |
| 33706 | 33786 | OSTRACE(("READ %d lock=%d\n", pFile->h, pFile->locktype)); |
| 33707 | 33787 | |
| 33788 | +#if SQLITE_OS_WINCE |
| 33708 | 33789 | if( seekWinFile(pFile, offset) ){ |
| 33709 | 33790 | return SQLITE_FULL; |
| 33710 | 33791 | } |
| 33711 | 33792 | while( !osReadFile(pFile->h, pBuf, amt, &nRead, 0) ){ |
| 33793 | +#else |
| 33794 | + memset(&overlapped, 0, sizeof(OVERLAPPED)); |
| 33795 | + overlapped.Offset = (LONG)(offset & 0xffffffff); |
| 33796 | + overlapped.OffsetHigh = (LONG)((offset>>32) & 0x7fffffff); |
| 33797 | + while( !osReadFile(pFile->h, pBuf, amt, &nRead, &overlapped) && |
| 33798 | + osGetLastError()!=ERROR_HANDLE_EOF ){ |
| 33799 | +#endif |
| 33712 | 33800 | DWORD lastErrno; |
| 33713 | 33801 | if( retryIoerr(&nRetry, &lastErrno) ) continue; |
| 33714 | 33802 | pFile->lastErrno = lastErrno; |
| 33715 | 33803 | return winLogError(SQLITE_IOERR_READ, pFile->lastErrno, |
| 33716 | 33804 | "winRead", pFile->zPath); |
| | @@ -33733,11 +33821,11 @@ |
| 33733 | 33821 | sqlite3_file *id, /* File to write into */ |
| 33734 | 33822 | const void *pBuf, /* The bytes to be written */ |
| 33735 | 33823 | int amt, /* Number of bytes to write */ |
| 33736 | 33824 | sqlite3_int64 offset /* Offset into the file to begin writing at */ |
| 33737 | 33825 | ){ |
| 33738 | | - int rc; /* True if error has occured, else false */ |
| 33826 | + int rc = 0; /* True if error has occured, else false */ |
| 33739 | 33827 | winFile *pFile = (winFile*)id; /* File handle */ |
| 33740 | 33828 | int nRetry = 0; /* Number of retries */ |
| 33741 | 33829 | |
| 33742 | 33830 | assert( amt>0 ); |
| 33743 | 33831 | assert( pFile ); |
| | @@ -33744,23 +33832,48 @@ |
| 33744 | 33832 | SimulateIOError(return SQLITE_IOERR_WRITE); |
| 33745 | 33833 | SimulateDiskfullError(return SQLITE_FULL); |
| 33746 | 33834 | |
| 33747 | 33835 | OSTRACE(("WRITE %d lock=%d\n", pFile->h, pFile->locktype)); |
| 33748 | 33836 | |
| 33837 | +#if SQLITE_OS_WINCE |
| 33749 | 33838 | rc = seekWinFile(pFile, offset); |
| 33750 | 33839 | if( rc==0 ){ |
| 33840 | +#else |
| 33841 | + { |
| 33842 | +#endif |
| 33843 | +#if !SQLITE_OS_WINCE |
| 33844 | + OVERLAPPED overlapped; /* The offset for WriteFile. */ |
| 33845 | +#endif |
| 33751 | 33846 | u8 *aRem = (u8 *)pBuf; /* Data yet to be written */ |
| 33752 | 33847 | int nRem = amt; /* Number of bytes yet to be written */ |
| 33753 | 33848 | DWORD nWrite; /* Bytes written by each WriteFile() call */ |
| 33754 | 33849 | DWORD lastErrno = NO_ERROR; /* Value returned by GetLastError() */ |
| 33850 | + |
| 33851 | +#if !SQLITE_OS_WINCE |
| 33852 | + memset(&overlapped, 0, sizeof(OVERLAPPED)); |
| 33853 | + overlapped.Offset = (LONG)(offset & 0xffffffff); |
| 33854 | + overlapped.OffsetHigh = (LONG)((offset>>32) & 0x7fffffff); |
| 33855 | +#endif |
| 33755 | 33856 | |
| 33756 | 33857 | while( nRem>0 ){ |
| 33858 | +#if SQLITE_OS_WINCE |
| 33757 | 33859 | if( !osWriteFile(pFile->h, aRem, nRem, &nWrite, 0) ){ |
| 33860 | +#else |
| 33861 | + if( !osWriteFile(pFile->h, aRem, nRem, &nWrite, &overlapped) ){ |
| 33862 | +#endif |
| 33758 | 33863 | if( retryIoerr(&nRetry, &lastErrno) ) continue; |
| 33759 | 33864 | break; |
| 33760 | 33865 | } |
| 33761 | | - if( nWrite<=0 ) break; |
| 33866 | + if( nWrite<=0 ){ |
| 33867 | + lastErrno = osGetLastError(); |
| 33868 | + break; |
| 33869 | + } |
| 33870 | +#if !SQLITE_OS_WINCE |
| 33871 | + offset += nWrite; |
| 33872 | + overlapped.Offset = (LONG)(offset & 0xffffffff); |
| 33873 | + overlapped.OffsetHigh = (LONG)((offset>>32) & 0x7fffffff); |
| 33874 | +#endif |
| 33762 | 33875 | aRem += nWrite; |
| 33763 | 33876 | nRem -= nWrite; |
| 33764 | 33877 | } |
| 33765 | 33878 | if( nRem>0 ){ |
| 33766 | 33879 | pFile->lastErrno = lastErrno; |
| | @@ -38302,10 +38415,11 @@ |
| 38302 | 38415 | # define sqlite3WalFrames(u,v,w,x,y,z) 0 |
| 38303 | 38416 | # define sqlite3WalCheckpoint(r,s,t,u,v,w,x,y,z) 0 |
| 38304 | 38417 | # define sqlite3WalCallback(z) 0 |
| 38305 | 38418 | # define sqlite3WalExclusiveMode(y,z) 0 |
| 38306 | 38419 | # define sqlite3WalHeapMemory(z) 0 |
| 38420 | +# define sqlite3WalFramesize(z) 0 |
| 38307 | 38421 | #else |
| 38308 | 38422 | |
| 38309 | 38423 | #define WAL_SAVEPOINT_NDATA 4 |
| 38310 | 38424 | |
| 38311 | 38425 | /* Connection to a write-ahead log (WAL) file. |
| | @@ -38382,10 +38496,17 @@ |
| 38382 | 38496 | /* Return true if the argument is non-NULL and the WAL module is using |
| 38383 | 38497 | ** heap-memory for the wal-index. Otherwise, if the argument is NULL or the |
| 38384 | 38498 | ** WAL module is using shared-memory, return false. |
| 38385 | 38499 | */ |
| 38386 | 38500 | SQLITE_PRIVATE int sqlite3WalHeapMemory(Wal *pWal); |
| 38501 | + |
| 38502 | +#ifdef SQLITE_ENABLE_ZIPVFS |
| 38503 | +/* If the WAL file is not empty, return the number of bytes of content |
| 38504 | +** stored in each frame (i.e. the db page-size when the WAL was created). |
| 38505 | +*/ |
| 38506 | +SQLITE_PRIVATE int sqlite3WalFramesize(Wal *pWal); |
| 38507 | +#endif |
| 38387 | 38508 | |
| 38388 | 38509 | #endif /* ifndef SQLITE_OMIT_WAL */ |
| 38389 | 38510 | #endif /* _WAL_H_ */ |
| 38390 | 38511 | |
| 38391 | 38512 | /************** End of wal.h *************************************************/ |
| | @@ -39037,13 +39158,13 @@ |
| 39037 | 39158 | i64 journalSizeLimit; /* Size limit for persistent journal files */ |
| 39038 | 39159 | char *zFilename; /* Name of the database file */ |
| 39039 | 39160 | char *zJournal; /* Name of the journal file */ |
| 39040 | 39161 | int (*xBusyHandler)(void*); /* Function to call when busy */ |
| 39041 | 39162 | void *pBusyHandlerArg; /* Context argument for xBusyHandler */ |
| 39042 | | - int nHit, nMiss; /* Total cache hits and misses */ |
| 39163 | + int aStat[3]; /* Total cache hits, misses and writes */ |
| 39043 | 39164 | #ifdef SQLITE_TEST |
| 39044 | | - int nRead, nWrite; /* Database pages read/written */ |
| 39165 | + int nRead; /* Database pages read */ |
| 39045 | 39166 | #endif |
| 39046 | 39167 | void (*xReiniter)(DbPage*); /* Call this routine when reloading pages */ |
| 39047 | 39168 | #ifdef SQLITE_HAS_CODEC |
| 39048 | 39169 | void *(*xCodec)(void*,void*,Pgno,int); /* Routine for en/decoding data */ |
| 39049 | 39170 | void (*xCodecSizeChng)(void*,int,int); /* Notify of page size changes */ |
| | @@ -39056,10 +39177,19 @@ |
| 39056 | 39177 | Wal *pWal; /* Write-ahead log used by "journal_mode=wal" */ |
| 39057 | 39178 | char *zWal; /* File name for write-ahead log */ |
| 39058 | 39179 | #endif |
| 39059 | 39180 | }; |
| 39060 | 39181 | |
| 39182 | +/* |
| 39183 | +** Indexes for use with Pager.aStat[]. The Pager.aStat[] array contains |
| 39184 | +** the values accessed by passing SQLITE_DBSTATUS_CACHE_HIT, CACHE_MISS |
| 39185 | +** or CACHE_WRITE to sqlite3_db_status(). |
| 39186 | +*/ |
| 39187 | +#define PAGER_STAT_HIT 0 |
| 39188 | +#define PAGER_STAT_MISS 1 |
| 39189 | +#define PAGER_STAT_WRITE 2 |
| 39190 | + |
| 39061 | 39191 | /* |
| 39062 | 39192 | ** The following global variables hold counters used for |
| 39063 | 39193 | ** testing purposes only. These variables do not exist in |
| 39064 | 39194 | ** a non-testing build. These variables are not thread-safe. |
| 39065 | 39195 | */ |
| | @@ -41338,10 +41468,11 @@ |
| 41338 | 41468 | PgHdr *pList, /* List of frames to log */ |
| 41339 | 41469 | Pgno nTruncate, /* Database size after this commit */ |
| 41340 | 41470 | int isCommit /* True if this is a commit */ |
| 41341 | 41471 | ){ |
| 41342 | 41472 | int rc; /* Return code */ |
| 41473 | + int nList; /* Number of pages in pList */ |
| 41343 | 41474 | #if defined(SQLITE_DEBUG) || defined(SQLITE_CHECK_PAGES) |
| 41344 | 41475 | PgHdr *p; /* For looping over pages */ |
| 41345 | 41476 | #endif |
| 41346 | 41477 | |
| 41347 | 41478 | assert( pPager->pWal ); |
| | @@ -41351,22 +41482,30 @@ |
| 41351 | 41482 | for(p=pList; p && p->pDirty; p=p->pDirty){ |
| 41352 | 41483 | assert( p->pgno < p->pDirty->pgno ); |
| 41353 | 41484 | } |
| 41354 | 41485 | #endif |
| 41355 | 41486 | |
| 41487 | + assert( pList->pDirty==0 || isCommit ); |
| 41356 | 41488 | if( isCommit ){ |
| 41357 | 41489 | /* If a WAL transaction is being committed, there is no point in writing |
| 41358 | 41490 | ** any pages with page numbers greater than nTruncate into the WAL file. |
| 41359 | 41491 | ** They will never be read by any client. So remove them from the pDirty |
| 41360 | 41492 | ** list here. */ |
| 41361 | 41493 | PgHdr *p; |
| 41362 | 41494 | PgHdr **ppNext = &pList; |
| 41495 | + nList = 0; |
| 41363 | 41496 | for(p=pList; (*ppNext = p); p=p->pDirty){ |
| 41364 | | - if( p->pgno<=nTruncate ) ppNext = &p->pDirty; |
| 41497 | + if( p->pgno<=nTruncate ){ |
| 41498 | + ppNext = &p->pDirty; |
| 41499 | + nList++; |
| 41500 | + } |
| 41365 | 41501 | } |
| 41366 | 41502 | assert( pList ); |
| 41503 | + }else{ |
| 41504 | + nList = 1; |
| 41367 | 41505 | } |
| 41506 | + pPager->aStat[PAGER_STAT_WRITE] += nList; |
| 41368 | 41507 | |
| 41369 | 41508 | if( pList->pgno==1 ) pager_write_changecounter(pList); |
| 41370 | 41509 | rc = sqlite3WalFrames(pPager->pWal, |
| 41371 | 41510 | pPager->pageSize, pList, nTruncate, isCommit, pPager->walSyncFlags |
| 41372 | 41511 | ); |
| | @@ -42430,19 +42569,19 @@ |
| 42430 | 42569 | memcpy(&pPager->dbFileVers, &pData[24], sizeof(pPager->dbFileVers)); |
| 42431 | 42570 | } |
| 42432 | 42571 | if( pgno>pPager->dbFileSize ){ |
| 42433 | 42572 | pPager->dbFileSize = pgno; |
| 42434 | 42573 | } |
| 42574 | + pPager->aStat[PAGER_STAT_WRITE]++; |
| 42435 | 42575 | |
| 42436 | 42576 | /* Update any backup objects copying the contents of this pager. */ |
| 42437 | 42577 | sqlite3BackupUpdate(pPager->pBackup, pgno, (u8*)pList->pData); |
| 42438 | 42578 | |
| 42439 | 42579 | PAGERTRACE(("STORE %d page %d hash(%08x)\n", |
| 42440 | 42580 | PAGERID(pPager), pgno, pager_pagehash(pList))); |
| 42441 | 42581 | IOTRACE(("PGOUT %p %d\n", pPager, pgno)); |
| 42442 | 42582 | PAGER_INCR(sqlite3_pager_writedb_count); |
| 42443 | | - PAGER_INCR(pPager->nWrite); |
| 42444 | 42583 | }else{ |
| 42445 | 42584 | PAGERTRACE(("NOSTORE %d page %d\n", PAGERID(pPager), pgno)); |
| 42446 | 42585 | } |
| 42447 | 42586 | pager_set_pagehash(pList); |
| 42448 | 42587 | pList = pList->pDirty; |
| | @@ -43396,11 +43535,11 @@ |
| 43396 | 43535 | |
| 43397 | 43536 | if( (*ppPage)->pPager && !noContent ){ |
| 43398 | 43537 | /* In this case the pcache already contains an initialized copy of |
| 43399 | 43538 | ** the page. Return without further ado. */ |
| 43400 | 43539 | assert( pgno<=PAGER_MAX_PGNO && pgno!=PAGER_MJ_PGNO(pPager) ); |
| 43401 | | - pPager->nHit++; |
| 43540 | + pPager->aStat[PAGER_STAT_HIT]++; |
| 43402 | 43541 | return SQLITE_OK; |
| 43403 | 43542 | |
| 43404 | 43543 | }else{ |
| 43405 | 43544 | /* The pager cache has created a new page. Its content needs to |
| 43406 | 43545 | ** be initialized. */ |
| | @@ -43438,11 +43577,11 @@ |
| 43438 | 43577 | } |
| 43439 | 43578 | memset(pPg->pData, 0, pPager->pageSize); |
| 43440 | 43579 | IOTRACE(("ZERO %p %d\n", pPager, pgno)); |
| 43441 | 43580 | }else{ |
| 43442 | 43581 | assert( pPg->pPager==pPager ); |
| 43443 | | - pPager->nMiss++; |
| 43582 | + pPager->aStat[PAGER_STAT_MISS]++; |
| 43444 | 43583 | rc = readDbPage(pPg); |
| 43445 | 43584 | if( rc!=SQLITE_OK ){ |
| 43446 | 43585 | goto pager_acquire_err; |
| 43447 | 43586 | } |
| 43448 | 43587 | } |
| | @@ -44023,10 +44162,11 @@ |
| 44023 | 44162 | const void *zBuf; |
| 44024 | 44163 | assert( pPager->dbFileSize>0 ); |
| 44025 | 44164 | CODEC2(pPager, pPgHdr->pData, 1, 6, rc=SQLITE_NOMEM, zBuf); |
| 44026 | 44165 | if( rc==SQLITE_OK ){ |
| 44027 | 44166 | rc = sqlite3OsWrite(pPager->fd, zBuf, pPager->pageSize, 0); |
| 44167 | + pPager->aStat[PAGER_STAT_WRITE]++; |
| 44028 | 44168 | } |
| 44029 | 44169 | if( rc==SQLITE_OK ){ |
| 44030 | 44170 | pPager->changeCountDone = 1; |
| 44031 | 44171 | } |
| 44032 | 44172 | }else{ |
| | @@ -44466,15 +44606,15 @@ |
| 44466 | 44606 | a[1] = sqlite3PcachePagecount(pPager->pPCache); |
| 44467 | 44607 | a[2] = sqlite3PcacheGetCachesize(pPager->pPCache); |
| 44468 | 44608 | a[3] = pPager->eState==PAGER_OPEN ? -1 : (int) pPager->dbSize; |
| 44469 | 44609 | a[4] = pPager->eState; |
| 44470 | 44610 | a[5] = pPager->errCode; |
| 44471 | | - a[6] = pPager->nHit; |
| 44472 | | - a[7] = pPager->nMiss; |
| 44611 | + a[6] = pPager->aStat[PAGER_STAT_HIT]; |
| 44612 | + a[7] = pPager->aStat[PAGER_STAT_MISS]; |
| 44473 | 44613 | a[8] = 0; /* Used to be pPager->nOvfl */ |
| 44474 | 44614 | a[9] = pPager->nRead; |
| 44475 | | - a[10] = pPager->nWrite; |
| 44615 | + a[10] = pPager->aStat[PAGER_STAT_WRITE]; |
| 44476 | 44616 | return a; |
| 44477 | 44617 | } |
| 44478 | 44618 | #endif |
| 44479 | 44619 | |
| 44480 | 44620 | /* |
| | @@ -44483,24 +44623,23 @@ |
| 44483 | 44623 | ** current cache hit or miss count, according to the value of eStat. If the |
| 44484 | 44624 | ** reset parameter is non-zero, the cache hit or miss count is zeroed before |
| 44485 | 44625 | ** returning. |
| 44486 | 44626 | */ |
| 44487 | 44627 | SQLITE_PRIVATE void sqlite3PagerCacheStat(Pager *pPager, int eStat, int reset, int *pnVal){ |
| 44488 | | - int *piStat; |
| 44489 | 44628 | |
| 44490 | 44629 | assert( eStat==SQLITE_DBSTATUS_CACHE_HIT |
| 44491 | 44630 | || eStat==SQLITE_DBSTATUS_CACHE_MISS |
| 44631 | + || eStat==SQLITE_DBSTATUS_CACHE_WRITE |
| 44492 | 44632 | ); |
| 44493 | | - if( eStat==SQLITE_DBSTATUS_CACHE_HIT ){ |
| 44494 | | - piStat = &pPager->nHit; |
| 44495 | | - }else{ |
| 44496 | | - piStat = &pPager->nMiss; |
| 44497 | | - } |
| 44498 | 44633 | |
| 44499 | | - *pnVal += *piStat; |
| 44634 | + assert( SQLITE_DBSTATUS_CACHE_HIT+1==SQLITE_DBSTATUS_CACHE_MISS ); |
| 44635 | + assert( SQLITE_DBSTATUS_CACHE_HIT+2==SQLITE_DBSTATUS_CACHE_WRITE ); |
| 44636 | + assert( PAGER_STAT_HIT==0 && PAGER_STAT_MISS==1 && PAGER_STAT_WRITE==2 ); |
| 44637 | + |
| 44638 | + *pnVal += pPager->aStat[eStat - SQLITE_DBSTATUS_CACHE_HIT]; |
| 44500 | 44639 | if( reset ){ |
| 44501 | | - *piStat = 0; |
| 44640 | + pPager->aStat[eStat - SQLITE_DBSTATUS_CACHE_HIT] = 0; |
| 44502 | 44641 | } |
| 44503 | 44642 | } |
| 44504 | 44643 | |
| 44505 | 44644 | /* |
| 44506 | 44645 | ** Return true if this is an in-memory pager. |
| | @@ -45237,10 +45376,24 @@ |
| 45237 | 45376 | pPager->pWal = 0; |
| 45238 | 45377 | } |
| 45239 | 45378 | } |
| 45240 | 45379 | return rc; |
| 45241 | 45380 | } |
| 45381 | + |
| 45382 | +#ifdef SQLITE_ENABLE_ZIPVFS |
| 45383 | +/* |
| 45384 | +** A read-lock must be held on the pager when this function is called. If |
| 45385 | +** the pager is in WAL mode and the WAL file currently contains one or more |
| 45386 | +** frames, return the size in bytes of the page images stored within the |
| 45387 | +** WAL frames. Otherwise, if this is not a WAL database or the WAL file |
| 45388 | +** is empty, return 0. |
| 45389 | +*/ |
| 45390 | +SQLITE_PRIVATE int sqlite3PagerWalFramesize(Pager *pPager){ |
| 45391 | + assert( pPager->eState==PAGER_READER ); |
| 45392 | + return sqlite3WalFramesize(pPager->pWal); |
| 45393 | +} |
| 45394 | +#endif |
| 45242 | 45395 | |
| 45243 | 45396 | #ifdef SQLITE_HAS_CODEC |
| 45244 | 45397 | /* |
| 45245 | 45398 | ** This function is called by the wal module when writing page content |
| 45246 | 45399 | ** into the log file. |
| | @@ -47657,11 +47810,11 @@ |
| 47657 | 47810 | testcase( sz<=32768 ); |
| 47658 | 47811 | testcase( sz>=65536 ); |
| 47659 | 47812 | iOffset = walFrameOffset(iRead, sz) + WAL_FRAME_HDRSIZE; |
| 47660 | 47813 | *pInWal = 1; |
| 47661 | 47814 | /* testcase( IS_BIG_INT(iOffset) ); // requires a 4GiB WAL */ |
| 47662 | | - return sqlite3OsRead(pWal->pWalFd, pOut, nOut, iOffset); |
| 47815 | + return sqlite3OsRead(pWal->pWalFd, pOut, (nOut>sz ? sz : nOut), iOffset); |
| 47663 | 47816 | } |
| 47664 | 47817 | |
| 47665 | 47818 | *pInWal = 0; |
| 47666 | 47819 | return SQLITE_OK; |
| 47667 | 47820 | } |
| | @@ -48327,10 +48480,22 @@ |
| 48327 | 48480 | ** WAL module is using shared-memory, return false. |
| 48328 | 48481 | */ |
| 48329 | 48482 | SQLITE_PRIVATE int sqlite3WalHeapMemory(Wal *pWal){ |
| 48330 | 48483 | return (pWal && pWal->exclusiveMode==WAL_HEAPMEMORY_MODE ); |
| 48331 | 48484 | } |
| 48485 | + |
| 48486 | +#ifdef SQLITE_ENABLE_ZIPVFS |
| 48487 | +/* |
| 48488 | +** If the argument is not NULL, it points to a Wal object that holds a |
| 48489 | +** read-lock. This function returns the database page-size if it is known, |
| 48490 | +** or zero if it is not (or if pWal is NULL). |
| 48491 | +*/ |
| 48492 | +SQLITE_PRIVATE int sqlite3WalFramesize(Wal *pWal){ |
| 48493 | + assert( pWal==0 || pWal->readLock>=0 ); |
| 48494 | + return (pWal ? pWal->szPage : 0); |
| 48495 | +} |
| 48496 | +#endif |
| 48332 | 48497 | |
| 48333 | 48498 | #endif /* #ifndef SQLITE_OMIT_WAL */ |
| 48334 | 48499 | |
| 48335 | 48500 | /************** End of wal.c *************************************************/ |
| 48336 | 48501 | /************** Begin file btmutex.c *****************************************/ |
| | @@ -51320,11 +51485,11 @@ |
| 51320 | 51485 | |
| 51321 | 51486 | /* Rollback any active transaction and free the handle structure. |
| 51322 | 51487 | ** The call to sqlite3BtreeRollback() drops any table-locks held by |
| 51323 | 51488 | ** this handle. |
| 51324 | 51489 | */ |
| 51325 | | - sqlite3BtreeRollback(p); |
| 51490 | + sqlite3BtreeRollback(p, SQLITE_OK); |
| 51326 | 51491 | sqlite3BtreeLeave(p); |
| 51327 | 51492 | |
| 51328 | 51493 | /* If there are still other outstanding references to the shared-btree |
| 51329 | 51494 | ** structure, return now. The remainder of this procedure cleans |
| 51330 | 51495 | ** up the shared-btree. |
| | @@ -52558,10 +52723,11 @@ |
| 52558 | 52723 | ** save the state of the cursor. The cursor must be |
| 52559 | 52724 | ** invalidated. |
| 52560 | 52725 | */ |
| 52561 | 52726 | SQLITE_PRIVATE void sqlite3BtreeTripAllCursors(Btree *pBtree, int errCode){ |
| 52562 | 52727 | BtCursor *p; |
| 52728 | + if( pBtree==0 ) return; |
| 52563 | 52729 | sqlite3BtreeEnter(pBtree); |
| 52564 | 52730 | for(p=pBtree->pBt->pCursor; p; p=p->pNext){ |
| 52565 | 52731 | int i; |
| 52566 | 52732 | sqlite3BtreeClearCursor(p); |
| 52567 | 52733 | p->eState = CURSOR_FAULT; |
| | @@ -52581,29 +52747,24 @@ |
| 52581 | 52747 | ** in an error. |
| 52582 | 52748 | ** |
| 52583 | 52749 | ** This will release the write lock on the database file. If there |
| 52584 | 52750 | ** are no active cursors, it also releases the read lock. |
| 52585 | 52751 | */ |
| 52586 | | -SQLITE_PRIVATE int sqlite3BtreeRollback(Btree *p){ |
| 52752 | +SQLITE_PRIVATE int sqlite3BtreeRollback(Btree *p, int tripCode){ |
| 52587 | 52753 | int rc; |
| 52588 | 52754 | BtShared *pBt = p->pBt; |
| 52589 | 52755 | MemPage *pPage1; |
| 52590 | 52756 | |
| 52591 | 52757 | sqlite3BtreeEnter(p); |
| 52592 | | - rc = saveAllCursors(pBt, 0, 0); |
| 52593 | | -#ifndef SQLITE_OMIT_SHARED_CACHE |
| 52594 | | - if( rc!=SQLITE_OK ){ |
| 52595 | | - /* This is a horrible situation. An IO or malloc() error occurred whilst |
| 52596 | | - ** trying to save cursor positions. If this is an automatic rollback (as |
| 52597 | | - ** the result of a constraint, malloc() failure or IO error) then |
| 52598 | | - ** the cache may be internally inconsistent (not contain valid trees) so |
| 52599 | | - ** we cannot simply return the error to the caller. Instead, abort |
| 52600 | | - ** all queries that may be using any of the cursors that failed to save. |
| 52601 | | - */ |
| 52602 | | - sqlite3BtreeTripAllCursors(p, rc); |
| 52603 | | - } |
| 52604 | | -#endif |
| 52758 | + if( tripCode==SQLITE_OK ){ |
| 52759 | + rc = tripCode = saveAllCursors(pBt, 0, 0); |
| 52760 | + }else{ |
| 52761 | + rc = SQLITE_OK; |
| 52762 | + } |
| 52763 | + if( tripCode ){ |
| 52764 | + sqlite3BtreeTripAllCursors(p, tripCode); |
| 52765 | + } |
| 52605 | 52766 | btreeIntegrity(p); |
| 52606 | 52767 | |
| 52607 | 52768 | if( p->inTrans==TRANS_WRITE ){ |
| 52608 | 52769 | int rc2; |
| 52609 | 52770 | |
| | @@ -56072,17 +56233,10 @@ |
| 56072 | 56233 | ** keys with no associated data. If the cursor was opened expecting an |
| 56073 | 56234 | ** intkey table, the caller should be inserting integer keys with a |
| 56074 | 56235 | ** blob of associated data. */ |
| 56075 | 56236 | assert( (pKey==0)==(pCur->pKeyInfo==0) ); |
| 56076 | 56237 | |
| 56077 | | - /* If this is an insert into a table b-tree, invalidate any incrblob |
| 56078 | | - ** cursors open on the row being replaced (assuming this is a replace |
| 56079 | | - ** operation - if it is not, the following is a no-op). */ |
| 56080 | | - if( pCur->pKeyInfo==0 ){ |
| 56081 | | - invalidateIncrblobCursors(p, nKey, 0); |
| 56082 | | - } |
| 56083 | | - |
| 56084 | 56238 | /* Save the positions of any other cursors open on this table. |
| 56085 | 56239 | ** |
| 56086 | 56240 | ** In some cases, the call to btreeMoveto() below is a no-op. For |
| 56087 | 56241 | ** example, when inserting data into a table with auto-generated integer |
| 56088 | 56242 | ** keys, the VDBE layer invokes sqlite3BtreeLast() to figure out the |
| | @@ -56092,10 +56246,18 @@ |
| 56092 | 56246 | ** doing any work. To avoid thwarting these optimizations, it is important |
| 56093 | 56247 | ** not to clear the cursor here. |
| 56094 | 56248 | */ |
| 56095 | 56249 | rc = saveAllCursors(pBt, pCur->pgnoRoot, pCur); |
| 56096 | 56250 | if( rc ) return rc; |
| 56251 | + |
| 56252 | + /* If this is an insert into a table b-tree, invalidate any incrblob |
| 56253 | + ** cursors open on the row being replaced (assuming this is a replace |
| 56254 | + ** operation - if it is not, the following is a no-op). */ |
| 56255 | + if( pCur->pKeyInfo==0 ){ |
| 56256 | + invalidateIncrblobCursors(p, nKey, 0); |
| 56257 | + } |
| 56258 | + |
| 56097 | 56259 | if( !loc ){ |
| 56098 | 56260 | rc = btreeMoveto(pCur, pKey, nKey, appendBias, &loc); |
| 56099 | 56261 | if( rc ) return rc; |
| 56100 | 56262 | } |
| 56101 | 56263 | assert( pCur->eState==CURSOR_VALID || (pCur->eState==CURSOR_INVALID && loc) ); |
| | @@ -56202,16 +56364,10 @@ |
| 56202 | 56364 | || NEVER(pCur->eState!=CURSOR_VALID) |
| 56203 | 56365 | ){ |
| 56204 | 56366 | return SQLITE_ERROR; /* Something has gone awry. */ |
| 56205 | 56367 | } |
| 56206 | 56368 | |
| 56207 | | - /* If this is a delete operation to remove a row from a table b-tree, |
| 56208 | | - ** invalidate any incrblob cursors open on the row being deleted. */ |
| 56209 | | - if( pCur->pKeyInfo==0 ){ |
| 56210 | | - invalidateIncrblobCursors(p, pCur->info.nKey, 0); |
| 56211 | | - } |
| 56212 | | - |
| 56213 | 56369 | iCellDepth = pCur->iPage; |
| 56214 | 56370 | iCellIdx = pCur->aiIdx[iCellDepth]; |
| 56215 | 56371 | pPage = pCur->apPage[iCellDepth]; |
| 56216 | 56372 | pCell = findCell(pPage, iCellIdx); |
| 56217 | 56373 | |
| | @@ -56233,10 +56389,17 @@ |
| 56233 | 56389 | ** deleted writable. Then free any overflow pages associated with the |
| 56234 | 56390 | ** entry and finally remove the cell itself from within the page. |
| 56235 | 56391 | */ |
| 56236 | 56392 | rc = saveAllCursors(pBt, pCur->pgnoRoot, pCur); |
| 56237 | 56393 | if( rc ) return rc; |
| 56394 | + |
| 56395 | + /* If this is a delete operation to remove a row from a table b-tree, |
| 56396 | + ** invalidate any incrblob cursors open on the row being deleted. */ |
| 56397 | + if( pCur->pKeyInfo==0 ){ |
| 56398 | + invalidateIncrblobCursors(p, pCur->info.nKey, 0); |
| 56399 | + } |
| 56400 | + |
| 56238 | 56401 | rc = sqlite3PagerWrite(pPage->pDbPage); |
| 56239 | 56402 | if( rc ) return rc; |
| 56240 | 56403 | rc = clearCell(pPage, pCell); |
| 56241 | 56404 | dropCell(pPage, iCellIdx, cellSizePtr(pPage, pCell), &rc); |
| 56242 | 56405 | if( rc ) return rc; |
| | @@ -56514,17 +56677,17 @@ |
| 56514 | 56677 | int rc; |
| 56515 | 56678 | BtShared *pBt = p->pBt; |
| 56516 | 56679 | sqlite3BtreeEnter(p); |
| 56517 | 56680 | assert( p->inTrans==TRANS_WRITE ); |
| 56518 | 56681 | |
| 56519 | | - /* Invalidate all incrblob cursors open on table iTable (assuming iTable |
| 56520 | | - ** is the root of a table b-tree - if it is not, the following call is |
| 56521 | | - ** a no-op). */ |
| 56522 | | - invalidateIncrblobCursors(p, 0, 1); |
| 56523 | | - |
| 56524 | 56682 | rc = saveAllCursors(pBt, (Pgno)iTable, 0); |
| 56683 | + |
| 56525 | 56684 | if( SQLITE_OK==rc ){ |
| 56685 | + /* Invalidate all incrblob cursors open on table iTable (assuming iTable |
| 56686 | + ** is the root of a table b-tree - if it is not, the following call is |
| 56687 | + ** a no-op). */ |
| 56688 | + invalidateIncrblobCursors(p, 0, 1); |
| 56526 | 56689 | rc = clearDatabasePage(pBt, (Pgno)iTable, 0, pnChange); |
| 56527 | 56690 | } |
| 56528 | 56691 | sqlite3BtreeLeave(p); |
| 56529 | 56692 | return rc; |
| 56530 | 56693 | } |
| | @@ -58121,11 +58284,11 @@ |
| 58121 | 58284 | } |
| 58122 | 58285 | *pp = p->pNext; |
| 58123 | 58286 | } |
| 58124 | 58287 | |
| 58125 | 58288 | /* If a transaction is still open on the Btree, roll it back. */ |
| 58126 | | - sqlite3BtreeRollback(p->pDest); |
| 58289 | + sqlite3BtreeRollback(p->pDest, SQLITE_OK); |
| 58127 | 58290 | |
| 58128 | 58291 | /* Set the error code of the destination database handle. */ |
| 58129 | 58292 | rc = (p->rc==SQLITE_DONE) ? SQLITE_OK : p->rc; |
| 58130 | 58293 | sqlite3Error(p->pDestDb, rc, 0); |
| 58131 | 58294 | |
| | @@ -58332,14 +58495,14 @@ |
| 58332 | 58495 | |
| 58333 | 58496 | /* |
| 58334 | 58497 | ** Make sure pMem->z points to a writable allocation of at least |
| 58335 | 58498 | ** n bytes. |
| 58336 | 58499 | ** |
| 58337 | | -** If the memory cell currently contains string or blob data |
| 58338 | | -** and the third argument passed to this function is true, the |
| 58339 | | -** current content of the cell is preserved. Otherwise, it may |
| 58340 | | -** be discarded. |
| 58500 | +** If the third argument passed to this function is true, then memory |
| 58501 | +** cell pMem must contain a string or blob. In this case the content is |
| 58502 | +** preserved. Otherwise, if the third parameter to this function is false, |
| 58503 | +** any current string or blob value may be discarded. |
| 58341 | 58504 | ** |
| 58342 | 58505 | ** This function sets the MEM_Dyn flag and clears any xDel callback. |
| 58343 | 58506 | ** It also clears MEM_Ephem and MEM_Static. If the preserve flag is |
| 58344 | 58507 | ** not set, Mem.n is zeroed. |
| 58345 | 58508 | */ |
| | @@ -58349,10 +58512,14 @@ |
| 58349 | 58512 | (((pMem->flags&MEM_Dyn)&&pMem->xDel) ? 1 : 0) + |
| 58350 | 58513 | ((pMem->flags&MEM_Ephem) ? 1 : 0) + |
| 58351 | 58514 | ((pMem->flags&MEM_Static) ? 1 : 0) |
| 58352 | 58515 | ); |
| 58353 | 58516 | assert( (pMem->flags&MEM_RowSet)==0 ); |
| 58517 | + |
| 58518 | + /* If the preserve flag is set to true, then the memory cell must already |
| 58519 | + ** contain a valid string or blob value. */ |
| 58520 | + assert( preserve==0 || pMem->flags&(MEM_Blob|MEM_Str) ); |
| 58354 | 58521 | |
| 58355 | 58522 | if( n<32 ) n = 32; |
| 58356 | 58523 | if( sqlite3DbMallocSize(pMem->db, pMem->zMalloc)<n ){ |
| 58357 | 58524 | if( preserve && pMem->z==pMem->zMalloc ){ |
| 58358 | 58525 | pMem->z = pMem->zMalloc = sqlite3DbReallocOrFree(pMem->db, pMem->z, n); |
| | @@ -60668,11 +60835,11 @@ |
| 60668 | 60835 | int nByte = (nSub+1)*sizeof(SubProgram*); |
| 60669 | 60836 | int j; |
| 60670 | 60837 | for(j=0; j<nSub; j++){ |
| 60671 | 60838 | if( apSub[j]==pOp->p4.pProgram ) break; |
| 60672 | 60839 | } |
| 60673 | | - if( j==nSub && SQLITE_OK==sqlite3VdbeMemGrow(pSub, nByte, 1) ){ |
| 60840 | + if( j==nSub && SQLITE_OK==sqlite3VdbeMemGrow(pSub, nByte, nSub!=0) ){ |
| 60674 | 60841 | apSub = (SubProgram **)pSub->z; |
| 60675 | 60842 | apSub[nSub++] = pOp->p4.pProgram; |
| 60676 | 60843 | pSub->flags |= MEM_Blob; |
| 60677 | 60844 | pSub->n = nSub*sizeof(SubProgram*); |
| 60678 | 60845 | } |
| | @@ -61431,36 +61598,10 @@ |
| 61431 | 61598 | } |
| 61432 | 61599 | #else |
| 61433 | 61600 | #define checkActiveVdbeCnt(x) |
| 61434 | 61601 | #endif |
| 61435 | 61602 | |
| 61436 | | -/* |
| 61437 | | -** For every Btree that in database connection db which |
| 61438 | | -** has been modified, "trip" or invalidate each cursor in |
| 61439 | | -** that Btree might have been modified so that the cursor |
| 61440 | | -** can never be used again. This happens when a rollback |
| 61441 | | -*** occurs. We have to trip all the other cursors, even |
| 61442 | | -** cursor from other VMs in different database connections, |
| 61443 | | -** so that none of them try to use the data at which they |
| 61444 | | -** were pointing and which now may have been changed due |
| 61445 | | -** to the rollback. |
| 61446 | | -** |
| 61447 | | -** Remember that a rollback can delete tables complete and |
| 61448 | | -** reorder rootpages. So it is not sufficient just to save |
| 61449 | | -** the state of the cursor. We have to invalidate the cursor |
| 61450 | | -** so that it is never used again. |
| 61451 | | -*/ |
| 61452 | | -static void invalidateCursorsOnModifiedBtrees(sqlite3 *db){ |
| 61453 | | - int i; |
| 61454 | | - for(i=0; i<db->nDb; i++){ |
| 61455 | | - Btree *p = db->aDb[i].pBt; |
| 61456 | | - if( p && sqlite3BtreeIsInTrans(p) ){ |
| 61457 | | - sqlite3BtreeTripAllCursors(p, SQLITE_ABORT); |
| 61458 | | - } |
| 61459 | | - } |
| 61460 | | -} |
| 61461 | | - |
| 61462 | 61603 | /* |
| 61463 | 61604 | ** If the Vdbe passed as the first argument opened a statement-transaction, |
| 61464 | 61605 | ** close it now. Argument eOp must be either SAVEPOINT_ROLLBACK or |
| 61465 | 61606 | ** SAVEPOINT_RELEASE. If it is SAVEPOINT_ROLLBACK, then the statement |
| 61466 | 61607 | ** transaction is rolled back. If eOp is SAVEPOINT_RELEASE, then the |
| | @@ -61621,12 +61762,11 @@ |
| 61621 | 61762 | eStatementOp = SAVEPOINT_ROLLBACK; |
| 61622 | 61763 | }else{ |
| 61623 | 61764 | /* We are forced to roll back the active transaction. Before doing |
| 61624 | 61765 | ** so, abort any other statements this handle currently has active. |
| 61625 | 61766 | */ |
| 61626 | | - invalidateCursorsOnModifiedBtrees(db); |
| 61627 | | - sqlite3RollbackAll(db); |
| 61767 | + sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK); |
| 61628 | 61768 | sqlite3CloseSavepoints(db); |
| 61629 | 61769 | db->autoCommit = 1; |
| 61630 | 61770 | } |
| 61631 | 61771 | } |
| 61632 | 61772 | } |
| | @@ -61664,27 +61804,26 @@ |
| 61664 | 61804 | if( rc==SQLITE_BUSY && p->readOnly ){ |
| 61665 | 61805 | sqlite3VdbeLeave(p); |
| 61666 | 61806 | return SQLITE_BUSY; |
| 61667 | 61807 | }else if( rc!=SQLITE_OK ){ |
| 61668 | 61808 | p->rc = rc; |
| 61669 | | - sqlite3RollbackAll(db); |
| 61809 | + sqlite3RollbackAll(db, SQLITE_OK); |
| 61670 | 61810 | }else{ |
| 61671 | 61811 | db->nDeferredCons = 0; |
| 61672 | 61812 | sqlite3CommitInternalChanges(db); |
| 61673 | 61813 | } |
| 61674 | 61814 | }else{ |
| 61675 | | - sqlite3RollbackAll(db); |
| 61815 | + sqlite3RollbackAll(db, SQLITE_OK); |
| 61676 | 61816 | } |
| 61677 | 61817 | db->nStatement = 0; |
| 61678 | 61818 | }else if( eStatementOp==0 ){ |
| 61679 | 61819 | if( p->rc==SQLITE_OK || p->errorAction==OE_Fail ){ |
| 61680 | 61820 | eStatementOp = SAVEPOINT_RELEASE; |
| 61681 | 61821 | }else if( p->errorAction==OE_Abort ){ |
| 61682 | 61822 | eStatementOp = SAVEPOINT_ROLLBACK; |
| 61683 | 61823 | }else{ |
| 61684 | | - invalidateCursorsOnModifiedBtrees(db); |
| 61685 | | - sqlite3RollbackAll(db); |
| 61824 | + sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK); |
| 61686 | 61825 | sqlite3CloseSavepoints(db); |
| 61687 | 61826 | db->autoCommit = 1; |
| 61688 | 61827 | } |
| 61689 | 61828 | } |
| 61690 | 61829 | |
| | @@ -61700,12 +61839,11 @@ |
| 61700 | 61839 | if( p->rc==SQLITE_OK || p->rc==SQLITE_CONSTRAINT ){ |
| 61701 | 61840 | p->rc = rc; |
| 61702 | 61841 | sqlite3DbFree(db, p->zErrMsg); |
| 61703 | 61842 | p->zErrMsg = 0; |
| 61704 | 61843 | } |
| 61705 | | - invalidateCursorsOnModifiedBtrees(db); |
| 61706 | | - sqlite3RollbackAll(db); |
| 61844 | + sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK); |
| 61707 | 61845 | sqlite3CloseSavepoints(db); |
| 61708 | 61846 | db->autoCommit = 1; |
| 61709 | 61847 | } |
| 61710 | 61848 | } |
| 61711 | 61849 | |
| | @@ -66946,10 +67084,15 @@ |
| 66946 | 67084 | ** |
| 66947 | 67085 | ** If the OPFLAG_CLEARCACHE bit is set on P5 and P1 is a pseudo-table cursor, |
| 66948 | 67086 | ** then the cache of the cursor is reset prior to extracting the column. |
| 66949 | 67087 | ** The first OP_Column against a pseudo-table after the value of the content |
| 66950 | 67088 | ** register has changed should have this bit set. |
| 67089 | +** |
| 67090 | +** If the OPFLAG_LENGTHARG and OPFLAG_TYPEOFARG bits are set on P5 when |
| 67091 | +** the result is guaranteed to only be used as the argument of a length() |
| 67092 | +** or typeof() function, respectively. The loading of large blobs can be |
| 67093 | +** skipped for length() and all content loading can be skipped for typeof(). |
| 66951 | 67094 | */ |
| 66952 | 67095 | case OP_Column: { |
| 66953 | 67096 | #if 0 /* local variables moved into u.an */ |
| 66954 | 67097 | u32 payloadSize; /* Number of bytes in the record */ |
| 66955 | 67098 | i64 payloadSize64; /* Number of bytes in the record */ |
| | @@ -67088,11 +67231,11 @@ |
| 67088 | 67231 | u.an.pC->aRow = (u8*)u.an.zData; |
| 67089 | 67232 | }else{ |
| 67090 | 67233 | u.an.pC->aRow = 0; |
| 67091 | 67234 | } |
| 67092 | 67235 | } |
| 67093 | | - /* The following assert is true in all cases accept when |
| 67236 | + /* The following assert is true in all cases except when |
| 67094 | 67237 | ** the database file has been corrupted externally. |
| 67095 | 67238 | ** assert( u.an.zRec!=0 || u.an.avail>=u.an.payloadSize || u.an.avail>=9 ); */ |
| 67096 | 67239 | u.an.szHdr = getVarint32((u8*)u.an.zData, u.an.offset); |
| 67097 | 67240 | |
| 67098 | 67241 | /* Make sure a corrupt database has not given us an oversize header. |
| | @@ -67163,15 +67306,15 @@ |
| 67163 | 67306 | if( u.an.offset<u.an.szField ){ /* True if u.an.offset overflows */ |
| 67164 | 67307 | u.an.zIdx = &u.an.zEndHdr[1]; /* Forces SQLITE_CORRUPT return below */ |
| 67165 | 67308 | break; |
| 67166 | 67309 | } |
| 67167 | 67310 | }else{ |
| 67168 | | - /* If u.an.i is less that u.an.nField, then there are less fields in this |
| 67311 | + /* If u.an.i is less that u.an.nField, then there are fewer fields in this |
| 67169 | 67312 | ** record than SetNumColumns indicated there are columns in the |
| 67170 | 67313 | ** table. Set the u.an.offset for any extra columns not present in |
| 67171 | | - ** the record to 0. This tells code below to store a NULL |
| 67172 | | - ** instead of deserializing a value from the record. |
| 67314 | + ** the record to 0. This tells code below to store the default value |
| 67315 | + ** for the column instead of deserializing a value from the record. |
| 67173 | 67316 | */ |
| 67174 | 67317 | u.an.aOffset[u.an.i] = 0; |
| 67175 | 67318 | } |
| 67176 | 67319 | } |
| 67177 | 67320 | sqlite3VdbeMemRelease(&u.an.sMem); |
| | @@ -67197,21 +67340,36 @@ |
| 67197 | 67340 | ** a pointer to a Mem object. |
| 67198 | 67341 | */ |
| 67199 | 67342 | if( u.an.aOffset[u.an.p2] ){ |
| 67200 | 67343 | assert( rc==SQLITE_OK ); |
| 67201 | 67344 | if( u.an.zRec ){ |
| 67345 | + /* This is the common case where the whole row fits on a single page */ |
| 67202 | 67346 | VdbeMemRelease(u.an.pDest); |
| 67203 | 67347 | sqlite3VdbeSerialGet((u8 *)&u.an.zRec[u.an.aOffset[u.an.p2]], u.an.aType[u.an.p2], u.an.pDest); |
| 67204 | 67348 | }else{ |
| 67205 | | - u.an.len = sqlite3VdbeSerialTypeLen(u.an.aType[u.an.p2]); |
| 67206 | | - sqlite3VdbeMemMove(&u.an.sMem, u.an.pDest); |
| 67207 | | - rc = sqlite3VdbeMemFromBtree(u.an.pCrsr, u.an.aOffset[u.an.p2], u.an.len, u.an.pC->isIndex, &u.an.sMem); |
| 67208 | | - if( rc!=SQLITE_OK ){ |
| 67209 | | - goto op_column_out; |
| 67210 | | - } |
| 67211 | | - u.an.zData = u.an.sMem.z; |
| 67212 | | - sqlite3VdbeSerialGet((u8*)u.an.zData, u.an.aType[u.an.p2], u.an.pDest); |
| 67349 | + /* This branch happens only when the row overflows onto multiple pages */ |
| 67350 | + u.an.t = u.an.aType[u.an.p2]; |
| 67351 | + if( (pOp->p5 & (OPFLAG_LENGTHARG|OPFLAG_TYPEOFARG))!=0 |
| 67352 | + && ((u.an.t>=12 && (u.an.t&1)==0) || (pOp->p5 & OPFLAG_TYPEOFARG)!=0) |
| 67353 | + ){ |
| 67354 | + /* Content is irrelevant for the typeof() function and for |
| 67355 | + ** the length(X) function if X is a blob. So we might as well use |
| 67356 | + ** bogus content rather than reading content from disk. NULL works |
| 67357 | + ** for text and blob and whatever is in the u.an.payloadSize64 variable |
| 67358 | + ** will work for everything else. */ |
| 67359 | + u.an.zData = u.an.t<12 ? (char*)&u.an.payloadSize64 : 0; |
| 67360 | + }else{ |
| 67361 | + u.an.len = sqlite3VdbeSerialTypeLen(u.an.t); |
| 67362 | + sqlite3VdbeMemMove(&u.an.sMem, u.an.pDest); |
| 67363 | + rc = sqlite3VdbeMemFromBtree(u.an.pCrsr, u.an.aOffset[u.an.p2], u.an.len, u.an.pC->isIndex, |
| 67364 | + &u.an.sMem); |
| 67365 | + if( rc!=SQLITE_OK ){ |
| 67366 | + goto op_column_out; |
| 67367 | + } |
| 67368 | + u.an.zData = u.an.sMem.z; |
| 67369 | + } |
| 67370 | + sqlite3VdbeSerialGet((u8*)u.an.zData, u.an.t, u.an.pDest); |
| 67213 | 67371 | } |
| 67214 | 67372 | u.an.pDest->enc = encoding; |
| 67215 | 67373 | }else{ |
| 67216 | 67374 | if( pOp->p4type==P4_MEM ){ |
| 67217 | 67375 | sqlite3VdbeMemShallowCopy(u.an.pDest, pOp->p4.pMem, MEM_Static); |
| | @@ -67513,20 +67671,16 @@ |
| 67513 | 67671 | u.ar.iSavepoint++; |
| 67514 | 67672 | } |
| 67515 | 67673 | if( !u.ar.pSavepoint ){ |
| 67516 | 67674 | sqlite3SetString(&p->zErrMsg, db, "no such savepoint: %s", u.ar.zName); |
| 67517 | 67675 | rc = SQLITE_ERROR; |
| 67518 | | - }else if( |
| 67519 | | - db->writeVdbeCnt>0 || (u.ar.p1==SAVEPOINT_ROLLBACK && db->activeVdbeCnt>1) |
| 67520 | | - ){ |
| 67676 | + }else if( db->writeVdbeCnt>0 && u.ar.p1==SAVEPOINT_RELEASE ){ |
| 67521 | 67677 | /* It is not possible to release (commit) a savepoint if there are |
| 67522 | | - ** active write statements. It is not possible to rollback a savepoint |
| 67523 | | - ** if there are any active statements at all. |
| 67678 | + ** active write statements. |
| 67524 | 67679 | */ |
| 67525 | 67680 | sqlite3SetString(&p->zErrMsg, db, |
| 67526 | | - "cannot %s savepoint - SQL statements in progress", |
| 67527 | | - (u.ar.p1==SAVEPOINT_ROLLBACK ? "rollback": "release") |
| 67681 | + "cannot release savepoint - SQL statements in progress" |
| 67528 | 67682 | ); |
| 67529 | 67683 | rc = SQLITE_BUSY; |
| 67530 | 67684 | }else{ |
| 67531 | 67685 | |
| 67532 | 67686 | /* Determine whether or not this is a transaction savepoint. If so, |
| | @@ -67547,10 +67701,15 @@ |
| 67547 | 67701 | } |
| 67548 | 67702 | db->isTransactionSavepoint = 0; |
| 67549 | 67703 | rc = p->rc; |
| 67550 | 67704 | }else{ |
| 67551 | 67705 | u.ar.iSavepoint = db->nSavepoint - u.ar.iSavepoint - 1; |
| 67706 | + if( u.ar.p1==SAVEPOINT_ROLLBACK ){ |
| 67707 | + for(u.ar.ii=0; u.ar.ii<db->nDb; u.ar.ii++){ |
| 67708 | + sqlite3BtreeTripAllCursors(db->aDb[u.ar.ii].pBt, SQLITE_ABORT); |
| 67709 | + } |
| 67710 | + } |
| 67552 | 67711 | for(u.ar.ii=0; u.ar.ii<db->nDb; u.ar.ii++){ |
| 67553 | 67712 | rc = sqlite3BtreeSavepoint(db->aDb[u.ar.ii].pBt, u.ar.p1, u.ar.iSavepoint); |
| 67554 | 67713 | if( rc!=SQLITE_OK ){ |
| 67555 | 67714 | goto abort_due_to_error; |
| 67556 | 67715 | } |
| | @@ -67617,29 +67776,32 @@ |
| 67617 | 67776 | u.as.turnOnAC = u.as.desiredAutoCommit && !db->autoCommit; |
| 67618 | 67777 | assert( u.as.desiredAutoCommit==1 || u.as.desiredAutoCommit==0 ); |
| 67619 | 67778 | assert( u.as.desiredAutoCommit==1 || u.as.iRollback==0 ); |
| 67620 | 67779 | assert( db->activeVdbeCnt>0 ); /* At least this one VM is active */ |
| 67621 | 67780 | |
| 67781 | +#if 0 |
| 67622 | 67782 | if( u.as.turnOnAC && u.as.iRollback && db->activeVdbeCnt>1 ){ |
| 67623 | 67783 | /* If this instruction implements a ROLLBACK and other VMs are |
| 67624 | 67784 | ** still running, and a transaction is active, return an error indicating |
| 67625 | 67785 | ** that the other VMs must complete first. |
| 67626 | 67786 | */ |
| 67627 | 67787 | sqlite3SetString(&p->zErrMsg, db, "cannot rollback transaction - " |
| 67628 | 67788 | "SQL statements in progress"); |
| 67629 | 67789 | rc = SQLITE_BUSY; |
| 67630 | | - }else if( u.as.turnOnAC && !u.as.iRollback && db->writeVdbeCnt>0 ){ |
| 67790 | + }else |
| 67791 | +#endif |
| 67792 | + if( u.as.turnOnAC && !u.as.iRollback && db->writeVdbeCnt>0 ){ |
| 67631 | 67793 | /* If this instruction implements a COMMIT and other VMs are writing |
| 67632 | 67794 | ** return an error indicating that the other VMs must complete first. |
| 67633 | 67795 | */ |
| 67634 | 67796 | sqlite3SetString(&p->zErrMsg, db, "cannot commit transaction - " |
| 67635 | 67797 | "SQL statements in progress"); |
| 67636 | 67798 | rc = SQLITE_BUSY; |
| 67637 | 67799 | }else if( u.as.desiredAutoCommit!=db->autoCommit ){ |
| 67638 | 67800 | if( u.as.iRollback ){ |
| 67639 | 67801 | assert( u.as.desiredAutoCommit==1 ); |
| 67640 | | - sqlite3RollbackAll(db); |
| 67802 | + sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK); |
| 67641 | 67803 | db->autoCommit = 1; |
| 67642 | 67804 | }else if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){ |
| 67643 | 67805 | goto vdbe_return; |
| 67644 | 67806 | }else{ |
| 67645 | 67807 | db->autoCommit = (u8)u.as.desiredAutoCommit; |
| | @@ -68701,11 +68863,11 @@ |
| 68701 | 68863 | u.bg.v = 1; /* IMP: R-61914-48074 */ |
| 68702 | 68864 | }else{ |
| 68703 | 68865 | assert( sqlite3BtreeCursorIsValid(u.bg.pC->pCursor) ); |
| 68704 | 68866 | rc = sqlite3BtreeKeySize(u.bg.pC->pCursor, &u.bg.v); |
| 68705 | 68867 | assert( rc==SQLITE_OK ); /* Cannot fail following BtreeLast() */ |
| 68706 | | - if( u.bg.v==MAX_ROWID ){ |
| 68868 | + if( u.bg.v>=MAX_ROWID ){ |
| 68707 | 68869 | u.bg.pC->useRandomRowid = 1; |
| 68708 | 68870 | }else{ |
| 68709 | 68871 | u.bg.v++; /* IMP: R-29538-34987 */ |
| 68710 | 68872 | } |
| 68711 | 68873 | } |
| | @@ -74821,27 +74983,59 @@ |
| 74821 | 74983 | int op, /* Expression opcode */ |
| 74822 | 74984 | Expr *pLeft, /* Left operand */ |
| 74823 | 74985 | Expr *pRight, /* Right operand */ |
| 74824 | 74986 | const Token *pToken /* Argument token */ |
| 74825 | 74987 | ){ |
| 74826 | | - Expr *p = sqlite3ExprAlloc(pParse->db, op, pToken, 1); |
| 74827 | | - sqlite3ExprAttachSubtrees(pParse->db, p, pLeft, pRight); |
| 74988 | + Expr *p; |
| 74989 | + if( op==TK_AND && pLeft && pRight ){ |
| 74990 | + /* Take advantage of short-circuit false optimization for AND */ |
| 74991 | + p = sqlite3ExprAnd(pParse->db, pLeft, pRight); |
| 74992 | + }else{ |
| 74993 | + p = sqlite3ExprAlloc(pParse->db, op, pToken, 1); |
| 74994 | + sqlite3ExprAttachSubtrees(pParse->db, p, pLeft, pRight); |
| 74995 | + } |
| 74828 | 74996 | if( p ) { |
| 74829 | 74997 | sqlite3ExprCheckHeight(pParse, p->nHeight); |
| 74830 | 74998 | } |
| 74831 | 74999 | return p; |
| 74832 | 75000 | } |
| 75001 | + |
| 75002 | +/* |
| 75003 | +** Return 1 if an expression must be FALSE in all cases and 0 if the |
| 75004 | +** expression might be true. This is an optimization. If is OK to |
| 75005 | +** return 0 here even if the expression really is always false (a |
| 75006 | +** false negative). But it is a bug to return 1 if the expression |
| 75007 | +** might be true in some rare circumstances (a false positive.) |
| 75008 | +** |
| 75009 | +** Note that if the expression is part of conditional for a |
| 75010 | +** LEFT JOIN, then we cannot determine at compile-time whether or not |
| 75011 | +** is it true or false, so always return 0. |
| 75012 | +*/ |
| 75013 | +static int exprAlwaysFalse(Expr *p){ |
| 75014 | + int v = 0; |
| 75015 | + if( ExprHasProperty(p, EP_FromJoin) ) return 0; |
| 75016 | + if( !sqlite3ExprIsInteger(p, &v) ) return 0; |
| 75017 | + return v==0; |
| 75018 | +} |
| 74833 | 75019 | |
| 74834 | 75020 | /* |
| 74835 | 75021 | ** Join two expressions using an AND operator. If either expression is |
| 74836 | 75022 | ** NULL, then just return the other expression. |
| 75023 | +** |
| 75024 | +** If one side or the other of the AND is known to be false, then instead |
| 75025 | +** of returning an AND expression, just return a constant expression with |
| 75026 | +** a value of false. |
| 74837 | 75027 | */ |
| 74838 | 75028 | SQLITE_PRIVATE Expr *sqlite3ExprAnd(sqlite3 *db, Expr *pLeft, Expr *pRight){ |
| 74839 | 75029 | if( pLeft==0 ){ |
| 74840 | 75030 | return pRight; |
| 74841 | 75031 | }else if( pRight==0 ){ |
| 74842 | 75032 | return pLeft; |
| 75033 | + }else if( exprAlwaysFalse(pLeft) || exprAlwaysFalse(pRight) ){ |
| 75034 | + sqlite3ExprDelete(db, pLeft); |
| 75035 | + sqlite3ExprDelete(db, pRight); |
| 75036 | + return sqlite3ExprAlloc(db, TK_INTEGER, &sqlite3IntTokens[0], 0); |
| 74843 | 75037 | }else{ |
| 74844 | 75038 | Expr *pNew = sqlite3ExprAlloc(db, TK_AND, 0, 0); |
| 74845 | 75039 | sqlite3ExprAttachSubtrees(db, pNew, pLeft, pRight); |
| 74846 | 75040 | return pNew; |
| 74847 | 75041 | } |
| | @@ -76369,19 +76563,10 @@ |
| 76369 | 76563 | ** Actually, the way the column cache is currently used, we are guaranteed |
| 76370 | 76564 | ** that the object will never already be in cache. Verify this guarantee. |
| 76371 | 76565 | */ |
| 76372 | 76566 | #ifndef NDEBUG |
| 76373 | 76567 | for(i=0, p=pParse->aColCache; i<SQLITE_N_COLCACHE; i++, p++){ |
| 76374 | | -#if 0 /* This code wold remove the entry from the cache if it existed */ |
| 76375 | | - if( p->iReg && p->iTable==iTab && p->iColumn==iCol ){ |
| 76376 | | - cacheEntryClear(pParse, p); |
| 76377 | | - p->iLevel = pParse->iCacheLevel; |
| 76378 | | - p->iReg = iReg; |
| 76379 | | - p->lru = pParse->iCacheCnt++; |
| 76380 | | - return; |
| 76381 | | - } |
| 76382 | | -#endif |
| 76383 | 76568 | assert( p->iReg==0 || p->iTable!=iTab || p->iColumn!=iCol ); |
| 76384 | 76569 | } |
| 76385 | 76570 | #endif |
| 76386 | 76571 | |
| 76387 | 76572 | /* Find an empty slot and replace it */ |
| | @@ -76512,11 +76697,12 @@ |
| 76512 | 76697 | SQLITE_PRIVATE int sqlite3ExprCodeGetColumn( |
| 76513 | 76698 | Parse *pParse, /* Parsing and code generating context */ |
| 76514 | 76699 | Table *pTab, /* Description of the table we are reading from */ |
| 76515 | 76700 | int iColumn, /* Index of the table column */ |
| 76516 | 76701 | int iTable, /* The cursor pointing to the table */ |
| 76517 | | - int iReg /* Store results here */ |
| 76702 | + int iReg, /* Store results here */ |
| 76703 | + u8 p5 /* P5 value for OP_Column */ |
| 76518 | 76704 | ){ |
| 76519 | 76705 | Vdbe *v = pParse->pVdbe; |
| 76520 | 76706 | int i; |
| 76521 | 76707 | struct yColCache *p; |
| 76522 | 76708 | |
| | @@ -76527,11 +76713,15 @@ |
| 76527 | 76713 | return p->iReg; |
| 76528 | 76714 | } |
| 76529 | 76715 | } |
| 76530 | 76716 | assert( v!=0 ); |
| 76531 | 76717 | sqlite3ExprCodeGetColumnOfTable(v, pTab, iTable, iColumn, iReg); |
| 76532 | | - sqlite3ExprCacheStore(pParse, iTable, iColumn, iReg); |
| 76718 | + if( p5 ){ |
| 76719 | + sqlite3VdbeChangeP5(v, p5); |
| 76720 | + }else{ |
| 76721 | + sqlite3ExprCacheStore(pParse, iTable, iColumn, iReg); |
| 76722 | + } |
| 76533 | 76723 | return iReg; |
| 76534 | 76724 | } |
| 76535 | 76725 | |
| 76536 | 76726 | /* |
| 76537 | 76727 | ** Clear all column cache entries. |
| | @@ -76655,11 +76845,12 @@ |
| 76655 | 76845 | /* This only happens when coding check constraints */ |
| 76656 | 76846 | assert( pParse->ckBase>0 ); |
| 76657 | 76847 | inReg = pExpr->iColumn + pParse->ckBase; |
| 76658 | 76848 | }else{ |
| 76659 | 76849 | inReg = sqlite3ExprCodeGetColumn(pParse, pExpr->pTab, |
| 76660 | | - pExpr->iColumn, pExpr->iTable, target); |
| 76850 | + pExpr->iColumn, pExpr->iTable, target, |
| 76851 | + pExpr->op2); |
| 76661 | 76852 | } |
| 76662 | 76853 | break; |
| 76663 | 76854 | } |
| 76664 | 76855 | case TK_INTEGER: { |
| 76665 | 76856 | codeInteger(pParse, pExpr, 0, target); |
| | @@ -76932,10 +77123,29 @@ |
| 76932 | 77123 | } |
| 76933 | 77124 | |
| 76934 | 77125 | |
| 76935 | 77126 | if( pFarg ){ |
| 76936 | 77127 | r1 = sqlite3GetTempRange(pParse, nFarg); |
| 77128 | + |
| 77129 | + /* For length() and typeof() functions with a column argument, |
| 77130 | + ** set the P5 parameter to the OP_Column opcode to OPFLAG_LENGTHARG |
| 77131 | + ** or OPFLAG_TYPEOFARG respectively, to avoid unnecessary data |
| 77132 | + ** loading. |
| 77133 | + */ |
| 77134 | + if( (pDef->flags & (SQLITE_FUNC_LENGTH|SQLITE_FUNC_TYPEOF))!=0 ){ |
| 77135 | + u8 exprOp; |
| 77136 | + assert( nFarg==1 ); |
| 77137 | + assert( pFarg->a[0].pExpr!=0 ); |
| 77138 | + exprOp = pFarg->a[0].pExpr->op; |
| 77139 | + if( exprOp==TK_COLUMN || exprOp==TK_AGG_COLUMN ){ |
| 77140 | + assert( SQLITE_FUNC_LENGTH==OPFLAG_LENGTHARG ); |
| 77141 | + assert( SQLITE_FUNC_TYPEOF==OPFLAG_TYPEOFARG ); |
| 77142 | + testcase( pDef->flags==SQLITE_FUNC_LENGTH ); |
| 77143 | + pFarg->a[0].pExpr->op2 = pDef->flags; |
| 77144 | + } |
| 77145 | + } |
| 77146 | + |
| 76937 | 77147 | sqlite3ExprCachePush(pParse); /* Ticket 2ea2425d34be */ |
| 76938 | 77148 | sqlite3ExprCodeExprList(pParse, pFarg, r1, 1); |
| 76939 | 77149 | sqlite3ExprCachePop(pParse, 1); /* Ticket 2ea2425d34be */ |
| 76940 | 77150 | }else{ |
| 76941 | 77151 | r1 = 0; |
| | @@ -80137,10 +80347,11 @@ |
| 80137 | 80347 | Index *pPrevIdx = 0; /* Previous index in the loop */ |
| 80138 | 80348 | int idx = 0; /* slot in pIdx->aSample[] for next sample */ |
| 80139 | 80349 | int eType; /* Datatype of a sample */ |
| 80140 | 80350 | IndexSample *pSample; /* A slot in pIdx->aSample[] */ |
| 80141 | 80351 | |
| 80352 | + assert( db->lookaside.bEnabled==0 ); |
| 80142 | 80353 | if( !sqlite3FindTable(db, "sqlite_stat3", zDb) ){ |
| 80143 | 80354 | return SQLITE_OK; |
| 80144 | 80355 | } |
| 80145 | 80356 | |
| 80146 | 80357 | zSql = sqlite3MPrintf(db, |
| | @@ -80163,11 +80374,11 @@ |
| 80163 | 80374 | nSample = sqlite3_column_int(pStmt, 1); |
| 80164 | 80375 | pIdx = sqlite3FindIndex(db, zIndex, zDb); |
| 80165 | 80376 | if( pIdx==0 ) continue; |
| 80166 | 80377 | assert( pIdx->nSample==0 ); |
| 80167 | 80378 | pIdx->nSample = nSample; |
| 80168 | | - pIdx->aSample = sqlite3MallocZero( nSample*sizeof(IndexSample) ); |
| 80379 | + pIdx->aSample = sqlite3DbMallocZero(db, nSample*sizeof(IndexSample)); |
| 80169 | 80380 | pIdx->avgEq = pIdx->aiRowEst[1]; |
| 80170 | 80381 | if( pIdx->aSample==0 ){ |
| 80171 | 80382 | db->mallocFailed = 1; |
| 80172 | 80383 | sqlite3_finalize(pStmt); |
| 80173 | 80384 | return SQLITE_NOMEM; |
| | @@ -80236,11 +80447,11 @@ |
| 80236 | 80447 | int n = z ? sqlite3_column_bytes(pStmt, 4) : 0; |
| 80237 | 80448 | pSample->nByte = n; |
| 80238 | 80449 | if( n < 1){ |
| 80239 | 80450 | pSample->u.z = 0; |
| 80240 | 80451 | }else{ |
| 80241 | | - pSample->u.z = sqlite3Malloc(n); |
| 80452 | + pSample->u.z = sqlite3DbMallocRaw(db, n); |
| 80242 | 80453 | if( pSample->u.z==0 ){ |
| 80243 | 80454 | db->mallocFailed = 1; |
| 80244 | 80455 | sqlite3_finalize(pStmt); |
| 80245 | 80456 | return SQLITE_NOMEM; |
| 80246 | 80457 | } |
| | @@ -80312,11 +80523,14 @@ |
| 80312 | 80523 | |
| 80313 | 80524 | |
| 80314 | 80525 | /* Load the statistics from the sqlite_stat3 table. */ |
| 80315 | 80526 | #ifdef SQLITE_ENABLE_STAT3 |
| 80316 | 80527 | if( rc==SQLITE_OK ){ |
| 80528 | + int lookasideEnabled = db->lookaside.bEnabled; |
| 80529 | + db->lookaside.bEnabled = 0; |
| 80317 | 80530 | rc = loadStat3(db, sInfo.zDatabase); |
| 80531 | + db->lookaside.bEnabled = lookasideEnabled; |
| 80318 | 80532 | } |
| 80319 | 80533 | #endif |
| 80320 | 80534 | |
| 80321 | 80535 | if( rc==SQLITE_NOMEM ){ |
| 80322 | 80536 | db->mallocFailed = 1; |
| | @@ -81675,11 +81889,11 @@ |
| 81675 | 81889 | sqliteDeleteColumnNames(db, pTable); |
| 81676 | 81890 | sqlite3DbFree(db, pTable->zName); |
| 81677 | 81891 | sqlite3DbFree(db, pTable->zColAff); |
| 81678 | 81892 | sqlite3SelectDelete(db, pTable->pSelect); |
| 81679 | 81893 | #ifndef SQLITE_OMIT_CHECK |
| 81680 | | - sqlite3ExprDelete(db, pTable->pCheck); |
| 81894 | + sqlite3ExprListDelete(db, pTable->pCheck); |
| 81681 | 81895 | #endif |
| 81682 | 81896 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 81683 | 81897 | sqlite3VtabClear(db, pTable); |
| 81684 | 81898 | #endif |
| 81685 | 81899 | sqlite3DbFree(db, pTable); |
| | @@ -82338,19 +82552,21 @@ |
| 82338 | 82552 | */ |
| 82339 | 82553 | SQLITE_PRIVATE void sqlite3AddCheckConstraint( |
| 82340 | 82554 | Parse *pParse, /* Parsing context */ |
| 82341 | 82555 | Expr *pCheckExpr /* The check expression */ |
| 82342 | 82556 | ){ |
| 82343 | | - sqlite3 *db = pParse->db; |
| 82344 | 82557 | #ifndef SQLITE_OMIT_CHECK |
| 82345 | 82558 | Table *pTab = pParse->pNewTable; |
| 82346 | 82559 | if( pTab && !IN_DECLARE_VTAB ){ |
| 82347 | | - pTab->pCheck = sqlite3ExprAnd(db, pTab->pCheck, pCheckExpr); |
| 82560 | + pTab->pCheck = sqlite3ExprListAppend(pParse, pTab->pCheck, pCheckExpr); |
| 82561 | + if( pParse->constraintName.n ){ |
| 82562 | + sqlite3ExprListSetName(pParse, pTab->pCheck, &pParse->constraintName, 1); |
| 82563 | + } |
| 82348 | 82564 | }else |
| 82349 | 82565 | #endif |
| 82350 | 82566 | { |
| 82351 | | - sqlite3ExprDelete(db, pCheckExpr); |
| 82567 | + sqlite3ExprDelete(pParse->db, pCheckExpr); |
| 82352 | 82568 | } |
| 82353 | 82569 | } |
| 82354 | 82570 | |
| 82355 | 82571 | /* |
| 82356 | 82572 | ** Set the collation function of the most recently parsed table column |
| | @@ -82616,10 +82832,12 @@ |
| 82616 | 82832 | /* Resolve names in all CHECK constraint expressions. |
| 82617 | 82833 | */ |
| 82618 | 82834 | if( p->pCheck ){ |
| 82619 | 82835 | SrcList sSrc; /* Fake SrcList for pParse->pNewTable */ |
| 82620 | 82836 | NameContext sNC; /* Name context for pParse->pNewTable */ |
| 82837 | + ExprList *pList; /* List of all CHECK constraints */ |
| 82838 | + int i; /* Loop counter */ |
| 82621 | 82839 | |
| 82622 | 82840 | memset(&sNC, 0, sizeof(sNC)); |
| 82623 | 82841 | memset(&sSrc, 0, sizeof(sSrc)); |
| 82624 | 82842 | sSrc.nSrc = 1; |
| 82625 | 82843 | sSrc.a[0].zName = p->zName; |
| | @@ -82626,12 +82844,15 @@ |
| 82626 | 82844 | sSrc.a[0].pTab = p; |
| 82627 | 82845 | sSrc.a[0].iCursor = -1; |
| 82628 | 82846 | sNC.pParse = pParse; |
| 82629 | 82847 | sNC.pSrcList = &sSrc; |
| 82630 | 82848 | sNC.isCheck = 1; |
| 82631 | | - if( sqlite3ResolveExprNames(&sNC, p->pCheck) ){ |
| 82632 | | - return; |
| 82849 | + pList = p->pCheck; |
| 82850 | + for(i=0; i<pList->nExpr; i++){ |
| 82851 | + if( sqlite3ResolveExprNames(&sNC, pList->a[i].pExpr) ){ |
| 82852 | + return; |
| 82853 | + } |
| 82633 | 82854 | } |
| 82634 | 82855 | } |
| 82635 | 82856 | #endif /* !defined(SQLITE_OMIT_CHECK) */ |
| 82636 | 82857 | |
| 82637 | 82858 | /* If the db->init.busy is 1 it means we are reading the SQL off the |
| | @@ -84178,23 +84399,25 @@ |
| 84178 | 84399 | exit_drop_index: |
| 84179 | 84400 | sqlite3SrcListDelete(db, pName); |
| 84180 | 84401 | } |
| 84181 | 84402 | |
| 84182 | 84403 | /* |
| 84183 | | -** pArray is a pointer to an array of objects. Each object in the |
| 84184 | | -** array is szEntry bytes in size. This routine allocates a new |
| 84185 | | -** object on the end of the array. |
| 84186 | | -** |
| 84187 | | -** *pnEntry is the number of entries already in use. *pnAlloc is |
| 84188 | | -** the previously allocated size of the array. initSize is the |
| 84189 | | -** suggested initial array size allocation. |
| 84190 | | -** |
| 84191 | | -** The index of the new entry is returned in *pIdx. |
| 84192 | | -** |
| 84193 | | -** This routine returns a pointer to the array of objects. This |
| 84194 | | -** might be the same as the pArray parameter or it might be a different |
| 84195 | | -** pointer if the array was resized. |
| 84404 | +** pArray is a pointer to an array of objects. Each object in the |
| 84405 | +** array is szEntry bytes in size. This routine uses sqlite3DbRealloc() |
| 84406 | +** to extend the array so that there is space for a new object at the end. |
| 84407 | +** |
| 84408 | +** When this function is called, *pnEntry contains the current size of |
| 84409 | +** the array (in entries - so the allocation is ((*pnEntry) * szEntry) bytes |
| 84410 | +** in total). |
| 84411 | +** |
| 84412 | +** If the realloc() is successful (i.e. if no OOM condition occurs), the |
| 84413 | +** space allocated for the new object is zeroed, *pnEntry updated to |
| 84414 | +** reflect the new size of the array and a pointer to the new allocation |
| 84415 | +** returned. *pIdx is set to the index of the new array entry in this case. |
| 84416 | +** |
| 84417 | +** Otherwise, if the realloc() fails, *pIdx is set to -1, *pnEntry remains |
| 84418 | +** unchanged and a copy of pArray returned. |
| 84196 | 84419 | */ |
| 84197 | 84420 | SQLITE_PRIVATE void *sqlite3ArrayAllocate( |
| 84198 | 84421 | sqlite3 *db, /* Connection to notify of malloc failures */ |
| 84199 | 84422 | void *pArray, /* Array of objects. Might be reallocated */ |
| 84200 | 84423 | int szEntry, /* Size of each object in the array */ |
| | @@ -85787,11 +86010,11 @@ |
| 85787 | 86010 | sqlite3VdbeAddOp2(v, OP_Null, 0, iRowSet); |
| 85788 | 86011 | pWInfo = sqlite3WhereBegin( |
| 85789 | 86012 | pParse, pTabList, pWhere, 0, 0, WHERE_DUPLICATES_OK |
| 85790 | 86013 | ); |
| 85791 | 86014 | if( pWInfo==0 ) goto delete_from_cleanup; |
| 85792 | | - regRowid = sqlite3ExprCodeGetColumn(pParse, pTab, -1, iCur, iRowid); |
| 86015 | + regRowid = sqlite3ExprCodeGetColumn(pParse, pTab, -1, iCur, iRowid, 0); |
| 85793 | 86016 | sqlite3VdbeAddOp2(v, OP_RowSetAdd, iRowSet, regRowid); |
| 85794 | 86017 | if( db->flags & SQLITE_CountRows ){ |
| 85795 | 86018 | sqlite3VdbeAddOp2(v, OP_AddImm, memCnt, 1); |
| 85796 | 86019 | } |
| 85797 | 86020 | sqlite3WhereEnd(pWInfo); |
| | @@ -87607,12 +87830,12 @@ |
| 87607 | 87830 | FUNCTION(min, 0, 0, 1, 0 ), |
| 87608 | 87831 | AGGREGATE(min, 1, 0, 1, minmaxStep, minMaxFinalize ), |
| 87609 | 87832 | FUNCTION(max, -1, 1, 1, minmaxFunc ), |
| 87610 | 87833 | FUNCTION(max, 0, 1, 1, 0 ), |
| 87611 | 87834 | AGGREGATE(max, 1, 1, 1, minmaxStep, minMaxFinalize ), |
| 87612 | | - FUNCTION(typeof, 1, 0, 0, typeofFunc ), |
| 87613 | | - FUNCTION(length, 1, 0, 0, lengthFunc ), |
| 87835 | + FUNCTION2(typeof, 1, 0, 0, typeofFunc, SQLITE_FUNC_TYPEOF), |
| 87836 | + FUNCTION2(length, 1, 0, 0, lengthFunc, SQLITE_FUNC_LENGTH), |
| 87614 | 87837 | FUNCTION(substr, 2, 0, 0, substrFunc ), |
| 87615 | 87838 | FUNCTION(substr, 3, 0, 0, substrFunc ), |
| 87616 | 87839 | FUNCTION(abs, 1, 0, 0, absFunc ), |
| 87617 | 87840 | #ifndef SQLITE_OMIT_FLOATING_POINT |
| 87618 | 87841 | FUNCTION(round, 1, 0, 0, roundFunc ), |
| | @@ -87620,15 +87843,13 @@ |
| 87620 | 87843 | #endif |
| 87621 | 87844 | FUNCTION(upper, 1, 0, 0, upperFunc ), |
| 87622 | 87845 | FUNCTION(lower, 1, 0, 0, lowerFunc ), |
| 87623 | 87846 | FUNCTION(coalesce, 1, 0, 0, 0 ), |
| 87624 | 87847 | FUNCTION(coalesce, 0, 0, 0, 0 ), |
| 87625 | | -/* FUNCTION(coalesce, -1, 0, 0, ifnullFunc ), */ |
| 87626 | | - {-1,SQLITE_UTF8,SQLITE_FUNC_COALESCE,0,0,ifnullFunc,0,0,"coalesce",0,0}, |
| 87848 | + FUNCTION2(coalesce, -1, 0, 0, ifnullFunc, SQLITE_FUNC_COALESCE), |
| 87627 | 87849 | FUNCTION(hex, 1, 0, 0, hexFunc ), |
| 87628 | | -/* FUNCTION(ifnull, 2, 0, 0, ifnullFunc ), */ |
| 87629 | | - {2,SQLITE_UTF8,SQLITE_FUNC_COALESCE,0,0,ifnullFunc,0,0,"ifnull",0,0}, |
| 87850 | + FUNCTION2(ifnull, 2, 0, 0, ifnullFunc, SQLITE_FUNC_COALESCE), |
| 87630 | 87851 | FUNCTION(random, 0, 0, 0, randomFunc ), |
| 87631 | 87852 | FUNCTION(randomblob, 1, 0, 0, randomBlob ), |
| 87632 | 87853 | FUNCTION(nullif, 2, 0, 1, nullifFunc ), |
| 87633 | 87854 | FUNCTION(sqlite_version, 0, 0, 0, versionFunc ), |
| 87634 | 87855 | FUNCTION(sqlite_source_id, 0, 0, 0, sourceidFunc ), |
| | @@ -90061,13 +90282,15 @@ |
| 90061 | 90282 | int j1; /* Addresss of jump instruction */ |
| 90062 | 90283 | int j2 = 0, j3; /* Addresses of jump instructions */ |
| 90063 | 90284 | int regData; /* Register containing first data column */ |
| 90064 | 90285 | int iCur; /* Table cursor number */ |
| 90065 | 90286 | Index *pIdx; /* Pointer to one of the indices */ |
| 90287 | + sqlite3 *db; /* Database connection */ |
| 90066 | 90288 | int seenReplace = 0; /* True if REPLACE is used to resolve INT PK conflict */ |
| 90067 | 90289 | int regOldRowid = (rowidChng && isUpdate) ? rowidChng : regRowid; |
| 90068 | 90290 | |
| 90291 | + db = pParse->db; |
| 90069 | 90292 | v = sqlite3GetVdbe(pParse); |
| 90070 | 90293 | assert( v!=0 ); |
| 90071 | 90294 | assert( pTab->pSelect==0 ); /* This table is not a VIEW */ |
| 90072 | 90295 | nCol = pTab->nCol; |
| 90073 | 90296 | regData = regRowid + 1; |
| | @@ -90096,11 +90319,11 @@ |
| 90096 | 90319 | case OE_Rollback: |
| 90097 | 90320 | case OE_Fail: { |
| 90098 | 90321 | char *zMsg; |
| 90099 | 90322 | sqlite3VdbeAddOp3(v, OP_HaltIfNull, |
| 90100 | 90323 | SQLITE_CONSTRAINT, onError, regData+i); |
| 90101 | | - zMsg = sqlite3MPrintf(pParse->db, "%s.%s may not be NULL", |
| 90324 | + zMsg = sqlite3MPrintf(db, "%s.%s may not be NULL", |
| 90102 | 90325 | pTab->zName, pTab->aCol[i].zName); |
| 90103 | 90326 | sqlite3VdbeChangeP4(v, -1, zMsg, P4_DYNAMIC); |
| 90104 | 90327 | break; |
| 90105 | 90328 | } |
| 90106 | 90329 | case OE_Ignore: { |
| | @@ -90118,22 +90341,31 @@ |
| 90118 | 90341 | } |
| 90119 | 90342 | |
| 90120 | 90343 | /* Test all CHECK constraints |
| 90121 | 90344 | */ |
| 90122 | 90345 | #ifndef SQLITE_OMIT_CHECK |
| 90123 | | - if( pTab->pCheck && (pParse->db->flags & SQLITE_IgnoreChecks)==0 ){ |
| 90124 | | - int allOk = sqlite3VdbeMakeLabel(v); |
| 90346 | + if( pTab->pCheck && (db->flags & SQLITE_IgnoreChecks)==0 ){ |
| 90347 | + ExprList *pCheck = pTab->pCheck; |
| 90125 | 90348 | pParse->ckBase = regData; |
| 90126 | | - sqlite3ExprIfTrue(pParse, pTab->pCheck, allOk, SQLITE_JUMPIFNULL); |
| 90127 | 90349 | onError = overrideError!=OE_Default ? overrideError : OE_Abort; |
| 90128 | | - if( onError==OE_Ignore ){ |
| 90129 | | - sqlite3VdbeAddOp2(v, OP_Goto, 0, ignoreDest); |
| 90130 | | - }else{ |
| 90131 | | - if( onError==OE_Replace ) onError = OE_Abort; /* IMP: R-15569-63625 */ |
| 90132 | | - sqlite3HaltConstraint(pParse, onError, 0, 0); |
| 90350 | + for(i=0; i<pCheck->nExpr; i++){ |
| 90351 | + int allOk = sqlite3VdbeMakeLabel(v); |
| 90352 | + sqlite3ExprIfTrue(pParse, pCheck->a[i].pExpr, allOk, SQLITE_JUMPIFNULL); |
| 90353 | + if( onError==OE_Ignore ){ |
| 90354 | + sqlite3VdbeAddOp2(v, OP_Goto, 0, ignoreDest); |
| 90355 | + }else{ |
| 90356 | + char *zConsName = pCheck->a[i].zName; |
| 90357 | + if( onError==OE_Replace ) onError = OE_Abort; /* IMP: R-15569-63625 */ |
| 90358 | + if( zConsName ){ |
| 90359 | + zConsName = sqlite3MPrintf(db, "constraint %s failed", zConsName); |
| 90360 | + }else{ |
| 90361 | + zConsName = 0; |
| 90362 | + } |
| 90363 | + sqlite3HaltConstraint(pParse, onError, zConsName, P4_DYNAMIC); |
| 90364 | + } |
| 90365 | + sqlite3VdbeResolveLabel(v, allOk); |
| 90133 | 90366 | } |
| 90134 | | - sqlite3VdbeResolveLabel(v, allOk); |
| 90135 | 90367 | } |
| 90136 | 90368 | #endif /* !defined(SQLITE_OMIT_CHECK) */ |
| 90137 | 90369 | |
| 90138 | 90370 | /* If we have an INTEGER PRIMARY KEY, make sure the primary key |
| 90139 | 90371 | ** of the new record does not previously exist. Except, if this |
| | @@ -90185,11 +90417,11 @@ |
| 90185 | 90417 | ** |
| 90186 | 90418 | ** to run without a statement journal if there are no indexes on the |
| 90187 | 90419 | ** table. |
| 90188 | 90420 | */ |
| 90189 | 90421 | Trigger *pTrigger = 0; |
| 90190 | | - if( pParse->db->flags&SQLITE_RecTriggers ){ |
| 90422 | + if( db->flags&SQLITE_RecTriggers ){ |
| 90191 | 90423 | pTrigger = sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0, 0); |
| 90192 | 90424 | } |
| 90193 | 90425 | if( pTrigger || sqlite3FkRequired(pParse, pTab, 0, 0) ){ |
| 90194 | 90426 | sqlite3MultiWrite(pParse); |
| 90195 | 90427 | sqlite3GenerateRowDelete( |
| | @@ -90274,11 +90506,11 @@ |
| 90274 | 90506 | StrAccum errMsg; |
| 90275 | 90507 | const char *zSep; |
| 90276 | 90508 | char *zErr; |
| 90277 | 90509 | |
| 90278 | 90510 | sqlite3StrAccumInit(&errMsg, 0, 0, 200); |
| 90279 | | - errMsg.db = pParse->db; |
| 90511 | + errMsg.db = db; |
| 90280 | 90512 | zSep = pIdx->nColumn>1 ? "columns " : "column "; |
| 90281 | 90513 | for(j=0; j<pIdx->nColumn; j++){ |
| 90282 | 90514 | char *zCol = pTab->aCol[pIdx->aiColumn[j]].zName; |
| 90283 | 90515 | sqlite3StrAccumAppend(&errMsg, zSep, -1); |
| 90284 | 90516 | zSep = ", "; |
| | @@ -90298,11 +90530,11 @@ |
| 90298 | 90530 | } |
| 90299 | 90531 | default: { |
| 90300 | 90532 | Trigger *pTrigger = 0; |
| 90301 | 90533 | assert( onError==OE_Replace ); |
| 90302 | 90534 | sqlite3MultiWrite(pParse); |
| 90303 | | - if( pParse->db->flags&SQLITE_RecTriggers ){ |
| 90535 | + if( db->flags&SQLITE_RecTriggers ){ |
| 90304 | 90536 | pTrigger = sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0, 0); |
| 90305 | 90537 | } |
| 90306 | 90538 | sqlite3GenerateRowDelete( |
| 90307 | 90539 | pParse, pTab, baseCur, regR, 0, pTrigger, OE_Replace |
| 90308 | 90540 | ); |
| | @@ -90628,11 +90860,11 @@ |
| 90628 | 90860 | if( pSrcIdx==0 ){ |
| 90629 | 90861 | return 0; /* pDestIdx has no corresponding index in pSrc */ |
| 90630 | 90862 | } |
| 90631 | 90863 | } |
| 90632 | 90864 | #ifndef SQLITE_OMIT_CHECK |
| 90633 | | - if( pDest->pCheck && sqlite3ExprCompare(pSrc->pCheck, pDest->pCheck) ){ |
| 90865 | + if( pDest->pCheck && sqlite3ExprListCompare(pSrc->pCheck, pDest->pCheck) ){ |
| 90634 | 90866 | return 0; /* Tables have different CHECK constraints. Ticket #2252 */ |
| 90635 | 90867 | } |
| 90636 | 90868 | #endif |
| 90637 | 90869 | #ifndef SQLITE_OMIT_FOREIGN_KEY |
| 90638 | 90870 | /* Disallow the transfer optimization if the destination table constains |
| | @@ -92317,13 +92549,16 @@ |
| 92317 | 92549 | char *zLeft = 0; /* Nul-terminated UTF-8 string <id> */ |
| 92318 | 92550 | char *zRight = 0; /* Nul-terminated UTF-8 string <value>, or NULL */ |
| 92319 | 92551 | const char *zDb = 0; /* The database name */ |
| 92320 | 92552 | Token *pId; /* Pointer to <id> token */ |
| 92321 | 92553 | int iDb; /* Database index for <database> */ |
| 92322 | | - sqlite3 *db = pParse->db; |
| 92323 | | - Db *pDb; |
| 92324 | | - Vdbe *v = pParse->pVdbe = sqlite3VdbeCreate(db); |
| 92554 | + char *aFcntl[4]; /* Argument to SQLITE_FCNTL_PRAGMA */ |
| 92555 | + int rc; /* return value form SQLITE_FCNTL_PRAGMA */ |
| 92556 | + sqlite3 *db = pParse->db; /* The database connection */ |
| 92557 | + Db *pDb; /* The specific database being pragmaed */ |
| 92558 | + Vdbe *v = pParse->pVdbe = sqlite3VdbeCreate(db); /* Prepared statement */ |
| 92559 | + |
| 92325 | 92560 | if( v==0 ) return; |
| 92326 | 92561 | sqlite3VdbeRunOnlyOnce(v); |
| 92327 | 92562 | pParse->nMem = 2; |
| 92328 | 92563 | |
| 92329 | 92564 | /* Interpret the [database.] part of the pragma statement. iDb is the |
| | @@ -92350,10 +92585,38 @@ |
| 92350 | 92585 | assert( pId2 ); |
| 92351 | 92586 | zDb = pId2->n>0 ? pDb->zName : 0; |
| 92352 | 92587 | if( sqlite3AuthCheck(pParse, SQLITE_PRAGMA, zLeft, zRight, zDb) ){ |
| 92353 | 92588 | goto pragma_out; |
| 92354 | 92589 | } |
| 92590 | + |
| 92591 | + /* Send an SQLITE_FCNTL_PRAGMA file-control to the underlying VFS |
| 92592 | + ** connection. If it returns SQLITE_OK, then assume that the VFS |
| 92593 | + ** handled the pragma and generate a no-op prepared statement. |
| 92594 | + */ |
| 92595 | + aFcntl[0] = 0; |
| 92596 | + aFcntl[1] = zLeft; |
| 92597 | + aFcntl[2] = zRight; |
| 92598 | + aFcntl[3] = 0; |
| 92599 | + rc = sqlite3_file_control(db, zDb, SQLITE_FCNTL_PRAGMA, (void*)aFcntl); |
| 92600 | + if( rc==SQLITE_OK ){ |
| 92601 | + if( aFcntl[0] ){ |
| 92602 | + int mem = ++pParse->nMem; |
| 92603 | + sqlite3VdbeAddOp4(v, OP_String8, 0, mem, 0, aFcntl[0], 0); |
| 92604 | + sqlite3VdbeSetNumCols(v, 1); |
| 92605 | + sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "result", SQLITE_STATIC); |
| 92606 | + sqlite3VdbeAddOp2(v, OP_ResultRow, mem, 1); |
| 92607 | + sqlite3_free(aFcntl[0]); |
| 92608 | + } |
| 92609 | + }else if( rc!=SQLITE_NOTFOUND ){ |
| 92610 | + if( aFcntl[0] ){ |
| 92611 | + sqlite3ErrorMsg(pParse, "%s", aFcntl[0]); |
| 92612 | + sqlite3_free(aFcntl[0]); |
| 92613 | + } |
| 92614 | + pParse->nErr++; |
| 92615 | + pParse->rc = rc; |
| 92616 | + }else |
| 92617 | + |
| 92355 | 92618 | |
| 92356 | 92619 | #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED) |
| 92357 | 92620 | /* |
| 92358 | 92621 | ** PRAGMA [database.]default_cache_size |
| 92359 | 92622 | ** PRAGMA [database.]default_cache_size=N |
| | @@ -92637,11 +92900,11 @@ |
| 92637 | 92900 | /* Call SetAutoVacuum() to set initialize the internal auto and |
| 92638 | 92901 | ** incr-vacuum flags. This is required in case this connection |
| 92639 | 92902 | ** creates the database file. It is important that it is created |
| 92640 | 92903 | ** as an auto-vacuum capable db. |
| 92641 | 92904 | */ |
| 92642 | | - int rc = sqlite3BtreeSetAutoVacuum(pBt, eAuto); |
| 92905 | + rc = sqlite3BtreeSetAutoVacuum(pBt, eAuto); |
| 92643 | 92906 | if( rc==SQLITE_OK && (eAuto==1 || eAuto==2) ){ |
| 92644 | 92907 | /* When setting the auto_vacuum mode to either "full" or |
| 92645 | 92908 | ** "incremental", write the value of meta[6] in the database |
| 92646 | 92909 | ** file. Before writing to meta[6], check that meta[3] indicates |
| 92647 | 92910 | ** that this really is an auto-vacuum capable database. |
| | @@ -92755,11 +93018,10 @@ |
| 92755 | 93018 | sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1); |
| 92756 | 93019 | } |
| 92757 | 93020 | }else{ |
| 92758 | 93021 | #ifndef SQLITE_OMIT_WSD |
| 92759 | 93022 | if( zRight[0] ){ |
| 92760 | | - int rc; |
| 92761 | 93023 | int res; |
| 92762 | 93024 | rc = sqlite3OsAccess(db->pVfs, zRight, SQLITE_ACCESS_READWRITE, &res); |
| 92763 | 93025 | if( rc!=SQLITE_OK || res==0 ){ |
| 92764 | 93026 | sqlite3ErrorMsg(pParse, "not a writable directory"); |
| 92765 | 93027 | goto pragma_out; |
| | @@ -95671,13 +95933,21 @@ |
| 95671 | 95933 | int nCol; /* Number of columns in the result set */ |
| 95672 | 95934 | Expr *p; /* Expression for a single result column */ |
| 95673 | 95935 | char *zName; /* Column name */ |
| 95674 | 95936 | int nName; /* Size of name in zName[] */ |
| 95675 | 95937 | |
| 95676 | | - *pnCol = nCol = pEList->nExpr; |
| 95677 | | - aCol = *paCol = sqlite3DbMallocZero(db, sizeof(aCol[0])*nCol); |
| 95678 | | - if( aCol==0 ) return SQLITE_NOMEM; |
| 95938 | + if( pEList ){ |
| 95939 | + nCol = pEList->nExpr; |
| 95940 | + aCol = sqlite3DbMallocZero(db, sizeof(aCol[0])*nCol); |
| 95941 | + testcase( aCol==0 ); |
| 95942 | + }else{ |
| 95943 | + nCol = 0; |
| 95944 | + aCol = 0; |
| 95945 | + } |
| 95946 | + *pnCol = nCol; |
| 95947 | + *paCol = aCol; |
| 95948 | + |
| 95679 | 95949 | for(i=0, pCol=aCol; i<nCol; i++, pCol++){ |
| 95680 | 95950 | /* Get an appropriate name for the column |
| 95681 | 95951 | */ |
| 95682 | 95952 | p = pEList->a[i].pExpr; |
| 95683 | 95953 | assert( p->pRight==0 || ExprHasProperty(p->pRight, EP_IntValue) |
| | @@ -98641,11 +98911,11 @@ |
| 98641 | 98911 | if( pCol->iSorterColumn>=j ){ |
| 98642 | 98912 | int r1 = j + regBase; |
| 98643 | 98913 | int r2; |
| 98644 | 98914 | |
| 98645 | 98915 | r2 = sqlite3ExprCodeGetColumn(pParse, |
| 98646 | | - pCol->pTab, pCol->iColumn, pCol->iTable, r1); |
| 98916 | + pCol->pTab, pCol->iColumn, pCol->iTable, r1, 0); |
| 98647 | 98917 | if( r1!=r2 ){ |
| 98648 | 98918 | sqlite3VdbeAddOp2(v, OP_SCopy, r2, r1); |
| 98649 | 98919 | } |
| 98650 | 98920 | j++; |
| 98651 | 98921 | } |
| | @@ -101201,10 +101471,22 @@ |
| 101201 | 101471 | char *zKey; |
| 101202 | 101472 | sqlite3CodecGetKey(db, 0, (void**)&zKey, &nKey); |
| 101203 | 101473 | if( nKey ) db->nextPagesize = 0; |
| 101204 | 101474 | } |
| 101205 | 101475 | #endif |
| 101476 | + |
| 101477 | + rc = execSql(db, pzErrMsg, "PRAGMA vacuum_db.synchronous=OFF"); |
| 101478 | + if( rc!=SQLITE_OK ) goto end_of_vacuum; |
| 101479 | + |
| 101480 | + /* Begin a transaction and take an exclusive lock on the main database |
| 101481 | + ** file. This is done before the sqlite3BtreeGetPageSize(pMain) call below, |
| 101482 | + ** to ensure that we do not try to change the page-size on a WAL database. |
| 101483 | + */ |
| 101484 | + rc = execSql(db, pzErrMsg, "BEGIN;"); |
| 101485 | + if( rc!=SQLITE_OK ) goto end_of_vacuum; |
| 101486 | + rc = sqlite3BtreeBeginTrans(pMain, 2); |
| 101487 | + if( rc!=SQLITE_OK ) goto end_of_vacuum; |
| 101206 | 101488 | |
| 101207 | 101489 | /* Do not attempt to change the page size for a WAL database */ |
| 101208 | 101490 | if( sqlite3PagerGetJournalMode(sqlite3BtreePager(pMain)) |
| 101209 | 101491 | ==PAGER_JOURNALMODE_WAL ){ |
| 101210 | 101492 | db->nextPagesize = 0; |
| | @@ -101215,24 +101497,16 @@ |
| 101215 | 101497 | || NEVER(db->mallocFailed) |
| 101216 | 101498 | ){ |
| 101217 | 101499 | rc = SQLITE_NOMEM; |
| 101218 | 101500 | goto end_of_vacuum; |
| 101219 | 101501 | } |
| 101220 | | - rc = execSql(db, pzErrMsg, "PRAGMA vacuum_db.synchronous=OFF"); |
| 101221 | | - if( rc!=SQLITE_OK ){ |
| 101222 | | - goto end_of_vacuum; |
| 101223 | | - } |
| 101224 | 101502 | |
| 101225 | 101503 | #ifndef SQLITE_OMIT_AUTOVACUUM |
| 101226 | 101504 | sqlite3BtreeSetAutoVacuum(pTemp, db->nextAutovac>=0 ? db->nextAutovac : |
| 101227 | 101505 | sqlite3BtreeGetAutoVacuum(pMain)); |
| 101228 | 101506 | #endif |
| 101229 | 101507 | |
| 101230 | | - /* Begin a transaction */ |
| 101231 | | - rc = execSql(db, pzErrMsg, "BEGIN EXCLUSIVE;"); |
| 101232 | | - if( rc!=SQLITE_OK ) goto end_of_vacuum; |
| 101233 | | - |
| 101234 | 101508 | /* Query the schema of the main database. Create a mirror schema |
| 101235 | 101509 | ** in the temporary database. |
| 101236 | 101510 | */ |
| 101237 | 101511 | rc = execExecSql(db, pzErrMsg, |
| 101238 | 101512 | "SELECT 'CREATE TABLE vacuum_db.' || substr(sql,14) " |
| | @@ -103126,11 +103400,14 @@ |
| 103126 | 103400 | #ifdef SQLITE_EBCDIC |
| 103127 | 103401 | if( *pnoCase ) return 0; |
| 103128 | 103402 | #endif |
| 103129 | 103403 | pList = pExpr->x.pList; |
| 103130 | 103404 | pLeft = pList->a[1].pExpr; |
| 103131 | | - if( pLeft->op!=TK_COLUMN || sqlite3ExprAffinity(pLeft)!=SQLITE_AFF_TEXT ){ |
| 103405 | + if( pLeft->op!=TK_COLUMN |
| 103406 | + || sqlite3ExprAffinity(pLeft)!=SQLITE_AFF_TEXT |
| 103407 | + || IsVirtual(pLeft->pTab) |
| 103408 | + ){ |
| 103132 | 103409 | /* IMP: R-02065-49465 The left-hand side of the LIKE or GLOB operator must |
| 103133 | 103410 | ** be the name of an indexed column with TEXT affinity. */ |
| 103134 | 103411 | return 0; |
| 103135 | 103412 | } |
| 103136 | 103413 | assert( pLeft->iColumn!=(-1) ); /* Because IPK never has AFF_TEXT */ |
| | @@ -105543,11 +105820,13 @@ |
| 105543 | 105820 | } |
| 105544 | 105821 | |
| 105545 | 105822 | /* If there is a DISTINCT qualifier and this index will scan rows in |
| 105546 | 105823 | ** order of the DISTINCT expressions, clear bDist and set the appropriate |
| 105547 | 105824 | ** flags in wsFlags. */ |
| 105548 | | - if( isDistinctIndex(pParse, pWC, pProbe, iCur, pDistinct, nEq) ){ |
| 105825 | + if( isDistinctIndex(pParse, pWC, pProbe, iCur, pDistinct, nEq) |
| 105826 | + && (wsFlags & WHERE_COLUMN_IN)==0 |
| 105827 | + ){ |
| 105549 | 105828 | bDist = 0; |
| 105550 | 105829 | wsFlags |= WHERE_ROWID_RANGE|WHERE_COLUMN_RANGE|WHERE_DISTINCT; |
| 105551 | 105830 | } |
| 105552 | 105831 | |
| 105553 | 105832 | /* If currently calculating the cost of using an index (not the IPK |
| | @@ -106240,12 +106519,11 @@ |
| 106240 | 106519 | */ |
| 106241 | 106520 | static Bitmask codeOneLoopStart( |
| 106242 | 106521 | WhereInfo *pWInfo, /* Complete information about the WHERE clause */ |
| 106243 | 106522 | int iLevel, /* Which level of pWInfo->a[] should be coded */ |
| 106244 | 106523 | u16 wctrlFlags, /* One of the WHERE_* flags defined in sqliteInt.h */ |
| 106245 | | - Bitmask notReady, /* Which tables are currently available */ |
| 106246 | | - Expr *pWhere /* Complete WHERE clause */ |
| 106524 | + Bitmask notReady /* Which tables are currently available */ |
| 106247 | 106525 | ){ |
| 106248 | 106526 | int j, k; /* Loop counters */ |
| 106249 | 106527 | int iCur; /* The VDBE cursor for the table */ |
| 106250 | 106528 | int addrNxt; /* Where to jump to continue with the next IN case */ |
| 106251 | 106529 | int omitTable; /* True if we use the index only */ |
| | @@ -106780,14 +107058,29 @@ |
| 106780 | 107058 | |
| 106781 | 107059 | /* If the original WHERE clause is z of the form: (x1 OR x2 OR ...) AND y |
| 106782 | 107060 | ** Then for every term xN, evaluate as the subexpression: xN AND z |
| 106783 | 107061 | ** That way, terms in y that are factored into the disjunction will |
| 106784 | 107062 | ** be picked up by the recursive calls to sqlite3WhereBegin() below. |
| 107063 | + ** |
| 107064 | + ** Actually, each subexpression is converted to "xN AND w" where w is |
| 107065 | + ** the "interesting" terms of z - terms that did not originate in the |
| 107066 | + ** ON or USING clause of a LEFT JOIN, and terms that are usable as |
| 107067 | + ** indices. |
| 106785 | 107068 | */ |
| 106786 | 107069 | if( pWC->nTerm>1 ){ |
| 106787 | | - pAndExpr = sqlite3ExprAlloc(pParse->db, TK_AND, 0, 0); |
| 106788 | | - pAndExpr->pRight = pWhere; |
| 107070 | + int iTerm; |
| 107071 | + for(iTerm=0; iTerm<pWC->nTerm; iTerm++){ |
| 107072 | + Expr *pExpr = pWC->a[iTerm].pExpr; |
| 107073 | + if( ExprHasProperty(pExpr, EP_FromJoin) ) continue; |
| 107074 | + if( pWC->a[iTerm].wtFlags & (TERM_VIRTUAL|TERM_ORINFO) ) continue; |
| 107075 | + if( (pWC->a[iTerm].eOperator & WO_ALL)==0 ) continue; |
| 107076 | + pExpr = sqlite3ExprDup(pParse->db, pExpr, 0); |
| 107077 | + pAndExpr = sqlite3ExprAnd(pParse->db, pAndExpr, pExpr); |
| 107078 | + } |
| 107079 | + if( pAndExpr ){ |
| 107080 | + pAndExpr = sqlite3PExpr(pParse, TK_AND, 0, pAndExpr, 0); |
| 107081 | + } |
| 106789 | 107082 | } |
| 106790 | 107083 | |
| 106791 | 107084 | for(ii=0; ii<pOrWc->nTerm; ii++){ |
| 106792 | 107085 | WhereTerm *pOrTerm = &pOrWc->a[ii]; |
| 106793 | 107086 | if( pOrTerm->leftCursor==iCur || pOrTerm->eOperator==WO_AND ){ |
| | @@ -106807,11 +107100,11 @@ |
| 106807 | 107100 | ); |
| 106808 | 107101 | if( (wctrlFlags & WHERE_DUPLICATES_OK)==0 ){ |
| 106809 | 107102 | int iSet = ((ii==pOrWc->nTerm-1)?-1:ii); |
| 106810 | 107103 | int r; |
| 106811 | 107104 | r = sqlite3ExprCodeGetColumn(pParse, pTabItem->pTab, -1, iCur, |
| 106812 | | - regRowid); |
| 107105 | + regRowid, 0); |
| 106813 | 107106 | sqlite3VdbeAddOp4Int(v, OP_RowSetTest, regRowset, |
| 106814 | 107107 | sqlite3VdbeCurrentAddr(v)+2, r, iSet); |
| 106815 | 107108 | } |
| 106816 | 107109 | sqlite3VdbeAddOp2(v, OP_Gosub, regReturn, iLoopBody); |
| 106817 | 107110 | |
| | @@ -106825,11 +107118,14 @@ |
| 106825 | 107118 | /* Finish the loop through table entries that match term pOrTerm. */ |
| 106826 | 107119 | sqlite3WhereEnd(pSubWInfo); |
| 106827 | 107120 | } |
| 106828 | 107121 | } |
| 106829 | 107122 | } |
| 106830 | | - sqlite3DbFree(pParse->db, pAndExpr); |
| 107123 | + if( pAndExpr ){ |
| 107124 | + pAndExpr->pLeft = 0; |
| 107125 | + sqlite3ExprDelete(pParse->db, pAndExpr); |
| 107126 | + } |
| 106831 | 107127 | sqlite3VdbeChangeP1(v, iRetInit, sqlite3VdbeCurrentAddr(v)); |
| 106832 | 107128 | sqlite3VdbeAddOp2(v, OP_Goto, 0, pLevel->addrBrk); |
| 106833 | 107129 | sqlite3VdbeResolveLabel(v, iLoopBody); |
| 106834 | 107130 | |
| 106835 | 107131 | if( pWInfo->nLevel>1 ) sqlite3StackFree(pParse->db, pOrTab); |
| | @@ -107481,11 +107777,11 @@ |
| 107481 | 107777 | */ |
| 107482 | 107778 | notReady = ~(Bitmask)0; |
| 107483 | 107779 | for(i=0; i<nTabList; i++){ |
| 107484 | 107780 | pLevel = &pWInfo->a[i]; |
| 107485 | 107781 | explainOneScan(pParse, pTabList, pLevel, i, pLevel->iFrom, wctrlFlags); |
| 107486 | | - notReady = codeOneLoopStart(pWInfo, i, wctrlFlags, notReady, pWhere); |
| 107782 | + notReady = codeOneLoopStart(pWInfo, i, wctrlFlags, notReady); |
| 107487 | 107783 | pWInfo->iContinue = pLevel->addrCont; |
| 107488 | 107784 | } |
| 107489 | 107785 | |
| 107490 | 107786 | #ifdef SQLITE_TEST /* For testing and debugging use only */ |
| 107491 | 107787 | /* Record in the query plan information about the current table |
| | @@ -107717,11 +108013,11 @@ |
| 107717 | 108013 | ** An instance of this structure is used to store the LIKE, |
| 107718 | 108014 | ** GLOB, NOT LIKE, and NOT GLOB operators. |
| 107719 | 108015 | */ |
| 107720 | 108016 | struct LikeOp { |
| 107721 | 108017 | Token eOperator; /* "like" or "glob" or "regexp" */ |
| 107722 | | - int not; /* True if the NOT keyword is present */ |
| 108018 | + int bNot; /* True if the NOT keyword is present */ |
| 107723 | 108019 | }; |
| 107724 | 108020 | |
| 107725 | 108021 | /* |
| 107726 | 108022 | ** An instance of the following structure describes the event of a |
| 107727 | 108023 | ** TRIGGER. "a" is the event type, one of TK_UPDATE, TK_INSERT, |
| | @@ -107896,12 +108192,12 @@ |
| 107896 | 108192 | #endif |
| 107897 | 108193 | #define sqlite3ParserARG_SDECL Parse *pParse; |
| 107898 | 108194 | #define sqlite3ParserARG_PDECL ,Parse *pParse |
| 107899 | 108195 | #define sqlite3ParserARG_FETCH Parse *pParse = yypParser->pParse |
| 107900 | 108196 | #define sqlite3ParserARG_STORE yypParser->pParse = pParse |
| 107901 | | -#define YYNSTATE 629 |
| 107902 | | -#define YYNRULE 327 |
| 108197 | +#define YYNSTATE 627 |
| 108198 | +#define YYNRULE 325 |
| 107903 | 108199 | #define YYFALLBACK 1 |
| 107904 | 108200 | #define YY_NO_ACTION (YYNSTATE+YYNRULE+2) |
| 107905 | 108201 | #define YY_ACCEPT_ACTION (YYNSTATE+YYNRULE+1) |
| 107906 | 108202 | #define YY_ERROR_ACTION (YYNSTATE+YYNRULE) |
| 107907 | 108203 | |
| | @@ -107967,480 +108263,478 @@ |
| 107967 | 108263 | ** shifting terminals. |
| 107968 | 108264 | ** yy_reduce_ofst[] For each state, the offset into yy_action for |
| 107969 | 108265 | ** shifting non-terminals after a reduce. |
| 107970 | 108266 | ** yy_default[] Default action for each state. |
| 107971 | 108267 | */ |
| 107972 | | -#define YY_ACTTAB_COUNT (1580) |
| 108268 | +#define YY_ACTTAB_COUNT (1561) |
| 107973 | 108269 | static const YYACTIONTYPE yy_action[] = { |
| 107974 | | - /* 0 */ 310, 328, 574, 573, 15, 172, 187, 596, 56, 56, |
| 108270 | + /* 0 */ 310, 328, 573, 572, 15, 171, 185, 595, 56, 56, |
| 107975 | 108271 | /* 10 */ 56, 56, 49, 54, 54, 54, 54, 53, 53, 52, |
| 107976 | | - /* 20 */ 52, 52, 51, 234, 622, 621, 626, 622, 621, 299, |
| 107977 | | - /* 30 */ 589, 583, 56, 56, 56, 56, 236, 54, 54, 54, |
| 107978 | | - /* 40 */ 54, 53, 53, 52, 52, 52, 51, 234, 351, 57, |
| 107979 | | - /* 50 */ 58, 48, 581, 580, 582, 582, 55, 55, 56, 56, |
| 107980 | | - /* 60 */ 56, 56, 570, 54, 54, 54, 54, 53, 53, 52, |
| 107981 | | - /* 70 */ 52, 52, 51, 234, 310, 596, 326, 607, 233, 232, |
| 108272 | + /* 20 */ 52, 52, 51, 233, 52, 52, 52, 51, 233, 624, |
| 108273 | + /* 30 */ 588, 582, 56, 56, 56, 56, 314, 54, 54, 54, |
| 108274 | + /* 40 */ 54, 53, 53, 52, 52, 52, 51, 233, 299, 57, |
| 108275 | + /* 50 */ 58, 48, 580, 579, 581, 581, 55, 55, 56, 56, |
| 108276 | + /* 60 */ 56, 56, 569, 54, 54, 54, 54, 53, 53, 52, |
| 108277 | + /* 70 */ 52, 52, 51, 233, 310, 595, 326, 575, 663, 65, |
| 107982 | 108278 | /* 80 */ 33, 54, 54, 54, 54, 53, 53, 52, 52, 52, |
| 107983 | | - /* 90 */ 51, 234, 619, 618, 326, 619, 618, 166, 605, 492, |
| 107984 | | - /* 100 */ 381, 378, 377, 235, 589, 583, 554, 495, 1, 59, |
| 107985 | | - /* 110 */ 19, 376, 622, 621, 53, 53, 52, 52, 52, 51, |
| 107986 | | - /* 120 */ 234, 571, 571, 57, 58, 48, 581, 580, 582, 582, |
| 107987 | | - /* 130 */ 55, 55, 56, 56, 56, 56, 215, 54, 54, 54, |
| 107988 | | - /* 140 */ 54, 53, 53, 52, 52, 52, 51, 234, 310, 224, |
| 107989 | | - /* 150 */ 50, 47, 147, 177, 139, 281, 384, 276, 383, 169, |
| 107990 | | - /* 160 */ 408, 553, 578, 578, 622, 621, 272, 224, 439, 550, |
| 107991 | | - /* 170 */ 552, 410, 139, 281, 384, 276, 383, 169, 589, 583, |
| 107992 | | - /* 180 */ 619, 618, 280, 620, 272, 195, 413, 309, 440, 441, |
| 107993 | | - /* 190 */ 567, 491, 214, 279, 560, 600, 92, 57, 58, 48, |
| 107994 | | - /* 200 */ 581, 580, 582, 582, 55, 55, 56, 56, 56, 56, |
| 107995 | | - /* 210 */ 559, 54, 54, 54, 54, 53, 53, 52, 52, 52, |
| 107996 | | - /* 220 */ 51, 234, 310, 464, 233, 232, 558, 133, 519, 50, |
| 107997 | | - /* 230 */ 47, 147, 619, 618, 565, 436, 397, 515, 514, 518, |
| 107998 | | - /* 240 */ 410, 387, 438, 389, 437, 622, 621, 442, 570, 433, |
| 107999 | | - /* 250 */ 203, 390, 589, 583, 6, 413, 166, 670, 250, 381, |
| 108000 | | - /* 260 */ 378, 377, 525, 190, 600, 92, 594, 571, 571, 465, |
| 108001 | | - /* 270 */ 376, 57, 58, 48, 581, 580, 582, 582, 55, 55, |
| 108002 | | - /* 280 */ 56, 56, 56, 56, 599, 54, 54, 54, 54, 53, |
| 108003 | | - /* 290 */ 53, 52, 52, 52, 51, 234, 310, 592, 592, 592, |
| 108004 | | - /* 300 */ 490, 182, 247, 548, 249, 397, 273, 410, 7, 439, |
| 108005 | | - /* 310 */ 398, 606, 67, 619, 618, 620, 472, 256, 347, 255, |
| 108006 | | - /* 320 */ 473, 620, 413, 576, 620, 65, 589, 583, 236, 440, |
| 108007 | | - /* 330 */ 336, 600, 92, 68, 364, 192, 481, 622, 621, 547, |
| 108008 | | - /* 340 */ 622, 621, 560, 323, 207, 57, 58, 48, 581, 580, |
| 108009 | | - /* 350 */ 582, 582, 55, 55, 56, 56, 56, 56, 559, 54, |
| 108010 | | - /* 360 */ 54, 54, 54, 53, 53, 52, 52, 52, 51, 234, |
| 108011 | | - /* 370 */ 310, 410, 397, 146, 558, 531, 401, 348, 599, 166, |
| 108012 | | - /* 380 */ 248, 204, 381, 378, 377, 541, 413, 171, 337, 570, |
| 108013 | | - /* 390 */ 622, 621, 40, 376, 38, 600, 74, 465, 548, 490, |
| 108014 | | - /* 400 */ 589, 583, 532, 350, 579, 619, 618, 297, 619, 618, |
| 108015 | | - /* 410 */ 480, 67, 470, 39, 620, 599, 406, 574, 573, 57, |
| 108016 | | - /* 420 */ 58, 48, 581, 580, 582, 582, 55, 55, 56, 56, |
| 108017 | | - /* 430 */ 56, 56, 577, 54, 54, 54, 54, 53, 53, 52, |
| 108018 | | - /* 440 */ 52, 52, 51, 234, 310, 256, 347, 255, 530, 52, |
| 108019 | | - /* 450 */ 52, 52, 51, 234, 345, 564, 236, 386, 619, 618, |
| 108020 | | - /* 460 */ 957, 185, 418, 2, 408, 410, 578, 578, 198, 197, |
| 108021 | | - /* 470 */ 196, 499, 183, 167, 589, 583, 671, 570, 505, 506, |
| 108022 | | - /* 480 */ 413, 267, 601, 672, 546, 208, 602, 36, 601, 600, |
| 108023 | | - /* 490 */ 91, 468, 602, 57, 58, 48, 581, 580, 582, 582, |
| 108024 | | - /* 500 */ 55, 55, 56, 56, 56, 56, 202, 54, 54, 54, |
| 108025 | | - /* 510 */ 54, 53, 53, 52, 52, 52, 51, 234, 310, 599, |
| 108026 | | - /* 520 */ 157, 408, 527, 578, 578, 263, 490, 265, 410, 873, |
| 108027 | | - /* 530 */ 410, 474, 474, 366, 373, 410, 504, 428, 67, 290, |
| 108028 | | - /* 540 */ 599, 620, 352, 413, 408, 413, 578, 578, 589, 583, |
| 108029 | | - /* 550 */ 413, 382, 600, 92, 600, 16, 543, 62, 503, 600, |
| 108030 | | - /* 560 */ 92, 408, 346, 578, 578, 168, 45, 57, 58, 48, |
| 108031 | | - /* 570 */ 581, 580, 582, 582, 55, 55, 56, 56, 56, 56, |
| 108032 | | - /* 580 */ 200, 54, 54, 54, 54, 53, 53, 52, 52, 52, |
| 108033 | | - /* 590 */ 51, 234, 310, 393, 395, 534, 510, 617, 616, 615, |
| 108034 | | - /* 600 */ 318, 314, 172, 66, 596, 410, 338, 596, 324, 571, |
| 108035 | | - /* 610 */ 571, 50, 47, 147, 599, 629, 627, 330, 539, 315, |
| 108036 | | - /* 620 */ 413, 30, 589, 583, 272, 236, 199, 144, 176, 600, |
| 108037 | | - /* 630 */ 73, 420, 947, 620, 947, 420, 946, 351, 946, 175, |
| 108038 | | - /* 640 */ 596, 57, 58, 48, 581, 580, 582, 582, 55, 55, |
| 108039 | | - /* 650 */ 56, 56, 56, 56, 410, 54, 54, 54, 54, 53, |
| 108040 | | - /* 660 */ 53, 52, 52, 52, 51, 234, 310, 261, 410, 413, |
| 108041 | | - /* 670 */ 269, 208, 596, 363, 410, 596, 424, 360, 600, 69, |
| 108042 | | - /* 680 */ 424, 327, 620, 413, 50, 47, 147, 410, 358, 413, |
| 108043 | | - /* 690 */ 575, 553, 600, 94, 483, 509, 589, 583, 600, 97, |
| 108044 | | - /* 700 */ 552, 484, 413, 620, 188, 599, 551, 563, 596, 566, |
| 108045 | | - /* 710 */ 334, 600, 95, 205, 201, 57, 58, 48, 581, 580, |
| 108046 | | - /* 720 */ 582, 582, 55, 55, 56, 56, 56, 56, 352, 54, |
| 108047 | | - /* 730 */ 54, 54, 54, 53, 53, 52, 52, 52, 51, 234, |
| 108048 | | - /* 740 */ 310, 410, 261, 410, 167, 22, 356, 599, 359, 623, |
| 108049 | | - /* 750 */ 50, 47, 147, 548, 357, 562, 413, 620, 413, 332, |
| 108050 | | - /* 760 */ 523, 270, 410, 167, 620, 600, 104, 600, 103, 603, |
| 108051 | | - /* 770 */ 589, 583, 339, 539, 304, 423, 222, 413, 174, 304, |
| 108052 | | - /* 780 */ 422, 561, 567, 405, 214, 260, 600, 106, 620, 57, |
| 108053 | | - /* 790 */ 58, 48, 581, 580, 582, 582, 55, 55, 56, 56, |
| 108054 | | - /* 800 */ 56, 56, 410, 54, 54, 54, 54, 53, 53, 52, |
| 108055 | | - /* 810 */ 52, 52, 51, 234, 310, 410, 557, 413, 410, 421, |
| 108056 | | - /* 820 */ 273, 35, 512, 146, 421, 12, 600, 107, 213, 144, |
| 108057 | | - /* 830 */ 413, 410, 32, 413, 410, 620, 365, 353, 358, 600, |
| 108058 | | - /* 840 */ 134, 11, 600, 135, 589, 583, 413, 21, 548, 413, |
| 108059 | | - /* 850 */ 316, 148, 620, 620, 170, 600, 98, 223, 600, 102, |
| 108060 | | - /* 860 */ 374, 168, 167, 57, 58, 48, 581, 580, 582, 582, |
| 108061 | | - /* 870 */ 55, 55, 56, 56, 56, 56, 410, 54, 54, 54, |
| 108062 | | - /* 880 */ 54, 53, 53, 52, 52, 52, 51, 234, 310, 410, |
| 108063 | | - /* 890 */ 273, 413, 410, 273, 212, 469, 410, 167, 628, 2, |
| 108064 | | - /* 900 */ 600, 101, 545, 221, 413, 620, 130, 413, 620, 410, |
| 108065 | | - /* 910 */ 539, 413, 537, 600, 93, 315, 600, 100, 589, 583, |
| 108066 | | - /* 920 */ 600, 77, 425, 305, 413, 620, 254, 322, 599, 458, |
| 108067 | | - /* 930 */ 320, 171, 543, 600, 96, 521, 520, 57, 58, 48, |
| 108068 | | - /* 940 */ 581, 580, 582, 582, 55, 55, 56, 56, 56, 56, |
| 108069 | | - /* 950 */ 410, 54, 54, 54, 54, 53, 53, 52, 52, 52, |
| 108070 | | - /* 960 */ 51, 234, 310, 410, 273, 413, 410, 457, 358, 35, |
| 108071 | | - /* 970 */ 426, 230, 306, 319, 600, 138, 467, 520, 413, 620, |
| 108072 | | - /* 980 */ 143, 413, 410, 620, 410, 353, 529, 600, 137, 142, |
| 108073 | | - /* 990 */ 600, 136, 589, 583, 604, 261, 528, 413, 229, 413, |
| 108074 | | - /* 1000 */ 620, 321, 495, 28, 543, 543, 600, 76, 600, 90, |
| 108075 | | - /* 1010 */ 620, 57, 46, 48, 581, 580, 582, 582, 55, 55, |
| 108076 | | - /* 1020 */ 56, 56, 56, 56, 410, 54, 54, 54, 54, 53, |
| 108077 | | - /* 1030 */ 53, 52, 52, 52, 51, 234, 310, 261, 451, 413, |
| 108078 | | - /* 1040 */ 410, 211, 611, 285, 283, 610, 609, 502, 600, 89, |
| 108079 | | - /* 1050 */ 380, 217, 620, 128, 140, 413, 220, 620, 410, 409, |
| 108080 | | - /* 1060 */ 620, 620, 588, 587, 600, 75, 589, 583, 271, 620, |
| 108081 | | - /* 1070 */ 51, 234, 127, 413, 620, 599, 627, 330, 27, 375, |
| 108082 | | - /* 1080 */ 449, 279, 600, 88, 585, 584, 58, 48, 581, 580, |
| 108083 | | - /* 1090 */ 582, 582, 55, 55, 56, 56, 56, 56, 410, 54, |
| 108084 | | - /* 1100 */ 54, 54, 54, 53, 53, 52, 52, 52, 51, 234, |
| 108085 | | - /* 1110 */ 310, 586, 410, 413, 410, 261, 593, 165, 399, 556, |
| 108086 | | - /* 1120 */ 126, 371, 600, 87, 478, 186, 123, 413, 367, 413, |
| 108087 | | - /* 1130 */ 620, 620, 410, 620, 620, 410, 600, 99, 600, 86, |
| 108088 | | - /* 1140 */ 589, 583, 475, 122, 258, 171, 471, 413, 160, 121, |
| 108089 | | - /* 1150 */ 413, 14, 159, 463, 25, 24, 600, 17, 448, 600, |
| 108090 | | - /* 1160 */ 85, 48, 581, 580, 582, 582, 55, 55, 56, 56, |
| 108091 | | - /* 1170 */ 56, 56, 158, 54, 54, 54, 54, 53, 53, 52, |
| 108092 | | - /* 1180 */ 52, 52, 51, 234, 44, 404, 261, 3, 544, 261, |
| 108093 | | - /* 1190 */ 540, 414, 621, 460, 119, 118, 538, 275, 10, 349, |
| 108094 | | - /* 1200 */ 4, 620, 407, 620, 620, 620, 116, 44, 404, 410, |
| 108095 | | - /* 1210 */ 3, 620, 620, 410, 414, 621, 456, 454, 252, 450, |
| 108096 | | - /* 1220 */ 508, 402, 111, 109, 413, 407, 155, 444, 413, 447, |
| 108097 | | - /* 1230 */ 435, 565, 219, 600, 84, 620, 108, 600, 83, 64, |
| 108098 | | - /* 1240 */ 434, 417, 625, 150, 402, 333, 410, 237, 238, 124, |
| 108099 | | - /* 1250 */ 274, 41, 42, 533, 565, 206, 189, 261, 43, 412, |
| 108100 | | - /* 1260 */ 411, 413, 261, 594, 488, 620, 329, 149, 419, 268, |
| 108101 | | - /* 1270 */ 600, 72, 620, 266, 41, 42, 181, 620, 410, 620, |
| 108102 | | - /* 1280 */ 105, 43, 412, 411, 620, 624, 594, 614, 620, 599, |
| 108103 | | - /* 1290 */ 228, 125, 313, 413, 592, 592, 592, 591, 590, 13, |
| 108104 | | - /* 1300 */ 218, 410, 600, 71, 236, 244, 44, 404, 264, 3, |
| 108105 | | - /* 1310 */ 312, 613, 340, 414, 621, 180, 413, 592, 592, 592, |
| 108106 | | - /* 1320 */ 591, 590, 13, 620, 407, 600, 82, 410, 416, 34, |
| 108107 | | - /* 1330 */ 404, 410, 3, 410, 262, 410, 414, 621, 612, 331, |
| 108108 | | - /* 1340 */ 178, 415, 413, 402, 8, 236, 413, 407, 413, 620, |
| 108109 | | - /* 1350 */ 413, 600, 81, 565, 257, 600, 80, 600, 70, 600, |
| 108110 | | - /* 1360 */ 18, 598, 361, 462, 461, 30, 402, 294, 31, 620, |
| 108111 | | - /* 1370 */ 293, 354, 251, 41, 42, 410, 565, 620, 620, 620, |
| 108112 | | - /* 1380 */ 43, 412, 411, 453, 396, 594, 620, 620, 394, 61, |
| 108113 | | - /* 1390 */ 413, 292, 443, 622, 621, 243, 41, 42, 620, 600, |
| 108114 | | - /* 1400 */ 79, 597, 291, 43, 412, 411, 60, 620, 594, 240, |
| 108115 | | - /* 1410 */ 620, 410, 231, 37, 555, 173, 592, 592, 592, 591, |
| 108116 | | - /* 1420 */ 590, 13, 216, 239, 620, 184, 413, 302, 301, 300, |
| 108117 | | - /* 1430 */ 179, 298, 388, 565, 452, 600, 78, 286, 620, 592, |
| 108118 | | - /* 1440 */ 592, 592, 591, 590, 13, 429, 29, 413, 151, 289, |
| 108119 | | - /* 1450 */ 242, 145, 392, 194, 193, 288, 600, 9, 542, 241, |
| 108120 | | - /* 1460 */ 620, 525, 391, 284, 620, 594, 620, 620, 522, 536, |
| 108121 | | - /* 1470 */ 620, 535, 153, 385, 465, 516, 282, 325, 154, 517, |
| 108122 | | - /* 1480 */ 277, 152, 512, 511, 513, 129, 226, 308, 487, 486, |
| 108123 | | - /* 1490 */ 485, 164, 372, 493, 307, 227, 592, 592, 592, 225, |
| 108124 | | - /* 1500 */ 479, 163, 368, 370, 162, 476, 210, 477, 26, 259, |
| 108125 | | - /* 1510 */ 161, 466, 362, 141, 132, 120, 117, 455, 156, 115, |
| 108126 | | - /* 1520 */ 344, 343, 256, 342, 245, 114, 113, 446, 311, 112, |
| 108127 | | - /* 1530 */ 23, 317, 432, 236, 131, 431, 110, 430, 20, 427, |
| 108128 | | - /* 1540 */ 608, 595, 295, 63, 379, 287, 509, 191, 278, 403, |
| 108129 | | - /* 1550 */ 572, 569, 497, 498, 496, 494, 335, 459, 445, 303, |
| 108130 | | - /* 1560 */ 296, 246, 341, 355, 5, 568, 369, 507, 253, 549, |
| 108131 | | - /* 1570 */ 526, 209, 400, 501, 500, 524, 234, 958, 489, 482, |
| 108279 | + /* 90 */ 51, 233, 53, 53, 52, 52, 52, 51, 233, 489, |
| 108280 | + /* 100 */ 663, 440, 663, 235, 588, 582, 553, 297, 363, 59, |
| 108281 | + /* 110 */ 481, 67, 360, 1, 618, 351, 618, 620, 619, 207, |
| 108282 | + /* 120 */ 6, 441, 442, 57, 58, 48, 580, 579, 581, 581, |
| 108283 | + /* 130 */ 55, 55, 56, 56, 56, 56, 605, 54, 54, 54, |
| 108284 | + /* 140 */ 54, 53, 53, 52, 52, 52, 51, 233, 310, 223, |
| 108285 | + /* 150 */ 50, 47, 146, 598, 138, 281, 385, 276, 384, 168, |
| 108286 | + /* 160 */ 489, 552, 620, 619, 620, 619, 272, 214, 440, 411, |
| 108287 | + /* 170 */ 551, 604, 67, 165, 7, 618, 352, 353, 588, 582, |
| 108288 | + /* 180 */ 443, 569, 192, 618, 414, 617, 616, 668, 441, 336, |
| 108289 | + /* 190 */ 669, 62, 618, 599, 92, 382, 346, 57, 58, 48, |
| 108290 | + /* 200 */ 580, 579, 581, 581, 55, 55, 56, 56, 56, 56, |
| 108291 | + /* 210 */ 670, 54, 54, 54, 54, 53, 53, 52, 52, 52, |
| 108292 | + /* 220 */ 51, 233, 310, 465, 232, 231, 373, 132, 514, 513, |
| 108293 | + /* 230 */ 617, 616, 617, 616, 398, 437, 411, 66, 280, 388, |
| 108294 | + /* 240 */ 411, 595, 439, 220, 438, 620, 619, 337, 569, 279, |
| 108295 | + /* 250 */ 201, 414, 588, 582, 166, 414, 546, 167, 68, 234, |
| 108296 | + /* 260 */ 599, 92, 620, 619, 599, 92, 19, 570, 570, 466, |
| 108297 | + /* 270 */ 564, 57, 58, 48, 580, 579, 581, 581, 55, 55, |
| 108298 | + /* 280 */ 56, 56, 56, 56, 598, 54, 54, 54, 54, 53, |
| 108299 | + /* 290 */ 53, 52, 52, 52, 51, 233, 310, 411, 524, 232, |
| 108300 | + /* 300 */ 231, 398, 593, 547, 559, 398, 348, 202, 175, 595, |
| 108301 | + /* 310 */ 399, 315, 414, 617, 616, 387, 272, 255, 347, 254, |
| 108302 | + /* 320 */ 558, 599, 74, 620, 619, 45, 588, 582, 235, 466, |
| 108303 | + /* 330 */ 617, 616, 511, 591, 591, 591, 557, 578, 402, 545, |
| 108304 | + /* 340 */ 600, 598, 570, 570, 601, 57, 58, 48, 580, 579, |
| 108305 | + /* 350 */ 581, 581, 55, 55, 56, 56, 56, 56, 550, 54, |
| 108306 | + /* 360 */ 54, 54, 54, 53, 53, 52, 52, 52, 51, 233, |
| 108307 | + /* 370 */ 310, 309, 411, 145, 566, 490, 213, 255, 347, 254, |
| 108308 | + /* 380 */ 196, 195, 194, 587, 586, 531, 600, 414, 235, 174, |
| 108309 | + /* 390 */ 601, 617, 616, 411, 620, 619, 599, 91, 547, 574, |
| 108310 | + /* 400 */ 588, 582, 50, 47, 146, 584, 583, 471, 414, 249, |
| 108311 | + /* 410 */ 565, 542, 186, 39, 304, 424, 562, 599, 16, 57, |
| 108312 | + /* 420 */ 58, 48, 580, 579, 581, 581, 55, 55, 56, 56, |
| 108313 | + /* 430 */ 56, 56, 585, 54, 54, 54, 54, 53, 53, 52, |
| 108314 | + /* 440 */ 52, 52, 51, 233, 310, 559, 290, 530, 529, 345, |
| 108315 | + /* 450 */ 533, 576, 540, 246, 170, 248, 411, 396, 411, 422, |
| 108316 | + /* 460 */ 199, 558, 617, 616, 165, 563, 50, 47, 146, 181, |
| 108317 | + /* 470 */ 498, 414, 166, 414, 588, 582, 269, 557, 166, 518, |
| 108318 | + /* 480 */ 599, 92, 599, 92, 561, 595, 469, 36, 173, 409, |
| 108319 | + /* 490 */ 517, 577, 577, 57, 58, 48, 580, 579, 581, 581, |
| 108320 | + /* 500 */ 55, 55, 56, 56, 56, 56, 338, 54, 54, 54, |
| 108321 | + /* 510 */ 54, 53, 53, 52, 52, 52, 51, 233, 310, 304, |
| 108322 | + /* 520 */ 423, 394, 526, 318, 869, 235, 167, 180, 473, 547, |
| 108323 | + /* 530 */ 503, 247, 474, 381, 378, 377, 409, 351, 577, 577, |
| 108324 | + /* 540 */ 409, 560, 577, 577, 376, 383, 364, 603, 588, 582, |
| 108325 | + /* 550 */ 620, 619, 502, 595, 409, 494, 577, 577, 409, 266, |
| 108326 | + /* 560 */ 577, 577, 421, 943, 422, 943, 198, 57, 58, 48, |
| 108327 | + /* 570 */ 580, 579, 581, 581, 55, 55, 56, 56, 56, 56, |
| 108328 | + /* 580 */ 315, 54, 54, 54, 54, 53, 53, 52, 52, 52, |
| 108329 | + /* 590 */ 51, 233, 310, 390, 421, 942, 509, 942, 556, 145, |
| 108330 | + /* 600 */ 598, 391, 324, 262, 549, 264, 411, 425, 407, 573, |
| 108331 | + /* 610 */ 572, 12, 197, 143, 489, 50, 47, 146, 617, 616, |
| 108332 | + /* 620 */ 206, 414, 588, 582, 547, 429, 67, 212, 143, 618, |
| 108333 | + /* 630 */ 599, 73, 504, 505, 207, 434, 475, 475, 366, 425, |
| 108334 | + /* 640 */ 35, 57, 58, 48, 580, 579, 581, 581, 55, 55, |
| 108335 | + /* 650 */ 56, 56, 56, 56, 598, 54, 54, 54, 54, 53, |
| 108336 | + /* 660 */ 53, 52, 52, 52, 51, 233, 310, 260, 598, 569, |
| 108337 | + /* 670 */ 268, 615, 614, 613, 171, 411, 595, 11, 411, 350, |
| 108338 | + /* 680 */ 411, 32, 618, 953, 183, 419, 2, 627, 625, 330, |
| 108339 | + /* 690 */ 414, 352, 552, 414, 538, 414, 588, 582, 188, 599, |
| 108340 | + /* 700 */ 69, 551, 599, 94, 599, 97, 374, 544, 166, 618, |
| 108341 | + /* 710 */ 334, 359, 50, 47, 146, 57, 58, 48, 580, 579, |
| 108342 | + /* 720 */ 581, 581, 55, 55, 56, 56, 56, 56, 411, 54, |
| 108343 | + /* 730 */ 54, 54, 54, 53, 53, 52, 52, 52, 51, 233, |
| 108344 | + /* 740 */ 310, 411, 129, 414, 595, 22, 273, 156, 411, 566, |
| 108345 | + /* 750 */ 406, 213, 599, 95, 570, 570, 414, 327, 169, 332, |
| 108346 | + /* 760 */ 411, 618, 536, 414, 358, 599, 104, 483, 508, 356, |
| 108347 | + /* 770 */ 588, 582, 599, 103, 484, 414, 470, 357, 166, 618, |
| 108348 | + /* 780 */ 626, 2, 204, 323, 599, 105, 40, 528, 38, 57, |
| 108349 | + /* 790 */ 58, 48, 580, 579, 581, 581, 55, 55, 56, 56, |
| 108350 | + /* 800 */ 56, 56, 411, 54, 54, 54, 54, 53, 53, 52, |
| 108351 | + /* 810 */ 52, 52, 51, 233, 310, 411, 598, 414, 411, 260, |
| 108352 | + /* 820 */ 273, 273, 273, 273, 426, 305, 599, 106, 520, 519, |
| 108353 | + /* 830 */ 414, 411, 142, 414, 618, 618, 618, 618, 618, 599, |
| 108354 | + /* 840 */ 133, 339, 599, 134, 588, 582, 414, 21, 30, 316, |
| 108355 | + /* 850 */ 147, 459, 221, 170, 527, 599, 98, 222, 322, 321, |
| 108356 | + /* 860 */ 320, 141, 259, 57, 58, 48, 580, 579, 581, 581, |
| 108357 | + /* 870 */ 55, 55, 56, 56, 56, 56, 411, 54, 54, 54, |
| 108358 | + /* 880 */ 54, 53, 53, 52, 52, 52, 51, 233, 310, 411, |
| 108359 | + /* 890 */ 260, 414, 411, 458, 200, 35, 411, 358, 211, 228, |
| 108360 | + /* 900 */ 599, 102, 468, 519, 414, 618, 28, 414, 538, 501, |
| 108361 | + /* 910 */ 411, 414, 618, 599, 101, 358, 599, 93, 588, 582, |
| 108362 | + /* 920 */ 599, 100, 522, 618, 427, 414, 306, 271, 598, 380, |
| 108363 | + /* 930 */ 618, 602, 598, 452, 599, 77, 210, 57, 58, 48, |
| 108364 | + /* 940 */ 580, 579, 581, 581, 55, 55, 56, 56, 56, 56, |
| 108365 | + /* 950 */ 411, 54, 54, 54, 54, 53, 53, 52, 52, 52, |
| 108366 | + /* 960 */ 51, 233, 310, 411, 621, 414, 411, 127, 609, 270, |
| 108367 | + /* 970 */ 598, 365, 51, 233, 599, 96, 625, 330, 414, 618, |
| 108368 | + /* 980 */ 126, 414, 411, 618, 411, 253, 608, 599, 137, 27, |
| 108369 | + /* 990 */ 599, 136, 588, 582, 375, 260, 125, 414, 164, 414, |
| 108370 | + /* 1000 */ 371, 618, 279, 219, 542, 542, 599, 135, 599, 76, |
| 108371 | + /* 1010 */ 618, 57, 46, 48, 580, 579, 581, 581, 55, 55, |
| 108372 | + /* 1020 */ 56, 56, 56, 56, 411, 54, 54, 54, 54, 53, |
| 108373 | + /* 1030 */ 53, 52, 52, 52, 51, 233, 310, 411, 450, 414, |
| 108374 | + /* 1040 */ 411, 260, 542, 229, 285, 607, 479, 184, 599, 90, |
| 108375 | + /* 1050 */ 367, 122, 414, 476, 121, 414, 618, 170, 411, 353, |
| 108376 | + /* 1060 */ 618, 599, 89, 410, 599, 75, 588, 582, 472, 257, |
| 108377 | + /* 1070 */ 538, 120, 159, 414, 618, 14, 464, 158, 618, 157, |
| 108378 | + /* 1080 */ 461, 283, 599, 88, 449, 618, 58, 48, 580, 579, |
| 108379 | + /* 1090 */ 581, 581, 55, 55, 56, 56, 56, 56, 411, 54, |
| 108380 | + /* 1100 */ 54, 54, 54, 53, 53, 52, 52, 52, 51, 233, |
| 108381 | + /* 1110 */ 310, 411, 260, 414, 411, 592, 260, 118, 25, 400, |
| 108382 | + /* 1120 */ 10, 24, 599, 87, 117, 216, 414, 618, 349, 414, |
| 108383 | + /* 1130 */ 618, 618, 411, 319, 618, 599, 99, 555, 599, 86, |
| 108384 | + /* 1140 */ 588, 582, 4, 260, 457, 455, 115, 414, 251, 154, |
| 108385 | + /* 1150 */ 451, 108, 618, 110, 436, 448, 599, 17, 618, 218, |
| 108386 | + /* 1160 */ 107, 48, 580, 579, 581, 581, 55, 55, 56, 56, |
| 108387 | + /* 1170 */ 56, 56, 435, 54, 54, 54, 54, 53, 53, 52, |
| 108388 | + /* 1180 */ 52, 52, 51, 233, 44, 405, 217, 3, 411, 260, |
| 108389 | + /* 1190 */ 543, 415, 619, 445, 64, 149, 539, 237, 333, 329, |
| 108390 | + /* 1200 */ 203, 187, 408, 414, 618, 618, 420, 44, 405, 411, |
| 108391 | + /* 1210 */ 3, 618, 599, 85, 415, 619, 148, 227, 622, 179, |
| 108392 | + /* 1220 */ 313, 403, 312, 612, 414, 408, 611, 124, 417, 178, |
| 108393 | + /* 1230 */ 610, 564, 243, 599, 84, 537, 8, 176, 235, 416, |
| 108394 | + /* 1240 */ 294, 418, 623, 30, 403, 597, 411, 236, 293, 123, |
| 108395 | + /* 1250 */ 618, 41, 42, 532, 564, 205, 292, 275, 43, 413, |
| 108396 | + /* 1260 */ 412, 414, 395, 593, 507, 274, 31, 397, 291, 37, |
| 108397 | + /* 1270 */ 599, 83, 618, 491, 41, 42, 267, 411, 265, 618, |
| 108398 | + /* 1280 */ 618, 43, 413, 412, 596, 263, 593, 60, 618, 598, |
| 108399 | + /* 1290 */ 261, 618, 414, 618, 591, 591, 591, 590, 589, 13, |
| 108400 | + /* 1300 */ 618, 599, 72, 554, 235, 618, 44, 405, 256, 3, |
| 108401 | + /* 1310 */ 361, 172, 340, 415, 619, 230, 411, 591, 591, 591, |
| 108402 | + /* 1320 */ 590, 589, 13, 618, 408, 618, 182, 411, 286, 34, |
| 108403 | + /* 1330 */ 405, 414, 3, 411, 463, 411, 415, 619, 29, 331, |
| 108404 | + /* 1340 */ 599, 71, 414, 403, 392, 386, 284, 408, 414, 618, |
| 108405 | + /* 1350 */ 414, 599, 82, 564, 411, 462, 354, 599, 81, 599, |
| 108406 | + /* 1360 */ 80, 541, 250, 535, 282, 521, 403, 534, 516, 414, |
| 108407 | + /* 1370 */ 618, 618, 454, 41, 42, 411, 564, 618, 599, 70, |
| 108408 | + /* 1380 */ 43, 413, 412, 444, 515, 593, 242, 618, 325, 61, |
| 108409 | + /* 1390 */ 414, 277, 239, 620, 619, 238, 41, 42, 618, 599, |
| 108410 | + /* 1400 */ 18, 618, 512, 43, 413, 412, 511, 618, 593, 430, |
| 108411 | + /* 1410 */ 618, 411, 128, 510, 308, 226, 591, 591, 591, 590, |
| 108412 | + /* 1420 */ 589, 13, 215, 289, 618, 225, 414, 302, 301, 300, |
| 108413 | + /* 1430 */ 177, 298, 411, 564, 453, 599, 79, 224, 618, 591, |
| 108414 | + /* 1440 */ 591, 591, 590, 589, 13, 389, 492, 414, 150, 144, |
| 108415 | + /* 1450 */ 241, 393, 288, 191, 190, 193, 599, 78, 165, 240, |
| 108416 | + /* 1460 */ 414, 524, 487, 307, 618, 593, 618, 618, 486, 599, |
| 108417 | + /* 1470 */ 9, 163, 152, 485, 466, 372, 480, 162, 153, 370, |
| 108418 | + /* 1480 */ 161, 151, 209, 478, 258, 368, 477, 26, 160, 467, |
| 108419 | + /* 1490 */ 140, 362, 131, 119, 116, 456, 591, 591, 591, 155, |
| 108420 | + /* 1500 */ 114, 344, 343, 113, 112, 111, 447, 109, 130, 23, |
| 108421 | + /* 1510 */ 317, 433, 20, 432, 431, 428, 606, 594, 63, 189, |
| 108422 | + /* 1520 */ 404, 571, 255, 342, 244, 295, 287, 278, 311, 508, |
| 108423 | + /* 1530 */ 496, 497, 495, 235, 493, 568, 379, 355, 460, 245, |
| 108424 | + /* 1540 */ 341, 446, 303, 567, 5, 252, 548, 208, 139, 506, |
| 108425 | + /* 1550 */ 369, 401, 500, 499, 296, 525, 335, 488, 482, 523, |
| 108426 | + /* 1560 */ 233, |
| 108132 | 108427 | }; |
| 108133 | 108428 | static const YYCODETYPE yy_lookahead[] = { |
| 108134 | 108429 | /* 0 */ 19, 169, 170, 171, 22, 24, 24, 26, 77, 78, |
| 108135 | 108430 | /* 10 */ 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, |
| 108136 | | - /* 20 */ 89, 90, 91, 92, 26, 27, 1, 26, 27, 15, |
| 108137 | | - /* 30 */ 49, 50, 77, 78, 79, 80, 116, 82, 83, 84, |
| 108138 | | - /* 40 */ 85, 86, 87, 88, 89, 90, 91, 92, 128, 68, |
| 108431 | + /* 20 */ 89, 90, 91, 92, 88, 89, 90, 91, 92, 1, |
| 108432 | + /* 30 */ 49, 50, 77, 78, 79, 80, 155, 82, 83, 84, |
| 108433 | + /* 40 */ 85, 86, 87, 88, 89, 90, 91, 92, 15, 68, |
| 108139 | 108434 | /* 50 */ 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, |
| 108140 | 108435 | /* 60 */ 79, 80, 230, 82, 83, 84, 85, 86, 87, 88, |
| 108141 | | - /* 70 */ 89, 90, 91, 92, 19, 94, 19, 23, 86, 87, |
| 108436 | + /* 70 */ 89, 90, 91, 92, 19, 94, 19, 23, 1, 25, |
| 108142 | 108437 | /* 80 */ 25, 82, 83, 84, 85, 86, 87, 88, 89, 90, |
| 108143 | | - /* 90 */ 91, 92, 94, 95, 19, 94, 95, 96, 172, 173, |
| 108144 | | - /* 100 */ 99, 100, 101, 197, 49, 50, 177, 181, 22, 54, |
| 108145 | | - /* 110 */ 204, 110, 26, 27, 86, 87, 88, 89, 90, 91, |
| 108146 | | - /* 120 */ 92, 129, 130, 68, 69, 70, 71, 72, 73, 74, |
| 108147 | | - /* 130 */ 75, 76, 77, 78, 79, 80, 22, 82, 83, 84, |
| 108438 | + /* 90 */ 91, 92, 86, 87, 88, 89, 90, 91, 92, 150, |
| 108439 | + /* 100 */ 23, 150, 25, 116, 49, 50, 177, 158, 227, 54, |
| 108440 | + /* 110 */ 161, 162, 231, 22, 165, 128, 165, 26, 27, 160, |
| 108441 | + /* 120 */ 22, 170, 171, 68, 69, 70, 71, 72, 73, 74, |
| 108442 | + /* 130 */ 75, 76, 77, 78, 79, 80, 23, 82, 83, 84, |
| 108148 | 108443 | /* 140 */ 85, 86, 87, 88, 89, 90, 91, 92, 19, 92, |
| 108149 | | - /* 150 */ 221, 222, 223, 96, 97, 98, 99, 100, 101, 102, |
| 108150 | | - /* 160 */ 112, 32, 114, 115, 26, 27, 109, 92, 150, 25, |
| 108151 | | - /* 170 */ 41, 150, 97, 98, 99, 100, 101, 102, 49, 50, |
| 108152 | | - /* 180 */ 94, 95, 98, 165, 109, 25, 165, 163, 170, 171, |
| 108153 | | - /* 190 */ 166, 167, 168, 109, 12, 174, 175, 68, 69, 70, |
| 108444 | + /* 150 */ 221, 222, 223, 194, 97, 98, 99, 100, 101, 102, |
| 108445 | + /* 160 */ 150, 32, 26, 27, 26, 27, 109, 22, 150, 150, |
| 108446 | + /* 170 */ 41, 161, 162, 96, 76, 165, 217, 150, 49, 50, |
| 108447 | + /* 180 */ 229, 230, 172, 165, 165, 94, 95, 118, 170, 171, |
| 108448 | + /* 190 */ 118, 232, 165, 174, 175, 185, 237, 68, 69, 70, |
| 108154 | 108449 | /* 200 */ 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, |
| 108155 | | - /* 210 */ 28, 82, 83, 84, 85, 86, 87, 88, 89, 90, |
| 108156 | | - /* 220 */ 91, 92, 19, 11, 86, 87, 44, 24, 46, 221, |
| 108157 | | - /* 230 */ 222, 223, 94, 95, 66, 97, 215, 7, 8, 57, |
| 108158 | | - /* 240 */ 150, 220, 104, 19, 106, 26, 27, 229, 230, 241, |
| 108159 | | - /* 250 */ 160, 27, 49, 50, 22, 165, 96, 118, 16, 99, |
| 108160 | | - /* 260 */ 100, 101, 94, 119, 174, 175, 98, 129, 130, 57, |
| 108161 | | - /* 270 */ 110, 68, 69, 70, 71, 72, 73, 74, 75, 76, |
| 108450 | + /* 210 */ 118, 82, 83, 84, 85, 86, 87, 88, 89, 90, |
| 108451 | + /* 220 */ 91, 92, 19, 11, 86, 87, 19, 24, 7, 8, |
| 108452 | + /* 230 */ 94, 95, 94, 95, 215, 97, 150, 22, 98, 220, |
| 108453 | + /* 240 */ 150, 26, 104, 216, 106, 26, 27, 229, 230, 109, |
| 108454 | + /* 250 */ 160, 165, 49, 50, 25, 165, 120, 50, 22, 197, |
| 108455 | + /* 260 */ 174, 175, 26, 27, 174, 175, 204, 129, 130, 57, |
| 108456 | + /* 270 */ 66, 68, 69, 70, 71, 72, 73, 74, 75, 76, |
| 108162 | 108457 | /* 280 */ 77, 78, 79, 80, 194, 82, 83, 84, 85, 86, |
| 108163 | | - /* 290 */ 87, 88, 89, 90, 91, 92, 19, 129, 130, 131, |
| 108164 | | - /* 300 */ 150, 23, 60, 25, 62, 215, 150, 150, 76, 150, |
| 108165 | | - /* 310 */ 220, 161, 162, 94, 95, 165, 30, 105, 106, 107, |
| 108166 | | - /* 320 */ 34, 165, 165, 23, 165, 25, 49, 50, 116, 170, |
| 108167 | | - /* 330 */ 171, 174, 175, 22, 48, 185, 186, 26, 27, 120, |
| 108168 | | - /* 340 */ 26, 27, 12, 187, 160, 68, 69, 70, 71, 72, |
| 108169 | | - /* 350 */ 73, 74, 75, 76, 77, 78, 79, 80, 28, 82, |
| 108458 | + /* 290 */ 87, 88, 89, 90, 91, 92, 19, 150, 94, 86, |
| 108459 | + /* 300 */ 87, 215, 98, 25, 12, 215, 220, 160, 118, 94, |
| 108460 | + /* 310 */ 220, 104, 165, 94, 95, 88, 109, 105, 106, 107, |
| 108461 | + /* 320 */ 28, 174, 175, 26, 27, 22, 49, 50, 116, 57, |
| 108462 | + /* 330 */ 94, 95, 103, 129, 130, 131, 44, 113, 46, 120, |
| 108463 | + /* 340 */ 113, 194, 129, 130, 117, 68, 69, 70, 71, 72, |
| 108464 | + /* 350 */ 73, 74, 75, 76, 77, 78, 79, 80, 177, 82, |
| 108170 | 108465 | /* 360 */ 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, |
| 108171 | | - /* 370 */ 19, 150, 215, 95, 44, 23, 46, 220, 194, 96, |
| 108172 | | - /* 380 */ 138, 160, 99, 100, 101, 23, 165, 25, 229, 230, |
| 108173 | | - /* 390 */ 26, 27, 135, 110, 137, 174, 175, 57, 120, 150, |
| 108174 | | - /* 400 */ 49, 50, 88, 219, 113, 94, 95, 158, 94, 95, |
| 108175 | | - /* 410 */ 161, 162, 21, 136, 165, 194, 169, 170, 171, 68, |
| 108466 | + /* 370 */ 19, 163, 150, 95, 166, 167, 168, 105, 106, 107, |
| 108467 | + /* 380 */ 105, 106, 107, 49, 50, 88, 113, 165, 116, 118, |
| 108468 | + /* 390 */ 117, 94, 95, 150, 26, 27, 174, 175, 120, 23, |
| 108469 | + /* 400 */ 49, 50, 221, 222, 223, 71, 72, 21, 165, 16, |
| 108470 | + /* 410 */ 23, 166, 22, 136, 22, 23, 11, 174, 175, 68, |
| 108176 | 108471 | /* 420 */ 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, |
| 108177 | | - /* 430 */ 79, 80, 23, 82, 83, 84, 85, 86, 87, 88, |
| 108178 | | - /* 440 */ 89, 90, 91, 92, 19, 105, 106, 107, 23, 88, |
| 108179 | | - /* 450 */ 89, 90, 91, 92, 63, 23, 116, 88, 94, 95, |
| 108180 | | - /* 460 */ 142, 143, 144, 145, 112, 150, 114, 115, 105, 106, |
| 108181 | | - /* 470 */ 107, 23, 23, 25, 49, 50, 118, 230, 97, 98, |
| 108182 | | - /* 480 */ 165, 16, 113, 118, 120, 160, 117, 136, 113, 174, |
| 108183 | | - /* 490 */ 175, 100, 117, 68, 69, 70, 71, 72, 73, 74, |
| 108184 | | - /* 500 */ 75, 76, 77, 78, 79, 80, 160, 82, 83, 84, |
| 108185 | | - /* 510 */ 85, 86, 87, 88, 89, 90, 91, 92, 19, 194, |
| 108186 | | - /* 520 */ 25, 112, 23, 114, 115, 60, 150, 62, 150, 138, |
| 108187 | | - /* 530 */ 150, 105, 106, 107, 19, 150, 36, 161, 162, 224, |
| 108188 | | - /* 540 */ 194, 165, 217, 165, 112, 165, 114, 115, 49, 50, |
| 108189 | | - /* 550 */ 165, 51, 174, 175, 174, 175, 166, 232, 58, 174, |
| 108190 | | - /* 560 */ 175, 112, 237, 114, 115, 50, 22, 68, 69, 70, |
| 108472 | + /* 430 */ 79, 80, 98, 82, 83, 84, 85, 86, 87, 88, |
| 108473 | + /* 440 */ 89, 90, 91, 92, 19, 12, 224, 23, 23, 63, |
| 108474 | + /* 450 */ 205, 23, 23, 60, 25, 62, 150, 214, 150, 67, |
| 108475 | + /* 460 */ 22, 28, 94, 95, 96, 23, 221, 222, 223, 23, |
| 108476 | + /* 470 */ 23, 165, 25, 165, 49, 50, 23, 44, 25, 46, |
| 108477 | + /* 480 */ 174, 175, 174, 175, 23, 26, 100, 136, 25, 112, |
| 108478 | + /* 490 */ 57, 114, 115, 68, 69, 70, 71, 72, 73, 74, |
| 108479 | + /* 500 */ 75, 76, 77, 78, 79, 80, 97, 82, 83, 84, |
| 108480 | + /* 510 */ 85, 86, 87, 88, 89, 90, 91, 92, 19, 22, |
| 108481 | + /* 520 */ 23, 215, 23, 215, 138, 116, 50, 23, 30, 25, |
| 108482 | + /* 530 */ 36, 138, 34, 99, 100, 101, 112, 128, 114, 115, |
| 108483 | + /* 540 */ 112, 23, 114, 115, 110, 51, 48, 173, 49, 50, |
| 108484 | + /* 550 */ 26, 27, 58, 94, 112, 181, 114, 115, 112, 16, |
| 108485 | + /* 560 */ 114, 115, 22, 23, 67, 25, 160, 68, 69, 70, |
| 108191 | 108486 | /* 570 */ 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, |
| 108192 | | - /* 580 */ 160, 82, 83, 84, 85, 86, 87, 88, 89, 90, |
| 108193 | | - /* 590 */ 91, 92, 19, 215, 214, 205, 23, 7, 8, 9, |
| 108194 | | - /* 600 */ 215, 155, 24, 22, 26, 150, 97, 26, 108, 129, |
| 108195 | | - /* 610 */ 130, 221, 222, 223, 194, 0, 1, 2, 150, 104, |
| 108196 | | - /* 620 */ 165, 126, 49, 50, 109, 116, 206, 207, 118, 174, |
| 108197 | | - /* 630 */ 175, 22, 23, 165, 25, 22, 23, 128, 25, 118, |
| 108198 | | - /* 640 */ 26, 68, 69, 70, 71, 72, 73, 74, 75, 76, |
| 108199 | | - /* 650 */ 77, 78, 79, 80, 150, 82, 83, 84, 85, 86, |
| 108200 | | - /* 660 */ 87, 88, 89, 90, 91, 92, 19, 150, 150, 165, |
| 108201 | | - /* 670 */ 23, 160, 94, 227, 150, 94, 67, 231, 174, 175, |
| 108202 | | - /* 680 */ 67, 213, 165, 165, 221, 222, 223, 150, 150, 165, |
| 108203 | | - /* 690 */ 23, 32, 174, 175, 181, 182, 49, 50, 174, 175, |
| 108204 | | - /* 700 */ 41, 188, 165, 165, 22, 194, 177, 11, 94, 23, |
| 108205 | | - /* 710 */ 193, 174, 175, 160, 22, 68, 69, 70, 71, 72, |
| 108206 | | - /* 720 */ 73, 74, 75, 76, 77, 78, 79, 80, 217, 82, |
| 108487 | + /* 580 */ 104, 82, 83, 84, 85, 86, 87, 88, 89, 90, |
| 108488 | + /* 590 */ 91, 92, 19, 19, 22, 23, 23, 25, 23, 95, |
| 108489 | + /* 600 */ 194, 27, 108, 60, 25, 62, 150, 67, 169, 170, |
| 108490 | + /* 610 */ 171, 35, 206, 207, 150, 221, 222, 223, 94, 95, |
| 108491 | + /* 620 */ 160, 165, 49, 50, 120, 161, 162, 206, 207, 165, |
| 108492 | + /* 630 */ 174, 175, 97, 98, 160, 241, 105, 106, 107, 67, |
| 108493 | + /* 640 */ 25, 68, 69, 70, 71, 72, 73, 74, 75, 76, |
| 108494 | + /* 650 */ 77, 78, 79, 80, 194, 82, 83, 84, 85, 86, |
| 108495 | + /* 660 */ 87, 88, 89, 90, 91, 92, 19, 150, 194, 230, |
| 108496 | + /* 670 */ 23, 7, 8, 9, 24, 150, 26, 35, 150, 219, |
| 108497 | + /* 680 */ 150, 25, 165, 142, 143, 144, 145, 0, 1, 2, |
| 108498 | + /* 690 */ 165, 217, 32, 165, 150, 165, 49, 50, 119, 174, |
| 108499 | + /* 700 */ 175, 41, 174, 175, 174, 175, 23, 120, 25, 165, |
| 108500 | + /* 710 */ 193, 237, 221, 222, 223, 68, 69, 70, 71, 72, |
| 108501 | + /* 720 */ 73, 74, 75, 76, 77, 78, 79, 80, 150, 82, |
| 108207 | 108502 | /* 730 */ 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, |
| 108208 | | - /* 740 */ 19, 150, 150, 150, 25, 24, 19, 194, 237, 150, |
| 108209 | | - /* 750 */ 221, 222, 223, 25, 27, 23, 165, 165, 165, 242, |
| 108210 | | - /* 760 */ 165, 23, 150, 25, 165, 174, 175, 174, 175, 174, |
| 108211 | | - /* 770 */ 49, 50, 219, 150, 22, 23, 238, 165, 25, 22, |
| 108212 | | - /* 780 */ 23, 23, 166, 167, 168, 193, 174, 175, 165, 68, |
| 108503 | + /* 740 */ 19, 150, 22, 165, 94, 24, 150, 25, 150, 166, |
| 108504 | + /* 750 */ 167, 168, 174, 175, 129, 130, 165, 213, 35, 242, |
| 108505 | + /* 760 */ 150, 165, 27, 165, 150, 174, 175, 181, 182, 19, |
| 108506 | + /* 770 */ 49, 50, 174, 175, 188, 165, 23, 27, 25, 165, |
| 108507 | + /* 780 */ 144, 145, 160, 187, 174, 175, 135, 23, 137, 68, |
| 108213 | 108508 | /* 790 */ 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, |
| 108214 | 108509 | /* 800 */ 79, 80, 150, 82, 83, 84, 85, 86, 87, 88, |
| 108215 | | - /* 810 */ 89, 90, 91, 92, 19, 150, 23, 165, 150, 67, |
| 108216 | | - /* 820 */ 150, 25, 103, 95, 67, 35, 174, 175, 206, 207, |
| 108217 | | - /* 830 */ 165, 150, 25, 165, 150, 165, 213, 150, 150, 174, |
| 108218 | | - /* 840 */ 175, 35, 174, 175, 49, 50, 165, 52, 120, 165, |
| 108219 | | - /* 850 */ 245, 246, 165, 165, 35, 174, 175, 187, 174, 175, |
| 108220 | | - /* 860 */ 23, 50, 25, 68, 69, 70, 71, 72, 73, 74, |
| 108510 | + /* 810 */ 89, 90, 91, 92, 19, 150, 194, 165, 150, 150, |
| 108511 | + /* 820 */ 150, 150, 150, 150, 247, 248, 174, 175, 190, 191, |
| 108512 | + /* 830 */ 165, 150, 118, 165, 165, 165, 165, 165, 165, 174, |
| 108513 | + /* 840 */ 175, 219, 174, 175, 49, 50, 165, 52, 126, 245, |
| 108514 | + /* 850 */ 246, 23, 238, 25, 23, 174, 175, 187, 187, 187, |
| 108515 | + /* 860 */ 187, 39, 193, 68, 69, 70, 71, 72, 73, 74, |
| 108221 | 108516 | /* 870 */ 75, 76, 77, 78, 79, 80, 150, 82, 83, 84, |
| 108222 | 108517 | /* 880 */ 85, 86, 87, 88, 89, 90, 91, 92, 19, 150, |
| 108223 | | - /* 890 */ 150, 165, 150, 150, 160, 23, 150, 25, 144, 145, |
| 108224 | | - /* 900 */ 174, 175, 120, 216, 165, 165, 22, 165, 165, 150, |
| 108225 | | - /* 910 */ 150, 165, 27, 174, 175, 104, 174, 175, 49, 50, |
| 108226 | | - /* 920 */ 174, 175, 247, 248, 165, 165, 238, 187, 194, 23, |
| 108227 | | - /* 930 */ 187, 25, 166, 174, 175, 190, 191, 68, 69, 70, |
| 108518 | + /* 890 */ 150, 165, 150, 23, 160, 25, 150, 150, 160, 52, |
| 108519 | + /* 900 */ 174, 175, 190, 191, 165, 165, 22, 165, 150, 29, |
| 108520 | + /* 910 */ 150, 165, 165, 174, 175, 150, 174, 175, 49, 50, |
| 108521 | + /* 920 */ 174, 175, 165, 165, 23, 165, 25, 25, 194, 52, |
| 108522 | + /* 930 */ 165, 174, 194, 193, 174, 175, 160, 68, 69, 70, |
| 108228 | 108523 | /* 940 */ 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, |
| 108229 | 108524 | /* 950 */ 150, 82, 83, 84, 85, 86, 87, 88, 89, 90, |
| 108230 | | - /* 960 */ 91, 92, 19, 150, 150, 165, 150, 23, 150, 25, |
| 108231 | | - /* 970 */ 23, 205, 25, 213, 174, 175, 190, 191, 165, 165, |
| 108232 | | - /* 980 */ 118, 165, 150, 165, 150, 150, 23, 174, 175, 39, |
| 108233 | | - /* 990 */ 174, 175, 49, 50, 173, 150, 23, 165, 52, 165, |
| 108234 | | - /* 1000 */ 165, 187, 181, 22, 166, 166, 174, 175, 174, 175, |
| 108525 | + /* 960 */ 91, 92, 19, 150, 150, 165, 150, 22, 150, 23, |
| 108526 | + /* 970 */ 194, 213, 91, 92, 174, 175, 1, 2, 165, 165, |
| 108527 | + /* 980 */ 22, 165, 150, 165, 150, 238, 150, 174, 175, 22, |
| 108528 | + /* 990 */ 174, 175, 49, 50, 52, 150, 22, 165, 102, 165, |
| 108529 | + /* 1000 */ 19, 165, 109, 238, 166, 166, 174, 175, 174, 175, |
| 108235 | 108530 | /* 1010 */ 165, 68, 69, 70, 71, 72, 73, 74, 75, 76, |
| 108236 | 108531 | /* 1020 */ 77, 78, 79, 80, 150, 82, 83, 84, 85, 86, |
| 108237 | 108532 | /* 1030 */ 87, 88, 89, 90, 91, 92, 19, 150, 193, 165, |
| 108238 | | - /* 1040 */ 150, 160, 150, 205, 205, 150, 150, 29, 174, 175, |
| 108239 | | - /* 1050 */ 52, 216, 165, 22, 150, 165, 238, 165, 150, 150, |
| 108240 | | - /* 1060 */ 165, 165, 49, 50, 174, 175, 49, 50, 23, 165, |
| 108241 | | - /* 1070 */ 91, 92, 22, 165, 165, 194, 1, 2, 22, 52, |
| 108242 | | - /* 1080 */ 193, 109, 174, 175, 71, 72, 69, 70, 71, 72, |
| 108533 | + /* 1040 */ 150, 150, 166, 205, 205, 150, 20, 24, 174, 175, |
| 108534 | + /* 1050 */ 43, 104, 165, 59, 53, 165, 165, 25, 150, 150, |
| 108535 | + /* 1060 */ 165, 174, 175, 150, 174, 175, 49, 50, 53, 138, |
| 108536 | + /* 1070 */ 150, 22, 104, 165, 165, 5, 1, 118, 165, 35, |
| 108537 | + /* 1080 */ 27, 205, 174, 175, 193, 165, 69, 70, 71, 72, |
| 108243 | 108538 | /* 1090 */ 73, 74, 75, 76, 77, 78, 79, 80, 150, 82, |
| 108244 | 108539 | /* 1100 */ 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, |
| 108245 | | - /* 1110 */ 19, 98, 150, 165, 150, 150, 150, 102, 150, 150, |
| 108246 | | - /* 1120 */ 22, 19, 174, 175, 20, 24, 104, 165, 43, 165, |
| 108247 | | - /* 1130 */ 165, 165, 150, 165, 165, 150, 174, 175, 174, 175, |
| 108248 | | - /* 1140 */ 49, 50, 59, 53, 138, 25, 53, 165, 104, 22, |
| 108249 | | - /* 1150 */ 165, 5, 118, 1, 76, 76, 174, 175, 193, 174, |
| 108250 | | - /* 1160 */ 175, 70, 71, 72, 73, 74, 75, 76, 77, 78, |
| 108251 | | - /* 1170 */ 79, 80, 35, 82, 83, 84, 85, 86, 87, 88, |
| 108252 | | - /* 1180 */ 89, 90, 91, 92, 19, 20, 150, 22, 150, 150, |
| 108253 | | - /* 1190 */ 150, 26, 27, 27, 108, 127, 150, 150, 22, 25, |
| 108254 | | - /* 1200 */ 22, 165, 37, 165, 165, 165, 119, 19, 20, 150, |
| 108255 | | - /* 1210 */ 22, 165, 165, 150, 26, 27, 23, 1, 16, 20, |
| 108256 | | - /* 1220 */ 150, 56, 119, 108, 165, 37, 121, 128, 165, 193, |
| 108257 | | - /* 1230 */ 23, 66, 193, 174, 175, 165, 127, 174, 175, 16, |
| 108258 | | - /* 1240 */ 23, 146, 147, 15, 56, 65, 150, 152, 140, 154, |
| 108259 | | - /* 1250 */ 150, 86, 87, 88, 66, 160, 22, 150, 93, 94, |
| 108260 | | - /* 1260 */ 95, 165, 150, 98, 150, 165, 3, 246, 4, 150, |
| 108261 | | - /* 1270 */ 174, 175, 165, 150, 86, 87, 6, 165, 150, 165, |
| 108262 | | - /* 1280 */ 164, 93, 94, 95, 165, 149, 98, 149, 165, 194, |
| 108263 | | - /* 1290 */ 180, 180, 249, 165, 129, 130, 131, 132, 133, 134, |
| 108264 | | - /* 1300 */ 193, 150, 174, 175, 116, 193, 19, 20, 150, 22, |
| 108265 | | - /* 1310 */ 249, 149, 217, 26, 27, 151, 165, 129, 130, 131, |
| 108266 | | - /* 1320 */ 132, 133, 134, 165, 37, 174, 175, 150, 149, 19, |
| 108267 | | - /* 1330 */ 20, 150, 22, 150, 150, 150, 26, 27, 13, 244, |
| 108268 | | - /* 1340 */ 151, 159, 165, 56, 25, 116, 165, 37, 165, 165, |
| 108269 | | - /* 1350 */ 165, 174, 175, 66, 150, 174, 175, 174, 175, 174, |
| 108270 | | - /* 1360 */ 175, 194, 150, 150, 150, 126, 56, 199, 124, 165, |
| 108271 | | - /* 1370 */ 200, 150, 150, 86, 87, 150, 66, 165, 165, 165, |
| 108272 | | - /* 1380 */ 93, 94, 95, 150, 122, 98, 165, 165, 123, 22, |
| 108273 | | - /* 1390 */ 165, 201, 150, 26, 27, 150, 86, 87, 165, 174, |
| 108274 | | - /* 1400 */ 175, 203, 202, 93, 94, 95, 125, 165, 98, 150, |
| 108275 | | - /* 1410 */ 165, 150, 225, 135, 157, 118, 129, 130, 131, 132, |
| 108276 | | - /* 1420 */ 133, 134, 5, 150, 165, 157, 165, 10, 11, 12, |
| 108277 | | - /* 1430 */ 13, 14, 150, 66, 17, 174, 175, 210, 165, 129, |
| 108278 | | - /* 1440 */ 130, 131, 132, 133, 134, 150, 104, 165, 31, 150, |
| 108279 | | - /* 1450 */ 33, 150, 150, 86, 87, 150, 174, 175, 211, 42, |
| 108280 | | - /* 1460 */ 165, 94, 121, 210, 165, 98, 165, 165, 176, 211, |
| 108281 | | - /* 1470 */ 165, 211, 55, 104, 57, 184, 210, 47, 61, 176, |
| 108282 | | - /* 1480 */ 176, 64, 103, 176, 178, 22, 92, 179, 176, 176, |
| 108283 | | - /* 1490 */ 176, 156, 18, 184, 179, 228, 129, 130, 131, 228, |
| 108284 | | - /* 1500 */ 157, 156, 45, 157, 156, 236, 157, 157, 135, 235, |
| 108285 | | - /* 1510 */ 156, 189, 157, 68, 218, 189, 22, 199, 156, 192, |
| 108286 | | - /* 1520 */ 157, 18, 105, 106, 107, 192, 192, 199, 111, 192, |
| 108287 | | - /* 1530 */ 240, 157, 40, 116, 218, 157, 189, 157, 240, 38, |
| 108288 | | - /* 1540 */ 153, 166, 198, 243, 178, 209, 182, 196, 177, 226, |
| 108289 | | - /* 1550 */ 230, 230, 166, 177, 177, 166, 139, 199, 199, 148, |
| 108290 | | - /* 1560 */ 195, 209, 209, 239, 196, 166, 234, 183, 239, 208, |
| 108291 | | - /* 1570 */ 174, 233, 191, 183, 183, 174, 92, 250, 186, 186, |
| 108540 | + /* 1110 */ 19, 150, 150, 165, 150, 150, 150, 108, 76, 150, |
| 108541 | + /* 1120 */ 22, 76, 174, 175, 127, 216, 165, 165, 25, 165, |
| 108542 | + /* 1130 */ 165, 165, 150, 213, 165, 174, 175, 150, 174, 175, |
| 108543 | + /* 1140 */ 49, 50, 22, 150, 23, 1, 119, 165, 16, 121, |
| 108544 | + /* 1150 */ 20, 108, 165, 119, 23, 193, 174, 175, 165, 193, |
| 108545 | + /* 1160 */ 127, 70, 71, 72, 73, 74, 75, 76, 77, 78, |
| 108546 | + /* 1170 */ 79, 80, 23, 82, 83, 84, 85, 86, 87, 88, |
| 108547 | + /* 1180 */ 89, 90, 91, 92, 19, 20, 193, 22, 150, 150, |
| 108548 | + /* 1190 */ 150, 26, 27, 128, 16, 15, 150, 140, 65, 3, |
| 108549 | + /* 1200 */ 164, 22, 37, 165, 165, 165, 4, 19, 20, 150, |
| 108550 | + /* 1210 */ 22, 165, 174, 175, 26, 27, 246, 180, 149, 6, |
| 108551 | + /* 1220 */ 249, 56, 249, 149, 165, 37, 149, 180, 149, 151, |
| 108552 | + /* 1230 */ 13, 66, 193, 174, 175, 150, 25, 151, 116, 159, |
| 108553 | + /* 1240 */ 199, 146, 147, 126, 56, 194, 150, 152, 200, 154, |
| 108554 | + /* 1250 */ 165, 86, 87, 88, 66, 160, 201, 150, 93, 94, |
| 108555 | + /* 1260 */ 95, 165, 123, 98, 150, 150, 124, 122, 202, 135, |
| 108556 | + /* 1270 */ 174, 175, 165, 150, 86, 87, 150, 150, 150, 165, |
| 108557 | + /* 1280 */ 165, 93, 94, 95, 203, 150, 98, 125, 165, 194, |
| 108558 | + /* 1290 */ 150, 165, 165, 165, 129, 130, 131, 132, 133, 134, |
| 108559 | + /* 1300 */ 165, 174, 175, 157, 116, 165, 19, 20, 150, 22, |
| 108560 | + /* 1310 */ 150, 118, 217, 26, 27, 225, 150, 129, 130, 131, |
| 108561 | + /* 1320 */ 132, 133, 134, 165, 37, 165, 157, 150, 210, 19, |
| 108562 | + /* 1330 */ 20, 165, 22, 150, 150, 150, 26, 27, 104, 244, |
| 108563 | + /* 1340 */ 174, 175, 165, 56, 121, 104, 210, 37, 165, 165, |
| 108564 | + /* 1350 */ 165, 174, 175, 66, 150, 150, 150, 174, 175, 174, |
| 108565 | + /* 1360 */ 175, 211, 150, 211, 210, 176, 56, 211, 176, 165, |
| 108566 | + /* 1370 */ 165, 165, 150, 86, 87, 150, 66, 165, 174, 175, |
| 108567 | + /* 1380 */ 93, 94, 95, 150, 184, 98, 150, 165, 47, 22, |
| 108568 | + /* 1390 */ 165, 176, 150, 26, 27, 150, 86, 87, 165, 174, |
| 108569 | + /* 1400 */ 175, 165, 178, 93, 94, 95, 103, 165, 98, 150, |
| 108570 | + /* 1410 */ 165, 150, 22, 176, 179, 228, 129, 130, 131, 132, |
| 108571 | + /* 1420 */ 133, 134, 5, 150, 165, 92, 165, 10, 11, 12, |
| 108572 | + /* 1430 */ 13, 14, 150, 66, 17, 174, 175, 228, 165, 129, |
| 108573 | + /* 1440 */ 130, 131, 132, 133, 134, 150, 184, 165, 31, 150, |
| 108574 | + /* 1450 */ 33, 150, 150, 86, 87, 172, 174, 175, 96, 42, |
| 108575 | + /* 1460 */ 165, 94, 176, 179, 165, 98, 165, 165, 176, 174, |
| 108576 | + /* 1470 */ 175, 156, 55, 176, 57, 18, 157, 156, 61, 157, |
| 108577 | + /* 1480 */ 156, 64, 157, 157, 235, 45, 236, 135, 156, 189, |
| 108578 | + /* 1490 */ 68, 157, 218, 189, 22, 199, 129, 130, 131, 156, |
| 108579 | + /* 1500 */ 192, 157, 18, 192, 192, 192, 199, 189, 218, 240, |
| 108580 | + /* 1510 */ 157, 40, 240, 157, 157, 38, 153, 166, 243, 196, |
| 108581 | + /* 1520 */ 226, 230, 105, 106, 107, 198, 209, 177, 111, 182, |
| 108582 | + /* 1530 */ 166, 177, 177, 116, 166, 230, 178, 239, 199, 209, |
| 108583 | + /* 1540 */ 209, 199, 148, 166, 196, 239, 208, 233, 172, 183, |
| 108584 | + /* 1550 */ 234, 191, 183, 183, 195, 174, 139, 186, 186, 174, |
| 108585 | + /* 1560 */ 92, |
| 108292 | 108586 | }; |
| 108293 | | -#define YY_SHIFT_USE_DFLT (-81) |
| 108294 | | -#define YY_SHIFT_COUNT (417) |
| 108295 | | -#define YY_SHIFT_MIN (-80) |
| 108296 | | -#define YY_SHIFT_MAX (1503) |
| 108587 | +#define YY_SHIFT_USE_DFLT (-70) |
| 108588 | +#define YY_SHIFT_COUNT (418) |
| 108589 | +#define YY_SHIFT_MIN (-69) |
| 108590 | +#define YY_SHIFT_MAX (1484) |
| 108297 | 108591 | static const short yy_shift_ofst[] = { |
| 108298 | | - /* 0 */ 1075, 1188, 1417, 1188, 1287, 1287, 138, 138, 1, -19, |
| 108299 | | - /* 10 */ 1287, 1287, 1287, 1287, 340, -2, 129, 129, 795, 1165, |
| 108592 | + /* 0 */ 975, 1188, 1417, 1188, 1287, 1287, 138, 138, 368, -19, |
| 108593 | + /* 10 */ 1287, 1287, 1287, 1287, 272, 524, 129, 129, 795, 1165, |
| 108300 | 108594 | /* 20 */ 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, |
| 108301 | 108595 | /* 30 */ 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, |
| 108302 | 108596 | /* 40 */ 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1310, 1287, |
| 108303 | 108597 | /* 50 */ 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, |
| 108304 | | - /* 60 */ 1287, 1287, 212, -2, -2, -8, -8, 614, 1229, 55, |
| 108598 | + /* 60 */ 1287, 1287, 212, 524, 524, 213, 213, 459, 1122, 55, |
| 108305 | 108599 | /* 70 */ 721, 647, 573, 499, 425, 351, 277, 203, 869, 869, |
| 108306 | 108600 | /* 80 */ 869, 869, 869, 869, 869, 869, 869, 869, 869, 869, |
| 108307 | 108601 | /* 90 */ 869, 869, 869, 943, 869, 1017, 1091, 1091, -69, -45, |
| 108308 | | - /* 100 */ -45, -45, -45, -45, -1, 57, 28, 361, -2, -2, |
| 108309 | | - /* 110 */ -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, |
| 108310 | | - /* 120 */ -2, -2, -2, -2, 391, 515, -2, -2, -2, -2, |
| 108311 | | - /* 130 */ -2, 509, -80, 614, 979, 1484, -81, -81, -81, 1367, |
| 108312 | | - /* 140 */ 75, 182, 182, 314, 311, 364, 219, 86, 613, 609, |
| 108313 | | - /* 150 */ -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, |
| 108314 | | - /* 160 */ -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, |
| 108315 | | - /* 170 */ -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, |
| 108316 | | - /* 180 */ -2, -2, 578, 578, 578, 615, 1229, 1229, 1229, -81, |
| 108317 | | - /* 190 */ -81, -81, 160, 168, 168, 283, 500, 500, 500, 278, |
| 108318 | | - /* 200 */ 449, 330, 432, 409, 352, 48, 48, 48, 48, 426, |
| 108319 | | - /* 210 */ 286, 48, 48, 728, 581, 369, 590, 495, 224, 224, |
| 108320 | | - /* 220 */ 727, 495, 727, 719, 614, 659, 614, 659, 811, 659, |
| 108321 | | - /* 230 */ 224, 257, 480, 480, 614, 144, 375, -18, 1501, 1297, |
| 108322 | | - /* 240 */ 1297, 1492, 1492, 1297, 1494, 1445, 1239, 1503, 1503, 1503, |
| 108323 | | - /* 250 */ 1503, 1297, 1474, 1239, 1494, 1445, 1445, 1297, 1474, 1373, |
| 108324 | | - /* 260 */ 1457, 1297, 1297, 1474, 1297, 1474, 1297, 1474, 1463, 1369, |
| 108325 | | - /* 270 */ 1369, 1369, 1430, 1394, 1394, 1463, 1369, 1379, 1369, 1430, |
| 108326 | | - /* 280 */ 1369, 1369, 1341, 1342, 1341, 1342, 1341, 1342, 1297, 1297, |
| 108327 | | - /* 290 */ 1278, 1281, 1262, 1244, 1265, 1239, 1229, 1319, 1325, 1325, |
| 108328 | | - /* 300 */ 1270, 1270, 1270, 1270, -81, -81, -81, -81, -81, -81, |
| 108329 | | - /* 310 */ 1013, 242, 757, 752, 465, 363, 947, 232, 944, 906, |
| 108330 | | - /* 320 */ 872, 837, 738, 448, 381, 230, 84, 362, 300, 1264, |
| 108331 | | - /* 330 */ 1263, 1234, 1108, 1228, 1180, 1223, 1217, 1207, 1099, 1174, |
| 108332 | | - /* 340 */ 1109, 1115, 1103, 1199, 1105, 1202, 1216, 1087, 1193, 1178, |
| 108333 | | - /* 350 */ 1174, 1176, 1068, 1079, 1078, 1086, 1166, 1137, 1034, 1152, |
| 108334 | | - /* 360 */ 1146, 1127, 1044, 1006, 1093, 1120, 1090, 1083, 1085, 1022, |
| 108335 | | - /* 370 */ 1101, 1104, 1102, 972, 1015, 1098, 1027, 1056, 1050, 1045, |
| 108336 | | - /* 380 */ 1031, 998, 1018, 981, 946, 950, 973, 963, 862, 885, |
| 108337 | | - /* 390 */ 819, 884, 782, 796, 806, 807, 790, 796, 793, 758, |
| 108338 | | - /* 400 */ 753, 732, 692, 696, 682, 686, 667, 544, 291, 521, |
| 108339 | | - /* 410 */ 510, 365, 358, 139, 114, 54, 14, 25, |
| 108602 | + /* 100 */ -45, -45, -45, -45, -1, 6, -64, 524, 524, 524, |
| 108603 | + /* 110 */ 524, 524, 524, 524, 524, 524, 524, 524, 524, 524, |
| 108604 | + /* 120 */ 524, 524, 524, 386, 207, 524, 524, 524, 524, 524, |
| 108605 | + /* 130 */ 409, -13, 459, 881, 1468, -70, -70, -70, 1367, 57, |
| 108606 | + /* 140 */ 433, 433, 297, 236, 219, 136, 91, 572, 540, 524, |
| 108607 | + /* 150 */ 524, 524, 524, 524, 524, 524, 524, 524, 524, 524, |
| 108608 | + /* 160 */ 524, 524, 524, 524, 524, 524, 524, 524, 524, 524, |
| 108609 | + /* 170 */ 524, 524, 524, 524, 524, 524, 524, 524, 524, 524, |
| 108610 | + /* 180 */ 650, 650, 650, 687, 1122, 1122, 1122, -70, -70, -70, |
| 108611 | + /* 190 */ 204, 204, 434, 434, 494, 494, 494, 504, 446, 292, |
| 108612 | + /* 200 */ 442, 428, 424, 77, 377, 377, 377, 377, 531, 498, |
| 108613 | + /* 210 */ 377, 377, 278, 215, 227, 664, 722, 574, 574, 750, |
| 108614 | + /* 220 */ 722, 750, 229, 459, 660, 459, 660, 476, 660, 574, |
| 108615 | + /* 230 */ 651, 625, 625, 459, 579, 273, -18, 1477, 1193, 1193, |
| 108616 | + /* 240 */ 1471, 1471, 1193, 1472, 1422, 1117, 1484, 1484, 1484, 1484, |
| 108617 | + /* 250 */ 1193, 1457, 1117, 1472, 1422, 1422, 1193, 1457, 1352, 1440, |
| 108618 | + /* 260 */ 1193, 1193, 1457, 1193, 1457, 1193, 1457, 1390, 1241, 1241, |
| 108619 | + /* 270 */ 1241, 1362, 1341, 1333, 1333, 1390, 1241, 1303, 1241, 1341, |
| 108620 | + /* 280 */ 1241, 1241, 1223, 1234, 1223, 1234, 1223, 1234, 1193, 1193, |
| 108621 | + /* 290 */ 1134, 1162, 1145, 1142, 1139, 1117, 1122, 1211, 1217, 1217, |
| 108622 | + /* 300 */ 1213, 1213, 1213, 1213, -70, -70, -70, -70, -70, -70, |
| 108623 | + /* 310 */ 334, 393, 497, 392, 543, 275, 901, 98, 870, 828, |
| 108624 | + /* 320 */ 753, 683, 453, 447, 535, 221, 140, 429, 54, 1202, |
| 108625 | + /* 330 */ 1196, 1179, 1057, 1180, 1133, 1178, 1149, 1131, 1065, 1103, |
| 108626 | + /* 340 */ 1033, 1043, 1034, 1130, 1028, 1132, 1144, 1027, 1121, 1120, |
| 108627 | + /* 350 */ 1103, 1098, 997, 1045, 1042, 1009, 1053, 1044, 959, 1075, |
| 108628 | + /* 360 */ 1070, 1049, 968, 931, 1015, 1032, 1001, 994, 1007, 947, |
| 108629 | + /* 370 */ 1023, 1026, 981, 893, 896, 974, 942, 967, 958, 946, |
| 108630 | + /* 380 */ 945, 877, 902, 880, 884, 847, 822, 831, 764, 714, |
| 108631 | + /* 390 */ 735, 723, 720, 587, 615, 642, 656, 576, 615, 575, |
| 108632 | + /* 400 */ 518, 463, 461, 438, 405, 390, 387, 376, 303, 224, |
| 108633 | + /* 410 */ 271, 190, 92, 72, 69, 145, 113, 33, 28, |
| 108340 | 108634 | }; |
| 108341 | 108635 | #define YY_REDUCE_USE_DFLT (-169) |
| 108342 | 108636 | #define YY_REDUCE_COUNT (309) |
| 108343 | 108637 | #define YY_REDUCE_MIN (-168) |
| 108344 | | -#define YY_REDUCE_MAX (1411) |
| 108638 | +#define YY_REDUCE_MAX (1394) |
| 108345 | 108639 | static const short yy_reduce_ofst[] = { |
| 108346 | | - /* 0 */ 318, 90, 1095, 221, 157, 21, 159, 18, 150, 390, |
| 108347 | | - /* 10 */ 385, 378, 380, 315, 325, 249, 529, -71, 8, 1282, |
| 108348 | | - /* 20 */ 1261, 1225, 1185, 1183, 1181, 1177, 1151, 1128, 1096, 1063, |
| 108349 | | - /* 30 */ 1059, 985, 982, 964, 962, 948, 908, 890, 874, 834, |
| 108350 | | - /* 40 */ 832, 816, 813, 800, 759, 746, 742, 739, 726, 684, |
| 108351 | | - /* 50 */ 681, 668, 665, 652, 612, 593, 591, 537, 524, 518, |
| 108352 | | - /* 60 */ 504, 455, 511, 376, 517, 247, -168, 24, 420, 463, |
| 108353 | | - /* 70 */ 463, 463, 463, 463, 463, 463, 463, 463, 463, 463, |
| 108354 | | - /* 80 */ 463, 463, 463, 463, 463, 463, 463, 463, 463, 463, |
| 108355 | | - /* 90 */ 463, 463, 463, 463, 463, 463, 463, 463, 463, 463, |
| 108356 | | - /* 100 */ 463, 463, 463, 463, 463, -74, 463, 463, 1112, 835, |
| 108357 | | - /* 110 */ 1107, 1039, 1036, 965, 887, 845, 818, 760, 688, 687, |
| 108358 | | - /* 120 */ 538, 743, 623, 592, 446, 513, 814, 740, 670, 156, |
| 108359 | | - /* 130 */ 468, 553, 184, 616, 463, 463, 463, 463, 463, 595, |
| 108360 | | - /* 140 */ 821, 786, 745, 909, 1305, 1302, 1301, 1299, 675, 675, |
| 108361 | | - /* 150 */ 1295, 1273, 1259, 1245, 1242, 1233, 1222, 1221, 1214, 1213, |
| 108362 | | - /* 160 */ 1212, 1204, 1184, 1158, 1123, 1119, 1114, 1100, 1070, 1047, |
| 108363 | | - /* 170 */ 1046, 1040, 1038, 969, 968, 966, 909, 904, 896, 895, |
| 108364 | | - /* 180 */ 892, 599, 839, 838, 766, 754, 881, 734, 346, 605, |
| 108365 | | - /* 190 */ 622, -94, 1393, 1401, 1396, 1392, 1391, 1390, 1384, 1361, |
| 108366 | | - /* 200 */ 1365, 1381, 1365, 1365, 1365, 1365, 1365, 1365, 1365, 1332, |
| 108367 | | - /* 210 */ 1338, 1365, 1365, 1361, 1399, 1368, 1411, 1359, 1353, 1352, |
| 108368 | | - /* 220 */ 1329, 1358, 1324, 1366, 1389, 1377, 1386, 1376, 1364, 1371, |
| 108369 | | - /* 230 */ 1336, 1323, 1321, 1320, 1375, 1344, 1351, 1387, 1300, 1380, |
| 108370 | | - /* 240 */ 1378, 1298, 1290, 1374, 1316, 1347, 1328, 1337, 1334, 1333, |
| 108371 | | - /* 250 */ 1327, 1363, 1362, 1318, 1296, 1326, 1322, 1355, 1354, 1269, |
| 108372 | | - /* 260 */ 1274, 1350, 1349, 1348, 1346, 1345, 1343, 1335, 1315, 1314, |
| 108373 | | - /* 270 */ 1313, 1312, 1309, 1271, 1267, 1308, 1307, 1306, 1304, 1291, |
| 108374 | | - /* 280 */ 1303, 1292, 1260, 1266, 1258, 1253, 1247, 1227, 1268, 1257, |
| 108375 | | - /* 290 */ 1187, 1198, 1200, 1190, 1170, 1168, 1167, 1182, 1189, 1164, |
| 108376 | | - /* 300 */ 1179, 1162, 1138, 1136, 1061, 1043, 1021, 1111, 1110, 1116, |
| 108640 | + /* 0 */ 541, 90, 1095, 147, 86, 19, 18, -49, 10, 245, |
| 108641 | + /* 10 */ 308, 306, 243, 222, -41, -51, 181, -71, 394, 1295, |
| 108642 | + /* 20 */ 1282, 1261, 1225, 1204, 1185, 1183, 1177, 1166, 1127, 1096, |
| 108643 | + /* 30 */ 1059, 1038, 982, 964, 961, 948, 908, 890, 887, 874, |
| 108644 | + /* 40 */ 834, 832, 816, 813, 800, 760, 746, 742, 739, 726, |
| 108645 | + /* 50 */ 681, 668, 665, 652, 610, 598, 591, 578, 530, 528, |
| 108646 | + /* 60 */ 525, 456, 474, 464, 517, 439, -168, 208, 406, 491, |
| 108647 | + /* 70 */ 491, 491, 491, 491, 491, 491, 491, 491, 491, 491, |
| 108648 | + /* 80 */ 491, 491, 491, 491, 491, 491, 491, 491, 491, 491, |
| 108649 | + /* 90 */ 491, 491, 491, 491, 491, 491, 491, 491, 491, 491, |
| 108650 | + /* 100 */ 491, 491, 491, 491, 491, 491, 491, 1039, 909, 993, |
| 108651 | + /* 110 */ 966, 962, 891, 845, 740, 765, 920, 747, 27, 614, |
| 108652 | + /* 120 */ 673, 758, 669, -119, 586, 672, 671, 670, 596, 544, |
| 108653 | + /* 130 */ 622, 460, 583, 491, 491, 491, 491, 491, 757, 374, |
| 108654 | + /* 140 */ 712, 638, 913, 1302, 1301, 1299, 1273, 577, 577, 1259, |
| 108655 | + /* 150 */ 1245, 1242, 1236, 1233, 1222, 1212, 1206, 1205, 1184, 1160, |
| 108656 | + /* 160 */ 1158, 1140, 1135, 1128, 1126, 1123, 1115, 1114, 1107, 1085, |
| 108657 | + /* 170 */ 1046, 1040, 987, 969, 965, 913, 895, 836, 818, 814, |
| 108658 | + /* 180 */ 876, 839, 838, 636, 776, 738, 734, 604, 421, 62, |
| 108659 | + /* 190 */ 1385, 1381, 1372, 1371, 1370, 1369, 1366, 1338, 1359, 1360, |
| 108660 | + /* 200 */ 1359, 1359, 1359, 1376, 1359, 1359, 1359, 1359, 1316, 1314, |
| 108661 | + /* 210 */ 1359, 1359, 1338, 1377, 1348, 1394, 1342, 1331, 1330, 1306, |
| 108662 | + /* 220 */ 1339, 1298, 1358, 1368, 1355, 1364, 1354, 1347, 1350, 1317, |
| 108663 | + /* 230 */ 1294, 1305, 1291, 1351, 1327, 1323, 1363, 1275, 1357, 1356, |
| 108664 | + /* 240 */ 1272, 1269, 1353, 1290, 1318, 1307, 1313, 1312, 1311, 1308, |
| 108665 | + /* 250 */ 1344, 1343, 1296, 1274, 1304, 1300, 1334, 1332, 1250, 1249, |
| 108666 | + /* 260 */ 1326, 1325, 1324, 1322, 1321, 1319, 1315, 1284, 1297, 1292, |
| 108667 | + /* 270 */ 1286, 1283, 1262, 1209, 1187, 1235, 1237, 1224, 1215, 1200, |
| 108668 | + /* 280 */ 1192, 1189, 1156, 1154, 1152, 1136, 1150, 1118, 1169, 1146, |
| 108669 | + /* 290 */ 1090, 1081, 1066, 1055, 1048, 1041, 1051, 1080, 1086, 1078, |
| 108670 | + /* 300 */ 1079, 1077, 1074, 1069, 973, 971, 970, 1047, 1037, 1036, |
| 108377 | 108671 | }; |
| 108378 | 108672 | static const YYACTIONTYPE yy_default[] = { |
| 108379 | | - /* 0 */ 634, 868, 956, 956, 868, 868, 956, 956, 956, 758, |
| 108380 | | - /* 10 */ 956, 956, 956, 866, 956, 956, 786, 786, 930, 956, |
| 108381 | | - /* 20 */ 956, 956, 956, 956, 956, 956, 956, 956, 956, 956, |
| 108382 | | - /* 30 */ 956, 956, 956, 956, 956, 956, 956, 956, 956, 956, |
| 108383 | | - /* 40 */ 956, 956, 956, 956, 956, 956, 956, 956, 956, 956, |
| 108384 | | - /* 50 */ 956, 956, 956, 956, 956, 956, 956, 956, 956, 956, |
| 108385 | | - /* 60 */ 956, 956, 956, 956, 956, 956, 956, 673, 762, 792, |
| 108386 | | - /* 70 */ 956, 956, 956, 956, 956, 956, 956, 956, 929, 931, |
| 108387 | | - /* 80 */ 800, 799, 909, 773, 797, 790, 794, 869, 862, 863, |
| 108388 | | - /* 90 */ 861, 865, 870, 956, 793, 829, 846, 828, 840, 845, |
| 108389 | | - /* 100 */ 852, 844, 841, 831, 830, 665, 832, 833, 956, 956, |
| 108390 | | - /* 110 */ 956, 956, 956, 956, 956, 956, 956, 956, 956, 956, |
| 108391 | | - /* 120 */ 956, 956, 956, 956, 660, 727, 956, 956, 956, 956, |
| 108392 | | - /* 130 */ 956, 956, 956, 956, 834, 835, 849, 848, 847, 956, |
| 108393 | | - /* 140 */ 956, 956, 956, 956, 956, 956, 956, 956, 956, 956, |
| 108394 | | - /* 150 */ 956, 936, 934, 956, 881, 956, 956, 956, 956, 956, |
| 108395 | | - /* 160 */ 956, 956, 956, 956, 956, 956, 956, 956, 956, 956, |
| 108396 | | - /* 170 */ 956, 956, 956, 956, 956, 956, 956, 956, 956, 956, |
| 108397 | | - /* 180 */ 956, 640, 758, 758, 758, 634, 956, 956, 956, 948, |
| 108398 | | - /* 190 */ 762, 752, 718, 956, 956, 956, 956, 956, 956, 956, |
| 108399 | | - /* 200 */ 956, 956, 956, 956, 956, 802, 741, 919, 921, 956, |
| 108400 | | - /* 210 */ 902, 739, 662, 760, 675, 750, 642, 796, 775, 775, |
| 108401 | | - /* 220 */ 914, 796, 914, 699, 956, 786, 956, 786, 696, 786, |
| 108402 | | - /* 230 */ 775, 864, 956, 956, 956, 759, 750, 956, 941, 766, |
| 108403 | | - /* 240 */ 766, 933, 933, 766, 808, 731, 796, 738, 738, 738, |
| 108404 | | - /* 250 */ 738, 766, 657, 796, 808, 731, 731, 766, 657, 908, |
| 108405 | | - /* 260 */ 906, 766, 766, 657, 766, 657, 766, 657, 874, 729, |
| 108406 | | - /* 270 */ 729, 729, 714, 878, 878, 874, 729, 699, 729, 714, |
| 108407 | | - /* 280 */ 729, 729, 779, 774, 779, 774, 779, 774, 766, 766, |
| 108408 | | - /* 290 */ 956, 791, 780, 789, 787, 796, 956, 717, 650, 650, |
| 108409 | | - /* 300 */ 639, 639, 639, 639, 953, 953, 948, 701, 701, 683, |
| 108410 | | - /* 310 */ 956, 956, 956, 956, 956, 956, 956, 883, 956, 956, |
| 108411 | | - /* 320 */ 956, 956, 956, 956, 956, 956, 956, 956, 956, 956, |
| 108412 | | - /* 330 */ 635, 943, 956, 956, 940, 956, 956, 956, 956, 801, |
| 108413 | | - /* 340 */ 956, 956, 956, 956, 956, 956, 956, 956, 956, 956, |
| 108414 | | - /* 350 */ 918, 956, 956, 956, 956, 956, 956, 956, 912, 956, |
| 108415 | | - /* 360 */ 956, 956, 956, 956, 956, 905, 904, 956, 956, 956, |
| 108416 | | - /* 370 */ 956, 956, 956, 956, 956, 956, 956, 956, 956, 956, |
| 108417 | | - /* 380 */ 956, 956, 956, 956, 956, 956, 956, 956, 956, 956, |
| 108418 | | - /* 390 */ 956, 956, 956, 788, 956, 781, 956, 867, 956, 956, |
| 108419 | | - /* 400 */ 956, 956, 956, 956, 956, 956, 956, 956, 744, 817, |
| 108420 | | - /* 410 */ 956, 816, 820, 815, 667, 956, 648, 956, 631, 636, |
| 108421 | | - /* 420 */ 952, 955, 954, 951, 950, 949, 944, 942, 939, 938, |
| 108422 | | - /* 430 */ 937, 935, 932, 928, 887, 885, 892, 891, 890, 889, |
| 108423 | | - /* 440 */ 888, 886, 884, 882, 803, 798, 795, 927, 880, 740, |
| 108424 | | - /* 450 */ 737, 736, 656, 945, 911, 920, 807, 806, 809, 917, |
| 108425 | | - /* 460 */ 916, 915, 913, 910, 897, 805, 804, 732, 872, 871, |
| 108426 | | - /* 470 */ 659, 901, 900, 899, 903, 907, 898, 768, 658, 655, |
| 108427 | | - /* 480 */ 664, 721, 720, 728, 726, 725, 724, 723, 722, 719, |
| 108428 | | - /* 490 */ 666, 674, 685, 713, 698, 697, 877, 879, 876, 875, |
| 108429 | | - /* 500 */ 706, 705, 711, 710, 709, 708, 707, 704, 703, 702, |
| 108430 | | - /* 510 */ 695, 694, 700, 693, 716, 715, 712, 692, 735, 734, |
| 108431 | | - /* 520 */ 733, 730, 691, 690, 689, 820, 688, 687, 826, 825, |
| 108432 | | - /* 530 */ 813, 856, 755, 754, 753, 765, 764, 777, 776, 811, |
| 108433 | | - /* 540 */ 810, 778, 763, 757, 756, 772, 771, 770, 769, 761, |
| 108434 | | - /* 550 */ 751, 783, 785, 784, 782, 858, 767, 855, 926, 925, |
| 108435 | | - /* 560 */ 924, 923, 922, 860, 859, 827, 824, 678, 679, 895, |
| 108436 | | - /* 570 */ 894, 896, 893, 681, 680, 677, 676, 857, 746, 745, |
| 108437 | | - /* 580 */ 853, 850, 842, 838, 854, 851, 843, 839, 837, 836, |
| 108438 | | - /* 590 */ 822, 821, 819, 818, 814, 823, 669, 747, 743, 742, |
| 108439 | | - /* 600 */ 812, 749, 748, 686, 684, 682, 663, 661, 654, 652, |
| 108440 | | - /* 610 */ 651, 653, 649, 647, 646, 645, 644, 643, 672, 671, |
| 108441 | | - /* 620 */ 670, 668, 667, 641, 638, 637, 633, 632, 630, |
| 108673 | + /* 0 */ 632, 864, 952, 952, 864, 864, 952, 952, 683, 754, |
| 108674 | + /* 10 */ 952, 952, 952, 862, 952, 952, 782, 782, 926, 952, |
| 108675 | + /* 20 */ 952, 952, 952, 952, 952, 952, 952, 952, 952, 952, |
| 108676 | + /* 30 */ 952, 952, 952, 952, 952, 952, 952, 952, 952, 952, |
| 108677 | + /* 40 */ 952, 952, 952, 952, 952, 952, 952, 952, 952, 952, |
| 108678 | + /* 50 */ 952, 952, 952, 952, 952, 952, 952, 952, 952, 952, |
| 108679 | + /* 60 */ 952, 952, 952, 952, 952, 952, 952, 671, 758, 788, |
| 108680 | + /* 70 */ 952, 952, 952, 952, 952, 952, 952, 952, 925, 927, |
| 108681 | + /* 80 */ 796, 795, 905, 769, 793, 786, 790, 865, 858, 859, |
| 108682 | + /* 90 */ 857, 861, 866, 952, 789, 825, 842, 824, 836, 841, |
| 108683 | + /* 100 */ 848, 840, 837, 827, 826, 828, 829, 952, 952, 952, |
| 108684 | + /* 110 */ 952, 952, 952, 952, 952, 952, 952, 952, 952, 952, |
| 108685 | + /* 120 */ 952, 952, 952, 658, 723, 952, 952, 952, 952, 952, |
| 108686 | + /* 130 */ 952, 952, 952, 830, 831, 845, 844, 843, 952, 952, |
| 108687 | + /* 140 */ 952, 952, 952, 952, 952, 952, 952, 952, 952, 952, |
| 108688 | + /* 150 */ 932, 930, 952, 877, 952, 952, 952, 952, 952, 952, |
| 108689 | + /* 160 */ 952, 952, 952, 952, 952, 952, 952, 952, 952, 952, |
| 108690 | + /* 170 */ 952, 952, 952, 952, 952, 952, 952, 952, 952, 638, |
| 108691 | + /* 180 */ 754, 754, 754, 632, 952, 952, 952, 944, 758, 748, |
| 108692 | + /* 190 */ 952, 952, 952, 952, 952, 952, 952, 952, 952, 952, |
| 108693 | + /* 200 */ 952, 952, 952, 683, 798, 737, 915, 917, 952, 898, |
| 108694 | + /* 210 */ 735, 660, 756, 673, 746, 640, 792, 771, 771, 910, |
| 108695 | + /* 220 */ 792, 910, 697, 952, 782, 952, 782, 694, 782, 771, |
| 108696 | + /* 230 */ 860, 952, 952, 952, 755, 746, 952, 937, 762, 762, |
| 108697 | + /* 240 */ 929, 929, 762, 804, 727, 792, 734, 734, 734, 734, |
| 108698 | + /* 250 */ 762, 655, 792, 804, 727, 727, 762, 655, 904, 902, |
| 108699 | + /* 260 */ 762, 762, 655, 762, 655, 762, 655, 870, 725, 725, |
| 108700 | + /* 270 */ 725, 683, 712, 874, 874, 870, 725, 697, 725, 712, |
| 108701 | + /* 280 */ 725, 725, 775, 770, 775, 770, 775, 770, 762, 762, |
| 108702 | + /* 290 */ 952, 787, 776, 785, 783, 792, 952, 715, 648, 648, |
| 108703 | + /* 300 */ 637, 637, 637, 637, 949, 949, 944, 699, 699, 681, |
| 108704 | + /* 310 */ 952, 952, 952, 952, 952, 952, 952, 879, 952, 952, |
| 108705 | + /* 320 */ 952, 952, 952, 952, 952, 952, 952, 952, 952, 952, |
| 108706 | + /* 330 */ 633, 939, 952, 952, 936, 952, 952, 952, 952, 797, |
| 108707 | + /* 340 */ 952, 952, 952, 952, 952, 952, 952, 952, 952, 952, |
| 108708 | + /* 350 */ 914, 952, 952, 952, 952, 952, 952, 952, 908, 952, |
| 108709 | + /* 360 */ 952, 952, 952, 952, 952, 901, 900, 952, 952, 952, |
| 108710 | + /* 370 */ 952, 952, 952, 952, 952, 952, 952, 952, 952, 952, |
| 108711 | + /* 380 */ 952, 952, 716, 952, 952, 952, 952, 952, 952, 952, |
| 108712 | + /* 390 */ 952, 952, 952, 952, 784, 952, 777, 952, 863, 952, |
| 108713 | + /* 400 */ 952, 952, 952, 952, 952, 952, 952, 952, 952, 740, |
| 108714 | + /* 410 */ 813, 952, 812, 816, 811, 665, 952, 646, 952, 629, |
| 108715 | + /* 420 */ 634, 948, 951, 950, 947, 946, 945, 940, 938, 935, |
| 108716 | + /* 430 */ 934, 933, 931, 928, 924, 883, 881, 888, 887, 886, |
| 108717 | + /* 440 */ 885, 884, 882, 880, 878, 799, 794, 791, 923, 876, |
| 108718 | + /* 450 */ 736, 733, 732, 654, 941, 907, 916, 803, 802, 805, |
| 108719 | + /* 460 */ 913, 912, 911, 909, 906, 893, 801, 800, 728, 868, |
| 108720 | + /* 470 */ 867, 657, 897, 896, 895, 899, 903, 894, 764, 656, |
| 108721 | + /* 480 */ 653, 662, 718, 724, 722, 721, 720, 719, 717, 664, |
| 108722 | + /* 490 */ 672, 682, 711, 696, 695, 873, 875, 872, 871, 704, |
| 108723 | + /* 500 */ 703, 709, 708, 707, 706, 705, 702, 701, 700, 693, |
| 108724 | + /* 510 */ 692, 698, 691, 714, 713, 710, 690, 731, 730, 729, |
| 108725 | + /* 520 */ 726, 689, 688, 687, 816, 686, 685, 822, 821, 809, |
| 108726 | + /* 530 */ 852, 751, 750, 749, 761, 760, 773, 772, 807, 806, |
| 108727 | + /* 540 */ 774, 759, 753, 752, 768, 767, 766, 765, 757, 747, |
| 108728 | + /* 550 */ 779, 781, 780, 778, 854, 763, 851, 922, 921, 920, |
| 108729 | + /* 560 */ 919, 918, 856, 855, 823, 820, 676, 677, 891, 890, |
| 108730 | + /* 570 */ 892, 889, 679, 678, 675, 674, 853, 742, 741, 849, |
| 108731 | + /* 580 */ 846, 838, 834, 850, 847, 839, 835, 833, 832, 818, |
| 108732 | + /* 590 */ 817, 815, 814, 810, 819, 667, 743, 739, 738, 808, |
| 108733 | + /* 600 */ 745, 744, 684, 680, 661, 659, 652, 650, 649, 651, |
| 108734 | + /* 610 */ 647, 645, 644, 643, 642, 641, 670, 669, 668, 666, |
| 108735 | + /* 620 */ 665, 639, 636, 635, 631, 630, 628, |
| 108442 | 108736 | }; |
| 108443 | 108737 | |
| 108444 | 108738 | /* The next table maps tokens into fallback tokens. If a construct |
| 108445 | 108739 | ** like the following: |
| 108446 | 108740 | ** |
| | @@ -108639,11 +108933,11 @@ |
| 108639 | 108933 | "create_table", "create_table_args", "createkw", "temp", |
| 108640 | 108934 | "ifnotexists", "dbnm", "columnlist", "conslist_opt", |
| 108641 | 108935 | "select", "column", "columnid", "type", |
| 108642 | 108936 | "carglist", "id", "ids", "typetoken", |
| 108643 | 108937 | "typename", "signed", "plus_num", "minus_num", |
| 108644 | | - "carg", "ccons", "term", "expr", |
| 108938 | + "cname", "ccons", "term", "expr", |
| 108645 | 108939 | "onconf", "sortorder", "autoinc", "idxlist_opt", |
| 108646 | 108940 | "refargs", "defer_subclause", "refarg", "refact", |
| 108647 | 108941 | "init_deferred_pred_opt", "conslist", "tcons", "idxlist", |
| 108648 | 108942 | "defer_subclause_opt", "orconf", "resolvetype", "raisetype", |
| 108649 | 108943 | "ifexists", "fullname", "oneselect", "multiselect_op", |
| | @@ -108719,14 +109013,14 @@ |
| 108719 | 109013 | /* 48 */ "typetoken ::= typename LP signed COMMA signed RP", |
| 108720 | 109014 | /* 49 */ "typename ::= ids", |
| 108721 | 109015 | /* 50 */ "typename ::= typename ids", |
| 108722 | 109016 | /* 51 */ "signed ::= plus_num", |
| 108723 | 109017 | /* 52 */ "signed ::= minus_num", |
| 108724 | | - /* 53 */ "carglist ::= carglist carg", |
| 109018 | + /* 53 */ "carglist ::= carglist cname ccons", |
| 108725 | 109019 | /* 54 */ "carglist ::=", |
| 108726 | | - /* 55 */ "carg ::= CONSTRAINT nm ccons", |
| 108727 | | - /* 56 */ "carg ::= ccons", |
| 109020 | + /* 55 */ "cname ::= CONSTRAINT nm", |
| 109021 | + /* 56 */ "cname ::=", |
| 108728 | 109022 | /* 57 */ "ccons ::= DEFAULT term", |
| 108729 | 109023 | /* 58 */ "ccons ::= DEFAULT LP expr RP", |
| 108730 | 109024 | /* 59 */ "ccons ::= DEFAULT PLUS term", |
| 108731 | 109025 | /* 60 */ "ccons ::= DEFAULT MINUS term", |
| 108732 | 109026 | /* 61 */ "ccons ::= DEFAULT id", |
| | @@ -108756,247 +109050,245 @@ |
| 108756 | 109050 | /* 85 */ "init_deferred_pred_opt ::=", |
| 108757 | 109051 | /* 86 */ "init_deferred_pred_opt ::= INITIALLY DEFERRED", |
| 108758 | 109052 | /* 87 */ "init_deferred_pred_opt ::= INITIALLY IMMEDIATE", |
| 108759 | 109053 | /* 88 */ "conslist_opt ::=", |
| 108760 | 109054 | /* 89 */ "conslist_opt ::= COMMA conslist", |
| 108761 | | - /* 90 */ "conslist ::= conslist COMMA tcons", |
| 108762 | | - /* 91 */ "conslist ::= conslist tcons", |
| 108763 | | - /* 92 */ "conslist ::= tcons", |
| 108764 | | - /* 93 */ "tcons ::= CONSTRAINT nm", |
| 108765 | | - /* 94 */ "tcons ::= PRIMARY KEY LP idxlist autoinc RP onconf", |
| 108766 | | - /* 95 */ "tcons ::= UNIQUE LP idxlist RP onconf", |
| 108767 | | - /* 96 */ "tcons ::= CHECK LP expr RP onconf", |
| 108768 | | - /* 97 */ "tcons ::= FOREIGN KEY LP idxlist RP REFERENCES nm idxlist_opt refargs defer_subclause_opt", |
| 108769 | | - /* 98 */ "defer_subclause_opt ::=", |
| 108770 | | - /* 99 */ "defer_subclause_opt ::= defer_subclause", |
| 108771 | | - /* 100 */ "onconf ::=", |
| 108772 | | - /* 101 */ "onconf ::= ON CONFLICT resolvetype", |
| 108773 | | - /* 102 */ "orconf ::=", |
| 108774 | | - /* 103 */ "orconf ::= OR resolvetype", |
| 108775 | | - /* 104 */ "resolvetype ::= raisetype", |
| 108776 | | - /* 105 */ "resolvetype ::= IGNORE", |
| 108777 | | - /* 106 */ "resolvetype ::= REPLACE", |
| 108778 | | - /* 107 */ "cmd ::= DROP TABLE ifexists fullname", |
| 108779 | | - /* 108 */ "ifexists ::= IF EXISTS", |
| 108780 | | - /* 109 */ "ifexists ::=", |
| 108781 | | - /* 110 */ "cmd ::= createkw temp VIEW ifnotexists nm dbnm AS select", |
| 108782 | | - /* 111 */ "cmd ::= DROP VIEW ifexists fullname", |
| 108783 | | - /* 112 */ "cmd ::= select", |
| 108784 | | - /* 113 */ "select ::= oneselect", |
| 108785 | | - /* 114 */ "select ::= select multiselect_op oneselect", |
| 108786 | | - /* 115 */ "multiselect_op ::= UNION", |
| 108787 | | - /* 116 */ "multiselect_op ::= UNION ALL", |
| 108788 | | - /* 117 */ "multiselect_op ::= EXCEPT|INTERSECT", |
| 108789 | | - /* 118 */ "oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt", |
| 108790 | | - /* 119 */ "distinct ::= DISTINCT", |
| 108791 | | - /* 120 */ "distinct ::= ALL", |
| 108792 | | - /* 121 */ "distinct ::=", |
| 108793 | | - /* 122 */ "sclp ::= selcollist COMMA", |
| 108794 | | - /* 123 */ "sclp ::=", |
| 108795 | | - /* 124 */ "selcollist ::= sclp expr as", |
| 108796 | | - /* 125 */ "selcollist ::= sclp STAR", |
| 108797 | | - /* 126 */ "selcollist ::= sclp nm DOT STAR", |
| 108798 | | - /* 127 */ "as ::= AS nm", |
| 108799 | | - /* 128 */ "as ::= ids", |
| 108800 | | - /* 129 */ "as ::=", |
| 108801 | | - /* 130 */ "from ::=", |
| 108802 | | - /* 131 */ "from ::= FROM seltablist", |
| 108803 | | - /* 132 */ "stl_prefix ::= seltablist joinop", |
| 108804 | | - /* 133 */ "stl_prefix ::=", |
| 108805 | | - /* 134 */ "seltablist ::= stl_prefix nm dbnm as indexed_opt on_opt using_opt", |
| 108806 | | - /* 135 */ "seltablist ::= stl_prefix LP select RP as on_opt using_opt", |
| 108807 | | - /* 136 */ "seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt", |
| 108808 | | - /* 137 */ "dbnm ::=", |
| 108809 | | - /* 138 */ "dbnm ::= DOT nm", |
| 108810 | | - /* 139 */ "fullname ::= nm dbnm", |
| 108811 | | - /* 140 */ "joinop ::= COMMA|JOIN", |
| 108812 | | - /* 141 */ "joinop ::= JOIN_KW JOIN", |
| 108813 | | - /* 142 */ "joinop ::= JOIN_KW nm JOIN", |
| 108814 | | - /* 143 */ "joinop ::= JOIN_KW nm nm JOIN", |
| 108815 | | - /* 144 */ "on_opt ::= ON expr", |
| 108816 | | - /* 145 */ "on_opt ::=", |
| 108817 | | - /* 146 */ "indexed_opt ::=", |
| 108818 | | - /* 147 */ "indexed_opt ::= INDEXED BY nm", |
| 108819 | | - /* 148 */ "indexed_opt ::= NOT INDEXED", |
| 108820 | | - /* 149 */ "using_opt ::= USING LP inscollist RP", |
| 108821 | | - /* 150 */ "using_opt ::=", |
| 108822 | | - /* 151 */ "orderby_opt ::=", |
| 108823 | | - /* 152 */ "orderby_opt ::= ORDER BY sortlist", |
| 108824 | | - /* 153 */ "sortlist ::= sortlist COMMA expr sortorder", |
| 108825 | | - /* 154 */ "sortlist ::= expr sortorder", |
| 108826 | | - /* 155 */ "sortorder ::= ASC", |
| 108827 | | - /* 156 */ "sortorder ::= DESC", |
| 108828 | | - /* 157 */ "sortorder ::=", |
| 108829 | | - /* 158 */ "groupby_opt ::=", |
| 108830 | | - /* 159 */ "groupby_opt ::= GROUP BY nexprlist", |
| 108831 | | - /* 160 */ "having_opt ::=", |
| 108832 | | - /* 161 */ "having_opt ::= HAVING expr", |
| 108833 | | - /* 162 */ "limit_opt ::=", |
| 108834 | | - /* 163 */ "limit_opt ::= LIMIT expr", |
| 108835 | | - /* 164 */ "limit_opt ::= LIMIT expr OFFSET expr", |
| 108836 | | - /* 165 */ "limit_opt ::= LIMIT expr COMMA expr", |
| 108837 | | - /* 166 */ "cmd ::= DELETE FROM fullname indexed_opt where_opt", |
| 108838 | | - /* 167 */ "where_opt ::=", |
| 108839 | | - /* 168 */ "where_opt ::= WHERE expr", |
| 108840 | | - /* 169 */ "cmd ::= UPDATE orconf fullname indexed_opt SET setlist where_opt", |
| 108841 | | - /* 170 */ "setlist ::= setlist COMMA nm EQ expr", |
| 108842 | | - /* 171 */ "setlist ::= nm EQ expr", |
| 108843 | | - /* 172 */ "cmd ::= insert_cmd INTO fullname inscollist_opt valuelist", |
| 108844 | | - /* 173 */ "cmd ::= insert_cmd INTO fullname inscollist_opt select", |
| 108845 | | - /* 174 */ "cmd ::= insert_cmd INTO fullname inscollist_opt DEFAULT VALUES", |
| 108846 | | - /* 175 */ "insert_cmd ::= INSERT orconf", |
| 108847 | | - /* 176 */ "insert_cmd ::= REPLACE", |
| 108848 | | - /* 177 */ "valuelist ::= VALUES LP nexprlist RP", |
| 108849 | | - /* 178 */ "valuelist ::= valuelist COMMA LP exprlist RP", |
| 108850 | | - /* 179 */ "inscollist_opt ::=", |
| 108851 | | - /* 180 */ "inscollist_opt ::= LP inscollist RP", |
| 108852 | | - /* 181 */ "inscollist ::= inscollist COMMA nm", |
| 108853 | | - /* 182 */ "inscollist ::= nm", |
| 108854 | | - /* 183 */ "expr ::= term", |
| 108855 | | - /* 184 */ "expr ::= LP expr RP", |
| 108856 | | - /* 185 */ "term ::= NULL", |
| 108857 | | - /* 186 */ "expr ::= id", |
| 108858 | | - /* 187 */ "expr ::= JOIN_KW", |
| 108859 | | - /* 188 */ "expr ::= nm DOT nm", |
| 108860 | | - /* 189 */ "expr ::= nm DOT nm DOT nm", |
| 108861 | | - /* 190 */ "term ::= INTEGER|FLOAT|BLOB", |
| 108862 | | - /* 191 */ "term ::= STRING", |
| 108863 | | - /* 192 */ "expr ::= REGISTER", |
| 108864 | | - /* 193 */ "expr ::= VARIABLE", |
| 108865 | | - /* 194 */ "expr ::= expr COLLATE ids", |
| 108866 | | - /* 195 */ "expr ::= CAST LP expr AS typetoken RP", |
| 108867 | | - /* 196 */ "expr ::= ID LP distinct exprlist RP", |
| 108868 | | - /* 197 */ "expr ::= ID LP STAR RP", |
| 108869 | | - /* 198 */ "term ::= CTIME_KW", |
| 108870 | | - /* 199 */ "expr ::= expr AND expr", |
| 108871 | | - /* 200 */ "expr ::= expr OR expr", |
| 108872 | | - /* 201 */ "expr ::= expr LT|GT|GE|LE expr", |
| 108873 | | - /* 202 */ "expr ::= expr EQ|NE expr", |
| 108874 | | - /* 203 */ "expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr", |
| 108875 | | - /* 204 */ "expr ::= expr PLUS|MINUS expr", |
| 108876 | | - /* 205 */ "expr ::= expr STAR|SLASH|REM expr", |
| 108877 | | - /* 206 */ "expr ::= expr CONCAT expr", |
| 108878 | | - /* 207 */ "likeop ::= LIKE_KW", |
| 108879 | | - /* 208 */ "likeop ::= NOT LIKE_KW", |
| 108880 | | - /* 209 */ "likeop ::= MATCH", |
| 108881 | | - /* 210 */ "likeop ::= NOT MATCH", |
| 108882 | | - /* 211 */ "expr ::= expr likeop expr", |
| 108883 | | - /* 212 */ "expr ::= expr likeop expr ESCAPE expr", |
| 108884 | | - /* 213 */ "expr ::= expr ISNULL|NOTNULL", |
| 108885 | | - /* 214 */ "expr ::= expr NOT NULL", |
| 108886 | | - /* 215 */ "expr ::= expr IS expr", |
| 108887 | | - /* 216 */ "expr ::= expr IS NOT expr", |
| 108888 | | - /* 217 */ "expr ::= NOT expr", |
| 108889 | | - /* 218 */ "expr ::= BITNOT expr", |
| 108890 | | - /* 219 */ "expr ::= MINUS expr", |
| 108891 | | - /* 220 */ "expr ::= PLUS expr", |
| 108892 | | - /* 221 */ "between_op ::= BETWEEN", |
| 108893 | | - /* 222 */ "between_op ::= NOT BETWEEN", |
| 108894 | | - /* 223 */ "expr ::= expr between_op expr AND expr", |
| 108895 | | - /* 224 */ "in_op ::= IN", |
| 108896 | | - /* 225 */ "in_op ::= NOT IN", |
| 108897 | | - /* 226 */ "expr ::= expr in_op LP exprlist RP", |
| 108898 | | - /* 227 */ "expr ::= LP select RP", |
| 108899 | | - /* 228 */ "expr ::= expr in_op LP select RP", |
| 108900 | | - /* 229 */ "expr ::= expr in_op nm dbnm", |
| 108901 | | - /* 230 */ "expr ::= EXISTS LP select RP", |
| 108902 | | - /* 231 */ "expr ::= CASE case_operand case_exprlist case_else END", |
| 108903 | | - /* 232 */ "case_exprlist ::= case_exprlist WHEN expr THEN expr", |
| 108904 | | - /* 233 */ "case_exprlist ::= WHEN expr THEN expr", |
| 108905 | | - /* 234 */ "case_else ::= ELSE expr", |
| 108906 | | - /* 235 */ "case_else ::=", |
| 108907 | | - /* 236 */ "case_operand ::= expr", |
| 108908 | | - /* 237 */ "case_operand ::=", |
| 108909 | | - /* 238 */ "exprlist ::= nexprlist", |
| 108910 | | - /* 239 */ "exprlist ::=", |
| 108911 | | - /* 240 */ "nexprlist ::= nexprlist COMMA expr", |
| 108912 | | - /* 241 */ "nexprlist ::= expr", |
| 108913 | | - /* 242 */ "cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP idxlist RP", |
| 108914 | | - /* 243 */ "uniqueflag ::= UNIQUE", |
| 108915 | | - /* 244 */ "uniqueflag ::=", |
| 108916 | | - /* 245 */ "idxlist_opt ::=", |
| 108917 | | - /* 246 */ "idxlist_opt ::= LP idxlist RP", |
| 108918 | | - /* 247 */ "idxlist ::= idxlist COMMA nm collate sortorder", |
| 108919 | | - /* 248 */ "idxlist ::= nm collate sortorder", |
| 108920 | | - /* 249 */ "collate ::=", |
| 108921 | | - /* 250 */ "collate ::= COLLATE ids", |
| 108922 | | - /* 251 */ "cmd ::= DROP INDEX ifexists fullname", |
| 108923 | | - /* 252 */ "cmd ::= VACUUM", |
| 108924 | | - /* 253 */ "cmd ::= VACUUM nm", |
| 108925 | | - /* 254 */ "cmd ::= PRAGMA nm dbnm", |
| 108926 | | - /* 255 */ "cmd ::= PRAGMA nm dbnm EQ nmnum", |
| 108927 | | - /* 256 */ "cmd ::= PRAGMA nm dbnm LP nmnum RP", |
| 108928 | | - /* 257 */ "cmd ::= PRAGMA nm dbnm EQ minus_num", |
| 108929 | | - /* 258 */ "cmd ::= PRAGMA nm dbnm LP minus_num RP", |
| 108930 | | - /* 259 */ "nmnum ::= plus_num", |
| 108931 | | - /* 260 */ "nmnum ::= nm", |
| 108932 | | - /* 261 */ "nmnum ::= ON", |
| 108933 | | - /* 262 */ "nmnum ::= DELETE", |
| 108934 | | - /* 263 */ "nmnum ::= DEFAULT", |
| 108935 | | - /* 264 */ "plus_num ::= PLUS number", |
| 108936 | | - /* 265 */ "plus_num ::= number", |
| 108937 | | - /* 266 */ "minus_num ::= MINUS number", |
| 108938 | | - /* 267 */ "number ::= INTEGER|FLOAT", |
| 108939 | | - /* 268 */ "cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END", |
| 108940 | | - /* 269 */ "trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause", |
| 108941 | | - /* 270 */ "trigger_time ::= BEFORE", |
| 108942 | | - /* 271 */ "trigger_time ::= AFTER", |
| 108943 | | - /* 272 */ "trigger_time ::= INSTEAD OF", |
| 108944 | | - /* 273 */ "trigger_time ::=", |
| 108945 | | - /* 274 */ "trigger_event ::= DELETE|INSERT", |
| 108946 | | - /* 275 */ "trigger_event ::= UPDATE", |
| 108947 | | - /* 276 */ "trigger_event ::= UPDATE OF inscollist", |
| 108948 | | - /* 277 */ "foreach_clause ::=", |
| 108949 | | - /* 278 */ "foreach_clause ::= FOR EACH ROW", |
| 108950 | | - /* 279 */ "when_clause ::=", |
| 108951 | | - /* 280 */ "when_clause ::= WHEN expr", |
| 108952 | | - /* 281 */ "trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI", |
| 108953 | | - /* 282 */ "trigger_cmd_list ::= trigger_cmd SEMI", |
| 108954 | | - /* 283 */ "trnm ::= nm", |
| 108955 | | - /* 284 */ "trnm ::= nm DOT nm", |
| 108956 | | - /* 285 */ "tridxby ::=", |
| 108957 | | - /* 286 */ "tridxby ::= INDEXED BY nm", |
| 108958 | | - /* 287 */ "tridxby ::= NOT INDEXED", |
| 108959 | | - /* 288 */ "trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt", |
| 108960 | | - /* 289 */ "trigger_cmd ::= insert_cmd INTO trnm inscollist_opt valuelist", |
| 108961 | | - /* 290 */ "trigger_cmd ::= insert_cmd INTO trnm inscollist_opt select", |
| 108962 | | - /* 291 */ "trigger_cmd ::= DELETE FROM trnm tridxby where_opt", |
| 108963 | | - /* 292 */ "trigger_cmd ::= select", |
| 108964 | | - /* 293 */ "expr ::= RAISE LP IGNORE RP", |
| 108965 | | - /* 294 */ "expr ::= RAISE LP raisetype COMMA nm RP", |
| 108966 | | - /* 295 */ "raisetype ::= ROLLBACK", |
| 108967 | | - /* 296 */ "raisetype ::= ABORT", |
| 108968 | | - /* 297 */ "raisetype ::= FAIL", |
| 108969 | | - /* 298 */ "cmd ::= DROP TRIGGER ifexists fullname", |
| 108970 | | - /* 299 */ "cmd ::= ATTACH database_kw_opt expr AS expr key_opt", |
| 108971 | | - /* 300 */ "cmd ::= DETACH database_kw_opt expr", |
| 108972 | | - /* 301 */ "key_opt ::=", |
| 108973 | | - /* 302 */ "key_opt ::= KEY expr", |
| 108974 | | - /* 303 */ "database_kw_opt ::= DATABASE", |
| 108975 | | - /* 304 */ "database_kw_opt ::=", |
| 108976 | | - /* 305 */ "cmd ::= REINDEX", |
| 108977 | | - /* 306 */ "cmd ::= REINDEX nm dbnm", |
| 108978 | | - /* 307 */ "cmd ::= ANALYZE", |
| 108979 | | - /* 308 */ "cmd ::= ANALYZE nm dbnm", |
| 108980 | | - /* 309 */ "cmd ::= ALTER TABLE fullname RENAME TO nm", |
| 108981 | | - /* 310 */ "cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt column", |
| 108982 | | - /* 311 */ "add_column_fullname ::= fullname", |
| 108983 | | - /* 312 */ "kwcolumn_opt ::=", |
| 108984 | | - /* 313 */ "kwcolumn_opt ::= COLUMNKW", |
| 108985 | | - /* 314 */ "cmd ::= create_vtab", |
| 108986 | | - /* 315 */ "cmd ::= create_vtab LP vtabarglist RP", |
| 108987 | | - /* 316 */ "create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm", |
| 108988 | | - /* 317 */ "vtabarglist ::= vtabarg", |
| 108989 | | - /* 318 */ "vtabarglist ::= vtabarglist COMMA vtabarg", |
| 108990 | | - /* 319 */ "vtabarg ::=", |
| 108991 | | - /* 320 */ "vtabarg ::= vtabarg vtabargtoken", |
| 108992 | | - /* 321 */ "vtabargtoken ::= ANY", |
| 108993 | | - /* 322 */ "vtabargtoken ::= lp anylist RP", |
| 108994 | | - /* 323 */ "lp ::= LP", |
| 108995 | | - /* 324 */ "anylist ::=", |
| 108996 | | - /* 325 */ "anylist ::= anylist LP anylist RP", |
| 108997 | | - /* 326 */ "anylist ::= anylist ANY", |
| 109055 | + /* 90 */ "conslist ::= conslist COMMA cname tcons", |
| 109056 | + /* 91 */ "conslist ::= cname tcons", |
| 109057 | + /* 92 */ "tcons ::= PRIMARY KEY LP idxlist autoinc RP onconf", |
| 109058 | + /* 93 */ "tcons ::= UNIQUE LP idxlist RP onconf", |
| 109059 | + /* 94 */ "tcons ::= CHECK LP expr RP onconf", |
| 109060 | + /* 95 */ "tcons ::= FOREIGN KEY LP idxlist RP REFERENCES nm idxlist_opt refargs defer_subclause_opt", |
| 109061 | + /* 96 */ "defer_subclause_opt ::=", |
| 109062 | + /* 97 */ "defer_subclause_opt ::= defer_subclause", |
| 109063 | + /* 98 */ "onconf ::=", |
| 109064 | + /* 99 */ "onconf ::= ON CONFLICT resolvetype", |
| 109065 | + /* 100 */ "orconf ::=", |
| 109066 | + /* 101 */ "orconf ::= OR resolvetype", |
| 109067 | + /* 102 */ "resolvetype ::= raisetype", |
| 109068 | + /* 103 */ "resolvetype ::= IGNORE", |
| 109069 | + /* 104 */ "resolvetype ::= REPLACE", |
| 109070 | + /* 105 */ "cmd ::= DROP TABLE ifexists fullname", |
| 109071 | + /* 106 */ "ifexists ::= IF EXISTS", |
| 109072 | + /* 107 */ "ifexists ::=", |
| 109073 | + /* 108 */ "cmd ::= createkw temp VIEW ifnotexists nm dbnm AS select", |
| 109074 | + /* 109 */ "cmd ::= DROP VIEW ifexists fullname", |
| 109075 | + /* 110 */ "cmd ::= select", |
| 109076 | + /* 111 */ "select ::= oneselect", |
| 109077 | + /* 112 */ "select ::= select multiselect_op oneselect", |
| 109078 | + /* 113 */ "multiselect_op ::= UNION", |
| 109079 | + /* 114 */ "multiselect_op ::= UNION ALL", |
| 109080 | + /* 115 */ "multiselect_op ::= EXCEPT|INTERSECT", |
| 109081 | + /* 116 */ "oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt", |
| 109082 | + /* 117 */ "distinct ::= DISTINCT", |
| 109083 | + /* 118 */ "distinct ::= ALL", |
| 109084 | + /* 119 */ "distinct ::=", |
| 109085 | + /* 120 */ "sclp ::= selcollist COMMA", |
| 109086 | + /* 121 */ "sclp ::=", |
| 109087 | + /* 122 */ "selcollist ::= sclp expr as", |
| 109088 | + /* 123 */ "selcollist ::= sclp STAR", |
| 109089 | + /* 124 */ "selcollist ::= sclp nm DOT STAR", |
| 109090 | + /* 125 */ "as ::= AS nm", |
| 109091 | + /* 126 */ "as ::= ids", |
| 109092 | + /* 127 */ "as ::=", |
| 109093 | + /* 128 */ "from ::=", |
| 109094 | + /* 129 */ "from ::= FROM seltablist", |
| 109095 | + /* 130 */ "stl_prefix ::= seltablist joinop", |
| 109096 | + /* 131 */ "stl_prefix ::=", |
| 109097 | + /* 132 */ "seltablist ::= stl_prefix nm dbnm as indexed_opt on_opt using_opt", |
| 109098 | + /* 133 */ "seltablist ::= stl_prefix LP select RP as on_opt using_opt", |
| 109099 | + /* 134 */ "seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt", |
| 109100 | + /* 135 */ "dbnm ::=", |
| 109101 | + /* 136 */ "dbnm ::= DOT nm", |
| 109102 | + /* 137 */ "fullname ::= nm dbnm", |
| 109103 | + /* 138 */ "joinop ::= COMMA|JOIN", |
| 109104 | + /* 139 */ "joinop ::= JOIN_KW JOIN", |
| 109105 | + /* 140 */ "joinop ::= JOIN_KW nm JOIN", |
| 109106 | + /* 141 */ "joinop ::= JOIN_KW nm nm JOIN", |
| 109107 | + /* 142 */ "on_opt ::= ON expr", |
| 109108 | + /* 143 */ "on_opt ::=", |
| 109109 | + /* 144 */ "indexed_opt ::=", |
| 109110 | + /* 145 */ "indexed_opt ::= INDEXED BY nm", |
| 109111 | + /* 146 */ "indexed_opt ::= NOT INDEXED", |
| 109112 | + /* 147 */ "using_opt ::= USING LP inscollist RP", |
| 109113 | + /* 148 */ "using_opt ::=", |
| 109114 | + /* 149 */ "orderby_opt ::=", |
| 109115 | + /* 150 */ "orderby_opt ::= ORDER BY sortlist", |
| 109116 | + /* 151 */ "sortlist ::= sortlist COMMA expr sortorder", |
| 109117 | + /* 152 */ "sortlist ::= expr sortorder", |
| 109118 | + /* 153 */ "sortorder ::= ASC", |
| 109119 | + /* 154 */ "sortorder ::= DESC", |
| 109120 | + /* 155 */ "sortorder ::=", |
| 109121 | + /* 156 */ "groupby_opt ::=", |
| 109122 | + /* 157 */ "groupby_opt ::= GROUP BY nexprlist", |
| 109123 | + /* 158 */ "having_opt ::=", |
| 109124 | + /* 159 */ "having_opt ::= HAVING expr", |
| 109125 | + /* 160 */ "limit_opt ::=", |
| 109126 | + /* 161 */ "limit_opt ::= LIMIT expr", |
| 109127 | + /* 162 */ "limit_opt ::= LIMIT expr OFFSET expr", |
| 109128 | + /* 163 */ "limit_opt ::= LIMIT expr COMMA expr", |
| 109129 | + /* 164 */ "cmd ::= DELETE FROM fullname indexed_opt where_opt", |
| 109130 | + /* 165 */ "where_opt ::=", |
| 109131 | + /* 166 */ "where_opt ::= WHERE expr", |
| 109132 | + /* 167 */ "cmd ::= UPDATE orconf fullname indexed_opt SET setlist where_opt", |
| 109133 | + /* 168 */ "setlist ::= setlist COMMA nm EQ expr", |
| 109134 | + /* 169 */ "setlist ::= nm EQ expr", |
| 109135 | + /* 170 */ "cmd ::= insert_cmd INTO fullname inscollist_opt valuelist", |
| 109136 | + /* 171 */ "cmd ::= insert_cmd INTO fullname inscollist_opt select", |
| 109137 | + /* 172 */ "cmd ::= insert_cmd INTO fullname inscollist_opt DEFAULT VALUES", |
| 109138 | + /* 173 */ "insert_cmd ::= INSERT orconf", |
| 109139 | + /* 174 */ "insert_cmd ::= REPLACE", |
| 109140 | + /* 175 */ "valuelist ::= VALUES LP nexprlist RP", |
| 109141 | + /* 176 */ "valuelist ::= valuelist COMMA LP exprlist RP", |
| 109142 | + /* 177 */ "inscollist_opt ::=", |
| 109143 | + /* 178 */ "inscollist_opt ::= LP inscollist RP", |
| 109144 | + /* 179 */ "inscollist ::= inscollist COMMA nm", |
| 109145 | + /* 180 */ "inscollist ::= nm", |
| 109146 | + /* 181 */ "expr ::= term", |
| 109147 | + /* 182 */ "expr ::= LP expr RP", |
| 109148 | + /* 183 */ "term ::= NULL", |
| 109149 | + /* 184 */ "expr ::= id", |
| 109150 | + /* 185 */ "expr ::= JOIN_KW", |
| 109151 | + /* 186 */ "expr ::= nm DOT nm", |
| 109152 | + /* 187 */ "expr ::= nm DOT nm DOT nm", |
| 109153 | + /* 188 */ "term ::= INTEGER|FLOAT|BLOB", |
| 109154 | + /* 189 */ "term ::= STRING", |
| 109155 | + /* 190 */ "expr ::= REGISTER", |
| 109156 | + /* 191 */ "expr ::= VARIABLE", |
| 109157 | + /* 192 */ "expr ::= expr COLLATE ids", |
| 109158 | + /* 193 */ "expr ::= CAST LP expr AS typetoken RP", |
| 109159 | + /* 194 */ "expr ::= ID LP distinct exprlist RP", |
| 109160 | + /* 195 */ "expr ::= ID LP STAR RP", |
| 109161 | + /* 196 */ "term ::= CTIME_KW", |
| 109162 | + /* 197 */ "expr ::= expr AND expr", |
| 109163 | + /* 198 */ "expr ::= expr OR expr", |
| 109164 | + /* 199 */ "expr ::= expr LT|GT|GE|LE expr", |
| 109165 | + /* 200 */ "expr ::= expr EQ|NE expr", |
| 109166 | + /* 201 */ "expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr", |
| 109167 | + /* 202 */ "expr ::= expr PLUS|MINUS expr", |
| 109168 | + /* 203 */ "expr ::= expr STAR|SLASH|REM expr", |
| 109169 | + /* 204 */ "expr ::= expr CONCAT expr", |
| 109170 | + /* 205 */ "likeop ::= LIKE_KW", |
| 109171 | + /* 206 */ "likeop ::= NOT LIKE_KW", |
| 109172 | + /* 207 */ "likeop ::= MATCH", |
| 109173 | + /* 208 */ "likeop ::= NOT MATCH", |
| 109174 | + /* 209 */ "expr ::= expr likeop expr", |
| 109175 | + /* 210 */ "expr ::= expr likeop expr ESCAPE expr", |
| 109176 | + /* 211 */ "expr ::= expr ISNULL|NOTNULL", |
| 109177 | + /* 212 */ "expr ::= expr NOT NULL", |
| 109178 | + /* 213 */ "expr ::= expr IS expr", |
| 109179 | + /* 214 */ "expr ::= expr IS NOT expr", |
| 109180 | + /* 215 */ "expr ::= NOT expr", |
| 109181 | + /* 216 */ "expr ::= BITNOT expr", |
| 109182 | + /* 217 */ "expr ::= MINUS expr", |
| 109183 | + /* 218 */ "expr ::= PLUS expr", |
| 109184 | + /* 219 */ "between_op ::= BETWEEN", |
| 109185 | + /* 220 */ "between_op ::= NOT BETWEEN", |
| 109186 | + /* 221 */ "expr ::= expr between_op expr AND expr", |
| 109187 | + /* 222 */ "in_op ::= IN", |
| 109188 | + /* 223 */ "in_op ::= NOT IN", |
| 109189 | + /* 224 */ "expr ::= expr in_op LP exprlist RP", |
| 109190 | + /* 225 */ "expr ::= LP select RP", |
| 109191 | + /* 226 */ "expr ::= expr in_op LP select RP", |
| 109192 | + /* 227 */ "expr ::= expr in_op nm dbnm", |
| 109193 | + /* 228 */ "expr ::= EXISTS LP select RP", |
| 109194 | + /* 229 */ "expr ::= CASE case_operand case_exprlist case_else END", |
| 109195 | + /* 230 */ "case_exprlist ::= case_exprlist WHEN expr THEN expr", |
| 109196 | + /* 231 */ "case_exprlist ::= WHEN expr THEN expr", |
| 109197 | + /* 232 */ "case_else ::= ELSE expr", |
| 109198 | + /* 233 */ "case_else ::=", |
| 109199 | + /* 234 */ "case_operand ::= expr", |
| 109200 | + /* 235 */ "case_operand ::=", |
| 109201 | + /* 236 */ "exprlist ::= nexprlist", |
| 109202 | + /* 237 */ "exprlist ::=", |
| 109203 | + /* 238 */ "nexprlist ::= nexprlist COMMA expr", |
| 109204 | + /* 239 */ "nexprlist ::= expr", |
| 109205 | + /* 240 */ "cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP idxlist RP", |
| 109206 | + /* 241 */ "uniqueflag ::= UNIQUE", |
| 109207 | + /* 242 */ "uniqueflag ::=", |
| 109208 | + /* 243 */ "idxlist_opt ::=", |
| 109209 | + /* 244 */ "idxlist_opt ::= LP idxlist RP", |
| 109210 | + /* 245 */ "idxlist ::= idxlist COMMA nm collate sortorder", |
| 109211 | + /* 246 */ "idxlist ::= nm collate sortorder", |
| 109212 | + /* 247 */ "collate ::=", |
| 109213 | + /* 248 */ "collate ::= COLLATE ids", |
| 109214 | + /* 249 */ "cmd ::= DROP INDEX ifexists fullname", |
| 109215 | + /* 250 */ "cmd ::= VACUUM", |
| 109216 | + /* 251 */ "cmd ::= VACUUM nm", |
| 109217 | + /* 252 */ "cmd ::= PRAGMA nm dbnm", |
| 109218 | + /* 253 */ "cmd ::= PRAGMA nm dbnm EQ nmnum", |
| 109219 | + /* 254 */ "cmd ::= PRAGMA nm dbnm LP nmnum RP", |
| 109220 | + /* 255 */ "cmd ::= PRAGMA nm dbnm EQ minus_num", |
| 109221 | + /* 256 */ "cmd ::= PRAGMA nm dbnm LP minus_num RP", |
| 109222 | + /* 257 */ "nmnum ::= plus_num", |
| 109223 | + /* 258 */ "nmnum ::= nm", |
| 109224 | + /* 259 */ "nmnum ::= ON", |
| 109225 | + /* 260 */ "nmnum ::= DELETE", |
| 109226 | + /* 261 */ "nmnum ::= DEFAULT", |
| 109227 | + /* 262 */ "plus_num ::= PLUS number", |
| 109228 | + /* 263 */ "plus_num ::= number", |
| 109229 | + /* 264 */ "minus_num ::= MINUS number", |
| 109230 | + /* 265 */ "number ::= INTEGER|FLOAT", |
| 109231 | + /* 266 */ "cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END", |
| 109232 | + /* 267 */ "trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause", |
| 109233 | + /* 268 */ "trigger_time ::= BEFORE", |
| 109234 | + /* 269 */ "trigger_time ::= AFTER", |
| 109235 | + /* 270 */ "trigger_time ::= INSTEAD OF", |
| 109236 | + /* 271 */ "trigger_time ::=", |
| 109237 | + /* 272 */ "trigger_event ::= DELETE|INSERT", |
| 109238 | + /* 273 */ "trigger_event ::= UPDATE", |
| 109239 | + /* 274 */ "trigger_event ::= UPDATE OF inscollist", |
| 109240 | + /* 275 */ "foreach_clause ::=", |
| 109241 | + /* 276 */ "foreach_clause ::= FOR EACH ROW", |
| 109242 | + /* 277 */ "when_clause ::=", |
| 109243 | + /* 278 */ "when_clause ::= WHEN expr", |
| 109244 | + /* 279 */ "trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI", |
| 109245 | + /* 280 */ "trigger_cmd_list ::= trigger_cmd SEMI", |
| 109246 | + /* 281 */ "trnm ::= nm", |
| 109247 | + /* 282 */ "trnm ::= nm DOT nm", |
| 109248 | + /* 283 */ "tridxby ::=", |
| 109249 | + /* 284 */ "tridxby ::= INDEXED BY nm", |
| 109250 | + /* 285 */ "tridxby ::= NOT INDEXED", |
| 109251 | + /* 286 */ "trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt", |
| 109252 | + /* 287 */ "trigger_cmd ::= insert_cmd INTO trnm inscollist_opt valuelist", |
| 109253 | + /* 288 */ "trigger_cmd ::= insert_cmd INTO trnm inscollist_opt select", |
| 109254 | + /* 289 */ "trigger_cmd ::= DELETE FROM trnm tridxby where_opt", |
| 109255 | + /* 290 */ "trigger_cmd ::= select", |
| 109256 | + /* 291 */ "expr ::= RAISE LP IGNORE RP", |
| 109257 | + /* 292 */ "expr ::= RAISE LP raisetype COMMA nm RP", |
| 109258 | + /* 293 */ "raisetype ::= ROLLBACK", |
| 109259 | + /* 294 */ "raisetype ::= ABORT", |
| 109260 | + /* 295 */ "raisetype ::= FAIL", |
| 109261 | + /* 296 */ "cmd ::= DROP TRIGGER ifexists fullname", |
| 109262 | + /* 297 */ "cmd ::= ATTACH database_kw_opt expr AS expr key_opt", |
| 109263 | + /* 298 */ "cmd ::= DETACH database_kw_opt expr", |
| 109264 | + /* 299 */ "key_opt ::=", |
| 109265 | + /* 300 */ "key_opt ::= KEY expr", |
| 109266 | + /* 301 */ "database_kw_opt ::= DATABASE", |
| 109267 | + /* 302 */ "database_kw_opt ::=", |
| 109268 | + /* 303 */ "cmd ::= REINDEX", |
| 109269 | + /* 304 */ "cmd ::= REINDEX nm dbnm", |
| 109270 | + /* 305 */ "cmd ::= ANALYZE", |
| 109271 | + /* 306 */ "cmd ::= ANALYZE nm dbnm", |
| 109272 | + /* 307 */ "cmd ::= ALTER TABLE fullname RENAME TO nm", |
| 109273 | + /* 308 */ "cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt column", |
| 109274 | + /* 309 */ "add_column_fullname ::= fullname", |
| 109275 | + /* 310 */ "kwcolumn_opt ::=", |
| 109276 | + /* 311 */ "kwcolumn_opt ::= COLUMNKW", |
| 109277 | + /* 312 */ "cmd ::= create_vtab", |
| 109278 | + /* 313 */ "cmd ::= create_vtab LP vtabarglist RP", |
| 109279 | + /* 314 */ "create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm", |
| 109280 | + /* 315 */ "vtabarglist ::= vtabarg", |
| 109281 | + /* 316 */ "vtabarglist ::= vtabarglist COMMA vtabarg", |
| 109282 | + /* 317 */ "vtabarg ::=", |
| 109283 | + /* 318 */ "vtabarg ::= vtabarg vtabargtoken", |
| 109284 | + /* 319 */ "vtabargtoken ::= ANY", |
| 109285 | + /* 320 */ "vtabargtoken ::= lp anylist RP", |
| 109286 | + /* 321 */ "lp ::= LP", |
| 109287 | + /* 322 */ "anylist ::=", |
| 109288 | + /* 323 */ "anylist ::= anylist LP anylist RP", |
| 109289 | + /* 324 */ "anylist ::= anylist ANY", |
| 108998 | 109290 | }; |
| 108999 | 109291 | #endif /* NDEBUG */ |
| 109000 | 109292 | |
| 109001 | 109293 | |
| 109002 | 109294 | #if YYSTACKDEPTH<=0 |
| | @@ -109438,14 +109730,14 @@ |
| 109438 | 109730 | { 167, 6 }, |
| 109439 | 109731 | { 168, 1 }, |
| 109440 | 109732 | { 168, 2 }, |
| 109441 | 109733 | { 169, 1 }, |
| 109442 | 109734 | { 169, 1 }, |
| 109443 | | - { 164, 2 }, |
| 109735 | + { 164, 3 }, |
| 109444 | 109736 | { 164, 0 }, |
| 109445 | | - { 172, 3 }, |
| 109446 | | - { 172, 1 }, |
| 109737 | + { 172, 2 }, |
| 109738 | + { 172, 0 }, |
| 109447 | 109739 | { 173, 2 }, |
| 109448 | 109740 | { 173, 4 }, |
| 109449 | 109741 | { 173, 3 }, |
| 109450 | 109742 | { 173, 3 }, |
| 109451 | 109743 | { 173, 2 }, |
| | @@ -109475,14 +109767,12 @@ |
| 109475 | 109767 | { 184, 0 }, |
| 109476 | 109768 | { 184, 2 }, |
| 109477 | 109769 | { 184, 2 }, |
| 109478 | 109770 | { 159, 0 }, |
| 109479 | 109771 | { 159, 2 }, |
| 109480 | | - { 185, 3 }, |
| 109772 | + { 185, 4 }, |
| 109481 | 109773 | { 185, 2 }, |
| 109482 | | - { 185, 1 }, |
| 109483 | | - { 186, 2 }, |
| 109484 | 109774 | { 186, 7 }, |
| 109485 | 109775 | { 186, 5 }, |
| 109486 | 109776 | { 186, 5 }, |
| 109487 | 109777 | { 186, 10 }, |
| 109488 | 109778 | { 188, 0 }, |
| | @@ -109787,12 +110077,12 @@ |
| 109787 | 110077 | {yygotominor.yy392 = TK_DEFERRED;} |
| 109788 | 110078 | break; |
| 109789 | 110079 | case 14: /* transtype ::= DEFERRED */ |
| 109790 | 110080 | case 15: /* transtype ::= IMMEDIATE */ yytestcase(yyruleno==15); |
| 109791 | 110081 | case 16: /* transtype ::= EXCLUSIVE */ yytestcase(yyruleno==16); |
| 109792 | | - case 115: /* multiselect_op ::= UNION */ yytestcase(yyruleno==115); |
| 109793 | | - case 117: /* multiselect_op ::= EXCEPT|INTERSECT */ yytestcase(yyruleno==117); |
| 110082 | + case 113: /* multiselect_op ::= UNION */ yytestcase(yyruleno==113); |
| 110083 | + case 115: /* multiselect_op ::= EXCEPT|INTERSECT */ yytestcase(yyruleno==115); |
| 109794 | 110084 | {yygotominor.yy392 = yymsp[0].major;} |
| 109795 | 110085 | break; |
| 109796 | 110086 | case 17: /* cmd ::= COMMIT trans_opt */ |
| 109797 | 110087 | case 18: /* cmd ::= END trans_opt */ yytestcase(yyruleno==18); |
| 109798 | 110088 | {sqlite3CommitTransaction(pParse);} |
| | @@ -109830,26 +110120,26 @@ |
| 109830 | 110120 | case 31: /* temp ::= */ yytestcase(yyruleno==31); |
| 109831 | 110121 | case 70: /* autoinc ::= */ yytestcase(yyruleno==70); |
| 109832 | 110122 | case 83: /* defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt */ yytestcase(yyruleno==83); |
| 109833 | 110123 | case 85: /* init_deferred_pred_opt ::= */ yytestcase(yyruleno==85); |
| 109834 | 110124 | case 87: /* init_deferred_pred_opt ::= INITIALLY IMMEDIATE */ yytestcase(yyruleno==87); |
| 109835 | | - case 98: /* defer_subclause_opt ::= */ yytestcase(yyruleno==98); |
| 109836 | | - case 109: /* ifexists ::= */ yytestcase(yyruleno==109); |
| 109837 | | - case 120: /* distinct ::= ALL */ yytestcase(yyruleno==120); |
| 109838 | | - case 121: /* distinct ::= */ yytestcase(yyruleno==121); |
| 109839 | | - case 221: /* between_op ::= BETWEEN */ yytestcase(yyruleno==221); |
| 109840 | | - case 224: /* in_op ::= IN */ yytestcase(yyruleno==224); |
| 110125 | + case 96: /* defer_subclause_opt ::= */ yytestcase(yyruleno==96); |
| 110126 | + case 107: /* ifexists ::= */ yytestcase(yyruleno==107); |
| 110127 | + case 118: /* distinct ::= ALL */ yytestcase(yyruleno==118); |
| 110128 | + case 119: /* distinct ::= */ yytestcase(yyruleno==119); |
| 110129 | + case 219: /* between_op ::= BETWEEN */ yytestcase(yyruleno==219); |
| 110130 | + case 222: /* in_op ::= IN */ yytestcase(yyruleno==222); |
| 109841 | 110131 | {yygotominor.yy392 = 0;} |
| 109842 | 110132 | break; |
| 109843 | 110133 | case 29: /* ifnotexists ::= IF NOT EXISTS */ |
| 109844 | 110134 | case 30: /* temp ::= TEMP */ yytestcase(yyruleno==30); |
| 109845 | 110135 | case 71: /* autoinc ::= AUTOINCR */ yytestcase(yyruleno==71); |
| 109846 | 110136 | case 86: /* init_deferred_pred_opt ::= INITIALLY DEFERRED */ yytestcase(yyruleno==86); |
| 109847 | | - case 108: /* ifexists ::= IF EXISTS */ yytestcase(yyruleno==108); |
| 109848 | | - case 119: /* distinct ::= DISTINCT */ yytestcase(yyruleno==119); |
| 109849 | | - case 222: /* between_op ::= NOT BETWEEN */ yytestcase(yyruleno==222); |
| 109850 | | - case 225: /* in_op ::= NOT IN */ yytestcase(yyruleno==225); |
| 110137 | + case 106: /* ifexists ::= IF EXISTS */ yytestcase(yyruleno==106); |
| 110138 | + case 117: /* distinct ::= DISTINCT */ yytestcase(yyruleno==117); |
| 110139 | + case 220: /* between_op ::= NOT BETWEEN */ yytestcase(yyruleno==220); |
| 110140 | + case 223: /* in_op ::= NOT IN */ yytestcase(yyruleno==223); |
| 109851 | 110141 | {yygotominor.yy392 = 1;} |
| 109852 | 110142 | break; |
| 109853 | 110143 | case 32: /* create_table_args ::= LP columnlist conslist_opt RP */ |
| 109854 | 110144 | { |
| 109855 | 110145 | sqlite3EndTable(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,0); |
| | @@ -109879,25 +110169,25 @@ |
| 109879 | 110169 | case 41: /* nm ::= id */ yytestcase(yyruleno==41); |
| 109880 | 110170 | case 42: /* nm ::= STRING */ yytestcase(yyruleno==42); |
| 109881 | 110171 | case 43: /* nm ::= JOIN_KW */ yytestcase(yyruleno==43); |
| 109882 | 110172 | case 46: /* typetoken ::= typename */ yytestcase(yyruleno==46); |
| 109883 | 110173 | case 49: /* typename ::= ids */ yytestcase(yyruleno==49); |
| 109884 | | - case 127: /* as ::= AS nm */ yytestcase(yyruleno==127); |
| 109885 | | - case 128: /* as ::= ids */ yytestcase(yyruleno==128); |
| 109886 | | - case 138: /* dbnm ::= DOT nm */ yytestcase(yyruleno==138); |
| 109887 | | - case 147: /* indexed_opt ::= INDEXED BY nm */ yytestcase(yyruleno==147); |
| 109888 | | - case 250: /* collate ::= COLLATE ids */ yytestcase(yyruleno==250); |
| 109889 | | - case 259: /* nmnum ::= plus_num */ yytestcase(yyruleno==259); |
| 109890 | | - case 260: /* nmnum ::= nm */ yytestcase(yyruleno==260); |
| 109891 | | - case 261: /* nmnum ::= ON */ yytestcase(yyruleno==261); |
| 109892 | | - case 262: /* nmnum ::= DELETE */ yytestcase(yyruleno==262); |
| 109893 | | - case 263: /* nmnum ::= DEFAULT */ yytestcase(yyruleno==263); |
| 109894 | | - case 264: /* plus_num ::= PLUS number */ yytestcase(yyruleno==264); |
| 109895 | | - case 265: /* plus_num ::= number */ yytestcase(yyruleno==265); |
| 109896 | | - case 266: /* minus_num ::= MINUS number */ yytestcase(yyruleno==266); |
| 109897 | | - case 267: /* number ::= INTEGER|FLOAT */ yytestcase(yyruleno==267); |
| 109898 | | - case 283: /* trnm ::= nm */ yytestcase(yyruleno==283); |
| 110174 | + case 125: /* as ::= AS nm */ yytestcase(yyruleno==125); |
| 110175 | + case 126: /* as ::= ids */ yytestcase(yyruleno==126); |
| 110176 | + case 136: /* dbnm ::= DOT nm */ yytestcase(yyruleno==136); |
| 110177 | + case 145: /* indexed_opt ::= INDEXED BY nm */ yytestcase(yyruleno==145); |
| 110178 | + case 248: /* collate ::= COLLATE ids */ yytestcase(yyruleno==248); |
| 110179 | + case 257: /* nmnum ::= plus_num */ yytestcase(yyruleno==257); |
| 110180 | + case 258: /* nmnum ::= nm */ yytestcase(yyruleno==258); |
| 110181 | + case 259: /* nmnum ::= ON */ yytestcase(yyruleno==259); |
| 110182 | + case 260: /* nmnum ::= DELETE */ yytestcase(yyruleno==260); |
| 110183 | + case 261: /* nmnum ::= DEFAULT */ yytestcase(yyruleno==261); |
| 110184 | + case 262: /* plus_num ::= PLUS number */ yytestcase(yyruleno==262); |
| 110185 | + case 263: /* plus_num ::= number */ yytestcase(yyruleno==263); |
| 110186 | + case 264: /* minus_num ::= MINUS number */ yytestcase(yyruleno==264); |
| 110187 | + case 265: /* number ::= INTEGER|FLOAT */ yytestcase(yyruleno==265); |
| 110188 | + case 281: /* trnm ::= nm */ yytestcase(yyruleno==281); |
| 109899 | 110189 | {yygotominor.yy0 = yymsp[0].minor.yy0;} |
| 109900 | 110190 | break; |
| 109901 | 110191 | case 45: /* type ::= typetoken */ |
| 109902 | 110192 | {sqlite3AddColumnType(pParse,&yymsp[0].minor.yy0);} |
| 109903 | 110193 | break; |
| | @@ -109913,10 +110203,16 @@ |
| 109913 | 110203 | yygotominor.yy0.n = (int)(&yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n] - yymsp[-5].minor.yy0.z); |
| 109914 | 110204 | } |
| 109915 | 110205 | break; |
| 109916 | 110206 | case 50: /* typename ::= typename ids */ |
| 109917 | 110207 | {yygotominor.yy0.z=yymsp[-1].minor.yy0.z; yygotominor.yy0.n=yymsp[0].minor.yy0.n+(int)(yymsp[0].minor.yy0.z-yymsp[-1].minor.yy0.z);} |
| 110208 | + break; |
| 110209 | + case 55: /* cname ::= CONSTRAINT nm */ |
| 110210 | +{pParse->constraintName = yymsp[0].minor.yy0;} |
| 110211 | + break; |
| 110212 | + case 56: /* cname ::= */ |
| 110213 | +{pParse->constraintName.n = 0;} |
| 109918 | 110214 | break; |
| 109919 | 110215 | case 57: /* ccons ::= DEFAULT term */ |
| 109920 | 110216 | case 59: /* ccons ::= DEFAULT PLUS term */ yytestcase(yyruleno==59); |
| 109921 | 110217 | {sqlite3AddDefaultValue(pParse,&yymsp[0].minor.yy342);} |
| 109922 | 110218 | break; |
| | @@ -109990,80 +110286,80 @@ |
| 109990 | 110286 | break; |
| 109991 | 110287 | case 82: /* refact ::= NO ACTION */ |
| 109992 | 110288 | { yygotominor.yy392 = OE_None; /* EV: R-33326-45252 */} |
| 109993 | 110289 | break; |
| 109994 | 110290 | case 84: /* defer_subclause ::= DEFERRABLE init_deferred_pred_opt */ |
| 109995 | | - case 99: /* defer_subclause_opt ::= defer_subclause */ yytestcase(yyruleno==99); |
| 109996 | | - case 101: /* onconf ::= ON CONFLICT resolvetype */ yytestcase(yyruleno==101); |
| 109997 | | - case 104: /* resolvetype ::= raisetype */ yytestcase(yyruleno==104); |
| 110291 | + case 97: /* defer_subclause_opt ::= defer_subclause */ yytestcase(yyruleno==97); |
| 110292 | + case 99: /* onconf ::= ON CONFLICT resolvetype */ yytestcase(yyruleno==99); |
| 110293 | + case 102: /* resolvetype ::= raisetype */ yytestcase(yyruleno==102); |
| 109998 | 110294 | {yygotominor.yy392 = yymsp[0].minor.yy392;} |
| 109999 | 110295 | break; |
| 110000 | 110296 | case 88: /* conslist_opt ::= */ |
| 110001 | 110297 | {yygotominor.yy0.n = 0; yygotominor.yy0.z = 0;} |
| 110002 | 110298 | break; |
| 110003 | 110299 | case 89: /* conslist_opt ::= COMMA conslist */ |
| 110004 | 110300 | {yygotominor.yy0 = yymsp[-1].minor.yy0;} |
| 110005 | 110301 | break; |
| 110006 | | - case 94: /* tcons ::= PRIMARY KEY LP idxlist autoinc RP onconf */ |
| 110302 | + case 92: /* tcons ::= PRIMARY KEY LP idxlist autoinc RP onconf */ |
| 110007 | 110303 | {sqlite3AddPrimaryKey(pParse,yymsp[-3].minor.yy442,yymsp[0].minor.yy392,yymsp[-2].minor.yy392,0);} |
| 110008 | 110304 | break; |
| 110009 | | - case 95: /* tcons ::= UNIQUE LP idxlist RP onconf */ |
| 110305 | + case 93: /* tcons ::= UNIQUE LP idxlist RP onconf */ |
| 110010 | 110306 | {sqlite3CreateIndex(pParse,0,0,0,yymsp[-2].minor.yy442,yymsp[0].minor.yy392,0,0,0,0);} |
| 110011 | 110307 | break; |
| 110012 | | - case 96: /* tcons ::= CHECK LP expr RP onconf */ |
| 110308 | + case 94: /* tcons ::= CHECK LP expr RP onconf */ |
| 110013 | 110309 | {sqlite3AddCheckConstraint(pParse,yymsp[-2].minor.yy342.pExpr);} |
| 110014 | 110310 | break; |
| 110015 | | - case 97: /* tcons ::= FOREIGN KEY LP idxlist RP REFERENCES nm idxlist_opt refargs defer_subclause_opt */ |
| 110311 | + case 95: /* tcons ::= FOREIGN KEY LP idxlist RP REFERENCES nm idxlist_opt refargs defer_subclause_opt */ |
| 110016 | 110312 | { |
| 110017 | 110313 | sqlite3CreateForeignKey(pParse, yymsp[-6].minor.yy442, &yymsp[-3].minor.yy0, yymsp[-2].minor.yy442, yymsp[-1].minor.yy392); |
| 110018 | 110314 | sqlite3DeferForeignKey(pParse, yymsp[0].minor.yy392); |
| 110019 | 110315 | } |
| 110020 | 110316 | break; |
| 110021 | | - case 100: /* onconf ::= */ |
| 110317 | + case 98: /* onconf ::= */ |
| 110022 | 110318 | {yygotominor.yy392 = OE_Default;} |
| 110023 | 110319 | break; |
| 110024 | | - case 102: /* orconf ::= */ |
| 110320 | + case 100: /* orconf ::= */ |
| 110025 | 110321 | {yygotominor.yy258 = OE_Default;} |
| 110026 | 110322 | break; |
| 110027 | | - case 103: /* orconf ::= OR resolvetype */ |
| 110323 | + case 101: /* orconf ::= OR resolvetype */ |
| 110028 | 110324 | {yygotominor.yy258 = (u8)yymsp[0].minor.yy392;} |
| 110029 | 110325 | break; |
| 110030 | | - case 105: /* resolvetype ::= IGNORE */ |
| 110326 | + case 103: /* resolvetype ::= IGNORE */ |
| 110031 | 110327 | {yygotominor.yy392 = OE_Ignore;} |
| 110032 | 110328 | break; |
| 110033 | | - case 106: /* resolvetype ::= REPLACE */ |
| 110329 | + case 104: /* resolvetype ::= REPLACE */ |
| 110034 | 110330 | {yygotominor.yy392 = OE_Replace;} |
| 110035 | 110331 | break; |
| 110036 | | - case 107: /* cmd ::= DROP TABLE ifexists fullname */ |
| 110332 | + case 105: /* cmd ::= DROP TABLE ifexists fullname */ |
| 110037 | 110333 | { |
| 110038 | 110334 | sqlite3DropTable(pParse, yymsp[0].minor.yy347, 0, yymsp[-1].minor.yy392); |
| 110039 | 110335 | } |
| 110040 | 110336 | break; |
| 110041 | | - case 110: /* cmd ::= createkw temp VIEW ifnotexists nm dbnm AS select */ |
| 110337 | + case 108: /* cmd ::= createkw temp VIEW ifnotexists nm dbnm AS select */ |
| 110042 | 110338 | { |
| 110043 | 110339 | sqlite3CreateView(pParse, &yymsp[-7].minor.yy0, &yymsp[-3].minor.yy0, &yymsp[-2].minor.yy0, yymsp[0].minor.yy159, yymsp[-6].minor.yy392, yymsp[-4].minor.yy392); |
| 110044 | 110340 | } |
| 110045 | 110341 | break; |
| 110046 | | - case 111: /* cmd ::= DROP VIEW ifexists fullname */ |
| 110342 | + case 109: /* cmd ::= DROP VIEW ifexists fullname */ |
| 110047 | 110343 | { |
| 110048 | 110344 | sqlite3DropTable(pParse, yymsp[0].minor.yy347, 1, yymsp[-1].minor.yy392); |
| 110049 | 110345 | } |
| 110050 | 110346 | break; |
| 110051 | | - case 112: /* cmd ::= select */ |
| 110347 | + case 110: /* cmd ::= select */ |
| 110052 | 110348 | { |
| 110053 | 110349 | SelectDest dest = {SRT_Output, 0, 0, 0, 0}; |
| 110054 | 110350 | sqlite3Select(pParse, yymsp[0].minor.yy159, &dest); |
| 110055 | 110351 | sqlite3ExplainBegin(pParse->pVdbe); |
| 110056 | 110352 | sqlite3ExplainSelect(pParse->pVdbe, yymsp[0].minor.yy159); |
| 110057 | 110353 | sqlite3ExplainFinish(pParse->pVdbe); |
| 110058 | 110354 | sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy159); |
| 110059 | 110355 | } |
| 110060 | 110356 | break; |
| 110061 | | - case 113: /* select ::= oneselect */ |
| 110357 | + case 111: /* select ::= oneselect */ |
| 110062 | 110358 | {yygotominor.yy159 = yymsp[0].minor.yy159;} |
| 110063 | 110359 | break; |
| 110064 | | - case 114: /* select ::= select multiselect_op oneselect */ |
| 110360 | + case 112: /* select ::= select multiselect_op oneselect */ |
| 110065 | 110361 | { |
| 110066 | 110362 | if( yymsp[0].minor.yy159 ){ |
| 110067 | 110363 | yymsp[0].minor.yy159->op = (u8)yymsp[-1].minor.yy392; |
| 110068 | 110364 | yymsp[0].minor.yy159->pPrior = yymsp[-2].minor.yy159; |
| 110069 | 110365 | }else{ |
| | @@ -110070,83 +110366,83 @@ |
| 110070 | 110366 | sqlite3SelectDelete(pParse->db, yymsp[-2].minor.yy159); |
| 110071 | 110367 | } |
| 110072 | 110368 | yygotominor.yy159 = yymsp[0].minor.yy159; |
| 110073 | 110369 | } |
| 110074 | 110370 | break; |
| 110075 | | - case 116: /* multiselect_op ::= UNION ALL */ |
| 110371 | + case 114: /* multiselect_op ::= UNION ALL */ |
| 110076 | 110372 | {yygotominor.yy392 = TK_ALL;} |
| 110077 | 110373 | break; |
| 110078 | | - case 118: /* oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt */ |
| 110374 | + case 116: /* oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt */ |
| 110079 | 110375 | { |
| 110080 | 110376 | yygotominor.yy159 = sqlite3SelectNew(pParse,yymsp[-6].minor.yy442,yymsp[-5].minor.yy347,yymsp[-4].minor.yy122,yymsp[-3].minor.yy442,yymsp[-2].minor.yy122,yymsp[-1].minor.yy442,yymsp[-7].minor.yy392,yymsp[0].minor.yy64.pLimit,yymsp[0].minor.yy64.pOffset); |
| 110081 | 110377 | } |
| 110082 | 110378 | break; |
| 110083 | | - case 122: /* sclp ::= selcollist COMMA */ |
| 110084 | | - case 246: /* idxlist_opt ::= LP idxlist RP */ yytestcase(yyruleno==246); |
| 110379 | + case 120: /* sclp ::= selcollist COMMA */ |
| 110380 | + case 244: /* idxlist_opt ::= LP idxlist RP */ yytestcase(yyruleno==244); |
| 110085 | 110381 | {yygotominor.yy442 = yymsp[-1].minor.yy442;} |
| 110086 | 110382 | break; |
| 110087 | | - case 123: /* sclp ::= */ |
| 110088 | | - case 151: /* orderby_opt ::= */ yytestcase(yyruleno==151); |
| 110089 | | - case 158: /* groupby_opt ::= */ yytestcase(yyruleno==158); |
| 110090 | | - case 239: /* exprlist ::= */ yytestcase(yyruleno==239); |
| 110091 | | - case 245: /* idxlist_opt ::= */ yytestcase(yyruleno==245); |
| 110383 | + case 121: /* sclp ::= */ |
| 110384 | + case 149: /* orderby_opt ::= */ yytestcase(yyruleno==149); |
| 110385 | + case 156: /* groupby_opt ::= */ yytestcase(yyruleno==156); |
| 110386 | + case 237: /* exprlist ::= */ yytestcase(yyruleno==237); |
| 110387 | + case 243: /* idxlist_opt ::= */ yytestcase(yyruleno==243); |
| 110092 | 110388 | {yygotominor.yy442 = 0;} |
| 110093 | 110389 | break; |
| 110094 | | - case 124: /* selcollist ::= sclp expr as */ |
| 110390 | + case 122: /* selcollist ::= sclp expr as */ |
| 110095 | 110391 | { |
| 110096 | 110392 | yygotominor.yy442 = sqlite3ExprListAppend(pParse, yymsp[-2].minor.yy442, yymsp[-1].minor.yy342.pExpr); |
| 110097 | 110393 | if( yymsp[0].minor.yy0.n>0 ) sqlite3ExprListSetName(pParse, yygotominor.yy442, &yymsp[0].minor.yy0, 1); |
| 110098 | 110394 | sqlite3ExprListSetSpan(pParse,yygotominor.yy442,&yymsp[-1].minor.yy342); |
| 110099 | 110395 | } |
| 110100 | 110396 | break; |
| 110101 | | - case 125: /* selcollist ::= sclp STAR */ |
| 110397 | + case 123: /* selcollist ::= sclp STAR */ |
| 110102 | 110398 | { |
| 110103 | 110399 | Expr *p = sqlite3Expr(pParse->db, TK_ALL, 0); |
| 110104 | 110400 | yygotominor.yy442 = sqlite3ExprListAppend(pParse, yymsp[-1].minor.yy442, p); |
| 110105 | 110401 | } |
| 110106 | 110402 | break; |
| 110107 | | - case 126: /* selcollist ::= sclp nm DOT STAR */ |
| 110403 | + case 124: /* selcollist ::= sclp nm DOT STAR */ |
| 110108 | 110404 | { |
| 110109 | 110405 | Expr *pRight = sqlite3PExpr(pParse, TK_ALL, 0, 0, &yymsp[0].minor.yy0); |
| 110110 | 110406 | Expr *pLeft = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[-2].minor.yy0); |
| 110111 | 110407 | Expr *pDot = sqlite3PExpr(pParse, TK_DOT, pLeft, pRight, 0); |
| 110112 | 110408 | yygotominor.yy442 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy442, pDot); |
| 110113 | 110409 | } |
| 110114 | 110410 | break; |
| 110115 | | - case 129: /* as ::= */ |
| 110411 | + case 127: /* as ::= */ |
| 110116 | 110412 | {yygotominor.yy0.n = 0;} |
| 110117 | 110413 | break; |
| 110118 | | - case 130: /* from ::= */ |
| 110414 | + case 128: /* from ::= */ |
| 110119 | 110415 | {yygotominor.yy347 = sqlite3DbMallocZero(pParse->db, sizeof(*yygotominor.yy347));} |
| 110120 | 110416 | break; |
| 110121 | | - case 131: /* from ::= FROM seltablist */ |
| 110417 | + case 129: /* from ::= FROM seltablist */ |
| 110122 | 110418 | { |
| 110123 | 110419 | yygotominor.yy347 = yymsp[0].minor.yy347; |
| 110124 | 110420 | sqlite3SrcListShiftJoinType(yygotominor.yy347); |
| 110125 | 110421 | } |
| 110126 | 110422 | break; |
| 110127 | | - case 132: /* stl_prefix ::= seltablist joinop */ |
| 110423 | + case 130: /* stl_prefix ::= seltablist joinop */ |
| 110128 | 110424 | { |
| 110129 | 110425 | yygotominor.yy347 = yymsp[-1].minor.yy347; |
| 110130 | 110426 | if( ALWAYS(yygotominor.yy347 && yygotominor.yy347->nSrc>0) ) yygotominor.yy347->a[yygotominor.yy347->nSrc-1].jointype = (u8)yymsp[0].minor.yy392; |
| 110131 | 110427 | } |
| 110132 | 110428 | break; |
| 110133 | | - case 133: /* stl_prefix ::= */ |
| 110429 | + case 131: /* stl_prefix ::= */ |
| 110134 | 110430 | {yygotominor.yy347 = 0;} |
| 110135 | 110431 | break; |
| 110136 | | - case 134: /* seltablist ::= stl_prefix nm dbnm as indexed_opt on_opt using_opt */ |
| 110432 | + case 132: /* seltablist ::= stl_prefix nm dbnm as indexed_opt on_opt using_opt */ |
| 110137 | 110433 | { |
| 110138 | 110434 | yygotominor.yy347 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy347,&yymsp[-5].minor.yy0,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,0,yymsp[-1].minor.yy122,yymsp[0].minor.yy180); |
| 110139 | 110435 | sqlite3SrcListIndexedBy(pParse, yygotominor.yy347, &yymsp[-2].minor.yy0); |
| 110140 | 110436 | } |
| 110141 | 110437 | break; |
| 110142 | | - case 135: /* seltablist ::= stl_prefix LP select RP as on_opt using_opt */ |
| 110438 | + case 133: /* seltablist ::= stl_prefix LP select RP as on_opt using_opt */ |
| 110143 | 110439 | { |
| 110144 | 110440 | yygotominor.yy347 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy347,0,0,&yymsp[-2].minor.yy0,yymsp[-4].minor.yy159,yymsp[-1].minor.yy122,yymsp[0].minor.yy180); |
| 110145 | 110441 | } |
| 110146 | 110442 | break; |
| 110147 | | - case 136: /* seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt */ |
| 110443 | + case 134: /* seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt */ |
| 110148 | 110444 | { |
| 110149 | 110445 | if( yymsp[-6].minor.yy347==0 && yymsp[-2].minor.yy0.n==0 && yymsp[-1].minor.yy122==0 && yymsp[0].minor.yy180==0 ){ |
| 110150 | 110446 | yygotominor.yy347 = yymsp[-4].minor.yy347; |
| 110151 | 110447 | }else{ |
| 110152 | 110448 | Select *pSubquery; |
| | @@ -110154,137 +110450,137 @@ |
| 110154 | 110450 | pSubquery = sqlite3SelectNew(pParse,0,yymsp[-4].minor.yy347,0,0,0,0,0,0,0); |
| 110155 | 110451 | yygotominor.yy347 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy347,0,0,&yymsp[-2].minor.yy0,pSubquery,yymsp[-1].minor.yy122,yymsp[0].minor.yy180); |
| 110156 | 110452 | } |
| 110157 | 110453 | } |
| 110158 | 110454 | break; |
| 110159 | | - case 137: /* dbnm ::= */ |
| 110160 | | - case 146: /* indexed_opt ::= */ yytestcase(yyruleno==146); |
| 110455 | + case 135: /* dbnm ::= */ |
| 110456 | + case 144: /* indexed_opt ::= */ yytestcase(yyruleno==144); |
| 110161 | 110457 | {yygotominor.yy0.z=0; yygotominor.yy0.n=0;} |
| 110162 | 110458 | break; |
| 110163 | | - case 139: /* fullname ::= nm dbnm */ |
| 110459 | + case 137: /* fullname ::= nm dbnm */ |
| 110164 | 110460 | {yygotominor.yy347 = sqlite3SrcListAppend(pParse->db,0,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0);} |
| 110165 | 110461 | break; |
| 110166 | | - case 140: /* joinop ::= COMMA|JOIN */ |
| 110462 | + case 138: /* joinop ::= COMMA|JOIN */ |
| 110167 | 110463 | { yygotominor.yy392 = JT_INNER; } |
| 110168 | 110464 | break; |
| 110169 | | - case 141: /* joinop ::= JOIN_KW JOIN */ |
| 110465 | + case 139: /* joinop ::= JOIN_KW JOIN */ |
| 110170 | 110466 | { yygotominor.yy392 = sqlite3JoinType(pParse,&yymsp[-1].minor.yy0,0,0); } |
| 110171 | 110467 | break; |
| 110172 | | - case 142: /* joinop ::= JOIN_KW nm JOIN */ |
| 110468 | + case 140: /* joinop ::= JOIN_KW nm JOIN */ |
| 110173 | 110469 | { yygotominor.yy392 = sqlite3JoinType(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,0); } |
| 110174 | 110470 | break; |
| 110175 | | - case 143: /* joinop ::= JOIN_KW nm nm JOIN */ |
| 110471 | + case 141: /* joinop ::= JOIN_KW nm nm JOIN */ |
| 110176 | 110472 | { yygotominor.yy392 = sqlite3JoinType(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0); } |
| 110177 | 110473 | break; |
| 110178 | | - case 144: /* on_opt ::= ON expr */ |
| 110179 | | - case 161: /* having_opt ::= HAVING expr */ yytestcase(yyruleno==161); |
| 110180 | | - case 168: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==168); |
| 110181 | | - case 234: /* case_else ::= ELSE expr */ yytestcase(yyruleno==234); |
| 110182 | | - case 236: /* case_operand ::= expr */ yytestcase(yyruleno==236); |
| 110474 | + case 142: /* on_opt ::= ON expr */ |
| 110475 | + case 159: /* having_opt ::= HAVING expr */ yytestcase(yyruleno==159); |
| 110476 | + case 166: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==166); |
| 110477 | + case 232: /* case_else ::= ELSE expr */ yytestcase(yyruleno==232); |
| 110478 | + case 234: /* case_operand ::= expr */ yytestcase(yyruleno==234); |
| 110183 | 110479 | {yygotominor.yy122 = yymsp[0].minor.yy342.pExpr;} |
| 110184 | 110480 | break; |
| 110185 | | - case 145: /* on_opt ::= */ |
| 110186 | | - case 160: /* having_opt ::= */ yytestcase(yyruleno==160); |
| 110187 | | - case 167: /* where_opt ::= */ yytestcase(yyruleno==167); |
| 110188 | | - case 235: /* case_else ::= */ yytestcase(yyruleno==235); |
| 110189 | | - case 237: /* case_operand ::= */ yytestcase(yyruleno==237); |
| 110481 | + case 143: /* on_opt ::= */ |
| 110482 | + case 158: /* having_opt ::= */ yytestcase(yyruleno==158); |
| 110483 | + case 165: /* where_opt ::= */ yytestcase(yyruleno==165); |
| 110484 | + case 233: /* case_else ::= */ yytestcase(yyruleno==233); |
| 110485 | + case 235: /* case_operand ::= */ yytestcase(yyruleno==235); |
| 110190 | 110486 | {yygotominor.yy122 = 0;} |
| 110191 | 110487 | break; |
| 110192 | | - case 148: /* indexed_opt ::= NOT INDEXED */ |
| 110488 | + case 146: /* indexed_opt ::= NOT INDEXED */ |
| 110193 | 110489 | {yygotominor.yy0.z=0; yygotominor.yy0.n=1;} |
| 110194 | 110490 | break; |
| 110195 | | - case 149: /* using_opt ::= USING LP inscollist RP */ |
| 110196 | | - case 180: /* inscollist_opt ::= LP inscollist RP */ yytestcase(yyruleno==180); |
| 110491 | + case 147: /* using_opt ::= USING LP inscollist RP */ |
| 110492 | + case 178: /* inscollist_opt ::= LP inscollist RP */ yytestcase(yyruleno==178); |
| 110197 | 110493 | {yygotominor.yy180 = yymsp[-1].minor.yy180;} |
| 110198 | 110494 | break; |
| 110199 | | - case 150: /* using_opt ::= */ |
| 110200 | | - case 179: /* inscollist_opt ::= */ yytestcase(yyruleno==179); |
| 110495 | + case 148: /* using_opt ::= */ |
| 110496 | + case 177: /* inscollist_opt ::= */ yytestcase(yyruleno==177); |
| 110201 | 110497 | {yygotominor.yy180 = 0;} |
| 110202 | 110498 | break; |
| 110203 | | - case 152: /* orderby_opt ::= ORDER BY sortlist */ |
| 110204 | | - case 159: /* groupby_opt ::= GROUP BY nexprlist */ yytestcase(yyruleno==159); |
| 110205 | | - case 238: /* exprlist ::= nexprlist */ yytestcase(yyruleno==238); |
| 110499 | + case 150: /* orderby_opt ::= ORDER BY sortlist */ |
| 110500 | + case 157: /* groupby_opt ::= GROUP BY nexprlist */ yytestcase(yyruleno==157); |
| 110501 | + case 236: /* exprlist ::= nexprlist */ yytestcase(yyruleno==236); |
| 110206 | 110502 | {yygotominor.yy442 = yymsp[0].minor.yy442;} |
| 110207 | 110503 | break; |
| 110208 | | - case 153: /* sortlist ::= sortlist COMMA expr sortorder */ |
| 110504 | + case 151: /* sortlist ::= sortlist COMMA expr sortorder */ |
| 110209 | 110505 | { |
| 110210 | 110506 | yygotominor.yy442 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy442,yymsp[-1].minor.yy342.pExpr); |
| 110211 | 110507 | if( yygotominor.yy442 ) yygotominor.yy442->a[yygotominor.yy442->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy392; |
| 110212 | 110508 | } |
| 110213 | 110509 | break; |
| 110214 | | - case 154: /* sortlist ::= expr sortorder */ |
| 110510 | + case 152: /* sortlist ::= expr sortorder */ |
| 110215 | 110511 | { |
| 110216 | 110512 | yygotominor.yy442 = sqlite3ExprListAppend(pParse,0,yymsp[-1].minor.yy342.pExpr); |
| 110217 | 110513 | if( yygotominor.yy442 && ALWAYS(yygotominor.yy442->a) ) yygotominor.yy442->a[0].sortOrder = (u8)yymsp[0].minor.yy392; |
| 110218 | 110514 | } |
| 110219 | 110515 | break; |
| 110220 | | - case 155: /* sortorder ::= ASC */ |
| 110221 | | - case 157: /* sortorder ::= */ yytestcase(yyruleno==157); |
| 110516 | + case 153: /* sortorder ::= ASC */ |
| 110517 | + case 155: /* sortorder ::= */ yytestcase(yyruleno==155); |
| 110222 | 110518 | {yygotominor.yy392 = SQLITE_SO_ASC;} |
| 110223 | 110519 | break; |
| 110224 | | - case 156: /* sortorder ::= DESC */ |
| 110520 | + case 154: /* sortorder ::= DESC */ |
| 110225 | 110521 | {yygotominor.yy392 = SQLITE_SO_DESC;} |
| 110226 | 110522 | break; |
| 110227 | | - case 162: /* limit_opt ::= */ |
| 110523 | + case 160: /* limit_opt ::= */ |
| 110228 | 110524 | {yygotominor.yy64.pLimit = 0; yygotominor.yy64.pOffset = 0;} |
| 110229 | 110525 | break; |
| 110230 | | - case 163: /* limit_opt ::= LIMIT expr */ |
| 110526 | + case 161: /* limit_opt ::= LIMIT expr */ |
| 110231 | 110527 | {yygotominor.yy64.pLimit = yymsp[0].minor.yy342.pExpr; yygotominor.yy64.pOffset = 0;} |
| 110232 | 110528 | break; |
| 110233 | | - case 164: /* limit_opt ::= LIMIT expr OFFSET expr */ |
| 110529 | + case 162: /* limit_opt ::= LIMIT expr OFFSET expr */ |
| 110234 | 110530 | {yygotominor.yy64.pLimit = yymsp[-2].minor.yy342.pExpr; yygotominor.yy64.pOffset = yymsp[0].minor.yy342.pExpr;} |
| 110235 | 110531 | break; |
| 110236 | | - case 165: /* limit_opt ::= LIMIT expr COMMA expr */ |
| 110532 | + case 163: /* limit_opt ::= LIMIT expr COMMA expr */ |
| 110237 | 110533 | {yygotominor.yy64.pOffset = yymsp[-2].minor.yy342.pExpr; yygotominor.yy64.pLimit = yymsp[0].minor.yy342.pExpr;} |
| 110238 | 110534 | break; |
| 110239 | | - case 166: /* cmd ::= DELETE FROM fullname indexed_opt where_opt */ |
| 110535 | + case 164: /* cmd ::= DELETE FROM fullname indexed_opt where_opt */ |
| 110240 | 110536 | { |
| 110241 | 110537 | sqlite3SrcListIndexedBy(pParse, yymsp[-2].minor.yy347, &yymsp[-1].minor.yy0); |
| 110242 | 110538 | sqlite3DeleteFrom(pParse,yymsp[-2].minor.yy347,yymsp[0].minor.yy122); |
| 110243 | 110539 | } |
| 110244 | 110540 | break; |
| 110245 | | - case 169: /* cmd ::= UPDATE orconf fullname indexed_opt SET setlist where_opt */ |
| 110541 | + case 167: /* cmd ::= UPDATE orconf fullname indexed_opt SET setlist where_opt */ |
| 110246 | 110542 | { |
| 110247 | 110543 | sqlite3SrcListIndexedBy(pParse, yymsp[-4].minor.yy347, &yymsp[-3].minor.yy0); |
| 110248 | 110544 | sqlite3ExprListCheckLength(pParse,yymsp[-1].minor.yy442,"set list"); |
| 110249 | 110545 | sqlite3Update(pParse,yymsp[-4].minor.yy347,yymsp[-1].minor.yy442,yymsp[0].minor.yy122,yymsp[-5].minor.yy258); |
| 110250 | 110546 | } |
| 110251 | 110547 | break; |
| 110252 | | - case 170: /* setlist ::= setlist COMMA nm EQ expr */ |
| 110548 | + case 168: /* setlist ::= setlist COMMA nm EQ expr */ |
| 110253 | 110549 | { |
| 110254 | 110550 | yygotominor.yy442 = sqlite3ExprListAppend(pParse, yymsp[-4].minor.yy442, yymsp[0].minor.yy342.pExpr); |
| 110255 | 110551 | sqlite3ExprListSetName(pParse, yygotominor.yy442, &yymsp[-2].minor.yy0, 1); |
| 110256 | 110552 | } |
| 110257 | 110553 | break; |
| 110258 | | - case 171: /* setlist ::= nm EQ expr */ |
| 110554 | + case 169: /* setlist ::= nm EQ expr */ |
| 110259 | 110555 | { |
| 110260 | 110556 | yygotominor.yy442 = sqlite3ExprListAppend(pParse, 0, yymsp[0].minor.yy342.pExpr); |
| 110261 | 110557 | sqlite3ExprListSetName(pParse, yygotominor.yy442, &yymsp[-2].minor.yy0, 1); |
| 110262 | 110558 | } |
| 110263 | 110559 | break; |
| 110264 | | - case 172: /* cmd ::= insert_cmd INTO fullname inscollist_opt valuelist */ |
| 110560 | + case 170: /* cmd ::= insert_cmd INTO fullname inscollist_opt valuelist */ |
| 110265 | 110561 | {sqlite3Insert(pParse, yymsp[-2].minor.yy347, yymsp[0].minor.yy487.pList, yymsp[0].minor.yy487.pSelect, yymsp[-1].minor.yy180, yymsp[-4].minor.yy258);} |
| 110266 | 110562 | break; |
| 110267 | | - case 173: /* cmd ::= insert_cmd INTO fullname inscollist_opt select */ |
| 110563 | + case 171: /* cmd ::= insert_cmd INTO fullname inscollist_opt select */ |
| 110268 | 110564 | {sqlite3Insert(pParse, yymsp[-2].minor.yy347, 0, yymsp[0].minor.yy159, yymsp[-1].minor.yy180, yymsp[-4].minor.yy258);} |
| 110269 | 110565 | break; |
| 110270 | | - case 174: /* cmd ::= insert_cmd INTO fullname inscollist_opt DEFAULT VALUES */ |
| 110566 | + case 172: /* cmd ::= insert_cmd INTO fullname inscollist_opt DEFAULT VALUES */ |
| 110271 | 110567 | {sqlite3Insert(pParse, yymsp[-3].minor.yy347, 0, 0, yymsp[-2].minor.yy180, yymsp[-5].minor.yy258);} |
| 110272 | 110568 | break; |
| 110273 | | - case 175: /* insert_cmd ::= INSERT orconf */ |
| 110569 | + case 173: /* insert_cmd ::= INSERT orconf */ |
| 110274 | 110570 | {yygotominor.yy258 = yymsp[0].minor.yy258;} |
| 110275 | 110571 | break; |
| 110276 | | - case 176: /* insert_cmd ::= REPLACE */ |
| 110572 | + case 174: /* insert_cmd ::= REPLACE */ |
| 110277 | 110573 | {yygotominor.yy258 = OE_Replace;} |
| 110278 | 110574 | break; |
| 110279 | | - case 177: /* valuelist ::= VALUES LP nexprlist RP */ |
| 110575 | + case 175: /* valuelist ::= VALUES LP nexprlist RP */ |
| 110280 | 110576 | { |
| 110281 | 110577 | yygotominor.yy487.pList = yymsp[-1].minor.yy442; |
| 110282 | 110578 | yygotominor.yy487.pSelect = 0; |
| 110283 | 110579 | } |
| 110284 | 110580 | break; |
| 110285 | | - case 178: /* valuelist ::= valuelist COMMA LP exprlist RP */ |
| 110581 | + case 176: /* valuelist ::= valuelist COMMA LP exprlist RP */ |
| 110286 | 110582 | { |
| 110287 | 110583 | Select *pRight = sqlite3SelectNew(pParse, yymsp[-1].minor.yy442, 0, 0, 0, 0, 0, 0, 0, 0); |
| 110288 | 110584 | if( yymsp[-4].minor.yy487.pList ){ |
| 110289 | 110585 | yymsp[-4].minor.yy487.pSelect = sqlite3SelectNew(pParse, yymsp[-4].minor.yy487.pList, 0, 0, 0, 0, 0, 0, 0, 0); |
| 110290 | 110586 | yymsp[-4].minor.yy487.pList = 0; |
| | @@ -110301,50 +110597,50 @@ |
| 110301 | 110597 | pRight->pPrior->selFlags |= SF_Values; |
| 110302 | 110598 | yygotominor.yy487.pSelect = pRight; |
| 110303 | 110599 | } |
| 110304 | 110600 | } |
| 110305 | 110601 | break; |
| 110306 | | - case 181: /* inscollist ::= inscollist COMMA nm */ |
| 110602 | + case 179: /* inscollist ::= inscollist COMMA nm */ |
| 110307 | 110603 | {yygotominor.yy180 = sqlite3IdListAppend(pParse->db,yymsp[-2].minor.yy180,&yymsp[0].minor.yy0);} |
| 110308 | 110604 | break; |
| 110309 | | - case 182: /* inscollist ::= nm */ |
| 110605 | + case 180: /* inscollist ::= nm */ |
| 110310 | 110606 | {yygotominor.yy180 = sqlite3IdListAppend(pParse->db,0,&yymsp[0].minor.yy0);} |
| 110311 | 110607 | break; |
| 110312 | | - case 183: /* expr ::= term */ |
| 110608 | + case 181: /* expr ::= term */ |
| 110313 | 110609 | {yygotominor.yy342 = yymsp[0].minor.yy342;} |
| 110314 | 110610 | break; |
| 110315 | | - case 184: /* expr ::= LP expr RP */ |
| 110611 | + case 182: /* expr ::= LP expr RP */ |
| 110316 | 110612 | {yygotominor.yy342.pExpr = yymsp[-1].minor.yy342.pExpr; spanSet(&yygotominor.yy342,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0);} |
| 110317 | 110613 | break; |
| 110318 | | - case 185: /* term ::= NULL */ |
| 110319 | | - case 190: /* term ::= INTEGER|FLOAT|BLOB */ yytestcase(yyruleno==190); |
| 110320 | | - case 191: /* term ::= STRING */ yytestcase(yyruleno==191); |
| 110614 | + case 183: /* term ::= NULL */ |
| 110615 | + case 188: /* term ::= INTEGER|FLOAT|BLOB */ yytestcase(yyruleno==188); |
| 110616 | + case 189: /* term ::= STRING */ yytestcase(yyruleno==189); |
| 110321 | 110617 | {spanExpr(&yygotominor.yy342, pParse, yymsp[0].major, &yymsp[0].minor.yy0);} |
| 110322 | 110618 | break; |
| 110323 | | - case 186: /* expr ::= id */ |
| 110324 | | - case 187: /* expr ::= JOIN_KW */ yytestcase(yyruleno==187); |
| 110619 | + case 184: /* expr ::= id */ |
| 110620 | + case 185: /* expr ::= JOIN_KW */ yytestcase(yyruleno==185); |
| 110325 | 110621 | {spanExpr(&yygotominor.yy342, pParse, TK_ID, &yymsp[0].minor.yy0);} |
| 110326 | 110622 | break; |
| 110327 | | - case 188: /* expr ::= nm DOT nm */ |
| 110623 | + case 186: /* expr ::= nm DOT nm */ |
| 110328 | 110624 | { |
| 110329 | 110625 | Expr *temp1 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[-2].minor.yy0); |
| 110330 | 110626 | Expr *temp2 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[0].minor.yy0); |
| 110331 | 110627 | yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_DOT, temp1, temp2, 0); |
| 110332 | 110628 | spanSet(&yygotominor.yy342,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); |
| 110333 | 110629 | } |
| 110334 | 110630 | break; |
| 110335 | | - case 189: /* expr ::= nm DOT nm DOT nm */ |
| 110631 | + case 187: /* expr ::= nm DOT nm DOT nm */ |
| 110336 | 110632 | { |
| 110337 | 110633 | Expr *temp1 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[-4].minor.yy0); |
| 110338 | 110634 | Expr *temp2 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[-2].minor.yy0); |
| 110339 | 110635 | Expr *temp3 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[0].minor.yy0); |
| 110340 | 110636 | Expr *temp4 = sqlite3PExpr(pParse, TK_DOT, temp2, temp3, 0); |
| 110341 | 110637 | yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_DOT, temp1, temp4, 0); |
| 110342 | 110638 | spanSet(&yygotominor.yy342,&yymsp[-4].minor.yy0,&yymsp[0].minor.yy0); |
| 110343 | 110639 | } |
| 110344 | 110640 | break; |
| 110345 | | - case 192: /* expr ::= REGISTER */ |
| 110641 | + case 190: /* expr ::= REGISTER */ |
| 110346 | 110642 | { |
| 110347 | 110643 | /* When doing a nested parse, one can include terms in an expression |
| 110348 | 110644 | ** that look like this: #1 #2 ... These terms refer to registers |
| 110349 | 110645 | ** in the virtual machine. #N is the N-th register. */ |
| 110350 | 110646 | if( pParse->nested==0 ){ |
| | @@ -110355,31 +110651,31 @@ |
| 110355 | 110651 | if( yygotominor.yy342.pExpr ) sqlite3GetInt32(&yymsp[0].minor.yy0.z[1], &yygotominor.yy342.pExpr->iTable); |
| 110356 | 110652 | } |
| 110357 | 110653 | spanSet(&yygotominor.yy342, &yymsp[0].minor.yy0, &yymsp[0].minor.yy0); |
| 110358 | 110654 | } |
| 110359 | 110655 | break; |
| 110360 | | - case 193: /* expr ::= VARIABLE */ |
| 110656 | + case 191: /* expr ::= VARIABLE */ |
| 110361 | 110657 | { |
| 110362 | 110658 | spanExpr(&yygotominor.yy342, pParse, TK_VARIABLE, &yymsp[0].minor.yy0); |
| 110363 | 110659 | sqlite3ExprAssignVarNumber(pParse, yygotominor.yy342.pExpr); |
| 110364 | 110660 | spanSet(&yygotominor.yy342, &yymsp[0].minor.yy0, &yymsp[0].minor.yy0); |
| 110365 | 110661 | } |
| 110366 | 110662 | break; |
| 110367 | | - case 194: /* expr ::= expr COLLATE ids */ |
| 110663 | + case 192: /* expr ::= expr COLLATE ids */ |
| 110368 | 110664 | { |
| 110369 | 110665 | yygotominor.yy342.pExpr = sqlite3ExprSetCollByToken(pParse, yymsp[-2].minor.yy342.pExpr, &yymsp[0].minor.yy0); |
| 110370 | 110666 | yygotominor.yy342.zStart = yymsp[-2].minor.yy342.zStart; |
| 110371 | 110667 | yygotominor.yy342.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n]; |
| 110372 | 110668 | } |
| 110373 | 110669 | break; |
| 110374 | | - case 195: /* expr ::= CAST LP expr AS typetoken RP */ |
| 110670 | + case 193: /* expr ::= CAST LP expr AS typetoken RP */ |
| 110375 | 110671 | { |
| 110376 | 110672 | yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_CAST, yymsp[-3].minor.yy342.pExpr, 0, &yymsp[-1].minor.yy0); |
| 110377 | 110673 | spanSet(&yygotominor.yy342,&yymsp[-5].minor.yy0,&yymsp[0].minor.yy0); |
| 110378 | 110674 | } |
| 110379 | 110675 | break; |
| 110380 | | - case 196: /* expr ::= ID LP distinct exprlist RP */ |
| 110676 | + case 194: /* expr ::= ID LP distinct exprlist RP */ |
| 110381 | 110677 | { |
| 110382 | 110678 | if( yymsp[-1].minor.yy442 && yymsp[-1].minor.yy442->nExpr>pParse->db->aLimit[SQLITE_LIMIT_FUNCTION_ARG] ){ |
| 110383 | 110679 | sqlite3ErrorMsg(pParse, "too many arguments on function %T", &yymsp[-4].minor.yy0); |
| 110384 | 110680 | } |
| 110385 | 110681 | yygotominor.yy342.pExpr = sqlite3ExprFunction(pParse, yymsp[-1].minor.yy442, &yymsp[-4].minor.yy0); |
| | @@ -110387,17 +110683,17 @@ |
| 110387 | 110683 | if( yymsp[-2].minor.yy392 && yygotominor.yy342.pExpr ){ |
| 110388 | 110684 | yygotominor.yy342.pExpr->flags |= EP_Distinct; |
| 110389 | 110685 | } |
| 110390 | 110686 | } |
| 110391 | 110687 | break; |
| 110392 | | - case 197: /* expr ::= ID LP STAR RP */ |
| 110688 | + case 195: /* expr ::= ID LP STAR RP */ |
| 110393 | 110689 | { |
| 110394 | 110690 | yygotominor.yy342.pExpr = sqlite3ExprFunction(pParse, 0, &yymsp[-3].minor.yy0); |
| 110395 | 110691 | spanSet(&yygotominor.yy342,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0); |
| 110396 | 110692 | } |
| 110397 | 110693 | break; |
| 110398 | | - case 198: /* term ::= CTIME_KW */ |
| 110694 | + case 196: /* term ::= CTIME_KW */ |
| 110399 | 110695 | { |
| 110400 | 110696 | /* The CURRENT_TIME, CURRENT_DATE, and CURRENT_TIMESTAMP values are |
| 110401 | 110697 | ** treated as functions that return constants */ |
| 110402 | 110698 | yygotominor.yy342.pExpr = sqlite3ExprFunction(pParse, 0,&yymsp[0].minor.yy0); |
| 110403 | 110699 | if( yygotominor.yy342.pExpr ){ |
| | @@ -110404,82 +110700,82 @@ |
| 110404 | 110700 | yygotominor.yy342.pExpr->op = TK_CONST_FUNC; |
| 110405 | 110701 | } |
| 110406 | 110702 | spanSet(&yygotominor.yy342, &yymsp[0].minor.yy0, &yymsp[0].minor.yy0); |
| 110407 | 110703 | } |
| 110408 | 110704 | break; |
| 110409 | | - case 199: /* expr ::= expr AND expr */ |
| 110410 | | - case 200: /* expr ::= expr OR expr */ yytestcase(yyruleno==200); |
| 110411 | | - case 201: /* expr ::= expr LT|GT|GE|LE expr */ yytestcase(yyruleno==201); |
| 110412 | | - case 202: /* expr ::= expr EQ|NE expr */ yytestcase(yyruleno==202); |
| 110413 | | - case 203: /* expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr */ yytestcase(yyruleno==203); |
| 110414 | | - case 204: /* expr ::= expr PLUS|MINUS expr */ yytestcase(yyruleno==204); |
| 110415 | | - case 205: /* expr ::= expr STAR|SLASH|REM expr */ yytestcase(yyruleno==205); |
| 110416 | | - case 206: /* expr ::= expr CONCAT expr */ yytestcase(yyruleno==206); |
| 110705 | + case 197: /* expr ::= expr AND expr */ |
| 110706 | + case 198: /* expr ::= expr OR expr */ yytestcase(yyruleno==198); |
| 110707 | + case 199: /* expr ::= expr LT|GT|GE|LE expr */ yytestcase(yyruleno==199); |
| 110708 | + case 200: /* expr ::= expr EQ|NE expr */ yytestcase(yyruleno==200); |
| 110709 | + case 201: /* expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr */ yytestcase(yyruleno==201); |
| 110710 | + case 202: /* expr ::= expr PLUS|MINUS expr */ yytestcase(yyruleno==202); |
| 110711 | + case 203: /* expr ::= expr STAR|SLASH|REM expr */ yytestcase(yyruleno==203); |
| 110712 | + case 204: /* expr ::= expr CONCAT expr */ yytestcase(yyruleno==204); |
| 110417 | 110713 | {spanBinaryExpr(&yygotominor.yy342,pParse,yymsp[-1].major,&yymsp[-2].minor.yy342,&yymsp[0].minor.yy342);} |
| 110418 | 110714 | break; |
| 110419 | | - case 207: /* likeop ::= LIKE_KW */ |
| 110420 | | - case 209: /* likeop ::= MATCH */ yytestcase(yyruleno==209); |
| 110421 | | -{yygotominor.yy318.eOperator = yymsp[0].minor.yy0; yygotominor.yy318.not = 0;} |
| 110422 | | - break; |
| 110423 | | - case 208: /* likeop ::= NOT LIKE_KW */ |
| 110424 | | - case 210: /* likeop ::= NOT MATCH */ yytestcase(yyruleno==210); |
| 110425 | | -{yygotominor.yy318.eOperator = yymsp[0].minor.yy0; yygotominor.yy318.not = 1;} |
| 110426 | | - break; |
| 110427 | | - case 211: /* expr ::= expr likeop expr */ |
| 110715 | + case 205: /* likeop ::= LIKE_KW */ |
| 110716 | + case 207: /* likeop ::= MATCH */ yytestcase(yyruleno==207); |
| 110717 | +{yygotominor.yy318.eOperator = yymsp[0].minor.yy0; yygotominor.yy318.bNot = 0;} |
| 110718 | + break; |
| 110719 | + case 206: /* likeop ::= NOT LIKE_KW */ |
| 110720 | + case 208: /* likeop ::= NOT MATCH */ yytestcase(yyruleno==208); |
| 110721 | +{yygotominor.yy318.eOperator = yymsp[0].minor.yy0; yygotominor.yy318.bNot = 1;} |
| 110722 | + break; |
| 110723 | + case 209: /* expr ::= expr likeop expr */ |
| 110428 | 110724 | { |
| 110429 | 110725 | ExprList *pList; |
| 110430 | 110726 | pList = sqlite3ExprListAppend(pParse,0, yymsp[0].minor.yy342.pExpr); |
| 110431 | 110727 | pList = sqlite3ExprListAppend(pParse,pList, yymsp[-2].minor.yy342.pExpr); |
| 110432 | 110728 | yygotominor.yy342.pExpr = sqlite3ExprFunction(pParse, pList, &yymsp[-1].minor.yy318.eOperator); |
| 110433 | | - if( yymsp[-1].minor.yy318.not ) yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy342.pExpr, 0, 0); |
| 110729 | + if( yymsp[-1].minor.yy318.bNot ) yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy342.pExpr, 0, 0); |
| 110434 | 110730 | yygotominor.yy342.zStart = yymsp[-2].minor.yy342.zStart; |
| 110435 | 110731 | yygotominor.yy342.zEnd = yymsp[0].minor.yy342.zEnd; |
| 110436 | 110732 | if( yygotominor.yy342.pExpr ) yygotominor.yy342.pExpr->flags |= EP_InfixFunc; |
| 110437 | 110733 | } |
| 110438 | 110734 | break; |
| 110439 | | - case 212: /* expr ::= expr likeop expr ESCAPE expr */ |
| 110735 | + case 210: /* expr ::= expr likeop expr ESCAPE expr */ |
| 110440 | 110736 | { |
| 110441 | 110737 | ExprList *pList; |
| 110442 | 110738 | pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy342.pExpr); |
| 110443 | 110739 | pList = sqlite3ExprListAppend(pParse,pList, yymsp[-4].minor.yy342.pExpr); |
| 110444 | 110740 | pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy342.pExpr); |
| 110445 | 110741 | yygotominor.yy342.pExpr = sqlite3ExprFunction(pParse, pList, &yymsp[-3].minor.yy318.eOperator); |
| 110446 | | - if( yymsp[-3].minor.yy318.not ) yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy342.pExpr, 0, 0); |
| 110742 | + if( yymsp[-3].minor.yy318.bNot ) yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy342.pExpr, 0, 0); |
| 110447 | 110743 | yygotominor.yy342.zStart = yymsp[-4].minor.yy342.zStart; |
| 110448 | 110744 | yygotominor.yy342.zEnd = yymsp[0].minor.yy342.zEnd; |
| 110449 | 110745 | if( yygotominor.yy342.pExpr ) yygotominor.yy342.pExpr->flags |= EP_InfixFunc; |
| 110450 | 110746 | } |
| 110451 | 110747 | break; |
| 110452 | | - case 213: /* expr ::= expr ISNULL|NOTNULL */ |
| 110748 | + case 211: /* expr ::= expr ISNULL|NOTNULL */ |
| 110453 | 110749 | {spanUnaryPostfix(&yygotominor.yy342,pParse,yymsp[0].major,&yymsp[-1].minor.yy342,&yymsp[0].minor.yy0);} |
| 110454 | 110750 | break; |
| 110455 | | - case 214: /* expr ::= expr NOT NULL */ |
| 110751 | + case 212: /* expr ::= expr NOT NULL */ |
| 110456 | 110752 | {spanUnaryPostfix(&yygotominor.yy342,pParse,TK_NOTNULL,&yymsp[-2].minor.yy342,&yymsp[0].minor.yy0);} |
| 110457 | 110753 | break; |
| 110458 | | - case 215: /* expr ::= expr IS expr */ |
| 110754 | + case 213: /* expr ::= expr IS expr */ |
| 110459 | 110755 | { |
| 110460 | 110756 | spanBinaryExpr(&yygotominor.yy342,pParse,TK_IS,&yymsp[-2].minor.yy342,&yymsp[0].minor.yy342); |
| 110461 | 110757 | binaryToUnaryIfNull(pParse, yymsp[0].minor.yy342.pExpr, yygotominor.yy342.pExpr, TK_ISNULL); |
| 110462 | 110758 | } |
| 110463 | 110759 | break; |
| 110464 | | - case 216: /* expr ::= expr IS NOT expr */ |
| 110760 | + case 214: /* expr ::= expr IS NOT expr */ |
| 110465 | 110761 | { |
| 110466 | 110762 | spanBinaryExpr(&yygotominor.yy342,pParse,TK_ISNOT,&yymsp[-3].minor.yy342,&yymsp[0].minor.yy342); |
| 110467 | 110763 | binaryToUnaryIfNull(pParse, yymsp[0].minor.yy342.pExpr, yygotominor.yy342.pExpr, TK_NOTNULL); |
| 110468 | 110764 | } |
| 110469 | 110765 | break; |
| 110470 | | - case 217: /* expr ::= NOT expr */ |
| 110471 | | - case 218: /* expr ::= BITNOT expr */ yytestcase(yyruleno==218); |
| 110766 | + case 215: /* expr ::= NOT expr */ |
| 110767 | + case 216: /* expr ::= BITNOT expr */ yytestcase(yyruleno==216); |
| 110472 | 110768 | {spanUnaryPrefix(&yygotominor.yy342,pParse,yymsp[-1].major,&yymsp[0].minor.yy342,&yymsp[-1].minor.yy0);} |
| 110473 | 110769 | break; |
| 110474 | | - case 219: /* expr ::= MINUS expr */ |
| 110770 | + case 217: /* expr ::= MINUS expr */ |
| 110475 | 110771 | {spanUnaryPrefix(&yygotominor.yy342,pParse,TK_UMINUS,&yymsp[0].minor.yy342,&yymsp[-1].minor.yy0);} |
| 110476 | 110772 | break; |
| 110477 | | - case 220: /* expr ::= PLUS expr */ |
| 110773 | + case 218: /* expr ::= PLUS expr */ |
| 110478 | 110774 | {spanUnaryPrefix(&yygotominor.yy342,pParse,TK_UPLUS,&yymsp[0].minor.yy342,&yymsp[-1].minor.yy0);} |
| 110479 | 110775 | break; |
| 110480 | | - case 223: /* expr ::= expr between_op expr AND expr */ |
| 110776 | + case 221: /* expr ::= expr between_op expr AND expr */ |
| 110481 | 110777 | { |
| 110482 | 110778 | ExprList *pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy342.pExpr); |
| 110483 | 110779 | pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy342.pExpr); |
| 110484 | 110780 | yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_BETWEEN, yymsp[-4].minor.yy342.pExpr, 0, 0); |
| 110485 | 110781 | if( yygotominor.yy342.pExpr ){ |
| | @@ -110490,11 +110786,11 @@ |
| 110490 | 110786 | if( yymsp[-3].minor.yy392 ) yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy342.pExpr, 0, 0); |
| 110491 | 110787 | yygotominor.yy342.zStart = yymsp[-4].minor.yy342.zStart; |
| 110492 | 110788 | yygotominor.yy342.zEnd = yymsp[0].minor.yy342.zEnd; |
| 110493 | 110789 | } |
| 110494 | 110790 | break; |
| 110495 | | - case 226: /* expr ::= expr in_op LP exprlist RP */ |
| 110791 | + case 224: /* expr ::= expr in_op LP exprlist RP */ |
| 110496 | 110792 | { |
| 110497 | 110793 | if( yymsp[-1].minor.yy442==0 ){ |
| 110498 | 110794 | /* Expressions of the form |
| 110499 | 110795 | ** |
| 110500 | 110796 | ** expr1 IN () |
| | @@ -110517,11 +110813,11 @@ |
| 110517 | 110813 | } |
| 110518 | 110814 | yygotominor.yy342.zStart = yymsp[-4].minor.yy342.zStart; |
| 110519 | 110815 | yygotominor.yy342.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n]; |
| 110520 | 110816 | } |
| 110521 | 110817 | break; |
| 110522 | | - case 227: /* expr ::= LP select RP */ |
| 110818 | + case 225: /* expr ::= LP select RP */ |
| 110523 | 110819 | { |
| 110524 | 110820 | yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_SELECT, 0, 0, 0); |
| 110525 | 110821 | if( yygotominor.yy342.pExpr ){ |
| 110526 | 110822 | yygotominor.yy342.pExpr->x.pSelect = yymsp[-1].minor.yy159; |
| 110527 | 110823 | ExprSetProperty(yygotominor.yy342.pExpr, EP_xIsSelect); |
| | @@ -110531,11 +110827,11 @@ |
| 110531 | 110827 | } |
| 110532 | 110828 | yygotominor.yy342.zStart = yymsp[-2].minor.yy0.z; |
| 110533 | 110829 | yygotominor.yy342.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n]; |
| 110534 | 110830 | } |
| 110535 | 110831 | break; |
| 110536 | | - case 228: /* expr ::= expr in_op LP select RP */ |
| 110832 | + case 226: /* expr ::= expr in_op LP select RP */ |
| 110537 | 110833 | { |
| 110538 | 110834 | yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy342.pExpr, 0, 0); |
| 110539 | 110835 | if( yygotominor.yy342.pExpr ){ |
| 110540 | 110836 | yygotominor.yy342.pExpr->x.pSelect = yymsp[-1].minor.yy159; |
| 110541 | 110837 | ExprSetProperty(yygotominor.yy342.pExpr, EP_xIsSelect); |
| | @@ -110546,11 +110842,11 @@ |
| 110546 | 110842 | if( yymsp[-3].minor.yy392 ) yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy342.pExpr, 0, 0); |
| 110547 | 110843 | yygotominor.yy342.zStart = yymsp[-4].minor.yy342.zStart; |
| 110548 | 110844 | yygotominor.yy342.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n]; |
| 110549 | 110845 | } |
| 110550 | 110846 | break; |
| 110551 | | - case 229: /* expr ::= expr in_op nm dbnm */ |
| 110847 | + case 227: /* expr ::= expr in_op nm dbnm */ |
| 110552 | 110848 | { |
| 110553 | 110849 | SrcList *pSrc = sqlite3SrcListAppend(pParse->db, 0,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0); |
| 110554 | 110850 | yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-3].minor.yy342.pExpr, 0, 0); |
| 110555 | 110851 | if( yygotominor.yy342.pExpr ){ |
| 110556 | 110852 | yygotominor.yy342.pExpr->x.pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0,0); |
| | @@ -110562,11 +110858,11 @@ |
| 110562 | 110858 | if( yymsp[-2].minor.yy392 ) yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy342.pExpr, 0, 0); |
| 110563 | 110859 | yygotominor.yy342.zStart = yymsp[-3].minor.yy342.zStart; |
| 110564 | 110860 | yygotominor.yy342.zEnd = yymsp[0].minor.yy0.z ? &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n] : &yymsp[-1].minor.yy0.z[yymsp[-1].minor.yy0.n]; |
| 110565 | 110861 | } |
| 110566 | 110862 | break; |
| 110567 | | - case 230: /* expr ::= EXISTS LP select RP */ |
| 110863 | + case 228: /* expr ::= EXISTS LP select RP */ |
| 110568 | 110864 | { |
| 110569 | 110865 | Expr *p = yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_EXISTS, 0, 0, 0); |
| 110570 | 110866 | if( p ){ |
| 110571 | 110867 | p->x.pSelect = yymsp[-1].minor.yy159; |
| 110572 | 110868 | ExprSetProperty(p, EP_xIsSelect); |
| | @@ -110576,11 +110872,11 @@ |
| 110576 | 110872 | } |
| 110577 | 110873 | yygotominor.yy342.zStart = yymsp[-3].minor.yy0.z; |
| 110578 | 110874 | yygotominor.yy342.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n]; |
| 110579 | 110875 | } |
| 110580 | 110876 | break; |
| 110581 | | - case 231: /* expr ::= CASE case_operand case_exprlist case_else END */ |
| 110877 | + case 229: /* expr ::= CASE case_operand case_exprlist case_else END */ |
| 110582 | 110878 | { |
| 110583 | 110879 | yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_CASE, yymsp[-3].minor.yy122, yymsp[-1].minor.yy122, 0); |
| 110584 | 110880 | if( yygotominor.yy342.pExpr ){ |
| 110585 | 110881 | yygotominor.yy342.pExpr->x.pList = yymsp[-2].minor.yy442; |
| 110586 | 110882 | sqlite3ExprSetHeight(pParse, yygotominor.yy342.pExpr); |
| | @@ -110589,43 +110885,43 @@ |
| 110589 | 110885 | } |
| 110590 | 110886 | yygotominor.yy342.zStart = yymsp[-4].minor.yy0.z; |
| 110591 | 110887 | yygotominor.yy342.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n]; |
| 110592 | 110888 | } |
| 110593 | 110889 | break; |
| 110594 | | - case 232: /* case_exprlist ::= case_exprlist WHEN expr THEN expr */ |
| 110890 | + case 230: /* case_exprlist ::= case_exprlist WHEN expr THEN expr */ |
| 110595 | 110891 | { |
| 110596 | 110892 | yygotominor.yy442 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy442, yymsp[-2].minor.yy342.pExpr); |
| 110597 | 110893 | yygotominor.yy442 = sqlite3ExprListAppend(pParse,yygotominor.yy442, yymsp[0].minor.yy342.pExpr); |
| 110598 | 110894 | } |
| 110599 | 110895 | break; |
| 110600 | | - case 233: /* case_exprlist ::= WHEN expr THEN expr */ |
| 110896 | + case 231: /* case_exprlist ::= WHEN expr THEN expr */ |
| 110601 | 110897 | { |
| 110602 | 110898 | yygotominor.yy442 = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy342.pExpr); |
| 110603 | 110899 | yygotominor.yy442 = sqlite3ExprListAppend(pParse,yygotominor.yy442, yymsp[0].minor.yy342.pExpr); |
| 110604 | 110900 | } |
| 110605 | 110901 | break; |
| 110606 | | - case 240: /* nexprlist ::= nexprlist COMMA expr */ |
| 110902 | + case 238: /* nexprlist ::= nexprlist COMMA expr */ |
| 110607 | 110903 | {yygotominor.yy442 = sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy442,yymsp[0].minor.yy342.pExpr);} |
| 110608 | 110904 | break; |
| 110609 | | - case 241: /* nexprlist ::= expr */ |
| 110905 | + case 239: /* nexprlist ::= expr */ |
| 110610 | 110906 | {yygotominor.yy442 = sqlite3ExprListAppend(pParse,0,yymsp[0].minor.yy342.pExpr);} |
| 110611 | 110907 | break; |
| 110612 | | - case 242: /* cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP idxlist RP */ |
| 110908 | + case 240: /* cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP idxlist RP */ |
| 110613 | 110909 | { |
| 110614 | 110910 | sqlite3CreateIndex(pParse, &yymsp[-6].minor.yy0, &yymsp[-5].minor.yy0, |
| 110615 | 110911 | sqlite3SrcListAppend(pParse->db,0,&yymsp[-3].minor.yy0,0), yymsp[-1].minor.yy442, yymsp[-9].minor.yy392, |
| 110616 | 110912 | &yymsp[-10].minor.yy0, &yymsp[0].minor.yy0, SQLITE_SO_ASC, yymsp[-7].minor.yy392); |
| 110617 | 110913 | } |
| 110618 | 110914 | break; |
| 110619 | | - case 243: /* uniqueflag ::= UNIQUE */ |
| 110620 | | - case 296: /* raisetype ::= ABORT */ yytestcase(yyruleno==296); |
| 110915 | + case 241: /* uniqueflag ::= UNIQUE */ |
| 110916 | + case 294: /* raisetype ::= ABORT */ yytestcase(yyruleno==294); |
| 110621 | 110917 | {yygotominor.yy392 = OE_Abort;} |
| 110622 | 110918 | break; |
| 110623 | | - case 244: /* uniqueflag ::= */ |
| 110919 | + case 242: /* uniqueflag ::= */ |
| 110624 | 110920 | {yygotominor.yy392 = OE_None;} |
| 110625 | 110921 | break; |
| 110626 | | - case 247: /* idxlist ::= idxlist COMMA nm collate sortorder */ |
| 110922 | + case 245: /* idxlist ::= idxlist COMMA nm collate sortorder */ |
| 110627 | 110923 | { |
| 110628 | 110924 | Expr *p = 0; |
| 110629 | 110925 | if( yymsp[-1].minor.yy0.n>0 ){ |
| 110630 | 110926 | p = sqlite3Expr(pParse->db, TK_COLUMN, 0); |
| 110631 | 110927 | sqlite3ExprSetCollByToken(pParse, p, &yymsp[-1].minor.yy0); |
| | @@ -110634,11 +110930,11 @@ |
| 110634 | 110930 | sqlite3ExprListSetName(pParse,yygotominor.yy442,&yymsp[-2].minor.yy0,1); |
| 110635 | 110931 | sqlite3ExprListCheckLength(pParse, yygotominor.yy442, "index"); |
| 110636 | 110932 | if( yygotominor.yy442 ) yygotominor.yy442->a[yygotominor.yy442->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy392; |
| 110637 | 110933 | } |
| 110638 | 110934 | break; |
| 110639 | | - case 248: /* idxlist ::= nm collate sortorder */ |
| 110935 | + case 246: /* idxlist ::= nm collate sortorder */ |
| 110640 | 110936 | { |
| 110641 | 110937 | Expr *p = 0; |
| 110642 | 110938 | if( yymsp[-1].minor.yy0.n>0 ){ |
| 110643 | 110939 | p = sqlite3PExpr(pParse, TK_COLUMN, 0, 0, 0); |
| 110644 | 110940 | sqlite3ExprSetCollByToken(pParse, p, &yymsp[-1].minor.yy0); |
| | @@ -110647,212 +110943,212 @@ |
| 110647 | 110943 | sqlite3ExprListSetName(pParse, yygotominor.yy442, &yymsp[-2].minor.yy0, 1); |
| 110648 | 110944 | sqlite3ExprListCheckLength(pParse, yygotominor.yy442, "index"); |
| 110649 | 110945 | if( yygotominor.yy442 ) yygotominor.yy442->a[yygotominor.yy442->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy392; |
| 110650 | 110946 | } |
| 110651 | 110947 | break; |
| 110652 | | - case 249: /* collate ::= */ |
| 110948 | + case 247: /* collate ::= */ |
| 110653 | 110949 | {yygotominor.yy0.z = 0; yygotominor.yy0.n = 0;} |
| 110654 | 110950 | break; |
| 110655 | | - case 251: /* cmd ::= DROP INDEX ifexists fullname */ |
| 110951 | + case 249: /* cmd ::= DROP INDEX ifexists fullname */ |
| 110656 | 110952 | {sqlite3DropIndex(pParse, yymsp[0].minor.yy347, yymsp[-1].minor.yy392);} |
| 110657 | 110953 | break; |
| 110658 | | - case 252: /* cmd ::= VACUUM */ |
| 110659 | | - case 253: /* cmd ::= VACUUM nm */ yytestcase(yyruleno==253); |
| 110954 | + case 250: /* cmd ::= VACUUM */ |
| 110955 | + case 251: /* cmd ::= VACUUM nm */ yytestcase(yyruleno==251); |
| 110660 | 110956 | {sqlite3Vacuum(pParse);} |
| 110661 | 110957 | break; |
| 110662 | | - case 254: /* cmd ::= PRAGMA nm dbnm */ |
| 110958 | + case 252: /* cmd ::= PRAGMA nm dbnm */ |
| 110663 | 110959 | {sqlite3Pragma(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,0,0);} |
| 110664 | 110960 | break; |
| 110665 | | - case 255: /* cmd ::= PRAGMA nm dbnm EQ nmnum */ |
| 110961 | + case 253: /* cmd ::= PRAGMA nm dbnm EQ nmnum */ |
| 110666 | 110962 | {sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,0);} |
| 110667 | 110963 | break; |
| 110668 | | - case 256: /* cmd ::= PRAGMA nm dbnm LP nmnum RP */ |
| 110964 | + case 254: /* cmd ::= PRAGMA nm dbnm LP nmnum RP */ |
| 110669 | 110965 | {sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,0);} |
| 110670 | 110966 | break; |
| 110671 | | - case 257: /* cmd ::= PRAGMA nm dbnm EQ minus_num */ |
| 110967 | + case 255: /* cmd ::= PRAGMA nm dbnm EQ minus_num */ |
| 110672 | 110968 | {sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,1);} |
| 110673 | 110969 | break; |
| 110674 | | - case 258: /* cmd ::= PRAGMA nm dbnm LP minus_num RP */ |
| 110970 | + case 256: /* cmd ::= PRAGMA nm dbnm LP minus_num RP */ |
| 110675 | 110971 | {sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,1);} |
| 110676 | 110972 | break; |
| 110677 | | - case 268: /* cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */ |
| 110973 | + case 266: /* cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */ |
| 110678 | 110974 | { |
| 110679 | 110975 | Token all; |
| 110680 | 110976 | all.z = yymsp[-3].minor.yy0.z; |
| 110681 | 110977 | all.n = (int)(yymsp[0].minor.yy0.z - yymsp[-3].minor.yy0.z) + yymsp[0].minor.yy0.n; |
| 110682 | 110978 | sqlite3FinishTrigger(pParse, yymsp[-1].minor.yy327, &all); |
| 110683 | 110979 | } |
| 110684 | 110980 | break; |
| 110685 | | - case 269: /* trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */ |
| 110981 | + case 267: /* trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */ |
| 110686 | 110982 | { |
| 110687 | 110983 | sqlite3BeginTrigger(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0, yymsp[-5].minor.yy392, yymsp[-4].minor.yy410.a, yymsp[-4].minor.yy410.b, yymsp[-2].minor.yy347, yymsp[0].minor.yy122, yymsp[-10].minor.yy392, yymsp[-8].minor.yy392); |
| 110688 | 110984 | yygotominor.yy0 = (yymsp[-6].minor.yy0.n==0?yymsp[-7].minor.yy0:yymsp[-6].minor.yy0); |
| 110689 | 110985 | } |
| 110690 | 110986 | break; |
| 110691 | | - case 270: /* trigger_time ::= BEFORE */ |
| 110692 | | - case 273: /* trigger_time ::= */ yytestcase(yyruleno==273); |
| 110987 | + case 268: /* trigger_time ::= BEFORE */ |
| 110988 | + case 271: /* trigger_time ::= */ yytestcase(yyruleno==271); |
| 110693 | 110989 | { yygotominor.yy392 = TK_BEFORE; } |
| 110694 | 110990 | break; |
| 110695 | | - case 271: /* trigger_time ::= AFTER */ |
| 110991 | + case 269: /* trigger_time ::= AFTER */ |
| 110696 | 110992 | { yygotominor.yy392 = TK_AFTER; } |
| 110697 | 110993 | break; |
| 110698 | | - case 272: /* trigger_time ::= INSTEAD OF */ |
| 110994 | + case 270: /* trigger_time ::= INSTEAD OF */ |
| 110699 | 110995 | { yygotominor.yy392 = TK_INSTEAD;} |
| 110700 | 110996 | break; |
| 110701 | | - case 274: /* trigger_event ::= DELETE|INSERT */ |
| 110702 | | - case 275: /* trigger_event ::= UPDATE */ yytestcase(yyruleno==275); |
| 110997 | + case 272: /* trigger_event ::= DELETE|INSERT */ |
| 110998 | + case 273: /* trigger_event ::= UPDATE */ yytestcase(yyruleno==273); |
| 110703 | 110999 | {yygotominor.yy410.a = yymsp[0].major; yygotominor.yy410.b = 0;} |
| 110704 | 111000 | break; |
| 110705 | | - case 276: /* trigger_event ::= UPDATE OF inscollist */ |
| 111001 | + case 274: /* trigger_event ::= UPDATE OF inscollist */ |
| 110706 | 111002 | {yygotominor.yy410.a = TK_UPDATE; yygotominor.yy410.b = yymsp[0].minor.yy180;} |
| 110707 | 111003 | break; |
| 110708 | | - case 279: /* when_clause ::= */ |
| 110709 | | - case 301: /* key_opt ::= */ yytestcase(yyruleno==301); |
| 111004 | + case 277: /* when_clause ::= */ |
| 111005 | + case 299: /* key_opt ::= */ yytestcase(yyruleno==299); |
| 110710 | 111006 | { yygotominor.yy122 = 0; } |
| 110711 | 111007 | break; |
| 110712 | | - case 280: /* when_clause ::= WHEN expr */ |
| 110713 | | - case 302: /* key_opt ::= KEY expr */ yytestcase(yyruleno==302); |
| 111008 | + case 278: /* when_clause ::= WHEN expr */ |
| 111009 | + case 300: /* key_opt ::= KEY expr */ yytestcase(yyruleno==300); |
| 110714 | 111010 | { yygotominor.yy122 = yymsp[0].minor.yy342.pExpr; } |
| 110715 | 111011 | break; |
| 110716 | | - case 281: /* trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */ |
| 111012 | + case 279: /* trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */ |
| 110717 | 111013 | { |
| 110718 | 111014 | assert( yymsp[-2].minor.yy327!=0 ); |
| 110719 | 111015 | yymsp[-2].minor.yy327->pLast->pNext = yymsp[-1].minor.yy327; |
| 110720 | 111016 | yymsp[-2].minor.yy327->pLast = yymsp[-1].minor.yy327; |
| 110721 | 111017 | yygotominor.yy327 = yymsp[-2].minor.yy327; |
| 110722 | 111018 | } |
| 110723 | 111019 | break; |
| 110724 | | - case 282: /* trigger_cmd_list ::= trigger_cmd SEMI */ |
| 111020 | + case 280: /* trigger_cmd_list ::= trigger_cmd SEMI */ |
| 110725 | 111021 | { |
| 110726 | 111022 | assert( yymsp[-1].minor.yy327!=0 ); |
| 110727 | 111023 | yymsp[-1].minor.yy327->pLast = yymsp[-1].minor.yy327; |
| 110728 | 111024 | yygotominor.yy327 = yymsp[-1].minor.yy327; |
| 110729 | 111025 | } |
| 110730 | 111026 | break; |
| 110731 | | - case 284: /* trnm ::= nm DOT nm */ |
| 111027 | + case 282: /* trnm ::= nm DOT nm */ |
| 110732 | 111028 | { |
| 110733 | 111029 | yygotominor.yy0 = yymsp[0].minor.yy0; |
| 110734 | 111030 | sqlite3ErrorMsg(pParse, |
| 110735 | 111031 | "qualified table names are not allowed on INSERT, UPDATE, and DELETE " |
| 110736 | 111032 | "statements within triggers"); |
| 110737 | 111033 | } |
| 110738 | 111034 | break; |
| 110739 | | - case 286: /* tridxby ::= INDEXED BY nm */ |
| 111035 | + case 284: /* tridxby ::= INDEXED BY nm */ |
| 110740 | 111036 | { |
| 110741 | 111037 | sqlite3ErrorMsg(pParse, |
| 110742 | 111038 | "the INDEXED BY clause is not allowed on UPDATE or DELETE statements " |
| 110743 | 111039 | "within triggers"); |
| 110744 | 111040 | } |
| 110745 | 111041 | break; |
| 110746 | | - case 287: /* tridxby ::= NOT INDEXED */ |
| 111042 | + case 285: /* tridxby ::= NOT INDEXED */ |
| 110747 | 111043 | { |
| 110748 | 111044 | sqlite3ErrorMsg(pParse, |
| 110749 | 111045 | "the NOT INDEXED clause is not allowed on UPDATE or DELETE statements " |
| 110750 | 111046 | "within triggers"); |
| 110751 | 111047 | } |
| 110752 | 111048 | break; |
| 110753 | | - case 288: /* trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt */ |
| 111049 | + case 286: /* trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt */ |
| 110754 | 111050 | { yygotominor.yy327 = sqlite3TriggerUpdateStep(pParse->db, &yymsp[-4].minor.yy0, yymsp[-1].minor.yy442, yymsp[0].minor.yy122, yymsp[-5].minor.yy258); } |
| 110755 | 111051 | break; |
| 110756 | | - case 289: /* trigger_cmd ::= insert_cmd INTO trnm inscollist_opt valuelist */ |
| 111052 | + case 287: /* trigger_cmd ::= insert_cmd INTO trnm inscollist_opt valuelist */ |
| 110757 | 111053 | {yygotominor.yy327 = sqlite3TriggerInsertStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy180, yymsp[0].minor.yy487.pList, yymsp[0].minor.yy487.pSelect, yymsp[-4].minor.yy258);} |
| 110758 | 111054 | break; |
| 110759 | | - case 290: /* trigger_cmd ::= insert_cmd INTO trnm inscollist_opt select */ |
| 111055 | + case 288: /* trigger_cmd ::= insert_cmd INTO trnm inscollist_opt select */ |
| 110760 | 111056 | {yygotominor.yy327 = sqlite3TriggerInsertStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy180, 0, yymsp[0].minor.yy159, yymsp[-4].minor.yy258);} |
| 110761 | 111057 | break; |
| 110762 | | - case 291: /* trigger_cmd ::= DELETE FROM trnm tridxby where_opt */ |
| 111058 | + case 289: /* trigger_cmd ::= DELETE FROM trnm tridxby where_opt */ |
| 110763 | 111059 | {yygotominor.yy327 = sqlite3TriggerDeleteStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[0].minor.yy122);} |
| 110764 | 111060 | break; |
| 110765 | | - case 292: /* trigger_cmd ::= select */ |
| 111061 | + case 290: /* trigger_cmd ::= select */ |
| 110766 | 111062 | {yygotominor.yy327 = sqlite3TriggerSelectStep(pParse->db, yymsp[0].minor.yy159); } |
| 110767 | 111063 | break; |
| 110768 | | - case 293: /* expr ::= RAISE LP IGNORE RP */ |
| 111064 | + case 291: /* expr ::= RAISE LP IGNORE RP */ |
| 110769 | 111065 | { |
| 110770 | 111066 | yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_RAISE, 0, 0, 0); |
| 110771 | 111067 | if( yygotominor.yy342.pExpr ){ |
| 110772 | 111068 | yygotominor.yy342.pExpr->affinity = OE_Ignore; |
| 110773 | 111069 | } |
| 110774 | 111070 | yygotominor.yy342.zStart = yymsp[-3].minor.yy0.z; |
| 110775 | 111071 | yygotominor.yy342.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n]; |
| 110776 | 111072 | } |
| 110777 | 111073 | break; |
| 110778 | | - case 294: /* expr ::= RAISE LP raisetype COMMA nm RP */ |
| 111074 | + case 292: /* expr ::= RAISE LP raisetype COMMA nm RP */ |
| 110779 | 111075 | { |
| 110780 | 111076 | yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_RAISE, 0, 0, &yymsp[-1].minor.yy0); |
| 110781 | 111077 | if( yygotominor.yy342.pExpr ) { |
| 110782 | 111078 | yygotominor.yy342.pExpr->affinity = (char)yymsp[-3].minor.yy392; |
| 110783 | 111079 | } |
| 110784 | 111080 | yygotominor.yy342.zStart = yymsp[-5].minor.yy0.z; |
| 110785 | 111081 | yygotominor.yy342.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n]; |
| 110786 | 111082 | } |
| 110787 | 111083 | break; |
| 110788 | | - case 295: /* raisetype ::= ROLLBACK */ |
| 111084 | + case 293: /* raisetype ::= ROLLBACK */ |
| 110789 | 111085 | {yygotominor.yy392 = OE_Rollback;} |
| 110790 | 111086 | break; |
| 110791 | | - case 297: /* raisetype ::= FAIL */ |
| 111087 | + case 295: /* raisetype ::= FAIL */ |
| 110792 | 111088 | {yygotominor.yy392 = OE_Fail;} |
| 110793 | 111089 | break; |
| 110794 | | - case 298: /* cmd ::= DROP TRIGGER ifexists fullname */ |
| 111090 | + case 296: /* cmd ::= DROP TRIGGER ifexists fullname */ |
| 110795 | 111091 | { |
| 110796 | 111092 | sqlite3DropTrigger(pParse,yymsp[0].minor.yy347,yymsp[-1].minor.yy392); |
| 110797 | 111093 | } |
| 110798 | 111094 | break; |
| 110799 | | - case 299: /* cmd ::= ATTACH database_kw_opt expr AS expr key_opt */ |
| 111095 | + case 297: /* cmd ::= ATTACH database_kw_opt expr AS expr key_opt */ |
| 110800 | 111096 | { |
| 110801 | 111097 | sqlite3Attach(pParse, yymsp[-3].minor.yy342.pExpr, yymsp[-1].minor.yy342.pExpr, yymsp[0].minor.yy122); |
| 110802 | 111098 | } |
| 110803 | 111099 | break; |
| 110804 | | - case 300: /* cmd ::= DETACH database_kw_opt expr */ |
| 111100 | + case 298: /* cmd ::= DETACH database_kw_opt expr */ |
| 110805 | 111101 | { |
| 110806 | 111102 | sqlite3Detach(pParse, yymsp[0].minor.yy342.pExpr); |
| 110807 | 111103 | } |
| 110808 | 111104 | break; |
| 110809 | | - case 305: /* cmd ::= REINDEX */ |
| 111105 | + case 303: /* cmd ::= REINDEX */ |
| 110810 | 111106 | {sqlite3Reindex(pParse, 0, 0);} |
| 110811 | 111107 | break; |
| 110812 | | - case 306: /* cmd ::= REINDEX nm dbnm */ |
| 111108 | + case 304: /* cmd ::= REINDEX nm dbnm */ |
| 110813 | 111109 | {sqlite3Reindex(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);} |
| 110814 | 111110 | break; |
| 110815 | | - case 307: /* cmd ::= ANALYZE */ |
| 111111 | + case 305: /* cmd ::= ANALYZE */ |
| 110816 | 111112 | {sqlite3Analyze(pParse, 0, 0);} |
| 110817 | 111113 | break; |
| 110818 | | - case 308: /* cmd ::= ANALYZE nm dbnm */ |
| 111114 | + case 306: /* cmd ::= ANALYZE nm dbnm */ |
| 110819 | 111115 | {sqlite3Analyze(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);} |
| 110820 | 111116 | break; |
| 110821 | | - case 309: /* cmd ::= ALTER TABLE fullname RENAME TO nm */ |
| 111117 | + case 307: /* cmd ::= ALTER TABLE fullname RENAME TO nm */ |
| 110822 | 111118 | { |
| 110823 | 111119 | sqlite3AlterRenameTable(pParse,yymsp[-3].minor.yy347,&yymsp[0].minor.yy0); |
| 110824 | 111120 | } |
| 110825 | 111121 | break; |
| 110826 | | - case 310: /* cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt column */ |
| 111122 | + case 308: /* cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt column */ |
| 110827 | 111123 | { |
| 110828 | 111124 | sqlite3AlterFinishAddColumn(pParse, &yymsp[0].minor.yy0); |
| 110829 | 111125 | } |
| 110830 | 111126 | break; |
| 110831 | | - case 311: /* add_column_fullname ::= fullname */ |
| 111127 | + case 309: /* add_column_fullname ::= fullname */ |
| 110832 | 111128 | { |
| 110833 | 111129 | pParse->db->lookaside.bEnabled = 0; |
| 110834 | 111130 | sqlite3AlterBeginAddColumn(pParse, yymsp[0].minor.yy347); |
| 110835 | 111131 | } |
| 110836 | 111132 | break; |
| 110837 | | - case 314: /* cmd ::= create_vtab */ |
| 111133 | + case 312: /* cmd ::= create_vtab */ |
| 110838 | 111134 | {sqlite3VtabFinishParse(pParse,0);} |
| 110839 | 111135 | break; |
| 110840 | | - case 315: /* cmd ::= create_vtab LP vtabarglist RP */ |
| 111136 | + case 313: /* cmd ::= create_vtab LP vtabarglist RP */ |
| 110841 | 111137 | {sqlite3VtabFinishParse(pParse,&yymsp[0].minor.yy0);} |
| 110842 | 111138 | break; |
| 110843 | | - case 316: /* create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */ |
| 111139 | + case 314: /* create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */ |
| 110844 | 111140 | { |
| 110845 | 111141 | sqlite3VtabBeginParse(pParse, &yymsp[-3].minor.yy0, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-4].minor.yy392); |
| 110846 | 111142 | } |
| 110847 | 111143 | break; |
| 110848 | | - case 319: /* vtabarg ::= */ |
| 111144 | + case 317: /* vtabarg ::= */ |
| 110849 | 111145 | {sqlite3VtabArgInit(pParse);} |
| 110850 | 111146 | break; |
| 110851 | | - case 321: /* vtabargtoken ::= ANY */ |
| 110852 | | - case 322: /* vtabargtoken ::= lp anylist RP */ yytestcase(yyruleno==322); |
| 110853 | | - case 323: /* lp ::= LP */ yytestcase(yyruleno==323); |
| 111147 | + case 319: /* vtabargtoken ::= ANY */ |
| 111148 | + case 320: /* vtabargtoken ::= lp anylist RP */ yytestcase(yyruleno==320); |
| 111149 | + case 321: /* lp ::= LP */ yytestcase(yyruleno==321); |
| 110854 | 111150 | {sqlite3VtabArgExtend(pParse,&yymsp[0].minor.yy0);} |
| 110855 | 111151 | break; |
| 110856 | 111152 | default: |
| 110857 | 111153 | /* (0) input ::= cmdlist */ yytestcase(yyruleno==0); |
| 110858 | 111154 | /* (1) cmdlist ::= cmdlist ecmd */ yytestcase(yyruleno==1); |
| | @@ -110868,32 +111164,28 @@ |
| 110868 | 111164 | /* (34) columnlist ::= columnlist COMMA column */ yytestcase(yyruleno==34); |
| 110869 | 111165 | /* (35) columnlist ::= column */ yytestcase(yyruleno==35); |
| 110870 | 111166 | /* (44) type ::= */ yytestcase(yyruleno==44); |
| 110871 | 111167 | /* (51) signed ::= plus_num */ yytestcase(yyruleno==51); |
| 110872 | 111168 | /* (52) signed ::= minus_num */ yytestcase(yyruleno==52); |
| 110873 | | - /* (53) carglist ::= carglist carg */ yytestcase(yyruleno==53); |
| 111169 | + /* (53) carglist ::= carglist cname ccons */ yytestcase(yyruleno==53); |
| 110874 | 111170 | /* (54) carglist ::= */ yytestcase(yyruleno==54); |
| 110875 | | - /* (55) carg ::= CONSTRAINT nm ccons */ yytestcase(yyruleno==55); |
| 110876 | | - /* (56) carg ::= ccons */ yytestcase(yyruleno==56); |
| 110877 | 111171 | /* (62) ccons ::= NULL onconf */ yytestcase(yyruleno==62); |
| 110878 | | - /* (90) conslist ::= conslist COMMA tcons */ yytestcase(yyruleno==90); |
| 110879 | | - /* (91) conslist ::= conslist tcons */ yytestcase(yyruleno==91); |
| 110880 | | - /* (92) conslist ::= tcons */ yytestcase(yyruleno==92); |
| 110881 | | - /* (93) tcons ::= CONSTRAINT nm */ yytestcase(yyruleno==93); |
| 110882 | | - /* (277) foreach_clause ::= */ yytestcase(yyruleno==277); |
| 110883 | | - /* (278) foreach_clause ::= FOR EACH ROW */ yytestcase(yyruleno==278); |
| 110884 | | - /* (285) tridxby ::= */ yytestcase(yyruleno==285); |
| 110885 | | - /* (303) database_kw_opt ::= DATABASE */ yytestcase(yyruleno==303); |
| 110886 | | - /* (304) database_kw_opt ::= */ yytestcase(yyruleno==304); |
| 110887 | | - /* (312) kwcolumn_opt ::= */ yytestcase(yyruleno==312); |
| 110888 | | - /* (313) kwcolumn_opt ::= COLUMNKW */ yytestcase(yyruleno==313); |
| 110889 | | - /* (317) vtabarglist ::= vtabarg */ yytestcase(yyruleno==317); |
| 110890 | | - /* (318) vtabarglist ::= vtabarglist COMMA vtabarg */ yytestcase(yyruleno==318); |
| 110891 | | - /* (320) vtabarg ::= vtabarg vtabargtoken */ yytestcase(yyruleno==320); |
| 110892 | | - /* (324) anylist ::= */ yytestcase(yyruleno==324); |
| 110893 | | - /* (325) anylist ::= anylist LP anylist RP */ yytestcase(yyruleno==325); |
| 110894 | | - /* (326) anylist ::= anylist ANY */ yytestcase(yyruleno==326); |
| 111172 | + /* (90) conslist ::= conslist COMMA cname tcons */ yytestcase(yyruleno==90); |
| 111173 | + /* (91) conslist ::= cname tcons */ yytestcase(yyruleno==91); |
| 111174 | + /* (275) foreach_clause ::= */ yytestcase(yyruleno==275); |
| 111175 | + /* (276) foreach_clause ::= FOR EACH ROW */ yytestcase(yyruleno==276); |
| 111176 | + /* (283) tridxby ::= */ yytestcase(yyruleno==283); |
| 111177 | + /* (301) database_kw_opt ::= DATABASE */ yytestcase(yyruleno==301); |
| 111178 | + /* (302) database_kw_opt ::= */ yytestcase(yyruleno==302); |
| 111179 | + /* (310) kwcolumn_opt ::= */ yytestcase(yyruleno==310); |
| 111180 | + /* (311) kwcolumn_opt ::= COLUMNKW */ yytestcase(yyruleno==311); |
| 111181 | + /* (315) vtabarglist ::= vtabarg */ yytestcase(yyruleno==315); |
| 111182 | + /* (316) vtabarglist ::= vtabarglist COMMA vtabarg */ yytestcase(yyruleno==316); |
| 111183 | + /* (318) vtabarg ::= vtabarg vtabargtoken */ yytestcase(yyruleno==318); |
| 111184 | + /* (322) anylist ::= */ yytestcase(yyruleno==322); |
| 111185 | + /* (323) anylist ::= anylist LP anylist RP */ yytestcase(yyruleno==323); |
| 111186 | + /* (324) anylist ::= anylist ANY */ yytestcase(yyruleno==324); |
| 110895 | 111187 | break; |
| 110896 | 111188 | }; |
| 110897 | 111189 | yygoto = yyRuleInfo[yyruleno].lhs; |
| 110898 | 111190 | yysize = yyRuleInfo[yyruleno].nrhs; |
| 110899 | 111191 | yypParser->yyidx -= yysize; |
| | @@ -113174,23 +113466,27 @@ |
| 113174 | 113466 | sqlite3_free(db); |
| 113175 | 113467 | return SQLITE_OK; |
| 113176 | 113468 | } |
| 113177 | 113469 | |
| 113178 | 113470 | /* |
| 113179 | | -** Rollback all database files. |
| 113471 | +** Rollback all database files. If tripCode is not SQLITE_OK, then |
| 113472 | +** any open cursors are invalidated ("tripped" - as in "tripping a circuit |
| 113473 | +** breaker") and made to return tripCode if there are any further |
| 113474 | +** attempts to use that cursor. |
| 113180 | 113475 | */ |
| 113181 | | -SQLITE_PRIVATE void sqlite3RollbackAll(sqlite3 *db){ |
| 113476 | +SQLITE_PRIVATE void sqlite3RollbackAll(sqlite3 *db, int tripCode){ |
| 113182 | 113477 | int i; |
| 113183 | 113478 | int inTrans = 0; |
| 113184 | 113479 | assert( sqlite3_mutex_held(db->mutex) ); |
| 113185 | 113480 | sqlite3BeginBenignMalloc(); |
| 113186 | 113481 | for(i=0; i<db->nDb; i++){ |
| 113187 | | - if( db->aDb[i].pBt ){ |
| 113188 | | - if( sqlite3BtreeIsInTrans(db->aDb[i].pBt) ){ |
| 113482 | + Btree *p = db->aDb[i].pBt; |
| 113483 | + if( p ){ |
| 113484 | + if( sqlite3BtreeIsInTrans(p) ){ |
| 113189 | 113485 | inTrans = 1; |
| 113190 | 113486 | } |
| 113191 | | - sqlite3BtreeRollback(db->aDb[i].pBt); |
| 113487 | + sqlite3BtreeRollback(p, tripCode); |
| 113192 | 113488 | db->aDb[i].inTrans = 0; |
| 113193 | 113489 | } |
| 113194 | 113490 | } |
| 113195 | 113491 | sqlite3VtabRollback(db); |
| 113196 | 113492 | sqlite3EndBenignMalloc(); |
| | @@ -113241,16 +113537,25 @@ |
| 113241 | 113537 | /* SQLITE_AUTH */ "authorization denied", |
| 113242 | 113538 | /* SQLITE_FORMAT */ "auxiliary database format error", |
| 113243 | 113539 | /* SQLITE_RANGE */ "bind or column index out of range", |
| 113244 | 113540 | /* SQLITE_NOTADB */ "file is encrypted or is not a database", |
| 113245 | 113541 | }; |
| 113246 | | - rc &= 0xff; |
| 113247 | | - if( ALWAYS(rc>=0) && rc<(int)(sizeof(aMsg)/sizeof(aMsg[0])) && aMsg[rc]!=0 ){ |
| 113248 | | - return aMsg[rc]; |
| 113249 | | - }else{ |
| 113250 | | - return "unknown error"; |
| 113542 | + const char *zErr = "unknown error"; |
| 113543 | + switch( rc ){ |
| 113544 | + case SQLITE_ABORT_ROLLBACK: { |
| 113545 | + zErr = "abort due to ROLLBACK"; |
| 113546 | + break; |
| 113547 | + } |
| 113548 | + default: { |
| 113549 | + rc &= 0xff; |
| 113550 | + if( ALWAYS(rc>=0) && rc<ArraySize(aMsg) && aMsg[rc]!=0 ){ |
| 113551 | + zErr = aMsg[rc]; |
| 113552 | + } |
| 113553 | + break; |
| 113554 | + } |
| 113251 | 113555 | } |
| 113556 | + return zErr; |
| 113252 | 113557 | } |
| 113253 | 113558 | |
| 113254 | 113559 | /* |
| 113255 | 113560 | ** This routine implements a busy callback that sleeps and tries |
| 113256 | 113561 | ** again until a timeout value is reached. The timeout value is |
| | @@ -113624,13 +113929,12 @@ |
| 113624 | 113929 | sqlite3_mutex_leave(db->mutex); |
| 113625 | 113930 | return pOld; |
| 113626 | 113931 | } |
| 113627 | 113932 | #endif /* SQLITE_OMIT_TRACE */ |
| 113628 | 113933 | |
| 113629 | | -/*** EXPERIMENTAL *** |
| 113630 | | -** |
| 113631 | | -** Register a function to be invoked when a transaction comments. |
| 113934 | +/* |
| 113935 | +** Register a function to be invoked when a transaction commits. |
| 113632 | 113936 | ** If the invoked function returns non-zero, then the commit becomes a |
| 113633 | 113937 | ** rollback. |
| 113634 | 113938 | */ |
| 113635 | 113939 | SQLITE_API void *sqlite3_commit_hook( |
| 113636 | 113940 | sqlite3 *db, /* Attach the hook to this database */ |
| | @@ -115017,39 +115321,31 @@ |
| 115017 | 115321 | /* |
| 115018 | 115322 | ** Invoke the xFileControl method on a particular database. |
| 115019 | 115323 | */ |
| 115020 | 115324 | SQLITE_API int sqlite3_file_control(sqlite3 *db, const char *zDbName, int op, void *pArg){ |
| 115021 | 115325 | int rc = SQLITE_ERROR; |
| 115022 | | - int iDb; |
| 115326 | + Btree *pBtree; |
| 115327 | + |
| 115023 | 115328 | sqlite3_mutex_enter(db->mutex); |
| 115024 | | - if( zDbName==0 ){ |
| 115025 | | - iDb = 0; |
| 115026 | | - }else{ |
| 115027 | | - for(iDb=0; iDb<db->nDb; iDb++){ |
| 115028 | | - if( strcmp(db->aDb[iDb].zName, zDbName)==0 ) break; |
| 115029 | | - } |
| 115030 | | - } |
| 115031 | | - if( iDb<db->nDb ){ |
| 115032 | | - Btree *pBtree = db->aDb[iDb].pBt; |
| 115033 | | - if( pBtree ){ |
| 115034 | | - Pager *pPager; |
| 115035 | | - sqlite3_file *fd; |
| 115036 | | - sqlite3BtreeEnter(pBtree); |
| 115037 | | - pPager = sqlite3BtreePager(pBtree); |
| 115038 | | - assert( pPager!=0 ); |
| 115039 | | - fd = sqlite3PagerFile(pPager); |
| 115040 | | - assert( fd!=0 ); |
| 115041 | | - if( op==SQLITE_FCNTL_FILE_POINTER ){ |
| 115042 | | - *(sqlite3_file**)pArg = fd; |
| 115043 | | - rc = SQLITE_OK; |
| 115044 | | - }else if( fd->pMethods ){ |
| 115045 | | - rc = sqlite3OsFileControl(fd, op, pArg); |
| 115046 | | - }else{ |
| 115047 | | - rc = SQLITE_NOTFOUND; |
| 115048 | | - } |
| 115049 | | - sqlite3BtreeLeave(pBtree); |
| 115050 | | - } |
| 115329 | + pBtree = sqlite3DbNameToBtree(db, zDbName); |
| 115330 | + if( pBtree ){ |
| 115331 | + Pager *pPager; |
| 115332 | + sqlite3_file *fd; |
| 115333 | + sqlite3BtreeEnter(pBtree); |
| 115334 | + pPager = sqlite3BtreePager(pBtree); |
| 115335 | + assert( pPager!=0 ); |
| 115336 | + fd = sqlite3PagerFile(pPager); |
| 115337 | + assert( fd!=0 ); |
| 115338 | + if( op==SQLITE_FCNTL_FILE_POINTER ){ |
| 115339 | + *(sqlite3_file**)pArg = fd; |
| 115340 | + rc = SQLITE_OK; |
| 115341 | + }else if( fd->pMethods ){ |
| 115342 | + rc = sqlite3OsFileControl(fd, op, pArg); |
| 115343 | + }else{ |
| 115344 | + rc = SQLITE_NOTFOUND; |
| 115345 | + } |
| 115346 | + sqlite3BtreeLeave(pBtree); |
| 115051 | 115347 | } |
| 115052 | 115348 | sqlite3_mutex_leave(db->mutex); |
| 115053 | 115349 | return rc; |
| 115054 | 115350 | } |
| 115055 | 115351 | |
| | @@ -115339,23 +115635,42 @@ |
| 115339 | 115635 | if( z && sqlite3Atoi64(z, &v, sqlite3Strlen30(z), SQLITE_UTF8)==SQLITE_OK ){ |
| 115340 | 115636 | bDflt = v; |
| 115341 | 115637 | } |
| 115342 | 115638 | return bDflt; |
| 115343 | 115639 | } |
| 115640 | + |
| 115641 | +/* |
| 115642 | +** Return the Btree pointer identified by zDbName. Return NULL if not found. |
| 115643 | +*/ |
| 115644 | +SQLITE_PRIVATE Btree *sqlite3DbNameToBtree(sqlite3 *db, const char *zDbName){ |
| 115645 | + int i; |
| 115646 | + for(i=0; i<db->nDb; i++){ |
| 115647 | + if( db->aDb[i].pBt |
| 115648 | + && (zDbName==0 || sqlite3StrICmp(zDbName, db->aDb[i].zName)==0) |
| 115649 | + ){ |
| 115650 | + return db->aDb[i].pBt; |
| 115651 | + } |
| 115652 | + } |
| 115653 | + return 0; |
| 115654 | +} |
| 115344 | 115655 | |
| 115345 | 115656 | /* |
| 115346 | 115657 | ** Return the filename of the database associated with a database |
| 115347 | 115658 | ** connection. |
| 115348 | 115659 | */ |
| 115349 | 115660 | SQLITE_API const char *sqlite3_db_filename(sqlite3 *db, const char *zDbName){ |
| 115350 | | - int i; |
| 115351 | | - for(i=0; i<db->nDb; i++){ |
| 115352 | | - if( db->aDb[i].pBt && sqlite3StrICmp(zDbName, db->aDb[i].zName)==0 ){ |
| 115353 | | - return sqlite3BtreeGetFilename(db->aDb[i].pBt); |
| 115354 | | - } |
| 115355 | | - } |
| 115356 | | - return 0; |
| 115661 | + Btree *pBt = sqlite3DbNameToBtree(db, zDbName); |
| 115662 | + return pBt ? sqlite3BtreeGetFilename(pBt) : 0; |
| 115663 | +} |
| 115664 | + |
| 115665 | +/* |
| 115666 | +** Return 1 if database is read-only or 0 if read/write. Return -1 if |
| 115667 | +** no such database exists. |
| 115668 | +*/ |
| 115669 | +SQLITE_API int sqlite3_db_readonly(sqlite3 *db, const char *zDbName){ |
| 115670 | + Btree *pBt = sqlite3DbNameToBtree(db, zDbName); |
| 115671 | + return pBt ? sqlite3PagerIsreadonly(sqlite3BtreePager(pBt)) : -1; |
| 115357 | 115672 | } |
| 115358 | 115673 | |
| 115359 | 115674 | /************** End of main.c ************************************************/ |
| 115360 | 115675 | /************** Begin file notify.c ******************************************/ |
| 115361 | 115676 | /* |
| | @@ -115761,11 +116076,11 @@ |
| 115761 | 116076 | ** option. But that functionality is no longer supported. |
| 115762 | 116077 | ** |
| 115763 | 116078 | ** A doclist is stored like this: |
| 115764 | 116079 | ** |
| 115765 | 116080 | ** array { |
| 115766 | | -** varint docid; |
| 116081 | +** varint docid; (delta from previous doclist) |
| 115767 | 116082 | ** array { (position list for column 0) |
| 115768 | 116083 | ** varint position; (2 more than the delta from previous position) |
| 115769 | 116084 | ** } |
| 115770 | 116085 | ** array { |
| 115771 | 116086 | ** varint POS_COLUMN; (marks start of position list for new column) |
| | @@ -115792,12 +116107,12 @@ |
| 115792 | 116107 | ** The 123 value is the first docid. For column zero in this document |
| 115793 | 116108 | ** there are two matches at positions 3 and 10 (5-2 and 9-2+3). The 1 |
| 115794 | 116109 | ** at D signals the start of a new column; the 1 at E indicates that the |
| 115795 | 116110 | ** new column is column number 1. There are two positions at 12 and 45 |
| 115796 | 116111 | ** (14-2 and 35-2+12). The 0 at H indicate the end-of-document. The |
| 115797 | | -** 234 at I is the next docid. It has one position 72 (72-2) and then |
| 115798 | | -** terminates with the 0 at K. |
| 116112 | +** 234 at I is the delta to next docid (357). It has one position 70 |
| 116113 | +** (72-2) and then terminates with the 0 at K. |
| 115799 | 116114 | ** |
| 115800 | 116115 | ** A "position-list" is the list of positions for multiple columns for |
| 115801 | 116116 | ** a single docid. A "column-list" is the set of positions for a single |
| 115802 | 116117 | ** column. Hence, a position-list consists of one or more column-lists, |
| 115803 | 116118 | ** a document record consists of a docid followed by a position-list and |
| | @@ -115977,14 +116292,10 @@ |
| 115977 | 116292 | ** we simply write the new doclist. Segment merges overwrite older |
| 115978 | 116293 | ** data for a particular docid with newer data, so deletes or updates |
| 115979 | 116294 | ** will eventually overtake the earlier data and knock it out. The |
| 115980 | 116295 | ** query logic likewise merges doclists so that newer data knocks out |
| 115981 | 116296 | ** older data. |
| 115982 | | -** |
| 115983 | | -** TODO(shess) Provide a VACUUM type operation to clear out all |
| 115984 | | -** deletions and duplications. This would basically be a forced merge |
| 115985 | | -** into a single segment. |
| 115986 | 116297 | */ |
| 115987 | 116298 | |
| 115988 | 116299 | /************** Include fts3Int.h in the middle of fts3.c ********************/ |
| 115989 | 116300 | /************** Begin file fts3Int.h *****************************************/ |
| 115990 | 116301 | /* |
| | @@ -116076,11 +116387,11 @@ |
| 116076 | 116387 | typedef struct sqlite3_tokenizer_cursor sqlite3_tokenizer_cursor; |
| 116077 | 116388 | |
| 116078 | 116389 | struct sqlite3_tokenizer_module { |
| 116079 | 116390 | |
| 116080 | 116391 | /* |
| 116081 | | - ** Structure version. Should always be set to 0. |
| 116392 | + ** Structure version. Should always be set to 0 or 1. |
| 116082 | 116393 | */ |
| 116083 | 116394 | int iVersion; |
| 116084 | 116395 | |
| 116085 | 116396 | /* |
| 116086 | 116397 | ** Create a new tokenizer. The values in the argv[] array are the |
| | @@ -116157,10 +116468,19 @@ |
| 116157 | 116468 | const char **ppToken, int *pnBytes, /* OUT: Normalized text for token */ |
| 116158 | 116469 | int *piStartOffset, /* OUT: Byte offset of token in input buffer */ |
| 116159 | 116470 | int *piEndOffset, /* OUT: Byte offset of end of token in input buffer */ |
| 116160 | 116471 | int *piPosition /* OUT: Number of tokens returned before this one */ |
| 116161 | 116472 | ); |
| 116473 | + |
| 116474 | + /*********************************************************************** |
| 116475 | + ** Methods below this point are only available if iVersion>=1. |
| 116476 | + */ |
| 116477 | + |
| 116478 | + /* |
| 116479 | + ** Configure the language id of a tokenizer cursor. |
| 116480 | + */ |
| 116481 | + int (*xLanguageid)(sqlite3_tokenizer_cursor *pCsr, int iLangid); |
| 116162 | 116482 | }; |
| 116163 | 116483 | |
| 116164 | 116484 | struct sqlite3_tokenizer { |
| 116165 | 116485 | const sqlite3_tokenizer_module *pModule; /* The module for this tokenizer */ |
| 116166 | 116486 | /* Tokenizer implementations will typically add additional fields */ |
| | @@ -116323,10 +116643,13 @@ |
| 116323 | 116643 | |
| 116324 | 116644 | |
| 116325 | 116645 | #ifndef MIN |
| 116326 | 116646 | # define MIN(x,y) ((x)<(y)?(x):(y)) |
| 116327 | 116647 | #endif |
| 116648 | +#ifndef MAX |
| 116649 | +# define MAX(x,y) ((x)>(y)?(x):(y)) |
| 116650 | +#endif |
| 116328 | 116651 | |
| 116329 | 116652 | /* |
| 116330 | 116653 | ** Maximum length of a varint encoded integer. The varint format is different |
| 116331 | 116654 | ** from that used by SQLite, so the maximum length is 10, not 9. |
| 116332 | 116655 | */ |
| | @@ -116377,20 +116700,21 @@ |
| 116377 | 116700 | #ifdef SQLITE_COVERAGE_TEST |
| 116378 | 116701 | # define ALWAYS(x) (1) |
| 116379 | 116702 | # define NEVER(X) (0) |
| 116380 | 116703 | #else |
| 116381 | 116704 | # define ALWAYS(x) (x) |
| 116382 | | -# define NEVER(X) (x) |
| 116705 | +# define NEVER(x) (x) |
| 116383 | 116706 | #endif |
| 116384 | 116707 | |
| 116385 | 116708 | /* |
| 116386 | 116709 | ** Internal types used by SQLite. |
| 116387 | 116710 | */ |
| 116388 | 116711 | typedef unsigned char u8; /* 1-byte (or larger) unsigned integer */ |
| 116389 | 116712 | typedef short int i16; /* 2-byte (or larger) signed integer */ |
| 116390 | 116713 | typedef unsigned int u32; /* 4-byte unsigned integer */ |
| 116391 | 116714 | typedef sqlite3_uint64 u64; /* 8-byte unsigned integer */ |
| 116715 | +typedef sqlite3_int64 i64; /* 8-byte signed integer */ |
| 116392 | 116716 | |
| 116393 | 116717 | /* |
| 116394 | 116718 | ** Macro used to suppress compiler warnings for unused parameters. |
| 116395 | 116719 | */ |
| 116396 | 116720 | #define UNUSED_PARAMETER(x) (void)(x) |
| | @@ -116448,55 +116772,64 @@ |
| 116448 | 116772 | const char *zName; /* virtual table name */ |
| 116449 | 116773 | int nColumn; /* number of named columns in virtual table */ |
| 116450 | 116774 | char **azColumn; /* column names. malloced */ |
| 116451 | 116775 | sqlite3_tokenizer *pTokenizer; /* tokenizer for inserts and queries */ |
| 116452 | 116776 | char *zContentTbl; /* content=xxx option, or NULL */ |
| 116777 | + char *zLanguageid; /* languageid=xxx option, or NULL */ |
| 116778 | + u8 bAutoincrmerge; /* True if automerge=1 */ |
| 116779 | + u32 nLeafAdd; /* Number of leaf blocks added this trans */ |
| 116453 | 116780 | |
| 116454 | 116781 | /* Precompiled statements used by the implementation. Each of these |
| 116455 | 116782 | ** statements is run and reset within a single virtual table API call. |
| 116456 | 116783 | */ |
| 116457 | | - sqlite3_stmt *aStmt[27]; |
| 116784 | + sqlite3_stmt *aStmt[37]; |
| 116458 | 116785 | |
| 116459 | 116786 | char *zReadExprlist; |
| 116460 | 116787 | char *zWriteExprlist; |
| 116461 | 116788 | |
| 116462 | 116789 | int nNodeSize; /* Soft limit for node size */ |
| 116790 | + u8 bFts4; /* True for FTS4, false for FTS3 */ |
| 116463 | 116791 | u8 bHasStat; /* True if %_stat table exists */ |
| 116464 | 116792 | u8 bHasDocsize; /* True if %_docsize table exists */ |
| 116465 | 116793 | u8 bDescIdx; /* True if doclists are in reverse order */ |
| 116794 | + u8 bIgnoreSavepoint; /* True to ignore xSavepoint invocations */ |
| 116466 | 116795 | int nPgsz; /* Page size for host database */ |
| 116467 | 116796 | char *zSegmentsTbl; /* Name of %_segments table */ |
| 116468 | 116797 | sqlite3_blob *pSegments; /* Blob handle open on %_segments table */ |
| 116469 | 116798 | |
| 116470 | | - /* TODO: Fix the first paragraph of this comment. |
| 116471 | | - ** |
| 116472 | | - ** The following hash table is used to buffer pending index updates during |
| 116473 | | - ** transactions. Variable nPendingData estimates the memory size of the |
| 116474 | | - ** pending data, including hash table overhead, but not malloc overhead. |
| 116475 | | - ** When nPendingData exceeds nMaxPendingData, the buffer is flushed |
| 116476 | | - ** automatically. Variable iPrevDocid is the docid of the most recently |
| 116477 | | - ** inserted record. |
| 116799 | + /* |
| 116800 | + ** The following array of hash tables is used to buffer pending index |
| 116801 | + ** updates during transactions. All pending updates buffered at any one |
| 116802 | + ** time must share a common language-id (see the FTS4 langid= feature). |
| 116803 | + ** The current language id is stored in variable iPrevLangid. |
| 116478 | 116804 | ** |
| 116479 | 116805 | ** A single FTS4 table may have multiple full-text indexes. For each index |
| 116480 | 116806 | ** there is an entry in the aIndex[] array. Index 0 is an index of all the |
| 116481 | 116807 | ** terms that appear in the document set. Each subsequent index in aIndex[] |
| 116482 | 116808 | ** is an index of prefixes of a specific length. |
| 116809 | + ** |
| 116810 | + ** Variable nPendingData contains an estimate the memory consumed by the |
| 116811 | + ** pending data structures, including hash table overhead, but not including |
| 116812 | + ** malloc overhead. When nPendingData exceeds nMaxPendingData, all hash |
| 116813 | + ** tables are flushed to disk. Variable iPrevDocid is the docid of the most |
| 116814 | + ** recently inserted record. |
| 116483 | 116815 | */ |
| 116484 | 116816 | int nIndex; /* Size of aIndex[] */ |
| 116485 | 116817 | struct Fts3Index { |
| 116486 | 116818 | int nPrefix; /* Prefix length (0 for main terms index) */ |
| 116487 | 116819 | Fts3Hash hPending; /* Pending terms table for this index */ |
| 116488 | 116820 | } *aIndex; |
| 116489 | 116821 | int nMaxPendingData; /* Max pending data before flush to disk */ |
| 116490 | 116822 | int nPendingData; /* Current bytes of pending data */ |
| 116491 | 116823 | sqlite_int64 iPrevDocid; /* Docid of most recently inserted document */ |
| 116824 | + int iPrevLangid; /* Langid of recently inserted document */ |
| 116492 | 116825 | |
| 116493 | 116826 | #if defined(SQLITE_DEBUG) || defined(SQLITE_COVERAGE_TEST) |
| 116494 | 116827 | /* State variables used for validating that the transaction control |
| 116495 | 116828 | ** methods of the virtual table are called at appropriate times. These |
| 116496 | | - ** values do not contribution to the FTS computation; they are used for |
| 116497 | | - ** verifying the SQLite core. |
| 116829 | + ** values do not contribute to FTS functionality; they are used for |
| 116830 | + ** verifying the operation of the SQLite core. |
| 116498 | 116831 | */ |
| 116499 | 116832 | int inTransaction; /* True after xBegin but before xCommit/xRollback */ |
| 116500 | 116833 | int mxSavepoint; /* Largest valid xSavepoint integer */ |
| 116501 | 116834 | #endif |
| 116502 | 116835 | }; |
| | @@ -116511,10 +116844,11 @@ |
| 116511 | 116844 | i16 eSearch; /* Search strategy (see below) */ |
| 116512 | 116845 | u8 isEof; /* True if at End Of Results */ |
| 116513 | 116846 | u8 isRequireSeek; /* True if must seek pStmt to %_content row */ |
| 116514 | 116847 | sqlite3_stmt *pStmt; /* Prepared statement in use by the cursor */ |
| 116515 | 116848 | Fts3Expr *pExpr; /* Parsed MATCH query string */ |
| 116849 | + int iLangid; /* Language being queried for */ |
| 116516 | 116850 | int nPhrase; /* Number of matchable phrases in query */ |
| 116517 | 116851 | Fts3DeferredToken *pDeferred; /* Deferred search tokens, if any */ |
| 116518 | 116852 | sqlite3_int64 iPrevId; /* Previous id read from aDoclist */ |
| 116519 | 116853 | char *pNextId; /* Pointer into the body of aDoclist */ |
| 116520 | 116854 | char *aDoclist; /* List of docids for full-text queries */ |
| | @@ -116662,11 +116996,11 @@ |
| 116662 | 116996 | SQLITE_PRIVATE int sqlite3Fts3SegReaderNew(int, int, sqlite3_int64, |
| 116663 | 116997 | sqlite3_int64, sqlite3_int64, const char *, int, Fts3SegReader**); |
| 116664 | 116998 | SQLITE_PRIVATE int sqlite3Fts3SegReaderPending( |
| 116665 | 116999 | Fts3Table*,int,const char*,int,int,Fts3SegReader**); |
| 116666 | 117000 | SQLITE_PRIVATE void sqlite3Fts3SegReaderFree(Fts3SegReader *); |
| 116667 | | -SQLITE_PRIVATE int sqlite3Fts3AllSegdirs(Fts3Table*, int, int, sqlite3_stmt **); |
| 117001 | +SQLITE_PRIVATE int sqlite3Fts3AllSegdirs(Fts3Table*, int, int, int, sqlite3_stmt **); |
| 116668 | 117002 | SQLITE_PRIVATE int sqlite3Fts3ReadLock(Fts3Table *); |
| 116669 | 117003 | SQLITE_PRIVATE int sqlite3Fts3ReadBlock(Fts3Table*, sqlite3_int64, char **, int*, int*); |
| 116670 | 117004 | |
| 116671 | 117005 | SQLITE_PRIVATE int sqlite3Fts3SelectDoctotal(Fts3Table *, sqlite3_stmt **); |
| 116672 | 117006 | SQLITE_PRIVATE int sqlite3Fts3SelectDocsize(Fts3Table *, sqlite3_int64, sqlite3_stmt **); |
| | @@ -116674,21 +117008,22 @@ |
| 116674 | 117008 | SQLITE_PRIVATE void sqlite3Fts3FreeDeferredTokens(Fts3Cursor *); |
| 116675 | 117009 | SQLITE_PRIVATE int sqlite3Fts3DeferToken(Fts3Cursor *, Fts3PhraseToken *, int); |
| 116676 | 117010 | SQLITE_PRIVATE int sqlite3Fts3CacheDeferredDoclists(Fts3Cursor *); |
| 116677 | 117011 | SQLITE_PRIVATE void sqlite3Fts3FreeDeferredDoclists(Fts3Cursor *); |
| 116678 | 117012 | SQLITE_PRIVATE void sqlite3Fts3SegmentsClose(Fts3Table *); |
| 117013 | +SQLITE_PRIVATE int sqlite3Fts3MaxLevel(Fts3Table *, int *); |
| 116679 | 117014 | |
| 116680 | 117015 | /* Special values interpreted by sqlite3SegReaderCursor() */ |
| 116681 | 117016 | #define FTS3_SEGCURSOR_PENDING -1 |
| 116682 | 117017 | #define FTS3_SEGCURSOR_ALL -2 |
| 116683 | 117018 | |
| 116684 | 117019 | SQLITE_PRIVATE int sqlite3Fts3SegReaderStart(Fts3Table*, Fts3MultiSegReader*, Fts3SegFilter*); |
| 116685 | 117020 | SQLITE_PRIVATE int sqlite3Fts3SegReaderStep(Fts3Table *, Fts3MultiSegReader *); |
| 116686 | 117021 | SQLITE_PRIVATE void sqlite3Fts3SegReaderFinish(Fts3MultiSegReader *); |
| 116687 | 117022 | |
| 116688 | | -SQLITE_PRIVATE int sqlite3Fts3SegReaderCursor( |
| 116689 | | - Fts3Table *, int, int, const char *, int, int, int, Fts3MultiSegReader *); |
| 117023 | +SQLITE_PRIVATE int sqlite3Fts3SegReaderCursor(Fts3Table *, |
| 117024 | + int, int, int, const char *, int, int, int, Fts3MultiSegReader *); |
| 116690 | 117025 | |
| 116691 | 117026 | /* Flags allowed as part of the 4th argument to SegmentReaderIterate() */ |
| 116692 | 117027 | #define FTS3_SEGMENT_REQUIRE_POS 0x00000001 |
| 116693 | 117028 | #define FTS3_SEGMENT_IGNORE_EMPTY 0x00000002 |
| 116694 | 117029 | #define FTS3_SEGMENT_COLUMN_FILTER 0x00000004 |
| | @@ -116725,19 +117060,22 @@ |
| 116725 | 117060 | int nTerm; /* Size of zTerm in bytes */ |
| 116726 | 117061 | char *aDoclist; /* Pointer to doclist buffer */ |
| 116727 | 117062 | int nDoclist; /* Size of aDoclist[] in bytes */ |
| 116728 | 117063 | }; |
| 116729 | 117064 | |
| 117065 | +SQLITE_PRIVATE int sqlite3Fts3Incrmerge(Fts3Table*,int,int); |
| 117066 | + |
| 116730 | 117067 | /* fts3.c */ |
| 116731 | 117068 | SQLITE_PRIVATE int sqlite3Fts3PutVarint(char *, sqlite3_int64); |
| 116732 | 117069 | SQLITE_PRIVATE int sqlite3Fts3GetVarint(const char *, sqlite_int64 *); |
| 116733 | 117070 | SQLITE_PRIVATE int sqlite3Fts3GetVarint32(const char *, int *); |
| 116734 | 117071 | SQLITE_PRIVATE int sqlite3Fts3VarintLen(sqlite3_uint64); |
| 116735 | 117072 | SQLITE_PRIVATE void sqlite3Fts3Dequote(char *); |
| 116736 | 117073 | SQLITE_PRIVATE void sqlite3Fts3DoclistPrev(int,char*,int,char**,sqlite3_int64*,int*,u8*); |
| 116737 | 117074 | SQLITE_PRIVATE int sqlite3Fts3EvalPhraseStats(Fts3Cursor *, Fts3Expr *, u32 *); |
| 116738 | 117075 | SQLITE_PRIVATE int sqlite3Fts3FirstFilter(sqlite3_int64, char *, int, char *); |
| 117076 | +SQLITE_PRIVATE void sqlite3Fts3CreateStatTable(int*, Fts3Table*); |
| 116739 | 117077 | |
| 116740 | 117078 | /* fts3_tokenizer.c */ |
| 116741 | 117079 | SQLITE_PRIVATE const char *sqlite3Fts3NextToken(const char *, int *); |
| 116742 | 117080 | SQLITE_PRIVATE int sqlite3Fts3InitHashTable(sqlite3 *, Fts3Hash *, const char *); |
| 116743 | 117081 | SQLITE_PRIVATE int sqlite3Fts3InitTokenizer(Fts3Hash *pHash, const char *, |
| | @@ -116751,18 +117089,22 @@ |
| 116751 | 117089 | const char *, const char *, int, int |
| 116752 | 117090 | ); |
| 116753 | 117091 | SQLITE_PRIVATE void sqlite3Fts3Matchinfo(sqlite3_context *, Fts3Cursor *, const char *); |
| 116754 | 117092 | |
| 116755 | 117093 | /* fts3_expr.c */ |
| 116756 | | -SQLITE_PRIVATE int sqlite3Fts3ExprParse(sqlite3_tokenizer *, |
| 117094 | +SQLITE_PRIVATE int sqlite3Fts3ExprParse(sqlite3_tokenizer *, int, |
| 116757 | 117095 | char **, int, int, int, const char *, int, Fts3Expr ** |
| 116758 | 117096 | ); |
| 116759 | 117097 | SQLITE_PRIVATE void sqlite3Fts3ExprFree(Fts3Expr *); |
| 116760 | 117098 | #ifdef SQLITE_TEST |
| 116761 | 117099 | SQLITE_PRIVATE int sqlite3Fts3ExprInitTestInterface(sqlite3 *db); |
| 116762 | 117100 | SQLITE_PRIVATE int sqlite3Fts3InitTerm(sqlite3 *db); |
| 116763 | 117101 | #endif |
| 117102 | + |
| 117103 | +SQLITE_PRIVATE int sqlite3Fts3OpenTokenizer(sqlite3_tokenizer *, int, const char *, int, |
| 117104 | + sqlite3_tokenizer_cursor ** |
| 117105 | +); |
| 116764 | 117106 | |
| 116765 | 117107 | /* fts3_aux.c */ |
| 116766 | 117108 | SQLITE_PRIVATE int sqlite3Fts3InitAux(sqlite3 *db); |
| 116767 | 117109 | |
| 116768 | 117110 | SQLITE_PRIVATE void sqlite3Fts3EvalPhraseCleanup(Fts3Phrase *); |
| | @@ -116954,10 +117296,11 @@ |
| 116954 | 117296 | } |
| 116955 | 117297 | sqlite3_free(p->zSegmentsTbl); |
| 116956 | 117298 | sqlite3_free(p->zReadExprlist); |
| 116957 | 117299 | sqlite3_free(p->zWriteExprlist); |
| 116958 | 117300 | sqlite3_free(p->zContentTbl); |
| 117301 | + sqlite3_free(p->zLanguageid); |
| 116959 | 117302 | |
| 116960 | 117303 | /* Invoke the tokenizer destructor to free the tokenizer. */ |
| 116961 | 117304 | p->pTokenizer->pModule->xDestroy(p->pTokenizer); |
| 116962 | 117305 | |
| 116963 | 117306 | sqlite3_free(p); |
| | @@ -117030,11 +117373,13 @@ |
| 117030 | 117373 | if( *pRc==SQLITE_OK ){ |
| 117031 | 117374 | int i; /* Iterator variable */ |
| 117032 | 117375 | int rc; /* Return code */ |
| 117033 | 117376 | char *zSql; /* SQL statement passed to declare_vtab() */ |
| 117034 | 117377 | char *zCols; /* List of user defined columns */ |
| 117378 | + const char *zLanguageid; |
| 117035 | 117379 | |
| 117380 | + zLanguageid = (p->zLanguageid ? p->zLanguageid : "__langid"); |
| 117036 | 117381 | sqlite3_vtab_config(p->db, SQLITE_VTAB_CONSTRAINT_SUPPORT, 1); |
| 117037 | 117382 | |
| 117038 | 117383 | /* Create a list of user columns for the virtual table */ |
| 117039 | 117384 | zCols = sqlite3_mprintf("%Q, ", p->azColumn[0]); |
| 117040 | 117385 | for(i=1; zCols && i<p->nColumn; i++){ |
| | @@ -117041,11 +117386,12 @@ |
| 117041 | 117386 | zCols = sqlite3_mprintf("%z%Q, ", zCols, p->azColumn[i]); |
| 117042 | 117387 | } |
| 117043 | 117388 | |
| 117044 | 117389 | /* Create the whole "CREATE TABLE" statement to pass to SQLite */ |
| 117045 | 117390 | zSql = sqlite3_mprintf( |
| 117046 | | - "CREATE TABLE x(%s %Q HIDDEN, docid HIDDEN)", zCols, p->zName |
| 117391 | + "CREATE TABLE x(%s %Q HIDDEN, docid HIDDEN, %Q HIDDEN)", |
| 117392 | + zCols, p->zName, zLanguageid |
| 117047 | 117393 | ); |
| 117048 | 117394 | if( !zCols || !zSql ){ |
| 117049 | 117395 | rc = SQLITE_NOMEM; |
| 117050 | 117396 | }else{ |
| 117051 | 117397 | rc = sqlite3_declare_vtab(p->db, zSql); |
| | @@ -117054,10 +117400,22 @@ |
| 117054 | 117400 | sqlite3_free(zSql); |
| 117055 | 117401 | sqlite3_free(zCols); |
| 117056 | 117402 | *pRc = rc; |
| 117057 | 117403 | } |
| 117058 | 117404 | } |
| 117405 | + |
| 117406 | +/* |
| 117407 | +** Create the %_stat table if it does not already exist. |
| 117408 | +*/ |
| 117409 | +SQLITE_PRIVATE void sqlite3Fts3CreateStatTable(int *pRc, Fts3Table *p){ |
| 117410 | + fts3DbExec(pRc, p->db, |
| 117411 | + "CREATE TABLE IF NOT EXISTS %Q.'%q_stat'" |
| 117412 | + "(id INTEGER PRIMARY KEY, value BLOB);", |
| 117413 | + p->zDb, p->zName |
| 117414 | + ); |
| 117415 | + if( (*pRc)==SQLITE_OK ) p->bHasStat = 1; |
| 117416 | +} |
| 117059 | 117417 | |
| 117060 | 117418 | /* |
| 117061 | 117419 | ** Create the backing store tables (%_content, %_segments and %_segdir) |
| 117062 | 117420 | ** required by the FTS3 table passed as the only argument. This is done |
| 117063 | 117421 | ** as part of the vtab xCreate() method. |
| | @@ -117070,18 +117428,22 @@ |
| 117070 | 117428 | int rc = SQLITE_OK; /* Return code */ |
| 117071 | 117429 | int i; /* Iterator variable */ |
| 117072 | 117430 | sqlite3 *db = p->db; /* The database connection */ |
| 117073 | 117431 | |
| 117074 | 117432 | if( p->zContentTbl==0 ){ |
| 117433 | + const char *zLanguageid = p->zLanguageid; |
| 117075 | 117434 | char *zContentCols; /* Columns of %_content table */ |
| 117076 | 117435 | |
| 117077 | 117436 | /* Create a list of user columns for the content table */ |
| 117078 | 117437 | zContentCols = sqlite3_mprintf("docid INTEGER PRIMARY KEY"); |
| 117079 | 117438 | for(i=0; zContentCols && i<p->nColumn; i++){ |
| 117080 | 117439 | char *z = p->azColumn[i]; |
| 117081 | 117440 | zContentCols = sqlite3_mprintf("%z, 'c%d%q'", zContentCols, i, z); |
| 117082 | 117441 | } |
| 117442 | + if( zLanguageid && zContentCols ){ |
| 117443 | + zContentCols = sqlite3_mprintf("%z, langid", zContentCols, zLanguageid); |
| 117444 | + } |
| 117083 | 117445 | if( zContentCols==0 ) rc = SQLITE_NOMEM; |
| 117084 | 117446 | |
| 117085 | 117447 | /* Create the content table */ |
| 117086 | 117448 | fts3DbExec(&rc, db, |
| 117087 | 117449 | "CREATE TABLE %Q.'%q_content'(%s)", |
| | @@ -117111,15 +117473,13 @@ |
| 117111 | 117473 | fts3DbExec(&rc, db, |
| 117112 | 117474 | "CREATE TABLE %Q.'%q_docsize'(docid INTEGER PRIMARY KEY, size BLOB);", |
| 117113 | 117475 | p->zDb, p->zName |
| 117114 | 117476 | ); |
| 117115 | 117477 | } |
| 117478 | + assert( p->bHasStat==p->bFts4 ); |
| 117116 | 117479 | if( p->bHasStat ){ |
| 117117 | | - fts3DbExec(&rc, db, |
| 117118 | | - "CREATE TABLE %Q.'%q_stat'(id INTEGER PRIMARY KEY, value BLOB);", |
| 117119 | | - p->zDb, p->zName |
| 117120 | | - ); |
| 117480 | + sqlite3Fts3CreateStatTable(&rc, p); |
| 117121 | 117481 | } |
| 117122 | 117482 | return rc; |
| 117123 | 117483 | } |
| 117124 | 117484 | |
| 117125 | 117485 | /* |
| | @@ -117222,11 +117582,11 @@ |
| 117222 | 117582 | ** memory. |
| 117223 | 117583 | */ |
| 117224 | 117584 | static char *fts3QuoteId(char const *zInput){ |
| 117225 | 117585 | int nRet; |
| 117226 | 117586 | char *zRet; |
| 117227 | | - nRet = 2 + strlen(zInput)*2 + 1; |
| 117587 | + nRet = 2 + (int)strlen(zInput)*2 + 1; |
| 117228 | 117588 | zRet = sqlite3_malloc(nRet); |
| 117229 | 117589 | if( zRet ){ |
| 117230 | 117590 | int i; |
| 117231 | 117591 | char *z = zRet; |
| 117232 | 117592 | *(z++) = '"'; |
| | @@ -117277,18 +117637,24 @@ |
| 117277 | 117637 | } |
| 117278 | 117638 | fts3Appendf(pRc, &zRet, "docid"); |
| 117279 | 117639 | for(i=0; i<p->nColumn; i++){ |
| 117280 | 117640 | fts3Appendf(pRc, &zRet, ",%s(x.'c%d%q')", zFunction, i, p->azColumn[i]); |
| 117281 | 117641 | } |
| 117642 | + if( p->zLanguageid ){ |
| 117643 | + fts3Appendf(pRc, &zRet, ", x.%Q", "langid"); |
| 117644 | + } |
| 117282 | 117645 | sqlite3_free(zFree); |
| 117283 | 117646 | }else{ |
| 117284 | 117647 | fts3Appendf(pRc, &zRet, "rowid"); |
| 117285 | 117648 | for(i=0; i<p->nColumn; i++){ |
| 117286 | 117649 | fts3Appendf(pRc, &zRet, ", x.'%q'", p->azColumn[i]); |
| 117287 | 117650 | } |
| 117651 | + if( p->zLanguageid ){ |
| 117652 | + fts3Appendf(pRc, &zRet, ", x.%Q", p->zLanguageid); |
| 117653 | + } |
| 117288 | 117654 | } |
| 117289 | | - fts3Appendf(pRc, &zRet, "FROM '%q'.'%q%s' AS x", |
| 117655 | + fts3Appendf(pRc, &zRet, " FROM '%q'.'%q%s' AS x", |
| 117290 | 117656 | p->zDb, |
| 117291 | 117657 | (p->zContentTbl ? p->zContentTbl : p->zName), |
| 117292 | 117658 | (p->zContentTbl ? "" : "_content") |
| 117293 | 117659 | ); |
| 117294 | 117660 | return zRet; |
| | @@ -117327,10 +117693,13 @@ |
| 117327 | 117693 | } |
| 117328 | 117694 | fts3Appendf(pRc, &zRet, "?"); |
| 117329 | 117695 | for(i=0; i<p->nColumn; i++){ |
| 117330 | 117696 | fts3Appendf(pRc, &zRet, ",%s(?)", zFunction); |
| 117331 | 117697 | } |
| 117698 | + if( p->zLanguageid ){ |
| 117699 | + fts3Appendf(pRc, &zRet, ", ?"); |
| 117700 | + } |
| 117332 | 117701 | sqlite3_free(zFree); |
| 117333 | 117702 | return zRet; |
| 117334 | 117703 | } |
| 117335 | 117704 | |
| 117336 | 117705 | /* |
| | @@ -117469,11 +117838,11 @@ |
| 117469 | 117838 | ** space required to store a copy of each column name, including the |
| 117470 | 117839 | ** nul-terminator byte. */ |
| 117471 | 117840 | nCol = sqlite3_column_count(pStmt); |
| 117472 | 117841 | for(i=0; i<nCol; i++){ |
| 117473 | 117842 | const char *zCol = sqlite3_column_name(pStmt, i); |
| 117474 | | - nStr += strlen(zCol) + 1; |
| 117843 | + nStr += (int)strlen(zCol) + 1; |
| 117475 | 117844 | } |
| 117476 | 117845 | |
| 117477 | 117846 | /* Allocate and populate the array to return. */ |
| 117478 | 117847 | azCol = (const char **)sqlite3_malloc(sizeof(char *) * nCol + nStr); |
| 117479 | 117848 | if( azCol==0 ){ |
| | @@ -117480,11 +117849,11 @@ |
| 117480 | 117849 | rc = SQLITE_NOMEM; |
| 117481 | 117850 | }else{ |
| 117482 | 117851 | char *p = (char *)&azCol[nCol]; |
| 117483 | 117852 | for(i=0; i<nCol; i++){ |
| 117484 | 117853 | const char *zCol = sqlite3_column_name(pStmt, i); |
| 117485 | | - int n = strlen(zCol)+1; |
| 117854 | + int n = (int)strlen(zCol)+1; |
| 117486 | 117855 | memcpy(p, zCol, n); |
| 117487 | 117856 | azCol[i] = p; |
| 117488 | 117857 | p += n; |
| 117489 | 117858 | } |
| 117490 | 117859 | } |
| | @@ -117542,10 +117911,11 @@ |
| 117542 | 117911 | int bDescIdx = 0; /* True to store descending indexes */ |
| 117543 | 117912 | char *zPrefix = 0; /* Prefix parameter value (or NULL) */ |
| 117544 | 117913 | char *zCompress = 0; /* compress=? parameter (or NULL) */ |
| 117545 | 117914 | char *zUncompress = 0; /* uncompress=? parameter (or NULL) */ |
| 117546 | 117915 | char *zContent = 0; /* content=? parameter (or NULL) */ |
| 117916 | + char *zLanguageid = 0; /* languageid=? parameter (or NULL) */ |
| 117547 | 117917 | |
| 117548 | 117918 | assert( strlen(argv[0])==4 ); |
| 117549 | 117919 | assert( (sqlite3_strnicmp(argv[0], "fts4", 4)==0 && isFts4) |
| 117550 | 117920 | || (sqlite3_strnicmp(argv[0], "fts3", 4)==0 && !isFts4) |
| 117551 | 117921 | ); |
| | @@ -117591,11 +117961,12 @@ |
| 117591 | 117961 | { "matchinfo", 9 }, /* 0 -> MATCHINFO */ |
| 117592 | 117962 | { "prefix", 6 }, /* 1 -> PREFIX */ |
| 117593 | 117963 | { "compress", 8 }, /* 2 -> COMPRESS */ |
| 117594 | 117964 | { "uncompress", 10 }, /* 3 -> UNCOMPRESS */ |
| 117595 | 117965 | { "order", 5 }, /* 4 -> ORDER */ |
| 117596 | | - { "content", 7 } /* 5 -> CONTENT */ |
| 117966 | + { "content", 7 }, /* 5 -> CONTENT */ |
| 117967 | + { "languageid", 10 } /* 6 -> LANGUAGEID */ |
| 117597 | 117968 | }; |
| 117598 | 117969 | |
| 117599 | 117970 | int iOpt; |
| 117600 | 117971 | if( !zVal ){ |
| 117601 | 117972 | rc = SQLITE_NOMEM; |
| | @@ -117645,16 +118016,22 @@ |
| 117645 | 118016 | rc = SQLITE_ERROR; |
| 117646 | 118017 | } |
| 117647 | 118018 | bDescIdx = (zVal[0]=='d' || zVal[0]=='D'); |
| 117648 | 118019 | break; |
| 117649 | 118020 | |
| 117650 | | - default: /* CONTENT */ |
| 117651 | | - assert( iOpt==5 ); |
| 117652 | | - sqlite3_free(zUncompress); |
| 118021 | + case 5: /* CONTENT */ |
| 118022 | + sqlite3_free(zContent); |
| 117653 | 118023 | zContent = zVal; |
| 117654 | 118024 | zVal = 0; |
| 117655 | 118025 | break; |
| 118026 | + |
| 118027 | + case 6: /* LANGUAGEID */ |
| 118028 | + assert( iOpt==6 ); |
| 118029 | + sqlite3_free(zLanguageid); |
| 118030 | + zLanguageid = zVal; |
| 118031 | + zVal = 0; |
| 118032 | + break; |
| 117656 | 118033 | } |
| 117657 | 118034 | } |
| 117658 | 118035 | sqlite3_free(zVal); |
| 117659 | 118036 | } |
| 117660 | 118037 | } |
| | @@ -117680,12 +118057,25 @@ |
| 117680 | 118057 | zUncompress = 0; |
| 117681 | 118058 | if( nCol==0 ){ |
| 117682 | 118059 | sqlite3_free((void*)aCol); |
| 117683 | 118060 | aCol = 0; |
| 117684 | 118061 | rc = fts3ContentColumns(db, argv[1], zContent, &aCol, &nCol, &nString); |
| 118062 | + |
| 118063 | + /* If a languageid= option was specified, remove the language id |
| 118064 | + ** column from the aCol[] array. */ |
| 118065 | + if( rc==SQLITE_OK && zLanguageid ){ |
| 118066 | + int j; |
| 118067 | + for(j=0; j<nCol; j++){ |
| 118068 | + if( sqlite3_stricmp(zLanguageid, aCol[j])==0 ){ |
| 118069 | + int k; |
| 118070 | + for(k=j; k<nCol; k++) aCol[k] = aCol[k+1]; |
| 118071 | + nCol--; |
| 118072 | + break; |
| 118073 | + } |
| 118074 | + } |
| 118075 | + } |
| 117685 | 118076 | } |
| 117686 | | - assert( rc!=SQLITE_OK || nCol>0 ); |
| 117687 | 118077 | } |
| 117688 | 118078 | if( rc!=SQLITE_OK ) goto fts3_init_out; |
| 117689 | 118079 | |
| 117690 | 118080 | if( nCol==0 ){ |
| 117691 | 118081 | assert( nString==0 ); |
| | @@ -117726,13 +118116,17 @@ |
| 117726 | 118116 | p->azColumn = (char **)&p[1]; |
| 117727 | 118117 | p->pTokenizer = pTokenizer; |
| 117728 | 118118 | p->nMaxPendingData = FTS3_MAX_PENDING_DATA; |
| 117729 | 118119 | p->bHasDocsize = (isFts4 && bNoDocsize==0); |
| 117730 | 118120 | p->bHasStat = isFts4; |
| 118121 | + p->bFts4 = isFts4; |
| 117731 | 118122 | p->bDescIdx = bDescIdx; |
| 118123 | + p->bAutoincrmerge = 0xff; /* 0xff means setting unknown */ |
| 117732 | 118124 | p->zContentTbl = zContent; |
| 118125 | + p->zLanguageid = zLanguageid; |
| 117733 | 118126 | zContent = 0; |
| 118127 | + zLanguageid = 0; |
| 117734 | 118128 | TESTONLY( p->inTransaction = -1 ); |
| 117735 | 118129 | TESTONLY( p->mxSavepoint = -1 ); |
| 117736 | 118130 | |
| 117737 | 118131 | p->aIndex = (struct Fts3Index *)&p->azColumn[nCol]; |
| 117738 | 118132 | memcpy(p->aIndex, aIndex, sizeof(struct Fts3Index) * nIndex); |
| | @@ -117776,10 +118170,20 @@ |
| 117776 | 118170 | ** database. TODO: For xConnect(), it could verify that said tables exist. |
| 117777 | 118171 | */ |
| 117778 | 118172 | if( isCreate ){ |
| 117779 | 118173 | rc = fts3CreateTables(p); |
| 117780 | 118174 | } |
| 118175 | + |
| 118176 | + /* Check to see if a legacy fts3 table has been "upgraded" by the |
| 118177 | + ** addition of a %_stat table so that it can use incremental merge. |
| 118178 | + */ |
| 118179 | + if( !isFts4 && !isCreate ){ |
| 118180 | + int rc2 = SQLITE_OK; |
| 118181 | + fts3DbExec(&rc2, db, "SELECT 1 FROM %Q.'%q_stat' WHERE id=2", |
| 118182 | + p->zDb, p->zName); |
| 118183 | + if( rc2==SQLITE_OK ) p->bHasStat = 1; |
| 118184 | + } |
| 117781 | 118185 | |
| 117782 | 118186 | /* Figure out the page-size for the database. This is required in order to |
| 117783 | 118187 | ** estimate the cost of loading large doclists from the database. */ |
| 117784 | 118188 | fts3DatabasePageSize(&rc, p); |
| 117785 | 118189 | p->nNodeSize = p->nPgsz-35; |
| | @@ -117791,10 +118195,11 @@ |
| 117791 | 118195 | sqlite3_free(zPrefix); |
| 117792 | 118196 | sqlite3_free(aIndex); |
| 117793 | 118197 | sqlite3_free(zCompress); |
| 117794 | 118198 | sqlite3_free(zUncompress); |
| 117795 | 118199 | sqlite3_free(zContent); |
| 118200 | + sqlite3_free(zLanguageid); |
| 117796 | 118201 | sqlite3_free((void *)aCol); |
| 117797 | 118202 | if( rc!=SQLITE_OK ){ |
| 117798 | 118203 | if( p ){ |
| 117799 | 118204 | fts3DisconnectMethod((sqlite3_vtab *)p); |
| 117800 | 118205 | }else if( pTokenizer ){ |
| | @@ -117842,10 +118247,11 @@ |
| 117842 | 118247 | */ |
| 117843 | 118248 | static int fts3BestIndexMethod(sqlite3_vtab *pVTab, sqlite3_index_info *pInfo){ |
| 117844 | 118249 | Fts3Table *p = (Fts3Table *)pVTab; |
| 117845 | 118250 | int i; /* Iterator variable */ |
| 117846 | 118251 | int iCons = -1; /* Index of constraint to use */ |
| 118252 | + int iLangidCons = -1; /* Index of langid=x constraint, if present */ |
| 117847 | 118253 | |
| 117848 | 118254 | /* By default use a full table scan. This is an expensive option, |
| 117849 | 118255 | ** so search through the constraints to see if a more efficient |
| 117850 | 118256 | ** strategy is possible. |
| 117851 | 118257 | */ |
| | @@ -117854,11 +118260,12 @@ |
| 117854 | 118260 | for(i=0; i<pInfo->nConstraint; i++){ |
| 117855 | 118261 | struct sqlite3_index_constraint *pCons = &pInfo->aConstraint[i]; |
| 117856 | 118262 | if( pCons->usable==0 ) continue; |
| 117857 | 118263 | |
| 117858 | 118264 | /* A direct lookup on the rowid or docid column. Assign a cost of 1.0. */ |
| 117859 | | - if( pCons->op==SQLITE_INDEX_CONSTRAINT_EQ |
| 118265 | + if( iCons<0 |
| 118266 | + && pCons->op==SQLITE_INDEX_CONSTRAINT_EQ |
| 117860 | 118267 | && (pCons->iColumn<0 || pCons->iColumn==p->nColumn+1 ) |
| 117861 | 118268 | ){ |
| 117862 | 118269 | pInfo->idxNum = FTS3_DOCID_SEARCH; |
| 117863 | 118270 | pInfo->estimatedCost = 1.0; |
| 117864 | 118271 | iCons = i; |
| | @@ -117877,18 +118284,27 @@ |
| 117877 | 118284 | && pCons->iColumn>=0 && pCons->iColumn<=p->nColumn |
| 117878 | 118285 | ){ |
| 117879 | 118286 | pInfo->idxNum = FTS3_FULLTEXT_SEARCH + pCons->iColumn; |
| 117880 | 118287 | pInfo->estimatedCost = 2.0; |
| 117881 | 118288 | iCons = i; |
| 117882 | | - break; |
| 118289 | + } |
| 118290 | + |
| 118291 | + /* Equality constraint on the langid column */ |
| 118292 | + if( pCons->op==SQLITE_INDEX_CONSTRAINT_EQ |
| 118293 | + && pCons->iColumn==p->nColumn + 2 |
| 118294 | + ){ |
| 118295 | + iLangidCons = i; |
| 117883 | 118296 | } |
| 117884 | 118297 | } |
| 117885 | 118298 | |
| 117886 | 118299 | if( iCons>=0 ){ |
| 117887 | 118300 | pInfo->aConstraintUsage[iCons].argvIndex = 1; |
| 117888 | 118301 | pInfo->aConstraintUsage[iCons].omit = 1; |
| 117889 | 118302 | } |
| 118303 | + if( iLangidCons>=0 ){ |
| 118304 | + pInfo->aConstraintUsage[iLangidCons].argvIndex = 2; |
| 118305 | + } |
| 117890 | 118306 | |
| 117891 | 118307 | /* Regardless of the strategy selected, FTS can deliver rows in rowid (or |
| 117892 | 118308 | ** docid) order. Both ascending and descending are possible. |
| 117893 | 118309 | */ |
| 117894 | 118310 | if( pInfo->nOrderBy==1 ){ |
| | @@ -118768,11 +119184,11 @@ |
| 118768 | 119184 | fts3GetDeltaVarint3(&p2, pEnd2, bDescDoclist, &i2); |
| 118769 | 119185 | } |
| 118770 | 119186 | } |
| 118771 | 119187 | |
| 118772 | 119188 | *paOut = aOut; |
| 118773 | | - *pnOut = (p-aOut); |
| 119189 | + *pnOut = (int)(p-aOut); |
| 118774 | 119190 | assert( *pnOut<=n1+n2+FTS3_VARINT_MAX-1 ); |
| 118775 | 119191 | return SQLITE_OK; |
| 118776 | 119192 | } |
| 118777 | 119193 | |
| 118778 | 119194 | /* |
| | @@ -118832,11 +119248,11 @@ |
| 118832 | 119248 | fts3PoslistCopy(0, &p2); |
| 118833 | 119249 | fts3GetDeltaVarint3(&p2, pEnd2, bDescDoclist, &i2); |
| 118834 | 119250 | } |
| 118835 | 119251 | } |
| 118836 | 119252 | |
| 118837 | | - *pnRight = p - aOut; |
| 119253 | + *pnRight = (int)(p - aOut); |
| 118838 | 119254 | } |
| 118839 | 119255 | |
| 118840 | 119256 | /* |
| 118841 | 119257 | ** Argument pList points to a position list nList bytes in size. This |
| 118842 | 119258 | ** function checks to see if the position list contains any entries for |
| | @@ -119034,10 +119450,11 @@ |
| 119034 | 119450 | ** This function returns SQLITE_OK if successful, or an SQLite error code |
| 119035 | 119451 | ** otherwise. |
| 119036 | 119452 | */ |
| 119037 | 119453 | static int fts3SegReaderCursor( |
| 119038 | 119454 | Fts3Table *p, /* FTS3 table handle */ |
| 119455 | + int iLangid, /* Language id */ |
| 119039 | 119456 | int iIndex, /* Index to search (from 0 to p->nIndex-1) */ |
| 119040 | 119457 | int iLevel, /* Level of segments to scan */ |
| 119041 | 119458 | const char *zTerm, /* Term to query for */ |
| 119042 | 119459 | int nTerm, /* Size of zTerm in bytes */ |
| 119043 | 119460 | int isPrefix, /* True for a prefix search */ |
| | @@ -119062,11 +119479,11 @@ |
| 119062 | 119479 | } |
| 119063 | 119480 | } |
| 119064 | 119481 | |
| 119065 | 119482 | if( iLevel!=FTS3_SEGCURSOR_PENDING ){ |
| 119066 | 119483 | if( rc==SQLITE_OK ){ |
| 119067 | | - rc = sqlite3Fts3AllSegdirs(p, iIndex, iLevel, &pStmt); |
| 119484 | + rc = sqlite3Fts3AllSegdirs(p, iLangid, iIndex, iLevel, &pStmt); |
| 119068 | 119485 | } |
| 119069 | 119486 | |
| 119070 | 119487 | while( rc==SQLITE_OK && SQLITE_ROW==(rc = sqlite3_step(pStmt)) ){ |
| 119071 | 119488 | Fts3SegReader *pSeg = 0; |
| 119072 | 119489 | |
| | @@ -119107,10 +119524,11 @@ |
| 119107 | 119524 | ** Set up a cursor object for iterating through a full-text index or a |
| 119108 | 119525 | ** single level therein. |
| 119109 | 119526 | */ |
| 119110 | 119527 | SQLITE_PRIVATE int sqlite3Fts3SegReaderCursor( |
| 119111 | 119528 | Fts3Table *p, /* FTS3 table handle */ |
| 119529 | + int iLangid, /* Language-id to search */ |
| 119112 | 119530 | int iIndex, /* Index to search (from 0 to p->nIndex-1) */ |
| 119113 | 119531 | int iLevel, /* Level of segments to scan */ |
| 119114 | 119532 | const char *zTerm, /* Term to query for */ |
| 119115 | 119533 | int nTerm, /* Size of zTerm in bytes */ |
| 119116 | 119534 | int isPrefix, /* True for a prefix search */ |
| | @@ -119124,18 +119542,13 @@ |
| 119124 | 119542 | ); |
| 119125 | 119543 | assert( iLevel<FTS3_SEGDIR_MAXLEVEL ); |
| 119126 | 119544 | assert( FTS3_SEGCURSOR_ALL<0 && FTS3_SEGCURSOR_PENDING<0 ); |
| 119127 | 119545 | assert( isPrefix==0 || isScan==0 ); |
| 119128 | 119546 | |
| 119129 | | - /* "isScan" is only set to true by the ft4aux module, an ordinary |
| 119130 | | - ** full-text tables. */ |
| 119131 | | - assert( isScan==0 || p->aIndex==0 ); |
| 119132 | | - |
| 119133 | 119547 | memset(pCsr, 0, sizeof(Fts3MultiSegReader)); |
| 119134 | | - |
| 119135 | 119548 | return fts3SegReaderCursor( |
| 119136 | | - p, iIndex, iLevel, zTerm, nTerm, isPrefix, isScan, pCsr |
| 119549 | + p, iLangid, iIndex, iLevel, zTerm, nTerm, isPrefix, isScan, pCsr |
| 119137 | 119550 | ); |
| 119138 | 119551 | } |
| 119139 | 119552 | |
| 119140 | 119553 | /* |
| 119141 | 119554 | ** In addition to its current configuration, have the Fts3MultiSegReader |
| | @@ -119143,15 +119556,18 @@ |
| 119143 | 119556 | ** |
| 119144 | 119557 | ** SQLITE_OK is returned if no error occurs, otherwise an SQLite error code. |
| 119145 | 119558 | */ |
| 119146 | 119559 | static int fts3SegReaderCursorAddZero( |
| 119147 | 119560 | Fts3Table *p, /* FTS virtual table handle */ |
| 119561 | + int iLangid, |
| 119148 | 119562 | const char *zTerm, /* Term to scan doclist of */ |
| 119149 | 119563 | int nTerm, /* Number of bytes in zTerm */ |
| 119150 | 119564 | Fts3MultiSegReader *pCsr /* Fts3MultiSegReader to modify */ |
| 119151 | 119565 | ){ |
| 119152 | | - return fts3SegReaderCursor(p, 0, FTS3_SEGCURSOR_ALL, zTerm, nTerm, 0, 0,pCsr); |
| 119566 | + return fts3SegReaderCursor(p, |
| 119567 | + iLangid, 0, FTS3_SEGCURSOR_ALL, zTerm, nTerm, 0, 0,pCsr |
| 119568 | + ); |
| 119153 | 119569 | } |
| 119154 | 119570 | |
| 119155 | 119571 | /* |
| 119156 | 119572 | ** Open an Fts3MultiSegReader to scan the doclist for term zTerm/nTerm. Or, |
| 119157 | 119573 | ** if isPrefix is true, to scan the doclist for all terms for which |
| | @@ -119183,32 +119599,35 @@ |
| 119183 | 119599 | |
| 119184 | 119600 | if( isPrefix ){ |
| 119185 | 119601 | for(i=1; bFound==0 && i<p->nIndex; i++){ |
| 119186 | 119602 | if( p->aIndex[i].nPrefix==nTerm ){ |
| 119187 | 119603 | bFound = 1; |
| 119188 | | - rc = sqlite3Fts3SegReaderCursor( |
| 119189 | | - p, i, FTS3_SEGCURSOR_ALL, zTerm, nTerm, 0, 0, pSegcsr); |
| 119604 | + rc = sqlite3Fts3SegReaderCursor(p, pCsr->iLangid, |
| 119605 | + i, FTS3_SEGCURSOR_ALL, zTerm, nTerm, 0, 0, pSegcsr |
| 119606 | + ); |
| 119190 | 119607 | pSegcsr->bLookup = 1; |
| 119191 | 119608 | } |
| 119192 | 119609 | } |
| 119193 | 119610 | |
| 119194 | 119611 | for(i=1; bFound==0 && i<p->nIndex; i++){ |
| 119195 | 119612 | if( p->aIndex[i].nPrefix==nTerm+1 ){ |
| 119196 | 119613 | bFound = 1; |
| 119197 | | - rc = sqlite3Fts3SegReaderCursor( |
| 119198 | | - p, i, FTS3_SEGCURSOR_ALL, zTerm, nTerm, 1, 0, pSegcsr |
| 119614 | + rc = sqlite3Fts3SegReaderCursor(p, pCsr->iLangid, |
| 119615 | + i, FTS3_SEGCURSOR_ALL, zTerm, nTerm, 1, 0, pSegcsr |
| 119199 | 119616 | ); |
| 119200 | 119617 | if( rc==SQLITE_OK ){ |
| 119201 | | - rc = fts3SegReaderCursorAddZero(p, zTerm, nTerm, pSegcsr); |
| 119618 | + rc = fts3SegReaderCursorAddZero( |
| 119619 | + p, pCsr->iLangid, zTerm, nTerm, pSegcsr |
| 119620 | + ); |
| 119202 | 119621 | } |
| 119203 | 119622 | } |
| 119204 | 119623 | } |
| 119205 | 119624 | } |
| 119206 | 119625 | |
| 119207 | 119626 | if( bFound==0 ){ |
| 119208 | | - rc = sqlite3Fts3SegReaderCursor( |
| 119209 | | - p, 0, FTS3_SEGCURSOR_ALL, zTerm, nTerm, isPrefix, 0, pSegcsr |
| 119627 | + rc = sqlite3Fts3SegReaderCursor(p, pCsr->iLangid, |
| 119628 | + 0, FTS3_SEGCURSOR_ALL, zTerm, nTerm, isPrefix, 0, pSegcsr |
| 119210 | 119629 | ); |
| 119211 | 119630 | pSegcsr->bLookup = !isPrefix; |
| 119212 | 119631 | } |
| 119213 | 119632 | } |
| 119214 | 119633 | |
| | @@ -119359,11 +119778,11 @@ |
| 119359 | 119778 | |
| 119360 | 119779 | UNUSED_PARAMETER(idxStr); |
| 119361 | 119780 | UNUSED_PARAMETER(nVal); |
| 119362 | 119781 | |
| 119363 | 119782 | assert( idxNum>=0 && idxNum<=(FTS3_FULLTEXT_SEARCH+p->nColumn) ); |
| 119364 | | - assert( nVal==0 || nVal==1 ); |
| 119783 | + assert( nVal==0 || nVal==1 || nVal==2 ); |
| 119365 | 119784 | assert( (nVal==0)==(idxNum==FTS3_FULLSCAN_SEARCH) ); |
| 119366 | 119785 | assert( p->pSegments==0 ); |
| 119367 | 119786 | |
| 119368 | 119787 | /* In case the cursor has been used before, clear it now. */ |
| 119369 | 119788 | sqlite3_finalize(pCsr->pStmt); |
| | @@ -119384,12 +119803,15 @@ |
| 119384 | 119803 | |
| 119385 | 119804 | if( zQuery==0 && sqlite3_value_type(apVal[0])!=SQLITE_NULL ){ |
| 119386 | 119805 | return SQLITE_NOMEM; |
| 119387 | 119806 | } |
| 119388 | 119807 | |
| 119389 | | - rc = sqlite3Fts3ExprParse(p->pTokenizer, p->azColumn, p->bHasStat, |
| 119390 | | - p->nColumn, iCol, zQuery, -1, &pCsr->pExpr |
| 119808 | + pCsr->iLangid = 0; |
| 119809 | + if( nVal==2 ) pCsr->iLangid = sqlite3_value_int(apVal[1]); |
| 119810 | + |
| 119811 | + rc = sqlite3Fts3ExprParse(p->pTokenizer, pCsr->iLangid, |
| 119812 | + p->azColumn, p->bFts4, p->nColumn, iCol, zQuery, -1, &pCsr->pExpr |
| 119391 | 119813 | ); |
| 119392 | 119814 | if( rc!=SQLITE_OK ){ |
| 119393 | 119815 | if( rc==SQLITE_ERROR ){ |
| 119394 | 119816 | static const char *zErr = "malformed MATCH expression: [%s]"; |
| 119395 | 119817 | p->base.zErrMsg = sqlite3_mprintf(zErr, zQuery); |
| | @@ -119456,37 +119878,56 @@ |
| 119456 | 119878 | } |
| 119457 | 119879 | |
| 119458 | 119880 | /* |
| 119459 | 119881 | ** This is the xColumn method, called by SQLite to request a value from |
| 119460 | 119882 | ** the row that the supplied cursor currently points to. |
| 119883 | +** |
| 119884 | +** If: |
| 119885 | +** |
| 119886 | +** (iCol < p->nColumn) -> The value of the iCol'th user column. |
| 119887 | +** (iCol == p->nColumn) -> Magic column with the same name as the table. |
| 119888 | +** (iCol == p->nColumn+1) -> Docid column |
| 119889 | +** (iCol == p->nColumn+2) -> Langid column |
| 119461 | 119890 | */ |
| 119462 | 119891 | static int fts3ColumnMethod( |
| 119463 | 119892 | sqlite3_vtab_cursor *pCursor, /* Cursor to retrieve value from */ |
| 119464 | | - sqlite3_context *pContext, /* Context for sqlite3_result_xxx() calls */ |
| 119893 | + sqlite3_context *pCtx, /* Context for sqlite3_result_xxx() calls */ |
| 119465 | 119894 | int iCol /* Index of column to read value from */ |
| 119466 | 119895 | ){ |
| 119467 | 119896 | int rc = SQLITE_OK; /* Return Code */ |
| 119468 | 119897 | Fts3Cursor *pCsr = (Fts3Cursor *) pCursor; |
| 119469 | 119898 | Fts3Table *p = (Fts3Table *)pCursor->pVtab; |
| 119470 | 119899 | |
| 119471 | 119900 | /* The column value supplied by SQLite must be in range. */ |
| 119472 | | - assert( iCol>=0 && iCol<=p->nColumn+1 ); |
| 119901 | + assert( iCol>=0 && iCol<=p->nColumn+2 ); |
| 119473 | 119902 | |
| 119474 | 119903 | if( iCol==p->nColumn+1 ){ |
| 119475 | 119904 | /* This call is a request for the "docid" column. Since "docid" is an |
| 119476 | 119905 | ** alias for "rowid", use the xRowid() method to obtain the value. |
| 119477 | 119906 | */ |
| 119478 | | - sqlite3_result_int64(pContext, pCsr->iPrevId); |
| 119907 | + sqlite3_result_int64(pCtx, pCsr->iPrevId); |
| 119479 | 119908 | }else if( iCol==p->nColumn ){ |
| 119480 | 119909 | /* The extra column whose name is the same as the table. |
| 119481 | | - ** Return a blob which is a pointer to the cursor. |
| 119482 | | - */ |
| 119483 | | - sqlite3_result_blob(pContext, &pCsr, sizeof(pCsr), SQLITE_TRANSIENT); |
| 119910 | + ** Return a blob which is a pointer to the cursor. */ |
| 119911 | + sqlite3_result_blob(pCtx, &pCsr, sizeof(pCsr), SQLITE_TRANSIENT); |
| 119912 | + }else if( iCol==p->nColumn+2 && pCsr->pExpr ){ |
| 119913 | + sqlite3_result_int64(pCtx, pCsr->iLangid); |
| 119484 | 119914 | }else{ |
| 119915 | + /* The requested column is either a user column (one that contains |
| 119916 | + ** indexed data), or the language-id column. */ |
| 119485 | 119917 | rc = fts3CursorSeek(0, pCsr); |
| 119486 | | - if( rc==SQLITE_OK && sqlite3_data_count(pCsr->pStmt)>(iCol+1) ){ |
| 119487 | | - sqlite3_result_value(pContext, sqlite3_column_value(pCsr->pStmt, iCol+1)); |
| 119918 | + |
| 119919 | + if( rc==SQLITE_OK ){ |
| 119920 | + if( iCol==p->nColumn+2 ){ |
| 119921 | + int iLangid = 0; |
| 119922 | + if( p->zLanguageid ){ |
| 119923 | + iLangid = sqlite3_column_int(pCsr->pStmt, p->nColumn+1); |
| 119924 | + } |
| 119925 | + sqlite3_result_int(pCtx, iLangid); |
| 119926 | + }else if( sqlite3_data_count(pCsr->pStmt)>(iCol+1) ){ |
| 119927 | + sqlite3_result_value(pCtx, sqlite3_column_value(pCsr->pStmt, iCol+1)); |
| 119928 | + } |
| 119488 | 119929 | } |
| 119489 | 119930 | } |
| 119490 | 119931 | |
| 119491 | 119932 | assert( ((Fts3Table *)pCsr->base.pVtab)->pSegments==0 ); |
| 119492 | 119933 | return rc; |
| | @@ -119509,26 +119950,61 @@ |
| 119509 | 119950 | /* |
| 119510 | 119951 | ** Implementation of xSync() method. Flush the contents of the pending-terms |
| 119511 | 119952 | ** hash-table to the database. |
| 119512 | 119953 | */ |
| 119513 | 119954 | static int fts3SyncMethod(sqlite3_vtab *pVtab){ |
| 119514 | | - int rc = sqlite3Fts3PendingTermsFlush((Fts3Table *)pVtab); |
| 119515 | | - sqlite3Fts3SegmentsClose((Fts3Table *)pVtab); |
| 119955 | + |
| 119956 | + /* Following an incremental-merge operation, assuming that the input |
| 119957 | + ** segments are not completely consumed (the usual case), they are updated |
| 119958 | + ** in place to remove the entries that have already been merged. This |
| 119959 | + ** involves updating the leaf block that contains the smallest unmerged |
| 119960 | + ** entry and each block (if any) between the leaf and the root node. So |
| 119961 | + ** if the height of the input segment b-trees is N, and input segments |
| 119962 | + ** are merged eight at a time, updating the input segments at the end |
| 119963 | + ** of an incremental-merge requires writing (8*(1+N)) blocks. N is usually |
| 119964 | + ** small - often between 0 and 2. So the overhead of the incremental |
| 119965 | + ** merge is somewhere between 8 and 24 blocks. To avoid this overhead |
| 119966 | + ** dwarfing the actual productive work accomplished, the incremental merge |
| 119967 | + ** is only attempted if it will write at least 64 leaf blocks. Hence |
| 119968 | + ** nMinMerge. |
| 119969 | + ** |
| 119970 | + ** Of course, updating the input segments also involves deleting a bunch |
| 119971 | + ** of blocks from the segments table. But this is not considered overhead |
| 119972 | + ** as it would also be required by a crisis-merge that used the same input |
| 119973 | + ** segments. |
| 119974 | + */ |
| 119975 | + const u32 nMinMerge = 64; /* Minimum amount of incr-merge work to do */ |
| 119976 | + |
| 119977 | + Fts3Table *p = (Fts3Table*)pVtab; |
| 119978 | + int rc = sqlite3Fts3PendingTermsFlush(p); |
| 119979 | + |
| 119980 | + if( rc==SQLITE_OK && p->bAutoincrmerge==1 && p->nLeafAdd>(nMinMerge/16) ){ |
| 119981 | + int mxLevel = 0; /* Maximum relative level value in db */ |
| 119982 | + int A; /* Incr-merge parameter A */ |
| 119983 | + |
| 119984 | + rc = sqlite3Fts3MaxLevel(p, &mxLevel); |
| 119985 | + assert( rc==SQLITE_OK || mxLevel==0 ); |
| 119986 | + A = p->nLeafAdd * mxLevel; |
| 119987 | + A += (A/2); |
| 119988 | + if( A>(int)nMinMerge ) rc = sqlite3Fts3Incrmerge(p, A, 8); |
| 119989 | + } |
| 119990 | + sqlite3Fts3SegmentsClose(p); |
| 119516 | 119991 | return rc; |
| 119517 | 119992 | } |
| 119518 | 119993 | |
| 119519 | 119994 | /* |
| 119520 | 119995 | ** Implementation of xBegin() method. This is a no-op. |
| 119521 | 119996 | */ |
| 119522 | 119997 | static int fts3BeginMethod(sqlite3_vtab *pVtab){ |
| 119523 | | - TESTONLY( Fts3Table *p = (Fts3Table*)pVtab ); |
| 119998 | + Fts3Table *p = (Fts3Table*)pVtab; |
| 119524 | 119999 | UNUSED_PARAMETER(pVtab); |
| 119525 | 120000 | assert( p->pSegments==0 ); |
| 119526 | 120001 | assert( p->nPendingData==0 ); |
| 119527 | 120002 | assert( p->inTransaction!=1 ); |
| 119528 | 120003 | TESTONLY( p->inTransaction = 1 ); |
| 119529 | 120004 | TESTONLY( p->mxSavepoint = -1; ); |
| 120005 | + p->nLeafAdd = 0; |
| 119530 | 120006 | return SQLITE_OK; |
| 119531 | 120007 | } |
| 119532 | 120008 | |
| 119533 | 120009 | /* |
| 119534 | 120010 | ** Implementation of xCommit() method. This is a no-op. The contents of |
| | @@ -119819,15 +120295,19 @@ |
| 119819 | 120295 | ** The xSavepoint() method. |
| 119820 | 120296 | ** |
| 119821 | 120297 | ** Flush the contents of the pending-terms table to disk. |
| 119822 | 120298 | */ |
| 119823 | 120299 | static int fts3SavepointMethod(sqlite3_vtab *pVtab, int iSavepoint){ |
| 120300 | + int rc = SQLITE_OK; |
| 119824 | 120301 | UNUSED_PARAMETER(iSavepoint); |
| 119825 | 120302 | assert( ((Fts3Table *)pVtab)->inTransaction ); |
| 119826 | 120303 | assert( ((Fts3Table *)pVtab)->mxSavepoint < iSavepoint ); |
| 119827 | 120304 | TESTONLY( ((Fts3Table *)pVtab)->mxSavepoint = iSavepoint ); |
| 119828 | | - return fts3SyncMethod(pVtab); |
| 120305 | + if( ((Fts3Table *)pVtab)->bIgnoreSavepoint==0 ){ |
| 120306 | + rc = fts3SyncMethod(pVtab); |
| 120307 | + } |
| 120308 | + return rc; |
| 119829 | 120309 | } |
| 119830 | 120310 | |
| 119831 | 120311 | /* |
| 119832 | 120312 | ** The xRelease() method. |
| 119833 | 120313 | ** |
| | @@ -120183,11 +120663,11 @@ |
| 120183 | 120663 | |
| 120184 | 120664 | assert( iPrev>=0 ); |
| 120185 | 120665 | fts3PoslistPhraseMerge(&aOut, iToken-iPrev, 0, 1, &p1, &p2); |
| 120186 | 120666 | sqlite3_free(aPoslist); |
| 120187 | 120667 | aPoslist = pList; |
| 120188 | | - nPoslist = aOut - aPoslist; |
| 120668 | + nPoslist = (int)(aOut - aPoslist); |
| 120189 | 120669 | if( nPoslist==0 ){ |
| 120190 | 120670 | sqlite3_free(aPoslist); |
| 120191 | 120671 | pPhrase->doclist.pList = 0; |
| 120192 | 120672 | pPhrase->doclist.nList = 0; |
| 120193 | 120673 | return SQLITE_OK; |
| | @@ -120227,11 +120707,11 @@ |
| 120227 | 120707 | } |
| 120228 | 120708 | |
| 120229 | 120709 | pPhrase->doclist.pList = aOut; |
| 120230 | 120710 | if( fts3PoslistPhraseMerge(&aOut, nDistance, 0, 1, &p1, &p2) ){ |
| 120231 | 120711 | pPhrase->doclist.bFreeList = 1; |
| 120232 | | - pPhrase->doclist.nList = (aOut - pPhrase->doclist.pList); |
| 120712 | + pPhrase->doclist.nList = (int)(aOut - pPhrase->doclist.pList); |
| 120233 | 120713 | }else{ |
| 120234 | 120714 | sqlite3_free(aOut); |
| 120235 | 120715 | pPhrase->doclist.pList = 0; |
| 120236 | 120716 | pPhrase->doclist.nList = 0; |
| 120237 | 120717 | } |
| | @@ -120323,11 +120803,11 @@ |
| 120323 | 120803 | fts3PoslistCopy(0, &pDocid); |
| 120324 | 120804 | while( pDocid<pEnd && *pDocid==0 ) pDocid++; |
| 120325 | 120805 | iMul = (bDescIdx ? -1 : 1); |
| 120326 | 120806 | } |
| 120327 | 120807 | |
| 120328 | | - *pnList = pEnd - pNext; |
| 120808 | + *pnList = (int)(pEnd - pNext); |
| 120329 | 120809 | *ppIter = pNext; |
| 120330 | 120810 | *piDocid = iDocid; |
| 120331 | 120811 | }else{ |
| 120332 | 120812 | int iMul = (bDescIdx ? -1 : 1); |
| 120333 | 120813 | sqlite3_int64 iDelta; |
| | @@ -120337,11 +120817,11 @@ |
| 120337 | 120817 | if( p==aDoclist ){ |
| 120338 | 120818 | *pbEof = 1; |
| 120339 | 120819 | }else{ |
| 120340 | 120820 | char *pSave = p; |
| 120341 | 120821 | fts3ReversePoslist(aDoclist, &p); |
| 120342 | | - *pnList = (pSave - p); |
| 120822 | + *pnList = (int)(pSave - p); |
| 120343 | 120823 | } |
| 120344 | 120824 | *ppIter = p; |
| 120345 | 120825 | } |
| 120346 | 120826 | } |
| 120347 | 120827 | |
| | @@ -120397,11 +120877,11 @@ |
| 120397 | 120877 | }else{ |
| 120398 | 120878 | pDL->iDocid -= iDelta; |
| 120399 | 120879 | } |
| 120400 | 120880 | pDL->pList = pIter; |
| 120401 | 120881 | fts3PoslistCopy(0, &pIter); |
| 120402 | | - pDL->nList = (pIter - pDL->pList); |
| 120882 | + pDL->nList = (int)(pIter - pDL->pList); |
| 120403 | 120883 | |
| 120404 | 120884 | /* pIter now points just past the 0x00 that terminates the position- |
| 120405 | 120885 | ** list for document pDL->iDocid. However, if this position-list was |
| 120406 | 120886 | ** edited in place by fts3EvalNearTrim(), then pIter may not actually |
| 120407 | 120887 | ** point to the start of the next docid value. The following line deals |
| | @@ -120738,11 +121218,11 @@ |
| 120738 | 121218 | |
| 120739 | 121219 | /* Allocate a MultiSegReader for each token in the expression. */ |
| 120740 | 121220 | fts3EvalAllocateReaders(pCsr, pCsr->pExpr, &nToken, &nOr, &rc); |
| 120741 | 121221 | |
| 120742 | 121222 | /* Determine which, if any, tokens in the expression should be deferred. */ |
| 120743 | | - if( rc==SQLITE_OK && nToken>1 && pTab->bHasStat ){ |
| 121223 | + if( rc==SQLITE_OK && nToken>1 && pTab->bFts4 ){ |
| 120744 | 121224 | Fts3TokenAndCost *aTC; |
| 120745 | 121225 | Fts3Expr **apOr; |
| 120746 | 121226 | aTC = (Fts3TokenAndCost *)sqlite3_malloc( |
| 120747 | 121227 | sizeof(Fts3TokenAndCost) * nToken |
| 120748 | 121228 | + sizeof(Fts3Expr *) * nOr * 2 |
| | @@ -120755,12 +121235,12 @@ |
| 120755 | 121235 | int ii; |
| 120756 | 121236 | Fts3TokenAndCost *pTC = aTC; |
| 120757 | 121237 | Fts3Expr **ppOr = apOr; |
| 120758 | 121238 | |
| 120759 | 121239 | fts3EvalTokenCosts(pCsr, 0, pCsr->pExpr, &pTC, &ppOr, &rc); |
| 120760 | | - nToken = pTC-aTC; |
| 120761 | | - nOr = ppOr-apOr; |
| 121240 | + nToken = (int)(pTC-aTC); |
| 121241 | + nOr = (int)(ppOr-apOr); |
| 120762 | 121242 | |
| 120763 | 121243 | if( rc==SQLITE_OK ){ |
| 120764 | 121244 | rc = fts3EvalSelectDeferred(pCsr, 0, aTC, nToken); |
| 120765 | 121245 | for(ii=0; rc==SQLITE_OK && ii<nOr; ii++){ |
| 120766 | 121246 | rc = fts3EvalSelectDeferred(pCsr, apOr[ii], aTC, nToken); |
| | @@ -120828,11 +121308,11 @@ |
| 120828 | 121308 | p2 = pOut = pPhrase->doclist.pList; |
| 120829 | 121309 | res = fts3PoslistNearMerge( |
| 120830 | 121310 | &pOut, aTmp, nParam1, nParam2, paPoslist, &p2 |
| 120831 | 121311 | ); |
| 120832 | 121312 | if( res ){ |
| 120833 | | - nNew = (pOut - pPhrase->doclist.pList) - 1; |
| 121313 | + nNew = (int)(pOut - pPhrase->doclist.pList) - 1; |
| 120834 | 121314 | assert( pPhrase->doclist.pList[nNew]=='\0' ); |
| 120835 | 121315 | assert( nNew<=pPhrase->doclist.nList && nNew>0 ); |
| 120836 | 121316 | memset(&pPhrase->doclist.pList[nNew], 0, pPhrase->doclist.nList - nNew); |
| 120837 | 121317 | pPhrase->doclist.nList = nNew; |
| 120838 | 121318 | *paPoslist = pPhrase->doclist.pList; |
| | @@ -121553,10 +122033,11 @@ |
| 121553 | 122033 | fts3SegReaderCursorFree(pPhrase->aToken[i].pSegcsr); |
| 121554 | 122034 | pPhrase->aToken[i].pSegcsr = 0; |
| 121555 | 122035 | } |
| 121556 | 122036 | } |
| 121557 | 122037 | } |
| 122038 | + |
| 121558 | 122039 | |
| 121559 | 122040 | /* |
| 121560 | 122041 | ** Return SQLITE_CORRUPT_VTAB. |
| 121561 | 122042 | */ |
| 121562 | 122043 | #ifdef SQLITE_DEBUG |
| | @@ -121661,13 +122142,13 @@ |
| 121661 | 122142 | ); |
| 121662 | 122143 | return SQLITE_ERROR; |
| 121663 | 122144 | } |
| 121664 | 122145 | |
| 121665 | 122146 | zDb = argv[1]; |
| 121666 | | - nDb = strlen(zDb); |
| 122147 | + nDb = (int)strlen(zDb); |
| 121667 | 122148 | zFts3 = argv[3]; |
| 121668 | | - nFts3 = strlen(zFts3); |
| 122149 | + nFts3 = (int)strlen(zFts3); |
| 121669 | 122150 | |
| 121670 | 122151 | rc = sqlite3_declare_vtab(db, FTS3_TERMS_SCHEMA); |
| 121671 | 122152 | if( rc!=SQLITE_OK ) return rc; |
| 121672 | 122153 | |
| 121673 | 122154 | nByte = sizeof(Fts3auxTable) + sizeof(Fts3Table) + nDb + nFts3 + 2; |
| | @@ -121958,11 +122439,11 @@ |
| 121958 | 122439 | pCsr->zStop = sqlite3_mprintf("%s", sqlite3_value_text(apVal[iIdx])); |
| 121959 | 122440 | pCsr->nStop = sqlite3_value_bytes(apVal[iIdx]); |
| 121960 | 122441 | if( pCsr->zStop==0 ) return SQLITE_NOMEM; |
| 121961 | 122442 | } |
| 121962 | 122443 | |
| 121963 | | - rc = sqlite3Fts3SegReaderCursor(pFts3, 0, FTS3_SEGCURSOR_ALL, |
| 122444 | + rc = sqlite3Fts3SegReaderCursor(pFts3, 0, 0, FTS3_SEGCURSOR_ALL, |
| 121964 | 122445 | pCsr->filter.zTerm, pCsr->filter.nTerm, 0, isScan, &pCsr->csr |
| 121965 | 122446 | ); |
| 121966 | 122447 | if( rc==SQLITE_OK ){ |
| 121967 | 122448 | rc = sqlite3Fts3SegReaderStart(pFts3, &pCsr->csr, &pCsr->filter); |
| 121968 | 122449 | } |
| | @@ -122150,10 +122631,11 @@ |
| 122150 | 122631 | ** zero. |
| 122151 | 122632 | */ |
| 122152 | 122633 | typedef struct ParseContext ParseContext; |
| 122153 | 122634 | struct ParseContext { |
| 122154 | 122635 | sqlite3_tokenizer *pTokenizer; /* Tokenizer module */ |
| 122636 | + int iLangid; /* Language id used with tokenizer */ |
| 122155 | 122637 | const char **azCol; /* Array of column names for fts3 table */ |
| 122156 | 122638 | int bFts4; /* True to allow FTS4-only syntax */ |
| 122157 | 122639 | int nCol; /* Number of entries in azCol[] */ |
| 122158 | 122640 | int iDefaultCol; /* Default column to query */ |
| 122159 | 122641 | int isNot; /* True if getNextNode() sees a unary - */ |
| | @@ -122185,10 +122667,37 @@ |
| 122185 | 122667 | void *pRet = sqlite3_malloc(nByte); |
| 122186 | 122668 | if( pRet ) memset(pRet, 0, nByte); |
| 122187 | 122669 | return pRet; |
| 122188 | 122670 | } |
| 122189 | 122671 | |
| 122672 | +SQLITE_PRIVATE int sqlite3Fts3OpenTokenizer( |
| 122673 | + sqlite3_tokenizer *pTokenizer, |
| 122674 | + int iLangid, |
| 122675 | + const char *z, |
| 122676 | + int n, |
| 122677 | + sqlite3_tokenizer_cursor **ppCsr |
| 122678 | +){ |
| 122679 | + sqlite3_tokenizer_module const *pModule = pTokenizer->pModule; |
| 122680 | + sqlite3_tokenizer_cursor *pCsr = 0; |
| 122681 | + int rc; |
| 122682 | + |
| 122683 | + rc = pModule->xOpen(pTokenizer, z, n, &pCsr); |
| 122684 | + assert( rc==SQLITE_OK || pCsr==0 ); |
| 122685 | + if( rc==SQLITE_OK ){ |
| 122686 | + pCsr->pTokenizer = pTokenizer; |
| 122687 | + if( pModule->iVersion>=1 ){ |
| 122688 | + rc = pModule->xLanguageid(pCsr, iLangid); |
| 122689 | + if( rc!=SQLITE_OK ){ |
| 122690 | + pModule->xClose(pCsr); |
| 122691 | + pCsr = 0; |
| 122692 | + } |
| 122693 | + } |
| 122694 | + } |
| 122695 | + *ppCsr = pCsr; |
| 122696 | + return rc; |
| 122697 | +} |
| 122698 | + |
| 122190 | 122699 | |
| 122191 | 122700 | /* |
| 122192 | 122701 | ** Extract the next token from buffer z (length n) using the tokenizer |
| 122193 | 122702 | ** and other information (column names etc.) in pParse. Create an Fts3Expr |
| 122194 | 122703 | ** structure of type FTSQUERY_PHRASE containing a phrase consisting of this |
| | @@ -122212,19 +122721,17 @@ |
| 122212 | 122721 | int rc; |
| 122213 | 122722 | sqlite3_tokenizer_cursor *pCursor; |
| 122214 | 122723 | Fts3Expr *pRet = 0; |
| 122215 | 122724 | int nConsumed = 0; |
| 122216 | 122725 | |
| 122217 | | - rc = pModule->xOpen(pTokenizer, z, n, &pCursor); |
| 122726 | + rc = sqlite3Fts3OpenTokenizer(pTokenizer, pParse->iLangid, z, n, &pCursor); |
| 122218 | 122727 | if( rc==SQLITE_OK ){ |
| 122219 | 122728 | const char *zToken; |
| 122220 | 122729 | int nToken, iStart, iEnd, iPosition; |
| 122221 | 122730 | int nByte; /* total space to allocate */ |
| 122222 | 122731 | |
| 122223 | | - pCursor->pTokenizer = pTokenizer; |
| 122224 | 122732 | rc = pModule->xNext(pCursor, &zToken, &nToken, &iStart, &iEnd, &iPosition); |
| 122225 | | - |
| 122226 | 122733 | if( rc==SQLITE_OK ){ |
| 122227 | 122734 | nByte = sizeof(Fts3Expr) + sizeof(Fts3Phrase) + nToken; |
| 122228 | 122735 | pRet = (Fts3Expr *)fts3MallocZero(nByte); |
| 122229 | 122736 | if( !pRet ){ |
| 122230 | 122737 | rc = SQLITE_NOMEM; |
| | @@ -122326,14 +122833,14 @@ |
| 122326 | 122833 | ** |
| 122327 | 122834 | ** The second pass, in the block that begins "if( rc==SQLITE_DONE )" below, |
| 122328 | 122835 | ** appends buffer zTemp to buffer p, and fills in the Fts3Expr and Fts3Phrase |
| 122329 | 122836 | ** structures. |
| 122330 | 122837 | */ |
| 122331 | | - rc = pModule->xOpen(pTokenizer, zInput, nInput, &pCursor); |
| 122838 | + rc = sqlite3Fts3OpenTokenizer( |
| 122839 | + pTokenizer, pParse->iLangid, zInput, nInput, &pCursor); |
| 122332 | 122840 | if( rc==SQLITE_OK ){ |
| 122333 | 122841 | int ii; |
| 122334 | | - pCursor->pTokenizer = pTokenizer; |
| 122335 | 122842 | for(ii=0; rc==SQLITE_OK; ii++){ |
| 122336 | 122843 | const char *zByte; |
| 122337 | 122844 | int nByte, iBegin, iEnd, iPos; |
| 122338 | 122845 | rc = pModule->xNext(pCursor, &zByte, &nByte, &iBegin, &iEnd, &iPos); |
| 122339 | 122846 | if( rc==SQLITE_OK ){ |
| | @@ -122803,10 +123310,11 @@ |
| 122803 | 123310 | ** specified as part of the query string), or -1 if tokens may by default |
| 122804 | 123311 | ** match any table column. |
| 122805 | 123312 | */ |
| 122806 | 123313 | SQLITE_PRIVATE int sqlite3Fts3ExprParse( |
| 122807 | 123314 | sqlite3_tokenizer *pTokenizer, /* Tokenizer module */ |
| 123315 | + int iLangid, /* Language id for tokenizer */ |
| 122808 | 123316 | char **azCol, /* Array of column names for fts3 table */ |
| 122809 | 123317 | int bFts4, /* True to allow FTS4-only syntax */ |
| 122810 | 123318 | int nCol, /* Number of entries in azCol[] */ |
| 122811 | 123319 | int iDefaultCol, /* Default column to query */ |
| 122812 | 123320 | const char *z, int n, /* Text of MATCH query */ |
| | @@ -122813,15 +123321,17 @@ |
| 122813 | 123321 | Fts3Expr **ppExpr /* OUT: Parsed query structure */ |
| 122814 | 123322 | ){ |
| 122815 | 123323 | int nParsed; |
| 122816 | 123324 | int rc; |
| 122817 | 123325 | ParseContext sParse; |
| 123326 | + |
| 123327 | + memset(&sParse, 0, sizeof(ParseContext)); |
| 122818 | 123328 | sParse.pTokenizer = pTokenizer; |
| 123329 | + sParse.iLangid = iLangid; |
| 122819 | 123330 | sParse.azCol = (const char **)azCol; |
| 122820 | 123331 | sParse.nCol = nCol; |
| 122821 | 123332 | sParse.iDefaultCol = iDefaultCol; |
| 122822 | | - sParse.nNest = 0; |
| 122823 | 123333 | sParse.bFts4 = bFts4; |
| 122824 | 123334 | if( z==0 ){ |
| 122825 | 123335 | *ppExpr = 0; |
| 122826 | 123336 | return SQLITE_OK; |
| 122827 | 123337 | } |
| | @@ -123008,11 +123518,11 @@ |
| 123008 | 123518 | for(ii=0; ii<nCol; ii++){ |
| 123009 | 123519 | azCol[ii] = (char *)sqlite3_value_text(argv[ii+2]); |
| 123010 | 123520 | } |
| 123011 | 123521 | |
| 123012 | 123522 | rc = sqlite3Fts3ExprParse( |
| 123013 | | - pTokenizer, azCol, 0, nCol, nCol, zExpr, nExpr, &pExpr |
| 123523 | + pTokenizer, 0, azCol, 0, nCol, nCol, zExpr, nExpr, &pExpr |
| 123014 | 123524 | ); |
| 123015 | 123525 | if( rc!=SQLITE_OK && rc!=SQLITE_NOMEM ){ |
| 123016 | 123526 | sqlite3_result_error(context, "Error parsing expression", -1); |
| 123017 | 123527 | }else if( rc==SQLITE_NOMEM || !(zBuf = exprToString(pExpr, 0)) ){ |
| 123018 | 123528 | sqlite3_result_error_nomem(context); |
| | @@ -124057,10 +124567,11 @@ |
| 124057 | 124567 | porterCreate, |
| 124058 | 124568 | porterDestroy, |
| 124059 | 124569 | porterOpen, |
| 124060 | 124570 | porterClose, |
| 124061 | 124571 | porterNext, |
| 124572 | + 0 |
| 124062 | 124573 | }; |
| 124063 | 124574 | |
| 124064 | 124575 | /* |
| 124065 | 124576 | ** Allocate a new porter tokenizer. Return a pointer to the new |
| 124066 | 124577 | ** tokenizer in *ppModule |
| | @@ -124362,15 +124873,14 @@ |
| 124362 | 124873 | if( SQLITE_OK!=p->xCreate(zArg ? 1 : 0, &zArg, &pTokenizer) ){ |
| 124363 | 124874 | zErr = "error in xCreate()"; |
| 124364 | 124875 | goto finish; |
| 124365 | 124876 | } |
| 124366 | 124877 | pTokenizer->pModule = p; |
| 124367 | | - if( SQLITE_OK!=p->xOpen(pTokenizer, zInput, nInput, &pCsr) ){ |
| 124878 | + if( sqlite3Fts3OpenTokenizer(pTokenizer, 0, zInput, nInput, &pCsr) ){ |
| 124368 | 124879 | zErr = "error in xOpen()"; |
| 124369 | 124880 | goto finish; |
| 124370 | 124881 | } |
| 124371 | | - pCsr->pTokenizer = pTokenizer; |
| 124372 | 124882 | |
| 124373 | 124883 | while( SQLITE_OK==p->xNext(pCsr, &zToken, &nToken, &iStart, &iEnd, &iPos) ){ |
| 124374 | 124884 | Tcl_ListObjAppendElement(0, pRet, Tcl_NewIntObj(iPos)); |
| 124375 | 124885 | Tcl_ListObjAppendElement(0, pRet, Tcl_NewStringObj(zToken, nToken)); |
| 124376 | 124886 | zToken = &zInput[iStart]; |
| | @@ -124782,10 +125292,11 @@ |
| 124782 | 125292 | simpleCreate, |
| 124783 | 125293 | simpleDestroy, |
| 124784 | 125294 | simpleOpen, |
| 124785 | 125295 | simpleClose, |
| 124786 | 125296 | simpleNext, |
| 125297 | + 0, |
| 124787 | 125298 | }; |
| 124788 | 125299 | |
| 124789 | 125300 | /* |
| 124790 | 125301 | ** Allocate a new simple tokenizer. Return a pointer to the new |
| 124791 | 125302 | ** tokenizer in *ppModule |
| | @@ -124823,10 +125334,13 @@ |
| 124823 | 125334 | |
| 124824 | 125335 | /* #include <string.h> */ |
| 124825 | 125336 | /* #include <assert.h> */ |
| 124826 | 125337 | /* #include <stdlib.h> */ |
| 124827 | 125338 | |
| 125339 | + |
| 125340 | +#define FTS_MAX_APPENDABLE_HEIGHT 16 |
| 125341 | + |
| 124828 | 125342 | /* |
| 124829 | 125343 | ** When full-text index nodes are loaded from disk, the buffer that they |
| 124830 | 125344 | ** are loaded into has the following number of bytes of padding at the end |
| 124831 | 125345 | ** of it. i.e. if a full-text index node is 900 bytes in size, then a buffer |
| 124832 | 125346 | ** of 920 bytes is allocated for it. |
| | @@ -124861,10 +125375,33 @@ |
| 124861 | 125375 | # define FTS3_NODE_CHUNK_THRESHOLD test_fts3_node_chunk_threshold |
| 124862 | 125376 | #else |
| 124863 | 125377 | # define FTS3_NODE_CHUNKSIZE (4*1024) |
| 124864 | 125378 | # define FTS3_NODE_CHUNK_THRESHOLD (FTS3_NODE_CHUNKSIZE*4) |
| 124865 | 125379 | #endif |
| 125380 | + |
| 125381 | +/* |
| 125382 | +** The two values that may be meaningfully bound to the :1 parameter in |
| 125383 | +** statements SQL_REPLACE_STAT and SQL_SELECT_STAT. |
| 125384 | +*/ |
| 125385 | +#define FTS_STAT_DOCTOTAL 0 |
| 125386 | +#define FTS_STAT_INCRMERGEHINT 1 |
| 125387 | +#define FTS_STAT_AUTOINCRMERGE 2 |
| 125388 | + |
| 125389 | +/* |
| 125390 | +** If FTS_LOG_MERGES is defined, call sqlite3_log() to report each automatic |
| 125391 | +** and incremental merge operation that takes place. This is used for |
| 125392 | +** debugging FTS only, it should not usually be turned on in production |
| 125393 | +** systems. |
| 125394 | +*/ |
| 125395 | +#ifdef FTS3_LOG_MERGES |
| 125396 | +static void fts3LogMerge(int nMerge, sqlite3_int64 iAbsLevel){ |
| 125397 | + sqlite3_log(SQLITE_OK, "%d-way merge from level %d", nMerge, (int)iAbsLevel); |
| 125398 | +} |
| 125399 | +#else |
| 125400 | +#define fts3LogMerge(x, y) |
| 125401 | +#endif |
| 125402 | + |
| 124866 | 125403 | |
| 124867 | 125404 | typedef struct PendingList PendingList; |
| 124868 | 125405 | typedef struct SegmentNode SegmentNode; |
| 124869 | 125406 | typedef struct SegmentWriter SegmentWriter; |
| 124870 | 125407 | |
| | @@ -125023,17 +125560,26 @@ |
| 125023 | 125560 | #define SQL_DELETE_SEGMENTS_RANGE 17 |
| 125024 | 125561 | #define SQL_CONTENT_INSERT 18 |
| 125025 | 125562 | #define SQL_DELETE_DOCSIZE 19 |
| 125026 | 125563 | #define SQL_REPLACE_DOCSIZE 20 |
| 125027 | 125564 | #define SQL_SELECT_DOCSIZE 21 |
| 125028 | | -#define SQL_SELECT_DOCTOTAL 22 |
| 125029 | | -#define SQL_REPLACE_DOCTOTAL 23 |
| 125565 | +#define SQL_SELECT_STAT 22 |
| 125566 | +#define SQL_REPLACE_STAT 23 |
| 125030 | 125567 | |
| 125031 | 125568 | #define SQL_SELECT_ALL_PREFIX_LEVEL 24 |
| 125032 | 125569 | #define SQL_DELETE_ALL_TERMS_SEGDIR 25 |
| 125033 | | - |
| 125034 | 125570 | #define SQL_DELETE_SEGDIR_RANGE 26 |
| 125571 | +#define SQL_SELECT_ALL_LANGID 27 |
| 125572 | +#define SQL_FIND_MERGE_LEVEL 28 |
| 125573 | +#define SQL_MAX_LEAF_NODE_ESTIMATE 29 |
| 125574 | +#define SQL_DELETE_SEGDIR_ENTRY 30 |
| 125575 | +#define SQL_SHIFT_SEGDIR_ENTRY 31 |
| 125576 | +#define SQL_SELECT_SEGDIR 32 |
| 125577 | +#define SQL_CHOMP_SEGDIR 33 |
| 125578 | +#define SQL_SEGMENT_IS_APPENDABLE 34 |
| 125579 | +#define SQL_SELECT_INDEXES 35 |
| 125580 | +#define SQL_SELECT_MXLEVEL 36 |
| 125035 | 125581 | |
| 125036 | 125582 | /* |
| 125037 | 125583 | ** This function is used to obtain an SQLite prepared statement handle |
| 125038 | 125584 | ** for the statement identified by the second argument. If successful, |
| 125039 | 125585 | ** *pp is set to the requested statement handle and SQLITE_OK returned. |
| | @@ -125058,13 +125604,13 @@ |
| 125058 | 125604 | /* 4 */ "DELETE FROM %Q.'%q_segdir'", |
| 125059 | 125605 | /* 5 */ "DELETE FROM %Q.'%q_docsize'", |
| 125060 | 125606 | /* 6 */ "DELETE FROM %Q.'%q_stat'", |
| 125061 | 125607 | /* 7 */ "SELECT %s WHERE rowid=?", |
| 125062 | 125608 | /* 8 */ "SELECT (SELECT max(idx) FROM %Q.'%q_segdir' WHERE level = ?) + 1", |
| 125063 | | -/* 9 */ "INSERT INTO %Q.'%q_segments'(blockid, block) VALUES(?, ?)", |
| 125609 | +/* 9 */ "REPLACE INTO %Q.'%q_segments'(blockid, block) VALUES(?, ?)", |
| 125064 | 125610 | /* 10 */ "SELECT coalesce((SELECT max(blockid) FROM %Q.'%q_segments') + 1, 1)", |
| 125065 | | -/* 11 */ "INSERT INTO %Q.'%q_segdir' VALUES(?,?,?,?,?,?)", |
| 125611 | +/* 11 */ "REPLACE INTO %Q.'%q_segdir' VALUES(?,?,?,?,?,?)", |
| 125066 | 125612 | |
| 125067 | 125613 | /* Return segments in order from oldest to newest.*/ |
| 125068 | 125614 | /* 12 */ "SELECT idx, start_block, leaves_end_block, end_block, root " |
| 125069 | 125615 | "FROM %Q.'%q_segdir' WHERE level = ? ORDER BY idx ASC", |
| 125070 | 125616 | /* 13 */ "SELECT idx, start_block, leaves_end_block, end_block, root " |
| | @@ -125078,17 +125624,65 @@ |
| 125078 | 125624 | /* 17 */ "DELETE FROM %Q.'%q_segments' WHERE blockid BETWEEN ? AND ?", |
| 125079 | 125625 | /* 18 */ "INSERT INTO %Q.'%q_content' VALUES(%s)", |
| 125080 | 125626 | /* 19 */ "DELETE FROM %Q.'%q_docsize' WHERE docid = ?", |
| 125081 | 125627 | /* 20 */ "REPLACE INTO %Q.'%q_docsize' VALUES(?,?)", |
| 125082 | 125628 | /* 21 */ "SELECT size FROM %Q.'%q_docsize' WHERE docid=?", |
| 125083 | | -/* 22 */ "SELECT value FROM %Q.'%q_stat' WHERE id=0", |
| 125084 | | -/* 23 */ "REPLACE INTO %Q.'%q_stat' VALUES(0,?)", |
| 125629 | +/* 22 */ "SELECT value FROM %Q.'%q_stat' WHERE id=?", |
| 125630 | +/* 23 */ "REPLACE INTO %Q.'%q_stat' VALUES(?,?)", |
| 125085 | 125631 | /* 24 */ "", |
| 125086 | 125632 | /* 25 */ "", |
| 125087 | 125633 | |
| 125088 | 125634 | /* 26 */ "DELETE FROM %Q.'%q_segdir' WHERE level BETWEEN ? AND ?", |
| 125635 | +/* 27 */ "SELECT DISTINCT level / (1024 * ?) FROM %Q.'%q_segdir'", |
| 125089 | 125636 | |
| 125637 | +/* This statement is used to determine which level to read the input from |
| 125638 | +** when performing an incremental merge. It returns the absolute level number |
| 125639 | +** of the oldest level in the db that contains at least ? segments. Or, |
| 125640 | +** if no level in the FTS index contains more than ? segments, the statement |
| 125641 | +** returns zero rows. */ |
| 125642 | +/* 28 */ "SELECT level FROM %Q.'%q_segdir' GROUP BY level HAVING count(*)>=?" |
| 125643 | + " ORDER BY (level %% 1024) ASC LIMIT 1", |
| 125644 | + |
| 125645 | +/* Estimate the upper limit on the number of leaf nodes in a new segment |
| 125646 | +** created by merging the oldest :2 segments from absolute level :1. See |
| 125647 | +** function sqlite3Fts3Incrmerge() for details. */ |
| 125648 | +/* 29 */ "SELECT 2 * total(1 + leaves_end_block - start_block) " |
| 125649 | + " FROM %Q.'%q_segdir' WHERE level = ? AND idx < ?", |
| 125650 | + |
| 125651 | +/* SQL_DELETE_SEGDIR_ENTRY |
| 125652 | +** Delete the %_segdir entry on absolute level :1 with index :2. */ |
| 125653 | +/* 30 */ "DELETE FROM %Q.'%q_segdir' WHERE level = ? AND idx = ?", |
| 125654 | + |
| 125655 | +/* SQL_SHIFT_SEGDIR_ENTRY |
| 125656 | +** Modify the idx value for the segment with idx=:3 on absolute level :2 |
| 125657 | +** to :1. */ |
| 125658 | +/* 31 */ "UPDATE %Q.'%q_segdir' SET idx = ? WHERE level=? AND idx=?", |
| 125659 | + |
| 125660 | +/* SQL_SELECT_SEGDIR |
| 125661 | +** Read a single entry from the %_segdir table. The entry from absolute |
| 125662 | +** level :1 with index value :2. */ |
| 125663 | +/* 32 */ "SELECT idx, start_block, leaves_end_block, end_block, root " |
| 125664 | + "FROM %Q.'%q_segdir' WHERE level = ? AND idx = ?", |
| 125665 | + |
| 125666 | +/* SQL_CHOMP_SEGDIR |
| 125667 | +** Update the start_block (:1) and root (:2) fields of the %_segdir |
| 125668 | +** entry located on absolute level :3 with index :4. */ |
| 125669 | +/* 33 */ "UPDATE %Q.'%q_segdir' SET start_block = ?, root = ?" |
| 125670 | + "WHERE level = ? AND idx = ?", |
| 125671 | + |
| 125672 | +/* SQL_SEGMENT_IS_APPENDABLE |
| 125673 | +** Return a single row if the segment with end_block=? is appendable. Or |
| 125674 | +** no rows otherwise. */ |
| 125675 | +/* 34 */ "SELECT 1 FROM %Q.'%q_segments' WHERE blockid=? AND block IS NULL", |
| 125676 | + |
| 125677 | +/* SQL_SELECT_INDEXES |
| 125678 | +** Return the list of valid segment indexes for absolute level ? */ |
| 125679 | +/* 35 */ "SELECT idx FROM %Q.'%q_segdir' WHERE level=? ORDER BY 1 ASC", |
| 125680 | + |
| 125681 | +/* SQL_SELECT_MXLEVEL |
| 125682 | +** Return the largest relative level in the FTS index or indexes. */ |
| 125683 | +/* 36 */ "SELECT max( level %% 1024 ) FROM %Q.'%q_segdir'" |
| 125090 | 125684 | }; |
| 125091 | 125685 | int rc = SQLITE_OK; |
| 125092 | 125686 | sqlite3_stmt *pStmt; |
| 125093 | 125687 | |
| 125094 | 125688 | assert( SizeofArray(azSql)==SizeofArray(p->aStmt) ); |
| | @@ -125121,27 +125715,23 @@ |
| 125121 | 125715 | } |
| 125122 | 125716 | } |
| 125123 | 125717 | *pp = pStmt; |
| 125124 | 125718 | return rc; |
| 125125 | 125719 | } |
| 125720 | + |
| 125126 | 125721 | |
| 125127 | 125722 | static int fts3SelectDocsize( |
| 125128 | 125723 | Fts3Table *pTab, /* FTS3 table handle */ |
| 125129 | | - int eStmt, /* Either SQL_SELECT_DOCSIZE or DOCTOTAL */ |
| 125130 | 125724 | sqlite3_int64 iDocid, /* Docid to bind for SQL_SELECT_DOCSIZE */ |
| 125131 | 125725 | sqlite3_stmt **ppStmt /* OUT: Statement handle */ |
| 125132 | 125726 | ){ |
| 125133 | 125727 | sqlite3_stmt *pStmt = 0; /* Statement requested from fts3SqlStmt() */ |
| 125134 | 125728 | int rc; /* Return code */ |
| 125135 | 125729 | |
| 125136 | | - assert( eStmt==SQL_SELECT_DOCSIZE || eStmt==SQL_SELECT_DOCTOTAL ); |
| 125137 | | - |
| 125138 | | - rc = fts3SqlStmt(pTab, eStmt, &pStmt, 0); |
| 125730 | + rc = fts3SqlStmt(pTab, SQL_SELECT_DOCSIZE, &pStmt, 0); |
| 125139 | 125731 | if( rc==SQLITE_OK ){ |
| 125140 | | - if( eStmt==SQL_SELECT_DOCSIZE ){ |
| 125141 | | - sqlite3_bind_int64(pStmt, 1, iDocid); |
| 125142 | | - } |
| 125732 | + sqlite3_bind_int64(pStmt, 1, iDocid); |
| 125143 | 125733 | rc = sqlite3_step(pStmt); |
| 125144 | 125734 | if( rc!=SQLITE_ROW || sqlite3_column_type(pStmt, 0)!=SQLITE_BLOB ){ |
| 125145 | 125735 | rc = sqlite3_reset(pStmt); |
| 125146 | 125736 | if( rc==SQLITE_OK ) rc = FTS_CORRUPT_VTAB; |
| 125147 | 125737 | pStmt = 0; |
| | @@ -125156,19 +125746,33 @@ |
| 125156 | 125746 | |
| 125157 | 125747 | SQLITE_PRIVATE int sqlite3Fts3SelectDoctotal( |
| 125158 | 125748 | Fts3Table *pTab, /* Fts3 table handle */ |
| 125159 | 125749 | sqlite3_stmt **ppStmt /* OUT: Statement handle */ |
| 125160 | 125750 | ){ |
| 125161 | | - return fts3SelectDocsize(pTab, SQL_SELECT_DOCTOTAL, 0, ppStmt); |
| 125751 | + sqlite3_stmt *pStmt = 0; |
| 125752 | + int rc; |
| 125753 | + rc = fts3SqlStmt(pTab, SQL_SELECT_STAT, &pStmt, 0); |
| 125754 | + if( rc==SQLITE_OK ){ |
| 125755 | + sqlite3_bind_int(pStmt, 1, FTS_STAT_DOCTOTAL); |
| 125756 | + if( sqlite3_step(pStmt)!=SQLITE_ROW |
| 125757 | + || sqlite3_column_type(pStmt, 0)!=SQLITE_BLOB |
| 125758 | + ){ |
| 125759 | + rc = sqlite3_reset(pStmt); |
| 125760 | + if( rc==SQLITE_OK ) rc = FTS_CORRUPT_VTAB; |
| 125761 | + pStmt = 0; |
| 125762 | + } |
| 125763 | + } |
| 125764 | + *ppStmt = pStmt; |
| 125765 | + return rc; |
| 125162 | 125766 | } |
| 125163 | 125767 | |
| 125164 | 125768 | SQLITE_PRIVATE int sqlite3Fts3SelectDocsize( |
| 125165 | 125769 | Fts3Table *pTab, /* Fts3 table handle */ |
| 125166 | 125770 | sqlite3_int64 iDocid, /* Docid to read size data for */ |
| 125167 | 125771 | sqlite3_stmt **ppStmt /* OUT: Statement handle */ |
| 125168 | 125772 | ){ |
| 125169 | | - return fts3SelectDocsize(pTab, SQL_SELECT_DOCSIZE, iDocid, ppStmt); |
| 125773 | + return fts3SelectDocsize(pTab, iDocid, ppStmt); |
| 125170 | 125774 | } |
| 125171 | 125775 | |
| 125172 | 125776 | /* |
| 125173 | 125777 | ** Similar to fts3SqlStmt(). Except, after binding the parameters in |
| 125174 | 125778 | ** array apVal[] to the SQL statement identified by eStmt, the statement |
| | @@ -125229,10 +125833,48 @@ |
| 125229 | 125833 | rc = SQLITE_OK; |
| 125230 | 125834 | } |
| 125231 | 125835 | |
| 125232 | 125836 | return rc; |
| 125233 | 125837 | } |
| 125838 | + |
| 125839 | +/* |
| 125840 | +** FTS maintains a separate indexes for each language-id (a 32-bit integer). |
| 125841 | +** Within each language id, a separate index is maintained to store the |
| 125842 | +** document terms, and each configured prefix size (configured the FTS |
| 125843 | +** "prefix=" option). And each index consists of multiple levels ("relative |
| 125844 | +** levels"). |
| 125845 | +** |
| 125846 | +** All three of these values (the language id, the specific index and the |
| 125847 | +** level within the index) are encoded in 64-bit integer values stored |
| 125848 | +** in the %_segdir table on disk. This function is used to convert three |
| 125849 | +** separate component values into the single 64-bit integer value that |
| 125850 | +** can be used to query the %_segdir table. |
| 125851 | +** |
| 125852 | +** Specifically, each language-id/index combination is allocated 1024 |
| 125853 | +** 64-bit integer level values ("absolute levels"). The main terms index |
| 125854 | +** for language-id 0 is allocate values 0-1023. The first prefix index |
| 125855 | +** (if any) for language-id 0 is allocated values 1024-2047. And so on. |
| 125856 | +** Language 1 indexes are allocated immediately following language 0. |
| 125857 | +** |
| 125858 | +** So, for a system with nPrefix prefix indexes configured, the block of |
| 125859 | +** absolute levels that corresponds to language-id iLangid and index |
| 125860 | +** iIndex starts at absolute level ((iLangid * (nPrefix+1) + iIndex) * 1024). |
| 125861 | +*/ |
| 125862 | +static sqlite3_int64 getAbsoluteLevel( |
| 125863 | + Fts3Table *p, /* FTS3 table handle */ |
| 125864 | + int iLangid, /* Language id */ |
| 125865 | + int iIndex, /* Index in p->aIndex[] */ |
| 125866 | + int iLevel /* Level of segments */ |
| 125867 | +){ |
| 125868 | + sqlite3_int64 iBase; /* First absolute level for iLangid/iIndex */ |
| 125869 | + assert( iLangid>=0 ); |
| 125870 | + assert( p->nIndex>0 ); |
| 125871 | + assert( iIndex>=0 && iIndex<p->nIndex ); |
| 125872 | + |
| 125873 | + iBase = ((sqlite3_int64)iLangid * p->nIndex + iIndex) * FTS3_SEGDIR_MAXLEVEL; |
| 125874 | + return iBase + iLevel; |
| 125875 | +} |
| 125234 | 125876 | |
| 125235 | 125877 | /* |
| 125236 | 125878 | ** Set *ppStmt to a statement handle that may be used to iterate through |
| 125237 | 125879 | ** all rows in the %_segdir table, from oldest to newest. If successful, |
| 125238 | 125880 | ** return SQLITE_OK. If an error occurs while preparing the statement, |
| | @@ -125249,12 +125891,13 @@ |
| 125249 | 125891 | ** 3: end_block |
| 125250 | 125892 | ** 4: root |
| 125251 | 125893 | */ |
| 125252 | 125894 | SQLITE_PRIVATE int sqlite3Fts3AllSegdirs( |
| 125253 | 125895 | Fts3Table *p, /* FTS3 table */ |
| 125896 | + int iLangid, /* Language being queried */ |
| 125254 | 125897 | int iIndex, /* Index for p->aIndex[] */ |
| 125255 | | - int iLevel, /* Level to select */ |
| 125898 | + int iLevel, /* Level to select (relative level) */ |
| 125256 | 125899 | sqlite3_stmt **ppStmt /* OUT: Compiled statement */ |
| 125257 | 125900 | ){ |
| 125258 | 125901 | int rc; |
| 125259 | 125902 | sqlite3_stmt *pStmt = 0; |
| 125260 | 125903 | |
| | @@ -125264,18 +125907,20 @@ |
| 125264 | 125907 | |
| 125265 | 125908 | if( iLevel<0 ){ |
| 125266 | 125909 | /* "SELECT * FROM %_segdir WHERE level BETWEEN ? AND ? ORDER BY ..." */ |
| 125267 | 125910 | rc = fts3SqlStmt(p, SQL_SELECT_LEVEL_RANGE, &pStmt, 0); |
| 125268 | 125911 | if( rc==SQLITE_OK ){ |
| 125269 | | - sqlite3_bind_int(pStmt, 1, iIndex*FTS3_SEGDIR_MAXLEVEL); |
| 125270 | | - sqlite3_bind_int(pStmt, 2, (iIndex+1)*FTS3_SEGDIR_MAXLEVEL-1); |
| 125912 | + sqlite3_bind_int64(pStmt, 1, getAbsoluteLevel(p, iLangid, iIndex, 0)); |
| 125913 | + sqlite3_bind_int64(pStmt, 2, |
| 125914 | + getAbsoluteLevel(p, iLangid, iIndex, FTS3_SEGDIR_MAXLEVEL-1) |
| 125915 | + ); |
| 125271 | 125916 | } |
| 125272 | 125917 | }else{ |
| 125273 | 125918 | /* "SELECT * FROM %_segdir WHERE level = ? ORDER BY ..." */ |
| 125274 | 125919 | rc = fts3SqlStmt(p, SQL_SELECT_LEVEL, &pStmt, 0); |
| 125275 | 125920 | if( rc==SQLITE_OK ){ |
| 125276 | | - sqlite3_bind_int(pStmt, 1, iLevel+iIndex*FTS3_SEGDIR_MAXLEVEL); |
| 125921 | + sqlite3_bind_int64(pStmt, 1, getAbsoluteLevel(p, iLangid, iIndex,iLevel)); |
| 125277 | 125922 | } |
| 125278 | 125923 | } |
| 125279 | 125924 | *ppStmt = pStmt; |
| 125280 | 125925 | return rc; |
| 125281 | 125926 | } |
| | @@ -125437,10 +126082,11 @@ |
| 125437 | 126082 | ** |
| 125438 | 126083 | ** If successful, SQLITE_OK is returned. Otherwise, an SQLite error code. |
| 125439 | 126084 | */ |
| 125440 | 126085 | static int fts3PendingTermsAdd( |
| 125441 | 126086 | Fts3Table *p, /* Table into which text will be inserted */ |
| 126087 | + int iLangid, /* Language id to use */ |
| 125442 | 126088 | const char *zText, /* Text of document to be inserted */ |
| 125443 | 126089 | int iCol, /* Column into which text is being inserted */ |
| 125444 | 126090 | u32 *pnWord /* OUT: Number of tokens inserted */ |
| 125445 | 126091 | ){ |
| 125446 | 126092 | int rc; |
| | @@ -125466,15 +126112,14 @@ |
| 125466 | 126112 | if( zText==0 ){ |
| 125467 | 126113 | *pnWord = 0; |
| 125468 | 126114 | return SQLITE_OK; |
| 125469 | 126115 | } |
| 125470 | 126116 | |
| 125471 | | - rc = pModule->xOpen(pTokenizer, zText, -1, &pCsr); |
| 126117 | + rc = sqlite3Fts3OpenTokenizer(pTokenizer, iLangid, zText, -1, &pCsr); |
| 125472 | 126118 | if( rc!=SQLITE_OK ){ |
| 125473 | 126119 | return rc; |
| 125474 | 126120 | } |
| 125475 | | - pCsr->pTokenizer = pTokenizer; |
| 125476 | 126121 | |
| 125477 | 126122 | xNext = pModule->xNext; |
| 125478 | 126123 | while( SQLITE_OK==rc |
| 125479 | 126124 | && SQLITE_OK==(rc = xNext(pCsr, &zToken, &nToken, &iStart, &iEnd, &iPos)) |
| 125480 | 126125 | ){ |
| | @@ -125513,22 +126158,32 @@ |
| 125513 | 126158 | /* |
| 125514 | 126159 | ** Calling this function indicates that subsequent calls to |
| 125515 | 126160 | ** fts3PendingTermsAdd() are to add term/position-list pairs for the |
| 125516 | 126161 | ** contents of the document with docid iDocid. |
| 125517 | 126162 | */ |
| 125518 | | -static int fts3PendingTermsDocid(Fts3Table *p, sqlite_int64 iDocid){ |
| 126163 | +static int fts3PendingTermsDocid( |
| 126164 | + Fts3Table *p, /* Full-text table handle */ |
| 126165 | + int iLangid, /* Language id of row being written */ |
| 126166 | + sqlite_int64 iDocid /* Docid of row being written */ |
| 126167 | +){ |
| 126168 | + assert( iLangid>=0 ); |
| 126169 | + |
| 125519 | 126170 | /* TODO(shess) Explore whether partially flushing the buffer on |
| 125520 | 126171 | ** forced-flush would provide better performance. I suspect that if |
| 125521 | 126172 | ** we ordered the doclists by size and flushed the largest until the |
| 125522 | 126173 | ** buffer was half empty, that would let the less frequent terms |
| 125523 | 126174 | ** generate longer doclists. |
| 125524 | 126175 | */ |
| 125525 | | - if( iDocid<=p->iPrevDocid || p->nPendingData>p->nMaxPendingData ){ |
| 126176 | + if( iDocid<=p->iPrevDocid |
| 126177 | + || p->iPrevLangid!=iLangid |
| 126178 | + || p->nPendingData>p->nMaxPendingData |
| 126179 | + ){ |
| 125526 | 126180 | int rc = sqlite3Fts3PendingTermsFlush(p); |
| 125527 | 126181 | if( rc!=SQLITE_OK ) return rc; |
| 125528 | 126182 | } |
| 125529 | 126183 | p->iPrevDocid = iDocid; |
| 126184 | + p->iPrevLangid = iLangid; |
| 125530 | 126185 | return SQLITE_OK; |
| 125531 | 126186 | } |
| 125532 | 126187 | |
| 125533 | 126188 | /* |
| 125534 | 126189 | ** Discard the contents of the pending-terms hash tables. |
| | @@ -125553,15 +126208,20 @@ |
| 125553 | 126208 | ** pendingTerms hash table. |
| 125554 | 126209 | ** |
| 125555 | 126210 | ** Argument apVal is the same as the similarly named argument passed to |
| 125556 | 126211 | ** fts3InsertData(). Parameter iDocid is the docid of the new row. |
| 125557 | 126212 | */ |
| 125558 | | -static int fts3InsertTerms(Fts3Table *p, sqlite3_value **apVal, u32 *aSz){ |
| 126213 | +static int fts3InsertTerms( |
| 126214 | + Fts3Table *p, |
| 126215 | + int iLangid, |
| 126216 | + sqlite3_value **apVal, |
| 126217 | + u32 *aSz |
| 126218 | +){ |
| 125559 | 126219 | int i; /* Iterator variable */ |
| 125560 | 126220 | for(i=2; i<p->nColumn+2; i++){ |
| 125561 | 126221 | const char *zText = (const char *)sqlite3_value_text(apVal[i]); |
| 125562 | | - int rc = fts3PendingTermsAdd(p, zText, i-2, &aSz[i-2]); |
| 126222 | + int rc = fts3PendingTermsAdd(p, iLangid, zText, i-2, &aSz[i-2]); |
| 125563 | 126223 | if( rc!=SQLITE_OK ){ |
| 125564 | 126224 | return rc; |
| 125565 | 126225 | } |
| 125566 | 126226 | aSz[p->nColumn] += sqlite3_value_bytes(apVal[i]); |
| 125567 | 126227 | } |
| | @@ -125578,10 +126238,11 @@ |
| 125578 | 126238 | ** apVal[2] Left-most user-defined column |
| 125579 | 126239 | ** ... |
| 125580 | 126240 | ** apVal[p->nColumn+1] Right-most user-defined column |
| 125581 | 126241 | ** apVal[p->nColumn+2] Hidden column with same name as table |
| 125582 | 126242 | ** apVal[p->nColumn+3] Hidden "docid" column (alias for rowid) |
| 126243 | +** apVal[p->nColumn+4] Hidden languageid column |
| 125583 | 126244 | */ |
| 125584 | 126245 | static int fts3InsertData( |
| 125585 | 126246 | Fts3Table *p, /* Full-text table */ |
| 125586 | 126247 | sqlite3_value **apVal, /* Array of values to insert */ |
| 125587 | 126248 | sqlite3_int64 *piDocid /* OUT: Docid for row just inserted */ |
| | @@ -125608,13 +126269,17 @@ |
| 125608 | 126269 | ** |
| 125609 | 126270 | ** The statement features N '?' variables, where N is the number of user |
| 125610 | 126271 | ** defined columns in the FTS3 table, plus one for the docid field. |
| 125611 | 126272 | */ |
| 125612 | 126273 | rc = fts3SqlStmt(p, SQL_CONTENT_INSERT, &pContentInsert, &apVal[1]); |
| 125613 | | - if( rc!=SQLITE_OK ){ |
| 125614 | | - return rc; |
| 126274 | + if( rc==SQLITE_OK && p->zLanguageid ){ |
| 126275 | + rc = sqlite3_bind_int( |
| 126276 | + pContentInsert, p->nColumn+2, |
| 126277 | + sqlite3_value_int(apVal[p->nColumn+4]) |
| 126278 | + ); |
| 125615 | 126279 | } |
| 126280 | + if( rc!=SQLITE_OK ) return rc; |
| 125616 | 126281 | |
| 125617 | 126282 | /* There is a quirk here. The users INSERT statement may have specified |
| 125618 | 126283 | ** a value for the "rowid" field, for the "docid" field, or for both. |
| 125619 | 126284 | ** Which is a problem, since "rowid" and "docid" are aliases for the |
| 125620 | 126285 | ** same value. For example: |
| | @@ -125669,10 +126334,19 @@ |
| 125669 | 126334 | if( p->bHasStat ){ |
| 125670 | 126335 | fts3SqlExec(&rc, p, SQL_DELETE_ALL_STAT, 0); |
| 125671 | 126336 | } |
| 125672 | 126337 | return rc; |
| 125673 | 126338 | } |
| 126339 | + |
| 126340 | +/* |
| 126341 | +** |
| 126342 | +*/ |
| 126343 | +static int langidFromSelect(Fts3Table *p, sqlite3_stmt *pSelect){ |
| 126344 | + int iLangid = 0; |
| 126345 | + if( p->zLanguageid ) iLangid = sqlite3_column_int(pSelect, p->nColumn+1); |
| 126346 | + return iLangid; |
| 126347 | +} |
| 125674 | 126348 | |
| 125675 | 126349 | /* |
| 125676 | 126350 | ** The first element in the apVal[] array is assumed to contain the docid |
| 125677 | 126351 | ** (an integer) of a row about to be deleted. Remove all terms from the |
| 125678 | 126352 | ** full-text index. |
| | @@ -125689,19 +126363,21 @@ |
| 125689 | 126363 | if( *pRC ) return; |
| 125690 | 126364 | rc = fts3SqlStmt(p, SQL_SELECT_CONTENT_BY_ROWID, &pSelect, &pRowid); |
| 125691 | 126365 | if( rc==SQLITE_OK ){ |
| 125692 | 126366 | if( SQLITE_ROW==sqlite3_step(pSelect) ){ |
| 125693 | 126367 | int i; |
| 125694 | | - for(i=1; i<=p->nColumn; i++){ |
| 126368 | + int iLangid = langidFromSelect(p, pSelect); |
| 126369 | + rc = fts3PendingTermsDocid(p, iLangid, sqlite3_column_int64(pSelect, 0)); |
| 126370 | + for(i=1; rc==SQLITE_OK && i<=p->nColumn; i++){ |
| 125695 | 126371 | const char *zText = (const char *)sqlite3_column_text(pSelect, i); |
| 125696 | | - rc = fts3PendingTermsAdd(p, zText, -1, &aSz[i-1]); |
| 125697 | | - if( rc!=SQLITE_OK ){ |
| 125698 | | - sqlite3_reset(pSelect); |
| 125699 | | - *pRC = rc; |
| 125700 | | - return; |
| 125701 | | - } |
| 126372 | + rc = fts3PendingTermsAdd(p, iLangid, zText, -1, &aSz[i-1]); |
| 125702 | 126373 | aSz[p->nColumn] += sqlite3_column_bytes(pSelect, i); |
| 126374 | + } |
| 126375 | + if( rc!=SQLITE_OK ){ |
| 126376 | + sqlite3_reset(pSelect); |
| 126377 | + *pRC = rc; |
| 126378 | + return; |
| 125703 | 126379 | } |
| 125704 | 126380 | } |
| 125705 | 126381 | rc = sqlite3_reset(pSelect); |
| 125706 | 126382 | }else{ |
| 125707 | 126383 | sqlite3_reset(pSelect); |
| | @@ -125711,11 +126387,11 @@ |
| 125711 | 126387 | |
| 125712 | 126388 | /* |
| 125713 | 126389 | ** Forward declaration to account for the circular dependency between |
| 125714 | 126390 | ** functions fts3SegmentMerge() and fts3AllocateSegdirIdx(). |
| 125715 | 126391 | */ |
| 125716 | | -static int fts3SegmentMerge(Fts3Table *, int, int); |
| 126392 | +static int fts3SegmentMerge(Fts3Table *, int, int, int); |
| 125717 | 126393 | |
| 125718 | 126394 | /* |
| 125719 | 126395 | ** This function allocates a new level iLevel index in the segdir table. |
| 125720 | 126396 | ** Usually, indexes are allocated within a level sequentially starting |
| 125721 | 126397 | ** with 0, so the allocated index is one greater than the value returned |
| | @@ -125730,22 +126406,28 @@ |
| 125730 | 126406 | ** If successful, *piIdx is set to the allocated index slot and SQLITE_OK |
| 125731 | 126407 | ** returned. Otherwise, an SQLite error code is returned. |
| 125732 | 126408 | */ |
| 125733 | 126409 | static int fts3AllocateSegdirIdx( |
| 125734 | 126410 | Fts3Table *p, |
| 126411 | + int iLangid, /* Language id */ |
| 125735 | 126412 | int iIndex, /* Index for p->aIndex */ |
| 125736 | 126413 | int iLevel, |
| 125737 | 126414 | int *piIdx |
| 125738 | 126415 | ){ |
| 125739 | 126416 | int rc; /* Return Code */ |
| 125740 | 126417 | sqlite3_stmt *pNextIdx; /* Query for next idx at level iLevel */ |
| 125741 | 126418 | int iNext = 0; /* Result of query pNextIdx */ |
| 125742 | 126419 | |
| 126420 | + assert( iLangid>=0 ); |
| 126421 | + assert( p->nIndex>=1 ); |
| 126422 | + |
| 125743 | 126423 | /* Set variable iNext to the next available segdir index at level iLevel. */ |
| 125744 | 126424 | rc = fts3SqlStmt(p, SQL_NEXT_SEGMENT_INDEX, &pNextIdx, 0); |
| 125745 | 126425 | if( rc==SQLITE_OK ){ |
| 125746 | | - sqlite3_bind_int(pNextIdx, 1, iIndex*FTS3_SEGDIR_MAXLEVEL + iLevel); |
| 126426 | + sqlite3_bind_int64( |
| 126427 | + pNextIdx, 1, getAbsoluteLevel(p, iLangid, iIndex, iLevel) |
| 126428 | + ); |
| 125747 | 126429 | if( SQLITE_ROW==sqlite3_step(pNextIdx) ){ |
| 125748 | 126430 | iNext = sqlite3_column_int(pNextIdx, 0); |
| 125749 | 126431 | } |
| 125750 | 126432 | rc = sqlite3_reset(pNextIdx); |
| 125751 | 126433 | } |
| | @@ -125755,11 +126437,12 @@ |
| 125755 | 126437 | ** full, merge all segments in level iLevel into a single iLevel+1 |
| 125756 | 126438 | ** segment and allocate (newly freed) index 0 at level iLevel. Otherwise, |
| 125757 | 126439 | ** if iNext is less than FTS3_MERGE_COUNT, allocate index iNext. |
| 125758 | 126440 | */ |
| 125759 | 126441 | if( iNext>=FTS3_MERGE_COUNT ){ |
| 125760 | | - rc = fts3SegmentMerge(p, iIndex, iLevel); |
| 126442 | + fts3LogMerge(16, getAbsoluteLevel(p, iLangid, iIndex, iLevel)); |
| 126443 | + rc = fts3SegmentMerge(p, iLangid, iIndex, iLevel); |
| 125761 | 126444 | *piIdx = 0; |
| 125762 | 126445 | }else{ |
| 125763 | 126446 | *piIdx = iNext; |
| 125764 | 126447 | } |
| 125765 | 126448 | } |
| | @@ -125802,11 +126485,11 @@ |
| 125802 | 126485 | int *pnLoad /* OUT: Bytes actually loaded */ |
| 125803 | 126486 | ){ |
| 125804 | 126487 | int rc; /* Return code */ |
| 125805 | 126488 | |
| 125806 | 126489 | /* pnBlob must be non-NULL. paBlob may be NULL or non-NULL. */ |
| 125807 | | - assert( pnBlob); |
| 126490 | + assert( pnBlob ); |
| 125808 | 126491 | |
| 125809 | 126492 | if( p->pSegments ){ |
| 125810 | 126493 | rc = sqlite3_blob_reopen(p->pSegments, iBlockid); |
| 125811 | 126494 | }else{ |
| 125812 | 126495 | if( 0==p->zSegmentsTbl ){ |
| | @@ -126143,11 +126826,11 @@ |
| 126143 | 126826 | int nOvfl = 0; |
| 126144 | 126827 | int ii; |
| 126145 | 126828 | int rc = SQLITE_OK; |
| 126146 | 126829 | int pgsz = p->nPgsz; |
| 126147 | 126830 | |
| 126148 | | - assert( p->bHasStat ); |
| 126831 | + assert( p->bFts4 ); |
| 126149 | 126832 | assert( pgsz>0 ); |
| 126150 | 126833 | |
| 126151 | 126834 | for(ii=0; rc==SQLITE_OK && ii<pMsr->nSegment; ii++){ |
| 126152 | 126835 | Fts3SegReader *pReader = pMsr->apSegment[ii]; |
| 126153 | 126836 | if( !fts3SegReaderIsPending(pReader) |
| | @@ -126500,17 +127183,38 @@ |
| 126500 | 127183 | sqlite3_step(pStmt); |
| 126501 | 127184 | rc = sqlite3_reset(pStmt); |
| 126502 | 127185 | } |
| 126503 | 127186 | return rc; |
| 126504 | 127187 | } |
| 127188 | + |
| 127189 | +/* |
| 127190 | +** Find the largest relative level number in the table. If successful, set |
| 127191 | +** *pnMax to this value and return SQLITE_OK. Otherwise, if an error occurs, |
| 127192 | +** set *pnMax to zero and return an SQLite error code. |
| 127193 | +*/ |
| 127194 | +SQLITE_PRIVATE int sqlite3Fts3MaxLevel(Fts3Table *p, int *pnMax){ |
| 127195 | + int rc; |
| 127196 | + int mxLevel = 0; |
| 127197 | + sqlite3_stmt *pStmt = 0; |
| 127198 | + |
| 127199 | + rc = fts3SqlStmt(p, SQL_SELECT_MXLEVEL, &pStmt, 0); |
| 127200 | + if( rc==SQLITE_OK ){ |
| 127201 | + if( SQLITE_ROW==sqlite3_step(pStmt) ){ |
| 127202 | + mxLevel = sqlite3_column_int(pStmt, 0); |
| 127203 | + } |
| 127204 | + rc = sqlite3_reset(pStmt); |
| 127205 | + } |
| 127206 | + *pnMax = mxLevel; |
| 127207 | + return rc; |
| 127208 | +} |
| 126505 | 127209 | |
| 126506 | 127210 | /* |
| 126507 | 127211 | ** Insert a record into the %_segdir table. |
| 126508 | 127212 | */ |
| 126509 | 127213 | static int fts3WriteSegdir( |
| 126510 | 127214 | Fts3Table *p, /* Virtual table handle */ |
| 126511 | | - int iLevel, /* Value for "level" field */ |
| 127215 | + sqlite3_int64 iLevel, /* Value for "level" field (absolute level) */ |
| 126512 | 127216 | int iIdx, /* Value for "idx" field */ |
| 126513 | 127217 | sqlite3_int64 iStartBlock, /* Value for "start_block" field */ |
| 126514 | 127218 | sqlite3_int64 iLeafEndBlock, /* Value for "leaves_end_block" field */ |
| 126515 | 127219 | sqlite3_int64 iEndBlock, /* Value for "end_block" field */ |
| 126516 | 127220 | char *zRoot, /* Blob value for "root" field */ |
| | @@ -126517,11 +127221,11 @@ |
| 126517 | 127221 | int nRoot /* Number of bytes in buffer zRoot */ |
| 126518 | 127222 | ){ |
| 126519 | 127223 | sqlite3_stmt *pStmt; |
| 126520 | 127224 | int rc = fts3SqlStmt(p, SQL_INSERT_SEGDIR, &pStmt, 0); |
| 126521 | 127225 | if( rc==SQLITE_OK ){ |
| 126522 | | - sqlite3_bind_int(pStmt, 1, iLevel); |
| 127226 | + sqlite3_bind_int64(pStmt, 1, iLevel); |
| 126523 | 127227 | sqlite3_bind_int(pStmt, 2, iIdx); |
| 126524 | 127228 | sqlite3_bind_int64(pStmt, 3, iStartBlock); |
| 126525 | 127229 | sqlite3_bind_int64(pStmt, 4, iLeafEndBlock); |
| 126526 | 127230 | sqlite3_bind_int64(pStmt, 5, iEndBlock); |
| 126527 | 127231 | sqlite3_bind_blob(pStmt, 6, zRoot, nRoot, SQLITE_STATIC); |
| | @@ -126817,10 +127521,11 @@ |
| 126817 | 127521 | int rc; |
| 126818 | 127522 | |
| 126819 | 127523 | /* The current leaf node is full. Write it out to the database. */ |
| 126820 | 127524 | rc = fts3WriteSegment(p, pWriter->iFree++, pWriter->aData, nData); |
| 126821 | 127525 | if( rc!=SQLITE_OK ) return rc; |
| 127526 | + p->nLeafAdd++; |
| 126822 | 127527 | |
| 126823 | 127528 | /* Add the current term to the interior node tree. The term added to |
| 126824 | 127529 | ** the interior tree must: |
| 126825 | 127530 | ** |
| 126826 | 127531 | ** a) be greater than the largest term on the leaf node just written |
| | @@ -126900,11 +127605,11 @@ |
| 126900 | 127605 | ** returned. Otherwise, an SQLite error code. |
| 126901 | 127606 | */ |
| 126902 | 127607 | static int fts3SegWriterFlush( |
| 126903 | 127608 | Fts3Table *p, /* Virtual table handle */ |
| 126904 | 127609 | SegmentWriter *pWriter, /* SegmentWriter to flush to the db */ |
| 126905 | | - int iLevel, /* Value for 'level' column of %_segdir */ |
| 127610 | + sqlite3_int64 iLevel, /* Value for 'level' column of %_segdir */ |
| 126906 | 127611 | int iIdx /* Value for 'idx' column of %_segdir */ |
| 126907 | 127612 | ){ |
| 126908 | 127613 | int rc; /* Return code */ |
| 126909 | 127614 | if( pWriter->pTree ){ |
| 126910 | 127615 | sqlite3_int64 iLast = 0; /* Largest block id written to database */ |
| | @@ -126925,10 +127630,11 @@ |
| 126925 | 127630 | }else{ |
| 126926 | 127631 | /* The entire tree fits on the root node. Write it to the segdir table. */ |
| 126927 | 127632 | rc = fts3WriteSegdir( |
| 126928 | 127633 | p, iLevel, iIdx, 0, 0, 0, pWriter->aData, pWriter->nData); |
| 126929 | 127634 | } |
| 127635 | + p->nLeafAdd++; |
| 126930 | 127636 | return rc; |
| 126931 | 127637 | } |
| 126932 | 127638 | |
| 126933 | 127639 | /* |
| 126934 | 127640 | ** Release all memory held by the SegmentWriter object passed as the |
| | @@ -126978,11 +127684,16 @@ |
| 126978 | 127684 | ** |
| 126979 | 127685 | ** Segment levels are stored in the 'level' column of the %_segdir table. |
| 126980 | 127686 | ** |
| 126981 | 127687 | ** Return SQLITE_OK if successful, or an SQLite error code if not. |
| 126982 | 127688 | */ |
| 126983 | | -static int fts3SegmentMaxLevel(Fts3Table *p, int iIndex, int *pnMax){ |
| 127689 | +static int fts3SegmentMaxLevel( |
| 127690 | + Fts3Table *p, |
| 127691 | + int iLangid, |
| 127692 | + int iIndex, |
| 127693 | + sqlite3_int64 *pnMax |
| 127694 | +){ |
| 126984 | 127695 | sqlite3_stmt *pStmt; |
| 126985 | 127696 | int rc; |
| 126986 | 127697 | assert( iIndex>=0 && iIndex<p->nIndex ); |
| 126987 | 127698 | |
| 126988 | 127699 | /* Set pStmt to the compiled version of: |
| | @@ -126991,17 +127702,42 @@ |
| 126991 | 127702 | ** |
| 126992 | 127703 | ** (1024 is actually the value of macro FTS3_SEGDIR_PREFIXLEVEL_STR). |
| 126993 | 127704 | */ |
| 126994 | 127705 | rc = fts3SqlStmt(p, SQL_SELECT_SEGDIR_MAX_LEVEL, &pStmt, 0); |
| 126995 | 127706 | if( rc!=SQLITE_OK ) return rc; |
| 126996 | | - sqlite3_bind_int(pStmt, 1, iIndex*FTS3_SEGDIR_MAXLEVEL); |
| 126997 | | - sqlite3_bind_int(pStmt, 2, (iIndex+1)*FTS3_SEGDIR_MAXLEVEL - 1); |
| 127707 | + sqlite3_bind_int64(pStmt, 1, getAbsoluteLevel(p, iLangid, iIndex, 0)); |
| 127708 | + sqlite3_bind_int64(pStmt, 2, |
| 127709 | + getAbsoluteLevel(p, iLangid, iIndex, FTS3_SEGDIR_MAXLEVEL-1) |
| 127710 | + ); |
| 126998 | 127711 | if( SQLITE_ROW==sqlite3_step(pStmt) ){ |
| 126999 | | - *pnMax = sqlite3_column_int(pStmt, 0); |
| 127712 | + *pnMax = sqlite3_column_int64(pStmt, 0); |
| 127000 | 127713 | } |
| 127001 | 127714 | return sqlite3_reset(pStmt); |
| 127002 | 127715 | } |
| 127716 | + |
| 127717 | +/* |
| 127718 | +** Delete all entries in the %_segments table associated with the segment |
| 127719 | +** opened with seg-reader pSeg. This function does not affect the contents |
| 127720 | +** of the %_segdir table. |
| 127721 | +*/ |
| 127722 | +static int fts3DeleteSegment( |
| 127723 | + Fts3Table *p, /* FTS table handle */ |
| 127724 | + Fts3SegReader *pSeg /* Segment to delete */ |
| 127725 | +){ |
| 127726 | + int rc = SQLITE_OK; /* Return code */ |
| 127727 | + if( pSeg->iStartBlock ){ |
| 127728 | + sqlite3_stmt *pDelete; /* SQL statement to delete rows */ |
| 127729 | + rc = fts3SqlStmt(p, SQL_DELETE_SEGMENTS_RANGE, &pDelete, 0); |
| 127730 | + if( rc==SQLITE_OK ){ |
| 127731 | + sqlite3_bind_int64(pDelete, 1, pSeg->iStartBlock); |
| 127732 | + sqlite3_bind_int64(pDelete, 2, pSeg->iEndBlock); |
| 127733 | + sqlite3_step(pDelete); |
| 127734 | + rc = sqlite3_reset(pDelete); |
| 127735 | + } |
| 127736 | + } |
| 127737 | + return rc; |
| 127738 | +} |
| 127003 | 127739 | |
| 127004 | 127740 | /* |
| 127005 | 127741 | ** This function is used after merging multiple segments into a single large |
| 127006 | 127742 | ** segment to delete the old, now redundant, segment b-trees. Specifically, |
| 127007 | 127743 | ** it: |
| | @@ -127015,44 +127751,42 @@ |
| 127015 | 127751 | ** |
| 127016 | 127752 | ** SQLITE_OK is returned if successful, otherwise an SQLite error code. |
| 127017 | 127753 | */ |
| 127018 | 127754 | static int fts3DeleteSegdir( |
| 127019 | 127755 | Fts3Table *p, /* Virtual table handle */ |
| 127756 | + int iLangid, /* Language id */ |
| 127020 | 127757 | int iIndex, /* Index for p->aIndex */ |
| 127021 | 127758 | int iLevel, /* Level of %_segdir entries to delete */ |
| 127022 | 127759 | Fts3SegReader **apSegment, /* Array of SegReader objects */ |
| 127023 | 127760 | int nReader /* Size of array apSegment */ |
| 127024 | 127761 | ){ |
| 127025 | | - int rc; /* Return Code */ |
| 127762 | + int rc = SQLITE_OK; /* Return Code */ |
| 127026 | 127763 | int i; /* Iterator variable */ |
| 127027 | | - sqlite3_stmt *pDelete; /* SQL statement to delete rows */ |
| 127764 | + sqlite3_stmt *pDelete = 0; /* SQL statement to delete rows */ |
| 127028 | 127765 | |
| 127029 | | - rc = fts3SqlStmt(p, SQL_DELETE_SEGMENTS_RANGE, &pDelete, 0); |
| 127030 | 127766 | for(i=0; rc==SQLITE_OK && i<nReader; i++){ |
| 127031 | | - Fts3SegReader *pSegment = apSegment[i]; |
| 127032 | | - if( pSegment->iStartBlock ){ |
| 127033 | | - sqlite3_bind_int64(pDelete, 1, pSegment->iStartBlock); |
| 127034 | | - sqlite3_bind_int64(pDelete, 2, pSegment->iEndBlock); |
| 127035 | | - sqlite3_step(pDelete); |
| 127036 | | - rc = sqlite3_reset(pDelete); |
| 127037 | | - } |
| 127767 | + rc = fts3DeleteSegment(p, apSegment[i]); |
| 127038 | 127768 | } |
| 127039 | 127769 | if( rc!=SQLITE_OK ){ |
| 127040 | 127770 | return rc; |
| 127041 | 127771 | } |
| 127042 | 127772 | |
| 127043 | 127773 | assert( iLevel>=0 || iLevel==FTS3_SEGCURSOR_ALL ); |
| 127044 | 127774 | if( iLevel==FTS3_SEGCURSOR_ALL ){ |
| 127045 | 127775 | rc = fts3SqlStmt(p, SQL_DELETE_SEGDIR_RANGE, &pDelete, 0); |
| 127046 | 127776 | if( rc==SQLITE_OK ){ |
| 127047 | | - sqlite3_bind_int(pDelete, 1, iIndex*FTS3_SEGDIR_MAXLEVEL); |
| 127048 | | - sqlite3_bind_int(pDelete, 2, (iIndex+1) * FTS3_SEGDIR_MAXLEVEL - 1); |
| 127777 | + sqlite3_bind_int64(pDelete, 1, getAbsoluteLevel(p, iLangid, iIndex, 0)); |
| 127778 | + sqlite3_bind_int64(pDelete, 2, |
| 127779 | + getAbsoluteLevel(p, iLangid, iIndex, FTS3_SEGDIR_MAXLEVEL-1) |
| 127780 | + ); |
| 127049 | 127781 | } |
| 127050 | 127782 | }else{ |
| 127051 | 127783 | rc = fts3SqlStmt(p, SQL_DELETE_SEGDIR_LEVEL, &pDelete, 0); |
| 127052 | 127784 | if( rc==SQLITE_OK ){ |
| 127053 | | - sqlite3_bind_int(pDelete, 1, iIndex*FTS3_SEGDIR_MAXLEVEL + iLevel); |
| 127785 | + sqlite3_bind_int64( |
| 127786 | + pDelete, 1, getAbsoluteLevel(p, iLangid, iIndex, iLevel) |
| 127787 | + ); |
| 127054 | 127788 | } |
| 127055 | 127789 | } |
| 127056 | 127790 | |
| 127057 | 127791 | if( rc==SQLITE_OK ){ |
| 127058 | 127792 | sqlite3_step(pDelete); |
| | @@ -127517,27 +128251,32 @@ |
| 127517 | 128251 | ** If this function is called with iLevel<0, but there is only one |
| 127518 | 128252 | ** segment in the database, SQLITE_DONE is returned immediately. |
| 127519 | 128253 | ** Otherwise, if successful, SQLITE_OK is returned. If an error occurs, |
| 127520 | 128254 | ** an SQLite error code is returned. |
| 127521 | 128255 | */ |
| 127522 | | -static int fts3SegmentMerge(Fts3Table *p, int iIndex, int iLevel){ |
| 128256 | +static int fts3SegmentMerge( |
| 128257 | + Fts3Table *p, |
| 128258 | + int iLangid, /* Language id to merge */ |
| 128259 | + int iIndex, /* Index in p->aIndex[] to merge */ |
| 128260 | + int iLevel /* Level to merge */ |
| 128261 | +){ |
| 127523 | 128262 | int rc; /* Return code */ |
| 127524 | 128263 | int iIdx = 0; /* Index of new segment */ |
| 127525 | | - int iNewLevel = 0; /* Level/index to create new segment at */ |
| 128264 | + sqlite3_int64 iNewLevel = 0; /* Level/index to create new segment at */ |
| 127526 | 128265 | SegmentWriter *pWriter = 0; /* Used to write the new, merged, segment */ |
| 127527 | 128266 | Fts3SegFilter filter; /* Segment term filter condition */ |
| 127528 | | - Fts3MultiSegReader csr; /* Cursor to iterate through level(s) */ |
| 128267 | + Fts3MultiSegReader csr; /* Cursor to iterate through level(s) */ |
| 127529 | 128268 | int bIgnoreEmpty = 0; /* True to ignore empty segments */ |
| 127530 | 128269 | |
| 127531 | 128270 | assert( iLevel==FTS3_SEGCURSOR_ALL |
| 127532 | 128271 | || iLevel==FTS3_SEGCURSOR_PENDING |
| 127533 | 128272 | || iLevel>=0 |
| 127534 | 128273 | ); |
| 127535 | 128274 | assert( iLevel<FTS3_SEGDIR_MAXLEVEL ); |
| 127536 | 128275 | assert( iIndex>=0 && iIndex<p->nIndex ); |
| 127537 | 128276 | |
| 127538 | | - rc = sqlite3Fts3SegReaderCursor(p, iIndex, iLevel, 0, 0, 1, 0, &csr); |
| 128277 | + rc = sqlite3Fts3SegReaderCursor(p, iLangid, iIndex, iLevel, 0, 0, 1, 0, &csr); |
| 127539 | 128278 | if( rc!=SQLITE_OK || csr.nSegment==0 ) goto finished; |
| 127540 | 128279 | |
| 127541 | 128280 | if( iLevel==FTS3_SEGCURSOR_ALL ){ |
| 127542 | 128281 | /* This call is to merge all segments in the database to a single |
| 127543 | 128282 | ** segment. The level of the new segment is equal to the the numerically |
| | @@ -127545,28 +128284,28 @@ |
| 127545 | 128284 | ** index. The idx of the new segment is always 0. */ |
| 127546 | 128285 | if( csr.nSegment==1 ){ |
| 127547 | 128286 | rc = SQLITE_DONE; |
| 127548 | 128287 | goto finished; |
| 127549 | 128288 | } |
| 127550 | | - rc = fts3SegmentMaxLevel(p, iIndex, &iNewLevel); |
| 128289 | + rc = fts3SegmentMaxLevel(p, iLangid, iIndex, &iNewLevel); |
| 127551 | 128290 | bIgnoreEmpty = 1; |
| 127552 | 128291 | |
| 127553 | 128292 | }else if( iLevel==FTS3_SEGCURSOR_PENDING ){ |
| 127554 | | - iNewLevel = iIndex * FTS3_SEGDIR_MAXLEVEL; |
| 127555 | | - rc = fts3AllocateSegdirIdx(p, iIndex, 0, &iIdx); |
| 128293 | + iNewLevel = getAbsoluteLevel(p, iLangid, iIndex, 0); |
| 128294 | + rc = fts3AllocateSegdirIdx(p, iLangid, iIndex, 0, &iIdx); |
| 127556 | 128295 | }else{ |
| 127557 | 128296 | /* This call is to merge all segments at level iLevel. find the next |
| 127558 | 128297 | ** available segment index at level iLevel+1. The call to |
| 127559 | 128298 | ** fts3AllocateSegdirIdx() will merge the segments at level iLevel+1 to |
| 127560 | 128299 | ** a single iLevel+2 segment if necessary. */ |
| 127561 | | - rc = fts3AllocateSegdirIdx(p, iIndex, iLevel+1, &iIdx); |
| 127562 | | - iNewLevel = iIndex * FTS3_SEGDIR_MAXLEVEL + iLevel+1; |
| 128300 | + rc = fts3AllocateSegdirIdx(p, iLangid, iIndex, iLevel+1, &iIdx); |
| 128301 | + iNewLevel = getAbsoluteLevel(p, iLangid, iIndex, iLevel+1); |
| 127563 | 128302 | } |
| 127564 | 128303 | if( rc!=SQLITE_OK ) goto finished; |
| 127565 | 128304 | assert( csr.nSegment>0 ); |
| 127566 | | - assert( iNewLevel>=(iIndex*FTS3_SEGDIR_MAXLEVEL) ); |
| 127567 | | - assert( iNewLevel<((iIndex+1)*FTS3_SEGDIR_MAXLEVEL) ); |
| 128305 | + assert( iNewLevel>=getAbsoluteLevel(p, iLangid, iIndex, 0) ); |
| 128306 | + assert( iNewLevel<getAbsoluteLevel(p, iLangid, iIndex,FTS3_SEGDIR_MAXLEVEL) ); |
| 127568 | 128307 | |
| 127569 | 128308 | memset(&filter, 0, sizeof(Fts3SegFilter)); |
| 127570 | 128309 | filter.flags = FTS3_SEGMENT_REQUIRE_POS; |
| 127571 | 128310 | filter.flags |= (bIgnoreEmpty ? FTS3_SEGMENT_IGNORE_EMPTY : 0); |
| 127572 | 128311 | |
| | @@ -127579,11 +128318,13 @@ |
| 127579 | 128318 | } |
| 127580 | 128319 | if( rc!=SQLITE_OK ) goto finished; |
| 127581 | 128320 | assert( pWriter ); |
| 127582 | 128321 | |
| 127583 | 128322 | if( iLevel!=FTS3_SEGCURSOR_PENDING ){ |
| 127584 | | - rc = fts3DeleteSegdir(p, iIndex, iLevel, csr.apSegment, csr.nSegment); |
| 128323 | + rc = fts3DeleteSegdir( |
| 128324 | + p, iLangid, iIndex, iLevel, csr.apSegment, csr.nSegment |
| 128325 | + ); |
| 127585 | 128326 | if( rc!=SQLITE_OK ) goto finished; |
| 127586 | 128327 | } |
| 127587 | 128328 | rc = fts3SegWriterFlush(p, pWriter, iNewLevel, iIdx); |
| 127588 | 128329 | |
| 127589 | 128330 | finished: |
| | @@ -127597,15 +128338,32 @@ |
| 127597 | 128338 | ** Flush the contents of pendingTerms to level 0 segments. |
| 127598 | 128339 | */ |
| 127599 | 128340 | SQLITE_PRIVATE int sqlite3Fts3PendingTermsFlush(Fts3Table *p){ |
| 127600 | 128341 | int rc = SQLITE_OK; |
| 127601 | 128342 | int i; |
| 128343 | + |
| 127602 | 128344 | for(i=0; rc==SQLITE_OK && i<p->nIndex; i++){ |
| 127603 | | - rc = fts3SegmentMerge(p, i, FTS3_SEGCURSOR_PENDING); |
| 128345 | + rc = fts3SegmentMerge(p, p->iPrevLangid, i, FTS3_SEGCURSOR_PENDING); |
| 127604 | 128346 | if( rc==SQLITE_DONE ) rc = SQLITE_OK; |
| 127605 | 128347 | } |
| 127606 | 128348 | sqlite3Fts3PendingTermsClear(p); |
| 128349 | + |
| 128350 | + /* Determine the auto-incr-merge setting if unknown. If enabled, |
| 128351 | + ** estimate the number of leaf blocks of content to be written |
| 128352 | + */ |
| 128353 | + if( rc==SQLITE_OK && p->bHasStat |
| 128354 | + && p->bAutoincrmerge==0xff && p->nLeafAdd>0 |
| 128355 | + ){ |
| 128356 | + sqlite3_stmt *pStmt = 0; |
| 128357 | + rc = fts3SqlStmt(p, SQL_SELECT_STAT, &pStmt, 0); |
| 128358 | + if( rc==SQLITE_OK ){ |
| 128359 | + sqlite3_bind_int(pStmt, 1, FTS_STAT_AUTOINCRMERGE); |
| 128360 | + rc = sqlite3_step(pStmt); |
| 128361 | + p->bAutoincrmerge = (rc==SQLITE_ROW && sqlite3_column_int(pStmt, 0)); |
| 128362 | + rc = sqlite3_reset(pStmt); |
| 128363 | + } |
| 128364 | + } |
| 127607 | 128365 | return rc; |
| 127608 | 128366 | } |
| 127609 | 128367 | |
| 127610 | 128368 | /* |
| 127611 | 128369 | ** Encode N integers as varints into a blob. |
| | @@ -127712,16 +128470,17 @@ |
| 127712 | 128470 | if( a==0 ){ |
| 127713 | 128471 | *pRC = SQLITE_NOMEM; |
| 127714 | 128472 | return; |
| 127715 | 128473 | } |
| 127716 | 128474 | pBlob = (char*)&a[nStat]; |
| 127717 | | - rc = fts3SqlStmt(p, SQL_SELECT_DOCTOTAL, &pStmt, 0); |
| 128475 | + rc = fts3SqlStmt(p, SQL_SELECT_STAT, &pStmt, 0); |
| 127718 | 128476 | if( rc ){ |
| 127719 | 128477 | sqlite3_free(a); |
| 127720 | 128478 | *pRC = rc; |
| 127721 | 128479 | return; |
| 127722 | 128480 | } |
| 128481 | + sqlite3_bind_int(pStmt, 1, FTS_STAT_DOCTOTAL); |
| 127723 | 128482 | if( sqlite3_step(pStmt)==SQLITE_ROW ){ |
| 127724 | 128483 | fts3DecodeIntArray(nStat, a, |
| 127725 | 128484 | sqlite3_column_blob(pStmt, 0), |
| 127726 | 128485 | sqlite3_column_bytes(pStmt, 0)); |
| 127727 | 128486 | }else{ |
| | @@ -127741,33 +128500,51 @@ |
| 127741 | 128500 | x = x + aSzIns[i] - aSzDel[i]; |
| 127742 | 128501 | } |
| 127743 | 128502 | a[i+1] = x; |
| 127744 | 128503 | } |
| 127745 | 128504 | fts3EncodeIntArray(nStat, a, pBlob, &nBlob); |
| 127746 | | - rc = fts3SqlStmt(p, SQL_REPLACE_DOCTOTAL, &pStmt, 0); |
| 128505 | + rc = fts3SqlStmt(p, SQL_REPLACE_STAT, &pStmt, 0); |
| 127747 | 128506 | if( rc ){ |
| 127748 | 128507 | sqlite3_free(a); |
| 127749 | 128508 | *pRC = rc; |
| 127750 | 128509 | return; |
| 127751 | 128510 | } |
| 127752 | | - sqlite3_bind_blob(pStmt, 1, pBlob, nBlob, SQLITE_STATIC); |
| 128511 | + sqlite3_bind_int(pStmt, 1, FTS_STAT_DOCTOTAL); |
| 128512 | + sqlite3_bind_blob(pStmt, 2, pBlob, nBlob, SQLITE_STATIC); |
| 127753 | 128513 | sqlite3_step(pStmt); |
| 127754 | 128514 | *pRC = sqlite3_reset(pStmt); |
| 127755 | 128515 | sqlite3_free(a); |
| 127756 | 128516 | } |
| 127757 | 128517 | |
| 128518 | +/* |
| 128519 | +** Merge the entire database so that there is one segment for each |
| 128520 | +** iIndex/iLangid combination. |
| 128521 | +*/ |
| 127758 | 128522 | static int fts3DoOptimize(Fts3Table *p, int bReturnDone){ |
| 127759 | | - int i; |
| 127760 | 128523 | int bSeenDone = 0; |
| 127761 | | - int rc = SQLITE_OK; |
| 127762 | | - for(i=0; rc==SQLITE_OK && i<p->nIndex; i++){ |
| 127763 | | - rc = fts3SegmentMerge(p, i, FTS3_SEGCURSOR_ALL); |
| 127764 | | - if( rc==SQLITE_DONE ){ |
| 127765 | | - bSeenDone = 1; |
| 127766 | | - rc = SQLITE_OK; |
| 127767 | | - } |
| 127768 | | - } |
| 128524 | + int rc; |
| 128525 | + sqlite3_stmt *pAllLangid = 0; |
| 128526 | + |
| 128527 | + rc = fts3SqlStmt(p, SQL_SELECT_ALL_LANGID, &pAllLangid, 0); |
| 128528 | + if( rc==SQLITE_OK ){ |
| 128529 | + int rc2; |
| 128530 | + sqlite3_bind_int(pAllLangid, 1, p->nIndex); |
| 128531 | + while( sqlite3_step(pAllLangid)==SQLITE_ROW ){ |
| 128532 | + int i; |
| 128533 | + int iLangid = sqlite3_column_int(pAllLangid, 0); |
| 128534 | + for(i=0; rc==SQLITE_OK && i<p->nIndex; i++){ |
| 128535 | + rc = fts3SegmentMerge(p, iLangid, i, FTS3_SEGCURSOR_ALL); |
| 128536 | + if( rc==SQLITE_DONE ){ |
| 128537 | + bSeenDone = 1; |
| 128538 | + rc = SQLITE_OK; |
| 128539 | + } |
| 128540 | + } |
| 128541 | + } |
| 128542 | + rc2 = sqlite3_reset(pAllLangid); |
| 128543 | + if( rc==SQLITE_OK ) rc = rc2; |
| 128544 | + } |
| 128545 | + |
| 127769 | 128546 | sqlite3Fts3SegmentsClose(p); |
| 127770 | 128547 | sqlite3Fts3PendingTermsClear(p); |
| 127771 | 128548 | |
| 127772 | 128549 | return (rc==SQLITE_OK && bReturnDone && bSeenDone) ? SQLITE_DONE : rc; |
| 127773 | 128550 | } |
| | @@ -127814,15 +128591,16 @@ |
| 127814 | 128591 | } |
| 127815 | 128592 | } |
| 127816 | 128593 | |
| 127817 | 128594 | while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){ |
| 127818 | 128595 | int iCol; |
| 127819 | | - rc = fts3PendingTermsDocid(p, sqlite3_column_int64(pStmt, 0)); |
| 128596 | + int iLangid = langidFromSelect(p, pStmt); |
| 128597 | + rc = fts3PendingTermsDocid(p, iLangid, sqlite3_column_int64(pStmt, 0)); |
| 127820 | 128598 | aSz[p->nColumn] = 0; |
| 127821 | 128599 | for(iCol=0; rc==SQLITE_OK && iCol<p->nColumn; iCol++){ |
| 127822 | 128600 | const char *z = (const char *) sqlite3_column_text(pStmt, iCol+1); |
| 127823 | | - rc = fts3PendingTermsAdd(p, z, iCol, &aSz[iCol]); |
| 128601 | + rc = fts3PendingTermsAdd(p, iLangid, z, iCol, &aSz[iCol]); |
| 127824 | 128602 | aSz[p->nColumn] += sqlite3_column_bytes(pStmt, iCol+1); |
| 127825 | 128603 | } |
| 127826 | 128604 | if( p->bHasDocsize ){ |
| 127827 | 128605 | fts3InsertDocsize(&rc, p, aSz); |
| 127828 | 128606 | } |
| | @@ -127834,11 +128612,11 @@ |
| 127834 | 128612 | for(iCol=0; iCol<=p->nColumn; iCol++){ |
| 127835 | 128613 | aSzIns[iCol] += aSz[iCol]; |
| 127836 | 128614 | } |
| 127837 | 128615 | } |
| 127838 | 128616 | } |
| 127839 | | - if( p->bHasStat ){ |
| 128617 | + if( p->bFts4 ){ |
| 127840 | 128618 | fts3UpdateDocTotals(&rc, p, aSzIns, aSzDel, nEntry); |
| 127841 | 128619 | } |
| 127842 | 128620 | sqlite3_free(aSz); |
| 127843 | 128621 | |
| 127844 | 128622 | if( pStmt ){ |
| | @@ -127850,10 +128628,1692 @@ |
| 127850 | 128628 | } |
| 127851 | 128629 | |
| 127852 | 128630 | return rc; |
| 127853 | 128631 | } |
| 127854 | 128632 | |
| 128633 | + |
| 128634 | +/* |
| 128635 | +** This function opens a cursor used to read the input data for an |
| 128636 | +** incremental merge operation. Specifically, it opens a cursor to scan |
| 128637 | +** the oldest nSeg segments (idx=0 through idx=(nSeg-1)) in absolute |
| 128638 | +** level iAbsLevel. |
| 128639 | +*/ |
| 128640 | +static int fts3IncrmergeCsr( |
| 128641 | + Fts3Table *p, /* FTS3 table handle */ |
| 128642 | + sqlite3_int64 iAbsLevel, /* Absolute level to open */ |
| 128643 | + int nSeg, /* Number of segments to merge */ |
| 128644 | + Fts3MultiSegReader *pCsr /* Cursor object to populate */ |
| 128645 | +){ |
| 128646 | + int rc; /* Return Code */ |
| 128647 | + sqlite3_stmt *pStmt = 0; /* Statement used to read %_segdir entry */ |
| 128648 | + int nByte; /* Bytes allocated at pCsr->apSegment[] */ |
| 128649 | + |
| 128650 | + /* Allocate space for the Fts3MultiSegReader.aCsr[] array */ |
| 128651 | + memset(pCsr, 0, sizeof(*pCsr)); |
| 128652 | + nByte = sizeof(Fts3SegReader *) * nSeg; |
| 128653 | + pCsr->apSegment = (Fts3SegReader **)sqlite3_malloc(nByte); |
| 128654 | + |
| 128655 | + if( pCsr->apSegment==0 ){ |
| 128656 | + rc = SQLITE_NOMEM; |
| 128657 | + }else{ |
| 128658 | + memset(pCsr->apSegment, 0, nByte); |
| 128659 | + rc = fts3SqlStmt(p, SQL_SELECT_LEVEL, &pStmt, 0); |
| 128660 | + } |
| 128661 | + if( rc==SQLITE_OK ){ |
| 128662 | + int i; |
| 128663 | + int rc2; |
| 128664 | + sqlite3_bind_int64(pStmt, 1, iAbsLevel); |
| 128665 | + assert( pCsr->nSegment==0 ); |
| 128666 | + for(i=0; rc==SQLITE_OK && sqlite3_step(pStmt)==SQLITE_ROW && i<nSeg; i++){ |
| 128667 | + rc = sqlite3Fts3SegReaderNew(i, 0, |
| 128668 | + sqlite3_column_int64(pStmt, 1), /* segdir.start_block */ |
| 128669 | + sqlite3_column_int64(pStmt, 2), /* segdir.leaves_end_block */ |
| 128670 | + sqlite3_column_int64(pStmt, 3), /* segdir.end_block */ |
| 128671 | + sqlite3_column_blob(pStmt, 4), /* segdir.root */ |
| 128672 | + sqlite3_column_bytes(pStmt, 4), /* segdir.root */ |
| 128673 | + &pCsr->apSegment[i] |
| 128674 | + ); |
| 128675 | + pCsr->nSegment++; |
| 128676 | + } |
| 128677 | + rc2 = sqlite3_reset(pStmt); |
| 128678 | + if( rc==SQLITE_OK ) rc = rc2; |
| 128679 | + } |
| 128680 | + |
| 128681 | + return rc; |
| 128682 | +} |
| 128683 | + |
| 128684 | +typedef struct IncrmergeWriter IncrmergeWriter; |
| 128685 | +typedef struct NodeWriter NodeWriter; |
| 128686 | +typedef struct Blob Blob; |
| 128687 | +typedef struct NodeReader NodeReader; |
| 128688 | + |
| 128689 | +/* |
| 128690 | +** An instance of the following structure is used as a dynamic buffer |
| 128691 | +** to build up nodes or other blobs of data in. |
| 128692 | +** |
| 128693 | +** The function blobGrowBuffer() is used to extend the allocation. |
| 128694 | +*/ |
| 128695 | +struct Blob { |
| 128696 | + char *a; /* Pointer to allocation */ |
| 128697 | + int n; /* Number of valid bytes of data in a[] */ |
| 128698 | + int nAlloc; /* Allocated size of a[] (nAlloc>=n) */ |
| 128699 | +}; |
| 128700 | + |
| 128701 | +/* |
| 128702 | +** This structure is used to build up buffers containing segment b-tree |
| 128703 | +** nodes (blocks). |
| 128704 | +*/ |
| 128705 | +struct NodeWriter { |
| 128706 | + sqlite3_int64 iBlock; /* Current block id */ |
| 128707 | + Blob key; /* Last key written to the current block */ |
| 128708 | + Blob block; /* Current block image */ |
| 128709 | +}; |
| 128710 | + |
| 128711 | +/* |
| 128712 | +** An object of this type contains the state required to create or append |
| 128713 | +** to an appendable b-tree segment. |
| 128714 | +*/ |
| 128715 | +struct IncrmergeWriter { |
| 128716 | + int nLeafEst; /* Space allocated for leaf blocks */ |
| 128717 | + int nWork; /* Number of leaf pages flushed */ |
| 128718 | + sqlite3_int64 iAbsLevel; /* Absolute level of input segments */ |
| 128719 | + int iIdx; /* Index of *output* segment in iAbsLevel+1 */ |
| 128720 | + sqlite3_int64 iStart; /* Block number of first allocated block */ |
| 128721 | + sqlite3_int64 iEnd; /* Block number of last allocated block */ |
| 128722 | + NodeWriter aNodeWriter[FTS_MAX_APPENDABLE_HEIGHT]; |
| 128723 | +}; |
| 128724 | + |
| 128725 | +/* |
| 128726 | +** An object of the following type is used to read data from a single |
| 128727 | +** FTS segment node. See the following functions: |
| 128728 | +** |
| 128729 | +** nodeReaderInit() |
| 128730 | +** nodeReaderNext() |
| 128731 | +** nodeReaderRelease() |
| 128732 | +*/ |
| 128733 | +struct NodeReader { |
| 128734 | + const char *aNode; |
| 128735 | + int nNode; |
| 128736 | + int iOff; /* Current offset within aNode[] */ |
| 128737 | + |
| 128738 | + /* Output variables. Containing the current node entry. */ |
| 128739 | + sqlite3_int64 iChild; /* Pointer to child node */ |
| 128740 | + Blob term; /* Current term */ |
| 128741 | + const char *aDoclist; /* Pointer to doclist */ |
| 128742 | + int nDoclist; /* Size of doclist in bytes */ |
| 128743 | +}; |
| 128744 | + |
| 128745 | +/* |
| 128746 | +** If *pRc is not SQLITE_OK when this function is called, it is a no-op. |
| 128747 | +** Otherwise, if the allocation at pBlob->a is not already at least nMin |
| 128748 | +** bytes in size, extend (realloc) it to be so. |
| 128749 | +** |
| 128750 | +** If an OOM error occurs, set *pRc to SQLITE_NOMEM and leave pBlob->a |
| 128751 | +** unmodified. Otherwise, if the allocation succeeds, update pBlob->nAlloc |
| 128752 | +** to reflect the new size of the pBlob->a[] buffer. |
| 128753 | +*/ |
| 128754 | +static void blobGrowBuffer(Blob *pBlob, int nMin, int *pRc){ |
| 128755 | + if( *pRc==SQLITE_OK && nMin>pBlob->nAlloc ){ |
| 128756 | + int nAlloc = nMin; |
| 128757 | + char *a = (char *)sqlite3_realloc(pBlob->a, nAlloc); |
| 128758 | + if( a ){ |
| 128759 | + pBlob->nAlloc = nAlloc; |
| 128760 | + pBlob->a = a; |
| 128761 | + }else{ |
| 128762 | + *pRc = SQLITE_NOMEM; |
| 128763 | + } |
| 128764 | + } |
| 128765 | +} |
| 128766 | + |
| 128767 | +/* |
| 128768 | +** Attempt to advance the node-reader object passed as the first argument to |
| 128769 | +** the next entry on the node. |
| 128770 | +** |
| 128771 | +** Return an error code if an error occurs (SQLITE_NOMEM is possible). |
| 128772 | +** Otherwise return SQLITE_OK. If there is no next entry on the node |
| 128773 | +** (e.g. because the current entry is the last) set NodeReader->aNode to |
| 128774 | +** NULL to indicate EOF. Otherwise, populate the NodeReader structure output |
| 128775 | +** variables for the new entry. |
| 128776 | +*/ |
| 128777 | +static int nodeReaderNext(NodeReader *p){ |
| 128778 | + int bFirst = (p->term.n==0); /* True for first term on the node */ |
| 128779 | + int nPrefix = 0; /* Bytes to copy from previous term */ |
| 128780 | + int nSuffix = 0; /* Bytes to append to the prefix */ |
| 128781 | + int rc = SQLITE_OK; /* Return code */ |
| 128782 | + |
| 128783 | + assert( p->aNode ); |
| 128784 | + if( p->iChild && bFirst==0 ) p->iChild++; |
| 128785 | + if( p->iOff>=p->nNode ){ |
| 128786 | + /* EOF */ |
| 128787 | + p->aNode = 0; |
| 128788 | + }else{ |
| 128789 | + if( bFirst==0 ){ |
| 128790 | + p->iOff += sqlite3Fts3GetVarint32(&p->aNode[p->iOff], &nPrefix); |
| 128791 | + } |
| 128792 | + p->iOff += sqlite3Fts3GetVarint32(&p->aNode[p->iOff], &nSuffix); |
| 128793 | + |
| 128794 | + blobGrowBuffer(&p->term, nPrefix+nSuffix, &rc); |
| 128795 | + if( rc==SQLITE_OK ){ |
| 128796 | + memcpy(&p->term.a[nPrefix], &p->aNode[p->iOff], nSuffix); |
| 128797 | + p->term.n = nPrefix+nSuffix; |
| 128798 | + p->iOff += nSuffix; |
| 128799 | + if( p->iChild==0 ){ |
| 128800 | + p->iOff += sqlite3Fts3GetVarint32(&p->aNode[p->iOff], &p->nDoclist); |
| 128801 | + p->aDoclist = &p->aNode[p->iOff]; |
| 128802 | + p->iOff += p->nDoclist; |
| 128803 | + } |
| 128804 | + } |
| 128805 | + } |
| 128806 | + |
| 128807 | + assert( p->iOff<=p->nNode ); |
| 128808 | + |
| 128809 | + return rc; |
| 128810 | +} |
| 128811 | + |
| 128812 | +/* |
| 128813 | +** Release all dynamic resources held by node-reader object *p. |
| 128814 | +*/ |
| 128815 | +static void nodeReaderRelease(NodeReader *p){ |
| 128816 | + sqlite3_free(p->term.a); |
| 128817 | +} |
| 128818 | + |
| 128819 | +/* |
| 128820 | +** Initialize a node-reader object to read the node in buffer aNode/nNode. |
| 128821 | +** |
| 128822 | +** If successful, SQLITE_OK is returned and the NodeReader object set to |
| 128823 | +** point to the first entry on the node (if any). Otherwise, an SQLite |
| 128824 | +** error code is returned. |
| 128825 | +*/ |
| 128826 | +static int nodeReaderInit(NodeReader *p, const char *aNode, int nNode){ |
| 128827 | + memset(p, 0, sizeof(NodeReader)); |
| 128828 | + p->aNode = aNode; |
| 128829 | + p->nNode = nNode; |
| 128830 | + |
| 128831 | + /* Figure out if this is a leaf or an internal node. */ |
| 128832 | + if( p->aNode[0] ){ |
| 128833 | + /* An internal node. */ |
| 128834 | + p->iOff = 1 + sqlite3Fts3GetVarint(&p->aNode[1], &p->iChild); |
| 128835 | + }else{ |
| 128836 | + p->iOff = 1; |
| 128837 | + } |
| 128838 | + |
| 128839 | + return nodeReaderNext(p); |
| 128840 | +} |
| 128841 | + |
| 128842 | +/* |
| 128843 | +** This function is called while writing an FTS segment each time a leaf o |
| 128844 | +** node is finished and written to disk. The key (zTerm/nTerm) is guaranteed |
| 128845 | +** to be greater than the largest key on the node just written, but smaller |
| 128846 | +** than or equal to the first key that will be written to the next leaf |
| 128847 | +** node. |
| 128848 | +** |
| 128849 | +** The block id of the leaf node just written to disk may be found in |
| 128850 | +** (pWriter->aNodeWriter[0].iBlock) when this function is called. |
| 128851 | +*/ |
| 128852 | +static int fts3IncrmergePush( |
| 128853 | + Fts3Table *p, /* Fts3 table handle */ |
| 128854 | + IncrmergeWriter *pWriter, /* Writer object */ |
| 128855 | + const char *zTerm, /* Term to write to internal node */ |
| 128856 | + int nTerm /* Bytes at zTerm */ |
| 128857 | +){ |
| 128858 | + sqlite3_int64 iPtr = pWriter->aNodeWriter[0].iBlock; |
| 128859 | + int iLayer; |
| 128860 | + |
| 128861 | + assert( nTerm>0 ); |
| 128862 | + for(iLayer=1; ALWAYS(iLayer<FTS_MAX_APPENDABLE_HEIGHT); iLayer++){ |
| 128863 | + sqlite3_int64 iNextPtr = 0; |
| 128864 | + NodeWriter *pNode = &pWriter->aNodeWriter[iLayer]; |
| 128865 | + int rc = SQLITE_OK; |
| 128866 | + int nPrefix; |
| 128867 | + int nSuffix; |
| 128868 | + int nSpace; |
| 128869 | + |
| 128870 | + /* Figure out how much space the key will consume if it is written to |
| 128871 | + ** the current node of layer iLayer. Due to the prefix compression, |
| 128872 | + ** the space required changes depending on which node the key is to |
| 128873 | + ** be added to. */ |
| 128874 | + nPrefix = fts3PrefixCompress(pNode->key.a, pNode->key.n, zTerm, nTerm); |
| 128875 | + nSuffix = nTerm - nPrefix; |
| 128876 | + nSpace = sqlite3Fts3VarintLen(nPrefix); |
| 128877 | + nSpace += sqlite3Fts3VarintLen(nSuffix) + nSuffix; |
| 128878 | + |
| 128879 | + if( pNode->key.n==0 || (pNode->block.n + nSpace)<=p->nNodeSize ){ |
| 128880 | + /* If the current node of layer iLayer contains zero keys, or if adding |
| 128881 | + ** the key to it will not cause it to grow to larger than nNodeSize |
| 128882 | + ** bytes in size, write the key here. */ |
| 128883 | + |
| 128884 | + Blob *pBlk = &pNode->block; |
| 128885 | + if( pBlk->n==0 ){ |
| 128886 | + blobGrowBuffer(pBlk, p->nNodeSize, &rc); |
| 128887 | + if( rc==SQLITE_OK ){ |
| 128888 | + pBlk->a[0] = (char)iLayer; |
| 128889 | + pBlk->n = 1 + sqlite3Fts3PutVarint(&pBlk->a[1], iPtr); |
| 128890 | + } |
| 128891 | + } |
| 128892 | + blobGrowBuffer(pBlk, pBlk->n + nSpace, &rc); |
| 128893 | + blobGrowBuffer(&pNode->key, nTerm, &rc); |
| 128894 | + |
| 128895 | + if( rc==SQLITE_OK ){ |
| 128896 | + if( pNode->key.n ){ |
| 128897 | + pBlk->n += sqlite3Fts3PutVarint(&pBlk->a[pBlk->n], nPrefix); |
| 128898 | + } |
| 128899 | + pBlk->n += sqlite3Fts3PutVarint(&pBlk->a[pBlk->n], nSuffix); |
| 128900 | + memcpy(&pBlk->a[pBlk->n], &zTerm[nPrefix], nSuffix); |
| 128901 | + pBlk->n += nSuffix; |
| 128902 | + |
| 128903 | + memcpy(pNode->key.a, zTerm, nTerm); |
| 128904 | + pNode->key.n = nTerm; |
| 128905 | + } |
| 128906 | + }else{ |
| 128907 | + /* Otherwise, flush the the current node of layer iLayer to disk. |
| 128908 | + ** Then allocate a new, empty sibling node. The key will be written |
| 128909 | + ** into the parent of this node. */ |
| 128910 | + rc = fts3WriteSegment(p, pNode->iBlock, pNode->block.a, pNode->block.n); |
| 128911 | + |
| 128912 | + assert( pNode->block.nAlloc>=p->nNodeSize ); |
| 128913 | + pNode->block.a[0] = (char)iLayer; |
| 128914 | + pNode->block.n = 1 + sqlite3Fts3PutVarint(&pNode->block.a[1], iPtr+1); |
| 128915 | + |
| 128916 | + iNextPtr = pNode->iBlock; |
| 128917 | + pNode->iBlock++; |
| 128918 | + pNode->key.n = 0; |
| 128919 | + } |
| 128920 | + |
| 128921 | + if( rc!=SQLITE_OK || iNextPtr==0 ) return rc; |
| 128922 | + iPtr = iNextPtr; |
| 128923 | + } |
| 128924 | + |
| 128925 | + assert( 0 ); |
| 128926 | + return 0; |
| 128927 | +} |
| 128928 | + |
| 128929 | +/* |
| 128930 | +** Append a term and (optionally) doclist to the FTS segment node currently |
| 128931 | +** stored in blob *pNode. The node need not contain any terms, but the |
| 128932 | +** header must be written before this function is called. |
| 128933 | +** |
| 128934 | +** A node header is a single 0x00 byte for a leaf node, or a height varint |
| 128935 | +** followed by the left-hand-child varint for an internal node. |
| 128936 | +** |
| 128937 | +** The term to be appended is passed via arguments zTerm/nTerm. For a |
| 128938 | +** leaf node, the doclist is passed as aDoclist/nDoclist. For an internal |
| 128939 | +** node, both aDoclist and nDoclist must be passed 0. |
| 128940 | +** |
| 128941 | +** If the size of the value in blob pPrev is zero, then this is the first |
| 128942 | +** term written to the node. Otherwise, pPrev contains a copy of the |
| 128943 | +** previous term. Before this function returns, it is updated to contain a |
| 128944 | +** copy of zTerm/nTerm. |
| 128945 | +** |
| 128946 | +** It is assumed that the buffer associated with pNode is already large |
| 128947 | +** enough to accommodate the new entry. The buffer associated with pPrev |
| 128948 | +** is extended by this function if requrired. |
| 128949 | +** |
| 128950 | +** If an error (i.e. OOM condition) occurs, an SQLite error code is |
| 128951 | +** returned. Otherwise, SQLITE_OK. |
| 128952 | +*/ |
| 128953 | +static int fts3AppendToNode( |
| 128954 | + Blob *pNode, /* Current node image to append to */ |
| 128955 | + Blob *pPrev, /* Buffer containing previous term written */ |
| 128956 | + const char *zTerm, /* New term to write */ |
| 128957 | + int nTerm, /* Size of zTerm in bytes */ |
| 128958 | + const char *aDoclist, /* Doclist (or NULL) to write */ |
| 128959 | + int nDoclist /* Size of aDoclist in bytes */ |
| 128960 | +){ |
| 128961 | + int rc = SQLITE_OK; /* Return code */ |
| 128962 | + int bFirst = (pPrev->n==0); /* True if this is the first term written */ |
| 128963 | + int nPrefix; /* Size of term prefix in bytes */ |
| 128964 | + int nSuffix; /* Size of term suffix in bytes */ |
| 128965 | + |
| 128966 | + /* Node must have already been started. There must be a doclist for a |
| 128967 | + ** leaf node, and there must not be a doclist for an internal node. */ |
| 128968 | + assert( pNode->n>0 ); |
| 128969 | + assert( (pNode->a[0]=='\0')==(aDoclist!=0) ); |
| 128970 | + |
| 128971 | + blobGrowBuffer(pPrev, nTerm, &rc); |
| 128972 | + if( rc!=SQLITE_OK ) return rc; |
| 128973 | + |
| 128974 | + nPrefix = fts3PrefixCompress(pPrev->a, pPrev->n, zTerm, nTerm); |
| 128975 | + nSuffix = nTerm - nPrefix; |
| 128976 | + memcpy(pPrev->a, zTerm, nTerm); |
| 128977 | + pPrev->n = nTerm; |
| 128978 | + |
| 128979 | + if( bFirst==0 ){ |
| 128980 | + pNode->n += sqlite3Fts3PutVarint(&pNode->a[pNode->n], nPrefix); |
| 128981 | + } |
| 128982 | + pNode->n += sqlite3Fts3PutVarint(&pNode->a[pNode->n], nSuffix); |
| 128983 | + memcpy(&pNode->a[pNode->n], &zTerm[nPrefix], nSuffix); |
| 128984 | + pNode->n += nSuffix; |
| 128985 | + |
| 128986 | + if( aDoclist ){ |
| 128987 | + pNode->n += sqlite3Fts3PutVarint(&pNode->a[pNode->n], nDoclist); |
| 128988 | + memcpy(&pNode->a[pNode->n], aDoclist, nDoclist); |
| 128989 | + pNode->n += nDoclist; |
| 128990 | + } |
| 128991 | + |
| 128992 | + assert( pNode->n<=pNode->nAlloc ); |
| 128993 | + |
| 128994 | + return SQLITE_OK; |
| 128995 | +} |
| 128996 | + |
| 128997 | +/* |
| 128998 | +** Append the current term and doclist pointed to by cursor pCsr to the |
| 128999 | +** appendable b-tree segment opened for writing by pWriter. |
| 129000 | +** |
| 129001 | +** Return SQLITE_OK if successful, or an SQLite error code otherwise. |
| 129002 | +*/ |
| 129003 | +static int fts3IncrmergeAppend( |
| 129004 | + Fts3Table *p, /* Fts3 table handle */ |
| 129005 | + IncrmergeWriter *pWriter, /* Writer object */ |
| 129006 | + Fts3MultiSegReader *pCsr /* Cursor containing term and doclist */ |
| 129007 | +){ |
| 129008 | + const char *zTerm = pCsr->zTerm; |
| 129009 | + int nTerm = pCsr->nTerm; |
| 129010 | + const char *aDoclist = pCsr->aDoclist; |
| 129011 | + int nDoclist = pCsr->nDoclist; |
| 129012 | + int rc = SQLITE_OK; /* Return code */ |
| 129013 | + int nSpace; /* Total space in bytes required on leaf */ |
| 129014 | + int nPrefix; /* Size of prefix shared with previous term */ |
| 129015 | + int nSuffix; /* Size of suffix (nTerm - nPrefix) */ |
| 129016 | + NodeWriter *pLeaf; /* Object used to write leaf nodes */ |
| 129017 | + |
| 129018 | + pLeaf = &pWriter->aNodeWriter[0]; |
| 129019 | + nPrefix = fts3PrefixCompress(pLeaf->key.a, pLeaf->key.n, zTerm, nTerm); |
| 129020 | + nSuffix = nTerm - nPrefix; |
| 129021 | + |
| 129022 | + nSpace = sqlite3Fts3VarintLen(nPrefix); |
| 129023 | + nSpace += sqlite3Fts3VarintLen(nSuffix) + nSuffix; |
| 129024 | + nSpace += sqlite3Fts3VarintLen(nDoclist) + nDoclist; |
| 129025 | + |
| 129026 | + /* If the current block is not empty, and if adding this term/doclist |
| 129027 | + ** to the current block would make it larger than Fts3Table.nNodeSize |
| 129028 | + ** bytes, write this block out to the database. */ |
| 129029 | + if( pLeaf->block.n>0 && (pLeaf->block.n + nSpace)>p->nNodeSize ){ |
| 129030 | + rc = fts3WriteSegment(p, pLeaf->iBlock, pLeaf->block.a, pLeaf->block.n); |
| 129031 | + pWriter->nWork++; |
| 129032 | + |
| 129033 | + /* Add the current term to the parent node. The term added to the |
| 129034 | + ** parent must: |
| 129035 | + ** |
| 129036 | + ** a) be greater than the largest term on the leaf node just written |
| 129037 | + ** to the database (still available in pLeaf->key), and |
| 129038 | + ** |
| 129039 | + ** b) be less than or equal to the term about to be added to the new |
| 129040 | + ** leaf node (zTerm/nTerm). |
| 129041 | + ** |
| 129042 | + ** In other words, it must be the prefix of zTerm 1 byte longer than |
| 129043 | + ** the common prefix (if any) of zTerm and pWriter->zTerm. |
| 129044 | + */ |
| 129045 | + if( rc==SQLITE_OK ){ |
| 129046 | + rc = fts3IncrmergePush(p, pWriter, zTerm, nPrefix+1); |
| 129047 | + } |
| 129048 | + |
| 129049 | + /* Advance to the next output block */ |
| 129050 | + pLeaf->iBlock++; |
| 129051 | + pLeaf->key.n = 0; |
| 129052 | + pLeaf->block.n = 0; |
| 129053 | + |
| 129054 | + nPrefix = 0; |
| 129055 | + nSuffix = nTerm; |
| 129056 | + nSpace = 1; |
| 129057 | + nSpace += sqlite3Fts3VarintLen(nSuffix) + nSuffix; |
| 129058 | + nSpace += sqlite3Fts3VarintLen(nDoclist) + nDoclist; |
| 129059 | + } |
| 129060 | + |
| 129061 | + blobGrowBuffer(&pLeaf->block, pLeaf->block.n + nSpace, &rc); |
| 129062 | + |
| 129063 | + if( rc==SQLITE_OK ){ |
| 129064 | + if( pLeaf->block.n==0 ){ |
| 129065 | + pLeaf->block.n = 1; |
| 129066 | + pLeaf->block.a[0] = '\0'; |
| 129067 | + } |
| 129068 | + rc = fts3AppendToNode( |
| 129069 | + &pLeaf->block, &pLeaf->key, zTerm, nTerm, aDoclist, nDoclist |
| 129070 | + ); |
| 129071 | + } |
| 129072 | + |
| 129073 | + return rc; |
| 129074 | +} |
| 129075 | + |
| 129076 | +/* |
| 129077 | +** This function is called to release all dynamic resources held by the |
| 129078 | +** merge-writer object pWriter, and if no error has occurred, to flush |
| 129079 | +** all outstanding node buffers held by pWriter to disk. |
| 129080 | +** |
| 129081 | +** If *pRc is not SQLITE_OK when this function is called, then no attempt |
| 129082 | +** is made to write any data to disk. Instead, this function serves only |
| 129083 | +** to release outstanding resources. |
| 129084 | +** |
| 129085 | +** Otherwise, if *pRc is initially SQLITE_OK and an error occurs while |
| 129086 | +** flushing buffers to disk, *pRc is set to an SQLite error code before |
| 129087 | +** returning. |
| 129088 | +*/ |
| 129089 | +static void fts3IncrmergeRelease( |
| 129090 | + Fts3Table *p, /* FTS3 table handle */ |
| 129091 | + IncrmergeWriter *pWriter, /* Merge-writer object */ |
| 129092 | + int *pRc /* IN/OUT: Error code */ |
| 129093 | +){ |
| 129094 | + int i; /* Used to iterate through non-root layers */ |
| 129095 | + int iRoot; /* Index of root in pWriter->aNodeWriter */ |
| 129096 | + NodeWriter *pRoot; /* NodeWriter for root node */ |
| 129097 | + int rc = *pRc; /* Error code */ |
| 129098 | + |
| 129099 | + /* Set iRoot to the index in pWriter->aNodeWriter[] of the output segment |
| 129100 | + ** root node. If the segment fits entirely on a single leaf node, iRoot |
| 129101 | + ** will be set to 0. If the root node is the parent of the leaves, iRoot |
| 129102 | + ** will be 1. And so on. */ |
| 129103 | + for(iRoot=FTS_MAX_APPENDABLE_HEIGHT-1; iRoot>=0; iRoot--){ |
| 129104 | + NodeWriter *pNode = &pWriter->aNodeWriter[iRoot]; |
| 129105 | + if( pNode->block.n>0 ) break; |
| 129106 | + assert( *pRc || pNode->block.nAlloc==0 ); |
| 129107 | + assert( *pRc || pNode->key.nAlloc==0 ); |
| 129108 | + sqlite3_free(pNode->block.a); |
| 129109 | + sqlite3_free(pNode->key.a); |
| 129110 | + } |
| 129111 | + |
| 129112 | + /* Empty output segment. This is a no-op. */ |
| 129113 | + if( iRoot<0 ) return; |
| 129114 | + |
| 129115 | + /* The entire output segment fits on a single node. Normally, this means |
| 129116 | + ** the node would be stored as a blob in the "root" column of the %_segdir |
| 129117 | + ** table. However, this is not permitted in this case. The problem is that |
| 129118 | + ** space has already been reserved in the %_segments table, and so the |
| 129119 | + ** start_block and end_block fields of the %_segdir table must be populated. |
| 129120 | + ** And, by design or by accident, released versions of FTS cannot handle |
| 129121 | + ** segments that fit entirely on the root node with start_block!=0. |
| 129122 | + ** |
| 129123 | + ** Instead, create a synthetic root node that contains nothing but a |
| 129124 | + ** pointer to the single content node. So that the segment consists of a |
| 129125 | + ** single leaf and a single interior (root) node. |
| 129126 | + ** |
| 129127 | + ** Todo: Better might be to defer allocating space in the %_segments |
| 129128 | + ** table until we are sure it is needed. |
| 129129 | + */ |
| 129130 | + if( iRoot==0 ){ |
| 129131 | + Blob *pBlock = &pWriter->aNodeWriter[1].block; |
| 129132 | + blobGrowBuffer(pBlock, 1 + FTS3_VARINT_MAX, &rc); |
| 129133 | + if( rc==SQLITE_OK ){ |
| 129134 | + pBlock->a[0] = 0x01; |
| 129135 | + pBlock->n = 1 + sqlite3Fts3PutVarint( |
| 129136 | + &pBlock->a[1], pWriter->aNodeWriter[0].iBlock |
| 129137 | + ); |
| 129138 | + } |
| 129139 | + iRoot = 1; |
| 129140 | + } |
| 129141 | + pRoot = &pWriter->aNodeWriter[iRoot]; |
| 129142 | + |
| 129143 | + /* Flush all currently outstanding nodes to disk. */ |
| 129144 | + for(i=0; i<iRoot; i++){ |
| 129145 | + NodeWriter *pNode = &pWriter->aNodeWriter[i]; |
| 129146 | + if( pNode->block.n>0 && rc==SQLITE_OK ){ |
| 129147 | + rc = fts3WriteSegment(p, pNode->iBlock, pNode->block.a, pNode->block.n); |
| 129148 | + } |
| 129149 | + sqlite3_free(pNode->block.a); |
| 129150 | + sqlite3_free(pNode->key.a); |
| 129151 | + } |
| 129152 | + |
| 129153 | + /* Write the %_segdir record. */ |
| 129154 | + if( rc==SQLITE_OK ){ |
| 129155 | + rc = fts3WriteSegdir(p, |
| 129156 | + pWriter->iAbsLevel+1, /* level */ |
| 129157 | + pWriter->iIdx, /* idx */ |
| 129158 | + pWriter->iStart, /* start_block */ |
| 129159 | + pWriter->aNodeWriter[0].iBlock, /* leaves_end_block */ |
| 129160 | + pWriter->iEnd, /* end_block */ |
| 129161 | + pRoot->block.a, pRoot->block.n /* root */ |
| 129162 | + ); |
| 129163 | + } |
| 129164 | + sqlite3_free(pRoot->block.a); |
| 129165 | + sqlite3_free(pRoot->key.a); |
| 129166 | + |
| 129167 | + *pRc = rc; |
| 129168 | +} |
| 129169 | + |
| 129170 | +/* |
| 129171 | +** Compare the term in buffer zLhs (size in bytes nLhs) with that in |
| 129172 | +** zRhs (size in bytes nRhs) using memcmp. If one term is a prefix of |
| 129173 | +** the other, it is considered to be smaller than the other. |
| 129174 | +** |
| 129175 | +** Return -ve if zLhs is smaller than zRhs, 0 if it is equal, or +ve |
| 129176 | +** if it is greater. |
| 129177 | +*/ |
| 129178 | +static int fts3TermCmp( |
| 129179 | + const char *zLhs, int nLhs, /* LHS of comparison */ |
| 129180 | + const char *zRhs, int nRhs /* RHS of comparison */ |
| 129181 | +){ |
| 129182 | + int nCmp = MIN(nLhs, nRhs); |
| 129183 | + int res; |
| 129184 | + |
| 129185 | + res = memcmp(zLhs, zRhs, nCmp); |
| 129186 | + if( res==0 ) res = nLhs - nRhs; |
| 129187 | + |
| 129188 | + return res; |
| 129189 | +} |
| 129190 | + |
| 129191 | + |
| 129192 | +/* |
| 129193 | +** Query to see if the entry in the %_segments table with blockid iEnd is |
| 129194 | +** NULL. If no error occurs and the entry is NULL, set *pbRes 1 before |
| 129195 | +** returning. Otherwise, set *pbRes to 0. |
| 129196 | +** |
| 129197 | +** Or, if an error occurs while querying the database, return an SQLite |
| 129198 | +** error code. The final value of *pbRes is undefined in this case. |
| 129199 | +** |
| 129200 | +** This is used to test if a segment is an "appendable" segment. If it |
| 129201 | +** is, then a NULL entry has been inserted into the %_segments table |
| 129202 | +** with blockid %_segdir.end_block. |
| 129203 | +*/ |
| 129204 | +static int fts3IsAppendable(Fts3Table *p, sqlite3_int64 iEnd, int *pbRes){ |
| 129205 | + int bRes = 0; /* Result to set *pbRes to */ |
| 129206 | + sqlite3_stmt *pCheck = 0; /* Statement to query database with */ |
| 129207 | + int rc; /* Return code */ |
| 129208 | + |
| 129209 | + rc = fts3SqlStmt(p, SQL_SEGMENT_IS_APPENDABLE, &pCheck, 0); |
| 129210 | + if( rc==SQLITE_OK ){ |
| 129211 | + sqlite3_bind_int64(pCheck, 1, iEnd); |
| 129212 | + if( SQLITE_ROW==sqlite3_step(pCheck) ) bRes = 1; |
| 129213 | + rc = sqlite3_reset(pCheck); |
| 129214 | + } |
| 129215 | + |
| 129216 | + *pbRes = bRes; |
| 129217 | + return rc; |
| 129218 | +} |
| 129219 | + |
| 129220 | +/* |
| 129221 | +** This function is called when initializing an incremental-merge operation. |
| 129222 | +** It checks if the existing segment with index value iIdx at absolute level |
| 129223 | +** (iAbsLevel+1) can be appended to by the incremental merge. If it can, the |
| 129224 | +** merge-writer object *pWriter is initialized to write to it. |
| 129225 | +** |
| 129226 | +** An existing segment can be appended to by an incremental merge if: |
| 129227 | +** |
| 129228 | +** * It was initially created as an appendable segment (with all required |
| 129229 | +** space pre-allocated), and |
| 129230 | +** |
| 129231 | +** * The first key read from the input (arguments zKey and nKey) is |
| 129232 | +** greater than the largest key currently stored in the potential |
| 129233 | +** output segment. |
| 129234 | +*/ |
| 129235 | +static int fts3IncrmergeLoad( |
| 129236 | + Fts3Table *p, /* Fts3 table handle */ |
| 129237 | + sqlite3_int64 iAbsLevel, /* Absolute level of input segments */ |
| 129238 | + int iIdx, /* Index of candidate output segment */ |
| 129239 | + const char *zKey, /* First key to write */ |
| 129240 | + int nKey, /* Number of bytes in nKey */ |
| 129241 | + IncrmergeWriter *pWriter /* Populate this object */ |
| 129242 | +){ |
| 129243 | + int rc; /* Return code */ |
| 129244 | + sqlite3_stmt *pSelect = 0; /* SELECT to read %_segdir entry */ |
| 129245 | + |
| 129246 | + rc = fts3SqlStmt(p, SQL_SELECT_SEGDIR, &pSelect, 0); |
| 129247 | + if( rc==SQLITE_OK ){ |
| 129248 | + sqlite3_int64 iStart = 0; /* Value of %_segdir.start_block */ |
| 129249 | + sqlite3_int64 iLeafEnd = 0; /* Value of %_segdir.leaves_end_block */ |
| 129250 | + sqlite3_int64 iEnd = 0; /* Value of %_segdir.end_block */ |
| 129251 | + const char *aRoot = 0; /* Pointer to %_segdir.root buffer */ |
| 129252 | + int nRoot = 0; /* Size of aRoot[] in bytes */ |
| 129253 | + int rc2; /* Return code from sqlite3_reset() */ |
| 129254 | + int bAppendable = 0; /* Set to true if segment is appendable */ |
| 129255 | + |
| 129256 | + /* Read the %_segdir entry for index iIdx absolute level (iAbsLevel+1) */ |
| 129257 | + sqlite3_bind_int64(pSelect, 1, iAbsLevel+1); |
| 129258 | + sqlite3_bind_int(pSelect, 2, iIdx); |
| 129259 | + if( sqlite3_step(pSelect)==SQLITE_ROW ){ |
| 129260 | + iStart = sqlite3_column_int64(pSelect, 1); |
| 129261 | + iLeafEnd = sqlite3_column_int64(pSelect, 2); |
| 129262 | + iEnd = sqlite3_column_int64(pSelect, 3); |
| 129263 | + nRoot = sqlite3_column_bytes(pSelect, 4); |
| 129264 | + aRoot = sqlite3_column_blob(pSelect, 4); |
| 129265 | + }else{ |
| 129266 | + return sqlite3_reset(pSelect); |
| 129267 | + } |
| 129268 | + |
| 129269 | + /* Check for the zero-length marker in the %_segments table */ |
| 129270 | + rc = fts3IsAppendable(p, iEnd, &bAppendable); |
| 129271 | + |
| 129272 | + /* Check that zKey/nKey is larger than the largest key the candidate */ |
| 129273 | + if( rc==SQLITE_OK && bAppendable ){ |
| 129274 | + char *aLeaf = 0; |
| 129275 | + int nLeaf = 0; |
| 129276 | + |
| 129277 | + rc = sqlite3Fts3ReadBlock(p, iLeafEnd, &aLeaf, &nLeaf, 0); |
| 129278 | + if( rc==SQLITE_OK ){ |
| 129279 | + NodeReader reader; |
| 129280 | + for(rc = nodeReaderInit(&reader, aLeaf, nLeaf); |
| 129281 | + rc==SQLITE_OK && reader.aNode; |
| 129282 | + rc = nodeReaderNext(&reader) |
| 129283 | + ){ |
| 129284 | + assert( reader.aNode ); |
| 129285 | + } |
| 129286 | + if( fts3TermCmp(zKey, nKey, reader.term.a, reader.term.n)<=0 ){ |
| 129287 | + bAppendable = 0; |
| 129288 | + } |
| 129289 | + nodeReaderRelease(&reader); |
| 129290 | + } |
| 129291 | + sqlite3_free(aLeaf); |
| 129292 | + } |
| 129293 | + |
| 129294 | + if( rc==SQLITE_OK && bAppendable ){ |
| 129295 | + /* It is possible to append to this segment. Set up the IncrmergeWriter |
| 129296 | + ** object to do so. */ |
| 129297 | + int i; |
| 129298 | + int nHeight = (int)aRoot[0]; |
| 129299 | + NodeWriter *pNode; |
| 129300 | + |
| 129301 | + pWriter->nLeafEst = (int)((iEnd - iStart) + 1)/FTS_MAX_APPENDABLE_HEIGHT; |
| 129302 | + pWriter->iStart = iStart; |
| 129303 | + pWriter->iEnd = iEnd; |
| 129304 | + pWriter->iAbsLevel = iAbsLevel; |
| 129305 | + pWriter->iIdx = iIdx; |
| 129306 | + |
| 129307 | + for(i=nHeight+1; i<FTS_MAX_APPENDABLE_HEIGHT; i++){ |
| 129308 | + pWriter->aNodeWriter[i].iBlock = pWriter->iStart + i*pWriter->nLeafEst; |
| 129309 | + } |
| 129310 | + |
| 129311 | + pNode = &pWriter->aNodeWriter[nHeight]; |
| 129312 | + pNode->iBlock = pWriter->iStart + pWriter->nLeafEst*nHeight; |
| 129313 | + blobGrowBuffer(&pNode->block, MAX(nRoot, p->nNodeSize), &rc); |
| 129314 | + if( rc==SQLITE_OK ){ |
| 129315 | + memcpy(pNode->block.a, aRoot, nRoot); |
| 129316 | + pNode->block.n = nRoot; |
| 129317 | + } |
| 129318 | + |
| 129319 | + for(i=nHeight; i>=0 && rc==SQLITE_OK; i--){ |
| 129320 | + NodeReader reader; |
| 129321 | + pNode = &pWriter->aNodeWriter[i]; |
| 129322 | + |
| 129323 | + rc = nodeReaderInit(&reader, pNode->block.a, pNode->block.n); |
| 129324 | + while( reader.aNode && rc==SQLITE_OK ) rc = nodeReaderNext(&reader); |
| 129325 | + blobGrowBuffer(&pNode->key, reader.term.n, &rc); |
| 129326 | + if( rc==SQLITE_OK ){ |
| 129327 | + memcpy(pNode->key.a, reader.term.a, reader.term.n); |
| 129328 | + pNode->key.n = reader.term.n; |
| 129329 | + if( i>0 ){ |
| 129330 | + char *aBlock = 0; |
| 129331 | + int nBlock = 0; |
| 129332 | + pNode = &pWriter->aNodeWriter[i-1]; |
| 129333 | + pNode->iBlock = reader.iChild; |
| 129334 | + rc = sqlite3Fts3ReadBlock(p, reader.iChild, &aBlock, &nBlock, 0); |
| 129335 | + blobGrowBuffer(&pNode->block, MAX(nBlock, p->nNodeSize), &rc); |
| 129336 | + if( rc==SQLITE_OK ){ |
| 129337 | + memcpy(pNode->block.a, aBlock, nBlock); |
| 129338 | + pNode->block.n = nBlock; |
| 129339 | + } |
| 129340 | + sqlite3_free(aBlock); |
| 129341 | + } |
| 129342 | + } |
| 129343 | + nodeReaderRelease(&reader); |
| 129344 | + } |
| 129345 | + } |
| 129346 | + |
| 129347 | + rc2 = sqlite3_reset(pSelect); |
| 129348 | + if( rc==SQLITE_OK ) rc = rc2; |
| 129349 | + } |
| 129350 | + |
| 129351 | + return rc; |
| 129352 | +} |
| 129353 | + |
| 129354 | +/* |
| 129355 | +** Determine the largest segment index value that exists within absolute |
| 129356 | +** level iAbsLevel+1. If no error occurs, set *piIdx to this value plus |
| 129357 | +** one before returning SQLITE_OK. Or, if there are no segments at all |
| 129358 | +** within level iAbsLevel, set *piIdx to zero. |
| 129359 | +** |
| 129360 | +** If an error occurs, return an SQLite error code. The final value of |
| 129361 | +** *piIdx is undefined in this case. |
| 129362 | +*/ |
| 129363 | +static int fts3IncrmergeOutputIdx( |
| 129364 | + Fts3Table *p, /* FTS Table handle */ |
| 129365 | + sqlite3_int64 iAbsLevel, /* Absolute index of input segments */ |
| 129366 | + int *piIdx /* OUT: Next free index at iAbsLevel+1 */ |
| 129367 | +){ |
| 129368 | + int rc; |
| 129369 | + sqlite3_stmt *pOutputIdx = 0; /* SQL used to find output index */ |
| 129370 | + |
| 129371 | + rc = fts3SqlStmt(p, SQL_NEXT_SEGMENT_INDEX, &pOutputIdx, 0); |
| 129372 | + if( rc==SQLITE_OK ){ |
| 129373 | + sqlite3_bind_int64(pOutputIdx, 1, iAbsLevel+1); |
| 129374 | + sqlite3_step(pOutputIdx); |
| 129375 | + *piIdx = sqlite3_column_int(pOutputIdx, 0); |
| 129376 | + rc = sqlite3_reset(pOutputIdx); |
| 129377 | + } |
| 129378 | + |
| 129379 | + return rc; |
| 129380 | +} |
| 129381 | + |
| 129382 | +/* |
| 129383 | +** Allocate an appendable output segment on absolute level iAbsLevel+1 |
| 129384 | +** with idx value iIdx. |
| 129385 | +** |
| 129386 | +** In the %_segdir table, a segment is defined by the values in three |
| 129387 | +** columns: |
| 129388 | +** |
| 129389 | +** start_block |
| 129390 | +** leaves_end_block |
| 129391 | +** end_block |
| 129392 | +** |
| 129393 | +** When an appendable segment is allocated, it is estimated that the |
| 129394 | +** maximum number of leaf blocks that may be required is the sum of the |
| 129395 | +** number of leaf blocks consumed by the input segments, plus the number |
| 129396 | +** of input segments, multiplied by two. This value is stored in stack |
| 129397 | +** variable nLeafEst. |
| 129398 | +** |
| 129399 | +** A total of 16*nLeafEst blocks are allocated when an appendable segment |
| 129400 | +** is created ((1 + end_block - start_block)==16*nLeafEst). The contiguous |
| 129401 | +** array of leaf nodes starts at the first block allocated. The array |
| 129402 | +** of interior nodes that are parents of the leaf nodes start at block |
| 129403 | +** (start_block + (1 + end_block - start_block) / 16). And so on. |
| 129404 | +** |
| 129405 | +** In the actual code below, the value "16" is replaced with the |
| 129406 | +** pre-processor macro FTS_MAX_APPENDABLE_HEIGHT. |
| 129407 | +*/ |
| 129408 | +static int fts3IncrmergeWriter( |
| 129409 | + Fts3Table *p, /* Fts3 table handle */ |
| 129410 | + sqlite3_int64 iAbsLevel, /* Absolute level of input segments */ |
| 129411 | + int iIdx, /* Index of new output segment */ |
| 129412 | + Fts3MultiSegReader *pCsr, /* Cursor that data will be read from */ |
| 129413 | + IncrmergeWriter *pWriter /* Populate this object */ |
| 129414 | +){ |
| 129415 | + int rc; /* Return Code */ |
| 129416 | + int i; /* Iterator variable */ |
| 129417 | + int nLeafEst = 0; /* Blocks allocated for leaf nodes */ |
| 129418 | + sqlite3_stmt *pLeafEst = 0; /* SQL used to determine nLeafEst */ |
| 129419 | + sqlite3_stmt *pFirstBlock = 0; /* SQL used to determine first block */ |
| 129420 | + |
| 129421 | + /* Calculate nLeafEst. */ |
| 129422 | + rc = fts3SqlStmt(p, SQL_MAX_LEAF_NODE_ESTIMATE, &pLeafEst, 0); |
| 129423 | + if( rc==SQLITE_OK ){ |
| 129424 | + sqlite3_bind_int64(pLeafEst, 1, iAbsLevel); |
| 129425 | + sqlite3_bind_int64(pLeafEst, 2, pCsr->nSegment); |
| 129426 | + if( SQLITE_ROW==sqlite3_step(pLeafEst) ){ |
| 129427 | + nLeafEst = sqlite3_column_int(pLeafEst, 0); |
| 129428 | + } |
| 129429 | + rc = sqlite3_reset(pLeafEst); |
| 129430 | + } |
| 129431 | + if( rc!=SQLITE_OK ) return rc; |
| 129432 | + |
| 129433 | + /* Calculate the first block to use in the output segment */ |
| 129434 | + rc = fts3SqlStmt(p, SQL_NEXT_SEGMENTS_ID, &pFirstBlock, 0); |
| 129435 | + if( rc==SQLITE_OK ){ |
| 129436 | + if( SQLITE_ROW==sqlite3_step(pFirstBlock) ){ |
| 129437 | + pWriter->iStart = sqlite3_column_int64(pFirstBlock, 0); |
| 129438 | + pWriter->iEnd = pWriter->iStart - 1; |
| 129439 | + pWriter->iEnd += nLeafEst * FTS_MAX_APPENDABLE_HEIGHT; |
| 129440 | + } |
| 129441 | + rc = sqlite3_reset(pFirstBlock); |
| 129442 | + } |
| 129443 | + if( rc!=SQLITE_OK ) return rc; |
| 129444 | + |
| 129445 | + /* Insert the marker in the %_segments table to make sure nobody tries |
| 129446 | + ** to steal the space just allocated. This is also used to identify |
| 129447 | + ** appendable segments. */ |
| 129448 | + rc = fts3WriteSegment(p, pWriter->iEnd, 0, 0); |
| 129449 | + if( rc!=SQLITE_OK ) return rc; |
| 129450 | + |
| 129451 | + pWriter->iAbsLevel = iAbsLevel; |
| 129452 | + pWriter->nLeafEst = nLeafEst; |
| 129453 | + pWriter->iIdx = iIdx; |
| 129454 | + |
| 129455 | + /* Set up the array of NodeWriter objects */ |
| 129456 | + for(i=0; i<FTS_MAX_APPENDABLE_HEIGHT; i++){ |
| 129457 | + pWriter->aNodeWriter[i].iBlock = pWriter->iStart + i*pWriter->nLeafEst; |
| 129458 | + } |
| 129459 | + return SQLITE_OK; |
| 129460 | +} |
| 129461 | + |
| 129462 | +/* |
| 129463 | +** Remove an entry from the %_segdir table. This involves running the |
| 129464 | +** following two statements: |
| 129465 | +** |
| 129466 | +** DELETE FROM %_segdir WHERE level = :iAbsLevel AND idx = :iIdx |
| 129467 | +** UPDATE %_segdir SET idx = idx - 1 WHERE level = :iAbsLevel AND idx > :iIdx |
| 129468 | +** |
| 129469 | +** The DELETE statement removes the specific %_segdir level. The UPDATE |
| 129470 | +** statement ensures that the remaining segments have contiguously allocated |
| 129471 | +** idx values. |
| 129472 | +*/ |
| 129473 | +static int fts3RemoveSegdirEntry( |
| 129474 | + Fts3Table *p, /* FTS3 table handle */ |
| 129475 | + sqlite3_int64 iAbsLevel, /* Absolute level to delete from */ |
| 129476 | + int iIdx /* Index of %_segdir entry to delete */ |
| 129477 | +){ |
| 129478 | + int rc; /* Return code */ |
| 129479 | + sqlite3_stmt *pDelete = 0; /* DELETE statement */ |
| 129480 | + |
| 129481 | + rc = fts3SqlStmt(p, SQL_DELETE_SEGDIR_ENTRY, &pDelete, 0); |
| 129482 | + if( rc==SQLITE_OK ){ |
| 129483 | + sqlite3_bind_int64(pDelete, 1, iAbsLevel); |
| 129484 | + sqlite3_bind_int(pDelete, 2, iIdx); |
| 129485 | + sqlite3_step(pDelete); |
| 129486 | + rc = sqlite3_reset(pDelete); |
| 129487 | + } |
| 129488 | + |
| 129489 | + return rc; |
| 129490 | +} |
| 129491 | + |
| 129492 | +/* |
| 129493 | +** One or more segments have just been removed from absolute level iAbsLevel. |
| 129494 | +** Update the 'idx' values of the remaining segments in the level so that |
| 129495 | +** the idx values are a contiguous sequence starting from 0. |
| 129496 | +*/ |
| 129497 | +static int fts3RepackSegdirLevel( |
| 129498 | + Fts3Table *p, /* FTS3 table handle */ |
| 129499 | + sqlite3_int64 iAbsLevel /* Absolute level to repack */ |
| 129500 | +){ |
| 129501 | + int rc; /* Return code */ |
| 129502 | + int *aIdx = 0; /* Array of remaining idx values */ |
| 129503 | + int nIdx = 0; /* Valid entries in aIdx[] */ |
| 129504 | + int nAlloc = 0; /* Allocated size of aIdx[] */ |
| 129505 | + int i; /* Iterator variable */ |
| 129506 | + sqlite3_stmt *pSelect = 0; /* Select statement to read idx values */ |
| 129507 | + sqlite3_stmt *pUpdate = 0; /* Update statement to modify idx values */ |
| 129508 | + |
| 129509 | + rc = fts3SqlStmt(p, SQL_SELECT_INDEXES, &pSelect, 0); |
| 129510 | + if( rc==SQLITE_OK ){ |
| 129511 | + int rc2; |
| 129512 | + sqlite3_bind_int64(pSelect, 1, iAbsLevel); |
| 129513 | + while( SQLITE_ROW==sqlite3_step(pSelect) ){ |
| 129514 | + if( nIdx>=nAlloc ){ |
| 129515 | + int *aNew; |
| 129516 | + nAlloc += 16; |
| 129517 | + aNew = sqlite3_realloc(aIdx, nAlloc*sizeof(int)); |
| 129518 | + if( !aNew ){ |
| 129519 | + rc = SQLITE_NOMEM; |
| 129520 | + break; |
| 129521 | + } |
| 129522 | + aIdx = aNew; |
| 129523 | + } |
| 129524 | + aIdx[nIdx++] = sqlite3_column_int(pSelect, 0); |
| 129525 | + } |
| 129526 | + rc2 = sqlite3_reset(pSelect); |
| 129527 | + if( rc==SQLITE_OK ) rc = rc2; |
| 129528 | + } |
| 129529 | + |
| 129530 | + if( rc==SQLITE_OK ){ |
| 129531 | + rc = fts3SqlStmt(p, SQL_SHIFT_SEGDIR_ENTRY, &pUpdate, 0); |
| 129532 | + } |
| 129533 | + if( rc==SQLITE_OK ){ |
| 129534 | + sqlite3_bind_int64(pUpdate, 2, iAbsLevel); |
| 129535 | + } |
| 129536 | + |
| 129537 | + assert( p->bIgnoreSavepoint==0 ); |
| 129538 | + p->bIgnoreSavepoint = 1; |
| 129539 | + for(i=0; rc==SQLITE_OK && i<nIdx; i++){ |
| 129540 | + if( aIdx[i]!=i ){ |
| 129541 | + sqlite3_bind_int(pUpdate, 3, aIdx[i]); |
| 129542 | + sqlite3_bind_int(pUpdate, 1, i); |
| 129543 | + sqlite3_step(pUpdate); |
| 129544 | + rc = sqlite3_reset(pUpdate); |
| 129545 | + } |
| 129546 | + } |
| 129547 | + p->bIgnoreSavepoint = 0; |
| 129548 | + |
| 129549 | + sqlite3_free(aIdx); |
| 129550 | + return rc; |
| 129551 | +} |
| 129552 | + |
| 129553 | +static void fts3StartNode(Blob *pNode, int iHeight, sqlite3_int64 iChild){ |
| 129554 | + pNode->a[0] = (char)iHeight; |
| 129555 | + if( iChild ){ |
| 129556 | + assert( pNode->nAlloc>=1+sqlite3Fts3VarintLen(iChild) ); |
| 129557 | + pNode->n = 1 + sqlite3Fts3PutVarint(&pNode->a[1], iChild); |
| 129558 | + }else{ |
| 129559 | + assert( pNode->nAlloc>=1 ); |
| 129560 | + pNode->n = 1; |
| 129561 | + } |
| 129562 | +} |
| 129563 | + |
| 129564 | +/* |
| 129565 | +** The first two arguments are a pointer to and the size of a segment b-tree |
| 129566 | +** node. The node may be a leaf or an internal node. |
| 129567 | +** |
| 129568 | +** This function creates a new node image in blob object *pNew by copying |
| 129569 | +** all terms that are greater than or equal to zTerm/nTerm (for leaf nodes) |
| 129570 | +** or greater than zTerm/nTerm (for internal nodes) from aNode/nNode. |
| 129571 | +*/ |
| 129572 | +static int fts3TruncateNode( |
| 129573 | + const char *aNode, /* Current node image */ |
| 129574 | + int nNode, /* Size of aNode in bytes */ |
| 129575 | + Blob *pNew, /* OUT: Write new node image here */ |
| 129576 | + const char *zTerm, /* Omit all terms smaller than this */ |
| 129577 | + int nTerm, /* Size of zTerm in bytes */ |
| 129578 | + sqlite3_int64 *piBlock /* OUT: Block number in next layer down */ |
| 129579 | +){ |
| 129580 | + NodeReader reader; /* Reader object */ |
| 129581 | + Blob prev = {0, 0, 0}; /* Previous term written to new node */ |
| 129582 | + int rc = SQLITE_OK; /* Return code */ |
| 129583 | + int bLeaf = aNode[0]=='\0'; /* True for a leaf node */ |
| 129584 | + |
| 129585 | + /* Allocate required output space */ |
| 129586 | + blobGrowBuffer(pNew, nNode, &rc); |
| 129587 | + if( rc!=SQLITE_OK ) return rc; |
| 129588 | + pNew->n = 0; |
| 129589 | + |
| 129590 | + /* Populate new node buffer */ |
| 129591 | + for(rc = nodeReaderInit(&reader, aNode, nNode); |
| 129592 | + rc==SQLITE_OK && reader.aNode; |
| 129593 | + rc = nodeReaderNext(&reader) |
| 129594 | + ){ |
| 129595 | + if( pNew->n==0 ){ |
| 129596 | + int res = fts3TermCmp(reader.term.a, reader.term.n, zTerm, nTerm); |
| 129597 | + if( res<0 || (bLeaf==0 && res==0) ) continue; |
| 129598 | + fts3StartNode(pNew, (int)aNode[0], reader.iChild); |
| 129599 | + *piBlock = reader.iChild; |
| 129600 | + } |
| 129601 | + rc = fts3AppendToNode( |
| 129602 | + pNew, &prev, reader.term.a, reader.term.n, |
| 129603 | + reader.aDoclist, reader.nDoclist |
| 129604 | + ); |
| 129605 | + if( rc!=SQLITE_OK ) break; |
| 129606 | + } |
| 129607 | + if( pNew->n==0 ){ |
| 129608 | + fts3StartNode(pNew, (int)aNode[0], reader.iChild); |
| 129609 | + *piBlock = reader.iChild; |
| 129610 | + } |
| 129611 | + assert( pNew->n<=pNew->nAlloc ); |
| 129612 | + |
| 129613 | + nodeReaderRelease(&reader); |
| 129614 | + sqlite3_free(prev.a); |
| 129615 | + return rc; |
| 129616 | +} |
| 129617 | + |
| 129618 | +/* |
| 129619 | +** Remove all terms smaller than zTerm/nTerm from segment iIdx in absolute |
| 129620 | +** level iAbsLevel. This may involve deleting entries from the %_segments |
| 129621 | +** table, and modifying existing entries in both the %_segments and %_segdir |
| 129622 | +** tables. |
| 129623 | +** |
| 129624 | +** SQLITE_OK is returned if the segment is updated successfully. Or an |
| 129625 | +** SQLite error code otherwise. |
| 129626 | +*/ |
| 129627 | +static int fts3TruncateSegment( |
| 129628 | + Fts3Table *p, /* FTS3 table handle */ |
| 129629 | + sqlite3_int64 iAbsLevel, /* Absolute level of segment to modify */ |
| 129630 | + int iIdx, /* Index within level of segment to modify */ |
| 129631 | + const char *zTerm, /* Remove terms smaller than this */ |
| 129632 | + int nTerm /* Number of bytes in buffer zTerm */ |
| 129633 | +){ |
| 129634 | + int rc = SQLITE_OK; /* Return code */ |
| 129635 | + Blob root = {0,0,0}; /* New root page image */ |
| 129636 | + Blob block = {0,0,0}; /* Buffer used for any other block */ |
| 129637 | + sqlite3_int64 iBlock = 0; /* Block id */ |
| 129638 | + sqlite3_int64 iNewStart = 0; /* New value for iStartBlock */ |
| 129639 | + sqlite3_int64 iOldStart = 0; /* Old value for iStartBlock */ |
| 129640 | + sqlite3_stmt *pFetch = 0; /* Statement used to fetch segdir */ |
| 129641 | + |
| 129642 | + rc = fts3SqlStmt(p, SQL_SELECT_SEGDIR, &pFetch, 0); |
| 129643 | + if( rc==SQLITE_OK ){ |
| 129644 | + int rc2; /* sqlite3_reset() return code */ |
| 129645 | + sqlite3_bind_int64(pFetch, 1, iAbsLevel); |
| 129646 | + sqlite3_bind_int(pFetch, 2, iIdx); |
| 129647 | + if( SQLITE_ROW==sqlite3_step(pFetch) ){ |
| 129648 | + const char *aRoot = sqlite3_column_blob(pFetch, 4); |
| 129649 | + int nRoot = sqlite3_column_bytes(pFetch, 4); |
| 129650 | + iOldStart = sqlite3_column_int64(pFetch, 1); |
| 129651 | + rc = fts3TruncateNode(aRoot, nRoot, &root, zTerm, nTerm, &iBlock); |
| 129652 | + } |
| 129653 | + rc2 = sqlite3_reset(pFetch); |
| 129654 | + if( rc==SQLITE_OK ) rc = rc2; |
| 129655 | + } |
| 129656 | + |
| 129657 | + while( rc==SQLITE_OK && iBlock ){ |
| 129658 | + char *aBlock = 0; |
| 129659 | + int nBlock = 0; |
| 129660 | + iNewStart = iBlock; |
| 129661 | + |
| 129662 | + rc = sqlite3Fts3ReadBlock(p, iBlock, &aBlock, &nBlock, 0); |
| 129663 | + if( rc==SQLITE_OK ){ |
| 129664 | + rc = fts3TruncateNode(aBlock, nBlock, &block, zTerm, nTerm, &iBlock); |
| 129665 | + } |
| 129666 | + if( rc==SQLITE_OK ){ |
| 129667 | + rc = fts3WriteSegment(p, iNewStart, block.a, block.n); |
| 129668 | + } |
| 129669 | + sqlite3_free(aBlock); |
| 129670 | + } |
| 129671 | + |
| 129672 | + /* Variable iNewStart now contains the first valid leaf node. */ |
| 129673 | + if( rc==SQLITE_OK && iNewStart ){ |
| 129674 | + sqlite3_stmt *pDel = 0; |
| 129675 | + rc = fts3SqlStmt(p, SQL_DELETE_SEGMENTS_RANGE, &pDel, 0); |
| 129676 | + if( rc==SQLITE_OK ){ |
| 129677 | + sqlite3_bind_int64(pDel, 1, iOldStart); |
| 129678 | + sqlite3_bind_int64(pDel, 2, iNewStart-1); |
| 129679 | + sqlite3_step(pDel); |
| 129680 | + rc = sqlite3_reset(pDel); |
| 129681 | + } |
| 129682 | + } |
| 129683 | + |
| 129684 | + if( rc==SQLITE_OK ){ |
| 129685 | + sqlite3_stmt *pChomp = 0; |
| 129686 | + rc = fts3SqlStmt(p, SQL_CHOMP_SEGDIR, &pChomp, 0); |
| 129687 | + if( rc==SQLITE_OK ){ |
| 129688 | + sqlite3_bind_int64(pChomp, 1, iNewStart); |
| 129689 | + sqlite3_bind_blob(pChomp, 2, root.a, root.n, SQLITE_STATIC); |
| 129690 | + sqlite3_bind_int64(pChomp, 3, iAbsLevel); |
| 129691 | + sqlite3_bind_int(pChomp, 4, iIdx); |
| 129692 | + sqlite3_step(pChomp); |
| 129693 | + rc = sqlite3_reset(pChomp); |
| 129694 | + } |
| 129695 | + } |
| 129696 | + |
| 129697 | + sqlite3_free(root.a); |
| 129698 | + sqlite3_free(block.a); |
| 129699 | + return rc; |
| 129700 | +} |
| 129701 | + |
| 129702 | +/* |
| 129703 | +** This function is called after an incrmental-merge operation has run to |
| 129704 | +** merge (or partially merge) two or more segments from absolute level |
| 129705 | +** iAbsLevel. |
| 129706 | +** |
| 129707 | +** Each input segment is either removed from the db completely (if all of |
| 129708 | +** its data was copied to the output segment by the incrmerge operation) |
| 129709 | +** or modified in place so that it no longer contains those entries that |
| 129710 | +** have been duplicated in the output segment. |
| 129711 | +*/ |
| 129712 | +static int fts3IncrmergeChomp( |
| 129713 | + Fts3Table *p, /* FTS table handle */ |
| 129714 | + sqlite3_int64 iAbsLevel, /* Absolute level containing segments */ |
| 129715 | + Fts3MultiSegReader *pCsr, /* Chomp all segments opened by this cursor */ |
| 129716 | + int *pnRem /* Number of segments not deleted */ |
| 129717 | +){ |
| 129718 | + int i; |
| 129719 | + int nRem = 0; |
| 129720 | + int rc = SQLITE_OK; |
| 129721 | + |
| 129722 | + for(i=pCsr->nSegment-1; i>=0 && rc==SQLITE_OK; i--){ |
| 129723 | + Fts3SegReader *pSeg = 0; |
| 129724 | + int j; |
| 129725 | + |
| 129726 | + /* Find the Fts3SegReader object with Fts3SegReader.iIdx==i. It is hiding |
| 129727 | + ** somewhere in the pCsr->apSegment[] array. */ |
| 129728 | + for(j=0; ALWAYS(j<pCsr->nSegment); j++){ |
| 129729 | + pSeg = pCsr->apSegment[j]; |
| 129730 | + if( pSeg->iIdx==i ) break; |
| 129731 | + } |
| 129732 | + assert( j<pCsr->nSegment && pSeg->iIdx==i ); |
| 129733 | + |
| 129734 | + if( pSeg->aNode==0 ){ |
| 129735 | + /* Seg-reader is at EOF. Remove the entire input segment. */ |
| 129736 | + rc = fts3DeleteSegment(p, pSeg); |
| 129737 | + if( rc==SQLITE_OK ){ |
| 129738 | + rc = fts3RemoveSegdirEntry(p, iAbsLevel, pSeg->iIdx); |
| 129739 | + } |
| 129740 | + *pnRem = 0; |
| 129741 | + }else{ |
| 129742 | + /* The incremental merge did not copy all the data from this |
| 129743 | + ** segment to the upper level. The segment is modified in place |
| 129744 | + ** so that it contains no keys smaller than zTerm/nTerm. */ |
| 129745 | + const char *zTerm = pSeg->zTerm; |
| 129746 | + int nTerm = pSeg->nTerm; |
| 129747 | + rc = fts3TruncateSegment(p, iAbsLevel, pSeg->iIdx, zTerm, nTerm); |
| 129748 | + nRem++; |
| 129749 | + } |
| 129750 | + } |
| 129751 | + |
| 129752 | + if( rc==SQLITE_OK && nRem!=pCsr->nSegment ){ |
| 129753 | + rc = fts3RepackSegdirLevel(p, iAbsLevel); |
| 129754 | + } |
| 129755 | + |
| 129756 | + *pnRem = nRem; |
| 129757 | + return rc; |
| 129758 | +} |
| 129759 | + |
| 129760 | +/* |
| 129761 | +** Store an incr-merge hint in the database. |
| 129762 | +*/ |
| 129763 | +static int fts3IncrmergeHintStore(Fts3Table *p, Blob *pHint){ |
| 129764 | + sqlite3_stmt *pReplace = 0; |
| 129765 | + int rc; /* Return code */ |
| 129766 | + |
| 129767 | + rc = fts3SqlStmt(p, SQL_REPLACE_STAT, &pReplace, 0); |
| 129768 | + if( rc==SQLITE_OK ){ |
| 129769 | + sqlite3_bind_int(pReplace, 1, FTS_STAT_INCRMERGEHINT); |
| 129770 | + sqlite3_bind_blob(pReplace, 2, pHint->a, pHint->n, SQLITE_STATIC); |
| 129771 | + sqlite3_step(pReplace); |
| 129772 | + rc = sqlite3_reset(pReplace); |
| 129773 | + } |
| 129774 | + |
| 129775 | + return rc; |
| 129776 | +} |
| 129777 | + |
| 129778 | +/* |
| 129779 | +** Load an incr-merge hint from the database. The incr-merge hint, if one |
| 129780 | +** exists, is stored in the rowid==1 row of the %_stat table. |
| 129781 | +** |
| 129782 | +** If successful, populate blob *pHint with the value read from the %_stat |
| 129783 | +** table and return SQLITE_OK. Otherwise, if an error occurs, return an |
| 129784 | +** SQLite error code. |
| 129785 | +*/ |
| 129786 | +static int fts3IncrmergeHintLoad(Fts3Table *p, Blob *pHint){ |
| 129787 | + sqlite3_stmt *pSelect = 0; |
| 129788 | + int rc; |
| 129789 | + |
| 129790 | + pHint->n = 0; |
| 129791 | + rc = fts3SqlStmt(p, SQL_SELECT_STAT, &pSelect, 0); |
| 129792 | + if( rc==SQLITE_OK ){ |
| 129793 | + int rc2; |
| 129794 | + sqlite3_bind_int(pSelect, 1, FTS_STAT_INCRMERGEHINT); |
| 129795 | + if( SQLITE_ROW==sqlite3_step(pSelect) ){ |
| 129796 | + const char *aHint = sqlite3_column_blob(pSelect, 0); |
| 129797 | + int nHint = sqlite3_column_bytes(pSelect, 0); |
| 129798 | + if( aHint ){ |
| 129799 | + blobGrowBuffer(pHint, nHint, &rc); |
| 129800 | + if( rc==SQLITE_OK ){ |
| 129801 | + memcpy(pHint->a, aHint, nHint); |
| 129802 | + pHint->n = nHint; |
| 129803 | + } |
| 129804 | + } |
| 129805 | + } |
| 129806 | + rc2 = sqlite3_reset(pSelect); |
| 129807 | + if( rc==SQLITE_OK ) rc = rc2; |
| 129808 | + } |
| 129809 | + |
| 129810 | + return rc; |
| 129811 | +} |
| 129812 | + |
| 129813 | +/* |
| 129814 | +** If *pRc is not SQLITE_OK when this function is called, it is a no-op. |
| 129815 | +** Otherwise, append an entry to the hint stored in blob *pHint. Each entry |
| 129816 | +** consists of two varints, the absolute level number of the input segments |
| 129817 | +** and the number of input segments. |
| 129818 | +** |
| 129819 | +** If successful, leave *pRc set to SQLITE_OK and return. If an error occurs, |
| 129820 | +** set *pRc to an SQLite error code before returning. |
| 129821 | +*/ |
| 129822 | +static void fts3IncrmergeHintPush( |
| 129823 | + Blob *pHint, /* Hint blob to append to */ |
| 129824 | + i64 iAbsLevel, /* First varint to store in hint */ |
| 129825 | + int nInput, /* Second varint to store in hint */ |
| 129826 | + int *pRc /* IN/OUT: Error code */ |
| 129827 | +){ |
| 129828 | + blobGrowBuffer(pHint, pHint->n + 2*FTS3_VARINT_MAX, pRc); |
| 129829 | + if( *pRc==SQLITE_OK ){ |
| 129830 | + pHint->n += sqlite3Fts3PutVarint(&pHint->a[pHint->n], iAbsLevel); |
| 129831 | + pHint->n += sqlite3Fts3PutVarint(&pHint->a[pHint->n], (i64)nInput); |
| 129832 | + } |
| 129833 | +} |
| 129834 | + |
| 129835 | +/* |
| 129836 | +** Read the last entry (most recently pushed) from the hint blob *pHint |
| 129837 | +** and then remove the entry. Write the two values read to *piAbsLevel and |
| 129838 | +** *pnInput before returning. |
| 129839 | +** |
| 129840 | +** If no error occurs, return SQLITE_OK. If the hint blob in *pHint does |
| 129841 | +** not contain at least two valid varints, return SQLITE_CORRUPT_VTAB. |
| 129842 | +*/ |
| 129843 | +static int fts3IncrmergeHintPop(Blob *pHint, i64 *piAbsLevel, int *pnInput){ |
| 129844 | + const int nHint = pHint->n; |
| 129845 | + int i; |
| 129846 | + |
| 129847 | + i = pHint->n-2; |
| 129848 | + while( i>0 && (pHint->a[i-1] & 0x80) ) i--; |
| 129849 | + while( i>0 && (pHint->a[i-1] & 0x80) ) i--; |
| 129850 | + |
| 129851 | + pHint->n = i; |
| 129852 | + i += sqlite3Fts3GetVarint(&pHint->a[i], piAbsLevel); |
| 129853 | + i += sqlite3Fts3GetVarint32(&pHint->a[i], pnInput); |
| 129854 | + if( i!=nHint ) return SQLITE_CORRUPT_VTAB; |
| 129855 | + |
| 129856 | + return SQLITE_OK; |
| 129857 | +} |
| 129858 | + |
| 129859 | + |
| 129860 | +/* |
| 129861 | +** Attempt an incremental merge that writes nMerge leaf blocks. |
| 129862 | +** |
| 129863 | +** Incremental merges happen nMin segments at a time. The two |
| 129864 | +** segments to be merged are the nMin oldest segments (the ones with |
| 129865 | +** the smallest indexes) in the highest level that contains at least |
| 129866 | +** nMin segments. Multiple merges might occur in an attempt to write the |
| 129867 | +** quota of nMerge leaf blocks. |
| 129868 | +*/ |
| 129869 | +SQLITE_PRIVATE int sqlite3Fts3Incrmerge(Fts3Table *p, int nMerge, int nMin){ |
| 129870 | + int rc; /* Return code */ |
| 129871 | + int nRem = nMerge; /* Number of leaf pages yet to be written */ |
| 129872 | + Fts3MultiSegReader *pCsr; /* Cursor used to read input data */ |
| 129873 | + Fts3SegFilter *pFilter; /* Filter used with cursor pCsr */ |
| 129874 | + IncrmergeWriter *pWriter; /* Writer object */ |
| 129875 | + int nSeg = 0; /* Number of input segments */ |
| 129876 | + sqlite3_int64 iAbsLevel = 0; /* Absolute level number to work on */ |
| 129877 | + Blob hint = {0, 0, 0}; /* Hint read from %_stat table */ |
| 129878 | + int bDirtyHint = 0; /* True if blob 'hint' has been modified */ |
| 129879 | + |
| 129880 | + /* Allocate space for the cursor, filter and writer objects */ |
| 129881 | + const int nAlloc = sizeof(*pCsr) + sizeof(*pFilter) + sizeof(*pWriter); |
| 129882 | + pWriter = (IncrmergeWriter *)sqlite3_malloc(nAlloc); |
| 129883 | + if( !pWriter ) return SQLITE_NOMEM; |
| 129884 | + pFilter = (Fts3SegFilter *)&pWriter[1]; |
| 129885 | + pCsr = (Fts3MultiSegReader *)&pFilter[1]; |
| 129886 | + |
| 129887 | + rc = fts3IncrmergeHintLoad(p, &hint); |
| 129888 | + while( rc==SQLITE_OK && nRem>0 ){ |
| 129889 | + const i64 nMod = FTS3_SEGDIR_MAXLEVEL * p->nIndex; |
| 129890 | + sqlite3_stmt *pFindLevel = 0; /* SQL used to determine iAbsLevel */ |
| 129891 | + int bUseHint = 0; /* True if attempting to append */ |
| 129892 | + |
| 129893 | + /* Search the %_segdir table for the absolute level with the smallest |
| 129894 | + ** relative level number that contains at least nMin segments, if any. |
| 129895 | + ** If one is found, set iAbsLevel to the absolute level number and |
| 129896 | + ** nSeg to nMin. If no level with at least nMin segments can be found, |
| 129897 | + ** set nSeg to -1. |
| 129898 | + */ |
| 129899 | + rc = fts3SqlStmt(p, SQL_FIND_MERGE_LEVEL, &pFindLevel, 0); |
| 129900 | + sqlite3_bind_int(pFindLevel, 1, nMin); |
| 129901 | + if( sqlite3_step(pFindLevel)==SQLITE_ROW ){ |
| 129902 | + iAbsLevel = sqlite3_column_int64(pFindLevel, 0); |
| 129903 | + nSeg = nMin; |
| 129904 | + }else{ |
| 129905 | + nSeg = -1; |
| 129906 | + } |
| 129907 | + rc = sqlite3_reset(pFindLevel); |
| 129908 | + |
| 129909 | + /* If the hint read from the %_stat table is not empty, check if the |
| 129910 | + ** last entry in it specifies a relative level smaller than or equal |
| 129911 | + ** to the level identified by the block above (if any). If so, this |
| 129912 | + ** iteration of the loop will work on merging at the hinted level. |
| 129913 | + */ |
| 129914 | + if( rc==SQLITE_OK && hint.n ){ |
| 129915 | + int nHint = hint.n; |
| 129916 | + sqlite3_int64 iHintAbsLevel = 0; /* Hint level */ |
| 129917 | + int nHintSeg = 0; /* Hint number of segments */ |
| 129918 | + |
| 129919 | + rc = fts3IncrmergeHintPop(&hint, &iHintAbsLevel, &nHintSeg); |
| 129920 | + if( nSeg<0 || (iAbsLevel % nMod) >= (iHintAbsLevel % nMod) ){ |
| 129921 | + iAbsLevel = iHintAbsLevel; |
| 129922 | + nSeg = nHintSeg; |
| 129923 | + bUseHint = 1; |
| 129924 | + bDirtyHint = 1; |
| 129925 | + }else{ |
| 129926 | + /* This undoes the effect of the HintPop() above - so that no entry |
| 129927 | + ** is removed from the hint blob. */ |
| 129928 | + hint.n = nHint; |
| 129929 | + } |
| 129930 | + } |
| 129931 | + |
| 129932 | + /* If nSeg is less that zero, then there is no level with at least |
| 129933 | + ** nMin segments and no hint in the %_stat table. No work to do. |
| 129934 | + ** Exit early in this case. */ |
| 129935 | + if( nSeg<0 ) break; |
| 129936 | + |
| 129937 | + /* Open a cursor to iterate through the contents of the oldest nSeg |
| 129938 | + ** indexes of absolute level iAbsLevel. If this cursor is opened using |
| 129939 | + ** the 'hint' parameters, it is possible that there are less than nSeg |
| 129940 | + ** segments available in level iAbsLevel. In this case, no work is |
| 129941 | + ** done on iAbsLevel - fall through to the next iteration of the loop |
| 129942 | + ** to start work on some other level. */ |
| 129943 | + memset(pWriter, 0, nAlloc); |
| 129944 | + pFilter->flags = FTS3_SEGMENT_REQUIRE_POS; |
| 129945 | + if( rc==SQLITE_OK ){ |
| 129946 | + rc = fts3IncrmergeCsr(p, iAbsLevel, nSeg, pCsr); |
| 129947 | + } |
| 129948 | + if( SQLITE_OK==rc && pCsr->nSegment==nSeg |
| 129949 | + && SQLITE_OK==(rc = sqlite3Fts3SegReaderStart(p, pCsr, pFilter)) |
| 129950 | + && SQLITE_ROW==(rc = sqlite3Fts3SegReaderStep(p, pCsr)) |
| 129951 | + ){ |
| 129952 | + int iIdx = 0; /* Largest idx in level (iAbsLevel+1) */ |
| 129953 | + rc = fts3IncrmergeOutputIdx(p, iAbsLevel, &iIdx); |
| 129954 | + if( rc==SQLITE_OK ){ |
| 129955 | + if( bUseHint && iIdx>0 ){ |
| 129956 | + const char *zKey = pCsr->zTerm; |
| 129957 | + int nKey = pCsr->nTerm; |
| 129958 | + rc = fts3IncrmergeLoad(p, iAbsLevel, iIdx-1, zKey, nKey, pWriter); |
| 129959 | + }else{ |
| 129960 | + rc = fts3IncrmergeWriter(p, iAbsLevel, iIdx, pCsr, pWriter); |
| 129961 | + } |
| 129962 | + } |
| 129963 | + |
| 129964 | + if( rc==SQLITE_OK && pWriter->nLeafEst ){ |
| 129965 | + fts3LogMerge(nSeg, iAbsLevel); |
| 129966 | + do { |
| 129967 | + rc = fts3IncrmergeAppend(p, pWriter, pCsr); |
| 129968 | + if( rc==SQLITE_OK ) rc = sqlite3Fts3SegReaderStep(p, pCsr); |
| 129969 | + if( pWriter->nWork>=nRem && rc==SQLITE_ROW ) rc = SQLITE_OK; |
| 129970 | + }while( rc==SQLITE_ROW ); |
| 129971 | + |
| 129972 | + /* Update or delete the input segments */ |
| 129973 | + if( rc==SQLITE_OK ){ |
| 129974 | + nRem -= (1 + pWriter->nWork); |
| 129975 | + rc = fts3IncrmergeChomp(p, iAbsLevel, pCsr, &nSeg); |
| 129976 | + if( nSeg!=0 ){ |
| 129977 | + bDirtyHint = 1; |
| 129978 | + fts3IncrmergeHintPush(&hint, iAbsLevel, nSeg, &rc); |
| 129979 | + } |
| 129980 | + } |
| 129981 | + } |
| 129982 | + |
| 129983 | + fts3IncrmergeRelease(p, pWriter, &rc); |
| 129984 | + } |
| 129985 | + |
| 129986 | + sqlite3Fts3SegReaderFinish(pCsr); |
| 129987 | + } |
| 129988 | + |
| 129989 | + /* Write the hint values into the %_stat table for the next incr-merger */ |
| 129990 | + if( bDirtyHint && rc==SQLITE_OK ){ |
| 129991 | + rc = fts3IncrmergeHintStore(p, &hint); |
| 129992 | + } |
| 129993 | + |
| 129994 | + sqlite3_free(pWriter); |
| 129995 | + sqlite3_free(hint.a); |
| 129996 | + return rc; |
| 129997 | +} |
| 129998 | + |
| 129999 | +/* |
| 130000 | +** Convert the text beginning at *pz into an integer and return |
| 130001 | +** its value. Advance *pz to point to the first character past |
| 130002 | +** the integer. |
| 130003 | +*/ |
| 130004 | +static int fts3Getint(const char **pz){ |
| 130005 | + const char *z = *pz; |
| 130006 | + int i = 0; |
| 130007 | + while( (*z)>='0' && (*z)<='9' ) i = 10*i + *(z++) - '0'; |
| 130008 | + *pz = z; |
| 130009 | + return i; |
| 130010 | +} |
| 130011 | + |
| 130012 | +/* |
| 130013 | +** Process statements of the form: |
| 130014 | +** |
| 130015 | +** INSERT INTO table(table) VALUES('merge=A,B'); |
| 130016 | +** |
| 130017 | +** A and B are integers that decode to be the number of leaf pages |
| 130018 | +** written for the merge, and the minimum number of segments on a level |
| 130019 | +** before it will be selected for a merge, respectively. |
| 130020 | +*/ |
| 130021 | +static int fts3DoIncrmerge( |
| 130022 | + Fts3Table *p, /* FTS3 table handle */ |
| 130023 | + const char *zParam /* Nul-terminated string containing "A,B" */ |
| 130024 | +){ |
| 130025 | + int rc; |
| 130026 | + int nMin = (FTS3_MERGE_COUNT / 2); |
| 130027 | + int nMerge = 0; |
| 130028 | + const char *z = zParam; |
| 130029 | + |
| 130030 | + /* Read the first integer value */ |
| 130031 | + nMerge = fts3Getint(&z); |
| 130032 | + |
| 130033 | + /* If the first integer value is followed by a ',', read the second |
| 130034 | + ** integer value. */ |
| 130035 | + if( z[0]==',' && z[1]!='\0' ){ |
| 130036 | + z++; |
| 130037 | + nMin = fts3Getint(&z); |
| 130038 | + } |
| 130039 | + |
| 130040 | + if( z[0]!='\0' || nMin<2 ){ |
| 130041 | + rc = SQLITE_ERROR; |
| 130042 | + }else{ |
| 130043 | + rc = SQLITE_OK; |
| 130044 | + if( !p->bHasStat ){ |
| 130045 | + assert( p->bFts4==0 ); |
| 130046 | + sqlite3Fts3CreateStatTable(&rc, p); |
| 130047 | + } |
| 130048 | + if( rc==SQLITE_OK ){ |
| 130049 | + rc = sqlite3Fts3Incrmerge(p, nMerge, nMin); |
| 130050 | + } |
| 130051 | + sqlite3Fts3SegmentsClose(p); |
| 130052 | + } |
| 130053 | + return rc; |
| 130054 | +} |
| 130055 | + |
| 130056 | +/* |
| 130057 | +** Process statements of the form: |
| 130058 | +** |
| 130059 | +** INSERT INTO table(table) VALUES('automerge=X'); |
| 130060 | +** |
| 130061 | +** where X is an integer. X==0 means to turn automerge off. X!=0 means |
| 130062 | +** turn it on. The setting is persistent. |
| 130063 | +*/ |
| 130064 | +static int fts3DoAutoincrmerge( |
| 130065 | + Fts3Table *p, /* FTS3 table handle */ |
| 130066 | + const char *zParam /* Nul-terminated string containing boolean */ |
| 130067 | +){ |
| 130068 | + int rc = SQLITE_OK; |
| 130069 | + sqlite3_stmt *pStmt = 0; |
| 130070 | + p->bAutoincrmerge = fts3Getint(&zParam)!=0; |
| 130071 | + if( !p->bHasStat ){ |
| 130072 | + assert( p->bFts4==0 ); |
| 130073 | + sqlite3Fts3CreateStatTable(&rc, p); |
| 130074 | + if( rc ) return rc; |
| 130075 | + } |
| 130076 | + rc = fts3SqlStmt(p, SQL_REPLACE_STAT, &pStmt, 0); |
| 130077 | + if( rc ) return rc;; |
| 130078 | + sqlite3_bind_int(pStmt, 1, FTS_STAT_AUTOINCRMERGE); |
| 130079 | + sqlite3_bind_int(pStmt, 2, p->bAutoincrmerge); |
| 130080 | + sqlite3_step(pStmt); |
| 130081 | + rc = sqlite3_reset(pStmt); |
| 130082 | + return rc; |
| 130083 | +} |
| 130084 | + |
| 130085 | +/* |
| 130086 | +** Return a 64-bit checksum for the FTS index entry specified by the |
| 130087 | +** arguments to this function. |
| 130088 | +*/ |
| 130089 | +static u64 fts3ChecksumEntry( |
| 130090 | + const char *zTerm, /* Pointer to buffer containing term */ |
| 130091 | + int nTerm, /* Size of zTerm in bytes */ |
| 130092 | + int iLangid, /* Language id for current row */ |
| 130093 | + int iIndex, /* Index (0..Fts3Table.nIndex-1) */ |
| 130094 | + i64 iDocid, /* Docid for current row. */ |
| 130095 | + int iCol, /* Column number */ |
| 130096 | + int iPos /* Position */ |
| 130097 | +){ |
| 130098 | + int i; |
| 130099 | + u64 ret = (u64)iDocid; |
| 130100 | + |
| 130101 | + ret += (ret<<3) + iLangid; |
| 130102 | + ret += (ret<<3) + iIndex; |
| 130103 | + ret += (ret<<3) + iCol; |
| 130104 | + ret += (ret<<3) + iPos; |
| 130105 | + for(i=0; i<nTerm; i++) ret += (ret<<3) + zTerm[i]; |
| 130106 | + |
| 130107 | + return ret; |
| 130108 | +} |
| 130109 | + |
| 130110 | +/* |
| 130111 | +** Return a checksum of all entries in the FTS index that correspond to |
| 130112 | +** language id iLangid. The checksum is calculated by XORing the checksums |
| 130113 | +** of each individual entry (see fts3ChecksumEntry()) together. |
| 130114 | +** |
| 130115 | +** If successful, the checksum value is returned and *pRc set to SQLITE_OK. |
| 130116 | +** Otherwise, if an error occurs, *pRc is set to an SQLite error code. The |
| 130117 | +** return value is undefined in this case. |
| 130118 | +*/ |
| 130119 | +static u64 fts3ChecksumIndex( |
| 130120 | + Fts3Table *p, /* FTS3 table handle */ |
| 130121 | + int iLangid, /* Language id to return cksum for */ |
| 130122 | + int iIndex, /* Index to cksum (0..p->nIndex-1) */ |
| 130123 | + int *pRc /* OUT: Return code */ |
| 130124 | +){ |
| 130125 | + Fts3SegFilter filter; |
| 130126 | + Fts3MultiSegReader csr; |
| 130127 | + int rc; |
| 130128 | + u64 cksum = 0; |
| 130129 | + |
| 130130 | + assert( *pRc==SQLITE_OK ); |
| 130131 | + |
| 130132 | + memset(&filter, 0, sizeof(filter)); |
| 130133 | + memset(&csr, 0, sizeof(csr)); |
| 130134 | + filter.flags = FTS3_SEGMENT_REQUIRE_POS|FTS3_SEGMENT_IGNORE_EMPTY; |
| 130135 | + filter.flags |= FTS3_SEGMENT_SCAN; |
| 130136 | + |
| 130137 | + rc = sqlite3Fts3SegReaderCursor( |
| 130138 | + p, iLangid, iIndex, FTS3_SEGCURSOR_ALL, 0, 0, 0, 1,&csr |
| 130139 | + ); |
| 130140 | + if( rc==SQLITE_OK ){ |
| 130141 | + rc = sqlite3Fts3SegReaderStart(p, &csr, &filter); |
| 130142 | + } |
| 130143 | + |
| 130144 | + if( rc==SQLITE_OK ){ |
| 130145 | + while( SQLITE_ROW==(rc = sqlite3Fts3SegReaderStep(p, &csr)) ){ |
| 130146 | + char *pCsr = csr.aDoclist; |
| 130147 | + char *pEnd = &pCsr[csr.nDoclist]; |
| 130148 | + |
| 130149 | + i64 iDocid = 0; |
| 130150 | + i64 iCol = 0; |
| 130151 | + i64 iPos = 0; |
| 130152 | + |
| 130153 | + pCsr += sqlite3Fts3GetVarint(pCsr, &iDocid); |
| 130154 | + while( pCsr<pEnd ){ |
| 130155 | + i64 iVal = 0; |
| 130156 | + pCsr += sqlite3Fts3GetVarint(pCsr, &iVal); |
| 130157 | + if( pCsr<pEnd ){ |
| 130158 | + if( iVal==0 || iVal==1 ){ |
| 130159 | + iCol = 0; |
| 130160 | + iPos = 0; |
| 130161 | + if( iVal ){ |
| 130162 | + pCsr += sqlite3Fts3GetVarint(pCsr, &iCol); |
| 130163 | + }else{ |
| 130164 | + pCsr += sqlite3Fts3GetVarint(pCsr, &iVal); |
| 130165 | + iDocid += iVal; |
| 130166 | + } |
| 130167 | + }else{ |
| 130168 | + iPos += (iVal - 2); |
| 130169 | + cksum = cksum ^ fts3ChecksumEntry( |
| 130170 | + csr.zTerm, csr.nTerm, iLangid, iIndex, iDocid, |
| 130171 | + (int)iCol, (int)iPos |
| 130172 | + ); |
| 130173 | + } |
| 130174 | + } |
| 130175 | + } |
| 130176 | + } |
| 130177 | + } |
| 130178 | + sqlite3Fts3SegReaderFinish(&csr); |
| 130179 | + |
| 130180 | + *pRc = rc; |
| 130181 | + return cksum; |
| 130182 | +} |
| 130183 | + |
| 130184 | +/* |
| 130185 | +** Check if the contents of the FTS index match the current contents of the |
| 130186 | +** content table. If no error occurs and the contents do match, set *pbOk |
| 130187 | +** to true and return SQLITE_OK. Or if the contents do not match, set *pbOk |
| 130188 | +** to false before returning. |
| 130189 | +** |
| 130190 | +** If an error occurs (e.g. an OOM or IO error), return an SQLite error |
| 130191 | +** code. The final value of *pbOk is undefined in this case. |
| 130192 | +*/ |
| 130193 | +static int fts3IntegrityCheck(Fts3Table *p, int *pbOk){ |
| 130194 | + int rc = SQLITE_OK; /* Return code */ |
| 130195 | + u64 cksum1 = 0; /* Checksum based on FTS index contents */ |
| 130196 | + u64 cksum2 = 0; /* Checksum based on %_content contents */ |
| 130197 | + sqlite3_stmt *pAllLangid = 0; /* Statement to return all language-ids */ |
| 130198 | + |
| 130199 | + /* This block calculates the checksum according to the FTS index. */ |
| 130200 | + rc = fts3SqlStmt(p, SQL_SELECT_ALL_LANGID, &pAllLangid, 0); |
| 130201 | + if( rc==SQLITE_OK ){ |
| 130202 | + int rc2; |
| 130203 | + sqlite3_bind_int(pAllLangid, 1, p->nIndex); |
| 130204 | + while( rc==SQLITE_OK && sqlite3_step(pAllLangid)==SQLITE_ROW ){ |
| 130205 | + int iLangid = sqlite3_column_int(pAllLangid, 0); |
| 130206 | + int i; |
| 130207 | + for(i=0; i<p->nIndex; i++){ |
| 130208 | + cksum1 = cksum1 ^ fts3ChecksumIndex(p, iLangid, i, &rc); |
| 130209 | + } |
| 130210 | + } |
| 130211 | + rc2 = sqlite3_reset(pAllLangid); |
| 130212 | + if( rc==SQLITE_OK ) rc = rc2; |
| 130213 | + } |
| 130214 | + |
| 130215 | + /* This block calculates the checksum according to the %_content table */ |
| 130216 | + rc = fts3SqlStmt(p, SQL_SELECT_ALL_LANGID, &pAllLangid, 0); |
| 130217 | + if( rc==SQLITE_OK ){ |
| 130218 | + sqlite3_tokenizer_module const *pModule = p->pTokenizer->pModule; |
| 130219 | + sqlite3_stmt *pStmt = 0; |
| 130220 | + char *zSql; |
| 130221 | + |
| 130222 | + zSql = sqlite3_mprintf("SELECT %s" , p->zReadExprlist); |
| 130223 | + if( !zSql ){ |
| 130224 | + rc = SQLITE_NOMEM; |
| 130225 | + }else{ |
| 130226 | + rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0); |
| 130227 | + sqlite3_free(zSql); |
| 130228 | + } |
| 130229 | + |
| 130230 | + while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){ |
| 130231 | + i64 iDocid = sqlite3_column_int64(pStmt, 0); |
| 130232 | + int iLang = langidFromSelect(p, pStmt); |
| 130233 | + int iCol; |
| 130234 | + |
| 130235 | + for(iCol=0; rc==SQLITE_OK && iCol<p->nColumn; iCol++){ |
| 130236 | + const char *zText = (const char *)sqlite3_column_text(pStmt, iCol+1); |
| 130237 | + int nText = sqlite3_column_bytes(pStmt, iCol+1); |
| 130238 | + sqlite3_tokenizer_cursor *pT = 0; |
| 130239 | + |
| 130240 | + rc = sqlite3Fts3OpenTokenizer(p->pTokenizer, iLang, zText, nText, &pT); |
| 130241 | + while( rc==SQLITE_OK ){ |
| 130242 | + char const *zToken; /* Buffer containing token */ |
| 130243 | + int nToken; /* Number of bytes in token */ |
| 130244 | + int iDum1, iDum2; /* Dummy variables */ |
| 130245 | + int iPos; /* Position of token in zText */ |
| 130246 | + |
| 130247 | + rc = pModule->xNext(pT, &zToken, &nToken, &iDum1, &iDum2, &iPos); |
| 130248 | + if( rc==SQLITE_OK ){ |
| 130249 | + int i; |
| 130250 | + cksum2 = cksum2 ^ fts3ChecksumEntry( |
| 130251 | + zToken, nToken, iLang, 0, iDocid, iCol, iPos |
| 130252 | + ); |
| 130253 | + for(i=1; i<p->nIndex; i++){ |
| 130254 | + if( p->aIndex[i].nPrefix<=nToken ){ |
| 130255 | + cksum2 = cksum2 ^ fts3ChecksumEntry( |
| 130256 | + zToken, p->aIndex[i].nPrefix, iLang, i, iDocid, iCol, iPos |
| 130257 | + ); |
| 130258 | + } |
| 130259 | + } |
| 130260 | + } |
| 130261 | + } |
| 130262 | + if( pT ) pModule->xClose(pT); |
| 130263 | + if( rc==SQLITE_DONE ) rc = SQLITE_OK; |
| 130264 | + } |
| 130265 | + } |
| 130266 | + |
| 130267 | + sqlite3_finalize(pStmt); |
| 130268 | + } |
| 130269 | + |
| 130270 | + *pbOk = (cksum1==cksum2); |
| 130271 | + return rc; |
| 130272 | +} |
| 130273 | + |
| 130274 | +/* |
| 130275 | +** Run the integrity-check. If no error occurs and the current contents of |
| 130276 | +** the FTS index are correct, return SQLITE_OK. Or, if the contents of the |
| 130277 | +** FTS index are incorrect, return SQLITE_CORRUPT_VTAB. |
| 130278 | +** |
| 130279 | +** Or, if an error (e.g. an OOM or IO error) occurs, return an SQLite |
| 130280 | +** error code. |
| 130281 | +** |
| 130282 | +** The integrity-check works as follows. For each token and indexed token |
| 130283 | +** prefix in the document set, a 64-bit checksum is calculated (by code |
| 130284 | +** in fts3ChecksumEntry()) based on the following: |
| 130285 | +** |
| 130286 | +** + The index number (0 for the main index, 1 for the first prefix |
| 130287 | +** index etc.), |
| 130288 | +** + The token (or token prefix) text itself, |
| 130289 | +** + The language-id of the row it appears in, |
| 130290 | +** + The docid of the row it appears in, |
| 130291 | +** + The column it appears in, and |
| 130292 | +** + The tokens position within that column. |
| 130293 | +** |
| 130294 | +** The checksums for all entries in the index are XORed together to create |
| 130295 | +** a single checksum for the entire index. |
| 130296 | +** |
| 130297 | +** The integrity-check code calculates the same checksum in two ways: |
| 130298 | +** |
| 130299 | +** 1. By scanning the contents of the FTS index, and |
| 130300 | +** 2. By scanning and tokenizing the content table. |
| 130301 | +** |
| 130302 | +** If the two checksums are identical, the integrity-check is deemed to have |
| 130303 | +** passed. |
| 130304 | +*/ |
| 130305 | +static int fts3DoIntegrityCheck( |
| 130306 | + Fts3Table *p /* FTS3 table handle */ |
| 130307 | +){ |
| 130308 | + int rc; |
| 130309 | + int bOk = 0; |
| 130310 | + rc = fts3IntegrityCheck(p, &bOk); |
| 130311 | + if( rc==SQLITE_OK && bOk==0 ) rc = SQLITE_CORRUPT_VTAB; |
| 130312 | + return rc; |
| 130313 | +} |
| 130314 | + |
| 127855 | 130315 | /* |
| 127856 | 130316 | ** Handle a 'special' INSERT of the form: |
| 127857 | 130317 | ** |
| 127858 | 130318 | ** "INSERT INTO tbl(tbl) VALUES(<expr>)" |
| 127859 | 130319 | ** |
| | @@ -127869,10 +130329,16 @@ |
| 127869 | 130329 | return SQLITE_NOMEM; |
| 127870 | 130330 | }else if( nVal==8 && 0==sqlite3_strnicmp(zVal, "optimize", 8) ){ |
| 127871 | 130331 | rc = fts3DoOptimize(p, 0); |
| 127872 | 130332 | }else if( nVal==7 && 0==sqlite3_strnicmp(zVal, "rebuild", 7) ){ |
| 127873 | 130333 | rc = fts3DoRebuild(p); |
| 130334 | + }else if( nVal==15 && 0==sqlite3_strnicmp(zVal, "integrity-check", 15) ){ |
| 130335 | + rc = fts3DoIntegrityCheck(p); |
| 130336 | + }else if( nVal>6 && 0==sqlite3_strnicmp(zVal, "merge=", 6) ){ |
| 130337 | + rc = fts3DoIncrmerge(p, &zVal[6]); |
| 130338 | + }else if( nVal>10 && 0==sqlite3_strnicmp(zVal, "automerge=", 10) ){ |
| 130339 | + rc = fts3DoAutoincrmerge(p, &zVal[10]); |
| 127874 | 130340 | #ifdef SQLITE_TEST |
| 127875 | 130341 | }else if( nVal>9 && 0==sqlite3_strnicmp(zVal, "nodesize=", 9) ){ |
| 127876 | 130342 | p->nNodeSize = atoi(&zVal[9]); |
| 127877 | 130343 | rc = SQLITE_OK; |
| 127878 | 130344 | }else if( nVal>11 && 0==sqlite3_strnicmp(zVal, "maxpending=", 9) ){ |
| | @@ -127937,18 +130403,17 @@ |
| 127937 | 130403 | |
| 127938 | 130404 | for(i=0; i<p->nColumn && rc==SQLITE_OK; i++){ |
| 127939 | 130405 | const char *zText = (const char *)sqlite3_column_text(pCsr->pStmt, i+1); |
| 127940 | 130406 | sqlite3_tokenizer_cursor *pTC = 0; |
| 127941 | 130407 | |
| 127942 | | - rc = pModule->xOpen(pT, zText, -1, &pTC); |
| 130408 | + rc = sqlite3Fts3OpenTokenizer(pT, pCsr->iLangid, zText, -1, &pTC); |
| 127943 | 130409 | while( rc==SQLITE_OK ){ |
| 127944 | 130410 | char const *zToken; /* Buffer containing token */ |
| 127945 | 130411 | int nToken; /* Number of bytes in token */ |
| 127946 | 130412 | int iDum1, iDum2; /* Dummy variables */ |
| 127947 | 130413 | int iPos; /* Position of token in zText */ |
| 127948 | 130414 | |
| 127949 | | - pTC->pTokenizer = pT; |
| 127950 | 130415 | rc = pModule->xNext(pTC, &zToken, &nToken, &iDum1, &iDum2, &iPos); |
| 127951 | 130416 | for(pDef=pCsr->pDeferred; pDef && rc==SQLITE_OK; pDef=pDef->pNext){ |
| 127952 | 130417 | Fts3PhraseToken *pPT = pDef->pToken; |
| 127953 | 130418 | if( (pDef->iCol>=p->nColumn || pDef->iCol==i) |
| 127954 | 130419 | && (pPT->bFirst==0 || iPos==0) |
| | @@ -128044,12 +130509,10 @@ |
| 128044 | 130509 | ** delete the contents of all three tables and throw away any |
| 128045 | 130510 | ** data in the pendingTerms hash table. */ |
| 128046 | 130511 | rc = fts3DeleteAll(p, 1); |
| 128047 | 130512 | *pnDoc = *pnDoc - 1; |
| 128048 | 130513 | }else{ |
| 128049 | | - sqlite3_int64 iRemove = sqlite3_value_int64(pRowid); |
| 128050 | | - rc = fts3PendingTermsDocid(p, iRemove); |
| 128051 | 130514 | fts3DeleteTerms(&rc, p, pRowid, aSzDel); |
| 128052 | 130515 | if( p->zContentTbl==0 ){ |
| 128053 | 130516 | fts3SqlExec(&rc, p, SQL_DELETE_CONTENT, &pRowid); |
| 128054 | 130517 | if( sqlite3_changes(p->db) ) *pnDoc = *pnDoc - 1; |
| 128055 | 130518 | }else{ |
| | @@ -128064,11 +130527,20 @@ |
| 128064 | 130527 | return rc; |
| 128065 | 130528 | } |
| 128066 | 130529 | |
| 128067 | 130530 | /* |
| 128068 | 130531 | ** This function does the work for the xUpdate method of FTS3 virtual |
| 128069 | | -** tables. |
| 130532 | +** tables. The schema of the virtual table being: |
| 130533 | +** |
| 130534 | +** CREATE TABLE <table name>( |
| 130535 | +** <user columns>, |
| 130536 | +** <table name> HIDDEN, |
| 130537 | +** docid HIDDEN, |
| 130538 | +** <langid> HIDDEN |
| 130539 | +** ); |
| 130540 | +** |
| 130541 | +** |
| 128070 | 130542 | */ |
| 128071 | 130543 | SQLITE_PRIVATE int sqlite3Fts3UpdateMethod( |
| 128072 | 130544 | sqlite3_vtab *pVtab, /* FTS3 vtab object */ |
| 128073 | 130545 | int nArg, /* Size of argument array */ |
| 128074 | 130546 | sqlite3_value **apVal, /* Array of arguments */ |
| | @@ -128081,10 +130553,14 @@ |
| 128081 | 130553 | u32 *aSzDel; /* Sizes of deleted documents */ |
| 128082 | 130554 | int nChng = 0; /* Net change in number of documents */ |
| 128083 | 130555 | int bInsertDone = 0; |
| 128084 | 130556 | |
| 128085 | 130557 | assert( p->pSegments==0 ); |
| 130558 | + assert( |
| 130559 | + nArg==1 /* DELETE operations */ |
| 130560 | + || nArg==(2 + p->nColumn + 3) /* INSERT or UPDATE operations */ |
| 130561 | + ); |
| 128086 | 130562 | |
| 128087 | 130563 | /* Check for a "special" INSERT operation. One of the form: |
| 128088 | 130564 | ** |
| 128089 | 130565 | ** INSERT INTO xyz(xyz) VALUES('command'); |
| 128090 | 130566 | */ |
| | @@ -128093,10 +130569,15 @@ |
| 128093 | 130569 | && sqlite3_value_type(apVal[p->nColumn+2])!=SQLITE_NULL |
| 128094 | 130570 | ){ |
| 128095 | 130571 | rc = fts3SpecialInsert(p, apVal[p->nColumn+2]); |
| 128096 | 130572 | goto update_out; |
| 128097 | 130573 | } |
| 130574 | + |
| 130575 | + if( nArg>1 && sqlite3_value_int(apVal[2 + p->nColumn + 2])<0 ){ |
| 130576 | + rc = SQLITE_CONSTRAINT; |
| 130577 | + goto update_out; |
| 130578 | + } |
| 128098 | 130579 | |
| 128099 | 130580 | /* Allocate space to hold the change in document sizes */ |
| 128100 | 130581 | aSzIns = sqlite3_malloc( sizeof(aSzIns[0])*(p->nColumn+1)*2 ); |
| 128101 | 130582 | if( aSzIns==0 ){ |
| 128102 | 130583 | rc = SQLITE_NOMEM; |
| | @@ -128161,30 +130642,31 @@ |
| 128161 | 130642 | isRemove = 1; |
| 128162 | 130643 | } |
| 128163 | 130644 | |
| 128164 | 130645 | /* If this is an INSERT or UPDATE operation, insert the new record. */ |
| 128165 | 130646 | if( nArg>1 && rc==SQLITE_OK ){ |
| 130647 | + int iLangid = sqlite3_value_int(apVal[2 + p->nColumn + 2]); |
| 128166 | 130648 | if( bInsertDone==0 ){ |
| 128167 | 130649 | rc = fts3InsertData(p, apVal, pRowid); |
| 128168 | 130650 | if( rc==SQLITE_CONSTRAINT && p->zContentTbl==0 ){ |
| 128169 | 130651 | rc = FTS_CORRUPT_VTAB; |
| 128170 | 130652 | } |
| 128171 | 130653 | } |
| 128172 | 130654 | if( rc==SQLITE_OK && (!isRemove || *pRowid!=p->iPrevDocid ) ){ |
| 128173 | | - rc = fts3PendingTermsDocid(p, *pRowid); |
| 130655 | + rc = fts3PendingTermsDocid(p, iLangid, *pRowid); |
| 128174 | 130656 | } |
| 128175 | 130657 | if( rc==SQLITE_OK ){ |
| 128176 | 130658 | assert( p->iPrevDocid==*pRowid ); |
| 128177 | | - rc = fts3InsertTerms(p, apVal, aSzIns); |
| 130659 | + rc = fts3InsertTerms(p, iLangid, apVal, aSzIns); |
| 128178 | 130660 | } |
| 128179 | 130661 | if( p->bHasDocsize ){ |
| 128180 | 130662 | fts3InsertDocsize(&rc, p, aSzIns); |
| 128181 | 130663 | } |
| 128182 | 130664 | nChng++; |
| 128183 | 130665 | } |
| 128184 | 130666 | |
| 128185 | | - if( p->bHasStat ){ |
| 130667 | + if( p->bFts4 ){ |
| 128186 | 130668 | fts3UpdateDocTotals(&rc, p, aSzIns, aSzDel, nChng); |
| 128187 | 130669 | } |
| 128188 | 130670 | |
| 128189 | 130671 | update_out: |
| 128190 | 130672 | sqlite3_free(aSzIns); |
| | @@ -128749,10 +131231,11 @@ |
| 128749 | 131231 | ** is no way for fts3BestSnippet() to know whether or not the document |
| 128750 | 131232 | ** actually contains terms that follow the final highlighted term. |
| 128751 | 131233 | */ |
| 128752 | 131234 | static int fts3SnippetShift( |
| 128753 | 131235 | Fts3Table *pTab, /* FTS3 table snippet comes from */ |
| 131236 | + int iLangid, /* Language id to use in tokenizing */ |
| 128754 | 131237 | int nSnippet, /* Number of tokens desired for snippet */ |
| 128755 | 131238 | const char *zDoc, /* Document text to extract snippet from */ |
| 128756 | 131239 | int nDoc, /* Size of buffer zDoc in bytes */ |
| 128757 | 131240 | int *piPos, /* IN/OUT: First token of snippet */ |
| 128758 | 131241 | u64 *pHlmask /* IN/OUT: Mask of tokens to highlight */ |
| | @@ -128784,15 +131267,14 @@ |
| 128784 | 131267 | pMod = (sqlite3_tokenizer_module *)pTab->pTokenizer->pModule; |
| 128785 | 131268 | |
| 128786 | 131269 | /* Open a cursor on zDoc/nDoc. Check if there are (nSnippet+nDesired) |
| 128787 | 131270 | ** or more tokens in zDoc/nDoc. |
| 128788 | 131271 | */ |
| 128789 | | - rc = pMod->xOpen(pTab->pTokenizer, zDoc, nDoc, &pC); |
| 131272 | + rc = sqlite3Fts3OpenTokenizer(pTab->pTokenizer, iLangid, zDoc, nDoc, &pC); |
| 128790 | 131273 | if( rc!=SQLITE_OK ){ |
| 128791 | 131274 | return rc; |
| 128792 | 131275 | } |
| 128793 | | - pC->pTokenizer = pTab->pTokenizer; |
| 128794 | 131276 | while( rc==SQLITE_OK && iCurrent<(nSnippet+nDesired) ){ |
| 128795 | 131277 | const char *ZDUMMY; int DUMMY1, DUMMY2, DUMMY3; |
| 128796 | 131278 | rc = pMod->xNext(pC, &ZDUMMY, &DUMMY1, &DUMMY2, &DUMMY3, &iCurrent); |
| 128797 | 131279 | } |
| 128798 | 131280 | pMod->xClose(pC); |
| | @@ -128848,15 +131330,14 @@ |
| 128848 | 131330 | } |
| 128849 | 131331 | nDoc = sqlite3_column_bytes(pCsr->pStmt, iCol); |
| 128850 | 131332 | |
| 128851 | 131333 | /* Open a token cursor on the document. */ |
| 128852 | 131334 | pMod = (sqlite3_tokenizer_module *)pTab->pTokenizer->pModule; |
| 128853 | | - rc = pMod->xOpen(pTab->pTokenizer, zDoc, nDoc, &pC); |
| 131335 | + rc = sqlite3Fts3OpenTokenizer(pTab->pTokenizer, pCsr->iLangid, zDoc,nDoc,&pC); |
| 128854 | 131336 | if( rc!=SQLITE_OK ){ |
| 128855 | 131337 | return rc; |
| 128856 | 131338 | } |
| 128857 | | - pC->pTokenizer = pTab->pTokenizer; |
| 128858 | 131339 | |
| 128859 | 131340 | while( rc==SQLITE_OK ){ |
| 128860 | 131341 | int iBegin; /* Offset in zDoc of start of token */ |
| 128861 | 131342 | int iFin; /* Offset in zDoc of end of token */ |
| 128862 | 131343 | int isHighlight; /* True for highlighted terms */ |
| | @@ -128874,11 +131355,13 @@ |
| 128874 | 131355 | } |
| 128875 | 131356 | if( iCurrent<iPos ){ continue; } |
| 128876 | 131357 | |
| 128877 | 131358 | if( !isShiftDone ){ |
| 128878 | 131359 | int n = nDoc - iBegin; |
| 128879 | | - rc = fts3SnippetShift(pTab, nSnippet, &zDoc[iBegin], n, &iPos, &hlmask); |
| 131360 | + rc = fts3SnippetShift( |
| 131361 | + pTab, pCsr->iLangid, nSnippet, &zDoc[iBegin], n, &iPos, &hlmask |
| 131362 | + ); |
| 128880 | 131363 | isShiftDone = 1; |
| 128881 | 131364 | |
| 128882 | 131365 | /* Now that the shift has been done, check if the initial "..." are |
| 128883 | 131366 | ** required. They are required if (a) this is not the first fragment, |
| 128884 | 131367 | ** or (b) this fragment does not begin at position 0 of its column. |
| | @@ -129010,12 +131493,12 @@ |
| 129010 | 131493 | char cArg, |
| 129011 | 131494 | char **pzErr |
| 129012 | 131495 | ){ |
| 129013 | 131496 | if( (cArg==FTS3_MATCHINFO_NPHRASE) |
| 129014 | 131497 | || (cArg==FTS3_MATCHINFO_NCOL) |
| 129015 | | - || (cArg==FTS3_MATCHINFO_NDOC && pTab->bHasStat) |
| 129016 | | - || (cArg==FTS3_MATCHINFO_AVGLENGTH && pTab->bHasStat) |
| 131498 | + || (cArg==FTS3_MATCHINFO_NDOC && pTab->bFts4) |
| 131499 | + || (cArg==FTS3_MATCHINFO_AVGLENGTH && pTab->bFts4) |
| 129017 | 131500 | || (cArg==FTS3_MATCHINFO_LENGTH && pTab->bHasDocsize) |
| 129018 | 131501 | || (cArg==FTS3_MATCHINFO_LCS) |
| 129019 | 131502 | || (cArg==FTS3_MATCHINFO_HITS) |
| 129020 | 131503 | ){ |
| 129021 | 131504 | return SQLITE_OK; |
| | @@ -129607,13 +132090,14 @@ |
| 129607 | 132090 | rc = SQLITE_NOMEM; |
| 129608 | 132091 | goto offsets_out; |
| 129609 | 132092 | } |
| 129610 | 132093 | |
| 129611 | 132094 | /* Initialize a tokenizer iterator to iterate through column iCol. */ |
| 129612 | | - rc = pMod->xOpen(pTab->pTokenizer, zDoc, nDoc, &pC); |
| 132095 | + rc = sqlite3Fts3OpenTokenizer(pTab->pTokenizer, pCsr->iLangid, |
| 132096 | + zDoc, nDoc, &pC |
| 132097 | + ); |
| 129613 | 132098 | if( rc!=SQLITE_OK ) goto offsets_out; |
| 129614 | | - pC->pTokenizer = pTab->pTokenizer; |
| 129615 | 132099 | |
| 129616 | 132100 | rc = pMod->xNext(pC, &ZDUMMY, &NDUMMY, &iStart, &iEnd, &iCurrent); |
| 129617 | 132101 | while( rc==SQLITE_OK ){ |
| 129618 | 132102 | int i; /* Used to loop through terms */ |
| 129619 | 132103 | int iMinPos = 0x7FFFFFFF; /* Position of next token */ |
| | @@ -132774,12 +135258,12 @@ |
| 132774 | 135258 | } |
| 132775 | 135259 | |
| 132776 | 135260 | sqlite3_vtab_config(db, SQLITE_VTAB_CONSTRAINT_SUPPORT, 1); |
| 132777 | 135261 | |
| 132778 | 135262 | /* Allocate the sqlite3_vtab structure */ |
| 132779 | | - nDb = strlen(argv[1]); |
| 132780 | | - nName = strlen(argv[2]); |
| 135263 | + nDb = (int)strlen(argv[1]); |
| 135264 | + nName = (int)strlen(argv[2]); |
| 132781 | 135265 | pRtree = (Rtree *)sqlite3_malloc(sizeof(Rtree)+nDb+nName+2); |
| 132782 | 135266 | if( !pRtree ){ |
| 132783 | 135267 | return SQLITE_NOMEM; |
| 132784 | 135268 | } |
| 132785 | 135269 | memset(pRtree, 0, sizeof(Rtree)+nDb+nName+2); |
| | @@ -132870,14 +135354,14 @@ |
| 132870 | 135354 | RtreeCell cell; |
| 132871 | 135355 | int jj; |
| 132872 | 135356 | |
| 132873 | 135357 | nodeGetCell(&tree, &node, ii, &cell); |
| 132874 | 135358 | sqlite3_snprintf(512-nCell,&zCell[nCell],"%lld", cell.iRowid); |
| 132875 | | - nCell = strlen(zCell); |
| 135359 | + nCell = (int)strlen(zCell); |
| 132876 | 135360 | for(jj=0; jj<tree.nDim*2; jj++){ |
| 132877 | 135361 | sqlite3_snprintf(512-nCell,&zCell[nCell]," %f",(double)cell.aCoord[jj].f); |
| 132878 | | - nCell = strlen(zCell); |
| 135362 | + nCell = (int)strlen(zCell); |
| 132879 | 135363 | } |
| 132880 | 135364 | |
| 132881 | 135365 | if( zText ){ |
| 132882 | 135366 | char *zTextNew = sqlite3_mprintf("%s {%s}", zText, zCell); |
| 132883 | 135367 | sqlite3_free(zText); |
| | @@ -133616,11 +136100,14 @@ |
| 133616 | 136100 | int iInput = 0; |
| 133617 | 136101 | int iOut = 0; |
| 133618 | 136102 | |
| 133619 | 136103 | *ppCursor = 0; |
| 133620 | 136104 | |
| 133621 | | - if( nInput<0 ){ |
| 136105 | + if( zInput==0 ){ |
| 136106 | + nInput = 0; |
| 136107 | + zInput = ""; |
| 136108 | + }else if( nInput<0 ){ |
| 133622 | 136109 | nInput = strlen(zInput); |
| 133623 | 136110 | } |
| 133624 | 136111 | nChar = nInput+1; |
| 133625 | 136112 | pCsr = (IcuCursor *)sqlite3_malloc( |
| 133626 | 136113 | sizeof(IcuCursor) + /* IcuCursor */ |
| 133627 | 136114 | |