Fossil SCM
Update the built-in SQLite to the latest 3.8.8 alpha.
Commit
5e598cec4426392869b7dc09ef74447fdf4b1868
Parent
8a5c394ba4c5da8…
2 files changed
+263
-156
+121
-97
+263
-156
| --- src/sqlite3.c | ||
| +++ src/sqlite3.c | ||
| @@ -231,11 +231,11 @@ | ||
| 231 | 231 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 232 | 232 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 233 | 233 | */ |
| 234 | 234 | #define SQLITE_VERSION "3.8.8" |
| 235 | 235 | #define SQLITE_VERSION_NUMBER 3008008 |
| 236 | -#define SQLITE_SOURCE_ID "2014-11-28 13:35:03 24fa2e9832daaa5d68ee28a00c56c55f97a4da9e" | |
| 236 | +#define SQLITE_SOURCE_ID "2014-12-06 14:56:49 6aeece19a235344be2537e66a3fe08b1febfb5a0" | |
| 237 | 237 | |
| 238 | 238 | /* |
| 239 | 239 | ** CAPI3REF: Run-Time Library Version Numbers |
| 240 | 240 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 241 | 241 | ** |
| @@ -1343,11 +1343,11 @@ | ||
| 1343 | 1343 | ** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_SHARED |
| 1344 | 1344 | ** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_EXCLUSIVE |
| 1345 | 1345 | ** </ul> |
| 1346 | 1346 | ** |
| 1347 | 1347 | ** When unlocking, the same SHARED or EXCLUSIVE flag must be supplied as |
| 1348 | -** was given no the corresponding lock. | |
| 1348 | +** was given on the corresponding lock. | |
| 1349 | 1349 | ** |
| 1350 | 1350 | ** The xShmLock method can transition between unlocked and SHARED or |
| 1351 | 1351 | ** between unlocked and EXCLUSIVE. It cannot transition between SHARED |
| 1352 | 1352 | ** and EXCLUSIVE. |
| 1353 | 1353 | */ |
| @@ -1646,12 +1646,12 @@ | ||
| 1646 | 1646 | ** tracks memory usage, for example. </dd> |
| 1647 | 1647 | ** |
| 1648 | 1648 | ** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt> |
| 1649 | 1649 | ** <dd> ^The SQLITE_CONFIG_MEMSTATUS option takes single argument of type int, |
| 1650 | 1650 | ** interpreted as a boolean, which enables or disables the collection of |
| 1651 | -** memory allocation statistics. ^(When memory allocation statistics are disabled, the | |
| 1652 | -** following SQLite interfaces become non-operational: | |
| 1651 | +** memory allocation statistics. ^(When memory allocation statistics are | |
| 1652 | +** disabled, the following SQLite interfaces become non-operational: | |
| 1653 | 1653 | ** <ul> |
| 1654 | 1654 | ** <li> [sqlite3_memory_used()] |
| 1655 | 1655 | ** <li> [sqlite3_memory_highwater()] |
| 1656 | 1656 | ** <li> [sqlite3_soft_heap_limit64()] |
| 1657 | 1657 | ** <li> [sqlite3_status()] |
| @@ -1688,11 +1688,12 @@ | ||
| 1688 | 1688 | ** that SQLite can use for the database page cache with the default page |
| 1689 | 1689 | ** cache implementation. |
| 1690 | 1690 | ** This configuration should not be used if an application-define page |
| 1691 | 1691 | ** cache implementation is loaded using the [SQLITE_CONFIG_PCACHE2] |
| 1692 | 1692 | ** configuration option. |
| 1693 | -** ^There are three arguments to SQLITE_CONFIG_PAGECACHE: A pointer to 8-byte aligned | |
| 1693 | +** ^There are three arguments to SQLITE_CONFIG_PAGECACHE: A pointer to | |
| 1694 | +** 8-byte aligned | |
| 1694 | 1695 | ** memory, the size of each page buffer (sz), and the number of pages (N). |
| 1695 | 1696 | ** The sz argument should be the size of the largest database page |
| 1696 | 1697 | ** (a power of two between 512 and 32768) plus some extra bytes for each |
| 1697 | 1698 | ** page header. ^The number of extra bytes needed by the page header |
| 1698 | 1699 | ** can be determined using the [SQLITE_CONFIG_PCACHE_HDRSZ] option |
| @@ -1708,11 +1709,12 @@ | ||
| 1708 | 1709 | ** SQLite goes to [sqlite3_malloc()] for the additional storage space.</dd> |
| 1709 | 1710 | ** |
| 1710 | 1711 | ** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt> |
| 1711 | 1712 | ** <dd> ^The SQLITE_CONFIG_HEAP option specifies a static memory buffer |
| 1712 | 1713 | ** that SQLite will use for all of its dynamic memory allocation needs |
| 1713 | -** beyond those provided for by [SQLITE_CONFIG_SCRATCH] and [SQLITE_CONFIG_PAGECACHE]. | |
| 1714 | +** beyond those provided for by [SQLITE_CONFIG_SCRATCH] and | |
| 1715 | +** [SQLITE_CONFIG_PAGECACHE]. | |
| 1714 | 1716 | ** ^The SQLITE_CONFIG_HEAP option is only available if SQLite is compiled |
| 1715 | 1717 | ** with either [SQLITE_ENABLE_MEMSYS3] or [SQLITE_ENABLE_MEMSYS5] and returns |
| 1716 | 1718 | ** [SQLITE_ERROR] if invoked otherwise. |
| 1717 | 1719 | ** ^There are three arguments to SQLITE_CONFIG_HEAP: |
| 1718 | 1720 | ** An 8-byte aligned pointer to the memory, |
| @@ -1728,13 +1730,13 @@ | ||
| 1728 | 1730 | ** for the minimum allocation size are 2**5 through 2**8.</dd> |
| 1729 | 1731 | ** |
| 1730 | 1732 | ** [[SQLITE_CONFIG_MUTEX]] <dt>SQLITE_CONFIG_MUTEX</dt> |
| 1731 | 1733 | ** <dd> ^(The SQLITE_CONFIG_MUTEX option takes a single argument which is a |
| 1732 | 1734 | ** pointer to an instance of the [sqlite3_mutex_methods] structure. |
| 1733 | -** The argument specifies alternative low-level mutex routines to be used in place | |
| 1734 | -** the mutex routines built into SQLite.)^ ^SQLite makes a copy of the | |
| 1735 | -** content of the [sqlite3_mutex_methods] structure before the call to | |
| 1735 | +** The argument specifies alternative low-level mutex routines to be used | |
| 1736 | +** in place the mutex routines built into SQLite.)^ ^SQLite makes a copy of | |
| 1737 | +** the content of the [sqlite3_mutex_methods] structure before the call to | |
| 1736 | 1738 | ** [sqlite3_config()] returns. ^If SQLite is compiled with |
| 1737 | 1739 | ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then |
| 1738 | 1740 | ** the entire mutexing subsystem is omitted from the build and hence calls to |
| 1739 | 1741 | ** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will |
| 1740 | 1742 | ** return [SQLITE_ERROR].</dd> |
| @@ -1768,12 +1770,12 @@ | ||
| 1768 | 1770 | ** the interface to a custom page cache implementation.)^ |
| 1769 | 1771 | ** ^SQLite makes a copy of the [sqlite3_pcache_methods2] object.</dd> |
| 1770 | 1772 | ** |
| 1771 | 1773 | ** [[SQLITE_CONFIG_GETPCACHE2]] <dt>SQLITE_CONFIG_GETPCACHE2</dt> |
| 1772 | 1774 | ** <dd> ^(The SQLITE_CONFIG_GETPCACHE2 option takes a single argument which |
| 1773 | -** is a pointer to an [sqlite3_pcache_methods2] object. SQLite copies of the current | |
| 1774 | -** page cache implementation into that object.)^ </dd> | |
| 1775 | +** is a pointer to an [sqlite3_pcache_methods2] object. SQLite copies of | |
| 1776 | +** the current page cache implementation into that object.)^ </dd> | |
| 1775 | 1777 | ** |
| 1776 | 1778 | ** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt> |
| 1777 | 1779 | ** <dd> The SQLITE_CONFIG_LOG option is used to configure the SQLite |
| 1778 | 1780 | ** global [error log]. |
| 1779 | 1781 | ** (^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a |
| @@ -1794,12 +1796,13 @@ | ||
| 1794 | 1796 | ** function must be threadsafe. </dd> |
| 1795 | 1797 | ** |
| 1796 | 1798 | ** [[SQLITE_CONFIG_URI]] <dt>SQLITE_CONFIG_URI |
| 1797 | 1799 | ** <dd>^(The SQLITE_CONFIG_URI option takes a single argument of type int. |
| 1798 | 1800 | ** If non-zero, then URI handling is globally enabled. If the parameter is zero, |
| 1799 | -** then URI handling is globally disabled.)^ ^If URI handling is globally enabled, | |
| 1800 | -** all filenames passed to [sqlite3_open()], [sqlite3_open_v2()], [sqlite3_open16()] or | |
| 1801 | +** then URI handling is globally disabled.)^ ^If URI handling is globally | |
| 1802 | +** enabled, all filenames passed to [sqlite3_open()], [sqlite3_open_v2()], | |
| 1803 | +** [sqlite3_open16()] or | |
| 1801 | 1804 | ** specified as part of [ATTACH] commands are interpreted as URIs, regardless |
| 1802 | 1805 | ** of whether or not the [SQLITE_OPEN_URI] flag is set when the database |
| 1803 | 1806 | ** connection is opened. ^If it is globally disabled, filenames are |
| 1804 | 1807 | ** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the |
| 1805 | 1808 | ** database connection is opened. ^(By default, URI handling is globally |
| @@ -1857,21 +1860,21 @@ | ||
| 1857 | 1860 | ** changed to its compile-time default. |
| 1858 | 1861 | ** |
| 1859 | 1862 | ** [[SQLITE_CONFIG_WIN32_HEAPSIZE]] |
| 1860 | 1863 | ** <dt>SQLITE_CONFIG_WIN32_HEAPSIZE |
| 1861 | 1864 | ** <dd>^The SQLITE_CONFIG_WIN32_HEAPSIZE option is only available if SQLite is |
| 1862 | -** compiled for Windows with the [SQLITE_WIN32_MALLOC] pre-processor macro defined. | |
| 1863 | -** ^SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit unsigned integer value | |
| 1865 | +** compiled for Windows with the [SQLITE_WIN32_MALLOC] pre-processor macro | |
| 1866 | +** defined. ^SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit unsigned integer value | |
| 1864 | 1867 | ** that specifies the maximum size of the created heap. |
| 1865 | 1868 | ** </dl> |
| 1866 | 1869 | ** |
| 1867 | 1870 | ** [[SQLITE_CONFIG_PCACHE_HDRSZ]] |
| 1868 | 1871 | ** <dt>SQLITE_CONFIG_PCACHE_HDRSZ |
| 1869 | 1872 | ** <dd>^The SQLITE_CONFIG_PCACHE_HDRSZ option takes a single parameter which |
| 1870 | 1873 | ** is a pointer to an integer and writes into that integer the number of extra |
| 1871 | -** bytes per page required for each page in [SQLITE_CONFIG_PAGECACHE]. The amount of | |
| 1872 | -** extra space required can change depending on the compiler, | |
| 1874 | +** bytes per page required for each page in [SQLITE_CONFIG_PAGECACHE]. | |
| 1875 | +** The amount of extra space required can change depending on the compiler, | |
| 1873 | 1876 | ** target platform, and SQLite version. |
| 1874 | 1877 | ** </dl> |
| 1875 | 1878 | */ |
| 1876 | 1879 | #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */ |
| 1877 | 1880 | #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */ |
| @@ -2171,10 +2174,11 @@ | ||
| 2171 | 2174 | SQLITE_API int sqlite3_complete(const char *sql); |
| 2172 | 2175 | SQLITE_API int sqlite3_complete16(const void *sql); |
| 2173 | 2176 | |
| 2174 | 2177 | /* |
| 2175 | 2178 | ** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors |
| 2179 | +** KEYWORDS: {busy-handler callback} {busy handler} | |
| 2176 | 2180 | ** |
| 2177 | 2181 | ** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X |
| 2178 | 2182 | ** that might be invoked with argument P whenever |
| 2179 | 2183 | ** an attempt is made to access a database table associated with |
| 2180 | 2184 | ** [database connection] D when another thread |
| @@ -2187,11 +2191,11 @@ | ||
| 2187 | 2191 | ** is not NULL, then the callback might be invoked with two arguments. |
| 2188 | 2192 | ** |
| 2189 | 2193 | ** ^The first argument to the busy handler is a copy of the void* pointer which |
| 2190 | 2194 | ** is the third argument to sqlite3_busy_handler(). ^The second argument to |
| 2191 | 2195 | ** the busy handler callback is the number of times that the busy handler has |
| 2192 | -** been invoked for the same locking event. ^If the | |
| 2196 | +** been invoked previously for the same locking event. ^If the | |
| 2193 | 2197 | ** busy callback returns 0, then no additional attempts are made to |
| 2194 | 2198 | ** access the database and [SQLITE_BUSY] is returned |
| 2195 | 2199 | ** to the application. |
| 2196 | 2200 | ** ^If the callback returns non-zero, then another attempt |
| 2197 | 2201 | ** is made to access the database and the cycle repeats. |
| @@ -4642,11 +4646,12 @@ | ||
| 4642 | 4646 | ** If these routines are called from within the different thread |
| 4643 | 4647 | ** than the one containing the application-defined function that received |
| 4644 | 4648 | ** the [sqlite3_context] pointer, the results are undefined. |
| 4645 | 4649 | */ |
| 4646 | 4650 | SQLITE_API void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*)); |
| 4647 | -SQLITE_API void sqlite3_result_blob64(sqlite3_context*,const void*,sqlite3_uint64,void(*)(void*)); | |
| 4651 | +SQLITE_API void sqlite3_result_blob64(sqlite3_context*,const void*, | |
| 4652 | + sqlite3_uint64,void(*)(void*)); | |
| 4648 | 4653 | SQLITE_API void sqlite3_result_double(sqlite3_context*, double); |
| 4649 | 4654 | SQLITE_API void sqlite3_result_error(sqlite3_context*, const char*, int); |
| 4650 | 4655 | SQLITE_API void sqlite3_result_error16(sqlite3_context*, const void*, int); |
| 4651 | 4656 | SQLITE_API void sqlite3_result_error_toobig(sqlite3_context*); |
| 4652 | 4657 | SQLITE_API void sqlite3_result_error_nomem(sqlite3_context*); |
| @@ -7368,101 +7373,118 @@ | ||
| 7368 | 7373 | SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int N); |
| 7369 | 7374 | |
| 7370 | 7375 | /* |
| 7371 | 7376 | ** CAPI3REF: Checkpoint a database |
| 7372 | 7377 | ** |
| 7373 | -** ^The [sqlite3_wal_checkpoint(D,X)] interface causes database named X | |
| 7374 | -** on [database connection] D to be [checkpointed]. ^If X is NULL or an | |
| 7375 | -** empty string, then a checkpoint is run on all databases of | |
| 7376 | -** connection D. ^If the database connection D is not in | |
| 7377 | -** [WAL | write-ahead log mode] then this interface is a harmless no-op. | |
| 7378 | -** ^The [sqlite3_wal_checkpoint(D,X)] interface initiates a | |
| 7379 | -** [sqlite3_wal_checkpoint_v2|PASSIVE] checkpoint. | |
| 7380 | -** Use the [sqlite3_wal_checkpoint_v2()] interface to get a FULL | |
| 7381 | -** or RESET checkpoint. | |
| 7382 | -** | |
| 7383 | -** ^The [wal_checkpoint pragma] can be used to invoke this interface | |
| 7384 | -** from SQL. ^The [sqlite3_wal_autocheckpoint()] interface and the | |
| 7385 | -** [wal_autocheckpoint pragma] can be used to cause this interface to be | |
| 7386 | -** run whenever the WAL reaches a certain size threshold. | |
| 7387 | -** | |
| 7388 | -** See also: [sqlite3_wal_checkpoint_v2()] | |
| 7378 | +** ^(The sqlite3_wal_checkpoint(D,X) is equivalent to | |
| 7379 | +** [sqlite3_wal_checkpoint_v2](D,X,[SQLITE_CHECKPOINT_PASSIVE],0,0).)^ | |
| 7380 | +** | |
| 7381 | +** In brief, sqlite3_wal_checkpoint(D,X) causes the content in the | |
| 7382 | +** [write-ahead log] for database X on [database connection] D to be | |
| 7383 | +** transferred into the database file and for the write-ahead log to | |
| 7384 | +** be reset. See the [checkpointing] documentation for addition | |
| 7385 | +** information. | |
| 7386 | +** | |
| 7387 | +** This interface used to be the only way to cause a checkpoint to | |
| 7388 | +** occur. But then the newer and more powerful [sqlite3_wal_checkpoint_v2()] | |
| 7389 | +** interface was added. This interface is retained for backwards | |
| 7390 | +** compatibility and as a convenience for applications that need to manually | |
| 7391 | +** start a callback but which do not need the full power (and corresponding | |
| 7392 | +** complication) of [sqlite3_wal_checkpoint_v2()]. | |
| 7389 | 7393 | */ |
| 7390 | 7394 | SQLITE_API int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb); |
| 7391 | 7395 | |
| 7392 | 7396 | /* |
| 7393 | 7397 | ** CAPI3REF: Checkpoint a database |
| 7394 | 7398 | ** |
| 7395 | -** Run a checkpoint operation on WAL database zDb attached to database | |
| 7396 | -** handle db. The specific operation is determined by the value of the | |
| 7397 | -** eMode parameter: | |
| 7399 | +** ^(The sqlite3_wal_checkpoint_v2(D,X,M,L,C) interface runs a checkpoint | |
| 7400 | +** operation on database X of [database connection] D in mode M. Status | |
| 7401 | +** information is written back into integers pointed to by L and C.)^ | |
| 7402 | +** ^(The M parameter must be a valid [checkpoint mode]:)^ | |
| 7398 | 7403 | ** |
| 7399 | 7404 | ** <dl> |
| 7400 | 7405 | ** <dt>SQLITE_CHECKPOINT_PASSIVE<dd> |
| 7401 | -** Checkpoint as many frames as possible without waiting for any database | |
| 7402 | -** readers or writers to finish. Sync the db file if all frames in the log | |
| 7403 | -** are checkpointed. This mode is the same as calling | |
| 7404 | -** sqlite3_wal_checkpoint(). The [sqlite3_busy_handler|busy-handler callback] | |
| 7405 | -** is never invoked. | |
| 7406 | +** ^Checkpoint as many frames as possible without waiting for any database | |
| 7407 | +** readers or writers to finish, then sync the database file if all frames | |
| 7408 | +** in the log were checkpointed. ^The [busy-handler callback] | |
| 7409 | +** is never invoked in the SQLITE_CHECKPOINT_PASSIVE mode. | |
| 7410 | +** ^On the other hand, passive mode might leave the checkpoint unfinished | |
| 7411 | +** if there are concurrent readers or writers. | |
| 7406 | 7412 | ** |
| 7407 | 7413 | ** <dt>SQLITE_CHECKPOINT_FULL<dd> |
| 7408 | -** This mode blocks (it invokes the | |
| 7414 | +** ^This mode blocks (it invokes the | |
| 7409 | 7415 | ** [sqlite3_busy_handler|busy-handler callback]) until there is no |
| 7410 | 7416 | ** database writer and all readers are reading from the most recent database |
| 7411 | -** snapshot. It then checkpoints all frames in the log file and syncs the | |
| 7412 | -** database file. This call blocks database writers while it is running, | |
| 7413 | -** but not database readers. | |
| 7417 | +** snapshot. ^It then checkpoints all frames in the log file and syncs the | |
| 7418 | +** database file. ^This mode blocks new database writers while it is pending, | |
| 7419 | +** but new database readers are allowed to continue unimpeded. | |
| 7414 | 7420 | ** |
| 7415 | 7421 | ** <dt>SQLITE_CHECKPOINT_RESTART<dd> |
| 7416 | -** This mode works the same way as SQLITE_CHECKPOINT_FULL, except after | |
| 7417 | -** checkpointing the log file it blocks (calls the | |
| 7418 | -** [sqlite3_busy_handler|busy-handler callback]) | |
| 7419 | -** until all readers are reading from the database file only. This ensures | |
| 7420 | -** that the next client to write to the database file restarts the log file | |
| 7421 | -** from the beginning. This call blocks database writers while it is running, | |
| 7422 | -** but not database readers. | |
| 7422 | +** ^This mode works the same way as SQLITE_CHECKPOINT_FULL with the addition | |
| 7423 | +** that after checkpointing the log file it blocks (calls the | |
| 7424 | +** [busy-handler callback]) | |
| 7425 | +** until all readers are reading from the database file only. ^This ensures | |
| 7426 | +** that the next writer will restart the log file from the beginning. | |
| 7427 | +** ^Like SQLITE_CHECKPOINT_FULL, this mode blocks new | |
| 7428 | +** database writer attempts while it is pending, but does not impede readers. | |
| 7429 | +** | |
| 7430 | +** <dt>SQLITE_CHECKPOINT_TRUNCATE<dd> | |
| 7431 | +** ^This mode works the same way as SQLITE_CHECKPOINT_RESTART with the | |
| 7432 | +** addition that it also truncates the log file to zero bytes just prior | |
| 7433 | +** to a successful return. | |
| 7423 | 7434 | ** </dl> |
| 7424 | 7435 | ** |
| 7425 | -** If pnLog is not NULL, then *pnLog is set to the total number of frames in | |
| 7426 | -** the log file before returning. If pnCkpt is not NULL, then *pnCkpt is set to | |
| 7427 | -** the total number of checkpointed frames (including any that were already | |
| 7428 | -** checkpointed when this function is called). *pnLog and *pnCkpt may be | |
| 7429 | -** populated even if sqlite3_wal_checkpoint_v2() returns other than SQLITE_OK. | |
| 7430 | -** If no values are available because of an error, they are both set to -1 | |
| 7431 | -** before returning to communicate this to the caller. | |
| 7436 | +** ^If pnLog is not NULL, then *pnLog is set to the total number of frames in | |
| 7437 | +** the log file or to -1 if the checkpoint could not run because | |
| 7438 | +** of an error or because the database is not in [WAL mode]. ^If pnCkpt is not | |
| 7439 | +** NULL,then *pnCkpt is set to the total number of checkpointed frames in the | |
| 7440 | +** log file (including any that were already checkpointed before the function | |
| 7441 | +** was called) or to -1 if the checkpoint could not run due to an error or | |
| 7442 | +** because the database is not in WAL mode. ^Note that upon successful | |
| 7443 | +** completion of an SQLITE_CHECKPOINT_TRUNCATE, the log file will have been | |
| 7444 | +** truncated to zero bytes and so both *pnLog and *pnCkpt will be set to zero. | |
| 7432 | 7445 | ** |
| 7433 | -** All calls obtain an exclusive "checkpoint" lock on the database file. If | |
| 7446 | +** ^All calls obtain an exclusive "checkpoint" lock on the database file. ^If | |
| 7434 | 7447 | ** any other process is running a checkpoint operation at the same time, the |
| 7435 | -** lock cannot be obtained and SQLITE_BUSY is returned. Even if there is a | |
| 7448 | +** lock cannot be obtained and SQLITE_BUSY is returned. ^Even if there is a | |
| 7436 | 7449 | ** busy-handler configured, it will not be invoked in this case. |
| 7437 | 7450 | ** |
| 7438 | -** The SQLITE_CHECKPOINT_FULL and RESTART modes also obtain the exclusive | |
| 7439 | -** "writer" lock on the database file. If the writer lock cannot be obtained | |
| 7440 | -** immediately, and a busy-handler is configured, it is invoked and the writer | |
| 7441 | -** lock retried until either the busy-handler returns 0 or the lock is | |
| 7442 | -** successfully obtained. The busy-handler is also invoked while waiting for | |
| 7443 | -** database readers as described above. If the busy-handler returns 0 before | |
| 7451 | +** ^The SQLITE_CHECKPOINT_FULL, RESTART and TRUNCATE modes also obtain the | |
| 7452 | +** exclusive "writer" lock on the database file. ^If the writer lock cannot be | |
| 7453 | +** obtained immediately, and a busy-handler is configured, it is invoked and | |
| 7454 | +** the writer lock retried until either the busy-handler returns 0 or the lock | |
| 7455 | +** is successfully obtained. ^The busy-handler is also invoked while waiting for | |
| 7456 | +** database readers as described above. ^If the busy-handler returns 0 before | |
| 7444 | 7457 | ** the writer lock is obtained or while waiting for database readers, the |
| 7445 | 7458 | ** checkpoint operation proceeds from that point in the same way as |
| 7446 | 7459 | ** SQLITE_CHECKPOINT_PASSIVE - checkpointing as many frames as possible |
| 7447 | -** without blocking any further. SQLITE_BUSY is returned in this case. | |
| 7460 | +** without blocking any further. ^SQLITE_BUSY is returned in this case. | |
| 7448 | 7461 | ** |
| 7449 | -** If parameter zDb is NULL or points to a zero length string, then the | |
| 7450 | -** specified operation is attempted on all WAL databases. In this case the | |
| 7451 | -** values written to output parameters *pnLog and *pnCkpt are undefined. If | |
| 7462 | +** ^If parameter zDb is NULL or points to a zero length string, then the | |
| 7463 | +** specified operation is attempted on all WAL databases [attached] to | |
| 7464 | +** [database connection] db. In this case the | |
| 7465 | +** values written to output parameters *pnLog and *pnCkpt are undefined. ^If | |
| 7452 | 7466 | ** an SQLITE_BUSY error is encountered when processing one or more of the |
| 7453 | 7467 | ** attached WAL databases, the operation is still attempted on any remaining |
| 7454 | -** attached databases and SQLITE_BUSY is returned to the caller. If any other | |
| 7468 | +** attached databases and SQLITE_BUSY is returned at the end. ^If any other | |
| 7455 | 7469 | ** error occurs while processing an attached database, processing is abandoned |
| 7456 | -** and the error code returned to the caller immediately. If no error | |
| 7470 | +** and the error code is returned to the caller immediately. ^If no error | |
| 7457 | 7471 | ** (SQLITE_BUSY or otherwise) is encountered while processing the attached |
| 7458 | 7472 | ** databases, SQLITE_OK is returned. |
| 7459 | 7473 | ** |
| 7460 | -** If database zDb is the name of an attached database that is not in WAL | |
| 7461 | -** mode, SQLITE_OK is returned and both *pnLog and *pnCkpt set to -1. If | |
| 7474 | +** ^If database zDb is the name of an attached database that is not in WAL | |
| 7475 | +** mode, SQLITE_OK is returned and both *pnLog and *pnCkpt set to -1. ^If | |
| 7462 | 7476 | ** zDb is not NULL (or a zero length string) and is not the name of any |
| 7463 | 7477 | ** attached database, SQLITE_ERROR is returned to the caller. |
| 7478 | +** | |
| 7479 | +** ^Unless it returns SQLITE_MISUSE, | |
| 7480 | +** the sqlite3_wal_checkpoint_v2() interface | |
| 7481 | +** sets the error information that is queried by | |
| 7482 | +** [sqlite3_errcode()] and [sqlite3_errmsg()]. | |
| 7483 | +** | |
| 7484 | +** ^The [PRAGMA wal_checkpoint] command can be used to invoke this interface | |
| 7485 | +** from SQL. | |
| 7464 | 7486 | */ |
| 7465 | 7487 | SQLITE_API int sqlite3_wal_checkpoint_v2( |
| 7466 | 7488 | sqlite3 *db, /* Database handle */ |
| 7467 | 7489 | const char *zDb, /* Name of attached database (or NULL) */ |
| 7468 | 7490 | int eMode, /* SQLITE_CHECKPOINT_* value */ |
| @@ -7469,20 +7491,22 @@ | ||
| 7469 | 7491 | int *pnLog, /* OUT: Size of WAL log in frames */ |
| 7470 | 7492 | int *pnCkpt /* OUT: Total number of frames checkpointed */ |
| 7471 | 7493 | ); |
| 7472 | 7494 | |
| 7473 | 7495 | /* |
| 7474 | -** CAPI3REF: Checkpoint operation parameters | |
| 7496 | +** CAPI3REF: Checkpoint Mode Values | |
| 7497 | +** KEYWORDS: {checkpoint mode} | |
| 7475 | 7498 | ** |
| 7476 | -** These constants can be used as the 3rd parameter to | |
| 7477 | -** [sqlite3_wal_checkpoint_v2()]. See the [sqlite3_wal_checkpoint_v2()] | |
| 7478 | -** documentation for additional information about the meaning and use of | |
| 7479 | -** each of these values. | |
| 7499 | +** These constants define all valid values for the "checkpoint mode" passed | |
| 7500 | +** as the third parameter to the [sqlite3_wal_checkpoint_v2()] interface. | |
| 7501 | +** See the [sqlite3_wal_checkpoint_v2()] documentation for details on the | |
| 7502 | +** meaning of each of these checkpoint modes. | |
| 7480 | 7503 | */ |
| 7481 | -#define SQLITE_CHECKPOINT_PASSIVE 0 | |
| 7482 | -#define SQLITE_CHECKPOINT_FULL 1 | |
| 7483 | -#define SQLITE_CHECKPOINT_RESTART 2 | |
| 7504 | +#define SQLITE_CHECKPOINT_PASSIVE 0 /* Do as much as possible w/o blocking */ | |
| 7505 | +#define SQLITE_CHECKPOINT_FULL 1 /* Wait for writers, then checkpoint */ | |
| 7506 | +#define SQLITE_CHECKPOINT_RESTART 2 /* Like FULL but wait for for readers */ | |
| 7507 | +#define SQLITE_CHECKPOINT_TRUNCATE 3 /* Like RESTART but also truncate WAL */ | |
| 7484 | 7508 | |
| 7485 | 7509 | /* |
| 7486 | 7510 | ** CAPI3REF: Virtual Table Interface Configuration |
| 7487 | 7511 | ** |
| 7488 | 7512 | ** This function may be called by either the [xConnect] or [xCreate] method |
| @@ -7577,16 +7601,16 @@ | ||
| 7577 | 7601 | ** [sqlite3_stmt_scanstatus(S,X,T,V)] interface. Each constant designates a |
| 7578 | 7602 | ** different metric for sqlite3_stmt_scanstatus() to return. |
| 7579 | 7603 | ** |
| 7580 | 7604 | ** <dl> |
| 7581 | 7605 | ** [[SQLITE_SCANSTAT_NLOOP]] <dt>SQLITE_SCANSTAT_NLOOP</dt> |
| 7582 | -** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be set to the | |
| 7583 | -** total number of times that the X-th loop has run.</dd> | |
| 7606 | +** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be | |
| 7607 | +** set to the total number of times that the X-th loop has run.</dd> | |
| 7584 | 7608 | ** |
| 7585 | 7609 | ** [[SQLITE_SCANSTAT_NVISIT]] <dt>SQLITE_SCANSTAT_NVISIT</dt> |
| 7586 | -** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be set to the | |
| 7587 | -** total number of rows examined by all iterations of the X-th loop.</dd> | |
| 7610 | +** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be set | |
| 7611 | +** to the total number of rows examined by all iterations of the X-th loop.</dd> | |
| 7588 | 7612 | ** |
| 7589 | 7613 | ** [[SQLITE_SCANSTAT_EST]] <dt>SQLITE_SCANSTAT_EST</dt> |
| 7590 | 7614 | ** <dd>^The "double" variable pointed to by the T parameter will be set to the |
| 7591 | 7615 | ** query planner's estimate for the average number of rows output from each |
| 7592 | 7616 | ** iteration of the X-th loop. If the query planner's estimates was accurate, |
| @@ -7593,18 +7617,18 @@ | ||
| 7593 | 7617 | ** then this value will approximate the quotient NVISIT/NLOOP and the |
| 7594 | 7618 | ** product of this value for all prior loops with the same SELECTID will |
| 7595 | 7619 | ** be the NLOOP value for the current loop. |
| 7596 | 7620 | ** |
| 7597 | 7621 | ** [[SQLITE_SCANSTAT_NAME]] <dt>SQLITE_SCANSTAT_NAME</dt> |
| 7598 | -** <dd>^The "const char *" variable pointed to by the T parameter will be set to | |
| 7599 | -** a zero-terminated UTF-8 string containing the name of the index or table used | |
| 7600 | -** for the X-th loop. | |
| 7622 | +** <dd>^The "const char *" variable pointed to by the T parameter will be set | |
| 7623 | +** to a zero-terminated UTF-8 string containing the name of the index or table | |
| 7624 | +** used for the X-th loop. | |
| 7601 | 7625 | ** |
| 7602 | 7626 | ** [[SQLITE_SCANSTAT_EXPLAIN]] <dt>SQLITE_SCANSTAT_EXPLAIN</dt> |
| 7603 | -** <dd>^The "const char *" variable pointed to by the T parameter will be set to | |
| 7604 | -** a zero-terminated UTF-8 string containing the [EXPLAIN QUERY PLAN] description | |
| 7605 | -** for the X-th loop. | |
| 7627 | +** <dd>^The "const char *" variable pointed to by the T parameter will be set | |
| 7628 | +** to a zero-terminated UTF-8 string containing the [EXPLAIN QUERY PLAN] | |
| 7629 | +** description for the X-th loop. | |
| 7606 | 7630 | ** |
| 7607 | 7631 | ** [[SQLITE_SCANSTAT_SELECTID]] <dt>SQLITE_SCANSTAT_SELECT</dt> |
| 7608 | 7632 | ** <dd>^The "int" variable pointed to by the T parameter will be set to the |
| 7609 | 7633 | ** "select-id" for the X-th loop. The select-id identifies which query or |
| 7610 | 7634 | ** subquery the loop is part of. The main query has a select-id of zero. |
| @@ -7623,12 +7647,12 @@ | ||
| 7623 | 7647 | ** CAPI3REF: Prepared Statement Scan Status |
| 7624 | 7648 | ** |
| 7625 | 7649 | ** Return status data for a single loop within query pStmt. |
| 7626 | 7650 | ** |
| 7627 | 7651 | ** The "iScanStatusOp" parameter determines which status information to return. |
| 7628 | -** The "iScanStatusOp" must be one of the [scanstatus options] or the behavior of | |
| 7629 | -** this interface is undefined. | |
| 7652 | +** The "iScanStatusOp" must be one of the [scanstatus options] or the behavior | |
| 7653 | +** of this interface is undefined. | |
| 7630 | 7654 | ** ^The requested measurement is written into a variable pointed to by |
| 7631 | 7655 | ** the "pOut" parameter. |
| 7632 | 7656 | ** Parameter "idx" identifies the specific loop to retrieve statistics for. |
| 7633 | 7657 | ** Loops are numbered starting from zero. ^If idx is out of range - less than |
| 7634 | 7658 | ** zero or greater than or equal to the total number of loops used to implement |
| @@ -11675,11 +11699,11 @@ | ||
| 11675 | 11699 | }; |
| 11676 | 11700 | |
| 11677 | 11701 | /* |
| 11678 | 11702 | ** The following are the meanings of bits in the Expr.flags field. |
| 11679 | 11703 | */ |
| 11680 | -#define EP_FromJoin 0x000001 /* Originated in ON or USING clause of a join */ | |
| 11704 | +#define EP_FromJoin 0x000001 /* Originates in ON/USING clause of outer join */ | |
| 11681 | 11705 | #define EP_Agg 0x000002 /* Contains one or more aggregate functions */ |
| 11682 | 11706 | #define EP_Resolved 0x000004 /* IDs have been resolved to COLUMNs */ |
| 11683 | 11707 | #define EP_Error 0x000008 /* Expression contains one or more errors */ |
| 11684 | 11708 | #define EP_Distinct 0x000010 /* Aggregate function with DISTINCT keyword */ |
| 11685 | 11709 | #define EP_VarSelect 0x000020 /* pSelect is correlated, not constant */ |
| @@ -11695,10 +11719,11 @@ | ||
| 11695 | 11719 | #define EP_Static 0x008000 /* Held in memory not obtained from malloc() */ |
| 11696 | 11720 | #define EP_MemToken 0x010000 /* Need to sqlite3DbFree() Expr.zToken */ |
| 11697 | 11721 | #define EP_NoReduce 0x020000 /* Cannot EXPRDUP_REDUCE this Expr */ |
| 11698 | 11722 | #define EP_Unlikely 0x040000 /* unlikely() or likelihood() function */ |
| 11699 | 11723 | #define EP_Constant 0x080000 /* Node is a constant */ |
| 11724 | +#define EP_CanBeNull 0x100000 /* Can be null despite NOT NULL constraint */ | |
| 11700 | 11725 | |
| 11701 | 11726 | /* |
| 11702 | 11727 | ** These macros can be used to test, set, or clear bits in the |
| 11703 | 11728 | ** Expr.flags field. |
| 11704 | 11729 | */ |
| @@ -48199,11 +48224,12 @@ | ||
| 48199 | 48224 | */ |
| 48200 | 48225 | SQLITE_PRIVATE int sqlite3PagerCheckpoint(Pager *pPager, int eMode, int *pnLog, int *pnCkpt){ |
| 48201 | 48226 | int rc = SQLITE_OK; |
| 48202 | 48227 | if( pPager->pWal ){ |
| 48203 | 48228 | rc = sqlite3WalCheckpoint(pPager->pWal, eMode, |
| 48204 | - pPager->xBusyHandler, pPager->pBusyHandlerArg, | |
| 48229 | + (eMode==SQLITE_CHECKPOINT_PASSIVE ? 0 : pPager->xBusyHandler), | |
| 48230 | + pPager->pBusyHandlerArg, | |
| 48205 | 48231 | pPager->ckptSyncFlags, pPager->pageSize, (u8 *)pPager->pTmpSpace, |
| 48206 | 48232 | pnLog, pnCkpt |
| 48207 | 48233 | ); |
| 48208 | 48234 | } |
| 48209 | 48235 | return rc; |
| @@ -50009,10 +50035,42 @@ | ||
| 50009 | 50035 | ** Return the page-size in bytes used by the database. |
| 50010 | 50036 | */ |
| 50011 | 50037 | static int walPagesize(Wal *pWal){ |
| 50012 | 50038 | return (pWal->hdr.szPage&0xfe00) + ((pWal->hdr.szPage&0x0001)<<16); |
| 50013 | 50039 | } |
| 50040 | + | |
| 50041 | +/* | |
| 50042 | +** The following is guaranteed when this function is called: | |
| 50043 | +** | |
| 50044 | +** a) the WRITER lock is held, | |
| 50045 | +** b) the entire log file has been checkpointed, and | |
| 50046 | +** c) any existing readers are reading exclusively from the database | |
| 50047 | +** file - there are no readers that may attempt to read a frame from | |
| 50048 | +** the log file. | |
| 50049 | +** | |
| 50050 | +** This function updates the shared-memory structures so that the next | |
| 50051 | +** client to write to the database (which may be this one) does so by | |
| 50052 | +** writing frames into the start of the log file. | |
| 50053 | +** | |
| 50054 | +** The value of parameter salt1 is used as the aSalt[1] value in the | |
| 50055 | +** new wal-index header. It should be passed a pseudo-random value (i.e. | |
| 50056 | +** one obtained from sqlite3_randomness()). | |
| 50057 | +*/ | |
| 50058 | +static void walRestartHdr(Wal *pWal, u32 salt1){ | |
| 50059 | + volatile WalCkptInfo *pInfo = walCkptInfo(pWal); | |
| 50060 | + int i; /* Loop counter */ | |
| 50061 | + u32 *aSalt = pWal->hdr.aSalt; /* Big-endian salt values */ | |
| 50062 | + pWal->nCkpt++; | |
| 50063 | + pWal->hdr.mxFrame = 0; | |
| 50064 | + sqlite3Put4byte((u8*)&aSalt[0], 1 + sqlite3Get4byte((u8*)&aSalt[0])); | |
| 50065 | + memcpy(&pWal->hdr.aSalt[1], &salt1, 4); | |
| 50066 | + walIndexWriteHdr(pWal); | |
| 50067 | + pInfo->nBackfill = 0; | |
| 50068 | + pInfo->aReadMark[1] = 0; | |
| 50069 | + for(i=2; i<WAL_NREADER; i++) pInfo->aReadMark[i] = READMARK_NOT_USED; | |
| 50070 | + assert( pInfo->aReadMark[0]==0 ); | |
| 50071 | +} | |
| 50014 | 50072 | |
| 50015 | 50073 | /* |
| 50016 | 50074 | ** Copy as much content as we can from the WAL back into the database file |
| 50017 | 50075 | ** in response to an sqlite3_wal_checkpoint() request or the equivalent. |
| 50018 | 50076 | ** |
| @@ -50044,11 +50102,11 @@ | ||
| 50044 | 50102 | ** time. |
| 50045 | 50103 | */ |
| 50046 | 50104 | static int walCheckpoint( |
| 50047 | 50105 | Wal *pWal, /* Wal connection */ |
| 50048 | 50106 | int eMode, /* One of PASSIVE, FULL or RESTART */ |
| 50049 | - int (*xBusyCall)(void*), /* Function to call when busy */ | |
| 50107 | + int (*xBusy)(void*), /* Function to call when busy */ | |
| 50050 | 50108 | void *pBusyArg, /* Context argument for xBusyHandler */ |
| 50051 | 50109 | int sync_flags, /* Flags for OsSync() (or 0) */ |
| 50052 | 50110 | u8 *zBuf /* Temporary buffer to use */ |
| 50053 | 50111 | ){ |
| 50054 | 50112 | int rc; /* Return code */ |
| @@ -50058,11 +50116,10 @@ | ||
| 50058 | 50116 | u32 iFrame = 0; /* Wal frame containing data for iDbpage */ |
| 50059 | 50117 | u32 mxSafeFrame; /* Max frame that can be backfilled */ |
| 50060 | 50118 | u32 mxPage; /* Max database page to write */ |
| 50061 | 50119 | int i; /* Loop counter */ |
| 50062 | 50120 | volatile WalCkptInfo *pInfo; /* The checkpoint status information */ |
| 50063 | - int (*xBusy)(void*) = 0; /* Function to call when waiting for locks */ | |
| 50064 | 50121 | |
| 50065 | 50122 | szPage = walPagesize(pWal); |
| 50066 | 50123 | testcase( szPage<=32768 ); |
| 50067 | 50124 | testcase( szPage>=65536 ); |
| 50068 | 50125 | pInfo = walCkptInfo(pWal); |
| @@ -50073,11 +50130,13 @@ | ||
| 50073 | 50130 | if( rc!=SQLITE_OK ){ |
| 50074 | 50131 | return rc; |
| 50075 | 50132 | } |
| 50076 | 50133 | assert( pIter ); |
| 50077 | 50134 | |
| 50078 | - if( eMode!=SQLITE_CHECKPOINT_PASSIVE ) xBusy = xBusyCall; | |
| 50135 | + /* EVIDENCE-OF: R-62920-47450 The busy-handler callback is never invoked | |
| 50136 | + ** in the SQLITE_CHECKPOINT_PASSIVE mode. */ | |
| 50137 | + assert( eMode!=SQLITE_CHECKPOINT_PASSIVE || xBusy==0 ); | |
| 50079 | 50138 | |
| 50080 | 50139 | /* Compute in mxSafeFrame the index of the last frame of the WAL that is |
| 50081 | 50140 | ** safe to write into the database. Frames beyond mxSafeFrame might |
| 50082 | 50141 | ** overwrite database pages that are in use by active readers and thus |
| 50083 | 50142 | ** cannot be backfilled from the WAL. |
| @@ -50162,23 +50221,42 @@ | ||
| 50162 | 50221 | /* Reset the return code so as not to report a checkpoint failure |
| 50163 | 50222 | ** just because there are active readers. */ |
| 50164 | 50223 | rc = SQLITE_OK; |
| 50165 | 50224 | } |
| 50166 | 50225 | |
| 50167 | - /* If this is an SQLITE_CHECKPOINT_RESTART operation, and the entire wal | |
| 50168 | - ** file has been copied into the database file, then block until all | |
| 50169 | - ** readers have finished using the wal file. This ensures that the next | |
| 50170 | - ** process to write to the database restarts the wal file. | |
| 50226 | + /* If this is an SQLITE_CHECKPOINT_RESTART or TRUNCATE operation, and the | |
| 50227 | + ** entire wal file has been copied into the database file, then block | |
| 50228 | + ** until all readers have finished using the wal file. This ensures that | |
| 50229 | + ** the next process to write to the database restarts the wal file. | |
| 50171 | 50230 | */ |
| 50172 | 50231 | if( rc==SQLITE_OK && eMode!=SQLITE_CHECKPOINT_PASSIVE ){ |
| 50173 | 50232 | assert( pWal->writeLock ); |
| 50174 | 50233 | if( pInfo->nBackfill<pWal->hdr.mxFrame ){ |
| 50175 | 50234 | rc = SQLITE_BUSY; |
| 50176 | - }else if( eMode==SQLITE_CHECKPOINT_RESTART ){ | |
| 50235 | + }else if( eMode>=SQLITE_CHECKPOINT_RESTART ){ | |
| 50236 | + u32 salt1; | |
| 50237 | + sqlite3_randomness(4, &salt1); | |
| 50177 | 50238 | assert( mxSafeFrame==pWal->hdr.mxFrame ); |
| 50178 | 50239 | rc = walBusyLock(pWal, xBusy, pBusyArg, WAL_READ_LOCK(1), WAL_NREADER-1); |
| 50179 | 50240 | if( rc==SQLITE_OK ){ |
| 50241 | + if( eMode==SQLITE_CHECKPOINT_TRUNCATE ){ | |
| 50242 | + /* IMPLEMENTATION-OF: R-44699-57140 This mode works the same way as | |
| 50243 | + ** SQLITE_CHECKPOINT_RESTART with the addition that it also | |
| 50244 | + ** truncates the log file to zero bytes just prior to a | |
| 50245 | + ** successful return. | |
| 50246 | + ** | |
| 50247 | + ** In theory, it might be safe to do this without updating the | |
| 50248 | + ** wal-index header in shared memory, as all subsequent reader or | |
| 50249 | + ** writer clients should see that the entire log file has been | |
| 50250 | + ** checkpointed and behave accordingly. This seems unsafe though, | |
| 50251 | + ** as it would leave the system in a state where the contents of | |
| 50252 | + ** the wal-index header do not match the contents of the | |
| 50253 | + ** file-system. To avoid this, update the wal-index header to | |
| 50254 | + ** indicate that the log file contains zero valid frames. */ | |
| 50255 | + walRestartHdr(pWal, salt1); | |
| 50256 | + rc = sqlite3OsTruncate(pWal->pWalFd, 0); | |
| 50257 | + } | |
| 50180 | 50258 | walUnlockExclusive(pWal, WAL_READ_LOCK(1), WAL_NREADER-1); |
| 50181 | 50259 | } |
| 50182 | 50260 | } |
| 50183 | 50261 | } |
| 50184 | 50262 | |
| @@ -50960,11 +51038,10 @@ | ||
| 50960 | 51038 | } |
| 50961 | 51039 | |
| 50962 | 51040 | return rc; |
| 50963 | 51041 | } |
| 50964 | 51042 | |
| 50965 | - | |
| 50966 | 51043 | /* |
| 50967 | 51044 | ** This function is called just before writing a set of frames to the log |
| 50968 | 51045 | ** file (see sqlite3WalFrames()). It checks to see if, instead of appending |
| 50969 | 51046 | ** to the current log file, it is possible to overwrite the start of the |
| 50970 | 51047 | ** existing log file with the new frames (i.e. "reset" the log). If so, |
| @@ -50993,24 +51070,12 @@ | ||
| 50993 | 51070 | ** wal-index header to reflect this. |
| 50994 | 51071 | ** |
| 50995 | 51072 | ** In theory it would be Ok to update the cache of the header only |
| 50996 | 51073 | ** at this point. But updating the actual wal-index header is also |
| 50997 | 51074 | ** safe and means there is no special case for sqlite3WalUndo() |
| 50998 | - ** to handle if this transaction is rolled back. | |
| 50999 | - */ | |
| 51000 | - int i; /* Loop counter */ | |
| 51001 | - u32 *aSalt = pWal->hdr.aSalt; /* Big-endian salt values */ | |
| 51002 | - | |
| 51003 | - pWal->nCkpt++; | |
| 51004 | - pWal->hdr.mxFrame = 0; | |
| 51005 | - sqlite3Put4byte((u8*)&aSalt[0], 1 + sqlite3Get4byte((u8*)&aSalt[0])); | |
| 51006 | - aSalt[1] = salt1; | |
| 51007 | - walIndexWriteHdr(pWal); | |
| 51008 | - pInfo->nBackfill = 0; | |
| 51009 | - pInfo->aReadMark[1] = 0; | |
| 51010 | - for(i=2; i<WAL_NREADER; i++) pInfo->aReadMark[i] = READMARK_NOT_USED; | |
| 51011 | - assert( pInfo->aReadMark[0]==0 ); | |
| 51075 | + ** to handle if this transaction is rolled back. */ | |
| 51076 | + walRestartHdr(pWal, salt1); | |
| 51012 | 51077 | walUnlockExclusive(pWal, WAL_READ_LOCK(1), WAL_NREADER-1); |
| 51013 | 51078 | }else if( rc!=SQLITE_BUSY ){ |
| 51014 | 51079 | return rc; |
| 51015 | 51080 | } |
| 51016 | 51081 | } |
| @@ -51294,11 +51359,11 @@ | ||
| 51294 | 51359 | ** If parameter xBusy is not NULL, it is a pointer to a busy-handler |
| 51295 | 51360 | ** callback. In this case this function runs a blocking checkpoint. |
| 51296 | 51361 | */ |
| 51297 | 51362 | SQLITE_PRIVATE int sqlite3WalCheckpoint( |
| 51298 | 51363 | Wal *pWal, /* Wal connection */ |
| 51299 | - int eMode, /* PASSIVE, FULL or RESTART */ | |
| 51364 | + int eMode, /* PASSIVE, FULL, RESTART, or TRUNCATE */ | |
| 51300 | 51365 | int (*xBusy)(void*), /* Function to call when busy */ |
| 51301 | 51366 | void *pBusyArg, /* Context argument for xBusyHandler */ |
| 51302 | 51367 | int sync_flags, /* Flags to sync db file with (or 0) */ |
| 51303 | 51368 | int nBuf, /* Size of temporary buffer */ |
| 51304 | 51369 | u8 *zBuf, /* Temporary buffer to use */ |
| @@ -51306,40 +51371,54 @@ | ||
| 51306 | 51371 | int *pnCkpt /* OUT: Number of backfilled frames in WAL */ |
| 51307 | 51372 | ){ |
| 51308 | 51373 | int rc; /* Return code */ |
| 51309 | 51374 | int isChanged = 0; /* True if a new wal-index header is loaded */ |
| 51310 | 51375 | int eMode2 = eMode; /* Mode to pass to walCheckpoint() */ |
| 51376 | + int (*xBusy2)(void*) = xBusy; /* Busy handler for eMode2 */ | |
| 51311 | 51377 | |
| 51312 | 51378 | assert( pWal->ckptLock==0 ); |
| 51313 | 51379 | assert( pWal->writeLock==0 ); |
| 51314 | 51380 | |
| 51381 | + /* EVIDENCE-OF: R-62920-47450 The busy-handler callback is never invoked | |
| 51382 | + ** in the SQLITE_CHECKPOINT_PASSIVE mode. */ | |
| 51383 | + assert( eMode!=SQLITE_CHECKPOINT_PASSIVE || xBusy==0 ); | |
| 51384 | + | |
| 51315 | 51385 | if( pWal->readOnly ) return SQLITE_READONLY; |
| 51316 | 51386 | WALTRACE(("WAL%p: checkpoint begins\n", pWal)); |
| 51387 | + | |
| 51388 | + /* IMPLEMENTATION-OF: R-62028-47212 All calls obtain an exclusive | |
| 51389 | + ** "checkpoint" lock on the database file. */ | |
| 51317 | 51390 | rc = walLockExclusive(pWal, WAL_CKPT_LOCK, 1); |
| 51318 | 51391 | if( rc ){ |
| 51319 | - /* Usually this is SQLITE_BUSY meaning that another thread or process | |
| 51320 | - ** is already running a checkpoint, or maybe a recovery. But it might | |
| 51321 | - ** also be SQLITE_IOERR. */ | |
| 51392 | + /* EVIDENCE-OF: R-10421-19736 If any other process is running a | |
| 51393 | + ** checkpoint operation at the same time, the lock cannot be obtained and | |
| 51394 | + ** SQLITE_BUSY is returned. | |
| 51395 | + ** EVIDENCE-OF: R-53820-33897 Even if there is a busy-handler configured, | |
| 51396 | + ** it will not be invoked in this case. | |
| 51397 | + */ | |
| 51398 | + testcase( rc==SQLITE_BUSY ); | |
| 51399 | + testcase( xBusy!=0 ); | |
| 51322 | 51400 | return rc; |
| 51323 | 51401 | } |
| 51324 | 51402 | pWal->ckptLock = 1; |
| 51325 | 51403 | |
| 51326 | - /* If this is a blocking-checkpoint, then obtain the write-lock as well | |
| 51327 | - ** to prevent any writers from running while the checkpoint is underway. | |
| 51328 | - ** This has to be done before the call to walIndexReadHdr() below. | |
| 51404 | + /* IMPLEMENTATION-OF: R-59782-36818 The SQLITE_CHECKPOINT_FULL, RESTART and | |
| 51405 | + ** TRUNCATE modes also obtain the exclusive "writer" lock on the database | |
| 51406 | + ** file. | |
| 51329 | 51407 | ** |
| 51330 | - ** If the writer lock cannot be obtained, then a passive checkpoint is | |
| 51331 | - ** run instead. Since the checkpointer is not holding the writer lock, | |
| 51332 | - ** there is no point in blocking waiting for any readers. Assuming no | |
| 51333 | - ** other error occurs, this function will return SQLITE_BUSY to the caller. | |
| 51408 | + ** EVIDENCE-OF: R-60642-04082 If the writer lock cannot be obtained | |
| 51409 | + ** immediately, and a busy-handler is configured, it is invoked and the | |
| 51410 | + ** writer lock retried until either the busy-handler returns 0 or the | |
| 51411 | + ** lock is successfully obtained. | |
| 51334 | 51412 | */ |
| 51335 | 51413 | if( eMode!=SQLITE_CHECKPOINT_PASSIVE ){ |
| 51336 | 51414 | rc = walBusyLock(pWal, xBusy, pBusyArg, WAL_WRITE_LOCK, 1); |
| 51337 | 51415 | if( rc==SQLITE_OK ){ |
| 51338 | 51416 | pWal->writeLock = 1; |
| 51339 | 51417 | }else if( rc==SQLITE_BUSY ){ |
| 51340 | 51418 | eMode2 = SQLITE_CHECKPOINT_PASSIVE; |
| 51419 | + xBusy2 = 0; | |
| 51341 | 51420 | rc = SQLITE_OK; |
| 51342 | 51421 | } |
| 51343 | 51422 | } |
| 51344 | 51423 | |
| 51345 | 51424 | /* Read the wal-index header. */ |
| @@ -51353,11 +51432,11 @@ | ||
| 51353 | 51432 | /* Copy data from the log to the database file. */ |
| 51354 | 51433 | if( rc==SQLITE_OK ){ |
| 51355 | 51434 | if( pWal->hdr.mxFrame && walPagesize(pWal)!=nBuf ){ |
| 51356 | 51435 | rc = SQLITE_CORRUPT_BKPT; |
| 51357 | 51436 | }else{ |
| 51358 | - rc = walCheckpoint(pWal, eMode2, xBusy, pBusyArg, sync_flags, zBuf); | |
| 51437 | + rc = walCheckpoint(pWal, eMode2, xBusy2, pBusyArg, sync_flags, zBuf); | |
| 51359 | 51438 | } |
| 51360 | 51439 | |
| 51361 | 51440 | /* If no error occurred, set the output variables. */ |
| 51362 | 51441 | if( rc==SQLITE_OK || rc==SQLITE_BUSY ){ |
| 51363 | 51442 | if( pnLog ) *pnLog = (int)pWal->hdr.mxFrame; |
| @@ -53821,11 +53900,11 @@ | ||
| 53821 | 53900 | ** to see if defragmentation is necessary. |
| 53822 | 53901 | */ |
| 53823 | 53902 | testcase( gap+2+nByte==top ); |
| 53824 | 53903 | if( gap+2+nByte>top ){ |
| 53825 | 53904 | defragment_page: |
| 53826 | - testcase( pPage->nCell==0 ); | |
| 53905 | + assert( pPage->nCell>0 || CORRUPT_DB ); | |
| 53827 | 53906 | rc = defragmentPage(pPage); |
| 53828 | 53907 | if( rc ) return rc; |
| 53829 | 53908 | top = get2byteNotZero(&data[hdr+5]); |
| 53830 | 53909 | assert( gap+nByte<=top ); |
| 53831 | 53910 | } |
| @@ -58881,11 +58960,11 @@ | ||
| 58881 | 58960 | assert( sqlite3_mutex_held(pPage->pBt->mutex) ); |
| 58882 | 58961 | assert( sqlite3PagerIswriteable(pParent->pDbPage) ); |
| 58883 | 58962 | assert( pPage->nOverflow==1 ); |
| 58884 | 58963 | |
| 58885 | 58964 | /* This error condition is now caught prior to reaching this function */ |
| 58886 | - if( pPage->nCell==0 ) return SQLITE_CORRUPT_BKPT; | |
| 58965 | + if( NEVER(pPage->nCell==0) ) return SQLITE_CORRUPT_BKPT; | |
| 58887 | 58966 | |
| 58888 | 58967 | /* Allocate a new page. This page will become the right-sibling of |
| 58889 | 58968 | ** pPage. Make the parent page writable, so that the new divider cell |
| 58890 | 58969 | ** may be inserted. If both these operations are successful, proceed. |
| 58891 | 58970 | */ |
| @@ -59324,11 +59403,15 @@ | ||
| 59324 | 59403 | ** pointer of the divider cell */ |
| 59325 | 59404 | memcpy(apCell[nCell], &pOld->aData[8], 4); |
| 59326 | 59405 | }else{ |
| 59327 | 59406 | assert( leafCorrection==4 ); |
| 59328 | 59407 | if( szCell[nCell]<4 ){ |
| 59329 | - /* Do not allow any cells smaller than 4 bytes. */ | |
| 59408 | + /* Do not allow any cells smaller than 4 bytes. If a smaller cell | |
| 59409 | + ** does exist, pad it with 0x00 bytes. */ | |
| 59410 | + assert( szCell[nCell]==3 ); | |
| 59411 | + assert( apCell[nCell]==&pTemp[iSpace1-3] ); | |
| 59412 | + pTemp[iSpace1++] = 0x00; | |
| 59330 | 59413 | szCell[nCell] = 4; |
| 59331 | 59414 | } |
| 59332 | 59415 | } |
| 59333 | 59416 | nCell++; |
| 59334 | 59417 | } |
| @@ -59559,11 +59642,15 @@ | ||
| 59559 | 59642 | ** was either part of sibling page iOld (possibly an overflow cell), |
| 59560 | 59643 | ** or else the divider cell to the left of sibling page iOld. So, |
| 59561 | 59644 | ** if sibling page iOld had the same page number as pNew, and if |
| 59562 | 59645 | ** pCell really was a part of sibling page iOld (not a divider or |
| 59563 | 59646 | ** overflow cell), we can skip updating the pointer map entries. */ |
| 59564 | - if( pNew->pgno!=aPgno[iOld] || pCell<aOld || pCell>=&aOld[usableSize] ){ | |
| 59647 | + if( iOld>=nNew | |
| 59648 | + || pNew->pgno!=aPgno[iOld] | |
| 59649 | + || pCell<aOld | |
| 59650 | + || pCell>=&aOld[usableSize] | |
| 59651 | + ){ | |
| 59565 | 59652 | if( !leafCorrection ){ |
| 59566 | 59653 | ptrmapPut(pBt, get4byte(pCell), PTRMAP_BTREE, pNew->pgno, &rc); |
| 59567 | 59654 | } |
| 59568 | 59655 | if( szCell[i]>pNew->minLocal ){ |
| 59569 | 59656 | ptrmapPutOvflPtr(pNew, pCell, &rc); |
| @@ -65699,11 +65786,11 @@ | ||
| 65699 | 65786 | for(n=0; n<nVar; n++){ |
| 65700 | 65787 | p->aVar[n].flags = MEM_Null; |
| 65701 | 65788 | p->aVar[n].db = db; |
| 65702 | 65789 | } |
| 65703 | 65790 | } |
| 65704 | - if( p->azVar ){ | |
| 65791 | + if( p->azVar && pParse->nzVar>0 ){ | |
| 65705 | 65792 | p->nzVar = pParse->nzVar; |
| 65706 | 65793 | memcpy(p->azVar, pParse->azVar, p->nzVar*sizeof(p->azVar[0])); |
| 65707 | 65794 | memset(pParse->azVar, 0, pParse->nzVar*sizeof(pParse->azVar[0])); |
| 65708 | 65795 | } |
| 65709 | 65796 | if( p->aMem ){ |
| @@ -75629,12 +75716,12 @@ | ||
| 75629 | 75716 | |
| 75630 | 75717 | #ifndef SQLITE_OMIT_WAL |
| 75631 | 75718 | /* Opcode: Checkpoint P1 P2 P3 * * |
| 75632 | 75719 | ** |
| 75633 | 75720 | ** Checkpoint database P1. This is a no-op if P1 is not currently in |
| 75634 | -** WAL mode. Parameter P2 is one of SQLITE_CHECKPOINT_PASSIVE, FULL | |
| 75635 | -** or RESTART. Write 1 or 0 into mem[P3] if the checkpoint returns | |
| 75721 | +** WAL mode. Parameter P2 is one of SQLITE_CHECKPOINT_PASSIVE, FULL, | |
| 75722 | +** RESTART, or TRUNCATE. Write 1 or 0 into mem[P3] if the checkpoint returns | |
| 75636 | 75723 | ** SQLITE_BUSY or not, respectively. Write the number of pages in the |
| 75637 | 75724 | ** WAL after the checkpoint into mem[P3+1] and the number of pages |
| 75638 | 75725 | ** in the WAL that have been checkpointed after the checkpoint |
| 75639 | 75726 | ** completes into mem[P3+2]. However on an error, mem[P3+1] and |
| 75640 | 75727 | ** mem[P3+2] are initialized to -1. |
| @@ -75648,10 +75735,11 @@ | ||
| 75648 | 75735 | aRes[0] = 0; |
| 75649 | 75736 | aRes[1] = aRes[2] = -1; |
| 75650 | 75737 | assert( pOp->p2==SQLITE_CHECKPOINT_PASSIVE |
| 75651 | 75738 | || pOp->p2==SQLITE_CHECKPOINT_FULL |
| 75652 | 75739 | || pOp->p2==SQLITE_CHECKPOINT_RESTART |
| 75740 | + || pOp->p2==SQLITE_CHECKPOINT_TRUNCATE | |
| 75653 | 75741 | ); |
| 75654 | 75742 | rc = sqlite3Checkpoint(db, pOp->p1, pOp->p2, &aRes[1], &aRes[2]); |
| 75655 | 75743 | if( rc==SQLITE_BUSY ){ |
| 75656 | 75744 | rc = SQLITE_OK; |
| 75657 | 75745 | aRes[0] = 1; |
| @@ -80411,10 +80499,14 @@ | ||
| 80411 | 80499 | } |
| 80412 | 80500 | } |
| 80413 | 80501 | if( pMatch ){ |
| 80414 | 80502 | pExpr->iTable = pMatch->iCursor; |
| 80415 | 80503 | pExpr->pTab = pMatch->pTab; |
| 80504 | + assert( (pMatch->jointype & JT_RIGHT)==0 ); /* RIGHT JOIN not (yet) supported */ | |
| 80505 | + if( (pMatch->jointype & JT_LEFT)!=0 ){ | |
| 80506 | + ExprSetProperty(pExpr, EP_CanBeNull); | |
| 80507 | + } | |
| 80416 | 80508 | pSchema = pExpr->pTab->pSchema; |
| 80417 | 80509 | } |
| 80418 | 80510 | } /* if( pSrcList ) */ |
| 80419 | 80511 | |
| 80420 | 80512 | #ifndef SQLITE_OMIT_TRIGGER |
| @@ -82968,11 +83060,12 @@ | ||
| 82968 | 83060 | case TK_FLOAT: |
| 82969 | 83061 | case TK_BLOB: |
| 82970 | 83062 | return 0; |
| 82971 | 83063 | case TK_COLUMN: |
| 82972 | 83064 | assert( p->pTab!=0 ); |
| 82973 | - return p->iColumn>=0 && p->pTab->aCol[p->iColumn].notNull==0; | |
| 83065 | + return ExprHasProperty(p, EP_CanBeNull) || | |
| 83066 | + (p->iColumn>=0 && p->pTab->aCol[p->iColumn].notNull==0); | |
| 82974 | 83067 | default: |
| 82975 | 83068 | return 1; |
| 82976 | 83069 | } |
| 82977 | 83070 | } |
| 82978 | 83071 | |
| @@ -88351,11 +88444,11 @@ | ||
| 88351 | 88444 | tRowcnt avgEq = 0; |
| 88352 | 88445 | tRowcnt nRow; /* Number of rows in index */ |
| 88353 | 88446 | i64 nSum100 = 0; /* Number of terms contributing to sumEq */ |
| 88354 | 88447 | i64 nDist100; /* Number of distinct values in index */ |
| 88355 | 88448 | |
| 88356 | - if( pIdx->aiRowEst==0 || pIdx->aiRowEst[iCol+1]==0 ){ | |
| 88449 | + if( !pIdx->aiRowEst || iCol>=pIdx->nKeyCol || pIdx->aiRowEst[iCol+1]==0 ){ | |
| 88357 | 88450 | nRow = pFinal->anLt[iCol]; |
| 88358 | 88451 | nDist100 = (i64)100 * pFinal->anDLt[iCol]; |
| 88359 | 88452 | nSample--; |
| 88360 | 88453 | }else{ |
| 88361 | 88454 | nRow = pIdx->aiRowEst[0]; |
| @@ -103921,11 +104014,11 @@ | ||
| 103921 | 104014 | break; |
| 103922 | 104015 | #endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */ |
| 103923 | 104016 | |
| 103924 | 104017 | #ifndef SQLITE_OMIT_WAL |
| 103925 | 104018 | /* |
| 103926 | - ** PRAGMA [database.]wal_checkpoint = passive|full|restart | |
| 104019 | + ** PRAGMA [database.]wal_checkpoint = passive|full|restart|truncate | |
| 103927 | 104020 | ** |
| 103928 | 104021 | ** Checkpoint the database. |
| 103929 | 104022 | */ |
| 103930 | 104023 | case PragTyp_WAL_CHECKPOINT: { |
| 103931 | 104024 | int iBt = (pId2->z?iDb:SQLITE_MAX_ATTACHED); |
| @@ -103933,10 +104026,12 @@ | ||
| 103933 | 104026 | if( zRight ){ |
| 103934 | 104027 | if( sqlite3StrICmp(zRight, "full")==0 ){ |
| 103935 | 104028 | eMode = SQLITE_CHECKPOINT_FULL; |
| 103936 | 104029 | }else if( sqlite3StrICmp(zRight, "restart")==0 ){ |
| 103937 | 104030 | eMode = SQLITE_CHECKPOINT_RESTART; |
| 104031 | + }else if( sqlite3StrICmp(zRight, "truncate")==0 ){ | |
| 104032 | + eMode = SQLITE_CHECKPOINT_TRUNCATE; | |
| 103938 | 104033 | } |
| 103939 | 104034 | } |
| 103940 | 104035 | sqlite3VdbeSetNumCols(v, 3); |
| 103941 | 104036 | pParse->nMem = 3; |
| 103942 | 104037 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "busy", SQLITE_STATIC); |
| @@ -109840,11 +109935,11 @@ | ||
| 109840 | 109935 | ** |
| 109841 | 109936 | ** SELECT DISTINCT xyz FROM ... ORDER BY xyz |
| 109842 | 109937 | ** |
| 109843 | 109938 | ** is transformed to: |
| 109844 | 109939 | ** |
| 109845 | - ** SELECT xyz FROM ... GROUP BY xyz | |
| 109940 | + ** SELECT xyz FROM ... GROUP BY xyz ORDER BY xyz | |
| 109846 | 109941 | ** |
| 109847 | 109942 | ** The second form is preferred as a single index (or temp-table) may be |
| 109848 | 109943 | ** used for both the ORDER BY and DISTINCT processing. As originally |
| 109849 | 109944 | ** written the query must use a temp-table for at least one of the ORDER |
| 109850 | 109945 | ** BY and DISTINCT, and an index or separate temp-table for the other. |
| @@ -109853,11 +109948,10 @@ | ||
| 109853 | 109948 | && sqlite3ExprListCompare(sSort.pOrderBy, p->pEList, -1)==0 |
| 109854 | 109949 | ){ |
| 109855 | 109950 | p->selFlags &= ~SF_Distinct; |
| 109856 | 109951 | p->pGroupBy = sqlite3ExprListDup(db, p->pEList, 0); |
| 109857 | 109952 | pGroupBy = p->pGroupBy; |
| 109858 | - sSort.pOrderBy = 0; | |
| 109859 | 109953 | /* Notice that even thought SF_Distinct has been cleared from p->selFlags, |
| 109860 | 109954 | ** the sDistinct.isTnct is still set. Hence, isTnct represents the |
| 109861 | 109955 | ** original setting of the SF_Distinct flag, not the current setting */ |
| 109862 | 109956 | assert( sDistinct.isTnct ); |
| 109863 | 109957 | } |
| @@ -114808,10 +114902,11 @@ | ||
| 114808 | 114902 | memcpy(pWC->a, pOld, sizeof(pWC->a[0])*pWC->nTerm); |
| 114809 | 114903 | if( pOld!=pWC->aStatic ){ |
| 114810 | 114904 | sqlite3DbFree(db, pOld); |
| 114811 | 114905 | } |
| 114812 | 114906 | pWC->nSlot = sqlite3DbMallocSize(db, pWC->a)/sizeof(pWC->a[0]); |
| 114907 | + memset(&pWC->a[pWC->nTerm], 0, sizeof(pWC->a[0])*(pWC->nSlot-pWC->nTerm)); | |
| 114813 | 114908 | } |
| 114814 | 114909 | pTerm = &pWC->a[idx = pWC->nTerm++]; |
| 114815 | 114910 | if( p && ExprHasProperty(p, EP_Unlikely) ){ |
| 114816 | 114911 | pTerm->truthProb = sqlite3LogEst(p->iTable) - 270; |
| 114817 | 114912 | }else{ |
| @@ -117533,11 +117628,11 @@ | ||
| 117533 | 117628 | WhereLevel *pLvl, /* Level to add scanstatus() entry for */ |
| 117534 | 117629 | int addrExplain /* Address of OP_Explain (or 0) */ |
| 117535 | 117630 | ){ |
| 117536 | 117631 | const char *zObj = 0; |
| 117537 | 117632 | WhereLoop *pLoop = pLvl->pWLoop; |
| 117538 | - if( (pLoop->wsFlags & (WHERE_IPK|WHERE_VIRTUALTABLE))==0 ){ | |
| 117633 | + if( (pLoop->wsFlags & WHERE_VIRTUALTABLE)==0 && pLoop->u.btree.pIndex!=0 ){ | |
| 117539 | 117634 | zObj = pLoop->u.btree.pIndex->zName; |
| 117540 | 117635 | }else{ |
| 117541 | 117636 | zObj = pSrclist->a[pLvl->iFrom].zName; |
| 117542 | 117637 | } |
| 117543 | 117638 | sqlite3VdbeScanStatus( |
| @@ -118177,14 +118272,13 @@ | ||
| 118177 | 118272 | int iTerm; |
| 118178 | 118273 | for(iTerm=0; iTerm<pWC->nTerm; iTerm++){ |
| 118179 | 118274 | Expr *pExpr = pWC->a[iTerm].pExpr; |
| 118180 | 118275 | if( &pWC->a[iTerm] == pTerm ) continue; |
| 118181 | 118276 | if( ExprHasProperty(pExpr, EP_FromJoin) ) continue; |
| 118182 | - testcase( pWC->a[iTerm].wtFlags & TERM_ORINFO ); | |
| 118183 | - testcase( pWC->a[iTerm].wtFlags & TERM_VIRTUAL ); | |
| 118184 | - if( pWC->a[iTerm].wtFlags & (TERM_ORINFO|TERM_VIRTUAL) ) continue; | |
| 118277 | + if( (pWC->a[iTerm].wtFlags & TERM_VIRTUAL)!=0 ) continue; | |
| 118185 | 118278 | if( (pWC->a[iTerm].eOperator & WO_ALL)==0 ) continue; |
| 118279 | + testcase( pWC->a[iTerm].wtFlags & TERM_ORINFO ); | |
| 118186 | 118280 | pExpr = sqlite3ExprDup(db, pExpr, 0); |
| 118187 | 118281 | pAndExpr = sqlite3ExprAnd(db, pAndExpr, pExpr); |
| 118188 | 118282 | } |
| 118189 | 118283 | if( pAndExpr ){ |
| 118190 | 118284 | pAndExpr = sqlite3PExpr(pParse, TK_AND, 0, pAndExpr, 0); |
| @@ -127079,10 +127173,18 @@ | ||
| 127079 | 127173 | |
| 127080 | 127174 | /* Close all database connections */ |
| 127081 | 127175 | for(j=0; j<db->nDb; j++){ |
| 127082 | 127176 | struct Db *pDb = &db->aDb[j]; |
| 127083 | 127177 | if( pDb->pBt ){ |
| 127178 | + if( pDb->pSchema ){ | |
| 127179 | + /* Must clear the KeyInfo cache. See ticket [e4a18565a36884b00edf] */ | |
| 127180 | + for(i=sqliteHashFirst(&pDb->pSchema->idxHash); i; i=sqliteHashNext(i)){ | |
| 127181 | + Index *pIdx = sqliteHashData(i); | |
| 127182 | + sqlite3KeyInfoUnref(pIdx->pKeyInfo); | |
| 127183 | + pIdx->pKeyInfo = 0; | |
| 127184 | + } | |
| 127185 | + } | |
| 127084 | 127186 | sqlite3BtreeClose(pDb->pBt); |
| 127085 | 127187 | pDb->pBt = 0; |
| 127086 | 127188 | if( j!=1 ){ |
| 127087 | 127189 | pDb->pSchema = 0; |
| 127088 | 127190 | } |
| @@ -127983,14 +128085,17 @@ | ||
| 127983 | 128085 | |
| 127984 | 128086 | /* Initialize the output variables to -1 in case an error occurs. */ |
| 127985 | 128087 | if( pnLog ) *pnLog = -1; |
| 127986 | 128088 | if( pnCkpt ) *pnCkpt = -1; |
| 127987 | 128089 | |
| 127988 | - assert( SQLITE_CHECKPOINT_FULL>SQLITE_CHECKPOINT_PASSIVE ); | |
| 127989 | - assert( SQLITE_CHECKPOINT_FULL<SQLITE_CHECKPOINT_RESTART ); | |
| 127990 | - assert( SQLITE_CHECKPOINT_PASSIVE+2==SQLITE_CHECKPOINT_RESTART ); | |
| 127991 | - if( eMode<SQLITE_CHECKPOINT_PASSIVE || eMode>SQLITE_CHECKPOINT_RESTART ){ | |
| 128090 | + assert( SQLITE_CHECKPOINT_PASSIVE==0 ); | |
| 128091 | + assert( SQLITE_CHECKPOINT_FULL==1 ); | |
| 128092 | + assert( SQLITE_CHECKPOINT_RESTART==2 ); | |
| 128093 | + assert( SQLITE_CHECKPOINT_TRUNCATE==3 ); | |
| 128094 | + if( eMode<SQLITE_CHECKPOINT_PASSIVE || eMode>SQLITE_CHECKPOINT_TRUNCATE ){ | |
| 128095 | + /* EVIDENCE-OF: R-03996-12088 The M parameter must be a valid checkpoint | |
| 128096 | + ** mode: */ | |
| 127992 | 128097 | return SQLITE_MISUSE; |
| 127993 | 128098 | } |
| 127994 | 128099 | |
| 127995 | 128100 | sqlite3_mutex_enter(db->mutex); |
| 127996 | 128101 | if( zDb && zDb[0] ){ |
| @@ -128014,11 +128119,13 @@ | ||
| 128014 | 128119 | ** Checkpoint database zDb. If zDb is NULL, or if the buffer zDb points |
| 128015 | 128120 | ** to contains a zero-length string, all attached databases are |
| 128016 | 128121 | ** checkpointed. |
| 128017 | 128122 | */ |
| 128018 | 128123 | SQLITE_API int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb){ |
| 128019 | - return sqlite3_wal_checkpoint_v2(db, zDb, SQLITE_CHECKPOINT_PASSIVE, 0, 0); | |
| 128124 | + /* EVIDENCE-OF: R-41613-20553 The sqlite3_wal_checkpoint(D,X) is equivalent to | |
| 128125 | + ** sqlite3_wal_checkpoint_v2(D,X,SQLITE_CHECKPOINT_PASSIVE,0,0). */ | |
| 128126 | + return sqlite3_wal_checkpoint_v2(db,zDb,SQLITE_CHECKPOINT_PASSIVE,0,0); | |
| 128020 | 128127 | } |
| 128021 | 128128 | |
| 128022 | 128129 | #ifndef SQLITE_OMIT_WAL |
| 128023 | 128130 | /* |
| 128024 | 128131 | ** Run a checkpoint on database iDb. This is a no-op if database iDb is |
| @@ -139164,11 +139271,11 @@ | ||
| 139164 | 139271 | ** Return true if the m-value for z is 1 or more. In other words, |
| 139165 | 139272 | ** return true if z contains at least one vowel that is followed |
| 139166 | 139273 | ** by a consonant. |
| 139167 | 139274 | ** |
| 139168 | 139275 | ** In this routine z[] is in reverse order. So we are really looking |
| 139169 | -** for an instance of of a consonant followed by a vowel. | |
| 139276 | +** for an instance of a consonant followed by a vowel. | |
| 139170 | 139277 | */ |
| 139171 | 139278 | static int m_gt_0(const char *z){ |
| 139172 | 139279 | while( isVowel(z) ){ z++; } |
| 139173 | 139280 | if( *z==0 ) return 0; |
| 139174 | 139281 | while( isConsonant(z) ){ z++; } |
| 139175 | 139282 |
| --- src/sqlite3.c | |
| +++ src/sqlite3.c | |
| @@ -231,11 +231,11 @@ | |
| 231 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 232 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 233 | */ |
| 234 | #define SQLITE_VERSION "3.8.8" |
| 235 | #define SQLITE_VERSION_NUMBER 3008008 |
| 236 | #define SQLITE_SOURCE_ID "2014-11-28 13:35:03 24fa2e9832daaa5d68ee28a00c56c55f97a4da9e" |
| 237 | |
| 238 | /* |
| 239 | ** CAPI3REF: Run-Time Library Version Numbers |
| 240 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 241 | ** |
| @@ -1343,11 +1343,11 @@ | |
| 1343 | ** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_SHARED |
| 1344 | ** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_EXCLUSIVE |
| 1345 | ** </ul> |
| 1346 | ** |
| 1347 | ** When unlocking, the same SHARED or EXCLUSIVE flag must be supplied as |
| 1348 | ** was given no the corresponding lock. |
| 1349 | ** |
| 1350 | ** The xShmLock method can transition between unlocked and SHARED or |
| 1351 | ** between unlocked and EXCLUSIVE. It cannot transition between SHARED |
| 1352 | ** and EXCLUSIVE. |
| 1353 | */ |
| @@ -1646,12 +1646,12 @@ | |
| 1646 | ** tracks memory usage, for example. </dd> |
| 1647 | ** |
| 1648 | ** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt> |
| 1649 | ** <dd> ^The SQLITE_CONFIG_MEMSTATUS option takes single argument of type int, |
| 1650 | ** interpreted as a boolean, which enables or disables the collection of |
| 1651 | ** memory allocation statistics. ^(When memory allocation statistics are disabled, the |
| 1652 | ** following SQLite interfaces become non-operational: |
| 1653 | ** <ul> |
| 1654 | ** <li> [sqlite3_memory_used()] |
| 1655 | ** <li> [sqlite3_memory_highwater()] |
| 1656 | ** <li> [sqlite3_soft_heap_limit64()] |
| 1657 | ** <li> [sqlite3_status()] |
| @@ -1688,11 +1688,12 @@ | |
| 1688 | ** that SQLite can use for the database page cache with the default page |
| 1689 | ** cache implementation. |
| 1690 | ** This configuration should not be used if an application-define page |
| 1691 | ** cache implementation is loaded using the [SQLITE_CONFIG_PCACHE2] |
| 1692 | ** configuration option. |
| 1693 | ** ^There are three arguments to SQLITE_CONFIG_PAGECACHE: A pointer to 8-byte aligned |
| 1694 | ** memory, the size of each page buffer (sz), and the number of pages (N). |
| 1695 | ** The sz argument should be the size of the largest database page |
| 1696 | ** (a power of two between 512 and 32768) plus some extra bytes for each |
| 1697 | ** page header. ^The number of extra bytes needed by the page header |
| 1698 | ** can be determined using the [SQLITE_CONFIG_PCACHE_HDRSZ] option |
| @@ -1708,11 +1709,12 @@ | |
| 1708 | ** SQLite goes to [sqlite3_malloc()] for the additional storage space.</dd> |
| 1709 | ** |
| 1710 | ** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt> |
| 1711 | ** <dd> ^The SQLITE_CONFIG_HEAP option specifies a static memory buffer |
| 1712 | ** that SQLite will use for all of its dynamic memory allocation needs |
| 1713 | ** beyond those provided for by [SQLITE_CONFIG_SCRATCH] and [SQLITE_CONFIG_PAGECACHE]. |
| 1714 | ** ^The SQLITE_CONFIG_HEAP option is only available if SQLite is compiled |
| 1715 | ** with either [SQLITE_ENABLE_MEMSYS3] or [SQLITE_ENABLE_MEMSYS5] and returns |
| 1716 | ** [SQLITE_ERROR] if invoked otherwise. |
| 1717 | ** ^There are three arguments to SQLITE_CONFIG_HEAP: |
| 1718 | ** An 8-byte aligned pointer to the memory, |
| @@ -1728,13 +1730,13 @@ | |
| 1728 | ** for the minimum allocation size are 2**5 through 2**8.</dd> |
| 1729 | ** |
| 1730 | ** [[SQLITE_CONFIG_MUTEX]] <dt>SQLITE_CONFIG_MUTEX</dt> |
| 1731 | ** <dd> ^(The SQLITE_CONFIG_MUTEX option takes a single argument which is a |
| 1732 | ** pointer to an instance of the [sqlite3_mutex_methods] structure. |
| 1733 | ** The argument specifies alternative low-level mutex routines to be used in place |
| 1734 | ** the mutex routines built into SQLite.)^ ^SQLite makes a copy of the |
| 1735 | ** content of the [sqlite3_mutex_methods] structure before the call to |
| 1736 | ** [sqlite3_config()] returns. ^If SQLite is compiled with |
| 1737 | ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then |
| 1738 | ** the entire mutexing subsystem is omitted from the build and hence calls to |
| 1739 | ** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will |
| 1740 | ** return [SQLITE_ERROR].</dd> |
| @@ -1768,12 +1770,12 @@ | |
| 1768 | ** the interface to a custom page cache implementation.)^ |
| 1769 | ** ^SQLite makes a copy of the [sqlite3_pcache_methods2] object.</dd> |
| 1770 | ** |
| 1771 | ** [[SQLITE_CONFIG_GETPCACHE2]] <dt>SQLITE_CONFIG_GETPCACHE2</dt> |
| 1772 | ** <dd> ^(The SQLITE_CONFIG_GETPCACHE2 option takes a single argument which |
| 1773 | ** is a pointer to an [sqlite3_pcache_methods2] object. SQLite copies of the current |
| 1774 | ** page cache implementation into that object.)^ </dd> |
| 1775 | ** |
| 1776 | ** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt> |
| 1777 | ** <dd> The SQLITE_CONFIG_LOG option is used to configure the SQLite |
| 1778 | ** global [error log]. |
| 1779 | ** (^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a |
| @@ -1794,12 +1796,13 @@ | |
| 1794 | ** function must be threadsafe. </dd> |
| 1795 | ** |
| 1796 | ** [[SQLITE_CONFIG_URI]] <dt>SQLITE_CONFIG_URI |
| 1797 | ** <dd>^(The SQLITE_CONFIG_URI option takes a single argument of type int. |
| 1798 | ** If non-zero, then URI handling is globally enabled. If the parameter is zero, |
| 1799 | ** then URI handling is globally disabled.)^ ^If URI handling is globally enabled, |
| 1800 | ** all filenames passed to [sqlite3_open()], [sqlite3_open_v2()], [sqlite3_open16()] or |
| 1801 | ** specified as part of [ATTACH] commands are interpreted as URIs, regardless |
| 1802 | ** of whether or not the [SQLITE_OPEN_URI] flag is set when the database |
| 1803 | ** connection is opened. ^If it is globally disabled, filenames are |
| 1804 | ** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the |
| 1805 | ** database connection is opened. ^(By default, URI handling is globally |
| @@ -1857,21 +1860,21 @@ | |
| 1857 | ** changed to its compile-time default. |
| 1858 | ** |
| 1859 | ** [[SQLITE_CONFIG_WIN32_HEAPSIZE]] |
| 1860 | ** <dt>SQLITE_CONFIG_WIN32_HEAPSIZE |
| 1861 | ** <dd>^The SQLITE_CONFIG_WIN32_HEAPSIZE option is only available if SQLite is |
| 1862 | ** compiled for Windows with the [SQLITE_WIN32_MALLOC] pre-processor macro defined. |
| 1863 | ** ^SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit unsigned integer value |
| 1864 | ** that specifies the maximum size of the created heap. |
| 1865 | ** </dl> |
| 1866 | ** |
| 1867 | ** [[SQLITE_CONFIG_PCACHE_HDRSZ]] |
| 1868 | ** <dt>SQLITE_CONFIG_PCACHE_HDRSZ |
| 1869 | ** <dd>^The SQLITE_CONFIG_PCACHE_HDRSZ option takes a single parameter which |
| 1870 | ** is a pointer to an integer and writes into that integer the number of extra |
| 1871 | ** bytes per page required for each page in [SQLITE_CONFIG_PAGECACHE]. The amount of |
| 1872 | ** extra space required can change depending on the compiler, |
| 1873 | ** target platform, and SQLite version. |
| 1874 | ** </dl> |
| 1875 | */ |
| 1876 | #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */ |
| 1877 | #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */ |
| @@ -2171,10 +2174,11 @@ | |
| 2171 | SQLITE_API int sqlite3_complete(const char *sql); |
| 2172 | SQLITE_API int sqlite3_complete16(const void *sql); |
| 2173 | |
| 2174 | /* |
| 2175 | ** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors |
| 2176 | ** |
| 2177 | ** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X |
| 2178 | ** that might be invoked with argument P whenever |
| 2179 | ** an attempt is made to access a database table associated with |
| 2180 | ** [database connection] D when another thread |
| @@ -2187,11 +2191,11 @@ | |
| 2187 | ** is not NULL, then the callback might be invoked with two arguments. |
| 2188 | ** |
| 2189 | ** ^The first argument to the busy handler is a copy of the void* pointer which |
| 2190 | ** is the third argument to sqlite3_busy_handler(). ^The second argument to |
| 2191 | ** the busy handler callback is the number of times that the busy handler has |
| 2192 | ** been invoked for the same locking event. ^If the |
| 2193 | ** busy callback returns 0, then no additional attempts are made to |
| 2194 | ** access the database and [SQLITE_BUSY] is returned |
| 2195 | ** to the application. |
| 2196 | ** ^If the callback returns non-zero, then another attempt |
| 2197 | ** is made to access the database and the cycle repeats. |
| @@ -4642,11 +4646,12 @@ | |
| 4642 | ** If these routines are called from within the different thread |
| 4643 | ** than the one containing the application-defined function that received |
| 4644 | ** the [sqlite3_context] pointer, the results are undefined. |
| 4645 | */ |
| 4646 | SQLITE_API void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*)); |
| 4647 | SQLITE_API void sqlite3_result_blob64(sqlite3_context*,const void*,sqlite3_uint64,void(*)(void*)); |
| 4648 | SQLITE_API void sqlite3_result_double(sqlite3_context*, double); |
| 4649 | SQLITE_API void sqlite3_result_error(sqlite3_context*, const char*, int); |
| 4650 | SQLITE_API void sqlite3_result_error16(sqlite3_context*, const void*, int); |
| 4651 | SQLITE_API void sqlite3_result_error_toobig(sqlite3_context*); |
| 4652 | SQLITE_API void sqlite3_result_error_nomem(sqlite3_context*); |
| @@ -7368,101 +7373,118 @@ | |
| 7368 | SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int N); |
| 7369 | |
| 7370 | /* |
| 7371 | ** CAPI3REF: Checkpoint a database |
| 7372 | ** |
| 7373 | ** ^The [sqlite3_wal_checkpoint(D,X)] interface causes database named X |
| 7374 | ** on [database connection] D to be [checkpointed]. ^If X is NULL or an |
| 7375 | ** empty string, then a checkpoint is run on all databases of |
| 7376 | ** connection D. ^If the database connection D is not in |
| 7377 | ** [WAL | write-ahead log mode] then this interface is a harmless no-op. |
| 7378 | ** ^The [sqlite3_wal_checkpoint(D,X)] interface initiates a |
| 7379 | ** [sqlite3_wal_checkpoint_v2|PASSIVE] checkpoint. |
| 7380 | ** Use the [sqlite3_wal_checkpoint_v2()] interface to get a FULL |
| 7381 | ** or RESET checkpoint. |
| 7382 | ** |
| 7383 | ** ^The [wal_checkpoint pragma] can be used to invoke this interface |
| 7384 | ** from SQL. ^The [sqlite3_wal_autocheckpoint()] interface and the |
| 7385 | ** [wal_autocheckpoint pragma] can be used to cause this interface to be |
| 7386 | ** run whenever the WAL reaches a certain size threshold. |
| 7387 | ** |
| 7388 | ** See also: [sqlite3_wal_checkpoint_v2()] |
| 7389 | */ |
| 7390 | SQLITE_API int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb); |
| 7391 | |
| 7392 | /* |
| 7393 | ** CAPI3REF: Checkpoint a database |
| 7394 | ** |
| 7395 | ** Run a checkpoint operation on WAL database zDb attached to database |
| 7396 | ** handle db. The specific operation is determined by the value of the |
| 7397 | ** eMode parameter: |
| 7398 | ** |
| 7399 | ** <dl> |
| 7400 | ** <dt>SQLITE_CHECKPOINT_PASSIVE<dd> |
| 7401 | ** Checkpoint as many frames as possible without waiting for any database |
| 7402 | ** readers or writers to finish. Sync the db file if all frames in the log |
| 7403 | ** are checkpointed. This mode is the same as calling |
| 7404 | ** sqlite3_wal_checkpoint(). The [sqlite3_busy_handler|busy-handler callback] |
| 7405 | ** is never invoked. |
| 7406 | ** |
| 7407 | ** <dt>SQLITE_CHECKPOINT_FULL<dd> |
| 7408 | ** This mode blocks (it invokes the |
| 7409 | ** [sqlite3_busy_handler|busy-handler callback]) until there is no |
| 7410 | ** database writer and all readers are reading from the most recent database |
| 7411 | ** snapshot. It then checkpoints all frames in the log file and syncs the |
| 7412 | ** database file. This call blocks database writers while it is running, |
| 7413 | ** but not database readers. |
| 7414 | ** |
| 7415 | ** <dt>SQLITE_CHECKPOINT_RESTART<dd> |
| 7416 | ** This mode works the same way as SQLITE_CHECKPOINT_FULL, except after |
| 7417 | ** checkpointing the log file it blocks (calls the |
| 7418 | ** [sqlite3_busy_handler|busy-handler callback]) |
| 7419 | ** until all readers are reading from the database file only. This ensures |
| 7420 | ** that the next client to write to the database file restarts the log file |
| 7421 | ** from the beginning. This call blocks database writers while it is running, |
| 7422 | ** but not database readers. |
| 7423 | ** </dl> |
| 7424 | ** |
| 7425 | ** If pnLog is not NULL, then *pnLog is set to the total number of frames in |
| 7426 | ** the log file before returning. If pnCkpt is not NULL, then *pnCkpt is set to |
| 7427 | ** the total number of checkpointed frames (including any that were already |
| 7428 | ** checkpointed when this function is called). *pnLog and *pnCkpt may be |
| 7429 | ** populated even if sqlite3_wal_checkpoint_v2() returns other than SQLITE_OK. |
| 7430 | ** If no values are available because of an error, they are both set to -1 |
| 7431 | ** before returning to communicate this to the caller. |
| 7432 | ** |
| 7433 | ** All calls obtain an exclusive "checkpoint" lock on the database file. If |
| 7434 | ** any other process is running a checkpoint operation at the same time, the |
| 7435 | ** lock cannot be obtained and SQLITE_BUSY is returned. Even if there is a |
| 7436 | ** busy-handler configured, it will not be invoked in this case. |
| 7437 | ** |
| 7438 | ** The SQLITE_CHECKPOINT_FULL and RESTART modes also obtain the exclusive |
| 7439 | ** "writer" lock on the database file. If the writer lock cannot be obtained |
| 7440 | ** immediately, and a busy-handler is configured, it is invoked and the writer |
| 7441 | ** lock retried until either the busy-handler returns 0 or the lock is |
| 7442 | ** successfully obtained. The busy-handler is also invoked while waiting for |
| 7443 | ** database readers as described above. If the busy-handler returns 0 before |
| 7444 | ** the writer lock is obtained or while waiting for database readers, the |
| 7445 | ** checkpoint operation proceeds from that point in the same way as |
| 7446 | ** SQLITE_CHECKPOINT_PASSIVE - checkpointing as many frames as possible |
| 7447 | ** without blocking any further. SQLITE_BUSY is returned in this case. |
| 7448 | ** |
| 7449 | ** If parameter zDb is NULL or points to a zero length string, then the |
| 7450 | ** specified operation is attempted on all WAL databases. In this case the |
| 7451 | ** values written to output parameters *pnLog and *pnCkpt are undefined. If |
| 7452 | ** an SQLITE_BUSY error is encountered when processing one or more of the |
| 7453 | ** attached WAL databases, the operation is still attempted on any remaining |
| 7454 | ** attached databases and SQLITE_BUSY is returned to the caller. If any other |
| 7455 | ** error occurs while processing an attached database, processing is abandoned |
| 7456 | ** and the error code returned to the caller immediately. If no error |
| 7457 | ** (SQLITE_BUSY or otherwise) is encountered while processing the attached |
| 7458 | ** databases, SQLITE_OK is returned. |
| 7459 | ** |
| 7460 | ** If database zDb is the name of an attached database that is not in WAL |
| 7461 | ** mode, SQLITE_OK is returned and both *pnLog and *pnCkpt set to -1. If |
| 7462 | ** zDb is not NULL (or a zero length string) and is not the name of any |
| 7463 | ** attached database, SQLITE_ERROR is returned to the caller. |
| 7464 | */ |
| 7465 | SQLITE_API int sqlite3_wal_checkpoint_v2( |
| 7466 | sqlite3 *db, /* Database handle */ |
| 7467 | const char *zDb, /* Name of attached database (or NULL) */ |
| 7468 | int eMode, /* SQLITE_CHECKPOINT_* value */ |
| @@ -7469,20 +7491,22 @@ | |
| 7469 | int *pnLog, /* OUT: Size of WAL log in frames */ |
| 7470 | int *pnCkpt /* OUT: Total number of frames checkpointed */ |
| 7471 | ); |
| 7472 | |
| 7473 | /* |
| 7474 | ** CAPI3REF: Checkpoint operation parameters |
| 7475 | ** |
| 7476 | ** These constants can be used as the 3rd parameter to |
| 7477 | ** [sqlite3_wal_checkpoint_v2()]. See the [sqlite3_wal_checkpoint_v2()] |
| 7478 | ** documentation for additional information about the meaning and use of |
| 7479 | ** each of these values. |
| 7480 | */ |
| 7481 | #define SQLITE_CHECKPOINT_PASSIVE 0 |
| 7482 | #define SQLITE_CHECKPOINT_FULL 1 |
| 7483 | #define SQLITE_CHECKPOINT_RESTART 2 |
| 7484 | |
| 7485 | /* |
| 7486 | ** CAPI3REF: Virtual Table Interface Configuration |
| 7487 | ** |
| 7488 | ** This function may be called by either the [xConnect] or [xCreate] method |
| @@ -7577,16 +7601,16 @@ | |
| 7577 | ** [sqlite3_stmt_scanstatus(S,X,T,V)] interface. Each constant designates a |
| 7578 | ** different metric for sqlite3_stmt_scanstatus() to return. |
| 7579 | ** |
| 7580 | ** <dl> |
| 7581 | ** [[SQLITE_SCANSTAT_NLOOP]] <dt>SQLITE_SCANSTAT_NLOOP</dt> |
| 7582 | ** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be set to the |
| 7583 | ** total number of times that the X-th loop has run.</dd> |
| 7584 | ** |
| 7585 | ** [[SQLITE_SCANSTAT_NVISIT]] <dt>SQLITE_SCANSTAT_NVISIT</dt> |
| 7586 | ** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be set to the |
| 7587 | ** total number of rows examined by all iterations of the X-th loop.</dd> |
| 7588 | ** |
| 7589 | ** [[SQLITE_SCANSTAT_EST]] <dt>SQLITE_SCANSTAT_EST</dt> |
| 7590 | ** <dd>^The "double" variable pointed to by the T parameter will be set to the |
| 7591 | ** query planner's estimate for the average number of rows output from each |
| 7592 | ** iteration of the X-th loop. If the query planner's estimates was accurate, |
| @@ -7593,18 +7617,18 @@ | |
| 7593 | ** then this value will approximate the quotient NVISIT/NLOOP and the |
| 7594 | ** product of this value for all prior loops with the same SELECTID will |
| 7595 | ** be the NLOOP value for the current loop. |
| 7596 | ** |
| 7597 | ** [[SQLITE_SCANSTAT_NAME]] <dt>SQLITE_SCANSTAT_NAME</dt> |
| 7598 | ** <dd>^The "const char *" variable pointed to by the T parameter will be set to |
| 7599 | ** a zero-terminated UTF-8 string containing the name of the index or table used |
| 7600 | ** for the X-th loop. |
| 7601 | ** |
| 7602 | ** [[SQLITE_SCANSTAT_EXPLAIN]] <dt>SQLITE_SCANSTAT_EXPLAIN</dt> |
| 7603 | ** <dd>^The "const char *" variable pointed to by the T parameter will be set to |
| 7604 | ** a zero-terminated UTF-8 string containing the [EXPLAIN QUERY PLAN] description |
| 7605 | ** for the X-th loop. |
| 7606 | ** |
| 7607 | ** [[SQLITE_SCANSTAT_SELECTID]] <dt>SQLITE_SCANSTAT_SELECT</dt> |
| 7608 | ** <dd>^The "int" variable pointed to by the T parameter will be set to the |
| 7609 | ** "select-id" for the X-th loop. The select-id identifies which query or |
| 7610 | ** subquery the loop is part of. The main query has a select-id of zero. |
| @@ -7623,12 +7647,12 @@ | |
| 7623 | ** CAPI3REF: Prepared Statement Scan Status |
| 7624 | ** |
| 7625 | ** Return status data for a single loop within query pStmt. |
| 7626 | ** |
| 7627 | ** The "iScanStatusOp" parameter determines which status information to return. |
| 7628 | ** The "iScanStatusOp" must be one of the [scanstatus options] or the behavior of |
| 7629 | ** this interface is undefined. |
| 7630 | ** ^The requested measurement is written into a variable pointed to by |
| 7631 | ** the "pOut" parameter. |
| 7632 | ** Parameter "idx" identifies the specific loop to retrieve statistics for. |
| 7633 | ** Loops are numbered starting from zero. ^If idx is out of range - less than |
| 7634 | ** zero or greater than or equal to the total number of loops used to implement |
| @@ -11675,11 +11699,11 @@ | |
| 11675 | }; |
| 11676 | |
| 11677 | /* |
| 11678 | ** The following are the meanings of bits in the Expr.flags field. |
| 11679 | */ |
| 11680 | #define EP_FromJoin 0x000001 /* Originated in ON or USING clause of a join */ |
| 11681 | #define EP_Agg 0x000002 /* Contains one or more aggregate functions */ |
| 11682 | #define EP_Resolved 0x000004 /* IDs have been resolved to COLUMNs */ |
| 11683 | #define EP_Error 0x000008 /* Expression contains one or more errors */ |
| 11684 | #define EP_Distinct 0x000010 /* Aggregate function with DISTINCT keyword */ |
| 11685 | #define EP_VarSelect 0x000020 /* pSelect is correlated, not constant */ |
| @@ -11695,10 +11719,11 @@ | |
| 11695 | #define EP_Static 0x008000 /* Held in memory not obtained from malloc() */ |
| 11696 | #define EP_MemToken 0x010000 /* Need to sqlite3DbFree() Expr.zToken */ |
| 11697 | #define EP_NoReduce 0x020000 /* Cannot EXPRDUP_REDUCE this Expr */ |
| 11698 | #define EP_Unlikely 0x040000 /* unlikely() or likelihood() function */ |
| 11699 | #define EP_Constant 0x080000 /* Node is a constant */ |
| 11700 | |
| 11701 | /* |
| 11702 | ** These macros can be used to test, set, or clear bits in the |
| 11703 | ** Expr.flags field. |
| 11704 | */ |
| @@ -48199,11 +48224,12 @@ | |
| 48199 | */ |
| 48200 | SQLITE_PRIVATE int sqlite3PagerCheckpoint(Pager *pPager, int eMode, int *pnLog, int *pnCkpt){ |
| 48201 | int rc = SQLITE_OK; |
| 48202 | if( pPager->pWal ){ |
| 48203 | rc = sqlite3WalCheckpoint(pPager->pWal, eMode, |
| 48204 | pPager->xBusyHandler, pPager->pBusyHandlerArg, |
| 48205 | pPager->ckptSyncFlags, pPager->pageSize, (u8 *)pPager->pTmpSpace, |
| 48206 | pnLog, pnCkpt |
| 48207 | ); |
| 48208 | } |
| 48209 | return rc; |
| @@ -50009,10 +50035,42 @@ | |
| 50009 | ** Return the page-size in bytes used by the database. |
| 50010 | */ |
| 50011 | static int walPagesize(Wal *pWal){ |
| 50012 | return (pWal->hdr.szPage&0xfe00) + ((pWal->hdr.szPage&0x0001)<<16); |
| 50013 | } |
| 50014 | |
| 50015 | /* |
| 50016 | ** Copy as much content as we can from the WAL back into the database file |
| 50017 | ** in response to an sqlite3_wal_checkpoint() request or the equivalent. |
| 50018 | ** |
| @@ -50044,11 +50102,11 @@ | |
| 50044 | ** time. |
| 50045 | */ |
| 50046 | static int walCheckpoint( |
| 50047 | Wal *pWal, /* Wal connection */ |
| 50048 | int eMode, /* One of PASSIVE, FULL or RESTART */ |
| 50049 | int (*xBusyCall)(void*), /* Function to call when busy */ |
| 50050 | void *pBusyArg, /* Context argument for xBusyHandler */ |
| 50051 | int sync_flags, /* Flags for OsSync() (or 0) */ |
| 50052 | u8 *zBuf /* Temporary buffer to use */ |
| 50053 | ){ |
| 50054 | int rc; /* Return code */ |
| @@ -50058,11 +50116,10 @@ | |
| 50058 | u32 iFrame = 0; /* Wal frame containing data for iDbpage */ |
| 50059 | u32 mxSafeFrame; /* Max frame that can be backfilled */ |
| 50060 | u32 mxPage; /* Max database page to write */ |
| 50061 | int i; /* Loop counter */ |
| 50062 | volatile WalCkptInfo *pInfo; /* The checkpoint status information */ |
| 50063 | int (*xBusy)(void*) = 0; /* Function to call when waiting for locks */ |
| 50064 | |
| 50065 | szPage = walPagesize(pWal); |
| 50066 | testcase( szPage<=32768 ); |
| 50067 | testcase( szPage>=65536 ); |
| 50068 | pInfo = walCkptInfo(pWal); |
| @@ -50073,11 +50130,13 @@ | |
| 50073 | if( rc!=SQLITE_OK ){ |
| 50074 | return rc; |
| 50075 | } |
| 50076 | assert( pIter ); |
| 50077 | |
| 50078 | if( eMode!=SQLITE_CHECKPOINT_PASSIVE ) xBusy = xBusyCall; |
| 50079 | |
| 50080 | /* Compute in mxSafeFrame the index of the last frame of the WAL that is |
| 50081 | ** safe to write into the database. Frames beyond mxSafeFrame might |
| 50082 | ** overwrite database pages that are in use by active readers and thus |
| 50083 | ** cannot be backfilled from the WAL. |
| @@ -50162,23 +50221,42 @@ | |
| 50162 | /* Reset the return code so as not to report a checkpoint failure |
| 50163 | ** just because there are active readers. */ |
| 50164 | rc = SQLITE_OK; |
| 50165 | } |
| 50166 | |
| 50167 | /* If this is an SQLITE_CHECKPOINT_RESTART operation, and the entire wal |
| 50168 | ** file has been copied into the database file, then block until all |
| 50169 | ** readers have finished using the wal file. This ensures that the next |
| 50170 | ** process to write to the database restarts the wal file. |
| 50171 | */ |
| 50172 | if( rc==SQLITE_OK && eMode!=SQLITE_CHECKPOINT_PASSIVE ){ |
| 50173 | assert( pWal->writeLock ); |
| 50174 | if( pInfo->nBackfill<pWal->hdr.mxFrame ){ |
| 50175 | rc = SQLITE_BUSY; |
| 50176 | }else if( eMode==SQLITE_CHECKPOINT_RESTART ){ |
| 50177 | assert( mxSafeFrame==pWal->hdr.mxFrame ); |
| 50178 | rc = walBusyLock(pWal, xBusy, pBusyArg, WAL_READ_LOCK(1), WAL_NREADER-1); |
| 50179 | if( rc==SQLITE_OK ){ |
| 50180 | walUnlockExclusive(pWal, WAL_READ_LOCK(1), WAL_NREADER-1); |
| 50181 | } |
| 50182 | } |
| 50183 | } |
| 50184 | |
| @@ -50960,11 +51038,10 @@ | |
| 50960 | } |
| 50961 | |
| 50962 | return rc; |
| 50963 | } |
| 50964 | |
| 50965 | |
| 50966 | /* |
| 50967 | ** This function is called just before writing a set of frames to the log |
| 50968 | ** file (see sqlite3WalFrames()). It checks to see if, instead of appending |
| 50969 | ** to the current log file, it is possible to overwrite the start of the |
| 50970 | ** existing log file with the new frames (i.e. "reset" the log). If so, |
| @@ -50993,24 +51070,12 @@ | |
| 50993 | ** wal-index header to reflect this. |
| 50994 | ** |
| 50995 | ** In theory it would be Ok to update the cache of the header only |
| 50996 | ** at this point. But updating the actual wal-index header is also |
| 50997 | ** safe and means there is no special case for sqlite3WalUndo() |
| 50998 | ** to handle if this transaction is rolled back. |
| 50999 | */ |
| 51000 | int i; /* Loop counter */ |
| 51001 | u32 *aSalt = pWal->hdr.aSalt; /* Big-endian salt values */ |
| 51002 | |
| 51003 | pWal->nCkpt++; |
| 51004 | pWal->hdr.mxFrame = 0; |
| 51005 | sqlite3Put4byte((u8*)&aSalt[0], 1 + sqlite3Get4byte((u8*)&aSalt[0])); |
| 51006 | aSalt[1] = salt1; |
| 51007 | walIndexWriteHdr(pWal); |
| 51008 | pInfo->nBackfill = 0; |
| 51009 | pInfo->aReadMark[1] = 0; |
| 51010 | for(i=2; i<WAL_NREADER; i++) pInfo->aReadMark[i] = READMARK_NOT_USED; |
| 51011 | assert( pInfo->aReadMark[0]==0 ); |
| 51012 | walUnlockExclusive(pWal, WAL_READ_LOCK(1), WAL_NREADER-1); |
| 51013 | }else if( rc!=SQLITE_BUSY ){ |
| 51014 | return rc; |
| 51015 | } |
| 51016 | } |
| @@ -51294,11 +51359,11 @@ | |
| 51294 | ** If parameter xBusy is not NULL, it is a pointer to a busy-handler |
| 51295 | ** callback. In this case this function runs a blocking checkpoint. |
| 51296 | */ |
| 51297 | SQLITE_PRIVATE int sqlite3WalCheckpoint( |
| 51298 | Wal *pWal, /* Wal connection */ |
| 51299 | int eMode, /* PASSIVE, FULL or RESTART */ |
| 51300 | int (*xBusy)(void*), /* Function to call when busy */ |
| 51301 | void *pBusyArg, /* Context argument for xBusyHandler */ |
| 51302 | int sync_flags, /* Flags to sync db file with (or 0) */ |
| 51303 | int nBuf, /* Size of temporary buffer */ |
| 51304 | u8 *zBuf, /* Temporary buffer to use */ |
| @@ -51306,40 +51371,54 @@ | |
| 51306 | int *pnCkpt /* OUT: Number of backfilled frames in WAL */ |
| 51307 | ){ |
| 51308 | int rc; /* Return code */ |
| 51309 | int isChanged = 0; /* True if a new wal-index header is loaded */ |
| 51310 | int eMode2 = eMode; /* Mode to pass to walCheckpoint() */ |
| 51311 | |
| 51312 | assert( pWal->ckptLock==0 ); |
| 51313 | assert( pWal->writeLock==0 ); |
| 51314 | |
| 51315 | if( pWal->readOnly ) return SQLITE_READONLY; |
| 51316 | WALTRACE(("WAL%p: checkpoint begins\n", pWal)); |
| 51317 | rc = walLockExclusive(pWal, WAL_CKPT_LOCK, 1); |
| 51318 | if( rc ){ |
| 51319 | /* Usually this is SQLITE_BUSY meaning that another thread or process |
| 51320 | ** is already running a checkpoint, or maybe a recovery. But it might |
| 51321 | ** also be SQLITE_IOERR. */ |
| 51322 | return rc; |
| 51323 | } |
| 51324 | pWal->ckptLock = 1; |
| 51325 | |
| 51326 | /* If this is a blocking-checkpoint, then obtain the write-lock as well |
| 51327 | ** to prevent any writers from running while the checkpoint is underway. |
| 51328 | ** This has to be done before the call to walIndexReadHdr() below. |
| 51329 | ** |
| 51330 | ** If the writer lock cannot be obtained, then a passive checkpoint is |
| 51331 | ** run instead. Since the checkpointer is not holding the writer lock, |
| 51332 | ** there is no point in blocking waiting for any readers. Assuming no |
| 51333 | ** other error occurs, this function will return SQLITE_BUSY to the caller. |
| 51334 | */ |
| 51335 | if( eMode!=SQLITE_CHECKPOINT_PASSIVE ){ |
| 51336 | rc = walBusyLock(pWal, xBusy, pBusyArg, WAL_WRITE_LOCK, 1); |
| 51337 | if( rc==SQLITE_OK ){ |
| 51338 | pWal->writeLock = 1; |
| 51339 | }else if( rc==SQLITE_BUSY ){ |
| 51340 | eMode2 = SQLITE_CHECKPOINT_PASSIVE; |
| 51341 | rc = SQLITE_OK; |
| 51342 | } |
| 51343 | } |
| 51344 | |
| 51345 | /* Read the wal-index header. */ |
| @@ -51353,11 +51432,11 @@ | |
| 51353 | /* Copy data from the log to the database file. */ |
| 51354 | if( rc==SQLITE_OK ){ |
| 51355 | if( pWal->hdr.mxFrame && walPagesize(pWal)!=nBuf ){ |
| 51356 | rc = SQLITE_CORRUPT_BKPT; |
| 51357 | }else{ |
| 51358 | rc = walCheckpoint(pWal, eMode2, xBusy, pBusyArg, sync_flags, zBuf); |
| 51359 | } |
| 51360 | |
| 51361 | /* If no error occurred, set the output variables. */ |
| 51362 | if( rc==SQLITE_OK || rc==SQLITE_BUSY ){ |
| 51363 | if( pnLog ) *pnLog = (int)pWal->hdr.mxFrame; |
| @@ -53821,11 +53900,11 @@ | |
| 53821 | ** to see if defragmentation is necessary. |
| 53822 | */ |
| 53823 | testcase( gap+2+nByte==top ); |
| 53824 | if( gap+2+nByte>top ){ |
| 53825 | defragment_page: |
| 53826 | testcase( pPage->nCell==0 ); |
| 53827 | rc = defragmentPage(pPage); |
| 53828 | if( rc ) return rc; |
| 53829 | top = get2byteNotZero(&data[hdr+5]); |
| 53830 | assert( gap+nByte<=top ); |
| 53831 | } |
| @@ -58881,11 +58960,11 @@ | |
| 58881 | assert( sqlite3_mutex_held(pPage->pBt->mutex) ); |
| 58882 | assert( sqlite3PagerIswriteable(pParent->pDbPage) ); |
| 58883 | assert( pPage->nOverflow==1 ); |
| 58884 | |
| 58885 | /* This error condition is now caught prior to reaching this function */ |
| 58886 | if( pPage->nCell==0 ) return SQLITE_CORRUPT_BKPT; |
| 58887 | |
| 58888 | /* Allocate a new page. This page will become the right-sibling of |
| 58889 | ** pPage. Make the parent page writable, so that the new divider cell |
| 58890 | ** may be inserted. If both these operations are successful, proceed. |
| 58891 | */ |
| @@ -59324,11 +59403,15 @@ | |
| 59324 | ** pointer of the divider cell */ |
| 59325 | memcpy(apCell[nCell], &pOld->aData[8], 4); |
| 59326 | }else{ |
| 59327 | assert( leafCorrection==4 ); |
| 59328 | if( szCell[nCell]<4 ){ |
| 59329 | /* Do not allow any cells smaller than 4 bytes. */ |
| 59330 | szCell[nCell] = 4; |
| 59331 | } |
| 59332 | } |
| 59333 | nCell++; |
| 59334 | } |
| @@ -59559,11 +59642,15 @@ | |
| 59559 | ** was either part of sibling page iOld (possibly an overflow cell), |
| 59560 | ** or else the divider cell to the left of sibling page iOld. So, |
| 59561 | ** if sibling page iOld had the same page number as pNew, and if |
| 59562 | ** pCell really was a part of sibling page iOld (not a divider or |
| 59563 | ** overflow cell), we can skip updating the pointer map entries. */ |
| 59564 | if( pNew->pgno!=aPgno[iOld] || pCell<aOld || pCell>=&aOld[usableSize] ){ |
| 59565 | if( !leafCorrection ){ |
| 59566 | ptrmapPut(pBt, get4byte(pCell), PTRMAP_BTREE, pNew->pgno, &rc); |
| 59567 | } |
| 59568 | if( szCell[i]>pNew->minLocal ){ |
| 59569 | ptrmapPutOvflPtr(pNew, pCell, &rc); |
| @@ -65699,11 +65786,11 @@ | |
| 65699 | for(n=0; n<nVar; n++){ |
| 65700 | p->aVar[n].flags = MEM_Null; |
| 65701 | p->aVar[n].db = db; |
| 65702 | } |
| 65703 | } |
| 65704 | if( p->azVar ){ |
| 65705 | p->nzVar = pParse->nzVar; |
| 65706 | memcpy(p->azVar, pParse->azVar, p->nzVar*sizeof(p->azVar[0])); |
| 65707 | memset(pParse->azVar, 0, pParse->nzVar*sizeof(pParse->azVar[0])); |
| 65708 | } |
| 65709 | if( p->aMem ){ |
| @@ -75629,12 +75716,12 @@ | |
| 75629 | |
| 75630 | #ifndef SQLITE_OMIT_WAL |
| 75631 | /* Opcode: Checkpoint P1 P2 P3 * * |
| 75632 | ** |
| 75633 | ** Checkpoint database P1. This is a no-op if P1 is not currently in |
| 75634 | ** WAL mode. Parameter P2 is one of SQLITE_CHECKPOINT_PASSIVE, FULL |
| 75635 | ** or RESTART. Write 1 or 0 into mem[P3] if the checkpoint returns |
| 75636 | ** SQLITE_BUSY or not, respectively. Write the number of pages in the |
| 75637 | ** WAL after the checkpoint into mem[P3+1] and the number of pages |
| 75638 | ** in the WAL that have been checkpointed after the checkpoint |
| 75639 | ** completes into mem[P3+2]. However on an error, mem[P3+1] and |
| 75640 | ** mem[P3+2] are initialized to -1. |
| @@ -75648,10 +75735,11 @@ | |
| 75648 | aRes[0] = 0; |
| 75649 | aRes[1] = aRes[2] = -1; |
| 75650 | assert( pOp->p2==SQLITE_CHECKPOINT_PASSIVE |
| 75651 | || pOp->p2==SQLITE_CHECKPOINT_FULL |
| 75652 | || pOp->p2==SQLITE_CHECKPOINT_RESTART |
| 75653 | ); |
| 75654 | rc = sqlite3Checkpoint(db, pOp->p1, pOp->p2, &aRes[1], &aRes[2]); |
| 75655 | if( rc==SQLITE_BUSY ){ |
| 75656 | rc = SQLITE_OK; |
| 75657 | aRes[0] = 1; |
| @@ -80411,10 +80499,14 @@ | |
| 80411 | } |
| 80412 | } |
| 80413 | if( pMatch ){ |
| 80414 | pExpr->iTable = pMatch->iCursor; |
| 80415 | pExpr->pTab = pMatch->pTab; |
| 80416 | pSchema = pExpr->pTab->pSchema; |
| 80417 | } |
| 80418 | } /* if( pSrcList ) */ |
| 80419 | |
| 80420 | #ifndef SQLITE_OMIT_TRIGGER |
| @@ -82968,11 +83060,12 @@ | |
| 82968 | case TK_FLOAT: |
| 82969 | case TK_BLOB: |
| 82970 | return 0; |
| 82971 | case TK_COLUMN: |
| 82972 | assert( p->pTab!=0 ); |
| 82973 | return p->iColumn>=0 && p->pTab->aCol[p->iColumn].notNull==0; |
| 82974 | default: |
| 82975 | return 1; |
| 82976 | } |
| 82977 | } |
| 82978 | |
| @@ -88351,11 +88444,11 @@ | |
| 88351 | tRowcnt avgEq = 0; |
| 88352 | tRowcnt nRow; /* Number of rows in index */ |
| 88353 | i64 nSum100 = 0; /* Number of terms contributing to sumEq */ |
| 88354 | i64 nDist100; /* Number of distinct values in index */ |
| 88355 | |
| 88356 | if( pIdx->aiRowEst==0 || pIdx->aiRowEst[iCol+1]==0 ){ |
| 88357 | nRow = pFinal->anLt[iCol]; |
| 88358 | nDist100 = (i64)100 * pFinal->anDLt[iCol]; |
| 88359 | nSample--; |
| 88360 | }else{ |
| 88361 | nRow = pIdx->aiRowEst[0]; |
| @@ -103921,11 +104014,11 @@ | |
| 103921 | break; |
| 103922 | #endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */ |
| 103923 | |
| 103924 | #ifndef SQLITE_OMIT_WAL |
| 103925 | /* |
| 103926 | ** PRAGMA [database.]wal_checkpoint = passive|full|restart |
| 103927 | ** |
| 103928 | ** Checkpoint the database. |
| 103929 | */ |
| 103930 | case PragTyp_WAL_CHECKPOINT: { |
| 103931 | int iBt = (pId2->z?iDb:SQLITE_MAX_ATTACHED); |
| @@ -103933,10 +104026,12 @@ | |
| 103933 | if( zRight ){ |
| 103934 | if( sqlite3StrICmp(zRight, "full")==0 ){ |
| 103935 | eMode = SQLITE_CHECKPOINT_FULL; |
| 103936 | }else if( sqlite3StrICmp(zRight, "restart")==0 ){ |
| 103937 | eMode = SQLITE_CHECKPOINT_RESTART; |
| 103938 | } |
| 103939 | } |
| 103940 | sqlite3VdbeSetNumCols(v, 3); |
| 103941 | pParse->nMem = 3; |
| 103942 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "busy", SQLITE_STATIC); |
| @@ -109840,11 +109935,11 @@ | |
| 109840 | ** |
| 109841 | ** SELECT DISTINCT xyz FROM ... ORDER BY xyz |
| 109842 | ** |
| 109843 | ** is transformed to: |
| 109844 | ** |
| 109845 | ** SELECT xyz FROM ... GROUP BY xyz |
| 109846 | ** |
| 109847 | ** The second form is preferred as a single index (or temp-table) may be |
| 109848 | ** used for both the ORDER BY and DISTINCT processing. As originally |
| 109849 | ** written the query must use a temp-table for at least one of the ORDER |
| 109850 | ** BY and DISTINCT, and an index or separate temp-table for the other. |
| @@ -109853,11 +109948,10 @@ | |
| 109853 | && sqlite3ExprListCompare(sSort.pOrderBy, p->pEList, -1)==0 |
| 109854 | ){ |
| 109855 | p->selFlags &= ~SF_Distinct; |
| 109856 | p->pGroupBy = sqlite3ExprListDup(db, p->pEList, 0); |
| 109857 | pGroupBy = p->pGroupBy; |
| 109858 | sSort.pOrderBy = 0; |
| 109859 | /* Notice that even thought SF_Distinct has been cleared from p->selFlags, |
| 109860 | ** the sDistinct.isTnct is still set. Hence, isTnct represents the |
| 109861 | ** original setting of the SF_Distinct flag, not the current setting */ |
| 109862 | assert( sDistinct.isTnct ); |
| 109863 | } |
| @@ -114808,10 +114902,11 @@ | |
| 114808 | memcpy(pWC->a, pOld, sizeof(pWC->a[0])*pWC->nTerm); |
| 114809 | if( pOld!=pWC->aStatic ){ |
| 114810 | sqlite3DbFree(db, pOld); |
| 114811 | } |
| 114812 | pWC->nSlot = sqlite3DbMallocSize(db, pWC->a)/sizeof(pWC->a[0]); |
| 114813 | } |
| 114814 | pTerm = &pWC->a[idx = pWC->nTerm++]; |
| 114815 | if( p && ExprHasProperty(p, EP_Unlikely) ){ |
| 114816 | pTerm->truthProb = sqlite3LogEst(p->iTable) - 270; |
| 114817 | }else{ |
| @@ -117533,11 +117628,11 @@ | |
| 117533 | WhereLevel *pLvl, /* Level to add scanstatus() entry for */ |
| 117534 | int addrExplain /* Address of OP_Explain (or 0) */ |
| 117535 | ){ |
| 117536 | const char *zObj = 0; |
| 117537 | WhereLoop *pLoop = pLvl->pWLoop; |
| 117538 | if( (pLoop->wsFlags & (WHERE_IPK|WHERE_VIRTUALTABLE))==0 ){ |
| 117539 | zObj = pLoop->u.btree.pIndex->zName; |
| 117540 | }else{ |
| 117541 | zObj = pSrclist->a[pLvl->iFrom].zName; |
| 117542 | } |
| 117543 | sqlite3VdbeScanStatus( |
| @@ -118177,14 +118272,13 @@ | |
| 118177 | int iTerm; |
| 118178 | for(iTerm=0; iTerm<pWC->nTerm; iTerm++){ |
| 118179 | Expr *pExpr = pWC->a[iTerm].pExpr; |
| 118180 | if( &pWC->a[iTerm] == pTerm ) continue; |
| 118181 | if( ExprHasProperty(pExpr, EP_FromJoin) ) continue; |
| 118182 | testcase( pWC->a[iTerm].wtFlags & TERM_ORINFO ); |
| 118183 | testcase( pWC->a[iTerm].wtFlags & TERM_VIRTUAL ); |
| 118184 | if( pWC->a[iTerm].wtFlags & (TERM_ORINFO|TERM_VIRTUAL) ) continue; |
| 118185 | if( (pWC->a[iTerm].eOperator & WO_ALL)==0 ) continue; |
| 118186 | pExpr = sqlite3ExprDup(db, pExpr, 0); |
| 118187 | pAndExpr = sqlite3ExprAnd(db, pAndExpr, pExpr); |
| 118188 | } |
| 118189 | if( pAndExpr ){ |
| 118190 | pAndExpr = sqlite3PExpr(pParse, TK_AND, 0, pAndExpr, 0); |
| @@ -127079,10 +127173,18 @@ | |
| 127079 | |
| 127080 | /* Close all database connections */ |
| 127081 | for(j=0; j<db->nDb; j++){ |
| 127082 | struct Db *pDb = &db->aDb[j]; |
| 127083 | if( pDb->pBt ){ |
| 127084 | sqlite3BtreeClose(pDb->pBt); |
| 127085 | pDb->pBt = 0; |
| 127086 | if( j!=1 ){ |
| 127087 | pDb->pSchema = 0; |
| 127088 | } |
| @@ -127983,14 +128085,17 @@ | |
| 127983 | |
| 127984 | /* Initialize the output variables to -1 in case an error occurs. */ |
| 127985 | if( pnLog ) *pnLog = -1; |
| 127986 | if( pnCkpt ) *pnCkpt = -1; |
| 127987 | |
| 127988 | assert( SQLITE_CHECKPOINT_FULL>SQLITE_CHECKPOINT_PASSIVE ); |
| 127989 | assert( SQLITE_CHECKPOINT_FULL<SQLITE_CHECKPOINT_RESTART ); |
| 127990 | assert( SQLITE_CHECKPOINT_PASSIVE+2==SQLITE_CHECKPOINT_RESTART ); |
| 127991 | if( eMode<SQLITE_CHECKPOINT_PASSIVE || eMode>SQLITE_CHECKPOINT_RESTART ){ |
| 127992 | return SQLITE_MISUSE; |
| 127993 | } |
| 127994 | |
| 127995 | sqlite3_mutex_enter(db->mutex); |
| 127996 | if( zDb && zDb[0] ){ |
| @@ -128014,11 +128119,13 @@ | |
| 128014 | ** Checkpoint database zDb. If zDb is NULL, or if the buffer zDb points |
| 128015 | ** to contains a zero-length string, all attached databases are |
| 128016 | ** checkpointed. |
| 128017 | */ |
| 128018 | SQLITE_API int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb){ |
| 128019 | return sqlite3_wal_checkpoint_v2(db, zDb, SQLITE_CHECKPOINT_PASSIVE, 0, 0); |
| 128020 | } |
| 128021 | |
| 128022 | #ifndef SQLITE_OMIT_WAL |
| 128023 | /* |
| 128024 | ** Run a checkpoint on database iDb. This is a no-op if database iDb is |
| @@ -139164,11 +139271,11 @@ | |
| 139164 | ** Return true if the m-value for z is 1 or more. In other words, |
| 139165 | ** return true if z contains at least one vowel that is followed |
| 139166 | ** by a consonant. |
| 139167 | ** |
| 139168 | ** In this routine z[] is in reverse order. So we are really looking |
| 139169 | ** for an instance of of a consonant followed by a vowel. |
| 139170 | */ |
| 139171 | static int m_gt_0(const char *z){ |
| 139172 | while( isVowel(z) ){ z++; } |
| 139173 | if( *z==0 ) return 0; |
| 139174 | while( isConsonant(z) ){ z++; } |
| 139175 |
| --- src/sqlite3.c | |
| +++ src/sqlite3.c | |
| @@ -231,11 +231,11 @@ | |
| 231 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 232 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 233 | */ |
| 234 | #define SQLITE_VERSION "3.8.8" |
| 235 | #define SQLITE_VERSION_NUMBER 3008008 |
| 236 | #define SQLITE_SOURCE_ID "2014-12-06 14:56:49 6aeece19a235344be2537e66a3fe08b1febfb5a0" |
| 237 | |
| 238 | /* |
| 239 | ** CAPI3REF: Run-Time Library Version Numbers |
| 240 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 241 | ** |
| @@ -1343,11 +1343,11 @@ | |
| 1343 | ** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_SHARED |
| 1344 | ** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_EXCLUSIVE |
| 1345 | ** </ul> |
| 1346 | ** |
| 1347 | ** When unlocking, the same SHARED or EXCLUSIVE flag must be supplied as |
| 1348 | ** was given on the corresponding lock. |
| 1349 | ** |
| 1350 | ** The xShmLock method can transition between unlocked and SHARED or |
| 1351 | ** between unlocked and EXCLUSIVE. It cannot transition between SHARED |
| 1352 | ** and EXCLUSIVE. |
| 1353 | */ |
| @@ -1646,12 +1646,12 @@ | |
| 1646 | ** tracks memory usage, for example. </dd> |
| 1647 | ** |
| 1648 | ** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt> |
| 1649 | ** <dd> ^The SQLITE_CONFIG_MEMSTATUS option takes single argument of type int, |
| 1650 | ** interpreted as a boolean, which enables or disables the collection of |
| 1651 | ** memory allocation statistics. ^(When memory allocation statistics are |
| 1652 | ** disabled, the following SQLite interfaces become non-operational: |
| 1653 | ** <ul> |
| 1654 | ** <li> [sqlite3_memory_used()] |
| 1655 | ** <li> [sqlite3_memory_highwater()] |
| 1656 | ** <li> [sqlite3_soft_heap_limit64()] |
| 1657 | ** <li> [sqlite3_status()] |
| @@ -1688,11 +1688,12 @@ | |
| 1688 | ** that SQLite can use for the database page cache with the default page |
| 1689 | ** cache implementation. |
| 1690 | ** This configuration should not be used if an application-define page |
| 1691 | ** cache implementation is loaded using the [SQLITE_CONFIG_PCACHE2] |
| 1692 | ** configuration option. |
| 1693 | ** ^There are three arguments to SQLITE_CONFIG_PAGECACHE: A pointer to |
| 1694 | ** 8-byte aligned |
| 1695 | ** memory, the size of each page buffer (sz), and the number of pages (N). |
| 1696 | ** The sz argument should be the size of the largest database page |
| 1697 | ** (a power of two between 512 and 32768) plus some extra bytes for each |
| 1698 | ** page header. ^The number of extra bytes needed by the page header |
| 1699 | ** can be determined using the [SQLITE_CONFIG_PCACHE_HDRSZ] option |
| @@ -1708,11 +1709,12 @@ | |
| 1709 | ** SQLite goes to [sqlite3_malloc()] for the additional storage space.</dd> |
| 1710 | ** |
| 1711 | ** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt> |
| 1712 | ** <dd> ^The SQLITE_CONFIG_HEAP option specifies a static memory buffer |
| 1713 | ** that SQLite will use for all of its dynamic memory allocation needs |
| 1714 | ** beyond those provided for by [SQLITE_CONFIG_SCRATCH] and |
| 1715 | ** [SQLITE_CONFIG_PAGECACHE]. |
| 1716 | ** ^The SQLITE_CONFIG_HEAP option is only available if SQLite is compiled |
| 1717 | ** with either [SQLITE_ENABLE_MEMSYS3] or [SQLITE_ENABLE_MEMSYS5] and returns |
| 1718 | ** [SQLITE_ERROR] if invoked otherwise. |
| 1719 | ** ^There are three arguments to SQLITE_CONFIG_HEAP: |
| 1720 | ** An 8-byte aligned pointer to the memory, |
| @@ -1728,13 +1730,13 @@ | |
| 1730 | ** for the minimum allocation size are 2**5 through 2**8.</dd> |
| 1731 | ** |
| 1732 | ** [[SQLITE_CONFIG_MUTEX]] <dt>SQLITE_CONFIG_MUTEX</dt> |
| 1733 | ** <dd> ^(The SQLITE_CONFIG_MUTEX option takes a single argument which is a |
| 1734 | ** pointer to an instance of the [sqlite3_mutex_methods] structure. |
| 1735 | ** The argument specifies alternative low-level mutex routines to be used |
| 1736 | ** in place the mutex routines built into SQLite.)^ ^SQLite makes a copy of |
| 1737 | ** the content of the [sqlite3_mutex_methods] structure before the call to |
| 1738 | ** [sqlite3_config()] returns. ^If SQLite is compiled with |
| 1739 | ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then |
| 1740 | ** the entire mutexing subsystem is omitted from the build and hence calls to |
| 1741 | ** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will |
| 1742 | ** return [SQLITE_ERROR].</dd> |
| @@ -1768,12 +1770,12 @@ | |
| 1770 | ** the interface to a custom page cache implementation.)^ |
| 1771 | ** ^SQLite makes a copy of the [sqlite3_pcache_methods2] object.</dd> |
| 1772 | ** |
| 1773 | ** [[SQLITE_CONFIG_GETPCACHE2]] <dt>SQLITE_CONFIG_GETPCACHE2</dt> |
| 1774 | ** <dd> ^(The SQLITE_CONFIG_GETPCACHE2 option takes a single argument which |
| 1775 | ** is a pointer to an [sqlite3_pcache_methods2] object. SQLite copies of |
| 1776 | ** the current page cache implementation into that object.)^ </dd> |
| 1777 | ** |
| 1778 | ** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt> |
| 1779 | ** <dd> The SQLITE_CONFIG_LOG option is used to configure the SQLite |
| 1780 | ** global [error log]. |
| 1781 | ** (^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a |
| @@ -1794,12 +1796,13 @@ | |
| 1796 | ** function must be threadsafe. </dd> |
| 1797 | ** |
| 1798 | ** [[SQLITE_CONFIG_URI]] <dt>SQLITE_CONFIG_URI |
| 1799 | ** <dd>^(The SQLITE_CONFIG_URI option takes a single argument of type int. |
| 1800 | ** If non-zero, then URI handling is globally enabled. If the parameter is zero, |
| 1801 | ** then URI handling is globally disabled.)^ ^If URI handling is globally |
| 1802 | ** enabled, all filenames passed to [sqlite3_open()], [sqlite3_open_v2()], |
| 1803 | ** [sqlite3_open16()] or |
| 1804 | ** specified as part of [ATTACH] commands are interpreted as URIs, regardless |
| 1805 | ** of whether or not the [SQLITE_OPEN_URI] flag is set when the database |
| 1806 | ** connection is opened. ^If it is globally disabled, filenames are |
| 1807 | ** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the |
| 1808 | ** database connection is opened. ^(By default, URI handling is globally |
| @@ -1857,21 +1860,21 @@ | |
| 1860 | ** changed to its compile-time default. |
| 1861 | ** |
| 1862 | ** [[SQLITE_CONFIG_WIN32_HEAPSIZE]] |
| 1863 | ** <dt>SQLITE_CONFIG_WIN32_HEAPSIZE |
| 1864 | ** <dd>^The SQLITE_CONFIG_WIN32_HEAPSIZE option is only available if SQLite is |
| 1865 | ** compiled for Windows with the [SQLITE_WIN32_MALLOC] pre-processor macro |
| 1866 | ** defined. ^SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit unsigned integer value |
| 1867 | ** that specifies the maximum size of the created heap. |
| 1868 | ** </dl> |
| 1869 | ** |
| 1870 | ** [[SQLITE_CONFIG_PCACHE_HDRSZ]] |
| 1871 | ** <dt>SQLITE_CONFIG_PCACHE_HDRSZ |
| 1872 | ** <dd>^The SQLITE_CONFIG_PCACHE_HDRSZ option takes a single parameter which |
| 1873 | ** is a pointer to an integer and writes into that integer the number of extra |
| 1874 | ** bytes per page required for each page in [SQLITE_CONFIG_PAGECACHE]. |
| 1875 | ** The amount of extra space required can change depending on the compiler, |
| 1876 | ** target platform, and SQLite version. |
| 1877 | ** </dl> |
| 1878 | */ |
| 1879 | #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */ |
| 1880 | #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */ |
| @@ -2171,10 +2174,11 @@ | |
| 2174 | SQLITE_API int sqlite3_complete(const char *sql); |
| 2175 | SQLITE_API int sqlite3_complete16(const void *sql); |
| 2176 | |
| 2177 | /* |
| 2178 | ** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors |
| 2179 | ** KEYWORDS: {busy-handler callback} {busy handler} |
| 2180 | ** |
| 2181 | ** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X |
| 2182 | ** that might be invoked with argument P whenever |
| 2183 | ** an attempt is made to access a database table associated with |
| 2184 | ** [database connection] D when another thread |
| @@ -2187,11 +2191,11 @@ | |
| 2191 | ** is not NULL, then the callback might be invoked with two arguments. |
| 2192 | ** |
| 2193 | ** ^The first argument to the busy handler is a copy of the void* pointer which |
| 2194 | ** is the third argument to sqlite3_busy_handler(). ^The second argument to |
| 2195 | ** the busy handler callback is the number of times that the busy handler has |
| 2196 | ** been invoked previously for the same locking event. ^If the |
| 2197 | ** busy callback returns 0, then no additional attempts are made to |
| 2198 | ** access the database and [SQLITE_BUSY] is returned |
| 2199 | ** to the application. |
| 2200 | ** ^If the callback returns non-zero, then another attempt |
| 2201 | ** is made to access the database and the cycle repeats. |
| @@ -4642,11 +4646,12 @@ | |
| 4646 | ** If these routines are called from within the different thread |
| 4647 | ** than the one containing the application-defined function that received |
| 4648 | ** the [sqlite3_context] pointer, the results are undefined. |
| 4649 | */ |
| 4650 | SQLITE_API void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*)); |
| 4651 | SQLITE_API void sqlite3_result_blob64(sqlite3_context*,const void*, |
| 4652 | sqlite3_uint64,void(*)(void*)); |
| 4653 | SQLITE_API void sqlite3_result_double(sqlite3_context*, double); |
| 4654 | SQLITE_API void sqlite3_result_error(sqlite3_context*, const char*, int); |
| 4655 | SQLITE_API void sqlite3_result_error16(sqlite3_context*, const void*, int); |
| 4656 | SQLITE_API void sqlite3_result_error_toobig(sqlite3_context*); |
| 4657 | SQLITE_API void sqlite3_result_error_nomem(sqlite3_context*); |
| @@ -7368,101 +7373,118 @@ | |
| 7373 | SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int N); |
| 7374 | |
| 7375 | /* |
| 7376 | ** CAPI3REF: Checkpoint a database |
| 7377 | ** |
| 7378 | ** ^(The sqlite3_wal_checkpoint(D,X) is equivalent to |
| 7379 | ** [sqlite3_wal_checkpoint_v2](D,X,[SQLITE_CHECKPOINT_PASSIVE],0,0).)^ |
| 7380 | ** |
| 7381 | ** In brief, sqlite3_wal_checkpoint(D,X) causes the content in the |
| 7382 | ** [write-ahead log] for database X on [database connection] D to be |
| 7383 | ** transferred into the database file and for the write-ahead log to |
| 7384 | ** be reset. See the [checkpointing] documentation for addition |
| 7385 | ** information. |
| 7386 | ** |
| 7387 | ** This interface used to be the only way to cause a checkpoint to |
| 7388 | ** occur. But then the newer and more powerful [sqlite3_wal_checkpoint_v2()] |
| 7389 | ** interface was added. This interface is retained for backwards |
| 7390 | ** compatibility and as a convenience for applications that need to manually |
| 7391 | ** start a callback but which do not need the full power (and corresponding |
| 7392 | ** complication) of [sqlite3_wal_checkpoint_v2()]. |
| 7393 | */ |
| 7394 | SQLITE_API int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb); |
| 7395 | |
| 7396 | /* |
| 7397 | ** CAPI3REF: Checkpoint a database |
| 7398 | ** |
| 7399 | ** ^(The sqlite3_wal_checkpoint_v2(D,X,M,L,C) interface runs a checkpoint |
| 7400 | ** operation on database X of [database connection] D in mode M. Status |
| 7401 | ** information is written back into integers pointed to by L and C.)^ |
| 7402 | ** ^(The M parameter must be a valid [checkpoint mode]:)^ |
| 7403 | ** |
| 7404 | ** <dl> |
| 7405 | ** <dt>SQLITE_CHECKPOINT_PASSIVE<dd> |
| 7406 | ** ^Checkpoint as many frames as possible without waiting for any database |
| 7407 | ** readers or writers to finish, then sync the database file if all frames |
| 7408 | ** in the log were checkpointed. ^The [busy-handler callback] |
| 7409 | ** is never invoked in the SQLITE_CHECKPOINT_PASSIVE mode. |
| 7410 | ** ^On the other hand, passive mode might leave the checkpoint unfinished |
| 7411 | ** if there are concurrent readers or writers. |
| 7412 | ** |
| 7413 | ** <dt>SQLITE_CHECKPOINT_FULL<dd> |
| 7414 | ** ^This mode blocks (it invokes the |
| 7415 | ** [sqlite3_busy_handler|busy-handler callback]) until there is no |
| 7416 | ** database writer and all readers are reading from the most recent database |
| 7417 | ** snapshot. ^It then checkpoints all frames in the log file and syncs the |
| 7418 | ** database file. ^This mode blocks new database writers while it is pending, |
| 7419 | ** but new database readers are allowed to continue unimpeded. |
| 7420 | ** |
| 7421 | ** <dt>SQLITE_CHECKPOINT_RESTART<dd> |
| 7422 | ** ^This mode works the same way as SQLITE_CHECKPOINT_FULL with the addition |
| 7423 | ** that after checkpointing the log file it blocks (calls the |
| 7424 | ** [busy-handler callback]) |
| 7425 | ** until all readers are reading from the database file only. ^This ensures |
| 7426 | ** that the next writer will restart the log file from the beginning. |
| 7427 | ** ^Like SQLITE_CHECKPOINT_FULL, this mode blocks new |
| 7428 | ** database writer attempts while it is pending, but does not impede readers. |
| 7429 | ** |
| 7430 | ** <dt>SQLITE_CHECKPOINT_TRUNCATE<dd> |
| 7431 | ** ^This mode works the same way as SQLITE_CHECKPOINT_RESTART with the |
| 7432 | ** addition that it also truncates the log file to zero bytes just prior |
| 7433 | ** to a successful return. |
| 7434 | ** </dl> |
| 7435 | ** |
| 7436 | ** ^If pnLog is not NULL, then *pnLog is set to the total number of frames in |
| 7437 | ** the log file or to -1 if the checkpoint could not run because |
| 7438 | ** of an error or because the database is not in [WAL mode]. ^If pnCkpt is not |
| 7439 | ** NULL,then *pnCkpt is set to the total number of checkpointed frames in the |
| 7440 | ** log file (including any that were already checkpointed before the function |
| 7441 | ** was called) or to -1 if the checkpoint could not run due to an error or |
| 7442 | ** because the database is not in WAL mode. ^Note that upon successful |
| 7443 | ** completion of an SQLITE_CHECKPOINT_TRUNCATE, the log file will have been |
| 7444 | ** truncated to zero bytes and so both *pnLog and *pnCkpt will be set to zero. |
| 7445 | ** |
| 7446 | ** ^All calls obtain an exclusive "checkpoint" lock on the database file. ^If |
| 7447 | ** any other process is running a checkpoint operation at the same time, the |
| 7448 | ** lock cannot be obtained and SQLITE_BUSY is returned. ^Even if there is a |
| 7449 | ** busy-handler configured, it will not be invoked in this case. |
| 7450 | ** |
| 7451 | ** ^The SQLITE_CHECKPOINT_FULL, RESTART and TRUNCATE modes also obtain the |
| 7452 | ** exclusive "writer" lock on the database file. ^If the writer lock cannot be |
| 7453 | ** obtained immediately, and a busy-handler is configured, it is invoked and |
| 7454 | ** the writer lock retried until either the busy-handler returns 0 or the lock |
| 7455 | ** is successfully obtained. ^The busy-handler is also invoked while waiting for |
| 7456 | ** database readers as described above. ^If the busy-handler returns 0 before |
| 7457 | ** the writer lock is obtained or while waiting for database readers, the |
| 7458 | ** checkpoint operation proceeds from that point in the same way as |
| 7459 | ** SQLITE_CHECKPOINT_PASSIVE - checkpointing as many frames as possible |
| 7460 | ** without blocking any further. ^SQLITE_BUSY is returned in this case. |
| 7461 | ** |
| 7462 | ** ^If parameter zDb is NULL or points to a zero length string, then the |
| 7463 | ** specified operation is attempted on all WAL databases [attached] to |
| 7464 | ** [database connection] db. In this case the |
| 7465 | ** values written to output parameters *pnLog and *pnCkpt are undefined. ^If |
| 7466 | ** an SQLITE_BUSY error is encountered when processing one or more of the |
| 7467 | ** attached WAL databases, the operation is still attempted on any remaining |
| 7468 | ** attached databases and SQLITE_BUSY is returned at the end. ^If any other |
| 7469 | ** error occurs while processing an attached database, processing is abandoned |
| 7470 | ** and the error code is returned to the caller immediately. ^If no error |
| 7471 | ** (SQLITE_BUSY or otherwise) is encountered while processing the attached |
| 7472 | ** databases, SQLITE_OK is returned. |
| 7473 | ** |
| 7474 | ** ^If database zDb is the name of an attached database that is not in WAL |
| 7475 | ** mode, SQLITE_OK is returned and both *pnLog and *pnCkpt set to -1. ^If |
| 7476 | ** zDb is not NULL (or a zero length string) and is not the name of any |
| 7477 | ** attached database, SQLITE_ERROR is returned to the caller. |
| 7478 | ** |
| 7479 | ** ^Unless it returns SQLITE_MISUSE, |
| 7480 | ** the sqlite3_wal_checkpoint_v2() interface |
| 7481 | ** sets the error information that is queried by |
| 7482 | ** [sqlite3_errcode()] and [sqlite3_errmsg()]. |
| 7483 | ** |
| 7484 | ** ^The [PRAGMA wal_checkpoint] command can be used to invoke this interface |
| 7485 | ** from SQL. |
| 7486 | */ |
| 7487 | SQLITE_API int sqlite3_wal_checkpoint_v2( |
| 7488 | sqlite3 *db, /* Database handle */ |
| 7489 | const char *zDb, /* Name of attached database (or NULL) */ |
| 7490 | int eMode, /* SQLITE_CHECKPOINT_* value */ |
| @@ -7469,20 +7491,22 @@ | |
| 7491 | int *pnLog, /* OUT: Size of WAL log in frames */ |
| 7492 | int *pnCkpt /* OUT: Total number of frames checkpointed */ |
| 7493 | ); |
| 7494 | |
| 7495 | /* |
| 7496 | ** CAPI3REF: Checkpoint Mode Values |
| 7497 | ** KEYWORDS: {checkpoint mode} |
| 7498 | ** |
| 7499 | ** These constants define all valid values for the "checkpoint mode" passed |
| 7500 | ** as the third parameter to the [sqlite3_wal_checkpoint_v2()] interface. |
| 7501 | ** See the [sqlite3_wal_checkpoint_v2()] documentation for details on the |
| 7502 | ** meaning of each of these checkpoint modes. |
| 7503 | */ |
| 7504 | #define SQLITE_CHECKPOINT_PASSIVE 0 /* Do as much as possible w/o blocking */ |
| 7505 | #define SQLITE_CHECKPOINT_FULL 1 /* Wait for writers, then checkpoint */ |
| 7506 | #define SQLITE_CHECKPOINT_RESTART 2 /* Like FULL but wait for for readers */ |
| 7507 | #define SQLITE_CHECKPOINT_TRUNCATE 3 /* Like RESTART but also truncate WAL */ |
| 7508 | |
| 7509 | /* |
| 7510 | ** CAPI3REF: Virtual Table Interface Configuration |
| 7511 | ** |
| 7512 | ** This function may be called by either the [xConnect] or [xCreate] method |
| @@ -7577,16 +7601,16 @@ | |
| 7601 | ** [sqlite3_stmt_scanstatus(S,X,T,V)] interface. Each constant designates a |
| 7602 | ** different metric for sqlite3_stmt_scanstatus() to return. |
| 7603 | ** |
| 7604 | ** <dl> |
| 7605 | ** [[SQLITE_SCANSTAT_NLOOP]] <dt>SQLITE_SCANSTAT_NLOOP</dt> |
| 7606 | ** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be |
| 7607 | ** set to the total number of times that the X-th loop has run.</dd> |
| 7608 | ** |
| 7609 | ** [[SQLITE_SCANSTAT_NVISIT]] <dt>SQLITE_SCANSTAT_NVISIT</dt> |
| 7610 | ** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be set |
| 7611 | ** to the total number of rows examined by all iterations of the X-th loop.</dd> |
| 7612 | ** |
| 7613 | ** [[SQLITE_SCANSTAT_EST]] <dt>SQLITE_SCANSTAT_EST</dt> |
| 7614 | ** <dd>^The "double" variable pointed to by the T parameter will be set to the |
| 7615 | ** query planner's estimate for the average number of rows output from each |
| 7616 | ** iteration of the X-th loop. If the query planner's estimates was accurate, |
| @@ -7593,18 +7617,18 @@ | |
| 7617 | ** then this value will approximate the quotient NVISIT/NLOOP and the |
| 7618 | ** product of this value for all prior loops with the same SELECTID will |
| 7619 | ** be the NLOOP value for the current loop. |
| 7620 | ** |
| 7621 | ** [[SQLITE_SCANSTAT_NAME]] <dt>SQLITE_SCANSTAT_NAME</dt> |
| 7622 | ** <dd>^The "const char *" variable pointed to by the T parameter will be set |
| 7623 | ** to a zero-terminated UTF-8 string containing the name of the index or table |
| 7624 | ** used for the X-th loop. |
| 7625 | ** |
| 7626 | ** [[SQLITE_SCANSTAT_EXPLAIN]] <dt>SQLITE_SCANSTAT_EXPLAIN</dt> |
| 7627 | ** <dd>^The "const char *" variable pointed to by the T parameter will be set |
| 7628 | ** to a zero-terminated UTF-8 string containing the [EXPLAIN QUERY PLAN] |
| 7629 | ** description for the X-th loop. |
| 7630 | ** |
| 7631 | ** [[SQLITE_SCANSTAT_SELECTID]] <dt>SQLITE_SCANSTAT_SELECT</dt> |
| 7632 | ** <dd>^The "int" variable pointed to by the T parameter will be set to the |
| 7633 | ** "select-id" for the X-th loop. The select-id identifies which query or |
| 7634 | ** subquery the loop is part of. The main query has a select-id of zero. |
| @@ -7623,12 +7647,12 @@ | |
| 7647 | ** CAPI3REF: Prepared Statement Scan Status |
| 7648 | ** |
| 7649 | ** Return status data for a single loop within query pStmt. |
| 7650 | ** |
| 7651 | ** The "iScanStatusOp" parameter determines which status information to return. |
| 7652 | ** The "iScanStatusOp" must be one of the [scanstatus options] or the behavior |
| 7653 | ** of this interface is undefined. |
| 7654 | ** ^The requested measurement is written into a variable pointed to by |
| 7655 | ** the "pOut" parameter. |
| 7656 | ** Parameter "idx" identifies the specific loop to retrieve statistics for. |
| 7657 | ** Loops are numbered starting from zero. ^If idx is out of range - less than |
| 7658 | ** zero or greater than or equal to the total number of loops used to implement |
| @@ -11675,11 +11699,11 @@ | |
| 11699 | }; |
| 11700 | |
| 11701 | /* |
| 11702 | ** The following are the meanings of bits in the Expr.flags field. |
| 11703 | */ |
| 11704 | #define EP_FromJoin 0x000001 /* Originates in ON/USING clause of outer join */ |
| 11705 | #define EP_Agg 0x000002 /* Contains one or more aggregate functions */ |
| 11706 | #define EP_Resolved 0x000004 /* IDs have been resolved to COLUMNs */ |
| 11707 | #define EP_Error 0x000008 /* Expression contains one or more errors */ |
| 11708 | #define EP_Distinct 0x000010 /* Aggregate function with DISTINCT keyword */ |
| 11709 | #define EP_VarSelect 0x000020 /* pSelect is correlated, not constant */ |
| @@ -11695,10 +11719,11 @@ | |
| 11719 | #define EP_Static 0x008000 /* Held in memory not obtained from malloc() */ |
| 11720 | #define EP_MemToken 0x010000 /* Need to sqlite3DbFree() Expr.zToken */ |
| 11721 | #define EP_NoReduce 0x020000 /* Cannot EXPRDUP_REDUCE this Expr */ |
| 11722 | #define EP_Unlikely 0x040000 /* unlikely() or likelihood() function */ |
| 11723 | #define EP_Constant 0x080000 /* Node is a constant */ |
| 11724 | #define EP_CanBeNull 0x100000 /* Can be null despite NOT NULL constraint */ |
| 11725 | |
| 11726 | /* |
| 11727 | ** These macros can be used to test, set, or clear bits in the |
| 11728 | ** Expr.flags field. |
| 11729 | */ |
| @@ -48199,11 +48224,12 @@ | |
| 48224 | */ |
| 48225 | SQLITE_PRIVATE int sqlite3PagerCheckpoint(Pager *pPager, int eMode, int *pnLog, int *pnCkpt){ |
| 48226 | int rc = SQLITE_OK; |
| 48227 | if( pPager->pWal ){ |
| 48228 | rc = sqlite3WalCheckpoint(pPager->pWal, eMode, |
| 48229 | (eMode==SQLITE_CHECKPOINT_PASSIVE ? 0 : pPager->xBusyHandler), |
| 48230 | pPager->pBusyHandlerArg, |
| 48231 | pPager->ckptSyncFlags, pPager->pageSize, (u8 *)pPager->pTmpSpace, |
| 48232 | pnLog, pnCkpt |
| 48233 | ); |
| 48234 | } |
| 48235 | return rc; |
| @@ -50009,10 +50035,42 @@ | |
| 50035 | ** Return the page-size in bytes used by the database. |
| 50036 | */ |
| 50037 | static int walPagesize(Wal *pWal){ |
| 50038 | return (pWal->hdr.szPage&0xfe00) + ((pWal->hdr.szPage&0x0001)<<16); |
| 50039 | } |
| 50040 | |
| 50041 | /* |
| 50042 | ** The following is guaranteed when this function is called: |
| 50043 | ** |
| 50044 | ** a) the WRITER lock is held, |
| 50045 | ** b) the entire log file has been checkpointed, and |
| 50046 | ** c) any existing readers are reading exclusively from the database |
| 50047 | ** file - there are no readers that may attempt to read a frame from |
| 50048 | ** the log file. |
| 50049 | ** |
| 50050 | ** This function updates the shared-memory structures so that the next |
| 50051 | ** client to write to the database (which may be this one) does so by |
| 50052 | ** writing frames into the start of the log file. |
| 50053 | ** |
| 50054 | ** The value of parameter salt1 is used as the aSalt[1] value in the |
| 50055 | ** new wal-index header. It should be passed a pseudo-random value (i.e. |
| 50056 | ** one obtained from sqlite3_randomness()). |
| 50057 | */ |
| 50058 | static void walRestartHdr(Wal *pWal, u32 salt1){ |
| 50059 | volatile WalCkptInfo *pInfo = walCkptInfo(pWal); |
| 50060 | int i; /* Loop counter */ |
| 50061 | u32 *aSalt = pWal->hdr.aSalt; /* Big-endian salt values */ |
| 50062 | pWal->nCkpt++; |
| 50063 | pWal->hdr.mxFrame = 0; |
| 50064 | sqlite3Put4byte((u8*)&aSalt[0], 1 + sqlite3Get4byte((u8*)&aSalt[0])); |
| 50065 | memcpy(&pWal->hdr.aSalt[1], &salt1, 4); |
| 50066 | walIndexWriteHdr(pWal); |
| 50067 | pInfo->nBackfill = 0; |
| 50068 | pInfo->aReadMark[1] = 0; |
| 50069 | for(i=2; i<WAL_NREADER; i++) pInfo->aReadMark[i] = READMARK_NOT_USED; |
| 50070 | assert( pInfo->aReadMark[0]==0 ); |
| 50071 | } |
| 50072 | |
| 50073 | /* |
| 50074 | ** Copy as much content as we can from the WAL back into the database file |
| 50075 | ** in response to an sqlite3_wal_checkpoint() request or the equivalent. |
| 50076 | ** |
| @@ -50044,11 +50102,11 @@ | |
| 50102 | ** time. |
| 50103 | */ |
| 50104 | static int walCheckpoint( |
| 50105 | Wal *pWal, /* Wal connection */ |
| 50106 | int eMode, /* One of PASSIVE, FULL or RESTART */ |
| 50107 | int (*xBusy)(void*), /* Function to call when busy */ |
| 50108 | void *pBusyArg, /* Context argument for xBusyHandler */ |
| 50109 | int sync_flags, /* Flags for OsSync() (or 0) */ |
| 50110 | u8 *zBuf /* Temporary buffer to use */ |
| 50111 | ){ |
| 50112 | int rc; /* Return code */ |
| @@ -50058,11 +50116,10 @@ | |
| 50116 | u32 iFrame = 0; /* Wal frame containing data for iDbpage */ |
| 50117 | u32 mxSafeFrame; /* Max frame that can be backfilled */ |
| 50118 | u32 mxPage; /* Max database page to write */ |
| 50119 | int i; /* Loop counter */ |
| 50120 | volatile WalCkptInfo *pInfo; /* The checkpoint status information */ |
| 50121 | |
| 50122 | szPage = walPagesize(pWal); |
| 50123 | testcase( szPage<=32768 ); |
| 50124 | testcase( szPage>=65536 ); |
| 50125 | pInfo = walCkptInfo(pWal); |
| @@ -50073,11 +50130,13 @@ | |
| 50130 | if( rc!=SQLITE_OK ){ |
| 50131 | return rc; |
| 50132 | } |
| 50133 | assert( pIter ); |
| 50134 | |
| 50135 | /* EVIDENCE-OF: R-62920-47450 The busy-handler callback is never invoked |
| 50136 | ** in the SQLITE_CHECKPOINT_PASSIVE mode. */ |
| 50137 | assert( eMode!=SQLITE_CHECKPOINT_PASSIVE || xBusy==0 ); |
| 50138 | |
| 50139 | /* Compute in mxSafeFrame the index of the last frame of the WAL that is |
| 50140 | ** safe to write into the database. Frames beyond mxSafeFrame might |
| 50141 | ** overwrite database pages that are in use by active readers and thus |
| 50142 | ** cannot be backfilled from the WAL. |
| @@ -50162,23 +50221,42 @@ | |
| 50221 | /* Reset the return code so as not to report a checkpoint failure |
| 50222 | ** just because there are active readers. */ |
| 50223 | rc = SQLITE_OK; |
| 50224 | } |
| 50225 | |
| 50226 | /* If this is an SQLITE_CHECKPOINT_RESTART or TRUNCATE operation, and the |
| 50227 | ** entire wal file has been copied into the database file, then block |
| 50228 | ** until all readers have finished using the wal file. This ensures that |
| 50229 | ** the next process to write to the database restarts the wal file. |
| 50230 | */ |
| 50231 | if( rc==SQLITE_OK && eMode!=SQLITE_CHECKPOINT_PASSIVE ){ |
| 50232 | assert( pWal->writeLock ); |
| 50233 | if( pInfo->nBackfill<pWal->hdr.mxFrame ){ |
| 50234 | rc = SQLITE_BUSY; |
| 50235 | }else if( eMode>=SQLITE_CHECKPOINT_RESTART ){ |
| 50236 | u32 salt1; |
| 50237 | sqlite3_randomness(4, &salt1); |
| 50238 | assert( mxSafeFrame==pWal->hdr.mxFrame ); |
| 50239 | rc = walBusyLock(pWal, xBusy, pBusyArg, WAL_READ_LOCK(1), WAL_NREADER-1); |
| 50240 | if( rc==SQLITE_OK ){ |
| 50241 | if( eMode==SQLITE_CHECKPOINT_TRUNCATE ){ |
| 50242 | /* IMPLEMENTATION-OF: R-44699-57140 This mode works the same way as |
| 50243 | ** SQLITE_CHECKPOINT_RESTART with the addition that it also |
| 50244 | ** truncates the log file to zero bytes just prior to a |
| 50245 | ** successful return. |
| 50246 | ** |
| 50247 | ** In theory, it might be safe to do this without updating the |
| 50248 | ** wal-index header in shared memory, as all subsequent reader or |
| 50249 | ** writer clients should see that the entire log file has been |
| 50250 | ** checkpointed and behave accordingly. This seems unsafe though, |
| 50251 | ** as it would leave the system in a state where the contents of |
| 50252 | ** the wal-index header do not match the contents of the |
| 50253 | ** file-system. To avoid this, update the wal-index header to |
| 50254 | ** indicate that the log file contains zero valid frames. */ |
| 50255 | walRestartHdr(pWal, salt1); |
| 50256 | rc = sqlite3OsTruncate(pWal->pWalFd, 0); |
| 50257 | } |
| 50258 | walUnlockExclusive(pWal, WAL_READ_LOCK(1), WAL_NREADER-1); |
| 50259 | } |
| 50260 | } |
| 50261 | } |
| 50262 | |
| @@ -50960,11 +51038,10 @@ | |
| 51038 | } |
| 51039 | |
| 51040 | return rc; |
| 51041 | } |
| 51042 | |
| 51043 | /* |
| 51044 | ** This function is called just before writing a set of frames to the log |
| 51045 | ** file (see sqlite3WalFrames()). It checks to see if, instead of appending |
| 51046 | ** to the current log file, it is possible to overwrite the start of the |
| 51047 | ** existing log file with the new frames (i.e. "reset" the log). If so, |
| @@ -50993,24 +51070,12 @@ | |
| 51070 | ** wal-index header to reflect this. |
| 51071 | ** |
| 51072 | ** In theory it would be Ok to update the cache of the header only |
| 51073 | ** at this point. But updating the actual wal-index header is also |
| 51074 | ** safe and means there is no special case for sqlite3WalUndo() |
| 51075 | ** to handle if this transaction is rolled back. */ |
| 51076 | walRestartHdr(pWal, salt1); |
| 51077 | walUnlockExclusive(pWal, WAL_READ_LOCK(1), WAL_NREADER-1); |
| 51078 | }else if( rc!=SQLITE_BUSY ){ |
| 51079 | return rc; |
| 51080 | } |
| 51081 | } |
| @@ -51294,11 +51359,11 @@ | |
| 51359 | ** If parameter xBusy is not NULL, it is a pointer to a busy-handler |
| 51360 | ** callback. In this case this function runs a blocking checkpoint. |
| 51361 | */ |
| 51362 | SQLITE_PRIVATE int sqlite3WalCheckpoint( |
| 51363 | Wal *pWal, /* Wal connection */ |
| 51364 | int eMode, /* PASSIVE, FULL, RESTART, or TRUNCATE */ |
| 51365 | int (*xBusy)(void*), /* Function to call when busy */ |
| 51366 | void *pBusyArg, /* Context argument for xBusyHandler */ |
| 51367 | int sync_flags, /* Flags to sync db file with (or 0) */ |
| 51368 | int nBuf, /* Size of temporary buffer */ |
| 51369 | u8 *zBuf, /* Temporary buffer to use */ |
| @@ -51306,40 +51371,54 @@ | |
| 51371 | int *pnCkpt /* OUT: Number of backfilled frames in WAL */ |
| 51372 | ){ |
| 51373 | int rc; /* Return code */ |
| 51374 | int isChanged = 0; /* True if a new wal-index header is loaded */ |
| 51375 | int eMode2 = eMode; /* Mode to pass to walCheckpoint() */ |
| 51376 | int (*xBusy2)(void*) = xBusy; /* Busy handler for eMode2 */ |
| 51377 | |
| 51378 | assert( pWal->ckptLock==0 ); |
| 51379 | assert( pWal->writeLock==0 ); |
| 51380 | |
| 51381 | /* EVIDENCE-OF: R-62920-47450 The busy-handler callback is never invoked |
| 51382 | ** in the SQLITE_CHECKPOINT_PASSIVE mode. */ |
| 51383 | assert( eMode!=SQLITE_CHECKPOINT_PASSIVE || xBusy==0 ); |
| 51384 | |
| 51385 | if( pWal->readOnly ) return SQLITE_READONLY; |
| 51386 | WALTRACE(("WAL%p: checkpoint begins\n", pWal)); |
| 51387 | |
| 51388 | /* IMPLEMENTATION-OF: R-62028-47212 All calls obtain an exclusive |
| 51389 | ** "checkpoint" lock on the database file. */ |
| 51390 | rc = walLockExclusive(pWal, WAL_CKPT_LOCK, 1); |
| 51391 | if( rc ){ |
| 51392 | /* EVIDENCE-OF: R-10421-19736 If any other process is running a |
| 51393 | ** checkpoint operation at the same time, the lock cannot be obtained and |
| 51394 | ** SQLITE_BUSY is returned. |
| 51395 | ** EVIDENCE-OF: R-53820-33897 Even if there is a busy-handler configured, |
| 51396 | ** it will not be invoked in this case. |
| 51397 | */ |
| 51398 | testcase( rc==SQLITE_BUSY ); |
| 51399 | testcase( xBusy!=0 ); |
| 51400 | return rc; |
| 51401 | } |
| 51402 | pWal->ckptLock = 1; |
| 51403 | |
| 51404 | /* IMPLEMENTATION-OF: R-59782-36818 The SQLITE_CHECKPOINT_FULL, RESTART and |
| 51405 | ** TRUNCATE modes also obtain the exclusive "writer" lock on the database |
| 51406 | ** file. |
| 51407 | ** |
| 51408 | ** EVIDENCE-OF: R-60642-04082 If the writer lock cannot be obtained |
| 51409 | ** immediately, and a busy-handler is configured, it is invoked and the |
| 51410 | ** writer lock retried until either the busy-handler returns 0 or the |
| 51411 | ** lock is successfully obtained. |
| 51412 | */ |
| 51413 | if( eMode!=SQLITE_CHECKPOINT_PASSIVE ){ |
| 51414 | rc = walBusyLock(pWal, xBusy, pBusyArg, WAL_WRITE_LOCK, 1); |
| 51415 | if( rc==SQLITE_OK ){ |
| 51416 | pWal->writeLock = 1; |
| 51417 | }else if( rc==SQLITE_BUSY ){ |
| 51418 | eMode2 = SQLITE_CHECKPOINT_PASSIVE; |
| 51419 | xBusy2 = 0; |
| 51420 | rc = SQLITE_OK; |
| 51421 | } |
| 51422 | } |
| 51423 | |
| 51424 | /* Read the wal-index header. */ |
| @@ -51353,11 +51432,11 @@ | |
| 51432 | /* Copy data from the log to the database file. */ |
| 51433 | if( rc==SQLITE_OK ){ |
| 51434 | if( pWal->hdr.mxFrame && walPagesize(pWal)!=nBuf ){ |
| 51435 | rc = SQLITE_CORRUPT_BKPT; |
| 51436 | }else{ |
| 51437 | rc = walCheckpoint(pWal, eMode2, xBusy2, pBusyArg, sync_flags, zBuf); |
| 51438 | } |
| 51439 | |
| 51440 | /* If no error occurred, set the output variables. */ |
| 51441 | if( rc==SQLITE_OK || rc==SQLITE_BUSY ){ |
| 51442 | if( pnLog ) *pnLog = (int)pWal->hdr.mxFrame; |
| @@ -53821,11 +53900,11 @@ | |
| 53900 | ** to see if defragmentation is necessary. |
| 53901 | */ |
| 53902 | testcase( gap+2+nByte==top ); |
| 53903 | if( gap+2+nByte>top ){ |
| 53904 | defragment_page: |
| 53905 | assert( pPage->nCell>0 || CORRUPT_DB ); |
| 53906 | rc = defragmentPage(pPage); |
| 53907 | if( rc ) return rc; |
| 53908 | top = get2byteNotZero(&data[hdr+5]); |
| 53909 | assert( gap+nByte<=top ); |
| 53910 | } |
| @@ -58881,11 +58960,11 @@ | |
| 58960 | assert( sqlite3_mutex_held(pPage->pBt->mutex) ); |
| 58961 | assert( sqlite3PagerIswriteable(pParent->pDbPage) ); |
| 58962 | assert( pPage->nOverflow==1 ); |
| 58963 | |
| 58964 | /* This error condition is now caught prior to reaching this function */ |
| 58965 | if( NEVER(pPage->nCell==0) ) return SQLITE_CORRUPT_BKPT; |
| 58966 | |
| 58967 | /* Allocate a new page. This page will become the right-sibling of |
| 58968 | ** pPage. Make the parent page writable, so that the new divider cell |
| 58969 | ** may be inserted. If both these operations are successful, proceed. |
| 58970 | */ |
| @@ -59324,11 +59403,15 @@ | |
| 59403 | ** pointer of the divider cell */ |
| 59404 | memcpy(apCell[nCell], &pOld->aData[8], 4); |
| 59405 | }else{ |
| 59406 | assert( leafCorrection==4 ); |
| 59407 | if( szCell[nCell]<4 ){ |
| 59408 | /* Do not allow any cells smaller than 4 bytes. If a smaller cell |
| 59409 | ** does exist, pad it with 0x00 bytes. */ |
| 59410 | assert( szCell[nCell]==3 ); |
| 59411 | assert( apCell[nCell]==&pTemp[iSpace1-3] ); |
| 59412 | pTemp[iSpace1++] = 0x00; |
| 59413 | szCell[nCell] = 4; |
| 59414 | } |
| 59415 | } |
| 59416 | nCell++; |
| 59417 | } |
| @@ -59559,11 +59642,15 @@ | |
| 59642 | ** was either part of sibling page iOld (possibly an overflow cell), |
| 59643 | ** or else the divider cell to the left of sibling page iOld. So, |
| 59644 | ** if sibling page iOld had the same page number as pNew, and if |
| 59645 | ** pCell really was a part of sibling page iOld (not a divider or |
| 59646 | ** overflow cell), we can skip updating the pointer map entries. */ |
| 59647 | if( iOld>=nNew |
| 59648 | || pNew->pgno!=aPgno[iOld] |
| 59649 | || pCell<aOld |
| 59650 | || pCell>=&aOld[usableSize] |
| 59651 | ){ |
| 59652 | if( !leafCorrection ){ |
| 59653 | ptrmapPut(pBt, get4byte(pCell), PTRMAP_BTREE, pNew->pgno, &rc); |
| 59654 | } |
| 59655 | if( szCell[i]>pNew->minLocal ){ |
| 59656 | ptrmapPutOvflPtr(pNew, pCell, &rc); |
| @@ -65699,11 +65786,11 @@ | |
| 65786 | for(n=0; n<nVar; n++){ |
| 65787 | p->aVar[n].flags = MEM_Null; |
| 65788 | p->aVar[n].db = db; |
| 65789 | } |
| 65790 | } |
| 65791 | if( p->azVar && pParse->nzVar>0 ){ |
| 65792 | p->nzVar = pParse->nzVar; |
| 65793 | memcpy(p->azVar, pParse->azVar, p->nzVar*sizeof(p->azVar[0])); |
| 65794 | memset(pParse->azVar, 0, pParse->nzVar*sizeof(pParse->azVar[0])); |
| 65795 | } |
| 65796 | if( p->aMem ){ |
| @@ -75629,12 +75716,12 @@ | |
| 75716 | |
| 75717 | #ifndef SQLITE_OMIT_WAL |
| 75718 | /* Opcode: Checkpoint P1 P2 P3 * * |
| 75719 | ** |
| 75720 | ** Checkpoint database P1. This is a no-op if P1 is not currently in |
| 75721 | ** WAL mode. Parameter P2 is one of SQLITE_CHECKPOINT_PASSIVE, FULL, |
| 75722 | ** RESTART, or TRUNCATE. Write 1 or 0 into mem[P3] if the checkpoint returns |
| 75723 | ** SQLITE_BUSY or not, respectively. Write the number of pages in the |
| 75724 | ** WAL after the checkpoint into mem[P3+1] and the number of pages |
| 75725 | ** in the WAL that have been checkpointed after the checkpoint |
| 75726 | ** completes into mem[P3+2]. However on an error, mem[P3+1] and |
| 75727 | ** mem[P3+2] are initialized to -1. |
| @@ -75648,10 +75735,11 @@ | |
| 75735 | aRes[0] = 0; |
| 75736 | aRes[1] = aRes[2] = -1; |
| 75737 | assert( pOp->p2==SQLITE_CHECKPOINT_PASSIVE |
| 75738 | || pOp->p2==SQLITE_CHECKPOINT_FULL |
| 75739 | || pOp->p2==SQLITE_CHECKPOINT_RESTART |
| 75740 | || pOp->p2==SQLITE_CHECKPOINT_TRUNCATE |
| 75741 | ); |
| 75742 | rc = sqlite3Checkpoint(db, pOp->p1, pOp->p2, &aRes[1], &aRes[2]); |
| 75743 | if( rc==SQLITE_BUSY ){ |
| 75744 | rc = SQLITE_OK; |
| 75745 | aRes[0] = 1; |
| @@ -80411,10 +80499,14 @@ | |
| 80499 | } |
| 80500 | } |
| 80501 | if( pMatch ){ |
| 80502 | pExpr->iTable = pMatch->iCursor; |
| 80503 | pExpr->pTab = pMatch->pTab; |
| 80504 | assert( (pMatch->jointype & JT_RIGHT)==0 ); /* RIGHT JOIN not (yet) supported */ |
| 80505 | if( (pMatch->jointype & JT_LEFT)!=0 ){ |
| 80506 | ExprSetProperty(pExpr, EP_CanBeNull); |
| 80507 | } |
| 80508 | pSchema = pExpr->pTab->pSchema; |
| 80509 | } |
| 80510 | } /* if( pSrcList ) */ |
| 80511 | |
| 80512 | #ifndef SQLITE_OMIT_TRIGGER |
| @@ -82968,11 +83060,12 @@ | |
| 83060 | case TK_FLOAT: |
| 83061 | case TK_BLOB: |
| 83062 | return 0; |
| 83063 | case TK_COLUMN: |
| 83064 | assert( p->pTab!=0 ); |
| 83065 | return ExprHasProperty(p, EP_CanBeNull) || |
| 83066 | (p->iColumn>=0 && p->pTab->aCol[p->iColumn].notNull==0); |
| 83067 | default: |
| 83068 | return 1; |
| 83069 | } |
| 83070 | } |
| 83071 | |
| @@ -88351,11 +88444,11 @@ | |
| 88444 | tRowcnt avgEq = 0; |
| 88445 | tRowcnt nRow; /* Number of rows in index */ |
| 88446 | i64 nSum100 = 0; /* Number of terms contributing to sumEq */ |
| 88447 | i64 nDist100; /* Number of distinct values in index */ |
| 88448 | |
| 88449 | if( !pIdx->aiRowEst || iCol>=pIdx->nKeyCol || pIdx->aiRowEst[iCol+1]==0 ){ |
| 88450 | nRow = pFinal->anLt[iCol]; |
| 88451 | nDist100 = (i64)100 * pFinal->anDLt[iCol]; |
| 88452 | nSample--; |
| 88453 | }else{ |
| 88454 | nRow = pIdx->aiRowEst[0]; |
| @@ -103921,11 +104014,11 @@ | |
| 104014 | break; |
| 104015 | #endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */ |
| 104016 | |
| 104017 | #ifndef SQLITE_OMIT_WAL |
| 104018 | /* |
| 104019 | ** PRAGMA [database.]wal_checkpoint = passive|full|restart|truncate |
| 104020 | ** |
| 104021 | ** Checkpoint the database. |
| 104022 | */ |
| 104023 | case PragTyp_WAL_CHECKPOINT: { |
| 104024 | int iBt = (pId2->z?iDb:SQLITE_MAX_ATTACHED); |
| @@ -103933,10 +104026,12 @@ | |
| 104026 | if( zRight ){ |
| 104027 | if( sqlite3StrICmp(zRight, "full")==0 ){ |
| 104028 | eMode = SQLITE_CHECKPOINT_FULL; |
| 104029 | }else if( sqlite3StrICmp(zRight, "restart")==0 ){ |
| 104030 | eMode = SQLITE_CHECKPOINT_RESTART; |
| 104031 | }else if( sqlite3StrICmp(zRight, "truncate")==0 ){ |
| 104032 | eMode = SQLITE_CHECKPOINT_TRUNCATE; |
| 104033 | } |
| 104034 | } |
| 104035 | sqlite3VdbeSetNumCols(v, 3); |
| 104036 | pParse->nMem = 3; |
| 104037 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "busy", SQLITE_STATIC); |
| @@ -109840,11 +109935,11 @@ | |
| 109935 | ** |
| 109936 | ** SELECT DISTINCT xyz FROM ... ORDER BY xyz |
| 109937 | ** |
| 109938 | ** is transformed to: |
| 109939 | ** |
| 109940 | ** SELECT xyz FROM ... GROUP BY xyz ORDER BY xyz |
| 109941 | ** |
| 109942 | ** The second form is preferred as a single index (or temp-table) may be |
| 109943 | ** used for both the ORDER BY and DISTINCT processing. As originally |
| 109944 | ** written the query must use a temp-table for at least one of the ORDER |
| 109945 | ** BY and DISTINCT, and an index or separate temp-table for the other. |
| @@ -109853,11 +109948,10 @@ | |
| 109948 | && sqlite3ExprListCompare(sSort.pOrderBy, p->pEList, -1)==0 |
| 109949 | ){ |
| 109950 | p->selFlags &= ~SF_Distinct; |
| 109951 | p->pGroupBy = sqlite3ExprListDup(db, p->pEList, 0); |
| 109952 | pGroupBy = p->pGroupBy; |
| 109953 | /* Notice that even thought SF_Distinct has been cleared from p->selFlags, |
| 109954 | ** the sDistinct.isTnct is still set. Hence, isTnct represents the |
| 109955 | ** original setting of the SF_Distinct flag, not the current setting */ |
| 109956 | assert( sDistinct.isTnct ); |
| 109957 | } |
| @@ -114808,10 +114902,11 @@ | |
| 114902 | memcpy(pWC->a, pOld, sizeof(pWC->a[0])*pWC->nTerm); |
| 114903 | if( pOld!=pWC->aStatic ){ |
| 114904 | sqlite3DbFree(db, pOld); |
| 114905 | } |
| 114906 | pWC->nSlot = sqlite3DbMallocSize(db, pWC->a)/sizeof(pWC->a[0]); |
| 114907 | memset(&pWC->a[pWC->nTerm], 0, sizeof(pWC->a[0])*(pWC->nSlot-pWC->nTerm)); |
| 114908 | } |
| 114909 | pTerm = &pWC->a[idx = pWC->nTerm++]; |
| 114910 | if( p && ExprHasProperty(p, EP_Unlikely) ){ |
| 114911 | pTerm->truthProb = sqlite3LogEst(p->iTable) - 270; |
| 114912 | }else{ |
| @@ -117533,11 +117628,11 @@ | |
| 117628 | WhereLevel *pLvl, /* Level to add scanstatus() entry for */ |
| 117629 | int addrExplain /* Address of OP_Explain (or 0) */ |
| 117630 | ){ |
| 117631 | const char *zObj = 0; |
| 117632 | WhereLoop *pLoop = pLvl->pWLoop; |
| 117633 | if( (pLoop->wsFlags & WHERE_VIRTUALTABLE)==0 && pLoop->u.btree.pIndex!=0 ){ |
| 117634 | zObj = pLoop->u.btree.pIndex->zName; |
| 117635 | }else{ |
| 117636 | zObj = pSrclist->a[pLvl->iFrom].zName; |
| 117637 | } |
| 117638 | sqlite3VdbeScanStatus( |
| @@ -118177,14 +118272,13 @@ | |
| 118272 | int iTerm; |
| 118273 | for(iTerm=0; iTerm<pWC->nTerm; iTerm++){ |
| 118274 | Expr *pExpr = pWC->a[iTerm].pExpr; |
| 118275 | if( &pWC->a[iTerm] == pTerm ) continue; |
| 118276 | if( ExprHasProperty(pExpr, EP_FromJoin) ) continue; |
| 118277 | if( (pWC->a[iTerm].wtFlags & TERM_VIRTUAL)!=0 ) continue; |
| 118278 | if( (pWC->a[iTerm].eOperator & WO_ALL)==0 ) continue; |
| 118279 | testcase( pWC->a[iTerm].wtFlags & TERM_ORINFO ); |
| 118280 | pExpr = sqlite3ExprDup(db, pExpr, 0); |
| 118281 | pAndExpr = sqlite3ExprAnd(db, pAndExpr, pExpr); |
| 118282 | } |
| 118283 | if( pAndExpr ){ |
| 118284 | pAndExpr = sqlite3PExpr(pParse, TK_AND, 0, pAndExpr, 0); |
| @@ -127079,10 +127173,18 @@ | |
| 127173 | |
| 127174 | /* Close all database connections */ |
| 127175 | for(j=0; j<db->nDb; j++){ |
| 127176 | struct Db *pDb = &db->aDb[j]; |
| 127177 | if( pDb->pBt ){ |
| 127178 | if( pDb->pSchema ){ |
| 127179 | /* Must clear the KeyInfo cache. See ticket [e4a18565a36884b00edf] */ |
| 127180 | for(i=sqliteHashFirst(&pDb->pSchema->idxHash); i; i=sqliteHashNext(i)){ |
| 127181 | Index *pIdx = sqliteHashData(i); |
| 127182 | sqlite3KeyInfoUnref(pIdx->pKeyInfo); |
| 127183 | pIdx->pKeyInfo = 0; |
| 127184 | } |
| 127185 | } |
| 127186 | sqlite3BtreeClose(pDb->pBt); |
| 127187 | pDb->pBt = 0; |
| 127188 | if( j!=1 ){ |
| 127189 | pDb->pSchema = 0; |
| 127190 | } |
| @@ -127983,14 +128085,17 @@ | |
| 128085 | |
| 128086 | /* Initialize the output variables to -1 in case an error occurs. */ |
| 128087 | if( pnLog ) *pnLog = -1; |
| 128088 | if( pnCkpt ) *pnCkpt = -1; |
| 128089 | |
| 128090 | assert( SQLITE_CHECKPOINT_PASSIVE==0 ); |
| 128091 | assert( SQLITE_CHECKPOINT_FULL==1 ); |
| 128092 | assert( SQLITE_CHECKPOINT_RESTART==2 ); |
| 128093 | assert( SQLITE_CHECKPOINT_TRUNCATE==3 ); |
| 128094 | if( eMode<SQLITE_CHECKPOINT_PASSIVE || eMode>SQLITE_CHECKPOINT_TRUNCATE ){ |
| 128095 | /* EVIDENCE-OF: R-03996-12088 The M parameter must be a valid checkpoint |
| 128096 | ** mode: */ |
| 128097 | return SQLITE_MISUSE; |
| 128098 | } |
| 128099 | |
| 128100 | sqlite3_mutex_enter(db->mutex); |
| 128101 | if( zDb && zDb[0] ){ |
| @@ -128014,11 +128119,13 @@ | |
| 128119 | ** Checkpoint database zDb. If zDb is NULL, or if the buffer zDb points |
| 128120 | ** to contains a zero-length string, all attached databases are |
| 128121 | ** checkpointed. |
| 128122 | */ |
| 128123 | SQLITE_API int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb){ |
| 128124 | /* EVIDENCE-OF: R-41613-20553 The sqlite3_wal_checkpoint(D,X) is equivalent to |
| 128125 | ** sqlite3_wal_checkpoint_v2(D,X,SQLITE_CHECKPOINT_PASSIVE,0,0). */ |
| 128126 | return sqlite3_wal_checkpoint_v2(db,zDb,SQLITE_CHECKPOINT_PASSIVE,0,0); |
| 128127 | } |
| 128128 | |
| 128129 | #ifndef SQLITE_OMIT_WAL |
| 128130 | /* |
| 128131 | ** Run a checkpoint on database iDb. This is a no-op if database iDb is |
| @@ -139164,11 +139271,11 @@ | |
| 139271 | ** Return true if the m-value for z is 1 or more. In other words, |
| 139272 | ** return true if z contains at least one vowel that is followed |
| 139273 | ** by a consonant. |
| 139274 | ** |
| 139275 | ** In this routine z[] is in reverse order. So we are really looking |
| 139276 | ** for an instance of a consonant followed by a vowel. |
| 139277 | */ |
| 139278 | static int m_gt_0(const char *z){ |
| 139279 | while( isVowel(z) ){ z++; } |
| 139280 | if( *z==0 ) return 0; |
| 139281 | while( isConsonant(z) ){ z++; } |
| 139282 |
+121
-97
| --- src/sqlite3.h | ||
| +++ src/sqlite3.h | ||
| @@ -107,11 +107,11 @@ | ||
| 107 | 107 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 108 | 108 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 109 | 109 | */ |
| 110 | 110 | #define SQLITE_VERSION "3.8.8" |
| 111 | 111 | #define SQLITE_VERSION_NUMBER 3008008 |
| 112 | -#define SQLITE_SOURCE_ID "2014-11-28 13:35:03 24fa2e9832daaa5d68ee28a00c56c55f97a4da9e" | |
| 112 | +#define SQLITE_SOURCE_ID "2014-12-06 14:56:49 6aeece19a235344be2537e66a3fe08b1febfb5a0" | |
| 113 | 113 | |
| 114 | 114 | /* |
| 115 | 115 | ** CAPI3REF: Run-Time Library Version Numbers |
| 116 | 116 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 117 | 117 | ** |
| @@ -1219,11 +1219,11 @@ | ||
| 1219 | 1219 | ** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_SHARED |
| 1220 | 1220 | ** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_EXCLUSIVE |
| 1221 | 1221 | ** </ul> |
| 1222 | 1222 | ** |
| 1223 | 1223 | ** When unlocking, the same SHARED or EXCLUSIVE flag must be supplied as |
| 1224 | -** was given no the corresponding lock. | |
| 1224 | +** was given on the corresponding lock. | |
| 1225 | 1225 | ** |
| 1226 | 1226 | ** The xShmLock method can transition between unlocked and SHARED or |
| 1227 | 1227 | ** between unlocked and EXCLUSIVE. It cannot transition between SHARED |
| 1228 | 1228 | ** and EXCLUSIVE. |
| 1229 | 1229 | */ |
| @@ -1522,12 +1522,12 @@ | ||
| 1522 | 1522 | ** tracks memory usage, for example. </dd> |
| 1523 | 1523 | ** |
| 1524 | 1524 | ** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt> |
| 1525 | 1525 | ** <dd> ^The SQLITE_CONFIG_MEMSTATUS option takes single argument of type int, |
| 1526 | 1526 | ** interpreted as a boolean, which enables or disables the collection of |
| 1527 | -** memory allocation statistics. ^(When memory allocation statistics are disabled, the | |
| 1528 | -** following SQLite interfaces become non-operational: | |
| 1527 | +** memory allocation statistics. ^(When memory allocation statistics are | |
| 1528 | +** disabled, the following SQLite interfaces become non-operational: | |
| 1529 | 1529 | ** <ul> |
| 1530 | 1530 | ** <li> [sqlite3_memory_used()] |
| 1531 | 1531 | ** <li> [sqlite3_memory_highwater()] |
| 1532 | 1532 | ** <li> [sqlite3_soft_heap_limit64()] |
| 1533 | 1533 | ** <li> [sqlite3_status()] |
| @@ -1564,11 +1564,12 @@ | ||
| 1564 | 1564 | ** that SQLite can use for the database page cache with the default page |
| 1565 | 1565 | ** cache implementation. |
| 1566 | 1566 | ** This configuration should not be used if an application-define page |
| 1567 | 1567 | ** cache implementation is loaded using the [SQLITE_CONFIG_PCACHE2] |
| 1568 | 1568 | ** configuration option. |
| 1569 | -** ^There are three arguments to SQLITE_CONFIG_PAGECACHE: A pointer to 8-byte aligned | |
| 1569 | +** ^There are three arguments to SQLITE_CONFIG_PAGECACHE: A pointer to | |
| 1570 | +** 8-byte aligned | |
| 1570 | 1571 | ** memory, the size of each page buffer (sz), and the number of pages (N). |
| 1571 | 1572 | ** The sz argument should be the size of the largest database page |
| 1572 | 1573 | ** (a power of two between 512 and 32768) plus some extra bytes for each |
| 1573 | 1574 | ** page header. ^The number of extra bytes needed by the page header |
| 1574 | 1575 | ** can be determined using the [SQLITE_CONFIG_PCACHE_HDRSZ] option |
| @@ -1584,11 +1585,12 @@ | ||
| 1584 | 1585 | ** SQLite goes to [sqlite3_malloc()] for the additional storage space.</dd> |
| 1585 | 1586 | ** |
| 1586 | 1587 | ** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt> |
| 1587 | 1588 | ** <dd> ^The SQLITE_CONFIG_HEAP option specifies a static memory buffer |
| 1588 | 1589 | ** that SQLite will use for all of its dynamic memory allocation needs |
| 1589 | -** beyond those provided for by [SQLITE_CONFIG_SCRATCH] and [SQLITE_CONFIG_PAGECACHE]. | |
| 1590 | +** beyond those provided for by [SQLITE_CONFIG_SCRATCH] and | |
| 1591 | +** [SQLITE_CONFIG_PAGECACHE]. | |
| 1590 | 1592 | ** ^The SQLITE_CONFIG_HEAP option is only available if SQLite is compiled |
| 1591 | 1593 | ** with either [SQLITE_ENABLE_MEMSYS3] or [SQLITE_ENABLE_MEMSYS5] and returns |
| 1592 | 1594 | ** [SQLITE_ERROR] if invoked otherwise. |
| 1593 | 1595 | ** ^There are three arguments to SQLITE_CONFIG_HEAP: |
| 1594 | 1596 | ** An 8-byte aligned pointer to the memory, |
| @@ -1604,13 +1606,13 @@ | ||
| 1604 | 1606 | ** for the minimum allocation size are 2**5 through 2**8.</dd> |
| 1605 | 1607 | ** |
| 1606 | 1608 | ** [[SQLITE_CONFIG_MUTEX]] <dt>SQLITE_CONFIG_MUTEX</dt> |
| 1607 | 1609 | ** <dd> ^(The SQLITE_CONFIG_MUTEX option takes a single argument which is a |
| 1608 | 1610 | ** pointer to an instance of the [sqlite3_mutex_methods] structure. |
| 1609 | -** The argument specifies alternative low-level mutex routines to be used in place | |
| 1610 | -** the mutex routines built into SQLite.)^ ^SQLite makes a copy of the | |
| 1611 | -** content of the [sqlite3_mutex_methods] structure before the call to | |
| 1611 | +** The argument specifies alternative low-level mutex routines to be used | |
| 1612 | +** in place the mutex routines built into SQLite.)^ ^SQLite makes a copy of | |
| 1613 | +** the content of the [sqlite3_mutex_methods] structure before the call to | |
| 1612 | 1614 | ** [sqlite3_config()] returns. ^If SQLite is compiled with |
| 1613 | 1615 | ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then |
| 1614 | 1616 | ** the entire mutexing subsystem is omitted from the build and hence calls to |
| 1615 | 1617 | ** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will |
| 1616 | 1618 | ** return [SQLITE_ERROR].</dd> |
| @@ -1644,12 +1646,12 @@ | ||
| 1644 | 1646 | ** the interface to a custom page cache implementation.)^ |
| 1645 | 1647 | ** ^SQLite makes a copy of the [sqlite3_pcache_methods2] object.</dd> |
| 1646 | 1648 | ** |
| 1647 | 1649 | ** [[SQLITE_CONFIG_GETPCACHE2]] <dt>SQLITE_CONFIG_GETPCACHE2</dt> |
| 1648 | 1650 | ** <dd> ^(The SQLITE_CONFIG_GETPCACHE2 option takes a single argument which |
| 1649 | -** is a pointer to an [sqlite3_pcache_methods2] object. SQLite copies of the current | |
| 1650 | -** page cache implementation into that object.)^ </dd> | |
| 1651 | +** is a pointer to an [sqlite3_pcache_methods2] object. SQLite copies of | |
| 1652 | +** the current page cache implementation into that object.)^ </dd> | |
| 1651 | 1653 | ** |
| 1652 | 1654 | ** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt> |
| 1653 | 1655 | ** <dd> The SQLITE_CONFIG_LOG option is used to configure the SQLite |
| 1654 | 1656 | ** global [error log]. |
| 1655 | 1657 | ** (^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a |
| @@ -1670,12 +1672,13 @@ | ||
| 1670 | 1672 | ** function must be threadsafe. </dd> |
| 1671 | 1673 | ** |
| 1672 | 1674 | ** [[SQLITE_CONFIG_URI]] <dt>SQLITE_CONFIG_URI |
| 1673 | 1675 | ** <dd>^(The SQLITE_CONFIG_URI option takes a single argument of type int. |
| 1674 | 1676 | ** If non-zero, then URI handling is globally enabled. If the parameter is zero, |
| 1675 | -** then URI handling is globally disabled.)^ ^If URI handling is globally enabled, | |
| 1676 | -** all filenames passed to [sqlite3_open()], [sqlite3_open_v2()], [sqlite3_open16()] or | |
| 1677 | +** then URI handling is globally disabled.)^ ^If URI handling is globally | |
| 1678 | +** enabled, all filenames passed to [sqlite3_open()], [sqlite3_open_v2()], | |
| 1679 | +** [sqlite3_open16()] or | |
| 1677 | 1680 | ** specified as part of [ATTACH] commands are interpreted as URIs, regardless |
| 1678 | 1681 | ** of whether or not the [SQLITE_OPEN_URI] flag is set when the database |
| 1679 | 1682 | ** connection is opened. ^If it is globally disabled, filenames are |
| 1680 | 1683 | ** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the |
| 1681 | 1684 | ** database connection is opened. ^(By default, URI handling is globally |
| @@ -1733,21 +1736,21 @@ | ||
| 1733 | 1736 | ** changed to its compile-time default. |
| 1734 | 1737 | ** |
| 1735 | 1738 | ** [[SQLITE_CONFIG_WIN32_HEAPSIZE]] |
| 1736 | 1739 | ** <dt>SQLITE_CONFIG_WIN32_HEAPSIZE |
| 1737 | 1740 | ** <dd>^The SQLITE_CONFIG_WIN32_HEAPSIZE option is only available if SQLite is |
| 1738 | -** compiled for Windows with the [SQLITE_WIN32_MALLOC] pre-processor macro defined. | |
| 1739 | -** ^SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit unsigned integer value | |
| 1741 | +** compiled for Windows with the [SQLITE_WIN32_MALLOC] pre-processor macro | |
| 1742 | +** defined. ^SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit unsigned integer value | |
| 1740 | 1743 | ** that specifies the maximum size of the created heap. |
| 1741 | 1744 | ** </dl> |
| 1742 | 1745 | ** |
| 1743 | 1746 | ** [[SQLITE_CONFIG_PCACHE_HDRSZ]] |
| 1744 | 1747 | ** <dt>SQLITE_CONFIG_PCACHE_HDRSZ |
| 1745 | 1748 | ** <dd>^The SQLITE_CONFIG_PCACHE_HDRSZ option takes a single parameter which |
| 1746 | 1749 | ** is a pointer to an integer and writes into that integer the number of extra |
| 1747 | -** bytes per page required for each page in [SQLITE_CONFIG_PAGECACHE]. The amount of | |
| 1748 | -** extra space required can change depending on the compiler, | |
| 1750 | +** bytes per page required for each page in [SQLITE_CONFIG_PAGECACHE]. | |
| 1751 | +** The amount of extra space required can change depending on the compiler, | |
| 1749 | 1752 | ** target platform, and SQLite version. |
| 1750 | 1753 | ** </dl> |
| 1751 | 1754 | */ |
| 1752 | 1755 | #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */ |
| 1753 | 1756 | #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */ |
| @@ -2047,10 +2050,11 @@ | ||
| 2047 | 2050 | SQLITE_API int sqlite3_complete(const char *sql); |
| 2048 | 2051 | SQLITE_API int sqlite3_complete16(const void *sql); |
| 2049 | 2052 | |
| 2050 | 2053 | /* |
| 2051 | 2054 | ** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors |
| 2055 | +** KEYWORDS: {busy-handler callback} {busy handler} | |
| 2052 | 2056 | ** |
| 2053 | 2057 | ** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X |
| 2054 | 2058 | ** that might be invoked with argument P whenever |
| 2055 | 2059 | ** an attempt is made to access a database table associated with |
| 2056 | 2060 | ** [database connection] D when another thread |
| @@ -2063,11 +2067,11 @@ | ||
| 2063 | 2067 | ** is not NULL, then the callback might be invoked with two arguments. |
| 2064 | 2068 | ** |
| 2065 | 2069 | ** ^The first argument to the busy handler is a copy of the void* pointer which |
| 2066 | 2070 | ** is the third argument to sqlite3_busy_handler(). ^The second argument to |
| 2067 | 2071 | ** the busy handler callback is the number of times that the busy handler has |
| 2068 | -** been invoked for the same locking event. ^If the | |
| 2072 | +** been invoked previously for the same locking event. ^If the | |
| 2069 | 2073 | ** busy callback returns 0, then no additional attempts are made to |
| 2070 | 2074 | ** access the database and [SQLITE_BUSY] is returned |
| 2071 | 2075 | ** to the application. |
| 2072 | 2076 | ** ^If the callback returns non-zero, then another attempt |
| 2073 | 2077 | ** is made to access the database and the cycle repeats. |
| @@ -4518,11 +4522,12 @@ | ||
| 4518 | 4522 | ** If these routines are called from within the different thread |
| 4519 | 4523 | ** than the one containing the application-defined function that received |
| 4520 | 4524 | ** the [sqlite3_context] pointer, the results are undefined. |
| 4521 | 4525 | */ |
| 4522 | 4526 | SQLITE_API void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*)); |
| 4523 | -SQLITE_API void sqlite3_result_blob64(sqlite3_context*,const void*,sqlite3_uint64,void(*)(void*)); | |
| 4527 | +SQLITE_API void sqlite3_result_blob64(sqlite3_context*,const void*, | |
| 4528 | + sqlite3_uint64,void(*)(void*)); | |
| 4524 | 4529 | SQLITE_API void sqlite3_result_double(sqlite3_context*, double); |
| 4525 | 4530 | SQLITE_API void sqlite3_result_error(sqlite3_context*, const char*, int); |
| 4526 | 4531 | SQLITE_API void sqlite3_result_error16(sqlite3_context*, const void*, int); |
| 4527 | 4532 | SQLITE_API void sqlite3_result_error_toobig(sqlite3_context*); |
| 4528 | 4533 | SQLITE_API void sqlite3_result_error_nomem(sqlite3_context*); |
| @@ -7244,101 +7249,118 @@ | ||
| 7244 | 7249 | SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int N); |
| 7245 | 7250 | |
| 7246 | 7251 | /* |
| 7247 | 7252 | ** CAPI3REF: Checkpoint a database |
| 7248 | 7253 | ** |
| 7249 | -** ^The [sqlite3_wal_checkpoint(D,X)] interface causes database named X | |
| 7250 | -** on [database connection] D to be [checkpointed]. ^If X is NULL or an | |
| 7251 | -** empty string, then a checkpoint is run on all databases of | |
| 7252 | -** connection D. ^If the database connection D is not in | |
| 7253 | -** [WAL | write-ahead log mode] then this interface is a harmless no-op. | |
| 7254 | -** ^The [sqlite3_wal_checkpoint(D,X)] interface initiates a | |
| 7255 | -** [sqlite3_wal_checkpoint_v2|PASSIVE] checkpoint. | |
| 7256 | -** Use the [sqlite3_wal_checkpoint_v2()] interface to get a FULL | |
| 7257 | -** or RESET checkpoint. | |
| 7258 | -** | |
| 7259 | -** ^The [wal_checkpoint pragma] can be used to invoke this interface | |
| 7260 | -** from SQL. ^The [sqlite3_wal_autocheckpoint()] interface and the | |
| 7261 | -** [wal_autocheckpoint pragma] can be used to cause this interface to be | |
| 7262 | -** run whenever the WAL reaches a certain size threshold. | |
| 7263 | -** | |
| 7264 | -** See also: [sqlite3_wal_checkpoint_v2()] | |
| 7254 | +** ^(The sqlite3_wal_checkpoint(D,X) is equivalent to | |
| 7255 | +** [sqlite3_wal_checkpoint_v2](D,X,[SQLITE_CHECKPOINT_PASSIVE],0,0).)^ | |
| 7256 | +** | |
| 7257 | +** In brief, sqlite3_wal_checkpoint(D,X) causes the content in the | |
| 7258 | +** [write-ahead log] for database X on [database connection] D to be | |
| 7259 | +** transferred into the database file and for the write-ahead log to | |
| 7260 | +** be reset. See the [checkpointing] documentation for addition | |
| 7261 | +** information. | |
| 7262 | +** | |
| 7263 | +** This interface used to be the only way to cause a checkpoint to | |
| 7264 | +** occur. But then the newer and more powerful [sqlite3_wal_checkpoint_v2()] | |
| 7265 | +** interface was added. This interface is retained for backwards | |
| 7266 | +** compatibility and as a convenience for applications that need to manually | |
| 7267 | +** start a callback but which do not need the full power (and corresponding | |
| 7268 | +** complication) of [sqlite3_wal_checkpoint_v2()]. | |
| 7265 | 7269 | */ |
| 7266 | 7270 | SQLITE_API int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb); |
| 7267 | 7271 | |
| 7268 | 7272 | /* |
| 7269 | 7273 | ** CAPI3REF: Checkpoint a database |
| 7270 | 7274 | ** |
| 7271 | -** Run a checkpoint operation on WAL database zDb attached to database | |
| 7272 | -** handle db. The specific operation is determined by the value of the | |
| 7273 | -** eMode parameter: | |
| 7275 | +** ^(The sqlite3_wal_checkpoint_v2(D,X,M,L,C) interface runs a checkpoint | |
| 7276 | +** operation on database X of [database connection] D in mode M. Status | |
| 7277 | +** information is written back into integers pointed to by L and C.)^ | |
| 7278 | +** ^(The M parameter must be a valid [checkpoint mode]:)^ | |
| 7274 | 7279 | ** |
| 7275 | 7280 | ** <dl> |
| 7276 | 7281 | ** <dt>SQLITE_CHECKPOINT_PASSIVE<dd> |
| 7277 | -** Checkpoint as many frames as possible without waiting for any database | |
| 7278 | -** readers or writers to finish. Sync the db file if all frames in the log | |
| 7279 | -** are checkpointed. This mode is the same as calling | |
| 7280 | -** sqlite3_wal_checkpoint(). The [sqlite3_busy_handler|busy-handler callback] | |
| 7281 | -** is never invoked. | |
| 7282 | +** ^Checkpoint as many frames as possible without waiting for any database | |
| 7283 | +** readers or writers to finish, then sync the database file if all frames | |
| 7284 | +** in the log were checkpointed. ^The [busy-handler callback] | |
| 7285 | +** is never invoked in the SQLITE_CHECKPOINT_PASSIVE mode. | |
| 7286 | +** ^On the other hand, passive mode might leave the checkpoint unfinished | |
| 7287 | +** if there are concurrent readers or writers. | |
| 7282 | 7288 | ** |
| 7283 | 7289 | ** <dt>SQLITE_CHECKPOINT_FULL<dd> |
| 7284 | -** This mode blocks (it invokes the | |
| 7290 | +** ^This mode blocks (it invokes the | |
| 7285 | 7291 | ** [sqlite3_busy_handler|busy-handler callback]) until there is no |
| 7286 | 7292 | ** database writer and all readers are reading from the most recent database |
| 7287 | -** snapshot. It then checkpoints all frames in the log file and syncs the | |
| 7288 | -** database file. This call blocks database writers while it is running, | |
| 7289 | -** but not database readers. | |
| 7293 | +** snapshot. ^It then checkpoints all frames in the log file and syncs the | |
| 7294 | +** database file. ^This mode blocks new database writers while it is pending, | |
| 7295 | +** but new database readers are allowed to continue unimpeded. | |
| 7290 | 7296 | ** |
| 7291 | 7297 | ** <dt>SQLITE_CHECKPOINT_RESTART<dd> |
| 7292 | -** This mode works the same way as SQLITE_CHECKPOINT_FULL, except after | |
| 7293 | -** checkpointing the log file it blocks (calls the | |
| 7294 | -** [sqlite3_busy_handler|busy-handler callback]) | |
| 7295 | -** until all readers are reading from the database file only. This ensures | |
| 7296 | -** that the next client to write to the database file restarts the log file | |
| 7297 | -** from the beginning. This call blocks database writers while it is running, | |
| 7298 | -** but not database readers. | |
| 7298 | +** ^This mode works the same way as SQLITE_CHECKPOINT_FULL with the addition | |
| 7299 | +** that after checkpointing the log file it blocks (calls the | |
| 7300 | +** [busy-handler callback]) | |
| 7301 | +** until all readers are reading from the database file only. ^This ensures | |
| 7302 | +** that the next writer will restart the log file from the beginning. | |
| 7303 | +** ^Like SQLITE_CHECKPOINT_FULL, this mode blocks new | |
| 7304 | +** database writer attempts while it is pending, but does not impede readers. | |
| 7305 | +** | |
| 7306 | +** <dt>SQLITE_CHECKPOINT_TRUNCATE<dd> | |
| 7307 | +** ^This mode works the same way as SQLITE_CHECKPOINT_RESTART with the | |
| 7308 | +** addition that it also truncates the log file to zero bytes just prior | |
| 7309 | +** to a successful return. | |
| 7299 | 7310 | ** </dl> |
| 7300 | 7311 | ** |
| 7301 | -** If pnLog is not NULL, then *pnLog is set to the total number of frames in | |
| 7302 | -** the log file before returning. If pnCkpt is not NULL, then *pnCkpt is set to | |
| 7303 | -** the total number of checkpointed frames (including any that were already | |
| 7304 | -** checkpointed when this function is called). *pnLog and *pnCkpt may be | |
| 7305 | -** populated even if sqlite3_wal_checkpoint_v2() returns other than SQLITE_OK. | |
| 7306 | -** If no values are available because of an error, they are both set to -1 | |
| 7307 | -** before returning to communicate this to the caller. | |
| 7312 | +** ^If pnLog is not NULL, then *pnLog is set to the total number of frames in | |
| 7313 | +** the log file or to -1 if the checkpoint could not run because | |
| 7314 | +** of an error or because the database is not in [WAL mode]. ^If pnCkpt is not | |
| 7315 | +** NULL,then *pnCkpt is set to the total number of checkpointed frames in the | |
| 7316 | +** log file (including any that were already checkpointed before the function | |
| 7317 | +** was called) or to -1 if the checkpoint could not run due to an error or | |
| 7318 | +** because the database is not in WAL mode. ^Note that upon successful | |
| 7319 | +** completion of an SQLITE_CHECKPOINT_TRUNCATE, the log file will have been | |
| 7320 | +** truncated to zero bytes and so both *pnLog and *pnCkpt will be set to zero. | |
| 7308 | 7321 | ** |
| 7309 | -** All calls obtain an exclusive "checkpoint" lock on the database file. If | |
| 7322 | +** ^All calls obtain an exclusive "checkpoint" lock on the database file. ^If | |
| 7310 | 7323 | ** any other process is running a checkpoint operation at the same time, the |
| 7311 | -** lock cannot be obtained and SQLITE_BUSY is returned. Even if there is a | |
| 7324 | +** lock cannot be obtained and SQLITE_BUSY is returned. ^Even if there is a | |
| 7312 | 7325 | ** busy-handler configured, it will not be invoked in this case. |
| 7313 | 7326 | ** |
| 7314 | -** The SQLITE_CHECKPOINT_FULL and RESTART modes also obtain the exclusive | |
| 7315 | -** "writer" lock on the database file. If the writer lock cannot be obtained | |
| 7316 | -** immediately, and a busy-handler is configured, it is invoked and the writer | |
| 7317 | -** lock retried until either the busy-handler returns 0 or the lock is | |
| 7318 | -** successfully obtained. The busy-handler is also invoked while waiting for | |
| 7319 | -** database readers as described above. If the busy-handler returns 0 before | |
| 7327 | +** ^The SQLITE_CHECKPOINT_FULL, RESTART and TRUNCATE modes also obtain the | |
| 7328 | +** exclusive "writer" lock on the database file. ^If the writer lock cannot be | |
| 7329 | +** obtained immediately, and a busy-handler is configured, it is invoked and | |
| 7330 | +** the writer lock retried until either the busy-handler returns 0 or the lock | |
| 7331 | +** is successfully obtained. ^The busy-handler is also invoked while waiting for | |
| 7332 | +** database readers as described above. ^If the busy-handler returns 0 before | |
| 7320 | 7333 | ** the writer lock is obtained or while waiting for database readers, the |
| 7321 | 7334 | ** checkpoint operation proceeds from that point in the same way as |
| 7322 | 7335 | ** SQLITE_CHECKPOINT_PASSIVE - checkpointing as many frames as possible |
| 7323 | -** without blocking any further. SQLITE_BUSY is returned in this case. | |
| 7336 | +** without blocking any further. ^SQLITE_BUSY is returned in this case. | |
| 7324 | 7337 | ** |
| 7325 | -** If parameter zDb is NULL or points to a zero length string, then the | |
| 7326 | -** specified operation is attempted on all WAL databases. In this case the | |
| 7327 | -** values written to output parameters *pnLog and *pnCkpt are undefined. If | |
| 7338 | +** ^If parameter zDb is NULL or points to a zero length string, then the | |
| 7339 | +** specified operation is attempted on all WAL databases [attached] to | |
| 7340 | +** [database connection] db. In this case the | |
| 7341 | +** values written to output parameters *pnLog and *pnCkpt are undefined. ^If | |
| 7328 | 7342 | ** an SQLITE_BUSY error is encountered when processing one or more of the |
| 7329 | 7343 | ** attached WAL databases, the operation is still attempted on any remaining |
| 7330 | -** attached databases and SQLITE_BUSY is returned to the caller. If any other | |
| 7344 | +** attached databases and SQLITE_BUSY is returned at the end. ^If any other | |
| 7331 | 7345 | ** error occurs while processing an attached database, processing is abandoned |
| 7332 | -** and the error code returned to the caller immediately. If no error | |
| 7346 | +** and the error code is returned to the caller immediately. ^If no error | |
| 7333 | 7347 | ** (SQLITE_BUSY or otherwise) is encountered while processing the attached |
| 7334 | 7348 | ** databases, SQLITE_OK is returned. |
| 7335 | 7349 | ** |
| 7336 | -** If database zDb is the name of an attached database that is not in WAL | |
| 7337 | -** mode, SQLITE_OK is returned and both *pnLog and *pnCkpt set to -1. If | |
| 7350 | +** ^If database zDb is the name of an attached database that is not in WAL | |
| 7351 | +** mode, SQLITE_OK is returned and both *pnLog and *pnCkpt set to -1. ^If | |
| 7338 | 7352 | ** zDb is not NULL (or a zero length string) and is not the name of any |
| 7339 | 7353 | ** attached database, SQLITE_ERROR is returned to the caller. |
| 7354 | +** | |
| 7355 | +** ^Unless it returns SQLITE_MISUSE, | |
| 7356 | +** the sqlite3_wal_checkpoint_v2() interface | |
| 7357 | +** sets the error information that is queried by | |
| 7358 | +** [sqlite3_errcode()] and [sqlite3_errmsg()]. | |
| 7359 | +** | |
| 7360 | +** ^The [PRAGMA wal_checkpoint] command can be used to invoke this interface | |
| 7361 | +** from SQL. | |
| 7340 | 7362 | */ |
| 7341 | 7363 | SQLITE_API int sqlite3_wal_checkpoint_v2( |
| 7342 | 7364 | sqlite3 *db, /* Database handle */ |
| 7343 | 7365 | const char *zDb, /* Name of attached database (or NULL) */ |
| 7344 | 7366 | int eMode, /* SQLITE_CHECKPOINT_* value */ |
| @@ -7345,20 +7367,22 @@ | ||
| 7345 | 7367 | int *pnLog, /* OUT: Size of WAL log in frames */ |
| 7346 | 7368 | int *pnCkpt /* OUT: Total number of frames checkpointed */ |
| 7347 | 7369 | ); |
| 7348 | 7370 | |
| 7349 | 7371 | /* |
| 7350 | -** CAPI3REF: Checkpoint operation parameters | |
| 7372 | +** CAPI3REF: Checkpoint Mode Values | |
| 7373 | +** KEYWORDS: {checkpoint mode} | |
| 7351 | 7374 | ** |
| 7352 | -** These constants can be used as the 3rd parameter to | |
| 7353 | -** [sqlite3_wal_checkpoint_v2()]. See the [sqlite3_wal_checkpoint_v2()] | |
| 7354 | -** documentation for additional information about the meaning and use of | |
| 7355 | -** each of these values. | |
| 7375 | +** These constants define all valid values for the "checkpoint mode" passed | |
| 7376 | +** as the third parameter to the [sqlite3_wal_checkpoint_v2()] interface. | |
| 7377 | +** See the [sqlite3_wal_checkpoint_v2()] documentation for details on the | |
| 7378 | +** meaning of each of these checkpoint modes. | |
| 7356 | 7379 | */ |
| 7357 | -#define SQLITE_CHECKPOINT_PASSIVE 0 | |
| 7358 | -#define SQLITE_CHECKPOINT_FULL 1 | |
| 7359 | -#define SQLITE_CHECKPOINT_RESTART 2 | |
| 7380 | +#define SQLITE_CHECKPOINT_PASSIVE 0 /* Do as much as possible w/o blocking */ | |
| 7381 | +#define SQLITE_CHECKPOINT_FULL 1 /* Wait for writers, then checkpoint */ | |
| 7382 | +#define SQLITE_CHECKPOINT_RESTART 2 /* Like FULL but wait for for readers */ | |
| 7383 | +#define SQLITE_CHECKPOINT_TRUNCATE 3 /* Like RESTART but also truncate WAL */ | |
| 7360 | 7384 | |
| 7361 | 7385 | /* |
| 7362 | 7386 | ** CAPI3REF: Virtual Table Interface Configuration |
| 7363 | 7387 | ** |
| 7364 | 7388 | ** This function may be called by either the [xConnect] or [xCreate] method |
| @@ -7453,16 +7477,16 @@ | ||
| 7453 | 7477 | ** [sqlite3_stmt_scanstatus(S,X,T,V)] interface. Each constant designates a |
| 7454 | 7478 | ** different metric for sqlite3_stmt_scanstatus() to return. |
| 7455 | 7479 | ** |
| 7456 | 7480 | ** <dl> |
| 7457 | 7481 | ** [[SQLITE_SCANSTAT_NLOOP]] <dt>SQLITE_SCANSTAT_NLOOP</dt> |
| 7458 | -** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be set to the | |
| 7459 | -** total number of times that the X-th loop has run.</dd> | |
| 7482 | +** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be | |
| 7483 | +** set to the total number of times that the X-th loop has run.</dd> | |
| 7460 | 7484 | ** |
| 7461 | 7485 | ** [[SQLITE_SCANSTAT_NVISIT]] <dt>SQLITE_SCANSTAT_NVISIT</dt> |
| 7462 | -** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be set to the | |
| 7463 | -** total number of rows examined by all iterations of the X-th loop.</dd> | |
| 7486 | +** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be set | |
| 7487 | +** to the total number of rows examined by all iterations of the X-th loop.</dd> | |
| 7464 | 7488 | ** |
| 7465 | 7489 | ** [[SQLITE_SCANSTAT_EST]] <dt>SQLITE_SCANSTAT_EST</dt> |
| 7466 | 7490 | ** <dd>^The "double" variable pointed to by the T parameter will be set to the |
| 7467 | 7491 | ** query planner's estimate for the average number of rows output from each |
| 7468 | 7492 | ** iteration of the X-th loop. If the query planner's estimates was accurate, |
| @@ -7469,18 +7493,18 @@ | ||
| 7469 | 7493 | ** then this value will approximate the quotient NVISIT/NLOOP and the |
| 7470 | 7494 | ** product of this value for all prior loops with the same SELECTID will |
| 7471 | 7495 | ** be the NLOOP value for the current loop. |
| 7472 | 7496 | ** |
| 7473 | 7497 | ** [[SQLITE_SCANSTAT_NAME]] <dt>SQLITE_SCANSTAT_NAME</dt> |
| 7474 | -** <dd>^The "const char *" variable pointed to by the T parameter will be set to | |
| 7475 | -** a zero-terminated UTF-8 string containing the name of the index or table used | |
| 7476 | -** for the X-th loop. | |
| 7498 | +** <dd>^The "const char *" variable pointed to by the T parameter will be set | |
| 7499 | +** to a zero-terminated UTF-8 string containing the name of the index or table | |
| 7500 | +** used for the X-th loop. | |
| 7477 | 7501 | ** |
| 7478 | 7502 | ** [[SQLITE_SCANSTAT_EXPLAIN]] <dt>SQLITE_SCANSTAT_EXPLAIN</dt> |
| 7479 | -** <dd>^The "const char *" variable pointed to by the T parameter will be set to | |
| 7480 | -** a zero-terminated UTF-8 string containing the [EXPLAIN QUERY PLAN] description | |
| 7481 | -** for the X-th loop. | |
| 7503 | +** <dd>^The "const char *" variable pointed to by the T parameter will be set | |
| 7504 | +** to a zero-terminated UTF-8 string containing the [EXPLAIN QUERY PLAN] | |
| 7505 | +** description for the X-th loop. | |
| 7482 | 7506 | ** |
| 7483 | 7507 | ** [[SQLITE_SCANSTAT_SELECTID]] <dt>SQLITE_SCANSTAT_SELECT</dt> |
| 7484 | 7508 | ** <dd>^The "int" variable pointed to by the T parameter will be set to the |
| 7485 | 7509 | ** "select-id" for the X-th loop. The select-id identifies which query or |
| 7486 | 7510 | ** subquery the loop is part of. The main query has a select-id of zero. |
| @@ -7499,12 +7523,12 @@ | ||
| 7499 | 7523 | ** CAPI3REF: Prepared Statement Scan Status |
| 7500 | 7524 | ** |
| 7501 | 7525 | ** Return status data for a single loop within query pStmt. |
| 7502 | 7526 | ** |
| 7503 | 7527 | ** The "iScanStatusOp" parameter determines which status information to return. |
| 7504 | -** The "iScanStatusOp" must be one of the [scanstatus options] or the behavior of | |
| 7505 | -** this interface is undefined. | |
| 7528 | +** The "iScanStatusOp" must be one of the [scanstatus options] or the behavior | |
| 7529 | +** of this interface is undefined. | |
| 7506 | 7530 | ** ^The requested measurement is written into a variable pointed to by |
| 7507 | 7531 | ** the "pOut" parameter. |
| 7508 | 7532 | ** Parameter "idx" identifies the specific loop to retrieve statistics for. |
| 7509 | 7533 | ** Loops are numbered starting from zero. ^If idx is out of range - less than |
| 7510 | 7534 | ** zero or greater than or equal to the total number of loops used to implement |
| 7511 | 7535 |
| --- src/sqlite3.h | |
| +++ src/sqlite3.h | |
| @@ -107,11 +107,11 @@ | |
| 107 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 108 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 109 | */ |
| 110 | #define SQLITE_VERSION "3.8.8" |
| 111 | #define SQLITE_VERSION_NUMBER 3008008 |
| 112 | #define SQLITE_SOURCE_ID "2014-11-28 13:35:03 24fa2e9832daaa5d68ee28a00c56c55f97a4da9e" |
| 113 | |
| 114 | /* |
| 115 | ** CAPI3REF: Run-Time Library Version Numbers |
| 116 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 117 | ** |
| @@ -1219,11 +1219,11 @@ | |
| 1219 | ** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_SHARED |
| 1220 | ** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_EXCLUSIVE |
| 1221 | ** </ul> |
| 1222 | ** |
| 1223 | ** When unlocking, the same SHARED or EXCLUSIVE flag must be supplied as |
| 1224 | ** was given no the corresponding lock. |
| 1225 | ** |
| 1226 | ** The xShmLock method can transition between unlocked and SHARED or |
| 1227 | ** between unlocked and EXCLUSIVE. It cannot transition between SHARED |
| 1228 | ** and EXCLUSIVE. |
| 1229 | */ |
| @@ -1522,12 +1522,12 @@ | |
| 1522 | ** tracks memory usage, for example. </dd> |
| 1523 | ** |
| 1524 | ** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt> |
| 1525 | ** <dd> ^The SQLITE_CONFIG_MEMSTATUS option takes single argument of type int, |
| 1526 | ** interpreted as a boolean, which enables or disables the collection of |
| 1527 | ** memory allocation statistics. ^(When memory allocation statistics are disabled, the |
| 1528 | ** following SQLite interfaces become non-operational: |
| 1529 | ** <ul> |
| 1530 | ** <li> [sqlite3_memory_used()] |
| 1531 | ** <li> [sqlite3_memory_highwater()] |
| 1532 | ** <li> [sqlite3_soft_heap_limit64()] |
| 1533 | ** <li> [sqlite3_status()] |
| @@ -1564,11 +1564,12 @@ | |
| 1564 | ** that SQLite can use for the database page cache with the default page |
| 1565 | ** cache implementation. |
| 1566 | ** This configuration should not be used if an application-define page |
| 1567 | ** cache implementation is loaded using the [SQLITE_CONFIG_PCACHE2] |
| 1568 | ** configuration option. |
| 1569 | ** ^There are three arguments to SQLITE_CONFIG_PAGECACHE: A pointer to 8-byte aligned |
| 1570 | ** memory, the size of each page buffer (sz), and the number of pages (N). |
| 1571 | ** The sz argument should be the size of the largest database page |
| 1572 | ** (a power of two between 512 and 32768) plus some extra bytes for each |
| 1573 | ** page header. ^The number of extra bytes needed by the page header |
| 1574 | ** can be determined using the [SQLITE_CONFIG_PCACHE_HDRSZ] option |
| @@ -1584,11 +1585,12 @@ | |
| 1584 | ** SQLite goes to [sqlite3_malloc()] for the additional storage space.</dd> |
| 1585 | ** |
| 1586 | ** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt> |
| 1587 | ** <dd> ^The SQLITE_CONFIG_HEAP option specifies a static memory buffer |
| 1588 | ** that SQLite will use for all of its dynamic memory allocation needs |
| 1589 | ** beyond those provided for by [SQLITE_CONFIG_SCRATCH] and [SQLITE_CONFIG_PAGECACHE]. |
| 1590 | ** ^The SQLITE_CONFIG_HEAP option is only available if SQLite is compiled |
| 1591 | ** with either [SQLITE_ENABLE_MEMSYS3] or [SQLITE_ENABLE_MEMSYS5] and returns |
| 1592 | ** [SQLITE_ERROR] if invoked otherwise. |
| 1593 | ** ^There are three arguments to SQLITE_CONFIG_HEAP: |
| 1594 | ** An 8-byte aligned pointer to the memory, |
| @@ -1604,13 +1606,13 @@ | |
| 1604 | ** for the minimum allocation size are 2**5 through 2**8.</dd> |
| 1605 | ** |
| 1606 | ** [[SQLITE_CONFIG_MUTEX]] <dt>SQLITE_CONFIG_MUTEX</dt> |
| 1607 | ** <dd> ^(The SQLITE_CONFIG_MUTEX option takes a single argument which is a |
| 1608 | ** pointer to an instance of the [sqlite3_mutex_methods] structure. |
| 1609 | ** The argument specifies alternative low-level mutex routines to be used in place |
| 1610 | ** the mutex routines built into SQLite.)^ ^SQLite makes a copy of the |
| 1611 | ** content of the [sqlite3_mutex_methods] structure before the call to |
| 1612 | ** [sqlite3_config()] returns. ^If SQLite is compiled with |
| 1613 | ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then |
| 1614 | ** the entire mutexing subsystem is omitted from the build and hence calls to |
| 1615 | ** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will |
| 1616 | ** return [SQLITE_ERROR].</dd> |
| @@ -1644,12 +1646,12 @@ | |
| 1644 | ** the interface to a custom page cache implementation.)^ |
| 1645 | ** ^SQLite makes a copy of the [sqlite3_pcache_methods2] object.</dd> |
| 1646 | ** |
| 1647 | ** [[SQLITE_CONFIG_GETPCACHE2]] <dt>SQLITE_CONFIG_GETPCACHE2</dt> |
| 1648 | ** <dd> ^(The SQLITE_CONFIG_GETPCACHE2 option takes a single argument which |
| 1649 | ** is a pointer to an [sqlite3_pcache_methods2] object. SQLite copies of the current |
| 1650 | ** page cache implementation into that object.)^ </dd> |
| 1651 | ** |
| 1652 | ** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt> |
| 1653 | ** <dd> The SQLITE_CONFIG_LOG option is used to configure the SQLite |
| 1654 | ** global [error log]. |
| 1655 | ** (^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a |
| @@ -1670,12 +1672,13 @@ | |
| 1670 | ** function must be threadsafe. </dd> |
| 1671 | ** |
| 1672 | ** [[SQLITE_CONFIG_URI]] <dt>SQLITE_CONFIG_URI |
| 1673 | ** <dd>^(The SQLITE_CONFIG_URI option takes a single argument of type int. |
| 1674 | ** If non-zero, then URI handling is globally enabled. If the parameter is zero, |
| 1675 | ** then URI handling is globally disabled.)^ ^If URI handling is globally enabled, |
| 1676 | ** all filenames passed to [sqlite3_open()], [sqlite3_open_v2()], [sqlite3_open16()] or |
| 1677 | ** specified as part of [ATTACH] commands are interpreted as URIs, regardless |
| 1678 | ** of whether or not the [SQLITE_OPEN_URI] flag is set when the database |
| 1679 | ** connection is opened. ^If it is globally disabled, filenames are |
| 1680 | ** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the |
| 1681 | ** database connection is opened. ^(By default, URI handling is globally |
| @@ -1733,21 +1736,21 @@ | |
| 1733 | ** changed to its compile-time default. |
| 1734 | ** |
| 1735 | ** [[SQLITE_CONFIG_WIN32_HEAPSIZE]] |
| 1736 | ** <dt>SQLITE_CONFIG_WIN32_HEAPSIZE |
| 1737 | ** <dd>^The SQLITE_CONFIG_WIN32_HEAPSIZE option is only available if SQLite is |
| 1738 | ** compiled for Windows with the [SQLITE_WIN32_MALLOC] pre-processor macro defined. |
| 1739 | ** ^SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit unsigned integer value |
| 1740 | ** that specifies the maximum size of the created heap. |
| 1741 | ** </dl> |
| 1742 | ** |
| 1743 | ** [[SQLITE_CONFIG_PCACHE_HDRSZ]] |
| 1744 | ** <dt>SQLITE_CONFIG_PCACHE_HDRSZ |
| 1745 | ** <dd>^The SQLITE_CONFIG_PCACHE_HDRSZ option takes a single parameter which |
| 1746 | ** is a pointer to an integer and writes into that integer the number of extra |
| 1747 | ** bytes per page required for each page in [SQLITE_CONFIG_PAGECACHE]. The amount of |
| 1748 | ** extra space required can change depending on the compiler, |
| 1749 | ** target platform, and SQLite version. |
| 1750 | ** </dl> |
| 1751 | */ |
| 1752 | #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */ |
| 1753 | #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */ |
| @@ -2047,10 +2050,11 @@ | |
| 2047 | SQLITE_API int sqlite3_complete(const char *sql); |
| 2048 | SQLITE_API int sqlite3_complete16(const void *sql); |
| 2049 | |
| 2050 | /* |
| 2051 | ** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors |
| 2052 | ** |
| 2053 | ** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X |
| 2054 | ** that might be invoked with argument P whenever |
| 2055 | ** an attempt is made to access a database table associated with |
| 2056 | ** [database connection] D when another thread |
| @@ -2063,11 +2067,11 @@ | |
| 2063 | ** is not NULL, then the callback might be invoked with two arguments. |
| 2064 | ** |
| 2065 | ** ^The first argument to the busy handler is a copy of the void* pointer which |
| 2066 | ** is the third argument to sqlite3_busy_handler(). ^The second argument to |
| 2067 | ** the busy handler callback is the number of times that the busy handler has |
| 2068 | ** been invoked for the same locking event. ^If the |
| 2069 | ** busy callback returns 0, then no additional attempts are made to |
| 2070 | ** access the database and [SQLITE_BUSY] is returned |
| 2071 | ** to the application. |
| 2072 | ** ^If the callback returns non-zero, then another attempt |
| 2073 | ** is made to access the database and the cycle repeats. |
| @@ -4518,11 +4522,12 @@ | |
| 4518 | ** If these routines are called from within the different thread |
| 4519 | ** than the one containing the application-defined function that received |
| 4520 | ** the [sqlite3_context] pointer, the results are undefined. |
| 4521 | */ |
| 4522 | SQLITE_API void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*)); |
| 4523 | SQLITE_API void sqlite3_result_blob64(sqlite3_context*,const void*,sqlite3_uint64,void(*)(void*)); |
| 4524 | SQLITE_API void sqlite3_result_double(sqlite3_context*, double); |
| 4525 | SQLITE_API void sqlite3_result_error(sqlite3_context*, const char*, int); |
| 4526 | SQLITE_API void sqlite3_result_error16(sqlite3_context*, const void*, int); |
| 4527 | SQLITE_API void sqlite3_result_error_toobig(sqlite3_context*); |
| 4528 | SQLITE_API void sqlite3_result_error_nomem(sqlite3_context*); |
| @@ -7244,101 +7249,118 @@ | |
| 7244 | SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int N); |
| 7245 | |
| 7246 | /* |
| 7247 | ** CAPI3REF: Checkpoint a database |
| 7248 | ** |
| 7249 | ** ^The [sqlite3_wal_checkpoint(D,X)] interface causes database named X |
| 7250 | ** on [database connection] D to be [checkpointed]. ^If X is NULL or an |
| 7251 | ** empty string, then a checkpoint is run on all databases of |
| 7252 | ** connection D. ^If the database connection D is not in |
| 7253 | ** [WAL | write-ahead log mode] then this interface is a harmless no-op. |
| 7254 | ** ^The [sqlite3_wal_checkpoint(D,X)] interface initiates a |
| 7255 | ** [sqlite3_wal_checkpoint_v2|PASSIVE] checkpoint. |
| 7256 | ** Use the [sqlite3_wal_checkpoint_v2()] interface to get a FULL |
| 7257 | ** or RESET checkpoint. |
| 7258 | ** |
| 7259 | ** ^The [wal_checkpoint pragma] can be used to invoke this interface |
| 7260 | ** from SQL. ^The [sqlite3_wal_autocheckpoint()] interface and the |
| 7261 | ** [wal_autocheckpoint pragma] can be used to cause this interface to be |
| 7262 | ** run whenever the WAL reaches a certain size threshold. |
| 7263 | ** |
| 7264 | ** See also: [sqlite3_wal_checkpoint_v2()] |
| 7265 | */ |
| 7266 | SQLITE_API int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb); |
| 7267 | |
| 7268 | /* |
| 7269 | ** CAPI3REF: Checkpoint a database |
| 7270 | ** |
| 7271 | ** Run a checkpoint operation on WAL database zDb attached to database |
| 7272 | ** handle db. The specific operation is determined by the value of the |
| 7273 | ** eMode parameter: |
| 7274 | ** |
| 7275 | ** <dl> |
| 7276 | ** <dt>SQLITE_CHECKPOINT_PASSIVE<dd> |
| 7277 | ** Checkpoint as many frames as possible without waiting for any database |
| 7278 | ** readers or writers to finish. Sync the db file if all frames in the log |
| 7279 | ** are checkpointed. This mode is the same as calling |
| 7280 | ** sqlite3_wal_checkpoint(). The [sqlite3_busy_handler|busy-handler callback] |
| 7281 | ** is never invoked. |
| 7282 | ** |
| 7283 | ** <dt>SQLITE_CHECKPOINT_FULL<dd> |
| 7284 | ** This mode blocks (it invokes the |
| 7285 | ** [sqlite3_busy_handler|busy-handler callback]) until there is no |
| 7286 | ** database writer and all readers are reading from the most recent database |
| 7287 | ** snapshot. It then checkpoints all frames in the log file and syncs the |
| 7288 | ** database file. This call blocks database writers while it is running, |
| 7289 | ** but not database readers. |
| 7290 | ** |
| 7291 | ** <dt>SQLITE_CHECKPOINT_RESTART<dd> |
| 7292 | ** This mode works the same way as SQLITE_CHECKPOINT_FULL, except after |
| 7293 | ** checkpointing the log file it blocks (calls the |
| 7294 | ** [sqlite3_busy_handler|busy-handler callback]) |
| 7295 | ** until all readers are reading from the database file only. This ensures |
| 7296 | ** that the next client to write to the database file restarts the log file |
| 7297 | ** from the beginning. This call blocks database writers while it is running, |
| 7298 | ** but not database readers. |
| 7299 | ** </dl> |
| 7300 | ** |
| 7301 | ** If pnLog is not NULL, then *pnLog is set to the total number of frames in |
| 7302 | ** the log file before returning. If pnCkpt is not NULL, then *pnCkpt is set to |
| 7303 | ** the total number of checkpointed frames (including any that were already |
| 7304 | ** checkpointed when this function is called). *pnLog and *pnCkpt may be |
| 7305 | ** populated even if sqlite3_wal_checkpoint_v2() returns other than SQLITE_OK. |
| 7306 | ** If no values are available because of an error, they are both set to -1 |
| 7307 | ** before returning to communicate this to the caller. |
| 7308 | ** |
| 7309 | ** All calls obtain an exclusive "checkpoint" lock on the database file. If |
| 7310 | ** any other process is running a checkpoint operation at the same time, the |
| 7311 | ** lock cannot be obtained and SQLITE_BUSY is returned. Even if there is a |
| 7312 | ** busy-handler configured, it will not be invoked in this case. |
| 7313 | ** |
| 7314 | ** The SQLITE_CHECKPOINT_FULL and RESTART modes also obtain the exclusive |
| 7315 | ** "writer" lock on the database file. If the writer lock cannot be obtained |
| 7316 | ** immediately, and a busy-handler is configured, it is invoked and the writer |
| 7317 | ** lock retried until either the busy-handler returns 0 or the lock is |
| 7318 | ** successfully obtained. The busy-handler is also invoked while waiting for |
| 7319 | ** database readers as described above. If the busy-handler returns 0 before |
| 7320 | ** the writer lock is obtained or while waiting for database readers, the |
| 7321 | ** checkpoint operation proceeds from that point in the same way as |
| 7322 | ** SQLITE_CHECKPOINT_PASSIVE - checkpointing as many frames as possible |
| 7323 | ** without blocking any further. SQLITE_BUSY is returned in this case. |
| 7324 | ** |
| 7325 | ** If parameter zDb is NULL or points to a zero length string, then the |
| 7326 | ** specified operation is attempted on all WAL databases. In this case the |
| 7327 | ** values written to output parameters *pnLog and *pnCkpt are undefined. If |
| 7328 | ** an SQLITE_BUSY error is encountered when processing one or more of the |
| 7329 | ** attached WAL databases, the operation is still attempted on any remaining |
| 7330 | ** attached databases and SQLITE_BUSY is returned to the caller. If any other |
| 7331 | ** error occurs while processing an attached database, processing is abandoned |
| 7332 | ** and the error code returned to the caller immediately. If no error |
| 7333 | ** (SQLITE_BUSY or otherwise) is encountered while processing the attached |
| 7334 | ** databases, SQLITE_OK is returned. |
| 7335 | ** |
| 7336 | ** If database zDb is the name of an attached database that is not in WAL |
| 7337 | ** mode, SQLITE_OK is returned and both *pnLog and *pnCkpt set to -1. If |
| 7338 | ** zDb is not NULL (or a zero length string) and is not the name of any |
| 7339 | ** attached database, SQLITE_ERROR is returned to the caller. |
| 7340 | */ |
| 7341 | SQLITE_API int sqlite3_wal_checkpoint_v2( |
| 7342 | sqlite3 *db, /* Database handle */ |
| 7343 | const char *zDb, /* Name of attached database (or NULL) */ |
| 7344 | int eMode, /* SQLITE_CHECKPOINT_* value */ |
| @@ -7345,20 +7367,22 @@ | |
| 7345 | int *pnLog, /* OUT: Size of WAL log in frames */ |
| 7346 | int *pnCkpt /* OUT: Total number of frames checkpointed */ |
| 7347 | ); |
| 7348 | |
| 7349 | /* |
| 7350 | ** CAPI3REF: Checkpoint operation parameters |
| 7351 | ** |
| 7352 | ** These constants can be used as the 3rd parameter to |
| 7353 | ** [sqlite3_wal_checkpoint_v2()]. See the [sqlite3_wal_checkpoint_v2()] |
| 7354 | ** documentation for additional information about the meaning and use of |
| 7355 | ** each of these values. |
| 7356 | */ |
| 7357 | #define SQLITE_CHECKPOINT_PASSIVE 0 |
| 7358 | #define SQLITE_CHECKPOINT_FULL 1 |
| 7359 | #define SQLITE_CHECKPOINT_RESTART 2 |
| 7360 | |
| 7361 | /* |
| 7362 | ** CAPI3REF: Virtual Table Interface Configuration |
| 7363 | ** |
| 7364 | ** This function may be called by either the [xConnect] or [xCreate] method |
| @@ -7453,16 +7477,16 @@ | |
| 7453 | ** [sqlite3_stmt_scanstatus(S,X,T,V)] interface. Each constant designates a |
| 7454 | ** different metric for sqlite3_stmt_scanstatus() to return. |
| 7455 | ** |
| 7456 | ** <dl> |
| 7457 | ** [[SQLITE_SCANSTAT_NLOOP]] <dt>SQLITE_SCANSTAT_NLOOP</dt> |
| 7458 | ** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be set to the |
| 7459 | ** total number of times that the X-th loop has run.</dd> |
| 7460 | ** |
| 7461 | ** [[SQLITE_SCANSTAT_NVISIT]] <dt>SQLITE_SCANSTAT_NVISIT</dt> |
| 7462 | ** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be set to the |
| 7463 | ** total number of rows examined by all iterations of the X-th loop.</dd> |
| 7464 | ** |
| 7465 | ** [[SQLITE_SCANSTAT_EST]] <dt>SQLITE_SCANSTAT_EST</dt> |
| 7466 | ** <dd>^The "double" variable pointed to by the T parameter will be set to the |
| 7467 | ** query planner's estimate for the average number of rows output from each |
| 7468 | ** iteration of the X-th loop. If the query planner's estimates was accurate, |
| @@ -7469,18 +7493,18 @@ | |
| 7469 | ** then this value will approximate the quotient NVISIT/NLOOP and the |
| 7470 | ** product of this value for all prior loops with the same SELECTID will |
| 7471 | ** be the NLOOP value for the current loop. |
| 7472 | ** |
| 7473 | ** [[SQLITE_SCANSTAT_NAME]] <dt>SQLITE_SCANSTAT_NAME</dt> |
| 7474 | ** <dd>^The "const char *" variable pointed to by the T parameter will be set to |
| 7475 | ** a zero-terminated UTF-8 string containing the name of the index or table used |
| 7476 | ** for the X-th loop. |
| 7477 | ** |
| 7478 | ** [[SQLITE_SCANSTAT_EXPLAIN]] <dt>SQLITE_SCANSTAT_EXPLAIN</dt> |
| 7479 | ** <dd>^The "const char *" variable pointed to by the T parameter will be set to |
| 7480 | ** a zero-terminated UTF-8 string containing the [EXPLAIN QUERY PLAN] description |
| 7481 | ** for the X-th loop. |
| 7482 | ** |
| 7483 | ** [[SQLITE_SCANSTAT_SELECTID]] <dt>SQLITE_SCANSTAT_SELECT</dt> |
| 7484 | ** <dd>^The "int" variable pointed to by the T parameter will be set to the |
| 7485 | ** "select-id" for the X-th loop. The select-id identifies which query or |
| 7486 | ** subquery the loop is part of. The main query has a select-id of zero. |
| @@ -7499,12 +7523,12 @@ | |
| 7499 | ** CAPI3REF: Prepared Statement Scan Status |
| 7500 | ** |
| 7501 | ** Return status data for a single loop within query pStmt. |
| 7502 | ** |
| 7503 | ** The "iScanStatusOp" parameter determines which status information to return. |
| 7504 | ** The "iScanStatusOp" must be one of the [scanstatus options] or the behavior of |
| 7505 | ** this interface is undefined. |
| 7506 | ** ^The requested measurement is written into a variable pointed to by |
| 7507 | ** the "pOut" parameter. |
| 7508 | ** Parameter "idx" identifies the specific loop to retrieve statistics for. |
| 7509 | ** Loops are numbered starting from zero. ^If idx is out of range - less than |
| 7510 | ** zero or greater than or equal to the total number of loops used to implement |
| 7511 |
| --- src/sqlite3.h | |
| +++ src/sqlite3.h | |
| @@ -107,11 +107,11 @@ | |
| 107 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 108 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 109 | */ |
| 110 | #define SQLITE_VERSION "3.8.8" |
| 111 | #define SQLITE_VERSION_NUMBER 3008008 |
| 112 | #define SQLITE_SOURCE_ID "2014-12-06 14:56:49 6aeece19a235344be2537e66a3fe08b1febfb5a0" |
| 113 | |
| 114 | /* |
| 115 | ** CAPI3REF: Run-Time Library Version Numbers |
| 116 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 117 | ** |
| @@ -1219,11 +1219,11 @@ | |
| 1219 | ** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_SHARED |
| 1220 | ** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_EXCLUSIVE |
| 1221 | ** </ul> |
| 1222 | ** |
| 1223 | ** When unlocking, the same SHARED or EXCLUSIVE flag must be supplied as |
| 1224 | ** was given on the corresponding lock. |
| 1225 | ** |
| 1226 | ** The xShmLock method can transition between unlocked and SHARED or |
| 1227 | ** between unlocked and EXCLUSIVE. It cannot transition between SHARED |
| 1228 | ** and EXCLUSIVE. |
| 1229 | */ |
| @@ -1522,12 +1522,12 @@ | |
| 1522 | ** tracks memory usage, for example. </dd> |
| 1523 | ** |
| 1524 | ** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt> |
| 1525 | ** <dd> ^The SQLITE_CONFIG_MEMSTATUS option takes single argument of type int, |
| 1526 | ** interpreted as a boolean, which enables or disables the collection of |
| 1527 | ** memory allocation statistics. ^(When memory allocation statistics are |
| 1528 | ** disabled, the following SQLite interfaces become non-operational: |
| 1529 | ** <ul> |
| 1530 | ** <li> [sqlite3_memory_used()] |
| 1531 | ** <li> [sqlite3_memory_highwater()] |
| 1532 | ** <li> [sqlite3_soft_heap_limit64()] |
| 1533 | ** <li> [sqlite3_status()] |
| @@ -1564,11 +1564,12 @@ | |
| 1564 | ** that SQLite can use for the database page cache with the default page |
| 1565 | ** cache implementation. |
| 1566 | ** This configuration should not be used if an application-define page |
| 1567 | ** cache implementation is loaded using the [SQLITE_CONFIG_PCACHE2] |
| 1568 | ** configuration option. |
| 1569 | ** ^There are three arguments to SQLITE_CONFIG_PAGECACHE: A pointer to |
| 1570 | ** 8-byte aligned |
| 1571 | ** memory, the size of each page buffer (sz), and the number of pages (N). |
| 1572 | ** The sz argument should be the size of the largest database page |
| 1573 | ** (a power of two between 512 and 32768) plus some extra bytes for each |
| 1574 | ** page header. ^The number of extra bytes needed by the page header |
| 1575 | ** can be determined using the [SQLITE_CONFIG_PCACHE_HDRSZ] option |
| @@ -1584,11 +1585,12 @@ | |
| 1585 | ** SQLite goes to [sqlite3_malloc()] for the additional storage space.</dd> |
| 1586 | ** |
| 1587 | ** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt> |
| 1588 | ** <dd> ^The SQLITE_CONFIG_HEAP option specifies a static memory buffer |
| 1589 | ** that SQLite will use for all of its dynamic memory allocation needs |
| 1590 | ** beyond those provided for by [SQLITE_CONFIG_SCRATCH] and |
| 1591 | ** [SQLITE_CONFIG_PAGECACHE]. |
| 1592 | ** ^The SQLITE_CONFIG_HEAP option is only available if SQLite is compiled |
| 1593 | ** with either [SQLITE_ENABLE_MEMSYS3] or [SQLITE_ENABLE_MEMSYS5] and returns |
| 1594 | ** [SQLITE_ERROR] if invoked otherwise. |
| 1595 | ** ^There are three arguments to SQLITE_CONFIG_HEAP: |
| 1596 | ** An 8-byte aligned pointer to the memory, |
| @@ -1604,13 +1606,13 @@ | |
| 1606 | ** for the minimum allocation size are 2**5 through 2**8.</dd> |
| 1607 | ** |
| 1608 | ** [[SQLITE_CONFIG_MUTEX]] <dt>SQLITE_CONFIG_MUTEX</dt> |
| 1609 | ** <dd> ^(The SQLITE_CONFIG_MUTEX option takes a single argument which is a |
| 1610 | ** pointer to an instance of the [sqlite3_mutex_methods] structure. |
| 1611 | ** The argument specifies alternative low-level mutex routines to be used |
| 1612 | ** in place the mutex routines built into SQLite.)^ ^SQLite makes a copy of |
| 1613 | ** the content of the [sqlite3_mutex_methods] structure before the call to |
| 1614 | ** [sqlite3_config()] returns. ^If SQLite is compiled with |
| 1615 | ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then |
| 1616 | ** the entire mutexing subsystem is omitted from the build and hence calls to |
| 1617 | ** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will |
| 1618 | ** return [SQLITE_ERROR].</dd> |
| @@ -1644,12 +1646,12 @@ | |
| 1646 | ** the interface to a custom page cache implementation.)^ |
| 1647 | ** ^SQLite makes a copy of the [sqlite3_pcache_methods2] object.</dd> |
| 1648 | ** |
| 1649 | ** [[SQLITE_CONFIG_GETPCACHE2]] <dt>SQLITE_CONFIG_GETPCACHE2</dt> |
| 1650 | ** <dd> ^(The SQLITE_CONFIG_GETPCACHE2 option takes a single argument which |
| 1651 | ** is a pointer to an [sqlite3_pcache_methods2] object. SQLite copies of |
| 1652 | ** the current page cache implementation into that object.)^ </dd> |
| 1653 | ** |
| 1654 | ** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt> |
| 1655 | ** <dd> The SQLITE_CONFIG_LOG option is used to configure the SQLite |
| 1656 | ** global [error log]. |
| 1657 | ** (^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a |
| @@ -1670,12 +1672,13 @@ | |
| 1672 | ** function must be threadsafe. </dd> |
| 1673 | ** |
| 1674 | ** [[SQLITE_CONFIG_URI]] <dt>SQLITE_CONFIG_URI |
| 1675 | ** <dd>^(The SQLITE_CONFIG_URI option takes a single argument of type int. |
| 1676 | ** If non-zero, then URI handling is globally enabled. If the parameter is zero, |
| 1677 | ** then URI handling is globally disabled.)^ ^If URI handling is globally |
| 1678 | ** enabled, all filenames passed to [sqlite3_open()], [sqlite3_open_v2()], |
| 1679 | ** [sqlite3_open16()] or |
| 1680 | ** specified as part of [ATTACH] commands are interpreted as URIs, regardless |
| 1681 | ** of whether or not the [SQLITE_OPEN_URI] flag is set when the database |
| 1682 | ** connection is opened. ^If it is globally disabled, filenames are |
| 1683 | ** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the |
| 1684 | ** database connection is opened. ^(By default, URI handling is globally |
| @@ -1733,21 +1736,21 @@ | |
| 1736 | ** changed to its compile-time default. |
| 1737 | ** |
| 1738 | ** [[SQLITE_CONFIG_WIN32_HEAPSIZE]] |
| 1739 | ** <dt>SQLITE_CONFIG_WIN32_HEAPSIZE |
| 1740 | ** <dd>^The SQLITE_CONFIG_WIN32_HEAPSIZE option is only available if SQLite is |
| 1741 | ** compiled for Windows with the [SQLITE_WIN32_MALLOC] pre-processor macro |
| 1742 | ** defined. ^SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit unsigned integer value |
| 1743 | ** that specifies the maximum size of the created heap. |
| 1744 | ** </dl> |
| 1745 | ** |
| 1746 | ** [[SQLITE_CONFIG_PCACHE_HDRSZ]] |
| 1747 | ** <dt>SQLITE_CONFIG_PCACHE_HDRSZ |
| 1748 | ** <dd>^The SQLITE_CONFIG_PCACHE_HDRSZ option takes a single parameter which |
| 1749 | ** is a pointer to an integer and writes into that integer the number of extra |
| 1750 | ** bytes per page required for each page in [SQLITE_CONFIG_PAGECACHE]. |
| 1751 | ** The amount of extra space required can change depending on the compiler, |
| 1752 | ** target platform, and SQLite version. |
| 1753 | ** </dl> |
| 1754 | */ |
| 1755 | #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */ |
| 1756 | #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */ |
| @@ -2047,10 +2050,11 @@ | |
| 2050 | SQLITE_API int sqlite3_complete(const char *sql); |
| 2051 | SQLITE_API int sqlite3_complete16(const void *sql); |
| 2052 | |
| 2053 | /* |
| 2054 | ** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors |
| 2055 | ** KEYWORDS: {busy-handler callback} {busy handler} |
| 2056 | ** |
| 2057 | ** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X |
| 2058 | ** that might be invoked with argument P whenever |
| 2059 | ** an attempt is made to access a database table associated with |
| 2060 | ** [database connection] D when another thread |
| @@ -2063,11 +2067,11 @@ | |
| 2067 | ** is not NULL, then the callback might be invoked with two arguments. |
| 2068 | ** |
| 2069 | ** ^The first argument to the busy handler is a copy of the void* pointer which |
| 2070 | ** is the third argument to sqlite3_busy_handler(). ^The second argument to |
| 2071 | ** the busy handler callback is the number of times that the busy handler has |
| 2072 | ** been invoked previously for the same locking event. ^If the |
| 2073 | ** busy callback returns 0, then no additional attempts are made to |
| 2074 | ** access the database and [SQLITE_BUSY] is returned |
| 2075 | ** to the application. |
| 2076 | ** ^If the callback returns non-zero, then another attempt |
| 2077 | ** is made to access the database and the cycle repeats. |
| @@ -4518,11 +4522,12 @@ | |
| 4522 | ** If these routines are called from within the different thread |
| 4523 | ** than the one containing the application-defined function that received |
| 4524 | ** the [sqlite3_context] pointer, the results are undefined. |
| 4525 | */ |
| 4526 | SQLITE_API void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*)); |
| 4527 | SQLITE_API void sqlite3_result_blob64(sqlite3_context*,const void*, |
| 4528 | sqlite3_uint64,void(*)(void*)); |
| 4529 | SQLITE_API void sqlite3_result_double(sqlite3_context*, double); |
| 4530 | SQLITE_API void sqlite3_result_error(sqlite3_context*, const char*, int); |
| 4531 | SQLITE_API void sqlite3_result_error16(sqlite3_context*, const void*, int); |
| 4532 | SQLITE_API void sqlite3_result_error_toobig(sqlite3_context*); |
| 4533 | SQLITE_API void sqlite3_result_error_nomem(sqlite3_context*); |
| @@ -7244,101 +7249,118 @@ | |
| 7249 | SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int N); |
| 7250 | |
| 7251 | /* |
| 7252 | ** CAPI3REF: Checkpoint a database |
| 7253 | ** |
| 7254 | ** ^(The sqlite3_wal_checkpoint(D,X) is equivalent to |
| 7255 | ** [sqlite3_wal_checkpoint_v2](D,X,[SQLITE_CHECKPOINT_PASSIVE],0,0).)^ |
| 7256 | ** |
| 7257 | ** In brief, sqlite3_wal_checkpoint(D,X) causes the content in the |
| 7258 | ** [write-ahead log] for database X on [database connection] D to be |
| 7259 | ** transferred into the database file and for the write-ahead log to |
| 7260 | ** be reset. See the [checkpointing] documentation for addition |
| 7261 | ** information. |
| 7262 | ** |
| 7263 | ** This interface used to be the only way to cause a checkpoint to |
| 7264 | ** occur. But then the newer and more powerful [sqlite3_wal_checkpoint_v2()] |
| 7265 | ** interface was added. This interface is retained for backwards |
| 7266 | ** compatibility and as a convenience for applications that need to manually |
| 7267 | ** start a callback but which do not need the full power (and corresponding |
| 7268 | ** complication) of [sqlite3_wal_checkpoint_v2()]. |
| 7269 | */ |
| 7270 | SQLITE_API int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb); |
| 7271 | |
| 7272 | /* |
| 7273 | ** CAPI3REF: Checkpoint a database |
| 7274 | ** |
| 7275 | ** ^(The sqlite3_wal_checkpoint_v2(D,X,M,L,C) interface runs a checkpoint |
| 7276 | ** operation on database X of [database connection] D in mode M. Status |
| 7277 | ** information is written back into integers pointed to by L and C.)^ |
| 7278 | ** ^(The M parameter must be a valid [checkpoint mode]:)^ |
| 7279 | ** |
| 7280 | ** <dl> |
| 7281 | ** <dt>SQLITE_CHECKPOINT_PASSIVE<dd> |
| 7282 | ** ^Checkpoint as many frames as possible without waiting for any database |
| 7283 | ** readers or writers to finish, then sync the database file if all frames |
| 7284 | ** in the log were checkpointed. ^The [busy-handler callback] |
| 7285 | ** is never invoked in the SQLITE_CHECKPOINT_PASSIVE mode. |
| 7286 | ** ^On the other hand, passive mode might leave the checkpoint unfinished |
| 7287 | ** if there are concurrent readers or writers. |
| 7288 | ** |
| 7289 | ** <dt>SQLITE_CHECKPOINT_FULL<dd> |
| 7290 | ** ^This mode blocks (it invokes the |
| 7291 | ** [sqlite3_busy_handler|busy-handler callback]) until there is no |
| 7292 | ** database writer and all readers are reading from the most recent database |
| 7293 | ** snapshot. ^It then checkpoints all frames in the log file and syncs the |
| 7294 | ** database file. ^This mode blocks new database writers while it is pending, |
| 7295 | ** but new database readers are allowed to continue unimpeded. |
| 7296 | ** |
| 7297 | ** <dt>SQLITE_CHECKPOINT_RESTART<dd> |
| 7298 | ** ^This mode works the same way as SQLITE_CHECKPOINT_FULL with the addition |
| 7299 | ** that after checkpointing the log file it blocks (calls the |
| 7300 | ** [busy-handler callback]) |
| 7301 | ** until all readers are reading from the database file only. ^This ensures |
| 7302 | ** that the next writer will restart the log file from the beginning. |
| 7303 | ** ^Like SQLITE_CHECKPOINT_FULL, this mode blocks new |
| 7304 | ** database writer attempts while it is pending, but does not impede readers. |
| 7305 | ** |
| 7306 | ** <dt>SQLITE_CHECKPOINT_TRUNCATE<dd> |
| 7307 | ** ^This mode works the same way as SQLITE_CHECKPOINT_RESTART with the |
| 7308 | ** addition that it also truncates the log file to zero bytes just prior |
| 7309 | ** to a successful return. |
| 7310 | ** </dl> |
| 7311 | ** |
| 7312 | ** ^If pnLog is not NULL, then *pnLog is set to the total number of frames in |
| 7313 | ** the log file or to -1 if the checkpoint could not run because |
| 7314 | ** of an error or because the database is not in [WAL mode]. ^If pnCkpt is not |
| 7315 | ** NULL,then *pnCkpt is set to the total number of checkpointed frames in the |
| 7316 | ** log file (including any that were already checkpointed before the function |
| 7317 | ** was called) or to -1 if the checkpoint could not run due to an error or |
| 7318 | ** because the database is not in WAL mode. ^Note that upon successful |
| 7319 | ** completion of an SQLITE_CHECKPOINT_TRUNCATE, the log file will have been |
| 7320 | ** truncated to zero bytes and so both *pnLog and *pnCkpt will be set to zero. |
| 7321 | ** |
| 7322 | ** ^All calls obtain an exclusive "checkpoint" lock on the database file. ^If |
| 7323 | ** any other process is running a checkpoint operation at the same time, the |
| 7324 | ** lock cannot be obtained and SQLITE_BUSY is returned. ^Even if there is a |
| 7325 | ** busy-handler configured, it will not be invoked in this case. |
| 7326 | ** |
| 7327 | ** ^The SQLITE_CHECKPOINT_FULL, RESTART and TRUNCATE modes also obtain the |
| 7328 | ** exclusive "writer" lock on the database file. ^If the writer lock cannot be |
| 7329 | ** obtained immediately, and a busy-handler is configured, it is invoked and |
| 7330 | ** the writer lock retried until either the busy-handler returns 0 or the lock |
| 7331 | ** is successfully obtained. ^The busy-handler is also invoked while waiting for |
| 7332 | ** database readers as described above. ^If the busy-handler returns 0 before |
| 7333 | ** the writer lock is obtained or while waiting for database readers, the |
| 7334 | ** checkpoint operation proceeds from that point in the same way as |
| 7335 | ** SQLITE_CHECKPOINT_PASSIVE - checkpointing as many frames as possible |
| 7336 | ** without blocking any further. ^SQLITE_BUSY is returned in this case. |
| 7337 | ** |
| 7338 | ** ^If parameter zDb is NULL or points to a zero length string, then the |
| 7339 | ** specified operation is attempted on all WAL databases [attached] to |
| 7340 | ** [database connection] db. In this case the |
| 7341 | ** values written to output parameters *pnLog and *pnCkpt are undefined. ^If |
| 7342 | ** an SQLITE_BUSY error is encountered when processing one or more of the |
| 7343 | ** attached WAL databases, the operation is still attempted on any remaining |
| 7344 | ** attached databases and SQLITE_BUSY is returned at the end. ^If any other |
| 7345 | ** error occurs while processing an attached database, processing is abandoned |
| 7346 | ** and the error code is returned to the caller immediately. ^If no error |
| 7347 | ** (SQLITE_BUSY or otherwise) is encountered while processing the attached |
| 7348 | ** databases, SQLITE_OK is returned. |
| 7349 | ** |
| 7350 | ** ^If database zDb is the name of an attached database that is not in WAL |
| 7351 | ** mode, SQLITE_OK is returned and both *pnLog and *pnCkpt set to -1. ^If |
| 7352 | ** zDb is not NULL (or a zero length string) and is not the name of any |
| 7353 | ** attached database, SQLITE_ERROR is returned to the caller. |
| 7354 | ** |
| 7355 | ** ^Unless it returns SQLITE_MISUSE, |
| 7356 | ** the sqlite3_wal_checkpoint_v2() interface |
| 7357 | ** sets the error information that is queried by |
| 7358 | ** [sqlite3_errcode()] and [sqlite3_errmsg()]. |
| 7359 | ** |
| 7360 | ** ^The [PRAGMA wal_checkpoint] command can be used to invoke this interface |
| 7361 | ** from SQL. |
| 7362 | */ |
| 7363 | SQLITE_API int sqlite3_wal_checkpoint_v2( |
| 7364 | sqlite3 *db, /* Database handle */ |
| 7365 | const char *zDb, /* Name of attached database (or NULL) */ |
| 7366 | int eMode, /* SQLITE_CHECKPOINT_* value */ |
| @@ -7345,20 +7367,22 @@ | |
| 7367 | int *pnLog, /* OUT: Size of WAL log in frames */ |
| 7368 | int *pnCkpt /* OUT: Total number of frames checkpointed */ |
| 7369 | ); |
| 7370 | |
| 7371 | /* |
| 7372 | ** CAPI3REF: Checkpoint Mode Values |
| 7373 | ** KEYWORDS: {checkpoint mode} |
| 7374 | ** |
| 7375 | ** These constants define all valid values for the "checkpoint mode" passed |
| 7376 | ** as the third parameter to the [sqlite3_wal_checkpoint_v2()] interface. |
| 7377 | ** See the [sqlite3_wal_checkpoint_v2()] documentation for details on the |
| 7378 | ** meaning of each of these checkpoint modes. |
| 7379 | */ |
| 7380 | #define SQLITE_CHECKPOINT_PASSIVE 0 /* Do as much as possible w/o blocking */ |
| 7381 | #define SQLITE_CHECKPOINT_FULL 1 /* Wait for writers, then checkpoint */ |
| 7382 | #define SQLITE_CHECKPOINT_RESTART 2 /* Like FULL but wait for for readers */ |
| 7383 | #define SQLITE_CHECKPOINT_TRUNCATE 3 /* Like RESTART but also truncate WAL */ |
| 7384 | |
| 7385 | /* |
| 7386 | ** CAPI3REF: Virtual Table Interface Configuration |
| 7387 | ** |
| 7388 | ** This function may be called by either the [xConnect] or [xCreate] method |
| @@ -7453,16 +7477,16 @@ | |
| 7477 | ** [sqlite3_stmt_scanstatus(S,X,T,V)] interface. Each constant designates a |
| 7478 | ** different metric for sqlite3_stmt_scanstatus() to return. |
| 7479 | ** |
| 7480 | ** <dl> |
| 7481 | ** [[SQLITE_SCANSTAT_NLOOP]] <dt>SQLITE_SCANSTAT_NLOOP</dt> |
| 7482 | ** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be |
| 7483 | ** set to the total number of times that the X-th loop has run.</dd> |
| 7484 | ** |
| 7485 | ** [[SQLITE_SCANSTAT_NVISIT]] <dt>SQLITE_SCANSTAT_NVISIT</dt> |
| 7486 | ** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be set |
| 7487 | ** to the total number of rows examined by all iterations of the X-th loop.</dd> |
| 7488 | ** |
| 7489 | ** [[SQLITE_SCANSTAT_EST]] <dt>SQLITE_SCANSTAT_EST</dt> |
| 7490 | ** <dd>^The "double" variable pointed to by the T parameter will be set to the |
| 7491 | ** query planner's estimate for the average number of rows output from each |
| 7492 | ** iteration of the X-th loop. If the query planner's estimates was accurate, |
| @@ -7469,18 +7493,18 @@ | |
| 7493 | ** then this value will approximate the quotient NVISIT/NLOOP and the |
| 7494 | ** product of this value for all prior loops with the same SELECTID will |
| 7495 | ** be the NLOOP value for the current loop. |
| 7496 | ** |
| 7497 | ** [[SQLITE_SCANSTAT_NAME]] <dt>SQLITE_SCANSTAT_NAME</dt> |
| 7498 | ** <dd>^The "const char *" variable pointed to by the T parameter will be set |
| 7499 | ** to a zero-terminated UTF-8 string containing the name of the index or table |
| 7500 | ** used for the X-th loop. |
| 7501 | ** |
| 7502 | ** [[SQLITE_SCANSTAT_EXPLAIN]] <dt>SQLITE_SCANSTAT_EXPLAIN</dt> |
| 7503 | ** <dd>^The "const char *" variable pointed to by the T parameter will be set |
| 7504 | ** to a zero-terminated UTF-8 string containing the [EXPLAIN QUERY PLAN] |
| 7505 | ** description for the X-th loop. |
| 7506 | ** |
| 7507 | ** [[SQLITE_SCANSTAT_SELECTID]] <dt>SQLITE_SCANSTAT_SELECT</dt> |
| 7508 | ** <dd>^The "int" variable pointed to by the T parameter will be set to the |
| 7509 | ** "select-id" for the X-th loop. The select-id identifies which query or |
| 7510 | ** subquery the loop is part of. The main query has a select-id of zero. |
| @@ -7499,12 +7523,12 @@ | |
| 7523 | ** CAPI3REF: Prepared Statement Scan Status |
| 7524 | ** |
| 7525 | ** Return status data for a single loop within query pStmt. |
| 7526 | ** |
| 7527 | ** The "iScanStatusOp" parameter determines which status information to return. |
| 7528 | ** The "iScanStatusOp" must be one of the [scanstatus options] or the behavior |
| 7529 | ** of this interface is undefined. |
| 7530 | ** ^The requested measurement is written into a variable pointed to by |
| 7531 | ** the "pOut" parameter. |
| 7532 | ** Parameter "idx" identifies the specific loop to retrieve statistics for. |
| 7533 | ** Loops are numbered starting from zero. ^If idx is out of range - less than |
| 7534 | ** zero or greater than or equal to the total number of loops used to implement |
| 7535 |