| | @@ -231,11 +231,11 @@ |
| 231 | 231 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 232 | 232 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 233 | 233 | */ |
| 234 | 234 | #define SQLITE_VERSION "3.8.8" |
| 235 | 235 | #define SQLITE_VERSION_NUMBER 3008008 |
| 236 | | -#define SQLITE_SOURCE_ID "2014-12-10 04:58:43 3528f8dd39acace8eeb7337994c8617313f4b04b" |
| 236 | +#define SQLITE_SOURCE_ID "2015-01-03 18:59:17 23d4c07eb81db5a5c6beb56b5820f0b6501f1fb6" |
| 237 | 237 | |
| 238 | 238 | /* |
| 239 | 239 | ** CAPI3REF: Run-Time Library Version Numbers |
| 240 | 240 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 241 | 241 | ** |
| | @@ -323,11 +323,11 @@ |
| 323 | 323 | ** This interface only reports on the compile-time mutex setting |
| 324 | 324 | ** of the [SQLITE_THREADSAFE] flag. If SQLite is compiled with |
| 325 | 325 | ** SQLITE_THREADSAFE=1 or =2 then mutexes are enabled by default but |
| 326 | 326 | ** can be fully or partially disabled using a call to [sqlite3_config()] |
| 327 | 327 | ** with the verbs [SQLITE_CONFIG_SINGLETHREAD], [SQLITE_CONFIG_MULTITHREAD], |
| 328 | | -** or [SQLITE_CONFIG_MUTEX]. ^(The return value of the |
| 328 | +** or [SQLITE_CONFIG_SERIALIZED]. ^(The return value of the |
| 329 | 329 | ** sqlite3_threadsafe() function shows only the compile-time setting of |
| 330 | 330 | ** thread safety, not any run-time changes to that setting made by |
| 331 | 331 | ** sqlite3_config(). In other words, the return value from sqlite3_threadsafe() |
| 332 | 332 | ** is unchanged by calls to sqlite3_config().)^ |
| 333 | 333 | ** |
| | @@ -1692,11 +1692,11 @@ |
| 1692 | 1692 | ** configuration option. |
| 1693 | 1693 | ** ^There are three arguments to SQLITE_CONFIG_PAGECACHE: A pointer to |
| 1694 | 1694 | ** 8-byte aligned |
| 1695 | 1695 | ** memory, the size of each page buffer (sz), and the number of pages (N). |
| 1696 | 1696 | ** The sz argument should be the size of the largest database page |
| 1697 | | -** (a power of two between 512 and 32768) plus some extra bytes for each |
| 1697 | +** (a power of two between 512 and 65536) plus some extra bytes for each |
| 1698 | 1698 | ** page header. ^The number of extra bytes needed by the page header |
| 1699 | 1699 | ** can be determined using the [SQLITE_CONFIG_PCACHE_HDRSZ] option |
| 1700 | 1700 | ** to [sqlite3_config()]. |
| 1701 | 1701 | ** ^It is harmless, apart from the wasted memory, |
| 1702 | 1702 | ** for the sz parameter to be larger than necessary. The first |
| | @@ -1872,10 +1872,21 @@ |
| 1872 | 1872 | ** <dd>^The SQLITE_CONFIG_PCACHE_HDRSZ option takes a single parameter which |
| 1873 | 1873 | ** is a pointer to an integer and writes into that integer the number of extra |
| 1874 | 1874 | ** bytes per page required for each page in [SQLITE_CONFIG_PAGECACHE]. |
| 1875 | 1875 | ** The amount of extra space required can change depending on the compiler, |
| 1876 | 1876 | ** target platform, and SQLite version. |
| 1877 | +** |
| 1878 | +** [[SQLITE_CONFIG_PMASZ]] |
| 1879 | +** <dt>SQLITE_CONFIG_PMASZ |
| 1880 | +** <dd>^The SQLITE_CONFIG_PMASZ option takes a single parameter which |
| 1881 | +** is an unsigned integer and sets the "Minimum PMA Size" for the multithreaded |
| 1882 | +** sorter to that integer. The default minimum PMA Size is set by the |
| 1883 | +** [SQLITE_SORTER_PMASZ] compile-time option. New threads are launched |
| 1884 | +** to help with sort operations when multithreaded sorting |
| 1885 | +** is enabled (using the [PRAGMA threads] command) and the amount of content |
| 1886 | +** to be sorted exceeds the page size times the minimum of the |
| 1887 | +** [PRAGMA cache_size] setting and this value. |
| 1877 | 1888 | ** </dl> |
| 1878 | 1889 | */ |
| 1879 | 1890 | #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */ |
| 1880 | 1891 | #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */ |
| 1881 | 1892 | #define SQLITE_CONFIG_SERIALIZED 3 /* nil */ |
| | @@ -1898,10 +1909,11 @@ |
| 1898 | 1909 | #define SQLITE_CONFIG_COVERING_INDEX_SCAN 20 /* int */ |
| 1899 | 1910 | #define SQLITE_CONFIG_SQLLOG 21 /* xSqllog, void* */ |
| 1900 | 1911 | #define SQLITE_CONFIG_MMAP_SIZE 22 /* sqlite3_int64, sqlite3_int64 */ |
| 1901 | 1912 | #define SQLITE_CONFIG_WIN32_HEAPSIZE 23 /* int nByte */ |
| 1902 | 1913 | #define SQLITE_CONFIG_PCACHE_HDRSZ 24 /* int *psz */ |
| 1914 | +#define SQLITE_CONFIG_PMASZ 25 /* unsigned int szPma */ |
| 1903 | 1915 | |
| 1904 | 1916 | /* |
| 1905 | 1917 | ** CAPI3REF: Database Connection Configuration Options |
| 1906 | 1918 | ** |
| 1907 | 1919 | ** These constants are the available integer configuration options that |
| | @@ -7307,16 +7319,14 @@ |
| 7307 | 7319 | |
| 7308 | 7320 | /* |
| 7309 | 7321 | ** CAPI3REF: Write-Ahead Log Commit Hook |
| 7310 | 7322 | ** |
| 7311 | 7323 | ** ^The [sqlite3_wal_hook()] function is used to register a callback that |
| 7312 | | -** will be invoked each time a database connection commits data to a |
| 7313 | | -** [write-ahead log] (i.e. whenever a transaction is committed in |
| 7314 | | -** [journal_mode | journal_mode=WAL mode]). |
| 7324 | +** is invoked each time data is committed to a database in wal mode. |
| 7315 | 7325 | ** |
| 7316 | | -** ^The callback is invoked by SQLite after the commit has taken place and |
| 7317 | | -** the associated write-lock on the database released, so the implementation |
| 7326 | +** ^(The callback is invoked by SQLite after the commit has taken place and |
| 7327 | +** the associated write-lock on the database released)^, so the implementation |
| 7318 | 7328 | ** may read, write or [checkpoint] the database as required. |
| 7319 | 7329 | ** |
| 7320 | 7330 | ** ^The first parameter passed to the callback function when it is invoked |
| 7321 | 7331 | ** is a copy of the third parameter passed to sqlite3_wal_hook() when |
| 7322 | 7332 | ** registering the callback. ^The second is a copy of the database handle. |
| | @@ -9100,11 +9110,11 @@ |
| 9100 | 9110 | #define _BTREE_H_ |
| 9101 | 9111 | |
| 9102 | 9112 | /* TODO: This definition is just included so other modules compile. It |
| 9103 | 9113 | ** needs to be revisited. |
| 9104 | 9114 | */ |
| 9105 | | -#define SQLITE_N_BTREE_META 10 |
| 9115 | +#define SQLITE_N_BTREE_META 16 |
| 9106 | 9116 | |
| 9107 | 9117 | /* |
| 9108 | 9118 | ** If defined as non-zero, auto-vacuum is enabled by default. Otherwise |
| 9109 | 9119 | ** it must be turned on for each database using "PRAGMA auto_vacuum = 1". |
| 9110 | 9120 | */ |
| | @@ -9215,10 +9225,15 @@ |
| 9215 | 9225 | ** offset = 36 + (idx * 4) |
| 9216 | 9226 | ** |
| 9217 | 9227 | ** For example, the free-page-count field is located at byte offset 36 of |
| 9218 | 9228 | ** the database file header. The incr-vacuum-flag field is located at |
| 9219 | 9229 | ** byte offset 64 (== 36+4*7). |
| 9230 | +** |
| 9231 | +** The BTREE_DATA_VERSION value is not really a value stored in the header. |
| 9232 | +** It is a read-only number computed by the pager. But we merge it with |
| 9233 | +** the header value access routines since its access pattern is the same. |
| 9234 | +** Call it a "virtual meta value". |
| 9220 | 9235 | */ |
| 9221 | 9236 | #define BTREE_FREE_PAGE_COUNT 0 |
| 9222 | 9237 | #define BTREE_SCHEMA_VERSION 1 |
| 9223 | 9238 | #define BTREE_FILE_FORMAT 2 |
| 9224 | 9239 | #define BTREE_DEFAULT_CACHE_SIZE 3 |
| | @@ -9225,10 +9240,11 @@ |
| 9225 | 9240 | #define BTREE_LARGEST_ROOT_PAGE 4 |
| 9226 | 9241 | #define BTREE_TEXT_ENCODING 5 |
| 9227 | 9242 | #define BTREE_USER_VERSION 6 |
| 9228 | 9243 | #define BTREE_INCR_VACUUM 7 |
| 9229 | 9244 | #define BTREE_APPLICATION_ID 8 |
| 9245 | +#define BTREE_DATA_VERSION 15 /* A virtual meta-value */ |
| 9230 | 9246 | |
| 9231 | 9247 | /* |
| 9232 | 9248 | ** Values that may be OR'd together to form the second argument of an |
| 9233 | 9249 | ** sqlite3BtreeCursorHints() call. |
| 9234 | 9250 | */ |
| | @@ -10006,10 +10022,11 @@ |
| 10006 | 10022 | SQLITE_PRIVATE int sqlite3PagerWalFramesize(Pager *pPager); |
| 10007 | 10023 | #endif |
| 10008 | 10024 | |
| 10009 | 10025 | /* Functions used to query pager state and configuration. */ |
| 10010 | 10026 | SQLITE_PRIVATE u8 sqlite3PagerIsreadonly(Pager*); |
| 10027 | +SQLITE_PRIVATE u32 sqlite3PagerDataVersion(Pager*); |
| 10011 | 10028 | SQLITE_PRIVATE int sqlite3PagerRefcount(Pager*); |
| 10012 | 10029 | SQLITE_PRIVATE int sqlite3PagerMemUsed(Pager*); |
| 10013 | 10030 | SQLITE_PRIVATE const char *sqlite3PagerFilename(Pager*, int); |
| 10014 | 10031 | SQLITE_PRIVATE const sqlite3_vfs *sqlite3PagerVfs(Pager*); |
| 10015 | 10032 | SQLITE_PRIVATE sqlite3_file *sqlite3PagerFile(Pager*); |
| | @@ -10747,10 +10764,11 @@ |
| 10747 | 10764 | i64 szMmap; /* Default mmap_size setting */ |
| 10748 | 10765 | unsigned int openFlags; /* Flags passed to sqlite3_vfs.xOpen() */ |
| 10749 | 10766 | int errCode; /* Most recent error code (SQLITE_*) */ |
| 10750 | 10767 | int errMask; /* & result codes with this before returning */ |
| 10751 | 10768 | u16 dbOptFlags; /* Flags to enable/disable optimizations */ |
| 10769 | + u8 enc; /* Text encoding */ |
| 10752 | 10770 | u8 autoCommit; /* The auto-commit flag. */ |
| 10753 | 10771 | u8 temp_store; /* 1: file 2: memory 0: default */ |
| 10754 | 10772 | u8 mallocFailed; /* True if we have seen a malloc failure */ |
| 10755 | 10773 | u8 dfltLockMode; /* Default locking-mode for attached dbs */ |
| 10756 | 10774 | signed char nextAutovac; /* Autovac setting after VACUUM if >=0 */ |
| | @@ -10848,11 +10866,12 @@ |
| 10848 | 10866 | }; |
| 10849 | 10867 | |
| 10850 | 10868 | /* |
| 10851 | 10869 | ** A macro to discover the encoding of a database. |
| 10852 | 10870 | */ |
| 10853 | | -#define ENC(db) ((db)->aDb[0].pSchema->enc) |
| 10871 | +#define SCHEMA_ENC(db) ((db)->aDb[0].pSchema->enc) |
| 10872 | +#define ENC(db) ((db)->enc) |
| 10854 | 10873 | |
| 10855 | 10874 | /* |
| 10856 | 10875 | ** Possible values for the sqlite3.flags. |
| 10857 | 10876 | */ |
| 10858 | 10877 | #define SQLITE_VdbeTrace 0x00000001 /* True to trace VDBE execution */ |
| | @@ -11472,11 +11491,10 @@ |
| 11472 | 11491 | Index *pNext; /* The next index associated with the same table */ |
| 11473 | 11492 | Schema *pSchema; /* Schema containing this index */ |
| 11474 | 11493 | u8 *aSortOrder; /* for each column: True==DESC, False==ASC */ |
| 11475 | 11494 | char **azColl; /* Array of collation sequence names for index */ |
| 11476 | 11495 | Expr *pPartIdxWhere; /* WHERE clause for partial indices */ |
| 11477 | | - KeyInfo *pKeyInfo; /* A KeyInfo object suitable for this index */ |
| 11478 | 11496 | int tnum; /* DB Page containing root of this index */ |
| 11479 | 11497 | LogEst szIdxRow; /* Estimated average row size in bytes */ |
| 11480 | 11498 | u16 nKeyCol; /* Number of columns forming the key */ |
| 11481 | 11499 | u16 nColumn; /* Number of columns stored in the index */ |
| 11482 | 11500 | u8 onError; /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */ |
| | @@ -12526,10 +12544,11 @@ |
| 12526 | 12544 | void *pPage; /* Page cache memory */ |
| 12527 | 12545 | int szPage; /* Size of each page in pPage[] */ |
| 12528 | 12546 | int nPage; /* Number of pages in pPage[] */ |
| 12529 | 12547 | int mxParserStack; /* maximum depth of the parser stack */ |
| 12530 | 12548 | int sharedCacheEnabled; /* true if shared-cache mode enabled */ |
| 12549 | + u32 szPma; /* Maximum Sorter PMA size */ |
| 12531 | 12550 | /* The above might be initialized to non-zero. The following need to always |
| 12532 | 12551 | ** initially be zero, however. */ |
| 12533 | 12552 | int isInit; /* True after initialization has finished */ |
| 12534 | 12553 | int inProgress; /* True while initialization in progress */ |
| 12535 | 12554 | int isMutexInit; /* True after mutexes are initialized */ |
| | @@ -13448,11 +13467,11 @@ |
| 13448 | 13467 | ** print I/O tracing messages. |
| 13449 | 13468 | */ |
| 13450 | 13469 | #ifdef SQLITE_ENABLE_IOTRACE |
| 13451 | 13470 | # define IOTRACE(A) if( sqlite3IoTrace ){ sqlite3IoTrace A; } |
| 13452 | 13471 | SQLITE_PRIVATE void sqlite3VdbeIOTraceSql(Vdbe*); |
| 13453 | | -SQLITE_PRIVATE void (*sqlite3IoTrace)(const char*,...); |
| 13472 | +void (*sqlite3IoTrace)(const char*,...); |
| 13454 | 13473 | #else |
| 13455 | 13474 | # define IOTRACE(A) |
| 13456 | 13475 | # define sqlite3VdbeIOTraceSql(X) |
| 13457 | 13476 | #endif |
| 13458 | 13477 | |
| | @@ -13661,10 +13680,17 @@ |
| 13661 | 13680 | */ |
| 13662 | 13681 | #ifndef SQLITE_ALLOW_COVERING_INDEX_SCAN |
| 13663 | 13682 | # define SQLITE_ALLOW_COVERING_INDEX_SCAN 1 |
| 13664 | 13683 | #endif |
| 13665 | 13684 | |
| 13685 | +/* The minimum PMA size is set to this value multiplied by the database |
| 13686 | +** page size in bytes. |
| 13687 | +*/ |
| 13688 | +#ifndef SQLITE_SORTER_PMASZ |
| 13689 | +# define SQLITE_SORTER_PMASZ 250 |
| 13690 | +#endif |
| 13691 | + |
| 13666 | 13692 | /* |
| 13667 | 13693 | ** The following singleton contains the global configuration for |
| 13668 | 13694 | ** the SQLite library. |
| 13669 | 13695 | */ |
| 13670 | 13696 | SQLITE_PRIVATE SQLITE_WSD struct Sqlite3Config sqlite3Config = { |
| | @@ -13691,10 +13717,11 @@ |
| 13691 | 13717 | (void*)0, /* pPage */ |
| 13692 | 13718 | 0, /* szPage */ |
| 13693 | 13719 | 0, /* nPage */ |
| 13694 | 13720 | 0, /* mxParserStack */ |
| 13695 | 13721 | 0, /* sharedCacheEnabled */ |
| 13722 | + SQLITE_SORTER_PMASZ, /* szPma */ |
| 13696 | 13723 | /* All the rest should always be initialized to zero */ |
| 13697 | 13724 | 0, /* isInit */ |
| 13698 | 13725 | 0, /* inProgress */ |
| 13699 | 13726 | 0, /* isMutexInit */ |
| 13700 | 13727 | 0, /* isMallocInit */ |
| | @@ -19976,10 +20003,16 @@ |
| 19976 | 20003 | #endif |
| 19977 | 20004 | } |
| 19978 | 20005 | break; |
| 19979 | 20006 | } |
| 19980 | 20007 | default: { |
| 20008 | +#ifdef SQLITE_ENABLE_API_ARMOR |
| 20009 | + if( iType-2<0 || iType-2>=ArraySize(winMutex_staticMutexes) ){ |
| 20010 | + (void)SQLITE_MISUSE_BKPT; |
| 20011 | + return 0; |
| 20012 | + } |
| 20013 | +#endif |
| 19981 | 20014 | assert( iType-2 >= 0 ); |
| 19982 | 20015 | assert( iType-2 < ArraySize(winMutex_staticMutexes) ); |
| 19983 | 20016 | assert( winMutex_isInit==1 ); |
| 19984 | 20017 | p = &winMutex_staticMutexes[iType-2]; |
| 19985 | 20018 | #ifdef SQLITE_DEBUG |
| | @@ -28783,28 +28816,31 @@ |
| 28783 | 28816 | do{ |
| 28784 | 28817 | err = osFallocate(pFile->h, buf.st_size, nSize-buf.st_size); |
| 28785 | 28818 | }while( err==EINTR ); |
| 28786 | 28819 | if( err ) return SQLITE_IOERR_WRITE; |
| 28787 | 28820 | #else |
| 28788 | | - /* If the OS does not have posix_fallocate(), fake it. First use |
| 28789 | | - ** ftruncate() to set the file size, then write a single byte to |
| 28790 | | - ** the last byte in each block within the extended region. This |
| 28791 | | - ** is the same technique used by glibc to implement posix_fallocate() |
| 28792 | | - ** on systems that do not have a real fallocate() system call. |
| 28821 | + /* If the OS does not have posix_fallocate(), fake it. Write a |
| 28822 | + ** single byte to the last byte in each block that falls entirely |
| 28823 | + ** within the extended region. Then, if required, a single byte |
| 28824 | + ** at offset (nSize-1), to set the size of the file correctly. |
| 28825 | + ** This is a similar technique to that used by glibc on systems |
| 28826 | + ** that do not have a real fallocate() call. |
| 28793 | 28827 | */ |
| 28794 | 28828 | int nBlk = buf.st_blksize; /* File-system block size */ |
| 28795 | 28829 | i64 iWrite; /* Next offset to write to */ |
| 28796 | 28830 | |
| 28797 | | - if( robust_ftruncate(pFile->h, nSize) ){ |
| 28798 | | - pFile->lastErrno = errno; |
| 28799 | | - return unixLogError(SQLITE_IOERR_TRUNCATE, "ftruncate", pFile->zPath); |
| 28800 | | - } |
| 28801 | 28831 | iWrite = ((buf.st_size + 2*nBlk - 1)/nBlk)*nBlk-1; |
| 28802 | | - while( iWrite<nSize ){ |
| 28832 | + assert( iWrite>=buf.st_size ); |
| 28833 | + assert( (iWrite/nBlk)==((buf.st_size+nBlk-1)/nBlk) ); |
| 28834 | + assert( ((iWrite+1)%nBlk)==0 ); |
| 28835 | + for(/*no-op*/; iWrite<nSize; iWrite+=nBlk ){ |
| 28803 | 28836 | int nWrite = seekAndWrite(pFile, iWrite, "", 1); |
| 28804 | 28837 | if( nWrite!=1 ) return SQLITE_IOERR_WRITE; |
| 28805 | | - iWrite += nBlk; |
| 28838 | + } |
| 28839 | + if( nSize%nBlk ){ |
| 28840 | + int nWrite = seekAndWrite(pFile, nSize-1, "", 1); |
| 28841 | + if( nWrite!=1 ) return SQLITE_IOERR_WRITE; |
| 28806 | 28842 | } |
| 28807 | 28843 | #endif |
| 28808 | 28844 | } |
| 28809 | 28845 | } |
| 28810 | 28846 | |
| | @@ -34018,12 +34054,12 @@ |
| 34018 | 34054 | */ |
| 34019 | 34055 | SQLITE_API int sqlite3_win32_reset_heap(){ |
| 34020 | 34056 | int rc; |
| 34021 | 34057 | MUTEX_LOGIC( sqlite3_mutex *pMaster; ) /* The main static mutex */ |
| 34022 | 34058 | MUTEX_LOGIC( sqlite3_mutex *pMem; ) /* The memsys static mutex */ |
| 34023 | | - MUTEX_LOGIC( pMaster = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); ) |
| 34024 | | - MUTEX_LOGIC( pMem = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM); ) |
| 34059 | + MUTEX_LOGIC( pMaster = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MASTER); ) |
| 34060 | + MUTEX_LOGIC( pMem = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MEM); ) |
| 34025 | 34061 | sqlite3_mutex_enter(pMaster); |
| 34026 | 34062 | sqlite3_mutex_enter(pMem); |
| 34027 | 34063 | winMemAssertMagic(); |
| 34028 | 34064 | if( winMemGetHeap()!=NULL && winMemGetOwned() && sqlite3_memory_used()==0 ){ |
| 34029 | 34065 | /* |
| | @@ -35294,11 +35330,11 @@ |
| 35294 | 35330 | sqlite3_file *id, /* File to read from */ |
| 35295 | 35331 | void *pBuf, /* Write content into this buffer */ |
| 35296 | 35332 | int amt, /* Number of bytes to read */ |
| 35297 | 35333 | sqlite3_int64 offset /* Begin reading at this offset */ |
| 35298 | 35334 | ){ |
| 35299 | | -#if !SQLITE_OS_WINCE |
| 35335 | +#if !SQLITE_OS_WINCE && !defined(SQLITE_WIN32_NO_OVERLAPPED) |
| 35300 | 35336 | OVERLAPPED overlapped; /* The offset for ReadFile. */ |
| 35301 | 35337 | #endif |
| 35302 | 35338 | winFile *pFile = (winFile*)id; /* file handle */ |
| 35303 | 35339 | DWORD nRead; /* Number of bytes actually read from file */ |
| 35304 | 35340 | int nRetry = 0; /* Number of retrys */ |
| | @@ -35326,11 +35362,11 @@ |
| 35326 | 35362 | offset += nCopy; |
| 35327 | 35363 | } |
| 35328 | 35364 | } |
| 35329 | 35365 | #endif |
| 35330 | 35366 | |
| 35331 | | -#if SQLITE_OS_WINCE |
| 35367 | +#if SQLITE_OS_WINCE || defined(SQLITE_WIN32_NO_OVERLAPPED) |
| 35332 | 35368 | if( winSeekFile(pFile, offset) ){ |
| 35333 | 35369 | OSTRACE(("READ file=%p, rc=SQLITE_FULL\n", pFile->h)); |
| 35334 | 35370 | return SQLITE_FULL; |
| 35335 | 35371 | } |
| 35336 | 35372 | while( !osReadFile(pFile->h, pBuf, amt, &nRead, 0) ){ |
| | @@ -35398,32 +35434,32 @@ |
| 35398 | 35434 | offset += nCopy; |
| 35399 | 35435 | } |
| 35400 | 35436 | } |
| 35401 | 35437 | #endif |
| 35402 | 35438 | |
| 35403 | | -#if SQLITE_OS_WINCE |
| 35439 | +#if SQLITE_OS_WINCE || defined(SQLITE_WIN32_NO_OVERLAPPED) |
| 35404 | 35440 | rc = winSeekFile(pFile, offset); |
| 35405 | 35441 | if( rc==0 ){ |
| 35406 | 35442 | #else |
| 35407 | 35443 | { |
| 35408 | 35444 | #endif |
| 35409 | | -#if !SQLITE_OS_WINCE |
| 35445 | +#if !SQLITE_OS_WINCE && !defined(SQLITE_WIN32_NO_OVERLAPPED) |
| 35410 | 35446 | OVERLAPPED overlapped; /* The offset for WriteFile. */ |
| 35411 | 35447 | #endif |
| 35412 | 35448 | u8 *aRem = (u8 *)pBuf; /* Data yet to be written */ |
| 35413 | 35449 | int nRem = amt; /* Number of bytes yet to be written */ |
| 35414 | 35450 | DWORD nWrite; /* Bytes written by each WriteFile() call */ |
| 35415 | 35451 | DWORD lastErrno = NO_ERROR; /* Value returned by GetLastError() */ |
| 35416 | 35452 | |
| 35417 | | -#if !SQLITE_OS_WINCE |
| 35453 | +#if !SQLITE_OS_WINCE && !defined(SQLITE_WIN32_NO_OVERLAPPED) |
| 35418 | 35454 | memset(&overlapped, 0, sizeof(OVERLAPPED)); |
| 35419 | 35455 | overlapped.Offset = (LONG)(offset & 0xffffffff); |
| 35420 | 35456 | overlapped.OffsetHigh = (LONG)((offset>>32) & 0x7fffffff); |
| 35421 | 35457 | #endif |
| 35422 | 35458 | |
| 35423 | 35459 | while( nRem>0 ){ |
| 35424 | | -#if SQLITE_OS_WINCE |
| 35460 | +#if SQLITE_OS_WINCE || defined(SQLITE_WIN32_NO_OVERLAPPED) |
| 35425 | 35461 | if( !osWriteFile(pFile->h, aRem, nRem, &nWrite, 0) ){ |
| 35426 | 35462 | #else |
| 35427 | 35463 | if( !osWriteFile(pFile->h, aRem, nRem, &nWrite, &overlapped) ){ |
| 35428 | 35464 | #endif |
| 35429 | 35465 | if( winRetryIoerr(&nRetry, &lastErrno) ) continue; |
| | @@ -35432,11 +35468,11 @@ |
| 35432 | 35468 | assert( nWrite==0 || nWrite<=(DWORD)nRem ); |
| 35433 | 35469 | if( nWrite==0 || nWrite>(DWORD)nRem ){ |
| 35434 | 35470 | lastErrno = osGetLastError(); |
| 35435 | 35471 | break; |
| 35436 | 35472 | } |
| 35437 | | -#if !SQLITE_OS_WINCE |
| 35473 | +#if !SQLITE_OS_WINCE && !defined(SQLITE_WIN32_NO_OVERLAPPED) |
| 35438 | 35474 | offset += nWrite; |
| 35439 | 35475 | overlapped.Offset = (LONG)(offset & 0xffffffff); |
| 35440 | 35476 | overlapped.OffsetHigh = (LONG)((offset>>32) & 0x7fffffff); |
| 35441 | 35477 | #endif |
| 35442 | 35478 | aRem += nWrite; |
| | @@ -38978,11 +39014,12 @@ |
| 38978 | 39014 | SQLITE_PRIVATE int sqlite3PcacheSetPageSize(PCache *pCache, int szPage){ |
| 38979 | 39015 | assert( pCache->nRef==0 && pCache->pDirty==0 ); |
| 38980 | 39016 | if( pCache->szPage ){ |
| 38981 | 39017 | sqlite3_pcache *pNew; |
| 38982 | 39018 | pNew = sqlite3GlobalConfig.pcache2.xCreate( |
| 38983 | | - szPage, pCache->szExtra + sizeof(PgHdr), pCache->bPurgeable |
| 39019 | + szPage, pCache->szExtra + ROUND8(sizeof(PgHdr)), |
| 39020 | + pCache->bPurgeable |
| 38984 | 39021 | ); |
| 38985 | 39022 | if( pNew==0 ) return SQLITE_NOMEM; |
| 38986 | 39023 | sqlite3GlobalConfig.pcache2.xCachesize(pNew, numberOfCachePages(pCache)); |
| 38987 | 39024 | if( pCache->pCache ){ |
| 38988 | 39025 | sqlite3GlobalConfig.pcache2.xDestroy(pCache->pCache); |
| | @@ -39437,11 +39474,11 @@ |
| 39437 | 39474 | |
| 39438 | 39475 | /* |
| 39439 | 39476 | ** Return the size of the header added by this middleware layer |
| 39440 | 39477 | ** in the page-cache hierarchy. |
| 39441 | 39478 | */ |
| 39442 | | -SQLITE_PRIVATE int sqlite3HeaderSizePcache(void){ return sizeof(PgHdr); } |
| 39479 | +SQLITE_PRIVATE int sqlite3HeaderSizePcache(void){ return ROUND8(sizeof(PgHdr)); } |
| 39443 | 39480 | |
| 39444 | 39481 | |
| 39445 | 39482 | #if defined(SQLITE_CHECK_PAGES) || defined(SQLITE_DEBUG) |
| 39446 | 39483 | /* |
| 39447 | 39484 | ** For all dirty pages currently in the cache, invoke the specified |
| | @@ -39753,11 +39790,11 @@ |
| 39753 | 39790 | pcache1Free(pPg); |
| 39754 | 39791 | sqlite3_free(p); |
| 39755 | 39792 | pPg = 0; |
| 39756 | 39793 | } |
| 39757 | 39794 | #else |
| 39758 | | - pPg = pcache1Alloc(sizeof(PgHdr1) + pCache->szPage + pCache->szExtra); |
| 39795 | + pPg = pcache1Alloc(ROUND8(sizeof(PgHdr1)) + pCache->szPage + pCache->szExtra); |
| 39759 | 39796 | p = (PgHdr1 *)&((u8 *)pPg)[pCache->szPage]; |
| 39760 | 39797 | #endif |
| 39761 | 39798 | pcache1EnterMutex(pCache->pGroup); |
| 39762 | 39799 | |
| 39763 | 39800 | if( pPg ){ |
| | @@ -40441,11 +40478,11 @@ |
| 40441 | 40478 | } |
| 40442 | 40479 | |
| 40443 | 40480 | /* |
| 40444 | 40481 | ** Return the size of the header on each page of this PCACHE implementation. |
| 40445 | 40482 | */ |
| 40446 | | -SQLITE_PRIVATE int sqlite3HeaderSizePcache1(void){ return sizeof(PgHdr1); } |
| 40483 | +SQLITE_PRIVATE int sqlite3HeaderSizePcache1(void){ return ROUND8(sizeof(PgHdr1)); } |
| 40447 | 40484 | |
| 40448 | 40485 | #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT |
| 40449 | 40486 | /* |
| 40450 | 40487 | ** This function is called to free superfluous dynamically allocated memory |
| 40451 | 40488 | ** held by the pager system. Memory in use by any SQLite pager allocated |
| | @@ -41799,10 +41836,12 @@ |
| 41799 | 41836 | u8 eLock; /* Current lock held on database file */ |
| 41800 | 41837 | u8 changeCountDone; /* Set after incrementing the change-counter */ |
| 41801 | 41838 | u8 setMaster; /* True if a m-j name has been written to jrnl */ |
| 41802 | 41839 | u8 doNotSpill; /* Do not spill the cache when non-zero */ |
| 41803 | 41840 | u8 subjInMemory; /* True to use in-memory sub-journals */ |
| 41841 | + u8 bUseFetch; /* True to use xFetch() */ |
| 41842 | + u8 hasBeenUsed; /* True if any content previously read from this pager*/ |
| 41804 | 41843 | Pgno dbSize; /* Number of pages in the database */ |
| 41805 | 41844 | Pgno dbOrigSize; /* dbSize before the current transaction */ |
| 41806 | 41845 | Pgno dbFileSize; /* Number of pages in the database file */ |
| 41807 | 41846 | Pgno dbHintSize; /* Value passed to FCNTL_SIZE_HINT call */ |
| 41808 | 41847 | int errCode; /* One of several kinds of errors */ |
| | @@ -41816,13 +41855,13 @@ |
| 41816 | 41855 | i64 journalOff; /* Current write offset in the journal file */ |
| 41817 | 41856 | i64 journalHdr; /* Byte offset to previous journal header */ |
| 41818 | 41857 | sqlite3_backup *pBackup; /* Pointer to list of ongoing backup processes */ |
| 41819 | 41858 | PagerSavepoint *aSavepoint; /* Array of active savepoints */ |
| 41820 | 41859 | int nSavepoint; /* Number of elements in aSavepoint[] */ |
| 41860 | + u32 iDataVersion; /* Changes whenever database content changes */ |
| 41821 | 41861 | char dbFileVers[16]; /* Changes whenever database file changes */ |
| 41822 | 41862 | |
| 41823 | | - u8 bUseFetch; /* True to use xFetch() */ |
| 41824 | 41863 | int nMmapOut; /* Number of mmap pages currently outstanding */ |
| 41825 | 41864 | sqlite3_int64 szMmap; /* Desired maximum mmap size */ |
| 41826 | 41865 | PgHdr *pMmapFreelist; /* List of free mmap page headers (pDirty) */ |
| 41827 | 41866 | /* |
| 41828 | 41867 | ** End of the routinely-changing class members |
| | @@ -42834,13 +42873,22 @@ |
| 42834 | 42873 | |
| 42835 | 42874 | /* |
| 42836 | 42875 | ** Discard the entire contents of the in-memory page-cache. |
| 42837 | 42876 | */ |
| 42838 | 42877 | static void pager_reset(Pager *pPager){ |
| 42878 | + pPager->iDataVersion++; |
| 42839 | 42879 | sqlite3BackupRestart(pPager->pBackup); |
| 42840 | 42880 | sqlite3PcacheClear(pPager->pPCache); |
| 42841 | 42881 | } |
| 42882 | + |
| 42883 | +/* |
| 42884 | +** Return the pPager->iDataVersion value |
| 42885 | +*/ |
| 42886 | +SQLITE_PRIVATE u32 sqlite3PagerDataVersion(Pager *pPager){ |
| 42887 | + assert( pPager->eState>PAGER_OPEN ); |
| 42888 | + return pPager->iDataVersion; |
| 42889 | +} |
| 42842 | 42890 | |
| 42843 | 42891 | /* |
| 42844 | 42892 | ** Free all structures in the Pager.aSavepoint[] array and set both |
| 42845 | 42893 | ** Pager.aSavepoint and Pager.nSavepoint to zero. Close the sub-journal |
| 42846 | 42894 | ** if it is open and the pager is not in exclusive mode. |
| | @@ -45040,11 +45088,11 @@ |
| 45040 | 45088 | Pgno pgno, /* Page number */ |
| 45041 | 45089 | void *pData, /* xFetch()'d data for this page */ |
| 45042 | 45090 | PgHdr **ppPage /* OUT: Acquired page object */ |
| 45043 | 45091 | ){ |
| 45044 | 45092 | PgHdr *p; /* Memory mapped page to return */ |
| 45045 | | - |
| 45093 | + |
| 45046 | 45094 | if( pPager->pMmapFreelist ){ |
| 45047 | 45095 | *ppPage = p = pPager->pMmapFreelist; |
| 45048 | 45096 | pPager->pMmapFreelist = p->pDirty; |
| 45049 | 45097 | p->pDirty = 0; |
| 45050 | 45098 | memset(p->pExtra, 0, pPager->nExtra); |
| | @@ -46271,20 +46319,16 @@ |
| 46271 | 46319 | assert( (pPager->eLock==SHARED_LOCK) |
| 46272 | 46320 | || (pPager->exclusiveMode && pPager->eLock>SHARED_LOCK) |
| 46273 | 46321 | ); |
| 46274 | 46322 | } |
| 46275 | 46323 | |
| 46276 | | - if( !pPager->tempFile && ( |
| 46277 | | - pPager->pBackup |
| 46278 | | - || sqlite3PcachePagecount(pPager->pPCache)>0 |
| 46279 | | - || USEFETCH(pPager) |
| 46280 | | - )){ |
| 46281 | | - /* The shared-lock has just been acquired on the database file |
| 46282 | | - ** and there are already pages in the cache (from a previous |
| 46283 | | - ** read or write transaction). Check to see if the database |
| 46284 | | - ** has been modified. If the database has changed, flush the |
| 46285 | | - ** cache. |
| 46324 | + if( !pPager->tempFile && pPager->hasBeenUsed ){ |
| 46325 | + /* The shared-lock has just been acquired then check to |
| 46326 | + ** see if the database has been modified. If the database has changed, |
| 46327 | + ** flush the cache. The pPager->hasBeenUsed flag prevents this from |
| 46328 | + ** occurring on the very first access to a file, in order to save a |
| 46329 | + ** single unnecessary sqlite3OsRead() call at the start-up. |
| 46286 | 46330 | ** |
| 46287 | 46331 | ** Database changes is detected by looking at 15 bytes beginning |
| 46288 | 46332 | ** at offset 24 into the file. The first 4 of these 16 bytes are |
| 46289 | 46333 | ** a 32-bit counter that is incremented with each change. The |
| 46290 | 46334 | ** other bytes change randomly with each file change when |
| | @@ -46445,10 +46489,11 @@ |
| 46445 | 46489 | assert( noContent==0 || bMmapOk==0 ); |
| 46446 | 46490 | |
| 46447 | 46491 | if( pgno==0 ){ |
| 46448 | 46492 | return SQLITE_CORRUPT_BKPT; |
| 46449 | 46493 | } |
| 46494 | + pPager->hasBeenUsed = 1; |
| 46450 | 46495 | |
| 46451 | 46496 | /* If the pager is in the error state, return an error immediately. |
| 46452 | 46497 | ** Otherwise, request the page from the PCache layer. */ |
| 46453 | 46498 | if( pPager->errCode!=SQLITE_OK ){ |
| 46454 | 46499 | rc = pPager->errCode; |
| | @@ -46594,10 +46639,11 @@ |
| 46594 | 46639 | sqlite3_pcache_page *pPage; |
| 46595 | 46640 | assert( pPager!=0 ); |
| 46596 | 46641 | assert( pgno!=0 ); |
| 46597 | 46642 | assert( pPager->pPCache!=0 ); |
| 46598 | 46643 | pPage = sqlite3PcacheFetch(pPager->pPCache, pgno, 0); |
| 46644 | + assert( pPage==0 || pPager->hasBeenUsed ); |
| 46599 | 46645 | return sqlite3PcacheFetchFinish(pPager->pPCache, pgno, pPage); |
| 46600 | 46646 | } |
| 46601 | 46647 | |
| 46602 | 46648 | /* |
| 46603 | 46649 | ** Release a page reference. |
| | @@ -47460,10 +47506,11 @@ |
| 47460 | 47506 | pPager->eState = PAGER_READER; |
| 47461 | 47507 | return SQLITE_OK; |
| 47462 | 47508 | } |
| 47463 | 47509 | |
| 47464 | 47510 | PAGERTRACE(("COMMIT %d\n", PAGERID(pPager))); |
| 47511 | + pPager->iDataVersion++; |
| 47465 | 47512 | rc = pager_end_transaction(pPager, pPager->setMaster, 1); |
| 47466 | 47513 | return pager_error(pPager, rc); |
| 47467 | 47514 | } |
| 47468 | 47515 | |
| 47469 | 47516 | /* |
| | @@ -50829,11 +50876,11 @@ |
| 50829 | 50876 | } |
| 50830 | 50877 | nCollide = HASHTABLE_NSLOT; |
| 50831 | 50878 | for(iKey=walHash(pgno); aHash[iKey]; iKey=walNextHash(iKey)){ |
| 50832 | 50879 | u32 iFrame = aHash[iKey] + iZero; |
| 50833 | 50880 | if( iFrame<=iLast && aPgno[aHash[iKey]]==pgno ){ |
| 50834 | | - /* assert( iFrame>iRead ); -- not true if there is corruption */ |
| 50881 | + assert( iFrame>iRead || CORRUPT_DB ); |
| 50835 | 50882 | iRead = iFrame; |
| 50836 | 50883 | } |
| 50837 | 50884 | if( (nCollide--)==0 ){ |
| 50838 | 50885 | return SQLITE_CORRUPT_BKPT; |
| 50839 | 50886 | } |
| | @@ -51935,10 +51982,11 @@ |
| 51935 | 51982 | u8 inTrans; /* TRANS_NONE, TRANS_READ or TRANS_WRITE */ |
| 51936 | 51983 | u8 sharable; /* True if we can share pBt with another db */ |
| 51937 | 51984 | u8 locked; /* True if db currently has pBt locked */ |
| 51938 | 51985 | int wantToLock; /* Number of nested calls to sqlite3BtreeEnter() */ |
| 51939 | 51986 | int nBackup; /* Number of backup operations reading this btree */ |
| 51987 | + u32 iDataVersion; /* Combines with pBt->pPager->iDataVersion */ |
| 51940 | 51988 | Btree *pNext; /* List of other sharable Btrees from the same db */ |
| 51941 | 51989 | Btree *pPrev; /* Back pointer of the same list */ |
| 51942 | 51990 | #ifndef SQLITE_OMIT_SHARED_CACHE |
| 51943 | 51991 | BtLock lock; /* Object used to lock page 1 */ |
| 51944 | 51992 | #endif |
| | @@ -56098,10 +56146,11 @@ |
| 56098 | 56146 | rc = sqlite3PagerCommitPhaseTwo(pBt->pPager); |
| 56099 | 56147 | if( rc!=SQLITE_OK && bCleanup==0 ){ |
| 56100 | 56148 | sqlite3BtreeLeave(p); |
| 56101 | 56149 | return rc; |
| 56102 | 56150 | } |
| 56151 | + p->iDataVersion--; /* Compensate for pPager->iDataVersion++; */ |
| 56103 | 56152 | pBt->inTransaction = TRANS_READ; |
| 56104 | 56153 | btreeClearHasContent(pBt); |
| 56105 | 56154 | } |
| 56106 | 56155 | |
| 56107 | 56156 | btreeEndTransaction(p); |
| | @@ -56461,11 +56510,11 @@ |
| 56461 | 56510 | } |
| 56462 | 56511 | for(i=0; i<=pCur->iPage; i++){ |
| 56463 | 56512 | releasePage(pCur->apPage[i]); |
| 56464 | 56513 | } |
| 56465 | 56514 | unlockBtreeIfUnused(pBt); |
| 56466 | | - sqlite3DbFree(pBtree->db, pCur->aOverflow); |
| 56515 | + sqlite3_free(pCur->aOverflow); |
| 56467 | 56516 | /* sqlite3_free(pCur); */ |
| 56468 | 56517 | sqlite3BtreeLeave(pBtree); |
| 56469 | 56518 | } |
| 56470 | 56519 | return SQLITE_OK; |
| 56471 | 56520 | } |
| | @@ -56755,10 +56804,11 @@ |
| 56755 | 56804 | pBuf += a; |
| 56756 | 56805 | amt -= a; |
| 56757 | 56806 | }else{ |
| 56758 | 56807 | offset -= pCur->info.nLocal; |
| 56759 | 56808 | } |
| 56809 | + |
| 56760 | 56810 | |
| 56761 | 56811 | if( rc==SQLITE_OK && amt>0 ){ |
| 56762 | 56812 | const u32 ovflSize = pBt->usableSize - 4; /* Bytes content per ovfl page */ |
| 56763 | 56813 | Pgno nextPage; |
| 56764 | 56814 | |
| | @@ -56773,12 +56823,12 @@ |
| 56773 | 56823 | ** means "not yet known" (the cache is lazily populated). |
| 56774 | 56824 | */ |
| 56775 | 56825 | if( eOp!=2 && (pCur->curFlags & BTCF_ValidOvfl)==0 ){ |
| 56776 | 56826 | int nOvfl = (pCur->info.nPayload-pCur->info.nLocal+ovflSize-1)/ovflSize; |
| 56777 | 56827 | if( nOvfl>pCur->nOvflAlloc ){ |
| 56778 | | - Pgno *aNew = (Pgno*)sqlite3DbRealloc( |
| 56779 | | - pCur->pBtree->db, pCur->aOverflow, nOvfl*2*sizeof(Pgno) |
| 56828 | + Pgno *aNew = (Pgno*)sqlite3Realloc( |
| 56829 | + pCur->aOverflow, nOvfl*2*sizeof(Pgno) |
| 56780 | 56830 | ); |
| 56781 | 56831 | if( aNew==0 ){ |
| 56782 | 56832 | rc = SQLITE_NOMEM; |
| 56783 | 56833 | }else{ |
| 56784 | 56834 | pCur->nOvflAlloc = nOvfl*2; |
| | @@ -56821,10 +56871,11 @@ |
| 56821 | 56871 | ** Note that the aOverflow[] array must be allocated because eOp!=2 |
| 56822 | 56872 | ** here. If eOp==2, then offset==0 and this branch is never taken. |
| 56823 | 56873 | */ |
| 56824 | 56874 | assert( eOp!=2 ); |
| 56825 | 56875 | assert( pCur->curFlags & BTCF_ValidOvfl ); |
| 56876 | + assert( pCur->pBtree->db==pBt->db ); |
| 56826 | 56877 | if( pCur->aOverflow[iIdx+1] ){ |
| 56827 | 56878 | nextPage = pCur->aOverflow[iIdx+1]; |
| 56828 | 56879 | }else{ |
| 56829 | 56880 | rc = getOverflowPage(pBt, nextPage, 0, &nextPage); |
| 56830 | 56881 | } |
| | @@ -59410,12 +59461,12 @@ |
| 59410 | 59461 | assert( leafCorrection==4 ); |
| 59411 | 59462 | if( szCell[nCell]<4 ){ |
| 59412 | 59463 | /* Do not allow any cells smaller than 4 bytes. If a smaller cell |
| 59413 | 59464 | ** does exist, pad it with 0x00 bytes. */ |
| 59414 | 59465 | assert( szCell[nCell]==3 ); |
| 59415 | | - assert( apCell[nCell]==&pTemp[iSpace1-3] ); |
| 59416 | | - pTemp[iSpace1++] = 0x00; |
| 59466 | + assert( apCell[nCell]==&aSpace1[iSpace1-3] ); |
| 59467 | + aSpace1[iSpace1++] = 0x00; |
| 59417 | 59468 | szCell[nCell] = 4; |
| 59418 | 59469 | } |
| 59419 | 59470 | } |
| 59420 | 59471 | nCell++; |
| 59421 | 59472 | } |
| | @@ -60723,10 +60774,17 @@ |
| 60723 | 60774 | ** is read-only, the others are read/write. |
| 60724 | 60775 | ** |
| 60725 | 60776 | ** The schema layer numbers meta values differently. At the schema |
| 60726 | 60777 | ** layer (and the SetCookie and ReadCookie opcodes) the number of |
| 60727 | 60778 | ** free pages is not visible. So Cookie[0] is the same as Meta[1]. |
| 60779 | +** |
| 60780 | +** This routine treats Meta[BTREE_DATA_VERSION] as a special case. Instead |
| 60781 | +** of reading the value out of the header, it instead loads the "DataVersion" |
| 60782 | +** from the pager. The BTREE_DATA_VERSION value is not actually stored in the |
| 60783 | +** database file. It is a number computed by the pager. But its access |
| 60784 | +** pattern is the same as header meta values, and so it is convenient to |
| 60785 | +** read it from this routine. |
| 60728 | 60786 | */ |
| 60729 | 60787 | SQLITE_PRIVATE void sqlite3BtreeGetMeta(Btree *p, int idx, u32 *pMeta){ |
| 60730 | 60788 | BtShared *pBt = p->pBt; |
| 60731 | 60789 | |
| 60732 | 60790 | sqlite3BtreeEnter(p); |
| | @@ -60733,11 +60791,15 @@ |
| 60733 | 60791 | assert( p->inTrans>TRANS_NONE ); |
| 60734 | 60792 | assert( SQLITE_OK==querySharedCacheTableLock(p, MASTER_ROOT, READ_LOCK) ); |
| 60735 | 60793 | assert( pBt->pPage1 ); |
| 60736 | 60794 | assert( idx>=0 && idx<=15 ); |
| 60737 | 60795 | |
| 60738 | | - *pMeta = get4byte(&pBt->pPage1->aData[36 + idx*4]); |
| 60796 | + if( idx==BTREE_DATA_VERSION ){ |
| 60797 | + *pMeta = sqlite3PagerDataVersion(pBt->pPager) + p->iDataVersion; |
| 60798 | + }else{ |
| 60799 | + *pMeta = get4byte(&pBt->pPage1->aData[36 + idx*4]); |
| 60800 | + } |
| 60739 | 60801 | |
| 60740 | 60802 | /* If auto-vacuum is disabled in this build and this is an auto-vacuum |
| 60741 | 60803 | ** database, mark the database as read-only. */ |
| 60742 | 60804 | #ifdef SQLITE_OMIT_AUTOVACUUM |
| 60743 | 60805 | if( idx==BTREE_LARGEST_ROOT_PAGE && *pMeta>0 ){ |
| | @@ -60824,11 +60886,11 @@ |
| 60824 | 60886 | if( pPage->leaf ){ |
| 60825 | 60887 | do { |
| 60826 | 60888 | if( pCur->iPage==0 ){ |
| 60827 | 60889 | /* All pages of the b-tree have been visited. Return successfully. */ |
| 60828 | 60890 | *pnEntry = nEntry; |
| 60829 | | - return SQLITE_OK; |
| 60891 | + return moveToRoot(pCur); |
| 60830 | 60892 | } |
| 60831 | 60893 | moveToParent(pCur); |
| 60832 | 60894 | }while ( pCur->aiIdx[pCur->iPage]>=pCur->apPage[pCur->iPage]->nCell ); |
| 60833 | 60895 | |
| 60834 | 60896 | pCur->aiIdx[pCur->iPage]++; |
| | @@ -61680,11 +61742,11 @@ |
| 61680 | 61742 | } |
| 61681 | 61743 | |
| 61682 | 61744 | /* |
| 61683 | 61745 | ** Return the size of the header added to each page by this module. |
| 61684 | 61746 | */ |
| 61685 | | -SQLITE_PRIVATE int sqlite3HeaderSizeBtree(void){ return sizeof(MemPage); } |
| 61747 | +SQLITE_PRIVATE int sqlite3HeaderSizeBtree(void){ return ROUND8(sizeof(MemPage)); } |
| 61686 | 61748 | |
| 61687 | 61749 | /************** End of btree.c ***********************************************/ |
| 61688 | 61750 | /************** Begin file backup.c ******************************************/ |
| 61689 | 61751 | /* |
| 61690 | 61752 | ** 2009 January 28 |
| | @@ -64444,36 +64506,39 @@ |
| 64444 | 64506 | ** |
| 64445 | 64507 | ** assert( sqlite3VdbeAssertMayAbort(pParse->pVdbe, pParse->mayAbort) ); |
| 64446 | 64508 | */ |
| 64447 | 64509 | SQLITE_PRIVATE int sqlite3VdbeAssertMayAbort(Vdbe *v, int mayAbort){ |
| 64448 | 64510 | int hasAbort = 0; |
| 64511 | + int hasFkCounter = 0; |
| 64449 | 64512 | Op *pOp; |
| 64450 | 64513 | VdbeOpIter sIter; |
| 64451 | 64514 | memset(&sIter, 0, sizeof(sIter)); |
| 64452 | 64515 | sIter.v = v; |
| 64453 | 64516 | |
| 64454 | 64517 | while( (pOp = opIterNext(&sIter))!=0 ){ |
| 64455 | 64518 | int opcode = pOp->opcode; |
| 64456 | 64519 | if( opcode==OP_Destroy || opcode==OP_VUpdate || opcode==OP_VRename |
| 64457 | | -#ifndef SQLITE_OMIT_FOREIGN_KEY |
| 64458 | | - || (opcode==OP_FkCounter && pOp->p1==0 && pOp->p2==1) |
| 64459 | | -#endif |
| 64460 | 64520 | || ((opcode==OP_Halt || opcode==OP_HaltIfNull) |
| 64461 | 64521 | && ((pOp->p1&0xff)==SQLITE_CONSTRAINT && pOp->p2==OE_Abort)) |
| 64462 | 64522 | ){ |
| 64463 | 64523 | hasAbort = 1; |
| 64464 | 64524 | break; |
| 64465 | 64525 | } |
| 64526 | +#ifndef SQLITE_OMIT_FOREIGN_KEY |
| 64527 | + if( opcode==OP_FkCounter && pOp->p1==0 && pOp->p2==1 ){ |
| 64528 | + hasFkCounter = 1; |
| 64529 | + } |
| 64530 | +#endif |
| 64466 | 64531 | } |
| 64467 | 64532 | sqlite3DbFree(v->db, sIter.apSub); |
| 64468 | 64533 | |
| 64469 | 64534 | /* Return true if hasAbort==mayAbort. Or if a malloc failure occurred. |
| 64470 | 64535 | ** If malloc failed, then the while() loop above may not have iterated |
| 64471 | 64536 | ** through all opcodes and hasAbort may be set incorrectly. Return |
| 64472 | 64537 | ** true for this case to prevent the assert() in the callers frame |
| 64473 | 64538 | ** from failing. */ |
| 64474 | | - return ( v->db->mallocFailed || hasAbort==mayAbort ); |
| 64539 | + return ( v->db->mallocFailed || hasAbort==mayAbort || hasFkCounter ); |
| 64475 | 64540 | } |
| 64476 | 64541 | #endif /* SQLITE_DEBUG - the sqlite3AssertMayAbort() function */ |
| 64477 | 64542 | |
| 64478 | 64543 | /* |
| 64479 | 64544 | ** Loop through the program looking for P2 values that are negative |
| | @@ -68593,11 +68658,14 @@ |
| 68593 | 68658 | #ifndef SQLITE_OMIT_WAL |
| 68594 | 68659 | int i; |
| 68595 | 68660 | for(i=0; i<db->nDb; i++){ |
| 68596 | 68661 | Btree *pBt = db->aDb[i].pBt; |
| 68597 | 68662 | if( pBt ){ |
| 68598 | | - int nEntry = sqlite3PagerWalCallback(sqlite3BtreePager(pBt)); |
| 68663 | + int nEntry; |
| 68664 | + sqlite3BtreeEnter(pBt); |
| 68665 | + nEntry = sqlite3PagerWalCallback(sqlite3BtreePager(pBt)); |
| 68666 | + sqlite3BtreeLeave(pBt); |
| 68599 | 68667 | if( db->xWalCallback && nEntry>0 && rc==SQLITE_OK ){ |
| 68600 | 68668 | rc = db->xWalCallback(db->pWalArg, db, db->aDb[i].zName, nEntry); |
| 68601 | 68669 | } |
| 68602 | 68670 | } |
| 68603 | 68671 | } |
| | @@ -68773,11 +68841,10 @@ |
| 68773 | 68841 | ** program counter to 0 to ensure that when the statement is |
| 68774 | 68842 | ** finalized or reset the parser error message is available via |
| 68775 | 68843 | ** sqlite3_errmsg() and sqlite3_errcode(). |
| 68776 | 68844 | */ |
| 68777 | 68845 | const char *zErr = (const char *)sqlite3_value_text(db->pErr); |
| 68778 | | - assert( zErr!=0 || db->mallocFailed ); |
| 68779 | 68846 | sqlite3DbFree(db, v->zErrMsg); |
| 68780 | 68847 | if( !db->mallocFailed ){ |
| 68781 | 68848 | v->zErrMsg = sqlite3DbStrDup(db, zErr); |
| 68782 | 68849 | v->rc = rc2; |
| 68783 | 68850 | } else { |
| | @@ -77135,11 +77202,11 @@ |
| 77135 | 77202 | /* |
| 77136 | 77203 | ** Hard-coded maximum amount of data to accumulate in memory before flushing |
| 77137 | 77204 | ** to a level 0 PMA. The purpose of this limit is to prevent various integer |
| 77138 | 77205 | ** overflows. 512MiB. |
| 77139 | 77206 | */ |
| 77140 | | -#define SQLITE_MAX_MXPMASIZE (1<<29) |
| 77207 | +#define SQLITE_MAX_PMASZ (1<<29) |
| 77141 | 77208 | |
| 77142 | 77209 | /* |
| 77143 | 77210 | ** Private objects used by the sorter |
| 77144 | 77211 | */ |
| 77145 | 77212 | typedef struct MergeEngine MergeEngine; /* Merge PMAs together */ |
| | @@ -77431,15 +77498,10 @@ |
| 77431 | 77498 | ** |
| 77432 | 77499 | ** void *SRVAL(SorterRecord *p) { return (void*)&p[1]; } |
| 77433 | 77500 | */ |
| 77434 | 77501 | #define SRVAL(p) ((void*)((SorterRecord*)(p) + 1)) |
| 77435 | 77502 | |
| 77436 | | -/* The minimum PMA size is set to this value multiplied by the database |
| 77437 | | -** page size in bytes. */ |
| 77438 | | -#ifndef SQLITE_SORTER_PMASZ |
| 77439 | | -# define SQLITE_SORTER_PMASZ 10 |
| 77440 | | -#endif |
| 77441 | 77503 | |
| 77442 | 77504 | /* Maximum number of PMAs that a single MergeEngine can merge */ |
| 77443 | 77505 | #define SORTER_MAX_MERGE_COUNT 16 |
| 77444 | 77506 | |
| 77445 | 77507 | static int vdbeIncrSwap(IncrMerger*); |
| | @@ -77834,14 +77896,15 @@ |
| 77834 | 77896 | SortSubtask *pTask = &pSorter->aTask[i]; |
| 77835 | 77897 | pTask->pSorter = pSorter; |
| 77836 | 77898 | } |
| 77837 | 77899 | |
| 77838 | 77900 | if( !sqlite3TempInMemory(db) ){ |
| 77839 | | - pSorter->mnPmaSize = SQLITE_SORTER_PMASZ * pgsz; |
| 77901 | + u32 szPma = sqlite3GlobalConfig.szPma; |
| 77902 | + pSorter->mnPmaSize = szPma * pgsz; |
| 77840 | 77903 | mxCache = db->aDb[0].pSchema->cache_size; |
| 77841 | | - if( mxCache<SQLITE_SORTER_PMASZ ) mxCache = SQLITE_SORTER_PMASZ; |
| 77842 | | - pSorter->mxPmaSize = MIN((i64)mxCache*pgsz, SQLITE_MAX_MXPMASIZE); |
| 77904 | + if( mxCache<(int)szPma ) mxCache = (int)szPma; |
| 77905 | + pSorter->mxPmaSize = MIN((i64)mxCache*pgsz, SQLITE_MAX_PMASZ); |
| 77843 | 77906 | |
| 77844 | 77907 | /* EVIDENCE-OF: R-26747-61719 When the application provides any amount of |
| 77845 | 77908 | ** scratch memory using SQLITE_CONFIG_SCRATCH, SQLite avoids unnecessary |
| 77846 | 77909 | ** large heap allocations. |
| 77847 | 77910 | */ |
| | @@ -78115,16 +78178,16 @@ |
| 78115 | 78178 | ** Whether or not the file does end up memory mapped of course depends on |
| 78116 | 78179 | ** the specific VFS implementation. |
| 78117 | 78180 | */ |
| 78118 | 78181 | static void vdbeSorterExtendFile(sqlite3 *db, sqlite3_file *pFd, i64 nByte){ |
| 78119 | 78182 | if( nByte<=(i64)(db->nMaxSorterMmap) && pFd->pMethods->iVersion>=3 ){ |
| 78120 | | - int rc = sqlite3OsTruncate(pFd, nByte); |
| 78121 | | - if( rc==SQLITE_OK ){ |
| 78122 | | - void *p = 0; |
| 78123 | | - sqlite3OsFetch(pFd, 0, (int)nByte, &p); |
| 78124 | | - sqlite3OsUnfetch(pFd, 0, p); |
| 78125 | | - } |
| 78183 | + void *p = 0; |
| 78184 | + int chunksize = 4*1024; |
| 78185 | + sqlite3OsFileControlHint(pFd, SQLITE_FCNTL_CHUNK_SIZE, &chunksize); |
| 78186 | + sqlite3OsFileControlHint(pFd, SQLITE_FCNTL_SIZE_HINT, &nByte); |
| 78187 | + sqlite3OsFetch(pFd, 0, (int)nByte, &p); |
| 78188 | + sqlite3OsUnfetch(pFd, 0, p); |
| 78126 | 78189 | } |
| 78127 | 78190 | } |
| 78128 | 78191 | #else |
| 78129 | 78192 | # define vdbeSorterExtendFile(x,y,z) |
| 78130 | 78193 | #endif |
| | @@ -87302,11 +87365,11 @@ |
| 87302 | 87365 | |
| 87303 | 87366 | p->iGet = -1; |
| 87304 | 87367 | p->mxSample = mxSample; |
| 87305 | 87368 | p->nPSample = (tRowcnt)(sqlite3_value_int64(argv[2])/(mxSample/3+1) + 1); |
| 87306 | 87369 | p->current.anLt = &p->current.anEq[nColUp]; |
| 87307 | | - p->iPrn = nCol*0x689e962d ^ sqlite3_value_int(argv[2])*0xd0944565; |
| 87370 | + p->iPrn = 0x689e962d*(u32)nCol ^ 0xd0944565*(u32)sqlite3_value_int(argv[2]); |
| 87308 | 87371 | |
| 87309 | 87372 | /* Set up the Stat4Accum.a[] and aBest[] arrays */ |
| 87310 | 87373 | p->a = (struct Stat4Sample*)&p->current.anLt[nColUp]; |
| 87311 | 87374 | p->aBest = &p->a[mxSample]; |
| 87312 | 87375 | pSpace = (u8*)(&p->a[mxSample+nCol]); |
| | @@ -88895,17 +88958,19 @@ |
| 88895 | 88958 | }else if( aNew->pSchema->file_format && aNew->pSchema->enc!=ENC(db) ){ |
| 88896 | 88959 | zErrDyn = sqlite3MPrintf(db, |
| 88897 | 88960 | "attached databases must use the same text encoding as main database"); |
| 88898 | 88961 | rc = SQLITE_ERROR; |
| 88899 | 88962 | } |
| 88963 | + sqlite3BtreeEnter(aNew->pBt); |
| 88900 | 88964 | pPager = sqlite3BtreePager(aNew->pBt); |
| 88901 | 88965 | sqlite3PagerLockingMode(pPager, db->dfltLockMode); |
| 88902 | 88966 | sqlite3BtreeSecureDelete(aNew->pBt, |
| 88903 | 88967 | sqlite3BtreeSecureDelete(db->aDb[0].pBt,-1) ); |
| 88904 | 88968 | #ifndef SQLITE_OMIT_PAGER_PRAGMAS |
| 88905 | 88969 | sqlite3BtreeSetPagerFlags(aNew->pBt, 3 | (db->flags & PAGER_FLAGS_MASK)); |
| 88906 | 88970 | #endif |
| 88971 | + sqlite3BtreeLeave(aNew->pBt); |
| 88907 | 88972 | } |
| 88908 | 88973 | aNew->safety_level = 3; |
| 88909 | 88974 | aNew->zName = sqlite3DbStrDup(db, zName); |
| 88910 | 88975 | if( rc==SQLITE_OK && aNew->zName==0 ){ |
| 88911 | 88976 | rc = SQLITE_NOMEM; |
| | @@ -90027,11 +90092,10 @@ |
| 90027 | 90092 | */ |
| 90028 | 90093 | static void freeIndex(sqlite3 *db, Index *p){ |
| 90029 | 90094 | #ifndef SQLITE_OMIT_ANALYZE |
| 90030 | 90095 | sqlite3DeleteIndexSamples(db, p); |
| 90031 | 90096 | #endif |
| 90032 | | - if( db==0 || db->pnBytesFreed==0 ) sqlite3KeyInfoUnref(p->pKeyInfo); |
| 90033 | 90097 | sqlite3ExprDelete(db, p->pPartIdxWhere); |
| 90034 | 90098 | sqlite3DbFree(db, p->zColAff); |
| 90035 | 90099 | if( p->isResized ) sqlite3DbFree(db, p->azColl); |
| 90036 | 90100 | #ifdef SQLITE_ENABLE_STAT3_OR_STAT4 |
| 90037 | 90101 | sqlite3_free(p->aiRowEst); |
| | @@ -91306,10 +91370,23 @@ |
| 91306 | 91370 | if( pPk==0 ) return; |
| 91307 | 91371 | pPk->idxType = SQLITE_IDXTYPE_PRIMARYKEY; |
| 91308 | 91372 | pTab->iPKey = -1; |
| 91309 | 91373 | }else{ |
| 91310 | 91374 | pPk = sqlite3PrimaryKeyIndex(pTab); |
| 91375 | + /* |
| 91376 | + ** Remove all redundant columns from the PRIMARY KEY. For example, change |
| 91377 | + ** "PRIMARY KEY(a,b,a,b,c,b,c,d)" into just "PRIMARY KEY(a,b,c,d)". Later |
| 91378 | + ** code assumes the PRIMARY KEY contains no repeated columns. |
| 91379 | + */ |
| 91380 | + for(i=j=1; i<pPk->nKeyCol; i++){ |
| 91381 | + if( hasColumn(pPk->aiColumn, j, pPk->aiColumn[i]) ){ |
| 91382 | + pPk->nColumn--; |
| 91383 | + }else{ |
| 91384 | + pPk->aiColumn[j++] = pPk->aiColumn[i]; |
| 91385 | + } |
| 91386 | + } |
| 91387 | + pPk->nKeyCol = j; |
| 91311 | 91388 | } |
| 91312 | 91389 | pPk->isCovering = 1; |
| 91313 | 91390 | assert( pPk!=0 ); |
| 91314 | 91391 | nPk = pPk->nKeyCol; |
| 91315 | 91392 | |
| | @@ -93782,44 +93859,35 @@ |
| 93782 | 93859 | ** |
| 93783 | 93860 | ** The caller should invoke sqlite3KeyInfoUnref() on the returned object |
| 93784 | 93861 | ** when it has finished using it. |
| 93785 | 93862 | */ |
| 93786 | 93863 | SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoOfIndex(Parse *pParse, Index *pIdx){ |
| 93864 | + int i; |
| 93865 | + int nCol = pIdx->nColumn; |
| 93866 | + int nKey = pIdx->nKeyCol; |
| 93867 | + KeyInfo *pKey; |
| 93787 | 93868 | if( pParse->nErr ) return 0; |
| 93788 | | -#ifndef SQLITE_OMIT_SHARED_CACHE |
| 93789 | | - if( pIdx->pKeyInfo && pIdx->pKeyInfo->db!=pParse->db ){ |
| 93790 | | - sqlite3KeyInfoUnref(pIdx->pKeyInfo); |
| 93791 | | - pIdx->pKeyInfo = 0; |
| 93792 | | - } |
| 93793 | | -#endif |
| 93794 | | - if( pIdx->pKeyInfo==0 ){ |
| 93795 | | - int i; |
| 93796 | | - int nCol = pIdx->nColumn; |
| 93797 | | - int nKey = pIdx->nKeyCol; |
| 93798 | | - KeyInfo *pKey; |
| 93799 | | - if( pIdx->uniqNotNull ){ |
| 93800 | | - pKey = sqlite3KeyInfoAlloc(pParse->db, nKey, nCol-nKey); |
| 93801 | | - }else{ |
| 93802 | | - pKey = sqlite3KeyInfoAlloc(pParse->db, nCol, 0); |
| 93803 | | - } |
| 93804 | | - if( pKey ){ |
| 93805 | | - assert( sqlite3KeyInfoIsWriteable(pKey) ); |
| 93806 | | - for(i=0; i<nCol; i++){ |
| 93807 | | - char *zColl = pIdx->azColl[i]; |
| 93808 | | - assert( zColl!=0 ); |
| 93809 | | - pKey->aColl[i] = strcmp(zColl,"BINARY")==0 ? 0 : |
| 93810 | | - sqlite3LocateCollSeq(pParse, zColl); |
| 93811 | | - pKey->aSortOrder[i] = pIdx->aSortOrder[i]; |
| 93812 | | - } |
| 93813 | | - if( pParse->nErr ){ |
| 93814 | | - sqlite3KeyInfoUnref(pKey); |
| 93815 | | - }else{ |
| 93816 | | - pIdx->pKeyInfo = pKey; |
| 93817 | | - } |
| 93818 | | - } |
| 93819 | | - } |
| 93820 | | - return sqlite3KeyInfoRef(pIdx->pKeyInfo); |
| 93869 | + if( pIdx->uniqNotNull ){ |
| 93870 | + pKey = sqlite3KeyInfoAlloc(pParse->db, nKey, nCol-nKey); |
| 93871 | + }else{ |
| 93872 | + pKey = sqlite3KeyInfoAlloc(pParse->db, nCol, 0); |
| 93873 | + } |
| 93874 | + if( pKey ){ |
| 93875 | + assert( sqlite3KeyInfoIsWriteable(pKey) ); |
| 93876 | + for(i=0; i<nCol; i++){ |
| 93877 | + char *zColl = pIdx->azColl[i]; |
| 93878 | + assert( zColl!=0 ); |
| 93879 | + pKey->aColl[i] = strcmp(zColl,"BINARY")==0 ? 0 : |
| 93880 | + sqlite3LocateCollSeq(pParse, zColl); |
| 93881 | + pKey->aSortOrder[i] = pIdx->aSortOrder[i]; |
| 93882 | + } |
| 93883 | + if( pParse->nErr ){ |
| 93884 | + sqlite3KeyInfoUnref(pKey); |
| 93885 | + pKey = 0; |
| 93886 | + } |
| 93887 | + } |
| 93888 | + return pKey; |
| 93821 | 93889 | } |
| 93822 | 93890 | |
| 93823 | 93891 | #ifndef SQLITE_OMIT_CTE |
| 93824 | 93892 | /* |
| 93825 | 93893 | ** This routine is invoked once per CTE by the parser while parsing a |
| | @@ -97436,11 +97504,11 @@ |
| 97436 | 97504 | assert( nIncr==1 ); |
| 97437 | 97505 | sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_FOREIGNKEY, |
| 97438 | 97506 | OE_Abort, 0, P4_STATIC, P5_ConstraintFK); |
| 97439 | 97507 | }else{ |
| 97440 | 97508 | if( nIncr>0 && pFKey->isDeferred==0 ){ |
| 97441 | | - sqlite3ParseToplevel(pParse)->mayAbort = 1; |
| 97509 | + sqlite3MayAbort(pParse); |
| 97442 | 97510 | } |
| 97443 | 97511 | sqlite3VdbeAddOp2(v, OP_FkCounter, pFKey->isDeferred, nIncr); |
| 97444 | 97512 | } |
| 97445 | 97513 | |
| 97446 | 97514 | sqlite3VdbeResolveLabel(v, iOk); |
| | @@ -97507,10 +97575,14 @@ |
| 97507 | 97575 | ** This function is called to generate code executed when a row is deleted |
| 97508 | 97576 | ** from the parent table of foreign key constraint pFKey and, if pFKey is |
| 97509 | 97577 | ** deferred, when a row is inserted into the same table. When generating |
| 97510 | 97578 | ** code for an SQL UPDATE operation, this function may be called twice - |
| 97511 | 97579 | ** once to "delete" the old row and once to "insert" the new row. |
| 97580 | +** |
| 97581 | +** Parameter nIncr is passed -1 when inserting a row (as this may decrease |
| 97582 | +** the number of FK violations in the db) or +1 when deleting one (as this |
| 97583 | +** may increase the number of FK constraint problems). |
| 97512 | 97584 | ** |
| 97513 | 97585 | ** The code generated by this function scans through the rows in the child |
| 97514 | 97586 | ** table that correspond to the parent table row being deleted or inserted. |
| 97515 | 97587 | ** For each child row found, one of the following actions is taken: |
| 97516 | 97588 | ** |
| | @@ -97624,17 +97696,13 @@ |
| 97624 | 97696 | sNameContext.pSrcList = pSrc; |
| 97625 | 97697 | sNameContext.pParse = pParse; |
| 97626 | 97698 | sqlite3ResolveExprNames(&sNameContext, pWhere); |
| 97627 | 97699 | |
| 97628 | 97700 | /* Create VDBE to loop through the entries in pSrc that match the WHERE |
| 97629 | | - ** clause. If the constraint is not deferred, throw an exception for |
| 97630 | | - ** each row found. Otherwise, for deferred constraints, increment the |
| 97631 | | - ** deferred constraint counter by nIncr for each row selected. */ |
| 97701 | + ** clause. For each row found, increment either the deferred or immediate |
| 97702 | + ** foreign key constraint counter. */ |
| 97632 | 97703 | pWInfo = sqlite3WhereBegin(pParse, pSrc, pWhere, 0, 0, 0, 0); |
| 97633 | | - if( nIncr>0 && pFKey->isDeferred==0 ){ |
| 97634 | | - sqlite3ParseToplevel(pParse)->mayAbort = 1; |
| 97635 | | - } |
| 97636 | 97704 | sqlite3VdbeAddOp2(v, OP_FkCounter, pFKey->isDeferred, nIncr); |
| 97637 | 97705 | if( pWInfo ){ |
| 97638 | 97706 | sqlite3WhereEnd(pWInfo); |
| 97639 | 97707 | } |
| 97640 | 97708 | |
| | @@ -97808,10 +97876,28 @@ |
| 97808 | 97876 | } |
| 97809 | 97877 | } |
| 97810 | 97878 | } |
| 97811 | 97879 | return 0; |
| 97812 | 97880 | } |
| 97881 | + |
| 97882 | +/* |
| 97883 | +** Return true if the parser passed as the first argument is being |
| 97884 | +** used to code a trigger that is really a "SET NULL" action belonging |
| 97885 | +** to trigger pFKey. |
| 97886 | +*/ |
| 97887 | +static int isSetNullAction(Parse *pParse, FKey *pFKey){ |
| 97888 | + Parse *pTop = sqlite3ParseToplevel(pParse); |
| 97889 | + if( pTop->pTriggerPrg ){ |
| 97890 | + Trigger *p = pTop->pTriggerPrg->pTrigger; |
| 97891 | + if( (p==pFKey->apTrigger[0] && pFKey->aAction[0]==OE_SetNull) |
| 97892 | + || (p==pFKey->apTrigger[1] && pFKey->aAction[1]==OE_SetNull) |
| 97893 | + ){ |
| 97894 | + return 1; |
| 97895 | + } |
| 97896 | + } |
| 97897 | + return 0; |
| 97898 | +} |
| 97813 | 97899 | |
| 97814 | 97900 | /* |
| 97815 | 97901 | ** This function is called when inserting, deleting or updating a row of |
| 97816 | 97902 | ** table pTab to generate VDBE code to perform foreign key constraint |
| 97817 | 97903 | ** processing for the operation. |
| | @@ -97861,11 +97947,11 @@ |
| 97861 | 97947 | Index *pIdx = 0; /* Index on key columns in pTo */ |
| 97862 | 97948 | int *aiFree = 0; |
| 97863 | 97949 | int *aiCol; |
| 97864 | 97950 | int iCol; |
| 97865 | 97951 | int i; |
| 97866 | | - int isIgnore = 0; |
| 97952 | + int bIgnore = 0; |
| 97867 | 97953 | |
| 97868 | 97954 | if( aChange |
| 97869 | 97955 | && sqlite3_stricmp(pTab->zName, pFKey->zTo)!=0 |
| 97870 | 97956 | && fkChildIsModified(pTab, pFKey, aChange, bChngRowid)==0 |
| 97871 | 97957 | ){ |
| | @@ -97920,11 +98006,11 @@ |
| 97920 | 98006 | ** values read from the parent table are NULL. */ |
| 97921 | 98007 | if( db->xAuth ){ |
| 97922 | 98008 | int rcauth; |
| 97923 | 98009 | char *zCol = pTo->aCol[pIdx ? pIdx->aiColumn[i] : pTo->iPKey].zName; |
| 97924 | 98010 | rcauth = sqlite3AuthReadCol(pParse, pTo->zName, zCol, iDb); |
| 97925 | | - isIgnore = (rcauth==SQLITE_IGNORE); |
| 98011 | + bIgnore = (rcauth==SQLITE_IGNORE); |
| 97926 | 98012 | } |
| 97927 | 98013 | #endif |
| 97928 | 98014 | } |
| 97929 | 98015 | |
| 97930 | 98016 | /* Take a shared-cache advisory read-lock on the parent table. Allocate |
| | @@ -97935,16 +98021,22 @@ |
| 97935 | 98021 | |
| 97936 | 98022 | if( regOld!=0 ){ |
| 97937 | 98023 | /* A row is being removed from the child table. Search for the parent. |
| 97938 | 98024 | ** If the parent does not exist, removing the child row resolves an |
| 97939 | 98025 | ** outstanding foreign key constraint violation. */ |
| 97940 | | - fkLookupParent(pParse, iDb, pTo, pIdx, pFKey, aiCol, regOld, -1,isIgnore); |
| 98026 | + fkLookupParent(pParse, iDb, pTo, pIdx, pFKey, aiCol, regOld, -1, bIgnore); |
| 97941 | 98027 | } |
| 97942 | | - if( regNew!=0 ){ |
| 98028 | + if( regNew!=0 && !isSetNullAction(pParse, pFKey) ){ |
| 97943 | 98029 | /* A row is being added to the child table. If a parent row cannot |
| 97944 | | - ** be found, adding the child row has violated the FK constraint. */ |
| 97945 | | - fkLookupParent(pParse, iDb, pTo, pIdx, pFKey, aiCol, regNew, +1,isIgnore); |
| 98030 | + ** be found, adding the child row has violated the FK constraint. |
| 98031 | + ** |
| 98032 | + ** If this operation is being performed as part of a trigger program |
| 98033 | + ** that is actually a "SET NULL" action belonging to this very |
| 98034 | + ** foreign key, then omit this scan altogether. As all child key |
| 98035 | + ** values are guaranteed to be NULL, it is not possible for adding |
| 98036 | + ** this row to cause an FK violation. */ |
| 98037 | + fkLookupParent(pParse, iDb, pTo, pIdx, pFKey, aiCol, regNew, +1, bIgnore); |
| 97946 | 98038 | } |
| 97947 | 98039 | |
| 97948 | 98040 | sqlite3DbFree(db, aiFree); |
| 97949 | 98041 | } |
| 97950 | 98042 | |
| | @@ -97961,12 +98053,12 @@ |
| 97961 | 98053 | |
| 97962 | 98054 | if( !pFKey->isDeferred && !(db->flags & SQLITE_DeferFKs) |
| 97963 | 98055 | && !pParse->pToplevel && !pParse->isMultiWrite |
| 97964 | 98056 | ){ |
| 97965 | 98057 | assert( regOld==0 && regNew!=0 ); |
| 97966 | | - /* Inserting a single row into a parent table cannot cause an immediate |
| 97967 | | - ** foreign key violation. So do nothing in this case. */ |
| 98058 | + /* Inserting a single row into a parent table cannot cause (or fix) |
| 98059 | + ** an immediate foreign key violation. So do nothing in this case. */ |
| 97968 | 98060 | continue; |
| 97969 | 98061 | } |
| 97970 | 98062 | |
| 97971 | 98063 | if( sqlite3FkLocateIndex(pParse, pTab, pFKey, &pIdx, &aiCol) ){ |
| 97972 | 98064 | if( !isIgnoreErrors || db->mallocFailed ) return; |
| | @@ -97986,17 +98078,32 @@ |
| 97986 | 98078 | |
| 97987 | 98079 | if( regNew!=0 ){ |
| 97988 | 98080 | fkScanChildren(pParse, pSrc, pTab, pIdx, pFKey, aiCol, regNew, -1); |
| 97989 | 98081 | } |
| 97990 | 98082 | if( regOld!=0 ){ |
| 97991 | | - /* If there is a RESTRICT action configured for the current operation |
| 97992 | | - ** on the parent table of this FK, then throw an exception |
| 97993 | | - ** immediately if the FK constraint is violated, even if this is a |
| 97994 | | - ** deferred trigger. That's what RESTRICT means. To defer checking |
| 97995 | | - ** the constraint, the FK should specify NO ACTION (represented |
| 97996 | | - ** using OE_None). NO ACTION is the default. */ |
| 98083 | + int eAction = pFKey->aAction[aChange!=0]; |
| 97997 | 98084 | fkScanChildren(pParse, pSrc, pTab, pIdx, pFKey, aiCol, regOld, 1); |
| 98085 | + /* If this is a deferred FK constraint, or a CASCADE or SET NULL |
| 98086 | + ** action applies, then any foreign key violations caused by |
| 98087 | + ** removing the parent key will be rectified by the action trigger. |
| 98088 | + ** So do not set the "may-abort" flag in this case. |
| 98089 | + ** |
| 98090 | + ** Note 1: If the FK is declared "ON UPDATE CASCADE", then the |
| 98091 | + ** may-abort flag will eventually be set on this statement anyway |
| 98092 | + ** (when this function is called as part of processing the UPDATE |
| 98093 | + ** within the action trigger). |
| 98094 | + ** |
| 98095 | + ** Note 2: At first glance it may seem like SQLite could simply omit |
| 98096 | + ** all OP_FkCounter related scans when either CASCADE or SET NULL |
| 98097 | + ** applies. The trouble starts if the CASCADE or SET NULL action |
| 98098 | + ** trigger causes other triggers or action rules attached to the |
| 98099 | + ** child table to fire. In these cases the fk constraint counters |
| 98100 | + ** might be set incorrectly if any OP_FkCounter related scans are |
| 98101 | + ** omitted. */ |
| 98102 | + if( !pFKey->isDeferred && eAction!=OE_Cascade && eAction!=OE_SetNull ){ |
| 98103 | + sqlite3MayAbort(pParse); |
| 98104 | + } |
| 97998 | 98105 | } |
| 97999 | 98106 | pItem->zName = 0; |
| 98000 | 98107 | sqlite3SrcListDelete(db, pSrc); |
| 98001 | 98108 | } |
| 98002 | 98109 | sqlite3DbFree(db, aiCol); |
| | @@ -101895,10 +102002,11 @@ |
| 101895 | 102002 | #define PragTyp_KEY 38 |
| 101896 | 102003 | #define PragTyp_REKEY 39 |
| 101897 | 102004 | #define PragTyp_LOCK_STATUS 40 |
| 101898 | 102005 | #define PragTyp_PARSER_TRACE 41 |
| 101899 | 102006 | #define PragFlag_NeedSchema 0x01 |
| 102007 | +#define PragFlag_ReadOnly 0x02 |
| 101900 | 102008 | static const struct sPragmaNames { |
| 101901 | 102009 | const char *const zName; /* Name of pragma */ |
| 101902 | 102010 | u8 ePragTyp; /* PragTyp_XXX value */ |
| 101903 | 102011 | u8 mPragFlag; /* Zero or more PragFlag_XXX values */ |
| 101904 | 102012 | u32 iArg; /* Extra argument */ |
| | @@ -101911,11 +102019,11 @@ |
| 101911 | 102019 | #endif |
| 101912 | 102020 | #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS) |
| 101913 | 102021 | { /* zName: */ "application_id", |
| 101914 | 102022 | /* ePragTyp: */ PragTyp_HEADER_VALUE, |
| 101915 | 102023 | /* ePragFlag: */ 0, |
| 101916 | | - /* iArg: */ 0 }, |
| 102024 | + /* iArg: */ BTREE_APPLICATION_ID }, |
| 101917 | 102025 | #endif |
| 101918 | 102026 | #if !defined(SQLITE_OMIT_AUTOVACUUM) |
| 101919 | 102027 | { /* zName: */ "auto_vacuum", |
| 101920 | 102028 | /* ePragTyp: */ PragTyp_AUTO_VACUUM, |
| 101921 | 102029 | /* ePragFlag: */ PragFlag_NeedSchema, |
| | @@ -101977,10 +102085,16 @@ |
| 101977 | 102085 | { /* zName: */ "data_store_directory", |
| 101978 | 102086 | /* ePragTyp: */ PragTyp_DATA_STORE_DIRECTORY, |
| 101979 | 102087 | /* ePragFlag: */ 0, |
| 101980 | 102088 | /* iArg: */ 0 }, |
| 101981 | 102089 | #endif |
| 102090 | +#if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS) |
| 102091 | + { /* zName: */ "data_version", |
| 102092 | + /* ePragTyp: */ PragTyp_HEADER_VALUE, |
| 102093 | + /* ePragFlag: */ PragFlag_ReadOnly, |
| 102094 | + /* iArg: */ BTREE_DATA_VERSION }, |
| 102095 | +#endif |
| 101982 | 102096 | #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) |
| 101983 | 102097 | { /* zName: */ "database_list", |
| 101984 | 102098 | /* ePragTyp: */ PragTyp_DATABASE_LIST, |
| 101985 | 102099 | /* ePragFlag: */ PragFlag_NeedSchema, |
| 101986 | 102100 | /* iArg: */ 0 }, |
| | @@ -102032,12 +102146,12 @@ |
| 102032 | 102146 | #endif |
| 102033 | 102147 | #endif |
| 102034 | 102148 | #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS) |
| 102035 | 102149 | { /* zName: */ "freelist_count", |
| 102036 | 102150 | /* ePragTyp: */ PragTyp_HEADER_VALUE, |
| 102037 | | - /* ePragFlag: */ 0, |
| 102038 | | - /* iArg: */ 0 }, |
| 102151 | + /* ePragFlag: */ PragFlag_ReadOnly, |
| 102152 | + /* iArg: */ BTREE_FREE_PAGE_COUNT }, |
| 102039 | 102153 | #endif |
| 102040 | 102154 | #if !defined(SQLITE_OMIT_FLAG_PRAGMAS) |
| 102041 | 102155 | { /* zName: */ "full_column_names", |
| 102042 | 102156 | /* ePragTyp: */ PragTyp_FLAG, |
| 102043 | 102157 | /* ePragFlag: */ 0, |
| | @@ -102185,11 +102299,11 @@ |
| 102185 | 102299 | #endif |
| 102186 | 102300 | #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS) |
| 102187 | 102301 | { /* zName: */ "schema_version", |
| 102188 | 102302 | /* ePragTyp: */ PragTyp_HEADER_VALUE, |
| 102189 | 102303 | /* ePragFlag: */ 0, |
| 102190 | | - /* iArg: */ 0 }, |
| 102304 | + /* iArg: */ BTREE_SCHEMA_VERSION }, |
| 102191 | 102305 | #endif |
| 102192 | 102306 | #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) |
| 102193 | 102307 | { /* zName: */ "secure_delete", |
| 102194 | 102308 | /* ePragTyp: */ PragTyp_SECURE_DELETE, |
| 102195 | 102309 | /* ePragFlag: */ 0, |
| | @@ -102251,11 +102365,11 @@ |
| 102251 | 102365 | /* iArg: */ 0 }, |
| 102252 | 102366 | #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS) |
| 102253 | 102367 | { /* zName: */ "user_version", |
| 102254 | 102368 | /* ePragTyp: */ PragTyp_HEADER_VALUE, |
| 102255 | 102369 | /* ePragFlag: */ 0, |
| 102256 | | - /* iArg: */ 0 }, |
| 102370 | + /* iArg: */ BTREE_USER_VERSION }, |
| 102257 | 102371 | #endif |
| 102258 | 102372 | #if !defined(SQLITE_OMIT_FLAG_PRAGMAS) |
| 102259 | 102373 | #if defined(SQLITE_DEBUG) |
| 102260 | 102374 | { /* zName: */ "vdbe_addoptrace", |
| 102261 | 102375 | /* ePragTyp: */ PragTyp_FLAG, |
| | @@ -102294,11 +102408,11 @@ |
| 102294 | 102408 | /* ePragTyp: */ PragTyp_FLAG, |
| 102295 | 102409 | /* ePragFlag: */ 0, |
| 102296 | 102410 | /* iArg: */ SQLITE_WriteSchema|SQLITE_RecoveryMode }, |
| 102297 | 102411 | #endif |
| 102298 | 102412 | }; |
| 102299 | | -/* Number of pragmas: 57 on by default, 70 total. */ |
| 102413 | +/* Number of pragmas: 58 on by default, 71 total. */ |
| 102300 | 102414 | /* End of the automatically generated pragma table. |
| 102301 | 102415 | ***************************************************************************/ |
| 102302 | 102416 | |
| 102303 | 102417 | /* |
| 102304 | 102418 | ** Interpret the given string as a safety level. Return 0 for OFF, |
| | @@ -103904,11 +104018,12 @@ |
| 103904 | 104018 | !(DbHasProperty(db, 0, DB_SchemaLoaded)) || |
| 103905 | 104019 | DbHasProperty(db, 0, DB_Empty) |
| 103906 | 104020 | ){ |
| 103907 | 104021 | for(pEnc=&encnames[0]; pEnc->zName; pEnc++){ |
| 103908 | 104022 | if( 0==sqlite3StrICmp(zRight, pEnc->zName) ){ |
| 103909 | | - ENC(pParse->db) = pEnc->enc ? pEnc->enc : SQLITE_UTF16NATIVE; |
| 104023 | + SCHEMA_ENC(db) = ENC(db) = |
| 104024 | + pEnc->enc ? pEnc->enc : SQLITE_UTF16NATIVE; |
| 103910 | 104025 | break; |
| 103911 | 104026 | } |
| 103912 | 104027 | } |
| 103913 | 104028 | if( !pEnc->zName ){ |
| 103914 | 104029 | sqlite3ErrorMsg(pParse, "unsupported encoding: %s", zRight); |
| | @@ -103949,28 +104064,13 @@ |
| 103949 | 104064 | ** |
| 103950 | 104065 | ** The user-version is not used internally by SQLite. It may be used by |
| 103951 | 104066 | ** applications for any purpose. |
| 103952 | 104067 | */ |
| 103953 | 104068 | case PragTyp_HEADER_VALUE: { |
| 103954 | | - int iCookie; /* Cookie index. 1 for schema-cookie, 6 for user-cookie. */ |
| 104069 | + int iCookie = aPragmaNames[mid].iArg; /* Which cookie to read or write */ |
| 103955 | 104070 | sqlite3VdbeUsesBtree(v, iDb); |
| 103956 | | - switch( zLeft[0] ){ |
| 103957 | | - case 'a': case 'A': |
| 103958 | | - iCookie = BTREE_APPLICATION_ID; |
| 103959 | | - break; |
| 103960 | | - case 'f': case 'F': |
| 103961 | | - iCookie = BTREE_FREE_PAGE_COUNT; |
| 103962 | | - break; |
| 103963 | | - case 's': case 'S': |
| 103964 | | - iCookie = BTREE_SCHEMA_VERSION; |
| 103965 | | - break; |
| 103966 | | - default: |
| 103967 | | - iCookie = BTREE_USER_VERSION; |
| 103968 | | - break; |
| 103969 | | - } |
| 103970 | | - |
| 103971 | | - if( zRight && iCookie!=BTREE_FREE_PAGE_COUNT ){ |
| 104071 | + if( zRight && (aPragmaNames[mid].mPragFlag & PragFlag_ReadOnly)==0 ){ |
| 103972 | 104072 | /* Write the specified cookie value */ |
| 103973 | 104073 | static const VdbeOpList setCookie[] = { |
| 103974 | 104074 | { OP_Transaction, 0, 1, 0}, /* 0 */ |
| 103975 | 104075 | { OP_Integer, 0, 1, 0}, /* 1 */ |
| 103976 | 104076 | { OP_SetCookie, 0, 0, 1}, /* 2 */ |
| | @@ -104612,13 +104712,15 @@ |
| 104612 | 104712 | SQLITE_PRIVATE int sqlite3Init(sqlite3 *db, char **pzErrMsg){ |
| 104613 | 104713 | int i, rc; |
| 104614 | 104714 | int commit_internal = !(db->flags&SQLITE_InternChanges); |
| 104615 | 104715 | |
| 104616 | 104716 | assert( sqlite3_mutex_held(db->mutex) ); |
| 104717 | + assert( sqlite3BtreeHoldsMutex(db->aDb[0].pBt) ); |
| 104617 | 104718 | assert( db->init.busy==0 ); |
| 104618 | 104719 | rc = SQLITE_OK; |
| 104619 | 104720 | db->init.busy = 1; |
| 104721 | + ENC(db) = SCHEMA_ENC(db); |
| 104620 | 104722 | for(i=0; rc==SQLITE_OK && i<db->nDb; i++){ |
| 104621 | 104723 | if( DbHasProperty(db, i, DB_SchemaLoaded) || i==1 ) continue; |
| 104622 | 104724 | rc = sqlite3InitOne(db, i, pzErrMsg); |
| 104623 | 104725 | if( rc ){ |
| 104624 | 104726 | sqlite3ResetOneSchema(db, i); |
| | @@ -110756,11 +110858,11 @@ |
| 110756 | 110858 | ){ |
| 110757 | 110859 | int rc; |
| 110758 | 110860 | TabResult res; |
| 110759 | 110861 | |
| 110760 | 110862 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 110761 | | - if( pazResult==0 ) return SQLITE_MISUSE_BKPT; |
| 110863 | + if( !sqlite3SafetyCheckOk(db) || pazResult==0 ) return SQLITE_MISUSE_BKPT; |
| 110762 | 110864 | #endif |
| 110763 | 110865 | *pazResult = 0; |
| 110764 | 110866 | if( pnColumn ) *pnColumn = 0; |
| 110765 | 110867 | if( pnRow ) *pnRow = 0; |
| 110766 | 110868 | if( pzErrMsg ) *pzErrMsg = 0; |
| | @@ -118626,11 +118728,10 @@ |
| 118626 | 118728 | sqlite3_free(p->u.vtab.idxStr); |
| 118627 | 118729 | p->u.vtab.needFree = 0; |
| 118628 | 118730 | p->u.vtab.idxStr = 0; |
| 118629 | 118731 | }else if( (p->wsFlags & WHERE_AUTO_INDEX)!=0 && p->u.btree.pIndex!=0 ){ |
| 118630 | 118732 | sqlite3DbFree(db, p->u.btree.pIndex->zColAff); |
| 118631 | | - sqlite3KeyInfoUnref(p->u.btree.pIndex->pKeyInfo); |
| 118632 | 118733 | sqlite3DbFree(db, p->u.btree.pIndex); |
| 118633 | 118734 | p->u.btree.pIndex = 0; |
| 118634 | 118735 | } |
| 118635 | 118736 | } |
| 118636 | 118737 | } |
| | @@ -125633,10 +125734,13 @@ |
| 125633 | 125734 | u8 enableLookaside; /* Saved value of db->lookaside.bEnabled */ |
| 125634 | 125735 | sqlite3 *db = pParse->db; /* The database connection */ |
| 125635 | 125736 | int mxSqlLen; /* Max length of an SQL string */ |
| 125636 | 125737 | |
| 125637 | 125738 | |
| 125739 | +#ifdef SQLITE_ENABLE_API_ARMOR |
| 125740 | + if( zSql==0 || pzErrMsg==0 ) return SQLITE_MISUSE_BKPT; |
| 125741 | +#endif |
| 125638 | 125742 | mxSqlLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH]; |
| 125639 | 125743 | if( db->nVdbeActive==0 ){ |
| 125640 | 125744 | db->u1.isInterrupted = 0; |
| 125641 | 125745 | } |
| 125642 | 125746 | pParse->rc = SQLITE_OK; |
| | @@ -125871,17 +125975,10 @@ |
| 125871 | 125975 | */ |
| 125872 | 125976 | SQLITE_API int sqlite3_complete(const char *zSql){ |
| 125873 | 125977 | u8 state = 0; /* Current state, using numbers defined in header comment */ |
| 125874 | 125978 | u8 token; /* Value of the next token */ |
| 125875 | 125979 | |
| 125876 | | -#ifdef SQLITE_ENABLE_API_ARMOR |
| 125877 | | - if( zSql==0 ){ |
| 125878 | | - (void)SQLITE_MISUSE_BKPT; |
| 125879 | | - return 0; |
| 125880 | | - } |
| 125881 | | -#endif |
| 125882 | | - |
| 125883 | 125980 | #ifndef SQLITE_OMIT_TRIGGER |
| 125884 | 125981 | /* A complex statement machine used to detect the end of a CREATE TRIGGER |
| 125885 | 125982 | ** statement. This is the normal case. |
| 125886 | 125983 | */ |
| 125887 | 125984 | static const u8 trans[8][8] = { |
| | @@ -125906,10 +126003,17 @@ |
| 125906 | 126003 | /* 0 INVALID: */ { 1, 0, 2, }, |
| 125907 | 126004 | /* 1 START: */ { 1, 1, 2, }, |
| 125908 | 126005 | /* 2 NORMAL: */ { 1, 2, 2, }, |
| 125909 | 126006 | }; |
| 125910 | 126007 | #endif /* SQLITE_OMIT_TRIGGER */ |
| 126008 | + |
| 126009 | +#ifdef SQLITE_ENABLE_API_ARMOR |
| 126010 | + if( zSql==0 ){ |
| 126011 | + (void)SQLITE_MISUSE_BKPT; |
| 126012 | + return 0; |
| 126013 | + } |
| 126014 | +#endif |
| 125911 | 126015 | |
| 125912 | 126016 | while( *zSql ){ |
| 125913 | 126017 | switch( *zSql ){ |
| 125914 | 126018 | case ';': { /* A semicolon */ |
| 125915 | 126019 | token = tkSEMI; |
| | @@ -126208,11 +126312,11 @@ |
| 126208 | 126312 | ** If the following function pointer is not NULL and if |
| 126209 | 126313 | ** SQLITE_ENABLE_IOTRACE is enabled, then messages describing |
| 126210 | 126314 | ** I/O active are written using this function. These messages |
| 126211 | 126315 | ** are intended for debugging activity only. |
| 126212 | 126316 | */ |
| 126213 | | -SQLITE_PRIVATE void (*sqlite3IoTrace)(const char*, ...) = 0; |
| 126317 | +/* not-private */ void (*sqlite3IoTrace)(const char*, ...) = 0; |
| 126214 | 126318 | #endif |
| 126215 | 126319 | |
| 126216 | 126320 | /* |
| 126217 | 126321 | ** If the following global variable points to a string which is the |
| 126218 | 126322 | ** name of a directory, then that directory will be used to store |
| | @@ -126417,10 +126521,17 @@ |
| 126417 | 126521 | ** routine is not threadsafe. But it is safe to invoke this routine |
| 126418 | 126522 | ** on when SQLite is already shut down. If SQLite is already shut down |
| 126419 | 126523 | ** when this routine is invoked, then this routine is a harmless no-op. |
| 126420 | 126524 | */ |
| 126421 | 126525 | SQLITE_API int sqlite3_shutdown(void){ |
| 126526 | +#ifdef SQLITE_OMIT_WSD |
| 126527 | + int rc = sqlite3_wsd_init(4096, 24); |
| 126528 | + if( rc!=SQLITE_OK ){ |
| 126529 | + return rc; |
| 126530 | + } |
| 126531 | +#endif |
| 126532 | + |
| 126422 | 126533 | if( sqlite3GlobalConfig.isInit ){ |
| 126423 | 126534 | #ifdef SQLITE_EXTRA_SHUTDOWN |
| 126424 | 126535 | void SQLITE_EXTRA_SHUTDOWN(void); |
| 126425 | 126536 | SQLITE_EXTRA_SHUTDOWN(); |
| 126426 | 126537 | #endif |
| | @@ -126732,10 +126843,15 @@ |
| 126732 | 126843 | ** heap. */ |
| 126733 | 126844 | sqlite3GlobalConfig.nHeap = va_arg(ap, int); |
| 126734 | 126845 | break; |
| 126735 | 126846 | } |
| 126736 | 126847 | #endif |
| 126848 | + |
| 126849 | + case SQLITE_CONFIG_PMASZ: { |
| 126850 | + sqlite3GlobalConfig.szPma = va_arg(ap, unsigned int); |
| 126851 | + break; |
| 126852 | + } |
| 126737 | 126853 | |
| 126738 | 126854 | default: { |
| 126739 | 126855 | rc = SQLITE_ERROR; |
| 126740 | 126856 | break; |
| 126741 | 126857 | } |
| | @@ -127178,20 +127294,10 @@ |
| 127178 | 127294 | |
| 127179 | 127295 | /* Close all database connections */ |
| 127180 | 127296 | for(j=0; j<db->nDb; j++){ |
| 127181 | 127297 | struct Db *pDb = &db->aDb[j]; |
| 127182 | 127298 | if( pDb->pBt ){ |
| 127183 | | - if( pDb->pSchema ){ |
| 127184 | | - /* Must clear the KeyInfo cache. See ticket [e4a18565a36884b00edf] */ |
| 127185 | | - sqlite3BtreeEnter(pDb->pBt); |
| 127186 | | - for(i=sqliteHashFirst(&pDb->pSchema->idxHash); i; i=sqliteHashNext(i)){ |
| 127187 | | - Index *pIdx = sqliteHashData(i); |
| 127188 | | - sqlite3KeyInfoUnref(pIdx->pKeyInfo); |
| 127189 | | - pIdx->pKeyInfo = 0; |
| 127190 | | - } |
| 127191 | | - sqlite3BtreeLeave(pDb->pBt); |
| 127192 | | - } |
| 127193 | 127299 | sqlite3BtreeClose(pDb->pBt); |
| 127194 | 127300 | pDb->pBt = 0; |
| 127195 | 127301 | if( j!=1 ){ |
| 127196 | 127302 | pDb->pSchema = 0; |
| 127197 | 127303 | } |
| | @@ -128315,36 +128421,10 @@ |
| 128315 | 128421 | */ |
| 128316 | 128422 | SQLITE_API const char *sqlite3_errstr(int rc){ |
| 128317 | 128423 | return sqlite3ErrStr(rc); |
| 128318 | 128424 | } |
| 128319 | 128425 | |
| 128320 | | -/* |
| 128321 | | -** Invalidate all cached KeyInfo objects for database connection "db" |
| 128322 | | -*/ |
| 128323 | | -static void invalidateCachedKeyInfo(sqlite3 *db){ |
| 128324 | | - Db *pDb; /* A single database */ |
| 128325 | | - int iDb; /* The database index number */ |
| 128326 | | - HashElem *k; /* For looping over tables in pDb */ |
| 128327 | | - Table *pTab; /* A table in the database */ |
| 128328 | | - Index *pIdx; /* Each index */ |
| 128329 | | - |
| 128330 | | - for(iDb=0, pDb=db->aDb; iDb<db->nDb; iDb++, pDb++){ |
| 128331 | | - if( pDb->pBt==0 ) continue; |
| 128332 | | - sqlite3BtreeEnter(pDb->pBt); |
| 128333 | | - for(k=sqliteHashFirst(&pDb->pSchema->tblHash); k; k=sqliteHashNext(k)){ |
| 128334 | | - pTab = (Table*)sqliteHashData(k); |
| 128335 | | - for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ |
| 128336 | | - if( pIdx->pKeyInfo && pIdx->pKeyInfo->db==db ){ |
| 128337 | | - sqlite3KeyInfoUnref(pIdx->pKeyInfo); |
| 128338 | | - pIdx->pKeyInfo = 0; |
| 128339 | | - } |
| 128340 | | - } |
| 128341 | | - } |
| 128342 | | - sqlite3BtreeLeave(pDb->pBt); |
| 128343 | | - } |
| 128344 | | -} |
| 128345 | | - |
| 128346 | 128426 | /* |
| 128347 | 128427 | ** Create a new collating function for database "db". The name is zName |
| 128348 | 128428 | ** and the encoding is enc. |
| 128349 | 128429 | */ |
| 128350 | 128430 | static int createCollation( |
| | @@ -128384,11 +128464,10 @@ |
| 128384 | 128464 | sqlite3ErrorWithMsg(db, SQLITE_BUSY, |
| 128385 | 128465 | "unable to delete/modify collation sequence due to active statements"); |
| 128386 | 128466 | return SQLITE_BUSY; |
| 128387 | 128467 | } |
| 128388 | 128468 | sqlite3ExpirePreparedStatements(db); |
| 128389 | | - invalidateCachedKeyInfo(db); |
| 128390 | 128469 | |
| 128391 | 128470 | /* If collation sequence pColl was created directly by a call to |
| 128392 | 128471 | ** sqlite3_create_collation, and not generated by synthCollSeq(), |
| 128393 | 128472 | ** then any copies made by synthCollSeq() need to be invalidated. |
| 128394 | 128473 | ** Also, collation destructor - CollSeq.xDel() - function may need |
| | @@ -128941,10 +129020,11 @@ |
| 128941 | 129020 | sqlite3Error(db, rc); |
| 128942 | 129021 | goto opendb_out; |
| 128943 | 129022 | } |
| 128944 | 129023 | sqlite3BtreeEnter(db->aDb[0].pBt); |
| 128945 | 129024 | db->aDb[0].pSchema = sqlite3SchemaGet(db, db->aDb[0].pBt); |
| 129025 | + if( !db->mallocFailed ) ENC(db) = SCHEMA_ENC(db); |
| 128946 | 129026 | sqlite3BtreeLeave(db->aDb[0].pBt); |
| 128947 | 129027 | db->aDb[1].pSchema = sqlite3SchemaGet(db, 0); |
| 128948 | 129028 | |
| 128949 | 129029 | /* The default safety_level for the main database is 'full'; for the temp |
| 128950 | 129030 | ** database it is 'NONE'. This matches the pager layer defaults. |
| | @@ -129099,11 +129179,11 @@ |
| 129099 | 129179 | if( zFilename8 ){ |
| 129100 | 129180 | rc = openDatabase(zFilename8, ppDb, |
| 129101 | 129181 | SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, 0); |
| 129102 | 129182 | assert( *ppDb || rc==SQLITE_NOMEM ); |
| 129103 | 129183 | if( rc==SQLITE_OK && !DbHasProperty(*ppDb, 0, DB_SchemaLoaded) ){ |
| 129104 | | - ENC(*ppDb) = SQLITE_UTF16NATIVE; |
| 129184 | + SCHEMA_ENC(*ppDb) = ENC(*ppDb) = SQLITE_UTF16NATIVE; |
| 129105 | 129185 | } |
| 129106 | 129186 | }else{ |
| 129107 | 129187 | rc = SQLITE_NOMEM; |
| 129108 | 129188 | } |
| 129109 | 129189 | sqlite3ValueFree(pVal); |
| | @@ -129841,32 +129921,34 @@ |
| 129841 | 129921 | /* |
| 129842 | 129922 | ** Return the filename of the database associated with a database |
| 129843 | 129923 | ** connection. |
| 129844 | 129924 | */ |
| 129845 | 129925 | SQLITE_API const char *sqlite3_db_filename(sqlite3 *db, const char *zDbName){ |
| 129926 | + Btree *pBt; |
| 129846 | 129927 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 129847 | 129928 | if( !sqlite3SafetyCheckOk(db) ){ |
| 129848 | 129929 | (void)SQLITE_MISUSE_BKPT; |
| 129849 | 129930 | return 0; |
| 129850 | 129931 | } |
| 129851 | 129932 | #endif |
| 129852 | | - Btree *pBt = sqlite3DbNameToBtree(db, zDbName); |
| 129933 | + pBt = sqlite3DbNameToBtree(db, zDbName); |
| 129853 | 129934 | return pBt ? sqlite3BtreeGetFilename(pBt) : 0; |
| 129854 | 129935 | } |
| 129855 | 129936 | |
| 129856 | 129937 | /* |
| 129857 | 129938 | ** Return 1 if database is read-only or 0 if read/write. Return -1 if |
| 129858 | 129939 | ** no such database exists. |
| 129859 | 129940 | */ |
| 129860 | 129941 | SQLITE_API int sqlite3_db_readonly(sqlite3 *db, const char *zDbName){ |
| 129942 | + Btree *pBt; |
| 129861 | 129943 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 129862 | 129944 | if( !sqlite3SafetyCheckOk(db) ){ |
| 129863 | 129945 | (void)SQLITE_MISUSE_BKPT; |
| 129864 | 129946 | return -1; |
| 129865 | 129947 | } |
| 129866 | 129948 | #endif |
| 129867 | | - Btree *pBt = sqlite3DbNameToBtree(db, zDbName); |
| 129949 | + pBt = sqlite3DbNameToBtree(db, zDbName); |
| 129868 | 129950 | return pBt ? sqlite3BtreeIsReadonly(pBt) : -1; |
| 129869 | 129951 | } |
| 129870 | 129952 | |
| 129871 | 129953 | /************** End of main.c ************************************************/ |
| 129872 | 129954 | /************** Begin file notify.c ******************************************/ |
| | @@ -150073,11 +150155,11 @@ |
| 150073 | 150155 | } |
| 150074 | 150156 | i = pCur->nPoint++; |
| 150075 | 150157 | pNew = pCur->aPoint + i; |
| 150076 | 150158 | pNew->rScore = rScore; |
| 150077 | 150159 | pNew->iLevel = iLevel; |
| 150078 | | - assert( iLevel>=0 && iLevel<=RTREE_MAX_DEPTH ); |
| 150160 | + assert( iLevel<=RTREE_MAX_DEPTH ); |
| 150079 | 150161 | while( i>0 ){ |
| 150080 | 150162 | RtreeSearchPoint *pParent; |
| 150081 | 150163 | j = (i-1)/2; |
| 150082 | 150164 | pParent = pCur->aPoint + j; |
| 150083 | 150165 | if( rtreeSearchPointCompare(pNew, pParent)>=0 ) break; |
| 150084 | 150166 | |