| | @@ -657,11 +657,11 @@ |
| 657 | 657 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 658 | 658 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 659 | 659 | */ |
| 660 | 660 | #define SQLITE_VERSION "3.7.10" |
| 661 | 661 | #define SQLITE_VERSION_NUMBER 3007010 |
| 662 | | -#define SQLITE_SOURCE_ID "2012-01-05 12:38:02 1378f905d37544701776d38987fe7a312b255983" |
| 662 | +#define SQLITE_SOURCE_ID "2012-01-11 16:16:08 9e31a275ef494ea8713a1d60a15b84157e57c3ff" |
| 663 | 663 | |
| 664 | 664 | /* |
| 665 | 665 | ** CAPI3REF: Run-Time Library Version Numbers |
| 666 | 666 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 667 | 667 | ** |
| | @@ -9396,17 +9396,19 @@ |
| 9396 | 9396 | SQLITE_PRIVATE int sqlite3OsFileSize(sqlite3_file*, i64 *pSize); |
| 9397 | 9397 | SQLITE_PRIVATE int sqlite3OsLock(sqlite3_file*, int); |
| 9398 | 9398 | SQLITE_PRIVATE int sqlite3OsUnlock(sqlite3_file*, int); |
| 9399 | 9399 | SQLITE_PRIVATE int sqlite3OsCheckReservedLock(sqlite3_file *id, int *pResOut); |
| 9400 | 9400 | SQLITE_PRIVATE int sqlite3OsFileControl(sqlite3_file*,int,void*); |
| 9401 | +SQLITE_PRIVATE void sqlite3OsFileControlHint(sqlite3_file*,int,void*); |
| 9401 | 9402 | #define SQLITE_FCNTL_DB_UNCHANGED 0xca093fa0 |
| 9402 | 9403 | SQLITE_PRIVATE int sqlite3OsSectorSize(sqlite3_file *id); |
| 9403 | 9404 | SQLITE_PRIVATE int sqlite3OsDeviceCharacteristics(sqlite3_file *id); |
| 9404 | 9405 | SQLITE_PRIVATE int sqlite3OsShmMap(sqlite3_file *,int,int,int,void volatile **); |
| 9405 | 9406 | SQLITE_PRIVATE int sqlite3OsShmLock(sqlite3_file *id, int, int, int); |
| 9406 | 9407 | SQLITE_PRIVATE void sqlite3OsShmBarrier(sqlite3_file *id); |
| 9407 | 9408 | SQLITE_PRIVATE int sqlite3OsShmUnmap(sqlite3_file *id, int); |
| 9409 | + |
| 9408 | 9410 | |
| 9409 | 9411 | /* |
| 9410 | 9412 | ** Functions for accessing sqlite3_vfs methods |
| 9411 | 9413 | */ |
| 9412 | 9414 | SQLITE_PRIVATE int sqlite3OsOpen(sqlite3_vfs *, const char *, sqlite3_file*, int, int *); |
| | @@ -13244,12 +13246,14 @@ |
| 13244 | 13246 | #endif |
| 13245 | 13247 | SQLITE_PRIVATE int sqlite3VdbeMemHandleBom(Mem *pMem); |
| 13246 | 13248 | |
| 13247 | 13249 | #ifndef SQLITE_OMIT_INCRBLOB |
| 13248 | 13250 | SQLITE_PRIVATE int sqlite3VdbeMemExpandBlob(Mem *); |
| 13251 | + #define ExpandBlob(P) (((P)->flags&MEM_Zero)?sqlite3VdbeMemExpandBlob(P):0) |
| 13249 | 13252 | #else |
| 13250 | 13253 | #define sqlite3VdbeMemExpandBlob(x) SQLITE_OK |
| 13254 | + #define ExpandBlob(P) SQLITE_OK |
| 13251 | 13255 | #endif |
| 13252 | 13256 | |
| 13253 | 13257 | #endif /* !defined(_VDBEINT_H_) */ |
| 13254 | 13258 | |
| 13255 | 13259 | /************** End of vdbeInt.h *********************************************/ |
| | @@ -14715,14 +14719,27 @@ |
| 14715 | 14719 | } |
| 14716 | 14720 | SQLITE_PRIVATE int sqlite3OsCheckReservedLock(sqlite3_file *id, int *pResOut){ |
| 14717 | 14721 | DO_OS_MALLOC_TEST(id); |
| 14718 | 14722 | return id->pMethods->xCheckReservedLock(id, pResOut); |
| 14719 | 14723 | } |
| 14724 | + |
| 14725 | +/* |
| 14726 | +** Use sqlite3OsFileControl() when we are doing something that might fail |
| 14727 | +** and we need to know about the failures. Use sqlite3OsFileControlHint() |
| 14728 | +** when simply tossing information over the wall to the VFS and we do not |
| 14729 | +** really care if the VFS receives and understands the information since it |
| 14730 | +** is only a hint and can be safely ignored. The sqlite3OsFileControlHint() |
| 14731 | +** routine has no return value since the return value would be meaningless. |
| 14732 | +*/ |
| 14720 | 14733 | SQLITE_PRIVATE int sqlite3OsFileControl(sqlite3_file *id, int op, void *pArg){ |
| 14721 | 14734 | DO_OS_MALLOC_TEST(id); |
| 14722 | 14735 | return id->pMethods->xFileControl(id, op, pArg); |
| 14723 | 14736 | } |
| 14737 | +SQLITE_PRIVATE void sqlite3OsFileControlHint(sqlite3_file *id, int op, void *pArg){ |
| 14738 | + (void)id->pMethods->xFileControl(id, op, pArg); |
| 14739 | +} |
| 14740 | + |
| 14724 | 14741 | SQLITE_PRIVATE int sqlite3OsSectorSize(sqlite3_file *id){ |
| 14725 | 14742 | int (*xSectorSize)(sqlite3_file*) = id->pMethods->xSectorSize; |
| 14726 | 14743 | return (xSectorSize ? xSectorSize(id) : SQLITE_DEFAULT_SECTOR_SIZE); |
| 14727 | 14744 | } |
| 14728 | 14745 | SQLITE_PRIVATE int sqlite3OsDeviceCharacteristics(sqlite3_file *id){ |
| | @@ -14769,10 +14786,11 @@ |
| 14769 | 14786 | assert( rc==SQLITE_OK || pFile->pMethods==0 ); |
| 14770 | 14787 | return rc; |
| 14771 | 14788 | } |
| 14772 | 14789 | SQLITE_PRIVATE int sqlite3OsDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){ |
| 14773 | 14790 | DO_OS_MALLOC_TEST(0); |
| 14791 | + assert( dirSync==0 || dirSync==1 ); |
| 14774 | 14792 | return pVfs->xDelete(pVfs, zPath, dirSync); |
| 14775 | 14793 | } |
| 14776 | 14794 | SQLITE_PRIVATE int sqlite3OsAccess( |
| 14777 | 14795 | sqlite3_vfs *pVfs, |
| 14778 | 14796 | const char *zPath, |
| | @@ -22113,31 +22131,26 @@ |
| 22113 | 22131 | ** characters of the original suffix. |
| 22114 | 22132 | ** |
| 22115 | 22133 | ** If SQLITE_ENABLE_8_3_NAMES is set to 2 at compile-time, then always |
| 22116 | 22134 | ** do the suffix shortening regardless of URI parameter. |
| 22117 | 22135 | ** |
| 22118 | | -** Assume that zBaseFilename contains two \000 terminator bytes (so that |
| 22119 | | -** it can be harmlessly passed into sqlite3_uri_parameter()) and copy both |
| 22120 | | -** zero terminator bytes into the end of the revised name. |
| 22121 | | -** |
| 22122 | 22136 | ** Examples: |
| 22123 | 22137 | ** |
| 22124 | 22138 | ** test.db-journal => test.nal |
| 22125 | 22139 | ** test.db-wal => test.wal |
| 22126 | 22140 | ** test.db-shm => test.shm |
| 22127 | 22141 | ** test.db-mj7f3319fa => test.9fa |
| 22128 | 22142 | */ |
| 22129 | 22143 | SQLITE_PRIVATE void sqlite3FileSuffix3(const char *zBaseFilename, char *z){ |
| 22130 | | - assert( zBaseFilename[strlen(zBaseFilename)+1]==0 ); |
| 22131 | 22144 | #if SQLITE_ENABLE_8_3_NAMES<2 |
| 22132 | 22145 | if( sqlite3_uri_boolean(zBaseFilename, "8_3_names", 0) ) |
| 22133 | 22146 | #endif |
| 22134 | 22147 | { |
| 22135 | 22148 | int i, sz; |
| 22136 | 22149 | sz = sqlite3Strlen30(z); |
| 22137 | 22150 | for(i=sz-1; i>0 && z[i]!='/' && z[i]!='.'; i--){} |
| 22138 | | - if( z[i]=='.' && ALWAYS(sz>i+4) ) memmove(&z[i+1], &z[sz-3], 5); |
| 22151 | + if( z[i]=='.' && ALWAYS(sz>i+4) ) memmove(&z[i+1], &z[sz-3], 4); |
| 22139 | 22152 | } |
| 22140 | 22153 | } |
| 22141 | 22154 | #endif |
| 22142 | 22155 | |
| 22143 | 22156 | /************** End of util.c ************************************************/ |
| | @@ -24941,11 +24954,10 @@ |
| 24941 | 24954 | #endif |
| 24942 | 24955 | #if SQLITE_ENABLE_LOCKING_STYLE || defined(__APPLE__) |
| 24943 | 24956 | unsigned fsFlags; /* cached details from statfs() */ |
| 24944 | 24957 | #endif |
| 24945 | 24958 | #if OS_VXWORKS |
| 24946 | | - int isDelete; /* Delete on close if true */ |
| 24947 | 24959 | struct vxworksFileId *pId; /* Unique file ID */ |
| 24948 | 24960 | #endif |
| 24949 | 24961 | #ifndef NDEBUG |
| 24950 | 24962 | /* The next group of variables are used to track whether or not the |
| 24951 | 24963 | ** transaction counter in bytes 24-27 of database files are updated |
| | @@ -24976,10 +24988,13 @@ |
| 24976 | 24988 | # define UNIXFILE_DIRSYNC 0x08 /* Directory sync needed */ |
| 24977 | 24989 | #else |
| 24978 | 24990 | # define UNIXFILE_DIRSYNC 0x00 |
| 24979 | 24991 | #endif |
| 24980 | 24992 | #define UNIXFILE_PSOW 0x10 /* SQLITE_IOCAP_POWERSAFE_OVERWRITE */ |
| 24993 | +#define UNIXFILE_DELETE 0x20 /* Delete on close */ |
| 24994 | +#define UNIXFILE_URI 0x40 /* Filename might have query parameters */ |
| 24995 | +#define UNIXFILE_NOLOCK 0x80 /* Do no file locking */ |
| 24981 | 24996 | |
| 24982 | 24997 | /* |
| 24983 | 24998 | ** Include code that is common to all os_*.c files |
| 24984 | 24999 | */ |
| 24985 | 25000 | /************** Include os_common.h in the middle of os_unix.c ***************/ |
| | @@ -26689,11 +26704,11 @@ |
| 26689 | 26704 | robust_close(pFile, pFile->h, __LINE__); |
| 26690 | 26705 | pFile->h = -1; |
| 26691 | 26706 | } |
| 26692 | 26707 | #if OS_VXWORKS |
| 26693 | 26708 | if( pFile->pId ){ |
| 26694 | | - if( pFile->isDelete ){ |
| 26709 | + if( pFile->ctrlFlags & UNIXFILE_DELETE ){ |
| 26695 | 26710 | osUnlink(pFile->pId->zCanonicalName); |
| 26696 | 26711 | } |
| 26697 | 26712 | vxworksReleaseFileId(pFile->pId); |
| 26698 | 26713 | pFile->pId = 0; |
| 26699 | 26714 | } |
| | @@ -28796,11 +28811,11 @@ |
| 28796 | 28811 | pShmNode = sqlite3_malloc( sizeof(*pShmNode) + nShmFilename ); |
| 28797 | 28812 | if( pShmNode==0 ){ |
| 28798 | 28813 | rc = SQLITE_NOMEM; |
| 28799 | 28814 | goto shm_open_err; |
| 28800 | 28815 | } |
| 28801 | | - memset(pShmNode, 0, sizeof(*pShmNode)); |
| 28816 | + memset(pShmNode, 0, sizeof(*pShmNode)+nShmFilename); |
| 28802 | 28817 | zShmFilename = pShmNode->zFilename = (char*)&pShmNode[1]; |
| 28803 | 28818 | #ifdef SQLITE_SHM_DIRECTORY |
| 28804 | 28819 | sqlite3_snprintf(nShmFilename, zShmFilename, |
| 28805 | 28820 | SQLITE_SHM_DIRECTORY "/sqlite-shm-%x-%x", |
| 28806 | 28821 | (u32)sStat.st_ino, (u32)sStat.st_dev); |
| | @@ -29479,28 +29494,20 @@ |
| 29479 | 29494 | ** Initialize the contents of the unixFile structure pointed to by pId. |
| 29480 | 29495 | */ |
| 29481 | 29496 | static int fillInUnixFile( |
| 29482 | 29497 | sqlite3_vfs *pVfs, /* Pointer to vfs object */ |
| 29483 | 29498 | int h, /* Open file descriptor of file being opened */ |
| 29484 | | - int syncDir, /* True to sync directory on first sync */ |
| 29485 | 29499 | sqlite3_file *pId, /* Write to the unixFile structure here */ |
| 29486 | 29500 | const char *zFilename, /* Name of the file being opened */ |
| 29487 | | - int noLock, /* Omit locking if true */ |
| 29488 | | - int isDelete, /* Delete on close if true */ |
| 29489 | | - int isReadOnly /* True if the file is opened read-only */ |
| 29501 | + int ctrlFlags /* Zero or more UNIXFILE_* values */ |
| 29490 | 29502 | ){ |
| 29491 | 29503 | const sqlite3_io_methods *pLockingStyle; |
| 29492 | 29504 | unixFile *pNew = (unixFile *)pId; |
| 29493 | 29505 | int rc = SQLITE_OK; |
| 29494 | 29506 | |
| 29495 | 29507 | assert( pNew->pInode==NULL ); |
| 29496 | 29508 | |
| 29497 | | - /* Parameter isDelete is only used on vxworks. Express this explicitly |
| 29498 | | - ** here to prevent compiler warnings about unused parameters. |
| 29499 | | - */ |
| 29500 | | - UNUSED_PARAMETER(isDelete); |
| 29501 | | - |
| 29502 | 29509 | /* Usually the path zFilename should not be a relative pathname. The |
| 29503 | 29510 | ** exception is when opening the proxy "conch" file in builds that |
| 29504 | 29511 | ** include the special Apple locking styles. |
| 29505 | 29512 | */ |
| 29506 | 29513 | #if defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE |
| | @@ -29509,39 +29516,34 @@ |
| 29509 | 29516 | #else |
| 29510 | 29517 | assert( zFilename==0 || zFilename[0]=='/' ); |
| 29511 | 29518 | #endif |
| 29512 | 29519 | |
| 29513 | 29520 | /* No locking occurs in temporary files */ |
| 29514 | | - assert( zFilename!=0 || noLock ); |
| 29521 | + assert( zFilename!=0 || (ctrlFlags & UNIXFILE_NOLOCK)!=0 ); |
| 29515 | 29522 | |
| 29516 | 29523 | OSTRACE(("OPEN %-3d %s\n", h, zFilename)); |
| 29517 | 29524 | pNew->h = h; |
| 29518 | 29525 | pNew->pVfs = pVfs; |
| 29519 | 29526 | pNew->zPath = zFilename; |
| 29520 | | - pNew->ctrlFlags = 0; |
| 29521 | | - if( sqlite3_uri_boolean(zFilename, "psow", SQLITE_POWERSAFE_OVERWRITE) ){ |
| 29527 | + pNew->ctrlFlags = (u8)ctrlFlags; |
| 29528 | + if( sqlite3_uri_boolean(((ctrlFlags & UNIXFILE_URI) ? zFilename : 0), |
| 29529 | + "psow", SQLITE_POWERSAFE_OVERWRITE) ){ |
| 29522 | 29530 | pNew->ctrlFlags |= UNIXFILE_PSOW; |
| 29523 | 29531 | } |
| 29524 | 29532 | if( memcmp(pVfs->zName,"unix-excl",10)==0 ){ |
| 29525 | 29533 | pNew->ctrlFlags |= UNIXFILE_EXCL; |
| 29526 | 29534 | } |
| 29527 | | - if( isReadOnly ){ |
| 29528 | | - pNew->ctrlFlags |= UNIXFILE_RDONLY; |
| 29529 | | - } |
| 29530 | | - if( syncDir ){ |
| 29531 | | - pNew->ctrlFlags |= UNIXFILE_DIRSYNC; |
| 29532 | | - } |
| 29533 | 29535 | |
| 29534 | 29536 | #if OS_VXWORKS |
| 29535 | 29537 | pNew->pId = vxworksFindFileId(zFilename); |
| 29536 | 29538 | if( pNew->pId==0 ){ |
| 29537 | | - noLock = 1; |
| 29539 | + ctrlFlags |= UNIXFILE_NOLOCK; |
| 29538 | 29540 | rc = SQLITE_NOMEM; |
| 29539 | 29541 | } |
| 29540 | 29542 | #endif |
| 29541 | 29543 | |
| 29542 | | - if( noLock ){ |
| 29544 | + if( ctrlFlags & UNIXFILE_NOLOCK ){ |
| 29543 | 29545 | pLockingStyle = &nolockIoMethods; |
| 29544 | 29546 | }else{ |
| 29545 | 29547 | pLockingStyle = (**(finder_type*)pVfs->pAppData)(zFilename, pNew); |
| 29546 | 29548 | #if SQLITE_ENABLE_LOCKING_STYLE |
| 29547 | 29549 | /* Cache zFilename in the locking context (AFP and dotlock override) for |
| | @@ -29658,11 +29660,11 @@ |
| 29658 | 29660 | if( h>=0 ) robust_close(pNew, h, __LINE__); |
| 29659 | 29661 | h = -1; |
| 29660 | 29662 | osUnlink(zFilename); |
| 29661 | 29663 | isDelete = 0; |
| 29662 | 29664 | } |
| 29663 | | - pNew->isDelete = isDelete; |
| 29665 | + if( isDelete ) pNew->ctrlFlags |= UNIXFILE_DELETE; |
| 29664 | 29666 | #endif |
| 29665 | 29667 | if( rc!=SQLITE_OK ){ |
| 29666 | 29668 | if( h>=0 ) robust_close(pNew, h, __LINE__); |
| 29667 | 29669 | }else{ |
| 29668 | 29670 | pNew->pMethod = pLockingStyle; |
| | @@ -29723,22 +29725,23 @@ |
| 29723 | 29725 | if( zDir==0 ) zDir = "."; |
| 29724 | 29726 | |
| 29725 | 29727 | /* Check that the output buffer is large enough for the temporary file |
| 29726 | 29728 | ** name. If it is not, return SQLITE_ERROR. |
| 29727 | 29729 | */ |
| 29728 | | - if( (strlen(zDir) + strlen(SQLITE_TEMP_FILE_PREFIX) + 17) >= (size_t)nBuf ){ |
| 29730 | + if( (strlen(zDir) + strlen(SQLITE_TEMP_FILE_PREFIX) + 18) >= (size_t)nBuf ){ |
| 29729 | 29731 | return SQLITE_ERROR; |
| 29730 | 29732 | } |
| 29731 | 29733 | |
| 29732 | 29734 | do{ |
| 29733 | | - sqlite3_snprintf(nBuf-17, zBuf, "%s/"SQLITE_TEMP_FILE_PREFIX, zDir); |
| 29735 | + sqlite3_snprintf(nBuf-18, zBuf, "%s/"SQLITE_TEMP_FILE_PREFIX, zDir); |
| 29734 | 29736 | j = (int)strlen(zBuf); |
| 29735 | 29737 | sqlite3_randomness(15, &zBuf[j]); |
| 29736 | 29738 | for(i=0; i<15; i++, j++){ |
| 29737 | 29739 | zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ]; |
| 29738 | 29740 | } |
| 29739 | 29741 | zBuf[j] = 0; |
| 29742 | + zBuf[j+1] = 0; |
| 29740 | 29743 | }while( osAccess(zBuf,0)==0 ); |
| 29741 | 29744 | return SQLITE_OK; |
| 29742 | 29745 | } |
| 29743 | 29746 | |
| 29744 | 29747 | #if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__) |
| | @@ -29913,10 +29916,11 @@ |
| 29913 | 29916 | int fd = -1; /* File descriptor returned by open() */ |
| 29914 | 29917 | int openFlags = 0; /* Flags to pass to open() */ |
| 29915 | 29918 | int eType = flags&0xFFFFFF00; /* Type of file to open */ |
| 29916 | 29919 | int noLock; /* True to omit locking primitives */ |
| 29917 | 29920 | int rc = SQLITE_OK; /* Function Return Code */ |
| 29921 | + int ctrlFlags = 0; /* UNIXFILE_* flags */ |
| 29918 | 29922 | |
| 29919 | 29923 | int isExclusive = (flags & SQLITE_OPEN_EXCLUSIVE); |
| 29920 | 29924 | int isDelete = (flags & SQLITE_OPEN_DELETEONCLOSE); |
| 29921 | 29925 | int isCreate = (flags & SQLITE_OPEN_CREATE); |
| 29922 | 29926 | int isReadonly = (flags & SQLITE_OPEN_READONLY); |
| | @@ -29939,11 +29943,11 @@ |
| 29939 | 29943 | )); |
| 29940 | 29944 | |
| 29941 | 29945 | /* If argument zPath is a NULL pointer, this function is required to open |
| 29942 | 29946 | ** a temporary file. Use this buffer to store the file name in. |
| 29943 | 29947 | */ |
| 29944 | | - char zTmpname[MAX_PATHNAME+1]; |
| 29948 | + char zTmpname[MAX_PATHNAME+2]; |
| 29945 | 29949 | const char *zName = zPath; |
| 29946 | 29950 | |
| 29947 | 29951 | /* Check the following statements are true: |
| 29948 | 29952 | ** |
| 29949 | 29953 | ** (a) Exactly one of the READWRITE and READONLY flags must be set, and |
| | @@ -29982,18 +29986,28 @@ |
| 29982 | 29986 | if( !pUnused ){ |
| 29983 | 29987 | return SQLITE_NOMEM; |
| 29984 | 29988 | } |
| 29985 | 29989 | } |
| 29986 | 29990 | p->pUnused = pUnused; |
| 29991 | + |
| 29992 | + /* Database filenames are double-zero terminated if they are not |
| 29993 | + ** URIs with parameters. Hence, they can always be passed into |
| 29994 | + ** sqlite3_uri_parameter(). */ |
| 29995 | + assert( (flags & SQLITE_OPEN_URI) || zName[strlen(zName)+1]==0 ); |
| 29996 | + |
| 29987 | 29997 | }else if( !zName ){ |
| 29988 | 29998 | /* If zName is NULL, the upper layer is requesting a temp file. */ |
| 29989 | 29999 | assert(isDelete && !syncDir); |
| 29990 | | - rc = unixGetTempname(MAX_PATHNAME+1, zTmpname); |
| 30000 | + rc = unixGetTempname(MAX_PATHNAME+2, zTmpname); |
| 29991 | 30001 | if( rc!=SQLITE_OK ){ |
| 29992 | 30002 | return rc; |
| 29993 | 30003 | } |
| 29994 | 30004 | zName = zTmpname; |
| 30005 | + |
| 30006 | + /* Generated temporary filenames are always double-zero terminated |
| 30007 | + ** for use by sqlite3_uri_parameter(). */ |
| 30008 | + assert( zName[strlen(zName)+1]==0 ); |
| 29995 | 30009 | } |
| 29996 | 30010 | |
| 29997 | 30011 | /* Determine the value of the flags parameter passed to POSIX function |
| 29998 | 30012 | ** open(). These must be calculated even if open() is not called, as |
| 29999 | 30013 | ** they may be stored as part of the file handle and used by the |
| | @@ -30066,11 +30080,18 @@ |
| 30066 | 30080 | } |
| 30067 | 30081 | if (0 == strncmp("msdos", fsInfo.f_fstypename, 5)) { |
| 30068 | 30082 | ((unixFile*)pFile)->fsFlags |= SQLITE_FSFLAGS_IS_MSDOS; |
| 30069 | 30083 | } |
| 30070 | 30084 | #endif |
| 30071 | | - |
| 30085 | + |
| 30086 | + /* Set up appropriate ctrlFlags */ |
| 30087 | + if( isDelete ) ctrlFlags |= UNIXFILE_DELETE; |
| 30088 | + if( isReadonly ) ctrlFlags |= UNIXFILE_RDONLY; |
| 30089 | + if( noLock ) ctrlFlags |= UNIXFILE_NOLOCK; |
| 30090 | + if( syncDir ) ctrlFlags |= UNIXFILE_DIRSYNC; |
| 30091 | + if( flags & SQLITE_OPEN_URI ) ctrlFlags |= UNIXFILE_URI; |
| 30092 | + |
| 30072 | 30093 | #if SQLITE_ENABLE_LOCKING_STYLE |
| 30073 | 30094 | #if SQLITE_PREFER_PROXY_LOCKING |
| 30074 | 30095 | isAutoProxy = 1; |
| 30075 | 30096 | #endif |
| 30076 | 30097 | if( isAutoProxy && (zPath!=NULL) && (!noLock) && pVfs->xOpen ){ |
| | @@ -30096,12 +30117,11 @@ |
| 30096 | 30117 | goto open_finished; |
| 30097 | 30118 | } |
| 30098 | 30119 | useProxy = !(fsInfo.f_flags&MNT_LOCAL); |
| 30099 | 30120 | } |
| 30100 | 30121 | if( useProxy ){ |
| 30101 | | - rc = fillInUnixFile(pVfs, fd, syncDir, pFile, zPath, noLock, |
| 30102 | | - isDelete, isReadonly); |
| 30122 | + rc = fillInUnixFile(pVfs, fd, pFile, zPath, ctrlFlags); |
| 30103 | 30123 | if( rc==SQLITE_OK ){ |
| 30104 | 30124 | rc = proxyTransformUnixFile((unixFile*)pFile, ":auto:"); |
| 30105 | 30125 | if( rc!=SQLITE_OK ){ |
| 30106 | 30126 | /* Use unixClose to clean up the resources added in fillInUnixFile |
| 30107 | 30127 | ** and clear all the structure's references. Specifically, |
| | @@ -30114,12 +30134,12 @@ |
| 30114 | 30134 | goto open_finished; |
| 30115 | 30135 | } |
| 30116 | 30136 | } |
| 30117 | 30137 | #endif |
| 30118 | 30138 | |
| 30119 | | - rc = fillInUnixFile(pVfs, fd, syncDir, pFile, zPath, noLock, |
| 30120 | | - isDelete, isReadonly); |
| 30139 | + rc = fillInUnixFile(pVfs, fd, pFile, zPath, ctrlFlags); |
| 30140 | + |
| 30121 | 30141 | open_finished: |
| 30122 | 30142 | if( rc!=SQLITE_OK ){ |
| 30123 | 30143 | sqlite3_free(p->pUnused); |
| 30124 | 30144 | } |
| 30125 | 30145 | return rc; |
| | @@ -30140,11 +30160,11 @@ |
| 30140 | 30160 | SimulateIOError(return SQLITE_IOERR_DELETE); |
| 30141 | 30161 | if( osUnlink(zPath)==(-1) && errno!=ENOENT ){ |
| 30142 | 30162 | return unixLogError(SQLITE_IOERR_DELETE, "unlink", zPath); |
| 30143 | 30163 | } |
| 30144 | 30164 | #ifndef SQLITE_DISABLE_DIRSYNC |
| 30145 | | - if( dirSync ){ |
| 30165 | + if( (dirSync & 1)!=0 ){ |
| 30146 | 30166 | int fd; |
| 30147 | 30167 | rc = osOpenDirectory(zPath, &fd); |
| 30148 | 30168 | if( rc==SQLITE_OK ){ |
| 30149 | 30169 | #if OS_VXWORKS |
| 30150 | 30170 | if( fsync(fd)==-1 ) |
| | @@ -30786,11 +30806,11 @@ |
| 30786 | 30806 | dummyVfs.zName = "dummy"; |
| 30787 | 30807 | pUnused->fd = fd; |
| 30788 | 30808 | pUnused->flags = openFlags; |
| 30789 | 30809 | pNew->pUnused = pUnused; |
| 30790 | 30810 | |
| 30791 | | - rc = fillInUnixFile(&dummyVfs, fd, 0, (sqlite3_file*)pNew, path, 0, 0, 0); |
| 30811 | + rc = fillInUnixFile(&dummyVfs, fd, (sqlite3_file*)pNew, path, 0); |
| 30792 | 30812 | if( rc==SQLITE_OK ){ |
| 30793 | 30813 | *ppFile = pNew; |
| 30794 | 30814 | return SQLITE_OK; |
| 30795 | 30815 | } |
| 30796 | 30816 | end_create_proxy: |
| | @@ -34388,11 +34408,13 @@ |
| 34388 | 34408 | winClose((sqlite3_file *)&p->hFile); |
| 34389 | 34409 | SimulateIOErrorBenign(0); |
| 34390 | 34410 | } |
| 34391 | 34411 | if( deleteFlag ){ |
| 34392 | 34412 | SimulateIOErrorBenign(1); |
| 34413 | + sqlite3BeginBenignMalloc(); |
| 34393 | 34414 | winDelete(pVfs, p->zFilename, 0); |
| 34415 | + sqlite3EndBenignMalloc(); |
| 34394 | 34416 | SimulateIOErrorBenign(0); |
| 34395 | 34417 | } |
| 34396 | 34418 | *pp = p->pNext; |
| 34397 | 34419 | sqlite3_free(p->aRegion); |
| 34398 | 34420 | sqlite3_free(p); |
| | @@ -34423,16 +34445,16 @@ |
| 34423 | 34445 | */ |
| 34424 | 34446 | p = sqlite3_malloc( sizeof(*p) ); |
| 34425 | 34447 | if( p==0 ) return SQLITE_IOERR_NOMEM; |
| 34426 | 34448 | memset(p, 0, sizeof(*p)); |
| 34427 | 34449 | nName = sqlite3Strlen30(pDbFd->zPath); |
| 34428 | | - pNew = sqlite3_malloc( sizeof(*pShmNode) + nName + 16 ); |
| 34450 | + pNew = sqlite3_malloc( sizeof(*pShmNode) + nName + 17 ); |
| 34429 | 34451 | if( pNew==0 ){ |
| 34430 | 34452 | sqlite3_free(p); |
| 34431 | 34453 | return SQLITE_IOERR_NOMEM; |
| 34432 | 34454 | } |
| 34433 | | - memset(pNew, 0, sizeof(*pNew)); |
| 34455 | + memset(pNew, 0, sizeof(*pNew) + nName + 17); |
| 34434 | 34456 | pNew->zFilename = (char*)&pNew[1]; |
| 34435 | 34457 | sqlite3_snprintf(nName+15, pNew->zFilename, "%s-shm", pDbFd->zPath); |
| 34436 | 34458 | sqlite3FileSuffix3(pDbFd->zPath, pNew->zFilename); |
| 34437 | 34459 | |
| 34438 | 34460 | /* Look to see if there is an existing winShmNode that can be used. |
| | @@ -34464,11 +34486,10 @@ |
| 34464 | 34486 | pShmNode->zFilename, /* Name of the file (UTF-8) */ |
| 34465 | 34487 | (sqlite3_file*)&pShmNode->hFile, /* File handle here */ |
| 34466 | 34488 | SQLITE_OPEN_WAL | SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, /* Mode flags */ |
| 34467 | 34489 | 0); |
| 34468 | 34490 | if( SQLITE_OK!=rc ){ |
| 34469 | | - rc = SQLITE_CANTOPEN_BKPT; |
| 34470 | 34491 | goto shm_open_err; |
| 34471 | 34492 | } |
| 34472 | 34493 | |
| 34473 | 34494 | /* Check to see if another process is holding the dead-man switch. |
| 34474 | 34495 | ** If not, truncate the file to zero length. |
| | @@ -34887,11 +34908,11 @@ |
| 34887 | 34908 | static char zChars[] = |
| 34888 | 34909 | "abcdefghijklmnopqrstuvwxyz" |
| 34889 | 34910 | "ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
| 34890 | 34911 | "0123456789"; |
| 34891 | 34912 | size_t i, j; |
| 34892 | | - char zTempPath[MAX_PATH+1]; |
| 34913 | + char zTempPath[MAX_PATH+2]; |
| 34893 | 34914 | |
| 34894 | 34915 | /* It's odd to simulate an io-error here, but really this is just |
| 34895 | 34916 | ** using the io-error infrastructure to test that SQLite handles this |
| 34896 | 34917 | ** function failing. |
| 34897 | 34918 | */ |
| | @@ -34930,25 +34951,26 @@ |
| 34930 | 34951 | } |
| 34931 | 34952 | |
| 34932 | 34953 | /* Check that the output buffer is large enough for the temporary file |
| 34933 | 34954 | ** name. If it is not, return SQLITE_ERROR. |
| 34934 | 34955 | */ |
| 34935 | | - if( (sqlite3Strlen30(zTempPath) + sqlite3Strlen30(SQLITE_TEMP_FILE_PREFIX) + 17) >= nBuf ){ |
| 34956 | + if( (sqlite3Strlen30(zTempPath) + sqlite3Strlen30(SQLITE_TEMP_FILE_PREFIX) + 18) >= nBuf ){ |
| 34936 | 34957 | return SQLITE_ERROR; |
| 34937 | 34958 | } |
| 34938 | 34959 | |
| 34939 | 34960 | for(i=sqlite3Strlen30(zTempPath); i>0 && zTempPath[i-1]=='\\'; i--){} |
| 34940 | 34961 | zTempPath[i] = 0; |
| 34941 | 34962 | |
| 34942 | | - sqlite3_snprintf(nBuf-17, zBuf, |
| 34963 | + sqlite3_snprintf(nBuf-18, zBuf, |
| 34943 | 34964 | "%s\\"SQLITE_TEMP_FILE_PREFIX, zTempPath); |
| 34944 | 34965 | j = sqlite3Strlen30(zBuf); |
| 34945 | 34966 | sqlite3_randomness(15, &zBuf[j]); |
| 34946 | 34967 | for(i=0; i<15; i++, j++){ |
| 34947 | 34968 | zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ]; |
| 34948 | 34969 | } |
| 34949 | 34970 | zBuf[j] = 0; |
| 34971 | + zBuf[j+1] = 0; |
| 34950 | 34972 | |
| 34951 | 34973 | OSTRACE(("TEMP FILENAME: %s\n", zBuf)); |
| 34952 | 34974 | return SQLITE_OK; |
| 34953 | 34975 | } |
| 34954 | 34976 | |
| | @@ -34977,11 +34999,11 @@ |
| 34977 | 34999 | int cnt = 0; |
| 34978 | 35000 | |
| 34979 | 35001 | /* If argument zPath is a NULL pointer, this function is required to open |
| 34980 | 35002 | ** a temporary file. Use this buffer to store the file name in. |
| 34981 | 35003 | */ |
| 34982 | | - char zTmpname[MAX_PATH+1]; /* Buffer used to create temp filename */ |
| 35004 | + char zTmpname[MAX_PATH+2]; /* Buffer used to create temp filename */ |
| 34983 | 35005 | |
| 34984 | 35006 | int rc = SQLITE_OK; /* Function Return Code */ |
| 34985 | 35007 | #if !defined(NDEBUG) || SQLITE_OS_WINCE |
| 34986 | 35008 | int eType = flags&0xFFFFFF00; /* Type of file to open */ |
| 34987 | 35009 | #endif |
| | @@ -35036,16 +35058,23 @@ |
| 35036 | 35058 | /* If the second argument to this function is NULL, generate a |
| 35037 | 35059 | ** temporary file name to use |
| 35038 | 35060 | */ |
| 35039 | 35061 | if( !zUtf8Name ){ |
| 35040 | 35062 | assert(isDelete && !isOpenJournal); |
| 35041 | | - rc = getTempname(MAX_PATH+1, zTmpname); |
| 35063 | + rc = getTempname(MAX_PATH+2, zTmpname); |
| 35042 | 35064 | if( rc!=SQLITE_OK ){ |
| 35043 | 35065 | return rc; |
| 35044 | 35066 | } |
| 35045 | 35067 | zUtf8Name = zTmpname; |
| 35046 | 35068 | } |
| 35069 | + |
| 35070 | + /* Database filenames are double-zero terminated if they are not |
| 35071 | + ** URIs with parameters. Hence, they can always be passed into |
| 35072 | + ** sqlite3_uri_parameter(). |
| 35073 | + */ |
| 35074 | + assert( (eType!=SQLITE_OPEN_MAIN_DB) || (flags & SQLITE_OPEN_URI) || |
| 35075 | + zUtf8Name[strlen(zUtf8Name)+1]==0 ); |
| 35047 | 35076 | |
| 35048 | 35077 | /* Convert the filename to the system encoding. */ |
| 35049 | 35078 | zConverted = convertUtf8Filename(zUtf8Name); |
| 35050 | 35079 | if( zConverted==0 ){ |
| 35051 | 35080 | return SQLITE_IOERR_NOMEM; |
| | @@ -36721,11 +36750,11 @@ |
| 36721 | 36750 | ** of. |
| 36722 | 36751 | ** |
| 36723 | 36752 | ** Mode 1 uses more memory (since PCache instances are not able to rob |
| 36724 | 36753 | ** unused pages from other PCaches) but it also operates without a mutex, |
| 36725 | 36754 | ** and is therefore often faster. Mode 2 requires a mutex in order to be |
| 36726 | | -** threadsafe, but is able recycle pages more efficient. |
| 36755 | +** threadsafe, but recycles pages more efficiently. |
| 36727 | 36756 | ** |
| 36728 | 36757 | ** For mode (1), PGroup.mutex is NULL. For mode (2) there is only a single |
| 36729 | 36758 | ** PGroup which is the pcache1.grp global variable and its mutex is |
| 36730 | 36759 | ** SQLITE_MUTEX_STATIC_LRU. |
| 36731 | 36760 | */ |
| | @@ -36747,11 +36776,11 @@ |
| 36747 | 36776 | ** opaque sqlite3_pcache* handles. |
| 36748 | 36777 | */ |
| 36749 | 36778 | struct PCache1 { |
| 36750 | 36779 | /* Cache configuration parameters. Page size (szPage) and the purgeable |
| 36751 | 36780 | ** flag (bPurgeable) are set when the cache is created. nMax may be |
| 36752 | | - ** modified at any time by a call to the pcache1CacheSize() method. |
| 36781 | + ** modified at any time by a call to the pcache1Cachesize() method. |
| 36753 | 36782 | ** The PGroup mutex must be held when accessing nMax. |
| 36754 | 36783 | */ |
| 36755 | 36784 | PGroup *pGroup; /* PGroup this cache belongs to */ |
| 36756 | 36785 | int szPage; /* Size of allocated pages in bytes */ |
| 36757 | 36786 | int szExtra; /* Size of extra space in bytes */ |
| | @@ -37038,11 +37067,11 @@ |
| 37038 | 37067 | ** it is desirable to avoid allocating a new page cache entry because |
| 37039 | 37068 | ** presumably SQLITE_CONFIG_PAGECACHE was suppose to be sufficient |
| 37040 | 37069 | ** for all page cache needs and we should not need to spill the |
| 37041 | 37070 | ** allocation onto the heap. |
| 37042 | 37071 | ** |
| 37043 | | -** Or, the heap is used for all page cache memory put the heap is |
| 37072 | +** Or, the heap is used for all page cache memory but the heap is |
| 37044 | 37073 | ** under memory pressure, then again it is desirable to avoid |
| 37045 | 37074 | ** allocating a new page cache entry in order to avoid stressing |
| 37046 | 37075 | ** the heap even further. |
| 37047 | 37076 | */ |
| 37048 | 37077 | static int pcache1UnderMemoryPressure(PCache1 *pCache){ |
| | @@ -37349,11 +37378,11 @@ |
| 37349 | 37378 | ** means to try really hard to allocate a new page. |
| 37350 | 37379 | ** |
| 37351 | 37380 | ** For a non-purgeable cache (a cache used as the storage for an in-memory |
| 37352 | 37381 | ** database) there is really no difference between createFlag 1 and 2. So |
| 37353 | 37382 | ** the calling function (pcache.c) will never have a createFlag of 1 on |
| 37354 | | -** a non-purgable cache. |
| 37383 | +** a non-purgeable cache. |
| 37355 | 37384 | ** |
| 37356 | 37385 | ** There are three different approaches to obtaining space for a page, |
| 37357 | 37386 | ** depending on the value of parameter createFlag (which may be 0, 1 or 2). |
| 37358 | 37387 | ** |
| 37359 | 37388 | ** 1. Regardless of the value of createFlag, the cache is searched for a |
| | @@ -40743,14 +40772,13 @@ |
| 40743 | 40772 | rc = sqlite3OsFileSize(pPager->fd, ¤tSize); |
| 40744 | 40773 | newSize = szPage*(i64)nPage; |
| 40745 | 40774 | if( rc==SQLITE_OK && currentSize!=newSize ){ |
| 40746 | 40775 | if( currentSize>newSize ){ |
| 40747 | 40776 | rc = sqlite3OsTruncate(pPager->fd, newSize); |
| 40748 | | - }else{ |
| 40777 | + }else if( (currentSize+szPage)<=newSize ){ |
| 40749 | 40778 | char *pTmp = pPager->pTmpSpace; |
| 40750 | 40779 | memset(pTmp, 0, szPage); |
| 40751 | | - testcase( (newSize-szPage) < currentSize ); |
| 40752 | 40780 | testcase( (newSize-szPage) == currentSize ); |
| 40753 | 40781 | testcase( (newSize-szPage) > currentSize ); |
| 40754 | 40782 | rc = sqlite3OsWrite(pPager->fd, pTmp, szPage, newSize-szPage); |
| 40755 | 40783 | } |
| 40756 | 40784 | if( rc==SQLITE_OK ){ |
| | @@ -41004,14 +41032,15 @@ |
| 41004 | 41032 | /* Following a rollback, the database file should be back in its original |
| 41005 | 41033 | ** state prior to the start of the transaction, so invoke the |
| 41006 | 41034 | ** SQLITE_FCNTL_DB_UNCHANGED file-control method to disable the |
| 41007 | 41035 | ** assertion that the transaction counter was modified. |
| 41008 | 41036 | */ |
| 41009 | | - assert( |
| 41010 | | - pPager->fd->pMethods==0 || |
| 41011 | | - sqlite3OsFileControl(pPager->fd,SQLITE_FCNTL_DB_UNCHANGED,0)>=SQLITE_OK |
| 41012 | | - ); |
| 41037 | +#ifdef SQLITE_DEBUG |
| 41038 | + if( pPager->fd->pMethods ){ |
| 41039 | + sqlite3OsFileControlHint(pPager->fd,SQLITE_FCNTL_DB_UNCHANGED,0); |
| 41040 | + } |
| 41041 | +#endif |
| 41013 | 41042 | |
| 41014 | 41043 | /* If this playback is happening automatically as a result of an IO or |
| 41015 | 41044 | ** malloc error that occurred after the change-counter was updated but |
| 41016 | 41045 | ** before the transaction was committed, then the change-counter |
| 41017 | 41046 | ** modification may just have been reverted. If this happens in exclusive |
| | @@ -41344,14 +41373,11 @@ |
| 41344 | 41373 | int rc = sqlite3OsFileSize(pPager->fd, &n); |
| 41345 | 41374 | if( rc!=SQLITE_OK ){ |
| 41346 | 41375 | return rc; |
| 41347 | 41376 | } |
| 41348 | 41377 | } |
| 41349 | | - nPage = (Pgno)(n / pPager->pageSize); |
| 41350 | | - if( nPage==0 && n>0 ){ |
| 41351 | | - nPage = 1; |
| 41352 | | - } |
| 41378 | + nPage = (Pgno)((n+pPager->pageSize-1) / pPager->pageSize); |
| 41353 | 41379 | } |
| 41354 | 41380 | |
| 41355 | 41381 | /* If the current number of pages in the file is greater than the |
| 41356 | 41382 | ** configured maximum pager number, increase the allowed limit so |
| 41357 | 41383 | ** that the file can be read. |
| | @@ -41778,11 +41804,11 @@ |
| 41778 | 41804 | if( !pNew ) rc = SQLITE_NOMEM; |
| 41779 | 41805 | } |
| 41780 | 41806 | |
| 41781 | 41807 | if( rc==SQLITE_OK ){ |
| 41782 | 41808 | pager_reset(pPager); |
| 41783 | | - pPager->dbSize = (Pgno)(nByte/pageSize); |
| 41809 | + pPager->dbSize = (Pgno)((nByte+pageSize-1)/pageSize); |
| 41784 | 41810 | pPager->pageSize = pageSize; |
| 41785 | 41811 | sqlite3PageFree(pPager->pTmpSpace); |
| 41786 | 41812 | pPager->pTmpSpace = pNew; |
| 41787 | 41813 | sqlite3PcacheSetPageSize(pPager->pPCache, pageSize); |
| 41788 | 41814 | } |
| | @@ -42286,13 +42312,11 @@ |
| 42286 | 42312 | ** file size will be. |
| 42287 | 42313 | */ |
| 42288 | 42314 | assert( rc!=SQLITE_OK || isOpen(pPager->fd) ); |
| 42289 | 42315 | if( rc==SQLITE_OK && pPager->dbSize>pPager->dbHintSize ){ |
| 42290 | 42316 | sqlite3_int64 szFile = pPager->pageSize * (sqlite3_int64)pPager->dbSize; |
| 42291 | | - sqlite3BeginBenignMalloc(); |
| 42292 | | - sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_SIZE_HINT, &szFile); |
| 42293 | | - sqlite3EndBenignMalloc(); |
| 42317 | + sqlite3OsFileControlHint(pPager->fd, SQLITE_FCNTL_SIZE_HINT, &szFile); |
| 42294 | 42318 | pPager->dbHintSize = pPager->dbSize; |
| 42295 | 42319 | } |
| 42296 | 42320 | |
| 42297 | 42321 | while( rc==SQLITE_OK && pList ){ |
| 42298 | 42322 | Pgno pgno = pList->pgno; |
| | @@ -44312,11 +44336,12 @@ |
| 44312 | 44336 | }else{ |
| 44313 | 44337 | rc = pager_playback(pPager, 0); |
| 44314 | 44338 | } |
| 44315 | 44339 | |
| 44316 | 44340 | assert( pPager->eState==PAGER_READER || rc!=SQLITE_OK ); |
| 44317 | | - assert( rc==SQLITE_OK || rc==SQLITE_FULL || (rc&0xFF)==SQLITE_IOERR ); |
| 44341 | + assert( rc==SQLITE_OK || rc==SQLITE_FULL |
| 44342 | + || rc==SQLITE_NOMEM || (rc&0xFF)==SQLITE_IOERR ); |
| 44318 | 44343 | |
| 44319 | 44344 | /* If an error occurs during a ROLLBACK, we can no longer trust the pager |
| 44320 | 44345 | ** cache. So call pager_error() on the way out to make any error persistent. |
| 44321 | 44346 | */ |
| 44322 | 44347 | return pager_error(pPager, rc); |
| | @@ -46887,11 +46912,11 @@ |
| 46887 | 46912 | */ |
| 46888 | 46913 | if( rc==SQLITE_OK ){ |
| 46889 | 46914 | i64 nReq = ((i64)mxPage * szPage); |
| 46890 | 46915 | rc = sqlite3OsFileSize(pWal->pDbFd, &nSize); |
| 46891 | 46916 | if( rc==SQLITE_OK && nSize<nReq ){ |
| 46892 | | - sqlite3OsFileControl(pWal->pDbFd, SQLITE_FCNTL_SIZE_HINT, &nReq); |
| 46917 | + sqlite3OsFileControlHint(pWal->pDbFd, SQLITE_FCNTL_SIZE_HINT, &nReq); |
| 46893 | 46918 | } |
| 46894 | 46919 | } |
| 46895 | 46920 | |
| 46896 | 46921 | /* Iterate through the contents of the WAL, copying data to the db file. */ |
| 46897 | 46922 | while( rc==SQLITE_OK && 0==walIteratorNext(pIter, &iDbpage, &iFrame) ){ |
| | @@ -47003,11 +47028,13 @@ |
| 47003 | 47028 | rc = sqlite3WalCheckpoint( |
| 47004 | 47029 | pWal, SQLITE_CHECKPOINT_PASSIVE, 0, 0, sync_flags, nBuf, zBuf, 0, 0 |
| 47005 | 47030 | ); |
| 47006 | 47031 | if( rc==SQLITE_OK ){ |
| 47007 | 47032 | int bPersist = -1; |
| 47008 | | - sqlite3OsFileControl(pWal->pDbFd, SQLITE_FCNTL_PERSIST_WAL, &bPersist); |
| 47033 | + sqlite3OsFileControlHint( |
| 47034 | + pWal->pDbFd, SQLITE_FCNTL_PERSIST_WAL, &bPersist |
| 47035 | + ); |
| 47009 | 47036 | if( bPersist!=1 ){ |
| 47010 | 47037 | /* Try to delete the WAL file if the checkpoint completed and |
| 47011 | 47038 | ** fsyned (rc==SQLITE_OK) and if we are not in persistent-wal |
| 47012 | 47039 | ** mode (!bPersist) */ |
| 47013 | 47040 | isDelete = 1; |
| | @@ -47024,11 +47051,13 @@ |
| 47024 | 47051 | } |
| 47025 | 47052 | |
| 47026 | 47053 | walIndexClose(pWal, isDelete); |
| 47027 | 47054 | sqlite3OsClose(pWal->pWalFd); |
| 47028 | 47055 | if( isDelete ){ |
| 47056 | + sqlite3BeginBenignMalloc(); |
| 47029 | 47057 | sqlite3OsDelete(pWal->pVfs, pWal->zWalName, 0); |
| 47058 | + sqlite3EndBenignMalloc(); |
| 47030 | 47059 | } |
| 47031 | 47060 | WALTRACE(("WAL%p: closed\n", pWal)); |
| 47032 | 47061 | sqlite3_free((void *)pWal->apWiData); |
| 47033 | 47062 | sqlite3_free(pWal); |
| 47034 | 47063 | } |
| | @@ -48525,10 +48554,11 @@ |
| 48525 | 48554 | u8 intKey; /* True if intkey flag is set */ |
| 48526 | 48555 | u8 leaf; /* True if leaf flag is set */ |
| 48527 | 48556 | u8 hasData; /* True if this page stores data */ |
| 48528 | 48557 | u8 hdrOffset; /* 100 for page 1. 0 otherwise */ |
| 48529 | 48558 | u8 childPtrSize; /* 0 if leaf==1. 4 if leaf==0 */ |
| 48559 | + u8 max1bytePayload; /* min(maxLocal,127) */ |
| 48530 | 48560 | u16 maxLocal; /* Copy of BtShared.maxLocal or BtShared.maxLeaf */ |
| 48531 | 48561 | u16 minLocal; /* Copy of BtShared.minLocal or BtShared.minLeaf */ |
| 48532 | 48562 | u16 cellOffset; /* Index in aData of first cell pointer */ |
| 48533 | 48563 | u16 nFree; /* Number of free bytes on the page */ |
| 48534 | 48564 | u16 nCell; /* Number of cells on this page, local and ovfl */ |
| | @@ -48655,21 +48685,18 @@ |
| 48655 | 48685 | struct BtShared { |
| 48656 | 48686 | Pager *pPager; /* The page cache */ |
| 48657 | 48687 | sqlite3 *db; /* Database connection currently using this Btree */ |
| 48658 | 48688 | BtCursor *pCursor; /* A list of all open cursors */ |
| 48659 | 48689 | MemPage *pPage1; /* First page of the database */ |
| 48660 | | - u8 readOnly; /* True if the underlying file is readonly */ |
| 48661 | | - u8 pageSizeFixed; /* True if the page size can no longer be changed */ |
| 48662 | | - u8 secureDelete; /* True if secure_delete is enabled */ |
| 48663 | | - u8 initiallyEmpty; /* Database is empty at start of transaction */ |
| 48664 | 48690 | u8 openFlags; /* Flags to sqlite3BtreeOpen() */ |
| 48665 | 48691 | #ifndef SQLITE_OMIT_AUTOVACUUM |
| 48666 | 48692 | u8 autoVacuum; /* True if auto-vacuum is enabled */ |
| 48667 | 48693 | u8 incrVacuum; /* True if incr-vacuum is enabled */ |
| 48668 | 48694 | #endif |
| 48669 | 48695 | u8 inTransaction; /* Transaction state */ |
| 48670 | | - u8 doNotUseWAL; /* If true, do not open write-ahead-log file */ |
| 48696 | + u8 max1bytePayload; /* Maximum first byte of cell for a 1-byte payload */ |
| 48697 | + u16 btsFlags; /* Boolean parameters. See BTS_* macros below */ |
| 48671 | 48698 | u16 maxLocal; /* Maximum local payload in non-LEAFDATA tables */ |
| 48672 | 48699 | u16 minLocal; /* Minimum local payload in non-LEAFDATA tables */ |
| 48673 | 48700 | u16 maxLeaf; /* Maximum local payload in a LEAFDATA table */ |
| 48674 | 48701 | u16 minLeaf; /* Minimum local payload in a LEAFDATA table */ |
| 48675 | 48702 | u32 pageSize; /* Total number of bytes on a page */ |
| | @@ -48683,16 +48710,25 @@ |
| 48683 | 48710 | #ifndef SQLITE_OMIT_SHARED_CACHE |
| 48684 | 48711 | int nRef; /* Number of references to this structure */ |
| 48685 | 48712 | BtShared *pNext; /* Next on a list of sharable BtShared structs */ |
| 48686 | 48713 | BtLock *pLock; /* List of locks held on this shared-btree struct */ |
| 48687 | 48714 | Btree *pWriter; /* Btree with currently open write transaction */ |
| 48688 | | - u8 isExclusive; /* True if pWriter has an EXCLUSIVE lock on the db */ |
| 48689 | | - u8 isPending; /* If waiting for read-locks to clear */ |
| 48690 | 48715 | #endif |
| 48691 | 48716 | u8 *pTmpSpace; /* BtShared.pageSize bytes of space for tmp use */ |
| 48692 | 48717 | }; |
| 48693 | 48718 | |
| 48719 | +/* |
| 48720 | +** Allowed values for BtShared.btsFlags |
| 48721 | +*/ |
| 48722 | +#define BTS_READ_ONLY 0x0001 /* Underlying file is readonly */ |
| 48723 | +#define BTS_PAGESIZE_FIXED 0x0002 /* Page size can no longer be changed */ |
| 48724 | +#define BTS_SECURE_DELETE 0x0004 /* PRAGMA secure_delete is enabled */ |
| 48725 | +#define BTS_INITIALLY_EMPTY 0x0008 /* Database was empty at trans start */ |
| 48726 | +#define BTS_NO_WAL 0x0010 /* Do not open write-ahead-log files */ |
| 48727 | +#define BTS_EXCLUSIVE 0x0020 /* pWriter has an exclusive lock */ |
| 48728 | +#define BTS_PENDING 0x0040 /* Waiting for read-locks to clear */ |
| 48729 | + |
| 48694 | 48730 | /* |
| 48695 | 48731 | ** An instance of the following structure is used to hold information |
| 48696 | 48732 | ** about a cell. The parseCellPtr() function fills in this structure |
| 48697 | 48733 | ** based on information extract from the raw disk page. |
| 48698 | 48734 | */ |
| | @@ -49410,11 +49446,11 @@ |
| 49410 | 49446 | } |
| 49411 | 49447 | |
| 49412 | 49448 | /* If some other connection is holding an exclusive lock, the |
| 49413 | 49449 | ** requested lock may not be obtained. |
| 49414 | 49450 | */ |
| 49415 | | - if( pBt->pWriter!=p && pBt->isExclusive ){ |
| 49451 | + if( pBt->pWriter!=p && (pBt->btsFlags & BTS_EXCLUSIVE)!=0 ){ |
| 49416 | 49452 | sqlite3ConnectionBlocked(p->db, pBt->pWriter->db); |
| 49417 | 49453 | return SQLITE_LOCKED_SHAREDCACHE; |
| 49418 | 49454 | } |
| 49419 | 49455 | |
| 49420 | 49456 | for(pIter=pBt->pLock; pIter; pIter=pIter->pNext){ |
| | @@ -49431,11 +49467,11 @@ |
| 49431 | 49467 | assert( eLock==READ_LOCK || pIter->pBtree==p || pIter->eLock==READ_LOCK); |
| 49432 | 49468 | if( pIter->pBtree!=p && pIter->iTable==iTab && pIter->eLock!=eLock ){ |
| 49433 | 49469 | sqlite3ConnectionBlocked(p->db, pIter->pBtree->db); |
| 49434 | 49470 | if( eLock==WRITE_LOCK ){ |
| 49435 | 49471 | assert( p==pBt->pWriter ); |
| 49436 | | - pBt->isPending = 1; |
| 49472 | + pBt->btsFlags |= BTS_PENDING; |
| 49437 | 49473 | } |
| 49438 | 49474 | return SQLITE_LOCKED_SHAREDCACHE; |
| 49439 | 49475 | } |
| 49440 | 49476 | } |
| 49441 | 49477 | return SQLITE_OK; |
| | @@ -49519,11 +49555,11 @@ |
| 49519 | 49555 | /* |
| 49520 | 49556 | ** Release all the table locks (locks obtained via calls to |
| 49521 | 49557 | ** the setSharedCacheTableLock() procedure) held by Btree object p. |
| 49522 | 49558 | ** |
| 49523 | 49559 | ** This function assumes that Btree p has an open read or write |
| 49524 | | -** transaction. If it does not, then the BtShared.isPending variable |
| 49560 | +** transaction. If it does not, then the BTS_PENDING flag |
| 49525 | 49561 | ** may be incorrectly cleared. |
| 49526 | 49562 | */ |
| 49527 | 49563 | static void clearAllSharedCacheTableLocks(Btree *p){ |
| 49528 | 49564 | BtShared *pBt = p->pBt; |
| 49529 | 49565 | BtLock **ppIter = &pBt->pLock; |
| | @@ -49532,11 +49568,11 @@ |
| 49532 | 49568 | assert( p->sharable || 0==*ppIter ); |
| 49533 | 49569 | assert( p->inTrans>0 ); |
| 49534 | 49570 | |
| 49535 | 49571 | while( *ppIter ){ |
| 49536 | 49572 | BtLock *pLock = *ppIter; |
| 49537 | | - assert( pBt->isExclusive==0 || pBt->pWriter==pLock->pBtree ); |
| 49573 | + assert( (pBt->btsFlags & BTS_EXCLUSIVE)==0 || pBt->pWriter==pLock->pBtree ); |
| 49538 | 49574 | assert( pLock->pBtree->inTrans>=pLock->eLock ); |
| 49539 | 49575 | if( pLock->pBtree==p ){ |
| 49540 | 49576 | *ppIter = pLock->pNext; |
| 49541 | 49577 | assert( pLock->iTable!=1 || pLock==&p->lock ); |
| 49542 | 49578 | if( pLock->iTable!=1 ){ |
| | @@ -49545,26 +49581,25 @@ |
| 49545 | 49581 | }else{ |
| 49546 | 49582 | ppIter = &pLock->pNext; |
| 49547 | 49583 | } |
| 49548 | 49584 | } |
| 49549 | 49585 | |
| 49550 | | - assert( pBt->isPending==0 || pBt->pWriter ); |
| 49586 | + assert( (pBt->btsFlags & BTS_PENDING)==0 || pBt->pWriter ); |
| 49551 | 49587 | if( pBt->pWriter==p ){ |
| 49552 | 49588 | pBt->pWriter = 0; |
| 49553 | | - pBt->isExclusive = 0; |
| 49554 | | - pBt->isPending = 0; |
| 49589 | + pBt->btsFlags &= ~(BTS_EXCLUSIVE|BTS_PENDING); |
| 49555 | 49590 | }else if( pBt->nTransaction==2 ){ |
| 49556 | 49591 | /* This function is called when Btree p is concluding its |
| 49557 | 49592 | ** transaction. If there currently exists a writer, and p is not |
| 49558 | 49593 | ** that writer, then the number of locks held by connections other |
| 49559 | 49594 | ** than the writer must be about to drop to zero. In this case |
| 49560 | | - ** set the isPending flag to 0. |
| 49595 | + ** set the BTS_PENDING flag to 0. |
| 49561 | 49596 | ** |
| 49562 | | - ** If there is not currently a writer, then BtShared.isPending must |
| 49597 | + ** If there is not currently a writer, then BTS_PENDING must |
| 49563 | 49598 | ** be zero already. So this next line is harmless in that case. |
| 49564 | 49599 | */ |
| 49565 | | - pBt->isPending = 0; |
| 49600 | + pBt->btsFlags &= ~BTS_PENDING; |
| 49566 | 49601 | } |
| 49567 | 49602 | } |
| 49568 | 49603 | |
| 49569 | 49604 | /* |
| 49570 | 49605 | ** This function changes all write-locks held by Btree p into read-locks. |
| | @@ -49572,12 +49607,11 @@ |
| 49572 | 49607 | static void downgradeAllSharedCacheTableLocks(Btree *p){ |
| 49573 | 49608 | BtShared *pBt = p->pBt; |
| 49574 | 49609 | if( pBt->pWriter==p ){ |
| 49575 | 49610 | BtLock *pLock; |
| 49576 | 49611 | pBt->pWriter = 0; |
| 49577 | | - pBt->isExclusive = 0; |
| 49578 | | - pBt->isPending = 0; |
| 49612 | + pBt->btsFlags &= ~(BTS_EXCLUSIVE|BTS_PENDING); |
| 49579 | 49613 | for(pLock=pBt->pLock; pLock; pLock=pLock->pNext){ |
| 49580 | 49614 | assert( pLock->eLock==READ_LOCK || pLock->pBtree==p ); |
| 49581 | 49615 | pLock->eLock = READ_LOCK; |
| 49582 | 49616 | } |
| 49583 | 49617 | } |
| | @@ -50431,11 +50465,11 @@ |
| 50431 | 50465 | assert( start>=pPage->hdrOffset+6+pPage->childPtrSize ); |
| 50432 | 50466 | assert( (start + size) <= (int)pPage->pBt->usableSize ); |
| 50433 | 50467 | assert( sqlite3_mutex_held(pPage->pBt->mutex) ); |
| 50434 | 50468 | assert( size>=0 ); /* Minimum cell size is 4 */ |
| 50435 | 50469 | |
| 50436 | | - if( pPage->pBt->secureDelete ){ |
| 50470 | + if( pPage->pBt->btsFlags & BTS_SECURE_DELETE ){ |
| 50437 | 50471 | /* Overwrite deleted information with zeros when the secure_delete |
| 50438 | 50472 | ** option is enabled */ |
| 50439 | 50473 | memset(&data[start], 0, size); |
| 50440 | 50474 | } |
| 50441 | 50475 | |
| | @@ -50534,10 +50568,11 @@ |
| 50534 | 50568 | pPage->maxLocal = pBt->maxLocal; |
| 50535 | 50569 | pPage->minLocal = pBt->minLocal; |
| 50536 | 50570 | }else{ |
| 50537 | 50571 | return SQLITE_CORRUPT_BKPT; |
| 50538 | 50572 | } |
| 50573 | + pPage->max1bytePayload = pBt->max1bytePayload; |
| 50539 | 50574 | return SQLITE_OK; |
| 50540 | 50575 | } |
| 50541 | 50576 | |
| 50542 | 50577 | /* |
| 50543 | 50578 | ** Initialize the auxiliary information for a disk block. |
| | @@ -50669,11 +50704,11 @@ |
| 50669 | 50704 | assert( sqlite3PagerPagenumber(pPage->pDbPage)==pPage->pgno ); |
| 50670 | 50705 | assert( sqlite3PagerGetExtra(pPage->pDbPage) == (void*)pPage ); |
| 50671 | 50706 | assert( sqlite3PagerGetData(pPage->pDbPage) == data ); |
| 50672 | 50707 | assert( sqlite3PagerIswriteable(pPage->pDbPage) ); |
| 50673 | 50708 | assert( sqlite3_mutex_held(pBt->mutex) ); |
| 50674 | | - if( pBt->secureDelete ){ |
| 50709 | + if( pBt->btsFlags & BTS_SECURE_DELETE ){ |
| 50675 | 50710 | memset(&data[hdr], 0, pBt->usableSize - hdr); |
| 50676 | 50711 | } |
| 50677 | 50712 | data[hdr] = (char)flags; |
| 50678 | 50713 | first = hdr + 8 + 4*((flags&PTF_LEAF)==0 ?1:0); |
| 50679 | 50714 | memset(&data[hdr+1], 0, 4); |
| | @@ -51022,13 +51057,13 @@ |
| 51022 | 51057 | sqlite3PagerSetBusyhandler(pBt->pPager, btreeInvokeBusyHandler, pBt); |
| 51023 | 51058 | p->pBt = pBt; |
| 51024 | 51059 | |
| 51025 | 51060 | pBt->pCursor = 0; |
| 51026 | 51061 | pBt->pPage1 = 0; |
| 51027 | | - pBt->readOnly = sqlite3PagerIsreadonly(pBt->pPager); |
| 51062 | + if( sqlite3PagerIsreadonly(pBt->pPager) ) pBt->btsFlags |= BTS_READ_ONLY; |
| 51028 | 51063 | #ifdef SQLITE_SECURE_DELETE |
| 51029 | | - pBt->secureDelete = 1; |
| 51064 | + pBt->btsFlags |= BTS_SECURE_DELETE; |
| 51030 | 51065 | #endif |
| 51031 | 51066 | pBt->pageSize = (zDbHeader[16]<<8) | (zDbHeader[17]<<16); |
| 51032 | 51067 | if( pBt->pageSize<512 || pBt->pageSize>SQLITE_MAX_PAGE_SIZE |
| 51033 | 51068 | || ((pBt->pageSize-1)&pBt->pageSize)!=0 ){ |
| 51034 | 51069 | pBt->pageSize = 0; |
| | @@ -51045,11 +51080,11 @@ |
| 51045 | 51080 | } |
| 51046 | 51081 | #endif |
| 51047 | 51082 | nReserve = 0; |
| 51048 | 51083 | }else{ |
| 51049 | 51084 | nReserve = zDbHeader[20]; |
| 51050 | | - pBt->pageSizeFixed = 1; |
| 51085 | + pBt->btsFlags |= BTS_PAGESIZE_FIXED; |
| 51051 | 51086 | #ifndef SQLITE_OMIT_AUTOVACUUM |
| 51052 | 51087 | pBt->autoVacuum = (get4byte(&zDbHeader[36 + 4*4])?1:0); |
| 51053 | 51088 | pBt->incrVacuum = (get4byte(&zDbHeader[36 + 7*4])?1:0); |
| 51054 | 51089 | #endif |
| 51055 | 51090 | } |
| | @@ -51333,19 +51368,19 @@ |
| 51333 | 51368 | ** at the beginning of a page. |
| 51334 | 51369 | ** |
| 51335 | 51370 | ** If parameter nReserve is less than zero, then the number of reserved |
| 51336 | 51371 | ** bytes per page is left unchanged. |
| 51337 | 51372 | ** |
| 51338 | | -** If the iFix!=0 then the pageSizeFixed flag is set so that the page size |
| 51373 | +** If the iFix!=0 then the BTS_PAGESIZE_FIXED flag is set so that the page size |
| 51339 | 51374 | ** and autovacuum mode can no longer be changed. |
| 51340 | 51375 | */ |
| 51341 | 51376 | SQLITE_PRIVATE int sqlite3BtreeSetPageSize(Btree *p, int pageSize, int nReserve, int iFix){ |
| 51342 | 51377 | int rc = SQLITE_OK; |
| 51343 | 51378 | BtShared *pBt = p->pBt; |
| 51344 | 51379 | assert( nReserve>=-1 && nReserve<=255 ); |
| 51345 | 51380 | sqlite3BtreeEnter(p); |
| 51346 | | - if( pBt->pageSizeFixed ){ |
| 51381 | + if( pBt->btsFlags & BTS_PAGESIZE_FIXED ){ |
| 51347 | 51382 | sqlite3BtreeLeave(p); |
| 51348 | 51383 | return SQLITE_READONLY; |
| 51349 | 51384 | } |
| 51350 | 51385 | if( nReserve<0 ){ |
| 51351 | 51386 | nReserve = pBt->pageSize - pBt->usableSize; |
| | @@ -51358,11 +51393,11 @@ |
| 51358 | 51393 | pBt->pageSize = (u32)pageSize; |
| 51359 | 51394 | freeTempSpace(pBt); |
| 51360 | 51395 | } |
| 51361 | 51396 | rc = sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize, nReserve); |
| 51362 | 51397 | pBt->usableSize = pBt->pageSize - (u16)nReserve; |
| 51363 | | - if( iFix ) pBt->pageSizeFixed = 1; |
| 51398 | + if( iFix ) pBt->btsFlags |= BTS_PAGESIZE_FIXED; |
| 51364 | 51399 | sqlite3BtreeLeave(p); |
| 51365 | 51400 | return rc; |
| 51366 | 51401 | } |
| 51367 | 51402 | |
| 51368 | 51403 | /* |
| | @@ -51398,22 +51433,23 @@ |
| 51398 | 51433 | sqlite3BtreeLeave(p); |
| 51399 | 51434 | return n; |
| 51400 | 51435 | } |
| 51401 | 51436 | |
| 51402 | 51437 | /* |
| 51403 | | -** Set the secureDelete flag if newFlag is 0 or 1. If newFlag is -1, |
| 51404 | | -** then make no changes. Always return the value of the secureDelete |
| 51438 | +** Set the BTS_SECURE_DELETE flag if newFlag is 0 or 1. If newFlag is -1, |
| 51439 | +** then make no changes. Always return the value of the BTS_SECURE_DELETE |
| 51405 | 51440 | ** setting after the change. |
| 51406 | 51441 | */ |
| 51407 | 51442 | SQLITE_PRIVATE int sqlite3BtreeSecureDelete(Btree *p, int newFlag){ |
| 51408 | 51443 | int b; |
| 51409 | 51444 | if( p==0 ) return 0; |
| 51410 | 51445 | sqlite3BtreeEnter(p); |
| 51411 | 51446 | if( newFlag>=0 ){ |
| 51412 | | - p->pBt->secureDelete = (newFlag!=0) ? 1 : 0; |
| 51447 | + p->pBt->btsFlags &= ~BTS_SECURE_DELETE; |
| 51448 | + if( newFlag ) p->pBt->btsFlags |= BTS_SECURE_DELETE; |
| 51413 | 51449 | } |
| 51414 | | - b = p->pBt->secureDelete; |
| 51450 | + b = (p->pBt->btsFlags & BTS_SECURE_DELETE)!=0; |
| 51415 | 51451 | sqlite3BtreeLeave(p); |
| 51416 | 51452 | return b; |
| 51417 | 51453 | } |
| 51418 | 51454 | #endif /* !defined(SQLITE_OMIT_PAGER_PRAGMAS) || !defined(SQLITE_OMIT_VACUUM) */ |
| 51419 | 51455 | |
| | @@ -51430,11 +51466,11 @@ |
| 51430 | 51466 | BtShared *pBt = p->pBt; |
| 51431 | 51467 | int rc = SQLITE_OK; |
| 51432 | 51468 | u8 av = (u8)autoVacuum; |
| 51433 | 51469 | |
| 51434 | 51470 | sqlite3BtreeEnter(p); |
| 51435 | | - if( pBt->pageSizeFixed && (av ?1:0)!=pBt->autoVacuum ){ |
| 51471 | + if( (pBt->btsFlags & BTS_PAGESIZE_FIXED)!=0 && (av ?1:0)!=pBt->autoVacuum ){ |
| 51436 | 51472 | rc = SQLITE_READONLY; |
| 51437 | 51473 | }else{ |
| 51438 | 51474 | pBt->autoVacuum = av ?1:0; |
| 51439 | 51475 | pBt->incrVacuum = av==2 ?1:0; |
| 51440 | 51476 | } |
| | @@ -51504,18 +51540,18 @@ |
| 51504 | 51540 | goto page1_init_failed; |
| 51505 | 51541 | } |
| 51506 | 51542 | |
| 51507 | 51543 | #ifdef SQLITE_OMIT_WAL |
| 51508 | 51544 | if( page1[18]>1 ){ |
| 51509 | | - pBt->readOnly = 1; |
| 51545 | + pBt->btsFlags |= BTS_READ_ONLY; |
| 51510 | 51546 | } |
| 51511 | 51547 | if( page1[19]>1 ){ |
| 51512 | 51548 | goto page1_init_failed; |
| 51513 | 51549 | } |
| 51514 | 51550 | #else |
| 51515 | 51551 | if( page1[18]>2 ){ |
| 51516 | | - pBt->readOnly = 1; |
| 51552 | + pBt->btsFlags |= BTS_READ_ONLY; |
| 51517 | 51553 | } |
| 51518 | 51554 | if( page1[19]>2 ){ |
| 51519 | 51555 | goto page1_init_failed; |
| 51520 | 51556 | } |
| 51521 | 51557 | |
| | @@ -51525,11 +51561,11 @@ |
| 51525 | 51561 | ** The caller detects this and calls this function again. This is |
| 51526 | 51562 | ** required as the version of page 1 currently in the page1 buffer |
| 51527 | 51563 | ** may not be the latest version - there may be a newer one in the log |
| 51528 | 51564 | ** file. |
| 51529 | 51565 | */ |
| 51530 | | - if( page1[19]==2 && pBt->doNotUseWAL==0 ){ |
| 51566 | + if( page1[19]==2 && (pBt->btsFlags & BTS_NO_WAL)==0 ){ |
| 51531 | 51567 | int isOpen = 0; |
| 51532 | 51568 | rc = sqlite3PagerOpenWal(pBt->pPager, &isOpen); |
| 51533 | 51569 | if( rc!=SQLITE_OK ){ |
| 51534 | 51570 | goto page1_init_failed; |
| 51535 | 51571 | }else if( isOpen==0 ){ |
| | @@ -51602,10 +51638,15 @@ |
| 51602 | 51638 | */ |
| 51603 | 51639 | pBt->maxLocal = (u16)((pBt->usableSize-12)*64/255 - 23); |
| 51604 | 51640 | pBt->minLocal = (u16)((pBt->usableSize-12)*32/255 - 23); |
| 51605 | 51641 | pBt->maxLeaf = (u16)(pBt->usableSize - 35); |
| 51606 | 51642 | pBt->minLeaf = (u16)((pBt->usableSize-12)*32/255 - 23); |
| 51643 | + if( pBt->maxLocal>127 ){ |
| 51644 | + pBt->max1bytePayload = 127; |
| 51645 | + }else{ |
| 51646 | + pBt->max1bytePayload = (u8)pBt->maxLocal; |
| 51647 | + } |
| 51607 | 51648 | assert( pBt->maxLeaf + 23 <= MX_CELL_SIZE(pBt) ); |
| 51608 | 51649 | pBt->pPage1 = pPage1; |
| 51609 | 51650 | pBt->nPage = nPage; |
| 51610 | 51651 | return SQLITE_OK; |
| 51611 | 51652 | |
| | @@ -51665,11 +51706,11 @@ |
| 51665 | 51706 | data[21] = 64; |
| 51666 | 51707 | data[22] = 32; |
| 51667 | 51708 | data[23] = 32; |
| 51668 | 51709 | memset(&data[24], 0, 100-24); |
| 51669 | 51710 | zeroPage(pP1, PTF_INTKEY|PTF_LEAF|PTF_LEAFDATA ); |
| 51670 | | - pBt->pageSizeFixed = 1; |
| 51711 | + pBt->btsFlags |= BTS_PAGESIZE_FIXED; |
| 51671 | 51712 | #ifndef SQLITE_OMIT_AUTOVACUUM |
| 51672 | 51713 | assert( pBt->autoVacuum==1 || pBt->autoVacuum==0 ); |
| 51673 | 51714 | assert( pBt->incrVacuum==1 || pBt->incrVacuum==0 ); |
| 51674 | 51715 | put4byte(&data[36 + 4*4], pBt->autoVacuum); |
| 51675 | 51716 | put4byte(&data[36 + 7*4], pBt->incrVacuum); |
| | @@ -51729,21 +51770,23 @@ |
| 51729 | 51770 | if( p->inTrans==TRANS_WRITE || (p->inTrans==TRANS_READ && !wrflag) ){ |
| 51730 | 51771 | goto trans_begun; |
| 51731 | 51772 | } |
| 51732 | 51773 | |
| 51733 | 51774 | /* Write transactions are not possible on a read-only database */ |
| 51734 | | - if( pBt->readOnly && wrflag ){ |
| 51775 | + if( (pBt->btsFlags & BTS_READ_ONLY)!=0 && wrflag ){ |
| 51735 | 51776 | rc = SQLITE_READONLY; |
| 51736 | 51777 | goto trans_begun; |
| 51737 | 51778 | } |
| 51738 | 51779 | |
| 51739 | 51780 | #ifndef SQLITE_OMIT_SHARED_CACHE |
| 51740 | 51781 | /* If another database handle has already opened a write transaction |
| 51741 | 51782 | ** on this shared-btree structure and a second write transaction is |
| 51742 | 51783 | ** requested, return SQLITE_LOCKED. |
| 51743 | 51784 | */ |
| 51744 | | - if( (wrflag && pBt->inTransaction==TRANS_WRITE) || pBt->isPending ){ |
| 51785 | + if( (wrflag && pBt->inTransaction==TRANS_WRITE) |
| 51786 | + || (pBt->btsFlags & BTS_PENDING)!=0 |
| 51787 | + ){ |
| 51745 | 51788 | pBlock = pBt->pWriter->db; |
| 51746 | 51789 | }else if( wrflag>1 ){ |
| 51747 | 51790 | BtLock *pIter; |
| 51748 | 51791 | for(pIter=pBt->pLock; pIter; pIter=pIter->pNext){ |
| 51749 | 51792 | if( pIter->pBtree!=p ){ |
| | @@ -51763,11 +51806,12 @@ |
| 51763 | 51806 | ** page 1. So if some other shared-cache client already has a write-lock |
| 51764 | 51807 | ** on page 1, the transaction cannot be opened. */ |
| 51765 | 51808 | rc = querySharedCacheTableLock(p, MASTER_ROOT, READ_LOCK); |
| 51766 | 51809 | if( SQLITE_OK!=rc ) goto trans_begun; |
| 51767 | 51810 | |
| 51768 | | - pBt->initiallyEmpty = (u8)(pBt->nPage==0); |
| 51811 | + pBt->btsFlags &= ~BTS_INITIALLY_EMPTY; |
| 51812 | + if( pBt->nPage==0 ) pBt->btsFlags |= BTS_INITIALLY_EMPTY; |
| 51769 | 51813 | do { |
| 51770 | 51814 | /* Call lockBtree() until either pBt->pPage1 is populated or |
| 51771 | 51815 | ** lockBtree() returns something other than SQLITE_OK. lockBtree() |
| 51772 | 51816 | ** may return SQLITE_OK but leave pBt->pPage1 set to 0 if after |
| 51773 | 51817 | ** reading page 1 it discovers that the page-size of the database |
| | @@ -51775,11 +51819,11 @@ |
| 51775 | 51819 | ** pBt->pageSize to the page-size of the file on disk. |
| 51776 | 51820 | */ |
| 51777 | 51821 | while( pBt->pPage1==0 && SQLITE_OK==(rc = lockBtree(pBt)) ); |
| 51778 | 51822 | |
| 51779 | 51823 | if( rc==SQLITE_OK && wrflag ){ |
| 51780 | | - if( pBt->readOnly ){ |
| 51824 | + if( (pBt->btsFlags & BTS_READ_ONLY)!=0 ){ |
| 51781 | 51825 | rc = SQLITE_READONLY; |
| 51782 | 51826 | }else{ |
| 51783 | 51827 | rc = sqlite3PagerBegin(pBt->pPager,wrflag>1,sqlite3TempInMemory(p->db)); |
| 51784 | 51828 | if( rc==SQLITE_OK ){ |
| 51785 | 51829 | rc = newDatabase(pBt); |
| | @@ -51812,11 +51856,12 @@ |
| 51812 | 51856 | if( wrflag ){ |
| 51813 | 51857 | MemPage *pPage1 = pBt->pPage1; |
| 51814 | 51858 | #ifndef SQLITE_OMIT_SHARED_CACHE |
| 51815 | 51859 | assert( !pBt->pWriter ); |
| 51816 | 51860 | pBt->pWriter = p; |
| 51817 | | - pBt->isExclusive = (u8)(wrflag>1); |
| 51861 | + pBt->btsFlags &= ~BTS_EXCLUSIVE; |
| 51862 | + if( wrflag>1 ) pBt->btsFlags |= BTS_EXCLUSIVE; |
| 51818 | 51863 | #endif |
| 51819 | 51864 | |
| 51820 | 51865 | /* If the db-size header field is incorrect (as it may be if an old |
| 51821 | 51866 | ** client has been writing the database file), update it now. Doing |
| 51822 | 51867 | ** this sooner rather than later means the database size can safely |
| | @@ -52541,11 +52586,11 @@ |
| 52541 | 52586 | SQLITE_PRIVATE int sqlite3BtreeBeginStmt(Btree *p, int iStatement){ |
| 52542 | 52587 | int rc; |
| 52543 | 52588 | BtShared *pBt = p->pBt; |
| 52544 | 52589 | sqlite3BtreeEnter(p); |
| 52545 | 52590 | assert( p->inTrans==TRANS_WRITE ); |
| 52546 | | - assert( pBt->readOnly==0 ); |
| 52591 | + assert( (pBt->btsFlags & BTS_READ_ONLY)==0 ); |
| 52547 | 52592 | assert( iStatement>0 ); |
| 52548 | 52593 | assert( iStatement>p->db->nSavepoint ); |
| 52549 | 52594 | assert( pBt->inTransaction==TRANS_WRITE ); |
| 52550 | 52595 | /* At the pager level, a statement transaction is a savepoint with |
| 52551 | 52596 | ** an index greater than all savepoints created explicitly using |
| | @@ -52576,11 +52621,13 @@ |
| 52576 | 52621 | assert( op==SAVEPOINT_RELEASE || op==SAVEPOINT_ROLLBACK ); |
| 52577 | 52622 | assert( iSavepoint>=0 || (iSavepoint==-1 && op==SAVEPOINT_ROLLBACK) ); |
| 52578 | 52623 | sqlite3BtreeEnter(p); |
| 52579 | 52624 | rc = sqlite3PagerSavepoint(pBt->pPager, op, iSavepoint); |
| 52580 | 52625 | if( rc==SQLITE_OK ){ |
| 52581 | | - if( iSavepoint<0 && pBt->initiallyEmpty ) pBt->nPage = 0; |
| 52626 | + if( iSavepoint<0 && (pBt->btsFlags & BTS_INITIALLY_EMPTY)!=0 ){ |
| 52627 | + pBt->nPage = 0; |
| 52628 | + } |
| 52582 | 52629 | rc = newDatabase(pBt); |
| 52583 | 52630 | pBt->nPage = get4byte(28 + pBt->pPage1->aData); |
| 52584 | 52631 | |
| 52585 | 52632 | /* The database size was written into the offset 28 of the header |
| 52586 | 52633 | ** when the transaction started, so we know that the value at offset |
| | @@ -52646,11 +52693,11 @@ |
| 52646 | 52693 | /* Assert that the caller has opened the required transaction. */ |
| 52647 | 52694 | assert( p->inTrans>TRANS_NONE ); |
| 52648 | 52695 | assert( wrFlag==0 || p->inTrans==TRANS_WRITE ); |
| 52649 | 52696 | assert( pBt->pPage1 && pBt->pPage1->aData ); |
| 52650 | 52697 | |
| 52651 | | - if( NEVER(wrFlag && pBt->readOnly) ){ |
| 52698 | + if( NEVER(wrFlag && (pBt->btsFlags & BTS_READ_ONLY)!=0) ){ |
| 52652 | 52699 | return SQLITE_READONLY; |
| 52653 | 52700 | } |
| 52654 | 52701 | if( iTable==1 && btreePagecount(pBt)==0 ){ |
| 52655 | 52702 | assert( wrFlag==0 ); |
| 52656 | 52703 | iTable = 0; |
| | @@ -53726,22 +53773,21 @@ |
| 53726 | 53773 | ** the entire cell by checking for the cases where the record is |
| 53727 | 53774 | ** stored entirely within the b-tree page by inspecting the first |
| 53728 | 53775 | ** 2 bytes of the cell. |
| 53729 | 53776 | */ |
| 53730 | 53777 | int nCell = pCell[0]; |
| 53731 | | - if( !(nCell & 0x80) |
| 53732 | | - && nCell<=pPage->maxLocal |
| 53733 | | - && (pCell+nCell+1)<=pPage->aDataEnd |
| 53778 | + if( nCell<=pPage->max1bytePayload |
| 53779 | + /* && (pCell+nCell)<pPage->aDataEnd */ |
| 53734 | 53780 | ){ |
| 53735 | 53781 | /* This branch runs if the record-size field of the cell is a |
| 53736 | 53782 | ** single byte varint and the record fits entirely on the main |
| 53737 | 53783 | ** b-tree page. */ |
| 53738 | 53784 | testcase( pCell+nCell+1==pPage->aDataEnd ); |
| 53739 | 53785 | c = sqlite3VdbeRecordCompare(nCell, (void*)&pCell[1], pIdxKey); |
| 53740 | 53786 | }else if( !(pCell[1] & 0x80) |
| 53741 | 53787 | && (nCell = ((nCell&0x7f)<<7) + pCell[1])<=pPage->maxLocal |
| 53742 | | - && (pCell+nCell+2)<=pPage->aDataEnd |
| 53788 | + /* && (pCell+nCell+2)<=pPage->aDataEnd */ |
| 53743 | 53789 | ){ |
| 53744 | 53790 | /* The record-size field is a 2 byte varint and the record |
| 53745 | 53791 | ** fits entirely on the main b-tree page. */ |
| 53746 | 53792 | testcase( pCell+nCell+2==pPage->aDataEnd ); |
| 53747 | 53793 | c = sqlite3VdbeRecordCompare(nCell, (void*)&pCell[2], pIdxKey); |
| | @@ -54283,11 +54329,11 @@ |
| 54283 | 54329 | rc = sqlite3PagerWrite(pPage1->pDbPage); |
| 54284 | 54330 | if( rc ) goto freepage_out; |
| 54285 | 54331 | nFree = get4byte(&pPage1->aData[36]); |
| 54286 | 54332 | put4byte(&pPage1->aData[36], nFree+1); |
| 54287 | 54333 | |
| 54288 | | - if( pBt->secureDelete ){ |
| 54334 | + if( pBt->btsFlags & BTS_SECURE_DELETE ){ |
| 54289 | 54335 | /* If the secure_delete option is enabled, then |
| 54290 | 54336 | ** always fully overwrite deleted information with zeros. |
| 54291 | 54337 | */ |
| 54292 | 54338 | if( (!pPage && ((rc = btreeGetPage(pBt, iPage, &pPage, 0))!=0) ) |
| 54293 | 54339 | || ((rc = sqlite3PagerWrite(pPage->pDbPage))!=0) |
| | @@ -54344,11 +54390,11 @@ |
| 54344 | 54390 | */ |
| 54345 | 54391 | rc = sqlite3PagerWrite(pTrunk->pDbPage); |
| 54346 | 54392 | if( rc==SQLITE_OK ){ |
| 54347 | 54393 | put4byte(&pTrunk->aData[4], nLeaf+1); |
| 54348 | 54394 | put4byte(&pTrunk->aData[8+nLeaf*4], iPage); |
| 54349 | | - if( pPage && !pBt->secureDelete ){ |
| 54395 | + if( pPage && (pBt->btsFlags & BTS_SECURE_DELETE)==0 ){ |
| 54350 | 54396 | sqlite3PagerDontWrite(pPage->pDbPage); |
| 54351 | 54397 | } |
| 54352 | 54398 | rc = btreeSetHasContent(pBt, iPage); |
| 54353 | 54399 | } |
| 54354 | 54400 | TRACE(("FREE-PAGE: %d leaf on trunk page %d\n",pPage->pgno,pTrunk->pgno)); |
| | @@ -55185,11 +55231,11 @@ |
| 55185 | 55231 | ** But not if we are in secure-delete mode. In secure-delete mode, |
| 55186 | 55232 | ** the dropCell() routine will overwrite the entire cell with zeroes. |
| 55187 | 55233 | ** In this case, temporarily copy the cell into the aOvflSpace[] |
| 55188 | 55234 | ** buffer. It will be copied out again as soon as the aSpace[] buffer |
| 55189 | 55235 | ** is allocated. */ |
| 55190 | | - if( pBt->secureDelete ){ |
| 55236 | + if( pBt->btsFlags & BTS_SECURE_DELETE ){ |
| 55191 | 55237 | int iOff; |
| 55192 | 55238 | |
| 55193 | 55239 | iOff = SQLITE_PTR_TO_INT(apDiv[i]) - SQLITE_PTR_TO_INT(pParent->aData); |
| 55194 | 55240 | if( (iOff+szNew[i])>(int)pBt->usableSize ){ |
| 55195 | 55241 | rc = SQLITE_CORRUPT_BKPT; |
| | @@ -55927,11 +55973,12 @@ |
| 55927 | 55973 | assert( pCur->skipNext!=SQLITE_OK ); |
| 55928 | 55974 | return pCur->skipNext; |
| 55929 | 55975 | } |
| 55930 | 55976 | |
| 55931 | 55977 | assert( cursorHoldsMutex(pCur) ); |
| 55932 | | - assert( pCur->wrFlag && pBt->inTransaction==TRANS_WRITE && !pBt->readOnly ); |
| 55978 | + assert( pCur->wrFlag && pBt->inTransaction==TRANS_WRITE |
| 55979 | + && (pBt->btsFlags & BTS_READ_ONLY)==0 ); |
| 55933 | 55980 | assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) ); |
| 55934 | 55981 | |
| 55935 | 55982 | /* Assert that the caller has been consistent. If this cursor was opened |
| 55936 | 55983 | ** expecting an index b-tree, then the caller should be inserting blob |
| 55937 | 55984 | ** keys with no associated data. If the cursor was opened expecting an |
| | @@ -56056,11 +56103,11 @@ |
| 56056 | 56103 | int iCellIdx; /* Index of cell to delete */ |
| 56057 | 56104 | int iCellDepth; /* Depth of node containing pCell */ |
| 56058 | 56105 | |
| 56059 | 56106 | assert( cursorHoldsMutex(pCur) ); |
| 56060 | 56107 | assert( pBt->inTransaction==TRANS_WRITE ); |
| 56061 | | - assert( !pBt->readOnly ); |
| 56108 | + assert( (pBt->btsFlags & BTS_READ_ONLY)==0 ); |
| 56062 | 56109 | assert( pCur->wrFlag ); |
| 56063 | 56110 | assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) ); |
| 56064 | 56111 | assert( !hasReadConflicts(p, pCur->pgnoRoot) ); |
| 56065 | 56112 | |
| 56066 | 56113 | if( NEVER(pCur->aiIdx[pCur->iPage]>=pCur->apPage[pCur->iPage]->nCell) |
| | @@ -56177,11 +56224,11 @@ |
| 56177 | 56224 | int rc; |
| 56178 | 56225 | int ptfFlags; /* Page-type flage for the root page of new table */ |
| 56179 | 56226 | |
| 56180 | 56227 | assert( sqlite3BtreeHoldsMutex(p) ); |
| 56181 | 56228 | assert( pBt->inTransaction==TRANS_WRITE ); |
| 56182 | | - assert( !pBt->readOnly ); |
| 56229 | + assert( (pBt->btsFlags & BTS_READ_ONLY)==0 ); |
| 56183 | 56230 | |
| 56184 | 56231 | #ifdef SQLITE_OMIT_AUTOVACUUM |
| 56185 | 56232 | rc = allocateBtreePage(pBt, &pRoot, &pgnoRoot, 1, 0); |
| 56186 | 56233 | if( rc ){ |
| 56187 | 56234 | return rc; |
| | @@ -56551,11 +56598,13 @@ |
| 56551 | 56598 | *pMeta = get4byte(&pBt->pPage1->aData[36 + idx*4]); |
| 56552 | 56599 | |
| 56553 | 56600 | /* If auto-vacuum is disabled in this build and this is an auto-vacuum |
| 56554 | 56601 | ** database, mark the database as read-only. */ |
| 56555 | 56602 | #ifdef SQLITE_OMIT_AUTOVACUUM |
| 56556 | | - if( idx==BTREE_LARGEST_ROOT_PAGE && *pMeta>0 ) pBt->readOnly = 1; |
| 56603 | + if( idx==BTREE_LARGEST_ROOT_PAGE && *pMeta>0 ){ |
| 56604 | + pBt->btsFlags |= BTS_READ_ONLY; |
| 56605 | + } |
| 56557 | 56606 | #endif |
| 56558 | 56607 | |
| 56559 | 56608 | sqlite3BtreeLeave(p); |
| 56560 | 56609 | } |
| 56561 | 56610 | |
| | @@ -57351,11 +57400,12 @@ |
| 57351 | 57400 | ** (e) the cursor points at a valid row of an intKey table. |
| 57352 | 57401 | */ |
| 57353 | 57402 | if( !pCsr->wrFlag ){ |
| 57354 | 57403 | return SQLITE_READONLY; |
| 57355 | 57404 | } |
| 57356 | | - assert( !pCsr->pBt->readOnly && pCsr->pBt->inTransaction==TRANS_WRITE ); |
| 57405 | + assert( (pCsr->pBt->btsFlags & BTS_READ_ONLY)==0 |
| 57406 | + && pCsr->pBt->inTransaction==TRANS_WRITE ); |
| 57357 | 57407 | assert( hasSharedCacheTableLock(pCsr->pBtree, pCsr->pgnoRoot, 0, 2) ); |
| 57358 | 57408 | assert( !hasReadConflicts(pCsr->pBtree, pCsr->pgnoRoot) ); |
| 57359 | 57409 | assert( pCsr->apPage[pCsr->iPage]->intKey ); |
| 57360 | 57410 | |
| 57361 | 57411 | return accessPayload(pCsr, offset, amt, (unsigned char *)z, 1); |
| | @@ -57391,11 +57441,12 @@ |
| 57391 | 57441 | assert( iVersion==1 || iVersion==2 ); |
| 57392 | 57442 | |
| 57393 | 57443 | /* If setting the version fields to 1, do not automatically open the |
| 57394 | 57444 | ** WAL connection, even if the version fields are currently set to 2. |
| 57395 | 57445 | */ |
| 57396 | | - pBt->doNotUseWAL = (u8)(iVersion==1); |
| 57446 | + pBt->btsFlags &= ~BTS_NO_WAL; |
| 57447 | + if( iVersion==1 ) pBt->btsFlags |= BTS_NO_WAL; |
| 57397 | 57448 | |
| 57398 | 57449 | rc = sqlite3BtreeBeginTrans(pBtree, 0); |
| 57399 | 57450 | if( rc==SQLITE_OK ){ |
| 57400 | 57451 | u8 *aData = pBt->pPage1->aData; |
| 57401 | 57452 | if( aData[18]!=(u8)iVersion || aData[19]!=(u8)iVersion ){ |
| | @@ -57408,11 +57459,11 @@ |
| 57408 | 57459 | } |
| 57409 | 57460 | } |
| 57410 | 57461 | } |
| 57411 | 57462 | } |
| 57412 | 57463 | |
| 57413 | | - pBt->doNotUseWAL = 0; |
| 57464 | + pBt->btsFlags &= ~BTS_NO_WAL; |
| 57414 | 57465 | return rc; |
| 57415 | 57466 | } |
| 57416 | 57467 | |
| 57417 | 57468 | /************** End of btree.c ***********************************************/ |
| 57418 | 57469 | /************** Begin file backup.c ******************************************/ |
| | @@ -58092,13 +58143,13 @@ |
| 58092 | 58143 | |
| 58093 | 58144 | assert( sqlite3BtreeIsInTrans(pTo) ); |
| 58094 | 58145 | pFd = sqlite3PagerFile(sqlite3BtreePager(pTo)); |
| 58095 | 58146 | if( pFd->pMethods ){ |
| 58096 | 58147 | i64 nByte = sqlite3BtreeGetPageSize(pFrom)*(i64)sqlite3BtreeLastPage(pFrom); |
| 58097 | | - sqlite3BeginBenignMalloc(); |
| 58098 | | - sqlite3OsFileControl(pFd, SQLITE_FCNTL_OVERWRITE, &nByte); |
| 58099 | | - sqlite3EndBenignMalloc(); |
| 58148 | + rc = sqlite3OsFileControl(pFd, SQLITE_FCNTL_OVERWRITE, &nByte); |
| 58149 | + if( rc==SQLITE_NOTFOUND ) rc = SQLITE_OK; |
| 58150 | + if( rc ) goto copy_finished; |
| 58100 | 58151 | } |
| 58101 | 58152 | |
| 58102 | 58153 | /* Set up an sqlite3_backup object. sqlite3_backup.pDestDb must be set |
| 58103 | 58154 | ** to 0. This is used by the implementations of sqlite3_backup_step() |
| 58104 | 58155 | ** and sqlite3_backup_finish() to detect that they are being called |
| | @@ -58119,16 +58170,17 @@ |
| 58119 | 58170 | */ |
| 58120 | 58171 | sqlite3_backup_step(&b, 0x7FFFFFFF); |
| 58121 | 58172 | assert( b.rc!=SQLITE_OK ); |
| 58122 | 58173 | rc = sqlite3_backup_finish(&b); |
| 58123 | 58174 | if( rc==SQLITE_OK ){ |
| 58124 | | - pTo->pBt->pageSizeFixed = 0; |
| 58175 | + pTo->pBt->btsFlags &= ~BTS_PAGESIZE_FIXED; |
| 58125 | 58176 | }else{ |
| 58126 | 58177 | sqlite3PagerClearCache(sqlite3BtreePager(b.pDest)); |
| 58127 | 58178 | } |
| 58128 | 58179 | |
| 58129 | 58180 | assert( sqlite3BtreeIsInTrans(pTo)==0 ); |
| 58181 | +copy_finished: |
| 58130 | 58182 | sqlite3BtreeLeave(pFrom); |
| 58131 | 58183 | sqlite3BtreeLeave(pTo); |
| 58132 | 58184 | return rc; |
| 58133 | 58185 | } |
| 58134 | 58186 | #endif /* SQLITE_OMIT_VACUUM */ |
| | @@ -58151,16 +58203,10 @@ |
| 58151 | 58203 | ** stores a single value in the VDBE. Mem is an opaque structure visible |
| 58152 | 58204 | ** only within the VDBE. Interface routines refer to a Mem using the |
| 58153 | 58205 | ** name sqlite_value |
| 58154 | 58206 | */ |
| 58155 | 58207 | |
| 58156 | | -/* |
| 58157 | | -** Call sqlite3VdbeMemExpandBlob() on the supplied value (type Mem*) |
| 58158 | | -** P if required. |
| 58159 | | -*/ |
| 58160 | | -#define expandBlob(P) (((P)->flags&MEM_Zero)?sqlite3VdbeMemExpandBlob(P):0) |
| 58161 | | - |
| 58162 | 58208 | /* |
| 58163 | 58209 | ** If pMem is an object with a valid string representation, this routine |
| 58164 | 58210 | ** ensures the internal encoding for the string representation is |
| 58165 | 58211 | ** 'desiredEnc', one of SQLITE_UTF8, SQLITE_UTF16LE or SQLITE_UTF16BE. |
| 58166 | 58212 | ** |
| | @@ -58256,11 +58302,11 @@ |
| 58256 | 58302 | */ |
| 58257 | 58303 | SQLITE_PRIVATE int sqlite3VdbeMemMakeWriteable(Mem *pMem){ |
| 58258 | 58304 | int f; |
| 58259 | 58305 | assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) ); |
| 58260 | 58306 | assert( (pMem->flags&MEM_RowSet)==0 ); |
| 58261 | | - expandBlob(pMem); |
| 58307 | + ExpandBlob(pMem); |
| 58262 | 58308 | f = pMem->flags; |
| 58263 | 58309 | if( (f&(MEM_Str|MEM_Blob)) && pMem->z!=pMem->zMalloc ){ |
| 58264 | 58310 | if( sqlite3VdbeMemGrow(pMem, pMem->n + 2, 1) ){ |
| 58265 | 58311 | return SQLITE_NOMEM; |
| 58266 | 58312 | } |
| | @@ -59093,11 +59139,11 @@ |
| 59093 | 59139 | if( pVal->flags&MEM_Null ){ |
| 59094 | 59140 | return 0; |
| 59095 | 59141 | } |
| 59096 | 59142 | assert( (MEM_Blob>>3) == MEM_Str ); |
| 59097 | 59143 | pVal->flags |= (pVal->flags & MEM_Blob)>>3; |
| 59098 | | - expandBlob(pVal); |
| 59144 | + ExpandBlob(pVal); |
| 59099 | 59145 | if( pVal->flags&MEM_Str ){ |
| 59100 | 59146 | sqlite3VdbeChangeEncoding(pVal, enc & ~SQLITE_UTF16_ALIGNED); |
| 59101 | 59147 | if( (enc & SQLITE_UTF16_ALIGNED)!=0 && 1==(1&SQLITE_PTR_TO_INT(pVal->z)) ){ |
| 59102 | 59148 | assert( (pVal->flags & (MEM_Ephem|MEM_Static))!=0 ); |
| 59103 | 59149 | if( sqlite3VdbeMemMakeWriteable(pVal)!=SQLITE_OK ){ |
| | @@ -64300,16 +64346,10 @@ |
| 64300 | 64346 | */ |
| 64301 | 64347 | #define Deephemeralize(P) \ |
| 64302 | 64348 | if( ((P)->flags&MEM_Ephem)!=0 \ |
| 64303 | 64349 | && sqlite3VdbeMemMakeWriteable(P) ){ goto no_mem;} |
| 64304 | 64350 | |
| 64305 | | -/* |
| 64306 | | -** Call sqlite3VdbeMemExpandBlob() on the supplied value (type Mem*) |
| 64307 | | -** P if required. |
| 64308 | | -*/ |
| 64309 | | -#define ExpandBlob(P) (((P)->flags&MEM_Zero)?sqlite3VdbeMemExpandBlob(P):0) |
| 64310 | | - |
| 64311 | 64351 | /* Return true if the cursor was opened using the OP_OpenSorter opcode. */ |
| 64312 | 64352 | #ifdef SQLITE_OMIT_MERGE_SORT |
| 64313 | 64353 | # define isSorter(x) 0 |
| 64314 | 64354 | #else |
| 64315 | 64355 | # define isSorter(x) ((x)->pSorter!=0) |
| | @@ -92659,11 +92699,11 @@ |
| 92659 | 92699 | if( sqlite3StrICmp(zLeft, "lock_proxy_file")==0 ){ |
| 92660 | 92700 | if( !zRight ){ |
| 92661 | 92701 | Pager *pPager = sqlite3BtreePager(pDb->pBt); |
| 92662 | 92702 | char *proxy_file_path = NULL; |
| 92663 | 92703 | sqlite3_file *pFile = sqlite3PagerFile(pPager); |
| 92664 | | - sqlite3OsFileControl(pFile, SQLITE_GET_LOCKPROXYFILE, |
| 92704 | + sqlite3OsFileControlHint(pFile, SQLITE_GET_LOCKPROXYFILE, |
| 92665 | 92705 | &proxy_file_path); |
| 92666 | 92706 | |
| 92667 | 92707 | if( proxy_file_path ){ |
| 92668 | 92708 | sqlite3VdbeSetNumCols(v, 1); |
| 92669 | 92709 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, |
| | @@ -123271,11 +123311,11 @@ |
| 123271 | 123311 | typedef struct porter_tokenizer { |
| 123272 | 123312 | sqlite3_tokenizer base; /* Base class */ |
| 123273 | 123313 | } porter_tokenizer; |
| 123274 | 123314 | |
| 123275 | 123315 | /* |
| 123276 | | -** Class derived from sqlit3_tokenizer_cursor |
| 123316 | +** Class derived from sqlite3_tokenizer_cursor |
| 123277 | 123317 | */ |
| 123278 | 123318 | typedef struct porter_tokenizer_cursor { |
| 123279 | 123319 | sqlite3_tokenizer_cursor base; |
| 123280 | 123320 | const char *zInput; /* input we are tokenizing */ |
| 123281 | 123321 | int nInput; /* size of the input */ |
| 123282 | 123322 | |