Fossil SCM
Update SQLite to the latest version 3.7.1 beta.
Commit
79c9de763a272f3c29a24c11a5d6d1301ae08874
Parent
98870a8510dc9a9…
2 files changed
+72
-34
+1
-1
+72
-34
| --- src/sqlite3.c | ||
| +++ src/sqlite3.c | ||
| @@ -216,20 +216,22 @@ | ||
| 216 | 216 | #endif |
| 217 | 217 | |
| 218 | 218 | /* Maximum page size. The upper bound on this value is 65536. This a limit |
| 219 | 219 | ** imposed by the use of 16-bit offsets within each page. |
| 220 | 220 | ** |
| 221 | -** If this limit is changed, then the compiled library is technically | |
| 222 | -** incompatible with an SQLite library compiled with a different limit. If | |
| 223 | -** a process operating on a database with a page-size of 65536 bytes | |
| 224 | -** crashes, then an instance of SQLite compiled with the default page-size | |
| 225 | -** limit will not be able to rollback the aborted transaction. This could | |
| 226 | -** lead to database corruption. | |
| 221 | +** Earlier versions of SQLite allowed the user to change this value at | |
| 222 | +** compile time. This is no longer permitted, on the grounds that it creates | |
| 223 | +** a library that is technically incompatible with an SQLite library | |
| 224 | +** compiled with a different limit. If a process operating on a database | |
| 225 | +** with a page-size of 65536 bytes crashes, then an instance of SQLite | |
| 226 | +** compiled with the default page-size limit will not be able to rollback | |
| 227 | +** the aborted transaction. This could lead to database corruption. | |
| 227 | 228 | */ |
| 228 | -#ifndef SQLITE_MAX_PAGE_SIZE | |
| 229 | -# define SQLITE_MAX_PAGE_SIZE 65536 | |
| 229 | +#ifdef SQLITE_MAX_PAGE_SIZE | |
| 230 | +# undef SQLITE_MAX_PAGE_SIZE | |
| 230 | 231 | #endif |
| 232 | +#define SQLITE_MAX_PAGE_SIZE 65536 | |
| 231 | 233 | |
| 232 | 234 | |
| 233 | 235 | /* |
| 234 | 236 | ** The default size of a database page. |
| 235 | 237 | */ |
| @@ -642,11 +644,11 @@ | ||
| 642 | 644 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 643 | 645 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 644 | 646 | */ |
| 645 | 647 | #define SQLITE_VERSION "3.7.1" |
| 646 | 648 | #define SQLITE_VERSION_NUMBER 3007001 |
| 647 | -#define SQLITE_SOURCE_ID "2010-08-17 19:49:14 acb171d4cfef2fec8833f761019f5c81f0d138a0" | |
| 649 | +#define SQLITE_SOURCE_ID "2010-08-20 15:32:21 5523ecd32295c188e3bf5dbd57d92d2879461e32" | |
| 648 | 650 | |
| 649 | 651 | /* |
| 650 | 652 | ** CAPI3REF: Run-Time Library Version Numbers |
| 651 | 653 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 652 | 654 | ** |
| @@ -14339,11 +14341,11 @@ | ||
| 14339 | 14341 | |
| 14340 | 14342 | /* |
| 14341 | 14343 | ** Set the "type" of an allocation. |
| 14342 | 14344 | */ |
| 14343 | 14345 | SQLITE_PRIVATE void sqlite3MemdebugSetType(void *p, u8 eType){ |
| 14344 | - if( p ){ | |
| 14346 | + if( p && sqlite3GlobalConfig.m.xMalloc==sqlite3MemMalloc ){ | |
| 14345 | 14347 | struct MemBlockHdr *pHdr; |
| 14346 | 14348 | pHdr = sqlite3MemsysGetHeader(p); |
| 14347 | 14349 | assert( pHdr->iForeGuard==FOREGUARD ); |
| 14348 | 14350 | pHdr->eType = eType; |
| 14349 | 14351 | } |
| @@ -14358,11 +14360,11 @@ | ||
| 14358 | 14360 | ** |
| 14359 | 14361 | ** assert( sqlite3MemdebugHasType(p, MEMTYPE_DB) ); |
| 14360 | 14362 | */ |
| 14361 | 14363 | SQLITE_PRIVATE int sqlite3MemdebugHasType(void *p, u8 eType){ |
| 14362 | 14364 | int rc = 1; |
| 14363 | - if( p ){ | |
| 14365 | + if( p && sqlite3GlobalConfig.m.xMalloc==sqlite3MemMalloc ){ | |
| 14364 | 14366 | struct MemBlockHdr *pHdr; |
| 14365 | 14367 | pHdr = sqlite3MemsysGetHeader(p); |
| 14366 | 14368 | assert( pHdr->iForeGuard==FOREGUARD ); /* Allocation is valid */ |
| 14367 | 14369 | if( (pHdr->eType&eType)==0 ){ |
| 14368 | 14370 | rc = 0; |
| @@ -14380,11 +14382,11 @@ | ||
| 14380 | 14382 | ** |
| 14381 | 14383 | ** assert( sqlite3MemdebugNoType(p, MEMTYPE_DB) ); |
| 14382 | 14384 | */ |
| 14383 | 14385 | SQLITE_PRIVATE int sqlite3MemdebugNoType(void *p, u8 eType){ |
| 14384 | 14386 | int rc = 1; |
| 14385 | - if( p ){ | |
| 14387 | + if( p && sqlite3GlobalConfig.m.xMalloc==sqlite3MemMalloc ){ | |
| 14386 | 14388 | struct MemBlockHdr *pHdr; |
| 14387 | 14389 | pHdr = sqlite3MemsysGetHeader(p); |
| 14388 | 14390 | assert( pHdr->iForeGuard==FOREGUARD ); /* Allocation is valid */ |
| 14389 | 14391 | if( (pHdr->eType&eType)!=0 ){ |
| 14390 | 14392 | rc = 0; |
| @@ -33010,10 +33012,29 @@ | ||
| 33010 | 33012 | sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_OVERFLOW, -iSize); |
| 33011 | 33013 | sqlite3_free(p); |
| 33012 | 33014 | } |
| 33013 | 33015 | } |
| 33014 | 33016 | |
| 33017 | +#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT | |
| 33018 | +/* | |
| 33019 | +** Return the size of a pache allocation | |
| 33020 | +*/ | |
| 33021 | +static int pcache1MemSize(void *p){ | |
| 33022 | + assert( sqlite3_mutex_held(pcache1.mutex) ); | |
| 33023 | + if( p>=pcache1.pStart && p<pcache1.pEnd ){ | |
| 33024 | + return pcache1.szSlot; | |
| 33025 | + }else{ | |
| 33026 | + int iSize; | |
| 33027 | + assert( sqlite3MemdebugHasType(p, MEMTYPE_PCACHE) ); | |
| 33028 | + sqlite3MemdebugSetType(p, MEMTYPE_HEAP); | |
| 33029 | + iSize = sqlite3MallocSize(p); | |
| 33030 | + sqlite3MemdebugSetType(p, MEMTYPE_PCACHE); | |
| 33031 | + return iSize; | |
| 33032 | + } | |
| 33033 | +} | |
| 33034 | +#endif /* SQLITE_ENABLE_MEMORY_MANAGEMENT */ | |
| 33035 | + | |
| 33015 | 33036 | /* |
| 33016 | 33037 | ** Allocate a new page object initially associated with cache pCache. |
| 33017 | 33038 | */ |
| 33018 | 33039 | static PgHdr1 *pcache1AllocPage(PCache1 *pCache){ |
| 33019 | 33040 | int nByte = sizeof(PgHdr1) + pCache->szPage; |
| @@ -33558,11 +33579,11 @@ | ||
| 33558 | 33579 | int nFree = 0; |
| 33559 | 33580 | if( pcache1.pStart==0 ){ |
| 33560 | 33581 | PgHdr1 *p; |
| 33561 | 33582 | pcache1EnterMutex(); |
| 33562 | 33583 | while( (nReq<0 || nFree<nReq) && (p=pcache1.pLruTail) ){ |
| 33563 | - nFree += sqlite3MallocSize(PGHDR1_TO_PAGE(p)); | |
| 33584 | + nFree += pcache1MemSize(PGHDR1_TO_PAGE(p)); | |
| 33564 | 33585 | pcache1PinPage(p); |
| 33565 | 33586 | pcache1RemoveFromHash(p); |
| 33566 | 33587 | pcache1FreePage(p); |
| 33567 | 33588 | } |
| 33568 | 33589 | pcache1LeaveMutex(); |
| @@ -35185,11 +35206,11 @@ | ||
| 35185 | 35206 | assert( eLock!=NO_LOCK || pagerUseWal(pPager)==0 ); |
| 35186 | 35207 | if( isOpen(pPager->fd) ){ |
| 35187 | 35208 | assert( pPager->eLock>=eLock ); |
| 35188 | 35209 | rc = sqlite3OsUnlock(pPager->fd, eLock); |
| 35189 | 35210 | if( pPager->eLock!=UNKNOWN_LOCK ){ |
| 35190 | - pPager->eLock = eLock; | |
| 35211 | + pPager->eLock = (u8)eLock; | |
| 35191 | 35212 | } |
| 35192 | 35213 | IOTRACE(("UNLOCK %p %d\n", pPager, eLock)) |
| 35193 | 35214 | } |
| 35194 | 35215 | return rc; |
| 35195 | 35216 | } |
| @@ -35209,11 +35230,11 @@ | ||
| 35209 | 35230 | |
| 35210 | 35231 | assert( eLock==SHARED_LOCK || eLock==RESERVED_LOCK || eLock==EXCLUSIVE_LOCK ); |
| 35211 | 35232 | if( pPager->eLock<eLock || pPager->eLock==UNKNOWN_LOCK ){ |
| 35212 | 35233 | rc = sqlite3OsLock(pPager->fd, eLock); |
| 35213 | 35234 | if( rc==SQLITE_OK && (pPager->eLock!=UNKNOWN_LOCK||eLock==EXCLUSIVE_LOCK) ){ |
| 35214 | - pPager->eLock = eLock; | |
| 35235 | + pPager->eLock = (u8)eLock; | |
| 35215 | 35236 | IOTRACE(("LOCK %p %d\n", pPager, eLock)) |
| 35216 | 35237 | } |
| 35217 | 35238 | } |
| 35218 | 35239 | return rc; |
| 35219 | 35240 | } |
| @@ -35636,10 +35657,18 @@ | ||
| 35636 | 35657 | if( SQLITE_OK!=(rc = read32bits(pPager->jfd, iHdrOff+20, &iSectorSize)) |
| 35637 | 35658 | || SQLITE_OK!=(rc = read32bits(pPager->jfd, iHdrOff+24, &iPageSize)) |
| 35638 | 35659 | ){ |
| 35639 | 35660 | return rc; |
| 35640 | 35661 | } |
| 35662 | + | |
| 35663 | + /* Versions of SQLite prior to 3.5.8 set the page-size field of the | |
| 35664 | + ** journal header to zero. In this case, assume that the Pager.pageSize | |
| 35665 | + ** variable is already set to the correct page size. | |
| 35666 | + */ | |
| 35667 | + if( iPageSize==0 ){ | |
| 35668 | + iPageSize = pPager->pageSize; | |
| 35669 | + } | |
| 35641 | 35670 | |
| 35642 | 35671 | /* Check that the values read from the page-size and sector-size fields |
| 35643 | 35672 | ** are within range. To be 'in range', both values need to be a power |
| 35644 | 35673 | ** of two greater than or equal to 512 or 32, and not greater than their |
| 35645 | 35674 | ** respective compile time maximum limits. |
| @@ -37494,11 +37523,11 @@ | ||
| 37494 | 37523 | assert( pageSize==0 || (pageSize>=512 && pageSize<=SQLITE_MAX_PAGE_SIZE) ); |
| 37495 | 37524 | if( (pPager->memDb==0 || pPager->dbSize==0) |
| 37496 | 37525 | && sqlite3PcacheRefCount(pPager->pPCache)==0 |
| 37497 | 37526 | && pageSize && pageSize!=(u32)pPager->pageSize |
| 37498 | 37527 | ){ |
| 37499 | - char *pNew; /* New temp space */ | |
| 37528 | + char *pNew = NULL; /* New temp space */ | |
| 37500 | 37529 | i64 nByte = 0; |
| 37501 | 37530 | |
| 37502 | 37531 | if( pPager->eState>PAGER_OPEN && isOpen(pPager->fd) ){ |
| 37503 | 37532 | rc = sqlite3OsFileSize(pPager->fd, &nByte); |
| 37504 | 37533 | } |
| @@ -37507,11 +37536,11 @@ | ||
| 37507 | 37536 | if( !pNew ) rc = SQLITE_NOMEM; |
| 37508 | 37537 | } |
| 37509 | 37538 | |
| 37510 | 37539 | if( rc==SQLITE_OK ){ |
| 37511 | 37540 | pager_reset(pPager); |
| 37512 | - pPager->dbSize = nByte/pageSize; | |
| 37541 | + pPager->dbSize = (Pgno)(nByte/pageSize); | |
| 37513 | 37542 | pPager->pageSize = pageSize; |
| 37514 | 37543 | sqlite3PageFree(pPager->pTmpSpace); |
| 37515 | 37544 | pPager->pTmpSpace = pNew; |
| 37516 | 37545 | sqlite3PcacheSetPageSize(pPager->pPCache, pageSize); |
| 37517 | 37546 | } |
| @@ -41910,11 +41939,11 @@ | ||
| 41910 | 41939 | |
| 41911 | 41940 | /* If nTruncate is non-zero, this is a commit record. */ |
| 41912 | 41941 | if( nTruncate ){ |
| 41913 | 41942 | pWal->hdr.mxFrame = iFrame; |
| 41914 | 41943 | pWal->hdr.nPage = nTruncate; |
| 41915 | - pWal->hdr.szPage = (szPage&0xff00) | (szPage>>16); | |
| 41944 | + pWal->hdr.szPage = (u16)((szPage&0xff00) | (szPage>>16)); | |
| 41916 | 41945 | testcase( szPage<=32768 ); |
| 41917 | 41946 | testcase( szPage>=65536 ); |
| 41918 | 41947 | aFrameCksum[0] = pWal->hdr.aFrameCksum[0]; |
| 41919 | 41948 | aFrameCksum[1] = pWal->hdr.aFrameCksum[1]; |
| 41920 | 41949 | } |
| @@ -43337,11 +43366,11 @@ | ||
| 43337 | 43366 | rc = walIndexAppend(pWal, iFrame, pLast->pgno); |
| 43338 | 43367 | } |
| 43339 | 43368 | |
| 43340 | 43369 | if( rc==SQLITE_OK ){ |
| 43341 | 43370 | /* Update the private copy of the header. */ |
| 43342 | - pWal->hdr.szPage = (szPage&0xff00) | (szPage>>16); | |
| 43371 | + pWal->hdr.szPage = (u16)((szPage&0xff00) | (szPage>>16)); | |
| 43343 | 43372 | testcase( szPage<=32768 ); |
| 43344 | 43373 | testcase( szPage>=65536 ); |
| 43345 | 43374 | pWal->hdr.mxFrame = iFrame; |
| 43346 | 43375 | if( isCommit ){ |
| 43347 | 43376 | pWal->hdr.iChange++; |
| @@ -45873,11 +45902,11 @@ | ||
| 45873 | 45902 | u16 pc; /* Address of a freeblock within pPage->aData[] */ |
| 45874 | 45903 | u8 hdr; /* Offset to beginning of page header */ |
| 45875 | 45904 | u8 *data; /* Equal to pPage->aData */ |
| 45876 | 45905 | BtShared *pBt; /* The main btree structure */ |
| 45877 | 45906 | int usableSize; /* Amount of usable space on each page */ |
| 45878 | - int cellOffset; /* Offset from start of page to first cell pointer */ | |
| 45907 | + u16 cellOffset; /* Offset from start of page to first cell pointer */ | |
| 45879 | 45908 | int nFree; /* Number of unused bytes on the page */ |
| 45880 | 45909 | int top; /* First byte of the cell content area */ |
| 45881 | 45910 | int iCellFirst; /* First allowable cell or freeblock offset */ |
| 45882 | 45911 | int iCellLast; /* Last possible cell or freeblock offset */ |
| 45883 | 45912 | |
| @@ -45988,11 +46017,11 @@ | ||
| 45988 | 46017 | data[hdr] = (char)flags; |
| 45989 | 46018 | first = hdr + 8 + 4*((flags&PTF_LEAF)==0 ?1:0); |
| 45990 | 46019 | memset(&data[hdr+1], 0, 4); |
| 45991 | 46020 | data[hdr+7] = 0; |
| 45992 | 46021 | put2byte(&data[hdr+5], pBt->usableSize); |
| 45993 | - pPage->nFree = pBt->usableSize - first; | |
| 46022 | + pPage->nFree = (u16)(pBt->usableSize - first); | |
| 45994 | 46023 | decodeFlags(pPage, flags); |
| 45995 | 46024 | pPage->hdrOffset = hdr; |
| 45996 | 46025 | pPage->cellOffset = first; |
| 45997 | 46026 | pPage->nOverflow = 0; |
| 45998 | 46027 | assert( pBt->pageSize>=512 && pBt->pageSize<=65536 ); |
| @@ -46817,11 +46846,11 @@ | ||
| 46817 | 46846 | ){ |
| 46818 | 46847 | goto page1_init_failed; |
| 46819 | 46848 | } |
| 46820 | 46849 | assert( (pageSize & 7)==0 ); |
| 46821 | 46850 | usableSize = pageSize - page1[20]; |
| 46822 | - if( pageSize!=pBt->pageSize ){ | |
| 46851 | + if( (u32)pageSize!=pBt->pageSize ){ | |
| 46823 | 46852 | /* After reading the first page of the database assuming a page size |
| 46824 | 46853 | ** of BtShared.pageSize, we have discovered that the page-size is |
| 46825 | 46854 | ** actually pageSize. Unlock the database, leave pBt->pPage1 at |
| 46826 | 46855 | ** zero and return SQLITE_OK. The caller will call this function |
| 46827 | 46856 | ** again with the correct page-size. |
| @@ -46856,18 +46885,18 @@ | ||
| 46856 | 46885 | ** 2-byte pointer to the cell |
| 46857 | 46886 | ** 4-byte child pointer |
| 46858 | 46887 | ** 9-byte nKey value |
| 46859 | 46888 | ** 4-byte nData value |
| 46860 | 46889 | ** 4-byte overflow page pointer |
| 46861 | - ** So a cell consists of a 2-byte poiner, a header which is as much as | |
| 46890 | + ** So a cell consists of a 2-byte pointer, a header which is as much as | |
| 46862 | 46891 | ** 17 bytes long, 0 to N bytes of payload, and an optional 4 byte overflow |
| 46863 | 46892 | ** page pointer. |
| 46864 | 46893 | */ |
| 46865 | - pBt->maxLocal = (pBt->usableSize-12)*64/255 - 23; | |
| 46866 | - pBt->minLocal = (pBt->usableSize-12)*32/255 - 23; | |
| 46867 | - pBt->maxLeaf = pBt->usableSize - 35; | |
| 46868 | - pBt->minLeaf = (pBt->usableSize-12)*32/255 - 23; | |
| 46894 | + pBt->maxLocal = (u16)((pBt->usableSize-12)*64/255 - 23); | |
| 46895 | + pBt->minLocal = (u16)((pBt->usableSize-12)*32/255 - 23); | |
| 46896 | + pBt->maxLeaf = (u16)(pBt->usableSize - 35); | |
| 46897 | + pBt->minLeaf = (u16)((pBt->usableSize-12)*32/255 - 23); | |
| 46869 | 46898 | assert( pBt->maxLeaf + 23 <= MX_CELL_SIZE(pBt) ); |
| 46870 | 46899 | pBt->pPage1 = pPage1; |
| 46871 | 46900 | pBt->nPage = nPage; |
| 46872 | 46901 | return SQLITE_OK; |
| 46873 | 46902 | |
| @@ -46916,12 +46945,12 @@ | ||
| 46916 | 46945 | data = pP1->aData; |
| 46917 | 46946 | rc = sqlite3PagerWrite(pP1->pDbPage); |
| 46918 | 46947 | if( rc ) return rc; |
| 46919 | 46948 | memcpy(data, zMagicHeader, sizeof(zMagicHeader)); |
| 46920 | 46949 | assert( sizeof(zMagicHeader)==16 ); |
| 46921 | - data[16] = (pBt->pageSize>>8)&0xff; | |
| 46922 | - data[17] = (pBt->pageSize>>16)&0xff; | |
| 46950 | + data[16] = (u8)((pBt->pageSize>>8)&0xff); | |
| 46951 | + data[17] = (u8)((pBt->pageSize>>16)&0xff); | |
| 46923 | 46952 | data[18] = 1; |
| 46924 | 46953 | data[19] = 1; |
| 46925 | 46954 | assert( pBt->usableSize<=pBt->pageSize && pBt->usableSize+255>=pBt->pageSize); |
| 46926 | 46955 | data[20] = (u8)(pBt->pageSize - pBt->usableSize); |
| 46927 | 46956 | data[21] = 64; |
| @@ -49599,11 +49628,11 @@ | ||
| 49599 | 49628 | BtShared *pBt = pPage->pBt; |
| 49600 | 49629 | CellInfo info; |
| 49601 | 49630 | Pgno ovflPgno; |
| 49602 | 49631 | int rc; |
| 49603 | 49632 | int nOvfl; |
| 49604 | - u16 ovflPageSize; | |
| 49633 | + u32 ovflPageSize; | |
| 49605 | 49634 | |
| 49606 | 49635 | assert( sqlite3_mutex_held(pPage->pBt->mutex) ); |
| 49607 | 49636 | btreeParseCellPtr(pPage, pCell, &info); |
| 49608 | 49637 | if( info.iOverflow==0 ){ |
| 49609 | 49638 | return SQLITE_OK; /* No overflow pages. Return without doing anything */ |
| @@ -50051,11 +50080,11 @@ | ||
| 50051 | 50080 | assert( sqlite3_mutex_held(pPage->pBt->mutex) ); |
| 50052 | 50081 | assert( sqlite3PagerIswriteable(pParent->pDbPage) ); |
| 50053 | 50082 | assert( pPage->nOverflow==1 ); |
| 50054 | 50083 | |
| 50055 | 50084 | /* This error condition is now caught prior to reaching this function */ |
| 50056 | - if( NEVER(pPage->nCell<=0) ) return SQLITE_CORRUPT_BKPT; | |
| 50085 | + if( pPage->nCell<=0 ) return SQLITE_CORRUPT_BKPT; | |
| 50057 | 50086 | |
| 50058 | 50087 | /* Allocate a new page. This page will become the right-sibling of |
| 50059 | 50088 | ** pPage. Make the parent page writable, so that the new divider cell |
| 50060 | 50089 | ** may be inserted. If both these operations are successful, proceed. |
| 50061 | 50090 | */ |
| @@ -50459,11 +50488,11 @@ | ||
| 50459 | 50488 | u8 *pTemp; |
| 50460 | 50489 | assert( nCell<nMaxCells ); |
| 50461 | 50490 | szCell[nCell] = sz; |
| 50462 | 50491 | pTemp = &aSpace1[iSpace1]; |
| 50463 | 50492 | iSpace1 += sz; |
| 50464 | - assert( sz<=pBt->pageSize/4 ); | |
| 50493 | + assert( sz<=pBt->maxLocal+23 ); | |
| 50465 | 50494 | assert( iSpace1<=pBt->pageSize ); |
| 50466 | 50495 | memcpy(pTemp, apDiv[i], sz); |
| 50467 | 50496 | apCell[nCell] = pTemp+leafCorrection; |
| 50468 | 50497 | assert( leafCorrection==0 || leafCorrection==4 ); |
| 50469 | 50498 | szCell[nCell] = szCell[nCell] - leafCorrection; |
| @@ -50705,11 +50734,11 @@ | ||
| 50705 | 50734 | assert(leafCorrection==4); |
| 50706 | 50735 | sz = cellSizePtr(pParent, pCell); |
| 50707 | 50736 | } |
| 50708 | 50737 | } |
| 50709 | 50738 | iOvflSpace += sz; |
| 50710 | - assert( sz<=pBt->pageSize/4 ); | |
| 50739 | + assert( sz<=pBt->maxLocal+23 ); | |
| 50711 | 50740 | assert( iOvflSpace<=pBt->pageSize ); |
| 50712 | 50741 | insertCell(pParent, nxDiv, pCell, sz, pTemp, pNew->pgno, &rc); |
| 50713 | 50742 | if( rc!=SQLITE_OK ) goto balance_cleanup; |
| 50714 | 50743 | assert( sqlite3PagerIswriteable(pParent->pDbPage) ); |
| 50715 | 50744 | |
| @@ -52796,10 +52825,19 @@ | ||
| 52796 | 52825 | ** page sizes of the source and destination differ. |
| 52797 | 52826 | */ |
| 52798 | 52827 | if( nSrcPgsz!=nDestPgsz && sqlite3PagerIsMemdb(pDestPager) ){ |
| 52799 | 52828 | rc = SQLITE_READONLY; |
| 52800 | 52829 | } |
| 52830 | + | |
| 52831 | +#ifdef SQLITE_HAS_CODEC | |
| 52832 | + /* Backup is not possible if the page size of the destination is changing | |
| 52833 | + ** a a codec is in use. | |
| 52834 | + */ | |
| 52835 | + if( nSrcPgsz!=nDestPgsz && sqlite3PagerGetCodec(pDestPager)!=0 ){ | |
| 52836 | + rc = SQLITE_READONLY; | |
| 52837 | + } | |
| 52838 | +#endif | |
| 52801 | 52839 | |
| 52802 | 52840 | /* This loop runs once for each destination page spanned by the source |
| 52803 | 52841 | ** page. For each iteration, variable iOff is set to the byte offset |
| 52804 | 52842 | ** of the destination page. |
| 52805 | 52843 | */ |
| @@ -68200,11 +68238,11 @@ | ||
| 68200 | 68238 | if( bOk==0 || i<1 || i>db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ){ |
| 68201 | 68239 | sqlite3ErrorMsg(pParse, "variable number must be between ?1 and ?%d", |
| 68202 | 68240 | db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER]); |
| 68203 | 68241 | } |
| 68204 | 68242 | if( i>pParse->nVar ){ |
| 68205 | - pParse->nVar = i; | |
| 68243 | + pParse->nVar = (int)i; | |
| 68206 | 68244 | } |
| 68207 | 68245 | }else{ |
| 68208 | 68246 | /* Wildcards like ":aaa", "$aaa" or "@aaa". Reuse the same variable |
| 68209 | 68247 | ** number as the prior appearance of the same name, or if the name |
| 68210 | 68248 | ** has never appeared before, reuse the same variable number |
| 68211 | 68249 |
| --- src/sqlite3.c | |
| +++ src/sqlite3.c | |
| @@ -216,20 +216,22 @@ | |
| 216 | #endif |
| 217 | |
| 218 | /* Maximum page size. The upper bound on this value is 65536. This a limit |
| 219 | ** imposed by the use of 16-bit offsets within each page. |
| 220 | ** |
| 221 | ** If this limit is changed, then the compiled library is technically |
| 222 | ** incompatible with an SQLite library compiled with a different limit. If |
| 223 | ** a process operating on a database with a page-size of 65536 bytes |
| 224 | ** crashes, then an instance of SQLite compiled with the default page-size |
| 225 | ** limit will not be able to rollback the aborted transaction. This could |
| 226 | ** lead to database corruption. |
| 227 | */ |
| 228 | #ifndef SQLITE_MAX_PAGE_SIZE |
| 229 | # define SQLITE_MAX_PAGE_SIZE 65536 |
| 230 | #endif |
| 231 | |
| 232 | |
| 233 | /* |
| 234 | ** The default size of a database page. |
| 235 | */ |
| @@ -642,11 +644,11 @@ | |
| 642 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 643 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 644 | */ |
| 645 | #define SQLITE_VERSION "3.7.1" |
| 646 | #define SQLITE_VERSION_NUMBER 3007001 |
| 647 | #define SQLITE_SOURCE_ID "2010-08-17 19:49:14 acb171d4cfef2fec8833f761019f5c81f0d138a0" |
| 648 | |
| 649 | /* |
| 650 | ** CAPI3REF: Run-Time Library Version Numbers |
| 651 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 652 | ** |
| @@ -14339,11 +14341,11 @@ | |
| 14339 | |
| 14340 | /* |
| 14341 | ** Set the "type" of an allocation. |
| 14342 | */ |
| 14343 | SQLITE_PRIVATE void sqlite3MemdebugSetType(void *p, u8 eType){ |
| 14344 | if( p ){ |
| 14345 | struct MemBlockHdr *pHdr; |
| 14346 | pHdr = sqlite3MemsysGetHeader(p); |
| 14347 | assert( pHdr->iForeGuard==FOREGUARD ); |
| 14348 | pHdr->eType = eType; |
| 14349 | } |
| @@ -14358,11 +14360,11 @@ | |
| 14358 | ** |
| 14359 | ** assert( sqlite3MemdebugHasType(p, MEMTYPE_DB) ); |
| 14360 | */ |
| 14361 | SQLITE_PRIVATE int sqlite3MemdebugHasType(void *p, u8 eType){ |
| 14362 | int rc = 1; |
| 14363 | if( p ){ |
| 14364 | struct MemBlockHdr *pHdr; |
| 14365 | pHdr = sqlite3MemsysGetHeader(p); |
| 14366 | assert( pHdr->iForeGuard==FOREGUARD ); /* Allocation is valid */ |
| 14367 | if( (pHdr->eType&eType)==0 ){ |
| 14368 | rc = 0; |
| @@ -14380,11 +14382,11 @@ | |
| 14380 | ** |
| 14381 | ** assert( sqlite3MemdebugNoType(p, MEMTYPE_DB) ); |
| 14382 | */ |
| 14383 | SQLITE_PRIVATE int sqlite3MemdebugNoType(void *p, u8 eType){ |
| 14384 | int rc = 1; |
| 14385 | if( p ){ |
| 14386 | struct MemBlockHdr *pHdr; |
| 14387 | pHdr = sqlite3MemsysGetHeader(p); |
| 14388 | assert( pHdr->iForeGuard==FOREGUARD ); /* Allocation is valid */ |
| 14389 | if( (pHdr->eType&eType)!=0 ){ |
| 14390 | rc = 0; |
| @@ -33010,10 +33012,29 @@ | |
| 33010 | sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_OVERFLOW, -iSize); |
| 33011 | sqlite3_free(p); |
| 33012 | } |
| 33013 | } |
| 33014 | |
| 33015 | /* |
| 33016 | ** Allocate a new page object initially associated with cache pCache. |
| 33017 | */ |
| 33018 | static PgHdr1 *pcache1AllocPage(PCache1 *pCache){ |
| 33019 | int nByte = sizeof(PgHdr1) + pCache->szPage; |
| @@ -33558,11 +33579,11 @@ | |
| 33558 | int nFree = 0; |
| 33559 | if( pcache1.pStart==0 ){ |
| 33560 | PgHdr1 *p; |
| 33561 | pcache1EnterMutex(); |
| 33562 | while( (nReq<0 || nFree<nReq) && (p=pcache1.pLruTail) ){ |
| 33563 | nFree += sqlite3MallocSize(PGHDR1_TO_PAGE(p)); |
| 33564 | pcache1PinPage(p); |
| 33565 | pcache1RemoveFromHash(p); |
| 33566 | pcache1FreePage(p); |
| 33567 | } |
| 33568 | pcache1LeaveMutex(); |
| @@ -35185,11 +35206,11 @@ | |
| 35185 | assert( eLock!=NO_LOCK || pagerUseWal(pPager)==0 ); |
| 35186 | if( isOpen(pPager->fd) ){ |
| 35187 | assert( pPager->eLock>=eLock ); |
| 35188 | rc = sqlite3OsUnlock(pPager->fd, eLock); |
| 35189 | if( pPager->eLock!=UNKNOWN_LOCK ){ |
| 35190 | pPager->eLock = eLock; |
| 35191 | } |
| 35192 | IOTRACE(("UNLOCK %p %d\n", pPager, eLock)) |
| 35193 | } |
| 35194 | return rc; |
| 35195 | } |
| @@ -35209,11 +35230,11 @@ | |
| 35209 | |
| 35210 | assert( eLock==SHARED_LOCK || eLock==RESERVED_LOCK || eLock==EXCLUSIVE_LOCK ); |
| 35211 | if( pPager->eLock<eLock || pPager->eLock==UNKNOWN_LOCK ){ |
| 35212 | rc = sqlite3OsLock(pPager->fd, eLock); |
| 35213 | if( rc==SQLITE_OK && (pPager->eLock!=UNKNOWN_LOCK||eLock==EXCLUSIVE_LOCK) ){ |
| 35214 | pPager->eLock = eLock; |
| 35215 | IOTRACE(("LOCK %p %d\n", pPager, eLock)) |
| 35216 | } |
| 35217 | } |
| 35218 | return rc; |
| 35219 | } |
| @@ -35636,10 +35657,18 @@ | |
| 35636 | if( SQLITE_OK!=(rc = read32bits(pPager->jfd, iHdrOff+20, &iSectorSize)) |
| 35637 | || SQLITE_OK!=(rc = read32bits(pPager->jfd, iHdrOff+24, &iPageSize)) |
| 35638 | ){ |
| 35639 | return rc; |
| 35640 | } |
| 35641 | |
| 35642 | /* Check that the values read from the page-size and sector-size fields |
| 35643 | ** are within range. To be 'in range', both values need to be a power |
| 35644 | ** of two greater than or equal to 512 or 32, and not greater than their |
| 35645 | ** respective compile time maximum limits. |
| @@ -37494,11 +37523,11 @@ | |
| 37494 | assert( pageSize==0 || (pageSize>=512 && pageSize<=SQLITE_MAX_PAGE_SIZE) ); |
| 37495 | if( (pPager->memDb==0 || pPager->dbSize==0) |
| 37496 | && sqlite3PcacheRefCount(pPager->pPCache)==0 |
| 37497 | && pageSize && pageSize!=(u32)pPager->pageSize |
| 37498 | ){ |
| 37499 | char *pNew; /* New temp space */ |
| 37500 | i64 nByte = 0; |
| 37501 | |
| 37502 | if( pPager->eState>PAGER_OPEN && isOpen(pPager->fd) ){ |
| 37503 | rc = sqlite3OsFileSize(pPager->fd, &nByte); |
| 37504 | } |
| @@ -37507,11 +37536,11 @@ | |
| 37507 | if( !pNew ) rc = SQLITE_NOMEM; |
| 37508 | } |
| 37509 | |
| 37510 | if( rc==SQLITE_OK ){ |
| 37511 | pager_reset(pPager); |
| 37512 | pPager->dbSize = nByte/pageSize; |
| 37513 | pPager->pageSize = pageSize; |
| 37514 | sqlite3PageFree(pPager->pTmpSpace); |
| 37515 | pPager->pTmpSpace = pNew; |
| 37516 | sqlite3PcacheSetPageSize(pPager->pPCache, pageSize); |
| 37517 | } |
| @@ -41910,11 +41939,11 @@ | |
| 41910 | |
| 41911 | /* If nTruncate is non-zero, this is a commit record. */ |
| 41912 | if( nTruncate ){ |
| 41913 | pWal->hdr.mxFrame = iFrame; |
| 41914 | pWal->hdr.nPage = nTruncate; |
| 41915 | pWal->hdr.szPage = (szPage&0xff00) | (szPage>>16); |
| 41916 | testcase( szPage<=32768 ); |
| 41917 | testcase( szPage>=65536 ); |
| 41918 | aFrameCksum[0] = pWal->hdr.aFrameCksum[0]; |
| 41919 | aFrameCksum[1] = pWal->hdr.aFrameCksum[1]; |
| 41920 | } |
| @@ -43337,11 +43366,11 @@ | |
| 43337 | rc = walIndexAppend(pWal, iFrame, pLast->pgno); |
| 43338 | } |
| 43339 | |
| 43340 | if( rc==SQLITE_OK ){ |
| 43341 | /* Update the private copy of the header. */ |
| 43342 | pWal->hdr.szPage = (szPage&0xff00) | (szPage>>16); |
| 43343 | testcase( szPage<=32768 ); |
| 43344 | testcase( szPage>=65536 ); |
| 43345 | pWal->hdr.mxFrame = iFrame; |
| 43346 | if( isCommit ){ |
| 43347 | pWal->hdr.iChange++; |
| @@ -45873,11 +45902,11 @@ | |
| 45873 | u16 pc; /* Address of a freeblock within pPage->aData[] */ |
| 45874 | u8 hdr; /* Offset to beginning of page header */ |
| 45875 | u8 *data; /* Equal to pPage->aData */ |
| 45876 | BtShared *pBt; /* The main btree structure */ |
| 45877 | int usableSize; /* Amount of usable space on each page */ |
| 45878 | int cellOffset; /* Offset from start of page to first cell pointer */ |
| 45879 | int nFree; /* Number of unused bytes on the page */ |
| 45880 | int top; /* First byte of the cell content area */ |
| 45881 | int iCellFirst; /* First allowable cell or freeblock offset */ |
| 45882 | int iCellLast; /* Last possible cell or freeblock offset */ |
| 45883 | |
| @@ -45988,11 +46017,11 @@ | |
| 45988 | data[hdr] = (char)flags; |
| 45989 | first = hdr + 8 + 4*((flags&PTF_LEAF)==0 ?1:0); |
| 45990 | memset(&data[hdr+1], 0, 4); |
| 45991 | data[hdr+7] = 0; |
| 45992 | put2byte(&data[hdr+5], pBt->usableSize); |
| 45993 | pPage->nFree = pBt->usableSize - first; |
| 45994 | decodeFlags(pPage, flags); |
| 45995 | pPage->hdrOffset = hdr; |
| 45996 | pPage->cellOffset = first; |
| 45997 | pPage->nOverflow = 0; |
| 45998 | assert( pBt->pageSize>=512 && pBt->pageSize<=65536 ); |
| @@ -46817,11 +46846,11 @@ | |
| 46817 | ){ |
| 46818 | goto page1_init_failed; |
| 46819 | } |
| 46820 | assert( (pageSize & 7)==0 ); |
| 46821 | usableSize = pageSize - page1[20]; |
| 46822 | if( pageSize!=pBt->pageSize ){ |
| 46823 | /* After reading the first page of the database assuming a page size |
| 46824 | ** of BtShared.pageSize, we have discovered that the page-size is |
| 46825 | ** actually pageSize. Unlock the database, leave pBt->pPage1 at |
| 46826 | ** zero and return SQLITE_OK. The caller will call this function |
| 46827 | ** again with the correct page-size. |
| @@ -46856,18 +46885,18 @@ | |
| 46856 | ** 2-byte pointer to the cell |
| 46857 | ** 4-byte child pointer |
| 46858 | ** 9-byte nKey value |
| 46859 | ** 4-byte nData value |
| 46860 | ** 4-byte overflow page pointer |
| 46861 | ** So a cell consists of a 2-byte poiner, a header which is as much as |
| 46862 | ** 17 bytes long, 0 to N bytes of payload, and an optional 4 byte overflow |
| 46863 | ** page pointer. |
| 46864 | */ |
| 46865 | pBt->maxLocal = (pBt->usableSize-12)*64/255 - 23; |
| 46866 | pBt->minLocal = (pBt->usableSize-12)*32/255 - 23; |
| 46867 | pBt->maxLeaf = pBt->usableSize - 35; |
| 46868 | pBt->minLeaf = (pBt->usableSize-12)*32/255 - 23; |
| 46869 | assert( pBt->maxLeaf + 23 <= MX_CELL_SIZE(pBt) ); |
| 46870 | pBt->pPage1 = pPage1; |
| 46871 | pBt->nPage = nPage; |
| 46872 | return SQLITE_OK; |
| 46873 | |
| @@ -46916,12 +46945,12 @@ | |
| 46916 | data = pP1->aData; |
| 46917 | rc = sqlite3PagerWrite(pP1->pDbPage); |
| 46918 | if( rc ) return rc; |
| 46919 | memcpy(data, zMagicHeader, sizeof(zMagicHeader)); |
| 46920 | assert( sizeof(zMagicHeader)==16 ); |
| 46921 | data[16] = (pBt->pageSize>>8)&0xff; |
| 46922 | data[17] = (pBt->pageSize>>16)&0xff; |
| 46923 | data[18] = 1; |
| 46924 | data[19] = 1; |
| 46925 | assert( pBt->usableSize<=pBt->pageSize && pBt->usableSize+255>=pBt->pageSize); |
| 46926 | data[20] = (u8)(pBt->pageSize - pBt->usableSize); |
| 46927 | data[21] = 64; |
| @@ -49599,11 +49628,11 @@ | |
| 49599 | BtShared *pBt = pPage->pBt; |
| 49600 | CellInfo info; |
| 49601 | Pgno ovflPgno; |
| 49602 | int rc; |
| 49603 | int nOvfl; |
| 49604 | u16 ovflPageSize; |
| 49605 | |
| 49606 | assert( sqlite3_mutex_held(pPage->pBt->mutex) ); |
| 49607 | btreeParseCellPtr(pPage, pCell, &info); |
| 49608 | if( info.iOverflow==0 ){ |
| 49609 | return SQLITE_OK; /* No overflow pages. Return without doing anything */ |
| @@ -50051,11 +50080,11 @@ | |
| 50051 | assert( sqlite3_mutex_held(pPage->pBt->mutex) ); |
| 50052 | assert( sqlite3PagerIswriteable(pParent->pDbPage) ); |
| 50053 | assert( pPage->nOverflow==1 ); |
| 50054 | |
| 50055 | /* This error condition is now caught prior to reaching this function */ |
| 50056 | if( NEVER(pPage->nCell<=0) ) return SQLITE_CORRUPT_BKPT; |
| 50057 | |
| 50058 | /* Allocate a new page. This page will become the right-sibling of |
| 50059 | ** pPage. Make the parent page writable, so that the new divider cell |
| 50060 | ** may be inserted. If both these operations are successful, proceed. |
| 50061 | */ |
| @@ -50459,11 +50488,11 @@ | |
| 50459 | u8 *pTemp; |
| 50460 | assert( nCell<nMaxCells ); |
| 50461 | szCell[nCell] = sz; |
| 50462 | pTemp = &aSpace1[iSpace1]; |
| 50463 | iSpace1 += sz; |
| 50464 | assert( sz<=pBt->pageSize/4 ); |
| 50465 | assert( iSpace1<=pBt->pageSize ); |
| 50466 | memcpy(pTemp, apDiv[i], sz); |
| 50467 | apCell[nCell] = pTemp+leafCorrection; |
| 50468 | assert( leafCorrection==0 || leafCorrection==4 ); |
| 50469 | szCell[nCell] = szCell[nCell] - leafCorrection; |
| @@ -50705,11 +50734,11 @@ | |
| 50705 | assert(leafCorrection==4); |
| 50706 | sz = cellSizePtr(pParent, pCell); |
| 50707 | } |
| 50708 | } |
| 50709 | iOvflSpace += sz; |
| 50710 | assert( sz<=pBt->pageSize/4 ); |
| 50711 | assert( iOvflSpace<=pBt->pageSize ); |
| 50712 | insertCell(pParent, nxDiv, pCell, sz, pTemp, pNew->pgno, &rc); |
| 50713 | if( rc!=SQLITE_OK ) goto balance_cleanup; |
| 50714 | assert( sqlite3PagerIswriteable(pParent->pDbPage) ); |
| 50715 | |
| @@ -52796,10 +52825,19 @@ | |
| 52796 | ** page sizes of the source and destination differ. |
| 52797 | */ |
| 52798 | if( nSrcPgsz!=nDestPgsz && sqlite3PagerIsMemdb(pDestPager) ){ |
| 52799 | rc = SQLITE_READONLY; |
| 52800 | } |
| 52801 | |
| 52802 | /* This loop runs once for each destination page spanned by the source |
| 52803 | ** page. For each iteration, variable iOff is set to the byte offset |
| 52804 | ** of the destination page. |
| 52805 | */ |
| @@ -68200,11 +68238,11 @@ | |
| 68200 | if( bOk==0 || i<1 || i>db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ){ |
| 68201 | sqlite3ErrorMsg(pParse, "variable number must be between ?1 and ?%d", |
| 68202 | db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER]); |
| 68203 | } |
| 68204 | if( i>pParse->nVar ){ |
| 68205 | pParse->nVar = i; |
| 68206 | } |
| 68207 | }else{ |
| 68208 | /* Wildcards like ":aaa", "$aaa" or "@aaa". Reuse the same variable |
| 68209 | ** number as the prior appearance of the same name, or if the name |
| 68210 | ** has never appeared before, reuse the same variable number |
| 68211 |
| --- src/sqlite3.c | |
| +++ src/sqlite3.c | |
| @@ -216,20 +216,22 @@ | |
| 216 | #endif |
| 217 | |
| 218 | /* Maximum page size. The upper bound on this value is 65536. This a limit |
| 219 | ** imposed by the use of 16-bit offsets within each page. |
| 220 | ** |
| 221 | ** Earlier versions of SQLite allowed the user to change this value at |
| 222 | ** compile time. This is no longer permitted, on the grounds that it creates |
| 223 | ** a library that is technically incompatible with an SQLite library |
| 224 | ** compiled with a different limit. If a process operating on a database |
| 225 | ** with a page-size of 65536 bytes crashes, then an instance of SQLite |
| 226 | ** compiled with the default page-size limit will not be able to rollback |
| 227 | ** the aborted transaction. This could lead to database corruption. |
| 228 | */ |
| 229 | #ifdef SQLITE_MAX_PAGE_SIZE |
| 230 | # undef SQLITE_MAX_PAGE_SIZE |
| 231 | #endif |
| 232 | #define SQLITE_MAX_PAGE_SIZE 65536 |
| 233 | |
| 234 | |
| 235 | /* |
| 236 | ** The default size of a database page. |
| 237 | */ |
| @@ -642,11 +644,11 @@ | |
| 644 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 645 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 646 | */ |
| 647 | #define SQLITE_VERSION "3.7.1" |
| 648 | #define SQLITE_VERSION_NUMBER 3007001 |
| 649 | #define SQLITE_SOURCE_ID "2010-08-20 15:32:21 5523ecd32295c188e3bf5dbd57d92d2879461e32" |
| 650 | |
| 651 | /* |
| 652 | ** CAPI3REF: Run-Time Library Version Numbers |
| 653 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 654 | ** |
| @@ -14339,11 +14341,11 @@ | |
| 14341 | |
| 14342 | /* |
| 14343 | ** Set the "type" of an allocation. |
| 14344 | */ |
| 14345 | SQLITE_PRIVATE void sqlite3MemdebugSetType(void *p, u8 eType){ |
| 14346 | if( p && sqlite3GlobalConfig.m.xMalloc==sqlite3MemMalloc ){ |
| 14347 | struct MemBlockHdr *pHdr; |
| 14348 | pHdr = sqlite3MemsysGetHeader(p); |
| 14349 | assert( pHdr->iForeGuard==FOREGUARD ); |
| 14350 | pHdr->eType = eType; |
| 14351 | } |
| @@ -14358,11 +14360,11 @@ | |
| 14360 | ** |
| 14361 | ** assert( sqlite3MemdebugHasType(p, MEMTYPE_DB) ); |
| 14362 | */ |
| 14363 | SQLITE_PRIVATE int sqlite3MemdebugHasType(void *p, u8 eType){ |
| 14364 | int rc = 1; |
| 14365 | if( p && sqlite3GlobalConfig.m.xMalloc==sqlite3MemMalloc ){ |
| 14366 | struct MemBlockHdr *pHdr; |
| 14367 | pHdr = sqlite3MemsysGetHeader(p); |
| 14368 | assert( pHdr->iForeGuard==FOREGUARD ); /* Allocation is valid */ |
| 14369 | if( (pHdr->eType&eType)==0 ){ |
| 14370 | rc = 0; |
| @@ -14380,11 +14382,11 @@ | |
| 14382 | ** |
| 14383 | ** assert( sqlite3MemdebugNoType(p, MEMTYPE_DB) ); |
| 14384 | */ |
| 14385 | SQLITE_PRIVATE int sqlite3MemdebugNoType(void *p, u8 eType){ |
| 14386 | int rc = 1; |
| 14387 | if( p && sqlite3GlobalConfig.m.xMalloc==sqlite3MemMalloc ){ |
| 14388 | struct MemBlockHdr *pHdr; |
| 14389 | pHdr = sqlite3MemsysGetHeader(p); |
| 14390 | assert( pHdr->iForeGuard==FOREGUARD ); /* Allocation is valid */ |
| 14391 | if( (pHdr->eType&eType)!=0 ){ |
| 14392 | rc = 0; |
| @@ -33010,10 +33012,29 @@ | |
| 33012 | sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_OVERFLOW, -iSize); |
| 33013 | sqlite3_free(p); |
| 33014 | } |
| 33015 | } |
| 33016 | |
| 33017 | #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT |
| 33018 | /* |
| 33019 | ** Return the size of a pache allocation |
| 33020 | */ |
| 33021 | static int pcache1MemSize(void *p){ |
| 33022 | assert( sqlite3_mutex_held(pcache1.mutex) ); |
| 33023 | if( p>=pcache1.pStart && p<pcache1.pEnd ){ |
| 33024 | return pcache1.szSlot; |
| 33025 | }else{ |
| 33026 | int iSize; |
| 33027 | assert( sqlite3MemdebugHasType(p, MEMTYPE_PCACHE) ); |
| 33028 | sqlite3MemdebugSetType(p, MEMTYPE_HEAP); |
| 33029 | iSize = sqlite3MallocSize(p); |
| 33030 | sqlite3MemdebugSetType(p, MEMTYPE_PCACHE); |
| 33031 | return iSize; |
| 33032 | } |
| 33033 | } |
| 33034 | #endif /* SQLITE_ENABLE_MEMORY_MANAGEMENT */ |
| 33035 | |
| 33036 | /* |
| 33037 | ** Allocate a new page object initially associated with cache pCache. |
| 33038 | */ |
| 33039 | static PgHdr1 *pcache1AllocPage(PCache1 *pCache){ |
| 33040 | int nByte = sizeof(PgHdr1) + pCache->szPage; |
| @@ -33558,11 +33579,11 @@ | |
| 33579 | int nFree = 0; |
| 33580 | if( pcache1.pStart==0 ){ |
| 33581 | PgHdr1 *p; |
| 33582 | pcache1EnterMutex(); |
| 33583 | while( (nReq<0 || nFree<nReq) && (p=pcache1.pLruTail) ){ |
| 33584 | nFree += pcache1MemSize(PGHDR1_TO_PAGE(p)); |
| 33585 | pcache1PinPage(p); |
| 33586 | pcache1RemoveFromHash(p); |
| 33587 | pcache1FreePage(p); |
| 33588 | } |
| 33589 | pcache1LeaveMutex(); |
| @@ -35185,11 +35206,11 @@ | |
| 35206 | assert( eLock!=NO_LOCK || pagerUseWal(pPager)==0 ); |
| 35207 | if( isOpen(pPager->fd) ){ |
| 35208 | assert( pPager->eLock>=eLock ); |
| 35209 | rc = sqlite3OsUnlock(pPager->fd, eLock); |
| 35210 | if( pPager->eLock!=UNKNOWN_LOCK ){ |
| 35211 | pPager->eLock = (u8)eLock; |
| 35212 | } |
| 35213 | IOTRACE(("UNLOCK %p %d\n", pPager, eLock)) |
| 35214 | } |
| 35215 | return rc; |
| 35216 | } |
| @@ -35209,11 +35230,11 @@ | |
| 35230 | |
| 35231 | assert( eLock==SHARED_LOCK || eLock==RESERVED_LOCK || eLock==EXCLUSIVE_LOCK ); |
| 35232 | if( pPager->eLock<eLock || pPager->eLock==UNKNOWN_LOCK ){ |
| 35233 | rc = sqlite3OsLock(pPager->fd, eLock); |
| 35234 | if( rc==SQLITE_OK && (pPager->eLock!=UNKNOWN_LOCK||eLock==EXCLUSIVE_LOCK) ){ |
| 35235 | pPager->eLock = (u8)eLock; |
| 35236 | IOTRACE(("LOCK %p %d\n", pPager, eLock)) |
| 35237 | } |
| 35238 | } |
| 35239 | return rc; |
| 35240 | } |
| @@ -35636,10 +35657,18 @@ | |
| 35657 | if( SQLITE_OK!=(rc = read32bits(pPager->jfd, iHdrOff+20, &iSectorSize)) |
| 35658 | || SQLITE_OK!=(rc = read32bits(pPager->jfd, iHdrOff+24, &iPageSize)) |
| 35659 | ){ |
| 35660 | return rc; |
| 35661 | } |
| 35662 | |
| 35663 | /* Versions of SQLite prior to 3.5.8 set the page-size field of the |
| 35664 | ** journal header to zero. In this case, assume that the Pager.pageSize |
| 35665 | ** variable is already set to the correct page size. |
| 35666 | */ |
| 35667 | if( iPageSize==0 ){ |
| 35668 | iPageSize = pPager->pageSize; |
| 35669 | } |
| 35670 | |
| 35671 | /* Check that the values read from the page-size and sector-size fields |
| 35672 | ** are within range. To be 'in range', both values need to be a power |
| 35673 | ** of two greater than or equal to 512 or 32, and not greater than their |
| 35674 | ** respective compile time maximum limits. |
| @@ -37494,11 +37523,11 @@ | |
| 37523 | assert( pageSize==0 || (pageSize>=512 && pageSize<=SQLITE_MAX_PAGE_SIZE) ); |
| 37524 | if( (pPager->memDb==0 || pPager->dbSize==0) |
| 37525 | && sqlite3PcacheRefCount(pPager->pPCache)==0 |
| 37526 | && pageSize && pageSize!=(u32)pPager->pageSize |
| 37527 | ){ |
| 37528 | char *pNew = NULL; /* New temp space */ |
| 37529 | i64 nByte = 0; |
| 37530 | |
| 37531 | if( pPager->eState>PAGER_OPEN && isOpen(pPager->fd) ){ |
| 37532 | rc = sqlite3OsFileSize(pPager->fd, &nByte); |
| 37533 | } |
| @@ -37507,11 +37536,11 @@ | |
| 37536 | if( !pNew ) rc = SQLITE_NOMEM; |
| 37537 | } |
| 37538 | |
| 37539 | if( rc==SQLITE_OK ){ |
| 37540 | pager_reset(pPager); |
| 37541 | pPager->dbSize = (Pgno)(nByte/pageSize); |
| 37542 | pPager->pageSize = pageSize; |
| 37543 | sqlite3PageFree(pPager->pTmpSpace); |
| 37544 | pPager->pTmpSpace = pNew; |
| 37545 | sqlite3PcacheSetPageSize(pPager->pPCache, pageSize); |
| 37546 | } |
| @@ -41910,11 +41939,11 @@ | |
| 41939 | |
| 41940 | /* If nTruncate is non-zero, this is a commit record. */ |
| 41941 | if( nTruncate ){ |
| 41942 | pWal->hdr.mxFrame = iFrame; |
| 41943 | pWal->hdr.nPage = nTruncate; |
| 41944 | pWal->hdr.szPage = (u16)((szPage&0xff00) | (szPage>>16)); |
| 41945 | testcase( szPage<=32768 ); |
| 41946 | testcase( szPage>=65536 ); |
| 41947 | aFrameCksum[0] = pWal->hdr.aFrameCksum[0]; |
| 41948 | aFrameCksum[1] = pWal->hdr.aFrameCksum[1]; |
| 41949 | } |
| @@ -43337,11 +43366,11 @@ | |
| 43366 | rc = walIndexAppend(pWal, iFrame, pLast->pgno); |
| 43367 | } |
| 43368 | |
| 43369 | if( rc==SQLITE_OK ){ |
| 43370 | /* Update the private copy of the header. */ |
| 43371 | pWal->hdr.szPage = (u16)((szPage&0xff00) | (szPage>>16)); |
| 43372 | testcase( szPage<=32768 ); |
| 43373 | testcase( szPage>=65536 ); |
| 43374 | pWal->hdr.mxFrame = iFrame; |
| 43375 | if( isCommit ){ |
| 43376 | pWal->hdr.iChange++; |
| @@ -45873,11 +45902,11 @@ | |
| 45902 | u16 pc; /* Address of a freeblock within pPage->aData[] */ |
| 45903 | u8 hdr; /* Offset to beginning of page header */ |
| 45904 | u8 *data; /* Equal to pPage->aData */ |
| 45905 | BtShared *pBt; /* The main btree structure */ |
| 45906 | int usableSize; /* Amount of usable space on each page */ |
| 45907 | u16 cellOffset; /* Offset from start of page to first cell pointer */ |
| 45908 | int nFree; /* Number of unused bytes on the page */ |
| 45909 | int top; /* First byte of the cell content area */ |
| 45910 | int iCellFirst; /* First allowable cell or freeblock offset */ |
| 45911 | int iCellLast; /* Last possible cell or freeblock offset */ |
| 45912 | |
| @@ -45988,11 +46017,11 @@ | |
| 46017 | data[hdr] = (char)flags; |
| 46018 | first = hdr + 8 + 4*((flags&PTF_LEAF)==0 ?1:0); |
| 46019 | memset(&data[hdr+1], 0, 4); |
| 46020 | data[hdr+7] = 0; |
| 46021 | put2byte(&data[hdr+5], pBt->usableSize); |
| 46022 | pPage->nFree = (u16)(pBt->usableSize - first); |
| 46023 | decodeFlags(pPage, flags); |
| 46024 | pPage->hdrOffset = hdr; |
| 46025 | pPage->cellOffset = first; |
| 46026 | pPage->nOverflow = 0; |
| 46027 | assert( pBt->pageSize>=512 && pBt->pageSize<=65536 ); |
| @@ -46817,11 +46846,11 @@ | |
| 46846 | ){ |
| 46847 | goto page1_init_failed; |
| 46848 | } |
| 46849 | assert( (pageSize & 7)==0 ); |
| 46850 | usableSize = pageSize - page1[20]; |
| 46851 | if( (u32)pageSize!=pBt->pageSize ){ |
| 46852 | /* After reading the first page of the database assuming a page size |
| 46853 | ** of BtShared.pageSize, we have discovered that the page-size is |
| 46854 | ** actually pageSize. Unlock the database, leave pBt->pPage1 at |
| 46855 | ** zero and return SQLITE_OK. The caller will call this function |
| 46856 | ** again with the correct page-size. |
| @@ -46856,18 +46885,18 @@ | |
| 46885 | ** 2-byte pointer to the cell |
| 46886 | ** 4-byte child pointer |
| 46887 | ** 9-byte nKey value |
| 46888 | ** 4-byte nData value |
| 46889 | ** 4-byte overflow page pointer |
| 46890 | ** So a cell consists of a 2-byte pointer, a header which is as much as |
| 46891 | ** 17 bytes long, 0 to N bytes of payload, and an optional 4 byte overflow |
| 46892 | ** page pointer. |
| 46893 | */ |
| 46894 | pBt->maxLocal = (u16)((pBt->usableSize-12)*64/255 - 23); |
| 46895 | pBt->minLocal = (u16)((pBt->usableSize-12)*32/255 - 23); |
| 46896 | pBt->maxLeaf = (u16)(pBt->usableSize - 35); |
| 46897 | pBt->minLeaf = (u16)((pBt->usableSize-12)*32/255 - 23); |
| 46898 | assert( pBt->maxLeaf + 23 <= MX_CELL_SIZE(pBt) ); |
| 46899 | pBt->pPage1 = pPage1; |
| 46900 | pBt->nPage = nPage; |
| 46901 | return SQLITE_OK; |
| 46902 | |
| @@ -46916,12 +46945,12 @@ | |
| 46945 | data = pP1->aData; |
| 46946 | rc = sqlite3PagerWrite(pP1->pDbPage); |
| 46947 | if( rc ) return rc; |
| 46948 | memcpy(data, zMagicHeader, sizeof(zMagicHeader)); |
| 46949 | assert( sizeof(zMagicHeader)==16 ); |
| 46950 | data[16] = (u8)((pBt->pageSize>>8)&0xff); |
| 46951 | data[17] = (u8)((pBt->pageSize>>16)&0xff); |
| 46952 | data[18] = 1; |
| 46953 | data[19] = 1; |
| 46954 | assert( pBt->usableSize<=pBt->pageSize && pBt->usableSize+255>=pBt->pageSize); |
| 46955 | data[20] = (u8)(pBt->pageSize - pBt->usableSize); |
| 46956 | data[21] = 64; |
| @@ -49599,11 +49628,11 @@ | |
| 49628 | BtShared *pBt = pPage->pBt; |
| 49629 | CellInfo info; |
| 49630 | Pgno ovflPgno; |
| 49631 | int rc; |
| 49632 | int nOvfl; |
| 49633 | u32 ovflPageSize; |
| 49634 | |
| 49635 | assert( sqlite3_mutex_held(pPage->pBt->mutex) ); |
| 49636 | btreeParseCellPtr(pPage, pCell, &info); |
| 49637 | if( info.iOverflow==0 ){ |
| 49638 | return SQLITE_OK; /* No overflow pages. Return without doing anything */ |
| @@ -50051,11 +50080,11 @@ | |
| 50080 | assert( sqlite3_mutex_held(pPage->pBt->mutex) ); |
| 50081 | assert( sqlite3PagerIswriteable(pParent->pDbPage) ); |
| 50082 | assert( pPage->nOverflow==1 ); |
| 50083 | |
| 50084 | /* This error condition is now caught prior to reaching this function */ |
| 50085 | if( pPage->nCell<=0 ) return SQLITE_CORRUPT_BKPT; |
| 50086 | |
| 50087 | /* Allocate a new page. This page will become the right-sibling of |
| 50088 | ** pPage. Make the parent page writable, so that the new divider cell |
| 50089 | ** may be inserted. If both these operations are successful, proceed. |
| 50090 | */ |
| @@ -50459,11 +50488,11 @@ | |
| 50488 | u8 *pTemp; |
| 50489 | assert( nCell<nMaxCells ); |
| 50490 | szCell[nCell] = sz; |
| 50491 | pTemp = &aSpace1[iSpace1]; |
| 50492 | iSpace1 += sz; |
| 50493 | assert( sz<=pBt->maxLocal+23 ); |
| 50494 | assert( iSpace1<=pBt->pageSize ); |
| 50495 | memcpy(pTemp, apDiv[i], sz); |
| 50496 | apCell[nCell] = pTemp+leafCorrection; |
| 50497 | assert( leafCorrection==0 || leafCorrection==4 ); |
| 50498 | szCell[nCell] = szCell[nCell] - leafCorrection; |
| @@ -50705,11 +50734,11 @@ | |
| 50734 | assert(leafCorrection==4); |
| 50735 | sz = cellSizePtr(pParent, pCell); |
| 50736 | } |
| 50737 | } |
| 50738 | iOvflSpace += sz; |
| 50739 | assert( sz<=pBt->maxLocal+23 ); |
| 50740 | assert( iOvflSpace<=pBt->pageSize ); |
| 50741 | insertCell(pParent, nxDiv, pCell, sz, pTemp, pNew->pgno, &rc); |
| 50742 | if( rc!=SQLITE_OK ) goto balance_cleanup; |
| 50743 | assert( sqlite3PagerIswriteable(pParent->pDbPage) ); |
| 50744 | |
| @@ -52796,10 +52825,19 @@ | |
| 52825 | ** page sizes of the source and destination differ. |
| 52826 | */ |
| 52827 | if( nSrcPgsz!=nDestPgsz && sqlite3PagerIsMemdb(pDestPager) ){ |
| 52828 | rc = SQLITE_READONLY; |
| 52829 | } |
| 52830 | |
| 52831 | #ifdef SQLITE_HAS_CODEC |
| 52832 | /* Backup is not possible if the page size of the destination is changing |
| 52833 | ** a a codec is in use. |
| 52834 | */ |
| 52835 | if( nSrcPgsz!=nDestPgsz && sqlite3PagerGetCodec(pDestPager)!=0 ){ |
| 52836 | rc = SQLITE_READONLY; |
| 52837 | } |
| 52838 | #endif |
| 52839 | |
| 52840 | /* This loop runs once for each destination page spanned by the source |
| 52841 | ** page. For each iteration, variable iOff is set to the byte offset |
| 52842 | ** of the destination page. |
| 52843 | */ |
| @@ -68200,11 +68238,11 @@ | |
| 68238 | if( bOk==0 || i<1 || i>db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ){ |
| 68239 | sqlite3ErrorMsg(pParse, "variable number must be between ?1 and ?%d", |
| 68240 | db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER]); |
| 68241 | } |
| 68242 | if( i>pParse->nVar ){ |
| 68243 | pParse->nVar = (int)i; |
| 68244 | } |
| 68245 | }else{ |
| 68246 | /* Wildcards like ":aaa", "$aaa" or "@aaa". Reuse the same variable |
| 68247 | ** number as the prior appearance of the same name, or if the name |
| 68248 | ** has never appeared before, reuse the same variable number |
| 68249 |
+1
-1
| --- src/sqlite3.h | ||
| +++ src/sqlite3.h | ||
| @@ -107,11 +107,11 @@ | ||
| 107 | 107 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 108 | 108 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 109 | 109 | */ |
| 110 | 110 | #define SQLITE_VERSION "3.7.1" |
| 111 | 111 | #define SQLITE_VERSION_NUMBER 3007001 |
| 112 | -#define SQLITE_SOURCE_ID "2010-08-17 19:49:14 acb171d4cfef2fec8833f761019f5c81f0d138a0" | |
| 112 | +#define SQLITE_SOURCE_ID "2010-08-20 15:32:21 5523ecd32295c188e3bf5dbd57d92d2879461e32" | |
| 113 | 113 | |
| 114 | 114 | /* |
| 115 | 115 | ** CAPI3REF: Run-Time Library Version Numbers |
| 116 | 116 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 117 | 117 | ** |
| 118 | 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.7.1" |
| 111 | #define SQLITE_VERSION_NUMBER 3007001 |
| 112 | #define SQLITE_SOURCE_ID "2010-08-17 19:49:14 acb171d4cfef2fec8833f761019f5c81f0d138a0" |
| 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.7.1" |
| 111 | #define SQLITE_VERSION_NUMBER 3007001 |
| 112 | #define SQLITE_SOURCE_ID "2010-08-20 15:32:21 5523ecd32295c188e3bf5dbd57d92d2879461e32" |
| 113 | |
| 114 | /* |
| 115 | ** CAPI3REF: Run-Time Library Version Numbers |
| 116 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 117 | ** |
| 118 |