Fossil SCM

Update the built-in SQLite to the latest 3.8.8 alpha.

drh 2014-12-06 15:44 trunk
Commit 5e598cec4426392869b7dc09ef74447fdf4b1868
2 files changed +263 -156 +121 -97
+263 -156
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -231,11 +231,11 @@
231231
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
232232
** [sqlite_version()] and [sqlite_source_id()].
233233
*/
234234
#define SQLITE_VERSION "3.8.8"
235235
#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"
237237
238238
/*
239239
** CAPI3REF: Run-Time Library Version Numbers
240240
** KEYWORDS: sqlite3_version, sqlite3_sourceid
241241
**
@@ -1343,11 +1343,11 @@
13431343
** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_SHARED
13441344
** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_EXCLUSIVE
13451345
** </ul>
13461346
**
13471347
** 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.
13491349
**
13501350
** The xShmLock method can transition between unlocked and SHARED or
13511351
** between unlocked and EXCLUSIVE. It cannot transition between SHARED
13521352
** and EXCLUSIVE.
13531353
*/
@@ -1646,12 +1646,12 @@
16461646
** tracks memory usage, for example. </dd>
16471647
**
16481648
** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt>
16491649
** <dd> ^The SQLITE_CONFIG_MEMSTATUS option takes single argument of type int,
16501650
** 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:
16531653
** <ul>
16541654
** <li> [sqlite3_memory_used()]
16551655
** <li> [sqlite3_memory_highwater()]
16561656
** <li> [sqlite3_soft_heap_limit64()]
16571657
** <li> [sqlite3_status()]
@@ -1688,11 +1688,12 @@
16881688
** that SQLite can use for the database page cache with the default page
16891689
** cache implementation.
16901690
** This configuration should not be used if an application-define page
16911691
** cache implementation is loaded using the [SQLITE_CONFIG_PCACHE2]
16921692
** 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
16941695
** memory, the size of each page buffer (sz), and the number of pages (N).
16951696
** The sz argument should be the size of the largest database page
16961697
** (a power of two between 512 and 32768) plus some extra bytes for each
16971698
** page header. ^The number of extra bytes needed by the page header
16981699
** can be determined using the [SQLITE_CONFIG_PCACHE_HDRSZ] option
@@ -1708,11 +1709,12 @@
17081709
** SQLite goes to [sqlite3_malloc()] for the additional storage space.</dd>
17091710
**
17101711
** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt>
17111712
** <dd> ^The SQLITE_CONFIG_HEAP option specifies a static memory buffer
17121713
** 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].
17141716
** ^The SQLITE_CONFIG_HEAP option is only available if SQLite is compiled
17151717
** with either [SQLITE_ENABLE_MEMSYS3] or [SQLITE_ENABLE_MEMSYS5] and returns
17161718
** [SQLITE_ERROR] if invoked otherwise.
17171719
** ^There are three arguments to SQLITE_CONFIG_HEAP:
17181720
** An 8-byte aligned pointer to the memory,
@@ -1728,13 +1730,13 @@
17281730
** for the minimum allocation size are 2**5 through 2**8.</dd>
17291731
**
17301732
** [[SQLITE_CONFIG_MUTEX]] <dt>SQLITE_CONFIG_MUTEX</dt>
17311733
** <dd> ^(The SQLITE_CONFIG_MUTEX option takes a single argument which is a
17321734
** 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
17361738
** [sqlite3_config()] returns. ^If SQLite is compiled with
17371739
** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
17381740
** the entire mutexing subsystem is omitted from the build and hence calls to
17391741
** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will
17401742
** return [SQLITE_ERROR].</dd>
@@ -1768,12 +1770,12 @@
17681770
** the interface to a custom page cache implementation.)^
17691771
** ^SQLite makes a copy of the [sqlite3_pcache_methods2] object.</dd>
17701772
**
17711773
** [[SQLITE_CONFIG_GETPCACHE2]] <dt>SQLITE_CONFIG_GETPCACHE2</dt>
17721774
** <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>
17751777
**
17761778
** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt>
17771779
** <dd> The SQLITE_CONFIG_LOG option is used to configure the SQLite
17781780
** global [error log].
17791781
** (^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a
@@ -1794,12 +1796,13 @@
17941796
** function must be threadsafe. </dd>
17951797
**
17961798
** [[SQLITE_CONFIG_URI]] <dt>SQLITE_CONFIG_URI
17971799
** <dd>^(The SQLITE_CONFIG_URI option takes a single argument of type int.
17981800
** 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
18011804
** specified as part of [ATTACH] commands are interpreted as URIs, regardless
18021805
** of whether or not the [SQLITE_OPEN_URI] flag is set when the database
18031806
** connection is opened. ^If it is globally disabled, filenames are
18041807
** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the
18051808
** database connection is opened. ^(By default, URI handling is globally
@@ -1857,21 +1860,21 @@
18571860
** changed to its compile-time default.
18581861
**
18591862
** [[SQLITE_CONFIG_WIN32_HEAPSIZE]]
18601863
** <dt>SQLITE_CONFIG_WIN32_HEAPSIZE
18611864
** <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
18641867
** that specifies the maximum size of the created heap.
18651868
** </dl>
18661869
**
18671870
** [[SQLITE_CONFIG_PCACHE_HDRSZ]]
18681871
** <dt>SQLITE_CONFIG_PCACHE_HDRSZ
18691872
** <dd>^The SQLITE_CONFIG_PCACHE_HDRSZ option takes a single parameter which
18701873
** 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,
18731876
** target platform, and SQLite version.
18741877
** </dl>
18751878
*/
18761879
#define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
18771880
#define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
@@ -2171,10 +2174,11 @@
21712174
SQLITE_API int sqlite3_complete(const char *sql);
21722175
SQLITE_API int sqlite3_complete16(const void *sql);
21732176
21742177
/*
21752178
** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors
2179
+** KEYWORDS: {busy-handler callback} {busy handler}
21762180
**
21772181
** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X
21782182
** that might be invoked with argument P whenever
21792183
** an attempt is made to access a database table associated with
21802184
** [database connection] D when another thread
@@ -2187,11 +2191,11 @@
21872191
** is not NULL, then the callback might be invoked with two arguments.
21882192
**
21892193
** ^The first argument to the busy handler is a copy of the void* pointer which
21902194
** is the third argument to sqlite3_busy_handler(). ^The second argument to
21912195
** 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
21932197
** busy callback returns 0, then no additional attempts are made to
21942198
** access the database and [SQLITE_BUSY] is returned
21952199
** to the application.
21962200
** ^If the callback returns non-zero, then another attempt
21972201
** is made to access the database and the cycle repeats.
@@ -4642,11 +4646,12 @@
46424646
** If these routines are called from within the different thread
46434647
** than the one containing the application-defined function that received
46444648
** the [sqlite3_context] pointer, the results are undefined.
46454649
*/
46464650
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*));
46484653
SQLITE_API void sqlite3_result_double(sqlite3_context*, double);
46494654
SQLITE_API void sqlite3_result_error(sqlite3_context*, const char*, int);
46504655
SQLITE_API void sqlite3_result_error16(sqlite3_context*, const void*, int);
46514656
SQLITE_API void sqlite3_result_error_toobig(sqlite3_context*);
46524657
SQLITE_API void sqlite3_result_error_nomem(sqlite3_context*);
@@ -7368,101 +7373,118 @@
73687373
SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
73697374
73707375
/*
73717376
** CAPI3REF: Checkpoint a database
73727377
**
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()].
73897393
*/
73907394
SQLITE_API int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb);
73917395
73927396
/*
73937397
** CAPI3REF: Checkpoint a database
73947398
**
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]:)^
73987403
**
73997404
** <dl>
74007405
** <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.
74067412
**
74077413
** <dt>SQLITE_CHECKPOINT_FULL<dd>
7408
-** This mode blocks (it invokes the
7414
+** ^This mode blocks (it invokes the
74097415
** [sqlite3_busy_handler|busy-handler callback]) until there is no
74107416
** 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.
74147420
**
74157421
** <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.
74237434
** </dl>
74247435
**
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.
74327445
**
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
74347447
** 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
74367449
** busy-handler configured, it will not be invoked in this case.
74377450
**
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
74447457
** the writer lock is obtained or while waiting for database readers, the
74457458
** checkpoint operation proceeds from that point in the same way as
74467459
** 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.
74487461
**
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
74527466
** an SQLITE_BUSY error is encountered when processing one or more of the
74537467
** 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
74557469
** 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
74577471
** (SQLITE_BUSY or otherwise) is encountered while processing the attached
74587472
** databases, SQLITE_OK is returned.
74597473
**
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
74627476
** zDb is not NULL (or a zero length string) and is not the name of any
74637477
** 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.
74647486
*/
74657487
SQLITE_API int sqlite3_wal_checkpoint_v2(
74667488
sqlite3 *db, /* Database handle */
74677489
const char *zDb, /* Name of attached database (or NULL) */
74687490
int eMode, /* SQLITE_CHECKPOINT_* value */
@@ -7469,20 +7491,22 @@
74697491
int *pnLog, /* OUT: Size of WAL log in frames */
74707492
int *pnCkpt /* OUT: Total number of frames checkpointed */
74717493
);
74727494
74737495
/*
7474
-** CAPI3REF: Checkpoint operation parameters
7496
+** CAPI3REF: Checkpoint Mode Values
7497
+** KEYWORDS: {checkpoint mode}
74757498
**
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.
74807503
*/
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 */
74847508
74857509
/*
74867510
** CAPI3REF: Virtual Table Interface Configuration
74877511
**
74887512
** This function may be called by either the [xConnect] or [xCreate] method
@@ -7577,16 +7601,16 @@
75777601
** [sqlite3_stmt_scanstatus(S,X,T,V)] interface. Each constant designates a
75787602
** different metric for sqlite3_stmt_scanstatus() to return.
75797603
**
75807604
** <dl>
75817605
** [[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>
75847608
**
75857609
** [[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>
75887612
**
75897613
** [[SQLITE_SCANSTAT_EST]] <dt>SQLITE_SCANSTAT_EST</dt>
75907614
** <dd>^The "double" variable pointed to by the T parameter will be set to the
75917615
** query planner's estimate for the average number of rows output from each
75927616
** iteration of the X-th loop. If the query planner's estimates was accurate,
@@ -7593,18 +7617,18 @@
75937617
** then this value will approximate the quotient NVISIT/NLOOP and the
75947618
** product of this value for all prior loops with the same SELECTID will
75957619
** be the NLOOP value for the current loop.
75967620
**
75977621
** [[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.
76017625
**
76027626
** [[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.
76067630
**
76077631
** [[SQLITE_SCANSTAT_SELECTID]] <dt>SQLITE_SCANSTAT_SELECT</dt>
76087632
** <dd>^The "int" variable pointed to by the T parameter will be set to the
76097633
** "select-id" for the X-th loop. The select-id identifies which query or
76107634
** subquery the loop is part of. The main query has a select-id of zero.
@@ -7623,12 +7647,12 @@
76237647
** CAPI3REF: Prepared Statement Scan Status
76247648
**
76257649
** Return status data for a single loop within query pStmt.
76267650
**
76277651
** 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.
76307654
** ^The requested measurement is written into a variable pointed to by
76317655
** the "pOut" parameter.
76327656
** Parameter "idx" identifies the specific loop to retrieve statistics for.
76337657
** Loops are numbered starting from zero. ^If idx is out of range - less than
76347658
** zero or greater than or equal to the total number of loops used to implement
@@ -11675,11 +11699,11 @@
1167511699
};
1167611700
1167711701
/*
1167811702
** The following are the meanings of bits in the Expr.flags field.
1167911703
*/
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 */
1168111705
#define EP_Agg 0x000002 /* Contains one or more aggregate functions */
1168211706
#define EP_Resolved 0x000004 /* IDs have been resolved to COLUMNs */
1168311707
#define EP_Error 0x000008 /* Expression contains one or more errors */
1168411708
#define EP_Distinct 0x000010 /* Aggregate function with DISTINCT keyword */
1168511709
#define EP_VarSelect 0x000020 /* pSelect is correlated, not constant */
@@ -11695,10 +11719,11 @@
1169511719
#define EP_Static 0x008000 /* Held in memory not obtained from malloc() */
1169611720
#define EP_MemToken 0x010000 /* Need to sqlite3DbFree() Expr.zToken */
1169711721
#define EP_NoReduce 0x020000 /* Cannot EXPRDUP_REDUCE this Expr */
1169811722
#define EP_Unlikely 0x040000 /* unlikely() or likelihood() function */
1169911723
#define EP_Constant 0x080000 /* Node is a constant */
11724
+#define EP_CanBeNull 0x100000 /* Can be null despite NOT NULL constraint */
1170011725
1170111726
/*
1170211727
** These macros can be used to test, set, or clear bits in the
1170311728
** Expr.flags field.
1170411729
*/
@@ -48199,11 +48224,12 @@
4819948224
*/
4820048225
SQLITE_PRIVATE int sqlite3PagerCheckpoint(Pager *pPager, int eMode, int *pnLog, int *pnCkpt){
4820148226
int rc = SQLITE_OK;
4820248227
if( pPager->pWal ){
4820348228
rc = sqlite3WalCheckpoint(pPager->pWal, eMode,
48204
- pPager->xBusyHandler, pPager->pBusyHandlerArg,
48229
+ (eMode==SQLITE_CHECKPOINT_PASSIVE ? 0 : pPager->xBusyHandler),
48230
+ pPager->pBusyHandlerArg,
4820548231
pPager->ckptSyncFlags, pPager->pageSize, (u8 *)pPager->pTmpSpace,
4820648232
pnLog, pnCkpt
4820748233
);
4820848234
}
4820948235
return rc;
@@ -50009,10 +50035,42 @@
5000950035
** Return the page-size in bytes used by the database.
5001050036
*/
5001150037
static int walPagesize(Wal *pWal){
5001250038
return (pWal->hdr.szPage&0xfe00) + ((pWal->hdr.szPage&0x0001)<<16);
5001350039
}
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
+}
5001450072
5001550073
/*
5001650074
** Copy as much content as we can from the WAL back into the database file
5001750075
** in response to an sqlite3_wal_checkpoint() request or the equivalent.
5001850076
**
@@ -50044,11 +50102,11 @@
5004450102
** time.
5004550103
*/
5004650104
static int walCheckpoint(
5004750105
Wal *pWal, /* Wal connection */
5004850106
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 */
5005050108
void *pBusyArg, /* Context argument for xBusyHandler */
5005150109
int sync_flags, /* Flags for OsSync() (or 0) */
5005250110
u8 *zBuf /* Temporary buffer to use */
5005350111
){
5005450112
int rc; /* Return code */
@@ -50058,11 +50116,10 @@
5005850116
u32 iFrame = 0; /* Wal frame containing data for iDbpage */
5005950117
u32 mxSafeFrame; /* Max frame that can be backfilled */
5006050118
u32 mxPage; /* Max database page to write */
5006150119
int i; /* Loop counter */
5006250120
volatile WalCkptInfo *pInfo; /* The checkpoint status information */
50063
- int (*xBusy)(void*) = 0; /* Function to call when waiting for locks */
5006450121
5006550122
szPage = walPagesize(pWal);
5006650123
testcase( szPage<=32768 );
5006750124
testcase( szPage>=65536 );
5006850125
pInfo = walCkptInfo(pWal);
@@ -50073,11 +50130,13 @@
5007350130
if( rc!=SQLITE_OK ){
5007450131
return rc;
5007550132
}
5007650133
assert( pIter );
5007750134
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 );
5007950138
5008050139
/* Compute in mxSafeFrame the index of the last frame of the WAL that is
5008150140
** safe to write into the database. Frames beyond mxSafeFrame might
5008250141
** overwrite database pages that are in use by active readers and thus
5008350142
** cannot be backfilled from the WAL.
@@ -50162,23 +50221,42 @@
5016250221
/* Reset the return code so as not to report a checkpoint failure
5016350222
** just because there are active readers. */
5016450223
rc = SQLITE_OK;
5016550224
}
5016650225
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.
5017150230
*/
5017250231
if( rc==SQLITE_OK && eMode!=SQLITE_CHECKPOINT_PASSIVE ){
5017350232
assert( pWal->writeLock );
5017450233
if( pInfo->nBackfill<pWal->hdr.mxFrame ){
5017550234
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);
5017750238
assert( mxSafeFrame==pWal->hdr.mxFrame );
5017850239
rc = walBusyLock(pWal, xBusy, pBusyArg, WAL_READ_LOCK(1), WAL_NREADER-1);
5017950240
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
+ }
5018050258
walUnlockExclusive(pWal, WAL_READ_LOCK(1), WAL_NREADER-1);
5018150259
}
5018250260
}
5018350261
}
5018450262
@@ -50960,11 +51038,10 @@
5096051038
}
5096151039
5096251040
return rc;
5096351041
}
5096451042
50965
-
5096651043
/*
5096751044
** This function is called just before writing a set of frames to the log
5096851045
** file (see sqlite3WalFrames()). It checks to see if, instead of appending
5096951046
** to the current log file, it is possible to overwrite the start of the
5097051047
** existing log file with the new frames (i.e. "reset" the log). If so,
@@ -50993,24 +51070,12 @@
5099351070
** wal-index header to reflect this.
5099451071
**
5099551072
** In theory it would be Ok to update the cache of the header only
5099651073
** at this point. But updating the actual wal-index header is also
5099751074
** 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);
5101251077
walUnlockExclusive(pWal, WAL_READ_LOCK(1), WAL_NREADER-1);
5101351078
}else if( rc!=SQLITE_BUSY ){
5101451079
return rc;
5101551080
}
5101651081
}
@@ -51294,11 +51359,11 @@
5129451359
** If parameter xBusy is not NULL, it is a pointer to a busy-handler
5129551360
** callback. In this case this function runs a blocking checkpoint.
5129651361
*/
5129751362
SQLITE_PRIVATE int sqlite3WalCheckpoint(
5129851363
Wal *pWal, /* Wal connection */
51299
- int eMode, /* PASSIVE, FULL or RESTART */
51364
+ int eMode, /* PASSIVE, FULL, RESTART, or TRUNCATE */
5130051365
int (*xBusy)(void*), /* Function to call when busy */
5130151366
void *pBusyArg, /* Context argument for xBusyHandler */
5130251367
int sync_flags, /* Flags to sync db file with (or 0) */
5130351368
int nBuf, /* Size of temporary buffer */
5130451369
u8 *zBuf, /* Temporary buffer to use */
@@ -51306,40 +51371,54 @@
5130651371
int *pnCkpt /* OUT: Number of backfilled frames in WAL */
5130751372
){
5130851373
int rc; /* Return code */
5130951374
int isChanged = 0; /* True if a new wal-index header is loaded */
5131051375
int eMode2 = eMode; /* Mode to pass to walCheckpoint() */
51376
+ int (*xBusy2)(void*) = xBusy; /* Busy handler for eMode2 */
5131151377
5131251378
assert( pWal->ckptLock==0 );
5131351379
assert( pWal->writeLock==0 );
5131451380
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
+
5131551385
if( pWal->readOnly ) return SQLITE_READONLY;
5131651386
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. */
5131751390
rc = walLockExclusive(pWal, WAL_CKPT_LOCK, 1);
5131851391
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 );
5132251400
return rc;
5132351401
}
5132451402
pWal->ckptLock = 1;
5132551403
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.
5132951407
**
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.
5133451412
*/
5133551413
if( eMode!=SQLITE_CHECKPOINT_PASSIVE ){
5133651414
rc = walBusyLock(pWal, xBusy, pBusyArg, WAL_WRITE_LOCK, 1);
5133751415
if( rc==SQLITE_OK ){
5133851416
pWal->writeLock = 1;
5133951417
}else if( rc==SQLITE_BUSY ){
5134051418
eMode2 = SQLITE_CHECKPOINT_PASSIVE;
51419
+ xBusy2 = 0;
5134151420
rc = SQLITE_OK;
5134251421
}
5134351422
}
5134451423
5134551424
/* Read the wal-index header. */
@@ -51353,11 +51432,11 @@
5135351432
/* Copy data from the log to the database file. */
5135451433
if( rc==SQLITE_OK ){
5135551434
if( pWal->hdr.mxFrame && walPagesize(pWal)!=nBuf ){
5135651435
rc = SQLITE_CORRUPT_BKPT;
5135751436
}else{
51358
- rc = walCheckpoint(pWal, eMode2, xBusy, pBusyArg, sync_flags, zBuf);
51437
+ rc = walCheckpoint(pWal, eMode2, xBusy2, pBusyArg, sync_flags, zBuf);
5135951438
}
5136051439
5136151440
/* If no error occurred, set the output variables. */
5136251441
if( rc==SQLITE_OK || rc==SQLITE_BUSY ){
5136351442
if( pnLog ) *pnLog = (int)pWal->hdr.mxFrame;
@@ -53821,11 +53900,11 @@
5382153900
** to see if defragmentation is necessary.
5382253901
*/
5382353902
testcase( gap+2+nByte==top );
5382453903
if( gap+2+nByte>top ){
5382553904
defragment_page:
53826
- testcase( pPage->nCell==0 );
53905
+ assert( pPage->nCell>0 || CORRUPT_DB );
5382753906
rc = defragmentPage(pPage);
5382853907
if( rc ) return rc;
5382953908
top = get2byteNotZero(&data[hdr+5]);
5383053909
assert( gap+nByte<=top );
5383153910
}
@@ -58881,11 +58960,11 @@
5888158960
assert( sqlite3_mutex_held(pPage->pBt->mutex) );
5888258961
assert( sqlite3PagerIswriteable(pParent->pDbPage) );
5888358962
assert( pPage->nOverflow==1 );
5888458963
5888558964
/* 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;
5888758966
5888858967
/* Allocate a new page. This page will become the right-sibling of
5888958968
** pPage. Make the parent page writable, so that the new divider cell
5889058969
** may be inserted. If both these operations are successful, proceed.
5889158970
*/
@@ -59324,11 +59403,15 @@
5932459403
** pointer of the divider cell */
5932559404
memcpy(apCell[nCell], &pOld->aData[8], 4);
5932659405
}else{
5932759406
assert( leafCorrection==4 );
5932859407
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;
5933059413
szCell[nCell] = 4;
5933159414
}
5933259415
}
5933359416
nCell++;
5933459417
}
@@ -59559,11 +59642,15 @@
5955959642
** was either part of sibling page iOld (possibly an overflow cell),
5956059643
** or else the divider cell to the left of sibling page iOld. So,
5956159644
** if sibling page iOld had the same page number as pNew, and if
5956259645
** pCell really was a part of sibling page iOld (not a divider or
5956359646
** 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
+ ){
5956559652
if( !leafCorrection ){
5956659653
ptrmapPut(pBt, get4byte(pCell), PTRMAP_BTREE, pNew->pgno, &rc);
5956759654
}
5956859655
if( szCell[i]>pNew->minLocal ){
5956959656
ptrmapPutOvflPtr(pNew, pCell, &rc);
@@ -65699,11 +65786,11 @@
6569965786
for(n=0; n<nVar; n++){
6570065787
p->aVar[n].flags = MEM_Null;
6570165788
p->aVar[n].db = db;
6570265789
}
6570365790
}
65704
- if( p->azVar ){
65791
+ if( p->azVar && pParse->nzVar>0 ){
6570565792
p->nzVar = pParse->nzVar;
6570665793
memcpy(p->azVar, pParse->azVar, p->nzVar*sizeof(p->azVar[0]));
6570765794
memset(pParse->azVar, 0, pParse->nzVar*sizeof(pParse->azVar[0]));
6570865795
}
6570965796
if( p->aMem ){
@@ -75629,12 +75716,12 @@
7562975716
7563075717
#ifndef SQLITE_OMIT_WAL
7563175718
/* Opcode: Checkpoint P1 P2 P3 * *
7563275719
**
7563375720
** 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
7563675723
** SQLITE_BUSY or not, respectively. Write the number of pages in the
7563775724
** WAL after the checkpoint into mem[P3+1] and the number of pages
7563875725
** in the WAL that have been checkpointed after the checkpoint
7563975726
** completes into mem[P3+2]. However on an error, mem[P3+1] and
7564075727
** mem[P3+2] are initialized to -1.
@@ -75648,10 +75735,11 @@
7564875735
aRes[0] = 0;
7564975736
aRes[1] = aRes[2] = -1;
7565075737
assert( pOp->p2==SQLITE_CHECKPOINT_PASSIVE
7565175738
|| pOp->p2==SQLITE_CHECKPOINT_FULL
7565275739
|| pOp->p2==SQLITE_CHECKPOINT_RESTART
75740
+ || pOp->p2==SQLITE_CHECKPOINT_TRUNCATE
7565375741
);
7565475742
rc = sqlite3Checkpoint(db, pOp->p1, pOp->p2, &aRes[1], &aRes[2]);
7565575743
if( rc==SQLITE_BUSY ){
7565675744
rc = SQLITE_OK;
7565775745
aRes[0] = 1;
@@ -80411,10 +80499,14 @@
8041180499
}
8041280500
}
8041380501
if( pMatch ){
8041480502
pExpr->iTable = pMatch->iCursor;
8041580503
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
+ }
8041680508
pSchema = pExpr->pTab->pSchema;
8041780509
}
8041880510
} /* if( pSrcList ) */
8041980511
8042080512
#ifndef SQLITE_OMIT_TRIGGER
@@ -82968,11 +83060,12 @@
8296883060
case TK_FLOAT:
8296983061
case TK_BLOB:
8297083062
return 0;
8297183063
case TK_COLUMN:
8297283064
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);
8297483067
default:
8297583068
return 1;
8297683069
}
8297783070
}
8297883071
@@ -88351,11 +88444,11 @@
8835188444
tRowcnt avgEq = 0;
8835288445
tRowcnt nRow; /* Number of rows in index */
8835388446
i64 nSum100 = 0; /* Number of terms contributing to sumEq */
8835488447
i64 nDist100; /* Number of distinct values in index */
8835588448
88356
- if( pIdx->aiRowEst==0 || pIdx->aiRowEst[iCol+1]==0 ){
88449
+ if( !pIdx->aiRowEst || iCol>=pIdx->nKeyCol || pIdx->aiRowEst[iCol+1]==0 ){
8835788450
nRow = pFinal->anLt[iCol];
8835888451
nDist100 = (i64)100 * pFinal->anDLt[iCol];
8835988452
nSample--;
8836088453
}else{
8836188454
nRow = pIdx->aiRowEst[0];
@@ -103921,11 +104014,11 @@
103921104014
break;
103922104015
#endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
103923104016
103924104017
#ifndef SQLITE_OMIT_WAL
103925104018
/*
103926
- ** PRAGMA [database.]wal_checkpoint = passive|full|restart
104019
+ ** PRAGMA [database.]wal_checkpoint = passive|full|restart|truncate
103927104020
**
103928104021
** Checkpoint the database.
103929104022
*/
103930104023
case PragTyp_WAL_CHECKPOINT: {
103931104024
int iBt = (pId2->z?iDb:SQLITE_MAX_ATTACHED);
@@ -103933,10 +104026,12 @@
103933104026
if( zRight ){
103934104027
if( sqlite3StrICmp(zRight, "full")==0 ){
103935104028
eMode = SQLITE_CHECKPOINT_FULL;
103936104029
}else if( sqlite3StrICmp(zRight, "restart")==0 ){
103937104030
eMode = SQLITE_CHECKPOINT_RESTART;
104031
+ }else if( sqlite3StrICmp(zRight, "truncate")==0 ){
104032
+ eMode = SQLITE_CHECKPOINT_TRUNCATE;
103938104033
}
103939104034
}
103940104035
sqlite3VdbeSetNumCols(v, 3);
103941104036
pParse->nMem = 3;
103942104037
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "busy", SQLITE_STATIC);
@@ -109840,11 +109935,11 @@
109840109935
**
109841109936
** SELECT DISTINCT xyz FROM ... ORDER BY xyz
109842109937
**
109843109938
** is transformed to:
109844109939
**
109845
- ** SELECT xyz FROM ... GROUP BY xyz
109940
+ ** SELECT xyz FROM ... GROUP BY xyz ORDER BY xyz
109846109941
**
109847109942
** The second form is preferred as a single index (or temp-table) may be
109848109943
** used for both the ORDER BY and DISTINCT processing. As originally
109849109944
** written the query must use a temp-table for at least one of the ORDER
109850109945
** BY and DISTINCT, and an index or separate temp-table for the other.
@@ -109853,11 +109948,10 @@
109853109948
&& sqlite3ExprListCompare(sSort.pOrderBy, p->pEList, -1)==0
109854109949
){
109855109950
p->selFlags &= ~SF_Distinct;
109856109951
p->pGroupBy = sqlite3ExprListDup(db, p->pEList, 0);
109857109952
pGroupBy = p->pGroupBy;
109858
- sSort.pOrderBy = 0;
109859109953
/* Notice that even thought SF_Distinct has been cleared from p->selFlags,
109860109954
** the sDistinct.isTnct is still set. Hence, isTnct represents the
109861109955
** original setting of the SF_Distinct flag, not the current setting */
109862109956
assert( sDistinct.isTnct );
109863109957
}
@@ -114808,10 +114902,11 @@
114808114902
memcpy(pWC->a, pOld, sizeof(pWC->a[0])*pWC->nTerm);
114809114903
if( pOld!=pWC->aStatic ){
114810114904
sqlite3DbFree(db, pOld);
114811114905
}
114812114906
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));
114813114908
}
114814114909
pTerm = &pWC->a[idx = pWC->nTerm++];
114815114910
if( p && ExprHasProperty(p, EP_Unlikely) ){
114816114911
pTerm->truthProb = sqlite3LogEst(p->iTable) - 270;
114817114912
}else{
@@ -117533,11 +117628,11 @@
117533117628
WhereLevel *pLvl, /* Level to add scanstatus() entry for */
117534117629
int addrExplain /* Address of OP_Explain (or 0) */
117535117630
){
117536117631
const char *zObj = 0;
117537117632
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 ){
117539117634
zObj = pLoop->u.btree.pIndex->zName;
117540117635
}else{
117541117636
zObj = pSrclist->a[pLvl->iFrom].zName;
117542117637
}
117543117638
sqlite3VdbeScanStatus(
@@ -118177,14 +118272,13 @@
118177118272
int iTerm;
118178118273
for(iTerm=0; iTerm<pWC->nTerm; iTerm++){
118179118274
Expr *pExpr = pWC->a[iTerm].pExpr;
118180118275
if( &pWC->a[iTerm] == pTerm ) continue;
118181118276
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;
118185118278
if( (pWC->a[iTerm].eOperator & WO_ALL)==0 ) continue;
118279
+ testcase( pWC->a[iTerm].wtFlags & TERM_ORINFO );
118186118280
pExpr = sqlite3ExprDup(db, pExpr, 0);
118187118281
pAndExpr = sqlite3ExprAnd(db, pAndExpr, pExpr);
118188118282
}
118189118283
if( pAndExpr ){
118190118284
pAndExpr = sqlite3PExpr(pParse, TK_AND, 0, pAndExpr, 0);
@@ -127079,10 +127173,18 @@
127079127173
127080127174
/* Close all database connections */
127081127175
for(j=0; j<db->nDb; j++){
127082127176
struct Db *pDb = &db->aDb[j];
127083127177
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
+ }
127084127186
sqlite3BtreeClose(pDb->pBt);
127085127187
pDb->pBt = 0;
127086127188
if( j!=1 ){
127087127189
pDb->pSchema = 0;
127088127190
}
@@ -127983,14 +128085,17 @@
127983128085
127984128086
/* Initialize the output variables to -1 in case an error occurs. */
127985128087
if( pnLog ) *pnLog = -1;
127986128088
if( pnCkpt ) *pnCkpt = -1;
127987128089
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: */
127992128097
return SQLITE_MISUSE;
127993128098
}
127994128099
127995128100
sqlite3_mutex_enter(db->mutex);
127996128101
if( zDb && zDb[0] ){
@@ -128014,11 +128119,13 @@
128014128119
** Checkpoint database zDb. If zDb is NULL, or if the buffer zDb points
128015128120
** to contains a zero-length string, all attached databases are
128016128121
** checkpointed.
128017128122
*/
128018128123
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);
128020128127
}
128021128128
128022128129
#ifndef SQLITE_OMIT_WAL
128023128130
/*
128024128131
** Run a checkpoint on database iDb. This is a no-op if database iDb is
@@ -139164,11 +139271,11 @@
139164139271
** Return true if the m-value for z is 1 or more. In other words,
139165139272
** return true if z contains at least one vowel that is followed
139166139273
** by a consonant.
139167139274
**
139168139275
** 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.
139170139277
*/
139171139278
static int m_gt_0(const char *z){
139172139279
while( isVowel(z) ){ z++; }
139173139280
if( *z==0 ) return 0;
139174139281
while( isConsonant(z) ){ z++; }
139175139282
--- 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 @@
107107
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108108
** [sqlite_version()] and [sqlite_source_id()].
109109
*/
110110
#define SQLITE_VERSION "3.8.8"
111111
#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"
113113
114114
/*
115115
** CAPI3REF: Run-Time Library Version Numbers
116116
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117117
**
@@ -1219,11 +1219,11 @@
12191219
** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_SHARED
12201220
** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_EXCLUSIVE
12211221
** </ul>
12221222
**
12231223
** 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.
12251225
**
12261226
** The xShmLock method can transition between unlocked and SHARED or
12271227
** between unlocked and EXCLUSIVE. It cannot transition between SHARED
12281228
** and EXCLUSIVE.
12291229
*/
@@ -1522,12 +1522,12 @@
15221522
** tracks memory usage, for example. </dd>
15231523
**
15241524
** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt>
15251525
** <dd> ^The SQLITE_CONFIG_MEMSTATUS option takes single argument of type int,
15261526
** 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:
15291529
** <ul>
15301530
** <li> [sqlite3_memory_used()]
15311531
** <li> [sqlite3_memory_highwater()]
15321532
** <li> [sqlite3_soft_heap_limit64()]
15331533
** <li> [sqlite3_status()]
@@ -1564,11 +1564,12 @@
15641564
** that SQLite can use for the database page cache with the default page
15651565
** cache implementation.
15661566
** This configuration should not be used if an application-define page
15671567
** cache implementation is loaded using the [SQLITE_CONFIG_PCACHE2]
15681568
** 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
15701571
** memory, the size of each page buffer (sz), and the number of pages (N).
15711572
** The sz argument should be the size of the largest database page
15721573
** (a power of two between 512 and 32768) plus some extra bytes for each
15731574
** page header. ^The number of extra bytes needed by the page header
15741575
** can be determined using the [SQLITE_CONFIG_PCACHE_HDRSZ] option
@@ -1584,11 +1585,12 @@
15841585
** SQLite goes to [sqlite3_malloc()] for the additional storage space.</dd>
15851586
**
15861587
** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt>
15871588
** <dd> ^The SQLITE_CONFIG_HEAP option specifies a static memory buffer
15881589
** 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].
15901592
** ^The SQLITE_CONFIG_HEAP option is only available if SQLite is compiled
15911593
** with either [SQLITE_ENABLE_MEMSYS3] or [SQLITE_ENABLE_MEMSYS5] and returns
15921594
** [SQLITE_ERROR] if invoked otherwise.
15931595
** ^There are three arguments to SQLITE_CONFIG_HEAP:
15941596
** An 8-byte aligned pointer to the memory,
@@ -1604,13 +1606,13 @@
16041606
** for the minimum allocation size are 2**5 through 2**8.</dd>
16051607
**
16061608
** [[SQLITE_CONFIG_MUTEX]] <dt>SQLITE_CONFIG_MUTEX</dt>
16071609
** <dd> ^(The SQLITE_CONFIG_MUTEX option takes a single argument which is a
16081610
** 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
16121614
** [sqlite3_config()] returns. ^If SQLite is compiled with
16131615
** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
16141616
** the entire mutexing subsystem is omitted from the build and hence calls to
16151617
** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will
16161618
** return [SQLITE_ERROR].</dd>
@@ -1644,12 +1646,12 @@
16441646
** the interface to a custom page cache implementation.)^
16451647
** ^SQLite makes a copy of the [sqlite3_pcache_methods2] object.</dd>
16461648
**
16471649
** [[SQLITE_CONFIG_GETPCACHE2]] <dt>SQLITE_CONFIG_GETPCACHE2</dt>
16481650
** <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>
16511653
**
16521654
** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt>
16531655
** <dd> The SQLITE_CONFIG_LOG option is used to configure the SQLite
16541656
** global [error log].
16551657
** (^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a
@@ -1670,12 +1672,13 @@
16701672
** function must be threadsafe. </dd>
16711673
**
16721674
** [[SQLITE_CONFIG_URI]] <dt>SQLITE_CONFIG_URI
16731675
** <dd>^(The SQLITE_CONFIG_URI option takes a single argument of type int.
16741676
** 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
16771680
** specified as part of [ATTACH] commands are interpreted as URIs, regardless
16781681
** of whether or not the [SQLITE_OPEN_URI] flag is set when the database
16791682
** connection is opened. ^If it is globally disabled, filenames are
16801683
** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the
16811684
** database connection is opened. ^(By default, URI handling is globally
@@ -1733,21 +1736,21 @@
17331736
** changed to its compile-time default.
17341737
**
17351738
** [[SQLITE_CONFIG_WIN32_HEAPSIZE]]
17361739
** <dt>SQLITE_CONFIG_WIN32_HEAPSIZE
17371740
** <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
17401743
** that specifies the maximum size of the created heap.
17411744
** </dl>
17421745
**
17431746
** [[SQLITE_CONFIG_PCACHE_HDRSZ]]
17441747
** <dt>SQLITE_CONFIG_PCACHE_HDRSZ
17451748
** <dd>^The SQLITE_CONFIG_PCACHE_HDRSZ option takes a single parameter which
17461749
** 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,
17491752
** target platform, and SQLite version.
17501753
** </dl>
17511754
*/
17521755
#define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
17531756
#define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
@@ -2047,10 +2050,11 @@
20472050
SQLITE_API int sqlite3_complete(const char *sql);
20482051
SQLITE_API int sqlite3_complete16(const void *sql);
20492052
20502053
/*
20512054
** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors
2055
+** KEYWORDS: {busy-handler callback} {busy handler}
20522056
**
20532057
** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X
20542058
** that might be invoked with argument P whenever
20552059
** an attempt is made to access a database table associated with
20562060
** [database connection] D when another thread
@@ -2063,11 +2067,11 @@
20632067
** is not NULL, then the callback might be invoked with two arguments.
20642068
**
20652069
** ^The first argument to the busy handler is a copy of the void* pointer which
20662070
** is the third argument to sqlite3_busy_handler(). ^The second argument to
20672071
** 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
20692073
** busy callback returns 0, then no additional attempts are made to
20702074
** access the database and [SQLITE_BUSY] is returned
20712075
** to the application.
20722076
** ^If the callback returns non-zero, then another attempt
20732077
** is made to access the database and the cycle repeats.
@@ -4518,11 +4522,12 @@
45184522
** If these routines are called from within the different thread
45194523
** than the one containing the application-defined function that received
45204524
** the [sqlite3_context] pointer, the results are undefined.
45214525
*/
45224526
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*));
45244529
SQLITE_API void sqlite3_result_double(sqlite3_context*, double);
45254530
SQLITE_API void sqlite3_result_error(sqlite3_context*, const char*, int);
45264531
SQLITE_API void sqlite3_result_error16(sqlite3_context*, const void*, int);
45274532
SQLITE_API void sqlite3_result_error_toobig(sqlite3_context*);
45284533
SQLITE_API void sqlite3_result_error_nomem(sqlite3_context*);
@@ -7244,101 +7249,118 @@
72447249
SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
72457250
72467251
/*
72477252
** CAPI3REF: Checkpoint a database
72487253
**
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()].
72657269
*/
72667270
SQLITE_API int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb);
72677271
72687272
/*
72697273
** CAPI3REF: Checkpoint a database
72707274
**
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]:)^
72747279
**
72757280
** <dl>
72767281
** <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.
72827288
**
72837289
** <dt>SQLITE_CHECKPOINT_FULL<dd>
7284
-** This mode blocks (it invokes the
7290
+** ^This mode blocks (it invokes the
72857291
** [sqlite3_busy_handler|busy-handler callback]) until there is no
72867292
** 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.
72907296
**
72917297
** <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.
72997310
** </dl>
73007311
**
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.
73087321
**
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
73107323
** 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
73127325
** busy-handler configured, it will not be invoked in this case.
73137326
**
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
73207333
** the writer lock is obtained or while waiting for database readers, the
73217334
** checkpoint operation proceeds from that point in the same way as
73227335
** 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.
73247337
**
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
73287342
** an SQLITE_BUSY error is encountered when processing one or more of the
73297343
** 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
73317345
** 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
73337347
** (SQLITE_BUSY or otherwise) is encountered while processing the attached
73347348
** databases, SQLITE_OK is returned.
73357349
**
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
73387352
** zDb is not NULL (or a zero length string) and is not the name of any
73397353
** 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.
73407362
*/
73417363
SQLITE_API int sqlite3_wal_checkpoint_v2(
73427364
sqlite3 *db, /* Database handle */
73437365
const char *zDb, /* Name of attached database (or NULL) */
73447366
int eMode, /* SQLITE_CHECKPOINT_* value */
@@ -7345,20 +7367,22 @@
73457367
int *pnLog, /* OUT: Size of WAL log in frames */
73467368
int *pnCkpt /* OUT: Total number of frames checkpointed */
73477369
);
73487370
73497371
/*
7350
-** CAPI3REF: Checkpoint operation parameters
7372
+** CAPI3REF: Checkpoint Mode Values
7373
+** KEYWORDS: {checkpoint mode}
73517374
**
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.
73567379
*/
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 */
73607384
73617385
/*
73627386
** CAPI3REF: Virtual Table Interface Configuration
73637387
**
73647388
** This function may be called by either the [xConnect] or [xCreate] method
@@ -7453,16 +7477,16 @@
74537477
** [sqlite3_stmt_scanstatus(S,X,T,V)] interface. Each constant designates a
74547478
** different metric for sqlite3_stmt_scanstatus() to return.
74557479
**
74567480
** <dl>
74577481
** [[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>
74607484
**
74617485
** [[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>
74647488
**
74657489
** [[SQLITE_SCANSTAT_EST]] <dt>SQLITE_SCANSTAT_EST</dt>
74667490
** <dd>^The "double" variable pointed to by the T parameter will be set to the
74677491
** query planner's estimate for the average number of rows output from each
74687492
** iteration of the X-th loop. If the query planner's estimates was accurate,
@@ -7469,18 +7493,18 @@
74697493
** then this value will approximate the quotient NVISIT/NLOOP and the
74707494
** product of this value for all prior loops with the same SELECTID will
74717495
** be the NLOOP value for the current loop.
74727496
**
74737497
** [[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.
74777501
**
74787502
** [[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.
74827506
**
74837507
** [[SQLITE_SCANSTAT_SELECTID]] <dt>SQLITE_SCANSTAT_SELECT</dt>
74847508
** <dd>^The "int" variable pointed to by the T parameter will be set to the
74857509
** "select-id" for the X-th loop. The select-id identifies which query or
74867510
** subquery the loop is part of. The main query has a select-id of zero.
@@ -7499,12 +7523,12 @@
74997523
** CAPI3REF: Prepared Statement Scan Status
75007524
**
75017525
** Return status data for a single loop within query pStmt.
75027526
**
75037527
** 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.
75067530
** ^The requested measurement is written into a variable pointed to by
75077531
** the "pOut" parameter.
75087532
** Parameter "idx" identifies the specific loop to retrieve statistics for.
75097533
** Loops are numbered starting from zero. ^If idx is out of range - less than
75107534
** zero or greater than or equal to the total number of loops used to implement
75117535
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button