Fossil SCM

Merge into trunk from experimental the lookaside hit and miss stats associated with the --sqltrace option.

drh 2010-12-21 21:32 trunk merge
Commit b41d0f61204a36150fe0ce415bbfb20ac7219be4
+6
--- src/db.c
+++ src/db.c
@@ -945,10 +945,16 @@
945945
if( g.db==0 ) return;
946946
if( g.fSqlTrace ){
947947
int cur, hiwtr;
948948
sqlite3_db_status(g.db, SQLITE_DBSTATUS_LOOKASIDE_USED, &cur, &hiwtr, 0);
949949
fprintf(stderr, "-- LOOKASIDE_USED %10d %10d\n", cur, hiwtr);
950
+ sqlite3_db_status(g.db, SQLITE_DBSTATUS_LOOKASIDE_HIT, &cur, &hiwtr, 0);
951
+ fprintf(stderr, "-- LOOKASIDE_HIT %10d\n", hiwtr);
952
+ sqlite3_db_status(g.db, SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE, &cur,&hiwtr,0);
953
+ fprintf(stderr, "-- LOOKASIDE_MISS_SIZE %10d\n", hiwtr);
954
+ sqlite3_db_status(g.db, SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL, &cur,&hiwtr,0);
955
+ fprintf(stderr, "-- LOOKASIDE_MISS_FULL %10d\n", hiwtr);
950956
sqlite3_db_status(g.db, SQLITE_DBSTATUS_CACHE_USED, &cur, &hiwtr, 0);
951957
fprintf(stderr, "-- CACHE_USED %10d\n", cur);
952958
sqlite3_db_status(g.db, SQLITE_DBSTATUS_SCHEMA_USED, &cur, &hiwtr, 0);
953959
fprintf(stderr, "-- SCHEMA_USED %10d\n", cur);
954960
sqlite3_db_status(g.db, SQLITE_DBSTATUS_STMT_USED, &cur, &hiwtr, 0);
955961
--- src/db.c
+++ src/db.c
@@ -945,10 +945,16 @@
945 if( g.db==0 ) return;
946 if( g.fSqlTrace ){
947 int cur, hiwtr;
948 sqlite3_db_status(g.db, SQLITE_DBSTATUS_LOOKASIDE_USED, &cur, &hiwtr, 0);
949 fprintf(stderr, "-- LOOKASIDE_USED %10d %10d\n", cur, hiwtr);
 
 
 
 
 
 
950 sqlite3_db_status(g.db, SQLITE_DBSTATUS_CACHE_USED, &cur, &hiwtr, 0);
951 fprintf(stderr, "-- CACHE_USED %10d\n", cur);
952 sqlite3_db_status(g.db, SQLITE_DBSTATUS_SCHEMA_USED, &cur, &hiwtr, 0);
953 fprintf(stderr, "-- SCHEMA_USED %10d\n", cur);
954 sqlite3_db_status(g.db, SQLITE_DBSTATUS_STMT_USED, &cur, &hiwtr, 0);
955
--- src/db.c
+++ src/db.c
@@ -945,10 +945,16 @@
945 if( g.db==0 ) return;
946 if( g.fSqlTrace ){
947 int cur, hiwtr;
948 sqlite3_db_status(g.db, SQLITE_DBSTATUS_LOOKASIDE_USED, &cur, &hiwtr, 0);
949 fprintf(stderr, "-- LOOKASIDE_USED %10d %10d\n", cur, hiwtr);
950 sqlite3_db_status(g.db, SQLITE_DBSTATUS_LOOKASIDE_HIT, &cur, &hiwtr, 0);
951 fprintf(stderr, "-- LOOKASIDE_HIT %10d\n", hiwtr);
952 sqlite3_db_status(g.db, SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE, &cur,&hiwtr,0);
953 fprintf(stderr, "-- LOOKASIDE_MISS_SIZE %10d\n", hiwtr);
954 sqlite3_db_status(g.db, SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL, &cur,&hiwtr,0);
955 fprintf(stderr, "-- LOOKASIDE_MISS_FULL %10d\n", hiwtr);
956 sqlite3_db_status(g.db, SQLITE_DBSTATUS_CACHE_USED, &cur, &hiwtr, 0);
957 fprintf(stderr, "-- CACHE_USED %10d\n", cur);
958 sqlite3_db_status(g.db, SQLITE_DBSTATUS_SCHEMA_USED, &cur, &hiwtr, 0);
959 fprintf(stderr, "-- SCHEMA_USED %10d\n", cur);
960 sqlite3_db_status(g.db, SQLITE_DBSTATUS_STMT_USED, &cur, &hiwtr, 0);
961
+177 -78
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -650,11 +650,11 @@
650650
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
651651
** [sqlite_version()] and [sqlite_source_id()].
652652
*/
653653
#define SQLITE_VERSION "3.7.4"
654654
#define SQLITE_VERSION_NUMBER 3007004
655
-#define SQLITE_SOURCE_ID "2010-12-06 21:09:59 fabcb6b95e1d4059d1e6c6183f65846f6cbd5749"
655
+#define SQLITE_SOURCE_ID "2010-12-21 21:28:38 b0888047bb6d9ac55e29b9224df2ff650728bb78"
656656
657657
/*
658658
** CAPI3REF: Run-Time Library Version Numbers
659659
** KEYWORDS: sqlite3_version, sqlite3_sourceid
660660
**
@@ -1256,10 +1256,15 @@
12561256
** by the user. The fourth argument to [sqlite3_file_control()] should
12571257
** point to an integer (type int) containing the new chunk-size to use
12581258
** for the nominated database. Allocating database file space in large
12591259
** chunks (say 1MB at a time), may reduce file-system fragmentation and
12601260
** improve performance on some systems.
1261
+**
1262
+** The [SQLITE_FCNTL_FILE_POINTER] opcode is used to obtain a pointer
1263
+** to the [sqlite3_file] object associated with a particular database
1264
+** connection. See the [sqlite3_file_control()] documentation for
1265
+** additional information.
12611266
*/
12621267
#define SQLITE_FCNTL_LOCKSTATE 1
12631268
#define SQLITE_GET_LOCKPROXYFILE 2
12641269
#define SQLITE_SET_LOCKPROXYFILE 3
12651270
#define SQLITE_LAST_ERRNO 4
@@ -3191,18 +3196,35 @@
31913196
SQLITE_API const char *sqlite3_sql(sqlite3_stmt *pStmt);
31923197
31933198
/*
31943199
** CAPI3REF: Determine If An SQL Statement Writes The Database
31953200
**
3196
-** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if
3197
-** the [prepared statement] X is [SELECT] statement and false (zero) if
3198
-** X is an [INSERT], [UPDATE], [DELETE], CREATE, DROP, [ANALYZE],
3199
-** [ALTER], or [REINDEX] statement.
3200
-** If X is a NULL pointer or any other kind of statement, including but
3201
-** not limited to [ATTACH], [DETACH], [COMMIT], [ROLLBACK], [RELEASE],
3202
-** [SAVEPOINT], [PRAGMA], or [VACUUM] the result of sqlite3_stmt_readonly(X) is
3203
-** undefined.
3201
+** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if
3202
+** and only if the [prepared statement] X is makes no direct changes to
3203
+** the content of the database file.
3204
+**
3205
+** Note that [application-defined SQL functions] or
3206
+** [virtual tables] might change the database indirectly as a side effect.
3207
+** ^(For example, if an application defines a function "eval()" that
3208
+** calls [sqlite3_exec()], then the following SQL statement would
3209
+** change the database file through side-effects:
3210
+**
3211
+** <blockquote><pre>
3212
+** SELECT eval('DELETE FROM t1') FROM t2;
3213
+** </pre></blockquote>
3214
+**
3215
+** But because the [SELECT] statement does not change the database file
3216
+** directly, sqlite3_stmt_readonly() would still return true.)^
3217
+**
3218
+** ^Transaction control statements such as [BEGIN], [COMMIT], [ROLLBACK],
3219
+** [SAVEPOINT], and [RELEASE] cause sqlite3_stmt_readonly() to return true,
3220
+** since the statements themselves do not actually modify the database but
3221
+** rather they control the timing of when other statements modify the
3222
+** database. ^The [ATTACH] and [DETACH] statements also cause
3223
+** sqlite3_stmt_readonly() to return true since, while those statements
3224
+** change the configuration of a database connection, they do not make
3225
+** changes to the content of the database files on disk.
32043226
*/
32053227
SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
32063228
32073229
/*
32083230
** CAPI3REF: Dynamically Typed Value Object
@@ -5927,11 +5949,12 @@
59275949
** internal equivalents). Only the value returned in the
59285950
** *pHighwater parameter to [sqlite3_status()] is of interest.
59295951
** The value written into the *pCurrent parameter is undefined.</dd>)^
59305952
**
59315953
** ^(<dt>SQLITE_STATUS_MALLOC_COUNT</dt>
5932
-** <dd>This parameter records the number of separate memory allocations.</dd>)^
5954
+** <dd>This parameter records the number of separate memory allocations
5955
+** currently checked out.</dd>)^
59335956
**
59345957
** ^(<dt>SQLITE_STATUS_PAGECACHE_USED</dt>
59355958
** <dd>This parameter returns the number of pages used out of the
59365959
** [pagecache memory allocator] that was configured using
59375960
** [SQLITE_CONFIG_PAGECACHE]. The
@@ -6032,10 +6055,32 @@
60326055
**
60336056
** <dl>
60346057
** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
60356058
** <dd>This parameter returns the number of lookaside memory slots currently
60366059
** checked out.</dd>)^
6060
+**
6061
+** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_HIT</dt>
6062
+** <dd>This parameter returns the number malloc attempts that were
6063
+** satisfied using lookaside memory. Only the high-water value is meaningful;
6064
+** the current value is always zero.
6065
+** checked out.</dd>)^
6066
+**
6067
+** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE</dt>
6068
+** <dd>This parameter returns the number malloc attempts that might have
6069
+** been satisfied using lookaside memory but failed due to the amount of
6070
+** memory requested being larger than the lookaside slot size.
6071
+** Only the high-water value is meaningful;
6072
+** the current value is always zero.
6073
+** checked out.</dd>)^
6074
+**
6075
+** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL</dt>
6076
+** <dd>This parameter returns the number malloc attempts that might have
6077
+** been satisfied using lookaside memory but failed due to all lookaside
6078
+** memory already being in use.
6079
+** Only the high-water value is meaningful;
6080
+** the current value is always zero.
6081
+** checked out.</dd>)^
60376082
**
60386083
** ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt>
60396084
** <dd>This parameter returns the approximate number of of bytes of heap
60406085
** memory used by all pager caches associated with the database connection.)^
60416086
** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
@@ -6055,15 +6100,18 @@
60556100
** the database connection.)^
60566101
** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0.
60576102
** </dd>
60586103
** </dl>
60596104
*/
6060
-#define SQLITE_DBSTATUS_LOOKASIDE_USED 0
6061
-#define SQLITE_DBSTATUS_CACHE_USED 1
6062
-#define SQLITE_DBSTATUS_SCHEMA_USED 2
6063
-#define SQLITE_DBSTATUS_STMT_USED 3
6064
-#define SQLITE_DBSTATUS_MAX 3 /* Largest defined DBSTATUS */
6105
+#define SQLITE_DBSTATUS_LOOKASIDE_USED 0
6106
+#define SQLITE_DBSTATUS_CACHE_USED 1
6107
+#define SQLITE_DBSTATUS_SCHEMA_USED 2
6108
+#define SQLITE_DBSTATUS_STMT_USED 3
6109
+#define SQLITE_DBSTATUS_LOOKASIDE_HIT 4
6110
+#define SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE 5
6111
+#define SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL 6
6112
+#define SQLITE_DBSTATUS_MAX 6 /* Largest defined DBSTATUS */
60656113
60666114
60676115
/*
60686116
** CAPI3REF: Prepared Statement Status
60696117
**
@@ -6307,15 +6355,16 @@
63076355
** It is useful either for creating backups of databases or
63086356
** for copying in-memory databases to or from persistent files.
63096357
**
63106358
** See Also: [Using the SQLite Online Backup API]
63116359
**
6312
-** ^Exclusive access is required to the destination database for the
6313
-** duration of the operation. ^However the source database is only
6314
-** read-locked while it is actually being read; it is not locked
6315
-** continuously for the entire backup operation. ^Thus, the backup may be
6316
-** performed on a live source database without preventing other users from
6360
+** ^SQLite holds a write transaction open on the destination database file
6361
+** for the duration of the backup operation.
6362
+** ^The source database is read-locked only while it is being read;
6363
+** it is not locked continuously for the entire backup operation.
6364
+** ^Thus, the backup may be performed on a live source database without
6365
+** preventing other database connections from
63176366
** reading or writing to the source database while the backup is underway.
63186367
**
63196368
** ^(To perform a backup operation:
63206369
** <ol>
63216370
** <li><b>sqlite3_backup_init()</b> is called once to initialize the
@@ -6338,15 +6387,15 @@
63386387
** an [ATTACH] statement for an attached database.
63396388
** ^The S and M arguments passed to
63406389
** sqlite3_backup_init(D,N,S,M) identify the [database connection]
63416390
** and database name of the source database, respectively.
63426391
** ^The source and destination [database connections] (parameters S and D)
6343
-** must be different or else sqlite3_backup_init(D,N,S,M) will file with
6392
+** must be different or else sqlite3_backup_init(D,N,S,M) will fail with
63446393
** an error.
63456394
**
63466395
** ^If an error occurs within sqlite3_backup_init(D,N,S,M), then NULL is
6347
-** returned and an error code and error message are store3d in the
6396
+** returned and an error code and error message are stored in the
63486397
** destination [database connection] D.
63496398
** ^The error code and message for the failed call to sqlite3_backup_init()
63506399
** can be retrieved using the [sqlite3_errcode()], [sqlite3_errmsg()], and/or
63516400
** [sqlite3_errmsg16()] functions.
63526401
** ^A successful call to sqlite3_backup_init() returns a pointer to an
@@ -6359,11 +6408,11 @@
63596408
**
63606409
** ^Function sqlite3_backup_step(B,N) will copy up to N pages between
63616410
** the source and destination databases specified by [sqlite3_backup] object B.
63626411
** ^If N is negative, all remaining source pages are copied.
63636412
** ^If sqlite3_backup_step(B,N) successfully copies N pages and there
6364
-** are still more pages to be copied, then the function resturns [SQLITE_OK].
6413
+** are still more pages to be copied, then the function returns [SQLITE_OK].
63656414
** ^If sqlite3_backup_step(B,N) successfully finishes copying all pages
63666415
** from source to destination, then it returns [SQLITE_DONE].
63676416
** ^If an error occurs while running sqlite3_backup_step(B,N),
63686417
** then an [error code] is returned. ^As well as [SQLITE_OK] and
63696418
** [SQLITE_DONE], a call to sqlite3_backup_step() may return [SQLITE_READONLY],
@@ -6373,11 +6422,11 @@
63736422
** ^(The sqlite3_backup_step() might return [SQLITE_READONLY] if
63746423
** <ol>
63756424
** <li> the destination database was opened read-only, or
63766425
** <li> the destination database is using write-ahead-log journaling
63776426
** and the destination and source page sizes differ, or
6378
-** <li> The destination database is an in-memory database and the
6427
+** <li> the destination database is an in-memory database and the
63796428
** destination and source page sizes differ.
63806429
** </ol>)^
63816430
**
63826431
** ^If sqlite3_backup_step() cannot obtain a required file-system lock, then
63836432
** the [sqlite3_busy_handler | busy-handler function]
@@ -6704,11 +6753,12 @@
67046753
**
67056754
** ^The [wal_autocheckpoint pragma] can be used to invoke this interface
67066755
** from SQL.
67076756
**
67086757
** ^Every new [database connection] defaults to having the auto-checkpoint
6709
-** enabled with a threshold of 1000 pages. The use of this interface
6758
+** enabled with a threshold of 1000 or [SQLITE_DEFAULT_WAL_AUTOCHECKPOINT]
6759
+** pages. The use of this interface
67106760
** is only necessary if the default setting is found to be suboptimal
67116761
** for a particular application.
67126762
*/
67136763
SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
67146764
@@ -8875,10 +8925,11 @@
88758925
u16 sz; /* Size of each buffer in bytes */
88768926
u8 bEnabled; /* False to disable new lookaside allocations */
88778927
u8 bMalloced; /* True if pStart obtained from sqlite3_malloc() */
88788928
int nOut; /* Number of buffers currently checked out */
88798929
int mxOut; /* Highwater mark for nOut */
8930
+ int anStat[3]; /* 0: hits. 1: size misses. 2: full misses */
88808931
LookasideSlot *pFree; /* List of available buffers */
88818932
void *pStart; /* First byte of available memory space */
88828933
void *pEnd; /* First byte past end of available space */
88838934
};
88848935
struct LookasideSlot {
@@ -12506,10 +12557,26 @@
1250612557
if( resetFlag ){
1250712558
db->lookaside.mxOut = db->lookaside.nOut;
1250812559
}
1250912560
break;
1251012561
}
12562
+
12563
+ case SQLITE_DBSTATUS_LOOKASIDE_HIT:
12564
+ case SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE:
12565
+ case SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL: {
12566
+ testcase( op==SQLITE_DBSTATUS_LOOKASIDE_HIT );
12567
+ testcase( op==SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE );
12568
+ testcase( op==SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL );
12569
+ assert( (op-SQLITE_DBSTATUS_LOOKASIDE_HIT)>=0 );
12570
+ assert( (op-SQLITE_DBSTATUS_LOOKASIDE_HIT)<3 );
12571
+ *pCurrent = 0;
12572
+ *pHighwater = db->lookaside.anStat[op - SQLITE_DBSTATUS_LOOKASIDE_HIT];
12573
+ if( resetFlag ){
12574
+ db->lookaside.anStat[op - SQLITE_DBSTATUS_LOOKASIDE_HIT] = 0;
12575
+ }
12576
+ break;
12577
+ }
1251112578
1251212579
/*
1251312580
** Return an approximation for the amount of memory currently used
1251412581
** by all pagers associated with the given database connection. The
1251512582
** highwater mark is meaningless and is returned as zero.
@@ -18068,18 +18135,24 @@
1806818135
if( db ){
1806918136
LookasideSlot *pBuf;
1807018137
if( db->mallocFailed ){
1807118138
return 0;
1807218139
}
18073
- if( db->lookaside.bEnabled && n<=db->lookaside.sz
18074
- && (pBuf = db->lookaside.pFree)!=0 ){
18075
- db->lookaside.pFree = pBuf->pNext;
18076
- db->lookaside.nOut++;
18077
- if( db->lookaside.nOut>db->lookaside.mxOut ){
18078
- db->lookaside.mxOut = db->lookaside.nOut;
18079
- }
18080
- return (void*)pBuf;
18140
+ if( db->lookaside.bEnabled ){
18141
+ if( n>db->lookaside.sz ){
18142
+ db->lookaside.anStat[1]++;
18143
+ }else if( (pBuf = db->lookaside.pFree)==0 ){
18144
+ db->lookaside.anStat[2]++;
18145
+ }else{
18146
+ db->lookaside.pFree = pBuf->pNext;
18147
+ db->lookaside.nOut++;
18148
+ db->lookaside.anStat[0]++;
18149
+ if( db->lookaside.nOut>db->lookaside.mxOut ){
18150
+ db->lookaside.mxOut = db->lookaside.nOut;
18151
+ }
18152
+ return (void*)pBuf;
18153
+ }
1808118154
}
1808218155
}
1808318156
#else
1808418157
if( db && db->mallocFailed ){
1808518158
return 0;
@@ -28391,22 +28464,23 @@
2839128464
2839228465
/* get the host ID via gethostuuid(), pHostID must point to PROXY_HOSTIDLEN
2839328466
** bytes of writable memory.
2839428467
*/
2839528468
static int proxyGetHostID(unsigned char *pHostID, int *pError){
28396
- struct timespec timeout = {1, 0}; /* 1 sec timeout */
28397
-
2839828469
assert(PROXY_HOSTIDLEN == sizeof(uuid_t));
2839928470
memset(pHostID, 0, PROXY_HOSTIDLEN);
2840028471
#if defined(__MAX_OS_X_VERSION_MIN_REQUIRED)\
2840128472
&& __MAC_OS_X_VERSION_MIN_REQUIRED<1050
28402
- if( gethostuuid(pHostID, &timeout) ){
28403
- int err = errno;
28404
- if( pError ){
28405
- *pError = err;
28473
+ {
28474
+ static const struct timespec timeout = {1, 0}; /* 1 sec timeout */
28475
+ if( gethostuuid(pHostID, &timeout) ){
28476
+ int err = errno;
28477
+ if( pError ){
28478
+ *pError = err;
28479
+ }
28480
+ return SQLITE_IOERR;
2840628481
}
28407
- return SQLITE_IOERR;
2840828482
}
2840928483
#endif
2841028484
#ifdef SQLITE_TEST
2841128485
/* simulate multiple hosts by creating unique hostid file paths */
2841228486
if( sqlite3_hostid_num != 0){
@@ -41896,18 +41970,18 @@
4189641970
**
4189741971
** This functionality is used by the checkpoint code (see walCheckpoint()).
4189841972
*/
4189941973
struct WalIterator {
4190041974
int iPrior; /* Last result returned from the iterator */
41901
- int nSegment; /* Size of the aSegment[] array */
41975
+ int nSegment; /* Number of entries in aSegment[] */
4190241976
struct WalSegment {
4190341977
int iNext; /* Next slot in aIndex[] not yet returned */
4190441978
ht_slot *aIndex; /* i0, i1, i2... such that aPgno[iN] ascend */
4190541979
u32 *aPgno; /* Array of page numbers. */
41906
- int nEntry; /* Max size of aPgno[] and aIndex[] arrays */
41980
+ int nEntry; /* Nr. of entries in aPgno[] and aIndex[] */
4190741981
int iZero; /* Frame number associated with aPgno[0] */
41908
- } aSegment[1]; /* One for every 32KB page in the WAL */
41982
+ } aSegment[1]; /* One for every 32KB page in the wal-index */
4190941983
};
4191041984
4191141985
/*
4191241986
** Define the parameters of the hash tables in the wal-index file. There
4191341987
** is a hash-table following every HASHTABLE_NPAGE page numbers in the
@@ -42767,13 +42841,33 @@
4276742841
return (iRet==0xFFFFFFFF);
4276842842
}
4276942843
4277042844
/*
4277142845
** This function merges two sorted lists into a single sorted list.
42846
+**
42847
+** aLeft[] and aRight[] are arrays of indices. The sort key is
42848
+** aContent[aLeft[]] and aContent[aRight[]]. Upon entry, the following
42849
+** is guaranteed for all J<K:
42850
+**
42851
+** aContent[aLeft[J]] < aContent[aLeft[K]]
42852
+** aContent[aRight[J]] < aContent[aRight[K]]
42853
+**
42854
+** This routine overwrites aRight[] with a new (probably longer) sequence
42855
+** of indices such that the aRight[] contains every index that appears in
42856
+** either aLeft[] or the old aRight[] and such that the second condition
42857
+** above is still met.
42858
+**
42859
+** The aContent[aLeft[X]] values will be unique for all X. And the
42860
+** aContent[aRight[X]] values will be unique too. But there might be
42861
+** one or more combinations of X and Y such that
42862
+**
42863
+** aLeft[X]!=aRight[Y] && aContent[aLeft[X]] == aContent[aRight[Y]]
42864
+**
42865
+** When that happens, omit the aLeft[X] and use the aRight[Y] index.
4277242866
*/
4277342867
static void walMerge(
42774
- u32 *aContent, /* Pages in wal */
42868
+ const u32 *aContent, /* Pages in wal - keys for the sort */
4277542869
ht_slot *aLeft, /* IN: Left hand input list */
4277642870
int nLeft, /* IN: Elements in array *paLeft */
4277742871
ht_slot **paRight, /* IN/OUT: Right hand input list */
4277842872
int *pnRight, /* IN/OUT: Elements in *paRight */
4277942873
ht_slot *aTmp /* Temporary buffer */
@@ -42809,14 +42903,28 @@
4280942903
*pnRight = iOut;
4281042904
memcpy(aLeft, aTmp, sizeof(aTmp[0])*iOut);
4281142905
}
4281242906
4281342907
/*
42814
-** Sort the elements in list aList, removing any duplicates.
42908
+** Sort the elements in list aList using aContent[] as the sort key.
42909
+** Remove elements with duplicate keys, preferring to keep the
42910
+** larger aList[] values.
42911
+**
42912
+** The aList[] entries are indices into aContent[]. The values in
42913
+** aList[] are to be sorted so that for all J<K:
42914
+**
42915
+** aContent[aList[J]] < aContent[aList[K]]
42916
+**
42917
+** For any X and Y such that
42918
+**
42919
+** aContent[aList[X]] == aContent[aList[Y]]
42920
+**
42921
+** Keep the larger of the two values aList[X] and aList[Y] and discard
42922
+** the smaller.
4281542923
*/
4281642924
static void walMergesort(
42817
- u32 *aContent, /* Pages in wal */
42925
+ const u32 *aContent, /* Pages in wal */
4281842926
ht_slot *aBuffer, /* Buffer of at least *pnList items to use */
4281942927
ht_slot *aList, /* IN/OUT: List to sort */
4282042928
int *pnList /* IN/OUT: Number of elements in aList[] */
4282142929
){
4282242930
struct Sublist {
@@ -42877,10 +42985,11 @@
4287742985
}
4287842986
4287942987
/*
4288042988
** Construct a WalInterator object that can be used to loop over all
4288142989
** pages in the WAL in ascending order. The caller must hold the checkpoint
42990
+** lock.
4288242991
**
4288342992
** On success, make *pp point to the newly allocated WalInterator object
4288442993
** return SQLITE_OK. Otherwise, return an error code. If this routine
4288542994
** returns an error, the value of *pp is undefined.
4288642995
**
@@ -43011,11 +43120,12 @@
4301143120
volatile WalCkptInfo *pInfo; /* The checkpoint status information */
4301243121
4301343122
szPage = (pWal->hdr.szPage&0xfe00) + ((pWal->hdr.szPage&0x0001)<<16);
4301443123
testcase( szPage<=32768 );
4301543124
testcase( szPage>=65536 );
43016
- if( pWal->hdr.mxFrame==0 ) return SQLITE_OK;
43125
+ pInfo = walCkptInfo(pWal);
43126
+ if( pInfo->nBackfill>=pWal->hdr.mxFrame ) return SQLITE_OK;
4301743127
4301843128
/* Allocate the iterator */
4301943129
rc = walIteratorInit(pWal, &pIter);
4302043130
if( rc!=SQLITE_OK ){
4302143131
return rc;
@@ -43033,11 +43143,10 @@
4303343143
** overwrite database pages that are in use by active readers and thus
4303443144
** cannot be backfilled from the WAL.
4303543145
*/
4303643146
mxSafeFrame = pWal->hdr.mxFrame;
4303743147
mxPage = pWal->hdr.nPage;
43038
- pInfo = walCkptInfo(pWal);
4303943148
for(i=1; i<WAL_NREADER; i++){
4304043149
u32 y = pInfo->aReadMark[i];
4304143150
if( mxSafeFrame>=y ){
4304243151
assert( y<=pWal->hdr.mxFrame );
4304343152
rc = walLockExclusive(pWal, WAL_READ_LOCK(i), 1);
@@ -55556,11 +55665,11 @@
5555655665
u8 opcode = pOp->opcode;
5555755666
5555855667
pOp->opflags = sqlite3OpcodeProperty[opcode];
5555955668
if( opcode==OP_Function || opcode==OP_AggStep ){
5556055669
if( pOp->p5>nMaxArgs ) nMaxArgs = pOp->p5;
55561
- }else if( opcode==OP_Transaction && pOp->p2!=0 ){
55670
+ }else if( (opcode==OP_Transaction && pOp->p2!=0) || opcode==OP_Vacuum ){
5556255671
p->readOnly = 0;
5556355672
#ifndef SQLITE_OMIT_VIRTUALTABLE
5556455673
}else if( opcode==OP_VUpdate ){
5556555674
if( pOp->p2>nMaxArgs ) nMaxArgs = pOp->p2;
5556655675
}else if( opcode==OP_VFilter ){
@@ -80921,13 +81030,13 @@
8092181030
if( caseSensitive ){
8092281031
pInfo = (struct compareInfo*)&likeInfoAlt;
8092381032
}else{
8092481033
pInfo = (struct compareInfo*)&likeInfoNorm;
8092581034
}
80926
- sqlite3CreateFunc(db, "like", 2, SQLITE_ANY, pInfo, likeFunc, 0, 0, 0);
80927
- sqlite3CreateFunc(db, "like", 3, SQLITE_ANY, pInfo, likeFunc, 0, 0, 0);
80928
- sqlite3CreateFunc(db, "glob", 2, SQLITE_ANY,
81035
+ sqlite3CreateFunc(db, "like", 2, SQLITE_UTF8, pInfo, likeFunc, 0, 0, 0);
81036
+ sqlite3CreateFunc(db, "like", 3, SQLITE_UTF8, pInfo, likeFunc, 0, 0, 0);
81037
+ sqlite3CreateFunc(db, "glob", 2, SQLITE_UTF8,
8092981038
(struct compareInfo*)&globInfo, likeFunc, 0, 0, 0);
8093081039
setLikeOptFlag(db, "glob", SQLITE_FUNC_LIKE | SQLITE_FUNC_CASE);
8093181040
setLikeOptFlag(db, "like",
8093281041
caseSensitive ? (SQLITE_FUNC_LIKE | SQLITE_FUNC_CASE) : SQLITE_FUNC_LIKE);
8093381042
}
@@ -97673,14 +97782,13 @@
9767397782
Parse *pParse,
9767497783
Expr *pExpr,
9767597784
u8 aff,
9767697785
sqlite3_value **pp
9767797786
){
97678
- /* The evalConstExpr() function will have already converted any TK_VARIABLE
97679
- ** expression involved in an comparison into a TK_REGISTER. */
97680
- assert( pExpr->op!=TK_VARIABLE );
97681
- if( pExpr->op==TK_REGISTER && pExpr->op2==TK_VARIABLE ){
97787
+ if( pExpr->op==TK_VARIABLE
97788
+ || (pExpr->op==TK_REGISTER && pExpr->op2==TK_VARIABLE)
97789
+ ){
9768297790
int iVar = pExpr->iColumn;
9768397791
sqlite3VdbeSetVarmask(pParse->pVdbe, iVar); /* IMP: R-23257-02778 */
9768497792
*pp = sqlite3VdbeGetValue(pParse->pReprepare, iVar, aff);
9768597793
return SQLITE_OK;
9768697794
}
@@ -106470,10 +106578,13 @@
106470106578
| SQLITE_LoadExtension
106471106579
#endif
106472106580
#if SQLITE_DEFAULT_RECURSIVE_TRIGGERS
106473106581
| SQLITE_RecTriggers
106474106582
#endif
106583
+#if defined(SQLITE_DEFAULT_FOREIGN_KEYS) && SQLITE_DEFAULT_FOREIGN_KEYS
106584
+ | SQLITE_ForeignKeys
106585
+#endif
106475106586
;
106476106587
sqlite3HashInit(&db->aCollSeq);
106477106588
#ifndef SQLITE_OMIT_VIRTUALTABLE
106478106589
sqlite3HashInit(&db->aModule);
106479106590
#endif
@@ -111307,13 +111418,20 @@
111307111418
int iCol /* Column of requested pos-list */
111308111419
){
111309111420
assert( pExpr->isLoaded );
111310111421
if( pExpr->aDoclist ){
111311111422
char *pEnd = &pExpr->aDoclist[pExpr->nDoclist];
111312
- char *pCsr = pExpr->pCurrent;
111423
+ char *pCsr;
111313111424
111425
+ if( pExpr->pCurrent==0 ){
111426
+ pExpr->pCurrent = pExpr->aDoclist;
111427
+ pExpr->iCurrent = 0;
111428
+ pExpr->pCurrent += sqlite3Fts3GetVarint(pExpr->pCurrent,&pExpr->iCurrent);
111429
+ }
111430
+ pCsr = pExpr->pCurrent;
111314111431
assert( pCsr );
111432
+
111315111433
while( pCsr<pEnd ){
111316111434
if( pExpr->iCurrent<iDocid ){
111317111435
fts3PoslistCopy(0, &pCsr);
111318111436
if( pCsr<pEnd ){
111319111437
fts3GetDeltaVarint(&pCsr, &pExpr->iCurrent);
@@ -117513,11 +117631,11 @@
117513117631
/*
117514117632
** This is an fts3ExprIterate() callback used while loading the doclists
117515117633
** for each phrase into Fts3Expr.aDoclist[]/nDoclist. See also
117516117634
** fts3ExprLoadDoclists().
117517117635
*/
117518
-static int fts3ExprLoadDoclistsCb1(Fts3Expr *pExpr, int iPhrase, void *ctx){
117636
+static int fts3ExprLoadDoclistsCb(Fts3Expr *pExpr, int iPhrase, void *ctx){
117519117637
int rc = SQLITE_OK;
117520117638
LoadDoclistCtx *p = (LoadDoclistCtx *)ctx;
117521117639
117522117640
UNUSED_PARAMETER(iPhrase);
117523117641
@@ -117533,26 +117651,10 @@
117533117651
}
117534117652
117535117653
return rc;
117536117654
}
117537117655
117538
-/*
117539
-** This is an fts3ExprIterate() callback used while loading the doclists
117540
-** for each phrase into Fts3Expr.aDoclist[]/nDoclist. See also
117541
-** fts3ExprLoadDoclists().
117542
-*/
117543
-static int fts3ExprLoadDoclistsCb2(Fts3Expr *pExpr, int iPhrase, void *ctx){
117544
- UNUSED_PARAMETER(iPhrase);
117545
- UNUSED_PARAMETER(ctx);
117546
- if( pExpr->aDoclist ){
117547
- pExpr->pCurrent = pExpr->aDoclist;
117548
- pExpr->iCurrent = 0;
117549
- pExpr->pCurrent += sqlite3Fts3GetVarint(pExpr->pCurrent, &pExpr->iCurrent);
117550
- }
117551
- return SQLITE_OK;
117552
-}
117553
-
117554117656
/*
117555117657
** Load the doclists for each phrase in the query associated with FTS3 cursor
117556117658
** pCsr.
117557117659
**
117558117660
** If pnPhrase is not NULL, then *pnPhrase is set to the number of matchable
@@ -117567,14 +117669,11 @@
117567117669
int *pnToken /* OUT: Number of tokens in query */
117568117670
){
117569117671
int rc; /* Return Code */
117570117672
LoadDoclistCtx sCtx = {0,0,0}; /* Context for fts3ExprIterate() */
117571117673
sCtx.pCsr = pCsr;
117572
- rc = fts3ExprIterate(pCsr->pExpr, fts3ExprLoadDoclistsCb1, (void *)&sCtx);
117573
- if( rc==SQLITE_OK ){
117574
- (void)fts3ExprIterate(pCsr->pExpr, fts3ExprLoadDoclistsCb2, 0);
117575
- }
117674
+ rc = fts3ExprIterate(pCsr->pExpr, fts3ExprLoadDoclistsCb, (void *)&sCtx);
117576117675
if( pnPhrase ) *pnPhrase = sCtx.nPhrase;
117577117676
if( pnToken ) *pnToken = sCtx.nToken;
117578117677
return rc;
117579117678
}
117580117679
117581117680
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -650,11 +650,11 @@
650 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
651 ** [sqlite_version()] and [sqlite_source_id()].
652 */
653 #define SQLITE_VERSION "3.7.4"
654 #define SQLITE_VERSION_NUMBER 3007004
655 #define SQLITE_SOURCE_ID "2010-12-06 21:09:59 fabcb6b95e1d4059d1e6c6183f65846f6cbd5749"
656
657 /*
658 ** CAPI3REF: Run-Time Library Version Numbers
659 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
660 **
@@ -1256,10 +1256,15 @@
1256 ** by the user. The fourth argument to [sqlite3_file_control()] should
1257 ** point to an integer (type int) containing the new chunk-size to use
1258 ** for the nominated database. Allocating database file space in large
1259 ** chunks (say 1MB at a time), may reduce file-system fragmentation and
1260 ** improve performance on some systems.
 
 
 
 
 
1261 */
1262 #define SQLITE_FCNTL_LOCKSTATE 1
1263 #define SQLITE_GET_LOCKPROXYFILE 2
1264 #define SQLITE_SET_LOCKPROXYFILE 3
1265 #define SQLITE_LAST_ERRNO 4
@@ -3191,18 +3196,35 @@
3191 SQLITE_API const char *sqlite3_sql(sqlite3_stmt *pStmt);
3192
3193 /*
3194 ** CAPI3REF: Determine If An SQL Statement Writes The Database
3195 **
3196 ** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if
3197 ** the [prepared statement] X is [SELECT] statement and false (zero) if
3198 ** X is an [INSERT], [UPDATE], [DELETE], CREATE, DROP, [ANALYZE],
3199 ** [ALTER], or [REINDEX] statement.
3200 ** If X is a NULL pointer or any other kind of statement, including but
3201 ** not limited to [ATTACH], [DETACH], [COMMIT], [ROLLBACK], [RELEASE],
3202 ** [SAVEPOINT], [PRAGMA], or [VACUUM] the result of sqlite3_stmt_readonly(X) is
3203 ** undefined.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3204 */
3205 SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
3206
3207 /*
3208 ** CAPI3REF: Dynamically Typed Value Object
@@ -5927,11 +5949,12 @@
5927 ** internal equivalents). Only the value returned in the
5928 ** *pHighwater parameter to [sqlite3_status()] is of interest.
5929 ** The value written into the *pCurrent parameter is undefined.</dd>)^
5930 **
5931 ** ^(<dt>SQLITE_STATUS_MALLOC_COUNT</dt>
5932 ** <dd>This parameter records the number of separate memory allocations.</dd>)^
 
5933 **
5934 ** ^(<dt>SQLITE_STATUS_PAGECACHE_USED</dt>
5935 ** <dd>This parameter returns the number of pages used out of the
5936 ** [pagecache memory allocator] that was configured using
5937 ** [SQLITE_CONFIG_PAGECACHE]. The
@@ -6032,10 +6055,32 @@
6032 **
6033 ** <dl>
6034 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
6035 ** <dd>This parameter returns the number of lookaside memory slots currently
6036 ** checked out.</dd>)^
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6037 **
6038 ** ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt>
6039 ** <dd>This parameter returns the approximate number of of bytes of heap
6040 ** memory used by all pager caches associated with the database connection.)^
6041 ** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
@@ -6055,15 +6100,18 @@
6055 ** the database connection.)^
6056 ** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0.
6057 ** </dd>
6058 ** </dl>
6059 */
6060 #define SQLITE_DBSTATUS_LOOKASIDE_USED 0
6061 #define SQLITE_DBSTATUS_CACHE_USED 1
6062 #define SQLITE_DBSTATUS_SCHEMA_USED 2
6063 #define SQLITE_DBSTATUS_STMT_USED 3
6064 #define SQLITE_DBSTATUS_MAX 3 /* Largest defined DBSTATUS */
 
 
 
6065
6066
6067 /*
6068 ** CAPI3REF: Prepared Statement Status
6069 **
@@ -6307,15 +6355,16 @@
6307 ** It is useful either for creating backups of databases or
6308 ** for copying in-memory databases to or from persistent files.
6309 **
6310 ** See Also: [Using the SQLite Online Backup API]
6311 **
6312 ** ^Exclusive access is required to the destination database for the
6313 ** duration of the operation. ^However the source database is only
6314 ** read-locked while it is actually being read; it is not locked
6315 ** continuously for the entire backup operation. ^Thus, the backup may be
6316 ** performed on a live source database without preventing other users from
 
6317 ** reading or writing to the source database while the backup is underway.
6318 **
6319 ** ^(To perform a backup operation:
6320 ** <ol>
6321 ** <li><b>sqlite3_backup_init()</b> is called once to initialize the
@@ -6338,15 +6387,15 @@
6338 ** an [ATTACH] statement for an attached database.
6339 ** ^The S and M arguments passed to
6340 ** sqlite3_backup_init(D,N,S,M) identify the [database connection]
6341 ** and database name of the source database, respectively.
6342 ** ^The source and destination [database connections] (parameters S and D)
6343 ** must be different or else sqlite3_backup_init(D,N,S,M) will file with
6344 ** an error.
6345 **
6346 ** ^If an error occurs within sqlite3_backup_init(D,N,S,M), then NULL is
6347 ** returned and an error code and error message are store3d in the
6348 ** destination [database connection] D.
6349 ** ^The error code and message for the failed call to sqlite3_backup_init()
6350 ** can be retrieved using the [sqlite3_errcode()], [sqlite3_errmsg()], and/or
6351 ** [sqlite3_errmsg16()] functions.
6352 ** ^A successful call to sqlite3_backup_init() returns a pointer to an
@@ -6359,11 +6408,11 @@
6359 **
6360 ** ^Function sqlite3_backup_step(B,N) will copy up to N pages between
6361 ** the source and destination databases specified by [sqlite3_backup] object B.
6362 ** ^If N is negative, all remaining source pages are copied.
6363 ** ^If sqlite3_backup_step(B,N) successfully copies N pages and there
6364 ** are still more pages to be copied, then the function resturns [SQLITE_OK].
6365 ** ^If sqlite3_backup_step(B,N) successfully finishes copying all pages
6366 ** from source to destination, then it returns [SQLITE_DONE].
6367 ** ^If an error occurs while running sqlite3_backup_step(B,N),
6368 ** then an [error code] is returned. ^As well as [SQLITE_OK] and
6369 ** [SQLITE_DONE], a call to sqlite3_backup_step() may return [SQLITE_READONLY],
@@ -6373,11 +6422,11 @@
6373 ** ^(The sqlite3_backup_step() might return [SQLITE_READONLY] if
6374 ** <ol>
6375 ** <li> the destination database was opened read-only, or
6376 ** <li> the destination database is using write-ahead-log journaling
6377 ** and the destination and source page sizes differ, or
6378 ** <li> The destination database is an in-memory database and the
6379 ** destination and source page sizes differ.
6380 ** </ol>)^
6381 **
6382 ** ^If sqlite3_backup_step() cannot obtain a required file-system lock, then
6383 ** the [sqlite3_busy_handler | busy-handler function]
@@ -6704,11 +6753,12 @@
6704 **
6705 ** ^The [wal_autocheckpoint pragma] can be used to invoke this interface
6706 ** from SQL.
6707 **
6708 ** ^Every new [database connection] defaults to having the auto-checkpoint
6709 ** enabled with a threshold of 1000 pages. The use of this interface
 
6710 ** is only necessary if the default setting is found to be suboptimal
6711 ** for a particular application.
6712 */
6713 SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
6714
@@ -8875,10 +8925,11 @@
8875 u16 sz; /* Size of each buffer in bytes */
8876 u8 bEnabled; /* False to disable new lookaside allocations */
8877 u8 bMalloced; /* True if pStart obtained from sqlite3_malloc() */
8878 int nOut; /* Number of buffers currently checked out */
8879 int mxOut; /* Highwater mark for nOut */
 
8880 LookasideSlot *pFree; /* List of available buffers */
8881 void *pStart; /* First byte of available memory space */
8882 void *pEnd; /* First byte past end of available space */
8883 };
8884 struct LookasideSlot {
@@ -12506,10 +12557,26 @@
12506 if( resetFlag ){
12507 db->lookaside.mxOut = db->lookaside.nOut;
12508 }
12509 break;
12510 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12511
12512 /*
12513 ** Return an approximation for the amount of memory currently used
12514 ** by all pagers associated with the given database connection. The
12515 ** highwater mark is meaningless and is returned as zero.
@@ -18068,18 +18135,24 @@
18068 if( db ){
18069 LookasideSlot *pBuf;
18070 if( db->mallocFailed ){
18071 return 0;
18072 }
18073 if( db->lookaside.bEnabled && n<=db->lookaside.sz
18074 && (pBuf = db->lookaside.pFree)!=0 ){
18075 db->lookaside.pFree = pBuf->pNext;
18076 db->lookaside.nOut++;
18077 if( db->lookaside.nOut>db->lookaside.mxOut ){
18078 db->lookaside.mxOut = db->lookaside.nOut;
18079 }
18080 return (void*)pBuf;
 
 
 
 
 
 
18081 }
18082 }
18083 #else
18084 if( db && db->mallocFailed ){
18085 return 0;
@@ -28391,22 +28464,23 @@
28391
28392 /* get the host ID via gethostuuid(), pHostID must point to PROXY_HOSTIDLEN
28393 ** bytes of writable memory.
28394 */
28395 static int proxyGetHostID(unsigned char *pHostID, int *pError){
28396 struct timespec timeout = {1, 0}; /* 1 sec timeout */
28397
28398 assert(PROXY_HOSTIDLEN == sizeof(uuid_t));
28399 memset(pHostID, 0, PROXY_HOSTIDLEN);
28400 #if defined(__MAX_OS_X_VERSION_MIN_REQUIRED)\
28401 && __MAC_OS_X_VERSION_MIN_REQUIRED<1050
28402 if( gethostuuid(pHostID, &timeout) ){
28403 int err = errno;
28404 if( pError ){
28405 *pError = err;
 
 
 
 
28406 }
28407 return SQLITE_IOERR;
28408 }
28409 #endif
28410 #ifdef SQLITE_TEST
28411 /* simulate multiple hosts by creating unique hostid file paths */
28412 if( sqlite3_hostid_num != 0){
@@ -41896,18 +41970,18 @@
41896 **
41897 ** This functionality is used by the checkpoint code (see walCheckpoint()).
41898 */
41899 struct WalIterator {
41900 int iPrior; /* Last result returned from the iterator */
41901 int nSegment; /* Size of the aSegment[] array */
41902 struct WalSegment {
41903 int iNext; /* Next slot in aIndex[] not yet returned */
41904 ht_slot *aIndex; /* i0, i1, i2... such that aPgno[iN] ascend */
41905 u32 *aPgno; /* Array of page numbers. */
41906 int nEntry; /* Max size of aPgno[] and aIndex[] arrays */
41907 int iZero; /* Frame number associated with aPgno[0] */
41908 } aSegment[1]; /* One for every 32KB page in the WAL */
41909 };
41910
41911 /*
41912 ** Define the parameters of the hash tables in the wal-index file. There
41913 ** is a hash-table following every HASHTABLE_NPAGE page numbers in the
@@ -42767,13 +42841,33 @@
42767 return (iRet==0xFFFFFFFF);
42768 }
42769
42770 /*
42771 ** This function merges two sorted lists into a single sorted list.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42772 */
42773 static void walMerge(
42774 u32 *aContent, /* Pages in wal */
42775 ht_slot *aLeft, /* IN: Left hand input list */
42776 int nLeft, /* IN: Elements in array *paLeft */
42777 ht_slot **paRight, /* IN/OUT: Right hand input list */
42778 int *pnRight, /* IN/OUT: Elements in *paRight */
42779 ht_slot *aTmp /* Temporary buffer */
@@ -42809,14 +42903,28 @@
42809 *pnRight = iOut;
42810 memcpy(aLeft, aTmp, sizeof(aTmp[0])*iOut);
42811 }
42812
42813 /*
42814 ** Sort the elements in list aList, removing any duplicates.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42815 */
42816 static void walMergesort(
42817 u32 *aContent, /* Pages in wal */
42818 ht_slot *aBuffer, /* Buffer of at least *pnList items to use */
42819 ht_slot *aList, /* IN/OUT: List to sort */
42820 int *pnList /* IN/OUT: Number of elements in aList[] */
42821 ){
42822 struct Sublist {
@@ -42877,10 +42985,11 @@
42877 }
42878
42879 /*
42880 ** Construct a WalInterator object that can be used to loop over all
42881 ** pages in the WAL in ascending order. The caller must hold the checkpoint
 
42882 **
42883 ** On success, make *pp point to the newly allocated WalInterator object
42884 ** return SQLITE_OK. Otherwise, return an error code. If this routine
42885 ** returns an error, the value of *pp is undefined.
42886 **
@@ -43011,11 +43120,12 @@
43011 volatile WalCkptInfo *pInfo; /* The checkpoint status information */
43012
43013 szPage = (pWal->hdr.szPage&0xfe00) + ((pWal->hdr.szPage&0x0001)<<16);
43014 testcase( szPage<=32768 );
43015 testcase( szPage>=65536 );
43016 if( pWal->hdr.mxFrame==0 ) return SQLITE_OK;
 
43017
43018 /* Allocate the iterator */
43019 rc = walIteratorInit(pWal, &pIter);
43020 if( rc!=SQLITE_OK ){
43021 return rc;
@@ -43033,11 +43143,10 @@
43033 ** overwrite database pages that are in use by active readers and thus
43034 ** cannot be backfilled from the WAL.
43035 */
43036 mxSafeFrame = pWal->hdr.mxFrame;
43037 mxPage = pWal->hdr.nPage;
43038 pInfo = walCkptInfo(pWal);
43039 for(i=1; i<WAL_NREADER; i++){
43040 u32 y = pInfo->aReadMark[i];
43041 if( mxSafeFrame>=y ){
43042 assert( y<=pWal->hdr.mxFrame );
43043 rc = walLockExclusive(pWal, WAL_READ_LOCK(i), 1);
@@ -55556,11 +55665,11 @@
55556 u8 opcode = pOp->opcode;
55557
55558 pOp->opflags = sqlite3OpcodeProperty[opcode];
55559 if( opcode==OP_Function || opcode==OP_AggStep ){
55560 if( pOp->p5>nMaxArgs ) nMaxArgs = pOp->p5;
55561 }else if( opcode==OP_Transaction && pOp->p2!=0 ){
55562 p->readOnly = 0;
55563 #ifndef SQLITE_OMIT_VIRTUALTABLE
55564 }else if( opcode==OP_VUpdate ){
55565 if( pOp->p2>nMaxArgs ) nMaxArgs = pOp->p2;
55566 }else if( opcode==OP_VFilter ){
@@ -80921,13 +81030,13 @@
80921 if( caseSensitive ){
80922 pInfo = (struct compareInfo*)&likeInfoAlt;
80923 }else{
80924 pInfo = (struct compareInfo*)&likeInfoNorm;
80925 }
80926 sqlite3CreateFunc(db, "like", 2, SQLITE_ANY, pInfo, likeFunc, 0, 0, 0);
80927 sqlite3CreateFunc(db, "like", 3, SQLITE_ANY, pInfo, likeFunc, 0, 0, 0);
80928 sqlite3CreateFunc(db, "glob", 2, SQLITE_ANY,
80929 (struct compareInfo*)&globInfo, likeFunc, 0, 0, 0);
80930 setLikeOptFlag(db, "glob", SQLITE_FUNC_LIKE | SQLITE_FUNC_CASE);
80931 setLikeOptFlag(db, "like",
80932 caseSensitive ? (SQLITE_FUNC_LIKE | SQLITE_FUNC_CASE) : SQLITE_FUNC_LIKE);
80933 }
@@ -97673,14 +97782,13 @@
97673 Parse *pParse,
97674 Expr *pExpr,
97675 u8 aff,
97676 sqlite3_value **pp
97677 ){
97678 /* The evalConstExpr() function will have already converted any TK_VARIABLE
97679 ** expression involved in an comparison into a TK_REGISTER. */
97680 assert( pExpr->op!=TK_VARIABLE );
97681 if( pExpr->op==TK_REGISTER && pExpr->op2==TK_VARIABLE ){
97682 int iVar = pExpr->iColumn;
97683 sqlite3VdbeSetVarmask(pParse->pVdbe, iVar); /* IMP: R-23257-02778 */
97684 *pp = sqlite3VdbeGetValue(pParse->pReprepare, iVar, aff);
97685 return SQLITE_OK;
97686 }
@@ -106470,10 +106578,13 @@
106470 | SQLITE_LoadExtension
106471 #endif
106472 #if SQLITE_DEFAULT_RECURSIVE_TRIGGERS
106473 | SQLITE_RecTriggers
106474 #endif
 
 
 
106475 ;
106476 sqlite3HashInit(&db->aCollSeq);
106477 #ifndef SQLITE_OMIT_VIRTUALTABLE
106478 sqlite3HashInit(&db->aModule);
106479 #endif
@@ -111307,13 +111418,20 @@
111307 int iCol /* Column of requested pos-list */
111308 ){
111309 assert( pExpr->isLoaded );
111310 if( pExpr->aDoclist ){
111311 char *pEnd = &pExpr->aDoclist[pExpr->nDoclist];
111312 char *pCsr = pExpr->pCurrent;
111313
 
 
 
 
 
 
111314 assert( pCsr );
 
111315 while( pCsr<pEnd ){
111316 if( pExpr->iCurrent<iDocid ){
111317 fts3PoslistCopy(0, &pCsr);
111318 if( pCsr<pEnd ){
111319 fts3GetDeltaVarint(&pCsr, &pExpr->iCurrent);
@@ -117513,11 +117631,11 @@
117513 /*
117514 ** This is an fts3ExprIterate() callback used while loading the doclists
117515 ** for each phrase into Fts3Expr.aDoclist[]/nDoclist. See also
117516 ** fts3ExprLoadDoclists().
117517 */
117518 static int fts3ExprLoadDoclistsCb1(Fts3Expr *pExpr, int iPhrase, void *ctx){
117519 int rc = SQLITE_OK;
117520 LoadDoclistCtx *p = (LoadDoclistCtx *)ctx;
117521
117522 UNUSED_PARAMETER(iPhrase);
117523
@@ -117533,26 +117651,10 @@
117533 }
117534
117535 return rc;
117536 }
117537
117538 /*
117539 ** This is an fts3ExprIterate() callback used while loading the doclists
117540 ** for each phrase into Fts3Expr.aDoclist[]/nDoclist. See also
117541 ** fts3ExprLoadDoclists().
117542 */
117543 static int fts3ExprLoadDoclistsCb2(Fts3Expr *pExpr, int iPhrase, void *ctx){
117544 UNUSED_PARAMETER(iPhrase);
117545 UNUSED_PARAMETER(ctx);
117546 if( pExpr->aDoclist ){
117547 pExpr->pCurrent = pExpr->aDoclist;
117548 pExpr->iCurrent = 0;
117549 pExpr->pCurrent += sqlite3Fts3GetVarint(pExpr->pCurrent, &pExpr->iCurrent);
117550 }
117551 return SQLITE_OK;
117552 }
117553
117554 /*
117555 ** Load the doclists for each phrase in the query associated with FTS3 cursor
117556 ** pCsr.
117557 **
117558 ** If pnPhrase is not NULL, then *pnPhrase is set to the number of matchable
@@ -117567,14 +117669,11 @@
117567 int *pnToken /* OUT: Number of tokens in query */
117568 ){
117569 int rc; /* Return Code */
117570 LoadDoclistCtx sCtx = {0,0,0}; /* Context for fts3ExprIterate() */
117571 sCtx.pCsr = pCsr;
117572 rc = fts3ExprIterate(pCsr->pExpr, fts3ExprLoadDoclistsCb1, (void *)&sCtx);
117573 if( rc==SQLITE_OK ){
117574 (void)fts3ExprIterate(pCsr->pExpr, fts3ExprLoadDoclistsCb2, 0);
117575 }
117576 if( pnPhrase ) *pnPhrase = sCtx.nPhrase;
117577 if( pnToken ) *pnToken = sCtx.nToken;
117578 return rc;
117579 }
117580
117581
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -650,11 +650,11 @@
650 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
651 ** [sqlite_version()] and [sqlite_source_id()].
652 */
653 #define SQLITE_VERSION "3.7.4"
654 #define SQLITE_VERSION_NUMBER 3007004
655 #define SQLITE_SOURCE_ID "2010-12-21 21:28:38 b0888047bb6d9ac55e29b9224df2ff650728bb78"
656
657 /*
658 ** CAPI3REF: Run-Time Library Version Numbers
659 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
660 **
@@ -1256,10 +1256,15 @@
1256 ** by the user. The fourth argument to [sqlite3_file_control()] should
1257 ** point to an integer (type int) containing the new chunk-size to use
1258 ** for the nominated database. Allocating database file space in large
1259 ** chunks (say 1MB at a time), may reduce file-system fragmentation and
1260 ** improve performance on some systems.
1261 **
1262 ** The [SQLITE_FCNTL_FILE_POINTER] opcode is used to obtain a pointer
1263 ** to the [sqlite3_file] object associated with a particular database
1264 ** connection. See the [sqlite3_file_control()] documentation for
1265 ** additional information.
1266 */
1267 #define SQLITE_FCNTL_LOCKSTATE 1
1268 #define SQLITE_GET_LOCKPROXYFILE 2
1269 #define SQLITE_SET_LOCKPROXYFILE 3
1270 #define SQLITE_LAST_ERRNO 4
@@ -3191,18 +3196,35 @@
3196 SQLITE_API const char *sqlite3_sql(sqlite3_stmt *pStmt);
3197
3198 /*
3199 ** CAPI3REF: Determine If An SQL Statement Writes The Database
3200 **
3201 ** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if
3202 ** and only if the [prepared statement] X is makes no direct changes to
3203 ** the content of the database file.
3204 **
3205 ** Note that [application-defined SQL functions] or
3206 ** [virtual tables] might change the database indirectly as a side effect.
3207 ** ^(For example, if an application defines a function "eval()" that
3208 ** calls [sqlite3_exec()], then the following SQL statement would
3209 ** change the database file through side-effects:
3210 **
3211 ** <blockquote><pre>
3212 ** SELECT eval('DELETE FROM t1') FROM t2;
3213 ** </pre></blockquote>
3214 **
3215 ** But because the [SELECT] statement does not change the database file
3216 ** directly, sqlite3_stmt_readonly() would still return true.)^
3217 **
3218 ** ^Transaction control statements such as [BEGIN], [COMMIT], [ROLLBACK],
3219 ** [SAVEPOINT], and [RELEASE] cause sqlite3_stmt_readonly() to return true,
3220 ** since the statements themselves do not actually modify the database but
3221 ** rather they control the timing of when other statements modify the
3222 ** database. ^The [ATTACH] and [DETACH] statements also cause
3223 ** sqlite3_stmt_readonly() to return true since, while those statements
3224 ** change the configuration of a database connection, they do not make
3225 ** changes to the content of the database files on disk.
3226 */
3227 SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
3228
3229 /*
3230 ** CAPI3REF: Dynamically Typed Value Object
@@ -5927,11 +5949,12 @@
5949 ** internal equivalents). Only the value returned in the
5950 ** *pHighwater parameter to [sqlite3_status()] is of interest.
5951 ** The value written into the *pCurrent parameter is undefined.</dd>)^
5952 **
5953 ** ^(<dt>SQLITE_STATUS_MALLOC_COUNT</dt>
5954 ** <dd>This parameter records the number of separate memory allocations
5955 ** currently checked out.</dd>)^
5956 **
5957 ** ^(<dt>SQLITE_STATUS_PAGECACHE_USED</dt>
5958 ** <dd>This parameter returns the number of pages used out of the
5959 ** [pagecache memory allocator] that was configured using
5960 ** [SQLITE_CONFIG_PAGECACHE]. The
@@ -6032,10 +6055,32 @@
6055 **
6056 ** <dl>
6057 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
6058 ** <dd>This parameter returns the number of lookaside memory slots currently
6059 ** checked out.</dd>)^
6060 **
6061 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_HIT</dt>
6062 ** <dd>This parameter returns the number malloc attempts that were
6063 ** satisfied using lookaside memory. Only the high-water value is meaningful;
6064 ** the current value is always zero.
6065 ** checked out.</dd>)^
6066 **
6067 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE</dt>
6068 ** <dd>This parameter returns the number malloc attempts that might have
6069 ** been satisfied using lookaside memory but failed due to the amount of
6070 ** memory requested being larger than the lookaside slot size.
6071 ** Only the high-water value is meaningful;
6072 ** the current value is always zero.
6073 ** checked out.</dd>)^
6074 **
6075 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL</dt>
6076 ** <dd>This parameter returns the number malloc attempts that might have
6077 ** been satisfied using lookaside memory but failed due to all lookaside
6078 ** memory already being in use.
6079 ** Only the high-water value is meaningful;
6080 ** the current value is always zero.
6081 ** checked out.</dd>)^
6082 **
6083 ** ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt>
6084 ** <dd>This parameter returns the approximate number of of bytes of heap
6085 ** memory used by all pager caches associated with the database connection.)^
6086 ** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
@@ -6055,15 +6100,18 @@
6100 ** the database connection.)^
6101 ** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0.
6102 ** </dd>
6103 ** </dl>
6104 */
6105 #define SQLITE_DBSTATUS_LOOKASIDE_USED 0
6106 #define SQLITE_DBSTATUS_CACHE_USED 1
6107 #define SQLITE_DBSTATUS_SCHEMA_USED 2
6108 #define SQLITE_DBSTATUS_STMT_USED 3
6109 #define SQLITE_DBSTATUS_LOOKASIDE_HIT 4
6110 #define SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE 5
6111 #define SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL 6
6112 #define SQLITE_DBSTATUS_MAX 6 /* Largest defined DBSTATUS */
6113
6114
6115 /*
6116 ** CAPI3REF: Prepared Statement Status
6117 **
@@ -6307,15 +6355,16 @@
6355 ** It is useful either for creating backups of databases or
6356 ** for copying in-memory databases to or from persistent files.
6357 **
6358 ** See Also: [Using the SQLite Online Backup API]
6359 **
6360 ** ^SQLite holds a write transaction open on the destination database file
6361 ** for the duration of the backup operation.
6362 ** ^The source database is read-locked only while it is being read;
6363 ** it is not locked continuously for the entire backup operation.
6364 ** ^Thus, the backup may be performed on a live source database without
6365 ** preventing other database connections from
6366 ** reading or writing to the source database while the backup is underway.
6367 **
6368 ** ^(To perform a backup operation:
6369 ** <ol>
6370 ** <li><b>sqlite3_backup_init()</b> is called once to initialize the
@@ -6338,15 +6387,15 @@
6387 ** an [ATTACH] statement for an attached database.
6388 ** ^The S and M arguments passed to
6389 ** sqlite3_backup_init(D,N,S,M) identify the [database connection]
6390 ** and database name of the source database, respectively.
6391 ** ^The source and destination [database connections] (parameters S and D)
6392 ** must be different or else sqlite3_backup_init(D,N,S,M) will fail with
6393 ** an error.
6394 **
6395 ** ^If an error occurs within sqlite3_backup_init(D,N,S,M), then NULL is
6396 ** returned and an error code and error message are stored in the
6397 ** destination [database connection] D.
6398 ** ^The error code and message for the failed call to sqlite3_backup_init()
6399 ** can be retrieved using the [sqlite3_errcode()], [sqlite3_errmsg()], and/or
6400 ** [sqlite3_errmsg16()] functions.
6401 ** ^A successful call to sqlite3_backup_init() returns a pointer to an
@@ -6359,11 +6408,11 @@
6408 **
6409 ** ^Function sqlite3_backup_step(B,N) will copy up to N pages between
6410 ** the source and destination databases specified by [sqlite3_backup] object B.
6411 ** ^If N is negative, all remaining source pages are copied.
6412 ** ^If sqlite3_backup_step(B,N) successfully copies N pages and there
6413 ** are still more pages to be copied, then the function returns [SQLITE_OK].
6414 ** ^If sqlite3_backup_step(B,N) successfully finishes copying all pages
6415 ** from source to destination, then it returns [SQLITE_DONE].
6416 ** ^If an error occurs while running sqlite3_backup_step(B,N),
6417 ** then an [error code] is returned. ^As well as [SQLITE_OK] and
6418 ** [SQLITE_DONE], a call to sqlite3_backup_step() may return [SQLITE_READONLY],
@@ -6373,11 +6422,11 @@
6422 ** ^(The sqlite3_backup_step() might return [SQLITE_READONLY] if
6423 ** <ol>
6424 ** <li> the destination database was opened read-only, or
6425 ** <li> the destination database is using write-ahead-log journaling
6426 ** and the destination and source page sizes differ, or
6427 ** <li> the destination database is an in-memory database and the
6428 ** destination and source page sizes differ.
6429 ** </ol>)^
6430 **
6431 ** ^If sqlite3_backup_step() cannot obtain a required file-system lock, then
6432 ** the [sqlite3_busy_handler | busy-handler function]
@@ -6704,11 +6753,12 @@
6753 **
6754 ** ^The [wal_autocheckpoint pragma] can be used to invoke this interface
6755 ** from SQL.
6756 **
6757 ** ^Every new [database connection] defaults to having the auto-checkpoint
6758 ** enabled with a threshold of 1000 or [SQLITE_DEFAULT_WAL_AUTOCHECKPOINT]
6759 ** pages. The use of this interface
6760 ** is only necessary if the default setting is found to be suboptimal
6761 ** for a particular application.
6762 */
6763 SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
6764
@@ -8875,10 +8925,11 @@
8925 u16 sz; /* Size of each buffer in bytes */
8926 u8 bEnabled; /* False to disable new lookaside allocations */
8927 u8 bMalloced; /* True if pStart obtained from sqlite3_malloc() */
8928 int nOut; /* Number of buffers currently checked out */
8929 int mxOut; /* Highwater mark for nOut */
8930 int anStat[3]; /* 0: hits. 1: size misses. 2: full misses */
8931 LookasideSlot *pFree; /* List of available buffers */
8932 void *pStart; /* First byte of available memory space */
8933 void *pEnd; /* First byte past end of available space */
8934 };
8935 struct LookasideSlot {
@@ -12506,10 +12557,26 @@
12557 if( resetFlag ){
12558 db->lookaside.mxOut = db->lookaside.nOut;
12559 }
12560 break;
12561 }
12562
12563 case SQLITE_DBSTATUS_LOOKASIDE_HIT:
12564 case SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE:
12565 case SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL: {
12566 testcase( op==SQLITE_DBSTATUS_LOOKASIDE_HIT );
12567 testcase( op==SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE );
12568 testcase( op==SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL );
12569 assert( (op-SQLITE_DBSTATUS_LOOKASIDE_HIT)>=0 );
12570 assert( (op-SQLITE_DBSTATUS_LOOKASIDE_HIT)<3 );
12571 *pCurrent = 0;
12572 *pHighwater = db->lookaside.anStat[op - SQLITE_DBSTATUS_LOOKASIDE_HIT];
12573 if( resetFlag ){
12574 db->lookaside.anStat[op - SQLITE_DBSTATUS_LOOKASIDE_HIT] = 0;
12575 }
12576 break;
12577 }
12578
12579 /*
12580 ** Return an approximation for the amount of memory currently used
12581 ** by all pagers associated with the given database connection. The
12582 ** highwater mark is meaningless and is returned as zero.
@@ -18068,18 +18135,24 @@
18135 if( db ){
18136 LookasideSlot *pBuf;
18137 if( db->mallocFailed ){
18138 return 0;
18139 }
18140 if( db->lookaside.bEnabled ){
18141 if( n>db->lookaside.sz ){
18142 db->lookaside.anStat[1]++;
18143 }else if( (pBuf = db->lookaside.pFree)==0 ){
18144 db->lookaside.anStat[2]++;
18145 }else{
18146 db->lookaside.pFree = pBuf->pNext;
18147 db->lookaside.nOut++;
18148 db->lookaside.anStat[0]++;
18149 if( db->lookaside.nOut>db->lookaside.mxOut ){
18150 db->lookaside.mxOut = db->lookaside.nOut;
18151 }
18152 return (void*)pBuf;
18153 }
18154 }
18155 }
18156 #else
18157 if( db && db->mallocFailed ){
18158 return 0;
@@ -28391,22 +28464,23 @@
28464
28465 /* get the host ID via gethostuuid(), pHostID must point to PROXY_HOSTIDLEN
28466 ** bytes of writable memory.
28467 */
28468 static int proxyGetHostID(unsigned char *pHostID, int *pError){
 
 
28469 assert(PROXY_HOSTIDLEN == sizeof(uuid_t));
28470 memset(pHostID, 0, PROXY_HOSTIDLEN);
28471 #if defined(__MAX_OS_X_VERSION_MIN_REQUIRED)\
28472 && __MAC_OS_X_VERSION_MIN_REQUIRED<1050
28473 {
28474 static const struct timespec timeout = {1, 0}; /* 1 sec timeout */
28475 if( gethostuuid(pHostID, &timeout) ){
28476 int err = errno;
28477 if( pError ){
28478 *pError = err;
28479 }
28480 return SQLITE_IOERR;
28481 }
 
28482 }
28483 #endif
28484 #ifdef SQLITE_TEST
28485 /* simulate multiple hosts by creating unique hostid file paths */
28486 if( sqlite3_hostid_num != 0){
@@ -41896,18 +41970,18 @@
41970 **
41971 ** This functionality is used by the checkpoint code (see walCheckpoint()).
41972 */
41973 struct WalIterator {
41974 int iPrior; /* Last result returned from the iterator */
41975 int nSegment; /* Number of entries in aSegment[] */
41976 struct WalSegment {
41977 int iNext; /* Next slot in aIndex[] not yet returned */
41978 ht_slot *aIndex; /* i0, i1, i2... such that aPgno[iN] ascend */
41979 u32 *aPgno; /* Array of page numbers. */
41980 int nEntry; /* Nr. of entries in aPgno[] and aIndex[] */
41981 int iZero; /* Frame number associated with aPgno[0] */
41982 } aSegment[1]; /* One for every 32KB page in the wal-index */
41983 };
41984
41985 /*
41986 ** Define the parameters of the hash tables in the wal-index file. There
41987 ** is a hash-table following every HASHTABLE_NPAGE page numbers in the
@@ -42767,13 +42841,33 @@
42841 return (iRet==0xFFFFFFFF);
42842 }
42843
42844 /*
42845 ** This function merges two sorted lists into a single sorted list.
42846 **
42847 ** aLeft[] and aRight[] are arrays of indices. The sort key is
42848 ** aContent[aLeft[]] and aContent[aRight[]]. Upon entry, the following
42849 ** is guaranteed for all J<K:
42850 **
42851 ** aContent[aLeft[J]] < aContent[aLeft[K]]
42852 ** aContent[aRight[J]] < aContent[aRight[K]]
42853 **
42854 ** This routine overwrites aRight[] with a new (probably longer) sequence
42855 ** of indices such that the aRight[] contains every index that appears in
42856 ** either aLeft[] or the old aRight[] and such that the second condition
42857 ** above is still met.
42858 **
42859 ** The aContent[aLeft[X]] values will be unique for all X. And the
42860 ** aContent[aRight[X]] values will be unique too. But there might be
42861 ** one or more combinations of X and Y such that
42862 **
42863 ** aLeft[X]!=aRight[Y] && aContent[aLeft[X]] == aContent[aRight[Y]]
42864 **
42865 ** When that happens, omit the aLeft[X] and use the aRight[Y] index.
42866 */
42867 static void walMerge(
42868 const u32 *aContent, /* Pages in wal - keys for the sort */
42869 ht_slot *aLeft, /* IN: Left hand input list */
42870 int nLeft, /* IN: Elements in array *paLeft */
42871 ht_slot **paRight, /* IN/OUT: Right hand input list */
42872 int *pnRight, /* IN/OUT: Elements in *paRight */
42873 ht_slot *aTmp /* Temporary buffer */
@@ -42809,14 +42903,28 @@
42903 *pnRight = iOut;
42904 memcpy(aLeft, aTmp, sizeof(aTmp[0])*iOut);
42905 }
42906
42907 /*
42908 ** Sort the elements in list aList using aContent[] as the sort key.
42909 ** Remove elements with duplicate keys, preferring to keep the
42910 ** larger aList[] values.
42911 **
42912 ** The aList[] entries are indices into aContent[]. The values in
42913 ** aList[] are to be sorted so that for all J<K:
42914 **
42915 ** aContent[aList[J]] < aContent[aList[K]]
42916 **
42917 ** For any X and Y such that
42918 **
42919 ** aContent[aList[X]] == aContent[aList[Y]]
42920 **
42921 ** Keep the larger of the two values aList[X] and aList[Y] and discard
42922 ** the smaller.
42923 */
42924 static void walMergesort(
42925 const u32 *aContent, /* Pages in wal */
42926 ht_slot *aBuffer, /* Buffer of at least *pnList items to use */
42927 ht_slot *aList, /* IN/OUT: List to sort */
42928 int *pnList /* IN/OUT: Number of elements in aList[] */
42929 ){
42930 struct Sublist {
@@ -42877,10 +42985,11 @@
42985 }
42986
42987 /*
42988 ** Construct a WalInterator object that can be used to loop over all
42989 ** pages in the WAL in ascending order. The caller must hold the checkpoint
42990 ** lock.
42991 **
42992 ** On success, make *pp point to the newly allocated WalInterator object
42993 ** return SQLITE_OK. Otherwise, return an error code. If this routine
42994 ** returns an error, the value of *pp is undefined.
42995 **
@@ -43011,11 +43120,12 @@
43120 volatile WalCkptInfo *pInfo; /* The checkpoint status information */
43121
43122 szPage = (pWal->hdr.szPage&0xfe00) + ((pWal->hdr.szPage&0x0001)<<16);
43123 testcase( szPage<=32768 );
43124 testcase( szPage>=65536 );
43125 pInfo = walCkptInfo(pWal);
43126 if( pInfo->nBackfill>=pWal->hdr.mxFrame ) return SQLITE_OK;
43127
43128 /* Allocate the iterator */
43129 rc = walIteratorInit(pWal, &pIter);
43130 if( rc!=SQLITE_OK ){
43131 return rc;
@@ -43033,11 +43143,10 @@
43143 ** overwrite database pages that are in use by active readers and thus
43144 ** cannot be backfilled from the WAL.
43145 */
43146 mxSafeFrame = pWal->hdr.mxFrame;
43147 mxPage = pWal->hdr.nPage;
 
43148 for(i=1; i<WAL_NREADER; i++){
43149 u32 y = pInfo->aReadMark[i];
43150 if( mxSafeFrame>=y ){
43151 assert( y<=pWal->hdr.mxFrame );
43152 rc = walLockExclusive(pWal, WAL_READ_LOCK(i), 1);
@@ -55556,11 +55665,11 @@
55665 u8 opcode = pOp->opcode;
55666
55667 pOp->opflags = sqlite3OpcodeProperty[opcode];
55668 if( opcode==OP_Function || opcode==OP_AggStep ){
55669 if( pOp->p5>nMaxArgs ) nMaxArgs = pOp->p5;
55670 }else if( (opcode==OP_Transaction && pOp->p2!=0) || opcode==OP_Vacuum ){
55671 p->readOnly = 0;
55672 #ifndef SQLITE_OMIT_VIRTUALTABLE
55673 }else if( opcode==OP_VUpdate ){
55674 if( pOp->p2>nMaxArgs ) nMaxArgs = pOp->p2;
55675 }else if( opcode==OP_VFilter ){
@@ -80921,13 +81030,13 @@
81030 if( caseSensitive ){
81031 pInfo = (struct compareInfo*)&likeInfoAlt;
81032 }else{
81033 pInfo = (struct compareInfo*)&likeInfoNorm;
81034 }
81035 sqlite3CreateFunc(db, "like", 2, SQLITE_UTF8, pInfo, likeFunc, 0, 0, 0);
81036 sqlite3CreateFunc(db, "like", 3, SQLITE_UTF8, pInfo, likeFunc, 0, 0, 0);
81037 sqlite3CreateFunc(db, "glob", 2, SQLITE_UTF8,
81038 (struct compareInfo*)&globInfo, likeFunc, 0, 0, 0);
81039 setLikeOptFlag(db, "glob", SQLITE_FUNC_LIKE | SQLITE_FUNC_CASE);
81040 setLikeOptFlag(db, "like",
81041 caseSensitive ? (SQLITE_FUNC_LIKE | SQLITE_FUNC_CASE) : SQLITE_FUNC_LIKE);
81042 }
@@ -97673,14 +97782,13 @@
97782 Parse *pParse,
97783 Expr *pExpr,
97784 u8 aff,
97785 sqlite3_value **pp
97786 ){
97787 if( pExpr->op==TK_VARIABLE
97788 || (pExpr->op==TK_REGISTER && pExpr->op2==TK_VARIABLE)
97789 ){
 
97790 int iVar = pExpr->iColumn;
97791 sqlite3VdbeSetVarmask(pParse->pVdbe, iVar); /* IMP: R-23257-02778 */
97792 *pp = sqlite3VdbeGetValue(pParse->pReprepare, iVar, aff);
97793 return SQLITE_OK;
97794 }
@@ -106470,10 +106578,13 @@
106578 | SQLITE_LoadExtension
106579 #endif
106580 #if SQLITE_DEFAULT_RECURSIVE_TRIGGERS
106581 | SQLITE_RecTriggers
106582 #endif
106583 #if defined(SQLITE_DEFAULT_FOREIGN_KEYS) && SQLITE_DEFAULT_FOREIGN_KEYS
106584 | SQLITE_ForeignKeys
106585 #endif
106586 ;
106587 sqlite3HashInit(&db->aCollSeq);
106588 #ifndef SQLITE_OMIT_VIRTUALTABLE
106589 sqlite3HashInit(&db->aModule);
106590 #endif
@@ -111307,13 +111418,20 @@
111418 int iCol /* Column of requested pos-list */
111419 ){
111420 assert( pExpr->isLoaded );
111421 if( pExpr->aDoclist ){
111422 char *pEnd = &pExpr->aDoclist[pExpr->nDoclist];
111423 char *pCsr;
111424
111425 if( pExpr->pCurrent==0 ){
111426 pExpr->pCurrent = pExpr->aDoclist;
111427 pExpr->iCurrent = 0;
111428 pExpr->pCurrent += sqlite3Fts3GetVarint(pExpr->pCurrent,&pExpr->iCurrent);
111429 }
111430 pCsr = pExpr->pCurrent;
111431 assert( pCsr );
111432
111433 while( pCsr<pEnd ){
111434 if( pExpr->iCurrent<iDocid ){
111435 fts3PoslistCopy(0, &pCsr);
111436 if( pCsr<pEnd ){
111437 fts3GetDeltaVarint(&pCsr, &pExpr->iCurrent);
@@ -117513,11 +117631,11 @@
117631 /*
117632 ** This is an fts3ExprIterate() callback used while loading the doclists
117633 ** for each phrase into Fts3Expr.aDoclist[]/nDoclist. See also
117634 ** fts3ExprLoadDoclists().
117635 */
117636 static int fts3ExprLoadDoclistsCb(Fts3Expr *pExpr, int iPhrase, void *ctx){
117637 int rc = SQLITE_OK;
117638 LoadDoclistCtx *p = (LoadDoclistCtx *)ctx;
117639
117640 UNUSED_PARAMETER(iPhrase);
117641
@@ -117533,26 +117651,10 @@
117651 }
117652
117653 return rc;
117654 }
117655
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
117656 /*
117657 ** Load the doclists for each phrase in the query associated with FTS3 cursor
117658 ** pCsr.
117659 **
117660 ** If pnPhrase is not NULL, then *pnPhrase is set to the number of matchable
@@ -117567,14 +117669,11 @@
117669 int *pnToken /* OUT: Number of tokens in query */
117670 ){
117671 int rc; /* Return Code */
117672 LoadDoclistCtx sCtx = {0,0,0}; /* Context for fts3ExprIterate() */
117673 sCtx.pCsr = pCsr;
117674 rc = fts3ExprIterate(pCsr->pExpr, fts3ExprLoadDoclistsCb, (void *)&sCtx);
 
 
 
117675 if( pnPhrase ) *pnPhrase = sCtx.nPhrase;
117676 if( pnToken ) *pnToken = sCtx.nToken;
117677 return rc;
117678 }
117679
117680
+177 -78
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -650,11 +650,11 @@
650650
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
651651
** [sqlite_version()] and [sqlite_source_id()].
652652
*/
653653
#define SQLITE_VERSION "3.7.4"
654654
#define SQLITE_VERSION_NUMBER 3007004
655
-#define SQLITE_SOURCE_ID "2010-12-06 21:09:59 fabcb6b95e1d4059d1e6c6183f65846f6cbd5749"
655
+#define SQLITE_SOURCE_ID "2010-12-21 21:28:38 b0888047bb6d9ac55e29b9224df2ff650728bb78"
656656
657657
/*
658658
** CAPI3REF: Run-Time Library Version Numbers
659659
** KEYWORDS: sqlite3_version, sqlite3_sourceid
660660
**
@@ -1256,10 +1256,15 @@
12561256
** by the user. The fourth argument to [sqlite3_file_control()] should
12571257
** point to an integer (type int) containing the new chunk-size to use
12581258
** for the nominated database. Allocating database file space in large
12591259
** chunks (say 1MB at a time), may reduce file-system fragmentation and
12601260
** improve performance on some systems.
1261
+**
1262
+** The [SQLITE_FCNTL_FILE_POINTER] opcode is used to obtain a pointer
1263
+** to the [sqlite3_file] object associated with a particular database
1264
+** connection. See the [sqlite3_file_control()] documentation for
1265
+** additional information.
12611266
*/
12621267
#define SQLITE_FCNTL_LOCKSTATE 1
12631268
#define SQLITE_GET_LOCKPROXYFILE 2
12641269
#define SQLITE_SET_LOCKPROXYFILE 3
12651270
#define SQLITE_LAST_ERRNO 4
@@ -3191,18 +3196,35 @@
31913196
SQLITE_API const char *sqlite3_sql(sqlite3_stmt *pStmt);
31923197
31933198
/*
31943199
** CAPI3REF: Determine If An SQL Statement Writes The Database
31953200
**
3196
-** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if
3197
-** the [prepared statement] X is [SELECT] statement and false (zero) if
3198
-** X is an [INSERT], [UPDATE], [DELETE], CREATE, DROP, [ANALYZE],
3199
-** [ALTER], or [REINDEX] statement.
3200
-** If X is a NULL pointer or any other kind of statement, including but
3201
-** not limited to [ATTACH], [DETACH], [COMMIT], [ROLLBACK], [RELEASE],
3202
-** [SAVEPOINT], [PRAGMA], or [VACUUM] the result of sqlite3_stmt_readonly(X) is
3203
-** undefined.
3201
+** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if
3202
+** and only if the [prepared statement] X is makes no direct changes to
3203
+** the content of the database file.
3204
+**
3205
+** Note that [application-defined SQL functions] or
3206
+** [virtual tables] might change the database indirectly as a side effect.
3207
+** ^(For example, if an application defines a function "eval()" that
3208
+** calls [sqlite3_exec()], then the following SQL statement would
3209
+** change the database file through side-effects:
3210
+**
3211
+** <blockquote><pre>
3212
+** SELECT eval('DELETE FROM t1') FROM t2;
3213
+** </pre></blockquote>
3214
+**
3215
+** But because the [SELECT] statement does not change the database file
3216
+** directly, sqlite3_stmt_readonly() would still return true.)^
3217
+**
3218
+** ^Transaction control statements such as [BEGIN], [COMMIT], [ROLLBACK],
3219
+** [SAVEPOINT], and [RELEASE] cause sqlite3_stmt_readonly() to return true,
3220
+** since the statements themselves do not actually modify the database but
3221
+** rather they control the timing of when other statements modify the
3222
+** database. ^The [ATTACH] and [DETACH] statements also cause
3223
+** sqlite3_stmt_readonly() to return true since, while those statements
3224
+** change the configuration of a database connection, they do not make
3225
+** changes to the content of the database files on disk.
32043226
*/
32053227
SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
32063228
32073229
/*
32083230
** CAPI3REF: Dynamically Typed Value Object
@@ -5927,11 +5949,12 @@
59275949
** internal equivalents). Only the value returned in the
59285950
** *pHighwater parameter to [sqlite3_status()] is of interest.
59295951
** The value written into the *pCurrent parameter is undefined.</dd>)^
59305952
**
59315953
** ^(<dt>SQLITE_STATUS_MALLOC_COUNT</dt>
5932
-** <dd>This parameter records the number of separate memory allocations.</dd>)^
5954
+** <dd>This parameter records the number of separate memory allocations
5955
+** currently checked out.</dd>)^
59335956
**
59345957
** ^(<dt>SQLITE_STATUS_PAGECACHE_USED</dt>
59355958
** <dd>This parameter returns the number of pages used out of the
59365959
** [pagecache memory allocator] that was configured using
59375960
** [SQLITE_CONFIG_PAGECACHE]. The
@@ -6032,10 +6055,32 @@
60326055
**
60336056
** <dl>
60346057
** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
60356058
** <dd>This parameter returns the number of lookaside memory slots currently
60366059
** checked out.</dd>)^
6060
+**
6061
+** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_HIT</dt>
6062
+** <dd>This parameter returns the number malloc attempts that were
6063
+** satisfied using lookaside memory. Only the high-water value is meaningful;
6064
+** the current value is always zero.
6065
+** checked out.</dd>)^
6066
+**
6067
+** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE</dt>
6068
+** <dd>This parameter returns the number malloc attempts that might have
6069
+** been satisfied using lookaside memory but failed due to the amount of
6070
+** memory requested being larger than the lookaside slot size.
6071
+** Only the high-water value is meaningful;
6072
+** the current value is always zero.
6073
+** checked out.</dd>)^
6074
+**
6075
+** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL</dt>
6076
+** <dd>This parameter returns the number malloc attempts that might have
6077
+** been satisfied using lookaside memory but failed due to all lookaside
6078
+** memory already being in use.
6079
+** Only the high-water value is meaningful;
6080
+** the current value is always zero.
6081
+** checked out.</dd>)^
60376082
**
60386083
** ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt>
60396084
** <dd>This parameter returns the approximate number of of bytes of heap
60406085
** memory used by all pager caches associated with the database connection.)^
60416086
** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
@@ -6055,15 +6100,18 @@
60556100
** the database connection.)^
60566101
** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0.
60576102
** </dd>
60586103
** </dl>
60596104
*/
6060
-#define SQLITE_DBSTATUS_LOOKASIDE_USED 0
6061
-#define SQLITE_DBSTATUS_CACHE_USED 1
6062
-#define SQLITE_DBSTATUS_SCHEMA_USED 2
6063
-#define SQLITE_DBSTATUS_STMT_USED 3
6064
-#define SQLITE_DBSTATUS_MAX 3 /* Largest defined DBSTATUS */
6105
+#define SQLITE_DBSTATUS_LOOKASIDE_USED 0
6106
+#define SQLITE_DBSTATUS_CACHE_USED 1
6107
+#define SQLITE_DBSTATUS_SCHEMA_USED 2
6108
+#define SQLITE_DBSTATUS_STMT_USED 3
6109
+#define SQLITE_DBSTATUS_LOOKASIDE_HIT 4
6110
+#define SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE 5
6111
+#define SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL 6
6112
+#define SQLITE_DBSTATUS_MAX 6 /* Largest defined DBSTATUS */
60656113
60666114
60676115
/*
60686116
** CAPI3REF: Prepared Statement Status
60696117
**
@@ -6307,15 +6355,16 @@
63076355
** It is useful either for creating backups of databases or
63086356
** for copying in-memory databases to or from persistent files.
63096357
**
63106358
** See Also: [Using the SQLite Online Backup API]
63116359
**
6312
-** ^Exclusive access is required to the destination database for the
6313
-** duration of the operation. ^However the source database is only
6314
-** read-locked while it is actually being read; it is not locked
6315
-** continuously for the entire backup operation. ^Thus, the backup may be
6316
-** performed on a live source database without preventing other users from
6360
+** ^SQLite holds a write transaction open on the destination database file
6361
+** for the duration of the backup operation.
6362
+** ^The source database is read-locked only while it is being read;
6363
+** it is not locked continuously for the entire backup operation.
6364
+** ^Thus, the backup may be performed on a live source database without
6365
+** preventing other database connections from
63176366
** reading or writing to the source database while the backup is underway.
63186367
**
63196368
** ^(To perform a backup operation:
63206369
** <ol>
63216370
** <li><b>sqlite3_backup_init()</b> is called once to initialize the
@@ -6338,15 +6387,15 @@
63386387
** an [ATTACH] statement for an attached database.
63396388
** ^The S and M arguments passed to
63406389
** sqlite3_backup_init(D,N,S,M) identify the [database connection]
63416390
** and database name of the source database, respectively.
63426391
** ^The source and destination [database connections] (parameters S and D)
6343
-** must be different or else sqlite3_backup_init(D,N,S,M) will file with
6392
+** must be different or else sqlite3_backup_init(D,N,S,M) will fail with
63446393
** an error.
63456394
**
63466395
** ^If an error occurs within sqlite3_backup_init(D,N,S,M), then NULL is
6347
-** returned and an error code and error message are store3d in the
6396
+** returned and an error code and error message are stored in the
63486397
** destination [database connection] D.
63496398
** ^The error code and message for the failed call to sqlite3_backup_init()
63506399
** can be retrieved using the [sqlite3_errcode()], [sqlite3_errmsg()], and/or
63516400
** [sqlite3_errmsg16()] functions.
63526401
** ^A successful call to sqlite3_backup_init() returns a pointer to an
@@ -6359,11 +6408,11 @@
63596408
**
63606409
** ^Function sqlite3_backup_step(B,N) will copy up to N pages between
63616410
** the source and destination databases specified by [sqlite3_backup] object B.
63626411
** ^If N is negative, all remaining source pages are copied.
63636412
** ^If sqlite3_backup_step(B,N) successfully copies N pages and there
6364
-** are still more pages to be copied, then the function resturns [SQLITE_OK].
6413
+** are still more pages to be copied, then the function returns [SQLITE_OK].
63656414
** ^If sqlite3_backup_step(B,N) successfully finishes copying all pages
63666415
** from source to destination, then it returns [SQLITE_DONE].
63676416
** ^If an error occurs while running sqlite3_backup_step(B,N),
63686417
** then an [error code] is returned. ^As well as [SQLITE_OK] and
63696418
** [SQLITE_DONE], a call to sqlite3_backup_step() may return [SQLITE_READONLY],
@@ -6373,11 +6422,11 @@
63736422
** ^(The sqlite3_backup_step() might return [SQLITE_READONLY] if
63746423
** <ol>
63756424
** <li> the destination database was opened read-only, or
63766425
** <li> the destination database is using write-ahead-log journaling
63776426
** and the destination and source page sizes differ, or
6378
-** <li> The destination database is an in-memory database and the
6427
+** <li> the destination database is an in-memory database and the
63796428
** destination and source page sizes differ.
63806429
** </ol>)^
63816430
**
63826431
** ^If sqlite3_backup_step() cannot obtain a required file-system lock, then
63836432
** the [sqlite3_busy_handler | busy-handler function]
@@ -6704,11 +6753,12 @@
67046753
**
67056754
** ^The [wal_autocheckpoint pragma] can be used to invoke this interface
67066755
** from SQL.
67076756
**
67086757
** ^Every new [database connection] defaults to having the auto-checkpoint
6709
-** enabled with a threshold of 1000 pages. The use of this interface
6758
+** enabled with a threshold of 1000 or [SQLITE_DEFAULT_WAL_AUTOCHECKPOINT]
6759
+** pages. The use of this interface
67106760
** is only necessary if the default setting is found to be suboptimal
67116761
** for a particular application.
67126762
*/
67136763
SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
67146764
@@ -8875,10 +8925,11 @@
88758925
u16 sz; /* Size of each buffer in bytes */
88768926
u8 bEnabled; /* False to disable new lookaside allocations */
88778927
u8 bMalloced; /* True if pStart obtained from sqlite3_malloc() */
88788928
int nOut; /* Number of buffers currently checked out */
88798929
int mxOut; /* Highwater mark for nOut */
8930
+ int anStat[3]; /* 0: hits. 1: size misses. 2: full misses */
88808931
LookasideSlot *pFree; /* List of available buffers */
88818932
void *pStart; /* First byte of available memory space */
88828933
void *pEnd; /* First byte past end of available space */
88838934
};
88848935
struct LookasideSlot {
@@ -12506,10 +12557,26 @@
1250612557
if( resetFlag ){
1250712558
db->lookaside.mxOut = db->lookaside.nOut;
1250812559
}
1250912560
break;
1251012561
}
12562
+
12563
+ case SQLITE_DBSTATUS_LOOKASIDE_HIT:
12564
+ case SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE:
12565
+ case SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL: {
12566
+ testcase( op==SQLITE_DBSTATUS_LOOKASIDE_HIT );
12567
+ testcase( op==SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE );
12568
+ testcase( op==SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL );
12569
+ assert( (op-SQLITE_DBSTATUS_LOOKASIDE_HIT)>=0 );
12570
+ assert( (op-SQLITE_DBSTATUS_LOOKASIDE_HIT)<3 );
12571
+ *pCurrent = 0;
12572
+ *pHighwater = db->lookaside.anStat[op - SQLITE_DBSTATUS_LOOKASIDE_HIT];
12573
+ if( resetFlag ){
12574
+ db->lookaside.anStat[op - SQLITE_DBSTATUS_LOOKASIDE_HIT] = 0;
12575
+ }
12576
+ break;
12577
+ }
1251112578
1251212579
/*
1251312580
** Return an approximation for the amount of memory currently used
1251412581
** by all pagers associated with the given database connection. The
1251512582
** highwater mark is meaningless and is returned as zero.
@@ -18068,18 +18135,24 @@
1806818135
if( db ){
1806918136
LookasideSlot *pBuf;
1807018137
if( db->mallocFailed ){
1807118138
return 0;
1807218139
}
18073
- if( db->lookaside.bEnabled && n<=db->lookaside.sz
18074
- && (pBuf = db->lookaside.pFree)!=0 ){
18075
- db->lookaside.pFree = pBuf->pNext;
18076
- db->lookaside.nOut++;
18077
- if( db->lookaside.nOut>db->lookaside.mxOut ){
18078
- db->lookaside.mxOut = db->lookaside.nOut;
18079
- }
18080
- return (void*)pBuf;
18140
+ if( db->lookaside.bEnabled ){
18141
+ if( n>db->lookaside.sz ){
18142
+ db->lookaside.anStat[1]++;
18143
+ }else if( (pBuf = db->lookaside.pFree)==0 ){
18144
+ db->lookaside.anStat[2]++;
18145
+ }else{
18146
+ db->lookaside.pFree = pBuf->pNext;
18147
+ db->lookaside.nOut++;
18148
+ db->lookaside.anStat[0]++;
18149
+ if( db->lookaside.nOut>db->lookaside.mxOut ){
18150
+ db->lookaside.mxOut = db->lookaside.nOut;
18151
+ }
18152
+ return (void*)pBuf;
18153
+ }
1808118154
}
1808218155
}
1808318156
#else
1808418157
if( db && db->mallocFailed ){
1808518158
return 0;
@@ -28391,22 +28464,23 @@
2839128464
2839228465
/* get the host ID via gethostuuid(), pHostID must point to PROXY_HOSTIDLEN
2839328466
** bytes of writable memory.
2839428467
*/
2839528468
static int proxyGetHostID(unsigned char *pHostID, int *pError){
28396
- struct timespec timeout = {1, 0}; /* 1 sec timeout */
28397
-
2839828469
assert(PROXY_HOSTIDLEN == sizeof(uuid_t));
2839928470
memset(pHostID, 0, PROXY_HOSTIDLEN);
2840028471
#if defined(__MAX_OS_X_VERSION_MIN_REQUIRED)\
2840128472
&& __MAC_OS_X_VERSION_MIN_REQUIRED<1050
28402
- if( gethostuuid(pHostID, &timeout) ){
28403
- int err = errno;
28404
- if( pError ){
28405
- *pError = err;
28473
+ {
28474
+ static const struct timespec timeout = {1, 0}; /* 1 sec timeout */
28475
+ if( gethostuuid(pHostID, &timeout) ){
28476
+ int err = errno;
28477
+ if( pError ){
28478
+ *pError = err;
28479
+ }
28480
+ return SQLITE_IOERR;
2840628481
}
28407
- return SQLITE_IOERR;
2840828482
}
2840928483
#endif
2841028484
#ifdef SQLITE_TEST
2841128485
/* simulate multiple hosts by creating unique hostid file paths */
2841228486
if( sqlite3_hostid_num != 0){
@@ -41896,18 +41970,18 @@
4189641970
**
4189741971
** This functionality is used by the checkpoint code (see walCheckpoint()).
4189841972
*/
4189941973
struct WalIterator {
4190041974
int iPrior; /* Last result returned from the iterator */
41901
- int nSegment; /* Size of the aSegment[] array */
41975
+ int nSegment; /* Number of entries in aSegment[] */
4190241976
struct WalSegment {
4190341977
int iNext; /* Next slot in aIndex[] not yet returned */
4190441978
ht_slot *aIndex; /* i0, i1, i2... such that aPgno[iN] ascend */
4190541979
u32 *aPgno; /* Array of page numbers. */
41906
- int nEntry; /* Max size of aPgno[] and aIndex[] arrays */
41980
+ int nEntry; /* Nr. of entries in aPgno[] and aIndex[] */
4190741981
int iZero; /* Frame number associated with aPgno[0] */
41908
- } aSegment[1]; /* One for every 32KB page in the WAL */
41982
+ } aSegment[1]; /* One for every 32KB page in the wal-index */
4190941983
};
4191041984
4191141985
/*
4191241986
** Define the parameters of the hash tables in the wal-index file. There
4191341987
** is a hash-table following every HASHTABLE_NPAGE page numbers in the
@@ -42767,13 +42841,33 @@
4276742841
return (iRet==0xFFFFFFFF);
4276842842
}
4276942843
4277042844
/*
4277142845
** This function merges two sorted lists into a single sorted list.
42846
+**
42847
+** aLeft[] and aRight[] are arrays of indices. The sort key is
42848
+** aContent[aLeft[]] and aContent[aRight[]]. Upon entry, the following
42849
+** is guaranteed for all J<K:
42850
+**
42851
+** aContent[aLeft[J]] < aContent[aLeft[K]]
42852
+** aContent[aRight[J]] < aContent[aRight[K]]
42853
+**
42854
+** This routine overwrites aRight[] with a new (probably longer) sequence
42855
+** of indices such that the aRight[] contains every index that appears in
42856
+** either aLeft[] or the old aRight[] and such that the second condition
42857
+** above is still met.
42858
+**
42859
+** The aContent[aLeft[X]] values will be unique for all X. And the
42860
+** aContent[aRight[X]] values will be unique too. But there might be
42861
+** one or more combinations of X and Y such that
42862
+**
42863
+** aLeft[X]!=aRight[Y] && aContent[aLeft[X]] == aContent[aRight[Y]]
42864
+**
42865
+** When that happens, omit the aLeft[X] and use the aRight[Y] index.
4277242866
*/
4277342867
static void walMerge(
42774
- u32 *aContent, /* Pages in wal */
42868
+ const u32 *aContent, /* Pages in wal - keys for the sort */
4277542869
ht_slot *aLeft, /* IN: Left hand input list */
4277642870
int nLeft, /* IN: Elements in array *paLeft */
4277742871
ht_slot **paRight, /* IN/OUT: Right hand input list */
4277842872
int *pnRight, /* IN/OUT: Elements in *paRight */
4277942873
ht_slot *aTmp /* Temporary buffer */
@@ -42809,14 +42903,28 @@
4280942903
*pnRight = iOut;
4281042904
memcpy(aLeft, aTmp, sizeof(aTmp[0])*iOut);
4281142905
}
4281242906
4281342907
/*
42814
-** Sort the elements in list aList, removing any duplicates.
42908
+** Sort the elements in list aList using aContent[] as the sort key.
42909
+** Remove elements with duplicate keys, preferring to keep the
42910
+** larger aList[] values.
42911
+**
42912
+** The aList[] entries are indices into aContent[]. The values in
42913
+** aList[] are to be sorted so that for all J<K:
42914
+**
42915
+** aContent[aList[J]] < aContent[aList[K]]
42916
+**
42917
+** For any X and Y such that
42918
+**
42919
+** aContent[aList[X]] == aContent[aList[Y]]
42920
+**
42921
+** Keep the larger of the two values aList[X] and aList[Y] and discard
42922
+** the smaller.
4281542923
*/
4281642924
static void walMergesort(
42817
- u32 *aContent, /* Pages in wal */
42925
+ const u32 *aContent, /* Pages in wal */
4281842926
ht_slot *aBuffer, /* Buffer of at least *pnList items to use */
4281942927
ht_slot *aList, /* IN/OUT: List to sort */
4282042928
int *pnList /* IN/OUT: Number of elements in aList[] */
4282142929
){
4282242930
struct Sublist {
@@ -42877,10 +42985,11 @@
4287742985
}
4287842986
4287942987
/*
4288042988
** Construct a WalInterator object that can be used to loop over all
4288142989
** pages in the WAL in ascending order. The caller must hold the checkpoint
42990
+** lock.
4288242991
**
4288342992
** On success, make *pp point to the newly allocated WalInterator object
4288442993
** return SQLITE_OK. Otherwise, return an error code. If this routine
4288542994
** returns an error, the value of *pp is undefined.
4288642995
**
@@ -43011,11 +43120,12 @@
4301143120
volatile WalCkptInfo *pInfo; /* The checkpoint status information */
4301243121
4301343122
szPage = (pWal->hdr.szPage&0xfe00) + ((pWal->hdr.szPage&0x0001)<<16);
4301443123
testcase( szPage<=32768 );
4301543124
testcase( szPage>=65536 );
43016
- if( pWal->hdr.mxFrame==0 ) return SQLITE_OK;
43125
+ pInfo = walCkptInfo(pWal);
43126
+ if( pInfo->nBackfill>=pWal->hdr.mxFrame ) return SQLITE_OK;
4301743127
4301843128
/* Allocate the iterator */
4301943129
rc = walIteratorInit(pWal, &pIter);
4302043130
if( rc!=SQLITE_OK ){
4302143131
return rc;
@@ -43033,11 +43143,10 @@
4303343143
** overwrite database pages that are in use by active readers and thus
4303443144
** cannot be backfilled from the WAL.
4303543145
*/
4303643146
mxSafeFrame = pWal->hdr.mxFrame;
4303743147
mxPage = pWal->hdr.nPage;
43038
- pInfo = walCkptInfo(pWal);
4303943148
for(i=1; i<WAL_NREADER; i++){
4304043149
u32 y = pInfo->aReadMark[i];
4304143150
if( mxSafeFrame>=y ){
4304243151
assert( y<=pWal->hdr.mxFrame );
4304343152
rc = walLockExclusive(pWal, WAL_READ_LOCK(i), 1);
@@ -55556,11 +55665,11 @@
5555655665
u8 opcode = pOp->opcode;
5555755666
5555855667
pOp->opflags = sqlite3OpcodeProperty[opcode];
5555955668
if( opcode==OP_Function || opcode==OP_AggStep ){
5556055669
if( pOp->p5>nMaxArgs ) nMaxArgs = pOp->p5;
55561
- }else if( opcode==OP_Transaction && pOp->p2!=0 ){
55670
+ }else if( (opcode==OP_Transaction && pOp->p2!=0) || opcode==OP_Vacuum ){
5556255671
p->readOnly = 0;
5556355672
#ifndef SQLITE_OMIT_VIRTUALTABLE
5556455673
}else if( opcode==OP_VUpdate ){
5556555674
if( pOp->p2>nMaxArgs ) nMaxArgs = pOp->p2;
5556655675
}else if( opcode==OP_VFilter ){
@@ -80921,13 +81030,13 @@
8092181030
if( caseSensitive ){
8092281031
pInfo = (struct compareInfo*)&likeInfoAlt;
8092381032
}else{
8092481033
pInfo = (struct compareInfo*)&likeInfoNorm;
8092581034
}
80926
- sqlite3CreateFunc(db, "like", 2, SQLITE_ANY, pInfo, likeFunc, 0, 0, 0);
80927
- sqlite3CreateFunc(db, "like", 3, SQLITE_ANY, pInfo, likeFunc, 0, 0, 0);
80928
- sqlite3CreateFunc(db, "glob", 2, SQLITE_ANY,
81035
+ sqlite3CreateFunc(db, "like", 2, SQLITE_UTF8, pInfo, likeFunc, 0, 0, 0);
81036
+ sqlite3CreateFunc(db, "like", 3, SQLITE_UTF8, pInfo, likeFunc, 0, 0, 0);
81037
+ sqlite3CreateFunc(db, "glob", 2, SQLITE_UTF8,
8092981038
(struct compareInfo*)&globInfo, likeFunc, 0, 0, 0);
8093081039
setLikeOptFlag(db, "glob", SQLITE_FUNC_LIKE | SQLITE_FUNC_CASE);
8093181040
setLikeOptFlag(db, "like",
8093281041
caseSensitive ? (SQLITE_FUNC_LIKE | SQLITE_FUNC_CASE) : SQLITE_FUNC_LIKE);
8093381042
}
@@ -97673,14 +97782,13 @@
9767397782
Parse *pParse,
9767497783
Expr *pExpr,
9767597784
u8 aff,
9767697785
sqlite3_value **pp
9767797786
){
97678
- /* The evalConstExpr() function will have already converted any TK_VARIABLE
97679
- ** expression involved in an comparison into a TK_REGISTER. */
97680
- assert( pExpr->op!=TK_VARIABLE );
97681
- if( pExpr->op==TK_REGISTER && pExpr->op2==TK_VARIABLE ){
97787
+ if( pExpr->op==TK_VARIABLE
97788
+ || (pExpr->op==TK_REGISTER && pExpr->op2==TK_VARIABLE)
97789
+ ){
9768297790
int iVar = pExpr->iColumn;
9768397791
sqlite3VdbeSetVarmask(pParse->pVdbe, iVar); /* IMP: R-23257-02778 */
9768497792
*pp = sqlite3VdbeGetValue(pParse->pReprepare, iVar, aff);
9768597793
return SQLITE_OK;
9768697794
}
@@ -106470,10 +106578,13 @@
106470106578
| SQLITE_LoadExtension
106471106579
#endif
106472106580
#if SQLITE_DEFAULT_RECURSIVE_TRIGGERS
106473106581
| SQLITE_RecTriggers
106474106582
#endif
106583
+#if defined(SQLITE_DEFAULT_FOREIGN_KEYS) && SQLITE_DEFAULT_FOREIGN_KEYS
106584
+ | SQLITE_ForeignKeys
106585
+#endif
106475106586
;
106476106587
sqlite3HashInit(&db->aCollSeq);
106477106588
#ifndef SQLITE_OMIT_VIRTUALTABLE
106478106589
sqlite3HashInit(&db->aModule);
106479106590
#endif
@@ -111307,13 +111418,20 @@
111307111418
int iCol /* Column of requested pos-list */
111308111419
){
111309111420
assert( pExpr->isLoaded );
111310111421
if( pExpr->aDoclist ){
111311111422
char *pEnd = &pExpr->aDoclist[pExpr->nDoclist];
111312
- char *pCsr = pExpr->pCurrent;
111423
+ char *pCsr;
111313111424
111425
+ if( pExpr->pCurrent==0 ){
111426
+ pExpr->pCurrent = pExpr->aDoclist;
111427
+ pExpr->iCurrent = 0;
111428
+ pExpr->pCurrent += sqlite3Fts3GetVarint(pExpr->pCurrent,&pExpr->iCurrent);
111429
+ }
111430
+ pCsr = pExpr->pCurrent;
111314111431
assert( pCsr );
111432
+
111315111433
while( pCsr<pEnd ){
111316111434
if( pExpr->iCurrent<iDocid ){
111317111435
fts3PoslistCopy(0, &pCsr);
111318111436
if( pCsr<pEnd ){
111319111437
fts3GetDeltaVarint(&pCsr, &pExpr->iCurrent);
@@ -117513,11 +117631,11 @@
117513117631
/*
117514117632
** This is an fts3ExprIterate() callback used while loading the doclists
117515117633
** for each phrase into Fts3Expr.aDoclist[]/nDoclist. See also
117516117634
** fts3ExprLoadDoclists().
117517117635
*/
117518
-static int fts3ExprLoadDoclistsCb1(Fts3Expr *pExpr, int iPhrase, void *ctx){
117636
+static int fts3ExprLoadDoclistsCb(Fts3Expr *pExpr, int iPhrase, void *ctx){
117519117637
int rc = SQLITE_OK;
117520117638
LoadDoclistCtx *p = (LoadDoclistCtx *)ctx;
117521117639
117522117640
UNUSED_PARAMETER(iPhrase);
117523117641
@@ -117533,26 +117651,10 @@
117533117651
}
117534117652
117535117653
return rc;
117536117654
}
117537117655
117538
-/*
117539
-** This is an fts3ExprIterate() callback used while loading the doclists
117540
-** for each phrase into Fts3Expr.aDoclist[]/nDoclist. See also
117541
-** fts3ExprLoadDoclists().
117542
-*/
117543
-static int fts3ExprLoadDoclistsCb2(Fts3Expr *pExpr, int iPhrase, void *ctx){
117544
- UNUSED_PARAMETER(iPhrase);
117545
- UNUSED_PARAMETER(ctx);
117546
- if( pExpr->aDoclist ){
117547
- pExpr->pCurrent = pExpr->aDoclist;
117548
- pExpr->iCurrent = 0;
117549
- pExpr->pCurrent += sqlite3Fts3GetVarint(pExpr->pCurrent, &pExpr->iCurrent);
117550
- }
117551
- return SQLITE_OK;
117552
-}
117553
-
117554117656
/*
117555117657
** Load the doclists for each phrase in the query associated with FTS3 cursor
117556117658
** pCsr.
117557117659
**
117558117660
** If pnPhrase is not NULL, then *pnPhrase is set to the number of matchable
@@ -117567,14 +117669,11 @@
117567117669
int *pnToken /* OUT: Number of tokens in query */
117568117670
){
117569117671
int rc; /* Return Code */
117570117672
LoadDoclistCtx sCtx = {0,0,0}; /* Context for fts3ExprIterate() */
117571117673
sCtx.pCsr = pCsr;
117572
- rc = fts3ExprIterate(pCsr->pExpr, fts3ExprLoadDoclistsCb1, (void *)&sCtx);
117573
- if( rc==SQLITE_OK ){
117574
- (void)fts3ExprIterate(pCsr->pExpr, fts3ExprLoadDoclistsCb2, 0);
117575
- }
117674
+ rc = fts3ExprIterate(pCsr->pExpr, fts3ExprLoadDoclistsCb, (void *)&sCtx);
117576117675
if( pnPhrase ) *pnPhrase = sCtx.nPhrase;
117577117676
if( pnToken ) *pnToken = sCtx.nToken;
117578117677
return rc;
117579117678
}
117580117679
117581117680
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -650,11 +650,11 @@
650 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
651 ** [sqlite_version()] and [sqlite_source_id()].
652 */
653 #define SQLITE_VERSION "3.7.4"
654 #define SQLITE_VERSION_NUMBER 3007004
655 #define SQLITE_SOURCE_ID "2010-12-06 21:09:59 fabcb6b95e1d4059d1e6c6183f65846f6cbd5749"
656
657 /*
658 ** CAPI3REF: Run-Time Library Version Numbers
659 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
660 **
@@ -1256,10 +1256,15 @@
1256 ** by the user. The fourth argument to [sqlite3_file_control()] should
1257 ** point to an integer (type int) containing the new chunk-size to use
1258 ** for the nominated database. Allocating database file space in large
1259 ** chunks (say 1MB at a time), may reduce file-system fragmentation and
1260 ** improve performance on some systems.
 
 
 
 
 
1261 */
1262 #define SQLITE_FCNTL_LOCKSTATE 1
1263 #define SQLITE_GET_LOCKPROXYFILE 2
1264 #define SQLITE_SET_LOCKPROXYFILE 3
1265 #define SQLITE_LAST_ERRNO 4
@@ -3191,18 +3196,35 @@
3191 SQLITE_API const char *sqlite3_sql(sqlite3_stmt *pStmt);
3192
3193 /*
3194 ** CAPI3REF: Determine If An SQL Statement Writes The Database
3195 **
3196 ** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if
3197 ** the [prepared statement] X is [SELECT] statement and false (zero) if
3198 ** X is an [INSERT], [UPDATE], [DELETE], CREATE, DROP, [ANALYZE],
3199 ** [ALTER], or [REINDEX] statement.
3200 ** If X is a NULL pointer or any other kind of statement, including but
3201 ** not limited to [ATTACH], [DETACH], [COMMIT], [ROLLBACK], [RELEASE],
3202 ** [SAVEPOINT], [PRAGMA], or [VACUUM] the result of sqlite3_stmt_readonly(X) is
3203 ** undefined.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3204 */
3205 SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
3206
3207 /*
3208 ** CAPI3REF: Dynamically Typed Value Object
@@ -5927,11 +5949,12 @@
5927 ** internal equivalents). Only the value returned in the
5928 ** *pHighwater parameter to [sqlite3_status()] is of interest.
5929 ** The value written into the *pCurrent parameter is undefined.</dd>)^
5930 **
5931 ** ^(<dt>SQLITE_STATUS_MALLOC_COUNT</dt>
5932 ** <dd>This parameter records the number of separate memory allocations.</dd>)^
 
5933 **
5934 ** ^(<dt>SQLITE_STATUS_PAGECACHE_USED</dt>
5935 ** <dd>This parameter returns the number of pages used out of the
5936 ** [pagecache memory allocator] that was configured using
5937 ** [SQLITE_CONFIG_PAGECACHE]. The
@@ -6032,10 +6055,32 @@
6032 **
6033 ** <dl>
6034 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
6035 ** <dd>This parameter returns the number of lookaside memory slots currently
6036 ** checked out.</dd>)^
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6037 **
6038 ** ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt>
6039 ** <dd>This parameter returns the approximate number of of bytes of heap
6040 ** memory used by all pager caches associated with the database connection.)^
6041 ** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
@@ -6055,15 +6100,18 @@
6055 ** the database connection.)^
6056 ** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0.
6057 ** </dd>
6058 ** </dl>
6059 */
6060 #define SQLITE_DBSTATUS_LOOKASIDE_USED 0
6061 #define SQLITE_DBSTATUS_CACHE_USED 1
6062 #define SQLITE_DBSTATUS_SCHEMA_USED 2
6063 #define SQLITE_DBSTATUS_STMT_USED 3
6064 #define SQLITE_DBSTATUS_MAX 3 /* Largest defined DBSTATUS */
 
 
 
6065
6066
6067 /*
6068 ** CAPI3REF: Prepared Statement Status
6069 **
@@ -6307,15 +6355,16 @@
6307 ** It is useful either for creating backups of databases or
6308 ** for copying in-memory databases to or from persistent files.
6309 **
6310 ** See Also: [Using the SQLite Online Backup API]
6311 **
6312 ** ^Exclusive access is required to the destination database for the
6313 ** duration of the operation. ^However the source database is only
6314 ** read-locked while it is actually being read; it is not locked
6315 ** continuously for the entire backup operation. ^Thus, the backup may be
6316 ** performed on a live source database without preventing other users from
 
6317 ** reading or writing to the source database while the backup is underway.
6318 **
6319 ** ^(To perform a backup operation:
6320 ** <ol>
6321 ** <li><b>sqlite3_backup_init()</b> is called once to initialize the
@@ -6338,15 +6387,15 @@
6338 ** an [ATTACH] statement for an attached database.
6339 ** ^The S and M arguments passed to
6340 ** sqlite3_backup_init(D,N,S,M) identify the [database connection]
6341 ** and database name of the source database, respectively.
6342 ** ^The source and destination [database connections] (parameters S and D)
6343 ** must be different or else sqlite3_backup_init(D,N,S,M) will file with
6344 ** an error.
6345 **
6346 ** ^If an error occurs within sqlite3_backup_init(D,N,S,M), then NULL is
6347 ** returned and an error code and error message are store3d in the
6348 ** destination [database connection] D.
6349 ** ^The error code and message for the failed call to sqlite3_backup_init()
6350 ** can be retrieved using the [sqlite3_errcode()], [sqlite3_errmsg()], and/or
6351 ** [sqlite3_errmsg16()] functions.
6352 ** ^A successful call to sqlite3_backup_init() returns a pointer to an
@@ -6359,11 +6408,11 @@
6359 **
6360 ** ^Function sqlite3_backup_step(B,N) will copy up to N pages between
6361 ** the source and destination databases specified by [sqlite3_backup] object B.
6362 ** ^If N is negative, all remaining source pages are copied.
6363 ** ^If sqlite3_backup_step(B,N) successfully copies N pages and there
6364 ** are still more pages to be copied, then the function resturns [SQLITE_OK].
6365 ** ^If sqlite3_backup_step(B,N) successfully finishes copying all pages
6366 ** from source to destination, then it returns [SQLITE_DONE].
6367 ** ^If an error occurs while running sqlite3_backup_step(B,N),
6368 ** then an [error code] is returned. ^As well as [SQLITE_OK] and
6369 ** [SQLITE_DONE], a call to sqlite3_backup_step() may return [SQLITE_READONLY],
@@ -6373,11 +6422,11 @@
6373 ** ^(The sqlite3_backup_step() might return [SQLITE_READONLY] if
6374 ** <ol>
6375 ** <li> the destination database was opened read-only, or
6376 ** <li> the destination database is using write-ahead-log journaling
6377 ** and the destination and source page sizes differ, or
6378 ** <li> The destination database is an in-memory database and the
6379 ** destination and source page sizes differ.
6380 ** </ol>)^
6381 **
6382 ** ^If sqlite3_backup_step() cannot obtain a required file-system lock, then
6383 ** the [sqlite3_busy_handler | busy-handler function]
@@ -6704,11 +6753,12 @@
6704 **
6705 ** ^The [wal_autocheckpoint pragma] can be used to invoke this interface
6706 ** from SQL.
6707 **
6708 ** ^Every new [database connection] defaults to having the auto-checkpoint
6709 ** enabled with a threshold of 1000 pages. The use of this interface
 
6710 ** is only necessary if the default setting is found to be suboptimal
6711 ** for a particular application.
6712 */
6713 SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
6714
@@ -8875,10 +8925,11 @@
8875 u16 sz; /* Size of each buffer in bytes */
8876 u8 bEnabled; /* False to disable new lookaside allocations */
8877 u8 bMalloced; /* True if pStart obtained from sqlite3_malloc() */
8878 int nOut; /* Number of buffers currently checked out */
8879 int mxOut; /* Highwater mark for nOut */
 
8880 LookasideSlot *pFree; /* List of available buffers */
8881 void *pStart; /* First byte of available memory space */
8882 void *pEnd; /* First byte past end of available space */
8883 };
8884 struct LookasideSlot {
@@ -12506,10 +12557,26 @@
12506 if( resetFlag ){
12507 db->lookaside.mxOut = db->lookaside.nOut;
12508 }
12509 break;
12510 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12511
12512 /*
12513 ** Return an approximation for the amount of memory currently used
12514 ** by all pagers associated with the given database connection. The
12515 ** highwater mark is meaningless and is returned as zero.
@@ -18068,18 +18135,24 @@
18068 if( db ){
18069 LookasideSlot *pBuf;
18070 if( db->mallocFailed ){
18071 return 0;
18072 }
18073 if( db->lookaside.bEnabled && n<=db->lookaside.sz
18074 && (pBuf = db->lookaside.pFree)!=0 ){
18075 db->lookaside.pFree = pBuf->pNext;
18076 db->lookaside.nOut++;
18077 if( db->lookaside.nOut>db->lookaside.mxOut ){
18078 db->lookaside.mxOut = db->lookaside.nOut;
18079 }
18080 return (void*)pBuf;
 
 
 
 
 
 
18081 }
18082 }
18083 #else
18084 if( db && db->mallocFailed ){
18085 return 0;
@@ -28391,22 +28464,23 @@
28391
28392 /* get the host ID via gethostuuid(), pHostID must point to PROXY_HOSTIDLEN
28393 ** bytes of writable memory.
28394 */
28395 static int proxyGetHostID(unsigned char *pHostID, int *pError){
28396 struct timespec timeout = {1, 0}; /* 1 sec timeout */
28397
28398 assert(PROXY_HOSTIDLEN == sizeof(uuid_t));
28399 memset(pHostID, 0, PROXY_HOSTIDLEN);
28400 #if defined(__MAX_OS_X_VERSION_MIN_REQUIRED)\
28401 && __MAC_OS_X_VERSION_MIN_REQUIRED<1050
28402 if( gethostuuid(pHostID, &timeout) ){
28403 int err = errno;
28404 if( pError ){
28405 *pError = err;
 
 
 
 
28406 }
28407 return SQLITE_IOERR;
28408 }
28409 #endif
28410 #ifdef SQLITE_TEST
28411 /* simulate multiple hosts by creating unique hostid file paths */
28412 if( sqlite3_hostid_num != 0){
@@ -41896,18 +41970,18 @@
41896 **
41897 ** This functionality is used by the checkpoint code (see walCheckpoint()).
41898 */
41899 struct WalIterator {
41900 int iPrior; /* Last result returned from the iterator */
41901 int nSegment; /* Size of the aSegment[] array */
41902 struct WalSegment {
41903 int iNext; /* Next slot in aIndex[] not yet returned */
41904 ht_slot *aIndex; /* i0, i1, i2... such that aPgno[iN] ascend */
41905 u32 *aPgno; /* Array of page numbers. */
41906 int nEntry; /* Max size of aPgno[] and aIndex[] arrays */
41907 int iZero; /* Frame number associated with aPgno[0] */
41908 } aSegment[1]; /* One for every 32KB page in the WAL */
41909 };
41910
41911 /*
41912 ** Define the parameters of the hash tables in the wal-index file. There
41913 ** is a hash-table following every HASHTABLE_NPAGE page numbers in the
@@ -42767,13 +42841,33 @@
42767 return (iRet==0xFFFFFFFF);
42768 }
42769
42770 /*
42771 ** This function merges two sorted lists into a single sorted list.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42772 */
42773 static void walMerge(
42774 u32 *aContent, /* Pages in wal */
42775 ht_slot *aLeft, /* IN: Left hand input list */
42776 int nLeft, /* IN: Elements in array *paLeft */
42777 ht_slot **paRight, /* IN/OUT: Right hand input list */
42778 int *pnRight, /* IN/OUT: Elements in *paRight */
42779 ht_slot *aTmp /* Temporary buffer */
@@ -42809,14 +42903,28 @@
42809 *pnRight = iOut;
42810 memcpy(aLeft, aTmp, sizeof(aTmp[0])*iOut);
42811 }
42812
42813 /*
42814 ** Sort the elements in list aList, removing any duplicates.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42815 */
42816 static void walMergesort(
42817 u32 *aContent, /* Pages in wal */
42818 ht_slot *aBuffer, /* Buffer of at least *pnList items to use */
42819 ht_slot *aList, /* IN/OUT: List to sort */
42820 int *pnList /* IN/OUT: Number of elements in aList[] */
42821 ){
42822 struct Sublist {
@@ -42877,10 +42985,11 @@
42877 }
42878
42879 /*
42880 ** Construct a WalInterator object that can be used to loop over all
42881 ** pages in the WAL in ascending order. The caller must hold the checkpoint
 
42882 **
42883 ** On success, make *pp point to the newly allocated WalInterator object
42884 ** return SQLITE_OK. Otherwise, return an error code. If this routine
42885 ** returns an error, the value of *pp is undefined.
42886 **
@@ -43011,11 +43120,12 @@
43011 volatile WalCkptInfo *pInfo; /* The checkpoint status information */
43012
43013 szPage = (pWal->hdr.szPage&0xfe00) + ((pWal->hdr.szPage&0x0001)<<16);
43014 testcase( szPage<=32768 );
43015 testcase( szPage>=65536 );
43016 if( pWal->hdr.mxFrame==0 ) return SQLITE_OK;
 
43017
43018 /* Allocate the iterator */
43019 rc = walIteratorInit(pWal, &pIter);
43020 if( rc!=SQLITE_OK ){
43021 return rc;
@@ -43033,11 +43143,10 @@
43033 ** overwrite database pages that are in use by active readers and thus
43034 ** cannot be backfilled from the WAL.
43035 */
43036 mxSafeFrame = pWal->hdr.mxFrame;
43037 mxPage = pWal->hdr.nPage;
43038 pInfo = walCkptInfo(pWal);
43039 for(i=1; i<WAL_NREADER; i++){
43040 u32 y = pInfo->aReadMark[i];
43041 if( mxSafeFrame>=y ){
43042 assert( y<=pWal->hdr.mxFrame );
43043 rc = walLockExclusive(pWal, WAL_READ_LOCK(i), 1);
@@ -55556,11 +55665,11 @@
55556 u8 opcode = pOp->opcode;
55557
55558 pOp->opflags = sqlite3OpcodeProperty[opcode];
55559 if( opcode==OP_Function || opcode==OP_AggStep ){
55560 if( pOp->p5>nMaxArgs ) nMaxArgs = pOp->p5;
55561 }else if( opcode==OP_Transaction && pOp->p2!=0 ){
55562 p->readOnly = 0;
55563 #ifndef SQLITE_OMIT_VIRTUALTABLE
55564 }else if( opcode==OP_VUpdate ){
55565 if( pOp->p2>nMaxArgs ) nMaxArgs = pOp->p2;
55566 }else if( opcode==OP_VFilter ){
@@ -80921,13 +81030,13 @@
80921 if( caseSensitive ){
80922 pInfo = (struct compareInfo*)&likeInfoAlt;
80923 }else{
80924 pInfo = (struct compareInfo*)&likeInfoNorm;
80925 }
80926 sqlite3CreateFunc(db, "like", 2, SQLITE_ANY, pInfo, likeFunc, 0, 0, 0);
80927 sqlite3CreateFunc(db, "like", 3, SQLITE_ANY, pInfo, likeFunc, 0, 0, 0);
80928 sqlite3CreateFunc(db, "glob", 2, SQLITE_ANY,
80929 (struct compareInfo*)&globInfo, likeFunc, 0, 0, 0);
80930 setLikeOptFlag(db, "glob", SQLITE_FUNC_LIKE | SQLITE_FUNC_CASE);
80931 setLikeOptFlag(db, "like",
80932 caseSensitive ? (SQLITE_FUNC_LIKE | SQLITE_FUNC_CASE) : SQLITE_FUNC_LIKE);
80933 }
@@ -97673,14 +97782,13 @@
97673 Parse *pParse,
97674 Expr *pExpr,
97675 u8 aff,
97676 sqlite3_value **pp
97677 ){
97678 /* The evalConstExpr() function will have already converted any TK_VARIABLE
97679 ** expression involved in an comparison into a TK_REGISTER. */
97680 assert( pExpr->op!=TK_VARIABLE );
97681 if( pExpr->op==TK_REGISTER && pExpr->op2==TK_VARIABLE ){
97682 int iVar = pExpr->iColumn;
97683 sqlite3VdbeSetVarmask(pParse->pVdbe, iVar); /* IMP: R-23257-02778 */
97684 *pp = sqlite3VdbeGetValue(pParse->pReprepare, iVar, aff);
97685 return SQLITE_OK;
97686 }
@@ -106470,10 +106578,13 @@
106470 | SQLITE_LoadExtension
106471 #endif
106472 #if SQLITE_DEFAULT_RECURSIVE_TRIGGERS
106473 | SQLITE_RecTriggers
106474 #endif
 
 
 
106475 ;
106476 sqlite3HashInit(&db->aCollSeq);
106477 #ifndef SQLITE_OMIT_VIRTUALTABLE
106478 sqlite3HashInit(&db->aModule);
106479 #endif
@@ -111307,13 +111418,20 @@
111307 int iCol /* Column of requested pos-list */
111308 ){
111309 assert( pExpr->isLoaded );
111310 if( pExpr->aDoclist ){
111311 char *pEnd = &pExpr->aDoclist[pExpr->nDoclist];
111312 char *pCsr = pExpr->pCurrent;
111313
 
 
 
 
 
 
111314 assert( pCsr );
 
111315 while( pCsr<pEnd ){
111316 if( pExpr->iCurrent<iDocid ){
111317 fts3PoslistCopy(0, &pCsr);
111318 if( pCsr<pEnd ){
111319 fts3GetDeltaVarint(&pCsr, &pExpr->iCurrent);
@@ -117513,11 +117631,11 @@
117513 /*
117514 ** This is an fts3ExprIterate() callback used while loading the doclists
117515 ** for each phrase into Fts3Expr.aDoclist[]/nDoclist. See also
117516 ** fts3ExprLoadDoclists().
117517 */
117518 static int fts3ExprLoadDoclistsCb1(Fts3Expr *pExpr, int iPhrase, void *ctx){
117519 int rc = SQLITE_OK;
117520 LoadDoclistCtx *p = (LoadDoclistCtx *)ctx;
117521
117522 UNUSED_PARAMETER(iPhrase);
117523
@@ -117533,26 +117651,10 @@
117533 }
117534
117535 return rc;
117536 }
117537
117538 /*
117539 ** This is an fts3ExprIterate() callback used while loading the doclists
117540 ** for each phrase into Fts3Expr.aDoclist[]/nDoclist. See also
117541 ** fts3ExprLoadDoclists().
117542 */
117543 static int fts3ExprLoadDoclistsCb2(Fts3Expr *pExpr, int iPhrase, void *ctx){
117544 UNUSED_PARAMETER(iPhrase);
117545 UNUSED_PARAMETER(ctx);
117546 if( pExpr->aDoclist ){
117547 pExpr->pCurrent = pExpr->aDoclist;
117548 pExpr->iCurrent = 0;
117549 pExpr->pCurrent += sqlite3Fts3GetVarint(pExpr->pCurrent, &pExpr->iCurrent);
117550 }
117551 return SQLITE_OK;
117552 }
117553
117554 /*
117555 ** Load the doclists for each phrase in the query associated with FTS3 cursor
117556 ** pCsr.
117557 **
117558 ** If pnPhrase is not NULL, then *pnPhrase is set to the number of matchable
@@ -117567,14 +117669,11 @@
117567 int *pnToken /* OUT: Number of tokens in query */
117568 ){
117569 int rc; /* Return Code */
117570 LoadDoclistCtx sCtx = {0,0,0}; /* Context for fts3ExprIterate() */
117571 sCtx.pCsr = pCsr;
117572 rc = fts3ExprIterate(pCsr->pExpr, fts3ExprLoadDoclistsCb1, (void *)&sCtx);
117573 if( rc==SQLITE_OK ){
117574 (void)fts3ExprIterate(pCsr->pExpr, fts3ExprLoadDoclistsCb2, 0);
117575 }
117576 if( pnPhrase ) *pnPhrase = sCtx.nPhrase;
117577 if( pnToken ) *pnToken = sCtx.nToken;
117578 return rc;
117579 }
117580
117581
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -650,11 +650,11 @@
650 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
651 ** [sqlite_version()] and [sqlite_source_id()].
652 */
653 #define SQLITE_VERSION "3.7.4"
654 #define SQLITE_VERSION_NUMBER 3007004
655 #define SQLITE_SOURCE_ID "2010-12-21 21:28:38 b0888047bb6d9ac55e29b9224df2ff650728bb78"
656
657 /*
658 ** CAPI3REF: Run-Time Library Version Numbers
659 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
660 **
@@ -1256,10 +1256,15 @@
1256 ** by the user. The fourth argument to [sqlite3_file_control()] should
1257 ** point to an integer (type int) containing the new chunk-size to use
1258 ** for the nominated database. Allocating database file space in large
1259 ** chunks (say 1MB at a time), may reduce file-system fragmentation and
1260 ** improve performance on some systems.
1261 **
1262 ** The [SQLITE_FCNTL_FILE_POINTER] opcode is used to obtain a pointer
1263 ** to the [sqlite3_file] object associated with a particular database
1264 ** connection. See the [sqlite3_file_control()] documentation for
1265 ** additional information.
1266 */
1267 #define SQLITE_FCNTL_LOCKSTATE 1
1268 #define SQLITE_GET_LOCKPROXYFILE 2
1269 #define SQLITE_SET_LOCKPROXYFILE 3
1270 #define SQLITE_LAST_ERRNO 4
@@ -3191,18 +3196,35 @@
3196 SQLITE_API const char *sqlite3_sql(sqlite3_stmt *pStmt);
3197
3198 /*
3199 ** CAPI3REF: Determine If An SQL Statement Writes The Database
3200 **
3201 ** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if
3202 ** and only if the [prepared statement] X is makes no direct changes to
3203 ** the content of the database file.
3204 **
3205 ** Note that [application-defined SQL functions] or
3206 ** [virtual tables] might change the database indirectly as a side effect.
3207 ** ^(For example, if an application defines a function "eval()" that
3208 ** calls [sqlite3_exec()], then the following SQL statement would
3209 ** change the database file through side-effects:
3210 **
3211 ** <blockquote><pre>
3212 ** SELECT eval('DELETE FROM t1') FROM t2;
3213 ** </pre></blockquote>
3214 **
3215 ** But because the [SELECT] statement does not change the database file
3216 ** directly, sqlite3_stmt_readonly() would still return true.)^
3217 **
3218 ** ^Transaction control statements such as [BEGIN], [COMMIT], [ROLLBACK],
3219 ** [SAVEPOINT], and [RELEASE] cause sqlite3_stmt_readonly() to return true,
3220 ** since the statements themselves do not actually modify the database but
3221 ** rather they control the timing of when other statements modify the
3222 ** database. ^The [ATTACH] and [DETACH] statements also cause
3223 ** sqlite3_stmt_readonly() to return true since, while those statements
3224 ** change the configuration of a database connection, they do not make
3225 ** changes to the content of the database files on disk.
3226 */
3227 SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
3228
3229 /*
3230 ** CAPI3REF: Dynamically Typed Value Object
@@ -5927,11 +5949,12 @@
5949 ** internal equivalents). Only the value returned in the
5950 ** *pHighwater parameter to [sqlite3_status()] is of interest.
5951 ** The value written into the *pCurrent parameter is undefined.</dd>)^
5952 **
5953 ** ^(<dt>SQLITE_STATUS_MALLOC_COUNT</dt>
5954 ** <dd>This parameter records the number of separate memory allocations
5955 ** currently checked out.</dd>)^
5956 **
5957 ** ^(<dt>SQLITE_STATUS_PAGECACHE_USED</dt>
5958 ** <dd>This parameter returns the number of pages used out of the
5959 ** [pagecache memory allocator] that was configured using
5960 ** [SQLITE_CONFIG_PAGECACHE]. The
@@ -6032,10 +6055,32 @@
6055 **
6056 ** <dl>
6057 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
6058 ** <dd>This parameter returns the number of lookaside memory slots currently
6059 ** checked out.</dd>)^
6060 **
6061 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_HIT</dt>
6062 ** <dd>This parameter returns the number malloc attempts that were
6063 ** satisfied using lookaside memory. Only the high-water value is meaningful;
6064 ** the current value is always zero.
6065 ** checked out.</dd>)^
6066 **
6067 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE</dt>
6068 ** <dd>This parameter returns the number malloc attempts that might have
6069 ** been satisfied using lookaside memory but failed due to the amount of
6070 ** memory requested being larger than the lookaside slot size.
6071 ** Only the high-water value is meaningful;
6072 ** the current value is always zero.
6073 ** checked out.</dd>)^
6074 **
6075 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL</dt>
6076 ** <dd>This parameter returns the number malloc attempts that might have
6077 ** been satisfied using lookaside memory but failed due to all lookaside
6078 ** memory already being in use.
6079 ** Only the high-water value is meaningful;
6080 ** the current value is always zero.
6081 ** checked out.</dd>)^
6082 **
6083 ** ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt>
6084 ** <dd>This parameter returns the approximate number of of bytes of heap
6085 ** memory used by all pager caches associated with the database connection.)^
6086 ** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
@@ -6055,15 +6100,18 @@
6100 ** the database connection.)^
6101 ** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0.
6102 ** </dd>
6103 ** </dl>
6104 */
6105 #define SQLITE_DBSTATUS_LOOKASIDE_USED 0
6106 #define SQLITE_DBSTATUS_CACHE_USED 1
6107 #define SQLITE_DBSTATUS_SCHEMA_USED 2
6108 #define SQLITE_DBSTATUS_STMT_USED 3
6109 #define SQLITE_DBSTATUS_LOOKASIDE_HIT 4
6110 #define SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE 5
6111 #define SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL 6
6112 #define SQLITE_DBSTATUS_MAX 6 /* Largest defined DBSTATUS */
6113
6114
6115 /*
6116 ** CAPI3REF: Prepared Statement Status
6117 **
@@ -6307,15 +6355,16 @@
6355 ** It is useful either for creating backups of databases or
6356 ** for copying in-memory databases to or from persistent files.
6357 **
6358 ** See Also: [Using the SQLite Online Backup API]
6359 **
6360 ** ^SQLite holds a write transaction open on the destination database file
6361 ** for the duration of the backup operation.
6362 ** ^The source database is read-locked only while it is being read;
6363 ** it is not locked continuously for the entire backup operation.
6364 ** ^Thus, the backup may be performed on a live source database without
6365 ** preventing other database connections from
6366 ** reading or writing to the source database while the backup is underway.
6367 **
6368 ** ^(To perform a backup operation:
6369 ** <ol>
6370 ** <li><b>sqlite3_backup_init()</b> is called once to initialize the
@@ -6338,15 +6387,15 @@
6387 ** an [ATTACH] statement for an attached database.
6388 ** ^The S and M arguments passed to
6389 ** sqlite3_backup_init(D,N,S,M) identify the [database connection]
6390 ** and database name of the source database, respectively.
6391 ** ^The source and destination [database connections] (parameters S and D)
6392 ** must be different or else sqlite3_backup_init(D,N,S,M) will fail with
6393 ** an error.
6394 **
6395 ** ^If an error occurs within sqlite3_backup_init(D,N,S,M), then NULL is
6396 ** returned and an error code and error message are stored in the
6397 ** destination [database connection] D.
6398 ** ^The error code and message for the failed call to sqlite3_backup_init()
6399 ** can be retrieved using the [sqlite3_errcode()], [sqlite3_errmsg()], and/or
6400 ** [sqlite3_errmsg16()] functions.
6401 ** ^A successful call to sqlite3_backup_init() returns a pointer to an
@@ -6359,11 +6408,11 @@
6408 **
6409 ** ^Function sqlite3_backup_step(B,N) will copy up to N pages between
6410 ** the source and destination databases specified by [sqlite3_backup] object B.
6411 ** ^If N is negative, all remaining source pages are copied.
6412 ** ^If sqlite3_backup_step(B,N) successfully copies N pages and there
6413 ** are still more pages to be copied, then the function returns [SQLITE_OK].
6414 ** ^If sqlite3_backup_step(B,N) successfully finishes copying all pages
6415 ** from source to destination, then it returns [SQLITE_DONE].
6416 ** ^If an error occurs while running sqlite3_backup_step(B,N),
6417 ** then an [error code] is returned. ^As well as [SQLITE_OK] and
6418 ** [SQLITE_DONE], a call to sqlite3_backup_step() may return [SQLITE_READONLY],
@@ -6373,11 +6422,11 @@
6422 ** ^(The sqlite3_backup_step() might return [SQLITE_READONLY] if
6423 ** <ol>
6424 ** <li> the destination database was opened read-only, or
6425 ** <li> the destination database is using write-ahead-log journaling
6426 ** and the destination and source page sizes differ, or
6427 ** <li> the destination database is an in-memory database and the
6428 ** destination and source page sizes differ.
6429 ** </ol>)^
6430 **
6431 ** ^If sqlite3_backup_step() cannot obtain a required file-system lock, then
6432 ** the [sqlite3_busy_handler | busy-handler function]
@@ -6704,11 +6753,12 @@
6753 **
6754 ** ^The [wal_autocheckpoint pragma] can be used to invoke this interface
6755 ** from SQL.
6756 **
6757 ** ^Every new [database connection] defaults to having the auto-checkpoint
6758 ** enabled with a threshold of 1000 or [SQLITE_DEFAULT_WAL_AUTOCHECKPOINT]
6759 ** pages. The use of this interface
6760 ** is only necessary if the default setting is found to be suboptimal
6761 ** for a particular application.
6762 */
6763 SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
6764
@@ -8875,10 +8925,11 @@
8925 u16 sz; /* Size of each buffer in bytes */
8926 u8 bEnabled; /* False to disable new lookaside allocations */
8927 u8 bMalloced; /* True if pStart obtained from sqlite3_malloc() */
8928 int nOut; /* Number of buffers currently checked out */
8929 int mxOut; /* Highwater mark for nOut */
8930 int anStat[3]; /* 0: hits. 1: size misses. 2: full misses */
8931 LookasideSlot *pFree; /* List of available buffers */
8932 void *pStart; /* First byte of available memory space */
8933 void *pEnd; /* First byte past end of available space */
8934 };
8935 struct LookasideSlot {
@@ -12506,10 +12557,26 @@
12557 if( resetFlag ){
12558 db->lookaside.mxOut = db->lookaside.nOut;
12559 }
12560 break;
12561 }
12562
12563 case SQLITE_DBSTATUS_LOOKASIDE_HIT:
12564 case SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE:
12565 case SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL: {
12566 testcase( op==SQLITE_DBSTATUS_LOOKASIDE_HIT );
12567 testcase( op==SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE );
12568 testcase( op==SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL );
12569 assert( (op-SQLITE_DBSTATUS_LOOKASIDE_HIT)>=0 );
12570 assert( (op-SQLITE_DBSTATUS_LOOKASIDE_HIT)<3 );
12571 *pCurrent = 0;
12572 *pHighwater = db->lookaside.anStat[op - SQLITE_DBSTATUS_LOOKASIDE_HIT];
12573 if( resetFlag ){
12574 db->lookaside.anStat[op - SQLITE_DBSTATUS_LOOKASIDE_HIT] = 0;
12575 }
12576 break;
12577 }
12578
12579 /*
12580 ** Return an approximation for the amount of memory currently used
12581 ** by all pagers associated with the given database connection. The
12582 ** highwater mark is meaningless and is returned as zero.
@@ -18068,18 +18135,24 @@
18135 if( db ){
18136 LookasideSlot *pBuf;
18137 if( db->mallocFailed ){
18138 return 0;
18139 }
18140 if( db->lookaside.bEnabled ){
18141 if( n>db->lookaside.sz ){
18142 db->lookaside.anStat[1]++;
18143 }else if( (pBuf = db->lookaside.pFree)==0 ){
18144 db->lookaside.anStat[2]++;
18145 }else{
18146 db->lookaside.pFree = pBuf->pNext;
18147 db->lookaside.nOut++;
18148 db->lookaside.anStat[0]++;
18149 if( db->lookaside.nOut>db->lookaside.mxOut ){
18150 db->lookaside.mxOut = db->lookaside.nOut;
18151 }
18152 return (void*)pBuf;
18153 }
18154 }
18155 }
18156 #else
18157 if( db && db->mallocFailed ){
18158 return 0;
@@ -28391,22 +28464,23 @@
28464
28465 /* get the host ID via gethostuuid(), pHostID must point to PROXY_HOSTIDLEN
28466 ** bytes of writable memory.
28467 */
28468 static int proxyGetHostID(unsigned char *pHostID, int *pError){
 
 
28469 assert(PROXY_HOSTIDLEN == sizeof(uuid_t));
28470 memset(pHostID, 0, PROXY_HOSTIDLEN);
28471 #if defined(__MAX_OS_X_VERSION_MIN_REQUIRED)\
28472 && __MAC_OS_X_VERSION_MIN_REQUIRED<1050
28473 {
28474 static const struct timespec timeout = {1, 0}; /* 1 sec timeout */
28475 if( gethostuuid(pHostID, &timeout) ){
28476 int err = errno;
28477 if( pError ){
28478 *pError = err;
28479 }
28480 return SQLITE_IOERR;
28481 }
 
28482 }
28483 #endif
28484 #ifdef SQLITE_TEST
28485 /* simulate multiple hosts by creating unique hostid file paths */
28486 if( sqlite3_hostid_num != 0){
@@ -41896,18 +41970,18 @@
41970 **
41971 ** This functionality is used by the checkpoint code (see walCheckpoint()).
41972 */
41973 struct WalIterator {
41974 int iPrior; /* Last result returned from the iterator */
41975 int nSegment; /* Number of entries in aSegment[] */
41976 struct WalSegment {
41977 int iNext; /* Next slot in aIndex[] not yet returned */
41978 ht_slot *aIndex; /* i0, i1, i2... such that aPgno[iN] ascend */
41979 u32 *aPgno; /* Array of page numbers. */
41980 int nEntry; /* Nr. of entries in aPgno[] and aIndex[] */
41981 int iZero; /* Frame number associated with aPgno[0] */
41982 } aSegment[1]; /* One for every 32KB page in the wal-index */
41983 };
41984
41985 /*
41986 ** Define the parameters of the hash tables in the wal-index file. There
41987 ** is a hash-table following every HASHTABLE_NPAGE page numbers in the
@@ -42767,13 +42841,33 @@
42841 return (iRet==0xFFFFFFFF);
42842 }
42843
42844 /*
42845 ** This function merges two sorted lists into a single sorted list.
42846 **
42847 ** aLeft[] and aRight[] are arrays of indices. The sort key is
42848 ** aContent[aLeft[]] and aContent[aRight[]]. Upon entry, the following
42849 ** is guaranteed for all J<K:
42850 **
42851 ** aContent[aLeft[J]] < aContent[aLeft[K]]
42852 ** aContent[aRight[J]] < aContent[aRight[K]]
42853 **
42854 ** This routine overwrites aRight[] with a new (probably longer) sequence
42855 ** of indices such that the aRight[] contains every index that appears in
42856 ** either aLeft[] or the old aRight[] and such that the second condition
42857 ** above is still met.
42858 **
42859 ** The aContent[aLeft[X]] values will be unique for all X. And the
42860 ** aContent[aRight[X]] values will be unique too. But there might be
42861 ** one or more combinations of X and Y such that
42862 **
42863 ** aLeft[X]!=aRight[Y] && aContent[aLeft[X]] == aContent[aRight[Y]]
42864 **
42865 ** When that happens, omit the aLeft[X] and use the aRight[Y] index.
42866 */
42867 static void walMerge(
42868 const u32 *aContent, /* Pages in wal - keys for the sort */
42869 ht_slot *aLeft, /* IN: Left hand input list */
42870 int nLeft, /* IN: Elements in array *paLeft */
42871 ht_slot **paRight, /* IN/OUT: Right hand input list */
42872 int *pnRight, /* IN/OUT: Elements in *paRight */
42873 ht_slot *aTmp /* Temporary buffer */
@@ -42809,14 +42903,28 @@
42903 *pnRight = iOut;
42904 memcpy(aLeft, aTmp, sizeof(aTmp[0])*iOut);
42905 }
42906
42907 /*
42908 ** Sort the elements in list aList using aContent[] as the sort key.
42909 ** Remove elements with duplicate keys, preferring to keep the
42910 ** larger aList[] values.
42911 **
42912 ** The aList[] entries are indices into aContent[]. The values in
42913 ** aList[] are to be sorted so that for all J<K:
42914 **
42915 ** aContent[aList[J]] < aContent[aList[K]]
42916 **
42917 ** For any X and Y such that
42918 **
42919 ** aContent[aList[X]] == aContent[aList[Y]]
42920 **
42921 ** Keep the larger of the two values aList[X] and aList[Y] and discard
42922 ** the smaller.
42923 */
42924 static void walMergesort(
42925 const u32 *aContent, /* Pages in wal */
42926 ht_slot *aBuffer, /* Buffer of at least *pnList items to use */
42927 ht_slot *aList, /* IN/OUT: List to sort */
42928 int *pnList /* IN/OUT: Number of elements in aList[] */
42929 ){
42930 struct Sublist {
@@ -42877,10 +42985,11 @@
42985 }
42986
42987 /*
42988 ** Construct a WalInterator object that can be used to loop over all
42989 ** pages in the WAL in ascending order. The caller must hold the checkpoint
42990 ** lock.
42991 **
42992 ** On success, make *pp point to the newly allocated WalInterator object
42993 ** return SQLITE_OK. Otherwise, return an error code. If this routine
42994 ** returns an error, the value of *pp is undefined.
42995 **
@@ -43011,11 +43120,12 @@
43120 volatile WalCkptInfo *pInfo; /* The checkpoint status information */
43121
43122 szPage = (pWal->hdr.szPage&0xfe00) + ((pWal->hdr.szPage&0x0001)<<16);
43123 testcase( szPage<=32768 );
43124 testcase( szPage>=65536 );
43125 pInfo = walCkptInfo(pWal);
43126 if( pInfo->nBackfill>=pWal->hdr.mxFrame ) return SQLITE_OK;
43127
43128 /* Allocate the iterator */
43129 rc = walIteratorInit(pWal, &pIter);
43130 if( rc!=SQLITE_OK ){
43131 return rc;
@@ -43033,11 +43143,10 @@
43143 ** overwrite database pages that are in use by active readers and thus
43144 ** cannot be backfilled from the WAL.
43145 */
43146 mxSafeFrame = pWal->hdr.mxFrame;
43147 mxPage = pWal->hdr.nPage;
 
43148 for(i=1; i<WAL_NREADER; i++){
43149 u32 y = pInfo->aReadMark[i];
43150 if( mxSafeFrame>=y ){
43151 assert( y<=pWal->hdr.mxFrame );
43152 rc = walLockExclusive(pWal, WAL_READ_LOCK(i), 1);
@@ -55556,11 +55665,11 @@
55665 u8 opcode = pOp->opcode;
55666
55667 pOp->opflags = sqlite3OpcodeProperty[opcode];
55668 if( opcode==OP_Function || opcode==OP_AggStep ){
55669 if( pOp->p5>nMaxArgs ) nMaxArgs = pOp->p5;
55670 }else if( (opcode==OP_Transaction && pOp->p2!=0) || opcode==OP_Vacuum ){
55671 p->readOnly = 0;
55672 #ifndef SQLITE_OMIT_VIRTUALTABLE
55673 }else if( opcode==OP_VUpdate ){
55674 if( pOp->p2>nMaxArgs ) nMaxArgs = pOp->p2;
55675 }else if( opcode==OP_VFilter ){
@@ -80921,13 +81030,13 @@
81030 if( caseSensitive ){
81031 pInfo = (struct compareInfo*)&likeInfoAlt;
81032 }else{
81033 pInfo = (struct compareInfo*)&likeInfoNorm;
81034 }
81035 sqlite3CreateFunc(db, "like", 2, SQLITE_UTF8, pInfo, likeFunc, 0, 0, 0);
81036 sqlite3CreateFunc(db, "like", 3, SQLITE_UTF8, pInfo, likeFunc, 0, 0, 0);
81037 sqlite3CreateFunc(db, "glob", 2, SQLITE_UTF8,
81038 (struct compareInfo*)&globInfo, likeFunc, 0, 0, 0);
81039 setLikeOptFlag(db, "glob", SQLITE_FUNC_LIKE | SQLITE_FUNC_CASE);
81040 setLikeOptFlag(db, "like",
81041 caseSensitive ? (SQLITE_FUNC_LIKE | SQLITE_FUNC_CASE) : SQLITE_FUNC_LIKE);
81042 }
@@ -97673,14 +97782,13 @@
97782 Parse *pParse,
97783 Expr *pExpr,
97784 u8 aff,
97785 sqlite3_value **pp
97786 ){
97787 if( pExpr->op==TK_VARIABLE
97788 || (pExpr->op==TK_REGISTER && pExpr->op2==TK_VARIABLE)
97789 ){
 
97790 int iVar = pExpr->iColumn;
97791 sqlite3VdbeSetVarmask(pParse->pVdbe, iVar); /* IMP: R-23257-02778 */
97792 *pp = sqlite3VdbeGetValue(pParse->pReprepare, iVar, aff);
97793 return SQLITE_OK;
97794 }
@@ -106470,10 +106578,13 @@
106578 | SQLITE_LoadExtension
106579 #endif
106580 #if SQLITE_DEFAULT_RECURSIVE_TRIGGERS
106581 | SQLITE_RecTriggers
106582 #endif
106583 #if defined(SQLITE_DEFAULT_FOREIGN_KEYS) && SQLITE_DEFAULT_FOREIGN_KEYS
106584 | SQLITE_ForeignKeys
106585 #endif
106586 ;
106587 sqlite3HashInit(&db->aCollSeq);
106588 #ifndef SQLITE_OMIT_VIRTUALTABLE
106589 sqlite3HashInit(&db->aModule);
106590 #endif
@@ -111307,13 +111418,20 @@
111418 int iCol /* Column of requested pos-list */
111419 ){
111420 assert( pExpr->isLoaded );
111421 if( pExpr->aDoclist ){
111422 char *pEnd = &pExpr->aDoclist[pExpr->nDoclist];
111423 char *pCsr;
111424
111425 if( pExpr->pCurrent==0 ){
111426 pExpr->pCurrent = pExpr->aDoclist;
111427 pExpr->iCurrent = 0;
111428 pExpr->pCurrent += sqlite3Fts3GetVarint(pExpr->pCurrent,&pExpr->iCurrent);
111429 }
111430 pCsr = pExpr->pCurrent;
111431 assert( pCsr );
111432
111433 while( pCsr<pEnd ){
111434 if( pExpr->iCurrent<iDocid ){
111435 fts3PoslistCopy(0, &pCsr);
111436 if( pCsr<pEnd ){
111437 fts3GetDeltaVarint(&pCsr, &pExpr->iCurrent);
@@ -117513,11 +117631,11 @@
117631 /*
117632 ** This is an fts3ExprIterate() callback used while loading the doclists
117633 ** for each phrase into Fts3Expr.aDoclist[]/nDoclist. See also
117634 ** fts3ExprLoadDoclists().
117635 */
117636 static int fts3ExprLoadDoclistsCb(Fts3Expr *pExpr, int iPhrase, void *ctx){
117637 int rc = SQLITE_OK;
117638 LoadDoclistCtx *p = (LoadDoclistCtx *)ctx;
117639
117640 UNUSED_PARAMETER(iPhrase);
117641
@@ -117533,26 +117651,10 @@
117651 }
117652
117653 return rc;
117654 }
117655
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
117656 /*
117657 ** Load the doclists for each phrase in the query associated with FTS3 cursor
117658 ** pCsr.
117659 **
117660 ** If pnPhrase is not NULL, then *pnPhrase is set to the number of matchable
@@ -117567,14 +117669,11 @@
117669 int *pnToken /* OUT: Number of tokens in query */
117670 ){
117671 int rc; /* Return Code */
117672 LoadDoclistCtx sCtx = {0,0,0}; /* Context for fts3ExprIterate() */
117673 sCtx.pCsr = pCsr;
117674 rc = fts3ExprIterate(pCsr->pExpr, fts3ExprLoadDoclistsCb, (void *)&sCtx);
 
 
 
117675 if( pnPhrase ) *pnPhrase = sCtx.nPhrase;
117676 if( pnToken ) *pnToken = sCtx.nToken;
117677 return rc;
117678 }
117679
117680
+75 -25
--- 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.7.4"
111111
#define SQLITE_VERSION_NUMBER 3007004
112
-#define SQLITE_SOURCE_ID "2010-12-06 21:09:59 fabcb6b95e1d4059d1e6c6183f65846f6cbd5749"
112
+#define SQLITE_SOURCE_ID "2010-12-21 21:28:38 b0888047bb6d9ac55e29b9224df2ff650728bb78"
113113
114114
/*
115115
** CAPI3REF: Run-Time Library Version Numbers
116116
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117117
**
@@ -713,10 +713,15 @@
713713
** by the user. The fourth argument to [sqlite3_file_control()] should
714714
** point to an integer (type int) containing the new chunk-size to use
715715
** for the nominated database. Allocating database file space in large
716716
** chunks (say 1MB at a time), may reduce file-system fragmentation and
717717
** improve performance on some systems.
718
+**
719
+** The [SQLITE_FCNTL_FILE_POINTER] opcode is used to obtain a pointer
720
+** to the [sqlite3_file] object associated with a particular database
721
+** connection. See the [sqlite3_file_control()] documentation for
722
+** additional information.
718723
*/
719724
#define SQLITE_FCNTL_LOCKSTATE 1
720725
#define SQLITE_GET_LOCKPROXYFILE 2
721726
#define SQLITE_SET_LOCKPROXYFILE 3
722727
#define SQLITE_LAST_ERRNO 4
@@ -2648,18 +2653,35 @@
26482653
SQLITE_API const char *sqlite3_sql(sqlite3_stmt *pStmt);
26492654
26502655
/*
26512656
** CAPI3REF: Determine If An SQL Statement Writes The Database
26522657
**
2653
-** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if
2654
-** the [prepared statement] X is [SELECT] statement and false (zero) if
2655
-** X is an [INSERT], [UPDATE], [DELETE], CREATE, DROP, [ANALYZE],
2656
-** [ALTER], or [REINDEX] statement.
2657
-** If X is a NULL pointer or any other kind of statement, including but
2658
-** not limited to [ATTACH], [DETACH], [COMMIT], [ROLLBACK], [RELEASE],
2659
-** [SAVEPOINT], [PRAGMA], or [VACUUM] the result of sqlite3_stmt_readonly(X) is
2660
-** undefined.
2658
+** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if
2659
+** and only if the [prepared statement] X is makes no direct changes to
2660
+** the content of the database file.
2661
+**
2662
+** Note that [application-defined SQL functions] or
2663
+** [virtual tables] might change the database indirectly as a side effect.
2664
+** ^(For example, if an application defines a function "eval()" that
2665
+** calls [sqlite3_exec()], then the following SQL statement would
2666
+** change the database file through side-effects:
2667
+**
2668
+** <blockquote><pre>
2669
+** SELECT eval('DELETE FROM t1') FROM t2;
2670
+** </pre></blockquote>
2671
+**
2672
+** But because the [SELECT] statement does not change the database file
2673
+** directly, sqlite3_stmt_readonly() would still return true.)^
2674
+**
2675
+** ^Transaction control statements such as [BEGIN], [COMMIT], [ROLLBACK],
2676
+** [SAVEPOINT], and [RELEASE] cause sqlite3_stmt_readonly() to return true,
2677
+** since the statements themselves do not actually modify the database but
2678
+** rather they control the timing of when other statements modify the
2679
+** database. ^The [ATTACH] and [DETACH] statements also cause
2680
+** sqlite3_stmt_readonly() to return true since, while those statements
2681
+** change the configuration of a database connection, they do not make
2682
+** changes to the content of the database files on disk.
26612683
*/
26622684
SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
26632685
26642686
/*
26652687
** CAPI3REF: Dynamically Typed Value Object
@@ -5384,11 +5406,12 @@
53845406
** internal equivalents). Only the value returned in the
53855407
** *pHighwater parameter to [sqlite3_status()] is of interest.
53865408
** The value written into the *pCurrent parameter is undefined.</dd>)^
53875409
**
53885410
** ^(<dt>SQLITE_STATUS_MALLOC_COUNT</dt>
5389
-** <dd>This parameter records the number of separate memory allocations.</dd>)^
5411
+** <dd>This parameter records the number of separate memory allocations
5412
+** currently checked out.</dd>)^
53905413
**
53915414
** ^(<dt>SQLITE_STATUS_PAGECACHE_USED</dt>
53925415
** <dd>This parameter returns the number of pages used out of the
53935416
** [pagecache memory allocator] that was configured using
53945417
** [SQLITE_CONFIG_PAGECACHE]. The
@@ -5489,10 +5512,32 @@
54895512
**
54905513
** <dl>
54915514
** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
54925515
** <dd>This parameter returns the number of lookaside memory slots currently
54935516
** checked out.</dd>)^
5517
+**
5518
+** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_HIT</dt>
5519
+** <dd>This parameter returns the number malloc attempts that were
5520
+** satisfied using lookaside memory. Only the high-water value is meaningful;
5521
+** the current value is always zero.
5522
+** checked out.</dd>)^
5523
+**
5524
+** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE</dt>
5525
+** <dd>This parameter returns the number malloc attempts that might have
5526
+** been satisfied using lookaside memory but failed due to the amount of
5527
+** memory requested being larger than the lookaside slot size.
5528
+** Only the high-water value is meaningful;
5529
+** the current value is always zero.
5530
+** checked out.</dd>)^
5531
+**
5532
+** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL</dt>
5533
+** <dd>This parameter returns the number malloc attempts that might have
5534
+** been satisfied using lookaside memory but failed due to all lookaside
5535
+** memory already being in use.
5536
+** Only the high-water value is meaningful;
5537
+** the current value is always zero.
5538
+** checked out.</dd>)^
54945539
**
54955540
** ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt>
54965541
** <dd>This parameter returns the approximate number of of bytes of heap
54975542
** memory used by all pager caches associated with the database connection.)^
54985543
** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
@@ -5512,15 +5557,18 @@
55125557
** the database connection.)^
55135558
** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0.
55145559
** </dd>
55155560
** </dl>
55165561
*/
5517
-#define SQLITE_DBSTATUS_LOOKASIDE_USED 0
5518
-#define SQLITE_DBSTATUS_CACHE_USED 1
5519
-#define SQLITE_DBSTATUS_SCHEMA_USED 2
5520
-#define SQLITE_DBSTATUS_STMT_USED 3
5521
-#define SQLITE_DBSTATUS_MAX 3 /* Largest defined DBSTATUS */
5562
+#define SQLITE_DBSTATUS_LOOKASIDE_USED 0
5563
+#define SQLITE_DBSTATUS_CACHE_USED 1
5564
+#define SQLITE_DBSTATUS_SCHEMA_USED 2
5565
+#define SQLITE_DBSTATUS_STMT_USED 3
5566
+#define SQLITE_DBSTATUS_LOOKASIDE_HIT 4
5567
+#define SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE 5
5568
+#define SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL 6
5569
+#define SQLITE_DBSTATUS_MAX 6 /* Largest defined DBSTATUS */
55225570
55235571
55245572
/*
55255573
** CAPI3REF: Prepared Statement Status
55265574
**
@@ -5764,15 +5812,16 @@
57645812
** It is useful either for creating backups of databases or
57655813
** for copying in-memory databases to or from persistent files.
57665814
**
57675815
** See Also: [Using the SQLite Online Backup API]
57685816
**
5769
-** ^Exclusive access is required to the destination database for the
5770
-** duration of the operation. ^However the source database is only
5771
-** read-locked while it is actually being read; it is not locked
5772
-** continuously for the entire backup operation. ^Thus, the backup may be
5773
-** performed on a live source database without preventing other users from
5817
+** ^SQLite holds a write transaction open on the destination database file
5818
+** for the duration of the backup operation.
5819
+** ^The source database is read-locked only while it is being read;
5820
+** it is not locked continuously for the entire backup operation.
5821
+** ^Thus, the backup may be performed on a live source database without
5822
+** preventing other database connections from
57745823
** reading or writing to the source database while the backup is underway.
57755824
**
57765825
** ^(To perform a backup operation:
57775826
** <ol>
57785827
** <li><b>sqlite3_backup_init()</b> is called once to initialize the
@@ -5795,15 +5844,15 @@
57955844
** an [ATTACH] statement for an attached database.
57965845
** ^The S and M arguments passed to
57975846
** sqlite3_backup_init(D,N,S,M) identify the [database connection]
57985847
** and database name of the source database, respectively.
57995848
** ^The source and destination [database connections] (parameters S and D)
5800
-** must be different or else sqlite3_backup_init(D,N,S,M) will file with
5849
+** must be different or else sqlite3_backup_init(D,N,S,M) will fail with
58015850
** an error.
58025851
**
58035852
** ^If an error occurs within sqlite3_backup_init(D,N,S,M), then NULL is
5804
-** returned and an error code and error message are store3d in the
5853
+** returned and an error code and error message are stored in the
58055854
** destination [database connection] D.
58065855
** ^The error code and message for the failed call to sqlite3_backup_init()
58075856
** can be retrieved using the [sqlite3_errcode()], [sqlite3_errmsg()], and/or
58085857
** [sqlite3_errmsg16()] functions.
58095858
** ^A successful call to sqlite3_backup_init() returns a pointer to an
@@ -5816,11 +5865,11 @@
58165865
**
58175866
** ^Function sqlite3_backup_step(B,N) will copy up to N pages between
58185867
** the source and destination databases specified by [sqlite3_backup] object B.
58195868
** ^If N is negative, all remaining source pages are copied.
58205869
** ^If sqlite3_backup_step(B,N) successfully copies N pages and there
5821
-** are still more pages to be copied, then the function resturns [SQLITE_OK].
5870
+** are still more pages to be copied, then the function returns [SQLITE_OK].
58225871
** ^If sqlite3_backup_step(B,N) successfully finishes copying all pages
58235872
** from source to destination, then it returns [SQLITE_DONE].
58245873
** ^If an error occurs while running sqlite3_backup_step(B,N),
58255874
** then an [error code] is returned. ^As well as [SQLITE_OK] and
58265875
** [SQLITE_DONE], a call to sqlite3_backup_step() may return [SQLITE_READONLY],
@@ -5830,11 +5879,11 @@
58305879
** ^(The sqlite3_backup_step() might return [SQLITE_READONLY] if
58315880
** <ol>
58325881
** <li> the destination database was opened read-only, or
58335882
** <li> the destination database is using write-ahead-log journaling
58345883
** and the destination and source page sizes differ, or
5835
-** <li> The destination database is an in-memory database and the
5884
+** <li> the destination database is an in-memory database and the
58365885
** destination and source page sizes differ.
58375886
** </ol>)^
58385887
**
58395888
** ^If sqlite3_backup_step() cannot obtain a required file-system lock, then
58405889
** the [sqlite3_busy_handler | busy-handler function]
@@ -6161,11 +6210,12 @@
61616210
**
61626211
** ^The [wal_autocheckpoint pragma] can be used to invoke this interface
61636212
** from SQL.
61646213
**
61656214
** ^Every new [database connection] defaults to having the auto-checkpoint
6166
-** enabled with a threshold of 1000 pages. The use of this interface
6215
+** enabled with a threshold of 1000 or [SQLITE_DEFAULT_WAL_AUTOCHECKPOINT]
6216
+** pages. The use of this interface
61676217
** is only necessary if the default setting is found to be suboptimal
61686218
** for a particular application.
61696219
*/
61706220
SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
61716221
61726222
--- 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.7.4"
111 #define SQLITE_VERSION_NUMBER 3007004
112 #define SQLITE_SOURCE_ID "2010-12-06 21:09:59 fabcb6b95e1d4059d1e6c6183f65846f6cbd5749"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -713,10 +713,15 @@
713 ** by the user. The fourth argument to [sqlite3_file_control()] should
714 ** point to an integer (type int) containing the new chunk-size to use
715 ** for the nominated database. Allocating database file space in large
716 ** chunks (say 1MB at a time), may reduce file-system fragmentation and
717 ** improve performance on some systems.
 
 
 
 
 
718 */
719 #define SQLITE_FCNTL_LOCKSTATE 1
720 #define SQLITE_GET_LOCKPROXYFILE 2
721 #define SQLITE_SET_LOCKPROXYFILE 3
722 #define SQLITE_LAST_ERRNO 4
@@ -2648,18 +2653,35 @@
2648 SQLITE_API const char *sqlite3_sql(sqlite3_stmt *pStmt);
2649
2650 /*
2651 ** CAPI3REF: Determine If An SQL Statement Writes The Database
2652 **
2653 ** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if
2654 ** the [prepared statement] X is [SELECT] statement and false (zero) if
2655 ** X is an [INSERT], [UPDATE], [DELETE], CREATE, DROP, [ANALYZE],
2656 ** [ALTER], or [REINDEX] statement.
2657 ** If X is a NULL pointer or any other kind of statement, including but
2658 ** not limited to [ATTACH], [DETACH], [COMMIT], [ROLLBACK], [RELEASE],
2659 ** [SAVEPOINT], [PRAGMA], or [VACUUM] the result of sqlite3_stmt_readonly(X) is
2660 ** undefined.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2661 */
2662 SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
2663
2664 /*
2665 ** CAPI3REF: Dynamically Typed Value Object
@@ -5384,11 +5406,12 @@
5384 ** internal equivalents). Only the value returned in the
5385 ** *pHighwater parameter to [sqlite3_status()] is of interest.
5386 ** The value written into the *pCurrent parameter is undefined.</dd>)^
5387 **
5388 ** ^(<dt>SQLITE_STATUS_MALLOC_COUNT</dt>
5389 ** <dd>This parameter records the number of separate memory allocations.</dd>)^
 
5390 **
5391 ** ^(<dt>SQLITE_STATUS_PAGECACHE_USED</dt>
5392 ** <dd>This parameter returns the number of pages used out of the
5393 ** [pagecache memory allocator] that was configured using
5394 ** [SQLITE_CONFIG_PAGECACHE]. The
@@ -5489,10 +5512,32 @@
5489 **
5490 ** <dl>
5491 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
5492 ** <dd>This parameter returns the number of lookaside memory slots currently
5493 ** checked out.</dd>)^
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5494 **
5495 ** ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt>
5496 ** <dd>This parameter returns the approximate number of of bytes of heap
5497 ** memory used by all pager caches associated with the database connection.)^
5498 ** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
@@ -5512,15 +5557,18 @@
5512 ** the database connection.)^
5513 ** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0.
5514 ** </dd>
5515 ** </dl>
5516 */
5517 #define SQLITE_DBSTATUS_LOOKASIDE_USED 0
5518 #define SQLITE_DBSTATUS_CACHE_USED 1
5519 #define SQLITE_DBSTATUS_SCHEMA_USED 2
5520 #define SQLITE_DBSTATUS_STMT_USED 3
5521 #define SQLITE_DBSTATUS_MAX 3 /* Largest defined DBSTATUS */
 
 
 
5522
5523
5524 /*
5525 ** CAPI3REF: Prepared Statement Status
5526 **
@@ -5764,15 +5812,16 @@
5764 ** It is useful either for creating backups of databases or
5765 ** for copying in-memory databases to or from persistent files.
5766 **
5767 ** See Also: [Using the SQLite Online Backup API]
5768 **
5769 ** ^Exclusive access is required to the destination database for the
5770 ** duration of the operation. ^However the source database is only
5771 ** read-locked while it is actually being read; it is not locked
5772 ** continuously for the entire backup operation. ^Thus, the backup may be
5773 ** performed on a live source database without preventing other users from
 
5774 ** reading or writing to the source database while the backup is underway.
5775 **
5776 ** ^(To perform a backup operation:
5777 ** <ol>
5778 ** <li><b>sqlite3_backup_init()</b> is called once to initialize the
@@ -5795,15 +5844,15 @@
5795 ** an [ATTACH] statement for an attached database.
5796 ** ^The S and M arguments passed to
5797 ** sqlite3_backup_init(D,N,S,M) identify the [database connection]
5798 ** and database name of the source database, respectively.
5799 ** ^The source and destination [database connections] (parameters S and D)
5800 ** must be different or else sqlite3_backup_init(D,N,S,M) will file with
5801 ** an error.
5802 **
5803 ** ^If an error occurs within sqlite3_backup_init(D,N,S,M), then NULL is
5804 ** returned and an error code and error message are store3d in the
5805 ** destination [database connection] D.
5806 ** ^The error code and message for the failed call to sqlite3_backup_init()
5807 ** can be retrieved using the [sqlite3_errcode()], [sqlite3_errmsg()], and/or
5808 ** [sqlite3_errmsg16()] functions.
5809 ** ^A successful call to sqlite3_backup_init() returns a pointer to an
@@ -5816,11 +5865,11 @@
5816 **
5817 ** ^Function sqlite3_backup_step(B,N) will copy up to N pages between
5818 ** the source and destination databases specified by [sqlite3_backup] object B.
5819 ** ^If N is negative, all remaining source pages are copied.
5820 ** ^If sqlite3_backup_step(B,N) successfully copies N pages and there
5821 ** are still more pages to be copied, then the function resturns [SQLITE_OK].
5822 ** ^If sqlite3_backup_step(B,N) successfully finishes copying all pages
5823 ** from source to destination, then it returns [SQLITE_DONE].
5824 ** ^If an error occurs while running sqlite3_backup_step(B,N),
5825 ** then an [error code] is returned. ^As well as [SQLITE_OK] and
5826 ** [SQLITE_DONE], a call to sqlite3_backup_step() may return [SQLITE_READONLY],
@@ -5830,11 +5879,11 @@
5830 ** ^(The sqlite3_backup_step() might return [SQLITE_READONLY] if
5831 ** <ol>
5832 ** <li> the destination database was opened read-only, or
5833 ** <li> the destination database is using write-ahead-log journaling
5834 ** and the destination and source page sizes differ, or
5835 ** <li> The destination database is an in-memory database and the
5836 ** destination and source page sizes differ.
5837 ** </ol>)^
5838 **
5839 ** ^If sqlite3_backup_step() cannot obtain a required file-system lock, then
5840 ** the [sqlite3_busy_handler | busy-handler function]
@@ -6161,11 +6210,12 @@
6161 **
6162 ** ^The [wal_autocheckpoint pragma] can be used to invoke this interface
6163 ** from SQL.
6164 **
6165 ** ^Every new [database connection] defaults to having the auto-checkpoint
6166 ** enabled with a threshold of 1000 pages. The use of this interface
 
6167 ** is only necessary if the default setting is found to be suboptimal
6168 ** for a particular application.
6169 */
6170 SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
6171
6172
--- 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.7.4"
111 #define SQLITE_VERSION_NUMBER 3007004
112 #define SQLITE_SOURCE_ID "2010-12-21 21:28:38 b0888047bb6d9ac55e29b9224df2ff650728bb78"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -713,10 +713,15 @@
713 ** by the user. The fourth argument to [sqlite3_file_control()] should
714 ** point to an integer (type int) containing the new chunk-size to use
715 ** for the nominated database. Allocating database file space in large
716 ** chunks (say 1MB at a time), may reduce file-system fragmentation and
717 ** improve performance on some systems.
718 **
719 ** The [SQLITE_FCNTL_FILE_POINTER] opcode is used to obtain a pointer
720 ** to the [sqlite3_file] object associated with a particular database
721 ** connection. See the [sqlite3_file_control()] documentation for
722 ** additional information.
723 */
724 #define SQLITE_FCNTL_LOCKSTATE 1
725 #define SQLITE_GET_LOCKPROXYFILE 2
726 #define SQLITE_SET_LOCKPROXYFILE 3
727 #define SQLITE_LAST_ERRNO 4
@@ -2648,18 +2653,35 @@
2653 SQLITE_API const char *sqlite3_sql(sqlite3_stmt *pStmt);
2654
2655 /*
2656 ** CAPI3REF: Determine If An SQL Statement Writes The Database
2657 **
2658 ** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if
2659 ** and only if the [prepared statement] X is makes no direct changes to
2660 ** the content of the database file.
2661 **
2662 ** Note that [application-defined SQL functions] or
2663 ** [virtual tables] might change the database indirectly as a side effect.
2664 ** ^(For example, if an application defines a function "eval()" that
2665 ** calls [sqlite3_exec()], then the following SQL statement would
2666 ** change the database file through side-effects:
2667 **
2668 ** <blockquote><pre>
2669 ** SELECT eval('DELETE FROM t1') FROM t2;
2670 ** </pre></blockquote>
2671 **
2672 ** But because the [SELECT] statement does not change the database file
2673 ** directly, sqlite3_stmt_readonly() would still return true.)^
2674 **
2675 ** ^Transaction control statements such as [BEGIN], [COMMIT], [ROLLBACK],
2676 ** [SAVEPOINT], and [RELEASE] cause sqlite3_stmt_readonly() to return true,
2677 ** since the statements themselves do not actually modify the database but
2678 ** rather they control the timing of when other statements modify the
2679 ** database. ^The [ATTACH] and [DETACH] statements also cause
2680 ** sqlite3_stmt_readonly() to return true since, while those statements
2681 ** change the configuration of a database connection, they do not make
2682 ** changes to the content of the database files on disk.
2683 */
2684 SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
2685
2686 /*
2687 ** CAPI3REF: Dynamically Typed Value Object
@@ -5384,11 +5406,12 @@
5406 ** internal equivalents). Only the value returned in the
5407 ** *pHighwater parameter to [sqlite3_status()] is of interest.
5408 ** The value written into the *pCurrent parameter is undefined.</dd>)^
5409 **
5410 ** ^(<dt>SQLITE_STATUS_MALLOC_COUNT</dt>
5411 ** <dd>This parameter records the number of separate memory allocations
5412 ** currently checked out.</dd>)^
5413 **
5414 ** ^(<dt>SQLITE_STATUS_PAGECACHE_USED</dt>
5415 ** <dd>This parameter returns the number of pages used out of the
5416 ** [pagecache memory allocator] that was configured using
5417 ** [SQLITE_CONFIG_PAGECACHE]. The
@@ -5489,10 +5512,32 @@
5512 **
5513 ** <dl>
5514 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
5515 ** <dd>This parameter returns the number of lookaside memory slots currently
5516 ** checked out.</dd>)^
5517 **
5518 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_HIT</dt>
5519 ** <dd>This parameter returns the number malloc attempts that were
5520 ** satisfied using lookaside memory. Only the high-water value is meaningful;
5521 ** the current value is always zero.
5522 ** checked out.</dd>)^
5523 **
5524 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE</dt>
5525 ** <dd>This parameter returns the number malloc attempts that might have
5526 ** been satisfied using lookaside memory but failed due to the amount of
5527 ** memory requested being larger than the lookaside slot size.
5528 ** Only the high-water value is meaningful;
5529 ** the current value is always zero.
5530 ** checked out.</dd>)^
5531 **
5532 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL</dt>
5533 ** <dd>This parameter returns the number malloc attempts that might have
5534 ** been satisfied using lookaside memory but failed due to all lookaside
5535 ** memory already being in use.
5536 ** Only the high-water value is meaningful;
5537 ** the current value is always zero.
5538 ** checked out.</dd>)^
5539 **
5540 ** ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt>
5541 ** <dd>This parameter returns the approximate number of of bytes of heap
5542 ** memory used by all pager caches associated with the database connection.)^
5543 ** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
@@ -5512,15 +5557,18 @@
5557 ** the database connection.)^
5558 ** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0.
5559 ** </dd>
5560 ** </dl>
5561 */
5562 #define SQLITE_DBSTATUS_LOOKASIDE_USED 0
5563 #define SQLITE_DBSTATUS_CACHE_USED 1
5564 #define SQLITE_DBSTATUS_SCHEMA_USED 2
5565 #define SQLITE_DBSTATUS_STMT_USED 3
5566 #define SQLITE_DBSTATUS_LOOKASIDE_HIT 4
5567 #define SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE 5
5568 #define SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL 6
5569 #define SQLITE_DBSTATUS_MAX 6 /* Largest defined DBSTATUS */
5570
5571
5572 /*
5573 ** CAPI3REF: Prepared Statement Status
5574 **
@@ -5764,15 +5812,16 @@
5812 ** It is useful either for creating backups of databases or
5813 ** for copying in-memory databases to or from persistent files.
5814 **
5815 ** See Also: [Using the SQLite Online Backup API]
5816 **
5817 ** ^SQLite holds a write transaction open on the destination database file
5818 ** for the duration of the backup operation.
5819 ** ^The source database is read-locked only while it is being read;
5820 ** it is not locked continuously for the entire backup operation.
5821 ** ^Thus, the backup may be performed on a live source database without
5822 ** preventing other database connections from
5823 ** reading or writing to the source database while the backup is underway.
5824 **
5825 ** ^(To perform a backup operation:
5826 ** <ol>
5827 ** <li><b>sqlite3_backup_init()</b> is called once to initialize the
@@ -5795,15 +5844,15 @@
5844 ** an [ATTACH] statement for an attached database.
5845 ** ^The S and M arguments passed to
5846 ** sqlite3_backup_init(D,N,S,M) identify the [database connection]
5847 ** and database name of the source database, respectively.
5848 ** ^The source and destination [database connections] (parameters S and D)
5849 ** must be different or else sqlite3_backup_init(D,N,S,M) will fail with
5850 ** an error.
5851 **
5852 ** ^If an error occurs within sqlite3_backup_init(D,N,S,M), then NULL is
5853 ** returned and an error code and error message are stored in the
5854 ** destination [database connection] D.
5855 ** ^The error code and message for the failed call to sqlite3_backup_init()
5856 ** can be retrieved using the [sqlite3_errcode()], [sqlite3_errmsg()], and/or
5857 ** [sqlite3_errmsg16()] functions.
5858 ** ^A successful call to sqlite3_backup_init() returns a pointer to an
@@ -5816,11 +5865,11 @@
5865 **
5866 ** ^Function sqlite3_backup_step(B,N) will copy up to N pages between
5867 ** the source and destination databases specified by [sqlite3_backup] object B.
5868 ** ^If N is negative, all remaining source pages are copied.
5869 ** ^If sqlite3_backup_step(B,N) successfully copies N pages and there
5870 ** are still more pages to be copied, then the function returns [SQLITE_OK].
5871 ** ^If sqlite3_backup_step(B,N) successfully finishes copying all pages
5872 ** from source to destination, then it returns [SQLITE_DONE].
5873 ** ^If an error occurs while running sqlite3_backup_step(B,N),
5874 ** then an [error code] is returned. ^As well as [SQLITE_OK] and
5875 ** [SQLITE_DONE], a call to sqlite3_backup_step() may return [SQLITE_READONLY],
@@ -5830,11 +5879,11 @@
5879 ** ^(The sqlite3_backup_step() might return [SQLITE_READONLY] if
5880 ** <ol>
5881 ** <li> the destination database was opened read-only, or
5882 ** <li> the destination database is using write-ahead-log journaling
5883 ** and the destination and source page sizes differ, or
5884 ** <li> the destination database is an in-memory database and the
5885 ** destination and source page sizes differ.
5886 ** </ol>)^
5887 **
5888 ** ^If sqlite3_backup_step() cannot obtain a required file-system lock, then
5889 ** the [sqlite3_busy_handler | busy-handler function]
@@ -6161,11 +6210,12 @@
6210 **
6211 ** ^The [wal_autocheckpoint pragma] can be used to invoke this interface
6212 ** from SQL.
6213 **
6214 ** ^Every new [database connection] defaults to having the auto-checkpoint
6215 ** enabled with a threshold of 1000 or [SQLITE_DEFAULT_WAL_AUTOCHECKPOINT]
6216 ** pages. The use of this interface
6217 ** is only necessary if the default setting is found to be suboptimal
6218 ** for a particular application.
6219 */
6220 SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
6221
6222
+75 -25
--- 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.7.4"
111111
#define SQLITE_VERSION_NUMBER 3007004
112
-#define SQLITE_SOURCE_ID "2010-12-06 21:09:59 fabcb6b95e1d4059d1e6c6183f65846f6cbd5749"
112
+#define SQLITE_SOURCE_ID "2010-12-21 21:28:38 b0888047bb6d9ac55e29b9224df2ff650728bb78"
113113
114114
/*
115115
** CAPI3REF: Run-Time Library Version Numbers
116116
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117117
**
@@ -713,10 +713,15 @@
713713
** by the user. The fourth argument to [sqlite3_file_control()] should
714714
** point to an integer (type int) containing the new chunk-size to use
715715
** for the nominated database. Allocating database file space in large
716716
** chunks (say 1MB at a time), may reduce file-system fragmentation and
717717
** improve performance on some systems.
718
+**
719
+** The [SQLITE_FCNTL_FILE_POINTER] opcode is used to obtain a pointer
720
+** to the [sqlite3_file] object associated with a particular database
721
+** connection. See the [sqlite3_file_control()] documentation for
722
+** additional information.
718723
*/
719724
#define SQLITE_FCNTL_LOCKSTATE 1
720725
#define SQLITE_GET_LOCKPROXYFILE 2
721726
#define SQLITE_SET_LOCKPROXYFILE 3
722727
#define SQLITE_LAST_ERRNO 4
@@ -2648,18 +2653,35 @@
26482653
SQLITE_API const char *sqlite3_sql(sqlite3_stmt *pStmt);
26492654
26502655
/*
26512656
** CAPI3REF: Determine If An SQL Statement Writes The Database
26522657
**
2653
-** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if
2654
-** the [prepared statement] X is [SELECT] statement and false (zero) if
2655
-** X is an [INSERT], [UPDATE], [DELETE], CREATE, DROP, [ANALYZE],
2656
-** [ALTER], or [REINDEX] statement.
2657
-** If X is a NULL pointer or any other kind of statement, including but
2658
-** not limited to [ATTACH], [DETACH], [COMMIT], [ROLLBACK], [RELEASE],
2659
-** [SAVEPOINT], [PRAGMA], or [VACUUM] the result of sqlite3_stmt_readonly(X) is
2660
-** undefined.
2658
+** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if
2659
+** and only if the [prepared statement] X is makes no direct changes to
2660
+** the content of the database file.
2661
+**
2662
+** Note that [application-defined SQL functions] or
2663
+** [virtual tables] might change the database indirectly as a side effect.
2664
+** ^(For example, if an application defines a function "eval()" that
2665
+** calls [sqlite3_exec()], then the following SQL statement would
2666
+** change the database file through side-effects:
2667
+**
2668
+** <blockquote><pre>
2669
+** SELECT eval('DELETE FROM t1') FROM t2;
2670
+** </pre></blockquote>
2671
+**
2672
+** But because the [SELECT] statement does not change the database file
2673
+** directly, sqlite3_stmt_readonly() would still return true.)^
2674
+**
2675
+** ^Transaction control statements such as [BEGIN], [COMMIT], [ROLLBACK],
2676
+** [SAVEPOINT], and [RELEASE] cause sqlite3_stmt_readonly() to return true,
2677
+** since the statements themselves do not actually modify the database but
2678
+** rather they control the timing of when other statements modify the
2679
+** database. ^The [ATTACH] and [DETACH] statements also cause
2680
+** sqlite3_stmt_readonly() to return true since, while those statements
2681
+** change the configuration of a database connection, they do not make
2682
+** changes to the content of the database files on disk.
26612683
*/
26622684
SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
26632685
26642686
/*
26652687
** CAPI3REF: Dynamically Typed Value Object
@@ -5384,11 +5406,12 @@
53845406
** internal equivalents). Only the value returned in the
53855407
** *pHighwater parameter to [sqlite3_status()] is of interest.
53865408
** The value written into the *pCurrent parameter is undefined.</dd>)^
53875409
**
53885410
** ^(<dt>SQLITE_STATUS_MALLOC_COUNT</dt>
5389
-** <dd>This parameter records the number of separate memory allocations.</dd>)^
5411
+** <dd>This parameter records the number of separate memory allocations
5412
+** currently checked out.</dd>)^
53905413
**
53915414
** ^(<dt>SQLITE_STATUS_PAGECACHE_USED</dt>
53925415
** <dd>This parameter returns the number of pages used out of the
53935416
** [pagecache memory allocator] that was configured using
53945417
** [SQLITE_CONFIG_PAGECACHE]. The
@@ -5489,10 +5512,32 @@
54895512
**
54905513
** <dl>
54915514
** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
54925515
** <dd>This parameter returns the number of lookaside memory slots currently
54935516
** checked out.</dd>)^
5517
+**
5518
+** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_HIT</dt>
5519
+** <dd>This parameter returns the number malloc attempts that were
5520
+** satisfied using lookaside memory. Only the high-water value is meaningful;
5521
+** the current value is always zero.
5522
+** checked out.</dd>)^
5523
+**
5524
+** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE</dt>
5525
+** <dd>This parameter returns the number malloc attempts that might have
5526
+** been satisfied using lookaside memory but failed due to the amount of
5527
+** memory requested being larger than the lookaside slot size.
5528
+** Only the high-water value is meaningful;
5529
+** the current value is always zero.
5530
+** checked out.</dd>)^
5531
+**
5532
+** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL</dt>
5533
+** <dd>This parameter returns the number malloc attempts that might have
5534
+** been satisfied using lookaside memory but failed due to all lookaside
5535
+** memory already being in use.
5536
+** Only the high-water value is meaningful;
5537
+** the current value is always zero.
5538
+** checked out.</dd>)^
54945539
**
54955540
** ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt>
54965541
** <dd>This parameter returns the approximate number of of bytes of heap
54975542
** memory used by all pager caches associated with the database connection.)^
54985543
** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
@@ -5512,15 +5557,18 @@
55125557
** the database connection.)^
55135558
** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0.
55145559
** </dd>
55155560
** </dl>
55165561
*/
5517
-#define SQLITE_DBSTATUS_LOOKASIDE_USED 0
5518
-#define SQLITE_DBSTATUS_CACHE_USED 1
5519
-#define SQLITE_DBSTATUS_SCHEMA_USED 2
5520
-#define SQLITE_DBSTATUS_STMT_USED 3
5521
-#define SQLITE_DBSTATUS_MAX 3 /* Largest defined DBSTATUS */
5562
+#define SQLITE_DBSTATUS_LOOKASIDE_USED 0
5563
+#define SQLITE_DBSTATUS_CACHE_USED 1
5564
+#define SQLITE_DBSTATUS_SCHEMA_USED 2
5565
+#define SQLITE_DBSTATUS_STMT_USED 3
5566
+#define SQLITE_DBSTATUS_LOOKASIDE_HIT 4
5567
+#define SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE 5
5568
+#define SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL 6
5569
+#define SQLITE_DBSTATUS_MAX 6 /* Largest defined DBSTATUS */
55225570
55235571
55245572
/*
55255573
** CAPI3REF: Prepared Statement Status
55265574
**
@@ -5764,15 +5812,16 @@
57645812
** It is useful either for creating backups of databases or
57655813
** for copying in-memory databases to or from persistent files.
57665814
**
57675815
** See Also: [Using the SQLite Online Backup API]
57685816
**
5769
-** ^Exclusive access is required to the destination database for the
5770
-** duration of the operation. ^However the source database is only
5771
-** read-locked while it is actually being read; it is not locked
5772
-** continuously for the entire backup operation. ^Thus, the backup may be
5773
-** performed on a live source database without preventing other users from
5817
+** ^SQLite holds a write transaction open on the destination database file
5818
+** for the duration of the backup operation.
5819
+** ^The source database is read-locked only while it is being read;
5820
+** it is not locked continuously for the entire backup operation.
5821
+** ^Thus, the backup may be performed on a live source database without
5822
+** preventing other database connections from
57745823
** reading or writing to the source database while the backup is underway.
57755824
**
57765825
** ^(To perform a backup operation:
57775826
** <ol>
57785827
** <li><b>sqlite3_backup_init()</b> is called once to initialize the
@@ -5795,15 +5844,15 @@
57955844
** an [ATTACH] statement for an attached database.
57965845
** ^The S and M arguments passed to
57975846
** sqlite3_backup_init(D,N,S,M) identify the [database connection]
57985847
** and database name of the source database, respectively.
57995848
** ^The source and destination [database connections] (parameters S and D)
5800
-** must be different or else sqlite3_backup_init(D,N,S,M) will file with
5849
+** must be different or else sqlite3_backup_init(D,N,S,M) will fail with
58015850
** an error.
58025851
**
58035852
** ^If an error occurs within sqlite3_backup_init(D,N,S,M), then NULL is
5804
-** returned and an error code and error message are store3d in the
5853
+** returned and an error code and error message are stored in the
58055854
** destination [database connection] D.
58065855
** ^The error code and message for the failed call to sqlite3_backup_init()
58075856
** can be retrieved using the [sqlite3_errcode()], [sqlite3_errmsg()], and/or
58085857
** [sqlite3_errmsg16()] functions.
58095858
** ^A successful call to sqlite3_backup_init() returns a pointer to an
@@ -5816,11 +5865,11 @@
58165865
**
58175866
** ^Function sqlite3_backup_step(B,N) will copy up to N pages between
58185867
** the source and destination databases specified by [sqlite3_backup] object B.
58195868
** ^If N is negative, all remaining source pages are copied.
58205869
** ^If sqlite3_backup_step(B,N) successfully copies N pages and there
5821
-** are still more pages to be copied, then the function resturns [SQLITE_OK].
5870
+** are still more pages to be copied, then the function returns [SQLITE_OK].
58225871
** ^If sqlite3_backup_step(B,N) successfully finishes copying all pages
58235872
** from source to destination, then it returns [SQLITE_DONE].
58245873
** ^If an error occurs while running sqlite3_backup_step(B,N),
58255874
** then an [error code] is returned. ^As well as [SQLITE_OK] and
58265875
** [SQLITE_DONE], a call to sqlite3_backup_step() may return [SQLITE_READONLY],
@@ -5830,11 +5879,11 @@
58305879
** ^(The sqlite3_backup_step() might return [SQLITE_READONLY] if
58315880
** <ol>
58325881
** <li> the destination database was opened read-only, or
58335882
** <li> the destination database is using write-ahead-log journaling
58345883
** and the destination and source page sizes differ, or
5835
-** <li> The destination database is an in-memory database and the
5884
+** <li> the destination database is an in-memory database and the
58365885
** destination and source page sizes differ.
58375886
** </ol>)^
58385887
**
58395888
** ^If sqlite3_backup_step() cannot obtain a required file-system lock, then
58405889
** the [sqlite3_busy_handler | busy-handler function]
@@ -6161,11 +6210,12 @@
61616210
**
61626211
** ^The [wal_autocheckpoint pragma] can be used to invoke this interface
61636212
** from SQL.
61646213
**
61656214
** ^Every new [database connection] defaults to having the auto-checkpoint
6166
-** enabled with a threshold of 1000 pages. The use of this interface
6215
+** enabled with a threshold of 1000 or [SQLITE_DEFAULT_WAL_AUTOCHECKPOINT]
6216
+** pages. The use of this interface
61676217
** is only necessary if the default setting is found to be suboptimal
61686218
** for a particular application.
61696219
*/
61706220
SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
61716221
61726222
--- 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.7.4"
111 #define SQLITE_VERSION_NUMBER 3007004
112 #define SQLITE_SOURCE_ID "2010-12-06 21:09:59 fabcb6b95e1d4059d1e6c6183f65846f6cbd5749"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -713,10 +713,15 @@
713 ** by the user. The fourth argument to [sqlite3_file_control()] should
714 ** point to an integer (type int) containing the new chunk-size to use
715 ** for the nominated database. Allocating database file space in large
716 ** chunks (say 1MB at a time), may reduce file-system fragmentation and
717 ** improve performance on some systems.
 
 
 
 
 
718 */
719 #define SQLITE_FCNTL_LOCKSTATE 1
720 #define SQLITE_GET_LOCKPROXYFILE 2
721 #define SQLITE_SET_LOCKPROXYFILE 3
722 #define SQLITE_LAST_ERRNO 4
@@ -2648,18 +2653,35 @@
2648 SQLITE_API const char *sqlite3_sql(sqlite3_stmt *pStmt);
2649
2650 /*
2651 ** CAPI3REF: Determine If An SQL Statement Writes The Database
2652 **
2653 ** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if
2654 ** the [prepared statement] X is [SELECT] statement and false (zero) if
2655 ** X is an [INSERT], [UPDATE], [DELETE], CREATE, DROP, [ANALYZE],
2656 ** [ALTER], or [REINDEX] statement.
2657 ** If X is a NULL pointer or any other kind of statement, including but
2658 ** not limited to [ATTACH], [DETACH], [COMMIT], [ROLLBACK], [RELEASE],
2659 ** [SAVEPOINT], [PRAGMA], or [VACUUM] the result of sqlite3_stmt_readonly(X) is
2660 ** undefined.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2661 */
2662 SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
2663
2664 /*
2665 ** CAPI3REF: Dynamically Typed Value Object
@@ -5384,11 +5406,12 @@
5384 ** internal equivalents). Only the value returned in the
5385 ** *pHighwater parameter to [sqlite3_status()] is of interest.
5386 ** The value written into the *pCurrent parameter is undefined.</dd>)^
5387 **
5388 ** ^(<dt>SQLITE_STATUS_MALLOC_COUNT</dt>
5389 ** <dd>This parameter records the number of separate memory allocations.</dd>)^
 
5390 **
5391 ** ^(<dt>SQLITE_STATUS_PAGECACHE_USED</dt>
5392 ** <dd>This parameter returns the number of pages used out of the
5393 ** [pagecache memory allocator] that was configured using
5394 ** [SQLITE_CONFIG_PAGECACHE]. The
@@ -5489,10 +5512,32 @@
5489 **
5490 ** <dl>
5491 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
5492 ** <dd>This parameter returns the number of lookaside memory slots currently
5493 ** checked out.</dd>)^
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5494 **
5495 ** ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt>
5496 ** <dd>This parameter returns the approximate number of of bytes of heap
5497 ** memory used by all pager caches associated with the database connection.)^
5498 ** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
@@ -5512,15 +5557,18 @@
5512 ** the database connection.)^
5513 ** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0.
5514 ** </dd>
5515 ** </dl>
5516 */
5517 #define SQLITE_DBSTATUS_LOOKASIDE_USED 0
5518 #define SQLITE_DBSTATUS_CACHE_USED 1
5519 #define SQLITE_DBSTATUS_SCHEMA_USED 2
5520 #define SQLITE_DBSTATUS_STMT_USED 3
5521 #define SQLITE_DBSTATUS_MAX 3 /* Largest defined DBSTATUS */
 
 
 
5522
5523
5524 /*
5525 ** CAPI3REF: Prepared Statement Status
5526 **
@@ -5764,15 +5812,16 @@
5764 ** It is useful either for creating backups of databases or
5765 ** for copying in-memory databases to or from persistent files.
5766 **
5767 ** See Also: [Using the SQLite Online Backup API]
5768 **
5769 ** ^Exclusive access is required to the destination database for the
5770 ** duration of the operation. ^However the source database is only
5771 ** read-locked while it is actually being read; it is not locked
5772 ** continuously for the entire backup operation. ^Thus, the backup may be
5773 ** performed on a live source database without preventing other users from
 
5774 ** reading or writing to the source database while the backup is underway.
5775 **
5776 ** ^(To perform a backup operation:
5777 ** <ol>
5778 ** <li><b>sqlite3_backup_init()</b> is called once to initialize the
@@ -5795,15 +5844,15 @@
5795 ** an [ATTACH] statement for an attached database.
5796 ** ^The S and M arguments passed to
5797 ** sqlite3_backup_init(D,N,S,M) identify the [database connection]
5798 ** and database name of the source database, respectively.
5799 ** ^The source and destination [database connections] (parameters S and D)
5800 ** must be different or else sqlite3_backup_init(D,N,S,M) will file with
5801 ** an error.
5802 **
5803 ** ^If an error occurs within sqlite3_backup_init(D,N,S,M), then NULL is
5804 ** returned and an error code and error message are store3d in the
5805 ** destination [database connection] D.
5806 ** ^The error code and message for the failed call to sqlite3_backup_init()
5807 ** can be retrieved using the [sqlite3_errcode()], [sqlite3_errmsg()], and/or
5808 ** [sqlite3_errmsg16()] functions.
5809 ** ^A successful call to sqlite3_backup_init() returns a pointer to an
@@ -5816,11 +5865,11 @@
5816 **
5817 ** ^Function sqlite3_backup_step(B,N) will copy up to N pages between
5818 ** the source and destination databases specified by [sqlite3_backup] object B.
5819 ** ^If N is negative, all remaining source pages are copied.
5820 ** ^If sqlite3_backup_step(B,N) successfully copies N pages and there
5821 ** are still more pages to be copied, then the function resturns [SQLITE_OK].
5822 ** ^If sqlite3_backup_step(B,N) successfully finishes copying all pages
5823 ** from source to destination, then it returns [SQLITE_DONE].
5824 ** ^If an error occurs while running sqlite3_backup_step(B,N),
5825 ** then an [error code] is returned. ^As well as [SQLITE_OK] and
5826 ** [SQLITE_DONE], a call to sqlite3_backup_step() may return [SQLITE_READONLY],
@@ -5830,11 +5879,11 @@
5830 ** ^(The sqlite3_backup_step() might return [SQLITE_READONLY] if
5831 ** <ol>
5832 ** <li> the destination database was opened read-only, or
5833 ** <li> the destination database is using write-ahead-log journaling
5834 ** and the destination and source page sizes differ, or
5835 ** <li> The destination database is an in-memory database and the
5836 ** destination and source page sizes differ.
5837 ** </ol>)^
5838 **
5839 ** ^If sqlite3_backup_step() cannot obtain a required file-system lock, then
5840 ** the [sqlite3_busy_handler | busy-handler function]
@@ -6161,11 +6210,12 @@
6161 **
6162 ** ^The [wal_autocheckpoint pragma] can be used to invoke this interface
6163 ** from SQL.
6164 **
6165 ** ^Every new [database connection] defaults to having the auto-checkpoint
6166 ** enabled with a threshold of 1000 pages. The use of this interface
 
6167 ** is only necessary if the default setting is found to be suboptimal
6168 ** for a particular application.
6169 */
6170 SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
6171
6172
--- 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.7.4"
111 #define SQLITE_VERSION_NUMBER 3007004
112 #define SQLITE_SOURCE_ID "2010-12-21 21:28:38 b0888047bb6d9ac55e29b9224df2ff650728bb78"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -713,10 +713,15 @@
713 ** by the user. The fourth argument to [sqlite3_file_control()] should
714 ** point to an integer (type int) containing the new chunk-size to use
715 ** for the nominated database. Allocating database file space in large
716 ** chunks (say 1MB at a time), may reduce file-system fragmentation and
717 ** improve performance on some systems.
718 **
719 ** The [SQLITE_FCNTL_FILE_POINTER] opcode is used to obtain a pointer
720 ** to the [sqlite3_file] object associated with a particular database
721 ** connection. See the [sqlite3_file_control()] documentation for
722 ** additional information.
723 */
724 #define SQLITE_FCNTL_LOCKSTATE 1
725 #define SQLITE_GET_LOCKPROXYFILE 2
726 #define SQLITE_SET_LOCKPROXYFILE 3
727 #define SQLITE_LAST_ERRNO 4
@@ -2648,18 +2653,35 @@
2653 SQLITE_API const char *sqlite3_sql(sqlite3_stmt *pStmt);
2654
2655 /*
2656 ** CAPI3REF: Determine If An SQL Statement Writes The Database
2657 **
2658 ** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if
2659 ** and only if the [prepared statement] X is makes no direct changes to
2660 ** the content of the database file.
2661 **
2662 ** Note that [application-defined SQL functions] or
2663 ** [virtual tables] might change the database indirectly as a side effect.
2664 ** ^(For example, if an application defines a function "eval()" that
2665 ** calls [sqlite3_exec()], then the following SQL statement would
2666 ** change the database file through side-effects:
2667 **
2668 ** <blockquote><pre>
2669 ** SELECT eval('DELETE FROM t1') FROM t2;
2670 ** </pre></blockquote>
2671 **
2672 ** But because the [SELECT] statement does not change the database file
2673 ** directly, sqlite3_stmt_readonly() would still return true.)^
2674 **
2675 ** ^Transaction control statements such as [BEGIN], [COMMIT], [ROLLBACK],
2676 ** [SAVEPOINT], and [RELEASE] cause sqlite3_stmt_readonly() to return true,
2677 ** since the statements themselves do not actually modify the database but
2678 ** rather they control the timing of when other statements modify the
2679 ** database. ^The [ATTACH] and [DETACH] statements also cause
2680 ** sqlite3_stmt_readonly() to return true since, while those statements
2681 ** change the configuration of a database connection, they do not make
2682 ** changes to the content of the database files on disk.
2683 */
2684 SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
2685
2686 /*
2687 ** CAPI3REF: Dynamically Typed Value Object
@@ -5384,11 +5406,12 @@
5406 ** internal equivalents). Only the value returned in the
5407 ** *pHighwater parameter to [sqlite3_status()] is of interest.
5408 ** The value written into the *pCurrent parameter is undefined.</dd>)^
5409 **
5410 ** ^(<dt>SQLITE_STATUS_MALLOC_COUNT</dt>
5411 ** <dd>This parameter records the number of separate memory allocations
5412 ** currently checked out.</dd>)^
5413 **
5414 ** ^(<dt>SQLITE_STATUS_PAGECACHE_USED</dt>
5415 ** <dd>This parameter returns the number of pages used out of the
5416 ** [pagecache memory allocator] that was configured using
5417 ** [SQLITE_CONFIG_PAGECACHE]. The
@@ -5489,10 +5512,32 @@
5512 **
5513 ** <dl>
5514 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
5515 ** <dd>This parameter returns the number of lookaside memory slots currently
5516 ** checked out.</dd>)^
5517 **
5518 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_HIT</dt>
5519 ** <dd>This parameter returns the number malloc attempts that were
5520 ** satisfied using lookaside memory. Only the high-water value is meaningful;
5521 ** the current value is always zero.
5522 ** checked out.</dd>)^
5523 **
5524 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE</dt>
5525 ** <dd>This parameter returns the number malloc attempts that might have
5526 ** been satisfied using lookaside memory but failed due to the amount of
5527 ** memory requested being larger than the lookaside slot size.
5528 ** Only the high-water value is meaningful;
5529 ** the current value is always zero.
5530 ** checked out.</dd>)^
5531 **
5532 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL</dt>
5533 ** <dd>This parameter returns the number malloc attempts that might have
5534 ** been satisfied using lookaside memory but failed due to all lookaside
5535 ** memory already being in use.
5536 ** Only the high-water value is meaningful;
5537 ** the current value is always zero.
5538 ** checked out.</dd>)^
5539 **
5540 ** ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt>
5541 ** <dd>This parameter returns the approximate number of of bytes of heap
5542 ** memory used by all pager caches associated with the database connection.)^
5543 ** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
@@ -5512,15 +5557,18 @@
5557 ** the database connection.)^
5558 ** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0.
5559 ** </dd>
5560 ** </dl>
5561 */
5562 #define SQLITE_DBSTATUS_LOOKASIDE_USED 0
5563 #define SQLITE_DBSTATUS_CACHE_USED 1
5564 #define SQLITE_DBSTATUS_SCHEMA_USED 2
5565 #define SQLITE_DBSTATUS_STMT_USED 3
5566 #define SQLITE_DBSTATUS_LOOKASIDE_HIT 4
5567 #define SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE 5
5568 #define SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL 6
5569 #define SQLITE_DBSTATUS_MAX 6 /* Largest defined DBSTATUS */
5570
5571
5572 /*
5573 ** CAPI3REF: Prepared Statement Status
5574 **
@@ -5764,15 +5812,16 @@
5812 ** It is useful either for creating backups of databases or
5813 ** for copying in-memory databases to or from persistent files.
5814 **
5815 ** See Also: [Using the SQLite Online Backup API]
5816 **
5817 ** ^SQLite holds a write transaction open on the destination database file
5818 ** for the duration of the backup operation.
5819 ** ^The source database is read-locked only while it is being read;
5820 ** it is not locked continuously for the entire backup operation.
5821 ** ^Thus, the backup may be performed on a live source database without
5822 ** preventing other database connections from
5823 ** reading or writing to the source database while the backup is underway.
5824 **
5825 ** ^(To perform a backup operation:
5826 ** <ol>
5827 ** <li><b>sqlite3_backup_init()</b> is called once to initialize the
@@ -5795,15 +5844,15 @@
5844 ** an [ATTACH] statement for an attached database.
5845 ** ^The S and M arguments passed to
5846 ** sqlite3_backup_init(D,N,S,M) identify the [database connection]
5847 ** and database name of the source database, respectively.
5848 ** ^The source and destination [database connections] (parameters S and D)
5849 ** must be different or else sqlite3_backup_init(D,N,S,M) will fail with
5850 ** an error.
5851 **
5852 ** ^If an error occurs within sqlite3_backup_init(D,N,S,M), then NULL is
5853 ** returned and an error code and error message are stored in the
5854 ** destination [database connection] D.
5855 ** ^The error code and message for the failed call to sqlite3_backup_init()
5856 ** can be retrieved using the [sqlite3_errcode()], [sqlite3_errmsg()], and/or
5857 ** [sqlite3_errmsg16()] functions.
5858 ** ^A successful call to sqlite3_backup_init() returns a pointer to an
@@ -5816,11 +5865,11 @@
5865 **
5866 ** ^Function sqlite3_backup_step(B,N) will copy up to N pages between
5867 ** the source and destination databases specified by [sqlite3_backup] object B.
5868 ** ^If N is negative, all remaining source pages are copied.
5869 ** ^If sqlite3_backup_step(B,N) successfully copies N pages and there
5870 ** are still more pages to be copied, then the function returns [SQLITE_OK].
5871 ** ^If sqlite3_backup_step(B,N) successfully finishes copying all pages
5872 ** from source to destination, then it returns [SQLITE_DONE].
5873 ** ^If an error occurs while running sqlite3_backup_step(B,N),
5874 ** then an [error code] is returned. ^As well as [SQLITE_OK] and
5875 ** [SQLITE_DONE], a call to sqlite3_backup_step() may return [SQLITE_READONLY],
@@ -5830,11 +5879,11 @@
5879 ** ^(The sqlite3_backup_step() might return [SQLITE_READONLY] if
5880 ** <ol>
5881 ** <li> the destination database was opened read-only, or
5882 ** <li> the destination database is using write-ahead-log journaling
5883 ** and the destination and source page sizes differ, or
5884 ** <li> the destination database is an in-memory database and the
5885 ** destination and source page sizes differ.
5886 ** </ol>)^
5887 **
5888 ** ^If sqlite3_backup_step() cannot obtain a required file-system lock, then
5889 ** the [sqlite3_busy_handler | busy-handler function]
@@ -6161,11 +6210,12 @@
6210 **
6211 ** ^The [wal_autocheckpoint pragma] can be used to invoke this interface
6212 ** from SQL.
6213 **
6214 ** ^Every new [database connection] defaults to having the auto-checkpoint
6215 ** enabled with a threshold of 1000 or [SQLITE_DEFAULT_WAL_AUTOCHECKPOINT]
6216 ** pages. The use of this interface
6217 ** is only necessary if the default setting is found to be suboptimal
6218 ** for a particular application.
6219 */
6220 SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
6221
6222

Keyboard Shortcuts

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