| | @@ -656,11 +656,11 @@ |
| 656 | 656 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 657 | 657 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 658 | 658 | */ |
| 659 | 659 | #define SQLITE_VERSION "3.8.0" |
| 660 | 660 | #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" |
| 662 | 662 | |
| 663 | 663 | /* |
| 664 | 664 | ** CAPI3REF: Run-Time Library Version Numbers |
| 665 | 665 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 666 | 666 | ** |
| | @@ -9288,12 +9288,12 @@ |
| 9288 | 9288 | #define PAGER_JOURNALMODE_WAL 5 /* Use write-ahead logging */ |
| 9289 | 9289 | |
| 9290 | 9290 | /* |
| 9291 | 9291 | ** Flags that make up the mask passed to sqlite3PagerAcquire(). |
| 9292 | 9292 | */ |
| 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 */ |
| 9295 | 9295 | |
| 9296 | 9296 | /* |
| 9297 | 9297 | ** Flags for sqlite3PagerSetFlags() |
| 9298 | 9298 | */ |
| 9299 | 9299 | #define PAGER_SYNCHRONOUS_OFF 0x01 /* PRAGMA synchronous=OFF */ |
| | @@ -11645,14 +11645,15 @@ |
| 11645 | 11645 | char *zBase; /* A base allocation. Not from malloc. */ |
| 11646 | 11646 | char *zText; /* The string collected so far */ |
| 11647 | 11647 | int nChar; /* Length of the string so far */ |
| 11648 | 11648 | int nAlloc; /* Amount of space allocated in zText */ |
| 11649 | 11649 | int mxAlloc; /* Maximum allowed string length */ |
| 11650 | | - u8 mallocFailed; /* Becomes true if any memory allocation fails */ |
| 11651 | 11650 | 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 */ |
| 11653 | 11652 | }; |
| 11653 | +#define STRACCUM_NOMEM 1 |
| 11654 | +#define STRACCUM_TOOBIG 2 |
| 11654 | 11655 | |
| 11655 | 11656 | /* |
| 11656 | 11657 | ** A pointer to this structure is used to communicate information |
| 11657 | 11658 | ** from sqlite3Init and OP_ParseSchema into the sqlite3InitCallback. |
| 11658 | 11659 | */ |
| | @@ -12373,17 +12374,18 @@ |
| 12373 | 12374 | # define sqlite3VtabSavepoint(X, Y, Z) SQLITE_OK |
| 12374 | 12375 | # define sqlite3GetVTable(X,Y) ((VTable*)0) |
| 12375 | 12376 | #else |
| 12376 | 12377 | SQLITE_PRIVATE void sqlite3VtabClear(sqlite3 *db, Table*); |
| 12377 | 12378 | SQLITE_PRIVATE void sqlite3VtabDisconnect(sqlite3 *db, Table *p); |
| 12378 | | -SQLITE_PRIVATE int sqlite3VtabSync(sqlite3 *db, char **); |
| 12379 | +SQLITE_PRIVATE int sqlite3VtabSync(sqlite3 *db, Vdbe*); |
| 12379 | 12380 | SQLITE_PRIVATE int sqlite3VtabRollback(sqlite3 *db); |
| 12380 | 12381 | SQLITE_PRIVATE int sqlite3VtabCommit(sqlite3 *db); |
| 12381 | 12382 | SQLITE_PRIVATE void sqlite3VtabLock(VTable *); |
| 12382 | 12383 | SQLITE_PRIVATE void sqlite3VtabUnlock(VTable *); |
| 12383 | 12384 | SQLITE_PRIVATE void sqlite3VtabUnlockList(sqlite3*); |
| 12384 | 12385 | SQLITE_PRIVATE int sqlite3VtabSavepoint(sqlite3 *, int, int); |
| 12386 | +SQLITE_PRIVATE void sqlite3VtabImportErrmsg(Vdbe*, sqlite3_vtab*); |
| 12385 | 12387 | SQLITE_PRIVATE VTable *sqlite3GetVTable(sqlite3*, Table*); |
| 12386 | 12388 | # define sqlite3VtabInSync(db) ((db)->nVTrans>0 && (db)->aVTrans==0) |
| 12387 | 12389 | #endif |
| 12388 | 12390 | SQLITE_PRIVATE void sqlite3VtabMakeWritable(Parse*,Table*); |
| 12389 | 12391 | SQLITE_PRIVATE void sqlite3VtabBeginParse(Parse*, Token*, Token*, Token*, int); |
| | @@ -19899,11 +19901,11 @@ |
| 19899 | 19901 | zOut = buf; |
| 19900 | 19902 | }else{ |
| 19901 | 19903 | nOut = precision + 10; |
| 19902 | 19904 | zOut = zExtra = sqlite3Malloc( nOut ); |
| 19903 | 19905 | if( zOut==0 ){ |
| 19904 | | - pAccum->mallocFailed = 1; |
| 19906 | + pAccum->accError = STRACCUM_NOMEM; |
| 19905 | 19907 | return; |
| 19906 | 19908 | } |
| 19907 | 19909 | } |
| 19908 | 19910 | bufpt = &zOut[nOut-1]; |
| 19909 | 19911 | if( xtype==etORDINAL ){ |
| | @@ -20011,11 +20013,11 @@ |
| 20011 | 20013 | e2 = exp; |
| 20012 | 20014 | } |
| 20013 | 20015 | if( MAX(e2,0)+precision+width > etBUFSIZE - 15 ){ |
| 20014 | 20016 | bufpt = zExtra = sqlite3Malloc( MAX(e2,0)+precision+width+15 ); |
| 20015 | 20017 | if( bufpt==0 ){ |
| 20016 | | - pAccum->mallocFailed = 1; |
| 20018 | + pAccum->accError = STRACCUM_NOMEM; |
| 20017 | 20019 | return; |
| 20018 | 20020 | } |
| 20019 | 20021 | } |
| 20020 | 20022 | zOut = bufpt; |
| 20021 | 20023 | nsd = 16 + flag_altform2*10; |
| | @@ -20146,11 +20148,11 @@ |
| 20146 | 20148 | needQuote = !isnull && xtype==etSQLESCAPE2; |
| 20147 | 20149 | n += i + 1 + needQuote*2; |
| 20148 | 20150 | if( n>etBUFSIZE ){ |
| 20149 | 20151 | bufpt = zExtra = sqlite3Malloc( n ); |
| 20150 | 20152 | if( bufpt==0 ){ |
| 20151 | | - pAccum->mallocFailed = 1; |
| 20153 | + pAccum->accError = STRACCUM_NOMEM; |
| 20152 | 20154 | return; |
| 20153 | 20155 | } |
| 20154 | 20156 | }else{ |
| 20155 | 20157 | bufpt = buf; |
| 20156 | 20158 | } |
| | @@ -20224,26 +20226,24 @@ |
| 20224 | 20226 | /* |
| 20225 | 20227 | ** Append N bytes of text from z to the StrAccum object. |
| 20226 | 20228 | */ |
| 20227 | 20229 | SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum *p, const char *z, int N){ |
| 20228 | 20230 | 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); |
| 20232 | 20234 | return; |
| 20233 | 20235 | } |
| 20234 | 20236 | assert( p->zText!=0 || p->nChar==0 ); |
| 20235 | | - if( N<0 ){ |
| 20237 | + if( N<=0 ){ |
| 20238 | + if( N==0 || z[0]==0 ) return; |
| 20236 | 20239 | N = sqlite3Strlen30(z); |
| 20237 | 20240 | } |
| 20238 | | - if( N==0 || NEVER(z==0) ){ |
| 20239 | | - return; |
| 20240 | | - } |
| 20241 | 20241 | if( p->nChar+N >= p->nAlloc ){ |
| 20242 | 20242 | char *zNew; |
| 20243 | 20243 | if( !p->useMalloc ){ |
| 20244 | | - p->tooBig = 1; |
| 20244 | + p->accError = STRACCUM_TOOBIG; |
| 20245 | 20245 | N = p->nAlloc - p->nChar - 1; |
| 20246 | 20246 | if( N<=0 ){ |
| 20247 | 20247 | return; |
| 20248 | 20248 | } |
| 20249 | 20249 | }else{ |
| | @@ -20250,11 +20250,11 @@ |
| 20250 | 20250 | char *zOld = (p->zText==p->zBase ? 0 : p->zText); |
| 20251 | 20251 | i64 szNew = p->nChar; |
| 20252 | 20252 | szNew += N + 1; |
| 20253 | 20253 | if( szNew > p->mxAlloc ){ |
| 20254 | 20254 | sqlite3StrAccumReset(p); |
| 20255 | | - p->tooBig = 1; |
| 20255 | + p->accError = STRACCUM_TOOBIG; |
| 20256 | 20256 | return; |
| 20257 | 20257 | }else{ |
| 20258 | 20258 | p->nAlloc = (int)szNew; |
| 20259 | 20259 | } |
| 20260 | 20260 | if( p->useMalloc==1 ){ |
| | @@ -20264,11 +20264,11 @@ |
| 20264 | 20264 | } |
| 20265 | 20265 | if( zNew ){ |
| 20266 | 20266 | if( zOld==0 && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar); |
| 20267 | 20267 | p->zText = zNew; |
| 20268 | 20268 | }else{ |
| 20269 | | - p->mallocFailed = 1; |
| 20269 | + p->accError = STRACCUM_NOMEM; |
| 20270 | 20270 | sqlite3StrAccumReset(p); |
| 20271 | 20271 | return; |
| 20272 | 20272 | } |
| 20273 | 20273 | } |
| 20274 | 20274 | } |
| | @@ -20292,11 +20292,11 @@ |
| 20292 | 20292 | p->zText = sqlite3_malloc(p->nChar+1); |
| 20293 | 20293 | } |
| 20294 | 20294 | if( p->zText ){ |
| 20295 | 20295 | memcpy(p->zText, p->zBase, p->nChar+1); |
| 20296 | 20296 | }else{ |
| 20297 | | - p->mallocFailed = 1; |
| 20297 | + p->accError = STRACCUM_NOMEM; |
| 20298 | 20298 | } |
| 20299 | 20299 | } |
| 20300 | 20300 | } |
| 20301 | 20301 | return p->zText; |
| 20302 | 20302 | } |
| | @@ -20323,12 +20323,11 @@ |
| 20323 | 20323 | p->db = 0; |
| 20324 | 20324 | p->nChar = 0; |
| 20325 | 20325 | p->nAlloc = n; |
| 20326 | 20326 | p->mxAlloc = mx; |
| 20327 | 20327 | p->useMalloc = 1; |
| 20328 | | - p->tooBig = 0; |
| 20329 | | - p->mallocFailed = 0; |
| 20328 | + p->accError = 0; |
| 20330 | 20329 | } |
| 20331 | 20330 | |
| 20332 | 20331 | /* |
| 20333 | 20332 | ** Print into memory obtained from sqliteMalloc(). Use the internal |
| 20334 | 20333 | ** %-conversion extensions. |
| | @@ -20341,11 +20340,11 @@ |
| 20341 | 20340 | sqlite3StrAccumInit(&acc, zBase, sizeof(zBase), |
| 20342 | 20341 | db->aLimit[SQLITE_LIMIT_LENGTH]); |
| 20343 | 20342 | acc.db = db; |
| 20344 | 20343 | sqlite3VXPrintf(&acc, 1, zFormat, ap); |
| 20345 | 20344 | z = sqlite3StrAccumFinish(&acc); |
| 20346 | | - if( acc.mallocFailed ){ |
| 20345 | + if( acc.accError==STRACCUM_NOMEM ){ |
| 20347 | 20346 | db->mallocFailed = 1; |
| 20348 | 20347 | } |
| 20349 | 20348 | return z; |
| 20350 | 20349 | } |
| 20351 | 20350 | |
| | @@ -20538,28 +20537,15 @@ |
| 20538 | 20537 | unsigned char i, j; /* State variables */ |
| 20539 | 20538 | unsigned char s[256]; /* State variables */ |
| 20540 | 20539 | } sqlite3Prng; |
| 20541 | 20540 | |
| 20542 | 20541 | /* |
| 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. |
| 20557 | 20543 | */ |
| 20558 | | -static u8 randomByte(void){ |
| 20544 | +SQLITE_API void sqlite3_randomness(int N, void *pBuf){ |
| 20559 | 20545 | unsigned char t; |
| 20560 | | - |
| 20546 | + unsigned char *zBuf = pBuf; |
| 20561 | 20547 | |
| 20562 | 20548 | /* The "wsdPrng" macro will resolve to the pseudo-random number generator |
| 20563 | 20549 | ** state vector. If writable static data is unsupported on the target, |
| 20564 | 20550 | ** we have to locate the state vector at run-time. In the more common |
| 20565 | 20551 | ** case where writable static data is supported, wsdPrng can refer directly |
| | @@ -20570,10 +20556,14 @@ |
| 20570 | 20556 | # define wsdPrng p[0] |
| 20571 | 20557 | #else |
| 20572 | 20558 | # define wsdPrng sqlite3Prng |
| 20573 | 20559 | #endif |
| 20574 | 20560 | |
| 20561 | +#if SQLITE_THREADSAFE |
| 20562 | + sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_PRNG); |
| 20563 | + sqlite3_mutex_enter(mutex); |
| 20564 | +#endif |
| 20575 | 20565 | |
| 20576 | 20566 | /* Initialize the state of the random number generator once, |
| 20577 | 20567 | ** the first time this routine is called. The seed value does |
| 20578 | 20568 | ** not need to contain a lot of randomness since we are not |
| 20579 | 20569 | ** trying to do secure encryption or anything like that... |
| | @@ -20598,32 +20588,18 @@ |
| 20598 | 20588 | wsdPrng.s[i] = t; |
| 20599 | 20589 | } |
| 20600 | 20590 | wsdPrng.isInit = 1; |
| 20601 | 20591 | } |
| 20602 | 20592 | |
| 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 | 20593 | 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]; |
| 20625 | 20601 | } |
| 20626 | 20602 | sqlite3_mutex_leave(mutex); |
| 20627 | 20603 | } |
| 20628 | 20604 | |
| 20629 | 20605 | #ifndef SQLITE_OMIT_BUILTIN_TEST |
| | @@ -39378,17 +39354,21 @@ |
| 39378 | 39354 | ** * The page-number is less than or equal to PagerSavepoint.nOrig, and |
| 39379 | 39355 | ** * The bit corresponding to the page-number is not set in |
| 39380 | 39356 | ** PagerSavepoint.pInSavepoint. |
| 39381 | 39357 | */ |
| 39382 | 39358 | static int subjRequiresPage(PgHdr *pPg){ |
| 39383 | | - Pgno pgno = pPg->pgno; |
| 39384 | 39359 | Pager *pPager = pPg->pPager; |
| 39360 | + PagerSavepoint *p; |
| 39361 | + Pgno pgno; |
| 39385 | 39362 | 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 | + } |
| 39390 | 39370 | } |
| 39391 | 39371 | } |
| 39392 | 39372 | return 0; |
| 39393 | 39373 | } |
| 39394 | 39374 | |
| | @@ -41230,16 +41210,10 @@ |
| 41230 | 41210 | int pgsz = pPager->pageSize; /* Number of bytes to read */ |
| 41231 | 41211 | |
| 41232 | 41212 | assert( pPager->eState>=PAGER_READER && !MEMDB ); |
| 41233 | 41213 | assert( isOpen(pPager->fd) ); |
| 41234 | 41214 | |
| 41235 | | - if( NEVER(!isOpen(pPager->fd)) ){ |
| 41236 | | - assert( pPager->tempFile ); |
| 41237 | | - memset(pPg->pData, 0, pPager->pageSize); |
| 41238 | | - return SQLITE_OK; |
| 41239 | | - } |
| 41240 | | - |
| 41241 | 41215 | #ifndef SQLITE_OMIT_WAL |
| 41242 | 41216 | if( iFrame ){ |
| 41243 | 41217 | /* Try to pull the page from the write-ahead log. */ |
| 41244 | 41218 | rc = sqlite3WalReadFrame(pPager->pWal, iFrame, pgsz, pPg->pData); |
| 41245 | 41219 | }else |
| | @@ -43589,23 +43563,23 @@ |
| 43589 | 43563 | */ |
| 43590 | 43564 | SQLITE_PRIVATE int sqlite3PagerAcquire( |
| 43591 | 43565 | Pager *pPager, /* The pager open on the database file */ |
| 43592 | 43566 | Pgno pgno, /* Page number to fetch */ |
| 43593 | 43567 | DbPage **ppPage, /* Write a pointer to the page here */ |
| 43594 | | - int flags /* PAGER_ACQUIRE_XXX flags */ |
| 43568 | + int flags /* PAGER_GET_XXX flags */ |
| 43595 | 43569 | ){ |
| 43596 | 43570 | int rc = SQLITE_OK; |
| 43597 | 43571 | PgHdr *pPg = 0; |
| 43598 | 43572 | 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); |
| 43600 | 43574 | |
| 43601 | 43575 | /* It is acceptable to use a read-only (mmap) page for any page except |
| 43602 | 43576 | ** page 1 if there is no write-transaction open or the ACQUIRE_READONLY |
| 43603 | 43577 | ** flag was specified by the caller. And so long as the db is not a |
| 43604 | 43578 | ** temporary or in-memory database. */ |
| 43605 | 43579 | 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)) |
| 43607 | 43581 | #ifdef SQLITE_HAS_CODEC |
| 43608 | 43582 | && pPager->xCodec==0 |
| 43609 | 43583 | #endif |
| 43610 | 43584 | ); |
| 43611 | 43585 | |
| | @@ -50544,11 +50518,12 @@ |
| 50544 | 50518 | assert( pPage->leaf==0 || pPage->leaf==1 ); |
| 50545 | 50519 | n = pPage->childPtrSize; |
| 50546 | 50520 | assert( n==4-4*pPage->leaf ); |
| 50547 | 50521 | if( pPage->intKey ){ |
| 50548 | 50522 | if( pPage->hasData ){ |
| 50549 | | - n += getVarint32(&pCell[n], nPayload); |
| 50523 | + assert( n==0 ); |
| 50524 | + n = getVarint32(pCell, nPayload); |
| 50550 | 50525 | }else{ |
| 50551 | 50526 | nPayload = 0; |
| 50552 | 50527 | } |
| 50553 | 50528 | n += getVarint(&pCell[n], (u64*)&pInfo->nKey); |
| 50554 | 50529 | pInfo->nData = nPayload; |
| | @@ -51188,19 +51163,16 @@ |
| 51188 | 51163 | */ |
| 51189 | 51164 | static int btreeGetPage( |
| 51190 | 51165 | BtShared *pBt, /* The btree */ |
| 51191 | 51166 | Pgno pgno, /* Number of the page to fetch */ |
| 51192 | 51167 | 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 */ |
| 51195 | 51169 | ){ |
| 51196 | 51170 | int rc; |
| 51197 | 51171 | DbPage *pDbPage; |
| 51198 | | - int flags = (noContent ? PAGER_ACQUIRE_NOCONTENT : 0) |
| 51199 | | - | (bReadonly ? PAGER_ACQUIRE_READONLY : 0); |
| 51200 | 51172 | |
| 51201 | | - assert( noContent==0 || bReadonly==0 ); |
| 51173 | + assert( flags==0 || flags==PAGER_GET_NOCONTENT || flags==PAGER_GET_READONLY ); |
| 51202 | 51174 | assert( sqlite3_mutex_held(pBt->mutex) ); |
| 51203 | 51175 | rc = sqlite3PagerAcquire(pBt->pPager, pgno, (DbPage**)&pDbPage, flags); |
| 51204 | 51176 | if( rc ) return rc; |
| 51205 | 51177 | *ppPage = btreePageFromDbPage(pDbPage, pgno, pBt); |
| 51206 | 51178 | return SQLITE_OK; |
| | @@ -51244,19 +51216,20 @@ |
| 51244 | 51216 | */ |
| 51245 | 51217 | static int getAndInitPage( |
| 51246 | 51218 | BtShared *pBt, /* The database file */ |
| 51247 | 51219 | Pgno pgno, /* Number of the page to get */ |
| 51248 | 51220 | 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 */ |
| 51250 | 51222 | ){ |
| 51251 | 51223 | int rc; |
| 51252 | 51224 | assert( sqlite3_mutex_held(pBt->mutex) ); |
| 51225 | + assert( bReadonly==PAGER_GET_READONLY || bReadonly==0 ); |
| 51253 | 51226 | |
| 51254 | 51227 | if( pgno>btreePagecount(pBt) ){ |
| 51255 | 51228 | rc = SQLITE_CORRUPT_BKPT; |
| 51256 | 51229 | }else{ |
| 51257 | | - rc = btreeGetPage(pBt, pgno, ppPage, 0, bReadonly); |
| 51230 | + rc = btreeGetPage(pBt, pgno, ppPage, bReadonly); |
| 51258 | 51231 | if( rc==SQLITE_OK ){ |
| 51259 | 51232 | rc = btreeInitPage(*ppPage); |
| 51260 | 51233 | if( rc!=SQLITE_OK ){ |
| 51261 | 51234 | releasePage(*ppPage); |
| 51262 | 51235 | } |
| | @@ -51985,11 +51958,11 @@ |
| 51985 | 51958 | |
| 51986 | 51959 | assert( sqlite3_mutex_held(pBt->mutex) ); |
| 51987 | 51960 | assert( pBt->pPage1==0 ); |
| 51988 | 51961 | rc = sqlite3PagerSharedLock(pBt->pPager); |
| 51989 | 51962 | if( rc!=SQLITE_OK ) return rc; |
| 51990 | | - rc = btreeGetPage(pBt, 1, &pPage1, 0, 0); |
| 51963 | + rc = btreeGetPage(pBt, 1, &pPage1, 0); |
| 51991 | 51964 | if( rc!=SQLITE_OK ) return rc; |
| 51992 | 51965 | |
| 51993 | 51966 | /* Do some checking to help insure the file we opened really is |
| 51994 | 51967 | ** a valid database file. |
| 51995 | 51968 | */ |
| | @@ -52567,11 +52540,11 @@ |
| 52567 | 52540 | /* Fix the database pointer on page iPtrPage that pointed at iDbPage so |
| 52568 | 52541 | ** that it points at iFreePage. Also fix the pointer map entry for |
| 52569 | 52542 | ** iPtrPage. |
| 52570 | 52543 | */ |
| 52571 | 52544 | if( eType!=PTRMAP_ROOTPAGE ){ |
| 52572 | | - rc = btreeGetPage(pBt, iPtrPage, &pPtrPage, 0, 0); |
| 52545 | + rc = btreeGetPage(pBt, iPtrPage, &pPtrPage, 0); |
| 52573 | 52546 | if( rc!=SQLITE_OK ){ |
| 52574 | 52547 | return rc; |
| 52575 | 52548 | } |
| 52576 | 52549 | rc = sqlite3PagerWrite(pPtrPage->pDbPage); |
| 52577 | 52550 | if( rc!=SQLITE_OK ){ |
| | @@ -52651,11 +52624,11 @@ |
| 52651 | 52624 | Pgno iFreePg; /* Index of free page to move pLastPg to */ |
| 52652 | 52625 | MemPage *pLastPg; |
| 52653 | 52626 | u8 eMode = BTALLOC_ANY; /* Mode parameter for allocateBtreePage() */ |
| 52654 | 52627 | Pgno iNear = 0; /* nearby parameter for allocateBtreePage() */ |
| 52655 | 52628 | |
| 52656 | | - rc = btreeGetPage(pBt, iLastPg, &pLastPg, 0, 0); |
| 52629 | + rc = btreeGetPage(pBt, iLastPg, &pLastPg, 0); |
| 52657 | 52630 | if( rc!=SQLITE_OK ){ |
| 52658 | 52631 | return rc; |
| 52659 | 52632 | } |
| 52660 | 52633 | |
| 52661 | 52634 | /* If bCommit is zero, this loop runs exactly once and page pLastPg |
| | @@ -53050,11 +53023,11 @@ |
| 53050 | 53023 | } |
| 53051 | 53024 | |
| 53052 | 53025 | /* The rollback may have destroyed the pPage1->aData value. So |
| 53053 | 53026 | ** call btreeGetPage() on page 1 again to make |
| 53054 | 53027 | ** 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 ){ |
| 53056 | 53029 | int nPage = get4byte(28+(u8*)pPage1->aData); |
| 53057 | 53030 | testcase( nPage==0 ); |
| 53058 | 53031 | if( nPage==0 ) sqlite3PagerPagecount(pBt->pPager, &nPage); |
| 53059 | 53032 | testcase( pBt->nPage!=nPage ); |
| 53060 | 53033 | pBt->nPage = nPage; |
| | @@ -53485,11 +53458,11 @@ |
| 53485 | 53458 | } |
| 53486 | 53459 | #endif |
| 53487 | 53460 | |
| 53488 | 53461 | assert( next==0 || rc==SQLITE_DONE ); |
| 53489 | 53462 | 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); |
| 53491 | 53464 | assert( rc==SQLITE_OK || pPage==0 ); |
| 53492 | 53465 | if( rc==SQLITE_OK ){ |
| 53493 | 53466 | next = get4byte(pPage->aData); |
| 53494 | 53467 | } |
| 53495 | 53468 | } |
| | @@ -53707,11 +53680,11 @@ |
| 53707 | 53680 | #endif |
| 53708 | 53681 | |
| 53709 | 53682 | { |
| 53710 | 53683 | DbPage *pDbPage; |
| 53711 | 53684 | rc = sqlite3PagerAcquire(pBt->pPager, nextPage, &pDbPage, |
| 53712 | | - (eOp==0 ? PAGER_ACQUIRE_READONLY : 0) |
| 53685 | + (eOp==0 ? PAGER_GET_READONLY : 0) |
| 53713 | 53686 | ); |
| 53714 | 53687 | if( rc==SQLITE_OK ){ |
| 53715 | 53688 | aPayload = sqlite3PagerGetData(pDbPage); |
| 53716 | 53689 | nextPage = get4byte(aPayload); |
| 53717 | 53690 | rc = copyPayload(&aPayload[offset+4], pBuf, a, eOp, pDbPage); |
| | @@ -53891,11 +53864,12 @@ |
| 53891 | 53864 | assert( pCur->iPage<BTCURSOR_MAX_DEPTH ); |
| 53892 | 53865 | assert( pCur->iPage>=0 ); |
| 53893 | 53866 | if( pCur->iPage>=(BTCURSOR_MAX_DEPTH-1) ){ |
| 53894 | 53867 | return SQLITE_CORRUPT_BKPT; |
| 53895 | 53868 | } |
| 53896 | | - rc = getAndInitPage(pBt, newPgno, &pNewPage, (pCur->wrFlag==0)); |
| 53869 | + rc = getAndInitPage(pBt, newPgno, &pNewPage, |
| 53870 | + pCur->wrFlag==0 ? PAGER_GET_READONLY : 0); |
| 53897 | 53871 | if( rc ) return rc; |
| 53898 | 53872 | pCur->apPage[i+1] = pNewPage; |
| 53899 | 53873 | pCur->aiIdx[i+1] = 0; |
| 53900 | 53874 | pCur->iPage++; |
| 53901 | 53875 | |
| | @@ -54008,11 +53982,12 @@ |
| 54008 | 53982 | pCur->iPage = 0; |
| 54009 | 53983 | }else if( pCur->pgnoRoot==0 ){ |
| 54010 | 53984 | pCur->eState = CURSOR_INVALID; |
| 54011 | 53985 | return SQLITE_OK; |
| 54012 | 53986 | }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); |
| 54014 | 53989 | if( rc!=SQLITE_OK ){ |
| 54015 | 53990 | pCur->eState = CURSOR_INVALID; |
| 54016 | 53991 | return rc; |
| 54017 | 53992 | } |
| 54018 | 53993 | pCur->iPage = 0; |
| | @@ -54645,11 +54620,11 @@ |
| 54645 | 54620 | } |
| 54646 | 54621 | testcase( iTrunk==mxPage ); |
| 54647 | 54622 | if( iTrunk>mxPage ){ |
| 54648 | 54623 | rc = SQLITE_CORRUPT_BKPT; |
| 54649 | 54624 | }else{ |
| 54650 | | - rc = btreeGetPage(pBt, iTrunk, &pTrunk, 0, 0); |
| 54625 | + rc = btreeGetPage(pBt, iTrunk, &pTrunk, 0); |
| 54651 | 54626 | } |
| 54652 | 54627 | if( rc ){ |
| 54653 | 54628 | pTrunk = 0; |
| 54654 | 54629 | goto end_allocate_page; |
| 54655 | 54630 | } |
| | @@ -54709,11 +54684,11 @@ |
| 54709 | 54684 | if( iNewTrunk>mxPage ){ |
| 54710 | 54685 | rc = SQLITE_CORRUPT_BKPT; |
| 54711 | 54686 | goto end_allocate_page; |
| 54712 | 54687 | } |
| 54713 | 54688 | testcase( iNewTrunk==mxPage ); |
| 54714 | | - rc = btreeGetPage(pBt, iNewTrunk, &pNewTrunk, 0, 0); |
| 54689 | + rc = btreeGetPage(pBt, iNewTrunk, &pNewTrunk, 0); |
| 54715 | 54690 | if( rc!=SQLITE_OK ){ |
| 54716 | 54691 | goto end_allocate_page; |
| 54717 | 54692 | } |
| 54718 | 54693 | rc = sqlite3PagerWrite(pNewTrunk->pDbPage); |
| 54719 | 54694 | if( rc!=SQLITE_OK ){ |
| | @@ -54788,12 +54763,12 @@ |
| 54788 | 54763 | if( rc ) goto end_allocate_page; |
| 54789 | 54764 | if( closest<k-1 ){ |
| 54790 | 54765 | memcpy(&aData[8+closest*4], &aData[4+k*4], 4); |
| 54791 | 54766 | } |
| 54792 | 54767 | 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); |
| 54795 | 54770 | if( rc==SQLITE_OK ){ |
| 54796 | 54771 | rc = sqlite3PagerWrite((*ppPage)->pDbPage); |
| 54797 | 54772 | if( rc!=SQLITE_OK ){ |
| 54798 | 54773 | releasePage(*ppPage); |
| 54799 | 54774 | } |
| | @@ -54821,11 +54796,11 @@ |
| 54821 | 54796 | ** content for any page that really does lie past the end of the database |
| 54822 | 54797 | ** file on disk. So the effects of disabling the no-content optimization |
| 54823 | 54798 | ** here are confined to those pages that lie between the end of the |
| 54824 | 54799 | ** database image and the end of the database file. |
| 54825 | 54800 | */ |
| 54826 | | - int bNoContent = (0==IfNotOmitAV(pBt->bDoTruncate)); |
| 54801 | + int bNoContent = (0==IfNotOmitAV(pBt->bDoTruncate)) ? PAGER_GET_NOCONTENT : 0; |
| 54827 | 54802 | |
| 54828 | 54803 | rc = sqlite3PagerWrite(pBt->pPage1->pDbPage); |
| 54829 | 54804 | if( rc ) return rc; |
| 54830 | 54805 | pBt->nPage++; |
| 54831 | 54806 | if( pBt->nPage==PENDING_BYTE_PAGE(pBt) ) pBt->nPage++; |
| | @@ -54837,11 +54812,11 @@ |
| 54837 | 54812 | ** becomes a new pointer-map page, the second is used by the caller. |
| 54838 | 54813 | */ |
| 54839 | 54814 | MemPage *pPg = 0; |
| 54840 | 54815 | TRACE(("ALLOCATE: %d from end of file (pointer-map page)\n", pBt->nPage)); |
| 54841 | 54816 | assert( pBt->nPage!=PENDING_BYTE_PAGE(pBt) ); |
| 54842 | | - rc = btreeGetPage(pBt, pBt->nPage, &pPg, bNoContent, 0); |
| 54817 | + rc = btreeGetPage(pBt, pBt->nPage, &pPg, bNoContent); |
| 54843 | 54818 | if( rc==SQLITE_OK ){ |
| 54844 | 54819 | rc = sqlite3PagerWrite(pPg->pDbPage); |
| 54845 | 54820 | releasePage(pPg); |
| 54846 | 54821 | } |
| 54847 | 54822 | if( rc ) return rc; |
| | @@ -54851,11 +54826,11 @@ |
| 54851 | 54826 | #endif |
| 54852 | 54827 | put4byte(28 + (u8*)pBt->pPage1->aData, pBt->nPage); |
| 54853 | 54828 | *pPgno = pBt->nPage; |
| 54854 | 54829 | |
| 54855 | 54830 | assert( *pPgno!=PENDING_BYTE_PAGE(pBt) ); |
| 54856 | | - rc = btreeGetPage(pBt, *pPgno, ppPage, bNoContent, 0); |
| 54831 | + rc = btreeGetPage(pBt, *pPgno, ppPage, bNoContent); |
| 54857 | 54832 | if( rc ) return rc; |
| 54858 | 54833 | rc = sqlite3PagerWrite((*ppPage)->pDbPage); |
| 54859 | 54834 | if( rc!=SQLITE_OK ){ |
| 54860 | 54835 | releasePage(*ppPage); |
| 54861 | 54836 | } |
| | @@ -54919,11 +54894,11 @@ |
| 54919 | 54894 | |
| 54920 | 54895 | if( pBt->btsFlags & BTS_SECURE_DELETE ){ |
| 54921 | 54896 | /* If the secure_delete option is enabled, then |
| 54922 | 54897 | ** always fully overwrite deleted information with zeros. |
| 54923 | 54898 | */ |
| 54924 | | - if( (!pPage && ((rc = btreeGetPage(pBt, iPage, &pPage, 0, 0))!=0) ) |
| 54899 | + if( (!pPage && ((rc = btreeGetPage(pBt, iPage, &pPage, 0))!=0) ) |
| 54925 | 54900 | || ((rc = sqlite3PagerWrite(pPage->pDbPage))!=0) |
| 54926 | 54901 | ){ |
| 54927 | 54902 | goto freepage_out; |
| 54928 | 54903 | } |
| 54929 | 54904 | memset(pPage->aData, 0, pPage->pBt->pageSize); |
| | @@ -54946,11 +54921,11 @@ |
| 54946 | 54921 | */ |
| 54947 | 54922 | if( nFree!=0 ){ |
| 54948 | 54923 | u32 nLeaf; /* Initial number of leaf cells on trunk page */ |
| 54949 | 54924 | |
| 54950 | 54925 | iTrunk = get4byte(&pPage1->aData[32]); |
| 54951 | | - rc = btreeGetPage(pBt, iTrunk, &pTrunk, 0, 0); |
| 54926 | + rc = btreeGetPage(pBt, iTrunk, &pTrunk, 0); |
| 54952 | 54927 | if( rc!=SQLITE_OK ){ |
| 54953 | 54928 | goto freepage_out; |
| 54954 | 54929 | } |
| 54955 | 54930 | |
| 54956 | 54931 | nLeaf = get4byte(&pTrunk->aData[4]); |
| | @@ -54992,11 +54967,11 @@ |
| 54992 | 54967 | ** the page being freed as a leaf page of the first trunk in the free-list. |
| 54993 | 54968 | ** Possibly because the free-list is empty, or possibly because the |
| 54994 | 54969 | ** first trunk in the free-list is full. Either way, the page being freed |
| 54995 | 54970 | ** will become the new first trunk page in the free-list. |
| 54996 | 54971 | */ |
| 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)) ){ |
| 54998 | 54973 | goto freepage_out; |
| 54999 | 54974 | } |
| 55000 | 54975 | rc = sqlite3PagerWrite(pPage->pDbPage); |
| 55001 | 54976 | if( rc!=SQLITE_OK ){ |
| 55002 | 54977 | goto freepage_out; |
| | @@ -56891,11 +56866,11 @@ |
| 56891 | 56866 | if( rc!=SQLITE_OK ){ |
| 56892 | 56867 | return rc; |
| 56893 | 56868 | } |
| 56894 | 56869 | |
| 56895 | 56870 | /* Move the page currently at pgnoRoot to pgnoMove. */ |
| 56896 | | - rc = btreeGetPage(pBt, pgnoRoot, &pRoot, 0, 0); |
| 56871 | + rc = btreeGetPage(pBt, pgnoRoot, &pRoot, 0); |
| 56897 | 56872 | if( rc!=SQLITE_OK ){ |
| 56898 | 56873 | return rc; |
| 56899 | 56874 | } |
| 56900 | 56875 | rc = ptrmapGet(pBt, pgnoRoot, &eType, &iPtrPage); |
| 56901 | 56876 | if( eType==PTRMAP_ROOTPAGE || eType==PTRMAP_FREEPAGE ){ |
| | @@ -56912,11 +56887,11 @@ |
| 56912 | 56887 | |
| 56913 | 56888 | /* Obtain the page at pgnoRoot */ |
| 56914 | 56889 | if( rc!=SQLITE_OK ){ |
| 56915 | 56890 | return rc; |
| 56916 | 56891 | } |
| 56917 | | - rc = btreeGetPage(pBt, pgnoRoot, &pRoot, 0, 0); |
| 56892 | + rc = btreeGetPage(pBt, pgnoRoot, &pRoot, 0); |
| 56918 | 56893 | if( rc!=SQLITE_OK ){ |
| 56919 | 56894 | return rc; |
| 56920 | 56895 | } |
| 56921 | 56896 | rc = sqlite3PagerWrite(pRoot->pDbPage); |
| 56922 | 56897 | if( rc!=SQLITE_OK ){ |
| | @@ -57090,11 +57065,11 @@ |
| 57090 | 57065 | if( NEVER(pBt->pCursor) ){ |
| 57091 | 57066 | sqlite3ConnectionBlocked(p->db, pBt->pCursor->pBtree->db); |
| 57092 | 57067 | return SQLITE_LOCKED_SHAREDCACHE; |
| 57093 | 57068 | } |
| 57094 | 57069 | |
| 57095 | | - rc = btreeGetPage(pBt, (Pgno)iTable, &pPage, 0, 0); |
| 57070 | + rc = btreeGetPage(pBt, (Pgno)iTable, &pPage, 0); |
| 57096 | 57071 | if( rc ) return rc; |
| 57097 | 57072 | rc = sqlite3BtreeClearTable(p, iTable, 0); |
| 57098 | 57073 | if( rc ){ |
| 57099 | 57074 | releasePage(pPage); |
| 57100 | 57075 | return rc; |
| | @@ -57125,21 +57100,21 @@ |
| 57125 | 57100 | ** number in the database. So move the page that does into the |
| 57126 | 57101 | ** gap left by the deleted root-page. |
| 57127 | 57102 | */ |
| 57128 | 57103 | MemPage *pMove; |
| 57129 | 57104 | releasePage(pPage); |
| 57130 | | - rc = btreeGetPage(pBt, maxRootPgno, &pMove, 0, 0); |
| 57105 | + rc = btreeGetPage(pBt, maxRootPgno, &pMove, 0); |
| 57131 | 57106 | if( rc!=SQLITE_OK ){ |
| 57132 | 57107 | return rc; |
| 57133 | 57108 | } |
| 57134 | 57109 | rc = relocatePage(pBt, pMove, PTRMAP_ROOTPAGE, 0, iTable, 0); |
| 57135 | 57110 | releasePage(pMove); |
| 57136 | 57111 | if( rc!=SQLITE_OK ){ |
| 57137 | 57112 | return rc; |
| 57138 | 57113 | } |
| 57139 | 57114 | pMove = 0; |
| 57140 | | - rc = btreeGetPage(pBt, maxRootPgno, &pMove, 0, 0); |
| 57115 | + rc = btreeGetPage(pBt, maxRootPgno, &pMove, 0); |
| 57141 | 57116 | freePage(pMove, &rc); |
| 57142 | 57117 | releasePage(pMove); |
| 57143 | 57118 | if( rc!=SQLITE_OK ){ |
| 57144 | 57119 | return rc; |
| 57145 | 57120 | } |
| | @@ -57350,11 +57325,11 @@ |
| 57350 | 57325 | if( zMsg1 ){ |
| 57351 | 57326 | sqlite3StrAccumAppend(&pCheck->errMsg, zMsg1, -1); |
| 57352 | 57327 | } |
| 57353 | 57328 | sqlite3VXPrintf(&pCheck->errMsg, 1, zFormat, ap); |
| 57354 | 57329 | va_end(ap); |
| 57355 | | - if( pCheck->errMsg.mallocFailed ){ |
| 57330 | + if( pCheck->errMsg.accError==STRACCUM_NOMEM ){ |
| 57356 | 57331 | pCheck->mallocFailed = 1; |
| 57357 | 57332 | } |
| 57358 | 57333 | } |
| 57359 | 57334 | #endif /* SQLITE_OMIT_INTEGRITY_CHECK */ |
| 57360 | 57335 | |
| | @@ -57547,11 +57522,11 @@ |
| 57547 | 57522 | */ |
| 57548 | 57523 | pBt = pCheck->pBt; |
| 57549 | 57524 | usableSize = pBt->usableSize; |
| 57550 | 57525 | if( iPage==0 ) return 0; |
| 57551 | 57526 | 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 ){ |
| 57553 | 57528 | checkAppendMsg(pCheck, zContext, |
| 57554 | 57529 | "unable to get the page. error code=%d", rc); |
| 57555 | 57530 | return 0; |
| 57556 | 57531 | } |
| 57557 | 57532 | |
| | @@ -58506,11 +58481,11 @@ |
| 58506 | 58481 | for(ii=0; (nPage<0 || ii<nPage) && p->iNext<=(Pgno)nSrcPage && !rc; ii++){ |
| 58507 | 58482 | const Pgno iSrcPg = p->iNext; /* Source page number */ |
| 58508 | 58483 | if( iSrcPg!=PENDING_BYTE_PAGE(p->pSrc->pBt) ){ |
| 58509 | 58484 | DbPage *pSrcPg; /* Source page object */ |
| 58510 | 58485 | rc = sqlite3PagerAcquire(pSrcPager, iSrcPg, &pSrcPg, |
| 58511 | | - PAGER_ACQUIRE_READONLY); |
| 58486 | + PAGER_GET_READONLY); |
| 58512 | 58487 | if( rc==SQLITE_OK ){ |
| 58513 | 58488 | rc = backupOnePage(p, iSrcPg, sqlite3PagerGetData(pSrcPg), 0); |
| 58514 | 58489 | sqlite3PagerUnref(pSrcPg); |
| 58515 | 58490 | } |
| 58516 | 58491 | } |
| | @@ -59661,38 +59636,33 @@ |
| 59661 | 59636 | /* If one value is a number and the other is not, the number is less. |
| 59662 | 59637 | ** If both are numbers, compare as reals if one is a real, or as integers |
| 59663 | 59638 | ** if both values are integers. |
| 59664 | 59639 | */ |
| 59665 | 59640 | 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 ){ |
| 59690 | 59643 | if( pMem1->u.i < pMem2->u.i ) return -1; |
| 59691 | 59644 | if( pMem1->u.i > pMem2->u.i ) return 1; |
| 59692 | 59645 | return 0; |
| 59693 | 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; |
| 59694 | 59664 | } |
| 59695 | 59665 | |
| 59696 | 59666 | /* If one value is a string and the other is a blob, the string is less. |
| 59697 | 59667 | ** If both are strings, compare using the collating functions. |
| 59698 | 59668 | */ |
| | @@ -61789,11 +61759,11 @@ |
| 61789 | 61759 | ** virtual module tables written in this transaction. This has to |
| 61790 | 61760 | ** be done before determining whether a master journal file is |
| 61791 | 61761 | ** required, as an xSync() callback may add an attached database |
| 61792 | 61762 | ** to the transaction. |
| 61793 | 61763 | */ |
| 61794 | | - rc = sqlite3VtabSync(db, &p->zErrMsg); |
| 61764 | + rc = sqlite3VtabSync(db, p); |
| 61795 | 61765 | |
| 61796 | 61766 | /* This loop determines (a) if the commit hook should be invoked and |
| 61797 | 61767 | ** (b) how many database files have open write transactions, not |
| 61798 | 61768 | ** including the temp database. (b) is important because if more than |
| 61799 | 61769 | ** one database file has an open write transaction, a master journal |
| | @@ -63329,10 +63299,25 @@ |
| 63329 | 63299 | }else{ |
| 63330 | 63300 | v->expmask |= ((u32)1 << (iVar-1)); |
| 63331 | 63301 | } |
| 63332 | 63302 | } |
| 63333 | 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 | + |
| 63334 | 63319 | /************** End of vdbeaux.c *********************************************/ |
| 63335 | 63320 | /************** Begin file vdbeapi.c *****************************************/ |
| 63336 | 63321 | /* |
| 63337 | 63322 | ** 2004 May 26 |
| 63338 | 63323 | ** |
| | @@ -65518,23 +65503,10 @@ |
| 65518 | 65503 | assert( n==(db->nSavepoint + db->isTransactionSavepoint) ); |
| 65519 | 65504 | return 1; |
| 65520 | 65505 | } |
| 65521 | 65506 | #endif |
| 65522 | 65507 | |
| 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 | 65508 | |
| 65537 | 65509 | /* |
| 65538 | 65510 | ** Execute as much of a VDBE program as we can then return. |
| 65539 | 65511 | ** |
| 65540 | 65512 | ** sqlite3VdbeMakeReady() must be called before this routine in order to |
| | @@ -69880,11 +69852,11 @@ |
| 69880 | 69852 | }else if( u.bn.pC->pVtabCursor ){ |
| 69881 | 69853 | u.bn.pVtab = u.bn.pC->pVtabCursor->pVtab; |
| 69882 | 69854 | u.bn.pModule = u.bn.pVtab->pModule; |
| 69883 | 69855 | assert( u.bn.pModule->xRowid ); |
| 69884 | 69856 | rc = u.bn.pModule->xRowid(u.bn.pC->pVtabCursor, &u.bn.v); |
| 69885 | | - importVtabErrMsg(p, u.bn.pVtab); |
| 69857 | + sqlite3VtabImportErrmsg(p, u.bn.pVtab); |
| 69886 | 69858 | #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| 69887 | 69859 | }else{ |
| 69888 | 69860 | assert( u.bn.pC->pCursor!=0 ); |
| 69889 | 69861 | rc = sqlite3VdbeCursorMoveto(u.bn.pC); |
| 69890 | 69862 | if( rc ) goto abort_due_to_error; |
| | @@ -71321,11 +71293,11 @@ |
| 71321 | 71293 | #if 0 /* local variables moved into u.cl */ |
| 71322 | 71294 | VTable *pVTab; |
| 71323 | 71295 | #endif /* local variables moved into u.cl */ |
| 71324 | 71296 | u.cl.pVTab = pOp->p4.pVtab; |
| 71325 | 71297 | 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); |
| 71327 | 71299 | break; |
| 71328 | 71300 | } |
| 71329 | 71301 | #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| 71330 | 71302 | |
| 71331 | 71303 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| | @@ -71374,11 +71346,11 @@ |
| 71374 | 71346 | u.cm.pVtabCursor = 0; |
| 71375 | 71347 | u.cm.pVtab = pOp->p4.pVtab->pVtab; |
| 71376 | 71348 | u.cm.pModule = (sqlite3_module *)u.cm.pVtab->pModule; |
| 71377 | 71349 | assert(u.cm.pVtab && u.cm.pModule); |
| 71378 | 71350 | rc = u.cm.pModule->xOpen(u.cm.pVtab, &u.cm.pVtabCursor); |
| 71379 | | - importVtabErrMsg(p, u.cm.pVtab); |
| 71351 | + sqlite3VtabImportErrmsg(p, u.cm.pVtab); |
| 71380 | 71352 | if( SQLITE_OK==rc ){ |
| 71381 | 71353 | /* Initialize sqlite3_vtab_cursor base class */ |
| 71382 | 71354 | u.cm.pVtabCursor->pVtab = u.cm.pVtab; |
| 71383 | 71355 | |
| 71384 | 71356 | /* Initialize vdbe cursor object */ |
| | @@ -71454,11 +71426,11 @@ |
| 71454 | 71426 | } |
| 71455 | 71427 | |
| 71456 | 71428 | p->inVtabMethod = 1; |
| 71457 | 71429 | rc = u.cn.pModule->xFilter(u.cn.pVtabCursor, u.cn.iQuery, pOp->p4.z, u.cn.nArg, u.cn.apArg); |
| 71458 | 71430 | p->inVtabMethod = 0; |
| 71459 | | - importVtabErrMsg(p, u.cn.pVtab); |
| 71431 | + sqlite3VtabImportErrmsg(p, u.cn.pVtab); |
| 71460 | 71432 | if( rc==SQLITE_OK ){ |
| 71461 | 71433 | u.cn.res = u.cn.pModule->xEof(u.cn.pVtabCursor); |
| 71462 | 71434 | } |
| 71463 | 71435 | |
| 71464 | 71436 | if( u.cn.res ){ |
| | @@ -71507,11 +71479,11 @@ |
| 71507 | 71479 | */ |
| 71508 | 71480 | sqlite3VdbeMemMove(&u.co.sContext.s, u.co.pDest); |
| 71509 | 71481 | MemSetTypeFlag(&u.co.sContext.s, MEM_Null); |
| 71510 | 71482 | |
| 71511 | 71483 | rc = u.co.pModule->xColumn(pCur->pVtabCursor, &u.co.sContext, pOp->p2); |
| 71512 | | - importVtabErrMsg(p, u.co.pVtab); |
| 71484 | + sqlite3VtabImportErrmsg(p, u.co.pVtab); |
| 71513 | 71485 | if( u.co.sContext.isError ){ |
| 71514 | 71486 | rc = u.co.sContext.isError; |
| 71515 | 71487 | } |
| 71516 | 71488 | |
| 71517 | 71489 | /* Copy the result of the function to the P3 register. We |
| | @@ -71562,11 +71534,11 @@ |
| 71562 | 71534 | ** some other method is next invoked on the save virtual table cursor. |
| 71563 | 71535 | */ |
| 71564 | 71536 | p->inVtabMethod = 1; |
| 71565 | 71537 | rc = u.cp.pModule->xNext(u.cp.pCur->pVtabCursor); |
| 71566 | 71538 | p->inVtabMethod = 0; |
| 71567 | | - importVtabErrMsg(p, u.cp.pVtab); |
| 71539 | + sqlite3VtabImportErrmsg(p, u.cp.pVtab); |
| 71568 | 71540 | if( rc==SQLITE_OK ){ |
| 71569 | 71541 | u.cp.res = u.cp.pModule->xEof(u.cp.pCur->pVtabCursor); |
| 71570 | 71542 | } |
| 71571 | 71543 | |
| 71572 | 71544 | if( !u.cp.res ){ |
| | @@ -71601,11 +71573,11 @@ |
| 71601 | 71573 | testcase( u.cq.pName->enc==SQLITE_UTF16BE ); |
| 71602 | 71574 | testcase( u.cq.pName->enc==SQLITE_UTF16LE ); |
| 71603 | 71575 | rc = sqlite3VdbeChangeEncoding(u.cq.pName, SQLITE_UTF8); |
| 71604 | 71576 | if( rc==SQLITE_OK ){ |
| 71605 | 71577 | 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); |
| 71607 | 71579 | p->expired = 0; |
| 71608 | 71580 | } |
| 71609 | 71581 | break; |
| 71610 | 71582 | } |
| 71611 | 71583 | #endif |
| | @@ -71665,11 +71637,11 @@ |
| 71665 | 71637 | u.cr.pX++; |
| 71666 | 71638 | } |
| 71667 | 71639 | db->vtabOnConflict = pOp->p5; |
| 71668 | 71640 | rc = u.cr.pModule->xUpdate(u.cr.pVtab, u.cr.nArg, u.cr.apArg, &u.cr.rowid); |
| 71669 | 71641 | db->vtabOnConflict = vtabOnConflict; |
| 71670 | | - importVtabErrMsg(p, u.cr.pVtab); |
| 71642 | + sqlite3VtabImportErrmsg(p, u.cr.pVtab); |
| 71671 | 71643 | if( rc==SQLITE_OK && pOp->p1 ){ |
| 71672 | 71644 | assert( u.cr.nArg>1 && u.cr.apArg[0] && (u.cr.apArg[0]->flags&MEM_Null) ); |
| 71673 | 71645 | db->lastRowid = lastRowid = u.cr.rowid; |
| 71674 | 71646 | } |
| 71675 | 71647 | if( (rc&0xff)==SQLITE_CONSTRAINT && pOp->p4.pVtab->bConstraint ){ |
| | @@ -75593,12 +75565,11 @@ |
| 75593 | 75565 | int op = p->op; |
| 75594 | 75566 | if( op==TK_CAST || op==TK_UPLUS ){ |
| 75595 | 75567 | p = p->pLeft; |
| 75596 | 75568 | continue; |
| 75597 | 75569 | } |
| 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) ){ |
| 75600 | 75571 | pColl = sqlite3GetCollSeq(pParse, ENC(db), 0, p->u.zToken); |
| 75601 | 75572 | break; |
| 75602 | 75573 | } |
| 75603 | 75574 | if( p->pTab!=0 |
| 75604 | 75575 | && (op==TK_AGG_COLUMN || op==TK_COLUMN |
| | @@ -78984,10 +78955,11 @@ |
| 78984 | 78955 | compLeft.pRight = pExpr->x.pList->a[0].pExpr; |
| 78985 | 78956 | compRight.op = TK_LE; |
| 78986 | 78957 | compRight.pLeft = &exprX; |
| 78987 | 78958 | compRight.pRight = pExpr->x.pList->a[1].pExpr; |
| 78988 | 78959 | exprX.iTable = sqlite3ExprCodeTemp(pParse, &exprX, ®Free1); |
| 78960 | + exprX.op2 = exprX.op; |
| 78989 | 78961 | exprX.op = TK_REGISTER; |
| 78990 | 78962 | if( jumpIfTrue ){ |
| 78991 | 78963 | sqlite3ExprIfTrue(pParse, &exprAnd, dest, jumpIfNull); |
| 78992 | 78964 | }else{ |
| 78993 | 78965 | sqlite3ExprIfFalse(pParse, &exprAnd, dest, jumpIfNull); |
| | @@ -89001,13 +88973,13 @@ |
| 89001 | 88973 | } |
| 89002 | 88974 | static void groupConcatFinalize(sqlite3_context *context){ |
| 89003 | 88975 | StrAccum *pAccum; |
| 89004 | 88976 | pAccum = sqlite3_aggregate_context(context, 0); |
| 89005 | 88977 | if( pAccum ){ |
| 89006 | | - if( pAccum->tooBig ){ |
| 88978 | + if( pAccum->accError==STRACCUM_TOOBIG ){ |
| 89007 | 88979 | sqlite3_result_error_toobig(context); |
| 89008 | | - }else if( pAccum->mallocFailed ){ |
| 88980 | + }else if( pAccum->accError==STRACCUM_NOMEM ){ |
| 89009 | 88981 | sqlite3_result_error_nomem(context); |
| 89010 | 88982 | }else{ |
| 89011 | 88983 | sqlite3_result_text(context, sqlite3StrAccumFinish(pAccum), -1, |
| 89012 | 88984 | sqlite3_free); |
| 89013 | 88985 | } |
| | @@ -104488,14 +104460,13 @@ |
| 104488 | 104460 | /* |
| 104489 | 104461 | ** Invoke the xSync method of all virtual tables in the sqlite3.aVTrans |
| 104490 | 104462 | ** array. Return the error code for the first error that occurs, or |
| 104491 | 104463 | ** SQLITE_OK if all xSync operations are successful. |
| 104492 | 104464 | ** |
| 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. |
| 104495 | 104466 | */ |
| 104496 | | -SQLITE_PRIVATE int sqlite3VtabSync(sqlite3 *db, char **pzErrmsg){ |
| 104467 | +SQLITE_PRIVATE int sqlite3VtabSync(sqlite3 *db, Vdbe *p){ |
| 104497 | 104468 | int i; |
| 104498 | 104469 | int rc = SQLITE_OK; |
| 104499 | 104470 | VTable **aVTrans = db->aVTrans; |
| 104500 | 104471 | |
| 104501 | 104472 | db->aVTrans = 0; |
| | @@ -104502,13 +104473,11 @@ |
| 104502 | 104473 | for(i=0; rc==SQLITE_OK && i<db->nVTrans; i++){ |
| 104503 | 104474 | int (*x)(sqlite3_vtab *); |
| 104504 | 104475 | sqlite3_vtab *pVtab = aVTrans[i]->pVtab; |
| 104505 | 104476 | if( pVtab && (x = pVtab->pModule->xSync)!=0 ){ |
| 104506 | 104477 | rc = x(pVtab); |
| 104507 | | - sqlite3DbFree(db, *pzErrmsg); |
| 104508 | | - *pzErrmsg = pVtab->zErrMsg; |
| 104509 | | - pVtab->zErrMsg = 0; |
| 104478 | + sqlite3VtabImportErrmsg(p, pVtab); |
| 104510 | 104479 | } |
| 104511 | 104480 | } |
| 104512 | 104481 | db->aVTrans = aVTrans; |
| 104513 | 104482 | return rc; |
| 104514 | 104483 | } |
| | @@ -104869,10 +104838,11 @@ |
| 104869 | 104838 | int iIdxCur; /* The VDBE cursor used to access pIdx */ |
| 104870 | 104839 | int addrBrk; /* Jump here to break out of the loop */ |
| 104871 | 104840 | int addrNxt; /* Jump here to start the next IN combination */ |
| 104872 | 104841 | int addrCont; /* Jump here to continue with the next loop cycle */ |
| 104873 | 104842 | int addrFirst; /* First instruction of interior of the loop */ |
| 104843 | + int addrBody; /* Beginning of the body of this loop */ |
| 104874 | 104844 | u8 iFrom; /* Which entry in the FROM clause */ |
| 104875 | 104845 | u8 op, p5; /* Opcode and P5 of the opcode that ends the loop */ |
| 104876 | 104846 | int p1, p2; /* Operands of the opcode used to ends the loop */ |
| 104877 | 104847 | union { /* Information that depends on pWLoop->wsFlags */ |
| 104878 | 104848 | struct { |
| | @@ -107808,11 +107778,11 @@ |
| 107808 | 107778 | pParse->db->mallocFailed = 1; |
| 107809 | 107779 | } |
| 107810 | 107780 | |
| 107811 | 107781 | /* Evaluate the equality constraints |
| 107812 | 107782 | */ |
| 107813 | | - assert( pIdx->nColumn>=nEq ); |
| 107783 | + assert( zAff==0 || strlen(zAff)>=nEq ); |
| 107814 | 107784 | for(j=0; j<nEq; j++){ |
| 107815 | 107785 | int r1; |
| 107816 | 107786 | pTerm = pLoop->aLTerm[j]; |
| 107817 | 107787 | assert( pTerm!=0 ); |
| 107818 | 107788 | /* The following true for indices with redundant columns. |
| | @@ -107900,11 +107870,12 @@ |
| 107900 | 107870 | } |
| 107901 | 107871 | sqlite3StrAccumInit(&txt, 0, 0, SQLITE_MAX_LENGTH); |
| 107902 | 107872 | txt.db = db; |
| 107903 | 107873 | sqlite3StrAccumAppend(&txt, " (", 2); |
| 107904 | 107874 | 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, "="); |
| 107906 | 107877 | } |
| 107907 | 107878 | |
| 107908 | 107879 | j = i; |
| 107909 | 107880 | if( pLoop->wsFlags&WHERE_BTM_LIMIT ){ |
| 107910 | 107881 | char *z = (j==pIndex->nColumn ) ? "rowid" : aCol[aiColumn[j]].zName; |
| | @@ -109115,17 +109086,15 @@ |
| 109115 | 109086 | pNew->rSetup = 0; |
| 109116 | 109087 | rLogSize = estLog(whereCost(pProbe->aiRowEst[0])); |
| 109117 | 109088 | for(; rc==SQLITE_OK && pTerm!=0; pTerm = whereScanNext(&scan)){ |
| 109118 | 109089 | int nIn = 0; |
| 109119 | 109090 | 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) |
| 109122 | 109092 | && (iCol<0 || pSrc->pTab->aCol[iCol].notNull) |
| 109123 | 109093 | ){ |
| 109124 | | - continue; /* skip IS NOT NULL constraints on a NOT NULL column */ |
| 109094 | + continue; /* ignore IS [NOT] NULL constraints on NOT NULL columns */ |
| 109125 | 109095 | } |
| 109126 | | -#endif |
| 109127 | 109096 | pNew->wsFlags = saved_wsFlags; |
| 109128 | 109097 | pNew->u.btree.nEq = saved_nEq; |
| 109129 | 109098 | pNew->nLTerm = saved_nLTerm; |
| 109130 | 109099 | if( whereLoopResize(db, pNew, pNew->nLTerm+1) ) break; /* OOM */ |
| 109131 | 109100 | pNew->aLTerm[pNew->nLTerm++] = pTerm; |
| | @@ -110764,15 +110733,10 @@ |
| 110764 | 110733 | assert( n<=pTab->nCol ); |
| 110765 | 110734 | } |
| 110766 | 110735 | }else{ |
| 110767 | 110736 | sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName); |
| 110768 | 110737 | } |
| 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 | 110738 | if( pLoop->wsFlags & WHERE_INDEXED ){ |
| 110775 | 110739 | Index *pIx = pLoop->u.btree.pIndex; |
| 110776 | 110740 | KeyInfo *pKey = sqlite3IndexKeyinfo(pParse, pIx); |
| 110777 | 110741 | /* FIXME: As an optimization use pTabItem->iCursor if WHERE_IDX_ONLY */ |
| 110778 | 110742 | int iIndexCur = pLevel->iIdxCur = iIdxCur ? iIdxCur : pParse->nTab++; |
| | @@ -110793,11 +110757,19 @@ |
| 110793 | 110757 | ** program. |
| 110794 | 110758 | */ |
| 110795 | 110759 | notReady = ~(Bitmask)0; |
| 110796 | 110760 | for(ii=0; ii<nTabList; ii++){ |
| 110797 | 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 |
| 110798 | 110769 | explainOneScan(pParse, pTabList, pLevel, ii, pLevel->iFrom, wctrlFlags); |
| 110770 | + pLevel->addrBody = sqlite3VdbeCurrentAddr(v); |
| 110799 | 110771 | notReady = codeOneLoopStart(pWInfo, ii, notReady); |
| 110800 | 110772 | pWInfo->iContinue = pLevel->addrCont; |
| 110801 | 110773 | } |
| 110802 | 110774 | |
| 110803 | 110775 | /* Done. */ |
| | @@ -110913,13 +110885,14 @@ |
| 110913 | 110885 | } |
| 110914 | 110886 | if( pIdx && !db->mallocFailed ){ |
| 110915 | 110887 | int k, j, last; |
| 110916 | 110888 | VdbeOp *pOp; |
| 110917 | 110889 | |
| 110918 | | - pOp = sqlite3VdbeGetOp(v, pWInfo->iTop); |
| 110919 | 110890 | 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++){ |
| 110921 | 110894 | if( pOp->p1!=pLevel->iTabCur ) continue; |
| 110922 | 110895 | if( pOp->opcode==OP_Column ){ |
| 110923 | 110896 | for(j=0; j<pIdx->nColumn; j++){ |
| 110924 | 110897 | if( pOp->p2==pIdx->aiColumn[j] ){ |
| 110925 | 110898 | pOp->p2 = j; |
| | @@ -134651,15 +134624,15 @@ |
| 134651 | 134624 | } |
| 134652 | 134625 | } |
| 134653 | 134626 | if( pTC ) pModule->xClose(pTC); |
| 134654 | 134627 | if( rc==SQLITE_DONE ) rc = SQLITE_OK; |
| 134655 | 134628 | } |
| 134629 | + } |
| 134656 | 134630 | |
| 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); |
| 134661 | 134634 | } |
| 134662 | 134635 | } |
| 134663 | 134636 | } |
| 134664 | 134637 | |
| 134665 | 134638 | return rc; |
| 134666 | 134639 | |