Fix some problems with OTA and empty target databases, or target databases with the wrong set of tables. Also add SQLITE_FCNTL_VFSNAME support to the OTA VFS.

FossilOrigin-Name: 46119e8d8e391d8dea844352521b58415f7365b1
This commit is contained in:
dan 2015-03-05 16:21:20 +00:00
parent 2bd7ace54e
commit 54fc21438e
8 changed files with 87 additions and 25 deletions

View File

@ -44,7 +44,21 @@ void usage(const char *zArgv0){
void report_default_vfs(){
sqlite3_vfs *pVfs = sqlite3_vfs_find(0);
fprintf(stdout, "using vfs \"%s\"\n", pVfs->zName);
fprintf(stdout, "default vfs is \"%s\"\n", pVfs->zName);
}
void report_ota_vfs(sqlite3ota *pOta){
if( pOta ){
sqlite3 *db = sqlite3ota_db(pOta, 0);
char *zName = 0;
sqlite3_file_control(db, "main", SQLITE_FCNTL_VFSNAME, &zName);
if( zName ){
fprintf(stdout, "using vfs \"%s\"\n", zName);
}else{
fprintf(stdout, "vfs name not available\n");
}
sqlite3_free(zName);
}
}
int main(int argc, char **argv){
@ -76,6 +90,7 @@ int main(int argc, char **argv){
** or an error occurs. Or, if nStep is greater than zero, call
** sqlite3ota_step() a maximum of nStep times. */
pOta = sqlite3ota_open(zTarget, zOta);
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);

View File

@ -548,7 +548,18 @@ foreach {tn3 create_vfs destroy_vfs} {
CREATE TABLE ota.data_t1(a, b, ota_control);
INSERT INTO ota.data_t1 VALUES(1, 2, 2);
} {SQLITE_ERROR - invalid ota_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);
} {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);
} {SQLITE_ERROR - no such table: t2}
} {
reset_db
forcedelete ota.db
@ -561,6 +572,14 @@ foreach {tn3 create_vfs destroy_vfs} {
}
}
# Test that an OTA database containing no input tables is handled
# correctly.
reset_db
forcedelete ota.db
do_test $tn3.7 {
list [catch { run_ota test.db ota.db } msg] $msg
} {0 SQLITE_DONE}
catch { db close }
eval $destroy_vfs
}

View File

@ -835,6 +835,10 @@ static int otaObjIterCacheTableInfo(sqlite3ota *p, OtaObjIter *pIter){
/* 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 ){
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;
@ -2618,16 +2622,22 @@ sqlite3ota *sqlite3ota_open(const char *zTarget, const char *zOta){
if( p->rc==SQLITE_OK ){
p->rc = sqlite3_exec(p->dbOta, "BEGIN IMMEDIATE", 0, 0, &p->zErrmsg);
}
assert( p->rc!=SQLITE_OK || p->pTargetFd->pWalFd );
/* Point the object iterator at the first object */
if( p->rc==SQLITE_OK ){
p->rc = otaObjIterFirst(p, &p->objiter);
}
/* If the OTA database contains no data_xxx tables, declare the OTA
** update finished. */
if( p->rc==SQLITE_OK && p->objiter.zTbl==0 ){
p->rc = SQLITE_DONE;
}
if( p->rc==SQLITE_OK ){
otaSetupOal(p, pState);
}
}else if( p->eStage==OTA_STAGE_MOVE ){
/* no-op */
}else if( p->eStage==OTA_STAGE_CKPT ){
@ -2970,10 +2980,10 @@ static int otaVfsCheckReservedLock(sqlite3_file *pFile, int *pResOut){
static int otaVfsFileControl(sqlite3_file *pFile, int op, void *pArg){
ota_file *p = (ota_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) );
if( op==SQLITE_FCNTL_OTA ){
int rc;
sqlite3ota *pOta = (sqlite3ota*)pArg;
/* First try to find another OTA vfs lower down in the vfs stack. If
@ -2998,7 +3008,17 @@ static int otaVfsFileControl(sqlite3_file *pFile, int op, void *pArg){
}
return rc;
}
return xControl(p->pReal, op, pArg);
rc = xControl(p->pReal, op, pArg);
if( rc==SQLITE_OK && op==SQLITE_FCNTL_VFSNAME ){
ota_vfs *pOtaVfs = p->pOtaVfs;
char *zIn = *(char**)pArg;
char *zOut = sqlite3_mprintf("ota(%s)/%z", pOtaVfs->base.zName, zIn);
*(char**)pArg = zOut;
if( zOut==0 ) rc = SQLITE_NOMEM;
}
return rc;
}
/*

View File

@ -334,14 +334,14 @@ sqlite3_int64 sqlite3ota_progress(sqlite3ota *pOta);
** to assemble an OTA enabled VFS stack that uses both zipvfs and
** multiplexor (error checking omitted):
**
** // Create a VFS named "multiplexor" (not the default).
** sqlite3_multiplex_initialize("multiplexor", 0);
** // 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
** // access the file-system via the system default VFS, bypassing the
** // multiplexor.
** sqlite3ota_create_vfs("ota", "multiplexor");
** sqlite3ota_create_vfs("ota", "multiplex");
**
** // Create a zipvfs VFS named "zipvfs" that uses ota.
** zipvfs_create_vfs_v3("zipvfs", "ota", 0, xCompressorAlgorithmDetector);

View File

@ -688,11 +688,10 @@ wordcount$(EXE): $(TOP)/test/wordcount.c sqlite3.c
$(TOP)/test/wordcount.c sqlite3.c
speedtest1$(EXE): $(TOP)/test/speedtest1.c sqlite3.o
$(TCC) -I. -o speedtest1$(EXE) $(TOP)/test/speedtest1.c sqlite3.o $(THREADLIB)
$(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 $(TOP)/ext/ota/sqlite3ota.c sqlite3.o \
$(TCC) -I. -o ota$(EXE) $(TOP)/ext/ota/ota.c sqlite3.o \
$(THREADLIB)
# This target will fail if the SQLite amalgamation contains any exported

View File

@ -1,5 +1,5 @@
C Add\scomments\sto\ssqlite3ota.h\sto\smake\sit\sclear\sthat\spassing\sNULL\sin\splace\sof\sa\sparent\sVFS\sname\sto\ssqlite3ota_create_vfs()\scauses\sthe\snew\sVFS\sto\suse\sthe\ssystem\sdefault\sas\sits\sparent.
D 2015-03-05T14:07:25.199
C Fix\ssome\sproblems\swith\sOTA\sand\sempty\starget\sdatabases,\sor\starget\sdatabases\swith\sthe\swrong\sset\sof\stables.\sAlso\sadd\sSQLITE_FCNTL_VFSNAME\ssupport\sto\sthe\sOTA\sVFS.
D 2015-03-05T16:21:20.067
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in 6b9e7677829aa94b9f30949656e27312aefb9a46
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@ -123,8 +123,8 @@ 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 c11a85af71dccc45976622fe7a51169a481caa91
F ext/ota/ota1.test 66cf5cb7fb1b2fcf74b9ec3fca2b5bf0286ae330
F ext/ota/ota.c feb0a11f720a8f30d2bebb835bba3c131a725685
F ext/ota/ota1.test 1684d4a1c4137190368ee5fd31c91b223172ed89
F ext/ota/ota10.test 85e0f6e7964db5007590c1b299e75211ed4240d4
F ext/ota/ota11.test 2f606cd2b4af260a86b549e91b9f395450fc75cb
F ext/ota/ota12.test 0dff44474de448fb4b0b28c20da63273a4149abb
@ -138,8 +138,8 @@ F ext/ota/otaA.test ef4bfa8cfd4ed814ae86f7457b64aa2f18c90171
F ext/ota/otacrash.test a078d34e2edbcedac5f894e3e7d08d452a327007
F ext/ota/otafault.test 8c43586c2b96ca16bbce00b5d7e7d67316126db8
F ext/ota/otafault2.test fa202a98ca221faec318f3e5c5f39485b1256561
F ext/ota/sqlite3ota.c f0ee6872b833c14c02101affc42e2f29ede54fec
F ext/ota/sqlite3ota.h d85a579448f5cb2cf042c63abefd1a440c46c962
F ext/ota/sqlite3ota.c 252a59574d1a6e9085d5d884a5c168db0e1f28e5
F ext/ota/sqlite3ota.h 5fec920aa2a9744be40c07da32dbe0b94a217e0f
F ext/ota/test_ota.c e34c801c665d64b4b9e00b71f1acf8c652404b2b
F ext/rtree/README 6315c0d73ebf0ec40dedb5aa0e942bc8b54e3761
F ext/rtree/rtree.c 14e6239434d4e3f65d3e90320713f26aa24e167f
@ -170,7 +170,7 @@ F ext/userauth/userauth.c 5fa3bdb492f481bbc1709fc83c91ebd13460c69e
F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x
F ltmain.sh 3ff0879076df340d2e23ae905484d8c15d5fdea8
F magic.txt 8273bf49ba3b0c8559cb2774495390c31fd61c60
F main.mk aac7f4bf0da24bd23faf1847d83f6b959e5a1635
F main.mk 584d60a533f4301ec660d54a6057970a7ee913c3
F mkopcodec.awk c2ff431854d702cdd2d779c9c0d1f58fa16fa4ea
F mkopcodeh.awk c6b3fa301db6ef7ac916b14c60868aeaec1337b5
F mkso.sh fd21c06b063bb16a5d25deea1752c2da6ac3ed83
@ -907,7 +907,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 2b416dca3a155fcaa849540b2e7fc1df12896c23
F test/speedtest1.c 9f1b745c24886cced3f70ffc666300152a39013c
F test/spellfix.test 24f676831acddd2f4056a598fd731a72c6311f49
F test/sqllimits1.test 9014524e7ab16e2a4976b13397db4c29cc29c6d9
F test/stat.test 76fd746b85459e812a0193410fb599f0531f22de
@ -1258,7 +1258,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
P 04087dec4c3db5f322eca289585525b7267ed4f8
R 1c3da4ddcbca798e150df95ec9fb5930
P 158c1a48818a9abc001b9ea547167c2624a7bad3
R 7821567dbf824c3a63e6bcb2750b28bb
U dan
Z 394f4029bb7037e7ee9a54787f07d0e0
Z 8ad790ee74643fcdb7735e278f227f09

View File

@ -1 +1 @@
158c1a48818a9abc001b9ea547167c2624a7bad3
46119e8d8e391d8dea844352521b58415f7365b1

View File

@ -43,6 +43,10 @@ static const char zHelp[] =
#include <string.h>
#include <ctype.h>
#ifdef SQLITE_ENABLE_OTA
# include "sqlite3ota.h"
#endif
/* All global state is held in this structure */
static struct Global {
sqlite3 *db; /* The open database connection */
@ -534,7 +538,7 @@ void testset_main(void){
speedtest1_exec("COMMIT");
speedtest1_end_test();
n = 10; //g.szTest/5;
n = 10; /* g.szTest/5; */
speedtest1_begin_test(145, "%d SELECTS w/ORDER BY and LIMIT, unindexed", n);
speedtest1_exec("BEGIN");
speedtest1_prepare(
@ -1204,6 +1208,11 @@ 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);
#endif
}else if( strcmp(z,"pagesize")==0 ){
if( i>=argc-1 ) fatal_error("missing argument on %s\n", argv[i]);
pageSize = integerValue(argv[++i]);