Fossil SCM

Update to the latest SQLite 3.8.0 beta for testing.

drh 2013-08-22 03:20 trunk
Commit 3c5f1f08d81fe8b36209dc62d16d606186cfd98b
3 files changed -1 +154 -181 +1 -1
--- src/shell.c
+++ src/shell.c
@@ -3186,11 +3186,10 @@
31863186
** we do the actual processing of arguments later in a second pass.
31873187
*/
31883188
stdin_is_interactive = 0;
31893189
}else if( strcmp(z,"-heap")==0 ){
31903190
#if defined(SQLITE_ENABLE_MEMSYS3) || defined(SQLITE_ENABLE_MEMSYS5)
3191
- int j, c;
31923191
const char *zSize;
31933192
sqlite3_int64 szHeap;
31943193
31953194
zSize = cmdline_option_value(argc, argv, ++i);
31963195
szHeap = integerValue(zSize);
31973196
--- src/shell.c
+++ src/shell.c
@@ -3186,11 +3186,10 @@
3186 ** we do the actual processing of arguments later in a second pass.
3187 */
3188 stdin_is_interactive = 0;
3189 }else if( strcmp(z,"-heap")==0 ){
3190 #if defined(SQLITE_ENABLE_MEMSYS3) || defined(SQLITE_ENABLE_MEMSYS5)
3191 int j, c;
3192 const char *zSize;
3193 sqlite3_int64 szHeap;
3194
3195 zSize = cmdline_option_value(argc, argv, ++i);
3196 szHeap = integerValue(zSize);
3197
--- src/shell.c
+++ src/shell.c
@@ -3186,11 +3186,10 @@
3186 ** we do the actual processing of arguments later in a second pass.
3187 */
3188 stdin_is_interactive = 0;
3189 }else if( strcmp(z,"-heap")==0 ){
3190 #if defined(SQLITE_ENABLE_MEMSYS3) || defined(SQLITE_ENABLE_MEMSYS5)
 
3191 const char *zSize;
3192 sqlite3_int64 szHeap;
3193
3194 zSize = cmdline_option_value(argc, argv, ++i);
3195 szHeap = integerValue(zSize);
3196
+154 -181
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -656,11 +656,11 @@
656656
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
657657
** [sqlite_version()] and [sqlite_source_id()].
658658
*/
659659
#define SQLITE_VERSION "3.8.0"
660660
#define SQLITE_VERSION_NUMBER 3008000
661
-#define SQLITE_SOURCE_ID "2013-08-20 03:13:51 7f72fc4f47445a2c01910b268335873de9f75059"
661
+#define SQLITE_SOURCE_ID "2013-08-22 02:56:28 0775501acf152dcbf4dd039f4511f3d8c4330d85"
662662
663663
/*
664664
** CAPI3REF: Run-Time Library Version Numbers
665665
** KEYWORDS: sqlite3_version, sqlite3_sourceid
666666
**
@@ -9288,12 +9288,12 @@
92889288
#define PAGER_JOURNALMODE_WAL 5 /* Use write-ahead logging */
92899289
92909290
/*
92919291
** Flags that make up the mask passed to sqlite3PagerAcquire().
92929292
*/
9293
-#define PAGER_ACQUIRE_NOCONTENT 0x01 /* Do not load data from disk */
9294
-#define PAGER_ACQUIRE_READONLY 0x02 /* Read-only page is acceptable */
9293
+#define PAGER_GET_NOCONTENT 0x01 /* Do not load data from disk */
9294
+#define PAGER_GET_READONLY 0x02 /* Read-only page is acceptable */
92959295
92969296
/*
92979297
** Flags for sqlite3PagerSetFlags()
92989298
*/
92999299
#define PAGER_SYNCHRONOUS_OFF 0x01 /* PRAGMA synchronous=OFF */
@@ -11645,14 +11645,15 @@
1164511645
char *zBase; /* A base allocation. Not from malloc. */
1164611646
char *zText; /* The string collected so far */
1164711647
int nChar; /* Length of the string so far */
1164811648
int nAlloc; /* Amount of space allocated in zText */
1164911649
int mxAlloc; /* Maximum allowed string length */
11650
- u8 mallocFailed; /* Becomes true if any memory allocation fails */
1165111650
u8 useMalloc; /* 0: none, 1: sqlite3DbMalloc, 2: sqlite3_malloc */
11652
- u8 tooBig; /* Becomes true if string size exceeds limits */
11651
+ u8 accError; /* STRACCUM_NOMEM or STRACCUM_TOOBIG */
1165311652
};
11653
+#define STRACCUM_NOMEM 1
11654
+#define STRACCUM_TOOBIG 2
1165411655
1165511656
/*
1165611657
** A pointer to this structure is used to communicate information
1165711658
** from sqlite3Init and OP_ParseSchema into the sqlite3InitCallback.
1165811659
*/
@@ -12373,17 +12374,18 @@
1237312374
# define sqlite3VtabSavepoint(X, Y, Z) SQLITE_OK
1237412375
# define sqlite3GetVTable(X,Y) ((VTable*)0)
1237512376
#else
1237612377
SQLITE_PRIVATE void sqlite3VtabClear(sqlite3 *db, Table*);
1237712378
SQLITE_PRIVATE void sqlite3VtabDisconnect(sqlite3 *db, Table *p);
12378
-SQLITE_PRIVATE int sqlite3VtabSync(sqlite3 *db, char **);
12379
+SQLITE_PRIVATE int sqlite3VtabSync(sqlite3 *db, Vdbe*);
1237912380
SQLITE_PRIVATE int sqlite3VtabRollback(sqlite3 *db);
1238012381
SQLITE_PRIVATE int sqlite3VtabCommit(sqlite3 *db);
1238112382
SQLITE_PRIVATE void sqlite3VtabLock(VTable *);
1238212383
SQLITE_PRIVATE void sqlite3VtabUnlock(VTable *);
1238312384
SQLITE_PRIVATE void sqlite3VtabUnlockList(sqlite3*);
1238412385
SQLITE_PRIVATE int sqlite3VtabSavepoint(sqlite3 *, int, int);
12386
+SQLITE_PRIVATE void sqlite3VtabImportErrmsg(Vdbe*, sqlite3_vtab*);
1238512387
SQLITE_PRIVATE VTable *sqlite3GetVTable(sqlite3*, Table*);
1238612388
# define sqlite3VtabInSync(db) ((db)->nVTrans>0 && (db)->aVTrans==0)
1238712389
#endif
1238812390
SQLITE_PRIVATE void sqlite3VtabMakeWritable(Parse*,Table*);
1238912391
SQLITE_PRIVATE void sqlite3VtabBeginParse(Parse*, Token*, Token*, Token*, int);
@@ -19899,11 +19901,11 @@
1989919901
zOut = buf;
1990019902
}else{
1990119903
nOut = precision + 10;
1990219904
zOut = zExtra = sqlite3Malloc( nOut );
1990319905
if( zOut==0 ){
19904
- pAccum->mallocFailed = 1;
19906
+ pAccum->accError = STRACCUM_NOMEM;
1990519907
return;
1990619908
}
1990719909
}
1990819910
bufpt = &zOut[nOut-1];
1990919911
if( xtype==etORDINAL ){
@@ -20011,11 +20013,11 @@
2001120013
e2 = exp;
2001220014
}
2001320015
if( MAX(e2,0)+precision+width > etBUFSIZE - 15 ){
2001420016
bufpt = zExtra = sqlite3Malloc( MAX(e2,0)+precision+width+15 );
2001520017
if( bufpt==0 ){
20016
- pAccum->mallocFailed = 1;
20018
+ pAccum->accError = STRACCUM_NOMEM;
2001720019
return;
2001820020
}
2001920021
}
2002020022
zOut = bufpt;
2002120023
nsd = 16 + flag_altform2*10;
@@ -20146,11 +20148,11 @@
2014620148
needQuote = !isnull && xtype==etSQLESCAPE2;
2014720149
n += i + 1 + needQuote*2;
2014820150
if( n>etBUFSIZE ){
2014920151
bufpt = zExtra = sqlite3Malloc( n );
2015020152
if( bufpt==0 ){
20151
- pAccum->mallocFailed = 1;
20153
+ pAccum->accError = STRACCUM_NOMEM;
2015220154
return;
2015320155
}
2015420156
}else{
2015520157
bufpt = buf;
2015620158
}
@@ -20224,26 +20226,24 @@
2022420226
/*
2022520227
** Append N bytes of text from z to the StrAccum object.
2022620228
*/
2022720229
SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum *p, const char *z, int N){
2022820230
assert( z!=0 || N==0 );
20229
- if( p->tooBig | p->mallocFailed ){
20230
- testcase(p->tooBig);
20231
- testcase(p->mallocFailed);
20231
+ if( p->accError ){
20232
+ testcase(p->accError==STRACCUM_TOOBIG);
20233
+ testcase(p->accError==STRACCUM_NOMEM);
2023220234
return;
2023320235
}
2023420236
assert( p->zText!=0 || p->nChar==0 );
20235
- if( N<0 ){
20237
+ if( N<=0 ){
20238
+ if( N==0 || z[0]==0 ) return;
2023620239
N = sqlite3Strlen30(z);
2023720240
}
20238
- if( N==0 || NEVER(z==0) ){
20239
- return;
20240
- }
2024120241
if( p->nChar+N >= p->nAlloc ){
2024220242
char *zNew;
2024320243
if( !p->useMalloc ){
20244
- p->tooBig = 1;
20244
+ p->accError = STRACCUM_TOOBIG;
2024520245
N = p->nAlloc - p->nChar - 1;
2024620246
if( N<=0 ){
2024720247
return;
2024820248
}
2024920249
}else{
@@ -20250,11 +20250,11 @@
2025020250
char *zOld = (p->zText==p->zBase ? 0 : p->zText);
2025120251
i64 szNew = p->nChar;
2025220252
szNew += N + 1;
2025320253
if( szNew > p->mxAlloc ){
2025420254
sqlite3StrAccumReset(p);
20255
- p->tooBig = 1;
20255
+ p->accError = STRACCUM_TOOBIG;
2025620256
return;
2025720257
}else{
2025820258
p->nAlloc = (int)szNew;
2025920259
}
2026020260
if( p->useMalloc==1 ){
@@ -20264,11 +20264,11 @@
2026420264
}
2026520265
if( zNew ){
2026620266
if( zOld==0 && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar);
2026720267
p->zText = zNew;
2026820268
}else{
20269
- p->mallocFailed = 1;
20269
+ p->accError = STRACCUM_NOMEM;
2027020270
sqlite3StrAccumReset(p);
2027120271
return;
2027220272
}
2027320273
}
2027420274
}
@@ -20292,11 +20292,11 @@
2029220292
p->zText = sqlite3_malloc(p->nChar+1);
2029320293
}
2029420294
if( p->zText ){
2029520295
memcpy(p->zText, p->zBase, p->nChar+1);
2029620296
}else{
20297
- p->mallocFailed = 1;
20297
+ p->accError = STRACCUM_NOMEM;
2029820298
}
2029920299
}
2030020300
}
2030120301
return p->zText;
2030220302
}
@@ -20323,12 +20323,11 @@
2032320323
p->db = 0;
2032420324
p->nChar = 0;
2032520325
p->nAlloc = n;
2032620326
p->mxAlloc = mx;
2032720327
p->useMalloc = 1;
20328
- p->tooBig = 0;
20329
- p->mallocFailed = 0;
20328
+ p->accError = 0;
2033020329
}
2033120330
2033220331
/*
2033320332
** Print into memory obtained from sqliteMalloc(). Use the internal
2033420333
** %-conversion extensions.
@@ -20341,11 +20340,11 @@
2034120340
sqlite3StrAccumInit(&acc, zBase, sizeof(zBase),
2034220341
db->aLimit[SQLITE_LIMIT_LENGTH]);
2034320342
acc.db = db;
2034420343
sqlite3VXPrintf(&acc, 1, zFormat, ap);
2034520344
z = sqlite3StrAccumFinish(&acc);
20346
- if( acc.mallocFailed ){
20345
+ if( acc.accError==STRACCUM_NOMEM ){
2034720346
db->mallocFailed = 1;
2034820347
}
2034920348
return z;
2035020349
}
2035120350
@@ -20538,28 +20537,15 @@
2053820537
unsigned char i, j; /* State variables */
2053920538
unsigned char s[256]; /* State variables */
2054020539
} sqlite3Prng;
2054120540
2054220541
/*
20543
-** Get a single 8-bit random value from the RC4 PRNG. The Mutex
20544
-** must be held while executing this routine.
20545
-**
20546
-** Why not just use a library random generator like lrand48() for this?
20547
-** Because the OP_NewRowid opcode in the VDBE depends on having a very
20548
-** good source of random numbers. The lrand48() library function may
20549
-** well be good enough. But maybe not. Or maybe lrand48() has some
20550
-** subtle problems on some systems that could cause problems. It is hard
20551
-** to know. To minimize the risk of problems due to bad lrand48()
20552
-** implementations, SQLite uses this random number generator based
20553
-** on RC4, which we know works very well.
20554
-**
20555
-** (Later): Actually, OP_NewRowid does not depend on a good source of
20556
-** randomness any more. But we will leave this code in all the same.
20542
+** Return N random bytes.
2055720543
*/
20558
-static u8 randomByte(void){
20544
+SQLITE_API void sqlite3_randomness(int N, void *pBuf){
2055920545
unsigned char t;
20560
-
20546
+ unsigned char *zBuf = pBuf;
2056120547
2056220548
/* The "wsdPrng" macro will resolve to the pseudo-random number generator
2056320549
** state vector. If writable static data is unsupported on the target,
2056420550
** we have to locate the state vector at run-time. In the more common
2056520551
** case where writable static data is supported, wsdPrng can refer directly
@@ -20570,10 +20556,14 @@
2057020556
# define wsdPrng p[0]
2057120557
#else
2057220558
# define wsdPrng sqlite3Prng
2057320559
#endif
2057420560
20561
+#if SQLITE_THREADSAFE
20562
+ sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_PRNG);
20563
+ sqlite3_mutex_enter(mutex);
20564
+#endif
2057520565
2057620566
/* Initialize the state of the random number generator once,
2057720567
** the first time this routine is called. The seed value does
2057820568
** not need to contain a lot of randomness since we are not
2057920569
** trying to do secure encryption or anything like that...
@@ -20598,32 +20588,18 @@
2059820588
wsdPrng.s[i] = t;
2059920589
}
2060020590
wsdPrng.isInit = 1;
2060120591
}
2060220592
20603
- /* Generate and return single random byte
20604
- */
20605
- wsdPrng.i++;
20606
- t = wsdPrng.s[wsdPrng.i];
20607
- wsdPrng.j += t;
20608
- wsdPrng.s[wsdPrng.i] = wsdPrng.s[wsdPrng.j];
20609
- wsdPrng.s[wsdPrng.j] = t;
20610
- t += wsdPrng.s[wsdPrng.i];
20611
- return wsdPrng.s[t];
20612
-}
20613
-
20614
-/*
20615
-** Return N random bytes.
20616
-*/
20617
-SQLITE_API void sqlite3_randomness(int N, void *pBuf){
20618
- unsigned char *zBuf = pBuf;
20619
-#if SQLITE_THREADSAFE
20620
- sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_PRNG);
20621
-#endif
20622
- sqlite3_mutex_enter(mutex);
2062320593
while( N-- ){
20624
- *(zBuf++) = randomByte();
20594
+ wsdPrng.i++;
20595
+ t = wsdPrng.s[wsdPrng.i];
20596
+ wsdPrng.j += t;
20597
+ wsdPrng.s[wsdPrng.i] = wsdPrng.s[wsdPrng.j];
20598
+ wsdPrng.s[wsdPrng.j] = t;
20599
+ t += wsdPrng.s[wsdPrng.i];
20600
+ *(zBuf++) = wsdPrng.s[t];
2062520601
}
2062620602
sqlite3_mutex_leave(mutex);
2062720603
}
2062820604
2062920605
#ifndef SQLITE_OMIT_BUILTIN_TEST
@@ -39378,17 +39354,21 @@
3937839354
** * The page-number is less than or equal to PagerSavepoint.nOrig, and
3937939355
** * The bit corresponding to the page-number is not set in
3938039356
** PagerSavepoint.pInSavepoint.
3938139357
*/
3938239358
static int subjRequiresPage(PgHdr *pPg){
39383
- Pgno pgno = pPg->pgno;
3938439359
Pager *pPager = pPg->pPager;
39360
+ PagerSavepoint *p;
39361
+ Pgno pgno;
3938539362
int i;
39386
- for(i=0; i<pPager->nSavepoint; i++){
39387
- PagerSavepoint *p = &pPager->aSavepoint[i];
39388
- if( p->nOrig>=pgno && 0==sqlite3BitvecTest(p->pInSavepoint, pgno) ){
39389
- return 1;
39363
+ if( pPager->nSavepoint ){
39364
+ pgno = pPg->pgno;
39365
+ for(i=0; i<pPager->nSavepoint; i++){
39366
+ p = &pPager->aSavepoint[i];
39367
+ if( p->nOrig>=pgno && 0==sqlite3BitvecTest(p->pInSavepoint, pgno) ){
39368
+ return 1;
39369
+ }
3939039370
}
3939139371
}
3939239372
return 0;
3939339373
}
3939439374
@@ -41230,16 +41210,10 @@
4123041210
int pgsz = pPager->pageSize; /* Number of bytes to read */
4123141211
4123241212
assert( pPager->eState>=PAGER_READER && !MEMDB );
4123341213
assert( isOpen(pPager->fd) );
4123441214
41235
- if( NEVER(!isOpen(pPager->fd)) ){
41236
- assert( pPager->tempFile );
41237
- memset(pPg->pData, 0, pPager->pageSize);
41238
- return SQLITE_OK;
41239
- }
41240
-
4124141215
#ifndef SQLITE_OMIT_WAL
4124241216
if( iFrame ){
4124341217
/* Try to pull the page from the write-ahead log. */
4124441218
rc = sqlite3WalReadFrame(pPager->pWal, iFrame, pgsz, pPg->pData);
4124541219
}else
@@ -43589,23 +43563,23 @@
4358943563
*/
4359043564
SQLITE_PRIVATE int sqlite3PagerAcquire(
4359143565
Pager *pPager, /* The pager open on the database file */
4359243566
Pgno pgno, /* Page number to fetch */
4359343567
DbPage **ppPage, /* Write a pointer to the page here */
43594
- int flags /* PAGER_ACQUIRE_XXX flags */
43568
+ int flags /* PAGER_GET_XXX flags */
4359543569
){
4359643570
int rc = SQLITE_OK;
4359743571
PgHdr *pPg = 0;
4359843572
u32 iFrame = 0; /* Frame to read from WAL file */
43599
- const int noContent = (flags & PAGER_ACQUIRE_NOCONTENT);
43573
+ const int noContent = (flags & PAGER_GET_NOCONTENT);
4360043574
4360143575
/* It is acceptable to use a read-only (mmap) page for any page except
4360243576
** page 1 if there is no write-transaction open or the ACQUIRE_READONLY
4360343577
** flag was specified by the caller. And so long as the db is not a
4360443578
** temporary or in-memory database. */
4360543579
const int bMmapOk = (pgno!=1 && USEFETCH(pPager)
43606
- && (pPager->eState==PAGER_READER || (flags & PAGER_ACQUIRE_READONLY))
43580
+ && (pPager->eState==PAGER_READER || (flags & PAGER_GET_READONLY))
4360743581
#ifdef SQLITE_HAS_CODEC
4360843582
&& pPager->xCodec==0
4360943583
#endif
4361043584
);
4361143585
@@ -50544,11 +50518,12 @@
5054450518
assert( pPage->leaf==0 || pPage->leaf==1 );
5054550519
n = pPage->childPtrSize;
5054650520
assert( n==4-4*pPage->leaf );
5054750521
if( pPage->intKey ){
5054850522
if( pPage->hasData ){
50549
- n += getVarint32(&pCell[n], nPayload);
50523
+ assert( n==0 );
50524
+ n = getVarint32(pCell, nPayload);
5055050525
}else{
5055150526
nPayload = 0;
5055250527
}
5055350528
n += getVarint(&pCell[n], (u64*)&pInfo->nKey);
5055450529
pInfo->nData = nPayload;
@@ -51188,19 +51163,16 @@
5118851163
*/
5118951164
static int btreeGetPage(
5119051165
BtShared *pBt, /* The btree */
5119151166
Pgno pgno, /* Number of the page to fetch */
5119251167
MemPage **ppPage, /* Return the page in this parameter */
51193
- int noContent, /* Do not load page content if true */
51194
- int bReadonly /* True if a read-only (mmap) page is ok */
51168
+ int flags /* PAGER_GET_NOCONTENT or PAGER_GET_READONLY */
5119551169
){
5119651170
int rc;
5119751171
DbPage *pDbPage;
51198
- int flags = (noContent ? PAGER_ACQUIRE_NOCONTENT : 0)
51199
- | (bReadonly ? PAGER_ACQUIRE_READONLY : 0);
5120051172
51201
- assert( noContent==0 || bReadonly==0 );
51173
+ assert( flags==0 || flags==PAGER_GET_NOCONTENT || flags==PAGER_GET_READONLY );
5120251174
assert( sqlite3_mutex_held(pBt->mutex) );
5120351175
rc = sqlite3PagerAcquire(pBt->pPager, pgno, (DbPage**)&pDbPage, flags);
5120451176
if( rc ) return rc;
5120551177
*ppPage = btreePageFromDbPage(pDbPage, pgno, pBt);
5120651178
return SQLITE_OK;
@@ -51244,19 +51216,20 @@
5124451216
*/
5124551217
static int getAndInitPage(
5124651218
BtShared *pBt, /* The database file */
5124751219
Pgno pgno, /* Number of the page to get */
5124851220
MemPage **ppPage, /* Write the page pointer here */
51249
- int bReadonly /* True if a read-only (mmap) page is ok */
51221
+ int bReadonly /* PAGER_GET_READONLY or 0 */
5125051222
){
5125151223
int rc;
5125251224
assert( sqlite3_mutex_held(pBt->mutex) );
51225
+ assert( bReadonly==PAGER_GET_READONLY || bReadonly==0 );
5125351226
5125451227
if( pgno>btreePagecount(pBt) ){
5125551228
rc = SQLITE_CORRUPT_BKPT;
5125651229
}else{
51257
- rc = btreeGetPage(pBt, pgno, ppPage, 0, bReadonly);
51230
+ rc = btreeGetPage(pBt, pgno, ppPage, bReadonly);
5125851231
if( rc==SQLITE_OK ){
5125951232
rc = btreeInitPage(*ppPage);
5126051233
if( rc!=SQLITE_OK ){
5126151234
releasePage(*ppPage);
5126251235
}
@@ -51985,11 +51958,11 @@
5198551958
5198651959
assert( sqlite3_mutex_held(pBt->mutex) );
5198751960
assert( pBt->pPage1==0 );
5198851961
rc = sqlite3PagerSharedLock(pBt->pPager);
5198951962
if( rc!=SQLITE_OK ) return rc;
51990
- rc = btreeGetPage(pBt, 1, &pPage1, 0, 0);
51963
+ rc = btreeGetPage(pBt, 1, &pPage1, 0);
5199151964
if( rc!=SQLITE_OK ) return rc;
5199251965
5199351966
/* Do some checking to help insure the file we opened really is
5199451967
** a valid database file.
5199551968
*/
@@ -52567,11 +52540,11 @@
5256752540
/* Fix the database pointer on page iPtrPage that pointed at iDbPage so
5256852541
** that it points at iFreePage. Also fix the pointer map entry for
5256952542
** iPtrPage.
5257052543
*/
5257152544
if( eType!=PTRMAP_ROOTPAGE ){
52572
- rc = btreeGetPage(pBt, iPtrPage, &pPtrPage, 0, 0);
52545
+ rc = btreeGetPage(pBt, iPtrPage, &pPtrPage, 0);
5257352546
if( rc!=SQLITE_OK ){
5257452547
return rc;
5257552548
}
5257652549
rc = sqlite3PagerWrite(pPtrPage->pDbPage);
5257752550
if( rc!=SQLITE_OK ){
@@ -52651,11 +52624,11 @@
5265152624
Pgno iFreePg; /* Index of free page to move pLastPg to */
5265252625
MemPage *pLastPg;
5265352626
u8 eMode = BTALLOC_ANY; /* Mode parameter for allocateBtreePage() */
5265452627
Pgno iNear = 0; /* nearby parameter for allocateBtreePage() */
5265552628
52656
- rc = btreeGetPage(pBt, iLastPg, &pLastPg, 0, 0);
52629
+ rc = btreeGetPage(pBt, iLastPg, &pLastPg, 0);
5265752630
if( rc!=SQLITE_OK ){
5265852631
return rc;
5265952632
}
5266052633
5266152634
/* If bCommit is zero, this loop runs exactly once and page pLastPg
@@ -53050,11 +53023,11 @@
5305053023
}
5305153024
5305253025
/* The rollback may have destroyed the pPage1->aData value. So
5305353026
** call btreeGetPage() on page 1 again to make
5305453027
** sure pPage1->aData is set correctly. */
53055
- if( btreeGetPage(pBt, 1, &pPage1, 0, 0)==SQLITE_OK ){
53028
+ if( btreeGetPage(pBt, 1, &pPage1, 0)==SQLITE_OK ){
5305653029
int nPage = get4byte(28+(u8*)pPage1->aData);
5305753030
testcase( nPage==0 );
5305853031
if( nPage==0 ) sqlite3PagerPagecount(pBt->pPager, &nPage);
5305953032
testcase( pBt->nPage!=nPage );
5306053033
pBt->nPage = nPage;
@@ -53485,11 +53458,11 @@
5348553458
}
5348653459
#endif
5348753460
5348853461
assert( next==0 || rc==SQLITE_DONE );
5348953462
if( rc==SQLITE_OK ){
53490
- rc = btreeGetPage(pBt, ovfl, &pPage, 0, (ppPage==0));
53463
+ rc = btreeGetPage(pBt, ovfl, &pPage, (ppPage==0) ? PAGER_GET_READONLY : 0);
5349153464
assert( rc==SQLITE_OK || pPage==0 );
5349253465
if( rc==SQLITE_OK ){
5349353466
next = get4byte(pPage->aData);
5349453467
}
5349553468
}
@@ -53707,11 +53680,11 @@
5370753680
#endif
5370853681
5370953682
{
5371053683
DbPage *pDbPage;
5371153684
rc = sqlite3PagerAcquire(pBt->pPager, nextPage, &pDbPage,
53712
- (eOp==0 ? PAGER_ACQUIRE_READONLY : 0)
53685
+ (eOp==0 ? PAGER_GET_READONLY : 0)
5371353686
);
5371453687
if( rc==SQLITE_OK ){
5371553688
aPayload = sqlite3PagerGetData(pDbPage);
5371653689
nextPage = get4byte(aPayload);
5371753690
rc = copyPayload(&aPayload[offset+4], pBuf, a, eOp, pDbPage);
@@ -53891,11 +53864,12 @@
5389153864
assert( pCur->iPage<BTCURSOR_MAX_DEPTH );
5389253865
assert( pCur->iPage>=0 );
5389353866
if( pCur->iPage>=(BTCURSOR_MAX_DEPTH-1) ){
5389453867
return SQLITE_CORRUPT_BKPT;
5389553868
}
53896
- rc = getAndInitPage(pBt, newPgno, &pNewPage, (pCur->wrFlag==0));
53869
+ rc = getAndInitPage(pBt, newPgno, &pNewPage,
53870
+ pCur->wrFlag==0 ? PAGER_GET_READONLY : 0);
5389753871
if( rc ) return rc;
5389853872
pCur->apPage[i+1] = pNewPage;
5389953873
pCur->aiIdx[i+1] = 0;
5390053874
pCur->iPage++;
5390153875
@@ -54008,11 +53982,12 @@
5400853982
pCur->iPage = 0;
5400953983
}else if( pCur->pgnoRoot==0 ){
5401053984
pCur->eState = CURSOR_INVALID;
5401153985
return SQLITE_OK;
5401253986
}else{
54013
- rc = getAndInitPage(pBt, pCur->pgnoRoot, &pCur->apPage[0], pCur->wrFlag==0);
53987
+ rc = getAndInitPage(pBt, pCur->pgnoRoot, &pCur->apPage[0],
53988
+ pCur->wrFlag==0 ? PAGER_GET_READONLY : 0);
5401453989
if( rc!=SQLITE_OK ){
5401553990
pCur->eState = CURSOR_INVALID;
5401653991
return rc;
5401753992
}
5401853993
pCur->iPage = 0;
@@ -54645,11 +54620,11 @@
5464554620
}
5464654621
testcase( iTrunk==mxPage );
5464754622
if( iTrunk>mxPage ){
5464854623
rc = SQLITE_CORRUPT_BKPT;
5464954624
}else{
54650
- rc = btreeGetPage(pBt, iTrunk, &pTrunk, 0, 0);
54625
+ rc = btreeGetPage(pBt, iTrunk, &pTrunk, 0);
5465154626
}
5465254627
if( rc ){
5465354628
pTrunk = 0;
5465454629
goto end_allocate_page;
5465554630
}
@@ -54709,11 +54684,11 @@
5470954684
if( iNewTrunk>mxPage ){
5471054685
rc = SQLITE_CORRUPT_BKPT;
5471154686
goto end_allocate_page;
5471254687
}
5471354688
testcase( iNewTrunk==mxPage );
54714
- rc = btreeGetPage(pBt, iNewTrunk, &pNewTrunk, 0, 0);
54689
+ rc = btreeGetPage(pBt, iNewTrunk, &pNewTrunk, 0);
5471554690
if( rc!=SQLITE_OK ){
5471654691
goto end_allocate_page;
5471754692
}
5471854693
rc = sqlite3PagerWrite(pNewTrunk->pDbPage);
5471954694
if( rc!=SQLITE_OK ){
@@ -54788,12 +54763,12 @@
5478854763
if( rc ) goto end_allocate_page;
5478954764
if( closest<k-1 ){
5479054765
memcpy(&aData[8+closest*4], &aData[4+k*4], 4);
5479154766
}
5479254767
put4byte(&aData[4], k-1);
54793
- noContent = !btreeGetHasContent(pBt, *pPgno);
54794
- rc = btreeGetPage(pBt, *pPgno, ppPage, noContent, 0);
54768
+ noContent = !btreeGetHasContent(pBt, *pPgno) ? PAGER_GET_NOCONTENT : 0;
54769
+ rc = btreeGetPage(pBt, *pPgno, ppPage, noContent);
5479554770
if( rc==SQLITE_OK ){
5479654771
rc = sqlite3PagerWrite((*ppPage)->pDbPage);
5479754772
if( rc!=SQLITE_OK ){
5479854773
releasePage(*ppPage);
5479954774
}
@@ -54821,11 +54796,11 @@
5482154796
** content for any page that really does lie past the end of the database
5482254797
** file on disk. So the effects of disabling the no-content optimization
5482354798
** here are confined to those pages that lie between the end of the
5482454799
** database image and the end of the database file.
5482554800
*/
54826
- int bNoContent = (0==IfNotOmitAV(pBt->bDoTruncate));
54801
+ int bNoContent = (0==IfNotOmitAV(pBt->bDoTruncate)) ? PAGER_GET_NOCONTENT : 0;
5482754802
5482854803
rc = sqlite3PagerWrite(pBt->pPage1->pDbPage);
5482954804
if( rc ) return rc;
5483054805
pBt->nPage++;
5483154806
if( pBt->nPage==PENDING_BYTE_PAGE(pBt) ) pBt->nPage++;
@@ -54837,11 +54812,11 @@
5483754812
** becomes a new pointer-map page, the second is used by the caller.
5483854813
*/
5483954814
MemPage *pPg = 0;
5484054815
TRACE(("ALLOCATE: %d from end of file (pointer-map page)\n", pBt->nPage));
5484154816
assert( pBt->nPage!=PENDING_BYTE_PAGE(pBt) );
54842
- rc = btreeGetPage(pBt, pBt->nPage, &pPg, bNoContent, 0);
54817
+ rc = btreeGetPage(pBt, pBt->nPage, &pPg, bNoContent);
5484354818
if( rc==SQLITE_OK ){
5484454819
rc = sqlite3PagerWrite(pPg->pDbPage);
5484554820
releasePage(pPg);
5484654821
}
5484754822
if( rc ) return rc;
@@ -54851,11 +54826,11 @@
5485154826
#endif
5485254827
put4byte(28 + (u8*)pBt->pPage1->aData, pBt->nPage);
5485354828
*pPgno = pBt->nPage;
5485454829
5485554830
assert( *pPgno!=PENDING_BYTE_PAGE(pBt) );
54856
- rc = btreeGetPage(pBt, *pPgno, ppPage, bNoContent, 0);
54831
+ rc = btreeGetPage(pBt, *pPgno, ppPage, bNoContent);
5485754832
if( rc ) return rc;
5485854833
rc = sqlite3PagerWrite((*ppPage)->pDbPage);
5485954834
if( rc!=SQLITE_OK ){
5486054835
releasePage(*ppPage);
5486154836
}
@@ -54919,11 +54894,11 @@
5491954894
5492054895
if( pBt->btsFlags & BTS_SECURE_DELETE ){
5492154896
/* If the secure_delete option is enabled, then
5492254897
** always fully overwrite deleted information with zeros.
5492354898
*/
54924
- if( (!pPage && ((rc = btreeGetPage(pBt, iPage, &pPage, 0, 0))!=0) )
54899
+ if( (!pPage && ((rc = btreeGetPage(pBt, iPage, &pPage, 0))!=0) )
5492554900
|| ((rc = sqlite3PagerWrite(pPage->pDbPage))!=0)
5492654901
){
5492754902
goto freepage_out;
5492854903
}
5492954904
memset(pPage->aData, 0, pPage->pBt->pageSize);
@@ -54946,11 +54921,11 @@
5494654921
*/
5494754922
if( nFree!=0 ){
5494854923
u32 nLeaf; /* Initial number of leaf cells on trunk page */
5494954924
5495054925
iTrunk = get4byte(&pPage1->aData[32]);
54951
- rc = btreeGetPage(pBt, iTrunk, &pTrunk, 0, 0);
54926
+ rc = btreeGetPage(pBt, iTrunk, &pTrunk, 0);
5495254927
if( rc!=SQLITE_OK ){
5495354928
goto freepage_out;
5495454929
}
5495554930
5495654931
nLeaf = get4byte(&pTrunk->aData[4]);
@@ -54992,11 +54967,11 @@
5499254967
** the page being freed as a leaf page of the first trunk in the free-list.
5499354968
** Possibly because the free-list is empty, or possibly because the
5499454969
** first trunk in the free-list is full. Either way, the page being freed
5499554970
** will become the new first trunk page in the free-list.
5499654971
*/
54997
- if( pPage==0 && SQLITE_OK!=(rc = btreeGetPage(pBt, iPage, &pPage, 0, 0)) ){
54972
+ if( pPage==0 && SQLITE_OK!=(rc = btreeGetPage(pBt, iPage, &pPage, 0)) ){
5499854973
goto freepage_out;
5499954974
}
5500054975
rc = sqlite3PagerWrite(pPage->pDbPage);
5500154976
if( rc!=SQLITE_OK ){
5500254977
goto freepage_out;
@@ -56891,11 +56866,11 @@
5689156866
if( rc!=SQLITE_OK ){
5689256867
return rc;
5689356868
}
5689456869
5689556870
/* Move the page currently at pgnoRoot to pgnoMove. */
56896
- rc = btreeGetPage(pBt, pgnoRoot, &pRoot, 0, 0);
56871
+ rc = btreeGetPage(pBt, pgnoRoot, &pRoot, 0);
5689756872
if( rc!=SQLITE_OK ){
5689856873
return rc;
5689956874
}
5690056875
rc = ptrmapGet(pBt, pgnoRoot, &eType, &iPtrPage);
5690156876
if( eType==PTRMAP_ROOTPAGE || eType==PTRMAP_FREEPAGE ){
@@ -56912,11 +56887,11 @@
5691256887
5691356888
/* Obtain the page at pgnoRoot */
5691456889
if( rc!=SQLITE_OK ){
5691556890
return rc;
5691656891
}
56917
- rc = btreeGetPage(pBt, pgnoRoot, &pRoot, 0, 0);
56892
+ rc = btreeGetPage(pBt, pgnoRoot, &pRoot, 0);
5691856893
if( rc!=SQLITE_OK ){
5691956894
return rc;
5692056895
}
5692156896
rc = sqlite3PagerWrite(pRoot->pDbPage);
5692256897
if( rc!=SQLITE_OK ){
@@ -57090,11 +57065,11 @@
5709057065
if( NEVER(pBt->pCursor) ){
5709157066
sqlite3ConnectionBlocked(p->db, pBt->pCursor->pBtree->db);
5709257067
return SQLITE_LOCKED_SHAREDCACHE;
5709357068
}
5709457069
57095
- rc = btreeGetPage(pBt, (Pgno)iTable, &pPage, 0, 0);
57070
+ rc = btreeGetPage(pBt, (Pgno)iTable, &pPage, 0);
5709657071
if( rc ) return rc;
5709757072
rc = sqlite3BtreeClearTable(p, iTable, 0);
5709857073
if( rc ){
5709957074
releasePage(pPage);
5710057075
return rc;
@@ -57125,21 +57100,21 @@
5712557100
** number in the database. So move the page that does into the
5712657101
** gap left by the deleted root-page.
5712757102
*/
5712857103
MemPage *pMove;
5712957104
releasePage(pPage);
57130
- rc = btreeGetPage(pBt, maxRootPgno, &pMove, 0, 0);
57105
+ rc = btreeGetPage(pBt, maxRootPgno, &pMove, 0);
5713157106
if( rc!=SQLITE_OK ){
5713257107
return rc;
5713357108
}
5713457109
rc = relocatePage(pBt, pMove, PTRMAP_ROOTPAGE, 0, iTable, 0);
5713557110
releasePage(pMove);
5713657111
if( rc!=SQLITE_OK ){
5713757112
return rc;
5713857113
}
5713957114
pMove = 0;
57140
- rc = btreeGetPage(pBt, maxRootPgno, &pMove, 0, 0);
57115
+ rc = btreeGetPage(pBt, maxRootPgno, &pMove, 0);
5714157116
freePage(pMove, &rc);
5714257117
releasePage(pMove);
5714357118
if( rc!=SQLITE_OK ){
5714457119
return rc;
5714557120
}
@@ -57350,11 +57325,11 @@
5735057325
if( zMsg1 ){
5735157326
sqlite3StrAccumAppend(&pCheck->errMsg, zMsg1, -1);
5735257327
}
5735357328
sqlite3VXPrintf(&pCheck->errMsg, 1, zFormat, ap);
5735457329
va_end(ap);
57355
- if( pCheck->errMsg.mallocFailed ){
57330
+ if( pCheck->errMsg.accError==STRACCUM_NOMEM ){
5735657331
pCheck->mallocFailed = 1;
5735757332
}
5735857333
}
5735957334
#endif /* SQLITE_OMIT_INTEGRITY_CHECK */
5736057335
@@ -57547,11 +57522,11 @@
5754757522
*/
5754857523
pBt = pCheck->pBt;
5754957524
usableSize = pBt->usableSize;
5755057525
if( iPage==0 ) return 0;
5755157526
if( checkRef(pCheck, iPage, zParentContext) ) return 0;
57552
- if( (rc = btreeGetPage(pBt, (Pgno)iPage, &pPage, 0, 0))!=0 ){
57527
+ if( (rc = btreeGetPage(pBt, (Pgno)iPage, &pPage, 0))!=0 ){
5755357528
checkAppendMsg(pCheck, zContext,
5755457529
"unable to get the page. error code=%d", rc);
5755557530
return 0;
5755657531
}
5755757532
@@ -58506,11 +58481,11 @@
5850658481
for(ii=0; (nPage<0 || ii<nPage) && p->iNext<=(Pgno)nSrcPage && !rc; ii++){
5850758482
const Pgno iSrcPg = p->iNext; /* Source page number */
5850858483
if( iSrcPg!=PENDING_BYTE_PAGE(p->pSrc->pBt) ){
5850958484
DbPage *pSrcPg; /* Source page object */
5851058485
rc = sqlite3PagerAcquire(pSrcPager, iSrcPg, &pSrcPg,
58511
- PAGER_ACQUIRE_READONLY);
58486
+ PAGER_GET_READONLY);
5851258487
if( rc==SQLITE_OK ){
5851358488
rc = backupOnePage(p, iSrcPg, sqlite3PagerGetData(pSrcPg), 0);
5851458489
sqlite3PagerUnref(pSrcPg);
5851558490
}
5851658491
}
@@ -59661,38 +59636,33 @@
5966159636
/* If one value is a number and the other is not, the number is less.
5966259637
** If both are numbers, compare as reals if one is a real, or as integers
5966359638
** if both values are integers.
5966459639
*/
5966559640
if( combined_flags&(MEM_Int|MEM_Real) ){
59666
- if( !(f1&(MEM_Int|MEM_Real)) ){
59667
- return 1;
59668
- }
59669
- if( !(f2&(MEM_Int|MEM_Real)) ){
59670
- return -1;
59671
- }
59672
- if( (f1 & f2 & MEM_Int)==0 ){
59673
- double r1, r2;
59674
- if( (f1&MEM_Real)==0 ){
59675
- r1 = (double)pMem1->u.i;
59676
- }else{
59677
- r1 = pMem1->r;
59678
- }
59679
- if( (f2&MEM_Real)==0 ){
59680
- r2 = (double)pMem2->u.i;
59681
- }else{
59682
- r2 = pMem2->r;
59683
- }
59684
- if( r1<r2 ) return -1;
59685
- if( r1>r2 ) return 1;
59686
- return 0;
59687
- }else{
59688
- assert( f1&MEM_Int );
59689
- assert( f2&MEM_Int );
59641
+ double r1, r2;
59642
+ if( (f1 & f2 & MEM_Int)!=0 ){
5969059643
if( pMem1->u.i < pMem2->u.i ) return -1;
5969159644
if( pMem1->u.i > pMem2->u.i ) return 1;
5969259645
return 0;
5969359646
}
59647
+ if( (f1&MEM_Real)!=0 ){
59648
+ r1 = pMem1->r;
59649
+ }else if( (f1&MEM_Int)!=0 ){
59650
+ r1 = (double)pMem1->u.i;
59651
+ }else{
59652
+ return 1;
59653
+ }
59654
+ if( (f2&MEM_Real)!=0 ){
59655
+ r2 = pMem2->r;
59656
+ }else if( (f2&MEM_Int)!=0 ){
59657
+ r2 = (double)pMem2->u.i;
59658
+ }else{
59659
+ return -1;
59660
+ }
59661
+ if( r1<r2 ) return -1;
59662
+ if( r1>r2 ) return 1;
59663
+ return 0;
5969459664
}
5969559665
5969659666
/* If one value is a string and the other is a blob, the string is less.
5969759667
** If both are strings, compare using the collating functions.
5969859668
*/
@@ -61789,11 +61759,11 @@
6178961759
** virtual module tables written in this transaction. This has to
6179061760
** be done before determining whether a master journal file is
6179161761
** required, as an xSync() callback may add an attached database
6179261762
** to the transaction.
6179361763
*/
61794
- rc = sqlite3VtabSync(db, &p->zErrMsg);
61764
+ rc = sqlite3VtabSync(db, p);
6179561765
6179661766
/* This loop determines (a) if the commit hook should be invoked and
6179761767
** (b) how many database files have open write transactions, not
6179861768
** including the temp database. (b) is important because if more than
6179961769
** one database file has an open write transaction, a master journal
@@ -63329,10 +63299,25 @@
6332963299
}else{
6333063300
v->expmask |= ((u32)1 << (iVar-1));
6333163301
}
6333263302
}
6333363303
63304
+#ifndef SQLITE_OMIT_VIRTUALTABLE
63305
+/*
63306
+** Transfer error message text from an sqlite3_vtab.zErrMsg (text stored
63307
+** in memory obtained from sqlite3_malloc) into a Vdbe.zErrMsg (text stored
63308
+** in memory obtained from sqlite3DbMalloc).
63309
+*/
63310
+SQLITE_PRIVATE void sqlite3VtabImportErrmsg(Vdbe *p, sqlite3_vtab *pVtab){
63311
+ sqlite3 *db = p->db;
63312
+ sqlite3DbFree(db, p->zErrMsg);
63313
+ p->zErrMsg = sqlite3DbStrDup(db, pVtab->zErrMsg);
63314
+ sqlite3_free(pVtab->zErrMsg);
63315
+ pVtab->zErrMsg = 0;
63316
+}
63317
+#endif /* SQLITE_OMIT_VIRTUALTABLE */
63318
+
6333463319
/************** End of vdbeaux.c *********************************************/
6333563320
/************** Begin file vdbeapi.c *****************************************/
6333663321
/*
6333763322
** 2004 May 26
6333863323
**
@@ -65518,23 +65503,10 @@
6551865503
assert( n==(db->nSavepoint + db->isTransactionSavepoint) );
6551965504
return 1;
6552065505
}
6552165506
#endif
6552265507
65523
-/*
65524
-** Transfer error message text from an sqlite3_vtab.zErrMsg (text stored
65525
-** in memory obtained from sqlite3_malloc) into a Vdbe.zErrMsg (text stored
65526
-** in memory obtained from sqlite3DbMalloc).
65527
-*/
65528
-static void importVtabErrMsg(Vdbe *p, sqlite3_vtab *pVtab){
65529
- sqlite3 *db = p->db;
65530
- sqlite3DbFree(db, p->zErrMsg);
65531
- p->zErrMsg = sqlite3DbStrDup(db, pVtab->zErrMsg);
65532
- sqlite3_free(pVtab->zErrMsg);
65533
- pVtab->zErrMsg = 0;
65534
-}
65535
-
6553665508
6553765509
/*
6553865510
** Execute as much of a VDBE program as we can then return.
6553965511
**
6554065512
** sqlite3VdbeMakeReady() must be called before this routine in order to
@@ -69880,11 +69852,11 @@
6988069852
}else if( u.bn.pC->pVtabCursor ){
6988169853
u.bn.pVtab = u.bn.pC->pVtabCursor->pVtab;
6988269854
u.bn.pModule = u.bn.pVtab->pModule;
6988369855
assert( u.bn.pModule->xRowid );
6988469856
rc = u.bn.pModule->xRowid(u.bn.pC->pVtabCursor, &u.bn.v);
69885
- importVtabErrMsg(p, u.bn.pVtab);
69857
+ sqlite3VtabImportErrmsg(p, u.bn.pVtab);
6988669858
#endif /* SQLITE_OMIT_VIRTUALTABLE */
6988769859
}else{
6988869860
assert( u.bn.pC->pCursor!=0 );
6988969861
rc = sqlite3VdbeCursorMoveto(u.bn.pC);
6989069862
if( rc ) goto abort_due_to_error;
@@ -71321,11 +71293,11 @@
7132171293
#if 0 /* local variables moved into u.cl */
7132271294
VTable *pVTab;
7132371295
#endif /* local variables moved into u.cl */
7132471296
u.cl.pVTab = pOp->p4.pVtab;
7132571297
rc = sqlite3VtabBegin(db, u.cl.pVTab);
71326
- if( u.cl.pVTab ) importVtabErrMsg(p, u.cl.pVTab->pVtab);
71298
+ if( u.cl.pVTab ) sqlite3VtabImportErrmsg(p, u.cl.pVTab->pVtab);
7132771299
break;
7132871300
}
7132971301
#endif /* SQLITE_OMIT_VIRTUALTABLE */
7133071302
7133171303
#ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -71374,11 +71346,11 @@
7137471346
u.cm.pVtabCursor = 0;
7137571347
u.cm.pVtab = pOp->p4.pVtab->pVtab;
7137671348
u.cm.pModule = (sqlite3_module *)u.cm.pVtab->pModule;
7137771349
assert(u.cm.pVtab && u.cm.pModule);
7137871350
rc = u.cm.pModule->xOpen(u.cm.pVtab, &u.cm.pVtabCursor);
71379
- importVtabErrMsg(p, u.cm.pVtab);
71351
+ sqlite3VtabImportErrmsg(p, u.cm.pVtab);
7138071352
if( SQLITE_OK==rc ){
7138171353
/* Initialize sqlite3_vtab_cursor base class */
7138271354
u.cm.pVtabCursor->pVtab = u.cm.pVtab;
7138371355
7138471356
/* Initialize vdbe cursor object */
@@ -71454,11 +71426,11 @@
7145471426
}
7145571427
7145671428
p->inVtabMethod = 1;
7145771429
rc = u.cn.pModule->xFilter(u.cn.pVtabCursor, u.cn.iQuery, pOp->p4.z, u.cn.nArg, u.cn.apArg);
7145871430
p->inVtabMethod = 0;
71459
- importVtabErrMsg(p, u.cn.pVtab);
71431
+ sqlite3VtabImportErrmsg(p, u.cn.pVtab);
7146071432
if( rc==SQLITE_OK ){
7146171433
u.cn.res = u.cn.pModule->xEof(u.cn.pVtabCursor);
7146271434
}
7146371435
7146471436
if( u.cn.res ){
@@ -71507,11 +71479,11 @@
7150771479
*/
7150871480
sqlite3VdbeMemMove(&u.co.sContext.s, u.co.pDest);
7150971481
MemSetTypeFlag(&u.co.sContext.s, MEM_Null);
7151071482
7151171483
rc = u.co.pModule->xColumn(pCur->pVtabCursor, &u.co.sContext, pOp->p2);
71512
- importVtabErrMsg(p, u.co.pVtab);
71484
+ sqlite3VtabImportErrmsg(p, u.co.pVtab);
7151371485
if( u.co.sContext.isError ){
7151471486
rc = u.co.sContext.isError;
7151571487
}
7151671488
7151771489
/* Copy the result of the function to the P3 register. We
@@ -71562,11 +71534,11 @@
7156271534
** some other method is next invoked on the save virtual table cursor.
7156371535
*/
7156471536
p->inVtabMethod = 1;
7156571537
rc = u.cp.pModule->xNext(u.cp.pCur->pVtabCursor);
7156671538
p->inVtabMethod = 0;
71567
- importVtabErrMsg(p, u.cp.pVtab);
71539
+ sqlite3VtabImportErrmsg(p, u.cp.pVtab);
7156871540
if( rc==SQLITE_OK ){
7156971541
u.cp.res = u.cp.pModule->xEof(u.cp.pCur->pVtabCursor);
7157071542
}
7157171543
7157271544
if( !u.cp.res ){
@@ -71601,11 +71573,11 @@
7160171573
testcase( u.cq.pName->enc==SQLITE_UTF16BE );
7160271574
testcase( u.cq.pName->enc==SQLITE_UTF16LE );
7160371575
rc = sqlite3VdbeChangeEncoding(u.cq.pName, SQLITE_UTF8);
7160471576
if( rc==SQLITE_OK ){
7160571577
rc = u.cq.pVtab->pModule->xRename(u.cq.pVtab, u.cq.pName->z);
71606
- importVtabErrMsg(p, u.cq.pVtab);
71578
+ sqlite3VtabImportErrmsg(p, u.cq.pVtab);
7160771579
p->expired = 0;
7160871580
}
7160971581
break;
7161071582
}
7161171583
#endif
@@ -71665,11 +71637,11 @@
7166571637
u.cr.pX++;
7166671638
}
7166771639
db->vtabOnConflict = pOp->p5;
7166871640
rc = u.cr.pModule->xUpdate(u.cr.pVtab, u.cr.nArg, u.cr.apArg, &u.cr.rowid);
7166971641
db->vtabOnConflict = vtabOnConflict;
71670
- importVtabErrMsg(p, u.cr.pVtab);
71642
+ sqlite3VtabImportErrmsg(p, u.cr.pVtab);
7167171643
if( rc==SQLITE_OK && pOp->p1 ){
7167271644
assert( u.cr.nArg>1 && u.cr.apArg[0] && (u.cr.apArg[0]->flags&MEM_Null) );
7167371645
db->lastRowid = lastRowid = u.cr.rowid;
7167471646
}
7167571647
if( (rc&0xff)==SQLITE_CONSTRAINT && pOp->p4.pVtab->bConstraint ){
@@ -75593,12 +75565,11 @@
7559375565
int op = p->op;
7559475566
if( op==TK_CAST || op==TK_UPLUS ){
7559575567
p = p->pLeft;
7559675568
continue;
7559775569
}
75598
- assert( op!=TK_REGISTER || p->op2!=TK_COLLATE );
75599
- if( op==TK_COLLATE ){
75570
+ if( op==TK_COLLATE || (op==TK_REGISTER && p->op2==TK_COLLATE) ){
7560075571
pColl = sqlite3GetCollSeq(pParse, ENC(db), 0, p->u.zToken);
7560175572
break;
7560275573
}
7560375574
if( p->pTab!=0
7560475575
&& (op==TK_AGG_COLUMN || op==TK_COLUMN
@@ -78984,10 +78955,11 @@
7898478955
compLeft.pRight = pExpr->x.pList->a[0].pExpr;
7898578956
compRight.op = TK_LE;
7898678957
compRight.pLeft = &exprX;
7898778958
compRight.pRight = pExpr->x.pList->a[1].pExpr;
7898878959
exprX.iTable = sqlite3ExprCodeTemp(pParse, &exprX, &regFree1);
78960
+ exprX.op2 = exprX.op;
7898978961
exprX.op = TK_REGISTER;
7899078962
if( jumpIfTrue ){
7899178963
sqlite3ExprIfTrue(pParse, &exprAnd, dest, jumpIfNull);
7899278964
}else{
7899378965
sqlite3ExprIfFalse(pParse, &exprAnd, dest, jumpIfNull);
@@ -89001,13 +88973,13 @@
8900188973
}
8900288974
static void groupConcatFinalize(sqlite3_context *context){
8900388975
StrAccum *pAccum;
8900488976
pAccum = sqlite3_aggregate_context(context, 0);
8900588977
if( pAccum ){
89006
- if( pAccum->tooBig ){
88978
+ if( pAccum->accError==STRACCUM_TOOBIG ){
8900788979
sqlite3_result_error_toobig(context);
89008
- }else if( pAccum->mallocFailed ){
88980
+ }else if( pAccum->accError==STRACCUM_NOMEM ){
8900988981
sqlite3_result_error_nomem(context);
8901088982
}else{
8901188983
sqlite3_result_text(context, sqlite3StrAccumFinish(pAccum), -1,
8901288984
sqlite3_free);
8901388985
}
@@ -104488,14 +104460,13 @@
104488104460
/*
104489104461
** Invoke the xSync method of all virtual tables in the sqlite3.aVTrans
104490104462
** array. Return the error code for the first error that occurs, or
104491104463
** SQLITE_OK if all xSync operations are successful.
104492104464
**
104493
-** Set *pzErrmsg to point to a buffer that should be released using
104494
-** sqlite3DbFree() containing an error message, if one is available.
104465
+** If an error message is available, leave it in p->zErrMsg.
104495104466
*/
104496
-SQLITE_PRIVATE int sqlite3VtabSync(sqlite3 *db, char **pzErrmsg){
104467
+SQLITE_PRIVATE int sqlite3VtabSync(sqlite3 *db, Vdbe *p){
104497104468
int i;
104498104469
int rc = SQLITE_OK;
104499104470
VTable **aVTrans = db->aVTrans;
104500104471
104501104472
db->aVTrans = 0;
@@ -104502,13 +104473,11 @@
104502104473
for(i=0; rc==SQLITE_OK && i<db->nVTrans; i++){
104503104474
int (*x)(sqlite3_vtab *);
104504104475
sqlite3_vtab *pVtab = aVTrans[i]->pVtab;
104505104476
if( pVtab && (x = pVtab->pModule->xSync)!=0 ){
104506104477
rc = x(pVtab);
104507
- sqlite3DbFree(db, *pzErrmsg);
104508
- *pzErrmsg = pVtab->zErrMsg;
104509
- pVtab->zErrMsg = 0;
104478
+ sqlite3VtabImportErrmsg(p, pVtab);
104510104479
}
104511104480
}
104512104481
db->aVTrans = aVTrans;
104513104482
return rc;
104514104483
}
@@ -104869,10 +104838,11 @@
104869104838
int iIdxCur; /* The VDBE cursor used to access pIdx */
104870104839
int addrBrk; /* Jump here to break out of the loop */
104871104840
int addrNxt; /* Jump here to start the next IN combination */
104872104841
int addrCont; /* Jump here to continue with the next loop cycle */
104873104842
int addrFirst; /* First instruction of interior of the loop */
104843
+ int addrBody; /* Beginning of the body of this loop */
104874104844
u8 iFrom; /* Which entry in the FROM clause */
104875104845
u8 op, p5; /* Opcode and P5 of the opcode that ends the loop */
104876104846
int p1, p2; /* Operands of the opcode used to ends the loop */
104877104847
union { /* Information that depends on pWLoop->wsFlags */
104878104848
struct {
@@ -107808,11 +107778,11 @@
107808107778
pParse->db->mallocFailed = 1;
107809107779
}
107810107780
107811107781
/* Evaluate the equality constraints
107812107782
*/
107813
- assert( pIdx->nColumn>=nEq );
107783
+ assert( zAff==0 || strlen(zAff)>=nEq );
107814107784
for(j=0; j<nEq; j++){
107815107785
int r1;
107816107786
pTerm = pLoop->aLTerm[j];
107817107787
assert( pTerm!=0 );
107818107788
/* The following true for indices with redundant columns.
@@ -107900,11 +107870,12 @@
107900107870
}
107901107871
sqlite3StrAccumInit(&txt, 0, 0, SQLITE_MAX_LENGTH);
107902107872
txt.db = db;
107903107873
sqlite3StrAccumAppend(&txt, " (", 2);
107904107874
for(i=0; i<nEq; i++){
107905
- explainAppendTerm(&txt, i, aCol[aiColumn[i]].zName, "=");
107875
+ char *z = (i==pIndex->nColumn ) ? "rowid" : aCol[aiColumn[i]].zName;
107876
+ explainAppendTerm(&txt, i, z, "=");
107906107877
}
107907107878
107908107879
j = i;
107909107880
if( pLoop->wsFlags&WHERE_BTM_LIMIT ){
107910107881
char *z = (j==pIndex->nColumn ) ? "rowid" : aCol[aiColumn[j]].zName;
@@ -109115,17 +109086,15 @@
109115109086
pNew->rSetup = 0;
109116109087
rLogSize = estLog(whereCost(pProbe->aiRowEst[0]));
109117109088
for(; rc==SQLITE_OK && pTerm!=0; pTerm = whereScanNext(&scan)){
109118109089
int nIn = 0;
109119109090
if( pTerm->prereqRight & pNew->maskSelf ) continue;
109120
-#ifdef SQLITE_ENABLE_STAT3
109121
- if( (pTerm->wtFlags & TERM_VNULL)!=0
109091
+ if( (pTerm->eOperator==WO_ISNULL || (pTerm->wtFlags&TERM_VNULL)!=0)
109122109092
&& (iCol<0 || pSrc->pTab->aCol[iCol].notNull)
109123109093
){
109124
- continue; /* skip IS NOT NULL constraints on a NOT NULL column */
109094
+ continue; /* ignore IS [NOT] NULL constraints on NOT NULL columns */
109125109095
}
109126
-#endif
109127109096
pNew->wsFlags = saved_wsFlags;
109128109097
pNew->u.btree.nEq = saved_nEq;
109129109098
pNew->nLTerm = saved_nLTerm;
109130109099
if( whereLoopResize(db, pNew, pNew->nLTerm+1) ) break; /* OOM */
109131109100
pNew->aLTerm[pNew->nLTerm++] = pTerm;
@@ -110764,15 +110733,10 @@
110764110733
assert( n<=pTab->nCol );
110765110734
}
110766110735
}else{
110767110736
sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
110768110737
}
110769
-#ifndef SQLITE_OMIT_AUTOMATIC_INDEX
110770
- if( (pLoop->wsFlags & WHERE_AUTO_INDEX)!=0 ){
110771
- constructAutomaticIndex(pParse, &pWInfo->sWC, pTabItem, notReady, pLevel);
110772
- }else
110773
-#endif
110774110738
if( pLoop->wsFlags & WHERE_INDEXED ){
110775110739
Index *pIx = pLoop->u.btree.pIndex;
110776110740
KeyInfo *pKey = sqlite3IndexKeyinfo(pParse, pIx);
110777110741
/* FIXME: As an optimization use pTabItem->iCursor if WHERE_IDX_ONLY */
110778110742
int iIndexCur = pLevel->iIdxCur = iIdxCur ? iIdxCur : pParse->nTab++;
@@ -110793,11 +110757,19 @@
110793110757
** program.
110794110758
*/
110795110759
notReady = ~(Bitmask)0;
110796110760
for(ii=0; ii<nTabList; ii++){
110797110761
pLevel = &pWInfo->a[ii];
110762
+#ifndef SQLITE_OMIT_AUTOMATIC_INDEX
110763
+ if( (pLevel->pWLoop->wsFlags & WHERE_AUTO_INDEX)!=0 ){
110764
+ constructAutomaticIndex(pParse, &pWInfo->sWC,
110765
+ &pTabList->a[pLevel->iFrom], notReady, pLevel);
110766
+ if( db->mallocFailed ) goto whereBeginError;
110767
+ }
110768
+#endif
110798110769
explainOneScan(pParse, pTabList, pLevel, ii, pLevel->iFrom, wctrlFlags);
110770
+ pLevel->addrBody = sqlite3VdbeCurrentAddr(v);
110799110771
notReady = codeOneLoopStart(pWInfo, ii, notReady);
110800110772
pWInfo->iContinue = pLevel->addrCont;
110801110773
}
110802110774
110803110775
/* Done. */
@@ -110913,13 +110885,14 @@
110913110885
}
110914110886
if( pIdx && !db->mallocFailed ){
110915110887
int k, j, last;
110916110888
VdbeOp *pOp;
110917110889
110918
- pOp = sqlite3VdbeGetOp(v, pWInfo->iTop);
110919110890
last = sqlite3VdbeCurrentAddr(v);
110920
- for(k=pWInfo->iTop; k<last; k++, pOp++){
110891
+ k = pLevel->addrBody;
110892
+ pOp = sqlite3VdbeGetOp(v, k);
110893
+ for(; k<last; k++, pOp++){
110921110894
if( pOp->p1!=pLevel->iTabCur ) continue;
110922110895
if( pOp->opcode==OP_Column ){
110923110896
for(j=0; j<pIdx->nColumn; j++){
110924110897
if( pOp->p2==pIdx->aiColumn[j] ){
110925110898
pOp->p2 = j;
@@ -134651,15 +134624,15 @@
134651134624
}
134652134625
}
134653134626
if( pTC ) pModule->xClose(pTC);
134654134627
if( rc==SQLITE_DONE ) rc = SQLITE_OK;
134655134628
}
134629
+ }
134656134630
134657
- for(pDef=pCsr->pDeferred; pDef && rc==SQLITE_OK; pDef=pDef->pNext){
134658
- if( pDef->pList ){
134659
- rc = fts3PendingListAppendVarint(&pDef->pList, 0);
134660
- }
134631
+ for(pDef=pCsr->pDeferred; pDef && rc==SQLITE_OK; pDef=pDef->pNext){
134632
+ if( pDef->pList ){
134633
+ rc = fts3PendingListAppendVarint(&pDef->pList, 0);
134661134634
}
134662134635
}
134663134636
}
134664134637
134665134638
return rc;
134666134639
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -656,11 +656,11 @@
656 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
657 ** [sqlite_version()] and [sqlite_source_id()].
658 */
659 #define SQLITE_VERSION "3.8.0"
660 #define SQLITE_VERSION_NUMBER 3008000
661 #define SQLITE_SOURCE_ID "2013-08-20 03:13:51 7f72fc4f47445a2c01910b268335873de9f75059"
662
663 /*
664 ** CAPI3REF: Run-Time Library Version Numbers
665 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
666 **
@@ -9288,12 +9288,12 @@
9288 #define PAGER_JOURNALMODE_WAL 5 /* Use write-ahead logging */
9289
9290 /*
9291 ** Flags that make up the mask passed to sqlite3PagerAcquire().
9292 */
9293 #define PAGER_ACQUIRE_NOCONTENT 0x01 /* Do not load data from disk */
9294 #define PAGER_ACQUIRE_READONLY 0x02 /* Read-only page is acceptable */
9295
9296 /*
9297 ** Flags for sqlite3PagerSetFlags()
9298 */
9299 #define PAGER_SYNCHRONOUS_OFF 0x01 /* PRAGMA synchronous=OFF */
@@ -11645,14 +11645,15 @@
11645 char *zBase; /* A base allocation. Not from malloc. */
11646 char *zText; /* The string collected so far */
11647 int nChar; /* Length of the string so far */
11648 int nAlloc; /* Amount of space allocated in zText */
11649 int mxAlloc; /* Maximum allowed string length */
11650 u8 mallocFailed; /* Becomes true if any memory allocation fails */
11651 u8 useMalloc; /* 0: none, 1: sqlite3DbMalloc, 2: sqlite3_malloc */
11652 u8 tooBig; /* Becomes true if string size exceeds limits */
11653 };
 
 
11654
11655 /*
11656 ** A pointer to this structure is used to communicate information
11657 ** from sqlite3Init and OP_ParseSchema into the sqlite3InitCallback.
11658 */
@@ -12373,17 +12374,18 @@
12373 # define sqlite3VtabSavepoint(X, Y, Z) SQLITE_OK
12374 # define sqlite3GetVTable(X,Y) ((VTable*)0)
12375 #else
12376 SQLITE_PRIVATE void sqlite3VtabClear(sqlite3 *db, Table*);
12377 SQLITE_PRIVATE void sqlite3VtabDisconnect(sqlite3 *db, Table *p);
12378 SQLITE_PRIVATE int sqlite3VtabSync(sqlite3 *db, char **);
12379 SQLITE_PRIVATE int sqlite3VtabRollback(sqlite3 *db);
12380 SQLITE_PRIVATE int sqlite3VtabCommit(sqlite3 *db);
12381 SQLITE_PRIVATE void sqlite3VtabLock(VTable *);
12382 SQLITE_PRIVATE void sqlite3VtabUnlock(VTable *);
12383 SQLITE_PRIVATE void sqlite3VtabUnlockList(sqlite3*);
12384 SQLITE_PRIVATE int sqlite3VtabSavepoint(sqlite3 *, int, int);
 
12385 SQLITE_PRIVATE VTable *sqlite3GetVTable(sqlite3*, Table*);
12386 # define sqlite3VtabInSync(db) ((db)->nVTrans>0 && (db)->aVTrans==0)
12387 #endif
12388 SQLITE_PRIVATE void sqlite3VtabMakeWritable(Parse*,Table*);
12389 SQLITE_PRIVATE void sqlite3VtabBeginParse(Parse*, Token*, Token*, Token*, int);
@@ -19899,11 +19901,11 @@
19899 zOut = buf;
19900 }else{
19901 nOut = precision + 10;
19902 zOut = zExtra = sqlite3Malloc( nOut );
19903 if( zOut==0 ){
19904 pAccum->mallocFailed = 1;
19905 return;
19906 }
19907 }
19908 bufpt = &zOut[nOut-1];
19909 if( xtype==etORDINAL ){
@@ -20011,11 +20013,11 @@
20011 e2 = exp;
20012 }
20013 if( MAX(e2,0)+precision+width > etBUFSIZE - 15 ){
20014 bufpt = zExtra = sqlite3Malloc( MAX(e2,0)+precision+width+15 );
20015 if( bufpt==0 ){
20016 pAccum->mallocFailed = 1;
20017 return;
20018 }
20019 }
20020 zOut = bufpt;
20021 nsd = 16 + flag_altform2*10;
@@ -20146,11 +20148,11 @@
20146 needQuote = !isnull && xtype==etSQLESCAPE2;
20147 n += i + 1 + needQuote*2;
20148 if( n>etBUFSIZE ){
20149 bufpt = zExtra = sqlite3Malloc( n );
20150 if( bufpt==0 ){
20151 pAccum->mallocFailed = 1;
20152 return;
20153 }
20154 }else{
20155 bufpt = buf;
20156 }
@@ -20224,26 +20226,24 @@
20224 /*
20225 ** Append N bytes of text from z to the StrAccum object.
20226 */
20227 SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum *p, const char *z, int N){
20228 assert( z!=0 || N==0 );
20229 if( p->tooBig | p->mallocFailed ){
20230 testcase(p->tooBig);
20231 testcase(p->mallocFailed);
20232 return;
20233 }
20234 assert( p->zText!=0 || p->nChar==0 );
20235 if( N<0 ){
 
20236 N = sqlite3Strlen30(z);
20237 }
20238 if( N==0 || NEVER(z==0) ){
20239 return;
20240 }
20241 if( p->nChar+N >= p->nAlloc ){
20242 char *zNew;
20243 if( !p->useMalloc ){
20244 p->tooBig = 1;
20245 N = p->nAlloc - p->nChar - 1;
20246 if( N<=0 ){
20247 return;
20248 }
20249 }else{
@@ -20250,11 +20250,11 @@
20250 char *zOld = (p->zText==p->zBase ? 0 : p->zText);
20251 i64 szNew = p->nChar;
20252 szNew += N + 1;
20253 if( szNew > p->mxAlloc ){
20254 sqlite3StrAccumReset(p);
20255 p->tooBig = 1;
20256 return;
20257 }else{
20258 p->nAlloc = (int)szNew;
20259 }
20260 if( p->useMalloc==1 ){
@@ -20264,11 +20264,11 @@
20264 }
20265 if( zNew ){
20266 if( zOld==0 && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar);
20267 p->zText = zNew;
20268 }else{
20269 p->mallocFailed = 1;
20270 sqlite3StrAccumReset(p);
20271 return;
20272 }
20273 }
20274 }
@@ -20292,11 +20292,11 @@
20292 p->zText = sqlite3_malloc(p->nChar+1);
20293 }
20294 if( p->zText ){
20295 memcpy(p->zText, p->zBase, p->nChar+1);
20296 }else{
20297 p->mallocFailed = 1;
20298 }
20299 }
20300 }
20301 return p->zText;
20302 }
@@ -20323,12 +20323,11 @@
20323 p->db = 0;
20324 p->nChar = 0;
20325 p->nAlloc = n;
20326 p->mxAlloc = mx;
20327 p->useMalloc = 1;
20328 p->tooBig = 0;
20329 p->mallocFailed = 0;
20330 }
20331
20332 /*
20333 ** Print into memory obtained from sqliteMalloc(). Use the internal
20334 ** %-conversion extensions.
@@ -20341,11 +20340,11 @@
20341 sqlite3StrAccumInit(&acc, zBase, sizeof(zBase),
20342 db->aLimit[SQLITE_LIMIT_LENGTH]);
20343 acc.db = db;
20344 sqlite3VXPrintf(&acc, 1, zFormat, ap);
20345 z = sqlite3StrAccumFinish(&acc);
20346 if( acc.mallocFailed ){
20347 db->mallocFailed = 1;
20348 }
20349 return z;
20350 }
20351
@@ -20538,28 +20537,15 @@
20538 unsigned char i, j; /* State variables */
20539 unsigned char s[256]; /* State variables */
20540 } sqlite3Prng;
20541
20542 /*
20543 ** Get a single 8-bit random value from the RC4 PRNG. The Mutex
20544 ** must be held while executing this routine.
20545 **
20546 ** Why not just use a library random generator like lrand48() for this?
20547 ** Because the OP_NewRowid opcode in the VDBE depends on having a very
20548 ** good source of random numbers. The lrand48() library function may
20549 ** well be good enough. But maybe not. Or maybe lrand48() has some
20550 ** subtle problems on some systems that could cause problems. It is hard
20551 ** to know. To minimize the risk of problems due to bad lrand48()
20552 ** implementations, SQLite uses this random number generator based
20553 ** on RC4, which we know works very well.
20554 **
20555 ** (Later): Actually, OP_NewRowid does not depend on a good source of
20556 ** randomness any more. But we will leave this code in all the same.
20557 */
20558 static u8 randomByte(void){
20559 unsigned char t;
20560
20561
20562 /* The "wsdPrng" macro will resolve to the pseudo-random number generator
20563 ** state vector. If writable static data is unsupported on the target,
20564 ** we have to locate the state vector at run-time. In the more common
20565 ** case where writable static data is supported, wsdPrng can refer directly
@@ -20570,10 +20556,14 @@
20570 # define wsdPrng p[0]
20571 #else
20572 # define wsdPrng sqlite3Prng
20573 #endif
20574
 
 
 
 
20575
20576 /* Initialize the state of the random number generator once,
20577 ** the first time this routine is called. The seed value does
20578 ** not need to contain a lot of randomness since we are not
20579 ** trying to do secure encryption or anything like that...
@@ -20598,32 +20588,18 @@
20598 wsdPrng.s[i] = t;
20599 }
20600 wsdPrng.isInit = 1;
20601 }
20602
20603 /* Generate and return single random byte
20604 */
20605 wsdPrng.i++;
20606 t = wsdPrng.s[wsdPrng.i];
20607 wsdPrng.j += t;
20608 wsdPrng.s[wsdPrng.i] = wsdPrng.s[wsdPrng.j];
20609 wsdPrng.s[wsdPrng.j] = t;
20610 t += wsdPrng.s[wsdPrng.i];
20611 return wsdPrng.s[t];
20612 }
20613
20614 /*
20615 ** Return N random bytes.
20616 */
20617 SQLITE_API void sqlite3_randomness(int N, void *pBuf){
20618 unsigned char *zBuf = pBuf;
20619 #if SQLITE_THREADSAFE
20620 sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_PRNG);
20621 #endif
20622 sqlite3_mutex_enter(mutex);
20623 while( N-- ){
20624 *(zBuf++) = randomByte();
 
 
 
 
 
 
20625 }
20626 sqlite3_mutex_leave(mutex);
20627 }
20628
20629 #ifndef SQLITE_OMIT_BUILTIN_TEST
@@ -39378,17 +39354,21 @@
39378 ** * The page-number is less than or equal to PagerSavepoint.nOrig, and
39379 ** * The bit corresponding to the page-number is not set in
39380 ** PagerSavepoint.pInSavepoint.
39381 */
39382 static int subjRequiresPage(PgHdr *pPg){
39383 Pgno pgno = pPg->pgno;
39384 Pager *pPager = pPg->pPager;
 
 
39385 int i;
39386 for(i=0; i<pPager->nSavepoint; i++){
39387 PagerSavepoint *p = &pPager->aSavepoint[i];
39388 if( p->nOrig>=pgno && 0==sqlite3BitvecTest(p->pInSavepoint, pgno) ){
39389 return 1;
 
 
 
39390 }
39391 }
39392 return 0;
39393 }
39394
@@ -41230,16 +41210,10 @@
41230 int pgsz = pPager->pageSize; /* Number of bytes to read */
41231
41232 assert( pPager->eState>=PAGER_READER && !MEMDB );
41233 assert( isOpen(pPager->fd) );
41234
41235 if( NEVER(!isOpen(pPager->fd)) ){
41236 assert( pPager->tempFile );
41237 memset(pPg->pData, 0, pPager->pageSize);
41238 return SQLITE_OK;
41239 }
41240
41241 #ifndef SQLITE_OMIT_WAL
41242 if( iFrame ){
41243 /* Try to pull the page from the write-ahead log. */
41244 rc = sqlite3WalReadFrame(pPager->pWal, iFrame, pgsz, pPg->pData);
41245 }else
@@ -43589,23 +43563,23 @@
43589 */
43590 SQLITE_PRIVATE int sqlite3PagerAcquire(
43591 Pager *pPager, /* The pager open on the database file */
43592 Pgno pgno, /* Page number to fetch */
43593 DbPage **ppPage, /* Write a pointer to the page here */
43594 int flags /* PAGER_ACQUIRE_XXX flags */
43595 ){
43596 int rc = SQLITE_OK;
43597 PgHdr *pPg = 0;
43598 u32 iFrame = 0; /* Frame to read from WAL file */
43599 const int noContent = (flags & PAGER_ACQUIRE_NOCONTENT);
43600
43601 /* It is acceptable to use a read-only (mmap) page for any page except
43602 ** page 1 if there is no write-transaction open or the ACQUIRE_READONLY
43603 ** flag was specified by the caller. And so long as the db is not a
43604 ** temporary or in-memory database. */
43605 const int bMmapOk = (pgno!=1 && USEFETCH(pPager)
43606 && (pPager->eState==PAGER_READER || (flags & PAGER_ACQUIRE_READONLY))
43607 #ifdef SQLITE_HAS_CODEC
43608 && pPager->xCodec==0
43609 #endif
43610 );
43611
@@ -50544,11 +50518,12 @@
50544 assert( pPage->leaf==0 || pPage->leaf==1 );
50545 n = pPage->childPtrSize;
50546 assert( n==4-4*pPage->leaf );
50547 if( pPage->intKey ){
50548 if( pPage->hasData ){
50549 n += getVarint32(&pCell[n], nPayload);
 
50550 }else{
50551 nPayload = 0;
50552 }
50553 n += getVarint(&pCell[n], (u64*)&pInfo->nKey);
50554 pInfo->nData = nPayload;
@@ -51188,19 +51163,16 @@
51188 */
51189 static int btreeGetPage(
51190 BtShared *pBt, /* The btree */
51191 Pgno pgno, /* Number of the page to fetch */
51192 MemPage **ppPage, /* Return the page in this parameter */
51193 int noContent, /* Do not load page content if true */
51194 int bReadonly /* True if a read-only (mmap) page is ok */
51195 ){
51196 int rc;
51197 DbPage *pDbPage;
51198 int flags = (noContent ? PAGER_ACQUIRE_NOCONTENT : 0)
51199 | (bReadonly ? PAGER_ACQUIRE_READONLY : 0);
51200
51201 assert( noContent==0 || bReadonly==0 );
51202 assert( sqlite3_mutex_held(pBt->mutex) );
51203 rc = sqlite3PagerAcquire(pBt->pPager, pgno, (DbPage**)&pDbPage, flags);
51204 if( rc ) return rc;
51205 *ppPage = btreePageFromDbPage(pDbPage, pgno, pBt);
51206 return SQLITE_OK;
@@ -51244,19 +51216,20 @@
51244 */
51245 static int getAndInitPage(
51246 BtShared *pBt, /* The database file */
51247 Pgno pgno, /* Number of the page to get */
51248 MemPage **ppPage, /* Write the page pointer here */
51249 int bReadonly /* True if a read-only (mmap) page is ok */
51250 ){
51251 int rc;
51252 assert( sqlite3_mutex_held(pBt->mutex) );
 
51253
51254 if( pgno>btreePagecount(pBt) ){
51255 rc = SQLITE_CORRUPT_BKPT;
51256 }else{
51257 rc = btreeGetPage(pBt, pgno, ppPage, 0, bReadonly);
51258 if( rc==SQLITE_OK ){
51259 rc = btreeInitPage(*ppPage);
51260 if( rc!=SQLITE_OK ){
51261 releasePage(*ppPage);
51262 }
@@ -51985,11 +51958,11 @@
51985
51986 assert( sqlite3_mutex_held(pBt->mutex) );
51987 assert( pBt->pPage1==0 );
51988 rc = sqlite3PagerSharedLock(pBt->pPager);
51989 if( rc!=SQLITE_OK ) return rc;
51990 rc = btreeGetPage(pBt, 1, &pPage1, 0, 0);
51991 if( rc!=SQLITE_OK ) return rc;
51992
51993 /* Do some checking to help insure the file we opened really is
51994 ** a valid database file.
51995 */
@@ -52567,11 +52540,11 @@
52567 /* Fix the database pointer on page iPtrPage that pointed at iDbPage so
52568 ** that it points at iFreePage. Also fix the pointer map entry for
52569 ** iPtrPage.
52570 */
52571 if( eType!=PTRMAP_ROOTPAGE ){
52572 rc = btreeGetPage(pBt, iPtrPage, &pPtrPage, 0, 0);
52573 if( rc!=SQLITE_OK ){
52574 return rc;
52575 }
52576 rc = sqlite3PagerWrite(pPtrPage->pDbPage);
52577 if( rc!=SQLITE_OK ){
@@ -52651,11 +52624,11 @@
52651 Pgno iFreePg; /* Index of free page to move pLastPg to */
52652 MemPage *pLastPg;
52653 u8 eMode = BTALLOC_ANY; /* Mode parameter for allocateBtreePage() */
52654 Pgno iNear = 0; /* nearby parameter for allocateBtreePage() */
52655
52656 rc = btreeGetPage(pBt, iLastPg, &pLastPg, 0, 0);
52657 if( rc!=SQLITE_OK ){
52658 return rc;
52659 }
52660
52661 /* If bCommit is zero, this loop runs exactly once and page pLastPg
@@ -53050,11 +53023,11 @@
53050 }
53051
53052 /* The rollback may have destroyed the pPage1->aData value. So
53053 ** call btreeGetPage() on page 1 again to make
53054 ** sure pPage1->aData is set correctly. */
53055 if( btreeGetPage(pBt, 1, &pPage1, 0, 0)==SQLITE_OK ){
53056 int nPage = get4byte(28+(u8*)pPage1->aData);
53057 testcase( nPage==0 );
53058 if( nPage==0 ) sqlite3PagerPagecount(pBt->pPager, &nPage);
53059 testcase( pBt->nPage!=nPage );
53060 pBt->nPage = nPage;
@@ -53485,11 +53458,11 @@
53485 }
53486 #endif
53487
53488 assert( next==0 || rc==SQLITE_DONE );
53489 if( rc==SQLITE_OK ){
53490 rc = btreeGetPage(pBt, ovfl, &pPage, 0, (ppPage==0));
53491 assert( rc==SQLITE_OK || pPage==0 );
53492 if( rc==SQLITE_OK ){
53493 next = get4byte(pPage->aData);
53494 }
53495 }
@@ -53707,11 +53680,11 @@
53707 #endif
53708
53709 {
53710 DbPage *pDbPage;
53711 rc = sqlite3PagerAcquire(pBt->pPager, nextPage, &pDbPage,
53712 (eOp==0 ? PAGER_ACQUIRE_READONLY : 0)
53713 );
53714 if( rc==SQLITE_OK ){
53715 aPayload = sqlite3PagerGetData(pDbPage);
53716 nextPage = get4byte(aPayload);
53717 rc = copyPayload(&aPayload[offset+4], pBuf, a, eOp, pDbPage);
@@ -53891,11 +53864,12 @@
53891 assert( pCur->iPage<BTCURSOR_MAX_DEPTH );
53892 assert( pCur->iPage>=0 );
53893 if( pCur->iPage>=(BTCURSOR_MAX_DEPTH-1) ){
53894 return SQLITE_CORRUPT_BKPT;
53895 }
53896 rc = getAndInitPage(pBt, newPgno, &pNewPage, (pCur->wrFlag==0));
 
53897 if( rc ) return rc;
53898 pCur->apPage[i+1] = pNewPage;
53899 pCur->aiIdx[i+1] = 0;
53900 pCur->iPage++;
53901
@@ -54008,11 +53982,12 @@
54008 pCur->iPage = 0;
54009 }else if( pCur->pgnoRoot==0 ){
54010 pCur->eState = CURSOR_INVALID;
54011 return SQLITE_OK;
54012 }else{
54013 rc = getAndInitPage(pBt, pCur->pgnoRoot, &pCur->apPage[0], pCur->wrFlag==0);
 
54014 if( rc!=SQLITE_OK ){
54015 pCur->eState = CURSOR_INVALID;
54016 return rc;
54017 }
54018 pCur->iPage = 0;
@@ -54645,11 +54620,11 @@
54645 }
54646 testcase( iTrunk==mxPage );
54647 if( iTrunk>mxPage ){
54648 rc = SQLITE_CORRUPT_BKPT;
54649 }else{
54650 rc = btreeGetPage(pBt, iTrunk, &pTrunk, 0, 0);
54651 }
54652 if( rc ){
54653 pTrunk = 0;
54654 goto end_allocate_page;
54655 }
@@ -54709,11 +54684,11 @@
54709 if( iNewTrunk>mxPage ){
54710 rc = SQLITE_CORRUPT_BKPT;
54711 goto end_allocate_page;
54712 }
54713 testcase( iNewTrunk==mxPage );
54714 rc = btreeGetPage(pBt, iNewTrunk, &pNewTrunk, 0, 0);
54715 if( rc!=SQLITE_OK ){
54716 goto end_allocate_page;
54717 }
54718 rc = sqlite3PagerWrite(pNewTrunk->pDbPage);
54719 if( rc!=SQLITE_OK ){
@@ -54788,12 +54763,12 @@
54788 if( rc ) goto end_allocate_page;
54789 if( closest<k-1 ){
54790 memcpy(&aData[8+closest*4], &aData[4+k*4], 4);
54791 }
54792 put4byte(&aData[4], k-1);
54793 noContent = !btreeGetHasContent(pBt, *pPgno);
54794 rc = btreeGetPage(pBt, *pPgno, ppPage, noContent, 0);
54795 if( rc==SQLITE_OK ){
54796 rc = sqlite3PagerWrite((*ppPage)->pDbPage);
54797 if( rc!=SQLITE_OK ){
54798 releasePage(*ppPage);
54799 }
@@ -54821,11 +54796,11 @@
54821 ** content for any page that really does lie past the end of the database
54822 ** file on disk. So the effects of disabling the no-content optimization
54823 ** here are confined to those pages that lie between the end of the
54824 ** database image and the end of the database file.
54825 */
54826 int bNoContent = (0==IfNotOmitAV(pBt->bDoTruncate));
54827
54828 rc = sqlite3PagerWrite(pBt->pPage1->pDbPage);
54829 if( rc ) return rc;
54830 pBt->nPage++;
54831 if( pBt->nPage==PENDING_BYTE_PAGE(pBt) ) pBt->nPage++;
@@ -54837,11 +54812,11 @@
54837 ** becomes a new pointer-map page, the second is used by the caller.
54838 */
54839 MemPage *pPg = 0;
54840 TRACE(("ALLOCATE: %d from end of file (pointer-map page)\n", pBt->nPage));
54841 assert( pBt->nPage!=PENDING_BYTE_PAGE(pBt) );
54842 rc = btreeGetPage(pBt, pBt->nPage, &pPg, bNoContent, 0);
54843 if( rc==SQLITE_OK ){
54844 rc = sqlite3PagerWrite(pPg->pDbPage);
54845 releasePage(pPg);
54846 }
54847 if( rc ) return rc;
@@ -54851,11 +54826,11 @@
54851 #endif
54852 put4byte(28 + (u8*)pBt->pPage1->aData, pBt->nPage);
54853 *pPgno = pBt->nPage;
54854
54855 assert( *pPgno!=PENDING_BYTE_PAGE(pBt) );
54856 rc = btreeGetPage(pBt, *pPgno, ppPage, bNoContent, 0);
54857 if( rc ) return rc;
54858 rc = sqlite3PagerWrite((*ppPage)->pDbPage);
54859 if( rc!=SQLITE_OK ){
54860 releasePage(*ppPage);
54861 }
@@ -54919,11 +54894,11 @@
54919
54920 if( pBt->btsFlags & BTS_SECURE_DELETE ){
54921 /* If the secure_delete option is enabled, then
54922 ** always fully overwrite deleted information with zeros.
54923 */
54924 if( (!pPage && ((rc = btreeGetPage(pBt, iPage, &pPage, 0, 0))!=0) )
54925 || ((rc = sqlite3PagerWrite(pPage->pDbPage))!=0)
54926 ){
54927 goto freepage_out;
54928 }
54929 memset(pPage->aData, 0, pPage->pBt->pageSize);
@@ -54946,11 +54921,11 @@
54946 */
54947 if( nFree!=0 ){
54948 u32 nLeaf; /* Initial number of leaf cells on trunk page */
54949
54950 iTrunk = get4byte(&pPage1->aData[32]);
54951 rc = btreeGetPage(pBt, iTrunk, &pTrunk, 0, 0);
54952 if( rc!=SQLITE_OK ){
54953 goto freepage_out;
54954 }
54955
54956 nLeaf = get4byte(&pTrunk->aData[4]);
@@ -54992,11 +54967,11 @@
54992 ** the page being freed as a leaf page of the first trunk in the free-list.
54993 ** Possibly because the free-list is empty, or possibly because the
54994 ** first trunk in the free-list is full. Either way, the page being freed
54995 ** will become the new first trunk page in the free-list.
54996 */
54997 if( pPage==0 && SQLITE_OK!=(rc = btreeGetPage(pBt, iPage, &pPage, 0, 0)) ){
54998 goto freepage_out;
54999 }
55000 rc = sqlite3PagerWrite(pPage->pDbPage);
55001 if( rc!=SQLITE_OK ){
55002 goto freepage_out;
@@ -56891,11 +56866,11 @@
56891 if( rc!=SQLITE_OK ){
56892 return rc;
56893 }
56894
56895 /* Move the page currently at pgnoRoot to pgnoMove. */
56896 rc = btreeGetPage(pBt, pgnoRoot, &pRoot, 0, 0);
56897 if( rc!=SQLITE_OK ){
56898 return rc;
56899 }
56900 rc = ptrmapGet(pBt, pgnoRoot, &eType, &iPtrPage);
56901 if( eType==PTRMAP_ROOTPAGE || eType==PTRMAP_FREEPAGE ){
@@ -56912,11 +56887,11 @@
56912
56913 /* Obtain the page at pgnoRoot */
56914 if( rc!=SQLITE_OK ){
56915 return rc;
56916 }
56917 rc = btreeGetPage(pBt, pgnoRoot, &pRoot, 0, 0);
56918 if( rc!=SQLITE_OK ){
56919 return rc;
56920 }
56921 rc = sqlite3PagerWrite(pRoot->pDbPage);
56922 if( rc!=SQLITE_OK ){
@@ -57090,11 +57065,11 @@
57090 if( NEVER(pBt->pCursor) ){
57091 sqlite3ConnectionBlocked(p->db, pBt->pCursor->pBtree->db);
57092 return SQLITE_LOCKED_SHAREDCACHE;
57093 }
57094
57095 rc = btreeGetPage(pBt, (Pgno)iTable, &pPage, 0, 0);
57096 if( rc ) return rc;
57097 rc = sqlite3BtreeClearTable(p, iTable, 0);
57098 if( rc ){
57099 releasePage(pPage);
57100 return rc;
@@ -57125,21 +57100,21 @@
57125 ** number in the database. So move the page that does into the
57126 ** gap left by the deleted root-page.
57127 */
57128 MemPage *pMove;
57129 releasePage(pPage);
57130 rc = btreeGetPage(pBt, maxRootPgno, &pMove, 0, 0);
57131 if( rc!=SQLITE_OK ){
57132 return rc;
57133 }
57134 rc = relocatePage(pBt, pMove, PTRMAP_ROOTPAGE, 0, iTable, 0);
57135 releasePage(pMove);
57136 if( rc!=SQLITE_OK ){
57137 return rc;
57138 }
57139 pMove = 0;
57140 rc = btreeGetPage(pBt, maxRootPgno, &pMove, 0, 0);
57141 freePage(pMove, &rc);
57142 releasePage(pMove);
57143 if( rc!=SQLITE_OK ){
57144 return rc;
57145 }
@@ -57350,11 +57325,11 @@
57350 if( zMsg1 ){
57351 sqlite3StrAccumAppend(&pCheck->errMsg, zMsg1, -1);
57352 }
57353 sqlite3VXPrintf(&pCheck->errMsg, 1, zFormat, ap);
57354 va_end(ap);
57355 if( pCheck->errMsg.mallocFailed ){
57356 pCheck->mallocFailed = 1;
57357 }
57358 }
57359 #endif /* SQLITE_OMIT_INTEGRITY_CHECK */
57360
@@ -57547,11 +57522,11 @@
57547 */
57548 pBt = pCheck->pBt;
57549 usableSize = pBt->usableSize;
57550 if( iPage==0 ) return 0;
57551 if( checkRef(pCheck, iPage, zParentContext) ) return 0;
57552 if( (rc = btreeGetPage(pBt, (Pgno)iPage, &pPage, 0, 0))!=0 ){
57553 checkAppendMsg(pCheck, zContext,
57554 "unable to get the page. error code=%d", rc);
57555 return 0;
57556 }
57557
@@ -58506,11 +58481,11 @@
58506 for(ii=0; (nPage<0 || ii<nPage) && p->iNext<=(Pgno)nSrcPage && !rc; ii++){
58507 const Pgno iSrcPg = p->iNext; /* Source page number */
58508 if( iSrcPg!=PENDING_BYTE_PAGE(p->pSrc->pBt) ){
58509 DbPage *pSrcPg; /* Source page object */
58510 rc = sqlite3PagerAcquire(pSrcPager, iSrcPg, &pSrcPg,
58511 PAGER_ACQUIRE_READONLY);
58512 if( rc==SQLITE_OK ){
58513 rc = backupOnePage(p, iSrcPg, sqlite3PagerGetData(pSrcPg), 0);
58514 sqlite3PagerUnref(pSrcPg);
58515 }
58516 }
@@ -59661,38 +59636,33 @@
59661 /* If one value is a number and the other is not, the number is less.
59662 ** If both are numbers, compare as reals if one is a real, or as integers
59663 ** if both values are integers.
59664 */
59665 if( combined_flags&(MEM_Int|MEM_Real) ){
59666 if( !(f1&(MEM_Int|MEM_Real)) ){
59667 return 1;
59668 }
59669 if( !(f2&(MEM_Int|MEM_Real)) ){
59670 return -1;
59671 }
59672 if( (f1 & f2 & MEM_Int)==0 ){
59673 double r1, r2;
59674 if( (f1&MEM_Real)==0 ){
59675 r1 = (double)pMem1->u.i;
59676 }else{
59677 r1 = pMem1->r;
59678 }
59679 if( (f2&MEM_Real)==0 ){
59680 r2 = (double)pMem2->u.i;
59681 }else{
59682 r2 = pMem2->r;
59683 }
59684 if( r1<r2 ) return -1;
59685 if( r1>r2 ) return 1;
59686 return 0;
59687 }else{
59688 assert( f1&MEM_Int );
59689 assert( f2&MEM_Int );
59690 if( pMem1->u.i < pMem2->u.i ) return -1;
59691 if( pMem1->u.i > pMem2->u.i ) return 1;
59692 return 0;
59693 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59694 }
59695
59696 /* If one value is a string and the other is a blob, the string is less.
59697 ** If both are strings, compare using the collating functions.
59698 */
@@ -61789,11 +61759,11 @@
61789 ** virtual module tables written in this transaction. This has to
61790 ** be done before determining whether a master journal file is
61791 ** required, as an xSync() callback may add an attached database
61792 ** to the transaction.
61793 */
61794 rc = sqlite3VtabSync(db, &p->zErrMsg);
61795
61796 /* This loop determines (a) if the commit hook should be invoked and
61797 ** (b) how many database files have open write transactions, not
61798 ** including the temp database. (b) is important because if more than
61799 ** one database file has an open write transaction, a master journal
@@ -63329,10 +63299,25 @@
63329 }else{
63330 v->expmask |= ((u32)1 << (iVar-1));
63331 }
63332 }
63333
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63334 /************** End of vdbeaux.c *********************************************/
63335 /************** Begin file vdbeapi.c *****************************************/
63336 /*
63337 ** 2004 May 26
63338 **
@@ -65518,23 +65503,10 @@
65518 assert( n==(db->nSavepoint + db->isTransactionSavepoint) );
65519 return 1;
65520 }
65521 #endif
65522
65523 /*
65524 ** Transfer error message text from an sqlite3_vtab.zErrMsg (text stored
65525 ** in memory obtained from sqlite3_malloc) into a Vdbe.zErrMsg (text stored
65526 ** in memory obtained from sqlite3DbMalloc).
65527 */
65528 static void importVtabErrMsg(Vdbe *p, sqlite3_vtab *pVtab){
65529 sqlite3 *db = p->db;
65530 sqlite3DbFree(db, p->zErrMsg);
65531 p->zErrMsg = sqlite3DbStrDup(db, pVtab->zErrMsg);
65532 sqlite3_free(pVtab->zErrMsg);
65533 pVtab->zErrMsg = 0;
65534 }
65535
65536
65537 /*
65538 ** Execute as much of a VDBE program as we can then return.
65539 **
65540 ** sqlite3VdbeMakeReady() must be called before this routine in order to
@@ -69880,11 +69852,11 @@
69880 }else if( u.bn.pC->pVtabCursor ){
69881 u.bn.pVtab = u.bn.pC->pVtabCursor->pVtab;
69882 u.bn.pModule = u.bn.pVtab->pModule;
69883 assert( u.bn.pModule->xRowid );
69884 rc = u.bn.pModule->xRowid(u.bn.pC->pVtabCursor, &u.bn.v);
69885 importVtabErrMsg(p, u.bn.pVtab);
69886 #endif /* SQLITE_OMIT_VIRTUALTABLE */
69887 }else{
69888 assert( u.bn.pC->pCursor!=0 );
69889 rc = sqlite3VdbeCursorMoveto(u.bn.pC);
69890 if( rc ) goto abort_due_to_error;
@@ -71321,11 +71293,11 @@
71321 #if 0 /* local variables moved into u.cl */
71322 VTable *pVTab;
71323 #endif /* local variables moved into u.cl */
71324 u.cl.pVTab = pOp->p4.pVtab;
71325 rc = sqlite3VtabBegin(db, u.cl.pVTab);
71326 if( u.cl.pVTab ) importVtabErrMsg(p, u.cl.pVTab->pVtab);
71327 break;
71328 }
71329 #endif /* SQLITE_OMIT_VIRTUALTABLE */
71330
71331 #ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -71374,11 +71346,11 @@
71374 u.cm.pVtabCursor = 0;
71375 u.cm.pVtab = pOp->p4.pVtab->pVtab;
71376 u.cm.pModule = (sqlite3_module *)u.cm.pVtab->pModule;
71377 assert(u.cm.pVtab && u.cm.pModule);
71378 rc = u.cm.pModule->xOpen(u.cm.pVtab, &u.cm.pVtabCursor);
71379 importVtabErrMsg(p, u.cm.pVtab);
71380 if( SQLITE_OK==rc ){
71381 /* Initialize sqlite3_vtab_cursor base class */
71382 u.cm.pVtabCursor->pVtab = u.cm.pVtab;
71383
71384 /* Initialize vdbe cursor object */
@@ -71454,11 +71426,11 @@
71454 }
71455
71456 p->inVtabMethod = 1;
71457 rc = u.cn.pModule->xFilter(u.cn.pVtabCursor, u.cn.iQuery, pOp->p4.z, u.cn.nArg, u.cn.apArg);
71458 p->inVtabMethod = 0;
71459 importVtabErrMsg(p, u.cn.pVtab);
71460 if( rc==SQLITE_OK ){
71461 u.cn.res = u.cn.pModule->xEof(u.cn.pVtabCursor);
71462 }
71463
71464 if( u.cn.res ){
@@ -71507,11 +71479,11 @@
71507 */
71508 sqlite3VdbeMemMove(&u.co.sContext.s, u.co.pDest);
71509 MemSetTypeFlag(&u.co.sContext.s, MEM_Null);
71510
71511 rc = u.co.pModule->xColumn(pCur->pVtabCursor, &u.co.sContext, pOp->p2);
71512 importVtabErrMsg(p, u.co.pVtab);
71513 if( u.co.sContext.isError ){
71514 rc = u.co.sContext.isError;
71515 }
71516
71517 /* Copy the result of the function to the P3 register. We
@@ -71562,11 +71534,11 @@
71562 ** some other method is next invoked on the save virtual table cursor.
71563 */
71564 p->inVtabMethod = 1;
71565 rc = u.cp.pModule->xNext(u.cp.pCur->pVtabCursor);
71566 p->inVtabMethod = 0;
71567 importVtabErrMsg(p, u.cp.pVtab);
71568 if( rc==SQLITE_OK ){
71569 u.cp.res = u.cp.pModule->xEof(u.cp.pCur->pVtabCursor);
71570 }
71571
71572 if( !u.cp.res ){
@@ -71601,11 +71573,11 @@
71601 testcase( u.cq.pName->enc==SQLITE_UTF16BE );
71602 testcase( u.cq.pName->enc==SQLITE_UTF16LE );
71603 rc = sqlite3VdbeChangeEncoding(u.cq.pName, SQLITE_UTF8);
71604 if( rc==SQLITE_OK ){
71605 rc = u.cq.pVtab->pModule->xRename(u.cq.pVtab, u.cq.pName->z);
71606 importVtabErrMsg(p, u.cq.pVtab);
71607 p->expired = 0;
71608 }
71609 break;
71610 }
71611 #endif
@@ -71665,11 +71637,11 @@
71665 u.cr.pX++;
71666 }
71667 db->vtabOnConflict = pOp->p5;
71668 rc = u.cr.pModule->xUpdate(u.cr.pVtab, u.cr.nArg, u.cr.apArg, &u.cr.rowid);
71669 db->vtabOnConflict = vtabOnConflict;
71670 importVtabErrMsg(p, u.cr.pVtab);
71671 if( rc==SQLITE_OK && pOp->p1 ){
71672 assert( u.cr.nArg>1 && u.cr.apArg[0] && (u.cr.apArg[0]->flags&MEM_Null) );
71673 db->lastRowid = lastRowid = u.cr.rowid;
71674 }
71675 if( (rc&0xff)==SQLITE_CONSTRAINT && pOp->p4.pVtab->bConstraint ){
@@ -75593,12 +75565,11 @@
75593 int op = p->op;
75594 if( op==TK_CAST || op==TK_UPLUS ){
75595 p = p->pLeft;
75596 continue;
75597 }
75598 assert( op!=TK_REGISTER || p->op2!=TK_COLLATE );
75599 if( op==TK_COLLATE ){
75600 pColl = sqlite3GetCollSeq(pParse, ENC(db), 0, p->u.zToken);
75601 break;
75602 }
75603 if( p->pTab!=0
75604 && (op==TK_AGG_COLUMN || op==TK_COLUMN
@@ -78984,10 +78955,11 @@
78984 compLeft.pRight = pExpr->x.pList->a[0].pExpr;
78985 compRight.op = TK_LE;
78986 compRight.pLeft = &exprX;
78987 compRight.pRight = pExpr->x.pList->a[1].pExpr;
78988 exprX.iTable = sqlite3ExprCodeTemp(pParse, &exprX, &regFree1);
 
78989 exprX.op = TK_REGISTER;
78990 if( jumpIfTrue ){
78991 sqlite3ExprIfTrue(pParse, &exprAnd, dest, jumpIfNull);
78992 }else{
78993 sqlite3ExprIfFalse(pParse, &exprAnd, dest, jumpIfNull);
@@ -89001,13 +88973,13 @@
89001 }
89002 static void groupConcatFinalize(sqlite3_context *context){
89003 StrAccum *pAccum;
89004 pAccum = sqlite3_aggregate_context(context, 0);
89005 if( pAccum ){
89006 if( pAccum->tooBig ){
89007 sqlite3_result_error_toobig(context);
89008 }else if( pAccum->mallocFailed ){
89009 sqlite3_result_error_nomem(context);
89010 }else{
89011 sqlite3_result_text(context, sqlite3StrAccumFinish(pAccum), -1,
89012 sqlite3_free);
89013 }
@@ -104488,14 +104460,13 @@
104488 /*
104489 ** Invoke the xSync method of all virtual tables in the sqlite3.aVTrans
104490 ** array. Return the error code for the first error that occurs, or
104491 ** SQLITE_OK if all xSync operations are successful.
104492 **
104493 ** Set *pzErrmsg to point to a buffer that should be released using
104494 ** sqlite3DbFree() containing an error message, if one is available.
104495 */
104496 SQLITE_PRIVATE int sqlite3VtabSync(sqlite3 *db, char **pzErrmsg){
104497 int i;
104498 int rc = SQLITE_OK;
104499 VTable **aVTrans = db->aVTrans;
104500
104501 db->aVTrans = 0;
@@ -104502,13 +104473,11 @@
104502 for(i=0; rc==SQLITE_OK && i<db->nVTrans; i++){
104503 int (*x)(sqlite3_vtab *);
104504 sqlite3_vtab *pVtab = aVTrans[i]->pVtab;
104505 if( pVtab && (x = pVtab->pModule->xSync)!=0 ){
104506 rc = x(pVtab);
104507 sqlite3DbFree(db, *pzErrmsg);
104508 *pzErrmsg = pVtab->zErrMsg;
104509 pVtab->zErrMsg = 0;
104510 }
104511 }
104512 db->aVTrans = aVTrans;
104513 return rc;
104514 }
@@ -104869,10 +104838,11 @@
104869 int iIdxCur; /* The VDBE cursor used to access pIdx */
104870 int addrBrk; /* Jump here to break out of the loop */
104871 int addrNxt; /* Jump here to start the next IN combination */
104872 int addrCont; /* Jump here to continue with the next loop cycle */
104873 int addrFirst; /* First instruction of interior of the loop */
 
104874 u8 iFrom; /* Which entry in the FROM clause */
104875 u8 op, p5; /* Opcode and P5 of the opcode that ends the loop */
104876 int p1, p2; /* Operands of the opcode used to ends the loop */
104877 union { /* Information that depends on pWLoop->wsFlags */
104878 struct {
@@ -107808,11 +107778,11 @@
107808 pParse->db->mallocFailed = 1;
107809 }
107810
107811 /* Evaluate the equality constraints
107812 */
107813 assert( pIdx->nColumn>=nEq );
107814 for(j=0; j<nEq; j++){
107815 int r1;
107816 pTerm = pLoop->aLTerm[j];
107817 assert( pTerm!=0 );
107818 /* The following true for indices with redundant columns.
@@ -107900,11 +107870,12 @@
107900 }
107901 sqlite3StrAccumInit(&txt, 0, 0, SQLITE_MAX_LENGTH);
107902 txt.db = db;
107903 sqlite3StrAccumAppend(&txt, " (", 2);
107904 for(i=0; i<nEq; i++){
107905 explainAppendTerm(&txt, i, aCol[aiColumn[i]].zName, "=");
 
107906 }
107907
107908 j = i;
107909 if( pLoop->wsFlags&WHERE_BTM_LIMIT ){
107910 char *z = (j==pIndex->nColumn ) ? "rowid" : aCol[aiColumn[j]].zName;
@@ -109115,17 +109086,15 @@
109115 pNew->rSetup = 0;
109116 rLogSize = estLog(whereCost(pProbe->aiRowEst[0]));
109117 for(; rc==SQLITE_OK && pTerm!=0; pTerm = whereScanNext(&scan)){
109118 int nIn = 0;
109119 if( pTerm->prereqRight & pNew->maskSelf ) continue;
109120 #ifdef SQLITE_ENABLE_STAT3
109121 if( (pTerm->wtFlags & TERM_VNULL)!=0
109122 && (iCol<0 || pSrc->pTab->aCol[iCol].notNull)
109123 ){
109124 continue; /* skip IS NOT NULL constraints on a NOT NULL column */
109125 }
109126 #endif
109127 pNew->wsFlags = saved_wsFlags;
109128 pNew->u.btree.nEq = saved_nEq;
109129 pNew->nLTerm = saved_nLTerm;
109130 if( whereLoopResize(db, pNew, pNew->nLTerm+1) ) break; /* OOM */
109131 pNew->aLTerm[pNew->nLTerm++] = pTerm;
@@ -110764,15 +110733,10 @@
110764 assert( n<=pTab->nCol );
110765 }
110766 }else{
110767 sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
110768 }
110769 #ifndef SQLITE_OMIT_AUTOMATIC_INDEX
110770 if( (pLoop->wsFlags & WHERE_AUTO_INDEX)!=0 ){
110771 constructAutomaticIndex(pParse, &pWInfo->sWC, pTabItem, notReady, pLevel);
110772 }else
110773 #endif
110774 if( pLoop->wsFlags & WHERE_INDEXED ){
110775 Index *pIx = pLoop->u.btree.pIndex;
110776 KeyInfo *pKey = sqlite3IndexKeyinfo(pParse, pIx);
110777 /* FIXME: As an optimization use pTabItem->iCursor if WHERE_IDX_ONLY */
110778 int iIndexCur = pLevel->iIdxCur = iIdxCur ? iIdxCur : pParse->nTab++;
@@ -110793,11 +110757,19 @@
110793 ** program.
110794 */
110795 notReady = ~(Bitmask)0;
110796 for(ii=0; ii<nTabList; ii++){
110797 pLevel = &pWInfo->a[ii];
 
 
 
 
 
 
 
110798 explainOneScan(pParse, pTabList, pLevel, ii, pLevel->iFrom, wctrlFlags);
 
110799 notReady = codeOneLoopStart(pWInfo, ii, notReady);
110800 pWInfo->iContinue = pLevel->addrCont;
110801 }
110802
110803 /* Done. */
@@ -110913,13 +110885,14 @@
110913 }
110914 if( pIdx && !db->mallocFailed ){
110915 int k, j, last;
110916 VdbeOp *pOp;
110917
110918 pOp = sqlite3VdbeGetOp(v, pWInfo->iTop);
110919 last = sqlite3VdbeCurrentAddr(v);
110920 for(k=pWInfo->iTop; k<last; k++, pOp++){
 
 
110921 if( pOp->p1!=pLevel->iTabCur ) continue;
110922 if( pOp->opcode==OP_Column ){
110923 for(j=0; j<pIdx->nColumn; j++){
110924 if( pOp->p2==pIdx->aiColumn[j] ){
110925 pOp->p2 = j;
@@ -134651,15 +134624,15 @@
134651 }
134652 }
134653 if( pTC ) pModule->xClose(pTC);
134654 if( rc==SQLITE_DONE ) rc = SQLITE_OK;
134655 }
 
134656
134657 for(pDef=pCsr->pDeferred; pDef && rc==SQLITE_OK; pDef=pDef->pNext){
134658 if( pDef->pList ){
134659 rc = fts3PendingListAppendVarint(&pDef->pList, 0);
134660 }
134661 }
134662 }
134663 }
134664
134665 return rc;
134666
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -656,11 +656,11 @@
656 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
657 ** [sqlite_version()] and [sqlite_source_id()].
658 */
659 #define SQLITE_VERSION "3.8.0"
660 #define SQLITE_VERSION_NUMBER 3008000
661 #define SQLITE_SOURCE_ID "2013-08-22 02:56:28 0775501acf152dcbf4dd039f4511f3d8c4330d85"
662
663 /*
664 ** CAPI3REF: Run-Time Library Version Numbers
665 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
666 **
@@ -9288,12 +9288,12 @@
9288 #define PAGER_JOURNALMODE_WAL 5 /* Use write-ahead logging */
9289
9290 /*
9291 ** Flags that make up the mask passed to sqlite3PagerAcquire().
9292 */
9293 #define PAGER_GET_NOCONTENT 0x01 /* Do not load data from disk */
9294 #define PAGER_GET_READONLY 0x02 /* Read-only page is acceptable */
9295
9296 /*
9297 ** Flags for sqlite3PagerSetFlags()
9298 */
9299 #define PAGER_SYNCHRONOUS_OFF 0x01 /* PRAGMA synchronous=OFF */
@@ -11645,14 +11645,15 @@
11645 char *zBase; /* A base allocation. Not from malloc. */
11646 char *zText; /* The string collected so far */
11647 int nChar; /* Length of the string so far */
11648 int nAlloc; /* Amount of space allocated in zText */
11649 int mxAlloc; /* Maximum allowed string length */
 
11650 u8 useMalloc; /* 0: none, 1: sqlite3DbMalloc, 2: sqlite3_malloc */
11651 u8 accError; /* STRACCUM_NOMEM or STRACCUM_TOOBIG */
11652 };
11653 #define STRACCUM_NOMEM 1
11654 #define STRACCUM_TOOBIG 2
11655
11656 /*
11657 ** A pointer to this structure is used to communicate information
11658 ** from sqlite3Init and OP_ParseSchema into the sqlite3InitCallback.
11659 */
@@ -12373,17 +12374,18 @@
12374 # define sqlite3VtabSavepoint(X, Y, Z) SQLITE_OK
12375 # define sqlite3GetVTable(X,Y) ((VTable*)0)
12376 #else
12377 SQLITE_PRIVATE void sqlite3VtabClear(sqlite3 *db, Table*);
12378 SQLITE_PRIVATE void sqlite3VtabDisconnect(sqlite3 *db, Table *p);
12379 SQLITE_PRIVATE int sqlite3VtabSync(sqlite3 *db, Vdbe*);
12380 SQLITE_PRIVATE int sqlite3VtabRollback(sqlite3 *db);
12381 SQLITE_PRIVATE int sqlite3VtabCommit(sqlite3 *db);
12382 SQLITE_PRIVATE void sqlite3VtabLock(VTable *);
12383 SQLITE_PRIVATE void sqlite3VtabUnlock(VTable *);
12384 SQLITE_PRIVATE void sqlite3VtabUnlockList(sqlite3*);
12385 SQLITE_PRIVATE int sqlite3VtabSavepoint(sqlite3 *, int, int);
12386 SQLITE_PRIVATE void sqlite3VtabImportErrmsg(Vdbe*, sqlite3_vtab*);
12387 SQLITE_PRIVATE VTable *sqlite3GetVTable(sqlite3*, Table*);
12388 # define sqlite3VtabInSync(db) ((db)->nVTrans>0 && (db)->aVTrans==0)
12389 #endif
12390 SQLITE_PRIVATE void sqlite3VtabMakeWritable(Parse*,Table*);
12391 SQLITE_PRIVATE void sqlite3VtabBeginParse(Parse*, Token*, Token*, Token*, int);
@@ -19899,11 +19901,11 @@
19901 zOut = buf;
19902 }else{
19903 nOut = precision + 10;
19904 zOut = zExtra = sqlite3Malloc( nOut );
19905 if( zOut==0 ){
19906 pAccum->accError = STRACCUM_NOMEM;
19907 return;
19908 }
19909 }
19910 bufpt = &zOut[nOut-1];
19911 if( xtype==etORDINAL ){
@@ -20011,11 +20013,11 @@
20013 e2 = exp;
20014 }
20015 if( MAX(e2,0)+precision+width > etBUFSIZE - 15 ){
20016 bufpt = zExtra = sqlite3Malloc( MAX(e2,0)+precision+width+15 );
20017 if( bufpt==0 ){
20018 pAccum->accError = STRACCUM_NOMEM;
20019 return;
20020 }
20021 }
20022 zOut = bufpt;
20023 nsd = 16 + flag_altform2*10;
@@ -20146,11 +20148,11 @@
20148 needQuote = !isnull && xtype==etSQLESCAPE2;
20149 n += i + 1 + needQuote*2;
20150 if( n>etBUFSIZE ){
20151 bufpt = zExtra = sqlite3Malloc( n );
20152 if( bufpt==0 ){
20153 pAccum->accError = STRACCUM_NOMEM;
20154 return;
20155 }
20156 }else{
20157 bufpt = buf;
20158 }
@@ -20224,26 +20226,24 @@
20226 /*
20227 ** Append N bytes of text from z to the StrAccum object.
20228 */
20229 SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum *p, const char *z, int N){
20230 assert( z!=0 || N==0 );
20231 if( p->accError ){
20232 testcase(p->accError==STRACCUM_TOOBIG);
20233 testcase(p->accError==STRACCUM_NOMEM);
20234 return;
20235 }
20236 assert( p->zText!=0 || p->nChar==0 );
20237 if( N<=0 ){
20238 if( N==0 || z[0]==0 ) return;
20239 N = sqlite3Strlen30(z);
20240 }
 
 
 
20241 if( p->nChar+N >= p->nAlloc ){
20242 char *zNew;
20243 if( !p->useMalloc ){
20244 p->accError = STRACCUM_TOOBIG;
20245 N = p->nAlloc - p->nChar - 1;
20246 if( N<=0 ){
20247 return;
20248 }
20249 }else{
@@ -20250,11 +20250,11 @@
20250 char *zOld = (p->zText==p->zBase ? 0 : p->zText);
20251 i64 szNew = p->nChar;
20252 szNew += N + 1;
20253 if( szNew > p->mxAlloc ){
20254 sqlite3StrAccumReset(p);
20255 p->accError = STRACCUM_TOOBIG;
20256 return;
20257 }else{
20258 p->nAlloc = (int)szNew;
20259 }
20260 if( p->useMalloc==1 ){
@@ -20264,11 +20264,11 @@
20264 }
20265 if( zNew ){
20266 if( zOld==0 && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar);
20267 p->zText = zNew;
20268 }else{
20269 p->accError = STRACCUM_NOMEM;
20270 sqlite3StrAccumReset(p);
20271 return;
20272 }
20273 }
20274 }
@@ -20292,11 +20292,11 @@
20292 p->zText = sqlite3_malloc(p->nChar+1);
20293 }
20294 if( p->zText ){
20295 memcpy(p->zText, p->zBase, p->nChar+1);
20296 }else{
20297 p->accError = STRACCUM_NOMEM;
20298 }
20299 }
20300 }
20301 return p->zText;
20302 }
@@ -20323,12 +20323,11 @@
20323 p->db = 0;
20324 p->nChar = 0;
20325 p->nAlloc = n;
20326 p->mxAlloc = mx;
20327 p->useMalloc = 1;
20328 p->accError = 0;
 
20329 }
20330
20331 /*
20332 ** Print into memory obtained from sqliteMalloc(). Use the internal
20333 ** %-conversion extensions.
@@ -20341,11 +20340,11 @@
20340 sqlite3StrAccumInit(&acc, zBase, sizeof(zBase),
20341 db->aLimit[SQLITE_LIMIT_LENGTH]);
20342 acc.db = db;
20343 sqlite3VXPrintf(&acc, 1, zFormat, ap);
20344 z = sqlite3StrAccumFinish(&acc);
20345 if( acc.accError==STRACCUM_NOMEM ){
20346 db->mallocFailed = 1;
20347 }
20348 return z;
20349 }
20350
@@ -20538,28 +20537,15 @@
20537 unsigned char i, j; /* State variables */
20538 unsigned char s[256]; /* State variables */
20539 } sqlite3Prng;
20540
20541 /*
20542 ** Return N random bytes.
 
 
 
 
 
 
 
 
 
 
 
 
 
20543 */
20544 SQLITE_API void sqlite3_randomness(int N, void *pBuf){
20545 unsigned char t;
20546 unsigned char *zBuf = pBuf;
20547
20548 /* The "wsdPrng" macro will resolve to the pseudo-random number generator
20549 ** state vector. If writable static data is unsupported on the target,
20550 ** we have to locate the state vector at run-time. In the more common
20551 ** case where writable static data is supported, wsdPrng can refer directly
@@ -20570,10 +20556,14 @@
20556 # define wsdPrng p[0]
20557 #else
20558 # define wsdPrng sqlite3Prng
20559 #endif
20560
20561 #if SQLITE_THREADSAFE
20562 sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_PRNG);
20563 sqlite3_mutex_enter(mutex);
20564 #endif
20565
20566 /* Initialize the state of the random number generator once,
20567 ** the first time this routine is called. The seed value does
20568 ** not need to contain a lot of randomness since we are not
20569 ** trying to do secure encryption or anything like that...
@@ -20598,32 +20588,18 @@
20588 wsdPrng.s[i] = t;
20589 }
20590 wsdPrng.isInit = 1;
20591 }
20592
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20593 while( N-- ){
20594 wsdPrng.i++;
20595 t = wsdPrng.s[wsdPrng.i];
20596 wsdPrng.j += t;
20597 wsdPrng.s[wsdPrng.i] = wsdPrng.s[wsdPrng.j];
20598 wsdPrng.s[wsdPrng.j] = t;
20599 t += wsdPrng.s[wsdPrng.i];
20600 *(zBuf++) = wsdPrng.s[t];
20601 }
20602 sqlite3_mutex_leave(mutex);
20603 }
20604
20605 #ifndef SQLITE_OMIT_BUILTIN_TEST
@@ -39378,17 +39354,21 @@
39354 ** * The page-number is less than or equal to PagerSavepoint.nOrig, and
39355 ** * The bit corresponding to the page-number is not set in
39356 ** PagerSavepoint.pInSavepoint.
39357 */
39358 static int subjRequiresPage(PgHdr *pPg){
 
39359 Pager *pPager = pPg->pPager;
39360 PagerSavepoint *p;
39361 Pgno pgno;
39362 int i;
39363 if( pPager->nSavepoint ){
39364 pgno = pPg->pgno;
39365 for(i=0; i<pPager->nSavepoint; i++){
39366 p = &pPager->aSavepoint[i];
39367 if( p->nOrig>=pgno && 0==sqlite3BitvecTest(p->pInSavepoint, pgno) ){
39368 return 1;
39369 }
39370 }
39371 }
39372 return 0;
39373 }
39374
@@ -41230,16 +41210,10 @@
41210 int pgsz = pPager->pageSize; /* Number of bytes to read */
41211
41212 assert( pPager->eState>=PAGER_READER && !MEMDB );
41213 assert( isOpen(pPager->fd) );
41214
 
 
 
 
 
 
41215 #ifndef SQLITE_OMIT_WAL
41216 if( iFrame ){
41217 /* Try to pull the page from the write-ahead log. */
41218 rc = sqlite3WalReadFrame(pPager->pWal, iFrame, pgsz, pPg->pData);
41219 }else
@@ -43589,23 +43563,23 @@
43563 */
43564 SQLITE_PRIVATE int sqlite3PagerAcquire(
43565 Pager *pPager, /* The pager open on the database file */
43566 Pgno pgno, /* Page number to fetch */
43567 DbPage **ppPage, /* Write a pointer to the page here */
43568 int flags /* PAGER_GET_XXX flags */
43569 ){
43570 int rc = SQLITE_OK;
43571 PgHdr *pPg = 0;
43572 u32 iFrame = 0; /* Frame to read from WAL file */
43573 const int noContent = (flags & PAGER_GET_NOCONTENT);
43574
43575 /* It is acceptable to use a read-only (mmap) page for any page except
43576 ** page 1 if there is no write-transaction open or the ACQUIRE_READONLY
43577 ** flag was specified by the caller. And so long as the db is not a
43578 ** temporary or in-memory database. */
43579 const int bMmapOk = (pgno!=1 && USEFETCH(pPager)
43580 && (pPager->eState==PAGER_READER || (flags & PAGER_GET_READONLY))
43581 #ifdef SQLITE_HAS_CODEC
43582 && pPager->xCodec==0
43583 #endif
43584 );
43585
@@ -50544,11 +50518,12 @@
50518 assert( pPage->leaf==0 || pPage->leaf==1 );
50519 n = pPage->childPtrSize;
50520 assert( n==4-4*pPage->leaf );
50521 if( pPage->intKey ){
50522 if( pPage->hasData ){
50523 assert( n==0 );
50524 n = getVarint32(pCell, nPayload);
50525 }else{
50526 nPayload = 0;
50527 }
50528 n += getVarint(&pCell[n], (u64*)&pInfo->nKey);
50529 pInfo->nData = nPayload;
@@ -51188,19 +51163,16 @@
51163 */
51164 static int btreeGetPage(
51165 BtShared *pBt, /* The btree */
51166 Pgno pgno, /* Number of the page to fetch */
51167 MemPage **ppPage, /* Return the page in this parameter */
51168 int flags /* PAGER_GET_NOCONTENT or PAGER_GET_READONLY */
 
51169 ){
51170 int rc;
51171 DbPage *pDbPage;
 
 
51172
51173 assert( flags==0 || flags==PAGER_GET_NOCONTENT || flags==PAGER_GET_READONLY );
51174 assert( sqlite3_mutex_held(pBt->mutex) );
51175 rc = sqlite3PagerAcquire(pBt->pPager, pgno, (DbPage**)&pDbPage, flags);
51176 if( rc ) return rc;
51177 *ppPage = btreePageFromDbPage(pDbPage, pgno, pBt);
51178 return SQLITE_OK;
@@ -51244,19 +51216,20 @@
51216 */
51217 static int getAndInitPage(
51218 BtShared *pBt, /* The database file */
51219 Pgno pgno, /* Number of the page to get */
51220 MemPage **ppPage, /* Write the page pointer here */
51221 int bReadonly /* PAGER_GET_READONLY or 0 */
51222 ){
51223 int rc;
51224 assert( sqlite3_mutex_held(pBt->mutex) );
51225 assert( bReadonly==PAGER_GET_READONLY || bReadonly==0 );
51226
51227 if( pgno>btreePagecount(pBt) ){
51228 rc = SQLITE_CORRUPT_BKPT;
51229 }else{
51230 rc = btreeGetPage(pBt, pgno, ppPage, bReadonly);
51231 if( rc==SQLITE_OK ){
51232 rc = btreeInitPage(*ppPage);
51233 if( rc!=SQLITE_OK ){
51234 releasePage(*ppPage);
51235 }
@@ -51985,11 +51958,11 @@
51958
51959 assert( sqlite3_mutex_held(pBt->mutex) );
51960 assert( pBt->pPage1==0 );
51961 rc = sqlite3PagerSharedLock(pBt->pPager);
51962 if( rc!=SQLITE_OK ) return rc;
51963 rc = btreeGetPage(pBt, 1, &pPage1, 0);
51964 if( rc!=SQLITE_OK ) return rc;
51965
51966 /* Do some checking to help insure the file we opened really is
51967 ** a valid database file.
51968 */
@@ -52567,11 +52540,11 @@
52540 /* Fix the database pointer on page iPtrPage that pointed at iDbPage so
52541 ** that it points at iFreePage. Also fix the pointer map entry for
52542 ** iPtrPage.
52543 */
52544 if( eType!=PTRMAP_ROOTPAGE ){
52545 rc = btreeGetPage(pBt, iPtrPage, &pPtrPage, 0);
52546 if( rc!=SQLITE_OK ){
52547 return rc;
52548 }
52549 rc = sqlite3PagerWrite(pPtrPage->pDbPage);
52550 if( rc!=SQLITE_OK ){
@@ -52651,11 +52624,11 @@
52624 Pgno iFreePg; /* Index of free page to move pLastPg to */
52625 MemPage *pLastPg;
52626 u8 eMode = BTALLOC_ANY; /* Mode parameter for allocateBtreePage() */
52627 Pgno iNear = 0; /* nearby parameter for allocateBtreePage() */
52628
52629 rc = btreeGetPage(pBt, iLastPg, &pLastPg, 0);
52630 if( rc!=SQLITE_OK ){
52631 return rc;
52632 }
52633
52634 /* If bCommit is zero, this loop runs exactly once and page pLastPg
@@ -53050,11 +53023,11 @@
53023 }
53024
53025 /* The rollback may have destroyed the pPage1->aData value. So
53026 ** call btreeGetPage() on page 1 again to make
53027 ** sure pPage1->aData is set correctly. */
53028 if( btreeGetPage(pBt, 1, &pPage1, 0)==SQLITE_OK ){
53029 int nPage = get4byte(28+(u8*)pPage1->aData);
53030 testcase( nPage==0 );
53031 if( nPage==0 ) sqlite3PagerPagecount(pBt->pPager, &nPage);
53032 testcase( pBt->nPage!=nPage );
53033 pBt->nPage = nPage;
@@ -53485,11 +53458,11 @@
53458 }
53459 #endif
53460
53461 assert( next==0 || rc==SQLITE_DONE );
53462 if( rc==SQLITE_OK ){
53463 rc = btreeGetPage(pBt, ovfl, &pPage, (ppPage==0) ? PAGER_GET_READONLY : 0);
53464 assert( rc==SQLITE_OK || pPage==0 );
53465 if( rc==SQLITE_OK ){
53466 next = get4byte(pPage->aData);
53467 }
53468 }
@@ -53707,11 +53680,11 @@
53680 #endif
53681
53682 {
53683 DbPage *pDbPage;
53684 rc = sqlite3PagerAcquire(pBt->pPager, nextPage, &pDbPage,
53685 (eOp==0 ? PAGER_GET_READONLY : 0)
53686 );
53687 if( rc==SQLITE_OK ){
53688 aPayload = sqlite3PagerGetData(pDbPage);
53689 nextPage = get4byte(aPayload);
53690 rc = copyPayload(&aPayload[offset+4], pBuf, a, eOp, pDbPage);
@@ -53891,11 +53864,12 @@
53864 assert( pCur->iPage<BTCURSOR_MAX_DEPTH );
53865 assert( pCur->iPage>=0 );
53866 if( pCur->iPage>=(BTCURSOR_MAX_DEPTH-1) ){
53867 return SQLITE_CORRUPT_BKPT;
53868 }
53869 rc = getAndInitPage(pBt, newPgno, &pNewPage,
53870 pCur->wrFlag==0 ? PAGER_GET_READONLY : 0);
53871 if( rc ) return rc;
53872 pCur->apPage[i+1] = pNewPage;
53873 pCur->aiIdx[i+1] = 0;
53874 pCur->iPage++;
53875
@@ -54008,11 +53982,12 @@
53982 pCur->iPage = 0;
53983 }else if( pCur->pgnoRoot==0 ){
53984 pCur->eState = CURSOR_INVALID;
53985 return SQLITE_OK;
53986 }else{
53987 rc = getAndInitPage(pBt, pCur->pgnoRoot, &pCur->apPage[0],
53988 pCur->wrFlag==0 ? PAGER_GET_READONLY : 0);
53989 if( rc!=SQLITE_OK ){
53990 pCur->eState = CURSOR_INVALID;
53991 return rc;
53992 }
53993 pCur->iPage = 0;
@@ -54645,11 +54620,11 @@
54620 }
54621 testcase( iTrunk==mxPage );
54622 if( iTrunk>mxPage ){
54623 rc = SQLITE_CORRUPT_BKPT;
54624 }else{
54625 rc = btreeGetPage(pBt, iTrunk, &pTrunk, 0);
54626 }
54627 if( rc ){
54628 pTrunk = 0;
54629 goto end_allocate_page;
54630 }
@@ -54709,11 +54684,11 @@
54684 if( iNewTrunk>mxPage ){
54685 rc = SQLITE_CORRUPT_BKPT;
54686 goto end_allocate_page;
54687 }
54688 testcase( iNewTrunk==mxPage );
54689 rc = btreeGetPage(pBt, iNewTrunk, &pNewTrunk, 0);
54690 if( rc!=SQLITE_OK ){
54691 goto end_allocate_page;
54692 }
54693 rc = sqlite3PagerWrite(pNewTrunk->pDbPage);
54694 if( rc!=SQLITE_OK ){
@@ -54788,12 +54763,12 @@
54763 if( rc ) goto end_allocate_page;
54764 if( closest<k-1 ){
54765 memcpy(&aData[8+closest*4], &aData[4+k*4], 4);
54766 }
54767 put4byte(&aData[4], k-1);
54768 noContent = !btreeGetHasContent(pBt, *pPgno) ? PAGER_GET_NOCONTENT : 0;
54769 rc = btreeGetPage(pBt, *pPgno, ppPage, noContent);
54770 if( rc==SQLITE_OK ){
54771 rc = sqlite3PagerWrite((*ppPage)->pDbPage);
54772 if( rc!=SQLITE_OK ){
54773 releasePage(*ppPage);
54774 }
@@ -54821,11 +54796,11 @@
54796 ** content for any page that really does lie past the end of the database
54797 ** file on disk. So the effects of disabling the no-content optimization
54798 ** here are confined to those pages that lie between the end of the
54799 ** database image and the end of the database file.
54800 */
54801 int bNoContent = (0==IfNotOmitAV(pBt->bDoTruncate)) ? PAGER_GET_NOCONTENT : 0;
54802
54803 rc = sqlite3PagerWrite(pBt->pPage1->pDbPage);
54804 if( rc ) return rc;
54805 pBt->nPage++;
54806 if( pBt->nPage==PENDING_BYTE_PAGE(pBt) ) pBt->nPage++;
@@ -54837,11 +54812,11 @@
54812 ** becomes a new pointer-map page, the second is used by the caller.
54813 */
54814 MemPage *pPg = 0;
54815 TRACE(("ALLOCATE: %d from end of file (pointer-map page)\n", pBt->nPage));
54816 assert( pBt->nPage!=PENDING_BYTE_PAGE(pBt) );
54817 rc = btreeGetPage(pBt, pBt->nPage, &pPg, bNoContent);
54818 if( rc==SQLITE_OK ){
54819 rc = sqlite3PagerWrite(pPg->pDbPage);
54820 releasePage(pPg);
54821 }
54822 if( rc ) return rc;
@@ -54851,11 +54826,11 @@
54826 #endif
54827 put4byte(28 + (u8*)pBt->pPage1->aData, pBt->nPage);
54828 *pPgno = pBt->nPage;
54829
54830 assert( *pPgno!=PENDING_BYTE_PAGE(pBt) );
54831 rc = btreeGetPage(pBt, *pPgno, ppPage, bNoContent);
54832 if( rc ) return rc;
54833 rc = sqlite3PagerWrite((*ppPage)->pDbPage);
54834 if( rc!=SQLITE_OK ){
54835 releasePage(*ppPage);
54836 }
@@ -54919,11 +54894,11 @@
54894
54895 if( pBt->btsFlags & BTS_SECURE_DELETE ){
54896 /* If the secure_delete option is enabled, then
54897 ** always fully overwrite deleted information with zeros.
54898 */
54899 if( (!pPage && ((rc = btreeGetPage(pBt, iPage, &pPage, 0))!=0) )
54900 || ((rc = sqlite3PagerWrite(pPage->pDbPage))!=0)
54901 ){
54902 goto freepage_out;
54903 }
54904 memset(pPage->aData, 0, pPage->pBt->pageSize);
@@ -54946,11 +54921,11 @@
54921 */
54922 if( nFree!=0 ){
54923 u32 nLeaf; /* Initial number of leaf cells on trunk page */
54924
54925 iTrunk = get4byte(&pPage1->aData[32]);
54926 rc = btreeGetPage(pBt, iTrunk, &pTrunk, 0);
54927 if( rc!=SQLITE_OK ){
54928 goto freepage_out;
54929 }
54930
54931 nLeaf = get4byte(&pTrunk->aData[4]);
@@ -54992,11 +54967,11 @@
54967 ** the page being freed as a leaf page of the first trunk in the free-list.
54968 ** Possibly because the free-list is empty, or possibly because the
54969 ** first trunk in the free-list is full. Either way, the page being freed
54970 ** will become the new first trunk page in the free-list.
54971 */
54972 if( pPage==0 && SQLITE_OK!=(rc = btreeGetPage(pBt, iPage, &pPage, 0)) ){
54973 goto freepage_out;
54974 }
54975 rc = sqlite3PagerWrite(pPage->pDbPage);
54976 if( rc!=SQLITE_OK ){
54977 goto freepage_out;
@@ -56891,11 +56866,11 @@
56866 if( rc!=SQLITE_OK ){
56867 return rc;
56868 }
56869
56870 /* Move the page currently at pgnoRoot to pgnoMove. */
56871 rc = btreeGetPage(pBt, pgnoRoot, &pRoot, 0);
56872 if( rc!=SQLITE_OK ){
56873 return rc;
56874 }
56875 rc = ptrmapGet(pBt, pgnoRoot, &eType, &iPtrPage);
56876 if( eType==PTRMAP_ROOTPAGE || eType==PTRMAP_FREEPAGE ){
@@ -56912,11 +56887,11 @@
56887
56888 /* Obtain the page at pgnoRoot */
56889 if( rc!=SQLITE_OK ){
56890 return rc;
56891 }
56892 rc = btreeGetPage(pBt, pgnoRoot, &pRoot, 0);
56893 if( rc!=SQLITE_OK ){
56894 return rc;
56895 }
56896 rc = sqlite3PagerWrite(pRoot->pDbPage);
56897 if( rc!=SQLITE_OK ){
@@ -57090,11 +57065,11 @@
57065 if( NEVER(pBt->pCursor) ){
57066 sqlite3ConnectionBlocked(p->db, pBt->pCursor->pBtree->db);
57067 return SQLITE_LOCKED_SHAREDCACHE;
57068 }
57069
57070 rc = btreeGetPage(pBt, (Pgno)iTable, &pPage, 0);
57071 if( rc ) return rc;
57072 rc = sqlite3BtreeClearTable(p, iTable, 0);
57073 if( rc ){
57074 releasePage(pPage);
57075 return rc;
@@ -57125,21 +57100,21 @@
57100 ** number in the database. So move the page that does into the
57101 ** gap left by the deleted root-page.
57102 */
57103 MemPage *pMove;
57104 releasePage(pPage);
57105 rc = btreeGetPage(pBt, maxRootPgno, &pMove, 0);
57106 if( rc!=SQLITE_OK ){
57107 return rc;
57108 }
57109 rc = relocatePage(pBt, pMove, PTRMAP_ROOTPAGE, 0, iTable, 0);
57110 releasePage(pMove);
57111 if( rc!=SQLITE_OK ){
57112 return rc;
57113 }
57114 pMove = 0;
57115 rc = btreeGetPage(pBt, maxRootPgno, &pMove, 0);
57116 freePage(pMove, &rc);
57117 releasePage(pMove);
57118 if( rc!=SQLITE_OK ){
57119 return rc;
57120 }
@@ -57350,11 +57325,11 @@
57325 if( zMsg1 ){
57326 sqlite3StrAccumAppend(&pCheck->errMsg, zMsg1, -1);
57327 }
57328 sqlite3VXPrintf(&pCheck->errMsg, 1, zFormat, ap);
57329 va_end(ap);
57330 if( pCheck->errMsg.accError==STRACCUM_NOMEM ){
57331 pCheck->mallocFailed = 1;
57332 }
57333 }
57334 #endif /* SQLITE_OMIT_INTEGRITY_CHECK */
57335
@@ -57547,11 +57522,11 @@
57522 */
57523 pBt = pCheck->pBt;
57524 usableSize = pBt->usableSize;
57525 if( iPage==0 ) return 0;
57526 if( checkRef(pCheck, iPage, zParentContext) ) return 0;
57527 if( (rc = btreeGetPage(pBt, (Pgno)iPage, &pPage, 0))!=0 ){
57528 checkAppendMsg(pCheck, zContext,
57529 "unable to get the page. error code=%d", rc);
57530 return 0;
57531 }
57532
@@ -58506,11 +58481,11 @@
58481 for(ii=0; (nPage<0 || ii<nPage) && p->iNext<=(Pgno)nSrcPage && !rc; ii++){
58482 const Pgno iSrcPg = p->iNext; /* Source page number */
58483 if( iSrcPg!=PENDING_BYTE_PAGE(p->pSrc->pBt) ){
58484 DbPage *pSrcPg; /* Source page object */
58485 rc = sqlite3PagerAcquire(pSrcPager, iSrcPg, &pSrcPg,
58486 PAGER_GET_READONLY);
58487 if( rc==SQLITE_OK ){
58488 rc = backupOnePage(p, iSrcPg, sqlite3PagerGetData(pSrcPg), 0);
58489 sqlite3PagerUnref(pSrcPg);
58490 }
58491 }
@@ -59661,38 +59636,33 @@
59636 /* If one value is a number and the other is not, the number is less.
59637 ** If both are numbers, compare as reals if one is a real, or as integers
59638 ** if both values are integers.
59639 */
59640 if( combined_flags&(MEM_Int|MEM_Real) ){
59641 double r1, r2;
59642 if( (f1 & f2 & MEM_Int)!=0 ){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59643 if( pMem1->u.i < pMem2->u.i ) return -1;
59644 if( pMem1->u.i > pMem2->u.i ) return 1;
59645 return 0;
59646 }
59647 if( (f1&MEM_Real)!=0 ){
59648 r1 = pMem1->r;
59649 }else if( (f1&MEM_Int)!=0 ){
59650 r1 = (double)pMem1->u.i;
59651 }else{
59652 return 1;
59653 }
59654 if( (f2&MEM_Real)!=0 ){
59655 r2 = pMem2->r;
59656 }else if( (f2&MEM_Int)!=0 ){
59657 r2 = (double)pMem2->u.i;
59658 }else{
59659 return -1;
59660 }
59661 if( r1<r2 ) return -1;
59662 if( r1>r2 ) return 1;
59663 return 0;
59664 }
59665
59666 /* If one value is a string and the other is a blob, the string is less.
59667 ** If both are strings, compare using the collating functions.
59668 */
@@ -61789,11 +61759,11 @@
61759 ** virtual module tables written in this transaction. This has to
61760 ** be done before determining whether a master journal file is
61761 ** required, as an xSync() callback may add an attached database
61762 ** to the transaction.
61763 */
61764 rc = sqlite3VtabSync(db, p);
61765
61766 /* This loop determines (a) if the commit hook should be invoked and
61767 ** (b) how many database files have open write transactions, not
61768 ** including the temp database. (b) is important because if more than
61769 ** one database file has an open write transaction, a master journal
@@ -63329,10 +63299,25 @@
63299 }else{
63300 v->expmask |= ((u32)1 << (iVar-1));
63301 }
63302 }
63303
63304 #ifndef SQLITE_OMIT_VIRTUALTABLE
63305 /*
63306 ** Transfer error message text from an sqlite3_vtab.zErrMsg (text stored
63307 ** in memory obtained from sqlite3_malloc) into a Vdbe.zErrMsg (text stored
63308 ** in memory obtained from sqlite3DbMalloc).
63309 */
63310 SQLITE_PRIVATE void sqlite3VtabImportErrmsg(Vdbe *p, sqlite3_vtab *pVtab){
63311 sqlite3 *db = p->db;
63312 sqlite3DbFree(db, p->zErrMsg);
63313 p->zErrMsg = sqlite3DbStrDup(db, pVtab->zErrMsg);
63314 sqlite3_free(pVtab->zErrMsg);
63315 pVtab->zErrMsg = 0;
63316 }
63317 #endif /* SQLITE_OMIT_VIRTUALTABLE */
63318
63319 /************** End of vdbeaux.c *********************************************/
63320 /************** Begin file vdbeapi.c *****************************************/
63321 /*
63322 ** 2004 May 26
63323 **
@@ -65518,23 +65503,10 @@
65503 assert( n==(db->nSavepoint + db->isTransactionSavepoint) );
65504 return 1;
65505 }
65506 #endif
65507
 
 
 
 
 
 
 
 
 
 
 
 
 
65508
65509 /*
65510 ** Execute as much of a VDBE program as we can then return.
65511 **
65512 ** sqlite3VdbeMakeReady() must be called before this routine in order to
@@ -69880,11 +69852,11 @@
69852 }else if( u.bn.pC->pVtabCursor ){
69853 u.bn.pVtab = u.bn.pC->pVtabCursor->pVtab;
69854 u.bn.pModule = u.bn.pVtab->pModule;
69855 assert( u.bn.pModule->xRowid );
69856 rc = u.bn.pModule->xRowid(u.bn.pC->pVtabCursor, &u.bn.v);
69857 sqlite3VtabImportErrmsg(p, u.bn.pVtab);
69858 #endif /* SQLITE_OMIT_VIRTUALTABLE */
69859 }else{
69860 assert( u.bn.pC->pCursor!=0 );
69861 rc = sqlite3VdbeCursorMoveto(u.bn.pC);
69862 if( rc ) goto abort_due_to_error;
@@ -71321,11 +71293,11 @@
71293 #if 0 /* local variables moved into u.cl */
71294 VTable *pVTab;
71295 #endif /* local variables moved into u.cl */
71296 u.cl.pVTab = pOp->p4.pVtab;
71297 rc = sqlite3VtabBegin(db, u.cl.pVTab);
71298 if( u.cl.pVTab ) sqlite3VtabImportErrmsg(p, u.cl.pVTab->pVtab);
71299 break;
71300 }
71301 #endif /* SQLITE_OMIT_VIRTUALTABLE */
71302
71303 #ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -71374,11 +71346,11 @@
71346 u.cm.pVtabCursor = 0;
71347 u.cm.pVtab = pOp->p4.pVtab->pVtab;
71348 u.cm.pModule = (sqlite3_module *)u.cm.pVtab->pModule;
71349 assert(u.cm.pVtab && u.cm.pModule);
71350 rc = u.cm.pModule->xOpen(u.cm.pVtab, &u.cm.pVtabCursor);
71351 sqlite3VtabImportErrmsg(p, u.cm.pVtab);
71352 if( SQLITE_OK==rc ){
71353 /* Initialize sqlite3_vtab_cursor base class */
71354 u.cm.pVtabCursor->pVtab = u.cm.pVtab;
71355
71356 /* Initialize vdbe cursor object */
@@ -71454,11 +71426,11 @@
71426 }
71427
71428 p->inVtabMethod = 1;
71429 rc = u.cn.pModule->xFilter(u.cn.pVtabCursor, u.cn.iQuery, pOp->p4.z, u.cn.nArg, u.cn.apArg);
71430 p->inVtabMethod = 0;
71431 sqlite3VtabImportErrmsg(p, u.cn.pVtab);
71432 if( rc==SQLITE_OK ){
71433 u.cn.res = u.cn.pModule->xEof(u.cn.pVtabCursor);
71434 }
71435
71436 if( u.cn.res ){
@@ -71507,11 +71479,11 @@
71479 */
71480 sqlite3VdbeMemMove(&u.co.sContext.s, u.co.pDest);
71481 MemSetTypeFlag(&u.co.sContext.s, MEM_Null);
71482
71483 rc = u.co.pModule->xColumn(pCur->pVtabCursor, &u.co.sContext, pOp->p2);
71484 sqlite3VtabImportErrmsg(p, u.co.pVtab);
71485 if( u.co.sContext.isError ){
71486 rc = u.co.sContext.isError;
71487 }
71488
71489 /* Copy the result of the function to the P3 register. We
@@ -71562,11 +71534,11 @@
71534 ** some other method is next invoked on the save virtual table cursor.
71535 */
71536 p->inVtabMethod = 1;
71537 rc = u.cp.pModule->xNext(u.cp.pCur->pVtabCursor);
71538 p->inVtabMethod = 0;
71539 sqlite3VtabImportErrmsg(p, u.cp.pVtab);
71540 if( rc==SQLITE_OK ){
71541 u.cp.res = u.cp.pModule->xEof(u.cp.pCur->pVtabCursor);
71542 }
71543
71544 if( !u.cp.res ){
@@ -71601,11 +71573,11 @@
71573 testcase( u.cq.pName->enc==SQLITE_UTF16BE );
71574 testcase( u.cq.pName->enc==SQLITE_UTF16LE );
71575 rc = sqlite3VdbeChangeEncoding(u.cq.pName, SQLITE_UTF8);
71576 if( rc==SQLITE_OK ){
71577 rc = u.cq.pVtab->pModule->xRename(u.cq.pVtab, u.cq.pName->z);
71578 sqlite3VtabImportErrmsg(p, u.cq.pVtab);
71579 p->expired = 0;
71580 }
71581 break;
71582 }
71583 #endif
@@ -71665,11 +71637,11 @@
71637 u.cr.pX++;
71638 }
71639 db->vtabOnConflict = pOp->p5;
71640 rc = u.cr.pModule->xUpdate(u.cr.pVtab, u.cr.nArg, u.cr.apArg, &u.cr.rowid);
71641 db->vtabOnConflict = vtabOnConflict;
71642 sqlite3VtabImportErrmsg(p, u.cr.pVtab);
71643 if( rc==SQLITE_OK && pOp->p1 ){
71644 assert( u.cr.nArg>1 && u.cr.apArg[0] && (u.cr.apArg[0]->flags&MEM_Null) );
71645 db->lastRowid = lastRowid = u.cr.rowid;
71646 }
71647 if( (rc&0xff)==SQLITE_CONSTRAINT && pOp->p4.pVtab->bConstraint ){
@@ -75593,12 +75565,11 @@
75565 int op = p->op;
75566 if( op==TK_CAST || op==TK_UPLUS ){
75567 p = p->pLeft;
75568 continue;
75569 }
75570 if( op==TK_COLLATE || (op==TK_REGISTER && p->op2==TK_COLLATE) ){
 
75571 pColl = sqlite3GetCollSeq(pParse, ENC(db), 0, p->u.zToken);
75572 break;
75573 }
75574 if( p->pTab!=0
75575 && (op==TK_AGG_COLUMN || op==TK_COLUMN
@@ -78984,10 +78955,11 @@
78955 compLeft.pRight = pExpr->x.pList->a[0].pExpr;
78956 compRight.op = TK_LE;
78957 compRight.pLeft = &exprX;
78958 compRight.pRight = pExpr->x.pList->a[1].pExpr;
78959 exprX.iTable = sqlite3ExprCodeTemp(pParse, &exprX, &regFree1);
78960 exprX.op2 = exprX.op;
78961 exprX.op = TK_REGISTER;
78962 if( jumpIfTrue ){
78963 sqlite3ExprIfTrue(pParse, &exprAnd, dest, jumpIfNull);
78964 }else{
78965 sqlite3ExprIfFalse(pParse, &exprAnd, dest, jumpIfNull);
@@ -89001,13 +88973,13 @@
88973 }
88974 static void groupConcatFinalize(sqlite3_context *context){
88975 StrAccum *pAccum;
88976 pAccum = sqlite3_aggregate_context(context, 0);
88977 if( pAccum ){
88978 if( pAccum->accError==STRACCUM_TOOBIG ){
88979 sqlite3_result_error_toobig(context);
88980 }else if( pAccum->accError==STRACCUM_NOMEM ){
88981 sqlite3_result_error_nomem(context);
88982 }else{
88983 sqlite3_result_text(context, sqlite3StrAccumFinish(pAccum), -1,
88984 sqlite3_free);
88985 }
@@ -104488,14 +104460,13 @@
104460 /*
104461 ** Invoke the xSync method of all virtual tables in the sqlite3.aVTrans
104462 ** array. Return the error code for the first error that occurs, or
104463 ** SQLITE_OK if all xSync operations are successful.
104464 **
104465 ** If an error message is available, leave it in p->zErrMsg.
 
104466 */
104467 SQLITE_PRIVATE int sqlite3VtabSync(sqlite3 *db, Vdbe *p){
104468 int i;
104469 int rc = SQLITE_OK;
104470 VTable **aVTrans = db->aVTrans;
104471
104472 db->aVTrans = 0;
@@ -104502,13 +104473,11 @@
104473 for(i=0; rc==SQLITE_OK && i<db->nVTrans; i++){
104474 int (*x)(sqlite3_vtab *);
104475 sqlite3_vtab *pVtab = aVTrans[i]->pVtab;
104476 if( pVtab && (x = pVtab->pModule->xSync)!=0 ){
104477 rc = x(pVtab);
104478 sqlite3VtabImportErrmsg(p, pVtab);
 
 
104479 }
104480 }
104481 db->aVTrans = aVTrans;
104482 return rc;
104483 }
@@ -104869,10 +104838,11 @@
104838 int iIdxCur; /* The VDBE cursor used to access pIdx */
104839 int addrBrk; /* Jump here to break out of the loop */
104840 int addrNxt; /* Jump here to start the next IN combination */
104841 int addrCont; /* Jump here to continue with the next loop cycle */
104842 int addrFirst; /* First instruction of interior of the loop */
104843 int addrBody; /* Beginning of the body of this loop */
104844 u8 iFrom; /* Which entry in the FROM clause */
104845 u8 op, p5; /* Opcode and P5 of the opcode that ends the loop */
104846 int p1, p2; /* Operands of the opcode used to ends the loop */
104847 union { /* Information that depends on pWLoop->wsFlags */
104848 struct {
@@ -107808,11 +107778,11 @@
107778 pParse->db->mallocFailed = 1;
107779 }
107780
107781 /* Evaluate the equality constraints
107782 */
107783 assert( zAff==0 || strlen(zAff)>=nEq );
107784 for(j=0; j<nEq; j++){
107785 int r1;
107786 pTerm = pLoop->aLTerm[j];
107787 assert( pTerm!=0 );
107788 /* The following true for indices with redundant columns.
@@ -107900,11 +107870,12 @@
107870 }
107871 sqlite3StrAccumInit(&txt, 0, 0, SQLITE_MAX_LENGTH);
107872 txt.db = db;
107873 sqlite3StrAccumAppend(&txt, " (", 2);
107874 for(i=0; i<nEq; i++){
107875 char *z = (i==pIndex->nColumn ) ? "rowid" : aCol[aiColumn[i]].zName;
107876 explainAppendTerm(&txt, i, z, "=");
107877 }
107878
107879 j = i;
107880 if( pLoop->wsFlags&WHERE_BTM_LIMIT ){
107881 char *z = (j==pIndex->nColumn ) ? "rowid" : aCol[aiColumn[j]].zName;
@@ -109115,17 +109086,15 @@
109086 pNew->rSetup = 0;
109087 rLogSize = estLog(whereCost(pProbe->aiRowEst[0]));
109088 for(; rc==SQLITE_OK && pTerm!=0; pTerm = whereScanNext(&scan)){
109089 int nIn = 0;
109090 if( pTerm->prereqRight & pNew->maskSelf ) continue;
109091 if( (pTerm->eOperator==WO_ISNULL || (pTerm->wtFlags&TERM_VNULL)!=0)
 
109092 && (iCol<0 || pSrc->pTab->aCol[iCol].notNull)
109093 ){
109094 continue; /* ignore IS [NOT] NULL constraints on NOT NULL columns */
109095 }
 
109096 pNew->wsFlags = saved_wsFlags;
109097 pNew->u.btree.nEq = saved_nEq;
109098 pNew->nLTerm = saved_nLTerm;
109099 if( whereLoopResize(db, pNew, pNew->nLTerm+1) ) break; /* OOM */
109100 pNew->aLTerm[pNew->nLTerm++] = pTerm;
@@ -110764,15 +110733,10 @@
110733 assert( n<=pTab->nCol );
110734 }
110735 }else{
110736 sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
110737 }
 
 
 
 
 
110738 if( pLoop->wsFlags & WHERE_INDEXED ){
110739 Index *pIx = pLoop->u.btree.pIndex;
110740 KeyInfo *pKey = sqlite3IndexKeyinfo(pParse, pIx);
110741 /* FIXME: As an optimization use pTabItem->iCursor if WHERE_IDX_ONLY */
110742 int iIndexCur = pLevel->iIdxCur = iIdxCur ? iIdxCur : pParse->nTab++;
@@ -110793,11 +110757,19 @@
110757 ** program.
110758 */
110759 notReady = ~(Bitmask)0;
110760 for(ii=0; ii<nTabList; ii++){
110761 pLevel = &pWInfo->a[ii];
110762 #ifndef SQLITE_OMIT_AUTOMATIC_INDEX
110763 if( (pLevel->pWLoop->wsFlags & WHERE_AUTO_INDEX)!=0 ){
110764 constructAutomaticIndex(pParse, &pWInfo->sWC,
110765 &pTabList->a[pLevel->iFrom], notReady, pLevel);
110766 if( db->mallocFailed ) goto whereBeginError;
110767 }
110768 #endif
110769 explainOneScan(pParse, pTabList, pLevel, ii, pLevel->iFrom, wctrlFlags);
110770 pLevel->addrBody = sqlite3VdbeCurrentAddr(v);
110771 notReady = codeOneLoopStart(pWInfo, ii, notReady);
110772 pWInfo->iContinue = pLevel->addrCont;
110773 }
110774
110775 /* Done. */
@@ -110913,13 +110885,14 @@
110885 }
110886 if( pIdx && !db->mallocFailed ){
110887 int k, j, last;
110888 VdbeOp *pOp;
110889
 
110890 last = sqlite3VdbeCurrentAddr(v);
110891 k = pLevel->addrBody;
110892 pOp = sqlite3VdbeGetOp(v, k);
110893 for(; k<last; k++, pOp++){
110894 if( pOp->p1!=pLevel->iTabCur ) continue;
110895 if( pOp->opcode==OP_Column ){
110896 for(j=0; j<pIdx->nColumn; j++){
110897 if( pOp->p2==pIdx->aiColumn[j] ){
110898 pOp->p2 = j;
@@ -134651,15 +134624,15 @@
134624 }
134625 }
134626 if( pTC ) pModule->xClose(pTC);
134627 if( rc==SQLITE_DONE ) rc = SQLITE_OK;
134628 }
134629 }
134630
134631 for(pDef=pCsr->pDeferred; pDef && rc==SQLITE_OK; pDef=pDef->pNext){
134632 if( pDef->pList ){
134633 rc = fts3PendingListAppendVarint(&pDef->pList, 0);
 
134634 }
134635 }
134636 }
134637
134638 return rc;
134639
+1 -1
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107107
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108108
** [sqlite_version()] and [sqlite_source_id()].
109109
*/
110110
#define SQLITE_VERSION "3.8.0"
111111
#define SQLITE_VERSION_NUMBER 3008000
112
-#define SQLITE_SOURCE_ID "2013-08-20 03:13:51 7f72fc4f47445a2c01910b268335873de9f75059"
112
+#define SQLITE_SOURCE_ID "2013-08-22 02:56:28 0775501acf152dcbf4dd039f4511f3d8c4330d85"
113113
114114
/*
115115
** CAPI3REF: Run-Time Library Version Numbers
116116
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117117
**
118118
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.8.0"
111 #define SQLITE_VERSION_NUMBER 3008000
112 #define SQLITE_SOURCE_ID "2013-08-20 03:13:51 7f72fc4f47445a2c01910b268335873de9f75059"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
118
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.8.0"
111 #define SQLITE_VERSION_NUMBER 3008000
112 #define SQLITE_SOURCE_ID "2013-08-22 02:56:28 0775501acf152dcbf4dd039f4511f3d8c4330d85"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
118

Keyboard Shortcuts

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