From: dan Date: Mon, 15 Sep 2014 19:34:04 +0000 (+0000) Subject: Remove the experimental sqlite3_transaction_save() and restore() APIs. X-Git-Tag: version-3.8.11~252^2~101 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=15e1ec4c5ba7436864b168e062952cc041b23cfd;p=thirdparty%2Fsqlite.git Remove the experimental sqlite3_transaction_save() and restore() APIs. FossilOrigin-Name: 48d201cd8b68c0377cf8a2cc6439b893f9462fe2 --- diff --git a/ext/ota/ota1.test b/ext/ota/ota1.test index 917d1d2c9e..60cc4fc30e 100644 --- a/ext/ota/ota1.test +++ b/ext/ota/ota1.test @@ -219,6 +219,12 @@ foreach {tn2 cmd} {1 run_ota 2 step_ota} { CREATE INDEX i2 ON t1(c, b); CREATE INDEX i3 ON t1(c, b, c); } + 4 { + CREATE TABLE t1(a INT PRIMARY KEY, b, c) WITHOUT ROWID; + CREATE INDEX i1 ON t1(b); + CREATE INDEX i2 ON t1(c, b); + CREATE INDEX i3 ON t1(c, b, c); + } } { reset_db execsql $schema @@ -261,6 +267,15 @@ foreach {tn2 cmd} {1 run_ota 2 step_ota} { CREATE INDEX i5 ON t1(c); CREATE INDEX i6 ON t1(c, b); } + 3 { + CREATE TABLE t1(a PRIMARY KEY, b, c, d) WITHOUT ROWID; + CREATE INDEX i1 ON t1(d); + CREATE INDEX i2 ON t1(d, c); + CREATE INDEX i3 ON t1(d, c, b); + CREATE INDEX i4 ON t1(b); + CREATE INDEX i5 ON t1(c); + CREATE INDEX i6 ON t1(c, b); + } } { reset_db execsql $schema diff --git a/manifest b/manifest index e463fef402..7898dc2ecf 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Merge\slatest\strunk\sfixes\sinto\sthis\sbranch. -D 2014-09-15T16:57:10.623 +C Remove\sthe\sexperimental\ssqlite3_transaction_save()\sand\srestore()\sAPIs. +D 2014-09-15T19:34:04.372 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in cf57f673d77606ab0f2d9627ca52a9ba1464146a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -122,7 +122,7 @@ F ext/misc/vfslog.c fe40fab5c077a40477f7e5eba994309ecac6cc95 F ext/misc/vtshim.c babb0dc2bf116029e3e7c9a618b8a1377045303e F ext/misc/wholenumber.c 784b12543d60702ebdd47da936e278aa03076212 F ext/ota/ota.c d37097e92a005d3915883adefbb93019ea6f8841 -F ext/ota/ota1.test fe0bb8acf0caef6c19937b84c6547b788342610d +F ext/ota/ota1.test 7cbf37a9f6cd29320f47b041cfeb0cc1d7eaa916 F ext/ota/ota2.test 13f76922446c62ed96192e938b8e625ebf0142fa F ext/ota/ota3.test 1c48b7476af1c5920db9a43e7b1476d421a463b5 F ext/ota/sqlite3ota.c 668ed08dd81ff8ae1e8524b2d4bf0f2609cbf907 @@ -199,7 +199,7 @@ F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d F src/legacy.c ba1863ea58c4c840335a84ec276fc2b25e22bc4e F src/lempar.c 7274c97d24bb46631e504332ccd3bd1b37841770 F src/loadext.c de741e66e5ddc1598d904d7289239696e40ed994 -F src/main.c 6b9fd1867a5575db2119f850302a883e7684009c +F src/main.c d15621461fb0c52675eba2b650492ed1beef69ab F src/malloc.c cc015821ba267ad5c91dc8761d0498a3fc3ce6ce F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c faf615aafd8be74a71494dfa027c113ea5c6615f @@ -220,21 +220,21 @@ F src/os_setup.h c9d4553b5aaa6f73391448b265b89bed0b890faa F src/os_unix.c addd023b26c623fec4dedc110fc4370a65b4768c F src/os_win.c 0a4042ef35f322e86fa01f6c8884c5e645b911e7 F src/os_win.h 09e751b20bbc107ffbd46e13555dc73576d88e21 -F src/pager.c b7c625fc92e86fea1971b8a630009eab3ff18997 -F src/pager.h 6a08df06b7edc3684375c0fab40602c695a044f2 +F src/pager.c c1cdf5509386b5c3695082655ce6de6431d920d6 +F src/pager.h 5c13927809e1c35d85e82e14342d817df3019e07 F src/parse.y 22d6a074e5f5a7258947a1dc55a9bf946b765dd0 F src/pcache.c 4121a0571c18581ee9f82f086d5e2030051ebd6a F src/pcache.h 9b559127b83f84ff76d735c8262f04853be0c59a F src/pcache1.c dab8ab930d4a73b99768d881185994f34b80ecaa -F src/pragma.c 5dba6b386cbfe0b094350b7d6c99fd410958f22d -F src/prepare.c 905c3c601ccadd22bb70b63cd48392f7126c9807 +F src/pragma.c c401b5ddbb5c882e2b9d9e16fad2abd8b4a86564 +F src/prepare.c 6ef0cf2f9274982988ed6b7cab1be23147e94196 F src/printf.c e74925089a85e3c9f0e315595f41c139d3d118c2 F src/random.c d10c1f85b6709ca97278428fd5db5bbb9c74eece F src/resolve.c a3466128b52a86c466e47ac1a19e2174f7b5cf89 F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e F src/select.c 0cd6706fd52ae5db229e9041094db6ec27195335 F src/shell.c c00220cdd7f2027780bc25b78376c16dc24e4b7d -F src/sqlite.h.in 5bcaca9d5a8403fda0c8677de4c527907b317f1d +F src/sqlite.h.in a98b0429855f023074f44a63dba23d11469ebc6d F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d F src/sqliteInt.h 3210f8bd040d1c6d8b1616325b15dd3ff749e48f @@ -242,7 +242,7 @@ F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d F src/status.c 7ac05a5c7017d0b9f0b4bcd701228b784f987158 F src/table.c 218ae2ba022881846741dfc8351aefdf129e0377 F src/tclsqlite.c ac7d1672f69c9d69defeb022f656d04f5cefd198 -F src/test1.c 75655557ebc7138e1d745313635b6b100c90c151 +F src/test1.c 44562bf344a6b12a273f46fd906631ef301a6416 F src/test2.c 98049e51a17dc62606a99a9eb95ee477f9996712 F src/test3.c 1c0e5d6f080b8e33c1ce8b3078e7013fdbcd560c F src/test4.c 9b32d22f5f150abe23c1830e2057c4037c45b3df @@ -304,8 +304,8 @@ F src/vdbemem.c dc36ea9fe26c25550c50085f388167086ef7d73a F src/vdbesort.c a7a40ceca6325b853040ffcc363dcd49a45f201b F src/vdbetrace.c 16d39c1ef7d1f4a3a7464bea3b7b4bdd7849c415 F src/vtab.c 019dbfd0406a7447c990e1f7bd1dfcdb8895697f -F src/wal.c 6f5ff51117293e7b2c75ad21834f51115e59ea96 -F src/wal.h 237bc4484f7c289f094ecb6efb2b6c02005484e1 +F src/wal.c 3c56c85d80a17b51cd8cb0bed5c1ecc4f0771012 +F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 F src/walker.c c253b95b4ee44b21c406e2a1052636c31ea27804 F src/where.c 839b5e1db2507e221ad1c308f148a8519ed750be F src/whereInt.h 124d970450955a6982e174b07c320ae6d62a595c @@ -1204,7 +1204,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 55b8011d5b455927f5b92a3cb911fd909fb0edab 4060efb646c873c4abde7ab9ddf330489a44f274 -R a8de04acab3d1132246bf5d89e41e027 +P 5efafef51d146bcba3adc425561bfa1ac083c0a7 +R 684c9325f89b1d695bf7f6172a6df69f U dan -Z 1d00f387d17c6184cf9c7c454dc66aca +Z 4568916327f8707f39b56bf66a2404a6 diff --git a/manifest.uuid b/manifest.uuid index 607c43815f..282b6874b8 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5efafef51d146bcba3adc425561bfa1ac083c0a7 \ No newline at end of file +48d201cd8b68c0377cf8a2cc6439b893f9462fe2 \ No newline at end of file diff --git a/src/main.c b/src/main.c index 6da74cbf2a..231890de4b 100644 --- a/src/main.c +++ b/src/main.c @@ -3473,15 +3473,3 @@ int sqlite3_db_readonly(sqlite3 *db, const char *zDbName){ Btree *pBt = sqlite3DbNameToBtree(db, zDbName); return pBt ? sqlite3BtreeIsReadonly(pBt) : -1; } - -int sqlite3_transaction_save(sqlite3 *db, void **ppState, int *pnState){ - Pager *pPager = sqlite3BtreePager(db->aDb[0].pBt); - return sqlite3PagerSaveState(pPager, ppState, pnState); -} - -int sqlite3_transaction_restore(sqlite3 *db, const void *pState, int nState){ - Pager *pPager = sqlite3BtreePager(db->aDb[0].pBt); - return sqlite3PagerRestoreState(pPager, pState, nState); -} - - diff --git a/src/pager.c b/src/pager.c index 3ab29f21b6..7de6a65550 100644 --- a/src/pager.c +++ b/src/pager.c @@ -7237,41 +7237,6 @@ int sqlite3PagerCloseWal(Pager *pPager){ return rc; } -int sqlite3PagerSaveState(Pager *pPager, void **ppState, int *pnState){ - int rc = SQLITE_OK; - *ppState = 0; - *pnState = 0; - if( pPager->pWal==0 || pPager->eStatepPCache); - rc = sqlite3WalFrames(pPager->pWal, - pPager->pageSize, pList, 0, 0, pPager->walSyncFlags - ); - if( rc==SQLITE_OK ){ - rc = sqlite3WalSaveState(pPager->pWal, ppState, pnState); - } - } - return rc; -} - -int sqlite3PagerRestoreState(Pager *pPager, const void *pState, int nState){ - int rc = SQLITE_OK; - if( pPager->pWal==0 - || pPager->eStatepPCache) - ){ - rc = SQLITE_ERROR; - }else{ - sqlite3PcacheTruncate(pPager->pPCache, 1); - rc = sqlite3WalRestoreState(pPager->pWal, pState, nState); - pPager->eState = PAGER_WRITER_CACHEMOD; - } - - return rc; -} - #endif /* !SQLITE_OMIT_WAL */ #ifdef SQLITE_ENABLE_ZIPVFS diff --git a/src/pager.h b/src/pager.h index fd2624c3fa..57948079d2 100644 --- a/src/pager.h +++ b/src/pager.h @@ -207,9 +207,6 @@ void *sqlite3PagerCodec(DbPage *); # define enable_simulated_io_errors() #endif -int sqlite3PagerSaveState(Pager *pPager, void **ppState, int *pnState); -int sqlite3PagerRestoreState(Pager *pPager, const void *pState, int nState); - int sqlite3PagerSetOtaMode(Pager *pPager, int bOta); #endif /* _PAGER_H_ */ diff --git a/src/pragma.c b/src/pragma.c index 734f4aa98e..9785a33c26 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -482,7 +482,6 @@ static const struct sPragmaNames { #endif }; /* Number of pragmas: 59 on by default, 72 total. */ -/* Number of pragmas: 58 on by default, 71 total. */ /* End of the automatically generated pragma table. ***************************************************************************/ diff --git a/src/prepare.c b/src/prepare.c index 2e2be0ec47..a05e619f3e 100644 --- a/src/prepare.c +++ b/src/prepare.c @@ -797,6 +797,7 @@ int sqlite3_prepare_v2( return rc; } + #ifndef SQLITE_OMIT_UTF16 /* ** Compile the UTF-16 encoded SQL statement zSql into a statement handle. diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 2222451859..2ad571ed0b 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -7464,25 +7464,6 @@ int sqlite3_index_writer( int **paiCol, int *pnCol /* OUT: See above */ ); -/* -** This function is used to save the state of an ongoing WAL mode write -** transaction on the "main" database of the supplied database handle. -** -** If successful, SQLITE_OK is returned and output variable (*ppState) -** is set to point to a buffer containing the transaction state data. -** (*pnState) is set to the size of that buffer in bytes. Otherwise, if -** an error occurs, an SQLite error code is returned and both output -** variables are zeroed. -** -** A transaction state may be saved if: -** -** * the transaction does not contain any schema modifications. -** * there are no open sub-transactions. -*/ -int sqlite3_transaction_save(sqlite3 *db, void **ppState, int *pnState); - -int sqlite3_transaction_restore(sqlite3 *db, const void *pState, int nState); - /* ** Undo the hack that converts floating point types to integer for ** builds on processors without floating point support. diff --git a/src/test1.c b/src/test1.c index abeb15e8fc..14785c35b3 100644 --- a/src/test1.c +++ b/src/test1.c @@ -6497,70 +6497,6 @@ static int sorter_test_sort4_helper( } -/* -** tclcmd: sqlite3_transaction_save DB -*/ -static int testTransactionSave( - void * clientData, - Tcl_Interp *interp, - int objc, - Tcl_Obj *CONST objv[] -){ - void *pState; - int nState; - sqlite3 *db; - int rc; - - if( objc!=2 ){ - Tcl_WrongNumArgs(interp, 1, objv, "DB"); - return TCL_ERROR; - } - if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; - - rc = sqlite3_transaction_save(db, &pState, &nState); - if( rc==SQLITE_OK ){ - Tcl_SetObjResult(interp, Tcl_NewByteArrayObj(pState, nState)); - }else{ - Tcl_SetObjResult(interp, Tcl_NewStringObj(sqlite3ErrName(rc), -1)); - return TCL_ERROR; - } - - sqlite3_free(pState); - return TCL_OK; -} - -/* -** tclcmd: sqlite3_transaction_restore DB BLOB -*/ -static int testTransactionRestore( - void * clientData, - Tcl_Interp *interp, - int objc, - Tcl_Obj *CONST objv[] -){ - void *pState; - int nState; - sqlite3 *db; - int rc; - - if( objc!=3 ){ - Tcl_WrongNumArgs(interp, 1, objv, "DB BLOB"); - return TCL_ERROR; - } - if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; - pState = (void*)Tcl_GetByteArrayFromObj(objv[2], &nState); - - rc = sqlite3_transaction_restore(db, pState, nState); - if( rc==SQLITE_OK ){ - Tcl_ResetResult(interp); - }else{ - Tcl_SetObjResult(interp, Tcl_NewStringObj(sqlite3ErrName(rc), -1)); - return TCL_ERROR; - } - - return TCL_OK; -} - #ifdef SQLITE_USER_AUTHENTICATION #include "sqlite3userauth.h" /* @@ -6924,8 +6860,6 @@ int Sqlitetest1_Init(Tcl_Interp *interp){ { "load_static_extension", tclLoadStaticExtensionCmd }, { "sorter_test_fakeheap", sorter_test_fakeheap }, { "sorter_test_sort4_helper", sorter_test_sort4_helper }, - { "sqlite3_transaction_save", testTransactionSave }, - { "sqlite3_transaction_restore", testTransactionRestore }, #ifdef SQLITE_USER_AUTHENTICATION { "sqlite3_user_authenticate", test_user_authenticate, 0 }, { "sqlite3_user_add", test_user_add, 0 }, diff --git a/src/wal.c b/src/wal.c index 80539807b1..aa797dfb53 100644 --- a/src/wal.c +++ b/src/wal.c @@ -1046,62 +1046,6 @@ static int walIndexAppend(Wal *pWal, u32 iFrame, u32 iPage){ return rc; } -static int walFileReadHdr(Wal *pWal, int *pbValid){ - u8 aBuf[WAL_HDRSIZE]; /* Buffer to load WAL header into */ - int rc; /* Return code */ - u32 magic; /* Magic value read from WAL header */ - int szPage; /* Page size according to the log */ - u32 version; /* Magic value read from WAL header */ - - *pbValid = 0; - - /* Read in the WAL header. */ - rc = sqlite3OsRead(pWal->pWalFd, aBuf, WAL_HDRSIZE, 0); - if( rc!=SQLITE_OK ){ - return rc; - } - - /* If the database page size is not a power of two, or is greater than - ** SQLITE_MAX_PAGE_SIZE, conclude that the WAL file contains no valid - ** data. Similarly, if the 'magic' value is invalid, ignore the whole - ** WAL file. - */ - magic = sqlite3Get4byte(&aBuf[0]); - szPage = sqlite3Get4byte(&aBuf[8]); - if( (magic&0xFFFFFFFE)!=WAL_MAGIC - || szPage&(szPage-1) - || szPage>SQLITE_MAX_PAGE_SIZE - || szPage<512 - ){ - return SQLITE_OK; - } - - pWal->hdr.bigEndCksum = (u8)(magic&0x00000001); - pWal->szPage = szPage; - pWal->nCkpt = sqlite3Get4byte(&aBuf[12]); - memcpy(&pWal->hdr.aSalt, &aBuf[16], 8); - - /* Verify that the WAL header checksum is correct */ - walChecksumBytes(pWal->hdr.bigEndCksum==SQLITE_BIGENDIAN, - aBuf, WAL_HDRSIZE-2*4, 0, pWal->hdr.aFrameCksum - ); - if( pWal->hdr.aFrameCksum[0]!=sqlite3Get4byte(&aBuf[24]) - || pWal->hdr.aFrameCksum[1]!=sqlite3Get4byte(&aBuf[28]) - ){ - return SQLITE_OK; - } - - /* Verify that the version number on the WAL format is one that - ** are able to understand */ - version = sqlite3Get4byte(&aBuf[4]); - if( version!=WAL_MAX_VERSION ){ - return SQLITE_CANTOPEN_BKPT; - } - - *pbValid = 1; - return SQLITE_OK; -} - /* ** Recover the wal-index by reading the write-ahead log file. @@ -1146,18 +1090,59 @@ static int walIndexRecover(Wal *pWal){ } if( nSize>WAL_HDRSIZE ){ + u8 aBuf[WAL_HDRSIZE]; /* Buffer to load WAL header into */ u8 *aFrame = 0; /* Malloc'd buffer to load entire frame */ int szFrame; /* Number of bytes in buffer aFrame[] */ u8 *aData; /* Pointer to data part of aFrame buffer */ int iFrame; /* Index of last frame read */ i64 iOffset; /* Next offset to read from log file */ int szPage; /* Page size according to the log */ + u32 magic; /* Magic value read from WAL header */ + u32 version; /* Magic value read from WAL header */ int isValid; /* True if this frame is valid */ - rc = walFileReadHdr(pWal, &isValid); - if( rc!=SQLITE_OK ) goto recovery_error; - if( isValid==0 ) goto finished; - szPage = pWal->szPage; + /* Read in the WAL header. */ + rc = sqlite3OsRead(pWal->pWalFd, aBuf, WAL_HDRSIZE, 0); + if( rc!=SQLITE_OK ){ + goto recovery_error; + } + + /* If the database page size is not a power of two, or is greater than + ** SQLITE_MAX_PAGE_SIZE, conclude that the WAL file contains no valid + ** data. Similarly, if the 'magic' value is invalid, ignore the whole + ** WAL file. + */ + magic = sqlite3Get4byte(&aBuf[0]); + szPage = sqlite3Get4byte(&aBuf[8]); + if( (magic&0xFFFFFFFE)!=WAL_MAGIC + || szPage&(szPage-1) + || szPage>SQLITE_MAX_PAGE_SIZE + || szPage<512 + ){ + goto finished; + } + pWal->hdr.bigEndCksum = (u8)(magic&0x00000001); + pWal->szPage = szPage; + pWal->nCkpt = sqlite3Get4byte(&aBuf[12]); + memcpy(&pWal->hdr.aSalt, &aBuf[16], 8); + + /* Verify that the WAL header checksum is correct */ + walChecksumBytes(pWal->hdr.bigEndCksum==SQLITE_BIGENDIAN, + aBuf, WAL_HDRSIZE-2*4, 0, pWal->hdr.aFrameCksum + ); + if( pWal->hdr.aFrameCksum[0]!=sqlite3Get4byte(&aBuf[24]) + || pWal->hdr.aFrameCksum[1]!=sqlite3Get4byte(&aBuf[28]) + ){ + goto finished; + } + + /* Verify that the version number on the WAL format is one that + ** are able to understand */ + version = sqlite3Get4byte(&aBuf[4]); + if( version!=WAL_MAX_VERSION ){ + rc = SQLITE_CANTOPEN_BKPT; + goto finished; + } /* Malloc a buffer to read frames into. */ szFrame = szPage + WAL_FRAME_HDRSIZE; @@ -1833,6 +1818,9 @@ static void walLimitSize(Wal *pWal, i64 nMax){ /* ** Close a connection to a log file. +** +** If parameter zBuf is not NULL, attempt to obtain an exclusive lock +** and run a checkpoint. */ int sqlite3WalClose( Wal *pWal, /* Wal to close */ @@ -3096,157 +3084,6 @@ int sqlite3WalHeapMemory(Wal *pWal){ return (pWal && pWal->exclusiveMode==WAL_HEAPMEMORY_MODE ); } -/* -** Save current transaction state. -** -** The transaction state consists of a series of 32-bit big-endian integers: -** -** * initial number of frames in WAL file. -** * initial checksum values (2 integers). -** * current number of frames. -** * current checksum values (2 integers). -*/ -int sqlite3WalSaveState(Wal *pWal, void **ppState, int *pnState){ - int rc = SQLITE_OK; - - *ppState = 0; - *pnState = 0; - if( pWal->writeLock==0 ){ - /* Must be in a write transaction to call this function. */ - rc = SQLITE_ERROR; - }else{ - WalIndexHdr *pOrig = (WalIndexHdr*)walIndexHdr(pWal); - int nBuf = 6 * 4; /* Bytes of space to allocate */ - u8 *aBuf; - - aBuf = sqlite3_malloc(nBuf); - if( aBuf==0 ){ - rc = SQLITE_NOMEM; - }else{ - sqlite3Put4byte(&aBuf[0], pOrig->mxFrame); - sqlite3Put4byte(&aBuf[4], pOrig->aFrameCksum[0]); - sqlite3Put4byte(&aBuf[8], pOrig->aFrameCksum[1]); - sqlite3Put4byte(&aBuf[12], pWal->hdr.mxFrame); - sqlite3Put4byte(&aBuf[16], pWal->hdr.aFrameCksum[0]); - sqlite3Put4byte(&aBuf[20], pWal->hdr.aFrameCksum[1]); - *ppState = (void*)aBuf; - *pnState = nBuf; - } - } - - return rc; -} - -static int walUndoNoop(void *pUndoCtx, Pgno pgno){ - UNUSED_PARAMETER(pUndoCtx); - UNUSED_PARAMETER(pgno); - return SQLITE_OK; -} - -/* -** If possible, restore the state of the curent transaction to that -** described by the second and third arguments. -*/ -int sqlite3WalRestoreState(Wal *pWal, const void *pState, int nState){ - int rc = SQLITE_OK; - - if( pWal->writeLock==0 ){ - /* Must have opened a write transaction to call this */ - rc = SQLITE_ERROR; - }else{ - u8 *aBuf = (u8*)pState; - int szFrame; /* Size of each frame in WAL file */ - u8 *aFrame = 0; /* Buffer to read data into */ - u8 *aData; /* Data part of aFrame[] buffer */ - u32 mxFrame; /* Maximum frame following restoration */ - int i; /* Iterator variable */ - - WalIndexHdr *pOrig = (WalIndexHdr*)walIndexHdr(pWal); - - /* Check that no dirty pages have been written to the WAL file since - ** the current transaction was opened. */ - if( pOrig->mxFrame!=pWal->hdr.mxFrame - || pOrig->aFrameCksum[0]!=pWal->hdr.aFrameCksum[0] - || pOrig->aFrameCksum[1]!=pWal->hdr.aFrameCksum[1] - ){ - rc = SQLITE_ERROR; - } - - /* Check that the WAL file is in the same state that it was when the - ** transaction was saved. If not, return SQLITE_MISMATCH - cannot - ** resume this transaction */ - if( rc==SQLITE_OK && ( - pWal->hdr.mxFrame!=sqlite3Get4byte(&aBuf[0]) - || pWal->hdr.aFrameCksum[0]!=sqlite3Get4byte(&aBuf[4]) - || pWal->hdr.aFrameCksum[1]!=sqlite3Get4byte(&aBuf[8]) - )){ - rc = SQLITE_MISMATCH; - } - - if( rc==SQLITE_OK && pWal->readLock==0 ){ - int cnt = 0; - walUnlockShared(pWal, WAL_READ_LOCK(0)); - pWal->readLock = -1; - do{ - int notUsed; - rc = walTryBeginRead(pWal, ¬Used, 1, ++cnt); - }while( rc==WAL_RETRY ); - - if( rc==SQLITE_OK ){ - int bValid; - rc = walFileReadHdr(pWal, &bValid); - if( rc==SQLITE_OK && bValid==0 ) rc = SQLITE_MISMATCH; - pWal->hdr.szPage = (u16)((pWal->szPage&0xff00) | (pWal->szPage>>16)); - } - } - - /* Malloc a buffer to read frames into. */ - if( rc==SQLITE_OK ){ - szFrame = pWal->szPage + WAL_FRAME_HDRSIZE; - aFrame = (u8*)sqlite3_malloc(szFrame); - if( !aFrame ){ - rc = SQLITE_NOMEM; - }else{ - aData = &aFrame[WAL_FRAME_HDRSIZE]; - } - } - - mxFrame = sqlite3Get4byte(&aBuf[12]); - for(i=pWal->hdr.mxFrame+1; rc==SQLITE_OK && i<=mxFrame; i++){ - sqlite3_int64 iOff = walFrameOffset(i, pWal->szPage); - rc = sqlite3OsRead(pWal->pWalFd, aFrame, szFrame, iOff); - if( rc==SQLITE_OK ){ - u32 iPg; - u32 dummy; - if( 0==walDecodeFrame(pWal, &iPg, &dummy, aData, aFrame) ){ - rc = SQLITE_MISMATCH; - }else{ - rc = walIndexAppend(pWal, i, iPg); - if( iPg>pWal->hdr.nPage ) pWal->hdr.nPage = iPg; - } - pWal->hdr.mxFrame = i; - } - } - sqlite3_free(aFrame); - - if( rc==SQLITE_OK ){ - assert( pWal->hdr.mxFrame==mxFrame ); - if( pWal->hdr.aFrameCksum[0]!=sqlite3Get4byte(&aBuf[16]) - || pWal->hdr.aFrameCksum[1]!=sqlite3Get4byte(&aBuf[20]) - ){ - rc = SQLITE_MISMATCH; - } - } - - - if( rc!=SQLITE_OK ){ - sqlite3WalUndo(pWal, walUndoNoop, 0); - } - } - - return rc; -} - #ifdef SQLITE_ENABLE_ZIPVFS /* ** If the argument is not NULL, it points to a Wal object that holds a diff --git a/src/wal.h b/src/wal.h index 08006fafe9..092546354b 100644 --- a/src/wal.h +++ b/src/wal.h @@ -126,9 +126,6 @@ int sqlite3WalExclusiveMode(Wal *pWal, int op); */ int sqlite3WalHeapMemory(Wal *pWal); -int sqlite3WalSaveState(Wal *pWal, void **ppState, int *pnState); -int sqlite3WalRestoreState(Wal *pWal, const void *pState, int nState); - #ifdef SQLITE_ENABLE_ZIPVFS /* If the WAL file is not empty, return the number of bytes of content ** stored in each frame (i.e. the db page-size when the WAL was created).