ADDED ext/ota/ota.c Index: ext/ota/ota.c ================================================================== --- /dev/null +++ ext/ota/ota.c @@ -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 +#include +#include + +/* +** 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 /* Required for error code definitions */ typedef struct sqlite3ota sqlite3ota; /* ** Open an OTA handle. Index: main.mk ================================================================== --- main.mk +++ main.mk @@ -662,10 +662,15 @@ $(TCC) -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION -o 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. #