Fossil SCM

Update the built-in SQLite sources to the latest 3.7.16.1 beta for the purpose of testing SQLite.

drh 2013-03-27 20:53 trunk
Commit 2e9be37f502f5d973250ecc019104517613033ec
2 files changed +173 -168 +12 -8
+173 -168
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
11
/******************************************************************************
22
** This file is an amalgamation of many separate C source files from SQLite
3
-** version 3.7.16. By combining all the individual C code files into this
3
+** version 3.7.16.1. By combining all the individual C code files into this
44
** single large file, the entire code can be compiled as a single translation
55
** unit. This allows many compilers to do optimizations that would not be
66
** possible if the files were compiled separately. Performance improvements
77
** of 5% or more are commonly seen when SQLite is compiled as a single
88
** translation unit.
@@ -676,13 +676,13 @@
676676
**
677677
** See also: [sqlite3_libversion()],
678678
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
679679
** [sqlite_version()] and [sqlite_source_id()].
680680
*/
681
-#define SQLITE_VERSION "3.7.16"
681
+#define SQLITE_VERSION "3.7.16.1"
682682
#define SQLITE_VERSION_NUMBER 3007016
683
-#define SQLITE_SOURCE_ID "2013-03-13 00:13:25 839aa91faf1db7025d90fa3c65e50efb829b053b"
683
+#define SQLITE_SOURCE_ID "2013-03-27 20:41:15 274d2a22660c7b34b8bbd85f3c29cbafbcb1b4e7"
684684
685685
/*
686686
** CAPI3REF: Run-Time Library Version Numbers
687687
** KEYWORDS: sqlite3_version, sqlite3_sourceid
688688
**
@@ -3249,11 +3249,11 @@
32493249
** "private". ^Setting it to "shared" is equivalent to setting the
32503250
** SQLITE_OPEN_SHAREDCACHE bit in the flags argument passed to
32513251
** sqlite3_open_v2(). ^Setting the cache parameter to "private" is
32523252
** equivalent to setting the SQLITE_OPEN_PRIVATECACHE bit.
32533253
** ^If sqlite3_open_v2() is used and the "cache" parameter is present in
3254
-** a URI filename, its value overrides any behaviour requested by setting
3254
+** a URI filename, its value overrides any behavior requested by setting
32553255
** SQLITE_OPEN_PRIVATECACHE or SQLITE_OPEN_SHAREDCACHE flag.
32563256
** </ul>
32573257
**
32583258
** ^Specifying an unknown parameter in the query component of a URI is not an
32593259
** error. Future versions of SQLite might understand additional query
@@ -4567,11 +4567,12 @@
45674567
SQLITE_API SQLITE_DEPRECATED int sqlite3_aggregate_count(sqlite3_context*);
45684568
SQLITE_API SQLITE_DEPRECATED int sqlite3_expired(sqlite3_stmt*);
45694569
SQLITE_API SQLITE_DEPRECATED int sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*);
45704570
SQLITE_API SQLITE_DEPRECATED int sqlite3_global_recover(void);
45714571
SQLITE_API SQLITE_DEPRECATED void sqlite3_thread_cleanup(void);
4572
-SQLITE_API SQLITE_DEPRECATED int sqlite3_memory_alarm(void(*)(void*,sqlite3_int64,int),void*,sqlite3_int64);
4572
+SQLITE_API SQLITE_DEPRECATED int sqlite3_memory_alarm(void(*)(void*,sqlite3_int64,int),
4573
+ void*,sqlite3_int64);
45734574
#endif
45744575
45754576
/*
45764577
** CAPI3REF: Obtaining SQL Function Parameter Values
45774578
**
@@ -4647,18 +4648,21 @@
46474648
** an aggregate query, the xStep() callback of the aggregate function
46484649
** implementation is never called and xFinal() is called exactly once.
46494650
** In those cases, sqlite3_aggregate_context() might be called for the
46504651
** first time from within xFinal().)^
46514652
**
4652
-** ^The sqlite3_aggregate_context(C,N) routine returns a NULL pointer if N is
4653
-** less than or equal to zero or if a memory allocate error occurs.
4653
+** ^The sqlite3_aggregate_context(C,N) routine returns a NULL pointer
4654
+** when first called if N is less than or equal to zero or if a memory
4655
+** allocate error occurs.
46544656
**
46554657
** ^(The amount of space allocated by sqlite3_aggregate_context(C,N) is
46564658
** determined by the N parameter on first successful call. Changing the
46574659
** value of N in subsequent call to sqlite3_aggregate_context() within
46584660
** the same aggregate function instance will not resize the memory
4659
-** allocation.)^
4661
+** allocation.)^ Within the xFinal callback, it is customary to set
4662
+** N=0 in calls to sqlite3_aggregate_context(C,N) so that no
4663
+** pointless memory allocations occur.
46604664
**
46614665
** ^SQLite automatically frees the memory allocated by
46624666
** sqlite3_aggregate_context() when the aggregate query concludes.
46634667
**
46644668
** The first parameter must be a copy of the
@@ -6948,11 +6952,11 @@
69486952
** intact. If the requested page is not already in the cache, then the
69496953
** cache implementation should use the value of the createFlag
69506954
** parameter to help it determined what action to take:
69516955
**
69526956
** <table border=1 width=85% align=center>
6953
-** <tr><th> createFlag <th> Behaviour when page is not already in cache
6957
+** <tr><th> createFlag <th> Behavior when page is not already in cache
69546958
** <tr><td> 0 <td> Do not allocate a new page. Return NULL.
69556959
** <tr><td> 1 <td> Allocate a new page if it easy and convenient to do so.
69566960
** Otherwise return NULL.
69576961
** <tr><td> 2 <td> Make every effort to allocate a new page. Only return
69586962
** NULL if allocating a new page is effectively impossible.
@@ -7753,11 +7757,11 @@
77537757
** May you do good and not evil.
77547758
** May you find forgiveness for yourself and forgive others.
77557759
** May you share freely, never taking more than you give.
77567760
**
77577761
*************************************************************************
7758
-** This is the header file for the generic hash-table implemenation
7762
+** This is the header file for the generic hash-table implementation
77597763
** used in SQLite.
77607764
*/
77617765
#ifndef _SQLITE_HASH_H_
77627766
#define _SQLITE_HASH_H_
77637767
@@ -12943,13 +12947,10 @@
1294312947
"OMIT_LOOKASIDE",
1294412948
#endif
1294512949
#ifdef SQLITE_OMIT_MEMORYDB
1294612950
"OMIT_MEMORYDB",
1294712951
#endif
12948
-#ifdef SQLITE_OMIT_MERGE_SORT
12949
- "OMIT_MERGE_SORT",
12950
-#endif
1295112952
#ifdef SQLITE_OMIT_OR_OPTIMIZATION
1295212953
"OMIT_OR_OPTIMIZATION",
1295312954
#endif
1295412955
#ifdef SQLITE_OMIT_PAGER_PRAGMAS
1295512956
"OMIT_PAGER_PRAGMAS",
@@ -13534,27 +13535,17 @@
1353413535
SQLITE_PRIVATE void sqlite3VdbeFrameDelete(VdbeFrame*);
1353513536
SQLITE_PRIVATE int sqlite3VdbeFrameRestore(VdbeFrame *);
1353613537
SQLITE_PRIVATE void sqlite3VdbeMemStoreType(Mem *pMem);
1353713538
SQLITE_PRIVATE int sqlite3VdbeTransferError(Vdbe *p);
1353813539
13539
-#ifdef SQLITE_OMIT_MERGE_SORT
13540
-# define sqlite3VdbeSorterInit(Y,Z) SQLITE_OK
13541
-# define sqlite3VdbeSorterWrite(X,Y,Z) SQLITE_OK
13542
-# define sqlite3VdbeSorterClose(Y,Z)
13543
-# define sqlite3VdbeSorterRowkey(Y,Z) SQLITE_OK
13544
-# define sqlite3VdbeSorterRewind(X,Y,Z) SQLITE_OK
13545
-# define sqlite3VdbeSorterNext(X,Y,Z) SQLITE_OK
13546
-# define sqlite3VdbeSorterCompare(X,Y,Z) SQLITE_OK
13547
-#else
1354813540
SQLITE_PRIVATE int sqlite3VdbeSorterInit(sqlite3 *, VdbeCursor *);
1354913541
SQLITE_PRIVATE void sqlite3VdbeSorterClose(sqlite3 *, VdbeCursor *);
1355013542
SQLITE_PRIVATE int sqlite3VdbeSorterRowkey(const VdbeCursor *, Mem *);
1355113543
SQLITE_PRIVATE int sqlite3VdbeSorterNext(sqlite3 *, const VdbeCursor *, int *);
1355213544
SQLITE_PRIVATE int sqlite3VdbeSorterRewind(sqlite3 *, const VdbeCursor *, int *);
1355313545
SQLITE_PRIVATE int sqlite3VdbeSorterWrite(sqlite3 *, const VdbeCursor *, Mem *);
1355413546
SQLITE_PRIVATE int sqlite3VdbeSorterCompare(const VdbeCursor *, Mem *, int *);
13555
-#endif
1355613547
1355713548
#if !defined(SQLITE_OMIT_SHARED_CACHE) && SQLITE_THREADSAFE>0
1355813549
SQLITE_PRIVATE void sqlite3VdbeEnter(Vdbe*);
1355913550
SQLITE_PRIVATE void sqlite3VdbeLeave(Vdbe*);
1356013551
#else
@@ -21334,11 +21325,11 @@
2133421325
** returns FALSE but it still converts the prefix and writes the result
2133521326
** into *pResult.
2133621327
*/
2133721328
SQLITE_PRIVATE int sqlite3AtoF(const char *z, double *pResult, int length, u8 enc){
2133821329
#ifndef SQLITE_OMIT_FLOATING_POINT
21339
- int incr = (enc==SQLITE_UTF8?1:2);
21330
+ int incr;
2134021331
const char *zEnd = z + length;
2134121332
/* sign * significand * (10 ^ (esign * exponent)) */
2134221333
int sign = 1; /* sign of significand */
2134321334
i64 s = 0; /* significand */
2134421335
int d = 0; /* adjust exponent for shifting decimal point */
@@ -21345,14 +21336,26 @@
2134521336
int esign = 1; /* sign of exponent */
2134621337
int e = 0; /* exponent */
2134721338
int eValid = 1; /* True exponent is either not used or is well-formed */
2134821339
double result;
2134921340
int nDigits = 0;
21341
+ int nonNum = 0;
2135021342
21343
+ assert( enc==SQLITE_UTF8 || enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE );
2135121344
*pResult = 0.0; /* Default return value, in case of an error */
2135221345
21353
- if( enc==SQLITE_UTF16BE ) z++;
21346
+ if( enc==SQLITE_UTF8 ){
21347
+ incr = 1;
21348
+ }else{
21349
+ int i;
21350
+ incr = 2;
21351
+ assert( SQLITE_UTF16LE==2 && SQLITE_UTF16BE==3 );
21352
+ for(i=3-enc; i<length && z[i]==0; i+=2){}
21353
+ nonNum = i<length;
21354
+ zEnd = z+i+enc-3;
21355
+ z += (enc&1);
21356
+ }
2135421357
2135521358
/* skip leading spaces */
2135621359
while( z<zEnd && sqlite3Isspace(*z) ) z+=incr;
2135721360
if( z>=zEnd ) return 0;
2135821361
@@ -21481,11 +21484,11 @@
2148121484
2148221485
/* store the result */
2148321486
*pResult = result;
2148421487
2148521488
/* return true if number and no extra non-whitespace chracters after */
21486
- return z>=zEnd && nDigits>0 && eValid;
21489
+ return z>=zEnd && nDigits>0 && eValid && nonNum==0;
2148721490
#else
2148821491
return !sqlite3Atoi64(z, pResult, length, enc);
2148921492
#endif /* SQLITE_OMIT_FLOATING_POINT */
2149021493
}
2149121494
@@ -21530,25 +21533,37 @@
2153021533
** If zNum is exactly 9223372036854665808, return 2. This special
2153121534
** case is broken out because while 9223372036854665808 cannot be a
2153221535
** signed 64-bit integer, its negative -9223372036854665808 can be.
2153321536
**
2153421537
** If zNum is too big for a 64-bit integer and is not
21535
-** 9223372036854665808 then return 1.
21538
+** 9223372036854665808 or if zNum contains any non-numeric text,
21539
+** then return 1.
2153621540
**
2153721541
** length is the number of bytes in the string (bytes, not characters).
2153821542
** The string is not necessarily zero-terminated. The encoding is
2153921543
** given by enc.
2154021544
*/
2154121545
SQLITE_PRIVATE int sqlite3Atoi64(const char *zNum, i64 *pNum, int length, u8 enc){
21542
- int incr = (enc==SQLITE_UTF8?1:2);
21546
+ int incr;
2154321547
u64 u = 0;
2154421548
int neg = 0; /* assume positive */
2154521549
int i;
2154621550
int c = 0;
21551
+ int nonNum = 0;
2154721552
const char *zStart;
2154821553
const char *zEnd = zNum + length;
21549
- if( enc==SQLITE_UTF16BE ) zNum++;
21554
+ assert( enc==SQLITE_UTF8 || enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE );
21555
+ if( enc==SQLITE_UTF8 ){
21556
+ incr = 1;
21557
+ }else{
21558
+ incr = 2;
21559
+ assert( SQLITE_UTF16LE==2 && SQLITE_UTF16BE==3 );
21560
+ for(i=3-enc; i<length && zNum[i]==0; i+=2){}
21561
+ nonNum = i<length;
21562
+ zEnd = zNum+i+enc-3;
21563
+ zNum += (enc&1);
21564
+ }
2155021565
while( zNum<zEnd && sqlite3Isspace(*zNum) ) zNum+=incr;
2155121566
if( zNum<zEnd ){
2155221567
if( *zNum=='-' ){
2155321568
neg = 1;
2155421569
zNum+=incr;
@@ -21569,11 +21584,11 @@
2156921584
*pNum = (i64)u;
2157021585
}
2157121586
testcase( i==18 );
2157221587
testcase( i==19 );
2157321588
testcase( i==20 );
21574
- if( (c!=0 && &zNum[i]<zEnd) || (i==0 && zStart==zNum) || i>19*incr ){
21589
+ if( (c+nonNum!=0 && &zNum[i]<zEnd) || (i==0 && zStart==zNum) || i>19*incr ){
2157521590
/* zNum is empty or contains non-numeric text or is longer
2157621591
** than 19 digits (thus guaranteeing that it is too large) */
2157721592
return 1;
2157821593
}else if( i<19*incr ){
2157921594
/* Less than 19 digits, so we know that it fits in 64 bits */
@@ -23250,11 +23265,11 @@
2325023265
** they may be overridden at runtime to facilitate fault injection during
2325123266
** testing and sandboxing. The following array holds the names and pointers
2325223267
** to all overrideable system calls.
2325323268
*/
2325423269
static struct unix_syscall {
23255
- const char *zName; /* Name of the sytem call */
23270
+ const char *zName; /* Name of the system call */
2325623271
sqlite3_syscall_ptr pCurrent; /* Current value of the system call */
2325723272
sqlite3_syscall_ptr pDefault; /* Default value */
2325823273
} aSyscall[] = {
2325923274
{ "open", (sqlite3_syscall_ptr)posixOpen, 0 },
2326023275
#define osOpen ((int(*)(const char*,int,int))aSyscall[0].pCurrent)
@@ -24822,11 +24837,11 @@
2482224837
******************************************************************************/
2482324838
2482424839
/******************************************************************************
2482524840
************************* Begin dot-file Locking ******************************
2482624841
**
24827
-** The dotfile locking implementation uses the existance of separate lock
24842
+** The dotfile locking implementation uses the existence of separate lock
2482824843
** files (really a directory) to control access to the database. This works
2482924844
** on just about every filesystem imaginable. But there are serious downsides:
2483024845
**
2483124846
** (1) There is zero concurrency. A single reader blocks all other
2483224847
** connections from reading or writing the database.
@@ -24837,11 +24852,11 @@
2483724852
** Nevertheless, a dotlock is an appropriate locking mode for use if no
2483824853
** other locking strategy is available.
2483924854
**
2484024855
** Dotfile locking works by creating a subdirectory in the same directory as
2484124856
** the database and with the same name but with a ".lock" extension added.
24842
-** The existance of a lock directory implies an EXCLUSIVE lock. All other
24857
+** The existence of a lock directory implies an EXCLUSIVE lock. All other
2484324858
** lock types (SHARED, RESERVED, PENDING) are mapped into EXCLUSIVE.
2484424859
*/
2484524860
2484624861
/*
2484724862
** The file suffix added to the data base filename in order to create the
@@ -26326,11 +26341,11 @@
2632626341
pFile->lastErrno = errno;
2632726342
return unixLogError(SQLITE_IOERR_FSYNC, "full_fsync", pFile->zPath);
2632826343
}
2632926344
2633026345
/* Also fsync the directory containing the file if the DIRSYNC flag
26331
- ** is set. This is a one-time occurrance. Many systems (examples: AIX)
26346
+ ** is set. This is a one-time occurrence. Many systems (examples: AIX)
2633226347
** are unable to fsync a directory, so ignore errors on the fsync.
2633326348
*/
2633426349
if( pFile->ctrlFlags & UNIXFILE_DIRSYNC ){
2633526350
int dirfd;
2633626351
OSTRACE(("DIRSYNC %s (have_fullfsync=%d fullsync=%d)\n", pFile->zPath,
@@ -27700,11 +27715,11 @@
2770027715
#endif
2770127716
){
2770227717
unixEnterMutex();
2770327718
rc = findInodeInfo(pNew, &pNew->pInode);
2770427719
if( rc!=SQLITE_OK ){
27705
- /* If an error occured in findInodeInfo(), close the file descriptor
27720
+ /* If an error occurred in findInodeInfo(), close the file descriptor
2770627721
** immediately, before releasing the mutex. findInodeInfo() may fail
2770727722
** in two scenarios:
2770827723
**
2770927724
** (a) A call to fstat() failed.
2771027725
** (b) A malloc failed.
@@ -28338,11 +28353,11 @@
2833828353
#endif
2833928354
return rc;
2834028355
}
2834128356
2834228357
/*
28343
-** Test the existance of or access permissions of file zPath. The
28358
+** Test the existence of or access permissions of file zPath. The
2834428359
** test performed depends on the value of flags:
2834528360
**
2834628361
** SQLITE_ACCESS_EXISTS: Return 1 if the file exists
2834728362
** SQLITE_ACCESS_READWRITE: Return 1 if the file is read and writable.
2834828363
** SQLITE_ACCESS_READONLY: Return 1 if the file is readable.
@@ -30442,11 +30457,11 @@
3044230457
** they may be overridden at runtime to facilitate fault injection during
3044330458
** testing and sandboxing. The following array holds the names and pointers
3044430459
** to all overrideable system calls.
3044530460
*/
3044630461
static struct win_syscall {
30447
- const char *zName; /* Name of the sytem call */
30462
+ const char *zName; /* Name of the system call */
3044830463
sqlite3_syscall_ptr pCurrent; /* Current value of the system call */
3044930464
sqlite3_syscall_ptr pDefault; /* Default value */
3045030465
} aSyscall[] = {
3045130466
#if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT
3045230467
{ "AreFileApisANSI", (SYSCALL)AreFileApisANSI, 0 },
@@ -32159,11 +32174,11 @@
3215932174
3216032175
/* API oddity: If successful, SetFilePointer() returns a dword
3216132176
** containing the lower 32-bits of the new file-offset. Or, if it fails,
3216232177
** it returns INVALID_SET_FILE_POINTER. However according to MSDN,
3216332178
** INVALID_SET_FILE_POINTER may also be a valid new offset. So to determine
32164
- ** whether an error has actually occured, it is also necessary to call
32179
+ ** whether an error has actually occurred, it is also necessary to call
3216532180
** GetLastError().
3216632181
*/
3216732182
dwRet = osSetFilePointer(pFile->h, lowerBits, &upperBits, FILE_BEGIN);
3216832183
3216932184
if( (dwRet==INVALID_SET_FILE_POINTER
@@ -32305,11 +32320,11 @@
3230532320
sqlite3_file *id, /* File to write into */
3230632321
const void *pBuf, /* The bytes to be written */
3230732322
int amt, /* Number of bytes to write */
3230832323
sqlite3_int64 offset /* Offset into the file to begin writing at */
3230932324
){
32310
- int rc = 0; /* True if error has occured, else false */
32325
+ int rc = 0; /* True if error has occurred, else false */
3231132326
winFile *pFile = (winFile*)id; /* File handle */
3231232327
int nRetry = 0; /* Number of retries */
3231332328
3231432329
assert( amt>0 );
3231532330
assert( pFile );
@@ -34127,11 +34142,11 @@
3412734142
OSTRACE(("DELETE \"%s\" %s\n", zFilename, (rc ? "failed" : "ok" )));
3412834143
return rc;
3412934144
}
3413034145
3413134146
/*
34132
-** Check the existance and status of a file.
34147
+** Check the existence and status of a file.
3413334148
*/
3413434149
static int winAccess(
3413534150
sqlite3_vfs *pVfs, /* Not used on win32 */
3413634151
const char *zFilename, /* Name of file to check */
3413734152
int flags, /* Type of test to make on this file */
@@ -34736,11 +34751,11 @@
3473634751
3473734752
3473834753
/*
3473934754
** A bitmap is an instance of the following structure.
3474034755
**
34741
-** This bitmap records the existance of zero or more bits
34756
+** This bitmap records the existence of zero or more bits
3474234757
** with values between 1 and iSize, inclusive.
3474334758
**
3474434759
** There are three possible representations of the bitmap.
3474534760
** If iSize<=BITVEC_NBIT, then Bitvec.u.aBitmap[] is a straight
3474634761
** bitmap. The least significant bit is bit 1.
@@ -37638,11 +37653,11 @@
3763837653
** layer must either commit or rollback the transaction.
3763937654
**
3764037655
** * A write transaction is active.
3764137656
** * An EXCLUSIVE or greater lock is held on the database file.
3764237657
** * All writing and syncing of journal and database data has finished.
37643
-** If no error occured, all that remains is to finalize the journal to
37658
+** If no error occurred, all that remains is to finalize the journal to
3764437659
** commit the transaction. If an error did occur, the caller will need
3764537660
** to rollback the transaction.
3764637661
**
3764737662
** ERROR:
3764837663
**
@@ -37886,11 +37901,11 @@
3788637901
** journal file from being successfully finalized, the setMaster flag
3788737902
** is cleared anyway (and the pager will move to ERROR state).
3788837903
**
3788937904
** doNotSpill, doNotSyncSpill
3789037905
**
37891
-** These two boolean variables control the behaviour of cache-spills
37906
+** These two boolean variables control the behavior of cache-spills
3789237907
** (calls made by the pcache module to the pagerStress() routine to
3789337908
** write cached data to the file-system in order to free up memory).
3789437909
**
3789537910
** When doNotSpill is non-zero, writing to the database from pagerStress()
3789637911
** is disabled altogether. This is done in a very obscure case that
@@ -38764,11 +38779,11 @@
3876438779
put32bits(&zHeader[sizeof(aJournalMagic)], 0xffffffff);
3876538780
}else{
3876638781
memset(zHeader, 0, sizeof(aJournalMagic)+4);
3876738782
}
3876838783
38769
- /* The random check-hash initialiser */
38784
+ /* The random check-hash initializer */
3877038785
sqlite3_randomness(sizeof(pPager->cksumInit), &pPager->cksumInit);
3877138786
put32bits(&zHeader[sizeof(aJournalMagic)+4], pPager->cksumInit);
3877238787
/* The initial database size */
3877338788
put32bits(&zHeader[sizeof(aJournalMagic)+8], pPager->dbOrigSize);
3877438789
/* The assumed sector size for this process */
@@ -41096,11 +41111,11 @@
4109641111
**
4109741112
** If the condition asserted by this function were not true, and the
4109841113
** dirty page were to be discarded from the cache via the pagerStress()
4109941114
** routine, pagerStress() would not write the current page content to
4110041115
** the database file. If a savepoint transaction were rolled back after
41101
-** this happened, the correct behaviour would be to restore the current
41116
+** this happened, the correct behavior would be to restore the current
4110241117
** content of the page. However, since this content is not present in either
4110341118
** the database file or the portion of the rollback journal and
4110441119
** sub-journal rolled back the content could not be restored and the
4110541120
** database image would become corrupt. It is therefore fortunate that
4110641121
** this circumstance cannot arise.
@@ -48938,10 +48953,23 @@
4893848953
*/
4893948954
static void btreeClearHasContent(BtShared *pBt){
4894048955
sqlite3BitvecDestroy(pBt->pHasContent);
4894148956
pBt->pHasContent = 0;
4894248957
}
48958
+
48959
+/*
48960
+** Release all of the apPage[] pages for a cursor.
48961
+*/
48962
+static void btreeReleaseAllCursorPages(BtCursor *pCur){
48963
+ int i;
48964
+ for(i=0; i<=pCur->iPage; i++){
48965
+ releasePage(pCur->apPage[i]);
48966
+ pCur->apPage[i] = 0;
48967
+ }
48968
+ pCur->iPage = -1;
48969
+}
48970
+
4894348971
4894448972
/*
4894548973
** Save the current cursor position in the variables BtCursor.nKey
4894648974
** and BtCursor.pKey. The cursor's state is set to CURSOR_REQUIRESEEK.
4894748975
**
@@ -48978,16 +49006,11 @@
4897849006
}
4897949007
}
4898049008
assert( !pCur->apPage[0]->intKey || !pCur->pKey );
4898149009
4898249010
if( rc==SQLITE_OK ){
48983
- int i;
48984
- for(i=0; i<=pCur->iPage; i++){
48985
- releasePage(pCur->apPage[i]);
48986
- pCur->apPage[i] = 0;
48987
- }
48988
- pCur->iPage = -1;
49011
+ btreeReleaseAllCursorPages(pCur);
4898949012
pCur->eState = CURSOR_REQUIRESEEK;
4899049013
}
4899149014
4899249015
invalidateOverflowCache(pCur);
4899349016
return rc;
@@ -49001,15 +49024,19 @@
4900149024
static int saveAllCursors(BtShared *pBt, Pgno iRoot, BtCursor *pExcept){
4900249025
BtCursor *p;
4900349026
assert( sqlite3_mutex_held(pBt->mutex) );
4900449027
assert( pExcept==0 || pExcept->pBt==pBt );
4900549028
for(p=pBt->pCursor; p; p=p->pNext){
49006
- if( p!=pExcept && (0==iRoot || p->pgnoRoot==iRoot) &&
49007
- p->eState==CURSOR_VALID ){
49008
- int rc = saveCursorPosition(p);
49009
- if( SQLITE_OK!=rc ){
49010
- return rc;
49029
+ if( p!=pExcept && (0==iRoot || p->pgnoRoot==iRoot) ){
49030
+ if( p->eState==CURSOR_VALID ){
49031
+ int rc = saveCursorPosition(p);
49032
+ if( SQLITE_OK!=rc ){
49033
+ return rc;
49034
+ }
49035
+ }else{
49036
+ testcase( p->iPage>0 );
49037
+ btreeReleaseAllCursorPages(p);
4901149038
}
4901249039
}
4901349040
}
4901449041
return SQLITE_OK;
4901549042
}
@@ -50593,11 +50620,11 @@
5059350620
**
5059450621
** This is useful in one special case in the backup API code where it is
5059550622
** known that the shared b-tree mutex is held, but the mutex on the
5059650623
** database handle that owns *p is not. In this case if sqlite3BtreeEnter()
5059750624
** were to be called, it might collide with some other operation on the
50598
-** database handle that owns *p, causing undefined behaviour.
50625
+** database handle that owns *p, causing undefined behavior.
5059950626
*/
5060050627
SQLITE_PRIVATE int sqlite3BtreeGetReserveNoMutex(Btree *p){
5060150628
assert( sqlite3_mutex_held(p->pBt->mutex) );
5060250629
return p->pBt->pageSize - p->pBt->usableSize;
5060350630
}
@@ -53873,11 +53900,11 @@
5387353900
** for that page now.
5387453901
**
5387553902
** If this is the first overflow page, then write a partial entry
5387653903
** to the pointer-map. If we write nothing to this pointer-map slot,
5387753904
** then the optimistic overflow chain processing in clearCell()
53878
- ** may misinterpret the uninitialised values and delete the
53905
+ ** may misinterpret the uninitialized values and delete the
5387953906
** wrong pages from the database.
5388053907
*/
5388153908
if( pBt->autoVacuum && rc==SQLITE_OK ){
5388253909
u8 eType = (pgnoPtrmap?PTRMAP_OVERFLOW2:PTRMAP_OVERFLOW1);
5388353910
ptrmapPut(pBt, pgnoOvfl, eType, pgnoPtrmap, &rc);
@@ -55346,11 +55373,11 @@
5534655373
assert( pPage->leaf );
5534755374
}
5534855375
insertCell(pPage, idx, newCell, szNew, 0, 0, &rc);
5534955376
assert( rc!=SQLITE_OK || pPage->nCell>0 || pPage->nOverflow>0 );
5535055377
55351
- /* If no error has occured and pPage has an overflow cell, call balance()
55378
+ /* If no error has occurred and pPage has an overflow cell, call balance()
5535255379
** to redistribute the cells within the tree. Since balance() may move
5535355380
** the cursor, zero the BtCursor.info.nSize and BtCursor.validNKey
5535455381
** variables.
5535555382
**
5535655383
** Previous versions of SQLite called moveToRoot() to move the cursor
@@ -59080,11 +59107,11 @@
5908059107
break;
5908159108
}
5908259109
}
5908359110
sqlite3DbFree(v->db, sIter.apSub);
5908459111
59085
- /* Return true if hasAbort==mayAbort. Or if a malloc failure occured.
59112
+ /* Return true if hasAbort==mayAbort. Or if a malloc failure occurred.
5908659113
** If malloc failed, then the while() loop above may not have iterated
5908759114
** through all opcodes and hasAbort may be set incorrectly. Return
5908859115
** true for this case to prevent the assert() in the callers frame
5908959116
** from failing. */
5909059117
return ( v->db->mallocFailed || hasAbort==mayAbort );
@@ -60712,11 +60739,11 @@
6071260739
sqlite3 *const db = p->db;
6071360740
int rc = SQLITE_OK;
6071460741
6071560742
/* If p->iStatement is greater than zero, then this Vdbe opened a
6071660743
** statement transaction that should be closed here. The only exception
60717
- ** is that an IO error may have occured, causing an emergency rollback.
60744
+ ** is that an IO error may have occurred, causing an emergency rollback.
6071860745
** In this case (db->nStatement==0), and there is nothing to do.
6071960746
*/
6072060747
if( db->nStatement && p->iStatement ){
6072160748
int i;
6072260749
const int iSavepoint = p->iStatement-1;
@@ -60848,11 +60875,11 @@
6084860875
** transaction must be rolled back to restore the database to a
6084960876
** consistent state.
6085060877
**
6085160878
** Even if the statement is read-only, it is important to perform
6085260879
** a statement or transaction rollback operation. If the error
60853
- ** occured while writing to the journal, sub-journal or database
60880
+ ** occurred while writing to the journal, sub-journal or database
6085460881
** file as part of an effort to free up cache space (see function
6085560882
** pagerStress() in pager.c), the rollback is required to restore
6085660883
** the pager to a consistent state.
6085760884
*/
6085860885
if( !p->readOnly || mrc!=SQLITE_INTERRUPT ){
@@ -61262,11 +61289,11 @@
6126261289
**
6126361290
** In an SQLite index record, the serial type is stored directly before
6126461291
** the blob of data that it corresponds to. In a table record, all serial
6126561292
** types are stored at the start of the record, and the blobs of data at
6126661293
** the end. Hence these functions allow the caller to handle the
61267
-** serial-type and data blob seperately.
61294
+** serial-type and data blob separately.
6126861295
**
6126961296
** The following table describes the various storage classes for data:
6127061297
**
6127161298
** serial type bytes of data type
6127261299
** -------------- --------------- ---------------
@@ -62402,11 +62429,11 @@
6240262429
|| rc==SQLITE_BUSY || rc==SQLITE_MISUSE
6240362430
);
6240462431
assert( p->rc!=SQLITE_ROW && p->rc!=SQLITE_DONE );
6240562432
if( p->isPrepareV2 && rc!=SQLITE_ROW && rc!=SQLITE_DONE ){
6240662433
/* If this statement was prepared using sqlite3_prepare_v2(), and an
62407
- ** error has occured, then return the error code in p->rc to the
62434
+ ** error has occurred, then return the error code in p->rc to the
6240862435
** caller. Set the error code in the database handle to the same value.
6240962436
*/
6241062437
rc = sqlite3VdbeTransferError(p);
6241162438
}
6241262439
return (rc&db->errMask);
@@ -63692,15 +63719,11 @@
6369263719
#define Deephemeralize(P) \
6369363720
if( ((P)->flags&MEM_Ephem)!=0 \
6369463721
&& sqlite3VdbeMemMakeWriteable(P) ){ goto no_mem;}
6369563722
6369663723
/* Return true if the cursor was opened using the OP_OpenSorter opcode. */
63697
-#ifdef SQLITE_OMIT_MERGE_SORT
63698
-# define isSorter(x) 0
63699
-#else
6370063724
# define isSorter(x) ((x)->pSorter!=0)
63701
-#endif
6370263725
6370363726
/*
6370463727
** Argument pMem points at a register that will be passed to a
6370563728
** user-defined function or returned to the user as the result of a query.
6370663729
** This routine sets the pMem->type variable used by the sqlite3_value_*()
@@ -67433,21 +67456,16 @@
6743367456
case OP_SorterOpen: {
6743467457
#if 0 /* local variables moved into u.ba */
6743567458
VdbeCursor *pCx;
6743667459
#endif /* local variables moved into u.ba */
6743767460
67438
-#ifndef SQLITE_OMIT_MERGE_SORT
6743967461
u.ba.pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1);
6744067462
if( u.ba.pCx==0 ) goto no_mem;
6744167463
u.ba.pCx->pKeyInfo = pOp->p4.pKeyInfo;
6744267464
u.ba.pCx->pKeyInfo->enc = ENC(p->db);
6744367465
u.ba.pCx->isSorter = 1;
6744467466
rc = sqlite3VdbeSorterInit(db, u.ba.pCx);
67445
-#else
67446
- pOp->opcode = OP_OpenEphemeral;
67447
- pc--;
67448
-#endif
6744967467
break;
6745067468
}
6745167469
6745267470
/* Opcode: OpenPseudo P1 P2 P3 * P5
6745367471
**
@@ -68348,19 +68366,14 @@
6834868366
case OP_SorterData: {
6834968367
#if 0 /* local variables moved into u.bl */
6835068368
VdbeCursor *pC;
6835168369
#endif /* local variables moved into u.bl */
6835268370
68353
-#ifndef SQLITE_OMIT_MERGE_SORT
6835468371
pOut = &aMem[pOp->p2];
6835568372
u.bl.pC = p->apCsr[pOp->p1];
6835668373
assert( u.bl.pC->isSorter );
6835768374
rc = sqlite3VdbeSorterRowkey(u.bl.pC, pOut);
68358
-#else
68359
- pOp->opcode = OP_RowKey;
68360
- pc--;
68361
-#endif
6836268375
break;
6836368376
}
6836468377
6836568378
/* Opcode: RowData P1 P2 * * *
6836668379
**
@@ -68563,13 +68576,10 @@
6856368576
** rewinding so that the global variable will be incremented and
6856468577
** regression tests can determine whether or not the optimizer is
6856568578
** correctly optimizing out sorts.
6856668579
*/
6856768580
case OP_SorterSort: /* jump */
68568
-#ifdef SQLITE_OMIT_MERGE_SORT
68569
- pOp->opcode = OP_Sort;
68570
-#endif
6857168581
case OP_Sort: { /* jump */
6857268582
#ifdef SQLITE_TEST
6857368583
sqlite3_sort_count++;
6857468584
sqlite3_search_count--;
6857568585
#endif
@@ -68646,13 +68656,10 @@
6864668656
**
6864768657
** If P5 is positive and the jump is taken, then event counter
6864868658
** number P5-1 in the prepared statement is incremented.
6864968659
*/
6865068660
case OP_SorterNext: /* jump */
68651
-#ifdef SQLITE_OMIT_MERGE_SORT
68652
- pOp->opcode = OP_Next;
68653
-#endif
6865468661
case OP_Prev: /* jump */
6865568662
case OP_Next: { /* jump */
6865668663
#if 0 /* local variables moved into u.br */
6865768664
VdbeCursor *pC;
6865868665
int res;
@@ -68701,13 +68708,10 @@
6870168708
**
6870268709
** This instruction only works for indices. The equivalent instruction
6870368710
** for tables is OP_Insert.
6870468711
*/
6870568712
case OP_SorterInsert: /* in2 */
68706
-#ifdef SQLITE_OMIT_MERGE_SORT
68707
- pOp->opcode = OP_IdxInsert;
68708
-#endif
6870968713
case OP_IdxInsert: { /* in2 */
6871068714
#if 0 /* local variables moved into u.bs */
6871168715
VdbeCursor *pC;
6871268716
BtCursor *pCrsr;
6871368717
int nKey;
@@ -69972,11 +69976,11 @@
6997269976
importVtabErrMsg(p, u.cm.pVtab);
6997369977
if( SQLITE_OK==rc ){
6997469978
/* Initialize sqlite3_vtab_cursor base class */
6997569979
u.cm.pVtabCursor->pVtab = u.cm.pVtab;
6997669980
69977
- /* Initialise vdbe cursor object */
69981
+ /* Initialize vdbe cursor object */
6997869982
u.cm.pCur = allocateCursor(p, pOp->p1, 0, -1, 0);
6997969983
if( u.cm.pCur ){
6998069984
u.cm.pCur->pVtabCursor = u.cm.pVtabCursor;
6998169985
u.cm.pCur->pModule = u.cm.pVtabCursor->pVtab->pModule;
6998269986
}else{
@@ -70954,11 +70958,10 @@
7095470958
** example, by CREATE INDEX statements on tables too large to fit in main
7095570959
** memory).
7095670960
*/
7095770961
7095870962
70959
-#ifndef SQLITE_OMIT_MERGE_SORT
7096070963
7096170964
typedef struct VdbeSorterIter VdbeSorterIter;
7096270965
typedef struct SorterRecord SorterRecord;
7096370966
typedef struct FileWriter FileWriter;
7096470967
@@ -71974,12 +71977,10 @@
7197471977
pKey = vdbeSorterRowkey(pSorter, &nKey);
7197571978
vdbeSorterCompare(pCsr, 1, pVal->z, pVal->n, pKey, nKey, pRes);
7197671979
return SQLITE_OK;
7197771980
}
7197871981
71979
-#endif /* #ifndef SQLITE_OMIT_MERGE_SORT */
71980
-
7198171982
/************** End of vdbesort.c ********************************************/
7198271983
/************** Begin file journal.c *****************************************/
7198371984
/*
7198471985
** 2007 August 22
7198571986
**
@@ -77513,11 +77514,11 @@
7751377514
int regFree1 = 0;
7751477515
int regFree2 = 0;
7751577516
int r1, r2;
7751677517
7751777518
assert( jumpIfNull==SQLITE_JUMPIFNULL || jumpIfNull==0 );
77518
- if( NEVER(v==0) ) return; /* Existance of VDBE checked by caller */
77519
+ if( NEVER(v==0) ) return; /* Existence of VDBE checked by caller */
7751977520
if( NEVER(pExpr==0) ) return; /* No way this can happen */
7752077521
op = pExpr->op;
7752177522
switch( op ){
7752277523
case TK_AND: {
7752377524
int d2 = sqlite3VdbeMakeLabel(v);
@@ -77633,11 +77634,11 @@
7763377634
int regFree1 = 0;
7763477635
int regFree2 = 0;
7763577636
int r1, r2;
7763677637
7763777638
assert( jumpIfNull==SQLITE_JUMPIFNULL || jumpIfNull==0 );
77638
- if( NEVER(v==0) ) return; /* Existance of VDBE checked by caller */
77639
+ if( NEVER(v==0) ) return; /* Existence of VDBE checked by caller */
7763977640
if( pExpr==0 ) return;
7764077641
7764177642
/* The value of pExpr->op and op are related as follows:
7764277643
**
7764377644
** pExpr->op op
@@ -80230,11 +80231,11 @@
8023080231
zErrDyn = sqlite3MPrintf(db, "database %s is already in use", zName);
8023180232
goto attach_error;
8023280233
}
8023380234
}
8023480235
80235
- /* Allocate the new entry in the db->aDb[] array and initialise the schema
80236
+ /* Allocate the new entry in the db->aDb[] array and initialize the schema
8023680237
** hash tables.
8023780238
*/
8023880239
if( db->aDb==db->aDbStatic ){
8023980240
aNew = sqlite3DbMallocRaw(db, sizeof(db->aDb[0])*3 );
8024080241
if( aNew==0 ) return;
@@ -80247,11 +80248,11 @@
8024780248
aNew = &db->aDb[db->nDb];
8024880249
memset(aNew, 0, sizeof(*aNew));
8024980250
8025080251
/* Open the database file. If the btree is successfully opened, use
8025180252
** it to obtain the database schema. At this point the schema may
80252
- ** or may not be initialised.
80253
+ ** or may not be initialized.
8025380254
*/
8025480255
flags = db->openFlags;
8025580256
rc = sqlite3ParseUri(db->pVfs->zName, zFile, &flags, &pVfs, &zPath, &zErr);
8025680257
if( rc!=SQLITE_OK ){
8025780258
if( rc==SQLITE_NOMEM ) db->mallocFailed = 1;
@@ -83033,11 +83034,11 @@
8303383034
#endif
8303483035
8303583036
/* Drop all SQLITE_MASTER table and index entries that refer to the
8303683037
** table. The program name loops through the master table and deletes
8303783038
** every row that refers to a table of the same name as the one being
83038
- ** dropped. Triggers are handled seperately because a trigger can be
83039
+ ** dropped. Triggers are handled separately because a trigger can be
8303983040
** created in the temp database that refers to a table in another
8304083041
** database.
8304183042
*/
8304283043
sqlite3NestedParse(pParse,
8304383044
"DELETE FROM %Q.%s WHERE tbl_name=%Q and type!='trigger'",
@@ -83325,13 +83326,10 @@
8332583326
int addr1; /* Address of top of loop */
8332683327
int addr2; /* Address to jump to for next iteration */
8332783328
int tnum; /* Root page of index */
8332883329
Vdbe *v; /* Generate code into this virtual machine */
8332983330
KeyInfo *pKey; /* KeyInfo for index */
83330
-#ifdef SQLITE_OMIT_MERGE_SORT
83331
- int regIdxKey; /* Registers containing the index key */
83332
-#endif
8333383331
int regRecord; /* Register holding assemblied index record */
8333483332
sqlite3 *db = pParse->db; /* The database connection */
8333583333
int iDb = sqlite3SchemaToIndex(db, pIndex->pSchema);
8333683334
8333783335
#ifndef SQLITE_OMIT_AUTHORIZATION
@@ -83355,25 +83353,20 @@
8335583353
pKey = sqlite3IndexKeyinfo(pParse, pIndex);
8335683354
sqlite3VdbeAddOp4(v, OP_OpenWrite, iIdx, tnum, iDb,
8335783355
(char *)pKey, P4_KEYINFO_HANDOFF);
8335883356
sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR|((memRootPage>=0)?OPFLAG_P2ISREG:0));
8335983357
83360
-#ifndef SQLITE_OMIT_MERGE_SORT
8336183358
/* Open the sorter cursor if we are to use one. */
8336283359
iSorter = pParse->nTab++;
8336383360
sqlite3VdbeAddOp4(v, OP_SorterOpen, iSorter, 0, 0, (char*)pKey, P4_KEYINFO);
83364
-#else
83365
- iSorter = iTab;
83366
-#endif
8336783361
8336883362
/* Open the table. Loop through all rows of the table, inserting index
8336983363
** records into the sorter. */
8337083364
sqlite3OpenTable(pParse, iTab, iDb, pTab, OP_OpenRead);
8337183365
addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iTab, 0);
8337283366
regRecord = sqlite3GetTempReg(pParse);
8337383367
83374
-#ifndef SQLITE_OMIT_MERGE_SORT
8337583368
sqlite3GenerateIndexKey(pParse, pIndex, iTab, regRecord, 1);
8337683369
sqlite3VdbeAddOp2(v, OP_SorterInsert, iSorter, regRecord);
8337783370
sqlite3VdbeAddOp2(v, OP_Next, iTab, addr1+1);
8337883371
sqlite3VdbeJumpHere(v, addr1);
8337983372
addr1 = sqlite3VdbeAddOp2(v, OP_SorterSort, iSorter, 0);
@@ -83389,34 +83382,10 @@
8338983382
addr2 = sqlite3VdbeCurrentAddr(v);
8339083383
}
8339183384
sqlite3VdbeAddOp2(v, OP_SorterData, iSorter, regRecord);
8339283385
sqlite3VdbeAddOp3(v, OP_IdxInsert, iIdx, regRecord, 1);
8339383386
sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
83394
-#else
83395
- regIdxKey = sqlite3GenerateIndexKey(pParse, pIndex, iTab, regRecord, 1);
83396
- addr2 = addr1 + 1;
83397
- if( pIndex->onError!=OE_None ){
83398
- const int regRowid = regIdxKey + pIndex->nColumn;
83399
- const int j2 = sqlite3VdbeCurrentAddr(v) + 2;
83400
- void * const pRegKey = SQLITE_INT_TO_PTR(regIdxKey);
83401
-
83402
- /* The registers accessed by the OP_IsUnique opcode were allocated
83403
- ** using sqlite3GetTempRange() inside of the sqlite3GenerateIndexKey()
83404
- ** call above. Just before that function was freed they were released
83405
- ** (made available to the compiler for reuse) using
83406
- ** sqlite3ReleaseTempRange(). So in some ways having the OP_IsUnique
83407
- ** opcode use the values stored within seems dangerous. However, since
83408
- ** we can be sure that no other temp registers have been allocated
83409
- ** since sqlite3ReleaseTempRange() was called, it is safe to do so.
83410
- */
83411
- sqlite3VdbeAddOp4(v, OP_IsUnique, iIdx, j2, regRowid, pRegKey, P4_INT32);
83412
- sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_UNIQUE,
83413
- "indexed columns are not unique", P4_STATIC);
83414
- }
83415
- sqlite3VdbeAddOp3(v, OP_IdxInsert, iIdx, regRecord, 0);
83416
- sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
83417
-#endif
8341883387
sqlite3ReleaseTempReg(pParse, regRecord);
8341983388
sqlite3VdbeAddOp2(v, OP_SorterNext, iSorter, addr2);
8342083389
sqlite3VdbeJumpHere(v, addr1);
8342183390
8342283391
sqlite3VdbeAddOp1(v, OP_Close, iTab);
@@ -83772,11 +83741,11 @@
8377283741
/* This constraint creates the same index as a previous
8377383742
** constraint specified somewhere in the CREATE TABLE statement.
8377483743
** However the ON CONFLICT clauses are different. If both this
8377583744
** constraint and the previous equivalent constraint have explicit
8377683745
** ON CONFLICT clauses this is an error. Otherwise, use the
83777
- ** explicitly specified behaviour for the index.
83746
+ ** explicitly specified behavior for the index.
8377883747
*/
8377983748
if( !(pIdx->onError==OE_Default || pIndex->onError==OE_Default) ){
8378083749
sqlite3ErrorMsg(pParse,
8378183750
"conflicting ON CONFLICT clauses specified", 0);
8378283751
}
@@ -94054,11 +94023,11 @@
9405494023
assert( sqlite3_mutex_held(db->mutex) );
9405594024
assert( iDb==1 || sqlite3BtreeHoldsMutex(db->aDb[iDb].pBt) );
9405694025
9405794026
/* zMasterSchema and zInitScript are set to point at the master schema
9405894027
** and initialisation script appropriate for the database being
94059
- ** initialised. zMasterName is the name of the master table.
94028
+ ** initialized. zMasterName is the name of the master table.
9406094029
*/
9406194030
if( !OMIT_TEMPDB && iDb==1 ){
9406294031
zMasterSchema = temp_master_schema;
9406394032
}else{
9406494033
zMasterSchema = master_schema;
@@ -94279,11 +94248,11 @@
9427994248
if( rc ){
9428094249
sqlite3ResetOneSchema(db, i);
9428194250
}
9428294251
}
9428394252
94284
- /* Once all the other databases have been initialised, load the schema
94253
+ /* Once all the other databases have been initialized, load the schema
9428594254
** for the TEMP database. This is loaded last, as the TEMP database
9428694255
** schema may contain references to objects in other databases.
9428794256
*/
9428894257
#ifndef SQLITE_OMIT_TEMPDB
9428994258
if( rc==SQLITE_OK && ALWAYS(db->nDb>1)
@@ -94302,11 +94271,11 @@
9430294271
9430394272
return rc;
9430494273
}
9430594274
9430694275
/*
94307
-** This routine is a no-op if the database schema is already initialised.
94276
+** This routine is a no-op if the database schema is already initialized.
9430894277
** Otherwise, the schema is loaded. An error code is returned.
9430994278
*/
9431094279
SQLITE_PRIVATE int sqlite3ReadSchema(Parse *pParse){
9431194280
int rc = SQLITE_OK;
9431294281
sqlite3 *db = pParse->db;
@@ -99315,11 +99284,11 @@
9931599284
** first iteration (since the first iteration of the loop is
9931699285
** guaranteed to operate on the row with the minimum or maximum
9931799286
** value of x, the only row required).
9931899287
**
9931999288
** A special flag must be passed to sqlite3WhereBegin() to slightly
99320
- ** modify behaviour as follows:
99289
+ ** modify behavior as follows:
9932199290
**
9932299291
** + If the query is a "SELECT min(x)", then the loop coded by
9932399292
** where.c should not iterate over any values with a NULL value
9932499293
** for x.
9932599294
**
@@ -101308,11 +101277,11 @@
101308101277
sqlite3CodeRowTrigger(pParse, pTrigger, TK_UPDATE, pChanges,
101309101278
TRIGGER_BEFORE, pTab, regOldRowid, onError, addr);
101310101279
101311101280
/* The row-trigger may have deleted the row being updated. In this
101312101281
** case, jump to the next row. No updates or AFTER triggers are
101313
- ** required. This behaviour - what happens when the row being updated
101282
+ ** required. This behavior - what happens when the row being updated
101314101283
** is deleted or renamed by a BEFORE trigger - is left undefined in the
101315101284
** documentation.
101316101285
*/
101317101286
sqlite3VdbeAddOp3(v, OP_NotExists, iCur, addr, regOldRowid);
101318101287
@@ -103237,10 +103206,12 @@
103237103206
#define WHERE_IDX_ONLY 0x00400000 /* Use index only - omit table */
103238103207
#define WHERE_ORDERED 0x00800000 /* Output will appear in correct order */
103239103208
#define WHERE_REVERSE 0x01000000 /* Scan in reverse order */
103240103209
#define WHERE_UNIQUE 0x02000000 /* Selects no more than one row */
103241103210
#define WHERE_ALL_UNIQUE 0x04000000 /* This and all prior have one row */
103211
+#define WHERE_OB_UNIQUE 0x00004000 /* Values in ORDER BY columns are
103212
+ ** different for every output row */
103242103213
#define WHERE_VIRTUALTABLE 0x08000000 /* Use virtual-table processing */
103243103214
#define WHERE_MULTI_OR 0x10000000 /* OR using multiple indices */
103244103215
#define WHERE_TEMP_INDEX 0x20000000 /* Uses an ephemeral index */
103245103216
#define WHERE_DISTINCT 0x40000000 /* Correct order for DISTINCT */
103246103217
#define WHERE_COVER_SCAN 0x80000000 /* Full scan of a covering index */
@@ -103537,11 +103508,11 @@
103537103508
103538103509
/*
103539103510
** Commute a comparison operator. Expressions of the form "X op Y"
103540103511
** are converted into "Y op X".
103541103512
**
103542
-** If left/right precendence rules come into play when determining the
103513
+** If left/right precedence rules come into play when determining the
103543103514
** collating
103544103515
** side of the comparison, it remains associated with the same side after
103545103516
** the commutation. So "Y collate NOCASE op X" becomes
103546103517
** "X op Y". This is because any collation sequence on
103547103518
** the left hand side of a comparison overrides any collation sequence
@@ -105878,11 +105849,12 @@
105878105849
*/
105879105850
static int isSortingIndex(
105880105851
WhereBestIdx *p, /* Best index search context */
105881105852
Index *pIdx, /* The index we are testing */
105882105853
int base, /* Cursor number for the table to be sorted */
105883
- int *pbRev /* Set to 1 for reverse-order scan of pIdx */
105854
+ int *pbRev, /* Set to 1 for reverse-order scan of pIdx */
105855
+ int *pbObUnique /* ORDER BY column values will different in every row */
105884105856
){
105885105857
int i; /* Number of pIdx terms used */
105886105858
int j; /* Number of ORDER BY terms satisfied */
105887105859
int sortOrder = 2; /* 0: forward. 1: backward. 2: unknown */
105888105860
int nTerm; /* Number of ORDER BY terms */
@@ -105892,25 +105864,32 @@
105892105864
Parse *pParse = p->pParse; /* Parser context */
105893105865
sqlite3 *db = pParse->db; /* Database connection */
105894105866
int nPriorSat; /* ORDER BY terms satisfied by outer loops */
105895105867
int seenRowid = 0; /* True if an ORDER BY rowid term is seen */
105896105868
int uniqueNotNull; /* pIdx is UNIQUE with all terms are NOT NULL */
105869
+ int outerObUnique; /* Outer loops generate different values in
105870
+ ** every row for the ORDER BY columns */
105897105871
105898105872
if( p->i==0 ){
105899105873
nPriorSat = 0;
105874
+ outerObUnique = 1;
105900105875
}else{
105876
+ u32 wsFlags = p->aLevel[p->i-1].plan.wsFlags;
105901105877
nPriorSat = p->aLevel[p->i-1].plan.nOBSat;
105902
- if( (p->aLevel[p->i-1].plan.wsFlags & WHERE_ORDERED)==0 ){
105878
+ if( (wsFlags & WHERE_ORDERED)==0 ){
105903105879
/* This loop cannot be ordered unless the next outer loop is
105904105880
** also ordered */
105905105881
return nPriorSat;
105906105882
}
105907105883
if( OptimizationDisabled(db, SQLITE_OrderByIdxJoin) ){
105908105884
/* Only look at the outer-most loop if the OrderByIdxJoin
105909105885
** optimization is disabled */
105910105886
return nPriorSat;
105911105887
}
105888
+ testcase( wsFlags & WHERE_OB_UNIQUE );
105889
+ testcase( wsFlags & WHERE_ALL_UNIQUE );
105890
+ outerObUnique = (wsFlags & (WHERE_OB_UNIQUE|WHERE_ALL_UNIQUE))!=0;
105912105891
}
105913105892
pOrderBy = p->pOrderBy;
105914105893
assert( pOrderBy!=0 );
105915105894
if( pIdx->bUnordered ){
105916105895
/* Hash indices (indicated by the "unordered" tag on sqlite_stat1) cannot
@@ -106048,23 +106027,38 @@
106048106027
testcase( isEq==2 );
106049106028
testcase( isEq==3 );
106050106029
uniqueNotNull = 0;
106051106030
}
106052106031
}
106032
+ if( seenRowid ){
106033
+ uniqueNotNull = 1;
106034
+ }else if( uniqueNotNull==0 || i<pIdx->nColumn ){
106035
+ uniqueNotNull = 0;
106036
+ }
106053106037
106054106038
/* If we have not found at least one ORDER BY term that matches the
106055106039
** index, then show no progress. */
106056106040
if( pOBItem==&pOrderBy->a[nPriorSat] ) return nPriorSat;
106041
+
106042
+ /* Either the outer queries must generate rows where there are no two
106043
+ ** rows with the same values in all ORDER BY columns, or else this
106044
+ ** loop must generate just a single row of output. Example: Suppose
106045
+ ** the outer loops generate A=1 and A=1, and this loop generates B=3
106046
+ ** and B=4. Then without the following test, ORDER BY A,B would
106047
+ ** generate the wrong order output: 1,3 1,4 1,3 1,4
106048
+ */
106049
+ if( outerObUnique==0 && uniqueNotNull==0 ) return nPriorSat;
106050
+ *pbObUnique = uniqueNotNull;
106057106051
106058106052
/* Return the necessary scan order back to the caller */
106059106053
*pbRev = sortOrder & 1;
106060106054
106061106055
/* If there was an "ORDER BY rowid" term that matched, or it is only
106062106056
** possible for a single row from this table to match, then skip over
106063106057
** any additional ORDER BY terms dealing with this table.
106064106058
*/
106065
- if( seenRowid || (uniqueNotNull && i>=pIdx->nColumn) ){
106059
+ if( uniqueNotNull ){
106066106060
/* Advance j over additional ORDER BY terms associated with base */
106067106061
WhereMaskSet *pMS = p->pWC->pMaskSet;
106068106062
Bitmask m = ~getMask(pMS, base);
106069106063
while( j<nTerm && (exprTableUsage(pMS, pOrderBy->a[j].pExpr)&m)==0 ){
106070106064
j++;
@@ -106344,16 +106338,18 @@
106344106338
** in pc.plan.wsFlags. Otherwise, if there is an ORDER BY clause but
106345106339
** the index will scan rows in a different order, set the bSort
106346106340
** variable. */
106347106341
if( bSort && (pSrc->jointype & JT_LEFT)==0 ){
106348106342
int bRev = 2;
106349
- WHERETRACE((" --> before isSortingIndex: nPriorSat=%d\n",nPriorSat));
106350
- pc.plan.nOBSat = isSortingIndex(p, pProbe, iCur, &bRev);
106351
- WHERETRACE((" --> after isSortingIndex: bRev=%d nOBSat=%d\n",
106352
- bRev, pc.plan.nOBSat));
106343
+ int bObUnique = 0;
106344
+ WHERETRACE((" --> before isSortIndex: nPriorSat=%d\n",nPriorSat));
106345
+ pc.plan.nOBSat = isSortingIndex(p, pProbe, iCur, &bRev, &bObUnique);
106346
+ WHERETRACE((" --> after isSortIndex: bRev=%d bObU=%d nOBSat=%d\n",
106347
+ bRev, bObUnique, pc.plan.nOBSat));
106353106348
if( nPriorSat<pc.plan.nOBSat || (pc.plan.wsFlags & WHERE_ALL_UNIQUE)!=0 ){
106354106349
pc.plan.wsFlags |= WHERE_ORDERED;
106350
+ if( bObUnique ) pc.plan.wsFlags |= WHERE_OB_UNIQUE;
106355106351
}
106356106352
if( nOrderBy==pc.plan.nOBSat ){
106357106353
bSort = 0;
106358106354
pc.plan.wsFlags |= WHERE_ROWID_RANGE|WHERE_COLUMN_RANGE;
106359106355
}
@@ -106443,11 +106439,12 @@
106443106439
** The ANALYZE command and the sqlite_stat1 and sqlite_stat3 tables do
106444106440
** not give us data on the relative sizes of table and index records.
106445106441
** So this computation assumes table records are about twice as big
106446106442
** as index records
106447106443
*/
106448
- if( (pc.plan.wsFlags&~(WHERE_REVERSE|WHERE_ORDERED))==WHERE_IDX_ONLY
106444
+ if( (pc.plan.wsFlags&~(WHERE_REVERSE|WHERE_ORDERED|WHERE_OB_UNIQUE))
106445
+ ==WHERE_IDX_ONLY
106449106446
&& (pWC->wctrlFlags & WHERE_ONEPASS_DESIRED)==0
106450106447
&& sqlite3GlobalConfig.bUseCis
106451106448
&& OptimizationEnabled(pParse->db, SQLITE_CoverIdxScan)
106452106449
){
106453106450
/* This index is not useful for indexing, but it is a covering index.
@@ -106603,11 +106600,11 @@
106603106600
}
106604106601
106605106602
/* If there is no ORDER BY clause and the SQLITE_ReverseOrder flag
106606106603
** is set, then reverse the order that the index will be scanned
106607106604
** in. This is used for application testing, to help find cases
106608
- ** where application behaviour depends on the (undefined) order that
106605
+ ** where application behavior depends on the (undefined) order that
106609106606
** SQLite outputs rows in in the absence of an ORDER BY clause. */
106610106607
if( !p->pOrderBy && pParse->db->flags & SQLITE_ReverseOrder ){
106611106608
p->cost.plan.wsFlags |= WHERE_REVERSE;
106612106609
}
106613106610
@@ -114198,11 +114195,11 @@
114198114195
return;
114199114196
}
114200114197
114201114198
/* If we reach this point, it means that the database connection has
114202114199
** closed all sqlite3_stmt and sqlite3_backup objects and has been
114203
- ** pased to sqlite3_close (meaning that it is a zombie). Therefore,
114200
+ ** passed to sqlite3_close (meaning that it is a zombie). Therefore,
114204114201
** go ahead and free all resources.
114205114202
*/
114206114203
114207114204
/* Free any outstanding Savepoint structures. */
114208114205
sqlite3CloseSavepoints(db);
@@ -117250,11 +117247,11 @@
117250117247
** to the strings "arg1" and "arg2".
117251117248
**
117252117249
** This method should return either SQLITE_OK (0), or an SQLite error
117253117250
** code. If SQLITE_OK is returned, then *ppTokenizer should be set
117254117251
** to point at the newly created tokenizer structure. The generic
117255
- ** sqlite3_tokenizer.pModule variable should not be initialised by
117252
+ ** sqlite3_tokenizer.pModule variable should not be initialized by
117256117253
** this callback. The caller will do so.
117257117254
*/
117258117255
int (*xCreate)(
117259117256
int argc, /* Size of argv array */
117260117257
const char *const*argv, /* Tokenizer argument strings */
@@ -117355,11 +117352,11 @@
117355117352
** May you do good and not evil.
117356117353
** May you find forgiveness for yourself and forgive others.
117357117354
** May you share freely, never taking more than you give.
117358117355
**
117359117356
*************************************************************************
117360
-** This is the header file for the generic hash-table implemenation
117357
+** This is the header file for the generic hash-table implementation
117361117358
** used in SQLite. We've modified it slightly to serve as a standalone
117362117359
** hash table implementation for the full-text indexing module.
117363117360
**
117364117361
*/
117365117362
#ifndef _FTS3_HASH_H_
@@ -119262,11 +119259,11 @@
119262119259
if( SQLITE_ROW==sqlite3_step(pCsr->pStmt) ){
119263119260
return SQLITE_OK;
119264119261
}else{
119265119262
rc = sqlite3_reset(pCsr->pStmt);
119266119263
if( rc==SQLITE_OK && ((Fts3Table *)pCsr->base.pVtab)->zContentTbl==0 ){
119267
- /* If no row was found and no error has occured, then the %_content
119264
+ /* If no row was found and no error has occurred, then the %_content
119268119265
** table is missing a row that is present in the full-text index.
119269119266
** The data structures are corrupt. */
119270119267
rc = FTS_CORRUPT_VTAB;
119271119268
pCsr->isEof = 1;
119272119269
}
@@ -120502,11 +120499,11 @@
120502120499
sqlite3Fts3SegReaderFinish(pSegcsr);
120503120500
sqlite3_free(pSegcsr);
120504120501
}
120505120502
120506120503
/*
120507
-** This function retreives the doclist for the specified term (or term
120504
+** This function retrieves the doclist for the specified term (or term
120508120505
** prefix) from the database.
120509120506
*/
120510120507
static int fts3TermSelect(
120511120508
Fts3Table *p, /* Virtual table handle */
120512120509
Fts3PhraseToken *pTok, /* Token to query for */
@@ -121253,11 +121250,11 @@
121253121250
#ifdef SQLITE_ENABLE_ICU
121254121251
SQLITE_PRIVATE void sqlite3Fts3IcuTokenizerModule(sqlite3_tokenizer_module const**ppModule);
121255121252
#endif
121256121253
121257121254
/*
121258
-** Initialise the fts3 extension. If this extension is built as part
121255
+** Initialize the fts3 extension. If this extension is built as part
121259121256
** of the sqlite library, then this function is called directly by
121260121257
** SQLite. If fts3 is built as a dynamically loadable extension, this
121261121258
** function is called by the sqlite3_extension_init() entry point.
121262121259
*/
121263121260
SQLITE_PRIVATE int sqlite3Fts3Init(sqlite3 *db){
@@ -121287,11 +121284,11 @@
121287121284
if( rc!=SQLITE_OK ) return rc;
121288121285
121289121286
sqlite3Fts3SimpleTokenizerModule(&pSimple);
121290121287
sqlite3Fts3PorterTokenizerModule(&pPorter);
121291121288
121292
- /* Allocate and initialise the hash-table used to store tokenizers. */
121289
+ /* Allocate and initialize the hash-table used to store tokenizers. */
121293121290
pHash = sqlite3_malloc(sizeof(Fts3Hash));
121294121291
if( !pHash ){
121295121292
rc = SQLITE_NOMEM;
121296121293
}else{
121297121294
sqlite3Fts3HashInit(pHash, FTS3_HASH_STRING, 1);
@@ -122886,11 +122883,11 @@
122886122883
** The returned value is either NULL or a pointer to a buffer containing
122887122884
** a position-list indicating the occurrences of the phrase in column iCol
122888122885
** of the current row.
122889122886
**
122890122887
** More specifically, the returned buffer contains 1 varint for each
122891
-** occurence of the phrase in the column, stored using the normal (delta+2)
122888
+** occurrence of the phrase in the column, stored using the normal (delta+2)
122892122889
** compression and is terminated by either an 0x01 or 0x00 byte. For example,
122893122890
** if the requested column contains "a b X c d X X" and the position-list
122894122891
** for 'X' is requested, the buffer returned may contain:
122895122892
**
122896122893
** 0x04 0x05 0x03 0x01 or 0x04 0x05 0x03 0x00
@@ -123625,11 +123622,11 @@
123625123622
123626123623
/*
123627123624
** This function is equivalent to the standard isspace() function.
123628123625
**
123629123626
** The standard isspace() can be awkward to use safely, because although it
123630
-** is defined to accept an argument of type int, its behaviour when passed
123627
+** is defined to accept an argument of type int, its behavior when passed
123631123628
** an integer that falls outside of the range of the unsigned char type
123632123629
** is undefined (and sometimes, "undefined" means segfault). This wrapper
123633123630
** is defined to accept an argument of type char, and always returns 0 for
123634123631
** any values that fall outside of the range of the unsigned char type (i.e.
123635123632
** negative values).
@@ -125993,11 +125990,11 @@
125993125990
#endif
125994125991
125995125992
/*
125996125993
** Set up SQL objects in database db used to access the contents of
125997125994
** the hash table pointed to by argument pHash. The hash table must
125998
-** been initialised to use string keys, and to take a private copy
125995
+** been initialized to use string keys, and to take a private copy
125999125996
** of the key when a value is inserted. i.e. by a call similar to:
126000125997
**
126001125998
** sqlite3Fts3HashInit(pHash, FTS3_HASH_STRING, 1);
126002125999
**
126003126000
** This function adds a scalar function (see header comment above
@@ -127772,10 +127769,11 @@
127772127769
if( ppOffsetList ){
127773127770
*ppOffsetList = pReader->pOffsetList;
127774127771
*pnOffsetList = (int)(p - pReader->pOffsetList - 1);
127775127772
}
127776127773
127774
+ /* List may have been edited in place by fts3EvalNearTrim() */
127777127775
while( p<pEnd && *p==0 ) p++;
127778127776
127779127777
/* If there are no more entries in the doclist, set pOffsetList to
127780127778
** NULL. Otherwise, set Fts3SegReader.iDocid to the next docid and
127781127779
** Fts3SegReader.pOffsetList to point to the next offset list before
@@ -128787,13 +128785,17 @@
128787128785
** function adjusts the pointer *ppList and the length *pnList so that they
128788128786
** identify the subset of the position list that corresponds to column iCol.
128789128787
**
128790128788
** If there are no entries in the input position list for column iCol, then
128791128789
** *pnList is set to zero before returning.
128790
+**
128791
+** If parameter bZero is non-zero, then any part of the input list following
128792
+** the end of the output list is zeroed before returning.
128792128793
*/
128793128794
static void fts3ColumnFilter(
128794128795
int iCol, /* Column to filter on */
128796
+ int bZero, /* Zero out anything following *ppList */
128795128797
char **ppList, /* IN/OUT: Pointer to position list */
128796128798
int *pnList /* IN/OUT: Size of buffer *ppList in bytes */
128797128799
){
128798128800
char *pList = *ppList;
128799128801
int nList = *pnList;
@@ -128818,10 +128820,13 @@
128818128820
}
128819128821
p = &pList[1];
128820128822
p += sqlite3Fts3GetVarint32(p, &iCurrent);
128821128823
}
128822128824
128825
+ if( bZero && &pList[nList]!=pEnd ){
128826
+ memset(&pList[nList], 0, pEnd - &pList[nList]);
128827
+ }
128823128828
*ppList = pList;
128824128829
*pnList = nList;
128825128830
}
128826128831
128827128832
/*
@@ -128890,24 +128895,24 @@
128890128895
rc = fts3SegReaderNextDocid(p, apSegment[j], 0, 0);
128891128896
j++;
128892128897
}
128893128898
if( rc!=SQLITE_OK ) return rc;
128894128899
fts3SegReaderSort(pMsr->apSegment, nMerge, j, xCmp);
128900
+
128901
+ if( nList>0 && fts3SegReaderIsPending(apSegment[0]) ){
128902
+ rc = fts3MsrBufferData(pMsr, pList, nList+1);
128903
+ if( rc!=SQLITE_OK ) return rc;
128904
+ assert( (pMsr->aBuffer[nList] & 0xFE)==0x00 );
128905
+ pList = pMsr->aBuffer;
128906
+ }
128895128907
128896128908
if( pMsr->iColFilter>=0 ){
128897
- fts3ColumnFilter(pMsr->iColFilter, &pList, &nList);
128909
+ fts3ColumnFilter(pMsr->iColFilter, 1, &pList, &nList);
128898128910
}
128899128911
128900128912
if( nList>0 ){
128901
- if( fts3SegReaderIsPending(apSegment[0]) ){
128902
- rc = fts3MsrBufferData(pMsr, pList, nList+1);
128903
- if( rc!=SQLITE_OK ) return rc;
128904
- *paPoslist = pMsr->aBuffer;
128905
- assert( (pMsr->aBuffer[nList] & 0xFE)==0x00 );
128906
- }else{
128907
- *paPoslist = pList;
128908
- }
128913
+ *paPoslist = pList;
128909128914
*piDocid = iDocid;
128910128915
*pnPoslist = nList;
128911128916
break;
128912128917
}
128913128918
}
@@ -129146,11 +129151,11 @@
129146129151
fts3SegReaderNextDocid(p, apSegment[j], 0, 0);
129147129152
j++;
129148129153
}
129149129154
129150129155
if( isColFilter ){
129151
- fts3ColumnFilter(pFilter->iCol, &pList, &nList);
129156
+ fts3ColumnFilter(pFilter->iCol, 0, &pList, &nList);
129152129157
}
129153129158
129154129159
if( !isIgnoreEmpty || nList>0 ){
129155129160
129156129161
/* Calculate the 'docid' delta value to write into the merged
@@ -132083,13 +132088,13 @@
132083132088
** Select the fragment of text consisting of nFragment contiguous tokens
132084132089
** from column iCol that represent the "best" snippet. The best snippet
132085132090
** is the snippet with the highest score, where scores are calculated
132086132091
** by adding:
132087132092
**
132088
-** (a) +1 point for each occurence of a matchable phrase in the snippet.
132093
+** (a) +1 point for each occurrence of a matchable phrase in the snippet.
132089132094
**
132090
-** (b) +1000 points for the first occurence of each matchable phrase in
132095
+** (b) +1000 points for the first occurrence of each matchable phrase in
132091132096
** the snippet for which the corresponding mCovered bit is not set.
132092132097
**
132093132098
** The selected snippet parameters are stored in structure *pFragment before
132094132099
** returning. The score of the selected snippet is stored in *piScore
132095132100
** before returning.
@@ -133340,11 +133345,11 @@
133340133345
** the return value of sqlite3FtsUnicodeIsalnum() is inverted for all
133341133346
** codepoints in the aiException[] array.
133342133347
**
133343133348
** If a standalone diacritic mark (one that sqlite3FtsUnicodeIsdiacritic()
133344133349
** identifies as a diacritic) occurs in the zIn/nIn string it is ignored.
133345
-** It is not possible to change the behaviour of the tokenizer with respect
133350
+** It is not possible to change the behavior of the tokenizer with respect
133346133351
** to these codepoints.
133347133352
*/
133348133353
static int unicodeAddExceptions(
133349133354
unicode_tokenizer *p, /* Tokenizer to add exceptions to */
133350133355
int bAlnum, /* Replace Isalnum() return value with this */
@@ -136643,11 +136648,11 @@
136643136648
RtreeNode *pLeaf = 0; /* Leaf node containing record iDelete */
136644136649
int iCell; /* Index of iDelete cell in pLeaf */
136645136650
RtreeNode *pRoot; /* Root node of rtree structure */
136646136651
136647136652
136648
- /* Obtain a reference to the root node to initialise Rtree.iDepth */
136653
+ /* Obtain a reference to the root node to initialize Rtree.iDepth */
136649136654
rc = nodeAcquire(pRtree, 1, 0, &pRoot);
136650136655
136651136656
/* Obtain a reference to the leaf node that contains the entry
136652136657
** about to be deleted.
136653136658
*/
136654136659
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.7.16. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a single translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% or more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -676,13 +676,13 @@
676 **
677 ** See also: [sqlite3_libversion()],
678 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
679 ** [sqlite_version()] and [sqlite_source_id()].
680 */
681 #define SQLITE_VERSION "3.7.16"
682 #define SQLITE_VERSION_NUMBER 3007016
683 #define SQLITE_SOURCE_ID "2013-03-13 00:13:25 839aa91faf1db7025d90fa3c65e50efb829b053b"
684
685 /*
686 ** CAPI3REF: Run-Time Library Version Numbers
687 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
688 **
@@ -3249,11 +3249,11 @@
3249 ** "private". ^Setting it to "shared" is equivalent to setting the
3250 ** SQLITE_OPEN_SHAREDCACHE bit in the flags argument passed to
3251 ** sqlite3_open_v2(). ^Setting the cache parameter to "private" is
3252 ** equivalent to setting the SQLITE_OPEN_PRIVATECACHE bit.
3253 ** ^If sqlite3_open_v2() is used and the "cache" parameter is present in
3254 ** a URI filename, its value overrides any behaviour requested by setting
3255 ** SQLITE_OPEN_PRIVATECACHE or SQLITE_OPEN_SHAREDCACHE flag.
3256 ** </ul>
3257 **
3258 ** ^Specifying an unknown parameter in the query component of a URI is not an
3259 ** error. Future versions of SQLite might understand additional query
@@ -4567,11 +4567,12 @@
4567 SQLITE_API SQLITE_DEPRECATED int sqlite3_aggregate_count(sqlite3_context*);
4568 SQLITE_API SQLITE_DEPRECATED int sqlite3_expired(sqlite3_stmt*);
4569 SQLITE_API SQLITE_DEPRECATED int sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*);
4570 SQLITE_API SQLITE_DEPRECATED int sqlite3_global_recover(void);
4571 SQLITE_API SQLITE_DEPRECATED void sqlite3_thread_cleanup(void);
4572 SQLITE_API SQLITE_DEPRECATED int sqlite3_memory_alarm(void(*)(void*,sqlite3_int64,int),void*,sqlite3_int64);
 
4573 #endif
4574
4575 /*
4576 ** CAPI3REF: Obtaining SQL Function Parameter Values
4577 **
@@ -4647,18 +4648,21 @@
4647 ** an aggregate query, the xStep() callback of the aggregate function
4648 ** implementation is never called and xFinal() is called exactly once.
4649 ** In those cases, sqlite3_aggregate_context() might be called for the
4650 ** first time from within xFinal().)^
4651 **
4652 ** ^The sqlite3_aggregate_context(C,N) routine returns a NULL pointer if N is
4653 ** less than or equal to zero or if a memory allocate error occurs.
 
4654 **
4655 ** ^(The amount of space allocated by sqlite3_aggregate_context(C,N) is
4656 ** determined by the N parameter on first successful call. Changing the
4657 ** value of N in subsequent call to sqlite3_aggregate_context() within
4658 ** the same aggregate function instance will not resize the memory
4659 ** allocation.)^
 
 
4660 **
4661 ** ^SQLite automatically frees the memory allocated by
4662 ** sqlite3_aggregate_context() when the aggregate query concludes.
4663 **
4664 ** The first parameter must be a copy of the
@@ -6948,11 +6952,11 @@
6948 ** intact. If the requested page is not already in the cache, then the
6949 ** cache implementation should use the value of the createFlag
6950 ** parameter to help it determined what action to take:
6951 **
6952 ** <table border=1 width=85% align=center>
6953 ** <tr><th> createFlag <th> Behaviour when page is not already in cache
6954 ** <tr><td> 0 <td> Do not allocate a new page. Return NULL.
6955 ** <tr><td> 1 <td> Allocate a new page if it easy and convenient to do so.
6956 ** Otherwise return NULL.
6957 ** <tr><td> 2 <td> Make every effort to allocate a new page. Only return
6958 ** NULL if allocating a new page is effectively impossible.
@@ -7753,11 +7757,11 @@
7753 ** May you do good and not evil.
7754 ** May you find forgiveness for yourself and forgive others.
7755 ** May you share freely, never taking more than you give.
7756 **
7757 *************************************************************************
7758 ** This is the header file for the generic hash-table implemenation
7759 ** used in SQLite.
7760 */
7761 #ifndef _SQLITE_HASH_H_
7762 #define _SQLITE_HASH_H_
7763
@@ -12943,13 +12947,10 @@
12943 "OMIT_LOOKASIDE",
12944 #endif
12945 #ifdef SQLITE_OMIT_MEMORYDB
12946 "OMIT_MEMORYDB",
12947 #endif
12948 #ifdef SQLITE_OMIT_MERGE_SORT
12949 "OMIT_MERGE_SORT",
12950 #endif
12951 #ifdef SQLITE_OMIT_OR_OPTIMIZATION
12952 "OMIT_OR_OPTIMIZATION",
12953 #endif
12954 #ifdef SQLITE_OMIT_PAGER_PRAGMAS
12955 "OMIT_PAGER_PRAGMAS",
@@ -13534,27 +13535,17 @@
13534 SQLITE_PRIVATE void sqlite3VdbeFrameDelete(VdbeFrame*);
13535 SQLITE_PRIVATE int sqlite3VdbeFrameRestore(VdbeFrame *);
13536 SQLITE_PRIVATE void sqlite3VdbeMemStoreType(Mem *pMem);
13537 SQLITE_PRIVATE int sqlite3VdbeTransferError(Vdbe *p);
13538
13539 #ifdef SQLITE_OMIT_MERGE_SORT
13540 # define sqlite3VdbeSorterInit(Y,Z) SQLITE_OK
13541 # define sqlite3VdbeSorterWrite(X,Y,Z) SQLITE_OK
13542 # define sqlite3VdbeSorterClose(Y,Z)
13543 # define sqlite3VdbeSorterRowkey(Y,Z) SQLITE_OK
13544 # define sqlite3VdbeSorterRewind(X,Y,Z) SQLITE_OK
13545 # define sqlite3VdbeSorterNext(X,Y,Z) SQLITE_OK
13546 # define sqlite3VdbeSorterCompare(X,Y,Z) SQLITE_OK
13547 #else
13548 SQLITE_PRIVATE int sqlite3VdbeSorterInit(sqlite3 *, VdbeCursor *);
13549 SQLITE_PRIVATE void sqlite3VdbeSorterClose(sqlite3 *, VdbeCursor *);
13550 SQLITE_PRIVATE int sqlite3VdbeSorterRowkey(const VdbeCursor *, Mem *);
13551 SQLITE_PRIVATE int sqlite3VdbeSorterNext(sqlite3 *, const VdbeCursor *, int *);
13552 SQLITE_PRIVATE int sqlite3VdbeSorterRewind(sqlite3 *, const VdbeCursor *, int *);
13553 SQLITE_PRIVATE int sqlite3VdbeSorterWrite(sqlite3 *, const VdbeCursor *, Mem *);
13554 SQLITE_PRIVATE int sqlite3VdbeSorterCompare(const VdbeCursor *, Mem *, int *);
13555 #endif
13556
13557 #if !defined(SQLITE_OMIT_SHARED_CACHE) && SQLITE_THREADSAFE>0
13558 SQLITE_PRIVATE void sqlite3VdbeEnter(Vdbe*);
13559 SQLITE_PRIVATE void sqlite3VdbeLeave(Vdbe*);
13560 #else
@@ -21334,11 +21325,11 @@
21334 ** returns FALSE but it still converts the prefix and writes the result
21335 ** into *pResult.
21336 */
21337 SQLITE_PRIVATE int sqlite3AtoF(const char *z, double *pResult, int length, u8 enc){
21338 #ifndef SQLITE_OMIT_FLOATING_POINT
21339 int incr = (enc==SQLITE_UTF8?1:2);
21340 const char *zEnd = z + length;
21341 /* sign * significand * (10 ^ (esign * exponent)) */
21342 int sign = 1; /* sign of significand */
21343 i64 s = 0; /* significand */
21344 int d = 0; /* adjust exponent for shifting decimal point */
@@ -21345,14 +21336,26 @@
21345 int esign = 1; /* sign of exponent */
21346 int e = 0; /* exponent */
21347 int eValid = 1; /* True exponent is either not used or is well-formed */
21348 double result;
21349 int nDigits = 0;
 
21350
 
21351 *pResult = 0.0; /* Default return value, in case of an error */
21352
21353 if( enc==SQLITE_UTF16BE ) z++;
 
 
 
 
 
 
 
 
 
 
21354
21355 /* skip leading spaces */
21356 while( z<zEnd && sqlite3Isspace(*z) ) z+=incr;
21357 if( z>=zEnd ) return 0;
21358
@@ -21481,11 +21484,11 @@
21481
21482 /* store the result */
21483 *pResult = result;
21484
21485 /* return true if number and no extra non-whitespace chracters after */
21486 return z>=zEnd && nDigits>0 && eValid;
21487 #else
21488 return !sqlite3Atoi64(z, pResult, length, enc);
21489 #endif /* SQLITE_OMIT_FLOATING_POINT */
21490 }
21491
@@ -21530,25 +21533,37 @@
21530 ** If zNum is exactly 9223372036854665808, return 2. This special
21531 ** case is broken out because while 9223372036854665808 cannot be a
21532 ** signed 64-bit integer, its negative -9223372036854665808 can be.
21533 **
21534 ** If zNum is too big for a 64-bit integer and is not
21535 ** 9223372036854665808 then return 1.
 
21536 **
21537 ** length is the number of bytes in the string (bytes, not characters).
21538 ** The string is not necessarily zero-terminated. The encoding is
21539 ** given by enc.
21540 */
21541 SQLITE_PRIVATE int sqlite3Atoi64(const char *zNum, i64 *pNum, int length, u8 enc){
21542 int incr = (enc==SQLITE_UTF8?1:2);
21543 u64 u = 0;
21544 int neg = 0; /* assume positive */
21545 int i;
21546 int c = 0;
 
21547 const char *zStart;
21548 const char *zEnd = zNum + length;
21549 if( enc==SQLITE_UTF16BE ) zNum++;
 
 
 
 
 
 
 
 
 
 
21550 while( zNum<zEnd && sqlite3Isspace(*zNum) ) zNum+=incr;
21551 if( zNum<zEnd ){
21552 if( *zNum=='-' ){
21553 neg = 1;
21554 zNum+=incr;
@@ -21569,11 +21584,11 @@
21569 *pNum = (i64)u;
21570 }
21571 testcase( i==18 );
21572 testcase( i==19 );
21573 testcase( i==20 );
21574 if( (c!=0 && &zNum[i]<zEnd) || (i==0 && zStart==zNum) || i>19*incr ){
21575 /* zNum is empty or contains non-numeric text or is longer
21576 ** than 19 digits (thus guaranteeing that it is too large) */
21577 return 1;
21578 }else if( i<19*incr ){
21579 /* Less than 19 digits, so we know that it fits in 64 bits */
@@ -23250,11 +23265,11 @@
23250 ** they may be overridden at runtime to facilitate fault injection during
23251 ** testing and sandboxing. The following array holds the names and pointers
23252 ** to all overrideable system calls.
23253 */
23254 static struct unix_syscall {
23255 const char *zName; /* Name of the sytem call */
23256 sqlite3_syscall_ptr pCurrent; /* Current value of the system call */
23257 sqlite3_syscall_ptr pDefault; /* Default value */
23258 } aSyscall[] = {
23259 { "open", (sqlite3_syscall_ptr)posixOpen, 0 },
23260 #define osOpen ((int(*)(const char*,int,int))aSyscall[0].pCurrent)
@@ -24822,11 +24837,11 @@
24822 ******************************************************************************/
24823
24824 /******************************************************************************
24825 ************************* Begin dot-file Locking ******************************
24826 **
24827 ** The dotfile locking implementation uses the existance of separate lock
24828 ** files (really a directory) to control access to the database. This works
24829 ** on just about every filesystem imaginable. But there are serious downsides:
24830 **
24831 ** (1) There is zero concurrency. A single reader blocks all other
24832 ** connections from reading or writing the database.
@@ -24837,11 +24852,11 @@
24837 ** Nevertheless, a dotlock is an appropriate locking mode for use if no
24838 ** other locking strategy is available.
24839 **
24840 ** Dotfile locking works by creating a subdirectory in the same directory as
24841 ** the database and with the same name but with a ".lock" extension added.
24842 ** The existance of a lock directory implies an EXCLUSIVE lock. All other
24843 ** lock types (SHARED, RESERVED, PENDING) are mapped into EXCLUSIVE.
24844 */
24845
24846 /*
24847 ** The file suffix added to the data base filename in order to create the
@@ -26326,11 +26341,11 @@
26326 pFile->lastErrno = errno;
26327 return unixLogError(SQLITE_IOERR_FSYNC, "full_fsync", pFile->zPath);
26328 }
26329
26330 /* Also fsync the directory containing the file if the DIRSYNC flag
26331 ** is set. This is a one-time occurrance. Many systems (examples: AIX)
26332 ** are unable to fsync a directory, so ignore errors on the fsync.
26333 */
26334 if( pFile->ctrlFlags & UNIXFILE_DIRSYNC ){
26335 int dirfd;
26336 OSTRACE(("DIRSYNC %s (have_fullfsync=%d fullsync=%d)\n", pFile->zPath,
@@ -27700,11 +27715,11 @@
27700 #endif
27701 ){
27702 unixEnterMutex();
27703 rc = findInodeInfo(pNew, &pNew->pInode);
27704 if( rc!=SQLITE_OK ){
27705 /* If an error occured in findInodeInfo(), close the file descriptor
27706 ** immediately, before releasing the mutex. findInodeInfo() may fail
27707 ** in two scenarios:
27708 **
27709 ** (a) A call to fstat() failed.
27710 ** (b) A malloc failed.
@@ -28338,11 +28353,11 @@
28338 #endif
28339 return rc;
28340 }
28341
28342 /*
28343 ** Test the existance of or access permissions of file zPath. The
28344 ** test performed depends on the value of flags:
28345 **
28346 ** SQLITE_ACCESS_EXISTS: Return 1 if the file exists
28347 ** SQLITE_ACCESS_READWRITE: Return 1 if the file is read and writable.
28348 ** SQLITE_ACCESS_READONLY: Return 1 if the file is readable.
@@ -30442,11 +30457,11 @@
30442 ** they may be overridden at runtime to facilitate fault injection during
30443 ** testing and sandboxing. The following array holds the names and pointers
30444 ** to all overrideable system calls.
30445 */
30446 static struct win_syscall {
30447 const char *zName; /* Name of the sytem call */
30448 sqlite3_syscall_ptr pCurrent; /* Current value of the system call */
30449 sqlite3_syscall_ptr pDefault; /* Default value */
30450 } aSyscall[] = {
30451 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT
30452 { "AreFileApisANSI", (SYSCALL)AreFileApisANSI, 0 },
@@ -32159,11 +32174,11 @@
32159
32160 /* API oddity: If successful, SetFilePointer() returns a dword
32161 ** containing the lower 32-bits of the new file-offset. Or, if it fails,
32162 ** it returns INVALID_SET_FILE_POINTER. However according to MSDN,
32163 ** INVALID_SET_FILE_POINTER may also be a valid new offset. So to determine
32164 ** whether an error has actually occured, it is also necessary to call
32165 ** GetLastError().
32166 */
32167 dwRet = osSetFilePointer(pFile->h, lowerBits, &upperBits, FILE_BEGIN);
32168
32169 if( (dwRet==INVALID_SET_FILE_POINTER
@@ -32305,11 +32320,11 @@
32305 sqlite3_file *id, /* File to write into */
32306 const void *pBuf, /* The bytes to be written */
32307 int amt, /* Number of bytes to write */
32308 sqlite3_int64 offset /* Offset into the file to begin writing at */
32309 ){
32310 int rc = 0; /* True if error has occured, else false */
32311 winFile *pFile = (winFile*)id; /* File handle */
32312 int nRetry = 0; /* Number of retries */
32313
32314 assert( amt>0 );
32315 assert( pFile );
@@ -34127,11 +34142,11 @@
34127 OSTRACE(("DELETE \"%s\" %s\n", zFilename, (rc ? "failed" : "ok" )));
34128 return rc;
34129 }
34130
34131 /*
34132 ** Check the existance and status of a file.
34133 */
34134 static int winAccess(
34135 sqlite3_vfs *pVfs, /* Not used on win32 */
34136 const char *zFilename, /* Name of file to check */
34137 int flags, /* Type of test to make on this file */
@@ -34736,11 +34751,11 @@
34736
34737
34738 /*
34739 ** A bitmap is an instance of the following structure.
34740 **
34741 ** This bitmap records the existance of zero or more bits
34742 ** with values between 1 and iSize, inclusive.
34743 **
34744 ** There are three possible representations of the bitmap.
34745 ** If iSize<=BITVEC_NBIT, then Bitvec.u.aBitmap[] is a straight
34746 ** bitmap. The least significant bit is bit 1.
@@ -37638,11 +37653,11 @@
37638 ** layer must either commit or rollback the transaction.
37639 **
37640 ** * A write transaction is active.
37641 ** * An EXCLUSIVE or greater lock is held on the database file.
37642 ** * All writing and syncing of journal and database data has finished.
37643 ** If no error occured, all that remains is to finalize the journal to
37644 ** commit the transaction. If an error did occur, the caller will need
37645 ** to rollback the transaction.
37646 **
37647 ** ERROR:
37648 **
@@ -37886,11 +37901,11 @@
37886 ** journal file from being successfully finalized, the setMaster flag
37887 ** is cleared anyway (and the pager will move to ERROR state).
37888 **
37889 ** doNotSpill, doNotSyncSpill
37890 **
37891 ** These two boolean variables control the behaviour of cache-spills
37892 ** (calls made by the pcache module to the pagerStress() routine to
37893 ** write cached data to the file-system in order to free up memory).
37894 **
37895 ** When doNotSpill is non-zero, writing to the database from pagerStress()
37896 ** is disabled altogether. This is done in a very obscure case that
@@ -38764,11 +38779,11 @@
38764 put32bits(&zHeader[sizeof(aJournalMagic)], 0xffffffff);
38765 }else{
38766 memset(zHeader, 0, sizeof(aJournalMagic)+4);
38767 }
38768
38769 /* The random check-hash initialiser */
38770 sqlite3_randomness(sizeof(pPager->cksumInit), &pPager->cksumInit);
38771 put32bits(&zHeader[sizeof(aJournalMagic)+4], pPager->cksumInit);
38772 /* The initial database size */
38773 put32bits(&zHeader[sizeof(aJournalMagic)+8], pPager->dbOrigSize);
38774 /* The assumed sector size for this process */
@@ -41096,11 +41111,11 @@
41096 **
41097 ** If the condition asserted by this function were not true, and the
41098 ** dirty page were to be discarded from the cache via the pagerStress()
41099 ** routine, pagerStress() would not write the current page content to
41100 ** the database file. If a savepoint transaction were rolled back after
41101 ** this happened, the correct behaviour would be to restore the current
41102 ** content of the page. However, since this content is not present in either
41103 ** the database file or the portion of the rollback journal and
41104 ** sub-journal rolled back the content could not be restored and the
41105 ** database image would become corrupt. It is therefore fortunate that
41106 ** this circumstance cannot arise.
@@ -48938,10 +48953,23 @@
48938 */
48939 static void btreeClearHasContent(BtShared *pBt){
48940 sqlite3BitvecDestroy(pBt->pHasContent);
48941 pBt->pHasContent = 0;
48942 }
 
 
 
 
 
 
 
 
 
 
 
 
 
48943
48944 /*
48945 ** Save the current cursor position in the variables BtCursor.nKey
48946 ** and BtCursor.pKey. The cursor's state is set to CURSOR_REQUIRESEEK.
48947 **
@@ -48978,16 +49006,11 @@
48978 }
48979 }
48980 assert( !pCur->apPage[0]->intKey || !pCur->pKey );
48981
48982 if( rc==SQLITE_OK ){
48983 int i;
48984 for(i=0; i<=pCur->iPage; i++){
48985 releasePage(pCur->apPage[i]);
48986 pCur->apPage[i] = 0;
48987 }
48988 pCur->iPage = -1;
48989 pCur->eState = CURSOR_REQUIRESEEK;
48990 }
48991
48992 invalidateOverflowCache(pCur);
48993 return rc;
@@ -49001,15 +49024,19 @@
49001 static int saveAllCursors(BtShared *pBt, Pgno iRoot, BtCursor *pExcept){
49002 BtCursor *p;
49003 assert( sqlite3_mutex_held(pBt->mutex) );
49004 assert( pExcept==0 || pExcept->pBt==pBt );
49005 for(p=pBt->pCursor; p; p=p->pNext){
49006 if( p!=pExcept && (0==iRoot || p->pgnoRoot==iRoot) &&
49007 p->eState==CURSOR_VALID ){
49008 int rc = saveCursorPosition(p);
49009 if( SQLITE_OK!=rc ){
49010 return rc;
 
 
 
 
49011 }
49012 }
49013 }
49014 return SQLITE_OK;
49015 }
@@ -50593,11 +50620,11 @@
50593 **
50594 ** This is useful in one special case in the backup API code where it is
50595 ** known that the shared b-tree mutex is held, but the mutex on the
50596 ** database handle that owns *p is not. In this case if sqlite3BtreeEnter()
50597 ** were to be called, it might collide with some other operation on the
50598 ** database handle that owns *p, causing undefined behaviour.
50599 */
50600 SQLITE_PRIVATE int sqlite3BtreeGetReserveNoMutex(Btree *p){
50601 assert( sqlite3_mutex_held(p->pBt->mutex) );
50602 return p->pBt->pageSize - p->pBt->usableSize;
50603 }
@@ -53873,11 +53900,11 @@
53873 ** for that page now.
53874 **
53875 ** If this is the first overflow page, then write a partial entry
53876 ** to the pointer-map. If we write nothing to this pointer-map slot,
53877 ** then the optimistic overflow chain processing in clearCell()
53878 ** may misinterpret the uninitialised values and delete the
53879 ** wrong pages from the database.
53880 */
53881 if( pBt->autoVacuum && rc==SQLITE_OK ){
53882 u8 eType = (pgnoPtrmap?PTRMAP_OVERFLOW2:PTRMAP_OVERFLOW1);
53883 ptrmapPut(pBt, pgnoOvfl, eType, pgnoPtrmap, &rc);
@@ -55346,11 +55373,11 @@
55346 assert( pPage->leaf );
55347 }
55348 insertCell(pPage, idx, newCell, szNew, 0, 0, &rc);
55349 assert( rc!=SQLITE_OK || pPage->nCell>0 || pPage->nOverflow>0 );
55350
55351 /* If no error has occured and pPage has an overflow cell, call balance()
55352 ** to redistribute the cells within the tree. Since balance() may move
55353 ** the cursor, zero the BtCursor.info.nSize and BtCursor.validNKey
55354 ** variables.
55355 **
55356 ** Previous versions of SQLite called moveToRoot() to move the cursor
@@ -59080,11 +59107,11 @@
59080 break;
59081 }
59082 }
59083 sqlite3DbFree(v->db, sIter.apSub);
59084
59085 /* Return true if hasAbort==mayAbort. Or if a malloc failure occured.
59086 ** If malloc failed, then the while() loop above may not have iterated
59087 ** through all opcodes and hasAbort may be set incorrectly. Return
59088 ** true for this case to prevent the assert() in the callers frame
59089 ** from failing. */
59090 return ( v->db->mallocFailed || hasAbort==mayAbort );
@@ -60712,11 +60739,11 @@
60712 sqlite3 *const db = p->db;
60713 int rc = SQLITE_OK;
60714
60715 /* If p->iStatement is greater than zero, then this Vdbe opened a
60716 ** statement transaction that should be closed here. The only exception
60717 ** is that an IO error may have occured, causing an emergency rollback.
60718 ** In this case (db->nStatement==0), and there is nothing to do.
60719 */
60720 if( db->nStatement && p->iStatement ){
60721 int i;
60722 const int iSavepoint = p->iStatement-1;
@@ -60848,11 +60875,11 @@
60848 ** transaction must be rolled back to restore the database to a
60849 ** consistent state.
60850 **
60851 ** Even if the statement is read-only, it is important to perform
60852 ** a statement or transaction rollback operation. If the error
60853 ** occured while writing to the journal, sub-journal or database
60854 ** file as part of an effort to free up cache space (see function
60855 ** pagerStress() in pager.c), the rollback is required to restore
60856 ** the pager to a consistent state.
60857 */
60858 if( !p->readOnly || mrc!=SQLITE_INTERRUPT ){
@@ -61262,11 +61289,11 @@
61262 **
61263 ** In an SQLite index record, the serial type is stored directly before
61264 ** the blob of data that it corresponds to. In a table record, all serial
61265 ** types are stored at the start of the record, and the blobs of data at
61266 ** the end. Hence these functions allow the caller to handle the
61267 ** serial-type and data blob seperately.
61268 **
61269 ** The following table describes the various storage classes for data:
61270 **
61271 ** serial type bytes of data type
61272 ** -------------- --------------- ---------------
@@ -62402,11 +62429,11 @@
62402 || rc==SQLITE_BUSY || rc==SQLITE_MISUSE
62403 );
62404 assert( p->rc!=SQLITE_ROW && p->rc!=SQLITE_DONE );
62405 if( p->isPrepareV2 && rc!=SQLITE_ROW && rc!=SQLITE_DONE ){
62406 /* If this statement was prepared using sqlite3_prepare_v2(), and an
62407 ** error has occured, then return the error code in p->rc to the
62408 ** caller. Set the error code in the database handle to the same value.
62409 */
62410 rc = sqlite3VdbeTransferError(p);
62411 }
62412 return (rc&db->errMask);
@@ -63692,15 +63719,11 @@
63692 #define Deephemeralize(P) \
63693 if( ((P)->flags&MEM_Ephem)!=0 \
63694 && sqlite3VdbeMemMakeWriteable(P) ){ goto no_mem;}
63695
63696 /* Return true if the cursor was opened using the OP_OpenSorter opcode. */
63697 #ifdef SQLITE_OMIT_MERGE_SORT
63698 # define isSorter(x) 0
63699 #else
63700 # define isSorter(x) ((x)->pSorter!=0)
63701 #endif
63702
63703 /*
63704 ** Argument pMem points at a register that will be passed to a
63705 ** user-defined function or returned to the user as the result of a query.
63706 ** This routine sets the pMem->type variable used by the sqlite3_value_*()
@@ -67433,21 +67456,16 @@
67433 case OP_SorterOpen: {
67434 #if 0 /* local variables moved into u.ba */
67435 VdbeCursor *pCx;
67436 #endif /* local variables moved into u.ba */
67437
67438 #ifndef SQLITE_OMIT_MERGE_SORT
67439 u.ba.pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1);
67440 if( u.ba.pCx==0 ) goto no_mem;
67441 u.ba.pCx->pKeyInfo = pOp->p4.pKeyInfo;
67442 u.ba.pCx->pKeyInfo->enc = ENC(p->db);
67443 u.ba.pCx->isSorter = 1;
67444 rc = sqlite3VdbeSorterInit(db, u.ba.pCx);
67445 #else
67446 pOp->opcode = OP_OpenEphemeral;
67447 pc--;
67448 #endif
67449 break;
67450 }
67451
67452 /* Opcode: OpenPseudo P1 P2 P3 * P5
67453 **
@@ -68348,19 +68366,14 @@
68348 case OP_SorterData: {
68349 #if 0 /* local variables moved into u.bl */
68350 VdbeCursor *pC;
68351 #endif /* local variables moved into u.bl */
68352
68353 #ifndef SQLITE_OMIT_MERGE_SORT
68354 pOut = &aMem[pOp->p2];
68355 u.bl.pC = p->apCsr[pOp->p1];
68356 assert( u.bl.pC->isSorter );
68357 rc = sqlite3VdbeSorterRowkey(u.bl.pC, pOut);
68358 #else
68359 pOp->opcode = OP_RowKey;
68360 pc--;
68361 #endif
68362 break;
68363 }
68364
68365 /* Opcode: RowData P1 P2 * * *
68366 **
@@ -68563,13 +68576,10 @@
68563 ** rewinding so that the global variable will be incremented and
68564 ** regression tests can determine whether or not the optimizer is
68565 ** correctly optimizing out sorts.
68566 */
68567 case OP_SorterSort: /* jump */
68568 #ifdef SQLITE_OMIT_MERGE_SORT
68569 pOp->opcode = OP_Sort;
68570 #endif
68571 case OP_Sort: { /* jump */
68572 #ifdef SQLITE_TEST
68573 sqlite3_sort_count++;
68574 sqlite3_search_count--;
68575 #endif
@@ -68646,13 +68656,10 @@
68646 **
68647 ** If P5 is positive and the jump is taken, then event counter
68648 ** number P5-1 in the prepared statement is incremented.
68649 */
68650 case OP_SorterNext: /* jump */
68651 #ifdef SQLITE_OMIT_MERGE_SORT
68652 pOp->opcode = OP_Next;
68653 #endif
68654 case OP_Prev: /* jump */
68655 case OP_Next: { /* jump */
68656 #if 0 /* local variables moved into u.br */
68657 VdbeCursor *pC;
68658 int res;
@@ -68701,13 +68708,10 @@
68701 **
68702 ** This instruction only works for indices. The equivalent instruction
68703 ** for tables is OP_Insert.
68704 */
68705 case OP_SorterInsert: /* in2 */
68706 #ifdef SQLITE_OMIT_MERGE_SORT
68707 pOp->opcode = OP_IdxInsert;
68708 #endif
68709 case OP_IdxInsert: { /* in2 */
68710 #if 0 /* local variables moved into u.bs */
68711 VdbeCursor *pC;
68712 BtCursor *pCrsr;
68713 int nKey;
@@ -69972,11 +69976,11 @@
69972 importVtabErrMsg(p, u.cm.pVtab);
69973 if( SQLITE_OK==rc ){
69974 /* Initialize sqlite3_vtab_cursor base class */
69975 u.cm.pVtabCursor->pVtab = u.cm.pVtab;
69976
69977 /* Initialise vdbe cursor object */
69978 u.cm.pCur = allocateCursor(p, pOp->p1, 0, -1, 0);
69979 if( u.cm.pCur ){
69980 u.cm.pCur->pVtabCursor = u.cm.pVtabCursor;
69981 u.cm.pCur->pModule = u.cm.pVtabCursor->pVtab->pModule;
69982 }else{
@@ -70954,11 +70958,10 @@
70954 ** example, by CREATE INDEX statements on tables too large to fit in main
70955 ** memory).
70956 */
70957
70958
70959 #ifndef SQLITE_OMIT_MERGE_SORT
70960
70961 typedef struct VdbeSorterIter VdbeSorterIter;
70962 typedef struct SorterRecord SorterRecord;
70963 typedef struct FileWriter FileWriter;
70964
@@ -71974,12 +71977,10 @@
71974 pKey = vdbeSorterRowkey(pSorter, &nKey);
71975 vdbeSorterCompare(pCsr, 1, pVal->z, pVal->n, pKey, nKey, pRes);
71976 return SQLITE_OK;
71977 }
71978
71979 #endif /* #ifndef SQLITE_OMIT_MERGE_SORT */
71980
71981 /************** End of vdbesort.c ********************************************/
71982 /************** Begin file journal.c *****************************************/
71983 /*
71984 ** 2007 August 22
71985 **
@@ -77513,11 +77514,11 @@
77513 int regFree1 = 0;
77514 int regFree2 = 0;
77515 int r1, r2;
77516
77517 assert( jumpIfNull==SQLITE_JUMPIFNULL || jumpIfNull==0 );
77518 if( NEVER(v==0) ) return; /* Existance of VDBE checked by caller */
77519 if( NEVER(pExpr==0) ) return; /* No way this can happen */
77520 op = pExpr->op;
77521 switch( op ){
77522 case TK_AND: {
77523 int d2 = sqlite3VdbeMakeLabel(v);
@@ -77633,11 +77634,11 @@
77633 int regFree1 = 0;
77634 int regFree2 = 0;
77635 int r1, r2;
77636
77637 assert( jumpIfNull==SQLITE_JUMPIFNULL || jumpIfNull==0 );
77638 if( NEVER(v==0) ) return; /* Existance of VDBE checked by caller */
77639 if( pExpr==0 ) return;
77640
77641 /* The value of pExpr->op and op are related as follows:
77642 **
77643 ** pExpr->op op
@@ -80230,11 +80231,11 @@
80230 zErrDyn = sqlite3MPrintf(db, "database %s is already in use", zName);
80231 goto attach_error;
80232 }
80233 }
80234
80235 /* Allocate the new entry in the db->aDb[] array and initialise the schema
80236 ** hash tables.
80237 */
80238 if( db->aDb==db->aDbStatic ){
80239 aNew = sqlite3DbMallocRaw(db, sizeof(db->aDb[0])*3 );
80240 if( aNew==0 ) return;
@@ -80247,11 +80248,11 @@
80247 aNew = &db->aDb[db->nDb];
80248 memset(aNew, 0, sizeof(*aNew));
80249
80250 /* Open the database file. If the btree is successfully opened, use
80251 ** it to obtain the database schema. At this point the schema may
80252 ** or may not be initialised.
80253 */
80254 flags = db->openFlags;
80255 rc = sqlite3ParseUri(db->pVfs->zName, zFile, &flags, &pVfs, &zPath, &zErr);
80256 if( rc!=SQLITE_OK ){
80257 if( rc==SQLITE_NOMEM ) db->mallocFailed = 1;
@@ -83033,11 +83034,11 @@
83033 #endif
83034
83035 /* Drop all SQLITE_MASTER table and index entries that refer to the
83036 ** table. The program name loops through the master table and deletes
83037 ** every row that refers to a table of the same name as the one being
83038 ** dropped. Triggers are handled seperately because a trigger can be
83039 ** created in the temp database that refers to a table in another
83040 ** database.
83041 */
83042 sqlite3NestedParse(pParse,
83043 "DELETE FROM %Q.%s WHERE tbl_name=%Q and type!='trigger'",
@@ -83325,13 +83326,10 @@
83325 int addr1; /* Address of top of loop */
83326 int addr2; /* Address to jump to for next iteration */
83327 int tnum; /* Root page of index */
83328 Vdbe *v; /* Generate code into this virtual machine */
83329 KeyInfo *pKey; /* KeyInfo for index */
83330 #ifdef SQLITE_OMIT_MERGE_SORT
83331 int regIdxKey; /* Registers containing the index key */
83332 #endif
83333 int regRecord; /* Register holding assemblied index record */
83334 sqlite3 *db = pParse->db; /* The database connection */
83335 int iDb = sqlite3SchemaToIndex(db, pIndex->pSchema);
83336
83337 #ifndef SQLITE_OMIT_AUTHORIZATION
@@ -83355,25 +83353,20 @@
83355 pKey = sqlite3IndexKeyinfo(pParse, pIndex);
83356 sqlite3VdbeAddOp4(v, OP_OpenWrite, iIdx, tnum, iDb,
83357 (char *)pKey, P4_KEYINFO_HANDOFF);
83358 sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR|((memRootPage>=0)?OPFLAG_P2ISREG:0));
83359
83360 #ifndef SQLITE_OMIT_MERGE_SORT
83361 /* Open the sorter cursor if we are to use one. */
83362 iSorter = pParse->nTab++;
83363 sqlite3VdbeAddOp4(v, OP_SorterOpen, iSorter, 0, 0, (char*)pKey, P4_KEYINFO);
83364 #else
83365 iSorter = iTab;
83366 #endif
83367
83368 /* Open the table. Loop through all rows of the table, inserting index
83369 ** records into the sorter. */
83370 sqlite3OpenTable(pParse, iTab, iDb, pTab, OP_OpenRead);
83371 addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iTab, 0);
83372 regRecord = sqlite3GetTempReg(pParse);
83373
83374 #ifndef SQLITE_OMIT_MERGE_SORT
83375 sqlite3GenerateIndexKey(pParse, pIndex, iTab, regRecord, 1);
83376 sqlite3VdbeAddOp2(v, OP_SorterInsert, iSorter, regRecord);
83377 sqlite3VdbeAddOp2(v, OP_Next, iTab, addr1+1);
83378 sqlite3VdbeJumpHere(v, addr1);
83379 addr1 = sqlite3VdbeAddOp2(v, OP_SorterSort, iSorter, 0);
@@ -83389,34 +83382,10 @@
83389 addr2 = sqlite3VdbeCurrentAddr(v);
83390 }
83391 sqlite3VdbeAddOp2(v, OP_SorterData, iSorter, regRecord);
83392 sqlite3VdbeAddOp3(v, OP_IdxInsert, iIdx, regRecord, 1);
83393 sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
83394 #else
83395 regIdxKey = sqlite3GenerateIndexKey(pParse, pIndex, iTab, regRecord, 1);
83396 addr2 = addr1 + 1;
83397 if( pIndex->onError!=OE_None ){
83398 const int regRowid = regIdxKey + pIndex->nColumn;
83399 const int j2 = sqlite3VdbeCurrentAddr(v) + 2;
83400 void * const pRegKey = SQLITE_INT_TO_PTR(regIdxKey);
83401
83402 /* The registers accessed by the OP_IsUnique opcode were allocated
83403 ** using sqlite3GetTempRange() inside of the sqlite3GenerateIndexKey()
83404 ** call above. Just before that function was freed they were released
83405 ** (made available to the compiler for reuse) using
83406 ** sqlite3ReleaseTempRange(). So in some ways having the OP_IsUnique
83407 ** opcode use the values stored within seems dangerous. However, since
83408 ** we can be sure that no other temp registers have been allocated
83409 ** since sqlite3ReleaseTempRange() was called, it is safe to do so.
83410 */
83411 sqlite3VdbeAddOp4(v, OP_IsUnique, iIdx, j2, regRowid, pRegKey, P4_INT32);
83412 sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_UNIQUE,
83413 "indexed columns are not unique", P4_STATIC);
83414 }
83415 sqlite3VdbeAddOp3(v, OP_IdxInsert, iIdx, regRecord, 0);
83416 sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
83417 #endif
83418 sqlite3ReleaseTempReg(pParse, regRecord);
83419 sqlite3VdbeAddOp2(v, OP_SorterNext, iSorter, addr2);
83420 sqlite3VdbeJumpHere(v, addr1);
83421
83422 sqlite3VdbeAddOp1(v, OP_Close, iTab);
@@ -83772,11 +83741,11 @@
83772 /* This constraint creates the same index as a previous
83773 ** constraint specified somewhere in the CREATE TABLE statement.
83774 ** However the ON CONFLICT clauses are different. If both this
83775 ** constraint and the previous equivalent constraint have explicit
83776 ** ON CONFLICT clauses this is an error. Otherwise, use the
83777 ** explicitly specified behaviour for the index.
83778 */
83779 if( !(pIdx->onError==OE_Default || pIndex->onError==OE_Default) ){
83780 sqlite3ErrorMsg(pParse,
83781 "conflicting ON CONFLICT clauses specified", 0);
83782 }
@@ -94054,11 +94023,11 @@
94054 assert( sqlite3_mutex_held(db->mutex) );
94055 assert( iDb==1 || sqlite3BtreeHoldsMutex(db->aDb[iDb].pBt) );
94056
94057 /* zMasterSchema and zInitScript are set to point at the master schema
94058 ** and initialisation script appropriate for the database being
94059 ** initialised. zMasterName is the name of the master table.
94060 */
94061 if( !OMIT_TEMPDB && iDb==1 ){
94062 zMasterSchema = temp_master_schema;
94063 }else{
94064 zMasterSchema = master_schema;
@@ -94279,11 +94248,11 @@
94279 if( rc ){
94280 sqlite3ResetOneSchema(db, i);
94281 }
94282 }
94283
94284 /* Once all the other databases have been initialised, load the schema
94285 ** for the TEMP database. This is loaded last, as the TEMP database
94286 ** schema may contain references to objects in other databases.
94287 */
94288 #ifndef SQLITE_OMIT_TEMPDB
94289 if( rc==SQLITE_OK && ALWAYS(db->nDb>1)
@@ -94302,11 +94271,11 @@
94302
94303 return rc;
94304 }
94305
94306 /*
94307 ** This routine is a no-op if the database schema is already initialised.
94308 ** Otherwise, the schema is loaded. An error code is returned.
94309 */
94310 SQLITE_PRIVATE int sqlite3ReadSchema(Parse *pParse){
94311 int rc = SQLITE_OK;
94312 sqlite3 *db = pParse->db;
@@ -99315,11 +99284,11 @@
99315 ** first iteration (since the first iteration of the loop is
99316 ** guaranteed to operate on the row with the minimum or maximum
99317 ** value of x, the only row required).
99318 **
99319 ** A special flag must be passed to sqlite3WhereBegin() to slightly
99320 ** modify behaviour as follows:
99321 **
99322 ** + If the query is a "SELECT min(x)", then the loop coded by
99323 ** where.c should not iterate over any values with a NULL value
99324 ** for x.
99325 **
@@ -101308,11 +101277,11 @@
101308 sqlite3CodeRowTrigger(pParse, pTrigger, TK_UPDATE, pChanges,
101309 TRIGGER_BEFORE, pTab, regOldRowid, onError, addr);
101310
101311 /* The row-trigger may have deleted the row being updated. In this
101312 ** case, jump to the next row. No updates or AFTER triggers are
101313 ** required. This behaviour - what happens when the row being updated
101314 ** is deleted or renamed by a BEFORE trigger - is left undefined in the
101315 ** documentation.
101316 */
101317 sqlite3VdbeAddOp3(v, OP_NotExists, iCur, addr, regOldRowid);
101318
@@ -103237,10 +103206,12 @@
103237 #define WHERE_IDX_ONLY 0x00400000 /* Use index only - omit table */
103238 #define WHERE_ORDERED 0x00800000 /* Output will appear in correct order */
103239 #define WHERE_REVERSE 0x01000000 /* Scan in reverse order */
103240 #define WHERE_UNIQUE 0x02000000 /* Selects no more than one row */
103241 #define WHERE_ALL_UNIQUE 0x04000000 /* This and all prior have one row */
 
 
103242 #define WHERE_VIRTUALTABLE 0x08000000 /* Use virtual-table processing */
103243 #define WHERE_MULTI_OR 0x10000000 /* OR using multiple indices */
103244 #define WHERE_TEMP_INDEX 0x20000000 /* Uses an ephemeral index */
103245 #define WHERE_DISTINCT 0x40000000 /* Correct order for DISTINCT */
103246 #define WHERE_COVER_SCAN 0x80000000 /* Full scan of a covering index */
@@ -103537,11 +103508,11 @@
103537
103538 /*
103539 ** Commute a comparison operator. Expressions of the form "X op Y"
103540 ** are converted into "Y op X".
103541 **
103542 ** If left/right precendence rules come into play when determining the
103543 ** collating
103544 ** side of the comparison, it remains associated with the same side after
103545 ** the commutation. So "Y collate NOCASE op X" becomes
103546 ** "X op Y". This is because any collation sequence on
103547 ** the left hand side of a comparison overrides any collation sequence
@@ -105878,11 +105849,12 @@
105878 */
105879 static int isSortingIndex(
105880 WhereBestIdx *p, /* Best index search context */
105881 Index *pIdx, /* The index we are testing */
105882 int base, /* Cursor number for the table to be sorted */
105883 int *pbRev /* Set to 1 for reverse-order scan of pIdx */
 
105884 ){
105885 int i; /* Number of pIdx terms used */
105886 int j; /* Number of ORDER BY terms satisfied */
105887 int sortOrder = 2; /* 0: forward. 1: backward. 2: unknown */
105888 int nTerm; /* Number of ORDER BY terms */
@@ -105892,25 +105864,32 @@
105892 Parse *pParse = p->pParse; /* Parser context */
105893 sqlite3 *db = pParse->db; /* Database connection */
105894 int nPriorSat; /* ORDER BY terms satisfied by outer loops */
105895 int seenRowid = 0; /* True if an ORDER BY rowid term is seen */
105896 int uniqueNotNull; /* pIdx is UNIQUE with all terms are NOT NULL */
 
 
105897
105898 if( p->i==0 ){
105899 nPriorSat = 0;
 
105900 }else{
 
105901 nPriorSat = p->aLevel[p->i-1].plan.nOBSat;
105902 if( (p->aLevel[p->i-1].plan.wsFlags & WHERE_ORDERED)==0 ){
105903 /* This loop cannot be ordered unless the next outer loop is
105904 ** also ordered */
105905 return nPriorSat;
105906 }
105907 if( OptimizationDisabled(db, SQLITE_OrderByIdxJoin) ){
105908 /* Only look at the outer-most loop if the OrderByIdxJoin
105909 ** optimization is disabled */
105910 return nPriorSat;
105911 }
 
 
 
105912 }
105913 pOrderBy = p->pOrderBy;
105914 assert( pOrderBy!=0 );
105915 if( pIdx->bUnordered ){
105916 /* Hash indices (indicated by the "unordered" tag on sqlite_stat1) cannot
@@ -106048,23 +106027,38 @@
106048 testcase( isEq==2 );
106049 testcase( isEq==3 );
106050 uniqueNotNull = 0;
106051 }
106052 }
 
 
 
 
 
106053
106054 /* If we have not found at least one ORDER BY term that matches the
106055 ** index, then show no progress. */
106056 if( pOBItem==&pOrderBy->a[nPriorSat] ) return nPriorSat;
 
 
 
 
 
 
 
 
 
 
106057
106058 /* Return the necessary scan order back to the caller */
106059 *pbRev = sortOrder & 1;
106060
106061 /* If there was an "ORDER BY rowid" term that matched, or it is only
106062 ** possible for a single row from this table to match, then skip over
106063 ** any additional ORDER BY terms dealing with this table.
106064 */
106065 if( seenRowid || (uniqueNotNull && i>=pIdx->nColumn) ){
106066 /* Advance j over additional ORDER BY terms associated with base */
106067 WhereMaskSet *pMS = p->pWC->pMaskSet;
106068 Bitmask m = ~getMask(pMS, base);
106069 while( j<nTerm && (exprTableUsage(pMS, pOrderBy->a[j].pExpr)&m)==0 ){
106070 j++;
@@ -106344,16 +106338,18 @@
106344 ** in pc.plan.wsFlags. Otherwise, if there is an ORDER BY clause but
106345 ** the index will scan rows in a different order, set the bSort
106346 ** variable. */
106347 if( bSort && (pSrc->jointype & JT_LEFT)==0 ){
106348 int bRev = 2;
106349 WHERETRACE((" --> before isSortingIndex: nPriorSat=%d\n",nPriorSat));
106350 pc.plan.nOBSat = isSortingIndex(p, pProbe, iCur, &bRev);
106351 WHERETRACE((" --> after isSortingIndex: bRev=%d nOBSat=%d\n",
106352 bRev, pc.plan.nOBSat));
 
106353 if( nPriorSat<pc.plan.nOBSat || (pc.plan.wsFlags & WHERE_ALL_UNIQUE)!=0 ){
106354 pc.plan.wsFlags |= WHERE_ORDERED;
 
106355 }
106356 if( nOrderBy==pc.plan.nOBSat ){
106357 bSort = 0;
106358 pc.plan.wsFlags |= WHERE_ROWID_RANGE|WHERE_COLUMN_RANGE;
106359 }
@@ -106443,11 +106439,12 @@
106443 ** The ANALYZE command and the sqlite_stat1 and sqlite_stat3 tables do
106444 ** not give us data on the relative sizes of table and index records.
106445 ** So this computation assumes table records are about twice as big
106446 ** as index records
106447 */
106448 if( (pc.plan.wsFlags&~(WHERE_REVERSE|WHERE_ORDERED))==WHERE_IDX_ONLY
 
106449 && (pWC->wctrlFlags & WHERE_ONEPASS_DESIRED)==0
106450 && sqlite3GlobalConfig.bUseCis
106451 && OptimizationEnabled(pParse->db, SQLITE_CoverIdxScan)
106452 ){
106453 /* This index is not useful for indexing, but it is a covering index.
@@ -106603,11 +106600,11 @@
106603 }
106604
106605 /* If there is no ORDER BY clause and the SQLITE_ReverseOrder flag
106606 ** is set, then reverse the order that the index will be scanned
106607 ** in. This is used for application testing, to help find cases
106608 ** where application behaviour depends on the (undefined) order that
106609 ** SQLite outputs rows in in the absence of an ORDER BY clause. */
106610 if( !p->pOrderBy && pParse->db->flags & SQLITE_ReverseOrder ){
106611 p->cost.plan.wsFlags |= WHERE_REVERSE;
106612 }
106613
@@ -114198,11 +114195,11 @@
114198 return;
114199 }
114200
114201 /* If we reach this point, it means that the database connection has
114202 ** closed all sqlite3_stmt and sqlite3_backup objects and has been
114203 ** pased to sqlite3_close (meaning that it is a zombie). Therefore,
114204 ** go ahead and free all resources.
114205 */
114206
114207 /* Free any outstanding Savepoint structures. */
114208 sqlite3CloseSavepoints(db);
@@ -117250,11 +117247,11 @@
117250 ** to the strings "arg1" and "arg2".
117251 **
117252 ** This method should return either SQLITE_OK (0), or an SQLite error
117253 ** code. If SQLITE_OK is returned, then *ppTokenizer should be set
117254 ** to point at the newly created tokenizer structure. The generic
117255 ** sqlite3_tokenizer.pModule variable should not be initialised by
117256 ** this callback. The caller will do so.
117257 */
117258 int (*xCreate)(
117259 int argc, /* Size of argv array */
117260 const char *const*argv, /* Tokenizer argument strings */
@@ -117355,11 +117352,11 @@
117355 ** May you do good and not evil.
117356 ** May you find forgiveness for yourself and forgive others.
117357 ** May you share freely, never taking more than you give.
117358 **
117359 *************************************************************************
117360 ** This is the header file for the generic hash-table implemenation
117361 ** used in SQLite. We've modified it slightly to serve as a standalone
117362 ** hash table implementation for the full-text indexing module.
117363 **
117364 */
117365 #ifndef _FTS3_HASH_H_
@@ -119262,11 +119259,11 @@
119262 if( SQLITE_ROW==sqlite3_step(pCsr->pStmt) ){
119263 return SQLITE_OK;
119264 }else{
119265 rc = sqlite3_reset(pCsr->pStmt);
119266 if( rc==SQLITE_OK && ((Fts3Table *)pCsr->base.pVtab)->zContentTbl==0 ){
119267 /* If no row was found and no error has occured, then the %_content
119268 ** table is missing a row that is present in the full-text index.
119269 ** The data structures are corrupt. */
119270 rc = FTS_CORRUPT_VTAB;
119271 pCsr->isEof = 1;
119272 }
@@ -120502,11 +120499,11 @@
120502 sqlite3Fts3SegReaderFinish(pSegcsr);
120503 sqlite3_free(pSegcsr);
120504 }
120505
120506 /*
120507 ** This function retreives the doclist for the specified term (or term
120508 ** prefix) from the database.
120509 */
120510 static int fts3TermSelect(
120511 Fts3Table *p, /* Virtual table handle */
120512 Fts3PhraseToken *pTok, /* Token to query for */
@@ -121253,11 +121250,11 @@
121253 #ifdef SQLITE_ENABLE_ICU
121254 SQLITE_PRIVATE void sqlite3Fts3IcuTokenizerModule(sqlite3_tokenizer_module const**ppModule);
121255 #endif
121256
121257 /*
121258 ** Initialise the fts3 extension. If this extension is built as part
121259 ** of the sqlite library, then this function is called directly by
121260 ** SQLite. If fts3 is built as a dynamically loadable extension, this
121261 ** function is called by the sqlite3_extension_init() entry point.
121262 */
121263 SQLITE_PRIVATE int sqlite3Fts3Init(sqlite3 *db){
@@ -121287,11 +121284,11 @@
121287 if( rc!=SQLITE_OK ) return rc;
121288
121289 sqlite3Fts3SimpleTokenizerModule(&pSimple);
121290 sqlite3Fts3PorterTokenizerModule(&pPorter);
121291
121292 /* Allocate and initialise the hash-table used to store tokenizers. */
121293 pHash = sqlite3_malloc(sizeof(Fts3Hash));
121294 if( !pHash ){
121295 rc = SQLITE_NOMEM;
121296 }else{
121297 sqlite3Fts3HashInit(pHash, FTS3_HASH_STRING, 1);
@@ -122886,11 +122883,11 @@
122886 ** The returned value is either NULL or a pointer to a buffer containing
122887 ** a position-list indicating the occurrences of the phrase in column iCol
122888 ** of the current row.
122889 **
122890 ** More specifically, the returned buffer contains 1 varint for each
122891 ** occurence of the phrase in the column, stored using the normal (delta+2)
122892 ** compression and is terminated by either an 0x01 or 0x00 byte. For example,
122893 ** if the requested column contains "a b X c d X X" and the position-list
122894 ** for 'X' is requested, the buffer returned may contain:
122895 **
122896 ** 0x04 0x05 0x03 0x01 or 0x04 0x05 0x03 0x00
@@ -123625,11 +123622,11 @@
123625
123626 /*
123627 ** This function is equivalent to the standard isspace() function.
123628 **
123629 ** The standard isspace() can be awkward to use safely, because although it
123630 ** is defined to accept an argument of type int, its behaviour when passed
123631 ** an integer that falls outside of the range of the unsigned char type
123632 ** is undefined (and sometimes, "undefined" means segfault). This wrapper
123633 ** is defined to accept an argument of type char, and always returns 0 for
123634 ** any values that fall outside of the range of the unsigned char type (i.e.
123635 ** negative values).
@@ -125993,11 +125990,11 @@
125993 #endif
125994
125995 /*
125996 ** Set up SQL objects in database db used to access the contents of
125997 ** the hash table pointed to by argument pHash. The hash table must
125998 ** been initialised to use string keys, and to take a private copy
125999 ** of the key when a value is inserted. i.e. by a call similar to:
126000 **
126001 ** sqlite3Fts3HashInit(pHash, FTS3_HASH_STRING, 1);
126002 **
126003 ** This function adds a scalar function (see header comment above
@@ -127772,10 +127769,11 @@
127772 if( ppOffsetList ){
127773 *ppOffsetList = pReader->pOffsetList;
127774 *pnOffsetList = (int)(p - pReader->pOffsetList - 1);
127775 }
127776
 
127777 while( p<pEnd && *p==0 ) p++;
127778
127779 /* If there are no more entries in the doclist, set pOffsetList to
127780 ** NULL. Otherwise, set Fts3SegReader.iDocid to the next docid and
127781 ** Fts3SegReader.pOffsetList to point to the next offset list before
@@ -128787,13 +128785,17 @@
128787 ** function adjusts the pointer *ppList and the length *pnList so that they
128788 ** identify the subset of the position list that corresponds to column iCol.
128789 **
128790 ** If there are no entries in the input position list for column iCol, then
128791 ** *pnList is set to zero before returning.
 
 
 
128792 */
128793 static void fts3ColumnFilter(
128794 int iCol, /* Column to filter on */
 
128795 char **ppList, /* IN/OUT: Pointer to position list */
128796 int *pnList /* IN/OUT: Size of buffer *ppList in bytes */
128797 ){
128798 char *pList = *ppList;
128799 int nList = *pnList;
@@ -128818,10 +128820,13 @@
128818 }
128819 p = &pList[1];
128820 p += sqlite3Fts3GetVarint32(p, &iCurrent);
128821 }
128822
 
 
 
128823 *ppList = pList;
128824 *pnList = nList;
128825 }
128826
128827 /*
@@ -128890,24 +128895,24 @@
128890 rc = fts3SegReaderNextDocid(p, apSegment[j], 0, 0);
128891 j++;
128892 }
128893 if( rc!=SQLITE_OK ) return rc;
128894 fts3SegReaderSort(pMsr->apSegment, nMerge, j, xCmp);
 
 
 
 
 
 
 
128895
128896 if( pMsr->iColFilter>=0 ){
128897 fts3ColumnFilter(pMsr->iColFilter, &pList, &nList);
128898 }
128899
128900 if( nList>0 ){
128901 if( fts3SegReaderIsPending(apSegment[0]) ){
128902 rc = fts3MsrBufferData(pMsr, pList, nList+1);
128903 if( rc!=SQLITE_OK ) return rc;
128904 *paPoslist = pMsr->aBuffer;
128905 assert( (pMsr->aBuffer[nList] & 0xFE)==0x00 );
128906 }else{
128907 *paPoslist = pList;
128908 }
128909 *piDocid = iDocid;
128910 *pnPoslist = nList;
128911 break;
128912 }
128913 }
@@ -129146,11 +129151,11 @@
129146 fts3SegReaderNextDocid(p, apSegment[j], 0, 0);
129147 j++;
129148 }
129149
129150 if( isColFilter ){
129151 fts3ColumnFilter(pFilter->iCol, &pList, &nList);
129152 }
129153
129154 if( !isIgnoreEmpty || nList>0 ){
129155
129156 /* Calculate the 'docid' delta value to write into the merged
@@ -132083,13 +132088,13 @@
132083 ** Select the fragment of text consisting of nFragment contiguous tokens
132084 ** from column iCol that represent the "best" snippet. The best snippet
132085 ** is the snippet with the highest score, where scores are calculated
132086 ** by adding:
132087 **
132088 ** (a) +1 point for each occurence of a matchable phrase in the snippet.
132089 **
132090 ** (b) +1000 points for the first occurence of each matchable phrase in
132091 ** the snippet for which the corresponding mCovered bit is not set.
132092 **
132093 ** The selected snippet parameters are stored in structure *pFragment before
132094 ** returning. The score of the selected snippet is stored in *piScore
132095 ** before returning.
@@ -133340,11 +133345,11 @@
133340 ** the return value of sqlite3FtsUnicodeIsalnum() is inverted for all
133341 ** codepoints in the aiException[] array.
133342 **
133343 ** If a standalone diacritic mark (one that sqlite3FtsUnicodeIsdiacritic()
133344 ** identifies as a diacritic) occurs in the zIn/nIn string it is ignored.
133345 ** It is not possible to change the behaviour of the tokenizer with respect
133346 ** to these codepoints.
133347 */
133348 static int unicodeAddExceptions(
133349 unicode_tokenizer *p, /* Tokenizer to add exceptions to */
133350 int bAlnum, /* Replace Isalnum() return value with this */
@@ -136643,11 +136648,11 @@
136643 RtreeNode *pLeaf = 0; /* Leaf node containing record iDelete */
136644 int iCell; /* Index of iDelete cell in pLeaf */
136645 RtreeNode *pRoot; /* Root node of rtree structure */
136646
136647
136648 /* Obtain a reference to the root node to initialise Rtree.iDepth */
136649 rc = nodeAcquire(pRtree, 1, 0, &pRoot);
136650
136651 /* Obtain a reference to the leaf node that contains the entry
136652 ** about to be deleted.
136653 */
136654
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.7.16.1. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a single translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% or more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -676,13 +676,13 @@
676 **
677 ** See also: [sqlite3_libversion()],
678 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
679 ** [sqlite_version()] and [sqlite_source_id()].
680 */
681 #define SQLITE_VERSION "3.7.16.1"
682 #define SQLITE_VERSION_NUMBER 3007016
683 #define SQLITE_SOURCE_ID "2013-03-27 20:41:15 274d2a22660c7b34b8bbd85f3c29cbafbcb1b4e7"
684
685 /*
686 ** CAPI3REF: Run-Time Library Version Numbers
687 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
688 **
@@ -3249,11 +3249,11 @@
3249 ** "private". ^Setting it to "shared" is equivalent to setting the
3250 ** SQLITE_OPEN_SHAREDCACHE bit in the flags argument passed to
3251 ** sqlite3_open_v2(). ^Setting the cache parameter to "private" is
3252 ** equivalent to setting the SQLITE_OPEN_PRIVATECACHE bit.
3253 ** ^If sqlite3_open_v2() is used and the "cache" parameter is present in
3254 ** a URI filename, its value overrides any behavior requested by setting
3255 ** SQLITE_OPEN_PRIVATECACHE or SQLITE_OPEN_SHAREDCACHE flag.
3256 ** </ul>
3257 **
3258 ** ^Specifying an unknown parameter in the query component of a URI is not an
3259 ** error. Future versions of SQLite might understand additional query
@@ -4567,11 +4567,12 @@
4567 SQLITE_API SQLITE_DEPRECATED int sqlite3_aggregate_count(sqlite3_context*);
4568 SQLITE_API SQLITE_DEPRECATED int sqlite3_expired(sqlite3_stmt*);
4569 SQLITE_API SQLITE_DEPRECATED int sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*);
4570 SQLITE_API SQLITE_DEPRECATED int sqlite3_global_recover(void);
4571 SQLITE_API SQLITE_DEPRECATED void sqlite3_thread_cleanup(void);
4572 SQLITE_API SQLITE_DEPRECATED int sqlite3_memory_alarm(void(*)(void*,sqlite3_int64,int),
4573 void*,sqlite3_int64);
4574 #endif
4575
4576 /*
4577 ** CAPI3REF: Obtaining SQL Function Parameter Values
4578 **
@@ -4647,18 +4648,21 @@
4648 ** an aggregate query, the xStep() callback of the aggregate function
4649 ** implementation is never called and xFinal() is called exactly once.
4650 ** In those cases, sqlite3_aggregate_context() might be called for the
4651 ** first time from within xFinal().)^
4652 **
4653 ** ^The sqlite3_aggregate_context(C,N) routine returns a NULL pointer
4654 ** when first called if N is less than or equal to zero or if a memory
4655 ** allocate error occurs.
4656 **
4657 ** ^(The amount of space allocated by sqlite3_aggregate_context(C,N) is
4658 ** determined by the N parameter on first successful call. Changing the
4659 ** value of N in subsequent call to sqlite3_aggregate_context() within
4660 ** the same aggregate function instance will not resize the memory
4661 ** allocation.)^ Within the xFinal callback, it is customary to set
4662 ** N=0 in calls to sqlite3_aggregate_context(C,N) so that no
4663 ** pointless memory allocations occur.
4664 **
4665 ** ^SQLite automatically frees the memory allocated by
4666 ** sqlite3_aggregate_context() when the aggregate query concludes.
4667 **
4668 ** The first parameter must be a copy of the
@@ -6948,11 +6952,11 @@
6952 ** intact. If the requested page is not already in the cache, then the
6953 ** cache implementation should use the value of the createFlag
6954 ** parameter to help it determined what action to take:
6955 **
6956 ** <table border=1 width=85% align=center>
6957 ** <tr><th> createFlag <th> Behavior when page is not already in cache
6958 ** <tr><td> 0 <td> Do not allocate a new page. Return NULL.
6959 ** <tr><td> 1 <td> Allocate a new page if it easy and convenient to do so.
6960 ** Otherwise return NULL.
6961 ** <tr><td> 2 <td> Make every effort to allocate a new page. Only return
6962 ** NULL if allocating a new page is effectively impossible.
@@ -7753,11 +7757,11 @@
7757 ** May you do good and not evil.
7758 ** May you find forgiveness for yourself and forgive others.
7759 ** May you share freely, never taking more than you give.
7760 **
7761 *************************************************************************
7762 ** This is the header file for the generic hash-table implementation
7763 ** used in SQLite.
7764 */
7765 #ifndef _SQLITE_HASH_H_
7766 #define _SQLITE_HASH_H_
7767
@@ -12943,13 +12947,10 @@
12947 "OMIT_LOOKASIDE",
12948 #endif
12949 #ifdef SQLITE_OMIT_MEMORYDB
12950 "OMIT_MEMORYDB",
12951 #endif
 
 
 
12952 #ifdef SQLITE_OMIT_OR_OPTIMIZATION
12953 "OMIT_OR_OPTIMIZATION",
12954 #endif
12955 #ifdef SQLITE_OMIT_PAGER_PRAGMAS
12956 "OMIT_PAGER_PRAGMAS",
@@ -13534,27 +13535,17 @@
13535 SQLITE_PRIVATE void sqlite3VdbeFrameDelete(VdbeFrame*);
13536 SQLITE_PRIVATE int sqlite3VdbeFrameRestore(VdbeFrame *);
13537 SQLITE_PRIVATE void sqlite3VdbeMemStoreType(Mem *pMem);
13538 SQLITE_PRIVATE int sqlite3VdbeTransferError(Vdbe *p);
13539
 
 
 
 
 
 
 
 
 
13540 SQLITE_PRIVATE int sqlite3VdbeSorterInit(sqlite3 *, VdbeCursor *);
13541 SQLITE_PRIVATE void sqlite3VdbeSorterClose(sqlite3 *, VdbeCursor *);
13542 SQLITE_PRIVATE int sqlite3VdbeSorterRowkey(const VdbeCursor *, Mem *);
13543 SQLITE_PRIVATE int sqlite3VdbeSorterNext(sqlite3 *, const VdbeCursor *, int *);
13544 SQLITE_PRIVATE int sqlite3VdbeSorterRewind(sqlite3 *, const VdbeCursor *, int *);
13545 SQLITE_PRIVATE int sqlite3VdbeSorterWrite(sqlite3 *, const VdbeCursor *, Mem *);
13546 SQLITE_PRIVATE int sqlite3VdbeSorterCompare(const VdbeCursor *, Mem *, int *);
 
13547
13548 #if !defined(SQLITE_OMIT_SHARED_CACHE) && SQLITE_THREADSAFE>0
13549 SQLITE_PRIVATE void sqlite3VdbeEnter(Vdbe*);
13550 SQLITE_PRIVATE void sqlite3VdbeLeave(Vdbe*);
13551 #else
@@ -21334,11 +21325,11 @@
21325 ** returns FALSE but it still converts the prefix and writes the result
21326 ** into *pResult.
21327 */
21328 SQLITE_PRIVATE int sqlite3AtoF(const char *z, double *pResult, int length, u8 enc){
21329 #ifndef SQLITE_OMIT_FLOATING_POINT
21330 int incr;
21331 const char *zEnd = z + length;
21332 /* sign * significand * (10 ^ (esign * exponent)) */
21333 int sign = 1; /* sign of significand */
21334 i64 s = 0; /* significand */
21335 int d = 0; /* adjust exponent for shifting decimal point */
@@ -21345,14 +21336,26 @@
21336 int esign = 1; /* sign of exponent */
21337 int e = 0; /* exponent */
21338 int eValid = 1; /* True exponent is either not used or is well-formed */
21339 double result;
21340 int nDigits = 0;
21341 int nonNum = 0;
21342
21343 assert( enc==SQLITE_UTF8 || enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE );
21344 *pResult = 0.0; /* Default return value, in case of an error */
21345
21346 if( enc==SQLITE_UTF8 ){
21347 incr = 1;
21348 }else{
21349 int i;
21350 incr = 2;
21351 assert( SQLITE_UTF16LE==2 && SQLITE_UTF16BE==3 );
21352 for(i=3-enc; i<length && z[i]==0; i+=2){}
21353 nonNum = i<length;
21354 zEnd = z+i+enc-3;
21355 z += (enc&1);
21356 }
21357
21358 /* skip leading spaces */
21359 while( z<zEnd && sqlite3Isspace(*z) ) z+=incr;
21360 if( z>=zEnd ) return 0;
21361
@@ -21481,11 +21484,11 @@
21484
21485 /* store the result */
21486 *pResult = result;
21487
21488 /* return true if number and no extra non-whitespace chracters after */
21489 return z>=zEnd && nDigits>0 && eValid && nonNum==0;
21490 #else
21491 return !sqlite3Atoi64(z, pResult, length, enc);
21492 #endif /* SQLITE_OMIT_FLOATING_POINT */
21493 }
21494
@@ -21530,25 +21533,37 @@
21533 ** If zNum is exactly 9223372036854665808, return 2. This special
21534 ** case is broken out because while 9223372036854665808 cannot be a
21535 ** signed 64-bit integer, its negative -9223372036854665808 can be.
21536 **
21537 ** If zNum is too big for a 64-bit integer and is not
21538 ** 9223372036854665808 or if zNum contains any non-numeric text,
21539 ** then return 1.
21540 **
21541 ** length is the number of bytes in the string (bytes, not characters).
21542 ** The string is not necessarily zero-terminated. The encoding is
21543 ** given by enc.
21544 */
21545 SQLITE_PRIVATE int sqlite3Atoi64(const char *zNum, i64 *pNum, int length, u8 enc){
21546 int incr;
21547 u64 u = 0;
21548 int neg = 0; /* assume positive */
21549 int i;
21550 int c = 0;
21551 int nonNum = 0;
21552 const char *zStart;
21553 const char *zEnd = zNum + length;
21554 assert( enc==SQLITE_UTF8 || enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE );
21555 if( enc==SQLITE_UTF8 ){
21556 incr = 1;
21557 }else{
21558 incr = 2;
21559 assert( SQLITE_UTF16LE==2 && SQLITE_UTF16BE==3 );
21560 for(i=3-enc; i<length && zNum[i]==0; i+=2){}
21561 nonNum = i<length;
21562 zEnd = zNum+i+enc-3;
21563 zNum += (enc&1);
21564 }
21565 while( zNum<zEnd && sqlite3Isspace(*zNum) ) zNum+=incr;
21566 if( zNum<zEnd ){
21567 if( *zNum=='-' ){
21568 neg = 1;
21569 zNum+=incr;
@@ -21569,11 +21584,11 @@
21584 *pNum = (i64)u;
21585 }
21586 testcase( i==18 );
21587 testcase( i==19 );
21588 testcase( i==20 );
21589 if( (c+nonNum!=0 && &zNum[i]<zEnd) || (i==0 && zStart==zNum) || i>19*incr ){
21590 /* zNum is empty or contains non-numeric text or is longer
21591 ** than 19 digits (thus guaranteeing that it is too large) */
21592 return 1;
21593 }else if( i<19*incr ){
21594 /* Less than 19 digits, so we know that it fits in 64 bits */
@@ -23250,11 +23265,11 @@
23265 ** they may be overridden at runtime to facilitate fault injection during
23266 ** testing and sandboxing. The following array holds the names and pointers
23267 ** to all overrideable system calls.
23268 */
23269 static struct unix_syscall {
23270 const char *zName; /* Name of the system call */
23271 sqlite3_syscall_ptr pCurrent; /* Current value of the system call */
23272 sqlite3_syscall_ptr pDefault; /* Default value */
23273 } aSyscall[] = {
23274 { "open", (sqlite3_syscall_ptr)posixOpen, 0 },
23275 #define osOpen ((int(*)(const char*,int,int))aSyscall[0].pCurrent)
@@ -24822,11 +24837,11 @@
24837 ******************************************************************************/
24838
24839 /******************************************************************************
24840 ************************* Begin dot-file Locking ******************************
24841 **
24842 ** The dotfile locking implementation uses the existence of separate lock
24843 ** files (really a directory) to control access to the database. This works
24844 ** on just about every filesystem imaginable. But there are serious downsides:
24845 **
24846 ** (1) There is zero concurrency. A single reader blocks all other
24847 ** connections from reading or writing the database.
@@ -24837,11 +24852,11 @@
24852 ** Nevertheless, a dotlock is an appropriate locking mode for use if no
24853 ** other locking strategy is available.
24854 **
24855 ** Dotfile locking works by creating a subdirectory in the same directory as
24856 ** the database and with the same name but with a ".lock" extension added.
24857 ** The existence of a lock directory implies an EXCLUSIVE lock. All other
24858 ** lock types (SHARED, RESERVED, PENDING) are mapped into EXCLUSIVE.
24859 */
24860
24861 /*
24862 ** The file suffix added to the data base filename in order to create the
@@ -26326,11 +26341,11 @@
26341 pFile->lastErrno = errno;
26342 return unixLogError(SQLITE_IOERR_FSYNC, "full_fsync", pFile->zPath);
26343 }
26344
26345 /* Also fsync the directory containing the file if the DIRSYNC flag
26346 ** is set. This is a one-time occurrence. Many systems (examples: AIX)
26347 ** are unable to fsync a directory, so ignore errors on the fsync.
26348 */
26349 if( pFile->ctrlFlags & UNIXFILE_DIRSYNC ){
26350 int dirfd;
26351 OSTRACE(("DIRSYNC %s (have_fullfsync=%d fullsync=%d)\n", pFile->zPath,
@@ -27700,11 +27715,11 @@
27715 #endif
27716 ){
27717 unixEnterMutex();
27718 rc = findInodeInfo(pNew, &pNew->pInode);
27719 if( rc!=SQLITE_OK ){
27720 /* If an error occurred in findInodeInfo(), close the file descriptor
27721 ** immediately, before releasing the mutex. findInodeInfo() may fail
27722 ** in two scenarios:
27723 **
27724 ** (a) A call to fstat() failed.
27725 ** (b) A malloc failed.
@@ -28338,11 +28353,11 @@
28353 #endif
28354 return rc;
28355 }
28356
28357 /*
28358 ** Test the existence of or access permissions of file zPath. The
28359 ** test performed depends on the value of flags:
28360 **
28361 ** SQLITE_ACCESS_EXISTS: Return 1 if the file exists
28362 ** SQLITE_ACCESS_READWRITE: Return 1 if the file is read and writable.
28363 ** SQLITE_ACCESS_READONLY: Return 1 if the file is readable.
@@ -30442,11 +30457,11 @@
30457 ** they may be overridden at runtime to facilitate fault injection during
30458 ** testing and sandboxing. The following array holds the names and pointers
30459 ** to all overrideable system calls.
30460 */
30461 static struct win_syscall {
30462 const char *zName; /* Name of the system call */
30463 sqlite3_syscall_ptr pCurrent; /* Current value of the system call */
30464 sqlite3_syscall_ptr pDefault; /* Default value */
30465 } aSyscall[] = {
30466 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT
30467 { "AreFileApisANSI", (SYSCALL)AreFileApisANSI, 0 },
@@ -32159,11 +32174,11 @@
32174
32175 /* API oddity: If successful, SetFilePointer() returns a dword
32176 ** containing the lower 32-bits of the new file-offset. Or, if it fails,
32177 ** it returns INVALID_SET_FILE_POINTER. However according to MSDN,
32178 ** INVALID_SET_FILE_POINTER may also be a valid new offset. So to determine
32179 ** whether an error has actually occurred, it is also necessary to call
32180 ** GetLastError().
32181 */
32182 dwRet = osSetFilePointer(pFile->h, lowerBits, &upperBits, FILE_BEGIN);
32183
32184 if( (dwRet==INVALID_SET_FILE_POINTER
@@ -32305,11 +32320,11 @@
32320 sqlite3_file *id, /* File to write into */
32321 const void *pBuf, /* The bytes to be written */
32322 int amt, /* Number of bytes to write */
32323 sqlite3_int64 offset /* Offset into the file to begin writing at */
32324 ){
32325 int rc = 0; /* True if error has occurred, else false */
32326 winFile *pFile = (winFile*)id; /* File handle */
32327 int nRetry = 0; /* Number of retries */
32328
32329 assert( amt>0 );
32330 assert( pFile );
@@ -34127,11 +34142,11 @@
34142 OSTRACE(("DELETE \"%s\" %s\n", zFilename, (rc ? "failed" : "ok" )));
34143 return rc;
34144 }
34145
34146 /*
34147 ** Check the existence and status of a file.
34148 */
34149 static int winAccess(
34150 sqlite3_vfs *pVfs, /* Not used on win32 */
34151 const char *zFilename, /* Name of file to check */
34152 int flags, /* Type of test to make on this file */
@@ -34736,11 +34751,11 @@
34751
34752
34753 /*
34754 ** A bitmap is an instance of the following structure.
34755 **
34756 ** This bitmap records the existence of zero or more bits
34757 ** with values between 1 and iSize, inclusive.
34758 **
34759 ** There are three possible representations of the bitmap.
34760 ** If iSize<=BITVEC_NBIT, then Bitvec.u.aBitmap[] is a straight
34761 ** bitmap. The least significant bit is bit 1.
@@ -37638,11 +37653,11 @@
37653 ** layer must either commit or rollback the transaction.
37654 **
37655 ** * A write transaction is active.
37656 ** * An EXCLUSIVE or greater lock is held on the database file.
37657 ** * All writing and syncing of journal and database data has finished.
37658 ** If no error occurred, all that remains is to finalize the journal to
37659 ** commit the transaction. If an error did occur, the caller will need
37660 ** to rollback the transaction.
37661 **
37662 ** ERROR:
37663 **
@@ -37886,11 +37901,11 @@
37901 ** journal file from being successfully finalized, the setMaster flag
37902 ** is cleared anyway (and the pager will move to ERROR state).
37903 **
37904 ** doNotSpill, doNotSyncSpill
37905 **
37906 ** These two boolean variables control the behavior of cache-spills
37907 ** (calls made by the pcache module to the pagerStress() routine to
37908 ** write cached data to the file-system in order to free up memory).
37909 **
37910 ** When doNotSpill is non-zero, writing to the database from pagerStress()
37911 ** is disabled altogether. This is done in a very obscure case that
@@ -38764,11 +38779,11 @@
38779 put32bits(&zHeader[sizeof(aJournalMagic)], 0xffffffff);
38780 }else{
38781 memset(zHeader, 0, sizeof(aJournalMagic)+4);
38782 }
38783
38784 /* The random check-hash initializer */
38785 sqlite3_randomness(sizeof(pPager->cksumInit), &pPager->cksumInit);
38786 put32bits(&zHeader[sizeof(aJournalMagic)+4], pPager->cksumInit);
38787 /* The initial database size */
38788 put32bits(&zHeader[sizeof(aJournalMagic)+8], pPager->dbOrigSize);
38789 /* The assumed sector size for this process */
@@ -41096,11 +41111,11 @@
41111 **
41112 ** If the condition asserted by this function were not true, and the
41113 ** dirty page were to be discarded from the cache via the pagerStress()
41114 ** routine, pagerStress() would not write the current page content to
41115 ** the database file. If a savepoint transaction were rolled back after
41116 ** this happened, the correct behavior would be to restore the current
41117 ** content of the page. However, since this content is not present in either
41118 ** the database file or the portion of the rollback journal and
41119 ** sub-journal rolled back the content could not be restored and the
41120 ** database image would become corrupt. It is therefore fortunate that
41121 ** this circumstance cannot arise.
@@ -48938,10 +48953,23 @@
48953 */
48954 static void btreeClearHasContent(BtShared *pBt){
48955 sqlite3BitvecDestroy(pBt->pHasContent);
48956 pBt->pHasContent = 0;
48957 }
48958
48959 /*
48960 ** Release all of the apPage[] pages for a cursor.
48961 */
48962 static void btreeReleaseAllCursorPages(BtCursor *pCur){
48963 int i;
48964 for(i=0; i<=pCur->iPage; i++){
48965 releasePage(pCur->apPage[i]);
48966 pCur->apPage[i] = 0;
48967 }
48968 pCur->iPage = -1;
48969 }
48970
48971
48972 /*
48973 ** Save the current cursor position in the variables BtCursor.nKey
48974 ** and BtCursor.pKey. The cursor's state is set to CURSOR_REQUIRESEEK.
48975 **
@@ -48978,16 +49006,11 @@
49006 }
49007 }
49008 assert( !pCur->apPage[0]->intKey || !pCur->pKey );
49009
49010 if( rc==SQLITE_OK ){
49011 btreeReleaseAllCursorPages(pCur);
 
 
 
 
 
49012 pCur->eState = CURSOR_REQUIRESEEK;
49013 }
49014
49015 invalidateOverflowCache(pCur);
49016 return rc;
@@ -49001,15 +49024,19 @@
49024 static int saveAllCursors(BtShared *pBt, Pgno iRoot, BtCursor *pExcept){
49025 BtCursor *p;
49026 assert( sqlite3_mutex_held(pBt->mutex) );
49027 assert( pExcept==0 || pExcept->pBt==pBt );
49028 for(p=pBt->pCursor; p; p=p->pNext){
49029 if( p!=pExcept && (0==iRoot || p->pgnoRoot==iRoot) ){
49030 if( p->eState==CURSOR_VALID ){
49031 int rc = saveCursorPosition(p);
49032 if( SQLITE_OK!=rc ){
49033 return rc;
49034 }
49035 }else{
49036 testcase( p->iPage>0 );
49037 btreeReleaseAllCursorPages(p);
49038 }
49039 }
49040 }
49041 return SQLITE_OK;
49042 }
@@ -50593,11 +50620,11 @@
50620 **
50621 ** This is useful in one special case in the backup API code where it is
50622 ** known that the shared b-tree mutex is held, but the mutex on the
50623 ** database handle that owns *p is not. In this case if sqlite3BtreeEnter()
50624 ** were to be called, it might collide with some other operation on the
50625 ** database handle that owns *p, causing undefined behavior.
50626 */
50627 SQLITE_PRIVATE int sqlite3BtreeGetReserveNoMutex(Btree *p){
50628 assert( sqlite3_mutex_held(p->pBt->mutex) );
50629 return p->pBt->pageSize - p->pBt->usableSize;
50630 }
@@ -53873,11 +53900,11 @@
53900 ** for that page now.
53901 **
53902 ** If this is the first overflow page, then write a partial entry
53903 ** to the pointer-map. If we write nothing to this pointer-map slot,
53904 ** then the optimistic overflow chain processing in clearCell()
53905 ** may misinterpret the uninitialized values and delete the
53906 ** wrong pages from the database.
53907 */
53908 if( pBt->autoVacuum && rc==SQLITE_OK ){
53909 u8 eType = (pgnoPtrmap?PTRMAP_OVERFLOW2:PTRMAP_OVERFLOW1);
53910 ptrmapPut(pBt, pgnoOvfl, eType, pgnoPtrmap, &rc);
@@ -55346,11 +55373,11 @@
55373 assert( pPage->leaf );
55374 }
55375 insertCell(pPage, idx, newCell, szNew, 0, 0, &rc);
55376 assert( rc!=SQLITE_OK || pPage->nCell>0 || pPage->nOverflow>0 );
55377
55378 /* If no error has occurred and pPage has an overflow cell, call balance()
55379 ** to redistribute the cells within the tree. Since balance() may move
55380 ** the cursor, zero the BtCursor.info.nSize and BtCursor.validNKey
55381 ** variables.
55382 **
55383 ** Previous versions of SQLite called moveToRoot() to move the cursor
@@ -59080,11 +59107,11 @@
59107 break;
59108 }
59109 }
59110 sqlite3DbFree(v->db, sIter.apSub);
59111
59112 /* Return true if hasAbort==mayAbort. Or if a malloc failure occurred.
59113 ** If malloc failed, then the while() loop above may not have iterated
59114 ** through all opcodes and hasAbort may be set incorrectly. Return
59115 ** true for this case to prevent the assert() in the callers frame
59116 ** from failing. */
59117 return ( v->db->mallocFailed || hasAbort==mayAbort );
@@ -60712,11 +60739,11 @@
60739 sqlite3 *const db = p->db;
60740 int rc = SQLITE_OK;
60741
60742 /* If p->iStatement is greater than zero, then this Vdbe opened a
60743 ** statement transaction that should be closed here. The only exception
60744 ** is that an IO error may have occurred, causing an emergency rollback.
60745 ** In this case (db->nStatement==0), and there is nothing to do.
60746 */
60747 if( db->nStatement && p->iStatement ){
60748 int i;
60749 const int iSavepoint = p->iStatement-1;
@@ -60848,11 +60875,11 @@
60875 ** transaction must be rolled back to restore the database to a
60876 ** consistent state.
60877 **
60878 ** Even if the statement is read-only, it is important to perform
60879 ** a statement or transaction rollback operation. If the error
60880 ** occurred while writing to the journal, sub-journal or database
60881 ** file as part of an effort to free up cache space (see function
60882 ** pagerStress() in pager.c), the rollback is required to restore
60883 ** the pager to a consistent state.
60884 */
60885 if( !p->readOnly || mrc!=SQLITE_INTERRUPT ){
@@ -61262,11 +61289,11 @@
61289 **
61290 ** In an SQLite index record, the serial type is stored directly before
61291 ** the blob of data that it corresponds to. In a table record, all serial
61292 ** types are stored at the start of the record, and the blobs of data at
61293 ** the end. Hence these functions allow the caller to handle the
61294 ** serial-type and data blob separately.
61295 **
61296 ** The following table describes the various storage classes for data:
61297 **
61298 ** serial type bytes of data type
61299 ** -------------- --------------- ---------------
@@ -62402,11 +62429,11 @@
62429 || rc==SQLITE_BUSY || rc==SQLITE_MISUSE
62430 );
62431 assert( p->rc!=SQLITE_ROW && p->rc!=SQLITE_DONE );
62432 if( p->isPrepareV2 && rc!=SQLITE_ROW && rc!=SQLITE_DONE ){
62433 /* If this statement was prepared using sqlite3_prepare_v2(), and an
62434 ** error has occurred, then return the error code in p->rc to the
62435 ** caller. Set the error code in the database handle to the same value.
62436 */
62437 rc = sqlite3VdbeTransferError(p);
62438 }
62439 return (rc&db->errMask);
@@ -63692,15 +63719,11 @@
63719 #define Deephemeralize(P) \
63720 if( ((P)->flags&MEM_Ephem)!=0 \
63721 && sqlite3VdbeMemMakeWriteable(P) ){ goto no_mem;}
63722
63723 /* Return true if the cursor was opened using the OP_OpenSorter opcode. */
 
 
 
63724 # define isSorter(x) ((x)->pSorter!=0)
 
63725
63726 /*
63727 ** Argument pMem points at a register that will be passed to a
63728 ** user-defined function or returned to the user as the result of a query.
63729 ** This routine sets the pMem->type variable used by the sqlite3_value_*()
@@ -67433,21 +67456,16 @@
67456 case OP_SorterOpen: {
67457 #if 0 /* local variables moved into u.ba */
67458 VdbeCursor *pCx;
67459 #endif /* local variables moved into u.ba */
67460
 
67461 u.ba.pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1);
67462 if( u.ba.pCx==0 ) goto no_mem;
67463 u.ba.pCx->pKeyInfo = pOp->p4.pKeyInfo;
67464 u.ba.pCx->pKeyInfo->enc = ENC(p->db);
67465 u.ba.pCx->isSorter = 1;
67466 rc = sqlite3VdbeSorterInit(db, u.ba.pCx);
 
 
 
 
67467 break;
67468 }
67469
67470 /* Opcode: OpenPseudo P1 P2 P3 * P5
67471 **
@@ -68348,19 +68366,14 @@
68366 case OP_SorterData: {
68367 #if 0 /* local variables moved into u.bl */
68368 VdbeCursor *pC;
68369 #endif /* local variables moved into u.bl */
68370
 
68371 pOut = &aMem[pOp->p2];
68372 u.bl.pC = p->apCsr[pOp->p1];
68373 assert( u.bl.pC->isSorter );
68374 rc = sqlite3VdbeSorterRowkey(u.bl.pC, pOut);
 
 
 
 
68375 break;
68376 }
68377
68378 /* Opcode: RowData P1 P2 * * *
68379 **
@@ -68563,13 +68576,10 @@
68576 ** rewinding so that the global variable will be incremented and
68577 ** regression tests can determine whether or not the optimizer is
68578 ** correctly optimizing out sorts.
68579 */
68580 case OP_SorterSort: /* jump */
 
 
 
68581 case OP_Sort: { /* jump */
68582 #ifdef SQLITE_TEST
68583 sqlite3_sort_count++;
68584 sqlite3_search_count--;
68585 #endif
@@ -68646,13 +68656,10 @@
68656 **
68657 ** If P5 is positive and the jump is taken, then event counter
68658 ** number P5-1 in the prepared statement is incremented.
68659 */
68660 case OP_SorterNext: /* jump */
 
 
 
68661 case OP_Prev: /* jump */
68662 case OP_Next: { /* jump */
68663 #if 0 /* local variables moved into u.br */
68664 VdbeCursor *pC;
68665 int res;
@@ -68701,13 +68708,10 @@
68708 **
68709 ** This instruction only works for indices. The equivalent instruction
68710 ** for tables is OP_Insert.
68711 */
68712 case OP_SorterInsert: /* in2 */
 
 
 
68713 case OP_IdxInsert: { /* in2 */
68714 #if 0 /* local variables moved into u.bs */
68715 VdbeCursor *pC;
68716 BtCursor *pCrsr;
68717 int nKey;
@@ -69972,11 +69976,11 @@
69976 importVtabErrMsg(p, u.cm.pVtab);
69977 if( SQLITE_OK==rc ){
69978 /* Initialize sqlite3_vtab_cursor base class */
69979 u.cm.pVtabCursor->pVtab = u.cm.pVtab;
69980
69981 /* Initialize vdbe cursor object */
69982 u.cm.pCur = allocateCursor(p, pOp->p1, 0, -1, 0);
69983 if( u.cm.pCur ){
69984 u.cm.pCur->pVtabCursor = u.cm.pVtabCursor;
69985 u.cm.pCur->pModule = u.cm.pVtabCursor->pVtab->pModule;
69986 }else{
@@ -70954,11 +70958,10 @@
70958 ** example, by CREATE INDEX statements on tables too large to fit in main
70959 ** memory).
70960 */
70961
70962
 
70963
70964 typedef struct VdbeSorterIter VdbeSorterIter;
70965 typedef struct SorterRecord SorterRecord;
70966 typedef struct FileWriter FileWriter;
70967
@@ -71974,12 +71977,10 @@
71977 pKey = vdbeSorterRowkey(pSorter, &nKey);
71978 vdbeSorterCompare(pCsr, 1, pVal->z, pVal->n, pKey, nKey, pRes);
71979 return SQLITE_OK;
71980 }
71981
 
 
71982 /************** End of vdbesort.c ********************************************/
71983 /************** Begin file journal.c *****************************************/
71984 /*
71985 ** 2007 August 22
71986 **
@@ -77513,11 +77514,11 @@
77514 int regFree1 = 0;
77515 int regFree2 = 0;
77516 int r1, r2;
77517
77518 assert( jumpIfNull==SQLITE_JUMPIFNULL || jumpIfNull==0 );
77519 if( NEVER(v==0) ) return; /* Existence of VDBE checked by caller */
77520 if( NEVER(pExpr==0) ) return; /* No way this can happen */
77521 op = pExpr->op;
77522 switch( op ){
77523 case TK_AND: {
77524 int d2 = sqlite3VdbeMakeLabel(v);
@@ -77633,11 +77634,11 @@
77634 int regFree1 = 0;
77635 int regFree2 = 0;
77636 int r1, r2;
77637
77638 assert( jumpIfNull==SQLITE_JUMPIFNULL || jumpIfNull==0 );
77639 if( NEVER(v==0) ) return; /* Existence of VDBE checked by caller */
77640 if( pExpr==0 ) return;
77641
77642 /* The value of pExpr->op and op are related as follows:
77643 **
77644 ** pExpr->op op
@@ -80230,11 +80231,11 @@
80231 zErrDyn = sqlite3MPrintf(db, "database %s is already in use", zName);
80232 goto attach_error;
80233 }
80234 }
80235
80236 /* Allocate the new entry in the db->aDb[] array and initialize the schema
80237 ** hash tables.
80238 */
80239 if( db->aDb==db->aDbStatic ){
80240 aNew = sqlite3DbMallocRaw(db, sizeof(db->aDb[0])*3 );
80241 if( aNew==0 ) return;
@@ -80247,11 +80248,11 @@
80248 aNew = &db->aDb[db->nDb];
80249 memset(aNew, 0, sizeof(*aNew));
80250
80251 /* Open the database file. If the btree is successfully opened, use
80252 ** it to obtain the database schema. At this point the schema may
80253 ** or may not be initialized.
80254 */
80255 flags = db->openFlags;
80256 rc = sqlite3ParseUri(db->pVfs->zName, zFile, &flags, &pVfs, &zPath, &zErr);
80257 if( rc!=SQLITE_OK ){
80258 if( rc==SQLITE_NOMEM ) db->mallocFailed = 1;
@@ -83033,11 +83034,11 @@
83034 #endif
83035
83036 /* Drop all SQLITE_MASTER table and index entries that refer to the
83037 ** table. The program name loops through the master table and deletes
83038 ** every row that refers to a table of the same name as the one being
83039 ** dropped. Triggers are handled separately because a trigger can be
83040 ** created in the temp database that refers to a table in another
83041 ** database.
83042 */
83043 sqlite3NestedParse(pParse,
83044 "DELETE FROM %Q.%s WHERE tbl_name=%Q and type!='trigger'",
@@ -83325,13 +83326,10 @@
83326 int addr1; /* Address of top of loop */
83327 int addr2; /* Address to jump to for next iteration */
83328 int tnum; /* Root page of index */
83329 Vdbe *v; /* Generate code into this virtual machine */
83330 KeyInfo *pKey; /* KeyInfo for index */
 
 
 
83331 int regRecord; /* Register holding assemblied index record */
83332 sqlite3 *db = pParse->db; /* The database connection */
83333 int iDb = sqlite3SchemaToIndex(db, pIndex->pSchema);
83334
83335 #ifndef SQLITE_OMIT_AUTHORIZATION
@@ -83355,25 +83353,20 @@
83353 pKey = sqlite3IndexKeyinfo(pParse, pIndex);
83354 sqlite3VdbeAddOp4(v, OP_OpenWrite, iIdx, tnum, iDb,
83355 (char *)pKey, P4_KEYINFO_HANDOFF);
83356 sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR|((memRootPage>=0)?OPFLAG_P2ISREG:0));
83357
 
83358 /* Open the sorter cursor if we are to use one. */
83359 iSorter = pParse->nTab++;
83360 sqlite3VdbeAddOp4(v, OP_SorterOpen, iSorter, 0, 0, (char*)pKey, P4_KEYINFO);
 
 
 
83361
83362 /* Open the table. Loop through all rows of the table, inserting index
83363 ** records into the sorter. */
83364 sqlite3OpenTable(pParse, iTab, iDb, pTab, OP_OpenRead);
83365 addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iTab, 0);
83366 regRecord = sqlite3GetTempReg(pParse);
83367
 
83368 sqlite3GenerateIndexKey(pParse, pIndex, iTab, regRecord, 1);
83369 sqlite3VdbeAddOp2(v, OP_SorterInsert, iSorter, regRecord);
83370 sqlite3VdbeAddOp2(v, OP_Next, iTab, addr1+1);
83371 sqlite3VdbeJumpHere(v, addr1);
83372 addr1 = sqlite3VdbeAddOp2(v, OP_SorterSort, iSorter, 0);
@@ -83389,34 +83382,10 @@
83382 addr2 = sqlite3VdbeCurrentAddr(v);
83383 }
83384 sqlite3VdbeAddOp2(v, OP_SorterData, iSorter, regRecord);
83385 sqlite3VdbeAddOp3(v, OP_IdxInsert, iIdx, regRecord, 1);
83386 sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83387 sqlite3ReleaseTempReg(pParse, regRecord);
83388 sqlite3VdbeAddOp2(v, OP_SorterNext, iSorter, addr2);
83389 sqlite3VdbeJumpHere(v, addr1);
83390
83391 sqlite3VdbeAddOp1(v, OP_Close, iTab);
@@ -83772,11 +83741,11 @@
83741 /* This constraint creates the same index as a previous
83742 ** constraint specified somewhere in the CREATE TABLE statement.
83743 ** However the ON CONFLICT clauses are different. If both this
83744 ** constraint and the previous equivalent constraint have explicit
83745 ** ON CONFLICT clauses this is an error. Otherwise, use the
83746 ** explicitly specified behavior for the index.
83747 */
83748 if( !(pIdx->onError==OE_Default || pIndex->onError==OE_Default) ){
83749 sqlite3ErrorMsg(pParse,
83750 "conflicting ON CONFLICT clauses specified", 0);
83751 }
@@ -94054,11 +94023,11 @@
94023 assert( sqlite3_mutex_held(db->mutex) );
94024 assert( iDb==1 || sqlite3BtreeHoldsMutex(db->aDb[iDb].pBt) );
94025
94026 /* zMasterSchema and zInitScript are set to point at the master schema
94027 ** and initialisation script appropriate for the database being
94028 ** initialized. zMasterName is the name of the master table.
94029 */
94030 if( !OMIT_TEMPDB && iDb==1 ){
94031 zMasterSchema = temp_master_schema;
94032 }else{
94033 zMasterSchema = master_schema;
@@ -94279,11 +94248,11 @@
94248 if( rc ){
94249 sqlite3ResetOneSchema(db, i);
94250 }
94251 }
94252
94253 /* Once all the other databases have been initialized, load the schema
94254 ** for the TEMP database. This is loaded last, as the TEMP database
94255 ** schema may contain references to objects in other databases.
94256 */
94257 #ifndef SQLITE_OMIT_TEMPDB
94258 if( rc==SQLITE_OK && ALWAYS(db->nDb>1)
@@ -94302,11 +94271,11 @@
94271
94272 return rc;
94273 }
94274
94275 /*
94276 ** This routine is a no-op if the database schema is already initialized.
94277 ** Otherwise, the schema is loaded. An error code is returned.
94278 */
94279 SQLITE_PRIVATE int sqlite3ReadSchema(Parse *pParse){
94280 int rc = SQLITE_OK;
94281 sqlite3 *db = pParse->db;
@@ -99315,11 +99284,11 @@
99284 ** first iteration (since the first iteration of the loop is
99285 ** guaranteed to operate on the row with the minimum or maximum
99286 ** value of x, the only row required).
99287 **
99288 ** A special flag must be passed to sqlite3WhereBegin() to slightly
99289 ** modify behavior as follows:
99290 **
99291 ** + If the query is a "SELECT min(x)", then the loop coded by
99292 ** where.c should not iterate over any values with a NULL value
99293 ** for x.
99294 **
@@ -101308,11 +101277,11 @@
101277 sqlite3CodeRowTrigger(pParse, pTrigger, TK_UPDATE, pChanges,
101278 TRIGGER_BEFORE, pTab, regOldRowid, onError, addr);
101279
101280 /* The row-trigger may have deleted the row being updated. In this
101281 ** case, jump to the next row. No updates or AFTER triggers are
101282 ** required. This behavior - what happens when the row being updated
101283 ** is deleted or renamed by a BEFORE trigger - is left undefined in the
101284 ** documentation.
101285 */
101286 sqlite3VdbeAddOp3(v, OP_NotExists, iCur, addr, regOldRowid);
101287
@@ -103237,10 +103206,12 @@
103206 #define WHERE_IDX_ONLY 0x00400000 /* Use index only - omit table */
103207 #define WHERE_ORDERED 0x00800000 /* Output will appear in correct order */
103208 #define WHERE_REVERSE 0x01000000 /* Scan in reverse order */
103209 #define WHERE_UNIQUE 0x02000000 /* Selects no more than one row */
103210 #define WHERE_ALL_UNIQUE 0x04000000 /* This and all prior have one row */
103211 #define WHERE_OB_UNIQUE 0x00004000 /* Values in ORDER BY columns are
103212 ** different for every output row */
103213 #define WHERE_VIRTUALTABLE 0x08000000 /* Use virtual-table processing */
103214 #define WHERE_MULTI_OR 0x10000000 /* OR using multiple indices */
103215 #define WHERE_TEMP_INDEX 0x20000000 /* Uses an ephemeral index */
103216 #define WHERE_DISTINCT 0x40000000 /* Correct order for DISTINCT */
103217 #define WHERE_COVER_SCAN 0x80000000 /* Full scan of a covering index */
@@ -103537,11 +103508,11 @@
103508
103509 /*
103510 ** Commute a comparison operator. Expressions of the form "X op Y"
103511 ** are converted into "Y op X".
103512 **
103513 ** If left/right precedence rules come into play when determining the
103514 ** collating
103515 ** side of the comparison, it remains associated with the same side after
103516 ** the commutation. So "Y collate NOCASE op X" becomes
103517 ** "X op Y". This is because any collation sequence on
103518 ** the left hand side of a comparison overrides any collation sequence
@@ -105878,11 +105849,12 @@
105849 */
105850 static int isSortingIndex(
105851 WhereBestIdx *p, /* Best index search context */
105852 Index *pIdx, /* The index we are testing */
105853 int base, /* Cursor number for the table to be sorted */
105854 int *pbRev, /* Set to 1 for reverse-order scan of pIdx */
105855 int *pbObUnique /* ORDER BY column values will different in every row */
105856 ){
105857 int i; /* Number of pIdx terms used */
105858 int j; /* Number of ORDER BY terms satisfied */
105859 int sortOrder = 2; /* 0: forward. 1: backward. 2: unknown */
105860 int nTerm; /* Number of ORDER BY terms */
@@ -105892,25 +105864,32 @@
105864 Parse *pParse = p->pParse; /* Parser context */
105865 sqlite3 *db = pParse->db; /* Database connection */
105866 int nPriorSat; /* ORDER BY terms satisfied by outer loops */
105867 int seenRowid = 0; /* True if an ORDER BY rowid term is seen */
105868 int uniqueNotNull; /* pIdx is UNIQUE with all terms are NOT NULL */
105869 int outerObUnique; /* Outer loops generate different values in
105870 ** every row for the ORDER BY columns */
105871
105872 if( p->i==0 ){
105873 nPriorSat = 0;
105874 outerObUnique = 1;
105875 }else{
105876 u32 wsFlags = p->aLevel[p->i-1].plan.wsFlags;
105877 nPriorSat = p->aLevel[p->i-1].plan.nOBSat;
105878 if( (wsFlags & WHERE_ORDERED)==0 ){
105879 /* This loop cannot be ordered unless the next outer loop is
105880 ** also ordered */
105881 return nPriorSat;
105882 }
105883 if( OptimizationDisabled(db, SQLITE_OrderByIdxJoin) ){
105884 /* Only look at the outer-most loop if the OrderByIdxJoin
105885 ** optimization is disabled */
105886 return nPriorSat;
105887 }
105888 testcase( wsFlags & WHERE_OB_UNIQUE );
105889 testcase( wsFlags & WHERE_ALL_UNIQUE );
105890 outerObUnique = (wsFlags & (WHERE_OB_UNIQUE|WHERE_ALL_UNIQUE))!=0;
105891 }
105892 pOrderBy = p->pOrderBy;
105893 assert( pOrderBy!=0 );
105894 if( pIdx->bUnordered ){
105895 /* Hash indices (indicated by the "unordered" tag on sqlite_stat1) cannot
@@ -106048,23 +106027,38 @@
106027 testcase( isEq==2 );
106028 testcase( isEq==3 );
106029 uniqueNotNull = 0;
106030 }
106031 }
106032 if( seenRowid ){
106033 uniqueNotNull = 1;
106034 }else if( uniqueNotNull==0 || i<pIdx->nColumn ){
106035 uniqueNotNull = 0;
106036 }
106037
106038 /* If we have not found at least one ORDER BY term that matches the
106039 ** index, then show no progress. */
106040 if( pOBItem==&pOrderBy->a[nPriorSat] ) return nPriorSat;
106041
106042 /* Either the outer queries must generate rows where there are no two
106043 ** rows with the same values in all ORDER BY columns, or else this
106044 ** loop must generate just a single row of output. Example: Suppose
106045 ** the outer loops generate A=1 and A=1, and this loop generates B=3
106046 ** and B=4. Then without the following test, ORDER BY A,B would
106047 ** generate the wrong order output: 1,3 1,4 1,3 1,4
106048 */
106049 if( outerObUnique==0 && uniqueNotNull==0 ) return nPriorSat;
106050 *pbObUnique = uniqueNotNull;
106051
106052 /* Return the necessary scan order back to the caller */
106053 *pbRev = sortOrder & 1;
106054
106055 /* If there was an "ORDER BY rowid" term that matched, or it is only
106056 ** possible for a single row from this table to match, then skip over
106057 ** any additional ORDER BY terms dealing with this table.
106058 */
106059 if( uniqueNotNull ){
106060 /* Advance j over additional ORDER BY terms associated with base */
106061 WhereMaskSet *pMS = p->pWC->pMaskSet;
106062 Bitmask m = ~getMask(pMS, base);
106063 while( j<nTerm && (exprTableUsage(pMS, pOrderBy->a[j].pExpr)&m)==0 ){
106064 j++;
@@ -106344,16 +106338,18 @@
106338 ** in pc.plan.wsFlags. Otherwise, if there is an ORDER BY clause but
106339 ** the index will scan rows in a different order, set the bSort
106340 ** variable. */
106341 if( bSort && (pSrc->jointype & JT_LEFT)==0 ){
106342 int bRev = 2;
106343 int bObUnique = 0;
106344 WHERETRACE((" --> before isSortIndex: nPriorSat=%d\n",nPriorSat));
106345 pc.plan.nOBSat = isSortingIndex(p, pProbe, iCur, &bRev, &bObUnique);
106346 WHERETRACE((" --> after isSortIndex: bRev=%d bObU=%d nOBSat=%d\n",
106347 bRev, bObUnique, pc.plan.nOBSat));
106348 if( nPriorSat<pc.plan.nOBSat || (pc.plan.wsFlags & WHERE_ALL_UNIQUE)!=0 ){
106349 pc.plan.wsFlags |= WHERE_ORDERED;
106350 if( bObUnique ) pc.plan.wsFlags |= WHERE_OB_UNIQUE;
106351 }
106352 if( nOrderBy==pc.plan.nOBSat ){
106353 bSort = 0;
106354 pc.plan.wsFlags |= WHERE_ROWID_RANGE|WHERE_COLUMN_RANGE;
106355 }
@@ -106443,11 +106439,12 @@
106439 ** The ANALYZE command and the sqlite_stat1 and sqlite_stat3 tables do
106440 ** not give us data on the relative sizes of table and index records.
106441 ** So this computation assumes table records are about twice as big
106442 ** as index records
106443 */
106444 if( (pc.plan.wsFlags&~(WHERE_REVERSE|WHERE_ORDERED|WHERE_OB_UNIQUE))
106445 ==WHERE_IDX_ONLY
106446 && (pWC->wctrlFlags & WHERE_ONEPASS_DESIRED)==0
106447 && sqlite3GlobalConfig.bUseCis
106448 && OptimizationEnabled(pParse->db, SQLITE_CoverIdxScan)
106449 ){
106450 /* This index is not useful for indexing, but it is a covering index.
@@ -106603,11 +106600,11 @@
106600 }
106601
106602 /* If there is no ORDER BY clause and the SQLITE_ReverseOrder flag
106603 ** is set, then reverse the order that the index will be scanned
106604 ** in. This is used for application testing, to help find cases
106605 ** where application behavior depends on the (undefined) order that
106606 ** SQLite outputs rows in in the absence of an ORDER BY clause. */
106607 if( !p->pOrderBy && pParse->db->flags & SQLITE_ReverseOrder ){
106608 p->cost.plan.wsFlags |= WHERE_REVERSE;
106609 }
106610
@@ -114198,11 +114195,11 @@
114195 return;
114196 }
114197
114198 /* If we reach this point, it means that the database connection has
114199 ** closed all sqlite3_stmt and sqlite3_backup objects and has been
114200 ** passed to sqlite3_close (meaning that it is a zombie). Therefore,
114201 ** go ahead and free all resources.
114202 */
114203
114204 /* Free any outstanding Savepoint structures. */
114205 sqlite3CloseSavepoints(db);
@@ -117250,11 +117247,11 @@
117247 ** to the strings "arg1" and "arg2".
117248 **
117249 ** This method should return either SQLITE_OK (0), or an SQLite error
117250 ** code. If SQLITE_OK is returned, then *ppTokenizer should be set
117251 ** to point at the newly created tokenizer structure. The generic
117252 ** sqlite3_tokenizer.pModule variable should not be initialized by
117253 ** this callback. The caller will do so.
117254 */
117255 int (*xCreate)(
117256 int argc, /* Size of argv array */
117257 const char *const*argv, /* Tokenizer argument strings */
@@ -117355,11 +117352,11 @@
117352 ** May you do good and not evil.
117353 ** May you find forgiveness for yourself and forgive others.
117354 ** May you share freely, never taking more than you give.
117355 **
117356 *************************************************************************
117357 ** This is the header file for the generic hash-table implementation
117358 ** used in SQLite. We've modified it slightly to serve as a standalone
117359 ** hash table implementation for the full-text indexing module.
117360 **
117361 */
117362 #ifndef _FTS3_HASH_H_
@@ -119262,11 +119259,11 @@
119259 if( SQLITE_ROW==sqlite3_step(pCsr->pStmt) ){
119260 return SQLITE_OK;
119261 }else{
119262 rc = sqlite3_reset(pCsr->pStmt);
119263 if( rc==SQLITE_OK && ((Fts3Table *)pCsr->base.pVtab)->zContentTbl==0 ){
119264 /* If no row was found and no error has occurred, then the %_content
119265 ** table is missing a row that is present in the full-text index.
119266 ** The data structures are corrupt. */
119267 rc = FTS_CORRUPT_VTAB;
119268 pCsr->isEof = 1;
119269 }
@@ -120502,11 +120499,11 @@
120499 sqlite3Fts3SegReaderFinish(pSegcsr);
120500 sqlite3_free(pSegcsr);
120501 }
120502
120503 /*
120504 ** This function retrieves the doclist for the specified term (or term
120505 ** prefix) from the database.
120506 */
120507 static int fts3TermSelect(
120508 Fts3Table *p, /* Virtual table handle */
120509 Fts3PhraseToken *pTok, /* Token to query for */
@@ -121253,11 +121250,11 @@
121250 #ifdef SQLITE_ENABLE_ICU
121251 SQLITE_PRIVATE void sqlite3Fts3IcuTokenizerModule(sqlite3_tokenizer_module const**ppModule);
121252 #endif
121253
121254 /*
121255 ** Initialize the fts3 extension. If this extension is built as part
121256 ** of the sqlite library, then this function is called directly by
121257 ** SQLite. If fts3 is built as a dynamically loadable extension, this
121258 ** function is called by the sqlite3_extension_init() entry point.
121259 */
121260 SQLITE_PRIVATE int sqlite3Fts3Init(sqlite3 *db){
@@ -121287,11 +121284,11 @@
121284 if( rc!=SQLITE_OK ) return rc;
121285
121286 sqlite3Fts3SimpleTokenizerModule(&pSimple);
121287 sqlite3Fts3PorterTokenizerModule(&pPorter);
121288
121289 /* Allocate and initialize the hash-table used to store tokenizers. */
121290 pHash = sqlite3_malloc(sizeof(Fts3Hash));
121291 if( !pHash ){
121292 rc = SQLITE_NOMEM;
121293 }else{
121294 sqlite3Fts3HashInit(pHash, FTS3_HASH_STRING, 1);
@@ -122886,11 +122883,11 @@
122883 ** The returned value is either NULL or a pointer to a buffer containing
122884 ** a position-list indicating the occurrences of the phrase in column iCol
122885 ** of the current row.
122886 **
122887 ** More specifically, the returned buffer contains 1 varint for each
122888 ** occurrence of the phrase in the column, stored using the normal (delta+2)
122889 ** compression and is terminated by either an 0x01 or 0x00 byte. For example,
122890 ** if the requested column contains "a b X c d X X" and the position-list
122891 ** for 'X' is requested, the buffer returned may contain:
122892 **
122893 ** 0x04 0x05 0x03 0x01 or 0x04 0x05 0x03 0x00
@@ -123625,11 +123622,11 @@
123622
123623 /*
123624 ** This function is equivalent to the standard isspace() function.
123625 **
123626 ** The standard isspace() can be awkward to use safely, because although it
123627 ** is defined to accept an argument of type int, its behavior when passed
123628 ** an integer that falls outside of the range of the unsigned char type
123629 ** is undefined (and sometimes, "undefined" means segfault). This wrapper
123630 ** is defined to accept an argument of type char, and always returns 0 for
123631 ** any values that fall outside of the range of the unsigned char type (i.e.
123632 ** negative values).
@@ -125993,11 +125990,11 @@
125990 #endif
125991
125992 /*
125993 ** Set up SQL objects in database db used to access the contents of
125994 ** the hash table pointed to by argument pHash. The hash table must
125995 ** been initialized to use string keys, and to take a private copy
125996 ** of the key when a value is inserted. i.e. by a call similar to:
125997 **
125998 ** sqlite3Fts3HashInit(pHash, FTS3_HASH_STRING, 1);
125999 **
126000 ** This function adds a scalar function (see header comment above
@@ -127772,10 +127769,11 @@
127769 if( ppOffsetList ){
127770 *ppOffsetList = pReader->pOffsetList;
127771 *pnOffsetList = (int)(p - pReader->pOffsetList - 1);
127772 }
127773
127774 /* List may have been edited in place by fts3EvalNearTrim() */
127775 while( p<pEnd && *p==0 ) p++;
127776
127777 /* If there are no more entries in the doclist, set pOffsetList to
127778 ** NULL. Otherwise, set Fts3SegReader.iDocid to the next docid and
127779 ** Fts3SegReader.pOffsetList to point to the next offset list before
@@ -128787,13 +128785,17 @@
128785 ** function adjusts the pointer *ppList and the length *pnList so that they
128786 ** identify the subset of the position list that corresponds to column iCol.
128787 **
128788 ** If there are no entries in the input position list for column iCol, then
128789 ** *pnList is set to zero before returning.
128790 **
128791 ** If parameter bZero is non-zero, then any part of the input list following
128792 ** the end of the output list is zeroed before returning.
128793 */
128794 static void fts3ColumnFilter(
128795 int iCol, /* Column to filter on */
128796 int bZero, /* Zero out anything following *ppList */
128797 char **ppList, /* IN/OUT: Pointer to position list */
128798 int *pnList /* IN/OUT: Size of buffer *ppList in bytes */
128799 ){
128800 char *pList = *ppList;
128801 int nList = *pnList;
@@ -128818,10 +128820,13 @@
128820 }
128821 p = &pList[1];
128822 p += sqlite3Fts3GetVarint32(p, &iCurrent);
128823 }
128824
128825 if( bZero && &pList[nList]!=pEnd ){
128826 memset(&pList[nList], 0, pEnd - &pList[nList]);
128827 }
128828 *ppList = pList;
128829 *pnList = nList;
128830 }
128831
128832 /*
@@ -128890,24 +128895,24 @@
128895 rc = fts3SegReaderNextDocid(p, apSegment[j], 0, 0);
128896 j++;
128897 }
128898 if( rc!=SQLITE_OK ) return rc;
128899 fts3SegReaderSort(pMsr->apSegment, nMerge, j, xCmp);
128900
128901 if( nList>0 && fts3SegReaderIsPending(apSegment[0]) ){
128902 rc = fts3MsrBufferData(pMsr, pList, nList+1);
128903 if( rc!=SQLITE_OK ) return rc;
128904 assert( (pMsr->aBuffer[nList] & 0xFE)==0x00 );
128905 pList = pMsr->aBuffer;
128906 }
128907
128908 if( pMsr->iColFilter>=0 ){
128909 fts3ColumnFilter(pMsr->iColFilter, 1, &pList, &nList);
128910 }
128911
128912 if( nList>0 ){
128913 *paPoslist = pList;
 
 
 
 
 
 
 
128914 *piDocid = iDocid;
128915 *pnPoslist = nList;
128916 break;
128917 }
128918 }
@@ -129146,11 +129151,11 @@
129151 fts3SegReaderNextDocid(p, apSegment[j], 0, 0);
129152 j++;
129153 }
129154
129155 if( isColFilter ){
129156 fts3ColumnFilter(pFilter->iCol, 0, &pList, &nList);
129157 }
129158
129159 if( !isIgnoreEmpty || nList>0 ){
129160
129161 /* Calculate the 'docid' delta value to write into the merged
@@ -132083,13 +132088,13 @@
132088 ** Select the fragment of text consisting of nFragment contiguous tokens
132089 ** from column iCol that represent the "best" snippet. The best snippet
132090 ** is the snippet with the highest score, where scores are calculated
132091 ** by adding:
132092 **
132093 ** (a) +1 point for each occurrence of a matchable phrase in the snippet.
132094 **
132095 ** (b) +1000 points for the first occurrence of each matchable phrase in
132096 ** the snippet for which the corresponding mCovered bit is not set.
132097 **
132098 ** The selected snippet parameters are stored in structure *pFragment before
132099 ** returning. The score of the selected snippet is stored in *piScore
132100 ** before returning.
@@ -133340,11 +133345,11 @@
133345 ** the return value of sqlite3FtsUnicodeIsalnum() is inverted for all
133346 ** codepoints in the aiException[] array.
133347 **
133348 ** If a standalone diacritic mark (one that sqlite3FtsUnicodeIsdiacritic()
133349 ** identifies as a diacritic) occurs in the zIn/nIn string it is ignored.
133350 ** It is not possible to change the behavior of the tokenizer with respect
133351 ** to these codepoints.
133352 */
133353 static int unicodeAddExceptions(
133354 unicode_tokenizer *p, /* Tokenizer to add exceptions to */
133355 int bAlnum, /* Replace Isalnum() return value with this */
@@ -136643,11 +136648,11 @@
136648 RtreeNode *pLeaf = 0; /* Leaf node containing record iDelete */
136649 int iCell; /* Index of iDelete cell in pLeaf */
136650 RtreeNode *pRoot; /* Root node of rtree structure */
136651
136652
136653 /* Obtain a reference to the root node to initialize Rtree.iDepth */
136654 rc = nodeAcquire(pRtree, 1, 0, &pRoot);
136655
136656 /* Obtain a reference to the leaf node that contains the entry
136657 ** about to be deleted.
136658 */
136659
+12 -8
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -105,13 +105,13 @@
105105
**
106106
** See also: [sqlite3_libversion()],
107107
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108108
** [sqlite_version()] and [sqlite_source_id()].
109109
*/
110
-#define SQLITE_VERSION "3.7.16"
110
+#define SQLITE_VERSION "3.7.16.1"
111111
#define SQLITE_VERSION_NUMBER 3007016
112
-#define SQLITE_SOURCE_ID "2013-03-13 00:13:25 839aa91faf1db7025d90fa3c65e50efb829b053b"
112
+#define SQLITE_SOURCE_ID "2013-03-27 20:41:15 274d2a22660c7b34b8bbd85f3c29cbafbcb1b4e7"
113113
114114
/*
115115
** CAPI3REF: Run-Time Library Version Numbers
116116
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117117
**
@@ -2678,11 +2678,11 @@
26782678
** "private". ^Setting it to "shared" is equivalent to setting the
26792679
** SQLITE_OPEN_SHAREDCACHE bit in the flags argument passed to
26802680
** sqlite3_open_v2(). ^Setting the cache parameter to "private" is
26812681
** equivalent to setting the SQLITE_OPEN_PRIVATECACHE bit.
26822682
** ^If sqlite3_open_v2() is used and the "cache" parameter is present in
2683
-** a URI filename, its value overrides any behaviour requested by setting
2683
+** a URI filename, its value overrides any behavior requested by setting
26842684
** SQLITE_OPEN_PRIVATECACHE or SQLITE_OPEN_SHAREDCACHE flag.
26852685
** </ul>
26862686
**
26872687
** ^Specifying an unknown parameter in the query component of a URI is not an
26882688
** error. Future versions of SQLite might understand additional query
@@ -3996,11 +3996,12 @@
39963996
SQLITE_API SQLITE_DEPRECATED int sqlite3_aggregate_count(sqlite3_context*);
39973997
SQLITE_API SQLITE_DEPRECATED int sqlite3_expired(sqlite3_stmt*);
39983998
SQLITE_API SQLITE_DEPRECATED int sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*);
39993999
SQLITE_API SQLITE_DEPRECATED int sqlite3_global_recover(void);
40004000
SQLITE_API SQLITE_DEPRECATED void sqlite3_thread_cleanup(void);
4001
-SQLITE_API SQLITE_DEPRECATED int sqlite3_memory_alarm(void(*)(void*,sqlite3_int64,int),void*,sqlite3_int64);
4001
+SQLITE_API SQLITE_DEPRECATED int sqlite3_memory_alarm(void(*)(void*,sqlite3_int64,int),
4002
+ void*,sqlite3_int64);
40024003
#endif
40034004
40044005
/*
40054006
** CAPI3REF: Obtaining SQL Function Parameter Values
40064007
**
@@ -4076,18 +4077,21 @@
40764077
** an aggregate query, the xStep() callback of the aggregate function
40774078
** implementation is never called and xFinal() is called exactly once.
40784079
** In those cases, sqlite3_aggregate_context() might be called for the
40794080
** first time from within xFinal().)^
40804081
**
4081
-** ^The sqlite3_aggregate_context(C,N) routine returns a NULL pointer if N is
4082
-** less than or equal to zero or if a memory allocate error occurs.
4082
+** ^The sqlite3_aggregate_context(C,N) routine returns a NULL pointer
4083
+** when first called if N is less than or equal to zero or if a memory
4084
+** allocate error occurs.
40834085
**
40844086
** ^(The amount of space allocated by sqlite3_aggregate_context(C,N) is
40854087
** determined by the N parameter on first successful call. Changing the
40864088
** value of N in subsequent call to sqlite3_aggregate_context() within
40874089
** the same aggregate function instance will not resize the memory
4088
-** allocation.)^
4090
+** allocation.)^ Within the xFinal callback, it is customary to set
4091
+** N=0 in calls to sqlite3_aggregate_context(C,N) so that no
4092
+** pointless memory allocations occur.
40894093
**
40904094
** ^SQLite automatically frees the memory allocated by
40914095
** sqlite3_aggregate_context() when the aggregate query concludes.
40924096
**
40934097
** The first parameter must be a copy of the
@@ -6377,11 +6381,11 @@
63776381
** intact. If the requested page is not already in the cache, then the
63786382
** cache implementation should use the value of the createFlag
63796383
** parameter to help it determined what action to take:
63806384
**
63816385
** <table border=1 width=85% align=center>
6382
-** <tr><th> createFlag <th> Behaviour when page is not already in cache
6386
+** <tr><th> createFlag <th> Behavior when page is not already in cache
63836387
** <tr><td> 0 <td> Do not allocate a new page. Return NULL.
63846388
** <tr><td> 1 <td> Allocate a new page if it easy and convenient to do so.
63856389
** Otherwise return NULL.
63866390
** <tr><td> 2 <td> Make every effort to allocate a new page. Only return
63876391
** NULL if allocating a new page is effectively impossible.
63886392
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -105,13 +105,13 @@
105 **
106 ** See also: [sqlite3_libversion()],
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.7.16"
111 #define SQLITE_VERSION_NUMBER 3007016
112 #define SQLITE_SOURCE_ID "2013-03-13 00:13:25 839aa91faf1db7025d90fa3c65e50efb829b053b"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -2678,11 +2678,11 @@
2678 ** "private". ^Setting it to "shared" is equivalent to setting the
2679 ** SQLITE_OPEN_SHAREDCACHE bit in the flags argument passed to
2680 ** sqlite3_open_v2(). ^Setting the cache parameter to "private" is
2681 ** equivalent to setting the SQLITE_OPEN_PRIVATECACHE bit.
2682 ** ^If sqlite3_open_v2() is used and the "cache" parameter is present in
2683 ** a URI filename, its value overrides any behaviour requested by setting
2684 ** SQLITE_OPEN_PRIVATECACHE or SQLITE_OPEN_SHAREDCACHE flag.
2685 ** </ul>
2686 **
2687 ** ^Specifying an unknown parameter in the query component of a URI is not an
2688 ** error. Future versions of SQLite might understand additional query
@@ -3996,11 +3996,12 @@
3996 SQLITE_API SQLITE_DEPRECATED int sqlite3_aggregate_count(sqlite3_context*);
3997 SQLITE_API SQLITE_DEPRECATED int sqlite3_expired(sqlite3_stmt*);
3998 SQLITE_API SQLITE_DEPRECATED int sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*);
3999 SQLITE_API SQLITE_DEPRECATED int sqlite3_global_recover(void);
4000 SQLITE_API SQLITE_DEPRECATED void sqlite3_thread_cleanup(void);
4001 SQLITE_API SQLITE_DEPRECATED int sqlite3_memory_alarm(void(*)(void*,sqlite3_int64,int),void*,sqlite3_int64);
 
4002 #endif
4003
4004 /*
4005 ** CAPI3REF: Obtaining SQL Function Parameter Values
4006 **
@@ -4076,18 +4077,21 @@
4076 ** an aggregate query, the xStep() callback of the aggregate function
4077 ** implementation is never called and xFinal() is called exactly once.
4078 ** In those cases, sqlite3_aggregate_context() might be called for the
4079 ** first time from within xFinal().)^
4080 **
4081 ** ^The sqlite3_aggregate_context(C,N) routine returns a NULL pointer if N is
4082 ** less than or equal to zero or if a memory allocate error occurs.
 
4083 **
4084 ** ^(The amount of space allocated by sqlite3_aggregate_context(C,N) is
4085 ** determined by the N parameter on first successful call. Changing the
4086 ** value of N in subsequent call to sqlite3_aggregate_context() within
4087 ** the same aggregate function instance will not resize the memory
4088 ** allocation.)^
 
 
4089 **
4090 ** ^SQLite automatically frees the memory allocated by
4091 ** sqlite3_aggregate_context() when the aggregate query concludes.
4092 **
4093 ** The first parameter must be a copy of the
@@ -6377,11 +6381,11 @@
6377 ** intact. If the requested page is not already in the cache, then the
6378 ** cache implementation should use the value of the createFlag
6379 ** parameter to help it determined what action to take:
6380 **
6381 ** <table border=1 width=85% align=center>
6382 ** <tr><th> createFlag <th> Behaviour when page is not already in cache
6383 ** <tr><td> 0 <td> Do not allocate a new page. Return NULL.
6384 ** <tr><td> 1 <td> Allocate a new page if it easy and convenient to do so.
6385 ** Otherwise return NULL.
6386 ** <tr><td> 2 <td> Make every effort to allocate a new page. Only return
6387 ** NULL if allocating a new page is effectively impossible.
6388
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -105,13 +105,13 @@
105 **
106 ** See also: [sqlite3_libversion()],
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.7.16.1"
111 #define SQLITE_VERSION_NUMBER 3007016
112 #define SQLITE_SOURCE_ID "2013-03-27 20:41:15 274d2a22660c7b34b8bbd85f3c29cbafbcb1b4e7"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -2678,11 +2678,11 @@
2678 ** "private". ^Setting it to "shared" is equivalent to setting the
2679 ** SQLITE_OPEN_SHAREDCACHE bit in the flags argument passed to
2680 ** sqlite3_open_v2(). ^Setting the cache parameter to "private" is
2681 ** equivalent to setting the SQLITE_OPEN_PRIVATECACHE bit.
2682 ** ^If sqlite3_open_v2() is used and the "cache" parameter is present in
2683 ** a URI filename, its value overrides any behavior requested by setting
2684 ** SQLITE_OPEN_PRIVATECACHE or SQLITE_OPEN_SHAREDCACHE flag.
2685 ** </ul>
2686 **
2687 ** ^Specifying an unknown parameter in the query component of a URI is not an
2688 ** error. Future versions of SQLite might understand additional query
@@ -3996,11 +3996,12 @@
3996 SQLITE_API SQLITE_DEPRECATED int sqlite3_aggregate_count(sqlite3_context*);
3997 SQLITE_API SQLITE_DEPRECATED int sqlite3_expired(sqlite3_stmt*);
3998 SQLITE_API SQLITE_DEPRECATED int sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*);
3999 SQLITE_API SQLITE_DEPRECATED int sqlite3_global_recover(void);
4000 SQLITE_API SQLITE_DEPRECATED void sqlite3_thread_cleanup(void);
4001 SQLITE_API SQLITE_DEPRECATED int sqlite3_memory_alarm(void(*)(void*,sqlite3_int64,int),
4002 void*,sqlite3_int64);
4003 #endif
4004
4005 /*
4006 ** CAPI3REF: Obtaining SQL Function Parameter Values
4007 **
@@ -4076,18 +4077,21 @@
4077 ** an aggregate query, the xStep() callback of the aggregate function
4078 ** implementation is never called and xFinal() is called exactly once.
4079 ** In those cases, sqlite3_aggregate_context() might be called for the
4080 ** first time from within xFinal().)^
4081 **
4082 ** ^The sqlite3_aggregate_context(C,N) routine returns a NULL pointer
4083 ** when first called if N is less than or equal to zero or if a memory
4084 ** allocate error occurs.
4085 **
4086 ** ^(The amount of space allocated by sqlite3_aggregate_context(C,N) is
4087 ** determined by the N parameter on first successful call. Changing the
4088 ** value of N in subsequent call to sqlite3_aggregate_context() within
4089 ** the same aggregate function instance will not resize the memory
4090 ** allocation.)^ Within the xFinal callback, it is customary to set
4091 ** N=0 in calls to sqlite3_aggregate_context(C,N) so that no
4092 ** pointless memory allocations occur.
4093 **
4094 ** ^SQLite automatically frees the memory allocated by
4095 ** sqlite3_aggregate_context() when the aggregate query concludes.
4096 **
4097 ** The first parameter must be a copy of the
@@ -6377,11 +6381,11 @@
6381 ** intact. If the requested page is not already in the cache, then the
6382 ** cache implementation should use the value of the createFlag
6383 ** parameter to help it determined what action to take:
6384 **
6385 ** <table border=1 width=85% align=center>
6386 ** <tr><th> createFlag <th> Behavior when page is not already in cache
6387 ** <tr><td> 0 <td> Do not allocate a new page. Return NULL.
6388 ** <tr><td> 1 <td> Allocate a new page if it easy and convenient to do so.
6389 ** Otherwise return NULL.
6390 ** <tr><td> 2 <td> Make every effort to allocate a new page. Only return
6391 ** NULL if allocating a new page is effectively impossible.
6392

Keyboard Shortcuts

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