]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add a command line program that uses the extension. This serves as example code and...
authordan <dan@noemail.net>
Wed, 3 Sep 2014 08:25:09 +0000 (08:25 +0000)
committerdan <dan@noemail.net>
Wed, 3 Sep 2014 08:25:09 +0000 (08:25 +0000)
FossilOrigin-Name: ffa1524ef2a4c32652183eb4745685f0d1c93af2

ext/ota/ota.c [new file with mode: 0644]
ext/ota/sqlite3ota.h
main.mk
manifest
manifest.uuid

diff --git a/ext/ota/ota.c b/ext/ota/ota.c
new file mode 100644 (file)
index 0000000..c9d576f
--- /dev/null
@@ -0,0 +1,92 @@
+/*
+** 2014 August 30
+**
+** The author disclaims copyright to this source code.  In place of
+** a legal notice, here is a blessing:
+**
+**    May you do good and not evil.
+**    May you find forgiveness for yourself and forgive others.
+**    May you share freely, never taking more than you give.
+**
+*************************************************************************
+**
+** This file contains a command-line application that uses the OTA 
+** extension. See the usage() function below for an explanation.
+*/
+
+#include "sqlite3ota.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+/*
+** Print a usage message and exit.
+*/
+void usage(const char *zArgv0){
+  fprintf(stderr, 
+"Usage: %s [-step NSTEP] TARGET-DB OTA-DB\n"
+"\n"
+"  Argument OTA-DB must be an OTA 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"
+"  target db.\n"
+"\n"
+, zArgv0);
+  exit(1);
+}
+
+int main(int argc, char **argv){
+  int i;
+  const char *zTarget;            /* Target database to apply OTA to */
+  const char *zOta;               /* Database containing OTA */
+  char *zErrmsg;                  /* Error message, if any */
+  sqlite3ota *pOta;               /* OTA handle */
+  int nStep = 0;                  /* Maximum number of step() calls */
+  int rc;
+
+  /* Process command line arguments. Following this block local variables 
+  ** zTarget, zOta 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]);
+    nStep = atoi(argv[2]);
+  }else if( argc!=3 ){
+    usage(argv[0]);
+  }
+  zTarget = argv[argc-2];
+  zOta = argv[argc-1];
+
+  /* Open an OTA handle. If nStep is less than or equal to zero, call
+  ** sqlite3ota_step() until either the OTA 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);
+  for(i=0; (nStep<=0 || i<nStep) && sqlite3ota_step(pOta)==SQLITE_OK; i++);
+  rc = sqlite3ota_close(pOta, &zErrmsg);
+
+  /* Let the user know what happened. */
+  switch( rc ){
+    case SQLITE_OK:
+      fprintf(stdout, "SQLITE_OK: ota update incomplete\n");
+      break;
+
+    case SQLITE_DONE:
+      fprintf(stdout, "SQLITE_DONE: ota update completed\n");
+      break;
+
+    default:
+      fprintf(stderr, "error=%d: %s\n", rc, zErrmsg);
+      break;
+  }
+
+  sqlite3_free(zErrmsg);
+  return (rc==SQLITE_OK || rc==SQLITE_DONE) ? 0 : 1;
+}
+
index 0e577520b283a0f9f417017894e6f42ee78aa2f5..12832674c7f94bf8efdc4d8a4a3295fe258d88fe 100644 (file)
 ** corresponding columns of the data_% table. The values stored in the
 ** other columns are not used.
 **
-** For each row to DELETE from the target database as part of the OTA 
+** For each row to UPDATE from the target database as part of the OTA 
 ** update, the corresponding data_% table should contain a single record
 ** with the "ota_control" column set to contain a value of type text.
 ** The real primary key values identifying the row to update should be 
 #ifndef _SQLITE3OTA_H
 #define _SQLITE3OTA_H
 
+#include <sqlite3.h>              /* Required for error code definitions */
+
 typedef struct sqlite3ota sqlite3ota;
 
 /*
diff --git a/main.mk b/main.mk
index b225e4ecd0fbb2bb1a458017911ba5f70d2b82fe..0c4a27501f1e661232d4b3138c803bd4d9e87bb9 100644 (file)
--- a/main.mk
+++ b/main.mk
@@ -665,6 +665,11 @@ wordcount$(EXE):   $(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)
 
+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 \
+         $(THREADLIB)
+
 # This target will fail if the SQLite amalgamation contains any exported
 # symbols that do not begin with "sqlite3_". It is run as part of the
 # releasetest.tcl script.
index da360992c22e4506fc59229889187c2a10932f9f..ca224c9b1ef3ee3ce13f9c2d3491db7b04b08bc7 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Add\san\sexperimental\sextension\sfor\sapplying\sbulk\supdates\sto\sdatabases.
-D 2014-09-02T19:59:40.729
+C Add\sa\scommand\sline\sprogram\sthat\suses\sthe\sextension.\sThis\sserves\sas\sexample\scode\sand\sis\salso\suseful\sfor\sperformance\stesting.
+D 2014-09-03T08:25:09.548
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in cf57f673d77606ab0f2d9627ca52a9ba1464146a
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -121,10 +121,11 @@ 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 4b48add9494f29144343f513aaac226ca5782189
 F ext/ota/ota1.test ea2865997ce573fadaf12eb0a0f80ef22d9dd77f
 F ext/ota/ota2.test 4f7abfe1dfb7c3709bf45e94f3e65f3839b4f115
 F ext/ota/sqlite3ota.c ad55821883e4110367a30ffca282032d2bf36e45
-F ext/ota/sqlite3ota.h d3187a98fe1e3445c58f7a27d96ac385b78486a1
+F ext/ota/sqlite3ota.h 545f0008b5f02f2595899cb9841caddada5c17c0
 F ext/rtree/README 6315c0d73ebf0ec40dedb5aa0e942bc8b54e3761
 F ext/rtree/rtree.c 57bec53e1a677ab74217fe1f20a58c3a47261d6b
 F ext/rtree/rtree.h 834dbcb82dc85b2481cde6a07cdadfddc99e9b9e
@@ -151,7 +152,7 @@ F ext/rtree/viewrtree.tcl eea6224b3553599ae665b239bd827e182b466024
 F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x
 F ltmain.sh 3ff0879076df340d2e23ae905484d8c15d5fdea8
 F magic.txt 8273bf49ba3b0c8559cb2774495390c31fd61c60
-F main.mk 566c36f247d19525264e584466b5f07c0a48302e
+F main.mk ed2e37f6cd016ecc614165b3392bdbf89a129b4a
 F mkopcodec.awk c2ff431854d702cdd2d779c9c0d1f58fa16fa4ea
 F mkopcodeh.awk c6b3fa301db6ef7ac916b14c60868aeaec1337b5
 F mkso.sh fd21c06b063bb16a5d25deea1752c2da6ac3ed83
@@ -1197,10 +1198,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 9779c7a9eb1e2bd36e9286331a9314f064014d80
-R 5df4197c767caad19feca7391f16a42d
-T *branch * experimental-bulk-update
-T *sym-experimental-bulk-update *
-T -sym-trunk *
+P 2954ab501049968430011b63d046eb42ff37a56c
+R 7bee98aca78bdb17f817d7637df95f18
 U dan
-Z 195de077202fec58ba90fc725d7305e7
+Z 3a37163be54ffa74ee7c4647ff1214ea
index 4ea970c6b0ddafab9a811b1aa136ce28da470233..7d509edecc2227a958fb083485422e1c389e2aa9 100644 (file)
@@ -1 +1 @@
-2954ab501049968430011b63d046eb42ff37a56c
\ No newline at end of file
+ffa1524ef2a4c32652183eb4745685f0d1c93af2
\ No newline at end of file