Fossil SCM

Update the built-in SQLite to the Jan 3 beta for 3.8.8.

drh 2015-01-03 19:58 trunk
Commit ab3fed40ec6dd1c7a347b17e3861f54baf59f49c
2 files changed +291 -209 +18 -8
+291 -209
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -231,11 +231,11 @@
231231
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
232232
** [sqlite_version()] and [sqlite_source_id()].
233233
*/
234234
#define SQLITE_VERSION "3.8.8"
235235
#define SQLITE_VERSION_NUMBER 3008008
236
-#define SQLITE_SOURCE_ID "2014-12-10 04:58:43 3528f8dd39acace8eeb7337994c8617313f4b04b"
236
+#define SQLITE_SOURCE_ID "2015-01-03 18:59:17 23d4c07eb81db5a5c6beb56b5820f0b6501f1fb6"
237237
238238
/*
239239
** CAPI3REF: Run-Time Library Version Numbers
240240
** KEYWORDS: sqlite3_version, sqlite3_sourceid
241241
**
@@ -323,11 +323,11 @@
323323
** This interface only reports on the compile-time mutex setting
324324
** of the [SQLITE_THREADSAFE] flag. If SQLite is compiled with
325325
** SQLITE_THREADSAFE=1 or =2 then mutexes are enabled by default but
326326
** can be fully or partially disabled using a call to [sqlite3_config()]
327327
** with the verbs [SQLITE_CONFIG_SINGLETHREAD], [SQLITE_CONFIG_MULTITHREAD],
328
-** or [SQLITE_CONFIG_MUTEX]. ^(The return value of the
328
+** or [SQLITE_CONFIG_SERIALIZED]. ^(The return value of the
329329
** sqlite3_threadsafe() function shows only the compile-time setting of
330330
** thread safety, not any run-time changes to that setting made by
331331
** sqlite3_config(). In other words, the return value from sqlite3_threadsafe()
332332
** is unchanged by calls to sqlite3_config().)^
333333
**
@@ -1692,11 +1692,11 @@
16921692
** configuration option.
16931693
** ^There are three arguments to SQLITE_CONFIG_PAGECACHE: A pointer to
16941694
** 8-byte aligned
16951695
** memory, the size of each page buffer (sz), and the number of pages (N).
16961696
** The sz argument should be the size of the largest database page
1697
-** (a power of two between 512 and 32768) plus some extra bytes for each
1697
+** (a power of two between 512 and 65536) plus some extra bytes for each
16981698
** page header. ^The number of extra bytes needed by the page header
16991699
** can be determined using the [SQLITE_CONFIG_PCACHE_HDRSZ] option
17001700
** to [sqlite3_config()].
17011701
** ^It is harmless, apart from the wasted memory,
17021702
** for the sz parameter to be larger than necessary. The first
@@ -1872,10 +1872,21 @@
18721872
** <dd>^The SQLITE_CONFIG_PCACHE_HDRSZ option takes a single parameter which
18731873
** is a pointer to an integer and writes into that integer the number of extra
18741874
** bytes per page required for each page in [SQLITE_CONFIG_PAGECACHE].
18751875
** The amount of extra space required can change depending on the compiler,
18761876
** target platform, and SQLite version.
1877
+**
1878
+** [[SQLITE_CONFIG_PMASZ]]
1879
+** <dt>SQLITE_CONFIG_PMASZ
1880
+** <dd>^The SQLITE_CONFIG_PMASZ option takes a single parameter which
1881
+** is an unsigned integer and sets the "Minimum PMA Size" for the multithreaded
1882
+** sorter to that integer. The default minimum PMA Size is set by the
1883
+** [SQLITE_SORTER_PMASZ] compile-time option. New threads are launched
1884
+** to help with sort operations when multithreaded sorting
1885
+** is enabled (using the [PRAGMA threads] command) and the amount of content
1886
+** to be sorted exceeds the page size times the minimum of the
1887
+** [PRAGMA cache_size] setting and this value.
18771888
** </dl>
18781889
*/
18791890
#define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
18801891
#define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
18811892
#define SQLITE_CONFIG_SERIALIZED 3 /* nil */
@@ -1898,10 +1909,11 @@
18981909
#define SQLITE_CONFIG_COVERING_INDEX_SCAN 20 /* int */
18991910
#define SQLITE_CONFIG_SQLLOG 21 /* xSqllog, void* */
19001911
#define SQLITE_CONFIG_MMAP_SIZE 22 /* sqlite3_int64, sqlite3_int64 */
19011912
#define SQLITE_CONFIG_WIN32_HEAPSIZE 23 /* int nByte */
19021913
#define SQLITE_CONFIG_PCACHE_HDRSZ 24 /* int *psz */
1914
+#define SQLITE_CONFIG_PMASZ 25 /* unsigned int szPma */
19031915
19041916
/*
19051917
** CAPI3REF: Database Connection Configuration Options
19061918
**
19071919
** These constants are the available integer configuration options that
@@ -7307,16 +7319,14 @@
73077319
73087320
/*
73097321
** CAPI3REF: Write-Ahead Log Commit Hook
73107322
**
73117323
** ^The [sqlite3_wal_hook()] function is used to register a callback that
7312
-** will be invoked each time a database connection commits data to a
7313
-** [write-ahead log] (i.e. whenever a transaction is committed in
7314
-** [journal_mode | journal_mode=WAL mode]).
7324
+** is invoked each time data is committed to a database in wal mode.
73157325
**
7316
-** ^The callback is invoked by SQLite after the commit has taken place and
7317
-** the associated write-lock on the database released, so the implementation
7326
+** ^(The callback is invoked by SQLite after the commit has taken place and
7327
+** the associated write-lock on the database released)^, so the implementation
73187328
** may read, write or [checkpoint] the database as required.
73197329
**
73207330
** ^The first parameter passed to the callback function when it is invoked
73217331
** is a copy of the third parameter passed to sqlite3_wal_hook() when
73227332
** registering the callback. ^The second is a copy of the database handle.
@@ -9100,11 +9110,11 @@
91009110
#define _BTREE_H_
91019111
91029112
/* TODO: This definition is just included so other modules compile. It
91039113
** needs to be revisited.
91049114
*/
9105
-#define SQLITE_N_BTREE_META 10
9115
+#define SQLITE_N_BTREE_META 16
91069116
91079117
/*
91089118
** If defined as non-zero, auto-vacuum is enabled by default. Otherwise
91099119
** it must be turned on for each database using "PRAGMA auto_vacuum = 1".
91109120
*/
@@ -9215,10 +9225,15 @@
92159225
** offset = 36 + (idx * 4)
92169226
**
92179227
** For example, the free-page-count field is located at byte offset 36 of
92189228
** the database file header. The incr-vacuum-flag field is located at
92199229
** byte offset 64 (== 36+4*7).
9230
+**
9231
+** The BTREE_DATA_VERSION value is not really a value stored in the header.
9232
+** It is a read-only number computed by the pager. But we merge it with
9233
+** the header value access routines since its access pattern is the same.
9234
+** Call it a "virtual meta value".
92209235
*/
92219236
#define BTREE_FREE_PAGE_COUNT 0
92229237
#define BTREE_SCHEMA_VERSION 1
92239238
#define BTREE_FILE_FORMAT 2
92249239
#define BTREE_DEFAULT_CACHE_SIZE 3
@@ -9225,10 +9240,11 @@
92259240
#define BTREE_LARGEST_ROOT_PAGE 4
92269241
#define BTREE_TEXT_ENCODING 5
92279242
#define BTREE_USER_VERSION 6
92289243
#define BTREE_INCR_VACUUM 7
92299244
#define BTREE_APPLICATION_ID 8
9245
+#define BTREE_DATA_VERSION 15 /* A virtual meta-value */
92309246
92319247
/*
92329248
** Values that may be OR'd together to form the second argument of an
92339249
** sqlite3BtreeCursorHints() call.
92349250
*/
@@ -10006,10 +10022,11 @@
1000610022
SQLITE_PRIVATE int sqlite3PagerWalFramesize(Pager *pPager);
1000710023
#endif
1000810024
1000910025
/* Functions used to query pager state and configuration. */
1001010026
SQLITE_PRIVATE u8 sqlite3PagerIsreadonly(Pager*);
10027
+SQLITE_PRIVATE u32 sqlite3PagerDataVersion(Pager*);
1001110028
SQLITE_PRIVATE int sqlite3PagerRefcount(Pager*);
1001210029
SQLITE_PRIVATE int sqlite3PagerMemUsed(Pager*);
1001310030
SQLITE_PRIVATE const char *sqlite3PagerFilename(Pager*, int);
1001410031
SQLITE_PRIVATE const sqlite3_vfs *sqlite3PagerVfs(Pager*);
1001510032
SQLITE_PRIVATE sqlite3_file *sqlite3PagerFile(Pager*);
@@ -10747,10 +10764,11 @@
1074710764
i64 szMmap; /* Default mmap_size setting */
1074810765
unsigned int openFlags; /* Flags passed to sqlite3_vfs.xOpen() */
1074910766
int errCode; /* Most recent error code (SQLITE_*) */
1075010767
int errMask; /* & result codes with this before returning */
1075110768
u16 dbOptFlags; /* Flags to enable/disable optimizations */
10769
+ u8 enc; /* Text encoding */
1075210770
u8 autoCommit; /* The auto-commit flag. */
1075310771
u8 temp_store; /* 1: file 2: memory 0: default */
1075410772
u8 mallocFailed; /* True if we have seen a malloc failure */
1075510773
u8 dfltLockMode; /* Default locking-mode for attached dbs */
1075610774
signed char nextAutovac; /* Autovac setting after VACUUM if >=0 */
@@ -10848,11 +10866,12 @@
1084810866
};
1084910867
1085010868
/*
1085110869
** A macro to discover the encoding of a database.
1085210870
*/
10853
-#define ENC(db) ((db)->aDb[0].pSchema->enc)
10871
+#define SCHEMA_ENC(db) ((db)->aDb[0].pSchema->enc)
10872
+#define ENC(db) ((db)->enc)
1085410873
1085510874
/*
1085610875
** Possible values for the sqlite3.flags.
1085710876
*/
1085810877
#define SQLITE_VdbeTrace 0x00000001 /* True to trace VDBE execution */
@@ -11472,11 +11491,10 @@
1147211491
Index *pNext; /* The next index associated with the same table */
1147311492
Schema *pSchema; /* Schema containing this index */
1147411493
u8 *aSortOrder; /* for each column: True==DESC, False==ASC */
1147511494
char **azColl; /* Array of collation sequence names for index */
1147611495
Expr *pPartIdxWhere; /* WHERE clause for partial indices */
11477
- KeyInfo *pKeyInfo; /* A KeyInfo object suitable for this index */
1147811496
int tnum; /* DB Page containing root of this index */
1147911497
LogEst szIdxRow; /* Estimated average row size in bytes */
1148011498
u16 nKeyCol; /* Number of columns forming the key */
1148111499
u16 nColumn; /* Number of columns stored in the index */
1148211500
u8 onError; /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */
@@ -12526,10 +12544,11 @@
1252612544
void *pPage; /* Page cache memory */
1252712545
int szPage; /* Size of each page in pPage[] */
1252812546
int nPage; /* Number of pages in pPage[] */
1252912547
int mxParserStack; /* maximum depth of the parser stack */
1253012548
int sharedCacheEnabled; /* true if shared-cache mode enabled */
12549
+ u32 szPma; /* Maximum Sorter PMA size */
1253112550
/* The above might be initialized to non-zero. The following need to always
1253212551
** initially be zero, however. */
1253312552
int isInit; /* True after initialization has finished */
1253412553
int inProgress; /* True while initialization in progress */
1253512554
int isMutexInit; /* True after mutexes are initialized */
@@ -13448,11 +13467,11 @@
1344813467
** print I/O tracing messages.
1344913468
*/
1345013469
#ifdef SQLITE_ENABLE_IOTRACE
1345113470
# define IOTRACE(A) if( sqlite3IoTrace ){ sqlite3IoTrace A; }
1345213471
SQLITE_PRIVATE void sqlite3VdbeIOTraceSql(Vdbe*);
13453
-SQLITE_PRIVATE void (*sqlite3IoTrace)(const char*,...);
13472
+void (*sqlite3IoTrace)(const char*,...);
1345413473
#else
1345513474
# define IOTRACE(A)
1345613475
# define sqlite3VdbeIOTraceSql(X)
1345713476
#endif
1345813477
@@ -13661,10 +13680,17 @@
1366113680
*/
1366213681
#ifndef SQLITE_ALLOW_COVERING_INDEX_SCAN
1366313682
# define SQLITE_ALLOW_COVERING_INDEX_SCAN 1
1366413683
#endif
1366513684
13685
+/* The minimum PMA size is set to this value multiplied by the database
13686
+** page size in bytes.
13687
+*/
13688
+#ifndef SQLITE_SORTER_PMASZ
13689
+# define SQLITE_SORTER_PMASZ 250
13690
+#endif
13691
+
1366613692
/*
1366713693
** The following singleton contains the global configuration for
1366813694
** the SQLite library.
1366913695
*/
1367013696
SQLITE_PRIVATE SQLITE_WSD struct Sqlite3Config sqlite3Config = {
@@ -13691,10 +13717,11 @@
1369113717
(void*)0, /* pPage */
1369213718
0, /* szPage */
1369313719
0, /* nPage */
1369413720
0, /* mxParserStack */
1369513721
0, /* sharedCacheEnabled */
13722
+ SQLITE_SORTER_PMASZ, /* szPma */
1369613723
/* All the rest should always be initialized to zero */
1369713724
0, /* isInit */
1369813725
0, /* inProgress */
1369913726
0, /* isMutexInit */
1370013727
0, /* isMallocInit */
@@ -19976,10 +20003,16 @@
1997620003
#endif
1997720004
}
1997820005
break;
1997920006
}
1998020007
default: {
20008
+#ifdef SQLITE_ENABLE_API_ARMOR
20009
+ if( iType-2<0 || iType-2>=ArraySize(winMutex_staticMutexes) ){
20010
+ (void)SQLITE_MISUSE_BKPT;
20011
+ return 0;
20012
+ }
20013
+#endif
1998120014
assert( iType-2 >= 0 );
1998220015
assert( iType-2 < ArraySize(winMutex_staticMutexes) );
1998320016
assert( winMutex_isInit==1 );
1998420017
p = &winMutex_staticMutexes[iType-2];
1998520018
#ifdef SQLITE_DEBUG
@@ -28783,28 +28816,31 @@
2878328816
do{
2878428817
err = osFallocate(pFile->h, buf.st_size, nSize-buf.st_size);
2878528818
}while( err==EINTR );
2878628819
if( err ) return SQLITE_IOERR_WRITE;
2878728820
#else
28788
- /* If the OS does not have posix_fallocate(), fake it. First use
28789
- ** ftruncate() to set the file size, then write a single byte to
28790
- ** the last byte in each block within the extended region. This
28791
- ** is the same technique used by glibc to implement posix_fallocate()
28792
- ** on systems that do not have a real fallocate() system call.
28821
+ /* If the OS does not have posix_fallocate(), fake it. Write a
28822
+ ** single byte to the last byte in each block that falls entirely
28823
+ ** within the extended region. Then, if required, a single byte
28824
+ ** at offset (nSize-1), to set the size of the file correctly.
28825
+ ** This is a similar technique to that used by glibc on systems
28826
+ ** that do not have a real fallocate() call.
2879328827
*/
2879428828
int nBlk = buf.st_blksize; /* File-system block size */
2879528829
i64 iWrite; /* Next offset to write to */
2879628830
28797
- if( robust_ftruncate(pFile->h, nSize) ){
28798
- pFile->lastErrno = errno;
28799
- return unixLogError(SQLITE_IOERR_TRUNCATE, "ftruncate", pFile->zPath);
28800
- }
2880128831
iWrite = ((buf.st_size + 2*nBlk - 1)/nBlk)*nBlk-1;
28802
- while( iWrite<nSize ){
28832
+ assert( iWrite>=buf.st_size );
28833
+ assert( (iWrite/nBlk)==((buf.st_size+nBlk-1)/nBlk) );
28834
+ assert( ((iWrite+1)%nBlk)==0 );
28835
+ for(/*no-op*/; iWrite<nSize; iWrite+=nBlk ){
2880328836
int nWrite = seekAndWrite(pFile, iWrite, "", 1);
2880428837
if( nWrite!=1 ) return SQLITE_IOERR_WRITE;
28805
- iWrite += nBlk;
28838
+ }
28839
+ if( nSize%nBlk ){
28840
+ int nWrite = seekAndWrite(pFile, nSize-1, "", 1);
28841
+ if( nWrite!=1 ) return SQLITE_IOERR_WRITE;
2880628842
}
2880728843
#endif
2880828844
}
2880928845
}
2881028846
@@ -34018,12 +34054,12 @@
3401834054
*/
3401934055
SQLITE_API int sqlite3_win32_reset_heap(){
3402034056
int rc;
3402134057
MUTEX_LOGIC( sqlite3_mutex *pMaster; ) /* The main static mutex */
3402234058
MUTEX_LOGIC( sqlite3_mutex *pMem; ) /* The memsys static mutex */
34023
- MUTEX_LOGIC( pMaster = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); )
34024
- MUTEX_LOGIC( pMem = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM); )
34059
+ MUTEX_LOGIC( pMaster = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MASTER); )
34060
+ MUTEX_LOGIC( pMem = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MEM); )
3402534061
sqlite3_mutex_enter(pMaster);
3402634062
sqlite3_mutex_enter(pMem);
3402734063
winMemAssertMagic();
3402834064
if( winMemGetHeap()!=NULL && winMemGetOwned() && sqlite3_memory_used()==0 ){
3402934065
/*
@@ -35294,11 +35330,11 @@
3529435330
sqlite3_file *id, /* File to read from */
3529535331
void *pBuf, /* Write content into this buffer */
3529635332
int amt, /* Number of bytes to read */
3529735333
sqlite3_int64 offset /* Begin reading at this offset */
3529835334
){
35299
-#if !SQLITE_OS_WINCE
35335
+#if !SQLITE_OS_WINCE && !defined(SQLITE_WIN32_NO_OVERLAPPED)
3530035336
OVERLAPPED overlapped; /* The offset for ReadFile. */
3530135337
#endif
3530235338
winFile *pFile = (winFile*)id; /* file handle */
3530335339
DWORD nRead; /* Number of bytes actually read from file */
3530435340
int nRetry = 0; /* Number of retrys */
@@ -35326,11 +35362,11 @@
3532635362
offset += nCopy;
3532735363
}
3532835364
}
3532935365
#endif
3533035366
35331
-#if SQLITE_OS_WINCE
35367
+#if SQLITE_OS_WINCE || defined(SQLITE_WIN32_NO_OVERLAPPED)
3533235368
if( winSeekFile(pFile, offset) ){
3533335369
OSTRACE(("READ file=%p, rc=SQLITE_FULL\n", pFile->h));
3533435370
return SQLITE_FULL;
3533535371
}
3533635372
while( !osReadFile(pFile->h, pBuf, amt, &nRead, 0) ){
@@ -35398,32 +35434,32 @@
3539835434
offset += nCopy;
3539935435
}
3540035436
}
3540135437
#endif
3540235438
35403
-#if SQLITE_OS_WINCE
35439
+#if SQLITE_OS_WINCE || defined(SQLITE_WIN32_NO_OVERLAPPED)
3540435440
rc = winSeekFile(pFile, offset);
3540535441
if( rc==0 ){
3540635442
#else
3540735443
{
3540835444
#endif
35409
-#if !SQLITE_OS_WINCE
35445
+#if !SQLITE_OS_WINCE && !defined(SQLITE_WIN32_NO_OVERLAPPED)
3541035446
OVERLAPPED overlapped; /* The offset for WriteFile. */
3541135447
#endif
3541235448
u8 *aRem = (u8 *)pBuf; /* Data yet to be written */
3541335449
int nRem = amt; /* Number of bytes yet to be written */
3541435450
DWORD nWrite; /* Bytes written by each WriteFile() call */
3541535451
DWORD lastErrno = NO_ERROR; /* Value returned by GetLastError() */
3541635452
35417
-#if !SQLITE_OS_WINCE
35453
+#if !SQLITE_OS_WINCE && !defined(SQLITE_WIN32_NO_OVERLAPPED)
3541835454
memset(&overlapped, 0, sizeof(OVERLAPPED));
3541935455
overlapped.Offset = (LONG)(offset & 0xffffffff);
3542035456
overlapped.OffsetHigh = (LONG)((offset>>32) & 0x7fffffff);
3542135457
#endif
3542235458
3542335459
while( nRem>0 ){
35424
-#if SQLITE_OS_WINCE
35460
+#if SQLITE_OS_WINCE || defined(SQLITE_WIN32_NO_OVERLAPPED)
3542535461
if( !osWriteFile(pFile->h, aRem, nRem, &nWrite, 0) ){
3542635462
#else
3542735463
if( !osWriteFile(pFile->h, aRem, nRem, &nWrite, &overlapped) ){
3542835464
#endif
3542935465
if( winRetryIoerr(&nRetry, &lastErrno) ) continue;
@@ -35432,11 +35468,11 @@
3543235468
assert( nWrite==0 || nWrite<=(DWORD)nRem );
3543335469
if( nWrite==0 || nWrite>(DWORD)nRem ){
3543435470
lastErrno = osGetLastError();
3543535471
break;
3543635472
}
35437
-#if !SQLITE_OS_WINCE
35473
+#if !SQLITE_OS_WINCE && !defined(SQLITE_WIN32_NO_OVERLAPPED)
3543835474
offset += nWrite;
3543935475
overlapped.Offset = (LONG)(offset & 0xffffffff);
3544035476
overlapped.OffsetHigh = (LONG)((offset>>32) & 0x7fffffff);
3544135477
#endif
3544235478
aRem += nWrite;
@@ -38978,11 +39014,12 @@
3897839014
SQLITE_PRIVATE int sqlite3PcacheSetPageSize(PCache *pCache, int szPage){
3897939015
assert( pCache->nRef==0 && pCache->pDirty==0 );
3898039016
if( pCache->szPage ){
3898139017
sqlite3_pcache *pNew;
3898239018
pNew = sqlite3GlobalConfig.pcache2.xCreate(
38983
- szPage, pCache->szExtra + sizeof(PgHdr), pCache->bPurgeable
39019
+ szPage, pCache->szExtra + ROUND8(sizeof(PgHdr)),
39020
+ pCache->bPurgeable
3898439021
);
3898539022
if( pNew==0 ) return SQLITE_NOMEM;
3898639023
sqlite3GlobalConfig.pcache2.xCachesize(pNew, numberOfCachePages(pCache));
3898739024
if( pCache->pCache ){
3898839025
sqlite3GlobalConfig.pcache2.xDestroy(pCache->pCache);
@@ -39437,11 +39474,11 @@
3943739474
3943839475
/*
3943939476
** Return the size of the header added by this middleware layer
3944039477
** in the page-cache hierarchy.
3944139478
*/
39442
-SQLITE_PRIVATE int sqlite3HeaderSizePcache(void){ return sizeof(PgHdr); }
39479
+SQLITE_PRIVATE int sqlite3HeaderSizePcache(void){ return ROUND8(sizeof(PgHdr)); }
3944339480
3944439481
3944539482
#if defined(SQLITE_CHECK_PAGES) || defined(SQLITE_DEBUG)
3944639483
/*
3944739484
** For all dirty pages currently in the cache, invoke the specified
@@ -39753,11 +39790,11 @@
3975339790
pcache1Free(pPg);
3975439791
sqlite3_free(p);
3975539792
pPg = 0;
3975639793
}
3975739794
#else
39758
- pPg = pcache1Alloc(sizeof(PgHdr1) + pCache->szPage + pCache->szExtra);
39795
+ pPg = pcache1Alloc(ROUND8(sizeof(PgHdr1)) + pCache->szPage + pCache->szExtra);
3975939796
p = (PgHdr1 *)&((u8 *)pPg)[pCache->szPage];
3976039797
#endif
3976139798
pcache1EnterMutex(pCache->pGroup);
3976239799
3976339800
if( pPg ){
@@ -40441,11 +40478,11 @@
4044140478
}
4044240479
4044340480
/*
4044440481
** Return the size of the header on each page of this PCACHE implementation.
4044540482
*/
40446
-SQLITE_PRIVATE int sqlite3HeaderSizePcache1(void){ return sizeof(PgHdr1); }
40483
+SQLITE_PRIVATE int sqlite3HeaderSizePcache1(void){ return ROUND8(sizeof(PgHdr1)); }
4044740484
4044840485
#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
4044940486
/*
4045040487
** This function is called to free superfluous dynamically allocated memory
4045140488
** held by the pager system. Memory in use by any SQLite pager allocated
@@ -41799,10 +41836,12 @@
4179941836
u8 eLock; /* Current lock held on database file */
4180041837
u8 changeCountDone; /* Set after incrementing the change-counter */
4180141838
u8 setMaster; /* True if a m-j name has been written to jrnl */
4180241839
u8 doNotSpill; /* Do not spill the cache when non-zero */
4180341840
u8 subjInMemory; /* True to use in-memory sub-journals */
41841
+ u8 bUseFetch; /* True to use xFetch() */
41842
+ u8 hasBeenUsed; /* True if any content previously read from this pager*/
4180441843
Pgno dbSize; /* Number of pages in the database */
4180541844
Pgno dbOrigSize; /* dbSize before the current transaction */
4180641845
Pgno dbFileSize; /* Number of pages in the database file */
4180741846
Pgno dbHintSize; /* Value passed to FCNTL_SIZE_HINT call */
4180841847
int errCode; /* One of several kinds of errors */
@@ -41816,13 +41855,13 @@
4181641855
i64 journalOff; /* Current write offset in the journal file */
4181741856
i64 journalHdr; /* Byte offset to previous journal header */
4181841857
sqlite3_backup *pBackup; /* Pointer to list of ongoing backup processes */
4181941858
PagerSavepoint *aSavepoint; /* Array of active savepoints */
4182041859
int nSavepoint; /* Number of elements in aSavepoint[] */
41860
+ u32 iDataVersion; /* Changes whenever database content changes */
4182141861
char dbFileVers[16]; /* Changes whenever database file changes */
4182241862
41823
- u8 bUseFetch; /* True to use xFetch() */
4182441863
int nMmapOut; /* Number of mmap pages currently outstanding */
4182541864
sqlite3_int64 szMmap; /* Desired maximum mmap size */
4182641865
PgHdr *pMmapFreelist; /* List of free mmap page headers (pDirty) */
4182741866
/*
4182841867
** End of the routinely-changing class members
@@ -42834,13 +42873,22 @@
4283442873
4283542874
/*
4283642875
** Discard the entire contents of the in-memory page-cache.
4283742876
*/
4283842877
static void pager_reset(Pager *pPager){
42878
+ pPager->iDataVersion++;
4283942879
sqlite3BackupRestart(pPager->pBackup);
4284042880
sqlite3PcacheClear(pPager->pPCache);
4284142881
}
42882
+
42883
+/*
42884
+** Return the pPager->iDataVersion value
42885
+*/
42886
+SQLITE_PRIVATE u32 sqlite3PagerDataVersion(Pager *pPager){
42887
+ assert( pPager->eState>PAGER_OPEN );
42888
+ return pPager->iDataVersion;
42889
+}
4284242890
4284342891
/*
4284442892
** Free all structures in the Pager.aSavepoint[] array and set both
4284542893
** Pager.aSavepoint and Pager.nSavepoint to zero. Close the sub-journal
4284642894
** if it is open and the pager is not in exclusive mode.
@@ -45040,11 +45088,11 @@
4504045088
Pgno pgno, /* Page number */
4504145089
void *pData, /* xFetch()'d data for this page */
4504245090
PgHdr **ppPage /* OUT: Acquired page object */
4504345091
){
4504445092
PgHdr *p; /* Memory mapped page to return */
45045
-
45093
+
4504645094
if( pPager->pMmapFreelist ){
4504745095
*ppPage = p = pPager->pMmapFreelist;
4504845096
pPager->pMmapFreelist = p->pDirty;
4504945097
p->pDirty = 0;
4505045098
memset(p->pExtra, 0, pPager->nExtra);
@@ -46271,20 +46319,16 @@
4627146319
assert( (pPager->eLock==SHARED_LOCK)
4627246320
|| (pPager->exclusiveMode && pPager->eLock>SHARED_LOCK)
4627346321
);
4627446322
}
4627546323
46276
- if( !pPager->tempFile && (
46277
- pPager->pBackup
46278
- || sqlite3PcachePagecount(pPager->pPCache)>0
46279
- || USEFETCH(pPager)
46280
- )){
46281
- /* The shared-lock has just been acquired on the database file
46282
- ** and there are already pages in the cache (from a previous
46283
- ** read or write transaction). Check to see if the database
46284
- ** has been modified. If the database has changed, flush the
46285
- ** cache.
46324
+ if( !pPager->tempFile && pPager->hasBeenUsed ){
46325
+ /* The shared-lock has just been acquired then check to
46326
+ ** see if the database has been modified. If the database has changed,
46327
+ ** flush the cache. The pPager->hasBeenUsed flag prevents this from
46328
+ ** occurring on the very first access to a file, in order to save a
46329
+ ** single unnecessary sqlite3OsRead() call at the start-up.
4628646330
**
4628746331
** Database changes is detected by looking at 15 bytes beginning
4628846332
** at offset 24 into the file. The first 4 of these 16 bytes are
4628946333
** a 32-bit counter that is incremented with each change. The
4629046334
** other bytes change randomly with each file change when
@@ -46445,10 +46489,11 @@
4644546489
assert( noContent==0 || bMmapOk==0 );
4644646490
4644746491
if( pgno==0 ){
4644846492
return SQLITE_CORRUPT_BKPT;
4644946493
}
46494
+ pPager->hasBeenUsed = 1;
4645046495
4645146496
/* If the pager is in the error state, return an error immediately.
4645246497
** Otherwise, request the page from the PCache layer. */
4645346498
if( pPager->errCode!=SQLITE_OK ){
4645446499
rc = pPager->errCode;
@@ -46594,10 +46639,11 @@
4659446639
sqlite3_pcache_page *pPage;
4659546640
assert( pPager!=0 );
4659646641
assert( pgno!=0 );
4659746642
assert( pPager->pPCache!=0 );
4659846643
pPage = sqlite3PcacheFetch(pPager->pPCache, pgno, 0);
46644
+ assert( pPage==0 || pPager->hasBeenUsed );
4659946645
return sqlite3PcacheFetchFinish(pPager->pPCache, pgno, pPage);
4660046646
}
4660146647
4660246648
/*
4660346649
** Release a page reference.
@@ -47460,10 +47506,11 @@
4746047506
pPager->eState = PAGER_READER;
4746147507
return SQLITE_OK;
4746247508
}
4746347509
4746447510
PAGERTRACE(("COMMIT %d\n", PAGERID(pPager)));
47511
+ pPager->iDataVersion++;
4746547512
rc = pager_end_transaction(pPager, pPager->setMaster, 1);
4746647513
return pager_error(pPager, rc);
4746747514
}
4746847515
4746947516
/*
@@ -50829,11 +50876,11 @@
5082950876
}
5083050877
nCollide = HASHTABLE_NSLOT;
5083150878
for(iKey=walHash(pgno); aHash[iKey]; iKey=walNextHash(iKey)){
5083250879
u32 iFrame = aHash[iKey] + iZero;
5083350880
if( iFrame<=iLast && aPgno[aHash[iKey]]==pgno ){
50834
- /* assert( iFrame>iRead ); -- not true if there is corruption */
50881
+ assert( iFrame>iRead || CORRUPT_DB );
5083550882
iRead = iFrame;
5083650883
}
5083750884
if( (nCollide--)==0 ){
5083850885
return SQLITE_CORRUPT_BKPT;
5083950886
}
@@ -51935,10 +51982,11 @@
5193551982
u8 inTrans; /* TRANS_NONE, TRANS_READ or TRANS_WRITE */
5193651983
u8 sharable; /* True if we can share pBt with another db */
5193751984
u8 locked; /* True if db currently has pBt locked */
5193851985
int wantToLock; /* Number of nested calls to sqlite3BtreeEnter() */
5193951986
int nBackup; /* Number of backup operations reading this btree */
51987
+ u32 iDataVersion; /* Combines with pBt->pPager->iDataVersion */
5194051988
Btree *pNext; /* List of other sharable Btrees from the same db */
5194151989
Btree *pPrev; /* Back pointer of the same list */
5194251990
#ifndef SQLITE_OMIT_SHARED_CACHE
5194351991
BtLock lock; /* Object used to lock page 1 */
5194451992
#endif
@@ -56098,10 +56146,11 @@
5609856146
rc = sqlite3PagerCommitPhaseTwo(pBt->pPager);
5609956147
if( rc!=SQLITE_OK && bCleanup==0 ){
5610056148
sqlite3BtreeLeave(p);
5610156149
return rc;
5610256150
}
56151
+ p->iDataVersion--; /* Compensate for pPager->iDataVersion++; */
5610356152
pBt->inTransaction = TRANS_READ;
5610456153
btreeClearHasContent(pBt);
5610556154
}
5610656155
5610756156
btreeEndTransaction(p);
@@ -56461,11 +56510,11 @@
5646156510
}
5646256511
for(i=0; i<=pCur->iPage; i++){
5646356512
releasePage(pCur->apPage[i]);
5646456513
}
5646556514
unlockBtreeIfUnused(pBt);
56466
- sqlite3DbFree(pBtree->db, pCur->aOverflow);
56515
+ sqlite3_free(pCur->aOverflow);
5646756516
/* sqlite3_free(pCur); */
5646856517
sqlite3BtreeLeave(pBtree);
5646956518
}
5647056519
return SQLITE_OK;
5647156520
}
@@ -56755,10 +56804,11 @@
5675556804
pBuf += a;
5675656805
amt -= a;
5675756806
}else{
5675856807
offset -= pCur->info.nLocal;
5675956808
}
56809
+
5676056810
5676156811
if( rc==SQLITE_OK && amt>0 ){
5676256812
const u32 ovflSize = pBt->usableSize - 4; /* Bytes content per ovfl page */
5676356813
Pgno nextPage;
5676456814
@@ -56773,12 +56823,12 @@
5677356823
** means "not yet known" (the cache is lazily populated).
5677456824
*/
5677556825
if( eOp!=2 && (pCur->curFlags & BTCF_ValidOvfl)==0 ){
5677656826
int nOvfl = (pCur->info.nPayload-pCur->info.nLocal+ovflSize-1)/ovflSize;
5677756827
if( nOvfl>pCur->nOvflAlloc ){
56778
- Pgno *aNew = (Pgno*)sqlite3DbRealloc(
56779
- pCur->pBtree->db, pCur->aOverflow, nOvfl*2*sizeof(Pgno)
56828
+ Pgno *aNew = (Pgno*)sqlite3Realloc(
56829
+ pCur->aOverflow, nOvfl*2*sizeof(Pgno)
5678056830
);
5678156831
if( aNew==0 ){
5678256832
rc = SQLITE_NOMEM;
5678356833
}else{
5678456834
pCur->nOvflAlloc = nOvfl*2;
@@ -56821,10 +56871,11 @@
5682156871
** Note that the aOverflow[] array must be allocated because eOp!=2
5682256872
** here. If eOp==2, then offset==0 and this branch is never taken.
5682356873
*/
5682456874
assert( eOp!=2 );
5682556875
assert( pCur->curFlags & BTCF_ValidOvfl );
56876
+ assert( pCur->pBtree->db==pBt->db );
5682656877
if( pCur->aOverflow[iIdx+1] ){
5682756878
nextPage = pCur->aOverflow[iIdx+1];
5682856879
}else{
5682956880
rc = getOverflowPage(pBt, nextPage, 0, &nextPage);
5683056881
}
@@ -59410,12 +59461,12 @@
5941059461
assert( leafCorrection==4 );
5941159462
if( szCell[nCell]<4 ){
5941259463
/* Do not allow any cells smaller than 4 bytes. If a smaller cell
5941359464
** does exist, pad it with 0x00 bytes. */
5941459465
assert( szCell[nCell]==3 );
59415
- assert( apCell[nCell]==&pTemp[iSpace1-3] );
59416
- pTemp[iSpace1++] = 0x00;
59466
+ assert( apCell[nCell]==&aSpace1[iSpace1-3] );
59467
+ aSpace1[iSpace1++] = 0x00;
5941759468
szCell[nCell] = 4;
5941859469
}
5941959470
}
5942059471
nCell++;
5942159472
}
@@ -60723,10 +60774,17 @@
6072360774
** is read-only, the others are read/write.
6072460775
**
6072560776
** The schema layer numbers meta values differently. At the schema
6072660777
** layer (and the SetCookie and ReadCookie opcodes) the number of
6072760778
** free pages is not visible. So Cookie[0] is the same as Meta[1].
60779
+**
60780
+** This routine treats Meta[BTREE_DATA_VERSION] as a special case. Instead
60781
+** of reading the value out of the header, it instead loads the "DataVersion"
60782
+** from the pager. The BTREE_DATA_VERSION value is not actually stored in the
60783
+** database file. It is a number computed by the pager. But its access
60784
+** pattern is the same as header meta values, and so it is convenient to
60785
+** read it from this routine.
6072860786
*/
6072960787
SQLITE_PRIVATE void sqlite3BtreeGetMeta(Btree *p, int idx, u32 *pMeta){
6073060788
BtShared *pBt = p->pBt;
6073160789
6073260790
sqlite3BtreeEnter(p);
@@ -60733,11 +60791,15 @@
6073360791
assert( p->inTrans>TRANS_NONE );
6073460792
assert( SQLITE_OK==querySharedCacheTableLock(p, MASTER_ROOT, READ_LOCK) );
6073560793
assert( pBt->pPage1 );
6073660794
assert( idx>=0 && idx<=15 );
6073760795
60738
- *pMeta = get4byte(&pBt->pPage1->aData[36 + idx*4]);
60796
+ if( idx==BTREE_DATA_VERSION ){
60797
+ *pMeta = sqlite3PagerDataVersion(pBt->pPager) + p->iDataVersion;
60798
+ }else{
60799
+ *pMeta = get4byte(&pBt->pPage1->aData[36 + idx*4]);
60800
+ }
6073960801
6074060802
/* If auto-vacuum is disabled in this build and this is an auto-vacuum
6074160803
** database, mark the database as read-only. */
6074260804
#ifdef SQLITE_OMIT_AUTOVACUUM
6074360805
if( idx==BTREE_LARGEST_ROOT_PAGE && *pMeta>0 ){
@@ -60824,11 +60886,11 @@
6082460886
if( pPage->leaf ){
6082560887
do {
6082660888
if( pCur->iPage==0 ){
6082760889
/* All pages of the b-tree have been visited. Return successfully. */
6082860890
*pnEntry = nEntry;
60829
- return SQLITE_OK;
60891
+ return moveToRoot(pCur);
6083060892
}
6083160893
moveToParent(pCur);
6083260894
}while ( pCur->aiIdx[pCur->iPage]>=pCur->apPage[pCur->iPage]->nCell );
6083360895
6083460896
pCur->aiIdx[pCur->iPage]++;
@@ -61680,11 +61742,11 @@
6168061742
}
6168161743
6168261744
/*
6168361745
** Return the size of the header added to each page by this module.
6168461746
*/
61685
-SQLITE_PRIVATE int sqlite3HeaderSizeBtree(void){ return sizeof(MemPage); }
61747
+SQLITE_PRIVATE int sqlite3HeaderSizeBtree(void){ return ROUND8(sizeof(MemPage)); }
6168661748
6168761749
/************** End of btree.c ***********************************************/
6168861750
/************** Begin file backup.c ******************************************/
6168961751
/*
6169061752
** 2009 January 28
@@ -64444,36 +64506,39 @@
6444464506
**
6444564507
** assert( sqlite3VdbeAssertMayAbort(pParse->pVdbe, pParse->mayAbort) );
6444664508
*/
6444764509
SQLITE_PRIVATE int sqlite3VdbeAssertMayAbort(Vdbe *v, int mayAbort){
6444864510
int hasAbort = 0;
64511
+ int hasFkCounter = 0;
6444964512
Op *pOp;
6445064513
VdbeOpIter sIter;
6445164514
memset(&sIter, 0, sizeof(sIter));
6445264515
sIter.v = v;
6445364516
6445464517
while( (pOp = opIterNext(&sIter))!=0 ){
6445564518
int opcode = pOp->opcode;
6445664519
if( opcode==OP_Destroy || opcode==OP_VUpdate || opcode==OP_VRename
64457
-#ifndef SQLITE_OMIT_FOREIGN_KEY
64458
- || (opcode==OP_FkCounter && pOp->p1==0 && pOp->p2==1)
64459
-#endif
6446064520
|| ((opcode==OP_Halt || opcode==OP_HaltIfNull)
6446164521
&& ((pOp->p1&0xff)==SQLITE_CONSTRAINT && pOp->p2==OE_Abort))
6446264522
){
6446364523
hasAbort = 1;
6446464524
break;
6446564525
}
64526
+#ifndef SQLITE_OMIT_FOREIGN_KEY
64527
+ if( opcode==OP_FkCounter && pOp->p1==0 && pOp->p2==1 ){
64528
+ hasFkCounter = 1;
64529
+ }
64530
+#endif
6446664531
}
6446764532
sqlite3DbFree(v->db, sIter.apSub);
6446864533
6446964534
/* Return true if hasAbort==mayAbort. Or if a malloc failure occurred.
6447064535
** If malloc failed, then the while() loop above may not have iterated
6447164536
** through all opcodes and hasAbort may be set incorrectly. Return
6447264537
** true for this case to prevent the assert() in the callers frame
6447364538
** from failing. */
64474
- return ( v->db->mallocFailed || hasAbort==mayAbort );
64539
+ return ( v->db->mallocFailed || hasAbort==mayAbort || hasFkCounter );
6447564540
}
6447664541
#endif /* SQLITE_DEBUG - the sqlite3AssertMayAbort() function */
6447764542
6447864543
/*
6447964544
** Loop through the program looking for P2 values that are negative
@@ -68593,11 +68658,14 @@
6859368658
#ifndef SQLITE_OMIT_WAL
6859468659
int i;
6859568660
for(i=0; i<db->nDb; i++){
6859668661
Btree *pBt = db->aDb[i].pBt;
6859768662
if( pBt ){
68598
- int nEntry = sqlite3PagerWalCallback(sqlite3BtreePager(pBt));
68663
+ int nEntry;
68664
+ sqlite3BtreeEnter(pBt);
68665
+ nEntry = sqlite3PagerWalCallback(sqlite3BtreePager(pBt));
68666
+ sqlite3BtreeLeave(pBt);
6859968667
if( db->xWalCallback && nEntry>0 && rc==SQLITE_OK ){
6860068668
rc = db->xWalCallback(db->pWalArg, db, db->aDb[i].zName, nEntry);
6860168669
}
6860268670
}
6860368671
}
@@ -68773,11 +68841,10 @@
6877368841
** program counter to 0 to ensure that when the statement is
6877468842
** finalized or reset the parser error message is available via
6877568843
** sqlite3_errmsg() and sqlite3_errcode().
6877668844
*/
6877768845
const char *zErr = (const char *)sqlite3_value_text(db->pErr);
68778
- assert( zErr!=0 || db->mallocFailed );
6877968846
sqlite3DbFree(db, v->zErrMsg);
6878068847
if( !db->mallocFailed ){
6878168848
v->zErrMsg = sqlite3DbStrDup(db, zErr);
6878268849
v->rc = rc2;
6878368850
} else {
@@ -77135,11 +77202,11 @@
7713577202
/*
7713677203
** Hard-coded maximum amount of data to accumulate in memory before flushing
7713777204
** to a level 0 PMA. The purpose of this limit is to prevent various integer
7713877205
** overflows. 512MiB.
7713977206
*/
77140
-#define SQLITE_MAX_MXPMASIZE (1<<29)
77207
+#define SQLITE_MAX_PMASZ (1<<29)
7714177208
7714277209
/*
7714377210
** Private objects used by the sorter
7714477211
*/
7714577212
typedef struct MergeEngine MergeEngine; /* Merge PMAs together */
@@ -77431,15 +77498,10 @@
7743177498
**
7743277499
** void *SRVAL(SorterRecord *p) { return (void*)&p[1]; }
7743377500
*/
7743477501
#define SRVAL(p) ((void*)((SorterRecord*)(p) + 1))
7743577502
77436
-/* The minimum PMA size is set to this value multiplied by the database
77437
-** page size in bytes. */
77438
-#ifndef SQLITE_SORTER_PMASZ
77439
-# define SQLITE_SORTER_PMASZ 10
77440
-#endif
7744177503
7744277504
/* Maximum number of PMAs that a single MergeEngine can merge */
7744377505
#define SORTER_MAX_MERGE_COUNT 16
7744477506
7744577507
static int vdbeIncrSwap(IncrMerger*);
@@ -77834,14 +77896,15 @@
7783477896
SortSubtask *pTask = &pSorter->aTask[i];
7783577897
pTask->pSorter = pSorter;
7783677898
}
7783777899
7783877900
if( !sqlite3TempInMemory(db) ){
77839
- pSorter->mnPmaSize = SQLITE_SORTER_PMASZ * pgsz;
77901
+ u32 szPma = sqlite3GlobalConfig.szPma;
77902
+ pSorter->mnPmaSize = szPma * pgsz;
7784077903
mxCache = db->aDb[0].pSchema->cache_size;
77841
- if( mxCache<SQLITE_SORTER_PMASZ ) mxCache = SQLITE_SORTER_PMASZ;
77842
- pSorter->mxPmaSize = MIN((i64)mxCache*pgsz, SQLITE_MAX_MXPMASIZE);
77904
+ if( mxCache<(int)szPma ) mxCache = (int)szPma;
77905
+ pSorter->mxPmaSize = MIN((i64)mxCache*pgsz, SQLITE_MAX_PMASZ);
7784377906
7784477907
/* EVIDENCE-OF: R-26747-61719 When the application provides any amount of
7784577908
** scratch memory using SQLITE_CONFIG_SCRATCH, SQLite avoids unnecessary
7784677909
** large heap allocations.
7784777910
*/
@@ -78115,16 +78178,16 @@
7811578178
** Whether or not the file does end up memory mapped of course depends on
7811678179
** the specific VFS implementation.
7811778180
*/
7811878181
static void vdbeSorterExtendFile(sqlite3 *db, sqlite3_file *pFd, i64 nByte){
7811978182
if( nByte<=(i64)(db->nMaxSorterMmap) && pFd->pMethods->iVersion>=3 ){
78120
- int rc = sqlite3OsTruncate(pFd, nByte);
78121
- if( rc==SQLITE_OK ){
78122
- void *p = 0;
78123
- sqlite3OsFetch(pFd, 0, (int)nByte, &p);
78124
- sqlite3OsUnfetch(pFd, 0, p);
78125
- }
78183
+ void *p = 0;
78184
+ int chunksize = 4*1024;
78185
+ sqlite3OsFileControlHint(pFd, SQLITE_FCNTL_CHUNK_SIZE, &chunksize);
78186
+ sqlite3OsFileControlHint(pFd, SQLITE_FCNTL_SIZE_HINT, &nByte);
78187
+ sqlite3OsFetch(pFd, 0, (int)nByte, &p);
78188
+ sqlite3OsUnfetch(pFd, 0, p);
7812678189
}
7812778190
}
7812878191
#else
7812978192
# define vdbeSorterExtendFile(x,y,z)
7813078193
#endif
@@ -87302,11 +87365,11 @@
8730287365
8730387366
p->iGet = -1;
8730487367
p->mxSample = mxSample;
8730587368
p->nPSample = (tRowcnt)(sqlite3_value_int64(argv[2])/(mxSample/3+1) + 1);
8730687369
p->current.anLt = &p->current.anEq[nColUp];
87307
- p->iPrn = nCol*0x689e962d ^ sqlite3_value_int(argv[2])*0xd0944565;
87370
+ p->iPrn = 0x689e962d*(u32)nCol ^ 0xd0944565*(u32)sqlite3_value_int(argv[2]);
8730887371
8730987372
/* Set up the Stat4Accum.a[] and aBest[] arrays */
8731087373
p->a = (struct Stat4Sample*)&p->current.anLt[nColUp];
8731187374
p->aBest = &p->a[mxSample];
8731287375
pSpace = (u8*)(&p->a[mxSample+nCol]);
@@ -88895,17 +88958,19 @@
8889588958
}else if( aNew->pSchema->file_format && aNew->pSchema->enc!=ENC(db) ){
8889688959
zErrDyn = sqlite3MPrintf(db,
8889788960
"attached databases must use the same text encoding as main database");
8889888961
rc = SQLITE_ERROR;
8889988962
}
88963
+ sqlite3BtreeEnter(aNew->pBt);
8890088964
pPager = sqlite3BtreePager(aNew->pBt);
8890188965
sqlite3PagerLockingMode(pPager, db->dfltLockMode);
8890288966
sqlite3BtreeSecureDelete(aNew->pBt,
8890388967
sqlite3BtreeSecureDelete(db->aDb[0].pBt,-1) );
8890488968
#ifndef SQLITE_OMIT_PAGER_PRAGMAS
8890588969
sqlite3BtreeSetPagerFlags(aNew->pBt, 3 | (db->flags & PAGER_FLAGS_MASK));
8890688970
#endif
88971
+ sqlite3BtreeLeave(aNew->pBt);
8890788972
}
8890888973
aNew->safety_level = 3;
8890988974
aNew->zName = sqlite3DbStrDup(db, zName);
8891088975
if( rc==SQLITE_OK && aNew->zName==0 ){
8891188976
rc = SQLITE_NOMEM;
@@ -90027,11 +90092,10 @@
9002790092
*/
9002890093
static void freeIndex(sqlite3 *db, Index *p){
9002990094
#ifndef SQLITE_OMIT_ANALYZE
9003090095
sqlite3DeleteIndexSamples(db, p);
9003190096
#endif
90032
- if( db==0 || db->pnBytesFreed==0 ) sqlite3KeyInfoUnref(p->pKeyInfo);
9003390097
sqlite3ExprDelete(db, p->pPartIdxWhere);
9003490098
sqlite3DbFree(db, p->zColAff);
9003590099
if( p->isResized ) sqlite3DbFree(db, p->azColl);
9003690100
#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
9003790101
sqlite3_free(p->aiRowEst);
@@ -91306,10 +91370,23 @@
9130691370
if( pPk==0 ) return;
9130791371
pPk->idxType = SQLITE_IDXTYPE_PRIMARYKEY;
9130891372
pTab->iPKey = -1;
9130991373
}else{
9131091374
pPk = sqlite3PrimaryKeyIndex(pTab);
91375
+ /*
91376
+ ** Remove all redundant columns from the PRIMARY KEY. For example, change
91377
+ ** "PRIMARY KEY(a,b,a,b,c,b,c,d)" into just "PRIMARY KEY(a,b,c,d)". Later
91378
+ ** code assumes the PRIMARY KEY contains no repeated columns.
91379
+ */
91380
+ for(i=j=1; i<pPk->nKeyCol; i++){
91381
+ if( hasColumn(pPk->aiColumn, j, pPk->aiColumn[i]) ){
91382
+ pPk->nColumn--;
91383
+ }else{
91384
+ pPk->aiColumn[j++] = pPk->aiColumn[i];
91385
+ }
91386
+ }
91387
+ pPk->nKeyCol = j;
9131191388
}
9131291389
pPk->isCovering = 1;
9131391390
assert( pPk!=0 );
9131491391
nPk = pPk->nKeyCol;
9131591392
@@ -93782,44 +93859,35 @@
9378293859
**
9378393860
** The caller should invoke sqlite3KeyInfoUnref() on the returned object
9378493861
** when it has finished using it.
9378593862
*/
9378693863
SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoOfIndex(Parse *pParse, Index *pIdx){
93864
+ int i;
93865
+ int nCol = pIdx->nColumn;
93866
+ int nKey = pIdx->nKeyCol;
93867
+ KeyInfo *pKey;
9378793868
if( pParse->nErr ) return 0;
93788
-#ifndef SQLITE_OMIT_SHARED_CACHE
93789
- if( pIdx->pKeyInfo && pIdx->pKeyInfo->db!=pParse->db ){
93790
- sqlite3KeyInfoUnref(pIdx->pKeyInfo);
93791
- pIdx->pKeyInfo = 0;
93792
- }
93793
-#endif
93794
- if( pIdx->pKeyInfo==0 ){
93795
- int i;
93796
- int nCol = pIdx->nColumn;
93797
- int nKey = pIdx->nKeyCol;
93798
- KeyInfo *pKey;
93799
- if( pIdx->uniqNotNull ){
93800
- pKey = sqlite3KeyInfoAlloc(pParse->db, nKey, nCol-nKey);
93801
- }else{
93802
- pKey = sqlite3KeyInfoAlloc(pParse->db, nCol, 0);
93803
- }
93804
- if( pKey ){
93805
- assert( sqlite3KeyInfoIsWriteable(pKey) );
93806
- for(i=0; i<nCol; i++){
93807
- char *zColl = pIdx->azColl[i];
93808
- assert( zColl!=0 );
93809
- pKey->aColl[i] = strcmp(zColl,"BINARY")==0 ? 0 :
93810
- sqlite3LocateCollSeq(pParse, zColl);
93811
- pKey->aSortOrder[i] = pIdx->aSortOrder[i];
93812
- }
93813
- if( pParse->nErr ){
93814
- sqlite3KeyInfoUnref(pKey);
93815
- }else{
93816
- pIdx->pKeyInfo = pKey;
93817
- }
93818
- }
93819
- }
93820
- return sqlite3KeyInfoRef(pIdx->pKeyInfo);
93869
+ if( pIdx->uniqNotNull ){
93870
+ pKey = sqlite3KeyInfoAlloc(pParse->db, nKey, nCol-nKey);
93871
+ }else{
93872
+ pKey = sqlite3KeyInfoAlloc(pParse->db, nCol, 0);
93873
+ }
93874
+ if( pKey ){
93875
+ assert( sqlite3KeyInfoIsWriteable(pKey) );
93876
+ for(i=0; i<nCol; i++){
93877
+ char *zColl = pIdx->azColl[i];
93878
+ assert( zColl!=0 );
93879
+ pKey->aColl[i] = strcmp(zColl,"BINARY")==0 ? 0 :
93880
+ sqlite3LocateCollSeq(pParse, zColl);
93881
+ pKey->aSortOrder[i] = pIdx->aSortOrder[i];
93882
+ }
93883
+ if( pParse->nErr ){
93884
+ sqlite3KeyInfoUnref(pKey);
93885
+ pKey = 0;
93886
+ }
93887
+ }
93888
+ return pKey;
9382193889
}
9382293890
9382393891
#ifndef SQLITE_OMIT_CTE
9382493892
/*
9382593893
** This routine is invoked once per CTE by the parser while parsing a
@@ -97436,11 +97504,11 @@
9743697504
assert( nIncr==1 );
9743797505
sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_FOREIGNKEY,
9743897506
OE_Abort, 0, P4_STATIC, P5_ConstraintFK);
9743997507
}else{
9744097508
if( nIncr>0 && pFKey->isDeferred==0 ){
97441
- sqlite3ParseToplevel(pParse)->mayAbort = 1;
97509
+ sqlite3MayAbort(pParse);
9744297510
}
9744397511
sqlite3VdbeAddOp2(v, OP_FkCounter, pFKey->isDeferred, nIncr);
9744497512
}
9744597513
9744697514
sqlite3VdbeResolveLabel(v, iOk);
@@ -97507,10 +97575,14 @@
9750797575
** This function is called to generate code executed when a row is deleted
9750897576
** from the parent table of foreign key constraint pFKey and, if pFKey is
9750997577
** deferred, when a row is inserted into the same table. When generating
9751097578
** code for an SQL UPDATE operation, this function may be called twice -
9751197579
** once to "delete" the old row and once to "insert" the new row.
97580
+**
97581
+** Parameter nIncr is passed -1 when inserting a row (as this may decrease
97582
+** the number of FK violations in the db) or +1 when deleting one (as this
97583
+** may increase the number of FK constraint problems).
9751297584
**
9751397585
** The code generated by this function scans through the rows in the child
9751497586
** table that correspond to the parent table row being deleted or inserted.
9751597587
** For each child row found, one of the following actions is taken:
9751697588
**
@@ -97624,17 +97696,13 @@
9762497696
sNameContext.pSrcList = pSrc;
9762597697
sNameContext.pParse = pParse;
9762697698
sqlite3ResolveExprNames(&sNameContext, pWhere);
9762797699
9762897700
/* Create VDBE to loop through the entries in pSrc that match the WHERE
97629
- ** clause. If the constraint is not deferred, throw an exception for
97630
- ** each row found. Otherwise, for deferred constraints, increment the
97631
- ** deferred constraint counter by nIncr for each row selected. */
97701
+ ** clause. For each row found, increment either the deferred or immediate
97702
+ ** foreign key constraint counter. */
9763297703
pWInfo = sqlite3WhereBegin(pParse, pSrc, pWhere, 0, 0, 0, 0);
97633
- if( nIncr>0 && pFKey->isDeferred==0 ){
97634
- sqlite3ParseToplevel(pParse)->mayAbort = 1;
97635
- }
9763697704
sqlite3VdbeAddOp2(v, OP_FkCounter, pFKey->isDeferred, nIncr);
9763797705
if( pWInfo ){
9763897706
sqlite3WhereEnd(pWInfo);
9763997707
}
9764097708
@@ -97808,10 +97876,28 @@
9780897876
}
9780997877
}
9781097878
}
9781197879
return 0;
9781297880
}
97881
+
97882
+/*
97883
+** Return true if the parser passed as the first argument is being
97884
+** used to code a trigger that is really a "SET NULL" action belonging
97885
+** to trigger pFKey.
97886
+*/
97887
+static int isSetNullAction(Parse *pParse, FKey *pFKey){
97888
+ Parse *pTop = sqlite3ParseToplevel(pParse);
97889
+ if( pTop->pTriggerPrg ){
97890
+ Trigger *p = pTop->pTriggerPrg->pTrigger;
97891
+ if( (p==pFKey->apTrigger[0] && pFKey->aAction[0]==OE_SetNull)
97892
+ || (p==pFKey->apTrigger[1] && pFKey->aAction[1]==OE_SetNull)
97893
+ ){
97894
+ return 1;
97895
+ }
97896
+ }
97897
+ return 0;
97898
+}
9781397899
9781497900
/*
9781597901
** This function is called when inserting, deleting or updating a row of
9781697902
** table pTab to generate VDBE code to perform foreign key constraint
9781797903
** processing for the operation.
@@ -97861,11 +97947,11 @@
9786197947
Index *pIdx = 0; /* Index on key columns in pTo */
9786297948
int *aiFree = 0;
9786397949
int *aiCol;
9786497950
int iCol;
9786597951
int i;
97866
- int isIgnore = 0;
97952
+ int bIgnore = 0;
9786797953
9786897954
if( aChange
9786997955
&& sqlite3_stricmp(pTab->zName, pFKey->zTo)!=0
9787097956
&& fkChildIsModified(pTab, pFKey, aChange, bChngRowid)==0
9787197957
){
@@ -97920,11 +98006,11 @@
9792098006
** values read from the parent table are NULL. */
9792198007
if( db->xAuth ){
9792298008
int rcauth;
9792398009
char *zCol = pTo->aCol[pIdx ? pIdx->aiColumn[i] : pTo->iPKey].zName;
9792498010
rcauth = sqlite3AuthReadCol(pParse, pTo->zName, zCol, iDb);
97925
- isIgnore = (rcauth==SQLITE_IGNORE);
98011
+ bIgnore = (rcauth==SQLITE_IGNORE);
9792698012
}
9792798013
#endif
9792898014
}
9792998015
9793098016
/* Take a shared-cache advisory read-lock on the parent table. Allocate
@@ -97935,16 +98021,22 @@
9793598021
9793698022
if( regOld!=0 ){
9793798023
/* A row is being removed from the child table. Search for the parent.
9793898024
** If the parent does not exist, removing the child row resolves an
9793998025
** outstanding foreign key constraint violation. */
97940
- fkLookupParent(pParse, iDb, pTo, pIdx, pFKey, aiCol, regOld, -1,isIgnore);
98026
+ fkLookupParent(pParse, iDb, pTo, pIdx, pFKey, aiCol, regOld, -1, bIgnore);
9794198027
}
97942
- if( regNew!=0 ){
98028
+ if( regNew!=0 && !isSetNullAction(pParse, pFKey) ){
9794398029
/* A row is being added to the child table. If a parent row cannot
97944
- ** be found, adding the child row has violated the FK constraint. */
97945
- fkLookupParent(pParse, iDb, pTo, pIdx, pFKey, aiCol, regNew, +1,isIgnore);
98030
+ ** be found, adding the child row has violated the FK constraint.
98031
+ **
98032
+ ** If this operation is being performed as part of a trigger program
98033
+ ** that is actually a "SET NULL" action belonging to this very
98034
+ ** foreign key, then omit this scan altogether. As all child key
98035
+ ** values are guaranteed to be NULL, it is not possible for adding
98036
+ ** this row to cause an FK violation. */
98037
+ fkLookupParent(pParse, iDb, pTo, pIdx, pFKey, aiCol, regNew, +1, bIgnore);
9794698038
}
9794798039
9794898040
sqlite3DbFree(db, aiFree);
9794998041
}
9795098042
@@ -97961,12 +98053,12 @@
9796198053
9796298054
if( !pFKey->isDeferred && !(db->flags & SQLITE_DeferFKs)
9796398055
&& !pParse->pToplevel && !pParse->isMultiWrite
9796498056
){
9796598057
assert( regOld==0 && regNew!=0 );
97966
- /* Inserting a single row into a parent table cannot cause an immediate
97967
- ** foreign key violation. So do nothing in this case. */
98058
+ /* Inserting a single row into a parent table cannot cause (or fix)
98059
+ ** an immediate foreign key violation. So do nothing in this case. */
9796898060
continue;
9796998061
}
9797098062
9797198063
if( sqlite3FkLocateIndex(pParse, pTab, pFKey, &pIdx, &aiCol) ){
9797298064
if( !isIgnoreErrors || db->mallocFailed ) return;
@@ -97986,17 +98078,32 @@
9798698078
9798798079
if( regNew!=0 ){
9798898080
fkScanChildren(pParse, pSrc, pTab, pIdx, pFKey, aiCol, regNew, -1);
9798998081
}
9799098082
if( regOld!=0 ){
97991
- /* If there is a RESTRICT action configured for the current operation
97992
- ** on the parent table of this FK, then throw an exception
97993
- ** immediately if the FK constraint is violated, even if this is a
97994
- ** deferred trigger. That's what RESTRICT means. To defer checking
97995
- ** the constraint, the FK should specify NO ACTION (represented
97996
- ** using OE_None). NO ACTION is the default. */
98083
+ int eAction = pFKey->aAction[aChange!=0];
9799798084
fkScanChildren(pParse, pSrc, pTab, pIdx, pFKey, aiCol, regOld, 1);
98085
+ /* If this is a deferred FK constraint, or a CASCADE or SET NULL
98086
+ ** action applies, then any foreign key violations caused by
98087
+ ** removing the parent key will be rectified by the action trigger.
98088
+ ** So do not set the "may-abort" flag in this case.
98089
+ **
98090
+ ** Note 1: If the FK is declared "ON UPDATE CASCADE", then the
98091
+ ** may-abort flag will eventually be set on this statement anyway
98092
+ ** (when this function is called as part of processing the UPDATE
98093
+ ** within the action trigger).
98094
+ **
98095
+ ** Note 2: At first glance it may seem like SQLite could simply omit
98096
+ ** all OP_FkCounter related scans when either CASCADE or SET NULL
98097
+ ** applies. The trouble starts if the CASCADE or SET NULL action
98098
+ ** trigger causes other triggers or action rules attached to the
98099
+ ** child table to fire. In these cases the fk constraint counters
98100
+ ** might be set incorrectly if any OP_FkCounter related scans are
98101
+ ** omitted. */
98102
+ if( !pFKey->isDeferred && eAction!=OE_Cascade && eAction!=OE_SetNull ){
98103
+ sqlite3MayAbort(pParse);
98104
+ }
9799898105
}
9799998106
pItem->zName = 0;
9800098107
sqlite3SrcListDelete(db, pSrc);
9800198108
}
9800298109
sqlite3DbFree(db, aiCol);
@@ -101895,10 +102002,11 @@
101895102002
#define PragTyp_KEY 38
101896102003
#define PragTyp_REKEY 39
101897102004
#define PragTyp_LOCK_STATUS 40
101898102005
#define PragTyp_PARSER_TRACE 41
101899102006
#define PragFlag_NeedSchema 0x01
102007
+#define PragFlag_ReadOnly 0x02
101900102008
static const struct sPragmaNames {
101901102009
const char *const zName; /* Name of pragma */
101902102010
u8 ePragTyp; /* PragTyp_XXX value */
101903102011
u8 mPragFlag; /* Zero or more PragFlag_XXX values */
101904102012
u32 iArg; /* Extra argument */
@@ -101911,11 +102019,11 @@
101911102019
#endif
101912102020
#if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
101913102021
{ /* zName: */ "application_id",
101914102022
/* ePragTyp: */ PragTyp_HEADER_VALUE,
101915102023
/* ePragFlag: */ 0,
101916
- /* iArg: */ 0 },
102024
+ /* iArg: */ BTREE_APPLICATION_ID },
101917102025
#endif
101918102026
#if !defined(SQLITE_OMIT_AUTOVACUUM)
101919102027
{ /* zName: */ "auto_vacuum",
101920102028
/* ePragTyp: */ PragTyp_AUTO_VACUUM,
101921102029
/* ePragFlag: */ PragFlag_NeedSchema,
@@ -101977,10 +102085,16 @@
101977102085
{ /* zName: */ "data_store_directory",
101978102086
/* ePragTyp: */ PragTyp_DATA_STORE_DIRECTORY,
101979102087
/* ePragFlag: */ 0,
101980102088
/* iArg: */ 0 },
101981102089
#endif
102090
+#if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
102091
+ { /* zName: */ "data_version",
102092
+ /* ePragTyp: */ PragTyp_HEADER_VALUE,
102093
+ /* ePragFlag: */ PragFlag_ReadOnly,
102094
+ /* iArg: */ BTREE_DATA_VERSION },
102095
+#endif
101982102096
#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
101983102097
{ /* zName: */ "database_list",
101984102098
/* ePragTyp: */ PragTyp_DATABASE_LIST,
101985102099
/* ePragFlag: */ PragFlag_NeedSchema,
101986102100
/* iArg: */ 0 },
@@ -102032,12 +102146,12 @@
102032102146
#endif
102033102147
#endif
102034102148
#if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
102035102149
{ /* zName: */ "freelist_count",
102036102150
/* ePragTyp: */ PragTyp_HEADER_VALUE,
102037
- /* ePragFlag: */ 0,
102038
- /* iArg: */ 0 },
102151
+ /* ePragFlag: */ PragFlag_ReadOnly,
102152
+ /* iArg: */ BTREE_FREE_PAGE_COUNT },
102039102153
#endif
102040102154
#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
102041102155
{ /* zName: */ "full_column_names",
102042102156
/* ePragTyp: */ PragTyp_FLAG,
102043102157
/* ePragFlag: */ 0,
@@ -102185,11 +102299,11 @@
102185102299
#endif
102186102300
#if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
102187102301
{ /* zName: */ "schema_version",
102188102302
/* ePragTyp: */ PragTyp_HEADER_VALUE,
102189102303
/* ePragFlag: */ 0,
102190
- /* iArg: */ 0 },
102304
+ /* iArg: */ BTREE_SCHEMA_VERSION },
102191102305
#endif
102192102306
#if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
102193102307
{ /* zName: */ "secure_delete",
102194102308
/* ePragTyp: */ PragTyp_SECURE_DELETE,
102195102309
/* ePragFlag: */ 0,
@@ -102251,11 +102365,11 @@
102251102365
/* iArg: */ 0 },
102252102366
#if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
102253102367
{ /* zName: */ "user_version",
102254102368
/* ePragTyp: */ PragTyp_HEADER_VALUE,
102255102369
/* ePragFlag: */ 0,
102256
- /* iArg: */ 0 },
102370
+ /* iArg: */ BTREE_USER_VERSION },
102257102371
#endif
102258102372
#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
102259102373
#if defined(SQLITE_DEBUG)
102260102374
{ /* zName: */ "vdbe_addoptrace",
102261102375
/* ePragTyp: */ PragTyp_FLAG,
@@ -102294,11 +102408,11 @@
102294102408
/* ePragTyp: */ PragTyp_FLAG,
102295102409
/* ePragFlag: */ 0,
102296102410
/* iArg: */ SQLITE_WriteSchema|SQLITE_RecoveryMode },
102297102411
#endif
102298102412
};
102299
-/* Number of pragmas: 57 on by default, 70 total. */
102413
+/* Number of pragmas: 58 on by default, 71 total. */
102300102414
/* End of the automatically generated pragma table.
102301102415
***************************************************************************/
102302102416
102303102417
/*
102304102418
** Interpret the given string as a safety level. Return 0 for OFF,
@@ -103904,11 +104018,12 @@
103904104018
!(DbHasProperty(db, 0, DB_SchemaLoaded)) ||
103905104019
DbHasProperty(db, 0, DB_Empty)
103906104020
){
103907104021
for(pEnc=&encnames[0]; pEnc->zName; pEnc++){
103908104022
if( 0==sqlite3StrICmp(zRight, pEnc->zName) ){
103909
- ENC(pParse->db) = pEnc->enc ? pEnc->enc : SQLITE_UTF16NATIVE;
104023
+ SCHEMA_ENC(db) = ENC(db) =
104024
+ pEnc->enc ? pEnc->enc : SQLITE_UTF16NATIVE;
103910104025
break;
103911104026
}
103912104027
}
103913104028
if( !pEnc->zName ){
103914104029
sqlite3ErrorMsg(pParse, "unsupported encoding: %s", zRight);
@@ -103949,28 +104064,13 @@
103949104064
**
103950104065
** The user-version is not used internally by SQLite. It may be used by
103951104066
** applications for any purpose.
103952104067
*/
103953104068
case PragTyp_HEADER_VALUE: {
103954
- int iCookie; /* Cookie index. 1 for schema-cookie, 6 for user-cookie. */
104069
+ int iCookie = aPragmaNames[mid].iArg; /* Which cookie to read or write */
103955104070
sqlite3VdbeUsesBtree(v, iDb);
103956
- switch( zLeft[0] ){
103957
- case 'a': case 'A':
103958
- iCookie = BTREE_APPLICATION_ID;
103959
- break;
103960
- case 'f': case 'F':
103961
- iCookie = BTREE_FREE_PAGE_COUNT;
103962
- break;
103963
- case 's': case 'S':
103964
- iCookie = BTREE_SCHEMA_VERSION;
103965
- break;
103966
- default:
103967
- iCookie = BTREE_USER_VERSION;
103968
- break;
103969
- }
103970
-
103971
- if( zRight && iCookie!=BTREE_FREE_PAGE_COUNT ){
104071
+ if( zRight && (aPragmaNames[mid].mPragFlag & PragFlag_ReadOnly)==0 ){
103972104072
/* Write the specified cookie value */
103973104073
static const VdbeOpList setCookie[] = {
103974104074
{ OP_Transaction, 0, 1, 0}, /* 0 */
103975104075
{ OP_Integer, 0, 1, 0}, /* 1 */
103976104076
{ OP_SetCookie, 0, 0, 1}, /* 2 */
@@ -104612,13 +104712,15 @@
104612104712
SQLITE_PRIVATE int sqlite3Init(sqlite3 *db, char **pzErrMsg){
104613104713
int i, rc;
104614104714
int commit_internal = !(db->flags&SQLITE_InternChanges);
104615104715
104616104716
assert( sqlite3_mutex_held(db->mutex) );
104717
+ assert( sqlite3BtreeHoldsMutex(db->aDb[0].pBt) );
104617104718
assert( db->init.busy==0 );
104618104719
rc = SQLITE_OK;
104619104720
db->init.busy = 1;
104721
+ ENC(db) = SCHEMA_ENC(db);
104620104722
for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
104621104723
if( DbHasProperty(db, i, DB_SchemaLoaded) || i==1 ) continue;
104622104724
rc = sqlite3InitOne(db, i, pzErrMsg);
104623104725
if( rc ){
104624104726
sqlite3ResetOneSchema(db, i);
@@ -110756,11 +110858,11 @@
110756110858
){
110757110859
int rc;
110758110860
TabResult res;
110759110861
110760110862
#ifdef SQLITE_ENABLE_API_ARMOR
110761
- if( pazResult==0 ) return SQLITE_MISUSE_BKPT;
110863
+ if( !sqlite3SafetyCheckOk(db) || pazResult==0 ) return SQLITE_MISUSE_BKPT;
110762110864
#endif
110763110865
*pazResult = 0;
110764110866
if( pnColumn ) *pnColumn = 0;
110765110867
if( pnRow ) *pnRow = 0;
110766110868
if( pzErrMsg ) *pzErrMsg = 0;
@@ -118626,11 +118728,10 @@
118626118728
sqlite3_free(p->u.vtab.idxStr);
118627118729
p->u.vtab.needFree = 0;
118628118730
p->u.vtab.idxStr = 0;
118629118731
}else if( (p->wsFlags & WHERE_AUTO_INDEX)!=0 && p->u.btree.pIndex!=0 ){
118630118732
sqlite3DbFree(db, p->u.btree.pIndex->zColAff);
118631
- sqlite3KeyInfoUnref(p->u.btree.pIndex->pKeyInfo);
118632118733
sqlite3DbFree(db, p->u.btree.pIndex);
118633118734
p->u.btree.pIndex = 0;
118634118735
}
118635118736
}
118636118737
}
@@ -125633,10 +125734,13 @@
125633125734
u8 enableLookaside; /* Saved value of db->lookaside.bEnabled */
125634125735
sqlite3 *db = pParse->db; /* The database connection */
125635125736
int mxSqlLen; /* Max length of an SQL string */
125636125737
125637125738
125739
+#ifdef SQLITE_ENABLE_API_ARMOR
125740
+ if( zSql==0 || pzErrMsg==0 ) return SQLITE_MISUSE_BKPT;
125741
+#endif
125638125742
mxSqlLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];
125639125743
if( db->nVdbeActive==0 ){
125640125744
db->u1.isInterrupted = 0;
125641125745
}
125642125746
pParse->rc = SQLITE_OK;
@@ -125871,17 +125975,10 @@
125871125975
*/
125872125976
SQLITE_API int sqlite3_complete(const char *zSql){
125873125977
u8 state = 0; /* Current state, using numbers defined in header comment */
125874125978
u8 token; /* Value of the next token */
125875125979
125876
-#ifdef SQLITE_ENABLE_API_ARMOR
125877
- if( zSql==0 ){
125878
- (void)SQLITE_MISUSE_BKPT;
125879
- return 0;
125880
- }
125881
-#endif
125882
-
125883125980
#ifndef SQLITE_OMIT_TRIGGER
125884125981
/* A complex statement machine used to detect the end of a CREATE TRIGGER
125885125982
** statement. This is the normal case.
125886125983
*/
125887125984
static const u8 trans[8][8] = {
@@ -125906,10 +126003,17 @@
125906126003
/* 0 INVALID: */ { 1, 0, 2, },
125907126004
/* 1 START: */ { 1, 1, 2, },
125908126005
/* 2 NORMAL: */ { 1, 2, 2, },
125909126006
};
125910126007
#endif /* SQLITE_OMIT_TRIGGER */
126008
+
126009
+#ifdef SQLITE_ENABLE_API_ARMOR
126010
+ if( zSql==0 ){
126011
+ (void)SQLITE_MISUSE_BKPT;
126012
+ return 0;
126013
+ }
126014
+#endif
125911126015
125912126016
while( *zSql ){
125913126017
switch( *zSql ){
125914126018
case ';': { /* A semicolon */
125915126019
token = tkSEMI;
@@ -126208,11 +126312,11 @@
126208126312
** If the following function pointer is not NULL and if
126209126313
** SQLITE_ENABLE_IOTRACE is enabled, then messages describing
126210126314
** I/O active are written using this function. These messages
126211126315
** are intended for debugging activity only.
126212126316
*/
126213
-SQLITE_PRIVATE void (*sqlite3IoTrace)(const char*, ...) = 0;
126317
+/* not-private */ void (*sqlite3IoTrace)(const char*, ...) = 0;
126214126318
#endif
126215126319
126216126320
/*
126217126321
** If the following global variable points to a string which is the
126218126322
** name of a directory, then that directory will be used to store
@@ -126417,10 +126521,17 @@
126417126521
** routine is not threadsafe. But it is safe to invoke this routine
126418126522
** on when SQLite is already shut down. If SQLite is already shut down
126419126523
** when this routine is invoked, then this routine is a harmless no-op.
126420126524
*/
126421126525
SQLITE_API int sqlite3_shutdown(void){
126526
+#ifdef SQLITE_OMIT_WSD
126527
+ int rc = sqlite3_wsd_init(4096, 24);
126528
+ if( rc!=SQLITE_OK ){
126529
+ return rc;
126530
+ }
126531
+#endif
126532
+
126422126533
if( sqlite3GlobalConfig.isInit ){
126423126534
#ifdef SQLITE_EXTRA_SHUTDOWN
126424126535
void SQLITE_EXTRA_SHUTDOWN(void);
126425126536
SQLITE_EXTRA_SHUTDOWN();
126426126537
#endif
@@ -126732,10 +126843,15 @@
126732126843
** heap. */
126733126844
sqlite3GlobalConfig.nHeap = va_arg(ap, int);
126734126845
break;
126735126846
}
126736126847
#endif
126848
+
126849
+ case SQLITE_CONFIG_PMASZ: {
126850
+ sqlite3GlobalConfig.szPma = va_arg(ap, unsigned int);
126851
+ break;
126852
+ }
126737126853
126738126854
default: {
126739126855
rc = SQLITE_ERROR;
126740126856
break;
126741126857
}
@@ -127178,20 +127294,10 @@
127178127294
127179127295
/* Close all database connections */
127180127296
for(j=0; j<db->nDb; j++){
127181127297
struct Db *pDb = &db->aDb[j];
127182127298
if( pDb->pBt ){
127183
- if( pDb->pSchema ){
127184
- /* Must clear the KeyInfo cache. See ticket [e4a18565a36884b00edf] */
127185
- sqlite3BtreeEnter(pDb->pBt);
127186
- for(i=sqliteHashFirst(&pDb->pSchema->idxHash); i; i=sqliteHashNext(i)){
127187
- Index *pIdx = sqliteHashData(i);
127188
- sqlite3KeyInfoUnref(pIdx->pKeyInfo);
127189
- pIdx->pKeyInfo = 0;
127190
- }
127191
- sqlite3BtreeLeave(pDb->pBt);
127192
- }
127193127299
sqlite3BtreeClose(pDb->pBt);
127194127300
pDb->pBt = 0;
127195127301
if( j!=1 ){
127196127302
pDb->pSchema = 0;
127197127303
}
@@ -128315,36 +128421,10 @@
128315128421
*/
128316128422
SQLITE_API const char *sqlite3_errstr(int rc){
128317128423
return sqlite3ErrStr(rc);
128318128424
}
128319128425
128320
-/*
128321
-** Invalidate all cached KeyInfo objects for database connection "db"
128322
-*/
128323
-static void invalidateCachedKeyInfo(sqlite3 *db){
128324
- Db *pDb; /* A single database */
128325
- int iDb; /* The database index number */
128326
- HashElem *k; /* For looping over tables in pDb */
128327
- Table *pTab; /* A table in the database */
128328
- Index *pIdx; /* Each index */
128329
-
128330
- for(iDb=0, pDb=db->aDb; iDb<db->nDb; iDb++, pDb++){
128331
- if( pDb->pBt==0 ) continue;
128332
- sqlite3BtreeEnter(pDb->pBt);
128333
- for(k=sqliteHashFirst(&pDb->pSchema->tblHash); k; k=sqliteHashNext(k)){
128334
- pTab = (Table*)sqliteHashData(k);
128335
- for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
128336
- if( pIdx->pKeyInfo && pIdx->pKeyInfo->db==db ){
128337
- sqlite3KeyInfoUnref(pIdx->pKeyInfo);
128338
- pIdx->pKeyInfo = 0;
128339
- }
128340
- }
128341
- }
128342
- sqlite3BtreeLeave(pDb->pBt);
128343
- }
128344
-}
128345
-
128346128426
/*
128347128427
** Create a new collating function for database "db". The name is zName
128348128428
** and the encoding is enc.
128349128429
*/
128350128430
static int createCollation(
@@ -128384,11 +128464,10 @@
128384128464
sqlite3ErrorWithMsg(db, SQLITE_BUSY,
128385128465
"unable to delete/modify collation sequence due to active statements");
128386128466
return SQLITE_BUSY;
128387128467
}
128388128468
sqlite3ExpirePreparedStatements(db);
128389
- invalidateCachedKeyInfo(db);
128390128469
128391128470
/* If collation sequence pColl was created directly by a call to
128392128471
** sqlite3_create_collation, and not generated by synthCollSeq(),
128393128472
** then any copies made by synthCollSeq() need to be invalidated.
128394128473
** Also, collation destructor - CollSeq.xDel() - function may need
@@ -128941,10 +129020,11 @@
128941129020
sqlite3Error(db, rc);
128942129021
goto opendb_out;
128943129022
}
128944129023
sqlite3BtreeEnter(db->aDb[0].pBt);
128945129024
db->aDb[0].pSchema = sqlite3SchemaGet(db, db->aDb[0].pBt);
129025
+ if( !db->mallocFailed ) ENC(db) = SCHEMA_ENC(db);
128946129026
sqlite3BtreeLeave(db->aDb[0].pBt);
128947129027
db->aDb[1].pSchema = sqlite3SchemaGet(db, 0);
128948129028
128949129029
/* The default safety_level for the main database is 'full'; for the temp
128950129030
** database it is 'NONE'. This matches the pager layer defaults.
@@ -129099,11 +129179,11 @@
129099129179
if( zFilename8 ){
129100129180
rc = openDatabase(zFilename8, ppDb,
129101129181
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, 0);
129102129182
assert( *ppDb || rc==SQLITE_NOMEM );
129103129183
if( rc==SQLITE_OK && !DbHasProperty(*ppDb, 0, DB_SchemaLoaded) ){
129104
- ENC(*ppDb) = SQLITE_UTF16NATIVE;
129184
+ SCHEMA_ENC(*ppDb) = ENC(*ppDb) = SQLITE_UTF16NATIVE;
129105129185
}
129106129186
}else{
129107129187
rc = SQLITE_NOMEM;
129108129188
}
129109129189
sqlite3ValueFree(pVal);
@@ -129841,32 +129921,34 @@
129841129921
/*
129842129922
** Return the filename of the database associated with a database
129843129923
** connection.
129844129924
*/
129845129925
SQLITE_API const char *sqlite3_db_filename(sqlite3 *db, const char *zDbName){
129926
+ Btree *pBt;
129846129927
#ifdef SQLITE_ENABLE_API_ARMOR
129847129928
if( !sqlite3SafetyCheckOk(db) ){
129848129929
(void)SQLITE_MISUSE_BKPT;
129849129930
return 0;
129850129931
}
129851129932
#endif
129852
- Btree *pBt = sqlite3DbNameToBtree(db, zDbName);
129933
+ pBt = sqlite3DbNameToBtree(db, zDbName);
129853129934
return pBt ? sqlite3BtreeGetFilename(pBt) : 0;
129854129935
}
129855129936
129856129937
/*
129857129938
** Return 1 if database is read-only or 0 if read/write. Return -1 if
129858129939
** no such database exists.
129859129940
*/
129860129941
SQLITE_API int sqlite3_db_readonly(sqlite3 *db, const char *zDbName){
129942
+ Btree *pBt;
129861129943
#ifdef SQLITE_ENABLE_API_ARMOR
129862129944
if( !sqlite3SafetyCheckOk(db) ){
129863129945
(void)SQLITE_MISUSE_BKPT;
129864129946
return -1;
129865129947
}
129866129948
#endif
129867
- Btree *pBt = sqlite3DbNameToBtree(db, zDbName);
129949
+ pBt = sqlite3DbNameToBtree(db, zDbName);
129868129950
return pBt ? sqlite3BtreeIsReadonly(pBt) : -1;
129869129951
}
129870129952
129871129953
/************** End of main.c ************************************************/
129872129954
/************** Begin file notify.c ******************************************/
@@ -150073,11 +150155,11 @@
150073150155
}
150074150156
i = pCur->nPoint++;
150075150157
pNew = pCur->aPoint + i;
150076150158
pNew->rScore = rScore;
150077150159
pNew->iLevel = iLevel;
150078
- assert( iLevel>=0 && iLevel<=RTREE_MAX_DEPTH );
150160
+ assert( iLevel<=RTREE_MAX_DEPTH );
150079150161
while( i>0 ){
150080150162
RtreeSearchPoint *pParent;
150081150163
j = (i-1)/2;
150082150164
pParent = pCur->aPoint + j;
150083150165
if( rtreeSearchPointCompare(pNew, pParent)>=0 ) break;
150084150166
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -231,11 +231,11 @@
231 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
232 ** [sqlite_version()] and [sqlite_source_id()].
233 */
234 #define SQLITE_VERSION "3.8.8"
235 #define SQLITE_VERSION_NUMBER 3008008
236 #define SQLITE_SOURCE_ID "2014-12-10 04:58:43 3528f8dd39acace8eeb7337994c8617313f4b04b"
237
238 /*
239 ** CAPI3REF: Run-Time Library Version Numbers
240 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
241 **
@@ -323,11 +323,11 @@
323 ** This interface only reports on the compile-time mutex setting
324 ** of the [SQLITE_THREADSAFE] flag. If SQLite is compiled with
325 ** SQLITE_THREADSAFE=1 or =2 then mutexes are enabled by default but
326 ** can be fully or partially disabled using a call to [sqlite3_config()]
327 ** with the verbs [SQLITE_CONFIG_SINGLETHREAD], [SQLITE_CONFIG_MULTITHREAD],
328 ** or [SQLITE_CONFIG_MUTEX]. ^(The return value of the
329 ** sqlite3_threadsafe() function shows only the compile-time setting of
330 ** thread safety, not any run-time changes to that setting made by
331 ** sqlite3_config(). In other words, the return value from sqlite3_threadsafe()
332 ** is unchanged by calls to sqlite3_config().)^
333 **
@@ -1692,11 +1692,11 @@
1692 ** configuration option.
1693 ** ^There are three arguments to SQLITE_CONFIG_PAGECACHE: A pointer to
1694 ** 8-byte aligned
1695 ** memory, the size of each page buffer (sz), and the number of pages (N).
1696 ** The sz argument should be the size of the largest database page
1697 ** (a power of two between 512 and 32768) plus some extra bytes for each
1698 ** page header. ^The number of extra bytes needed by the page header
1699 ** can be determined using the [SQLITE_CONFIG_PCACHE_HDRSZ] option
1700 ** to [sqlite3_config()].
1701 ** ^It is harmless, apart from the wasted memory,
1702 ** for the sz parameter to be larger than necessary. The first
@@ -1872,10 +1872,21 @@
1872 ** <dd>^The SQLITE_CONFIG_PCACHE_HDRSZ option takes a single parameter which
1873 ** is a pointer to an integer and writes into that integer the number of extra
1874 ** bytes per page required for each page in [SQLITE_CONFIG_PAGECACHE].
1875 ** The amount of extra space required can change depending on the compiler,
1876 ** target platform, and SQLite version.
 
 
 
 
 
 
 
 
 
 
 
1877 ** </dl>
1878 */
1879 #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
1880 #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
1881 #define SQLITE_CONFIG_SERIALIZED 3 /* nil */
@@ -1898,10 +1909,11 @@
1898 #define SQLITE_CONFIG_COVERING_INDEX_SCAN 20 /* int */
1899 #define SQLITE_CONFIG_SQLLOG 21 /* xSqllog, void* */
1900 #define SQLITE_CONFIG_MMAP_SIZE 22 /* sqlite3_int64, sqlite3_int64 */
1901 #define SQLITE_CONFIG_WIN32_HEAPSIZE 23 /* int nByte */
1902 #define SQLITE_CONFIG_PCACHE_HDRSZ 24 /* int *psz */
 
1903
1904 /*
1905 ** CAPI3REF: Database Connection Configuration Options
1906 **
1907 ** These constants are the available integer configuration options that
@@ -7307,16 +7319,14 @@
7307
7308 /*
7309 ** CAPI3REF: Write-Ahead Log Commit Hook
7310 **
7311 ** ^The [sqlite3_wal_hook()] function is used to register a callback that
7312 ** will be invoked each time a database connection commits data to a
7313 ** [write-ahead log] (i.e. whenever a transaction is committed in
7314 ** [journal_mode | journal_mode=WAL mode]).
7315 **
7316 ** ^The callback is invoked by SQLite after the commit has taken place and
7317 ** the associated write-lock on the database released, so the implementation
7318 ** may read, write or [checkpoint] the database as required.
7319 **
7320 ** ^The first parameter passed to the callback function when it is invoked
7321 ** is a copy of the third parameter passed to sqlite3_wal_hook() when
7322 ** registering the callback. ^The second is a copy of the database handle.
@@ -9100,11 +9110,11 @@
9100 #define _BTREE_H_
9101
9102 /* TODO: This definition is just included so other modules compile. It
9103 ** needs to be revisited.
9104 */
9105 #define SQLITE_N_BTREE_META 10
9106
9107 /*
9108 ** If defined as non-zero, auto-vacuum is enabled by default. Otherwise
9109 ** it must be turned on for each database using "PRAGMA auto_vacuum = 1".
9110 */
@@ -9215,10 +9225,15 @@
9215 ** offset = 36 + (idx * 4)
9216 **
9217 ** For example, the free-page-count field is located at byte offset 36 of
9218 ** the database file header. The incr-vacuum-flag field is located at
9219 ** byte offset 64 (== 36+4*7).
 
 
 
 
 
9220 */
9221 #define BTREE_FREE_PAGE_COUNT 0
9222 #define BTREE_SCHEMA_VERSION 1
9223 #define BTREE_FILE_FORMAT 2
9224 #define BTREE_DEFAULT_CACHE_SIZE 3
@@ -9225,10 +9240,11 @@
9225 #define BTREE_LARGEST_ROOT_PAGE 4
9226 #define BTREE_TEXT_ENCODING 5
9227 #define BTREE_USER_VERSION 6
9228 #define BTREE_INCR_VACUUM 7
9229 #define BTREE_APPLICATION_ID 8
 
9230
9231 /*
9232 ** Values that may be OR'd together to form the second argument of an
9233 ** sqlite3BtreeCursorHints() call.
9234 */
@@ -10006,10 +10022,11 @@
10006 SQLITE_PRIVATE int sqlite3PagerWalFramesize(Pager *pPager);
10007 #endif
10008
10009 /* Functions used to query pager state and configuration. */
10010 SQLITE_PRIVATE u8 sqlite3PagerIsreadonly(Pager*);
 
10011 SQLITE_PRIVATE int sqlite3PagerRefcount(Pager*);
10012 SQLITE_PRIVATE int sqlite3PagerMemUsed(Pager*);
10013 SQLITE_PRIVATE const char *sqlite3PagerFilename(Pager*, int);
10014 SQLITE_PRIVATE const sqlite3_vfs *sqlite3PagerVfs(Pager*);
10015 SQLITE_PRIVATE sqlite3_file *sqlite3PagerFile(Pager*);
@@ -10747,10 +10764,11 @@
10747 i64 szMmap; /* Default mmap_size setting */
10748 unsigned int openFlags; /* Flags passed to sqlite3_vfs.xOpen() */
10749 int errCode; /* Most recent error code (SQLITE_*) */
10750 int errMask; /* & result codes with this before returning */
10751 u16 dbOptFlags; /* Flags to enable/disable optimizations */
 
10752 u8 autoCommit; /* The auto-commit flag. */
10753 u8 temp_store; /* 1: file 2: memory 0: default */
10754 u8 mallocFailed; /* True if we have seen a malloc failure */
10755 u8 dfltLockMode; /* Default locking-mode for attached dbs */
10756 signed char nextAutovac; /* Autovac setting after VACUUM if >=0 */
@@ -10848,11 +10866,12 @@
10848 };
10849
10850 /*
10851 ** A macro to discover the encoding of a database.
10852 */
10853 #define ENC(db) ((db)->aDb[0].pSchema->enc)
 
10854
10855 /*
10856 ** Possible values for the sqlite3.flags.
10857 */
10858 #define SQLITE_VdbeTrace 0x00000001 /* True to trace VDBE execution */
@@ -11472,11 +11491,10 @@
11472 Index *pNext; /* The next index associated with the same table */
11473 Schema *pSchema; /* Schema containing this index */
11474 u8 *aSortOrder; /* for each column: True==DESC, False==ASC */
11475 char **azColl; /* Array of collation sequence names for index */
11476 Expr *pPartIdxWhere; /* WHERE clause for partial indices */
11477 KeyInfo *pKeyInfo; /* A KeyInfo object suitable for this index */
11478 int tnum; /* DB Page containing root of this index */
11479 LogEst szIdxRow; /* Estimated average row size in bytes */
11480 u16 nKeyCol; /* Number of columns forming the key */
11481 u16 nColumn; /* Number of columns stored in the index */
11482 u8 onError; /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */
@@ -12526,10 +12544,11 @@
12526 void *pPage; /* Page cache memory */
12527 int szPage; /* Size of each page in pPage[] */
12528 int nPage; /* Number of pages in pPage[] */
12529 int mxParserStack; /* maximum depth of the parser stack */
12530 int sharedCacheEnabled; /* true if shared-cache mode enabled */
 
12531 /* The above might be initialized to non-zero. The following need to always
12532 ** initially be zero, however. */
12533 int isInit; /* True after initialization has finished */
12534 int inProgress; /* True while initialization in progress */
12535 int isMutexInit; /* True after mutexes are initialized */
@@ -13448,11 +13467,11 @@
13448 ** print I/O tracing messages.
13449 */
13450 #ifdef SQLITE_ENABLE_IOTRACE
13451 # define IOTRACE(A) if( sqlite3IoTrace ){ sqlite3IoTrace A; }
13452 SQLITE_PRIVATE void sqlite3VdbeIOTraceSql(Vdbe*);
13453 SQLITE_PRIVATE void (*sqlite3IoTrace)(const char*,...);
13454 #else
13455 # define IOTRACE(A)
13456 # define sqlite3VdbeIOTraceSql(X)
13457 #endif
13458
@@ -13661,10 +13680,17 @@
13661 */
13662 #ifndef SQLITE_ALLOW_COVERING_INDEX_SCAN
13663 # define SQLITE_ALLOW_COVERING_INDEX_SCAN 1
13664 #endif
13665
 
 
 
 
 
 
 
13666 /*
13667 ** The following singleton contains the global configuration for
13668 ** the SQLite library.
13669 */
13670 SQLITE_PRIVATE SQLITE_WSD struct Sqlite3Config sqlite3Config = {
@@ -13691,10 +13717,11 @@
13691 (void*)0, /* pPage */
13692 0, /* szPage */
13693 0, /* nPage */
13694 0, /* mxParserStack */
13695 0, /* sharedCacheEnabled */
 
13696 /* All the rest should always be initialized to zero */
13697 0, /* isInit */
13698 0, /* inProgress */
13699 0, /* isMutexInit */
13700 0, /* isMallocInit */
@@ -19976,10 +20003,16 @@
19976 #endif
19977 }
19978 break;
19979 }
19980 default: {
 
 
 
 
 
 
19981 assert( iType-2 >= 0 );
19982 assert( iType-2 < ArraySize(winMutex_staticMutexes) );
19983 assert( winMutex_isInit==1 );
19984 p = &winMutex_staticMutexes[iType-2];
19985 #ifdef SQLITE_DEBUG
@@ -28783,28 +28816,31 @@
28783 do{
28784 err = osFallocate(pFile->h, buf.st_size, nSize-buf.st_size);
28785 }while( err==EINTR );
28786 if( err ) return SQLITE_IOERR_WRITE;
28787 #else
28788 /* If the OS does not have posix_fallocate(), fake it. First use
28789 ** ftruncate() to set the file size, then write a single byte to
28790 ** the last byte in each block within the extended region. This
28791 ** is the same technique used by glibc to implement posix_fallocate()
28792 ** on systems that do not have a real fallocate() system call.
 
28793 */
28794 int nBlk = buf.st_blksize; /* File-system block size */
28795 i64 iWrite; /* Next offset to write to */
28796
28797 if( robust_ftruncate(pFile->h, nSize) ){
28798 pFile->lastErrno = errno;
28799 return unixLogError(SQLITE_IOERR_TRUNCATE, "ftruncate", pFile->zPath);
28800 }
28801 iWrite = ((buf.st_size + 2*nBlk - 1)/nBlk)*nBlk-1;
28802 while( iWrite<nSize ){
 
 
 
28803 int nWrite = seekAndWrite(pFile, iWrite, "", 1);
28804 if( nWrite!=1 ) return SQLITE_IOERR_WRITE;
28805 iWrite += nBlk;
 
 
 
28806 }
28807 #endif
28808 }
28809 }
28810
@@ -34018,12 +34054,12 @@
34018 */
34019 SQLITE_API int sqlite3_win32_reset_heap(){
34020 int rc;
34021 MUTEX_LOGIC( sqlite3_mutex *pMaster; ) /* The main static mutex */
34022 MUTEX_LOGIC( sqlite3_mutex *pMem; ) /* The memsys static mutex */
34023 MUTEX_LOGIC( pMaster = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); )
34024 MUTEX_LOGIC( pMem = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM); )
34025 sqlite3_mutex_enter(pMaster);
34026 sqlite3_mutex_enter(pMem);
34027 winMemAssertMagic();
34028 if( winMemGetHeap()!=NULL && winMemGetOwned() && sqlite3_memory_used()==0 ){
34029 /*
@@ -35294,11 +35330,11 @@
35294 sqlite3_file *id, /* File to read from */
35295 void *pBuf, /* Write content into this buffer */
35296 int amt, /* Number of bytes to read */
35297 sqlite3_int64 offset /* Begin reading at this offset */
35298 ){
35299 #if !SQLITE_OS_WINCE
35300 OVERLAPPED overlapped; /* The offset for ReadFile. */
35301 #endif
35302 winFile *pFile = (winFile*)id; /* file handle */
35303 DWORD nRead; /* Number of bytes actually read from file */
35304 int nRetry = 0; /* Number of retrys */
@@ -35326,11 +35362,11 @@
35326 offset += nCopy;
35327 }
35328 }
35329 #endif
35330
35331 #if SQLITE_OS_WINCE
35332 if( winSeekFile(pFile, offset) ){
35333 OSTRACE(("READ file=%p, rc=SQLITE_FULL\n", pFile->h));
35334 return SQLITE_FULL;
35335 }
35336 while( !osReadFile(pFile->h, pBuf, amt, &nRead, 0) ){
@@ -35398,32 +35434,32 @@
35398 offset += nCopy;
35399 }
35400 }
35401 #endif
35402
35403 #if SQLITE_OS_WINCE
35404 rc = winSeekFile(pFile, offset);
35405 if( rc==0 ){
35406 #else
35407 {
35408 #endif
35409 #if !SQLITE_OS_WINCE
35410 OVERLAPPED overlapped; /* The offset for WriteFile. */
35411 #endif
35412 u8 *aRem = (u8 *)pBuf; /* Data yet to be written */
35413 int nRem = amt; /* Number of bytes yet to be written */
35414 DWORD nWrite; /* Bytes written by each WriteFile() call */
35415 DWORD lastErrno = NO_ERROR; /* Value returned by GetLastError() */
35416
35417 #if !SQLITE_OS_WINCE
35418 memset(&overlapped, 0, sizeof(OVERLAPPED));
35419 overlapped.Offset = (LONG)(offset & 0xffffffff);
35420 overlapped.OffsetHigh = (LONG)((offset>>32) & 0x7fffffff);
35421 #endif
35422
35423 while( nRem>0 ){
35424 #if SQLITE_OS_WINCE
35425 if( !osWriteFile(pFile->h, aRem, nRem, &nWrite, 0) ){
35426 #else
35427 if( !osWriteFile(pFile->h, aRem, nRem, &nWrite, &overlapped) ){
35428 #endif
35429 if( winRetryIoerr(&nRetry, &lastErrno) ) continue;
@@ -35432,11 +35468,11 @@
35432 assert( nWrite==0 || nWrite<=(DWORD)nRem );
35433 if( nWrite==0 || nWrite>(DWORD)nRem ){
35434 lastErrno = osGetLastError();
35435 break;
35436 }
35437 #if !SQLITE_OS_WINCE
35438 offset += nWrite;
35439 overlapped.Offset = (LONG)(offset & 0xffffffff);
35440 overlapped.OffsetHigh = (LONG)((offset>>32) & 0x7fffffff);
35441 #endif
35442 aRem += nWrite;
@@ -38978,11 +39014,12 @@
38978 SQLITE_PRIVATE int sqlite3PcacheSetPageSize(PCache *pCache, int szPage){
38979 assert( pCache->nRef==0 && pCache->pDirty==0 );
38980 if( pCache->szPage ){
38981 sqlite3_pcache *pNew;
38982 pNew = sqlite3GlobalConfig.pcache2.xCreate(
38983 szPage, pCache->szExtra + sizeof(PgHdr), pCache->bPurgeable
 
38984 );
38985 if( pNew==0 ) return SQLITE_NOMEM;
38986 sqlite3GlobalConfig.pcache2.xCachesize(pNew, numberOfCachePages(pCache));
38987 if( pCache->pCache ){
38988 sqlite3GlobalConfig.pcache2.xDestroy(pCache->pCache);
@@ -39437,11 +39474,11 @@
39437
39438 /*
39439 ** Return the size of the header added by this middleware layer
39440 ** in the page-cache hierarchy.
39441 */
39442 SQLITE_PRIVATE int sqlite3HeaderSizePcache(void){ return sizeof(PgHdr); }
39443
39444
39445 #if defined(SQLITE_CHECK_PAGES) || defined(SQLITE_DEBUG)
39446 /*
39447 ** For all dirty pages currently in the cache, invoke the specified
@@ -39753,11 +39790,11 @@
39753 pcache1Free(pPg);
39754 sqlite3_free(p);
39755 pPg = 0;
39756 }
39757 #else
39758 pPg = pcache1Alloc(sizeof(PgHdr1) + pCache->szPage + pCache->szExtra);
39759 p = (PgHdr1 *)&((u8 *)pPg)[pCache->szPage];
39760 #endif
39761 pcache1EnterMutex(pCache->pGroup);
39762
39763 if( pPg ){
@@ -40441,11 +40478,11 @@
40441 }
40442
40443 /*
40444 ** Return the size of the header on each page of this PCACHE implementation.
40445 */
40446 SQLITE_PRIVATE int sqlite3HeaderSizePcache1(void){ return sizeof(PgHdr1); }
40447
40448 #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
40449 /*
40450 ** This function is called to free superfluous dynamically allocated memory
40451 ** held by the pager system. Memory in use by any SQLite pager allocated
@@ -41799,10 +41836,12 @@
41799 u8 eLock; /* Current lock held on database file */
41800 u8 changeCountDone; /* Set after incrementing the change-counter */
41801 u8 setMaster; /* True if a m-j name has been written to jrnl */
41802 u8 doNotSpill; /* Do not spill the cache when non-zero */
41803 u8 subjInMemory; /* True to use in-memory sub-journals */
 
 
41804 Pgno dbSize; /* Number of pages in the database */
41805 Pgno dbOrigSize; /* dbSize before the current transaction */
41806 Pgno dbFileSize; /* Number of pages in the database file */
41807 Pgno dbHintSize; /* Value passed to FCNTL_SIZE_HINT call */
41808 int errCode; /* One of several kinds of errors */
@@ -41816,13 +41855,13 @@
41816 i64 journalOff; /* Current write offset in the journal file */
41817 i64 journalHdr; /* Byte offset to previous journal header */
41818 sqlite3_backup *pBackup; /* Pointer to list of ongoing backup processes */
41819 PagerSavepoint *aSavepoint; /* Array of active savepoints */
41820 int nSavepoint; /* Number of elements in aSavepoint[] */
 
41821 char dbFileVers[16]; /* Changes whenever database file changes */
41822
41823 u8 bUseFetch; /* True to use xFetch() */
41824 int nMmapOut; /* Number of mmap pages currently outstanding */
41825 sqlite3_int64 szMmap; /* Desired maximum mmap size */
41826 PgHdr *pMmapFreelist; /* List of free mmap page headers (pDirty) */
41827 /*
41828 ** End of the routinely-changing class members
@@ -42834,13 +42873,22 @@
42834
42835 /*
42836 ** Discard the entire contents of the in-memory page-cache.
42837 */
42838 static void pager_reset(Pager *pPager){
 
42839 sqlite3BackupRestart(pPager->pBackup);
42840 sqlite3PcacheClear(pPager->pPCache);
42841 }
 
 
 
 
 
 
 
 
42842
42843 /*
42844 ** Free all structures in the Pager.aSavepoint[] array and set both
42845 ** Pager.aSavepoint and Pager.nSavepoint to zero. Close the sub-journal
42846 ** if it is open and the pager is not in exclusive mode.
@@ -45040,11 +45088,11 @@
45040 Pgno pgno, /* Page number */
45041 void *pData, /* xFetch()'d data for this page */
45042 PgHdr **ppPage /* OUT: Acquired page object */
45043 ){
45044 PgHdr *p; /* Memory mapped page to return */
45045
45046 if( pPager->pMmapFreelist ){
45047 *ppPage = p = pPager->pMmapFreelist;
45048 pPager->pMmapFreelist = p->pDirty;
45049 p->pDirty = 0;
45050 memset(p->pExtra, 0, pPager->nExtra);
@@ -46271,20 +46319,16 @@
46271 assert( (pPager->eLock==SHARED_LOCK)
46272 || (pPager->exclusiveMode && pPager->eLock>SHARED_LOCK)
46273 );
46274 }
46275
46276 if( !pPager->tempFile && (
46277 pPager->pBackup
46278 || sqlite3PcachePagecount(pPager->pPCache)>0
46279 || USEFETCH(pPager)
46280 )){
46281 /* The shared-lock has just been acquired on the database file
46282 ** and there are already pages in the cache (from a previous
46283 ** read or write transaction). Check to see if the database
46284 ** has been modified. If the database has changed, flush the
46285 ** cache.
46286 **
46287 ** Database changes is detected by looking at 15 bytes beginning
46288 ** at offset 24 into the file. The first 4 of these 16 bytes are
46289 ** a 32-bit counter that is incremented with each change. The
46290 ** other bytes change randomly with each file change when
@@ -46445,10 +46489,11 @@
46445 assert( noContent==0 || bMmapOk==0 );
46446
46447 if( pgno==0 ){
46448 return SQLITE_CORRUPT_BKPT;
46449 }
 
46450
46451 /* If the pager is in the error state, return an error immediately.
46452 ** Otherwise, request the page from the PCache layer. */
46453 if( pPager->errCode!=SQLITE_OK ){
46454 rc = pPager->errCode;
@@ -46594,10 +46639,11 @@
46594 sqlite3_pcache_page *pPage;
46595 assert( pPager!=0 );
46596 assert( pgno!=0 );
46597 assert( pPager->pPCache!=0 );
46598 pPage = sqlite3PcacheFetch(pPager->pPCache, pgno, 0);
 
46599 return sqlite3PcacheFetchFinish(pPager->pPCache, pgno, pPage);
46600 }
46601
46602 /*
46603 ** Release a page reference.
@@ -47460,10 +47506,11 @@
47460 pPager->eState = PAGER_READER;
47461 return SQLITE_OK;
47462 }
47463
47464 PAGERTRACE(("COMMIT %d\n", PAGERID(pPager)));
 
47465 rc = pager_end_transaction(pPager, pPager->setMaster, 1);
47466 return pager_error(pPager, rc);
47467 }
47468
47469 /*
@@ -50829,11 +50876,11 @@
50829 }
50830 nCollide = HASHTABLE_NSLOT;
50831 for(iKey=walHash(pgno); aHash[iKey]; iKey=walNextHash(iKey)){
50832 u32 iFrame = aHash[iKey] + iZero;
50833 if( iFrame<=iLast && aPgno[aHash[iKey]]==pgno ){
50834 /* assert( iFrame>iRead ); -- not true if there is corruption */
50835 iRead = iFrame;
50836 }
50837 if( (nCollide--)==0 ){
50838 return SQLITE_CORRUPT_BKPT;
50839 }
@@ -51935,10 +51982,11 @@
51935 u8 inTrans; /* TRANS_NONE, TRANS_READ or TRANS_WRITE */
51936 u8 sharable; /* True if we can share pBt with another db */
51937 u8 locked; /* True if db currently has pBt locked */
51938 int wantToLock; /* Number of nested calls to sqlite3BtreeEnter() */
51939 int nBackup; /* Number of backup operations reading this btree */
 
51940 Btree *pNext; /* List of other sharable Btrees from the same db */
51941 Btree *pPrev; /* Back pointer of the same list */
51942 #ifndef SQLITE_OMIT_SHARED_CACHE
51943 BtLock lock; /* Object used to lock page 1 */
51944 #endif
@@ -56098,10 +56146,11 @@
56098 rc = sqlite3PagerCommitPhaseTwo(pBt->pPager);
56099 if( rc!=SQLITE_OK && bCleanup==0 ){
56100 sqlite3BtreeLeave(p);
56101 return rc;
56102 }
 
56103 pBt->inTransaction = TRANS_READ;
56104 btreeClearHasContent(pBt);
56105 }
56106
56107 btreeEndTransaction(p);
@@ -56461,11 +56510,11 @@
56461 }
56462 for(i=0; i<=pCur->iPage; i++){
56463 releasePage(pCur->apPage[i]);
56464 }
56465 unlockBtreeIfUnused(pBt);
56466 sqlite3DbFree(pBtree->db, pCur->aOverflow);
56467 /* sqlite3_free(pCur); */
56468 sqlite3BtreeLeave(pBtree);
56469 }
56470 return SQLITE_OK;
56471 }
@@ -56755,10 +56804,11 @@
56755 pBuf += a;
56756 amt -= a;
56757 }else{
56758 offset -= pCur->info.nLocal;
56759 }
 
56760
56761 if( rc==SQLITE_OK && amt>0 ){
56762 const u32 ovflSize = pBt->usableSize - 4; /* Bytes content per ovfl page */
56763 Pgno nextPage;
56764
@@ -56773,12 +56823,12 @@
56773 ** means "not yet known" (the cache is lazily populated).
56774 */
56775 if( eOp!=2 && (pCur->curFlags & BTCF_ValidOvfl)==0 ){
56776 int nOvfl = (pCur->info.nPayload-pCur->info.nLocal+ovflSize-1)/ovflSize;
56777 if( nOvfl>pCur->nOvflAlloc ){
56778 Pgno *aNew = (Pgno*)sqlite3DbRealloc(
56779 pCur->pBtree->db, pCur->aOverflow, nOvfl*2*sizeof(Pgno)
56780 );
56781 if( aNew==0 ){
56782 rc = SQLITE_NOMEM;
56783 }else{
56784 pCur->nOvflAlloc = nOvfl*2;
@@ -56821,10 +56871,11 @@
56821 ** Note that the aOverflow[] array must be allocated because eOp!=2
56822 ** here. If eOp==2, then offset==0 and this branch is never taken.
56823 */
56824 assert( eOp!=2 );
56825 assert( pCur->curFlags & BTCF_ValidOvfl );
 
56826 if( pCur->aOverflow[iIdx+1] ){
56827 nextPage = pCur->aOverflow[iIdx+1];
56828 }else{
56829 rc = getOverflowPage(pBt, nextPage, 0, &nextPage);
56830 }
@@ -59410,12 +59461,12 @@
59410 assert( leafCorrection==4 );
59411 if( szCell[nCell]<4 ){
59412 /* Do not allow any cells smaller than 4 bytes. If a smaller cell
59413 ** does exist, pad it with 0x00 bytes. */
59414 assert( szCell[nCell]==3 );
59415 assert( apCell[nCell]==&pTemp[iSpace1-3] );
59416 pTemp[iSpace1++] = 0x00;
59417 szCell[nCell] = 4;
59418 }
59419 }
59420 nCell++;
59421 }
@@ -60723,10 +60774,17 @@
60723 ** is read-only, the others are read/write.
60724 **
60725 ** The schema layer numbers meta values differently. At the schema
60726 ** layer (and the SetCookie and ReadCookie opcodes) the number of
60727 ** free pages is not visible. So Cookie[0] is the same as Meta[1].
 
 
 
 
 
 
 
60728 */
60729 SQLITE_PRIVATE void sqlite3BtreeGetMeta(Btree *p, int idx, u32 *pMeta){
60730 BtShared *pBt = p->pBt;
60731
60732 sqlite3BtreeEnter(p);
@@ -60733,11 +60791,15 @@
60733 assert( p->inTrans>TRANS_NONE );
60734 assert( SQLITE_OK==querySharedCacheTableLock(p, MASTER_ROOT, READ_LOCK) );
60735 assert( pBt->pPage1 );
60736 assert( idx>=0 && idx<=15 );
60737
60738 *pMeta = get4byte(&pBt->pPage1->aData[36 + idx*4]);
 
 
 
 
60739
60740 /* If auto-vacuum is disabled in this build and this is an auto-vacuum
60741 ** database, mark the database as read-only. */
60742 #ifdef SQLITE_OMIT_AUTOVACUUM
60743 if( idx==BTREE_LARGEST_ROOT_PAGE && *pMeta>0 ){
@@ -60824,11 +60886,11 @@
60824 if( pPage->leaf ){
60825 do {
60826 if( pCur->iPage==0 ){
60827 /* All pages of the b-tree have been visited. Return successfully. */
60828 *pnEntry = nEntry;
60829 return SQLITE_OK;
60830 }
60831 moveToParent(pCur);
60832 }while ( pCur->aiIdx[pCur->iPage]>=pCur->apPage[pCur->iPage]->nCell );
60833
60834 pCur->aiIdx[pCur->iPage]++;
@@ -61680,11 +61742,11 @@
61680 }
61681
61682 /*
61683 ** Return the size of the header added to each page by this module.
61684 */
61685 SQLITE_PRIVATE int sqlite3HeaderSizeBtree(void){ return sizeof(MemPage); }
61686
61687 /************** End of btree.c ***********************************************/
61688 /************** Begin file backup.c ******************************************/
61689 /*
61690 ** 2009 January 28
@@ -64444,36 +64506,39 @@
64444 **
64445 ** assert( sqlite3VdbeAssertMayAbort(pParse->pVdbe, pParse->mayAbort) );
64446 */
64447 SQLITE_PRIVATE int sqlite3VdbeAssertMayAbort(Vdbe *v, int mayAbort){
64448 int hasAbort = 0;
 
64449 Op *pOp;
64450 VdbeOpIter sIter;
64451 memset(&sIter, 0, sizeof(sIter));
64452 sIter.v = v;
64453
64454 while( (pOp = opIterNext(&sIter))!=0 ){
64455 int opcode = pOp->opcode;
64456 if( opcode==OP_Destroy || opcode==OP_VUpdate || opcode==OP_VRename
64457 #ifndef SQLITE_OMIT_FOREIGN_KEY
64458 || (opcode==OP_FkCounter && pOp->p1==0 && pOp->p2==1)
64459 #endif
64460 || ((opcode==OP_Halt || opcode==OP_HaltIfNull)
64461 && ((pOp->p1&0xff)==SQLITE_CONSTRAINT && pOp->p2==OE_Abort))
64462 ){
64463 hasAbort = 1;
64464 break;
64465 }
 
 
 
 
 
64466 }
64467 sqlite3DbFree(v->db, sIter.apSub);
64468
64469 /* Return true if hasAbort==mayAbort. Or if a malloc failure occurred.
64470 ** If malloc failed, then the while() loop above may not have iterated
64471 ** through all opcodes and hasAbort may be set incorrectly. Return
64472 ** true for this case to prevent the assert() in the callers frame
64473 ** from failing. */
64474 return ( v->db->mallocFailed || hasAbort==mayAbort );
64475 }
64476 #endif /* SQLITE_DEBUG - the sqlite3AssertMayAbort() function */
64477
64478 /*
64479 ** Loop through the program looking for P2 values that are negative
@@ -68593,11 +68658,14 @@
68593 #ifndef SQLITE_OMIT_WAL
68594 int i;
68595 for(i=0; i<db->nDb; i++){
68596 Btree *pBt = db->aDb[i].pBt;
68597 if( pBt ){
68598 int nEntry = sqlite3PagerWalCallback(sqlite3BtreePager(pBt));
 
 
 
68599 if( db->xWalCallback && nEntry>0 && rc==SQLITE_OK ){
68600 rc = db->xWalCallback(db->pWalArg, db, db->aDb[i].zName, nEntry);
68601 }
68602 }
68603 }
@@ -68773,11 +68841,10 @@
68773 ** program counter to 0 to ensure that when the statement is
68774 ** finalized or reset the parser error message is available via
68775 ** sqlite3_errmsg() and sqlite3_errcode().
68776 */
68777 const char *zErr = (const char *)sqlite3_value_text(db->pErr);
68778 assert( zErr!=0 || db->mallocFailed );
68779 sqlite3DbFree(db, v->zErrMsg);
68780 if( !db->mallocFailed ){
68781 v->zErrMsg = sqlite3DbStrDup(db, zErr);
68782 v->rc = rc2;
68783 } else {
@@ -77135,11 +77202,11 @@
77135 /*
77136 ** Hard-coded maximum amount of data to accumulate in memory before flushing
77137 ** to a level 0 PMA. The purpose of this limit is to prevent various integer
77138 ** overflows. 512MiB.
77139 */
77140 #define SQLITE_MAX_MXPMASIZE (1<<29)
77141
77142 /*
77143 ** Private objects used by the sorter
77144 */
77145 typedef struct MergeEngine MergeEngine; /* Merge PMAs together */
@@ -77431,15 +77498,10 @@
77431 **
77432 ** void *SRVAL(SorterRecord *p) { return (void*)&p[1]; }
77433 */
77434 #define SRVAL(p) ((void*)((SorterRecord*)(p) + 1))
77435
77436 /* The minimum PMA size is set to this value multiplied by the database
77437 ** page size in bytes. */
77438 #ifndef SQLITE_SORTER_PMASZ
77439 # define SQLITE_SORTER_PMASZ 10
77440 #endif
77441
77442 /* Maximum number of PMAs that a single MergeEngine can merge */
77443 #define SORTER_MAX_MERGE_COUNT 16
77444
77445 static int vdbeIncrSwap(IncrMerger*);
@@ -77834,14 +77896,15 @@
77834 SortSubtask *pTask = &pSorter->aTask[i];
77835 pTask->pSorter = pSorter;
77836 }
77837
77838 if( !sqlite3TempInMemory(db) ){
77839 pSorter->mnPmaSize = SQLITE_SORTER_PMASZ * pgsz;
 
77840 mxCache = db->aDb[0].pSchema->cache_size;
77841 if( mxCache<SQLITE_SORTER_PMASZ ) mxCache = SQLITE_SORTER_PMASZ;
77842 pSorter->mxPmaSize = MIN((i64)mxCache*pgsz, SQLITE_MAX_MXPMASIZE);
77843
77844 /* EVIDENCE-OF: R-26747-61719 When the application provides any amount of
77845 ** scratch memory using SQLITE_CONFIG_SCRATCH, SQLite avoids unnecessary
77846 ** large heap allocations.
77847 */
@@ -78115,16 +78178,16 @@
78115 ** Whether or not the file does end up memory mapped of course depends on
78116 ** the specific VFS implementation.
78117 */
78118 static void vdbeSorterExtendFile(sqlite3 *db, sqlite3_file *pFd, i64 nByte){
78119 if( nByte<=(i64)(db->nMaxSorterMmap) && pFd->pMethods->iVersion>=3 ){
78120 int rc = sqlite3OsTruncate(pFd, nByte);
78121 if( rc==SQLITE_OK ){
78122 void *p = 0;
78123 sqlite3OsFetch(pFd, 0, (int)nByte, &p);
78124 sqlite3OsUnfetch(pFd, 0, p);
78125 }
78126 }
78127 }
78128 #else
78129 # define vdbeSorterExtendFile(x,y,z)
78130 #endif
@@ -87302,11 +87365,11 @@
87302
87303 p->iGet = -1;
87304 p->mxSample = mxSample;
87305 p->nPSample = (tRowcnt)(sqlite3_value_int64(argv[2])/(mxSample/3+1) + 1);
87306 p->current.anLt = &p->current.anEq[nColUp];
87307 p->iPrn = nCol*0x689e962d ^ sqlite3_value_int(argv[2])*0xd0944565;
87308
87309 /* Set up the Stat4Accum.a[] and aBest[] arrays */
87310 p->a = (struct Stat4Sample*)&p->current.anLt[nColUp];
87311 p->aBest = &p->a[mxSample];
87312 pSpace = (u8*)(&p->a[mxSample+nCol]);
@@ -88895,17 +88958,19 @@
88895 }else if( aNew->pSchema->file_format && aNew->pSchema->enc!=ENC(db) ){
88896 zErrDyn = sqlite3MPrintf(db,
88897 "attached databases must use the same text encoding as main database");
88898 rc = SQLITE_ERROR;
88899 }
 
88900 pPager = sqlite3BtreePager(aNew->pBt);
88901 sqlite3PagerLockingMode(pPager, db->dfltLockMode);
88902 sqlite3BtreeSecureDelete(aNew->pBt,
88903 sqlite3BtreeSecureDelete(db->aDb[0].pBt,-1) );
88904 #ifndef SQLITE_OMIT_PAGER_PRAGMAS
88905 sqlite3BtreeSetPagerFlags(aNew->pBt, 3 | (db->flags & PAGER_FLAGS_MASK));
88906 #endif
 
88907 }
88908 aNew->safety_level = 3;
88909 aNew->zName = sqlite3DbStrDup(db, zName);
88910 if( rc==SQLITE_OK && aNew->zName==0 ){
88911 rc = SQLITE_NOMEM;
@@ -90027,11 +90092,10 @@
90027 */
90028 static void freeIndex(sqlite3 *db, Index *p){
90029 #ifndef SQLITE_OMIT_ANALYZE
90030 sqlite3DeleteIndexSamples(db, p);
90031 #endif
90032 if( db==0 || db->pnBytesFreed==0 ) sqlite3KeyInfoUnref(p->pKeyInfo);
90033 sqlite3ExprDelete(db, p->pPartIdxWhere);
90034 sqlite3DbFree(db, p->zColAff);
90035 if( p->isResized ) sqlite3DbFree(db, p->azColl);
90036 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
90037 sqlite3_free(p->aiRowEst);
@@ -91306,10 +91370,23 @@
91306 if( pPk==0 ) return;
91307 pPk->idxType = SQLITE_IDXTYPE_PRIMARYKEY;
91308 pTab->iPKey = -1;
91309 }else{
91310 pPk = sqlite3PrimaryKeyIndex(pTab);
 
 
 
 
 
 
 
 
 
 
 
 
 
91311 }
91312 pPk->isCovering = 1;
91313 assert( pPk!=0 );
91314 nPk = pPk->nKeyCol;
91315
@@ -93782,44 +93859,35 @@
93782 **
93783 ** The caller should invoke sqlite3KeyInfoUnref() on the returned object
93784 ** when it has finished using it.
93785 */
93786 SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoOfIndex(Parse *pParse, Index *pIdx){
 
 
 
 
93787 if( pParse->nErr ) return 0;
93788 #ifndef SQLITE_OMIT_SHARED_CACHE
93789 if( pIdx->pKeyInfo && pIdx->pKeyInfo->db!=pParse->db ){
93790 sqlite3KeyInfoUnref(pIdx->pKeyInfo);
93791 pIdx->pKeyInfo = 0;
93792 }
93793 #endif
93794 if( pIdx->pKeyInfo==0 ){
93795 int i;
93796 int nCol = pIdx->nColumn;
93797 int nKey = pIdx->nKeyCol;
93798 KeyInfo *pKey;
93799 if( pIdx->uniqNotNull ){
93800 pKey = sqlite3KeyInfoAlloc(pParse->db, nKey, nCol-nKey);
93801 }else{
93802 pKey = sqlite3KeyInfoAlloc(pParse->db, nCol, 0);
93803 }
93804 if( pKey ){
93805 assert( sqlite3KeyInfoIsWriteable(pKey) );
93806 for(i=0; i<nCol; i++){
93807 char *zColl = pIdx->azColl[i];
93808 assert( zColl!=0 );
93809 pKey->aColl[i] = strcmp(zColl,"BINARY")==0 ? 0 :
93810 sqlite3LocateCollSeq(pParse, zColl);
93811 pKey->aSortOrder[i] = pIdx->aSortOrder[i];
93812 }
93813 if( pParse->nErr ){
93814 sqlite3KeyInfoUnref(pKey);
93815 }else{
93816 pIdx->pKeyInfo = pKey;
93817 }
93818 }
93819 }
93820 return sqlite3KeyInfoRef(pIdx->pKeyInfo);
93821 }
93822
93823 #ifndef SQLITE_OMIT_CTE
93824 /*
93825 ** This routine is invoked once per CTE by the parser while parsing a
@@ -97436,11 +97504,11 @@
97436 assert( nIncr==1 );
97437 sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_FOREIGNKEY,
97438 OE_Abort, 0, P4_STATIC, P5_ConstraintFK);
97439 }else{
97440 if( nIncr>0 && pFKey->isDeferred==0 ){
97441 sqlite3ParseToplevel(pParse)->mayAbort = 1;
97442 }
97443 sqlite3VdbeAddOp2(v, OP_FkCounter, pFKey->isDeferred, nIncr);
97444 }
97445
97446 sqlite3VdbeResolveLabel(v, iOk);
@@ -97507,10 +97575,14 @@
97507 ** This function is called to generate code executed when a row is deleted
97508 ** from the parent table of foreign key constraint pFKey and, if pFKey is
97509 ** deferred, when a row is inserted into the same table. When generating
97510 ** code for an SQL UPDATE operation, this function may be called twice -
97511 ** once to "delete" the old row and once to "insert" the new row.
 
 
 
 
97512 **
97513 ** The code generated by this function scans through the rows in the child
97514 ** table that correspond to the parent table row being deleted or inserted.
97515 ** For each child row found, one of the following actions is taken:
97516 **
@@ -97624,17 +97696,13 @@
97624 sNameContext.pSrcList = pSrc;
97625 sNameContext.pParse = pParse;
97626 sqlite3ResolveExprNames(&sNameContext, pWhere);
97627
97628 /* Create VDBE to loop through the entries in pSrc that match the WHERE
97629 ** clause. If the constraint is not deferred, throw an exception for
97630 ** each row found. Otherwise, for deferred constraints, increment the
97631 ** deferred constraint counter by nIncr for each row selected. */
97632 pWInfo = sqlite3WhereBegin(pParse, pSrc, pWhere, 0, 0, 0, 0);
97633 if( nIncr>0 && pFKey->isDeferred==0 ){
97634 sqlite3ParseToplevel(pParse)->mayAbort = 1;
97635 }
97636 sqlite3VdbeAddOp2(v, OP_FkCounter, pFKey->isDeferred, nIncr);
97637 if( pWInfo ){
97638 sqlite3WhereEnd(pWInfo);
97639 }
97640
@@ -97808,10 +97876,28 @@
97808 }
97809 }
97810 }
97811 return 0;
97812 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97813
97814 /*
97815 ** This function is called when inserting, deleting or updating a row of
97816 ** table pTab to generate VDBE code to perform foreign key constraint
97817 ** processing for the operation.
@@ -97861,11 +97947,11 @@
97861 Index *pIdx = 0; /* Index on key columns in pTo */
97862 int *aiFree = 0;
97863 int *aiCol;
97864 int iCol;
97865 int i;
97866 int isIgnore = 0;
97867
97868 if( aChange
97869 && sqlite3_stricmp(pTab->zName, pFKey->zTo)!=0
97870 && fkChildIsModified(pTab, pFKey, aChange, bChngRowid)==0
97871 ){
@@ -97920,11 +98006,11 @@
97920 ** values read from the parent table are NULL. */
97921 if( db->xAuth ){
97922 int rcauth;
97923 char *zCol = pTo->aCol[pIdx ? pIdx->aiColumn[i] : pTo->iPKey].zName;
97924 rcauth = sqlite3AuthReadCol(pParse, pTo->zName, zCol, iDb);
97925 isIgnore = (rcauth==SQLITE_IGNORE);
97926 }
97927 #endif
97928 }
97929
97930 /* Take a shared-cache advisory read-lock on the parent table. Allocate
@@ -97935,16 +98021,22 @@
97935
97936 if( regOld!=0 ){
97937 /* A row is being removed from the child table. Search for the parent.
97938 ** If the parent does not exist, removing the child row resolves an
97939 ** outstanding foreign key constraint violation. */
97940 fkLookupParent(pParse, iDb, pTo, pIdx, pFKey, aiCol, regOld, -1,isIgnore);
97941 }
97942 if( regNew!=0 ){
97943 /* A row is being added to the child table. If a parent row cannot
97944 ** be found, adding the child row has violated the FK constraint. */
97945 fkLookupParent(pParse, iDb, pTo, pIdx, pFKey, aiCol, regNew, +1,isIgnore);
 
 
 
 
 
 
97946 }
97947
97948 sqlite3DbFree(db, aiFree);
97949 }
97950
@@ -97961,12 +98053,12 @@
97961
97962 if( !pFKey->isDeferred && !(db->flags & SQLITE_DeferFKs)
97963 && !pParse->pToplevel && !pParse->isMultiWrite
97964 ){
97965 assert( regOld==0 && regNew!=0 );
97966 /* Inserting a single row into a parent table cannot cause an immediate
97967 ** foreign key violation. So do nothing in this case. */
97968 continue;
97969 }
97970
97971 if( sqlite3FkLocateIndex(pParse, pTab, pFKey, &pIdx, &aiCol) ){
97972 if( !isIgnoreErrors || db->mallocFailed ) return;
@@ -97986,17 +98078,32 @@
97986
97987 if( regNew!=0 ){
97988 fkScanChildren(pParse, pSrc, pTab, pIdx, pFKey, aiCol, regNew, -1);
97989 }
97990 if( regOld!=0 ){
97991 /* If there is a RESTRICT action configured for the current operation
97992 ** on the parent table of this FK, then throw an exception
97993 ** immediately if the FK constraint is violated, even if this is a
97994 ** deferred trigger. That's what RESTRICT means. To defer checking
97995 ** the constraint, the FK should specify NO ACTION (represented
97996 ** using OE_None). NO ACTION is the default. */
97997 fkScanChildren(pParse, pSrc, pTab, pIdx, pFKey, aiCol, regOld, 1);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97998 }
97999 pItem->zName = 0;
98000 sqlite3SrcListDelete(db, pSrc);
98001 }
98002 sqlite3DbFree(db, aiCol);
@@ -101895,10 +102002,11 @@
101895 #define PragTyp_KEY 38
101896 #define PragTyp_REKEY 39
101897 #define PragTyp_LOCK_STATUS 40
101898 #define PragTyp_PARSER_TRACE 41
101899 #define PragFlag_NeedSchema 0x01
 
101900 static const struct sPragmaNames {
101901 const char *const zName; /* Name of pragma */
101902 u8 ePragTyp; /* PragTyp_XXX value */
101903 u8 mPragFlag; /* Zero or more PragFlag_XXX values */
101904 u32 iArg; /* Extra argument */
@@ -101911,11 +102019,11 @@
101911 #endif
101912 #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
101913 { /* zName: */ "application_id",
101914 /* ePragTyp: */ PragTyp_HEADER_VALUE,
101915 /* ePragFlag: */ 0,
101916 /* iArg: */ 0 },
101917 #endif
101918 #if !defined(SQLITE_OMIT_AUTOVACUUM)
101919 { /* zName: */ "auto_vacuum",
101920 /* ePragTyp: */ PragTyp_AUTO_VACUUM,
101921 /* ePragFlag: */ PragFlag_NeedSchema,
@@ -101977,10 +102085,16 @@
101977 { /* zName: */ "data_store_directory",
101978 /* ePragTyp: */ PragTyp_DATA_STORE_DIRECTORY,
101979 /* ePragFlag: */ 0,
101980 /* iArg: */ 0 },
101981 #endif
 
 
 
 
 
 
101982 #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
101983 { /* zName: */ "database_list",
101984 /* ePragTyp: */ PragTyp_DATABASE_LIST,
101985 /* ePragFlag: */ PragFlag_NeedSchema,
101986 /* iArg: */ 0 },
@@ -102032,12 +102146,12 @@
102032 #endif
102033 #endif
102034 #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
102035 { /* zName: */ "freelist_count",
102036 /* ePragTyp: */ PragTyp_HEADER_VALUE,
102037 /* ePragFlag: */ 0,
102038 /* iArg: */ 0 },
102039 #endif
102040 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
102041 { /* zName: */ "full_column_names",
102042 /* ePragTyp: */ PragTyp_FLAG,
102043 /* ePragFlag: */ 0,
@@ -102185,11 +102299,11 @@
102185 #endif
102186 #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
102187 { /* zName: */ "schema_version",
102188 /* ePragTyp: */ PragTyp_HEADER_VALUE,
102189 /* ePragFlag: */ 0,
102190 /* iArg: */ 0 },
102191 #endif
102192 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
102193 { /* zName: */ "secure_delete",
102194 /* ePragTyp: */ PragTyp_SECURE_DELETE,
102195 /* ePragFlag: */ 0,
@@ -102251,11 +102365,11 @@
102251 /* iArg: */ 0 },
102252 #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
102253 { /* zName: */ "user_version",
102254 /* ePragTyp: */ PragTyp_HEADER_VALUE,
102255 /* ePragFlag: */ 0,
102256 /* iArg: */ 0 },
102257 #endif
102258 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
102259 #if defined(SQLITE_DEBUG)
102260 { /* zName: */ "vdbe_addoptrace",
102261 /* ePragTyp: */ PragTyp_FLAG,
@@ -102294,11 +102408,11 @@
102294 /* ePragTyp: */ PragTyp_FLAG,
102295 /* ePragFlag: */ 0,
102296 /* iArg: */ SQLITE_WriteSchema|SQLITE_RecoveryMode },
102297 #endif
102298 };
102299 /* Number of pragmas: 57 on by default, 70 total. */
102300 /* End of the automatically generated pragma table.
102301 ***************************************************************************/
102302
102303 /*
102304 ** Interpret the given string as a safety level. Return 0 for OFF,
@@ -103904,11 +104018,12 @@
103904 !(DbHasProperty(db, 0, DB_SchemaLoaded)) ||
103905 DbHasProperty(db, 0, DB_Empty)
103906 ){
103907 for(pEnc=&encnames[0]; pEnc->zName; pEnc++){
103908 if( 0==sqlite3StrICmp(zRight, pEnc->zName) ){
103909 ENC(pParse->db) = pEnc->enc ? pEnc->enc : SQLITE_UTF16NATIVE;
 
103910 break;
103911 }
103912 }
103913 if( !pEnc->zName ){
103914 sqlite3ErrorMsg(pParse, "unsupported encoding: %s", zRight);
@@ -103949,28 +104064,13 @@
103949 **
103950 ** The user-version is not used internally by SQLite. It may be used by
103951 ** applications for any purpose.
103952 */
103953 case PragTyp_HEADER_VALUE: {
103954 int iCookie; /* Cookie index. 1 for schema-cookie, 6 for user-cookie. */
103955 sqlite3VdbeUsesBtree(v, iDb);
103956 switch( zLeft[0] ){
103957 case 'a': case 'A':
103958 iCookie = BTREE_APPLICATION_ID;
103959 break;
103960 case 'f': case 'F':
103961 iCookie = BTREE_FREE_PAGE_COUNT;
103962 break;
103963 case 's': case 'S':
103964 iCookie = BTREE_SCHEMA_VERSION;
103965 break;
103966 default:
103967 iCookie = BTREE_USER_VERSION;
103968 break;
103969 }
103970
103971 if( zRight && iCookie!=BTREE_FREE_PAGE_COUNT ){
103972 /* Write the specified cookie value */
103973 static const VdbeOpList setCookie[] = {
103974 { OP_Transaction, 0, 1, 0}, /* 0 */
103975 { OP_Integer, 0, 1, 0}, /* 1 */
103976 { OP_SetCookie, 0, 0, 1}, /* 2 */
@@ -104612,13 +104712,15 @@
104612 SQLITE_PRIVATE int sqlite3Init(sqlite3 *db, char **pzErrMsg){
104613 int i, rc;
104614 int commit_internal = !(db->flags&SQLITE_InternChanges);
104615
104616 assert( sqlite3_mutex_held(db->mutex) );
 
104617 assert( db->init.busy==0 );
104618 rc = SQLITE_OK;
104619 db->init.busy = 1;
 
104620 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
104621 if( DbHasProperty(db, i, DB_SchemaLoaded) || i==1 ) continue;
104622 rc = sqlite3InitOne(db, i, pzErrMsg);
104623 if( rc ){
104624 sqlite3ResetOneSchema(db, i);
@@ -110756,11 +110858,11 @@
110756 ){
110757 int rc;
110758 TabResult res;
110759
110760 #ifdef SQLITE_ENABLE_API_ARMOR
110761 if( pazResult==0 ) return SQLITE_MISUSE_BKPT;
110762 #endif
110763 *pazResult = 0;
110764 if( pnColumn ) *pnColumn = 0;
110765 if( pnRow ) *pnRow = 0;
110766 if( pzErrMsg ) *pzErrMsg = 0;
@@ -118626,11 +118728,10 @@
118626 sqlite3_free(p->u.vtab.idxStr);
118627 p->u.vtab.needFree = 0;
118628 p->u.vtab.idxStr = 0;
118629 }else if( (p->wsFlags & WHERE_AUTO_INDEX)!=0 && p->u.btree.pIndex!=0 ){
118630 sqlite3DbFree(db, p->u.btree.pIndex->zColAff);
118631 sqlite3KeyInfoUnref(p->u.btree.pIndex->pKeyInfo);
118632 sqlite3DbFree(db, p->u.btree.pIndex);
118633 p->u.btree.pIndex = 0;
118634 }
118635 }
118636 }
@@ -125633,10 +125734,13 @@
125633 u8 enableLookaside; /* Saved value of db->lookaside.bEnabled */
125634 sqlite3 *db = pParse->db; /* The database connection */
125635 int mxSqlLen; /* Max length of an SQL string */
125636
125637
 
 
 
125638 mxSqlLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];
125639 if( db->nVdbeActive==0 ){
125640 db->u1.isInterrupted = 0;
125641 }
125642 pParse->rc = SQLITE_OK;
@@ -125871,17 +125975,10 @@
125871 */
125872 SQLITE_API int sqlite3_complete(const char *zSql){
125873 u8 state = 0; /* Current state, using numbers defined in header comment */
125874 u8 token; /* Value of the next token */
125875
125876 #ifdef SQLITE_ENABLE_API_ARMOR
125877 if( zSql==0 ){
125878 (void)SQLITE_MISUSE_BKPT;
125879 return 0;
125880 }
125881 #endif
125882
125883 #ifndef SQLITE_OMIT_TRIGGER
125884 /* A complex statement machine used to detect the end of a CREATE TRIGGER
125885 ** statement. This is the normal case.
125886 */
125887 static const u8 trans[8][8] = {
@@ -125906,10 +126003,17 @@
125906 /* 0 INVALID: */ { 1, 0, 2, },
125907 /* 1 START: */ { 1, 1, 2, },
125908 /* 2 NORMAL: */ { 1, 2, 2, },
125909 };
125910 #endif /* SQLITE_OMIT_TRIGGER */
 
 
 
 
 
 
 
125911
125912 while( *zSql ){
125913 switch( *zSql ){
125914 case ';': { /* A semicolon */
125915 token = tkSEMI;
@@ -126208,11 +126312,11 @@
126208 ** If the following function pointer is not NULL and if
126209 ** SQLITE_ENABLE_IOTRACE is enabled, then messages describing
126210 ** I/O active are written using this function. These messages
126211 ** are intended for debugging activity only.
126212 */
126213 SQLITE_PRIVATE void (*sqlite3IoTrace)(const char*, ...) = 0;
126214 #endif
126215
126216 /*
126217 ** If the following global variable points to a string which is the
126218 ** name of a directory, then that directory will be used to store
@@ -126417,10 +126521,17 @@
126417 ** routine is not threadsafe. But it is safe to invoke this routine
126418 ** on when SQLite is already shut down. If SQLite is already shut down
126419 ** when this routine is invoked, then this routine is a harmless no-op.
126420 */
126421 SQLITE_API int sqlite3_shutdown(void){
 
 
 
 
 
 
 
126422 if( sqlite3GlobalConfig.isInit ){
126423 #ifdef SQLITE_EXTRA_SHUTDOWN
126424 void SQLITE_EXTRA_SHUTDOWN(void);
126425 SQLITE_EXTRA_SHUTDOWN();
126426 #endif
@@ -126732,10 +126843,15 @@
126732 ** heap. */
126733 sqlite3GlobalConfig.nHeap = va_arg(ap, int);
126734 break;
126735 }
126736 #endif
 
 
 
 
 
126737
126738 default: {
126739 rc = SQLITE_ERROR;
126740 break;
126741 }
@@ -127178,20 +127294,10 @@
127178
127179 /* Close all database connections */
127180 for(j=0; j<db->nDb; j++){
127181 struct Db *pDb = &db->aDb[j];
127182 if( pDb->pBt ){
127183 if( pDb->pSchema ){
127184 /* Must clear the KeyInfo cache. See ticket [e4a18565a36884b00edf] */
127185 sqlite3BtreeEnter(pDb->pBt);
127186 for(i=sqliteHashFirst(&pDb->pSchema->idxHash); i; i=sqliteHashNext(i)){
127187 Index *pIdx = sqliteHashData(i);
127188 sqlite3KeyInfoUnref(pIdx->pKeyInfo);
127189 pIdx->pKeyInfo = 0;
127190 }
127191 sqlite3BtreeLeave(pDb->pBt);
127192 }
127193 sqlite3BtreeClose(pDb->pBt);
127194 pDb->pBt = 0;
127195 if( j!=1 ){
127196 pDb->pSchema = 0;
127197 }
@@ -128315,36 +128421,10 @@
128315 */
128316 SQLITE_API const char *sqlite3_errstr(int rc){
128317 return sqlite3ErrStr(rc);
128318 }
128319
128320 /*
128321 ** Invalidate all cached KeyInfo objects for database connection "db"
128322 */
128323 static void invalidateCachedKeyInfo(sqlite3 *db){
128324 Db *pDb; /* A single database */
128325 int iDb; /* The database index number */
128326 HashElem *k; /* For looping over tables in pDb */
128327 Table *pTab; /* A table in the database */
128328 Index *pIdx; /* Each index */
128329
128330 for(iDb=0, pDb=db->aDb; iDb<db->nDb; iDb++, pDb++){
128331 if( pDb->pBt==0 ) continue;
128332 sqlite3BtreeEnter(pDb->pBt);
128333 for(k=sqliteHashFirst(&pDb->pSchema->tblHash); k; k=sqliteHashNext(k)){
128334 pTab = (Table*)sqliteHashData(k);
128335 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
128336 if( pIdx->pKeyInfo && pIdx->pKeyInfo->db==db ){
128337 sqlite3KeyInfoUnref(pIdx->pKeyInfo);
128338 pIdx->pKeyInfo = 0;
128339 }
128340 }
128341 }
128342 sqlite3BtreeLeave(pDb->pBt);
128343 }
128344 }
128345
128346 /*
128347 ** Create a new collating function for database "db". The name is zName
128348 ** and the encoding is enc.
128349 */
128350 static int createCollation(
@@ -128384,11 +128464,10 @@
128384 sqlite3ErrorWithMsg(db, SQLITE_BUSY,
128385 "unable to delete/modify collation sequence due to active statements");
128386 return SQLITE_BUSY;
128387 }
128388 sqlite3ExpirePreparedStatements(db);
128389 invalidateCachedKeyInfo(db);
128390
128391 /* If collation sequence pColl was created directly by a call to
128392 ** sqlite3_create_collation, and not generated by synthCollSeq(),
128393 ** then any copies made by synthCollSeq() need to be invalidated.
128394 ** Also, collation destructor - CollSeq.xDel() - function may need
@@ -128941,10 +129020,11 @@
128941 sqlite3Error(db, rc);
128942 goto opendb_out;
128943 }
128944 sqlite3BtreeEnter(db->aDb[0].pBt);
128945 db->aDb[0].pSchema = sqlite3SchemaGet(db, db->aDb[0].pBt);
 
128946 sqlite3BtreeLeave(db->aDb[0].pBt);
128947 db->aDb[1].pSchema = sqlite3SchemaGet(db, 0);
128948
128949 /* The default safety_level for the main database is 'full'; for the temp
128950 ** database it is 'NONE'. This matches the pager layer defaults.
@@ -129099,11 +129179,11 @@
129099 if( zFilename8 ){
129100 rc = openDatabase(zFilename8, ppDb,
129101 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, 0);
129102 assert( *ppDb || rc==SQLITE_NOMEM );
129103 if( rc==SQLITE_OK && !DbHasProperty(*ppDb, 0, DB_SchemaLoaded) ){
129104 ENC(*ppDb) = SQLITE_UTF16NATIVE;
129105 }
129106 }else{
129107 rc = SQLITE_NOMEM;
129108 }
129109 sqlite3ValueFree(pVal);
@@ -129841,32 +129921,34 @@
129841 /*
129842 ** Return the filename of the database associated with a database
129843 ** connection.
129844 */
129845 SQLITE_API const char *sqlite3_db_filename(sqlite3 *db, const char *zDbName){
 
129846 #ifdef SQLITE_ENABLE_API_ARMOR
129847 if( !sqlite3SafetyCheckOk(db) ){
129848 (void)SQLITE_MISUSE_BKPT;
129849 return 0;
129850 }
129851 #endif
129852 Btree *pBt = sqlite3DbNameToBtree(db, zDbName);
129853 return pBt ? sqlite3BtreeGetFilename(pBt) : 0;
129854 }
129855
129856 /*
129857 ** Return 1 if database is read-only or 0 if read/write. Return -1 if
129858 ** no such database exists.
129859 */
129860 SQLITE_API int sqlite3_db_readonly(sqlite3 *db, const char *zDbName){
 
129861 #ifdef SQLITE_ENABLE_API_ARMOR
129862 if( !sqlite3SafetyCheckOk(db) ){
129863 (void)SQLITE_MISUSE_BKPT;
129864 return -1;
129865 }
129866 #endif
129867 Btree *pBt = sqlite3DbNameToBtree(db, zDbName);
129868 return pBt ? sqlite3BtreeIsReadonly(pBt) : -1;
129869 }
129870
129871 /************** End of main.c ************************************************/
129872 /************** Begin file notify.c ******************************************/
@@ -150073,11 +150155,11 @@
150073 }
150074 i = pCur->nPoint++;
150075 pNew = pCur->aPoint + i;
150076 pNew->rScore = rScore;
150077 pNew->iLevel = iLevel;
150078 assert( iLevel>=0 && iLevel<=RTREE_MAX_DEPTH );
150079 while( i>0 ){
150080 RtreeSearchPoint *pParent;
150081 j = (i-1)/2;
150082 pParent = pCur->aPoint + j;
150083 if( rtreeSearchPointCompare(pNew, pParent)>=0 ) break;
150084
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -231,11 +231,11 @@
231 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
232 ** [sqlite_version()] and [sqlite_source_id()].
233 */
234 #define SQLITE_VERSION "3.8.8"
235 #define SQLITE_VERSION_NUMBER 3008008
236 #define SQLITE_SOURCE_ID "2015-01-03 18:59:17 23d4c07eb81db5a5c6beb56b5820f0b6501f1fb6"
237
238 /*
239 ** CAPI3REF: Run-Time Library Version Numbers
240 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
241 **
@@ -323,11 +323,11 @@
323 ** This interface only reports on the compile-time mutex setting
324 ** of the [SQLITE_THREADSAFE] flag. If SQLite is compiled with
325 ** SQLITE_THREADSAFE=1 or =2 then mutexes are enabled by default but
326 ** can be fully or partially disabled using a call to [sqlite3_config()]
327 ** with the verbs [SQLITE_CONFIG_SINGLETHREAD], [SQLITE_CONFIG_MULTITHREAD],
328 ** or [SQLITE_CONFIG_SERIALIZED]. ^(The return value of the
329 ** sqlite3_threadsafe() function shows only the compile-time setting of
330 ** thread safety, not any run-time changes to that setting made by
331 ** sqlite3_config(). In other words, the return value from sqlite3_threadsafe()
332 ** is unchanged by calls to sqlite3_config().)^
333 **
@@ -1692,11 +1692,11 @@
1692 ** configuration option.
1693 ** ^There are three arguments to SQLITE_CONFIG_PAGECACHE: A pointer to
1694 ** 8-byte aligned
1695 ** memory, the size of each page buffer (sz), and the number of pages (N).
1696 ** The sz argument should be the size of the largest database page
1697 ** (a power of two between 512 and 65536) plus some extra bytes for each
1698 ** page header. ^The number of extra bytes needed by the page header
1699 ** can be determined using the [SQLITE_CONFIG_PCACHE_HDRSZ] option
1700 ** to [sqlite3_config()].
1701 ** ^It is harmless, apart from the wasted memory,
1702 ** for the sz parameter to be larger than necessary. The first
@@ -1872,10 +1872,21 @@
1872 ** <dd>^The SQLITE_CONFIG_PCACHE_HDRSZ option takes a single parameter which
1873 ** is a pointer to an integer and writes into that integer the number of extra
1874 ** bytes per page required for each page in [SQLITE_CONFIG_PAGECACHE].
1875 ** The amount of extra space required can change depending on the compiler,
1876 ** target platform, and SQLite version.
1877 **
1878 ** [[SQLITE_CONFIG_PMASZ]]
1879 ** <dt>SQLITE_CONFIG_PMASZ
1880 ** <dd>^The SQLITE_CONFIG_PMASZ option takes a single parameter which
1881 ** is an unsigned integer and sets the "Minimum PMA Size" for the multithreaded
1882 ** sorter to that integer. The default minimum PMA Size is set by the
1883 ** [SQLITE_SORTER_PMASZ] compile-time option. New threads are launched
1884 ** to help with sort operations when multithreaded sorting
1885 ** is enabled (using the [PRAGMA threads] command) and the amount of content
1886 ** to be sorted exceeds the page size times the minimum of the
1887 ** [PRAGMA cache_size] setting and this value.
1888 ** </dl>
1889 */
1890 #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
1891 #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
1892 #define SQLITE_CONFIG_SERIALIZED 3 /* nil */
@@ -1898,10 +1909,11 @@
1909 #define SQLITE_CONFIG_COVERING_INDEX_SCAN 20 /* int */
1910 #define SQLITE_CONFIG_SQLLOG 21 /* xSqllog, void* */
1911 #define SQLITE_CONFIG_MMAP_SIZE 22 /* sqlite3_int64, sqlite3_int64 */
1912 #define SQLITE_CONFIG_WIN32_HEAPSIZE 23 /* int nByte */
1913 #define SQLITE_CONFIG_PCACHE_HDRSZ 24 /* int *psz */
1914 #define SQLITE_CONFIG_PMASZ 25 /* unsigned int szPma */
1915
1916 /*
1917 ** CAPI3REF: Database Connection Configuration Options
1918 **
1919 ** These constants are the available integer configuration options that
@@ -7307,16 +7319,14 @@
7319
7320 /*
7321 ** CAPI3REF: Write-Ahead Log Commit Hook
7322 **
7323 ** ^The [sqlite3_wal_hook()] function is used to register a callback that
7324 ** is invoked each time data is committed to a database in wal mode.
 
 
7325 **
7326 ** ^(The callback is invoked by SQLite after the commit has taken place and
7327 ** the associated write-lock on the database released)^, so the implementation
7328 ** may read, write or [checkpoint] the database as required.
7329 **
7330 ** ^The first parameter passed to the callback function when it is invoked
7331 ** is a copy of the third parameter passed to sqlite3_wal_hook() when
7332 ** registering the callback. ^The second is a copy of the database handle.
@@ -9100,11 +9110,11 @@
9110 #define _BTREE_H_
9111
9112 /* TODO: This definition is just included so other modules compile. It
9113 ** needs to be revisited.
9114 */
9115 #define SQLITE_N_BTREE_META 16
9116
9117 /*
9118 ** If defined as non-zero, auto-vacuum is enabled by default. Otherwise
9119 ** it must be turned on for each database using "PRAGMA auto_vacuum = 1".
9120 */
@@ -9215,10 +9225,15 @@
9225 ** offset = 36 + (idx * 4)
9226 **
9227 ** For example, the free-page-count field is located at byte offset 36 of
9228 ** the database file header. The incr-vacuum-flag field is located at
9229 ** byte offset 64 (== 36+4*7).
9230 **
9231 ** The BTREE_DATA_VERSION value is not really a value stored in the header.
9232 ** It is a read-only number computed by the pager. But we merge it with
9233 ** the header value access routines since its access pattern is the same.
9234 ** Call it a "virtual meta value".
9235 */
9236 #define BTREE_FREE_PAGE_COUNT 0
9237 #define BTREE_SCHEMA_VERSION 1
9238 #define BTREE_FILE_FORMAT 2
9239 #define BTREE_DEFAULT_CACHE_SIZE 3
@@ -9225,10 +9240,11 @@
9240 #define BTREE_LARGEST_ROOT_PAGE 4
9241 #define BTREE_TEXT_ENCODING 5
9242 #define BTREE_USER_VERSION 6
9243 #define BTREE_INCR_VACUUM 7
9244 #define BTREE_APPLICATION_ID 8
9245 #define BTREE_DATA_VERSION 15 /* A virtual meta-value */
9246
9247 /*
9248 ** Values that may be OR'd together to form the second argument of an
9249 ** sqlite3BtreeCursorHints() call.
9250 */
@@ -10006,10 +10022,11 @@
10022 SQLITE_PRIVATE int sqlite3PagerWalFramesize(Pager *pPager);
10023 #endif
10024
10025 /* Functions used to query pager state and configuration. */
10026 SQLITE_PRIVATE u8 sqlite3PagerIsreadonly(Pager*);
10027 SQLITE_PRIVATE u32 sqlite3PagerDataVersion(Pager*);
10028 SQLITE_PRIVATE int sqlite3PagerRefcount(Pager*);
10029 SQLITE_PRIVATE int sqlite3PagerMemUsed(Pager*);
10030 SQLITE_PRIVATE const char *sqlite3PagerFilename(Pager*, int);
10031 SQLITE_PRIVATE const sqlite3_vfs *sqlite3PagerVfs(Pager*);
10032 SQLITE_PRIVATE sqlite3_file *sqlite3PagerFile(Pager*);
@@ -10747,10 +10764,11 @@
10764 i64 szMmap; /* Default mmap_size setting */
10765 unsigned int openFlags; /* Flags passed to sqlite3_vfs.xOpen() */
10766 int errCode; /* Most recent error code (SQLITE_*) */
10767 int errMask; /* & result codes with this before returning */
10768 u16 dbOptFlags; /* Flags to enable/disable optimizations */
10769 u8 enc; /* Text encoding */
10770 u8 autoCommit; /* The auto-commit flag. */
10771 u8 temp_store; /* 1: file 2: memory 0: default */
10772 u8 mallocFailed; /* True if we have seen a malloc failure */
10773 u8 dfltLockMode; /* Default locking-mode for attached dbs */
10774 signed char nextAutovac; /* Autovac setting after VACUUM if >=0 */
@@ -10848,11 +10866,12 @@
10866 };
10867
10868 /*
10869 ** A macro to discover the encoding of a database.
10870 */
10871 #define SCHEMA_ENC(db) ((db)->aDb[0].pSchema->enc)
10872 #define ENC(db) ((db)->enc)
10873
10874 /*
10875 ** Possible values for the sqlite3.flags.
10876 */
10877 #define SQLITE_VdbeTrace 0x00000001 /* True to trace VDBE execution */
@@ -11472,11 +11491,10 @@
11491 Index *pNext; /* The next index associated with the same table */
11492 Schema *pSchema; /* Schema containing this index */
11493 u8 *aSortOrder; /* for each column: True==DESC, False==ASC */
11494 char **azColl; /* Array of collation sequence names for index */
11495 Expr *pPartIdxWhere; /* WHERE clause for partial indices */
 
11496 int tnum; /* DB Page containing root of this index */
11497 LogEst szIdxRow; /* Estimated average row size in bytes */
11498 u16 nKeyCol; /* Number of columns forming the key */
11499 u16 nColumn; /* Number of columns stored in the index */
11500 u8 onError; /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */
@@ -12526,10 +12544,11 @@
12544 void *pPage; /* Page cache memory */
12545 int szPage; /* Size of each page in pPage[] */
12546 int nPage; /* Number of pages in pPage[] */
12547 int mxParserStack; /* maximum depth of the parser stack */
12548 int sharedCacheEnabled; /* true if shared-cache mode enabled */
12549 u32 szPma; /* Maximum Sorter PMA size */
12550 /* The above might be initialized to non-zero. The following need to always
12551 ** initially be zero, however. */
12552 int isInit; /* True after initialization has finished */
12553 int inProgress; /* True while initialization in progress */
12554 int isMutexInit; /* True after mutexes are initialized */
@@ -13448,11 +13467,11 @@
13467 ** print I/O tracing messages.
13468 */
13469 #ifdef SQLITE_ENABLE_IOTRACE
13470 # define IOTRACE(A) if( sqlite3IoTrace ){ sqlite3IoTrace A; }
13471 SQLITE_PRIVATE void sqlite3VdbeIOTraceSql(Vdbe*);
13472 void (*sqlite3IoTrace)(const char*,...);
13473 #else
13474 # define IOTRACE(A)
13475 # define sqlite3VdbeIOTraceSql(X)
13476 #endif
13477
@@ -13661,10 +13680,17 @@
13680 */
13681 #ifndef SQLITE_ALLOW_COVERING_INDEX_SCAN
13682 # define SQLITE_ALLOW_COVERING_INDEX_SCAN 1
13683 #endif
13684
13685 /* The minimum PMA size is set to this value multiplied by the database
13686 ** page size in bytes.
13687 */
13688 #ifndef SQLITE_SORTER_PMASZ
13689 # define SQLITE_SORTER_PMASZ 250
13690 #endif
13691
13692 /*
13693 ** The following singleton contains the global configuration for
13694 ** the SQLite library.
13695 */
13696 SQLITE_PRIVATE SQLITE_WSD struct Sqlite3Config sqlite3Config = {
@@ -13691,10 +13717,11 @@
13717 (void*)0, /* pPage */
13718 0, /* szPage */
13719 0, /* nPage */
13720 0, /* mxParserStack */
13721 0, /* sharedCacheEnabled */
13722 SQLITE_SORTER_PMASZ, /* szPma */
13723 /* All the rest should always be initialized to zero */
13724 0, /* isInit */
13725 0, /* inProgress */
13726 0, /* isMutexInit */
13727 0, /* isMallocInit */
@@ -19976,10 +20003,16 @@
20003 #endif
20004 }
20005 break;
20006 }
20007 default: {
20008 #ifdef SQLITE_ENABLE_API_ARMOR
20009 if( iType-2<0 || iType-2>=ArraySize(winMutex_staticMutexes) ){
20010 (void)SQLITE_MISUSE_BKPT;
20011 return 0;
20012 }
20013 #endif
20014 assert( iType-2 >= 0 );
20015 assert( iType-2 < ArraySize(winMutex_staticMutexes) );
20016 assert( winMutex_isInit==1 );
20017 p = &winMutex_staticMutexes[iType-2];
20018 #ifdef SQLITE_DEBUG
@@ -28783,28 +28816,31 @@
28816 do{
28817 err = osFallocate(pFile->h, buf.st_size, nSize-buf.st_size);
28818 }while( err==EINTR );
28819 if( err ) return SQLITE_IOERR_WRITE;
28820 #else
28821 /* If the OS does not have posix_fallocate(), fake it. Write a
28822 ** single byte to the last byte in each block that falls entirely
28823 ** within the extended region. Then, if required, a single byte
28824 ** at offset (nSize-1), to set the size of the file correctly.
28825 ** This is a similar technique to that used by glibc on systems
28826 ** that do not have a real fallocate() call.
28827 */
28828 int nBlk = buf.st_blksize; /* File-system block size */
28829 i64 iWrite; /* Next offset to write to */
28830
 
 
 
 
28831 iWrite = ((buf.st_size + 2*nBlk - 1)/nBlk)*nBlk-1;
28832 assert( iWrite>=buf.st_size );
28833 assert( (iWrite/nBlk)==((buf.st_size+nBlk-1)/nBlk) );
28834 assert( ((iWrite+1)%nBlk)==0 );
28835 for(/*no-op*/; iWrite<nSize; iWrite+=nBlk ){
28836 int nWrite = seekAndWrite(pFile, iWrite, "", 1);
28837 if( nWrite!=1 ) return SQLITE_IOERR_WRITE;
28838 }
28839 if( nSize%nBlk ){
28840 int nWrite = seekAndWrite(pFile, nSize-1, "", 1);
28841 if( nWrite!=1 ) return SQLITE_IOERR_WRITE;
28842 }
28843 #endif
28844 }
28845 }
28846
@@ -34018,12 +34054,12 @@
34054 */
34055 SQLITE_API int sqlite3_win32_reset_heap(){
34056 int rc;
34057 MUTEX_LOGIC( sqlite3_mutex *pMaster; ) /* The main static mutex */
34058 MUTEX_LOGIC( sqlite3_mutex *pMem; ) /* The memsys static mutex */
34059 MUTEX_LOGIC( pMaster = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MASTER); )
34060 MUTEX_LOGIC( pMem = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MEM); )
34061 sqlite3_mutex_enter(pMaster);
34062 sqlite3_mutex_enter(pMem);
34063 winMemAssertMagic();
34064 if( winMemGetHeap()!=NULL && winMemGetOwned() && sqlite3_memory_used()==0 ){
34065 /*
@@ -35294,11 +35330,11 @@
35330 sqlite3_file *id, /* File to read from */
35331 void *pBuf, /* Write content into this buffer */
35332 int amt, /* Number of bytes to read */
35333 sqlite3_int64 offset /* Begin reading at this offset */
35334 ){
35335 #if !SQLITE_OS_WINCE && !defined(SQLITE_WIN32_NO_OVERLAPPED)
35336 OVERLAPPED overlapped; /* The offset for ReadFile. */
35337 #endif
35338 winFile *pFile = (winFile*)id; /* file handle */
35339 DWORD nRead; /* Number of bytes actually read from file */
35340 int nRetry = 0; /* Number of retrys */
@@ -35326,11 +35362,11 @@
35362 offset += nCopy;
35363 }
35364 }
35365 #endif
35366
35367 #if SQLITE_OS_WINCE || defined(SQLITE_WIN32_NO_OVERLAPPED)
35368 if( winSeekFile(pFile, offset) ){
35369 OSTRACE(("READ file=%p, rc=SQLITE_FULL\n", pFile->h));
35370 return SQLITE_FULL;
35371 }
35372 while( !osReadFile(pFile->h, pBuf, amt, &nRead, 0) ){
@@ -35398,32 +35434,32 @@
35434 offset += nCopy;
35435 }
35436 }
35437 #endif
35438
35439 #if SQLITE_OS_WINCE || defined(SQLITE_WIN32_NO_OVERLAPPED)
35440 rc = winSeekFile(pFile, offset);
35441 if( rc==0 ){
35442 #else
35443 {
35444 #endif
35445 #if !SQLITE_OS_WINCE && !defined(SQLITE_WIN32_NO_OVERLAPPED)
35446 OVERLAPPED overlapped; /* The offset for WriteFile. */
35447 #endif
35448 u8 *aRem = (u8 *)pBuf; /* Data yet to be written */
35449 int nRem = amt; /* Number of bytes yet to be written */
35450 DWORD nWrite; /* Bytes written by each WriteFile() call */
35451 DWORD lastErrno = NO_ERROR; /* Value returned by GetLastError() */
35452
35453 #if !SQLITE_OS_WINCE && !defined(SQLITE_WIN32_NO_OVERLAPPED)
35454 memset(&overlapped, 0, sizeof(OVERLAPPED));
35455 overlapped.Offset = (LONG)(offset & 0xffffffff);
35456 overlapped.OffsetHigh = (LONG)((offset>>32) & 0x7fffffff);
35457 #endif
35458
35459 while( nRem>0 ){
35460 #if SQLITE_OS_WINCE || defined(SQLITE_WIN32_NO_OVERLAPPED)
35461 if( !osWriteFile(pFile->h, aRem, nRem, &nWrite, 0) ){
35462 #else
35463 if( !osWriteFile(pFile->h, aRem, nRem, &nWrite, &overlapped) ){
35464 #endif
35465 if( winRetryIoerr(&nRetry, &lastErrno) ) continue;
@@ -35432,11 +35468,11 @@
35468 assert( nWrite==0 || nWrite<=(DWORD)nRem );
35469 if( nWrite==0 || nWrite>(DWORD)nRem ){
35470 lastErrno = osGetLastError();
35471 break;
35472 }
35473 #if !SQLITE_OS_WINCE && !defined(SQLITE_WIN32_NO_OVERLAPPED)
35474 offset += nWrite;
35475 overlapped.Offset = (LONG)(offset & 0xffffffff);
35476 overlapped.OffsetHigh = (LONG)((offset>>32) & 0x7fffffff);
35477 #endif
35478 aRem += nWrite;
@@ -38978,11 +39014,12 @@
39014 SQLITE_PRIVATE int sqlite3PcacheSetPageSize(PCache *pCache, int szPage){
39015 assert( pCache->nRef==0 && pCache->pDirty==0 );
39016 if( pCache->szPage ){
39017 sqlite3_pcache *pNew;
39018 pNew = sqlite3GlobalConfig.pcache2.xCreate(
39019 szPage, pCache->szExtra + ROUND8(sizeof(PgHdr)),
39020 pCache->bPurgeable
39021 );
39022 if( pNew==0 ) return SQLITE_NOMEM;
39023 sqlite3GlobalConfig.pcache2.xCachesize(pNew, numberOfCachePages(pCache));
39024 if( pCache->pCache ){
39025 sqlite3GlobalConfig.pcache2.xDestroy(pCache->pCache);
@@ -39437,11 +39474,11 @@
39474
39475 /*
39476 ** Return the size of the header added by this middleware layer
39477 ** in the page-cache hierarchy.
39478 */
39479 SQLITE_PRIVATE int sqlite3HeaderSizePcache(void){ return ROUND8(sizeof(PgHdr)); }
39480
39481
39482 #if defined(SQLITE_CHECK_PAGES) || defined(SQLITE_DEBUG)
39483 /*
39484 ** For all dirty pages currently in the cache, invoke the specified
@@ -39753,11 +39790,11 @@
39790 pcache1Free(pPg);
39791 sqlite3_free(p);
39792 pPg = 0;
39793 }
39794 #else
39795 pPg = pcache1Alloc(ROUND8(sizeof(PgHdr1)) + pCache->szPage + pCache->szExtra);
39796 p = (PgHdr1 *)&((u8 *)pPg)[pCache->szPage];
39797 #endif
39798 pcache1EnterMutex(pCache->pGroup);
39799
39800 if( pPg ){
@@ -40441,11 +40478,11 @@
40478 }
40479
40480 /*
40481 ** Return the size of the header on each page of this PCACHE implementation.
40482 */
40483 SQLITE_PRIVATE int sqlite3HeaderSizePcache1(void){ return ROUND8(sizeof(PgHdr1)); }
40484
40485 #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
40486 /*
40487 ** This function is called to free superfluous dynamically allocated memory
40488 ** held by the pager system. Memory in use by any SQLite pager allocated
@@ -41799,10 +41836,12 @@
41836 u8 eLock; /* Current lock held on database file */
41837 u8 changeCountDone; /* Set after incrementing the change-counter */
41838 u8 setMaster; /* True if a m-j name has been written to jrnl */
41839 u8 doNotSpill; /* Do not spill the cache when non-zero */
41840 u8 subjInMemory; /* True to use in-memory sub-journals */
41841 u8 bUseFetch; /* True to use xFetch() */
41842 u8 hasBeenUsed; /* True if any content previously read from this pager*/
41843 Pgno dbSize; /* Number of pages in the database */
41844 Pgno dbOrigSize; /* dbSize before the current transaction */
41845 Pgno dbFileSize; /* Number of pages in the database file */
41846 Pgno dbHintSize; /* Value passed to FCNTL_SIZE_HINT call */
41847 int errCode; /* One of several kinds of errors */
@@ -41816,13 +41855,13 @@
41855 i64 journalOff; /* Current write offset in the journal file */
41856 i64 journalHdr; /* Byte offset to previous journal header */
41857 sqlite3_backup *pBackup; /* Pointer to list of ongoing backup processes */
41858 PagerSavepoint *aSavepoint; /* Array of active savepoints */
41859 int nSavepoint; /* Number of elements in aSavepoint[] */
41860 u32 iDataVersion; /* Changes whenever database content changes */
41861 char dbFileVers[16]; /* Changes whenever database file changes */
41862
 
41863 int nMmapOut; /* Number of mmap pages currently outstanding */
41864 sqlite3_int64 szMmap; /* Desired maximum mmap size */
41865 PgHdr *pMmapFreelist; /* List of free mmap page headers (pDirty) */
41866 /*
41867 ** End of the routinely-changing class members
@@ -42834,13 +42873,22 @@
42873
42874 /*
42875 ** Discard the entire contents of the in-memory page-cache.
42876 */
42877 static void pager_reset(Pager *pPager){
42878 pPager->iDataVersion++;
42879 sqlite3BackupRestart(pPager->pBackup);
42880 sqlite3PcacheClear(pPager->pPCache);
42881 }
42882
42883 /*
42884 ** Return the pPager->iDataVersion value
42885 */
42886 SQLITE_PRIVATE u32 sqlite3PagerDataVersion(Pager *pPager){
42887 assert( pPager->eState>PAGER_OPEN );
42888 return pPager->iDataVersion;
42889 }
42890
42891 /*
42892 ** Free all structures in the Pager.aSavepoint[] array and set both
42893 ** Pager.aSavepoint and Pager.nSavepoint to zero. Close the sub-journal
42894 ** if it is open and the pager is not in exclusive mode.
@@ -45040,11 +45088,11 @@
45088 Pgno pgno, /* Page number */
45089 void *pData, /* xFetch()'d data for this page */
45090 PgHdr **ppPage /* OUT: Acquired page object */
45091 ){
45092 PgHdr *p; /* Memory mapped page to return */
45093
45094 if( pPager->pMmapFreelist ){
45095 *ppPage = p = pPager->pMmapFreelist;
45096 pPager->pMmapFreelist = p->pDirty;
45097 p->pDirty = 0;
45098 memset(p->pExtra, 0, pPager->nExtra);
@@ -46271,20 +46319,16 @@
46319 assert( (pPager->eLock==SHARED_LOCK)
46320 || (pPager->exclusiveMode && pPager->eLock>SHARED_LOCK)
46321 );
46322 }
46323
46324 if( !pPager->tempFile && pPager->hasBeenUsed ){
46325 /* The shared-lock has just been acquired then check to
46326 ** see if the database has been modified. If the database has changed,
46327 ** flush the cache. The pPager->hasBeenUsed flag prevents this from
46328 ** occurring on the very first access to a file, in order to save a
46329 ** single unnecessary sqlite3OsRead() call at the start-up.
 
 
 
 
46330 **
46331 ** Database changes is detected by looking at 15 bytes beginning
46332 ** at offset 24 into the file. The first 4 of these 16 bytes are
46333 ** a 32-bit counter that is incremented with each change. The
46334 ** other bytes change randomly with each file change when
@@ -46445,10 +46489,11 @@
46489 assert( noContent==0 || bMmapOk==0 );
46490
46491 if( pgno==0 ){
46492 return SQLITE_CORRUPT_BKPT;
46493 }
46494 pPager->hasBeenUsed = 1;
46495
46496 /* If the pager is in the error state, return an error immediately.
46497 ** Otherwise, request the page from the PCache layer. */
46498 if( pPager->errCode!=SQLITE_OK ){
46499 rc = pPager->errCode;
@@ -46594,10 +46639,11 @@
46639 sqlite3_pcache_page *pPage;
46640 assert( pPager!=0 );
46641 assert( pgno!=0 );
46642 assert( pPager->pPCache!=0 );
46643 pPage = sqlite3PcacheFetch(pPager->pPCache, pgno, 0);
46644 assert( pPage==0 || pPager->hasBeenUsed );
46645 return sqlite3PcacheFetchFinish(pPager->pPCache, pgno, pPage);
46646 }
46647
46648 /*
46649 ** Release a page reference.
@@ -47460,10 +47506,11 @@
47506 pPager->eState = PAGER_READER;
47507 return SQLITE_OK;
47508 }
47509
47510 PAGERTRACE(("COMMIT %d\n", PAGERID(pPager)));
47511 pPager->iDataVersion++;
47512 rc = pager_end_transaction(pPager, pPager->setMaster, 1);
47513 return pager_error(pPager, rc);
47514 }
47515
47516 /*
@@ -50829,11 +50876,11 @@
50876 }
50877 nCollide = HASHTABLE_NSLOT;
50878 for(iKey=walHash(pgno); aHash[iKey]; iKey=walNextHash(iKey)){
50879 u32 iFrame = aHash[iKey] + iZero;
50880 if( iFrame<=iLast && aPgno[aHash[iKey]]==pgno ){
50881 assert( iFrame>iRead || CORRUPT_DB );
50882 iRead = iFrame;
50883 }
50884 if( (nCollide--)==0 ){
50885 return SQLITE_CORRUPT_BKPT;
50886 }
@@ -51935,10 +51982,11 @@
51982 u8 inTrans; /* TRANS_NONE, TRANS_READ or TRANS_WRITE */
51983 u8 sharable; /* True if we can share pBt with another db */
51984 u8 locked; /* True if db currently has pBt locked */
51985 int wantToLock; /* Number of nested calls to sqlite3BtreeEnter() */
51986 int nBackup; /* Number of backup operations reading this btree */
51987 u32 iDataVersion; /* Combines with pBt->pPager->iDataVersion */
51988 Btree *pNext; /* List of other sharable Btrees from the same db */
51989 Btree *pPrev; /* Back pointer of the same list */
51990 #ifndef SQLITE_OMIT_SHARED_CACHE
51991 BtLock lock; /* Object used to lock page 1 */
51992 #endif
@@ -56098,10 +56146,11 @@
56146 rc = sqlite3PagerCommitPhaseTwo(pBt->pPager);
56147 if( rc!=SQLITE_OK && bCleanup==0 ){
56148 sqlite3BtreeLeave(p);
56149 return rc;
56150 }
56151 p->iDataVersion--; /* Compensate for pPager->iDataVersion++; */
56152 pBt->inTransaction = TRANS_READ;
56153 btreeClearHasContent(pBt);
56154 }
56155
56156 btreeEndTransaction(p);
@@ -56461,11 +56510,11 @@
56510 }
56511 for(i=0; i<=pCur->iPage; i++){
56512 releasePage(pCur->apPage[i]);
56513 }
56514 unlockBtreeIfUnused(pBt);
56515 sqlite3_free(pCur->aOverflow);
56516 /* sqlite3_free(pCur); */
56517 sqlite3BtreeLeave(pBtree);
56518 }
56519 return SQLITE_OK;
56520 }
@@ -56755,10 +56804,11 @@
56804 pBuf += a;
56805 amt -= a;
56806 }else{
56807 offset -= pCur->info.nLocal;
56808 }
56809
56810
56811 if( rc==SQLITE_OK && amt>0 ){
56812 const u32 ovflSize = pBt->usableSize - 4; /* Bytes content per ovfl page */
56813 Pgno nextPage;
56814
@@ -56773,12 +56823,12 @@
56823 ** means "not yet known" (the cache is lazily populated).
56824 */
56825 if( eOp!=2 && (pCur->curFlags & BTCF_ValidOvfl)==0 ){
56826 int nOvfl = (pCur->info.nPayload-pCur->info.nLocal+ovflSize-1)/ovflSize;
56827 if( nOvfl>pCur->nOvflAlloc ){
56828 Pgno *aNew = (Pgno*)sqlite3Realloc(
56829 pCur->aOverflow, nOvfl*2*sizeof(Pgno)
56830 );
56831 if( aNew==0 ){
56832 rc = SQLITE_NOMEM;
56833 }else{
56834 pCur->nOvflAlloc = nOvfl*2;
@@ -56821,10 +56871,11 @@
56871 ** Note that the aOverflow[] array must be allocated because eOp!=2
56872 ** here. If eOp==2, then offset==0 and this branch is never taken.
56873 */
56874 assert( eOp!=2 );
56875 assert( pCur->curFlags & BTCF_ValidOvfl );
56876 assert( pCur->pBtree->db==pBt->db );
56877 if( pCur->aOverflow[iIdx+1] ){
56878 nextPage = pCur->aOverflow[iIdx+1];
56879 }else{
56880 rc = getOverflowPage(pBt, nextPage, 0, &nextPage);
56881 }
@@ -59410,12 +59461,12 @@
59461 assert( leafCorrection==4 );
59462 if( szCell[nCell]<4 ){
59463 /* Do not allow any cells smaller than 4 bytes. If a smaller cell
59464 ** does exist, pad it with 0x00 bytes. */
59465 assert( szCell[nCell]==3 );
59466 assert( apCell[nCell]==&aSpace1[iSpace1-3] );
59467 aSpace1[iSpace1++] = 0x00;
59468 szCell[nCell] = 4;
59469 }
59470 }
59471 nCell++;
59472 }
@@ -60723,10 +60774,17 @@
60774 ** is read-only, the others are read/write.
60775 **
60776 ** The schema layer numbers meta values differently. At the schema
60777 ** layer (and the SetCookie and ReadCookie opcodes) the number of
60778 ** free pages is not visible. So Cookie[0] is the same as Meta[1].
60779 **
60780 ** This routine treats Meta[BTREE_DATA_VERSION] as a special case. Instead
60781 ** of reading the value out of the header, it instead loads the "DataVersion"
60782 ** from the pager. The BTREE_DATA_VERSION value is not actually stored in the
60783 ** database file. It is a number computed by the pager. But its access
60784 ** pattern is the same as header meta values, and so it is convenient to
60785 ** read it from this routine.
60786 */
60787 SQLITE_PRIVATE void sqlite3BtreeGetMeta(Btree *p, int idx, u32 *pMeta){
60788 BtShared *pBt = p->pBt;
60789
60790 sqlite3BtreeEnter(p);
@@ -60733,11 +60791,15 @@
60791 assert( p->inTrans>TRANS_NONE );
60792 assert( SQLITE_OK==querySharedCacheTableLock(p, MASTER_ROOT, READ_LOCK) );
60793 assert( pBt->pPage1 );
60794 assert( idx>=0 && idx<=15 );
60795
60796 if( idx==BTREE_DATA_VERSION ){
60797 *pMeta = sqlite3PagerDataVersion(pBt->pPager) + p->iDataVersion;
60798 }else{
60799 *pMeta = get4byte(&pBt->pPage1->aData[36 + idx*4]);
60800 }
60801
60802 /* If auto-vacuum is disabled in this build and this is an auto-vacuum
60803 ** database, mark the database as read-only. */
60804 #ifdef SQLITE_OMIT_AUTOVACUUM
60805 if( idx==BTREE_LARGEST_ROOT_PAGE && *pMeta>0 ){
@@ -60824,11 +60886,11 @@
60886 if( pPage->leaf ){
60887 do {
60888 if( pCur->iPage==0 ){
60889 /* All pages of the b-tree have been visited. Return successfully. */
60890 *pnEntry = nEntry;
60891 return moveToRoot(pCur);
60892 }
60893 moveToParent(pCur);
60894 }while ( pCur->aiIdx[pCur->iPage]>=pCur->apPage[pCur->iPage]->nCell );
60895
60896 pCur->aiIdx[pCur->iPage]++;
@@ -61680,11 +61742,11 @@
61742 }
61743
61744 /*
61745 ** Return the size of the header added to each page by this module.
61746 */
61747 SQLITE_PRIVATE int sqlite3HeaderSizeBtree(void){ return ROUND8(sizeof(MemPage)); }
61748
61749 /************** End of btree.c ***********************************************/
61750 /************** Begin file backup.c ******************************************/
61751 /*
61752 ** 2009 January 28
@@ -64444,36 +64506,39 @@
64506 **
64507 ** assert( sqlite3VdbeAssertMayAbort(pParse->pVdbe, pParse->mayAbort) );
64508 */
64509 SQLITE_PRIVATE int sqlite3VdbeAssertMayAbort(Vdbe *v, int mayAbort){
64510 int hasAbort = 0;
64511 int hasFkCounter = 0;
64512 Op *pOp;
64513 VdbeOpIter sIter;
64514 memset(&sIter, 0, sizeof(sIter));
64515 sIter.v = v;
64516
64517 while( (pOp = opIterNext(&sIter))!=0 ){
64518 int opcode = pOp->opcode;
64519 if( opcode==OP_Destroy || opcode==OP_VUpdate || opcode==OP_VRename
 
 
 
64520 || ((opcode==OP_Halt || opcode==OP_HaltIfNull)
64521 && ((pOp->p1&0xff)==SQLITE_CONSTRAINT && pOp->p2==OE_Abort))
64522 ){
64523 hasAbort = 1;
64524 break;
64525 }
64526 #ifndef SQLITE_OMIT_FOREIGN_KEY
64527 if( opcode==OP_FkCounter && pOp->p1==0 && pOp->p2==1 ){
64528 hasFkCounter = 1;
64529 }
64530 #endif
64531 }
64532 sqlite3DbFree(v->db, sIter.apSub);
64533
64534 /* Return true if hasAbort==mayAbort. Or if a malloc failure occurred.
64535 ** If malloc failed, then the while() loop above may not have iterated
64536 ** through all opcodes and hasAbort may be set incorrectly. Return
64537 ** true for this case to prevent the assert() in the callers frame
64538 ** from failing. */
64539 return ( v->db->mallocFailed || hasAbort==mayAbort || hasFkCounter );
64540 }
64541 #endif /* SQLITE_DEBUG - the sqlite3AssertMayAbort() function */
64542
64543 /*
64544 ** Loop through the program looking for P2 values that are negative
@@ -68593,11 +68658,14 @@
68658 #ifndef SQLITE_OMIT_WAL
68659 int i;
68660 for(i=0; i<db->nDb; i++){
68661 Btree *pBt = db->aDb[i].pBt;
68662 if( pBt ){
68663 int nEntry;
68664 sqlite3BtreeEnter(pBt);
68665 nEntry = sqlite3PagerWalCallback(sqlite3BtreePager(pBt));
68666 sqlite3BtreeLeave(pBt);
68667 if( db->xWalCallback && nEntry>0 && rc==SQLITE_OK ){
68668 rc = db->xWalCallback(db->pWalArg, db, db->aDb[i].zName, nEntry);
68669 }
68670 }
68671 }
@@ -68773,11 +68841,10 @@
68841 ** program counter to 0 to ensure that when the statement is
68842 ** finalized or reset the parser error message is available via
68843 ** sqlite3_errmsg() and sqlite3_errcode().
68844 */
68845 const char *zErr = (const char *)sqlite3_value_text(db->pErr);
 
68846 sqlite3DbFree(db, v->zErrMsg);
68847 if( !db->mallocFailed ){
68848 v->zErrMsg = sqlite3DbStrDup(db, zErr);
68849 v->rc = rc2;
68850 } else {
@@ -77135,11 +77202,11 @@
77202 /*
77203 ** Hard-coded maximum amount of data to accumulate in memory before flushing
77204 ** to a level 0 PMA. The purpose of this limit is to prevent various integer
77205 ** overflows. 512MiB.
77206 */
77207 #define SQLITE_MAX_PMASZ (1<<29)
77208
77209 /*
77210 ** Private objects used by the sorter
77211 */
77212 typedef struct MergeEngine MergeEngine; /* Merge PMAs together */
@@ -77431,15 +77498,10 @@
77498 **
77499 ** void *SRVAL(SorterRecord *p) { return (void*)&p[1]; }
77500 */
77501 #define SRVAL(p) ((void*)((SorterRecord*)(p) + 1))
77502
 
 
 
 
 
77503
77504 /* Maximum number of PMAs that a single MergeEngine can merge */
77505 #define SORTER_MAX_MERGE_COUNT 16
77506
77507 static int vdbeIncrSwap(IncrMerger*);
@@ -77834,14 +77896,15 @@
77896 SortSubtask *pTask = &pSorter->aTask[i];
77897 pTask->pSorter = pSorter;
77898 }
77899
77900 if( !sqlite3TempInMemory(db) ){
77901 u32 szPma = sqlite3GlobalConfig.szPma;
77902 pSorter->mnPmaSize = szPma * pgsz;
77903 mxCache = db->aDb[0].pSchema->cache_size;
77904 if( mxCache<(int)szPma ) mxCache = (int)szPma;
77905 pSorter->mxPmaSize = MIN((i64)mxCache*pgsz, SQLITE_MAX_PMASZ);
77906
77907 /* EVIDENCE-OF: R-26747-61719 When the application provides any amount of
77908 ** scratch memory using SQLITE_CONFIG_SCRATCH, SQLite avoids unnecessary
77909 ** large heap allocations.
77910 */
@@ -78115,16 +78178,16 @@
78178 ** Whether or not the file does end up memory mapped of course depends on
78179 ** the specific VFS implementation.
78180 */
78181 static void vdbeSorterExtendFile(sqlite3 *db, sqlite3_file *pFd, i64 nByte){
78182 if( nByte<=(i64)(db->nMaxSorterMmap) && pFd->pMethods->iVersion>=3 ){
78183 void *p = 0;
78184 int chunksize = 4*1024;
78185 sqlite3OsFileControlHint(pFd, SQLITE_FCNTL_CHUNK_SIZE, &chunksize);
78186 sqlite3OsFileControlHint(pFd, SQLITE_FCNTL_SIZE_HINT, &nByte);
78187 sqlite3OsFetch(pFd, 0, (int)nByte, &p);
78188 sqlite3OsUnfetch(pFd, 0, p);
78189 }
78190 }
78191 #else
78192 # define vdbeSorterExtendFile(x,y,z)
78193 #endif
@@ -87302,11 +87365,11 @@
87365
87366 p->iGet = -1;
87367 p->mxSample = mxSample;
87368 p->nPSample = (tRowcnt)(sqlite3_value_int64(argv[2])/(mxSample/3+1) + 1);
87369 p->current.anLt = &p->current.anEq[nColUp];
87370 p->iPrn = 0x689e962d*(u32)nCol ^ 0xd0944565*(u32)sqlite3_value_int(argv[2]);
87371
87372 /* Set up the Stat4Accum.a[] and aBest[] arrays */
87373 p->a = (struct Stat4Sample*)&p->current.anLt[nColUp];
87374 p->aBest = &p->a[mxSample];
87375 pSpace = (u8*)(&p->a[mxSample+nCol]);
@@ -88895,17 +88958,19 @@
88958 }else if( aNew->pSchema->file_format && aNew->pSchema->enc!=ENC(db) ){
88959 zErrDyn = sqlite3MPrintf(db,
88960 "attached databases must use the same text encoding as main database");
88961 rc = SQLITE_ERROR;
88962 }
88963 sqlite3BtreeEnter(aNew->pBt);
88964 pPager = sqlite3BtreePager(aNew->pBt);
88965 sqlite3PagerLockingMode(pPager, db->dfltLockMode);
88966 sqlite3BtreeSecureDelete(aNew->pBt,
88967 sqlite3BtreeSecureDelete(db->aDb[0].pBt,-1) );
88968 #ifndef SQLITE_OMIT_PAGER_PRAGMAS
88969 sqlite3BtreeSetPagerFlags(aNew->pBt, 3 | (db->flags & PAGER_FLAGS_MASK));
88970 #endif
88971 sqlite3BtreeLeave(aNew->pBt);
88972 }
88973 aNew->safety_level = 3;
88974 aNew->zName = sqlite3DbStrDup(db, zName);
88975 if( rc==SQLITE_OK && aNew->zName==0 ){
88976 rc = SQLITE_NOMEM;
@@ -90027,11 +90092,10 @@
90092 */
90093 static void freeIndex(sqlite3 *db, Index *p){
90094 #ifndef SQLITE_OMIT_ANALYZE
90095 sqlite3DeleteIndexSamples(db, p);
90096 #endif
 
90097 sqlite3ExprDelete(db, p->pPartIdxWhere);
90098 sqlite3DbFree(db, p->zColAff);
90099 if( p->isResized ) sqlite3DbFree(db, p->azColl);
90100 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
90101 sqlite3_free(p->aiRowEst);
@@ -91306,10 +91370,23 @@
91370 if( pPk==0 ) return;
91371 pPk->idxType = SQLITE_IDXTYPE_PRIMARYKEY;
91372 pTab->iPKey = -1;
91373 }else{
91374 pPk = sqlite3PrimaryKeyIndex(pTab);
91375 /*
91376 ** Remove all redundant columns from the PRIMARY KEY. For example, change
91377 ** "PRIMARY KEY(a,b,a,b,c,b,c,d)" into just "PRIMARY KEY(a,b,c,d)". Later
91378 ** code assumes the PRIMARY KEY contains no repeated columns.
91379 */
91380 for(i=j=1; i<pPk->nKeyCol; i++){
91381 if( hasColumn(pPk->aiColumn, j, pPk->aiColumn[i]) ){
91382 pPk->nColumn--;
91383 }else{
91384 pPk->aiColumn[j++] = pPk->aiColumn[i];
91385 }
91386 }
91387 pPk->nKeyCol = j;
91388 }
91389 pPk->isCovering = 1;
91390 assert( pPk!=0 );
91391 nPk = pPk->nKeyCol;
91392
@@ -93782,44 +93859,35 @@
93859 **
93860 ** The caller should invoke sqlite3KeyInfoUnref() on the returned object
93861 ** when it has finished using it.
93862 */
93863 SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoOfIndex(Parse *pParse, Index *pIdx){
93864 int i;
93865 int nCol = pIdx->nColumn;
93866 int nKey = pIdx->nKeyCol;
93867 KeyInfo *pKey;
93868 if( pParse->nErr ) return 0;
93869 if( pIdx->uniqNotNull ){
93870 pKey = sqlite3KeyInfoAlloc(pParse->db, nKey, nCol-nKey);
93871 }else{
93872 pKey = sqlite3KeyInfoAlloc(pParse->db, nCol, 0);
93873 }
93874 if( pKey ){
93875 assert( sqlite3KeyInfoIsWriteable(pKey) );
93876 for(i=0; i<nCol; i++){
93877 char *zColl = pIdx->azColl[i];
93878 assert( zColl!=0 );
93879 pKey->aColl[i] = strcmp(zColl,"BINARY")==0 ? 0 :
93880 sqlite3LocateCollSeq(pParse, zColl);
93881 pKey->aSortOrder[i] = pIdx->aSortOrder[i];
93882 }
93883 if( pParse->nErr ){
93884 sqlite3KeyInfoUnref(pKey);
93885 pKey = 0;
93886 }
93887 }
93888 return pKey;
 
 
 
 
 
 
 
 
 
 
 
 
 
93889 }
93890
93891 #ifndef SQLITE_OMIT_CTE
93892 /*
93893 ** This routine is invoked once per CTE by the parser while parsing a
@@ -97436,11 +97504,11 @@
97504 assert( nIncr==1 );
97505 sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_FOREIGNKEY,
97506 OE_Abort, 0, P4_STATIC, P5_ConstraintFK);
97507 }else{
97508 if( nIncr>0 && pFKey->isDeferred==0 ){
97509 sqlite3MayAbort(pParse);
97510 }
97511 sqlite3VdbeAddOp2(v, OP_FkCounter, pFKey->isDeferred, nIncr);
97512 }
97513
97514 sqlite3VdbeResolveLabel(v, iOk);
@@ -97507,10 +97575,14 @@
97575 ** This function is called to generate code executed when a row is deleted
97576 ** from the parent table of foreign key constraint pFKey and, if pFKey is
97577 ** deferred, when a row is inserted into the same table. When generating
97578 ** code for an SQL UPDATE operation, this function may be called twice -
97579 ** once to "delete" the old row and once to "insert" the new row.
97580 **
97581 ** Parameter nIncr is passed -1 when inserting a row (as this may decrease
97582 ** the number of FK violations in the db) or +1 when deleting one (as this
97583 ** may increase the number of FK constraint problems).
97584 **
97585 ** The code generated by this function scans through the rows in the child
97586 ** table that correspond to the parent table row being deleted or inserted.
97587 ** For each child row found, one of the following actions is taken:
97588 **
@@ -97624,17 +97696,13 @@
97696 sNameContext.pSrcList = pSrc;
97697 sNameContext.pParse = pParse;
97698 sqlite3ResolveExprNames(&sNameContext, pWhere);
97699
97700 /* Create VDBE to loop through the entries in pSrc that match the WHERE
97701 ** clause. For each row found, increment either the deferred or immediate
97702 ** foreign key constraint counter. */
 
97703 pWInfo = sqlite3WhereBegin(pParse, pSrc, pWhere, 0, 0, 0, 0);
 
 
 
97704 sqlite3VdbeAddOp2(v, OP_FkCounter, pFKey->isDeferred, nIncr);
97705 if( pWInfo ){
97706 sqlite3WhereEnd(pWInfo);
97707 }
97708
@@ -97808,10 +97876,28 @@
97876 }
97877 }
97878 }
97879 return 0;
97880 }
97881
97882 /*
97883 ** Return true if the parser passed as the first argument is being
97884 ** used to code a trigger that is really a "SET NULL" action belonging
97885 ** to trigger pFKey.
97886 */
97887 static int isSetNullAction(Parse *pParse, FKey *pFKey){
97888 Parse *pTop = sqlite3ParseToplevel(pParse);
97889 if( pTop->pTriggerPrg ){
97890 Trigger *p = pTop->pTriggerPrg->pTrigger;
97891 if( (p==pFKey->apTrigger[0] && pFKey->aAction[0]==OE_SetNull)
97892 || (p==pFKey->apTrigger[1] && pFKey->aAction[1]==OE_SetNull)
97893 ){
97894 return 1;
97895 }
97896 }
97897 return 0;
97898 }
97899
97900 /*
97901 ** This function is called when inserting, deleting or updating a row of
97902 ** table pTab to generate VDBE code to perform foreign key constraint
97903 ** processing for the operation.
@@ -97861,11 +97947,11 @@
97947 Index *pIdx = 0; /* Index on key columns in pTo */
97948 int *aiFree = 0;
97949 int *aiCol;
97950 int iCol;
97951 int i;
97952 int bIgnore = 0;
97953
97954 if( aChange
97955 && sqlite3_stricmp(pTab->zName, pFKey->zTo)!=0
97956 && fkChildIsModified(pTab, pFKey, aChange, bChngRowid)==0
97957 ){
@@ -97920,11 +98006,11 @@
98006 ** values read from the parent table are NULL. */
98007 if( db->xAuth ){
98008 int rcauth;
98009 char *zCol = pTo->aCol[pIdx ? pIdx->aiColumn[i] : pTo->iPKey].zName;
98010 rcauth = sqlite3AuthReadCol(pParse, pTo->zName, zCol, iDb);
98011 bIgnore = (rcauth==SQLITE_IGNORE);
98012 }
98013 #endif
98014 }
98015
98016 /* Take a shared-cache advisory read-lock on the parent table. Allocate
@@ -97935,16 +98021,22 @@
98021
98022 if( regOld!=0 ){
98023 /* A row is being removed from the child table. Search for the parent.
98024 ** If the parent does not exist, removing the child row resolves an
98025 ** outstanding foreign key constraint violation. */
98026 fkLookupParent(pParse, iDb, pTo, pIdx, pFKey, aiCol, regOld, -1, bIgnore);
98027 }
98028 if( regNew!=0 && !isSetNullAction(pParse, pFKey) ){
98029 /* A row is being added to the child table. If a parent row cannot
98030 ** be found, adding the child row has violated the FK constraint.
98031 **
98032 ** If this operation is being performed as part of a trigger program
98033 ** that is actually a "SET NULL" action belonging to this very
98034 ** foreign key, then omit this scan altogether. As all child key
98035 ** values are guaranteed to be NULL, it is not possible for adding
98036 ** this row to cause an FK violation. */
98037 fkLookupParent(pParse, iDb, pTo, pIdx, pFKey, aiCol, regNew, +1, bIgnore);
98038 }
98039
98040 sqlite3DbFree(db, aiFree);
98041 }
98042
@@ -97961,12 +98053,12 @@
98053
98054 if( !pFKey->isDeferred && !(db->flags & SQLITE_DeferFKs)
98055 && !pParse->pToplevel && !pParse->isMultiWrite
98056 ){
98057 assert( regOld==0 && regNew!=0 );
98058 /* Inserting a single row into a parent table cannot cause (or fix)
98059 ** an immediate foreign key violation. So do nothing in this case. */
98060 continue;
98061 }
98062
98063 if( sqlite3FkLocateIndex(pParse, pTab, pFKey, &pIdx, &aiCol) ){
98064 if( !isIgnoreErrors || db->mallocFailed ) return;
@@ -97986,17 +98078,32 @@
98078
98079 if( regNew!=0 ){
98080 fkScanChildren(pParse, pSrc, pTab, pIdx, pFKey, aiCol, regNew, -1);
98081 }
98082 if( regOld!=0 ){
98083 int eAction = pFKey->aAction[aChange!=0];
 
 
 
 
 
98084 fkScanChildren(pParse, pSrc, pTab, pIdx, pFKey, aiCol, regOld, 1);
98085 /* If this is a deferred FK constraint, or a CASCADE or SET NULL
98086 ** action applies, then any foreign key violations caused by
98087 ** removing the parent key will be rectified by the action trigger.
98088 ** So do not set the "may-abort" flag in this case.
98089 **
98090 ** Note 1: If the FK is declared "ON UPDATE CASCADE", then the
98091 ** may-abort flag will eventually be set on this statement anyway
98092 ** (when this function is called as part of processing the UPDATE
98093 ** within the action trigger).
98094 **
98095 ** Note 2: At first glance it may seem like SQLite could simply omit
98096 ** all OP_FkCounter related scans when either CASCADE or SET NULL
98097 ** applies. The trouble starts if the CASCADE or SET NULL action
98098 ** trigger causes other triggers or action rules attached to the
98099 ** child table to fire. In these cases the fk constraint counters
98100 ** might be set incorrectly if any OP_FkCounter related scans are
98101 ** omitted. */
98102 if( !pFKey->isDeferred && eAction!=OE_Cascade && eAction!=OE_SetNull ){
98103 sqlite3MayAbort(pParse);
98104 }
98105 }
98106 pItem->zName = 0;
98107 sqlite3SrcListDelete(db, pSrc);
98108 }
98109 sqlite3DbFree(db, aiCol);
@@ -101895,10 +102002,11 @@
102002 #define PragTyp_KEY 38
102003 #define PragTyp_REKEY 39
102004 #define PragTyp_LOCK_STATUS 40
102005 #define PragTyp_PARSER_TRACE 41
102006 #define PragFlag_NeedSchema 0x01
102007 #define PragFlag_ReadOnly 0x02
102008 static const struct sPragmaNames {
102009 const char *const zName; /* Name of pragma */
102010 u8 ePragTyp; /* PragTyp_XXX value */
102011 u8 mPragFlag; /* Zero or more PragFlag_XXX values */
102012 u32 iArg; /* Extra argument */
@@ -101911,11 +102019,11 @@
102019 #endif
102020 #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
102021 { /* zName: */ "application_id",
102022 /* ePragTyp: */ PragTyp_HEADER_VALUE,
102023 /* ePragFlag: */ 0,
102024 /* iArg: */ BTREE_APPLICATION_ID },
102025 #endif
102026 #if !defined(SQLITE_OMIT_AUTOVACUUM)
102027 { /* zName: */ "auto_vacuum",
102028 /* ePragTyp: */ PragTyp_AUTO_VACUUM,
102029 /* ePragFlag: */ PragFlag_NeedSchema,
@@ -101977,10 +102085,16 @@
102085 { /* zName: */ "data_store_directory",
102086 /* ePragTyp: */ PragTyp_DATA_STORE_DIRECTORY,
102087 /* ePragFlag: */ 0,
102088 /* iArg: */ 0 },
102089 #endif
102090 #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
102091 { /* zName: */ "data_version",
102092 /* ePragTyp: */ PragTyp_HEADER_VALUE,
102093 /* ePragFlag: */ PragFlag_ReadOnly,
102094 /* iArg: */ BTREE_DATA_VERSION },
102095 #endif
102096 #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
102097 { /* zName: */ "database_list",
102098 /* ePragTyp: */ PragTyp_DATABASE_LIST,
102099 /* ePragFlag: */ PragFlag_NeedSchema,
102100 /* iArg: */ 0 },
@@ -102032,12 +102146,12 @@
102146 #endif
102147 #endif
102148 #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
102149 { /* zName: */ "freelist_count",
102150 /* ePragTyp: */ PragTyp_HEADER_VALUE,
102151 /* ePragFlag: */ PragFlag_ReadOnly,
102152 /* iArg: */ BTREE_FREE_PAGE_COUNT },
102153 #endif
102154 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
102155 { /* zName: */ "full_column_names",
102156 /* ePragTyp: */ PragTyp_FLAG,
102157 /* ePragFlag: */ 0,
@@ -102185,11 +102299,11 @@
102299 #endif
102300 #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
102301 { /* zName: */ "schema_version",
102302 /* ePragTyp: */ PragTyp_HEADER_VALUE,
102303 /* ePragFlag: */ 0,
102304 /* iArg: */ BTREE_SCHEMA_VERSION },
102305 #endif
102306 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
102307 { /* zName: */ "secure_delete",
102308 /* ePragTyp: */ PragTyp_SECURE_DELETE,
102309 /* ePragFlag: */ 0,
@@ -102251,11 +102365,11 @@
102365 /* iArg: */ 0 },
102366 #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
102367 { /* zName: */ "user_version",
102368 /* ePragTyp: */ PragTyp_HEADER_VALUE,
102369 /* ePragFlag: */ 0,
102370 /* iArg: */ BTREE_USER_VERSION },
102371 #endif
102372 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
102373 #if defined(SQLITE_DEBUG)
102374 { /* zName: */ "vdbe_addoptrace",
102375 /* ePragTyp: */ PragTyp_FLAG,
@@ -102294,11 +102408,11 @@
102408 /* ePragTyp: */ PragTyp_FLAG,
102409 /* ePragFlag: */ 0,
102410 /* iArg: */ SQLITE_WriteSchema|SQLITE_RecoveryMode },
102411 #endif
102412 };
102413 /* Number of pragmas: 58 on by default, 71 total. */
102414 /* End of the automatically generated pragma table.
102415 ***************************************************************************/
102416
102417 /*
102418 ** Interpret the given string as a safety level. Return 0 for OFF,
@@ -103904,11 +104018,12 @@
104018 !(DbHasProperty(db, 0, DB_SchemaLoaded)) ||
104019 DbHasProperty(db, 0, DB_Empty)
104020 ){
104021 for(pEnc=&encnames[0]; pEnc->zName; pEnc++){
104022 if( 0==sqlite3StrICmp(zRight, pEnc->zName) ){
104023 SCHEMA_ENC(db) = ENC(db) =
104024 pEnc->enc ? pEnc->enc : SQLITE_UTF16NATIVE;
104025 break;
104026 }
104027 }
104028 if( !pEnc->zName ){
104029 sqlite3ErrorMsg(pParse, "unsupported encoding: %s", zRight);
@@ -103949,28 +104064,13 @@
104064 **
104065 ** The user-version is not used internally by SQLite. It may be used by
104066 ** applications for any purpose.
104067 */
104068 case PragTyp_HEADER_VALUE: {
104069 int iCookie = aPragmaNames[mid].iArg; /* Which cookie to read or write */
104070 sqlite3VdbeUsesBtree(v, iDb);
104071 if( zRight && (aPragmaNames[mid].mPragFlag & PragFlag_ReadOnly)==0 ){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104072 /* Write the specified cookie value */
104073 static const VdbeOpList setCookie[] = {
104074 { OP_Transaction, 0, 1, 0}, /* 0 */
104075 { OP_Integer, 0, 1, 0}, /* 1 */
104076 { OP_SetCookie, 0, 0, 1}, /* 2 */
@@ -104612,13 +104712,15 @@
104712 SQLITE_PRIVATE int sqlite3Init(sqlite3 *db, char **pzErrMsg){
104713 int i, rc;
104714 int commit_internal = !(db->flags&SQLITE_InternChanges);
104715
104716 assert( sqlite3_mutex_held(db->mutex) );
104717 assert( sqlite3BtreeHoldsMutex(db->aDb[0].pBt) );
104718 assert( db->init.busy==0 );
104719 rc = SQLITE_OK;
104720 db->init.busy = 1;
104721 ENC(db) = SCHEMA_ENC(db);
104722 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
104723 if( DbHasProperty(db, i, DB_SchemaLoaded) || i==1 ) continue;
104724 rc = sqlite3InitOne(db, i, pzErrMsg);
104725 if( rc ){
104726 sqlite3ResetOneSchema(db, i);
@@ -110756,11 +110858,11 @@
110858 ){
110859 int rc;
110860 TabResult res;
110861
110862 #ifdef SQLITE_ENABLE_API_ARMOR
110863 if( !sqlite3SafetyCheckOk(db) || pazResult==0 ) return SQLITE_MISUSE_BKPT;
110864 #endif
110865 *pazResult = 0;
110866 if( pnColumn ) *pnColumn = 0;
110867 if( pnRow ) *pnRow = 0;
110868 if( pzErrMsg ) *pzErrMsg = 0;
@@ -118626,11 +118728,10 @@
118728 sqlite3_free(p->u.vtab.idxStr);
118729 p->u.vtab.needFree = 0;
118730 p->u.vtab.idxStr = 0;
118731 }else if( (p->wsFlags & WHERE_AUTO_INDEX)!=0 && p->u.btree.pIndex!=0 ){
118732 sqlite3DbFree(db, p->u.btree.pIndex->zColAff);
 
118733 sqlite3DbFree(db, p->u.btree.pIndex);
118734 p->u.btree.pIndex = 0;
118735 }
118736 }
118737 }
@@ -125633,10 +125734,13 @@
125734 u8 enableLookaside; /* Saved value of db->lookaside.bEnabled */
125735 sqlite3 *db = pParse->db; /* The database connection */
125736 int mxSqlLen; /* Max length of an SQL string */
125737
125738
125739 #ifdef SQLITE_ENABLE_API_ARMOR
125740 if( zSql==0 || pzErrMsg==0 ) return SQLITE_MISUSE_BKPT;
125741 #endif
125742 mxSqlLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];
125743 if( db->nVdbeActive==0 ){
125744 db->u1.isInterrupted = 0;
125745 }
125746 pParse->rc = SQLITE_OK;
@@ -125871,17 +125975,10 @@
125975 */
125976 SQLITE_API int sqlite3_complete(const char *zSql){
125977 u8 state = 0; /* Current state, using numbers defined in header comment */
125978 u8 token; /* Value of the next token */
125979
 
 
 
 
 
 
 
125980 #ifndef SQLITE_OMIT_TRIGGER
125981 /* A complex statement machine used to detect the end of a CREATE TRIGGER
125982 ** statement. This is the normal case.
125983 */
125984 static const u8 trans[8][8] = {
@@ -125906,10 +126003,17 @@
126003 /* 0 INVALID: */ { 1, 0, 2, },
126004 /* 1 START: */ { 1, 1, 2, },
126005 /* 2 NORMAL: */ { 1, 2, 2, },
126006 };
126007 #endif /* SQLITE_OMIT_TRIGGER */
126008
126009 #ifdef SQLITE_ENABLE_API_ARMOR
126010 if( zSql==0 ){
126011 (void)SQLITE_MISUSE_BKPT;
126012 return 0;
126013 }
126014 #endif
126015
126016 while( *zSql ){
126017 switch( *zSql ){
126018 case ';': { /* A semicolon */
126019 token = tkSEMI;
@@ -126208,11 +126312,11 @@
126312 ** If the following function pointer is not NULL and if
126313 ** SQLITE_ENABLE_IOTRACE is enabled, then messages describing
126314 ** I/O active are written using this function. These messages
126315 ** are intended for debugging activity only.
126316 */
126317 /* not-private */ void (*sqlite3IoTrace)(const char*, ...) = 0;
126318 #endif
126319
126320 /*
126321 ** If the following global variable points to a string which is the
126322 ** name of a directory, then that directory will be used to store
@@ -126417,10 +126521,17 @@
126521 ** routine is not threadsafe. But it is safe to invoke this routine
126522 ** on when SQLite is already shut down. If SQLite is already shut down
126523 ** when this routine is invoked, then this routine is a harmless no-op.
126524 */
126525 SQLITE_API int sqlite3_shutdown(void){
126526 #ifdef SQLITE_OMIT_WSD
126527 int rc = sqlite3_wsd_init(4096, 24);
126528 if( rc!=SQLITE_OK ){
126529 return rc;
126530 }
126531 #endif
126532
126533 if( sqlite3GlobalConfig.isInit ){
126534 #ifdef SQLITE_EXTRA_SHUTDOWN
126535 void SQLITE_EXTRA_SHUTDOWN(void);
126536 SQLITE_EXTRA_SHUTDOWN();
126537 #endif
@@ -126732,10 +126843,15 @@
126843 ** heap. */
126844 sqlite3GlobalConfig.nHeap = va_arg(ap, int);
126845 break;
126846 }
126847 #endif
126848
126849 case SQLITE_CONFIG_PMASZ: {
126850 sqlite3GlobalConfig.szPma = va_arg(ap, unsigned int);
126851 break;
126852 }
126853
126854 default: {
126855 rc = SQLITE_ERROR;
126856 break;
126857 }
@@ -127178,20 +127294,10 @@
127294
127295 /* Close all database connections */
127296 for(j=0; j<db->nDb; j++){
127297 struct Db *pDb = &db->aDb[j];
127298 if( pDb->pBt ){
 
 
 
 
 
 
 
 
 
 
127299 sqlite3BtreeClose(pDb->pBt);
127300 pDb->pBt = 0;
127301 if( j!=1 ){
127302 pDb->pSchema = 0;
127303 }
@@ -128315,36 +128421,10 @@
128421 */
128422 SQLITE_API const char *sqlite3_errstr(int rc){
128423 return sqlite3ErrStr(rc);
128424 }
128425
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
128426 /*
128427 ** Create a new collating function for database "db". The name is zName
128428 ** and the encoding is enc.
128429 */
128430 static int createCollation(
@@ -128384,11 +128464,10 @@
128464 sqlite3ErrorWithMsg(db, SQLITE_BUSY,
128465 "unable to delete/modify collation sequence due to active statements");
128466 return SQLITE_BUSY;
128467 }
128468 sqlite3ExpirePreparedStatements(db);
 
128469
128470 /* If collation sequence pColl was created directly by a call to
128471 ** sqlite3_create_collation, and not generated by synthCollSeq(),
128472 ** then any copies made by synthCollSeq() need to be invalidated.
128473 ** Also, collation destructor - CollSeq.xDel() - function may need
@@ -128941,10 +129020,11 @@
129020 sqlite3Error(db, rc);
129021 goto opendb_out;
129022 }
129023 sqlite3BtreeEnter(db->aDb[0].pBt);
129024 db->aDb[0].pSchema = sqlite3SchemaGet(db, db->aDb[0].pBt);
129025 if( !db->mallocFailed ) ENC(db) = SCHEMA_ENC(db);
129026 sqlite3BtreeLeave(db->aDb[0].pBt);
129027 db->aDb[1].pSchema = sqlite3SchemaGet(db, 0);
129028
129029 /* The default safety_level for the main database is 'full'; for the temp
129030 ** database it is 'NONE'. This matches the pager layer defaults.
@@ -129099,11 +129179,11 @@
129179 if( zFilename8 ){
129180 rc = openDatabase(zFilename8, ppDb,
129181 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, 0);
129182 assert( *ppDb || rc==SQLITE_NOMEM );
129183 if( rc==SQLITE_OK && !DbHasProperty(*ppDb, 0, DB_SchemaLoaded) ){
129184 SCHEMA_ENC(*ppDb) = ENC(*ppDb) = SQLITE_UTF16NATIVE;
129185 }
129186 }else{
129187 rc = SQLITE_NOMEM;
129188 }
129189 sqlite3ValueFree(pVal);
@@ -129841,32 +129921,34 @@
129921 /*
129922 ** Return the filename of the database associated with a database
129923 ** connection.
129924 */
129925 SQLITE_API const char *sqlite3_db_filename(sqlite3 *db, const char *zDbName){
129926 Btree *pBt;
129927 #ifdef SQLITE_ENABLE_API_ARMOR
129928 if( !sqlite3SafetyCheckOk(db) ){
129929 (void)SQLITE_MISUSE_BKPT;
129930 return 0;
129931 }
129932 #endif
129933 pBt = sqlite3DbNameToBtree(db, zDbName);
129934 return pBt ? sqlite3BtreeGetFilename(pBt) : 0;
129935 }
129936
129937 /*
129938 ** Return 1 if database is read-only or 0 if read/write. Return -1 if
129939 ** no such database exists.
129940 */
129941 SQLITE_API int sqlite3_db_readonly(sqlite3 *db, const char *zDbName){
129942 Btree *pBt;
129943 #ifdef SQLITE_ENABLE_API_ARMOR
129944 if( !sqlite3SafetyCheckOk(db) ){
129945 (void)SQLITE_MISUSE_BKPT;
129946 return -1;
129947 }
129948 #endif
129949 pBt = sqlite3DbNameToBtree(db, zDbName);
129950 return pBt ? sqlite3BtreeIsReadonly(pBt) : -1;
129951 }
129952
129953 /************** End of main.c ************************************************/
129954 /************** Begin file notify.c ******************************************/
@@ -150073,11 +150155,11 @@
150155 }
150156 i = pCur->nPoint++;
150157 pNew = pCur->aPoint + i;
150158 pNew->rScore = rScore;
150159 pNew->iLevel = iLevel;
150160 assert( iLevel<=RTREE_MAX_DEPTH );
150161 while( i>0 ){
150162 RtreeSearchPoint *pParent;
150163 j = (i-1)/2;
150164 pParent = pCur->aPoint + j;
150165 if( rtreeSearchPointCompare(pNew, pParent)>=0 ) break;
150166
+18 -8
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107107
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108108
** [sqlite_version()] and [sqlite_source_id()].
109109
*/
110110
#define SQLITE_VERSION "3.8.8"
111111
#define SQLITE_VERSION_NUMBER 3008008
112
-#define SQLITE_SOURCE_ID "2014-12-10 04:58:43 3528f8dd39acace8eeb7337994c8617313f4b04b"
112
+#define SQLITE_SOURCE_ID "2015-01-03 18:59:17 23d4c07eb81db5a5c6beb56b5820f0b6501f1fb6"
113113
114114
/*
115115
** CAPI3REF: Run-Time Library Version Numbers
116116
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117117
**
@@ -199,11 +199,11 @@
199199
** This interface only reports on the compile-time mutex setting
200200
** of the [SQLITE_THREADSAFE] flag. If SQLite is compiled with
201201
** SQLITE_THREADSAFE=1 or =2 then mutexes are enabled by default but
202202
** can be fully or partially disabled using a call to [sqlite3_config()]
203203
** with the verbs [SQLITE_CONFIG_SINGLETHREAD], [SQLITE_CONFIG_MULTITHREAD],
204
-** or [SQLITE_CONFIG_MUTEX]. ^(The return value of the
204
+** or [SQLITE_CONFIG_SERIALIZED]. ^(The return value of the
205205
** sqlite3_threadsafe() function shows only the compile-time setting of
206206
** thread safety, not any run-time changes to that setting made by
207207
** sqlite3_config(). In other words, the return value from sqlite3_threadsafe()
208208
** is unchanged by calls to sqlite3_config().)^
209209
**
@@ -1568,11 +1568,11 @@
15681568
** configuration option.
15691569
** ^There are three arguments to SQLITE_CONFIG_PAGECACHE: A pointer to
15701570
** 8-byte aligned
15711571
** memory, the size of each page buffer (sz), and the number of pages (N).
15721572
** The sz argument should be the size of the largest database page
1573
-** (a power of two between 512 and 32768) plus some extra bytes for each
1573
+** (a power of two between 512 and 65536) plus some extra bytes for each
15741574
** page header. ^The number of extra bytes needed by the page header
15751575
** can be determined using the [SQLITE_CONFIG_PCACHE_HDRSZ] option
15761576
** to [sqlite3_config()].
15771577
** ^It is harmless, apart from the wasted memory,
15781578
** for the sz parameter to be larger than necessary. The first
@@ -1748,10 +1748,21 @@
17481748
** <dd>^The SQLITE_CONFIG_PCACHE_HDRSZ option takes a single parameter which
17491749
** is a pointer to an integer and writes into that integer the number of extra
17501750
** bytes per page required for each page in [SQLITE_CONFIG_PAGECACHE].
17511751
** The amount of extra space required can change depending on the compiler,
17521752
** target platform, and SQLite version.
1753
+**
1754
+** [[SQLITE_CONFIG_PMASZ]]
1755
+** <dt>SQLITE_CONFIG_PMASZ
1756
+** <dd>^The SQLITE_CONFIG_PMASZ option takes a single parameter which
1757
+** is an unsigned integer and sets the "Minimum PMA Size" for the multithreaded
1758
+** sorter to that integer. The default minimum PMA Size is set by the
1759
+** [SQLITE_SORTER_PMASZ] compile-time option. New threads are launched
1760
+** to help with sort operations when multithreaded sorting
1761
+** is enabled (using the [PRAGMA threads] command) and the amount of content
1762
+** to be sorted exceeds the page size times the minimum of the
1763
+** [PRAGMA cache_size] setting and this value.
17531764
** </dl>
17541765
*/
17551766
#define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
17561767
#define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
17571768
#define SQLITE_CONFIG_SERIALIZED 3 /* nil */
@@ -1774,10 +1785,11 @@
17741785
#define SQLITE_CONFIG_COVERING_INDEX_SCAN 20 /* int */
17751786
#define SQLITE_CONFIG_SQLLOG 21 /* xSqllog, void* */
17761787
#define SQLITE_CONFIG_MMAP_SIZE 22 /* sqlite3_int64, sqlite3_int64 */
17771788
#define SQLITE_CONFIG_WIN32_HEAPSIZE 23 /* int nByte */
17781789
#define SQLITE_CONFIG_PCACHE_HDRSZ 24 /* int *psz */
1790
+#define SQLITE_CONFIG_PMASZ 25 /* unsigned int szPma */
17791791
17801792
/*
17811793
** CAPI3REF: Database Connection Configuration Options
17821794
**
17831795
** These constants are the available integer configuration options that
@@ -7183,16 +7195,14 @@
71837195
71847196
/*
71857197
** CAPI3REF: Write-Ahead Log Commit Hook
71867198
**
71877199
** ^The [sqlite3_wal_hook()] function is used to register a callback that
7188
-** will be invoked each time a database connection commits data to a
7189
-** [write-ahead log] (i.e. whenever a transaction is committed in
7190
-** [journal_mode | journal_mode=WAL mode]).
7200
+** is invoked each time data is committed to a database in wal mode.
71917201
**
7192
-** ^The callback is invoked by SQLite after the commit has taken place and
7193
-** the associated write-lock on the database released, so the implementation
7202
+** ^(The callback is invoked by SQLite after the commit has taken place and
7203
+** the associated write-lock on the database released)^, so the implementation
71947204
** may read, write or [checkpoint] the database as required.
71957205
**
71967206
** ^The first parameter passed to the callback function when it is invoked
71977207
** is a copy of the third parameter passed to sqlite3_wal_hook() when
71987208
** registering the callback. ^The second is a copy of the database handle.
71997209
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.8.8"
111 #define SQLITE_VERSION_NUMBER 3008008
112 #define SQLITE_SOURCE_ID "2014-12-10 04:58:43 3528f8dd39acace8eeb7337994c8617313f4b04b"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -199,11 +199,11 @@
199 ** This interface only reports on the compile-time mutex setting
200 ** of the [SQLITE_THREADSAFE] flag. If SQLite is compiled with
201 ** SQLITE_THREADSAFE=1 or =2 then mutexes are enabled by default but
202 ** can be fully or partially disabled using a call to [sqlite3_config()]
203 ** with the verbs [SQLITE_CONFIG_SINGLETHREAD], [SQLITE_CONFIG_MULTITHREAD],
204 ** or [SQLITE_CONFIG_MUTEX]. ^(The return value of the
205 ** sqlite3_threadsafe() function shows only the compile-time setting of
206 ** thread safety, not any run-time changes to that setting made by
207 ** sqlite3_config(). In other words, the return value from sqlite3_threadsafe()
208 ** is unchanged by calls to sqlite3_config().)^
209 **
@@ -1568,11 +1568,11 @@
1568 ** configuration option.
1569 ** ^There are three arguments to SQLITE_CONFIG_PAGECACHE: A pointer to
1570 ** 8-byte aligned
1571 ** memory, the size of each page buffer (sz), and the number of pages (N).
1572 ** The sz argument should be the size of the largest database page
1573 ** (a power of two between 512 and 32768) plus some extra bytes for each
1574 ** page header. ^The number of extra bytes needed by the page header
1575 ** can be determined using the [SQLITE_CONFIG_PCACHE_HDRSZ] option
1576 ** to [sqlite3_config()].
1577 ** ^It is harmless, apart from the wasted memory,
1578 ** for the sz parameter to be larger than necessary. The first
@@ -1748,10 +1748,21 @@
1748 ** <dd>^The SQLITE_CONFIG_PCACHE_HDRSZ option takes a single parameter which
1749 ** is a pointer to an integer and writes into that integer the number of extra
1750 ** bytes per page required for each page in [SQLITE_CONFIG_PAGECACHE].
1751 ** The amount of extra space required can change depending on the compiler,
1752 ** target platform, and SQLite version.
 
 
 
 
 
 
 
 
 
 
 
1753 ** </dl>
1754 */
1755 #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
1756 #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
1757 #define SQLITE_CONFIG_SERIALIZED 3 /* nil */
@@ -1774,10 +1785,11 @@
1774 #define SQLITE_CONFIG_COVERING_INDEX_SCAN 20 /* int */
1775 #define SQLITE_CONFIG_SQLLOG 21 /* xSqllog, void* */
1776 #define SQLITE_CONFIG_MMAP_SIZE 22 /* sqlite3_int64, sqlite3_int64 */
1777 #define SQLITE_CONFIG_WIN32_HEAPSIZE 23 /* int nByte */
1778 #define SQLITE_CONFIG_PCACHE_HDRSZ 24 /* int *psz */
 
1779
1780 /*
1781 ** CAPI3REF: Database Connection Configuration Options
1782 **
1783 ** These constants are the available integer configuration options that
@@ -7183,16 +7195,14 @@
7183
7184 /*
7185 ** CAPI3REF: Write-Ahead Log Commit Hook
7186 **
7187 ** ^The [sqlite3_wal_hook()] function is used to register a callback that
7188 ** will be invoked each time a database connection commits data to a
7189 ** [write-ahead log] (i.e. whenever a transaction is committed in
7190 ** [journal_mode | journal_mode=WAL mode]).
7191 **
7192 ** ^The callback is invoked by SQLite after the commit has taken place and
7193 ** the associated write-lock on the database released, so the implementation
7194 ** may read, write or [checkpoint] the database as required.
7195 **
7196 ** ^The first parameter passed to the callback function when it is invoked
7197 ** is a copy of the third parameter passed to sqlite3_wal_hook() when
7198 ** registering the callback. ^The second is a copy of the database handle.
7199
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.8.8"
111 #define SQLITE_VERSION_NUMBER 3008008
112 #define SQLITE_SOURCE_ID "2015-01-03 18:59:17 23d4c07eb81db5a5c6beb56b5820f0b6501f1fb6"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -199,11 +199,11 @@
199 ** This interface only reports on the compile-time mutex setting
200 ** of the [SQLITE_THREADSAFE] flag. If SQLite is compiled with
201 ** SQLITE_THREADSAFE=1 or =2 then mutexes are enabled by default but
202 ** can be fully or partially disabled using a call to [sqlite3_config()]
203 ** with the verbs [SQLITE_CONFIG_SINGLETHREAD], [SQLITE_CONFIG_MULTITHREAD],
204 ** or [SQLITE_CONFIG_SERIALIZED]. ^(The return value of the
205 ** sqlite3_threadsafe() function shows only the compile-time setting of
206 ** thread safety, not any run-time changes to that setting made by
207 ** sqlite3_config(). In other words, the return value from sqlite3_threadsafe()
208 ** is unchanged by calls to sqlite3_config().)^
209 **
@@ -1568,11 +1568,11 @@
1568 ** configuration option.
1569 ** ^There are three arguments to SQLITE_CONFIG_PAGECACHE: A pointer to
1570 ** 8-byte aligned
1571 ** memory, the size of each page buffer (sz), and the number of pages (N).
1572 ** The sz argument should be the size of the largest database page
1573 ** (a power of two between 512 and 65536) plus some extra bytes for each
1574 ** page header. ^The number of extra bytes needed by the page header
1575 ** can be determined using the [SQLITE_CONFIG_PCACHE_HDRSZ] option
1576 ** to [sqlite3_config()].
1577 ** ^It is harmless, apart from the wasted memory,
1578 ** for the sz parameter to be larger than necessary. The first
@@ -1748,10 +1748,21 @@
1748 ** <dd>^The SQLITE_CONFIG_PCACHE_HDRSZ option takes a single parameter which
1749 ** is a pointer to an integer and writes into that integer the number of extra
1750 ** bytes per page required for each page in [SQLITE_CONFIG_PAGECACHE].
1751 ** The amount of extra space required can change depending on the compiler,
1752 ** target platform, and SQLite version.
1753 **
1754 ** [[SQLITE_CONFIG_PMASZ]]
1755 ** <dt>SQLITE_CONFIG_PMASZ
1756 ** <dd>^The SQLITE_CONFIG_PMASZ option takes a single parameter which
1757 ** is an unsigned integer and sets the "Minimum PMA Size" for the multithreaded
1758 ** sorter to that integer. The default minimum PMA Size is set by the
1759 ** [SQLITE_SORTER_PMASZ] compile-time option. New threads are launched
1760 ** to help with sort operations when multithreaded sorting
1761 ** is enabled (using the [PRAGMA threads] command) and the amount of content
1762 ** to be sorted exceeds the page size times the minimum of the
1763 ** [PRAGMA cache_size] setting and this value.
1764 ** </dl>
1765 */
1766 #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
1767 #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
1768 #define SQLITE_CONFIG_SERIALIZED 3 /* nil */
@@ -1774,10 +1785,11 @@
1785 #define SQLITE_CONFIG_COVERING_INDEX_SCAN 20 /* int */
1786 #define SQLITE_CONFIG_SQLLOG 21 /* xSqllog, void* */
1787 #define SQLITE_CONFIG_MMAP_SIZE 22 /* sqlite3_int64, sqlite3_int64 */
1788 #define SQLITE_CONFIG_WIN32_HEAPSIZE 23 /* int nByte */
1789 #define SQLITE_CONFIG_PCACHE_HDRSZ 24 /* int *psz */
1790 #define SQLITE_CONFIG_PMASZ 25 /* unsigned int szPma */
1791
1792 /*
1793 ** CAPI3REF: Database Connection Configuration Options
1794 **
1795 ** These constants are the available integer configuration options that
@@ -7183,16 +7195,14 @@
7195
7196 /*
7197 ** CAPI3REF: Write-Ahead Log Commit Hook
7198 **
7199 ** ^The [sqlite3_wal_hook()] function is used to register a callback that
7200 ** is invoked each time data is committed to a database in wal mode.
 
 
7201 **
7202 ** ^(The callback is invoked by SQLite after the commit has taken place and
7203 ** the associated write-lock on the database released)^, so the implementation
7204 ** may read, write or [checkpoint] the database as required.
7205 **
7206 ** ^The first parameter passed to the callback function when it is invoked
7207 ** is a copy of the third parameter passed to sqlite3_wal_hook() when
7208 ** registering the callback. ^The second is a copy of the database handle.
7209

Keyboard Shortcuts

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