diff options
author | drh <drh@noemail.net> | 2015-07-23 21:59:58 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2015-07-23 21:59:58 +0000 |
commit | 244c8d7077ea25763bf2efce123da2f7d2d811cc (patch) | |
tree | 76ee15618f861fe989e7b16dfaca84bb121f35a3 | |
parent | 38151adfe2f51c07ca50e9cbc6f44a9811097eb1 (diff) | |
parent | cfb8f8d6a9073040e90f0bf502f4b108d7917433 (diff) | |
download | sqlite-244c8d7077ea25763bf2efce123da2f7d2d811cc.tar.gz sqlite-244c8d7077ea25763bf2efce123da2f7d2d811cc.zip |
Merge all changes in the latest 3.8.11 beta into the sessions branch.
Changes include the rename of OTA to RBU, the WITHOUT-ROWID-OR-Skipscan fix,
and improvements to pcache1.
FossilOrigin-Name: 7f0ee77062d2fcb014942c7c62c163ccc801f21b
-rw-r--r-- | Makefile.in | 10 | ||||
-rw-r--r-- | Makefile.msc | 8 | ||||
-rw-r--r-- | autoconf/tea/Makefile.in | 2 | ||||
-rw-r--r-- | ext/fts5/fts5_aux.c | 14 | ||||
-rw-r--r-- | ext/fts5/fts5_expr.c | 4 | ||||
-rw-r--r-- | ext/fts5/fts5_hash.c | 19 | ||||
-rw-r--r-- | ext/fts5/fts5_index.c | 21 | ||||
-rw-r--r-- | ext/fts5/fts5_main.c | 8 | ||||
-rw-r--r-- | ext/fts5/fts5_storage.c | 6 | ||||
-rw-r--r-- | ext/rbu/rbu.c (renamed from ext/ota/ota.c) | 50 | ||||
-rw-r--r-- | ext/rbu/rbu1.test (renamed from ext/ota/ota1.test) | 272 | ||||
-rw-r--r-- | ext/rbu/rbu10.test (renamed from ext/ota/ota10.test) | 58 | ||||
-rw-r--r-- | ext/rbu/rbu11.test (renamed from ext/ota/ota11.test) | 102 | ||||
-rw-r--r-- | ext/rbu/rbu12.test (renamed from ext/ota/ota12.test) | 100 | ||||
-rw-r--r-- | ext/rbu/rbu13.test (renamed from ext/ota/ota13.test) | 18 | ||||
-rw-r--r-- | ext/rbu/rbu3.test (renamed from ext/ota/ota3.test) | 92 | ||||
-rw-r--r-- | ext/rbu/rbu5.test (renamed from ext/ota/ota5.test) | 86 | ||||
-rw-r--r-- | ext/rbu/rbu6.test (renamed from ext/ota/ota6.test) | 52 | ||||
-rw-r--r-- | ext/rbu/rbu7.test (renamed from ext/ota/ota7.test) | 38 | ||||
-rw-r--r-- | ext/rbu/rbu8.test (renamed from ext/ota/ota8.test) | 30 | ||||
-rw-r--r-- | ext/rbu/rbu9.test (renamed from ext/ota/ota9.test) | 36 | ||||
-rw-r--r-- | ext/rbu/rbuA.test (renamed from ext/ota/otaA.test) | 40 | ||||
-rw-r--r-- | ext/rbu/rbucrash.test (renamed from ext/ota/otacrash.test) | 78 | ||||
-rw-r--r-- | ext/rbu/rbufault.test (renamed from ext/ota/otafault.test) | 66 | ||||
-rw-r--r-- | ext/rbu/rbufault2.test (renamed from ext/ota/otafault2.test) | 22 | ||||
-rw-r--r-- | ext/rbu/sqlite3rbu.c (renamed from ext/ota/sqlite3ota.c) | 1578 | ||||
-rw-r--r-- | ext/rbu/sqlite3rbu.h (renamed from ext/ota/sqlite3ota.h) | 249 | ||||
-rw-r--r-- | ext/rbu/test_rbu.c (renamed from ext/ota/test_ota.c) | 75 | ||||
-rw-r--r-- | main.mk | 18 | ||||
-rw-r--r-- | manifest | 122 | ||||
-rw-r--r-- | manifest.uuid | 2 | ||||
-rw-r--r-- | src/btree.c | 2 | ||||
-rw-r--r-- | src/date.c | 2 | ||||
-rw-r--r-- | src/main.c | 2 | ||||
-rw-r--r-- | src/pcache1.c | 91 | ||||
-rw-r--r-- | src/pragma.c | 1 | ||||
-rw-r--r-- | src/pragma.h | 2 | ||||
-rw-r--r-- | src/printf.c | 5 | ||||
-rw-r--r-- | src/select.c | 28 | ||||
-rw-r--r-- | src/sqlite.h.in | 8 | ||||
-rw-r--r-- | src/sqliteInt.h | 6 | ||||
-rw-r--r-- | src/tclsqlite.c | 4 | ||||
-rw-r--r-- | src/test1.c | 3 | ||||
-rw-r--r-- | src/test_config.c | 6 | ||||
-rw-r--r-- | src/wal.c | 24 | ||||
-rw-r--r-- | src/wherecode.c | 6 | ||||
-rw-r--r-- | test/fuzz3.test | 7 | ||||
-rw-r--r-- | test/malloc5.test | 35 | ||||
-rw-r--r-- | test/pcache.test | 2 | ||||
-rw-r--r-- | test/pcache2.test | 4 | ||||
-rw-r--r-- | test/permutations.test | 8 | ||||
-rw-r--r-- | test/rbu.test (renamed from test/ota.test) | 7 | ||||
-rw-r--r-- | test/releasetest.tcl | 2 | ||||
-rw-r--r-- | test/skipscan1.test | 30 | ||||
-rw-r--r-- | test/speedtest1.c | 12 | ||||
-rw-r--r-- | tool/mkpragmatab.tcl | 1 | ||||
-rw-r--r-- | tool/mksqlite3c-noext.tcl | 4 | ||||
-rw-r--r-- | tool/mksqlite3c.tcl | 8 |
58 files changed, 1839 insertions, 1747 deletions
diff --git a/Makefile.in b/Makefile.in index 9ffc15baf..469f144e6 100644 --- a/Makefile.in +++ b/Makefile.in @@ -351,8 +351,8 @@ SRC += \ $(TOP)/ext/session/sqlite3session.c \ $(TOP)/ext/session/sqlite3session.h SRC += \ - $(TOP)/ext/ota/sqlite3ota.h \ - $(TOP)/ext/ota/sqlite3ota.c + $(TOP)/ext/rbu/sqlite3rbu.h \ + $(TOP)/ext/rbu/sqlite3rbu.c # Generated source code files # @@ -410,7 +410,7 @@ TESTSRC = \ $(TOP)/ext/fts3/fts3_term.c \ $(TOP)/ext/fts3/fts3_test.c \ $(TOP)/ext/session/test_session.c \ - $(TOP)/ext/ota/test_ota.c + $(TOP)/ext/rbu/test_rbu.c # Statically linked extensions # @@ -1203,10 +1203,10 @@ clean: rm -f fuzzershell fuzzershell.exe rm -f fuzzcheck fuzzcheck.exe rm -f sqldiff sqldiff.exe - rm -f fts5.c fts5.h fts5parse.* + rm -f fts5.* fts5parse.* distclean: clean - rm -f config.log config.status libtool Makefile sqlite3.pc + rm -f config.h config.log config.status libtool Makefile sqlite3.pc # # Windows section diff --git a/Makefile.msc b/Makefile.msc index a42290384..cd5010b2c 100644 --- a/Makefile.msc +++ b/Makefile.msc @@ -1020,8 +1020,8 @@ SRC4 = \ $(TOP)\ext\rtree\rtree.c \ $(TOP)\ext\session\sqlite3session.h \ $(TOP)\ext\session\sqlite3session.c \ - $(TOP)\ext\ota\sqlite3ota.h \ - $(TOP)\ext\ota\sqlite3ota.c + $(TOP)\ext\rbu\sqlite3rbu.h \ + $(TOP)\ext\rbu\sqlite3rbu.c # Generated source code files @@ -1083,7 +1083,7 @@ TESTSRC = \ $(TOP)\ext\fts3\fts3_term.c \ $(TOP)\ext\fts3\fts3_test.c \ $(TOP)\ext\session\test_session.c \ - $(TOP)\ext\ota\test_ota.c + $(TOP)\ext\rbu\test_rbu.c # Statically linked extensions # @@ -1866,7 +1866,7 @@ clean: del /Q sqlite3_analyzer.exe sqlite3_analyzer.c 2>NUL del /Q sqlite-*-output.vsix 2>NUL del /Q fuzzershell.exe fuzzcheck.exe sqldiff.exe 2>NUL - del /Q fts5.c fts5.h fts5parse.* 2>NUL + del /Q fts5.* fts5parse.* 2>NUL # Dynamic link library section. # diff --git a/autoconf/tea/Makefile.in b/autoconf/tea/Makefile.in index a8708974b..3e481dadf 100644 --- a/autoconf/tea/Makefile.in +++ b/autoconf/tea/Makefile.in @@ -348,7 +348,7 @@ clean: distclean: clean -rm -f *.tab.c -rm -f $(CONFIG_CLEAN_FILES) - -rm -f config.cache config.log config.status + -rm -f config.h config.cache config.log config.status #======================================================================== # Install binary object libraries. On Windows this includes both .dll and diff --git a/ext/fts5/fts5_aux.c b/ext/fts5/fts5_aux.c index 3f9c227e6..818dfcf29 100644 --- a/ext/fts5/fts5_aux.c +++ b/ext/fts5/fts5_aux.c @@ -255,7 +255,7 @@ static void fts5SnippetFunction( int iCol; /* 1st argument to snippet() */ const char *zEllips; /* 4th argument to snippet() */ int nToken; /* 5th argument to snippet() */ - int nInst; /* Number of instance matches this row */ + int nInst = 0; /* Number of instance matches this row */ int i; /* Used to iterate through instances */ int nPhrase; /* Number of phrases in query */ unsigned char *aSeen; /* Array of "seen instance" flags */ @@ -263,7 +263,7 @@ static void fts5SnippetFunction( int iBestStart = 0; /* First token of best snippet */ int iBestLast; /* Last token of best snippet */ int nBestScore = 0; /* Score of best snippet */ - int nColSize; /* Total size of iBestCol in tokens */ + int nColSize = 0; /* Total size of iBestCol in tokens */ if( nVal!=5 ){ const char *zErr = "wrong number of arguments to function snippet()"; @@ -407,8 +407,8 @@ static int fts5Bm25GetData( p = pApi->xGetAuxdata(pFts, 0); if( p==0 ){ int nPhrase; /* Number of phrases in query */ - sqlite3_int64 nRow; /* Number of rows in table */ - sqlite3_int64 nToken; /* Number of tokens in table */ + sqlite3_int64 nRow = 0; /* Number of rows in table */ + sqlite3_int64 nToken = 0; /* Number of tokens in table */ int nByte; /* Bytes of space to allocate */ int i; @@ -481,9 +481,9 @@ static void fts5Bm25Function( double score = 0.0; /* SQL function return value */ Fts5Bm25Data *pData; /* Values allocated/calculated once only */ int i; /* Iterator variable */ - int nInst; /* Value returned by xInstCount() */ - double D; /* Total number of tokens in row */ - double *aFreq; /* Array of phrase freq. for current row */ + int nInst = 0; /* Value returned by xInstCount() */ + double D = 0.0; /* Total number of tokens in row */ + double *aFreq = 0; /* Array of phrase freq. for current row */ /* Calculate the phrase frequency (symbol "f(qi,D)" in the documentation) ** for each phrase in the query for the current row. */ diff --git a/ext/fts5/fts5_expr.c b/ext/fts5/fts5_expr.c index a02a66f15..97ff3c72a 100644 --- a/ext/fts5/fts5_expr.c +++ b/ext/fts5/fts5_expr.c @@ -83,7 +83,7 @@ struct Fts5ExprPhrase { Fts5ExprNode *pNode; /* FTS5_STRING node this phrase is part of */ Fts5Buffer poslist; /* Current position list */ int nTerm; /* Number of entries in aTerm[] */ - Fts5ExprTerm aTerm[0]; /* Terms that make up this phrase */ + Fts5ExprTerm aTerm[1]; /* Terms that make up this phrase */ }; /* @@ -104,7 +104,7 @@ struct Fts5ExprNearset { int nNear; /* NEAR parameter */ Fts5ExprColset *pColset; /* Columns to search (NULL -> all columns) */ int nPhrase; /* Number of entries in aPhrase[] array */ - Fts5ExprPhrase *apPhrase[0]; /* Array of phrase pointers */ + Fts5ExprPhrase *apPhrase[1]; /* Array of phrase pointers */ }; diff --git a/ext/fts5/fts5_hash.c b/ext/fts5/fts5_hash.c index 0f878cf78..ff440fa61 100644 --- a/ext/fts5/fts5_hash.c +++ b/ext/fts5/fts5_hash.c @@ -66,10 +66,17 @@ struct Fts5HashEntry { int iCol; /* Column of last value written */ int iPos; /* Position of last value written */ i64 iRowid; /* Rowid of last value written */ - char zKey[0]; /* Nul-terminated entry key */ + char zKey[8]; /* Nul-terminated entry key */ }; /* +** Size of Fts5HashEntry without the zKey[] array. +*/ +#define FTS5_HASHENTRYSIZE (sizeof(Fts5HashEntry)-8) + + + +/* ** Allocate a new hash table. */ int sqlite3Fts5HashNew(Fts5Hash **ppNew, int *pnByte){ @@ -220,7 +227,7 @@ int sqlite3Fts5HashWrite( /* If an existing hash entry cannot be found, create a new one. */ if( p==0 ){ - int nByte = sizeof(Fts5HashEntry) + (nToken+1) + 1 + 64; + int nByte = FTS5_HASHENTRYSIZE + (nToken+1) + 1 + 64; if( nByte<128 ) nByte = 128; if( (pHash->nEntry*2)>=pHash->nSlot ){ @@ -231,13 +238,13 @@ int sqlite3Fts5HashWrite( p = (Fts5HashEntry*)sqlite3_malloc(nByte); if( !p ) return SQLITE_NOMEM; - memset(p, 0, sizeof(Fts5HashEntry)); + memset(p, 0, FTS5_HASHENTRYSIZE); p->nAlloc = nByte; p->zKey[0] = bByte; memcpy(&p->zKey[1], pToken, nToken); assert( iHash==fts5HashKey(pHash->nSlot, p->zKey, nToken+1) ); p->zKey[nToken+1] = '\0'; - p->nData = nToken+1 + 1 + sizeof(Fts5HashEntry); + p->nData = nToken+1 + 1 + FTS5_HASHENTRYSIZE; p->nData += sqlite3Fts5PutVarint(&((u8*)p)[p->nData], iRowid); p->iSzPoslist = p->nData; p->nData += 1; @@ -417,7 +424,7 @@ int sqlite3Fts5HashQuery( if( p ){ fts5HashAddPoslistSize(p); *ppDoclist = (const u8*)&p->zKey[nTerm+1]; - *pnDoclist = p->nData - (sizeof(*p) + nTerm + 1); + *pnDoclist = p->nData - (FTS5_HASHENTRYSIZE + nTerm + 1); }else{ *ppDoclist = 0; *pnDoclist = 0; @@ -454,7 +461,7 @@ void sqlite3Fts5HashScanEntry( fts5HashAddPoslistSize(p); *pzTerm = p->zKey; *ppDoclist = (const u8*)&p->zKey[nTerm+1]; - *pnDoclist = p->nData - (sizeof(*p) + nTerm + 1); + *pnDoclist = p->nData - (FTS5_HASHENTRYSIZE + nTerm + 1); }else{ *pzTerm = 0; *ppDoclist = 0; diff --git a/ext/fts5/fts5_index.c b/ext/fts5/fts5_index.c index 0b8f137eb..422957339 100644 --- a/ext/fts5/fts5_index.c +++ b/ext/fts5/fts5_index.c @@ -368,7 +368,7 @@ struct Fts5Structure { u64 nWriteCounter; /* Total leaves written to level 0 */ int nSegment; /* Total segments in this structure */ int nLevel; /* Number of levels in this index */ - Fts5StructureLevel aLevel[0]; /* Array of nLevel level objects */ + Fts5StructureLevel aLevel[1]; /* Array of nLevel level objects */ }; /* @@ -738,7 +738,7 @@ static Fts5Data *fts5DataReadOrBuffer( if( rc==SQLITE_ERROR ) rc = FTS5_CORRUPT; if( rc==SQLITE_OK ){ - u8 *aOut; /* Read blob data into this buffer */ + u8 *aOut = 0; /* Read blob data into this buffer */ int nByte = sqlite3_blob_bytes(p->pReader); if( pBuf ){ fts5BufferSize(pBuf, MAX(nByte, p->pConfig->pgsz) + 20); @@ -929,7 +929,7 @@ static int fts5StructureDecode( i += fts5GetVarint32(&pData[i], nSegment); nByte = ( sizeof(Fts5Structure) + /* Main structure */ - sizeof(Fts5StructureLevel) * (nLevel) /* aLevel[] array */ + sizeof(Fts5StructureLevel) * (nLevel-1) /* aLevel[] array */ ); pRet = (Fts5Structure*)sqlite3Fts5MallocZero(&rc, nByte); @@ -1198,7 +1198,7 @@ static void fts5StructurePromote( if( p->rc==SQLITE_OK ){ int iTst; int iPromote = -1; - int szPromote; /* Promote anything this size or smaller */ + int szPromote = 0; /* Promote anything this size or smaller */ Fts5StructureSegment *pSeg; /* Segment just written */ int szSeg; /* Size of segment just written */ @@ -1863,8 +1863,8 @@ static void fts5SegIterNext( } }else if( pIter->pSeg==0 ){ const u8 *pList = 0; - const char *zTerm; - int nList; + const char *zTerm = 0; + int nList = 0; if( 0==(pIter->flags & FTS5_SEGITER_ONETERM) ){ sqlite3Fts5HashScanNext(p->pHash); sqlite3Fts5HashScanEntry(p->pHash, &zTerm, &pList, &nList); @@ -2215,7 +2215,6 @@ static void fts5LeafSeek( while( 1 ){ int i; int nCmp; - i64 rowid; /* Figure out how many new bytes are in this term */ fts5IndexGetVarint32(a, iOff, nNew); @@ -2324,7 +2323,6 @@ static void fts5SegIterSeekInit( int h; int bGe = (flags & FTS5INDEX_QUERY_SCAN); int bDlidx = 0; /* True if there is a doclist-index */ - Fts5Data *pLeaf; static int nCall = 0; nCall++; @@ -3072,7 +3070,7 @@ static void fts5ChunkIterate( ** returned in this case. */ static int fts5AllocateSegid(Fts5Index *p, Fts5Structure *pStruct){ - u32 iSegid = 0; + int iSegid = 0; if( p->rc==SQLITE_OK ){ if( pStruct->nSegment>=FTS5_MAX_SEGMENT ){ @@ -3081,8 +3079,7 @@ static int fts5AllocateSegid(Fts5Index *p, Fts5Structure *pStruct){ while( iSegid==0 ){ int iLvl, iSeg; sqlite3_randomness(sizeof(u32), (void*)&iSegid); - iSegid = (iSegid % ((1 << FTS5_DATA_ID_B) - 2)) + 1; - assert( iSegid>0 && iSegid<=65535 ); + iSegid = iSegid & ((1 << FTS5_DATA_ID_B)-1); for(iLvl=0; iLvl<pStruct->nLevel; iLvl++){ for(iSeg=0; iSeg<pStruct->aLevel[iLvl].nSeg; iSeg++){ if( iSegid==pStruct->aLevel[iLvl].aSeg[iSeg].iSegid ){ @@ -3094,7 +3091,7 @@ static int fts5AllocateSegid(Fts5Index *p, Fts5Structure *pStruct){ } } - return (int)iSegid; + return iSegid; } /* diff --git a/ext/fts5/fts5_main.c b/ext/fts5/fts5_main.c index ccb94bd8d..7afe0653e 100644 --- a/ext/fts5/fts5_main.c +++ b/ext/fts5/fts5_main.c @@ -145,7 +145,7 @@ struct Fts5Sorter { i64 iRowid; /* Current rowid */ const u8 *aPoslist; /* Position lists for current row */ int nIdx; /* Number of entries in aIdx[] */ - int aIdx[0]; /* Offsets into aPoslist for current row */ + int aIdx[1]; /* Offsets into aPoslist for current row */ }; @@ -361,7 +361,7 @@ static int fts5InitVtab( Fts5Global *pGlobal = (Fts5Global*)pAux; const char **azConfig = (const char**)argv; int rc = SQLITE_OK; /* Return code */ - Fts5Config *pConfig; /* Results of parsing argc/argv */ + Fts5Config *pConfig = 0; /* Results of parsing argc/argv */ Fts5Table *pTab = 0; /* New virtual table object */ /* Allocate the new vtab object and parse the configuration */ @@ -756,7 +756,7 @@ static int fts5CursorReseek(Fts5Cursor *pCsr, int *pbSkip){ */ static int fts5NextMethod(sqlite3_vtab_cursor *pCursor){ Fts5Cursor *pCsr = (Fts5Cursor*)pCursor; - int rc; + int rc = SQLITE_OK; assert( (pCsr->ePlan<2)== (pCsr->ePlan==FTS5_PLAN_MATCH || pCsr->ePlan==FTS5_PLAN_SOURCE) @@ -808,7 +808,7 @@ static int fts5CursorFirstSorted(Fts5Table *pTab, Fts5Cursor *pCsr, int bDesc){ const char *zRankArgs = pCsr->zRankArgs; nPhrase = sqlite3Fts5ExprPhraseCount(pCsr->pExpr); - nByte = sizeof(Fts5Sorter) + sizeof(int) * nPhrase; + nByte = sizeof(Fts5Sorter) + sizeof(int) * (nPhrase-1); pSorter = (Fts5Sorter*)sqlite3_malloc(nByte); if( pSorter==0 ) return SQLITE_NOMEM; memset(pSorter, 0, nByte); diff --git a/ext/fts5/fts5_storage.c b/ext/fts5/fts5_storage.c index 601f85713..da822ffad 100644 --- a/ext/fts5/fts5_storage.c +++ b/ext/fts5/fts5_storage.c @@ -501,7 +501,7 @@ static int fts5StorageSaveTotals(Fts5Storage *p){ int sqlite3Fts5StorageDelete(Fts5Storage *p, i64 iDel){ Fts5Config *pConfig = p->pConfig; int rc; - sqlite3_stmt *pDel; + sqlite3_stmt *pDel = 0; rc = fts5StorageLoadTotals(p, 1); @@ -545,7 +545,7 @@ int sqlite3Fts5StorageSpecialDelete( ){ Fts5Config *pConfig = p->pConfig; int rc; - sqlite3_stmt *pDel; + sqlite3_stmt *pDel = 0; assert( pConfig->eContent!=FTS5_CONTENT_NORMAL ); rc = fts5StorageLoadTotals(p, 1); @@ -719,7 +719,7 @@ int sqlite3Fts5StorageInsert( ){ Fts5Config *pConfig = p->pConfig; int rc = SQLITE_OK; /* Return code */ - sqlite3_stmt *pInsert; /* Statement used to write %_content table */ + sqlite3_stmt *pInsert = 0; /* Statement used to write %_content table */ int eStmt = 0; /* Type of statement used on %_content */ int i; /* Counter variable */ Fts5InsertCtx ctx; /* Tokenization callback context object */ diff --git a/ext/ota/ota.c b/ext/rbu/rbu.c index fffc1267b..6e84bbdeb 100644 --- a/ext/ota/ota.c +++ b/ext/rbu/rbu.c @@ -10,11 +10,11 @@ ** ************************************************************************* ** -** This file contains a command-line application that uses the OTA +** This file contains a command-line application that uses the RBU ** extension. See the usage() function below for an explanation. */ -#include "sqlite3ota.h" +#include "sqlite3rbu.h" #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -24,18 +24,18 @@ */ void usage(const char *zArgv0){ fprintf(stderr, -"Usage: %s [-step NSTEP] TARGET-DB OTA-DB\n" +"Usage: %s [-step NSTEP] TARGET-DB RBU-DB\n" "\n" -" Argument OTA-DB must be an OTA database containing an update suitable for\n" +" Argument RBU-DB must be an RBU database containing an update suitable for\n" " target database TARGET-DB. If NSTEP is set to less than or equal to zero\n" " (the default value), this program attempts to apply the entire update to\n" " the target database.\n" "\n" " If NSTEP is greater than zero, then a maximum of NSTEP calls are made\n" -" to sqlite3ota_step(). If the OTA update has not been completely applied\n" -" after the NSTEP'th call is made, the state is saved in the database OTA-DB\n" -" and the program exits. Subsequent invocations of this (or any other OTA)\n" -" application will use this state to resume applying the OTA update to the\n" +" to sqlite3rbu_step(). If the RBU update has not been completely applied\n" +" after the NSTEP'th call is made, the state is saved in the database RBU-DB\n" +" and the program exits. Subsequent invocations of this (or any other RBU)\n" +" application will use this state to resume applying the RBU update to the\n" " target db.\n" "\n" , zArgv0); @@ -47,8 +47,8 @@ void report_default_vfs(){ fprintf(stdout, "default vfs is \"%s\"\n", pVfs->zName); } -void report_ota_vfs(sqlite3ota *pOta){ - sqlite3 *db = sqlite3ota_db(pOta, 0); +void report_rbu_vfs(sqlite3rbu *pRbu){ + sqlite3 *db = sqlite3rbu_db(pRbu, 0); if( db ){ char *zName = 0; sqlite3_file_control(db, "main", SQLITE_FCNTL_VFSNAME, &zName); @@ -63,16 +63,16 @@ void report_ota_vfs(sqlite3ota *pOta){ int main(int argc, char **argv){ int i; - const char *zTarget; /* Target database to apply OTA to */ - const char *zOta; /* Database containing OTA */ + const char *zTarget; /* Target database to apply RBU to */ + const char *zRbu; /* Database containing RBU */ char *zErrmsg; /* Error message, if any */ - sqlite3ota *pOta; /* OTA handle */ + sqlite3rbu *pRbu; /* RBU handle */ int nStep = 0; /* Maximum number of step() calls */ int rc; sqlite3_int64 nProgress = 0; /* Process command line arguments. Following this block local variables - ** zTarget, zOta and nStep are all set. */ + ** zTarget, zRbu and nStep are all set. */ if( argc==5 ){ int nArg1 = strlen(argv[1]); if( nArg1>5 || nArg1<2 || memcmp("-step", argv[1], nArg1) ) usage(argv[0]); @@ -81,32 +81,32 @@ int main(int argc, char **argv){ usage(argv[0]); } zTarget = argv[argc-2]; - zOta = argv[argc-1]; + zRbu = argv[argc-1]; report_default_vfs(); - /* Open an OTA handle. If nStep is less than or equal to zero, call - ** sqlite3ota_step() until either the OTA has been completely applied + /* Open an RBU handle. If nStep is less than or equal to zero, call + ** sqlite3rbu_step() until either the RBU has been completely applied ** or an error occurs. Or, if nStep is greater than zero, call - ** sqlite3ota_step() a maximum of nStep times. */ - pOta = sqlite3ota_open(zTarget, zOta, 0); - report_ota_vfs(pOta); - for(i=0; (nStep<=0 || i<nStep) && sqlite3ota_step(pOta)==SQLITE_OK; i++); - nProgress = sqlite3ota_progress(pOta); - rc = sqlite3ota_close(pOta, &zErrmsg); + ** sqlite3rbu_step() a maximum of nStep times. */ + pRbu = sqlite3rbu_open(zTarget, zRbu, 0); + report_rbu_vfs(pRbu); + for(i=0; (nStep<=0 || i<nStep) && sqlite3rbu_step(pRbu)==SQLITE_OK; i++); + nProgress = sqlite3rbu_progress(pRbu); + rc = sqlite3rbu_close(pRbu, &zErrmsg); /* Let the user know what happened. */ switch( rc ){ case SQLITE_OK: fprintf(stdout, - "SQLITE_OK: ota update incomplete (%lld operations so far)\n", + "SQLITE_OK: rbu update incomplete (%lld operations so far)\n", nProgress ); break; case SQLITE_DONE: fprintf(stdout, - "SQLITE_DONE: ota update completed (%lld operations)\n", + "SQLITE_DONE: rbu update completed (%lld operations)\n", nProgress ); break; diff --git a/ext/ota/ota1.test b/ext/rbu/rbu1.test index 97fd2a3f9..19b3d27a9 100644 --- a/ext/ota/ota1.test +++ b/ext/rbu/rbu1.test @@ -14,128 +14,128 @@ if {![info exists testdir]} { set testdir [file join [file dirname [info script]] .. .. test] } source $testdir/tester.tcl -set ::testprefix ota1 +set ::testprefix rbu1 db close sqlite3_shutdown sqlite3_config_uri 1 -# Create a simple OTA database. That expects to write to a table: +# Create a simple RBU database. That expects to write to a table: # # CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c); # -proc create_ota1 {filename} { +proc create_rbu1 {filename} { forcedelete $filename - sqlite3 ota1 $filename - ota1 eval { - CREATE TABLE data_t1(a, b, c, ota_control); + sqlite3 rbu1 $filename + rbu1 eval { + CREATE TABLE data_t1(a, b, c, rbu_control); INSERT INTO data_t1 VALUES(1, 2, 3, 0); INSERT INTO data_t1 VALUES(2, 'two', 'three', 0); INSERT INTO data_t1 VALUES(3, NULL, 8.2, 0); } - ota1 close + rbu1 close return $filename } -# Create a simple OTA database. That expects to write to a table: +# Create a simple RBU database. That expects to write to a table: # # CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c); # -# This OTA includes both insert and delete operations. +# This RBU includes both insert and delete operations. # -proc create_ota4 {filename} { +proc create_rbu4 {filename} { forcedelete $filename - sqlite3 ota1 $filename - ota1 eval { - CREATE TABLE data_t1(a, b, c, ota_control); + sqlite3 rbu1 $filename + rbu1 eval { + CREATE TABLE data_t1(a, b, c, rbu_control); INSERT INTO data_t1 VALUES(1, 2, 3, 0); INSERT INTO data_t1 VALUES(2, NULL, 5, 1); INSERT INTO data_t1 VALUES(3, 8, 9, 0); INSERT INTO data_t1 VALUES(4, NULL, 11, 1); } - ota1 close + rbu1 close return $filename } # -# Create a simple OTA database. That expects to write to a table: +# Create a simple RBU database. That expects to write to a table: # # CREATE TABLE t1(c, b, '(a)' INTEGER PRIMARY KEY); # -# This OTA includes both insert and delete operations. +# This RBU includes both insert and delete operations. # -proc create_ota4b {filename} { +proc create_rbu4b {filename} { forcedelete $filename - sqlite3 ota1 $filename - ota1 eval { - CREATE TABLE data_t1(c, b, '(a)', ota_control); + sqlite3 rbu1 $filename + rbu1 eval { + CREATE TABLE data_t1(c, b, '(a)', rbu_control); INSERT INTO data_t1 VALUES(3, 2, 1, 0); INSERT INTO data_t1 VALUES(5, NULL, 2, 1); INSERT INTO data_t1 VALUES(9, 8, 3, 0); INSERT INTO data_t1 VALUES(11, NULL, 4, 1); } - ota1 close + rbu1 close return $filename } -# Create a simple OTA database. That expects to write to a table: +# Create a simple RBU database. That expects to write to a table: # # CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c, d); # -# This OTA includes update statements. +# This RBU includes update statements. # -proc create_ota5 {filename} { +proc create_rbu5 {filename} { forcedelete $filename - sqlite3 ota5 $filename - ota5 eval { - CREATE TABLE data_t1(a, b, c, d, ota_control); + sqlite3 rbu5 $filename + rbu5 eval { + CREATE TABLE data_t1(a, b, c, d, rbu_control); INSERT INTO data_t1 VALUES(1, NULL, NULL, 5, '...x'); -- SET d = 5 INSERT INTO data_t1 VALUES(2, NULL, 10, 5, '..xx'); -- SET c=10, d = 5 INSERT INTO data_t1 VALUES(3, 11, NULL, NULL, '.x..'); -- SET b=11 } - ota5 close + rbu5 close return $filename } -# Run the OTA in file $ota on target database $target until completion. +# Run the RBU in file $rbu on target database $target until completion. # -proc run_ota {target ota} { - sqlite3ota ota $target $ota +proc run_rbu {target rbu} { + sqlite3rbu rbu $target $rbu while 1 { - set rc [ota step] + set rc [rbu step] if {$rc!="SQLITE_OK"} break } - ota close + rbu close } -proc step_ota {target ota} { +proc step_rbu {target rbu} { while 1 { - sqlite3ota ota $target $ota - set rc [ota step] - ota close + sqlite3rbu rbu $target $rbu + set rc [rbu step] + rbu close if {$rc != "SQLITE_OK"} break } set rc } -# Same as [step_ota], except using a URI to open the target db. +# Same as [step_rbu], except using a URI to open the target db. # -proc step_ota_uri {target ota} { +proc step_rbu_uri {target rbu} { while 1 { - sqlite3ota ota file:$target?xyz=&abc=123 $ota - set rc [ota step] - ota close + sqlite3rbu rbu file:$target?xyz=&abc=123 $rbu + set rc [rbu step] + rbu close if {$rc != "SQLITE_OK"} break } set rc } -# Same as [step_ota], except using an external state database - "state.db" +# Same as [step_rbu], except using an external state database - "state.db" # -proc step_ota_state {target ota} { +proc step_rbu_state {target rbu} { while 1 { - sqlite3ota ota $target $ota state.db - set rc [ota step] - ota close + sqlite3rbu rbu $target $rbu state.db + set rc [rbu step] + rbu close if {$rc != "SQLITE_OK"} break } set rc @@ -151,17 +151,17 @@ proc dbfilecksum {file} { foreach {tn3 create_vfs destroy_vfs} { 1 {} {} 2 { - sqlite3ota_create_vfs -default myota "" + sqlite3rbu_create_vfs -default myrbu "" } { - sqlite3ota_destroy_vfs myota + sqlite3rbu_destroy_vfs myrbu } } { eval $create_vfs foreach {tn2 cmd} { - 1 run_ota - 2 step_ota 3 step_ota_uri 4 step_ota_state + 1 run_rbu + 2 step_rbu 3 step_rbu_uri 4 step_rbu_state } { foreach {tn schema} { 1 { @@ -240,12 +240,12 @@ foreach {tn3 create_vfs destroy_vfs} { } { reset_db execsql $schema - create_ota1 ota.db - set check [dbfilecksum ota.db] + create_rbu1 rbu.db + set check [dbfilecksum rbu.db] forcedelete state.db do_test $tn3.1.$tn2.$tn.1 { - $cmd test.db ota.db + $cmd test.db rbu.db } {SQLITE_DONE} do_execsql_test $tn3.1.$tn2.$tn.2 { SELECT * FROM t1 ORDER BY a ASC } { @@ -266,51 +266,51 @@ foreach {tn3 create_vfs destroy_vfs} { do_execsql_test $tn3.1.$tn2.$tn.5 { PRAGMA integrity_check } ok - if {$cmd=="step_ota_state"} { + if {$cmd=="step_rbu_state"} { do_test $tn3.1.$tn2.$tn.6 { file exists state.db } 1 - do_test $tn3.1.$tn2.$tn.7 { expr {$check == [dbfilecksum ota.db]} } 1 + do_test $tn3.1.$tn2.$tn.7 { expr {$check == [dbfilecksum rbu.db]} } 1 } else { do_test $tn3.1.$tn2.$tn.8 { file exists state.db } 0 - do_test $tn3.1.$tn2.$tn.9 { expr {$check == [dbfilecksum ota.db]} } 0 + do_test $tn3.1.$tn2.$tn.9 { expr {$check == [dbfilecksum rbu.db]} } 0 } } } #------------------------------------------------------------------------- - # Check that an OTA cannot be applied to a table that has no PK. + # Check that an RBU cannot be applied to a table that has no PK. # - # UPDATE: At one point OTA required that all tables featured either + # UPDATE: At one point RBU required that all tables featured either # explicit IPK columns or were declared WITHOUT ROWID. This has been # relaxed so that external PRIMARY KEYs on tables with automatic rowids # are now allowed. # # UPDATE 2: Tables without any PRIMARY KEY declaration are now allowed. - # However the input table must feature an "ota_rowid" column. + # However the input table must feature an "rbu_rowid" column. # reset_db - create_ota1 ota.db + create_rbu1 rbu.db do_execsql_test $tn3.2.1 { CREATE TABLE t1(a, b, c) } do_test $tn3.2.2 { - sqlite3ota ota test.db ota.db - ota step + sqlite3rbu rbu test.db rbu.db + rbu step } {SQLITE_ERROR} do_test $tn3.2.3 { - list [catch { ota close } msg] $msg - } {1 {SQLITE_ERROR - table data_t1 requires ota_rowid column}} + list [catch { rbu close } msg] $msg + } {1 {SQLITE_ERROR - table data_t1 requires rbu_rowid column}} reset_db do_execsql_test $tn3.2.4 { CREATE TABLE t1(a PRIMARY KEY, b, c) } do_test $tn3.2.5 { - sqlite3ota ota test.db ota.db - ota step + sqlite3rbu rbu test.db rbu.db + rbu step } {SQLITE_OK} do_test $tn3.2.6 { - list [catch { ota close } msg] $msg + list [catch { rbu close } msg] $msg } {0 SQLITE_OK} #------------------------------------------------------------------------- # Check that if a UNIQUE constraint is violated the current and all - # subsequent [ota step] calls return SQLITE_CONSTRAINT. And that the OTA - # transaction is rolled back by the [ota close] that deletes the ota + # subsequent [rbu step] calls return SQLITE_CONSTRAINT. And that the RBU + # transaction is rolled back by the [rbu close] that deletes the rbu # handle. # foreach {tn errcode errmsg schema} { @@ -340,16 +340,16 @@ foreach {tn3 create_vfs destroy_vfs} { set cksum [dbcksum db main] do_test $tn3.3.$tn.1 { - create_ota1 ota.db - sqlite3ota ota test.db ota.db - while {[set res [ota step]]=="SQLITE_OK"} {} + create_rbu1 rbu.db + sqlite3rbu rbu test.db rbu.db + while {[set res [rbu step]]=="SQLITE_OK"} {} set res } $errcode - do_test $tn3.3.$tn.2 { ota step } $errcode + do_test $tn3.3.$tn.2 { rbu step } $errcode do_test $tn3.3.$tn.3 { - list [catch { ota close } msg] $msg + list [catch { rbu close } msg] $msg } [list 1 "$errcode - $errmsg"] do_test $tn3.3.$tn.4 { dbcksum db main } $cksum @@ -357,7 +357,7 @@ foreach {tn3 create_vfs destroy_vfs} { #------------------------------------------------------------------------- # - foreach {tn2 cmd} {1 run_ota 2 step_ota 3 step_ota_state } { + foreach {tn2 cmd} {1 run_rbu 2 step_rbu 3 step_rbu_state } { foreach {tn schema} { 1 { CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c); @@ -406,12 +406,12 @@ foreach {tn3 create_vfs destroy_vfs} { INSERT INTO t1 VALUES(6, 'hello', 'xyz'); } - create_ota4 ota.db - set check [dbfilecksum ota.db] + create_rbu4 rbu.db + set check [dbfilecksum rbu.db] forcedelete state.db do_test $tn3.4.$tn2.$tn.1 { - $cmd test.db ota.db + $cmd test.db rbu.db } {SQLITE_DONE} do_execsql_test $tn3.4.$tn2.$tn.2 { @@ -424,17 +424,17 @@ foreach {tn3 create_vfs destroy_vfs} { do_execsql_test $tn3.4.$tn2.$tn.3 { PRAGMA integrity_check } ok - if {$cmd=="step_ota_state"} { + if {$cmd=="step_rbu_state"} { do_test $tn3.4.$tn2.$tn.4 { file exists state.db } 1 - do_test $tn3.4.$tn2.$tn.5 { expr {$check == [dbfilecksum ota.db]} } 1 + do_test $tn3.4.$tn2.$tn.5 { expr {$check == [dbfilecksum rbu.db]} } 1 } else { do_test $tn3.4.$tn2.$tn.6 { file exists state.db } 0 - do_test $tn3.4.$tn2.$tn.7 { expr {$check == [dbfilecksum ota.db]} } 0 + do_test $tn3.4.$tn2.$tn.7 { expr {$check == [dbfilecksum rbu.db]} } 0 } } } - foreach {tn2 cmd} {1 run_ota 2 step_ota 3 step_ota_state} { + foreach {tn2 cmd} {1 run_rbu 2 step_rbu 3 step_rbu_state} { foreach {tn schema} { 1 { CREATE TABLE t1(c, b, '(a)' INTEGER PRIMARY KEY); @@ -455,12 +455,12 @@ foreach {tn3 create_vfs destroy_vfs} { INSERT INTO t1('(a)', b, c) VALUES(6, 'hello', 'xyz'); } - create_ota4b ota.db - set check [dbfilecksum ota.db] + create_rbu4b rbu.db + set check [dbfilecksum rbu.db] forcedelete state.db do_test $tn3.5.$tn2.$tn.1 { - $cmd test.db ota.db + $cmd test.db rbu.db } {SQLITE_DONE} do_execsql_test $tn3.5.$tn2.$tn.2 { @@ -473,19 +473,19 @@ foreach {tn3 create_vfs destroy_vfs} { do_execsql_test $tn3.4.$tn2.$tn.3 { PRAGMA integrity_check } ok - if {$cmd=="step_ota_state"} { + if {$cmd=="step_rbu_state"} { do_test $tn3.5.$tn2.$tn.4 { file exists state.db } 1 - do_test $tn3.5.$tn2.$tn.5 { expr {$check == [dbfilecksum ota.db]} } 1 + do_test $tn3.5.$tn2.$tn.5 { expr {$check == [dbfilecksum rbu.db]} } 1 } else { do_test $tn3.5.$tn2.$tn.6 { file exists state.db } 0 - do_test $tn3.5.$tn2.$tn.7 { expr {$check == [dbfilecksum ota.db]} } 0 + do_test $tn3.5.$tn2.$tn.7 { expr {$check == [dbfilecksum rbu.db]} } 0 } } } #------------------------------------------------------------------------- # - foreach {tn2 cmd} {1 run_ota 2 step_ota 3 step_ota_state} { + foreach {tn2 cmd} {1 run_rbu 2 step_rbu 3 step_rbu_state} { foreach {tn schema} { 1 { CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c, d); @@ -526,12 +526,12 @@ foreach {tn3 create_vfs destroy_vfs} { INSERT INTO t1 VALUES(3, 8, 9, 10); } - create_ota5 ota.db - set check [dbfilecksum ota.db] + create_rbu5 rbu.db + set check [dbfilecksum rbu.db] forcedelete state.db do_test $tn3.5.$tn2.$tn.1 { - $cmd test.db ota.db + $cmd test.db rbu.db } {SQLITE_DONE} do_execsql_test $tn3.5.$tn2.$tn.2 { @@ -544,12 +544,12 @@ foreach {tn3 create_vfs destroy_vfs} { do_execsql_test $tn3.6.$tn2.$tn.3 { PRAGMA integrity_check } ok - if {$cmd=="step_ota_state"} { + if {$cmd=="step_rbu_state"} { do_test $tn3.6.$tn2.$tn.4 { file exists state.db } 1 - do_test $tn3.6.$tn2.$tn.5 { expr {$check == [dbfilecksum ota.db]} } 1 + do_test $tn3.6.$tn2.$tn.5 { expr {$check == [dbfilecksum rbu.db]} } 1 } else { do_test $tn3.6.$tn2.$tn.6 { file exists state.db } 0 - do_test $tn3.6.$tn2.$tn.7 { expr {$check == [dbfilecksum ota.db]} } 0 + do_test $tn3.6.$tn2.$tn.7 { expr {$check == [dbfilecksum rbu.db]} } 0 } } } @@ -557,9 +557,9 @@ foreach {tn3 create_vfs destroy_vfs} { #------------------------------------------------------------------------- # Test some error cases: # - # * A virtual table with no ota_rowid column. - # * A no-PK table with no ota_rowid column. - # * A PK table with an ota_rowid column. + # * A virtual table with no rbu_rowid column. + # * A no-PK table with no rbu_rowid column. + # * A PK table with an rbu_rowid column. # # 6: An update string of the wrong length # @@ -567,88 +567,88 @@ foreach {tn3 create_vfs destroy_vfs} { foreach {tn schema error} { 1 { CREATE TABLE t1(a, b); - CREATE TABLE ota.data_t1(a, b, ota_control); - } {SQLITE_ERROR - table data_t1 requires ota_rowid column} + CREATE TABLE rbu.data_t1(a, b, rbu_control); + } {SQLITE_ERROR - table data_t1 requires rbu_rowid column} 2 { CREATE VIRTUAL TABLE t1 USING fts4(a, b); - CREATE TABLE ota.data_t1(a, b, ota_control); - } {SQLITE_ERROR - table data_t1 requires ota_rowid column} + CREATE TABLE rbu.data_t1(a, b, rbu_control); + } {SQLITE_ERROR - table data_t1 requires rbu_rowid column} 3 { CREATE TABLE t1(a PRIMARY KEY, b); - CREATE TABLE ota.data_t1(a, b, ota_rowid, ota_control); - } {SQLITE_ERROR - table data_t1 may not have ota_rowid column} + CREATE TABLE rbu.data_t1(a, b, rbu_rowid, rbu_control); + } {SQLITE_ERROR - table data_t1 may not have rbu_rowid column} 4 { CREATE TABLE t1(a INTEGER PRIMARY KEY, b); - CREATE TABLE ota.data_t1(a, b, ota_rowid, ota_control); - } {SQLITE_ERROR - table data_t1 may not have ota_rowid column} + CREATE TABLE rbu.data_t1(a, b, rbu_rowid, rbu_control); + } {SQLITE_ERROR - table data_t1 may not have rbu_rowid column} 5 { CREATE TABLE t1(a, b PRIMARY KEY) WITHOUT ROWID; - CREATE TABLE ota.data_t1(a, b, ota_rowid, ota_control); - } {SQLITE_ERROR - table data_t1 may not have ota_rowid column} + CREATE TABLE rbu.data_t1(a, b, rbu_rowid, rbu_control); + } {SQLITE_ERROR - table data_t1 may not have rbu_rowid column} 6 { CREATE TABLE t1(a, b PRIMARY KEY) WITHOUT ROWID; - CREATE TABLE ota.data_t1(a, b, ota_control); - INSERT INTO ota.data_t1 VALUES(1, 2, 'x.x'); - } {SQLITE_ERROR - invalid ota_control value} + CREATE TABLE rbu.data_t1(a, b, rbu_control); + INSERT INTO rbu.data_t1 VALUES(1, 2, 'x.x'); + } {SQLITE_ERROR - invalid rbu_control value} 7 { CREATE TABLE t1(a, b PRIMARY KEY) WITHOUT ROWID; - CREATE TABLE ota.data_t1(a, b, ota_control); - INSERT INTO ota.data_t1 VALUES(1, 2, NULL); - } {SQLITE_ERROR - invalid ota_control value} + CREATE TABLE rbu.data_t1(a, b, rbu_control); + INSERT INTO rbu.data_t1 VALUES(1, 2, NULL); + } {SQLITE_ERROR - invalid rbu_control value} 8 { CREATE TABLE t1(a, b PRIMARY KEY) WITHOUT ROWID; - CREATE TABLE ota.data_t1(a, b, ota_control); - INSERT INTO ota.data_t1 VALUES(1, 2, 4); - } {SQLITE_ERROR - invalid ota_control value} + CREATE TABLE rbu.data_t1(a, b, rbu_control); + INSERT INTO rbu.data_t1 VALUES(1, 2, 4); + } {SQLITE_ERROR - invalid rbu_control value} 9 { CREATE TABLE t1(a, b PRIMARY KEY) WITHOUT ROWID; - CREATE TABLE ota.data_t1(a, b, ota_control); - INSERT INTO ota.data_t1 VALUES(1, 2, 2); - } {SQLITE_ERROR - invalid ota_control value} + CREATE TABLE rbu.data_t1(a, b, rbu_control); + INSERT INTO rbu.data_t1 VALUES(1, 2, 2); + } {SQLITE_ERROR - invalid rbu_control value} 10 { CREATE TABLE t2(a, b); - CREATE TABLE ota.data_t1(a, b, ota_control); - INSERT INTO ota.data_t1 VALUES(1, 2, 2); + CREATE TABLE rbu.data_t1(a, b, rbu_control); + INSERT INTO rbu.data_t1 VALUES(1, 2, 2); } {SQLITE_ERROR - no such table: t1} 11 { - CREATE TABLE ota.data_t2(a, b, ota_control); - INSERT INTO ota.data_t2 VALUES(1, 2, 2); + CREATE TABLE rbu.data_t2(a, b, rbu_control); + INSERT INTO rbu.data_t2 VALUES(1, 2, 2); } {SQLITE_ERROR - no such table: t2} } { reset_db - forcedelete ota.db - execsql { ATTACH 'ota.db' AS ota } + forcedelete rbu.db + execsql { ATTACH 'rbu.db' AS rbu } execsql $schema do_test $tn3.7.$tn { - list [catch { run_ota test.db ota.db } msg] $msg + list [catch { run_rbu test.db rbu.db } msg] $msg } [list 1 $error] } } - # Test that an OTA database containing no input tables is handled + # Test that an RBU database containing no input tables is handled # correctly. reset_db - forcedelete ota.db + forcedelete rbu.db do_test $tn3.8 { - list [catch { run_ota test.db ota.db } msg] $msg + list [catch { run_rbu test.db rbu.db } msg] $msg } {0 SQLITE_DONE} - # Test that OTA can update indexes containing NULL values. + # Test that RBU can update indexes containing NULL values. # reset_db - forcedelete ota.db + forcedelete rbu.db do_execsql_test $tn3.9.1 { CREATE TABLE t1(a PRIMARY KEY, b, c); CREATE INDEX i1 ON t1(b, c); @@ -656,14 +656,14 @@ foreach {tn3 create_vfs destroy_vfs} { INSERT INTO t1 VALUES(2, NULL, 2); INSERT INTO t1 VALUES(3, NULL, NULL); - ATTACH 'ota.db' AS ota; - CREATE TABLE ota.data_t1(a, b, c, ota_control); + ATTACH 'rbu.db' AS rbu; + CREATE TABLE rbu.data_t1(a, b, c, rbu_control); INSERT INTO data_t1 VALUES(1, NULL, NULL, 1); INSERT INTO data_t1 VALUES(3, NULL, NULL, 1); } {} do_test $tn3.9.2 { - list [catch { run_ota test.db ota.db } msg] $msg + list [catch { run_rbu test.db rbu.db } msg] $msg } {0 SQLITE_DONE} do_execsql_test $tn3.9.3 { diff --git a/ext/ota/ota10.test b/ext/rbu/rbu10.test index 52cc27a8f..04aab00a0 100644 --- a/ext/ota/ota10.test +++ b/ext/rbu/rbu10.test @@ -14,7 +14,7 @@ if {![info exists testdir]} { set testdir [file join [file dirname [info script]] .. .. test] } source $testdir/tester.tcl -set ::testprefix ota10 +set ::testprefix rbu10 #-------------------------------------------------------------------- @@ -26,19 +26,19 @@ do_execsql_test 1.0 { INSERT INTO t1 VALUES(1, 'b', 'c'); } -proc apply_ota {sql} { - forcedelete ota.db - sqlite3 db2 ota.db +proc apply_rbu {sql} { + forcedelete rbu.db + sqlite3 db2 rbu.db db2 eval $sql db2 close - sqlite3ota ota test.db ota.db - while { [ota step]=="SQLITE_OK" } {} - ota close + sqlite3rbu rbu test.db rbu.db + while { [rbu step]=="SQLITE_OK" } {} + rbu close } do_test 1.1 { - apply_ota { - CREATE TABLE data_t1(a, c, b, ota_control); + apply_rbu { + CREATE TABLE data_t1(a, c, b, rbu_control); INSERT INTO data_t1 VALUES(1, 'xxx', NULL, '.x.'); } db eval { SELECT * FROM t1 } @@ -53,8 +53,8 @@ ifcapable fts3 { CREATE VIRTUAL TABLE ft USING fts4(a, b, languageid='langid'); } do_test 2.1 { - apply_ota { - CREATE TABLE data_ft(a, b, ota_rowid, langid, ota_control); + apply_rbu { + CREATE TABLE data_ft(a, b, rbu_rowid, langid, rbu_control); INSERT INTO data_ft VALUES('a', 'b', 22, 1, 0); -- insert INSERT INTO data_ft VALUES('a', 'b', 23, 10, 0); -- insert INSERT INTO data_ft VALUES('a', 'b', 24, 100, 0); -- insert @@ -70,8 +70,8 @@ ifcapable fts3 { # defaults to 0. # do_test 2.2 { - apply_ota { - CREATE TABLE data_ft(a, b, ota_rowid, ota_control); + apply_rbu { + CREATE TABLE data_ft(a, b, rbu_rowid, rbu_control); INSERT INTO data_ft VALUES('a', 'b', 25, 0); -- insert } db eval { SELECT a, b, rowid, langid FROM ft } @@ -85,8 +85,8 @@ ifcapable fts3 { # Update langid. # do_test 2.3 { - apply_ota { - CREATE TABLE data_ft(a, b, ota_rowid, langid, ota_control); + apply_rbu { + CREATE TABLE data_ft(a, b, rbu_rowid, langid, rbu_control); INSERT INTO data_ft VALUES(NULL, NULL, 23, 50, '..x'); INSERT INTO data_ft VALUES(NULL, NULL, 25, 500, '..x'); } @@ -101,7 +101,7 @@ ifcapable fts3 { #-------------------------------------------------------------------- # Test that if writing a hidden virtual table column is an error, -# attempting to do so via ota is also an error. +# attempting to do so via rbu is also an error. # ifcapable fts3 { do_execsql_test 3.0 { @@ -109,8 +109,8 @@ ifcapable fts3 { } do_test 3.1 { list [catch { - apply_ota { - CREATE TABLE data_xt(a, xt, ota_rowid, ota_control); + apply_rbu { + CREATE TABLE data_xt(a, xt, rbu_rowid, rbu_control); INSERT INTO data_xt VALUES('a', 'b', 1, 0); } } msg] $msg @@ -119,7 +119,7 @@ ifcapable fts3 { #-------------------------------------------------------------------- # Test that it is not possible to violate a NOT NULL constraint by -# applying an OTA update. +# applying an RBU update. # do_execsql_test 4.1 { CREATE TABLE t2(a INTEGER NOT NULL, b TEXT NOT NULL, c PRIMARY KEY); @@ -131,7 +131,7 @@ do_execsql_test 4.1 { INSERT INTO t4 VALUES(10, 10); } -foreach {tn error ota} { +foreach {tn error rbu} { 2 {SQLITE_CONSTRAINT - NOT NULL constraint failed: t2.a} { INSERT INTO data_t2 VALUES(NULL, 'abc', 1, 0); } @@ -163,24 +163,24 @@ foreach {tn error ota} { INSERT INTO data_t3 VALUES(1, 'abc', 'text', 0); } } { - set ota " - CREATE TABLE data_t2(a, b, c, ota_control); - CREATE TABLE data_t3(a, b, c, ota_control); - CREATE TABLE data_t4(a, b, ota_control); - $ota + set rbu " + CREATE TABLE data_t2(a, b, c, rbu_control); + CREATE TABLE data_t3(a, b, c, rbu_control); + CREATE TABLE data_t4(a, b, rbu_control); + $rbu " do_test 4.2.$tn { - list [catch { apply_ota $ota } msg] $msg + list [catch { apply_rbu $rbu } msg] $msg } [list 1 $error] } do_test 4.3 { - set ota { - CREATE TABLE data_t3(a, b, c, ota_control); + set rbu { + CREATE TABLE data_t3(a, b, c, rbu_control); INSERT INTO data_t3 VALUES(1, 'abc', '5', 0); INSERT INTO data_t3 VALUES(1, 'abc', '-6.0', 0); } - list [catch { apply_ota $ota } msg] $msg + list [catch { apply_rbu $rbu } msg] $msg } {0 SQLITE_DONE} diff --git a/ext/ota/ota11.test b/ext/rbu/rbu11.test index 6bd233c0c..fdc701ace 100644 --- a/ext/ota/ota11.test +++ b/ext/rbu/rbu11.test @@ -14,17 +14,17 @@ if {![info exists testdir]} { set testdir [file join [file dirname [info script]] .. .. test] } source $testdir/tester.tcl -set ::testprefix ota11 +set ::testprefix rbu11 #-------------------------------------------------------------------- -# Test that the xAccess() method of an ota vfs handles queries other +# Test that the xAccess() method of an rbu vfs handles queries other # than SQLITE_ACCESS_EXISTS correctly. The test code below causes # SQLite to call xAccess(SQLITE_ACCESS_READWRITE) on the directory # path argument passed to "PRAGMA temp_store_directory". # do_test 1.1 { - sqlite3ota_create_vfs -default ota "" + sqlite3rbu_create_vfs -default rbu "" reset_db catchsql { PRAGMA temp_store_directory = '/no/such/directory' } } {1 {not a writable directory}} @@ -39,11 +39,11 @@ do_test 1.3 { do_test 1.4 { db close - sqlite3ota_destroy_vfs ota + sqlite3rbu_destroy_vfs rbu } {} #-------------------------------------------------------------------- -# Try to trick ota into operating on a database opened in wal mode. +# Try to trick rbu into operating on a database opened in wal mode. # reset_db do_execsql_test 2.1 { @@ -57,10 +57,10 @@ do_test 2.2 { db_save db close - forcedelete ota.db - sqlite3 dbo ota.db + forcedelete rbu.db + sqlite3 dbo rbu.db dbo eval { - CREATE TABLE data_t1(a, b, c, ota_control); + CREATE TABLE data_t1(a, b, c, rbu_control); INSERT INTO data_t1 VALUES(4, 5, 6, 0); INSERT INTO data_t1 VALUES(7, 8, 9, 0); } @@ -72,12 +72,12 @@ do_test 2.2 { } {1} do_test 2.3 { - sqlite3ota ota test.db ota.db - ota step + sqlite3rbu rbu test.db rbu.db + rbu step } {SQLITE_ERROR} do_test 2.4 { - list [catch {ota close} msg] $msg + list [catch {rbu close} msg] $msg } {1 {SQLITE_ERROR - cannot update wal mode database}} #-------------------------------------------------------------------- @@ -94,26 +94,26 @@ do_execsql_test 3.1 { db close do_test 3.2 { - forcedelete ota.db - sqlite3 dbo ota.db + forcedelete rbu.db + sqlite3 dbo rbu.db dbo eval { - CREATE TABLE "data_(t1)"(a, b, c, ota_control); + CREATE TABLE "data_(t1)"(a, b, c, rbu_control); INSERT INTO "data_(t1)" VALUES(4, 8, 9, 0); } dbo close - sqlite3ota ota test.db ota.db - ota step - ota step + sqlite3rbu rbu test.db rbu.db + rbu step + rbu step } {SQLITE_CONSTRAINT} do_test 3.3 { - list [catch {ota close} msg] $msg + list [catch {rbu close} msg] $msg } {1 {SQLITE_CONSTRAINT - UNIQUE constraint failed: (t1).a}} #-------------------------------------------------------------------- -# Check that once an OTA update has been applied, attempting to apply -# it a second time is a no-op (as the state stored in the OTA database is +# Check that once an RBU update has been applied, attempting to apply +# it a second time is a no-op (as the state stored in the RBU database is # "all steps completed"). # reset_db @@ -125,74 +125,74 @@ do_execsql_test 4.1 { db close do_test 4.2 { - forcedelete ota.db - sqlite3 dbo ota.db + forcedelete rbu.db + sqlite3 dbo rbu.db dbo eval { - CREATE TABLE "data_(t1)"(a, b, c, ota_control); + CREATE TABLE "data_(t1)"(a, b, c, rbu_control); INSERT INTO "data_(t1)" VALUES(7, 8, 9, 0); INSERT INTO "data_(t1)" VALUES(1, 2, 3, 1); } dbo close - sqlite3ota ota test.db ota.db - while {[ota step]=="SQLITE_OK"} { } - ota close + sqlite3rbu rbu test.db rbu.db + while {[rbu step]=="SQLITE_OK"} { } + rbu close } {SQLITE_DONE} do_test 4.3 { - sqlite3ota ota test.db ota.db - ota step + sqlite3rbu rbu test.db rbu.db + rbu step } {SQLITE_DONE} do_test 4.4 { - ota close + rbu close } {SQLITE_DONE} do_test 4.5.1 { - sqlite3 dbo ota.db - dbo eval { INSERT INTO ota_state VALUES(100, 100) } + sqlite3 dbo rbu.db + dbo eval { INSERT INTO rbu_state VALUES(100, 100) } dbo close - sqlite3ota ota test.db ota.db - ota step + sqlite3rbu rbu test.db rbu.db + rbu step } {SQLITE_CORRUPT} do_test 4.5.2 { - list [catch {ota close} msg] $msg + list [catch {rbu close} msg] $msg } {1 SQLITE_CORRUPT} do_test 4.5.3 { - sqlite3 dbo ota.db - dbo eval { DELETE FROM ota_state WHERE k = 100 } + sqlite3 dbo rbu.db + dbo eval { DELETE FROM rbu_state WHERE k = 100 } dbo close } {} -# Also, check that an invalid state value in the ota_state table is +# Also, check that an invalid state value in the rbu_state table is # detected and reported as corruption. do_test 4.6.1 { - sqlite3 dbo ota.db - dbo eval { UPDATE ota_state SET v = v*-1 WHERE k = 1 } + sqlite3 dbo rbu.db + dbo eval { UPDATE rbu_state SET v = v*-1 WHERE k = 1 } dbo close - sqlite3ota ota test.db ota.db - ota step + sqlite3rbu rbu test.db rbu.db + rbu step } {SQLITE_CORRUPT} do_test 4.6.2 { - list [catch {ota close} msg] $msg + list [catch {rbu close} msg] $msg } {1 SQLITE_CORRUPT} do_test 4.6.3 { - sqlite3 dbo ota.db - dbo eval { UPDATE ota_state SET v = v*-1 WHERE k = 1 } + sqlite3 dbo rbu.db + dbo eval { UPDATE rbu_state SET v = v*-1 WHERE k = 1 } dbo close } {} do_test 4.7.1 { - sqlite3 dbo ota.db - dbo eval { UPDATE ota_state SET v = 1 WHERE k = 1 } - dbo eval { UPDATE ota_state SET v = 'nosuchtable' WHERE k = 2 } + sqlite3 dbo rbu.db + dbo eval { UPDATE rbu_state SET v = 1 WHERE k = 1 } + dbo eval { UPDATE rbu_state SET v = 'nosuchtable' WHERE k = 2 } dbo close - sqlite3ota ota test.db ota.db - ota step + sqlite3rbu rbu test.db rbu.db + rbu step } {SQLITE_ERROR} do_test 4.7.2 { - list [catch {ota close} msg] $msg -} {1 {SQLITE_ERROR - ota_state mismatch error}} + list [catch {rbu close} msg] $msg +} {1 {SQLITE_ERROR - rbu_state mismatch error}} finish_test diff --git a/ext/ota/ota12.test b/ext/rbu/rbu12.test index b97f10653..a83d0891a 100644 --- a/ext/ota/ota12.test +++ b/ext/rbu/rbu12.test @@ -15,7 +15,7 @@ if {![info exists testdir]} { } source $testdir/tester.tcl source $testdir/lock_common.tcl -set ::testprefix ota12 +set ::testprefix rbu12 set setup_sql { DROP TABLE IF EXISTS xx; @@ -24,34 +24,34 @@ set setup_sql { INSERT INTO xx VALUES(1, 2, 3); CREATE TABLE xy(a, b, c PRIMARY KEY); - ATTACH 'ota.db' AS ota; + ATTACH 'rbu.db' AS rbu; DROP TABLE IF EXISTS data_xx; - CREATE TABLE ota.data_xx(a, b, c, ota_control); + CREATE TABLE rbu.data_xx(a, b, c, rbu_control); INSERT INTO data_xx VALUES(4, 5, 6, 0); INSERT INTO data_xx VALUES(7, 8, 9, 0); - CREATE TABLE ota.data_xy(a, b, c, ota_control); + CREATE TABLE rbu.data_xy(a, b, c, rbu_control); INSERT INTO data_xy VALUES(10, 11, 12, 0); - DETACH ota; + DETACH rbu; } do_multiclient_test tn { - # Initialize a target (test.db) and ota (ota.db) database. + # Initialize a target (test.db) and rbu (rbu.db) database. # - forcedelete ota.db + forcedelete rbu.db sql1 $setup_sql # Using connection 2, open a read transaction on the target database. - # OTA will still be able to generate "test.db-oal", but it will not be + # RBU will still be able to generate "test.db-oal", but it will not be # able to rename it to "test.db-wal". # do_test 1.$tn.1 { sql2 { BEGIN; SELECT * FROM xx; } } {1 2 3} do_test 1.$tn.2 { - sqlite3ota ota test.db ota.db + sqlite3rbu rbu test.db rbu.db while 1 { - set res [ota step] + set res [rbu step] if {$res!="SQLITE_OK"} break } set res @@ -64,119 +64,119 @@ do_multiclient_test tn { } {0 1} do_test 1.$tn.6 { sql2 COMMIT } {} - # The ota object that hit the SQLITE_BUSY error above cannot be reused. + # The rbu object that hit the SQLITE_BUSY error above cannot be reused. # It is stuck in a permanent SQLITE_BUSY state at this point. # - do_test 1.$tn.7 { ota step } {SQLITE_BUSY} + do_test 1.$tn.7 { rbu step } {SQLITE_BUSY} do_test 1.$tn.8 { - list [catch { ota close } msg] $msg + list [catch { rbu close } msg] $msg } {1 SQLITE_BUSY} do_test 1.$tn.9.1 { sql2 { BEGIN EXCLUSIVE } } {} do_test 1.$tn.9.2 { - sqlite3ota ota test.db ota.db - ota step + sqlite3rbu rbu test.db rbu.db + rbu step } {SQLITE_BUSY} do_test 1.$tn.9.3 { - list [catch { ota close } msg] $msg + list [catch { rbu close } msg] $msg } {1 {SQLITE_BUSY - database is locked}} do_test 1.$tn.9.4 { sql2 COMMIT } {} - sqlite3ota ota test.db ota.db + sqlite3rbu rbu test.db rbu.db do_test 1.$tn.10.1 { sql2 { BEGIN EXCLUSIVE } } {} do_test 1.$tn.10.2 { - ota step + rbu step } {SQLITE_BUSY} do_test 1.$tn.10.3 { - list [catch { ota close } msg] $msg + list [catch { rbu close } msg] $msg } {1 SQLITE_BUSY} do_test 1.$tn.10.4 { sql2 COMMIT } {} - # A new ota object can finish the work though. + # A new rbu object can finish the work though. # do_test 1.$tn.11 { - sqlite3ota ota test.db ota.db - ota step + sqlite3rbu rbu test.db rbu.db + rbu step } {SQLITE_OK} do_test 1.$tn.12 { list [file exists test.db-wal] [file exists test.db-oal] } {1 0} do_test 1.$tn.13 { while 1 { - set res [ota step] + set res [rbu step] if {$res!="SQLITE_OK"} break } set res } {SQLITE_DONE} do_test 1.$tn.14 { - ota close + rbu close } {SQLITE_DONE} } do_multiclient_test tn { - # Initialize a target (test.db) and ota (ota.db) database. + # Initialize a target (test.db) and rbu (rbu.db) database. # - forcedelete ota.db + forcedelete rbu.db sql1 $setup_sql do_test 2.$tn.1 { - sqlite3ota ota test.db ota.db + sqlite3rbu rbu test.db rbu.db while {[file exists test.db-wal]==0} { - if {[ota step]!="SQLITE_OK"} {error "problem here...."} + if {[rbu step]!="SQLITE_OK"} {error "problem here...."} } - ota close + rbu close } {SQLITE_OK} do_test 2.$tn.2 { sql2 { BEGIN IMMEDIATE } } {} do_test 2.$tn.3 { - sqlite3ota ota test.db ota.db - ota step + sqlite3rbu rbu test.db rbu.db + rbu step } {SQLITE_BUSY} - do_test 2.$tn.4 { list [catch { ota close } msg] $msg } {1 SQLITE_BUSY} + do_test 2.$tn.4 { list [catch { rbu close } msg] $msg } {1 SQLITE_BUSY} do_test 2.$tn.5 { sql2 { SELECT * FROM xx ; COMMIT } } {1 2 3 4 5 6 7 8 9} do_test 2.$tn.6 { - sqlite3ota ota test.db ota.db - ota step - ota close + sqlite3rbu rbu test.db rbu.db + rbu step + rbu close } {SQLITE_OK} do_test 2.$tn.7 { sql2 { BEGIN EXCLUSIVE } } {} do_test 2.$tn.8 { - sqlite3ota ota test.db ota.db - ota step + sqlite3rbu rbu test.db rbu.db + rbu step } {SQLITE_BUSY} - do_test 2.$tn.9 { list [catch { ota close } msg] $msg } {1 SQLITE_BUSY} + do_test 2.$tn.9 { list [catch { rbu close } msg] $msg } {1 SQLITE_BUSY} do_test 2.$tn.10 { sql2 { SELECT * FROM xx ; COMMIT } } {1 2 3 4 5 6 7 8 9} do_test 2.$tn.11 { - sqlite3ota ota test.db ota.db - while {[ota step]=="SQLITE_OK"} {} - ota close + sqlite3rbu rbu test.db rbu.db + while {[rbu step]=="SQLITE_OK"} {} + rbu close } {SQLITE_DONE} } #------------------------------------------------------------------------- -# Test that "PRAGMA data_version" works when an OTA client writes the +# Test that "PRAGMA data_version" works when an RBU client writes the # database. # do_multiclient_test tn { - # Initialize a target (test.db) and ota (ota.db) database. + # Initialize a target (test.db) and rbu (rbu.db) database. # - forcedelete ota.db + forcedelete rbu.db sql1 $setup_sql # Check the initial database contains table "xx" with a single row. @@ -195,17 +195,17 @@ do_multiclient_test tn { list [sql1 {PRAGMA data_version}] [sql2 {PRAGMA data_version}] } [list $V1 $V2] - # Start stepping the OTA. From the point of view of [db1] and [db2], the + # Start stepping the RBU. From the point of view of [db1] and [db2], the # data-version values remain unchanged until the database contents are # modified. At which point the values are incremented. # - sqlite3ota ota test.db ota.db + sqlite3rbu rbu test.db rbu.db set x 0 while {[db one {SELECT count(*) FROM xx}]==1} { do_test 2.$tn.3.[incr x] { list [sql1 {PRAGMA data_version}] [sql2 {PRAGMA data_version}] } [list $V1 $V2] - ota step + rbu step } do_test 2.$tn.5.1 { expr {$V1 < [sql1 {PRAGMA data_version}]} } 1 do_test 2.$tn.5.2 { expr {$V2 < [sql2 {PRAGMA data_version}]} } 1 @@ -219,11 +219,11 @@ do_multiclient_test tn { set V1 [sql1 {PRAGMA data_version}] set V2 [sql2 {PRAGMA data_version}] - # Finish applying the OTA (i.e. do the incremental checkpoint). Check that + # Finish applying the RBU (i.e. do the incremental checkpoint). Check that # this does not cause the data-version values to change. # - while {[ota step]=="SQLITE_OK"} { } - ota close + while {[rbu step]=="SQLITE_OK"} { } + rbu close do_test 2.$tn.6 { list [sql1 {PRAGMA data_version}] [sql2 {PRAGMA data_version}] diff --git a/ext/ota/ota13.test b/ext/rbu/rbu13.test index 42911a060..ad67a98f8 100644 --- a/ext/ota/ota13.test +++ b/ext/rbu/rbu13.test @@ -9,8 +9,8 @@ # #*********************************************************************** # -# Test an OTA update that features lots of different ota_control strings -# for UPDATE statements. This tests OTA's internal UPDATE statement cache. +# Test an RBU update that features lots of different rbu_control strings +# for UPDATE statements. This tests RBU's internal UPDATE statement cache. # if {![info exists testdir]} { @@ -18,7 +18,7 @@ if {![info exists testdir]} { } source $testdir/tester.tcl source $testdir/lock_common.tcl -set ::testprefix ota13 +set ::testprefix rbu13 do_execsql_test 1.0 { CREATE TABLE t1(a PRIMARY KEY, b, c, d, e, f, g, h); @@ -26,10 +26,10 @@ do_execsql_test 1.0 { INSERT INTO t1 SELECT i, 0, 0, 0, 0, 0, 0, 0 FROM ii; } -forcedelete ota.db +forcedelete rbu.db do_execsql_test 1.1 { - ATTACH 'ota.db' AS ota; - CREATE TABLE ota.data_t1(a, b, c, d, e, f, g, h, ota_control); + ATTACH 'rbu.db' AS rbu; + CREATE TABLE rbu.data_t1(a, b, c, d, e, f, g, h, rbu_control); } do_test 1.2 { @@ -47,12 +47,12 @@ do_test 1.2 { } {} do_test 1.3 { - sqlite3ota ota test.db ota.db + sqlite3rbu rbu test.db rbu.db while 1 { - set rc [ota step] + set rc [rbu step] if {$rc!="SQLITE_OK"} break } - ota close + rbu close } {SQLITE_DONE} do_execsql_test 1.4 { diff --git a/ext/ota/ota3.test b/ext/rbu/rbu3.test index 24d5ffde3..995b3123f 100644 --- a/ext/ota/ota3.test +++ b/ext/rbu/rbu3.test @@ -14,25 +14,25 @@ if {![info exists testdir]} { set testdir [file join [file dirname [info script]] .. .. test] } source $testdir/tester.tcl -set ::testprefix ota3 +set ::testprefix rbu3 -# Run the OTA in file $ota on target database $target until completion. +# Run the RBU in file $rbu on target database $target until completion. # -proc run_ota {target ota} { - sqlite3ota ota $target $ota - while { [ota step]=="SQLITE_OK" } {} - ota close +proc run_rbu {target rbu} { + sqlite3rbu rbu $target $rbu + while { [rbu step]=="SQLITE_OK" } {} + rbu close } -forcedelete test.db-oal ota.db +forcedelete test.db-oal rbu.db db close sqlite3_shutdown sqlite3_config_uri 1 reset_db #-------------------------------------------------------------------- -# Test that for an OTA to be applied, no corruption results if the +# Test that for an RBU to be applied, no corruption results if the # affinities on the source and target table do not match. # do_execsql_test 1.0 { @@ -41,14 +41,14 @@ do_execsql_test 1.0 { } {} do_test 1.1 { - sqlite3 db2 ota.db + sqlite3 db2 rbu.db db2 eval { - CREATE TABLE data_x1(a, b, c, ota_control); + CREATE TABLE data_x1(a, b, c, rbu_control); INSERT INTO data_x1 VALUES(1, '123', '123', 0); INSERT INTO data_x1 VALUES(2, 123, 123, 0); } db2 close - run_ota test.db ota.db + run_rbu test.db rbu.db } {SQLITE_DONE} do_execsql_test 1.2 { @@ -59,7 +59,7 @@ do_execsql_test 1.2 { # Test that NULL values may not be inserted into INTEGER PRIMARY KEY # columns. # -forcedelete ota.db +forcedelete rbu.db reset_db do_execsql_test 2.0 { @@ -67,23 +67,23 @@ do_execsql_test 2.0 { CREATE INDEX i1 ON x1(b, c); } {} -foreach {tn otadb} { +foreach {tn rbudb} { 1 { - CREATE TABLE data_x1(a, b, c, ota_control); + CREATE TABLE data_x1(a, b, c, rbu_control); INSERT INTO data_x1 VALUES(NULL, 'a', 'b', 0); } 2 { - CREATE TABLE data_x1(c, b, a, ota_control); + CREATE TABLE data_x1(c, b, a, rbu_control); INSERT INTO data_x1 VALUES('b', 'a', NULL, 0); } } { do_test 2.$tn.1 { - forcedelete ota.db - sqlite3 db2 ota.db - db2 eval $otadb + forcedelete rbu.db + sqlite3 db2 rbu.db + db2 eval $rbudb db2 close - list [catch { run_ota test.db ota.db } msg] $msg + list [catch { run_rbu test.db rbu.db } msg] $msg } {1 {SQLITE_MISMATCH - datatype mismatch}} do_execsql_test 2.1.2 { @@ -94,7 +94,7 @@ foreach {tn otadb} { #-------------------------------------------------------------------- # Test that missing columns are detected. # -forcedelete ota.db +forcedelete rbu.db reset_db do_execsql_test 2.0 { @@ -103,13 +103,13 @@ do_execsql_test 2.0 { } {} do_test 2.1 { - sqlite3 db2 ota.db + sqlite3 db2 rbu.db db2 eval { - CREATE TABLE data_x1(a, b, ota_control); + CREATE TABLE data_x1(a, b, rbu_control); INSERT INTO data_x1 VALUES(1, 'a', 0); } db2 close - list [catch { run_ota test.db ota.db } msg] $msg + list [catch { run_rbu test.db rbu.db } msg] $msg } {1 {SQLITE_ERROR - column missing from data_x1: c}} do_execsql_test 2.2 { @@ -124,14 +124,14 @@ do_execsql_test 2.3 { } {} do_test 2.4 { - forcedelete ota.db - sqlite3 db2 ota.db + forcedelete rbu.db + sqlite3 db2 rbu.db db2 eval { - CREATE TABLE data_x2(a, b, c, d, ota_control); + CREATE TABLE data_x2(a, b, c, d, rbu_control); INSERT INTO data_x2 VALUES(1, 'a', 2, 3, 0); } db2 close - list [catch { run_ota test.db ota.db } msg] $msg + list [catch { run_rbu test.db rbu.db } msg] $msg } {1 SQLITE_ERROR} do_execsql_test 2.5 { @@ -140,48 +140,48 @@ do_execsql_test 2.5 { #------------------------------------------------------------------------- -# Test that sqlite3ota_create_vfs() returns an error if the requested +# Test that sqlite3rbu_create_vfs() returns an error if the requested # parent VFS is unknown. # # And that nothing disasterous happens if a VFS name passed to -# sqlite3ota_destroy_vfs() is unknown or not an OTA vfs. +# sqlite3rbu_destroy_vfs() is unknown or not an RBU vfs. # do_test 3.1 { - list [catch {sqlite3ota_create_vfs xyz nosuchparent} msg] $msg + list [catch {sqlite3rbu_create_vfs xyz nosuchparent} msg] $msg } {1 SQLITE_NOTFOUND} do_test 3.2 { - sqlite3ota_destroy_vfs nosuchvfs - sqlite3ota_destroy_vfs unix - sqlite3ota_destroy_vfs win32 + sqlite3rbu_destroy_vfs nosuchvfs + sqlite3rbu_destroy_vfs unix + sqlite3rbu_destroy_vfs win32 } {} #------------------------------------------------------------------------- # Test that it is an error to specify an explicit VFS that does not -# include ota VFS functionality. +# include rbu VFS functionality. # do_test 4.1 { testvfs tvfs - sqlite3ota ota file:test.db?vfs=tvfs ota.db - list [catch { ota step } msg] $msg + sqlite3rbu rbu file:test.db?vfs=tvfs rbu.db + list [catch { rbu step } msg] $msg } {0 SQLITE_ERROR} do_test 4.2 { - list [catch { ota close } msg] $msg -} {1 {SQLITE_ERROR - ota vfs not found}} + list [catch { rbu close } msg] $msg +} {1 {SQLITE_ERROR - rbu vfs not found}} tvfs delete #------------------------------------------------------------------------- -# Test a large ota update to ensure that wal_autocheckpoint does not get +# Test a large rbu update to ensure that wal_autocheckpoint does not get # in the way. # -forcedelete ota.db +forcedelete rbu.db reset_db do_execsql_test 5.1 { CREATE TABLE x1(a, b, c, PRIMARY KEY(a)) WITHOUT ROWID; CREATE INDEX i1 ON x1(a); - ATTACH 'ota.db' AS ota; - CREATE TABLE ota.data_x1(a, b, c, ota_control); + ATTACH 'rbu.db' AS rbu; + CREATE TABLE rbu.data_x1(a, b, c, rbu_control); WITH s(a, b, c) AS ( SELECT randomblob(300), randomblob(300), 1 UNION ALL @@ -191,16 +191,16 @@ do_execsql_test 5.1 { } do_test 5.2 { - sqlite3ota ota test.db ota.db - while {[ota step]=="SQLITE_OK" && [file exists test.db-wal]==0} {} - ota close + sqlite3rbu rbu test.db rbu.db + while {[rbu step]=="SQLITE_OK" && [file exists test.db-wal]==0} {} + rbu close } {SQLITE_OK} do_test 5.3 { expr {[file size test.db-wal] > (1024 * 1200)} } 1 -do_test 6.1 { sqlite3ota_internal_test } {} +do_test 6.1 { sqlite3rbu_internal_test } {} finish_test diff --git a/ext/ota/ota5.test b/ext/rbu/rbu5.test index 8b62eb0f6..9a0f17bc5 100644 --- a/ext/ota/ota5.test +++ b/ext/rbu/rbu5.test @@ -9,33 +9,33 @@ # #*********************************************************************** # -# Test some properties of the pager_ota_mode and ota_mode pragmas. +# Test some properties of the pager_rbu_mode and rbu_mode pragmas. # if {![info exists testdir]} { set testdir [file join [file dirname [info script]] .. .. test] } source $testdir/tester.tcl -set ::testprefix ota5 +set ::testprefix rbu5 -# Run the OTA in file $ota on target database $target until completion. +# Run the RBU in file $rbu on target database $target until completion. # -proc run_ota {target ota} { - sqlite3ota ota $target $ota - while { [ota step]=="SQLITE_OK" } {} - ota close +proc run_rbu {target rbu} { + sqlite3rbu rbu $target $rbu + while { [rbu step]=="SQLITE_OK" } {} + rbu close } -# Run the OTA in file $ota on target database $target one step at a +# Run the RBU in file $rbu on target database $target one step at a # time until completion. # -proc step_ota {target ota} { +proc step_rbu {target rbu} { while 1 { - sqlite3ota ota $target $ota - set rc [ota step] - ota close + sqlite3rbu rbu $target $rbu + set rc [rbu step] + rbu close if {$rc != "SQLITE_OK"} break } set rc @@ -99,31 +99,31 @@ proc ucontrol {args} { # Argument $target is the name of an SQLite database file. $sql is an SQL # script containing INSERT, UPDATE and DELETE statements to execute against -# it. This command creates an OTA update database in file $ota that has +# it. This command creates an RBU update database in file $rbu that has # the same effect as the script. The target database is not modified by # this command. # -proc generate_ota_db {target ota sql} { +proc generate_rbu_db {target rbu sql} { - forcedelete $ota + forcedelete $rbu forcecopy $target copy.db # Evaluate the SQL script to modify the contents of copy.db. # - sqlite3 dbOta copy.db - dbOta eval $sql + sqlite3 dbRbu copy.db + dbRbu eval $sql - dbOta function ucontrol ucontrol + dbRbu function ucontrol ucontrol # Evaluate the SQL script to modify the contents of copy.db. - set ret [datacksum dbOta] + set ret [datacksum dbRbu] - dbOta eval { ATTACH $ota AS ota } - dbOta eval { ATTACH $target AS orig } + dbRbu eval { ATTACH $rbu AS rbu } + dbRbu eval { ATTACH $target AS orig } - dbOta eval { SELECT name AS tbl FROM sqlite_master WHERE type = 'table' } { - set pk [pkcols dbOta $tbl] - set cols [allcols dbOta $tbl] + dbRbu eval { SELECT name AS tbl FROM sqlite_master WHERE type = 'table' } { + set pk [pkcols dbRbu $tbl] + set cols [allcols dbRbu $tbl] # A WHERE clause to test that the PK columns match. # @@ -138,25 +138,25 @@ proc generate_ota_db {target ota sql} { set ucontrol "ucontrol([join $where2 ,])" set where2 [join $where2 " AND "] - # Create a data_xxx table in the OTA update database. - dbOta eval " - CREATE TABLE ota.data_$tbl AS SELECT *, '' AS ota_control + # Create a data_xxx table in the RBU update database. + dbRbu eval " + CREATE TABLE rbu.data_$tbl AS SELECT *, '' AS rbu_control FROM main.$tbl LIMIT 0 " # Find all new rows INSERTed by the script. - dbOta eval " - INSERT INTO ota.data_$tbl - SELECT *, 0 AS ota_control FROM main.$tbl + dbRbu eval " + INSERT INTO rbu.data_$tbl + SELECT *, 0 AS rbu_control FROM main.$tbl WHERE NOT EXISTS ( SELECT 1 FROM orig.$tbl WHERE $where ) " # Find all old rows DELETEd by the script. - dbOta eval " - INSERT INTO ota.data_$tbl - SELECT *, 1 AS ota_control FROM orig.$tbl + dbRbu eval " + INSERT INTO rbu.data_$tbl + SELECT *, 1 AS rbu_control FROM orig.$tbl WHERE NOT EXISTS ( SELECT 1 FROM main.$tbl WHERE $where ) @@ -166,16 +166,16 @@ proc generate_ota_db {target ota sql} { set origcols [list] foreach c $cols { lappend origcols "main.$tbl.$c" } set origcols [join $origcols ,] - dbOta eval " - INSERT INTO ota.data_$tbl - SELECT $origcols, $ucontrol AS ota_control + dbRbu eval " + INSERT INTO rbu.data_$tbl + SELECT $origcols, $ucontrol AS rbu_control FROM orig.$tbl, main.$tbl WHERE $where AND NOT ($where2) " } - dbOta close + dbRbu close forcedelete copy.db return $ret @@ -197,7 +197,7 @@ do_execsql_test 1.0 { } db close -set cksum [generate_ota_db test.db ota.db { +set cksum [generate_rbu_db test.db rbu.db { INSERT INTO t1 VALUES(4, 8, 12); DELETE FROM t1 WHERE a = 2; UPDATE t1 SET c = 15 WHERE a=3; @@ -217,13 +217,13 @@ foreach {tn idx} { } { foreach cmd {run step} { forcecopy test.db test.db2 - forcecopy ota.db ota.db2 + forcecopy rbu.db rbu.db2 sqlite3 db test.db2 db eval $idx do_test 1.$tn.$cmd.1 { - ${cmd}_ota test.db2 ota.db2 + ${cmd}_rbu test.db2 rbu.db2 datacksum db } $cksum @@ -265,7 +265,7 @@ do_execsql_test 2.0 { } db close -set cksum [generate_ota_db test.db ota.db { +set cksum [generate_rbu_db test.db rbu.db { INSERT INTO t2 VALUES(222916.23,'idh',X'472C517405',X'E3',X'7C4F31824669'); INSERT INTO t2 VALUES('xcndjwafcoxwxizoktd',-319567.21,NULL,-720906.43,-577170); INSERT INTO t2 VALUES(376369.99,-536058,'yoaiurfqupdscwc',X'29EC8A2542EC3953E9',-740485.22); @@ -305,13 +305,13 @@ foreach {tn idx} { } { foreach cmd {run step} { forcecopy test.db test.db2 - forcecopy ota.db ota.db2 + forcecopy rbu.db rbu.db2 sqlite3 db test.db2 db eval $idx do_test 2.$tn.$cmd.1 { - ${cmd}_ota test.db2 ota.db2 + ${cmd}_rbu test.db2 rbu.db2 datacksum db } $cksum diff --git a/ext/ota/ota6.test b/ext/rbu/rbu6.test index 4fe14950b..f05721574 100644 --- a/ext/ota/ota6.test +++ b/ext/rbu/rbu6.test @@ -9,15 +9,15 @@ # #*********************************************************************** # -# This file contains tests for the OTA module. Specifically, it tests the -# outcome of some other client writing to the database while an OTA update +# This file contains tests for the RBU module. Specifically, it tests the +# outcome of some other client writing to the database while an RBU update # is being applied. if {![info exists testdir]} { set testdir [file join [file dirname [info script]] .. .. test] } source $testdir/tester.tcl -set ::testprefix ota6 +set ::testprefix rbu6 proc setup_test {} { reset_db @@ -28,17 +28,17 @@ proc setup_test {} { } db close - forcedelete ota.db - sqlite3 ota ota.db - ota eval { - CREATE TABLE data_t1(a, b, ota_control); - CREATE TABLE data_t2(a, b, ota_control); - CREATE TABLE data_t3(a, b, ota_control); + forcedelete rbu.db + sqlite3 rbu rbu.db + rbu eval { + CREATE TABLE data_t1(a, b, rbu_control); + CREATE TABLE data_t2(a, b, rbu_control); + CREATE TABLE data_t3(a, b, rbu_control); INSERT INTO data_t1 VALUES(1, 't1', 0); INSERT INTO data_t2 VALUES(2, 't2', 0); INSERT INTO data_t3 VALUES(3, 't3', 0); } - ota close + rbu close } # Test the outcome of some other client writing the db while the *-oal @@ -48,49 +48,49 @@ proc setup_test {} { for {set nStep 1} {$nStep < 8} {incr nStep} { do_test 1.$nStep.1 { setup_test - sqlite3ota ota test.db ota.db - for {set i 0} {$i<$nStep} {incr i} {ota step} + sqlite3rbu rbu test.db rbu.db + for {set i 0} {$i<$nStep} {incr i} {rbu step} - ota close + rbu close sqlite3 db test.db execsql { INSERT INTO t1 VALUES(5, 'hello') } - sqlite3ota ota test.db ota.db - ota step + sqlite3rbu rbu test.db rbu.db + rbu step } {SQLITE_BUSY} do_test 1.$nStep.2 { - ota step + rbu step } {SQLITE_BUSY} do_test 1.$nStep.3 { list [file exists test.db-oal] [file exists test.db-wal] } {1 0} do_test 1.$nStep.4 { - list [catch { ota close } msg] $msg - } {1 {SQLITE_BUSY - database modified during ota update}} + list [catch { rbu close } msg] $msg + } {1 {SQLITE_BUSY - database modified during rbu update}} } # Test the outcome of some other client writing the db after the *-oal # file has been copied to the *-wal path. Once this has happened, any -# other client writing to the db causes OTA to consider its job finished. +# other client writing to the db causes RBU to consider its job finished. # for {set nStep 8} {$nStep < 20} {incr nStep} { do_test 1.$nStep.1 { setup_test - sqlite3ota ota test.db ota.db - for {set i 0} {$i<$nStep} {incr i} {ota step} - ota close + sqlite3rbu rbu test.db rbu.db + for {set i 0} {$i<$nStep} {incr i} {rbu step} + rbu close sqlite3 db test.db execsql { INSERT INTO t1 VALUES(5, 'hello') } - sqlite3ota ota test.db ota.db - ota step + sqlite3rbu rbu test.db rbu.db + rbu step } {SQLITE_DONE} do_test 1.$nStep.2 { - ota step + rbu step } {SQLITE_DONE} do_test 1.$nStep.3 { file exists test.db-oal } {0} do_test 1.$nStep.4 { - list [catch { ota close } msg] $msg + list [catch { rbu close } msg] $msg } {0 SQLITE_DONE} do_execsql_test 1.$nStep.5 { diff --git a/ext/ota/ota7.test b/ext/rbu/rbu7.test index a4ee6b41a..f773c9e5a 100644 --- a/ext/ota/ota7.test +++ b/ext/rbu/rbu7.test @@ -9,7 +9,7 @@ # #*********************************************************************** # -# This file contains tests for the OTA module. +# This file contains tests for the RBU module. # @@ -17,12 +17,12 @@ if {![info exists testdir]} { set testdir [file join [file dirname [info script]] .. .. test] } source $testdir/tester.tcl -set ::testprefix ota7 +set ::testprefix rbu7 # Test index: # # 1.*: That affinities are correctly applied to values within the -# OTA database. +# RBU database. # # 2.*: Tests for multi-column primary keys. # @@ -34,19 +34,19 @@ do_test 1.0 { INSERT INTO t1 VALUES(2, 'def'); } - forcedelete ota.db - sqlite3 ota ota.db - ota eval { - CREATE TABLE data_t1(a, b, ota_control); + forcedelete rbu.db + sqlite3 rbu rbu.db + rbu eval { + CREATE TABLE data_t1(a, b, rbu_control); INSERT INTO data_t1 VALUES('1', NULL, 1); } - ota close + rbu close } {} do_test 1.1 { - sqlite3ota ota test.db ota.db - while { [ota step]=="SQLITE_OK" } {} - ota close + sqlite3rbu rbu test.db rbu.db + while { [rbu step]=="SQLITE_OK" } {} + rbu close } {SQLITE_DONE} sqlite3 db test.db @@ -72,24 +72,24 @@ foreach {tn tbl} { } do_test 2.$tn.2 { - forcedelete ota.db - sqlite3 ota ota.db + forcedelete rbu.db + sqlite3 rbu rbu.db execsql { - CREATE TABLE data_t1(a, b, c, ota_control); + CREATE TABLE data_t1(a, b, c, rbu_control); INSERT INTO data_t1 VALUES(3, 1, 'e', 0); INSERT INTO data_t1 VALUES(3, 2, 'f', 0); INSERT INTO data_t1 VALUES(1, 2, NULL, 1); INSERT INTO data_t1 VALUES(2, 1, 'X', '..x'); - } ota - ota close + } rbu + rbu close } {} do_test 2.$tn.3 { set rc "SQLITE_OK" while {$rc == "SQLITE_OK"} { - sqlite3ota ota test.db ota.db - ota step - set rc [ota close] + sqlite3rbu rbu test.db rbu.db + rbu step + set rc [rbu close] } set rc } {SQLITE_DONE} diff --git a/ext/ota/ota8.test b/ext/rbu/rbu8.test index 24a6e7224..75edd4efb 100644 --- a/ext/ota/ota8.test +++ b/ext/rbu/rbu8.test @@ -9,14 +9,14 @@ # #*********************************************************************** # -# Test the ota_delta() feature. +# Test the rbu_delta() feature. # if {![info exists testdir]} { set testdir [file join [file dirname [info script]] .. .. test] } source $testdir/tester.tcl -set ::testprefix ota8 +set ::testprefix rbu8 do_execsql_test 1.0 { CREATE TABLE t1(x, y PRIMARY KEY, z); @@ -27,10 +27,10 @@ do_execsql_test 1.0 { } do_test 1.1 { - forcedelete ota.db - sqlite3 db2 ota.db + forcedelete rbu.db + sqlite3 db2 rbu.db db2 eval { - CREATE TABLE data_t1(x, y, z, ota_control); + CREATE TABLE data_t1(x, y, z, rbu_control); INSERT INTO data_t1 VALUES('a', 1, '_i' , 'x.d'); INSERT INTO data_t1 VALUES('b', 2, 2 , '..x'); INSERT INTO data_t1 VALUES('_iii', 3, '-III' , 'd.d'); @@ -39,26 +39,26 @@ do_test 1.1 { } {} do_test 1.2.1 { - sqlite3ota ota test.db ota.db - ota step + sqlite3rbu rbu test.db rbu.db + rbu step } {SQLITE_ERROR} do_test 1.2.2 { - list [catch {ota close} msg] $msg -} {1 {SQLITE_ERROR - no such function: ota_delta}} + list [catch {rbu close} msg] $msg +} {1 {SQLITE_ERROR - no such function: rbu_delta}} -proc ota_delta {orig new} { +proc rbu_delta {orig new} { return "${orig}${new}" } do_test 1.3.1 { while 1 { - sqlite3ota ota test.db ota.db - ota create_ota_delta - set rc [ota step] + sqlite3rbu rbu test.db rbu.db + rbu create_rbu_delta + set rc [rbu step] if {$rc != "SQLITE_OK"} break - ota close + rbu close } - ota close + rbu close } {SQLITE_DONE} do_execsql_test 1.3.2 { diff --git a/ext/ota/ota9.test b/ext/rbu/rbu9.test index e746d363f..3ce649d25 100644 --- a/ext/ota/ota9.test +++ b/ext/rbu/rbu9.test @@ -9,14 +9,14 @@ # #*********************************************************************** # -# Test OTA with virtual tables. And tables with no PRIMARY KEY declarations. +# Test RBU with virtual tables. And tables with no PRIMARY KEY declarations. # if {![info exists testdir]} { set testdir [file join [file dirname [info script]] .. .. test] } source $testdir/tester.tcl -set ::testprefix ota9 +set ::testprefix rbu9 ifcapable !fts3 { finish_test @@ -31,10 +31,10 @@ do_execsql_test 1.1 { } do_test 1.1 { - forcedelete ota.db - sqlite3 db2 ota.db + forcedelete rbu.db + sqlite3 db2 rbu.db db2 eval { - CREATE TABLE data_f1(ota_rowid, a, b, c, ota_control); + CREATE TABLE data_f1(rbu_rowid, a, b, c, rbu_control); INSERT INTO data_f1 VALUES(14, 'x', 'y', 'z', 0); -- INSERT INSERT INTO data_f1 VALUES(11, NULL, NULL, NULL, 1); -- DELETE INSERT INTO data_f1 VALUES(13, NULL, NULL, 'X', '..x'); -- UPDATE @@ -44,12 +44,12 @@ do_test 1.1 { do_test 1.2.1 { while 1 { - sqlite3ota ota test.db ota.db - set rc [ota step] + sqlite3rbu rbu test.db rbu.db + set rc [rbu step] if {$rc != "SQLITE_OK"} break - ota close + rbu close } - ota close + rbu close } {SQLITE_DONE} do_execsql_test 1.2.2 { SELECT rowid, * FROM f1 } { @@ -64,12 +64,12 @@ integrity_check 1.2.4 # Tables with no PK declaration. # -# Run the OTA in file $ota on target database $target until completion. +# Run the RBU in file $rbu on target database $target until completion. # -proc run_ota {target ota} { - sqlite3ota ota $target $ota - while { [ota step]=="SQLITE_OK" } {} - ota close +proc run_rbu {target rbu} { + sqlite3rbu rbu $target $rbu + while { [rbu step]=="SQLITE_OK" } {} + rbu close } foreach {tn idx} { @@ -96,10 +96,10 @@ foreach {tn idx} { db eval $idx do_test 2.$tn.2 { - forcedelete ota.db - sqlite3 db2 ota.db + forcedelete rbu.db + sqlite3 db2 rbu.db db2 eval { - CREATE TABLE data_t1(ota_rowid, a, b, c, ota_control); + CREATE TABLE data_t1(rbu_rowid, a, b, c, rbu_control); INSERT INTO data_t1 VALUES(3, 'x', 'y', 'z', 0); INSERT INTO data_t1 VALUES(NULL, 'X', 'Y', 'Z', 0); INSERT INTO data_t1 VALUES('1', NULL, NULL, NULL, 1); @@ -108,7 +108,7 @@ foreach {tn idx} { db2 close } {} - run_ota test.db ota.db + run_rbu test.db rbu.db do_execsql_test 2.$tn.3 { SELECT rowid, a, b, c FROM t1 ORDER BY rowid; diff --git a/ext/ota/otaA.test b/ext/rbu/rbuA.test index bcc9a8b72..d15a7dbb7 100644 --- a/ext/ota/otaA.test +++ b/ext/rbu/rbuA.test @@ -9,22 +9,22 @@ # #*********************************************************************** # -# This file contains tests for the OTA module. More specifically, it +# This file contains tests for the RBU module. More specifically, it # contains tests to ensure that it is an error to attempt to update -# a wal mode database via OTA. +# a wal mode database via RBU. # if {![info exists testdir]} { set testdir [file join [file dirname [info script]] .. .. test] } source $testdir/tester.tcl -set ::testprefix otaA +set ::testprefix rbuA set db_sql { CREATE TABLE t1(a PRIMARY KEY, b, c); } -set ota_sql { - CREATE TABLE data_t1(a, b, c, ota_control); +set rbu_sql { + CREATE TABLE data_t1(a, b, c, rbu_control); INSERT INTO data_t1 VALUES(1, 2, 3, 0); INSERT INTO data_t1 VALUES(4, 5, 6, 0); INSERT INTO data_t1 VALUES(7, 8, 9, 0); @@ -32,38 +32,38 @@ set ota_sql { do_test 1.0 { db close - forcedelete test.db ota.db + forcedelete test.db rbu.db sqlite3 db test.db db eval $db_sql db eval { PRAGMA journal_mode = wal } db close - sqlite3 db ota.db - db eval $ota_sql + sqlite3 db rbu.db + db eval $rbu_sql db close - sqlite3ota ota test.db ota.db - ota step + sqlite3rbu rbu test.db rbu.db + rbu step } {SQLITE_ERROR} do_test 1.1 { - list [catch { ota close } msg] $msg + list [catch { rbu close } msg] $msg } {1 {SQLITE_ERROR - cannot update wal mode database}} do_test 2.0 { - forcedelete test.db ota.db + forcedelete test.db rbu.db sqlite3 db test.db db eval $db_sql db close - sqlite3 db ota.db - db eval $ota_sql + sqlite3 db rbu.db + db eval $rbu_sql db close - sqlite3ota ota test.db ota.db - ota step - ota close + sqlite3rbu rbu test.db rbu.db + rbu step + rbu close } {SQLITE_OK} do_test 2.1 { @@ -71,12 +71,12 @@ do_test 2.1 { db eval {PRAGMA journal_mode = wal} db close breakpoint - sqlite3ota ota test.db ota.db - ota step + sqlite3rbu rbu test.db rbu.db + rbu step } {SQLITE_ERROR} do_test 2.2 { - list [catch { ota close } msg] $msg + list [catch { rbu close } msg] $msg } {1 {SQLITE_ERROR - cannot update wal mode database}} diff --git a/ext/ota/otacrash.test b/ext/rbu/rbucrash.test index 992b87cd0..40993ac61 100644 --- a/ext/ota/otacrash.test +++ b/ext/rbu/rbucrash.test @@ -14,16 +14,16 @@ if {![info exists testdir]} { set testdir [file join [file dirname [info script]] .. .. test] } source $testdir/tester.tcl -set ::testprefix otacrash +set ::testprefix rbucrash db close -forcedelete test.db-oal ota.db +forcedelete test.db-oal rbu.db sqlite3_shutdown sqlite3_config_uri 1 reset_db -# Set up a target database and an ota update database. The target -# db is the usual "test.db", the ota db is "test.db2". +# Set up a target database and an rbu update database. The target +# db is the usual "test.db", the rbu db is "test.db2". # forcedelete test.db2 do_execsql_test 1.0 { @@ -32,8 +32,8 @@ do_execsql_test 1.0 { INSERT INTO t1 VALUES(4, 5, 6); INSERT INTO t1 VALUES(7, 8, 9); - ATTACH 'test.db2' AS ota; - CREATE TABLE ota.data_t1(a, b, c, ota_control); + ATTACH 'test.db2' AS rbu; + CREATE TABLE rbu.data_t1(a, b, c, rbu_control); INSERT INTO data_t1 VALUES(10, 11, 12, 0); INSERT INTO data_t1 VALUES(13, 14, 15, 0); INSERT INTO data_t1 VALUES(4, NULL, NULL, 1); @@ -42,63 +42,63 @@ do_execsql_test 1.0 { db_save_and_close -# Determine the number of steps in applying the ota update to the test -# target database created above. Set $::ota_num_steps accordingly +# Determine the number of steps in applying the rbu update to the test +# target database created above. Set $::rbu_num_steps accordingly # -# Check that the same number of steps are required to apply the ota -# update using many calls to sqlite3ota_step() on a single ota handle -# as required to apply it using a series of ota handles, on each of -# which sqlite3ota_step() is called once. +# Check that the same number of steps are required to apply the rbu +# update using many calls to sqlite3rbu_step() on a single rbu handle +# as required to apply it using a series of rbu handles, on each of +# which sqlite3rbu_step() is called once. # do_test 1.1 { db_restore - sqlite3ota ota test.db test.db2 + sqlite3rbu rbu test.db test.db2 breakpoint set nStep 0 - while {[ota step]=="SQLITE_OK"} { incr nStep } - ota close + while {[rbu step]=="SQLITE_OK"} { incr nStep } + rbu close } {SQLITE_DONE} -set ota_num_steps $nStep +set rbu_num_steps $nStep do_test 1.2 { db_restore set nStep 0 while {1} { - sqlite3ota ota test.db test.db2 - ota step - if {[ota close]=="SQLITE_DONE"} break + sqlite3rbu rbu test.db test.db2 + rbu step + if {[rbu close]=="SQLITE_DONE"} break incr nStep } set nStep -} $ota_num_steps +} $rbu_num_steps -# Run one or more tests using the target (test.db) and ota (test.db2) +# Run one or more tests using the target (test.db) and rbu (test.db2) # databases created above. As follows: # -# 1. This process starts the ota update and calls sqlite3ota_step() -# $nPre times. Then closes the ota update handle. +# 1. This process starts the rbu update and calls sqlite3rbu_step() +# $nPre times. Then closes the rbu update handle. # -# 2. A second process resumes the ota update and attempts to call -# sqlite3ota_step() $nStep times before closing the handle. A +# 2. A second process resumes the rbu update and attempts to call +# sqlite3rbu_step() $nStep times before closing the handle. A # crash is simulated during each xSync() of file test.db2. # -# 3. This process attempts to resume the ota update from whatever +# 3. This process attempts to resume the rbu update from whatever # state it was left in by step (2). Test that it is successful # in doing so and that the final target database is as expected. # # In total (nSync+1) tests are run, where nSync is the number of times # xSync() is called on test.db2. # -proc do_ota_crash_test {tn nPre nStep} { +proc do_rbu_crash_test {tn nPre nStep} { set script [subst -nocommands { - sqlite3ota ota test.db file:test.db2?vfs=crash + sqlite3rbu rbu test.db file:test.db2?vfs=crash set i 0 while {[set i] < $nStep} { - if {[ota step]!="SQLITE_OK"} break + if {[rbu step]!="SQLITE_OK"} break incr i } - ota close + rbu close }] set bDone 0 @@ -107,12 +107,12 @@ proc do_ota_crash_test {tn nPre nStep} { db_restore if {$nPre>0} { - sqlite3ota ota test.db file:test.db2 + sqlite3rbu rbu test.db file:test.db2 set i 0 for {set i 0} {$i < $nPre} {incr i} { - if {[ota step]!="SQLITE_OK"} break + if {[rbu step]!="SQLITE_OK"} break } - ota close + rbu close } set res [ @@ -126,9 +126,9 @@ proc do_ota_crash_test {tn nPre nStep} { error "unexected catchsql result: $res" } - sqlite3ota ota test.db test.db2 - while {[ota step]=="SQLITE_OK"} {} - ota close + sqlite3rbu rbu test.db test.db2 + while {[rbu step]=="SQLITE_OK"} {} + rbu close sqlite3 db test.db do_execsql_test $tn.delay=$iDelay { @@ -139,9 +139,9 @@ proc do_ota_crash_test {tn nPre nStep} { } } -for {set nPre 0} {$nPre < $ota_num_steps} {incr nPre} { - for {set is 1} {$is <= ($ota_num_steps - $nPre)} {incr is} { - do_ota_crash_test 2.pre=$nPre.step=$is $nPre $is +for {set nPre 0} {$nPre < $rbu_num_steps} {incr nPre} { + for {set is 1} {$is <= ($rbu_num_steps - $nPre)} {incr is} { + do_rbu_crash_test 2.pre=$nPre.step=$is $nPre $is } } diff --git a/ext/ota/otafault.test b/ext/rbu/rbufault.test index de6939a55..3f30fb233 100644 --- a/ext/ota/otafault.test +++ b/ext/rbu/rbufault.test @@ -15,7 +15,7 @@ if {![info exists testdir]} { } source $testdir/tester.tcl source $testdir/malloc_common.tcl -set ::testprefix otafault +set ::testprefix rbufault proc copy_if_exists {src target} { if {[file exists $src]} { @@ -33,7 +33,7 @@ foreach {tn2 setup sql expect} { INSERT INTO t1 VALUES(2, 2, 2); INSERT INTO t1 VALUES(3, 3, 3); - CREATE TABLE ota.data_t1(a, b, c, ota_control); + CREATE TABLE rbu.data_t1(a, b, c, rbu_control); INSERT INTO data_t1 VALUES(2, NULL, NULL, 1); INSERT INTO data_t1 VALUES(3, 'three', NULL, '.x.'); INSERT INTO data_t1 VALUES(4, 4, 4, 0); @@ -48,7 +48,7 @@ foreach {tn2 setup sql expect} { INSERT INTO t2 VALUES('b', 'b', 'b'); INSERT INTO t2 VALUES('c', 'c', 'c'); - CREATE TABLE ota.data_t2(a, b, c, ota_control); + CREATE TABLE rbu.data_t2(a, b, c, rbu_control); INSERT INTO data_t2 VALUES('b', NULL, NULL, 1); INSERT INTO data_t2 VALUES('c', 'see', NULL, '.x.'); INSERT INTO data_t2 VALUES('d', 'd', 'd', 0); @@ -62,8 +62,8 @@ foreach {tn2 setup sql expect} { CREATE INDEX t1cb ON t1(c, b); CREATE INDEX t2cb ON t2(c, b); - CREATE TABLE ota.data_t1(a, b, c, ota_control); - CREATE TABLE ota.data_t2(a, b, c, ota_control); + CREATE TABLE rbu.data_t1(a, b, c, rbu_control); + CREATE TABLE rbu.data_t2(a, b, c, rbu_control); INSERT INTO data_t1 VALUES(1, 2, 3, 0); INSERT INTO data_t2 VALUES(4, 5, 6, 0); } { @@ -76,7 +76,7 @@ foreach {tn2 setup sql expect} { INSERT INTO t1 VALUES('A', 'B', 'C'); INSERT INTO t1 VALUES('D', 'E', 'F'); - CREATE TABLE ota.data_t1(a, b, c, ota_control); + CREATE TABLE rbu.data_t1(a, b, c, rbu_control); INSERT INTO data_t1 VALUES('D', NULL, NULL, 1); INSERT INTO data_t1 VALUES('A', 'Z', NULL, '.x.'); INSERT INTO data_t1 VALUES('G', 'H', 'I', 0); @@ -88,7 +88,7 @@ foreach {tn2 setup sql expect} { CREATE TABLE t1(a, b, c); CREATE INDEX t1c ON t1(c, b); - CREATE TABLE ota.data_t1(a, b, c, ota_rowid, ota_control); + CREATE TABLE rbu.data_t1(a, b, c, rbu_rowid, rbu_control); INSERT INTO data_t1 VALUES('a', 'b', 'c', 1, 0); INSERT INTO data_t1 VALUES('d', 'e', 'f', '2', 0); } { @@ -97,17 +97,17 @@ foreach {tn2 setup sql expect} { } { catch {db close} - forcedelete ota.db test.db + forcedelete rbu.db test.db sqlite3 db test.db execsql { PRAGMA encoding = utf16; - ATTACH 'ota.db' AS ota; + ATTACH 'rbu.db' AS rbu; } execsql $setup db close forcecopy test.db test.db.bak - forcecopy ota.db ota.db.bak + forcecopy rbu.db rbu.db.bak foreach {tn f reslist} { 1 oom-tra* { @@ -126,8 +126,8 @@ foreach {tn2 setup sql expect} { {1 SQLITE_IOERR_READ} {1 SQLITE_IOERR_FSYNC} {1 {SQLITE_ERROR - SQL logic error or missing database}} - {1 {SQLITE_ERROR - unable to open database: ota.db}} - {1 {SQLITE_IOERR - unable to open database: ota.db}} + {1 {SQLITE_ERROR - unable to open database: rbu.db}} + {1 {SQLITE_IOERR - unable to open database: rbu.db}} } 3 shmerr-* { @@ -145,13 +145,13 @@ foreach {tn2 setup sql expect} { do_faultsim_test 2.$tn2 -faults $::f -prep { catch { db close } - forcedelete test.db-journal test.db-wal ota.db-journal ota.db-wal + forcedelete test.db-journal test.db-wal rbu.db-journal rbu.db-wal forcecopy test.db.bak test.db - forcecopy ota.db.bak ota.db + forcecopy rbu.db.bak rbu.db } -body { - sqlite3ota ota test.db ota.db - while {[ota step]=="SQLITE_OK"} {} - ota close + sqlite3rbu rbu test.db rbu.db + while {[rbu step]=="SQLITE_OK"} {} + rbu close } -test { faultsim_test_result {*}$::reslist if {$testrc==0} { @@ -176,46 +176,46 @@ foreach {tn2 setup sql expect} { for {set iStep 0} {$iStep<=21} {incr iStep} { - forcedelete test.db-journal test.db-wal ota.db-journal ota.db-wal + forcedelete test.db-journal test.db-wal rbu.db-journal rbu.db-wal copy_if_exists test.db.bak test.db - copy_if_exists ota.db.bak ota.db + copy_if_exists rbu.db.bak rbu.db - sqlite3ota ota test.db ota.db - for {set x 0} {$x < $::iStep} {incr x} { ota step } - ota close + sqlite3rbu rbu test.db rbu.db + for {set x 0} {$x < $::iStep} {incr x} { rbu step } + rbu close -# sqlite3 x ota.db ; puts "XYZ [x eval { SELECT * FROM ota_state } ]" ; x close +# sqlite3 x rbu.db ; puts "XYZ [x eval { SELECT * FROM rbu_state } ]" ; x close copy_if_exists test.db test.db.bak.2 copy_if_exists test.db-wal test.db.bak.2-wal copy_if_exists test.db-oal test.db.bak.2-oal - copy_if_exists ota.db ota.db.bak.2 + copy_if_exists rbu.db rbu.db.bak.2 do_faultsim_test 3.$tn.$iStep -faults $::f -prep { catch { db close } - forcedelete test.db-journal test.db-wal ota.db-journal ota.db-wal + forcedelete test.db-journal test.db-wal rbu.db-journal rbu.db-wal copy_if_exists test.db.bak.2 test.db copy_if_exists test.db.bak.2-wal test.db-wal copy_if_exists test.db.bak.2-oal test.db-oal - copy_if_exists ota.db.bak.2 ota.db + copy_if_exists rbu.db.bak.2 rbu.db } -body { - sqlite3ota ota test.db ota.db - ota step - ota close + sqlite3rbu rbu test.db rbu.db + rbu step + rbu close } -test { if {$testresult=="SQLITE_OK"} {set testresult "SQLITE_DONE"} faultsim_test_result {*}$::reslist if {$testrc==0} { - # No error occurred. If the OTA has not already been fully applied, + # No error occurred. If the RBU has not already been fully applied, # apply the rest of it now. Then ensure that the final state of the # target db is as expected. And that "PRAGMA integrity_check" # passes. - sqlite3ota ota test.db ota.db - while {[ota step] == "SQLITE_OK"} {} - ota close + sqlite3rbu rbu test.db rbu.db + while {[rbu step] == "SQLITE_OK"} {} + rbu close sqlite3 db test.db faultsim_integrity_check diff --git a/ext/ota/otafault2.test b/ext/rbu/rbufault2.test index 659cfec1f..ec89397fd 100644 --- a/ext/ota/otafault2.test +++ b/ext/rbu/rbufault2.test @@ -15,33 +15,33 @@ if {![info exists testdir]} { } source $testdir/tester.tcl source $testdir/malloc_common.tcl -set ::testprefix otafault2 +set ::testprefix rbufault2 -forcedelete ota.db +forcedelete rbu.db do_execsql_test 1.0 { CREATE TABLE target(x UNIQUE, y, z, PRIMARY KEY(y)); INSERT INTO target VALUES(1, 2, 3); INSERT INTO target VALUES(4, 5, 6); - ATTACH 'ota.db' AS ota; - CREATE TABLE ota.data_target(x, y, z, ota_control); + ATTACH 'rbu.db' AS rbu; + CREATE TABLE rbu.data_target(x, y, z, rbu_control); INSERT INTO data_target VALUES(7, 8, 9, 0); INSERT INTO data_target VALUES(1, 11, 12, 0); - DETACH ota; + DETACH rbu; } db close forcecopy test.db test.db-bak -forcecopy ota.db ota.db-bak +forcecopy rbu.db rbu.db-bak do_faultsim_test 1 -faults oom* -prep { forcecopy test.db-bak test.db - forcecopy ota.db-bak ota.db - forcedelete test.db-oal test.db-wal ota.db-journal - sqlite3ota ota test.db ota.db + forcecopy rbu.db-bak rbu.db + forcedelete test.db-oal test.db-wal rbu.db-journal + sqlite3rbu rbu test.db rbu.db } -body { - while {[ota step]=="SQLITE_OK"} { } - ota close + while {[rbu step]=="SQLITE_OK"} { } + rbu close } -test { faultsim_test_result \ {1 {SQLITE_CONSTRAINT - UNIQUE constraint failed: target.x}} \ diff --git a/ext/ota/sqlite3ota.c b/ext/rbu/sqlite3rbu.c index b53d12899..11090d082 100644 --- a/ext/ota/sqlite3ota.c +++ b/ext/rbu/sqlite3rbu.c @@ -13,11 +13,11 @@ ** ** OVERVIEW ** -** The OTA extension requires that the OTA update be packaged as an +** The RBU extension requires that the RBU update be packaged as an ** SQLite database. The tables it expects to find are described in -** sqlite3ota.h. Essentially, for each table xyz in the target database +** sqlite3rbu.h. Essentially, for each table xyz in the target database ** that the user wishes to write to, a corresponding data_xyz table is -** created in the OTA database and populated with one row for each row to +** created in the RBU database and populated with one row for each row to ** update, insert or delete from the target table. ** ** The update proceeds in three stages: @@ -29,7 +29,7 @@ ** "<database>-oal", they go on using the original database in ** rollback mode while the *-oal file is being generated. ** -** During this stage OTA does not update the database by writing +** During this stage RBU does not update the database by writing ** directly to the target tables. Instead it creates "imposter" ** tables using the SQLITE_TESTCTRL_IMPOSTER interface that it uses ** to update each b-tree individually. All updates required by each @@ -37,45 +37,45 @@ ** updates are done in sorted key order. ** ** 2) The "<database>-oal" file is moved to the equivalent "<database>-wal" -** location using a call to rename(2). Before doing this the OTA +** location using a call to rename(2). Before doing this the RBU ** module takes an EXCLUSIVE lock on the database file, ensuring ** that there are no other active readers. ** ** Once the EXCLUSIVE lock is released, any other database readers ** detect the new *-wal file and read the database in wal mode. At ** this point they see the new version of the database - including -** the updates made as part of the OTA update. +** the updates made as part of the RBU update. ** ** 3) The new *-wal file is checkpointed. This proceeds in the same way ** as a regular database checkpoint, except that a single frame is -** checkpointed each time sqlite3ota_step() is called. If the OTA +** checkpointed each time sqlite3rbu_step() is called. If the RBU ** handle is closed before the entire *-wal file is checkpointed, -** the checkpoint progress is saved in the OTA database and the -** checkpoint can be resumed by another OTA client at some point in +** the checkpoint progress is saved in the RBU database and the +** checkpoint can be resumed by another RBU client at some point in ** the future. ** ** POTENTIAL PROBLEMS ** -** The rename() call might not be portable. And OTA is not currently +** The rename() call might not be portable. And RBU is not currently ** syncing the directory after renaming the file. ** ** When state is saved, any commit to the *-oal file and the commit to -** the OTA update database are not atomic. So if the power fails at the +** the RBU update database are not atomic. So if the power fails at the ** wrong moment they might get out of sync. As the main database will be -** committed before the OTA update database this will likely either just +** committed before the RBU update database this will likely either just ** pass unnoticed, or result in SQLITE_CONSTRAINT errors (due to UNIQUE ** constraint violations). ** -** If some client does modify the target database mid OTA update, or some -** other error occurs, the OTA extension will keep throwing errors. It's +** If some client does modify the target database mid RBU update, or some +** other error occurs, the RBU extension will keep throwing errors. It's ** not really clear how to get out of this state. The system could just -** by delete the OTA update database and *-oal file and have the device +** by delete the RBU update database and *-oal file and have the device ** download the update again and start over. ** ** At present, for an UPDATE, both the new.* and old.* records are -** collected in the ota_xyz table. And for both UPDATEs and DELETEs all +** collected in the rbu_xyz table. And for both UPDATEs and DELETEs all ** fields are collected. This means we're probably writing a lot more -** data to disk when saving the state of an ongoing update to the OTA +** data to disk when saving the state of an ongoing update to the RBU ** update database than is strictly necessary. ** */ @@ -87,11 +87,11 @@ #include "sqlite3.h" -#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_OTA) -#include "sqlite3ota.h" +#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_RBU) +#include "sqlite3rbu.h" /* Maximum number of prepared UPDATE statements held by this module */ -#define SQLITE_OTA_UPDATE_CACHESIZE 16 +#define SQLITE_RBU_UPDATE_CACHESIZE 16 /* ** Swap two objects of type TYPE. @@ -101,74 +101,74 @@ #endif /* -** The ota_state table is used to save the state of a partially applied +** The rbu_state table is used to save the state of a partially applied ** update so that it can be resumed later. The table consists of integer ** keys mapped to values as follows: ** -** OTA_STATE_STAGE: +** RBU_STATE_STAGE: ** May be set to integer values 1, 2, 4 or 5. As follows: -** 1: the *-ota file is currently under construction. -** 2: the *-ota file has been constructed, but not yet moved +** 1: the *-rbu file is currently under construction. +** 2: the *-rbu file has been constructed, but not yet moved ** to the *-wal path. ** 4: the checkpoint is underway. -** 5: the ota update has been checkpointed. +** 5: the rbu update has been checkpointed. ** -** OTA_STATE_TBL: +** RBU_STATE_TBL: ** Only valid if STAGE==1. The target database name of the table ** currently being written. ** -** OTA_STATE_IDX: +** RBU_STATE_IDX: ** Only valid if STAGE==1. The target database name of the index ** currently being written, or NULL if the main table is currently being ** updated. ** -** OTA_STATE_ROW: +** RBU_STATE_ROW: ** Only valid if STAGE==1. Number of rows already processed for the current ** table/index. ** -** OTA_STATE_PROGRESS: -** Total number of sqlite3ota_step() calls made so far as part of this -** ota update. +** RBU_STATE_PROGRESS: +** Trbul number of sqlite3rbu_step() calls made so far as part of this +** rbu update. ** -** OTA_STATE_CKPT: +** RBU_STATE_CKPT: ** Valid if STAGE==4. The 64-bit checksum associated with the wal-index ** header created by recovering the *-wal file. This is used to detect ** cases when another client appends frames to the *-wal file in the ** middle of an incremental checkpoint (an incremental checkpoint cannot ** be continued if this happens). ** -** OTA_STATE_COOKIE: +** RBU_STATE_COOKIE: ** Valid if STAGE==1. The current change-counter cookie value in the ** target db file. ** -** OTA_STATE_OALSZ: +** RBU_STATE_OALSZ: ** Valid if STAGE==1. The size in bytes of the *-oal file. */ -#define OTA_STATE_STAGE 1 -#define OTA_STATE_TBL 2 -#define OTA_STATE_IDX 3 -#define OTA_STATE_ROW 4 -#define OTA_STATE_PROGRESS 5 -#define OTA_STATE_CKPT 6 -#define OTA_STATE_COOKIE 7 -#define OTA_STATE_OALSZ 8 +#define RBU_STATE_STAGE 1 +#define RBU_STATE_TBL 2 +#define RBU_STATE_IDX 3 +#define RBU_STATE_ROW 4 +#define RBU_STATE_PROGRESS 5 +#define RBU_STATE_CKPT 6 +#define RBU_STATE_COOKIE 7 +#define RBU_STATE_OALSZ 8 -#define OTA_STAGE_OAL 1 -#define OTA_STAGE_MOVE 2 -#define OTA_STAGE_CAPTURE 3 -#define OTA_STAGE_CKPT 4 -#define OTA_STAGE_DONE 5 +#define RBU_STAGE_OAL 1 +#define RBU_STAGE_MOVE 2 +#define RBU_STAGE_CAPTURE 3 +#define RBU_STAGE_CKPT 4 +#define RBU_STAGE_DONE 5 -#define OTA_CREATE_STATE \ - "CREATE TABLE IF NOT EXISTS %s.ota_state(k INTEGER PRIMARY KEY, v)" +#define RBU_CREATE_STATE \ + "CREATE TABLE IF NOT EXISTS %s.rbu_state(k INTEGER PRIMARY KEY, v)" -typedef struct OtaFrame OtaFrame; -typedef struct OtaObjIter OtaObjIter; -typedef struct OtaState OtaState; -typedef struct ota_vfs ota_vfs; -typedef struct ota_file ota_file; -typedef struct OtaUpdateStmt OtaUpdateStmt; +typedef struct RbuFrame RbuFrame; +typedef struct RbuObjIter RbuObjIter; +typedef struct RbuState RbuState; +typedef struct rbu_vfs rbu_vfs; +typedef struct rbu_file rbu_file; +typedef struct RbuUpdateStmt RbuUpdateStmt; #if !defined(SQLITE_AMALGAMATION) typedef unsigned int u32; @@ -186,9 +186,9 @@ typedef sqlite3_int64 i64; #define WAL_LOCK_READ0 3 /* -** A structure to store values read from the ota_state table in memory. +** A structure to store values read from the rbu_state table in memory. */ -struct OtaState { +struct RbuState { int eStage; char *zTbl; char *zIdx; @@ -199,10 +199,10 @@ struct OtaState { i64 iOalSz; }; -struct OtaUpdateStmt { +struct RbuUpdateStmt { char *zMask; /* Copy of update mask used with pUpdate */ sqlite3_stmt *pUpdate; /* Last update statement (or NULL) */ - OtaUpdateStmt *pNext; + RbuUpdateStmt *pNext; }; /* @@ -221,7 +221,7 @@ struct OtaUpdateStmt { ** index. Or clear otherwise. ** */ -struct OtaObjIter { +struct RbuObjIter { sqlite3_stmt *pTblIter; /* Iterate through tables */ sqlite3_stmt *pIdxIter; /* Index iterator */ int nTblCol; /* Size of azTblCol[] array */ @@ -231,7 +231,7 @@ struct OtaObjIter { u8 *abTblPk; /* Array of flags, set on target PK columns */ u8 *abNotNull; /* Array of flags, set on NOT NULL columns */ u8 *abIndexed; /* Array of flags, set on indexed & PK cols */ - int eType; /* Table type - an OTA_PK_XXX value */ + int eType; /* Table type - an RBU_PK_XXX value */ /* Output variables. zTbl==0 implies EOF. */ int bCleanup; /* True in "cleanup" state */ @@ -241,19 +241,19 @@ struct OtaObjIter { int iPkTnum; /* If eType==EXTERNAL, root of PK index */ int bUnique; /* Current index is unique */ - /* Statements created by otaObjIterPrepareAll() */ + /* Statements created by rbuObjIterPrepareAll() */ int nCol; /* Number of columns in current object */ sqlite3_stmt *pSelect; /* Source data */ sqlite3_stmt *pInsert; /* Statement for INSERT operations */ sqlite3_stmt *pDelete; /* Statement for DELETE ops */ - sqlite3_stmt *pTmpInsert; /* Insert into ota_tmp_$zTbl */ + sqlite3_stmt *pTmpInsert; /* Insert into rbu_tmp_$zTbl */ /* Last UPDATE used (for PK b-tree updates only), or NULL. */ - OtaUpdateStmt *pOtaUpdate; + RbuUpdateStmt *pRbuUpdate; }; /* -** Values for OtaObjIter.eType +** Values for RbuObjIter.eType ** ** 0: Table does not exist (error) ** 1: Table has an implicit rowid. @@ -262,86 +262,86 @@ struct OtaObjIter { ** 4: Table is WITHOUT ROWID. ** 5: Table is a virtual table. */ -#define OTA_PK_NOTABLE 0 -#define OTA_PK_NONE 1 -#define OTA_PK_IPK 2 -#define OTA_PK_EXTERNAL 3 -#define OTA_PK_WITHOUT_ROWID 4 -#define OTA_PK_VTAB 5 +#define RBU_PK_NOTABLE 0 +#define RBU_PK_NONE 1 +#define RBU_PK_IPK 2 +#define RBU_PK_EXTERNAL 3 +#define RBU_PK_WITHOUT_ROWID 4 +#define RBU_PK_VTAB 5 /* -** Within the OTA_STAGE_OAL stage, each call to sqlite3ota_step() performs +** Within the RBU_STAGE_OAL stage, each call to sqlite3rbu_step() performs ** one of the following operations. */ -#define OTA_INSERT 1 /* Insert on a main table b-tree */ -#define OTA_DELETE 2 /* Delete a row from a main table b-tree */ -#define OTA_IDX_DELETE 3 /* Delete a row from an aux. index b-tree */ -#define OTA_IDX_INSERT 4 /* Insert on an aux. index b-tree */ -#define OTA_UPDATE 5 /* Update a row in a main table b-tree */ +#define RBU_INSERT 1 /* Insert on a main table b-tree */ +#define RBU_DELETE 2 /* Delete a row from a main table b-tree */ +#define RBU_IDX_DELETE 3 /* Delete a row from an aux. index b-tree */ +#define RBU_IDX_INSERT 4 /* Insert on an aux. index b-tree */ +#define RBU_UPDATE 5 /* Update a row in a main table b-tree */ /* ** A single step of an incremental checkpoint - frame iWalFrame of the wal ** file should be copied to page iDbPage of the database file. */ -struct OtaFrame { +struct RbuFrame { u32 iDbPage; u32 iWalFrame; }; /* -** OTA handle. +** RBU handle. */ -struct sqlite3ota { - int eStage; /* Value of OTA_STATE_STAGE field */ +struct sqlite3rbu { + int eStage; /* Value of RBU_STATE_STAGE field */ sqlite3 *dbMain; /* target database handle */ - sqlite3 *dbOta; /* ota database handle */ + sqlite3 *dbRbu; /* rbu database handle */ char *zTarget; /* Path to target db */ - char *zOta; /* Path to ota db */ - char *zState; /* Path to state db (or NULL if zOta) */ + char *zRbu; /* Path to rbu db */ + char *zState; /* Path to state db (or NULL if zRbu) */ char zStateDb[5]; /* Db name for state ("stat" or "main") */ - int rc; /* Value returned by last ota_step() call */ + int rc; /* Value returned by last rbu_step() call */ char *zErrmsg; /* Error message if rc!=SQLITE_OK */ int nStep; /* Rows processed for current object */ int nProgress; /* Rows processed for all objects */ - OtaObjIter objiter; /* Iterator for skipping through tbl/idx */ - const char *zVfsName; /* Name of automatically created ota vfs */ - ota_file *pTargetFd; /* File handle open on target db */ + RbuObjIter objiter; /* Iterator for skipping through tbl/idx */ + const char *zVfsName; /* Name of automatically created rbu vfs */ + rbu_file *pTargetFd; /* File handle open on target db */ i64 iOalSz; /* The following state variables are used as part of the incremental - ** checkpoint stage (eStage==OTA_STAGE_CKPT). See comments surrounding - ** function otaSetupCheckpoint() for details. */ + ** checkpoint stage (eStage==RBU_STAGE_CKPT). See comments surrounding + ** function rbuSetupCheckpoint() for details. */ u32 iMaxFrame; /* Largest iWalFrame value in aFrame[] */ u32 mLock; int nFrame; /* Entries in aFrame[] array */ int nFrameAlloc; /* Allocated size of aFrame[] array */ - OtaFrame *aFrame; + RbuFrame *aFrame; int pgsz; u8 *aBuf; i64 iWalCksum; }; /* -** An ota VFS is implemented using an instance of this structure. +** An rbu VFS is implemented using an instance of this structure. */ -struct ota_vfs { - sqlite3_vfs base; /* ota VFS shim methods */ +struct rbu_vfs { + sqlite3_vfs base; /* rbu VFS shim methods */ sqlite3_vfs *pRealVfs; /* Underlying VFS */ sqlite3_mutex *mutex; /* Mutex to protect pMain */ - ota_file *pMain; /* Linked list of main db files */ + rbu_file *pMain; /* Linked list of main db files */ }; /* -** Each file opened by an ota VFS is represented by an instance of +** Each file opened by an rbu VFS is represented by an instance of ** the following structure. */ -struct ota_file { +struct rbu_file { sqlite3_file base; /* sqlite3_file methods */ sqlite3_file *pReal; /* Underlying file handle */ - ota_vfs *pOtaVfs; /* Pointer to the ota_vfs object */ - sqlite3ota *pOta; /* Pointer to ota object (ota target only) */ + rbu_vfs *pRbuVfs; /* Pointer to the rbu_vfs object */ + sqlite3rbu *pRbu; /* Pointer to rbu object (rbu target only) */ int openFlags; /* Flags this file was opened with */ u32 iCookie; /* Cookie value for main db files */ @@ -352,8 +352,8 @@ struct ota_file { char *zDel; /* Delete this when closing file */ const char *zWal; /* Wal filename for this main db file */ - ota_file *pWalFd; /* Wal file descriptor for this main db */ - ota_file *pMainNext; /* Next MAIN_DB file */ + rbu_file *pWalFd; /* Wal file descriptor for this main db */ + rbu_file *pMainNext; /* Next MAIN_DB file */ }; @@ -431,10 +431,10 @@ static int prepareFreeAndCollectError( } /* -** Free the OtaObjIter.azTblCol[] and OtaObjIter.abTblPk[] arrays allocated -** by an earlier call to otaObjIterCacheTableInfo(). +** Free the RbuObjIter.azTblCol[] and RbuObjIter.abTblPk[] arrays allocated +** by an earlier call to rbuObjIterCacheTableInfo(). */ -static void otaObjIterFreeCols(OtaObjIter *pIter){ +static void rbuObjIterFreeCols(RbuObjIter *pIter){ int i; for(i=0; i<pIter->nTblCol; i++){ sqlite3_free(pIter->azTblCol[i]); @@ -454,16 +454,16 @@ static void otaObjIterFreeCols(OtaObjIter *pIter){ ** Finalize all statements and free all allocations that are specific to ** the current object (table/index pair). */ -static void otaObjIterClearStatements(OtaObjIter *pIter){ - OtaUpdateStmt *pUp; +static void rbuObjIterClearStatements(RbuObjIter *pIter){ + RbuUpdateStmt *pUp; sqlite3_finalize(pIter->pSelect); sqlite3_finalize(pIter->pInsert); sqlite3_finalize(pIter->pDelete); sqlite3_finalize(pIter->pTmpInsert); - pUp = pIter->pOtaUpdate; + pUp = pIter->pRbuUpdate; while( pUp ){ - OtaUpdateStmt *pTmp = pUp->pNext; + RbuUpdateStmt *pTmp = pUp->pNext; sqlite3_finalize(pUp->pUpdate); sqlite3_free(pUp); pUp = pTmp; @@ -472,7 +472,7 @@ static void otaObjIterClearStatements(OtaObjIter *pIter){ pIter->pSelect = 0; pIter->pInsert = 0; pIter->pDelete = 0; - pIter->pOtaUpdate = 0; + pIter->pRbuUpdate = 0; pIter->pTmpInsert = 0; pIter->nCol = 0; } @@ -481,12 +481,12 @@ static void otaObjIterClearStatements(OtaObjIter *pIter){ ** Clean up any resources allocated as part of the iterator object passed ** as the only argument. */ -static void otaObjIterFinalize(OtaObjIter *pIter){ - otaObjIterClearStatements(pIter); +static void rbuObjIterFinalize(RbuObjIter *pIter){ + rbuObjIterClearStatements(pIter); sqlite3_finalize(pIter->pTblIter); sqlite3_finalize(pIter->pIdxIter); - otaObjIterFreeCols(pIter); - memset(pIter, 0, sizeof(OtaObjIter)); + rbuObjIterFreeCols(pIter); + memset(pIter, 0, sizeof(RbuObjIter)); } /* @@ -494,28 +494,28 @@ static void otaObjIterFinalize(OtaObjIter *pIter){ ** ** If no error occurs, SQLITE_OK is returned and the iterator is left ** pointing to the next entry. Otherwise, an error code and message is -** left in the OTA handle passed as the first argument. A copy of the +** left in the RBU handle passed as the first argument. A copy of the ** error code is returned. */ -static int otaObjIterNext(sqlite3ota *p, OtaObjIter *pIter){ +static int rbuObjIterNext(sqlite3rbu *p, RbuObjIter *pIter){ int rc = p->rc; if( rc==SQLITE_OK ){ /* Free any SQLite statements used while processing the previous object */ - otaObjIterClearStatements(pIter); + rbuObjIterClearStatements(pIter); if( pIter->zIdx==0 ){ rc = sqlite3_exec(p->dbMain, - "DROP TRIGGER IF EXISTS temp.ota_insert_tr;" - "DROP TRIGGER IF EXISTS temp.ota_update1_tr;" - "DROP TRIGGER IF EXISTS temp.ota_update2_tr;" - "DROP TRIGGER IF EXISTS temp.ota_delete_tr;" + "DROP TRIGGER IF EXISTS temp.rbu_insert_tr;" + "DROP TRIGGER IF EXISTS temp.rbu_update1_tr;" + "DROP TRIGGER IF EXISTS temp.rbu_update2_tr;" + "DROP TRIGGER IF EXISTS temp.rbu_delete_tr;" , 0, 0, &p->zErrmsg ); } if( rc==SQLITE_OK ){ if( pIter->bCleanup ){ - otaObjIterFreeCols(pIter); + rbuObjIterFreeCols(pIter); pIter->bCleanup = 0; rc = sqlite3_step(pIter->pTblIter); if( rc!=SQLITE_ROW ){ @@ -548,7 +548,7 @@ static int otaObjIterNext(sqlite3ota *p, OtaObjIter *pIter){ } if( rc!=SQLITE_OK ){ - otaObjIterFinalize(pIter); + rbuObjIterFinalize(pIter); p->rc = rc; } return rc; @@ -559,14 +559,14 @@ static int otaObjIterNext(sqlite3ota *p, OtaObjIter *pIter){ ** ** If no error occurs, SQLITE_OK is returned and the iterator is left ** pointing to the first entry. Otherwise, an error code and message is -** left in the OTA handle passed as the first argument. A copy of the +** left in the RBU handle passed as the first argument. A copy of the ** error code is returned. */ -static int otaObjIterFirst(sqlite3ota *p, OtaObjIter *pIter){ +static int rbuObjIterFirst(sqlite3rbu *p, RbuObjIter *pIter){ int rc; - memset(pIter, 0, sizeof(OtaObjIter)); + memset(pIter, 0, sizeof(RbuObjIter)); - rc = prepareAndCollectError(p->dbOta, &pIter->pTblIter, &p->zErrmsg, + rc = prepareAndCollectError(p->dbRbu, &pIter->pTblIter, &p->zErrmsg, "SELECT substr(name, 6) FROM sqlite_master " "WHERE type='table' AND name LIKE 'data_%'" ); @@ -581,19 +581,19 @@ static int otaObjIterFirst(sqlite3ota *p, OtaObjIter *pIter){ pIter->bCleanup = 1; p->rc = rc; - return otaObjIterNext(p, pIter); + return rbuObjIterNext(p, pIter); } /* ** This is a wrapper around "sqlite3_mprintf(zFmt, ...)". If an OOM occurs, -** an error code is stored in the OTA handle passed as the first argument. +** an error code is stored in the RBU handle passed as the first argument. ** ** If an error has already occurred (p->rc is already set to something other ** than SQLITE_OK), then this function returns NULL without modifying the ** stored error code. In this case it still calls sqlite3_free() on any ** printf() parameters associated with %z conversions. */ -static char *otaMPrintf(sqlite3ota *p, const char *zFmt, ...){ +static char *rbuMPrintf(sqlite3rbu *p, const char *zFmt, ...){ char *zSql = 0; va_list ap; va_start(ap, zFmt); @@ -612,13 +612,13 @@ static char *otaMPrintf(sqlite3ota *p, const char *zFmt, ...){ ** Argument zFmt is a sqlite3_mprintf() style format string. The trailing ** arguments are the usual subsitution values. This function performs ** the printf() style substitutions and executes the result as an SQL -** statement on the OTA handles database. +** statement on the RBU handles database. ** ** If an error occurs, an error code and error message is stored in the -** OTA handle. If an error has already occurred when this function is +** RBU handle. If an error has already occurred when this function is ** called, it is a no-op. */ -static int otaMPrintfExec(sqlite3ota *p, sqlite3 *db, const char *zFmt, ...){ +static int rbuMPrintfExec(sqlite3rbu *p, sqlite3 *db, const char *zFmt, ...){ va_list ap; va_start(ap, zFmt); char *zSql = sqlite3_vmprintf(zFmt, ap); @@ -639,12 +639,12 @@ static int otaMPrintfExec(sqlite3ota *p, sqlite3 *db, const char *zFmt, ...){ ** bytes. ** ** If an error (i.e. an OOM condition) occurs, return NULL and leave an -** error code in the ota handle passed as the first argument. Or, if an +** error code in the rbu handle passed as the first argument. Or, if an ** error has already occurred when this function is called, return NULL ** immediately without attempting the allocation or modifying the stored ** error code. */ -static void *otaMalloc(sqlite3ota *p, int nByte){ +static void *rbuMalloc(sqlite3rbu *p, int nByte){ void *pRet = 0; if( p->rc==SQLITE_OK ){ assert( nByte>0 ); @@ -662,13 +662,13 @@ static void *otaMalloc(sqlite3ota *p, int nByte){ /* ** Allocate and zero the pIter->azTblCol[] and abTblPk[] arrays so that ** there is room for at least nCol elements. If an OOM occurs, store an -** error code in the OTA handle passed as the first argument. +** error code in the RBU handle passed as the first argument. */ -static void otaAllocateIterArrays(sqlite3ota *p, OtaObjIter *pIter, int nCol){ +static void rbuAllocateIterArrays(sqlite3rbu *p, RbuObjIter *pIter, int nCol){ int nByte = (2*sizeof(char*) + sizeof(int) + 3*sizeof(u8)) * nCol; char **azNew; - azNew = (char**)otaMalloc(p, nByte); + azNew = (char**)rbuMalloc(p, nByte); if( azNew ){ pIter->azTblCol = azNew; pIter->azTblType = &azNew[nCol]; @@ -689,7 +689,7 @@ static void otaAllocateIterArrays(sqlite3ota *p, OtaObjIter *pIter, int nCol){ ** output variable (*pRc) is set to SQLITE_NOMEM before returning. Otherwise, ** if the allocation succeeds, (*pRc) is left unchanged. */ -static char *otaStrndup(const char *zStr, int *pRc){ +static char *rbuStrndup(const char *zStr, int *pRc){ char *zRet = 0; assert( *pRc==SQLITE_OK ); @@ -710,10 +710,10 @@ static char *otaStrndup(const char *zStr, int *pRc){ ** Finalize the statement passed as the second argument. ** ** If the sqlite3_finalize() call indicates that an error occurs, and the -** ota handle error code is not already set, set the error code and error +** rbu handle error code is not already set, set the error code and error ** message accordingly. */ -static void otaFinalize(sqlite3ota *p, sqlite3_stmt *pStmt){ +static void rbuFinalize(sqlite3rbu *p, sqlite3_stmt *pStmt){ sqlite3 *db = sqlite3_db_handle(pStmt); int rc = sqlite3_finalize(pStmt); if( p->rc==SQLITE_OK && rc!=SQLITE_OK ){ @@ -728,12 +728,12 @@ static void otaFinalize(sqlite3ota *p, sqlite3_stmt *pStmt){ ** (int). This call sets the output parameter as follows, depending ** on the type of the table specified by parameters dbName and zTbl. ** -** OTA_PK_NOTABLE: No such table. -** OTA_PK_NONE: Table has an implicit rowid. -** OTA_PK_IPK: Table has an explicit IPK column. -** OTA_PK_EXTERNAL: Table has an external PK index. -** OTA_PK_WITHOUT_ROWID: Table is WITHOUT ROWID. -** OTA_PK_VTAB: Table is a virtual table. +** RBU_PK_NOTABLE: No such table. +** RBU_PK_NONE: Table has an implicit rowid. +** RBU_PK_IPK: Table has an explicit IPK column. +** RBU_PK_EXTERNAL: Table has an external PK index. +** RBU_PK_WITHOUT_ROWID: Table is WITHOUT ROWID. +** RBU_PK_VTAB: Table is a virtual table. ** ** Argument *piPk is also of type (int*), and also points to an output ** parameter. Unless the table has an external primary key index @@ -745,24 +745,24 @@ static void otaFinalize(sqlite3ota *p, sqlite3_stmt *pStmt){ ** ALGORITHM: ** ** if( no entry exists in sqlite_master ){ -** return OTA_PK_NOTABLE +** return RBU_PK_NOTABLE ** }else if( sql for the entry starts with "CREATE VIRTUAL" ){ -** return OTA_PK_VTAB +** return RBU_PK_VTAB ** }else if( "PRAGMA index_list()" for the table contains a "pk" index ){ ** if( the index that is the pk exists in sqlite_master ){ ** *piPK = rootpage of that index. -** return OTA_PK_EXTERNAL +** return RBU_PK_EXTERNAL ** }else{ -** return OTA_PK_WITHOUT_ROWID +** return RBU_PK_WITHOUT_ROWID ** } ** }else if( "PRAGMA table_info()" lists one or more "pk" columns ){ -** return OTA_PK_IPK +** return RBU_PK_IPK ** }else{ -** return OTA_PK_NONE +** return RBU_PK_NONE ** } */ -static void otaTableType( - sqlite3ota *p, +static void rbuTableType( + sqlite3rbu *p, const char *zTab, int *peType, int *piTnum, @@ -776,7 +776,7 @@ static void otaTableType( */ sqlite3_stmt *aStmt[4] = {0, 0, 0, 0}; - *peType = OTA_PK_NOTABLE; + *peType = RBU_PK_NOTABLE; *piPk = 0; assert( p->rc==SQLITE_OK ); @@ -788,18 +788,18 @@ static void otaTableType( )); if( p->rc!=SQLITE_OK || sqlite3_step(aStmt[0])!=SQLITE_ROW ){ /* Either an error, or no such table. */ - goto otaTableType_end; + goto rbuTableType_end; } if( sqlite3_column_int(aStmt[0], 0) ){ - *peType = OTA_PK_VTAB; /* virtual table */ - goto otaTableType_end; + *peType = RBU_PK_VTAB; /* virtual table */ + goto rbuTableType_end; } *piTnum = sqlite3_column_int(aStmt[0], 1); p->rc = prepareFreeAndCollectError(p->dbMain, &aStmt[1], &p->zErrmsg, sqlite3_mprintf("PRAGMA index_list=%Q",zTab) ); - if( p->rc ) goto otaTableType_end; + if( p->rc ) goto rbuTableType_end; while( sqlite3_step(aStmt[1])==SQLITE_ROW ){ const u8 *zOrig = sqlite3_column_text(aStmt[1], 3); const u8 *zIdx = sqlite3_column_text(aStmt[1], 1); @@ -811,12 +811,12 @@ static void otaTableType( if( p->rc==SQLITE_OK ){ if( sqlite3_step(aStmt[2])==SQLITE_ROW ){ *piPk = sqlite3_column_int(aStmt[2], 0); - *peType = OTA_PK_EXTERNAL; + *peType = RBU_PK_EXTERNAL; }else{ - *peType = OTA_PK_WITHOUT_ROWID; + *peType = RBU_PK_WITHOUT_ROWID; } } - goto otaTableType_end; + goto rbuTableType_end; } } @@ -826,26 +826,26 @@ static void otaTableType( if( p->rc==SQLITE_OK ){ while( sqlite3_step(aStmt[3])==SQLITE_ROW ){ if( sqlite3_column_int(aStmt[3],5)>0 ){ - *peType = OTA_PK_IPK; /* explicit IPK column */ - goto otaTableType_end; + *peType = RBU_PK_IPK; /* explicit IPK column */ + goto rbuTableType_end; } } - *peType = OTA_PK_NONE; + *peType = RBU_PK_NONE; } -otaTableType_end: { +rbuTableType_end: { int i; for(i=0; i<sizeof(aStmt)/sizeof(aStmt[0]); i++){ - otaFinalize(p, aStmt[i]); + rbuFinalize(p, aStmt[i]); } } } /* -** This is a helper function for otaObjIterCacheTableInfo(). It populates +** This is a helper function for rbuObjIterCacheTableInfo(). It populates ** the pIter->abIndexed[] array. */ -static void otaObjIterCacheIndexedCols(sqlite3ota *p, OtaObjIter *pIter){ +static void rbuObjIterCacheIndexedCols(sqlite3rbu *p, RbuObjIter *pIter){ sqlite3_stmt *pList = 0; int bIndex = 0; @@ -867,11 +867,11 @@ static void otaObjIterCacheIndexedCols(sqlite3ota *p, OtaObjIter *pIter){ int iCid = sqlite3_column_int(pXInfo, 1); if( iCid>=0 ) pIter->abIndexed[iCid] = 1; } - otaFinalize(p, pXInfo); + rbuFinalize(p, pXInfo); bIndex = 1; } - otaFinalize(p, pList); + rbuFinalize(p, pList); if( bIndex==0 ) pIter->abIndexed = 0; } @@ -883,63 +883,63 @@ static void otaObjIterCacheIndexedCols(sqlite3ota *p, OtaObjIter *pIter){ ** ** Return SQLITE_OK if successful, or an SQLite error code otherwise. If ** an error does occur, an error code and error message are also left in -** the OTA handle. +** the RBU handle. */ -static int otaObjIterCacheTableInfo(sqlite3ota *p, OtaObjIter *pIter){ +static int rbuObjIterCacheTableInfo(sqlite3rbu *p, RbuObjIter *pIter){ if( pIter->azTblCol==0 ){ sqlite3_stmt *pStmt = 0; int nCol = 0; int i; /* for() loop iterator variable */ - int bOtaRowid = 0; /* If input table has column "ota_rowid" */ + int bRbuRowid = 0; /* If input table has column "rbu_rowid" */ int iOrder = 0; int iTnum = 0; /* Figure out the type of table this step will deal with. */ assert( pIter->eType==0 ); - otaTableType(p, pIter->zTbl, &pIter->eType, &iTnum, &pIter->iPkTnum); - if( p->rc==SQLITE_OK && pIter->eType==OTA_PK_NOTABLE ){ + rbuTableType(p, pIter->zTbl, &pIter->eType, &iTnum, &pIter->iPkTnum); + if( p->rc==SQLITE_OK && pIter->eType==RBU_PK_NOTABLE ){ p->rc = SQLITE_ERROR; p->zErrmsg = sqlite3_mprintf("no such table: %s", pIter->zTbl); } if( p->rc ) return p->rc; if( pIter->zIdx==0 ) pIter->iTnum = iTnum; - assert( pIter->eType==OTA_PK_NONE || pIter->eType==OTA_PK_IPK - || pIter->eType==OTA_PK_EXTERNAL || pIter->eType==OTA_PK_WITHOUT_ROWID - || pIter->eType==OTA_PK_VTAB + assert( pIter->eType==RBU_PK_NONE || pIter->eType==RBU_PK_IPK + || pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_WITHOUT_ROWID + || pIter->eType==RBU_PK_VTAB ); /* Populate the azTblCol[] and nTblCol variables based on the columns ** of the input table. Ignore any input table columns that begin with - ** "ota_". */ - p->rc = prepareFreeAndCollectError(p->dbOta, &pStmt, &p->zErrmsg, + ** "rbu_". */ + p->rc = prepareFreeAndCollectError(p->dbRbu, &pStmt, &p->zErrmsg, sqlite3_mprintf("SELECT * FROM 'data_%q'", pIter->zTbl) ); if( p->rc==SQLITE_OK ){ nCol = sqlite3_column_count(pStmt); - otaAllocateIterArrays(p, pIter, nCol); + rbuAllocateIterArrays(p, pIter, nCol); } for(i=0; p->rc==SQLITE_OK && i<nCol; i++){ const char *zName = (const char*)sqlite3_column_name(pStmt, i); - if( sqlite3_strnicmp("ota_", zName, 4) ){ - char *zCopy = otaStrndup(zName, &p->rc); + if( sqlite3_strnicmp("rbu_", zName, 4) ){ + char *zCopy = rbuStrndup(zName, &p->rc); pIter->aiSrcOrder[pIter->nTblCol] = pIter->nTblCol; pIter->azTblCol[pIter->nTblCol++] = zCopy; } - else if( 0==sqlite3_stricmp("ota_rowid", zName) ){ - bOtaRowid = 1; + else if( 0==sqlite3_stricmp("rbu_rowid", zName) ){ + bRbuRowid = 1; } } sqlite3_finalize(pStmt); pStmt = 0; if( p->rc==SQLITE_OK - && bOtaRowid!=(pIter->eType==OTA_PK_VTAB || pIter->eType==OTA_PK_NONE) + && bRbuRowid!=(pIter->eType==RBU_PK_VTAB || pIter->eType==RBU_PK_NONE) ){ p->rc = SQLITE_ERROR; p->zErrmsg = sqlite3_mprintf( - "table data_%q %s ota_rowid column", pIter->zTbl, - (bOtaRowid ? "may not have" : "requires") + "table data_%q %s rbu_rowid column", pIter->zTbl, + (bRbuRowid ? "may not have" : "requires") ); } @@ -972,16 +972,16 @@ static int otaObjIterCacheTableInfo(sqlite3ota *p, OtaObjIter *pIter){ SWAP(char*, pIter->azTblCol[i], pIter->azTblCol[iOrder]); } - pIter->azTblType[iOrder] = otaStrndup(zType, &p->rc); + pIter->azTblType[iOrder] = rbuStrndup(zType, &p->rc); pIter->abTblPk[iOrder] = (iPk!=0); pIter->abNotNull[iOrder] = (u8)bNotNull || (iPk!=0); iOrder++; } } - otaFinalize(p, pStmt); - otaObjIterCacheIndexedCols(p, pIter); - assert( pIter->eType!=OTA_PK_VTAB || pIter->abIndexed==0 ); + rbuFinalize(p, pStmt); + rbuObjIterCacheIndexedCols(p, pIter); + assert( pIter->eType!=RBU_PK_VTAB || pIter->abIndexed==0 ); } return p->rc; @@ -992,16 +992,16 @@ static int otaObjIterCacheTableInfo(sqlite3ota *p, OtaObjIter *pIter){ ** string containing some SQL clause or list based on one or more of the ** column names currently stored in the pIter->azTblCol[] array. */ -static char *otaObjIterGetCollist( - sqlite3ota *p, /* OTA object */ - OtaObjIter *pIter /* Object iterator for column names */ +static char *rbuObjIterGetCollist( + sqlite3rbu *p, /* RBU object */ + RbuObjIter *pIter /* Object iterator for column names */ ){ char *zList = 0; const char *zSep = ""; int i; for(i=0; i<pIter->nTblCol; i++){ const char *z = pIter->azTblCol[i]; - zList = otaMPrintf(p, "%z%s\"%w\"", zList, zSep, z); + zList = rbuMPrintf(p, "%z%s\"%w\"", zList, zSep, z); zSep = ", "; } return zList; @@ -1010,7 +1010,7 @@ static char *otaObjIterGetCollist( /* ** This function is used to create a SELECT list (the list of SQL ** expressions that follows a SELECT keyword) for a SELECT statement -** used to read from an data_xxx or ota_tmp_xxx table while updating the +** used to read from an data_xxx or rbu_tmp_xxx table while updating the ** index object currently indicated by the iterator object passed as the ** second argument. A "PRAGMA index_xinfo = <idxname>" statement is used ** to obtain the required information. @@ -1031,13 +1031,13 @@ static char *otaObjIterGetCollist( ** pzImposterPk: ... ** pzWhere: ... */ -static char *otaObjIterGetIndexCols( - sqlite3ota *p, /* OTA object */ - OtaObjIter *pIter, /* Object iterator for column names */ +static char *rbuObjIterGetIndexCols( + sqlite3rbu *p, /* RBU object */ + RbuObjIter *pIter, /* Object iterator for column names */ char **pzImposterCols, /* OUT: Columns for imposter table */ char **pzImposterPk, /* OUT: Imposter PK clause */ char **pzWhere, /* OUT: WHERE clause */ - int *pnBind /* OUT: Total number of columns */ + int *pnBind /* OUT: Trbul number of columns */ ){ int rc = p->rc; /* Error code */ int rc2; /* sqlite3_finalize() return code */ @@ -1066,14 +1066,14 @@ static char *otaObjIterGetIndexCols( if( iCid<0 ){ /* An integer primary key. If the table has an explicit IPK, use - ** its name. Otherwise, use "ota_rowid". */ - if( pIter->eType==OTA_PK_IPK ){ + ** its name. Otherwise, use "rbu_rowid". */ + if( pIter->eType==RBU_PK_IPK ){ int i; for(i=0; pIter->abTblPk[i]==0; i++); assert( i<pIter->nTblCol ); zCol = pIter->azTblCol[i]; }else{ - zCol = "ota_rowid"; + zCol = "rbu_rowid"; } zType = "INTEGER"; }else{ @@ -1084,15 +1084,15 @@ static char *otaObjIterGetIndexCols( zRet = sqlite3_mprintf("%z%s\"%w\" COLLATE %Q", zRet, zCom, zCol, zCollate); if( pIter->bUnique==0 || sqlite3_column_int(pXInfo, 5) ){ const char *zOrder = (bDesc ? " DESC" : ""); - zImpPK = sqlite3_mprintf("%z%s\"ota_imp_%d%w\"%s", + zImpPK = sqlite3_mprintf("%z%s\"rbu_imp_%d%w\"%s", zImpPK, zCom, nBind, zCol, zOrder ); } - zImpCols = sqlite3_mprintf("%z%s\"ota_imp_%d%w\" %s COLLATE %Q", + zImpCols = sqlite3_mprintf("%z%s\"rbu_imp_%d%w\" %s COLLATE %Q", zImpCols, zCom, nBind, zCol, zType, zCollate ); zWhere = sqlite3_mprintf( - "%z%s\"ota_imp_%d%w\" IS ?", zWhere, zAnd, nBind, zCol + "%z%s\"rbu_imp_%d%w\" IS ?", zWhere, zAnd, nBind, zCol ); if( zRet==0 || zImpPK==0 || zImpCols==0 || zWhere==0 ) rc = SQLITE_NOMEM; zCom = ", "; @@ -1130,12 +1130,12 @@ static char *otaObjIterGetIndexCols( ** ** With the column names escaped. ** -** For tables with implicit rowids - OTA_PK_EXTERNAL and OTA_PK_NONE, append +** For tables with implicit rowids - RBU_PK_EXTERNAL and RBU_PK_NONE, append ** the text ", old._rowid_" to the returned value. */ -static char *otaObjIterGetOldlist( - sqlite3ota *p, - OtaObjIter *pIter, +static char *rbuObjIterGetOldlist( + sqlite3rbu *p, + RbuObjIter *pIter, const char *zObj ){ char *zList = 0; @@ -1157,8 +1157,8 @@ static char *otaObjIterGetOldlist( } /* For a table with implicit rowids, append "old._rowid_" to the list. */ - if( pIter->eType==OTA_PK_EXTERNAL || pIter->eType==OTA_PK_NONE ){ - zList = otaMPrintf(p, "%z, %s._rowid_", zList, zObj); + if( pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE ){ + zList = rbuMPrintf(p, "%z, %s._rowid_", zList, zObj); } } return zList; @@ -1174,24 +1174,24 @@ static char *otaObjIterGetOldlist( ** ** "b = ?1 AND c = ?2" */ -static char *otaObjIterGetWhere( - sqlite3ota *p, - OtaObjIter *pIter +static char *rbuObjIterGetWhere( + sqlite3rbu *p, + RbuObjIter *pIter ){ char *zList = 0; - if( pIter->eType==OTA_PK_VTAB || pIter->eType==OTA_PK_NONE ){ - zList = otaMPrintf(p, "_rowid_ = ?%d", pIter->nTblCol+1); - }else if( pIter->eType==OTA_PK_EXTERNAL ){ + if( pIter->eType==RBU_PK_VTAB || pIter->eType==RBU_PK_NONE ){ + zList = rbuMPrintf(p, "_rowid_ = ?%d", pIter->nTblCol+1); + }else if( pIter->eType==RBU_PK_EXTERNAL ){ const char *zSep = ""; int i; for(i=0; i<pIter->nTblCol; i++){ if( pIter->abTblPk[i] ){ - zList = otaMPrintf(p, "%z%sc%d=?%d", zList, zSep, i, i+1); + zList = rbuMPrintf(p, "%z%sc%d=?%d", zList, zSep, i, i+1); zSep = " AND "; } } - zList = otaMPrintf(p, - "_rowid_ = (SELECT id FROM ota_imposter2 WHERE %z)", zList + zList = rbuMPrintf(p, + "_rowid_ = (SELECT id FROM rbu_imposter2 WHERE %z)", zList ); }else{ @@ -1200,7 +1200,7 @@ static char *otaObjIterGetWhere( for(i=0; i<pIter->nTblCol; i++){ if( pIter->abTblPk[i] ){ const char *zCol = pIter->azTblCol[i]; - zList = otaMPrintf(p, "%z%s\"%w\"=?%d", zList, zSep, zCol, i+1); + zList = rbuMPrintf(p, "%z%s\"%w\"=?%d", zList, zSep, zCol, i+1); zSep = " AND "; } } @@ -1211,13 +1211,13 @@ static char *otaObjIterGetWhere( /* ** The SELECT statement iterating through the keys for the current object ** (p->objiter.pSelect) currently points to a valid row. However, there -** is something wrong with the ota_control value in the ota_control value +** is something wrong with the rbu_control value in the rbu_control value ** stored in the (p->nCol+1)'th column. Set the error code and error message -** of the OTA handle to something reflecting this. +** of the RBU handle to something reflecting this. */ -static void otaBadControlError(sqlite3ota *p){ +static void rbuBadControlError(sqlite3rbu *p){ p->rc = SQLITE_ERROR; - p->zErrmsg = sqlite3_mprintf("invalid ota_control value"); + p->zErrmsg = sqlite3_mprintf("invalid rbu_control value"); } @@ -1225,7 +1225,7 @@ static void otaBadControlError(sqlite3ota *p){ ** Return a nul-terminated string containing the comma separated list of ** assignments that should be included following the "SET" keyword of ** an UPDATE statement used to update the table object that the iterator -** passed as the second argument currently points to if the ota_control +** passed as the second argument currently points to if the rbu_control ** column of the data_xxx table entry is set to zMask. ** ** The memory for the returned string is obtained from sqlite3_malloc(). @@ -1233,14 +1233,14 @@ static void otaBadControlError(sqlite3ota *p){ ** sqlite3_free(). ** ** If an OOM error is encountered when allocating space for the new -** string, an error code is left in the ota handle passed as the first +** string, an error code is left in the rbu handle passed as the first ** argument and NULL is returned. Or, if an error has already occurred ** when this function is called, NULL is returned immediately, without ** attempting the allocation or modifying the stored error code. */ -static char *otaObjIterGetSetlist( - sqlite3ota *p, - OtaObjIter *pIter, +static char *rbuObjIterGetSetlist( + sqlite3rbu *p, + RbuObjIter *pIter, const char *zMask ){ char *zList = 0; @@ -1248,19 +1248,19 @@ static char *otaObjIterGetSetlist( int i; if( strlen(zMask)!=pIter->nTblCol ){ - otaBadControlError(p); + rbuBadControlError(p); }else{ const char *zSep = ""; for(i=0; i<pIter->nTblCol; i++){ char c = zMask[pIter->aiSrcOrder[i]]; if( c=='x' ){ - zList = otaMPrintf(p, "%z%s\"%w\"=?%d", + zList = rbuMPrintf(p, "%z%s\"%w\"=?%d", zList, zSep, pIter->azTblCol[i], i+1 ); zSep = ", "; } if( c=='d' ){ - zList = otaMPrintf(p, "%z%s\"%w\"=ota_delta(\"%w\", ?%d)", + zList = rbuMPrintf(p, "%z%s\"%w\"=rbu_delta(\"%w\", ?%d)", zList, zSep, pIter->azTblCol[i], pIter->azTblCol[i], i+1 ); zSep = ", "; @@ -1281,16 +1281,16 @@ static char *otaObjIterGetSetlist( ** sqlite3_free(). ** ** If an OOM error is encountered when allocating space for the new -** string, an error code is left in the ota handle passed as the first +** string, an error code is left in the rbu handle passed as the first ** argument and NULL is returned. Or, if an error has already occurred ** when this function is called, NULL is returned immediately, without ** attempting the allocation or modifying the stored error code. */ -static char *otaObjIterGetBindlist(sqlite3ota *p, int nBind){ +static char *rbuObjIterGetBindlist(sqlite3rbu *p, int nBind){ char *zRet = 0; int nByte = nBind*2 + 1; - zRet = (char*)otaMalloc(p, nByte); + zRet = (char*)rbuMalloc(p, nByte); if( zRet ){ int i; for(i=0; i<nBind; i++){ @@ -1303,7 +1303,7 @@ static char *otaObjIterGetBindlist(sqlite3ota *p, int nBind){ /* ** The iterator currently points to a table (not index) of type -** OTA_PK_WITHOUT_ROWID. This function creates the PRIMARY KEY +** RBU_PK_WITHOUT_ROWID. This function creates the PRIMARY KEY ** declaration for the corresponding imposter table. For example, ** if the iterator points to a table created as: ** @@ -1313,7 +1313,7 @@ static char *otaObjIterGetBindlist(sqlite3ota *p, int nBind){ ** ** PRIMARY KEY("b", "a" DESC) */ -static char *otaWithoutRowidPK(sqlite3ota *p, OtaObjIter *pIter){ +static char *rbuWithoutRowidPK(sqlite3rbu *p, RbuObjIter *pIter){ char *z = 0; assert( pIter->zIdx==0 ); if( p->rc==SQLITE_OK ){ @@ -1336,19 +1336,19 @@ static char *otaWithoutRowidPK(sqlite3ota *p, OtaObjIter *pIter){ break; } } - otaFinalize(p, pXList); + rbuFinalize(p, pXList); while( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pXInfo) ){ if( sqlite3_column_int(pXInfo, 5) ){ /* int iCid = sqlite3_column_int(pXInfo, 0); */ const char *zCol = (const char*)sqlite3_column_text(pXInfo, 2); const char *zDesc = sqlite3_column_int(pXInfo, 3) ? " DESC" : ""; - z = otaMPrintf(p, "%z%s\"%w\"%s", z, zSep, zCol, zDesc); + z = rbuMPrintf(p, "%z%s\"%w\"%s", z, zSep, zCol, zDesc); zSep = ", "; } } - z = otaMPrintf(p, "%z)", z); - otaFinalize(p, pXInfo); + z = rbuMPrintf(p, "%z)", z); + rbuFinalize(p, pXInfo); } return z; } @@ -1361,7 +1361,7 @@ static char *otaWithoutRowidPK(sqlite3ota *p, OtaObjIter *pIter){ ** no-op. ** ** Assuming the iterator does point to a table with an external PK, this -** function creates a WITHOUT ROWID imposter table named "ota_imposter2" +** function creates a WITHOUT ROWID imposter table named "rbu_imposter2" ** used to access that PK index. For example, if the target table is ** declared as follows: ** @@ -1369,11 +1369,11 @@ static char *otaWithoutRowidPK(sqlite3ota *p, OtaObjIter *pIter){ ** ** then the imposter table schema is: ** -** CREATE TABLE ota_imposter2(c1 TEXT, c2 REAL, id INTEGER) WITHOUT ROWID; +** CREATE TABLE rbu_imposter2(c1 TEXT, c2 REAL, id INTEGER) WITHOUT ROWID; ** */ -static void otaCreateImposterTable2(sqlite3ota *p, OtaObjIter *pIter){ - if( p->rc==SQLITE_OK && pIter->eType==OTA_PK_EXTERNAL ){ +static void rbuCreateImposterTable2(sqlite3rbu *p, RbuObjIter *pIter){ + if( p->rc==SQLITE_OK && pIter->eType==RBU_PK_EXTERNAL ){ int tnum = pIter->iPkTnum; /* Root page of PK index */ sqlite3_stmt *pQuery = 0; /* SELECT name ... WHERE rootpage = $tnum */ const char *zIdx = 0; /* Name of PK index */ @@ -1399,7 +1399,7 @@ static void otaCreateImposterTable2(sqlite3ota *p, OtaObjIter *pIter){ sqlite3_mprintf("PRAGMA main.index_xinfo = %Q", zIdx) ); } - otaFinalize(p, pQuery); + rbuFinalize(p, pQuery); while( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pXInfo) ){ int bKey = sqlite3_column_int(pXInfo, 5); @@ -1407,19 +1407,19 @@ static void otaCreateImposterTable2(sqlite3ota *p, OtaObjIter *pIter){ int iCid = sqlite3_column_int(pXInfo, 1); int bDesc = sqlite3_column_int(pXInfo, 3); const char *zCollate = (const char*)sqlite3_column_text(pXInfo, 4); - zCols = otaMPrintf(p, "%z%sc%d %s COLLATE %s", zCols, zComma, + zCols = rbuMPrintf(p, "%z%sc%d %s COLLATE %s", zCols, zComma, iCid, pIter->azTblType[iCid], zCollate ); - zPk = otaMPrintf(p, "%z%sc%d%s", zPk, zComma, iCid, bDesc?" DESC":""); + zPk = rbuMPrintf(p, "%z%sc%d%s", zPk, zComma, iCid, bDesc?" DESC":""); zComma = ", "; } } - zCols = otaMPrintf(p, "%z, id INTEGER", zCols); - otaFinalize(p, pXInfo); + zCols = rbuMPrintf(p, "%z, id INTEGER", zCols); + rbuFinalize(p, pXInfo); sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 1, tnum); - otaMPrintfExec(p, p->dbMain, - "CREATE TABLE ota_imposter2(%z, PRIMARY KEY(%z)) WITHOUT ROWID", + rbuMPrintfExec(p, p->dbMain, + "CREATE TABLE rbu_imposter2(%z, PRIMARY KEY(%z)) WITHOUT ROWID", zCols, zPk ); sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 0, 0); @@ -1430,7 +1430,7 @@ static void otaCreateImposterTable2(sqlite3ota *p, OtaObjIter *pIter){ ** If an error has already occurred when this function is called, it ** immediately returns zero (without doing any work). Or, if an error ** occurs during the execution of this function, it sets the error code -** in the sqlite3ota object indicated by the first argument and returns +** in the sqlite3rbu object indicated by the first argument and returns ** zero. ** ** The iterator passed as the second argument is guaranteed to point to @@ -1439,15 +1439,15 @@ static void otaCreateImposterTable2(sqlite3ota *p, OtaObjIter *pIter){ ** table b-tree of the table before returning. Non-zero is returned if ** an imposter table are created, or zero otherwise. ** -** An imposter table is required in all cases except OTA_PK_VTAB. Only +** An imposter table is required in all cases except RBU_PK_VTAB. Only ** virtual tables are written to directly. The imposter table has the ** same schema as the actual target table (less any UNIQUE constraints). ** More precisely, the "same schema" means the same columns, types, ** collation sequences. For tables that do not have an external PRIMARY ** KEY, it also means the same PRIMARY KEY declaration. */ -static void otaCreateImposterTable(sqlite3ota *p, OtaObjIter *pIter){ - if( p->rc==SQLITE_OK && pIter->eType!=OTA_PK_VTAB ){ +static void rbuCreateImposterTable(sqlite3rbu *p, RbuObjIter *pIter){ + if( p->rc==SQLITE_OK && pIter->eType!=RBU_PK_VTAB ){ int tnum = pIter->iTnum; const char *zComma = ""; char *zSql = 0; @@ -1463,69 +1463,69 @@ static void otaCreateImposterTable(sqlite3ota *p, OtaObjIter *pIter){ p->dbMain, "main", pIter->zTbl, zCol, 0, &zColl, 0, 0, 0 ); - if( pIter->eType==OTA_PK_IPK && pIter->abTblPk[iCol] ){ + if( pIter->eType==RBU_PK_IPK && pIter->abTblPk[iCol] ){ /* If the target table column is an "INTEGER PRIMARY KEY", add ** "PRIMARY KEY" to the imposter table column declaration. */ zPk = "PRIMARY KEY "; } - zSql = otaMPrintf(p, "%z%s\"%w\" %s %sCOLLATE %s%s", + zSql = rbuMPrintf(p, "%z%s\"%w\" %s %sCOLLATE %s%s", zSql, zComma, zCol, pIter->azTblType[iCol], zPk, zColl, (pIter->abNotNull[iCol] ? " NOT NULL" : "") ); zComma = ", "; } - if( pIter->eType==OTA_PK_WITHOUT_ROWID ){ - char *zPk = otaWithoutRowidPK(p, pIter); + if( pIter->eType==RBU_PK_WITHOUT_ROWID ){ + char *zPk = rbuWithoutRowidPK(p, pIter); if( zPk ){ - zSql = otaMPrintf(p, "%z, %z", zSql, zPk); + zSql = rbuMPrintf(p, "%z, %z", zSql, zPk); } } sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 1, tnum); - otaMPrintfExec(p, p->dbMain, "CREATE TABLE \"ota_imp_%w\"(%z)%s", + rbuMPrintfExec(p, p->dbMain, "CREATE TABLE \"rbu_imp_%w\"(%z)%s", pIter->zTbl, zSql, - (pIter->eType==OTA_PK_WITHOUT_ROWID ? " WITHOUT ROWID" : "") + (pIter->eType==RBU_PK_WITHOUT_ROWID ? " WITHOUT ROWID" : "") ); sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 0, 0); } } /* -** Prepare a statement used to insert rows into the "ota_tmp_xxx" table. +** Prepare a statement used to insert rows into the "rbu_tmp_xxx" table. ** Specifically a statement of the form: ** -** INSERT INTO ota_tmp_xxx VALUES(?, ?, ? ...); +** INSERT INTO rbu_tmp_xxx VALUES(?, ?, ? ...); ** ** The number of bound variables is equal to the number of columns in -** the target table, plus one (for the ota_control column), plus one more -** (for the ota_rowid column) if the target table is an implicit IPK or +** the target table, plus one (for the rbu_control column), plus one more +** (for the rbu_rowid column) if the target table is an implicit IPK or ** virtual table. */ -static void otaObjIterPrepareTmpInsert( - sqlite3ota *p, - OtaObjIter *pIter, +static void rbuObjIterPrepareTmpInsert( + sqlite3rbu *p, + RbuObjIter *pIter, const char *zCollist, - const char *zOtaRowid + const char *zRbuRowid ){ - int bOtaRowid = (pIter->eType==OTA_PK_EXTERNAL || pIter->eType==OTA_PK_NONE); - char *zBind = otaObjIterGetBindlist(p, pIter->nTblCol + 1 + bOtaRowid); + int bRbuRowid = (pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE); + char *zBind = rbuObjIterGetBindlist(p, pIter->nTblCol + 1 + bRbuRowid); if( zBind ){ assert( pIter->pTmpInsert==0 ); p->rc = prepareFreeAndCollectError( - p->dbOta, &pIter->pTmpInsert, &p->zErrmsg, sqlite3_mprintf( - "INSERT INTO %s.'ota_tmp_%q'(ota_control,%s%s) VALUES(%z)", - p->zStateDb, pIter->zTbl, zCollist, zOtaRowid, zBind + p->dbRbu, &pIter->pTmpInsert, &p->zErrmsg, sqlite3_mprintf( + "INSERT INTO %s.'rbu_tmp_%q'(rbu_control,%s%s) VALUES(%z)", + p->zStateDb, pIter->zTbl, zCollist, zRbuRowid, zBind )); } } -static void otaTmpInsertFunc( +static void rbuTmpInsertFunc( sqlite3_context *pCtx, int nVal, sqlite3_value **apVal ){ - sqlite3ota *p = sqlite3_user_data(pCtx); + sqlite3rbu *p = sqlite3_user_data(pCtx); int rc = SQLITE_OK; int i; @@ -1547,13 +1547,13 @@ static void otaTmpInsertFunc( ** target database object currently indicated by the iterator passed ** as the second argument are available. */ -static int otaObjIterPrepareAll( - sqlite3ota *p, - OtaObjIter *pIter, +static int rbuObjIterPrepareAll( + sqlite3rbu *p, + RbuObjIter *pIter, int nOffset /* Add "LIMIT -1 OFFSET $nOffset" to SELECT */ ){ assert( pIter->bCleanup==0 ); - if( pIter->pSelect==0 && otaObjIterCacheTableInfo(p, pIter)==SQLITE_OK ){ + if( pIter->pSelect==0 && rbuObjIterCacheTableInfo(p, pIter)==SQLITE_OK ){ const int tnum = pIter->iTnum; char *zCollist = 0; /* List of indexed columns */ char **pz = &p->zErrmsg; @@ -1573,17 +1573,17 @@ static int otaObjIterPrepareAll( char *zBind = 0; int nBind = 0; - assert( pIter->eType!=OTA_PK_VTAB ); - zCollist = otaObjIterGetIndexCols( + assert( pIter->eType!=RBU_PK_VTAB ); + zCollist = rbuObjIterGetIndexCols( p, pIter, &zImposterCols, &zImposterPK, &zWhere, &nBind ); - zBind = otaObjIterGetBindlist(p, nBind); + zBind = rbuObjIterGetBindlist(p, nBind); /* Create the imposter table used to write to this index. */ sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 0, 1); sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 1,tnum); - otaMPrintfExec(p, p->dbMain, - "CREATE TABLE \"ota_imp_%w\"( %s, PRIMARY KEY( %s ) ) WITHOUT ROWID", + rbuMPrintfExec(p, p->dbMain, + "CREATE TABLE \"rbu_imp_%w\"( %s, PRIMARY KEY( %s ) ) WITHOUT ROWID", zTbl, zImposterCols, zImposterPK ); sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 0, 0); @@ -1593,7 +1593,7 @@ static int otaObjIterPrepareAll( if( p->rc==SQLITE_OK ){ p->rc = prepareFreeAndCollectError( p->dbMain, &pIter->pInsert, &p->zErrmsg, - sqlite3_mprintf("INSERT INTO \"ota_imp_%w\" VALUES(%s)", zTbl, zBind) + sqlite3_mprintf("INSERT INTO \"rbu_imp_%w\" VALUES(%s)", zTbl, zBind) ); } @@ -1601,32 +1601,32 @@ static int otaObjIterPrepareAll( if( p->rc==SQLITE_OK ){ p->rc = prepareFreeAndCollectError( p->dbMain, &pIter->pDelete, &p->zErrmsg, - sqlite3_mprintf("DELETE FROM \"ota_imp_%w\" WHERE %s", zTbl, zWhere) + sqlite3_mprintf("DELETE FROM \"rbu_imp_%w\" WHERE %s", zTbl, zWhere) ); } /* Create the SELECT statement to read keys in sorted order */ if( p->rc==SQLITE_OK ){ char *zSql; - if( pIter->eType==OTA_PK_EXTERNAL || pIter->eType==OTA_PK_NONE ){ + if( pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE ){ zSql = sqlite3_mprintf( - "SELECT %s, ota_control FROM %s.'ota_tmp_%q' ORDER BY %s%s", + "SELECT %s, rbu_control FROM %s.'rbu_tmp_%q' ORDER BY %s%s", zCollist, p->zStateDb, pIter->zTbl, zCollist, zLimit ); }else{ zSql = sqlite3_mprintf( - "SELECT %s, ota_control FROM 'data_%q' " - "WHERE typeof(ota_control)='integer' AND ota_control!=1 " + "SELECT %s, rbu_control FROM 'data_%q' " + "WHERE typeof(rbu_control)='integer' AND rbu_control!=1 " "UNION ALL " - "SELECT %s, ota_control FROM %s.'ota_tmp_%q' " + "SELECT %s, rbu_control FROM %s.'rbu_tmp_%q' " "ORDER BY %s%s", zCollist, pIter->zTbl, zCollist, p->zStateDb, pIter->zTbl, zCollist, zLimit ); } - p->rc = prepareFreeAndCollectError(p->dbOta, &pIter->pSelect, pz, zSql); + p->rc = prepareFreeAndCollectError(p->dbRbu, &pIter->pSelect, pz, zSql); } sqlite3_free(zImposterCols); @@ -1634,39 +1634,39 @@ static int otaObjIterPrepareAll( sqlite3_free(zWhere); sqlite3_free(zBind); }else{ - int bOtaRowid = (pIter->eType==OTA_PK_VTAB || pIter->eType==OTA_PK_NONE); + int bRbuRowid = (pIter->eType==RBU_PK_VTAB || pIter->eType==RBU_PK_NONE); const char *zTbl = pIter->zTbl; /* Table this step applies to */ const char *zWrite; /* Imposter table name */ - char *zBindings = otaObjIterGetBindlist(p, pIter->nTblCol + bOtaRowid); - char *zWhere = otaObjIterGetWhere(p, pIter); - char *zOldlist = otaObjIterGetOldlist(p, pIter, "old"); - char *zNewlist = otaObjIterGetOldlist(p, pIter, "new"); + char *zBindings = rbuObjIterGetBindlist(p, pIter->nTblCol + bRbuRowid); + char *zWhere = rbuObjIterGetWhere(p, pIter); + char *zOldlist = rbuObjIterGetOldlist(p, pIter, "old"); + char *zNewlist = rbuObjIterGetOldlist(p, pIter, "new"); - zCollist = otaObjIterGetCollist(p, pIter); + zCollist = rbuObjIterGetCollist(p, pIter); pIter->nCol = pIter->nTblCol; /* Create the SELECT statement to read keys from data_xxx */ if( p->rc==SQLITE_OK ){ - p->rc = prepareFreeAndCollectError(p->dbOta, &pIter->pSelect, pz, + p->rc = prepareFreeAndCollectError(p->dbRbu, &pIter->pSelect, pz, sqlite3_mprintf( - "SELECT %s, ota_control%s FROM 'data_%q'%s", - zCollist, (bOtaRowid ? ", ota_rowid" : ""), zTbl, zLimit + "SELECT %s, rbu_control%s FROM 'data_%q'%s", + zCollist, (bRbuRowid ? ", rbu_rowid" : ""), zTbl, zLimit ) ); } /* Create the imposter table or tables (if required). */ - otaCreateImposterTable(p, pIter); - otaCreateImposterTable2(p, pIter); - zWrite = (pIter->eType==OTA_PK_VTAB ? "" : "ota_imp_"); + rbuCreateImposterTable(p, pIter); + rbuCreateImposterTable2(p, pIter); + zWrite = (pIter->eType==RBU_PK_VTAB ? "" : "rbu_imp_"); /* Create the INSERT statement to write to the target PK b-tree */ if( p->rc==SQLITE_OK ){ p->rc = prepareFreeAndCollectError(p->dbMain, &pIter->pInsert, pz, sqlite3_mprintf( "INSERT INTO \"%s%w\"(%s%s) VALUES(%s)", - zWrite, zTbl, zCollist, (bOtaRowid ? ", _rowid_" : ""), zBindings + zWrite, zTbl, zCollist, (bRbuRowid ? ", _rowid_" : ""), zBindings ) ); } @@ -1681,51 +1681,51 @@ static int otaObjIterPrepareAll( } if( pIter->abIndexed ){ - const char *zOtaRowid = ""; - if( pIter->eType==OTA_PK_EXTERNAL || pIter->eType==OTA_PK_NONE ){ - zOtaRowid = ", ota_rowid"; + const char *zRbuRowid = ""; + if( pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE ){ + zRbuRowid = ", rbu_rowid"; } - /* Create the ota_tmp_xxx table and the triggers to populate it. */ - otaMPrintfExec(p, p->dbOta, - "CREATE TABLE IF NOT EXISTS %s.'ota_tmp_%q' AS " + /* Create the rbu_tmp_xxx table and the triggers to populate it. */ + rbuMPrintfExec(p, p->dbRbu, + "CREATE TABLE IF NOT EXISTS %s.'rbu_tmp_%q' AS " "SELECT *%s FROM 'data_%q' WHERE 0;" , p->zStateDb - , zTbl, (pIter->eType==OTA_PK_EXTERNAL ? ", 0 AS ota_rowid" : "") + , zTbl, (pIter->eType==RBU_PK_EXTERNAL ? ", 0 AS rbu_rowid" : "") , zTbl ); - otaMPrintfExec(p, p->dbMain, - "CREATE TEMP TRIGGER ota_delete_tr BEFORE DELETE ON \"%s%w\" " + rbuMPrintfExec(p, p->dbMain, + "CREATE TEMP TRIGGER rbu_delete_tr BEFORE DELETE ON \"%s%w\" " "BEGIN " - " SELECT ota_tmp_insert(2, %s);" + " SELECT rbu_tmp_insert(2, %s);" "END;" - "CREATE TEMP TRIGGER ota_update1_tr BEFORE UPDATE ON \"%s%w\" " + "CREATE TEMP TRIGGER rbu_update1_tr BEFORE UPDATE ON \"%s%w\" " "BEGIN " - " SELECT ota_tmp_insert(2, %s);" + " SELECT rbu_tmp_insert(2, %s);" "END;" - "CREATE TEMP TRIGGER ota_update2_tr AFTER UPDATE ON \"%s%w\" " + "CREATE TEMP TRIGGER rbu_update2_tr AFTER UPDATE ON \"%s%w\" " "BEGIN " - " SELECT ota_tmp_insert(3, %s);" + " SELECT rbu_tmp_insert(3, %s);" "END;", zWrite, zTbl, zOldlist, zWrite, zTbl, zOldlist, zWrite, zTbl, zNewlist ); - if( pIter->eType==OTA_PK_EXTERNAL || pIter->eType==OTA_PK_NONE ){ - otaMPrintfExec(p, p->dbMain, - "CREATE TEMP TRIGGER ota_insert_tr AFTER INSERT ON \"%s%w\" " + if( pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE ){ + rbuMPrintfExec(p, p->dbMain, + "CREATE TEMP TRIGGER rbu_insert_tr AFTER INSERT ON \"%s%w\" " "BEGIN " - " SELECT ota_tmp_insert(0, %s);" + " SELECT rbu_tmp_insert(0, %s);" "END;", zWrite, zTbl, zNewlist ); } - otaObjIterPrepareTmpInsert(p, pIter, zCollist, zOtaRowid); + rbuObjIterPrepareTmpInsert(p, pIter, zCollist, zRbuRowid); } sqlite3_free(zWhere); @@ -1744,19 +1744,19 @@ static int otaObjIterPrepareAll( ** Set output variable *ppStmt to point to an UPDATE statement that may ** be used to update the imposter table for the main table b-tree of the ** table object that pIter currently points to, assuming that the -** ota_control column of the data_xyz table contains zMask. +** rbu_control column of the data_xyz table contains zMask. ** ** If the zMask string does not specify any columns to update, then this ** is not an error. Output variable *ppStmt is set to NULL in this case. */ -static int otaGetUpdateStmt( - sqlite3ota *p, /* OTA handle */ - OtaObjIter *pIter, /* Object iterator */ - const char *zMask, /* ota_control value ('x.x.') */ +static int rbuGetUpdateStmt( + sqlite3rbu *p, /* RBU handle */ + RbuObjIter *pIter, /* Object iterator */ + const char *zMask, /* rbu_control value ('x.x.') */ sqlite3_stmt **ppStmt /* OUT: UPDATE statement handle */ ){ - OtaUpdateStmt **pp; - OtaUpdateStmt *pUp = 0; + RbuUpdateStmt **pp; + RbuUpdateStmt *pUp = 0; int nUp = 0; /* In case an error occurs */ @@ -1766,12 +1766,12 @@ static int otaGetUpdateStmt( ** of the LRU queue and return immediately. Otherwise, leave nUp pointing ** to the number of statements currently in the cache and pUp to the ** last object in the list. */ - for(pp=&pIter->pOtaUpdate; *pp; pp=&((*pp)->pNext)){ + for(pp=&pIter->pRbuUpdate; *pp; pp=&((*pp)->pNext)){ pUp = *pp; if( strcmp(pUp->zMask, zMask)==0 ){ *pp = pUp->pNext; - pUp->pNext = pIter->pOtaUpdate; - pIter->pOtaUpdate = pUp; + pUp->pNext = pIter->pRbuUpdate; + pIter->pRbuUpdate = pUp; *ppStmt = pUp->pUpdate; return SQLITE_OK; } @@ -1779,29 +1779,29 @@ static int otaGetUpdateStmt( } assert( pUp==0 || pUp->pNext==0 ); - if( nUp>=SQLITE_OTA_UPDATE_CACHESIZE ){ - for(pp=&pIter->pOtaUpdate; *pp!=pUp; pp=&((*pp)->pNext)); + if( nUp>=SQLITE_RBU_UPDATE_CACHESIZE ){ + for(pp=&pIter->pRbuUpdate; *pp!=pUp; pp=&((*pp)->pNext)); *pp = 0; sqlite3_finalize(pUp->pUpdate); pUp->pUpdate = 0; }else{ - pUp = (OtaUpdateStmt*)otaMalloc(p, sizeof(OtaUpdateStmt)+pIter->nTblCol+1); + pUp = (RbuUpdateStmt*)rbuMalloc(p, sizeof(RbuUpdateStmt)+pIter->nTblCol+1); } if( pUp ){ - char *zWhere = otaObjIterGetWhere(p, pIter); - char *zSet = otaObjIterGetSetlist(p, pIter, zMask); + char *zWhere = rbuObjIterGetWhere(p, pIter); + char *zSet = rbuObjIterGetSetlist(p, pIter, zMask); char *zUpdate = 0; pUp->zMask = (char*)&pUp[1]; memcpy(pUp->zMask, zMask, pIter->nTblCol); - pUp->pNext = pIter->pOtaUpdate; - pIter->pOtaUpdate = pUp; + pUp->pNext = pIter->pRbuUpdate; + pIter->pRbuUpdate = pUp; if( zSet ){ const char *zPrefix = ""; - if( pIter->eType!=OTA_PK_VTAB ) zPrefix = "ota_imp_"; + if( pIter->eType!=RBU_PK_VTAB ) zPrefix = "rbu_imp_"; zUpdate = sqlite3_mprintf("UPDATE \"%s%w\" SET %s WHERE %s", zPrefix, pIter->zTbl, zSet, zWhere ); @@ -1817,7 +1817,7 @@ static int otaGetUpdateStmt( return p->rc; } -static sqlite3 *otaOpenDbhandle(sqlite3ota *p, const char *zName){ +static sqlite3 *rbuOpenDbhandle(sqlite3rbu *p, const char *zName){ sqlite3 *db = 0; if( p->rc==SQLITE_OK ){ const int flags = SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|SQLITE_OPEN_URI; @@ -1832,21 +1832,21 @@ static sqlite3 *otaOpenDbhandle(sqlite3ota *p, const char *zName){ } /* -** 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. +** Open the database handle and attach the RBU database as "rbu". If an +** error occurs, leave an error code and message in the RBU handle. */ -static void otaOpenDatabase(sqlite3ota *p){ +static void rbuOpenDatabase(sqlite3rbu *p){ assert( p->rc==SQLITE_OK ); - assert( p->dbMain==0 && p->dbOta==0 ); + assert( p->dbMain==0 && p->dbRbu==0 ); p->eStage = 0; - p->dbMain = otaOpenDbhandle(p, p->zTarget); - p->dbOta = otaOpenDbhandle(p, p->zOta); + p->dbMain = rbuOpenDbhandle(p, p->zTarget); + p->dbRbu = rbuOpenDbhandle(p, p->zRbu); - /* If using separate OTA and state databases, attach the state database to - ** the OTA db handle now. */ + /* If using separate RBU and state databases, attach the state database to + ** the RBU db handle now. */ if( p->zState ){ - otaMPrintfExec(p, p->dbOta, "ATTACH %Q AS stat", p->zState); + rbuMPrintfExec(p, p->dbRbu, "ATTACH %Q AS stat", p->zState); memcpy(p->zStateDb, "stat", 4); }else{ memcpy(p->zStateDb, "main", 4); @@ -1854,25 +1854,25 @@ static void otaOpenDatabase(sqlite3ota *p){ if( p->rc==SQLITE_OK ){ p->rc = sqlite3_create_function(p->dbMain, - "ota_tmp_insert", -1, SQLITE_UTF8, (void*)p, otaTmpInsertFunc, 0, 0 + "rbu_tmp_insert", -1, SQLITE_UTF8, (void*)p, rbuTmpInsertFunc, 0, 0 ); } if( p->rc==SQLITE_OK ){ - p->rc = sqlite3_file_control(p->dbMain, "main", SQLITE_FCNTL_OTA, (void*)p); + p->rc = sqlite3_file_control(p->dbMain, "main", SQLITE_FCNTL_RBU, (void*)p); } - otaMPrintfExec(p, p->dbMain, "SELECT * FROM sqlite_master"); + rbuMPrintfExec(p, p->dbMain, "SELECT * FROM sqlite_master"); - /* 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. + /* Mark the database file just opened as an RBU target database. If + ** this call returns SQLITE_NOTFOUND, then the RBU vfs is not in use. ** This is an error. */ if( p->rc==SQLITE_OK ){ - p->rc = sqlite3_file_control(p->dbMain, "main", SQLITE_FCNTL_OTA, (void*)p); + p->rc = sqlite3_file_control(p->dbMain, "main", SQLITE_FCNTL_RBU, (void*)p); } if( p->rc==SQLITE_NOTFOUND ){ p->rc = SQLITE_ERROR; - p->zErrmsg = sqlite3_mprintf("ota vfs not found"); + p->zErrmsg = sqlite3_mprintf("rbu vfs not found"); } } @@ -1896,7 +1896,7 @@ static void otaOpenDatabase(sqlite3ota *p){ ** test.db-shm => test.shm ** test.db-mj7f3319fa => test.9fa */ -static void otaFileSuffix3(const char *zBase, char *z){ +static void rbuFileSuffix3(const char *zBase, char *z){ #ifdef SQLITE_ENABLE_8_3_NAMES #if SQLITE_ENABLE_8_3_NAMES<2 if( sqlite3_uri_boolean(zBase, "8_3_names", 0) ) @@ -1917,7 +1917,7 @@ static void otaFileSuffix3(const char *zBase, char *z){ ** The checksum is store in the first page of xShmMap memory as an 8-byte ** blob starting at byte offset 40. */ -static i64 otaShmChecksum(sqlite3ota *p){ +static i64 rbuShmChecksum(sqlite3rbu *p){ i64 iRet = 0; if( p->rc==SQLITE_OK ){ sqlite3_file *pDb = p->pTargetFd->pReal; @@ -1934,19 +1934,19 @@ static i64 otaShmChecksum(sqlite3ota *p){ ** This function is called as part of initializing or reinitializing an ** incremental checkpoint. ** -** It populates the sqlite3ota.aFrame[] array with the set of +** It populates the sqlite3rbu.aFrame[] array with the set of ** (wal frame -> db page) copy operations required to checkpoint the ** current wal file, and obtains the set of shm locks required to safely ** perform the copy operations directly on the file-system. ** ** If argument pState is not NULL, then the incremental checkpoint is ** being resumed. In this case, if the checksum of the wal-index-header -** following recovery is not the same as the checksum saved in the OtaState -** object, then the ota handle is set to DONE state. This occurs if some +** following recovery is not the same as the checksum saved in the RbuState +** object, then the rbu handle is set to DONE state. This occurs if some ** other client appends a transaction to the wal file in the middle of ** an incremental checkpoint. */ -static void otaSetupCheckpoint(sqlite3ota *p, OtaState *pState){ +static void rbuSetupCheckpoint(sqlite3rbu *p, RbuState *pState){ /* If pState is NULL, then the wal file may not have been opened and ** recovered. Running a read-statement here to ensure that doing so @@ -1959,8 +1959,8 @@ static void otaSetupCheckpoint(sqlite3ota *p, OtaState *pState){ } /* Assuming no error has occurred, run a "restart" checkpoint with the - ** sqlite3ota.eStage variable set to CAPTURE. This turns on the following - ** special behaviour in the ota VFS: + ** sqlite3rbu.eStage variable set to CAPTURE. This turns on the following + ** special behaviour in the rbu VFS: ** ** * If the exclusive shm WRITER or READ0 lock cannot be obtained, ** the checkpoint fails with SQLITE_BUSY (normally SQLite would @@ -1968,7 +1968,7 @@ static void otaSetupCheckpoint(sqlite3ota *p, OtaState *pState){ ** ** * Attempts to read from the *-wal file or write to the database file ** do not perform any IO. Instead, the frame/page combinations that - ** would be read/written are recorded in the sqlite3ota.aFrame[] + ** would be read/written are recorded in the sqlite3rbu.aFrame[] ** array. ** ** * Calls to xShmLock(UNLOCK) to release the exclusive shm WRITER, @@ -1988,72 +1988,72 @@ static void otaSetupCheckpoint(sqlite3ota *p, OtaState *pState){ */ if( p->rc==SQLITE_OK ){ int rc2; - p->eStage = OTA_STAGE_CAPTURE; + p->eStage = RBU_STAGE_CAPTURE; rc2 = sqlite3_exec(p->dbMain, "PRAGMA main.wal_checkpoint=restart", 0, 0,0); if( rc2!=SQLITE_INTERNAL ) p->rc = rc2; } if( p->rc==SQLITE_OK ){ - p->eStage = OTA_STAGE_CKPT; + p->eStage = RBU_STAGE_CKPT; p->nStep = (pState ? pState->nRow : 0); - p->aBuf = otaMalloc(p, p->pgsz); - p->iWalCksum = otaShmChecksum(p); + p->aBuf = rbuMalloc(p, p->pgsz); + p->iWalCksum = rbuShmChecksum(p); } if( p->rc==SQLITE_OK && pState && pState->iWalCksum!=p->iWalCksum ){ p->rc = SQLITE_DONE; - p->eStage = OTA_STAGE_DONE; + p->eStage = RBU_STAGE_DONE; } } /* ** Called when iAmt bytes are read from offset iOff of the wal file while -** the ota object is in capture mode. Record the frame number of the frame +** the rbu object is in capture mode. Record the frame number of the frame ** being read in the aFrame[] array. */ -static int otaCaptureWalRead(sqlite3ota *pOta, i64 iOff, int iAmt){ +static int rbuCaptureWalRead(sqlite3rbu *pRbu, i64 iOff, int iAmt){ const u32 mReq = (1<<WAL_LOCK_WRITE)|(1<<WAL_LOCK_CKPT)|(1<<WAL_LOCK_READ0); u32 iFrame; - if( pOta->mLock!=mReq ){ - pOta->rc = SQLITE_BUSY; + if( pRbu->mLock!=mReq ){ + pRbu->rc = SQLITE_BUSY; return SQLITE_INTERNAL; } - pOta->pgsz = iAmt; - if( pOta->nFrame==pOta->nFrameAlloc ){ - int nNew = (pOta->nFrameAlloc ? pOta->nFrameAlloc : 64) * 2; - OtaFrame *aNew; - aNew = (OtaFrame*)sqlite3_realloc(pOta->aFrame, nNew * sizeof(OtaFrame)); + pRbu->pgsz = iAmt; + if( pRbu->nFrame==pRbu->nFrameAlloc ){ + int nNew = (pRbu->nFrameAlloc ? pRbu->nFrameAlloc : 64) * 2; + RbuFrame *aNew; + aNew = (RbuFrame*)sqlite3_realloc(pRbu->aFrame, nNew * sizeof(RbuFrame)); if( aNew==0 ) return SQLITE_NOMEM; - pOta->aFrame = aNew; - pOta->nFrameAlloc = nNew; + pRbu->aFrame = aNew; + pRbu->nFrameAlloc = nNew; } iFrame = (u32)((iOff-32) / (i64)(iAmt+24)) + 1; - if( pOta->iMaxFrame<iFrame ) pOta->iMaxFrame = iFrame; - pOta->aFrame[pOta->nFrame].iWalFrame = iFrame; - pOta->aFrame[pOta->nFrame].iDbPage = 0; - pOta->nFrame++; + if( pRbu->iMaxFrame<iFrame ) pRbu->iMaxFrame = iFrame; + pRbu->aFrame[pRbu->nFrame].iWalFrame = iFrame; + pRbu->aFrame[pRbu->nFrame].iDbPage = 0; + pRbu->nFrame++; return SQLITE_OK; } /* ** Called when a page of data is written to offset iOff of the database -** file while the ota handle is in capture mode. Record the page number +** file while the rbu handle is in capture mode. Record the page number ** of the page being written in the aFrame[] array. */ -static int otaCaptureDbWrite(sqlite3ota *pOta, i64 iOff){ - pOta->aFrame[pOta->nFrame-1].iDbPage = (u32)(iOff / pOta->pgsz) + 1; +static int rbuCaptureDbWrite(sqlite3rbu *pRbu, i64 iOff){ + pRbu->aFrame[pRbu->nFrame-1].iDbPage = (u32)(iOff / pRbu->pgsz) + 1; return SQLITE_OK; } /* ** This is called as part of an incremental checkpoint operation. Copy ** a single frame of data from the wal file into the database file, as -** indicated by the OtaFrame object. +** indicated by the RbuFrame object. */ -static void otaCheckpointFrame(sqlite3ota *p, OtaFrame *pFrame){ +static void rbuCheckpointFrame(sqlite3rbu *p, RbuFrame *pFrame){ sqlite3_file *pWal = p->pTargetFd->pWalFd->pReal; sqlite3_file *pDb = p->pTargetFd->pReal; i64 iOff; @@ -2071,7 +2071,7 @@ static void otaCheckpointFrame(sqlite3ota *p, OtaFrame *pFrame){ /* ** Take an EXCLUSIVE lock on the database file. */ -static void otaLockDatabase(sqlite3ota *p){ +static void rbuLockDatabase(sqlite3rbu *p){ sqlite3_file *pReal = p->pTargetFd->pReal; assert( p->rc==SQLITE_OK ); p->rc = pReal->pMethods->xLock(pReal, SQLITE_LOCK_SHARED); @@ -2081,19 +2081,19 @@ static void otaLockDatabase(sqlite3ota *p){ } /* -** The OTA handle is currently in OTA_STAGE_OAL state, with a SHARED lock +** The RBU handle is currently in RBU_STAGE_OAL state, with a SHARED lock ** on the database file. This proc moves the *-oal file to the *-wal path, ** then reopens the database file (this time in vanilla, non-oal, WAL mode). -** If an error occurs, leave an error code and error message in the ota +** If an error occurs, leave an error code and error message in the rbu ** handle. */ -static void otaMoveOalFile(sqlite3ota *p){ +static void rbuMoveOalFile(sqlite3rbu *p){ const char *zBase = sqlite3_db_filename(p->dbMain, "main"); char *zWal = sqlite3_mprintf("%s-wal", zBase); char *zOal = sqlite3_mprintf("%s-oal", zBase); - assert( p->eStage==OTA_STAGE_MOVE ); + assert( p->eStage==RBU_STAGE_MOVE ); assert( p->rc==SQLITE_OK && p->zErrmsg==0 ); if( zWal==0 || zOal==0 ){ p->rc = SQLITE_NOMEM; @@ -2105,21 +2105,21 @@ static void otaMoveOalFile(sqlite3ota *p){ ** In order to ensure that there are no database readers, an EXCLUSIVE ** lock is obtained here before the *-oal is moved to *-wal. */ - otaLockDatabase(p); + rbuLockDatabase(p); if( p->rc==SQLITE_OK ){ - otaFileSuffix3(zBase, zWal); - otaFileSuffix3(zBase, zOal); + rbuFileSuffix3(zBase, zWal); + rbuFileSuffix3(zBase, zOal); /* Re-open the databases. */ - otaObjIterFinalize(&p->objiter); + rbuObjIterFinalize(&p->objiter); sqlite3_close(p->dbMain); - sqlite3_close(p->dbOta); + sqlite3_close(p->dbRbu); p->rc = rename(zOal, zWal) ? SQLITE_IOERR : SQLITE_OK; if( p->rc==SQLITE_OK ){ p->dbMain = 0; - p->dbOta = 0; - otaOpenDatabase(p); - otaSetupCheckpoint(p, 0); + p->dbRbu = 0; + rbuOpenDatabase(p); + rbuSetupCheckpoint(p, 0); } } } @@ -2134,32 +2134,32 @@ static void otaMoveOalFile(sqlite3ota *p){ ** determines the type of operation requested by this row and returns ** one of the following values to indicate the result: ** -** * OTA_INSERT -** * OTA_DELETE -** * OTA_IDX_DELETE -** * OTA_UPDATE +** * RBU_INSERT +** * RBU_DELETE +** * RBU_IDX_DELETE +** * RBU_UPDATE ** -** If OTA_UPDATE is returned, then output variable *pzMask is set to +** If RBU_UPDATE is returned, then output variable *pzMask is set to ** point to the text value indicating the columns to update. ** -** If the ota_control field contains an invalid value, an error code and -** message are left in the OTA handle and zero returned. +** If the rbu_control field contains an invalid value, an error code and +** message are left in the RBU handle and zero returned. */ -static int otaStepType(sqlite3ota *p, const char **pzMask){ - int iCol = p->objiter.nCol; /* Index of ota_control column */ +static int rbuStepType(sqlite3rbu *p, const char **pzMask){ + int iCol = p->objiter.nCol; /* Index of rbu_control column */ int res = 0; /* Return value */ switch( sqlite3_column_type(p->objiter.pSelect, iCol) ){ case SQLITE_INTEGER: { int iVal = sqlite3_column_int(p->objiter.pSelect, iCol); if( iVal==0 ){ - res = OTA_INSERT; + res = RBU_INSERT; }else if( iVal==1 ){ - res = OTA_DELETE; + res = RBU_DELETE; }else if( iVal==2 ){ - res = OTA_IDX_DELETE; + res = RBU_IDX_DELETE; }else if( iVal==3 ){ - res = OTA_IDX_INSERT; + res = RBU_IDX_INSERT; } break; } @@ -2171,7 +2171,7 @@ static int otaStepType(sqlite3ota *p, const char **pzMask){ }else{ *pzMask = (const char*)z; } - res = OTA_UPDATE; + res = RBU_UPDATE; break; } @@ -2181,7 +2181,7 @@ static int otaStepType(sqlite3ota *p, const char **pzMask){ } if( res==0 ){ - otaBadControlError(p); + rbuBadControlError(p); } return res; } @@ -2199,41 +2199,41 @@ static void assertColumnName(sqlite3_stmt *pStmt, int iCol, const char *zName){ #endif /* -** This function does the work for an sqlite3ota_step() call. +** This function does the work for an sqlite3rbu_step() call. ** ** The object-iterator (p->objiter) currently points to a valid object, ** and the input cursor (p->objiter.pSelect) currently points to a valid ** input row. Perform whatever processing is required and return. ** ** If no error occurs, SQLITE_OK is returned. Otherwise, an error code -** and message is left in the OTA handle and a copy of the error code +** and message is left in the RBU handle and a copy of the error code ** returned. */ -static int otaStep(sqlite3ota *p){ - OtaObjIter *pIter = &p->objiter; +static int rbuStep(sqlite3rbu *p){ + RbuObjIter *pIter = &p->objiter; const char *zMask = 0; int i; - int eType = otaStepType(p, &zMask); + int eType = rbuStepType(p, &zMask); if( eType ){ - assert( eType!=OTA_UPDATE || pIter->zIdx==0 ); + assert( eType!=RBU_UPDATE || pIter->zIdx==0 ); - if( pIter->zIdx==0 && eType==OTA_IDX_DELETE ){ - otaBadControlError(p); + if( pIter->zIdx==0 && eType==RBU_IDX_DELETE ){ + rbuBadControlError(p); } else if( - eType==OTA_INSERT - || eType==OTA_DELETE - || eType==OTA_IDX_DELETE - || eType==OTA_IDX_INSERT + eType==RBU_INSERT + || eType==RBU_DELETE + || eType==RBU_IDX_DELETE + || eType==RBU_IDX_INSERT ){ sqlite3_value *pVal; sqlite3_stmt *pWriter; - assert( eType!=OTA_UPDATE ); - assert( eType!=OTA_DELETE || pIter->zIdx==0 ); + assert( eType!=RBU_UPDATE ); + assert( eType!=RBU_DELETE || pIter->zIdx==0 ); - if( eType==OTA_IDX_DELETE || eType==OTA_DELETE ){ + if( eType==RBU_IDX_DELETE || eType==RBU_DELETE ){ pWriter = pIter->pDelete; }else{ pWriter = pIter->pInsert; @@ -2243,8 +2243,8 @@ static int otaStep(sqlite3ota *p){ /* If this is an INSERT into a table b-tree and the table has an ** explicit INTEGER PRIMARY KEY, check that this is not an attempt ** to write a NULL into the IPK column. That is not permitted. */ - if( eType==OTA_INSERT - && pIter->zIdx==0 && pIter->eType==OTA_PK_IPK && pIter->abTblPk[i] + if( eType==RBU_INSERT + && pIter->zIdx==0 && pIter->eType==RBU_PK_IPK && pIter->abTblPk[i] && sqlite3_column_type(pIter->pSelect, i)==SQLITE_NULL ){ p->rc = SQLITE_MISMATCH; @@ -2252,7 +2252,7 @@ static int otaStep(sqlite3ota *p){ goto step_out; } - if( eType==OTA_DELETE && pIter->abTblPk[i]==0 ){ + if( eType==RBU_DELETE && pIter->abTblPk[i]==0 ){ continue; } @@ -2261,16 +2261,16 @@ static int otaStep(sqlite3ota *p){ if( p->rc ) goto step_out; } if( pIter->zIdx==0 - && (pIter->eType==OTA_PK_VTAB || pIter->eType==OTA_PK_NONE) + && (pIter->eType==RBU_PK_VTAB || pIter->eType==RBU_PK_NONE) ){ /* For a virtual table, or a table with no primary key, the ** SELECT statement is: ** - ** SELECT <cols>, ota_control, ota_rowid FROM .... + ** SELECT <cols>, rbu_control, rbu_rowid FROM .... ** ** Hence column_value(pIter->nCol+1). */ - assertColumnName(pIter->pSelect, pIter->nCol+1, "ota_rowid"); + assertColumnName(pIter->pSelect, pIter->nCol+1, "rbu_rowid"); pVal = sqlite3_column_value(pIter->pSelect, pIter->nCol+1); p->rc = sqlite3_bind_value(pWriter, pIter->nCol+1, pVal); } @@ -2281,8 +2281,8 @@ static int otaStep(sqlite3ota *p){ }else{ sqlite3_value *pVal; sqlite3_stmt *pUpdate = 0; - assert( eType==OTA_UPDATE ); - otaGetUpdateStmt(p, pIter, zMask, &pUpdate); + assert( eType==RBU_UPDATE ); + rbuGetUpdateStmt(p, pIter, zMask, &pUpdate); if( pUpdate ){ for(i=0; p->rc==SQLITE_OK && i<pIter->nCol; i++){ char c = zMask[pIter->aiSrcOrder[i]]; @@ -2292,10 +2292,10 @@ static int otaStep(sqlite3ota *p){ } } if( p->rc==SQLITE_OK - && (pIter->eType==OTA_PK_VTAB || pIter->eType==OTA_PK_NONE) + && (pIter->eType==RBU_PK_VTAB || pIter->eType==RBU_PK_NONE) ){ - /* Bind the ota_rowid value to column _rowid_ */ - assertColumnName(pIter->pSelect, pIter->nCol+1, "ota_rowid"); + /* Bind the rbu_rowid value to column _rowid_ */ + assertColumnName(pIter->pSelect, pIter->nCol+1, "rbu_rowid"); pVal = sqlite3_column_value(pIter->pSelect, pIter->nCol+1); p->rc = sqlite3_bind_value(pUpdate, pIter->nCol+1, pVal); } @@ -2314,7 +2314,7 @@ static int otaStep(sqlite3ota *p){ /* ** Increment the schema cookie of the main database opened by p->dbMain. */ -static void otaIncrSchemaCookie(sqlite3ota *p){ +static void rbuIncrSchemaCookie(sqlite3rbu *p){ if( p->rc==SQLITE_OK ){ int iCookie = 1000000; sqlite3_stmt *pStmt; @@ -2331,28 +2331,28 @@ static void otaIncrSchemaCookie(sqlite3ota *p){ if( SQLITE_ROW==sqlite3_step(pStmt) ){ iCookie = sqlite3_column_int(pStmt, 0); } - otaFinalize(p, pStmt); + rbuFinalize(p, pStmt); } if( p->rc==SQLITE_OK ){ - otaMPrintfExec(p, p->dbMain, "PRAGMA schema_version = %d", iCookie+1); + rbuMPrintfExec(p, p->dbMain, "PRAGMA schema_version = %d", iCookie+1); } } } /* -** Update the contents of the ota_state table within the ota database. The -** value stored in the OTA_STATE_STAGE column is eStage. All other values -** are determined by inspecting the ota handle passed as the first argument. +** Update the contents of the rbu_state table within the rbu database. The +** value stored in the RBU_STATE_STAGE column is eStage. All other values +** are determined by inspecting the rbu handle passed as the first argument. */ -static void otaSaveState(sqlite3ota *p, int eStage){ +static void rbuSaveState(sqlite3rbu *p, int eStage){ if( p->rc==SQLITE_OK || p->rc==SQLITE_DONE ){ sqlite3_stmt *pInsert = 0; int rc; assert( p->zErrmsg==0 ); - rc = prepareFreeAndCollectError(p->dbOta, &pInsert, &p->zErrmsg, + rc = prepareFreeAndCollectError(p->dbRbu, &pInsert, &p->zErrmsg, sqlite3_mprintf( - "INSERT OR REPLACE INTO %s.ota_state(k, v) VALUES " + "INSERT OR REPLACE INTO %s.rbu_state(k, v) VALUES " "(%d, %d), " "(%d, %Q), " "(%d, %Q), " @@ -2362,14 +2362,14 @@ static void otaSaveState(sqlite3ota *p, int eStage){ "(%d, %lld), " "(%d, %lld) ", p->zStateDb, - OTA_STATE_STAGE, eStage, - OTA_STATE_TBL, p->objiter.zTbl, - OTA_STATE_IDX, p->objiter.zIdx, - OTA_STATE_ROW, p->nStep, - OTA_STATE_PROGRESS, p->nProgress, - OTA_STATE_CKPT, p->iWalCksum, - OTA_STATE_COOKIE, (i64)p->pTargetFd->iCookie, - OTA_STATE_OALSZ, p->iOalSz + RBU_STATE_STAGE, eStage, + RBU_STATE_TBL, p->objiter.zTbl, + RBU_STATE_IDX, p->objiter.zIdx, + RBU_STATE_ROW, p->nStep, + RBU_STATE_PROGRESS, p->nProgress, + RBU_STATE_CKPT, p->iWalCksum, + RBU_STATE_COOKIE, (i64)p->pTargetFd->iCookie, + RBU_STATE_OALSZ, p->iOalSz ) ); assert( pInsert==0 || rc==SQLITE_OK ); @@ -2384,26 +2384,26 @@ static void otaSaveState(sqlite3ota *p, int eStage){ /* -** Step the OTA object. +** Step the RBU object. */ -int sqlite3ota_step(sqlite3ota *p){ +int sqlite3rbu_step(sqlite3rbu *p){ if( p ){ switch( p->eStage ){ - case OTA_STAGE_OAL: { - OtaObjIter *pIter = &p->objiter; + case RBU_STAGE_OAL: { + RbuObjIter *pIter = &p->objiter; while( p->rc==SQLITE_OK && pIter->zTbl ){ if( pIter->bCleanup ){ - /* Clean up the ota_tmp_xxx table for the previous table. It + /* Clean up the rbu_tmp_xxx table for the previous table. It ** cannot be dropped as there are currently active SQL statements. ** But the contents can be deleted. */ if( pIter->abIndexed ){ - otaMPrintfExec(p, p->dbOta, - "DELETE FROM %s.'ota_tmp_%q'", p->zStateDb, pIter->zTbl + rbuMPrintfExec(p, p->dbRbu, + "DELETE FROM %s.'rbu_tmp_%q'", p->zStateDb, pIter->zTbl ); } }else{ - otaObjIterPrepareAll(p, pIter, 0); + rbuObjIterPrepareAll(p, pIter, 0); /* Advance to the next row to process. */ if( p->rc==SQLITE_OK ){ @@ -2411,40 +2411,40 @@ int sqlite3ota_step(sqlite3ota *p){ if( rc==SQLITE_ROW ){ p->nProgress++; p->nStep++; - return otaStep(p); + return rbuStep(p); } p->rc = sqlite3_reset(pIter->pSelect); p->nStep = 0; } } - otaObjIterNext(p, pIter); + rbuObjIterNext(p, pIter); } if( p->rc==SQLITE_OK ){ assert( pIter->zTbl==0 ); - otaSaveState(p, OTA_STAGE_MOVE); - otaIncrSchemaCookie(p); + rbuSaveState(p, RBU_STAGE_MOVE); + rbuIncrSchemaCookie(p); if( p->rc==SQLITE_OK ){ p->rc = sqlite3_exec(p->dbMain, "COMMIT", 0, 0, &p->zErrmsg); } if( p->rc==SQLITE_OK ){ - p->rc = sqlite3_exec(p->dbOta, "COMMIT", 0, 0, &p->zErrmsg); + p->rc = sqlite3_exec(p->dbRbu, "COMMIT", 0, 0, &p->zErrmsg); } - p->eStage = OTA_STAGE_MOVE; + p->eStage = RBU_STAGE_MOVE; } break; } - case OTA_STAGE_MOVE: { + case RBU_STAGE_MOVE: { if( p->rc==SQLITE_OK ){ - otaMoveOalFile(p); + rbuMoveOalFile(p); p->nProgress++; } break; } - case OTA_STAGE_CKPT: { + case RBU_STAGE_CKPT: { if( p->rc==SQLITE_OK ){ if( p->nStep>=p->nFrame ){ sqlite3_file *pDb = p->pTargetFd->pReal; @@ -2462,12 +2462,12 @@ int sqlite3ota_step(sqlite3ota *p){ } if( p->rc==SQLITE_OK ){ - p->eStage = OTA_STAGE_DONE; + p->eStage = RBU_STAGE_DONE; p->rc = SQLITE_DONE; } }else{ - OtaFrame *pFrame = &p->aFrame[p->nStep]; - otaCheckpointFrame(p, pFrame); + RbuFrame *pFrame = &p->aFrame[p->nStep]; + rbuCheckpointFrame(p, pFrame); p->nStep++; } p->nProgress++; @@ -2485,9 +2485,9 @@ int sqlite3ota_step(sqlite3ota *p){ } /* -** Free an OtaState object allocated by otaLoadState(). +** Free an RbuState object allocated by rbuLoadState(). */ -static void otaFreeState(OtaState *p){ +static void rbuFreeState(RbuState *p){ if( p ){ sqlite3_free(p->zTbl); sqlite3_free(p->zIdx); @@ -2496,63 +2496,63 @@ static void otaFreeState(OtaState *p){ } /* -** Allocate an OtaState object and load the contents of the ota_state +** Allocate an RbuState object and load the contents of the rbu_state ** table into it. Return a pointer to the new object. It is the ** responsibility of the caller to eventually free the object using ** sqlite3_free(). ** -** If an error occurs, leave an error code and message in the ota handle +** If an error occurs, leave an error code and message in the rbu handle ** and return NULL. */ -static OtaState *otaLoadState(sqlite3ota *p){ - OtaState *pRet = 0; +static RbuState *rbuLoadState(sqlite3rbu *p){ + RbuState *pRet = 0; sqlite3_stmt *pStmt = 0; int rc; int rc2; - pRet = (OtaState*)otaMalloc(p, sizeof(OtaState)); + pRet = (RbuState*)rbuMalloc(p, sizeof(RbuState)); if( pRet==0 ) return 0; - rc = prepareFreeAndCollectError(p->dbOta, &pStmt, &p->zErrmsg, - sqlite3_mprintf("SELECT k, v FROM %s.ota_state", p->zStateDb) + rc = prepareFreeAndCollectError(p->dbRbu, &pStmt, &p->zErrmsg, + sqlite3_mprintf("SELECT k, v FROM %s.rbu_state", p->zStateDb) ); while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){ switch( sqlite3_column_int(pStmt, 0) ){ - case OTA_STATE_STAGE: + case RBU_STATE_STAGE: pRet->eStage = sqlite3_column_int(pStmt, 1); - if( pRet->eStage!=OTA_STAGE_OAL - && pRet->eStage!=OTA_STAGE_MOVE - && pRet->eStage!=OTA_STAGE_CKPT + if( pRet->eStage!=RBU_STAGE_OAL + && pRet->eStage!=RBU_STAGE_MOVE + && pRet->eStage!=RBU_STAGE_CKPT ){ p->rc = SQLITE_CORRUPT; } break; - case OTA_STATE_TBL: - pRet->zTbl = otaStrndup((char*)sqlite3_column_text(pStmt, 1), &rc); + case RBU_STATE_TBL: + pRet->zTbl = rbuStrndup((char*)sqlite3_column_text(pStmt, 1), &rc); break; - case OTA_STATE_IDX: - pRet->zIdx = otaStrndup((char*)sqlite3_column_text(pStmt, 1), &rc); + case RBU_STATE_IDX: + pRet->zIdx = rbuStrndup((char*)sqlite3_column_text(pStmt, 1), &rc); break; - case OTA_STATE_ROW: + case RBU_STATE_ROW: pRet->nRow = sqlite3_column_int(pStmt, 1); break; - case OTA_STATE_PROGRESS: + case RBU_STATE_PROGRESS: pRet->nProgress = sqlite3_column_int64(pStmt, 1); break; - case OTA_STATE_CKPT: + case RBU_STATE_CKPT: pRet->iWalCksum = sqlite3_column_int64(pStmt, 1); break; - case OTA_STATE_COOKIE: + case RBU_STATE_COOKIE: pRet->iCookie = (u32)sqlite3_column_int64(pStmt, 1); break; - case OTA_STATE_OALSZ: + case RBU_STATE_OALSZ: pRet->iOalSz = (u32)sqlite3_column_int64(pStmt, 1); break; @@ -2573,43 +2573,43 @@ static OtaState *otaLoadState(sqlite3ota *p){ ** otherwise. Either or both argument may be NULL. Two NULL values are ** considered equal, and NULL is considered distinct from all other values. */ -static int otaStrCompare(const char *z1, const char *z2){ +static int rbuStrCompare(const char *z1, const char *z2){ if( z1==0 && z2==0 ) return 0; if( z1==0 || z2==0 ) return 1; return (sqlite3_stricmp(z1, z2)!=0); } /* -** This function is called as part of sqlite3ota_open() when initializing -** an ota handle in OAL stage. If the ota update has not started (i.e. -** the ota_state table was empty) it is a no-op. Otherwise, it arranges -** things so that the next call to sqlite3ota_step() continues on from -** where the previous ota handle left off. +** This function is called as part of sqlite3rbu_open() when initializing +** an rbu handle in OAL stage. If the rbu update has not started (i.e. +** the rbu_state table was empty) it is a no-op. Otherwise, it arranges +** things so that the next call to sqlite3rbu_step() continues on from +** where the previous rbu handle left off. ** ** If an error occurs, an error code and error message are left in the -** ota handle passed as the first argument. +** rbu handle passed as the first argument. */ -static void otaSetupOal(sqlite3ota *p, OtaState *pState){ +static void rbuSetupOal(sqlite3rbu *p, RbuState *pState){ assert( p->rc==SQLITE_OK ); if( pState->zTbl ){ - OtaObjIter *pIter = &p->objiter; + RbuObjIter *pIter = &p->objiter; int rc = SQLITE_OK; while( rc==SQLITE_OK && pIter->zTbl && (pIter->bCleanup - || otaStrCompare(pIter->zIdx, pState->zIdx) - || otaStrCompare(pIter->zTbl, pState->zTbl) + || rbuStrCompare(pIter->zIdx, pState->zIdx) + || rbuStrCompare(pIter->zTbl, pState->zTbl) )){ - rc = otaObjIterNext(p, pIter); + rc = rbuObjIterNext(p, pIter); } if( rc==SQLITE_OK && !pIter->zTbl ){ rc = SQLITE_ERROR; - p->zErrmsg = sqlite3_mprintf("ota_state mismatch error"); + p->zErrmsg = sqlite3_mprintf("rbu_state mismatch error"); } if( rc==SQLITE_OK ){ p->nStep = pState->nRow; - rc = otaObjIterPrepareAll(p, &p->objiter, p->nStep); + rc = rbuObjIterPrepareAll(p, &p->objiter, p->nStep); } p->rc = rc; @@ -2619,9 +2619,9 @@ static void otaSetupOal(sqlite3ota *p, OtaState *pState){ /* ** If there is a "*-oal" file in the file-system corresponding to the ** target database in the file-system, delete it. If an error occurs, -** leave an error code and error message in the ota handle. +** leave an error code and error message in the rbu handle. */ -static void otaDeleteOalFile(sqlite3ota *p){ +static void rbuDeleteOalFile(sqlite3rbu *p){ char *zOal = sqlite3_mprintf("%s-oal", p->zTarget); assert( p->rc==SQLITE_OK && p->zErrmsg==0 ); unlink(zOal); @@ -2629,19 +2629,19 @@ static void otaDeleteOalFile(sqlite3ota *p){ } /* -** Allocate a private ota VFS for the ota handle passed as the only -** argument. This VFS will be used unless the call to sqlite3ota_open() +** Allocate a private rbu VFS for the rbu handle passed as the only +** argument. This VFS will be used unless the call to sqlite3rbu_open() ** specified a URI with a vfs=? option in place of a target database ** file name. */ -static void otaCreateVfs(sqlite3ota *p){ +static void rbuCreateVfs(sqlite3rbu *p){ int rnd; char zRnd[64]; assert( p->rc==SQLITE_OK ); sqlite3_randomness(sizeof(int), (void*)&rnd); - sprintf(zRnd, "ota_vfs_%d", rnd); - p->rc = sqlite3ota_create_vfs(zRnd, 0); + sprintf(zRnd, "rbu_vfs_%d", rnd); + p->rc = sqlite3rbu_create_vfs(zRnd, 0); if( p->rc==SQLITE_OK ){ sqlite3_vfs *pVfs = sqlite3_vfs_find(zRnd); assert( pVfs ); @@ -2650,61 +2650,61 @@ static void otaCreateVfs(sqlite3ota *p){ } /* -** Destroy the private VFS created for the ota handle passed as the only -** argument by an earlier call to otaCreateVfs(). +** Destroy the private VFS created for the rbu handle passed as the only +** argument by an earlier call to rbuCreateVfs(). */ -static void otaDeleteVfs(sqlite3ota *p){ +static void rbuDeleteVfs(sqlite3rbu *p){ if( p->zVfsName ){ - sqlite3ota_destroy_vfs(p->zVfsName); + sqlite3rbu_destroy_vfs(p->zVfsName); p->zVfsName = 0; } } /* -** Open and return a new OTA handle. +** Open and return a new RBU handle. */ -sqlite3ota *sqlite3ota_open( +sqlite3rbu *sqlite3rbu_open( const char *zTarget, - const char *zOta, + const char *zRbu, const char *zState ){ - sqlite3ota *p; + sqlite3rbu *p; int nTarget = strlen(zTarget); - int nOta = strlen(zOta); + int nRbu = strlen(zRbu); int nState = zState ? strlen(zState) : 0; - p = (sqlite3ota*)sqlite3_malloc(sizeof(sqlite3ota)+nTarget+1+nOta+1+nState+1); + p = (sqlite3rbu*)sqlite3_malloc(sizeof(sqlite3rbu)+nTarget+1+nRbu+1+nState+1); if( p ){ - OtaState *pState = 0; + RbuState *pState = 0; /* Create the custom VFS. */ - memset(p, 0, sizeof(sqlite3ota)); - otaCreateVfs(p); + memset(p, 0, sizeof(sqlite3rbu)); + rbuCreateVfs(p); /* Open the target database */ if( p->rc==SQLITE_OK ){ p->zTarget = (char*)&p[1]; memcpy(p->zTarget, zTarget, nTarget+1); - p->zOta = &p->zTarget[nTarget+1]; - memcpy(p->zOta, zOta, nOta+1); + p->zRbu = &p->zTarget[nTarget+1]; + memcpy(p->zRbu, zRbu, nRbu+1); if( zState ){ - p->zState = &p->zOta[nOta+1]; + p->zState = &p->zRbu[nRbu+1]; memcpy(p->zState, zState, nState+1); } - otaOpenDatabase(p); + rbuOpenDatabase(p); } - /* If it has not already been created, create the ota_state table */ - otaMPrintfExec(p, p->dbOta, OTA_CREATE_STATE, p->zStateDb); + /* If it has not already been created, create the rbu_state table */ + rbuMPrintfExec(p, p->dbRbu, RBU_CREATE_STATE, p->zStateDb); if( p->rc==SQLITE_OK ){ - pState = otaLoadState(p); + pState = rbuLoadState(p); assert( pState || p->rc!=SQLITE_OK ); if( p->rc==SQLITE_OK ){ if( pState->eStage==0 ){ - otaDeleteOalFile(p); - p->eStage = OTA_STAGE_OAL; + rbuDeleteOalFile(p); + p->eStage = RBU_STAGE_OAL; }else{ p->eStage = pState->eStage; } @@ -2715,17 +2715,17 @@ sqlite3ota *sqlite3ota_open( assert( p->rc!=SQLITE_OK || p->eStage!=0 ); if( p->rc==SQLITE_OK && p->pTargetFd->pWalFd ){ - if( p->eStage==OTA_STAGE_OAL ){ + if( p->eStage==RBU_STAGE_OAL ){ p->rc = SQLITE_ERROR; p->zErrmsg = sqlite3_mprintf("cannot update wal mode database"); - }else if( p->eStage==OTA_STAGE_MOVE ){ - p->eStage = OTA_STAGE_CKPT; + }else if( p->eStage==RBU_STAGE_MOVE ){ + p->eStage = RBU_STAGE_CKPT; p->nStep = 0; } } if( p->rc==SQLITE_OK - && (p->eStage==OTA_STAGE_OAL || p->eStage==OTA_STAGE_MOVE) + && (p->eStage==RBU_STAGE_OAL || p->eStage==RBU_STAGE_MOVE) && pState->eStage!=0 && p->pTargetFd->iCookie!=pState->iCookie ){ /* At this point (pTargetFd->iCookie) contains the value of the @@ -2733,46 +2733,46 @@ sqlite3ota *sqlite3ota_open( ** transaction is committed in rollback mode) currently stored on ** page 1 of the database file. */ p->rc = SQLITE_BUSY; - p->zErrmsg = sqlite3_mprintf("database modified during ota update"); + p->zErrmsg = sqlite3_mprintf("database modified during rbu update"); } if( p->rc==SQLITE_OK ){ - if( p->eStage==OTA_STAGE_OAL ){ + if( p->eStage==RBU_STAGE_OAL ){ /* Open transactions both databases. The *-oal file is opened or ** created at this point. */ p->rc = sqlite3_exec(p->dbMain, "BEGIN IMMEDIATE", 0, 0, &p->zErrmsg); if( p->rc==SQLITE_OK ){ - p->rc = sqlite3_exec(p->dbOta, "BEGIN IMMEDIATE", 0, 0, &p->zErrmsg); + p->rc = sqlite3_exec(p->dbRbu, "BEGIN IMMEDIATE", 0, 0, &p->zErrmsg); } /* Point the object iterator at the first object */ if( p->rc==SQLITE_OK ){ - p->rc = otaObjIterFirst(p, &p->objiter); + p->rc = rbuObjIterFirst(p, &p->objiter); } - /* If the OTA database contains no data_xxx tables, declare the OTA + /* If the RBU database contains no data_xxx tables, declare the RBU ** update finished. */ if( p->rc==SQLITE_OK && p->objiter.zTbl==0 ){ p->rc = SQLITE_DONE; } if( p->rc==SQLITE_OK ){ - otaSetupOal(p, pState); + rbuSetupOal(p, pState); } - }else if( p->eStage==OTA_STAGE_MOVE ){ + }else if( p->eStage==RBU_STAGE_MOVE ){ /* no-op */ - }else if( p->eStage==OTA_STAGE_CKPT ){ - otaSetupCheckpoint(p, pState); - }else if( p->eStage==OTA_STAGE_DONE ){ + }else if( p->eStage==RBU_STAGE_CKPT ){ + rbuSetupCheckpoint(p, pState); + }else if( p->eStage==RBU_STAGE_DONE ){ p->rc = SQLITE_DONE; }else{ p->rc = SQLITE_CORRUPT; } } - otaFreeState(pState); + rbuFreeState(pState); } return p; @@ -2780,28 +2780,28 @@ sqlite3ota *sqlite3ota_open( /* -** Return the database handle used by pOta. +** Return the database handle used by pRbu. */ -sqlite3 *sqlite3ota_db(sqlite3ota *pOta, int bOta){ +sqlite3 *sqlite3rbu_db(sqlite3rbu *pRbu, int bRbu){ sqlite3 *db = 0; - if( pOta ){ - db = (bOta ? pOta->dbOta : pOta->dbMain); + if( pRbu ){ + db = (bRbu ? pRbu->dbRbu : pRbu->dbMain); } return db; } /* -** If the error code currently stored in the OTA handle is SQLITE_CONSTRAINT, +** If the error code currently stored in the RBU handle is SQLITE_CONSTRAINT, ** then edit any error message string so as to remove all occurrences of -** the pattern "ota_imp_[0-9]*". +** the pattern "rbu_imp_[0-9]*". */ -static void otaEditErrmsg(sqlite3ota *p){ +static void rbuEditErrmsg(sqlite3rbu *p){ if( p->rc==SQLITE_CONSTRAINT && p->zErrmsg ){ int i; int nErrmsg = strlen(p->zErrmsg); for(i=0; i<(nErrmsg-8); i++){ - if( memcmp(&p->zErrmsg[i], "ota_imp_", 8)==0 ){ + if( memcmp(&p->zErrmsg[i], "rbu_imp_", 8)==0 ){ int nDel = 8; while( p->zErrmsg[i+nDel]>='0' && p->zErrmsg[i+nDel]<='9' ) nDel++; memmove(&p->zErrmsg[i], &p->zErrmsg[i+nDel], nErrmsg + 1 - i - nDel); @@ -2812,34 +2812,34 @@ static void otaEditErrmsg(sqlite3ota *p){ } /* -** Close the OTA handle. +** Close the RBU handle. */ -int sqlite3ota_close(sqlite3ota *p, char **pzErrmsg){ +int sqlite3rbu_close(sqlite3rbu *p, char **pzErrmsg){ int rc; if( p ){ /* Commit the transaction to the *-oal file. */ - if( p->rc==SQLITE_OK && p->eStage==OTA_STAGE_OAL ){ + if( p->rc==SQLITE_OK && p->eStage==RBU_STAGE_OAL ){ p->rc = sqlite3_exec(p->dbMain, "COMMIT", 0, 0, &p->zErrmsg); } - otaSaveState(p, p->eStage); + rbuSaveState(p, p->eStage); - if( p->rc==SQLITE_OK && p->eStage==OTA_STAGE_OAL ){ - p->rc = sqlite3_exec(p->dbOta, "COMMIT", 0, 0, &p->zErrmsg); + if( p->rc==SQLITE_OK && p->eStage==RBU_STAGE_OAL ){ + p->rc = sqlite3_exec(p->dbRbu, "COMMIT", 0, 0, &p->zErrmsg); } /* Close any open statement handles. */ - otaObjIterFinalize(&p->objiter); + rbuObjIterFinalize(&p->objiter); /* Close the open database handle and VFS object. */ sqlite3_close(p->dbMain); - sqlite3_close(p->dbOta); - otaDeleteVfs(p); + sqlite3_close(p->dbRbu); + rbuDeleteVfs(p); sqlite3_free(p->aBuf); sqlite3_free(p->aFrame); - otaEditErrmsg(p); + rbuEditErrmsg(p); rc = p->rc; *pzErrmsg = p->zErrmsg; sqlite3_free(p); @@ -2853,61 +2853,61 @@ int sqlite3ota_close(sqlite3ota *p, char **pzErrmsg){ /* ** Return the total number of key-value operations (inserts, deletes or ** updates) that have been performed on the target database since the -** current OTA update was started. +** current RBU update was started. */ -sqlite3_int64 sqlite3ota_progress(sqlite3ota *pOta){ - return pOta->nProgress; +sqlite3_int64 sqlite3rbu_progress(sqlite3rbu *pRbu){ + return pRbu->nProgress; } /************************************************************************** -** Beginning of OTA VFS shim methods. The VFS shim modifies the behaviour +** Beginning of RBU VFS shim methods. The VFS shim modifies the behaviour ** of a standard VFS in the following ways: ** ** 1. Whenever the first page of a main database file is read or ** written, the value of the change-counter cookie is stored in -** ota_file.iCookie. Similarly, the value of the "write-version" -** database header field is stored in ota_file.iWriteVer. This ensures +** rbu_file.iCookie. Similarly, the value of the "write-version" +** database header field is stored in rbu_file.iWriteVer. This ensures ** that the values are always trustworthy within an open transaction. ** -** 2. Whenever an SQLITE_OPEN_WAL file is opened, the (ota_file.pWalFd) +** 2. Whenever an SQLITE_OPEN_WAL file is opened, the (rbu_file.pWalFd) ** member variable of the associated database file descriptor is set ** to point to the new file. A mutex protected linked list of all main -** db fds opened using a particular OTA VFS is maintained at -** ota_vfs.pMain to facilitate this. +** db fds opened using a particular RBU VFS is maintained at +** rbu_vfs.pMain to facilitate this. ** -** 3. Using a new file-control "SQLITE_FCNTL_OTA", a main db ota_file -** object can be marked as the target database of an OTA update. This +** 3. Using a new file-control "SQLITE_FCNTL_RBU", a main db rbu_file +** object can be marked as the target database of an RBU update. This ** turns on the following extra special behaviour: ** ** 3a. If xAccess() is called to check if there exists a *-wal file -** associated with an OTA target database currently in OTA_STAGE_OAL +** associated with an RBU target database currently in RBU_STAGE_OAL ** stage (preparing the *-oal file), the following special handling ** applies: ** -** * if the *-wal file does exist, return SQLITE_CANTOPEN. An OTA +** * if the *-wal file does exist, return SQLITE_CANTOPEN. An RBU ** target database may not be in wal mode already. ** ** * if the *-wal file does not exist, set the output parameter to ** non-zero (to tell SQLite that it does exist) anyway. ** ** Then, when xOpen() is called to open the *-wal file associated with -** the OTA target in OTA_STAGE_OAL stage, instead of opening the *-wal -** file, the ota vfs opens the corresponding *-oal file instead. +** the RBU target in RBU_STAGE_OAL stage, instead of opening the *-wal +** file, the rbu vfs opens the corresponding *-oal file instead. ** ** 3b. The *-shm pages returned by xShmMap() for a target db file in -** OTA_STAGE_OAL mode are actually stored in heap memory. This is to +** RBU_STAGE_OAL mode are actually stored in heap memory. This is to ** avoid creating a *-shm file on disk. Additionally, xShmLock() calls -** are no-ops on target database files in OTA_STAGE_OAL mode. This is +** are no-ops on target database files in RBU_STAGE_OAL mode. This is ** because assert() statements in some VFS implementations fail if ** xShmLock() is called before xShmMap(). ** ** 3c. If an EXCLUSIVE lock is attempted on a target database file in any -** mode except OTA_STAGE_DONE (all work completed and checkpointed), it -** fails with an SQLITE_BUSY error. This is to stop OTA connections +** mode except RBU_STAGE_DONE (all work completed and checkpointed), it +** fails with an SQLITE_BUSY error. This is to stop RBU connections ** from automatically checkpointing a *-wal (or *-oal) file from within ** sqlite3_close(). ** -** 3d. In OTA_STAGE_CAPTURE mode, all xRead() calls on the wal file, and +** 3d. In RBU_STAGE_CAPTURE mode, all xRead() calls on the wal file, and ** all xWrite() calls on the target database file perform no IO. ** Instead the frame and page numbers that would be read and written ** are recorded. Additionally, successful attempts to obtain exclusive @@ -2918,24 +2918,24 @@ sqlite3_int64 sqlite3ota_progress(sqlite3ota *pOta){ ** file fail with SQLITE_INTERNAL errors. */ -static void otaUnlockShm(ota_file *p){ - if( p->pOta ){ +static void rbuUnlockShm(rbu_file *p){ + if( p->pRbu ){ int (*xShmLock)(sqlite3_file*,int,int,int) = p->pReal->pMethods->xShmLock; int i; for(i=0; i<SQLITE_SHM_NLOCK;i++){ - if( (1<<i) & p->pOta->mLock ){ + if( (1<<i) & p->pRbu->mLock ){ xShmLock(p->pReal, i, 1, SQLITE_SHM_UNLOCK|SQLITE_SHM_EXCLUSIVE); } } - p->pOta->mLock = 0; + p->pRbu->mLock = 0; } } /* -** Close an ota file. +** Close an rbu file. */ -static int otaVfsClose(sqlite3_file *pFile){ - ota_file *p = (ota_file*)pFile; +static int rbuVfsClose(sqlite3_file *pFile){ + rbu_file *p = (rbu_file*)pFile; int rc; int i; @@ -2948,12 +2948,12 @@ static int otaVfsClose(sqlite3_file *pFile){ sqlite3_free(p->zDel); if( p->openFlags & SQLITE_OPEN_MAIN_DB ){ - ota_file **pp; - sqlite3_mutex_enter(p->pOtaVfs->mutex); - for(pp=&p->pOtaVfs->pMain; *pp!=p; pp=&((*pp)->pMainNext)); + rbu_file **pp; + sqlite3_mutex_enter(p->pRbuVfs->mutex); + for(pp=&p->pRbuVfs->pMain; *pp!=p; pp=&((*pp)->pMainNext)); *pp = p->pMainNext; - sqlite3_mutex_leave(p->pOtaVfs->mutex); - otaUnlockShm(p); + sqlite3_mutex_leave(p->pRbuVfs->mutex); + rbuUnlockShm(p); p->pReal->pMethods->xShmUnmap(p->pReal, 0); } @@ -2967,7 +2967,7 @@ static int otaVfsClose(sqlite3_file *pFile){ ** Read and return an unsigned 32-bit big-endian integer from the buffer ** passed as the only argument. */ -static u32 otaGetU32(u8 *aBuf){ +static u32 rbuGetU32(u8 *aBuf){ return ((u32)aBuf[0] << 24) + ((u32)aBuf[1] << 16) + ((u32)aBuf[2] << 8) @@ -2975,25 +2975,25 @@ static u32 otaGetU32(u8 *aBuf){ } /* -** Read data from an otaVfs-file. +** Read data from an rbuVfs-file. */ -static int otaVfsRead( +static int rbuVfsRead( sqlite3_file *pFile, void *zBuf, int iAmt, sqlite_int64 iOfst ){ - ota_file *p = (ota_file*)pFile; - sqlite3ota *pOta = p->pOta; + rbu_file *p = (rbu_file*)pFile; + sqlite3rbu *pRbu = p->pRbu; int rc; - if( pOta && pOta->eStage==OTA_STAGE_CAPTURE ){ + if( pRbu && pRbu->eStage==RBU_STAGE_CAPTURE ){ assert( p->openFlags & SQLITE_OPEN_WAL ); - rc = otaCaptureWalRead(p->pOta, iOfst, iAmt); + rc = rbuCaptureWalRead(p->pRbu, iOfst, iAmt); }else{ - if( pOta && pOta->eStage==OTA_STAGE_OAL + if( pRbu && pRbu->eStage==RBU_STAGE_OAL && (p->openFlags & SQLITE_OPEN_WAL) - && iOfst>=pOta->iOalSz + && iOfst>=pRbu->iOalSz ){ rc = SQLITE_OK; memset(zBuf, 0, iAmt); @@ -3004,7 +3004,7 @@ static int otaVfsRead( /* These look like magic numbers. But they are stable, as they are part ** of the definition of the SQLite file format, which may not change. */ u8 *pBuf = (u8*)zBuf; - p->iCookie = otaGetU32(&pBuf[24]); + p->iCookie = rbuGetU32(&pBuf[24]); p->iWriteVer = pBuf[19]; } } @@ -3012,34 +3012,34 @@ static int otaVfsRead( } /* -** Write data to an otaVfs-file. +** Write data to an rbuVfs-file. */ -static int otaVfsWrite( +static int rbuVfsWrite( sqlite3_file *pFile, const void *zBuf, int iAmt, sqlite_int64 iOfst ){ - ota_file *p = (ota_file*)pFile; - sqlite3ota *pOta = p->pOta; + rbu_file *p = (rbu_file*)pFile; + sqlite3rbu *pRbu = p->pRbu; int rc; - if( pOta && pOta->eStage==OTA_STAGE_CAPTURE ){ + if( pRbu && pRbu->eStage==RBU_STAGE_CAPTURE ){ assert( p->openFlags & SQLITE_OPEN_MAIN_DB ); - rc = otaCaptureDbWrite(p->pOta, iOfst); + rc = rbuCaptureDbWrite(p->pRbu, iOfst); }else{ - if( pOta && pOta->eStage==OTA_STAGE_OAL + if( pRbu && pRbu->eStage==RBU_STAGE_OAL && (p->openFlags & SQLITE_OPEN_WAL) - && iOfst>=pOta->iOalSz + && iOfst>=pRbu->iOalSz ){ - pOta->iOalSz = iAmt + iOfst; + pRbu->iOalSz = iAmt + iOfst; } rc = p->pReal->pMethods->xWrite(p->pReal, zBuf, iAmt, iOfst); if( rc==SQLITE_OK && iOfst==0 && (p->openFlags & SQLITE_OPEN_MAIN_DB) ){ /* These look like magic numbers. But they are stable, as they are part ** of the definition of the SQLite file format, which may not change. */ u8 *pBuf = (u8*)zBuf; - p->iCookie = otaGetU32(&pBuf[24]); + p->iCookie = rbuGetU32(&pBuf[24]); p->iWriteVer = pBuf[19]; } } @@ -3047,19 +3047,19 @@ static int otaVfsWrite( } /* -** Truncate an otaVfs-file. +** Truncate an rbuVfs-file. */ -static int otaVfsTruncate(sqlite3_file *pFile, sqlite_int64 size){ - ota_file *p = (ota_file*)pFile; +static int rbuVfsTruncate(sqlite3_file *pFile, sqlite_int64 size){ + rbu_file *p = (rbu_file*)pFile; return p->pReal->pMethods->xTruncate(p->pReal, size); } /* -** Sync an otaVfs-file. +** Sync an rbuVfs-file. */ -static int otaVfsSync(sqlite3_file *pFile, int flags){ - ota_file *p = (ota_file *)pFile; - if( p->pOta && p->pOta->eStage==OTA_STAGE_CAPTURE ){ +static int rbuVfsSync(sqlite3_file *pFile, int flags){ + rbu_file *p = (rbu_file *)pFile; + if( p->pRbu && p->pRbu->eStage==RBU_STAGE_CAPTURE ){ if( p->openFlags & SQLITE_OPEN_MAIN_DB ){ return SQLITE_INTERNAL; } @@ -3069,23 +3069,23 @@ static int otaVfsSync(sqlite3_file *pFile, int flags){ } /* -** Return the current file-size of an otaVfs-file. +** Return the current file-size of an rbuVfs-file. */ -static int otaVfsFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){ - ota_file *p = (ota_file *)pFile; +static int rbuVfsFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){ + rbu_file *p = (rbu_file *)pFile; return p->pReal->pMethods->xFileSize(p->pReal, pSize); } /* -** Lock an otaVfs-file. +** Lock an rbuVfs-file. */ -static int otaVfsLock(sqlite3_file *pFile, int eLock){ - ota_file *p = (ota_file*)pFile; - sqlite3ota *pOta = p->pOta; +static int rbuVfsLock(sqlite3_file *pFile, int eLock){ + rbu_file *p = (rbu_file*)pFile; + sqlite3rbu *pRbu = p->pRbu; int rc = SQLITE_OK; assert( p->openFlags & (SQLITE_OPEN_MAIN_DB|SQLITE_OPEN_TEMP_DB) ); - if( pOta && eLock==SQLITE_LOCK_EXCLUSIVE && pOta->eStage!=OTA_STAGE_DONE ){ + if( pRbu && eLock==SQLITE_LOCK_EXCLUSIVE && pRbu->eStage!=RBU_STAGE_DONE ){ /* Do not allow EXCLUSIVE locks. Preventing SQLite from taking this ** prevents it from checkpointing the database from sqlite3_close(). */ rc = SQLITE_BUSY; @@ -3097,38 +3097,38 @@ static int otaVfsLock(sqlite3_file *pFile, int eLock){ } /* -** Unlock an otaVfs-file. +** Unlock an rbuVfs-file. */ -static int otaVfsUnlock(sqlite3_file *pFile, int eLock){ - ota_file *p = (ota_file *)pFile; +static int rbuVfsUnlock(sqlite3_file *pFile, int eLock){ + rbu_file *p = (rbu_file *)pFile; return p->pReal->pMethods->xUnlock(p->pReal, eLock); } /* -** Check if another file-handle holds a RESERVED lock on an otaVfs-file. +** Check if another file-handle holds a RESERVED lock on an rbuVfs-file. */ -static int otaVfsCheckReservedLock(sqlite3_file *pFile, int *pResOut){ - ota_file *p = (ota_file *)pFile; +static int rbuVfsCheckReservedLock(sqlite3_file *pFile, int *pResOut){ + rbu_file *p = (rbu_file *)pFile; return p->pReal->pMethods->xCheckReservedLock(p->pReal, pResOut); } /* -** File control method. For custom operations on an otaVfs-file. +** File control method. For custom operations on an rbuVfs-file. */ -static int otaVfsFileControl(sqlite3_file *pFile, int op, void *pArg){ - ota_file *p = (ota_file *)pFile; +static int rbuVfsFileControl(sqlite3_file *pFile, int op, void *pArg){ + rbu_file *p = (rbu_file *)pFile; int (*xControl)(sqlite3_file*,int,void*) = p->pReal->pMethods->xFileControl; int rc; assert( p->openFlags & (SQLITE_OPEN_MAIN_DB|SQLITE_OPEN_TEMP_DB) || p->openFlags & (SQLITE_OPEN_TRANSIENT_DB|SQLITE_OPEN_TEMP_JOURNAL) ); - if( op==SQLITE_FCNTL_OTA ){ - sqlite3ota *pOta = (sqlite3ota*)pArg; + if( op==SQLITE_FCNTL_RBU ){ + sqlite3rbu *pRbu = (sqlite3rbu*)pArg; - /* First try to find another OTA vfs lower down in the vfs stack. If + /* First try to find another RBU vfs lower down in the vfs stack. If ** one is found, this vfs will operate in pass-through mode. The lower - ** level vfs will do the special OTA handling. */ + ** level vfs will do the special RBU handling. */ rc = xControl(p->pReal, op, pArg); if( rc==SQLITE_NOTFOUND ){ @@ -3138,11 +3138,11 @@ static int otaVfsFileControl(sqlite3_file *pFile, int op, void *pArg){ rc = xControl(p->pReal, SQLITE_FCNTL_ZIPVFS, &dummy); if( rc==SQLITE_OK ){ rc = SQLITE_ERROR; - pOta->zErrmsg = sqlite3_mprintf("ota/zipvfs setup error"); + pRbu->zErrmsg = sqlite3_mprintf("rbu/zipvfs setup error"); }else if( rc==SQLITE_NOTFOUND ){ - pOta->pTargetFd = p; - p->pOta = pOta; - if( p->pWalFd ) p->pWalFd->pOta = pOta; + pRbu->pTargetFd = p; + p->pRbu = pRbu; + if( p->pWalFd ) p->pWalFd->pRbu = pRbu; rc = SQLITE_OK; } } @@ -3151,9 +3151,9 @@ static int otaVfsFileControl(sqlite3_file *pFile, int op, void *pArg){ rc = xControl(p->pReal, op, pArg); if( rc==SQLITE_OK && op==SQLITE_FCNTL_VFSNAME ){ - ota_vfs *pOtaVfs = p->pOtaVfs; + rbu_vfs *pRbuVfs = p->pRbuVfs; char *zIn = *(char**)pArg; - char *zOut = sqlite3_mprintf("ota(%s)/%z", pOtaVfs->base.zName, zIn); + char *zOut = sqlite3_mprintf("rbu(%s)/%z", pRbuVfs->base.zName, zIn); *(char**)pArg = zOut; if( zOut==0 ) rc = SQLITE_NOMEM; } @@ -3162,27 +3162,27 @@ static int otaVfsFileControl(sqlite3_file *pFile, int op, void *pArg){ } /* -** Return the sector-size in bytes for an otaVfs-file. +** Return the sector-size in bytes for an rbuVfs-file. */ -static int otaVfsSectorSize(sqlite3_file *pFile){ - ota_file *p = (ota_file *)pFile; +static int rbuVfsSectorSize(sqlite3_file *pFile){ + rbu_file *p = (rbu_file *)pFile; return p->pReal->pMethods->xSectorSize(p->pReal); } /* -** Return the device characteristic flags supported by an otaVfs-file. +** Return the device characteristic flags supported by an rbuVfs-file. */ -static int otaVfsDeviceCharacteristics(sqlite3_file *pFile){ - ota_file *p = (ota_file *)pFile; +static int rbuVfsDeviceCharacteristics(sqlite3_file *pFile){ + rbu_file *p = (rbu_file *)pFile; return p->pReal->pMethods->xDeviceCharacteristics(p->pReal); } /* ** Take or release a shared-memory lock. */ -static int otaVfsShmLock(sqlite3_file *pFile, int ofst, int n, int flags){ - ota_file *p = (ota_file*)pFile; - sqlite3ota *pOta = p->pOta; +static int rbuVfsShmLock(sqlite3_file *pFile, int ofst, int n, int flags){ + rbu_file *p = (rbu_file*)pFile; + sqlite3rbu *pRbu = p->pRbu; int rc = SQLITE_OK; #ifdef SQLITE_AMALGAMATION @@ -3190,7 +3190,7 @@ static int otaVfsShmLock(sqlite3_file *pFile, int ofst, int n, int flags){ #endif assert( p->openFlags & (SQLITE_OPEN_MAIN_DB|SQLITE_OPEN_TEMP_DB) ); - if( pOta && (pOta->eStage==OTA_STAGE_OAL || pOta->eStage==OTA_STAGE_MOVE) ){ + if( pRbu && (pRbu->eStage==RBU_STAGE_OAL || pRbu->eStage==RBU_STAGE_MOVE) ){ /* 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 @@ -3199,7 +3199,7 @@ static int otaVfsShmLock(sqlite3_file *pFile, int ofst, int n, int flags){ }else{ int bCapture = 0; if( n==1 && (flags & SQLITE_SHM_EXCLUSIVE) - && pOta && pOta->eStage==OTA_STAGE_CAPTURE + && pRbu && pRbu->eStage==RBU_STAGE_CAPTURE && (ofst==WAL_LOCK_WRITE || ofst==WAL_LOCK_CKPT || ofst==WAL_LOCK_READ0) ){ bCapture = 1; @@ -3208,7 +3208,7 @@ static int otaVfsShmLock(sqlite3_file *pFile, int ofst, int n, int flags){ if( bCapture==0 || 0==(flags & SQLITE_SHM_UNLOCK) ){ rc = p->pReal->pMethods->xShmLock(p->pReal, ofst, n, flags); if( bCapture && rc==SQLITE_OK ){ - pOta->mLock |= (1 << ofst); + pRbu->mLock |= (1 << ofst); } } } @@ -3219,22 +3219,22 @@ static int otaVfsShmLock(sqlite3_file *pFile, int ofst, int n, int flags){ /* ** Obtain a pointer to a mapping of a single 32KiB page of the *-shm file. */ -static int otaVfsShmMap( +static int rbuVfsShmMap( sqlite3_file *pFile, int iRegion, int szRegion, int isWrite, void volatile **pp ){ - ota_file *p = (ota_file*)pFile; + rbu_file *p = (rbu_file*)pFile; int rc = SQLITE_OK; - int eStage = (p->pOta ? p->pOta->eStage : 0); + int eStage = (p->pRbu ? p->pRbu->eStage : 0); - /* If not in OTA_STAGE_OAL, allow this call to pass through. Or, if this - ** ota is in the OTA_STAGE_OAL state, use heap memory for *-shm space + /* If not in RBU_STAGE_OAL, allow this call to pass through. Or, if this + ** rbu is in the RBU_STAGE_OAL state, use heap memory for *-shm space ** instead of a file on disk. */ assert( p->openFlags & (SQLITE_OPEN_MAIN_DB|SQLITE_OPEN_TEMP_DB) ); - if( eStage==OTA_STAGE_OAL || eStage==OTA_STAGE_MOVE ){ + if( eStage==RBU_STAGE_OAL || eStage==RBU_STAGE_MOVE ){ if( iRegion<=p->nShm ){ int nByte = (iRegion+1) * sizeof(char*); char **apNew = (char**)sqlite3_realloc(p->apShm, nByte); @@ -3273,25 +3273,25 @@ static int otaVfsShmMap( /* ** Memory barrier. */ -static void otaVfsShmBarrier(sqlite3_file *pFile){ - ota_file *p = (ota_file *)pFile; +static void rbuVfsShmBarrier(sqlite3_file *pFile){ + rbu_file *p = (rbu_file *)pFile; p->pReal->pMethods->xShmBarrier(p->pReal); } /* ** The xShmUnmap method. */ -static int otaVfsShmUnmap(sqlite3_file *pFile, int delFlag){ - ota_file *p = (ota_file*)pFile; +static int rbuVfsShmUnmap(sqlite3_file *pFile, int delFlag){ + rbu_file *p = (rbu_file*)pFile; int rc = SQLITE_OK; - int eStage = (p->pOta ? p->pOta->eStage : 0); + int eStage = (p->pRbu ? p->pRbu->eStage : 0); assert( p->openFlags & (SQLITE_OPEN_MAIN_DB|SQLITE_OPEN_TEMP_DB) ); - if( eStage==OTA_STAGE_OAL || eStage==OTA_STAGE_MOVE ){ + if( eStage==RBU_STAGE_OAL || eStage==RBU_STAGE_MOVE ){ /* no-op */ }else{ /* Release the checkpointer and writer locks */ - otaUnlockShm(p); + rbuUnlockShm(p); rc = p->pReal->pMethods->xShmUnmap(p->pReal, delFlag); } return rc; @@ -3303,52 +3303,52 @@ static int otaVfsShmUnmap(sqlite3_file *pFile, int delFlag){ ** file-handle opened by the same database connection on the corresponding ** database file. */ -static ota_file *otaFindMaindb(ota_vfs *pOtaVfs, const char *zWal){ - ota_file *pDb; - sqlite3_mutex_enter(pOtaVfs->mutex); - for(pDb=pOtaVfs->pMain; pDb && pDb->zWal!=zWal; pDb=pDb->pMainNext); - sqlite3_mutex_leave(pOtaVfs->mutex); +static rbu_file *rbuFindMaindb(rbu_vfs *pRbuVfs, const char *zWal){ + rbu_file *pDb; + sqlite3_mutex_enter(pRbuVfs->mutex); + for(pDb=pRbuVfs->pMain; pDb && pDb->zWal!=zWal; pDb=pDb->pMainNext); + sqlite3_mutex_leave(pRbuVfs->mutex); return pDb; } /* -** Open an ota file handle. +** Open an rbu file handle. */ -static int otaVfsOpen( +static int rbuVfsOpen( sqlite3_vfs *pVfs, const char *zName, sqlite3_file *pFile, int flags, int *pOutFlags ){ - static sqlite3_io_methods otavfs_io_methods = { + static sqlite3_io_methods rbuvfs_io_methods = { 2, /* iVersion */ - otaVfsClose, /* xClose */ - otaVfsRead, /* xRead */ - otaVfsWrite, /* xWrite */ - otaVfsTruncate, /* xTruncate */ - otaVfsSync, /* xSync */ - otaVfsFileSize, /* xFileSize */ - otaVfsLock, /* xLock */ - otaVfsUnlock, /* xUnlock */ - otaVfsCheckReservedLock, /* xCheckReservedLock */ - otaVfsFileControl, /* xFileControl */ - otaVfsSectorSize, /* xSectorSize */ - otaVfsDeviceCharacteristics, /* xDeviceCharacteristics */ - otaVfsShmMap, /* xShmMap */ - otaVfsShmLock, /* xShmLock */ - otaVfsShmBarrier, /* xShmBarrier */ - otaVfsShmUnmap /* xShmUnmap */ + rbuVfsClose, /* xClose */ + rbuVfsRead, /* xRead */ + rbuVfsWrite, /* xWrite */ + rbuVfsTruncate, /* xTruncate */ + rbuVfsSync, /* xSync */ + rbuVfsFileSize, /* xFileSize */ + rbuVfsLock, /* xLock */ + rbuVfsUnlock, /* xUnlock */ + rbuVfsCheckReservedLock, /* xCheckReservedLock */ + rbuVfsFileControl, /* xFileControl */ + rbuVfsSectorSize, /* xSectorSize */ + rbuVfsDeviceCharacteristics, /* xDeviceCharacteristics */ + rbuVfsShmMap, /* xShmMap */ + rbuVfsShmLock, /* xShmLock */ + rbuVfsShmBarrier, /* xShmBarrier */ + rbuVfsShmUnmap /* xShmUnmap */ }; - ota_vfs *pOtaVfs = (ota_vfs*)pVfs; - sqlite3_vfs *pRealVfs = pOtaVfs->pRealVfs; - ota_file *pFd = (ota_file *)pFile; + rbu_vfs *pRbuVfs = (rbu_vfs*)pVfs; + sqlite3_vfs *pRealVfs = pRbuVfs->pRealVfs; + rbu_file *pFd = (rbu_file *)pFile; int rc = SQLITE_OK; const char *zOpen = zName; - memset(pFd, 0, sizeof(ota_file)); + memset(pFd, 0, sizeof(rbu_file)); pFd->pReal = (sqlite3_file*)&pFd[1]; - pFd->pOtaVfs = pOtaVfs; + pFd->pRbuVfs = pRbuVfs; pFd->openFlags = flags; if( zName ){ if( flags & SQLITE_OPEN_MAIN_DB ){ @@ -3376,9 +3376,9 @@ static int otaVfsOpen( pFd->zWal = z; } else if( flags & SQLITE_OPEN_WAL ){ - ota_file *pDb = otaFindMaindb(pOtaVfs, zName); + rbu_file *pDb = rbuFindMaindb(pRbuVfs, zName); if( pDb ){ - if( pDb->pOta && pDb->pOta->eStage==OTA_STAGE_OAL ){ + if( pDb->pRbu && pDb->pRbu->eStage==RBU_STAGE_OAL ){ /* This call is to open a *-wal file. Intead, open the *-oal. This ** code ensures that the string passed to xOpen() is terminated by a ** pair of '\0' bytes in case the VFS attempts to extract a URI @@ -3394,7 +3394,7 @@ static int otaVfsOpen( }else{ rc = SQLITE_NOMEM; } - pFd->pOta = pDb->pOta; + pFd->pRbu = pDb->pRbu; } pDb->pWalFd = pFd; } @@ -3408,12 +3408,12 @@ static int otaVfsOpen( /* The xOpen() operation has succeeded. Set the sqlite3_file.pMethods ** pointer and, if the file is a main database file, link it into the ** mutex protected linked list of all such files. */ - pFile->pMethods = &otavfs_io_methods; + pFile->pMethods = &rbuvfs_io_methods; if( flags & SQLITE_OPEN_MAIN_DB ){ - sqlite3_mutex_enter(pOtaVfs->mutex); - pFd->pMainNext = pOtaVfs->pMain; - pOtaVfs->pMain = pFd; - sqlite3_mutex_leave(pOtaVfs->mutex); + sqlite3_mutex_enter(pRbuVfs->mutex); + pFd->pMainNext = pRbuVfs->pMain; + pRbuVfs->pMain = pFd; + sqlite3_mutex_leave(pRbuVfs->mutex); } }else{ sqlite3_free(pFd->zDel); @@ -3425,8 +3425,8 @@ static int otaVfsOpen( /* ** Delete the file located at zPath. */ -static int otaVfsDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){ - sqlite3_vfs *pRealVfs = ((ota_vfs*)pVfs)->pRealVfs; +static int rbuVfsDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){ + sqlite3_vfs *pRealVfs = ((rbu_vfs*)pVfs)->pRealVfs; return pRealVfs->xDelete(pRealVfs, zPath, dirSync); } @@ -3434,35 +3434,35 @@ static int otaVfsDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){ ** Test for access permissions. Return true if the requested permission ** is available, or false otherwise. */ -static int otaVfsAccess( +static int rbuVfsAccess( sqlite3_vfs *pVfs, const char *zPath, int flags, int *pResOut ){ - ota_vfs *pOtaVfs = (ota_vfs*)pVfs; - sqlite3_vfs *pRealVfs = pOtaVfs->pRealVfs; + rbu_vfs *pRbuVfs = (rbu_vfs*)pVfs; + sqlite3_vfs *pRealVfs = pRbuVfs->pRealVfs; int rc; rc = pRealVfs->xAccess(pRealVfs, zPath, flags, pResOut); - /* If this call is to check if a *-wal file associated with an OTA target - ** database connection exists, and the OTA update is in OTA_STAGE_OAL, + /* If this call is to check if a *-wal file associated with an RBU target + ** database connection exists, and the RBU update is in RBU_STAGE_OAL, ** the following special handling is activated: ** ** a) if the *-wal file does exist, return SQLITE_CANTOPEN. This - ** ensures that the OTA extension never tries to update a database + ** ensures that the RBU extension never tries to update a database ** in wal mode, even if the first page of the database file has ** been damaged. ** ** b) if the *-wal file does not exist, claim that it does anyway, ** causing SQLite to call xOpen() to open it. This call will also - ** be intercepted (see the otaVfsOpen() function) and the *-oal + ** be intercepted (see the rbuVfsOpen() function) and the *-oal ** file opened instead. */ if( rc==SQLITE_OK && flags==SQLITE_ACCESS_EXISTS ){ - ota_file *pDb = otaFindMaindb(pOtaVfs, zPath); - if( pDb && pDb->pOta && pDb->pOta->eStage==OTA_STAGE_OAL ){ + rbu_file *pDb = rbuFindMaindb(pRbuVfs, zPath); + if( pDb && pDb->pRbu && pDb->pRbu->eStage==RBU_STAGE_OAL ){ if( *pResOut ){ rc = SQLITE_CANTOPEN; }else{ @@ -3479,13 +3479,13 @@ static int otaVfsAccess( ** to the pathname in zPath. zOut is guaranteed to point to a buffer ** of at least (DEVSYM_MAX_PATHNAME+1) bytes. */ -static int otaVfsFullPathname( +static int rbuVfsFullPathname( sqlite3_vfs *pVfs, const char *zPath, int nOut, char *zOut ){ - sqlite3_vfs *pRealVfs = ((ota_vfs*)pVfs)->pRealVfs; + sqlite3_vfs *pRealVfs = ((rbu_vfs*)pVfs)->pRealVfs; return pRealVfs->xFullPathname(pRealVfs, zPath, nOut, zOut); } @@ -3493,8 +3493,8 @@ static int otaVfsFullPathname( /* ** Open the dynamic library located at zPath and return a handle. */ -static void *otaVfsDlOpen(sqlite3_vfs *pVfs, const char *zPath){ - sqlite3_vfs *pRealVfs = ((ota_vfs*)pVfs)->pRealVfs; +static void *rbuVfsDlOpen(sqlite3_vfs *pVfs, const char *zPath){ + sqlite3_vfs *pRealVfs = ((rbu_vfs*)pVfs)->pRealVfs; return pRealVfs->xDlOpen(pRealVfs, zPath); } @@ -3503,28 +3503,28 @@ static void *otaVfsDlOpen(sqlite3_vfs *pVfs, const char *zPath){ ** utf-8 string describing the most recent error encountered associated ** with dynamic libraries. */ -static void otaVfsDlError(sqlite3_vfs *pVfs, int nByte, char *zErrMsg){ - sqlite3_vfs *pRealVfs = ((ota_vfs*)pVfs)->pRealVfs; +static void rbuVfsDlError(sqlite3_vfs *pVfs, int nByte, char *zErrMsg){ + sqlite3_vfs *pRealVfs = ((rbu_vfs*)pVfs)->pRealVfs; pRealVfs->xDlError(pRealVfs, nByte, zErrMsg); } /* ** Return a pointer to the symbol zSymbol in the dynamic library pHandle. */ -static void (*otaVfsDlSym( +static void (*rbuVfsDlSym( sqlite3_vfs *pVfs, void *pArg, const char *zSym ))(void){ - sqlite3_vfs *pRealVfs = ((ota_vfs*)pVfs)->pRealVfs; + sqlite3_vfs *pRealVfs = ((rbu_vfs*)pVfs)->pRealVfs; return pRealVfs->xDlSym(pRealVfs, pArg, zSym); } /* ** Close the dynamic library handle pHandle. */ -static void otaVfsDlClose(sqlite3_vfs *pVfs, void *pHandle){ - sqlite3_vfs *pRealVfs = ((ota_vfs*)pVfs)->pRealVfs; +static void rbuVfsDlClose(sqlite3_vfs *pVfs, void *pHandle){ + sqlite3_vfs *pRealVfs = ((rbu_vfs*)pVfs)->pRealVfs; return pRealVfs->xDlClose(pRealVfs, pHandle); } #endif /* SQLITE_OMIT_LOAD_EXTENSION */ @@ -3533,8 +3533,8 @@ static void otaVfsDlClose(sqlite3_vfs *pVfs, void *pHandle){ ** Populate the buffer pointed to by zBufOut with nByte bytes of ** random data. */ -static int otaVfsRandomness(sqlite3_vfs *pVfs, int nByte, char *zBufOut){ - sqlite3_vfs *pRealVfs = ((ota_vfs*)pVfs)->pRealVfs; +static int rbuVfsRandomness(sqlite3_vfs *pVfs, int nByte, char *zBufOut){ + sqlite3_vfs *pRealVfs = ((rbu_vfs*)pVfs)->pRealVfs; return pRealVfs->xRandomness(pRealVfs, nByte, zBufOut); } @@ -3542,45 +3542,45 @@ static int otaVfsRandomness(sqlite3_vfs *pVfs, int nByte, char *zBufOut){ ** Sleep for nMicro microseconds. Return the number of microseconds ** actually slept. */ -static int otaVfsSleep(sqlite3_vfs *pVfs, int nMicro){ - sqlite3_vfs *pRealVfs = ((ota_vfs*)pVfs)->pRealVfs; +static int rbuVfsSleep(sqlite3_vfs *pVfs, int nMicro){ + sqlite3_vfs *pRealVfs = ((rbu_vfs*)pVfs)->pRealVfs; return pRealVfs->xSleep(pRealVfs, nMicro); } /* ** Return the current time as a Julian Day number in *pTimeOut. */ -static int otaVfsCurrentTime(sqlite3_vfs *pVfs, double *pTimeOut){ - sqlite3_vfs *pRealVfs = ((ota_vfs*)pVfs)->pRealVfs; +static int rbuVfsCurrentTime(sqlite3_vfs *pVfs, double *pTimeOut){ + sqlite3_vfs *pRealVfs = ((rbu_vfs*)pVfs)->pRealVfs; return pRealVfs->xCurrentTime(pRealVfs, pTimeOut); } /* ** No-op. */ -static int otaVfsGetLastError(sqlite3_vfs *pVfs, int a, char *b){ +static int rbuVfsGetLastError(sqlite3_vfs *pVfs, int a, char *b){ return 0; } /* -** Deregister and destroy an OTA vfs created by an earlier call to -** sqlite3ota_create_vfs(). +** Deregister and destroy an RBU vfs created by an earlier call to +** sqlite3rbu_create_vfs(). */ -void sqlite3ota_destroy_vfs(const char *zName){ +void sqlite3rbu_destroy_vfs(const char *zName){ sqlite3_vfs *pVfs = sqlite3_vfs_find(zName); - if( pVfs && pVfs->xOpen==otaVfsOpen ){ - sqlite3_mutex_free(((ota_vfs*)pVfs)->mutex); + if( pVfs && pVfs->xOpen==rbuVfsOpen ){ + sqlite3_mutex_free(((rbu_vfs*)pVfs)->mutex); sqlite3_vfs_unregister(pVfs); sqlite3_free(pVfs); } } /* -** Create an OTA VFS named zName that accesses the underlying file-system +** Create an RBU VFS named zName that accesses the underlying file-system ** via existing VFS zParent. The new object is registered as a non-default ** VFS with SQLite before returning. */ -int sqlite3ota_create_vfs(const char *zName, const char *zParent){ +int sqlite3rbu_create_vfs(const char *zName, const char *zParent){ /* Template for VFS */ static sqlite3_vfs vfs_template = { @@ -3590,36 +3590,36 @@ int sqlite3ota_create_vfs(const char *zName, const char *zParent){ 0, /* pNext */ 0, /* zName */ 0, /* pAppData */ - otaVfsOpen, /* xOpen */ - otaVfsDelete, /* xDelete */ - otaVfsAccess, /* xAccess */ - otaVfsFullPathname, /* xFullPathname */ + rbuVfsOpen, /* xOpen */ + rbuVfsDelete, /* xDelete */ + rbuVfsAccess, /* xAccess */ + rbuVfsFullPathname, /* xFullPathname */ #ifndef SQLITE_OMIT_LOAD_EXTENSION - otaVfsDlOpen, /* xDlOpen */ - otaVfsDlError, /* xDlError */ - otaVfsDlSym, /* xDlSym */ - otaVfsDlClose, /* xDlClose */ + rbuVfsDlOpen, /* xDlOpen */ + rbuVfsDlError, /* xDlError */ + rbuVfsDlSym, /* xDlSym */ + rbuVfsDlClose, /* xDlClose */ #else 0, 0, 0, 0, #endif - otaVfsRandomness, /* xRandomness */ - otaVfsSleep, /* xSleep */ - otaVfsCurrentTime, /* xCurrentTime */ - otaVfsGetLastError, /* xGetLastError */ + rbuVfsRandomness, /* xRandomness */ + rbuVfsSleep, /* xSleep */ + rbuVfsCurrentTime, /* xCurrentTime */ + rbuVfsGetLastError, /* xGetLastError */ 0, /* xCurrentTimeInt64 (version 2) */ 0, 0, 0 /* Unimplemented version 3 methods */ }; - ota_vfs *pNew = 0; /* Newly allocated VFS */ + rbu_vfs *pNew = 0; /* Newly allocated VFS */ int nName; int rc = SQLITE_OK; int nByte; nName = strlen(zName); - nByte = sizeof(ota_vfs) + nName + 1; - pNew = (ota_vfs*)sqlite3_malloc(nByte); + nByte = sizeof(rbu_vfs) + nName + 1; + pNew = (rbu_vfs*)sqlite3_malloc(nByte); if( pNew==0 ){ rc = SQLITE_NOMEM; }else{ @@ -3632,7 +3632,7 @@ int sqlite3ota_create_vfs(const char *zName, const char *zParent){ char *zSpace; memcpy(&pNew->base, &vfs_template, sizeof(sqlite3_vfs)); pNew->base.mxPathname = pParent->mxPathname; - pNew->base.szOsFile = sizeof(ota_file) + pParent->szOsFile; + pNew->base.szOsFile = sizeof(rbu_file) + pParent->szOsFile; pNew->pRealVfs = pParent; pNew->base.zName = (const char*)(zSpace = (char*)&pNew[1]); memcpy(zSpace, zName, nName); @@ -3658,4 +3658,4 @@ int sqlite3ota_create_vfs(const char *zName, const char *zParent){ /**************************************************************************/ -#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_OTA) */ +#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_RBU) */ diff --git a/ext/ota/sqlite3ota.h b/ext/rbu/sqlite3rbu.h index a255611ea..bc1f74fb2 100644 --- a/ext/ota/sqlite3ota.h +++ b/ext/rbu/sqlite3rbu.h @@ -10,7 +10,7 @@ ** ************************************************************************* ** -** This file contains the public interface for the OTA extension. +** This file contains the public interface for the RBU extension. */ /* @@ -47,14 +47,14 @@ ** to read from the original database snapshot. In other words, partially ** applied transactions are not visible to other clients. ** -** "OTA" stands for "Over The Air" update. As in a large database update +** "RBU" stands for "Over The Air" update. As in a large database update ** transmitted via a wireless network to a mobile device. A transaction -** applied using this extension is hence refered to as an "OTA update". +** applied using this extension is hence refered to as an "RBU update". ** ** ** LIMITATIONS ** -** An "OTA update" transaction is subject to the following limitations: +** An "RBU update" transaction is subject to the following limitations: ** ** * The transaction must consist of INSERT, UPDATE and DELETE operations ** only. @@ -79,41 +79,41 @@ ** ** PREPARATION ** -** An "OTA update" is stored as a separate SQLite database. A database -** containing an OTA update is an "OTA database". For each table in the -** target database to be updated, the OTA database should contain a table +** An "RBU update" is stored as a separate SQLite database. A database +** containing an RBU update is an "RBU database". For each table in the +** target database to be updated, the RBU database should contain a table ** named "data_<target name>" containing the same set of columns as the -** target table, and one more - "ota_control". The data_% table should +** target table, and one more - "rbu_control". The data_% table should ** have no PRIMARY KEY or UNIQUE constraints, but each column should have ** the same type as the corresponding column in the target database. -** The "ota_control" column should have no type at all. For example, if +** The "rbu_control" column should have no type at all. For example, if ** the target database contains: ** ** CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT, c UNIQUE); ** -** Then the OTA database should contain: +** Then the RBU database should contain: ** -** CREATE TABLE data_t1(a INTEGER, b TEXT, c, ota_control); +** CREATE TABLE data_t1(a INTEGER, b TEXT, c, rbu_control); ** ** The order of the columns in the data_% table does not matter. ** ** If the target database table is a virtual table or a table that has no ** PRIMARY KEY declaration, the data_% table must also contain a column -** named "ota_rowid". This column is mapped to the tables implicit primary +** named "rbu_rowid". This column is mapped to the tables implicit primary ** key column - "rowid". Virtual tables for which the "rowid" column does -** not function like a primary key value cannot be updated using OTA. For +** not function like a primary key value cannot be updated using RBU. For ** example, if the target db contains either of the following: ** ** CREATE VIRTUAL TABLE x1 USING fts3(a, b); ** CREATE TABLE x1(a, b) ** -** then the OTA database should contain: +** then the RBU database should contain: ** -** CREATE TABLE data_x1(a, b, ota_rowid, ota_control); +** CREATE TABLE data_x1(a, b, rbu_rowid, rbu_control); ** ** All non-hidden columns (i.e. all columns matched by "SELECT *") of the ** target table must be present in the input table. For virtual tables, -** hidden columns are optional - they are updated by OTA if present in +** hidden columns are optional - they are updated by RBU if present in ** the input table, or not otherwise. For example, to write to an fts4 ** table with a hidden languageid column such as: ** @@ -121,12 +121,12 @@ ** ** Either of the following input table schemas may be used: ** -** CREATE TABLE data_ft1(a, b, langid, ota_rowid, ota_control); -** CREATE TABLE data_ft1(a, b, ota_rowid, ota_control); +** CREATE TABLE data_ft1(a, b, langid, rbu_rowid, rbu_control); +** CREATE TABLE data_ft1(a, b, rbu_rowid, rbu_control); ** -** For each row to INSERT into the target database as part of the OTA +** For each row to INSERT into the target database as part of the RBU ** update, the corresponding data_% table should contain a single record -** with the "ota_control" column set to contain integer value 0. The +** with the "rbu_control" column set to contain integer value 0. The ** other columns should be set to the values that make up the new record ** to insert. ** @@ -134,54 +134,54 @@ ** possible to insert a NULL value into the IPK column. Attempting to ** do so results in an SQLITE_MISMATCH error. ** -** For each row to DELETE from the target database as part of the OTA +** For each row to DELETE from the target database as part of the RBU ** update, the corresponding data_% table should contain a single record -** with the "ota_control" column set to contain integer value 1. The +** with the "rbu_control" column set to contain integer value 1. The ** real primary key values of the row to delete should be stored in the ** corresponding columns of the data_% table. The values stored in the ** other columns are not used. ** -** For each row to UPDATE from the target database as part of the OTA +** For each row to UPDATE from the target database as part of the RBU ** update, the corresponding data_% table should contain a single record -** with the "ota_control" column set to contain a value of type text. +** with the "rbu_control" column set to contain a value of type text. ** The real primary key values identifying the row to update should be ** stored in the corresponding columns of the data_% table row, as should ** the new values of all columns being update. The text value in the -** "ota_control" column must contain the same number of characters as +** "rbu_control" column must contain the same number of characters as ** there are columns in the target database table, and must consist entirely ** of 'x' and '.' characters (or in some special cases 'd' - see below). For ** each column that is being updated, the corresponding character is set to ** 'x'. For those that remain as they are, the corresponding character of the -** ota_control value should be set to '.'. For example, given the tables +** rbu_control value should be set to '.'. For example, given the tables ** above, the update statement: ** ** UPDATE t1 SET c = 'usa' WHERE a = 4; ** ** is represented by the data_t1 row created by: ** -** INSERT INTO data_t1(a, b, c, ota_control) VALUES(4, NULL, 'usa', '..x'); +** INSERT INTO data_t1(a, b, c, rbu_control) VALUES(4, NULL, 'usa', '..x'); ** -** Instead of an 'x' character, characters of the ota_control value specified +** Instead of an 'x' character, characters of the rbu_control value specified ** for UPDATEs may also be set to 'd'. In this case, instead of updating the ** target table with the value stored in the corresponding data_% column, the -** user-defined SQL function "ota_delta()" is invoked and the result stored in -** the target table column. ota_delta() is invoked with two arguments - the +** user-defined SQL function "rbu_delta()" is invoked and the result stored in +** the target table column. rbu_delta() is invoked with two arguments - the ** original value currently stored in the target table column and the ** value specified in the data_xxx table. ** ** For example, this row: ** -** INSERT INTO data_t1(a, b, c, ota_control) VALUES(4, NULL, 'usa', '..d'); +** INSERT INTO data_t1(a, b, c, rbu_control) VALUES(4, NULL, 'usa', '..d'); ** ** is similar to an UPDATE statement such as: ** -** UPDATE t1 SET c = ota_delta(c, 'usa') WHERE a = 4; +** UPDATE t1 SET c = rbu_delta(c, 'usa') WHERE a = 4; ** ** If the target database table is a virtual table or a table with no PRIMARY -** KEY, the ota_control value should not include a character corresponding -** to the ota_rowid value. For example, this: +** KEY, the rbu_control value should not include a character corresponding +** to the rbu_rowid value. For example, this: ** -** INSERT INTO data_ft1(a, b, ota_rowid, ota_control) +** INSERT INTO data_ft1(a, b, rbu_rowid, rbu_control) ** VALUES(NULL, 'usa', 12, '.x'); ** ** causes a result similar to: @@ -189,7 +189,7 @@ ** UPDATE ft1 SET b = 'usa' WHERE rowid = 12; ** ** The data_xxx tables themselves should have no PRIMARY KEY declarations. -** However, OTA is more efficient if reading the rows in from each data_xxx +** However, RBU is more efficient if reading the rows in from each data_xxx ** table in "rowid" order is roughly the same as reading them sorted by ** the PRIMARY KEY of the corresponding target database table. In other ** words, rows should be sorted using the destination table PRIMARY KEY @@ -197,107 +197,107 @@ ** ** USAGE ** -** The API declared below allows an application to apply an OTA update +** The API declared below allows an application to apply an RBU update ** stored on disk to an existing target database. Essentially, the ** application: ** -** 1) Opens an OTA handle using the sqlite3ota_open() function. +** 1) Opens an RBU handle using the sqlite3rbu_open() function. ** ** 2) Registers any required virtual table modules with the database -** handle returned by sqlite3ota_db(). Also, if required, register -** the ota_delta() implementation. +** handle returned by sqlite3rbu_db(). Also, if required, register +** the rbu_delta() implementation. ** -** 3) Calls the sqlite3ota_step() function one or more times on -** the new handle. Each call to sqlite3ota_step() performs a single +** 3) Calls the sqlite3rbu_step() function one or more times on +** the new handle. Each call to sqlite3rbu_step() performs a single ** b-tree operation, so thousands of calls may be required to apply ** a complete update. ** -** 4) Calls sqlite3ota_close() to close the OTA update handle. If -** sqlite3ota_step() has been called enough times to completely -** apply the update to the target database, then the OTA database -** is marked as fully applied. Otherwise, the state of the OTA -** update application is saved in the OTA database for later +** 4) Calls sqlite3rbu_close() to close the RBU update handle. If +** sqlite3rbu_step() has been called enough times to completely +** apply the update to the target database, then the RBU database +** is marked as fully applied. Otherwise, the state of the RBU +** update application is saved in the RBU database for later ** resumption. ** ** See comments below for more detail on APIs. ** ** If an update is only partially applied to the target database by the -** time sqlite3ota_close() is called, various state information is saved -** within the OTA database. This allows subsequent processes to automatically -** resume the OTA update from where it left off. +** time sqlite3rbu_close() is called, various state information is saved +** within the RBU database. This allows subsequent processes to automatically +** resume the RBU update from where it left off. ** -** To remove all OTA extension state information, returning an OTA database +** To remove all RBU extension state information, returning an RBU database ** to its original contents, it is sufficient to drop all tables that begin -** with the prefix "ota_" +** with the prefix "rbu_" ** ** DATABASE LOCKING ** -** An OTA update may not be applied to a database in WAL mode. Attempting +** An RBU update may not be applied to a database in WAL mode. Attempting ** to do so is an error (SQLITE_ERROR). ** -** While an OTA handle is open, a SHARED lock may be held on the target +** While an RBU handle is open, a SHARED lock may be held on the target ** database file. This means it is possible for other clients to read the ** database, but not to write it. ** -** If an OTA update is started and then suspended before it is completed, +** If an RBU update is started and then suspended before it is completed, ** then an external client writes to the database, then attempting to resume -** the suspended OTA update is also an error (SQLITE_BUSY). +** the suspended RBU update is also an error (SQLITE_BUSY). */ -#ifndef _SQLITE3OTA_H -#define _SQLITE3OTA_H +#ifndef _SQLITE3RBU_H +#define _SQLITE3RBU_H #include "sqlite3.h" /* Required for error code definitions */ -typedef struct sqlite3ota sqlite3ota; +typedef struct sqlite3rbu sqlite3rbu; /* -** Open an OTA handle. +** Open an RBU handle. ** -** Argument zTarget is the path to the target database. Argument zOta is -** the path to the OTA database. Each call to this function must be matched -** by a call to sqlite3ota_close(). When opening the databases, OTA passes +** Argument zTarget is the path to the target database. Argument zRbu is +** the path to the RBU database. Each call to this function must be matched +** by a call to sqlite3rbu_close(). When opening the databases, RBU passes ** the SQLITE_CONFIG_URI flag to sqlite3_open_v2(). So if either zTarget -** or zOta begin with "file:", it will be interpreted as an SQLite +** or zRbu begin with "file:", it will be interpreted as an SQLite ** database URI, not a regular file name. ** -** If the zState argument is passed a NULL value, the OTA extension stores +** If the zState argument is passed a NULL value, the RBU extension stores ** the current state of the update (how many rows have been updated, which -** indexes are yet to be updated etc.) within the OTA database itself. This -** can be convenient, as it means that the OTA application does not need to +** indexes are yet to be updated etc.) within the RBU database itself. This +** can be convenient, as it means that the RBU application does not need to ** organize removing a separate state file after the update is concluded. ** Or, if zState is non-NULL, it must be a path to a database file in which -** the OTA extension can store the state of the update. +** the RBU extension can store the state of the update. ** -** When resuming an OTA update, the zState argument must be passed the same -** value as when the OTA update was started. +** When resuming an RBU update, the zState argument must be passed the same +** value as when the RBU update was started. ** -** Once the OTA update is finished, the OTA extension does not +** Once the RBU update is finished, the RBU extension does not ** automatically remove any zState database file, even if it created it. ** -** By default, OTA uses the default VFS to access the files on disk. To +** By default, RBU uses the default VFS to access the files on disk. To ** use a VFS other than the default, an SQLite "file:" URI containing a ** "vfs=..." option may be passed as the zTarget option. ** -** IMPORTANT NOTE FOR ZIPVFS USERS: The OTA extension works with all of +** IMPORTANT NOTE FOR ZIPVFS USERS: The RBU extension works with all of ** SQLite's built-in VFSs, including the multiplexor VFS. However it does ** not work out of the box with zipvfs. Refer to the comment describing -** the zipvfs_create_vfs() API below for details on using OTA with zipvfs. +** the zipvfs_create_vfs() API below for details on using RBU with zipvfs. */ -sqlite3ota *sqlite3ota_open( +sqlite3rbu *sqlite3rbu_open( const char *zTarget, - const char *zOta, + const char *zRbu, const char *zState ); /* -** Internally, each OTA connection uses a separate SQLite database -** connection to access the target and ota update databases. This +** Internally, each RBU connection uses a separate SQLite database +** connection to access the target and rbu update databases. This ** API allows the application direct access to these database handles. ** -** The first argument passed to this function must be a valid, open, OTA +** The first argument passed to this function must be a valid, open, RBU ** handle. The second argument should be passed zero to access the target -** database handle, or non-zero to access the ota update database handle. +** database handle, or non-zero to access the rbu update database handle. ** Accessing the underlying database handles may be useful in the ** following scenarios: ** @@ -305,44 +305,44 @@ sqlite3ota *sqlite3ota_open( ** call sqlite3_create_module() on the target database handle to ** register the required virtual table implementations. ** -** * If the data_xxx tables in the OTA source database are virtual +** * If the data_xxx tables in the RBU source database are virtual ** tables, the application may need to call sqlite3_create_module() on -** the ota update db handle to any required virtual table +** the rbu update db handle to any required virtual table ** implementations. ** -** * If the application uses the "ota_delta()" feature described above, +** * If the application uses the "rbu_delta()" feature described above, ** it must use sqlite3_create_function() or similar to register the -** ota_delta() implementation with the target database handle. +** rbu_delta() implementation with the target database handle. ** -** If an error has occurred, either while opening or stepping the OTA object, +** If an error has occurred, either while opening or stepping the RBU object, ** this function may return NULL. The error code and message may be collected -** when sqlite3ota_close() is called. +** when sqlite3rbu_close() is called. */ -sqlite3 *sqlite3ota_db(sqlite3ota*, int bOta); +sqlite3 *sqlite3rbu_db(sqlite3rbu*, int bRbu); /* -** Do some work towards applying the OTA update to the target db. +** Do some work towards applying the RBU update to the target db. ** ** Return SQLITE_DONE if the update has been completely applied, or ** SQLITE_OK if no error occurs but there remains work to do to apply -** the OTA update. If an error does occur, some other error code is +** the RBU update. If an error does occur, some other error code is ** returned. ** -** Once a call to sqlite3ota_step() has returned a value other than -** SQLITE_OK, all subsequent calls on the same OTA handle are no-ops +** Once a call to sqlite3rbu_step() has returned a value other than +** SQLITE_OK, all subsequent calls on the same RBU handle are no-ops ** that immediately return the same value. */ -int sqlite3ota_step(sqlite3ota *pOta); +int sqlite3rbu_step(sqlite3rbu *pRbu); /* -** Close an OTA handle. +** Close an RBU handle. ** -** If the OTA update has been completely applied, mark the OTA database +** If the RBU update has been completely applied, mark the RBU database ** as fully applied. Otherwise, assuming no error has occurred, save the -** current state of the OTA update appliation to the OTA database. +** current state of the RBU update appliation to the RBU database. ** -** If an error has already occurred as part of an sqlite3ota_step() -** or sqlite3ota_open() call, or if one occurs within this function, an +** If an error has already occurred as part of an sqlite3rbu_step() +** or sqlite3rbu_open() call, or if one occurs within this function, an ** SQLite error code is returned. Additionally, *pzErrmsg may be set to ** point to a buffer containing a utf-8 formatted English language error ** message. It is the responsibility of the caller to eventually free any @@ -352,68 +352,67 @@ int sqlite3ota_step(sqlite3ota *pOta); ** update has been partially applied, or SQLITE_DONE if it has been ** completely applied. */ -int sqlite3ota_close(sqlite3ota *pOta, char **pzErrmsg); +int sqlite3rbu_close(sqlite3rbu *pRbu, char **pzErrmsg); /* ** Return the total number of key-value operations (inserts, deletes or ** updates) that have been performed on the target database since the -** current OTA update was started. +** current RBU update was started. */ -sqlite3_int64 sqlite3ota_progress(sqlite3ota *pOta); +sqlite3_int64 sqlite3rbu_progress(sqlite3rbu *pRbu); /* -** Create an OTA VFS named zName that accesses the underlying file-system +** Create an RBU VFS named zName that accesses the underlying file-system ** via existing VFS zParent. Or, if the zParent parameter is passed NULL, -** then the new OTA VFS uses the default system VFS to access the file-system. +** then the new RBU VFS uses the default system VFS to access the file-system. ** The new object is registered as a non-default VFS with SQLite before ** returning. ** -** Part of the OTA implementation uses a custom VFS object. Usually, this -** object is created and deleted automatically by OTA. +** Part of the RBU implementation uses a custom VFS object. Usually, this +** object is created and deleted automatically by RBU. ** ** The exception is for applications that also use zipvfs. In this case, -** the custom VFS must be explicitly created by the user before the OTA -** handle is opened. The OTA VFS should be installed so that the zipvfs -** VFS uses the OTA VFS, which in turn uses any other VFS layers in use +** the custom VFS must be explicitly created by the user before the RBU +** handle is opened. The RBU VFS should be installed so that the zipvfs +** VFS uses the RBU VFS, which in turn uses any other VFS layers in use ** (for example multiplexor) to access the file-system. For example, -** to assemble an OTA enabled VFS stack that uses both zipvfs and +** to assemble an RBU enabled VFS stack that uses both zipvfs and ** multiplexor (error checking omitted): ** ** // Create a VFS named "multiplex" (not the default). ** sqlite3_multiplex_initialize(0, 0); ** -** // Create an ota VFS named "ota" that uses multiplexor. If the -** // second argument were replaced with NULL, the "ota" VFS would +** // Create an rbu VFS named "rbu" that uses multiplexor. If the +** // second argument were replaced with NULL, the "rbu" VFS would ** // access the file-system via the system default VFS, bypassing the ** // multiplexor. -** sqlite3ota_create_vfs("ota", "multiplex"); +** sqlite3rbu_create_vfs("rbu", "multiplex"); ** -** // Create a zipvfs VFS named "zipvfs" that uses ota. -** zipvfs_create_vfs_v3("zipvfs", "ota", 0, xCompressorAlgorithmDetector); +** // Create a zipvfs VFS named "zipvfs" that uses rbu. +** zipvfs_create_vfs_v3("zipvfs", "rbu", 0, xCompressorAlgorithmDetector); ** ** // Make zipvfs the default VFS. ** sqlite3_vfs_register(sqlite3_vfs_find("zipvfs"), 1); ** -** Because the default VFS created above includes a OTA functionality, it -** may be used by OTA clients. Attempting to use OTA with a zipvfs VFS stack -** that does not include the OTA layer results in an error. +** Because the default VFS created above includes a RBU functionality, it +** may be used by RBU clients. Attempting to use RBU with a zipvfs VFS stack +** that does not include the RBU layer results in an error. ** -** The overhead of adding the "ota" VFS to the system is negligible for -** non-OTA users. There is no harm in an application accessing the -** file-system via "ota" all the time, even if it only uses OTA functionality +** The overhead of adding the "rbu" VFS to the system is negligible for +** non-RBU users. There is no harm in an application accessing the +** file-system via "rbu" all the time, even if it only uses RBU functionality ** occasionally. */ -int sqlite3ota_create_vfs(const char *zName, const char *zParent); +int sqlite3rbu_create_vfs(const char *zName, const char *zParent); /* -** Deregister and destroy an OTA vfs created by an earlier call to -** sqlite3ota_create_vfs(). +** Deregister and destroy an RBU vfs created by an earlier call to +** sqlite3rbu_create_vfs(). ** ** VFS objects are not reference counted. If a VFS object is destroyed ** before all database handles that use it have been closed, the results ** are undefined. */ -void sqlite3ota_destroy_vfs(const char *zName); - -#endif /* _SQLITE3OTA_H */ +void sqlite3rbu_destroy_vfs(const char *zName); +#endif /* _SQLITE3RBU_H */ diff --git a/ext/ota/test_ota.c b/ext/rbu/test_rbu.c index 33ef63403..fbaea1626 100644 --- a/ext/ota/test_ota.c +++ b/ext/rbu/test_rbu.c @@ -14,23 +14,23 @@ #include "sqlite3.h" #if defined(SQLITE_TEST) -#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_OTA) +#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_RBU) -#include "sqlite3ota.h" +#include "sqlite3rbu.h" #include <tcl.h> #include <assert.h> /* From main.c (apparently...) */ extern const char *sqlite3ErrName(int); -void test_ota_delta(sqlite3_context *pCtx, int nArg, sqlite3_value **apVal){ +void test_rbu_delta(sqlite3_context *pCtx, int nArg, sqlite3_value **apVal){ Tcl_Interp *interp = (Tcl_Interp*)sqlite3_user_data(pCtx); Tcl_Obj *pScript; int i; pScript = Tcl_NewObj(); Tcl_IncrRefCount(pScript); - Tcl_ListObjAppendElement(0, pScript, Tcl_NewStringObj("ota_delta", -1)); + Tcl_ListObjAppendElement(0, pScript, Tcl_NewStringObj("rbu_delta", -1)); for(i=0; i<nArg; i++){ sqlite3_value *pIn = apVal[i]; const char *z = (const char*)sqlite3_value_text(pIn); @@ -48,15 +48,15 @@ void test_ota_delta(sqlite3_context *pCtx, int nArg, sqlite3_value **apVal){ } -static int test_sqlite3ota_cmd( +static int test_sqlite3rbu_cmd( ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[] ){ int ret = TCL_OK; - sqlite3ota *pOta = (sqlite3ota*)clientData; - const char *azMethod[] = { "step", "close", "create_ota_delta", 0 }; + sqlite3rbu *pRbu = (sqlite3rbu*)clientData; + const char *azMethod[] = { "step", "close", "create_rbu_delta", 0 }; int iMethod; if( objc!=2 ){ @@ -69,7 +69,7 @@ static int test_sqlite3ota_cmd( switch( iMethod ){ case 0: /* step */ { - int rc = sqlite3ota_step(pOta); + int rc = sqlite3rbu_step(pRbu); Tcl_SetObjResult(interp, Tcl_NewStringObj(sqlite3ErrName(rc), -1)); break; } @@ -78,7 +78,7 @@ static int test_sqlite3ota_cmd( char *zErrmsg = 0; int rc; Tcl_DeleteCommand(interp, Tcl_GetString(objv[0])); - rc = sqlite3ota_close(pOta, &zErrmsg); + rc = sqlite3rbu_close(pRbu, &zErrmsg); if( rc==SQLITE_OK || rc==SQLITE_DONE ){ Tcl_SetObjResult(interp, Tcl_NewStringObj(sqlite3ErrName(rc), -1)); assert( zErrmsg==0 ); @@ -93,10 +93,10 @@ static int test_sqlite3ota_cmd( break; } - case 2: /* create_ota_delta */ { - sqlite3 *db = sqlite3ota_db(pOta, 0); + case 2: /* create_rbu_delta */ { + sqlite3 *db = sqlite3rbu_db(pRbu, 0); int rc = sqlite3_create_function( - db, "ota_delta", -1, SQLITE_UTF8, (void*)interp, test_ota_delta, 0, 0 + db, "rbu_delta", -1, SQLITE_UTF8, (void*)interp, test_rbu_delta, 0, 0 ); Tcl_SetObjResult(interp, Tcl_NewStringObj(sqlite3ErrName(rc), -1)); ret = (rc==SQLITE_OK ? TCL_OK : TCL_ERROR); @@ -112,39 +112,39 @@ static int test_sqlite3ota_cmd( } /* -** Tclcmd: sqlite3ota CMD <target-db> <ota-db> ?<state-db>? +** Tclcmd: sqlite3rbu CMD <target-db> <rbu-db> ?<state-db>? */ -static int test_sqlite3ota( +static int test_sqlite3rbu( ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[] ){ - sqlite3ota *pOta = 0; + sqlite3rbu *pRbu = 0; const char *zCmd; const char *zTarget; - const char *zOta; + const char *zRbu; const char *zStateDb = 0; if( objc!=4 && objc!=5 ){ - Tcl_WrongNumArgs(interp, 1, objv, "NAME TARGET-DB OTA-DB ?STATE-DB?"); + Tcl_WrongNumArgs(interp, 1, objv, "NAME TARGET-DB RBU-DB ?STATE-DB?"); return TCL_ERROR; } zCmd = Tcl_GetString(objv[1]); zTarget = Tcl_GetString(objv[2]); - zOta = Tcl_GetString(objv[3]); + zRbu = Tcl_GetString(objv[3]); if( objc==5 ) zStateDb = Tcl_GetString(objv[4]); - pOta = sqlite3ota_open(zTarget, zOta, zStateDb); - Tcl_CreateObjCommand(interp, zCmd, test_sqlite3ota_cmd, (ClientData)pOta, 0); + pRbu = sqlite3rbu_open(zTarget, zRbu, zStateDb); + Tcl_CreateObjCommand(interp, zCmd, test_sqlite3rbu_cmd, (ClientData)pRbu, 0); Tcl_SetObjResult(interp, objv[1]); return TCL_OK; } /* -** Tclcmd: sqlite3ota_create_vfs ?-default? NAME PARENT +** Tclcmd: sqlite3rbu_create_vfs ?-default? NAME PARENT */ -static int test_sqlite3ota_create_vfs( +static int test_sqlite3rbu_create_vfs( ClientData clientData, Tcl_Interp *interp, int objc, @@ -163,7 +163,7 @@ static int test_sqlite3ota_create_vfs( zParent = Tcl_GetString(objv[objc-1]); if( zParent[0]=='\0' ) zParent = 0; - rc = sqlite3ota_create_vfs(zName, zParent); + rc = sqlite3rbu_create_vfs(zName, zParent); if( rc!=SQLITE_OK ){ Tcl_SetObjResult(interp, Tcl_NewStringObj(sqlite3ErrName(rc), -1)); return TCL_ERROR; @@ -177,9 +177,9 @@ static int test_sqlite3ota_create_vfs( } /* -** Tclcmd: sqlite3ota_destroy_vfs NAME +** Tclcmd: sqlite3rbu_destroy_vfs NAME */ -static int test_sqlite3ota_destroy_vfs( +static int test_sqlite3rbu_destroy_vfs( ClientData clientData, Tcl_Interp *interp, int objc, @@ -193,14 +193,14 @@ static int test_sqlite3ota_destroy_vfs( } zName = Tcl_GetString(objv[1]); - sqlite3ota_destroy_vfs(zName); + sqlite3rbu_destroy_vfs(zName); return TCL_OK; } /* -** Tclcmd: sqlite3ota_internal_test +** Tclcmd: sqlite3rbu_internal_test */ -static int test_sqlite3ota_internal_test( +static int test_sqlite3rbu_internal_test( ClientData clientData, Tcl_Interp *interp, int objc, @@ -213,24 +213,24 @@ static int test_sqlite3ota_internal_test( return TCL_ERROR; } - db = sqlite3ota_db(0, 0); + db = sqlite3rbu_db(0, 0); if( db!=0 ){ - Tcl_AppendResult(interp, "sqlite3ota_db(0, 0)!=0", 0); + Tcl_AppendResult(interp, "sqlite3rbu_db(0, 0)!=0", 0); return TCL_ERROR; } return TCL_OK; } -int SqliteOta_Init(Tcl_Interp *interp){ +int SqliteRbu_Init(Tcl_Interp *interp){ static struct { char *zName; Tcl_ObjCmdProc *xProc; } aObjCmd[] = { - { "sqlite3ota", test_sqlite3ota }, - { "sqlite3ota_create_vfs", test_sqlite3ota_create_vfs }, - { "sqlite3ota_destroy_vfs", test_sqlite3ota_destroy_vfs }, - { "sqlite3ota_internal_test", test_sqlite3ota_internal_test }, + { "sqlite3rbu", test_sqlite3rbu }, + { "sqlite3rbu_create_vfs", test_sqlite3rbu_create_vfs }, + { "sqlite3rbu_destroy_vfs", test_sqlite3rbu_destroy_vfs }, + { "sqlite3rbu_internal_test", test_sqlite3rbu_internal_test }, }; int i; for(i=0; i<sizeof(aObjCmd)/sizeof(aObjCmd[0]); i++){ @@ -241,7 +241,6 @@ int SqliteOta_Init(Tcl_Interp *interp){ #else #include <tcl.h> -int SqliteOta_Init(Tcl_Interp *interp){ return TCL_OK; } -#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_OTA) */ +int SqliteRbu_Init(Tcl_Interp *interp){ return TCL_OK; } +#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_RBU) */ #endif /* defined(SQLITE_TEST) */ - @@ -66,7 +66,7 @@ LIBOBJ+= vdbe.o parse.o \ mutex.o mutex_noop.o mutex_unix.o mutex_w32.o \ notify.o opcodes.o os.o os_unix.o os_win.o \ pager.o pcache.o pcache1.o pragma.o prepare.o printf.o \ - random.o resolve.o rowset.o rtree.o select.o sqlite3ota.o status.o \ + random.o resolve.o rowset.o rtree.o select.o sqlite3rbu.o status.o \ table.o threads.o tokenize.o treeview.o trigger.o \ update.o userauth.o util.o vacuum.o \ vdbeapi.o vdbeaux.o vdbeblob.o vdbemem.o vdbesort.o \ @@ -233,8 +233,8 @@ SRC += \ $(TOP)/ext/userauth/sqlite3userauth.h SRC += \ - $(TOP)/ext/ota/sqlite3ota.c \ - $(TOP)/ext/ota/sqlite3ota.h + $(TOP)/ext/rbu/sqlite3rbu.c \ + $(TOP)/ext/rbu/sqlite3rbu.h # Generated source code files @@ -253,7 +253,7 @@ SRC += \ TESTSRC = \ $(TOP)/ext/fts3/fts3_term.c \ $(TOP)/ext/fts3/fts3_test.c \ - $(TOP)/ext/ota/test_ota.c \ + $(TOP)/ext/rbu/test_rbu.c \ $(TOP)/src/test1.c \ $(TOP)/src/test2.c \ $(TOP)/src/test3.c \ @@ -679,8 +679,8 @@ userauth.o: $(TOP)/ext/userauth/userauth.c $(HDR) $(EXTHDR) sqlite3session.o: $(TOP)/ext/session/sqlite3session.c $(HDR) $(EXTHDR) $(TCCX) -DSQLITE_CORE -c $(TOP)/ext/session/sqlite3session.c -sqlite3ota.o: $(TOP)/ext/ota/sqlite3ota.c $(HDR) $(EXTHDR) - $(TCCX) -DSQLITE_CORE -c $(TOP)/ext/ota/sqlite3ota.c +sqlite3rbu.o: $(TOP)/ext/rbu/sqlite3rbu.c $(HDR) $(EXTHDR) + $(TCCX) -DSQLITE_CORE -c $(TOP)/ext/rbu/sqlite3rbu.c # Rules for building test programs and for running tests # @@ -829,8 +829,8 @@ wordcount$(EXE): $(TOP)/test/wordcount.c sqlite3.c speedtest1$(EXE): $(TOP)/test/speedtest1.c sqlite3.o $(TCC) -I. $(OTAFLAGS) -o speedtest1$(EXE) $(TOP)/test/speedtest1.c sqlite3.o $(THREADLIB) -ota$(EXE): $(TOP)/ext/ota/ota.c $(TOP)/ext/ota/sqlite3ota.c sqlite3.o - $(TCC) -I. -o ota$(EXE) $(TOP)/ext/ota/ota.c sqlite3.o \ +rbu$(EXE): $(TOP)/ext/rbu/rbu.c $(TOP)/ext/rbu/sqlite3rbu.c sqlite3.o + $(TCC) -I. -o rbu$(EXE) $(TOP)/ext/rbu/rbu.c sqlite3.o \ $(THREADLIB) loadfts: $(TOP)/tool/loadfts.c libsqlite3.a @@ -888,4 +888,4 @@ clean: rm -f fuzzershell fuzzershell.exe rm -f fuzzcheck fuzzcheck.exe rm -f sqldiff sqldiff.exe - rm -f fts5.c fts5.h fts5parse.* + rm -f fts5.* fts5parse.* @@ -1,9 +1,9 @@ -C Merge\strunk\schanges,\sincluding\sthe\saddition\sof\sFTS5\sand\spcache1\sperformance\nenhancements. -D 2015-07-14T15:39:22.594 +C Merge\sall\schanges\sin\sthe\slatest\s3.8.11\sbeta\sinto\sthe\ssessions\sbranch.\nChanges\sinclude\sthe\srename\sof\sOTA\sto\sRBU,\sthe\sWITHOUT-ROWID-OR-Skipscan\sfix,\nand\simprovements\sto\spcache1. +D 2015-07-23T21:59:58.899 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f -F Makefile.in 82cd7996d31d7b0a9a80a6c247ad9fd9b41223af +F Makefile.in e4e700c7c1764b1e731e2747dc9121e63eb951fc F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 -F Makefile.msc 69a5df1f8764b991cb1a269825538258f9097c4c +F Makefile.msc bbb9d41e71f6b32ea5eb12dfec06302f7f6de70a F Makefile.vxworks e1b65dea203f054e71653415bd8f96dcaed47858 F README.md 8ecc12493ff9f820cdea6520a9016001cb2e59b7 F VERSION ce0ae95abd7121c534f6917c1c8f2b70d9acd4db @@ -23,7 +23,7 @@ F autoconf/depcomp 0b26f101e3bc9fd1ff0be1da9fb4a82371142f92 x F autoconf/install-sh 06ee6336e63bb845c8439d777c32eb2eccc4fbf1 x F autoconf/ltmain.sh 7a658a24028f02331c1d2446562758083c5eadd1 F autoconf/missing d7c9981a81af13370d4ed152b24c0a82b7028585 x -F autoconf/tea/Makefile.in d55bcc63832caf0309c2ff80358756116618cfca +F autoconf/tea/Makefile.in b438a7020446c8a8156e8d97c8914a04833da6fd F autoconf/tea/README 3e9a3c060f29a44344ab50aec506f4db903fb873 F autoconf/tea/aclocal.m4 52c47aac44ce0ddb1f918b6993e8beb8eee88f43 F autoconf/tea/configure.ac 93d43c79e936fb16556e22498177d7e8571efa04 @@ -107,14 +107,14 @@ F ext/fts3/unicode/parseunicode.tcl da577d1384810fb4e2b209bf3313074353193e95 F ext/fts5/extract_api_docs.tcl 06583c935f89075ea0b32f85efa5dd7619fcbd03 F ext/fts5/fts5.h 81d1a92fc2b4bd477af7e4e0b38b456f3e199fba F ext/fts5/fts5Int.h 8d9bce1847a10df2e4ed9492ea4f3868276748fb -F ext/fts5/fts5_aux.c 7cd0e2858171dacf505fea4e2e84ee6126854c3d +F ext/fts5/fts5_aux.c 044cb176a815f4388308738437f6e130aa384fb0 F ext/fts5/fts5_buffer.c 80f9ba4431848cb857e3d2158f5280093dcd8015 F ext/fts5/fts5_config.c b2456e9625bca41c51d54c363e369c6356895c90 -F ext/fts5/fts5_expr.c d2e148345639c5a5583e0daa39a639bf298ae6a7 -F ext/fts5/fts5_hash.c 219f4edd72e5cf95b19c33f1058809a18fad5229 -F ext/fts5/fts5_index.c 1a1fd996dfe2d632df1dd00689553bc0d205497d -F ext/fts5/fts5_main.c 2e43726b3ef40b3d5efc0adc7c279d857b1c74fe -F ext/fts5/fts5_storage.c 4cae85b5287b159d9d98174a4e70adf872b0930a +F ext/fts5/fts5_expr.c ac0614f843cf5c80a85c4c6aa44bbede62a51bb2 +F ext/fts5/fts5_hash.c ff07722c73587c12781213133edbdb22cd156378 +F ext/fts5/fts5_index.c d6ad9293280f39c56343ef5035b0475ff2a6be12 +F ext/fts5/fts5_main.c 0de7ba81488d2c502c8e794eaf7983d468e4c6e9 +F ext/fts5/fts5_storage.c 1c35a38a564ee9cadcbd7ae0b13a806bdda722bd F ext/fts5/fts5_tcl.c 85eb4e0d0fefa9420b78151496ad4599a1783e20 F ext/fts5/fts5_tokenize.c 30f97a8c74683797b4cd233790444fbefb3b0708 F ext/fts5/fts5_unicode2.c 78273fbd588d1d9bd0a7e4e0ccc9207348bae33c @@ -200,25 +200,25 @@ F ext/misc/totype.c 4a167594e791abeed95e0a8db028822b5e8fe512 F ext/misc/vfslog.c fe40fab5c077a40477f7e5eba994309ecac6cc95 F ext/misc/vtshim.c babb0dc2bf116029e3e7c9a618b8a1377045303e F ext/misc/wholenumber.c 784b12543d60702ebdd47da936e278aa03076212 -F ext/ota/ota.c 3a849c3b0a4ad6e63125668be9f67be03621216e -F ext/ota/ota1.test abdcbe746db4c7f7b51e842b576cacb33eef28f5 -F ext/ota/ota10.test 85e0f6e7964db5007590c1b299e75211ed4240d4 -F ext/ota/ota11.test 2f606cd2b4af260a86b549e91b9f395450fc75cb -F ext/ota/ota12.test e4c0b9a14255ffbe04d241fc15da2c65b3c06846 -F ext/ota/ota13.test f7a3d73fa5d3fabf2755b569f125fce7390a874c -F ext/ota/ota3.test 3fe3521fbdce32d0e4e116a60999c3cba47712c5 -F ext/ota/ota5.test ad0799daf8923ddebffe75ae8c5504ca90b7fadb -F ext/ota/ota6.test 3bde7f69a894748b27206b6753462ec3b75b6bb6 -F ext/ota/ota7.test 1fe2c5761705374530e29f70c39693076028221a -F ext/ota/ota8.test cd70e63a0c29c45c0906692827deafa34638feda -F ext/ota/ota9.test d3eee95dd836824d07a22e5efcdb7bf6e869358b -F ext/ota/otaA.test ab67f7f53670b81c750dcc946c5b704f51c429a4 -F ext/ota/otacrash.test 8346192b2d46cbe7787d5d65904d81d3262a3cbf -F ext/ota/otafault.test 8c43586c2b96ca16bbce00b5d7e7d67316126db8 -F ext/ota/otafault2.test fa202a98ca221faec318f3e5c5f39485b1256561 -F ext/ota/sqlite3ota.c 21575d86eac30482a9bfbb2a531f433015e0e03c -F ext/ota/sqlite3ota.h 00028de37eede471ff1947d455cc3f33d3a911c6 -F ext/ota/test_ota.c a876f88550d7d59a3ef62d4c1a5c04c4c2f1ebe1 +F ext/rbu/rbu.c e04e7baea76b6dd719a4f290f8a58166efc8d234 w ext/ota/ota.c +F ext/rbu/rbu1.test 57601977588603e82700a43c279bd55282ffa482 w ext/ota/ota1.test +F ext/rbu/rbu10.test 046b0980041d30700464a800bbf6733ed2df515d w ext/ota/ota10.test +F ext/rbu/rbu11.test 9bc68c2d3dbeb1720153626e3bd0466dcc017702 w ext/ota/ota11.test +F ext/rbu/rbu12.test bde22ed0004dd5d1888c72a84ae407e574aeae16 w ext/ota/ota12.test +F ext/rbu/rbu13.test 462ff799c4afedc3ef8a47ff818c0ffbf14ae4f2 w ext/ota/ota13.test +F ext/rbu/rbu3.test 8bd4c6b87367c358981b6a47dc3d654fa60bff90 w ext/ota/ota3.test +F ext/rbu/rbu5.test 2e24fee3e615aecd99bbdd46967935a641e866f7 w ext/ota/ota5.test +F ext/rbu/rbu6.test 32e8ed60631b6facdb6366bd2b5f5f25245e7edb w ext/ota/ota6.test +F ext/rbu/rbu7.test fd025d5ba440fcfe151fbb0e3835e1e7fe964fa1 w ext/ota/ota7.test +F ext/rbu/rbu8.test 3bbf2c35d71a843c463efe93946f14ad10c3ede0 w ext/ota/ota8.test +F ext/rbu/rbu9.test 0806d1772c9f4981774ff028de6656e4183082af w ext/ota/ota9.test +F ext/rbu/rbuA.test c1a7b3e2d926b8f8448bb3b4ae787e314ee4b2b3 w ext/ota/otaA.test +F ext/rbu/rbucrash.test 8d2ed5d4b05fef6c00c2a6b5f7ead71fa172a695 w ext/ota/otacrash.test +F ext/rbu/rbufault.test cc0be8d5d392d98b0c2d6a51be377ea989250a89 w ext/ota/otafault.test +F ext/rbu/rbufault2.test 9a7f19edd6ea35c4c9f807d8a3db0a03a5670c06 w ext/ota/otafault2.test +F ext/rbu/sqlite3rbu.c d37e1ca2d13e439cb3df7cd9d98db90458f21433 w ext/ota/sqlite3ota.c +F ext/rbu/sqlite3rbu.h 27dc1bdc18df6c9bfa3bd7d7b011699ed619d6f6 w ext/ota/sqlite3ota.h +F ext/rbu/test_rbu.c f99698956cc9158d6bf865e461e2d15876538ac1 w ext/ota/test_ota.c F ext/rtree/README 6315c0d73ebf0ec40dedb5aa0e942bc8b54e3761 F ext/rtree/rtree.c 0f9b595bd0debcbedf1d7a63d0e0678d619e6c9c F ext/rtree/rtree.h 834dbcb82dc85b2481cde6a07cdadfddc99e9b9e @@ -267,7 +267,7 @@ F ext/userauth/userauth.c 5fa3bdb492f481bbc1709fc83c91ebd13460c69e F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x F ltmain.sh 3ff0879076df340d2e23ae905484d8c15d5fdea8 F magic.txt 8273bf49ba3b0c8559cb2774495390c31fd61c60 -F main.mk c4250d110d0275a9903f12788346f1dc795275bf +F main.mk 7e9671e3b41d23a454398e8ab5b1fa5a05bd6df6 F mkopcodec.awk c2ff431854d702cdd2d779c9c0d1f58fa16fa4ea F mkopcodeh.awk 0e7f04a8eb90f92259e47d80110e4e98d7ce337a F mkso.sh fd21c06b063bb16a5d25deea1752c2da6ac3ed83 @@ -288,14 +288,14 @@ F src/auth.c b56c78ebe40a2110fd361379f7e8162d23f92240 F src/backup.c 4d9134dc988a87838c06056c89c0e8c4700a0452 F src/bitvec.c d1f21d7d91690747881f03940584f4cc548c9d3d F src/btmutex.c 45a968cc85afed9b5e6cf55bf1f42f8d18107f79 -F src/btree.c 781deff0d5af639e8dd4f83ec963cc3bbf8cffc2 +F src/btree.c f48b3ef91676c06a90a8832987ecef6b94c931ee F src/btree.h 969adc948e89e449220ff0ff724c94bb2a52e9f1 F src/btreeInt.h 2ad754dd4528baa8d0946a593cc373b890bf859e F src/build.c b3f15255d5b16e42dafeaa638fd4f8a47c94ed70 F src/callback.c 7b44ce59674338ad48b0e84e7b72f935ea4f68b0 F src/complete.c addcd8160b081131005d5bc2d34adf20c1c5c92f F src/ctime.c 5a0b735dc95604766f5dac73973658eef782ee8b -F src/date.c e4d50b3283696836ec1036b695ead9a19e37a5ac +F src/date.c 8ec787fed4929d8ccdf6b1bc360fccc3e1d2ca58 F src/dbstat.c f402e77e25089c6003d0c60b3233b9b3947d599a F src/delete.c b998fbc3c55e8331a5f40aa7ff80972254de8de1 F src/expr.c c5c58e4d01c7ceb2266791d8d877f1b23a88e316 @@ -311,7 +311,7 @@ F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d F src/legacy.c ba1863ea58c4c840335a84ec276fc2b25e22bc4e F src/lempar.c 92bafa308607dd985ca389a788cd9e0a2b608712 F src/loadext.c e722f4b832f923744788365df5fb8515c0bc8a47 -F src/main.c 5e170f7c4872c272d733572a99628e47fe92ab43 +F src/main.c 6dd8bf94f181925a50a1f494042e50a64d5ecaca F src/malloc.c 19461e159bccf0e2cf06a50e867963d0a7b124a8 F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c abe6ee469b6c5a35c7f22bfeb9c9bac664a1c987 @@ -338,25 +338,25 @@ F src/pager.h 6d435f563b3f7fcae4b84433b76a6ac2730036e2 F src/parse.y 6d60dda8f8d418b6dc034f1fbccd816c459983a8 F src/pcache.c cde06aa50962595e412d497e22fd2e07878ba1f0 F src/pcache.h 9968603796240cdf83da7e7bef76edf90619cea9 -F src/pcache1.c 3f4c87cf913f2de8189026d9a5223ddaf55eaf6b -F src/pragma.c c1f4d012ea9f6b1ce52d341b2cd0ad72d560afd7 -F src/pragma.h b8632d7cdda7b25323fa580e3e558a4f0d4502cc +F src/pcache1.c d08939800abf3031bd0affd5a13fbc4d7ba3fb68 +F src/pragma.c e52084b37a08a88f258830518461e94627af2621 +F src/pragma.h 631a91c8b0e6ca8f051a1d8a4a0da4150e04620a F src/prepare.c 82e5db1013846a819f198336fed72c44c974e7b1 -F src/printf.c db11b5960105ee661dcac690f2ae6276e49bf251 +F src/printf.c 2bc439ff20a4aad0e0ad50a37a67b5eae7d20edc F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c 2d47554370de8de6dd5be060cef9559eec315005 F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e -F src/select.c d3c04f01549317afbe02455c4ca9465100e9c5fe +F src/select.c 57ef3d98c4400b93eea318813be41b2af2da2217 F src/shell.c e4ad9031072a6d679b2c69a780014d30db62dc7f -F src/sqlite.h.in 84aac470adebde08e319c200f892664c6e976692 +F src/sqlite.h.in 814992bc580544d632965a5480f8dc76eee331ed F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h be1a718b7d2ce40ceba725ae92c8eb5f18003066 -F src/sqliteInt.h f5d9aa5d0cb0c89af4030c5b5b0ff93d5ef1e9a3 +F src/sqliteInt.h cdc9b0c2dc12273c60603eb6c4157dd998603039 F src/sqliteLimit.h 216557999cb45f2e3578ed53ebefe228d779cb46 F src/status.c f266ad8a2892d659b74f0f50cb6a88b6e7c12179 F src/table.c 51b46b2a62d1b3a959633d593b89bab5e2c9155e -F src/tclsqlite.c 6cfb538d12565aba52840709721a02dd99806f1c -F src/test1.c e055ab594a48d25720ed31daa5eced1163544488 +F src/tclsqlite.c e2344bee0d192397f555a24ef3fab26f2ed93bcc +F src/test1.c 375d7bd56d9f806095deb91a3dafe61bd0e367c8 F src/test2.c 577961fe48961b2f2e5c8b56ee50c3f459d3359d F src/test3.c 64d2afdd68feac1bb5e2ffb8226c8c639f798622 F src/test4.c d168f83cc78d02e8d35567bb5630e40dcd85ac1e @@ -370,7 +370,7 @@ F src/test_autoext.c dea8a01a7153b9adc97bd26161e4226329546e12 F src/test_backup.c 2e6e6a081870150f20c526a2e9d0d29cda47d803 F src/test_blob.c e5a7a81d61a780da79101aeb1e60d300af169e07 F src/test_btree.c 2e9978eca99a9a4bfa8cae949efb00886860a64f -F src/test_config.c c15d03e834c4bda571e689a0fefb106a288450a4 +F src/test_config.c 548c99a1a91fd89fe2c94ee08017884091e3d6f0 F src/test_demovfs.c 0de72c2c89551629f58486fde5734b7d90758852 F src/test_devsym.c e7498904e72ba7491d142d5c83b476c4e76993bc F src/test_fs.c ced436e3d4b8e4681328409b8081051ce614e28f @@ -420,12 +420,12 @@ F src/vdbesort.c f5009e7a35e3065635d8918b9a31f498a499976b F src/vdbetrace.c 8befe829faff6d9e6f6e4dee5a7d3f85cc85f1a0 F src/vtab.c 082b35a25a26e3d36f365ca8cd73c1922532f05e F src/vxworks.h c18586c8edc1bddbc15c004fa16aeb1e1342b4fb -F src/wal.c ce2cb2d06faab54d1bce3e739bec79e063dd9113 +F src/wal.c 6fb6b68969e4692593c2552c4e7bff5882de2cb8 F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 F src/walker.c c253b95b4ee44b21c406e2a1052636c31ea27804 F src/where.c 909eba3b6db984eb2adfbca9de2c237ee7056adb F src/whereInt.h 5f87e3c4b0551747d119730dfebddd3c54f04047 -F src/wherecode.c 0669481cabaf5caf934b6bb825df15bc57f60d40 +F src/wherecode.c 5da5049224f12db314931ae7e0919b4914a2a0b1 F src/whereexpr.c 9ce1c9cfedbf80c93c7d899497025ec8256ce652 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/affinity2.test a6d901b436328bd67a79b41bb0ac2663918fe3bd @@ -751,7 +751,7 @@ F test/func5.test cdd224400bc3e48d891827cc913a57051a426fa4 F test/fuzz-oss1.test 4912e528ec9cf2f42134456933659d371c9e0d74 F test/fuzz.test 96083052bf5765e4518c1ba686ce2bab785670d1 F test/fuzz2.test 76dc35b32b6d6f965259508508abce75a6c4d7e1 -F test/fuzz3.test efd384b896c647b61a2c1848ba70d42aad60a7b3 +F test/fuzz3.test 0d13010d1c13003a3aa57dda2f69b6b71ccac46e F test/fuzz_common.tcl a87dfbb88c2a6b08a38e9a070dabd129e617b45b F test/fuzz_malloc.test 328f70aaca63adf29b4c6f06505ed0cf57ca7c26 F test/fuzzcheck.c b973b06b500e6fc052d7059257cdf70df1f3a986 @@ -842,7 +842,7 @@ F test/make-where7.tcl 05c16b5d4f5d6512881dfec560cb793915932ef9 F test/malloc.test 21c213365f2cca95ab2d7dc078dc8525f96065f8 F test/malloc3.test e3b32c724b5a124b57cb0ed177f675249ad0c66a F test/malloc4.test 957337613002b7058a85116493a262f679f3a261 -F test/malloc5.test e9a9116f80ab6b7a9ca258876c6f3dedb08cb08b +F test/malloc5.test 4e87e596a28908c034eb5777fc33dd921bb44fc3 F test/malloc6.test 2f039d9821927eacae43e1831f815e157659a151 F test/malloc7.test 7c68a32942858bc715284856c5507446bba88c3a F test/malloc8.test 9b7a3f8cb9cf0b12fff566e80a980b1767bd961d @@ -908,7 +908,6 @@ F test/orderby6.test 8b38138ab0972588240b3fca0985d2e400432859 F test/orderby7.test 3d1383d52ade5b9eb3a173b3147fdd296f0202da F test/orderby8.test 23ef1a5d72bd3adcc2f65561c654295d1b8047bd F test/oserror.test 14fec2796c2b6fe431c7823750e8a18a761176d7 -F test/ota.test 3a8d97cbf8f7210dc6a638797c4e4cd674036927 F test/ovfl.test 4f7ca651cba5c059a12d8c67dddd49bec5747799 F test/pager1.test 1acbdb14c5952a72dd43129cabdbf69aaa3ed1fa F test/pager2.test 67b8f40ae98112bcdba1f2b2d03ea83266418c71 @@ -919,10 +918,10 @@ F test/pagerfault2.test caf4c7facb914fd3b03a17b31ae2b180c8d6ca1f F test/pagerfault3.test 1003fcda009bf48a8e22a516e193b6ef0dd1bbd8 F test/pageropt.test 6b8f6a123a5572c195ad4ae40f2987007923bbd6 F test/pagesize.test 5769fc62d8c890a83a503f67d47508dfdc543305 -F test/pcache.test b09104b03160aca0d968d99e8cd2c5b1921a993d -F test/pcache2.test ec3ae192f444ee6a0a80d1fd80d99695d884bfb3 +F test/pcache.test c8acbedd3b6fd0f9a7ca887a83b11d24a007972b +F test/pcache2.test c70d92547550136ba6f818e6a44fe246d2738604 F test/percentile.test 4243af26b8f3f4555abe166f723715a1f74c77ff -F test/permutations.test 1a49f543ec7f0e075ca24eae3bda7f75bb00634b +F test/permutations.test dacb0a4094fbf20fc8b5c0e6d40fb5a985836b19 F test/pragma.test be7195f0aa72bdb8a512133e9640ac40f15b57a2 F test/pragma2.test f624a496a95ee878e81e59961eade66d5c00c028 F test/pragma3.test 6f849ccffeee7e496d2f2b5e74152306c0b8757c @@ -938,10 +937,11 @@ F test/quota2.test 7dc12e08b11cbc4c16c9ba2aa2e040ea8d8ab4b8 F test/quote.test 215897dbe8de1a6f701265836d6601cc6ed103e6 F test/randexpr1.tcl 40dec52119ed3a2b8b2a773bce24b63a3a746459 F test/randexpr1.test eda062a97e60f9c38ae8d806b03b0ddf23d796df +F test/rbu.test 168573d353cd0fd10196b87b0caa322c144ef736 w test/ota.test F test/rdonly.test 64e2696c322e3538df0b1ed624e21f9a23ed9ff8 F test/regexp1.test 497ea812f264d12b6198d6e50a76be4a1973a9d8 F test/reindex.test 44edd3966b474468b823d481eafef0c305022254 -F test/releasetest.tcl 2aaffa548a8f8d10053b20bcf68a1b5a01081e51 +F test/releasetest.tcl 8eb718bca8bca71c0c0145384f9915bb7e53fca3 F test/resolver01.test f4022acafda7f4d40eca94dbf16bc5fc4ac30ceb F test/rollback.test 458fe73eb3ffdfdf9f6ba3e9b7350a6220414dea F test/rollback2.test fc14cf6d1a2b250d2735ef16124b971bce152f14 @@ -1005,7 +1005,7 @@ F test/shortread1.test bb591ef20f0fd9ed26d0d12e80eee6d7ac8897a3 F test/show_speedtest1_rtree.tcl 32e6c5f073d7426148a6936a0408f4b5b169aba5 F test/shrink.test 06deac10d591186017466ce67d10645150bfdeec F test/sidedelete.test f0ad71abe6233e3b153100f3b8d679b19a488329 -F test/skipscan1.test 2ddfe5d168462170c4487f534e2a99fb006b2076 +F test/skipscan1.test d37a75b4be4eb9dedeb69b4f38b1d0a74b5021d7 F test/skipscan2.test d1d1450952b7275f0b0a3a981f0230532743951a F test/skipscan3.test ec5bab3f81c7038b43450e7b3062e04a198bdbb5 F test/skipscan5.test 67817a4b6857c47e0e33ba3e506da6f23ef68de2 @@ -1026,7 +1026,7 @@ F test/speed3.test d32043614c08c53eafdc80f33191d5bd9b920523 F test/speed4.test abc0ad3399dcf9703abed2fff8705e4f8e416715 F test/speed4p.explain 6b5f104ebeb34a038b2f714150f51d01143e59aa F test/speed4p.test 0e51908951677de5a969b723e03a27a1c45db38b -F test/speedtest1.c 54f211994e2fb5b3f7c5c82137378f46ca89aae8 +F test/speedtest1.c 857439869d1cb4db35e1c720ee9c2756eb9ea2a0 F test/spellfix.test 0597065ff57042df1f138e6a2611ae19c2698135 F test/sqldiff1.test 8f6bc7c6a5b3585d350d779c6078869ba402f8f5 F test/sqllimits1.test e05786eaed7950ff6a2d00031d001d8a26131e68 @@ -1347,10 +1347,10 @@ F tool/logest.c eef612f8adf4d0993dafed0416064cf50d5d33c6 F tool/mkautoconfamal.sh d1a2da0e15b2ed33d60af35c7e9d483f13a8eb9f F tool/mkkeywordhash.c dfff09dbbfaf950e89af294f48f902181b144670 F tool/mkopts.tcl 66ac10d240cc6e86abd37dc908d50382f84ff46e -F tool/mkpragmatab.tcl 40c287d3f929ece67da6e9e7c49885789960accf +F tool/mkpragmatab.tcl 84af2b180484323a2ea22a2279e8bd9e3e1e492e F tool/mkspeedsql.tcl a1a334d288f7adfe6e996f2e712becf076745c97 -F tool/mksqlite3c-noext.tcl 69bae8ce4aa52d2ff82d4a8a856bf283ec035b2e -F tool/mksqlite3c.tcl 12444ca6af8600db9fa08cbd134705f2f758387e +F tool/mksqlite3c-noext.tcl 87240b09c20042999b41d5fabe091b7111287835 +F tool/mksqlite3c.tcl 038ed0aee939e6207c462727088a08d0bdf49a8c F tool/mksqlite3h.tcl 96d92fcac21c6037d9db20c7cb2e06b534b550ac F tool/mksqlite3internalh.tcl eb994013e833359137eb53a55acdad0b5ae1049b F tool/mkvsix.tcl 3b58b9398f91c7dbf18d49eb87cefeee9efdbce1 @@ -1385,7 +1385,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 85ca4409bdca7aee801e9fba1c49a87fabbf2064 202479aa0a62067343e724487960b8a039e2e978 -R 582a57d0946e0ad5287c5fb6b7d3efee +P db4cbefb8674c6cfff27c1e918741de1885c845c 017c5019e1ce042025d4f327e50ec50af49f9fa4 +R 9260e9fdfb3bce3b7e0f7ced18f40623 U drh -Z a3ed5c85e5c2e63374f7522fd856797b +Z 699bda1d1e2b37f0ec4352c1a5a3ac67 diff --git a/manifest.uuid b/manifest.uuid index e44d2c0c2..ffc2052ad 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -db4cbefb8674c6cfff27c1e918741de1885c845c
\ No newline at end of file +7f0ee77062d2fcb014942c7c62c163ccc801f21b
\ No newline at end of file diff --git a/src/btree.c b/src/btree.c index 17c7bb67c..2692ade8e 100644 --- a/src/btree.c +++ b/src/btree.c @@ -8959,7 +8959,7 @@ static int checkTreePage( const char *saved_zPfx = pCheck->zPfx; int saved_v1 = pCheck->v1; int saved_v2 = pCheck->v2; - u8 savedIsInit; + u8 savedIsInit = 0; /* Check that the page exists */ diff --git a/src/date.c b/src/date.c index 5f3f247ca..6b11d9904 100644 --- a/src/date.c +++ b/src/date.c @@ -355,7 +355,7 @@ static void computeYMD(DateTime *p){ A = Z + 1 + A - (A/4); B = A + 1524; C = (int)((B - 122.1)/365.25); - D = (36525*C)/100; + D = (36525*(C&32767))/100; E = (int)((B-D)/30.6001); X1 = (int)(30.6001*E); p->D = B - D - X1; diff --git a/src/main.c b/src/main.c index addb3987f..d0545ccf1 100644 --- a/src/main.c +++ b/src/main.c @@ -642,6 +642,7 @@ int sqlite3_config(int op, ...){ ** the lookaside memory. */ static int setupLookaside(sqlite3 *db, void *pBuf, int sz, int cnt){ +#ifndef SQLITE_OMIT_LOOKASIDE void *pStart; if( db->lookaside.nOut ){ return SQLITE_BUSY; @@ -692,6 +693,7 @@ static int setupLookaside(sqlite3 *db, void *pBuf, int sz, int cnt){ db->lookaside.bEnabled = 0; db->lookaside.bMalloced = 0; } +#endif /* SQLITE_OMIT_LOOKASIDE */ return SQLITE_OK; } diff --git a/src/pcache1.c b/src/pcache1.c index a345e6760..187f09f59 100644 --- a/src/pcache1.c +++ b/src/pcache1.c @@ -191,6 +191,7 @@ static SQLITE_WSD struct PCacheGlobal { */ int isInit; /* True if initialized */ int separateCache; /* Use a new PGroup for each PCache */ + int nInitPage; /* Initial bulk allocation size */ int szSlot; /* Size of each free slot */ int nSlot; /* The number of pcache slots */ int nReserve; /* Try to keep nFreeSlot above this */ @@ -260,6 +261,43 @@ void sqlite3PCacheBufferSetup(void *pBuf, int sz, int n){ } /* +** Try to initialize the pCache->pFree and pCache->pBulk fields. Return +** true if pCache->pFree ends up containing one or more free pages. +*/ +static int pcache1InitBulk(PCache1 *pCache){ + i64 szBulk; + char *zBulk; + if( pcache1.nInitPage==0 ) return 0; + /* Do not bother with a bulk allocation if the cache size very small */ + if( pCache->nMax<3 ) return 0; + sqlite3BeginBenignMalloc(); + if( pcache1.nInitPage>0 ){ + szBulk = pCache->szAlloc * (i64)pcache1.nInitPage; + }else{ + szBulk = -1024 * (i64)pcache1.nInitPage; + } + if( szBulk > pCache->szAlloc*(i64)pCache->nMax ){ + szBulk = pCache->szAlloc*pCache->nMax; + } + zBulk = pCache->pBulk = sqlite3Malloc( szBulk ); + sqlite3EndBenignMalloc(); + if( zBulk ){ + int nBulk = sqlite3MallocSize(zBulk)/pCache->szAlloc; + int i; + for(i=0; i<nBulk; i++){ + PgHdr1 *pX = (PgHdr1*)&zBulk[pCache->szPage]; + pX->page.pBuf = zBulk; + pX->page.pExtra = &pX[1]; + pX->isBulkLocal = 1; + pX->pNext = pCache->pFree; + pCache->pFree = pX; + zBulk += pCache->szAlloc; + } + } + return pCache->pFree!=0; +} + +/* ** Malloc function used within this file to allocate space from the buffer ** configured using sqlite3_config(SQLITE_CONFIG_PAGECACHE) option. If no ** such buffer exists or there is no space left in it, this function falls @@ -359,7 +397,7 @@ static PgHdr1 *pcache1AllocPage(PCache1 *pCache){ void *pPg; assert( sqlite3_mutex_held(pCache->pGroup->mutex) ); - if( pCache->pFree ){ + if( pCache->pFree || (pCache->nPage==0 && pcache1InitBulk(pCache)) ){ p = pCache->pFree; pCache->pFree = p->pNext; p->pNext = 0; @@ -563,7 +601,8 @@ static void pcache1RemoveFromHash(PgHdr1 *pPage, int freeFlag){ ** If there are currently more than nMaxPage pages allocated, try ** to recycle pages to reduce the number allocated to nMaxPage. */ -static void pcache1EnforceMaxPage(PGroup *pGroup){ +static void pcache1EnforceMaxPage(PCache1 *pCache){ + PGroup *pGroup = pCache->pGroup; assert( sqlite3_mutex_held(pGroup->mutex) ); while( pGroup->nCurrentPage>pGroup->nMaxPage && pGroup->pLruTail ){ PgHdr1 *p = pGroup->pLruTail; @@ -572,6 +611,10 @@ static void pcache1EnforceMaxPage(PGroup *pGroup){ pcache1PinPage(p); pcache1RemoveFromHash(p, 1); } + if( pCache->nPage==0 && pCache->pBulk ){ + sqlite3_free(pCache->pBulk); + pCache->pBulk = pCache->pFree = 0; + } } /* @@ -647,6 +690,14 @@ static int pcache1Init(void *NotUsed){ pcache1.mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_PMEM); } #endif + if( pcache1.separateCache + && sqlite3GlobalConfig.nPage!=0 + && sqlite3GlobalConfig.pPage==0 + ){ + pcache1.nInitPage = sqlite3GlobalConfig.nPage; + }else{ + pcache1.nInitPage = 0; + } pcache1.grp.mxPinned = 10; pcache1.isInit = 1; return SQLITE_OK; @@ -701,36 +752,6 @@ static sqlite3_pcache *pcache1Create(int szPage, int szExtra, int bPurgeable){ pGroup->mxPinned = pGroup->nMaxPage + 10 - pGroup->nMinPage; } pcache1LeaveMutex(pGroup); - /* Try to initialize the local bulk pagecache line allocation if using - ** separate caches and if nPage!=0 */ - if( pcache1.separateCache - && sqlite3GlobalConfig.nPage!=0 - && sqlite3GlobalConfig.pPage==0 - ){ - int szBulk; - char *zBulk; - sqlite3BeginBenignMalloc(); - if( sqlite3GlobalConfig.nPage>0 ){ - szBulk = pCache->szAlloc * sqlite3GlobalConfig.nPage; - }else{ - szBulk = -1024*sqlite3GlobalConfig.nPage; - } - zBulk = pCache->pBulk = sqlite3Malloc( szBulk ); - sqlite3EndBenignMalloc(); - if( zBulk ){ - int nBulk = sqlite3MallocSize(zBulk)/pCache->szAlloc; - int i; - for(i=0; i<nBulk; i++){ - PgHdr1 *pX = (PgHdr1*)&zBulk[szPage]; - pX->page.pBuf = zBulk; - pX->page.pExtra = &pX[1]; - pX->isBulkLocal = 1; - pX->pNext = pCache->pFree; - pCache->pFree = pX; - zBulk += pCache->szAlloc; - } - } - } if( pCache->nHash==0 ){ pcache1Destroy((sqlite3_pcache*)pCache); pCache = 0; @@ -753,7 +774,7 @@ static void pcache1Cachesize(sqlite3_pcache *p, int nMax){ pGroup->mxPinned = pGroup->nMaxPage + 10 - pGroup->nMinPage; pCache->nMax = nMax; pCache->n90pct = pCache->nMax*9/10; - pcache1EnforceMaxPage(pGroup); + pcache1EnforceMaxPage(pCache); pcache1LeaveMutex(pGroup); } } @@ -771,7 +792,7 @@ static void pcache1Shrink(sqlite3_pcache *p){ pcache1EnterMutex(pGroup); savedMaxPage = pGroup->nMaxPage; pGroup->nMaxPage = 0; - pcache1EnforceMaxPage(pGroup); + pcache1EnforceMaxPage(pCache); pGroup->nMaxPage = savedMaxPage; pcache1LeaveMutex(pGroup); } @@ -1108,7 +1129,7 @@ static void pcache1Destroy(sqlite3_pcache *p){ assert( pGroup->nMinPage >= pCache->nMin ); pGroup->nMinPage -= pCache->nMin; pGroup->mxPinned = pGroup->nMaxPage + 10 - pGroup->nMinPage; - pcache1EnforceMaxPage(pGroup); + pcache1EnforceMaxPage(pCache); pcache1LeaveMutex(pGroup); sqlite3_free(pCache->pBulk); sqlite3_free(pCache->apHash); diff --git a/src/pragma.c b/src/pragma.c index 1b4213844..ffa068572 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -721,6 +721,7 @@ void sqlite3Pragma( case PragTyp_CACHE_SIZE: { assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); if( !zRight ){ + if( sqlite3ReadSchema(pParse) ) goto pragma_out; returnSingleInt(pParse, "cache_size", pDb->pSchema->cache_size); }else{ int size = sqlite3Atoi(zRight); diff --git a/src/pragma.h b/src/pragma.h index bbf141ee2..9e206dac4 100644 --- a/src/pragma.h +++ b/src/pragma.h @@ -86,7 +86,7 @@ static const struct sPragmaNames { #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) { /* zName: */ "cache_size", /* ePragTyp: */ PragTyp_CACHE_SIZE, - /* ePragFlag: */ PragFlag_NeedSchema, + /* ePragFlag: */ 0, /* iArg: */ 0 }, #endif #if !defined(SQLITE_OMIT_FLAG_PRAGMAS) diff --git a/src/printf.c b/src/printf.c index 72b9497d7..018df412f 100644 --- a/src/printf.c +++ b/src/printf.c @@ -1012,6 +1012,11 @@ char *sqlite3_snprintf(int n, char *zBuf, const char *zFormat, ...){ ** sqlite3_log() must render into a static buffer. It cannot dynamically ** allocate memory because it might be called while the memory allocator ** mutex is held. +** +** sqlite3VXPrintf() might ask for *temporary* memory allocations for +** certain format characters (%q) or for very large precisions or widths. +** Care must be taken that any sqlite3_log() calls that occur while the +** memory mutex is held do not use these mechanisms. */ static void renderLogMsg(int iErrCode, const char *zFormat, va_list ap){ StrAccum acc; /* String accumulator */ diff --git a/src/select.c b/src/select.c index 13de02942..8ac98f175 100644 --- a/src/select.c +++ b/src/select.c @@ -1082,7 +1082,6 @@ static KeyInfo *keyInfoFromExprList( return pInfo; } -#ifndef SQLITE_OMIT_COMPOUND_SELECT /* ** Name of the connection operator, used for error messages. */ @@ -1096,7 +1095,6 @@ static const char *selectOpName(int id){ } return z; } -#endif /* SQLITE_OMIT_COMPOUND_SELECT */ #ifndef SQLITE_OMIT_EXPLAIN /* @@ -2100,19 +2098,6 @@ static int multiSelectOrderBy( ); /* -** Error message for when two or more terms of a compound select have different -** size result sets. -*/ -void sqlite3SelectWrongNumTermsError(Parse *pParse, Select *p){ - if( p->selFlags & SF_Values ){ - sqlite3ErrorMsg(pParse, "all VALUES must have the same number of terms"); - }else{ - sqlite3ErrorMsg(pParse, "SELECTs to the left and right of %s" - " do not have the same number of result columns", selectOpName(p->op)); - } -} - -/* ** Handle the special case of a compound-select that originates from a ** VALUES clause. By handling this as a special case, we avoid deep ** recursion, and thus do not need to enforce the SQLITE_LIMIT_COMPOUND_SELECT @@ -2539,6 +2524,19 @@ multi_select_end: #endif /* SQLITE_OMIT_COMPOUND_SELECT */ /* +** Error message for when two or more terms of a compound select have different +** size result sets. +*/ +void sqlite3SelectWrongNumTermsError(Parse *pParse, Select *p){ + if( p->selFlags & SF_Values ){ + sqlite3ErrorMsg(pParse, "all VALUES must have the same number of terms"); + }else{ + sqlite3ErrorMsg(pParse, "SELECTs to the left and right of %s" + " do not have the same number of result columns", selectOpName(p->op)); + } +} + +/* ** Code an output subroutine for a coroutine implementation of a ** SELECT statment. ** diff --git a/src/sqlite.h.in b/src/sqlite.h.in index fcae1b147..3ddd8ece5 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -967,9 +967,9 @@ struct sqlite3_io_methods { ** The [SQLITE_FCNTL_ZIPVFS] opcode is implemented by zipvfs only. All other ** VFS should return SQLITE_NOTFOUND for this opcode. ** -** <li>[[SQLITE_FCNTL_OTA]] -** The [SQLITE_FCNTL_OTA] opcode is implemented by the special VFS used by -** the OTA extension only. All other VFS should return SQLITE_NOTFOUND for +** <li>[[SQLITE_FCNTL_RBU]] +** The [SQLITE_FCNTL_RBU] opcode is implemented by the special VFS used by +** the RBU extension only. All other VFS should return SQLITE_NOTFOUND for ** this opcode. ** </ul> */ @@ -997,7 +997,7 @@ struct sqlite3_io_methods { #define SQLITE_FCNTL_WIN32_SET_HANDLE 23 #define SQLITE_FCNTL_WAL_BLOCK 24 #define SQLITE_FCNTL_ZIPVFS 25 -#define SQLITE_FCNTL_OTA 26 +#define SQLITE_FCNTL_RBU 26 /* deprecated names */ #define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 6edb885c1..7d99d772f 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -189,7 +189,7 @@ ** Make sure that the compiler intrinsics we desire are enabled when ** compiling with an appropriate version of MSVC. */ -#if defined(_MSC_VER) && _MSC_VER>=1300 +#if defined(_MSC_VER) && _MSC_VER>=1300 && !defined(_WIN32_WCE) # include <intrin.h> # pragma intrinsic(_byteswap_ushort) # pragma intrinsic(_byteswap_ulong) @@ -754,7 +754,9 @@ extern const int sqlite3one; # if defined(__linux__) \ || defined(_WIN32) \ || (defined(__APPLE__) && defined(__MACH__)) \ - || defined(__sun) + || defined(__sun) \ + || defined(__FreeBSD__) \ + || defined(__DragonFly__) # define SQLITE_MAX_MMAP_SIZE 0x7fff0000 /* 2147418112 */ # else # define SQLITE_MAX_MMAP_SIZE 0 diff --git a/src/tclsqlite.c b/src/tclsqlite.c index 0f572bd01..608b3b2ba 100644 --- a/src/tclsqlite.c +++ b/src/tclsqlite.c @@ -3910,7 +3910,7 @@ static void init_all(Tcl_Interp *interp){ extern int TestSession_Init(Tcl_Interp*); #endif extern int Fts5tcl_Init(Tcl_Interp *); - extern int SqliteOta_Init(Tcl_Interp*); + extern int SqliteRbu_Init(Tcl_Interp*); #if defined(SQLITE_ENABLE_FTS3) || defined(SQLITE_ENABLE_FTS4) extern int Sqlitetestfts3_Init(Tcl_Interp *interp); #endif @@ -3957,7 +3957,7 @@ static void init_all(Tcl_Interp *interp){ TestSession_Init(interp); #endif Fts5tcl_Init(interp); - SqliteOta_Init(interp); + SqliteRbu_Init(interp); #if defined(SQLITE_ENABLE_FTS3) || defined(SQLITE_ENABLE_FTS4) Sqlitetestfts3_Init(interp); diff --git a/src/test1.c b/src/test1.c index 3885b71ca..15fd8c7f7 100644 --- a/src/test1.c +++ b/src/test1.c @@ -274,6 +274,9 @@ static int clang_sanitize_address( res = 1; # endif #endif +#ifdef __SANITIZE_ADDRESS__ + res = 1; +#endif if( res==0 && getenv("OMIT_MISUSE")!=0 ) res = 1; Tcl_SetObjResult(interp, Tcl_NewIntObj(res)); return TCL_OK; diff --git a/src/test_config.c b/src/test_config.c index eb30e2d25..1335ced67 100644 --- a/src/test_config.c +++ b/src/test_config.c @@ -442,10 +442,10 @@ Tcl_SetVar2(interp, "sqlite_options", "mergesort", "1", TCL_GLOBAL_ONLY); Tcl_SetVar2(interp, "sqlite_options", "or_opt", "1", TCL_GLOBAL_ONLY); #endif -#ifdef SQLITE_ENABLE_OTA - Tcl_SetVar2(interp, "sqlite_options", "ota", "1", TCL_GLOBAL_ONLY); +#ifdef SQLITE_ENABLE_RBU + Tcl_SetVar2(interp, "sqlite_options", "rbu", "1", TCL_GLOBAL_ONLY); #else - Tcl_SetVar2(interp, "sqlite_options", "ota", "0", TCL_GLOBAL_ONLY); + Tcl_SetVar2(interp, "sqlite_options", "rbu", "0", TCL_GLOBAL_ONLY); #endif #ifdef SQLITE_OMIT_PAGER_PRAGMAS @@ -648,9 +648,9 @@ static void walIndexWriteHdr(Wal *pWal){ pWal->hdr.isInit = 1; pWal->hdr.iVersion = WALINDEX_MAX_VERSION; walChecksumBytes(1, (u8*)&pWal->hdr, nCksum, 0, pWal->hdr.aCksum); - memcpy((void *)&aHdr[1], (void *)&pWal->hdr, sizeof(WalIndexHdr)); + memcpy((void*)&aHdr[1], (const void*)&pWal->hdr, sizeof(WalIndexHdr)); walShmBarrier(pWal); - memcpy((void *)&aHdr[0], (void *)&pWal->hdr, sizeof(WalIndexHdr)); + memcpy((void*)&aHdr[0], (const void*)&pWal->hdr, sizeof(WalIndexHdr)); } /* @@ -952,13 +952,13 @@ static void walCleanupHash(Wal *pWal){ ** via the hash table even after the cleanup. */ if( iLimit ){ - int i; /* Loop counter */ + int j; /* Loop counter */ int iKey; /* Hash key */ - for(i=1; i<=iLimit; i++){ - for(iKey=walHash(aPgno[i]); aHash[iKey]; iKey=walNextHash(iKey)){ - if( aHash[iKey]==i ) break; + for(j=1; j<=iLimit; j++){ + for(iKey=walHash(aPgno[j]); aHash[iKey]; iKey=walNextHash(iKey)){ + if( aHash[iKey]==j ) break; } - assert( aHash[iKey]==i ); + assert( aHash[iKey]==j ); } } #endif /* SQLITE_ENABLE_EXPENSIVE_ASSERT */ @@ -1460,7 +1460,7 @@ static void walMergesort( int nMerge = 0; /* Number of elements in list aMerge */ ht_slot *aMerge = 0; /* List to be merged */ int iList; /* Index into input list */ - int iSub = 0; /* Index into aSub array */ + u32 iSub = 0; /* Index into aSub array */ struct Sublist aSub[13]; /* Array of sub-lists */ memset(aSub, 0, sizeof(aSub)); @@ -1471,7 +1471,9 @@ static void walMergesort( nMerge = 1; aMerge = &aList[iList]; for(iSub=0; iList & (1<<iSub); iSub++){ - struct Sublist *p = &aSub[iSub]; + struct Sublist *p; + assert( iSub<ArraySize(aSub) ); + p = &aSub[iSub]; assert( p->aList && p->nList<=(1<<iSub) ); assert( p->aList==&aList[iList&~((2<<iSub)-1)] ); walMerge(aContent, p->aList, p->nList, &aMerge, &nMerge, aBuffer); @@ -1482,7 +1484,9 @@ static void walMergesort( for(iSub++; iSub<ArraySize(aSub); iSub++){ if( nList & (1<<iSub) ){ - struct Sublist *p = &aSub[iSub]; + struct Sublist *p; + assert( iSub<ArraySize(aSub) ); + p = &aSub[iSub]; assert( p->nList<=(1<<iSub) ); assert( p->aList==&aList[nList&~((2<<iSub)-1)] ); walMerge(aContent, p->aList, p->nList, &aMerge, &nMerge, aBuffer); diff --git a/src/wherecode.c b/src/wherecode.c index e1f0f8661..9747f7f37 100644 --- a/src/wherecode.c +++ b/src/wherecode.c @@ -1296,7 +1296,11 @@ Bitmask sqlite3WhereCodeOneLoopStart( r = sqlite3GetTempRange(pParse, nPk); for(iPk=0; iPk<nPk; iPk++){ int iCol = pPk->aiColumn[iPk]; - sqlite3ExprCodeGetColumn(pParse, pTab, iCol, iCur, r+iPk, 0); + int rx; + rx = sqlite3ExprCodeGetColumn(pParse, pTab, iCol, iCur,r+iPk,0); + if( rx!=r+iPk ){ + sqlite3VdbeAddOp2(v, OP_SCopy, rx, r+iPk); + } } /* Check if the temp table already contains this key. If so, diff --git a/test/fuzz3.test b/test/fuzz3.test index 2b21404f4..e54b81114 100644 --- a/test/fuzz3.test +++ b/test/fuzz3.test @@ -21,6 +21,13 @@ source $testdir/tester.tcl # These tests deal with corrupt database files # database_may_be_corrupt +db close +sqlite3_shutdown +sqlite3_config_pagecache 0 0 +sqlite3_initialize +autoinstall_test_functions +sqlite3 db test.db + expr srand(123) diff --git a/test/malloc5.test b/test/malloc5.test index 2b8ba74e5..3f5208acc 100644 --- a/test/malloc5.test +++ b/test/malloc5.test @@ -20,6 +20,11 @@ # # $Id: malloc5.test,v 1.22 2009/04/11 19:09:54 drh Exp $ +sqlite3_shutdown +sqlite3_config_pagecache 0 100 +sqlite3_initialize +autoinstall_test_functions + set testdir [file dirname $argv0] source $testdir/tester.tcl source $testdir/malloc_common.tcl @@ -41,6 +46,7 @@ ifcapable !memorymanage { sqlite3_soft_heap_limit 0 sqlite3 db test.db +db eval {PRAGMA cache_size=1} do_test malloc5-1.1 { # Simplest possible test. Call sqlite3_release_memory when there is exactly @@ -61,15 +67,14 @@ do_test malloc5-1.2 { # not the case before version 3.6.2). # sqlite3 db2 test.db - execsql { SELECT * FROM sqlite_master } db2 + execsql {PRAGMA cache_size=2; SELECT * FROM sqlite_master } db2 } {} do_test malloc5-1.3 { # Call [sqlite3_release_memory] when there is exactly one unused page # in the cache belonging to db2. # set ::pgalloc [sqlite3_release_memory] - expr $::pgalloc > 0 -} {1} +} {0} # The sizes of memory allocations from system malloc() might vary, # depending on the memory allocator algorithms used. The following @@ -231,6 +236,7 @@ do_test malloc5-4.1 { expr $nMaxBytes > 1000000 } {1} do_test malloc5-4.2 { + db eval {PRAGMA cache_size=1} db cache flush sqlite3_release_memory sqlite3_soft_heap_limit 100000 @@ -302,7 +308,7 @@ do_test malloc5-6.1.1 { sqlite3 db test.db execsql { PRAGMA page_size=1024; - PRAGMA default_cache_size=10; + PRAGMA default_cache_size=2; } execsql { PRAGMA temp_store = memory; @@ -325,24 +331,25 @@ do_test malloc5-6.1.1 { } forcecopy test.db test2.db sqlite3 db2 test2.db + db2 eval {PRAGMA cache_size=2} list \ [expr ([file size test.db]/1024)>20] [expr ([file size test2.db]/1024)>20] } {1 1} do_test malloc5-6.1.2 { list [execsql {PRAGMA cache_size}] [execsql {PRAGMA cache_size} db2] -} {10 10} +} {2 2} do_test malloc5-6.2.1 { execsql {SELECT * FROM abc} db2 execsql {SELECT * FROM abc} db expr [nPage db] + [nPage db2] -} {20} +} {4} do_test malloc5-6.2.2 { # If we now try to reclaim some memory, it should come from the db2 cache. sqlite3_release_memory 3000 expr [nPage db] + [nPage db2] -} {17} +} {4} do_test malloc5-6.2.3 { # Access the db2 cache again, so that all the db2 pages have been used # more recently than all the db pages. Then try to reclaim 3000 bytes. @@ -350,7 +357,7 @@ do_test malloc5-6.2.3 { execsql { SELECT * FROM abc } db2 sqlite3_release_memory 3000 expr [nPage db] + [nPage db2] -} {17} +} {4} do_test malloc5-6.3.1 { # Now open a transaction and update 2 pages in the db2 cache. Then @@ -367,19 +374,19 @@ do_test malloc5-6.3.1 { } db2 execsql { SELECT * FROM abc } db expr [nPage db] + [nPage db2] -} {20} +} {4} do_test malloc5-6.3.2 { # Try to release 7700 bytes. This should release all the # non-dirty pages held by db2. sqlite3_release_memory [expr 7*1132] list [nPage db] [nPage db2] -} {10 3} +} {1 3} do_test malloc5-6.3.3 { # Try to release another 1000 bytes. This should come fromt the db # cache, since all three pages held by db2 are either in-use or diry. sqlite3_release_memory 1000 list [nPage db] [nPage db2] -} {9 3} +} {1 3} do_test malloc5-6.3.4 { # Now release 9900 more (about 9 pages worth). This should expunge # the rest of the db cache. But the db2 cache remains intact, because @@ -390,20 +397,20 @@ do_test malloc5-6.3.4 { sqlite3_release_memory 9900 } list [nPage db] [nPage db2] -} {0 3} +} {1 3} do_test malloc5-6.3.5 { # But if we are really insistent, SQLite will consent to call sync() # if there is no other option. UPDATE: As of 3.6.2, SQLite will not # call sync() in this scenario. So no further memory can be reclaimed. sqlite3_release_memory 1000 list [nPage db] [nPage db2] -} {0 3} +} {1 3} do_test malloc5-6.3.6 { # The referenced page (page 1 of the db2 cache) will not be freed no # matter how much memory we ask for: sqlite3_release_memory 31459 list [nPage db] [nPage db2] -} {0 3} +} {1 3} db2 close diff --git a/test/pcache.test b/test/pcache.test index 0766fce08..5d9d93edb 100644 --- a/test/pcache.test +++ b/test/pcache.test @@ -73,7 +73,7 @@ do_test pcache-1.4 { do_test pcache-1.5 { sqlite3 db2 test.db - execsql "PRAGMA cache_size=10" db2 + execsql "PRAGMA cache_size; PRAGMA cache_size=10" db2 pcache_stats } {current 11 max 22 min 20 recyclable 1} diff --git a/test/pcache2.test b/test/pcache2.test index 1c15b8b56..c59dfb25d 100644 --- a/test/pcache2.test +++ b/test/pcache2.test @@ -36,13 +36,13 @@ do_test pcache2-1.1 { do_test pcache2-1.2 { forcedelete test.db test.db-journal sqlite3 db test.db - db eval {PRAGMA cache_size=10} + db eval {PRAGMA cache_size=10; SELECT 1 FROM sqlite_master;} lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0] 1 } {2} do_test pcache2-1.3 { forcedelete test2.db test2.db-journal sqlite3 db2 test2.db - db2 eval {PRAGMA cache_size=50} + db2 eval {PRAGMA cache_size=50; SELECT 1 FROM sqlite_master;} lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0] 1 } {4} diff --git a/test/permutations.test b/test/permutations.test index 7298ed28f..747b663d3 100644 --- a/test/permutations.test +++ b/test/permutations.test @@ -117,7 +117,7 @@ set allquicktests [test_set $alltests -exclude { vtab_err.test walslow.test walcrash.test walcrash3.test walthread.test rtree3.test indexfault.test securedel2.test sort3.test sort4.test fts4growth.test fts4growth2.test - bigsort.test ota.test + bigsort.test rbu.test }] if {[info exists ::env(QUICKTEST_INCLUDE)]} { set allquicktests [concat $allquicktests $::env(QUICKTEST_INCLUDE)] @@ -986,10 +986,10 @@ test_suite "session_strm" -description { set ::sqlite3session_streams 1 } -test_suite "ota" -description { - OTA tests. +test_suite "rbu" -description { + RBU tests. } -files [ - test_set [glob -nocomplain $::testdir/../ext/ota/*.test] -exclude ota.test + test_set [glob -nocomplain $::testdir/../ext/rbu/*.test] -exclude rbu.test ] test_suite "no_optimization" -description { diff --git a/test/ota.test b/test/rbu.test index 9dc01c2b3..405419507 100644 --- a/test/ota.test +++ b/test/rbu.test @@ -5,14 +5,13 @@ # May you share freely, never taking more than you give. # #*********************************************************************** -# This file runs all rtree related tests. +# This file runs all RBU related tests. # set testdir [file dirname $argv0] source $testdir/permutations.test -ifcapable !ota { finish_test ; return } +ifcapable !rbu { finish_test ; return } -run_test_suite ota +run_test_suite rbu finish_test - diff --git a/test/releasetest.tcl b/test/releasetest.tcl index 6e475c9d2..43473e2a0 100644 --- a/test/releasetest.tcl +++ b/test/releasetest.tcl @@ -116,7 +116,7 @@ array set ::Configs [strip_comments { -DSQLITE_ENABLE_FTS4=1 -DSQLITE_ENABLE_RTREE=1 -DSQLITE_ENABLE_STAT4 - -DSQLITE_ENABLE_OTA + -DSQLITE_ENABLE_RBU -DSQLITE_MAX_ATTACHED=125 } "Device-One" { diff --git a/test/skipscan1.test b/test/skipscan1.test index 4f996df97..ac2671160 100644 --- a/test/skipscan1.test +++ b/test/skipscan1.test @@ -292,4 +292,34 @@ do_execsql_test skipscan1-7.3 { EXPLAIN QUERY PLAN SELECT * FROM t1 WHERE b=1; } {~/ANY/} +# Ticket 8fd39115d8f46ece70e7d4b3c481d1bd86194746 2015-07-23 +# Incorrect code generated for a skipscan within an OR optimization +# on a WITHOUT ROWID table. +# +do_execsql_test skipscan1-8.1 { + DROP TABLE IF EXISTS t1; + CREATE TABLE t1(x, y, PRIMARY KEY(x,y)) WITHOUT ROWID; + INSERT INTO t1(x,y) VALUES(1,'AB'); + INSERT INTO t1(x,y) VALUES(2,'CD'); + ANALYZE; + DROP TABLE IF EXISTS sqlite_stat4; + DELETE FROM sqlite_stat1; + INSERT INTO sqlite_stat1(tbl,idx,stat) VALUES('t1','t1','1000000 100 1'); + ANALYZE sqlite_master; + SELECT * FROM t1 + WHERE (y = 'AB' AND x <= 4) + OR (y = 'EF' AND x = 5); +} {1 AB} +do_execsql_test skipscan1-8.1eqp { + EXPLAIN QUERY PLAN + SELECT * FROM t1 + WHERE (y = 'AB' AND x <= 4) + OR (y = 'EF' AND x = 5); +} {/ANY/} +do_execsql_test skipscan1-8.2 { + SELECT * FROM t1 + WHERE y = 'AB' OR (y = 'CD' AND x = 2) + ORDER BY +x; +} {1 AB 2 CD} + finish_test diff --git a/test/speedtest1.c b/test/speedtest1.c index 9ac9fbb96..b34dae65a 100644 --- a/test/speedtest1.c +++ b/test/speedtest1.c @@ -51,8 +51,8 @@ static const char zHelp[] = #if SQLITE_VERSION_NUMBER<3005000 # define sqlite3_int64 sqlite_int64 #endif -#ifdef SQLITE_ENABLE_OTA -# include "sqlite3ota.h" +#ifdef SQLITE_ENABLE_RBU +# include "sqlite3rbu.h" #endif /* All global state is held in this structure */ @@ -1240,10 +1240,10 @@ int main(int argc, char **argv){ noSync = 1; }else if( strcmp(z,"notnull")==0 ){ g.zNN = "NOT NULL"; -#ifdef SQLITE_ENABLE_OTA - }else if( strcmp(z,"ota")==0 ){ - sqlite3ota_create_vfs("ota", 0); - sqlite3_vfs_register(sqlite3_vfs_find("ota"), 1); +#ifdef SQLITE_ENABLE_RBU + }else if( strcmp(z,"rbu")==0 ){ + sqlite3ota_create_vfs("rbu", 0); + sqlite3_vfs_register(sqlite3_vfs_find("rbu"), 1); #endif }else if( strcmp(z,"pagesize")==0 ){ if( i>=argc-1 ) fatal_error("missing argument on %s\n", argv[i]); diff --git a/tool/mkpragmatab.tcl b/tool/mkpragmatab.tcl index cb3aed0ff..bbdf9da75 100644 --- a/tool/mkpragmatab.tcl +++ b/tool/mkpragmatab.tcl @@ -170,7 +170,6 @@ set pragma_def { IF: !defined(SQLITE_OMIT_PAGER_PRAGMAS) NAME: cache_size - FLAG: NeedSchema IF: !defined(SQLITE_OMIT_PAGER_PRAGMAS) NAME: mmap_size diff --git a/tool/mksqlite3c-noext.tcl b/tool/mksqlite3c-noext.tcl index 0e1d0fcd1..601b8cce8 100644 --- a/tool/mksqlite3c-noext.tcl +++ b/tool/mksqlite3c-noext.tcl @@ -180,6 +180,10 @@ proc copy_file {filename} { copy_file tsrc/$hdr section_comment "Continuing where we left off in $tail" if {$linemacros} {puts $out "#line [expr {$ln+1}] \"$filename\""} + } else { + # Comment out the entire line, replacing any nested comment + # begin/end markers with the harmless substring "**". + puts $out "/* [string map [list /* ** */ **] $line] */" } } elseif {![info exists seen_hdr($hdr)]} { if {![regexp {/\*\s+amalgamator:\s+dontcache\s+\*/} $line]} { diff --git a/tool/mksqlite3c.tcl b/tool/mksqlite3c.tcl index b326de254..f2f949e40 100644 --- a/tool/mksqlite3c.tcl +++ b/tool/mksqlite3c.tcl @@ -115,7 +115,7 @@ foreach hdr { sqlite3ext.h sqlite3.h sqlite3ext.h - sqlite3ota.h + sqlite3rbu.h sqliteicu.h sqliteInt.h sqliteLimit.h @@ -191,6 +191,10 @@ proc copy_file {filename} { copy_file tsrc/$hdr section_comment "Continuing where we left off in $tail" if {$linemacros} {puts $out "#line [expr {$ln+1}] \"$filename\""} + } else { + # Comment out the entire line, replacing any nested comment + # begin/end markers with the harmless substring "**". + puts $out "/* [string map [list /* ** */ **] $line] */" } } elseif {![info exists seen_hdr($hdr)]} { if {![regexp {/\*\s+amalgamator:\s+dontcache\s+\*/} $line]} { @@ -375,7 +379,7 @@ foreach file { rtree.c icu.c fts3_icu.c - sqlite3ota.c + sqlite3rbu.c dbstat.c sqlite3session.c } { |