Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Difference From 13380236a123bb96 To 73bf3080dc01a374
2012-05-23
| ||
14:03 | including the latest EPSG CRS definitions supported by PROJ4 v.4.8.0 check-in: b9a70ef80a user: sandro tags: trunk | |
2012-05-18
| ||
12:02 | including the latest SQLite 3.7.12 check-in: 13380236a1 user: sandro tags: trunk | |
2012-05-15
| ||
10:05 | fixing a bug in load_shapefile() and load_dbf() [double quoting the table name] check-in: 0076590df5 user: sandro tags: trunk | |
2012-05-12
| ||
02:06 | FiFix a typo in the configure.ac script that causes problems detecting a 3.3.0 or later version of GEOS. check-in: 73bf3080dc user: bradh tags: trunk | |
2012-05-10
| ||
15:40 | udating the build scripts in order to support Android (as suggested by Marco Bernasocchi, QGIS-Android) check-in: 75bf471ff5 user: sandro tags: trunk | |
Changes to src/headers/spatialite/sqlite3.h.
103 103 ** string contains the date and time of the check-in (UTC) and an SHA1 104 104 ** hash of the entire source tree. 105 105 ** 106 106 ** See also: [sqlite3_libversion()], 107 107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()], 108 108 ** [sqlite_version()] and [sqlite_source_id()]. 109 109 */ 110 -#define SQLITE_VERSION "3.7.12" 111 -#define SQLITE_VERSION_NUMBER 3007012 112 -#define SQLITE_SOURCE_ID "2012-05-14 01:41:23 8654aa9540fe9fd210899d83d17f3f407096c004" 110 +#define SQLITE_VERSION "3.7.11" 111 +#define SQLITE_VERSION_NUMBER 3007011 112 +#define SQLITE_SOURCE_ID "2012-03-20 11:35:50 00bb9c9ce4f465e6ac321ced2a9d0062dc364669" 113 113 114 114 /* 115 115 ** CAPI3REF: Run-Time Library Version Numbers 116 116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid 117 117 ** 118 118 ** These interfaces provide the same information as the [SQLITE_VERSION], 119 119 ** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros ................................................................................ 454 454 #define SQLITE_IOERR_SHMSIZE (SQLITE_IOERR | (19<<8)) 455 455 #define SQLITE_IOERR_SHMLOCK (SQLITE_IOERR | (20<<8)) 456 456 #define SQLITE_IOERR_SHMMAP (SQLITE_IOERR | (21<<8)) 457 457 #define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8)) 458 458 #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8)) 459 459 #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8)) 460 460 #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8)) 461 -#define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8)) 462 461 #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8)) 463 462 #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8)) 464 463 #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8)) 465 464 #define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2<<8)) 466 465 467 466 /* 468 467 ** CAPI3REF: Flags For File Open Operations ................................................................................ 768 767 ** integer is the delay. If either integer is negative, then the setting 769 768 ** is not changed but instead the prior value of that setting is written 770 769 ** into the array entry, allowing the current retry settings to be 771 770 ** interrogated. The zDbName parameter is ignored. 772 771 ** 773 772 ** <li>[[SQLITE_FCNTL_PERSIST_WAL]] 774 773 ** ^The [SQLITE_FCNTL_PERSIST_WAL] opcode is used to set or query the 775 -** persistent [WAL | Write Ahead Log] setting. By default, the auxiliary 774 +** persistent [WAL | Write AHead Log] setting. By default, the auxiliary 776 775 ** write ahead log and shared memory files used for transaction control 777 776 ** are automatically deleted when the latest connection to the database 778 777 ** closes. Setting persistent WAL mode causes those files to persist after 779 778 ** close. Persisting the files is useful when other processes that do not 780 779 ** have write permission on the directory containing the database file want 781 780 ** to read the database file, as the WAL and shared memory files must exist 782 781 ** in order for the database to be readable. The fourth parameter to ................................................................................ 1544 1543 ** connection is opened. If it is globally disabled, filenames are 1545 1544 ** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the 1546 1545 ** database connection is opened. By default, URI handling is globally 1547 1546 ** disabled. The default value may be changed by compiling with the 1548 1547 ** [SQLITE_USE_URI] symbol defined. 1549 1548 ** 1550 1549 ** [[SQLITE_CONFIG_PCACHE]] [[SQLITE_CONFIG_GETPCACHE]] 1551 -** <dt>SQLITE_CONFIG_PCACHE and SQLITE_CONFIG_GETPCACHE 1550 +** <dt>SQLITE_CONFIG_PCACHE and SQLITE_CONFNIG_GETPCACHE 1552 1551 ** <dd> These options are obsolete and should not be used by new code. 1553 1552 ** They are retained for backwards compatibility but are now no-ops. 1554 1553 ** </dl> 1555 1554 */ 1556 1555 #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */ 1557 1556 #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */ 1558 1557 #define SQLITE_CONFIG_SERIALIZED 3 /* nil */ ................................................................................ 6003 6002 ** </dd> 6004 6003 ** 6005 6004 ** [[SQLITE_DBSTATUS_CACHE_MISS]] ^(<dt>SQLITE_DBSTATUS_CACHE_MISS</dt> 6006 6005 ** <dd>This parameter returns the number of pager cache misses that have 6007 6006 ** occurred.)^ ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_MISS 6008 6007 ** is always 0. 6009 6008 ** </dd> 6010 -** 6011 -** [[SQLITE_DBSTATUS_CACHE_WRITE]] ^(<dt>SQLITE_DBSTATUS_CACHE_WRITE</dt> 6012 -** <dd>This parameter returns the number of dirty cache entries that have 6013 -** been written to disk. Specifically, the number of pages written to the 6014 -** wal file in wal mode databases, or the number of pages written to the 6015 -** database file in rollback mode databases. Any pages written as part of 6016 -** transaction rollback or database recovery operations are not included. 6017 -** If an IO or other error occurs while writing a page to disk, the effect 6018 -** on subsequent SQLITE_DBSTATUS_CACHE_WRITE requests is undefined.)^ ^The 6019 -** highwater mark associated with SQLITE_DBSTATUS_CACHE_WRITE is always 0. 6020 -** </dd> 6021 6009 ** </dl> 6022 6010 */ 6023 6011 #define SQLITE_DBSTATUS_LOOKASIDE_USED 0 6024 6012 #define SQLITE_DBSTATUS_CACHE_USED 1 6025 6013 #define SQLITE_DBSTATUS_SCHEMA_USED 2 6026 6014 #define SQLITE_DBSTATUS_STMT_USED 3 6027 6015 #define SQLITE_DBSTATUS_LOOKASIDE_HIT 4 6028 6016 #define SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE 5 6029 6017 #define SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL 6 6030 6018 #define SQLITE_DBSTATUS_CACHE_HIT 7 6031 6019 #define SQLITE_DBSTATUS_CACHE_MISS 8 6032 -#define SQLITE_DBSTATUS_CACHE_WRITE 9 6033 -#define SQLITE_DBSTATUS_MAX 9 /* Largest defined DBSTATUS */ 6020 +#define SQLITE_DBSTATUS_MAX 8 /* Largest defined DBSTATUS */ 6034 6021 6035 6022 6036 6023 /* 6037 6024 ** CAPI3REF: Prepared Statement Status 6038 6025 ** 6039 6026 ** ^(Each prepared statement maintains various 6040 6027 ** [SQLITE_STMTSTATUS counters] that measure the number ................................................................................ 6982 6969 ** R-Tree geometry query as follows: 6983 6970 ** 6984 6971 ** SELECT ... FROM <rtree> WHERE <rtree col> MATCH $zGeom(... params ...) 6985 6972 */ 6986 6973 SQLITE_API int sqlite3_rtree_geometry_callback( 6987 6974 sqlite3 *db, 6988 6975 const char *zGeom, 6989 -#ifdef SQLITE_RTREE_INT_ONLY 6990 - int (*xGeom)(sqlite3_rtree_geometry*, int n, sqlite3_int64 *a, int *pRes), 6991 -#else 6992 - int (*xGeom)(sqlite3_rtree_geometry*, int n, double *a, int *pRes), 6993 -#endif 6976 + int (*xGeom)(sqlite3_rtree_geometry *, int nCoord, double *aCoord, int *pRes), 6994 6977 void *pContext 6995 6978 ); 6996 6979 6997 6980 6998 6981 /* 6999 6982 ** A pointer to a structure of the following type is passed as the first 7000 6983 ** argument to callbacks registered using rtree_geometry_callback().
Changes to src/shapefiles/shapefiles.c.
295 295 int current_row; 296 296 char **col_name = NULL; 297 297 unsigned char *blob; 298 298 int blob_size; 299 299 char *geom_type; 300 300 char *txt_dims; 301 301 char *geo_column = column; 302 - char qtable[1024]; 303 - char *xtable = NULL; 304 302 if (!geo_column) 305 303 geo_column = "Geometry"; 306 - xtable = gaiaDoubleQuotedSql (table); 307 - if (xtable) 308 - { 309 - strcpy (qtable, xtable); 310 - free (xtable); 311 - } 312 304 /* checking if TABLE already exists */ 313 305 sprintf (sql, 314 306 "SELECT name FROM sqlite_master WHERE type = 'table' AND name LIKE '%s'", 315 307 table); 316 308 ret = sqlite3_prepare_v2 (sqlite, sql, strlen (sql), &stmt, NULL); 317 309 if (ret != SQLITE_OK) 318 310 { ................................................................................ 456 448 else 457 449 sprintf (err_msg, "load shapefile error: <%s>\n", errMsg); 458 450 sqlite3_free (errMsg); 459 451 sqlError = 1; 460 452 goto clean_up; 461 453 } 462 454 /* creating the Table */ 463 - sprintf (sql, "CREATE TABLE \"%s\"", qtable); 455 + sprintf (sql, "CREATE TABLE %s", table); 464 456 strcat (sql, " (\nPK_UID INTEGER PRIMARY KEY AUTOINCREMENT"); 465 457 cnt = 0; 466 458 dbf_field = shp->Dbf->First; 467 459 while (dbf_field) 468 460 { 469 461 strcat (sql, ",\n\""); 470 462 strcat (sql, *(col_name + cnt)); ................................................................................ 618 610 / LINESTRING/MULTILINESTRING or 619 611 / POLYGON/MULTIPOLYGON 620 612 */ 621 613 gaiaShpAnalyze (shp); 622 614 } 623 615 } 624 616 /* preparing the INSERT INTO parametrerized statement */ 625 - sprintf (sql, "INSERT INTO \"%s\" (PK_UID,", qtable); 617 + sprintf (sql, "INSERT INTO %s (PK_UID,", table); 626 618 cnt = 0; 627 619 dbf_field = shp->Dbf->First; 628 620 while (dbf_field) 629 621 { 630 622 /* columns corresponding to some DBF attribute */ 631 623 strcat (sql, "\""); 632 624 strcat (sql, *(col_name + cnt++)); ................................................................................ 695 687 case GAIA_DOUBLE_VALUE: 696 688 sqlite3_bind_double (stmt, cnt + 2, 697 689 dbf_field->Value->DblValue); 698 690 break; 699 691 case GAIA_TEXT_VALUE: 700 692 sqlite3_bind_text (stmt, cnt + 2, 701 693 dbf_field->Value->TxtValue, 702 - strlen (dbf_field-> 703 - Value->TxtValue), 694 + strlen (dbf_field->Value-> 695 + TxtValue), 704 696 SQLITE_STATIC); 705 697 break; 706 698 default: 707 699 sqlite3_bind_null (stmt, cnt + 2); 708 700 break; 709 701 } 710 702 } ................................................................................ 1490 1482 int seed; 1491 1483 int len; 1492 1484 int dup; 1493 1485 int idup; 1494 1486 int current_row; 1495 1487 char **col_name = NULL; 1496 1488 int deleted; 1497 - char qtable[1024]; 1498 - char *xtable = NULL; 1499 - xtable = gaiaDoubleQuotedSql (table); 1500 - if (xtable) 1501 - { 1502 - strcpy (qtable, xtable); 1503 - free (xtable); 1504 - } 1505 1489 /* checking if TABLE already exists */ 1506 1490 sprintf (sql, 1507 1491 "SELECT name FROM sqlite_master WHERE type = 'table' AND name LIKE '%s'", 1508 1492 table); 1509 1493 ret = sqlite3_prepare_v2 (sqlite, sql, strlen (sql), &stmt, NULL); 1510 1494 if (ret != SQLITE_OK) 1511 1495 { ................................................................................ 1611 1595 else 1612 1596 sprintf (err_msg, "load DBF error: <%s>\n", errMsg); 1613 1597 sqlite3_free (errMsg); 1614 1598 sqlError = 1; 1615 1599 goto clean_up; 1616 1600 } 1617 1601 /* creating the Table */ 1618 - sprintf (sql, "CREATE TABLE \"%s\"", qtable); 1602 + sprintf (sql, "CREATE TABLE %s", table); 1619 1603 strcat (sql, " (\nPK_UID INTEGER PRIMARY KEY AUTOINCREMENT"); 1620 1604 cnt = 0; 1621 1605 dbf_field = dbf->Dbf->First; 1622 1606 while (dbf_field) 1623 1607 { 1624 1608 strcat (sql, ",\n\""); 1625 1609 strcat (sql, *(col_name + cnt)); ................................................................................ 1663 1647 else 1664 1648 sprintf (err_msg, "load DBF error: <%s>\n", errMsg); 1665 1649 sqlite3_free (errMsg); 1666 1650 sqlError = 1; 1667 1651 goto clean_up; 1668 1652 } 1669 1653 /* preparing the INSERT INTO parametrerized statement */ 1670 - sprintf (sql, "INSERT INTO \"%s\" (PK_UID", qtable); 1654 + sprintf (sql, "INSERT INTO %s (PK_UID", table); 1671 1655 cnt = 0; 1672 1656 dbf_field = dbf->Dbf->First; 1673 1657 while (dbf_field) 1674 1658 { 1675 1659 /* columns corresponding to some DBF attribute */ 1676 1660 strcat (sql, ",\""); 1677 1661 strcat (sql, *(col_name + cnt++)); ................................................................................ 1742 1726 case GAIA_DOUBLE_VALUE: 1743 1727 sqlite3_bind_double (stmt, cnt + 2, 1744 1728 dbf_field->Value->DblValue); 1745 1729 break; 1746 1730 case GAIA_TEXT_VALUE: 1747 1731 sqlite3_bind_text (stmt, cnt + 2, 1748 1732 dbf_field->Value->TxtValue, 1749 - strlen (dbf_field-> 1750 - Value->TxtValue), 1733 + strlen (dbf_field->Value-> 1734 + TxtValue), 1751 1735 SQLITE_STATIC); 1752 1736 break; 1753 1737 default: 1754 1738 sqlite3_bind_null (stmt, cnt + 2); 1755 1739 break; 1756 1740 } 1757 1741 }
Changes to src/sqlite3/sqlite3.c.
1 1 /****************************************************************************** 2 2 ** This file is an amalgamation of many separate C source files from SQLite 3 -** version 3.7.12. By combining all the individual C code files into this 3 +** version 3.7.11. 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. 9 9 ** 10 10 ** This file is all you need to compile SQLite. To use SQLite in other ................................................................................ 653 653 ** string contains the date and time of the check-in (UTC) and an SHA1 654 654 ** hash of the entire source tree. 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.12" 661 -#define SQLITE_VERSION_NUMBER 3007012 662 -#define SQLITE_SOURCE_ID "2012-05-14 01:41:23 8654aa9540fe9fd210899d83d17f3f407096c004" 660 +#define SQLITE_VERSION "3.7.11" 661 +#define SQLITE_VERSION_NUMBER 3007011 662 +#define SQLITE_SOURCE_ID "2012-03-20 11:35:50 00bb9c9ce4f465e6ac321ced2a9d0062dc364669" 663 663 664 664 /* 665 665 ** CAPI3REF: Run-Time Library Version Numbers 666 666 ** KEYWORDS: sqlite3_version, sqlite3_sourceid 667 667 ** 668 668 ** These interfaces provide the same information as the [SQLITE_VERSION], 669 669 ** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros ................................................................................ 1004 1004 #define SQLITE_IOERR_SHMSIZE (SQLITE_IOERR | (19<<8)) 1005 1005 #define SQLITE_IOERR_SHMLOCK (SQLITE_IOERR | (20<<8)) 1006 1006 #define SQLITE_IOERR_SHMMAP (SQLITE_IOERR | (21<<8)) 1007 1007 #define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8)) 1008 1008 #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8)) 1009 1009 #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8)) 1010 1010 #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8)) 1011 -#define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8)) 1012 1011 #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8)) 1013 1012 #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8)) 1014 1013 #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8)) 1015 1014 #define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2<<8)) 1016 1015 1017 1016 /* 1018 1017 ** CAPI3REF: Flags For File Open Operations ................................................................................ 1318 1317 ** integer is the delay. If either integer is negative, then the setting 1319 1318 ** is not changed but instead the prior value of that setting is written 1320 1319 ** into the array entry, allowing the current retry settings to be 1321 1320 ** interrogated. The zDbName parameter is ignored. 1322 1321 ** 1323 1322 ** <li>[[SQLITE_FCNTL_PERSIST_WAL]] 1324 1323 ** ^The [SQLITE_FCNTL_PERSIST_WAL] opcode is used to set or query the 1325 -** persistent [WAL | Write Ahead Log] setting. By default, the auxiliary 1324 +** persistent [WAL | Write AHead Log] setting. By default, the auxiliary 1326 1325 ** write ahead log and shared memory files used for transaction control 1327 1326 ** are automatically deleted when the latest connection to the database 1328 1327 ** closes. Setting persistent WAL mode causes those files to persist after 1329 1328 ** close. Persisting the files is useful when other processes that do not 1330 1329 ** have write permission on the directory containing the database file want 1331 1330 ** to read the database file, as the WAL and shared memory files must exist 1332 1331 ** in order for the database to be readable. The fourth parameter to ................................................................................ 2094 2093 ** connection is opened. If it is globally disabled, filenames are 2095 2094 ** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the 2096 2095 ** database connection is opened. By default, URI handling is globally 2097 2096 ** disabled. The default value may be changed by compiling with the 2098 2097 ** [SQLITE_USE_URI] symbol defined. 2099 2098 ** 2100 2099 ** [[SQLITE_CONFIG_PCACHE]] [[SQLITE_CONFIG_GETPCACHE]] 2101 -** <dt>SQLITE_CONFIG_PCACHE and SQLITE_CONFIG_GETPCACHE 2100 +** <dt>SQLITE_CONFIG_PCACHE and SQLITE_CONFNIG_GETPCACHE 2102 2101 ** <dd> These options are obsolete and should not be used by new code. 2103 2102 ** They are retained for backwards compatibility but are now no-ops. 2104 2103 ** </dl> 2105 2104 */ 2106 2105 #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */ 2107 2106 #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */ 2108 2107 #define SQLITE_CONFIG_SERIALIZED 3 /* nil */ ................................................................................ 6553 6552 ** </dd> 6554 6553 ** 6555 6554 ** [[SQLITE_DBSTATUS_CACHE_MISS]] ^(<dt>SQLITE_DBSTATUS_CACHE_MISS</dt> 6556 6555 ** <dd>This parameter returns the number of pager cache misses that have 6557 6556 ** occurred.)^ ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_MISS 6558 6557 ** is always 0. 6559 6558 ** </dd> 6560 -** 6561 -** [[SQLITE_DBSTATUS_CACHE_WRITE]] ^(<dt>SQLITE_DBSTATUS_CACHE_WRITE</dt> 6562 -** <dd>This parameter returns the number of dirty cache entries that have 6563 -** been written to disk. Specifically, the number of pages written to the 6564 -** wal file in wal mode databases, or the number of pages written to the 6565 -** database file in rollback mode databases. Any pages written as part of 6566 -** transaction rollback or database recovery operations are not included. 6567 -** If an IO or other error occurs while writing a page to disk, the effect 6568 -** on subsequent SQLITE_DBSTATUS_CACHE_WRITE requests is undefined.)^ ^The 6569 -** highwater mark associated with SQLITE_DBSTATUS_CACHE_WRITE is always 0. 6570 -** </dd> 6571 6559 ** </dl> 6572 6560 */ 6573 6561 #define SQLITE_DBSTATUS_LOOKASIDE_USED 0 6574 6562 #define SQLITE_DBSTATUS_CACHE_USED 1 6575 6563 #define SQLITE_DBSTATUS_SCHEMA_USED 2 6576 6564 #define SQLITE_DBSTATUS_STMT_USED 3 6577 6565 #define SQLITE_DBSTATUS_LOOKASIDE_HIT 4 6578 6566 #define SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE 5 6579 6567 #define SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL 6 6580 6568 #define SQLITE_DBSTATUS_CACHE_HIT 7 6581 6569 #define SQLITE_DBSTATUS_CACHE_MISS 8 6582 -#define SQLITE_DBSTATUS_CACHE_WRITE 9 6583 -#define SQLITE_DBSTATUS_MAX 9 /* Largest defined DBSTATUS */ 6570 +#define SQLITE_DBSTATUS_MAX 8 /* Largest defined DBSTATUS */ 6584 6571 6585 6572 6586 6573 /* 6587 6574 ** CAPI3REF: Prepared Statement Status 6588 6575 ** 6589 6576 ** ^(Each prepared statement maintains various 6590 6577 ** [SQLITE_STMTSTATUS counters] that measure the number ................................................................................ 7532 7519 ** R-Tree geometry query as follows: 7533 7520 ** 7534 7521 ** SELECT ... FROM <rtree> WHERE <rtree col> MATCH $zGeom(... params ...) 7535 7522 */ 7536 7523 SQLITE_API int sqlite3_rtree_geometry_callback( 7537 7524 sqlite3 *db, 7538 7525 const char *zGeom, 7539 -#ifdef SQLITE_RTREE_INT_ONLY 7540 - int (*xGeom)(sqlite3_rtree_geometry*, int n, sqlite3_int64 *a, int *pRes), 7541 -#else 7542 - int (*xGeom)(sqlite3_rtree_geometry*, int n, double *a, int *pRes), 7543 -#endif 7526 + int (*xGeom)(sqlite3_rtree_geometry *, int nCoord, double *aCoord, int *pRes), 7544 7527 void *pContext 7545 7528 ); 7546 7529 7547 7530 7548 7531 /* 7549 7532 ** A pointer to a structure of the following type is passed as the first 7550 7533 ** argument to callbacks registered using rtree_geometry_callback(). ................................................................................ 9934 9917 struct FuncDestructor { 9935 9918 int nRef; 9936 9919 void (*xDestroy)(void *); 9937 9920 void *pUserData; 9938 9921 }; 9939 9922 9940 9923 /* 9941 -** Possible values for FuncDef.flags. Note that the _LENGTH and _TYPEOF 9942 -** values must correspond to OPFLAG_LENGTHARG and OPFLAG_TYPEOFARG. There 9943 -** are assert() statements in the code to verify this. 9924 +** Possible values for FuncDef.flags 9944 9925 */ 9945 9926 #define SQLITE_FUNC_LIKE 0x01 /* Candidate for the LIKE optimization */ 9946 9927 #define SQLITE_FUNC_CASE 0x02 /* Case-sensitive LIKE-type function */ 9947 9928 #define SQLITE_FUNC_EPHEM 0x04 /* Ephemeral. Delete with VDBE */ 9948 9929 #define SQLITE_FUNC_NEEDCOLL 0x08 /* sqlite3GetFuncCollSeq() might be called */ 9949 -#define SQLITE_FUNC_COUNT 0x10 /* Built-in count(*) aggregate */ 9950 -#define SQLITE_FUNC_COALESCE 0x20 /* Built-in coalesce() or ifnull() function */ 9951 -#define SQLITE_FUNC_LENGTH 0x40 /* Built-in length() function */ 9952 -#define SQLITE_FUNC_TYPEOF 0x80 /* Built-in typeof() function */ 9930 +#define SQLITE_FUNC_COUNT 0x20 /* Built-in count(*) aggregate */ 9931 +#define SQLITE_FUNC_COALESCE 0x40 /* Built-in coalesce() or ifnull() function */ 9953 9932 9954 9933 /* 9955 9934 ** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are 9956 9935 ** used to create the initializers for the FuncDef structures. 9957 9936 ** 9958 9937 ** FUNCTION(zName, nArg, iArg, bNC, xFunc) 9959 9938 ** Used to create a scalar function definition of a function zName ................................................................................ 9973 9952 ** that accepts nArg arguments and is implemented by a call to C 9974 9953 ** function likeFunc. Argument pArg is cast to a (void *) and made 9975 9954 ** available as the function user-data (sqlite3_user_data()). The 9976 9955 ** FuncDef.flags variable is set to the value passed as the flags 9977 9956 ** parameter. 9978 9957 */ 9979 9958 #define FUNCTION(zName, nArg, iArg, bNC, xFunc) \ 9980 - {nArg, SQLITE_UTF8, (bNC*SQLITE_FUNC_NEEDCOLL), \ 9981 - SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0} 9982 -#define FUNCTION2(zName, nArg, iArg, bNC, xFunc, extraFlags) \ 9983 - {nArg, SQLITE_UTF8, (bNC*SQLITE_FUNC_NEEDCOLL)|extraFlags, \ 9959 + {nArg, SQLITE_UTF8, bNC*SQLITE_FUNC_NEEDCOLL, \ 9984 9960 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0} 9985 9961 #define STR_FUNCTION(zName, nArg, pArg, bNC, xFunc) \ 9986 9962 {nArg, SQLITE_UTF8, bNC*SQLITE_FUNC_NEEDCOLL, \ 9987 9963 pArg, 0, xFunc, 0, 0, #zName, 0, 0} 9988 9964 #define LIKEFUNC(zName, nArg, arg, flags) \ 9989 9965 {nArg, SQLITE_UTF8, flags, (void *)arg, 0, likeFunc, 0, 0, #zName, 0, 0} 9990 9966 #define AGGREGATE(zName, nArg, arg, nc, xStep, xFinal) \ ................................................................................ 10206 10182 Select *pSelect; /* NULL for tables. Points to definition if a view. */ 10207 10183 u16 nRef; /* Number of pointers to this Table */ 10208 10184 u8 tabFlags; /* Mask of TF_* values */ 10209 10185 u8 keyConf; /* What to do in case of uniqueness conflict on iPKey */ 10210 10186 FKey *pFKey; /* Linked list of all foreign keys in this table */ 10211 10187 char *zColAff; /* String defining the affinity of each column */ 10212 10188 #ifndef SQLITE_OMIT_CHECK 10213 - ExprList *pCheck; /* All CHECK constraints */ 10189 + Expr *pCheck; /* The AND of all CHECK constraints */ 10214 10190 #endif 10215 10191 #ifndef SQLITE_OMIT_ALTERTABLE 10216 10192 int addColOffset; /* Offset in CREATE TABLE stmt to add a new column */ 10217 10193 #endif 10218 10194 #ifndef SQLITE_OMIT_VIRTUALTABLE 10219 10195 VTable *pVTable; /* List of VTable objects. */ 10220 10196 int nModuleArg; /* Number of arguments to the module */ ................................................................................ 10599 10575 ** TK_TRIGGER: 1 -> new, 0 -> old */ 10600 10576 ynVar iColumn; /* TK_COLUMN: column index. -1 for rowid. 10601 10577 ** TK_VARIABLE: variable number (always >= 1). */ 10602 10578 i16 iAgg; /* Which entry in pAggInfo->aCol[] or ->aFunc[] */ 10603 10579 i16 iRightJoinTable; /* If EP_FromJoin, the right table of the join */ 10604 10580 u8 flags2; /* Second set of flags. EP2_... */ 10605 10581 u8 op2; /* If a TK_REGISTER, the original value of Expr.op */ 10606 - /* If TK_COLUMN, the value of p5 for OP_Column */ 10607 10582 AggInfo *pAggInfo; /* Used by TK_AGG_COLUMN and TK_AGG_FUNCTION */ 10608 10583 Table *pTab; /* Table for TK_COLUMN expressions. */ 10609 10584 #if SQLITE_MAX_EXPR_DEPTH>0 10610 10585 int nHeight; /* Height of the tree headed by this node */ 10611 10586 #endif 10612 10587 }; 10613 10588 ................................................................................ 10622 10597 #define EP_VarSelect 0x0020 /* pSelect is correlated, not constant */ 10623 10598 #define EP_DblQuoted 0x0040 /* token.z was originally in "..." */ 10624 10599 #define EP_InfixFunc 0x0080 /* True for an infix function: LIKE, GLOB, etc */ 10625 10600 #define EP_ExpCollate 0x0100 /* Collating sequence specified explicitly */ 10626 10601 #define EP_FixedDest 0x0200 /* Result needed in a specific register */ 10627 10602 #define EP_IntValue 0x0400 /* Integer value contained in u.iValue */ 10628 10603 #define EP_xIsSelect 0x0800 /* x.pSelect is valid (otherwise x.pList is) */ 10629 -#define EP_Hint 0x1000 /* Not used */ 10604 +#define EP_Hint 0x1000 /* Optimizer hint. Not required for correctness */ 10630 10605 #define EP_Reduced 0x2000 /* Expr struct is EXPR_REDUCEDSIZE bytes only */ 10631 10606 #define EP_TokenOnly 0x4000 /* Expr struct is EXPR_TOKENONLYSIZE bytes only */ 10632 10607 #define EP_Static 0x8000 /* Held in memory not obtained from malloc() */ 10633 10608 10634 10609 /* 10635 10610 ** The following are the meanings of bits in the Expr.flags2 field. 10636 10611 */ ................................................................................ 10936 10911 SrcList *pSrcList; /* One or more tables used to resolve names */ 10937 10912 ExprList *pEList; /* Optional list of named expressions */ 10938 10913 int nRef; /* Number of names resolved by this context */ 10939 10914 int nErr; /* Number of errors encountered while resolving names */ 10940 10915 u8 allowAgg; /* Aggregate functions allowed here */ 10941 10916 u8 hasAgg; /* True if aggregates are seen */ 10942 10917 u8 isCheck; /* True if resolving names in a CHECK constraint */ 10918 + int nDepth; /* Depth of subquery recursion. 1 for no recursion */ 10943 10919 AggInfo *pAggInfo; /* Information about aggregates at this level */ 10944 10920 NameContext *pNext; /* Next outer name context. NULL for outermost */ 10945 10921 }; 10946 10922 10947 10923 /* 10948 10924 ** An instance of the following structure contains all information 10949 10925 ** needed to generate code for a single SELECT statement. ................................................................................ 11140 11116 yDbMask writeMask; /* Start a write transaction on these databases */ 11141 11117 yDbMask cookieMask; /* Bitmask of schema verified databases */ 11142 11118 int cookieGoto; /* Address of OP_Goto to cookie verifier subroutine */ 11143 11119 int cookieValue[SQLITE_MAX_ATTACHED+2]; /* Values of cookies to verify */ 11144 11120 int regRowid; /* Register holding rowid of CREATE TABLE entry */ 11145 11121 int regRoot; /* Register holding root page number for new objects */ 11146 11122 int nMaxArg; /* Max args passed to user function by sub-program */ 11147 - Token constraintName;/* Name of the constraint currently being parsed */ 11148 11123 #ifndef SQLITE_OMIT_SHARED_CACHE 11149 11124 int nTableLock; /* Number of locks in aTableLock */ 11150 11125 TableLock *aTableLock; /* Required table locks for shared-cache mode */ 11151 11126 #endif 11152 11127 AutoincInfo *pAinc; /* Information about AUTOINCREMENT counters */ 11153 11128 11154 11129 /* Information used while coding trigger programs. */ ................................................................................ 11209 11184 */ 11210 11185 struct AuthContext { 11211 11186 const char *zAuthContext; /* Put saved Parse.zAuthContext here */ 11212 11187 Parse *pParse; /* The Parse structure */ 11213 11188 }; 11214 11189 11215 11190 /* 11216 -** Bitfield flags for P5 value in various opcodes. 11191 +** Bitfield flags for P5 value in OP_Insert and OP_Delete 11217 11192 */ 11218 11193 #define OPFLAG_NCHANGE 0x01 /* Set to update db->nChange */ 11219 11194 #define OPFLAG_LASTROWID 0x02 /* Set to update db->lastRowid */ 11220 11195 #define OPFLAG_ISUPDATE 0x04 /* This OP_Insert is an sql UPDATE */ 11221 11196 #define OPFLAG_APPEND 0x08 /* This is likely to be an append */ 11222 11197 #define OPFLAG_USESEEKRESULT 0x10 /* Try to avoid a seek in BtreeInsert() */ 11223 11198 #define OPFLAG_CLEARCACHE 0x20 /* Clear pseudo-table cache in OP_Column */ 11224 -#define OPFLAG_LENGTHARG 0x40 /* OP_Column only used for length() */ 11225 -#define OPFLAG_TYPEOFARG 0x80 /* OP_Column only used for typeof() */ 11226 11199 11227 11200 /* 11228 11201 * Each trigger present in the database schema is stored as an instance of 11229 11202 * struct Trigger. 11230 11203 * 11231 11204 * Pointers to instances of struct Trigger are stored in two ways. 11232 11205 * 1. In the "trigHash" hash table (part of the sqlite3* that represents the ................................................................................ 11401 11374 struct Walker { 11402 11375 int (*xExprCallback)(Walker*, Expr*); /* Callback for expressions */ 11403 11376 int (*xSelectCallback)(Walker*,Select*); /* Callback for SELECTs */ 11404 11377 Parse *pParse; /* Parser context. */ 11405 11378 union { /* Extra data for callback */ 11406 11379 NameContext *pNC; /* Naming context */ 11407 11380 int i; /* Integer value */ 11408 - SrcList *pSrcList; /* FROM clause */ 11409 11381 } u; 11410 11382 }; 11411 11383 11412 11384 /* Forward declarations */ 11413 11385 SQLITE_PRIVATE int sqlite3WalkExpr(Walker*, Expr*); 11414 11386 SQLITE_PRIVATE int sqlite3WalkExprList(Walker*, ExprList*); 11415 11387 SQLITE_PRIVATE int sqlite3WalkSelect(Walker*, Select*); ................................................................................ 11703 11675 #if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) && !defined(SQLITE_OMIT_SUBQUERY) 11704 11676 SQLITE_PRIVATE Expr *sqlite3LimitWhere(Parse *, SrcList *, Expr *, ExprList *, Expr *, Expr *, char *); 11705 11677 #endif 11706 11678 SQLITE_PRIVATE void sqlite3DeleteFrom(Parse*, SrcList*, Expr*); 11707 11679 SQLITE_PRIVATE void sqlite3Update(Parse*, SrcList*, ExprList*, Expr*, int); 11708 11680 SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin(Parse*, SrcList*, Expr*, ExprList**,ExprList*,u16); 11709 11681 SQLITE_PRIVATE void sqlite3WhereEnd(WhereInfo*); 11710 -SQLITE_PRIVATE int sqlite3ExprCodeGetColumn(Parse*, Table*, int, int, int, u8); 11682 +SQLITE_PRIVATE int sqlite3ExprCodeGetColumn(Parse*, Table*, int, int, int); 11711 11683 SQLITE_PRIVATE void sqlite3ExprCodeGetColumnOfTable(Vdbe*, Table*, int, int, int); 11712 11684 SQLITE_PRIVATE void sqlite3ExprCodeMove(Parse*, int, int, int); 11713 11685 SQLITE_PRIVATE void sqlite3ExprCodeCopy(Parse*, int, int, int); 11714 11686 SQLITE_PRIVATE void sqlite3ExprCacheStore(Parse*, int, int, int); 11715 11687 SQLITE_PRIVATE void sqlite3ExprCachePush(Parse*); 11716 11688 SQLITE_PRIVATE void sqlite3ExprCachePop(Parse*, int); 11717 11689 SQLITE_PRIVATE void sqlite3ExprCacheRemove(Parse*, int, int); ................................................................................ 11770 11742 SQLITE_PRIVATE void sqlite3HaltConstraint(Parse*, int, char*, int); 11771 11743 SQLITE_PRIVATE Expr *sqlite3ExprDup(sqlite3*,Expr*,int); 11772 11744 SQLITE_PRIVATE ExprList *sqlite3ExprListDup(sqlite3*,ExprList*,int); 11773 11745 SQLITE_PRIVATE SrcList *sqlite3SrcListDup(sqlite3*,SrcList*,int); 11774 11746 SQLITE_PRIVATE IdList *sqlite3IdListDup(sqlite3*,IdList*); 11775 11747 SQLITE_PRIVATE Select *sqlite3SelectDup(sqlite3*,Select*,int); 11776 11748 SQLITE_PRIVATE void sqlite3FuncDefInsert(FuncDefHash*, FuncDef*); 11777 -SQLITE_PRIVATE FuncDef *sqlite3FindFunction(sqlite3*,const char*,int,int,u8,u8); 11749 +SQLITE_PRIVATE FuncDef *sqlite3FindFunction(sqlite3*,const char*,int,int,u8,int); 11778 11750 SQLITE_PRIVATE void sqlite3RegisterBuiltinFunctions(sqlite3*); 11779 11751 SQLITE_PRIVATE void sqlite3RegisterDateTimeFunctions(void); 11780 11752 SQLITE_PRIVATE void sqlite3RegisterGlobalFunctions(void); 11781 11753 SQLITE_PRIVATE int sqlite3SafetyCheckOk(sqlite3*); 11782 11754 SQLITE_PRIVATE int sqlite3SafetyCheckSickOrOk(sqlite3*); 11783 11755 SQLITE_PRIVATE void sqlite3ChangeCookie(Parse*, int); 11784 11756 ................................................................................ 13535 13507 13536 13508 /* 13537 13509 ** Set *pCurrent to the total cache hits or misses encountered by all 13538 13510 ** pagers the database handle is connected to. *pHighwater is always set 13539 13511 ** to zero. 13540 13512 */ 13541 13513 case SQLITE_DBSTATUS_CACHE_HIT: 13542 - case SQLITE_DBSTATUS_CACHE_MISS: 13543 - case SQLITE_DBSTATUS_CACHE_WRITE:{ 13514 + case SQLITE_DBSTATUS_CACHE_MISS: { 13544 13515 int i; 13545 13516 int nRet = 0; 13546 13517 assert( SQLITE_DBSTATUS_CACHE_MISS==SQLITE_DBSTATUS_CACHE_HIT+1 ); 13547 - assert( SQLITE_DBSTATUS_CACHE_WRITE==SQLITE_DBSTATUS_CACHE_HIT+2 ); 13548 13518 13549 13519 for(i=0; i<db->nDb; i++){ 13550 13520 if( db->aDb[i].pBt ){ 13551 13521 Pager *pPager = sqlite3BtreePager(db->aDb[i].pBt); 13552 13522 sqlite3PagerCacheStat(pPager, op, resetFlag, &nRet); 13553 13523 } 13554 13524 } ................................................................................ 24998 24968 ** Default permissions when creating a new file 24999 24969 */ 25000 24970 #ifndef SQLITE_DEFAULT_FILE_PERMISSIONS 25001 24971 # define SQLITE_DEFAULT_FILE_PERMISSIONS 0644 25002 24972 #endif 25003 24973 25004 24974 /* 25005 -** Default permissions when creating auto proxy dir 25006 -*/ 24975 + ** Default permissions when creating auto proxy dir 24976 + */ 25007 24977 #ifndef SQLITE_DEFAULT_PROXYDIR_PERMISSIONS 25008 24978 # define SQLITE_DEFAULT_PROXYDIR_PERMISSIONS 0755 25009 24979 #endif 25010 24980 25011 24981 /* 25012 24982 ** Maximum supported path-length. 25013 24983 */ ................................................................................ 25553 25523 if( aSyscall[i].pCurrent!=0 ) return aSyscall[i].zName; 25554 25524 } 25555 25525 return 0; 25556 25526 } 25557 25527 25558 25528 /* 25559 25529 ** Invoke open(). Do so multiple times, until it either succeeds or 25560 -** fails for some reason other than EINTR. 25530 +** files for some reason other than EINTR. 25561 25531 ** 25562 25532 ** If the file creation mode "m" is 0 then set it to the default for 25563 25533 ** SQLite. The default is SQLITE_DEFAULT_FILE_PERMISSIONS (normally 25564 25534 ** 0644) as modified by the system umask. If m is not 0, then 25565 25535 ** make the file creation mode be exactly m ignoring the umask. 25566 25536 ** 25567 25537 ** The m parameter will be non-zero only when creating -wal, -journal, ................................................................................ 25569 25539 ** permissions as their original database, unadulterated by the umask. 25570 25540 ** In that way, if a database file is -rw-rw-rw or -rw-rw-r-, and a 25571 25541 ** transaction crashes and leaves behind hot journals, then any 25572 25542 ** process that is able to write to the database will also be able to 25573 25543 ** recover the hot journals. 25574 25544 */ 25575 25545 static int robust_open(const char *z, int f, mode_t m){ 25576 - int fd; 25546 + int rc; 25577 25547 mode_t m2; 25578 25548 mode_t origM = 0; 25579 25549 if( m==0 ){ 25580 25550 m2 = SQLITE_DEFAULT_FILE_PERMISSIONS; 25581 25551 }else{ 25582 25552 m2 = m; 25583 25553 origM = osUmask(0); 25584 25554 } 25585 - do{ 25586 -#if defined(O_CLOEXEC) 25587 - fd = osOpen(z,f|O_CLOEXEC,m2); 25588 -#else 25589 - fd = osOpen(z,f,m2); 25590 -#endif 25591 - }while( fd<0 && errno==EINTR ); 25555 + do{ rc = osOpen(z,f,m2); }while( rc<0 && errno==EINTR ); 25592 25556 if( m ){ 25593 25557 osUmask(origM); 25594 25558 } 25595 -#if defined(FD_CLOEXEC) && (!defined(O_CLOEXEC) || O_CLOEXEC==0) 25596 - if( fd>=0 ) osFcntl(fd, F_SETFD, osFcntl(fd, F_GETFD, 0) | FD_CLOEXEC); 25597 -#endif 25598 - return fd; 25559 + return rc; 25599 25560 } 25600 25561 25601 25562 /* 25602 25563 ** Helper functions to obtain and relinquish the global mutex. The 25603 25564 ** global mutex is used to protect the unixInodeInfo and 25604 25565 ** vxworksFileId objects used by this file, all of which may be 25605 25566 ** shared by multiple threads. ................................................................................ 28386 28347 28387 28348 sqlite3_snprintf(MAX_PATHNAME, zDirname, "%s", zFilename); 28388 28349 for(ii=(int)strlen(zDirname); ii>1 && zDirname[ii]!='/'; ii--); 28389 28350 if( ii>0 ){ 28390 28351 zDirname[ii] = '\0'; 28391 28352 fd = robust_open(zDirname, O_RDONLY|O_BINARY, 0); 28392 28353 if( fd>=0 ){ 28354 +#ifdef FD_CLOEXEC 28355 + osFcntl(fd, F_SETFD, osFcntl(fd, F_GETFD, 0) | FD_CLOEXEC); 28356 +#endif 28393 28357 OSTRACE(("OPENDIR %-3d %s\n", fd, zDirname)); 28394 28358 } 28395 28359 } 28396 28360 *pFd = fd; 28397 28361 return (fd>=0?SQLITE_OK:unixLogError(SQLITE_CANTOPEN_BKPT, "open", zDirname)); 28398 28362 } 28399 28363 ................................................................................ 28468 28432 SimulateIOError( return SQLITE_IOERR_TRUNCATE ); 28469 28433 28470 28434 /* If the user has configured a chunk-size for this file, truncate the 28471 28435 ** file so that it consists of an integer number of chunks (i.e. the 28472 28436 ** actual file size after the operation may be larger than the requested 28473 28437 ** size). 28474 28438 */ 28475 - if( pFile->szChunk>0 ){ 28439 + if( pFile->szChunk ){ 28476 28440 nByte = ((nByte + pFile->szChunk - 1)/pFile->szChunk) * pFile->szChunk; 28477 28441 } 28478 28442 28479 28443 rc = robust_ftruncate(pFile->h, (off_t)nByte); 28480 28444 if( rc ){ 28481 28445 pFile->lastErrno = errno; 28482 28446 return unixLogError(SQLITE_IOERR_TRUNCATE, "ftruncate", pFile->zPath); ................................................................................ 30229 30193 #endif 30230 30194 } 30231 30195 #if SQLITE_ENABLE_LOCKING_STYLE 30232 30196 else{ 30233 30197 p->openFlags = openFlags; 30234 30198 } 30235 30199 #endif 30200 + 30201 +#ifdef FD_CLOEXEC 30202 + osFcntl(fd, F_SETFD, osFcntl(fd, F_GETFD, 0) | FD_CLOEXEC); 30203 +#endif 30236 30204 30237 30205 noLock = eType!=SQLITE_OPEN_MAIN_DB; 30238 30206 30239 30207 30240 30208 #if defined(__APPLE__) || SQLITE_ENABLE_LOCKING_STYLE 30241 30209 if( fstatfs(fd, &fsInfo) == -1 ){ 30242 30210 ((unixFile*)pFile)->lastErrno = errno; ................................................................................ 33757 33725 ){ 33758 33726 osSleep(100); /* Wait a little before trying again */ 33759 33727 } 33760 33728 sqlite3_free(pFile->zDeleteOnClose); 33761 33729 } 33762 33730 #endif 33763 33731 OSTRACE(("CLOSE %d %s\n", pFile->h, rc ? "ok" : "failed")); 33764 - if( rc ){ 33765 - pFile->h = NULL; 33766 - } 33767 33732 OpenCounter(-1); 33768 33733 return rc ? SQLITE_OK 33769 33734 : winLogError(SQLITE_IOERR_CLOSE, osGetLastError(), 33770 33735 "winClose", pFile->zPath); 33771 33736 } 33772 33737 33773 33738 /* ................................................................................ 33777 33742 */ 33778 33743 static int winRead( 33779 33744 sqlite3_file *id, /* File to read from */ 33780 33745 void *pBuf, /* Write content into this buffer */ 33781 33746 int amt, /* Number of bytes to read */ 33782 33747 sqlite3_int64 offset /* Begin reading at this offset */ 33783 33748 ){ 33784 -#if !SQLITE_OS_WINCE 33785 - OVERLAPPED overlapped; /* The offset for ReadFile. */ 33786 -#endif 33787 33749 winFile *pFile = (winFile*)id; /* file handle */ 33788 33750 DWORD nRead; /* Number of bytes actually read from file */ 33789 33751 int nRetry = 0; /* Number of retrys */ 33790 33752 33791 33753 assert( id!=0 ); 33792 33754 SimulateIOError(return SQLITE_IOERR_READ); 33793 33755 OSTRACE(("READ %d lock=%d\n", pFile->h, pFile->locktype)); 33794 33756 33795 -#if SQLITE_OS_WINCE 33796 33757 if( seekWinFile(pFile, offset) ){ 33797 33758 return SQLITE_FULL; 33798 33759 } 33799 33760 while( !osReadFile(pFile->h, pBuf, amt, &nRead, 0) ){ 33800 -#else 33801 - memset(&overlapped, 0, sizeof(OVERLAPPED)); 33802 - overlapped.Offset = (LONG)(offset & 0xffffffff); 33803 - overlapped.OffsetHigh = (LONG)((offset>>32) & 0x7fffffff); 33804 - while( !osReadFile(pFile->h, pBuf, amt, &nRead, &overlapped) && 33805 - osGetLastError()!=ERROR_HANDLE_EOF ){ 33806 -#endif 33807 33761 DWORD lastErrno; 33808 33762 if( retryIoerr(&nRetry, &lastErrno) ) continue; 33809 33763 pFile->lastErrno = lastErrno; 33810 33764 return winLogError(SQLITE_IOERR_READ, pFile->lastErrno, 33811 33765 "winRead", pFile->zPath); 33812 33766 } 33813 33767 logIoerr(nRetry); ................................................................................ 33826 33780 */ 33827 33781 static int winWrite( 33828 33782 sqlite3_file *id, /* File to write into */ 33829 33783 const void *pBuf, /* The bytes to be written */ 33830 33784 int amt, /* Number of bytes to write */ 33831 33785 sqlite3_int64 offset /* Offset into the file to begin writing at */ 33832 33786 ){ 33833 - int rc = 0; /* True if error has occured, else false */ 33787 + int rc; /* True if error has occured, else false */ 33834 33788 winFile *pFile = (winFile*)id; /* File handle */ 33835 33789 int nRetry = 0; /* Number of retries */ 33836 33790 33837 33791 assert( amt>0 ); 33838 33792 assert( pFile ); 33839 33793 SimulateIOError(return SQLITE_IOERR_WRITE); 33840 33794 SimulateDiskfullError(return SQLITE_FULL); 33841 33795 33842 33796 OSTRACE(("WRITE %d lock=%d\n", pFile->h, pFile->locktype)); 33843 33797 33844 -#if SQLITE_OS_WINCE 33845 33798 rc = seekWinFile(pFile, offset); 33846 33799 if( rc==0 ){ 33847 -#else 33848 - { 33849 -#endif 33850 -#if !SQLITE_OS_WINCE 33851 - OVERLAPPED overlapped; /* The offset for WriteFile. */ 33852 -#endif 33853 33800 u8 *aRem = (u8 *)pBuf; /* Data yet to be written */ 33854 33801 int nRem = amt; /* Number of bytes yet to be written */ 33855 33802 DWORD nWrite; /* Bytes written by each WriteFile() call */ 33856 33803 DWORD lastErrno = NO_ERROR; /* Value returned by GetLastError() */ 33857 33804 33858 -#if !SQLITE_OS_WINCE 33859 - memset(&overlapped, 0, sizeof(OVERLAPPED)); 33860 - overlapped.Offset = (LONG)(offset & 0xffffffff); 33861 - overlapped.OffsetHigh = (LONG)((offset>>32) & 0x7fffffff); 33862 -#endif 33863 - 33864 33805 while( nRem>0 ){ 33865 -#if SQLITE_OS_WINCE 33866 33806 if( !osWriteFile(pFile->h, aRem, nRem, &nWrite, 0) ){ 33867 -#else 33868 - if( !osWriteFile(pFile->h, aRem, nRem, &nWrite, &overlapped) ){ 33869 -#endif 33870 33807 if( retryIoerr(&nRetry, &lastErrno) ) continue; 33871 33808 break; 33872 33809 } 33873 - if( nWrite<=0 ){ 33874 - lastErrno = osGetLastError(); 33875 - break; 33876 - } 33877 -#if !SQLITE_OS_WINCE 33878 - offset += nWrite; 33879 - overlapped.Offset = (LONG)(offset & 0xffffffff); 33880 - overlapped.OffsetHigh = (LONG)((offset>>32) & 0x7fffffff); 33881 -#endif 33810 + if( nWrite<=0 ) break; 33882 33811 aRem += nWrite; 33883 33812 nRem -= nWrite; 33884 33813 } 33885 33814 if( nRem>0 ){ 33886 33815 pFile->lastErrno = lastErrno; 33887 33816 rc = 1; 33888 33817 } ................................................................................ 35172 35101 zBuf[j] = 0; 35173 35102 zBuf[j+1] = 0; 35174 35103 35175 35104 OSTRACE(("TEMP FILENAME: %s\n", zBuf)); 35176 35105 return SQLITE_OK; 35177 35106 } 35178 35107 35179 -/* 35180 -** Return TRUE if the named file is really a directory. Return false if 35181 -** it is something other than a directory, or if there is any kind of memory 35182 -** allocation failure. 35183 -*/ 35184 -static int winIsDir(const void *zConverted){ 35185 - DWORD attr; 35186 - int rc = 0; 35187 - DWORD lastErrno; 35188 - 35189 - if( isNT() ){ 35190 - int cnt = 0; 35191 - WIN32_FILE_ATTRIBUTE_DATA sAttrData; 35192 - memset(&sAttrData, 0, sizeof(sAttrData)); 35193 - while( !(rc = osGetFileAttributesExW((LPCWSTR)zConverted, 35194 - GetFileExInfoStandard, 35195 - &sAttrData)) && retryIoerr(&cnt, &lastErrno) ){} 35196 - if( !rc ){ 35197 - return 0; /* Invalid name? */ 35198 - } 35199 - attr = sAttrData.dwFileAttributes; 35200 -#if SQLITE_OS_WINCE==0 35201 - }else{ 35202 - attr = osGetFileAttributesA((char*)zConverted); 35203 -#endif 35204 - } 35205 - return (attr!=INVALID_FILE_ATTRIBUTES) && (attr&FILE_ATTRIBUTE_DIRECTORY); 35206 -} 35207 - 35208 35108 /* 35209 35109 ** Open a file. 35210 35110 */ 35211 35111 static int winOpen( 35212 35112 sqlite3_vfs *pVfs, /* Not used */ 35213 35113 const char *zName, /* Name of the file (UTF-8) */ 35214 35114 sqlite3_file *id, /* Write the SQLite file handle here */ ................................................................................ 35307 35207 35308 35208 /* Convert the filename to the system encoding. */ 35309 35209 zConverted = convertUtf8Filename(zUtf8Name); 35310 35210 if( zConverted==0 ){ 35311 35211 return SQLITE_IOERR_NOMEM; 35312 35212 } 35313 35213 35314 - if( winIsDir(zConverted) ){ 35315 - sqlite3_free(zConverted); 35316 - return SQLITE_CANTOPEN_ISDIR; 35317 - } 35318 - 35319 35214 if( isReadWrite ){ 35320 35215 dwDesiredAccess = GENERIC_READ | GENERIC_WRITE; 35321 35216 }else{ 35322 35217 dwDesiredAccess = GENERIC_READ; 35323 35218 } 35324 35219 35325 35220 /* SQLITE_OPEN_EXCLUSIVE is used to make sure that a new file is ................................................................................ 35361 35256 if( isNT() ){ 35362 35257 while( (h = osCreateFileW((LPCWSTR)zConverted, 35363 35258 dwDesiredAccess, 35364 35259 dwShareMode, NULL, 35365 35260 dwCreationDisposition, 35366 35261 dwFlagsAndAttributes, 35367 35262 NULL))==INVALID_HANDLE_VALUE && 35368 - retryIoerr(&cnt, &lastErrno) ){ 35369 - /* Noop */ 35370 - } 35263 + retryIoerr(&cnt, &lastErrno) ){} 35264 +/* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed. 35265 +** Since the ANSI version of these Windows API do not exist for WINCE, 35266 +** it's important to not reference them for WINCE builds. 35267 +*/ 35371 35268 #if SQLITE_OS_WINCE==0 35372 35269 }else{ 35373 35270 while( (h = osCreateFileA((LPCSTR)zConverted, 35374 35271 dwDesiredAccess, 35375 35272 dwShareMode, NULL, 35376 35273 dwCreationDisposition, 35377 35274 dwFlagsAndAttributes, 35378 35275 NULL))==INVALID_HANDLE_VALUE && 35379 - retryIoerr(&cnt, &lastErrno) ){ 35380 - /* Noop */ 35381 - } 35276 + retryIoerr(&cnt, &lastErrno) ){} 35382 35277 #endif 35383 35278 } 35384 35279 35385 35280 logIoerr(cnt); 35386 35281 35387 35282 OSTRACE(("OPEN %d %s 0x%lx %s\n", 35388 35283 h, zName, dwDesiredAccess, ................................................................................ 35454 35349 static int winDelete( 35455 35350 sqlite3_vfs *pVfs, /* Not used on win32 */ 35456 35351 const char *zFilename, /* Name of file to delete */ 35457 35352 int syncDir /* Not used on win32 */ 35458 35353 ){ 35459 35354 int cnt = 0; 35460 35355 int rc; 35461 - DWORD attr; 35462 35356 DWORD lastErrno; 35463 35357 void *zConverted; 35464 35358 UNUSED_PARAMETER(pVfs); 35465 35359 UNUSED_PARAMETER(syncDir); 35466 35360 35467 35361 SimulateIOError(return SQLITE_IOERR_DELETE); 35468 35362 zConverted = convertUtf8Filename(zFilename); 35469 35363 if( zConverted==0 ){ 35470 35364 return SQLITE_IOERR_NOMEM; 35471 35365 } 35472 35366 if( isNT() ){ 35473 - do { 35474 - attr = osGetFileAttributesW(zConverted); 35475 - if ( attr==INVALID_FILE_ATTRIBUTES ){ 35476 - rc = SQLITE_OK; /* Already gone? */ 35477 - break; 35478 - } 35479 - if ( attr&FILE_ATTRIBUTE_DIRECTORY ){ 35480 - rc = SQLITE_ERROR; /* Files only. */ 35481 - break; 35482 - } 35483 - if ( osDeleteFileW(zConverted) ){ 35484 - rc = SQLITE_OK; /* Deleted OK. */ 35485 - break; 35486 - } 35487 - if ( !retryIoerr(&cnt, &lastErrno) ){ 35488 - rc = SQLITE_ERROR; /* No more retries. */ 35489 - break; 35490 - } 35491 - } while(1); 35367 + rc = 1; 35368 + while( osGetFileAttributesW(zConverted)!=INVALID_FILE_ATTRIBUTES && 35369 + (rc = osDeleteFileW(zConverted))==0 && retryIoerr(&cnt, &lastErrno) ){} 35370 + rc = rc ? SQLITE_OK : SQLITE_ERROR; 35492 35371 /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed. 35493 35372 ** Since the ANSI version of these Windows API do not exist for WINCE, 35494 35373 ** it's important to not reference them for WINCE builds. 35495 35374 */ 35496 35375 #if SQLITE_OS_WINCE==0 35497 35376 }else{ 35498 - do { 35499 - attr = osGetFileAttributesA(zConverted); 35500 - if ( attr==INVALID_FILE_ATTRIBUTES ){ 35501 - rc = SQLITE_OK; /* Already gone? */ 35502 - break; 35503 - } 35504 - if ( attr&FILE_ATTRIBUTE_DIRECTORY ){ 35505 - rc = SQLITE_ERROR; /* Files only. */ 35506 - break; 35507 - } 35508 - if ( osDeleteFileA(zConverted) ){ 35509 - rc = SQLITE_OK; /* Deleted OK. */ 35510 - break; 35511 - } 35512 - if ( !retryIoerr(&cnt, &lastErrno) ){ 35513 - rc = SQLITE_ERROR; /* No more retries. */ 35514 - break; 35515 - } 35516 - } while(1); 35377 + rc = 1; 35378 + while( osGetFileAttributesA(zConverted)!=INVALID_FILE_ATTRIBUTES && 35379 + (rc = osDeleteFileA(zConverted))==0 && retryIoerr(&cnt, &lastErrno) ){} 35380 + rc = rc ? SQLITE_OK : SQLITE_ERROR; 35517 35381 #endif 35518 35382 } 35519 35383 if( rc ){ 35520 35384 rc = winLogError(SQLITE_IOERR_DELETE, lastErrno, 35521 35385 "winDelete", zFilename); 35522 35386 }else{ 35523 35387 logIoerr(cnt); ................................................................................ 38071 37935 ** The number of rowset entries per allocation chunk. 38072 37936 */ 38073 37937 #define ROWSET_ENTRY_PER_CHUNK \ 38074 37938 ((ROWSET_ALLOCATION_SIZE-8)/sizeof(struct RowSetEntry)) 38075 37939 38076 37940 /* 38077 37941 ** Each entry in a RowSet is an instance of the following object. 38078 -** 38079 -** This same object is reused to store a linked list of trees of RowSetEntry 38080 -** objects. In that alternative use, pRight points to the next entry 38081 -** in the list, pLeft points to the tree, and v is unused. The 38082 -** RowSet.pForest value points to the head of this forest list. 38083 37942 */ 38084 37943 struct RowSetEntry { 38085 37944 i64 v; /* ROWID value for this entry */ 38086 37945 struct RowSetEntry *pRight; /* Right subtree (larger entries) or list */ 38087 37946 struct RowSetEntry *pLeft; /* Left subtree (smaller entries) */ 38088 37947 }; 38089 37948 ................................................................................ 38105 37964 */ 38106 37965 struct RowSet { 38107 37966 struct RowSetChunk *pChunk; /* List of all chunk allocations */ 38108 37967 sqlite3 *db; /* The database connection */ 38109 37968 struct RowSetEntry *pEntry; /* List of entries using pRight */ 38110 37969 struct RowSetEntry *pLast; /* Last entry on the pEntry list */ 38111 37970 struct RowSetEntry *pFresh; /* Source of new entry objects */ 38112 - struct RowSetEntry *pForest; /* List of binary trees of entries */ 37971 + struct RowSetEntry *pTree; /* Binary tree of entries */ 38113 37972 u16 nFresh; /* Number of objects on pFresh */ 38114 - u8 rsFlags; /* Various flags */ 37973 + u8 isSorted; /* True if pEntry is sorted */ 38115 37974 u8 iBatch; /* Current insert batch */ 38116 37975 }; 38117 37976 38118 -/* 38119 -** Allowed values for RowSet.rsFlags 38120 -*/ 38121 -#define ROWSET_SORTED 0x01 /* True if RowSet.pEntry is sorted */ 38122 -#define ROWSET_NEXT 0x02 /* True if sqlite3RowSetNext() has been called */ 38123 - 38124 37977 /* 38125 37978 ** Turn bulk memory into a RowSet object. N bytes of memory 38126 37979 ** are available at pSpace. The db pointer is used as a memory context 38127 37980 ** for any subsequent allocations that need to occur. 38128 37981 ** Return a pointer to the new RowSet object. 38129 37982 ** 38130 37983 ** It must be the case that N is sufficient to make a Rowset. If not ................................................................................ 38137 37990 RowSet *p; 38138 37991 assert( N >= ROUND8(sizeof(*p)) ); 38139 37992 p = pSpace; 38140 37993 p->pChunk = 0; 38141 37994 p->db = db; 38142 37995 p->pEntry = 0; 38143 37996 p->pLast = 0; 38144 - p->pForest = 0; 37997 + p->pTree = 0; 38145 37998 p->pFresh = (struct RowSetEntry*)(ROUND8(sizeof(*p)) + (char*)p); 38146 37999 p->nFresh = (u16)((N - ROUND8(sizeof(*p)))/sizeof(struct RowSetEntry)); 38147 - p->rsFlags = ROWSET_SORTED; 38000 + p->isSorted = 1; 38148 38001 p->iBatch = 0; 38149 38002 return p; 38150 38003 } 38151 38004 38152 38005 /* 38153 38006 ** Deallocate all chunks from a RowSet. This frees all memory that 38154 38007 ** the RowSet has allocated over its lifetime. This routine is ................................................................................ 38160 38013 pNextChunk = pChunk->pNextChunk; 38161 38014 sqlite3DbFree(p->db, pChunk); 38162 38015 } 38163 38016 p->pChunk = 0; 38164 38017 p->nFresh = 0; 38165 38018 p->pEntry = 0; 38166 38019 p->pLast = 0; 38167 - p->pForest = 0; 38168 - p->rsFlags = ROWSET_SORTED; 38169 -} 38170 - 38171 -/* 38172 -** Allocate a new RowSetEntry object that is associated with the 38173 -** given RowSet. Return a pointer to the new and completely uninitialized 38174 -** objected. 38175 -** 38176 -** In an OOM situation, the RowSet.db->mallocFailed flag is set and this 38177 -** routine returns NULL. 38178 -*/ 38179 -static struct RowSetEntry *rowSetEntryAlloc(RowSet *p){ 38180 - assert( p!=0 ); 38181 - if( p->nFresh==0 ){ 38182 - struct RowSetChunk *pNew; 38183 - pNew = sqlite3DbMallocRaw(p->db, sizeof(*pNew)); 38184 - if( pNew==0 ){ 38185 - return 0; 38186 - } 38187 - pNew->pNextChunk = p->pChunk; 38188 - p->pChunk = pNew; 38189 - p->pFresh = pNew->aEntry; 38190 - p->nFresh = ROWSET_ENTRY_PER_CHUNK; 38191 - } 38192 - p->nFresh--; 38193 - return p->pFresh++; 38020 + p->pTree = 0; 38021 + p->isSorted = 1; 38194 38022 } 38195 38023 38196 38024 /* 38197 38025 ** Insert a new value into a RowSet. 38198 38026 ** 38199 38027 ** The mallocFailed flag of the database connection is set if a 38200 38028 ** memory allocation fails. 38201 38029 */ 38202 38030 SQLITE_PRIVATE void sqlite3RowSetInsert(RowSet *p, i64 rowid){ 38203 38031 struct RowSetEntry *pEntry; /* The new entry */ 38204 38032 struct RowSetEntry *pLast; /* The last prior entry */ 38205 - 38206 - /* This routine is never called after sqlite3RowSetNext() */ 38207 - assert( p!=0 && (p->rsFlags & ROWSET_NEXT)==0 ); 38208 - 38209 - pEntry = rowSetEntryAlloc(p); 38210 - if( pEntry==0 ) return; 38033 + assert( p!=0 ); 38034 + if( p->nFresh==0 ){ 38035 + struct RowSetChunk *pNew; 38036 + pNew = sqlite3DbMallocRaw(p->db, sizeof(*pNew)); 38037 + if( pNew==0 ){ 38038 + return; 38039 + } 38040 + pNew->pNextChunk = p->pChunk; 38041 + p->pChunk = pNew; 38042 + p->pFresh = pNew->aEntry; 38043 + p->nFresh = ROWSET_ENTRY_PER_CHUNK; 38044 + } 38045 + pEntry = p->pFresh++; 38046 + p->nFresh--; 38211 38047 pEntry->v = rowid; 38212 38048 pEntry->pRight = 0; 38213 38049 pLast = p->pLast; 38214 38050 if( pLast ){ 38215 - if( (p->rsFlags & ROWSET_SORTED)!=0 && rowid<=pLast->v ){ 38216 - p->rsFlags &= ~ROWSET_SORTED; 38051 + if( p->isSorted && rowid<=pLast->v ){ 38052 + p->isSorted = 0; 38217 38053 } 38218 38054 pLast->pRight = pEntry; 38219 38055 }else{ 38056 + assert( p->pEntry==0 ); /* Fires if INSERT after SMALLEST */ 38220 38057 p->pEntry = pEntry; 38221 38058 } 38222 38059 p->pLast = pEntry; 38223 38060 } 38224 38061 38225 38062 /* 38226 38063 ** Merge two lists of RowSetEntry objects. Remove duplicates. 38227 38064 ** 38228 38065 ** The input lists are connected via pRight pointers and are 38229 38066 ** assumed to each already be in sorted order. 38230 38067 */ 38231 -static struct RowSetEntry *rowSetEntryMerge( 38068 +static struct RowSetEntry *rowSetMerge( 38232 38069 struct RowSetEntry *pA, /* First sorted list to be merged */ 38233 38070 struct RowSetEntry *pB /* Second sorted list to be merged */ 38234 38071 ){ 38235 38072 struct RowSetEntry head; 38236 38073 struct RowSetEntry *pTail; 38237 38074 38238 38075 pTail = &head; ................................................................................ 38258 38095 assert( pB==0 || pB->pRight==0 || pB->v<=pB->pRight->v ); 38259 38096 pTail->pRight = pB; 38260 38097 } 38261 38098 return head.pRight; 38262 38099 } 38263 38100 38264 38101 /* 38265 -** Sort all elements on the list of RowSetEntry objects into order of 38266 -** increasing v. 38102 +** Sort all elements on the pEntry list of the RowSet into ascending order. 38267 38103 */ 38268 -static struct RowSetEntry *rowSetEntrySort(struct RowSetEntry *pIn){ 38104 +static void rowSetSort(RowSet *p){ 38269 38105 unsigned int i; 38270 - struct RowSetEntry *pNext, *aBucket[40]; 38106 + struct RowSetEntry *pEntry; 38107 + struct RowSetEntry *aBucket[40]; 38271 38108 38109 + assert( p->isSorted==0 ); 38272 38110 memset(aBucket, 0, sizeof(aBucket)); 38273 - while( pIn ){ 38274 - pNext = pIn->pRight; 38275 - pIn->pRight = 0; 38111 + while( p->pEntry ){ 38112 + pEntry = p->pEntry; 38113 + p->pEntry = pEntry->pRight; 38114 + pEntry->pRight = 0; 38276 38115 for(i=0; aBucket[i]; i++){ 38277 - pIn = rowSetEntryMerge(aBucket[i], pIn); 38116 + pEntry = rowSetMerge(aBucket[i], pEntry); 38278 38117 aBucket[i] = 0; 38279 38118 } 38280 - aBucket[i] = pIn; 38281 - pIn = pNext; 38119 + aBucket[i] = pEntry; 38282 38120 } 38283 - pIn = 0; 38121 + pEntry = 0; 38284 38122 for(i=0; i<sizeof(aBucket)/sizeof(aBucket[0]); i++){ 38285 - pIn = rowSetEntryMerge(pIn, aBucket[i]); 38123 + pEntry = rowSetMerge(pEntry, aBucket[i]); 38286 38124 } 38287 - return pIn; 38125 + p->pEntry = pEntry; 38126 + p->pLast = 0; 38127 + p->isSorted = 1; 38288 38128 } 38289 38129 38290 38130 38291 38131 /* 38292 38132 ** The input, pIn, is a binary tree (or subtree) of RowSetEntry objects. 38293 38133 ** Convert this tree into a linked list connected by the pRight pointers 38294 38134 ** and return pointers to the first and last elements of the new list. ................................................................................ 38374 38214 p->pLeft = pLeft; 38375 38215 p->pRight = rowSetNDeepTree(&pList, iDepth); 38376 38216 } 38377 38217 return p; 38378 38218 } 38379 38219 38380 38220 /* 38381 -** Take all the entries on p->pEntry and on the trees in p->pForest and 38382 -** sort them all together into one big ordered list on p->pEntry. 38383 -** 38384 -** This routine should only be called once in the life of a RowSet. 38221 +** Convert the list in p->pEntry into a sorted list if it is not 38222 +** sorted already. If there is a binary tree on p->pTree, then 38223 +** convert it into a list too and merge it into the p->pEntry list. 38385 38224 */ 38386 38225 static void rowSetToList(RowSet *p){ 38387 - 38388 - /* This routine is called only once */ 38389 - assert( p!=0 && (p->rsFlags & ROWSET_NEXT)==0 ); 38390 - 38391 - if( (p->rsFlags & ROWSET_SORTED)==0 ){ 38392 - p->pEntry = rowSetEntrySort(p->pEntry); 38226 + if( !p->isSorted ){ 38227 + rowSetSort(p); 38393 38228 } 38394 - 38395 - /* While this module could theoretically support it, sqlite3RowSetNext() 38396 - ** is never called after sqlite3RowSetText() for the same RowSet. So 38397 - ** there is never a forest to deal with. Should this change, simply 38398 - ** remove the assert() and the #if 0. */ 38399 - assert( p->pForest==0 ); 38400 -#if 0 38401 - while( p->pForest ){ 38402 - struct RowSetEntry *pTree = p->pForest->pLeft; 38403 - if( pTree ){ 38404 - struct RowSetEntry *pHead, *pTail; 38405 - rowSetTreeToList(pTree, &pHead, &pTail); 38406 - p->pEntry = rowSetEntryMerge(p->pEntry, pHead); 38407 - } 38408 - p->pForest = p->pForest->pRight; 38229 + if( p->pTree ){ 38230 + struct RowSetEntry *pHead, *pTail; 38231 + rowSetTreeToList(p->pTree, &pHead, &pTail); 38232 + p->pTree = 0; 38233 + p->pEntry = rowSetMerge(p->pEntry, pHead); 38409 38234 } 38410 -#endif 38411 - p->rsFlags |= ROWSET_NEXT; /* Verify this routine is never called again */ 38412 38235 } 38413 38236 38414 38237 /* 38415 38238 ** Extract the smallest element from the RowSet. 38416 38239 ** Write the element into *pRowid. Return 1 on success. Return 38417 38240 ** 0 if the RowSet is already empty. 38418 38241 ** 38419 38242 ** After this routine has been called, the sqlite3RowSetInsert() 38420 38243 ** routine may not be called again. 38421 38244 */ 38422 38245 SQLITE_PRIVATE int sqlite3RowSetNext(RowSet *p, i64 *pRowid){ 38423 - assert( p!=0 ); 38424 - 38425 - /* Merge the forest into a single sorted list on first call */ 38426 - if( (p->rsFlags & ROWSET_NEXT)==0 ) rowSetToList(p); 38427 - 38428 - /* Return the next entry on the list */ 38246 + rowSetToList(p); 38429 38247 if( p->pEntry ){ 38430 38248 *pRowid = p->pEntry->v; 38431 38249 p->pEntry = p->pEntry->pRight; 38432 38250 if( p->pEntry==0 ){ 38433 38251 sqlite3RowSetClear(p); 38434 38252 } 38435 38253 return 1; ................................................................................ 38437 38255 return 0; 38438 38256 } 38439 38257 } 38440 38258 38441 38259 /* 38442 38260 ** Check to see if element iRowid was inserted into the the rowset as 38443 38261 ** part of any insert batch prior to iBatch. Return 1 or 0. 38444 -** 38445 -** If this is the first test of a new batch and if there exist entires 38446 -** on pRowSet->pEntry, then sort those entires into the forest at 38447 -** pRowSet->pForest so that they can be tested. 38448 38262 */ 38449 38263 SQLITE_PRIVATE int sqlite3RowSetTest(RowSet *pRowSet, u8 iBatch, sqlite3_int64 iRowid){ 38450 - struct RowSetEntry *p, *pTree; 38451 - 38452 - /* This routine is never called after sqlite3RowSetNext() */ 38453 - assert( pRowSet!=0 && (pRowSet->rsFlags & ROWSET_NEXT)==0 ); 38454 - 38455 - /* Sort entries into the forest on the first test of a new batch 38456 - */ 38264 + struct RowSetEntry *p; 38457 38265 if( iBatch!=pRowSet->iBatch ){ 38458 - p = pRowSet->pEntry; 38459 - if( p ){ 38460 - struct RowSetEntry **ppPrevTree = &pRowSet->pForest; 38461 - if( (pRowSet->rsFlags & ROWSET_SORTED)==0 ){ 38462 - p = rowSetEntrySort(p); 38463 - } 38464 - for(pTree = pRowSet->pForest; pTree; pTree=pTree->pRight){ 38465 - ppPrevTree = &pTree->pRight; 38466 - if( pTree->pLeft==0 ){ 38467 - pTree->pLeft = rowSetListToTree(p); 38468 - break; 38469 - }else{ 38470 - struct RowSetEntry *pAux, *pTail; 38471 - rowSetTreeToList(pTree->pLeft, &pAux, &pTail); 38472 - pTree->pLeft = 0; 38473 - p = rowSetEntryMerge(pAux, p); 38474 - } 38475 - } 38476 - if( pTree==0 ){ 38477 - *ppPrevTree = pTree = rowSetEntryAlloc(pRowSet); 38478 - if( pTree ){ 38479 - pTree->v = 0; 38480 - pTree->pRight = 0; 38481 - pTree->pLeft = rowSetListToTree(p); 38482 - } 38483 - } 38266 + if( pRowSet->pEntry ){ 38267 + rowSetToList(pRowSet); 38268 + pRowSet->pTree = rowSetListToTree(pRowSet->pEntry); 38484 38269 pRowSet->pEntry = 0; 38485 38270 pRowSet->pLast = 0; 38486 - pRowSet->rsFlags |= ROWSET_SORTED; 38487 38271 } 38488 38272 pRowSet->iBatch = iBatch; 38489 38273 } 38490 - 38491 - /* Test to see if the iRowid value appears anywhere in the forest. 38492 - ** Return 1 if it does and 0 if not. 38493 - */ 38494 - for(pTree = pRowSet->pForest; pTree; pTree=pTree->pRight){ 38495 - p = pTree->pLeft; 38496 - while( p ){ 38497 - if( p->v<iRowid ){ 38498 - p = p->pRight; 38499 - }else if( p->v>iRowid ){ 38500 - p = p->pLeft; 38501 - }else{ 38502 - return 1; 38503 - } 38274 + p = pRowSet->pTree; 38275 + while( p ){ 38276 + if( p->v<iRowid ){ 38277 + p = p->pRight; 38278 + }else if( p->v>iRowid ){ 38279 + p = p->pLeft; 38280 + }else{ 38281 + return 1; 38504 38282 } 38505 38283 } 38506 38284 return 0; 38507 38285 } 38508 38286 38509 38287 /************** End of rowset.c **********************************************/ 38510 38288 /************** Begin file pager.c *******************************************/ ................................................................................ 39314 39092 int pageSize; /* Number of bytes in a page */ 39315 39093 Pgno mxPgno; /* Maximum allowed size of the database */ 39316 39094 i64 journalSizeLimit; /* Size limit for persistent journal files */ 39317 39095 char *zFilename; /* Name of the database file */ 39318 39096 char *zJournal; /* Name of the journal file */ 39319 39097 int (*xBusyHandler)(void*); /* Function to call when busy */ 39320 39098 void *pBusyHandlerArg; /* Context argument for xBusyHandler */ 39321 - int aStat[3]; /* Total cache hits, misses and writes */ 39099 + int nHit, nMiss; /* Total cache hits and misses */ 39322 39100 #ifdef SQLITE_TEST 39323 - int nRead; /* Database pages read */ 39101 + int nRead, nWrite; /* Database pages read/written */ 39324 39102 #endif 39325 39103 void (*xReiniter)(DbPage*); /* Call this routine when reloading pages */ 39326 39104 #ifdef SQLITE_HAS_CODEC 39327 39105 void *(*xCodec)(void*,void*,Pgno,int); /* Routine for en/decoding data */ 39328 39106 void (*xCodecSizeChng)(void*,int,int); /* Notify of page size changes */ 39329 39107 void (*xCodecFree)(void*); /* Destructor for the codec */ 39330 39108 void *pCodec; /* First argument to xCodec... methods */ ................................................................................ 39333 39111 PCache *pPCache; /* Pointer to page cache object */ 39334 39112 #ifndef SQLITE_OMIT_WAL 39335 39113 Wal *pWal; /* Write-ahead log used by "journal_mode=wal" */ 39336 39114 char *zWal; /* File name for write-ahead log */ 39337 39115 #endif 39338 39116 }; 39339 39117 39340 -/* 39341 -** Indexes for use with Pager.aStat[]. The Pager.aStat[] array contains 39342 -** the values accessed by passing SQLITE_DBSTATUS_CACHE_HIT, CACHE_MISS 39343 -** or CACHE_WRITE to sqlite3_db_status(). 39344 -*/ 39345 -#define PAGER_STAT_HIT 0 39346 -#define PAGER_STAT_MISS 1 39347 -#define PAGER_STAT_WRITE 2 39348 - 39349 39118 /* 39350 39119 ** The following global variables hold counters used for 39351 39120 ** testing purposes only. These variables do not exist in 39352 39121 ** a non-testing build. These variables are not thread-safe. 39353 39122 */ 39354 39123 #ifdef SQLITE_TEST 39355 39124 SQLITE_API int sqlite3_pager_readdb_count = 0; /* Number of full pages read from DB */ ................................................................................ 41624 41393 static int pagerWalFrames( 41625 41394 Pager *pPager, /* Pager object */ 41626 41395 PgHdr *pList, /* List of frames to log */ 41627 41396 Pgno nTruncate, /* Database size after this commit */ 41628 41397 int isCommit /* True if this is a commit */ 41629 41398 ){ 41630 41399 int rc; /* Return code */ 41631 - int nList; /* Number of pages in pList */ 41632 41400 #if defined(SQLITE_DEBUG) || defined(SQLITE_CHECK_PAGES) 41633 41401 PgHdr *p; /* For looping over pages */ 41634 41402 #endif 41635 41403 41636 41404 assert( pPager->pWal ); 41637 41405 assert( pList ); 41638 41406 #ifdef SQLITE_DEBUG 41639 41407 /* Verify that the page list is in accending order */ 41640 41408 for(p=pList; p && p->pDirty; p=p->pDirty){ 41641 41409 assert( p->pgno < p->pDirty->pgno ); 41642 41410 } 41643 41411 #endif 41644 41412 41645 - assert( pList->pDirty==0 || isCommit ); 41646 41413 if( isCommit ){ 41647 41414 /* If a WAL transaction is being committed, there is no point in writing 41648 41415 ** any pages with page numbers greater than nTruncate into the WAL file. 41649 41416 ** They will never be read by any client. So remove them from the pDirty 41650 41417 ** list here. */ 41651 41418 PgHdr *p; 41652 41419 PgHdr **ppNext = &pList; 41653 - nList = 0; 41654 - for(p=pList; (*ppNext = p)!=0; p=p->pDirty){ 41655 - if( p->pgno<=nTruncate ){ 41656 - ppNext = &p->pDirty; 41657 - nList++; 41658 - } 41420 + for(p=pList; (*ppNext = p); p=p->pDirty){ 41421 + if( p->pgno<=nTruncate ) ppNext = &p->pDirty; 41659 41422 } 41660 41423 assert( pList ); 41661 - }else{ 41662 - nList = 1; 41663 41424 } 41664 - pPager->aStat[PAGER_STAT_WRITE] += nList; 41665 41425 41666 41426 if( pList->pgno==1 ) pager_write_changecounter(pList); 41667 41427 rc = sqlite3WalFrames(pPager->pWal, 41668 41428 pPager->pageSize, pList, nTruncate, isCommit, pPager->walSyncFlags 41669 41429 ); 41670 41430 if( rc==SQLITE_OK && pPager->pBackup ){ 41671 41431 PgHdr *p; ................................................................................ 42725 42485 */ 42726 42486 if( pgno==1 ){ 42727 42487 memcpy(&pPager->dbFileVers, &pData[24], sizeof(pPager->dbFileVers)); 42728 42488 } 42729 42489 if( pgno>pPager->dbFileSize ){ 42730 42490 pPager->dbFileSize = pgno; 42731 42491 } 42732 - pPager->aStat[PAGER_STAT_WRITE]++; 42733 42492 42734 42493 /* Update any backup objects copying the contents of this pager. */ 42735 42494 sqlite3BackupUpdate(pPager->pBackup, pgno, (u8*)pList->pData); 42736 42495 42737 42496 PAGERTRACE(("STORE %d page %d hash(%08x)\n", 42738 42497 PAGERID(pPager), pgno, pager_pagehash(pList))); 42739 42498 IOTRACE(("PGOUT %p %d\n", pPager, pgno)); 42740 42499 PAGER_INCR(sqlite3_pager_writedb_count); 42500 + PAGER_INCR(pPager->nWrite); 42741 42501 }else{ 42742 42502 PAGERTRACE(("NOSTORE %d page %d\n", PAGERID(pPager), pgno)); 42743 42503 } 42744 42504 pager_set_pagehash(pList); 42745 42505 pList = pList->pDirty; 42746 42506 } 42747 42507 ................................................................................ 43691 43451 assert( (*ppPage)->pgno==pgno ); 43692 43452 assert( (*ppPage)->pPager==pPager || (*ppPage)->pPager==0 ); 43693 43453 43694 43454 if( (*ppPage)->pPager && !noContent ){ 43695 43455 /* In this case the pcache already contains an initialized copy of 43696 43456 ** the page. Return without further ado. */ 43697 43457 assert( pgno<=PAGER_MAX_PGNO && pgno!=PAGER_MJ_PGNO(pPager) ); 43698 - pPager->aStat[PAGER_STAT_HIT]++; 43458 + pPager->nHit++; 43699 43459 return SQLITE_OK; 43700 43460 43701 43461 }else{ 43702 43462 /* The pager cache has created a new page. Its content needs to 43703 43463 ** be initialized. */ 43704 43464 43705 43465 pPg = *ppPage; ................................................................................ 43733 43493 testcase( rc==SQLITE_NOMEM ); 43734 43494 sqlite3EndBenignMalloc(); 43735 43495 } 43736 43496 memset(pPg->pData, 0, pPager->pageSize); 43737 43497 IOTRACE(("ZERO %p %d\n", pPager, pgno)); 43738 43498 }else{ 43739 43499 assert( pPg->pPager==pPager ); 43740 - pPager->aStat[PAGER_STAT_MISS]++; 43500 + pPager->nMiss++; 43741 43501 rc = readDbPage(pPg); 43742 43502 if( rc!=SQLITE_OK ){ 43743 43503 goto pager_acquire_err; 43744 43504 } 43745 43505 } 43746 43506 pager_set_pagehash(pPg); 43747 43507 } ................................................................................ 44318 44078 /* If running in direct mode, write the contents of page 1 to the file. */ 44319 44079 if( DIRECT_MODE ){ 44320 44080 const void *zBuf; 44321 44081 assert( pPager->dbFileSize>0 ); 44322 44082 CODEC2(pPager, pPgHdr->pData, 1, 6, rc=SQLITE_NOMEM, zBuf); 44323 44083 if( rc==SQLITE_OK ){ 44324 44084 rc = sqlite3OsWrite(pPager->fd, zBuf, pPager->pageSize, 0); 44325 - pPager->aStat[PAGER_STAT_WRITE]++; 44326 44085 } 44327 44086 if( rc==SQLITE_OK ){ 44328 44087 pPager->changeCountDone = 1; 44329 44088 } 44330 44089 }else{ 44331 44090 pPager->changeCountDone = 1; 44332 44091 } ................................................................................ 44762 44521 static int a[11]; 44763 44522 a[0] = sqlite3PcacheRefCount(pPager->pPCache); 44764 44523 a[1] = sqlite3PcachePagecount(pPager->pPCache); 44765 44524 a[2] = sqlite3PcacheGetCachesize(pPager->pPCache); 44766 44525 a[3] = pPager->eState==PAGER_OPEN ? -1 : (int) pPager->dbSize; 44767 44526 a[4] = pPager->eState; 44768 44527 a[5] = pPager->errCode; 44769 - a[6] = pPager->aStat[PAGER_STAT_HIT]; 44770 - a[7] = pPager->aStat[PAGER_STAT_MISS]; 44528 + a[6] = pPager->nHit; 44529 + a[7] = pPager->nMiss; 44771 44530 a[8] = 0; /* Used to be pPager->nOvfl */ 44772 44531 a[9] = pPager->nRead; 44773 - a[10] = pPager->aStat[PAGER_STAT_WRITE]; 44532 + a[10] = pPager->nWrite; 44774 44533 return a; 44775 44534 } 44776 44535 #endif 44777 44536 44778 44537 /* 44779 44538 ** Parameter eStat must be either SQLITE_DBSTATUS_CACHE_HIT or 44780 44539 ** SQLITE_DBSTATUS_CACHE_MISS. Before returning, *pnVal is incremented by the 44781 44540 ** current cache hit or miss count, according to the value of eStat. If the 44782 44541 ** reset parameter is non-zero, the cache hit or miss count is zeroed before 44783 44542 ** returning. 44784 44543 */ 44785 44544 SQLITE_PRIVATE void sqlite3PagerCacheStat(Pager *pPager, int eStat, int reset, int *pnVal){ 44545 + int *piStat; 44786 44546 44787 44547 assert( eStat==SQLITE_DBSTATUS_CACHE_HIT 44788 44548 || eStat==SQLITE_DBSTATUS_CACHE_MISS 44789 - || eStat==SQLITE_DBSTATUS_CACHE_WRITE 44790 44549 ); 44550 + if( eStat==SQLITE_DBSTATUS_CACHE_HIT ){ 44551 + piStat = &pPager->nHit; 44552 + }else{ 44553 + piStat = &pPager->nMiss; 44554 + } 44791 44555 44792 - assert( SQLITE_DBSTATUS_CACHE_HIT+1==SQLITE_DBSTATUS_CACHE_MISS ); 44793 - assert( SQLITE_DBSTATUS_CACHE_HIT+2==SQLITE_DBSTATUS_CACHE_WRITE ); 44794 - assert( PAGER_STAT_HIT==0 && PAGER_STAT_MISS==1 && PAGER_STAT_WRITE==2 ); 44795 - 44796 - *pnVal += pPager->aStat[eStat - SQLITE_DBSTATUS_CACHE_HIT]; 44556 + *pnVal += *piStat; 44797 44557 if( reset ){ 44798 - pPager->aStat[eStat - SQLITE_DBSTATUS_CACHE_HIT] = 0; 44558 + *piStat = 0; 44799 44559 } 44800 44560 } 44801 44561 44802 44562 /* 44803 44563 ** Return true if this is an in-memory pager. 44804 44564 */ 44805 44565 SQLITE_PRIVATE int sqlite3PagerIsMemdb(Pager *pPager){ ................................................................................ 49304 49064 #define ISAUTOVACUUM 0 49305 49065 #endif 49306 49066 49307 49067 49308 49068 /* 49309 49069 ** This structure is passed around through all the sanity checking routines 49310 49070 ** in order to keep track of some global state information. 49311 -** 49312 -** The aRef[] array is allocated so that there is 1 bit for each page in 49313 -** the database. As the integrity-check proceeds, for each page used in 49314 -** the database the corresponding bit is set. This allows integrity-check to 49315 -** detect pages that are used twice and orphaned pages (both of which 49316 -** indicate corruption). 49317 49071 */ 49318 49072 typedef struct IntegrityCk IntegrityCk; 49319 49073 struct IntegrityCk { 49320 49074 BtShared *pBt; /* The tree being checked out */ 49321 49075 Pager *pPager; /* The associated pager. Also accessible by pBt->pPager */ 49322 - u8 *aPgRef; /* 1 bit per page in the db (see above) */ 49076 + int *anRef; /* Number of times each page is referenced */ 49323 49077 Pgno nPage; /* Number of pages in the database */ 49324 49078 int mxErr; /* Stop accumulating errors when this reaches zero */ 49325 49079 int nErr; /* Number of messages written to zErrMsg so far */ 49326 49080 int mallocFailed; /* A memory allocation error has occurred */ 49327 49081 StrAccum errMsg; /* Accumulate the error message text here */ 49328 49082 }; 49329 49083 ................................................................................ 56394 56148 56395 56149 /* Assert that the caller has been consistent. If this cursor was opened 56396 56150 ** expecting an index b-tree, then the caller should be inserting blob 56397 56151 ** keys with no associated data. If the cursor was opened expecting an 56398 56152 ** intkey table, the caller should be inserting integer keys with a 56399 56153 ** blob of associated data. */ 56400 56154 assert( (pKey==0)==(pCur->pKeyInfo==0) ); 56155 + 56156 + /* If this is an insert into a table b-tree, invalidate any incrblob 56157 + ** cursors open on the row being replaced (assuming this is a replace 56158 + ** operation - if it is not, the following is a no-op). */ 56159 + if( pCur->pKeyInfo==0 ){ 56160 + invalidateIncrblobCursors(p, nKey, 0); 56161 + } 56401 56162 56402 56163 /* Save the positions of any other cursors open on this table. 56403 56164 ** 56404 56165 ** In some cases, the call to btreeMoveto() below is a no-op. For 56405 56166 ** example, when inserting data into a table with auto-generated integer 56406 56167 ** keys, the VDBE layer invokes sqlite3BtreeLast() to figure out the 56407 56168 ** integer key to use. It then calls this function to actually insert the ................................................................................ 56408 56169 ** data into the intkey B-Tree. In this case btreeMoveto() recognizes 56409 56170 ** that the cursor is already where it needs to be and returns without 56410 56171 ** doing any work. To avoid thwarting these optimizations, it is important 56411 56172 ** not to clear the cursor here. 56412 56173 */ 56413 56174 rc = saveAllCursors(pBt, pCur->pgnoRoot, pCur); 56414 56175 if( rc ) return rc; 56415 - 56416 - /* If this is an insert into a table b-tree, invalidate any incrblob 56417 - ** cursors open on the row being replaced (assuming this is a replace 56418 - ** operation - if it is not, the following is a no-op). */ 56419 - if( pCur->pKeyInfo==0 ){ 56420 - invalidateIncrblobCursors(p, nKey, 0); 56421 - } 56422 - 56423 56176 if( !loc ){ 56424 56177 rc = btreeMoveto(pCur, pKey, nKey, appendBias, &loc); 56425 56178 if( rc ) return rc; 56426 56179 } 56427 56180 assert( pCur->eState==CURSOR_VALID || (pCur->eState==CURSOR_INVALID && loc) ); 56428 56181 56429 56182 pPage = pCur->apPage[pCur->iPage]; ................................................................................ 56525 56278 assert( !hasReadConflicts(p, pCur->pgnoRoot) ); 56526 56279 56527 56280 if( NEVER(pCur->aiIdx[pCur->iPage]>=pCur->apPage[pCur->iPage]->nCell) 56528 56281 || NEVER(pCur->eState!=CURSOR_VALID) 56529 56282 ){ 56530 56283 return SQLITE_ERROR; /* Something has gone awry. */ 56531 56284 } 56285 + 56286 + /* If this is a delete operation to remove a row from a table b-tree, 56287 + ** invalidate any incrblob cursors open on the row being deleted. */ 56288 + if( pCur->pKeyInfo==0 ){ 56289 + invalidateIncrblobCursors(p, pCur->info.nKey, 0); 56290 + } 56532 56291 56533 56292 iCellDepth = pCur->iPage; 56534 56293 iCellIdx = pCur->aiIdx[iCellDepth]; 56535 56294 pPage = pCur->apPage[iCellDepth]; 56536 56295 pCell = findCell(pPage, iCellIdx); 56537 56296 56538 56297 /* If the page containing the entry to delete is not a leaf page, move ................................................................................ 56551 56310 /* Save the positions of any other cursors open on this table before 56552 56311 ** making any modifications. Make the page containing the entry to be 56553 56312 ** deleted writable. Then free any overflow pages associated with the 56554 56313 ** entry and finally remove the cell itself from within the page. 56555 56314 */ 56556 56315 rc = saveAllCursors(pBt, pCur->pgnoRoot, pCur); 56557 56316 if( rc ) return rc; 56558 - 56559 - /* If this is a delete operation to remove a row from a table b-tree, 56560 - ** invalidate any incrblob cursors open on the row being deleted. */ 56561 - if( pCur->pKeyInfo==0 ){ 56562 - invalidateIncrblobCursors(p, pCur->info.nKey, 0); 56563 - } 56564 - 56565 56317 rc = sqlite3PagerWrite(pPage->pDbPage); 56566 56318 if( rc ) return rc; 56567 56319 rc = clearCell(pPage, pCell); 56568 56320 dropCell(pPage, iCellIdx, cellSizePtr(pPage, pCell), &rc); 56569 56321 if( rc ) return rc; 56570 56322 56571 56323 /* If the cell deleted was not located on a leaf page, then the cursor ................................................................................ 56838 56590 ** entries in the table. 56839 56591 */ 56840 56592 SQLITE_PRIVATE int sqlite3BtreeClearTable(Btree *p, int iTable, int *pnChange){ 56841 56593 int rc; 56842 56594 BtShared *pBt = p->pBt; 56843 56595 sqlite3BtreeEnter(p); 56844 56596 assert( p->inTrans==TRANS_WRITE ); 56597 + 56598 + /* Invalidate all incrblob cursors open on table iTable (assuming iTable 56599 + ** is the root of a table b-tree - if it is not, the following call is 56600 + ** a no-op). */ 56601 + invalidateIncrblobCursors(p, 0, 1); 56845 56602 56846 56603 rc = saveAllCursors(pBt, (Pgno)iTable, 0); 56847 - 56848 56604 if( SQLITE_OK==rc ){ 56849 - /* Invalidate all incrblob cursors open on table iTable (assuming iTable 56850 - ** is the root of a table b-tree - if it is not, the following call is 56851 - ** a no-op). */ 56852 - invalidateIncrblobCursors(p, 0, 1); 56853 56605 rc = clearDatabasePage(pBt, (Pgno)iTable, 0, pnChange); 56854 56606 } 56855 56607 sqlite3BtreeLeave(p); 56856 56608 return rc; 56857 56609 } 56858 56610 56859 56611 /* ................................................................................ 57160 56912 if( pCheck->errMsg.mallocFailed ){ 57161 56913 pCheck->mallocFailed = 1; 57162 56914 } 57163 56915 } 57164 56916 #endif /* SQLITE_OMIT_INTEGRITY_CHECK */ 57165 56917 57166 56918 #ifndef SQLITE_OMIT_INTEGRITY_CHECK 57167 - 57168 -/* 57169 -** Return non-zero if the bit in the IntegrityCk.aPgRef[] array that 57170 -** corresponds to page iPg is already set. 57171 -*/ 57172 -static int getPageReferenced(IntegrityCk *pCheck, Pgno iPg){ 57173 - assert( iPg<=pCheck->nPage && sizeof(pCheck->aPgRef[0])==1 ); 57174 - return (pCheck->aPgRef[iPg/8] & (1 << (iPg & 0x07))); 57175 -} 57176 - 57177 -/* 57178 -** Set the bit in the IntegrityCk.aPgRef[] array that corresponds to page iPg. 57179 -*/ 57180 -static void setPageReferenced(IntegrityCk *pCheck, Pgno iPg){ 57181 - assert( iPg<=pCheck->nPage && sizeof(pCheck->aPgRef[0])==1 ); 57182 - pCheck->aPgRef[iPg/8] |= (1 << (iPg & 0x07)); 57183 -} 57184 - 57185 - 57186 56919 /* 57187 56920 ** Add 1 to the reference count for page iPage. If this is the second 57188 56921 ** reference to the page, add an error message to pCheck->zErrMsg. 57189 56922 ** Return 1 if there are 2 ore more references to the page and 0 if 57190 56923 ** if this is the first reference to the page. 57191 56924 ** 57192 56925 ** Also check that the page number is in bounds. ................................................................................ 57193 56926 */ 57194 56927 static int checkRef(IntegrityCk *pCheck, Pgno iPage, char *zContext){ 57195 56928 if( iPage==0 ) return 1; 57196 56929 if( iPage>pCheck->nPage ){ 57197 56930 checkAppendMsg(pCheck, zContext, "invalid page number %d", iPage); 57198 56931 return 1; 57199 56932 } 57200 - if( getPageReferenced(pCheck, iPage) ){ 56933 + if( pCheck->anRef[iPage]==1 ){ 57201 56934 checkAppendMsg(pCheck, zContext, "2nd reference to page %d", iPage); 57202 56935 return 1; 57203 56936 } 57204 - setPageReferenced(pCheck, iPage); 57205 - return 0; 56937 + return (pCheck->anRef[iPage]++)>1; 57206 56938 } 57207 56939 57208 56940 #ifndef SQLITE_OMIT_AUTOVACUUM 57209 56941 /* 57210 56942 ** Check that the entry in the pointer-map for page iChild maps to 57211 56943 ** page iParent, pointer type ptrType. If not, append an error message 57212 56944 ** to pCheck. ................................................................................ 57574 57306 sCheck.nErr = 0; 57575 57307 sCheck.mallocFailed = 0; 57576 57308 *pnErr = 0; 57577 57309 if( sCheck.nPage==0 ){ 57578 57310 sqlite3BtreeLeave(p); 57579 57311 return 0; 57580 57312 } 57581 - 57582 - sCheck.aPgRef = sqlite3MallocZero((sCheck.nPage / 8)+ 1); 57583 - if( !sCheck.aPgRef ){ 57313 + sCheck.anRef = sqlite3Malloc( (sCheck.nPage+1)*sizeof(sCheck.anRef[0]) ); 57314 + if( !sCheck.anRef ){ 57584 57315 *pnErr = 1; 57585 57316 sqlite3BtreeLeave(p); 57586 57317 return 0; 57587 57318 } 57319 + for(i=0; i<=sCheck.nPage; i++){ sCheck.anRef[i] = 0; } 57588 57320 i = PENDING_BYTE_PAGE(pBt); 57589 - if( i<=sCheck.nPage ) setPageReferenced(&sCheck, i); 57321 + if( i<=sCheck.nPage ){ 57322 + sCheck.anRef[i] = 1; 57323 + } 57590 57324 sqlite3StrAccumInit(&sCheck.errMsg, zErr, sizeof(zErr), 20000); 57591 57325 sCheck.errMsg.useMalloc = 2; 57592 57326 57593 57327 /* Check the integrity of the freelist 57594 57328 */ 57595 57329 checkList(&sCheck, 1, get4byte(&pBt->pPage1->aData[32]), 57596 57330 get4byte(&pBt->pPage1->aData[36]), "Main freelist: "); ................................................................................ 57607 57341 checkTreePage(&sCheck, aRoot[i], "List of tree roots: ", NULL, NULL); 57608 57342 } 57609 57343 57610 57344 /* Make sure every page in the file is referenced 57611 57345 */ 57612 57346 for(i=1; i<=sCheck.nPage && sCheck.mxErr; i++){ 57613 57347 #ifdef SQLITE_OMIT_AUTOVACUUM 57614 - if( getPageReferenced(&sCheck, i)==0 ){ 57348 + if( sCheck.anRef[i]==0 ){ 57615 57349 checkAppendMsg(&sCheck, 0, "Page %d is never used", i); 57616 57350 } 57617 57351 #else 57618 57352 /* If the database supports auto-vacuum, make sure no tables contain 57619 57353 ** references to pointer-map pages. 57620 57354 */ 57621 - if( getPageReferenced(&sCheck, i)==0 && 57355 + if( sCheck.anRef[i]==0 && 57622 57356 (PTRMAP_PAGENO(pBt, i)!=i || !pBt->autoVacuum) ){ 57623 57357 checkAppendMsg(&sCheck, 0, "Page %d is never used", i); 57624 57358 } 57625 - if( getPageReferenced(&sCheck, i)!=0 && 57359 + if( sCheck.anRef[i]!=0 && 57626 57360 (PTRMAP_PAGENO(pBt, i)==i && pBt->autoVacuum) ){ 57627 57361 checkAppendMsg(&sCheck, 0, "Pointer map page %d is referenced", i); 57628 57362 } 57629 57363 #endif 57630 57364 } 57631 57365 57632 57366 /* Make sure this analysis did not leave any unref() pages. ................................................................................ 57639 57373 nRef, sqlite3PagerRefcount(pBt->pPager) 57640 57374 ); 57641 57375 } 57642 57376 57643 57377 /* Clean up and report errors. 57644 57378 */ 57645 57379 sqlite3BtreeLeave(p); 57646 - sqlite3_free(sCheck.aPgRef); 57380 + sqlite3_free(sCheck.anRef); 57647 57381 if( sCheck.mallocFailed ){ 57648 57382 sqlite3StrAccumReset(&sCheck.errMsg); 57649 57383 *pnErr = sCheck.nErr+1; 57650 57384 return 0; 57651 57385 } 57652 57386 *pnErr = sCheck.nErr; 57653 57387 if( sCheck.nErr==0 ) sqlite3StrAccumReset(&sCheck.errMsg); ................................................................................ 58675 58409 #endif 58676 58410 } 58677 58411 58678 58412 /* 58679 58413 ** Make sure pMem->z points to a writable allocation of at least 58680 58414 ** n bytes. 58681 58415 ** 58682 -** If the third argument passed to this function is true, then memory 58683 -** cell pMem must contain a string or blob. In this case the content is 58684 -** preserved. Otherwise, if the third parameter to this function is false, 58685 -** any current string or blob value may be discarded. 58416 +** If the memory cell currently contains string or blob data 58417 +** and the third argument passed to this function is true, the 58418 +** current content of the cell is preserved. Otherwise, it may 58419 +** be discarded. 58686 58420 ** 58687 58421 ** This function sets the MEM_Dyn flag and clears any xDel callback. 58688 58422 ** It also clears MEM_Ephem and MEM_Static. If the preserve flag is 58689 58423 ** not set, Mem.n is zeroed. 58690 58424 */ 58691 58425 SQLITE_PRIVATE int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve){ 58692 58426 assert( 1 >= ................................................................................ 58693 58427 ((pMem->zMalloc && pMem->zMalloc==pMem->z) ? 1 : 0) + 58694 58428 (((pMem->flags&MEM_Dyn)&&pMem->xDel) ? 1 : 0) + 58695 58429 ((pMem->flags&MEM_Ephem) ? 1 : 0) + 58696 58430 ((pMem->flags&MEM_Static) ? 1 : 0) 58697 58431 ); 58698 58432 assert( (pMem->flags&MEM_RowSet)==0 ); 58699 58433 58700 - /* If the preserve flag is set to true, then the memory cell must already 58701 - ** contain a valid string or blob value. */ 58702 - assert( preserve==0 || pMem->flags&(MEM_Blob|MEM_Str) ); 58703 - 58704 58434 if( n<32 ) n = 32; 58705 58435 if( sqlite3DbMallocSize(pMem->db, pMem->zMalloc)<n ){ 58706 58436 if( preserve && pMem->z==pMem->zMalloc ){ 58707 58437 pMem->z = pMem->zMalloc = sqlite3DbReallocOrFree(pMem->db, pMem->z, n); 58708 58438 preserve = 0; 58709 58439 }else{ 58710 58440 sqlite3DbFree(pMem->db, pMem->zMalloc); ................................................................................ 61015 60745 */ 61016 60746 if( pOp->p4type==P4_SUBPROGRAM ){ 61017 60747 int nByte = (nSub+1)*sizeof(SubProgram*); 61018 60748 int j; 61019 60749 for(j=0; j<nSub; j++){ 61020 60750 if( apSub[j]==pOp->p4.pProgram ) break; 61021 60751 } 61022 - if( j==nSub && SQLITE_OK==sqlite3VdbeMemGrow(pSub, nByte, nSub!=0) ){ 60752 + if( j==nSub && SQLITE_OK==sqlite3VdbeMemGrow(pSub, nByte, 1) ){ 61023 60753 apSub = (SubProgram **)pSub->z; 61024 60754 apSub[nSub++] = pOp->p4.pProgram; 61025 60755 pSub->flags |= MEM_Blob; 61026 60756 pSub->n = nSub*sizeof(SubProgram*); 61027 60757 } 61028 60758 } 61029 60759 } ................................................................................ 67264 66994 ** if the P4 argument is a P4_MEM use the value of the P4 argument as 67265 66995 ** the result. 67266 66996 ** 67267 66997 ** If the OPFLAG_CLEARCACHE bit is set on P5 and P1 is a pseudo-table cursor, 67268 66998 ** then the cache of the cursor is reset prior to extracting the column. 67269 66999 ** The first OP_Column against a pseudo-table after the value of the content 67270 67000 ** register has changed should have this bit set. 67271 -** 67272 -** If the OPFLAG_LENGTHARG and OPFLAG_TYPEOFARG bits are set on P5 when 67273 -** the result is guaranteed to only be used as the argument of a length() 67274 -** or typeof() function, respectively. The loading of large blobs can be 67275 -** skipped for length() and all content loading can be skipped for typeof(). 67276 67001 */ 67277 67002 case OP_Column: { 67278 67003 #if 0 /* local variables moved into u.an */ 67279 67004 u32 payloadSize; /* Number of bytes in the record */ 67280 67005 i64 payloadSize64; /* Number of bytes in the record */ 67281 67006 int p1; /* P1 value of the opcode */ 67282 67007 int p2; /* column number to retrieve */ ................................................................................ 67411 67136 if( u.an.payloadSize <= (u32)u.an.avail ){ 67412 67137 u.an.zRec = u.an.zData; 67413 67138 u.an.pC->aRow = (u8*)u.an.zData; 67414 67139 }else{ 67415 67140 u.an.pC->aRow = 0; 67416 67141 } 67417 67142 } 67418 - /* The following assert is true in all cases except when 67143 + /* The following assert is true in all cases accept when 67419 67144 ** the database file has been corrupted externally. 67420 67145 ** assert( u.an.zRec!=0 || u.an.avail>=u.an.payloadSize || u.an.avail>=9 ); */ 67421 67146 u.an.szHdr = getVarint32((u8*)u.an.zData, u.an.offset); 67422 67147 67423 67148 /* Make sure a corrupt database has not given us an oversize header. 67424 67149 ** Do this now to avoid an oversize memory allocation. 67425 67150 ** ................................................................................ 67486 67211 u.an.szField = sqlite3VdbeSerialTypeLen(u.an.t); 67487 67212 u.an.offset += u.an.szField; 67488 67213 if( u.an.offset<u.an.szField ){ /* True if u.an.offset overflows */ 67489 67214 u.an.zIdx = &u.an.zEndHdr[1]; /* Forces SQLITE_CORRUPT return below */ 67490 67215 break; 67491 67216 } 67492 67217 }else{ 67493 - /* If u.an.i is less that u.an.nField, then there are fewer fields in this 67218 + /* If u.an.i is less that u.an.nField, then there are less fields in this 67494 67219 ** record than SetNumColumns indicated there are columns in the 67495 67220 ** table. Set the u.an.offset for any extra columns not present in 67496 - ** the record to 0. This tells code below to store the default value 67497 - ** for the column instead of deserializing a value from the record. 67221 + ** the record to 0. This tells code below to store a NULL 67222 + ** instead of deserializing a value from the record. 67498 67223 */ 67499 67224 u.an.aOffset[u.an.i] = 0; 67500 67225 } 67501 67226 } 67502 67227 sqlite3VdbeMemRelease(&u.an.sMem); 67503 67228 u.an.sMem.flags = MEM_Null; 67504 67229 ................................................................................ 67520 67245 ** then there are not enough fields in the record to satisfy the 67521 67246 ** request. In this case, set the value NULL or to P4 if P4 is 67522 67247 ** a pointer to a Mem object. 67523 67248 */ 67524 67249 if( u.an.aOffset[u.an.p2] ){ 67525 67250 assert( rc==SQLITE_OK ); 67526 67251 if( u.an.zRec ){ 67527 - /* This is the common case where the whole row fits on a single page */ 67528 67252 VdbeMemRelease(u.an.pDest); 67529 67253 sqlite3VdbeSerialGet((u8 *)&u.an.zRec[u.an.aOffset[u.an.p2]], u.an.aType[u.an.p2], u.an.pDest); 67530 67254 }else{ 67531 - /* This branch happens only when the row overflows onto multiple pages */ 67532 - u.an.t = u.an.aType[u.an.p2]; 67533 - if( (pOp->p5 & (OPFLAG_LENGTHARG|OPFLAG_TYPEOFARG))!=0 67534 - && ((u.an.t>=12 && (u.an.t&1)==0) || (pOp->p5 & OPFLAG_TYPEOFARG)!=0) 67535 - ){ 67536 - /* Content is irrelevant for the typeof() function and for 67537 - ** the length(X) function if X is a blob. So we might as well use 67538 - ** bogus content rather than reading content from disk. NULL works 67539 - ** for text and blob and whatever is in the u.an.payloadSize64 variable 67540 - ** will work for everything else. */ 67541 - u.an.zData = u.an.t<12 ? (char*)&u.an.payloadSize64 : 0; 67542 - }else{ 67543 - u.an.len = sqlite3VdbeSerialTypeLen(u.an.t); 67544 - sqlite3VdbeMemMove(&u.an.sMem, u.an.pDest); 67545 - rc = sqlite3VdbeMemFromBtree(u.an.pCrsr, u.an.aOffset[u.an.p2], u.an.len, u.an.pC->isIndex, 67546 - &u.an.sMem); 67547 - if( rc!=SQLITE_OK ){ 67548 - goto op_column_out; 67549 - } 67550 - u.an.zData = u.an.sMem.z; 67255 + u.an.len = sqlite3VdbeSerialTypeLen(u.an.aType[u.an.p2]); 67256 + sqlite3VdbeMemMove(&u.an.sMem, u.an.pDest); 67257 + rc = sqlite3VdbeMemFromBtree(u.an.pCrsr, u.an.aOffset[u.an.p2], u.an.len, u.an.pC->isIndex, &u.an.sMem); 67258 + if( rc!=SQLITE_OK ){ 67259 + goto op_column_out; 67551 67260 } 67552 - sqlite3VdbeSerialGet((u8*)u.an.zData, u.an.t, u.an.pDest); 67261 + u.an.zData = u.an.sMem.z; 67262 + sqlite3VdbeSerialGet((u8*)u.an.zData, u.an.aType[u.an.p2], u.an.pDest); 67553 67263 } 67554 67264 u.an.pDest->enc = encoding; 67555 67265 }else{ 67556 67266 if( pOp->p4type==P4_MEM ){ 67557 67267 sqlite3VdbeMemShallowCopy(u.an.pDest, pOp->p4.pMem, MEM_Static); 67558 67268 }else{ 67559 67269 MemSetTypeFlag(u.an.pDest, MEM_Null); ................................................................................ 67881 67591 p->rc = rc = SQLITE_BUSY; 67882 67592 goto vdbe_return; 67883 67593 } 67884 67594 db->isTransactionSavepoint = 0; 67885 67595 rc = p->rc; 67886 67596 }else{ 67887 67597 u.ar.iSavepoint = db->nSavepoint - u.ar.iSavepoint - 1; 67888 - if( u.ar.p1==SAVEPOINT_ROLLBACK ){ 67889 - for(u.ar.ii=0; u.ar.ii<db->nDb; u.ar.ii++){ 67890 - sqlite3BtreeTripAllCursors(db->aDb[u.ar.ii].pBt, SQLITE_ABORT); 67891 - } 67598 + for(u.ar.ii=0; u.ar.ii<db->nDb; u.ar.ii++){ 67599 + sqlite3BtreeTripAllCursors(db->aDb[u.ar.ii].pBt, SQLITE_ABORT); 67892 67600 } 67893 67601 for(u.ar.ii=0; u.ar.ii<db->nDb; u.ar.ii++){ 67894 67602 rc = sqlite3BtreeSavepoint(db->aDb[u.ar.ii].pBt, u.ar.p1, u.ar.iSavepoint); 67895 67603 if( rc!=SQLITE_OK ){ 67896 67604 goto abort_due_to_error; 67897 67605 } 67898 67606 } ................................................................................ 73987 73695 73988 73696 testcase( pExpr->op==TK_CONST_FUNC ); 73989 73697 assert( !ExprHasProperty(pExpr, EP_xIsSelect) ); 73990 73698 zId = pExpr->u.zToken; 73991 73699 nId = sqlite3Strlen30(zId); 73992 73700 pDef = sqlite3FindFunction(pParse->db, zId, nId, n, enc, 0); 73993 73701 if( pDef==0 ){ 73994 - pDef = sqlite3FindFunction(pParse->db, zId, nId, -2, enc, 0); 73702 + pDef = sqlite3FindFunction(pParse->db, zId, nId, -1, enc, 0); 73995 73703 if( pDef==0 ){ 73996 73704 no_such_func = 1; 73997 73705 }else{ 73998 73706 wrong_num_args = 1; 73999 73707 } 74000 73708 }else{ 74001 73709 is_agg = pDef->xFunc==0; ................................................................................ 74337 74045 */ 74338 74046 static int resolveOrderGroupBy( 74339 74047 NameContext *pNC, /* The name context of the SELECT statement */ 74340 74048 Select *pSelect, /* The SELECT statement holding pOrderBy */ 74341 74049 ExprList *pOrderBy, /* An ORDER BY or GROUP BY clause to resolve */ 74342 74050 const char *zType /* Either "ORDER" or "GROUP", as appropriate */ 74343 74051 ){ 74344 - int i, j; /* Loop counters */ 74052 + int i; /* Loop counter */ 74345 74053 int iCol; /* Column number */ 74346 74054 struct ExprList_item *pItem; /* A term of the ORDER BY clause */ 74347 74055 Parse *pParse; /* Parsing context */ 74348 74056 int nResult; /* Number of terms in the result set */ 74349 74057 74350 74058 if( pOrderBy==0 ) return 0; 74351 74059 nResult = pSelect->pEList->nExpr; ................................................................................ 74374 74082 } 74375 74083 74376 74084 /* Otherwise, treat the ORDER BY term as an ordinary expression */ 74377 74085 pItem->iOrderByCol = 0; 74378 74086 if( sqlite3ResolveExprNames(pNC, pE) ){ 74379 74087 return 1; 74380 74088 } 74381 - for(j=0; j<pSelect->pEList->nExpr; j++){ 74382 - if( sqlite3ExprCompare(pE, pSelect->pEList->a[j].pExpr)==0 ){ 74383 - pItem->iOrderByCol = j+1; 74384 - } 74385 - } 74386 74089 } 74387 74090 return sqlite3ResolveOrderGroupBy(pParse, pSelect, pOrderBy, zType); 74388 74091 } 74389 74092 74390 74093 /* 74391 74094 ** Resolve names in the SELECT statement p and all of its descendents. 74392 74095 */ ................................................................................ 75168 74871 SQLITE_PRIVATE Expr *sqlite3PExpr( 75169 74872 Parse *pParse, /* Parsing context */ 75170 74873 int op, /* Expression opcode */ 75171 74874 Expr *pLeft, /* Left operand */ 75172 74875 Expr *pRight, /* Right operand */ 75173 74876 const Token *pToken /* Argument token */ 75174 74877 ){ 75175 - Expr *p; 75176 - if( op==TK_AND && pLeft && pRight ){ 75177 - /* Take advantage of short-circuit false optimization for AND */ 75178 - p = sqlite3ExprAnd(pParse->db, pLeft, pRight); 75179 - }else{ 75180 - p = sqlite3ExprAlloc(pParse->db, op, pToken, 1); 75181 - sqlite3ExprAttachSubtrees(pParse->db, p, pLeft, pRight); 75182 - } 74878 + Expr *p = sqlite3ExprAlloc(pParse->db, op, pToken, 1); 74879 + sqlite3ExprAttachSubtrees(pParse->db, p, pLeft, pRight); 75183 74880 if( p ) { 75184 74881 sqlite3ExprCheckHeight(pParse, p->nHeight); 75185 74882 } 75186 74883 return p; 75187 74884 } 75188 74885 75189 -/* 75190 -** Return 1 if an expression must be FALSE in all cases and 0 if the 75191 -** expression might be true. This is an optimization. If is OK to 75192 -** return 0 here even if the expression really is always false (a 75193 -** false negative). But it is a bug to return 1 if the expression 75194 -** might be true in some rare circumstances (a false positive.) 75195 -** 75196 -** Note that if the expression is part of conditional for a 75197 -** LEFT JOIN, then we cannot determine at compile-time whether or not 75198 -** is it true or false, so always return 0. 75199 -*/ 75200 -static int exprAlwaysFalse(Expr *p){ 75201 - int v = 0; 75202 - if( ExprHasProperty(p, EP_FromJoin) ) return 0; 75203 - if( !sqlite3ExprIsInteger(p, &v) ) return 0; 75204 - return v==0; 75205 -} 75206 - 75207 74886 /* 75208 74887 ** Join two expressions using an AND operator. If either expression is 75209 74888 ** NULL, then just return the other expression. 75210 -** 75211 -** If one side or the other of the AND is known to be false, then instead 75212 -** of returning an AND expression, just return a constant expression with 75213 -** a value of false. 75214 74889 */ 75215 74890 SQLITE_PRIVATE Expr *sqlite3ExprAnd(sqlite3 *db, Expr *pLeft, Expr *pRight){ 75216 74891 if( pLeft==0 ){ 75217 74892 return pRight; 75218 74893 }else if( pRight==0 ){ 75219 74894 return pLeft; 75220 - }else if( exprAlwaysFalse(pLeft) || exprAlwaysFalse(pRight) ){ 75221 - sqlite3ExprDelete(db, pLeft); 75222 - sqlite3ExprDelete(db, pRight); 75223 - return sqlite3ExprAlloc(db, TK_INTEGER, &sqlite3IntTokens[0], 0); 75224 74895 }else{ 75225 74896 Expr *pNew = sqlite3ExprAlloc(db, TK_AND, 0, 0); 75226 74897 sqlite3ExprAttachSubtrees(db, pNew, pLeft, pRight); 75227 74898 return pNew; 75228 74899 } 75229 74900 } 75230 74901 ................................................................................ 76748 76419 /* First replace any existing entry. 76749 76420 ** 76750 76421 ** Actually, the way the column cache is currently used, we are guaranteed 76751 76422 ** that the object will never already be in cache. Verify this guarantee. 76752 76423 */ 76753 76424 #ifndef NDEBUG 76754 76425 for(i=0, p=pParse->aColCache; i<SQLITE_N_COLCACHE; i++, p++){ 76426 +#if 0 /* This code wold remove the entry from the cache if it existed */ 76427 + if( p->iReg && p->iTable==iTab && p->iColumn==iCol ){ 76428 + cacheEntryClear(pParse, p); 76429 + p->iLevel = pParse->iCacheLevel; 76430 + p->iReg = iReg; 76431 + p->lru = pParse->iCacheCnt++; 76432 + return; 76433 + } 76434 +#endif 76755 76435 assert( p->iReg==0 || p->iTable!=iTab || p->iColumn!=iCol ); 76756 76436 } 76757 76437 #endif 76758 76438 76759 76439 /* Find an empty slot and replace it */ 76760 76440 for(i=0, p=pParse->aColCache; i<SQLITE_N_COLCACHE; i++, p++){ 76761 76441 if( p->iReg==0 ){ ................................................................................ 76882 76562 ** is called. If iColumn<0 then code is generated that extracts the rowid. 76883 76563 */ 76884 76564 SQLITE_PRIVATE int sqlite3ExprCodeGetColumn( 76885 76565 Parse *pParse, /* Parsing and code generating context */ 76886 76566 Table *pTab, /* Description of the table we are reading from */ 76887 76567 int iColumn, /* Index of the table column */ 76888 76568 int iTable, /* The cursor pointing to the table */ 76889 - int iReg, /* Store results here */ 76890 - u8 p5 /* P5 value for OP_Column */ 76569 + int iReg /* Store results here */ 76891 76570 ){ 76892 76571 Vdbe *v = pParse->pVdbe; 76893 76572 int i; 76894 76573 struct yColCache *p; 76895 76574 76896 76575 for(i=0, p=pParse->aColCache; i<SQLITE_N_COLCACHE; i++, p++){ 76897 76576 if( p->iReg>0 && p->iTable==iTable && p->iColumn==iColumn ){ ................................................................................ 76898 76577 p->lru = pParse->iCacheCnt++; 76899 76578 sqlite3ExprCachePinRegister(pParse, p->iReg); 76900 76579 return p->iReg; 76901 76580 } 76902 76581 } 76903 76582 assert( v!=0 ); 76904 76583 sqlite3ExprCodeGetColumnOfTable(v, pTab, iTable, iColumn, iReg); 76905 - if( p5 ){ 76906 - sqlite3VdbeChangeP5(v, p5); 76907 - }else{ 76908 - sqlite3ExprCacheStore(pParse, iTable, iColumn, iReg); 76909 - } 76584 + sqlite3ExprCacheStore(pParse, iTable, iColumn, iReg); 76910 76585 return iReg; 76911 76586 } 76912 76587 76913 76588 /* 76914 76589 ** Clear all column cache entries. 76915 76590 */ 76916 76591 SQLITE_PRIVATE void sqlite3ExprCacheClear(Parse *pParse){ ................................................................................ 77030 76705 case TK_COLUMN: { 77031 76706 if( pExpr->iTable<0 ){ 77032 76707 /* This only happens when coding check constraints */ 77033 76708 assert( pParse->ckBase>0 ); 77034 76709 inReg = pExpr->iColumn + pParse->ckBase; 77035 76710 }else{ 77036 76711 inReg = sqlite3ExprCodeGetColumn(pParse, pExpr->pTab, 77037 - pExpr->iColumn, pExpr->iTable, target, 77038 - pExpr->op2); 76712 + pExpr->iColumn, pExpr->iTable, target); 77039 76713 } 77040 76714 break; 77041 76715 } 77042 76716 case TK_INTEGER: { 77043 76717 codeInteger(pParse, pExpr, 0, target); 77044 76718 break; 77045 76719 } ................................................................................ 77308 76982 sqlite3VdbeResolveLabel(v, endCoalesce); 77309 76983 break; 77310 76984 } 77311 76985 77312 76986 77313 76987 if( pFarg ){ 77314 76988 r1 = sqlite3GetTempRange(pParse, nFarg); 77315 - 77316 - /* For length() and typeof() functions with a column argument, 77317 - ** set the P5 parameter to the OP_Column opcode to OPFLAG_LENGTHARG 77318 - ** or OPFLAG_TYPEOFARG respectively, to avoid unnecessary data 77319 - ** loading. 77320 - */ 77321 - if( (pDef->flags & (SQLITE_FUNC_LENGTH|SQLITE_FUNC_TYPEOF))!=0 ){ 77322 - u8 exprOp; 77323 - assert( nFarg==1 ); 77324 - assert( pFarg->a[0].pExpr!=0 ); 77325 - exprOp = pFarg->a[0].pExpr->op; 77326 - if( exprOp==TK_COLUMN || exprOp==TK_AGG_COLUMN ){ 77327 - assert( SQLITE_FUNC_LENGTH==OPFLAG_LENGTHARG ); 77328 - assert( SQLITE_FUNC_TYPEOF==OPFLAG_TYPEOFARG ); 77329 - testcase( pDef->flags==SQLITE_FUNC_LENGTH ); 77330 - pFarg->a[0].pExpr->op2 = pDef->flags; 77331 - } 77332 - } 77333 - 77334 76989 sqlite3ExprCachePush(pParse); /* Ticket 2ea2425d34be */ 77335 76990 sqlite3ExprCodeExprList(pParse, pFarg, r1, 1); 77336 76991 sqlite3ExprCachePop(pParse, 1); /* Ticket 2ea2425d34be */ 77337 76992 }else{ 77338 76993 r1 = 0; 77339 76994 } 77340 76995 #ifndef SQLITE_OMIT_VIRTUALTABLE ................................................................................ 78462 78117 if( sqlite3ExprCompare(pA->pRight, pB->pRight) ) return 2; 78463 78118 if( sqlite3ExprListCompare(pA->x.pList, pB->x.pList) ) return 2; 78464 78119 if( pA->iTable!=pB->iTable || pA->iColumn!=pB->iColumn ) return 2; 78465 78120 if( ExprHasProperty(pA, EP_IntValue) ){ 78466 78121 if( !ExprHasProperty(pB, EP_IntValue) || pA->u.iValue!=pB->u.iValue ){ 78467 78122 return 2; 78468 78123 } 78469 - }else if( pA->op!=TK_COLUMN && pA->op!=TK_AGG_COLUMN && pA->u.zToken ){ 78124 + }else if( pA->op!=TK_COLUMN && pA->u.zToken ){ 78470 78125 if( ExprHasProperty(pB, EP_IntValue) || NEVER(pB->u.zToken==0) ) return 2; 78471 78126 if( strcmp(pA->u.zToken,pB->u.zToken)!=0 ){ 78472 78127 return 2; 78473 78128 } 78474 78129 } 78475 78130 if( (pA->flags & EP_ExpCollate)!=(pB->flags & EP_ExpCollate) ) return 1; 78476 78131 if( (pA->flags & EP_ExpCollate)!=0 && pA->pColl!=pB->pColl ) return 2; ................................................................................ 78499 78154 Expr *pExprB = pB->a[i].pExpr; 78500 78155 if( pA->a[i].sortOrder!=pB->a[i].sortOrder ) return 1; 78501 78156 if( sqlite3ExprCompare(pExprA, pExprB) ) return 1; 78502 78157 } 78503 78158 return 0; 78504 78159 } 78505 78160 78506 -/* 78507 -** This is the expression callback for sqlite3FunctionUsesOtherSrc(). 78508 -** 78509 -** Determine if an expression references any table other than one of the 78510 -** tables in pWalker->u.pSrcList and abort if it does. 78511 -*/ 78512 -static int exprUsesOtherSrc(Walker *pWalker, Expr *pExpr){ 78513 - if( pExpr->op==TK_COLUMN || pExpr->op==TK_AGG_COLUMN ){ 78514 - int i; 78515 - SrcList *pSrc = pWalker->u.pSrcList; 78516 - for(i=0; i<pSrc->nSrc; i++){ 78517 - if( pExpr->iTable==pSrc->a[i].iCursor ) return WRC_Continue; 78518 - } 78519 - return WRC_Abort; 78520 - }else{ 78521 - return WRC_Continue; 78522 - } 78523 -} 78524 - 78525 -/* 78526 -** Determine if any of the arguments to the pExpr Function references 78527 -** any SrcList other than pSrcList. Return true if they do. Return 78528 -** false if pExpr has no argument or has only constant arguments or 78529 -** only references tables named in pSrcList. 78530 -*/ 78531 -static int sqlite3FunctionUsesOtherSrc(Expr *pExpr, SrcList *pSrcList){ 78532 - Walker w; 78533 - assert( pExpr->op==TK_AGG_FUNCTION ); 78534 - memset(&w, 0, sizeof(w)); 78535 - w.xExprCallback = exprUsesOtherSrc; 78536 - w.u.pSrcList = pSrcList; 78537 - if( sqlite3WalkExprList(&w, pExpr->x.pList)!=WRC_Continue ) return 1; 78538 - return 0; 78539 -} 78540 - 78541 78161 /* 78542 78162 ** Add a new element to the pAggInfo->aCol[] array. Return the index of 78543 78163 ** the new element. Return a negative number if malloc fails. 78544 78164 */ 78545 78165 static int addAggInfoColumn(sqlite3 *db, AggInfo *pInfo){ 78546 78166 int i; 78547 78167 pInfo->aCol = sqlite3ArrayAllocate( ................................................................................ 78649 78269 break; 78650 78270 } /* endif pExpr->iTable==pItem->iCursor */ 78651 78271 } /* end loop over pSrcList */ 78652 78272 } 78653 78273 return WRC_Prune; 78654 78274 } 78655 78275 case TK_AGG_FUNCTION: { 78656 - if( !sqlite3FunctionUsesOtherSrc(pExpr, pSrcList) ){ 78276 + /* The pNC->nDepth==0 test causes aggregate functions in subqueries 78277 + ** to be ignored */ 78278 + if( pNC->nDepth==0 ){ 78657 78279 /* Check to see if pExpr is a duplicate of another aggregate 78658 78280 ** function that is already in the pAggInfo structure 78659 78281 */ 78660 78282 struct AggInfo_func *pItem = pAggInfo->aFunc; 78661 78283 for(i=0; i<pAggInfo->nFunc; i++, pItem++){ 78662 78284 if( sqlite3ExprCompare(pItem->pExpr, pExpr)==0 ){ 78663 78285 break; ................................................................................ 78693 78315 return WRC_Prune; 78694 78316 } 78695 78317 } 78696 78318 } 78697 78319 return WRC_Continue; 78698 78320 } 78699 78321 static int analyzeAggregatesInSelect(Walker *pWalker, Select *pSelect){ 78700 - UNUSED_PARAMETER(pWalker); 78701 - UNUSED_PARAMETER(pSelect); 78702 - return WRC_Continue; 78322 + NameContext *pNC = pWalker->u.pNC; 78323 + if( pNC->nDepth==0 ){ 78324 + pNC->nDepth++; 78325 + sqlite3WalkSelect(pWalker, pSelect); 78326 + pNC->nDepth--; 78327 + return WRC_Prune; 78328 + }else{ 78329 + return WRC_Continue; 78330 + } 78703 78331 } 78704 78332 78705 78333 /* 78706 78334 ** Analyze the given expression looking for aggregate functions and 78707 78335 ** for variables that need to be added to the pParse->aAgg[] array. 78708 78336 ** Make additional entries to the pParse->aAgg[] array as necessary. 78709 78337 ** 78710 78338 ** This routine should only be called after the expression has been 78711 78339 ** analyzed by sqlite3ResolveExprNames(). 78712 78340 */ 78713 78341 SQLITE_PRIVATE void sqlite3ExprAnalyzeAggregates(NameContext *pNC, Expr *pExpr){ 78714 78342 Walker w; 78715 - memset(&w, 0, sizeof(w)); 78716 78343 w.xExprCallback = analyzeAggregate; 78717 78344 w.xSelectCallback = analyzeAggregatesInSelect; 78718 78345 w.u.pNC = pNC; 78719 78346 assert( pNC->pSrcList!=0 ); 78720 78347 sqlite3WalkExpr(&w, pExpr); 78721 78348 } 78722 78349 ................................................................................ 82102 81729 /* Delete the Table structure itself. 82103 81730 */ 82104 81731 sqliteDeleteColumnNames(db, pTable); 82105 81732 sqlite3DbFree(db, pTable->zName); 82106 81733 sqlite3DbFree(db, pTable->zColAff); 82107 81734 sqlite3SelectDelete(db, pTable->pSelect); 82108 81735 #ifndef SQLITE_OMIT_CHECK 82109 - sqlite3ExprListDelete(db, pTable->pCheck); 81736 + sqlite3ExprDelete(db, pTable->pCheck); 82110 81737 #endif 82111 81738 #ifndef SQLITE_OMIT_VIRTUALTABLE 82112 81739 sqlite3VtabClear(db, pTable); 82113 81740 #endif 82114 81741 sqlite3DbFree(db, pTable); 82115 81742 } 82116 81743 ................................................................................ 82765 82392 /* 82766 82393 ** Add a new CHECK constraint to the table currently under construction. 82767 82394 */ 82768 82395 SQLITE_PRIVATE void sqlite3AddCheckConstraint( 82769 82396 Parse *pParse, /* Parsing context */ 82770 82397 Expr *pCheckExpr /* The check expression */ 82771 82398 ){ 82399 + sqlite3 *db = pParse->db; 82772 82400 #ifndef SQLITE_OMIT_CHECK 82773 82401 Table *pTab = pParse->pNewTable; 82774 82402 if( pTab && !IN_DECLARE_VTAB ){ 82775 - pTab->pCheck = sqlite3ExprListAppend(pParse, pTab->pCheck, pCheckExpr); 82776 - if( pParse->constraintName.n ){ 82777 - sqlite3ExprListSetName(pParse, pTab->pCheck, &pParse->constraintName, 1); 82778 - } 82403 + pTab->pCheck = sqlite3ExprAnd(db, pTab->pCheck, pCheckExpr); 82779 82404 }else 82780 82405 #endif 82781 82406 { 82782 - sqlite3ExprDelete(pParse->db, pCheckExpr); 82407 + sqlite3ExprDelete(db, pCheckExpr); 82783 82408 } 82784 82409 } 82785 82410 82786 82411 /* 82787 82412 ** Set the collation function of the most recently parsed table column 82788 82413 ** to the CollSeq given. 82789 82414 */ ................................................................................ 83045 82670 83046 82671 #ifndef SQLITE_OMIT_CHECK 83047 82672 /* Resolve names in all CHECK constraint expressions. 83048 82673 */ 83049 82674 if( p->pCheck ){ 83050 82675 SrcList sSrc; /* Fake SrcList for pParse->pNewTable */ 83051 82676 NameContext sNC; /* Name context for pParse->pNewTable */ 83052 - ExprList *pList; /* List of all CHECK constraints */ 83053 - int i; /* Loop counter */ 83054 82677 83055 82678 memset(&sNC, 0, sizeof(sNC)); 83056 82679 memset(&sSrc, 0, sizeof(sSrc)); 83057 82680 sSrc.nSrc = 1; 83058 82681 sSrc.a[0].zName = p->zName; 83059 82682 sSrc.a[0].pTab = p; 83060 82683 sSrc.a[0].iCursor = -1; 83061 82684 sNC.pParse = pParse; 83062 82685 sNC.pSrcList = &sSrc; 83063 82686 sNC.isCheck = 1; 83064 - pList = p->pCheck; 83065 - for(i=0; i<pList->nExpr; i++){ 83066 - if( sqlite3ResolveExprNames(&sNC, pList->a[i].pExpr) ){ 83067 - return; 83068 - } 82687 + if( sqlite3ResolveExprNames(&sNC, p->pCheck) ){ 82688 + return; 83069 82689 } 83070 82690 } 83071 82691 #endif /* !defined(SQLITE_OMIT_CHECK) */ 83072 82692 83073 82693 /* If the db->init.busy is 1 it means we are reading the SQL off the 83074 82694 ** "sqlite_master" or "sqlite_temp_master" table on the disk. 83075 82695 ** So do not write to the disk again. Extract the root page number ................................................................................ 84612 84232 } 84613 84233 84614 84234 exit_drop_index: 84615 84235 sqlite3SrcListDelete(db, pName); 84616 84236 } 84617 84237 84618 84238 /* 84619 -** pArray is a pointer to an array of objects. Each object in the 84620 -** array is szEntry bytes in size. This routine uses sqlite3DbRealloc() 84621 -** to extend the array so that there is space for a new object at the end. 84239 +** pArray is a pointer to an array of objects. Each object in the 84240 +** array is szEntry bytes in size. This routine allocates a new 84241 +** object on the end of the array. 84622 84242 ** 84623 -** When this function is called, *pnEntry contains the current size of 84624 -** the array (in entries - so the allocation is ((*pnEntry) * szEntry) bytes 84625 -** in total). 84243 +** *pnEntry is the number of entries already in use. *pnAlloc is 84244 +** the previously allocated size of the array. initSize is the 84245 +** suggested initial array size allocation. 84626 84246 ** 84627 -** If the realloc() is successful (i.e. if no OOM condition occurs), the 84628 -** space allocated for the new object is zeroed, *pnEntry updated to 84629 -** reflect the new size of the array and a pointer to the new allocation 84630 -** returned. *pIdx is set to the index of the new array entry in this case. 84247 +** The index of the new entry is returned in *pIdx. 84631 84248 ** 84632 -** Otherwise, if the realloc() fails, *pIdx is set to -1, *pnEntry remains 84633 -** unchanged and a copy of pArray returned. 84249 +** This routine returns a pointer to the array of objects. This 84250 +** might be the same as the pArray parameter or it might be a different 84251 +** pointer if the array was resized. 84634 84252 */ 84635 84253 SQLITE_PRIVATE void *sqlite3ArrayAllocate( 84636 84254 sqlite3 *db, /* Connection to notify of malloc failures */ 84637 84255 void *pArray, /* Array of objects. Might be reallocated */ 84638 84256 int szEntry, /* Size of each object in the array */ 84639 84257 int *pnEntry, /* Number of objects currently in use */ 84640 84258 int *pIdx /* Write the index of a new slot here */ ................................................................................ 85613 85231 85614 85232 /* During the search for the best function definition, this procedure 85615 85233 ** is called to test how well the function passed as the first argument 85616 85234 ** matches the request for a function with nArg arguments in a system 85617 85235 ** that uses encoding enc. The value returned indicates how well the 85618 85236 ** request is matched. A higher value indicates a better match. 85619 85237 ** 85620 -** If nArg is -1 that means to only return a match (non-zero) if p->nArg 85621 -** is also -1. In other words, we are searching for a function that 85622 -** takes a variable number of arguments. 85623 -** 85624 -** If nArg is -2 that means that we are searching for any function 85625 -** regardless of the number of arguments it uses, so return a positive 85626 -** match score for any 85627 -** 85628 85238 ** The returned value is always between 0 and 6, as follows: 85629 85239 ** 85630 -** 0: Not a match. 85631 -** 1: UTF8/16 conversion required and function takes any number of arguments. 85632 -** 2: UTF16 byte order change required and function takes any number of args. 85633 -** 3: encoding matches and function takes any number of arguments 85634 -** 4: UTF8/16 conversion required - argument count matches exactly 85635 -** 5: UTF16 byte order conversion required - argument count matches exactly 85636 -** 6: Perfect match: encoding and argument count match exactly. 85637 -** 85638 -** If nArg==(-2) then any function with a non-null xStep or xFunc is 85639 -** a perfect match and any function with both xStep and xFunc NULL is 85640 -** a non-match. 85641 -*/ 85642 -#define FUNC_PERFECT_MATCH 6 /* The score for a perfect match */ 85643 -static int matchQuality( 85644 - FuncDef *p, /* The function we are evaluating for match quality */ 85645 - int nArg, /* Desired number of arguments. (-1)==any */ 85646 - u8 enc /* Desired text encoding */ 85647 -){ 85648 - int match; 85649 - 85650 - /* nArg of -2 is a special case */ 85651 - if( nArg==(-2) ) return (p->xFunc==0 && p->xStep==0) ? 0 : FUNC_PERFECT_MATCH; 85652 - 85653 - /* Wrong number of arguments means "no match" */ 85654 - if( p->nArg!=nArg && p->nArg>=0 ) return 0; 85655 - 85656 - /* Give a better score to a function with a specific number of arguments 85657 - ** than to function that accepts any number of arguments. */ 85658 - if( p->nArg==nArg ){ 85659 - match = 4; 85660 - }else{ 85240 +** 0: Not a match, or if nArg<0 and the function is has no implementation. 85241 +** 1: A variable arguments function that prefers UTF-8 when a UTF-16 85242 +** encoding is requested, or vice versa. 85243 +** 2: A variable arguments function that uses UTF-16BE when UTF-16LE is 85244 +** requested, or vice versa. 85245 +** 3: A variable arguments function using the same text encoding. 85246 +** 4: A function with the exact number of arguments requested that 85247 +** prefers UTF-8 when a UTF-16 encoding is requested, or vice versa. 85248 +** 5: A function with the exact number of arguments requested that 85249 +** prefers UTF-16LE when UTF-16BE is requested, or vice versa. 85250 +** 6: An exact match. 85251 +** 85252 +*/ 85253 +static int matchQuality(FuncDef *p, int nArg, u8 enc){ 85254 + int match = 0; 85255 + if( p->nArg==-1 || p->nArg==nArg 85256 + || (nArg==-1 && (p->xFunc!=0 || p->xStep!=0)) 85257 + ){ 85661 85258 match = 1; 85259 + if( p->nArg==nArg || nArg==-1 ){ 85260 + match = 4; 85261 + } 85262 + if( enc==p->iPrefEnc ){ 85263 + match += 2; 85264 + } 85265 + else if( (enc==SQLITE_UTF16LE && p->iPrefEnc==SQLITE_UTF16BE) || 85266 + (enc==SQLITE_UTF16BE && p->iPrefEnc==SQLITE_UTF16LE) ){ 85267 + match += 1; 85268 + } 85662 85269 } 85663 - 85664 - /* Bonus points if the text encoding matches */ 85665 - if( enc==p->iPrefEnc ){ 85666 - match += 2; /* Exact encoding match */ 85667 - }else if( (enc & p->iPrefEnc & 2)!=0 ){ 85668 - match += 1; /* Both are UTF16, but with different byte orders */ 85669 - } 85670 - 85671 85270 return match; 85672 85271 } 85673 85272 85674 85273 /* 85675 85274 ** Search a FuncDefHash for a function with the given name. Return 85676 85275 ** a pointer to the matching FuncDef if found, or 0 if there is no match. 85677 85276 */ ................................................................................ 85719 85318 ** Locate a user function given a name, a number of arguments and a flag 85720 85319 ** indicating whether the function prefers UTF-16 over UTF-8. Return a 85721 85320 ** pointer to the FuncDef structure that defines that function, or return 85722 85321 ** NULL if the function does not exist. 85723 85322 ** 85724 85323 ** If the createFlag argument is true, then a new (blank) FuncDef 85725 85324 ** structure is created and liked into the "db" structure if a 85726 -** no matching function previously existed. 85325 +** no matching function previously existed. When createFlag is true 85326 +** and the nArg parameter is -1, then only a function that accepts 85327 +** any number of arguments will be returned. 85727 85328 ** 85728 -** If nArg is -2, then the first valid function found is returned. A 85729 -** function is valid if either xFunc or xStep is non-zero. The nArg==(-2) 85730 -** case is used to see if zName is a valid function name for some number 85731 -** of arguments. If nArg is -2, then createFlag must be 0. 85329 +** If createFlag is false and nArg is -1, then the first valid 85330 +** function found is returned. A function is valid if either xFunc 85331 +** or xStep is non-zero. 85732 85332 ** 85733 85333 ** If createFlag is false, then a function with the required name and 85734 85334 ** number of arguments may be returned even if the eTextRep flag does not 85735 85335 ** match that requested. 85736 85336 */ 85737 85337 SQLITE_PRIVATE FuncDef *sqlite3FindFunction( 85738 85338 sqlite3 *db, /* An open database */ 85739 85339 const char *zName, /* Name of the function. Not null-terminated */ 85740 85340 int nName, /* Number of characters in the name */ 85741 85341 int nArg, /* Number of arguments. -1 means any number */ 85742 85342 u8 enc, /* Preferred text encoding */ 85743 - u8 createFlag /* Create new entry if true and does not otherwise exist */ 85343 + int createFlag /* Create new entry if true and does not otherwise exist */ 85744 85344 ){ 85745 85345 FuncDef *p; /* Iterator variable */ 85746 85346 FuncDef *pBest = 0; /* Best match found so far */ 85747 85347 int bestScore = 0; /* Score of best match */ 85748 85348 int h; /* Hash value */ 85749 85349 85750 - assert( nArg>=(-2) ); 85751 - assert( nArg>=(-1) || createFlag==0 ); 85350 + 85752 85351 assert( enc==SQLITE_UTF8 || enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE ); 85753 85352 h = (sqlite3UpperToLower[(u8)zName[0]] + nName) % ArraySize(db->aFunc.a); 85754 85353 85755 85354 /* First search for a match amongst the application-defined functions. 85756 85355 */ 85757 85356 p = functionSearch(&db->aFunc, h, zName, nName); 85758 85357 while( p ){ ................................................................................ 85790 85389 } 85791 85390 } 85792 85391 85793 85392 /* If the createFlag parameter is true and the search did not reveal an 85794 85393 ** exact match for the name, number of arguments and encoding, then add a 85795 85394 ** new entry to the hash table and return it. 85796 85395 */ 85797 - if( createFlag && bestScore<FUNC_PERFECT_MATCH && 85396 + if( createFlag && (bestScore<6 || pBest->nArg!=nArg) && 85798 85397 (pBest = sqlite3DbMallocZero(db, sizeof(*pBest)+nName+1))!=0 ){ 85799 85398 pBest->zName = (char *)&pBest[1]; 85800 85399 pBest->nArg = (u16)nArg; 85801 85400 pBest->iPrefEnc = enc; 85802 85401 memcpy(pBest->zName, zName, nName); 85803 85402 pBest->zName[nName] = 0; 85804 85403 sqlite3FuncDefInsert(&db->aFunc, pBest); ................................................................................ 86242 85841 /* Collect rowids of every row to be deleted. 86243 85842 */ 86244 85843 sqlite3VdbeAddOp2(v, OP_Null, 0, iRowSet); 86245 85844 pWInfo = sqlite3WhereBegin( 86246 85845 pParse, pTabList, pWhere, 0, 0, WHERE_DUPLICATES_OK 86247 85846 ); 86248 85847 if( pWInfo==0 ) goto delete_from_cleanup; 86249 - regRowid = sqlite3ExprCodeGetColumn(pParse, pTab, -1, iCur, iRowid, 0); 85848 + regRowid = sqlite3ExprCodeGetColumn(pParse, pTab, -1, iCur, iRowid); 86250 85849 sqlite3VdbeAddOp2(v, OP_RowSetAdd, iRowSet, regRowid); 86251 85850 if( db->flags & SQLITE_CountRows ){ 86252 85851 sqlite3VdbeAddOp2(v, OP_AddImm, memCnt, 1); 86253 85852 } 86254 85853 sqlite3WhereEnd(pWInfo); 86255 85854 86256 85855 /* Delete every item whose key was written to the list during the ................................................................................ 88062 87661 FUNCTION(trim, 2, 3, 0, trimFunc ), 88063 87662 FUNCTION(min, -1, 0, 1, minmaxFunc ), 88064 87663 FUNCTION(min, 0, 0, 1, 0 ), 88065 87664 AGGREGATE(min, 1, 0, 1, minmaxStep, minMaxFinalize ), 88066 87665 FUNCTION(max, -1, 1, 1, minmaxFunc ), 88067 87666 FUNCTION(max, 0, 1, 1, 0 ), 88068 87667 AGGREGATE(max, 1, 1, 1, minmaxStep, minMaxFinalize ), 88069 - FUNCTION2(typeof, 1, 0, 0, typeofFunc, SQLITE_FUNC_TYPEOF), 88070 - FUNCTION2(length, 1, 0, 0, lengthFunc, SQLITE_FUNC_LENGTH), 87668 + FUNCTION(typeof, 1, 0, 0, typeofFunc ), 87669 + FUNCTION(length, 1, 0, 0, lengthFunc ), 88071 87670 FUNCTION(substr, 2, 0, 0, substrFunc ), 88072 87671 FUNCTION(substr, 3, 0, 0, substrFunc ), 88073 87672 FUNCTION(abs, 1, 0, 0, absFunc ), 88074 87673 #ifndef SQLITE_OMIT_FLOATING_POINT 88075 87674 FUNCTION(round, 1, 0, 0, roundFunc ), 88076 87675 FUNCTION(round, 2, 0, 0, roundFunc ), 88077 87676 #endif 88078 87677 FUNCTION(upper, 1, 0, 0, upperFunc ), 88079 87678 FUNCTION(lower, 1, 0, 0, lowerFunc ), 88080 87679 FUNCTION(coalesce, 1, 0, 0, 0 ), 88081 87680 FUNCTION(coalesce, 0, 0, 0, 0 ), 88082 - FUNCTION2(coalesce, -1, 0, 0, ifnullFunc, SQLITE_FUNC_COALESCE), 87681 +/* FUNCTION(coalesce, -1, 0, 0, ifnullFunc ), */ 87682 + {-1,SQLITE_UTF8,SQLITE_FUNC_COALESCE,0,0,ifnullFunc,0,0,"coalesce",0,0}, 88083 87683 FUNCTION(hex, 1, 0, 0, hexFunc ), 88084 - FUNCTION2(ifnull, 2, 0, 0, ifnullFunc, SQLITE_FUNC_COALESCE), 87684 +/* FUNCTION(ifnull, 2, 0, 0, ifnullFunc ), */ 87685 + {2,SQLITE_UTF8,SQLITE_FUNC_COALESCE,0,0,ifnullFunc,0,0,"ifnull",0,0}, 88085 87686 FUNCTION(random, 0, 0, 0, randomFunc ), 88086 87687 FUNCTION(randomblob, 1, 0, 0, randomBlob ), 88087 87688 FUNCTION(nullif, 2, 0, 1, nullifFunc ), 88088 87689 FUNCTION(sqlite_version, 0, 0, 0, versionFunc ), 88089 87690 FUNCTION(sqlite_source_id, 0, 0, 0, sourceidFunc ), 88090 87691 FUNCTION(sqlite_log, 2, 0, 0, errlogFunc ), 88091 87692 #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS ................................................................................ 90514 90115 int nCol; /* Number of columns */ 90515 90116 int onError; /* Conflict resolution strategy */ 90516 90117 int j1; /* Addresss of jump instruction */ 90517 90118 int j2 = 0, j3; /* Addresses of jump instructions */ 90518 90119 int regData; /* Register containing first data column */ 90519 90120 int iCur; /* Table cursor number */ 90520 90121 Index *pIdx; /* Pointer to one of the indices */ 90521 - sqlite3 *db; /* Database connection */ 90522 90122 int seenReplace = 0; /* True if REPLACE is used to resolve INT PK conflict */ 90523 90123 int regOldRowid = (rowidChng && isUpdate) ? rowidChng : regRowid; 90524 90124 90525 - db = pParse->db; 90526 90125 v = sqlite3GetVdbe(pParse); 90527 90126 assert( v!=0 ); 90528 90127 assert( pTab->pSelect==0 ); /* This table is not a VIEW */ 90529 90128 nCol = pTab->nCol; 90530 90129 regData = regRowid + 1; 90531 90130 90532 90131 /* Test all NOT NULL constraints. ................................................................................ 90551 90150 case OE_Abort: 90552 90151 sqlite3MayAbort(pParse); 90553 90152 case OE_Rollback: 90554 90153 case OE_Fail: { 90555 90154 char *zMsg; 90556 90155 sqlite3VdbeAddOp3(v, OP_HaltIfNull, 90557 90156 SQLITE_CONSTRAINT, onError, regData+i); 90558 - zMsg = sqlite3MPrintf(db, "%s.%s may not be NULL", 90157 + zMsg = sqlite3MPrintf(pParse->db, "%s.%s may not be NULL", 90559 90158 pTab->zName, pTab->aCol[i].zName); 90560 90159 sqlite3VdbeChangeP4(v, -1, zMsg, P4_DYNAMIC); 90561 90160 break; 90562 90161 } 90563 90162 case OE_Ignore: { 90564 90163 sqlite3VdbeAddOp2(v, OP_IsNull, regData+i, ignoreDest); 90565 90164 break; ................................................................................ 90573 90172 } 90574 90173 } 90575 90174 } 90576 90175 90577 90176 /* Test all CHECK constraints 90578 90177 */ 90579 90178 #ifndef SQLITE_OMIT_CHECK 90580 - if( pTab->pCheck && (db->flags & SQLITE_IgnoreChecks)==0 ){ 90581 - ExprList *pCheck = pTab->pCheck; 90179 + if( pTab->pCheck && (pParse->db->flags & SQLITE_IgnoreChecks)==0 ){ 90180 + int allOk = sqlite3VdbeMakeLabel(v); 90582 90181 pParse->ckBase = regData; 90182 + sqlite3ExprIfTrue(pParse, pTab->pCheck, allOk, SQLITE_JUMPIFNULL); 90583 90183 onError = overrideError!=OE_Default ? overrideError : OE_Abort; 90584 - for(i=0; i<pCheck->nExpr; i++){ 90585 - int allOk = sqlite3VdbeMakeLabel(v); 90586 - sqlite3ExprIfTrue(pParse, pCheck->a[i].pExpr, allOk, SQLITE_JUMPIFNULL); 90587 - if( onError==OE_Ignore ){ 90588 - sqlite3VdbeAddOp2(v, OP_Goto, 0, ignoreDest); 90589 - }else{ 90590 - char *zConsName = pCheck->a[i].zName; 90591 - if( onError==OE_Replace ) onError = OE_Abort; /* IMP: R-15569-63625 */ 90592 - if( zConsName ){ 90593 - zConsName = sqlite3MPrintf(db, "constraint %s failed", zConsName); 90594 - }else{ 90595 - zConsName = 0; 90596 - } 90597 - sqlite3HaltConstraint(pParse, onError, zConsName, P4_DYNAMIC); 90598 - } 90599 - sqlite3VdbeResolveLabel(v, allOk); 90184 + if( onError==OE_Ignore ){ 90185 + sqlite3VdbeAddOp2(v, OP_Goto, 0, ignoreDest); 90186 + }else{ 90187 + if( onError==OE_Replace ) onError = OE_Abort; /* IMP: R-15569-63625 */ 90188 + sqlite3HaltConstraint(pParse, onError, 0, 0); 90600 90189 } 90190 + sqlite3VdbeResolveLabel(v, allOk); 90601 90191 } 90602 90192 #endif /* !defined(SQLITE_OMIT_CHECK) */ 90603 90193 90604 90194 /* If we have an INTEGER PRIMARY KEY, make sure the primary key 90605 90195 ** of the new record does not previously exist. Except, if this 90606 90196 ** is an UPDATE and the primary key is not changing, that is OK. 90607 90197 */ ................................................................................ 90649 90239 ** 90650 90240 ** REPLACE INTO t(rowid) VALUES($newrowid) 90651 90241 ** 90652 90242 ** to run without a statement journal if there are no indexes on the 90653 90243 ** table. 90654 90244 */ 90655 90245 Trigger *pTrigger = 0; 90656 - if( db->flags&SQLITE_RecTriggers ){ 90246 + if( pParse->db->flags&SQLITE_RecTriggers ){ 90657 90247 pTrigger = sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0, 0); 90658 90248 } 90659 90249 if( pTrigger || sqlite3FkRequired(pParse, pTab, 0, 0) ){ 90660 90250 sqlite3MultiWrite(pParse); 90661 90251 sqlite3GenerateRowDelete( 90662 90252 pParse, pTab, baseCur, regRowid, 0, pTrigger, OE_Replace 90663 90253 ); ................................................................................ 90738 90328 case OE_Fail: { 90739 90329 int j; 90740 90330 StrAccum errMsg; 90741 90331 const char *zSep; 90742 90332 char *zErr; 90743 90333 90744 90334 sqlite3StrAccumInit(&errMsg, 0, 0, 200); 90745 - errMsg.db = db; 90335 + errMsg.db = pParse->db; 90746 90336 zSep = pIdx->nColumn>1 ? "columns " : "column "; 90747 90337 for(j=0; j<pIdx->nColumn; j++){ 90748 90338 char *zCol = pTab->aCol[pIdx->aiColumn[j]].zName; 90749 90339 sqlite3StrAccumAppend(&errMsg, zSep, -1); 90750 90340 zSep = ", "; 90751 90341 sqlite3StrAccumAppend(&errMsg, zCol, -1); 90752 90342 } ................................................................................ 90762 90352 sqlite3VdbeAddOp2(v, OP_Goto, 0, ignoreDest); 90763 90353 break; 90764 90354 } 90765 90355 default: { 90766 90356 Trigger *pTrigger = 0; 90767 90357 assert( onError==OE_Replace ); 90768 90358 sqlite3MultiWrite(pParse); 90769 - if( db->flags&SQLITE_RecTriggers ){ 90359 + if( pParse->db->flags&SQLITE_RecTriggers ){ 90770 90360 pTrigger = sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0, 0); 90771 90361 } 90772 90362 sqlite3GenerateRowDelete( 90773 90363 pParse, pTab, baseCur, regR, 0, pTrigger, OE_Replace 90774 90364 ); 90775 90365 seenReplace = 1; 90776 90366 break; ................................................................................ 91092 90682 if( xferCompatibleIndex(pDestIdx, pSrcIdx) ) break; 91093 90683 } 91094 90684 if( pSrcIdx==0 ){ 91095 90685 return 0; /* pDestIdx has no corresponding index in pSrc */ 91096 90686 } 91097 90687 } 91098 90688 #ifndef SQLITE_OMIT_CHECK 91099 - if( pDest->pCheck && sqlite3ExprListCompare(pSrc->pCheck, pDest->pCheck) ){ 90689 + if( pDest->pCheck && sqlite3ExprCompare(pSrc->pCheck, pDest->pCheck) ){ 91100 90690 return 0; /* Tables have different CHECK constraints. Ticket #2252 */ 91101 90691 } 91102 90692 #endif 91103 90693 #ifndef SQLITE_OMIT_FOREIGN_KEY 91104 90694 /* Disallow the transfer optimization if the destination table constains 91105 90695 ** any foreign key constraints. This is more restrictive than necessary. 91106 90696 ** But the main beneficiary of the transfer optimization is the VACUUM ................................................................................ 96165 95755 int cnt; /* Index added to make the name unique */ 96166 95756 Column *aCol, *pCol; /* For looping over result columns */ 96167 95757 int nCol; /* Number of columns in the result set */ 96168 95758 Expr *p; /* Expression for a single result column */ 96169 95759 char *zName; /* Column name */ 96170 95760 int nName; /* Size of name in zName[] */ 96171 95761 96172 - if( pEList ){ 96173 - nCol = pEList->nExpr; 96174 - aCol = sqlite3DbMallocZero(db, sizeof(aCol[0])*nCol); 96175 - testcase( aCol==0 ); 96176 - }else{ 96177 - nCol = 0; 96178 - aCol = 0; 96179 - } 96180 - *pnCol = nCol; 96181 - *paCol = aCol; 96182 - 95762 + *pnCol = nCol = pEList ? pEList->nExpr : 0; 95763 + aCol = *paCol = sqlite3DbMallocZero(db, sizeof(aCol[0])*nCol); 95764 + if( aCol==0 ) return SQLITE_NOMEM; 96183 95765 for(i=0, pCol=aCol; i<nCol; i++, pCol++){ 96184 95766 /* Get an appropriate name for the column 96185 95767 */ 96186 95768 p = pEList->a[i].pExpr; 96187 95769 assert( p->pRight==0 || ExprHasProperty(p->pRight, EP_IntValue) 96188 95770 || p->pRight->u.zToken==0 || p->pRight->u.zToken[0]!=0 ); 96189 95771 if( (zName = pEList->a[i].zName)!=0 ){ ................................................................................ 97758 97340 } 97759 97341 } 97760 97342 97761 97343 /***** If we reach this point, flattening is permitted. *****/ 97762 97344 97763 97345 /* Authorize the subquery */ 97764 97346 pParse->zAuthContext = pSubitem->zName; 97765 - TESTONLY(i =) sqlite3AuthCheck(pParse, SQLITE_SELECT, 0, 0, 0); 97766 - testcase( i==SQLITE_DENY ); 97347 + sqlite3AuthCheck(pParse, SQLITE_SELECT, 0, 0, 0); 97767 97348 pParse->zAuthContext = zSavedAuthContext; 97768 97349 97769 97350 /* If the sub-query is a compound SELECT statement, then (by restrictions 97770 97351 ** 17 and 18 above) it must be a UNION ALL and the parent query must 97771 97352 ** be of the form: 97772 97353 ** 97773 97354 ** SELECT <expr-list> FROM (<sub-query>) <where-clause> ................................................................................ 99144 98725 for(i=0; i<sAggInfo.nColumn; i++){ 99145 98726 struct AggInfo_col *pCol = &sAggInfo.aCol[i]; 99146 98727 if( pCol->iSorterColumn>=j ){ 99147 98728 int r1 = j + regBase; 99148 98729 int r2; 99149 98730 99150 98731 r2 = sqlite3ExprCodeGetColumn(pParse, 99151 - pCol->pTab, pCol->iColumn, pCol->iTable, r1, 0); 98732 + pCol->pTab, pCol->iColumn, pCol->iTable, r1); 99152 98733 if( r1!=r2 ){ 99153 98734 sqlite3VdbeAddOp2(v, OP_SCopy, r2, r1); 99154 98735 } 99155 98736 j++; 99156 98737 } 99157 98738 } 99158 98739 regRecord = sqlite3GetTempReg(pParse); ................................................................................ 102325 101906 static int vtabCallConstructor( 102326 101907 sqlite3 *db, 102327 101908 Table *pTab, 102328 101909 Module *pMod, 102329 101910 int (*xConstruct)(sqlite3*,void*,int,const char*const*,sqlite3_vtab**,char**), 102330 101911 char **pzErr 102331 101912 ){ 102332 - VtabCtx sCtx, *pPriorCtx; 101913 + VtabCtx sCtx; 102333 101914 VTable *pVTable; 102334 101915 int rc; 102335 101916 const char *const*azArg = (const char *const*)pTab->azModuleArg; 102336 101917 int nArg = pTab->nModuleArg; 102337 101918 char *zErr = 0; 102338 101919 char *zModuleName = sqlite3MPrintf(db, "%s", pTab->zName); 102339 101920 ................................................................................ 102350 101931 pVTable->pMod = pMod; 102351 101932 102352 101933 /* Invoke the virtual table constructor */ 102353 101934 assert( &db->pVtabCtx ); 102354 101935 assert( xConstruct ); 102355 101936 sCtx.pTab = pTab; 102356 101937 sCtx.pVTable = pVTable; 102357 - pPriorCtx = db->pVtabCtx; 102358 101938 db->pVtabCtx = &sCtx; 102359 101939 rc = xConstruct(db, pMod->pAux, nArg, azArg, &pVTable->pVtab, &zErr); 102360 - db->pVtabCtx = pPriorCtx; 101940 + db->pVtabCtx = 0; 102361 101941 if( rc==SQLITE_NOMEM ) db->mallocFailed = 1; 102362 101942 102363 101943 if( SQLITE_OK!=rc ){ 102364 101944 if( zErr==0 ){ 102365 101945 *pzErr = sqlite3MPrintf(db, "vtable constructor failed: %s", zModuleName); 102366 101946 }else { 102367 101947 *pzErr = sqlite3MPrintf(db, "%s", zErr); ................................................................................ 103634 103214 return 0; 103635 103215 } 103636 103216 #ifdef SQLITE_EBCDIC 103637 103217 if( *pnoCase ) return 0; 103638 103218 #endif 103639 103219 pList = pExpr->x.pList; 103640 103220 pLeft = pList->a[1].pExpr; 103641 - if( pLeft->op!=TK_COLUMN 103642 - || sqlite3ExprAffinity(pLeft)!=SQLITE_AFF_TEXT 103643 - || IsVirtual(pLeft->pTab) 103644 - ){ 103221 + if( pLeft->op!=TK_COLUMN || sqlite3ExprAffinity(pLeft)!=SQLITE_AFF_TEXT ){ 103645 103222 /* IMP: R-02065-49465 The left-hand side of the LIKE or GLOB operator must 103646 103223 ** be the name of an indexed column with TEXT affinity. */ 103647 103224 return 0; 103648 103225 } 103649 103226 assert( pLeft->iColumn!=(-1) ); /* Because IPK never has AFF_TEXT */ 103650 103227 103651 103228 pRight = pList->a[0].pExpr; ................................................................................ 104510 104087 ** 104511 104088 ** 1. The index is itself UNIQUE, and 104512 104089 ** 104513 104090 ** 2. All of the columns in the index are either part of the pDistinct 104514 104091 ** list, or else the WHERE clause contains a term of the form "col=X", 104515 104092 ** where X is a constant value. The collation sequences of the 104516 104093 ** comparison and select-list expressions must match those of the index. 104517 - ** 104518 - ** 3. All of those index columns for which the WHERE clause does not 104519 - ** contain a "col=X" term are subject to a NOT NULL constraint. 104520 104094 */ 104521 104095 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ 104522 104096 if( pIdx->onError==OE_None ) continue; 104523 104097 for(i=0; i<pIdx->nColumn; i++){ 104524 104098 int iCol = pIdx->aiColumn[i]; 104525 - if( 0==findTerm(pWC, iBase, iCol, ~(Bitmask)0, WO_EQ, pIdx) ){ 104526 - int iIdxCol = findIndexCol(pParse, pDistinct, iBase, pIdx, i); 104527 - if( iIdxCol<0 || pTab->aCol[pIdx->aiColumn[i]].notNull==0 ){ 104528 - break; 104529 - } 104099 + if( 0==findTerm(pWC, iBase, iCol, ~(Bitmask)0, WO_EQ, pIdx) 104100 + && 0>findIndexCol(pParse, pDistinct, iBase, pIdx, i) 104101 + ){ 104102 + break; 104530 104103 } 104531 104104 } 104532 104105 if( i==pIdx->nColumn ){ 104533 104106 /* This index implies that the DISTINCT qualifier is redundant. */ 104534 104107 return 1; 104535 104108 } 104536 104109 } ................................................................................ 104670 104243 if( j>=nTerm ){ 104671 104244 /* All terms of the ORDER BY clause are covered by this index so 104672 104245 ** this index can be used for sorting. */ 104673 104246 return 1; 104674 104247 } 104675 104248 if( pIdx->onError!=OE_None && i==pIdx->nColumn 104676 104249 && (wsFlags & WHERE_COLUMN_NULL)==0 104677 - && !referencesOtherTables(pOrderBy, pMaskSet, j, base) 104678 - ){ 104679 - Column *aCol = pIdx->pTable->aCol; 104680 - 104681 - /* All terms of this index match some prefix of the ORDER BY clause, 104682 - ** the index is UNIQUE, and no terms on the tail of the ORDER BY 104683 - ** refer to other tables in a join. So, assuming that the index entries 104684 - ** visited contain no NULL values, then this index delivers rows in 104685 - ** the required order. 104686 - ** 104687 - ** It is not possible for any of the first nEqCol index fields to be 104688 - ** NULL (since the corresponding "=" operator in the WHERE clause would 104689 - ** not be true). So if all remaining index columns have NOT NULL 104690 - ** constaints attached to them, we can be confident that the visited 104691 - ** index entries are free of NULLs. */ 104692 - for(i=nEqCol; i<pIdx->nColumn; i++){ 104693 - if( aCol[pIdx->aiColumn[i]].notNull==0 ) break; 104694 - } 104695 - return (i==pIdx->nColumn); 104250 + && !referencesOtherTables(pOrderBy, pMaskSet, j, base) ){ 104251 + /* All terms of this index match some prefix of the ORDER BY clause 104252 + ** and the index is UNIQUE and no terms on the tail of the ORDER BY 104253 + ** clause reference other tables in a join. If this is all true then 104254 + ** the order by clause is superfluous. Not that if the matching 104255 + ** condition is IS NULL then the result is not necessarily unique 104256 + ** even on a UNIQUE index, so disallow those cases. */ 104257 + return 1; 104696 104258 } 104697 104259 return 0; 104698 104260 } 104699 104261 104700 104262 /* 104701 104263 ** Prepare a crude estimate of the logarithm of the input value. 104702 104264 ** The results need not be exact. This is only used for estimating ................................................................................ 107349 106911 explainOneScan( 107350 106912 pParse, pOrTab, &pSubWInfo->a[0], iLevel, pLevel->iFrom, 0 107351 106913 ); 107352 106914 if( (wctrlFlags & WHERE_DUPLICATES_OK)==0 ){ 107353 106915 int iSet = ((ii==pOrWc->nTerm-1)?-1:ii); 107354 106916 int r; 107355 106917 r = sqlite3ExprCodeGetColumn(pParse, pTabItem->pTab, -1, iCur, 107356 - regRowid, 0); 106918 + regRowid); 107357 106919 sqlite3VdbeAddOp4Int(v, OP_RowSetTest, regRowset, 107358 106920 sqlite3VdbeCurrentAddr(v)+2, r, iSet); 107359 106921 } 107360 106922 sqlite3VdbeAddOp2(v, OP_Gosub, regReturn, iLoopBody); 107361 106923 107362 106924 /* The pSubWInfo->untestedTerms flag means that this OR term 107363 106925 ** contained one or more AND term from a notReady table. The ................................................................................ 108262 107824 108263 107825 /* 108264 107826 ** An instance of this structure is used to store the LIKE, 108265 107827 ** GLOB, NOT LIKE, and NOT GLOB operators. 108266 107828 */ 108267 107829 struct LikeOp { 108268 107830 Token eOperator; /* "like" or "glob" or "regexp" */ 108269 - int bNot; /* True if the NOT keyword is present */ 107831 + int not; /* True if the NOT keyword is present */ 108270 107832 }; 108271 107833 108272 107834 /* 108273 107835 ** An instance of the following structure describes the event of a 108274 107836 ** TRIGGER. "a" is the event type, one of TK_UPDATE, TK_INSERT, 108275 107837 ** TK_DELETE, or TK_INSTEAD. If the event is of the form 108276 107838 ** ................................................................................ 108441 108003 #ifndef YYSTACKDEPTH 108442 108004 #define YYSTACKDEPTH 100 108443 108005 #endif 108444 108006 #define sqlite3ParserARG_SDECL Parse *pParse; 108445 108007 #define sqlite3ParserARG_PDECL ,Parse *pParse 108446 108008 #define sqlite3ParserARG_FETCH Parse *pParse = yypParser->pParse 108447 108009 #define sqlite3ParserARG_STORE yypParser->pParse = pParse 108448 -#define YYNSTATE 627 108010 +#define YYNSTATE 629 108449 108011 #define YYNRULE 327 108450 108012 #define YYFALLBACK 1 108451 108013 #define YY_NO_ACTION (YYNSTATE+YYNRULE+2) 108452 108014 #define YY_ACCEPT_ACTION (YYNSTATE+YYNRULE+1) 108453 108015 #define YY_ERROR_ACTION (YYNSTATE+YYNRULE) 108454 108016 108455 108017 /* The yyzerominor constant is used to initialize instances of ................................................................................ 108512 108074 ** yy_action. Used to detect hash collisions. 108513 108075 ** yy_shift_ofst[] For each state, the offset into yy_action for 108514 108076 ** shifting terminals. 108515 108077 ** yy_reduce_ofst[] For each state, the offset into yy_action for 108516 108078 ** shifting non-terminals after a reduce. 108517 108079 ** yy_default[] Default action for each state. 108518 108080 */ 108519 -#define YY_ACTTAB_COUNT (1564) 108081 +#define YY_ACTTAB_COUNT (1580) 108520 108082 static const YYACTIONTYPE yy_action[] = { 108521 - /* 0 */ 309, 955, 184, 417, 2, 171, 624, 594, 56, 56, 108083 + /* 0 */ 310, 328, 574, 573, 15, 172, 187, 596, 56, 56, 108522 108084 /* 10 */ 56, 56, 49, 54, 54, 54, 54, 53, 53, 52, 108523 - /* 20 */ 52, 52, 51, 233, 620, 619, 298, 620, 619, 234, 108524 - /* 30 */ 587, 581, 56, 56, 56, 56, 19, 54, 54, 54, 108525 - /* 40 */ 54, 53, 53, 52, 52, 52, 51, 233, 605, 57, 108526 - /* 50 */ 58, 48, 579, 578, 580, 580, 55, 55, 56, 56, 108527 - /* 60 */ 56, 56, 541, 54, 54, 54, 54, 53, 53, 52, 108528 - /* 70 */ 52, 52, 51, 233, 309, 594, 325, 196, 195, 194, 108085 + /* 20 */ 52, 52, 51, 234, 622, 621, 626, 622, 621, 299, 108086 + /* 30 */ 589, 583, 56, 56, 56, 56, 236, 54, 54, 54, 108087 + /* 40 */ 54, 53, 53, 52, 52, 52, 51, 234, 351, 57, 108088 + /* 50 */ 58, 48, 581, 580, 582, 582, 55, 55, 56, 56, 108089 + /* 60 */ 56, 56, 570, 54, 54, 54, 54, 53, 53, 52, 108090 + /* 70 */ 52, 52, 51, 234, 310, 596, 326, 607, 233, 232, 108529 108091 /* 80 */ 33, 54, 54, 54, 54, 53, 53, 52, 52, 52, 108530 - /* 90 */ 51, 233, 617, 616, 165, 617, 616, 380, 377, 376, 108531 - /* 100 */ 407, 532, 576, 576, 587, 581, 303, 422, 375, 59, 108532 - /* 110 */ 53, 53, 52, 52, 52, 51, 233, 50, 47, 146, 108533 - /* 120 */ 574, 545, 65, 57, 58, 48, 579, 578, 580, 580, 108534 - /* 130 */ 55, 55, 56, 56, 56, 56, 213, 54, 54, 54, 108535 - /* 140 */ 54, 53, 53, 52, 52, 52, 51, 233, 309, 223, 108536 - /* 150 */ 539, 420, 170, 176, 138, 280, 383, 275, 382, 168, 108537 - /* 160 */ 489, 551, 409, 668, 620, 619, 271, 438, 409, 438, 108538 - /* 170 */ 550, 604, 67, 482, 507, 618, 599, 412, 587, 581, 108539 - /* 180 */ 600, 483, 618, 412, 618, 598, 91, 439, 440, 439, 108540 - /* 190 */ 335, 598, 73, 669, 222, 266, 480, 57, 58, 48, 108541 - /* 200 */ 579, 578, 580, 580, 55, 55, 56, 56, 56, 56, 108542 - /* 210 */ 670, 54, 54, 54, 54, 53, 53, 52, 52, 52, 108543 - /* 220 */ 51, 233, 309, 279, 232, 231, 1, 132, 200, 385, 108544 - /* 230 */ 620, 619, 617, 616, 278, 435, 289, 563, 175, 262, 108545 - /* 240 */ 409, 264, 437, 497, 436, 166, 441, 568, 336, 568, 108546 - /* 250 */ 201, 537, 587, 581, 599, 412, 165, 594, 600, 380, 108547 - /* 260 */ 377, 376, 597, 598, 92, 523, 618, 569, 569, 592, 108548 - /* 270 */ 375, 57, 58, 48, 579, 578, 580, 580, 55, 55, 108549 - /* 280 */ 56, 56, 56, 56, 597, 54, 54, 54, 54, 53, 108550 - /* 290 */ 53, 52, 52, 52, 51, 233, 309, 463, 617, 616, 108551 - /* 300 */ 590, 590, 590, 174, 272, 396, 409, 272, 409, 548, 108552 - /* 310 */ 397, 620, 619, 68, 326, 620, 619, 620, 619, 618, 108553 - /* 320 */ 546, 412, 618, 412, 471, 594, 587, 581, 472, 598, 108554 - /* 330 */ 92, 598, 92, 52, 52, 52, 51, 233, 513, 512, 108555 - /* 340 */ 206, 322, 363, 464, 221, 57, 58, 48, 579, 578, 108556 - /* 350 */ 580, 580, 55, 55, 56, 56, 56, 56, 529, 54, 108557 - /* 360 */ 54, 54, 54, 53, 53, 52, 52, 52, 51, 233, 108558 - /* 370 */ 309, 396, 409, 396, 597, 372, 386, 530, 347, 617, 108559 - /* 380 */ 616, 575, 202, 617, 616, 617, 616, 412, 620, 619, 108560 - /* 390 */ 145, 255, 346, 254, 577, 598, 74, 351, 45, 489, 108561 - /* 400 */ 587, 581, 235, 189, 464, 544, 167, 296, 187, 469, 108562 - /* 410 */ 479, 67, 62, 39, 618, 546, 597, 345, 573, 57, 108563 - /* 420 */ 58, 48, 579, 578, 580, 580, 55, 55, 56, 56, 108564 - /* 430 */ 56, 56, 6, 54, 54, 54, 54, 53, 53, 52, 108565 - /* 440 */ 52, 52, 51, 233, 309, 562, 558, 407, 528, 576, 108566 - /* 450 */ 576, 344, 255, 346, 254, 182, 617, 616, 503, 504, 108567 - /* 460 */ 314, 409, 557, 235, 166, 271, 409, 352, 564, 181, 108568 - /* 470 */ 407, 546, 576, 576, 587, 581, 412, 537, 556, 561, 108569 - /* 480 */ 517, 412, 618, 249, 598, 16, 7, 36, 467, 598, 108570 - /* 490 */ 92, 516, 618, 57, 58, 48, 579, 578, 580, 580, 108571 - /* 500 */ 55, 55, 56, 56, 56, 56, 541, 54, 54, 54, 108572 - /* 510 */ 54, 53, 53, 52, 52, 52, 51, 233, 309, 327, 108573 - /* 520 */ 572, 571, 525, 558, 560, 394, 871, 246, 409, 248, 108574 - /* 530 */ 171, 392, 594, 219, 407, 409, 576, 576, 502, 557, 108575 - /* 540 */ 364, 145, 510, 412, 407, 229, 576, 576, 587, 581, 108576 - /* 550 */ 412, 598, 92, 381, 269, 556, 166, 400, 598, 69, 108577 - /* 560 */ 501, 419, 945, 199, 945, 198, 546, 57, 58, 48, 108578 - /* 570 */ 579, 578, 580, 580, 55, 55, 56, 56, 56, 56, 108579 - /* 580 */ 568, 54, 54, 54, 54, 53, 53, 52, 52, 52, 108580 - /* 590 */ 51, 233, 309, 317, 419, 944, 508, 944, 308, 597, 108581 - /* 600 */ 594, 565, 490, 212, 173, 247, 423, 615, 614, 613, 108582 - /* 610 */ 323, 197, 143, 405, 572, 571, 489, 66, 50, 47, 108583 - /* 620 */ 146, 594, 587, 581, 232, 231, 559, 427, 67, 555, 108584 - /* 630 */ 15, 618, 186, 543, 303, 421, 35, 206, 432, 423, 108585 - /* 640 */ 552, 57, 58, 48, 579, 578, 580, 580, 55, 55, 108586 - /* 650 */ 56, 56, 56, 56, 205, 54, 54, 54, 54, 53, 108587 - /* 660 */ 53, 52, 52, 52, 51, 233, 309, 569, 569, 260, 108588 - /* 670 */ 268, 597, 12, 373, 568, 166, 409, 313, 409, 420, 108589 - /* 680 */ 409, 473, 473, 365, 618, 50, 47, 146, 597, 594, 108590 - /* 690 */ 468, 412, 166, 412, 351, 412, 587, 581, 32, 598, 108591 - /* 700 */ 94, 598, 97, 598, 95, 627, 625, 329, 142, 50, 108592 - /* 710 */ 47, 146, 333, 349, 358, 57, 58, 48, 579, 578, 108593 - /* 720 */ 580, 580, 55, 55, 56, 56, 56, 56, 409, 54, 108594 - /* 730 */ 54, 54, 54, 53, 53, 52, 52, 52, 51, 233, 108595 - /* 740 */ 309, 409, 388, 412, 409, 22, 565, 404, 212, 362, 108596 - /* 750 */ 389, 598, 104, 359, 409, 156, 412, 409, 603, 412, 108597 - /* 760 */ 537, 331, 569, 569, 598, 103, 493, 598, 105, 412, 108598 - /* 770 */ 587, 581, 412, 260, 549, 618, 11, 598, 106, 521, 108599 - /* 780 */ 598, 133, 169, 457, 456, 170, 35, 601, 618, 57, 108600 - /* 790 */ 58, 48, 579, 578, 580, 580, 55, 55, 56, 56, 108601 - /* 800 */ 56, 56, 409, 54, 54, 54, 54, 53, 53, 52, 108602 - /* 810 */ 52, 52, 51, 233, 309, 409, 259, 412, 409, 50, 108603 - /* 820 */ 47, 146, 357, 318, 355, 598, 134, 527, 352, 337, 108604 - /* 830 */ 412, 409, 356, 412, 357, 409, 357, 618, 598, 98, 108605 - /* 840 */ 129, 598, 102, 618, 587, 581, 412, 21, 235, 618, 108606 - /* 850 */ 412, 618, 211, 143, 598, 101, 30, 167, 598, 93, 108607 - /* 860 */ 350, 535, 203, 57, 58, 48, 579, 578, 580, 580, 108608 - /* 870 */ 55, 55, 56, 56, 56, 56, 409, 54, 54, 54, 108609 - /* 880 */ 54, 53, 53, 52, 52, 52, 51, 233, 309, 409, 108610 - /* 890 */ 526, 412, 409, 425, 215, 305, 597, 551, 141, 598, 108611 - /* 900 */ 100, 40, 409, 38, 412, 409, 550, 412, 409, 228, 108612 - /* 910 */ 220, 314, 598, 77, 500, 598, 96, 412, 587, 581, 108613 - /* 920 */ 412, 338, 253, 412, 218, 598, 137, 379, 598, 136, 108614 - /* 930 */ 28, 598, 135, 270, 715, 210, 481, 57, 58, 48, 108615 - /* 940 */ 579, 578, 580, 580, 55, 55, 56, 56, 56, 56, 108616 - /* 950 */ 409, 54, 54, 54, 54, 53, 53, 52, 52, 52, 108617 - /* 960 */ 51, 233, 309, 409, 272, 412, 409, 315, 147, 597, 108618 - /* 970 */ 272, 626, 2, 598, 76, 209, 409, 127, 412, 618, 108619 - /* 980 */ 126, 412, 409, 621, 235, 618, 598, 90, 374, 598, 108620 - /* 990 */ 89, 412, 587, 581, 27, 260, 350, 412, 618, 598, 108621 - /* 1000 */ 75, 321, 541, 541, 125, 598, 88, 320, 278, 597, 108622 - /* 1010 */ 618, 57, 46, 48, 579, 578, 580, 580, 55, 55, 108623 - /* 1020 */ 56, 56, 56, 56, 409, 54, 54, 54, 54, 53, 108624 - /* 1030 */ 53, 52, 52, 52, 51, 233, 309, 409, 450, 412, 108625 - /* 1040 */ 164, 284, 282, 272, 609, 424, 304, 598, 87, 370, 108626 - /* 1050 */ 409, 477, 412, 409, 608, 409, 607, 602, 618, 618, 108627 - /* 1060 */ 598, 99, 586, 585, 122, 412, 587, 581, 412, 618, 108628 - /* 1070 */ 412, 618, 618, 598, 86, 366, 598, 17, 598, 85, 108629 - /* 1080 */ 319, 185, 519, 518, 583, 582, 58, 48, 579, 578, 108630 - /* 1090 */ 580, 580, 55, 55, 56, 56, 56, 56, 409, 54, 108631 - /* 1100 */ 54, 54, 54, 53, 53, 52, 52, 52, 51, 233, 108632 - /* 1110 */ 309, 584, 409, 412, 409, 260, 260, 260, 408, 591, 108633 - /* 1120 */ 474, 598, 84, 170, 409, 466, 518, 412, 121, 412, 108634 - /* 1130 */ 618, 618, 618, 618, 618, 598, 83, 598, 72, 412, 108635 - /* 1140 */ 587, 581, 51, 233, 625, 329, 470, 598, 71, 257, 108636 - /* 1150 */ 159, 120, 14, 462, 157, 158, 117, 260, 448, 447, 108637 - /* 1160 */ 446, 48, 579, 578, 580, 580, 55, 55, 56, 56, 108638 - /* 1170 */ 56, 56, 618, 54, 54, 54, 54, 53, 53, 52, 108639 - /* 1180 */ 52, 52, 51, 233, 44, 403, 260, 3, 409, 459, 108640 - /* 1190 */ 260, 413, 619, 118, 398, 10, 25, 24, 554, 348, 108641 - /* 1200 */ 217, 618, 406, 412, 409, 618, 4, 44, 403, 618, 108642 - /* 1210 */ 3, 598, 82, 618, 413, 619, 455, 542, 115, 412, 108643 - /* 1220 */ 538, 401, 536, 274, 506, 406, 251, 598, 81, 216, 108644 - /* 1230 */ 273, 563, 618, 243, 453, 618, 154, 618, 618, 618, 108645 - /* 1240 */ 449, 416, 623, 110, 401, 618, 409, 236, 64, 123, 108646 - /* 1250 */ 487, 41, 42, 531, 563, 204, 409, 267, 43, 411, 108647 - /* 1260 */ 410, 412, 265, 592, 108, 618, 107, 434, 332, 598, 108648 - /* 1270 */ 80, 412, 618, 263, 41, 42, 443, 618, 409, 598, 108649 - /* 1280 */ 70, 43, 411, 410, 433, 261, 592, 149, 618, 597, 108650 - /* 1290 */ 256, 237, 188, 412, 590, 590, 590, 589, 588, 13, 108651 - /* 1300 */ 618, 598, 18, 328, 235, 618, 44, 403, 360, 3, 108652 - /* 1310 */ 418, 461, 339, 413, 619, 227, 124, 590, 590, 590, 108653 - /* 1320 */ 589, 588, 13, 618, 406, 409, 618, 409, 139, 34, 108654 - /* 1330 */ 403, 387, 3, 148, 622, 312, 413, 619, 311, 330, 108655 - /* 1340 */ 412, 460, 412, 401, 180, 353, 412, 406, 598, 79, 108656 - /* 1350 */ 598, 78, 250, 563, 598, 9, 618, 612, 611, 610, 108657 - /* 1360 */ 618, 8, 452, 442, 242, 415, 401, 618, 239, 235, 108658 - /* 1370 */ 179, 238, 428, 41, 42, 288, 563, 618, 618, 618, 108659 - /* 1380 */ 43, 411, 410, 618, 144, 592, 618, 618, 177, 61, 108660 - /* 1390 */ 618, 596, 391, 620, 619, 287, 41, 42, 414, 618, 108661 - /* 1400 */ 293, 30, 393, 43, 411, 410, 292, 618, 592, 31, 108662 - /* 1410 */ 618, 395, 291, 60, 230, 37, 590, 590, 590, 589, 108663 - /* 1420 */ 588, 13, 214, 553, 183, 290, 172, 301, 300, 299, 108664 - /* 1430 */ 178, 297, 595, 563, 451, 29, 285, 390, 540, 590, 108665 - /* 1440 */ 590, 590, 589, 588, 13, 283, 520, 534, 150, 533, 108666 - /* 1450 */ 241, 281, 384, 192, 191, 324, 515, 514, 276, 240, 108667 - /* 1460 */ 510, 523, 307, 511, 128, 592, 509, 225, 226, 486, 108668 - /* 1470 */ 485, 224, 152, 491, 464, 306, 484, 163, 153, 371, 108669 - /* 1480 */ 478, 151, 162, 258, 369, 161, 367, 208, 475, 476, 108670 - /* 1490 */ 26, 160, 465, 140, 361, 131, 590, 590, 590, 116, 108671 - /* 1500 */ 119, 454, 343, 155, 114, 342, 113, 112, 445, 111, 108672 - /* 1510 */ 130, 109, 431, 316, 426, 430, 23, 429, 20, 606, 108673 - /* 1520 */ 190, 507, 255, 341, 244, 63, 294, 593, 310, 570, 108674 - /* 1530 */ 277, 402, 354, 235, 567, 496, 495, 492, 494, 302, 108675 - /* 1540 */ 458, 378, 286, 245, 566, 5, 252, 547, 193, 444, 108676 - /* 1550 */ 233, 340, 207, 524, 368, 505, 334, 522, 499, 399, 108677 - /* 1560 */ 295, 498, 956, 488, 108092 + /* 90 */ 51, 234, 619, 618, 326, 619, 618, 166, 605, 492, 108093 + /* 100 */ 381, 378, 377, 235, 589, 583, 554, 495, 1, 59, 108094 + /* 110 */ 19, 376, 622, 621, 53, 53, 52, 52, 52, 51, 108095 + /* 120 */ 234, 571, 571, 57, 58, 48, 581, 580, 582, 582, 108096 + /* 130 */ 55, 55, 56, 56, 56, 56, 215, 54, 54, 54, 108097 + /* 140 */ 54, 53, 53, 52, 52, 52, 51, 234, 310, 224, 108098 + /* 150 */ 50, 47, 147, 177, 139, 281, 384, 276, 383, 169, 108099 + /* 160 */ 408, 553, 578, 578, 622, 621, 272, 224, 439, 550, 108100 + /* 170 */ 552, 410, 139, 281, 384, 276, 383, 169, 589, 583, 108101 + /* 180 */ 619, 618, 280, 620, 272, 195, 413, 309, 440, 441, 108102 + /* 190 */ 567, 491, 214, 279, 560, 600, 92, 57, 58, 48, 108103 + /* 200 */ 581, 580, 582, 582, 55, 55, 56, 56, 56, 56, 108104 + /* 210 */ 559, 54, 54, 54, 54, 53, 53, 52, 52, 52, 108105 + /* 220 */ 51, 234, 310, 464, 233, 232, 558, 133, 519, 50, 108106 + /* 230 */ 47, 147, 619, 618, 565, 436, 397, 515, 514, 518, 108107 + /* 240 */ 410, 387, 438, 389, 437, 622, 621, 442, 570, 433, 108108 + /* 250 */ 203, 390, 589, 583, 6, 413, 166, 670, 250, 381, 108109 + /* 260 */ 378, 377, 525, 190, 600, 92, 594, 571, 571, 465, 108110 + /* 270 */ 376, 57, 58, 48, 581, 580, 582, 582, 55, 55, 108111 + /* 280 */ 56, 56, 56, 56, 599, 54, 54, 54, 54, 53, 108112 + /* 290 */ 53, 52, 52, 52, 51, 234, 310, 592, 592, 592, 108113 + /* 300 */ 490, 182, 247, 548, 249, 397, 273, 410, 7, 439, 108114 + /* 310 */ 398, 606, 67, 619, 618, 620, 472, 256, 347, 255, 108115 + /* 320 */ 473, 620, 413, 576, 620, 65, 589, 583, 236, 440, 108116 + /* 330 */ 336, 600, 92, 68, 364, 192, 481, 622, 621, 547, 108117 + /* 340 */ 622, 621, 560, 323, 207, 57, 58, 48, 581, 580, 108118 + /* 350 */ 582, 582, 55, 55, 56, 56, 56, 56, 559, 54, 108119 + /* 360 */ 54, 54, 54, 53, 53, 52, 52, 52, 51, 234, 108120 + /* 370 */ 310, 410, 397, 146, 558, 531, 401, 348, 599, 166, 108121 + /* 380 */ 248, 204, 381, 378, 377, 541, 413, 171, 337, 570, 108122 + /* 390 */ 622, 621, 40, 376, 38, 600, 74, 465, 548, 490, 108123 + /* 400 */ 589, 583, 532, 350, 579, 619, 618, 297, 619, 618, 108124 + /* 410 */ 480, 67, 470, 39, 620, 599, 406, 574, 573, 57, 108125 + /* 420 */ 58, 48, 581, 580, 582, 582, 55, 55, 56, 56, 108126 + /* 430 */ 56, 56, 577, 54, 54, 54, 54, 53, 53, 52, 108127 + /* 440 */ 52, 52, 51, 234, 310, 256, 347, 255, 530, 52, 108128 + /* 450 */ 52, 52, 51, 234, 345, 564, 236, 386, 619, 618, 108129 + /* 460 */ 957, 185, 418, 2, 408, 410, 578, 578, 198, 197, 108130 + /* 470 */ 196, 499, 183, 167, 589, 583, 671, 570, 505, 506, 108131 + /* 480 */ 413, 267, 601, 672, 546, 208, 602, 36, 601, 600, 108132 + /* 490 */ 91, 468, 602, 57, 58, 48, 581, 580, 582, 582, 108133 + /* 500 */ 55, 55, 56, 56, 56, 56, 202, 54, 54, 54, 108134 + /* 510 */ 54, 53, 53, 52, 52, 52, 51, 234, 310, 599, 108135 + /* 520 */ 157, 408, 527, 578, 578, 263, 490, 265, 410, 873, 108136 + /* 530 */ 410, 474, 474, 366, 373, 410, 504, 428, 67, 290, 108137 + /* 540 */ 599, 620, 352, 413, 408, 413, 578, 578, 589, 583, 108138 + /* 550 */ 413, 382, 600, 92, 600, 16, 543, 62, 503, 600, 108139 + /* 560 */ 92, 408, 346, 578, 578, 168, 45, 57, 58, 48, 108140 + /* 570 */ 581, 580, 582, 582, 55, 55, 56, 56, 56, 56, 108141 + /* 580 */ 200, 54, 54, 54, 54, 53, 53, 52, 52, 52, 108142 + /* 590 */ 51, 234, 310, 393, 395, 534, 510, 617, 616, 615, 108143 + /* 600 */ 318, 314, 172, 66, 596, 410, 338, 596, 324, 571, 108144 + /* 610 */ 571, 50, 47, 147, 599, 629, 627, 330, 539, 315, 108145 + /* 620 */ 413, 30, 589, 583, 272, 236, 199, 144, 176, 600, 108146 + /* 630 */ 73, 420, 947, 620, 947, 420, 946, 351, 946, 175, 108147 + /* 640 */ 596, 57, 58, 48, 581, 580, 582, 582, 55, 55, 108148 + /* 650 */ 56, 56, 56, 56, 410, 54, 54, 54, 54, 53, 108149 + /* 660 */ 53, 52, 52, 52, 51, 234, 310, 261, 410, 413, 108150 + /* 670 */ 269, 208, 596, 363, 410, 596, 424, 360, 600, 69, 108151 + /* 680 */ 424, 327, 620, 413, 50, 47, 147, 410, 358, 413, 108152 + /* 690 */ 575, 553, 600, 94, 483, 509, 589, 583, 600, 97, 108153 + /* 700 */ 552, 484, 413, 620, 188, 599, 551, 563, 596, 566, 108154 + /* 710 */ 334, 600, 95, 205, 201, 57, 58, 48, 581, 580, 108155 + /* 720 */ 582, 582, 55, 55, 56, 56, 56, 56, 352, 54, 108156 + /* 730 */ 54, 54, 54, 53, 53, 52, 52, 52, 51, 234, 108157 + /* 740 */ 310, 410, 261, 410, 167, 22, 356, 599, 359, 623, 108158 + /* 750 */ 50, 47, 147, 548, 357, 562, 413, 620, 413, 332, 108159 + /* 760 */ 523, 270, 410, 167, 620, 600, 104, 600, 103, 603, 108160 + /* 770 */ 589, 583, 339, 539, 304, 423, 222, 413, 174, 304, 108161 + /* 780 */ 422, 561, 567, 405, 214, 260, 600, 106, 620, 57, 108162 + /* 790 */ 58, 48, 581, 580, 582, 582, 55, 55, 56, 56, 108163 + /* 800 */ 56, 56, 410, 54, 54, 54, 54, 53, 53, 52, 108164 + /* 810 */ 52, 52, 51, 234, 310, 410, 557, 413, 410, 421, 108165 + /* 820 */ 273, 35, 512, 146, 421, 12, 600, 107, 213, 144, 108166 + /* 830 */ 413, 410, 32, 413, 410, 620, 365, 353, 358, 600, 108167 + /* 840 */ 134, 11, 600, 135, 589, 583, 413, 21, 548, 413, 108168 + /* 850 */ 316, 148, 620, 620, 170, 600, 98, 223, 600, 102, 108169 + /* 860 */ 374, 168, 167, 57, 58, 48, 581, 580, 582, 582, 108170 + /* 870 */ 55, 55, 56, 56, 56, 56, 410, 54, 54, 54, 108171 + /* 880 */ 54, 53, 53, 52, 52, 52, 51, 234, 310, 410, 108172 + /* 890 */ 273, 413, 410, 273, 212, 469, 410, 167, 628, 2, 108173 + /* 900 */ 600, 101, 545, 221, 413, 620, 130, 413, 620, 410, 108174 + /* 910 */ 539, 413, 537, 600, 93, 315, 600, 100, 589, 583, 108175 + /* 920 */ 600, 77, 425, 305, 413, 620, 254, 322, 599, 458, 108176 + /* 930 */ 320, 171, 543, 600, 96, 521, 520, 57, 58, 48, 108177 + /* 940 */ 581, 580, 582, 582, 55, 55, 56, 56, 56, 56, 108178 + /* 950 */ 410, 54, 54, 54, 54, 53, 53, 52, 52, 52, 108179 + /* 960 */ 51, 234, 310, 410, 273, 413, 410, 457, 358, 35, 108180 + /* 970 */ 426, 230, 306, 319, 600, 138, 467, 520, 413, 620, 108181 + /* 980 */ 143, 413, 410, 620, 410, 353, 529, 600, 137, 142, 108182 + /* 990 */ 600, 136, 589, 583, 604, 261, 528, 413, 229, 413, 108183 + /* 1000 */ 620, 321, 495, 28, 543, 543, 600, 76, 600, 90, 108184 + /* 1010 */ 620, 57, 46, 48, 581, 580, 582, 582, 55, 55, 108185 + /* 1020 */ 56, 56, 56, 56, 410, 54, 54, 54, 54, 53, 108186 + /* 1030 */ 53, 52, 52, 52, 51, 234, 310, 261, 451, 413, 108187 + /* 1040 */ 410, 211, 611, 285, 283, 610, 609, 502, 600, 89, 108188 + /* 1050 */ 380, 217, 620, 128, 140, 413, 220, 620, 410, 409, 108189 + /* 1060 */ 620, 620, 588, 587, 600, 75, 589, 583, 271, 620, 108190 + /* 1070 */ 51, 234, 127, 413, 620, 599, 627, 330, 27, 375, 108191 + /* 1080 */ 449, 279, 600, 88, 585, 584, 58, 48, 581, 580, 108192 + /* 1090 */ 582, 582, 55, 55, 56, 56, 56, 56, 410, 54, 108193 + /* 1100 */ 54, 54, 54, 53, 53, 52, 52, 52, 51, 234, 108194 + /* 1110 */ 310, 586, 410, 413, 410, 261, 593, 165, 399, 556, 108195 + /* 1120 */ 126, 371, 600, 87, 478, 186, 123, 413, 367, 413, 108196 + /* 1130 */ 620, 620, 410, 620, 620, 410, 600, 99, 600, 86, 108197 + /* 1140 */ 589, 583, 475, 122, 258, 171, 471, 413, 160, 121, 108198 + /* 1150 */ 413, 14, 159, 463, 25, 24, 600, 17, 448, 600, 108199 + /* 1160 */ 85, 48, 581, 580, 582, 582, 55, 55, 56, 56, 108200 + /* 1170 */ 56, 56, 158, 54, 54, 54, 54, 53, 53, 52, 108201 + /* 1180 */ 52, 52, 51, 234, 44, 404, 261, 3, 544, 261, 108202 + /* 1190 */ 540, 414, 621, 460, 119, 118, 538, 275, 10, 349, 108203 + /* 1200 */ 4, 620, 407, 620, 620, 620, 116, 44, 404, 410, 108204 + /* 1210 */ 3, 620, 620, 410, 414, 621, 456, 454, 252, 450, 108205 + /* 1220 */ 508, 402, 111, 109, 413, 407, 155, 444, 413, 447, 108206 + /* 1230 */ 435, 565, 219, 600, 84, 620, 108, 600, 83, 64, 108207 + /* 1240 */ 434, 417, 625, 150, 402, 333, 410, 237, 238, 124, 108208 + /* 1250 */ 274, 41, 42, 533, 565, 206, 189, 261, 43, 412, 108209 + /* 1260 */ 411, 413, 261, 594, 488, 620, 329, 149, 419, 268, 108210 + /* 1270 */ 600, 72, 620, 266, 41, 42, 181, 620, 410, 620, 108211 + /* 1280 */ 105, 43, 412, 411, 620, 624, 594, 614, 620, 599, 108212 + /* 1290 */ 228, 125, 313, 413, 592, 592, 592, 591, 590, 13, 108213 + /* 1300 */ 218, 410, 600, 71, 236, 244, 44, 404, 264, 3, 108214 + /* 1310 */ 312, 613, 340, 414, 621, 180, 413, 592, 592, 592, 108215 + /* 1320 */ 591, 590, 13, 620, 407, 600, 82, 410, 416, 34, 108216 + /* 1330 */ 404, 410, 3, 410, 262, 410, 414, 621, 612, 331, 108217 + /* 1340 */ 178, 415, 413, 402, 8, 236, 413, 407, 413, 620, 108218 + /* 1350 */ 413, 600, 81, 565, 257, 600, 80, 600, 70, 600, 108219 + /* 1360 */ 18, 598, 361, 462, 461, 30, 402, 294, 31, 620, 108220 + /* 1370 */ 293, 354, 251, 41, 42, 410, 565, 620, 620, 620, 108221 + /* 1380 */ 43, 412, 411, 453, 396, 594, 620, 620, 394, 61, 108222 + /* 1390 */ 413, 292, 443, 622, 621, 243, 41, 42, 620, 600, 108223 + /* 1400 */ 79, 597, 291, 43, 412, 411, 60, 620, 594, 240, 108224 + /* 1410 */ 620, 410, 231, 37, 555, 173, 592, 592, 592, 591, 108225 + /* 1420 */ 590, 13, 216, 239, 620, 184, 413, 302, 301, 300, 108226 + /* 1430 */ 179, 298, 388, 565, 452, 600, 78, 286, 620, 592, 108227 + /* 1440 */ 592, 592, 591, 590, 13, 429, 29, 413, 151, 289, 108228 + /* 1450 */ 242, 145, 392, 194, 193, 288, 600, 9, 542, 241, 108229 + /* 1460 */ 620, 525, 391, 284, 620, 594, 620, 620, 522, 536, 108230 + /* 1470 */ 620, 535, 153, 385, 465, 516, 282, 325, 154, 517, 108231 + /* 1480 */ 277, 152, 512, 511, 513, 129, 226, 308, 487, 486, 108232 + /* 1490 */ 485, 164, 372, 493, 307, 227, 592, 592, 592, 225, 108233 + /* 1500 */ 479, 163, 368, 370, 162, 476, 210, 477, 26, 259, 108234 + /* 1510 */ 161, 466, 362, 141, 132, 120, 117, 455, 156, 115, 108235 + /* 1520 */ 344, 343, 256, 342, 245, 114, 113, 446, 311, 112, 108236 + /* 1530 */ 23, 317, 432, 236, 131, 431, 110, 430, 20, 427, 108237 + /* 1540 */ 608, 595, 295, 63, 379, 287, 509, 191, 278, 403, 108238 + /* 1550 */ 572, 569, 497, 498, 496, 494, 335, 459, 445, 303, 108239 + /* 1560 */ 296, 246, 341, 355, 5, 568, 369, 507, 253, 549, 108240 + /* 1570 */ 526, 209, 400, 501, 500, 524, 234, 958, 489, 482, 108678 108241 }; 108679 108242 static const YYCODETYPE yy_lookahead[] = { 108680 - /* 0 */ 19, 142, 143, 144, 145, 24, 1, 26, 77, 78, 108243 + /* 0 */ 19, 169, 170, 171, 22, 24, 24, 26, 77, 78, 108681 108244 /* 10 */ 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 108682 - /* 20 */ 89, 90, 91, 92, 26, 27, 15, 26, 27, 197, 108683 - /* 30 */ 49, 50, 77, 78, 79, 80, 204, 82, 83, 84, 108684 - /* 40 */ 85, 86, 87, 88, 89, 90, 91, 92, 23, 68, 108245 + /* 20 */ 89, 90, 91, 92, 26, 27, 1, 26, 27, 15, 108246 + /* 30 */ 49, 50, 77, 78, 79, 80, 116, 82, 83, 84, 108247 + /* 40 */ 85, 86, 87, 88, 89, 90, 91, 92, 128, 68, 108685 108248 /* 50 */ 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 108686 - /* 60 */ 79, 80, 166, 82, 83, 84, 85, 86, 87, 88, 108687 - /* 70 */ 89, 90, 91, 92, 19, 94, 19, 105, 106, 107, 108249 + /* 60 */ 79, 80, 230, 82, 83, 84, 85, 86, 87, 88, 108250 + /* 70 */ 89, 90, 91, 92, 19, 94, 19, 23, 86, 87, 108688 108251 /* 80 */ 25, 82, 83, 84, 85, 86, 87, 88, 89, 90, 108689 - /* 90 */ 91, 92, 94, 95, 96, 94, 95, 99, 100, 101, 108690 - /* 100 */ 112, 205, 114, 115, 49, 50, 22, 23, 110, 54, 108691 - /* 110 */ 86, 87, 88, 89, 90, 91, 92, 221, 222, 223, 108692 - /* 120 */ 23, 120, 25, 68, 69, 70, 71, 72, 73, 74, 108252 + /* 90 */ 91, 92, 94, 95, 19, 94, 95, 96, 172, 173, 108253 + /* 100 */ 99, 100, 101, 197, 49, 50, 177, 181, 22, 54, 108254 + /* 110 */ 204, 110, 26, 27, 86, 87, 88, 89, 90, 91, 108255 + /* 120 */ 92, 129, 130, 68, 69, 70, 71, 72, 73, 74, 108693 108256 /* 130 */ 75, 76, 77, 78, 79, 80, 22, 82, 83, 84, 108694 108257 /* 140 */ 85, 86, 87, 88, 89, 90, 91, 92, 19, 92, 108695 - /* 150 */ 23, 67, 25, 96, 97, 98, 99, 100, 101, 102, 108696 - /* 160 */ 150, 32, 150, 118, 26, 27, 109, 150, 150, 150, 108697 - /* 170 */ 41, 161, 162, 180, 181, 165, 113, 165, 49, 50, 108698 - /* 180 */ 117, 188, 165, 165, 165, 173, 174, 170, 171, 170, 108699 - /* 190 */ 171, 173, 174, 118, 184, 16, 186, 68, 69, 70, 108258 + /* 150 */ 221, 222, 223, 96, 97, 98, 99, 100, 101, 102, 108259 + /* 160 */ 112, 32, 114, 115, 26, 27, 109, 92, 150, 25, 108260 + /* 170 */ 41, 150, 97, 98, 99, 100, 101, 102, 49, 50, 108261 + /* 180 */ 94, 95, 98, 165, 109, 25, 165, 163, 170, 171, 108262 + /* 190 */ 166, 167, 168, 109, 12, 174, 175, 68, 69, 70, 108700 108263 /* 200 */ 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 108701 - /* 210 */ 118, 82, 83, 84, 85, 86, 87, 88, 89, 90, 108702 - /* 220 */ 91, 92, 19, 98, 86, 87, 22, 24, 160, 88, 108703 - /* 230 */ 26, 27, 94, 95, 109, 97, 224, 66, 118, 60, 108704 - /* 240 */ 150, 62, 104, 23, 106, 25, 229, 230, 229, 230, 108705 - /* 250 */ 160, 150, 49, 50, 113, 165, 96, 26, 117, 99, 108706 - /* 260 */ 100, 101, 194, 173, 174, 94, 165, 129, 130, 98, 108264 + /* 210 */ 28, 82, 83, 84, 85, 86, 87, 88, 89, 90, 108265 + /* 220 */ 91, 92, 19, 11, 86, 87, 44, 24, 46, 221, 108266 + /* 230 */ 222, 223, 94, 95, 66, 97, 215, 7, 8, 57, 108267 + /* 240 */ 150, 220, 104, 19, 106, 26, 27, 229, 230, 241, 108268 + /* 250 */ 160, 27, 49, 50, 22, 165, 96, 118, 16, 99, 108269 + /* 260 */ 100, 101, 94, 119, 174, 175, 98, 129, 130, 57, 108707 108270 /* 270 */ 110, 68, 69, 70, 71, 72, 73, 74, 75, 76, 108708 108271 /* 280 */ 77, 78, 79, 80, 194, 82, 83, 84, 85, 86, 108709 - /* 290 */ 87, 88, 89, 90, 91, 92, 19, 11, 94, 95, 108710 - /* 300 */ 129, 130, 131, 118, 150, 215, 150, 150, 150, 25, 108711 - /* 310 */ 220, 26, 27, 22, 213, 26, 27, 26, 27, 165, 108712 - /* 320 */ 25, 165, 165, 165, 30, 94, 49, 50, 34, 173, 108713 - /* 330 */ 174, 173, 174, 88, 89, 90, 91, 92, 7, 8, 108714 - /* 340 */ 160, 187, 48, 57, 187, 68, 69, 70, 71, 72, 108715 - /* 350 */ 73, 74, 75, 76, 77, 78, 79, 80, 23, 82, 108272 + /* 290 */ 87, 88, 89, 90, 91, 92, 19, 129, 130, 131, 108273 + /* 300 */ 150, 23, 60, 25, 62, 215, 150, 150, 76, 150, 108274 + /* 310 */ 220, 161, 162, 94, 95, 165, 30, 105, 106, 107, 108275 + /* 320 */ 34, 165, 165, 23, 165, 25, 49, 50, 116, 170, 108276 + /* 330 */ 171, 174, 175, 22, 48, 185, 186, 26, 27, 120, 108277 + /* 340 */ 26, 27, 12, 187, 160, 68, 69, 70, 71, 72, 108278 + /* 350 */ 73, 74, 75, 76, 77, 78, 79, 80, 28, 82, 108716 108279 /* 360 */ 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 108717 - /* 370 */ 19, 215, 150, 215, 194, 19, 220, 88, 220, 94, 108718 - /* 380 */ 95, 23, 160, 94, 95, 94, 95, 165, 26, 27, 108719 - /* 390 */ 95, 105, 106, 107, 113, 173, 174, 217, 22, 150, 108720 - /* 400 */ 49, 50, 116, 119, 57, 120, 50, 158, 22, 21, 108721 - /* 410 */ 161, 162, 232, 136, 165, 120, 194, 237, 23, 68, 108280 + /* 370 */ 19, 150, 215, 95, 44, 23, 46, 220, 194, 96, 108281 + /* 380 */ 138, 160, 99, 100, 101, 23, 165, 25, 229, 230, 108282 + /* 390 */ 26, 27, 135, 110, 137, 174, 175, 57, 120, 150, 108283 + /* 400 */ 49, 50, 88, 219, 113, 94, 95, 158, 94, 95, 108284 + /* 410 */ 161, 162, 21, 136, 165, 194, 169, 170, 171, 68, 108722 108285 /* 420 */ 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 108723 - /* 430 */ 79, 80, 22, 82, 83, 84, 85, 86, 87, 88, 108724 - /* 440 */ 89, 90, 91, 92, 19, 23, 12, 112, 23, 114, 108725 - /* 450 */ 115, 63, 105, 106, 107, 23, 94, 95, 97, 98, 108726 - /* 460 */ 104, 150, 28, 116, 25, 109, 150, 150, 23, 23, 108727 - /* 470 */ 112, 25, 114, 115, 49, 50, 165, 150, 44, 11, 108728 - /* 480 */ 46, 165, 165, 16, 173, 174, 76, 136, 100, 173, 108729 - /* 490 */ 174, 57, 165, 68, 69, 70, 71, 72, 73, 74, 108730 - /* 500 */ 75, 76, 77, 78, 79, 80, 166, 82, 83, 84, 108731 - /* 510 */ 85, 86, 87, 88, 89, 90, 91, 92, 19, 169, 108732 - /* 520 */ 170, 171, 23, 12, 23, 214, 138, 60, 150, 62, 108733 - /* 530 */ 24, 215, 26, 216, 112, 150, 114, 115, 36, 28, 108734 - /* 540 */ 213, 95, 103, 165, 112, 205, 114, 115, 49, 50, 108735 - /* 550 */ 165, 173, 174, 51, 23, 44, 25, 46, 173, 174, 108736 - /* 560 */ 58, 22, 23, 22, 25, 160, 120, 68, 69, 70, 108286 + /* 430 */ 79, 80, 23, 82, 83, 84, 85, 86, 87, 88, 108287 + /* 440 */ 89, 90, 91, 92, 19, 105, 106, 107, 23, 88, 108288 + /* 450 */ 89, 90, 91, 92, 63, 23, 116, 88, 94, 95, 108289 + /* 460 */ 142, 143, 144, 145, 112, 150, 114, 115, 105, 106, 108290 + /* 470 */ 107, 23, 23, 25, 49, 50, 118, 230, 97, 98, 108291 + /* 480 */ 165, 16, 113, 118, 120, 160, 117, 136, 113, 174, 108292 + /* 490 */ 175, 100, 117, 68, 69, 70, 71, 72, 73, 74, 108293 + /* 500 */ 75, 76, 77, 78, 79, 80, 160, 82, 83, 84, 108294 + /* 510 */ 85, 86, 87, 88, 89, 90, 91, 92, 19, 194, 108295 + /* 520 */ 25, 112, 23, 114, 115, 60, 150, 62, 150, 138, 108296 + /* 530 */ 150, 105, 106, 107, 19, 150, 36, 161, 162, 224, 108297 + /* 540 */ 194, 165, 217, 165, 112, 165, 114, 115, 49, 50, 108298 + /* 550 */ 165, 51, 174, 175, 174, 175, 166, 232, 58, 174, 108299 + /* 560 */ 175, 112, 237, 114, 115, 50, 22, 68, 69, 70, 108737 108300 /* 570 */ 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 108738 - /* 580 */ 230, 82, 83, 84, 85, 86, 87, 88, 89, 90, 108739 - /* 590 */ 91, 92, 19, 215, 22, 23, 23, 25, 163, 194, 108740 - /* 600 */ 94, 166, 167, 168, 25, 138, 67, 7, 8, 9, 108741 - /* 610 */ 108, 206, 207, 169, 170, 171, 150, 22, 221, 222, 108742 - /* 620 */ 223, 26, 49, 50, 86, 87, 23, 161, 162, 23, 108743 - /* 630 */ 22, 165, 24, 120, 22, 23, 25, 160, 241, 67, 108744 - /* 640 */ 176, 68, 69, 70, 71, 72, 73, 74, 75, 76, 108745 - /* 650 */ 77, 78, 79, 80, 160, 82, 83, 84, 85, 86, 108746 - /* 660 */ 87, 88, 89, 90, 91, 92, 19, 129, 130, 150, 108747 - /* 670 */ 23, 194, 35, 23, 230, 25, 150, 155, 150, 67, 108748 - /* 680 */ 150, 105, 106, 107, 165, 221, 222, 223, 194, 94, 108749 - /* 690 */ 23, 165, 25, 165, 217, 165, 49, 50, 25, 173, 108750 - /* 700 */ 174, 173, 174, 173, 174, 0, 1, 2, 118, 221, 108751 - /* 710 */ 222, 223, 193, 219, 237, 68, 69, 70, 71, 72, 108752 - /* 720 */ 73, 74, 75, 76, 77, 78, 79, 80, 150, 82, 108301 + /* 580 */ 160, 82, 83, 84, 85, 86, 87, 88, 89, 90, 108302 + /* 590 */ 91, 92, 19, 215, 214, 205, 23, 7, 8, 9, 108303 + /* 600 */ 215, 155, 24, 22, 26, 150, 97, 26, 108, 129, 108304 + /* 610 */ 130, 221, 222, 223, 194, 0, 1, 2, 150, 104, 108305 + /* 620 */ 165, 126, 49, 50, 109, 116, 206, 207, 118, 174, 108306 + /* 630 */ 175, 22, 23, 165, 25, 22, 23, 128, 25, 118, 108307 + /* 640 */ 26, 68, 69, 70, 71, 72, 73, 74, 75, 76, 108308 + /* 650 */ 77, 78, 79, 80, 150, 82, 83, 84, 85, 86, 108309 + /* 660 */ 87, 88, 89, 90, 91, 92, 19, 150, 150, 165, 108310 + /* 670 */ 23, 160, 94, 227, 150, 94, 67, 231, 174, 175, 108311 + /* 680 */ 67, 213, 165, 165, 221, 222, 223, 150, 150, 165, 108312 + /* 690 */ 23, 32, 174, 175, 181, 182, 49, 50, 174, 175, 108313 + /* 700 */ 41, 188, 165, 165, 22, 194, 177, 11, 94, 23, 108314 + /* 710 */ 193, 174, 175, 160, 22, 68, 69, 70, 71, 72, 108315 + /* 720 */ 73, 74, 75, 76, 77, 78, 79, 80, 217, 82, 108753 108316 /* 730 */ 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 108754 - /* 740 */ 19, 150, 19, 165, 150, 24, 166, 167, 168, 227, 108755 - /* 750 */ 27, 173, 174, 231, 150, 25, 165, 150, 172, 165, 108756 - /* 760 */ 150, 242, 129, 130, 173, 174, 180, 173, 174, 165, 108757 - /* 770 */ 49, 50, 165, 150, 176, 165, 35, 173, 174, 165, 108758 - /* 780 */ 173, 174, 35, 23, 23, 25, 25, 173, 165, 68, 108317 + /* 740 */ 19, 150, 150, 150, 25, 24, 19, 194, 237, 150, 108318 + /* 750 */ 221, 222, 223, 25, 27, 23, 165, 165, 165, 242, 108319 + /* 760 */ 165, 23, 150, 25, 165, 174, 175, 174, 175, 174, 108320 + /* 770 */ 49, 50, 219, 150, 22, 23, 238, 165, 25, 22, 108321 + /* 780 */ 23, 23, 166, 167, 168, 193, 174, 175, 165, 68, 108759 108322 /* 790 */ 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 108760 108323 /* 800 */ 79, 80, 150, 82, 83, 84, 85, 86, 87, 88, 108761 - /* 810 */ 89, 90, 91, 92, 19, 150, 193, 165, 150, 221, 108762 - /* 820 */ 222, 223, 150, 213, 19, 173, 174, 23, 150, 97, 108763 - /* 830 */ 165, 150, 27, 165, 150, 150, 150, 165, 173, 174, 108764 - /* 840 */ 22, 173, 174, 165, 49, 50, 165, 52, 116, 165, 108765 - /* 850 */ 165, 165, 206, 207, 173, 174, 126, 50, 173, 174, 108766 - /* 860 */ 128, 27, 160, 68, 69, 70, 71, 72, 73, 74, 108324 + /* 810 */ 89, 90, 91, 92, 19, 150, 23, 165, 150, 67, 108325 + /* 820 */ 150, 25, 103, 95, 67, 35, 174, 175, 206, 207, 108326 + /* 830 */ 165, 150, 25, 165, 150, 165, 213, 150, 150, 174, 108327 + /* 840 */ 175, 35, 174, 175, 49, 50, 165, 52, 120, 165, 108328 + /* 850 */ 245, 246, 165, 165, 35, 174, 175, 187, 174, 175, 108329 + /* 860 */ 23, 50, 25, 68, 69, 70, 71, 72, 73, 74, 108767 108330 /* 870 */ 75, 76, 77, 78, 79, 80, 150, 82, 83, 84, 108768 108331 /* 880 */ 85, 86, 87, 88, 89, 90, 91, 92, 19, 150, 108769 - /* 890 */ 23, 165, 150, 23, 216, 25, 194, 32, 39, 173, 108770 - /* 900 */ 174, 135, 150, 137, 165, 150, 41, 165, 150, 52, 108771 - /* 910 */ 238, 104, 173, 174, 29, 173, 174, 165, 49, 50, 108772 - /* 920 */ 165, 219, 238, 165, 238, 173, 174, 52, 173, 174, 108773 - /* 930 */ 22, 173, 174, 23, 23, 160, 25, 68, 69, 70, 108332 + /* 890 */ 150, 165, 150, 150, 160, 23, 150, 25, 144, 145, 108333 + /* 900 */ 174, 175, 120, 216, 165, 165, 22, 165, 165, 150, 108334 + /* 910 */ 150, 165, 27, 174, 175, 104, 174, 175, 49, 50, 108335 + /* 920 */ 174, 175, 247, 248, 165, 165, 238, 187, 194, 23, 108336 + /* 930 */ 187, 25, 166, 174, 175, 190, 191, 68, 69, 70, 108774 108337 /* 940 */ 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 108775 108338 /* 950 */ 150, 82, 83, 84, 85, 86, 87, 88, 89, 90, 108776 - /* 960 */ 91, 92, 19, 150, 150, 165, 150, 245, 246, 194, 108777 - /* 970 */ 150, 144, 145, 173, 174, 160, 150, 22, 165, 165, 108778 - /* 980 */ 22, 165, 150, 150, 116, 165, 173, 174, 52, 173, 108779 - /* 990 */ 174, 165, 49, 50, 22, 150, 128, 165, 165, 173, 108780 - /* 1000 */ 174, 187, 166, 166, 22, 173, 174, 187, 109, 194, 108339 + /* 960 */ 91, 92, 19, 150, 150, 165, 150, 23, 150, 25, 108340 + /* 970 */ 23, 205, 25, 213, 174, 175, 190, 191, 165, 165, 108341 + /* 980 */ 118, 165, 150, 165, 150, 150, 23, 174, 175, 39, 108342 + /* 990 */ 174, 175, 49, 50, 173, 150, 23, 165, 52, 165, 108343 + /* 1000 */ 165, 187, 181, 22, 166, 166, 174, 175, 174, 175, 108781 108344 /* 1010 */ 165, 68, 69, 70, 71, 72, 73, 74, 75, 76, 108782 108345 /* 1020 */ 77, 78, 79, 80, 150, 82, 83, 84, 85, 86, 108783 108346 /* 1030 */ 87, 88, 89, 90, 91, 92, 19, 150, 193, 165, 108784 - /* 1040 */ 102, 205, 205, 150, 150, 247, 248, 173, 174, 19, 108785 - /* 1050 */ 150, 20, 165, 150, 150, 150, 150, 150, 165, 165, 108786 - /* 1060 */ 173, 174, 49, 50, 104, 165, 49, 50, 165, 165, 108787 - /* 1070 */ 165, 165, 165, 173, 174, 43, 173, 174, 173, 174, 108788 - /* 1080 */ 187, 24, 190, 191, 71, 72, 69, 70, 71, 72, 108347 + /* 1040 */ 150, 160, 150, 205, 205, 150, 150, 29, 174, 175, 108348 + /* 1050 */ 52, 216, 165, 22, 150, 165, 238, 165, 150, 150, 108349 + /* 1060 */ 165, 165, 49, 50, 174, 175, 49, 50, 23, 165, 108350 + /* 1070 */ 91, 92, 22, 165, 165, 194, 1, 2, 22, 52, 108351 + /* 1080 */ 193, 109, 174, 175, 71, 72, 69, 70, 71, 72, 108789 108352 /* 1090 */ 73, 74, 75, 76, 77, 78, 79, 80, 150, 82, 108790 108353 /* 1100 */ 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 108791 - /* 1110 */ 19, 98, 150, 165, 150, 150, 150, 150, 150, 150, 108792 - /* 1120 */ 59, 173, 174, 25, 150, 190, 191, 165, 53, 165, 108793 - /* 1130 */ 165, 165, 165, 165, 165, 173, 174, 173, 174, 165, 108794 - /* 1140 */ 49, 50, 91, 92, 1, 2, 53, 173, 174, 138, 108795 - /* 1150 */ 104, 22, 5, 1, 35, 118, 127, 150, 193, 193, 108796 - /* 1160 */ 193, 70, 71, 72, 73, 74, 75, 76, 77, 78, 108797 - /* 1170 */ 79, 80, 165, 82, 83, 84, 85, 86, 87, 88, 108798 - /* 1180 */ 89, 90, 91, 92, 19, 20, 150, 22, 150, 27, 108799 - /* 1190 */ 150, 26, 27, 108, 150, 22, 76, 76, 150, 25, 108800 - /* 1200 */ 193, 165, 37, 165, 150, 165, 22, 19, 20, 165, 108801 - /* 1210 */ 22, 173, 174, 165, 26, 27, 23, 150, 119, 165, 108802 - /* 1220 */ 150, 56, 150, 150, 150, 37, 16, 173, 174, 193, 108803 - /* 1230 */ 150, 66, 165, 193, 1, 165, 121, 165, 165, 165, 108804 - /* 1240 */ 20, 146, 147, 119, 56, 165, 150, 152, 16, 154, 108805 - /* 1250 */ 150, 86, 87, 88, 66, 160, 150, 150, 93, 94, 108806 - /* 1260 */ 95, 165, 150, 98, 108, 165, 127, 23, 65, 173, 108807 - /* 1270 */ 174, 165, 165, 150, 86, 87, 128, 165, 150, 173, 108808 - /* 1280 */ 174, 93, 94, 95, 23, 150, 98, 15, 165, 194, 108809 - /* 1290 */ 150, 140, 22, 165, 129, 130, 131, 132, 133, 134, 108810 - /* 1300 */ 165, 173, 174, 3, 116, 165, 19, 20, 150, 22, 108811 - /* 1310 */ 4, 150, 217, 26, 27, 179, 179, 129, 130, 131, 108812 - /* 1320 */ 132, 133, 134, 165, 37, 150, 165, 150, 164, 19, 108813 - /* 1330 */ 20, 150, 22, 246, 149, 249, 26, 27, 249, 244, 108814 - /* 1340 */ 165, 150, 165, 56, 6, 150, 165, 37, 173, 174, 108815 - /* 1350 */ 173, 174, 150, 66, 173, 174, 165, 149, 149, 13, 108816 - /* 1360 */ 165, 25, 150, 150, 150, 149, 56, 165, 150, 116, 108817 - /* 1370 */ 151, 150, 150, 86, 87, 150, 66, 165, 165, 165, 108818 - /* 1380 */ 93, 94, 95, 165, 150, 98, 165, 165, 151, 22, 108819 - /* 1390 */ 165, 194, 150, 26, 27, 150, 86, 87, 159, 165, 108820 - /* 1400 */ 199, 126, 123, 93, 94, 95, 200, 165, 98, 124, 108821 - /* 1410 */ 165, 122, 201, 125, 225, 135, 129, 130, 131, 132, 108822 - /* 1420 */ 133, 134, 5, 157, 157, 202, 118, 10, 11, 12, 108823 - /* 1430 */ 13, 14, 203, 66, 17, 104, 210, 121, 211, 129, 108824 - /* 1440 */ 130, 131, 132, 133, 134, 210, 175, 211, 31, 211, 108825 - /* 1450 */ 33, 210, 104, 86, 87, 47, 175, 183, 175, 42, 108826 - /* 1460 */ 103, 94, 178, 177, 22, 98, 175, 92, 228, 175, 108827 - /* 1470 */ 175, 228, 55, 183, 57, 178, 175, 156, 61, 18, 108828 - /* 1480 */ 157, 64, 156, 235, 157, 156, 45, 157, 236, 157, 108829 - /* 1490 */ 135, 156, 189, 68, 157, 218, 129, 130, 131, 22, 108830 - /* 1500 */ 189, 199, 157, 156, 192, 18, 192, 192, 199, 192, 108831 - /* 1510 */ 218, 189, 40, 157, 38, 157, 240, 157, 240, 153, 108832 - /* 1520 */ 196, 181, 105, 106, 107, 243, 198, 166, 111, 230, 108833 - /* 1530 */ 176, 226, 239, 116, 230, 176, 166, 166, 176, 148, 108834 - /* 1540 */ 199, 177, 209, 209, 166, 196, 239, 208, 185, 199, 108835 - /* 1550 */ 92, 209, 233, 173, 234, 182, 139, 173, 182, 191, 108836 - /* 1560 */ 195, 182, 250, 186, 108837 -}; 108838 -#define YY_SHIFT_USE_DFLT (-70) 108839 -#define YY_SHIFT_COUNT (416) 108840 -#define YY_SHIFT_MIN (-69) 108841 -#define YY_SHIFT_MAX (1487) 108354 + /* 1110 */ 19, 98, 150, 165, 150, 150, 150, 102, 150, 150, 108355 + /* 1120 */ 22, 19, 174, 175, 20, 24, 104, 165, 43, 165, 108356 + /* 1130 */ 165, 165, 150, 165, 165, 150, 174, 175, 174, 175, 108357 + /* 1140 */ 49, 50, 59, 53, 138, 25, 53, 165, 104, 22, 108358 + /* 1150 */ 165, 5, 118, 1, 76, 76, 174, 175, 193, 174, 108359 + /* 1160 */ 175, 70, 71, 72, 73, 74, 75, 76, 77, 78, 108360 + /* 1170 */ 79, 80, 35, 82, 83, 84, 85, 86, 87, 88, 108361 + /* 1180 */ 89, 90, 91, 92, 19, 20, 150, 22, 150, 150, 108362 + /* 1190 */ 150, 26, 27, 27, 108, 127, 150, 150, 22, 25, 108363 + /* 1200 */ 22, 165, 37, 165, 165, 165, 119, 19, 20, 150, 108364 + /* 1210 */ 22, 165, 165, 150, 26, 27, 23, 1, 16, 20, 108365 + /* 1220 */ 150, 56, 119, 108, 165, 37, 121, 128, 165, 193, 108366 + /* 1230 */ 23, 66, 193, 174, 175, 165, 127, 174, 175, 16, 108367 + /* 1240 */ 23, 146, 147, 15, 56, 65, 150, 152, 140, 154, 108368 + /* 1250 */ 150, 86, 87, 88, 66, 160, 22, 150, 93, 94, 108369 + /* 1260 */ 95, 165, 150, 98, 150, 165, 3, 246, 4, 150, 108370 + /* 1270 */ 174, 175, 165, 150, 86, 87, 6, 165, 150, 165, 108371 + /* 1280 */ 164, 93, 94, 95, 165, 149, 98, 149, 165, 194, 108372 + /* 1290 */ 180, 180, 249, 165, 129, 130, 131, 132, 133, 134, 108373 + /* 1300 */ 193, 150, 174, 175, 116, 193, 19, 20, 150, 22, 108374 + /* 1310 */ 249, 149, 217, 26, 27, 151, 165, 129, 130, 131, 108375 + /* 1320 */ 132, 133, 134, 165, 37, 174, 175, 150, 149, 19, 108376 + /* 1330 */ 20, 150, 22, 150, 150, 150, 26, 27, 13, 244, 108377 + /* 1340 */ 151, 159, 165, 56, 25, 116, 165, 37, 165, 165, 108378 + /* 1350 */ 165, 174, 175, 66, 150, 174, 175, 174, 175, 174, 108379 + /* 1360 */ 175, 194, 150, 150, 150, 126, 56, 199, 124, 165, 108380 + /* 1370 */ 200, 150, 150, 86, 87, 150, 66, 165, 165, 165, 108381 + /* 1380 */ 93, 94, 95, 150, 122, 98, 165, 165, 123, 22, 108382 + /* 1390 */ 165, 201, 150, 26, 27, 150, 86, 87, 165, 174, 108383 + /* 1400 */ 175, 203, 202, 93, 94, 95, 125, 165, 98, 150, 108384 + /* 1410 */ 165, 150, 225, 135, 157, 118, 129, 130, 131, 132, 108385 + /* 1420 */ 133, 134, 5, 150, 165, 157, 165, 10, 11, 12, 108386 + /* 1430 */ 13, 14, 150, 66, 17, 174, 175, 210, 165, 129, 108387 + /* 1440 */ 130, 131, 132, 133, 134, 150, 104, 165, 31, 150, 108388 + /* 1450 */ 33, 150, 150, 86, 87, 150, 174, 175, 211, 42, 108389 + /* 1460 */ 165, 94, 121, 210, 165, 98, 165, 165, 176, 211, 108390 + /* 1470 */ 165, 211, 55, 104, 57, 184, 210, 47, 61, 176, 108391 + /* 1480 */ 176, 64, 103, 176, 178, 22, 92, 179, 176, 176, 108392 + /* 1490 */ 176, 156, 18, 184, 179, 228, 129, 130, 131, 228, 108393 + /* 1500 */ 157, 156, 45, 157, 156, 236, 157, 157, 135, 235, 108394 + /* 1510 */ 156, 189, 157, 68, 218, 189, 22, 199, 156, 192, 108395 + /* 1520 */ 157, 18, 105, 106, 107, 192, 192, 199, 111, 192, 108396 + /* 1530 */ 240, 157, 40, 116, 218, 157, 189, 157, 240, 38, 108397 + /* 1540 */ 153, 166, 198, 243, 178, 209, 182, 196, 177, 226, 108398 + /* 1550 */ 230, 230, 166, 177, 177, 166, 139, 199, 199, 148, 108399 + /* 1560 */ 195, 209, 209, 239, 196, 166, 234, 183, 239, 208, 108400 + /* 1570 */ 174, 233, 191, 183, 183, 174, 92, 250, 186, 186, 108401 +}; 108402 +#define YY_SHIFT_USE_DFLT (-81) 108403 +#define YY_SHIFT_COUNT (417) 108404 +#define YY_SHIFT_MIN (-80) 108405 +#define YY_SHIFT_MAX (1503) 108842 108406 static const short yy_shift_ofst[] = { 108843 - /* 0 */ 1143, 1188, 1417, 1188, 1287, 1287, 138, 138, -2, -19, 108844 - /* 10 */ 1287, 1287, 1287, 1287, 347, 362, 129, 129, 795, 1165, 108407 + /* 0 */ 1075, 1188, 1417, 1188, 1287, 1287, 138, 138, 1, -19, 108408 + /* 10 */ 1287, 1287, 1287, 1287, 340, -2, 129, 129, 795, 1165, 108845 108409 /* 20 */ 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 108846 108410 /* 30 */ 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 108847 108411 /* 40 */ 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1310, 1287, 108848 108412 /* 50 */ 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 108849 - /* 60 */ 1287, 1287, 286, 362, 362, 538, 538, 231, 1253, 55, 108413 + /* 60 */ 1287, 1287, 212, -2, -2, -8, -8, 614, 1229, 55, 108850 108414 /* 70 */ 721, 647, 573, 499, 425, 351, 277, 203, 869, 869, 108851 108415 /* 80 */ 869, 869, 869, 869, 869, 869, 869, 869, 869, 869, 108852 108416 /* 90 */ 869, 869, 869, 943, 869, 1017, 1091, 1091, -69, -45, 108853 - /* 100 */ -45, -45, -45, -45, -1, 24, 245, 362, 362, 362, 108854 - /* 110 */ 362, 362, 362, 362, 362, 362, 362, 362, 362, 362, 108855 - /* 120 */ 362, 362, 362, 388, 356, 362, 362, 362, 362, 362, 108856 - /* 130 */ 732, 868, 231, 1051, 1458, -70, -70, -70, 1367, 57, 108857 - /* 140 */ 434, 434, 289, 291, 285, 1, 204, 572, 539, 362, 108858 - /* 150 */ 362, 362, 362, 362, 362, 362, 362, 362, 362, 362, 108859 - /* 160 */ 362, 362, 362, 362, 362, 362, 362, 362, 362, 362, 108860 - /* 170 */ 362, 362, 362, 362, 362, 362, 362, 362, 362, 362, 108861 - /* 180 */ 362, 506, 506, 506, 705, 1253, 1253, 1253, -70, -70, 108862 - /* 190 */ -70, 171, 171, 160, 502, 502, 502, 446, 432, 511, 108863 - /* 200 */ 422, 358, 335, -12, -12, -12, -12, 576, 294, -12, 108864 - /* 210 */ -12, 295, 595, 141, 600, 730, 723, 723, 805, 730, 108865 - /* 220 */ 805, 439, 911, 231, 865, 231, 865, 807, 865, 723, 108866 - /* 230 */ 766, 633, 633, 231, 284, 63, 608, 1476, 1308, 1308, 108867 - /* 240 */ 1472, 1472, 1308, 1477, 1425, 1275, 1487, 1487, 1487, 1487, 108868 - /* 250 */ 1308, 1461, 1275, 1477, 1425, 1425, 1308, 1461, 1355, 1441, 108869 - /* 260 */ 1308, 1308, 1461, 1308, 1461, 1308, 1461, 1442, 1348, 1348, 108870 - /* 270 */ 1348, 1408, 1375, 1375, 1442, 1348, 1357, 1348, 1408, 1348, 108871 - /* 280 */ 1348, 1316, 1331, 1316, 1331, 1316, 1331, 1308, 1308, 1280, 108872 - /* 290 */ 1288, 1289, 1285, 1279, 1275, 1253, 1336, 1346, 1346, 1338, 108873 - /* 300 */ 1338, 1338, 1338, -70, -70, -70, -70, -70, -70, 1013, 108874 - /* 310 */ 467, 612, 84, 179, -28, 870, 410, 761, 760, 667, 108875 - /* 320 */ 650, 531, 220, 361, 331, 125, 127, 97, 1306, 1300, 108876 - /* 330 */ 1270, 1151, 1272, 1203, 1232, 1261, 1244, 1148, 1174, 1139, 108877 - /* 340 */ 1156, 1124, 1220, 1115, 1210, 1233, 1099, 1193, 1184, 1174, 108878 - /* 350 */ 1173, 1029, 1121, 1120, 1085, 1162, 1119, 1037, 1152, 1147, 108879 - /* 360 */ 1129, 1046, 1011, 1093, 1098, 1075, 1061, 1032, 960, 1057, 108880 - /* 370 */ 1031, 1030, 899, 938, 982, 936, 972, 958, 910, 955, 108881 - /* 380 */ 875, 885, 908, 857, 859, 867, 804, 590, 834, 747, 108882 - /* 390 */ 818, 513, 611, 741, 673, 637, 611, 606, 603, 579, 108883 - /* 400 */ 501, 541, 468, 386, 445, 395, 376, 281, 185, 120, 108884 - /* 410 */ 92, 75, 45, 114, 25, 11, 5, 108417 + /* 100 */ -45, -45, -45, -45, -1, 57, 28, 361, -2, -2, 108418 + /* 110 */ -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, 108419 + /* 120 */ -2, -2, -2, -2, 391, 515, -2, -2, -2, -2, 108420 + /* 130 */ -2, 509, -80, 614, 979, 1484, -81, -81, -81, 1367, 108421 + /* 140 */ 75, 182, 182, 314, 311, 364, 219, 86, 613, 609, 108422 + /* 150 */ -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, 108423 + /* 160 */ -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, 108424 + /* 170 */ -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, 108425 + /* 180 */ -2, -2, 578, 578, 578, 615, 1229, 1229, 1229, -81, 108426 + /* 190 */ -81, -81, 160, 168, 168, 283, 500, 500, 500, 278, 108427 + /* 200 */ 449, 330, 432, 409, 352, 48, 48, 48, 48, 426, 108428 + /* 210 */ 286, 48, 48, 728, 581, 369, 590, 495, 224, 224, 108429 + /* 220 */ 727, 495, 727, 719, 614, 659, 614, 659, 811, 659, 108430 + /* 230 */ 224, 257, 480, 480, 614, 144, 375, -18, 1501, 1297, 108431 + /* 240 */ 1297, 1492, 1492, 1297, 1494, 1445, 1239, 1503, 1503, 1503, 108432 + /* 250 */ 1503, 1297, 1474, 1239, 1494, 1445, 1445, 1297, 1474, 1373, 108433 + /* 260 */ 1457, 1297, 1297, 1474, 1297, 1474, 1297, 1474, 1463, 1369, 108434 + /* 270 */ 1369, 1369, 1430, 1394, 1394, 1463, 1369, 1379, 1369, 1430, 108435 + /* 280 */ 1369, 1369, 1341, 1342, 1341, 1342, 1341, 1342, 1297, 1297, 108436 + /* 290 */ 1278, 1281, 1262, 1244, 1265, 1239, 1229, 1319, 1325, 1325, 108437 + /* 300 */ 1270, 1270, 1270, 1270, -81, -81, -81, -81, -81, -81, 108438 + /* 310 */ 1013, 242, 757, 752, 465, 363, 947, 232, 944, 906, 108439 + /* 320 */ 872, 837, 738, 448, 381, 230, 84, 362, 300, 1264, 108440 + /* 330 */ 1263, 1234, 1108, 1228, 1180, 1223, 1217, 1207, 1099, 1174, 108441 + /* 340 */ 1109, 1115, 1103, 1199, 1105, 1202, 1216, 1087, 1193, 1178, 108442 + /* 350 */ 1174, 1176, 1068, 1079, 1078, 1086, 1166, 1137, 1034, 1152, 108443 + /* 360 */ 1146, 1127, 1044, 1006, 1093, 1120, 1090, 1083, 1085, 1022, 108444 + /* 370 */ 1101, 1104, 1102, 972, 1015, 1098, 1027, 1056, 1050, 1045, 108445 + /* 380 */ 1031, 998, 1018, 981, 946, 950, 973, 963, 862, 885, 108446 + /* 390 */ 819, 884, 782, 796, 806, 807, 790, 796, 793, 758, 108447 + /* 400 */ 753, 732, 692, 696, 682, 686, 667, 544, 291, 521, 108448 + /* 410 */ 510, 365, 358, 139, 114, 54, 14, 25, 108885 108449 }; 108886 108450 #define YY_REDUCE_USE_DFLT (-169) 108887 -#define YY_REDUCE_COUNT (308) 108451 +#define YY_REDUCE_COUNT (309) 108888 108452 #define YY_REDUCE_MIN (-168) 108889 -#define YY_REDUCE_MAX (1391) 108453 +#define YY_REDUCE_MAX (1411) 108890 108454 static const short yy_reduce_ofst[] = { 108891 - /* 0 */ -141, 90, 1095, 222, 158, 156, 19, 17, 10, -104, 108892 - /* 10 */ 378, 316, 311, 12, 180, 249, 598, 464, 397, 1181, 108893 - /* 20 */ 1177, 1175, 1128, 1106, 1096, 1054, 1038, 974, 964, 962, 108894 - /* 30 */ 948, 905, 903, 900, 887, 874, 832, 826, 816, 813, 108895 - /* 40 */ 800, 758, 755, 752, 742, 739, 726, 685, 681, 668, 108896 - /* 50 */ 665, 652, 607, 604, 594, 591, 578, 530, 528, 526, 108897 - /* 60 */ 385, 18, 477, 466, 519, 444, 350, 435, 405, 488, 108898 - /* 70 */ 488, 488, 488, 488, 488, 488, 488, 488, 488, 488, 108899 - /* 80 */ 488, 488, 488, 488, 488, 488, 488, 488, 488, 488, 108900 - /* 90 */ 488, 488, 488, 488, 488, 488, 488, 488, 488, 488, 108901 - /* 100 */ 488, 488, 488, 488, 488, 488, 488, 1040, 678, 1036, 108902 - /* 110 */ 1007, 967, 966, 965, 845, 686, 610, 684, 317, 672, 108903 - /* 120 */ 893, 327, 623, 522, -7, 820, 814, 157, 154, 101, 108904 - /* 130 */ 702, 494, 580, 488, 488, 488, 488, 488, 614, 586, 108905 - /* 140 */ 935, 892, 968, 1245, 1242, 1234, 1225, 798, 798, 1222, 108906 - /* 150 */ 1221, 1218, 1214, 1213, 1212, 1202, 1195, 1191, 1161, 1158, 108907 - /* 160 */ 1140, 1135, 1123, 1112, 1107, 1100, 1080, 1074, 1073, 1072, 108908 - /* 170 */ 1070, 1067, 1048, 1044, 969, 968, 907, 906, 904, 894, 108909 - /* 180 */ 833, 837, 836, 340, 827, 815, 775, 68, 722, 646, 108910 - /* 190 */ -168, 1384, 1380, 1377, 1379, 1376, 1373, 1339, 1365, 1368, 108911 - /* 200 */ 1365, 1365, 1365, 1365, 1365, 1365, 1365, 1320, 1319, 1365, 108912 - /* 210 */ 1365, 1339, 1378, 1349, 1391, 1350, 1342, 1334, 1307, 1341, 108913 - /* 220 */ 1293, 1364, 1363, 1371, 1362, 1370, 1359, 1340, 1354, 1333, 108914 - /* 230 */ 1305, 1304, 1299, 1361, 1328, 1324, 1366, 1282, 1360, 1358, 108915 - /* 240 */ 1278, 1276, 1356, 1292, 1322, 1309, 1317, 1315, 1314, 1312, 108916 - /* 250 */ 1345, 1347, 1302, 1277, 1311, 1303, 1337, 1335, 1252, 1248, 108917 - /* 260 */ 1332, 1330, 1329, 1327, 1326, 1323, 1321, 1297, 1301, 1295, 108918 - /* 270 */ 1294, 1290, 1243, 1240, 1284, 1291, 1286, 1283, 1274, 1281, 108919 - /* 280 */ 1271, 1238, 1241, 1236, 1235, 1227, 1226, 1267, 1266, 1189, 108920 - /* 290 */ 1229, 1223, 1211, 1206, 1201, 1197, 1239, 1237, 1219, 1216, 108921 - /* 300 */ 1209, 1208, 1185, 1089, 1086, 1087, 1137, 1136, 1164, 108455 + /* 0 */ 318, 90, 1095, 221, 157, 21, 159, 18, 150, 390, 108456 + /* 10 */ 385, 378, 380, 315, 325, 249, 529, -71, 8, 1282, 108457 + /* 20 */ 1261, 1225, 1185, 1183, 1181, 1177, 1151, 1128, 1096, 1063, 108458 + /* 30 */ 1059, 985, 982, 964, 962, 948, 908, 890, 874, 834, 108459 + /* 40 */ 832, 816, 813, 800, 759, 746, 742, 739, 726, 684, 108460 + /* 50 */ 681, 668, 665, 652, 612, 593, 591, 537, 524, 518, 108461 + /* 60 */ 504, 455, 511, 376, 517, 247, -168, 24, 420, 463, 108462 + /* 70 */ 463, 463, 463, 463, 463, 463, 463, 463, 463, 463, 108463 + /* 80 */ 463, 463, 463, 463, 463, 463, 463, 463, 463, 463, 108464 + /* 90 */ 463, 463, 463, 463, 463, 463, 463, 463, 463, 463, 108465 + /* 100 */ 463, 463, 463, 463, 463, -74, 463, 463, 1112, 835, 108466 + /* 110 */ 1107, 1039, 1036, 965, 887, 845, 818, 760, 688, 687, 108467 + /* 120 */ 538, 743, 623, 592, 446, 513, 814, 740, 670, 156, 108468 + /* 130 */ 468, 553, 184, 616, 463, 463, 463, 463, 463, 595, 108469 + /* 140 */ 821, 786, 745, 909, 1305, 1302, 1301, 1299, 675, 675, 108470 + /* 150 */ 1295, 1273, 1259, 1245, 1242, 1233, 1222, 1221, 1214, 1213, 108471 + /* 160 */ 1212, 1204, 1184, 1158, 1123, 1119, 1114, 1100, 1070, 1047, 108472 + /* 170 */ 1046, 1040, 1038, 969, 968, 966, 909, 904, 896, 895, 108473 + /* 180 */ 892, 599, 839, 838, 766, 754, 881, 734, 346, 605, 108474 + /* 190 */ 622, -94, 1393, 1401, 1396, 1392, 1391, 1390, 1384, 1361, 108475 + /* 200 */ 1365, 1381, 1365, 1365, 1365, 1365, 1365, 1365, 1365, 1332, 108476 + /* 210 */ 1338, 1365, 1365, 1361, 1399, 1368, 1411, 1359, 1353, 1352, 108477 + /* 220 */ 1329, 1358, 1324, 1366, 1389, 1377, 1386, 1376, 1364, 1371, 108478 + /* 230 */ 1336, 1323, 1321, 1320, 1375, 1344, 1351, 1387, 1300, 1380, 108479 + /* 240 */ 1378, 1298, 1290, 1374, 1316, 1347, 1328, 1337, 1334, 1333, 108480 + /* 250 */ 1327, 1363, 1362, 1318, 1296, 1326, 1322, 1355, 1354, 1269, 108481 + /* 260 */ 1274, 1350, 1349, 1348, 1346, 1345, 1343, 1335, 1315, 1314, 108482 + /* 270 */ 1313, 1312, 1309, 1271, 1267, 1308, 1307, 1306, 1304, 1291, 108483 + /* 280 */ 1303, 1292, 1260, 1266, 1258, 1253, 1247, 1227, 1268, 1257, 108484 + /* 290 */ 1187, 1198, 1200, 1190, 1170, 1168, 1167, 1182, 1189, 1164, 108485 + /* 300 */ 1179, 1162, 1138, 1136, 1061, 1043, 1021, 1111, 1110, 1116, 108922 108486 }; 108923 108487 static const YYACTIONTYPE yy_default[] = { 108924 - /* 0 */ 632, 866, 954, 954, 866, 866, 954, 954, 954, 756, 108925 - /* 10 */ 954, 954, 954, 864, 954, 954, 784, 784, 928, 954, 108926 - /* 20 */ 954, 954, 954, 954, 954, 954, 954, 954, 954, 954, 108927 - /* 30 */ 954, 954, 954, 954, 954, 954, 954, 954, 954, 954, 108928 - /* 40 */ 954, 954, 954, 954, 954, 954, 954, 954, 954, 954, 108929 - /* 50 */ 954, 954, 954, 954, 954, 954, 954, 954, 954, 954, 108930 - /* 60 */ 954, 954, 954, 954, 954, 954, 954, 671, 760, 790, 108931 - /* 70 */ 954, 954, 954, 954, 954, 954, 954, 954, 927, 929, 108932 - /* 80 */ 798, 797, 907, 771, 795, 788, 792, 867, 860, 861, 108933 - /* 90 */ 859, 863, 868, 954, 791, 827, 844, 826, 838, 843, 108934 - /* 100 */ 850, 842, 839, 829, 828, 830, 831, 954, 954, 954, 108935 - /* 110 */ 954, 954, 954, 954, 954, 954, 954, 954, 954, 954, 108936 - /* 120 */ 954, 954, 954, 658, 725, 954, 954, 954, 954, 954, 108937 - /* 130 */ 954, 954, 954, 832, 833, 847, 846, 845, 954, 663, 108938 - /* 140 */ 954, 954, 954, 954, 954, 954, 954, 954, 954, 954, 108939 - /* 150 */ 934, 932, 954, 879, 954, 954, 954, 954, 954, 954, 108940 - /* 160 */ 954, 954, 954, 954, 954, 954, 954, 954, 954, 954, 108941 - /* 170 */ 954, 954, 954, 954, 954, 954, 954, 954, 954, 954, 108942 - /* 180 */ 638, 756, 756, 756, 632, 954, 954, 954, 946, 760, 108943 - /* 190 */ 750, 954, 954, 954, 954, 954, 954, 954, 954, 954, 108944 - /* 200 */ 954, 954, 954, 800, 739, 917, 919, 954, 900, 737, 108945 - /* 210 */ 660, 758, 673, 748, 640, 794, 773, 773, 912, 794, 108946 - /* 220 */ 912, 696, 719, 954, 784, 954, 784, 693, 784, 773, 108947 - /* 230 */ 862, 954, 954, 954, 757, 748, 954, 939, 764, 764, 108948 - /* 240 */ 931, 931, 764, 806, 729, 794, 736, 736, 736, 736, 108949 - /* 250 */ 764, 655, 794, 806, 729, 729, 764, 655, 906, 904, 108950 - /* 260 */ 764, 764, 655, 764, 655, 764, 655, 872, 727, 727, 108951 - /* 270 */ 727, 711, 876, 876, 872, 727, 696, 727, 711, 727, 108952 - /* 280 */ 727, 777, 772, 777, 772, 777, 772, 764, 764, 954, 108953 - /* 290 */ 789, 778, 787, 785, 794, 954, 714, 648, 648, 637, 108954 - /* 300 */ 637, 637, 637, 951, 951, 946, 698, 698, 681, 954, 108955 - /* 310 */ 954, 954, 954, 954, 954, 954, 881, 954, 954, 954, 108956 - /* 320 */ 954, 954, 954, 954, 954, 954, 954, 954, 954, 633, 108957 - /* 330 */ 941, 954, 954, 938, 954, 954, 954, 954, 799, 954, 108958 - /* 340 */ 954, 954, 954, 954, 954, 954, 954, 954, 954, 916, 108959 - /* 350 */ 954, 954, 954, 954, 954, 954, 954, 910, 954, 954, 108960 - /* 360 */ 954, 954, 954, 954, 903, 902, 954, 954, 954, 954, 108961 - /* 370 */ 954, 954, 954, 954, 954, 954, 954, 954, 954, 954, 108962 - /* 380 */ 954, 954, 954, 954, 954, 954, 954, 954, 954, 954, 108963 - /* 390 */ 954, 954, 786, 954, 779, 954, 865, 954, 954, 954, 108964 - /* 400 */ 954, 954, 954, 954, 954, 954, 954, 742, 815, 954, 108965 - /* 410 */ 814, 818, 813, 665, 954, 646, 954, 629, 634, 950, 108966 - /* 420 */ 953, 952, 949, 948, 947, 942, 940, 937, 936, 935, 108967 - /* 430 */ 933, 930, 926, 885, 883, 890, 889, 888, 887, 886, 108968 - /* 440 */ 884, 882, 880, 801, 796, 793, 925, 878, 738, 735, 108969 - /* 450 */ 734, 654, 943, 909, 918, 805, 804, 807, 915, 914, 108970 - /* 460 */ 913, 911, 908, 895, 803, 802, 730, 870, 869, 657, 108971 - /* 470 */ 899, 898, 897, 901, 905, 896, 766, 656, 653, 662, 108972 - /* 480 */ 717, 718, 726, 724, 723, 722, 721, 720, 716, 664, 108973 - /* 490 */ 672, 710, 695, 694, 875, 877, 874, 873, 703, 702, 108974 - /* 500 */ 708, 707, 706, 705, 704, 701, 700, 699, 692, 691, 108975 - /* 510 */ 697, 690, 713, 712, 709, 689, 733, 732, 731, 728, 108976 - /* 520 */ 688, 687, 686, 818, 685, 684, 824, 823, 811, 854, 108977 - /* 530 */ 753, 752, 751, 763, 762, 775, 774, 809, 808, 776, 108978 - /* 540 */ 761, 755, 754, 770, 769, 768, 767, 759, 749, 781, 108979 - /* 550 */ 783, 782, 780, 856, 765, 853, 924, 923, 922, 921, 108980 - /* 560 */ 920, 858, 857, 825, 822, 676, 677, 893, 892, 894, 108981 - /* 570 */ 891, 679, 678, 675, 674, 855, 744, 743, 851, 848, 108982 - /* 580 */ 840, 836, 852, 849, 841, 837, 835, 834, 820, 819, 108983 - /* 590 */ 817, 816, 812, 821, 667, 745, 741, 740, 810, 747, 108984 - /* 600 */ 746, 683, 682, 680, 661, 659, 652, 650, 649, 651, 108985 - /* 610 */ 647, 645, 644, 643, 642, 641, 670, 669, 668, 666, 108986 - /* 620 */ 665, 639, 636, 635, 631, 630, 628, 108488 + /* 0 */ 634, 868, 956, 956, 868, 868, 956, 956, 956, 758, 108489 + /* 10 */ 956, 956, 956, 866, 956, 956, 786, 786, 930, 956, 108490 + /* 20 */ 956, 956, 956, 956, 956, 956, 956, 956, 956, 956, 108491 + /* 30 */ 956, 956, 956, 956, 956, 956, 956, 956, 956, 956, 108492 + /* 40 */ 956, 956, 956, 956, 956, 956, 956, 956, 956, 956, 108493 + /* 50 */ 956, 956, 956, 956, 956, 956, 956, 956, 956, 956, 108494 + /* 60 */ 956, 956, 956, 956, 956, 956, 956, 673, 762, 792, 108495 + /* 70 */ 956, 956, 956, 956, 956, 956, 956, 956, 929, 931, 108496 + /* 80 */ 800, 799, 909, 773, 797, 790, 794, 869, 862, 863, 108497 + /* 90 */ 861, 865, 870, 956, 793, 829, 846, 828, 840, 845, 108498 + /* 100 */ 852, 844, 841, 831, 830, 665, 832, 833, 956, 956, 108499 + /* 110 */ 956, 956, 956, 956, 956, 956, 956, 956, 956, 956, 108500 + /* 120 */ 956, 956, 956, 956, 660, 727, 956, 956, 956, 956, 108501 + /* 130 */ 956, 956, 956, 956, 834, 835, 849, 848, 847, 956, 108502 + /* 140 */ 956, 956, 956, 956, 956, 956, 956, 956, 956, 956, 108503 + /* 150 */ 956, 936, 934, 956, 881, 956, 956, 956, 956, 956, 108504 + /* 160 */ 956, 956, 956, 956, 956, 956, 956, 956, 956, 956, 108505 + /* 170 */ 956, 956, 956, 956, 956, 956, 956, 956, 956, 956, 108506 + /* 180 */ 956, 640, 758, 758, 758, 634, 956, 956, 956, 948, 108507 + /* 190 */ 762, 752, 718, 956, 956, 956, 956, 956, 956, 956, 108508 + /* 200 */ 956, 956, 956, 956, 956, 802, 741, 919, 921, 956, 108509 + /* 210 */ 902, 739, 662, 760, 675, 750, 642, 796, 775, 775, 108510 + /* 220 */ 914, 796, 914, 699, 956, 786, 956, 786, 696, 786, 108511 + /* 230 */ 775, 864, 956, 956, 956, 759, 750, 956, 941, 766, 108512 + /* 240 */ 766, 933, 933, 766, 808, 731, 796, 738, 738, 738, 108513 + /* 250 */ 738, 766, 657, 796, 808, 731, 731, 766, 657, 908, 108514 + /* 260 */ 906, 766, 766, 657, 766, 657, 766, 657, 874, 729, 108515 + /* 270 */ 729, 729, 714, 878, 878, 874, 729, 699, 729, 714, 108516 + /* 280 */ 729, 729, 779, 774, 779, 774, 779, 774, 766, 766, 108517 + /* 290 */ 956, 791, 780, 789, 787, 796, 956, 717, 650, 650, 108518 + /* 300 */ 639, 639, 639, 639, 953, 953, 948, 701, 701, 683, 108519 + /* 310 */ 956, 956, 956, 956, 956, 956, 956, 883, 956, 956, 108520 + /* 320 */ 956, 956, 956, 956, 956, 956, 956, 956, 956, 956, 108521 + /* 330 */ 635, 943, 956, 956, 940, 956, 956, 956, 956, 801, 108522 + /* 340 */ 956, 956, 956, 956, 956, 956, 956, 956, 956, 956, 108523 + /* 350 */ 918, 956, 956, 956, 956, 956, 956, 956, 912, 956, 108524 + /* 360 */ 956, 956, 956, 956, 956, 905, 904, 956, 956, 956, 108525 + /* 370 */ 956, 956, 956, 956, 956, 956, 956, 956, 956, 956, 108526 + /* 380 */ 956, 956, 956, 956, 956, 956, 956, 956, 956, 956, 108527 + /* 390 */ 956, 956, 956, 788, 956, 781, 956, 867, 956, 956, 108528 + /* 400 */ 956, 956, 956, 956, 956, 956, 956, 956, 744, 817, 108529 + /* 410 */ 956, 816, 820, 815, 667, 956, 648, 956, 631, 636, 108530 + /* 420 */ 952, 955, 954, 951, 950, 949, 944, 942, 939, 938, 108531 + /* 430 */ 937, 935, 932, 928, 887, 885, 892, 891, 890, 889, 108532 + /* 440 */ 888, 886, 884, 882, 803, 798, 795, 927, 880, 740, 108533 + /* 450 */ 737, 736, 656, 945, 911, 920, 807, 806, 809, 917, 108534 + /* 460 */ 916, 915, 913, 910, 897, 805, 804, 732, 872, 871, 108535 + /* 470 */ 659, 901, 900, 899, 903, 907, 898, 768, 658, 655, 108536 + /* 480 */ 664, 721, 720, 728, 726, 725, 724, 723, 722, 719, 108537 + /* 490 */ 666, 674, 685, 713, 698, 697, 877, 879, 876, 875, 108538 + /* 500 */ 706, 705, 711, 710, 709, 708, 707, 704, 703, 702, 108539 + /* 510 */ 695, 694, 700, 693, 716, 715, 712, 692, 735, 734, 108540 + /* 520 */ 733, 730, 691, 690, 689, 820, 688, 687, 826, 825, 108541 + /* 530 */ 813, 856, 755, 754, 753, 765, 764, 777, 776, 811, 108542 + /* 540 */ 810, 778, 763, 757, 756, 772, 771, 770, 769, 761, 108543 + /* 550 */ 751, 783, 785, 784, 782, 858, 767, 855, 926, 925, 108544 + /* 560 */ 924, 923, 922, 860, 859, 827, 824, 678, 679, 895, 108545 + /* 570 */ 894, 896, 893, 681, 680, 677, 676, 857, 746, 745, 108546 + /* 580 */ 853, 850, 842, 838, 854, 851, 843, 839, 837, 836, 108547 + /* 590 */ 822, 821, 819, 818, 814, 823, 669, 747, 743, 742, 108548 + /* 600 */ 812, 749, 748, 686, 684, 682, 663, 661, 654, 652, 108549 + /* 610 */ 651, 653, 649, 647, 646, 645, 644, 643, 672, 671, 108550 + /* 620 */ 670, 668, 667, 641, 638, 637, 633, 632, 630, 108987 108551 }; 108988 108552 108989 108553 /* The next table maps tokens into fallback tokens. If a construct 108990 108554 ** like the following: 108991 108555 ** 108992 108556 ** %fallback ID X Y Z. 108993 108557 ** ................................................................................ 109182 108746 "ecmd", "explain", "cmdx", "cmd", 109183 108747 "transtype", "trans_opt", "nm", "savepoint_opt", 109184 108748 "create_table", "create_table_args", "createkw", "temp", 109185 108749 "ifnotexists", "dbnm", "columnlist", "conslist_opt", 109186 108750 "select", "column", "columnid", "type", 109187 108751 "carglist", "id", "ids", "typetoken", 109188 108752 "typename", "signed", "plus_num", "minus_num", 109189 - "ccons", "term", "expr", "onconf", 109190 - "sortorder", "autoinc", "idxlist_opt", "refargs", 109191 - "defer_subclause", "refarg", "refact", "init_deferred_pred_opt", 109192 - "conslist", "tconscomma", "tcons", "idxlist", 108753 + "carg", "ccons", "term", "expr", 108754 + "onconf", "sortorder", "autoinc", "idxlist_opt", 108755 + "refargs", "defer_subclause", "refarg", "refact", 108756 + "init_deferred_pred_opt", "conslist", "tcons", "idxlist", 109193 108757 "defer_subclause_opt", "orconf", "resolvetype", "raisetype", 109194 108758 "ifexists", "fullname", "oneselect", "multiselect_op", 109195 108759 "distinct", "selcollist", "from", "where_opt", 109196 108760 "groupby_opt", "having_opt", "orderby_opt", "limit_opt", 109197 108761 "sclp", "as", "seltablist", "stl_prefix", 109198 108762 "joinop", "indexed_opt", "on_opt", "using_opt", 109199 108763 "joinop2", "inscollist", "sortlist", "nexprlist", ................................................................................ 109262 108826 /* 46 */ "typetoken ::= typename", 109263 108827 /* 47 */ "typetoken ::= typename LP signed RP", 109264 108828 /* 48 */ "typetoken ::= typename LP signed COMMA signed RP", 109265 108829 /* 49 */ "typename ::= ids", 109266 108830 /* 50 */ "typename ::= typename ids", 109267 108831 /* 51 */ "signed ::= plus_num", 109268 108832 /* 52 */ "signed ::= minus_num", 109269 - /* 53 */ "carglist ::= carglist ccons", 108833 + /* 53 */ "carglist ::= carglist carg", 109270 108834 /* 54 */ "carglist ::=", 109271 - /* 55 */ "ccons ::= CONSTRAINT nm", 109272 - /* 56 */ "ccons ::= DEFAULT term", 109273 - /* 57 */ "ccons ::= DEFAULT LP expr RP", 109274 - /* 58 */ "ccons ::= DEFAULT PLUS term", 109275 - /* 59 */ "ccons ::= DEFAULT MINUS term", 109276 - /* 60 */ "ccons ::= DEFAULT id", 109277 - /* 61 */ "ccons ::= NULL onconf", 109278 - /* 62 */ "ccons ::= NOT NULL onconf", 109279 - /* 63 */ "ccons ::= PRIMARY KEY sortorder onconf autoinc", 109280 - /* 64 */ "ccons ::= UNIQUE onconf", 109281 - /* 65 */ "ccons ::= CHECK LP expr RP", 109282 - /* 66 */ "ccons ::= REFERENCES nm idxlist_opt refargs", 109283 - /* 67 */ "ccons ::= defer_subclause", 109284 - /* 68 */ "ccons ::= COLLATE ids", 109285 - /* 69 */ "autoinc ::=", 109286 - /* 70 */ "autoinc ::= AUTOINCR", 109287 - /* 71 */ "refargs ::=", 109288 - /* 72 */ "refargs ::= refargs refarg", 109289 - /* 73 */ "refarg ::= MATCH nm", 109290 - /* 74 */ "refarg ::= ON INSERT refact", 109291 - /* 75 */ "refarg ::= ON DELETE refact", 109292 - /* 76 */ "refarg ::= ON UPDATE refact", 109293 - /* 77 */ "refact ::= SET NULL", 109294 - /* 78 */ "refact ::= SET DEFAULT", 109295 - /* 79 */ "refact ::= CASCADE", 109296 - /* 80 */ "refact ::= RESTRICT", 109297 - /* 81 */ "refact ::= NO ACTION", 109298 - /* 82 */ "defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt", 109299 - /* 83 */ "defer_subclause ::= DEFERRABLE init_deferred_pred_opt", 109300 - /* 84 */ "init_deferred_pred_opt ::=", 109301 - /* 85 */ "init_deferred_pred_opt ::= INITIALLY DEFERRED", 109302 - /* 86 */ "init_deferred_pred_opt ::= INITIALLY IMMEDIATE", 109303 - /* 87 */ "conslist_opt ::=", 109304 - /* 88 */ "conslist_opt ::= COMMA conslist", 109305 - /* 89 */ "conslist ::= conslist tconscomma tcons", 109306 - /* 90 */ "conslist ::= tcons", 109307 - /* 91 */ "tconscomma ::= COMMA", 109308 - /* 92 */ "tconscomma ::=", 108835 + /* 55 */ "carg ::= CONSTRAINT nm ccons", 108836 + /* 56 */ "carg ::= ccons", 108837 + /* 57 */ "ccons ::= DEFAULT term", 108838 + /* 58 */ "ccons ::= DEFAULT LP expr RP", 108839 + /* 59 */ "ccons ::= DEFAULT PLUS term", 108840 + /* 60 */ "ccons ::= DEFAULT MINUS term", 108841 + /* 61 */ "ccons ::= DEFAULT id", 108842 + /* 62 */ "ccons ::= NULL onconf", 108843 + /* 63 */ "ccons ::= NOT NULL onconf", 108844 + /* 64 */ "ccons ::= PRIMARY KEY sortorder onconf autoinc", 108845 + /* 65 */ "ccons ::= UNIQUE onconf", 108846 + /* 66 */ "ccons ::= CHECK LP expr RP", 108847 + /* 67 */ "ccons ::= REFERENCES nm idxlist_opt refargs", 108848 + /* 68 */ "ccons ::= defer_subclause", 108849 + /* 69 */ "ccons ::= COLLATE ids", 108850 + /* 70 */ "autoinc ::=", 108851 + /* 71 */ "autoinc ::= AUTOINCR", 108852 + /* 72 */ "refargs ::=", 108853 + /* 73 */ "refargs ::= refargs refarg", 108854 + /* 74 */ "refarg ::= MATCH nm", 108855 + /* 75 */ "refarg ::= ON INSERT refact", 108856 + /* 76 */ "refarg ::= ON DELETE refact", 108857 + /* 77 */ "refarg ::= ON UPDATE refact", 108858 + /* 78 */ "refact ::= SET NULL", 108859 + /* 79 */ "refact ::= SET DEFAULT", 108860 + /* 80 */ "refact ::= CASCADE", 108861 + /* 81 */ "refact ::= RESTRICT", 108862 + /* 82 */ "refact ::= NO ACTION", 108863 + /* 83 */ "defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt", 108864 + /* 84 */ "defer_subclause ::= DEFERRABLE init_deferred_pred_opt", 108865 + /* 85 */ "init_deferred_pred_opt ::=", 108866 + /* 86 */ "init_deferred_pred_opt ::= INITIALLY DEFERRED", 108867 + /* 87 */ "init_deferred_pred_opt ::= INITIALLY IMMEDIATE", 108868 + /* 88 */ "conslist_opt ::=", 108869 + /* 89 */ "conslist_opt ::= COMMA conslist", 108870 + /* 90 */ "conslist ::= conslist COMMA tcons", 108871 + /* 91 */ "conslist ::= conslist tcons", 108872 + /* 92 */ "conslist ::= tcons", 109309 108873 /* 93 */ "tcons ::= CONSTRAINT nm", 109310 108874 /* 94 */ "tcons ::= PRIMARY KEY LP idxlist autoinc RP onconf", 109311 108875 /* 95 */ "tcons ::= UNIQUE LP idxlist RP onconf", 109312 108876 /* 96 */ "tcons ::= CHECK LP expr RP onconf", 109313 108877 /* 97 */ "tcons ::= FOREIGN KEY LP idxlist RP REFERENCES nm idxlist_opt refargs defer_subclause_opt", 109314 108878 /* 98 */ "defer_subclause_opt ::=", 109315 108879 /* 99 */ "defer_subclause_opt ::= defer_subclause", ................................................................................ 109620 109184 */ 109621 109185 case 160: /* select */ 109622 109186 case 194: /* oneselect */ 109623 109187 { 109624 109188 sqlite3SelectDelete(pParse->db, (yypminor->yy159)); 109625 109189 } 109626 109190 break; 109627 - case 173: /* term */ 109628 - case 174: /* expr */ 109191 + case 174: /* term */ 109192 + case 175: /* expr */ 109629 109193 { 109630 109194 sqlite3ExprDelete(pParse->db, (yypminor->yy342).pExpr); 109631 109195 } 109632 109196 break; 109633 - case 178: /* idxlist_opt */ 109197 + case 179: /* idxlist_opt */ 109634 109198 case 187: /* idxlist */ 109635 109199 case 197: /* selcollist */ 109636 109200 case 200: /* groupby_opt */ 109637 109201 case 202: /* orderby_opt */ 109638 109202 case 204: /* sclp */ 109639 109203 case 214: /* sortlist */ 109640 109204 case 215: /* nexprlist */ ................................................................................ 109983 109547 { 167, 6 }, 109984 109548 { 168, 1 }, 109985 109549 { 168, 2 }, 109986 109550 { 169, 1 }, 109987 109551 { 169, 1 }, 109988 109552 { 164, 2 }, 109989 109553 { 164, 0 }, 109990 - { 172, 2 }, 109991 - { 172, 2 }, 109992 - { 172, 4 }, 109993 109554 { 172, 3 }, 109994 - { 172, 3 }, 109995 - { 172, 2 }, 109996 - { 172, 2 }, 109997 - { 172, 3 }, 109998 - { 172, 5 }, 109999 - { 172, 2 }, 110000 - { 172, 4 }, 110001 - { 172, 4 }, 110002 109555 { 172, 1 }, 110003 - { 172, 2 }, 110004 - { 177, 0 }, 110005 - { 177, 1 }, 110006 - { 179, 0 }, 110007 - { 179, 2 }, 110008 - { 181, 2 }, 110009 - { 181, 3 }, 110010 - { 181, 3 }, 110011 - { 181, 3 }, 109556 + { 173, 2 }, 109557 + { 173, 4 }, 109558 + { 173, 3 }, 109559 + { 173, 3 }, 109560 + { 173, 2 }, 109561 + { 173, 2 }, 109562 + { 173, 3 }, 109563 + { 173, 5 }, 109564 + { 173, 2 }, 109565 + { 173, 4 }, 109566 + { 173, 4 }, 109567 + { 173, 1 }, 109568 + { 173, 2 }, 109569 + { 178, 0 }, 109570 + { 178, 1 }, 109571 + { 180, 0 }, 109572 + { 180, 2 }, 110012 109573 { 182, 2 }, 110013 - { 182, 2 }, 110014 - { 182, 1 }, 110015 - { 182, 1 }, 110016 - { 182, 2 }, 110017 - { 180, 3 }, 110018 - { 180, 2 }, 110019 - { 183, 0 }, 109574 + { 182, 3 }, 109575 + { 182, 3 }, 109576 + { 182, 3 }, 109577 + { 183, 2 }, 109578 + { 183, 2 }, 109579 + { 183, 1 }, 109580 + { 183, 1 }, 110020 109581 { 183, 2 }, 110021 - { 183, 2 }, 109582 + { 181, 3 }, 109583 + { 181, 2 }, 109584 + { 184, 0 }, 109585 + { 184, 2 }, 109586 + { 184, 2 }, 110022 109587 { 159, 0 }, 110023 109588 { 159, 2 }, 110024 - { 184, 3 }, 110025 - { 184, 1 }, 109589 + { 185, 3 }, 109590 + { 185, 2 }, 110026 109591 { 185, 1 }, 110027 - { 185, 0 }, 110028 109592 { 186, 2 }, 110029 109593 { 186, 7 }, 110030 109594 { 186, 5 }, 110031 109595 { 186, 5 }, 110032 109596 { 186, 10 }, 110033 109597 { 188, 0 }, 110034 109598 { 188, 1 }, 110035 - { 175, 0 }, 110036 - { 175, 3 }, 109599 + { 176, 0 }, 109600 + { 176, 3 }, 110037 109601 { 189, 0 }, 110038 109602 { 189, 2 }, 110039 109603 { 190, 1 }, 110040 109604 { 190, 1 }, 110041 109605 { 190, 1 }, 110042 109606 { 147, 4 }, 110043 109607 { 192, 2 }, ................................................................................ 110083 109647 { 209, 2 }, 110084 109648 { 211, 4 }, 110085 109649 { 211, 0 }, 110086 109650 { 202, 0 }, 110087 109651 { 202, 3 }, 110088 109652 { 214, 4 }, 110089 109653 { 214, 2 }, 110090 - { 176, 1 }, 110091 - { 176, 1 }, 110092 - { 176, 0 }, 109654 + { 177, 1 }, 109655 + { 177, 1 }, 109656 + { 177, 0 }, 110093 109657 { 200, 0 }, 110094 109658 { 200, 3 }, 110095 109659 { 201, 0 }, 110096 109660 { 201, 2 }, 110097 109661 { 203, 0 }, 110098 109662 { 203, 2 }, 110099 109663 { 203, 4 }, ................................................................................ 110111 109675 { 217, 1 }, 110112 109676 { 219, 4 }, 110113 109677 { 219, 5 }, 110114 109678 { 218, 0 }, 110115 109679 { 218, 3 }, 110116 109680 { 213, 3 }, 110117 109681 { 213, 1 }, 109682 + { 175, 1 }, 109683 + { 175, 3 }, 110118 109684 { 174, 1 }, 110119 - { 174, 3 }, 110120 - { 173, 1 }, 109685 + { 175, 1 }, 109686 + { 175, 1 }, 109687 + { 175, 3 }, 109688 + { 175, 5 }, 110121 109689 { 174, 1 }, 110122 109690 { 174, 1 }, 110123 - { 174, 3 }, 110124 - { 174, 5 }, 110125 - { 173, 1 }, 110126 - { 173, 1 }, 110127 - { 174, 1 }, 109691 + { 175, 1 }, 109692 + { 175, 1 }, 109693 + { 175, 3 }, 109694 + { 175, 6 }, 109695 + { 175, 5 }, 109696 + { 175, 4 }, 110128 109697 { 174, 1 }, 110129 - { 174, 3 }, 110130 - { 174, 6 }, 110131 - { 174, 5 }, 110132 - { 174, 4 }, 110133 - { 173, 1 }, 110134 - { 174, 3 }, 110135 - { 174, 3 }, 110136 - { 174, 3 }, 110137 - { 174, 3 }, 110138 - { 174, 3 }, 110139 - { 174, 3 }, 110140 - { 174, 3 }, 110141 - { 174, 3 }, 109698 + { 175, 3 }, 109699 + { 175, 3 }, 109700 + { 175, 3 }, 109701 + { 175, 3 }, 109702 + { 175, 3 }, 109703 + { 175, 3 }, 109704 + { 175, 3 }, 109705 + { 175, 3 }, 110142 109706 { 221, 1 }, 110143 109707 { 221, 2 }, 110144 109708 { 221, 1 }, 110145 109709 { 221, 2 }, 110146 - { 174, 3 }, 110147 - { 174, 5 }, 110148 - { 174, 2 }, 110149 - { 174, 3 }, 110150 - { 174, 3 }, 110151 - { 174, 4 }, 110152 - { 174, 2 }, 110153 - { 174, 2 }, 110154 - { 174, 2 }, 110155 - { 174, 2 }, 109710 + { 175, 3 }, 109711 + { 175, 5 }, 109712 + { 175, 2 }, 109713 + { 175, 3 }, 109714 + { 175, 3 }, 109715 + { 175, 4 }, 109716 + { 175, 2 }, 109717 + { 175, 2 }, 109718 + { 175, 2 }, 109719 + { 175, 2 }, 110156 109720 { 222, 1 }, 110157 109721 { 222, 2 }, 110158 - { 174, 5 }, 109722 + { 175, 5 }, 110159 109723 { 223, 1 }, 110160 109724 { 223, 2 }, 110161 - { 174, 5 }, 110162 - { 174, 3 }, 110163 - { 174, 5 }, 110164 - { 174, 4 }, 110165 - { 174, 4 }, 110166 - { 174, 5 }, 109725 + { 175, 5 }, 109726 + { 175, 3 }, 109727 + { 175, 5 }, 109728 + { 175, 4 }, 109729 + { 175, 4 }, 109730 + { 175, 5 }, 110167 109731 { 225, 5 }, 110168 109732 { 225, 4 }, 110169 109733 { 226, 2 }, 110170 109734 { 226, 0 }, 110171 109735 { 224, 1 }, 110172 109736 { 224, 0 }, 110173 109737 { 220, 1 }, 110174 109738 { 220, 0 }, 110175 109739 { 215, 3 }, 110176 109740 { 215, 1 }, 110177 109741 { 147, 11 }, 110178 109742 { 227, 1 }, 110179 109743 { 227, 0 }, 110180 - { 178, 0 }, 110181 - { 178, 3 }, 109744 + { 179, 0 }, 109745 + { 179, 3 }, 110182 109746 { 187, 5 }, 110183 109747 { 187, 3 }, 110184 109748 { 228, 0 }, 110185 109749 { 228, 2 }, 110186 109750 { 147, 4 }, 110187 109751 { 147, 1 }, 110188 109752 { 147, 2 }, ................................................................................ 110221 109785 { 239, 3 }, 110222 109786 { 239, 2 }, 110223 109787 { 237, 7 }, 110224 109788 { 237, 5 }, 110225 109789 { 237, 5 }, 110226 109790 { 237, 5 }, 110227 109791 { 237, 1 }, 110228 - { 174, 4 }, 110229 - { 174, 6 }, 109792 + { 175, 4 }, 109793 + { 175, 6 }, 110230 109794 { 191, 1 }, 110231 109795 { 191, 1 }, 110232 109796 { 191, 1 }, 110233 109797 { 147, 4 }, 110234 109798 { 147, 6 }, 110235 109799 { 147, 3 }, 110236 109800 { 241, 0 }, ................................................................................ 110369 109933 { 110370 109934 pParse->db->lookaside.bEnabled = 0; 110371 109935 yygotominor.yy0 = yymsp[0].minor.yy0; 110372 109936 } 110373 109937 break; 110374 109938 case 28: /* ifnotexists ::= */ 110375 109939 case 31: /* temp ::= */ yytestcase(yyruleno==31); 110376 - case 69: /* autoinc ::= */ yytestcase(yyruleno==69); 110377 - case 82: /* defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt */ yytestcase(yyruleno==82); 110378 - case 84: /* init_deferred_pred_opt ::= */ yytestcase(yyruleno==84); 110379 - case 86: /* init_deferred_pred_opt ::= INITIALLY IMMEDIATE */ yytestcase(yyruleno==86); 109940 + case 70: /* autoinc ::= */ yytestcase(yyruleno==70); 109941 + case 83: /* defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt */ yytestcase(yyruleno==83); 109942 + case 85: /* init_deferred_pred_opt ::= */ yytestcase(yyruleno==85); 109943 + case 87: /* init_deferred_pred_opt ::= INITIALLY IMMEDIATE */ yytestcase(yyruleno==87); 110380 109944 case 98: /* defer_subclause_opt ::= */ yytestcase(yyruleno==98); 110381 109945 case 109: /* ifexists ::= */ yytestcase(yyruleno==109); 110382 109946 case 120: /* distinct ::= ALL */ yytestcase(yyruleno==120); 110383 109947 case 121: /* distinct ::= */ yytestcase(yyruleno==121); 110384 109948 case 221: /* between_op ::= BETWEEN */ yytestcase(yyruleno==221); 110385 109949 case 224: /* in_op ::= IN */ yytestcase(yyruleno==224); 110386 109950 {yygotominor.yy392 = 0;} 110387 109951 break; 110388 109952 case 29: /* ifnotexists ::= IF NOT EXISTS */ 110389 109953 case 30: /* temp ::= TEMP */ yytestcase(yyruleno==30); 110390 - case 70: /* autoinc ::= AUTOINCR */ yytestcase(yyruleno==70); 110391 - case 85: /* init_deferred_pred_opt ::= INITIALLY DEFERRED */ yytestcase(yyruleno==85); 109954 + case 71: /* autoinc ::= AUTOINCR */ yytestcase(yyruleno==71); 109955 + case 86: /* init_deferred_pred_opt ::= INITIALLY DEFERRED */ yytestcase(yyruleno==86); 110392 109956 case 108: /* ifexists ::= IF EXISTS */ yytestcase(yyruleno==108); 110393 109957 case 119: /* distinct ::= DISTINCT */ yytestcase(yyruleno==119); 110394 109958 case 222: /* between_op ::= NOT BETWEEN */ yytestcase(yyruleno==222); 110395 109959 case 225: /* in_op ::= NOT IN */ yytestcase(yyruleno==225); 110396 109960 {yygotominor.yy392 = 1;} 110397 109961 break; 110398 109962 case 32: /* create_table_args ::= LP columnlist conslist_opt RP */ ................................................................................ 110412 109976 yygotominor.yy0.n = (int)(pParse->sLastToken.z-yymsp[-2].minor.yy0.z) + pParse->sLastToken.n; 110413 109977 } 110414 109978 break; 110415 109979 case 37: /* columnid ::= nm */ 110416 109980 { 110417 109981 sqlite3AddColumn(pParse,&yymsp[0].minor.yy0); 110418 109982 yygotominor.yy0 = yymsp[0].minor.yy0; 110419 - pParse->constraintName.n = 0; 110420 109983 } 110421 109984 break; 110422 109985 case 38: /* id ::= ID */ 110423 109986 case 39: /* id ::= INDEXED */ yytestcase(yyruleno==39); 110424 109987 case 40: /* ids ::= ID|STRING */ yytestcase(yyruleno==40); 110425 109988 case 41: /* nm ::= id */ yytestcase(yyruleno==41); 110426 109989 case 42: /* nm ::= STRING */ yytestcase(yyruleno==42); ................................................................................ 110458 110021 yygotominor.yy0.z = yymsp[-5].minor.yy0.z; 110459 110022 yygotominor.yy0.n = (int)(&yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n] - yymsp[-5].minor.yy0.z); 110460 110023 } 110461 110024 break; 110462 110025 case 50: /* typename ::= typename ids */ 110463 110026 {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);} 110464 110027 break; 110465 - case 55: /* ccons ::= CONSTRAINT nm */ 110466 - case 93: /* tcons ::= CONSTRAINT nm */ yytestcase(yyruleno==93); 110467 -{pParse->constraintName = yymsp[0].minor.yy0;} 110468 - break; 110469 - case 56: /* ccons ::= DEFAULT term */ 110470 - case 58: /* ccons ::= DEFAULT PLUS term */ yytestcase(yyruleno==58); 110028 + case 57: /* ccons ::= DEFAULT term */ 110029 + case 59: /* ccons ::= DEFAULT PLUS term */ yytestcase(yyruleno==59); 110471 110030 {sqlite3AddDefaultValue(pParse,&yymsp[0].minor.yy342);} 110472 110031 break; 110473 - case 57: /* ccons ::= DEFAULT LP expr RP */ 110032 + case 58: /* ccons ::= DEFAULT LP expr RP */ 110474 110033 {sqlite3AddDefaultValue(pParse,&yymsp[-1].minor.yy342);} 110475 110034 break; 110476 - case 59: /* ccons ::= DEFAULT MINUS term */ 110035 + case 60: /* ccons ::= DEFAULT MINUS term */ 110477 110036 { 110478 110037 ExprSpan v; 110479 110038 v.pExpr = sqlite3PExpr(pParse, TK_UMINUS, yymsp[0].minor.yy342.pExpr, 0, 0); 110480 110039 v.zStart = yymsp[-1].minor.yy0.z; 110481 110040 v.zEnd = yymsp[0].minor.yy342.zEnd; 110482 110041 sqlite3AddDefaultValue(pParse,&v); 110483 110042 } 110484 110043 break; 110485 - case 60: /* ccons ::= DEFAULT id */ 110044 + case 61: /* ccons ::= DEFAULT id */ 110486 110045 { 110487 110046 ExprSpan v; 110488 110047 spanExpr(&v, pParse, TK_STRING, &yymsp[0].minor.yy0); 110489 110048 sqlite3AddDefaultValue(pParse,&v); 110490 110049 } 110491 110050 break; 110492 - case 62: /* ccons ::= NOT NULL onconf */ 110051 + case 63: /* ccons ::= NOT NULL onconf */ 110493 110052 {sqlite3AddNotNull(pParse, yymsp[0].minor.yy392);} 110494 110053 break; 110495 - case 63: /* ccons ::= PRIMARY KEY sortorder onconf autoinc */ 110054 + case 64: /* ccons ::= PRIMARY KEY sortorder onconf autoinc */ 110496 110055 {sqlite3AddPrimaryKey(pParse,0,yymsp[-1].minor.yy392,yymsp[0].minor.yy392,yymsp[-2].minor.yy392);} 110497 110056 break; 110498 - case 64: /* ccons ::= UNIQUE onconf */ 110057 + case 65: /* ccons ::= UNIQUE onconf */ 110499 110058 {sqlite3CreateIndex(pParse,0,0,0,0,yymsp[0].minor.yy392,0,0,0,0);} 110500 110059 break; 110501 - case 65: /* ccons ::= CHECK LP expr RP */ 110060 + case 66: /* ccons ::= CHECK LP expr RP */ 110502 110061 {sqlite3AddCheckConstraint(pParse,yymsp[-1].minor.yy342.pExpr);} 110503 110062 break; 110504 - case 66: /* ccons ::= REFERENCES nm idxlist_opt refargs */ 110063 + case 67: /* ccons ::= REFERENCES nm idxlist_opt refargs */ 110505 110064 {sqlite3CreateForeignKey(pParse,0,&yymsp[-2].minor.yy0,yymsp[-1].minor.yy442,yymsp[0].minor.yy392);} 110506 110065 break; 110507 - case 67: /* ccons ::= defer_subclause */ 110066 + case 68: /* ccons ::= defer_subclause */ 110508 110067 {sqlite3DeferForeignKey(pParse,yymsp[0].minor.yy392);} 110509 110068 break; 110510 - case 68: /* ccons ::= COLLATE ids */ 110069 + case 69: /* ccons ::= COLLATE ids */ 110511 110070 {sqlite3AddCollateType(pParse, &yymsp[0].minor.yy0);} 110512 110071 break; 110513 - case 71: /* refargs ::= */ 110072 + case 72: /* refargs ::= */ 110514 110073 { yygotominor.yy392 = OE_None*0x0101; /* EV: R-19803-45884 */} 110515 110074 break; 110516 - case 72: /* refargs ::= refargs refarg */ 110075 + case 73: /* refargs ::= refargs refarg */ 110517 110076 { yygotominor.yy392 = (yymsp[-1].minor.yy392 & ~yymsp[0].minor.yy207.mask) | yymsp[0].minor.yy207.value; } 110518 110077 break; 110519 - case 73: /* refarg ::= MATCH nm */ 110520 - case 74: /* refarg ::= ON INSERT refact */ yytestcase(yyruleno==74); 110078 + case 74: /* refarg ::= MATCH nm */ 110079 + case 75: /* refarg ::= ON INSERT refact */ yytestcase(yyruleno==75); 110521 110080 { yygotominor.yy207.value = 0; yygotominor.yy207.mask = 0x000000; } 110522 110081 break; 110523 - case 75: /* refarg ::= ON DELETE refact */ 110082 + case 76: /* refarg ::= ON DELETE refact */ 110524 110083 { yygotominor.yy207.value = yymsp[0].minor.yy392; yygotominor.yy207.mask = 0x0000ff; } 110525 110084 break; 110526 - case 76: /* refarg ::= ON UPDATE refact */ 110085 + case 77: /* refarg ::= ON UPDATE refact */ 110527 110086 { yygotominor.yy207.value = yymsp[0].minor.yy392<<8; yygotominor.yy207.mask = 0x00ff00; } 110528 110087 break; 110529 - case 77: /* refact ::= SET NULL */ 110088 + case 78: /* refact ::= SET NULL */ 110530 110089 { yygotominor.yy392 = OE_SetNull; /* EV: R-33326-45252 */} 110531 110090 break; 110532 - case 78: /* refact ::= SET DEFAULT */ 110091 + case 79: /* refact ::= SET DEFAULT */ 110533 110092 { yygotominor.yy392 = OE_SetDflt; /* EV: R-33326-45252 */} 110534 110093 break; 110535 - case 79: /* refact ::= CASCADE */ 110094 + case 80: /* refact ::= CASCADE */ 110536 110095 { yygotominor.yy392 = OE_Cascade; /* EV: R-33326-45252 */} 110537 110096 break; 110538 - case 80: /* refact ::= RESTRICT */ 110097 + case 81: /* refact ::= RESTRICT */ 110539 110098 { yygotominor.yy392 = OE_Restrict; /* EV: R-33326-45252 */} 110540 110099 break; 110541 - case 81: /* refact ::= NO ACTION */ 110100 + case 82: /* refact ::= NO ACTION */ 110542 110101 { yygotominor.yy392 = OE_None; /* EV: R-33326-45252 */} 110543 110102 break; 110544 - case 83: /* defer_subclause ::= DEFERRABLE init_deferred_pred_opt */ 110103 + case 84: /* defer_subclause ::= DEFERRABLE init_deferred_pred_opt */ 110545 110104 case 99: /* defer_subclause_opt ::= defer_subclause */ yytestcase(yyruleno==99); 110546 110105 case 101: /* onconf ::= ON CONFLICT resolvetype */ yytestcase(yyruleno==101); 110547 110106 case 104: /* resolvetype ::= raisetype */ yytestcase(yyruleno==104); 110548 110107 {yygotominor.yy392 = yymsp[0].minor.yy392;} 110549 110108 break; 110550 - case 87: /* conslist_opt ::= */ 110109 + case 88: /* conslist_opt ::= */ 110551 110110 {yygotominor.yy0.n = 0; yygotominor.yy0.z = 0;} 110552 110111 break; 110553 - case 88: /* conslist_opt ::= COMMA conslist */ 110112 + case 89: /* conslist_opt ::= COMMA conslist */ 110554 110113 {yygotominor.yy0 = yymsp[-1].minor.yy0;} 110555 110114 break; 110556 - case 91: /* tconscomma ::= COMMA */ 110557 -{pParse->constraintName.n = 0;} 110558 - break; 110559 110115 case 94: /* tcons ::= PRIMARY KEY LP idxlist autoinc RP onconf */ 110560 110116 {sqlite3AddPrimaryKey(pParse,yymsp[-3].minor.yy442,yymsp[0].minor.yy392,yymsp[-2].minor.yy392,0);} 110561 110117 break; 110562 110118 case 95: /* tcons ::= UNIQUE LP idxlist RP onconf */ 110563 110119 {sqlite3CreateIndex(pParse,0,0,0,yymsp[-2].minor.yy442,yymsp[0].minor.yy392,0,0,0,0);} 110564 110120 break; 110565 110121 case 96: /* tcons ::= CHECK LP expr RP onconf */ ................................................................................ 110967 110523 case 204: /* expr ::= expr PLUS|MINUS expr */ yytestcase(yyruleno==204); 110968 110524 case 205: /* expr ::= expr STAR|SLASH|REM expr */ yytestcase(yyruleno==205); 110969 110525 case 206: /* expr ::= expr CONCAT expr */ yytestcase(yyruleno==206); 110970 110526 {spanBinaryExpr(&yygotominor.yy342,pParse,yymsp[-1].major,&yymsp[-2].minor.yy342,&yymsp[0].minor.yy342);} 110971 110527 break; 110972 110528 case 207: /* likeop ::= LIKE_KW */ 110973 110529 case 209: /* likeop ::= MATCH */ yytestcase(yyruleno==209); 110974 -{yygotominor.yy318.eOperator = yymsp[0].minor.yy0; yygotominor.yy318.bNot = 0;} 110530 +{yygotominor.yy318.eOperator = yymsp[0].minor.yy0; yygotominor.yy318.not = 0;} 110975 110531 break; 110976 110532 case 208: /* likeop ::= NOT LIKE_KW */ 110977 110533 case 210: /* likeop ::= NOT MATCH */ yytestcase(yyruleno==210); 110978 -{yygotominor.yy318.eOperator = yymsp[0].minor.yy0; yygotominor.yy318.bNot = 1;} 110534 +{yygotominor.yy318.eOperator = yymsp[0].minor.yy0; yygotominor.yy318.not = 1;} 110979 110535 break; 110980 110536 case 211: /* expr ::= expr likeop expr */ 110981 110537 { 110982 110538 ExprList *pList; 110983 110539 pList = sqlite3ExprListAppend(pParse,0, yymsp[0].minor.yy342.pExpr); 110984 110540 pList = sqlite3ExprListAppend(pParse,pList, yymsp[-2].minor.yy342.pExpr); 110985 110541 yygotominor.yy342.pExpr = sqlite3ExprFunction(pParse, pList, &yymsp[-1].minor.yy318.eOperator); 110986 - if( yymsp[-1].minor.yy318.bNot ) yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy342.pExpr, 0, 0); 110542 + if( yymsp[-1].minor.yy318.not ) yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy342.pExpr, 0, 0); 110987 110543 yygotominor.yy342.zStart = yymsp[-2].minor.yy342.zStart; 110988 110544 yygotominor.yy342.zEnd = yymsp[0].minor.yy342.zEnd; 110989 110545 if( yygotominor.yy342.pExpr ) yygotominor.yy342.pExpr->flags |= EP_InfixFunc; 110990 110546 } 110991 110547 break; 110992 110548 case 212: /* expr ::= expr likeop expr ESCAPE expr */ 110993 110549 { 110994 110550 ExprList *pList; 110995 110551 pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy342.pExpr); 110996 110552 pList = sqlite3ExprListAppend(pParse,pList, yymsp[-4].minor.yy342.pExpr); 110997 110553 pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy342.pExpr); 110998 110554 yygotominor.yy342.pExpr = sqlite3ExprFunction(pParse, pList, &yymsp[-3].minor.yy318.eOperator); 110999 - if( yymsp[-3].minor.yy318.bNot ) yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy342.pExpr, 0, 0); 110555 + if( yymsp[-3].minor.yy318.not ) yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy342.pExpr, 0, 0); 111000 110556 yygotominor.yy342.zStart = yymsp[-4].minor.yy342.zStart; 111001 110557 yygotominor.yy342.zEnd = yymsp[0].minor.yy342.zEnd; 111002 110558 if( yygotominor.yy342.pExpr ) yygotominor.yy342.pExpr->flags |= EP_InfixFunc; 111003 110559 } 111004 110560 break; 111005 110561 case 213: /* expr ::= expr ISNULL|NOTNULL */ 111006 110562 {spanUnaryPostfix(&yygotominor.yy342,pParse,yymsp[0].major,&yymsp[-1].minor.yy342,&yymsp[0].minor.yy0);} ................................................................................ 111419 110975 /* (21) savepoint_opt ::= */ yytestcase(yyruleno==21); 111420 110976 /* (25) cmd ::= create_table create_table_args */ yytestcase(yyruleno==25); 111421 110977 /* (34) columnlist ::= columnlist COMMA column */ yytestcase(yyruleno==34); 111422 110978 /* (35) columnlist ::= column */ yytestcase(yyruleno==35); 111423 110979 /* (44) type ::= */ yytestcase(yyruleno==44); 111424 110980 /* (51) signed ::= plus_num */ yytestcase(yyruleno==51); 111425 110981 /* (52) signed ::= minus_num */ yytestcase(yyruleno==52); 111426 - /* (53) carglist ::= carglist ccons */ yytestcase(yyruleno==53); 110982 + /* (53) carglist ::= carglist carg */ yytestcase(yyruleno==53); 111427 110983 /* (54) carglist ::= */ yytestcase(yyruleno==54); 111428 - /* (61) ccons ::= NULL onconf */ yytestcase(yyruleno==61); 111429 - /* (89) conslist ::= conslist tconscomma tcons */ yytestcase(yyruleno==89); 111430 - /* (90) conslist ::= tcons */ yytestcase(yyruleno==90); 111431 - /* (92) tconscomma ::= */ yytestcase(yyruleno==92); 110984 + /* (55) carg ::= CONSTRAINT nm ccons */ yytestcase(yyruleno==55); 110985 + /* (56) carg ::= ccons */ yytestcase(yyruleno==56); 110986 + /* (62) ccons ::= NULL onconf */ yytestcase(yyruleno==62); 110987 + /* (90) conslist ::= conslist COMMA tcons */ yytestcase(yyruleno==90); 110988 + /* (91) conslist ::= conslist tcons */ yytestcase(yyruleno==91); 110989 + /* (92) conslist ::= tcons */ yytestcase(yyruleno==92); 110990 + /* (93) tcons ::= CONSTRAINT nm */ yytestcase(yyruleno==93); 111432 110991 /* (277) foreach_clause ::= */ yytestcase(yyruleno==277); 111433 110992 /* (278) foreach_clause ::= FOR EACH ROW */ yytestcase(yyruleno==278); 111434 110993 /* (285) tridxby ::= */ yytestcase(yyruleno==285); 111435 110994 /* (303) database_kw_opt ::= DATABASE */ yytestcase(yyruleno==303); 111436 110995 /* (304) database_kw_opt ::= */ yytestcase(yyruleno==304); 111437 110996 /* (312) kwcolumn_opt ::= */ yytestcase(yyruleno==312); 111438 110997 /* (313) kwcolumn_opt ::= COLUMNKW */ yytestcase(yyruleno==313); ................................................................................ 116332 115891 ** 116333 115892 ** FTS3 used to optionally store character offsets using a compile-time 116334 115893 ** option. But that functionality is no longer supported. 116335 115894 ** 116336 115895 ** A doclist is stored like this: 116337 115896 ** 116338 115897 ** array { 116339 -** varint docid; (delta from previous doclist) 115898 +** varint docid; 116340 115899 ** array { (position list for column 0) 116341 115900 ** varint position; (2 more than the delta from previous position) 116342 115901 ** } 116343 115902 ** array { 116344 115903 ** varint POS_COLUMN; (marks start of position list for new column) 116345 115904 ** varint column; (index of new column) 116346 115905 ** array { ................................................................................ 116363 115922 ** value: 123 5 9 1 1 14 35 0 234 72 0 116364 115923 ** 116365 115924 ** The 123 value is the first docid. For column zero in this document 116366 115925 ** there are two matches at positions 3 and 10 (5-2 and 9-2+3). The 1 116367 115926 ** at D signals the start of a new column; the 1 at E indicates that the 116368 115927 ** new column is column number 1. There are two positions at 12 and 45 116369 115928 ** (14-2 and 35-2+12). The 0 at H indicate the end-of-document. The 116370 -** 234 at I is the delta to next docid (357). It has one position 70 116371 -** (72-2) and then terminates with the 0 at K. 115929 +** 234 at I is the next docid. It has one position 72 (72-2) and then 115930 +** terminates with the 0 at K. 116372 115931 ** 116373 115932 ** A "position-list" is the list of positions for multiple columns for 116374 115933 ** a single docid. A "column-list" is the set of positions for a single 116375 115934 ** column. Hence, a position-list consists of one or more column-lists, 116376 115935 ** a document record consists of a docid followed by a position-list and 116377 115936 ** a doclist consists of one or more document records. 116378 115937 ** ................................................................................ 116899 116458 */ 116900 116459 #define SizeofArray(X) ((int)(sizeof(X)/sizeof(X[0]))) 116901 116460 116902 116461 116903 116462 #ifndef MIN 116904 116463 # define MIN(x,y) ((x)<(y)?(x):(y)) 116905 116464 #endif 116906 -#ifndef MAX 116907 -# define MAX(x,y) ((x)>(y)?(x):(y)) 116908 -#endif 116909 116465 116910 116466 /* 116911 116467 ** Maximum length of a varint encoded integer. The varint format is different 116912 116468 ** from that used by SQLite, so the maximum length is 10, not 9. 116913 116469 */ 116914 116470 #define FTS3_VARINT_MAX 10 116915 116471 ................................................................................ 116956 116512 ** false. 116957 116513 */ 116958 116514 #ifdef SQLITE_COVERAGE_TEST 116959 116515 # define ALWAYS(x) (1) 116960 116516 # define NEVER(X) (0) 116961 116517 #else 116962 116518 # define ALWAYS(x) (x) 116963 -# define NEVER(x) (x) 116519 +# define NEVER(X) (x) 116964 116520 #endif 116965 116521 116966 116522 /* 116967 116523 ** Internal types used by SQLite. 116968 116524 */ 116969 116525 typedef unsigned char u8; /* 1-byte (or larger) unsigned integer */ 116970 116526 typedef short int i16; /* 2-byte (or larger) signed integer */ 116971 116527 typedef unsigned int u32; /* 4-byte unsigned integer */ 116972 116528 typedef sqlite3_uint64 u64; /* 8-byte unsigned integer */ 116973 -typedef sqlite3_int64 i64; /* 8-byte signed integer */ 116974 116529 116975 116530 /* 116976 116531 ** Macro used to suppress compiler warnings for unused parameters. 116977 116532 */ 116978 116533 #define UNUSED_PARAMETER(x) (void)(x) 116979 116534 116980 116535 /* ................................................................................ 117029 116584 const char *zDb; /* logical database name */ 117030 116585 const char *zName; /* virtual table name */ 117031 116586 int nColumn; /* number of named columns in virtual table */ 117032 116587 char **azColumn; /* column names. malloced */ 117033 116588 sqlite3_tokenizer *pTokenizer; /* tokenizer for inserts and queries */ 117034 116589 char *zContentTbl; /* content=xxx option, or NULL */ 117035 116590 char *zLanguageid; /* languageid=xxx option, or NULL */ 117036 - u8 bAutoincrmerge; /* True if automerge=1 */ 117037 - u32 nLeafAdd; /* Number of leaf blocks added this trans */ 117038 116591 117039 116592 /* Precompiled statements used by the implementation. Each of these 117040 116593 ** statements is run and reset within a single virtual table API call. 117041 116594 */ 117042 - sqlite3_stmt *aStmt[37]; 116595 + sqlite3_stmt *aStmt[28]; 117043 116596 117044 116597 char *zReadExprlist; 117045 116598 char *zWriteExprlist; 117046 116599 117047 116600 int nNodeSize; /* Soft limit for node size */ 117048 - u8 bFts4; /* True for FTS4, false for FTS3 */ 117049 116601 u8 bHasStat; /* True if %_stat table exists */ 117050 116602 u8 bHasDocsize; /* True if %_docsize table exists */ 117051 116603 u8 bDescIdx; /* True if doclists are in reverse order */ 117052 - u8 bIgnoreSavepoint; /* True to ignore xSavepoint invocations */ 117053 116604 int nPgsz; /* Page size for host database */ 117054 116605 char *zSegmentsTbl; /* Name of %_segments table */ 117055 116606 sqlite3_blob *pSegments; /* Blob handle open on %_segments table */ 117056 116607 117057 - /* 116608 + /* TODO: Fix the first paragraph of this comment. 116609 + ** 117058 116610 ** The following array of hash tables is used to buffer pending index 117059 - ** updates during transactions. All pending updates buffered at any one 117060 - ** time must share a common language-id (see the FTS4 langid= feature). 117061 - ** The current language id is stored in variable iPrevLangid. 116611 + ** updates during transactions. Variable nPendingData estimates the memory 116612 + ** size of the pending data, including hash table overhead, not including 116613 + ** malloc overhead. When nPendingData exceeds nMaxPendingData, the buffer 116614 + ** is flushed automatically. Variable iPrevDocid is the docid of the most 116615 + ** recently inserted record. 117062 116616 ** 117063 116617 ** A single FTS4 table may have multiple full-text indexes. For each index 117064 116618 ** there is an entry in the aIndex[] array. Index 0 is an index of all the 117065 116619 ** terms that appear in the document set. Each subsequent index in aIndex[] 117066 116620 ** is an index of prefixes of a specific length. 117067 - ** 117068 - ** Variable nPendingData contains an estimate the memory consumed by the 117069 - ** pending data structures, including hash table overhead, but not including 117070 - ** malloc overhead. When nPendingData exceeds nMaxPendingData, all hash 117071 - ** tables are flushed to disk. Variable iPrevDocid is the docid of the most 117072 - ** recently inserted record. 117073 116621 */ 117074 116622 int nIndex; /* Size of aIndex[] */ 117075 116623 struct Fts3Index { 117076 116624 int nPrefix; /* Prefix length (0 for main terms index) */ 117077 116625 Fts3Hash hPending; /* Pending terms table for this index */ 117078 116626 } *aIndex; 117079 116627 int nMaxPendingData; /* Max pending data before flush to disk */ ................................................................................ 117264 116812 SQLITE_PRIVATE int sqlite3Fts3SelectDocsize(Fts3Table *, sqlite3_int64, sqlite3_stmt **); 117265 116813 117266 116814 SQLITE_PRIVATE void sqlite3Fts3FreeDeferredTokens(Fts3Cursor *); 117267 116815 SQLITE_PRIVATE int sqlite3Fts3DeferToken(Fts3Cursor *, Fts3PhraseToken *, int); 117268 116816 SQLITE_PRIVATE int sqlite3Fts3CacheDeferredDoclists(Fts3Cursor *); 117269 116817 SQLITE_PRIVATE void sqlite3Fts3FreeDeferredDoclists(Fts3Cursor *); 117270 116818 SQLITE_PRIVATE void sqlite3Fts3SegmentsClose(Fts3Table *); 117271 -SQLITE_PRIVATE int sqlite3Fts3MaxLevel(Fts3Table *, int *); 117272 116819 117273 116820 /* Special values interpreted by sqlite3SegReaderCursor() */ 117274 116821 #define FTS3_SEGCURSOR_PENDING -1 117275 116822 #define FTS3_SEGCURSOR_ALL -2 117276 116823 117277 116824 SQLITE_PRIVATE int sqlite3Fts3SegReaderStart(Fts3Table*, Fts3MultiSegReader*, Fts3SegFilter*); 117278 116825 SQLITE_PRIVATE int sqlite3Fts3SegReaderStep(Fts3Table *, Fts3MultiSegReader *); ................................................................................ 117316 116863 /* Output values. Valid only after Fts3SegReaderStep() returns SQLITE_ROW. */ 117317 116864 char *zTerm; /* Pointer to term buffer */ 117318 116865 int nTerm; /* Size of zTerm in bytes */ 117319 116866 char *aDoclist; /* Pointer to doclist buffer */ 117320 116867 int nDoclist; /* Size of aDoclist[] in bytes */ 117321 116868 }; 117322 116869 117323 -SQLITE_PRIVATE int sqlite3Fts3Incrmerge(Fts3Table*,int,int); 117324 - 117325 116870 /* fts3.c */ 117326 116871 SQLITE_PRIVATE int sqlite3Fts3PutVarint(char *, sqlite3_int64); 117327 116872 SQLITE_PRIVATE int sqlite3Fts3GetVarint(const char *, sqlite_int64 *); 117328 116873 SQLITE_PRIVATE int sqlite3Fts3GetVarint32(const char *, int *); 117329 116874 SQLITE_PRIVATE int sqlite3Fts3VarintLen(sqlite3_uint64); 117330 116875 SQLITE_PRIVATE void sqlite3Fts3Dequote(char *); 117331 116876 SQLITE_PRIVATE void sqlite3Fts3DoclistPrev(int,char*,int,char**,sqlite3_int64*,int*,u8*); 117332 116877 SQLITE_PRIVATE int sqlite3Fts3EvalPhraseStats(Fts3Cursor *, Fts3Expr *, u32 *); 117333 116878 SQLITE_PRIVATE int sqlite3Fts3FirstFilter(sqlite3_int64, char *, int, char *); 117334 -SQLITE_PRIVATE void sqlite3Fts3CreateStatTable(int*, Fts3Table*); 117335 116879 117336 116880 /* fts3_tokenizer.c */ 117337 116881 SQLITE_PRIVATE const char *sqlite3Fts3NextToken(const char *, int *); 117338 116882 SQLITE_PRIVATE int sqlite3Fts3InitHashTable(sqlite3 *, Fts3Hash *, const char *); 117339 116883 SQLITE_PRIVATE int sqlite3Fts3InitTokenizer(Fts3Hash *pHash, const char *, 117340 116884 sqlite3_tokenizer **, char ** 117341 116885 ); ................................................................................ 117367 116911 117368 116912 SQLITE_PRIVATE void sqlite3Fts3EvalPhraseCleanup(Fts3Phrase *); 117369 116913 117370 116914 SQLITE_PRIVATE int sqlite3Fts3MsrIncrStart( 117371 116915 Fts3Table*, Fts3MultiSegReader*, int, const char*, int); 117372 116916 SQLITE_PRIVATE int sqlite3Fts3MsrIncrNext( 117373 116917 Fts3Table *, Fts3MultiSegReader *, sqlite3_int64 *, char **, int *); 117374 -SQLITE_PRIVATE int sqlite3Fts3EvalPhrasePoslist(Fts3Cursor *, Fts3Expr *, int iCol, char **); 116918 +SQLITE_PRIVATE char *sqlite3Fts3EvalPhrasePoslist(Fts3Cursor *, Fts3Expr *, int iCol); 117375 116919 SQLITE_PRIVATE int sqlite3Fts3MsrOvfl(Fts3Cursor *, Fts3MultiSegReader *, int *); 117376 116920 SQLITE_PRIVATE int sqlite3Fts3MsrIncrRestart(Fts3MultiSegReader *pCsr); 117377 116921 117378 116922 SQLITE_PRIVATE int sqlite3Fts3DeferredTokenList(Fts3DeferredToken *, char **, int *); 117379 116923 117380 116924 #endif /* !SQLITE_CORE || SQLITE_ENABLE_FTS3 */ 117381 116925 #endif /* _FTSINT_H */ ................................................................................ 117657 117201 117658 117202 sqlite3_free(zSql); 117659 117203 sqlite3_free(zCols); 117660 117204 *pRc = rc; 117661 117205 } 117662 117206 } 117663 117207 117664 -/* 117665 -** Create the %_stat table if it does not already exist. 117666 -*/ 117667 -SQLITE_PRIVATE void sqlite3Fts3CreateStatTable(int *pRc, Fts3Table *p){ 117668 - fts3DbExec(pRc, p->db, 117669 - "CREATE TABLE IF NOT EXISTS %Q.'%q_stat'" 117670 - "(id INTEGER PRIMARY KEY, value BLOB);", 117671 - p->zDb, p->zName 117672 - ); 117673 - if( (*pRc)==SQLITE_OK ) p->bHasStat = 1; 117674 -} 117675 - 117676 117208 /* 117677 117209 ** Create the backing store tables (%_content, %_segments and %_segdir) 117678 117210 ** required by the FTS3 table passed as the only argument. This is done 117679 117211 ** as part of the vtab xCreate() method. 117680 117212 ** 117681 117213 ** If the p->bHasDocsize boolean is true (indicating that this is an 117682 117214 ** FTS4 table, not an FTS3 table) then also create the %_docsize and ................................................................................ 117729 117261 ); 117730 117262 if( p->bHasDocsize ){ 117731 117263 fts3DbExec(&rc, db, 117732 117264 "CREATE TABLE %Q.'%q_docsize'(docid INTEGER PRIMARY KEY, size BLOB);", 117733 117265 p->zDb, p->zName 117734 117266 ); 117735 117267 } 117736 - assert( p->bHasStat==p->bFts4 ); 117737 117268 if( p->bHasStat ){ 117738 - sqlite3Fts3CreateStatTable(&rc, p); 117269 + fts3DbExec(&rc, db, 117270 + "CREATE TABLE %Q.'%q_stat'(id INTEGER PRIMARY KEY, value BLOB);", 117271 + p->zDb, p->zName 117272 + ); 117739 117273 } 117740 117274 return rc; 117741 117275 } 117742 117276 117743 117277 /* 117744 117278 ** Store the current database page-size in bytes in p->nPgsz. 117745 117279 ** ................................................................................ 118372 117906 p->nColumn = nCol; 118373 117907 p->nPendingData = 0; 118374 117908 p->azColumn = (char **)&p[1]; 118375 117909 p->pTokenizer = pTokenizer; 118376 117910 p->nMaxPendingData = FTS3_MAX_PENDING_DATA; 118377 117911 p->bHasDocsize = (isFts4 && bNoDocsize==0); 118378 117912 p->bHasStat = isFts4; 118379 - p->bFts4 = isFts4; 118380 117913 p->bDescIdx = bDescIdx; 118381 - p->bAutoincrmerge = 0xff; /* 0xff means setting unknown */ 118382 117914 p->zContentTbl = zContent; 118383 117915 p->zLanguageid = zLanguageid; 118384 117916 zContent = 0; 118385 117917 zLanguageid = 0; 118386 117918 TESTONLY( p->inTransaction = -1 ); 118387 117919 TESTONLY( p->mxSavepoint = -1 ); 118388 117920 ................................................................................ 118427 117959 /* If this is an xCreate call, create the underlying tables in the 118428 117960 ** database. TODO: For xConnect(), it could verify that said tables exist. 118429 117961 */ 118430 117962 if( isCreate ){ 118431 117963 rc = fts3CreateTables(p); 118432 117964 } 118433 117965 118434 - /* Check to see if a legacy fts3 table has been "upgraded" by the 118435 - ** addition of a %_stat table so that it can use incremental merge. 118436 - */ 118437 - if( !isFts4 && !isCreate ){ 118438 - int rc2 = SQLITE_OK; 118439 - fts3DbExec(&rc2, db, "SELECT 1 FROM %Q.'%q_stat' WHERE id=2", 118440 - p->zDb, p->zName); 118441 - if( rc2==SQLITE_OK ) p->bHasStat = 1; 118442 - } 118443 - 118444 117966 /* Figure out the page-size for the database. This is required in order to 118445 117967 ** estimate the cost of loading large doclists from the database. */ 118446 117968 fts3DatabasePageSize(&rc, p); 118447 117969 p->nNodeSize = p->nPgsz-35; 118448 117970 118449 117971 /* Declare the table schema to SQLite. */ 118450 117972 fts3DeclareVtab(&rc, p); ................................................................................ 119780 119302 119781 119303 /* 119782 119304 ** Set up a cursor object for iterating through a full-text index or a 119783 119305 ** single level therein. 119784 119306 */ 119785 119307 SQLITE_PRIVATE int sqlite3Fts3SegReaderCursor( 119786 119308 Fts3Table *p, /* FTS3 table handle */ 119787 - int iLangid, /* Language-id to search */ 119309 + int iLangid, 119788 119310 int iIndex, /* Index to search (from 0 to p->nIndex-1) */ 119789 119311 int iLevel, /* Level of segments to scan */ 119790 119312 const char *zTerm, /* Term to query for */ 119791 119313 int nTerm, /* Size of zTerm in bytes */ 119792 119314 int isPrefix, /* True for a prefix search */ 119793 119315 int isScan, /* True to scan from zTerm to EOF */ 119794 119316 Fts3MultiSegReader *pCsr /* Cursor object to populate */ ................................................................................ 119797 119319 assert( iLevel==FTS3_SEGCURSOR_ALL 119798 119320 || iLevel==FTS3_SEGCURSOR_PENDING 119799 119321 || iLevel>=0 119800 119322 ); 119801 119323 assert( iLevel<FTS3_SEGDIR_MAXLEVEL ); 119802 119324 assert( FTS3_SEGCURSOR_ALL<0 && FTS3_SEGCURSOR_PENDING<0 ); 119803 119325 assert( isPrefix==0 || isScan==0 ); 119326 + 119327 + /* "isScan" is only set to true by the ft4aux module, an ordinary 119328 + ** full-text tables. */ 119329 + assert( isScan==0 || p->aIndex==0 ); 119804 119330 119805 119331 memset(pCsr, 0, sizeof(Fts3MultiSegReader)); 119332 + 119806 119333 return fts3SegReaderCursor( 119807 119334 p, iLangid, iIndex, iLevel, zTerm, nTerm, isPrefix, isScan, pCsr 119808 119335 ); 119809 119336 } 119810 119337 119811 119338 /* 119812 119339 ** In addition to its current configuration, have the Fts3MultiSegReader ................................................................................ 120063 119590 return SQLITE_NOMEM; 120064 119591 } 120065 119592 120066 119593 pCsr->iLangid = 0; 120067 119594 if( nVal==2 ) pCsr->iLangid = sqlite3_value_int(apVal[1]); 120068 119595 120069 119596 rc = sqlite3Fts3ExprParse(p->pTokenizer, pCsr->iLangid, 120070 - p->azColumn, p->bFts4, p->nColumn, iCol, zQuery, -1, &pCsr->pExpr 119597 + p->azColumn, p->bHasStat, p->nColumn, iCol, zQuery, -1, &pCsr->pExpr 120071 119598 ); 120072 119599 if( rc!=SQLITE_OK ){ 120073 119600 if( rc==SQLITE_ERROR ){ 120074 119601 static const char *zErr = "malformed MATCH expression: [%s]"; 120075 119602 p->base.zErrMsg = sqlite3_mprintf(zErr, zQuery); 120076 119603 } 120077 119604 return rc; ................................................................................ 120206 119733 } 120207 119734 120208 119735 /* 120209 119736 ** Implementation of xSync() method. Flush the contents of the pending-terms 120210 119737 ** hash-table to the database. 120211 119738 */ 120212 119739 static int fts3SyncMethod(sqlite3_vtab *pVtab){ 120213 - 120214 - /* Following an incremental-merge operation, assuming that the input 120215 - ** segments are not completely consumed (the usual case), they are updated 120216 - ** in place to remove the entries that have already been merged. This 120217 - ** involves updating the leaf block that contains the smallest unmerged 120218 - ** entry and each block (if any) between the leaf and the root node. So 120219 - ** if the height of the input segment b-trees is N, and input segments 120220 - ** are merged eight at a time, updating the input segments at the end 120221 - ** of an incremental-merge requires writing (8*(1+N)) blocks. N is usually 120222 - ** small - often between 0 and 2. So the overhead of the incremental 120223 - ** merge is somewhere between 8 and 24 blocks. To avoid this overhead 120224 - ** dwarfing the actual productive work accomplished, the incremental merge 120225 - ** is only attempted if it will write at least 64 leaf blocks. Hence 120226 - ** nMinMerge. 120227 - ** 120228 - ** Of course, updating the input segments also involves deleting a bunch 120229 - ** of blocks from the segments table. But this is not considered overhead 120230 - ** as it would also be required by a crisis-merge that used the same input 120231 - ** segments. 120232 - */ 120233 - const u32 nMinMerge = 64; /* Minimum amount of incr-merge work to do */ 120234 - 120235 - Fts3Table *p = (Fts3Table*)pVtab; 120236 - int rc = sqlite3Fts3PendingTermsFlush(p); 120237 - 120238 - if( rc==SQLITE_OK && p->bAutoincrmerge==1 && p->nLeafAdd>(nMinMerge/16) ){ 120239 - int mxLevel = 0; /* Maximum relative level value in db */ 120240 - int A; /* Incr-merge parameter A */ 120241 - 120242 - rc = sqlite3Fts3MaxLevel(p, &mxLevel); 120243 - assert( rc==SQLITE_OK || mxLevel==0 ); 120244 - A = p->nLeafAdd * mxLevel; 120245 - A += (A/2); 120246 - if( A>(int)nMinMerge ) rc = sqlite3Fts3Incrmerge(p, A, 8); 120247 - } 120248 - sqlite3Fts3SegmentsClose(p); 119740 + int rc = sqlite3Fts3PendingTermsFlush((Fts3Table *)pVtab); 119741 + sqlite3Fts3SegmentsClose((Fts3Table *)pVtab); 120249 119742 return rc; 120250 119743 } 120251 119744 120252 119745 /* 120253 119746 ** Implementation of xBegin() method. This is a no-op. 120254 119747 */ 120255 119748 static int fts3BeginMethod(sqlite3_vtab *pVtab){ 120256 - Fts3Table *p = (Fts3Table*)pVtab; 119749 + TESTONLY( Fts3Table *p = (Fts3Table*)pVtab ); 120257 119750 UNUSED_PARAMETER(pVtab); 120258 119751 assert( p->pSegments==0 ); 120259 119752 assert( p->nPendingData==0 ); 120260 119753 assert( p->inTransaction!=1 ); 120261 119754 TESTONLY( p->inTransaction = 1 ); 120262 119755 TESTONLY( p->mxSavepoint = -1; ); 120263 - p->nLeafAdd = 0; 120264 119756 return SQLITE_OK; 120265 119757 } 120266 119758 120267 119759 /* 120268 119760 ** Implementation of xCommit() method. This is a no-op. The contents of 120269 119761 ** the pending-terms hash-table have already been flushed into the database 120270 119762 ** by fts3SyncMethod(). ................................................................................ 120551 120043 120552 120044 /* 120553 120045 ** The xSavepoint() method. 120554 120046 ** 120555 120047 ** Flush the contents of the pending-terms table to disk. 120556 120048 */ 120557 120049 static int fts3SavepointMethod(sqlite3_vtab *pVtab, int iSavepoint){ 120558 - int rc = SQLITE_OK; 120559 120050 UNUSED_PARAMETER(iSavepoint); 120560 120051 assert( ((Fts3Table *)pVtab)->inTransaction ); 120561 120052 assert( ((Fts3Table *)pVtab)->mxSavepoint < iSavepoint ); 120562 120053 TESTONLY( ((Fts3Table *)pVtab)->mxSavepoint = iSavepoint ); 120563 - if( ((Fts3Table *)pVtab)->bIgnoreSavepoint==0 ){ 120564 - rc = fts3SyncMethod(pVtab); 120565 - } 120566 - return rc; 120054 + return fts3SyncMethod(pVtab); 120567 120055 } 120568 120056 120569 120057 /* 120570 120058 ** The xRelease() method. 120571 120059 ** 120572 120060 ** This is a no-op. 120573 120061 */ ................................................................................ 121032 120520 */ 121033 120521 SQLITE_PRIVATE void sqlite3Fts3DoclistPrev( 121034 120522 int bDescIdx, /* True if the doclist is desc */ 121035 120523 char *aDoclist, /* Pointer to entire doclist */ 121036 120524 int nDoclist, /* Length of aDoclist in bytes */ 121037 120525 char **ppIter, /* IN/OUT: Iterator pointer */ 121038 120526 sqlite3_int64 *piDocid, /* IN/OUT: Docid pointer */ 121039 - int *pnList, /* OUT: List length pointer */ 120527 + int *pnList, /* IN/OUT: List length pointer */ 121040 120528 u8 *pbEof /* OUT: End-of-file flag */ 121041 120529 ){ 121042 120530 char *p = *ppIter; 121043 120531 121044 120532 assert( nDoclist>0 ); 121045 120533 assert( *pbEof==0 ); 121046 120534 assert( p || *piDocid==0 ); ................................................................................ 121079 120567 fts3ReversePoslist(aDoclist, &p); 121080 120568 *pnList = (int)(pSave - p); 121081 120569 } 121082 120570 *ppIter = p; 121083 120571 } 121084 120572 } 121085 120573 121086 -/* 121087 -** Iterate forwards through a doclist. 121088 -*/ 121089 -SQLITE_PRIVATE void sqlite3Fts3DoclistNext( 121090 - int bDescIdx, /* True if the doclist is desc */ 121091 - char *aDoclist, /* Pointer to entire doclist */ 121092 - int nDoclist, /* Length of aDoclist in bytes */ 121093 - char **ppIter, /* IN/OUT: Iterator pointer */ 121094 - sqlite3_int64 *piDocid, /* IN/OUT: Docid pointer */ 121095 - u8 *pbEof /* OUT: End-of-file flag */ 121096 -){ 121097 - char *p = *ppIter; 121098 - 121099 - assert( nDoclist>0 ); 121100 - assert( *pbEof==0 ); 121101 - assert( p || *piDocid==0 ); 121102 - assert( !p || (p>=aDoclist && p<=&aDoclist[nDoclist]) ); 121103 - 121104 - if( p==0 ){ 121105 - p = aDoclist; 121106 - p += sqlite3Fts3GetVarint(p, piDocid); 121107 - }else{ 121108 - fts3PoslistCopy(0, &p); 121109 - if( p>=&aDoclist[nDoclist] ){ 121110 - *pbEof = 1; 121111 - }else{ 121112 - sqlite3_int64 iVar; 121113 - p += sqlite3Fts3GetVarint(p, &iVar); 121114 - *piDocid += ((bDescIdx ? -1 : 1) * iVar); 121115 - } 121116 - } 121117 - 121118 - *ppIter = p; 121119 -} 121120 - 121121 120574 /* 121122 120575 ** Attempt to move the phrase iterator to point to the next matching docid. 121123 120576 ** If an error occurs, return an SQLite error code. Otherwise, return 121124 120577 ** SQLITE_OK. 121125 120578 ** 121126 120579 ** If there is no "next" entry and no error occurs, then *pbEof is set to 121127 120580 ** 1 before returning. Otherwise, if no error occurs and the iterator is ................................................................................ 121509 120962 int nToken = 0; 121510 120963 int nOr = 0; 121511 120964 121512 120965 /* Allocate a MultiSegReader for each token in the expression. */ 121513 120966 fts3EvalAllocateReaders(pCsr, pCsr->pExpr, &nToken, &nOr, &rc); 121514 120967 121515 120968 /* Determine which, if any, tokens in the expression should be deferred. */ 121516 - if( rc==SQLITE_OK && nToken>1 && pTab->bFts4 ){ 120969 + if( rc==SQLITE_OK && nToken>1 && pTab->bHasStat ){ 121517 120970 Fts3TokenAndCost *aTC; 121518 120971 Fts3Expr **apOr; 121519 120972 aTC = (Fts3TokenAndCost *)sqlite3_malloc( 121520 120973 sizeof(Fts3TokenAndCost) * nToken 121521 120974 + sizeof(Fts3Expr *) * nOr * 2 121522 120975 ); 121523 120976 apOr = (Fts3Expr **)&aTC[nToken]; ................................................................................ 122269 121722 ** for 'X' is requested, the buffer returned may contain: 122270 121723 ** 122271 121724 ** 0x04 0x05 0x03 0x01 or 0x04 0x05 0x03 0x00 122272 121725 ** 122273 121726 ** This function works regardless of whether or not the phrase is deferred, 122274 121727 ** incremental, or neither. 122275 121728 */ 122276 -SQLITE_PRIVATE int sqlite3Fts3EvalPhrasePoslist( 121729 +SQLITE_PRIVATE char *sqlite3Fts3EvalPhrasePoslist( 122277 121730 Fts3Cursor *pCsr, /* FTS3 cursor object */ 122278 121731 Fts3Expr *pExpr, /* Phrase to return doclist for */ 122279 - int iCol, /* Column to return position list for */ 122280 - char **ppOut /* OUT: Pointer to position list */ 121732 + int iCol /* Column to return position list for */ 122281 121733 ){ 122282 121734 Fts3Phrase *pPhrase = pExpr->pPhrase; 122283 121735 Fts3Table *pTab = (Fts3Table *)pCsr->base.pVtab; 122284 - char *pIter; 121736 + char *pIter = pPhrase->doclist.pList; 122285 121737 int iThis; 122286 - sqlite3_int64 iDocid; 122287 121738 122288 - /* If this phrase is applies specifically to some column other than 122289 - ** column iCol, return a NULL pointer. */ 122290 - *ppOut = 0; 122291 121739 assert( iCol>=0 && iCol<pTab->nColumn ); 122292 - if( (pPhrase->iColumn<pTab->nColumn && pPhrase->iColumn!=iCol) ){ 122293 - return SQLITE_OK; 122294 - } 122295 - 122296 - iDocid = pExpr->iDocid; 122297 - pIter = pPhrase->doclist.pList; 122298 - if( iDocid!=pCsr->iPrevId || pExpr->bEof ){ 122299 - int bDescDoclist = pTab->bDescIdx; /* For DOCID_CMP macro */ 122300 - int bOr = 0; 122301 - u8 bEof = 0; 122302 - Fts3Expr *p; 122303 - 122304 - /* Check if this phrase descends from an OR expression node. If not, 122305 - ** return NULL. Otherwise, the entry that corresponds to docid 122306 - ** pCsr->iPrevId may lie earlier in the doclist buffer. */ 122307 - for(p=pExpr->pParent; p; p=p->pParent){ 122308 - if( p->eType==FTSQUERY_OR ) bOr = 1; 122309 - } 122310 - if( bOr==0 ) return SQLITE_OK; 122311 - 122312 - /* This is the descendent of an OR node. In this case we cannot use 122313 - ** an incremental phrase. Load the entire doclist for the phrase 122314 - ** into memory in this case. */ 122315 - if( pPhrase->bIncr ){ 122316 - int rc = SQLITE_OK; 122317 - int bEofSave = pExpr->bEof; 122318 - fts3EvalRestart(pCsr, pExpr, &rc); 122319 - while( rc==SQLITE_OK && !pExpr->bEof ){ 122320 - fts3EvalNextRow(pCsr, pExpr, &rc); 122321 - if( bEofSave==0 && pExpr->iDocid==iDocid ) break; 122322 - } 122323 - pIter = pPhrase->doclist.pList; 122324 - assert( rc!=SQLITE_OK || pPhrase->bIncr==0 ); 122325 - if( rc!=SQLITE_OK ) return rc; 122326 - } 122327 - 122328 - if( pExpr->bEof ){ 122329 - pIter = 0; 122330 - iDocid = 0; 122331 - } 122332 - bEof = (pPhrase->doclist.nAll==0); 122333 - assert( bDescDoclist==0 || bDescDoclist==1 ); 122334 - assert( pCsr->bDesc==0 || pCsr->bDesc==1 ); 122335 - 122336 - if( pCsr->bDesc==bDescDoclist ){ 122337 - int dummy; 122338 - while( (pIter==0 || DOCID_CMP(iDocid, pCsr->iPrevId)>0 ) && bEof==0 ){ 122339 - sqlite3Fts3DoclistPrev( 122340 - bDescDoclist, pPhrase->doclist.aAll, pPhrase->doclist.nAll, 122341 - &pIter, &iDocid, &dummy, &bEof 122342 - ); 122343 - } 122344 - }else{ 122345 - while( (pIter==0 || DOCID_CMP(iDocid, pCsr->iPrevId)<0 ) && bEof==0 ){ 122346 - sqlite3Fts3DoclistNext( 122347 - bDescDoclist, pPhrase->doclist.aAll, pPhrase->doclist.nAll, 122348 - &pIter, &iDocid, &bEof 122349 - ); 122350 - } 122351 - } 122352 - 122353 - if( bEof || iDocid!=pCsr->iPrevId ) pIter = 0; 122354 - } 122355 - if( pIter==0 ) return SQLITE_OK; 122356 - 121740 + if( !pIter 121741 + || pExpr->bEof 121742 + || pExpr->iDocid!=pCsr->iPrevId 121743 + || (pPhrase->iColumn<pTab->nColumn && pPhrase->iColumn!=iCol) 121744 + ){ 121745 + return 0; 121746 + } 121747 + 121748 + assert( pPhrase->doclist.nList>0 ); 122357 121749 if( *pIter==0x01 ){ 122358 121750 pIter++; 122359 121751 pIter += sqlite3Fts3GetVarint32(pIter, &iThis); 122360 121752 }else{ 122361 121753 iThis = 0; 122362 121754 } 122363 121755 while( iThis<iCol ){ 122364 121756 fts3ColumnlistCopy(0, &pIter); 122365 121757 if( *pIter==0x00 ) return 0; 122366 121758 pIter++; 122367 121759 pIter += sqlite3Fts3GetVarint32(pIter, &iThis); 122368 121760 } 122369 121761 122370 - *ppOut = ((iCol==iThis)?pIter:0); 122371 - return SQLITE_OK; 121762 + return ((iCol==iThis)?pIter:0); 122372 121763 } 122373 121764 122374 121765 /* 122375 121766 ** Free all components of the Fts3Phrase structure that were allocated by 122376 121767 ** the eval module. Specifically, this means to free: 122377 121768 ** 122378 121769 ** * the contents of pPhrase->doclist, and ................................................................................ 122386 121777 memset(&pPhrase->doclist, 0, sizeof(Fts3Doclist)); 122387 121778 for(i=0; i<pPhrase->nToken; i++){ 122388 121779 fts3SegReaderCursorFree(pPhrase->aToken[i].pSegcsr); 122389 121780 pPhrase->aToken[i].pSegcsr = 0; 122390 121781 } 122391 121782 } 122392 121783 } 122393 - 122394 121784 122395 121785 /* 122396 121786 ** Return SQLITE_CORRUPT_VTAB. 122397 121787 */ 122398 121788 #ifdef SQLITE_DEBUG 122399 121789 SQLITE_PRIVATE int sqlite3Fts3Corrupt(){ 122400 121790 return SQLITE_CORRUPT_VTAB; ................................................................................ 125687 125077 125688 125078 #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) 125689 125079 125690 125080 /* #include <string.h> */ 125691 125081 /* #include <assert.h> */ 125692 125082 /* #include <stdlib.h> */ 125693 125083 125694 - 125695 -#define FTS_MAX_APPENDABLE_HEIGHT 16 125696 - 125697 125084 /* 125698 125085 ** When full-text index nodes are loaded from disk, the buffer that they 125699 125086 ** are loaded into has the following number of bytes of padding at the end 125700 125087 ** of it. i.e. if a full-text index node is 900 bytes in size, then a buffer 125701 125088 ** of 920 bytes is allocated for it. 125702 125089 ** 125703 125090 ** This means that if we have a pointer into a buffer containing node data, ................................................................................ 125728 125115 int test_fts3_node_chunk_threshold = (4*1024)*4; 125729 125116 # define FTS3_NODE_CHUNKSIZE test_fts3_node_chunksize 125730 125117 # define FTS3_NODE_CHUNK_THRESHOLD test_fts3_node_chunk_threshold 125731 125118 #else 125732 125119 # define FTS3_NODE_CHUNKSIZE (4*1024) 125733 125120 # define FTS3_NODE_CHUNK_THRESHOLD (FTS3_NODE_CHUNKSIZE*4) 125734 125121 #endif 125735 - 125736 -/* 125737 -** The two values that may be meaningfully bound to the :1 parameter in 125738 -** statements SQL_REPLACE_STAT and SQL_SELECT_STAT. 125739 -*/ 125740 -#define FTS_STAT_DOCTOTAL 0 125741 -#define FTS_STAT_INCRMERGEHINT 1 125742 -#define FTS_STAT_AUTOINCRMERGE 2 125743 - 125744 -/* 125745 -** If FTS_LOG_MERGES is defined, call sqlite3_log() to report each automatic 125746 -** and incremental merge operation that takes place. This is used for 125747 -** debugging FTS only, it should not usually be turned on in production 125748 -** systems. 125749 -*/ 125750 -#ifdef FTS3_LOG_MERGES 125751 -static void fts3LogMerge(int nMerge, sqlite3_int64 iAbsLevel){ 125752 - sqlite3_log(SQLITE_OK, "%d-way merge from level %d", nMerge, (int)iAbsLevel); 125753 -} 125754 -#else 125755 -#define fts3LogMerge(x, y) 125756 -#endif 125757 - 125758 125122 125759 125123 typedef struct PendingList PendingList; 125760 125124 typedef struct SegmentNode SegmentNode; 125761 125125 typedef struct SegmentWriter SegmentWriter; 125762 125126 125763 125127 /* 125764 125128 ** An instance of the following data structure is used to build doclists ................................................................................ 125913 125277 #define SQL_SELECT_SEGDIR_MAX_LEVEL 15 125914 125278 #define SQL_DELETE_SEGDIR_LEVEL 16 125915 125279 #define SQL_DELETE_SEGMENTS_RANGE 17 125916 125280 #define SQL_CONTENT_INSERT 18 125917 125281 #define SQL_DELETE_DOCSIZE 19 125918 125282 #define SQL_REPLACE_DOCSIZE 20 125919 125283 #define SQL_SELECT_DOCSIZE 21 125920 -#define SQL_SELECT_STAT 22 125921 -#define SQL_REPLACE_STAT 23 125284 +#define SQL_SELECT_DOCTOTAL 22 125285 +#define SQL_REPLACE_DOCTOTAL 23 125922 125286 125923 125287 #define SQL_SELECT_ALL_PREFIX_LEVEL 24 125924 125288 #define SQL_DELETE_ALL_TERMS_SEGDIR 25 125289 + 125925 125290 #define SQL_DELETE_SEGDIR_RANGE 26 125291 + 125926 125292 #define SQL_SELECT_ALL_LANGID 27 125927 -#define SQL_FIND_MERGE_LEVEL 28 125928 -#define SQL_MAX_LEAF_NODE_ESTIMATE 29 125929 -#define SQL_DELETE_SEGDIR_ENTRY 30 125930 -#define SQL_SHIFT_SEGDIR_ENTRY 31 125931 -#define SQL_SELECT_SEGDIR 32 125932 -#define SQL_CHOMP_SEGDIR 33 125933 -#define SQL_SEGMENT_IS_APPENDABLE 34 125934 -#define SQL_SELECT_INDEXES 35 125935 -#define SQL_SELECT_MXLEVEL 36 125936 125293 125937 125294 /* 125938 125295 ** This function is used to obtain an SQLite prepared statement handle 125939 125296 ** for the statement identified by the second argument. If successful, 125940 125297 ** *pp is set to the requested statement handle and SQLITE_OK returned. 125941 125298 ** Otherwise, an SQLite error code is returned and *pp is set to 0. 125942 125299 ** ................................................................................ 125957 125314 /* 2 */ "DELETE FROM %Q.'%q_content'", 125958 125315 /* 3 */ "DELETE FROM %Q.'%q_segments'", 125959 125316 /* 4 */ "DELETE FROM %Q.'%q_segdir'", 125960 125317 /* 5 */ "DELETE FROM %Q.'%q_docsize'", 125961 125318 /* 6 */ "DELETE FROM %Q.'%q_stat'", 125962 125319 /* 7 */ "SELECT %s WHERE rowid=?", 125963 125320 /* 8 */ "SELECT (SELECT max(idx) FROM %Q.'%q_segdir' WHERE level = ?) + 1", 125964 -/* 9 */ "REPLACE INTO %Q.'%q_segments'(blockid, block) VALUES(?, ?)", 125321 +/* 9 */ "INSERT INTO %Q.'%q_segments'(blockid, block) VALUES(?, ?)", 125965 125322 /* 10 */ "SELECT coalesce((SELECT max(blockid) FROM %Q.'%q_segments') + 1, 1)", 125966 -/* 11 */ "REPLACE INTO %Q.'%q_segdir' VALUES(?,?,?,?,?,?)", 125323 +/* 11 */ "INSERT INTO %Q.'%q_segdir' VALUES(?,?,?,?,?,?)", 125967 125324 125968 125325 /* Return segments in order from oldest to newest.*/ 125969 125326 /* 12 */ "SELECT idx, start_block, leaves_end_block, end_block, root " 125970 125327 "FROM %Q.'%q_segdir' WHERE level = ? ORDER BY idx ASC", 125971 125328 /* 13 */ "SELECT idx, start_block, leaves_end_block, end_block, root " 125972 125329 "FROM %Q.'%q_segdir' WHERE level BETWEEN ? AND ?" 125973 125330 "ORDER BY level DESC, idx ASC", ................................................................................ 125977 125334 125978 125335 /* 16 */ "DELETE FROM %Q.'%q_segdir' WHERE level = ?", 125979 125336 /* 17 */ "DELETE FROM %Q.'%q_segments' WHERE blockid BETWEEN ? AND ?", 125980 125337 /* 18 */ "INSERT INTO %Q.'%q_content' VALUES(%s)", 125981 125338 /* 19 */ "DELETE FROM %Q.'%q_docsize' WHERE docid = ?", 125982 125339 /* 20 */ "REPLACE INTO %Q.'%q_docsize' VALUES(?,?)", 125983 125340 /* 21 */ "SELECT size FROM %Q.'%q_docsize' WHERE docid=?", 125984 -/* 22 */ "SELECT value FROM %Q.'%q_stat' WHERE id=?", 125985 -/* 23 */ "REPLACE INTO %Q.'%q_stat' VALUES(?,?)", 125341 +/* 22 */ "SELECT value FROM %Q.'%q_stat' WHERE id=0", 125342 +/* 23 */ "REPLACE INTO %Q.'%q_stat' VALUES(0,?)", 125986 125343 /* 24 */ "", 125987 125344 /* 25 */ "", 125988 125345 125989 125346 /* 26 */ "DELETE FROM %Q.'%q_segdir' WHERE level BETWEEN ? AND ?", 125990 125347 /* 27 */ "SELECT DISTINCT level / (1024 * ?) FROM %Q.'%q_segdir'", 125991 125348 125992 -/* This statement is used to determine which level to read the input from 125993 -** when performing an incremental merge. It returns the absolute level number 125994 -** of the oldest level in the db that contains at least ? segments. Or, 125995 -** if no level in the FTS index contains more than ? segments, the statement 125996 -** returns zero rows. */ 125997 -/* 28 */ "SELECT level FROM %Q.'%q_segdir' GROUP BY level HAVING count(*)>=?" 125998 - " ORDER BY (level %% 1024) ASC LIMIT 1", 125999 - 126000 -/* Estimate the upper limit on the number of leaf nodes in a new segment 126001 -** created by merging the oldest :2 segments from absolute level :1. See 126002 -** function sqlite3Fts3Incrmerge() for details. */ 126003 -/* 29 */ "SELECT 2 * total(1 + leaves_end_block - start_block) " 126004 - " FROM %Q.'%q_segdir' WHERE level = ? AND idx < ?", 126005 - 126006 -/* SQL_DELETE_SEGDIR_ENTRY 126007 -** Delete the %_segdir entry on absolute level :1 with index :2. */ 126008 -/* 30 */ "DELETE FROM %Q.'%q_segdir' WHERE level = ? AND idx = ?", 126009 - 126010 -/* SQL_SHIFT_SEGDIR_ENTRY 126011 -** Modify the idx value for the segment with idx=:3 on absolute level :2 126012 -** to :1. */ 126013 -/* 31 */ "UPDATE %Q.'%q_segdir' SET idx = ? WHERE level=? AND idx=?", 126014 - 126015 -/* SQL_SELECT_SEGDIR 126016 -** Read a single entry from the %_segdir table. The entry from absolute 126017 -** level :1 with index value :2. */ 126018 -/* 32 */ "SELECT idx, start_block, leaves_end_block, end_block, root " 126019 - "FROM %Q.'%q_segdir' WHERE level = ? AND idx = ?", 126020 - 126021 -/* SQL_CHOMP_SEGDIR 126022 -** Update the start_block (:1) and root (:2) fields of the %_segdir 126023 -** entry located on absolute level :3 with index :4. */ 126024 -/* 33 */ "UPDATE %Q.'%q_segdir' SET start_block = ?, root = ?" 126025 - "WHERE level = ? AND idx = ?", 126026 - 126027 -/* SQL_SEGMENT_IS_APPENDABLE 126028 -** Return a single row if the segment with end_block=? is appendable. Or 126029 -** no rows otherwise. */ 126030 -/* 34 */ "SELECT 1 FROM %Q.'%q_segments' WHERE blockid=? AND block IS NULL", 126031 - 126032 -/* SQL_SELECT_INDEXES 126033 -** Return the list of valid segment indexes for absolute level ? */ 126034 -/* 35 */ "SELECT idx FROM %Q.'%q_segdir' WHERE level=? ORDER BY 1 ASC", 126035 - 126036 -/* SQL_SELECT_MXLEVEL 126037 -** Return the largest relative level in the FTS index or indexes. */ 126038 -/* 36 */ "SELECT max( level %% 1024 ) FROM %Q.'%q_segdir'" 126039 125349 }; 126040 125350 int rc = SQLITE_OK; 126041 125351 sqlite3_stmt *pStmt; 126042 125352 126043 125353 assert( SizeofArray(azSql)==SizeofArray(p->aStmt) ); 126044 125354 assert( eStmt<SizeofArray(azSql) && eStmt>=0 ); 126045 125355 ................................................................................ 126069 125379 rc = sqlite3_bind_value(pStmt, i+1, apVal[i]); 126070 125380 } 126071 125381 } 126072 125382 *pp = pStmt; 126073 125383 return rc; 126074 125384 } 126075 125385 126076 - 126077 125386 static int fts3SelectDocsize( 126078 125387 Fts3Table *pTab, /* FTS3 table handle */ 125388 + int eStmt, /* Either SQL_SELECT_DOCSIZE or DOCTOTAL */ 126079 125389 sqlite3_int64 iDocid, /* Docid to bind for SQL_SELECT_DOCSIZE */ 126080 125390 sqlite3_stmt **ppStmt /* OUT: Statement handle */ 126081 125391 ){ 126082 125392 sqlite3_stmt *pStmt = 0; /* Statement requested from fts3SqlStmt() */ 126083 125393 int rc; /* Return code */ 126084 125394 126085 - rc = fts3SqlStmt(pTab, SQL_SELECT_DOCSIZE, &pStmt, 0); 125395 + assert( eStmt==SQL_SELECT_DOCSIZE || eStmt==SQL_SELECT_DOCTOTAL ); 125396 + 125397 + rc = fts3SqlStmt(pTab, eStmt, &pStmt, 0); 126086 125398 if( rc==SQLITE_OK ){ 126087 - sqlite3_bind_int64(pStmt, 1, iDocid); 125399 + if( eStmt==SQL_SELECT_DOCSIZE ){ 125400 + sqlite3_bind_int64(pStmt, 1, iDocid); 125401 + } 126088 125402 rc = sqlite3_step(pStmt); 126089 125403 if( rc!=SQLITE_ROW || sqlite3_column_type(pStmt, 0)!=SQLITE_BLOB ){ 126090 125404 rc = sqlite3_reset(pStmt); 126091 125405 if( rc==SQLITE_OK ) rc = FTS_CORRUPT_VTAB; 126092 125406 pStmt = 0; 126093 125407 }else{ 126094 125408 rc = SQLITE_OK; ................................................................................ 126099 125413 return rc; 126100 125414 } 126101 125415 126102 125416 SQLITE_PRIVATE int sqlite3Fts3SelectDoctotal( 126103 125417 Fts3Table *pTab, /* Fts3 table handle */ 126104 125418 sqlite3_stmt **ppStmt /* OUT: Statement handle */ 126105 125419 ){ 126106 - sqlite3_stmt *pStmt = 0; 126107 - int rc; 126108 - rc = fts3SqlStmt(pTab, SQL_SELECT_STAT, &pStmt, 0); 126109 - if( rc==SQLITE_OK ){ 126110 - sqlite3_bind_int(pStmt, 1, FTS_STAT_DOCTOTAL); 126111 - if( sqlite3_step(pStmt)!=SQLITE_ROW 126112 - || sqlite3_column_type(pStmt, 0)!=SQLITE_BLOB 126113 - ){ 126114 - rc = sqlite3_reset(pStmt); 126115 - if( rc==SQLITE_OK ) rc = FTS_CORRUPT_VTAB; 126116 - pStmt = 0; 126117 - } 126118 - } 126119 - *ppStmt = pStmt; 126120 - return rc; 125420 + return fts3SelectDocsize(pTab, SQL_SELECT_DOCTOTAL, 0, ppStmt); 126121 125421 } 126122 125422 126123 125423 SQLITE_PRIVATE int sqlite3Fts3SelectDocsize( 126124 125424 Fts3Table *pTab, /* Fts3 table handle */ 126125 125425 sqlite3_int64 iDocid, /* Docid to read size data for */ 126126 125426 sqlite3_stmt **ppStmt /* OUT: Statement handle */ 126127 125427 ){ 126128 - return fts3SelectDocsize(pTab, iDocid, ppStmt); 125428 + return fts3SelectDocsize(pTab, SQL_SELECT_DOCSIZE, iDocid, ppStmt); 126129 125429 } 126130 125430 126131 125431 /* 126132 125432 ** Similar to fts3SqlStmt(). Except, after binding the parameters in 126133 125433 ** array apVal[] to the SQL statement identified by eStmt, the statement 126134 125434 ** is executed. 126135 125435 ** ................................................................................ 126211 125511 ** Language 1 indexes are allocated immediately following language 0. 126212 125512 ** 126213 125513 ** So, for a system with nPrefix prefix indexes configured, the block of 126214 125514 ** absolute levels that corresponds to language-id iLangid and index 126215 125515 ** iIndex starts at absolute level ((iLangid * (nPrefix+1) + iIndex) * 1024). 126216 125516 */ 126217 125517 static sqlite3_int64 getAbsoluteLevel( 126218 - Fts3Table *p, /* FTS3 table handle */ 126219 - int iLangid, /* Language id */ 126220 - int iIndex, /* Index in p->aIndex[] */ 126221 - int iLevel /* Level of segments */ 125518 + Fts3Table *p, 125519 + int iLangid, 125520 + int iIndex, 125521 + int iLevel 126222 125522 ){ 126223 125523 sqlite3_int64 iBase; /* First absolute level for iLangid/iIndex */ 126224 125524 assert( iLangid>=0 ); 126225 125525 assert( p->nIndex>0 ); 126226 125526 assert( iIndex>=0 && iIndex<p->nIndex ); 126227 125527 126228 125528 iBase = ((sqlite3_int64)iLangid * p->nIndex + iIndex) * FTS3_SEGDIR_MAXLEVEL; 126229 125529 return iBase + iLevel; 126230 125530 } 125531 + 126231 125532 126232 125533 /* 126233 125534 ** Set *ppStmt to a statement handle that may be used to iterate through 126234 125535 ** all rows in the %_segdir table, from oldest to newest. If successful, 126235 125536 ** return SQLITE_OK. If an error occurs while preparing the statement, 126236 125537 ** return an SQLite error code. 126237 125538 ** ................................................................................ 126790 126091 if( rc==SQLITE_OK ){ 126791 126092 /* If iNext is FTS3_MERGE_COUNT, indicating that level iLevel is already 126792 126093 ** full, merge all segments in level iLevel into a single iLevel+1 126793 126094 ** segment and allocate (newly freed) index 0 at level iLevel. Otherwise, 126794 126095 ** if iNext is less than FTS3_MERGE_COUNT, allocate index iNext. 126795 126096 */ 126796 126097 if( iNext>=FTS3_MERGE_COUNT ){ 126797 - fts3LogMerge(16, getAbsoluteLevel(p, iLangid, iIndex, iLevel)); 126798 126098 rc = fts3SegmentMerge(p, iLangid, iIndex, iLevel); 126799 126099 *piIdx = 0; 126800 126100 }else{ 126801 126101 *piIdx = iNext; 126802 126102 } 126803 126103 } 126804 126104 ................................................................................ 126838 126138 char **paBlob, /* OUT: Blob data in malloc'd buffer */ 126839 126139 int *pnBlob, /* OUT: Size of blob data */ 126840 126140 int *pnLoad /* OUT: Bytes actually loaded */ 126841 126141 ){ 126842 126142 int rc; /* Return code */ 126843 126143 126844 126144 /* pnBlob must be non-NULL. paBlob may be NULL or non-NULL. */ 126845 - assert( pnBlob ); 126145 + assert( pnBlob); 126846 126146 126847 126147 if( p->pSegments ){ 126848 126148 rc = sqlite3_blob_reopen(p->pSegments, iBlockid); 126849 126149 }else{ 126850 126150 if( 0==p->zSegmentsTbl ){ 126851 126151 p->zSegmentsTbl = sqlite3_mprintf("%s_segments", p->zName); 126852 126152 if( 0==p->zSegmentsTbl ) return SQLITE_NOMEM; ................................................................................ 127179 126479 ){ 127180 126480 Fts3Table *p = (Fts3Table*)pCsr->base.pVtab; 127181 126481 int nOvfl = 0; 127182 126482 int ii; 127183 126483 int rc = SQLITE_OK; 127184 126484 int pgsz = p->nPgsz; 127185 126485 127186 - assert( p->bFts4 ); 126486 + assert( p->bHasStat ); 127187 126487 assert( pgsz>0 ); 127188 126488 127189 126489 for(ii=0; rc==SQLITE_OK && ii<pMsr->nSegment; ii++){ 127190 126490 Fts3SegReader *pReader = pMsr->apSegment[ii]; 127191 126491 if( !fts3SegReaderIsPending(pReader) 127192 126492 && !fts3SegReaderIsRootOnly(pReader) 127193 126493 ){ ................................................................................ 127537 126837 sqlite3_bind_blob(pStmt, 2, z, n, SQLITE_STATIC); 127538 126838 sqlite3_step(pStmt); 127539 126839 rc = sqlite3_reset(pStmt); 127540 126840 } 127541 126841 return rc; 127542 126842 } 127543 126843 127544 -/* 127545 -** Find the largest relative level number in the table. If successful, set 127546 -** *pnMax to this value and return SQLITE_OK. Otherwise, if an error occurs, 127547 -** set *pnMax to zero and return an SQLite error code. 127548 -*/ 127549 -SQLITE_PRIVATE int sqlite3Fts3MaxLevel(Fts3Table *p, int *pnMax){ 127550 - int rc; 127551 - int mxLevel = 0; 127552 - sqlite3_stmt *pStmt = 0; 127553 - 127554 - rc = fts3SqlStmt(p, SQL_SELECT_MXLEVEL, &pStmt, 0); 127555 - if( rc==SQLITE_OK ){ 127556 - if( SQLITE_ROW==sqlite3_step(pStmt) ){ 127557 - mxLevel = sqlite3_column_int(pStmt, 0); 127558 - } 127559 - rc = sqlite3_reset(pStmt); 127560 - } 127561 - *pnMax = mxLevel; 127562 - return rc; 127563 -} 127564 - 127565 126844 /* 127566 126845 ** Insert a record into the %_segdir table. 127567 126846 */ 127568 126847 static int fts3WriteSegdir( 127569 126848 Fts3Table *p, /* Virtual table handle */ 127570 126849 sqlite3_int64 iLevel, /* Value for "level" field (absolute level) */ 127571 126850 int iIdx, /* Value for "idx" field */ ................................................................................ 127874 127153 127875 127154 if( nData>0 && nData+nReq>p->nNodeSize ){ 127876 127155 int rc; 127877 127156 127878 127157 /* The current leaf node is full. Write it out to the database. */ 127879 127158 rc = fts3WriteSegment(p, pWriter->iFree++, pWriter->aData, nData); 127880 127159 if( rc!=SQLITE_OK ) return rc; 127881 - p->nLeafAdd++; 127882 127160 127883 127161 /* Add the current term to the interior node tree. The term added to 127884 127162 ** the interior tree must: 127885 127163 ** 127886 127164 ** a) be greater than the largest term on the leaf node just written 127887 127165 ** to the database (still available in pWriter->zTerm), and 127888 127166 ** ................................................................................ 127983 127261 p, iLevel, iIdx, pWriter->iFirst, iLastLeaf, iLast, zRoot, nRoot); 127984 127262 } 127985 127263 }else{ 127986 127264 /* The entire tree fits on the root node. Write it to the segdir table. */ 127987 127265 rc = fts3WriteSegdir( 127988 127266 p, iLevel, iIdx, 0, 0, 0, pWriter->aData, pWriter->nData); 127989 127267 } 127990 - p->nLeafAdd++; 127991 127268 return rc; 127992 127269 } 127993 127270 127994 127271 /* 127995 127272 ** Release all memory held by the SegmentWriter object passed as the 127996 127273 ** first argument. 127997 127274 */ ................................................................................ 128065 127342 ); 128066 127343 if( SQLITE_ROW==sqlite3_step(pStmt) ){ 128067 127344 *pnMax = sqlite3_column_int64(pStmt, 0); 128068 127345 } 128069 127346 return sqlite3_reset(pStmt); 128070 127347 } 128071 127348 128072 -/* 128073 -** Delete all entries in the %_segments table associated with the segment 128074 -** opened with seg-reader pSeg. This function does not affect the contents 128075 -** of the %_segdir table. 128076 -*/ 128077 -static int fts3DeleteSegment( 128078 - Fts3Table *p, /* FTS table handle */ 128079 - Fts3SegReader *pSeg /* Segment to delete */ 128080 -){ 128081 - int rc = SQLITE_OK; /* Return code */ 128082 - if( pSeg->iStartBlock ){ 128083 - sqlite3_stmt *pDelete; /* SQL statement to delete rows */ 128084 - rc = fts3SqlStmt(p, SQL_DELETE_SEGMENTS_RANGE, &pDelete, 0); 128085 - if( rc==SQLITE_OK ){ 128086 - sqlite3_bind_int64(pDelete, 1, pSeg->iStartBlock); 128087 - sqlite3_bind_int64(pDelete, 2, pSeg->iEndBlock); 128088 - sqlite3_step(pDelete); 128089 - rc = sqlite3_reset(pDelete); 128090 - } 128091 - } 128092 - return rc; 128093 -} 128094 - 128095 127349 /* 128096 127350 ** This function is used after merging multiple segments into a single large 128097 127351 ** segment to delete the old, now redundant, segment b-trees. Specifically, 128098 127352 ** it: 128099 127353 ** 128100 127354 ** 1) Deletes all %_segments entries for the segments associated with 128101 127355 ** each of the SegReader objects in the array passed as the third ................................................................................ 128110 127364 Fts3Table *p, /* Virtual table handle */ 128111 127365 int iLangid, /* Language id */ 128112 127366 int iIndex, /* Index for p->aIndex */ 128113 127367 int iLevel, /* Level of %_segdir entries to delete */ 128114 127368 Fts3SegReader **apSegment, /* Array of SegReader objects */ 128115 127369 int nReader /* Size of array apSegment */ 128116 127370 ){ 128117 - int rc = SQLITE_OK; /* Return Code */ 127371 + int rc; /* Return Code */ 128118 127372 int i; /* Iterator variable */ 128119 - sqlite3_stmt *pDelete = 0; /* SQL statement to delete rows */ 127373 + sqlite3_stmt *pDelete; /* SQL statement to delete rows */ 128120 127374 127375 + rc = fts3SqlStmt(p, SQL_DELETE_SEGMENTS_RANGE, &pDelete, 0); 128121 127376 for(i=0; rc==SQLITE_OK && i<nReader; i++){ 128122 - rc = fts3DeleteSegment(p, apSegment[i]); 127377 + Fts3SegReader *pSegment = apSegment[i]; 127378 + if( pSegment->iStartBlock ){ 127379 + sqlite3_bind_int64(pDelete, 1, pSegment->iStartBlock); 127380 + sqlite3_bind_int64(pDelete, 2, pSegment->iEndBlock); 127381 + sqlite3_step(pDelete); 127382 + rc = sqlite3_reset(pDelete); 127383 + } 128123 127384 } 128124 127385 if( rc!=SQLITE_OK ){ 128125 127386 return rc; 128126 127387 } 128127 127388 128128 127389 assert( iLevel>=0 || iLevel==FTS3_SEGCURSOR_ALL ); 128129 127390 if( iLevel==FTS3_SEGCURSOR_ALL ){ ................................................................................ 128691 127952 128692 127953 /* 128693 127954 ** Flush the contents of pendingTerms to level 0 segments. 128694 127955 */ 128695 127956 SQLITE_PRIVATE int sqlite3Fts3PendingTermsFlush(Fts3Table *p){ 128696 127957 int rc = SQLITE_OK; 128697 127958 int i; 128698 - 128699 127959 for(i=0; rc==SQLITE_OK && i<p->nIndex; i++){ 128700 127960 rc = fts3SegmentMerge(p, p->iPrevLangid, i, FTS3_SEGCURSOR_PENDING); 128701 127961 if( rc==SQLITE_DONE ) rc = SQLITE_OK; 128702 127962 } 128703 127963 sqlite3Fts3PendingTermsClear(p); 128704 - 128705 - /* Determine the auto-incr-merge setting if unknown. If enabled, 128706 - ** estimate the number of leaf blocks of content to be written 128707 - */ 128708 - if( rc==SQLITE_OK && p->bHasStat 128709 - && p->bAutoincrmerge==0xff && p->nLeafAdd>0 128710 - ){ 128711 - sqlite3_stmt *pStmt = 0; 128712 - rc = fts3SqlStmt(p, SQL_SELECT_STAT, &pStmt, 0); 128713 - if( rc==SQLITE_OK ){ 128714 - sqlite3_bind_int(pStmt, 1, FTS_STAT_AUTOINCRMERGE); 128715 - rc = sqlite3_step(pStmt); 128716 - p->bAutoincrmerge = (rc==SQLITE_ROW && sqlite3_column_int(pStmt, 0)); 128717 - rc = sqlite3_reset(pStmt); 128718 - } 128719 - } 128720 127964 return rc; 128721 127965 } 128722 127966 128723 127967 /* 128724 127968 ** Encode N integers as varints into a blob. 128725 127969 */ 128726 127970 static void fts3EncodeIntArray( ................................................................................ 128823 128067 if( *pRC ) return; 128824 128068 a = sqlite3_malloc( (sizeof(u32)+10)*nStat ); 128825 128069 if( a==0 ){ 128826 128070 *pRC = SQLITE_NOMEM; 128827 128071 return; 128828 128072 } 128829 128073 pBlob = (char*)&a[nStat]; 128830 - rc = fts3SqlStmt(p, SQL_SELECT_STAT, &pStmt, 0); 128074 + rc = fts3SqlStmt(p, SQL_SELECT_DOCTOTAL, &pStmt, 0); 128831 128075 if( rc ){ 128832 128076 sqlite3_free(a); 128833 128077 *pRC = rc; 128834 128078 return; 128835 128079 } 128836 - sqlite3_bind_int(pStmt, 1, FTS_STAT_DOCTOTAL); 128837 128080 if( sqlite3_step(pStmt)==SQLITE_ROW ){ 128838 128081 fts3DecodeIntArray(nStat, a, 128839 128082 sqlite3_column_blob(pStmt, 0), 128840 128083 sqlite3_column_bytes(pStmt, 0)); 128841 128084 }else{ 128842 128085 memset(a, 0, sizeof(u32)*(nStat) ); 128843 128086 } ................................................................................ 128853 128096 x = 0; 128854 128097 }else{ 128855 128098 x = x + aSzIns[i] - aSzDel[i]; 128856 128099 } 128857 128100 a[i+1] = x; 128858 128101 } 128859 128102 fts3EncodeIntArray(nStat, a, pBlob, &nBlob); 128860 - rc = fts3SqlStmt(p, SQL_REPLACE_STAT, &pStmt, 0); 128103 + rc = fts3SqlStmt(p, SQL_REPLACE_DOCTOTAL, &pStmt, 0); 128861 128104 if( rc ){ 128862 128105 sqlite3_free(a); 128863 128106 *pRC = rc; 128864 128107 return; 128865 128108 } 128866 - sqlite3_bind_int(pStmt, 1, FTS_STAT_DOCTOTAL); 128867 - sqlite3_bind_blob(pStmt, 2, pBlob, nBlob, SQLITE_STATIC); 128109 + sqlite3_bind_blob(pStmt, 1, pBlob, nBlob, SQLITE_STATIC); 128868 128110 sqlite3_step(pStmt); 128869 128111 *pRC = sqlite3_reset(pStmt); 128870 128112 sqlite3_free(a); 128871 128113 } 128872 128114 128873 128115 /* 128874 128116 ** Merge the entire database so that there is one segment for each ................................................................................ 128965 128207 }else{ 128966 128208 nEntry++; 128967 128209 for(iCol=0; iCol<=p->nColumn; iCol++){ 128968 128210 aSzIns[iCol] += aSz[iCol]; 128969 128211 } 128970 128212 } 128971 128213 } 128972 - if( p->bFts4 ){ 128214 + if( p->bHasStat ){ 128973 128215 fts3UpdateDocTotals(&rc, p, aSzIns, aSzDel, nEntry); 128974 128216 } 128975 128217 sqlite3_free(aSz); 128976 128218 128977 128219 if( pStmt ){ 128978 128220 int rc2 = sqlite3_finalize(pStmt); 128979 128221 if( rc==SQLITE_OK ){ ................................................................................ 128981 128223 } 128982 128224 } 128983 128225 } 128984 128226 128985 128227 return rc; 128986 128228 } 128987 128229 128988 - 128989 -/* 128990 -** This function opens a cursor used to read the input data for an 128991 -** incremental merge operation. Specifically, it opens a cursor to scan 128992 -** the oldest nSeg segments (idx=0 through idx=(nSeg-1)) in absolute 128993 -** level iAbsLevel. 128994 -*/ 128995 -static int fts3IncrmergeCsr( 128996 - Fts3Table *p, /* FTS3 table handle */ 128997 - sqlite3_int64 iAbsLevel, /* Absolute level to open */ 128998 - int nSeg, /* Number of segments to merge */ 128999 - Fts3MultiSegReader *pCsr /* Cursor object to populate */ 129000 -){ 129001 - int rc; /* Return Code */ 129002 - sqlite3_stmt *pStmt = 0; /* Statement used to read %_segdir entry */ 129003 - int nByte; /* Bytes allocated at pCsr->apSegment[] */ 129004 - 129005 - /* Allocate space for the Fts3MultiSegReader.aCsr[] array */ 129006 - memset(pCsr, 0, sizeof(*pCsr)); 129007 - nByte = sizeof(Fts3SegReader *) * nSeg; 129008 - pCsr->apSegment = (Fts3SegReader **)sqlite3_malloc(nByte); 129009 - 129010 - if( pCsr->apSegment==0 ){ 129011 - rc = SQLITE_NOMEM; 129012 - }else{ 129013 - memset(pCsr->apSegment, 0, nByte); 129014 - rc = fts3SqlStmt(p, SQL_SELECT_LEVEL, &pStmt, 0); 129015 - } 129016 - if( rc==SQLITE_OK ){ 129017 - int i; 129018 - int rc2; 129019 - sqlite3_bind_int64(pStmt, 1, iAbsLevel); 129020 - assert( pCsr->nSegment==0 ); 129021 - for(i=0; rc==SQLITE_OK && sqlite3_step(pStmt)==SQLITE_ROW && i<nSeg; i++){ 129022 - rc = sqlite3Fts3SegReaderNew(i, 0, 129023 - sqlite3_column_int64(pStmt, 1), /* segdir.start_block */ 129024 - sqlite3_column_int64(pStmt, 2), /* segdir.leaves_end_block */ 129025 - sqlite3_column_int64(pStmt, 3), /* segdir.end_block */ 129026 - sqlite3_column_blob(pStmt, 4), /* segdir.root */ 129027 - sqlite3_column_bytes(pStmt, 4), /* segdir.root */ 129028 - &pCsr->apSegment[i] 129029 - ); 129030 - pCsr->nSegment++; 129031 - } 129032 - rc2 = sqlite3_reset(pStmt); 129033 - if( rc==SQLITE_OK ) rc = rc2; 129034 - } 129035 - 129036 - return rc; 129037 -} 129038 - 129039 -typedef struct IncrmergeWriter IncrmergeWriter; 129040 -typedef struct NodeWriter NodeWriter; 129041 -typedef struct Blob Blob; 129042 -typedef struct NodeReader NodeReader; 129043 - 129044 -/* 129045 -** An instance of the following structure is used as a dynamic buffer 129046 -** to build up nodes or other blobs of data in. 129047 -** 129048 -** The function blobGrowBuffer() is used to extend the allocation. 129049 -*/ 129050 -struct Blob { 129051 - char *a; /* Pointer to allocation */ 129052 - int n; /* Number of valid bytes of data in a[] */ 129053 - int nAlloc; /* Allocated size of a[] (nAlloc>=n) */ 129054 -}; 129055 - 129056 -/* 129057 -** This structure is used to build up buffers containing segment b-tree 129058 -** nodes (blocks). 129059 -*/ 129060 -struct NodeWriter { 129061 - sqlite3_int64 iBlock; /* Current block id */ 129062 - Blob key; /* Last key written to the current block */ 129063 - Blob block; /* Current block image */ 129064 -}; 129065 - 129066 -/* 129067 -** An object of this type contains the state required to create or append 129068 -** to an appendable b-tree segment. 129069 -*/ 129070 -struct IncrmergeWriter { 129071 - int nLeafEst; /* Space allocated for leaf blocks */ 129072 - int nWork; /* Number of leaf pages flushed */ 129073 - sqlite3_int64 iAbsLevel; /* Absolute level of input segments */ 129074 - int iIdx; /* Index of *output* segment in iAbsLevel+1 */ 129075 - sqlite3_int64 iStart; /* Block number of first allocated block */ 129076 - sqlite3_int64 iEnd; /* Block number of last allocated block */ 129077 - NodeWriter aNodeWriter[FTS_MAX_APPENDABLE_HEIGHT]; 129078 -}; 129079 - 129080 -/* 129081 -** An object of the following type is used to read data from a single 129082 -** FTS segment node. See the following functions: 129083 -** 129084 -** nodeReaderInit() 129085 -** nodeReaderNext() 129086 -** nodeReaderRelease() 129087 -*/ 129088 -struct NodeReader { 129089 - const char *aNode; 129090 - int nNode; 129091 - int iOff; /* Current offset within aNode[] */ 129092 - 129093 - /* Output variables. Containing the current node entry. */ 129094 - sqlite3_int64 iChild; /* Pointer to child node */ 129095 - Blob term; /* Current term */ 129096 - const char *aDoclist; /* Pointer to doclist */ 129097 - int nDoclist; /* Size of doclist in bytes */ 129098 -}; 129099 - 129100 -/* 129101 -** If *pRc is not SQLITE_OK when this function is called, it is a no-op. 129102 -** Otherwise, if the allocation at pBlob->a is not already at least nMin 129103 -** bytes in size, extend (realloc) it to be so. 129104 -** 129105 -** If an OOM error occurs, set *pRc to SQLITE_NOMEM and leave pBlob->a 129106 -** unmodified. Otherwise, if the allocation succeeds, update pBlob->nAlloc 129107 -** to reflect the new size of the pBlob->a[] buffer. 129108 -*/ 129109 -static void blobGrowBuffer(Blob *pBlob, int nMin, int *pRc){ 129110 - if( *pRc==SQLITE_OK && nMin>pBlob->nAlloc ){ 129111 - int nAlloc = nMin; 129112 - char *a = (char *)sqlite3_realloc(pBlob->a, nAlloc); 129113 - if( a ){ 129114 - pBlob->nAlloc = nAlloc; 129115 - pBlob->a = a; 129116 - }else{ 129117 - *pRc = SQLITE_NOMEM; 129118 - } 129119 - } 129120 -} 129121 - 129122 -/* 129123 -** Attempt to advance the node-reader object passed as the first argument to 129124 -** the next entry on the node. 129125 -** 129126 -** Return an error code if an error occurs (SQLITE_NOMEM is possible). 129127 -** Otherwise return SQLITE_OK. If there is no next entry on the node 129128 -** (e.g. because the current entry is the last) set NodeReader->aNode to 129129 -** NULL to indicate EOF. Otherwise, populate the NodeReader structure output 129130 -** variables for the new entry. 129131 -*/ 129132 -static int nodeReaderNext(NodeReader *p){ 129133 - int bFirst = (p->term.n==0); /* True for first term on the node */ 129134 - int nPrefix = 0; /* Bytes to copy from previous term */ 129135 - int nSuffix = 0; /* Bytes to append to the prefix */ 129136 - int rc = SQLITE_OK; /* Return code */ 129137 - 129138 - assert( p->aNode ); 129139 - if( p->iChild && bFirst==0 ) p->iChild++; 129140 - if( p->iOff>=p->nNode ){ 129141 - /* EOF */ 129142 - p->aNode = 0; 129143 - }else{ 129144 - if( bFirst==0 ){ 129145 - p->iOff += sqlite3Fts3GetVarint32(&p->aNode[p->iOff], &nPrefix); 129146 - } 129147 - p->iOff += sqlite3Fts3GetVarint32(&p->aNode[p->iOff], &nSuffix); 129148 - 129149 - blobGrowBuffer(&p->term, nPrefix+nSuffix, &rc); 129150 - if( rc==SQLITE_OK ){ 129151 - memcpy(&p->term.a[nPrefix], &p->aNode[p->iOff], nSuffix); 129152 - p->term.n = nPrefix+nSuffix; 129153 - p->iOff += nSuffix; 129154 - if( p->iChild==0 ){ 129155 - p->iOff += sqlite3Fts3GetVarint32(&p->aNode[p->iOff], &p->nDoclist); 129156 - p->aDoclist = &p->aNode[p->iOff]; 129157 - p->iOff += p->nDoclist; 129158 - } 129159 - } 129160 - } 129161 - 129162 - assert( p->iOff<=p->nNode ); 129163 - 129164 - return rc; 129165 -} 129166 - 129167 -/* 129168 -** Release all dynamic resources held by node-reader object *p. 129169 -*/ 129170 -static void nodeReaderRelease(NodeReader *p){ 129171 - sqlite3_free(p->term.a); 129172 -} 129173 - 129174 -/* 129175 -** Initialize a node-reader object to read the node in buffer aNode/nNode. 129176 -** 129177 -** If successful, SQLITE_OK is returned and the NodeReader object set to 129178 -** point to the first entry on the node (if any). Otherwise, an SQLite 129179 -** error code is returned. 129180 -*/ 129181 -static int nodeReaderInit(NodeReader *p, const char *aNode, int nNode){ 129182 - memset(p, 0, sizeof(NodeReader)); 129183 - p->aNode = aNode; 129184 - p->nNode = nNode; 129185 - 129186 - /* Figure out if this is a leaf or an internal node. */ 129187 - if( p->aNode[0] ){ 129188 - /* An internal node. */ 129189 - p->iOff = 1 + sqlite3Fts3GetVarint(&p->aNode[1], &p->iChild); 129190 - }else{ 129191 - p->iOff = 1; 129192 - } 129193 - 129194 - return nodeReaderNext(p); 129195 -} 129196 - 129197 -/* 129198 -** This function is called while writing an FTS segment each time a leaf o 129199 -** node is finished and written to disk. The key (zTerm/nTerm) is guaranteed 129200 -** to be greater than the largest key on the node just written, but smaller 129201 -** than or equal to the first key that will be written to the next leaf 129202 -** node. 129203 -** 129204 -** The block id of the leaf node just written to disk may be found in 129205 -** (pWriter->aNodeWriter[0].iBlock) when this function is called. 129206 -*/ 129207 -static int fts3IncrmergePush( 129208 - Fts3Table *p, /* Fts3 table handle */ 129209 - IncrmergeWriter *pWriter, /* Writer object */ 129210 - const char *zTerm, /* Term to write to internal node */ 129211 - int nTerm /* Bytes at zTerm */ 129212 -){ 129213 - sqlite3_int64 iPtr = pWriter->aNodeWriter[0].iBlock; 129214 - int iLayer; 129215 - 129216 - assert( nTerm>0 ); 129217 - for(iLayer=1; ALWAYS(iLayer<FTS_MAX_APPENDABLE_HEIGHT); iLayer++){ 129218 - sqlite3_int64 iNextPtr = 0; 129219 - NodeWriter *pNode = &pWriter->aNodeWriter[iLayer]; 129220 - int rc = SQLITE_OK; 129221 - int nPrefix; 129222 - int nSuffix; 129223 - int nSpace; 129224 - 129225 - /* Figure out how much space the key will consume if it is written to 129226 - ** the current node of layer iLayer. Due to the prefix compression, 129227 - ** the space required changes depending on which node the key is to 129228 - ** be added to. */ 129229 - nPrefix = fts3PrefixCompress(pNode->key.a, pNode->key.n, zTerm, nTerm); 129230 - nSuffix = nTerm - nPrefix; 129231 - nSpace = sqlite3Fts3VarintLen(nPrefix); 129232 - nSpace += sqlite3Fts3VarintLen(nSuffix) + nSuffix; 129233 - 129234 - if( pNode->key.n==0 || (pNode->block.n + nSpace)<=p->nNodeSize ){ 129235 - /* If the current node of layer iLayer contains zero keys, or if adding 129236 - ** the key to it will not cause it to grow to larger than nNodeSize 129237 - ** bytes in size, write the key here. */ 129238 - 129239 - Blob *pBlk = &pNode->block; 129240 - if( pBlk->n==0 ){ 129241 - blobGrowBuffer(pBlk, p->nNodeSize, &rc); 129242 - if( rc==SQLITE_OK ){ 129243 - pBlk->a[0] = (char)iLayer; 129244 - pBlk->n = 1 + sqlite3Fts3PutVarint(&pBlk->a[1], iPtr); 129245 - } 129246 - } 129247 - blobGrowBuffer(pBlk, pBlk->n + nSpace, &rc); 129248 - blobGrowBuffer(&pNode->key, nTerm, &rc); 129249 - 129250 - if( rc==SQLITE_OK ){ 129251 - if( pNode->key.n ){ 129252 - pBlk->n += sqlite3Fts3PutVarint(&pBlk->a[pBlk->n], nPrefix); 129253 - } 129254 - pBlk->n += sqlite3Fts3PutVarint(&pBlk->a[pBlk->n], nSuffix); 129255 - memcpy(&pBlk->a[pBlk->n], &zTerm[nPrefix], nSuffix); 129256 - pBlk->n += nSuffix; 129257 - 129258 - memcpy(pNode->key.a, zTerm, nTerm); 129259 - pNode->key.n = nTerm; 129260 - } 129261 - }else{ 129262 - /* Otherwise, flush the the current node of layer iLayer to disk. 129263 - ** Then allocate a new, empty sibling node. The key will be written 129264 - ** into the parent of this node. */ 129265 - rc = fts3WriteSegment(p, pNode->iBlock, pNode->block.a, pNode->block.n); 129266 - 129267 - assert( pNode->block.nAlloc>=p->nNodeSize ); 129268 - pNode->block.a[0] = (char)iLayer; 129269 - pNode->block.n = 1 + sqlite3Fts3PutVarint(&pNode->block.a[1], iPtr+1); 129270 - 129271 - iNextPtr = pNode->iBlock; 129272 - pNode->iBlock++; 129273 - pNode->key.n = 0; 129274 - } 129275 - 129276 - if( rc!=SQLITE_OK || iNextPtr==0 ) return rc; 129277 - iPtr = iNextPtr; 129278 - } 129279 - 129280 - assert( 0 ); 129281 - return 0; 129282 -} 129283 - 129284 -/* 129285 -** Append a term and (optionally) doclist to the FTS segment node currently 129286 -** stored in blob *pNode. The node need not contain any terms, but the 129287 -** header must be written before this function is called. 129288 -** 129289 -** A node header is a single 0x00 byte for a leaf node, or a height varint 129290 -** followed by the left-hand-child varint for an internal node. 129291 -** 129292 -** The term to be appended is passed via arguments zTerm/nTerm. For a 129293 -** leaf node, the doclist is passed as aDoclist/nDoclist. For an internal 129294 -** node, both aDoclist and nDoclist must be passed 0. 129295 -** 129296 -** If the size of the value in blob pPrev is zero, then this is the first 129297 -** term written to the node. Otherwise, pPrev contains a copy of the 129298 -** previous term. Before this function returns, it is updated to contain a 129299 -** copy of zTerm/nTerm. 129300 -** 129301 -** It is assumed that the buffer associated with pNode is already large 129302 -** enough to accommodate the new entry. The buffer associated with pPrev 129303 -** is extended by this function if requrired. 129304 -** 129305 -** If an error (i.e. OOM condition) occurs, an SQLite error code is 129306 -** returned. Otherwise, SQLITE_OK. 129307 -*/ 129308 -static int fts3AppendToNode( 129309 - Blob *pNode, /* Current node image to append to */ 129310 - Blob *pPrev, /* Buffer containing previous term written */ 129311 - const char *zTerm, /* New term to write */ 129312 - int nTerm, /* Size of zTerm in bytes */ 129313 - const char *aDoclist, /* Doclist (or NULL) to write */ 129314 - int nDoclist /* Size of aDoclist in bytes */ 129315 -){ 129316 - int rc = SQLITE_OK; /* Return code */ 129317 - int bFirst = (pPrev->n==0); /* True if this is the first term written */ 129318 - int nPrefix; /* Size of term prefix in bytes */ 129319 - int nSuffix; /* Size of term suffix in bytes */ 129320 - 129321 - /* Node must have already been started. There must be a doclist for a 129322 - ** leaf node, and there must not be a doclist for an internal node. */ 129323 - assert( pNode->n>0 ); 129324 - assert( (pNode->a[0]=='\0')==(aDoclist!=0) ); 129325 - 129326 - blobGrowBuffer(pPrev, nTerm, &rc); 129327 - if( rc!=SQLITE_OK ) return rc; 129328 - 129329 - nPrefix = fts3PrefixCompress(pPrev->a, pPrev->n, zTerm, nTerm); 129330 - nSuffix = nTerm - nPrefix; 129331 - memcpy(pPrev->a, zTerm, nTerm); 129332 - pPrev->n = nTerm; 129333 - 129334 - if( bFirst==0 ){ 129335 - pNode->n += sqlite3Fts3PutVarint(&pNode->a[pNode->n], nPrefix); 129336 - } 129337 - pNode->n += sqlite3Fts3PutVarint(&pNode->a[pNode->n], nSuffix); 129338 - memcpy(&pNode->a[pNode->n], &zTerm[nPrefix], nSuffix); 129339 - pNode->n += nSuffix; 129340 - 129341 - if( aDoclist ){ 129342 - pNode->n += sqlite3Fts3PutVarint(&pNode->a[pNode->n], nDoclist); 129343 - memcpy(&pNode->a[pNode->n], aDoclist, nDoclist); 129344 - pNode->n += nDoclist; 129345 - } 129346 - 129347 - assert( pNode->n<=pNode->nAlloc ); 129348 - 129349 - return SQLITE_OK; 129350 -} 129351 - 129352 -/* 129353 -** Append the current term and doclist pointed to by cursor pCsr to the 129354 -** appendable b-tree segment opened for writing by pWriter. 129355 -** 129356 -** Return SQLITE_OK if successful, or an SQLite error code otherwise. 129357 -*/ 129358 -static int fts3IncrmergeAppend( 129359 - Fts3Table *p, /* Fts3 table handle */ 129360 - IncrmergeWriter *pWriter, /* Writer object */ 129361 - Fts3MultiSegReader *pCsr /* Cursor containing term and doclist */ 129362 -){ 129363 - const char *zTerm = pCsr->zTerm; 129364 - int nTerm = pCsr->nTerm; 129365 - const char *aDoclist = pCsr->aDoclist; 129366 - int nDoclist = pCsr->nDoclist; 129367 - int rc = SQLITE_OK; /* Return code */ 129368 - int nSpace; /* Total space in bytes required on leaf */ 129369 - int nPrefix; /* Size of prefix shared with previous term */ 129370 - int nSuffix; /* Size of suffix (nTerm - nPrefix) */ 129371 - NodeWriter *pLeaf; /* Object used to write leaf nodes */ 129372 - 129373 - pLeaf = &pWriter->aNodeWriter[0]; 129374 - nPrefix = fts3PrefixCompress(pLeaf->key.a, pLeaf->key.n, zTerm, nTerm); 129375 - nSuffix = nTerm - nPrefix; 129376 - 129377 - nSpace = sqlite3Fts3VarintLen(nPrefix); 129378 - nSpace += sqlite3Fts3VarintLen(nSuffix) + nSuffix; 129379 - nSpace += sqlite3Fts3VarintLen(nDoclist) + nDoclist; 129380 - 129381 - /* If the current block is not empty, and if adding this term/doclist 129382 - ** to the current block would make it larger than Fts3Table.nNodeSize 129383 - ** bytes, write this block out to the database. */ 129384 - if( pLeaf->block.n>0 && (pLeaf->block.n + nSpace)>p->nNodeSize ){ 129385 - rc = fts3WriteSegment(p, pLeaf->iBlock, pLeaf->block.a, pLeaf->block.n); 129386 - pWriter->nWork++; 129387 - 129388 - /* Add the current term to the parent node. The term added to the 129389 - ** parent must: 129390 - ** 129391 - ** a) be greater than the largest term on the leaf node just written 129392 - ** to the database (still available in pLeaf->key), and 129393 - ** 129394 - ** b) be less than or equal to the term about to be added to the new 129395 - ** leaf node (zTerm/nTerm). 129396 - ** 129397 - ** In other words, it must be the prefix of zTerm 1 byte longer than 129398 - ** the common prefix (if any) of zTerm and pWriter->zTerm. 129399 - */ 129400 - if( rc==SQLITE_OK ){ 129401 - rc = fts3IncrmergePush(p, pWriter, zTerm, nPrefix+1); 129402 - } 129403 - 129404 - /* Advance to the next output block */ 129405 - pLeaf->iBlock++; 129406 - pLeaf->key.n = 0; 129407 - pLeaf->block.n = 0; 129408 - 129409 - nSuffix = nTerm; 129410 - nSpace = 1; 129411 - nSpace += sqlite3Fts3VarintLen(nSuffix) + nSuffix; 129412 - nSpace += sqlite3Fts3VarintLen(nDoclist) + nDoclist; 129413 - } 129414 - 129415 - blobGrowBuffer(&pLeaf->block, pLeaf->block.n + nSpace, &rc); 129416 - 129417 - if( rc==SQLITE_OK ){ 129418 - if( pLeaf->block.n==0 ){ 129419 - pLeaf->block.n = 1; 129420 - pLeaf->block.a[0] = '\0'; 129421 - } 129422 - rc = fts3AppendToNode( 129423 - &pLeaf->block, &pLeaf->key, zTerm, nTerm, aDoclist, nDoclist 129424 - ); 129425 - } 129426 - 129427 - return rc; 129428 -} 129429 - 129430 -/* 129431 -** This function is called to release all dynamic resources held by the 129432 -** merge-writer object pWriter, and if no error has occurred, to flush 129433 -** all outstanding node buffers held by pWriter to disk. 129434 -** 129435 -** If *pRc is not SQLITE_OK when this function is called, then no attempt 129436 -** is made to write any data to disk. Instead, this function serves only 129437 -** to release outstanding resources. 129438 -** 129439 -** Otherwise, if *pRc is initially SQLITE_OK and an error occurs while 129440 -** flushing buffers to disk, *pRc is set to an SQLite error code before 129441 -** returning. 129442 -*/ 129443 -static void fts3IncrmergeRelease( 129444 - Fts3Table *p, /* FTS3 table handle */ 129445 - IncrmergeWriter *pWriter, /* Merge-writer object */ 129446 - int *pRc /* IN/OUT: Error code */ 129447 -){ 129448 - int i; /* Used to iterate through non-root layers */ 129449 - int iRoot; /* Index of root in pWriter->aNodeWriter */ 129450 - NodeWriter *pRoot; /* NodeWriter for root node */ 129451 - int rc = *pRc; /* Error code */ 129452 - 129453 - /* Set iRoot to the index in pWriter->aNodeWriter[] of the output segment 129454 - ** root node. If the segment fits entirely on a single leaf node, iRoot 129455 - ** will be set to 0. If the root node is the parent of the leaves, iRoot 129456 - ** will be 1. And so on. */ 129457 - for(iRoot=FTS_MAX_APPENDABLE_HEIGHT-1; iRoot>=0; iRoot--){ 129458 - NodeWriter *pNode = &pWriter->aNodeWriter[iRoot]; 129459 - if( pNode->block.n>0 ) break; 129460 - assert( *pRc || pNode->block.nAlloc==0 ); 129461 - assert( *pRc || pNode->key.nAlloc==0 ); 129462 - sqlite3_free(pNode->block.a); 129463 - sqlite3_free(pNode->key.a); 129464 - } 129465 - 129466 - /* Empty output segment. This is a no-op. */ 129467 - if( iRoot<0 ) return; 129468 - 129469 - /* The entire output segment fits on a single node. Normally, this means 129470 - ** the node would be stored as a blob in the "root" column of the %_segdir 129471 - ** table. However, this is not permitted in this case. The problem is that 129472 - ** space has already been reserved in the %_segments table, and so the 129473 - ** start_block and end_block fields of the %_segdir table must be populated. 129474 - ** And, by design or by accident, released versions of FTS cannot handle 129475 - ** segments that fit entirely on the root node with start_block!=0. 129476 - ** 129477 - ** Instead, create a synthetic root node that contains nothing but a 129478 - ** pointer to the single content node. So that the segment consists of a 129479 - ** single leaf and a single interior (root) node. 129480 - ** 129481 - ** Todo: Better might be to defer allocating space in the %_segments 129482 - ** table until we are sure it is needed. 129483 - */ 129484 - if( iRoot==0 ){ 129485 - Blob *pBlock = &pWriter->aNodeWriter[1].block; 129486 - blobGrowBuffer(pBlock, 1 + FTS3_VARINT_MAX, &rc); 129487 - if( rc==SQLITE_OK ){ 129488 - pBlock->a[0] = 0x01; 129489 - pBlock->n = 1 + sqlite3Fts3PutVarint( 129490 - &pBlock->a[1], pWriter->aNodeWriter[0].iBlock 129491 - ); 129492 - } 129493 - iRoot = 1; 129494 - } 129495 - pRoot = &pWriter->aNodeWriter[iRoot]; 129496 - 129497 - /* Flush all currently outstanding nodes to disk. */ 129498 - for(i=0; i<iRoot; i++){ 129499 - NodeWriter *pNode = &pWriter->aNodeWriter[i]; 129500 - if( pNode->block.n>0 && rc==SQLITE_OK ){ 129501 - rc = fts3WriteSegment(p, pNode->iBlock, pNode->block.a, pNode->block.n); 129502 - } 129503 - sqlite3_free(pNode->block.a); 129504 - sqlite3_free(pNode->key.a); 129505 - } 129506 - 129507 - /* Write the %_segdir record. */ 129508 - if( rc==SQLITE_OK ){ 129509 - rc = fts3WriteSegdir(p, 129510 - pWriter->iAbsLevel+1, /* level */ 129511 - pWriter->iIdx, /* idx */ 129512 - pWriter->iStart, /* start_block */ 129513 - pWriter->aNodeWriter[0].iBlock, /* leaves_end_block */ 129514 - pWriter->iEnd, /* end_block */ 129515 - pRoot->block.a, pRoot->block.n /* root */ 129516 - ); 129517 - } 129518 - sqlite3_free(pRoot->block.a); 129519 - sqlite3_free(pRoot->key.a); 129520 - 129521 - *pRc = rc; 129522 -} 129523 - 129524 -/* 129525 -** Compare the term in buffer zLhs (size in bytes nLhs) with that in 129526 -** zRhs (size in bytes nRhs) using memcmp. If one term is a prefix of 129527 -** the other, it is considered to be smaller than the other. 129528 -** 129529 -** Return -ve if zLhs is smaller than zRhs, 0 if it is equal, or +ve 129530 -** if it is greater. 129531 -*/ 129532 -static int fts3TermCmp( 129533 - const char *zLhs, int nLhs, /* LHS of comparison */ 129534 - const char *zRhs, int nRhs /* RHS of comparison */ 129535 -){ 129536 - int nCmp = MIN(nLhs, nRhs); 129537 - int res; 129538 - 129539 - res = memcmp(zLhs, zRhs, nCmp); 129540 - if( res==0 ) res = nLhs - nRhs; 129541 - 129542 - return res; 129543 -} 129544 - 129545 - 129546 -/* 129547 -** Query to see if the entry in the %_segments table with blockid iEnd is 129548 -** NULL. If no error occurs and the entry is NULL, set *pbRes 1 before 129549 -** returning. Otherwise, set *pbRes to 0. 129550 -** 129551 -** Or, if an error occurs while querying the database, return an SQLite 129552 -** error code. The final value of *pbRes is undefined in this case. 129553 -** 129554 -** This is used to test if a segment is an "appendable" segment. If it 129555 -** is, then a NULL entry has been inserted into the %_segments table 129556 -** with blockid %_segdir.end_block. 129557 -*/ 129558 -static int fts3IsAppendable(Fts3Table *p, sqlite3_int64 iEnd, int *pbRes){ 129559 - int bRes = 0; /* Result to set *pbRes to */ 129560 - sqlite3_stmt *pCheck = 0; /* Statement to query database with */ 129561 - int rc; /* Return code */ 129562 - 129563 - rc = fts3SqlStmt(p, SQL_SEGMENT_IS_APPENDABLE, &pCheck, 0); 129564 - if( rc==SQLITE_OK ){ 129565 - sqlite3_bind_int64(pCheck, 1, iEnd); 129566 - if( SQLITE_ROW==sqlite3_step(pCheck) ) bRes = 1; 129567 - rc = sqlite3_reset(pCheck); 129568 - } 129569 - 129570 - *pbRes = bRes; 129571 - return rc; 129572 -} 129573 - 129574 -/* 129575 -** This function is called when initializing an incremental-merge operation. 129576 -** It checks if the existing segment with index value iIdx at absolute level 129577 -** (iAbsLevel+1) can be appended to by the incremental merge. If it can, the 129578 -** merge-writer object *pWriter is initialized to write to it. 129579 -** 129580 -** An existing segment can be appended to by an incremental merge if: 129581 -** 129582 -** * It was initially created as an appendable segment (with all required 129583 -** space pre-allocated), and 129584 -** 129585 -** * The first key read from the input (arguments zKey and nKey) is 129586 -** greater than the largest key currently stored in the potential 129587 -** output segment. 129588 -*/ 129589 -static int fts3IncrmergeLoad( 129590 - Fts3Table *p, /* Fts3 table handle */ 129591 - sqlite3_int64 iAbsLevel, /* Absolute level of input segments */ 129592 - int iIdx, /* Index of candidate output segment */ 129593 - const char *zKey, /* First key to write */ 129594 - int nKey, /* Number of bytes in nKey */ 129595 - IncrmergeWriter *pWriter /* Populate this object */ 129596 -){ 129597 - int rc; /* Return code */ 129598 - sqlite3_stmt *pSelect = 0; /* SELECT to read %_segdir entry */ 129599 - 129600 - rc = fts3SqlStmt(p, SQL_SELECT_SEGDIR, &pSelect, 0); 129601 - if( rc==SQLITE_OK ){ 129602 - sqlite3_int64 iStart = 0; /* Value of %_segdir.start_block */ 129603 - sqlite3_int64 iLeafEnd = 0; /* Value of %_segdir.leaves_end_block */ 129604 - sqlite3_int64 iEnd = 0; /* Value of %_segdir.end_block */ 129605 - const char *aRoot = 0; /* Pointer to %_segdir.root buffer */ 129606 - int nRoot = 0; /* Size of aRoot[] in bytes */ 129607 - int rc2; /* Return code from sqlite3_reset() */ 129608 - int bAppendable = 0; /* Set to true if segment is appendable */ 129609 - 129610 - /* Read the %_segdir entry for index iIdx absolute level (iAbsLevel+1) */ 129611 - sqlite3_bind_int64(pSelect, 1, iAbsLevel+1); 129612 - sqlite3_bind_int(pSelect, 2, iIdx); 129613 - if( sqlite3_step(pSelect)==SQLITE_ROW ){ 129614 - iStart = sqlite3_column_int64(pSelect, 1); 129615 - iLeafEnd = sqlite3_column_int64(pSelect, 2); 129616 - iEnd = sqlite3_column_int64(pSelect, 3); 129617 - nRoot = sqlite3_column_bytes(pSelect, 4); 129618 - aRoot = sqlite3_column_blob(pSelect, 4); 129619 - }else{ 129620 - return sqlite3_reset(pSelect); 129621 - } 129622 - 129623 - /* Check for the zero-length marker in the %_segments table */ 129624 - rc = fts3IsAppendable(p, iEnd, &bAppendable); 129625 - 129626 - /* Check that zKey/nKey is larger than the largest key the candidate */ 129627 - if( rc==SQLITE_OK && bAppendable ){ 129628 - char *aLeaf = 0; 129629 - int nLeaf = 0; 129630 - 129631 - rc = sqlite3Fts3ReadBlock(p, iLeafEnd, &aLeaf, &nLeaf, 0); 129632 - if( rc==SQLITE_OK ){ 129633 - NodeReader reader; 129634 - for(rc = nodeReaderInit(&reader, aLeaf, nLeaf); 129635 - rc==SQLITE_OK && reader.aNode; 129636 - rc = nodeReaderNext(&reader) 129637 - ){ 129638 - assert( reader.aNode ); 129639 - } 129640 - if( fts3TermCmp(zKey, nKey, reader.term.a, reader.term.n)<=0 ){ 129641 - bAppendable = 0; 129642 - } 129643 - nodeReaderRelease(&reader); 129644 - } 129645 - sqlite3_free(aLeaf); 129646 - } 129647 - 129648 - if( rc==SQLITE_OK && bAppendable ){ 129649 - /* It is possible to append to this segment. Set up the IncrmergeWriter 129650 - ** object to do so. */ 129651 - int i; 129652 - int nHeight = (int)aRoot[0]; 129653 - NodeWriter *pNode; 129654 - 129655 - pWriter->nLeafEst = (int)((iEnd - iStart) + 1)/FTS_MAX_APPENDABLE_HEIGHT; 129656 - pWriter->iStart = iStart; 129657 - pWriter->iEnd = iEnd; 129658 - pWriter->iAbsLevel = iAbsLevel; 129659 - pWriter->iIdx = iIdx; 129660 - 129661 - for(i=nHeight+1; i<FTS_MAX_APPENDABLE_HEIGHT; i++){ 129662 - pWriter->aNodeWriter[i].iBlock = pWriter->iStart + i*pWriter->nLeafEst; 129663 - } 129664 - 129665 - pNode = &pWriter->aNodeWriter[nHeight]; 129666 - pNode->iBlock = pWriter->iStart + pWriter->nLeafEst*nHeight; 129667 - blobGrowBuffer(&pNode->block, MAX(nRoot, p->nNodeSize), &rc); 129668 - if( rc==SQLITE_OK ){ 129669 - memcpy(pNode->block.a, aRoot, nRoot); 129670 - pNode->block.n = nRoot; 129671 - } 129672 - 129673 - for(i=nHeight; i>=0 && rc==SQLITE_OK; i--){ 129674 - NodeReader reader; 129675 - pNode = &pWriter->aNodeWriter[i]; 129676 - 129677 - rc = nodeReaderInit(&reader, pNode->block.a, pNode->block.n); 129678 - while( reader.aNode && rc==SQLITE_OK ) rc = nodeReaderNext(&reader); 129679 - blobGrowBuffer(&pNode->key, reader.term.n, &rc); 129680 - if( rc==SQLITE_OK ){ 129681 - memcpy(pNode->key.a, reader.term.a, reader.term.n); 129682 - pNode->key.n = reader.term.n; 129683 - if( i>0 ){ 129684 - char *aBlock = 0; 129685 - int nBlock = 0; 129686 - pNode = &pWriter->aNodeWriter[i-1]; 129687 - pNode->iBlock = reader.iChild; 129688 - rc = sqlite3Fts3ReadBlock(p, reader.iChild, &aBlock, &nBlock, 0); 129689 - blobGrowBuffer(&pNode->block, MAX(nBlock, p->nNodeSize), &rc); 129690 - if( rc==SQLITE_OK ){ 129691 - memcpy(pNode->block.a, aBlock, nBlock); 129692 - pNode->block.n = nBlock; 129693 - } 129694 - sqlite3_free(aBlock); 129695 - } 129696 - } 129697 - nodeReaderRelease(&reader); 129698 - } 129699 - } 129700 - 129701 - rc2 = sqlite3_reset(pSelect); 129702 - if( rc==SQLITE_OK ) rc = rc2; 129703 - } 129704 - 129705 - return rc; 129706 -} 129707 - 129708 -/* 129709 -** Determine the largest segment index value that exists within absolute 129710 -** level iAbsLevel+1. If no error occurs, set *piIdx to this value plus 129711 -** one before returning SQLITE_OK. Or, if there are no segments at all 129712 -** within level iAbsLevel, set *piIdx to zero. 129713 -** 129714 -** If an error occurs, return an SQLite error code. The final value of 129715 -** *piIdx is undefined in this case. 129716 -*/ 129717 -static int fts3IncrmergeOutputIdx( 129718 - Fts3Table *p, /* FTS Table handle */ 129719 - sqlite3_int64 iAbsLevel, /* Absolute index of input segments */ 129720 - int *piIdx /* OUT: Next free index at iAbsLevel+1 */ 129721 -){ 129722 - int rc; 129723 - sqlite3_stmt *pOutputIdx = 0; /* SQL used to find output index */ 129724 - 129725 - rc = fts3SqlStmt(p, SQL_NEXT_SEGMENT_INDEX, &pOutputIdx, 0); 129726 - if( rc==SQLITE_OK ){ 129727 - sqlite3_bind_int64(pOutputIdx, 1, iAbsLevel+1); 129728 - sqlite3_step(pOutputIdx); 129729 - *piIdx = sqlite3_column_int(pOutputIdx, 0); 129730 - rc = sqlite3_reset(pOutputIdx); 129731 - } 129732 - 129733 - return rc; 129734 -} 129735 - 129736 -/* 129737 -** Allocate an appendable output segment on absolute level iAbsLevel+1 129738 -** with idx value iIdx. 129739 -** 129740 -** In the %_segdir table, a segment is defined by the values in three 129741 -** columns: 129742 -** 129743 -** start_block 129744 -** leaves_end_block 129745 -** end_block 129746 -** 129747 -** When an appendable segment is allocated, it is estimated that the 129748 -** maximum number of leaf blocks that may be required is the sum of the 129749 -** number of leaf blocks consumed by the input segments, plus the number 129750 -** of input segments, multiplied by two. This value is stored in stack 129751 -** variable nLeafEst. 129752 -** 129753 -** A total of 16*nLeafEst blocks are allocated when an appendable segment 129754 -** is created ((1 + end_block - start_block)==16*nLeafEst). The contiguous 129755 -** array of leaf nodes starts at the first block allocated. The array 129756 -** of interior nodes that are parents of the leaf nodes start at block 129757 -** (start_block + (1 + end_block - start_block) / 16). And so on. 129758 -** 129759 -** In the actual code below, the value "16" is replaced with the 129760 -** pre-processor macro FTS_MAX_APPENDABLE_HEIGHT. 129761 -*/ 129762 -static int fts3IncrmergeWriter( 129763 - Fts3Table *p, /* Fts3 table handle */ 129764 - sqlite3_int64 iAbsLevel, /* Absolute level of input segments */ 129765 - int iIdx, /* Index of new output segment */ 129766 - Fts3MultiSegReader *pCsr, /* Cursor that data will be read from */ 129767 - IncrmergeWriter *pWriter /* Populate this object */ 129768 -){ 129769 - int rc; /* Return Code */ 129770 - int i; /* Iterator variable */ 129771 - int nLeafEst = 0; /* Blocks allocated for leaf nodes */ 129772 - sqlite3_stmt *pLeafEst = 0; /* SQL used to determine nLeafEst */ 129773 - sqlite3_stmt *pFirstBlock = 0; /* SQL used to determine first block */ 129774 - 129775 - /* Calculate nLeafEst. */ 129776 - rc = fts3SqlStmt(p, SQL_MAX_LEAF_NODE_ESTIMATE, &pLeafEst, 0); 129777 - if( rc==SQLITE_OK ){ 129778 - sqlite3_bind_int64(pLeafEst, 1, iAbsLevel); 129779 - sqlite3_bind_int64(pLeafEst, 2, pCsr->nSegment); 129780 - if( SQLITE_ROW==sqlite3_step(pLeafEst) ){ 129781 - nLeafEst = sqlite3_column_int(pLeafEst, 0); 129782 - } 129783 - rc = sqlite3_reset(pLeafEst); 129784 - } 129785 - if( rc!=SQLITE_OK ) return rc; 129786 - 129787 - /* Calculate the first block to use in the output segment */ 129788 - rc = fts3SqlStmt(p, SQL_NEXT_SEGMENTS_ID, &pFirstBlock, 0); 129789 - if( rc==SQLITE_OK ){ 129790 - if( SQLITE_ROW==sqlite3_step(pFirstBlock) ){ 129791 - pWriter->iStart = sqlite3_column_int64(pFirstBlock, 0); 129792 - pWriter->iEnd = pWriter->iStart - 1; 129793 - pWriter->iEnd += nLeafEst * FTS_MAX_APPENDABLE_HEIGHT; 129794 - } 129795 - rc = sqlite3_reset(pFirstBlock); 129796 - } 129797 - if( rc!=SQLITE_OK ) return rc; 129798 - 129799 - /* Insert the marker in the %_segments table to make sure nobody tries 129800 - ** to steal the space just allocated. This is also used to identify 129801 - ** appendable segments. */ 129802 - rc = fts3WriteSegment(p, pWriter->iEnd, 0, 0); 129803 - if( rc!=SQLITE_OK ) return rc; 129804 - 129805 - pWriter->iAbsLevel = iAbsLevel; 129806 - pWriter->nLeafEst = nLeafEst; 129807 - pWriter->iIdx = iIdx; 129808 - 129809 - /* Set up the array of NodeWriter objects */ 129810 - for(i=0; i<FTS_MAX_APPENDABLE_HEIGHT; i++){ 129811 - pWriter->aNodeWriter[i].iBlock = pWriter->iStart + i*pWriter->nLeafEst; 129812 - } 129813 - return SQLITE_OK; 129814 -} 129815 - 129816 -/* 129817 -** Remove an entry from the %_segdir table. This involves running the 129818 -** following two statements: 129819 -** 129820 -** DELETE FROM %_segdir WHERE level = :iAbsLevel AND idx = :iIdx 129821 -** UPDATE %_segdir SET idx = idx - 1 WHERE level = :iAbsLevel AND idx > :iIdx 129822 -** 129823 -** The DELETE statement removes the specific %_segdir level. The UPDATE 129824 -** statement ensures that the remaining segments have contiguously allocated 129825 -** idx values. 129826 -*/ 129827 -static int fts3RemoveSegdirEntry( 129828 - Fts3Table *p, /* FTS3 table handle */ 129829 - sqlite3_int64 iAbsLevel, /* Absolute level to delete from */ 129830 - int iIdx /* Index of %_segdir entry to delete */ 129831 -){ 129832 - int rc; /* Return code */ 129833 - sqlite3_stmt *pDelete = 0; /* DELETE statement */ 129834 - 129835 - rc = fts3SqlStmt(p, SQL_DELETE_SEGDIR_ENTRY, &pDelete, 0); 129836 - if( rc==SQLITE_OK ){ 129837 - sqlite3_bind_int64(pDelete, 1, iAbsLevel); 129838 - sqlite3_bind_int(pDelete, 2, iIdx); 129839 - sqlite3_step(pDelete); 129840 - rc = sqlite3_reset(pDelete); 129841 - } 129842 - 129843 - return rc; 129844 -} 129845 - 129846 -/* 129847 -** One or more segments have just been removed from absolute level iAbsLevel. 129848 -** Update the 'idx' values of the remaining segments in the level so that 129849 -** the idx values are a contiguous sequence starting from 0. 129850 -*/ 129851 -static int fts3RepackSegdirLevel( 129852 - Fts3Table *p, /* FTS3 table handle */ 129853 - sqlite3_int64 iAbsLevel /* Absolute level to repack */ 129854 -){ 129855 - int rc; /* Return code */ 129856 - int *aIdx = 0; /* Array of remaining idx values */ 129857 - int nIdx = 0; /* Valid entries in aIdx[] */ 129858 - int nAlloc = 0; /* Allocated size of aIdx[] */ 129859 - int i; /* Iterator variable */ 129860 - sqlite3_stmt *pSelect = 0; /* Select statement to read idx values */ 129861 - sqlite3_stmt *pUpdate = 0; /* Update statement to modify idx values */ 129862 - 129863 - rc = fts3SqlStmt(p, SQL_SELECT_INDEXES, &pSelect, 0); 129864 - if( rc==SQLITE_OK ){ 129865 - int rc2; 129866 - sqlite3_bind_int64(pSelect, 1, iAbsLevel); 129867 - while( SQLITE_ROW==sqlite3_step(pSelect) ){ 129868 - if( nIdx>=nAlloc ){ 129869 - int *aNew; 129870 - nAlloc += 16; 129871 - aNew = sqlite3_realloc(aIdx, nAlloc*sizeof(int)); 129872 - if( !aNew ){ 129873 - rc = SQLITE_NOMEM; 129874 - break; 129875 - } 129876 - aIdx = aNew; 129877 - } 129878 - aIdx[nIdx++] = sqlite3_column_int(pSelect, 0); 129879 - } 129880 - rc2 = sqlite3_reset(pSelect); 129881 - if( rc==SQLITE_OK ) rc = rc2; 129882 - } 129883 - 129884 - if( rc==SQLITE_OK ){ 129885 - rc = fts3SqlStmt(p, SQL_SHIFT_SEGDIR_ENTRY, &pUpdate, 0); 129886 - } 129887 - if( rc==SQLITE_OK ){ 129888 - sqlite3_bind_int64(pUpdate, 2, iAbsLevel); 129889 - } 129890 - 129891 - assert( p->bIgnoreSavepoint==0 ); 129892 - p->bIgnoreSavepoint = 1; 129893 - for(i=0; rc==SQLITE_OK && i<nIdx; i++){ 129894 - if( aIdx[i]!=i ){ 129895 - sqlite3_bind_int(pUpdate, 3, aIdx[i]); 129896 - sqlite3_bind_int(pUpdate, 1, i); 129897 - sqlite3_step(pUpdate); 129898 - rc = sqlite3_reset(pUpdate); 129899 - } 129900 - } 129901 - p->bIgnoreSavepoint = 0; 129902 - 129903 - sqlite3_free(aIdx); 129904 - return rc; 129905 -} 129906 - 129907 -static void fts3StartNode(Blob *pNode, int iHeight, sqlite3_int64 iChild){ 129908 - pNode->a[0] = (char)iHeight; 129909 - if( iChild ){ 129910 - assert( pNode->nAlloc>=1+sqlite3Fts3VarintLen(iChild) ); 129911 - pNode->n = 1 + sqlite3Fts3PutVarint(&pNode->a[1], iChild); 129912 - }else{ 129913 - assert( pNode->nAlloc>=1 ); 129914 - pNode->n = 1; 129915 - } 129916 -} 129917 - 129918 -/* 129919 -** The first two arguments are a pointer to and the size of a segment b-tree 129920 -** node. The node may be a leaf or an internal node. 129921 -** 129922 -** This function creates a new node image in blob object *pNew by copying 129923 -** all terms that are greater than or equal to zTerm/nTerm (for leaf nodes) 129924 -** or greater than zTerm/nTerm (for internal nodes) from aNode/nNode. 129925 -*/ 129926 -static int fts3TruncateNode( 129927 - const char *aNode, /* Current node image */ 129928 - int nNode, /* Size of aNode in bytes */ 129929 - Blob *pNew, /* OUT: Write new node image here */ 129930 - const char *zTerm, /* Omit all terms smaller than this */ 129931 - int nTerm, /* Size of zTerm in bytes */ 129932 - sqlite3_int64 *piBlock /* OUT: Block number in next layer down */ 129933 -){ 129934 - NodeReader reader; /* Reader object */ 129935 - Blob prev = {0, 0, 0}; /* Previous term written to new node */ 129936 - int rc = SQLITE_OK; /* Return code */ 129937 - int bLeaf = aNode[0]=='\0'; /* True for a leaf node */ 129938 - 129939 - /* Allocate required output space */ 129940 - blobGrowBuffer(pNew, nNode, &rc); 129941 - if( rc!=SQLITE_OK ) return rc; 129942 - pNew->n = 0; 129943 - 129944 - /* Populate new node buffer */ 129945 - for(rc = nodeReaderInit(&reader, aNode, nNode); 129946 - rc==SQLITE_OK && reader.aNode; 129947 - rc = nodeReaderNext(&reader) 129948 - ){ 129949 - if( pNew->n==0 ){ 129950 - int res = fts3TermCmp(reader.term.a, reader.term.n, zTerm, nTerm); 129951 - if( res<0 || (bLeaf==0 && res==0) ) continue; 129952 - fts3StartNode(pNew, (int)aNode[0], reader.iChild); 129953 - *piBlock = reader.iChild; 129954 - } 129955 - rc = fts3AppendToNode( 129956 - pNew, &prev, reader.term.a, reader.term.n, 129957 - reader.aDoclist, reader.nDoclist 129958 - ); 129959 - if( rc!=SQLITE_OK ) break; 129960 - } 129961 - if( pNew->n==0 ){ 129962 - fts3StartNode(pNew, (int)aNode[0], reader.iChild); 129963 - *piBlock = reader.iChild; 129964 - } 129965 - assert( pNew->n<=pNew->nAlloc ); 129966 - 129967 - nodeReaderRelease(&reader); 129968 - sqlite3_free(prev.a); 129969 - return rc; 129970 -} 129971 - 129972 -/* 129973 -** Remove all terms smaller than zTerm/nTerm from segment iIdx in absolute 129974 -** level iAbsLevel. This may involve deleting entries from the %_segments 129975 -** table, and modifying existing entries in both the %_segments and %_segdir 129976 -** tables. 129977 -** 129978 -** SQLITE_OK is returned if the segment is updated successfully. Or an 129979 -** SQLite error code otherwise. 129980 -*/ 129981 -static int fts3TruncateSegment( 129982 - Fts3Table *p, /* FTS3 table handle */ 129983 - sqlite3_int64 iAbsLevel, /* Absolute level of segment to modify */ 129984 - int iIdx, /* Index within level of segment to modify */ 129985 - const char *zTerm, /* Remove terms smaller than this */ 129986 - int nTerm /* Number of bytes in buffer zTerm */ 129987 -){ 129988 - int rc = SQLITE_OK; /* Return code */ 129989 - Blob root = {0,0,0}; /* New root page image */ 129990 - Blob block = {0,0,0}; /* Buffer used for any other block */ 129991 - sqlite3_int64 iBlock = 0; /* Block id */ 129992 - sqlite3_int64 iNewStart = 0; /* New value for iStartBlock */ 129993 - sqlite3_int64 iOldStart = 0; /* Old value for iStartBlock */ 129994 - sqlite3_stmt *pFetch = 0; /* Statement used to fetch segdir */ 129995 - 129996 - rc = fts3SqlStmt(p, SQL_SELECT_SEGDIR, &pFetch, 0); 129997 - if( rc==SQLITE_OK ){ 129998 - int rc2; /* sqlite3_reset() return code */ 129999 - sqlite3_bind_int64(pFetch, 1, iAbsLevel); 130000 - sqlite3_bind_int(pFetch, 2, iIdx); 130001 - if( SQLITE_ROW==sqlite3_step(pFetch) ){ 130002 - const char *aRoot = sqlite3_column_blob(pFetch, 4); 130003 - int nRoot = sqlite3_column_bytes(pFetch, 4); 130004 - iOldStart = sqlite3_column_int64(pFetch, 1); 130005 - rc = fts3TruncateNode(aRoot, nRoot, &root, zTerm, nTerm, &iBlock); 130006 - } 130007 - rc2 = sqlite3_reset(pFetch); 130008 - if( rc==SQLITE_OK ) rc = rc2; 130009 - } 130010 - 130011 - while( rc==SQLITE_OK && iBlock ){ 130012 - char *aBlock = 0; 130013 - int nBlock = 0; 130014 - iNewStart = iBlock; 130015 - 130016 - rc = sqlite3Fts3ReadBlock(p, iBlock, &aBlock, &nBlock, 0); 130017 - if( rc==SQLITE_OK ){ 130018 - rc = fts3TruncateNode(aBlock, nBlock, &block, zTerm, nTerm, &iBlock); 130019 - } 130020 - if( rc==SQLITE_OK ){ 130021 - rc = fts3WriteSegment(p, iNewStart, block.a, block.n); 130022 - } 130023 - sqlite3_free(aBlock); 130024 - } 130025 - 130026 - /* Variable iNewStart now contains the first valid leaf node. */ 130027 - if( rc==SQLITE_OK && iNewStart ){ 130028 - sqlite3_stmt *pDel = 0; 130029 - rc = fts3SqlStmt(p, SQL_DELETE_SEGMENTS_RANGE, &pDel, 0); 130030 - if( rc==SQLITE_OK ){ 130031 - sqlite3_bind_int64(pDel, 1, iOldStart); 130032 - sqlite3_bind_int64(pDel, 2, iNewStart-1); 130033 - sqlite3_step(pDel); 130034 - rc = sqlite3_reset(pDel); 130035 - } 130036 - } 130037 - 130038 - if( rc==SQLITE_OK ){ 130039 - sqlite3_stmt *pChomp = 0; 130040 - rc = fts3SqlStmt(p, SQL_CHOMP_SEGDIR, &pChomp, 0); 130041 - if( rc==SQLITE_OK ){ 130042 - sqlite3_bind_int64(pChomp, 1, iNewStart); 130043 - sqlite3_bind_blob(pChomp, 2, root.a, root.n, SQLITE_STATIC); 130044 - sqlite3_bind_int64(pChomp, 3, iAbsLevel); 130045 - sqlite3_bind_int(pChomp, 4, iIdx); 130046 - sqlite3_step(pChomp); 130047 - rc = sqlite3_reset(pChomp); 130048 - } 130049 - } 130050 - 130051 - sqlite3_free(root.a); 130052 - sqlite3_free(block.a); 130053 - return rc; 130054 -} 130055 - 130056 -/* 130057 -** This function is called after an incrmental-merge operation has run to 130058 -** merge (or partially merge) two or more segments from absolute level 130059 -** iAbsLevel. 130060 -** 130061 -** Each input segment is either removed from the db completely (if all of 130062 -** its data was copied to the output segment by the incrmerge operation) 130063 -** or modified in place so that it no longer contains those entries that 130064 -** have been duplicated in the output segment. 130065 -*/ 130066 -static int fts3IncrmergeChomp( 130067 - Fts3Table *p, /* FTS table handle */ 130068 - sqlite3_int64 iAbsLevel, /* Absolute level containing segments */ 130069 - Fts3MultiSegReader *pCsr, /* Chomp all segments opened by this cursor */ 130070 - int *pnRem /* Number of segments not deleted */ 130071 -){ 130072 - int i; 130073 - int nRem = 0; 130074 - int rc = SQLITE_OK; 130075 - 130076 - for(i=pCsr->nSegment-1; i>=0 && rc==SQLITE_OK; i--){ 130077 - Fts3SegReader *pSeg = 0; 130078 - int j; 130079 - 130080 - /* Find the Fts3SegReader object with Fts3SegReader.iIdx==i. It is hiding 130081 - ** somewhere in the pCsr->apSegment[] array. */ 130082 - for(j=0; ALWAYS(j<pCsr->nSegment); j++){ 130083 - pSeg = pCsr->apSegment[j]; 130084 - if( pSeg->iIdx==i ) break; 130085 - } 130086 - assert( j<pCsr->nSegment && pSeg->iIdx==i ); 130087 - 130088 - if( pSeg->aNode==0 ){ 130089 - /* Seg-reader is at EOF. Remove the entire input segment. */ 130090 - rc = fts3DeleteSegment(p, pSeg); 130091 - if( rc==SQLITE_OK ){ 130092 - rc = fts3RemoveSegdirEntry(p, iAbsLevel, pSeg->iIdx); 130093 - } 130094 - *pnRem = 0; 130095 - }else{ 130096 - /* The incremental merge did not copy all the data from this 130097 - ** segment to the upper level. The segment is modified in place 130098 - ** so that it contains no keys smaller than zTerm/nTerm. */ 130099 - const char *zTerm = pSeg->zTerm; 130100 - int nTerm = pSeg->nTerm; 130101 - rc = fts3TruncateSegment(p, iAbsLevel, pSeg->iIdx, zTerm, nTerm); 130102 - nRem++; 130103 - } 130104 - } 130105 - 130106 - if( rc==SQLITE_OK && nRem!=pCsr->nSegment ){ 130107 - rc = fts3RepackSegdirLevel(p, iAbsLevel); 130108 - } 130109 - 130110 - *pnRem = nRem; 130111 - return rc; 130112 -} 130113 - 130114 -/* 130115 -** Store an incr-merge hint in the database. 130116 -*/ 130117 -static int fts3IncrmergeHintStore(Fts3Table *p, Blob *pHint){ 130118 - sqlite3_stmt *pReplace = 0; 130119 - int rc; /* Return code */ 130120 - 130121 - rc = fts3SqlStmt(p, SQL_REPLACE_STAT, &pReplace, 0); 130122 - if( rc==SQLITE_OK ){ 130123 - sqlite3_bind_int(pReplace, 1, FTS_STAT_INCRMERGEHINT); 130124 - sqlite3_bind_blob(pReplace, 2, pHint->a, pHint->n, SQLITE_STATIC); 130125 - sqlite3_step(pReplace); 130126 - rc = sqlite3_reset(pReplace); 130127 - } 130128 - 130129 - return rc; 130130 -} 130131 - 130132 -/* 130133 -** Load an incr-merge hint from the database. The incr-merge hint, if one 130134 -** exists, is stored in the rowid==1 row of the %_stat table. 130135 -** 130136 -** If successful, populate blob *pHint with the value read from the %_stat 130137 -** table and return SQLITE_OK. Otherwise, if an error occurs, return an 130138 -** SQLite error code. 130139 -*/ 130140 -static int fts3IncrmergeHintLoad(Fts3Table *p, Blob *pHint){ 130141 - sqlite3_stmt *pSelect = 0; 130142 - int rc; 130143 - 130144 - pHint->n = 0; 130145 - rc = fts3SqlStmt(p, SQL_SELECT_STAT, &pSelect, 0); 130146 - if( rc==SQLITE_OK ){ 130147 - int rc2; 130148 - sqlite3_bind_int(pSelect, 1, FTS_STAT_INCRMERGEHINT); 130149 - if( SQLITE_ROW==sqlite3_step(pSelect) ){ 130150 - const char *aHint = sqlite3_column_blob(pSelect, 0); 130151 - int nHint = sqlite3_column_bytes(pSelect, 0); 130152 - if( aHint ){ 130153 - blobGrowBuffer(pHint, nHint, &rc); 130154 - if( rc==SQLITE_OK ){ 130155 - memcpy(pHint->a, aHint, nHint); 130156 - pHint->n = nHint; 130157 - } 130158 - } 130159 - } 130160 - rc2 = sqlite3_reset(pSelect); 130161 - if( rc==SQLITE_OK ) rc = rc2; 130162 - } 130163 - 130164 - return rc; 130165 -} 130166 - 130167 -/* 130168 -** If *pRc is not SQLITE_OK when this function is called, it is a no-op. 130169 -** Otherwise, append an entry to the hint stored in blob *pHint. Each entry 130170 -** consists of two varints, the absolute level number of the input segments 130171 -** and the number of input segments. 130172 -** 130173 -** If successful, leave *pRc set to SQLITE_OK and return. If an error occurs, 130174 -** set *pRc to an SQLite error code before returning. 130175 -*/ 130176 -static void fts3IncrmergeHintPush( 130177 - Blob *pHint, /* Hint blob to append to */ 130178 - i64 iAbsLevel, /* First varint to store in hint */ 130179 - int nInput, /* Second varint to store in hint */ 130180 - int *pRc /* IN/OUT: Error code */ 130181 -){ 130182 - blobGrowBuffer(pHint, pHint->n + 2*FTS3_VARINT_MAX, pRc); 130183 - if( *pRc==SQLITE_OK ){ 130184 - pHint->n += sqlite3Fts3PutVarint(&pHint->a[pHint->n], iAbsLevel); 130185 - pHint->n += sqlite3Fts3PutVarint(&pHint->a[pHint->n], (i64)nInput); 130186 - } 130187 -} 130188 - 130189 -/* 130190 -** Read the last entry (most recently pushed) from the hint blob *pHint 130191 -** and then remove the entry. Write the two values read to *piAbsLevel and 130192 -** *pnInput before returning. 130193 -** 130194 -** If no error occurs, return SQLITE_OK. If the hint blob in *pHint does 130195 -** not contain at least two valid varints, return SQLITE_CORRUPT_VTAB. 130196 -*/ 130197 -static int fts3IncrmergeHintPop(Blob *pHint, i64 *piAbsLevel, int *pnInput){ 130198 - const int nHint = pHint->n; 130199 - int i; 130200 - 130201 - i = pHint->n-2; 130202 - while( i>0 && (pHint->a[i-1] & 0x80) ) i--; 130203 - while( i>0 && (pHint->a[i-1] & 0x80) ) i--; 130204 - 130205 - pHint->n = i; 130206 - i += sqlite3Fts3GetVarint(&pHint->a[i], piAbsLevel); 130207 - i += sqlite3Fts3GetVarint32(&pHint->a[i], pnInput); 130208 - if( i!=nHint ) return SQLITE_CORRUPT_VTAB; 130209 - 130210 - return SQLITE_OK; 130211 -} 130212 - 130213 - 130214 -/* 130215 -** Attempt an incremental merge that writes nMerge leaf blocks. 130216 -** 130217 -** Incremental merges happen nMin segments at a time. The two 130218 -** segments to be merged are the nMin oldest segments (the ones with 130219 -** the smallest indexes) in the highest level that contains at least 130220 -** nMin segments. Multiple merges might occur in an attempt to write the 130221 -** quota of nMerge leaf blocks. 130222 -*/ 130223 -SQLITE_PRIVATE int sqlite3Fts3Incrmerge(Fts3Table *p, int nMerge, int nMin){ 130224 - int rc; /* Return code */ 130225 - int nRem = nMerge; /* Number of leaf pages yet to be written */ 130226 - Fts3MultiSegReader *pCsr; /* Cursor used to read input data */ 130227 - Fts3SegFilter *pFilter; /* Filter used with cursor pCsr */ 130228 - IncrmergeWriter *pWriter; /* Writer object */ 130229 - int nSeg = 0; /* Number of input segments */ 130230 - sqlite3_int64 iAbsLevel = 0; /* Absolute level number to work on */ 130231 - Blob hint = {0, 0, 0}; /* Hint read from %_stat table */ 130232 - int bDirtyHint = 0; /* True if blob 'hint' has been modified */ 130233 - 130234 - /* Allocate space for the cursor, filter and writer objects */ 130235 - const int nAlloc = sizeof(*pCsr) + sizeof(*pFilter) + sizeof(*pWriter); 130236 - pWriter = (IncrmergeWriter *)sqlite3_malloc(nAlloc); 130237 - if( !pWriter ) return SQLITE_NOMEM; 130238 - pFilter = (Fts3SegFilter *)&pWriter[1]; 130239 - pCsr = (Fts3MultiSegReader *)&pFilter[1]; 130240 - 130241 - rc = fts3IncrmergeHintLoad(p, &hint); 130242 - while( rc==SQLITE_OK && nRem>0 ){ 130243 - const i64 nMod = FTS3_SEGDIR_MAXLEVEL * p->nIndex; 130244 - sqlite3_stmt *pFindLevel = 0; /* SQL used to determine iAbsLevel */ 130245 - int bUseHint = 0; /* True if attempting to append */ 130246 - 130247 - /* Search the %_segdir table for the absolute level with the smallest 130248 - ** relative level number that contains at least nMin segments, if any. 130249 - ** If one is found, set iAbsLevel to the absolute level number and 130250 - ** nSeg to nMin. If no level with at least nMin segments can be found, 130251 - ** set nSeg to -1. 130252 - */ 130253 - rc = fts3SqlStmt(p, SQL_FIND_MERGE_LEVEL, &pFindLevel, 0); 130254 - sqlite3_bind_int(pFindLevel, 1, nMin); 130255 - if( sqlite3_step(pFindLevel)==SQLITE_ROW ){ 130256 - iAbsLevel = sqlite3_column_int64(pFindLevel, 0); 130257 - nSeg = nMin; 130258 - }else{ 130259 - nSeg = -1; 130260 - } 130261 - rc = sqlite3_reset(pFindLevel); 130262 - 130263 - /* If the hint read from the %_stat table is not empty, check if the 130264 - ** last entry in it specifies a relative level smaller than or equal 130265 - ** to the level identified by the block above (if any). If so, this 130266 - ** iteration of the loop will work on merging at the hinted level. 130267 - */ 130268 - if( rc==SQLITE_OK && hint.n ){ 130269 - int nHint = hint.n; 130270 - sqlite3_int64 iHintAbsLevel = 0; /* Hint level */ 130271 - int nHintSeg = 0; /* Hint number of segments */ 130272 - 130273 - rc = fts3IncrmergeHintPop(&hint, &iHintAbsLevel, &nHintSeg); 130274 - if( nSeg<0 || (iAbsLevel % nMod) >= (iHintAbsLevel % nMod) ){ 130275 - iAbsLevel = iHintAbsLevel; 130276 - nSeg = nHintSeg; 130277 - bUseHint = 1; 130278 - bDirtyHint = 1; 130279 - }else{ 130280 - /* This undoes the effect of the HintPop() above - so that no entry 130281 - ** is removed from the hint blob. */ 130282 - hint.n = nHint; 130283 - } 130284 - } 130285 - 130286 - /* If nSeg is less that zero, then there is no level with at least 130287 - ** nMin segments and no hint in the %_stat table. No work to do. 130288 - ** Exit early in this case. */ 130289 - if( nSeg<0 ) break; 130290 - 130291 - /* Open a cursor to iterate through the contents of the oldest nSeg 130292 - ** indexes of absolute level iAbsLevel. If this cursor is opened using 130293 - ** the 'hint' parameters, it is possible that there are less than nSeg 130294 - ** segments available in level iAbsLevel. In this case, no work is 130295 - ** done on iAbsLevel - fall through to the next iteration of the loop 130296 - ** to start work on some other level. */ 130297 - memset(pWriter, 0, nAlloc); 130298 - pFilter->flags = FTS3_SEGMENT_REQUIRE_POS; 130299 - if( rc==SQLITE_OK ){ 130300 - rc = fts3IncrmergeCsr(p, iAbsLevel, nSeg, pCsr); 130301 - } 130302 - if( SQLITE_OK==rc && pCsr->nSegment==nSeg 130303 - && SQLITE_OK==(rc = sqlite3Fts3SegReaderStart(p, pCsr, pFilter)) 130304 - && SQLITE_ROW==(rc = sqlite3Fts3SegReaderStep(p, pCsr)) 130305 - ){ 130306 - int iIdx = 0; /* Largest idx in level (iAbsLevel+1) */ 130307 - rc = fts3IncrmergeOutputIdx(p, iAbsLevel, &iIdx); 130308 - if( rc==SQLITE_OK ){ 130309 - if( bUseHint && iIdx>0 ){ 130310 - const char *zKey = pCsr->zTerm; 130311 - int nKey = pCsr->nTerm; 130312 - rc = fts3IncrmergeLoad(p, iAbsLevel, iIdx-1, zKey, nKey, pWriter); 130313 - }else{ 130314 - rc = fts3IncrmergeWriter(p, iAbsLevel, iIdx, pCsr, pWriter); 130315 - } 130316 - } 130317 - 130318 - if( rc==SQLITE_OK && pWriter->nLeafEst ){ 130319 - fts3LogMerge(nSeg, iAbsLevel); 130320 - do { 130321 - rc = fts3IncrmergeAppend(p, pWriter, pCsr); 130322 - if( rc==SQLITE_OK ) rc = sqlite3Fts3SegReaderStep(p, pCsr); 130323 - if( pWriter->nWork>=nRem && rc==SQLITE_ROW ) rc = SQLITE_OK; 130324 - }while( rc==SQLITE_ROW ); 130325 - 130326 - /* Update or delete the input segments */ 130327 - if( rc==SQLITE_OK ){ 130328 - nRem -= (1 + pWriter->nWork); 130329 - rc = fts3IncrmergeChomp(p, iAbsLevel, pCsr, &nSeg); 130330 - if( nSeg!=0 ){ 130331 - bDirtyHint = 1; 130332 - fts3IncrmergeHintPush(&hint, iAbsLevel, nSeg, &rc); 130333 - } 130334 - } 130335 - } 130336 - 130337 - fts3IncrmergeRelease(p, pWriter, &rc); 130338 - } 130339 - 130340 - sqlite3Fts3SegReaderFinish(pCsr); 130341 - } 130342 - 130343 - /* Write the hint values into the %_stat table for the next incr-merger */ 130344 - if( bDirtyHint && rc==SQLITE_OK ){ 130345 - rc = fts3IncrmergeHintStore(p, &hint); 130346 - } 130347 - 130348 - sqlite3_free(pWriter); 130349 - sqlite3_free(hint.a); 130350 - return rc; 130351 -} 130352 - 130353 -/* 130354 -** Convert the text beginning at *pz into an integer and return 130355 -** its value. Advance *pz to point to the first character past 130356 -** the integer. 130357 -*/ 130358 -static int fts3Getint(const char **pz){ 130359 - const char *z = *pz; 130360 - int i = 0; 130361 - while( (*z)>='0' && (*z)<='9' ) i = 10*i + *(z++) - '0'; 130362 - *pz = z; 130363 - return i; 130364 -} 130365 - 130366 -/* 130367 -** Process statements of the form: 130368 -** 130369 -** INSERT INTO table(table) VALUES('merge=A,B'); 130370 -** 130371 -** A and B are integers that decode to be the number of leaf pages 130372 -** written for the merge, and the minimum number of segments on a level 130373 -** before it will be selected for a merge, respectively. 130374 -*/ 130375 -static int fts3DoIncrmerge( 130376 - Fts3Table *p, /* FTS3 table handle */ 130377 - const char *zParam /* Nul-terminated string containing "A,B" */ 130378 -){ 130379 - int rc; 130380 - int nMin = (FTS3_MERGE_COUNT / 2); 130381 - int nMerge = 0; 130382 - const char *z = zParam; 130383 - 130384 - /* Read the first integer value */ 130385 - nMerge = fts3Getint(&z); 130386 - 130387 - /* If the first integer value is followed by a ',', read the second 130388 - ** integer value. */ 130389 - if( z[0]==',' && z[1]!='\0' ){ 130390 - z++; 130391 - nMin = fts3Getint(&z); 130392 - } 130393 - 130394 - if( z[0]!='\0' || nMin<2 ){ 130395 - rc = SQLITE_ERROR; 130396 - }else{ 130397 - rc = SQLITE_OK; 130398 - if( !p->bHasStat ){ 130399 - assert( p->bFts4==0 ); 130400 - sqlite3Fts3CreateStatTable(&rc, p); 130401 - } 130402 - if( rc==SQLITE_OK ){ 130403 - rc = sqlite3Fts3Incrmerge(p, nMerge, nMin); 130404 - } 130405 - sqlite3Fts3SegmentsClose(p); 130406 - } 130407 - return rc; 130408 -} 130409 - 130410 -/* 130411 -** Process statements of the form: 130412 -** 130413 -** INSERT INTO table(table) VALUES('automerge=X'); 130414 -** 130415 -** where X is an integer. X==0 means to turn automerge off. X!=0 means 130416 -** turn it on. The setting is persistent. 130417 -*/ 130418 -static int fts3DoAutoincrmerge( 130419 - Fts3Table *p, /* FTS3 table handle */ 130420 - const char *zParam /* Nul-terminated string containing boolean */ 130421 -){ 130422 - int rc = SQLITE_OK; 130423 - sqlite3_stmt *pStmt = 0; 130424 - p->bAutoincrmerge = fts3Getint(&zParam)!=0; 130425 - if( !p->bHasStat ){ 130426 - assert( p->bFts4==0 ); 130427 - sqlite3Fts3CreateStatTable(&rc, p); 130428 - if( rc ) return rc; 130429 - } 130430 - rc = fts3SqlStmt(p, SQL_REPLACE_STAT, &pStmt, 0); 130431 - if( rc ) return rc;; 130432 - sqlite3_bind_int(pStmt, 1, FTS_STAT_AUTOINCRMERGE); 130433 - sqlite3_bind_int(pStmt, 2, p->bAutoincrmerge); 130434 - sqlite3_step(pStmt); 130435 - rc = sqlite3_reset(pStmt); 130436 - return rc; 130437 -} 130438 - 130439 -/* 130440 -** Return a 64-bit checksum for the FTS index entry specified by the 130441 -** arguments to this function. 130442 -*/ 130443 -static u64 fts3ChecksumEntry( 130444 - const char *zTerm, /* Pointer to buffer containing term */ 130445 - int nTerm, /* Size of zTerm in bytes */ 130446 - int iLangid, /* Language id for current row */ 130447 - int iIndex, /* Index (0..Fts3Table.nIndex-1) */ 130448 - i64 iDocid, /* Docid for current row. */ 130449 - int iCol, /* Column number */ 130450 - int iPos /* Position */ 130451 -){ 130452 - int i; 130453 - u64 ret = (u64)iDocid; 130454 - 130455 - ret += (ret<<3) + iLangid; 130456 - ret += (ret<<3) + iIndex; 130457 - ret += (ret<<3) + iCol; 130458 - ret += (ret<<3) + iPos; 130459 - for(i=0; i<nTerm; i++) ret += (ret<<3) + zTerm[i]; 130460 - 130461 - return ret; 130462 -} 130463 - 130464 -/* 130465 -** Return a checksum of all entries in the FTS index that correspond to 130466 -** language id iLangid. The checksum is calculated by XORing the checksums 130467 -** of each individual entry (see fts3ChecksumEntry()) together. 130468 -** 130469 -** If successful, the checksum value is returned and *pRc set to SQLITE_OK. 130470 -** Otherwise, if an error occurs, *pRc is set to an SQLite error code. The 130471 -** return value is undefined in this case. 130472 -*/ 130473 -static u64 fts3ChecksumIndex( 130474 - Fts3Table *p, /* FTS3 table handle */ 130475 - int iLangid, /* Language id to return cksum for */ 130476 - int iIndex, /* Index to cksum (0..p->nIndex-1) */ 130477 - int *pRc /* OUT: Return code */ 130478 -){ 130479 - Fts3SegFilter filter; 130480 - Fts3MultiSegReader csr; 130481 - int rc; 130482 - u64 cksum = 0; 130483 - 130484 - assert( *pRc==SQLITE_OK ); 130485 - 130486 - memset(&filter, 0, sizeof(filter)); 130487 - memset(&csr, 0, sizeof(csr)); 130488 - filter.flags = FTS3_SEGMENT_REQUIRE_POS|FTS3_SEGMENT_IGNORE_EMPTY; 130489 - filter.flags |= FTS3_SEGMENT_SCAN; 130490 - 130491 - rc = sqlite3Fts3SegReaderCursor( 130492 - p, iLangid, iIndex, FTS3_SEGCURSOR_ALL, 0, 0, 0, 1,&csr 130493 - ); 130494 - if( rc==SQLITE_OK ){ 130495 - rc = sqlite3Fts3SegReaderStart(p, &csr, &filter); 130496 - } 130497 - 130498 - if( rc==SQLITE_OK ){ 130499 - while( SQLITE_ROW==(rc = sqlite3Fts3SegReaderStep(p, &csr)) ){ 130500 - char *pCsr = csr.aDoclist; 130501 - char *pEnd = &pCsr[csr.nDoclist]; 130502 - 130503 - i64 iDocid = 0; 130504 - i64 iCol = 0; 130505 - i64 iPos = 0; 130506 - 130507 - pCsr += sqlite3Fts3GetVarint(pCsr, &iDocid); 130508 - while( pCsr<pEnd ){ 130509 - i64 iVal = 0; 130510 - pCsr += sqlite3Fts3GetVarint(pCsr, &iVal); 130511 - if( pCsr<pEnd ){ 130512 - if( iVal==0 || iVal==1 ){ 130513 - iCol = 0; 130514 - iPos = 0; 130515 - if( iVal ){ 130516 - pCsr += sqlite3Fts3GetVarint(pCsr, &iCol); 130517 - }else{ 130518 - pCsr += sqlite3Fts3GetVarint(pCsr, &iVal); 130519 - iDocid += iVal; 130520 - } 130521 - }else{ 130522 - iPos += (iVal - 2); 130523 - cksum = cksum ^ fts3ChecksumEntry( 130524 - csr.zTerm, csr.nTerm, iLangid, iIndex, iDocid, 130525 - (int)iCol, (int)iPos 130526 - ); 130527 - } 130528 - } 130529 - } 130530 - } 130531 - } 130532 - sqlite3Fts3SegReaderFinish(&csr); 130533 - 130534 - *pRc = rc; 130535 - return cksum; 130536 -} 130537 - 130538 -/* 130539 -** Check if the contents of the FTS index match the current contents of the 130540 -** content table. If no error occurs and the contents do match, set *pbOk 130541 -** to true and return SQLITE_OK. Or if the contents do not match, set *pbOk 130542 -** to false before returning. 130543 -** 130544 -** If an error occurs (e.g. an OOM or IO error), return an SQLite error 130545 -** code. The final value of *pbOk is undefined in this case. 130546 -*/ 130547 -static int fts3IntegrityCheck(Fts3Table *p, int *pbOk){ 130548 - int rc = SQLITE_OK; /* Return code */ 130549 - u64 cksum1 = 0; /* Checksum based on FTS index contents */ 130550 - u64 cksum2 = 0; /* Checksum based on %_content contents */ 130551 - sqlite3_stmt *pAllLangid = 0; /* Statement to return all language-ids */ 130552 - 130553 - /* This block calculates the checksum according to the FTS index. */ 130554 - rc = fts3SqlStmt(p, SQL_SELECT_ALL_LANGID, &pAllLangid, 0); 130555 - if( rc==SQLITE_OK ){ 130556 - int rc2; 130557 - sqlite3_bind_int(pAllLangid, 1, p->nIndex); 130558 - while( rc==SQLITE_OK && sqlite3_step(pAllLangid)==SQLITE_ROW ){ 130559 - int iLangid = sqlite3_column_int(pAllLangid, 0); 130560 - int i; 130561 - for(i=0; i<p->nIndex; i++){ 130562 - cksum1 = cksum1 ^ fts3ChecksumIndex(p, iLangid, i, &rc); 130563 - } 130564 - } 130565 - rc2 = sqlite3_reset(pAllLangid); 130566 - if( rc==SQLITE_OK ) rc = rc2; 130567 - } 130568 - 130569 - /* This block calculates the checksum according to the %_content table */ 130570 - rc = fts3SqlStmt(p, SQL_SELECT_ALL_LANGID, &pAllLangid, 0); 130571 - if( rc==SQLITE_OK ){ 130572 - sqlite3_tokenizer_module const *pModule = p->pTokenizer->pModule; 130573 - sqlite3_stmt *pStmt = 0; 130574 - char *zSql; 130575 - 130576 - zSql = sqlite3_mprintf("SELECT %s" , p->zReadExprlist); 130577 - if( !zSql ){ 130578 - rc = SQLITE_NOMEM; 130579 - }else{ 130580 - rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0); 130581 - sqlite3_free(zSql); 130582 - } 130583 - 130584 - while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){ 130585 - i64 iDocid = sqlite3_column_int64(pStmt, 0); 130586 - int iLang = langidFromSelect(p, pStmt); 130587 - int iCol; 130588 - 130589 - for(iCol=0; rc==SQLITE_OK && iCol<p->nColumn; iCol++){ 130590 - const char *zText = (const char *)sqlite3_column_text(pStmt, iCol+1); 130591 - int nText = sqlite3_column_bytes(pStmt, iCol+1); 130592 - sqlite3_tokenizer_cursor *pT = 0; 130593 - 130594 - rc = sqlite3Fts3OpenTokenizer(p->pTokenizer, iLang, zText, nText, &pT); 130595 - while( rc==SQLITE_OK ){ 130596 - char const *zToken; /* Buffer containing token */ 130597 - int nToken; /* Number of bytes in token */ 130598 - int iDum1, iDum2; /* Dummy variables */ 130599 - int iPos; /* Position of token in zText */ 130600 - 130601 - rc = pModule->xNext(pT, &zToken, &nToken, &iDum1, &iDum2, &iPos); 130602 - if( rc==SQLITE_OK ){ 130603 - int i; 130604 - cksum2 = cksum2 ^ fts3ChecksumEntry( 130605 - zToken, nToken, iLang, 0, iDocid, iCol, iPos 130606 - ); 130607 - for(i=1; i<p->nIndex; i++){ 130608 - if( p->aIndex[i].nPrefix<=nToken ){ 130609 - cksum2 = cksum2 ^ fts3ChecksumEntry( 130610 - zToken, p->aIndex[i].nPrefix, iLang, i, iDocid, iCol, iPos 130611 - ); 130612 - } 130613 - } 130614 - } 130615 - } 130616 - if( pT ) pModule->xClose(pT); 130617 - if( rc==SQLITE_DONE ) rc = SQLITE_OK; 130618 - } 130619 - } 130620 - 130621 - sqlite3_finalize(pStmt); 130622 - } 130623 - 130624 - *pbOk = (cksum1==cksum2); 130625 - return rc; 130626 -} 130627 - 130628 -/* 130629 -** Run the integrity-check. If no error occurs and the current contents of 130630 -** the FTS index are correct, return SQLITE_OK. Or, if the contents of the 130631 -** FTS index are incorrect, return SQLITE_CORRUPT_VTAB. 130632 -** 130633 -** Or, if an error (e.g. an OOM or IO error) occurs, return an SQLite 130634 -** error code. 130635 -** 130636 -** The integrity-check works as follows. For each token and indexed token 130637 -** prefix in the document set, a 64-bit checksum is calculated (by code 130638 -** in fts3ChecksumEntry()) based on the following: 130639 -** 130640 -** + The index number (0 for the main index, 1 for the first prefix 130641 -** index etc.), 130642 -** + The token (or token prefix) text itself, 130643 -** + The language-id of the row it appears in, 130644 -** + The docid of the row it appears in, 130645 -** + The column it appears in, and 130646 -** + The tokens position within that column. 130647 -** 130648 -** The checksums for all entries in the index are XORed together to create 130649 -** a single checksum for the entire index. 130650 -** 130651 -** The integrity-check code calculates the same checksum in two ways: 130652 -** 130653 -** 1. By scanning the contents of the FTS index, and 130654 -** 2. By scanning and tokenizing the content table. 130655 -** 130656 -** If the two checksums are identical, the integrity-check is deemed to have 130657 -** passed. 130658 -*/ 130659 -static int fts3DoIntegrityCheck( 130660 - Fts3Table *p /* FTS3 table handle */ 130661 -){ 130662 - int rc; 130663 - int bOk = 0; 130664 - rc = fts3IntegrityCheck(p, &bOk); 130665 - if( rc==SQLITE_OK && bOk==0 ) rc = SQLITE_CORRUPT_VTAB; 130666 - return rc; 130667 -} 130668 - 130669 128230 /* 130670 128231 ** Handle a 'special' INSERT of the form: 130671 128232 ** 130672 128233 ** "INSERT INTO tbl(tbl) VALUES(<expr>)" 130673 128234 ** 130674 128235 ** Argument pVal contains the result of <expr>. Currently the only 130675 128236 ** meaningful value to insert is the text 'optimize'. ................................................................................ 130681 128242 130682 128243 if( !zVal ){ 130683 128244 return SQLITE_NOMEM; 130684 128245 }else if( nVal==8 && 0==sqlite3_strnicmp(zVal, "optimize", 8) ){ 130685 128246 rc = fts3DoOptimize(p, 0); 130686 128247 }else if( nVal==7 && 0==sqlite3_strnicmp(zVal, "rebuild", 7) ){ 130687 128248 rc = fts3DoRebuild(p); 130688 - }else if( nVal==15 && 0==sqlite3_strnicmp(zVal, "integrity-check", 15) ){ 130689 - rc = fts3DoIntegrityCheck(p); 130690 - }else if( nVal>6 && 0==sqlite3_strnicmp(zVal, "merge=", 6) ){ 130691 - rc = fts3DoIncrmerge(p, &zVal[6]); 130692 - }else if( nVal>10 && 0==sqlite3_strnicmp(zVal, "automerge=", 10) ){ 130693 - rc = fts3DoAutoincrmerge(p, &zVal[10]); 130694 128249 #ifdef SQLITE_TEST 130695 128250 }else if( nVal>9 && 0==sqlite3_strnicmp(zVal, "nodesize=", 9) ){ 130696 128251 p->nNodeSize = atoi(&zVal[9]); 130697 128252 rc = SQLITE_OK; 130698 128253 }else if( nVal>11 && 0==sqlite3_strnicmp(zVal, "maxpending=", 9) ){ 130699 128254 p->nMaxPendingData = atoi(&zVal[11]); 130700 128255 rc = SQLITE_OK; ................................................................................ 130882 128437 } 130883 128438 130884 128439 /* 130885 128440 ** This function does the work for the xUpdate method of FTS3 virtual 130886 128441 ** tables. The schema of the virtual table being: 130887 128442 ** 130888 128443 ** CREATE TABLE <table name>( 130889 -** <user columns>, 128444 +** <user COLUMns>, 130890 128445 ** <table name> HIDDEN, 130891 128446 ** docid HIDDEN, 130892 128447 ** <langid> HIDDEN 130893 128448 ** ); 130894 128449 ** 130895 128450 ** 130896 128451 */ ................................................................................ 131014 128569 } 131015 128570 if( p->bHasDocsize ){ 131016 128571 fts3InsertDocsize(&rc, p, aSzIns); 131017 128572 } 131018 128573 nChng++; 131019 128574 } 131020 128575 131021 - if( p->bFts4 ){ 128576 + if( p->bHasStat ){ 131022 128577 fts3UpdateDocTotals(&rc, p, aSzIns, aSzDel, nChng); 131023 128578 } 131024 128579 131025 128580 update_out: 131026 128581 sqlite3_free(aSzIns); 131027 128582 sqlite3Fts3SegmentsClose(p); 131028 128583 return rc; ................................................................................ 131411 128966 ** This function is an fts3ExprIterate() callback used by fts3BestSnippet(). 131412 128967 ** Each invocation populates an element of the SnippetIter.aPhrase[] array. 131413 128968 */ 131414 128969 static int fts3SnippetFindPositions(Fts3Expr *pExpr, int iPhrase, void *ctx){ 131415 128970 SnippetIter *p = (SnippetIter *)ctx; 131416 128971 SnippetPhrase *pPhrase = &p->aPhrase[iPhrase]; 131417 128972 char *pCsr; 131418 - int rc; 131419 128973 131420 128974 pPhrase->nToken = pExpr->pPhrase->nToken; 131421 - rc = sqlite3Fts3EvalPhrasePoslist(p->pCsr, pExpr, p->iCol, &pCsr); 131422 - assert( rc==SQLITE_OK || pCsr==0 ); 128975 + 128976 + pCsr = sqlite3Fts3EvalPhrasePoslist(p->pCsr, pExpr, p->iCol); 131423 128977 if( pCsr ){ 131424 128978 int iFirst = 0; 131425 128979 pPhrase->pList = pCsr; 131426 128980 fts3GetDeltaPosition(&pCsr, &iFirst); 131427 128981 assert( iFirst>=0 ); 131428 128982 pPhrase->pHead = pCsr; 131429 128983 pPhrase->pTail = pCsr; 131430 128984 pPhrase->iHead = iFirst; 131431 128985 pPhrase->iTail = iFirst; 131432 128986 }else{ 131433 - assert( rc!=SQLITE_OK || ( 131434 - pPhrase->pList==0 && pPhrase->pHead==0 && pPhrase->pTail==0 131435 - )); 128987 + assert( pPhrase->pList==0 && pPhrase->pHead==0 && pPhrase->pTail==0 ); 131436 128988 } 131437 128989 131438 - return rc; 128990 + return SQLITE_OK; 131439 128991 } 131440 128992 131441 128993 /* 131442 128994 ** Select the fragment of text consisting of nFragment contiguous tokens 131443 128995 ** from column iCol that represent the "best" snippet. The best snippet 131444 128996 ** is the snippet with the highest score, where scores are calculated 131445 128997 ** by adding: ................................................................................ 131824 129376 ** array that are different for each row returned by the query. 131825 129377 */ 131826 129378 static int fts3ExprLocalHitsCb( 131827 129379 Fts3Expr *pExpr, /* Phrase expression node */ 131828 129380 int iPhrase, /* Phrase number */ 131829 129381 void *pCtx /* Pointer to MatchInfo structure */ 131830 129382 ){ 131831 - int rc = SQLITE_OK; 131832 129383 MatchInfo *p = (MatchInfo *)pCtx; 131833 129384 int iStart = iPhrase * p->nCol * 3; 131834 129385 int i; 131835 129386 131836 - for(i=0; i<p->nCol && rc==SQLITE_OK; i++){ 129387 + for(i=0; i<p->nCol; i++){ 131837 129388 char *pCsr; 131838 - rc = sqlite3Fts3EvalPhrasePoslist(p->pCursor, pExpr, i, &pCsr); 129389 + pCsr = sqlite3Fts3EvalPhrasePoslist(p->pCursor, pExpr, i); 131839 129390 if( pCsr ){ 131840 129391 p->aMatchinfo[iStart+i*3] = fts3ColumnlistCount(&pCsr); 131841 129392 }else{ 131842 129393 p->aMatchinfo[iStart+i*3] = 0; 131843 129394 } 131844 129395 } 131845 129396 131846 - return rc; 129397 + return SQLITE_OK; 131847 129398 } 131848 129399 131849 129400 static int fts3MatchinfoCheck( 131850 129401 Fts3Table *pTab, 131851 129402 char cArg, 131852 129403 char **pzErr 131853 129404 ){ 131854 129405 if( (cArg==FTS3_MATCHINFO_NPHRASE) 131855 129406 || (cArg==FTS3_MATCHINFO_NCOL) 131856 - || (cArg==FTS3_MATCHINFO_NDOC && pTab->bFts4) 131857 - || (cArg==FTS3_MATCHINFO_AVGLENGTH && pTab->bFts4) 129407 + || (cArg==FTS3_MATCHINFO_NDOC && pTab->bHasStat) 129408 + || (cArg==FTS3_MATCHINFO_AVGLENGTH && pTab->bHasStat) 131858 129409 || (cArg==FTS3_MATCHINFO_LENGTH && pTab->bHasDocsize) 131859 129410 || (cArg==FTS3_MATCHINFO_LCS) 131860 129411 || (cArg==FTS3_MATCHINFO_HITS) 131861 129412 ){ 131862 129413 return SQLITE_OK; 131863 129414 } 131864 129415 *pzErr = sqlite3_mprintf("unrecognized matchinfo request: %c", cArg); ................................................................................ 132000 129551 } 132001 129552 132002 129553 for(iCol=0; iCol<pInfo->nCol; iCol++){ 132003 129554 int nLcs = 0; /* LCS value for this column */ 132004 129555 int nLive = 0; /* Number of iterators in aIter not at EOF */ 132005 129556 132006 129557 for(i=0; i<pInfo->nPhrase; i++){ 132007 - int rc; 132008 129558 LcsIterator *pIt = &aIter[i]; 132009 - rc = sqlite3Fts3EvalPhrasePoslist(pCsr, pIt->pExpr, iCol, &pIt->pRead); 132010 - if( rc!=SQLITE_OK ) return rc; 129559 + pIt->pRead = sqlite3Fts3EvalPhrasePoslist(pCsr, pIt->pExpr, iCol); 132011 129560 if( pIt->pRead ){ 132012 129561 pIt->iPos = pIt->iPosOffset; 132013 129562 fts3LcsIteratorAdvance(&aIter[i]); 132014 129563 nLive++; 132015 129564 } 132016 129565 } 132017 129566 ................................................................................ 132355 129904 */ 132356 129905 static int fts3ExprTermOffsetInit(Fts3Expr *pExpr, int iPhrase, void *ctx){ 132357 129906 TermOffsetCtx *p = (TermOffsetCtx *)ctx; 132358 129907 int nTerm; /* Number of tokens in phrase */ 132359 129908 int iTerm; /* For looping through nTerm phrase terms */ 132360 129909 char *pList; /* Pointer to position list for phrase */ 132361 129910 int iPos = 0; /* First position in position-list */ 132362 - int rc; 132363 129911 132364 129912 UNUSED_PARAMETER(iPhrase); 132365 - rc = sqlite3Fts3EvalPhrasePoslist(p->pCsr, pExpr, p->iCol, &pList); 129913 + pList = sqlite3Fts3EvalPhrasePoslist(p->pCsr, pExpr, p->iCol); 132366 129914 nTerm = pExpr->pPhrase->nToken; 132367 129915 if( pList ){ 132368 129916 fts3GetDeltaPosition(&pList, &iPos); 132369 129917 assert( iPos>=0 ); 132370 129918 } 132371 129919 132372 129920 for(iTerm=0; iTerm<nTerm; iTerm++){ 132373 129921 TermOffset *pT = &p->aTerm[p->iTerm++]; 132374 129922 pT->iOff = nTerm-iTerm-1; 132375 129923 pT->pList = pList; 132376 129924 pT->iPos = iPos; 132377 129925 } 132378 129926 132379 - return rc; 129927 + return SQLITE_OK; 132380 129928 } 132381 129929 132382 129930 /* 132383 129931 ** Implementation of offsets() function. 132384 129932 */ 132385 129933 SQLITE_PRIVATE void sqlite3Fts3Offsets( 132386 129934 sqlite3_context *pCtx, /* SQLite function call context */ ................................................................................ 132743 130291 int eCoordType; 132744 130292 }; 132745 130293 132746 130294 /* Possible values for eCoordType: */ 132747 130295 #define RTREE_COORD_REAL32 0 132748 130296 #define RTREE_COORD_INT32 1 132749 130297 132750 -/* 132751 -** If SQLITE_RTREE_INT_ONLY is defined, then this virtual table will 132752 -** only deal with integer coordinates. No floating point operations 132753 -** will be done. 132754 -*/ 132755 -#ifdef SQLITE_RTREE_INT_ONLY 132756 - typedef sqlite3_int64 RtreeDValue; /* High accuracy coordinate */ 132757 - typedef int RtreeValue; /* Low accuracy coordinate */ 132758 -#else 132759 - typedef double RtreeDValue; /* High accuracy coordinate */ 132760 - typedef float RtreeValue; /* Low accuracy coordinate */ 132761 -#endif 132762 - 132763 130298 /* 132764 130299 ** The minimum number of cells allowed for a node is a third of the 132765 130300 ** maximum. In Gutman's notation: 132766 130301 ** 132767 130302 ** m = M/3 132768 130303 ** 132769 130304 ** If an R*-tree "Reinsert" operation is required, the same number of ................................................................................ 132791 130326 int iCell; /* Index of current cell in pNode */ 132792 130327 int iStrategy; /* Copy of idxNum search parameter */ 132793 130328 int nConstraint; /* Number of entries in aConstraint */ 132794 130329 RtreeConstraint *aConstraint; /* Search constraints. */ 132795 130330 }; 132796 130331 132797 130332 union RtreeCoord { 132798 - RtreeValue f; 130333 + float f; 132799 130334 int i; 132800 130335 }; 132801 130336 132802 130337 /* 132803 130338 ** The argument is an RtreeCoord. Return the value stored within the RtreeCoord 132804 -** formatted as a RtreeDValue (double or int64). This macro assumes that local 132805 -** variable pRtree points to the Rtree structure associated with the 132806 -** RtreeCoord. 130339 +** formatted as a double. This macro assumes that local variable pRtree points 130340 +** to the Rtree structure associated with the RtreeCoord. 132807 130341 */ 132808 -#ifdef SQLITE_RTREE_INT_ONLY 132809 -# define DCOORD(coord) ((RtreeDValue)coord.i) 132810 -#else 132811 -# define DCOORD(coord) ( \ 132812 - (pRtree->eCoordType==RTREE_COORD_REAL32) ? \ 132813 - ((double)coord.f) : \ 132814 - ((double)coord.i) \ 132815 - ) 132816 -#endif 130342 +#define DCOORD(coord) ( \ 130343 + (pRtree->eCoordType==RTREE_COORD_REAL32) ? \ 130344 + ((double)coord.f) : \ 130345 + ((double)coord.i) \ 130346 +) 132817 130347 132818 130348 /* 132819 130349 ** A search constraint. 132820 130350 */ 132821 130351 struct RtreeConstraint { 132822 130352 int iCoord; /* Index of constrained coordinate */ 132823 130353 int op; /* Constraining operation */ 132824 - RtreeDValue rValue; /* Constraint value. */ 132825 - int (*xGeom)(sqlite3_rtree_geometry*, int, RtreeDValue*, int*); 130354 + double rValue; /* Constraint value. */ 130355 + int (*xGeom)(sqlite3_rtree_geometry *, int, double *, int *); 132826 130356 sqlite3_rtree_geometry *pGeom; /* Constraint callback argument for a MATCH */ 132827 130357 }; 132828 130358 132829 130359 /* Possible values for RtreeConstraint.op */ 132830 130360 #define RTREE_EQ 0x41 132831 130361 #define RTREE_LE 0x42 132832 130362 #define RTREE_LT 0x43 ................................................................................ 132866 130396 /* 132867 130397 ** An instance of this structure must be supplied as a blob argument to 132868 130398 ** the right-hand-side of an SQL MATCH operator used to constrain an 132869 130399 ** r-tree query. 132870 130400 */ 132871 130401 struct RtreeMatchArg { 132872 130402 u32 magic; /* Always RTREE_GEOMETRY_MAGIC */ 132873 - int (*xGeom)(sqlite3_rtree_geometry *, int, RtreeDValue*, int *); 130403 + int (*xGeom)(sqlite3_rtree_geometry *, int, double *, int *); 132874 130404 void *pContext; 132875 130405 int nParam; 132876 - RtreeDValue aParam[1]; 130406 + double aParam[1]; 132877 130407 }; 132878 130408 132879 130409 /* 132880 130410 ** When a geometry callback is created (see sqlite3_rtree_geometry_callback), 132881 130411 ** a single instance of the following structure is allocated. It is used 132882 130412 ** as the context for the user-function created by by s_r_g_c(). The object 132883 130413 ** is eventually deleted by the destructor mechanism provided by 132884 130414 ** sqlite3_create_function_v2() (which is called by s_r_g_c() to create 132885 130415 ** the geometry callback function). 132886 130416 */ 132887 130417 struct RtreeGeomCallback { 132888 - int (*xGeom)(sqlite3_rtree_geometry*, int, RtreeDValue*, int*); 130418 + int (*xGeom)(sqlite3_rtree_geometry *, int, double *, int *); 132889 130419 void *pContext; 132890 130420 }; 132891 130421 132892 130422 #ifndef MAX 132893 130423 # define MAX(x,y) ((x) < (y) ? (y) : (x)) 132894 130424 #endif 132895 130425 #ifndef MIN ................................................................................ 133447 130977 static int testRtreeGeom( 133448 130978 Rtree *pRtree, /* R-Tree object */ 133449 130979 RtreeConstraint *pConstraint, /* MATCH constraint to test */ 133450 130980 RtreeCell *pCell, /* Cell to test */ 133451 130981 int *pbRes /* OUT: Test result */ 133452 130982 ){ 133453 130983 int i; 133454 - RtreeDValue aCoord[RTREE_MAX_DIMENSIONS*2]; 130984 + double aCoord[RTREE_MAX_DIMENSIONS*2]; 133455 130985 int nCoord = pRtree->nDim*2; 133456 130986 133457 130987 assert( pConstraint->op==RTREE_MATCH ); 133458 130988 assert( pConstraint->pGeom ); 133459 130989 133460 130990 for(i=0; i<nCoord; i++){ 133461 130991 aCoord[i] = DCOORD(pCell->aCoord[i]); ................................................................................ 133477 131007 int ii; 133478 131008 int bRes = 0; 133479 131009 int rc = SQLITE_OK; 133480 131010 133481 131011 nodeGetCell(pRtree, pCursor->pNode, pCursor->iCell, &cell); 133482 131012 for(ii=0; bRes==0 && ii<pCursor->nConstraint; ii++){ 133483 131013 RtreeConstraint *p = &pCursor->aConstraint[ii]; 133484 - RtreeDValue cell_min = DCOORD(cell.aCoord[(p->iCoord>>1)*2]); 133485 - RtreeDValue cell_max = DCOORD(cell.aCoord[(p->iCoord>>1)*2+1]); 131014 + double cell_min = DCOORD(cell.aCoord[(p->iCoord>>1)*2]); 131015 + double cell_max = DCOORD(cell.aCoord[(p->iCoord>>1)*2+1]); 133486 131016 133487 131017 assert(p->op==RTREE_LE || p->op==RTREE_LT || p->op==RTREE_GE 133488 131018 || p->op==RTREE_GT || p->op==RTREE_EQ || p->op==RTREE_MATCH 133489 131019 ); 133490 131020 133491 131021 switch( p->op ){ 133492 131022 case RTREE_LE: case RTREE_LT: ................................................................................ 133530 131060 RtreeCell cell; 133531 131061 int ii; 133532 131062 *pbEof = 0; 133533 131063 133534 131064 nodeGetCell(pRtree, pCursor->pNode, pCursor->iCell, &cell); 133535 131065 for(ii=0; ii<pCursor->nConstraint; ii++){ 133536 131066 RtreeConstraint *p = &pCursor->aConstraint[ii]; 133537 - RtreeDValue coord = DCOORD(cell.aCoord[p->iCoord]); 131067 + double coord = DCOORD(cell.aCoord[p->iCoord]); 133538 131068 int res; 133539 131069 assert(p->op==RTREE_LE || p->op==RTREE_LT || p->op==RTREE_GE 133540 131070 || p->op==RTREE_GT || p->op==RTREE_EQ || p->op==RTREE_MATCH 133541 131071 ); 133542 131072 switch( p->op ){ 133543 131073 case RTREE_LE: res = (coord<=p->rValue); break; 133544 131074 case RTREE_LT: res = (coord<p->rValue); break; ................................................................................ 133728 131258 133729 131259 if( i==0 ){ 133730 131260 i64 iRowid = nodeGetRowid(pRtree, pCsr->pNode, pCsr->iCell); 133731 131261 sqlite3_result_int64(ctx, iRowid); 133732 131262 }else{ 133733 131263 RtreeCoord c; 133734 131264 nodeGetCoord(pRtree, pCsr->pNode, pCsr->iCell, i-1, &c); 133735 -#ifndef SQLITE_RTREE_INT_ONLY 133736 131265 if( pRtree->eCoordType==RTREE_COORD_REAL32 ){ 133737 131266 sqlite3_result_double(ctx, c.f); 133738 - }else 133739 -#endif 133740 - { 131267 + }else{ 133741 131268 assert( pRtree->eCoordType==RTREE_COORD_INT32 ); 133742 131269 sqlite3_result_int(ctx, c.i); 133743 131270 } 133744 131271 } 133745 131272 133746 131273 return SQLITE_OK; 133747 131274 } ................................................................................ 133780 131307 133781 131308 /* Check that value is actually a blob. */ 133782 131309 if( sqlite3_value_type(pValue)!=SQLITE_BLOB ) return SQLITE_ERROR; 133783 131310 133784 131311 /* Check that the blob is roughly the right size. */ 133785 131312 nBlob = sqlite3_value_bytes(pValue); 133786 131313 if( nBlob<(int)sizeof(RtreeMatchArg) 133787 - || ((nBlob-sizeof(RtreeMatchArg))%sizeof(RtreeDValue))!=0 131314 + || ((nBlob-sizeof(RtreeMatchArg))%sizeof(double))!=0 133788 131315 ){ 133789 131316 return SQLITE_ERROR; 133790 131317 } 133791 131318 133792 131319 pGeom = (sqlite3_rtree_geometry *)sqlite3_malloc( 133793 131320 sizeof(sqlite3_rtree_geometry) + nBlob 133794 131321 ); 133795 131322 if( !pGeom ) return SQLITE_NOMEM; 133796 131323 memset(pGeom, 0, sizeof(sqlite3_rtree_geometry)); 133797 131324 p = (RtreeMatchArg *)&pGeom[1]; 133798 131325 133799 131326 memcpy(p, sqlite3_value_blob(pValue), nBlob); 133800 131327 if( p->magic!=RTREE_GEOMETRY_MAGIC 133801 - || nBlob!=(int)(sizeof(RtreeMatchArg) + (p->nParam-1)*sizeof(RtreeDValue)) 131328 + || nBlob!=(int)(sizeof(RtreeMatchArg) + (p->nParam-1)*sizeof(double)) 133802 131329 ){ 133803 131330 sqlite3_free(pGeom); 133804 131331 return SQLITE_ERROR; 133805 131332 } 133806 131333 133807 131334 pGeom->pContext = p->pContext; 133808 131335 pGeom->nParam = p->nParam; ................................................................................ 133866 131393 ** an sqlite3_rtree_geometry_callback() SQL user function. 133867 131394 */ 133868 131395 rc = deserializeGeometry(argv[ii], p); 133869 131396 if( rc!=SQLITE_OK ){ 133870 131397 break; 133871 131398 } 133872 131399 }else{ 133873 -#ifdef SQLITE_RTREE_INT_ONLY 133874 - p->rValue = sqlite3_value_int64(argv[ii]); 133875 -#else 133876 131400 p->rValue = sqlite3_value_double(argv[ii]); 133877 -#endif 133878 131401 } 133879 131402 } 133880 131403 } 133881 131404 } 133882 131405 133883 131406 if( rc==SQLITE_OK ){ 133884 131407 pCsr->pNode = 0; ................................................................................ 134004 131527 pIdxInfo->estimatedCost = (2000000.0 / (double)(iIdx + 1)); 134005 131528 return rc; 134006 131529 } 134007 131530 134008 131531 /* 134009 131532 ** Return the N-dimensional volumn of the cell stored in *p. 134010 131533 */ 134011 -static RtreeDValue cellArea(Rtree *pRtree, RtreeCell *p){ 134012 - RtreeDValue area = (RtreeDValue)1; 131534 +static float cellArea(Rtree *pRtree, RtreeCell *p){ 131535 + float area = 1.0; 134013 131536 int ii; 134014 131537 for(ii=0; ii<(pRtree->nDim*2); ii+=2){ 134015 - area = (area * (DCOORD(p->aCoord[ii+1]) - DCOORD(p->aCoord[ii]))); 131538 + area = (float)(area * (DCOORD(p->aCoord[ii+1]) - DCOORD(p->aCoord[ii]))); 134016 131539 } 134017 131540 return area; 134018 131541 } 134019 131542 134020 131543 /* 134021 131544 ** Return the margin length of cell p. The margin length is the sum 134022 131545 ** of the objects size in each dimension. 134023 131546 */ 134024 -static RtreeDValue cellMargin(Rtree *pRtree, RtreeCell *p){ 134025 - RtreeDValue margin = (RtreeDValue)0; 131547 +static float cellMargin(Rtree *pRtree, RtreeCell *p){ 131548 + float margin = 0.0; 134026 131549 int ii; 134027 131550 for(ii=0; ii<(pRtree->nDim*2); ii+=2){ 134028 - margin += (DCOORD(p->aCoord[ii+1]) - DCOORD(p->aCoord[ii])); 131551 + margin += (float)(DCOORD(p->aCoord[ii+1]) - DCOORD(p->aCoord[ii])); 134029 131552 } 134030 131553 return margin; 134031 131554 } 134032 131555 134033 131556 /* 134034 131557 ** Store the union of cells p1 and p2 in p1. 134035 131558 */ ................................................................................ 134066 131589 } 134067 131590 return 1; 134068 131591 } 134069 131592 134070 131593 /* 134071 131594 ** Return the amount cell p would grow by if it were unioned with pCell. 134072 131595 */ 134073 -static RtreeDValue cellGrowth(Rtree *pRtree, RtreeCell *p, RtreeCell *pCell){ 134074 - RtreeDValue area; 131596 +static float cellGrowth(Rtree *pRtree, RtreeCell *p, RtreeCell *pCell){ 131597 + float area; 134075 131598 RtreeCell cell; 134076 131599 memcpy(&cell, p, sizeof(RtreeCell)); 134077 131600 area = cellArea(pRtree, &cell); 134078 131601 cellUnion(pRtree, &cell, pCell); 134079 131602 return (cellArea(pRtree, &cell)-area); 134080 131603 } 134081 131604 134082 131605 #if VARIANT_RSTARTREE_CHOOSESUBTREE || VARIANT_RSTARTREE_SPLIT 134083 -static RtreeDValue cellOverlap( 131606 +static float cellOverlap( 134084 131607 Rtree *pRtree, 134085 131608 RtreeCell *p, 134086 131609 RtreeCell *aCell, 134087 131610 int nCell, 134088 131611 int iExclude 134089 131612 ){ 134090 131613 int ii; 134091 - RtreeDValue overlap = 0.0; 131614 + float overlap = 0.0; 134092 131615 for(ii=0; ii<nCell; ii++){ 134093 131616 #if VARIANT_RSTARTREE_CHOOSESUBTREE 134094 131617 if( ii!=iExclude ) 134095 131618 #else 134096 131619 assert( iExclude==-1 ); 134097 131620 UNUSED_PARAMETER(iExclude); 134098 131621 #endif 134099 131622 { 134100 131623 int jj; 134101 - RtreeDValue o = (RtreeDValue)1; 131624 + float o = 1.0; 134102 131625 for(jj=0; jj<(pRtree->nDim*2); jj+=2){ 134103 - RtreeDValue x1, x2; 131626 + double x1; 131627 + double x2; 134104 131628 134105 131629 x1 = MAX(DCOORD(p->aCoord[jj]), DCOORD(aCell[ii].aCoord[jj])); 134106 131630 x2 = MIN(DCOORD(p->aCoord[jj+1]), DCOORD(aCell[ii].aCoord[jj+1])); 134107 131631 134108 131632 if( x2<x1 ){ 134109 131633 o = 0.0; 134110 131634 break; 134111 131635 }else{ 134112 - o = o * (x2-x1); 131636 + o = o * (float)(x2-x1); 134113 131637 } 134114 131638 } 134115 131639 overlap += o; 134116 131640 } 134117 131641 } 134118 131642 return overlap; 134119 131643 } 134120 131644 #endif 134121 131645 134122 131646 #if VARIANT_RSTARTREE_CHOOSESUBTREE 134123 -static RtreeDValue cellOverlapEnlargement( 131647 +static float cellOverlapEnlargement( 134124 131648 Rtree *pRtree, 134125 131649 RtreeCell *p, 134126 131650 RtreeCell *pInsert, 134127 131651 RtreeCell *aCell, 134128 131652 int nCell, 134129 131653 int iExclude 134130 131654 ){ 134131 - RtreeDValue before, after; 131655 + double before; 131656 + double after; 134132 131657 before = cellOverlap(pRtree, p, aCell, nCell, iExclude); 134133 131658 cellUnion(pRtree, p, pInsert); 134134 131659 after = cellOverlap(pRtree, p, aCell, nCell, iExclude); 134135 - return (after-before); 131660 + return (float)(after-before); 134136 131661 } 134137 131662 #endif 134138 131663 134139 131664 134140 131665 /* 134141 131666 ** This function implements the ChooseLeaf algorithm from Gutman[84]. 134142 131667 ** ChooseSubTree in r*tree terminology. ................................................................................ 134152 131677 RtreeNode *pNode; 134153 131678 rc = nodeAcquire(pRtree, 1, 0, &pNode); 134154 131679 134155 131680 for(ii=0; rc==SQLITE_OK && ii<(pRtree->iDepth-iHeight); ii++){ 134156 131681 int iCell; 134157 131682 sqlite3_int64 iBest = 0; 134158 131683 134159 - RtreeDValue fMinGrowth = 0.0; 134160 - RtreeDValue fMinArea = 0.0; 131684 + float fMinGrowth = 0.0; 131685 + float fMinArea = 0.0; 134161 131686 #if VARIANT_RSTARTREE_CHOOSESUBTREE 134162 - RtreeDValue fMinOverlap = 0.0; 134163 - RtreeDValue overlap; 131687 + float fMinOverlap = 0.0; 131688 + float overlap; 134164 131689 #endif 134165 131690 134166 131691 int nCell = NCELL(pNode); 134167 131692 RtreeCell cell; 134168 131693 RtreeNode *pChild; 134169 131694 134170 131695 RtreeCell *aCell = 0; ................................................................................ 134187 131712 134188 131713 /* Select the child node which will be enlarged the least if pCell 134189 131714 ** is inserted into it. Resolve ties by choosing the entry with 134190 131715 ** the smallest area. 134191 131716 */ 134192 131717 for(iCell=0; iCell<nCell; iCell++){ 134193 131718 int bBest = 0; 134194 - RtreeDValue growth; 134195 - RtreeDValue area; 131719 + float growth; 131720 + float area; 134196 131721 nodeGetCell(pRtree, pNode, iCell, &cell); 134197 131722 growth = cellGrowth(pRtree, &cell, pCell); 134198 131723 area = cellArea(pRtree, &cell); 134199 131724 134200 131725 #if VARIANT_RSTARTREE_CHOOSESUBTREE 134201 131726 if( ii==(pRtree->iDepth-1) ){ 134202 131727 overlap = cellOverlapEnlargement(pRtree,&cell,pCell,aCell,nCell,iCell); ................................................................................ 134315 131840 int nCell, 134316 131841 int *piLeftSeed, 134317 131842 int *piRightSeed 134318 131843 ){ 134319 131844 int i; 134320 131845 int iLeftSeed = 0; 134321 131846 int iRightSeed = 1; 134322 - RtreeDValue maxNormalInnerWidth = (RtreeDValue)0; 131847 + float maxNormalInnerWidth = 0.0; 134323 131848 134324 131849 /* Pick two "seed" cells from the array of cells. The algorithm used 134325 131850 ** here is the LinearPickSeeds algorithm from Gutman[1984]. The 134326 131851 ** indices of the two seed cells in the array are stored in local 134327 131852 ** variables iLeftSeek and iRightSeed. 134328 131853 */ 134329 131854 for(i=0; i<pRtree->nDim; i++){ 134330 - RtreeDValue x1 = DCOORD(aCell[0].aCoord[i*2]); 134331 - RtreeDValue x2 = DCOORD(aCell[0].aCoord[i*2+1]); 134332 - RtreeDValue x3 = x1; 134333 - RtreeDValue x4 = x2; 131855 + float x1 = DCOORD(aCell[0].aCoord[i*2]); 131856 + float x2 = DCOORD(aCell[0].aCoord[i*2+1]); 131857 + float x3 = x1; 131858 + float x4 = x2; 134334 131859 int jj; 134335 131860 134336 131861 int iCellLeft = 0; 134337 131862 int iCellRight = 0; 134338 131863 134339 131864 for(jj=1; jj<nCell; jj++){ 134340 - RtreeDValue left = DCOORD(aCell[jj].aCoord[i*2]); 134341 - RtreeDValue right = DCOORD(aCell[jj].aCoord[i*2+1]); 131865 + float left = DCOORD(aCell[jj].aCoord[i*2]); 131866 + float right = DCOORD(aCell[jj].aCoord[i*2+1]); 134342 131867 134343 131868 if( left<x1 ) x1 = left; 134344 131869 if( right>x4 ) x4 = right; 134345 131870 if( left>x3 ){ 134346 131871 x3 = left; 134347 131872 iCellRight = jj; 134348 131873 } ................................................................................ 134349 131874 if( right<x2 ){ 134350 131875 x2 = right; 134351 131876 iCellLeft = jj; 134352 131877 } 134353 131878 } 134354 131879 134355 131880 if( x4!=x1 ){ 134356 - RtreeDValue normalwidth = (x3 - x2) / (x4 - x1); 131881 + float normalwidth = (x3 - x2) / (x4 - x1); 134357 131882 if( normalwidth>maxNormalInnerWidth ){ 134358 131883 iLeftSeed = iCellLeft; 134359 131884 iRightSeed = iCellRight; 134360 131885 } 134361 131886 } 134362 131887 } 134363 131888 ................................................................................ 134378 131903 RtreeCell *pLeftBox, 134379 131904 RtreeCell *pRightBox, 134380 131905 int *aiUsed 134381 131906 ){ 134382 131907 #define FABS(a) ((a)<0.0?-1.0*(a):(a)) 134383 131908 134384 131909 int iSelect = -1; 134385 - RtreeDValue fDiff; 131910 + float fDiff; 134386 131911 int ii; 134387 131912 for(ii=0; ii<nCell; ii++){ 134388 131913 if( aiUsed[ii]==0 ){ 134389 - RtreeDValue left = cellGrowth(pRtree, pLeftBox, &aCell[ii]); 134390 - RtreeDValue right = cellGrowth(pRtree, pLeftBox, &aCell[ii]); 134391 - RtreeDValue diff = FABS(right-left); 131914 + float left = cellGrowth(pRtree, pLeftBox, &aCell[ii]); 131915 + float right = cellGrowth(pRtree, pLeftBox, &aCell[ii]); 131916 + float diff = FABS(right-left); 134392 131917 if( iSelect<0 || diff>fDiff ){ 134393 131918 fDiff = diff; 134394 131919 iSelect = ii; 134395 131920 } 134396 131921 } 134397 131922 } 134398 131923 aiUsed[iSelect] = 1; ................................................................................ 134411 131936 int *piRightSeed 134412 131937 ){ 134413 131938 int ii; 134414 131939 int jj; 134415 131940 134416 131941 int iLeftSeed = 0; 134417 131942 int iRightSeed = 1; 134418 - RtreeDValue fWaste = 0.0; 131943 + float fWaste = 0.0; 134419 131944 134420 131945 for(ii=0; ii<nCell; ii++){ 134421 131946 for(jj=ii+1; jj<nCell; jj++){ 134422 - RtreeDValue right = cellArea(pRtree, &aCell[jj]); 134423 - RtreeDValue growth = cellGrowth(pRtree, &aCell[ii], &aCell[jj]); 134424 - RtreeDValue waste = growth - right; 131947 + float right = cellArea(pRtree, &aCell[jj]); 131948 + float growth = cellGrowth(pRtree, &aCell[ii], &aCell[jj]); 131949 + float waste = growth - right; 134425 131950 134426 131951 if( waste>fWaste ){ 134427 131952 iLeftSeed = ii; 134428 131953 iRightSeed = jj; 134429 131954 fWaste = waste; 134430 131955 } 134431 131956 } ................................................................................ 134452 131977 ** 134453 131978 ** The aSpare array is used as temporary working space by the 134454 131979 ** sorting algorithm. 134455 131980 */ 134456 131981 static void SortByDistance( 134457 131982 int *aIdx, 134458 131983 int nIdx, 134459 - RtreeDValue *aDistance, 131984 + float *aDistance, 134460 131985 int *aSpare 134461 131986 ){ 134462 131987 if( nIdx>1 ){ 134463 131988 int iLeft = 0; 134464 131989 int iRight = 0; 134465 131990 134466 131991 int nLeft = nIdx/2; ................................................................................ 134478 132003 if( iLeft==nLeft ){ 134479 132004 aIdx[iLeft+iRight] = aRight[iRight]; 134480 132005 iRight++; 134481 132006 }else if( iRight==nRight ){ 134482 132007 aIdx[iLeft+iRight] = aLeft[iLeft]; 134483 132008 iLeft++; 134484 132009 }else{ 134485 - RtreeDValue fLeft = aDistance[aLeft[iLeft]]; 134486 - RtreeDValue fRight = aDistance[aRight[iRight]]; 132010 + float fLeft = aDistance[aLeft[iLeft]]; 132011 + float fRight = aDistance[aRight[iRight]]; 134487 132012 if( fLeft<fRight ){ 134488 132013 aIdx[iLeft+iRight] = aLeft[iLeft]; 134489 132014 iLeft++; 134490 132015 }else{ 134491 132016 aIdx[iLeft+iRight] = aRight[iRight]; 134492 132017 iRight++; 134493 132018 } ................................................................................ 134495 132020 } 134496 132021 134497 132022 #if 0 134498 132023 /* Check that the sort worked */ 134499 132024 { 134500 132025 int jj; 134501 132026 for(jj=1; jj<nIdx; jj++){ 134502 - RtreeDValue left = aDistance[aIdx[jj-1]]; 134503 - RtreeDValue right = aDistance[aIdx[jj]]; 132027 + float left = aDistance[aIdx[jj-1]]; 132028 + float right = aDistance[aIdx[jj]]; 134504 132029 assert( left<=right ); 134505 132030 } 134506 132031 } 134507 132032 #endif 134508 132033 } 134509 132034 } 134510 132035 ................................................................................ 134539 132064 134540 132065 SortByDimension(pRtree, aLeft, nLeft, iDim, aCell, aSpare); 134541 132066 SortByDimension(pRtree, aRight, nRight, iDim, aCell, aSpare); 134542 132067 134543 132068 memcpy(aSpare, aLeft, sizeof(int)*nLeft); 134544 132069 aLeft = aSpare; 134545 132070 while( iLeft<nLeft || iRight<nRight ){ 134546 - RtreeDValue xleft1 = DCOORD(aCell[aLeft[iLeft]].aCoord[iDim*2]); 134547 - RtreeDValue xleft2 = DCOORD(aCell[aLeft[iLeft]].aCoord[iDim*2+1]); 134548 - RtreeDValue xright1 = DCOORD(aCell[aRight[iRight]].aCoord[iDim*2]); 134549 - RtreeDValue xright2 = DCOORD(aCell[aRight[iRight]].aCoord[iDim*2+1]); 132071 + double xleft1 = DCOORD(aCell[aLeft[iLeft]].aCoord[iDim*2]); 132072 + double xleft2 = DCOORD(aCell[aLeft[iLeft]].aCoord[iDim*2+1]); 132073 + double xright1 = DCOORD(aCell[aRight[iRight]].aCoord[iDim*2]); 132074 + double xright2 = DCOORD(aCell[aRight[iRight]].aCoord[iDim*2+1]); 134550 132075 if( (iLeft!=nLeft) && ((iRight==nRight) 134551 132076 || (xleft1<xright1) 134552 132077 || (xleft1==xright1 && xleft2<xright2) 134553 132078 )){ 134554 132079 aIdx[iLeft+iRight] = aLeft[iLeft]; 134555 132080 iLeft++; 134556 132081 }else{ ................................................................................ 134560 132085 } 134561 132086 134562 132087 #if 0 134563 132088 /* Check that the sort worked */ 134564 132089 { 134565 132090 int jj; 134566 132091 for(jj=1; jj<nIdx; jj++){ 134567 - RtreeDValue xleft1 = aCell[aIdx[jj-1]].aCoord[iDim*2]; 134568 - RtreeDValue xleft2 = aCell[aIdx[jj-1]].aCoord[iDim*2+1]; 134569 - RtreeDValue xright1 = aCell[aIdx[jj]].aCoord[iDim*2]; 134570 - RtreeDValue xright2 = aCell[aIdx[jj]].aCoord[iDim*2+1]; 132092 + float xleft1 = aCell[aIdx[jj-1]].aCoord[iDim*2]; 132093 + float xleft2 = aCell[aIdx[jj-1]].aCoord[iDim*2+1]; 132094 + float xright1 = aCell[aIdx[jj]].aCoord[iDim*2]; 132095 + float xright2 = aCell[aIdx[jj]].aCoord[iDim*2+1]; 134571 132096 assert( xleft1<=xright1 && (xleft1<xright1 || xleft2<=xright2) ); 134572 132097 } 134573 132098 } 134574 132099 #endif 134575 132100 } 134576 132101 } 134577 132102 ................................................................................ 134590 132115 ){ 134591 132116 int **aaSorted; 134592 132117 int *aSpare; 134593 132118 int ii; 134594 132119 134595 132120 int iBestDim = 0; 134596 132121 int iBestSplit = 0; 134597 - RtreeDValue fBestMargin = 0.0; 132122 + float fBestMargin = 0.0; 134598 132123 134599 132124 int nByte = (pRtree->nDim+1)*(sizeof(int*)+nCell*sizeof(int)); 134600 132125 134601 132126 aaSorted = (int **)sqlite3_malloc(nByte); 134602 132127 if( !aaSorted ){ 134603 132128 return SQLITE_NOMEM; 134604 132129 } ................................................................................ 134611 132136 for(jj=0; jj<nCell; jj++){ 134612 132137 aaSorted[ii][jj] = jj; 134613 132138 } 134614 132139 SortByDimension(pRtree, aaSorted[ii], nCell, ii, aCell, aSpare); 134615 132140 } 134616 132141 134617 132142 for(ii=0; ii<pRtree->nDim; ii++){ 134618 - RtreeDValue margin = 0.0; 134619 - RtreeDValue fBestOverlap = 0.0; 134620 - RtreeDValue fBestArea = 0.0; 132143 + float margin = 0.0; 132144 + float fBestOverlap = 0.0; 132145 + float fBestArea = 0.0; 134621 132146 int iBestLeft = 0; 134622 132147 int nLeft; 134623 132148 134624 132149 for( 134625 132150 nLeft=RTREE_MINCELLS(pRtree); 134626 132151 nLeft<=(nCell-RTREE_MINCELLS(pRtree)); 134627 132152 nLeft++ 134628 132153 ){ 134629 132154 RtreeCell left; 134630 132155 RtreeCell right; 134631 132156 int kk; 134632 - RtreeDValue overlap; 134633 - RtreeDValue area; 132157 + float overlap; 132158 + float area; 134634 132159 134635 132160 memcpy(&left, &aCell[aaSorted[ii][0]], sizeof(RtreeCell)); 134636 132161 memcpy(&right, &aCell[aaSorted[ii][nCell-1]], sizeof(RtreeCell)); 134637 132162 for(kk=1; kk<(nCell-1); kk++){ 134638 132163 if( kk<nLeft ){ 134639 132164 cellUnion(pRtree, &left, &aCell[aaSorted[ii][kk]]); 134640 132165 }else{ ................................................................................ 134709 132234 nodeInsertCell(pRtree, pRight, &aCell[iRightSeed]); 134710 132235 aiUsed[iLeftSeed] = 1; 134711 132236 aiUsed[iRightSeed] = 1; 134712 132237 134713 132238 for(i=nCell-2; i>0; i--){ 134714 132239 RtreeCell *pNext; 134715 132240 pNext = PickNext(pRtree, aCell, nCell, pBboxLeft, pBboxRight, aiUsed); 134716 - RtreeDValue diff = 132241 + float diff = 134717 132242 cellGrowth(pRtree, pBboxLeft, pNext) - 134718 132243 cellGrowth(pRtree, pBboxRight, pNext) 134719 132244 ; 134720 132245 if( (RTREE_MINCELLS(pRtree)-NCELL(pRight)==i) 134721 132246 || (diff>0.0 && (RTREE_MINCELLS(pRtree)-NCELL(pLeft)!=i)) 134722 132247 ){ 134723 132248 nodeInsertCell(pRtree, pRight, pNext); ................................................................................ 135042 132567 RtreeNode *pNode, 135043 132568 RtreeCell *pCell, 135044 132569 int iHeight 135045 132570 ){ 135046 132571 int *aOrder; 135047 132572 int *aSpare; 135048 132573 RtreeCell *aCell; 135049 - RtreeDValue *aDistance; 132574 + float *aDistance; 135050 132575 int nCell; 135051 - RtreeDValue aCenterCoord[RTREE_MAX_DIMENSIONS]; 132576 + float aCenterCoord[RTREE_MAX_DIMENSIONS]; 135052 132577 int iDim; 135053 132578 int ii; 135054 132579 int rc = SQLITE_OK; 135055 - int n; 135056 132580 135057 - memset(aCenterCoord, 0, sizeof(RtreeDValue)*RTREE_MAX_DIMENSIONS); 132581 + memset(aCenterCoord, 0, sizeof(float)*RTREE_MAX_DIMENSIONS); 135058 132582 135059 132583 nCell = NCELL(pNode)+1; 135060 - n = (nCell+1)&(~1); 135061 132584 135062 132585 /* Allocate the buffers used by this operation. The allocation is 135063 132586 ** relinquished before this function returns. 135064 132587 */ 135065 - aCell = (RtreeCell *)sqlite3_malloc(n * ( 135066 - sizeof(RtreeCell) + /* aCell array */ 135067 - sizeof(int) + /* aOrder array */ 135068 - sizeof(int) + /* aSpare array */ 135069 - sizeof(RtreeDValue) /* aDistance array */ 132588 + aCell = (RtreeCell *)sqlite3_malloc(nCell * ( 132589 + sizeof(RtreeCell) + /* aCell array */ 132590 + sizeof(int) + /* aOrder array */ 132591 + sizeof(int) + /* aSpare array */ 132592 + sizeof(float) /* aDistance array */ 135070 132593 )); 135071 132594 if( !aCell ){ 135072 132595 return SQLITE_NOMEM; 135073 132596 } 135074 - aOrder = (int *)&aCell[n]; 135075 - aSpare = (int *)&aOrder[n]; 135076 - aDistance = (RtreeDValue *)&aSpare[n]; 132597 + aOrder = (int *)&aCell[nCell]; 132598 + aSpare = (int *)&aOrder[nCell]; 132599 + aDistance = (float *)&aSpare[nCell]; 135077 132600 135078 132601 for(ii=0; ii<nCell; ii++){ 135079 132602 if( ii==(nCell-1) ){ 135080 132603 memcpy(&aCell[ii], pCell, sizeof(RtreeCell)); 135081 132604 }else{ 135082 132605 nodeGetCell(pRtree, pNode, ii, &aCell[ii]); 135083 132606 } 135084 132607 aOrder[ii] = ii; 135085 132608 for(iDim=0; iDim<pRtree->nDim; iDim++){ 135086 - aCenterCoord[iDim] += DCOORD(aCell[ii].aCoord[iDim*2]); 135087 - aCenterCoord[iDim] += DCOORD(aCell[ii].aCoord[iDim*2+1]); 132609 + aCenterCoord[iDim] += (float)DCOORD(aCell[ii].aCoord[iDim*2]); 132610 + aCenterCoord[iDim] += (float)DCOORD(aCell[ii].aCoord[iDim*2+1]); 135088 132611 } 135089 132612 } 135090 132613 for(iDim=0; iDim<pRtree->nDim; iDim++){ 135091 - aCenterCoord[iDim] = (aCenterCoord[iDim]/(nCell*(RtreeDValue)2)); 132614 + aCenterCoord[iDim] = (float)(aCenterCoord[iDim]/((float)nCell*2.0)); 135092 132615 } 135093 132616 135094 132617 for(ii=0; ii<nCell; ii++){ 135095 132618 aDistance[ii] = 0.0; 135096 132619 for(iDim=0; iDim<pRtree->nDim; iDim++){ 135097 - RtreeDValue coord = (DCOORD(aCell[ii].aCoord[iDim*2+1]) - 135098 - DCOORD(aCell[ii].aCoord[iDim*2])); 132620 + float coord = (float)(DCOORD(aCell[ii].aCoord[iDim*2+1]) - 132621 + DCOORD(aCell[ii].aCoord[iDim*2])); 135099 132622 aDistance[ii] += (coord-aCenterCoord[iDim])*(coord-aCenterCoord[iDim]); 135100 132623 } 135101 132624 } 135102 132625 135103 132626 SortByDistance(aOrder, nCell, aDistance, aSpare); 135104 132627 nodeZero(pRtree, pNode); 135105 132628 ................................................................................ 135333 132856 ** conflict-handling mode specified by the user. 135334 132857 */ 135335 132858 if( nData>1 ){ 135336 132859 int ii; 135337 132860 135338 132861 /* Populate the cell.aCoord[] array. The first coordinate is azData[3]. */ 135339 132862 assert( nData==(pRtree->nDim*2 + 3) ); 135340 -#ifndef SQLITE_RTREE_INT_ONLY 135341 132863 if( pRtree->eCoordType==RTREE_COORD_REAL32 ){ 135342 132864 for(ii=0; ii<(pRtree->nDim*2); ii+=2){ 135343 - cell.aCoord[ii].f = (RtreeValue)sqlite3_value_double(azData[ii+3]); 135344 - cell.aCoord[ii+1].f = (RtreeValue)sqlite3_value_double(azData[ii+4]); 132865 + cell.aCoord[ii].f = (float)sqlite3_value_double(azData[ii+3]); 132866 + cell.aCoord[ii+1].f = (float)sqlite3_value_double(azData[ii+4]); 135345 132867 if( cell.aCoord[ii].f>cell.aCoord[ii+1].f ){ 135346 132868 rc = SQLITE_CONSTRAINT; 135347 132869 goto constraint; 135348 132870 } 135349 132871 } 135350 - }else 135351 -#endif 135352 - { 132872 + }else{ 135353 132873 for(ii=0; ii<(pRtree->nDim*2); ii+=2){ 135354 132874 cell.aCoord[ii].i = sqlite3_value_int(azData[ii+3]); 135355 132875 cell.aCoord[ii+1].i = sqlite3_value_int(azData[ii+4]); 135356 132876 if( cell.aCoord[ii].i>cell.aCoord[ii+1].i ){ 135357 132877 rc = SQLITE_CONSTRAINT; 135358 132878 goto constraint; 135359 132879 } ................................................................................ 135743 133263 RtreeCell cell; 135744 133264 int jj; 135745 133265 135746 133266 nodeGetCell(&tree, &node, ii, &cell); 135747 133267 sqlite3_snprintf(512-nCell,&zCell[nCell],"%lld", cell.iRowid); 135748 133268 nCell = (int)strlen(zCell); 135749 133269 for(jj=0; jj<tree.nDim*2; jj++){ 135750 -#ifndef SQLITE_RTREE_INT_ONLY 135751 - sqlite3_snprintf(512-nCell,&zCell[nCell], " %f", 135752 - (double)cell.aCoord[jj].f); 135753 -#else 135754 - sqlite3_snprintf(512-nCell,&zCell[nCell], " %d", 135755 - cell.aCoord[jj].i); 135756 -#endif 133270 + sqlite3_snprintf(512-nCell,&zCell[nCell]," %f",(double)cell.aCoord[jj].f); 135757 133271 nCell = (int)strlen(zCell); 135758 133272 } 135759 133273 135760 133274 if( zText ){ 135761 133275 char *zTextNew = sqlite3_mprintf("%s {%s}", zText, zCell); 135762 133276 sqlite3_free(zText); 135763 133277 zText = zTextNew; ................................................................................ 135791 133305 int rc; 135792 133306 135793 133307 rc = sqlite3_create_function(db, "rtreenode", 2, utf8, 0, rtreenode, 0, 0); 135794 133308 if( rc==SQLITE_OK ){ 135795 133309 rc = sqlite3_create_function(db, "rtreedepth", 1, utf8, 0,rtreedepth, 0, 0); 135796 133310 } 135797 133311 if( rc==SQLITE_OK ){ 135798 -#ifdef SQLITE_RTREE_INT_ONLY 135799 - void *c = (void *)RTREE_COORD_INT32; 135800 -#else 135801 133312 void *c = (void *)RTREE_COORD_REAL32; 135802 -#endif 135803 133313 rc = sqlite3_create_module_v2(db, "rtree", &rtreeModule, c, 0); 135804 133314 } 135805 133315 if( rc==SQLITE_OK ){ 135806 133316 void *c = (void *)RTREE_COORD_INT32; 135807 133317 rc = sqlite3_create_module_v2(db, "rtree_i32", &rtreeModule, c, 0); 135808 133318 } 135809 133319 ................................................................................ 135829 133339 ** table MATCH operators. 135830 133340 */ 135831 133341 static void geomCallback(sqlite3_context *ctx, int nArg, sqlite3_value **aArg){ 135832 133342 RtreeGeomCallback *pGeomCtx = (RtreeGeomCallback *)sqlite3_user_data(ctx); 135833 133343 RtreeMatchArg *pBlob; 135834 133344 int nBlob; 135835 133345 135836 - nBlob = sizeof(RtreeMatchArg) + (nArg-1)*sizeof(RtreeDValue); 133346 + nBlob = sizeof(RtreeMatchArg) + (nArg-1)*sizeof(double); 135837 133347 pBlob = (RtreeMatchArg *)sqlite3_malloc(nBlob); 135838 133348 if( !pBlob ){ 135839 133349 sqlite3_result_error_nomem(ctx); 135840 133350 }else{ 135841 133351 int i; 135842 133352 pBlob->magic = RTREE_GEOMETRY_MAGIC; 135843 133353 pBlob->xGeom = pGeomCtx->xGeom; 135844 133354 pBlob->pContext = pGeomCtx->pContext; 135845 133355 pBlob->nParam = nArg; 135846 133356 for(i=0; i<nArg; i++){ 135847 -#ifdef SQLITE_RTREE_INT_ONLY 135848 - pBlob->aParam[i] = sqlite3_value_int64(aArg[i]); 135849 -#else 135850 133357 pBlob->aParam[i] = sqlite3_value_double(aArg[i]); 135851 -#endif 135852 133358 } 135853 133359 sqlite3_result_blob(ctx, pBlob, nBlob, doSqlite3Free); 135854 133360 } 135855 133361 } 135856 133362 135857 133363 /* 135858 133364 ** Register a new geometry function for use with the r-tree MATCH operator. 135859 133365 */ 135860 133366 SQLITE_API int sqlite3_rtree_geometry_callback( 135861 133367 sqlite3 *db, 135862 133368 const char *zGeom, 135863 - int (*xGeom)(sqlite3_rtree_geometry *, int, RtreeDValue *, int *), 133369 + int (*xGeom)(sqlite3_rtree_geometry *, int, double *, int *), 135864 133370 void *pContext 135865 133371 ){ 135866 133372 RtreeGeomCallback *pGeomCtx; /* Context object for new user-function */ 135867 133373 135868 133374 /* Allocate and populate the context object. */ 135869 133375 pGeomCtx = (RtreeGeomCallback *)sqlite3_malloc(sizeof(RtreeGeomCallback)); 135870 133376 if( !pGeomCtx ) return SQLITE_NOMEM; ................................................................................ 136501 134007 136502 134008 UChar32 c; 136503 134009 int iInput = 0; 136504 134010 int iOut = 0; 136505 134011 136506 134012 *ppCursor = 0; 136507 134013 136508 - if( zInput==0 ){ 136509 - nInput = 0; 136510 - zInput = ""; 136511 - }else if( nInput<0 ){ 134014 + if( nInput<0 ){ 136512 134015 nInput = strlen(zInput); 136513 134016 } 136514 134017 nChar = nInput+1; 136515 134018 pCsr = (IcuCursor *)sqlite3_malloc( 136516 134019 sizeof(IcuCursor) + /* IcuCursor */ 136517 134020 nChar * sizeof(UChar) + /* IcuCursor.aChar[] */ 136518 134021 (nChar+1) * sizeof(int) /* IcuCursor.aOffset[] */
Changes to test/sql_stmt_tests/testFDO.sqlite.
cannot compute difference between binary files
Changes to test/sql_stmt_tests/testFGF.sqlite.
cannot compute difference between binary files