| | @@ -41,10 +41,57 @@ |
| 41 | 41 | ** |
| 42 | 42 | */ |
| 43 | 43 | #ifndef _SQLITEINT_H_ |
| 44 | 44 | #define _SQLITEINT_H_ |
| 45 | 45 | |
| 46 | +/* |
| 47 | +** Include the header file used to customize the compiler options for MSVC. |
| 48 | +** This should be done first so that it can successfully prevent spurious |
| 49 | +** compiler warnings due to subsequent content in this file and other files |
| 50 | +** that are included by this file. |
| 51 | +*/ |
| 52 | +/************** Include msvc.h in the middle of sqliteInt.h ******************/ |
| 53 | +/************** Begin file msvc.h ********************************************/ |
| 54 | +/* |
| 55 | +** 2015 January 12 |
| 56 | +** |
| 57 | +** The author disclaims copyright to this source code. In place of |
| 58 | +** a legal notice, here is a blessing: |
| 59 | +** |
| 60 | +** May you do good and not evil. |
| 61 | +** May you find forgiveness for yourself and forgive others. |
| 62 | +** May you share freely, never taking more than you give. |
| 63 | +** |
| 64 | +****************************************************************************** |
| 65 | +** |
| 66 | +** This file contains code that is specific to MSVC. |
| 67 | +*/ |
| 68 | +#ifndef _MSVC_H_ |
| 69 | +#define _MSVC_H_ |
| 70 | + |
| 71 | +#if defined(_MSC_VER) |
| 72 | +#pragma warning(disable : 4054) |
| 73 | +#pragma warning(disable : 4055) |
| 74 | +#pragma warning(disable : 4100) |
| 75 | +#pragma warning(disable : 4127) |
| 76 | +#pragma warning(disable : 4152) |
| 77 | +#pragma warning(disable : 4189) |
| 78 | +#pragma warning(disable : 4206) |
| 79 | +#pragma warning(disable : 4210) |
| 80 | +#pragma warning(disable : 4232) |
| 81 | +#pragma warning(disable : 4244) |
| 82 | +#pragma warning(disable : 4305) |
| 83 | +#pragma warning(disable : 4306) |
| 84 | +#pragma warning(disable : 4702) |
| 85 | +#pragma warning(disable : 4706) |
| 86 | +#endif /* defined(_MSC_VER) */ |
| 87 | + |
| 88 | +#endif /* _MSVC_H_ */ |
| 89 | + |
| 90 | +/************** End of msvc.h ************************************************/ |
| 91 | +/************** Continuing where we left off in sqliteInt.h ******************/ |
| 92 | + |
| 46 | 93 | /* |
| 47 | 94 | ** These #defines should enable >2GB file support on POSIX if the |
| 48 | 95 | ** underlying operating system supports it. If the OS lacks |
| 49 | 96 | ** large file support, or if the OS is windows, these should be no-ops. |
| 50 | 97 | ** |
| | @@ -231,11 +278,11 @@ |
| 231 | 278 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 232 | 279 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 233 | 280 | */ |
| 234 | 281 | #define SQLITE_VERSION "3.8.8" |
| 235 | 282 | #define SQLITE_VERSION_NUMBER 3008008 |
| 236 | | -#define SQLITE_SOURCE_ID "2014-12-10 04:58:43 3528f8dd39acace8eeb7337994c8617313f4b04b" |
| 283 | +#define SQLITE_SOURCE_ID "2015-01-12 21:43:00 e693e11d1b9265974c32bddba873ea30a4d0b708" |
| 237 | 284 | |
| 238 | 285 | /* |
| 239 | 286 | ** CAPI3REF: Run-Time Library Version Numbers |
| 240 | 287 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 241 | 288 | ** |
| | @@ -323,11 +370,11 @@ |
| 323 | 370 | ** This interface only reports on the compile-time mutex setting |
| 324 | 371 | ** of the [SQLITE_THREADSAFE] flag. If SQLite is compiled with |
| 325 | 372 | ** SQLITE_THREADSAFE=1 or =2 then mutexes are enabled by default but |
| 326 | 373 | ** can be fully or partially disabled using a call to [sqlite3_config()] |
| 327 | 374 | ** with the verbs [SQLITE_CONFIG_SINGLETHREAD], [SQLITE_CONFIG_MULTITHREAD], |
| 328 | | -** or [SQLITE_CONFIG_MUTEX]. ^(The return value of the |
| 375 | +** or [SQLITE_CONFIG_SERIALIZED]. ^(The return value of the |
| 329 | 376 | ** sqlite3_threadsafe() function shows only the compile-time setting of |
| 330 | 377 | ** thread safety, not any run-time changes to that setting made by |
| 331 | 378 | ** sqlite3_config(). In other words, the return value from sqlite3_threadsafe() |
| 332 | 379 | ** is unchanged by calls to sqlite3_config().)^ |
| 333 | 380 | ** |
| | @@ -1692,11 +1739,11 @@ |
| 1692 | 1739 | ** configuration option. |
| 1693 | 1740 | ** ^There are three arguments to SQLITE_CONFIG_PAGECACHE: A pointer to |
| 1694 | 1741 | ** 8-byte aligned |
| 1695 | 1742 | ** memory, the size of each page buffer (sz), and the number of pages (N). |
| 1696 | 1743 | ** 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 |
| 1744 | +** (a power of two between 512 and 65536) plus some extra bytes for each |
| 1698 | 1745 | ** page header. ^The number of extra bytes needed by the page header |
| 1699 | 1746 | ** can be determined using the [SQLITE_CONFIG_PCACHE_HDRSZ] option |
| 1700 | 1747 | ** to [sqlite3_config()]. |
| 1701 | 1748 | ** ^It is harmless, apart from the wasted memory, |
| 1702 | 1749 | ** for the sz parameter to be larger than necessary. The first |
| | @@ -1872,10 +1919,21 @@ |
| 1872 | 1919 | ** <dd>^The SQLITE_CONFIG_PCACHE_HDRSZ option takes a single parameter which |
| 1873 | 1920 | ** is a pointer to an integer and writes into that integer the number of extra |
| 1874 | 1921 | ** bytes per page required for each page in [SQLITE_CONFIG_PAGECACHE]. |
| 1875 | 1922 | ** The amount of extra space required can change depending on the compiler, |
| 1876 | 1923 | ** target platform, and SQLite version. |
| 1924 | +** |
| 1925 | +** [[SQLITE_CONFIG_PMASZ]] |
| 1926 | +** <dt>SQLITE_CONFIG_PMASZ |
| 1927 | +** <dd>^The SQLITE_CONFIG_PMASZ option takes a single parameter which |
| 1928 | +** is an unsigned integer and sets the "Minimum PMA Size" for the multithreaded |
| 1929 | +** sorter to that integer. The default minimum PMA Size is set by the |
| 1930 | +** [SQLITE_SORTER_PMASZ] compile-time option. New threads are launched |
| 1931 | +** to help with sort operations when multithreaded sorting |
| 1932 | +** is enabled (using the [PRAGMA threads] command) and the amount of content |
| 1933 | +** to be sorted exceeds the page size times the minimum of the |
| 1934 | +** [PRAGMA cache_size] setting and this value. |
| 1877 | 1935 | ** </dl> |
| 1878 | 1936 | */ |
| 1879 | 1937 | #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */ |
| 1880 | 1938 | #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */ |
| 1881 | 1939 | #define SQLITE_CONFIG_SERIALIZED 3 /* nil */ |
| | @@ -1898,10 +1956,11 @@ |
| 1898 | 1956 | #define SQLITE_CONFIG_COVERING_INDEX_SCAN 20 /* int */ |
| 1899 | 1957 | #define SQLITE_CONFIG_SQLLOG 21 /* xSqllog, void* */ |
| 1900 | 1958 | #define SQLITE_CONFIG_MMAP_SIZE 22 /* sqlite3_int64, sqlite3_int64 */ |
| 1901 | 1959 | #define SQLITE_CONFIG_WIN32_HEAPSIZE 23 /* int nByte */ |
| 1902 | 1960 | #define SQLITE_CONFIG_PCACHE_HDRSZ 24 /* int *psz */ |
| 1961 | +#define SQLITE_CONFIG_PMASZ 25 /* unsigned int szPma */ |
| 1903 | 1962 | |
| 1904 | 1963 | /* |
| 1905 | 1964 | ** CAPI3REF: Database Connection Configuration Options |
| 1906 | 1965 | ** |
| 1907 | 1966 | ** These constants are the available integer configuration options that |
| | @@ -7307,16 +7366,14 @@ |
| 7307 | 7366 | |
| 7308 | 7367 | /* |
| 7309 | 7368 | ** CAPI3REF: Write-Ahead Log Commit Hook |
| 7310 | 7369 | ** |
| 7311 | 7370 | ** ^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]). |
| 7371 | +** is invoked each time data is committed to a database in wal mode. |
| 7315 | 7372 | ** |
| 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 |
| 7373 | +** ^(The callback is invoked by SQLite after the commit has taken place and |
| 7374 | +** the associated write-lock on the database released)^, so the implementation |
| 7318 | 7375 | ** may read, write or [checkpoint] the database as required. |
| 7319 | 7376 | ** |
| 7320 | 7377 | ** ^The first parameter passed to the callback function when it is invoked |
| 7321 | 7378 | ** is a copy of the third parameter passed to sqlite3_wal_hook() when |
| 7322 | 7379 | ** registering the callback. ^The second is a copy of the database handle. |
| | @@ -7603,10 +7660,14 @@ |
| 7603 | 7660 | ** |
| 7604 | 7661 | ** The following constants can be used for the T parameter to the |
| 7605 | 7662 | ** [sqlite3_stmt_scanstatus(S,X,T,V)] interface. Each constant designates a |
| 7606 | 7663 | ** different metric for sqlite3_stmt_scanstatus() to return. |
| 7607 | 7664 | ** |
| 7665 | +** When the value returned to V is a string, space to hold that string is |
| 7666 | +** managed by the prepared statement S and will be automatically freed when |
| 7667 | +** S is finalized. |
| 7668 | +** |
| 7608 | 7669 | ** <dl> |
| 7609 | 7670 | ** [[SQLITE_SCANSTAT_NLOOP]] <dt>SQLITE_SCANSTAT_NLOOP</dt> |
| 7610 | 7671 | ** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be |
| 7611 | 7672 | ** set to the total number of times that the X-th loop has run.</dd> |
| 7612 | 7673 | ** |
| | @@ -7648,11 +7709,18 @@ |
| 7648 | 7709 | #define SQLITE_SCANSTAT_SELECTID 5 |
| 7649 | 7710 | |
| 7650 | 7711 | /* |
| 7651 | 7712 | ** CAPI3REF: Prepared Statement Scan Status |
| 7652 | 7713 | ** |
| 7653 | | -** Return status data for a single loop within query pStmt. |
| 7714 | +** This interface returns information about the predicted and measured |
| 7715 | +** performance for pStmt. Advanced applications can use this |
| 7716 | +** interface to compare the predicted and the measured performance and |
| 7717 | +** issue warnings and/or rerun [ANALYZE] if discrepancies are found. |
| 7718 | +** |
| 7719 | +** Since this interface is expected to be rarely used, it is only |
| 7720 | +** available if SQLite is compiled using the [SQLITE_ENABLE_STMT_SCANSTATUS] |
| 7721 | +** compile-time option. |
| 7654 | 7722 | ** |
| 7655 | 7723 | ** The "iScanStatusOp" parameter determines which status information to return. |
| 7656 | 7724 | ** The "iScanStatusOp" must be one of the [scanstatus options] or the behavior |
| 7657 | 7725 | ** of this interface is undefined. |
| 7658 | 7726 | ** ^The requested measurement is written into a variable pointed to by |
| | @@ -7666,13 +7734,10 @@ |
| 7666 | 7734 | ** ^Statistics might not be available for all loops in all statements. ^In cases |
| 7667 | 7735 | ** where there exist loops with no available statistics, this function behaves |
| 7668 | 7736 | ** as if the loop did not exist - it returns non-zero and leave the variable |
| 7669 | 7737 | ** that pOut points to unchanged. |
| 7670 | 7738 | ** |
| 7671 | | -** This API is only available if the library is built with pre-processor |
| 7672 | | -** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined. |
| 7673 | | -** |
| 7674 | 7739 | ** See also: [sqlite3_stmt_scanstatus_reset()] |
| 7675 | 7740 | */ |
| 7676 | 7741 | SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_stmt_scanstatus( |
| 7677 | 7742 | sqlite3_stmt *pStmt, /* Prepared statement for which info desired */ |
| 7678 | 7743 | int idx, /* Index of loop to report on */ |
| | @@ -9100,11 +9165,11 @@ |
| 9100 | 9165 | #define _BTREE_H_ |
| 9101 | 9166 | |
| 9102 | 9167 | /* TODO: This definition is just included so other modules compile. It |
| 9103 | 9168 | ** needs to be revisited. |
| 9104 | 9169 | */ |
| 9105 | | -#define SQLITE_N_BTREE_META 10 |
| 9170 | +#define SQLITE_N_BTREE_META 16 |
| 9106 | 9171 | |
| 9107 | 9172 | /* |
| 9108 | 9173 | ** If defined as non-zero, auto-vacuum is enabled by default. Otherwise |
| 9109 | 9174 | ** it must be turned on for each database using "PRAGMA auto_vacuum = 1". |
| 9110 | 9175 | */ |
| | @@ -9215,10 +9280,15 @@ |
| 9215 | 9280 | ** offset = 36 + (idx * 4) |
| 9216 | 9281 | ** |
| 9217 | 9282 | ** For example, the free-page-count field is located at byte offset 36 of |
| 9218 | 9283 | ** the database file header. The incr-vacuum-flag field is located at |
| 9219 | 9284 | ** byte offset 64 (== 36+4*7). |
| 9285 | +** |
| 9286 | +** The BTREE_DATA_VERSION value is not really a value stored in the header. |
| 9287 | +** It is a read-only number computed by the pager. But we merge it with |
| 9288 | +** the header value access routines since its access pattern is the same. |
| 9289 | +** Call it a "virtual meta value". |
| 9220 | 9290 | */ |
| 9221 | 9291 | #define BTREE_FREE_PAGE_COUNT 0 |
| 9222 | 9292 | #define BTREE_SCHEMA_VERSION 1 |
| 9223 | 9293 | #define BTREE_FILE_FORMAT 2 |
| 9224 | 9294 | #define BTREE_DEFAULT_CACHE_SIZE 3 |
| | @@ -9225,10 +9295,11 @@ |
| 9225 | 9295 | #define BTREE_LARGEST_ROOT_PAGE 4 |
| 9226 | 9296 | #define BTREE_TEXT_ENCODING 5 |
| 9227 | 9297 | #define BTREE_USER_VERSION 6 |
| 9228 | 9298 | #define BTREE_INCR_VACUUM 7 |
| 9229 | 9299 | #define BTREE_APPLICATION_ID 8 |
| 9300 | +#define BTREE_DATA_VERSION 15 /* A virtual meta-value */ |
| 9230 | 9301 | |
| 9231 | 9302 | /* |
| 9232 | 9303 | ** Values that may be OR'd together to form the second argument of an |
| 9233 | 9304 | ** sqlite3BtreeCursorHints() call. |
| 9234 | 9305 | */ |
| | @@ -10006,10 +10077,11 @@ |
| 10006 | 10077 | SQLITE_PRIVATE int sqlite3PagerWalFramesize(Pager *pPager); |
| 10007 | 10078 | #endif |
| 10008 | 10079 | |
| 10009 | 10080 | /* Functions used to query pager state and configuration. */ |
| 10010 | 10081 | SQLITE_PRIVATE u8 sqlite3PagerIsreadonly(Pager*); |
| 10082 | +SQLITE_PRIVATE u32 sqlite3PagerDataVersion(Pager*); |
| 10011 | 10083 | SQLITE_PRIVATE int sqlite3PagerRefcount(Pager*); |
| 10012 | 10084 | SQLITE_PRIVATE int sqlite3PagerMemUsed(Pager*); |
| 10013 | 10085 | SQLITE_PRIVATE const char *sqlite3PagerFilename(Pager*, int); |
| 10014 | 10086 | SQLITE_PRIVATE const sqlite3_vfs *sqlite3PagerVfs(Pager*); |
| 10015 | 10087 | SQLITE_PRIVATE sqlite3_file *sqlite3PagerFile(Pager*); |
| | @@ -10747,10 +10819,11 @@ |
| 10747 | 10819 | i64 szMmap; /* Default mmap_size setting */ |
| 10748 | 10820 | unsigned int openFlags; /* Flags passed to sqlite3_vfs.xOpen() */ |
| 10749 | 10821 | int errCode; /* Most recent error code (SQLITE_*) */ |
| 10750 | 10822 | int errMask; /* & result codes with this before returning */ |
| 10751 | 10823 | u16 dbOptFlags; /* Flags to enable/disable optimizations */ |
| 10824 | + u8 enc; /* Text encoding */ |
| 10752 | 10825 | u8 autoCommit; /* The auto-commit flag. */ |
| 10753 | 10826 | u8 temp_store; /* 1: file 2: memory 0: default */ |
| 10754 | 10827 | u8 mallocFailed; /* True if we have seen a malloc failure */ |
| 10755 | 10828 | u8 dfltLockMode; /* Default locking-mode for attached dbs */ |
| 10756 | 10829 | signed char nextAutovac; /* Autovac setting after VACUUM if >=0 */ |
| | @@ -10848,11 +10921,12 @@ |
| 10848 | 10921 | }; |
| 10849 | 10922 | |
| 10850 | 10923 | /* |
| 10851 | 10924 | ** A macro to discover the encoding of a database. |
| 10852 | 10925 | */ |
| 10853 | | -#define ENC(db) ((db)->aDb[0].pSchema->enc) |
| 10926 | +#define SCHEMA_ENC(db) ((db)->aDb[0].pSchema->enc) |
| 10927 | +#define ENC(db) ((db)->enc) |
| 10854 | 10928 | |
| 10855 | 10929 | /* |
| 10856 | 10930 | ** Possible values for the sqlite3.flags. |
| 10857 | 10931 | */ |
| 10858 | 10932 | #define SQLITE_VdbeTrace 0x00000001 /* True to trace VDBE execution */ |
| | @@ -11472,11 +11546,10 @@ |
| 11472 | 11546 | Index *pNext; /* The next index associated with the same table */ |
| 11473 | 11547 | Schema *pSchema; /* Schema containing this index */ |
| 11474 | 11548 | u8 *aSortOrder; /* for each column: True==DESC, False==ASC */ |
| 11475 | 11549 | char **azColl; /* Array of collation sequence names for index */ |
| 11476 | 11550 | Expr *pPartIdxWhere; /* WHERE clause for partial indices */ |
| 11477 | | - KeyInfo *pKeyInfo; /* A KeyInfo object suitable for this index */ |
| 11478 | 11551 | int tnum; /* DB Page containing root of this index */ |
| 11479 | 11552 | LogEst szIdxRow; /* Estimated average row size in bytes */ |
| 11480 | 11553 | u16 nKeyCol; /* Number of columns forming the key */ |
| 11481 | 11554 | u16 nColumn; /* Number of columns stored in the index */ |
| 11482 | 11555 | u8 onError; /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */ |
| | @@ -12036,11 +12109,11 @@ |
| 12036 | 12109 | #define SF_UsesEphemeral 0x0008 /* Uses the OpenEphemeral opcode */ |
| 12037 | 12110 | #define SF_Expanded 0x0010 /* sqlite3SelectExpand() called on this */ |
| 12038 | 12111 | #define SF_HasTypeInfo 0x0020 /* FROM subqueries have Table metadata */ |
| 12039 | 12112 | #define SF_Compound 0x0040 /* Part of a compound query */ |
| 12040 | 12113 | #define SF_Values 0x0080 /* Synthesized from VALUES clause */ |
| 12041 | | - /* 0x0100 NOT USED */ |
| 12114 | +#define SF_AllValues 0x0100 /* All terms of compound are VALUES */ |
| 12042 | 12115 | #define SF_NestedFrom 0x0200 /* Part of a parenthesized FROM clause */ |
| 12043 | 12116 | #define SF_MaybeConvert 0x0400 /* Need convertCompoundSelectToSubquery() */ |
| 12044 | 12117 | #define SF_Recursive 0x0800 /* The recursive part of a recursive CTE */ |
| 12045 | 12118 | #define SF_MinMaxAgg 0x1000 /* Aggregate containing min() or max() */ |
| 12046 | 12119 | |
| | @@ -12526,10 +12599,11 @@ |
| 12526 | 12599 | void *pPage; /* Page cache memory */ |
| 12527 | 12600 | int szPage; /* Size of each page in pPage[] */ |
| 12528 | 12601 | int nPage; /* Number of pages in pPage[] */ |
| 12529 | 12602 | int mxParserStack; /* maximum depth of the parser stack */ |
| 12530 | 12603 | int sharedCacheEnabled; /* true if shared-cache mode enabled */ |
| 12604 | + u32 szPma; /* Maximum Sorter PMA size */ |
| 12531 | 12605 | /* The above might be initialized to non-zero. The following need to always |
| 12532 | 12606 | ** initially be zero, however. */ |
| 12533 | 12607 | int isInit; /* True after initialization has finished */ |
| 12534 | 12608 | int inProgress; /* True while initialization in progress */ |
| 12535 | 12609 | int isMutexInit; /* True after mutexes are initialized */ |
| | @@ -12663,11 +12737,11 @@ |
| 12663 | 12737 | ** FTS4 is really an extension for FTS3. It is enabled using the |
| 12664 | 12738 | ** SQLITE_ENABLE_FTS3 macro. But to avoid confusion we also call |
| 12665 | 12739 | ** the SQLITE_ENABLE_FTS4 macro to serve as an alias for SQLITE_ENABLE_FTS3. |
| 12666 | 12740 | */ |
| 12667 | 12741 | #if defined(SQLITE_ENABLE_FTS4) && !defined(SQLITE_ENABLE_FTS3) |
| 12668 | | -# define SQLITE_ENABLE_FTS3 |
| 12742 | +# define SQLITE_ENABLE_FTS3 1 |
| 12669 | 12743 | #endif |
| 12670 | 12744 | |
| 12671 | 12745 | /* |
| 12672 | 12746 | ** The ctype.h header is needed for non-ASCII systems. It is also |
| 12673 | 12747 | ** needed by FTS3 when FTS3 is included in the amalgamation. |
| | @@ -13448,11 +13522,11 @@ |
| 13448 | 13522 | ** print I/O tracing messages. |
| 13449 | 13523 | */ |
| 13450 | 13524 | #ifdef SQLITE_ENABLE_IOTRACE |
| 13451 | 13525 | # define IOTRACE(A) if( sqlite3IoTrace ){ sqlite3IoTrace A; } |
| 13452 | 13526 | SQLITE_PRIVATE void sqlite3VdbeIOTraceSql(Vdbe*); |
| 13453 | | -SQLITE_PRIVATE void (*sqlite3IoTrace)(const char*,...); |
| 13527 | +void (*sqlite3IoTrace)(const char*,...); |
| 13454 | 13528 | #else |
| 13455 | 13529 | # define IOTRACE(A) |
| 13456 | 13530 | # define sqlite3VdbeIOTraceSql(X) |
| 13457 | 13531 | #endif |
| 13458 | 13532 | |
| | @@ -13661,10 +13735,17 @@ |
| 13661 | 13735 | */ |
| 13662 | 13736 | #ifndef SQLITE_ALLOW_COVERING_INDEX_SCAN |
| 13663 | 13737 | # define SQLITE_ALLOW_COVERING_INDEX_SCAN 1 |
| 13664 | 13738 | #endif |
| 13665 | 13739 | |
| 13740 | +/* The minimum PMA size is set to this value multiplied by the database |
| 13741 | +** page size in bytes. |
| 13742 | +*/ |
| 13743 | +#ifndef SQLITE_SORTER_PMASZ |
| 13744 | +# define SQLITE_SORTER_PMASZ 250 |
| 13745 | +#endif |
| 13746 | + |
| 13666 | 13747 | /* |
| 13667 | 13748 | ** The following singleton contains the global configuration for |
| 13668 | 13749 | ** the SQLite library. |
| 13669 | 13750 | */ |
| 13670 | 13751 | SQLITE_PRIVATE SQLITE_WSD struct Sqlite3Config sqlite3Config = { |
| | @@ -13691,10 +13772,11 @@ |
| 13691 | 13772 | (void*)0, /* pPage */ |
| 13692 | 13773 | 0, /* szPage */ |
| 13693 | 13774 | 0, /* nPage */ |
| 13694 | 13775 | 0, /* mxParserStack */ |
| 13695 | 13776 | 0, /* sharedCacheEnabled */ |
| 13777 | + SQLITE_SORTER_PMASZ, /* szPma */ |
| 13696 | 13778 | /* All the rest should always be initialized to zero */ |
| 13697 | 13779 | 0, /* isInit */ |
| 13698 | 13780 | 0, /* inProgress */ |
| 13699 | 13781 | 0, /* isMutexInit */ |
| 13700 | 13782 | 0, /* isMallocInit */ |
| | @@ -13797,355 +13879,355 @@ |
| 13797 | 13879 | /* These macros are provided to "stringify" the value of the define |
| 13798 | 13880 | ** for those options in which the value is meaningful. */ |
| 13799 | 13881 | #define CTIMEOPT_VAL_(opt) #opt |
| 13800 | 13882 | #define CTIMEOPT_VAL(opt) CTIMEOPT_VAL_(opt) |
| 13801 | 13883 | |
| 13802 | | -#ifdef SQLITE_32BIT_ROWID |
| 13884 | +#if SQLITE_32BIT_ROWID |
| 13803 | 13885 | "32BIT_ROWID", |
| 13804 | 13886 | #endif |
| 13805 | | -#ifdef SQLITE_4_BYTE_ALIGNED_MALLOC |
| 13887 | +#if SQLITE_4_BYTE_ALIGNED_MALLOC |
| 13806 | 13888 | "4_BYTE_ALIGNED_MALLOC", |
| 13807 | 13889 | #endif |
| 13808 | | -#ifdef SQLITE_CASE_SENSITIVE_LIKE |
| 13890 | +#if SQLITE_CASE_SENSITIVE_LIKE |
| 13809 | 13891 | "CASE_SENSITIVE_LIKE", |
| 13810 | 13892 | #endif |
| 13811 | | -#ifdef SQLITE_CHECK_PAGES |
| 13893 | +#if SQLITE_CHECK_PAGES |
| 13812 | 13894 | "CHECK_PAGES", |
| 13813 | 13895 | #endif |
| 13814 | | -#ifdef SQLITE_COVERAGE_TEST |
| 13896 | +#if SQLITE_COVERAGE_TEST |
| 13815 | 13897 | "COVERAGE_TEST", |
| 13816 | 13898 | #endif |
| 13817 | | -#ifdef SQLITE_DEBUG |
| 13899 | +#if SQLITE_DEBUG |
| 13818 | 13900 | "DEBUG", |
| 13819 | 13901 | #endif |
| 13820 | | -#ifdef SQLITE_DEFAULT_LOCKING_MODE |
| 13902 | +#if SQLITE_DEFAULT_LOCKING_MODE |
| 13821 | 13903 | "DEFAULT_LOCKING_MODE=" CTIMEOPT_VAL(SQLITE_DEFAULT_LOCKING_MODE), |
| 13822 | 13904 | #endif |
| 13823 | 13905 | #if defined(SQLITE_DEFAULT_MMAP_SIZE) && !defined(SQLITE_DEFAULT_MMAP_SIZE_xc) |
| 13824 | 13906 | "DEFAULT_MMAP_SIZE=" CTIMEOPT_VAL(SQLITE_DEFAULT_MMAP_SIZE), |
| 13825 | 13907 | #endif |
| 13826 | | -#ifdef SQLITE_DISABLE_DIRSYNC |
| 13908 | +#if SQLITE_DISABLE_DIRSYNC |
| 13827 | 13909 | "DISABLE_DIRSYNC", |
| 13828 | 13910 | #endif |
| 13829 | | -#ifdef SQLITE_DISABLE_LFS |
| 13911 | +#if SQLITE_DISABLE_LFS |
| 13830 | 13912 | "DISABLE_LFS", |
| 13831 | 13913 | #endif |
| 13832 | | -#ifdef SQLITE_ENABLE_API_ARMOR |
| 13914 | +#if SQLITE_ENABLE_API_ARMOR |
| 13833 | 13915 | "ENABLE_API_ARMOR", |
| 13834 | 13916 | #endif |
| 13835 | | -#ifdef SQLITE_ENABLE_ATOMIC_WRITE |
| 13917 | +#if SQLITE_ENABLE_ATOMIC_WRITE |
| 13836 | 13918 | "ENABLE_ATOMIC_WRITE", |
| 13837 | 13919 | #endif |
| 13838 | | -#ifdef SQLITE_ENABLE_CEROD |
| 13920 | +#if SQLITE_ENABLE_CEROD |
| 13839 | 13921 | "ENABLE_CEROD", |
| 13840 | 13922 | #endif |
| 13841 | | -#ifdef SQLITE_ENABLE_COLUMN_METADATA |
| 13923 | +#if SQLITE_ENABLE_COLUMN_METADATA |
| 13842 | 13924 | "ENABLE_COLUMN_METADATA", |
| 13843 | 13925 | #endif |
| 13844 | | -#ifdef SQLITE_ENABLE_EXPENSIVE_ASSERT |
| 13926 | +#if SQLITE_ENABLE_EXPENSIVE_ASSERT |
| 13845 | 13927 | "ENABLE_EXPENSIVE_ASSERT", |
| 13846 | 13928 | #endif |
| 13847 | | -#ifdef SQLITE_ENABLE_FTS1 |
| 13929 | +#if SQLITE_ENABLE_FTS1 |
| 13848 | 13930 | "ENABLE_FTS1", |
| 13849 | 13931 | #endif |
| 13850 | | -#ifdef SQLITE_ENABLE_FTS2 |
| 13932 | +#if SQLITE_ENABLE_FTS2 |
| 13851 | 13933 | "ENABLE_FTS2", |
| 13852 | 13934 | #endif |
| 13853 | | -#ifdef SQLITE_ENABLE_FTS3 |
| 13935 | +#if SQLITE_ENABLE_FTS3 |
| 13854 | 13936 | "ENABLE_FTS3", |
| 13855 | 13937 | #endif |
| 13856 | | -#ifdef SQLITE_ENABLE_FTS3_PARENTHESIS |
| 13938 | +#if SQLITE_ENABLE_FTS3_PARENTHESIS |
| 13857 | 13939 | "ENABLE_FTS3_PARENTHESIS", |
| 13858 | 13940 | #endif |
| 13859 | | -#ifdef SQLITE_ENABLE_FTS4 |
| 13941 | +#if SQLITE_ENABLE_FTS4 |
| 13860 | 13942 | "ENABLE_FTS4", |
| 13861 | 13943 | #endif |
| 13862 | | -#ifdef SQLITE_ENABLE_ICU |
| 13944 | +#if SQLITE_ENABLE_ICU |
| 13863 | 13945 | "ENABLE_ICU", |
| 13864 | 13946 | #endif |
| 13865 | | -#ifdef SQLITE_ENABLE_IOTRACE |
| 13947 | +#if SQLITE_ENABLE_IOTRACE |
| 13866 | 13948 | "ENABLE_IOTRACE", |
| 13867 | 13949 | #endif |
| 13868 | | -#ifdef SQLITE_ENABLE_LOAD_EXTENSION |
| 13950 | +#if SQLITE_ENABLE_LOAD_EXTENSION |
| 13869 | 13951 | "ENABLE_LOAD_EXTENSION", |
| 13870 | 13952 | #endif |
| 13871 | | -#ifdef SQLITE_ENABLE_LOCKING_STYLE |
| 13953 | +#if SQLITE_ENABLE_LOCKING_STYLE |
| 13872 | 13954 | "ENABLE_LOCKING_STYLE=" CTIMEOPT_VAL(SQLITE_ENABLE_LOCKING_STYLE), |
| 13873 | 13955 | #endif |
| 13874 | | -#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT |
| 13956 | +#if SQLITE_ENABLE_MEMORY_MANAGEMENT |
| 13875 | 13957 | "ENABLE_MEMORY_MANAGEMENT", |
| 13876 | 13958 | #endif |
| 13877 | | -#ifdef SQLITE_ENABLE_MEMSYS3 |
| 13959 | +#if SQLITE_ENABLE_MEMSYS3 |
| 13878 | 13960 | "ENABLE_MEMSYS3", |
| 13879 | 13961 | #endif |
| 13880 | | -#ifdef SQLITE_ENABLE_MEMSYS5 |
| 13962 | +#if SQLITE_ENABLE_MEMSYS5 |
| 13881 | 13963 | "ENABLE_MEMSYS5", |
| 13882 | 13964 | #endif |
| 13883 | | -#ifdef SQLITE_ENABLE_OVERSIZE_CELL_CHECK |
| 13965 | +#if SQLITE_ENABLE_OVERSIZE_CELL_CHECK |
| 13884 | 13966 | "ENABLE_OVERSIZE_CELL_CHECK", |
| 13885 | 13967 | #endif |
| 13886 | | -#ifdef SQLITE_ENABLE_RTREE |
| 13968 | +#if SQLITE_ENABLE_RTREE |
| 13887 | 13969 | "ENABLE_RTREE", |
| 13888 | 13970 | #endif |
| 13889 | 13971 | #if defined(SQLITE_ENABLE_STAT4) |
| 13890 | 13972 | "ENABLE_STAT4", |
| 13891 | 13973 | #elif defined(SQLITE_ENABLE_STAT3) |
| 13892 | 13974 | "ENABLE_STAT3", |
| 13893 | 13975 | #endif |
| 13894 | | -#ifdef SQLITE_ENABLE_UNLOCK_NOTIFY |
| 13976 | +#if SQLITE_ENABLE_UNLOCK_NOTIFY |
| 13895 | 13977 | "ENABLE_UNLOCK_NOTIFY", |
| 13896 | 13978 | #endif |
| 13897 | | -#ifdef SQLITE_ENABLE_UPDATE_DELETE_LIMIT |
| 13979 | +#if SQLITE_ENABLE_UPDATE_DELETE_LIMIT |
| 13898 | 13980 | "ENABLE_UPDATE_DELETE_LIMIT", |
| 13899 | 13981 | #endif |
| 13900 | | -#ifdef SQLITE_HAS_CODEC |
| 13982 | +#if SQLITE_HAS_CODEC |
| 13901 | 13983 | "HAS_CODEC", |
| 13902 | 13984 | #endif |
| 13903 | | -#ifdef SQLITE_HAVE_ISNAN |
| 13985 | +#if HAVE_ISNAN || SQLITE_HAVE_ISNAN |
| 13904 | 13986 | "HAVE_ISNAN", |
| 13905 | 13987 | #endif |
| 13906 | | -#ifdef SQLITE_HOMEGROWN_RECURSIVE_MUTEX |
| 13988 | +#if SQLITE_HOMEGROWN_RECURSIVE_MUTEX |
| 13907 | 13989 | "HOMEGROWN_RECURSIVE_MUTEX", |
| 13908 | 13990 | #endif |
| 13909 | | -#ifdef SQLITE_IGNORE_AFP_LOCK_ERRORS |
| 13991 | +#if SQLITE_IGNORE_AFP_LOCK_ERRORS |
| 13910 | 13992 | "IGNORE_AFP_LOCK_ERRORS", |
| 13911 | 13993 | #endif |
| 13912 | | -#ifdef SQLITE_IGNORE_FLOCK_LOCK_ERRORS |
| 13994 | +#if SQLITE_IGNORE_FLOCK_LOCK_ERRORS |
| 13913 | 13995 | "IGNORE_FLOCK_LOCK_ERRORS", |
| 13914 | 13996 | #endif |
| 13915 | 13997 | #ifdef SQLITE_INT64_TYPE |
| 13916 | 13998 | "INT64_TYPE", |
| 13917 | 13999 | #endif |
| 13918 | | -#ifdef SQLITE_LOCK_TRACE |
| 14000 | +#if SQLITE_LOCK_TRACE |
| 13919 | 14001 | "LOCK_TRACE", |
| 13920 | 14002 | #endif |
| 13921 | 14003 | #if defined(SQLITE_MAX_MMAP_SIZE) && !defined(SQLITE_MAX_MMAP_SIZE_xc) |
| 13922 | 14004 | "MAX_MMAP_SIZE=" CTIMEOPT_VAL(SQLITE_MAX_MMAP_SIZE), |
| 13923 | 14005 | #endif |
| 13924 | 14006 | #ifdef SQLITE_MAX_SCHEMA_RETRY |
| 13925 | 14007 | "MAX_SCHEMA_RETRY=" CTIMEOPT_VAL(SQLITE_MAX_SCHEMA_RETRY), |
| 13926 | 14008 | #endif |
| 13927 | | -#ifdef SQLITE_MEMDEBUG |
| 14009 | +#if SQLITE_MEMDEBUG |
| 13928 | 14010 | "MEMDEBUG", |
| 13929 | 14011 | #endif |
| 13930 | | -#ifdef SQLITE_MIXED_ENDIAN_64BIT_FLOAT |
| 14012 | +#if SQLITE_MIXED_ENDIAN_64BIT_FLOAT |
| 13931 | 14013 | "MIXED_ENDIAN_64BIT_FLOAT", |
| 13932 | 14014 | #endif |
| 13933 | | -#ifdef SQLITE_NO_SYNC |
| 14015 | +#if SQLITE_NO_SYNC |
| 13934 | 14016 | "NO_SYNC", |
| 13935 | 14017 | #endif |
| 13936 | | -#ifdef SQLITE_OMIT_ALTERTABLE |
| 14018 | +#if SQLITE_OMIT_ALTERTABLE |
| 13937 | 14019 | "OMIT_ALTERTABLE", |
| 13938 | 14020 | #endif |
| 13939 | | -#ifdef SQLITE_OMIT_ANALYZE |
| 14021 | +#if SQLITE_OMIT_ANALYZE |
| 13940 | 14022 | "OMIT_ANALYZE", |
| 13941 | 14023 | #endif |
| 13942 | | -#ifdef SQLITE_OMIT_ATTACH |
| 14024 | +#if SQLITE_OMIT_ATTACH |
| 13943 | 14025 | "OMIT_ATTACH", |
| 13944 | 14026 | #endif |
| 13945 | | -#ifdef SQLITE_OMIT_AUTHORIZATION |
| 14027 | +#if SQLITE_OMIT_AUTHORIZATION |
| 13946 | 14028 | "OMIT_AUTHORIZATION", |
| 13947 | 14029 | #endif |
| 13948 | | -#ifdef SQLITE_OMIT_AUTOINCREMENT |
| 14030 | +#if SQLITE_OMIT_AUTOINCREMENT |
| 13949 | 14031 | "OMIT_AUTOINCREMENT", |
| 13950 | 14032 | #endif |
| 13951 | | -#ifdef SQLITE_OMIT_AUTOINIT |
| 14033 | +#if SQLITE_OMIT_AUTOINIT |
| 13952 | 14034 | "OMIT_AUTOINIT", |
| 13953 | 14035 | #endif |
| 13954 | | -#ifdef SQLITE_OMIT_AUTOMATIC_INDEX |
| 14036 | +#if SQLITE_OMIT_AUTOMATIC_INDEX |
| 13955 | 14037 | "OMIT_AUTOMATIC_INDEX", |
| 13956 | 14038 | #endif |
| 13957 | | -#ifdef SQLITE_OMIT_AUTORESET |
| 14039 | +#if SQLITE_OMIT_AUTORESET |
| 13958 | 14040 | "OMIT_AUTORESET", |
| 13959 | 14041 | #endif |
| 13960 | | -#ifdef SQLITE_OMIT_AUTOVACUUM |
| 14042 | +#if SQLITE_OMIT_AUTOVACUUM |
| 13961 | 14043 | "OMIT_AUTOVACUUM", |
| 13962 | 14044 | #endif |
| 13963 | | -#ifdef SQLITE_OMIT_BETWEEN_OPTIMIZATION |
| 14045 | +#if SQLITE_OMIT_BETWEEN_OPTIMIZATION |
| 13964 | 14046 | "OMIT_BETWEEN_OPTIMIZATION", |
| 13965 | 14047 | #endif |
| 13966 | | -#ifdef SQLITE_OMIT_BLOB_LITERAL |
| 14048 | +#if SQLITE_OMIT_BLOB_LITERAL |
| 13967 | 14049 | "OMIT_BLOB_LITERAL", |
| 13968 | 14050 | #endif |
| 13969 | | -#ifdef SQLITE_OMIT_BTREECOUNT |
| 14051 | +#if SQLITE_OMIT_BTREECOUNT |
| 13970 | 14052 | "OMIT_BTREECOUNT", |
| 13971 | 14053 | #endif |
| 13972 | | -#ifdef SQLITE_OMIT_BUILTIN_TEST |
| 14054 | +#if SQLITE_OMIT_BUILTIN_TEST |
| 13973 | 14055 | "OMIT_BUILTIN_TEST", |
| 13974 | 14056 | #endif |
| 13975 | | -#ifdef SQLITE_OMIT_CAST |
| 14057 | +#if SQLITE_OMIT_CAST |
| 13976 | 14058 | "OMIT_CAST", |
| 13977 | 14059 | #endif |
| 13978 | | -#ifdef SQLITE_OMIT_CHECK |
| 14060 | +#if SQLITE_OMIT_CHECK |
| 13979 | 14061 | "OMIT_CHECK", |
| 13980 | 14062 | #endif |
| 13981 | | -#ifdef SQLITE_OMIT_COMPLETE |
| 14063 | +#if SQLITE_OMIT_COMPLETE |
| 13982 | 14064 | "OMIT_COMPLETE", |
| 13983 | 14065 | #endif |
| 13984 | | -#ifdef SQLITE_OMIT_COMPOUND_SELECT |
| 14066 | +#if SQLITE_OMIT_COMPOUND_SELECT |
| 13985 | 14067 | "OMIT_COMPOUND_SELECT", |
| 13986 | 14068 | #endif |
| 13987 | | -#ifdef SQLITE_OMIT_CTE |
| 14069 | +#if SQLITE_OMIT_CTE |
| 13988 | 14070 | "OMIT_CTE", |
| 13989 | 14071 | #endif |
| 13990 | | -#ifdef SQLITE_OMIT_DATETIME_FUNCS |
| 14072 | +#if SQLITE_OMIT_DATETIME_FUNCS |
| 13991 | 14073 | "OMIT_DATETIME_FUNCS", |
| 13992 | 14074 | #endif |
| 13993 | | -#ifdef SQLITE_OMIT_DECLTYPE |
| 14075 | +#if SQLITE_OMIT_DECLTYPE |
| 13994 | 14076 | "OMIT_DECLTYPE", |
| 13995 | 14077 | #endif |
| 13996 | | -#ifdef SQLITE_OMIT_DEPRECATED |
| 14078 | +#if SQLITE_OMIT_DEPRECATED |
| 13997 | 14079 | "OMIT_DEPRECATED", |
| 13998 | 14080 | #endif |
| 13999 | | -#ifdef SQLITE_OMIT_DISKIO |
| 14081 | +#if SQLITE_OMIT_DISKIO |
| 14000 | 14082 | "OMIT_DISKIO", |
| 14001 | 14083 | #endif |
| 14002 | | -#ifdef SQLITE_OMIT_EXPLAIN |
| 14084 | +#if SQLITE_OMIT_EXPLAIN |
| 14003 | 14085 | "OMIT_EXPLAIN", |
| 14004 | 14086 | #endif |
| 14005 | | -#ifdef SQLITE_OMIT_FLAG_PRAGMAS |
| 14087 | +#if SQLITE_OMIT_FLAG_PRAGMAS |
| 14006 | 14088 | "OMIT_FLAG_PRAGMAS", |
| 14007 | 14089 | #endif |
| 14008 | | -#ifdef SQLITE_OMIT_FLOATING_POINT |
| 14090 | +#if SQLITE_OMIT_FLOATING_POINT |
| 14009 | 14091 | "OMIT_FLOATING_POINT", |
| 14010 | 14092 | #endif |
| 14011 | | -#ifdef SQLITE_OMIT_FOREIGN_KEY |
| 14093 | +#if SQLITE_OMIT_FOREIGN_KEY |
| 14012 | 14094 | "OMIT_FOREIGN_KEY", |
| 14013 | 14095 | #endif |
| 14014 | | -#ifdef SQLITE_OMIT_GET_TABLE |
| 14096 | +#if SQLITE_OMIT_GET_TABLE |
| 14015 | 14097 | "OMIT_GET_TABLE", |
| 14016 | 14098 | #endif |
| 14017 | | -#ifdef SQLITE_OMIT_INCRBLOB |
| 14099 | +#if SQLITE_OMIT_INCRBLOB |
| 14018 | 14100 | "OMIT_INCRBLOB", |
| 14019 | 14101 | #endif |
| 14020 | | -#ifdef SQLITE_OMIT_INTEGRITY_CHECK |
| 14102 | +#if SQLITE_OMIT_INTEGRITY_CHECK |
| 14021 | 14103 | "OMIT_INTEGRITY_CHECK", |
| 14022 | 14104 | #endif |
| 14023 | | -#ifdef SQLITE_OMIT_LIKE_OPTIMIZATION |
| 14105 | +#if SQLITE_OMIT_LIKE_OPTIMIZATION |
| 14024 | 14106 | "OMIT_LIKE_OPTIMIZATION", |
| 14025 | 14107 | #endif |
| 14026 | | -#ifdef SQLITE_OMIT_LOAD_EXTENSION |
| 14108 | +#if SQLITE_OMIT_LOAD_EXTENSION |
| 14027 | 14109 | "OMIT_LOAD_EXTENSION", |
| 14028 | 14110 | #endif |
| 14029 | | -#ifdef SQLITE_OMIT_LOCALTIME |
| 14111 | +#if SQLITE_OMIT_LOCALTIME |
| 14030 | 14112 | "OMIT_LOCALTIME", |
| 14031 | 14113 | #endif |
| 14032 | | -#ifdef SQLITE_OMIT_LOOKASIDE |
| 14114 | +#if SQLITE_OMIT_LOOKASIDE |
| 14033 | 14115 | "OMIT_LOOKASIDE", |
| 14034 | 14116 | #endif |
| 14035 | | -#ifdef SQLITE_OMIT_MEMORYDB |
| 14117 | +#if SQLITE_OMIT_MEMORYDB |
| 14036 | 14118 | "OMIT_MEMORYDB", |
| 14037 | 14119 | #endif |
| 14038 | | -#ifdef SQLITE_OMIT_OR_OPTIMIZATION |
| 14120 | +#if SQLITE_OMIT_OR_OPTIMIZATION |
| 14039 | 14121 | "OMIT_OR_OPTIMIZATION", |
| 14040 | 14122 | #endif |
| 14041 | | -#ifdef SQLITE_OMIT_PAGER_PRAGMAS |
| 14123 | +#if SQLITE_OMIT_PAGER_PRAGMAS |
| 14042 | 14124 | "OMIT_PAGER_PRAGMAS", |
| 14043 | 14125 | #endif |
| 14044 | | -#ifdef SQLITE_OMIT_PRAGMA |
| 14126 | +#if SQLITE_OMIT_PRAGMA |
| 14045 | 14127 | "OMIT_PRAGMA", |
| 14046 | 14128 | #endif |
| 14047 | | -#ifdef SQLITE_OMIT_PROGRESS_CALLBACK |
| 14129 | +#if SQLITE_OMIT_PROGRESS_CALLBACK |
| 14048 | 14130 | "OMIT_PROGRESS_CALLBACK", |
| 14049 | 14131 | #endif |
| 14050 | | -#ifdef SQLITE_OMIT_QUICKBALANCE |
| 14132 | +#if SQLITE_OMIT_QUICKBALANCE |
| 14051 | 14133 | "OMIT_QUICKBALANCE", |
| 14052 | 14134 | #endif |
| 14053 | | -#ifdef SQLITE_OMIT_REINDEX |
| 14135 | +#if SQLITE_OMIT_REINDEX |
| 14054 | 14136 | "OMIT_REINDEX", |
| 14055 | 14137 | #endif |
| 14056 | | -#ifdef SQLITE_OMIT_SCHEMA_PRAGMAS |
| 14138 | +#if SQLITE_OMIT_SCHEMA_PRAGMAS |
| 14057 | 14139 | "OMIT_SCHEMA_PRAGMAS", |
| 14058 | 14140 | #endif |
| 14059 | | -#ifdef SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS |
| 14141 | +#if SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS |
| 14060 | 14142 | "OMIT_SCHEMA_VERSION_PRAGMAS", |
| 14061 | 14143 | #endif |
| 14062 | | -#ifdef SQLITE_OMIT_SHARED_CACHE |
| 14144 | +#if SQLITE_OMIT_SHARED_CACHE |
| 14063 | 14145 | "OMIT_SHARED_CACHE", |
| 14064 | 14146 | #endif |
| 14065 | | -#ifdef SQLITE_OMIT_SUBQUERY |
| 14147 | +#if SQLITE_OMIT_SUBQUERY |
| 14066 | 14148 | "OMIT_SUBQUERY", |
| 14067 | 14149 | #endif |
| 14068 | | -#ifdef SQLITE_OMIT_TCL_VARIABLE |
| 14150 | +#if SQLITE_OMIT_TCL_VARIABLE |
| 14069 | 14151 | "OMIT_TCL_VARIABLE", |
| 14070 | 14152 | #endif |
| 14071 | | -#ifdef SQLITE_OMIT_TEMPDB |
| 14153 | +#if SQLITE_OMIT_TEMPDB |
| 14072 | 14154 | "OMIT_TEMPDB", |
| 14073 | 14155 | #endif |
| 14074 | | -#ifdef SQLITE_OMIT_TRACE |
| 14156 | +#if SQLITE_OMIT_TRACE |
| 14075 | 14157 | "OMIT_TRACE", |
| 14076 | 14158 | #endif |
| 14077 | | -#ifdef SQLITE_OMIT_TRIGGER |
| 14159 | +#if SQLITE_OMIT_TRIGGER |
| 14078 | 14160 | "OMIT_TRIGGER", |
| 14079 | 14161 | #endif |
| 14080 | | -#ifdef SQLITE_OMIT_TRUNCATE_OPTIMIZATION |
| 14162 | +#if SQLITE_OMIT_TRUNCATE_OPTIMIZATION |
| 14081 | 14163 | "OMIT_TRUNCATE_OPTIMIZATION", |
| 14082 | 14164 | #endif |
| 14083 | | -#ifdef SQLITE_OMIT_UTF16 |
| 14165 | +#if SQLITE_OMIT_UTF16 |
| 14084 | 14166 | "OMIT_UTF16", |
| 14085 | 14167 | #endif |
| 14086 | | -#ifdef SQLITE_OMIT_VACUUM |
| 14168 | +#if SQLITE_OMIT_VACUUM |
| 14087 | 14169 | "OMIT_VACUUM", |
| 14088 | 14170 | #endif |
| 14089 | | -#ifdef SQLITE_OMIT_VIEW |
| 14171 | +#if SQLITE_OMIT_VIEW |
| 14090 | 14172 | "OMIT_VIEW", |
| 14091 | 14173 | #endif |
| 14092 | | -#ifdef SQLITE_OMIT_VIRTUALTABLE |
| 14174 | +#if SQLITE_OMIT_VIRTUALTABLE |
| 14093 | 14175 | "OMIT_VIRTUALTABLE", |
| 14094 | 14176 | #endif |
| 14095 | | -#ifdef SQLITE_OMIT_WAL |
| 14177 | +#if SQLITE_OMIT_WAL |
| 14096 | 14178 | "OMIT_WAL", |
| 14097 | 14179 | #endif |
| 14098 | | -#ifdef SQLITE_OMIT_WSD |
| 14180 | +#if SQLITE_OMIT_WSD |
| 14099 | 14181 | "OMIT_WSD", |
| 14100 | 14182 | #endif |
| 14101 | | -#ifdef SQLITE_OMIT_XFER_OPT |
| 14183 | +#if SQLITE_OMIT_XFER_OPT |
| 14102 | 14184 | "OMIT_XFER_OPT", |
| 14103 | 14185 | #endif |
| 14104 | | -#ifdef SQLITE_PERFORMANCE_TRACE |
| 14186 | +#if SQLITE_PERFORMANCE_TRACE |
| 14105 | 14187 | "PERFORMANCE_TRACE", |
| 14106 | 14188 | #endif |
| 14107 | | -#ifdef SQLITE_PROXY_DEBUG |
| 14189 | +#if SQLITE_PROXY_DEBUG |
| 14108 | 14190 | "PROXY_DEBUG", |
| 14109 | 14191 | #endif |
| 14110 | | -#ifdef SQLITE_RTREE_INT_ONLY |
| 14192 | +#if SQLITE_RTREE_INT_ONLY |
| 14111 | 14193 | "RTREE_INT_ONLY", |
| 14112 | 14194 | #endif |
| 14113 | | -#ifdef SQLITE_SECURE_DELETE |
| 14195 | +#if SQLITE_SECURE_DELETE |
| 14114 | 14196 | "SECURE_DELETE", |
| 14115 | 14197 | #endif |
| 14116 | | -#ifdef SQLITE_SMALL_STACK |
| 14198 | +#if SQLITE_SMALL_STACK |
| 14117 | 14199 | "SMALL_STACK", |
| 14118 | 14200 | #endif |
| 14119 | | -#ifdef SQLITE_SOUNDEX |
| 14201 | +#if SQLITE_SOUNDEX |
| 14120 | 14202 | "SOUNDEX", |
| 14121 | 14203 | #endif |
| 14122 | | -#ifdef SQLITE_SYSTEM_MALLOC |
| 14204 | +#if SQLITE_SYSTEM_MALLOC |
| 14123 | 14205 | "SYSTEM_MALLOC", |
| 14124 | 14206 | #endif |
| 14125 | | -#ifdef SQLITE_TCL |
| 14207 | +#if SQLITE_TCL |
| 14126 | 14208 | "TCL", |
| 14127 | 14209 | #endif |
| 14128 | 14210 | #if defined(SQLITE_TEMP_STORE) && !defined(SQLITE_TEMP_STORE_xc) |
| 14129 | 14211 | "TEMP_STORE=" CTIMEOPT_VAL(SQLITE_TEMP_STORE), |
| 14130 | 14212 | #endif |
| 14131 | | -#ifdef SQLITE_TEST |
| 14213 | +#if SQLITE_TEST |
| 14132 | 14214 | "TEST", |
| 14133 | 14215 | #endif |
| 14134 | 14216 | #if defined(SQLITE_THREADSAFE) |
| 14135 | 14217 | "THREADSAFE=" CTIMEOPT_VAL(SQLITE_THREADSAFE), |
| 14136 | 14218 | #endif |
| 14137 | | -#ifdef SQLITE_USE_ALLOCA |
| 14219 | +#if SQLITE_USE_ALLOCA |
| 14138 | 14220 | "USE_ALLOCA", |
| 14139 | 14221 | #endif |
| 14140 | | -#ifdef SQLITE_USER_AUTHENTICATION |
| 14222 | +#if SQLITE_USER_AUTHENTICATION |
| 14141 | 14223 | "USER_AUTHENTICATION", |
| 14142 | 14224 | #endif |
| 14143 | | -#ifdef SQLITE_WIN32_MALLOC |
| 14225 | +#if SQLITE_WIN32_MALLOC |
| 14144 | 14226 | "WIN32_MALLOC", |
| 14145 | 14227 | #endif |
| 14146 | | -#ifdef SQLITE_ZERO_MALLOC |
| 14228 | +#if SQLITE_ZERO_MALLOC |
| 14147 | 14229 | "ZERO_MALLOC" |
| 14148 | 14230 | #endif |
| 14149 | 14231 | }; |
| 14150 | 14232 | |
| 14151 | 14233 | /* |
| | @@ -14156,11 +14238,11 @@ |
| 14156 | 14238 | ** is not required for a match. |
| 14157 | 14239 | */ |
| 14158 | 14240 | SQLITE_API int sqlite3_compileoption_used(const char *zOptName){ |
| 14159 | 14241 | int i, n; |
| 14160 | 14242 | |
| 14161 | | -#ifdef SQLITE_ENABLE_API_ARMOR |
| 14243 | +#if SQLITE_ENABLE_API_ARMOR |
| 14162 | 14244 | if( zOptName==0 ){ |
| 14163 | 14245 | (void)SQLITE_MISUSE_BKPT; |
| 14164 | 14246 | return 0; |
| 14165 | 14247 | } |
| 14166 | 14248 | #endif |
| | @@ -15384,12 +15466,13 @@ |
| 15384 | 15466 | ** |
| 15385 | 15467 | ** If the user has not indicated to use localtime_r() or localtime_s() |
| 15386 | 15468 | ** already, check for an MSVC build environment that provides |
| 15387 | 15469 | ** localtime_s(). |
| 15388 | 15470 | */ |
| 15389 | | -#if !defined(HAVE_LOCALTIME_R) && !defined(HAVE_LOCALTIME_S) && \ |
| 15390 | | - defined(_MSC_VER) && defined(_CRT_INSECURE_DEPRECATE) |
| 15471 | +#if !HAVE_LOCALTIME_R && !HAVE_LOCALTIME_S \ |
| 15472 | + && defined(_MSC_VER) && defined(_CRT_INSECURE_DEPRECATE) |
| 15473 | +#undef HAVE_LOCALTIME_S |
| 15391 | 15474 | #define HAVE_LOCALTIME_S 1 |
| 15392 | 15475 | #endif |
| 15393 | 15476 | |
| 15394 | 15477 | #ifndef SQLITE_OMIT_LOCALTIME |
| 15395 | 15478 | /* |
| | @@ -15405,12 +15488,11 @@ |
| 15405 | 15488 | ** library function localtime_r() is used to assist in the calculation of |
| 15406 | 15489 | ** local time. |
| 15407 | 15490 | */ |
| 15408 | 15491 | static int osLocaltime(time_t *t, struct tm *pTm){ |
| 15409 | 15492 | int rc; |
| 15410 | | -#if (!defined(HAVE_LOCALTIME_R) || !HAVE_LOCALTIME_R) \ |
| 15411 | | - && (!defined(HAVE_LOCALTIME_S) || !HAVE_LOCALTIME_S) |
| 15493 | +#if !HAVE_LOCALTIME_R && !HAVE_LOCALTIME_S |
| 15412 | 15494 | struct tm *pX; |
| 15413 | 15495 | #if SQLITE_THREADSAFE>0 |
| 15414 | 15496 | sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); |
| 15415 | 15497 | #endif |
| 15416 | 15498 | sqlite3_mutex_enter(mutex); |
| | @@ -15423,11 +15505,11 @@ |
| 15423 | 15505 | rc = pX==0; |
| 15424 | 15506 | #else |
| 15425 | 15507 | #ifndef SQLITE_OMIT_BUILTIN_TEST |
| 15426 | 15508 | if( sqlite3GlobalConfig.bLocaltimeFault ) return 1; |
| 15427 | 15509 | #endif |
| 15428 | | -#if defined(HAVE_LOCALTIME_R) && HAVE_LOCALTIME_R |
| 15510 | +#if HAVE_LOCALTIME_R |
| 15429 | 15511 | rc = localtime_r(t, pTm)==0; |
| 15430 | 15512 | #else |
| 15431 | 15513 | rc = localtime_s(pTm, t); |
| 15432 | 15514 | #endif /* HAVE_LOCALTIME_R */ |
| 15433 | 15515 | #endif /* HAVE_LOCALTIME_R || HAVE_LOCALTIME_S */ |
| | @@ -15867,12 +15949,14 @@ |
| 15867 | 15949 | DateTime x; |
| 15868 | 15950 | u64 n; |
| 15869 | 15951 | size_t i,j; |
| 15870 | 15952 | char *z; |
| 15871 | 15953 | sqlite3 *db; |
| 15872 | | - const char *zFmt = (const char*)sqlite3_value_text(argv[0]); |
| 15954 | + const char *zFmt; |
| 15873 | 15955 | char zBuf[100]; |
| 15956 | + if( argc==0 ) return; |
| 15957 | + zFmt = (const char*)sqlite3_value_text(argv[0]); |
| 15874 | 15958 | if( zFmt==0 || isDate(context, argc-1, argv+1, &x) ) return; |
| 15875 | 15959 | db = sqlite3_context_db_handle(context); |
| 15876 | 15960 | for(i=0, n=1; zFmt[i]; i++, n++){ |
| 15877 | 15961 | if( zFmt[i]=='%' ){ |
| 15878 | 15962 | switch( zFmt[i+1] ){ |
| | @@ -16062,11 +16146,11 @@ |
| 16062 | 16146 | UNUSED_PARAMETER(argv); |
| 16063 | 16147 | |
| 16064 | 16148 | iT = sqlite3StmtCurrentTime(context); |
| 16065 | 16149 | if( iT<=0 ) return; |
| 16066 | 16150 | t = iT/1000 - 10000*(sqlite3_int64)21086676; |
| 16067 | | -#ifdef HAVE_GMTIME_R |
| 16151 | +#if HAVE_GMTIME_R |
| 16068 | 16152 | pTm = gmtime_r(&t, &sNow); |
| 16069 | 16153 | #else |
| 16070 | 16154 | sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER)); |
| 16071 | 16155 | pTm = gmtime(&t); |
| 16072 | 16156 | if( pTm ) memcpy(&sNow, pTm, sizeof(sNow)); |
| | @@ -16736,13 +16820,13 @@ |
| 16736 | 16820 | |
| 16737 | 16821 | /* |
| 16738 | 16822 | ** The malloc.h header file is needed for malloc_usable_size() function |
| 16739 | 16823 | ** on some systems (e.g. Linux). |
| 16740 | 16824 | */ |
| 16741 | | -#if defined(HAVE_MALLOC_H) && defined(HAVE_MALLOC_USABLE_SIZE) |
| 16742 | | -# define SQLITE_USE_MALLOC_H |
| 16743 | | -# define SQLITE_USE_MALLOC_USABLE_SIZE |
| 16825 | +#if HAVE_MALLOC_H && HAVE_MALLOC_USABLE_SIZE |
| 16826 | +# define SQLITE_USE_MALLOC_H 1 |
| 16827 | +# define SQLITE_USE_MALLOC_USABLE_SIZE 1 |
| 16744 | 16828 | /* |
| 16745 | 16829 | ** The MSVCRT has malloc_usable_size(), but it is called _msize(). The |
| 16746 | 16830 | ** use of _msize() is automatic, but can be disabled by compiling with |
| 16747 | 16831 | ** -DSQLITE_WITHOUT_MSIZE. Using the _msize() function also requires |
| 16748 | 16832 | ** the malloc.h header file. |
| | @@ -19976,10 +20060,16 @@ |
| 19976 | 20060 | #endif |
| 19977 | 20061 | } |
| 19978 | 20062 | break; |
| 19979 | 20063 | } |
| 19980 | 20064 | default: { |
| 20065 | +#ifdef SQLITE_ENABLE_API_ARMOR |
| 20066 | + if( iType-2<0 || iType-2>=ArraySize(winMutex_staticMutexes) ){ |
| 20067 | + (void)SQLITE_MISUSE_BKPT; |
| 20068 | + return 0; |
| 20069 | + } |
| 20070 | +#endif |
| 19981 | 20071 | assert( iType-2 >= 0 ); |
| 19982 | 20072 | assert( iType-2 < ArraySize(winMutex_staticMutexes) ); |
| 19983 | 20073 | assert( winMutex_isInit==1 ); |
| 19984 | 20074 | p = &winMutex_staticMutexes[iType-2]; |
| 19985 | 20075 | #ifdef SQLITE_DEBUG |
| | @@ -20971,21 +21061,10 @@ |
| 20971 | 21061 | ** This file contains code for a set of "printf"-like routines. These |
| 20972 | 21062 | ** routines format strings much like the printf() from the standard C |
| 20973 | 21063 | ** library, though the implementation here has enhancements to support |
| 20974 | 21064 | ** SQLlite. |
| 20975 | 21065 | */ |
| 20976 | | - |
| 20977 | | -/* |
| 20978 | | -** If the strchrnul() library function is available, then set |
| 20979 | | -** HAVE_STRCHRNUL. If that routine is not available, this module |
| 20980 | | -** will supply its own. The built-in version is slower than |
| 20981 | | -** the glibc version so the glibc version is definitely preferred. |
| 20982 | | -*/ |
| 20983 | | -#if !defined(HAVE_STRCHRNUL) |
| 20984 | | -# define HAVE_STRCHRNUL 0 |
| 20985 | | -#endif |
| 20986 | | - |
| 20987 | 21066 | |
| 20988 | 21067 | /* |
| 20989 | 21068 | ** Conversion types fall into various categories as defined by the |
| 20990 | 21069 | ** following enumeration. |
| 20991 | 21070 | */ |
| | @@ -22280,10 +22359,12 @@ |
| 22280 | 22359 | ** single threaded systems. Nothing in SQLite requires multiple threads. |
| 22281 | 22360 | ** This interface exists so that applications that want to take advantage |
| 22282 | 22361 | ** of multiple cores can do so, while also allowing applications to stay |
| 22283 | 22362 | ** single-threaded if desired. |
| 22284 | 22363 | */ |
| 22364 | +#if SQLITE_OS_WIN |
| 22365 | +#endif |
| 22285 | 22366 | |
| 22286 | 22367 | #if SQLITE_MAX_WORKER_THREADS>0 |
| 22287 | 22368 | |
| 22288 | 22369 | /********************************* Unix Pthreads ****************************/ |
| 22289 | 22370 | #if SQLITE_OS_UNIX && defined(SQLITE_MUTEX_PTHREADS) && SQLITE_THREADSAFE>0 |
| | @@ -23066,11 +23147,11 @@ |
| 23066 | 23147 | ** This file contains functions for allocating memory, comparing |
| 23067 | 23148 | ** strings, and stuff like that. |
| 23068 | 23149 | ** |
| 23069 | 23150 | */ |
| 23070 | 23151 | /* #include <stdarg.h> */ |
| 23071 | | -#ifdef SQLITE_HAVE_ISNAN |
| 23152 | +#if HAVE_ISNAN || SQLITE_HAVE_ISNAN |
| 23072 | 23153 | # include <math.h> |
| 23073 | 23154 | #endif |
| 23074 | 23155 | |
| 23075 | 23156 | /* |
| 23076 | 23157 | ** Routine needed to support the testcase() macro. |
| | @@ -23107,11 +23188,11 @@ |
| 23107 | 23188 | ** Use the math library isnan() function if compiled with SQLITE_HAVE_ISNAN. |
| 23108 | 23189 | ** Otherwise, we have our own implementation that works on most systems. |
| 23109 | 23190 | */ |
| 23110 | 23191 | SQLITE_PRIVATE int sqlite3IsNaN(double x){ |
| 23111 | 23192 | int rc; /* The value return */ |
| 23112 | | -#if !defined(SQLITE_HAVE_ISNAN) |
| 23193 | +#if !SQLITE_HAVE_ISNAN && !HAVE_ISNAN |
| 23113 | 23194 | /* |
| 23114 | 23195 | ** Systems that support the isnan() library function should probably |
| 23115 | 23196 | ** make use of it by compiling with -DSQLITE_HAVE_ISNAN. But we have |
| 23116 | 23197 | ** found that many systems do not have a working isnan() function so |
| 23117 | 23198 | ** this implementation is provided as an alternative. |
| | @@ -23137,13 +23218,13 @@ |
| 23137 | 23218 | # error SQLite will not work correctly with the -ffast-math option of GCC. |
| 23138 | 23219 | #endif |
| 23139 | 23220 | volatile double y = x; |
| 23140 | 23221 | volatile double z = y; |
| 23141 | 23222 | rc = (y!=z); |
| 23142 | | -#else /* if defined(SQLITE_HAVE_ISNAN) */ |
| 23223 | +#else /* if HAVE_ISNAN */ |
| 23143 | 23224 | rc = isnan(x); |
| 23144 | | -#endif /* SQLITE_HAVE_ISNAN */ |
| 23225 | +#endif /* HAVE_ISNAN */ |
| 23145 | 23226 | testcase( rc ); |
| 23146 | 23227 | return rc; |
| 23147 | 23228 | } |
| 23148 | 23229 | #endif /* SQLITE_OMIT_FLOATING_POINT */ |
| 23149 | 23230 | |
| | @@ -28460,13 +28541,13 @@ |
| 28460 | 28541 | |
| 28461 | 28542 | /* |
| 28462 | 28543 | ** We do not trust systems to provide a working fdatasync(). Some do. |
| 28463 | 28544 | ** Others do no. To be safe, we will stick with the (slightly slower) |
| 28464 | 28545 | ** fsync(). If you know that your system does support fdatasync() correctly, |
| 28465 | | -** then simply compile with -Dfdatasync=fdatasync |
| 28546 | +** then simply compile with -Dfdatasync=fdatasync or -DHAVE_FDATASYNC |
| 28466 | 28547 | */ |
| 28467 | | -#if !defined(fdatasync) |
| 28548 | +#if !defined(fdatasync) && !HAVE_FDATASYNC |
| 28468 | 28549 | # define fdatasync fsync |
| 28469 | 28550 | #endif |
| 28470 | 28551 | |
| 28471 | 28552 | /* |
| 28472 | 28553 | ** Define HAVE_FULLFSYNC to 0 or 1 depending on whether or not |
| | @@ -28783,28 +28864,32 @@ |
| 28783 | 28864 | do{ |
| 28784 | 28865 | err = osFallocate(pFile->h, buf.st_size, nSize-buf.st_size); |
| 28785 | 28866 | }while( err==EINTR ); |
| 28786 | 28867 | if( err ) return SQLITE_IOERR_WRITE; |
| 28787 | 28868 | #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. |
| 28869 | + /* If the OS does not have posix_fallocate(), fake it. Write a |
| 28870 | + ** single byte to the last byte in each block that falls entirely |
| 28871 | + ** within the extended region. Then, if required, a single byte |
| 28872 | + ** at offset (nSize-1), to set the size of the file correctly. |
| 28873 | + ** This is a similar technique to that used by glibc on systems |
| 28874 | + ** that do not have a real fallocate() call. |
| 28793 | 28875 | */ |
| 28794 | 28876 | int nBlk = buf.st_blksize; /* File-system block size */ |
| 28877 | + int nWrite = 0; /* Number of bytes written by seekAndWrite */ |
| 28795 | 28878 | i64 iWrite; /* Next offset to write to */ |
| 28796 | 28879 | |
| 28797 | | - if( robust_ftruncate(pFile->h, nSize) ){ |
| 28798 | | - pFile->lastErrno = errno; |
| 28799 | | - return unixLogError(SQLITE_IOERR_TRUNCATE, "ftruncate", pFile->zPath); |
| 28800 | | - } |
| 28801 | 28880 | iWrite = ((buf.st_size + 2*nBlk - 1)/nBlk)*nBlk-1; |
| 28802 | | - while( iWrite<nSize ){ |
| 28803 | | - int nWrite = seekAndWrite(pFile, iWrite, "", 1); |
| 28881 | + assert( iWrite>=buf.st_size ); |
| 28882 | + assert( (iWrite/nBlk)==((buf.st_size+nBlk-1)/nBlk) ); |
| 28883 | + assert( ((iWrite+1)%nBlk)==0 ); |
| 28884 | + for(/*no-op*/; iWrite<nSize; iWrite+=nBlk ){ |
| 28885 | + nWrite = seekAndWrite(pFile, iWrite, "", 1); |
| 28804 | 28886 | if( nWrite!=1 ) return SQLITE_IOERR_WRITE; |
| 28805 | | - iWrite += nBlk; |
| 28887 | + } |
| 28888 | + if( nWrite==0 || (nSize%nBlk) ){ |
| 28889 | + nWrite = seekAndWrite(pFile, nSize-1, "", 1); |
| 28890 | + if( nWrite!=1 ) return SQLITE_IOERR_WRITE; |
| 28806 | 28891 | } |
| 28807 | 28892 | #endif |
| 28808 | 28893 | } |
| 28809 | 28894 | } |
| 28810 | 28895 | |
| | @@ -34018,12 +34103,12 @@ |
| 34018 | 34103 | */ |
| 34019 | 34104 | SQLITE_API int sqlite3_win32_reset_heap(){ |
| 34020 | 34105 | int rc; |
| 34021 | 34106 | MUTEX_LOGIC( sqlite3_mutex *pMaster; ) /* The main static mutex */ |
| 34022 | 34107 | 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); ) |
| 34108 | + MUTEX_LOGIC( pMaster = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MASTER); ) |
| 34109 | + MUTEX_LOGIC( pMem = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MEM); ) |
| 34025 | 34110 | sqlite3_mutex_enter(pMaster); |
| 34026 | 34111 | sqlite3_mutex_enter(pMem); |
| 34027 | 34112 | winMemAssertMagic(); |
| 34028 | 34113 | if( winMemGetHeap()!=NULL && winMemGetOwned() && sqlite3_memory_used()==0 ){ |
| 34029 | 34114 | /* |
| | @@ -35294,11 +35379,11 @@ |
| 35294 | 35379 | sqlite3_file *id, /* File to read from */ |
| 35295 | 35380 | void *pBuf, /* Write content into this buffer */ |
| 35296 | 35381 | int amt, /* Number of bytes to read */ |
| 35297 | 35382 | sqlite3_int64 offset /* Begin reading at this offset */ |
| 35298 | 35383 | ){ |
| 35299 | | -#if !SQLITE_OS_WINCE |
| 35384 | +#if !SQLITE_OS_WINCE && !defined(SQLITE_WIN32_NO_OVERLAPPED) |
| 35300 | 35385 | OVERLAPPED overlapped; /* The offset for ReadFile. */ |
| 35301 | 35386 | #endif |
| 35302 | 35387 | winFile *pFile = (winFile*)id; /* file handle */ |
| 35303 | 35388 | DWORD nRead; /* Number of bytes actually read from file */ |
| 35304 | 35389 | int nRetry = 0; /* Number of retrys */ |
| | @@ -35326,11 +35411,11 @@ |
| 35326 | 35411 | offset += nCopy; |
| 35327 | 35412 | } |
| 35328 | 35413 | } |
| 35329 | 35414 | #endif |
| 35330 | 35415 | |
| 35331 | | -#if SQLITE_OS_WINCE |
| 35416 | +#if SQLITE_OS_WINCE || defined(SQLITE_WIN32_NO_OVERLAPPED) |
| 35332 | 35417 | if( winSeekFile(pFile, offset) ){ |
| 35333 | 35418 | OSTRACE(("READ file=%p, rc=SQLITE_FULL\n", pFile->h)); |
| 35334 | 35419 | return SQLITE_FULL; |
| 35335 | 35420 | } |
| 35336 | 35421 | while( !osReadFile(pFile->h, pBuf, amt, &nRead, 0) ){ |
| | @@ -35398,32 +35483,32 @@ |
| 35398 | 35483 | offset += nCopy; |
| 35399 | 35484 | } |
| 35400 | 35485 | } |
| 35401 | 35486 | #endif |
| 35402 | 35487 | |
| 35403 | | -#if SQLITE_OS_WINCE |
| 35488 | +#if SQLITE_OS_WINCE || defined(SQLITE_WIN32_NO_OVERLAPPED) |
| 35404 | 35489 | rc = winSeekFile(pFile, offset); |
| 35405 | 35490 | if( rc==0 ){ |
| 35406 | 35491 | #else |
| 35407 | 35492 | { |
| 35408 | 35493 | #endif |
| 35409 | | -#if !SQLITE_OS_WINCE |
| 35494 | +#if !SQLITE_OS_WINCE && !defined(SQLITE_WIN32_NO_OVERLAPPED) |
| 35410 | 35495 | OVERLAPPED overlapped; /* The offset for WriteFile. */ |
| 35411 | 35496 | #endif |
| 35412 | 35497 | u8 *aRem = (u8 *)pBuf; /* Data yet to be written */ |
| 35413 | 35498 | int nRem = amt; /* Number of bytes yet to be written */ |
| 35414 | 35499 | DWORD nWrite; /* Bytes written by each WriteFile() call */ |
| 35415 | 35500 | DWORD lastErrno = NO_ERROR; /* Value returned by GetLastError() */ |
| 35416 | 35501 | |
| 35417 | | -#if !SQLITE_OS_WINCE |
| 35502 | +#if !SQLITE_OS_WINCE && !defined(SQLITE_WIN32_NO_OVERLAPPED) |
| 35418 | 35503 | memset(&overlapped, 0, sizeof(OVERLAPPED)); |
| 35419 | 35504 | overlapped.Offset = (LONG)(offset & 0xffffffff); |
| 35420 | 35505 | overlapped.OffsetHigh = (LONG)((offset>>32) & 0x7fffffff); |
| 35421 | 35506 | #endif |
| 35422 | 35507 | |
| 35423 | 35508 | while( nRem>0 ){ |
| 35424 | | -#if SQLITE_OS_WINCE |
| 35509 | +#if SQLITE_OS_WINCE || defined(SQLITE_WIN32_NO_OVERLAPPED) |
| 35425 | 35510 | if( !osWriteFile(pFile->h, aRem, nRem, &nWrite, 0) ){ |
| 35426 | 35511 | #else |
| 35427 | 35512 | if( !osWriteFile(pFile->h, aRem, nRem, &nWrite, &overlapped) ){ |
| 35428 | 35513 | #endif |
| 35429 | 35514 | if( winRetryIoerr(&nRetry, &lastErrno) ) continue; |
| | @@ -35432,11 +35517,11 @@ |
| 35432 | 35517 | assert( nWrite==0 || nWrite<=(DWORD)nRem ); |
| 35433 | 35518 | if( nWrite==0 || nWrite>(DWORD)nRem ){ |
| 35434 | 35519 | lastErrno = osGetLastError(); |
| 35435 | 35520 | break; |
| 35436 | 35521 | } |
| 35437 | | -#if !SQLITE_OS_WINCE |
| 35522 | +#if !SQLITE_OS_WINCE && !defined(SQLITE_WIN32_NO_OVERLAPPED) |
| 35438 | 35523 | offset += nWrite; |
| 35439 | 35524 | overlapped.Offset = (LONG)(offset & 0xffffffff); |
| 35440 | 35525 | overlapped.OffsetHigh = (LONG)((offset>>32) & 0x7fffffff); |
| 35441 | 35526 | #endif |
| 35442 | 35527 | aRem += nWrite; |
| | @@ -38813,22 +38898,10 @@ |
| 38813 | 38898 | void *pStress; /* Argument to xStress */ |
| 38814 | 38899 | sqlite3_pcache *pCache; /* Pluggable cache module */ |
| 38815 | 38900 | PgHdr *pPage1; /* Reference to page 1 */ |
| 38816 | 38901 | }; |
| 38817 | 38902 | |
| 38818 | | -/* |
| 38819 | | -** Some of the assert() macros in this code are too expensive to run |
| 38820 | | -** even during normal debugging. Use them only rarely on long-running |
| 38821 | | -** tests. Enable the expensive asserts using the |
| 38822 | | -** -DSQLITE_ENABLE_EXPENSIVE_ASSERT=1 compile-time option. |
| 38823 | | -*/ |
| 38824 | | -#ifdef SQLITE_ENABLE_EXPENSIVE_ASSERT |
| 38825 | | -# define expensive_assert(X) assert(X) |
| 38826 | | -#else |
| 38827 | | -# define expensive_assert(X) |
| 38828 | | -#endif |
| 38829 | | - |
| 38830 | 38903 | /********************************** Linked List Management ********************/ |
| 38831 | 38904 | |
| 38832 | 38905 | /* Allowed values for second argument to pcacheManageDirtyList() */ |
| 38833 | 38906 | #define PCACHE_DIRTYLIST_REMOVE 1 /* Remove pPage from dirty list */ |
| 38834 | 38907 | #define PCACHE_DIRTYLIST_ADD 2 /* Add pPage to the dirty list */ |
| | @@ -38978,11 +39051,12 @@ |
| 38978 | 39051 | SQLITE_PRIVATE int sqlite3PcacheSetPageSize(PCache *pCache, int szPage){ |
| 38979 | 39052 | assert( pCache->nRef==0 && pCache->pDirty==0 ); |
| 38980 | 39053 | if( pCache->szPage ){ |
| 38981 | 39054 | sqlite3_pcache *pNew; |
| 38982 | 39055 | pNew = sqlite3GlobalConfig.pcache2.xCreate( |
| 38983 | | - szPage, pCache->szExtra + sizeof(PgHdr), pCache->bPurgeable |
| 39056 | + szPage, pCache->szExtra + ROUND8(sizeof(PgHdr)), |
| 39057 | + pCache->bPurgeable |
| 38984 | 39058 | ); |
| 38985 | 39059 | if( pNew==0 ) return SQLITE_NOMEM; |
| 38986 | 39060 | sqlite3GlobalConfig.pcache2.xCachesize(pNew, numberOfCachePages(pCache)); |
| 38987 | 39061 | if( pCache->pCache ){ |
| 38988 | 39062 | sqlite3GlobalConfig.pcache2.xDestroy(pCache->pCache); |
| | @@ -39437,11 +39511,11 @@ |
| 39437 | 39511 | |
| 39438 | 39512 | /* |
| 39439 | 39513 | ** Return the size of the header added by this middleware layer |
| 39440 | 39514 | ** in the page-cache hierarchy. |
| 39441 | 39515 | */ |
| 39442 | | -SQLITE_PRIVATE int sqlite3HeaderSizePcache(void){ return sizeof(PgHdr); } |
| 39516 | +SQLITE_PRIVATE int sqlite3HeaderSizePcache(void){ return ROUND8(sizeof(PgHdr)); } |
| 39443 | 39517 | |
| 39444 | 39518 | |
| 39445 | 39519 | #if defined(SQLITE_CHECK_PAGES) || defined(SQLITE_DEBUG) |
| 39446 | 39520 | /* |
| 39447 | 39521 | ** For all dirty pages currently in the cache, invoke the specified |
| | @@ -39753,11 +39827,11 @@ |
| 39753 | 39827 | pcache1Free(pPg); |
| 39754 | 39828 | sqlite3_free(p); |
| 39755 | 39829 | pPg = 0; |
| 39756 | 39830 | } |
| 39757 | 39831 | #else |
| 39758 | | - pPg = pcache1Alloc(sizeof(PgHdr1) + pCache->szPage + pCache->szExtra); |
| 39832 | + pPg = pcache1Alloc(ROUND8(sizeof(PgHdr1)) + pCache->szPage + pCache->szExtra); |
| 39759 | 39833 | p = (PgHdr1 *)&((u8 *)pPg)[pCache->szPage]; |
| 39760 | 39834 | #endif |
| 39761 | 39835 | pcache1EnterMutex(pCache->pGroup); |
| 39762 | 39836 | |
| 39763 | 39837 | if( pPg ){ |
| | @@ -40441,11 +40515,11 @@ |
| 40441 | 40515 | } |
| 40442 | 40516 | |
| 40443 | 40517 | /* |
| 40444 | 40518 | ** Return the size of the header on each page of this PCACHE implementation. |
| 40445 | 40519 | */ |
| 40446 | | -SQLITE_PRIVATE int sqlite3HeaderSizePcache1(void){ return sizeof(PgHdr1); } |
| 40520 | +SQLITE_PRIVATE int sqlite3HeaderSizePcache1(void){ return ROUND8(sizeof(PgHdr1)); } |
| 40447 | 40521 | |
| 40448 | 40522 | #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT |
| 40449 | 40523 | /* |
| 40450 | 40524 | ** This function is called to free superfluous dynamically allocated memory |
| 40451 | 40525 | ** held by the pager system. Memory in use by any SQLite pager allocated |
| | @@ -41799,10 +41873,12 @@ |
| 41799 | 41873 | u8 eLock; /* Current lock held on database file */ |
| 41800 | 41874 | u8 changeCountDone; /* Set after incrementing the change-counter */ |
| 41801 | 41875 | u8 setMaster; /* True if a m-j name has been written to jrnl */ |
| 41802 | 41876 | u8 doNotSpill; /* Do not spill the cache when non-zero */ |
| 41803 | 41877 | u8 subjInMemory; /* True to use in-memory sub-journals */ |
| 41878 | + u8 bUseFetch; /* True to use xFetch() */ |
| 41879 | + u8 hasBeenUsed; /* True if any content previously read from this pager*/ |
| 41804 | 41880 | Pgno dbSize; /* Number of pages in the database */ |
| 41805 | 41881 | Pgno dbOrigSize; /* dbSize before the current transaction */ |
| 41806 | 41882 | Pgno dbFileSize; /* Number of pages in the database file */ |
| 41807 | 41883 | Pgno dbHintSize; /* Value passed to FCNTL_SIZE_HINT call */ |
| 41808 | 41884 | int errCode; /* One of several kinds of errors */ |
| | @@ -41816,13 +41892,13 @@ |
| 41816 | 41892 | i64 journalOff; /* Current write offset in the journal file */ |
| 41817 | 41893 | i64 journalHdr; /* Byte offset to previous journal header */ |
| 41818 | 41894 | sqlite3_backup *pBackup; /* Pointer to list of ongoing backup processes */ |
| 41819 | 41895 | PagerSavepoint *aSavepoint; /* Array of active savepoints */ |
| 41820 | 41896 | int nSavepoint; /* Number of elements in aSavepoint[] */ |
| 41897 | + u32 iDataVersion; /* Changes whenever database content changes */ |
| 41821 | 41898 | char dbFileVers[16]; /* Changes whenever database file changes */ |
| 41822 | 41899 | |
| 41823 | | - u8 bUseFetch; /* True to use xFetch() */ |
| 41824 | 41900 | int nMmapOut; /* Number of mmap pages currently outstanding */ |
| 41825 | 41901 | sqlite3_int64 szMmap; /* Desired maximum mmap size */ |
| 41826 | 41902 | PgHdr *pMmapFreelist; /* List of free mmap page headers (pDirty) */ |
| 41827 | 41903 | /* |
| 41828 | 41904 | ** End of the routinely-changing class members |
| | @@ -42834,13 +42910,22 @@ |
| 42834 | 42910 | |
| 42835 | 42911 | /* |
| 42836 | 42912 | ** Discard the entire contents of the in-memory page-cache. |
| 42837 | 42913 | */ |
| 42838 | 42914 | static void pager_reset(Pager *pPager){ |
| 42915 | + pPager->iDataVersion++; |
| 42839 | 42916 | sqlite3BackupRestart(pPager->pBackup); |
| 42840 | 42917 | sqlite3PcacheClear(pPager->pPCache); |
| 42841 | 42918 | } |
| 42919 | + |
| 42920 | +/* |
| 42921 | +** Return the pPager->iDataVersion value |
| 42922 | +*/ |
| 42923 | +SQLITE_PRIVATE u32 sqlite3PagerDataVersion(Pager *pPager){ |
| 42924 | + assert( pPager->eState>PAGER_OPEN ); |
| 42925 | + return pPager->iDataVersion; |
| 42926 | +} |
| 42842 | 42927 | |
| 42843 | 42928 | /* |
| 42844 | 42929 | ** Free all structures in the Pager.aSavepoint[] array and set both |
| 42845 | 42930 | ** Pager.aSavepoint and Pager.nSavepoint to zero. Close the sub-journal |
| 42846 | 42931 | ** if it is open and the pager is not in exclusive mode. |
| | @@ -45040,11 +45125,11 @@ |
| 45040 | 45125 | Pgno pgno, /* Page number */ |
| 45041 | 45126 | void *pData, /* xFetch()'d data for this page */ |
| 45042 | 45127 | PgHdr **ppPage /* OUT: Acquired page object */ |
| 45043 | 45128 | ){ |
| 45044 | 45129 | PgHdr *p; /* Memory mapped page to return */ |
| 45045 | | - |
| 45130 | + |
| 45046 | 45131 | if( pPager->pMmapFreelist ){ |
| 45047 | 45132 | *ppPage = p = pPager->pMmapFreelist; |
| 45048 | 45133 | pPager->pMmapFreelist = p->pDirty; |
| 45049 | 45134 | p->pDirty = 0; |
| 45050 | 45135 | memset(p->pExtra, 0, pPager->nExtra); |
| | @@ -46271,20 +46356,16 @@ |
| 46271 | 46356 | assert( (pPager->eLock==SHARED_LOCK) |
| 46272 | 46357 | || (pPager->exclusiveMode && pPager->eLock>SHARED_LOCK) |
| 46273 | 46358 | ); |
| 46274 | 46359 | } |
| 46275 | 46360 | |
| 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. |
| 46361 | + if( !pPager->tempFile && pPager->hasBeenUsed ){ |
| 46362 | + /* The shared-lock has just been acquired then check to |
| 46363 | + ** see if the database has been modified. If the database has changed, |
| 46364 | + ** flush the cache. The pPager->hasBeenUsed flag prevents this from |
| 46365 | + ** occurring on the very first access to a file, in order to save a |
| 46366 | + ** single unnecessary sqlite3OsRead() call at the start-up. |
| 46286 | 46367 | ** |
| 46287 | 46368 | ** Database changes is detected by looking at 15 bytes beginning |
| 46288 | 46369 | ** at offset 24 into the file. The first 4 of these 16 bytes are |
| 46289 | 46370 | ** a 32-bit counter that is incremented with each change. The |
| 46290 | 46371 | ** other bytes change randomly with each file change when |
| | @@ -46445,10 +46526,11 @@ |
| 46445 | 46526 | assert( noContent==0 || bMmapOk==0 ); |
| 46446 | 46527 | |
| 46447 | 46528 | if( pgno==0 ){ |
| 46448 | 46529 | return SQLITE_CORRUPT_BKPT; |
| 46449 | 46530 | } |
| 46531 | + pPager->hasBeenUsed = 1; |
| 46450 | 46532 | |
| 46451 | 46533 | /* If the pager is in the error state, return an error immediately. |
| 46452 | 46534 | ** Otherwise, request the page from the PCache layer. */ |
| 46453 | 46535 | if( pPager->errCode!=SQLITE_OK ){ |
| 46454 | 46536 | rc = pPager->errCode; |
| | @@ -46594,10 +46676,11 @@ |
| 46594 | 46676 | sqlite3_pcache_page *pPage; |
| 46595 | 46677 | assert( pPager!=0 ); |
| 46596 | 46678 | assert( pgno!=0 ); |
| 46597 | 46679 | assert( pPager->pPCache!=0 ); |
| 46598 | 46680 | pPage = sqlite3PcacheFetch(pPager->pPCache, pgno, 0); |
| 46681 | + assert( pPage==0 || pPager->hasBeenUsed ); |
| 46599 | 46682 | return sqlite3PcacheFetchFinish(pPager->pPCache, pgno, pPage); |
| 46600 | 46683 | } |
| 46601 | 46684 | |
| 46602 | 46685 | /* |
| 46603 | 46686 | ** Release a page reference. |
| | @@ -47460,10 +47543,11 @@ |
| 47460 | 47543 | pPager->eState = PAGER_READER; |
| 47461 | 47544 | return SQLITE_OK; |
| 47462 | 47545 | } |
| 47463 | 47546 | |
| 47464 | 47547 | PAGERTRACE(("COMMIT %d\n", PAGERID(pPager))); |
| 47548 | + pPager->iDataVersion++; |
| 47465 | 47549 | rc = pager_end_transaction(pPager, pPager->setMaster, 1); |
| 47466 | 47550 | return pager_error(pPager, rc); |
| 47467 | 47551 | } |
| 47468 | 47552 | |
| 47469 | 47553 | /* |
| | @@ -50829,11 +50913,11 @@ |
| 50829 | 50913 | } |
| 50830 | 50914 | nCollide = HASHTABLE_NSLOT; |
| 50831 | 50915 | for(iKey=walHash(pgno); aHash[iKey]; iKey=walNextHash(iKey)){ |
| 50832 | 50916 | u32 iFrame = aHash[iKey] + iZero; |
| 50833 | 50917 | if( iFrame<=iLast && aPgno[aHash[iKey]]==pgno ){ |
| 50834 | | - /* assert( iFrame>iRead ); -- not true if there is corruption */ |
| 50918 | + assert( iFrame>iRead || CORRUPT_DB ); |
| 50835 | 50919 | iRead = iFrame; |
| 50836 | 50920 | } |
| 50837 | 50921 | if( (nCollide--)==0 ){ |
| 50838 | 50922 | return SQLITE_CORRUPT_BKPT; |
| 50839 | 50923 | } |
| | @@ -51935,10 +52019,11 @@ |
| 51935 | 52019 | u8 inTrans; /* TRANS_NONE, TRANS_READ or TRANS_WRITE */ |
| 51936 | 52020 | u8 sharable; /* True if we can share pBt with another db */ |
| 51937 | 52021 | u8 locked; /* True if db currently has pBt locked */ |
| 51938 | 52022 | int wantToLock; /* Number of nested calls to sqlite3BtreeEnter() */ |
| 51939 | 52023 | int nBackup; /* Number of backup operations reading this btree */ |
| 52024 | + u32 iDataVersion; /* Combines with pBt->pPager->iDataVersion */ |
| 51940 | 52025 | Btree *pNext; /* List of other sharable Btrees from the same db */ |
| 51941 | 52026 | Btree *pPrev; /* Back pointer of the same list */ |
| 51942 | 52027 | #ifndef SQLITE_OMIT_SHARED_CACHE |
| 51943 | 52028 | BtLock lock; /* Object used to lock page 1 */ |
| 51944 | 52029 | #endif |
| | @@ -56098,10 +56183,11 @@ |
| 56098 | 56183 | rc = sqlite3PagerCommitPhaseTwo(pBt->pPager); |
| 56099 | 56184 | if( rc!=SQLITE_OK && bCleanup==0 ){ |
| 56100 | 56185 | sqlite3BtreeLeave(p); |
| 56101 | 56186 | return rc; |
| 56102 | 56187 | } |
| 56188 | + p->iDataVersion--; /* Compensate for pPager->iDataVersion++; */ |
| 56103 | 56189 | pBt->inTransaction = TRANS_READ; |
| 56104 | 56190 | btreeClearHasContent(pBt); |
| 56105 | 56191 | } |
| 56106 | 56192 | |
| 56107 | 56193 | btreeEndTransaction(p); |
| | @@ -56461,11 +56547,11 @@ |
| 56461 | 56547 | } |
| 56462 | 56548 | for(i=0; i<=pCur->iPage; i++){ |
| 56463 | 56549 | releasePage(pCur->apPage[i]); |
| 56464 | 56550 | } |
| 56465 | 56551 | unlockBtreeIfUnused(pBt); |
| 56466 | | - sqlite3DbFree(pBtree->db, pCur->aOverflow); |
| 56552 | + sqlite3_free(pCur->aOverflow); |
| 56467 | 56553 | /* sqlite3_free(pCur); */ |
| 56468 | 56554 | sqlite3BtreeLeave(pBtree); |
| 56469 | 56555 | } |
| 56470 | 56556 | return SQLITE_OK; |
| 56471 | 56557 | } |
| | @@ -56755,10 +56841,11 @@ |
| 56755 | 56841 | pBuf += a; |
| 56756 | 56842 | amt -= a; |
| 56757 | 56843 | }else{ |
| 56758 | 56844 | offset -= pCur->info.nLocal; |
| 56759 | 56845 | } |
| 56846 | + |
| 56760 | 56847 | |
| 56761 | 56848 | if( rc==SQLITE_OK && amt>0 ){ |
| 56762 | 56849 | const u32 ovflSize = pBt->usableSize - 4; /* Bytes content per ovfl page */ |
| 56763 | 56850 | Pgno nextPage; |
| 56764 | 56851 | |
| | @@ -56773,12 +56860,12 @@ |
| 56773 | 56860 | ** means "not yet known" (the cache is lazily populated). |
| 56774 | 56861 | */ |
| 56775 | 56862 | if( eOp!=2 && (pCur->curFlags & BTCF_ValidOvfl)==0 ){ |
| 56776 | 56863 | int nOvfl = (pCur->info.nPayload-pCur->info.nLocal+ovflSize-1)/ovflSize; |
| 56777 | 56864 | if( nOvfl>pCur->nOvflAlloc ){ |
| 56778 | | - Pgno *aNew = (Pgno*)sqlite3DbRealloc( |
| 56779 | | - pCur->pBtree->db, pCur->aOverflow, nOvfl*2*sizeof(Pgno) |
| 56865 | + Pgno *aNew = (Pgno*)sqlite3Realloc( |
| 56866 | + pCur->aOverflow, nOvfl*2*sizeof(Pgno) |
| 56780 | 56867 | ); |
| 56781 | 56868 | if( aNew==0 ){ |
| 56782 | 56869 | rc = SQLITE_NOMEM; |
| 56783 | 56870 | }else{ |
| 56784 | 56871 | pCur->nOvflAlloc = nOvfl*2; |
| | @@ -56821,10 +56908,11 @@ |
| 56821 | 56908 | ** Note that the aOverflow[] array must be allocated because eOp!=2 |
| 56822 | 56909 | ** here. If eOp==2, then offset==0 and this branch is never taken. |
| 56823 | 56910 | */ |
| 56824 | 56911 | assert( eOp!=2 ); |
| 56825 | 56912 | assert( pCur->curFlags & BTCF_ValidOvfl ); |
| 56913 | + assert( pCur->pBtree->db==pBt->db ); |
| 56826 | 56914 | if( pCur->aOverflow[iIdx+1] ){ |
| 56827 | 56915 | nextPage = pCur->aOverflow[iIdx+1]; |
| 56828 | 56916 | }else{ |
| 56829 | 56917 | rc = getOverflowPage(pBt, nextPage, 0, &nextPage); |
| 56830 | 56918 | } |
| | @@ -59410,12 +59498,12 @@ |
| 59410 | 59498 | assert( leafCorrection==4 ); |
| 59411 | 59499 | if( szCell[nCell]<4 ){ |
| 59412 | 59500 | /* Do not allow any cells smaller than 4 bytes. If a smaller cell |
| 59413 | 59501 | ** does exist, pad it with 0x00 bytes. */ |
| 59414 | 59502 | assert( szCell[nCell]==3 ); |
| 59415 | | - assert( apCell[nCell]==&pTemp[iSpace1-3] ); |
| 59416 | | - pTemp[iSpace1++] = 0x00; |
| 59503 | + assert( apCell[nCell]==&aSpace1[iSpace1-3] ); |
| 59504 | + aSpace1[iSpace1++] = 0x00; |
| 59417 | 59505 | szCell[nCell] = 4; |
| 59418 | 59506 | } |
| 59419 | 59507 | } |
| 59420 | 59508 | nCell++; |
| 59421 | 59509 | } |
| | @@ -60723,10 +60811,17 @@ |
| 60723 | 60811 | ** is read-only, the others are read/write. |
| 60724 | 60812 | ** |
| 60725 | 60813 | ** The schema layer numbers meta values differently. At the schema |
| 60726 | 60814 | ** layer (and the SetCookie and ReadCookie opcodes) the number of |
| 60727 | 60815 | ** free pages is not visible. So Cookie[0] is the same as Meta[1]. |
| 60816 | +** |
| 60817 | +** This routine treats Meta[BTREE_DATA_VERSION] as a special case. Instead |
| 60818 | +** of reading the value out of the header, it instead loads the "DataVersion" |
| 60819 | +** from the pager. The BTREE_DATA_VERSION value is not actually stored in the |
| 60820 | +** database file. It is a number computed by the pager. But its access |
| 60821 | +** pattern is the same as header meta values, and so it is convenient to |
| 60822 | +** read it from this routine. |
| 60728 | 60823 | */ |
| 60729 | 60824 | SQLITE_PRIVATE void sqlite3BtreeGetMeta(Btree *p, int idx, u32 *pMeta){ |
| 60730 | 60825 | BtShared *pBt = p->pBt; |
| 60731 | 60826 | |
| 60732 | 60827 | sqlite3BtreeEnter(p); |
| | @@ -60733,11 +60828,15 @@ |
| 60733 | 60828 | assert( p->inTrans>TRANS_NONE ); |
| 60734 | 60829 | assert( SQLITE_OK==querySharedCacheTableLock(p, MASTER_ROOT, READ_LOCK) ); |
| 60735 | 60830 | assert( pBt->pPage1 ); |
| 60736 | 60831 | assert( idx>=0 && idx<=15 ); |
| 60737 | 60832 | |
| 60738 | | - *pMeta = get4byte(&pBt->pPage1->aData[36 + idx*4]); |
| 60833 | + if( idx==BTREE_DATA_VERSION ){ |
| 60834 | + *pMeta = sqlite3PagerDataVersion(pBt->pPager) + p->iDataVersion; |
| 60835 | + }else{ |
| 60836 | + *pMeta = get4byte(&pBt->pPage1->aData[36 + idx*4]); |
| 60837 | + } |
| 60739 | 60838 | |
| 60740 | 60839 | /* If auto-vacuum is disabled in this build and this is an auto-vacuum |
| 60741 | 60840 | ** database, mark the database as read-only. */ |
| 60742 | 60841 | #ifdef SQLITE_OMIT_AUTOVACUUM |
| 60743 | 60842 | if( idx==BTREE_LARGEST_ROOT_PAGE && *pMeta>0 ){ |
| | @@ -60824,11 +60923,11 @@ |
| 60824 | 60923 | if( pPage->leaf ){ |
| 60825 | 60924 | do { |
| 60826 | 60925 | if( pCur->iPage==0 ){ |
| 60827 | 60926 | /* All pages of the b-tree have been visited. Return successfully. */ |
| 60828 | 60927 | *pnEntry = nEntry; |
| 60829 | | - return SQLITE_OK; |
| 60928 | + return moveToRoot(pCur); |
| 60830 | 60929 | } |
| 60831 | 60930 | moveToParent(pCur); |
| 60832 | 60931 | }while ( pCur->aiIdx[pCur->iPage]>=pCur->apPage[pCur->iPage]->nCell ); |
| 60833 | 60932 | |
| 60834 | 60933 | pCur->aiIdx[pCur->iPage]++; |
| | @@ -61680,11 +61779,11 @@ |
| 61680 | 61779 | } |
| 61681 | 61780 | |
| 61682 | 61781 | /* |
| 61683 | 61782 | ** Return the size of the header added to each page by this module. |
| 61684 | 61783 | */ |
| 61685 | | -SQLITE_PRIVATE int sqlite3HeaderSizeBtree(void){ return sizeof(MemPage); } |
| 61784 | +SQLITE_PRIVATE int sqlite3HeaderSizeBtree(void){ return ROUND8(sizeof(MemPage)); } |
| 61686 | 61785 | |
| 61687 | 61786 | /************** End of btree.c ***********************************************/ |
| 61688 | 61787 | /************** Begin file backup.c ******************************************/ |
| 61689 | 61788 | /* |
| 61690 | 61789 | ** 2009 January 28 |
| | @@ -64444,36 +64543,39 @@ |
| 64444 | 64543 | ** |
| 64445 | 64544 | ** assert( sqlite3VdbeAssertMayAbort(pParse->pVdbe, pParse->mayAbort) ); |
| 64446 | 64545 | */ |
| 64447 | 64546 | SQLITE_PRIVATE int sqlite3VdbeAssertMayAbort(Vdbe *v, int mayAbort){ |
| 64448 | 64547 | int hasAbort = 0; |
| 64548 | + int hasFkCounter = 0; |
| 64449 | 64549 | Op *pOp; |
| 64450 | 64550 | VdbeOpIter sIter; |
| 64451 | 64551 | memset(&sIter, 0, sizeof(sIter)); |
| 64452 | 64552 | sIter.v = v; |
| 64453 | 64553 | |
| 64454 | 64554 | while( (pOp = opIterNext(&sIter))!=0 ){ |
| 64455 | 64555 | int opcode = pOp->opcode; |
| 64456 | 64556 | 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 | 64557 | || ((opcode==OP_Halt || opcode==OP_HaltIfNull) |
| 64461 | 64558 | && ((pOp->p1&0xff)==SQLITE_CONSTRAINT && pOp->p2==OE_Abort)) |
| 64462 | 64559 | ){ |
| 64463 | 64560 | hasAbort = 1; |
| 64464 | 64561 | break; |
| 64465 | 64562 | } |
| 64563 | +#ifndef SQLITE_OMIT_FOREIGN_KEY |
| 64564 | + if( opcode==OP_FkCounter && pOp->p1==0 && pOp->p2==1 ){ |
| 64565 | + hasFkCounter = 1; |
| 64566 | + } |
| 64567 | +#endif |
| 64466 | 64568 | } |
| 64467 | 64569 | sqlite3DbFree(v->db, sIter.apSub); |
| 64468 | 64570 | |
| 64469 | 64571 | /* Return true if hasAbort==mayAbort. Or if a malloc failure occurred. |
| 64470 | 64572 | ** If malloc failed, then the while() loop above may not have iterated |
| 64471 | 64573 | ** through all opcodes and hasAbort may be set incorrectly. Return |
| 64472 | 64574 | ** true for this case to prevent the assert() in the callers frame |
| 64473 | 64575 | ** from failing. */ |
| 64474 | | - return ( v->db->mallocFailed || hasAbort==mayAbort ); |
| 64576 | + return ( v->db->mallocFailed || hasAbort==mayAbort || hasFkCounter ); |
| 64475 | 64577 | } |
| 64476 | 64578 | #endif /* SQLITE_DEBUG - the sqlite3AssertMayAbort() function */ |
| 64477 | 64579 | |
| 64478 | 64580 | /* |
| 64479 | 64581 | ** Loop through the program looking for P2 values that are negative |
| | @@ -68593,11 +68695,14 @@ |
| 68593 | 68695 | #ifndef SQLITE_OMIT_WAL |
| 68594 | 68696 | int i; |
| 68595 | 68697 | for(i=0; i<db->nDb; i++){ |
| 68596 | 68698 | Btree *pBt = db->aDb[i].pBt; |
| 68597 | 68699 | if( pBt ){ |
| 68598 | | - int nEntry = sqlite3PagerWalCallback(sqlite3BtreePager(pBt)); |
| 68700 | + int nEntry; |
| 68701 | + sqlite3BtreeEnter(pBt); |
| 68702 | + nEntry = sqlite3PagerWalCallback(sqlite3BtreePager(pBt)); |
| 68703 | + sqlite3BtreeLeave(pBt); |
| 68599 | 68704 | if( db->xWalCallback && nEntry>0 && rc==SQLITE_OK ){ |
| 68600 | 68705 | rc = db->xWalCallback(db->pWalArg, db, db->aDb[i].zName, nEntry); |
| 68601 | 68706 | } |
| 68602 | 68707 | } |
| 68603 | 68708 | } |
| | @@ -68773,11 +68878,10 @@ |
| 68773 | 68878 | ** program counter to 0 to ensure that when the statement is |
| 68774 | 68879 | ** finalized or reset the parser error message is available via |
| 68775 | 68880 | ** sqlite3_errmsg() and sqlite3_errcode(). |
| 68776 | 68881 | */ |
| 68777 | 68882 | const char *zErr = (const char *)sqlite3_value_text(db->pErr); |
| 68778 | | - assert( zErr!=0 || db->mallocFailed ); |
| 68779 | 68883 | sqlite3DbFree(db, v->zErrMsg); |
| 68780 | 68884 | if( !db->mallocFailed ){ |
| 68781 | 68885 | v->zErrMsg = sqlite3DbStrDup(db, zErr); |
| 68782 | 68886 | v->rc = rc2; |
| 68783 | 68887 | } else { |
| | @@ -73838,12 +73942,12 @@ |
| 73838 | 73942 | pIdxKey->default_rc = 0; |
| 73839 | 73943 | if( pOp->opcode==OP_NoConflict ){ |
| 73840 | 73944 | /* For the OP_NoConflict opcode, take the jump if any of the |
| 73841 | 73945 | ** input fields are NULL, since any key with a NULL will not |
| 73842 | 73946 | ** conflict */ |
| 73843 | | - for(ii=0; ii<r.nField; ii++){ |
| 73844 | | - if( r.aMem[ii].flags & MEM_Null ){ |
| 73947 | + for(ii=0; ii<pIdxKey->nField; ii++){ |
| 73948 | + if( pIdxKey->aMem[ii].flags & MEM_Null ){ |
| 73845 | 73949 | pc = pOp->p2 - 1; VdbeBranchTaken(1,2); |
| 73846 | 73950 | break; |
| 73847 | 73951 | } |
| 73848 | 73952 | } |
| 73849 | 73953 | } |
| | @@ -77135,11 +77239,11 @@ |
| 77135 | 77239 | /* |
| 77136 | 77240 | ** Hard-coded maximum amount of data to accumulate in memory before flushing |
| 77137 | 77241 | ** to a level 0 PMA. The purpose of this limit is to prevent various integer |
| 77138 | 77242 | ** overflows. 512MiB. |
| 77139 | 77243 | */ |
| 77140 | | -#define SQLITE_MAX_MXPMASIZE (1<<29) |
| 77244 | +#define SQLITE_MAX_PMASZ (1<<29) |
| 77141 | 77245 | |
| 77142 | 77246 | /* |
| 77143 | 77247 | ** Private objects used by the sorter |
| 77144 | 77248 | */ |
| 77145 | 77249 | typedef struct MergeEngine MergeEngine; /* Merge PMAs together */ |
| | @@ -77431,15 +77535,10 @@ |
| 77431 | 77535 | ** |
| 77432 | 77536 | ** void *SRVAL(SorterRecord *p) { return (void*)&p[1]; } |
| 77433 | 77537 | */ |
| 77434 | 77538 | #define SRVAL(p) ((void*)((SorterRecord*)(p) + 1)) |
| 77435 | 77539 | |
| 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 | 77540 | |
| 77442 | 77541 | /* Maximum number of PMAs that a single MergeEngine can merge */ |
| 77443 | 77542 | #define SORTER_MAX_MERGE_COUNT 16 |
| 77444 | 77543 | |
| 77445 | 77544 | static int vdbeIncrSwap(IncrMerger*); |
| | @@ -77834,14 +77933,15 @@ |
| 77834 | 77933 | SortSubtask *pTask = &pSorter->aTask[i]; |
| 77835 | 77934 | pTask->pSorter = pSorter; |
| 77836 | 77935 | } |
| 77837 | 77936 | |
| 77838 | 77937 | if( !sqlite3TempInMemory(db) ){ |
| 77839 | | - pSorter->mnPmaSize = SQLITE_SORTER_PMASZ * pgsz; |
| 77938 | + u32 szPma = sqlite3GlobalConfig.szPma; |
| 77939 | + pSorter->mnPmaSize = szPma * pgsz; |
| 77840 | 77940 | 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); |
| 77941 | + if( mxCache<(int)szPma ) mxCache = (int)szPma; |
| 77942 | + pSorter->mxPmaSize = MIN((i64)mxCache*pgsz, SQLITE_MAX_PMASZ); |
| 77843 | 77943 | |
| 77844 | 77944 | /* EVIDENCE-OF: R-26747-61719 When the application provides any amount of |
| 77845 | 77945 | ** scratch memory using SQLITE_CONFIG_SCRATCH, SQLite avoids unnecessary |
| 77846 | 77946 | ** large heap allocations. |
| 77847 | 77947 | */ |
| | @@ -78115,16 +78215,16 @@ |
| 78115 | 78215 | ** Whether or not the file does end up memory mapped of course depends on |
| 78116 | 78216 | ** the specific VFS implementation. |
| 78117 | 78217 | */ |
| 78118 | 78218 | static void vdbeSorterExtendFile(sqlite3 *db, sqlite3_file *pFd, i64 nByte){ |
| 78119 | 78219 | 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 | | - } |
| 78220 | + void *p = 0; |
| 78221 | + int chunksize = 4*1024; |
| 78222 | + sqlite3OsFileControlHint(pFd, SQLITE_FCNTL_CHUNK_SIZE, &chunksize); |
| 78223 | + sqlite3OsFileControlHint(pFd, SQLITE_FCNTL_SIZE_HINT, &nByte); |
| 78224 | + sqlite3OsFetch(pFd, 0, (int)nByte, &p); |
| 78225 | + sqlite3OsUnfetch(pFd, 0, p); |
| 78126 | 78226 | } |
| 78127 | 78227 | } |
| 78128 | 78228 | #else |
| 78129 | 78229 | # define vdbeSorterExtendFile(x,y,z) |
| 78130 | 78230 | #endif |
| | @@ -79401,10 +79501,11 @@ |
| 79401 | 79501 | rc = vdbePmaReaderNext(pSorter->pReader); |
| 79402 | 79502 | *pbEof = (pSorter->pReader->pFd==0); |
| 79403 | 79503 | }else |
| 79404 | 79504 | #endif |
| 79405 | 79505 | /*if( !pSorter->bUseThreads )*/ { |
| 79506 | + assert( pSorter->pMerger!=0 ); |
| 79406 | 79507 | assert( pSorter->pMerger->pTask==(&pSorter->aTask[0]) ); |
| 79407 | 79508 | rc = vdbeMergeEngineStep(pSorter->pMerger, pbEof); |
| 79408 | 79509 | } |
| 79409 | 79510 | }else{ |
| 79410 | 79511 | SorterRecord *pFree = pSorter->list.pList; |
| | @@ -82167,11 +82268,11 @@ |
| 82167 | 82268 | Expr *pLeft, /* Left operand */ |
| 82168 | 82269 | Expr *pRight, /* Right operand */ |
| 82169 | 82270 | const Token *pToken /* Argument token */ |
| 82170 | 82271 | ){ |
| 82171 | 82272 | Expr *p; |
| 82172 | | - if( op==TK_AND && pLeft && pRight ){ |
| 82273 | + if( op==TK_AND && pLeft && pRight && pParse->nErr==0 ){ |
| 82173 | 82274 | /* Take advantage of short-circuit false optimization for AND */ |
| 82174 | 82275 | p = sqlite3ExprAnd(pParse->db, pLeft, pRight); |
| 82175 | 82276 | }else{ |
| 82176 | 82277 | p = sqlite3ExprAlloc(pParse->db, op, pToken, 1); |
| 82177 | 82278 | sqlite3ExprAttachSubtrees(pParse->db, p, pLeft, pRight); |
| | @@ -85721,14 +85822,15 @@ |
| 85721 | 85822 | ** NEVER() will need to be removed. */ |
| 85722 | 85823 | if( pExpr->op==TK_COLUMN || NEVER(pExpr->op==TK_AGG_COLUMN) ){ |
| 85723 | 85824 | int i; |
| 85724 | 85825 | struct SrcCount *p = pWalker->u.pSrcCount; |
| 85725 | 85826 | SrcList *pSrc = p->pSrc; |
| 85726 | | - for(i=0; i<pSrc->nSrc; i++){ |
| 85827 | + int nSrc = pSrc ? pSrc->nSrc : 0; |
| 85828 | + for(i=0; i<nSrc; i++){ |
| 85727 | 85829 | if( pExpr->iTable==pSrc->a[i].iCursor ) break; |
| 85728 | 85830 | } |
| 85729 | | - if( i<pSrc->nSrc ){ |
| 85831 | + if( i<nSrc ){ |
| 85730 | 85832 | p->nThis++; |
| 85731 | 85833 | }else{ |
| 85732 | 85834 | p->nOther++; |
| 85733 | 85835 | } |
| 85734 | 85836 | } |
| | @@ -87302,11 +87404,11 @@ |
| 87302 | 87404 | |
| 87303 | 87405 | p->iGet = -1; |
| 87304 | 87406 | p->mxSample = mxSample; |
| 87305 | 87407 | p->nPSample = (tRowcnt)(sqlite3_value_int64(argv[2])/(mxSample/3+1) + 1); |
| 87306 | 87408 | p->current.anLt = &p->current.anEq[nColUp]; |
| 87307 | | - p->iPrn = nCol*0x689e962d ^ sqlite3_value_int(argv[2])*0xd0944565; |
| 87409 | + p->iPrn = 0x689e962d*(u32)nCol ^ 0xd0944565*(u32)sqlite3_value_int(argv[2]); |
| 87308 | 87410 | |
| 87309 | 87411 | /* Set up the Stat4Accum.a[] and aBest[] arrays */ |
| 87310 | 87412 | p->a = (struct Stat4Sample*)&p->current.anLt[nColUp]; |
| 87311 | 87413 | p->aBest = &p->a[mxSample]; |
| 87312 | 87414 | pSpace = (u8*)(&p->a[mxSample+nCol]); |
| | @@ -88895,17 +88997,19 @@ |
| 88895 | 88997 | }else if( aNew->pSchema->file_format && aNew->pSchema->enc!=ENC(db) ){ |
| 88896 | 88998 | zErrDyn = sqlite3MPrintf(db, |
| 88897 | 88999 | "attached databases must use the same text encoding as main database"); |
| 88898 | 89000 | rc = SQLITE_ERROR; |
| 88899 | 89001 | } |
| 89002 | + sqlite3BtreeEnter(aNew->pBt); |
| 88900 | 89003 | pPager = sqlite3BtreePager(aNew->pBt); |
| 88901 | 89004 | sqlite3PagerLockingMode(pPager, db->dfltLockMode); |
| 88902 | 89005 | sqlite3BtreeSecureDelete(aNew->pBt, |
| 88903 | 89006 | sqlite3BtreeSecureDelete(db->aDb[0].pBt,-1) ); |
| 88904 | 89007 | #ifndef SQLITE_OMIT_PAGER_PRAGMAS |
| 88905 | 89008 | sqlite3BtreeSetPagerFlags(aNew->pBt, 3 | (db->flags & PAGER_FLAGS_MASK)); |
| 88906 | 89009 | #endif |
| 89010 | + sqlite3BtreeLeave(aNew->pBt); |
| 88907 | 89011 | } |
| 88908 | 89012 | aNew->safety_level = 3; |
| 88909 | 89013 | aNew->zName = sqlite3DbStrDup(db, zName); |
| 88910 | 89014 | if( rc==SQLITE_OK && aNew->zName==0 ){ |
| 88911 | 89015 | rc = SQLITE_NOMEM; |
| | @@ -90027,11 +90131,10 @@ |
| 90027 | 90131 | */ |
| 90028 | 90132 | static void freeIndex(sqlite3 *db, Index *p){ |
| 90029 | 90133 | #ifndef SQLITE_OMIT_ANALYZE |
| 90030 | 90134 | sqlite3DeleteIndexSamples(db, p); |
| 90031 | 90135 | #endif |
| 90032 | | - if( db==0 || db->pnBytesFreed==0 ) sqlite3KeyInfoUnref(p->pKeyInfo); |
| 90033 | 90136 | sqlite3ExprDelete(db, p->pPartIdxWhere); |
| 90034 | 90137 | sqlite3DbFree(db, p->zColAff); |
| 90035 | 90138 | if( p->isResized ) sqlite3DbFree(db, p->azColl); |
| 90036 | 90139 | #ifdef SQLITE_ENABLE_STAT3_OR_STAT4 |
| 90037 | 90140 | sqlite3_free(p->aiRowEst); |
| | @@ -91306,10 +91409,23 @@ |
| 91306 | 91409 | if( pPk==0 ) return; |
| 91307 | 91410 | pPk->idxType = SQLITE_IDXTYPE_PRIMARYKEY; |
| 91308 | 91411 | pTab->iPKey = -1; |
| 91309 | 91412 | }else{ |
| 91310 | 91413 | pPk = sqlite3PrimaryKeyIndex(pTab); |
| 91414 | + /* |
| 91415 | + ** Remove all redundant columns from the PRIMARY KEY. For example, change |
| 91416 | + ** "PRIMARY KEY(a,b,a,b,c,b,c,d)" into just "PRIMARY KEY(a,b,c,d)". Later |
| 91417 | + ** code assumes the PRIMARY KEY contains no repeated columns. |
| 91418 | + */ |
| 91419 | + for(i=j=1; i<pPk->nKeyCol; i++){ |
| 91420 | + if( hasColumn(pPk->aiColumn, j, pPk->aiColumn[i]) ){ |
| 91421 | + pPk->nColumn--; |
| 91422 | + }else{ |
| 91423 | + pPk->aiColumn[j++] = pPk->aiColumn[i]; |
| 91424 | + } |
| 91425 | + } |
| 91426 | + pPk->nKeyCol = j; |
| 91311 | 91427 | } |
| 91312 | 91428 | pPk->isCovering = 1; |
| 91313 | 91429 | assert( pPk!=0 ); |
| 91314 | 91430 | nPk = pPk->nKeyCol; |
| 91315 | 91431 | |
| | @@ -93782,44 +93898,35 @@ |
| 93782 | 93898 | ** |
| 93783 | 93899 | ** The caller should invoke sqlite3KeyInfoUnref() on the returned object |
| 93784 | 93900 | ** when it has finished using it. |
| 93785 | 93901 | */ |
| 93786 | 93902 | SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoOfIndex(Parse *pParse, Index *pIdx){ |
| 93903 | + int i; |
| 93904 | + int nCol = pIdx->nColumn; |
| 93905 | + int nKey = pIdx->nKeyCol; |
| 93906 | + KeyInfo *pKey; |
| 93787 | 93907 | 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); |
| 93908 | + if( pIdx->uniqNotNull ){ |
| 93909 | + pKey = sqlite3KeyInfoAlloc(pParse->db, nKey, nCol-nKey); |
| 93910 | + }else{ |
| 93911 | + pKey = sqlite3KeyInfoAlloc(pParse->db, nCol, 0); |
| 93912 | + } |
| 93913 | + if( pKey ){ |
| 93914 | + assert( sqlite3KeyInfoIsWriteable(pKey) ); |
| 93915 | + for(i=0; i<nCol; i++){ |
| 93916 | + char *zColl = pIdx->azColl[i]; |
| 93917 | + assert( zColl!=0 ); |
| 93918 | + pKey->aColl[i] = strcmp(zColl,"BINARY")==0 ? 0 : |
| 93919 | + sqlite3LocateCollSeq(pParse, zColl); |
| 93920 | + pKey->aSortOrder[i] = pIdx->aSortOrder[i]; |
| 93921 | + } |
| 93922 | + if( pParse->nErr ){ |
| 93923 | + sqlite3KeyInfoUnref(pKey); |
| 93924 | + pKey = 0; |
| 93925 | + } |
| 93926 | + } |
| 93927 | + return pKey; |
| 93821 | 93928 | } |
| 93822 | 93929 | |
| 93823 | 93930 | #ifndef SQLITE_OMIT_CTE |
| 93824 | 93931 | /* |
| 93825 | 93932 | ** This routine is invoked once per CTE by the parser while parsing a |
| | @@ -94596,12 +94703,12 @@ |
| 94596 | 94703 | const char *zDb; /* Name of database holding pTab */ |
| 94597 | 94704 | int i; /* Loop counter */ |
| 94598 | 94705 | WhereInfo *pWInfo; /* Information about the WHERE clause */ |
| 94599 | 94706 | Index *pIdx; /* For looping over indices of the table */ |
| 94600 | 94707 | int iTabCur; /* Cursor number for the table */ |
| 94601 | | - int iDataCur; /* VDBE cursor for the canonical data source */ |
| 94602 | | - int iIdxCur; /* Cursor number of the first index */ |
| 94708 | + int iDataCur = 0; /* VDBE cursor for the canonical data source */ |
| 94709 | + int iIdxCur = 0; /* Cursor number of the first index */ |
| 94603 | 94710 | int nIdx; /* Number of indices */ |
| 94604 | 94711 | sqlite3 *db; /* Main database structure */ |
| 94605 | 94712 | AuthContext sContext; /* Authorization context */ |
| 94606 | 94713 | NameContext sNC; /* Name context to resolve expressions in */ |
| 94607 | 94714 | int iDb; /* Database number */ |
| | @@ -97436,11 +97543,11 @@ |
| 97436 | 97543 | assert( nIncr==1 ); |
| 97437 | 97544 | sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_FOREIGNKEY, |
| 97438 | 97545 | OE_Abort, 0, P4_STATIC, P5_ConstraintFK); |
| 97439 | 97546 | }else{ |
| 97440 | 97547 | if( nIncr>0 && pFKey->isDeferred==0 ){ |
| 97441 | | - sqlite3ParseToplevel(pParse)->mayAbort = 1; |
| 97548 | + sqlite3MayAbort(pParse); |
| 97442 | 97549 | } |
| 97443 | 97550 | sqlite3VdbeAddOp2(v, OP_FkCounter, pFKey->isDeferred, nIncr); |
| 97444 | 97551 | } |
| 97445 | 97552 | |
| 97446 | 97553 | sqlite3VdbeResolveLabel(v, iOk); |
| | @@ -97507,10 +97614,14 @@ |
| 97507 | 97614 | ** This function is called to generate code executed when a row is deleted |
| 97508 | 97615 | ** from the parent table of foreign key constraint pFKey and, if pFKey is |
| 97509 | 97616 | ** deferred, when a row is inserted into the same table. When generating |
| 97510 | 97617 | ** code for an SQL UPDATE operation, this function may be called twice - |
| 97511 | 97618 | ** once to "delete" the old row and once to "insert" the new row. |
| 97619 | +** |
| 97620 | +** Parameter nIncr is passed -1 when inserting a row (as this may decrease |
| 97621 | +** the number of FK violations in the db) or +1 when deleting one (as this |
| 97622 | +** may increase the number of FK constraint problems). |
| 97512 | 97623 | ** |
| 97513 | 97624 | ** The code generated by this function scans through the rows in the child |
| 97514 | 97625 | ** table that correspond to the parent table row being deleted or inserted. |
| 97515 | 97626 | ** For each child row found, one of the following actions is taken: |
| 97516 | 97627 | ** |
| | @@ -97624,17 +97735,13 @@ |
| 97624 | 97735 | sNameContext.pSrcList = pSrc; |
| 97625 | 97736 | sNameContext.pParse = pParse; |
| 97626 | 97737 | sqlite3ResolveExprNames(&sNameContext, pWhere); |
| 97627 | 97738 | |
| 97628 | 97739 | /* 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. */ |
| 97740 | + ** clause. For each row found, increment either the deferred or immediate |
| 97741 | + ** foreign key constraint counter. */ |
| 97632 | 97742 | pWInfo = sqlite3WhereBegin(pParse, pSrc, pWhere, 0, 0, 0, 0); |
| 97633 | | - if( nIncr>0 && pFKey->isDeferred==0 ){ |
| 97634 | | - sqlite3ParseToplevel(pParse)->mayAbort = 1; |
| 97635 | | - } |
| 97636 | 97743 | sqlite3VdbeAddOp2(v, OP_FkCounter, pFKey->isDeferred, nIncr); |
| 97637 | 97744 | if( pWInfo ){ |
| 97638 | 97745 | sqlite3WhereEnd(pWInfo); |
| 97639 | 97746 | } |
| 97640 | 97747 | |
| | @@ -97808,10 +97915,28 @@ |
| 97808 | 97915 | } |
| 97809 | 97916 | } |
| 97810 | 97917 | } |
| 97811 | 97918 | return 0; |
| 97812 | 97919 | } |
| 97920 | + |
| 97921 | +/* |
| 97922 | +** Return true if the parser passed as the first argument is being |
| 97923 | +** used to code a trigger that is really a "SET NULL" action belonging |
| 97924 | +** to trigger pFKey. |
| 97925 | +*/ |
| 97926 | +static int isSetNullAction(Parse *pParse, FKey *pFKey){ |
| 97927 | + Parse *pTop = sqlite3ParseToplevel(pParse); |
| 97928 | + if( pTop->pTriggerPrg ){ |
| 97929 | + Trigger *p = pTop->pTriggerPrg->pTrigger; |
| 97930 | + if( (p==pFKey->apTrigger[0] && pFKey->aAction[0]==OE_SetNull) |
| 97931 | + || (p==pFKey->apTrigger[1] && pFKey->aAction[1]==OE_SetNull) |
| 97932 | + ){ |
| 97933 | + return 1; |
| 97934 | + } |
| 97935 | + } |
| 97936 | + return 0; |
| 97937 | +} |
| 97813 | 97938 | |
| 97814 | 97939 | /* |
| 97815 | 97940 | ** This function is called when inserting, deleting or updating a row of |
| 97816 | 97941 | ** table pTab to generate VDBE code to perform foreign key constraint |
| 97817 | 97942 | ** processing for the operation. |
| | @@ -97861,11 +97986,11 @@ |
| 97861 | 97986 | Index *pIdx = 0; /* Index on key columns in pTo */ |
| 97862 | 97987 | int *aiFree = 0; |
| 97863 | 97988 | int *aiCol; |
| 97864 | 97989 | int iCol; |
| 97865 | 97990 | int i; |
| 97866 | | - int isIgnore = 0; |
| 97991 | + int bIgnore = 0; |
| 97867 | 97992 | |
| 97868 | 97993 | if( aChange |
| 97869 | 97994 | && sqlite3_stricmp(pTab->zName, pFKey->zTo)!=0 |
| 97870 | 97995 | && fkChildIsModified(pTab, pFKey, aChange, bChngRowid)==0 |
| 97871 | 97996 | ){ |
| | @@ -97920,11 +98045,11 @@ |
| 97920 | 98045 | ** values read from the parent table are NULL. */ |
| 97921 | 98046 | if( db->xAuth ){ |
| 97922 | 98047 | int rcauth; |
| 97923 | 98048 | char *zCol = pTo->aCol[pIdx ? pIdx->aiColumn[i] : pTo->iPKey].zName; |
| 97924 | 98049 | rcauth = sqlite3AuthReadCol(pParse, pTo->zName, zCol, iDb); |
| 97925 | | - isIgnore = (rcauth==SQLITE_IGNORE); |
| 98050 | + bIgnore = (rcauth==SQLITE_IGNORE); |
| 97926 | 98051 | } |
| 97927 | 98052 | #endif |
| 97928 | 98053 | } |
| 97929 | 98054 | |
| 97930 | 98055 | /* Take a shared-cache advisory read-lock on the parent table. Allocate |
| | @@ -97935,16 +98060,22 @@ |
| 97935 | 98060 | |
| 97936 | 98061 | if( regOld!=0 ){ |
| 97937 | 98062 | /* A row is being removed from the child table. Search for the parent. |
| 97938 | 98063 | ** If the parent does not exist, removing the child row resolves an |
| 97939 | 98064 | ** outstanding foreign key constraint violation. */ |
| 97940 | | - fkLookupParent(pParse, iDb, pTo, pIdx, pFKey, aiCol, regOld, -1,isIgnore); |
| 98065 | + fkLookupParent(pParse, iDb, pTo, pIdx, pFKey, aiCol, regOld, -1, bIgnore); |
| 97941 | 98066 | } |
| 97942 | | - if( regNew!=0 ){ |
| 98067 | + if( regNew!=0 && !isSetNullAction(pParse, pFKey) ){ |
| 97943 | 98068 | /* 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); |
| 98069 | + ** be found, adding the child row has violated the FK constraint. |
| 98070 | + ** |
| 98071 | + ** If this operation is being performed as part of a trigger program |
| 98072 | + ** that is actually a "SET NULL" action belonging to this very |
| 98073 | + ** foreign key, then omit this scan altogether. As all child key |
| 98074 | + ** values are guaranteed to be NULL, it is not possible for adding |
| 98075 | + ** this row to cause an FK violation. */ |
| 98076 | + fkLookupParent(pParse, iDb, pTo, pIdx, pFKey, aiCol, regNew, +1, bIgnore); |
| 97946 | 98077 | } |
| 97947 | 98078 | |
| 97948 | 98079 | sqlite3DbFree(db, aiFree); |
| 97949 | 98080 | } |
| 97950 | 98081 | |
| | @@ -97961,12 +98092,12 @@ |
| 97961 | 98092 | |
| 97962 | 98093 | if( !pFKey->isDeferred && !(db->flags & SQLITE_DeferFKs) |
| 97963 | 98094 | && !pParse->pToplevel && !pParse->isMultiWrite |
| 97964 | 98095 | ){ |
| 97965 | 98096 | 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. */ |
| 98097 | + /* Inserting a single row into a parent table cannot cause (or fix) |
| 98098 | + ** an immediate foreign key violation. So do nothing in this case. */ |
| 97968 | 98099 | continue; |
| 97969 | 98100 | } |
| 97970 | 98101 | |
| 97971 | 98102 | if( sqlite3FkLocateIndex(pParse, pTab, pFKey, &pIdx, &aiCol) ){ |
| 97972 | 98103 | if( !isIgnoreErrors || db->mallocFailed ) return; |
| | @@ -97986,17 +98117,32 @@ |
| 97986 | 98117 | |
| 97987 | 98118 | if( regNew!=0 ){ |
| 97988 | 98119 | fkScanChildren(pParse, pSrc, pTab, pIdx, pFKey, aiCol, regNew, -1); |
| 97989 | 98120 | } |
| 97990 | 98121 | 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. */ |
| 98122 | + int eAction = pFKey->aAction[aChange!=0]; |
| 97997 | 98123 | fkScanChildren(pParse, pSrc, pTab, pIdx, pFKey, aiCol, regOld, 1); |
| 98124 | + /* If this is a deferred FK constraint, or a CASCADE or SET NULL |
| 98125 | + ** action applies, then any foreign key violations caused by |
| 98126 | + ** removing the parent key will be rectified by the action trigger. |
| 98127 | + ** So do not set the "may-abort" flag in this case. |
| 98128 | + ** |
| 98129 | + ** Note 1: If the FK is declared "ON UPDATE CASCADE", then the |
| 98130 | + ** may-abort flag will eventually be set on this statement anyway |
| 98131 | + ** (when this function is called as part of processing the UPDATE |
| 98132 | + ** within the action trigger). |
| 98133 | + ** |
| 98134 | + ** Note 2: At first glance it may seem like SQLite could simply omit |
| 98135 | + ** all OP_FkCounter related scans when either CASCADE or SET NULL |
| 98136 | + ** applies. The trouble starts if the CASCADE or SET NULL action |
| 98137 | + ** trigger causes other triggers or action rules attached to the |
| 98138 | + ** child table to fire. In these cases the fk constraint counters |
| 98139 | + ** might be set incorrectly if any OP_FkCounter related scans are |
| 98140 | + ** omitted. */ |
| 98141 | + if( !pFKey->isDeferred && eAction!=OE_Cascade && eAction!=OE_SetNull ){ |
| 98142 | + sqlite3MayAbort(pParse); |
| 98143 | + } |
| 97998 | 98144 | } |
| 97999 | 98145 | pItem->zName = 0; |
| 98000 | 98146 | sqlite3SrcListDelete(db, pSrc); |
| 98001 | 98147 | } |
| 98002 | 98148 | sqlite3DbFree(db, aiCol); |
| | @@ -101895,10 +102041,11 @@ |
| 101895 | 102041 | #define PragTyp_KEY 38 |
| 101896 | 102042 | #define PragTyp_REKEY 39 |
| 101897 | 102043 | #define PragTyp_LOCK_STATUS 40 |
| 101898 | 102044 | #define PragTyp_PARSER_TRACE 41 |
| 101899 | 102045 | #define PragFlag_NeedSchema 0x01 |
| 102046 | +#define PragFlag_ReadOnly 0x02 |
| 101900 | 102047 | static const struct sPragmaNames { |
| 101901 | 102048 | const char *const zName; /* Name of pragma */ |
| 101902 | 102049 | u8 ePragTyp; /* PragTyp_XXX value */ |
| 101903 | 102050 | u8 mPragFlag; /* Zero or more PragFlag_XXX values */ |
| 101904 | 102051 | u32 iArg; /* Extra argument */ |
| | @@ -101911,11 +102058,11 @@ |
| 101911 | 102058 | #endif |
| 101912 | 102059 | #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS) |
| 101913 | 102060 | { /* zName: */ "application_id", |
| 101914 | 102061 | /* ePragTyp: */ PragTyp_HEADER_VALUE, |
| 101915 | 102062 | /* ePragFlag: */ 0, |
| 101916 | | - /* iArg: */ 0 }, |
| 102063 | + /* iArg: */ BTREE_APPLICATION_ID }, |
| 101917 | 102064 | #endif |
| 101918 | 102065 | #if !defined(SQLITE_OMIT_AUTOVACUUM) |
| 101919 | 102066 | { /* zName: */ "auto_vacuum", |
| 101920 | 102067 | /* ePragTyp: */ PragTyp_AUTO_VACUUM, |
| 101921 | 102068 | /* ePragFlag: */ PragFlag_NeedSchema, |
| | @@ -101977,10 +102124,16 @@ |
| 101977 | 102124 | { /* zName: */ "data_store_directory", |
| 101978 | 102125 | /* ePragTyp: */ PragTyp_DATA_STORE_DIRECTORY, |
| 101979 | 102126 | /* ePragFlag: */ 0, |
| 101980 | 102127 | /* iArg: */ 0 }, |
| 101981 | 102128 | #endif |
| 102129 | +#if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS) |
| 102130 | + { /* zName: */ "data_version", |
| 102131 | + /* ePragTyp: */ PragTyp_HEADER_VALUE, |
| 102132 | + /* ePragFlag: */ PragFlag_ReadOnly, |
| 102133 | + /* iArg: */ BTREE_DATA_VERSION }, |
| 102134 | +#endif |
| 101982 | 102135 | #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) |
| 101983 | 102136 | { /* zName: */ "database_list", |
| 101984 | 102137 | /* ePragTyp: */ PragTyp_DATABASE_LIST, |
| 101985 | 102138 | /* ePragFlag: */ PragFlag_NeedSchema, |
| 101986 | 102139 | /* iArg: */ 0 }, |
| | @@ -102032,12 +102185,12 @@ |
| 102032 | 102185 | #endif |
| 102033 | 102186 | #endif |
| 102034 | 102187 | #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS) |
| 102035 | 102188 | { /* zName: */ "freelist_count", |
| 102036 | 102189 | /* ePragTyp: */ PragTyp_HEADER_VALUE, |
| 102037 | | - /* ePragFlag: */ 0, |
| 102038 | | - /* iArg: */ 0 }, |
| 102190 | + /* ePragFlag: */ PragFlag_ReadOnly, |
| 102191 | + /* iArg: */ BTREE_FREE_PAGE_COUNT }, |
| 102039 | 102192 | #endif |
| 102040 | 102193 | #if !defined(SQLITE_OMIT_FLAG_PRAGMAS) |
| 102041 | 102194 | { /* zName: */ "full_column_names", |
| 102042 | 102195 | /* ePragTyp: */ PragTyp_FLAG, |
| 102043 | 102196 | /* ePragFlag: */ 0, |
| | @@ -102185,11 +102338,11 @@ |
| 102185 | 102338 | #endif |
| 102186 | 102339 | #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS) |
| 102187 | 102340 | { /* zName: */ "schema_version", |
| 102188 | 102341 | /* ePragTyp: */ PragTyp_HEADER_VALUE, |
| 102189 | 102342 | /* ePragFlag: */ 0, |
| 102190 | | - /* iArg: */ 0 }, |
| 102343 | + /* iArg: */ BTREE_SCHEMA_VERSION }, |
| 102191 | 102344 | #endif |
| 102192 | 102345 | #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) |
| 102193 | 102346 | { /* zName: */ "secure_delete", |
| 102194 | 102347 | /* ePragTyp: */ PragTyp_SECURE_DELETE, |
| 102195 | 102348 | /* ePragFlag: */ 0, |
| | @@ -102251,11 +102404,11 @@ |
| 102251 | 102404 | /* iArg: */ 0 }, |
| 102252 | 102405 | #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS) |
| 102253 | 102406 | { /* zName: */ "user_version", |
| 102254 | 102407 | /* ePragTyp: */ PragTyp_HEADER_VALUE, |
| 102255 | 102408 | /* ePragFlag: */ 0, |
| 102256 | | - /* iArg: */ 0 }, |
| 102409 | + /* iArg: */ BTREE_USER_VERSION }, |
| 102257 | 102410 | #endif |
| 102258 | 102411 | #if !defined(SQLITE_OMIT_FLAG_PRAGMAS) |
| 102259 | 102412 | #if defined(SQLITE_DEBUG) |
| 102260 | 102413 | { /* zName: */ "vdbe_addoptrace", |
| 102261 | 102414 | /* ePragTyp: */ PragTyp_FLAG, |
| | @@ -102294,11 +102447,11 @@ |
| 102294 | 102447 | /* ePragTyp: */ PragTyp_FLAG, |
| 102295 | 102448 | /* ePragFlag: */ 0, |
| 102296 | 102449 | /* iArg: */ SQLITE_WriteSchema|SQLITE_RecoveryMode }, |
| 102297 | 102450 | #endif |
| 102298 | 102451 | }; |
| 102299 | | -/* Number of pragmas: 57 on by default, 70 total. */ |
| 102452 | +/* Number of pragmas: 58 on by default, 71 total. */ |
| 102300 | 102453 | /* End of the automatically generated pragma table. |
| 102301 | 102454 | ***************************************************************************/ |
| 102302 | 102455 | |
| 102303 | 102456 | /* |
| 102304 | 102457 | ** Interpret the given string as a safety level. Return 0 for OFF, |
| | @@ -102544,11 +102697,11 @@ |
| 102544 | 102697 | char *zRight = 0; /* Nul-terminated UTF-8 string <value>, or NULL */ |
| 102545 | 102698 | const char *zDb = 0; /* The database name */ |
| 102546 | 102699 | Token *pId; /* Pointer to <id> token */ |
| 102547 | 102700 | char *aFcntl[4]; /* Argument to SQLITE_FCNTL_PRAGMA */ |
| 102548 | 102701 | int iDb; /* Database index for <database> */ |
| 102549 | | - int lwr, upr, mid; /* Binary search bounds */ |
| 102702 | + int lwr, upr, mid = 0; /* Binary search bounds */ |
| 102550 | 102703 | int rc; /* return value form SQLITE_FCNTL_PRAGMA */ |
| 102551 | 102704 | sqlite3 *db = pParse->db; /* The database connection */ |
| 102552 | 102705 | Db *pDb; /* The specific database being pragmaed */ |
| 102553 | 102706 | Vdbe *v = sqlite3GetVdbe(pParse); /* Prepared statement */ |
| 102554 | 102707 | |
| | @@ -103904,11 +104057,12 @@ |
| 103904 | 104057 | !(DbHasProperty(db, 0, DB_SchemaLoaded)) || |
| 103905 | 104058 | DbHasProperty(db, 0, DB_Empty) |
| 103906 | 104059 | ){ |
| 103907 | 104060 | for(pEnc=&encnames[0]; pEnc->zName; pEnc++){ |
| 103908 | 104061 | if( 0==sqlite3StrICmp(zRight, pEnc->zName) ){ |
| 103909 | | - ENC(pParse->db) = pEnc->enc ? pEnc->enc : SQLITE_UTF16NATIVE; |
| 104062 | + SCHEMA_ENC(db) = ENC(db) = |
| 104063 | + pEnc->enc ? pEnc->enc : SQLITE_UTF16NATIVE; |
| 103910 | 104064 | break; |
| 103911 | 104065 | } |
| 103912 | 104066 | } |
| 103913 | 104067 | if( !pEnc->zName ){ |
| 103914 | 104068 | sqlite3ErrorMsg(pParse, "unsupported encoding: %s", zRight); |
| | @@ -103949,28 +104103,13 @@ |
| 103949 | 104103 | ** |
| 103950 | 104104 | ** The user-version is not used internally by SQLite. It may be used by |
| 103951 | 104105 | ** applications for any purpose. |
| 103952 | 104106 | */ |
| 103953 | 104107 | case PragTyp_HEADER_VALUE: { |
| 103954 | | - int iCookie; /* Cookie index. 1 for schema-cookie, 6 for user-cookie. */ |
| 104108 | + int iCookie = aPragmaNames[mid].iArg; /* Which cookie to read or write */ |
| 103955 | 104109 | 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 ){ |
| 104110 | + if( zRight && (aPragmaNames[mid].mPragFlag & PragFlag_ReadOnly)==0 ){ |
| 103972 | 104111 | /* Write the specified cookie value */ |
| 103973 | 104112 | static const VdbeOpList setCookie[] = { |
| 103974 | 104113 | { OP_Transaction, 0, 1, 0}, /* 0 */ |
| 103975 | 104114 | { OP_Integer, 0, 1, 0}, /* 1 */ |
| 103976 | 104115 | { OP_SetCookie, 0, 0, 1}, /* 2 */ |
| | @@ -104612,13 +104751,15 @@ |
| 104612 | 104751 | SQLITE_PRIVATE int sqlite3Init(sqlite3 *db, char **pzErrMsg){ |
| 104613 | 104752 | int i, rc; |
| 104614 | 104753 | int commit_internal = !(db->flags&SQLITE_InternChanges); |
| 104615 | 104754 | |
| 104616 | 104755 | assert( sqlite3_mutex_held(db->mutex) ); |
| 104756 | + assert( sqlite3BtreeHoldsMutex(db->aDb[0].pBt) ); |
| 104617 | 104757 | assert( db->init.busy==0 ); |
| 104618 | 104758 | rc = SQLITE_OK; |
| 104619 | 104759 | db->init.busy = 1; |
| 104760 | + ENC(db) = SCHEMA_ENC(db); |
| 104620 | 104761 | for(i=0; rc==SQLITE_OK && i<db->nDb; i++){ |
| 104621 | 104762 | if( DbHasProperty(db, i, DB_SchemaLoaded) || i==1 ) continue; |
| 104622 | 104763 | rc = sqlite3InitOne(db, i, pzErrMsg); |
| 104623 | 104764 | if( rc ){ |
| 104624 | 104765 | sqlite3ResetOneSchema(db, i); |
| | @@ -105169,24 +105310,29 @@ |
| 105169 | 105310 | u8 sortFlags; /* Zero or more SORTFLAG_* bits */ |
| 105170 | 105311 | }; |
| 105171 | 105312 | #define SORTFLAG_UseSorter 0x01 /* Use SorterOpen instead of OpenEphemeral */ |
| 105172 | 105313 | |
| 105173 | 105314 | /* |
| 105174 | | -** Delete all the content of a Select structure but do not deallocate |
| 105175 | | -** the select structure itself. |
| 105315 | +** Delete all the content of a Select structure. Deallocate the structure |
| 105316 | +** itself only if bFree is true. |
| 105176 | 105317 | */ |
| 105177 | | -static void clearSelect(sqlite3 *db, Select *p){ |
| 105178 | | - sqlite3ExprListDelete(db, p->pEList); |
| 105179 | | - sqlite3SrcListDelete(db, p->pSrc); |
| 105180 | | - sqlite3ExprDelete(db, p->pWhere); |
| 105181 | | - sqlite3ExprListDelete(db, p->pGroupBy); |
| 105182 | | - sqlite3ExprDelete(db, p->pHaving); |
| 105183 | | - sqlite3ExprListDelete(db, p->pOrderBy); |
| 105184 | | - sqlite3SelectDelete(db, p->pPrior); |
| 105185 | | - sqlite3ExprDelete(db, p->pLimit); |
| 105186 | | - sqlite3ExprDelete(db, p->pOffset); |
| 105187 | | - sqlite3WithDelete(db, p->pWith); |
| 105318 | +static void clearSelect(sqlite3 *db, Select *p, int bFree){ |
| 105319 | + while( p ){ |
| 105320 | + Select *pPrior = p->pPrior; |
| 105321 | + sqlite3ExprListDelete(db, p->pEList); |
| 105322 | + sqlite3SrcListDelete(db, p->pSrc); |
| 105323 | + sqlite3ExprDelete(db, p->pWhere); |
| 105324 | + sqlite3ExprListDelete(db, p->pGroupBy); |
| 105325 | + sqlite3ExprDelete(db, p->pHaving); |
| 105326 | + sqlite3ExprListDelete(db, p->pOrderBy); |
| 105327 | + sqlite3ExprDelete(db, p->pLimit); |
| 105328 | + sqlite3ExprDelete(db, p->pOffset); |
| 105329 | + sqlite3WithDelete(db, p->pWith); |
| 105330 | + if( bFree ) sqlite3DbFree(db, p); |
| 105331 | + p = pPrior; |
| 105332 | + bFree = 1; |
| 105333 | + } |
| 105188 | 105334 | } |
| 105189 | 105335 | |
| 105190 | 105336 | /* |
| 105191 | 105337 | ** Initialize a SelectDest structure. |
| 105192 | 105338 | */ |
| | @@ -105241,12 +105387,11 @@ |
| 105241 | 105387 | pNew->pOffset = pOffset; |
| 105242 | 105388 | assert( pOffset==0 || pLimit!=0 ); |
| 105243 | 105389 | pNew->addrOpenEphm[0] = -1; |
| 105244 | 105390 | pNew->addrOpenEphm[1] = -1; |
| 105245 | 105391 | if( db->mallocFailed ) { |
| 105246 | | - clearSelect(db, pNew); |
| 105247 | | - if( pNew!=&standin ) sqlite3DbFree(db, pNew); |
| 105392 | + clearSelect(db, pNew, pNew!=&standin); |
| 105248 | 105393 | pNew = 0; |
| 105249 | 105394 | }else{ |
| 105250 | 105395 | assert( pNew->pSrc!=0 || pParse->nErr>0 ); |
| 105251 | 105396 | } |
| 105252 | 105397 | assert( pNew!=&standin ); |
| | @@ -105267,14 +105412,11 @@ |
| 105267 | 105412 | |
| 105268 | 105413 | /* |
| 105269 | 105414 | ** Delete the given Select structure and all of its substructures. |
| 105270 | 105415 | */ |
| 105271 | 105416 | SQLITE_PRIVATE void sqlite3SelectDelete(sqlite3 *db, Select *p){ |
| 105272 | | - if( p ){ |
| 105273 | | - clearSelect(db, p); |
| 105274 | | - sqlite3DbFree(db, p); |
| 105275 | | - } |
| 105417 | + clearSelect(db, p, 1); |
| 105276 | 105418 | } |
| 105277 | 105419 | |
| 105278 | 105420 | /* |
| 105279 | 105421 | ** Return a pointer to the right-most SELECT statement in a compound. |
| 105280 | 105422 | */ |
| | @@ -107186,10 +107328,70 @@ |
| 107186 | 107328 | Parse *pParse, /* Parsing context */ |
| 107187 | 107329 | Select *p, /* The right-most of SELECTs to be coded */ |
| 107188 | 107330 | SelectDest *pDest /* What to do with query results */ |
| 107189 | 107331 | ); |
| 107190 | 107332 | |
| 107333 | +/* |
| 107334 | +** Error message for when two or more terms of a compound select have different |
| 107335 | +** size result sets. |
| 107336 | +*/ |
| 107337 | +static void selectWrongNumTermsError(Parse *pParse, Select *p){ |
| 107338 | + if( p->selFlags & SF_Values ){ |
| 107339 | + sqlite3ErrorMsg(pParse, "all VALUES must have the same number of terms"); |
| 107340 | + }else{ |
| 107341 | + sqlite3ErrorMsg(pParse, "SELECTs to the left and right of %s" |
| 107342 | + " do not have the same number of result columns", selectOpName(p->op)); |
| 107343 | + } |
| 107344 | +} |
| 107345 | + |
| 107346 | +/* |
| 107347 | +** Handle the special case of a compound-select that originates from a |
| 107348 | +** VALUES clause. By handling this as a special case, we avoid deep |
| 107349 | +** recursion, and thus do not need to enforce the SQLITE_LIMIT_COMPOUND_SELECT |
| 107350 | +** on a VALUES clause. |
| 107351 | +** |
| 107352 | +** Because the Select object originates from a VALUES clause: |
| 107353 | +** (1) It has no LIMIT or OFFSET |
| 107354 | +** (2) All terms are UNION ALL |
| 107355 | +** (3) There is no ORDER BY clause |
| 107356 | +*/ |
| 107357 | +static int multiSelectValues( |
| 107358 | + Parse *pParse, /* Parsing context */ |
| 107359 | + Select *p, /* The right-most of SELECTs to be coded */ |
| 107360 | + SelectDest *pDest /* What to do with query results */ |
| 107361 | +){ |
| 107362 | + Select *pPrior; |
| 107363 | + int nExpr = p->pEList->nExpr; |
| 107364 | + int nRow = 1; |
| 107365 | + int rc = 0; |
| 107366 | + assert( p->pNext==0 ); |
| 107367 | + assert( p->selFlags & SF_AllValues ); |
| 107368 | + do{ |
| 107369 | + assert( p->selFlags & SF_Values ); |
| 107370 | + assert( p->op==TK_ALL || (p->op==TK_SELECT && p->pPrior==0) ); |
| 107371 | + assert( p->pLimit==0 ); |
| 107372 | + assert( p->pOffset==0 ); |
| 107373 | + if( p->pEList->nExpr!=nExpr ){ |
| 107374 | + selectWrongNumTermsError(pParse, p); |
| 107375 | + return 1; |
| 107376 | + } |
| 107377 | + if( p->pPrior==0 ) break; |
| 107378 | + assert( p->pPrior->pNext==p ); |
| 107379 | + p = p->pPrior; |
| 107380 | + nRow++; |
| 107381 | + }while(1); |
| 107382 | + while( p ){ |
| 107383 | + pPrior = p->pPrior; |
| 107384 | + p->pPrior = 0; |
| 107385 | + rc = sqlite3Select(pParse, p, pDest); |
| 107386 | + p->pPrior = pPrior; |
| 107387 | + if( rc ) break; |
| 107388 | + p->nSelectRow = nRow; |
| 107389 | + p = p->pNext; |
| 107390 | + } |
| 107391 | + return rc; |
| 107392 | +} |
| 107191 | 107393 | |
| 107192 | 107394 | /* |
| 107193 | 107395 | ** This routine is called to process a compound query form from |
| 107194 | 107396 | ** two or more separate queries using UNION, UNION ALL, EXCEPT, or |
| 107195 | 107397 | ** INTERSECT |
| | @@ -107266,22 +107468,24 @@ |
| 107266 | 107468 | assert( p->pEList ); |
| 107267 | 107469 | sqlite3VdbeAddOp2(v, OP_OpenEphemeral, dest.iSDParm, p->pEList->nExpr); |
| 107268 | 107470 | sqlite3VdbeChangeP5(v, BTREE_UNORDERED); |
| 107269 | 107471 | dest.eDest = SRT_Table; |
| 107270 | 107472 | } |
| 107473 | + |
| 107474 | + /* Special handling for a compound-select that originates as a VALUES clause. |
| 107475 | + */ |
| 107476 | + if( p->selFlags & SF_AllValues ){ |
| 107477 | + rc = multiSelectValues(pParse, p, &dest); |
| 107478 | + goto multi_select_end; |
| 107479 | + } |
| 107271 | 107480 | |
| 107272 | 107481 | /* Make sure all SELECTs in the statement have the same number of elements |
| 107273 | 107482 | ** in their result sets. |
| 107274 | 107483 | */ |
| 107275 | 107484 | assert( p->pEList && pPrior->pEList ); |
| 107276 | 107485 | if( p->pEList->nExpr!=pPrior->pEList->nExpr ){ |
| 107277 | | - if( p->selFlags & SF_Values ){ |
| 107278 | | - sqlite3ErrorMsg(pParse, "all VALUES must have the same number of terms"); |
| 107279 | | - }else{ |
| 107280 | | - sqlite3ErrorMsg(pParse, "SELECTs to the left and right of %s" |
| 107281 | | - " do not have the same number of result columns", selectOpName(p->op)); |
| 107282 | | - } |
| 107486 | + selectWrongNumTermsError(pParse, p); |
| 107283 | 107487 | rc = 1; |
| 107284 | 107488 | goto multi_select_end; |
| 107285 | 107489 | } |
| 107286 | 107490 | |
| 107287 | 107491 | #ifndef SQLITE_OMIT_CTE |
| | @@ -109163,11 +109367,13 @@ |
| 109163 | 109367 | if( NEVER(p->pSrc==0) || (selFlags & SF_Expanded)!=0 ){ |
| 109164 | 109368 | return WRC_Prune; |
| 109165 | 109369 | } |
| 109166 | 109370 | pTabList = p->pSrc; |
| 109167 | 109371 | pEList = p->pEList; |
| 109168 | | - sqlite3WithPush(pParse, findRightmost(p)->pWith, 0); |
| 109372 | + if( pWalker->xSelectCallback2==selectPopWith ){ |
| 109373 | + sqlite3WithPush(pParse, findRightmost(p)->pWith, 0); |
| 109374 | + } |
| 109169 | 109375 | |
| 109170 | 109376 | /* Make sure cursor numbers have been assigned to all entries in |
| 109171 | 109377 | ** the FROM clause of the SELECT statement. |
| 109172 | 109378 | */ |
| 109173 | 109379 | sqlite3SrcListAssignCursors(pParse, pTabList); |
| | @@ -109454,11 +109660,13 @@ |
| 109454 | 109660 | if( pParse->hasCompound ){ |
| 109455 | 109661 | w.xSelectCallback = convertCompoundSelectToSubquery; |
| 109456 | 109662 | sqlite3WalkSelect(&w, pSelect); |
| 109457 | 109663 | } |
| 109458 | 109664 | w.xSelectCallback = selectExpander; |
| 109459 | | - w.xSelectCallback2 = selectPopWith; |
| 109665 | + if( (pSelect->selFlags & SF_AllValues)==0 ){ |
| 109666 | + w.xSelectCallback2 = selectPopWith; |
| 109667 | + } |
| 109460 | 109668 | sqlite3WalkSelect(&w, pSelect); |
| 109461 | 109669 | } |
| 109462 | 109670 | |
| 109463 | 109671 | |
| 109464 | 109672 | #ifndef SQLITE_OMIT_SUBQUERY |
| | @@ -110756,11 +110964,11 @@ |
| 110756 | 110964 | ){ |
| 110757 | 110965 | int rc; |
| 110758 | 110966 | TabResult res; |
| 110759 | 110967 | |
| 110760 | 110968 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 110761 | | - if( pazResult==0 ) return SQLITE_MISUSE_BKPT; |
| 110969 | + if( !sqlite3SafetyCheckOk(db) || pazResult==0 ) return SQLITE_MISUSE_BKPT; |
| 110762 | 110970 | #endif |
| 110763 | 110971 | *pazResult = 0; |
| 110764 | 110972 | if( pnColumn ) *pnColumn = 0; |
| 110765 | 110973 | if( pnRow ) *pnRow = 0; |
| 110766 | 110974 | if( pzErrMsg ) *pzErrMsg = 0; |
| | @@ -118626,11 +118834,10 @@ |
| 118626 | 118834 | sqlite3_free(p->u.vtab.idxStr); |
| 118627 | 118835 | p->u.vtab.needFree = 0; |
| 118628 | 118836 | p->u.vtab.idxStr = 0; |
| 118629 | 118837 | }else if( (p->wsFlags & WHERE_AUTO_INDEX)!=0 && p->u.btree.pIndex!=0 ){ |
| 118630 | 118838 | sqlite3DbFree(db, p->u.btree.pIndex->zColAff); |
| 118631 | | - sqlite3KeyInfoUnref(p->u.btree.pIndex->pKeyInfo); |
| 118632 | 118839 | sqlite3DbFree(db, p->u.btree.pIndex); |
| 118633 | 118840 | p->u.btree.pIndex = 0; |
| 118634 | 118841 | } |
| 118635 | 118842 | } |
| 118636 | 118843 | } |
| | @@ -123783,17 +123990,23 @@ |
| 123783 | 123990 | Select *p = yymsp[0].minor.yy3, *pNext, *pLoop; |
| 123784 | 123991 | if( p ){ |
| 123785 | 123992 | int cnt = 0, mxSelect; |
| 123786 | 123993 | p->pWith = yymsp[-1].minor.yy59; |
| 123787 | 123994 | if( p->pPrior ){ |
| 123995 | + u16 allValues = SF_Values; |
| 123788 | 123996 | pNext = 0; |
| 123789 | 123997 | for(pLoop=p; pLoop; pNext=pLoop, pLoop=pLoop->pPrior, cnt++){ |
| 123790 | 123998 | pLoop->pNext = pNext; |
| 123791 | 123999 | pLoop->selFlags |= SF_Compound; |
| 124000 | + allValues &= pLoop->selFlags; |
| 123792 | 124001 | } |
| 123793 | | - mxSelect = pParse->db->aLimit[SQLITE_LIMIT_COMPOUND_SELECT]; |
| 123794 | | - if( mxSelect && cnt>mxSelect ){ |
| 124002 | + if( allValues ){ |
| 124003 | + p->selFlags |= SF_AllValues; |
| 124004 | + }else if( |
| 124005 | + (mxSelect = pParse->db->aLimit[SQLITE_LIMIT_COMPOUND_SELECT])>0 |
| 124006 | + && cnt>mxSelect |
| 124007 | + ){ |
| 123795 | 124008 | sqlite3ErrorMsg(pParse, "too many terms in compound SELECT"); |
| 123796 | 124009 | } |
| 123797 | 124010 | } |
| 123798 | 124011 | }else{ |
| 123799 | 124012 | sqlite3WithDelete(pParse->db, yymsp[-1].minor.yy59); |
| | @@ -125633,10 +125846,13 @@ |
| 125633 | 125846 | u8 enableLookaside; /* Saved value of db->lookaside.bEnabled */ |
| 125634 | 125847 | sqlite3 *db = pParse->db; /* The database connection */ |
| 125635 | 125848 | int mxSqlLen; /* Max length of an SQL string */ |
| 125636 | 125849 | |
| 125637 | 125850 | |
| 125851 | +#ifdef SQLITE_ENABLE_API_ARMOR |
| 125852 | + if( zSql==0 || pzErrMsg==0 ) return SQLITE_MISUSE_BKPT; |
| 125853 | +#endif |
| 125638 | 125854 | mxSqlLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH]; |
| 125639 | 125855 | if( db->nVdbeActive==0 ){ |
| 125640 | 125856 | db->u1.isInterrupted = 0; |
| 125641 | 125857 | } |
| 125642 | 125858 | pParse->rc = SQLITE_OK; |
| | @@ -125871,17 +126087,10 @@ |
| 125871 | 126087 | */ |
| 125872 | 126088 | SQLITE_API int sqlite3_complete(const char *zSql){ |
| 125873 | 126089 | u8 state = 0; /* Current state, using numbers defined in header comment */ |
| 125874 | 126090 | u8 token; /* Value of the next token */ |
| 125875 | 126091 | |
| 125876 | | -#ifdef SQLITE_ENABLE_API_ARMOR |
| 125877 | | - if( zSql==0 ){ |
| 125878 | | - (void)SQLITE_MISUSE_BKPT; |
| 125879 | | - return 0; |
| 125880 | | - } |
| 125881 | | -#endif |
| 125882 | | - |
| 125883 | 126092 | #ifndef SQLITE_OMIT_TRIGGER |
| 125884 | 126093 | /* A complex statement machine used to detect the end of a CREATE TRIGGER |
| 125885 | 126094 | ** statement. This is the normal case. |
| 125886 | 126095 | */ |
| 125887 | 126096 | static const u8 trans[8][8] = { |
| | @@ -125906,10 +126115,17 @@ |
| 125906 | 126115 | /* 0 INVALID: */ { 1, 0, 2, }, |
| 125907 | 126116 | /* 1 START: */ { 1, 1, 2, }, |
| 125908 | 126117 | /* 2 NORMAL: */ { 1, 2, 2, }, |
| 125909 | 126118 | }; |
| 125910 | 126119 | #endif /* SQLITE_OMIT_TRIGGER */ |
| 126120 | + |
| 126121 | +#ifdef SQLITE_ENABLE_API_ARMOR |
| 126122 | + if( zSql==0 ){ |
| 126123 | + (void)SQLITE_MISUSE_BKPT; |
| 126124 | + return 0; |
| 126125 | + } |
| 126126 | +#endif |
| 125911 | 126127 | |
| 125912 | 126128 | while( *zSql ){ |
| 125913 | 126129 | switch( *zSql ){ |
| 125914 | 126130 | case ';': { /* A semicolon */ |
| 125915 | 126131 | token = tkSEMI; |
| | @@ -126208,11 +126424,11 @@ |
| 126208 | 126424 | ** If the following function pointer is not NULL and if |
| 126209 | 126425 | ** SQLITE_ENABLE_IOTRACE is enabled, then messages describing |
| 126210 | 126426 | ** I/O active are written using this function. These messages |
| 126211 | 126427 | ** are intended for debugging activity only. |
| 126212 | 126428 | */ |
| 126213 | | -SQLITE_PRIVATE void (*sqlite3IoTrace)(const char*, ...) = 0; |
| 126429 | +/* not-private */ void (*sqlite3IoTrace)(const char*, ...) = 0; |
| 126214 | 126430 | #endif |
| 126215 | 126431 | |
| 126216 | 126432 | /* |
| 126217 | 126433 | ** If the following global variable points to a string which is the |
| 126218 | 126434 | ** name of a directory, then that directory will be used to store |
| | @@ -126417,10 +126633,17 @@ |
| 126417 | 126633 | ** routine is not threadsafe. But it is safe to invoke this routine |
| 126418 | 126634 | ** on when SQLite is already shut down. If SQLite is already shut down |
| 126419 | 126635 | ** when this routine is invoked, then this routine is a harmless no-op. |
| 126420 | 126636 | */ |
| 126421 | 126637 | SQLITE_API int sqlite3_shutdown(void){ |
| 126638 | +#ifdef SQLITE_OMIT_WSD |
| 126639 | + int rc = sqlite3_wsd_init(4096, 24); |
| 126640 | + if( rc!=SQLITE_OK ){ |
| 126641 | + return rc; |
| 126642 | + } |
| 126643 | +#endif |
| 126644 | + |
| 126422 | 126645 | if( sqlite3GlobalConfig.isInit ){ |
| 126423 | 126646 | #ifdef SQLITE_EXTRA_SHUTDOWN |
| 126424 | 126647 | void SQLITE_EXTRA_SHUTDOWN(void); |
| 126425 | 126648 | SQLITE_EXTRA_SHUTDOWN(); |
| 126426 | 126649 | #endif |
| | @@ -126732,10 +126955,15 @@ |
| 126732 | 126955 | ** heap. */ |
| 126733 | 126956 | sqlite3GlobalConfig.nHeap = va_arg(ap, int); |
| 126734 | 126957 | break; |
| 126735 | 126958 | } |
| 126736 | 126959 | #endif |
| 126960 | + |
| 126961 | + case SQLITE_CONFIG_PMASZ: { |
| 126962 | + sqlite3GlobalConfig.szPma = va_arg(ap, unsigned int); |
| 126963 | + break; |
| 126964 | + } |
| 126737 | 126965 | |
| 126738 | 126966 | default: { |
| 126739 | 126967 | rc = SQLITE_ERROR; |
| 126740 | 126968 | break; |
| 126741 | 126969 | } |
| | @@ -127178,20 +127406,10 @@ |
| 127178 | 127406 | |
| 127179 | 127407 | /* Close all database connections */ |
| 127180 | 127408 | for(j=0; j<db->nDb; j++){ |
| 127181 | 127409 | struct Db *pDb = &db->aDb[j]; |
| 127182 | 127410 | 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 | 127411 | sqlite3BtreeClose(pDb->pBt); |
| 127194 | 127412 | pDb->pBt = 0; |
| 127195 | 127413 | if( j!=1 ){ |
| 127196 | 127414 | pDb->pSchema = 0; |
| 127197 | 127415 | } |
| | @@ -127494,11 +127712,11 @@ |
| 127494 | 127712 | */ |
| 127495 | 127713 | static int sqliteDefaultBusyCallback( |
| 127496 | 127714 | void *ptr, /* Database connection */ |
| 127497 | 127715 | int count /* Number of times table has been busy */ |
| 127498 | 127716 | ){ |
| 127499 | | -#if SQLITE_OS_WIN || (defined(HAVE_USLEEP) && HAVE_USLEEP) |
| 127717 | +#if SQLITE_OS_WIN || HAVE_USLEEP |
| 127500 | 127718 | static const u8 delays[] = |
| 127501 | 127719 | { 1, 2, 5, 10, 15, 20, 25, 25, 25, 50, 50, 100 }; |
| 127502 | 127720 | static const u8 totals[] = |
| 127503 | 127721 | { 0, 1, 3, 8, 18, 33, 53, 78, 103, 128, 178, 228 }; |
| 127504 | 127722 | # define NDELAY ArraySize(delays) |
| | @@ -128315,36 +128533,10 @@ |
| 128315 | 128533 | */ |
| 128316 | 128534 | SQLITE_API const char *sqlite3_errstr(int rc){ |
| 128317 | 128535 | return sqlite3ErrStr(rc); |
| 128318 | 128536 | } |
| 128319 | 128537 | |
| 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 | 128538 | /* |
| 128347 | 128539 | ** Create a new collating function for database "db". The name is zName |
| 128348 | 128540 | ** and the encoding is enc. |
| 128349 | 128541 | */ |
| 128350 | 128542 | static int createCollation( |
| | @@ -128384,11 +128576,10 @@ |
| 128384 | 128576 | sqlite3ErrorWithMsg(db, SQLITE_BUSY, |
| 128385 | 128577 | "unable to delete/modify collation sequence due to active statements"); |
| 128386 | 128578 | return SQLITE_BUSY; |
| 128387 | 128579 | } |
| 128388 | 128580 | sqlite3ExpirePreparedStatements(db); |
| 128389 | | - invalidateCachedKeyInfo(db); |
| 128390 | 128581 | |
| 128391 | 128582 | /* If collation sequence pColl was created directly by a call to |
| 128392 | 128583 | ** sqlite3_create_collation, and not generated by synthCollSeq(), |
| 128393 | 128584 | ** then any copies made by synthCollSeq() need to be invalidated. |
| 128394 | 128585 | ** Also, collation destructor - CollSeq.xDel() - function may need |
| | @@ -128941,10 +129132,11 @@ |
| 128941 | 129132 | sqlite3Error(db, rc); |
| 128942 | 129133 | goto opendb_out; |
| 128943 | 129134 | } |
| 128944 | 129135 | sqlite3BtreeEnter(db->aDb[0].pBt); |
| 128945 | 129136 | db->aDb[0].pSchema = sqlite3SchemaGet(db, db->aDb[0].pBt); |
| 129137 | + if( !db->mallocFailed ) ENC(db) = SCHEMA_ENC(db); |
| 128946 | 129138 | sqlite3BtreeLeave(db->aDb[0].pBt); |
| 128947 | 129139 | db->aDb[1].pSchema = sqlite3SchemaGet(db, 0); |
| 128948 | 129140 | |
| 128949 | 129141 | /* The default safety_level for the main database is 'full'; for the temp |
| 128950 | 129142 | ** database it is 'NONE'. This matches the pager layer defaults. |
| | @@ -129099,11 +129291,11 @@ |
| 129099 | 129291 | if( zFilename8 ){ |
| 129100 | 129292 | rc = openDatabase(zFilename8, ppDb, |
| 129101 | 129293 | SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, 0); |
| 129102 | 129294 | assert( *ppDb || rc==SQLITE_NOMEM ); |
| 129103 | 129295 | if( rc==SQLITE_OK && !DbHasProperty(*ppDb, 0, DB_SchemaLoaded) ){ |
| 129104 | | - ENC(*ppDb) = SQLITE_UTF16NATIVE; |
| 129296 | + SCHEMA_ENC(*ppDb) = ENC(*ppDb) = SQLITE_UTF16NATIVE; |
| 129105 | 129297 | } |
| 129106 | 129298 | }else{ |
| 129107 | 129299 | rc = SQLITE_NOMEM; |
| 129108 | 129300 | } |
| 129109 | 129301 | sqlite3ValueFree(pVal); |
| | @@ -129310,11 +129502,11 @@ |
| 129310 | 129502 | ){ |
| 129311 | 129503 | int rc; |
| 129312 | 129504 | char *zErrMsg = 0; |
| 129313 | 129505 | Table *pTab = 0; |
| 129314 | 129506 | Column *pCol = 0; |
| 129315 | | - int iCol; |
| 129507 | + int iCol = 0; |
| 129316 | 129508 | |
| 129317 | 129509 | char const *zDataType = 0; |
| 129318 | 129510 | char const *zCollSeq = 0; |
| 129319 | 129511 | int notnull = 0; |
| 129320 | 129512 | int primarykey = 0; |
| | @@ -129841,32 +130033,34 @@ |
| 129841 | 130033 | /* |
| 129842 | 130034 | ** Return the filename of the database associated with a database |
| 129843 | 130035 | ** connection. |
| 129844 | 130036 | */ |
| 129845 | 130037 | SQLITE_API const char *sqlite3_db_filename(sqlite3 *db, const char *zDbName){ |
| 130038 | + Btree *pBt; |
| 129846 | 130039 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 129847 | 130040 | if( !sqlite3SafetyCheckOk(db) ){ |
| 129848 | 130041 | (void)SQLITE_MISUSE_BKPT; |
| 129849 | 130042 | return 0; |
| 129850 | 130043 | } |
| 129851 | 130044 | #endif |
| 129852 | | - Btree *pBt = sqlite3DbNameToBtree(db, zDbName); |
| 130045 | + pBt = sqlite3DbNameToBtree(db, zDbName); |
| 129853 | 130046 | return pBt ? sqlite3BtreeGetFilename(pBt) : 0; |
| 129854 | 130047 | } |
| 129855 | 130048 | |
| 129856 | 130049 | /* |
| 129857 | 130050 | ** Return 1 if database is read-only or 0 if read/write. Return -1 if |
| 129858 | 130051 | ** no such database exists. |
| 129859 | 130052 | */ |
| 129860 | 130053 | SQLITE_API int sqlite3_db_readonly(sqlite3 *db, const char *zDbName){ |
| 130054 | + Btree *pBt; |
| 129861 | 130055 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 129862 | 130056 | if( !sqlite3SafetyCheckOk(db) ){ |
| 129863 | 130057 | (void)SQLITE_MISUSE_BKPT; |
| 129864 | 130058 | return -1; |
| 129865 | 130059 | } |
| 129866 | 130060 | #endif |
| 129867 | | - Btree *pBt = sqlite3DbNameToBtree(db, zDbName); |
| 130061 | + pBt = sqlite3DbNameToBtree(db, zDbName); |
| 129868 | 130062 | return pBt ? sqlite3BtreeIsReadonly(pBt) : -1; |
| 129869 | 130063 | } |
| 129870 | 130064 | |
| 129871 | 130065 | /************** End of main.c ************************************************/ |
| 129872 | 130066 | /************** Begin file notify.c ******************************************/ |
| | @@ -132931,11 +133125,11 @@ |
| 132931 | 133125 | const char *zNode, /* Buffer containing segment interior node */ |
| 132932 | 133126 | int nNode, /* Size of buffer at zNode */ |
| 132933 | 133127 | sqlite3_int64 *piLeaf, /* Selected leaf node */ |
| 132934 | 133128 | sqlite3_int64 *piLeaf2 /* Selected leaf node */ |
| 132935 | 133129 | ){ |
| 132936 | | - int rc; /* Return code */ |
| 133130 | + int rc = SQLITE_OK; /* Return code */ |
| 132937 | 133131 | int iHeight; /* Height of this node in tree */ |
| 132938 | 133132 | |
| 132939 | 133133 | assert( piLeaf || piLeaf2 ); |
| 132940 | 133134 | |
| 132941 | 133135 | fts3GetVarint32(zNode, &iHeight); |
| | @@ -132942,11 +133136,11 @@ |
| 132942 | 133136 | rc = fts3ScanInteriorNode(zTerm, nTerm, zNode, nNode, piLeaf, piLeaf2); |
| 132943 | 133137 | assert( !piLeaf2 || !piLeaf || rc!=SQLITE_OK || (*piLeaf<=*piLeaf2) ); |
| 132944 | 133138 | |
| 132945 | 133139 | if( rc==SQLITE_OK && iHeight>1 ){ |
| 132946 | 133140 | char *zBlob = 0; /* Blob read from %_segments table */ |
| 132947 | | - int nBlob; /* Size of zBlob in bytes */ |
| 133141 | + int nBlob = 0; /* Size of zBlob in bytes */ |
| 132948 | 133142 | |
| 132949 | 133143 | if( piLeaf && piLeaf2 && (*piLeaf!=*piLeaf2) ){ |
| 132950 | 133144 | rc = sqlite3Fts3ReadBlock(p, *piLeaf, &zBlob, &nBlob, 0); |
| 132951 | 133145 | if( rc==SQLITE_OK ){ |
| 132952 | 133146 | rc = fts3SelectLeaf(p, zTerm, nTerm, zBlob, nBlob, piLeaf, 0); |
| | @@ -134164,11 +134358,11 @@ |
| 134164 | 134358 | int idxNum, /* Strategy index */ |
| 134165 | 134359 | const char *idxStr, /* Unused */ |
| 134166 | 134360 | int nVal, /* Number of elements in apVal */ |
| 134167 | 134361 | sqlite3_value **apVal /* Arguments for the indexing scheme */ |
| 134168 | 134362 | ){ |
| 134169 | | - int rc; |
| 134363 | + int rc = SQLITE_OK; |
| 134170 | 134364 | char *zSql; /* SQL statement used to access %_content */ |
| 134171 | 134365 | int eSearch; |
| 134172 | 134366 | Fts3Table *p = (Fts3Table *)pCursor->pVtab; |
| 134173 | 134367 | Fts3Cursor *pCsr = (Fts3Cursor *)pCursor; |
| 134174 | 134368 | |
| | @@ -140652,11 +140846,11 @@ |
| 140652 | 140846 | int argc, /* Number of elements in argv array */ |
| 140653 | 140847 | const char * const *argv, /* xCreate/xConnect argument array */ |
| 140654 | 140848 | sqlite3_vtab **ppVtab, /* OUT: New sqlite3_vtab object */ |
| 140655 | 140849 | char **pzErr /* OUT: sqlite3_malloc'd error message */ |
| 140656 | 140850 | ){ |
| 140657 | | - Fts3tokTable *pTab; |
| 140851 | + Fts3tokTable *pTab = 0; |
| 140658 | 140852 | const sqlite3_tokenizer_module *pMod = 0; |
| 140659 | 140853 | sqlite3_tokenizer *pTok = 0; |
| 140660 | 140854 | int rc; |
| 140661 | 140855 | char **azDequote = 0; |
| 140662 | 140856 | int nDequote; |
| | @@ -144027,12 +144221,12 @@ |
| 144027 | 144221 | } |
| 144028 | 144222 | rc = sqlite3_reset(pRange); |
| 144029 | 144223 | |
| 144030 | 144224 | if( bOk ){ |
| 144031 | 144225 | int iIdx = 0; |
| 144032 | | - sqlite3_stmt *pUpdate1; |
| 144033 | | - sqlite3_stmt *pUpdate2; |
| 144226 | + sqlite3_stmt *pUpdate1 = 0; |
| 144227 | + sqlite3_stmt *pUpdate2 = 0; |
| 144034 | 144228 | |
| 144035 | 144229 | if( rc==SQLITE_OK ){ |
| 144036 | 144230 | rc = fts3SqlStmt(p, SQL_UPDATE_LEVEL_IDX, &pUpdate1, 0); |
| 144037 | 144231 | } |
| 144038 | 144232 | if( rc==SQLITE_OK ){ |
| | @@ -150073,11 +150267,11 @@ |
| 150073 | 150267 | } |
| 150074 | 150268 | i = pCur->nPoint++; |
| 150075 | 150269 | pNew = pCur->aPoint + i; |
| 150076 | 150270 | pNew->rScore = rScore; |
| 150077 | 150271 | pNew->iLevel = iLevel; |
| 150078 | | - assert( iLevel>=0 && iLevel<=RTREE_MAX_DEPTH ); |
| 150272 | + assert( iLevel<=RTREE_MAX_DEPTH ); |
| 150079 | 150273 | while( i>0 ){ |
| 150080 | 150274 | RtreeSearchPoint *pParent; |
| 150081 | 150275 | j = (i-1)/2; |
| 150082 | 150276 | pParent = pCur->aPoint + j; |
| 150083 | 150277 | if( rtreeSearchPointCompare(pNew, pParent)>=0 ) break; |
| | @@ -151696,10 +151890,12 @@ |
| 151696 | 151890 | RtreeCell cell; /* New cell to insert if nData>1 */ |
| 151697 | 151891 | int bHaveRowid = 0; /* Set to 1 after new rowid is determined */ |
| 151698 | 151892 | |
| 151699 | 151893 | rtreeReference(pRtree); |
| 151700 | 151894 | assert(nData>=1); |
| 151895 | + |
| 151896 | + cell.iRowid = 0; /* Used only to suppress a compiler warning */ |
| 151701 | 151897 | |
| 151702 | 151898 | /* Constraint handling. A write operation on an r-tree table may return |
| 151703 | 151899 | ** SQLITE_CONSTRAINT for two reasons: |
| 151704 | 151900 | ** |
| 151705 | 151901 | ** 1. A duplicate rowid value, or |
| 151706 | 151902 | |