From: dan Date: Tue, 10 Feb 2015 20:00:38 +0000 (+0000) Subject: Further tweaks to work with zipvfs. X-Git-Tag: version-3.8.11~252^2~48^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cd732441445c4c384d1642142361b040e20babe8;p=thirdparty%2Fsqlite.git Further tweaks to work with zipvfs. FossilOrigin-Name: 0f152416be792457c52417aeb531ac860d12a5bd --- diff --git a/ext/ota/sqlite3ota.c b/ext/ota/sqlite3ota.c index 72c4333ed4..39f2042b96 100644 --- a/ext/ota/sqlite3ota.c +++ b/ext/ota/sqlite3ota.c @@ -75,7 +75,6 @@ #define OTA_STATE_COOKIE 7 #define OTA_STAGE_OAL 1 -#define OTA_STAGE_COPY 2 #define OTA_STAGE_CKPT 3 #define OTA_STAGE_DONE 4 @@ -175,7 +174,6 @@ struct sqlite3ota { sqlite3_ckpt *pCkpt; /* Incr-checkpoint handle */ ota_file *pTargetFd; /* File handle open on target db */ const char *zVfsName; /* Name of automatically created ota vfs */ - unsigned int iCookie; }; struct ota_vfs { @@ -190,6 +188,8 @@ struct ota_file { sqlite3_file *pReal; /* Underlying file handle */ ota_vfs *pOtaVfs; /* Pointer to the ota_vfs object */ sqlite3ota *pOta; /* Pointer to ota object (ota target only) */ + int openFlags; /* Flags this file was opened with */ + unsigned int iCookie; /* Cookie value for main db files */ int nShm; /* Number of entries in apShm[] array */ char **apShm; /* Array of mmap'd *-shm regions */ @@ -1469,6 +1469,10 @@ static int otaGetUpdateStmt( return p->rc; } +static void otaSqlTrace(void *pCtx, const char *zSql){ + /* printf("SQL: %s\n", zSql); */ +} + /* ** Open the database handle and attach the OTA database as "ota". If an ** error occurs, leave an error code and message in the OTA handle. @@ -1482,15 +1486,18 @@ static void otaOpenDatabase(sqlite3ota *p){ if( p->rc ){ p->zErrmsg = sqlite3_mprintf("%s", sqlite3_errmsg(p->db)); }else{ + otaMPrintfExec(p, "ATTACH %Q AS ota", p->zOta); + /* sqlite3_trace(p->db, otaSqlTrace, 0); */ + /* Mark the database file just opened as an OTA target database. If ** this call returns SQLITE_NOTFOUND, then the OTA vfs is not in use. ** This is an error. */ - p->rc = sqlite3_file_control(p->db, "main", SQLITE_FCNTL_OTA, (void*)p); - if( p->rc==SQLITE_NOTFOUND ){ - p->rc = SQLITE_ERROR; - p->zErrmsg = sqlite3_mprintf("ota vfs not found"); - }else{ - otaMPrintfExec(p, "ATTACH %Q AS ota", p->zOta); + if( p->rc==SQLITE_OK ){ + p->rc = sqlite3_file_control(p->db, "main", SQLITE_FCNTL_OTA, (void*)p); + if( p->rc==SQLITE_NOTFOUND ){ + p->rc = SQLITE_ERROR; + p->zErrmsg = sqlite3_mprintf("ota vfs not found"); + } } } } @@ -1855,7 +1862,7 @@ static void otaSaveTransactionState(sqlite3ota *p){ OTA_STATE_ROW, p->nStep, OTA_STATE_PROGRESS, p->nProgress, OTA_STATE_CKPT, - OTA_STATE_COOKIE, (sqlite3_int64)p->iCookie + OTA_STATE_COOKIE, (sqlite3_int64)p->pTargetFd->iCookie ) ); assert( pInsert==0 || rc==SQLITE_OK ); @@ -1902,7 +1909,7 @@ static void otaFreeState(OtaState *p){ static OtaState *otaLoadState(sqlite3ota *p){ const char *zSelect = "SELECT k, v FROM ota.ota_state"; OtaState *pRet = 0; - sqlite3_stmt *pStmt; + sqlite3_stmt *pStmt = 0; int rc; int rc2; @@ -1920,7 +1927,6 @@ static OtaState *otaLoadState(sqlite3ota *p){ case OTA_STATE_STAGE: pRet->eStage = sqlite3_column_int(pStmt, 1); if( pRet->eStage!=OTA_STAGE_OAL - && pRet->eStage!=OTA_STAGE_COPY && pRet->eStage!=OTA_STAGE_CKPT ){ p->rc = SQLITE_CORRUPT; @@ -1956,7 +1962,7 @@ static OtaState *otaLoadState(sqlite3ota *p){ ** committed in rollback mode) currently stored on page 1 of the ** database file. */ if( pRet->eStage==OTA_STAGE_OAL - && p->iCookie!=(unsigned int)sqlite3_column_int64(pStmt, 1) + && p->pTargetFd->iCookie!=(unsigned int)sqlite3_column_int64(pStmt, 1) ){ rc = SQLITE_BUSY; p->zErrmsg = sqlite3_mprintf("database modified during ota update"); @@ -2257,10 +2263,8 @@ static int otaVfsRead( ){ ota_file *p = (ota_file*)pFile; int rc = p->pReal->pMethods->xRead(p->pReal, zBuf, iAmt, iOfst); - if( rc==SQLITE_OK && p->pOta && iOfst==0 ){ - unsigned char *pBuf = (unsigned char*)zBuf; - assert( iAmt>=100 ); - p->pOta->iCookie = otaGetU32(&pBuf[24]); + if( rc==SQLITE_OK && iOfst==0 && (p->openFlags & SQLITE_OPEN_MAIN_DB) ){ + p->iCookie = otaGetU32((unsigned char*)&zBuf[24]); } return rc; } @@ -2276,10 +2280,8 @@ static int otaVfsWrite( ){ ota_file *p = (ota_file*)pFile; int rc = p->pReal->pMethods->xWrite(p->pReal, zBuf, iAmt, iOfst); - if( rc==SQLITE_OK && p->pOta && iOfst==0 ){ - unsigned char *pBuf = (unsigned char*)zBuf; - assert( iAmt>=100 ); - p->pOta->iCookie = otaGetU32(&pBuf[24]); + if( rc==SQLITE_OK && iOfst==0 && (p->openFlags & SQLITE_OPEN_MAIN_DB) ){ + p->iCookie = otaGetU32((unsigned char*)&zBuf[24]); } return rc; } @@ -2404,11 +2406,11 @@ static int otaVfsShmLock(sqlite3_file *pFile, int ofst, int n, int flags){ int rc = SQLITE_OK; #ifdef SQLITE_AMALGAMATION - assert( WAL_WRITE_CKPT==1 ); + assert( WAL_CKPT_LOCK==1 ); #endif if( p->pOta && p->pOta->eStage==OTA_STAGE_OAL ){ - /* Magic number 1 is the WAL_WRITE_CKPT lock. Preventing SQLite from + /* Magic number 1 is the WAL_CKPT_LOCK lock. Preventing SQLite from ** taking this lock also prevents any checkpoints from occurring. ** todo: really, it's not clear why this might occur, as ** wal_autocheckpoint ought to be turned off. */ @@ -2452,6 +2454,7 @@ static int otaVfsShmMap( if( pNew==0 ){ rc = SQLITE_NOMEM; }else{ + memset(pNew, 0, szRegion); p->apShm[iRegion] = pNew; } } @@ -2527,6 +2530,7 @@ static int otaVfsOpen( memset(pFd, 0, sizeof(ota_file)); pFd->pReal = (sqlite3_file*)&pFd[1]; pFd->pOtaVfs = pOtaVfs; + pFd->openFlags = flags; if( zName ){ if( flags & SQLITE_OPEN_MAIN_DB ){ /* A main database has just been opened. The following block sets diff --git a/main.mk b/main.mk index b9d613a78d..4727430718 100644 --- a/main.mk +++ b/main.mk @@ -219,6 +219,9 @@ SRC += \ SRC += \ $(TOP)/ext/userauth/userauth.c \ $(TOP)/ext/userauth/sqlite3userauth.h +SRC += \ + $(TOP)/ext/ota/sqlite3ota.c \ + $(TOP)/ext/ota/sqlite3ota.h # Generated source code files # diff --git a/manifest b/manifest index 7a19969c20..24b4a814d1 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sdocumentation\sand\stest\scases\sfor\ssqlite3ota_create_vfs().\sAlso\scode\sto\sdetect\serrors\sin\szipvfs/ota\ssetup. -D 2015-02-10T17:08:17.934 +C Further\stweaks\sto\swork\swith\szipvfs. +D 2015-02-10T20:00:38.125 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 6b9e7677829aa94b9f30949656e27312aefb9a46 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -134,7 +134,7 @@ F ext/ota/ota7.test 1fe2c5761705374530e29f70c39693076028221a F ext/ota/ota8.test cd70e63a0c29c45c0906692827deafa34638feda F ext/ota/ota9.test d3eee95dd836824d07a22e5efcdb7bf6e869358b F ext/ota/otafault.test 508ba87c83d632670ac0f94371a465d4bb4d49dd -F ext/ota/sqlite3ota.c c73855939e124005f5c91fb50987297d50a81405 +F ext/ota/sqlite3ota.c 1f96966839c57e6a6f4ca8e8a771b23fbf79b8f6 F ext/ota/sqlite3ota.h 1cc7201086fe65a36957740381485a24738c4077 F ext/rtree/README 6315c0d73ebf0ec40dedb5aa0e942bc8b54e3761 F ext/rtree/rtree.c 14e6239434d4e3f65d3e90320713f26aa24e167f @@ -165,7 +165,7 @@ F ext/userauth/userauth.c 5fa3bdb492f481bbc1709fc83c91ebd13460c69e F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x F ltmain.sh 3ff0879076df340d2e23ae905484d8c15d5fdea8 F magic.txt 8273bf49ba3b0c8559cb2774495390c31fd61c60 -F main.mk 1de9f345052b7cf631e3323b42bd35064cdfcf0a +F main.mk 57c115aba023c1988564edb80ac87c3e07472b05 F mkopcodec.awk c2ff431854d702cdd2d779c9c0d1f58fa16fa4ea F mkopcodeh.awk c6b3fa301db6ef7ac916b14c60868aeaec1337b5 F mkso.sh fd21c06b063bb16a5d25deea1752c2da6ac3ed83 @@ -1220,7 +1220,7 @@ F tool/mkopts.tcl 66ac10d240cc6e86abd37dc908d50382f84ff46e F tool/mkpragmatab.tcl 94f196c9961e0ca3513e29f57125a3197808be2d F tool/mkspeedsql.tcl a1a334d288f7adfe6e996f2e712becf076745c97 F tool/mksqlite3c-noext.tcl 9ef48e1748dce7b844f67e2450ff9dfeb0fb4ab5 -F tool/mksqlite3c.tcl 6b8e572a90eb4e0086e3ba90d88b76c085919863 +F tool/mksqlite3c.tcl d8b0b0cc5f0e912058c9300f052769c62404d2d9 F tool/mksqlite3h.tcl ba24038056f51fde07c0079c41885ab85e2cff12 F tool/mksqlite3internalh.tcl eb994013e833359137eb53a55acdad0b5ae1049b F tool/mkvsix.tcl 52a4c613707ac34ae9c226e5ccc69cb948556105 @@ -1253,7 +1253,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 96443ecb6909141aa621a16e628455857d036482 -R 5e91280662dadb1373699ffdcf091961 +P e729668168f00325459bc2e9b515aa95e57f2754 +R 245c10d0f1613c672374bc7bdeb81ab9 U dan -Z 228647d512212dceaeb5d71668e39aca +Z 8b6e26dd39381b8c315cf4c234f64cec diff --git a/manifest.uuid b/manifest.uuid index 64d574f4ff..5c028557bb 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -e729668168f00325459bc2e9b515aa95e57f2754 \ No newline at end of file +0f152416be792457c52417aeb531ac860d12a5bd \ No newline at end of file diff --git a/tool/mksqlite3c.tcl b/tool/mksqlite3c.tcl index 4ab8b12b45..4034128d5b 100644 --- a/tool/mksqlite3c.tcl +++ b/tool/mksqlite3c.tcl @@ -112,8 +112,9 @@ foreach hdr { pcache.h pragma.h rtree.h - sqlite3ext.h sqlite3.h + sqlite3ext.h + sqlite3ota.h sqliteicu.h sqliteInt.h sqliteLimit.h @@ -334,6 +335,7 @@ foreach file { rtree.c icu.c fts3_icu.c + sqlite3ota.c } { copy_file tsrc/$file }