]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Fix some problems with OTA and empty target databases, or target databases with the...
authordan <dan@noemail.net>
Thu, 5 Mar 2015 16:21:20 +0000 (16:21 +0000)
committerdan <dan@noemail.net>
Thu, 5 Mar 2015 16:21:20 +0000 (16:21 +0000)
FossilOrigin-Name: 46119e8d8e391d8dea844352521b58415f7365b1

ext/ota/ota.c
ext/ota/ota1.test
ext/ota/sqlite3ota.c
ext/ota/sqlite3ota.h
main.mk
manifest
manifest.uuid
test/speedtest1.c

index febdbfe2da9ee19eb11eae2ad4efc7e7a2974d32..59e783b6eb8389092f03d075b587b549adfef1a9 100644 (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);
index a2ebd56c427657e80945d3b806d7dc7f6802d42f..db52bdb7abc6cb5438a2b4f35f128755cb2274c2 100644 (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
 }
index 39f986f9d8d90cb9c8c1460fb9834f2344ff7e84..2cafaaa569d275b7e3d5136c9b9c4e15e16a5202 100644 (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;
 }
 
 /*
index d1a11948ea5374602681599363ed763f3ede7fc8..c48a6b38f5cf19e2cf2ab5317a23b0b50662b4f6 100644 (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);
diff --git a/main.mk b/main.mk
index 40e5e1a8734325a98f3c9cc61b5de998bb8e5df6..a41a86acd66007a3307fea0850f4c2a665b45a65 100644 (file)
--- a/main.mk
+++ b/main.mk
@@ -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
index 84de50ad735fcd15fed77b7e1263b41d004e0496..5e8cdc587f56c8355339ce1fad0a4cb75915ccf4 100644 (file)
--- a/manifest
+++ b/manifest
@@ -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
index 665b4f66c2b648539f61967c750b9780c57b5131..d8a0339114350ca4ba3600e4839960bf0432e134 100644 (file)
@@ -1 +1 @@
-158c1a48818a9abc001b9ea547167c2624a7bad3
\ No newline at end of file
+46119e8d8e391d8dea844352521b58415f7365b1
\ No newline at end of file
index 93f7d145eebb1c24497fab153aeff3de4e77fe96..8f3f579557ae3949eccaf5f17e271af38a606b54 100644 (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]);