| | @@ -1162,11 +1162,11 @@ |
| 1162 | 1162 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 1163 | 1163 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 1164 | 1164 | */ |
| 1165 | 1165 | #define SQLITE_VERSION "3.33.0" |
| 1166 | 1166 | #define SQLITE_VERSION_NUMBER 3033000 |
| 1167 | | -#define SQLITE_SOURCE_ID "2020-06-08 11:34:40 6e6b3729e0549de028f6c5bf494b2d69d621c81b61a1dc0a329d3950039342fb" |
| 1167 | +#define SQLITE_SOURCE_ID "2020-06-19 15:24:12 7a876209a678a34c198b54ceef9e3c041f128a14dc73357f6a57cadadaa6cf7b" |
| 1168 | 1168 | |
| 1169 | 1169 | /* |
| 1170 | 1170 | ** CAPI3REF: Run-Time Library Version Numbers |
| 1171 | 1171 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 1172 | 1172 | ** |
| | @@ -1601,19 +1601,22 @@ |
| 1601 | 1601 | #define SQLITE_OPEN_TEMP_DB 0x00000200 /* VFS only */ |
| 1602 | 1602 | #define SQLITE_OPEN_TRANSIENT_DB 0x00000400 /* VFS only */ |
| 1603 | 1603 | #define SQLITE_OPEN_MAIN_JOURNAL 0x00000800 /* VFS only */ |
| 1604 | 1604 | #define SQLITE_OPEN_TEMP_JOURNAL 0x00001000 /* VFS only */ |
| 1605 | 1605 | #define SQLITE_OPEN_SUBJOURNAL 0x00002000 /* VFS only */ |
| 1606 | | -#define SQLITE_OPEN_MASTER_JOURNAL 0x00004000 /* VFS only */ |
| 1606 | +#define SQLITE_OPEN_SUPER_JOURNAL 0x00004000 /* VFS only */ |
| 1607 | 1607 | #define SQLITE_OPEN_NOMUTEX 0x00008000 /* Ok for sqlite3_open_v2() */ |
| 1608 | 1608 | #define SQLITE_OPEN_FULLMUTEX 0x00010000 /* Ok for sqlite3_open_v2() */ |
| 1609 | 1609 | #define SQLITE_OPEN_SHAREDCACHE 0x00020000 /* Ok for sqlite3_open_v2() */ |
| 1610 | 1610 | #define SQLITE_OPEN_PRIVATECACHE 0x00040000 /* Ok for sqlite3_open_v2() */ |
| 1611 | 1611 | #define SQLITE_OPEN_WAL 0x00080000 /* VFS only */ |
| 1612 | 1612 | #define SQLITE_OPEN_NOFOLLOW 0x01000000 /* Ok for sqlite3_open_v2() */ |
| 1613 | 1613 | |
| 1614 | 1614 | /* Reserved: 0x00F00000 */ |
| 1615 | +/* Legacy compatibility: */ |
| 1616 | +#define SQLITE_OPEN_MASTER_JOURNAL 0x00004000 /* VFS only */ |
| 1617 | + |
| 1615 | 1618 | |
| 1616 | 1619 | /* |
| 1617 | 1620 | ** CAPI3REF: Device Characteristics |
| 1618 | 1621 | ** |
| 1619 | 1622 | ** The xDeviceCharacteristics method of the [sqlite3_io_methods] |
| | @@ -1907,11 +1910,11 @@ |
| 1907 | 1910 | ** because the user has configured SQLite with |
| 1908 | 1911 | ** [PRAGMA synchronous | PRAGMA synchronous=OFF] it is invoked in place |
| 1909 | 1912 | ** of the xSync method. In most cases, the pointer argument passed with |
| 1910 | 1913 | ** this file-control is NULL. However, if the database file is being synced |
| 1911 | 1914 | ** as part of a multi-database commit, the argument points to a nul-terminated |
| 1912 | | -** string containing the transactions master-journal file name. VFSes that |
| 1915 | +** string containing the transactions super-journal file name. VFSes that |
| 1913 | 1916 | ** do not need this signal should silently ignore this opcode. Applications |
| 1914 | 1917 | ** should not call [sqlite3_file_control()] with this opcode as doing so may |
| 1915 | 1918 | ** disrupt the operation of the specialized VFSes that do require it. |
| 1916 | 1919 | ** |
| 1917 | 1920 | ** <li>[[SQLITE_FCNTL_COMMIT_PHASETWO]] |
| | @@ -2304,11 +2307,11 @@ |
| 2304 | 2307 | ** <li> [SQLITE_OPEN_MAIN_JOURNAL] |
| 2305 | 2308 | ** <li> [SQLITE_OPEN_TEMP_DB] |
| 2306 | 2309 | ** <li> [SQLITE_OPEN_TEMP_JOURNAL] |
| 2307 | 2310 | ** <li> [SQLITE_OPEN_TRANSIENT_DB] |
| 2308 | 2311 | ** <li> [SQLITE_OPEN_SUBJOURNAL] |
| 2309 | | -** <li> [SQLITE_OPEN_MASTER_JOURNAL] |
| 2312 | +** <li> [SQLITE_OPEN_SUPER_JOURNAL] |
| 2310 | 2313 | ** <li> [SQLITE_OPEN_WAL] |
| 2311 | 2314 | ** </ul>)^ |
| 2312 | 2315 | ** |
| 2313 | 2316 | ** The file I/O implementation can use the object type flags to |
| 2314 | 2317 | ** change the way it deals with files. For example, an application |
| | @@ -2682,11 +2685,11 @@ |
| 2682 | 2685 | ** structures. The xShutdown method is invoked (indirectly) by |
| 2683 | 2686 | ** [sqlite3_shutdown()] and should deallocate any resources acquired |
| 2684 | 2687 | ** by xInit. The pAppData pointer is used as the only parameter to |
| 2685 | 2688 | ** xInit and xShutdown. |
| 2686 | 2689 | ** |
| 2687 | | -** SQLite holds the [SQLITE_MUTEX_STATIC_MASTER] mutex when it invokes |
| 2690 | +** SQLite holds the [SQLITE_MUTEX_STATIC_MAIN] mutex when it invokes |
| 2688 | 2691 | ** the xInit method, so the xInit method need not be threadsafe. The |
| 2689 | 2692 | ** xShutdown method is only called from [sqlite3_shutdown()] so it does |
| 2690 | 2693 | ** not need to be threadsafe either. For all other methods, SQLite |
| 2691 | 2694 | ** holds the [SQLITE_MUTEX_STATIC_MEM] mutex as long as the |
| 2692 | 2695 | ** [SQLITE_CONFIG_MEMSTATUS] configuration option is turned on (which |
| | @@ -3320,12 +3323,11 @@ |
| 3320 | 3323 | ** </dd> |
| 3321 | 3324 | ** |
| 3322 | 3325 | ** [[SQLITE_DBCONFIG_TRUSTED_SCHEMA]] |
| 3323 | 3326 | ** <dt>SQLITE_DBCONFIG_TRUSTED_SCHEMA</td> |
| 3324 | 3327 | ** <dd>The SQLITE_DBCONFIG_TRUSTED_SCHEMA option tells SQLite to |
| 3325 | | -** assume that database schemas (the contents of the [sqlite_master] tables) |
| 3326 | | -** are untainted by malicious content. |
| 3328 | +** assume that database schemas are untainted by malicious content. |
| 3327 | 3329 | ** When the SQLITE_DBCONFIG_TRUSTED_SCHEMA option is disabled, SQLite |
| 3328 | 3330 | ** takes additional defensive steps to protect the application from harm |
| 3329 | 3331 | ** including: |
| 3330 | 3332 | ** <ul> |
| 3331 | 3333 | ** <li> Prohibit the use of SQL functions inside triggers, views, |
| | @@ -7311,11 +7313,11 @@ |
| 7311 | 7313 | ** database and table name containing the affected row. |
| 7312 | 7314 | ** ^The final callback parameter is the [rowid] of the row. |
| 7313 | 7315 | ** ^In the case of an update, this is the [rowid] after the update takes place. |
| 7314 | 7316 | ** |
| 7315 | 7317 | ** ^(The update hook is not invoked when internal system tables are |
| 7316 | | -** modified (i.e. sqlite_master and sqlite_sequence).)^ |
| 7318 | +** modified (i.e. sqlite_sequence).)^ |
| 7317 | 7319 | ** ^The update hook is not invoked when [WITHOUT ROWID] tables are modified. |
| 7318 | 7320 | ** |
| 7319 | 7321 | ** ^In the current implementation, the update hook |
| 7320 | 7322 | ** is not invoked when conflicting rows are deleted because of an |
| 7321 | 7323 | ** [ON CONFLICT | ON CONFLICT REPLACE] clause. ^Nor is the update hook |
| | @@ -8413,11 +8415,11 @@ |
| 8413 | 8415 | ** integer constants: |
| 8414 | 8416 | ** |
| 8415 | 8417 | ** <ul> |
| 8416 | 8418 | ** <li> SQLITE_MUTEX_FAST |
| 8417 | 8419 | ** <li> SQLITE_MUTEX_RECURSIVE |
| 8418 | | -** <li> SQLITE_MUTEX_STATIC_MASTER |
| 8420 | +** <li> SQLITE_MUTEX_STATIC_MAIN |
| 8419 | 8421 | ** <li> SQLITE_MUTEX_STATIC_MEM |
| 8420 | 8422 | ** <li> SQLITE_MUTEX_STATIC_OPEN |
| 8421 | 8423 | ** <li> SQLITE_MUTEX_STATIC_PRNG |
| 8422 | 8424 | ** <li> SQLITE_MUTEX_STATIC_LRU |
| 8423 | 8425 | ** <li> SQLITE_MUTEX_STATIC_PMEM |
| | @@ -8615,11 +8617,11 @@ |
| 8615 | 8617 | ** next. Applications that override the built-in mutex logic must be |
| 8616 | 8618 | ** prepared to accommodate additional static mutexes. |
| 8617 | 8619 | */ |
| 8618 | 8620 | #define SQLITE_MUTEX_FAST 0 |
| 8619 | 8621 | #define SQLITE_MUTEX_RECURSIVE 1 |
| 8620 | | -#define SQLITE_MUTEX_STATIC_MASTER 2 |
| 8622 | +#define SQLITE_MUTEX_STATIC_MAIN 2 |
| 8621 | 8623 | #define SQLITE_MUTEX_STATIC_MEM 3 /* sqlite3_malloc() */ |
| 8622 | 8624 | #define SQLITE_MUTEX_STATIC_MEM2 4 /* NOT USED */ |
| 8623 | 8625 | #define SQLITE_MUTEX_STATIC_OPEN 4 /* sqlite3BtreeOpen() */ |
| 8624 | 8626 | #define SQLITE_MUTEX_STATIC_PRNG 5 /* sqlite3_randomness() */ |
| 8625 | 8627 | #define SQLITE_MUTEX_STATIC_LRU 6 /* lru page list */ |
| | @@ -8629,10 +8631,14 @@ |
| 8629 | 8631 | #define SQLITE_MUTEX_STATIC_APP2 9 /* For use by application */ |
| 8630 | 8632 | #define SQLITE_MUTEX_STATIC_APP3 10 /* For use by application */ |
| 8631 | 8633 | #define SQLITE_MUTEX_STATIC_VFS1 11 /* For use by built-in VFS */ |
| 8632 | 8634 | #define SQLITE_MUTEX_STATIC_VFS2 12 /* For use by extension VFS */ |
| 8633 | 8635 | #define SQLITE_MUTEX_STATIC_VFS3 13 /* For use by application VFS */ |
| 8636 | + |
| 8637 | +/* Legacy compatibility: */ |
| 8638 | +#define SQLITE_MUTEX_STATIC_MASTER 2 |
| 8639 | + |
| 8634 | 8640 | |
| 8635 | 8641 | /* |
| 8636 | 8642 | ** CAPI3REF: Retrieve the mutex for a database connection |
| 8637 | 8643 | ** METHOD: sqlite3 |
| 8638 | 8644 | ** |
| | @@ -10425,11 +10431,11 @@ |
| 10425 | 10431 | ** ^The third parameter to [sqlite3_preupdate_hook()] is passed through as |
| 10426 | 10432 | ** the first parameter to callbacks. |
| 10427 | 10433 | ** |
| 10428 | 10434 | ** ^The preupdate hook only fires for changes to real database tables; the |
| 10429 | 10435 | ** preupdate hook is not invoked for changes to [virtual tables] or to |
| 10430 | | -** system tables like sqlite_master or sqlite_stat1. |
| 10436 | +** system tables like sqlite_sequence or sqlite_stat1. |
| 10431 | 10437 | ** |
| 10432 | 10438 | ** ^The second parameter to the preupdate callback is a pointer to |
| 10433 | 10439 | ** the [database connection] that registered the preupdate hook. |
| 10434 | 10440 | ** ^The third parameter to the preupdate callback is one of the constants |
| 10435 | 10441 | ** [SQLITE_INSERT], [SQLITE_DELETE], or [SQLITE_UPDATE] to identify the |
| | @@ -14522,10 +14528,20 @@ |
| 14522 | 14528 | #if defined(SQLITE_ENABLE_SELECTTRACE) |
| 14523 | 14529 | # define SELECTTRACE_ENABLED 1 |
| 14524 | 14530 | #else |
| 14525 | 14531 | # define SELECTTRACE_ENABLED 0 |
| 14526 | 14532 | #endif |
| 14533 | +#if defined(SQLITE_ENABLE_SELECTTRACE) |
| 14534 | +# define SELECTTRACE_ENABLED 1 |
| 14535 | +# define SELECTTRACE(K,P,S,X) \ |
| 14536 | + if(sqlite3SelectTrace&(K)) \ |
| 14537 | + sqlite3DebugPrintf("%u/%d/%p: ",(S)->selId,(P)->addrExplain,(S)),\ |
| 14538 | + sqlite3DebugPrintf X |
| 14539 | +#else |
| 14540 | +# define SELECTTRACE(K,P,S,X) |
| 14541 | +# define SELECTTRACE_ENABLED 0 |
| 14542 | +#endif |
| 14527 | 14543 | |
| 14528 | 14544 | /* |
| 14529 | 14545 | ** An instance of the following structure is used to store the busy-handler |
| 14530 | 14546 | ** callback for a given sqlite handle. |
| 14531 | 14547 | ** |
| | @@ -14540,26 +14556,28 @@ |
| 14540 | 14556 | void *pBusyArg; /* First arg to busy callback */ |
| 14541 | 14557 | int nBusy; /* Incremented with each busy call */ |
| 14542 | 14558 | }; |
| 14543 | 14559 | |
| 14544 | 14560 | /* |
| 14545 | | -** Name of the master database table. The master database table |
| 14546 | | -** is a special table that holds the names and attributes of all |
| 14547 | | -** user tables and indices. |
| 14548 | | -*/ |
| 14549 | | -#define MASTER_NAME "sqlite_master" |
| 14550 | | -#define TEMP_MASTER_NAME "sqlite_temp_master" |
| 14551 | | - |
| 14552 | | -/* |
| 14553 | | -** The root-page of the master database table. |
| 14554 | | -*/ |
| 14555 | | -#define MASTER_ROOT 1 |
| 14556 | | - |
| 14557 | | -/* |
| 14558 | | -** The name of the schema table. |
| 14559 | | -*/ |
| 14560 | | -#define SCHEMA_TABLE(x) ((!OMIT_TEMPDB)&&(x==1)?TEMP_MASTER_NAME:MASTER_NAME) |
| 14561 | +** Name of table that holds the database schema. |
| 14562 | +*/ |
| 14563 | +#define DFLT_SCHEMA_TABLE "sqlite_master" |
| 14564 | +#define DFLT_TEMP_SCHEMA_TABLE "sqlite_temp_master" |
| 14565 | +#define ALT_SCHEMA_TABLE "sqlite_schema" |
| 14566 | +#define ALT_TEMP_SCHEMA_TABLE "sqlite_temp_schema" |
| 14567 | + |
| 14568 | + |
| 14569 | +/* |
| 14570 | +** The root-page of the schema table. |
| 14571 | +*/ |
| 14572 | +#define SCHEMA_ROOT 1 |
| 14573 | + |
| 14574 | +/* |
| 14575 | +** The name of the schema table. The name is different for TEMP. |
| 14576 | +*/ |
| 14577 | +#define SCHEMA_TABLE(x) \ |
| 14578 | + ((!OMIT_TEMPDB)&&(x==1)?DFLT_TEMP_SCHEMA_TABLE:DFLT_SCHEMA_TABLE) |
| 14561 | 14579 | |
| 14562 | 14580 | /* |
| 14563 | 14581 | ** A convenience macro that returns the number of elements in |
| 14564 | 14582 | ** an array. |
| 14565 | 14583 | */ |
| | @@ -14799,11 +14817,11 @@ |
| 14799 | 14817 | SQLITE_PRIVATE int sqlite3BtreeGetRequestedReserve(Btree*); |
| 14800 | 14818 | SQLITE_PRIVATE int sqlite3BtreeGetReserveNoMutex(Btree *p); |
| 14801 | 14819 | SQLITE_PRIVATE int sqlite3BtreeSetAutoVacuum(Btree *, int); |
| 14802 | 14820 | SQLITE_PRIVATE int sqlite3BtreeGetAutoVacuum(Btree *); |
| 14803 | 14821 | SQLITE_PRIVATE int sqlite3BtreeBeginTrans(Btree*,int,int*); |
| 14804 | | -SQLITE_PRIVATE int sqlite3BtreeCommitPhaseOne(Btree*, const char *zMaster); |
| 14822 | +SQLITE_PRIVATE int sqlite3BtreeCommitPhaseOne(Btree*, const char*); |
| 14805 | 14823 | SQLITE_PRIVATE int sqlite3BtreeCommitPhaseTwo(Btree*, int); |
| 14806 | 14824 | SQLITE_PRIVATE int sqlite3BtreeCommit(Btree*); |
| 14807 | 14825 | SQLITE_PRIVATE int sqlite3BtreeRollback(Btree*,int,int); |
| 14808 | 14826 | SQLITE_PRIVATE int sqlite3BtreeBeginStmt(Btree*,int); |
| 14809 | 14827 | SQLITE_PRIVATE int sqlite3BtreeCreateTable(Btree*, int*, int flags); |
| | @@ -15788,12 +15806,12 @@ |
| 15788 | 15806 | |
| 15789 | 15807 | /* |
| 15790 | 15808 | ** Page number PAGER_MJ_PGNO is never used in an SQLite database (it is |
| 15791 | 15809 | ** reserved for working around a windows/posix incompatibility). It is |
| 15792 | 15810 | ** used in the journal to signify that the remainder of the journal file |
| 15793 | | -** is devoted to storing a master journal name - there are no more pages to |
| 15794 | | -** roll back. See comments for function writeMasterJournal() in pager.c |
| 15811 | +** is devoted to storing a super-journal name - there are no more pages to |
| 15812 | +** roll back. See comments for function writeSuperJournal() in pager.c |
| 15795 | 15813 | ** for details. |
| 15796 | 15814 | */ |
| 15797 | 15815 | #define PAGER_MJ_PGNO(x) ((Pgno)((PENDING_BYTE/((x)->pageSize))+1)) |
| 15798 | 15816 | |
| 15799 | 15817 | /* |
| | @@ -15903,13 +15921,13 @@ |
| 15903 | 15921 | SQLITE_PRIVATE void *sqlite3PagerGetExtra(DbPage *); |
| 15904 | 15922 | |
| 15905 | 15923 | /* Functions used to manage pager transactions and savepoints. */ |
| 15906 | 15924 | SQLITE_PRIVATE void sqlite3PagerPagecount(Pager*, int*); |
| 15907 | 15925 | SQLITE_PRIVATE int sqlite3PagerBegin(Pager*, int exFlag, int); |
| 15908 | | -SQLITE_PRIVATE int sqlite3PagerCommitPhaseOne(Pager*,const char *zMaster, int); |
| 15926 | +SQLITE_PRIVATE int sqlite3PagerCommitPhaseOne(Pager*,const char *zSuper, int); |
| 15909 | 15927 | SQLITE_PRIVATE int sqlite3PagerExclusiveLock(Pager*); |
| 15910 | | -SQLITE_PRIVATE int sqlite3PagerSync(Pager *pPager, const char *zMaster); |
| 15928 | +SQLITE_PRIVATE int sqlite3PagerSync(Pager *pPager, const char *zSuper); |
| 15911 | 15929 | SQLITE_PRIVATE int sqlite3PagerCommitPhaseTwo(Pager*); |
| 15912 | 15930 | SQLITE_PRIVATE int sqlite3PagerRollback(Pager*); |
| 15913 | 15931 | SQLITE_PRIVATE int sqlite3PagerOpenSavepoint(Pager *pPager, int n); |
| 15914 | 15932 | SQLITE_PRIVATE int sqlite3PagerSavepoint(Pager *pPager, int op, int iSavepoint); |
| 15915 | 15933 | SQLITE_PRIVATE int sqlite3PagerSharedLock(Pager *pPager); |
| | @@ -16901,11 +16919,11 @@ |
| 16901 | 16919 | int nStatement; /* Number of nested statement-transactions */ |
| 16902 | 16920 | i64 nDeferredCons; /* Net deferred constraints this transaction. */ |
| 16903 | 16921 | i64 nDeferredImmCons; /* Net deferred immediate constraints */ |
| 16904 | 16922 | int *pnBytesFreed; /* If not NULL, increment this in DbFree() */ |
| 16905 | 16923 | #ifdef SQLITE_ENABLE_UNLOCK_NOTIFY |
| 16906 | | - /* The following variables are all protected by the STATIC_MASTER |
| 16924 | + /* The following variables are all protected by the STATIC_MAIN |
| 16907 | 16925 | ** mutex, not by sqlite3.mutex. They are used by code in notify.c. |
| 16908 | 16926 | ** |
| 16909 | 16927 | ** When X.pUnlockConnection==Y, that means that X is waiting for Y to |
| 16910 | 16928 | ** unlock so that it can proceed. |
| 16911 | 16929 | ** |
| | @@ -16943,11 +16961,11 @@ |
| 16943 | 16961 | ** Value constraints (enforced via assert()): |
| 16944 | 16962 | ** SQLITE_FullFSync == PAGER_FULLFSYNC |
| 16945 | 16963 | ** SQLITE_CkptFullFSync == PAGER_CKPT_FULLFSYNC |
| 16946 | 16964 | ** SQLITE_CacheSpill == PAGER_CACHE_SPILL |
| 16947 | 16965 | */ |
| 16948 | | -#define SQLITE_WriteSchema 0x00000001 /* OK to update SQLITE_MASTER */ |
| 16966 | +#define SQLITE_WriteSchema 0x00000001 /* OK to update SQLITE_SCHEMA */ |
| 16949 | 16967 | #define SQLITE_LegacyFileFmt 0x00000002 /* Create new databases in format 1 */ |
| 16950 | 16968 | #define SQLITE_FullColNames 0x00000004 /* Show full column names on SELECT */ |
| 16951 | 16969 | #define SQLITE_FullFSync 0x00000008 /* Use full fsync on the backend */ |
| 16952 | 16970 | #define SQLITE_CkptFullFSync 0x00000010 /* Use full fsync for checkpoint */ |
| 16953 | 16971 | #define SQLITE_CacheSpill 0x00000020 /* OK to spill pager cache */ |
| | @@ -17737,11 +17755,11 @@ |
| 17737 | 17755 | ** and the value of Index.onError indicate the which conflict resolution |
| 17738 | 17756 | ** algorithm to employ whenever an attempt is made to insert a non-unique |
| 17739 | 17757 | ** element. |
| 17740 | 17758 | ** |
| 17741 | 17759 | ** While parsing a CREATE TABLE or CREATE INDEX statement in order to |
| 17742 | | -** generate VDBE code (as opposed to parsing one read from an sqlite_master |
| 17760 | +** generate VDBE code (as opposed to parsing one read from an sqlite_schema |
| 17743 | 17761 | ** table as part of parsing an existing database schema), transient instances |
| 17744 | 17762 | ** of this structure may be created. In this case the Index.tnum variable is |
| 17745 | 17763 | ** used to store the address of a VDBE instruction, not a database page |
| 17746 | 17764 | ** number (it cannot - the database page is not allocated until the VDBE |
| 17747 | 17765 | ** program is executed). See convertToWithoutRowidTable() for details. |
| | @@ -17861,11 +17879,11 @@ |
| 17861 | 17879 | int nSortingColumn; /* Number of columns in the sorting index */ |
| 17862 | 17880 | int mnReg, mxReg; /* Range of registers allocated for aCol and aFunc */ |
| 17863 | 17881 | ExprList *pGroupBy; /* The group by clause */ |
| 17864 | 17882 | struct AggInfo_col { /* For each column used in source tables */ |
| 17865 | 17883 | Table *pTab; /* Source table */ |
| 17866 | | - Expr *pExpr; /* The original expression */ |
| 17884 | + Expr *pCExpr; /* The original expression */ |
| 17867 | 17885 | int iTable; /* Cursor number of the source table */ |
| 17868 | 17886 | int iMem; /* Memory location that acts as accumulator */ |
| 17869 | 17887 | i16 iColumn; /* Column number within the source table */ |
| 17870 | 17888 | i16 iSorterColumn; /* Column number in the sorting index */ |
| 17871 | 17889 | } *aCol; |
| | @@ -17872,19 +17890,17 @@ |
| 17872 | 17890 | int nColumn; /* Number of used entries in aCol[] */ |
| 17873 | 17891 | int nAccumulator; /* Number of columns that show through to the output. |
| 17874 | 17892 | ** Additional columns are used only as parameters to |
| 17875 | 17893 | ** aggregate functions */ |
| 17876 | 17894 | struct AggInfo_func { /* For each aggregate function */ |
| 17877 | | - Expr *pExpr; /* Expression encoding the function */ |
| 17895 | + Expr *pFExpr; /* Expression encoding the function */ |
| 17878 | 17896 | FuncDef *pFunc; /* The aggregate function implementation */ |
| 17879 | 17897 | int iMem; /* Memory location that acts as accumulator */ |
| 17880 | 17898 | int iDistinct; /* Ephemeral table used to enforce DISTINCT */ |
| 17881 | 17899 | } *aFunc; |
| 17882 | 17900 | int nFunc; /* Number of entries in aFunc[] */ |
| 17883 | | -#ifdef SQLITE_DEBUG |
| 17884 | | - int iAggMagic; /* Magic number when valid */ |
| 17885 | | -#endif |
| 17901 | + u32 selId; /* Select to which this AggInfo belongs */ |
| 17886 | 17902 | AggInfo *pNext; /* Next in list of them all */ |
| 17887 | 17903 | }; |
| 17888 | 17904 | |
| 17889 | 17905 | /* |
| 17890 | 17906 | ** Value for AggInfo.iAggMagic when the structure is valid |
| | @@ -18065,11 +18081,11 @@ |
| 18065 | 18081 | #define EP_Subrtn 0x2000000 /* Uses Expr.y.sub. TK_IN, _SELECT, or _EXISTS */ |
| 18066 | 18082 | #define EP_Quoted 0x4000000 /* TK_ID was originally quoted */ |
| 18067 | 18083 | #define EP_Static 0x8000000 /* Held in memory not obtained from malloc() */ |
| 18068 | 18084 | #define EP_IsTrue 0x10000000 /* Always has boolean value of TRUE */ |
| 18069 | 18085 | #define EP_IsFalse 0x20000000 /* Always has boolean value of FALSE */ |
| 18070 | | -#define EP_FromDDL 0x40000000 /* Originates from sqlite_master */ |
| 18086 | +#define EP_FromDDL 0x40000000 /* Originates from sqlite_schema */ |
| 18071 | 18087 | /* 0x80000000 // Available */ |
| 18072 | 18088 | |
| 18073 | 18089 | /* |
| 18074 | 18090 | ** The EP_Propagate mask is a set of properties that automatically propagate |
| 18075 | 18091 | ** upwards into parent nodes. |
| | @@ -18245,11 +18261,11 @@ |
| 18245 | 18261 | unsigned isIndexedBy :1; /* True if there is an INDEXED BY clause */ |
| 18246 | 18262 | unsigned isTabFunc :1; /* True if table-valued-function syntax */ |
| 18247 | 18263 | unsigned isCorrelated :1; /* True if sub-query is correlated */ |
| 18248 | 18264 | unsigned viaCoroutine :1; /* Implemented as a co-routine */ |
| 18249 | 18265 | unsigned isRecursive :1; /* True for recursive reference in WITH */ |
| 18250 | | - unsigned fromDDL :1; /* Comes from sqlite_master */ |
| 18266 | + unsigned fromDDL :1; /* Comes from sqlite_schema */ |
| 18251 | 18267 | } fg; |
| 18252 | 18268 | int iCursor; /* The VDBE cursor number used to access this table */ |
| 18253 | 18269 | Expr *pOn; /* The ON clause of a join */ |
| 18254 | 18270 | IdList *pUsing; /* The USING clause of a join */ |
| 18255 | 18271 | Bitmask colUsed; /* Bit N (1<<N) set if column N of pTab is used */ |
| | @@ -18366,11 +18382,11 @@ |
| 18366 | 18382 | #define NC_Complex 0x02000 /* True if a function or subquery seen */ |
| 18367 | 18383 | #define NC_AllowWin 0x04000 /* Window functions are allowed here */ |
| 18368 | 18384 | #define NC_HasWin 0x08000 /* One or more window functions seen */ |
| 18369 | 18385 | #define NC_IsDDL 0x10000 /* Resolving names in a CREATE statement */ |
| 18370 | 18386 | #define NC_InAggFunc 0x20000 /* True if analyzing arguments to an agg func */ |
| 18371 | | -#define NC_FromDDL 0x40000 /* SQL text comes from sqlite_master */ |
| 18387 | +#define NC_FromDDL 0x40000 /* SQL text comes from sqlite_schema */ |
| 18372 | 18388 | |
| 18373 | 18389 | /* |
| 18374 | 18390 | ** An instance of the following object describes a single ON CONFLICT |
| 18375 | 18391 | ** clause in an upsert. |
| 18376 | 18392 | ** |
| | @@ -18469,10 +18485,11 @@ |
| 18469 | 18485 | #define SF_IncludeHidden 0x0020000 /* Include hidden columns in output */ |
| 18470 | 18486 | #define SF_ComplexResult 0x0040000 /* Result contains subquery or function */ |
| 18471 | 18487 | #define SF_WhereBegin 0x0080000 /* Really a WhereBegin() call. Debug Only */ |
| 18472 | 18488 | #define SF_WinRewrite 0x0100000 /* Window function rewrite accomplished */ |
| 18473 | 18489 | #define SF_View 0x0200000 /* SELECT statement is a view */ |
| 18490 | +#define SF_NoopOrderBy 0x0400000 /* ORDER BY is ignored for this query */ |
| 18474 | 18491 | |
| 18475 | 18492 | /* |
| 18476 | 18493 | ** The results of a SELECT can be distributed in several ways, as defined |
| 18477 | 18494 | ** by one of the following macros. The "SRT" prefix means "SELECT Result |
| 18478 | 18495 | ** Type". |
| | @@ -19490,11 +19507,11 @@ |
| 19490 | 19507 | SQLITE_PRIVATE void sqlite3CommitInternalChanges(sqlite3*); |
| 19491 | 19508 | SQLITE_PRIVATE void sqlite3DeleteColumnNames(sqlite3*,Table*); |
| 19492 | 19509 | SQLITE_PRIVATE int sqlite3ColumnsFromExprList(Parse*,ExprList*,i16*,Column**); |
| 19493 | 19510 | SQLITE_PRIVATE void sqlite3SelectAddColumnTypeAndCollation(Parse*,Table*,Select*,char); |
| 19494 | 19511 | SQLITE_PRIVATE Table *sqlite3ResultSetOfSelect(Parse*,Select*,char); |
| 19495 | | -SQLITE_PRIVATE void sqlite3OpenMasterTable(Parse *, int); |
| 19512 | +SQLITE_PRIVATE void sqlite3OpenSchemaTable(Parse *, int); |
| 19496 | 19513 | SQLITE_PRIVATE Index *sqlite3PrimaryKeyIndex(Table*); |
| 19497 | 19514 | SQLITE_PRIVATE i16 sqlite3TableColumnToIndex(Index*, i16); |
| 19498 | 19515 | #ifdef SQLITE_OMIT_GENERATED_COLUMNS |
| 19499 | 19516 | # define sqlite3TableColumnToStorage(T,X) (X) /* No-op pass-through */ |
| 19500 | 19517 | # define sqlite3StorageColumnToTable(T,X) (X) /* No-op pass-through */ |
| | @@ -19912,14 +19929,15 @@ |
| 19912 | 19929 | SQLITE_PRIVATE const char sqlite3StrBINARY[]; |
| 19913 | 19930 | SQLITE_PRIVATE const unsigned char sqlite3UpperToLower[]; |
| 19914 | 19931 | SQLITE_PRIVATE const unsigned char sqlite3CtypeMap[]; |
| 19915 | 19932 | SQLITE_PRIVATE SQLITE_WSD struct Sqlite3Config sqlite3Config; |
| 19916 | 19933 | SQLITE_PRIVATE FuncDefHash sqlite3BuiltinFunctions; |
| 19934 | +SQLITE_PRIVATE u32 sqlite3SelectTrace; |
| 19917 | 19935 | #ifndef SQLITE_OMIT_WSD |
| 19918 | 19936 | SQLITE_PRIVATE int sqlite3PendingByte; |
| 19919 | 19937 | #endif |
| 19920 | | -#endif |
| 19938 | +#endif /* SQLITE_AMALGAMATION */ |
| 19921 | 19939 | #ifdef VDBE_PROFILE |
| 19922 | 19940 | SQLITE_PRIVATE sqlite3_uint64 sqlite3NProfileCnt; |
| 19923 | 19941 | #endif |
| 19924 | 19942 | SQLITE_PRIVATE void sqlite3RootPageMoved(sqlite3*, int, int, int); |
| 19925 | 19943 | SQLITE_PRIVATE void sqlite3Reindex(Parse*, Token*, Token*); |
| | @@ -20625,10 +20643,15 @@ |
| 20625 | 20643 | */ |
| 20626 | 20644 | #ifndef SQLITE_OMIT_WSD |
| 20627 | 20645 | SQLITE_PRIVATE int sqlite3PendingByte = 0x40000000; |
| 20628 | 20646 | #endif |
| 20629 | 20647 | |
| 20648 | +/* |
| 20649 | +** Flags for select tracing and the ".selecttrace" macro of the CLI |
| 20650 | +*/ |
| 20651 | +/**/ u32 sqlite3SelectTrace = 0; |
| 20652 | + |
| 20630 | 20653 | /* #include "opcodes.h" */ |
| 20631 | 20654 | /* |
| 20632 | 20655 | ** Properties of opcodes. The OPFLG_INITIALIZER macro is |
| 20633 | 20656 | ** created by mkopcodeh.awk during compilation. Data is obtained |
| 20634 | 20657 | ** from the comments following the "case OP_xxxx:" statements in |
| | @@ -22181,11 +22204,11 @@ |
| 22181 | 22204 | static int osLocaltime(time_t *t, struct tm *pTm){ |
| 22182 | 22205 | int rc; |
| 22183 | 22206 | #if !HAVE_LOCALTIME_R && !HAVE_LOCALTIME_S |
| 22184 | 22207 | struct tm *pX; |
| 22185 | 22208 | #if SQLITE_THREADSAFE>0 |
| 22186 | | - sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); |
| 22209 | + sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN); |
| 22187 | 22210 | #endif |
| 22188 | 22211 | sqlite3_mutex_enter(mutex); |
| 22189 | 22212 | pX = localtime(t); |
| 22190 | 22213 | #ifndef SQLITE_UNTESTABLE |
| 22191 | 22214 | if( sqlite3GlobalConfig.bLocaltimeFault ) pX = 0; |
| | @@ -22877,14 +22900,14 @@ |
| 22877 | 22900 | if( iT<=0 ) return; |
| 22878 | 22901 | t = iT/1000 - 10000*(sqlite3_int64)21086676; |
| 22879 | 22902 | #if HAVE_GMTIME_R |
| 22880 | 22903 | pTm = gmtime_r(&t, &sNow); |
| 22881 | 22904 | #else |
| 22882 | | - sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER)); |
| 22905 | + sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN)); |
| 22883 | 22906 | pTm = gmtime(&t); |
| 22884 | 22907 | if( pTm ) memcpy(&sNow, pTm, sizeof(sNow)); |
| 22885 | | - sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER)); |
| 22908 | + sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN)); |
| 22886 | 22909 | #endif |
| 22887 | 22910 | if( pTm ){ |
| 22888 | 22911 | strftime(zBuf, 20, zFormat, &sNow); |
| 22889 | 22912 | sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT); |
| 22890 | 22913 | } |
| | @@ -23271,11 +23294,11 @@ |
| 23271 | 23294 | #ifndef SQLITE_OMIT_AUTOINIT |
| 23272 | 23295 | int rc = sqlite3_initialize(); |
| 23273 | 23296 | if( rc ) return 0; |
| 23274 | 23297 | #endif |
| 23275 | 23298 | #if SQLITE_THREADSAFE |
| 23276 | | - mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); |
| 23299 | + mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN); |
| 23277 | 23300 | #endif |
| 23278 | 23301 | sqlite3_mutex_enter(mutex); |
| 23279 | 23302 | for(pVfs = vfsList; pVfs; pVfs=pVfs->pNext){ |
| 23280 | 23303 | if( zVfs==0 ) break; |
| 23281 | 23304 | if( strcmp(zVfs, pVfs->zName)==0 ) break; |
| | @@ -23286,11 +23309,11 @@ |
| 23286 | 23309 | |
| 23287 | 23310 | /* |
| 23288 | 23311 | ** Unlink a VFS from the linked list |
| 23289 | 23312 | */ |
| 23290 | 23313 | static void vfsUnlink(sqlite3_vfs *pVfs){ |
| 23291 | | - assert( sqlite3_mutex_held(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER)) ); |
| 23314 | + assert( sqlite3_mutex_held(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN)) ); |
| 23292 | 23315 | if( pVfs==0 ){ |
| 23293 | 23316 | /* No-op */ |
| 23294 | 23317 | }else if( vfsList==pVfs ){ |
| 23295 | 23318 | vfsList = pVfs->pNext; |
| 23296 | 23319 | }else if( vfsList ){ |
| | @@ -23317,11 +23340,11 @@ |
| 23317 | 23340 | #endif |
| 23318 | 23341 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 23319 | 23342 | if( pVfs==0 ) return SQLITE_MISUSE_BKPT; |
| 23320 | 23343 | #endif |
| 23321 | 23344 | |
| 23322 | | - MUTEX_LOGIC( mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); ) |
| 23345 | + MUTEX_LOGIC( mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN); ) |
| 23323 | 23346 | sqlite3_mutex_enter(mutex); |
| 23324 | 23347 | vfsUnlink(pVfs); |
| 23325 | 23348 | if( makeDflt || vfsList==0 ){ |
| 23326 | 23349 | pVfs->pNext = vfsList; |
| 23327 | 23350 | vfsList = pVfs; |
| | @@ -23341,11 +23364,11 @@ |
| 23341 | 23364 | MUTEX_LOGIC(sqlite3_mutex *mutex;) |
| 23342 | 23365 | #ifndef SQLITE_OMIT_AUTOINIT |
| 23343 | 23366 | int rc = sqlite3_initialize(); |
| 23344 | 23367 | if( rc ) return rc; |
| 23345 | 23368 | #endif |
| 23346 | | - MUTEX_LOGIC( mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); ) |
| 23369 | + MUTEX_LOGIC( mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN); ) |
| 23347 | 23370 | sqlite3_mutex_enter(mutex); |
| 23348 | 23371 | vfsUnlink(pVfs); |
| 23349 | 23372 | sqlite3_mutex_leave(mutex); |
| 23350 | 23373 | return SQLITE_OK; |
| 23351 | 23374 | } |
| | @@ -24447,20 +24470,20 @@ |
| 24447 | 24470 | sqlite3_mutex *mutex; |
| 24448 | 24471 | |
| 24449 | 24472 | /* |
| 24450 | 24473 | ** The minimum amount of free space that we have seen. |
| 24451 | 24474 | */ |
| 24452 | | - u32 mnMaster; |
| 24475 | + u32 mnKeyBlk; |
| 24453 | 24476 | |
| 24454 | 24477 | /* |
| 24455 | | - ** iMaster is the index of the master chunk. Most new allocations |
| 24456 | | - ** occur off of this chunk. szMaster is the size (in Mem3Blocks) |
| 24457 | | - ** of the current master. iMaster is 0 if there is not master chunk. |
| 24458 | | - ** The master chunk is not in either the aiHash[] or aiSmall[]. |
| 24478 | + ** iKeyBlk is the index of the key chunk. Most new allocations |
| 24479 | + ** occur off of this chunk. szKeyBlk is the size (in Mem3Blocks) |
| 24480 | + ** of the current key chunk. iKeyBlk is 0 if there is no key chunk. |
| 24481 | + ** The key chunk is not in either the aiHash[] or aiSmall[]. |
| 24459 | 24482 | */ |
| 24460 | | - u32 iMaster; |
| 24461 | | - u32 szMaster; |
| 24483 | + u32 iKeyBlk; |
| 24484 | + u32 szKeyBlk; |
| 24462 | 24485 | |
| 24463 | 24486 | /* |
| 24464 | 24487 | ** Array of lists of free blocks according to the block size |
| 24465 | 24488 | ** for smaller chunks, or a hash on the block size for larger |
| 24466 | 24489 | ** chunks. |
| | @@ -24592,38 +24615,38 @@ |
| 24592 | 24615 | mem3.aPool[i+nBlock-1].u.hdr.size4x |= 2; |
| 24593 | 24616 | return &mem3.aPool[i]; |
| 24594 | 24617 | } |
| 24595 | 24618 | |
| 24596 | 24619 | /* |
| 24597 | | -** Carve a piece off of the end of the mem3.iMaster free chunk. |
| 24598 | | -** Return a pointer to the new allocation. Or, if the master chunk |
| 24620 | +** Carve a piece off of the end of the mem3.iKeyBlk free chunk. |
| 24621 | +** Return a pointer to the new allocation. Or, if the key chunk |
| 24599 | 24622 | ** is not large enough, return 0. |
| 24600 | 24623 | */ |
| 24601 | | -static void *memsys3FromMaster(u32 nBlock){ |
| 24624 | +static void *memsys3FromKeyBlk(u32 nBlock){ |
| 24602 | 24625 | assert( sqlite3_mutex_held(mem3.mutex) ); |
| 24603 | | - assert( mem3.szMaster>=nBlock ); |
| 24604 | | - if( nBlock>=mem3.szMaster-1 ){ |
| 24605 | | - /* Use the entire master */ |
| 24606 | | - void *p = memsys3Checkout(mem3.iMaster, mem3.szMaster); |
| 24607 | | - mem3.iMaster = 0; |
| 24608 | | - mem3.szMaster = 0; |
| 24609 | | - mem3.mnMaster = 0; |
| 24626 | + assert( mem3.szKeyBlk>=nBlock ); |
| 24627 | + if( nBlock>=mem3.szKeyBlk-1 ){ |
| 24628 | + /* Use the entire key chunk */ |
| 24629 | + void *p = memsys3Checkout(mem3.iKeyBlk, mem3.szKeyBlk); |
| 24630 | + mem3.iKeyBlk = 0; |
| 24631 | + mem3.szKeyBlk = 0; |
| 24632 | + mem3.mnKeyBlk = 0; |
| 24610 | 24633 | return p; |
| 24611 | 24634 | }else{ |
| 24612 | | - /* Split the master block. Return the tail. */ |
| 24635 | + /* Split the key block. Return the tail. */ |
| 24613 | 24636 | u32 newi, x; |
| 24614 | | - newi = mem3.iMaster + mem3.szMaster - nBlock; |
| 24615 | | - assert( newi > mem3.iMaster+1 ); |
| 24616 | | - mem3.aPool[mem3.iMaster+mem3.szMaster-1].u.hdr.prevSize = nBlock; |
| 24617 | | - mem3.aPool[mem3.iMaster+mem3.szMaster-1].u.hdr.size4x |= 2; |
| 24637 | + newi = mem3.iKeyBlk + mem3.szKeyBlk - nBlock; |
| 24638 | + assert( newi > mem3.iKeyBlk+1 ); |
| 24639 | + mem3.aPool[mem3.iKeyBlk+mem3.szKeyBlk-1].u.hdr.prevSize = nBlock; |
| 24640 | + mem3.aPool[mem3.iKeyBlk+mem3.szKeyBlk-1].u.hdr.size4x |= 2; |
| 24618 | 24641 | mem3.aPool[newi-1].u.hdr.size4x = nBlock*4 + 1; |
| 24619 | | - mem3.szMaster -= nBlock; |
| 24620 | | - mem3.aPool[newi-1].u.hdr.prevSize = mem3.szMaster; |
| 24621 | | - x = mem3.aPool[mem3.iMaster-1].u.hdr.size4x & 2; |
| 24622 | | - mem3.aPool[mem3.iMaster-1].u.hdr.size4x = mem3.szMaster*4 | x; |
| 24623 | | - if( mem3.szMaster < mem3.mnMaster ){ |
| 24624 | | - mem3.mnMaster = mem3.szMaster; |
| 24642 | + mem3.szKeyBlk -= nBlock; |
| 24643 | + mem3.aPool[newi-1].u.hdr.prevSize = mem3.szKeyBlk; |
| 24644 | + x = mem3.aPool[mem3.iKeyBlk-1].u.hdr.size4x & 2; |
| 24645 | + mem3.aPool[mem3.iKeyBlk-1].u.hdr.size4x = mem3.szKeyBlk*4 | x; |
| 24646 | + if( mem3.szKeyBlk < mem3.mnKeyBlk ){ |
| 24647 | + mem3.mnKeyBlk = mem3.szKeyBlk; |
| 24625 | 24648 | } |
| 24626 | 24649 | return (void*)&mem3.aPool[newi]; |
| 24627 | 24650 | } |
| 24628 | 24651 | } |
| 24629 | 24652 | |
| | @@ -24633,17 +24656,17 @@ |
| 24633 | 24656 | ** mem3.aiSmall[] or mem3.aiHash[]. |
| 24634 | 24657 | ** |
| 24635 | 24658 | ** This routine examines all entries on the given list and tries |
| 24636 | 24659 | ** to coalesce each entries with adjacent free chunks. |
| 24637 | 24660 | ** |
| 24638 | | -** If it sees a chunk that is larger than mem3.iMaster, it replaces |
| 24639 | | -** the current mem3.iMaster with the new larger chunk. In order for |
| 24640 | | -** this mem3.iMaster replacement to work, the master chunk must be |
| 24661 | +** If it sees a chunk that is larger than mem3.iKeyBlk, it replaces |
| 24662 | +** the current mem3.iKeyBlk with the new larger chunk. In order for |
| 24663 | +** this mem3.iKeyBlk replacement to work, the key chunk must be |
| 24641 | 24664 | ** linked into the hash tables. That is not the normal state of |
| 24642 | | -** affairs, of course. The calling routine must link the master |
| 24665 | +** affairs, of course. The calling routine must link the key |
| 24643 | 24666 | ** chunk before invoking this routine, then must unlink the (possibly |
| 24644 | | -** changed) master chunk once this routine has finished. |
| 24667 | +** changed) key chunk once this routine has finished. |
| 24645 | 24668 | */ |
| 24646 | 24669 | static void memsys3Merge(u32 *pRoot){ |
| 24647 | 24670 | u32 iNext, prev, size, i, x; |
| 24648 | 24671 | |
| 24649 | 24672 | assert( sqlite3_mutex_held(mem3.mutex) ); |
| | @@ -24666,13 +24689,13 @@ |
| 24666 | 24689 | memsys3Link(prev); |
| 24667 | 24690 | i = prev; |
| 24668 | 24691 | }else{ |
| 24669 | 24692 | size /= 4; |
| 24670 | 24693 | } |
| 24671 | | - if( size>mem3.szMaster ){ |
| 24672 | | - mem3.iMaster = i; |
| 24673 | | - mem3.szMaster = size; |
| 24694 | + if( size>mem3.szKeyBlk ){ |
| 24695 | + mem3.iKeyBlk = i; |
| 24696 | + mem3.szKeyBlk = size; |
| 24674 | 24697 | } |
| 24675 | 24698 | } |
| 24676 | 24699 | } |
| 24677 | 24700 | |
| 24678 | 24701 | /* |
| | @@ -24717,41 +24740,41 @@ |
| 24717 | 24740 | } |
| 24718 | 24741 | } |
| 24719 | 24742 | |
| 24720 | 24743 | /* STEP 2: |
| 24721 | 24744 | ** Try to satisfy the allocation by carving a piece off of the end |
| 24722 | | - ** of the master chunk. This step usually works if step 1 fails. |
| 24745 | + ** of the key chunk. This step usually works if step 1 fails. |
| 24723 | 24746 | */ |
| 24724 | | - if( mem3.szMaster>=nBlock ){ |
| 24725 | | - return memsys3FromMaster(nBlock); |
| 24747 | + if( mem3.szKeyBlk>=nBlock ){ |
| 24748 | + return memsys3FromKeyBlk(nBlock); |
| 24726 | 24749 | } |
| 24727 | 24750 | |
| 24728 | 24751 | |
| 24729 | 24752 | /* STEP 3: |
| 24730 | 24753 | ** Loop through the entire memory pool. Coalesce adjacent free |
| 24731 | | - ** chunks. Recompute the master chunk as the largest free chunk. |
| 24754 | + ** chunks. Recompute the key chunk as the largest free chunk. |
| 24732 | 24755 | ** Then try again to satisfy the allocation by carving a piece off |
| 24733 | | - ** of the end of the master chunk. This step happens very |
| 24756 | + ** of the end of the key chunk. This step happens very |
| 24734 | 24757 | ** rarely (we hope!) |
| 24735 | 24758 | */ |
| 24736 | 24759 | for(toFree=nBlock*16; toFree<(mem3.nPool*16); toFree *= 2){ |
| 24737 | 24760 | memsys3OutOfMemory(toFree); |
| 24738 | | - if( mem3.iMaster ){ |
| 24739 | | - memsys3Link(mem3.iMaster); |
| 24740 | | - mem3.iMaster = 0; |
| 24741 | | - mem3.szMaster = 0; |
| 24761 | + if( mem3.iKeyBlk ){ |
| 24762 | + memsys3Link(mem3.iKeyBlk); |
| 24763 | + mem3.iKeyBlk = 0; |
| 24764 | + mem3.szKeyBlk = 0; |
| 24742 | 24765 | } |
| 24743 | 24766 | for(i=0; i<N_HASH; i++){ |
| 24744 | 24767 | memsys3Merge(&mem3.aiHash[i]); |
| 24745 | 24768 | } |
| 24746 | 24769 | for(i=0; i<MX_SMALL-1; i++){ |
| 24747 | 24770 | memsys3Merge(&mem3.aiSmall[i]); |
| 24748 | 24771 | } |
| 24749 | | - if( mem3.szMaster ){ |
| 24750 | | - memsys3Unlink(mem3.iMaster); |
| 24751 | | - if( mem3.szMaster>=nBlock ){ |
| 24752 | | - return memsys3FromMaster(nBlock); |
| 24772 | + if( mem3.szKeyBlk ){ |
| 24773 | + memsys3Unlink(mem3.iKeyBlk); |
| 24774 | + if( mem3.szKeyBlk>=nBlock ){ |
| 24775 | + return memsys3FromKeyBlk(nBlock); |
| 24753 | 24776 | } |
| 24754 | 24777 | } |
| 24755 | 24778 | } |
| 24756 | 24779 | |
| 24757 | 24780 | /* If none of the above worked, then we fail. */ |
| | @@ -24777,27 +24800,27 @@ |
| 24777 | 24800 | mem3.aPool[i-1].u.hdr.size4x &= ~1; |
| 24778 | 24801 | mem3.aPool[i+size-1].u.hdr.prevSize = size; |
| 24779 | 24802 | mem3.aPool[i+size-1].u.hdr.size4x &= ~2; |
| 24780 | 24803 | memsys3Link(i); |
| 24781 | 24804 | |
| 24782 | | - /* Try to expand the master using the newly freed chunk */ |
| 24783 | | - if( mem3.iMaster ){ |
| 24784 | | - while( (mem3.aPool[mem3.iMaster-1].u.hdr.size4x&2)==0 ){ |
| 24785 | | - size = mem3.aPool[mem3.iMaster-1].u.hdr.prevSize; |
| 24786 | | - mem3.iMaster -= size; |
| 24787 | | - mem3.szMaster += size; |
| 24788 | | - memsys3Unlink(mem3.iMaster); |
| 24789 | | - x = mem3.aPool[mem3.iMaster-1].u.hdr.size4x & 2; |
| 24790 | | - mem3.aPool[mem3.iMaster-1].u.hdr.size4x = mem3.szMaster*4 | x; |
| 24791 | | - mem3.aPool[mem3.iMaster+mem3.szMaster-1].u.hdr.prevSize = mem3.szMaster; |
| 24792 | | - } |
| 24793 | | - x = mem3.aPool[mem3.iMaster-1].u.hdr.size4x & 2; |
| 24794 | | - while( (mem3.aPool[mem3.iMaster+mem3.szMaster-1].u.hdr.size4x&1)==0 ){ |
| 24795 | | - memsys3Unlink(mem3.iMaster+mem3.szMaster); |
| 24796 | | - mem3.szMaster += mem3.aPool[mem3.iMaster+mem3.szMaster-1].u.hdr.size4x/4; |
| 24797 | | - mem3.aPool[mem3.iMaster-1].u.hdr.size4x = mem3.szMaster*4 | x; |
| 24798 | | - mem3.aPool[mem3.iMaster+mem3.szMaster-1].u.hdr.prevSize = mem3.szMaster; |
| 24805 | + /* Try to expand the key using the newly freed chunk */ |
| 24806 | + if( mem3.iKeyBlk ){ |
| 24807 | + while( (mem3.aPool[mem3.iKeyBlk-1].u.hdr.size4x&2)==0 ){ |
| 24808 | + size = mem3.aPool[mem3.iKeyBlk-1].u.hdr.prevSize; |
| 24809 | + mem3.iKeyBlk -= size; |
| 24810 | + mem3.szKeyBlk += size; |
| 24811 | + memsys3Unlink(mem3.iKeyBlk); |
| 24812 | + x = mem3.aPool[mem3.iKeyBlk-1].u.hdr.size4x & 2; |
| 24813 | + mem3.aPool[mem3.iKeyBlk-1].u.hdr.size4x = mem3.szKeyBlk*4 | x; |
| 24814 | + mem3.aPool[mem3.iKeyBlk+mem3.szKeyBlk-1].u.hdr.prevSize = mem3.szKeyBlk; |
| 24815 | + } |
| 24816 | + x = mem3.aPool[mem3.iKeyBlk-1].u.hdr.size4x & 2; |
| 24817 | + while( (mem3.aPool[mem3.iKeyBlk+mem3.szKeyBlk-1].u.hdr.size4x&1)==0 ){ |
| 24818 | + memsys3Unlink(mem3.iKeyBlk+mem3.szKeyBlk); |
| 24819 | + mem3.szKeyBlk += mem3.aPool[mem3.iKeyBlk+mem3.szKeyBlk-1].u.hdr.size4x/4; |
| 24820 | + mem3.aPool[mem3.iKeyBlk-1].u.hdr.size4x = mem3.szKeyBlk*4 | x; |
| 24821 | + mem3.aPool[mem3.iKeyBlk+mem3.szKeyBlk-1].u.hdr.prevSize = mem3.szKeyBlk; |
| 24799 | 24822 | } |
| 24800 | 24823 | } |
| 24801 | 24824 | } |
| 24802 | 24825 | |
| 24803 | 24826 | /* |
| | @@ -24889,15 +24912,15 @@ |
| 24889 | 24912 | /* Store a pointer to the memory block in global structure mem3. */ |
| 24890 | 24913 | assert( sizeof(Mem3Block)==8 ); |
| 24891 | 24914 | mem3.aPool = (Mem3Block *)sqlite3GlobalConfig.pHeap; |
| 24892 | 24915 | mem3.nPool = (sqlite3GlobalConfig.nHeap / sizeof(Mem3Block)) - 2; |
| 24893 | 24916 | |
| 24894 | | - /* Initialize the master block. */ |
| 24895 | | - mem3.szMaster = mem3.nPool; |
| 24896 | | - mem3.mnMaster = mem3.szMaster; |
| 24897 | | - mem3.iMaster = 1; |
| 24898 | | - mem3.aPool[0].u.hdr.size4x = (mem3.szMaster<<2) + 2; |
| 24917 | + /* Initialize the key block. */ |
| 24918 | + mem3.szKeyBlk = mem3.nPool; |
| 24919 | + mem3.mnKeyBlk = mem3.szKeyBlk; |
| 24920 | + mem3.iKeyBlk = 1; |
| 24921 | + mem3.aPool[0].u.hdr.size4x = (mem3.szKeyBlk<<2) + 2; |
| 24899 | 24922 | mem3.aPool[mem3.nPool].u.hdr.prevSize = mem3.nPool; |
| 24900 | 24923 | mem3.aPool[mem3.nPool].u.hdr.size4x = 1; |
| 24901 | 24924 | |
| 24902 | 24925 | return SQLITE_OK; |
| 24903 | 24926 | } |
| | @@ -24953,11 +24976,11 @@ |
| 24953 | 24976 | } |
| 24954 | 24977 | if( size&1 ){ |
| 24955 | 24978 | fprintf(out, "%p %6d bytes checked out\n", &mem3.aPool[i], (size/4)*8-8); |
| 24956 | 24979 | }else{ |
| 24957 | 24980 | fprintf(out, "%p %6d bytes free%s\n", &mem3.aPool[i], (size/4)*8-8, |
| 24958 | | - i==mem3.iMaster ? " **master**" : ""); |
| 24981 | + i==mem3.iKeyBlk ? " **key**" : ""); |
| 24959 | 24982 | } |
| 24960 | 24983 | } |
| 24961 | 24984 | for(i=0; i<MX_SMALL-1; i++){ |
| 24962 | 24985 | if( mem3.aiSmall[i]==0 ) continue; |
| 24963 | 24986 | fprintf(out, "small(%2d):", i); |
| | @@ -24974,13 +24997,13 @@ |
| 24974 | 24997 | fprintf(out, " %p(%d)", &mem3.aPool[j], |
| 24975 | 24998 | (mem3.aPool[j-1].u.hdr.size4x/4)*8-8); |
| 24976 | 24999 | } |
| 24977 | 25000 | fprintf(out, "\n"); |
| 24978 | 25001 | } |
| 24979 | | - fprintf(out, "master=%d\n", mem3.iMaster); |
| 24980 | | - fprintf(out, "nowUsed=%d\n", mem3.nPool*8 - mem3.szMaster*8); |
| 24981 | | - fprintf(out, "mxUsed=%d\n", mem3.nPool*8 - mem3.mnMaster*8); |
| 25002 | + fprintf(out, "key=%d\n", mem3.iKeyBlk); |
| 25003 | + fprintf(out, "nowUsed=%d\n", mem3.nPool*8 - mem3.szKeyBlk*8); |
| 25004 | + fprintf(out, "mxUsed=%d\n", mem3.nPool*8 - mem3.mnKeyBlk*8); |
| 24982 | 25005 | sqlite3_mutex_leave(mem3.mutex); |
| 24983 | 25006 | if( out==stdout ){ |
| 24984 | 25007 | fflush(stdout); |
| 24985 | 25008 | }else{ |
| 24986 | 25009 | fclose(out); |
| | @@ -26292,11 +26315,11 @@ |
| 26292 | 26315 | ** to sqlite3_mutex_alloc() is one of these integer constants: |
| 26293 | 26316 | ** |
| 26294 | 26317 | ** <ul> |
| 26295 | 26318 | ** <li> SQLITE_MUTEX_FAST |
| 26296 | 26319 | ** <li> SQLITE_MUTEX_RECURSIVE |
| 26297 | | -** <li> SQLITE_MUTEX_STATIC_MASTER |
| 26320 | +** <li> SQLITE_MUTEX_STATIC_MAIN |
| 26298 | 26321 | ** <li> SQLITE_MUTEX_STATIC_MEM |
| 26299 | 26322 | ** <li> SQLITE_MUTEX_STATIC_OPEN |
| 26300 | 26323 | ** <li> SQLITE_MUTEX_STATIC_PRNG |
| 26301 | 26324 | ** <li> SQLITE_MUTEX_STATIC_LRU |
| 26302 | 26325 | ** <li> SQLITE_MUTEX_STATIC_PMEM |
| | @@ -27038,11 +27061,11 @@ |
| 27038 | 27061 | ** to sqlite3_mutex_alloc() is one of these integer constants: |
| 27039 | 27062 | ** |
| 27040 | 27063 | ** <ul> |
| 27041 | 27064 | ** <li> SQLITE_MUTEX_FAST |
| 27042 | 27065 | ** <li> SQLITE_MUTEX_RECURSIVE |
| 27043 | | -** <li> SQLITE_MUTEX_STATIC_MASTER |
| 27066 | +** <li> SQLITE_MUTEX_STATIC_MAIN |
| 27044 | 27067 | ** <li> SQLITE_MUTEX_STATIC_MEM |
| 27045 | 27068 | ** <li> SQLITE_MUTEX_STATIC_OPEN |
| 27046 | 27069 | ** <li> SQLITE_MUTEX_STATIC_PRNG |
| 27047 | 27070 | ** <li> SQLITE_MUTEX_STATIC_LRU |
| 27048 | 27071 | ** <li> SQLITE_MUTEX_STATIC_PMEM |
| | @@ -29990,12 +30013,13 @@ |
| 29990 | 30013 | #else |
| 29991 | 30014 | pWin = 0; |
| 29992 | 30015 | #endif |
| 29993 | 30016 | } |
| 29994 | 30017 | if( pExpr->op==TK_AGG_FUNCTION ){ |
| 29995 | | - sqlite3TreeViewLine(pView, "AGG_FUNCTION%d %Q%s iAgg=%d agg=%p", |
| 30018 | + sqlite3TreeViewLine(pView, "AGG_FUNCTION%d %Q%s agg=%d[%d]/%p", |
| 29996 | 30019 | pExpr->op2, pExpr->u.zToken, zFlgs, |
| 30020 | + pExpr->pAggInfo ? pExpr->pAggInfo->selId : 0, |
| 29997 | 30021 | pExpr->iAgg, pExpr->pAggInfo); |
| 29998 | 30022 | }else if( pExpr->op2!=0 ){ |
| 29999 | 30023 | const char *zOp2; |
| 30000 | 30024 | char zBuf[8]; |
| 30001 | 30025 | sqlite3_snprintf(sizeof(zBuf),zBuf,"0x%02x",pExpr->op2); |
| | @@ -36800,11 +36824,11 @@ |
| 36800 | 36824 | int got; |
| 36801 | 36825 | assert( id ); |
| 36802 | 36826 | assert( offset>=0 ); |
| 36803 | 36827 | assert( amt>0 ); |
| 36804 | 36828 | |
| 36805 | | - /* If this is a database file (not a journal, master-journal or temp |
| 36829 | + /* If this is a database file (not a journal, super-journal or temp |
| 36806 | 36830 | ** file), the bytes in the locking range should never be read or written. */ |
| 36807 | 36831 | #if 0 |
| 36808 | 36832 | assert( pFile->pPreallocatedUnused==0 |
| 36809 | 36833 | || offset>=PENDING_BYTE+512 |
| 36810 | 36834 | || offset+amt<=PENDING_BYTE |
| | @@ -36913,11 +36937,11 @@ |
| 36913 | 36937 | unixFile *pFile = (unixFile*)id; |
| 36914 | 36938 | int wrote = 0; |
| 36915 | 36939 | assert( id ); |
| 36916 | 36940 | assert( amt>0 ); |
| 36917 | 36941 | |
| 36918 | | - /* If this is a database file (not a journal, master-journal or temp |
| 36942 | + /* If this is a database file (not a journal, super-journal or temp |
| 36919 | 36943 | ** file), the bytes in the locking range should never be read or written. */ |
| 36920 | 36944 | #if 0 |
| 36921 | 36945 | assert( pFile->pPreallocatedUnused==0 |
| 36922 | 36946 | || offset>=PENDING_BYTE+512 |
| 36923 | 36947 | || offset+amt<=PENDING_BYTE |
| | @@ -39233,11 +39257,11 @@ |
| 39233 | 39257 | static int proxyTransformUnixFile(unixFile*, const char*); |
| 39234 | 39258 | #endif |
| 39235 | 39259 | |
| 39236 | 39260 | /* |
| 39237 | 39261 | ** Search for an unused file descriptor that was opened on the database |
| 39238 | | -** file (not a journal or master-journal file) identified by pathname |
| 39262 | +** file (not a journal or super-journal file) identified by pathname |
| 39239 | 39263 | ** zPath with SQLITE_OPEN_XXX flags matching those passed as the second |
| 39240 | 39264 | ** argument to this function. |
| 39241 | 39265 | ** |
| 39242 | 39266 | ** Such a file descriptor may exist if a database connection was closed |
| 39243 | 39267 | ** but the associated file descriptor could not be closed because some |
| | @@ -39367,11 +39391,11 @@ |
| 39367 | 39391 | */ |
| 39368 | 39392 | nDb = sqlite3Strlen30(zPath) - 1; |
| 39369 | 39393 | while( zPath[nDb]!='-' ){ |
| 39370 | 39394 | /* In normal operation, the journal file name will always contain |
| 39371 | 39395 | ** a '-' character. However in 8+3 filename mode, or if a corrupt |
| 39372 | | - ** rollback journal specifies a master journal with a goofy name, then |
| 39396 | + ** rollback journal specifies a super-journal with a goofy name, then |
| 39373 | 39397 | ** the '-' might be missing. */ |
| 39374 | 39398 | if( nDb==0 || zPath[nDb]=='.' ) return SQLITE_OK; |
| 39375 | 39399 | nDb--; |
| 39376 | 39400 | } |
| 39377 | 39401 | memcpy(zDb, zPath, nDb); |
| | @@ -39440,16 +39464,16 @@ |
| 39440 | 39464 | #endif |
| 39441 | 39465 | #if defined(__APPLE__) || SQLITE_ENABLE_LOCKING_STYLE |
| 39442 | 39466 | struct statfs fsInfo; |
| 39443 | 39467 | #endif |
| 39444 | 39468 | |
| 39445 | | - /* If creating a master or main-file journal, this function will open |
| 39469 | + /* If creating a super- or main-file journal, this function will open |
| 39446 | 39470 | ** a file-descriptor on the directory too. The first time unixSync() |
| 39447 | 39471 | ** is called the directory file descriptor will be fsync()ed and close()d. |
| 39448 | 39472 | */ |
| 39449 | 39473 | int isNewJrnl = (isCreate && ( |
| 39450 | | - eType==SQLITE_OPEN_MASTER_JOURNAL |
| 39474 | + eType==SQLITE_OPEN_SUPER_JOURNAL |
| 39451 | 39475 | || eType==SQLITE_OPEN_MAIN_JOURNAL |
| 39452 | 39476 | || eType==SQLITE_OPEN_WAL |
| 39453 | 39477 | )); |
| 39454 | 39478 | |
| 39455 | 39479 | /* If argument zPath is a NULL pointer, this function is required to open |
| | @@ -39468,21 +39492,21 @@ |
| 39468 | 39492 | assert((isReadonly==0 || isReadWrite==0) && (isReadWrite || isReadonly)); |
| 39469 | 39493 | assert(isCreate==0 || isReadWrite); |
| 39470 | 39494 | assert(isExclusive==0 || isCreate); |
| 39471 | 39495 | assert(isDelete==0 || isCreate); |
| 39472 | 39496 | |
| 39473 | | - /* The main DB, main journal, WAL file and master journal are never |
| 39497 | + /* The main DB, main journal, WAL file and super-journal are never |
| 39474 | 39498 | ** automatically deleted. Nor are they ever temporary files. */ |
| 39475 | 39499 | assert( (!isDelete && zName) || eType!=SQLITE_OPEN_MAIN_DB ); |
| 39476 | 39500 | assert( (!isDelete && zName) || eType!=SQLITE_OPEN_MAIN_JOURNAL ); |
| 39477 | | - assert( (!isDelete && zName) || eType!=SQLITE_OPEN_MASTER_JOURNAL ); |
| 39501 | + assert( (!isDelete && zName) || eType!=SQLITE_OPEN_SUPER_JOURNAL ); |
| 39478 | 39502 | assert( (!isDelete && zName) || eType!=SQLITE_OPEN_WAL ); |
| 39479 | 39503 | |
| 39480 | 39504 | /* Assert that the upper layer has set one of the "file-type" flags. */ |
| 39481 | 39505 | assert( eType==SQLITE_OPEN_MAIN_DB || eType==SQLITE_OPEN_TEMP_DB |
| 39482 | 39506 | || eType==SQLITE_OPEN_MAIN_JOURNAL || eType==SQLITE_OPEN_TEMP_JOURNAL |
| 39483 | | - || eType==SQLITE_OPEN_SUBJOURNAL || eType==SQLITE_OPEN_MASTER_JOURNAL |
| 39507 | + || eType==SQLITE_OPEN_SUBJOURNAL || eType==SQLITE_OPEN_SUPER_JOURNAL |
| 39484 | 39508 | || eType==SQLITE_OPEN_TRANSIENT_DB || eType==SQLITE_OPEN_WAL |
| 39485 | 39509 | ); |
| 39486 | 39510 | |
| 39487 | 39511 | /* Detect a pid change and reset the PRNG. There is a race condition |
| 39488 | 39512 | ** here such that two or more threads all trying to open databases at |
| | @@ -39671,11 +39695,11 @@ |
| 39671 | 39695 | } |
| 39672 | 39696 | } |
| 39673 | 39697 | #endif |
| 39674 | 39698 | |
| 39675 | 39699 | assert( zPath==0 || zPath[0]=='/' |
| 39676 | | - || eType==SQLITE_OPEN_MASTER_JOURNAL || eType==SQLITE_OPEN_MAIN_JOURNAL |
| 39700 | + || eType==SQLITE_OPEN_SUPER_JOURNAL || eType==SQLITE_OPEN_MAIN_JOURNAL |
| 39677 | 39701 | ); |
| 39678 | 39702 | rc = fillInUnixFile(pVfs, fd, pFile, zPath, ctrlFlags); |
| 39679 | 39703 | |
| 39680 | 39704 | open_finished: |
| 39681 | 39705 | if( rc!=SQLITE_OK ){ |
| | @@ -42887,21 +42911,21 @@ |
| 42887 | 42911 | ** the sqlite3_memory_used() function does not return zero, SQLITE_BUSY will |
| 42888 | 42912 | ** be returned and no changes will be made to the Win32 native heap. |
| 42889 | 42913 | */ |
| 42890 | 42914 | SQLITE_API int sqlite3_win32_reset_heap(){ |
| 42891 | 42915 | int rc; |
| 42892 | | - MUTEX_LOGIC( sqlite3_mutex *pMaster; ) /* The main static mutex */ |
| 42916 | + MUTEX_LOGIC( sqlite3_mutex *pMainMtx; ) /* The main static mutex */ |
| 42893 | 42917 | MUTEX_LOGIC( sqlite3_mutex *pMem; ) /* The memsys static mutex */ |
| 42894 | | - MUTEX_LOGIC( pMaster = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); ) |
| 42918 | + MUTEX_LOGIC( pMainMtx = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN); ) |
| 42895 | 42919 | MUTEX_LOGIC( pMem = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM); ) |
| 42896 | | - sqlite3_mutex_enter(pMaster); |
| 42920 | + sqlite3_mutex_enter(pMainMtx); |
| 42897 | 42921 | sqlite3_mutex_enter(pMem); |
| 42898 | 42922 | winMemAssertMagic(); |
| 42899 | 42923 | if( winMemGetHeap()!=NULL && winMemGetOwned() && sqlite3_memory_used()==0 ){ |
| 42900 | 42924 | /* |
| 42901 | 42925 | ** At this point, there should be no outstanding memory allocations on |
| 42902 | | - ** the heap. Also, since both the master and memsys locks are currently |
| 42926 | + ** the heap. Also, since both the main and memsys locks are currently |
| 42903 | 42927 | ** being held by us, no other function (i.e. from another thread) should |
| 42904 | 42928 | ** be able to even access the heap. Attempt to destroy and recreate our |
| 42905 | 42929 | ** isolated Win32 native heap now. |
| 42906 | 42930 | */ |
| 42907 | 42931 | assert( winMemGetHeap()!=NULL ); |
| | @@ -42920,11 +42944,11 @@ |
| 42920 | 42944 | ** The Win32 native heap cannot be modified because it may be in use. |
| 42921 | 42945 | */ |
| 42922 | 42946 | rc = SQLITE_BUSY; |
| 42923 | 42947 | } |
| 42924 | 42948 | sqlite3_mutex_leave(pMem); |
| 42925 | | - sqlite3_mutex_leave(pMaster); |
| 42949 | + sqlite3_mutex_leave(pMainMtx); |
| 42926 | 42950 | return rc; |
| 42927 | 42951 | } |
| 42928 | 42952 | #endif /* SQLITE_WIN32_MALLOC */ |
| 42929 | 42953 | |
| 42930 | 42954 | /* |
| | @@ -46620,11 +46644,11 @@ |
| 46620 | 46644 | int isReadonly = (flags & SQLITE_OPEN_READONLY); |
| 46621 | 46645 | int isReadWrite = (flags & SQLITE_OPEN_READWRITE); |
| 46622 | 46646 | |
| 46623 | 46647 | #ifndef NDEBUG |
| 46624 | 46648 | int isOpenJournal = (isCreate && ( |
| 46625 | | - eType==SQLITE_OPEN_MASTER_JOURNAL |
| 46649 | + eType==SQLITE_OPEN_SUPER_JOURNAL |
| 46626 | 46650 | || eType==SQLITE_OPEN_MAIN_JOURNAL |
| 46627 | 46651 | || eType==SQLITE_OPEN_WAL |
| 46628 | 46652 | )); |
| 46629 | 46653 | #endif |
| 46630 | 46654 | |
| | @@ -46641,21 +46665,21 @@ |
| 46641 | 46665 | assert((isReadonly==0 || isReadWrite==0) && (isReadWrite || isReadonly)); |
| 46642 | 46666 | assert(isCreate==0 || isReadWrite); |
| 46643 | 46667 | assert(isExclusive==0 || isCreate); |
| 46644 | 46668 | assert(isDelete==0 || isCreate); |
| 46645 | 46669 | |
| 46646 | | - /* The main DB, main journal, WAL file and master journal are never |
| 46670 | + /* The main DB, main journal, WAL file and super-journal are never |
| 46647 | 46671 | ** automatically deleted. Nor are they ever temporary files. */ |
| 46648 | 46672 | assert( (!isDelete && zName) || eType!=SQLITE_OPEN_MAIN_DB ); |
| 46649 | 46673 | assert( (!isDelete && zName) || eType!=SQLITE_OPEN_MAIN_JOURNAL ); |
| 46650 | | - assert( (!isDelete && zName) || eType!=SQLITE_OPEN_MASTER_JOURNAL ); |
| 46674 | + assert( (!isDelete && zName) || eType!=SQLITE_OPEN_SUPER_JOURNAL ); |
| 46651 | 46675 | assert( (!isDelete && zName) || eType!=SQLITE_OPEN_WAL ); |
| 46652 | 46676 | |
| 46653 | 46677 | /* Assert that the upper layer has set one of the "file-type" flags. */ |
| 46654 | 46678 | assert( eType==SQLITE_OPEN_MAIN_DB || eType==SQLITE_OPEN_TEMP_DB |
| 46655 | 46679 | || eType==SQLITE_OPEN_MAIN_JOURNAL || eType==SQLITE_OPEN_TEMP_JOURNAL |
| 46656 | | - || eType==SQLITE_OPEN_SUBJOURNAL || eType==SQLITE_OPEN_MASTER_JOURNAL |
| 46680 | + || eType==SQLITE_OPEN_SUBJOURNAL || eType==SQLITE_OPEN_SUPER_JOURNAL |
| 46657 | 46681 | || eType==SQLITE_OPEN_TRANSIENT_DB || eType==SQLITE_OPEN_WAL |
| 46658 | 46682 | ); |
| 46659 | 46683 | |
| 46660 | 46684 | assert( pFile!=0 ); |
| 46661 | 46685 | memset(pFile, 0, sizeof(winFile)); |
| | @@ -48094,11 +48118,11 @@ |
| 48094 | 48118 | p->base.pMethods = &memdb_io_methods; |
| 48095 | 48119 | p->szMax = sqlite3GlobalConfig.mxMemdbSize; |
| 48096 | 48120 | return SQLITE_OK; |
| 48097 | 48121 | } |
| 48098 | 48122 | |
| 48099 | | -#if 0 /* Only used to delete rollback journals, master journals, and WAL |
| 48123 | +#if 0 /* Only used to delete rollback journals, super-journals, and WAL |
| 48100 | 48124 | ** files, none of which exist in memdb. So this routine is never used */ |
| 48101 | 48125 | /* |
| 48102 | 48126 | ** Delete the file located at zPath. If the dirSync argument is true, |
| 48103 | 48127 | ** ensure the file-system modifications are synced to disk before |
| 48104 | 48128 | ** returning. |
| | @@ -51690,12 +51714,12 @@ |
| 51690 | 51714 | ** first 100 bytes of the database file. |
| 51691 | 51715 | ** |
| 51692 | 51716 | ** (5) All writes to the database file are synced prior to the rollback journal |
| 51693 | 51717 | ** being deleted, truncated, or zeroed. |
| 51694 | 51718 | ** |
| 51695 | | -** (6) If a master journal file is used, then all writes to the database file |
| 51696 | | -** are synced prior to the master journal being deleted. |
| 51719 | +** (6) If a super-journal file is used, then all writes to the database file |
| 51720 | +** are synced prior to the super-journal being deleted. |
| 51697 | 51721 | ** |
| 51698 | 51722 | ** Definition: Two databases (or the same database at two points it time) |
| 51699 | 51723 | ** are said to be "logically equivalent" if they give the same answer to |
| 51700 | 51724 | ** all queries. Note in particular the content of freelist leaf |
| 51701 | 51725 | ** pages can be changed arbitrarily without affecting the logical equivalence |
| | @@ -52108,33 +52132,33 @@ |
| 52108 | 52132 | ** |
| 52109 | 52133 | ** This mechanism means that when running in exclusive mode, a connection |
| 52110 | 52134 | ** need only update the change-counter once, for the first transaction |
| 52111 | 52135 | ** committed. |
| 52112 | 52136 | ** |
| 52113 | | -** setMaster |
| 52137 | +** setSuper |
| 52114 | 52138 | ** |
| 52115 | 52139 | ** When PagerCommitPhaseOne() is called to commit a transaction, it may |
| 52116 | | -** (or may not) specify a master-journal name to be written into the |
| 52140 | +** (or may not) specify a super-journal name to be written into the |
| 52117 | 52141 | ** journal file before it is synced to disk. |
| 52118 | 52142 | ** |
| 52119 | | -** Whether or not a journal file contains a master-journal pointer affects |
| 52143 | +** Whether or not a journal file contains a super-journal pointer affects |
| 52120 | 52144 | ** the way in which the journal file is finalized after the transaction is |
| 52121 | 52145 | ** committed or rolled back when running in "journal_mode=PERSIST" mode. |
| 52122 | | -** If a journal file does not contain a master-journal pointer, it is |
| 52146 | +** If a journal file does not contain a super-journal pointer, it is |
| 52123 | 52147 | ** finalized by overwriting the first journal header with zeroes. If |
| 52124 | | -** it does contain a master-journal pointer the journal file is finalized |
| 52148 | +** it does contain a super-journal pointer the journal file is finalized |
| 52125 | 52149 | ** by truncating it to zero bytes, just as if the connection were |
| 52126 | 52150 | ** running in "journal_mode=truncate" mode. |
| 52127 | 52151 | ** |
| 52128 | | -** Journal files that contain master journal pointers cannot be finalized |
| 52152 | +** Journal files that contain super-journal pointers cannot be finalized |
| 52129 | 52153 | ** simply by overwriting the first journal-header with zeroes, as the |
| 52130 | | -** master journal pointer could interfere with hot-journal rollback of any |
| 52154 | +** super-journal pointer could interfere with hot-journal rollback of any |
| 52131 | 52155 | ** subsequently interrupted transaction that reuses the journal file. |
| 52132 | 52156 | ** |
| 52133 | 52157 | ** The flag is cleared as soon as the journal file is finalized (either |
| 52134 | 52158 | ** by PagerCommitPhaseTwo or PagerRollback). If an IO error prevents the |
| 52135 | | -** journal file from being successfully finalized, the setMaster flag |
| 52159 | +** journal file from being successfully finalized, the setSuper flag |
| 52136 | 52160 | ** is cleared anyway (and the pager will move to ERROR state). |
| 52137 | 52161 | ** |
| 52138 | 52162 | ** doNotSpill |
| 52139 | 52163 | ** |
| 52140 | 52164 | ** This variables control the behavior of cache-spills (calls made by |
| | @@ -52262,11 +52286,11 @@ |
| 52262 | 52286 | ** "configuration" of the pager. |
| 52263 | 52287 | */ |
| 52264 | 52288 | u8 eState; /* Pager state (OPEN, READER, WRITER_LOCKED..) */ |
| 52265 | 52289 | u8 eLock; /* Current lock held on database file */ |
| 52266 | 52290 | u8 changeCountDone; /* Set after incrementing the change-counter */ |
| 52267 | | - u8 setMaster; /* True if a m-j name has been written to jrnl */ |
| 52291 | + u8 setSuper; /* Super-jrnl name is written into jrnl */ |
| 52268 | 52292 | u8 doNotSpill; /* Do not spill the cache when non-zero */ |
| 52269 | 52293 | u8 subjInMemory; /* True to use in-memory sub-journals */ |
| 52270 | 52294 | u8 bUseFetch; /* True to use xFetch() */ |
| 52271 | 52295 | u8 hasHeldSharedLock; /* True if a shared lock has ever been held */ |
| 52272 | 52296 | Pgno dbSize; /* Number of pages in the database */ |
| | @@ -52540,11 +52564,11 @@ |
| 52540 | 52564 | assert( p->eLock>=RESERVED_LOCK ); |
| 52541 | 52565 | } |
| 52542 | 52566 | assert( pPager->dbSize==pPager->dbOrigSize ); |
| 52543 | 52567 | assert( pPager->dbOrigSize==pPager->dbFileSize ); |
| 52544 | 52568 | assert( pPager->dbOrigSize==pPager->dbHintSize ); |
| 52545 | | - assert( pPager->setMaster==0 ); |
| 52569 | + assert( pPager->setSuper==0 ); |
| 52546 | 52570 | break; |
| 52547 | 52571 | |
| 52548 | 52572 | case PAGER_WRITER_CACHEMOD: |
| 52549 | 52573 | assert( p->eLock!=UNKNOWN_LOCK ); |
| 52550 | 52574 | assert( pPager->errCode==SQLITE_OK ); |
| | @@ -52894,70 +52918,70 @@ |
| 52894 | 52918 | #define CHECK_PAGE(x) |
| 52895 | 52919 | #endif /* SQLITE_CHECK_PAGES */ |
| 52896 | 52920 | |
| 52897 | 52921 | /* |
| 52898 | 52922 | ** When this is called the journal file for pager pPager must be open. |
| 52899 | | -** This function attempts to read a master journal file name from the |
| 52923 | +** This function attempts to read a super-journal file name from the |
| 52900 | 52924 | ** end of the file and, if successful, copies it into memory supplied |
| 52901 | | -** by the caller. See comments above writeMasterJournal() for the format |
| 52902 | | -** used to store a master journal file name at the end of a journal file. |
| 52925 | +** by the caller. See comments above writeSuperJournal() for the format |
| 52926 | +** used to store a super-journal file name at the end of a journal file. |
| 52903 | 52927 | ** |
| 52904 | | -** zMaster must point to a buffer of at least nMaster bytes allocated by |
| 52928 | +** zSuper must point to a buffer of at least nSuper bytes allocated by |
| 52905 | 52929 | ** the caller. This should be sqlite3_vfs.mxPathname+1 (to ensure there is |
| 52906 | | -** enough space to write the master journal name). If the master journal |
| 52907 | | -** name in the journal is longer than nMaster bytes (including a |
| 52908 | | -** nul-terminator), then this is handled as if no master journal name |
| 52930 | +** enough space to write the super-journal name). If the super-journal |
| 52931 | +** name in the journal is longer than nSuper bytes (including a |
| 52932 | +** nul-terminator), then this is handled as if no super-journal name |
| 52909 | 52933 | ** were present in the journal. |
| 52910 | 52934 | ** |
| 52911 | | -** If a master journal file name is present at the end of the journal |
| 52912 | | -** file, then it is copied into the buffer pointed to by zMaster. A |
| 52913 | | -** nul-terminator byte is appended to the buffer following the master |
| 52914 | | -** journal file name. |
| 52935 | +** If a super-journal file name is present at the end of the journal |
| 52936 | +** file, then it is copied into the buffer pointed to by zSuper. A |
| 52937 | +** nul-terminator byte is appended to the buffer following the |
| 52938 | +** super-journal file name. |
| 52915 | 52939 | ** |
| 52916 | | -** If it is determined that no master journal file name is present |
| 52917 | | -** zMaster[0] is set to 0 and SQLITE_OK returned. |
| 52940 | +** If it is determined that no super-journal file name is present |
| 52941 | +** zSuper[0] is set to 0 and SQLITE_OK returned. |
| 52918 | 52942 | ** |
| 52919 | 52943 | ** If an error occurs while reading from the journal file, an SQLite |
| 52920 | 52944 | ** error code is returned. |
| 52921 | 52945 | */ |
| 52922 | | -static int readMasterJournal(sqlite3_file *pJrnl, char *zMaster, u32 nMaster){ |
| 52946 | +static int readSuperJournal(sqlite3_file *pJrnl, char *zSuper, u32 nSuper){ |
| 52923 | 52947 | int rc; /* Return code */ |
| 52924 | | - u32 len; /* Length in bytes of master journal name */ |
| 52948 | + u32 len; /* Length in bytes of super-journal name */ |
| 52925 | 52949 | i64 szJ; /* Total size in bytes of journal file pJrnl */ |
| 52926 | 52950 | u32 cksum; /* MJ checksum value read from journal */ |
| 52927 | 52951 | u32 u; /* Unsigned loop counter */ |
| 52928 | 52952 | unsigned char aMagic[8]; /* A buffer to hold the magic header */ |
| 52929 | | - zMaster[0] = '\0'; |
| 52953 | + zSuper[0] = '\0'; |
| 52930 | 52954 | |
| 52931 | 52955 | if( SQLITE_OK!=(rc = sqlite3OsFileSize(pJrnl, &szJ)) |
| 52932 | 52956 | || szJ<16 |
| 52933 | 52957 | || SQLITE_OK!=(rc = read32bits(pJrnl, szJ-16, &len)) |
| 52934 | | - || len>=nMaster |
| 52958 | + || len>=nSuper |
| 52935 | 52959 | || len>szJ-16 |
| 52936 | 52960 | || len==0 |
| 52937 | 52961 | || SQLITE_OK!=(rc = read32bits(pJrnl, szJ-12, &cksum)) |
| 52938 | 52962 | || SQLITE_OK!=(rc = sqlite3OsRead(pJrnl, aMagic, 8, szJ-8)) |
| 52939 | 52963 | || memcmp(aMagic, aJournalMagic, 8) |
| 52940 | | - || SQLITE_OK!=(rc = sqlite3OsRead(pJrnl, zMaster, len, szJ-16-len)) |
| 52964 | + || SQLITE_OK!=(rc = sqlite3OsRead(pJrnl, zSuper, len, szJ-16-len)) |
| 52941 | 52965 | ){ |
| 52942 | 52966 | return rc; |
| 52943 | 52967 | } |
| 52944 | 52968 | |
| 52945 | | - /* See if the checksum matches the master journal name */ |
| 52969 | + /* See if the checksum matches the super-journal name */ |
| 52946 | 52970 | for(u=0; u<len; u++){ |
| 52947 | | - cksum -= zMaster[u]; |
| 52971 | + cksum -= zSuper[u]; |
| 52948 | 52972 | } |
| 52949 | 52973 | if( cksum ){ |
| 52950 | 52974 | /* If the checksum doesn't add up, then one or more of the disk sectors |
| 52951 | | - ** containing the master journal filename is corrupted. This means |
| 52975 | + ** containing the super-journal filename is corrupted. This means |
| 52952 | 52976 | ** definitely roll back, so just return SQLITE_OK and report a (nul) |
| 52953 | | - ** master-journal filename. |
| 52977 | + ** super-journal filename. |
| 52954 | 52978 | */ |
| 52955 | 52979 | len = 0; |
| 52956 | 52980 | } |
| 52957 | | - zMaster[len] = '\0'; |
| 52958 | | - zMaster[len+1] = '\0'; |
| 52981 | + zSuper[len] = '\0'; |
| 52982 | + zSuper[len+1] = '\0'; |
| 52959 | 52983 | |
| 52960 | 52984 | return SQLITE_OK; |
| 52961 | 52985 | } |
| 52962 | 52986 | |
| 52963 | 52987 | /* |
| | @@ -53281,80 +53305,80 @@ |
| 53281 | 53305 | return rc; |
| 53282 | 53306 | } |
| 53283 | 53307 | |
| 53284 | 53308 | |
| 53285 | 53309 | /* |
| 53286 | | -** Write the supplied master journal name into the journal file for pager |
| 53287 | | -** pPager at the current location. The master journal name must be the last |
| 53310 | +** Write the supplied super-journal name into the journal file for pager |
| 53311 | +** pPager at the current location. The super-journal name must be the last |
| 53288 | 53312 | ** thing written to a journal file. If the pager is in full-sync mode, the |
| 53289 | 53313 | ** journal file descriptor is advanced to the next sector boundary before |
| 53290 | 53314 | ** anything is written. The format is: |
| 53291 | 53315 | ** |
| 53292 | 53316 | ** + 4 bytes: PAGER_MJ_PGNO. |
| 53293 | | -** + N bytes: Master journal filename in utf-8. |
| 53294 | | -** + 4 bytes: N (length of master journal name in bytes, no nul-terminator). |
| 53295 | | -** + 4 bytes: Master journal name checksum. |
| 53317 | +** + N bytes: super-journal filename in utf-8. |
| 53318 | +** + 4 bytes: N (length of super-journal name in bytes, no nul-terminator). |
| 53319 | +** + 4 bytes: super-journal name checksum. |
| 53296 | 53320 | ** + 8 bytes: aJournalMagic[]. |
| 53297 | 53321 | ** |
| 53298 | | -** The master journal page checksum is the sum of the bytes in the master |
| 53299 | | -** journal name, where each byte is interpreted as a signed 8-bit integer. |
| 53322 | +** The super-journal page checksum is the sum of the bytes in thesuper-journal |
| 53323 | +** name, where each byte is interpreted as a signed 8-bit integer. |
| 53300 | 53324 | ** |
| 53301 | | -** If zMaster is a NULL pointer (occurs for a single database transaction), |
| 53325 | +** If zSuper is a NULL pointer (occurs for a single database transaction), |
| 53302 | 53326 | ** this call is a no-op. |
| 53303 | 53327 | */ |
| 53304 | | -static int writeMasterJournal(Pager *pPager, const char *zMaster){ |
| 53328 | +static int writeSuperJournal(Pager *pPager, const char *zSuper){ |
| 53305 | 53329 | int rc; /* Return code */ |
| 53306 | | - int nMaster; /* Length of string zMaster */ |
| 53330 | + int nSuper; /* Length of string zSuper */ |
| 53307 | 53331 | i64 iHdrOff; /* Offset of header in journal file */ |
| 53308 | 53332 | i64 jrnlSize; /* Size of journal file on disk */ |
| 53309 | | - u32 cksum = 0; /* Checksum of string zMaster */ |
| 53333 | + u32 cksum = 0; /* Checksum of string zSuper */ |
| 53310 | 53334 | |
| 53311 | | - assert( pPager->setMaster==0 ); |
| 53335 | + assert( pPager->setSuper==0 ); |
| 53312 | 53336 | assert( !pagerUseWal(pPager) ); |
| 53313 | 53337 | |
| 53314 | | - if( !zMaster |
| 53338 | + if( !zSuper |
| 53315 | 53339 | || pPager->journalMode==PAGER_JOURNALMODE_MEMORY |
| 53316 | 53340 | || !isOpen(pPager->jfd) |
| 53317 | 53341 | ){ |
| 53318 | 53342 | return SQLITE_OK; |
| 53319 | 53343 | } |
| 53320 | | - pPager->setMaster = 1; |
| 53344 | + pPager->setSuper = 1; |
| 53321 | 53345 | assert( pPager->journalHdr <= pPager->journalOff ); |
| 53322 | 53346 | |
| 53323 | | - /* Calculate the length in bytes and the checksum of zMaster */ |
| 53324 | | - for(nMaster=0; zMaster[nMaster]; nMaster++){ |
| 53325 | | - cksum += zMaster[nMaster]; |
| 53347 | + /* Calculate the length in bytes and the checksum of zSuper */ |
| 53348 | + for(nSuper=0; zSuper[nSuper]; nSuper++){ |
| 53349 | + cksum += zSuper[nSuper]; |
| 53326 | 53350 | } |
| 53327 | 53351 | |
| 53328 | 53352 | /* If in full-sync mode, advance to the next disk sector before writing |
| 53329 | | - ** the master journal name. This is in case the previous page written to |
| 53353 | + ** the super-journal name. This is in case the previous page written to |
| 53330 | 53354 | ** the journal has already been synced. |
| 53331 | 53355 | */ |
| 53332 | 53356 | if( pPager->fullSync ){ |
| 53333 | 53357 | pPager->journalOff = journalHdrOffset(pPager); |
| 53334 | 53358 | } |
| 53335 | 53359 | iHdrOff = pPager->journalOff; |
| 53336 | 53360 | |
| 53337 | | - /* Write the master journal data to the end of the journal file. If |
| 53361 | + /* Write the super-journal data to the end of the journal file. If |
| 53338 | 53362 | ** an error occurs, return the error code to the caller. |
| 53339 | 53363 | */ |
| 53340 | 53364 | if( (0 != (rc = write32bits(pPager->jfd, iHdrOff, PAGER_MJ_PGNO(pPager)))) |
| 53341 | | - || (0 != (rc = sqlite3OsWrite(pPager->jfd, zMaster, nMaster, iHdrOff+4))) |
| 53342 | | - || (0 != (rc = write32bits(pPager->jfd, iHdrOff+4+nMaster, nMaster))) |
| 53343 | | - || (0 != (rc = write32bits(pPager->jfd, iHdrOff+4+nMaster+4, cksum))) |
| 53365 | + || (0 != (rc = sqlite3OsWrite(pPager->jfd, zSuper, nSuper, iHdrOff+4))) |
| 53366 | + || (0 != (rc = write32bits(pPager->jfd, iHdrOff+4+nSuper, nSuper))) |
| 53367 | + || (0 != (rc = write32bits(pPager->jfd, iHdrOff+4+nSuper+4, cksum))) |
| 53344 | 53368 | || (0 != (rc = sqlite3OsWrite(pPager->jfd, aJournalMagic, 8, |
| 53345 | | - iHdrOff+4+nMaster+8))) |
| 53369 | + iHdrOff+4+nSuper+8))) |
| 53346 | 53370 | ){ |
| 53347 | 53371 | return rc; |
| 53348 | 53372 | } |
| 53349 | | - pPager->journalOff += (nMaster+20); |
| 53373 | + pPager->journalOff += (nSuper+20); |
| 53350 | 53374 | |
| 53351 | 53375 | /* If the pager is in peristent-journal mode, then the physical |
| 53352 | | - ** journal-file may extend past the end of the master-journal name |
| 53376 | + ** journal-file may extend past the end of the super-journal name |
| 53353 | 53377 | ** and 8 bytes of magic data just written to the file. This is |
| 53354 | 53378 | ** dangerous because the code to rollback a hot-journal file |
| 53355 | | - ** will not be able to find the master-journal name to determine |
| 53379 | + ** will not be able to find the super-journal name to determine |
| 53356 | 53380 | ** whether or not the journal is hot. |
| 53357 | 53381 | ** |
| 53358 | 53382 | ** Easiest thing to do in this scenario is to truncate the journal |
| 53359 | 53383 | ** file to the required size. |
| 53360 | 53384 | */ |
| | @@ -53511,11 +53535,11 @@ |
| 53511 | 53535 | setGetterMethod(pPager); |
| 53512 | 53536 | } |
| 53513 | 53537 | |
| 53514 | 53538 | pPager->journalOff = 0; |
| 53515 | 53539 | pPager->journalHdr = 0; |
| 53516 | | - pPager->setMaster = 0; |
| 53540 | + pPager->setSuper = 0; |
| 53517 | 53541 | } |
| 53518 | 53542 | |
| 53519 | 53543 | /* |
| 53520 | 53544 | ** This function is called whenever an IOERR or FULL error that requires |
| 53521 | 53545 | ** the pager to transition into the ERROR state may ahve occurred. |
| | @@ -53627,11 +53651,11 @@ |
| 53627 | 53651 | ** tries to unlock the database file if not in exclusive mode. If the |
| 53628 | 53652 | ** unlock operation fails as well, then the first error code related |
| 53629 | 53653 | ** to the first error encountered (the journal finalization one) is |
| 53630 | 53654 | ** returned. |
| 53631 | 53655 | */ |
| 53632 | | -static int pager_end_transaction(Pager *pPager, int hasMaster, int bCommit){ |
| 53656 | +static int pager_end_transaction(Pager *pPager, int hasSuper, int bCommit){ |
| 53633 | 53657 | int rc = SQLITE_OK; /* Error code from journal finalization operation */ |
| 53634 | 53658 | int rc2 = SQLITE_OK; /* Error code from db file unlock operation */ |
| 53635 | 53659 | |
| 53636 | 53660 | /* Do nothing if the pager does not have an open write transaction |
| 53637 | 53661 | ** or at least a RESERVED lock. This function may be called when there |
| | @@ -53679,11 +53703,11 @@ |
| 53679 | 53703 | } |
| 53680 | 53704 | pPager->journalOff = 0; |
| 53681 | 53705 | }else if( pPager->journalMode==PAGER_JOURNALMODE_PERSIST |
| 53682 | 53706 | || (pPager->exclusiveMode && pPager->journalMode!=PAGER_JOURNALMODE_WAL) |
| 53683 | 53707 | ){ |
| 53684 | | - rc = zeroJournalHdr(pPager, hasMaster||pPager->tempFile); |
| 53708 | + rc = zeroJournalHdr(pPager, hasSuper||pPager->tempFile); |
| 53685 | 53709 | pPager->journalOff = 0; |
| 53686 | 53710 | }else{ |
| 53687 | 53711 | /* This branch may be executed with Pager.journalMode==MEMORY if |
| 53688 | 53712 | ** a hot-journal was just rolled back. In this case the journal |
| 53689 | 53713 | ** file should be closed and deleted. If this connection writes to |
| | @@ -53752,11 +53776,11 @@ |
| 53752 | 53776 | && (!pagerUseWal(pPager) || sqlite3WalExclusiveMode(pPager->pWal, 0)) |
| 53753 | 53777 | ){ |
| 53754 | 53778 | rc2 = pagerUnlockDb(pPager, SHARED_LOCK); |
| 53755 | 53779 | } |
| 53756 | 53780 | pPager->eState = PAGER_READER; |
| 53757 | | - pPager->setMaster = 0; |
| 53781 | + pPager->setSuper = 0; |
| 53758 | 53782 | |
| 53759 | 53783 | return (rc==SQLITE_OK?rc2:rc); |
| 53760 | 53784 | } |
| 53761 | 53785 | |
| 53762 | 53786 | /* |
| | @@ -54060,141 +54084,141 @@ |
| 54060 | 54084 | } |
| 54061 | 54085 | return rc; |
| 54062 | 54086 | } |
| 54063 | 54087 | |
| 54064 | 54088 | /* |
| 54065 | | -** Parameter zMaster is the name of a master journal file. A single journal |
| 54066 | | -** file that referred to the master journal file has just been rolled back. |
| 54067 | | -** This routine checks if it is possible to delete the master journal file, |
| 54089 | +** Parameter zSuper is the name of a super-journal file. A single journal |
| 54090 | +** file that referred to the super-journal file has just been rolled back. |
| 54091 | +** This routine checks if it is possible to delete the super-journal file, |
| 54068 | 54092 | ** and does so if it is. |
| 54069 | 54093 | ** |
| 54070 | | -** Argument zMaster may point to Pager.pTmpSpace. So that buffer is not |
| 54094 | +** Argument zSuper may point to Pager.pTmpSpace. So that buffer is not |
| 54071 | 54095 | ** available for use within this function. |
| 54072 | 54096 | ** |
| 54073 | | -** When a master journal file is created, it is populated with the names |
| 54097 | +** When a super-journal file is created, it is populated with the names |
| 54074 | 54098 | ** of all of its child journals, one after another, formatted as utf-8 |
| 54075 | 54099 | ** encoded text. The end of each child journal file is marked with a |
| 54076 | | -** nul-terminator byte (0x00). i.e. the entire contents of a master journal |
| 54100 | +** nul-terminator byte (0x00). i.e. the entire contents of a super-journal |
| 54077 | 54101 | ** file for a transaction involving two databases might be: |
| 54078 | 54102 | ** |
| 54079 | 54103 | ** "/home/bill/a.db-journal\x00/home/bill/b.db-journal\x00" |
| 54080 | 54104 | ** |
| 54081 | | -** A master journal file may only be deleted once all of its child |
| 54105 | +** A super-journal file may only be deleted once all of its child |
| 54082 | 54106 | ** journals have been rolled back. |
| 54083 | 54107 | ** |
| 54084 | | -** This function reads the contents of the master-journal file into |
| 54108 | +** This function reads the contents of the super-journal file into |
| 54085 | 54109 | ** memory and loops through each of the child journal names. For |
| 54086 | 54110 | ** each child journal, it checks if: |
| 54087 | 54111 | ** |
| 54088 | 54112 | ** * if the child journal exists, and if so |
| 54089 | | -** * if the child journal contains a reference to master journal |
| 54090 | | -** file zMaster |
| 54113 | +** * if the child journal contains a reference to super-journal |
| 54114 | +** file zSuper |
| 54091 | 54115 | ** |
| 54092 | 54116 | ** If a child journal can be found that matches both of the criteria |
| 54093 | 54117 | ** above, this function returns without doing anything. Otherwise, if |
| 54094 | | -** no such child journal can be found, file zMaster is deleted from |
| 54118 | +** no such child journal can be found, file zSuper is deleted from |
| 54095 | 54119 | ** the file-system using sqlite3OsDelete(). |
| 54096 | 54120 | ** |
| 54097 | 54121 | ** If an IO error within this function, an error code is returned. This |
| 54098 | 54122 | ** function allocates memory by calling sqlite3Malloc(). If an allocation |
| 54099 | 54123 | ** fails, SQLITE_NOMEM is returned. Otherwise, if no IO or malloc errors |
| 54100 | 54124 | ** occur, SQLITE_OK is returned. |
| 54101 | 54125 | ** |
| 54102 | 54126 | ** TODO: This function allocates a single block of memory to load |
| 54103 | | -** the entire contents of the master journal file. This could be |
| 54127 | +** the entire contents of the super-journal file. This could be |
| 54104 | 54128 | ** a couple of kilobytes or so - potentially larger than the page |
| 54105 | 54129 | ** size. |
| 54106 | 54130 | */ |
| 54107 | | -static int pager_delmaster(Pager *pPager, const char *zMaster){ |
| 54131 | +static int pager_delsuper(Pager *pPager, const char *zSuper){ |
| 54108 | 54132 | sqlite3_vfs *pVfs = pPager->pVfs; |
| 54109 | 54133 | int rc; /* Return code */ |
| 54110 | | - sqlite3_file *pMaster; /* Malloc'd master-journal file descriptor */ |
| 54134 | + sqlite3_file *pSuper; /* Malloc'd super-journal file descriptor */ |
| 54111 | 54135 | sqlite3_file *pJournal; /* Malloc'd child-journal file descriptor */ |
| 54112 | | - char *zMasterJournal = 0; /* Contents of master journal file */ |
| 54113 | | - i64 nMasterJournal; /* Size of master journal file */ |
| 54136 | + char *zSuperJournal = 0; /* Contents of super-journal file */ |
| 54137 | + i64 nSuperJournal; /* Size of super-journal file */ |
| 54114 | 54138 | char *zJournal; /* Pointer to one journal within MJ file */ |
| 54115 | | - char *zMasterPtr; /* Space to hold MJ filename from a journal file */ |
| 54116 | | - int nMasterPtr; /* Amount of space allocated to zMasterPtr[] */ |
| 54117 | | - |
| 54118 | | - /* Allocate space for both the pJournal and pMaster file descriptors. |
| 54119 | | - ** If successful, open the master journal file for reading. |
| 54120 | | - */ |
| 54121 | | - pMaster = (sqlite3_file *)sqlite3MallocZero(pVfs->szOsFile * 2); |
| 54122 | | - pJournal = (sqlite3_file *)(((u8 *)pMaster) + pVfs->szOsFile); |
| 54123 | | - if( !pMaster ){ |
| 54124 | | - rc = SQLITE_NOMEM_BKPT; |
| 54125 | | - }else{ |
| 54126 | | - const int flags = (SQLITE_OPEN_READONLY|SQLITE_OPEN_MASTER_JOURNAL); |
| 54127 | | - rc = sqlite3OsOpen(pVfs, zMaster, pMaster, flags, 0); |
| 54128 | | - } |
| 54129 | | - if( rc!=SQLITE_OK ) goto delmaster_out; |
| 54130 | | - |
| 54131 | | - /* Load the entire master journal file into space obtained from |
| 54132 | | - ** sqlite3_malloc() and pointed to by zMasterJournal. Also obtain |
| 54133 | | - ** sufficient space (in zMasterPtr) to hold the names of master |
| 54134 | | - ** journal files extracted from regular rollback-journals. |
| 54135 | | - */ |
| 54136 | | - rc = sqlite3OsFileSize(pMaster, &nMasterJournal); |
| 54137 | | - if( rc!=SQLITE_OK ) goto delmaster_out; |
| 54138 | | - nMasterPtr = pVfs->mxPathname+1; |
| 54139 | | - zMasterJournal = sqlite3Malloc(nMasterJournal + nMasterPtr + 2); |
| 54140 | | - if( !zMasterJournal ){ |
| 54141 | | - rc = SQLITE_NOMEM_BKPT; |
| 54142 | | - goto delmaster_out; |
| 54143 | | - } |
| 54144 | | - zMasterPtr = &zMasterJournal[nMasterJournal+2]; |
| 54145 | | - rc = sqlite3OsRead(pMaster, zMasterJournal, (int)nMasterJournal, 0); |
| 54146 | | - if( rc!=SQLITE_OK ) goto delmaster_out; |
| 54147 | | - zMasterJournal[nMasterJournal] = 0; |
| 54148 | | - zMasterJournal[nMasterJournal+1] = 0; |
| 54149 | | - |
| 54150 | | - zJournal = zMasterJournal; |
| 54151 | | - while( (zJournal-zMasterJournal)<nMasterJournal ){ |
| 54139 | + char *zSuperPtr; /* Space to hold super-journal filename */ |
| 54140 | + int nSuperPtr; /* Amount of space allocated to zSuperPtr[] */ |
| 54141 | + |
| 54142 | + /* Allocate space for both the pJournal and pSuper file descriptors. |
| 54143 | + ** If successful, open the super-journal file for reading. |
| 54144 | + */ |
| 54145 | + pSuper = (sqlite3_file *)sqlite3MallocZero(pVfs->szOsFile * 2); |
| 54146 | + pJournal = (sqlite3_file *)(((u8 *)pSuper) + pVfs->szOsFile); |
| 54147 | + if( !pSuper ){ |
| 54148 | + rc = SQLITE_NOMEM_BKPT; |
| 54149 | + }else{ |
| 54150 | + const int flags = (SQLITE_OPEN_READONLY|SQLITE_OPEN_SUPER_JOURNAL); |
| 54151 | + rc = sqlite3OsOpen(pVfs, zSuper, pSuper, flags, 0); |
| 54152 | + } |
| 54153 | + if( rc!=SQLITE_OK ) goto delsuper_out; |
| 54154 | + |
| 54155 | + /* Load the entire super-journal file into space obtained from |
| 54156 | + ** sqlite3_malloc() and pointed to by zSuperJournal. Also obtain |
| 54157 | + ** sufficient space (in zSuperPtr) to hold the names of super-journal |
| 54158 | + ** files extracted from regular rollback-journals. |
| 54159 | + */ |
| 54160 | + rc = sqlite3OsFileSize(pSuper, &nSuperJournal); |
| 54161 | + if( rc!=SQLITE_OK ) goto delsuper_out; |
| 54162 | + nSuperPtr = pVfs->mxPathname+1; |
| 54163 | + zSuperJournal = sqlite3Malloc(nSuperJournal + nSuperPtr + 2); |
| 54164 | + if( !zSuperJournal ){ |
| 54165 | + rc = SQLITE_NOMEM_BKPT; |
| 54166 | + goto delsuper_out; |
| 54167 | + } |
| 54168 | + zSuperPtr = &zSuperJournal[nSuperJournal+2]; |
| 54169 | + rc = sqlite3OsRead(pSuper, zSuperJournal, (int)nSuperJournal, 0); |
| 54170 | + if( rc!=SQLITE_OK ) goto delsuper_out; |
| 54171 | + zSuperJournal[nSuperJournal] = 0; |
| 54172 | + zSuperJournal[nSuperJournal+1] = 0; |
| 54173 | + |
| 54174 | + zJournal = zSuperJournal; |
| 54175 | + while( (zJournal-zSuperJournal)<nSuperJournal ){ |
| 54152 | 54176 | int exists; |
| 54153 | 54177 | rc = sqlite3OsAccess(pVfs, zJournal, SQLITE_ACCESS_EXISTS, &exists); |
| 54154 | 54178 | if( rc!=SQLITE_OK ){ |
| 54155 | | - goto delmaster_out; |
| 54179 | + goto delsuper_out; |
| 54156 | 54180 | } |
| 54157 | 54181 | if( exists ){ |
| 54158 | | - /* One of the journals pointed to by the master journal exists. |
| 54159 | | - ** Open it and check if it points at the master journal. If |
| 54160 | | - ** so, return without deleting the master journal file. |
| 54182 | + /* One of the journals pointed to by the super-journal exists. |
| 54183 | + ** Open it and check if it points at the super-journal. If |
| 54184 | + ** so, return without deleting the super-journal file. |
| 54161 | 54185 | ** NB: zJournal is really a MAIN_JOURNAL. But call it a |
| 54162 | | - ** MASTER_JOURNAL here so that the VFS will not send the zJournal |
| 54186 | + ** SUPER_JOURNAL here so that the VFS will not send the zJournal |
| 54163 | 54187 | ** name into sqlite3_database_file_object(). |
| 54164 | 54188 | */ |
| 54165 | 54189 | int c; |
| 54166 | | - int flags = (SQLITE_OPEN_READONLY|SQLITE_OPEN_MASTER_JOURNAL); |
| 54190 | + int flags = (SQLITE_OPEN_READONLY|SQLITE_OPEN_SUPER_JOURNAL); |
| 54167 | 54191 | rc = sqlite3OsOpen(pVfs, zJournal, pJournal, flags, 0); |
| 54168 | 54192 | if( rc!=SQLITE_OK ){ |
| 54169 | | - goto delmaster_out; |
| 54193 | + goto delsuper_out; |
| 54170 | 54194 | } |
| 54171 | 54195 | |
| 54172 | | - rc = readMasterJournal(pJournal, zMasterPtr, nMasterPtr); |
| 54196 | + rc = readSuperJournal(pJournal, zSuperPtr, nSuperPtr); |
| 54173 | 54197 | sqlite3OsClose(pJournal); |
| 54174 | 54198 | if( rc!=SQLITE_OK ){ |
| 54175 | | - goto delmaster_out; |
| 54199 | + goto delsuper_out; |
| 54176 | 54200 | } |
| 54177 | 54201 | |
| 54178 | | - c = zMasterPtr[0]!=0 && strcmp(zMasterPtr, zMaster)==0; |
| 54202 | + c = zSuperPtr[0]!=0 && strcmp(zSuperPtr, zSuper)==0; |
| 54179 | 54203 | if( c ){ |
| 54180 | | - /* We have a match. Do not delete the master journal file. */ |
| 54181 | | - goto delmaster_out; |
| 54204 | + /* We have a match. Do not delete the super-journal file. */ |
| 54205 | + goto delsuper_out; |
| 54182 | 54206 | } |
| 54183 | 54207 | } |
| 54184 | 54208 | zJournal += (sqlite3Strlen30(zJournal)+1); |
| 54185 | 54209 | } |
| 54186 | 54210 | |
| 54187 | | - sqlite3OsClose(pMaster); |
| 54188 | | - rc = sqlite3OsDelete(pVfs, zMaster, 0); |
| 54211 | + sqlite3OsClose(pSuper); |
| 54212 | + rc = sqlite3OsDelete(pVfs, zSuper, 0); |
| 54189 | 54213 | |
| 54190 | | -delmaster_out: |
| 54191 | | - sqlite3_free(zMasterJournal); |
| 54192 | | - if( pMaster ){ |
| 54193 | | - sqlite3OsClose(pMaster); |
| 54214 | +delsuper_out: |
| 54215 | + sqlite3_free(zSuperJournal); |
| 54216 | + if( pSuper ){ |
| 54217 | + sqlite3OsClose(pSuper); |
| 54194 | 54218 | assert( !isOpen(pJournal) ); |
| 54195 | | - sqlite3_free(pMaster); |
| 54219 | + sqlite3_free(pSuper); |
| 54196 | 54220 | } |
| 54197 | 54221 | return rc; |
| 54198 | 54222 | } |
| 54199 | 54223 | |
| 54200 | 54224 | |
| | @@ -54268,11 +54292,11 @@ |
| 54268 | 54292 | /* |
| 54269 | 54293 | ** Set the value of the Pager.sectorSize variable for the given |
| 54270 | 54294 | ** pager based on the value returned by the xSectorSize method |
| 54271 | 54295 | ** of the open database file. The sector size will be used |
| 54272 | 54296 | ** to determine the size and alignment of journal header and |
| 54273 | | -** master journal pointers within created journal files. |
| 54297 | +** super-journal pointers within created journal files. |
| 54274 | 54298 | ** |
| 54275 | 54299 | ** For temporary files the effective sector size is always 512 bytes. |
| 54276 | 54300 | ** |
| 54277 | 54301 | ** Otherwise, for non-temporary files, the effective sector size is |
| 54278 | 54302 | ** the value returned by the xSectorSize() method rounded up to 32 if |
| | @@ -54367,11 +54391,11 @@ |
| 54367 | 54391 | u32 nRec; /* Number of Records in the journal */ |
| 54368 | 54392 | u32 u; /* Unsigned loop counter */ |
| 54369 | 54393 | Pgno mxPg = 0; /* Size of the original file in pages */ |
| 54370 | 54394 | int rc; /* Result code of a subroutine */ |
| 54371 | 54395 | int res = 1; /* Value returned by sqlite3OsAccess() */ |
| 54372 | | - char *zMaster = 0; /* Name of master journal file if any */ |
| 54396 | + char *zSuper = 0; /* Name of super-journal file if any */ |
| 54373 | 54397 | int needPagerReset; /* True to reset page prior to first page rollback */ |
| 54374 | 54398 | int nPlayback = 0; /* Total number of pages restored from journal */ |
| 54375 | 54399 | u32 savedPageSize = pPager->pageSize; |
| 54376 | 54400 | |
| 54377 | 54401 | /* Figure out how many records are in the journal. Abort early if |
| | @@ -54381,27 +54405,27 @@ |
| 54381 | 54405 | rc = sqlite3OsFileSize(pPager->jfd, &szJ); |
| 54382 | 54406 | if( rc!=SQLITE_OK ){ |
| 54383 | 54407 | goto end_playback; |
| 54384 | 54408 | } |
| 54385 | 54409 | |
| 54386 | | - /* Read the master journal name from the journal, if it is present. |
| 54387 | | - ** If a master journal file name is specified, but the file is not |
| 54410 | + /* Read the super-journal name from the journal, if it is present. |
| 54411 | + ** If a super-journal file name is specified, but the file is not |
| 54388 | 54412 | ** present on disk, then the journal is not hot and does not need to be |
| 54389 | 54413 | ** played back. |
| 54390 | 54414 | ** |
| 54391 | 54415 | ** TODO: Technically the following is an error because it assumes that |
| 54392 | 54416 | ** buffer Pager.pTmpSpace is (mxPathname+1) bytes or larger. i.e. that |
| 54393 | 54417 | ** (pPager->pageSize >= pPager->pVfs->mxPathname+1). Using os_unix.c, |
| 54394 | 54418 | ** mxPathname is 512, which is the same as the minimum allowable value |
| 54395 | 54419 | ** for pageSize. |
| 54396 | 54420 | */ |
| 54397 | | - zMaster = pPager->pTmpSpace; |
| 54398 | | - rc = readMasterJournal(pPager->jfd, zMaster, pPager->pVfs->mxPathname+1); |
| 54399 | | - if( rc==SQLITE_OK && zMaster[0] ){ |
| 54400 | | - rc = sqlite3OsAccess(pVfs, zMaster, SQLITE_ACCESS_EXISTS, &res); |
| 54421 | + zSuper = pPager->pTmpSpace; |
| 54422 | + rc = readSuperJournal(pPager->jfd, zSuper, pPager->pVfs->mxPathname+1); |
| 54423 | + if( rc==SQLITE_OK && zSuper[0] ){ |
| 54424 | + rc = sqlite3OsAccess(pVfs, zSuper, SQLITE_ACCESS_EXISTS, &res); |
| 54401 | 54425 | } |
| 54402 | | - zMaster = 0; |
| 54426 | + zSuper = 0; |
| 54403 | 54427 | if( rc!=SQLITE_OK || !res ){ |
| 54404 | 54428 | goto end_playback; |
| 54405 | 54429 | } |
| 54406 | 54430 | pPager->journalOff = 0; |
| 54407 | 54431 | needPagerReset = isHot; |
| | @@ -54524,28 +54548,28 @@ |
| 54524 | 54548 | ** in case this has happened, clear the changeCountDone flag now. |
| 54525 | 54549 | */ |
| 54526 | 54550 | pPager->changeCountDone = pPager->tempFile; |
| 54527 | 54551 | |
| 54528 | 54552 | if( rc==SQLITE_OK ){ |
| 54529 | | - zMaster = pPager->pTmpSpace; |
| 54530 | | - rc = readMasterJournal(pPager->jfd, zMaster, pPager->pVfs->mxPathname+1); |
| 54553 | + zSuper = pPager->pTmpSpace; |
| 54554 | + rc = readSuperJournal(pPager->jfd, zSuper, pPager->pVfs->mxPathname+1); |
| 54531 | 54555 | testcase( rc!=SQLITE_OK ); |
| 54532 | 54556 | } |
| 54533 | 54557 | if( rc==SQLITE_OK |
| 54534 | 54558 | && (pPager->eState>=PAGER_WRITER_DBMOD || pPager->eState==PAGER_OPEN) |
| 54535 | 54559 | ){ |
| 54536 | 54560 | rc = sqlite3PagerSync(pPager, 0); |
| 54537 | 54561 | } |
| 54538 | 54562 | if( rc==SQLITE_OK ){ |
| 54539 | | - rc = pager_end_transaction(pPager, zMaster[0]!='\0', 0); |
| 54563 | + rc = pager_end_transaction(pPager, zSuper[0]!='\0', 0); |
| 54540 | 54564 | testcase( rc!=SQLITE_OK ); |
| 54541 | 54565 | } |
| 54542 | | - if( rc==SQLITE_OK && zMaster[0] && res ){ |
| 54543 | | - /* If there was a master journal and this routine will return success, |
| 54544 | | - ** see if it is possible to delete the master journal. |
| 54566 | + if( rc==SQLITE_OK && zSuper[0] && res ){ |
| 54567 | + /* If there was a super-journal and this routine will return success, |
| 54568 | + ** see if it is possible to delete the super-journal. |
| 54545 | 54569 | */ |
| 54546 | | - rc = pager_delmaster(pPager, zMaster); |
| 54570 | + rc = pager_delsuper(pPager, zSuper); |
| 54547 | 54571 | testcase( rc!=SQLITE_OK ); |
| 54548 | 54572 | } |
| 54549 | 54573 | if( isHot && nPlayback ){ |
| 54550 | 54574 | sqlite3_log(SQLITE_NOTICE_RECOVER_ROLLBACK, "recovered %d pages from %s", |
| 54551 | 54575 | nPlayback, pPager->zJournal); |
| | @@ -54920,11 +54944,11 @@ |
| 54920 | 54944 | } |
| 54921 | 54945 | #endif |
| 54922 | 54946 | |
| 54923 | 54947 | /* |
| 54924 | 54948 | ** Playback savepoint pSavepoint. Or, if pSavepoint==NULL, then playback |
| 54925 | | -** the entire master journal file. The case pSavepoint==NULL occurs when |
| 54949 | +** the entire super-journal file. The case pSavepoint==NULL occurs when |
| 54926 | 54950 | ** a ROLLBACK TO command is invoked on a SAVEPOINT that is a transaction |
| 54927 | 54951 | ** savepoint. |
| 54928 | 54952 | ** |
| 54929 | 54953 | ** When pSavepoint is not NULL (meaning a non-transaction savepoint is |
| 54930 | 54954 | ** being rolled back), then the rollback consists of up to three stages, |
| | @@ -56660,12 +56684,12 @@ |
| 56660 | 56684 | ** exists, that is probably an old journal left over from a prior |
| 56661 | 56685 | ** database with the same name. In this case the journal file is |
| 56662 | 56686 | ** just deleted using OsDelete, *pExists is set to 0 and SQLITE_OK |
| 56663 | 56687 | ** is returned. |
| 56664 | 56688 | ** |
| 56665 | | -** This routine does not check if there is a master journal filename |
| 56666 | | -** at the end of the file. If there is, and that master journal file |
| 56689 | +** This routine does not check if there is a super-journal filename |
| 56690 | +** at the end of the file. If there is, and that super-journal file |
| 56667 | 56691 | ** does not exist, then the journal file is not really hot. In this |
| 56668 | 56692 | ** case this routine will return a false-positive. The pager_playback() |
| 56669 | 56693 | ** routine will discover that the journal file is not really hot and |
| 56670 | 56694 | ** will not roll it back. |
| 56671 | 56695 | ** |
| | @@ -57406,11 +57430,11 @@ |
| 57406 | 57430 | */ |
| 57407 | 57431 | if( rc==SQLITE_OK ){ |
| 57408 | 57432 | /* TODO: Check if all of these are really required. */ |
| 57409 | 57433 | pPager->nRec = 0; |
| 57410 | 57434 | pPager->journalOff = 0; |
| 57411 | | - pPager->setMaster = 0; |
| 57435 | + pPager->setSuper = 0; |
| 57412 | 57436 | pPager->journalHdr = 0; |
| 57413 | 57437 | rc = writeJournalHdr(pPager); |
| 57414 | 57438 | } |
| 57415 | 57439 | } |
| 57416 | 57440 | |
| | @@ -57918,13 +57942,13 @@ |
| 57918 | 57942 | ** or pages with the Pager.noSync flag set. |
| 57919 | 57943 | ** |
| 57920 | 57944 | ** If successful, or if called on a pager for which it is a no-op, this |
| 57921 | 57945 | ** function returns SQLITE_OK. Otherwise, an IO error code is returned. |
| 57922 | 57946 | */ |
| 57923 | | -SQLITE_PRIVATE int sqlite3PagerSync(Pager *pPager, const char *zMaster){ |
| 57947 | +SQLITE_PRIVATE int sqlite3PagerSync(Pager *pPager, const char *zSuper){ |
| 57924 | 57948 | int rc = SQLITE_OK; |
| 57925 | | - void *pArg = (void*)zMaster; |
| 57949 | + void *pArg = (void*)zSuper; |
| 57926 | 57950 | rc = sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_SYNC, pArg); |
| 57927 | 57951 | if( rc==SQLITE_NOTFOUND ) rc = SQLITE_OK; |
| 57928 | 57952 | if( rc==SQLITE_OK && !pPager->noSync ){ |
| 57929 | 57953 | assert( !MEMDB ); |
| 57930 | 57954 | rc = sqlite3OsSync(pPager->fd, pPager->syncFlags); |
| | @@ -57958,14 +57982,14 @@ |
| 57958 | 57982 | } |
| 57959 | 57983 | return rc; |
| 57960 | 57984 | } |
| 57961 | 57985 | |
| 57962 | 57986 | /* |
| 57963 | | -** Sync the database file for the pager pPager. zMaster points to the name |
| 57964 | | -** of a master journal file that should be written into the individual |
| 57965 | | -** journal file. zMaster may be NULL, which is interpreted as no master |
| 57966 | | -** journal (a single database transaction). |
| 57987 | +** Sync the database file for the pager pPager. zSuper points to the name |
| 57988 | +** of a super-journal file that should be written into the individual |
| 57989 | +** journal file. zSuper may be NULL, which is interpreted as no |
| 57990 | +** super-journal (a single database transaction). |
| 57967 | 57991 | ** |
| 57968 | 57992 | ** This routine ensures that: |
| 57969 | 57993 | ** |
| 57970 | 57994 | ** * The database file change-counter is updated, |
| 57971 | 57995 | ** * the journal is synced (unless the atomic-write optimization is used), |
| | @@ -57973,23 +57997,23 @@ |
| 57973 | 57997 | ** * the database file is truncated (if required), and |
| 57974 | 57998 | ** * the database file synced. |
| 57975 | 57999 | ** |
| 57976 | 58000 | ** The only thing that remains to commit the transaction is to finalize |
| 57977 | 58001 | ** (delete, truncate or zero the first part of) the journal file (or |
| 57978 | | -** delete the master journal file if specified). |
| 58002 | +** delete the super-journal file if specified). |
| 57979 | 58003 | ** |
| 57980 | | -** Note that if zMaster==NULL, this does not overwrite a previous value |
| 58004 | +** Note that if zSuper==NULL, this does not overwrite a previous value |
| 57981 | 58005 | ** passed to an sqlite3PagerCommitPhaseOne() call. |
| 57982 | 58006 | ** |
| 57983 | 58007 | ** If the final parameter - noSync - is true, then the database file itself |
| 57984 | 58008 | ** is not synced. The caller must call sqlite3PagerSync() directly to |
| 57985 | 58009 | ** sync the database file before calling CommitPhaseTwo() to delete the |
| 57986 | 58010 | ** journal file in this case. |
| 57987 | 58011 | */ |
| 57988 | 58012 | SQLITE_PRIVATE int sqlite3PagerCommitPhaseOne( |
| 57989 | 58013 | Pager *pPager, /* Pager object */ |
| 57990 | | - const char *zMaster, /* If not NULL, the master journal name */ |
| 58014 | + const char *zSuper, /* If not NULL, the super-journal name */ |
| 57991 | 58015 | int noSync /* True to omit the xSync on the db file */ |
| 57992 | 58016 | ){ |
| 57993 | 58017 | int rc = SQLITE_OK; /* Return code */ |
| 57994 | 58018 | |
| 57995 | 58019 | assert( pPager->eState==PAGER_WRITER_LOCKED |
| | @@ -58003,12 +58027,12 @@ |
| 58003 | 58027 | if( NEVER(pPager->errCode) ) return pPager->errCode; |
| 58004 | 58028 | |
| 58005 | 58029 | /* Provide the ability to easily simulate an I/O error during testing */ |
| 58006 | 58030 | if( sqlite3FaultSim(400) ) return SQLITE_IOERR; |
| 58007 | 58031 | |
| 58008 | | - PAGERTRACE(("DATABASE SYNC: File=%s zMaster=%s nSize=%d\n", |
| 58009 | | - pPager->zFilename, zMaster, pPager->dbSize)); |
| 58032 | + PAGERTRACE(("DATABASE SYNC: File=%s zSuper=%s nSize=%d\n", |
| 58033 | + pPager->zFilename, zSuper, pPager->dbSize)); |
| 58010 | 58034 | |
| 58011 | 58035 | /* If no database changes have been made, return early. */ |
| 58012 | 58036 | if( pPager->eState<PAGER_WRITER_CACHEMOD ) return SQLITE_OK; |
| 58013 | 58037 | |
| 58014 | 58038 | assert( MEMDB==0 || pPager->tempFile ); |
| | @@ -58043,11 +58067,11 @@ |
| 58043 | 58067 | ** should be used. No rollback journal is created if batch-atomic-write |
| 58044 | 58068 | ** is enabled. |
| 58045 | 58069 | */ |
| 58046 | 58070 | #ifdef SQLITE_ENABLE_BATCH_ATOMIC_WRITE |
| 58047 | 58071 | sqlite3_file *fd = pPager->fd; |
| 58048 | | - int bBatch = zMaster==0 /* An SQLITE_IOCAP_BATCH_ATOMIC commit */ |
| 58072 | + int bBatch = zSuper==0 /* An SQLITE_IOCAP_BATCH_ATOMIC commit */ |
| 58049 | 58073 | && (sqlite3OsDeviceCharacteristics(fd) & SQLITE_IOCAP_BATCH_ATOMIC) |
| 58050 | 58074 | && !pPager->noSync |
| 58051 | 58075 | && sqlite3JournalIsInMemory(pPager->jfd); |
| 58052 | 58076 | #else |
| 58053 | 58077 | # define bBatch 0 |
| | @@ -58081,11 +58105,11 @@ |
| 58081 | 58105 | PgHdr *pPg; |
| 58082 | 58106 | assert( isOpen(pPager->jfd) |
| 58083 | 58107 | || pPager->journalMode==PAGER_JOURNALMODE_OFF |
| 58084 | 58108 | || pPager->journalMode==PAGER_JOURNALMODE_WAL |
| 58085 | 58109 | ); |
| 58086 | | - if( !zMaster && isOpen(pPager->jfd) |
| 58110 | + if( !zSuper && isOpen(pPager->jfd) |
| 58087 | 58111 | && pPager->journalOff==jrnlBufferSize(pPager) |
| 58088 | 58112 | && pPager->dbSize>=pPager->dbOrigSize |
| 58089 | 58113 | && (!(pPg = sqlite3PcacheDirtyList(pPager->pPCache)) || 0==pPg->pDirty) |
| 58090 | 58114 | ){ |
| 58091 | 58115 | /* Update the db file change counter via the direct-write method. The |
| | @@ -58102,25 +58126,25 @@ |
| 58102 | 58126 | } |
| 58103 | 58127 | } |
| 58104 | 58128 | } |
| 58105 | 58129 | #else /* SQLITE_ENABLE_ATOMIC_WRITE */ |
| 58106 | 58130 | #ifdef SQLITE_ENABLE_BATCH_ATOMIC_WRITE |
| 58107 | | - if( zMaster ){ |
| 58131 | + if( zSuper ){ |
| 58108 | 58132 | rc = sqlite3JournalCreate(pPager->jfd); |
| 58109 | 58133 | if( rc!=SQLITE_OK ) goto commit_phase_one_exit; |
| 58110 | 58134 | assert( bBatch==0 ); |
| 58111 | 58135 | } |
| 58112 | 58136 | #endif |
| 58113 | 58137 | rc = pager_incr_changecounter(pPager, 0); |
| 58114 | 58138 | #endif /* !SQLITE_ENABLE_ATOMIC_WRITE */ |
| 58115 | 58139 | if( rc!=SQLITE_OK ) goto commit_phase_one_exit; |
| 58116 | 58140 | |
| 58117 | | - /* Write the master journal name into the journal file. If a master |
| 58118 | | - ** journal file name has already been written to the journal file, |
| 58119 | | - ** or if zMaster is NULL (no master journal), then this call is a no-op. |
| 58141 | + /* Write the super-journal name into the journal file. If a |
| 58142 | + ** super-journal file name has already been written to the journal file, |
| 58143 | + ** or if zSuper is NULL (no super-journal), then this call is a no-op. |
| 58120 | 58144 | */ |
| 58121 | | - rc = writeMasterJournal(pPager, zMaster); |
| 58145 | + rc = writeSuperJournal(pPager, zSuper); |
| 58122 | 58146 | if( rc!=SQLITE_OK ) goto commit_phase_one_exit; |
| 58123 | 58147 | |
| 58124 | 58148 | /* Sync the journal file and write all dirty pages to the database. |
| 58125 | 58149 | ** If the atomic-update optimization is being used, this sync will not |
| 58126 | 58150 | ** create the journal file or perform any real IO. |
| | @@ -58184,11 +58208,11 @@ |
| 58184 | 58208 | if( rc!=SQLITE_OK ) goto commit_phase_one_exit; |
| 58185 | 58209 | } |
| 58186 | 58210 | |
| 58187 | 58211 | /* Finally, sync the database file. */ |
| 58188 | 58212 | if( !noSync ){ |
| 58189 | | - rc = sqlite3PagerSync(pPager, zMaster); |
| 58213 | + rc = sqlite3PagerSync(pPager, zSuper); |
| 58190 | 58214 | } |
| 58191 | 58215 | IOTRACE(("DBSYNC %p\n", pPager)) |
| 58192 | 58216 | } |
| 58193 | 58217 | } |
| 58194 | 58218 | |
| | @@ -58249,11 +58273,11 @@ |
| 58249 | 58273 | pPager->eState = PAGER_READER; |
| 58250 | 58274 | return SQLITE_OK; |
| 58251 | 58275 | } |
| 58252 | 58276 | |
| 58253 | 58277 | PAGERTRACE(("COMMIT %d\n", PAGERID(pPager))); |
| 58254 | | - rc = pager_end_transaction(pPager, pPager->setMaster, 1); |
| 58278 | + rc = pager_end_transaction(pPager, pPager->setSuper, 1); |
| 58255 | 58279 | return pager_error(pPager, rc); |
| 58256 | 58280 | } |
| 58257 | 58281 | |
| 58258 | 58282 | /* |
| 58259 | 58283 | ** If a write transaction is open, then all changes made within the |
| | @@ -58294,11 +58318,11 @@ |
| 58294 | 58318 | if( pPager->eState<=PAGER_READER ) return SQLITE_OK; |
| 58295 | 58319 | |
| 58296 | 58320 | if( pagerUseWal(pPager) ){ |
| 58297 | 58321 | int rc2; |
| 58298 | 58322 | rc = sqlite3PagerSavepoint(pPager, SAVEPOINT_ROLLBACK, -1); |
| 58299 | | - rc2 = pager_end_transaction(pPager, pPager->setMaster, 0); |
| 58323 | + rc2 = pager_end_transaction(pPager, pPager->setSuper, 0); |
| 58300 | 58324 | if( rc==SQLITE_OK ) rc = rc2; |
| 58301 | 58325 | }else if( !isOpen(pPager->jfd) || pPager->eState==PAGER_WRITER_LOCKED ){ |
| 58302 | 58326 | int eState = pPager->eState; |
| 58303 | 58327 | rc = pager_end_transaction(pPager, 0, 0); |
| 58304 | 58328 | if( !MEMDB && eState>PAGER_WRITER_LOCKED ){ |
| | @@ -63712,11 +63736,11 @@ |
| 63712 | 63736 | ** to this one BtShared object. BtShared.nRef is the number of |
| 63713 | 63737 | ** connections currently sharing this database file. |
| 63714 | 63738 | ** |
| 63715 | 63739 | ** Fields in this structure are accessed under the BtShared.mutex |
| 63716 | 63740 | ** mutex, except for nRef and pNext which are accessed under the |
| 63717 | | -** global SQLITE_MUTEX_STATIC_MASTER mutex. The pPager field |
| 63741 | +** global SQLITE_MUTEX_STATIC_MAIN mutex. The pPager field |
| 63718 | 63742 | ** may not be modified once it is initially set as long as nRef>0. |
| 63719 | 63743 | ** The pSchema field may be set once under BtShared.mutex and |
| 63720 | 63744 | ** thereafter is unchanged as long as nRef>0. |
| 63721 | 63745 | ** |
| 63722 | 63746 | ** isPending: |
| | @@ -64407,11 +64431,11 @@ |
| 64407 | 64431 | ** A list of BtShared objects that are eligible for participation |
| 64408 | 64432 | ** in shared cache. This variable has file scope during normal builds, |
| 64409 | 64433 | ** but the test harness needs to access it so we make it global for |
| 64410 | 64434 | ** test builds. |
| 64411 | 64435 | ** |
| 64412 | | -** Access to this variable is protected by SQLITE_MUTEX_STATIC_MASTER. |
| 64436 | +** Access to this variable is protected by SQLITE_MUTEX_STATIC_MAIN. |
| 64413 | 64437 | */ |
| 64414 | 64438 | #ifdef SQLITE_TEST |
| 64415 | 64439 | SQLITE_PRIVATE BtShared *SQLITE_WSD sqlite3SharedCacheList = 0; |
| 64416 | 64440 | #else |
| 64417 | 64441 | static BtShared *SQLITE_WSD sqlite3SharedCacheList = 0; |
| | @@ -64538,20 +64562,22 @@ |
| 64538 | 64562 | ** b-trees, this is just the root page of the b-tree being read or |
| 64539 | 64563 | ** written. For index b-trees, it is the root page of the associated |
| 64540 | 64564 | ** table. */ |
| 64541 | 64565 | if( isIndex ){ |
| 64542 | 64566 | HashElem *p; |
| 64567 | + int bSeen = 0; |
| 64543 | 64568 | for(p=sqliteHashFirst(&pSchema->idxHash); p; p=sqliteHashNext(p)){ |
| 64544 | 64569 | Index *pIdx = (Index *)sqliteHashData(p); |
| 64545 | 64570 | if( pIdx->tnum==(int)iRoot ){ |
| 64546 | | - if( iTab ){ |
| 64571 | + if( bSeen ){ |
| 64547 | 64572 | /* Two or more indexes share the same root page. There must |
| 64548 | 64573 | ** be imposter tables. So just return true. The assert is not |
| 64549 | 64574 | ** useful in that case. */ |
| 64550 | 64575 | return 1; |
| 64551 | 64576 | } |
| 64552 | 64577 | iTab = pIdx->pTable->tnum; |
| 64578 | + bSeen = 1; |
| 64553 | 64579 | } |
| 64554 | 64580 | } |
| 64555 | 64581 | }else{ |
| 64556 | 64582 | iTab = iRoot; |
| 64557 | 64583 | } |
| | @@ -64693,11 +64719,11 @@ |
| 64693 | 64719 | assert( eLock==READ_LOCK || eLock==WRITE_LOCK ); |
| 64694 | 64720 | assert( p->db!=0 ); |
| 64695 | 64721 | |
| 64696 | 64722 | /* A connection with the read-uncommitted flag set will never try to |
| 64697 | 64723 | ** obtain a read-lock using this function. The only read-lock obtained |
| 64698 | | - ** by a connection in read-uncommitted mode is on the sqlite_master |
| 64724 | + ** by a connection in read-uncommitted mode is on the sqlite_schema |
| 64699 | 64725 | ** table, and that lock is obtained in BtreeBeginTrans(). */ |
| 64700 | 64726 | assert( 0==(p->db->flags&SQLITE_ReadUncommit) || eLock==WRITE_LOCK ); |
| 64701 | 64727 | |
| 64702 | 64728 | /* This function should only be called on a sharable b-tree after it |
| 64703 | 64729 | ** has been determined that no other b-tree holds a conflicting lock. */ |
| | @@ -65329,11 +65355,11 @@ |
| 65329 | 65355 | int rc; /* Return code from subfunctions */ |
| 65330 | 65356 | |
| 65331 | 65357 | if( *pRC ) return; |
| 65332 | 65358 | |
| 65333 | 65359 | assert( sqlite3_mutex_held(pBt->mutex) ); |
| 65334 | | - /* The master-journal page number must never be used as a pointer map page */ |
| 65360 | + /* The super-journal page number must never be used as a pointer map page */ |
| 65335 | 65361 | assert( 0==PTRMAP_ISPAGE(pBt, PENDING_BYTE_PAGE(pBt)) ); |
| 65336 | 65362 | |
| 65337 | 65363 | assert( pBt->autoVacuum ); |
| 65338 | 65364 | if( key==0 ){ |
| 65339 | 65365 | *pRC = SQLITE_CORRUPT_BKPT; |
| | @@ -66089,11 +66115,11 @@ |
| 66089 | 66115 | */ |
| 66090 | 66116 | if( iFreeBlk && iEnd+3>=iFreeBlk ){ |
| 66091 | 66117 | nFrag = iFreeBlk - iEnd; |
| 66092 | 66118 | if( iEnd>iFreeBlk ) return SQLITE_CORRUPT_PAGE(pPage); |
| 66093 | 66119 | iEnd = iFreeBlk + get2byte(&data[iFreeBlk+2]); |
| 66094 | | - if( NEVER(iEnd > pPage->pBt->usableSize) ){ |
| 66120 | + if( iEnd > pPage->pBt->usableSize ){ |
| 66095 | 66121 | return SQLITE_CORRUPT_PAGE(pPage); |
| 66096 | 66122 | } |
| 66097 | 66123 | iSize = iEnd - iStart; |
| 66098 | 66124 | iFreeBlk = get2byte(&data[iFreeBlk]); |
| 66099 | 66125 | } |
| | @@ -66758,11 +66784,11 @@ |
| 66758 | 66784 | } |
| 66759 | 66785 | } |
| 66760 | 66786 | #if SQLITE_THREADSAFE |
| 66761 | 66787 | mutexOpen = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_OPEN); |
| 66762 | 66788 | sqlite3_mutex_enter(mutexOpen); |
| 66763 | | - mutexShared = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); |
| 66789 | + mutexShared = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN); |
| 66764 | 66790 | sqlite3_mutex_enter(mutexShared); |
| 66765 | 66791 | #endif |
| 66766 | 66792 | for(pBt=GLOBAL(BtShared*,sqlite3SharedCacheList); pBt; pBt=pBt->pNext){ |
| 66767 | 66793 | assert( pBt->nRef>0 ); |
| 66768 | 66794 | if( 0==strcmp(zFullPathname, sqlite3PagerFilename(pBt->pPager, 0)) |
| | @@ -66877,11 +66903,11 @@ |
| 66877 | 66903 | /* Add the new BtShared object to the linked list sharable BtShareds. |
| 66878 | 66904 | */ |
| 66879 | 66905 | pBt->nRef = 1; |
| 66880 | 66906 | if( p->sharable ){ |
| 66881 | 66907 | MUTEX_LOGIC( sqlite3_mutex *mutexShared; ) |
| 66882 | | - MUTEX_LOGIC( mutexShared = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);) |
| 66908 | + MUTEX_LOGIC( mutexShared = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN);) |
| 66883 | 66909 | if( SQLITE_THREADSAFE && sqlite3GlobalConfig.bCoreMutex ){ |
| 66884 | 66910 | pBt->mutex = sqlite3MutexAlloc(SQLITE_MUTEX_FAST); |
| 66885 | 66911 | if( pBt->mutex==0 ){ |
| 66886 | 66912 | rc = SQLITE_NOMEM_BKPT; |
| 66887 | 66913 | goto btree_open_out; |
| | @@ -66966,17 +66992,17 @@ |
| 66966 | 66992 | ** true if the BtShared.nRef counter reaches zero and return |
| 66967 | 66993 | ** false if it is still positive. |
| 66968 | 66994 | */ |
| 66969 | 66995 | static int removeFromSharingList(BtShared *pBt){ |
| 66970 | 66996 | #ifndef SQLITE_OMIT_SHARED_CACHE |
| 66971 | | - MUTEX_LOGIC( sqlite3_mutex *pMaster; ) |
| 66997 | + MUTEX_LOGIC( sqlite3_mutex *pMainMtx; ) |
| 66972 | 66998 | BtShared *pList; |
| 66973 | 66999 | int removed = 0; |
| 66974 | 67000 | |
| 66975 | 67001 | assert( sqlite3_mutex_notheld(pBt->mutex) ); |
| 66976 | | - MUTEX_LOGIC( pMaster = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); ) |
| 66977 | | - sqlite3_mutex_enter(pMaster); |
| 67002 | + MUTEX_LOGIC( pMainMtx = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN); ) |
| 67003 | + sqlite3_mutex_enter(pMainMtx); |
| 66978 | 67004 | pBt->nRef--; |
| 66979 | 67005 | if( pBt->nRef<=0 ){ |
| 66980 | 67006 | if( GLOBAL(BtShared*,sqlite3SharedCacheList)==pBt ){ |
| 66981 | 67007 | GLOBAL(BtShared*,sqlite3SharedCacheList) = pBt->pNext; |
| 66982 | 67008 | }else{ |
| | @@ -66991,11 +67017,11 @@ |
| 66991 | 67017 | if( SQLITE_THREADSAFE ){ |
| 66992 | 67018 | sqlite3_mutex_free(pBt->mutex); |
| 66993 | 67019 | } |
| 66994 | 67020 | removed = 1; |
| 66995 | 67021 | } |
| 66996 | | - sqlite3_mutex_leave(pMaster); |
| 67022 | + sqlite3_mutex_leave(pMainMtx); |
| 66997 | 67023 | return removed; |
| 66998 | 67024 | #else |
| 66999 | 67025 | return 1; |
| 67000 | 67026 | #endif |
| 67001 | 67027 | } |
| | @@ -67767,11 +67793,11 @@ |
| 67767 | 67793 | #endif |
| 67768 | 67794 | |
| 67769 | 67795 | /* Any read-only or read-write transaction implies a read-lock on |
| 67770 | 67796 | ** page 1. So if some other shared-cache client already has a write-lock |
| 67771 | 67797 | ** on page 1, the transaction cannot be opened. */ |
| 67772 | | - rc = querySharedCacheTableLock(p, MASTER_ROOT, READ_LOCK); |
| 67798 | + rc = querySharedCacheTableLock(p, SCHEMA_ROOT, READ_LOCK); |
| 67773 | 67799 | if( SQLITE_OK!=rc ) goto trans_begun; |
| 67774 | 67800 | |
| 67775 | 67801 | pBt->btsFlags &= ~BTS_INITIALLY_EMPTY; |
| 67776 | 67802 | if( pBt->nPage==0 ) pBt->btsFlags |= BTS_INITIALLY_EMPTY; |
| 67777 | 67803 | do { |
| | @@ -68319,22 +68345,22 @@ |
| 68319 | 68345 | ** committed. See sqlite3BtreeCommitPhaseTwo() for the second phase of the |
| 68320 | 68346 | ** commit process. |
| 68321 | 68347 | ** |
| 68322 | 68348 | ** This call is a no-op if no write-transaction is currently active on pBt. |
| 68323 | 68349 | ** |
| 68324 | | -** Otherwise, sync the database file for the btree pBt. zMaster points to |
| 68325 | | -** the name of a master journal file that should be written into the |
| 68326 | | -** individual journal file, or is NULL, indicating no master journal file |
| 68350 | +** Otherwise, sync the database file for the btree pBt. zSuperJrnl points to |
| 68351 | +** the name of a super-journal file that should be written into the |
| 68352 | +** individual journal file, or is NULL, indicating no super-journal file |
| 68327 | 68353 | ** (single database transaction). |
| 68328 | 68354 | ** |
| 68329 | | -** When this is called, the master journal should already have been |
| 68355 | +** When this is called, the super-journal should already have been |
| 68330 | 68356 | ** created, populated with this journal pointer and synced to disk. |
| 68331 | 68357 | ** |
| 68332 | 68358 | ** Once this is routine has returned, the only thing required to commit |
| 68333 | 68359 | ** the write-transaction for this database file is to delete the journal. |
| 68334 | 68360 | */ |
| 68335 | | -SQLITE_PRIVATE int sqlite3BtreeCommitPhaseOne(Btree *p, const char *zMaster){ |
| 68361 | +SQLITE_PRIVATE int sqlite3BtreeCommitPhaseOne(Btree *p, const char *zSuperJrnl){ |
| 68336 | 68362 | int rc = SQLITE_OK; |
| 68337 | 68363 | if( p->inTrans==TRANS_WRITE ){ |
| 68338 | 68364 | BtShared *pBt = p->pBt; |
| 68339 | 68365 | sqlite3BtreeEnter(p); |
| 68340 | 68366 | #ifndef SQLITE_OMIT_AUTOVACUUM |
| | @@ -68347,11 +68373,11 @@ |
| 68347 | 68373 | } |
| 68348 | 68374 | if( pBt->bDoTruncate ){ |
| 68349 | 68375 | sqlite3PagerTruncateImage(pBt->pPager, pBt->nPage); |
| 68350 | 68376 | } |
| 68351 | 68377 | #endif |
| 68352 | | - rc = sqlite3PagerCommitPhaseOne(pBt->pPager, zMaster, 0); |
| 68378 | + rc = sqlite3PagerCommitPhaseOne(pBt->pPager, zSuperJrnl, 0); |
| 68353 | 68379 | sqlite3BtreeLeave(p); |
| 68354 | 68380 | } |
| 68355 | 68381 | return rc; |
| 68356 | 68382 | } |
| 68357 | 68383 | |
| | @@ -68410,11 +68436,11 @@ |
| 68410 | 68436 | ** Normally, if an error occurs while the pager layer is attempting to |
| 68411 | 68437 | ** finalize the underlying journal file, this function returns an error and |
| 68412 | 68438 | ** the upper layer will attempt a rollback. However, if the second argument |
| 68413 | 68439 | ** is non-zero then this b-tree transaction is part of a multi-file |
| 68414 | 68440 | ** transaction. In this case, the transaction has already been committed |
| 68415 | | -** (by deleting a master journal file) and the caller will ignore this |
| 68441 | +** (by deleting a super-journal file) and the caller will ignore this |
| 68416 | 68442 | ** functions return code. So, even if an error occurs in the pager layer, |
| 68417 | 68443 | ** reset the b-tree objects internal state to indicate that the write |
| 68418 | 68444 | ** transaction has been closed. This is quite safe, as the pager will have |
| 68419 | 68445 | ** transitioned to the error state. |
| 68420 | 68446 | ** |
| | @@ -73815,11 +73841,11 @@ |
| 73815 | 73841 | SQLITE_PRIVATE void sqlite3BtreeGetMeta(Btree *p, int idx, u32 *pMeta){ |
| 73816 | 73842 | BtShared *pBt = p->pBt; |
| 73817 | 73843 | |
| 73818 | 73844 | sqlite3BtreeEnter(p); |
| 73819 | 73845 | assert( p->inTrans>TRANS_NONE ); |
| 73820 | | - assert( SQLITE_OK==querySharedCacheTableLock(p, MASTER_ROOT, READ_LOCK) ); |
| 73846 | + assert( SQLITE_OK==querySharedCacheTableLock(p, SCHEMA_ROOT, READ_LOCK) ); |
| 73821 | 73847 | assert( pBt->pPage1 ); |
| 73822 | 73848 | assert( idx>=0 && idx<=15 ); |
| 73823 | 73849 | |
| 73824 | 73850 | if( idx==BTREE_DATA_VERSION ){ |
| 73825 | 73851 | *pMeta = sqlite3PagerDataVersion(pBt->pPager) + p->iDataVersion; |
| | @@ -74692,17 +74718,17 @@ |
| 74692 | 74718 | } |
| 74693 | 74719 | |
| 74694 | 74720 | /* |
| 74695 | 74721 | ** Return SQLITE_LOCKED_SHAREDCACHE if another user of the same shared |
| 74696 | 74722 | ** btree as the argument handle holds an exclusive lock on the |
| 74697 | | -** sqlite_master table. Otherwise SQLITE_OK. |
| 74723 | +** sqlite_schema table. Otherwise SQLITE_OK. |
| 74698 | 74724 | */ |
| 74699 | 74725 | SQLITE_PRIVATE int sqlite3BtreeSchemaLocked(Btree *p){ |
| 74700 | 74726 | int rc; |
| 74701 | 74727 | assert( sqlite3_mutex_held(p->db->mutex) ); |
| 74702 | 74728 | sqlite3BtreeEnter(p); |
| 74703 | | - rc = querySharedCacheTableLock(p, MASTER_ROOT, READ_LOCK); |
| 74729 | + rc = querySharedCacheTableLock(p, SCHEMA_ROOT, READ_LOCK); |
| 74704 | 74730 | assert( rc==SQLITE_OK || rc==SQLITE_LOCKED_SHAREDCACHE ); |
| 74705 | 74731 | sqlite3BtreeLeave(p); |
| 74706 | 74732 | return rc; |
| 74707 | 74733 | } |
| 74708 | 74734 | |
| | @@ -80176,17 +80202,17 @@ |
| 80176 | 80202 | |
| 80177 | 80203 | /* |
| 80178 | 80204 | ** A read or write transaction may or may not be active on database handle |
| 80179 | 80205 | ** db. If a transaction is active, commit it. If there is a |
| 80180 | 80206 | ** write-transaction spanning more than one database file, this routine |
| 80181 | | -** takes care of the master journal trickery. |
| 80207 | +** takes care of the super-journal trickery. |
| 80182 | 80208 | */ |
| 80183 | 80209 | static int vdbeCommit(sqlite3 *db, Vdbe *p){ |
| 80184 | 80210 | int i; |
| 80185 | 80211 | int nTrans = 0; /* Number of databases with an active write-transaction |
| 80186 | 80212 | ** that are candidates for a two-phase commit using a |
| 80187 | | - ** master-journal */ |
| 80213 | + ** super-journal */ |
| 80188 | 80214 | int rc = SQLITE_OK; |
| 80189 | 80215 | int needXcommit = 0; |
| 80190 | 80216 | |
| 80191 | 80217 | #ifdef SQLITE_OMIT_VIRTUALTABLE |
| 80192 | 80218 | /* With this option, sqlite3VtabSync() is defined to be simply |
| | @@ -80195,28 +80221,28 @@ |
| 80195 | 80221 | UNUSED_PARAMETER(p); |
| 80196 | 80222 | #endif |
| 80197 | 80223 | |
| 80198 | 80224 | /* Before doing anything else, call the xSync() callback for any |
| 80199 | 80225 | ** virtual module tables written in this transaction. This has to |
| 80200 | | - ** be done before determining whether a master journal file is |
| 80226 | + ** be done before determining whether a super-journal file is |
| 80201 | 80227 | ** required, as an xSync() callback may add an attached database |
| 80202 | 80228 | ** to the transaction. |
| 80203 | 80229 | */ |
| 80204 | 80230 | rc = sqlite3VtabSync(db, p); |
| 80205 | 80231 | |
| 80206 | 80232 | /* This loop determines (a) if the commit hook should be invoked and |
| 80207 | 80233 | ** (b) how many database files have open write transactions, not |
| 80208 | 80234 | ** including the temp database. (b) is important because if more than |
| 80209 | | - ** one database file has an open write transaction, a master journal |
| 80235 | + ** one database file has an open write transaction, a super-journal |
| 80210 | 80236 | ** file is required for an atomic commit. |
| 80211 | 80237 | */ |
| 80212 | 80238 | for(i=0; rc==SQLITE_OK && i<db->nDb; i++){ |
| 80213 | 80239 | Btree *pBt = db->aDb[i].pBt; |
| 80214 | 80240 | if( sqlite3BtreeIsInTrans(pBt) ){ |
| 80215 | | - /* Whether or not a database might need a master journal depends upon |
| 80241 | + /* Whether or not a database might need a super-journal depends upon |
| 80216 | 80242 | ** its journal mode (among other things). This matrix determines which |
| 80217 | | - ** journal modes use a master journal and which do not */ |
| 80243 | + ** journal modes use a super-journal and which do not */ |
| 80218 | 80244 | static const u8 aMJNeeded[] = { |
| 80219 | 80245 | /* DELETE */ 1, |
| 80220 | 80246 | /* PERSIST */ 1, |
| 80221 | 80247 | /* OFF */ 0, |
| 80222 | 80248 | /* TRUNCATE */ 1, |
| | @@ -80250,11 +80276,11 @@ |
| 80250 | 80276 | } |
| 80251 | 80277 | } |
| 80252 | 80278 | |
| 80253 | 80279 | /* The simple case - no more than one database file (not counting the |
| 80254 | 80280 | ** TEMP database) has a transaction active. There is no need for the |
| 80255 | | - ** master-journal. |
| 80281 | + ** super-journal. |
| 80256 | 80282 | ** |
| 80257 | 80283 | ** If the return value of sqlite3BtreeGetFilename() is a zero length |
| 80258 | 80284 | ** string, it means the main database is :memory: or a temp file. In |
| 80259 | 80285 | ** that case we do not support atomic multi-file commits, so use the |
| 80260 | 80286 | ** simple case then too. |
| | @@ -80284,66 +80310,66 @@ |
| 80284 | 80310 | sqlite3VtabCommit(db); |
| 80285 | 80311 | } |
| 80286 | 80312 | } |
| 80287 | 80313 | |
| 80288 | 80314 | /* The complex case - There is a multi-file write-transaction active. |
| 80289 | | - ** This requires a master journal file to ensure the transaction is |
| 80315 | + ** This requires a super-journal file to ensure the transaction is |
| 80290 | 80316 | ** committed atomically. |
| 80291 | 80317 | */ |
| 80292 | 80318 | #ifndef SQLITE_OMIT_DISKIO |
| 80293 | 80319 | else{ |
| 80294 | 80320 | sqlite3_vfs *pVfs = db->pVfs; |
| 80295 | | - char *zMaster = 0; /* File-name for the master journal */ |
| 80321 | + char *zSuper = 0; /* File-name for the super-journal */ |
| 80296 | 80322 | char const *zMainFile = sqlite3BtreeGetFilename(db->aDb[0].pBt); |
| 80297 | | - sqlite3_file *pMaster = 0; |
| 80323 | + sqlite3_file *pSuperJrnl = 0; |
| 80298 | 80324 | i64 offset = 0; |
| 80299 | 80325 | int res; |
| 80300 | 80326 | int retryCount = 0; |
| 80301 | 80327 | int nMainFile; |
| 80302 | 80328 | |
| 80303 | | - /* Select a master journal file name */ |
| 80329 | + /* Select a super-journal file name */ |
| 80304 | 80330 | nMainFile = sqlite3Strlen30(zMainFile); |
| 80305 | | - zMaster = sqlite3MPrintf(db, "%.4c%s%.16c", 0,zMainFile,0); |
| 80306 | | - if( zMaster==0 ) return SQLITE_NOMEM_BKPT; |
| 80307 | | - zMaster += 4; |
| 80331 | + zSuper = sqlite3MPrintf(db, "%.4c%s%.16c", 0,zMainFile,0); |
| 80332 | + if( zSuper==0 ) return SQLITE_NOMEM_BKPT; |
| 80333 | + zSuper += 4; |
| 80308 | 80334 | do { |
| 80309 | 80335 | u32 iRandom; |
| 80310 | 80336 | if( retryCount ){ |
| 80311 | 80337 | if( retryCount>100 ){ |
| 80312 | | - sqlite3_log(SQLITE_FULL, "MJ delete: %s", zMaster); |
| 80313 | | - sqlite3OsDelete(pVfs, zMaster, 0); |
| 80338 | + sqlite3_log(SQLITE_FULL, "MJ delete: %s", zSuper); |
| 80339 | + sqlite3OsDelete(pVfs, zSuper, 0); |
| 80314 | 80340 | break; |
| 80315 | 80341 | }else if( retryCount==1 ){ |
| 80316 | | - sqlite3_log(SQLITE_FULL, "MJ collide: %s", zMaster); |
| 80342 | + sqlite3_log(SQLITE_FULL, "MJ collide: %s", zSuper); |
| 80317 | 80343 | } |
| 80318 | 80344 | } |
| 80319 | 80345 | retryCount++; |
| 80320 | 80346 | sqlite3_randomness(sizeof(iRandom), &iRandom); |
| 80321 | | - sqlite3_snprintf(13, &zMaster[nMainFile], "-mj%06X9%02X", |
| 80347 | + sqlite3_snprintf(13, &zSuper[nMainFile], "-mj%06X9%02X", |
| 80322 | 80348 | (iRandom>>8)&0xffffff, iRandom&0xff); |
| 80323 | | - /* The antipenultimate character of the master journal name must |
| 80349 | + /* The antipenultimate character of the super-journal name must |
| 80324 | 80350 | ** be "9" to avoid name collisions when using 8+3 filenames. */ |
| 80325 | | - assert( zMaster[sqlite3Strlen30(zMaster)-3]=='9' ); |
| 80326 | | - sqlite3FileSuffix3(zMainFile, zMaster); |
| 80327 | | - rc = sqlite3OsAccess(pVfs, zMaster, SQLITE_ACCESS_EXISTS, &res); |
| 80351 | + assert( zSuper[sqlite3Strlen30(zSuper)-3]=='9' ); |
| 80352 | + sqlite3FileSuffix3(zMainFile, zSuper); |
| 80353 | + rc = sqlite3OsAccess(pVfs, zSuper, SQLITE_ACCESS_EXISTS, &res); |
| 80328 | 80354 | }while( rc==SQLITE_OK && res ); |
| 80329 | 80355 | if( rc==SQLITE_OK ){ |
| 80330 | | - /* Open the master journal. */ |
| 80331 | | - rc = sqlite3OsOpenMalloc(pVfs, zMaster, &pMaster, |
| 80356 | + /* Open the super-journal. */ |
| 80357 | + rc = sqlite3OsOpenMalloc(pVfs, zSuper, &pSuperJrnl, |
| 80332 | 80358 | SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE| |
| 80333 | | - SQLITE_OPEN_EXCLUSIVE|SQLITE_OPEN_MASTER_JOURNAL, 0 |
| 80359 | + SQLITE_OPEN_EXCLUSIVE|SQLITE_OPEN_SUPER_JOURNAL, 0 |
| 80334 | 80360 | ); |
| 80335 | 80361 | } |
| 80336 | 80362 | if( rc!=SQLITE_OK ){ |
| 80337 | | - sqlite3DbFree(db, zMaster-4); |
| 80363 | + sqlite3DbFree(db, zSuper-4); |
| 80338 | 80364 | return rc; |
| 80339 | 80365 | } |
| 80340 | 80366 | |
| 80341 | 80367 | /* Write the name of each database file in the transaction into the new |
| 80342 | | - ** master journal file. If an error occurs at this point close |
| 80343 | | - ** and delete the master journal file. All the individual journal files |
| 80344 | | - ** still have 'null' as the master journal pointer, so they will roll |
| 80368 | + ** super-journal file. If an error occurs at this point close |
| 80369 | + ** and delete the super-journal file. All the individual journal files |
| 80370 | + ** still have 'null' as the super-journal pointer, so they will roll |
| 80345 | 80371 | ** back independently if a failure occurs. |
| 80346 | 80372 | */ |
| 80347 | 80373 | for(i=0; i<db->nDb; i++){ |
| 80348 | 80374 | Btree *pBt = db->aDb[i].pBt; |
| 80349 | 80375 | if( sqlite3BtreeIsInTrans(pBt) ){ |
| | @@ -80350,63 +80376,63 @@ |
| 80350 | 80376 | char const *zFile = sqlite3BtreeGetJournalname(pBt); |
| 80351 | 80377 | if( zFile==0 ){ |
| 80352 | 80378 | continue; /* Ignore TEMP and :memory: databases */ |
| 80353 | 80379 | } |
| 80354 | 80380 | assert( zFile[0]!=0 ); |
| 80355 | | - rc = sqlite3OsWrite(pMaster, zFile, sqlite3Strlen30(zFile)+1, offset); |
| 80381 | + rc = sqlite3OsWrite(pSuperJrnl, zFile, sqlite3Strlen30(zFile)+1,offset); |
| 80356 | 80382 | offset += sqlite3Strlen30(zFile)+1; |
| 80357 | 80383 | if( rc!=SQLITE_OK ){ |
| 80358 | | - sqlite3OsCloseFree(pMaster); |
| 80359 | | - sqlite3OsDelete(pVfs, zMaster, 0); |
| 80360 | | - sqlite3DbFree(db, zMaster-4); |
| 80384 | + sqlite3OsCloseFree(pSuperJrnl); |
| 80385 | + sqlite3OsDelete(pVfs, zSuper, 0); |
| 80386 | + sqlite3DbFree(db, zSuper-4); |
| 80361 | 80387 | return rc; |
| 80362 | 80388 | } |
| 80363 | 80389 | } |
| 80364 | 80390 | } |
| 80365 | 80391 | |
| 80366 | | - /* Sync the master journal file. If the IOCAP_SEQUENTIAL device |
| 80392 | + /* Sync the super-journal file. If the IOCAP_SEQUENTIAL device |
| 80367 | 80393 | ** flag is set this is not required. |
| 80368 | 80394 | */ |
| 80369 | | - if( 0==(sqlite3OsDeviceCharacteristics(pMaster)&SQLITE_IOCAP_SEQUENTIAL) |
| 80370 | | - && SQLITE_OK!=(rc = sqlite3OsSync(pMaster, SQLITE_SYNC_NORMAL)) |
| 80395 | + if( 0==(sqlite3OsDeviceCharacteristics(pSuperJrnl)&SQLITE_IOCAP_SEQUENTIAL) |
| 80396 | + && SQLITE_OK!=(rc = sqlite3OsSync(pSuperJrnl, SQLITE_SYNC_NORMAL)) |
| 80371 | 80397 | ){ |
| 80372 | | - sqlite3OsCloseFree(pMaster); |
| 80373 | | - sqlite3OsDelete(pVfs, zMaster, 0); |
| 80374 | | - sqlite3DbFree(db, zMaster-4); |
| 80398 | + sqlite3OsCloseFree(pSuperJrnl); |
| 80399 | + sqlite3OsDelete(pVfs, zSuper, 0); |
| 80400 | + sqlite3DbFree(db, zSuper-4); |
| 80375 | 80401 | return rc; |
| 80376 | 80402 | } |
| 80377 | 80403 | |
| 80378 | 80404 | /* Sync all the db files involved in the transaction. The same call |
| 80379 | | - ** sets the master journal pointer in each individual journal. If |
| 80380 | | - ** an error occurs here, do not delete the master journal file. |
| 80405 | + ** sets the super-journal pointer in each individual journal. If |
| 80406 | + ** an error occurs here, do not delete the super-journal file. |
| 80381 | 80407 | ** |
| 80382 | 80408 | ** If the error occurs during the first call to |
| 80383 | 80409 | ** sqlite3BtreeCommitPhaseOne(), then there is a chance that the |
| 80384 | | - ** master journal file will be orphaned. But we cannot delete it, |
| 80385 | | - ** in case the master journal file name was written into the journal |
| 80410 | + ** super-journal file will be orphaned. But we cannot delete it, |
| 80411 | + ** in case the super-journal file name was written into the journal |
| 80386 | 80412 | ** file before the failure occurred. |
| 80387 | 80413 | */ |
| 80388 | 80414 | for(i=0; rc==SQLITE_OK && i<db->nDb; i++){ |
| 80389 | 80415 | Btree *pBt = db->aDb[i].pBt; |
| 80390 | 80416 | if( pBt ){ |
| 80391 | | - rc = sqlite3BtreeCommitPhaseOne(pBt, zMaster); |
| 80417 | + rc = sqlite3BtreeCommitPhaseOne(pBt, zSuper); |
| 80392 | 80418 | } |
| 80393 | 80419 | } |
| 80394 | | - sqlite3OsCloseFree(pMaster); |
| 80420 | + sqlite3OsCloseFree(pSuperJrnl); |
| 80395 | 80421 | assert( rc!=SQLITE_BUSY ); |
| 80396 | 80422 | if( rc!=SQLITE_OK ){ |
| 80397 | | - sqlite3DbFree(db, zMaster-4); |
| 80423 | + sqlite3DbFree(db, zSuper-4); |
| 80398 | 80424 | return rc; |
| 80399 | 80425 | } |
| 80400 | 80426 | |
| 80401 | | - /* Delete the master journal file. This commits the transaction. After |
| 80427 | + /* Delete the super-journal file. This commits the transaction. After |
| 80402 | 80428 | ** doing this the directory is synced again before any individual |
| 80403 | 80429 | ** transaction files are deleted. |
| 80404 | 80430 | */ |
| 80405 | | - rc = sqlite3OsDelete(pVfs, zMaster, 1); |
| 80406 | | - sqlite3DbFree(db, zMaster-4); |
| 80407 | | - zMaster = 0; |
| 80431 | + rc = sqlite3OsDelete(pVfs, zSuper, 1); |
| 80432 | + sqlite3DbFree(db, zSuper-4); |
| 80433 | + zSuper = 0; |
| 80408 | 80434 | if( rc ){ |
| 80409 | 80435 | return rc; |
| 80410 | 80436 | } |
| 80411 | 80437 | |
| 80412 | 80438 | /* All files and directories have already been synced, so the following |
| | @@ -87212,11 +87238,11 @@ |
| 87212 | 87238 | affinity = pOp->p5 & SQLITE_AFF_MASK; |
| 87213 | 87239 | if( affinity>=SQLITE_AFF_NUMERIC ){ |
| 87214 | 87240 | if( (flags1 | flags3)&MEM_Str ){ |
| 87215 | 87241 | if( (flags1 & (MEM_Int|MEM_IntReal|MEM_Real|MEM_Str))==MEM_Str ){ |
| 87216 | 87242 | applyNumericAffinity(pIn1,0); |
| 87217 | | - assert( flags3==pIn3->flags ); |
| 87243 | + testcase( flags3==pIn3->flags ); |
| 87218 | 87244 | flags3 = pIn3->flags; |
| 87219 | 87245 | } |
| 87220 | 87246 | if( (flags3 & (MEM_Int|MEM_IntReal|MEM_Real|MEM_Str))==MEM_Str ){ |
| 87221 | 87247 | applyNumericAffinity(pIn3,0); |
| 87222 | 87248 | } |
| | @@ -89086,20 +89112,20 @@ |
| 89086 | 89112 | if( (pCx->pKeyInfo = pKeyInfo = pOp->p4.pKeyInfo)!=0 ){ |
| 89087 | 89113 | assert( pOp->p4type==P4_KEYINFO ); |
| 89088 | 89114 | rc = sqlite3BtreeCreateTable(pCx->pBtx, (int*)&pCx->pgnoRoot, |
| 89089 | 89115 | BTREE_BLOBKEY | pOp->p5); |
| 89090 | 89116 | if( rc==SQLITE_OK ){ |
| 89091 | | - assert( pCx->pgnoRoot==MASTER_ROOT+1 ); |
| 89117 | + assert( pCx->pgnoRoot==SCHEMA_ROOT+1 ); |
| 89092 | 89118 | assert( pKeyInfo->db==db ); |
| 89093 | 89119 | assert( pKeyInfo->enc==ENC(db) ); |
| 89094 | 89120 | rc = sqlite3BtreeCursor(pCx->pBtx, pCx->pgnoRoot, BTREE_WRCSR, |
| 89095 | 89121 | pKeyInfo, pCx->uc.pCursor); |
| 89096 | 89122 | } |
| 89097 | 89123 | pCx->isTable = 0; |
| 89098 | 89124 | }else{ |
| 89099 | | - pCx->pgnoRoot = MASTER_ROOT; |
| 89100 | | - rc = sqlite3BtreeCursor(pCx->pBtx, MASTER_ROOT, BTREE_WRCSR, |
| 89125 | + pCx->pgnoRoot = SCHEMA_ROOT; |
| 89126 | + rc = sqlite3BtreeCursor(pCx->pBtx, SCHEMA_ROOT, BTREE_WRCSR, |
| 89101 | 89127 | 0, pCx->uc.pCursor); |
| 89102 | 89128 | pCx->isTable = 1; |
| 89103 | 89129 | } |
| 89104 | 89130 | } |
| 89105 | 89131 | pCx->isOrdered = (pOp->p5!=BTREE_UNORDERED); |
| | @@ -91202,20 +91228,20 @@ |
| 91202 | 91228 | break; |
| 91203 | 91229 | } |
| 91204 | 91230 | |
| 91205 | 91231 | /* Opcode: ParseSchema P1 * * P4 * |
| 91206 | 91232 | ** |
| 91207 | | -** Read and parse all entries from the SQLITE_MASTER table of database P1 |
| 91233 | +** Read and parse all entries from the schema table of database P1 |
| 91208 | 91234 | ** that match the WHERE clause P4. If P4 is a NULL pointer, then the |
| 91209 | 91235 | ** entire schema for P1 is reparsed. |
| 91210 | 91236 | ** |
| 91211 | 91237 | ** This opcode invokes the parser to create a new virtual machine, |
| 91212 | 91238 | ** then runs the new virtual machine. It is thus a re-entrant opcode. |
| 91213 | 91239 | */ |
| 91214 | 91240 | case OP_ParseSchema: { |
| 91215 | 91241 | int iDb; |
| 91216 | | - const char *zMaster; |
| 91242 | + const char *zSchema; |
| 91217 | 91243 | char *zSql; |
| 91218 | 91244 | InitData initData; |
| 91219 | 91245 | |
| 91220 | 91246 | /* Any prepared statement that invokes this opcode will hold mutexes |
| 91221 | 91247 | ** on every btree. This is a prerequisite for invoking |
| | @@ -91239,18 +91265,18 @@ |
| 91239 | 91265 | db->mDbFlags |= DBFLAG_SchemaChange; |
| 91240 | 91266 | p->expired = 0; |
| 91241 | 91267 | }else |
| 91242 | 91268 | #endif |
| 91243 | 91269 | { |
| 91244 | | - zMaster = MASTER_NAME; |
| 91270 | + zSchema = DFLT_SCHEMA_TABLE; |
| 91245 | 91271 | initData.db = db; |
| 91246 | 91272 | initData.iDb = iDb; |
| 91247 | 91273 | initData.pzErrMsg = &p->zErrMsg; |
| 91248 | 91274 | initData.mInitFlags = 0; |
| 91249 | 91275 | zSql = sqlite3MPrintf(db, |
| 91250 | 91276 | "SELECT*FROM\"%w\".%s WHERE %s ORDER BY rowid", |
| 91251 | | - db->aDb[iDb].zDbSName, zMaster, pOp->p4.z); |
| 91277 | + db->aDb[iDb].zDbSName, zSchema, pOp->p4.z); |
| 91252 | 91278 | if( zSql==0 ){ |
| 91253 | 91279 | rc = SQLITE_NOMEM_BKPT; |
| 91254 | 91280 | }else{ |
| 91255 | 91281 | assert( db->init.busy==0 ); |
| 91256 | 91282 | db->init.busy = 1; |
| | @@ -91260,11 +91286,11 @@ |
| 91260 | 91286 | rc = sqlite3_exec(db, zSql, sqlite3InitCallback, &initData, 0); |
| 91261 | 91287 | if( rc==SQLITE_OK ) rc = initData.rc; |
| 91262 | 91288 | if( rc==SQLITE_OK && initData.nInitRow==0 ){ |
| 91263 | 91289 | /* The OP_ParseSchema opcode with a non-NULL P4 argument should parse |
| 91264 | 91290 | ** at least one SQL statement. Any less than that indicates that |
| 91265 | | - ** the sqlite_master table is corrupt. */ |
| 91291 | + ** the sqlite_schema table is corrupt. */ |
| 91266 | 91292 | rc = SQLITE_CORRUPT_BKPT; |
| 91267 | 91293 | } |
| 91268 | 91294 | sqlite3DbFreeNN(db, zSql); |
| 91269 | 91295 | db->init.busy = 0; |
| 91270 | 91296 | } |
| | @@ -101493,14 +101519,14 @@ |
| 101493 | 101519 | ** In all cases, the callbacks set Walker.eCode=0 and abort if the expression |
| 101494 | 101520 | ** is found to not be a constant. |
| 101495 | 101521 | ** |
| 101496 | 101522 | ** The sqlite3ExprIsConstantOrFunction() is used for evaluating DEFAULT |
| 101497 | 101523 | ** expressions in a CREATE TABLE statement. The Walker.eCode value is 5 |
| 101498 | | -** when parsing an existing schema out of the sqlite_master table and 4 |
| 101524 | +** when parsing an existing schema out of the sqlite_schema table and 4 |
| 101499 | 101525 | ** when processing a new CREATE TABLE statement. A bound parameter raises |
| 101500 | 101526 | ** an error for new statements, but is silently converted |
| 101501 | | -** to NULL for existing schemas. This allows sqlite_master tables that |
| 101527 | +** to NULL for existing schemas. This allows sqlite_schema tables that |
| 101502 | 101528 | ** contain a bound parameter because they were generated by older versions |
| 101503 | 101529 | ** of SQLite to be parsed by newer versions of SQLite without raising a |
| 101504 | 101530 | ** malformed schema error. |
| 101505 | 101531 | */ |
| 101506 | 101532 | static int exprNodeIsConstant(Walker *pWalker, Expr *pExpr){ |
| | @@ -101548,19 +101574,21 @@ |
| 101548 | 101574 | return WRC_Continue; |
| 101549 | 101575 | } |
| 101550 | 101576 | /* Fall through */ |
| 101551 | 101577 | case TK_IF_NULL_ROW: |
| 101552 | 101578 | case TK_REGISTER: |
| 101579 | + case TK_DOT: |
| 101553 | 101580 | testcase( pExpr->op==TK_REGISTER ); |
| 101554 | 101581 | testcase( pExpr->op==TK_IF_NULL_ROW ); |
| 101582 | + testcase( pExpr->op==TK_DOT ); |
| 101555 | 101583 | pWalker->eCode = 0; |
| 101556 | 101584 | return WRC_Abort; |
| 101557 | 101585 | case TK_VARIABLE: |
| 101558 | 101586 | if( pWalker->eCode==5 ){ |
| 101559 | 101587 | /* Silently convert bound parameters that appear inside of CREATE |
| 101560 | 101588 | ** statements into a NULL when parsing the CREATE statement text out |
| 101561 | | - ** of the sqlite_master table */ |
| 101589 | + ** of the sqlite_schema table */ |
| 101562 | 101590 | pExpr->op = TK_NULL; |
| 101563 | 101591 | }else if( pWalker->eCode==4 ){ |
| 101564 | 101592 | /* A bound parameter in a CREATE statement that originates from |
| 101565 | 101593 | ** sqlite3_prepare() causes an error */ |
| 101566 | 101594 | pWalker->eCode = 0; |
| | @@ -101689,16 +101717,16 @@ |
| 101689 | 101717 | ** in a CREATE TABLE statement. Return non-zero if the expression is |
| 101690 | 101718 | ** acceptable for use as a DEFAULT. That is to say, return non-zero if |
| 101691 | 101719 | ** the expression is constant or a function call with constant arguments. |
| 101692 | 101720 | ** Return and 0 if there are any variables. |
| 101693 | 101721 | ** |
| 101694 | | -** isInit is true when parsing from sqlite_master. isInit is false when |
| 101722 | +** isInit is true when parsing from sqlite_schema. isInit is false when |
| 101695 | 101723 | ** processing a new CREATE TABLE statement. When isInit is true, parameters |
| 101696 | 101724 | ** (such as ? or $abc) in the expression are converted into NULL. When |
| 101697 | 101725 | ** isInit is false, parameters raise an error. Parameters should not be |
| 101698 | 101726 | ** allowed in a CREATE TABLE statement, but some legacy versions of SQLite |
| 101699 | | -** allowed it, so we need to support it when reading sqlite_master for |
| 101727 | +** allowed it, so we need to support it when reading sqlite_schema for |
| 101700 | 101728 | ** backwards compatibility. |
| 101701 | 101729 | ** |
| 101702 | 101730 | ** If isInit is true, set EP_FromDDL on every TK_FUNCTION node. |
| 101703 | 101731 | ** |
| 101704 | 101732 | ** For the purposes of this function, a double-quoted string (ex: "abc") |
| | @@ -105154,13 +105182,28 @@ |
| 105154 | 105182 | ** aggregate function, in order to implement the |
| 105155 | 105183 | ** sqlite3FunctionThisSrc() routine. |
| 105156 | 105184 | */ |
| 105157 | 105185 | struct SrcCount { |
| 105158 | 105186 | SrcList *pSrc; /* One particular FROM clause in a nested query */ |
| 105187 | + int iSrcInner; /* Smallest cursor number in this context */ |
| 105159 | 105188 | int nThis; /* Number of references to columns in pSrcList */ |
| 105160 | 105189 | int nOther; /* Number of references to columns in other FROM clauses */ |
| 105161 | 105190 | }; |
| 105191 | + |
| 105192 | +/* |
| 105193 | +** xSelect callback for sqlite3FunctionUsesThisSrc(). If this is the first |
| 105194 | +** SELECT with a FROM clause encountered during this iteration, set |
| 105195 | +** SrcCount.iSrcInner to the cursor number of the leftmost object in |
| 105196 | +** the FROM cause. |
| 105197 | +*/ |
| 105198 | +static int selectSrcCount(Walker *pWalker, Select *pSel){ |
| 105199 | + struct SrcCount *p = pWalker->u.pSrcCount; |
| 105200 | + if( p->iSrcInner==0x7FFFFFFF && ALWAYS(pSel->pSrc) && pSel->pSrc->nSrc ){ |
| 105201 | + pWalker->u.pSrcCount->iSrcInner = pSel->pSrc->a[0].iCursor; |
| 105202 | + } |
| 105203 | + return WRC_Continue; |
| 105204 | +} |
| 105162 | 105205 | |
| 105163 | 105206 | /* |
| 105164 | 105207 | ** Count the number of references to columns. |
| 105165 | 105208 | */ |
| 105166 | 105209 | static int exprSrcCount(Walker *pWalker, Expr *pExpr){ |
| | @@ -105178,11 +105221,11 @@ |
| 105178 | 105221 | for(i=0; i<nSrc; i++){ |
| 105179 | 105222 | if( pExpr->iTable==pSrc->a[i].iCursor ) break; |
| 105180 | 105223 | } |
| 105181 | 105224 | if( i<nSrc ){ |
| 105182 | 105225 | p->nThis++; |
| 105183 | | - }else if( nSrc==0 || pExpr->iTable<pSrc->a[0].iCursor ){ |
| 105226 | + }else if( pExpr->iTable<p->iSrcInner ){ |
| 105184 | 105227 | /* In a well-formed parse tree (no name resolution errors), |
| 105185 | 105228 | ** TK_COLUMN nodes with smaller Expr.iTable values are in an |
| 105186 | 105229 | ** outer context. Those are the only ones to count as "other" */ |
| 105187 | 105230 | p->nOther++; |
| 105188 | 105231 | } |
| | @@ -105200,13 +105243,14 @@ |
| 105200 | 105243 | Walker w; |
| 105201 | 105244 | struct SrcCount cnt; |
| 105202 | 105245 | assert( pExpr->op==TK_AGG_FUNCTION ); |
| 105203 | 105246 | memset(&w, 0, sizeof(w)); |
| 105204 | 105247 | w.xExprCallback = exprSrcCount; |
| 105205 | | - w.xSelectCallback = sqlite3SelectWalkNoop; |
| 105248 | + w.xSelectCallback = selectSrcCount; |
| 105206 | 105249 | w.u.pSrcCount = &cnt; |
| 105207 | 105250 | cnt.pSrc = pSrcList; |
| 105251 | + cnt.iSrcInner = (pSrcList&&pSrcList->nSrc)?pSrcList->a[0].iCursor:0x7FFFFFFF; |
| 105208 | 105252 | cnt.nThis = 0; |
| 105209 | 105253 | cnt.nOther = 0; |
| 105210 | 105254 | sqlite3WalkExprList(&w, pExpr->x.pList); |
| 105211 | 105255 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 105212 | 105256 | if( ExprHasProperty(pExpr, EP_WinFunc) ){ |
| | @@ -105238,24 +105282,24 @@ |
| 105238 | 105282 | Parse *pParse = pWalker->pParse; |
| 105239 | 105283 | sqlite3 *db = pParse->db; |
| 105240 | 105284 | assert( pExpr->op==TK_AGG_COLUMN || pExpr->op==TK_AGG_FUNCTION ); |
| 105241 | 105285 | if( pExpr->op==TK_AGG_COLUMN ){ |
| 105242 | 105286 | assert( iAgg>=0 && iAgg<pAggInfo->nColumn ); |
| 105243 | | - if( pAggInfo->aCol[iAgg].pExpr==pExpr ){ |
| 105287 | + if( pAggInfo->aCol[iAgg].pCExpr==pExpr ){ |
| 105244 | 105288 | pExpr = sqlite3ExprDup(db, pExpr, 0); |
| 105245 | 105289 | if( pExpr ){ |
| 105246 | | - pAggInfo->aCol[iAgg].pExpr = pExpr; |
| 105290 | + pAggInfo->aCol[iAgg].pCExpr = pExpr; |
| 105247 | 105291 | pParse->pConstExpr = |
| 105248 | 105292 | sqlite3ExprListAppend(pParse, pParse->pConstExpr, pExpr); |
| 105249 | 105293 | } |
| 105250 | 105294 | } |
| 105251 | 105295 | }else{ |
| 105252 | 105296 | assert( iAgg>=0 && iAgg<pAggInfo->nFunc ); |
| 105253 | | - if( pAggInfo->aFunc[iAgg].pExpr==pExpr ){ |
| 105297 | + if( pAggInfo->aFunc[iAgg].pFExpr==pExpr ){ |
| 105254 | 105298 | pExpr = sqlite3ExprDup(db, pExpr, 0); |
| 105255 | 105299 | if( pExpr ){ |
| 105256 | | - pAggInfo->aFunc[iAgg].pExpr = pExpr; |
| 105300 | + pAggInfo->aFunc[iAgg].pFExpr = pExpr; |
| 105257 | 105301 | pParse->pConstExpr = |
| 105258 | 105302 | sqlite3ExprListAppend(pParse, pParse->pConstExpr, pExpr); |
| 105259 | 105303 | } |
| 105260 | 105304 | } |
| 105261 | 105305 | } |
| | @@ -105353,11 +105397,11 @@ |
| 105353 | 105397 | pCol->pTab = pExpr->y.pTab; |
| 105354 | 105398 | pCol->iTable = pExpr->iTable; |
| 105355 | 105399 | pCol->iColumn = pExpr->iColumn; |
| 105356 | 105400 | pCol->iMem = ++pParse->nMem; |
| 105357 | 105401 | pCol->iSorterColumn = -1; |
| 105358 | | - pCol->pExpr = pExpr; |
| 105402 | + pCol->pCExpr = pExpr; |
| 105359 | 105403 | if( pAggInfo->pGroupBy ){ |
| 105360 | 105404 | int j, n; |
| 105361 | 105405 | ExprList *pGB = pAggInfo->pGroupBy; |
| 105362 | 105406 | struct ExprList_item *pTerm = pGB->a; |
| 105363 | 105407 | n = pGB->nExpr; |
| | @@ -105396,11 +105440,11 @@ |
| 105396 | 105440 | /* Check to see if pExpr is a duplicate of another aggregate |
| 105397 | 105441 | ** function that is already in the pAggInfo structure |
| 105398 | 105442 | */ |
| 105399 | 105443 | struct AggInfo_func *pItem = pAggInfo->aFunc; |
| 105400 | 105444 | for(i=0; i<pAggInfo->nFunc; i++, pItem++){ |
| 105401 | | - if( sqlite3ExprCompare(0, pItem->pExpr, pExpr, -1)==0 ){ |
| 105445 | + if( sqlite3ExprCompare(0, pItem->pFExpr, pExpr, -1)==0 ){ |
| 105402 | 105446 | break; |
| 105403 | 105447 | } |
| 105404 | 105448 | } |
| 105405 | 105449 | if( i>=pAggInfo->nFunc ){ |
| 105406 | 105450 | /* pExpr is original. Make a new entry in pAggInfo->aFunc[] |
| | @@ -105408,11 +105452,11 @@ |
| 105408 | 105452 | u8 enc = ENC(pParse->db); |
| 105409 | 105453 | i = addAggInfoFunc(pParse->db, pAggInfo); |
| 105410 | 105454 | if( i>=0 ){ |
| 105411 | 105455 | assert( !ExprHasProperty(pExpr, EP_xIsSelect) ); |
| 105412 | 105456 | pItem = &pAggInfo->aFunc[i]; |
| 105413 | | - pItem->pExpr = pExpr; |
| 105457 | + pItem->pFExpr = pExpr; |
| 105414 | 105458 | pItem->iMem = ++pParse->nMem; |
| 105415 | 105459 | assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 105416 | 105460 | pItem->pFunc = sqlite3FindFunction(pParse->db, |
| 105417 | 105461 | pExpr->u.zToken, |
| 105418 | 105462 | pExpr->x.pList ? pExpr->x.pList->nExpr : 0, enc, 0); |
| | @@ -105617,26 +105661,26 @@ |
| 105617 | 105661 | ** objects unusable. |
| 105618 | 105662 | */ |
| 105619 | 105663 | static void renameTestSchema(Parse *pParse, const char *zDb, int bTemp){ |
| 105620 | 105664 | sqlite3NestedParse(pParse, |
| 105621 | 105665 | "SELECT 1 " |
| 105622 | | - "FROM \"%w\".%s " |
| 105666 | + "FROM \"%w\"." DFLT_SCHEMA_TABLE " " |
| 105623 | 105667 | "WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X'" |
| 105624 | 105668 | " AND sql NOT LIKE 'create virtual%%'" |
| 105625 | 105669 | " AND sqlite_rename_test(%Q, sql, type, name, %d)=NULL ", |
| 105626 | | - zDb, MASTER_NAME, |
| 105670 | + zDb, |
| 105627 | 105671 | zDb, bTemp |
| 105628 | 105672 | ); |
| 105629 | 105673 | |
| 105630 | 105674 | if( bTemp==0 ){ |
| 105631 | 105675 | sqlite3NestedParse(pParse, |
| 105632 | 105676 | "SELECT 1 " |
| 105633 | | - "FROM temp.%s " |
| 105677 | + "FROM temp." DFLT_SCHEMA_TABLE " " |
| 105634 | 105678 | "WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X'" |
| 105635 | 105679 | " AND sql NOT LIKE 'create virtual%%'" |
| 105636 | 105680 | " AND sqlite_rename_test(%Q, sql, type, name, 1)=NULL ", |
| 105637 | | - MASTER_NAME, zDb |
| 105681 | + zDb |
| 105638 | 105682 | ); |
| 105639 | 105683 | } |
| 105640 | 105684 | } |
| 105641 | 105685 | |
| 105642 | 105686 | /* |
| | @@ -105750,31 +105794,31 @@ |
| 105750 | 105794 | nTabName = sqlite3Utf8CharLen(zTabName, -1); |
| 105751 | 105795 | |
| 105752 | 105796 | /* Rewrite all CREATE TABLE, INDEX, TRIGGER or VIEW statements in |
| 105753 | 105797 | ** the schema to use the new table name. */ |
| 105754 | 105798 | sqlite3NestedParse(pParse, |
| 105755 | | - "UPDATE \"%w\".%s SET " |
| 105799 | + "UPDATE \"%w\"." DFLT_SCHEMA_TABLE " SET " |
| 105756 | 105800 | "sql = sqlite_rename_table(%Q, type, name, sql, %Q, %Q, %d) " |
| 105757 | 105801 | "WHERE (type!='index' OR tbl_name=%Q COLLATE nocase)" |
| 105758 | 105802 | "AND name NOT LIKE 'sqliteX_%%' ESCAPE 'X'" |
| 105759 | | - , zDb, MASTER_NAME, zDb, zTabName, zName, (iDb==1), zTabName |
| 105803 | + , zDb, zDb, zTabName, zName, (iDb==1), zTabName |
| 105760 | 105804 | ); |
| 105761 | 105805 | |
| 105762 | | - /* Update the tbl_name and name columns of the sqlite_master table |
| 105806 | + /* Update the tbl_name and name columns of the sqlite_schema table |
| 105763 | 105807 | ** as required. */ |
| 105764 | 105808 | sqlite3NestedParse(pParse, |
| 105765 | | - "UPDATE %Q.%s SET " |
| 105809 | + "UPDATE %Q." DFLT_SCHEMA_TABLE " SET " |
| 105766 | 105810 | "tbl_name = %Q, " |
| 105767 | 105811 | "name = CASE " |
| 105768 | 105812 | "WHEN type='table' THEN %Q " |
| 105769 | 105813 | "WHEN name LIKE 'sqliteX_autoindex%%' ESCAPE 'X' " |
| 105770 | 105814 | " AND type='index' THEN " |
| 105771 | 105815 | "'sqlite_autoindex_' || %Q || substr(name,%d+18) " |
| 105772 | 105816 | "ELSE name END " |
| 105773 | 105817 | "WHERE tbl_name=%Q COLLATE nocase AND " |
| 105774 | 105818 | "(type='table' OR type='index' OR type='trigger');", |
| 105775 | | - zDb, MASTER_NAME, |
| 105819 | + zDb, |
| 105776 | 105820 | zName, zName, zName, |
| 105777 | 105821 | nTabName, zTabName |
| 105778 | 105822 | ); |
| 105779 | 105823 | |
| 105780 | 105824 | #ifndef SQLITE_OMIT_AUTOINCREMENT |
| | @@ -105791,11 +105835,11 @@ |
| 105791 | 105835 | /* If the table being renamed is not itself part of the temp database, |
| 105792 | 105836 | ** edit view and trigger definitions within the temp database |
| 105793 | 105837 | ** as required. */ |
| 105794 | 105838 | if( iDb!=1 ){ |
| 105795 | 105839 | sqlite3NestedParse(pParse, |
| 105796 | | - "UPDATE sqlite_temp_master SET " |
| 105840 | + "UPDATE sqlite_temp_schema SET " |
| 105797 | 105841 | "sql = sqlite_rename_table(%Q, type, name, sql, %Q, %Q, 1), " |
| 105798 | 105842 | "tbl_name = " |
| 105799 | 105843 | "CASE WHEN tbl_name=%Q COLLATE nocase AND " |
| 105800 | 105844 | " sqlite_rename_test(%Q, sql, type, name, 1) " |
| 105801 | 105845 | "THEN %Q ELSE tbl_name END " |
| | @@ -105947,14 +105991,14 @@ |
| 105947 | 105991 | while( zEnd>zCol && (*zEnd==';' || sqlite3Isspace(*zEnd)) ){ |
| 105948 | 105992 | *zEnd-- = '\0'; |
| 105949 | 105993 | } |
| 105950 | 105994 | db->mDbFlags |= DBFLAG_PreferBuiltin; |
| 105951 | 105995 | sqlite3NestedParse(pParse, |
| 105952 | | - "UPDATE \"%w\".%s SET " |
| 105996 | + "UPDATE \"%w\"." DFLT_SCHEMA_TABLE " SET " |
| 105953 | 105997 | "sql = substr(sql,1,%d) || ', ' || %Q || substr(sql,%d) " |
| 105954 | 105998 | "WHERE type = 'table' AND name = %Q", |
| 105955 | | - zDb, MASTER_NAME, pNew->addColOffset, zCol, pNew->addColOffset+1, |
| 105999 | + zDb, pNew->addColOffset, zCol, pNew->addColOffset+1, |
| 105956 | 106000 | zTab |
| 105957 | 106001 | ); |
| 105958 | 106002 | sqlite3DbFree(db, zCol); |
| 105959 | 106003 | db->mDbFlags = savedDbFlags; |
| 105960 | 106004 | } |
| | @@ -106152,33 +106196,32 @@ |
| 106152 | 106196 | goto exit_rename_column; |
| 106153 | 106197 | } |
| 106154 | 106198 | |
| 106155 | 106199 | /* Do the rename operation using a recursive UPDATE statement that |
| 106156 | 106200 | ** uses the sqlite_rename_column() SQL function to compute the new |
| 106157 | | - ** CREATE statement text for the sqlite_master table. |
| 106201 | + ** CREATE statement text for the sqlite_schema table. |
| 106158 | 106202 | */ |
| 106159 | 106203 | sqlite3MayAbort(pParse); |
| 106160 | 106204 | zNew = sqlite3NameFromToken(db, pNew); |
| 106161 | 106205 | if( !zNew ) goto exit_rename_column; |
| 106162 | 106206 | assert( pNew->n>0 ); |
| 106163 | 106207 | bQuote = sqlite3Isquote(pNew->z[0]); |
| 106164 | 106208 | sqlite3NestedParse(pParse, |
| 106165 | | - "UPDATE \"%w\".%s SET " |
| 106209 | + "UPDATE \"%w\"." DFLT_SCHEMA_TABLE " SET " |
| 106166 | 106210 | "sql = sqlite_rename_column(sql, type, name, %Q, %Q, %d, %Q, %d, %d) " |
| 106167 | 106211 | "WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X' " |
| 106168 | 106212 | " AND (type != 'index' OR tbl_name = %Q)" |
| 106169 | 106213 | " AND sql NOT LIKE 'create virtual%%'", |
| 106170 | | - zDb, MASTER_NAME, |
| 106214 | + zDb, |
| 106171 | 106215 | zDb, pTab->zName, iCol, zNew, bQuote, iSchema==1, |
| 106172 | 106216 | pTab->zName |
| 106173 | 106217 | ); |
| 106174 | 106218 | |
| 106175 | 106219 | sqlite3NestedParse(pParse, |
| 106176 | | - "UPDATE temp.%s SET " |
| 106220 | + "UPDATE temp." DFLT_SCHEMA_TABLE " SET " |
| 106177 | 106221 | "sql = sqlite_rename_column(sql, type, name, %Q, %Q, %d, %Q, %d, 1) " |
| 106178 | 106222 | "WHERE type IN ('trigger', 'view')", |
| 106179 | | - MASTER_NAME, |
| 106180 | 106223 | zDb, pTab->zName, iCol, zNew, bQuote |
| 106181 | 106224 | ); |
| 106182 | 106225 | |
| 106183 | 106226 | /* Drop and reload the database schema. */ |
| 106184 | 106227 | renameReloadSchema(pParse, iSchema); |
| | @@ -110403,11 +110446,11 @@ |
| 110403 | 110446 | ** this way, the final OP_Halt is not appended and other initialization |
| 110404 | 110447 | ** and finalization steps are omitted because those are handling by the |
| 110405 | 110448 | ** outermost parser. |
| 110406 | 110449 | ** |
| 110407 | 110450 | ** Not everything is nestable. This facility is designed to permit |
| 110408 | | -** INSERT, UPDATE, and DELETE operations against SQLITE_MASTER. Use |
| 110451 | +** INSERT, UPDATE, and DELETE operations against the schema table. Use |
| 110409 | 110452 | ** care if you decide to try to use this routine for some other purposes. |
| 110410 | 110453 | */ |
| 110411 | 110454 | SQLITE_PRIVATE void sqlite3NestedParse(Parse *pParse, const char *zFormat, ...){ |
| 110412 | 110455 | va_list ap; |
| 110413 | 110456 | char *zSql; |
| | @@ -110485,13 +110528,25 @@ |
| 110485 | 110528 | }else{ |
| 110486 | 110529 | return 0; |
| 110487 | 110530 | } |
| 110488 | 110531 | } |
| 110489 | 110532 | p = sqlite3HashFind(&db->aDb[i].pSchema->tblHash, zName); |
| 110490 | | - if( p==0 && i==1 && sqlite3StrICmp(zName, MASTER_NAME)==0 ){ |
| 110491 | | - /* All temp.sqlite_master to be an alias for sqlite_temp_master */ |
| 110492 | | - p = sqlite3HashFind(&db->aDb[1].pSchema->tblHash, TEMP_MASTER_NAME); |
| 110533 | + if( p==0 && sqlite3StrNICmp(zName, "sqlite_", 7)==0 ){ |
| 110534 | + if( i==1 ){ |
| 110535 | + if( sqlite3StrICmp(zName+7, ALT_TEMP_SCHEMA_TABLE+7)==0 |
| 110536 | + || sqlite3StrICmp(zName+7, ALT_SCHEMA_TABLE+7)==0 |
| 110537 | + || sqlite3StrICmp(zName+7, DFLT_SCHEMA_TABLE+7)==0 |
| 110538 | + ){ |
| 110539 | + p = sqlite3HashFind(&db->aDb[1].pSchema->tblHash, |
| 110540 | + DFLT_TEMP_SCHEMA_TABLE); |
| 110541 | + } |
| 110542 | + }else{ |
| 110543 | + if( sqlite3StrICmp(zName+7, ALT_SCHEMA_TABLE+7)==0 ){ |
| 110544 | + p = sqlite3HashFind(&db->aDb[i].pSchema->tblHash, |
| 110545 | + DFLT_SCHEMA_TABLE); |
| 110546 | + } |
| 110547 | + } |
| 110493 | 110548 | } |
| 110494 | 110549 | }else{ |
| 110495 | 110550 | /* Match against TEMP first */ |
| 110496 | 110551 | p = sqlite3HashFind(&db->aDb[1].pSchema->tblHash, zName); |
| 110497 | 110552 | if( p ) return p; |
| | @@ -110501,10 +110556,18 @@ |
| 110501 | 110556 | /* Attached databases are in order of attachment */ |
| 110502 | 110557 | for(i=2; i<db->nDb; i++){ |
| 110503 | 110558 | assert( sqlite3SchemaMutexHeld(db, i, 0) ); |
| 110504 | 110559 | p = sqlite3HashFind(&db->aDb[i].pSchema->tblHash, zName); |
| 110505 | 110560 | if( p ) break; |
| 110561 | + } |
| 110562 | + if( p==0 && sqlite3StrNICmp(zName, "sqlite_", 7)==0 ){ |
| 110563 | + if( sqlite3StrICmp(zName+7, ALT_SCHEMA_TABLE+7)==0 ){ |
| 110564 | + p = sqlite3HashFind(&db->aDb[0].pSchema->tblHash, DFLT_SCHEMA_TABLE); |
| 110565 | + }else if( sqlite3StrICmp(zName+7, ALT_TEMP_SCHEMA_TABLE+7)==0 ){ |
| 110566 | + p = sqlite3HashFind(&db->aDb[1].pSchema->tblHash, |
| 110567 | + DFLT_TEMP_SCHEMA_TABLE); |
| 110568 | + } |
| 110506 | 110569 | } |
| 110507 | 110570 | } |
| 110508 | 110571 | return p; |
| 110509 | 110572 | } |
| 110510 | 110573 | |
| | @@ -110893,17 +110956,17 @@ |
| 110893 | 110956 | } |
| 110894 | 110957 | return zName; |
| 110895 | 110958 | } |
| 110896 | 110959 | |
| 110897 | 110960 | /* |
| 110898 | | -** Open the sqlite_master table stored in database number iDb for |
| 110961 | +** Open the sqlite_schema table stored in database number iDb for |
| 110899 | 110962 | ** writing. The table is opened using cursor 0. |
| 110900 | 110963 | */ |
| 110901 | | -SQLITE_PRIVATE void sqlite3OpenMasterTable(Parse *p, int iDb){ |
| 110964 | +SQLITE_PRIVATE void sqlite3OpenSchemaTable(Parse *p, int iDb){ |
| 110902 | 110965 | Vdbe *v = sqlite3GetVdbe(p); |
| 110903 | | - sqlite3TableLock(p, iDb, MASTER_ROOT, 1, MASTER_NAME); |
| 110904 | | - sqlite3VdbeAddOp4Int(v, OP_OpenWrite, 0, MASTER_ROOT, iDb, 5); |
| 110966 | + sqlite3TableLock(p, iDb, SCHEMA_ROOT, 1, DFLT_SCHEMA_TABLE); |
| 110967 | + sqlite3VdbeAddOp4Int(v, OP_OpenWrite, 0, SCHEMA_ROOT, iDb, 5); |
| 110905 | 110968 | if( p->nTab==0 ){ |
| 110906 | 110969 | p->nTab = 1; |
| 110907 | 110970 | } |
| 110908 | 110971 | } |
| 110909 | 110972 | |
| | @@ -111007,11 +111070,11 @@ |
| 111007 | 111070 | ** unqualified name for a new schema object (table, index, view or |
| 111008 | 111071 | ** trigger). All names are legal except those that begin with the string |
| 111009 | 111072 | ** "sqlite_" (in upper, lower or mixed case). This portion of the namespace |
| 111010 | 111073 | ** is reserved for internal use. |
| 111011 | 111074 | ** |
| 111012 | | -** When parsing the sqlite_master table, this routine also checks to |
| 111075 | +** When parsing the sqlite_schema table, this routine also checks to |
| 111013 | 111076 | ** make sure the "type", "name", and "tbl_name" columns are consistent |
| 111014 | 111077 | ** with the SQL. |
| 111015 | 111078 | */ |
| 111016 | 111079 | SQLITE_PRIVATE int sqlite3CheckObjectName( |
| 111017 | 111080 | Parse *pParse, /* Parsing context */ |
| | @@ -111179,11 +111242,11 @@ |
| 111179 | 111242 | Vdbe *v; |
| 111180 | 111243 | int iDb; /* Database number to create the table in */ |
| 111181 | 111244 | Token *pName; /* Unqualified name of the table to create */ |
| 111182 | 111245 | |
| 111183 | 111246 | if( db->init.busy && db->init.newTnum==1 ){ |
| 111184 | | - /* Special case: Parsing the sqlite_master or sqlite_temp_master schema */ |
| 111247 | + /* Special case: Parsing the sqlite_schema or sqlite_temp_schema schema */ |
| 111185 | 111248 | iDb = db->init.iDb; |
| 111186 | 111249 | zName = sqlite3DbStrDup(db, SCHEMA_TABLE(iDb)); |
| 111187 | 111250 | pName = pName1; |
| 111188 | 111251 | }else{ |
| 111189 | 111252 | /* The common case */ |
| | @@ -111285,11 +111348,11 @@ |
| 111285 | 111348 | pTable->pSchema->pSeqTab = pTable; |
| 111286 | 111349 | } |
| 111287 | 111350 | #endif |
| 111288 | 111351 | |
| 111289 | 111352 | /* Begin generating the code that will insert the table record into |
| 111290 | | - ** the SQLITE_MASTER table. Note in particular that we must go ahead |
| 111353 | + ** the schema table. Note in particular that we must go ahead |
| 111291 | 111354 | ** and allocate the record number for the table entry now. Before any |
| 111292 | 111355 | ** PRIMARY KEY or UNIQUE keywords are parsed. Those keywords will cause |
| 111293 | 111356 | ** indices to be created and the table record must come before the |
| 111294 | 111357 | ** indices. Hence, the record number for the table must be allocated |
| 111295 | 111358 | ** now. |
| | @@ -111321,11 +111384,11 @@ |
| 111321 | 111384 | 1 : SQLITE_MAX_FILE_FORMAT; |
| 111322 | 111385 | sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_FILE_FORMAT, fileFormat); |
| 111323 | 111386 | sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_TEXT_ENCODING, ENC(db)); |
| 111324 | 111387 | sqlite3VdbeJumpHere(v, addr1); |
| 111325 | 111388 | |
| 111326 | | - /* This just creates a place-holder record in the sqlite_master table. |
| 111389 | + /* This just creates a place-holder record in the sqlite_schema table. |
| 111327 | 111390 | ** The record created does not contain anything yet. It will be replaced |
| 111328 | 111391 | ** by the real entry in code generated at sqlite3EndTable(). |
| 111329 | 111392 | ** |
| 111330 | 111393 | ** The rowid for the new entry is left in register pParse->regRowid. |
| 111331 | 111394 | ** The root page number of the new table is left in reg pParse->regRoot. |
| | @@ -111339,11 +111402,11 @@ |
| 111339 | 111402 | #endif |
| 111340 | 111403 | { |
| 111341 | 111404 | pParse->addrCrTab = |
| 111342 | 111405 | sqlite3VdbeAddOp3(v, OP_CreateBtree, iDb, reg2, BTREE_INTKEY); |
| 111343 | 111406 | } |
| 111344 | | - sqlite3OpenMasterTable(pParse, iDb); |
| 111407 | + sqlite3OpenSchemaTable(pParse, iDb); |
| 111345 | 111408 | sqlite3VdbeAddOp2(v, OP_NewRowid, 0, reg1); |
| 111346 | 111409 | sqlite3VdbeAddOp4(v, OP_Blob, 6, reg3, 0, nullRow, P4_STATIC); |
| 111347 | 111410 | sqlite3VdbeAddOp3(v, OP_Insert, 0, reg3, reg1); |
| 111348 | 111411 | sqlite3VdbeChangeP5(v, OPFLAG_APPEND); |
| 111349 | 111412 | sqlite3VdbeAddOp0(v, OP_Close); |
| | @@ -112149,13 +112212,13 @@ |
| 112149 | 112212 | ** Changes include: |
| 112150 | 112213 | ** |
| 112151 | 112214 | ** (1) Set all columns of the PRIMARY KEY schema object to be NOT NULL. |
| 112152 | 112215 | ** (2) Convert P3 parameter of the OP_CreateBtree from BTREE_INTKEY |
| 112153 | 112216 | ** into BTREE_BLOBKEY. |
| 112154 | | -** (3) Bypass the creation of the sqlite_master table entry |
| 112217 | +** (3) Bypass the creation of the sqlite_schema table entry |
| 112155 | 112218 | ** for the PRIMARY KEY as the primary key index is now |
| 112156 | | -** identified by the sqlite_master table entry of the table itself. |
| 112219 | +** identified by the sqlite_schema table entry of the table itself. |
| 112157 | 112220 | ** (4) Set the Index.tnum of the PRIMARY KEY Index object in the |
| 112158 | 112221 | ** schema to the rootpage from the main table. |
| 112159 | 112222 | ** (5) Add all table columns to the PRIMARY KEY Index object |
| 112160 | 112223 | ** so that the PRIMARY KEY is a covering index. The surplus |
| 112161 | 112224 | ** columns are part of KeyInfo.nAllField and are not used for |
| | @@ -112238,11 +112301,11 @@ |
| 112238 | 112301 | assert( pPk!=0 ); |
| 112239 | 112302 | pPk->isCovering = 1; |
| 112240 | 112303 | if( !db->init.imposterTable ) pPk->uniqNotNull = 1; |
| 112241 | 112304 | nPk = pPk->nColumn = pPk->nKeyCol; |
| 112242 | 112305 | |
| 112243 | | - /* Bypass the creation of the PRIMARY KEY btree and the sqlite_master |
| 112306 | + /* Bypass the creation of the PRIMARY KEY btree and the sqlite_schema |
| 112244 | 112307 | ** table entry. This is only required if currently generating VDBE |
| 112245 | 112308 | ** code for a CREATE TABLE (not when parsing one as part of reading |
| 112246 | 112309 | ** a database schema). */ |
| 112247 | 112310 | if( v && pPk->tnum>0 ){ |
| 112248 | 112311 | assert( db->init.busy==0 ); |
| | @@ -112386,16 +112449,16 @@ |
| 112386 | 112449 | ** |
| 112387 | 112450 | ** The table structure that other action routines have been building |
| 112388 | 112451 | ** is added to the internal hash tables, assuming no errors have |
| 112389 | 112452 | ** occurred. |
| 112390 | 112453 | ** |
| 112391 | | -** An entry for the table is made in the master table on disk, unless |
| 112454 | +** An entry for the table is made in the schema table on disk, unless |
| 112392 | 112455 | ** this is a temporary table or db->init.busy==1. When db->init.busy==1 |
| 112393 | | -** it means we are reading the sqlite_master table because we just |
| 112394 | | -** connected to the database or because the sqlite_master table has |
| 112456 | +** it means we are reading the sqlite_schema table because we just |
| 112457 | +** connected to the database or because the sqlite_schema table has |
| 112395 | 112458 | ** recently changed, so the entry for this table already exists in |
| 112396 | | -** the sqlite_master table. We do not want to create it again. |
| 112459 | +** the sqlite_schema table. We do not want to create it again. |
| 112397 | 112460 | ** |
| 112398 | 112461 | ** If the pSelect argument is not NULL, it means that this routine |
| 112399 | 112462 | ** was called to create a table generated from a |
| 112400 | 112463 | ** "CREATE TABLE ... AS SELECT ..." statement. The column names of |
| 112401 | 112464 | ** the new table will match the result set of the SELECT. |
| | @@ -112422,16 +112485,16 @@ |
| 112422 | 112485 | if( pSelect==0 && sqlite3ShadowTableName(db, p->zName) ){ |
| 112423 | 112486 | p->tabFlags |= TF_Shadow; |
| 112424 | 112487 | } |
| 112425 | 112488 | |
| 112426 | 112489 | /* If the db->init.busy is 1 it means we are reading the SQL off the |
| 112427 | | - ** "sqlite_master" or "sqlite_temp_master" table on the disk. |
| 112490 | + ** "sqlite_schema" or "sqlite_temp_schema" table on the disk. |
| 112428 | 112491 | ** So do not write to the disk again. Extract the root page number |
| 112429 | 112492 | ** for the table from the db->init.newTnum field. (The page number |
| 112430 | 112493 | ** should have been put there by the sqliteOpenCb routine.) |
| 112431 | 112494 | ** |
| 112432 | | - ** If the root page number is 1, that means this is the sqlite_master |
| 112495 | + ** If the root page number is 1, that means this is the sqlite_schema |
| 112433 | 112496 | ** table itself. So mark it read-only. |
| 112434 | 112497 | */ |
| 112435 | 112498 | if( db->init.busy ){ |
| 112436 | 112499 | if( pSelect ){ |
| 112437 | 112500 | sqlite3ErrorMsg(pParse, ""); |
| | @@ -112514,11 +112577,11 @@ |
| 112514 | 112577 | for(pIdx=p->pIndex; pIdx; pIdx=pIdx->pNext){ |
| 112515 | 112578 | estimateIndexWidth(pIdx); |
| 112516 | 112579 | } |
| 112517 | 112580 | |
| 112518 | 112581 | /* If not initializing, then create a record for the new table |
| 112519 | | - ** in the SQLITE_MASTER table of the database. |
| 112582 | + ** in the schema table of the database. |
| 112520 | 112583 | ** |
| 112521 | 112584 | ** If this is a TEMPORARY table, write the entry into the auxiliary |
| 112522 | 112585 | ** file instead of into the main database file. |
| 112523 | 112586 | */ |
| 112524 | 112587 | if( !db->init.busy ){ |
| | @@ -112616,18 +112679,18 @@ |
| 112616 | 112679 | "CREATE %s %.*s", zType2, n, pParse->sNameToken.z |
| 112617 | 112680 | ); |
| 112618 | 112681 | } |
| 112619 | 112682 | |
| 112620 | 112683 | /* A slot for the record has already been allocated in the |
| 112621 | | - ** SQLITE_MASTER table. We just need to update that slot with all |
| 112684 | + ** schema table. We just need to update that slot with all |
| 112622 | 112685 | ** the information we've collected. |
| 112623 | 112686 | */ |
| 112624 | 112687 | sqlite3NestedParse(pParse, |
| 112625 | | - "UPDATE %Q.%s " |
| 112626 | | - "SET type='%s', name=%Q, tbl_name=%Q, rootpage=#%d, sql=%Q " |
| 112627 | | - "WHERE rowid=#%d", |
| 112628 | | - db->aDb[iDb].zDbSName, MASTER_NAME, |
| 112688 | + "UPDATE %Q." DFLT_SCHEMA_TABLE |
| 112689 | + " SET type='%s', name=%Q, tbl_name=%Q, rootpage=#%d, sql=%Q" |
| 112690 | + " WHERE rowid=#%d", |
| 112691 | + db->aDb[iDb].zDbSName, |
| 112629 | 112692 | zType, |
| 112630 | 112693 | p->zName, |
| 112631 | 112694 | p->zName, |
| 112632 | 112695 | pParse->regRoot, |
| 112633 | 112696 | zStmt, |
| | @@ -112751,11 +112814,11 @@ |
| 112751 | 112814 | z = pBegin->z; |
| 112752 | 112815 | while( sqlite3Isspace(z[n-1]) ){ n--; } |
| 112753 | 112816 | sEnd.z = &z[n-1]; |
| 112754 | 112817 | sEnd.n = 1; |
| 112755 | 112818 | |
| 112756 | | - /* Use sqlite3EndTable() to add the view to the SQLITE_MASTER table */ |
| 112819 | + /* Use sqlite3EndTable() to add the view to the schema table */ |
| 112757 | 112820 | sqlite3EndTable(pParse, 0, &sEnd, 0, 0); |
| 112758 | 112821 | |
| 112759 | 112822 | create_view_fail: |
| 112760 | 112823 | sqlite3SelectDelete(db, pSelect); |
| 112761 | 112824 | if( IN_RENAME_OBJECT ){ |
| | @@ -112966,11 +113029,11 @@ |
| 112966 | 113029 | } |
| 112967 | 113030 | #endif |
| 112968 | 113031 | |
| 112969 | 113032 | /* |
| 112970 | 113033 | ** Write code to erase the table with root-page iTable from database iDb. |
| 112971 | | -** Also write code to modify the sqlite_master table and internal schema |
| 113034 | +** Also write code to modify the sqlite_schema table and internal schema |
| 112972 | 113035 | ** if a root-page of another table is moved by the btree-layer whilst |
| 112973 | 113036 | ** erasing iTable (this can happen with an auto-vacuum database). |
| 112974 | 113037 | */ |
| 112975 | 113038 | static void destroyRootPage(Parse *pParse, int iTable, int iDb){ |
| 112976 | 113039 | Vdbe *v = sqlite3GetVdbe(pParse); |
| | @@ -112979,27 +113042,28 @@ |
| 112979 | 113042 | sqlite3VdbeAddOp3(v, OP_Destroy, iTable, r1, iDb); |
| 112980 | 113043 | sqlite3MayAbort(pParse); |
| 112981 | 113044 | #ifndef SQLITE_OMIT_AUTOVACUUM |
| 112982 | 113045 | /* OP_Destroy stores an in integer r1. If this integer |
| 112983 | 113046 | ** is non-zero, then it is the root page number of a table moved to |
| 112984 | | - ** location iTable. The following code modifies the sqlite_master table to |
| 113047 | + ** location iTable. The following code modifies the sqlite_schema table to |
| 112985 | 113048 | ** reflect this. |
| 112986 | 113049 | ** |
| 112987 | 113050 | ** The "#NNN" in the SQL is a special constant that means whatever value |
| 112988 | 113051 | ** is in register NNN. See grammar rules associated with the TK_REGISTER |
| 112989 | 113052 | ** token for additional information. |
| 112990 | 113053 | */ |
| 112991 | 113054 | sqlite3NestedParse(pParse, |
| 112992 | | - "UPDATE %Q.%s SET rootpage=%d WHERE #%d AND rootpage=#%d", |
| 112993 | | - pParse->db->aDb[iDb].zDbSName, MASTER_NAME, iTable, r1, r1); |
| 113055 | + "UPDATE %Q." DFLT_SCHEMA_TABLE |
| 113056 | + " SET rootpage=%d WHERE #%d AND rootpage=#%d", |
| 113057 | + pParse->db->aDb[iDb].zDbSName, iTable, r1, r1); |
| 112994 | 113058 | #endif |
| 112995 | 113059 | sqlite3ReleaseTempReg(pParse, r1); |
| 112996 | 113060 | } |
| 112997 | 113061 | |
| 112998 | 113062 | /* |
| 112999 | 113063 | ** Write VDBE code to erase table pTab and all associated indices on disk. |
| 113000 | | -** Code to update the sqlite_master tables and internal schema definitions |
| 113064 | +** Code to update the sqlite_schema tables and internal schema definitions |
| 113001 | 113065 | ** in case a root-page belonging to another table is moved by the btree layer |
| 113002 | 113066 | ** is also added (this can happen with an auto-vacuum database). |
| 113003 | 113067 | */ |
| 113004 | 113068 | static void destroyTable(Parse *pParse, Table *pTab){ |
| 113005 | 113069 | /* If the database may be auto-vacuum capable (if SQLITE_OMIT_AUTOVACUUM |
| | @@ -113088,12 +113152,12 @@ |
| 113088 | 113152 | sqlite3VdbeAddOp0(v, OP_VBegin); |
| 113089 | 113153 | } |
| 113090 | 113154 | #endif |
| 113091 | 113155 | |
| 113092 | 113156 | /* Drop all triggers associated with the table being dropped. Code |
| 113093 | | - ** is generated to remove entries from sqlite_master and/or |
| 113094 | | - ** sqlite_temp_master if required. |
| 113157 | + ** is generated to remove entries from sqlite_schema and/or |
| 113158 | + ** sqlite_temp_schema if required. |
| 113095 | 113159 | */ |
| 113096 | 113160 | pTrigger = sqlite3TriggerList(pParse, pTab); |
| 113097 | 113161 | while( pTrigger ){ |
| 113098 | 113162 | assert( pTrigger->pSchema==pTab->pSchema || |
| 113099 | 113163 | pTrigger->pSchema==db->aDb[1].pSchema ); |
| | @@ -113113,20 +113177,21 @@ |
| 113113 | 113177 | pDb->zDbSName, pTab->zName |
| 113114 | 113178 | ); |
| 113115 | 113179 | } |
| 113116 | 113180 | #endif |
| 113117 | 113181 | |
| 113118 | | - /* Drop all SQLITE_MASTER table and index entries that refer to the |
| 113119 | | - ** table. The program name loops through the master table and deletes |
| 113182 | + /* Drop all entries in the schema table that refer to the |
| 113183 | + ** table. The program name loops through the schema table and deletes |
| 113120 | 113184 | ** every row that refers to a table of the same name as the one being |
| 113121 | 113185 | ** dropped. Triggers are handled separately because a trigger can be |
| 113122 | 113186 | ** created in the temp database that refers to a table in another |
| 113123 | 113187 | ** database. |
| 113124 | 113188 | */ |
| 113125 | 113189 | sqlite3NestedParse(pParse, |
| 113126 | | - "DELETE FROM %Q.%s WHERE tbl_name=%Q and type!='trigger'", |
| 113127 | | - pDb->zDbSName, MASTER_NAME, pTab->zName); |
| 113190 | + "DELETE FROM %Q." DFLT_SCHEMA_TABLE |
| 113191 | + " WHERE tbl_name=%Q and type!='trigger'", |
| 113192 | + pDb->zDbSName, pTab->zName); |
| 113128 | 113193 | if( !isView && !IsVirtual(pTab) ){ |
| 113129 | 113194 | destroyTable(pParse, pTab); |
| 113130 | 113195 | } |
| 113131 | 113196 | |
| 113132 | 113197 | /* Remove the table entry from SQLite's internal schema and modify |
| | @@ -113258,11 +113323,11 @@ |
| 113258 | 113323 | sqlite3ErrorMsg(pParse, "use DROP VIEW to delete view %s", pTab->zName); |
| 113259 | 113324 | goto exit_drop_table; |
| 113260 | 113325 | } |
| 113261 | 113326 | #endif |
| 113262 | 113327 | |
| 113263 | | - /* Generate code to remove the table from the master table |
| 113328 | + /* Generate code to remove the table from the schema table |
| 113264 | 113329 | ** on disk. |
| 113265 | 113330 | */ |
| 113266 | 113331 | v = sqlite3GetVdbe(pParse); |
| 113267 | 113332 | if( v ){ |
| 113268 | 113333 | sqlite3BeginWriteOperation(pParse, 1, iDb); |
| | @@ -113712,14 +113777,11 @@ |
| 113712 | 113777 | && db->init.busy==0 |
| 113713 | 113778 | && pTblName!=0 |
| 113714 | 113779 | #if SQLITE_USER_AUTHENTICATION |
| 113715 | 113780 | && sqlite3UserAuthTable(pTab->zName)==0 |
| 113716 | 113781 | #endif |
| 113717 | | -#ifdef SQLITE_ALLOW_SQLITE_MASTER_INDEX |
| 113718 | | - && sqlite3StrICmp(&pTab->zName[7],"master")!=0 |
| 113719 | | -#endif |
| 113720 | | - ){ |
| 113782 | + ){ |
| 113721 | 113783 | sqlite3ErrorMsg(pParse, "table %s may not be indexed", pTab->zName); |
| 113722 | 113784 | goto exit_create_index; |
| 113723 | 113785 | } |
| 113724 | 113786 | #ifndef SQLITE_OMIT_VIEW |
| 113725 | 113787 | if( pTab->pSelect ){ |
| | @@ -113737,11 +113799,11 @@ |
| 113737 | 113799 | /* |
| 113738 | 113800 | ** Find the name of the index. Make sure there is not already another |
| 113739 | 113801 | ** index or table with the same name. |
| 113740 | 113802 | ** |
| 113741 | 113803 | ** Exception: If we are reading the names of permanent indices from the |
| 113742 | | - ** sqlite_master table (because some other process changed the schema) and |
| 113804 | + ** sqlite_schema table (because some other process changed the schema) and |
| 113743 | 113805 | ** one of the index names collides with the name of a temporary table or |
| 113744 | 113806 | ** index, then we will continue to process this index. |
| 113745 | 113807 | ** |
| 113746 | 113808 | ** If pName==0 it means that we are |
| 113747 | 113809 | ** dealing with a primary key or UNIQUE constraint. We have to invent our |
| | @@ -114081,12 +114143,12 @@ |
| 114081 | 114143 | } |
| 114082 | 114144 | |
| 114083 | 114145 | /* If this is the initial CREATE INDEX statement (or CREATE TABLE if the |
| 114084 | 114146 | ** index is an implied index for a UNIQUE or PRIMARY KEY constraint) then |
| 114085 | 114147 | ** emit code to allocate the index rootpage on disk and make an entry for |
| 114086 | | - ** the index in the sqlite_master table and populate the index with |
| 114087 | | - ** content. But, do not do this if we are simply reading the sqlite_master |
| 114148 | + ** the index in the sqlite_schema table and populate the index with |
| 114149 | + ** content. But, do not do this if we are simply reading the sqlite_schema |
| 114088 | 114150 | ** table to parse the schema, or if this index is the PRIMARY KEY index |
| 114089 | 114151 | ** of a WITHOUT ROWID table. |
| 114090 | 114152 | ** |
| 114091 | 114153 | ** If pTblName==0 it means this index is generated as an implied PRIMARY KEY |
| 114092 | 114154 | ** or UNIQUE index in a CREATE TABLE statement. Since the table |
| | @@ -114126,15 +114188,15 @@ |
| 114126 | 114188 | /* An automatic index created by a PRIMARY KEY or UNIQUE constraint */ |
| 114127 | 114189 | /* zStmt = sqlite3MPrintf(""); */ |
| 114128 | 114190 | zStmt = 0; |
| 114129 | 114191 | } |
| 114130 | 114192 | |
| 114131 | | - /* Add an entry in sqlite_master for this index |
| 114193 | + /* Add an entry in sqlite_schema for this index |
| 114132 | 114194 | */ |
| 114133 | 114195 | sqlite3NestedParse(pParse, |
| 114134 | | - "INSERT INTO %Q.%s VALUES('index',%Q,%Q,#%d,%Q);", |
| 114135 | | - db->aDb[iDb].zDbSName, MASTER_NAME, |
| 114196 | + "INSERT INTO %Q." DFLT_SCHEMA_TABLE " VALUES('index',%Q,%Q,#%d,%Q);", |
| 114197 | + db->aDb[iDb].zDbSName, |
| 114136 | 114198 | pIndex->zName, |
| 114137 | 114199 | pTab->zName, |
| 114138 | 114200 | iMem, |
| 114139 | 114201 | zStmt |
| 114140 | 114202 | ); |
| | @@ -114295,17 +114357,17 @@ |
| 114295 | 114357 | goto exit_drop_index; |
| 114296 | 114358 | } |
| 114297 | 114359 | } |
| 114298 | 114360 | #endif |
| 114299 | 114361 | |
| 114300 | | - /* Generate code to remove the index and from the master table */ |
| 114362 | + /* Generate code to remove the index and from the schema table */ |
| 114301 | 114363 | v = sqlite3GetVdbe(pParse); |
| 114302 | 114364 | if( v ){ |
| 114303 | 114365 | sqlite3BeginWriteOperation(pParse, 1, iDb); |
| 114304 | 114366 | sqlite3NestedParse(pParse, |
| 114305 | | - "DELETE FROM %Q.%s WHERE name=%Q AND type='index'", |
| 114306 | | - db->aDb[iDb].zDbSName, MASTER_NAME, pIndex->zName |
| 114367 | + "DELETE FROM %Q." DFLT_SCHEMA_TABLE " WHERE name=%Q AND type='index'", |
| 114368 | + db->aDb[iDb].zDbSName, pIndex->zName |
| 114307 | 114369 | ); |
| 114308 | 114370 | sqlite3ClearStatTables(pParse, iDb, "idx", pIndex->zName); |
| 114309 | 114371 | sqlite3ChangeCookie(pParse, iDb); |
| 114310 | 114372 | destroyRootPage(pParse, pIndex->tnum, iDb); |
| 114311 | 114373 | sqlite3VdbeAddOp4(v, OP_DropIndex, iDb, 0, 0, pIndex->zName, 0); |
| | @@ -115852,11 +115914,11 @@ |
| 115852 | 115914 | ** A table is read-only if any of the following are true: |
| 115853 | 115915 | ** |
| 115854 | 115916 | ** 1) It is a virtual table and no implementation of the xUpdate method |
| 115855 | 115917 | ** has been provided |
| 115856 | 115918 | ** |
| 115857 | | -** 2) It is a system table (i.e. sqlite_master), this call is not |
| 115919 | +** 2) It is a system table (i.e. sqlite_schema), this call is not |
| 115858 | 115920 | ** part of a nested parse and writable_schema pragma has not |
| 115859 | 115921 | ** been specified |
| 115860 | 115922 | ** |
| 115861 | 115923 | ** 3) The table is a shadow table, the database connection is in |
| 115862 | 115924 | ** defensive mode, and the current sqlite3_prepare() |
| | @@ -122882,11 +122944,11 @@ |
| 122882 | 122944 | pSrc = sqlite3LocateTableItem(pParse, 0, pItem); |
| 122883 | 122945 | if( pSrc==0 ){ |
| 122884 | 122946 | return 0; /* FROM clause does not contain a real table */ |
| 122885 | 122947 | } |
| 122886 | 122948 | if( pSrc->tnum==pDest->tnum && pSrc->pSchema==pDest->pSchema ){ |
| 122887 | | - testcase( pSrc!=pDest ); /* Possible due to bad sqlite_master.rootpage */ |
| 122949 | + testcase( pSrc!=pDest ); /* Possible due to bad sqlite_schema.rootpage */ |
| 122888 | 122950 | return 0; /* tab1 and tab2 may not be the same table */ |
| 122889 | 122951 | } |
| 122890 | 122952 | if( HasRowid(pDest)!=HasRowid(pSrc) ){ |
| 122891 | 122953 | return 0; /* source and destination must both be WITHOUT ROWID or not */ |
| 122892 | 122954 | } |
| | @@ -124646,11 +124708,11 @@ |
| 124646 | 124708 | |
| 124647 | 124709 | /* |
| 124648 | 124710 | ** The following object holds the list of automatically loaded |
| 124649 | 124711 | ** extensions. |
| 124650 | 124712 | ** |
| 124651 | | -** This list is shared across threads. The SQLITE_MUTEX_STATIC_MASTER |
| 124713 | +** This list is shared across threads. The SQLITE_MUTEX_STATIC_MAIN |
| 124652 | 124714 | ** mutex must be held while accessing this list. |
| 124653 | 124715 | */ |
| 124654 | 124716 | typedef struct sqlite3AutoExtList sqlite3AutoExtList; |
| 124655 | 124717 | static SQLITE_WSD struct sqlite3AutoExtList { |
| 124656 | 124718 | u32 nExt; /* Number of entries in aExt[] */ |
| | @@ -124688,11 +124750,11 @@ |
| 124688 | 124750 | }else |
| 124689 | 124751 | #endif |
| 124690 | 124752 | { |
| 124691 | 124753 | u32 i; |
| 124692 | 124754 | #if SQLITE_THREADSAFE |
| 124693 | | - sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); |
| 124755 | + sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN); |
| 124694 | 124756 | #endif |
| 124695 | 124757 | wsdAutoextInit; |
| 124696 | 124758 | sqlite3_mutex_enter(mutex); |
| 124697 | 124759 | for(i=0; i<wsdAutoext.nExt; i++){ |
| 124698 | 124760 | if( wsdAutoext.aExt[i]==xInit ) break; |
| | @@ -124726,11 +124788,11 @@ |
| 124726 | 124788 | */ |
| 124727 | 124789 | SQLITE_API int sqlite3_cancel_auto_extension( |
| 124728 | 124790 | void (*xInit)(void) |
| 124729 | 124791 | ){ |
| 124730 | 124792 | #if SQLITE_THREADSAFE |
| 124731 | | - sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); |
| 124793 | + sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN); |
| 124732 | 124794 | #endif |
| 124733 | 124795 | int i; |
| 124734 | 124796 | int n = 0; |
| 124735 | 124797 | wsdAutoextInit; |
| 124736 | 124798 | sqlite3_mutex_enter(mutex); |
| | @@ -124753,11 +124815,11 @@ |
| 124753 | 124815 | #ifndef SQLITE_OMIT_AUTOINIT |
| 124754 | 124816 | if( sqlite3_initialize()==SQLITE_OK ) |
| 124755 | 124817 | #endif |
| 124756 | 124818 | { |
| 124757 | 124819 | #if SQLITE_THREADSAFE |
| 124758 | | - sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); |
| 124820 | + sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN); |
| 124759 | 124821 | #endif |
| 124760 | 124822 | wsdAutoextInit; |
| 124761 | 124823 | sqlite3_mutex_enter(mutex); |
| 124762 | 124824 | sqlite3_free(wsdAutoext.aExt); |
| 124763 | 124825 | wsdAutoext.aExt = 0; |
| | @@ -124783,11 +124845,11 @@ |
| 124783 | 124845 | return; |
| 124784 | 124846 | } |
| 124785 | 124847 | for(i=0; go; i++){ |
| 124786 | 124848 | char *zErrmsg; |
| 124787 | 124849 | #if SQLITE_THREADSAFE |
| 124788 | | - sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); |
| 124850 | + sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN); |
| 124789 | 124851 | #endif |
| 124790 | 124852 | #ifdef SQLITE_OMIT_LOAD_EXTENSION |
| 124791 | 124853 | const sqlite3_api_routines *pThunk = 0; |
| 124792 | 124854 | #else |
| 124793 | 124855 | const sqlite3_api_routines *pThunk = &sqlite3Apis; |
| | @@ -128205,11 +128267,11 @@ |
| 128205 | 128267 | #endif |
| 128206 | 128268 | Db *pDb; |
| 128207 | 128269 | char const *azArg[6]; |
| 128208 | 128270 | int meta[5]; |
| 128209 | 128271 | InitData initData; |
| 128210 | | - const char *zMasterName; |
| 128272 | + const char *zSchemaTabName; |
| 128211 | 128273 | int openedTransaction = 0; |
| 128212 | 128274 | int mask = ((db->mDbFlags & DBFLAG_EncodingFixed) | ~DBFLAG_EncodingFixed); |
| 128213 | 128275 | |
| 128214 | 128276 | assert( (db->mDbFlags & DBFLAG_SchemaKnownOk)==0 ); |
| 128215 | 128277 | assert( iDb>=0 && iDb<db->nDb ); |
| | @@ -128217,17 +128279,17 @@ |
| 128217 | 128279 | assert( sqlite3_mutex_held(db->mutex) ); |
| 128218 | 128280 | assert( iDb==1 || sqlite3BtreeHoldsMutex(db->aDb[iDb].pBt) ); |
| 128219 | 128281 | |
| 128220 | 128282 | db->init.busy = 1; |
| 128221 | 128283 | |
| 128222 | | - /* Construct the in-memory representation schema tables (sqlite_master or |
| 128223 | | - ** sqlite_temp_master) by invoking the parser directly. The appropriate |
| 128284 | + /* Construct the in-memory representation schema tables (sqlite_schema or |
| 128285 | + ** sqlite_temp_schema) by invoking the parser directly. The appropriate |
| 128224 | 128286 | ** table name will be inserted automatically by the parser so we can just |
| 128225 | 128287 | ** use the abbreviation "x" here. The parser will also automatically tag |
| 128226 | 128288 | ** the schema table as read-only. */ |
| 128227 | 128289 | azArg[0] = "table"; |
| 128228 | | - azArg[1] = zMasterName = SCHEMA_TABLE(iDb); |
| 128290 | + azArg[1] = zSchemaTabName = SCHEMA_TABLE(iDb); |
| 128229 | 128291 | azArg[2] = azArg[1]; |
| 128230 | 128292 | azArg[3] = "1"; |
| 128231 | 128293 | azArg[4] = "CREATE TABLE x(type text,name text,tbl_name text," |
| 128232 | 128294 | "rootpage int,sql text)"; |
| 128233 | 128295 | azArg[5] = 0; |
| | @@ -128361,11 +128423,11 @@ |
| 128361 | 128423 | assert( db->init.busy ); |
| 128362 | 128424 | { |
| 128363 | 128425 | char *zSql; |
| 128364 | 128426 | zSql = sqlite3MPrintf(db, |
| 128365 | 128427 | "SELECT*FROM\"%w\".%s ORDER BY rowid", |
| 128366 | | - db->aDb[iDb].zDbSName, zMasterName); |
| 128428 | + db->aDb[iDb].zDbSName, zSchemaTabName); |
| 128367 | 128429 | #ifndef SQLITE_OMIT_AUTHORIZATION |
| 128368 | 128430 | { |
| 128369 | 128431 | sqlite3_xauth xAuth; |
| 128370 | 128432 | xAuth = db->xAuth; |
| 128371 | 128433 | db->xAuth = 0; |
| | @@ -128391,11 +128453,11 @@ |
| 128391 | 128453 | /* Black magic: If the SQLITE_NoSchemaError flag is set, then consider |
| 128392 | 128454 | ** the schema loaded, even if errors occurred. In this situation the |
| 128393 | 128455 | ** current sqlite3_prepare() operation will fail, but the following one |
| 128394 | 128456 | ** will attempt to compile the supplied statement against whatever subset |
| 128395 | 128457 | ** of the schema was loaded before the error occurred. The primary |
| 128396 | | - ** purpose of this is to allow access to the sqlite_master table |
| 128458 | + ** purpose of this is to allow access to the sqlite_schema table |
| 128397 | 128459 | ** even when its contents have been corrupted. |
| 128398 | 128460 | */ |
| 128399 | 128461 | DbSetProperty(db, iDb, DB_SchemaLoaded); |
| 128400 | 128462 | rc = SQLITE_OK; |
| 128401 | 128463 | } |
| | @@ -128771,11 +128833,11 @@ |
| 128771 | 128833 | /* |
| 128772 | 128834 | ** Rerun the compilation of a statement after a schema change. |
| 128773 | 128835 | ** |
| 128774 | 128836 | ** If the statement is successfully recompiled, return SQLITE_OK. Otherwise, |
| 128775 | 128837 | ** if the statement cannot be recompiled because another connection has |
| 128776 | | -** locked the sqlite3_master table, return SQLITE_LOCKED. If any other error |
| 128838 | +** locked the sqlite3_schema table, return SQLITE_LOCKED. If any other error |
| 128777 | 128839 | ** occurs, return SQLITE_SCHEMA. |
| 128778 | 128840 | */ |
| 128779 | 128841 | SQLITE_PRIVATE int sqlite3Reprepare(Vdbe *p){ |
| 128780 | 128842 | int rc; |
| 128781 | 128843 | sqlite3_stmt *pNew; |
| | @@ -128988,24 +129050,10 @@ |
| 128988 | 129050 | ************************************************************************* |
| 128989 | 129051 | ** This file contains C code routines that are called by the parser |
| 128990 | 129052 | ** to handle SELECT statements in SQLite. |
| 128991 | 129053 | */ |
| 128992 | 129054 | /* #include "sqliteInt.h" */ |
| 128993 | | - |
| 128994 | | -/* |
| 128995 | | -** Trace output macros |
| 128996 | | -*/ |
| 128997 | | -#if SELECTTRACE_ENABLED |
| 128998 | | -/***/ int sqlite3SelectTrace = 0; |
| 128999 | | -# define SELECTTRACE(K,P,S,X) \ |
| 129000 | | - if(sqlite3SelectTrace&(K)) \ |
| 129001 | | - sqlite3DebugPrintf("%u/%d/%p: ",(S)->selId,(P)->addrExplain,(S)),\ |
| 129002 | | - sqlite3DebugPrintf X |
| 129003 | | -#else |
| 129004 | | -# define SELECTTRACE(K,P,S,X) |
| 129005 | | -#endif |
| 129006 | | - |
| 129007 | 129055 | |
| 129008 | 129056 | /* |
| 129009 | 129057 | ** An instance of the following object is used to record information about |
| 129010 | 129058 | ** how to process the DISTINCT keyword, to simplify passing that information |
| 129011 | 129059 | ** into the selectInnerLoop() routine. |
| | @@ -131691,13 +131739,11 @@ |
| 131691 | 131739 | uniondest.eDest = op; |
| 131692 | 131740 | ExplainQueryPlan((pParse, 1, "%s USING TEMP B-TREE", |
| 131693 | 131741 | selectOpName(p->op))); |
| 131694 | 131742 | rc = sqlite3Select(pParse, p, &uniondest); |
| 131695 | 131743 | testcase( rc!=SQLITE_OK ); |
| 131696 | | - /* Query flattening in sqlite3Select() might refill p->pOrderBy. |
| 131697 | | - ** Be sure to delete p->pOrderBy, therefore, to avoid a memory leak. */ |
| 131698 | | - sqlite3ExprListDelete(db, p->pOrderBy); |
| 131744 | + assert( p->pOrderBy==0 ); |
| 131699 | 131745 | pDelete = p->pPrior; |
| 131700 | 131746 | p->pPrior = pPrior; |
| 131701 | 131747 | p->pOrderBy = 0; |
| 131702 | 131748 | if( p->op==TK_UNION ){ |
| 131703 | 131749 | p->nSelectRow = sqlite3LogEstAdd(p->nSelectRow, pPrior->nSelectRow); |
| | @@ -133080,11 +133126,11 @@ |
| 133080 | 133126 | ** \_____________________ outer query ______________________________/ |
| 133081 | 133127 | ** |
| 133082 | 133128 | ** We look at every expression in the outer query and every place we see |
| 133083 | 133129 | ** "a" we substitute "x*3" and every place we see "b" we substitute "y+10". |
| 133084 | 133130 | */ |
| 133085 | | - if( pSub->pOrderBy ){ |
| 133131 | + if( pSub->pOrderBy && (pParent->selFlags & SF_NoopOrderBy)==0 ){ |
| 133086 | 133132 | /* At this point, any non-zero iOrderByCol values indicate that the |
| 133087 | 133133 | ** ORDER BY column expression is identical to the iOrderByCol'th |
| 133088 | 133134 | ** expression returned by SELECT statement pSub. Since these values |
| 133089 | 133135 | ** do not necessarily correspond to columns in SELECT statement pParent, |
| 133090 | 133136 | ** zero them before transfering the ORDER BY clause. |
| | @@ -133104,11 +133150,17 @@ |
| 133104 | 133150 | pWhere = pSub->pWhere; |
| 133105 | 133151 | pSub->pWhere = 0; |
| 133106 | 133152 | if( isLeftJoin>0 ){ |
| 133107 | 133153 | sqlite3SetJoinExpr(pWhere, iNewParent); |
| 133108 | 133154 | } |
| 133109 | | - pParent->pWhere = sqlite3ExprAnd(pParse, pWhere, pParent->pWhere); |
| 133155 | + if( pWhere ){ |
| 133156 | + if( pParent->pWhere ){ |
| 133157 | + pParent->pWhere = sqlite3PExpr(pParse, TK_AND, pWhere, pParent->pWhere); |
| 133158 | + }else{ |
| 133159 | + pParent->pWhere = pWhere; |
| 133160 | + } |
| 133161 | + } |
| 133110 | 133162 | if( db->mallocFailed==0 ){ |
| 133111 | 133163 | SubstContext x; |
| 133112 | 133164 | x.pParse = pParse; |
| 133113 | 133165 | x.iTable = iParent; |
| 133114 | 133166 | x.iNewTable = iNewParent; |
| | @@ -133403,15 +133455,18 @@ |
| 133403 | 133455 | int iCursor, /* Cursor number of the subquery */ |
| 133404 | 133456 | int isLeftJoin /* True if pSubq is the right term of a LEFT JOIN */ |
| 133405 | 133457 | ){ |
| 133406 | 133458 | Expr *pNew; |
| 133407 | 133459 | int nChng = 0; |
| 133460 | + Select *pSel; |
| 133408 | 133461 | if( pWhere==0 ) return 0; |
| 133409 | 133462 | if( pSubq->selFlags & SF_Recursive ) return 0; /* restriction (2) */ |
| 133410 | 133463 | |
| 133411 | 133464 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 133412 | | - if( pSubq->pWin ) return 0; /* restriction (6) */ |
| 133465 | + for(pSel=pSubq; pSel; pSel=pSel->pPrior){ |
| 133466 | + if( pSel->pWin ) return 0; /* restriction (6) */ |
| 133467 | + } |
| 133413 | 133468 | #endif |
| 133414 | 133469 | |
| 133415 | 133470 | #ifdef SQLITE_DEBUG |
| 133416 | 133471 | /* Only the first term of a compound can have a WITH clause. But make |
| 133417 | 133472 | ** sure no other terms are marked SF_Recursive in case something changes |
| | @@ -133607,10 +133662,18 @@ |
| 133607 | 133662 | if( p->pPrior==0 ) return WRC_Continue; |
| 133608 | 133663 | if( p->pOrderBy==0 ) return WRC_Continue; |
| 133609 | 133664 | for(pX=p; pX && (pX->op==TK_ALL || pX->op==TK_SELECT); pX=pX->pPrior){} |
| 133610 | 133665 | if( pX==0 ) return WRC_Continue; |
| 133611 | 133666 | a = p->pOrderBy->a; |
| 133667 | +#ifndef SQLITE_OMIT_WINDOWFUNC |
| 133668 | + /* If iOrderByCol is already non-zero, then it has already been matched |
| 133669 | + ** to a result column of the SELECT statement. This occurs when the |
| 133670 | + ** SELECT is rewritten for window-functions processing and then passed |
| 133671 | + ** to sqlite3SelectPrep() and similar a second time. The rewriting done |
| 133672 | + ** by this function is not required in this case. */ |
| 133673 | + if( a[0].u.x.iOrderByCol ) return WRC_Continue; |
| 133674 | +#endif |
| 133612 | 133675 | for(i=p->pOrderBy->nExpr-1; i>=0; i--){ |
| 133613 | 133676 | if( a[i].pExpr->flags & EP_Collate ) break; |
| 133614 | 133677 | } |
| 133615 | 133678 | if( i<0 ) return WRC_Continue; |
| 133616 | 133679 | |
| | @@ -134364,11 +134427,11 @@ |
| 134364 | 134427 | } |
| 134365 | 134428 | #endif |
| 134366 | 134429 | sqlite3VdbeAddOp3(v, OP_Null, 0, pAggInfo->mnReg, pAggInfo->mxReg); |
| 134367 | 134430 | for(pFunc=pAggInfo->aFunc, i=0; i<pAggInfo->nFunc; i++, pFunc++){ |
| 134368 | 134431 | if( pFunc->iDistinct>=0 ){ |
| 134369 | | - Expr *pE = pFunc->pExpr; |
| 134432 | + Expr *pE = pFunc->pFExpr; |
| 134370 | 134433 | assert( !ExprHasProperty(pE, EP_xIsSelect) ); |
| 134371 | 134434 | if( pE->x.pList==0 || pE->x.pList->nExpr!=1 ){ |
| 134372 | 134435 | sqlite3ErrorMsg(pParse, "DISTINCT aggregates must have exactly one " |
| 134373 | 134436 | "argument"); |
| 134374 | 134437 | pFunc->iDistinct = -1; |
| | @@ -134388,12 +134451,12 @@ |
| 134388 | 134451 | static void finalizeAggFunctions(Parse *pParse, AggInfo *pAggInfo){ |
| 134389 | 134452 | Vdbe *v = pParse->pVdbe; |
| 134390 | 134453 | int i; |
| 134391 | 134454 | struct AggInfo_func *pF; |
| 134392 | 134455 | for(i=0, pF=pAggInfo->aFunc; i<pAggInfo->nFunc; i++, pF++){ |
| 134393 | | - ExprList *pList = pF->pExpr->x.pList; |
| 134394 | | - assert( !ExprHasProperty(pF->pExpr, EP_xIsSelect) ); |
| 134456 | + ExprList *pList = pF->pFExpr->x.pList; |
| 134457 | + assert( !ExprHasProperty(pF->pFExpr, EP_xIsSelect) ); |
| 134395 | 134458 | sqlite3VdbeAddOp2(v, OP_AggFinal, pF->iMem, pList ? pList->nExpr : 0); |
| 134396 | 134459 | sqlite3VdbeAppendP4(v, pF->pFunc, P4_FUNCDEF); |
| 134397 | 134460 | } |
| 134398 | 134461 | } |
| 134399 | 134462 | |
| | @@ -134418,15 +134481,15 @@ |
| 134418 | 134481 | pAggInfo->directMode = 1; |
| 134419 | 134482 | for(i=0, pF=pAggInfo->aFunc; i<pAggInfo->nFunc; i++, pF++){ |
| 134420 | 134483 | int nArg; |
| 134421 | 134484 | int addrNext = 0; |
| 134422 | 134485 | int regAgg; |
| 134423 | | - ExprList *pList = pF->pExpr->x.pList; |
| 134424 | | - assert( !ExprHasProperty(pF->pExpr, EP_xIsSelect) ); |
| 134425 | | - assert( !IsWindowFunc(pF->pExpr) ); |
| 134426 | | - if( ExprHasProperty(pF->pExpr, EP_WinFunc) ){ |
| 134427 | | - Expr *pFilter = pF->pExpr->y.pWin->pFilter; |
| 134486 | + ExprList *pList = pF->pFExpr->x.pList; |
| 134487 | + assert( !ExprHasProperty(pF->pFExpr, EP_xIsSelect) ); |
| 134488 | + assert( !IsWindowFunc(pF->pFExpr) ); |
| 134489 | + if( ExprHasProperty(pF->pFExpr, EP_WinFunc) ){ |
| 134490 | + Expr *pFilter = pF->pFExpr->y.pWin->pFilter; |
| 134428 | 134491 | if( pAggInfo->nAccumulator |
| 134429 | 134492 | && (pF->pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL) |
| 134430 | 134493 | ){ |
| 134431 | 134494 | if( regHit==0 ) regHit = ++pParse->nMem; |
| 134432 | 134495 | /* If this is the first row of the group (regAcc==0), clear the |
| | @@ -134484,11 +134547,11 @@ |
| 134484 | 134547 | } |
| 134485 | 134548 | if( regHit ){ |
| 134486 | 134549 | addrHitTest = sqlite3VdbeAddOp1(v, OP_If, regHit); VdbeCoverage(v); |
| 134487 | 134550 | } |
| 134488 | 134551 | for(i=0, pC=pAggInfo->aCol; i<pAggInfo->nAccumulator; i++, pC++){ |
| 134489 | | - sqlite3ExprCode(pParse, pC->pExpr, pC->iMem); |
| 134552 | + sqlite3ExprCode(pParse, pC->pCExpr, pC->iMem); |
| 134490 | 134553 | } |
| 134491 | 134554 | |
| 134492 | 134555 | pAggInfo->directMode = 0; |
| 134493 | 134556 | if( addrHitTest ){ |
| 134494 | 134557 | sqlite3VdbeJumpHereOrPopInst(v, addrHitTest); |
| | @@ -134763,10 +134826,11 @@ |
| 134763 | 134826 | /* If ORDER BY makes no difference in the output then neither does |
| 134764 | 134827 | ** DISTINCT so it can be removed too. */ |
| 134765 | 134828 | sqlite3ExprListDelete(db, p->pOrderBy); |
| 134766 | 134829 | p->pOrderBy = 0; |
| 134767 | 134830 | p->selFlags &= ~SF_Distinct; |
| 134831 | + p->selFlags |= SF_NoopOrderBy; |
| 134768 | 134832 | } |
| 134769 | 134833 | sqlite3SelectPrep(pParse, p, 0); |
| 134770 | 134834 | if( pParse->nErr || db->mallocFailed ){ |
| 134771 | 134835 | goto select_end; |
| 134772 | 134836 | } |
| | @@ -134798,18 +134862,23 @@ |
| 134798 | 134862 | pTabList = p->pSrc; |
| 134799 | 134863 | isAgg = (p->selFlags & SF_Aggregate)!=0; |
| 134800 | 134864 | memset(&sSort, 0, sizeof(sSort)); |
| 134801 | 134865 | sSort.pOrderBy = p->pOrderBy; |
| 134802 | 134866 | |
| 134803 | | - /* Try to various optimizations (flattening subqueries, and strength |
| 134867 | + /* Try to do various optimizations (flattening subqueries, and strength |
| 134804 | 134868 | ** reduction of join operators) in the FROM clause up into the main query |
| 134805 | 134869 | */ |
| 134806 | 134870 | #if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) |
| 134807 | 134871 | for(i=0; !p->pPrior && i<pTabList->nSrc; i++){ |
| 134808 | 134872 | struct SrcList_item *pItem = &pTabList->a[i]; |
| 134809 | 134873 | Select *pSub = pItem->pSelect; |
| 134810 | 134874 | Table *pTab = pItem->pTab; |
| 134875 | + |
| 134876 | + /* The expander should have already created transient Table objects |
| 134877 | + ** even for FROM clause elements such as subqueries that do not correspond |
| 134878 | + ** to a real table */ |
| 134879 | + assert( pTab!=0 ); |
| 134811 | 134880 | |
| 134812 | 134881 | /* Convert LEFT JOIN into JOIN if there are terms of the right table |
| 134813 | 134882 | ** of the LEFT JOIN used in the WHERE clause. |
| 134814 | 134883 | */ |
| 134815 | 134884 | if( (pItem->fg.jointype & JT_LEFT)!=0 |
| | @@ -135198,11 +135267,11 @@ |
| 135198 | 135267 | if( !isAgg && pGroupBy==0 ){ |
| 135199 | 135268 | /* No aggregate functions and no GROUP BY clause */ |
| 135200 | 135269 | u16 wctrlFlags = (sDistinct.isTnct ? WHERE_WANT_DISTINCT : 0) |
| 135201 | 135270 | | (p->selFlags & SF_FixedLimit); |
| 135202 | 135271 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 135203 | | - Window *pWin = p->pWin; /* Master window object (or NULL) */ |
| 135272 | + Window *pWin = p->pWin; /* Main window object (or NULL) */ |
| 135204 | 135273 | if( pWin ){ |
| 135205 | 135274 | sqlite3WindowCodeInit(pParse, p); |
| 135206 | 135275 | } |
| 135207 | 135276 | #endif |
| 135208 | 135277 | assert( WHERE_USE_LIMIT==SF_FixedLimit ); |
| | @@ -135337,10 +135406,11 @@ |
| 135337 | 135406 | if( pAggInfo==0 ){ |
| 135338 | 135407 | goto select_end; |
| 135339 | 135408 | } |
| 135340 | 135409 | pAggInfo->pNext = pParse->pAggList; |
| 135341 | 135410 | pParse->pAggList = pAggInfo; |
| 135411 | + pAggInfo->selId = p->selId; |
| 135342 | 135412 | memset(&sNC, 0, sizeof(sNC)); |
| 135343 | 135413 | sNC.pParse = pParse; |
| 135344 | 135414 | sNC.pSrcList = pTabList; |
| 135345 | 135415 | sNC.uNC.pAggInfo = pAggInfo; |
| 135346 | 135416 | VVA_ONLY( sNC.ncFlags = NC_UAggInfo; ) |
| | @@ -135359,16 +135429,16 @@ |
| 135359 | 135429 | } |
| 135360 | 135430 | sqlite3ExprAnalyzeAggregates(&sNC, pHaving); |
| 135361 | 135431 | } |
| 135362 | 135432 | pAggInfo->nAccumulator = pAggInfo->nColumn; |
| 135363 | 135433 | if( p->pGroupBy==0 && p->pHaving==0 && pAggInfo->nFunc==1 ){ |
| 135364 | | - minMaxFlag = minMaxQuery(db, pAggInfo->aFunc[0].pExpr, &pMinMaxOrderBy); |
| 135434 | + minMaxFlag = minMaxQuery(db, pAggInfo->aFunc[0].pFExpr, &pMinMaxOrderBy); |
| 135365 | 135435 | }else{ |
| 135366 | 135436 | minMaxFlag = WHERE_ORDERBY_NORMAL; |
| 135367 | 135437 | } |
| 135368 | 135438 | for(i=0; i<pAggInfo->nFunc; i++){ |
| 135369 | | - Expr *pExpr = pAggInfo->aFunc[i].pExpr; |
| 135439 | + Expr *pExpr = pAggInfo->aFunc[i].pFExpr; |
| 135370 | 135440 | assert( !ExprHasProperty(pExpr, EP_xIsSelect) ); |
| 135371 | 135441 | sNC.ncFlags |= NC_InAggFunc; |
| 135372 | 135442 | sqlite3ExprAnalyzeAggList(&sNC, pExpr->x.pList); |
| 135373 | 135443 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 135374 | 135444 | assert( !IsWindowFunc(pExpr) ); |
| | @@ -135386,16 +135456,16 @@ |
| 135386 | 135456 | SELECTTRACE(0x400,pParse,p,("After aggregate analysis %p:\n", pAggInfo)); |
| 135387 | 135457 | sqlite3TreeViewSelect(0, p, 0); |
| 135388 | 135458 | for(ii=0; ii<pAggInfo->nColumn; ii++){ |
| 135389 | 135459 | sqlite3DebugPrintf("agg-column[%d] iMem=%d\n", |
| 135390 | 135460 | ii, pAggInfo->aCol[ii].iMem); |
| 135391 | | - sqlite3TreeViewExpr(0, pAggInfo->aCol[ii].pExpr, 0); |
| 135461 | + sqlite3TreeViewExpr(0, pAggInfo->aCol[ii].pCExpr, 0); |
| 135392 | 135462 | } |
| 135393 | 135463 | for(ii=0; ii<pAggInfo->nFunc; ii++){ |
| 135394 | 135464 | sqlite3DebugPrintf("agg-func[%d]: iMem=%d\n", |
| 135395 | 135465 | ii, pAggInfo->aFunc[ii].iMem); |
| 135396 | | - sqlite3TreeViewExpr(0, pAggInfo->aFunc[ii].pExpr, 0); |
| 135466 | + sqlite3TreeViewExpr(0, pAggInfo->aFunc[ii].pFExpr, 0); |
| 135397 | 135467 | } |
| 135398 | 135468 | } |
| 135399 | 135469 | #endif |
| 135400 | 135470 | |
| 135401 | 135471 | |
| | @@ -135696,11 +135766,11 @@ |
| 135696 | 135766 | ** first row visited by the aggregate, so that they are updated at |
| 135697 | 135767 | ** least once even if the FILTER clause means the min() or max() |
| 135698 | 135768 | ** function visits zero rows. */ |
| 135699 | 135769 | if( pAggInfo->nAccumulator ){ |
| 135700 | 135770 | for(i=0; i<pAggInfo->nFunc; i++){ |
| 135701 | | - if( ExprHasProperty(pAggInfo->aFunc[i].pExpr, EP_WinFunc) ){ |
| 135771 | + if( ExprHasProperty(pAggInfo->aFunc[i].pFExpr, EP_WinFunc) ){ |
| 135702 | 135772 | continue; |
| 135703 | 135773 | } |
| 135704 | 135774 | if( pAggInfo->aFunc[i].pFunc->funcFlags&SQLITE_FUNC_NEEDCOLL ){ |
| 135705 | 135775 | break; |
| 135706 | 135776 | } |
| | @@ -135778,20 +135848,20 @@ |
| 135778 | 135848 | ** successful coding of the SELECT. |
| 135779 | 135849 | */ |
| 135780 | 135850 | select_end: |
| 135781 | 135851 | sqlite3ExprListDelete(db, pMinMaxOrderBy); |
| 135782 | 135852 | #ifdef SQLITE_DEBUG |
| 135783 | | - if( pAggInfo ){ |
| 135853 | + if( pAggInfo && !db->mallocFailed ){ |
| 135784 | 135854 | for(i=0; i<pAggInfo->nColumn; i++){ |
| 135785 | | - Expr *pExpr = pAggInfo->aCol[i].pExpr; |
| 135855 | + Expr *pExpr = pAggInfo->aCol[i].pCExpr; |
| 135786 | 135856 | assert( pExpr!=0 || db->mallocFailed ); |
| 135787 | 135857 | if( pExpr==0 ) continue; |
| 135788 | 135858 | assert( pExpr->pAggInfo==pAggInfo ); |
| 135789 | 135859 | assert( pExpr->iAgg==i ); |
| 135790 | 135860 | } |
| 135791 | 135861 | for(i=0; i<pAggInfo->nFunc; i++){ |
| 135792 | | - Expr *pExpr = pAggInfo->aFunc[i].pExpr; |
| 135862 | + Expr *pExpr = pAggInfo->aFunc[i].pFExpr; |
| 135793 | 135863 | assert( pExpr!=0 || db->mallocFailed ); |
| 135794 | 135864 | if( pExpr==0 ) continue; |
| 135795 | 135865 | assert( pExpr->pAggInfo==pAggInfo ); |
| 135796 | 135866 | assert( pExpr->iAgg==i ); |
| 135797 | 135867 | } |
| | @@ -136139,11 +136209,11 @@ |
| 136139 | 136209 | ** |
| 136140 | 136210 | ** CREATE TRIGGER attached.demo AFTER INSERT ON attached.tab .... |
| 136141 | 136211 | ** ^^^^^^^^ |
| 136142 | 136212 | ** |
| 136143 | 136213 | ** To maintain backwards compatibility, ignore the database |
| 136144 | | - ** name on pTableName if we are reparsing out of SQLITE_MASTER. |
| 136214 | + ** name on pTableName if we are reparsing out of the schema table |
| 136145 | 136215 | */ |
| 136146 | 136216 | if( db->init.busy && iDb!=1 ){ |
| 136147 | 136217 | sqlite3DbFree(db, pTableName->a[0].zDatabase); |
| 136148 | 136218 | pTableName->a[0].zDatabase = 0; |
| 136149 | 136219 | } |
| | @@ -136329,25 +136399,26 @@ |
| 136329 | 136399 | pTrig = 0; |
| 136330 | 136400 | }else |
| 136331 | 136401 | #endif |
| 136332 | 136402 | |
| 136333 | 136403 | /* if we are not initializing, |
| 136334 | | - ** build the sqlite_master entry |
| 136404 | + ** build the sqlite_schema entry |
| 136335 | 136405 | */ |
| 136336 | 136406 | if( !db->init.busy ){ |
| 136337 | 136407 | Vdbe *v; |
| 136338 | 136408 | char *z; |
| 136339 | 136409 | |
| 136340 | | - /* Make an entry in the sqlite_master table */ |
| 136410 | + /* Make an entry in the sqlite_schema table */ |
| 136341 | 136411 | v = sqlite3GetVdbe(pParse); |
| 136342 | 136412 | if( v==0 ) goto triggerfinish_cleanup; |
| 136343 | 136413 | sqlite3BeginWriteOperation(pParse, 0, iDb); |
| 136344 | 136414 | z = sqlite3DbStrNDup(db, (char*)pAll->z, pAll->n); |
| 136345 | 136415 | testcase( z==0 ); |
| 136346 | 136416 | sqlite3NestedParse(pParse, |
| 136347 | | - "INSERT INTO %Q.%s VALUES('trigger',%Q,%Q,0,'CREATE TRIGGER %q')", |
| 136348 | | - db->aDb[iDb].zDbSName, MASTER_NAME, zName, |
| 136417 | + "INSERT INTO %Q." DFLT_SCHEMA_TABLE |
| 136418 | + " VALUES('trigger',%Q,%Q,0,'CREATE TRIGGER %q')", |
| 136419 | + db->aDb[iDb].zDbSName, zName, |
| 136349 | 136420 | pTrig->table, z); |
| 136350 | 136421 | sqlite3DbFree(db, z); |
| 136351 | 136422 | sqlite3ChangeCookie(pParse, iDb); |
| 136352 | 136423 | sqlite3VdbeAddParseSchemaOp(v, iDb, |
| 136353 | 136424 | sqlite3MPrintf(db, "type='trigger' AND name='%q'", zName)); |
| | @@ -136650,12 +136721,12 @@ |
| 136650 | 136721 | |
| 136651 | 136722 | /* Generate code to destroy the database record of the trigger. |
| 136652 | 136723 | */ |
| 136653 | 136724 | if( (v = sqlite3GetVdbe(pParse))!=0 ){ |
| 136654 | 136725 | sqlite3NestedParse(pParse, |
| 136655 | | - "DELETE FROM %Q.%s WHERE name=%Q AND type='trigger'", |
| 136656 | | - db->aDb[iDb].zDbSName, MASTER_NAME, pTrigger->zName |
| 136726 | + "DELETE FROM %Q." DFLT_SCHEMA_TABLE " WHERE name=%Q AND type='trigger'", |
| 136727 | + db->aDb[iDb].zDbSName, pTrigger->zName |
| 136657 | 136728 | ); |
| 136658 | 136729 | sqlite3ChangeCookie(pParse, iDb); |
| 136659 | 136730 | sqlite3VdbeAddOp4(v, OP_DropTrigger, iDb, 0, 0, pTrigger->zName, 0); |
| 136660 | 136731 | } |
| 136661 | 136732 | } |
| | @@ -137258,11 +137329,11 @@ |
| 137258 | 137329 | ** |
| 137259 | 137330 | ** Column definitions created by an ALTER TABLE command may only have |
| 137260 | 137331 | ** literal default values specified: a number, null or a string. (If a more |
| 137261 | 137332 | ** complicated default expression value was provided, it is evaluated |
| 137262 | 137333 | ** when the ALTER TABLE is executed and one of the literal values written |
| 137263 | | -** into the sqlite_master table.) |
| 137334 | +** into the sqlite_schema table.) |
| 137264 | 137335 | ** |
| 137265 | 137336 | ** Therefore, the P4 parameter is only required if the default value for |
| 137266 | 137337 | ** the column is a literal number, string or null. The sqlite3ValueFromExpr() |
| 137267 | 137338 | ** function is capable of transforming these types of expressions into |
| 137268 | 137339 | ** sqlite3_value objects. |
| | @@ -138591,11 +138662,11 @@ |
| 138591 | 138662 | while( SQLITE_ROW==(rc = sqlite3_step(pStmt)) ){ |
| 138592 | 138663 | const char *zSubSql = (const char*)sqlite3_column_text(pStmt,0); |
| 138593 | 138664 | assert( sqlite3_strnicmp(zSql,"SELECT",6)==0 ); |
| 138594 | 138665 | /* The secondary SQL must be one of CREATE TABLE, CREATE INDEX, |
| 138595 | 138666 | ** or INSERT. Historically there have been attacks that first |
| 138596 | | - ** corrupt the sqlite_master.sql field with other kinds of statements |
| 138667 | + ** corrupt the sqlite_schema.sql field with other kinds of statements |
| 138597 | 138668 | ** then run VACUUM to get those statements to execute at inappropriate |
| 138598 | 138669 | ** times. */ |
| 138599 | 138670 | if( zSubSql |
| 138600 | 138671 | && (strncmp(zSubSql,"CRE",3)==0 || strncmp(zSubSql,"INS",3)==0) |
| 138601 | 138672 | ){ |
| | @@ -138822,18 +138893,18 @@ |
| 138822 | 138893 | /* Query the schema of the main database. Create a mirror schema |
| 138823 | 138894 | ** in the temporary database. |
| 138824 | 138895 | */ |
| 138825 | 138896 | db->init.iDb = nDb; /* force new CREATE statements into vacuum_db */ |
| 138826 | 138897 | rc = execSqlF(db, pzErrMsg, |
| 138827 | | - "SELECT sql FROM \"%w\".sqlite_master" |
| 138898 | + "SELECT sql FROM \"%w\".sqlite_schema" |
| 138828 | 138899 | " WHERE type='table'AND name<>'sqlite_sequence'" |
| 138829 | 138900 | " AND coalesce(rootpage,1)>0", |
| 138830 | 138901 | zDbMain |
| 138831 | 138902 | ); |
| 138832 | 138903 | if( rc!=SQLITE_OK ) goto end_of_vacuum; |
| 138833 | 138904 | rc = execSqlF(db, pzErrMsg, |
| 138834 | | - "SELECT sql FROM \"%w\".sqlite_master" |
| 138905 | + "SELECT sql FROM \"%w\".sqlite_schema" |
| 138835 | 138906 | " WHERE type='index'", |
| 138836 | 138907 | zDbMain |
| 138837 | 138908 | ); |
| 138838 | 138909 | if( rc!=SQLITE_OK ) goto end_of_vacuum; |
| 138839 | 138910 | db->init.iDb = 0; |
| | @@ -138843,11 +138914,11 @@ |
| 138843 | 138914 | ** the contents to the temporary database. |
| 138844 | 138915 | */ |
| 138845 | 138916 | rc = execSqlF(db, pzErrMsg, |
| 138846 | 138917 | "SELECT'INSERT INTO vacuum_db.'||quote(name)" |
| 138847 | 138918 | "||' SELECT*FROM\"%w\".'||quote(name)" |
| 138848 | | - "FROM vacuum_db.sqlite_master " |
| 138919 | + "FROM vacuum_db.sqlite_schema " |
| 138849 | 138920 | "WHERE type='table'AND coalesce(rootpage,1)>0", |
| 138850 | 138921 | zDbMain |
| 138851 | 138922 | ); |
| 138852 | 138923 | assert( (db->mDbFlags & DBFLAG_Vacuum)!=0 ); |
| 138853 | 138924 | db->mDbFlags &= ~DBFLAG_Vacuum; |
| | @@ -138854,15 +138925,15 @@ |
| 138854 | 138925 | if( rc!=SQLITE_OK ) goto end_of_vacuum; |
| 138855 | 138926 | |
| 138856 | 138927 | /* Copy the triggers, views, and virtual tables from the main database |
| 138857 | 138928 | ** over to the temporary database. None of these objects has any |
| 138858 | 138929 | ** associated storage, so all we have to do is copy their entries |
| 138859 | | - ** from the SQLITE_MASTER table. |
| 138930 | + ** from the schema table. |
| 138860 | 138931 | */ |
| 138861 | 138932 | rc = execSqlF(db, pzErrMsg, |
| 138862 | | - "INSERT INTO vacuum_db.sqlite_master" |
| 138863 | | - " SELECT*FROM \"%w\".sqlite_master" |
| 138933 | + "INSERT INTO vacuum_db.sqlite_schema" |
| 138934 | + " SELECT*FROM \"%w\".sqlite_schema" |
| 138864 | 138935 | " WHERE type IN('view','trigger')" |
| 138865 | 138936 | " OR(type='table'AND rootpage=0)", |
| 138866 | 138937 | zDbMain |
| 138867 | 138938 | ); |
| 138868 | 138939 | if( rc ) goto end_of_vacuum; |
| | @@ -139362,11 +139433,11 @@ |
| 139362 | 139433 | ); |
| 139363 | 139434 | |
| 139364 | 139435 | #ifndef SQLITE_OMIT_AUTHORIZATION |
| 139365 | 139436 | /* Creating a virtual table invokes the authorization callback twice. |
| 139366 | 139437 | ** The first invocation, to obtain permission to INSERT a row into the |
| 139367 | | - ** sqlite_master table, has already been made by sqlite3StartTable(). |
| 139438 | + ** sqlite_schema table, has already been made by sqlite3StartTable(). |
| 139368 | 139439 | ** The second call, to obtain permission to create the table, is made now. |
| 139369 | 139440 | */ |
| 139370 | 139441 | if( pTable->azModuleArg ){ |
| 139371 | 139442 | int iDb = sqlite3SchemaToIndex(db, pTable->pSchema); |
| 139372 | 139443 | assert( iDb>=0 ); /* The database the table is being created in */ |
| | @@ -139403,13 +139474,13 @@ |
| 139403 | 139474 | pParse->sArg.z = 0; |
| 139404 | 139475 | if( pTab->nModuleArg<1 ) return; |
| 139405 | 139476 | |
| 139406 | 139477 | /* If the CREATE VIRTUAL TABLE statement is being entered for the |
| 139407 | 139478 | ** first time (in other words if the virtual table is actually being |
| 139408 | | - ** created now instead of just being read out of sqlite_master) then |
| 139479 | + ** created now instead of just being read out of sqlite_schema) then |
| 139409 | 139480 | ** do additional initialization work and store the statement text |
| 139410 | | - ** in the sqlite_master table. |
| 139481 | + ** in the sqlite_schema table. |
| 139411 | 139482 | */ |
| 139412 | 139483 | if( !db->init.busy ){ |
| 139413 | 139484 | char *zStmt; |
| 139414 | 139485 | char *zWhere; |
| 139415 | 139486 | int iDb; |
| | @@ -139423,23 +139494,23 @@ |
| 139423 | 139494 | pParse->sNameToken.n = (int)(pEnd->z - pParse->sNameToken.z) + pEnd->n; |
| 139424 | 139495 | } |
| 139425 | 139496 | zStmt = sqlite3MPrintf(db, "CREATE VIRTUAL TABLE %T", &pParse->sNameToken); |
| 139426 | 139497 | |
| 139427 | 139498 | /* A slot for the record has already been allocated in the |
| 139428 | | - ** SQLITE_MASTER table. We just need to update that slot with all |
| 139499 | + ** schema table. We just need to update that slot with all |
| 139429 | 139500 | ** the information we've collected. |
| 139430 | 139501 | ** |
| 139431 | 139502 | ** The VM register number pParse->regRowid holds the rowid of an |
| 139432 | | - ** entry in the sqlite_master table tht was created for this vtab |
| 139503 | + ** entry in the sqlite_schema table tht was created for this vtab |
| 139433 | 139504 | ** by sqlite3StartTable(). |
| 139434 | 139505 | */ |
| 139435 | 139506 | iDb = sqlite3SchemaToIndex(db, pTab->pSchema); |
| 139436 | 139507 | sqlite3NestedParse(pParse, |
| 139437 | | - "UPDATE %Q.%s " |
| 139508 | + "UPDATE %Q." DFLT_SCHEMA_TABLE " " |
| 139438 | 139509 | "SET type='table', name=%Q, tbl_name=%Q, rootpage=0, sql=%Q " |
| 139439 | 139510 | "WHERE rowid=#%d", |
| 139440 | | - db->aDb[iDb].zDbSName, MASTER_NAME, |
| 139511 | + db->aDb[iDb].zDbSName, |
| 139441 | 139512 | pTab->zName, |
| 139442 | 139513 | pTab->zName, |
| 139443 | 139514 | zStmt, |
| 139444 | 139515 | pParse->regRowid |
| 139445 | 139516 | ); |
| | @@ -139454,11 +139525,11 @@ |
| 139454 | 139525 | iReg = ++pParse->nMem; |
| 139455 | 139526 | sqlite3VdbeLoadString(v, iReg, pTab->zName); |
| 139456 | 139527 | sqlite3VdbeAddOp2(v, OP_VCreate, iDb, iReg); |
| 139457 | 139528 | } |
| 139458 | 139529 | |
| 139459 | | - /* If we are rereading the sqlite_master table create the in-memory |
| 139530 | + /* If we are rereading the sqlite_schema table create the in-memory |
| 139460 | 139531 | ** record of the table. The xConnect() method is not called until |
| 139461 | 139532 | ** the first time the virtual table is used in an SQL statement. This |
| 139462 | 139533 | ** allows a schema that contains virtual tables to be loaded before |
| 139463 | 139534 | ** the required virtual table implementations are registered. */ |
| 139464 | 139535 | else { |
| | @@ -151486,11 +151557,11 @@ |
| 151486 | 151557 | ExprList *pGroupBy = p->pGroupBy; |
| 151487 | 151558 | Expr *pHaving = p->pHaving; |
| 151488 | 151559 | ExprList *pSort = 0; |
| 151489 | 151560 | |
| 151490 | 151561 | ExprList *pSublist = 0; /* Expression list for sub-query */ |
| 151491 | | - Window *pMWin = p->pWin; /* Master window object */ |
| 151562 | + Window *pMWin = p->pWin; /* Main window object */ |
| 151492 | 151563 | Window *pWin; /* Window object iterator */ |
| 151493 | 151564 | Table *pTab; |
| 151494 | 151565 | Walker w; |
| 151495 | 151566 | |
| 151496 | 151567 | u32 selFlags = p->selFlags; |
| | @@ -151576,10 +151647,13 @@ |
| 151576 | 151647 | } |
| 151577 | 151648 | |
| 151578 | 151649 | pSub = sqlite3SelectNew( |
| 151579 | 151650 | pParse, pSublist, pSrc, pWhere, pGroupBy, pHaving, pSort, 0, 0 |
| 151580 | 151651 | ); |
| 151652 | + SELECTTRACE(1,pParse,pSub, |
| 151653 | + ("New window-function subquery in FROM clause of (%u/%p)\n", |
| 151654 | + p->selId, p)); |
| 151581 | 151655 | p->pSrc = sqlite3SrcListAppend(pParse, 0, 0, 0); |
| 151582 | 151656 | if( p->pSrc ){ |
| 151583 | 151657 | Table *pTab2; |
| 151584 | 151658 | p->pSrc->a[0].pSelect = pSub; |
| 151585 | 151659 | sqlite3SrcListAssignCursors(pParse, p->pSrc); |
| | @@ -160360,11 +160434,10 @@ |
| 160360 | 160434 | |
| 160361 | 160435 | #if 0 |
| 160362 | 160436 | } /* extern "C" */ |
| 160363 | 160437 | #endif /* __cplusplus */ |
| 160364 | 160438 | |
| 160365 | | - |
| 160366 | 160439 | /************** End of sqliteicu.h *******************************************/ |
| 160367 | 160440 | /************** Continuing where we left off in main.c ***********************/ |
| 160368 | 160441 | #endif |
| 160369 | 160442 | |
| 160370 | 160443 | /* |
| | @@ -160540,11 +160613,11 @@ |
| 160540 | 160613 | ** |
| 160541 | 160614 | ** * Recursive calls to this routine from thread X return immediately |
| 160542 | 160615 | ** without blocking. |
| 160543 | 160616 | */ |
| 160544 | 160617 | SQLITE_API int sqlite3_initialize(void){ |
| 160545 | | - MUTEX_LOGIC( sqlite3_mutex *pMaster; ) /* The main static mutex */ |
| 160618 | + MUTEX_LOGIC( sqlite3_mutex *pMainMtx; ) /* The main static mutex */ |
| 160546 | 160619 | int rc; /* Result code */ |
| 160547 | 160620 | #ifdef SQLITE_EXTRA_INIT |
| 160548 | 160621 | int bRunExtraInit = 0; /* Extra initialization needed */ |
| 160549 | 160622 | #endif |
| 160550 | 160623 | |
| | @@ -160580,17 +160653,17 @@ |
| 160580 | 160653 | */ |
| 160581 | 160654 | rc = sqlite3MutexInit(); |
| 160582 | 160655 | if( rc ) return rc; |
| 160583 | 160656 | |
| 160584 | 160657 | /* Initialize the malloc() system and the recursive pInitMutex mutex. |
| 160585 | | - ** This operation is protected by the STATIC_MASTER mutex. Note that |
| 160658 | + ** This operation is protected by the STATIC_MAIN mutex. Note that |
| 160586 | 160659 | ** MutexAlloc() is called for a static mutex prior to initializing the |
| 160587 | 160660 | ** malloc subsystem - this implies that the allocation of a static |
| 160588 | 160661 | ** mutex must not require support from the malloc subsystem. |
| 160589 | 160662 | */ |
| 160590 | | - MUTEX_LOGIC( pMaster = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); ) |
| 160591 | | - sqlite3_mutex_enter(pMaster); |
| 160663 | + MUTEX_LOGIC( pMainMtx = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN); ) |
| 160664 | + sqlite3_mutex_enter(pMainMtx); |
| 160592 | 160665 | sqlite3GlobalConfig.isMutexInit = 1; |
| 160593 | 160666 | if( !sqlite3GlobalConfig.isMallocInit ){ |
| 160594 | 160667 | rc = sqlite3MallocInit(); |
| 160595 | 160668 | } |
| 160596 | 160669 | if( rc==SQLITE_OK ){ |
| | @@ -160604,11 +160677,11 @@ |
| 160604 | 160677 | } |
| 160605 | 160678 | } |
| 160606 | 160679 | if( rc==SQLITE_OK ){ |
| 160607 | 160680 | sqlite3GlobalConfig.nRefInitMutex++; |
| 160608 | 160681 | } |
| 160609 | | - sqlite3_mutex_leave(pMaster); |
| 160682 | + sqlite3_mutex_leave(pMainMtx); |
| 160610 | 160683 | |
| 160611 | 160684 | /* If rc is not SQLITE_OK at this point, then either the malloc |
| 160612 | 160685 | ** subsystem could not be initialized or the system failed to allocate |
| 160613 | 160686 | ** the pInitMutex mutex. Return an error in either case. */ |
| 160614 | 160687 | if( rc!=SQLITE_OK ){ |
| | @@ -160665,18 +160738,18 @@ |
| 160665 | 160738 | sqlite3_mutex_leave(sqlite3GlobalConfig.pInitMutex); |
| 160666 | 160739 | |
| 160667 | 160740 | /* Go back under the static mutex and clean up the recursive |
| 160668 | 160741 | ** mutex to prevent a resource leak. |
| 160669 | 160742 | */ |
| 160670 | | - sqlite3_mutex_enter(pMaster); |
| 160743 | + sqlite3_mutex_enter(pMainMtx); |
| 160671 | 160744 | sqlite3GlobalConfig.nRefInitMutex--; |
| 160672 | 160745 | if( sqlite3GlobalConfig.nRefInitMutex<=0 ){ |
| 160673 | 160746 | assert( sqlite3GlobalConfig.nRefInitMutex==0 ); |
| 160674 | 160747 | sqlite3_mutex_free(sqlite3GlobalConfig.pInitMutex); |
| 160675 | 160748 | sqlite3GlobalConfig.pInitMutex = 0; |
| 160676 | 160749 | } |
| 160677 | | - sqlite3_mutex_leave(pMaster); |
| 160750 | + sqlite3_mutex_leave(pMainMtx); |
| 160678 | 160751 | |
| 160679 | 160752 | /* The following is just a sanity check to make sure SQLite has |
| 160680 | 160753 | ** been compiled correctly. It is important to run this code, but |
| 160681 | 160754 | ** we don't want to run it too often and soak up CPU cycles for no |
| 160682 | 160755 | ** reason. So we run it once during initialization. |
| | @@ -163451,11 +163524,11 @@ |
| 163451 | 163524 | SQLITE_OPEN_TEMP_DB | |
| 163452 | 163525 | SQLITE_OPEN_TRANSIENT_DB | |
| 163453 | 163526 | SQLITE_OPEN_MAIN_JOURNAL | |
| 163454 | 163527 | SQLITE_OPEN_TEMP_JOURNAL | |
| 163455 | 163528 | SQLITE_OPEN_SUBJOURNAL | |
| 163456 | | - SQLITE_OPEN_MASTER_JOURNAL | |
| 163529 | + SQLITE_OPEN_SUPER_JOURNAL | |
| 163457 | 163530 | SQLITE_OPEN_NOMUTEX | |
| 163458 | 163531 | SQLITE_OPEN_FULLMUTEX | |
| 163459 | 163532 | SQLITE_OPEN_WAL |
| 163460 | 163533 | ); |
| 163461 | 163534 | |
| | @@ -164428,11 +164501,11 @@ |
| 164428 | 164501 | } |
| 164429 | 164502 | |
| 164430 | 164503 | /* sqlite3_test_control(SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS, int); |
| 164431 | 164504 | ** |
| 164432 | 164505 | ** Set or clear a flag that causes SQLite to verify that type, name, |
| 164433 | | - ** and tbl_name fields of the sqlite_master table. This is normally |
| 164506 | + ** and tbl_name fields of the sqlite_schema table. This is normally |
| 164434 | 164507 | ** on, but it is sometimes useful to turn it off for testing. |
| 164435 | 164508 | */ |
| 164436 | 164509 | case SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS: { |
| 164437 | 164510 | sqlite3GlobalConfig.bExtraSchemaChecks = va_arg(ap, int); |
| 164438 | 164511 | break; |
| | @@ -164967,16 +165040,16 @@ |
| 164967 | 165040 | ** sqlite3ConnectionClosed() |
| 164968 | 165041 | ** sqlite3_unlock_notify() |
| 164969 | 165042 | */ |
| 164970 | 165043 | |
| 164971 | 165044 | #define assertMutexHeld() \ |
| 164972 | | - assert( sqlite3_mutex_held(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER)) ) |
| 165045 | + assert( sqlite3_mutex_held(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN)) ) |
| 164973 | 165046 | |
| 164974 | 165047 | /* |
| 164975 | 165048 | ** Head of a linked list of all sqlite3 objects created by this process |
| 164976 | 165049 | ** for which either sqlite3.pBlockingConnection or sqlite3.pUnlockConnection |
| 164977 | | -** is not NULL. This variable may only accessed while the STATIC_MASTER |
| 165050 | +** is not NULL. This variable may only accessed while the STATIC_MAIN |
| 164978 | 165051 | ** mutex is held. |
| 164979 | 165052 | */ |
| 164980 | 165053 | static sqlite3 *SQLITE_WSD sqlite3BlockedList = 0; |
| 164981 | 165054 | |
| 164982 | 165055 | #ifndef NDEBUG |
| | @@ -165046,24 +165119,24 @@ |
| 165046 | 165119 | db->pNextBlocked = *pp; |
| 165047 | 165120 | *pp = db; |
| 165048 | 165121 | } |
| 165049 | 165122 | |
| 165050 | 165123 | /* |
| 165051 | | -** Obtain the STATIC_MASTER mutex. |
| 165124 | +** Obtain the STATIC_MAIN mutex. |
| 165052 | 165125 | */ |
| 165053 | 165126 | static void enterMutex(void){ |
| 165054 | | - sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER)); |
| 165127 | + sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN)); |
| 165055 | 165128 | checkListProperties(0); |
| 165056 | 165129 | } |
| 165057 | 165130 | |
| 165058 | 165131 | /* |
| 165059 | | -** Release the STATIC_MASTER mutex. |
| 165132 | +** Release the STATIC_MAIN mutex. |
| 165060 | 165133 | */ |
| 165061 | 165134 | static void leaveMutex(void){ |
| 165062 | 165135 | assertMutexHeld(); |
| 165063 | 165136 | checkListProperties(0); |
| 165064 | | - sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER)); |
| 165137 | + sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN)); |
| 165065 | 165138 | } |
| 165066 | 165139 | |
| 165067 | 165140 | /* |
| 165068 | 165141 | ** Register an unlock-notify callback. |
| 165069 | 165142 | ** |
| | @@ -165170,11 +165243,11 @@ |
| 165170 | 165243 | void **aArg; /* Arguments to the unlock callback */ |
| 165171 | 165244 | void **aDyn = 0; /* Dynamically allocated space for aArg[] */ |
| 165172 | 165245 | void *aStatic[16]; /* Starter space for aArg[]. No malloc required */ |
| 165173 | 165246 | |
| 165174 | 165247 | aArg = aStatic; |
| 165175 | | - enterMutex(); /* Enter STATIC_MASTER mutex */ |
| 165248 | + enterMutex(); /* Enter STATIC_MAIN mutex */ |
| 165176 | 165249 | |
| 165177 | 165250 | /* This loop runs once for each entry in the blocked-connections list. */ |
| 165178 | 165251 | for(pp=&sqlite3BlockedList; *pp; /* no-op */ ){ |
| 165179 | 165252 | sqlite3 *p = *pp; |
| 165180 | 165253 | |
| | @@ -165253,11 +165326,11 @@ |
| 165253 | 165326 | |
| 165254 | 165327 | if( nArg!=0 ){ |
| 165255 | 165328 | xUnlockNotify(aArg, nArg); |
| 165256 | 165329 | } |
| 165257 | 165330 | sqlite3_free(aDyn); |
| 165258 | | - leaveMutex(); /* Leave STATIC_MASTER mutex */ |
| 165331 | + leaveMutex(); /* Leave STATIC_MAIN mutex */ |
| 165259 | 165332 | } |
| 165260 | 165333 | |
| 165261 | 165334 | /* |
| 165262 | 165335 | ** This is called when the database connection passed as an argument is |
| 165263 | 165336 | ** being closed. The connection is removed from the blocked list. |
| | @@ -168475,10 +168548,13 @@ |
| 168475 | 168548 | ** after the list written. No terminator (POS_END or POS_COLUMN) is |
| 168476 | 168549 | ** written to the output. |
| 168477 | 168550 | */ |
| 168478 | 168551 | fts3GetDeltaVarint(&p1, &i1); |
| 168479 | 168552 | fts3GetDeltaVarint(&p2, &i2); |
| 168553 | + if( i1<2 || i2<2 ){ |
| 168554 | + break; |
| 168555 | + } |
| 168480 | 168556 | do { |
| 168481 | 168557 | fts3PutDeltaVarint(&p, &iPrev, (i1<i2) ? i1 : i2); |
| 168482 | 168558 | iPrev -= 2; |
| 168483 | 168559 | if( i1==i2 ){ |
| 168484 | 168560 | fts3ReadNextPos(&p1, &i1); |
| | @@ -168543,11 +168619,11 @@ |
| 168543 | 168619 | int iCol2 = 0; |
| 168544 | 168620 | |
| 168545 | 168621 | /* Never set both isSaveLeft and isExact for the same invocation. */ |
| 168546 | 168622 | assert( isSaveLeft==0 || isExact==0 ); |
| 168547 | 168623 | |
| 168548 | | - assert( p!=0 && *p1!=0 && *p2!=0 ); |
| 168624 | + assert_fts3_nc( p!=0 && *p1!=0 && *p2!=0 ); |
| 168549 | 168625 | if( *p1==POS_COLUMN ){ |
| 168550 | 168626 | p1++; |
| 168551 | 168627 | p1 += fts3GetVarint32(p1, &iCol1); |
| 168552 | 168628 | } |
| 168553 | 168629 | if( *p2==POS_COLUMN ){ |
| | @@ -170728,11 +170804,11 @@ |
| 170728 | 170804 | ){ |
| 170729 | 170805 | char *p = *ppIter; |
| 170730 | 170806 | |
| 170731 | 170807 | assert( nDoclist>0 ); |
| 170732 | 170808 | assert( *pbEof==0 ); |
| 170733 | | - assert( p || *piDocid==0 ); |
| 170809 | + assert_fts3_nc( p || *piDocid==0 ); |
| 170734 | 170810 | assert( !p || (p>=aDoclist && p<=&aDoclist[nDoclist]) ); |
| 170735 | 170811 | |
| 170736 | 170812 | if( p==0 ){ |
| 170737 | 170813 | p = aDoclist; |
| 170738 | 170814 | p += sqlite3Fts3GetVarint(p, piDocid); |
| | @@ -171378,11 +171454,11 @@ |
| 171378 | 171454 | ** |
| 171379 | 171455 | ** abc NEAR/5 "def ghi" |
| 171380 | 171456 | ** |
| 171381 | 171457 | ** Parameter nNear is passed the NEAR distance of the expression (5 in |
| 171382 | 171458 | ** the example above). When this function is called, *paPoslist points to |
| 171383 | | -** the position list, and *pnToken is the number of phrase tokens in, the |
| 171459 | +** the position list, and *pnToken is the number of phrase tokens in the |
| 171384 | 171460 | ** phrase on the other side of the NEAR operator to pPhrase. For example, |
| 171385 | 171461 | ** if pPhrase refers to the "def ghi" phrase, then *paPoslist points to |
| 171386 | 171462 | ** the position list associated with phrase "abc". |
| 171387 | 171463 | ** |
| 171388 | 171464 | ** All positions in the pPhrase position list that are not sufficiently |
| | @@ -171768,11 +171844,14 @@ |
| 171768 | 171844 | bHit = (pPhrase->doclist.pList!=0); |
| 171769 | 171845 | pExpr->iDocid = pCsr->iPrevId; |
| 171770 | 171846 | }else |
| 171771 | 171847 | #endif |
| 171772 | 171848 | { |
| 171773 | | - bHit = (pExpr->bEof==0 && pExpr->iDocid==pCsr->iPrevId); |
| 171849 | + bHit = ( |
| 171850 | + pExpr->bEof==0 && pExpr->iDocid==pCsr->iPrevId |
| 171851 | + && pExpr->pPhrase->doclist.nList>0 |
| 171852 | + ); |
| 171774 | 171853 | } |
| 171775 | 171854 | break; |
| 171776 | 171855 | } |
| 171777 | 171856 | } |
| 171778 | 171857 | } |
| | @@ -192395,10 +192474,12 @@ |
| 192395 | 192474 | aCoord[0].f = mnX; |
| 192396 | 192475 | aCoord[1].f = mxX; |
| 192397 | 192476 | aCoord[2].f = mnY; |
| 192398 | 192477 | aCoord[3].f = mxY; |
| 192399 | 192478 | } |
| 192479 | + }else{ |
| 192480 | + memset(aCoord, 0, sizeof(RtreeCoord)*4); |
| 192400 | 192481 | } |
| 192401 | 192482 | return pOut; |
| 192402 | 192483 | } |
| 192403 | 192484 | |
| 192404 | 192485 | /* |
| | @@ -196108,20 +196189,20 @@ |
| 196108 | 196189 | memset(pIter, 0, sizeof(RbuObjIter)); |
| 196109 | 196190 | |
| 196110 | 196191 | rc = prepareFreeAndCollectError(p->dbRbu, &pIter->pTblIter, &p->zErrmsg, |
| 196111 | 196192 | sqlite3_mprintf( |
| 196112 | 196193 | "SELECT rbu_target_name(name, type='view') AS target, name " |
| 196113 | | - "FROM sqlite_master " |
| 196194 | + "FROM sqlite_schema " |
| 196114 | 196195 | "WHERE type IN ('table', 'view') AND target IS NOT NULL " |
| 196115 | 196196 | " %s " |
| 196116 | 196197 | "ORDER BY name" |
| 196117 | 196198 | , rbuIsVacuum(p) ? "AND rootpage!=0 AND rootpage IS NOT NULL" : "")); |
| 196118 | 196199 | |
| 196119 | 196200 | if( rc==SQLITE_OK ){ |
| 196120 | 196201 | rc = prepareAndCollectError(p->dbMain, &pIter->pIdxIter, &p->zErrmsg, |
| 196121 | 196202 | "SELECT name, rootpage, sql IS NULL OR substr(8, 6)=='UNIQUE' " |
| 196122 | | - " FROM main.sqlite_master " |
| 196203 | + " FROM main.sqlite_schema " |
| 196123 | 196204 | " WHERE type='index' AND tbl_name = ?" |
| 196124 | 196205 | ); |
| 196125 | 196206 | } |
| 196126 | 196207 | |
| 196127 | 196208 | pIter->bCleanup = 1; |
| | @@ -196289,16 +196370,16 @@ |
| 196289 | 196370 | ** is set to the root page number of the primary key index before |
| 196290 | 196371 | ** returning. |
| 196291 | 196372 | ** |
| 196292 | 196373 | ** ALGORITHM: |
| 196293 | 196374 | ** |
| 196294 | | -** if( no entry exists in sqlite_master ){ |
| 196375 | +** if( no entry exists in sqlite_schema ){ |
| 196295 | 196376 | ** return RBU_PK_NOTABLE |
| 196296 | 196377 | ** }else if( sql for the entry starts with "CREATE VIRTUAL" ){ |
| 196297 | 196378 | ** return RBU_PK_VTAB |
| 196298 | 196379 | ** }else if( "PRAGMA index_list()" for the table contains a "pk" index ){ |
| 196299 | | -** if( the index that is the pk exists in sqlite_master ){ |
| 196380 | +** if( the index that is the pk exists in sqlite_schema ){ |
| 196300 | 196381 | ** *piPK = rootpage of that index. |
| 196301 | 196382 | ** return RBU_PK_EXTERNAL |
| 196302 | 196383 | ** }else{ |
| 196303 | 196384 | ** return RBU_PK_WITHOUT_ROWID |
| 196304 | 196385 | ** } |
| | @@ -196314,13 +196395,13 @@ |
| 196314 | 196395 | int *peType, |
| 196315 | 196396 | int *piTnum, |
| 196316 | 196397 | int *piPk |
| 196317 | 196398 | ){ |
| 196318 | 196399 | /* |
| 196319 | | - ** 0) SELECT count(*) FROM sqlite_master where name=%Q AND IsVirtual(%Q) |
| 196400 | + ** 0) SELECT count(*) FROM sqlite_schema where name=%Q AND IsVirtual(%Q) |
| 196320 | 196401 | ** 1) PRAGMA index_list = ? |
| 196321 | | - ** 2) SELECT count(*) FROM sqlite_master where name=%Q |
| 196402 | + ** 2) SELECT count(*) FROM sqlite_schema where name=%Q |
| 196322 | 196403 | ** 3) PRAGMA table_info = ? |
| 196323 | 196404 | */ |
| 196324 | 196405 | sqlite3_stmt *aStmt[4] = {0, 0, 0, 0}; |
| 196325 | 196406 | |
| 196326 | 196407 | *peType = RBU_PK_NOTABLE; |
| | @@ -196328,11 +196409,11 @@ |
| 196328 | 196409 | |
| 196329 | 196410 | assert( p->rc==SQLITE_OK ); |
| 196330 | 196411 | p->rc = prepareFreeAndCollectError(p->dbMain, &aStmt[0], &p->zErrmsg, |
| 196331 | 196412 | sqlite3_mprintf( |
| 196332 | 196413 | "SELECT (sql LIKE 'create virtual%%'), rootpage" |
| 196333 | | - " FROM sqlite_master" |
| 196414 | + " FROM sqlite_schema" |
| 196334 | 196415 | " WHERE name=%Q", zTab |
| 196335 | 196416 | )); |
| 196336 | 196417 | if( p->rc!=SQLITE_OK || sqlite3_step(aStmt[0])!=SQLITE_ROW ){ |
| 196337 | 196418 | /* Either an error, or no such table. */ |
| 196338 | 196419 | goto rbuTableType_end; |
| | @@ -196351,11 +196432,11 @@ |
| 196351 | 196432 | const u8 *zOrig = sqlite3_column_text(aStmt[1], 3); |
| 196352 | 196433 | const u8 *zIdx = sqlite3_column_text(aStmt[1], 1); |
| 196353 | 196434 | if( zOrig && zIdx && zOrig[0]=='p' ){ |
| 196354 | 196435 | p->rc = prepareFreeAndCollectError(p->dbMain, &aStmt[2], &p->zErrmsg, |
| 196355 | 196436 | sqlite3_mprintf( |
| 196356 | | - "SELECT rootpage FROM sqlite_master WHERE name = %Q", zIdx |
| 196437 | + "SELECT rootpage FROM sqlite_schema WHERE name = %Q", zIdx |
| 196357 | 196438 | )); |
| 196358 | 196439 | if( p->rc==SQLITE_OK ){ |
| 196359 | 196440 | if( sqlite3_step(aStmt[2])==SQLITE_ROW ){ |
| 196360 | 196441 | *piPk = sqlite3_column_int(aStmt[2], 0); |
| 196361 | 196442 | *peType = RBU_PK_EXTERNAL; |
| | @@ -197171,11 +197252,11 @@ |
| 197171 | 197252 | |
| 197172 | 197253 | /* Figure out the name of the primary key index for the current table. |
| 197173 | 197254 | ** This is needed for the argument to "PRAGMA index_xinfo". Set |
| 197174 | 197255 | ** zIdx to point to a nul-terminated string containing this name. */ |
| 197175 | 197256 | p->rc = prepareAndCollectError(p->dbMain, &pQuery, &p->zErrmsg, |
| 197176 | | - "SELECT name FROM sqlite_master WHERE rootpage = ?" |
| 197257 | + "SELECT name FROM sqlite_schema WHERE rootpage = ?" |
| 197177 | 197258 | ); |
| 197178 | 197259 | if( p->rc==SQLITE_OK ){ |
| 197179 | 197260 | sqlite3_bind_int(pQuery, 1, tnum); |
| 197180 | 197261 | if( SQLITE_ROW==sqlite3_step(pQuery) ){ |
| 197181 | 197262 | zIdx = (const char*)sqlite3_column_text(pQuery, 0); |
| | @@ -197344,11 +197425,11 @@ |
| 197344 | 197425 | |
| 197345 | 197426 | assert( pIter->zIdxSql==0 && pIter->nIdxCol==0 && pIter->aIdxCol==0 ); |
| 197346 | 197427 | |
| 197347 | 197428 | if( rc==SQLITE_OK ){ |
| 197348 | 197429 | rc = prepareAndCollectError(p->dbMain, &pStmt, &p->zErrmsg, |
| 197349 | | - "SELECT trim(sql) FROM sqlite_master WHERE type='index' AND name=?" |
| 197430 | + "SELECT trim(sql) FROM sqlite_schema WHERE type='index' AND name=?" |
| 197350 | 197431 | ); |
| 197351 | 197432 | } |
| 197352 | 197433 | if( rc==SQLITE_OK ){ |
| 197353 | 197434 | int rc2; |
| 197354 | 197435 | rc = sqlite3_bind_text(pStmt, 1, pIter->zIdx, -1, SQLITE_STATIC); |
| | @@ -197926,11 +198007,11 @@ |
| 197926 | 198007 | if( p->rc==SQLITE_OK ){ |
| 197927 | 198008 | int rc2; |
| 197928 | 198009 | int bOk = 0; |
| 197929 | 198010 | sqlite3_stmt *pCnt = 0; |
| 197930 | 198011 | p->rc = prepareAndCollectError(p->dbRbu, &pCnt, &p->zErrmsg, |
| 197931 | | - "SELECT count(*) FROM stat.sqlite_master" |
| 198012 | + "SELECT count(*) FROM stat.sqlite_schema" |
| 197932 | 198013 | ); |
| 197933 | 198014 | if( p->rc==SQLITE_OK |
| 197934 | 198015 | && sqlite3_step(pCnt)==SQLITE_ROW |
| 197935 | 198016 | && 1==sqlite3_column_int(pCnt, 0) |
| 197936 | 198017 | ){ |
| | @@ -198030,11 +198111,11 @@ |
| 198030 | 198111 | } |
| 198031 | 198112 | |
| 198032 | 198113 | if( p->rc==SQLITE_OK ){ |
| 198033 | 198114 | p->rc = sqlite3_file_control(p->dbMain, "main", SQLITE_FCNTL_RBU, (void*)p); |
| 198034 | 198115 | } |
| 198035 | | - rbuMPrintfExec(p, p->dbMain, "SELECT * FROM sqlite_master"); |
| 198116 | + rbuMPrintfExec(p, p->dbMain, "SELECT * FROM sqlite_schema"); |
| 198036 | 198117 | |
| 198037 | 198118 | /* Mark the database file just opened as an RBU target database. If |
| 198038 | 198119 | ** this call returns SQLITE_NOTFOUND, then the RBU vfs is not in use. |
| 198039 | 198120 | ** This is an error. */ |
| 198040 | 198121 | if( p->rc==SQLITE_OK ){ |
| | @@ -198123,11 +198204,11 @@ |
| 198123 | 198204 | ** recovered. Running a read-statement here to ensure that doing so |
| 198124 | 198205 | ** does not interfere with the "capture" process below. */ |
| 198125 | 198206 | if( pState==0 ){ |
| 198126 | 198207 | p->eStage = 0; |
| 198127 | 198208 | if( p->rc==SQLITE_OK ){ |
| 198128 | | - p->rc = sqlite3_exec(p->dbMain, "SELECT * FROM sqlite_master", 0, 0, 0); |
| 198209 | + p->rc = sqlite3_exec(p->dbMain, "SELECT * FROM sqlite_schema", 0, 0, 0); |
| 198129 | 198210 | } |
| 198130 | 198211 | } |
| 198131 | 198212 | |
| 198132 | 198213 | /* Assuming no error has occurred, run a "restart" checkpoint with the |
| 198133 | 198214 | ** sqlite3rbu.eStage variable set to CAPTURE. This turns on the following |
| | @@ -198714,11 +198795,11 @@ |
| 198714 | 198795 | |
| 198715 | 198796 | assert( rbuIsVacuum(p) ); |
| 198716 | 198797 | p->rc = sqlite3_exec(p->dbMain, "PRAGMA writable_schema=1", 0,0, &p->zErrmsg); |
| 198717 | 198798 | if( p->rc==SQLITE_OK ){ |
| 198718 | 198799 | p->rc = prepareAndCollectError(p->dbRbu, &pSql, &p->zErrmsg, |
| 198719 | | - "SELECT sql FROM sqlite_master WHERE sql!='' AND rootpage!=0" |
| 198800 | + "SELECT sql FROM sqlite_schema WHERE sql!='' AND rootpage!=0" |
| 198720 | 198801 | " AND name!='sqlite_sequence' " |
| 198721 | 198802 | " ORDER BY type DESC" |
| 198722 | 198803 | ); |
| 198723 | 198804 | } |
| 198724 | 198805 | |
| | @@ -198729,17 +198810,17 @@ |
| 198729 | 198810 | rbuFinalize(p, pSql); |
| 198730 | 198811 | if( p->rc!=SQLITE_OK ) return; |
| 198731 | 198812 | |
| 198732 | 198813 | if( p->rc==SQLITE_OK ){ |
| 198733 | 198814 | p->rc = prepareAndCollectError(p->dbRbu, &pSql, &p->zErrmsg, |
| 198734 | | - "SELECT * FROM sqlite_master WHERE rootpage=0 OR rootpage IS NULL" |
| 198815 | + "SELECT * FROM sqlite_schema WHERE rootpage=0 OR rootpage IS NULL" |
| 198735 | 198816 | ); |
| 198736 | 198817 | } |
| 198737 | 198818 | |
| 198738 | 198819 | if( p->rc==SQLITE_OK ){ |
| 198739 | 198820 | p->rc = prepareAndCollectError(p->dbMain, &pInsert, &p->zErrmsg, |
| 198740 | | - "INSERT INTO sqlite_master VALUES(?,?,?,?,?)" |
| 198821 | + "INSERT INTO sqlite_schema VALUES(?,?,?,?,?)" |
| 198741 | 198822 | ); |
| 198742 | 198823 | } |
| 198743 | 198824 | |
| 198744 | 198825 | while( p->rc==SQLITE_OK && sqlite3_step(pSql)==SQLITE_ROW ){ |
| 198745 | 198826 | int i; |
| | @@ -198998,11 +199079,11 @@ |
| 198998 | 199079 | sqlite3 *db = (rbuIsVacuum(p) ? p->dbRbu : p->dbMain); |
| 198999 | 199080 | |
| 199000 | 199081 | assert( nVal==1 ); |
| 199001 | 199082 | |
| 199002 | 199083 | rc = prepareFreeAndCollectError(db, &pStmt, &zErrmsg, |
| 199003 | | - sqlite3_mprintf("SELECT count(*) FROM sqlite_master " |
| 199084 | + sqlite3_mprintf("SELECT count(*) FROM sqlite_schema " |
| 199004 | 199085 | "WHERE type='index' AND tbl_name = %Q", sqlite3_value_text(apVal[0])) |
| 199005 | 199086 | ); |
| 199006 | 199087 | if( rc!=SQLITE_OK ){ |
| 199007 | 199088 | sqlite3_result_error(pCtx, zErrmsg, -1); |
| 199008 | 199089 | }else{ |
| | @@ -199049,11 +199130,11 @@ |
| 199049 | 199130 | |
| 199050 | 199131 | /* Check for the rbu_count table. If it does not exist, or if an error |
| 199051 | 199132 | ** occurs, nPhaseOneStep will be left set to -1. */ |
| 199052 | 199133 | if( p->rc==SQLITE_OK ){ |
| 199053 | 199134 | p->rc = prepareAndCollectError(p->dbRbu, &pStmt, &p->zErrmsg, |
| 199054 | | - "SELECT 1 FROM sqlite_master WHERE tbl_name = 'rbu_count'" |
| 199135 | + "SELECT 1 FROM sqlite_schema WHERE tbl_name = 'rbu_count'" |
| 199055 | 199136 | ); |
| 199056 | 199137 | } |
| 199057 | 199138 | if( p->rc==SQLITE_OK ){ |
| 199058 | 199139 | if( SQLITE_ROW==sqlite3_step(pStmt) ){ |
| 199059 | 199140 | bExists = 1; |
| | @@ -201164,14 +201245,14 @@ |
| 201164 | 201245 | pCsr->isAgg = 0; |
| 201165 | 201246 | } |
| 201166 | 201247 | pSql = sqlite3_str_new(pTab->db); |
| 201167 | 201248 | sqlite3_str_appendf(pSql, |
| 201168 | 201249 | "SELECT * FROM (" |
| 201169 | | - "SELECT 'sqlite_master' AS name,1 AS rootpage,'table' AS type" |
| 201250 | + "SELECT 'sqlite_schema' AS name,1 AS rootpage,'table' AS type" |
| 201170 | 201251 | " UNION ALL " |
| 201171 | 201252 | "SELECT name,rootpage,type" |
| 201172 | | - " FROM \"%w\".sqlite_master WHERE rootpage!=0)", |
| 201253 | + " FROM \"%w\".sqlite_schema WHERE rootpage!=0)", |
| 201173 | 201254 | pTab->db->aDb[pCsr->iDb].zDbSName); |
| 201174 | 201255 | if( zName ){ |
| 201175 | 201256 | sqlite3_str_appendf(pSql, "WHERE name=%Q", zName); |
| 201176 | 201257 | } |
| 201177 | 201258 | if( idxNum & 0x08 ){ |
| | @@ -205194,10 +205275,11 @@ |
| 205194 | 205275 | int nCol; /* Size of azCol[] and abPK[] arrays */ |
| 205195 | 205276 | const char **azCol; /* Array of column names */ |
| 205196 | 205277 | u8 *abPK; /* Boolean array - true if column is in PK */ |
| 205197 | 205278 | int bStat1; /* True if table is sqlite_stat1 */ |
| 205198 | 205279 | int bDeferConstraints; /* True to defer constraints */ |
| 205280 | + int bInvertConstraints; /* Invert when iterating constraints buffer */ |
| 205199 | 205281 | SessionBuffer constraints; /* Deferred constraints are stored here */ |
| 205200 | 205282 | SessionBuffer rebase; /* Rebase information (if any) here */ |
| 205201 | 205283 | u8 bRebaseStarted; /* If table header is already in rebase */ |
| 205202 | 205284 | u8 bRebase; /* True to collect rebase information */ |
| 205203 | 205285 | }; |
| | @@ -205966,11 +206048,13 @@ |
| 205966 | 206048 | while( pApply->constraints.nBuf ){ |
| 205967 | 206049 | sqlite3_changeset_iter *pIter2 = 0; |
| 205968 | 206050 | SessionBuffer cons = pApply->constraints; |
| 205969 | 206051 | memset(&pApply->constraints, 0, sizeof(SessionBuffer)); |
| 205970 | 206052 | |
| 205971 | | - rc = sessionChangesetStart(&pIter2, 0, 0, cons.nBuf, cons.aBuf, 0); |
| 206053 | + rc = sessionChangesetStart( |
| 206054 | + &pIter2, 0, 0, cons.nBuf, cons.aBuf, pApply->bInvertConstraints |
| 206055 | + ); |
| 205972 | 206056 | if( rc==SQLITE_OK ){ |
| 205973 | 206057 | size_t nByte = 2*pApply->nCol*sizeof(sqlite3_value*); |
| 205974 | 206058 | int rc2; |
| 205975 | 206059 | pIter2->bPatchset = bPatchset; |
| 205976 | 206060 | pIter2->zTab = (char*)zTab; |
| | @@ -206033,10 +206117,11 @@ |
| 206033 | 206117 | assert( xConflict!=0 ); |
| 206034 | 206118 | |
| 206035 | 206119 | pIter->in.bNoDiscard = 1; |
| 206036 | 206120 | memset(&sApply, 0, sizeof(sApply)); |
| 206037 | 206121 | sApply.bRebase = (ppRebase && pnRebase); |
| 206122 | + sApply.bInvertConstraints = !!(flags & SQLITE_CHANGESETAPPLY_INVERT); |
| 206038 | 206123 | sqlite3_mutex_enter(sqlite3_db_mutex(db)); |
| 206039 | 206124 | if( (flags & SQLITE_CHANGESETAPPLY_NOSAVEPOINT)==0 ){ |
| 206040 | 206125 | rc = sqlite3_exec(db, "SAVEPOINT changeset_apply", 0, 0, 0); |
| 206041 | 206126 | } |
| 206042 | 206127 | if( rc==SQLITE_OK ){ |
| | @@ -224997,11 +225082,11 @@ |
| 224997 | 225082 | int nArg, /* Number of args */ |
| 224998 | 225083 | sqlite3_value **apUnused /* Function arguments */ |
| 224999 | 225084 | ){ |
| 225000 | 225085 | assert( nArg==0 ); |
| 225001 | 225086 | UNUSED_PARAM2(nArg, apUnused); |
| 225002 | | - sqlite3_result_text(pCtx, "fts5: 2020-06-08 11:34:40 6e6b3729e0549de028f6c5bf494b2d69d621c81b61a1dc0a329d3950039342fb", -1, SQLITE_TRANSIENT); |
| 225087 | + sqlite3_result_text(pCtx, "fts5: 2020-06-19 15:24:12 7a876209a678a34c198b54ceef9e3c041f128a14dc73357f6a57cadadaa6cf7b", -1, SQLITE_TRANSIENT); |
| 225003 | 225088 | } |
| 225004 | 225089 | |
| 225005 | 225090 | /* |
| 225006 | 225091 | ** Return true if zName is the extension on one of the shadow tables used |
| 225007 | 225092 | ** by this module. |
| | @@ -229780,12 +229865,12 @@ |
| 229780 | 229865 | } |
| 229781 | 229866 | #endif /* SQLITE_CORE */ |
| 229782 | 229867 | #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */ |
| 229783 | 229868 | |
| 229784 | 229869 | /************** End of stmt.c ************************************************/ |
| 229785 | | -#if __LINE__!=229785 |
| 229870 | +#if __LINE__!=229870 |
| 229786 | 229871 | #undef SQLITE_SOURCE_ID |
| 229787 | | -#define SQLITE_SOURCE_ID "2020-06-08 11:34:40 6e6b3729e0549de028f6c5bf494b2d69d621c81b61a1dc0a329d39500393alt2" |
| 229872 | +#define SQLITE_SOURCE_ID "2020-06-19 15:24:12 7a876209a678a34c198b54ceef9e3c041f128a14dc73357f6a57cadadaa6alt2" |
| 229788 | 229873 | #endif |
| 229789 | 229874 | /* Return the source-id for this library */ |
| 229790 | 229875 | SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; } |
| 229791 | 229876 | /************************** End of sqlite3.c ******************************/ |
| 229792 | 229877 | |