Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Move tcl test code from sqlite3ota.c to new file ext/ota/test_ota.c. |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | ota-update |
Files: | files | file ages | folders |
SHA1: |
f20779a6e890ba73bfaa904cefcf3a02 |
User & Date: | dan 2015-02-16 06:27:37.241 |
Context
2015-02-16
| ||
11:48 | Add further tests and fixes for ota. (check-in: 62dc1fffc3 user: dan tags: ota-update) | |
06:27 | Move tcl test code from sqlite3ota.c to new file ext/ota/test_ota.c. (check-in: f20779a6e8 user: dan tags: ota-update) | |
2015-02-14
| ||
18:58 | Change the way the "incremental checkpoint" function of OTA works in order to reduce the effect on the SQLite core code. (check-in: b64a11a754 user: dan tags: ota-update) | |
Changes
Changes to ext/ota/sqlite3ota.c.
︙ | ︙ | |||
512 513 514 515 516 517 518 | pIter->azTblType = &azNew[nCol]; pIter->aiSrcOrder = (int*)&pIter->azTblType[nCol]; pIter->abTblPk = (u8*)&pIter->aiSrcOrder[nCol]; pIter->abNotNull = (u8*)&pIter->abTblPk[nCol]; } } | | < > | < | 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 | pIter->azTblType = &azNew[nCol]; pIter->aiSrcOrder = (int*)&pIter->azTblType[nCol]; pIter->abTblPk = (u8*)&pIter->aiSrcOrder[nCol]; pIter->abNotNull = (u8*)&pIter->abTblPk[nCol]; } } static char *otaStrndup(const char *zStr, int *pRc){ char *zRet = 0; assert( *pRc==SQLITE_OK ); if( zStr ){ int nCopy = strlen(zStr) + 1; zRet = (char*)sqlite3_malloc(nCopy); if( zRet ){ memcpy(zRet, zStr, nCopy); }else{ *pRc = SQLITE_NOMEM; } } |
︙ | ︙ | |||
693 694 695 696 697 698 699 | if( p->rc==SQLITE_OK ){ nCol = sqlite3_column_count(pStmt); otaAllocateIterArrays(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) ){ | | | 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 | if( p->rc==SQLITE_OK ){ nCol = sqlite3_column_count(pStmt); otaAllocateIterArrays(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); pIter->aiSrcOrder[pIter->nTblCol] = pIter->nTblCol; pIter->azTblCol[pIter->nTblCol++] = zCopy; } else if( 0==sqlite3_stricmp("ota_rowid", zName) ){ bOtaRowid = 1; } } |
︙ | ︙ | |||
742 743 744 745 746 747 748 | const char *zType = (const char*)sqlite3_column_text(pStmt, 2); if( i!=iOrder ){ SWAP(int, pIter->aiSrcOrder[i], pIter->aiSrcOrder[iOrder]); SWAP(char*, pIter->azTblCol[i], pIter->azTblCol[iOrder]); } | | | 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 | const char *zType = (const char*)sqlite3_column_text(pStmt, 2); if( i!=iOrder ){ SWAP(int, pIter->aiSrcOrder[i], pIter->aiSrcOrder[iOrder]); SWAP(char*, pIter->azTblCol[i], pIter->azTblCol[iOrder]); } pIter->azTblType[iOrder] = otaStrndup(zType, &p->rc); pIter->abTblPk[iOrder] = (iPk!=0); pIter->abNotNull[iOrder] = (u8)bNotNull || (iPk!=0); iOrder++; } } rc2 = sqlite3_finalize(pStmt); |
︙ | ︙ | |||
1439 1440 1441 1442 1443 1444 1445 | "END;", zWrite, zTbl, zTbl, zCollist, zNewlist ); } } /* Allocate space required for the zMask field. */ | < < | < < < < < < | 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 | "END;", zWrite, zTbl, zTbl, zCollist, zNewlist ); } } /* Allocate space required for the zMask field. */ pIter->zMask = (char*)otaMalloc(p, pIter->nTblCol+1); sqlite3_free(zWhere); sqlite3_free(zOldlist); sqlite3_free(zNewlist); sqlite3_free(zBindings); } sqlite3_free(zCollist); |
︙ | ︙ | |||
2038 2039 2040 2041 2042 2043 2044 | static OtaState *otaLoadState(sqlite3ota *p){ const char *zSelect = "SELECT k, v FROM ota.ota_state"; OtaState *pRet = 0; sqlite3_stmt *pStmt = 0; int rc; int rc2; | < | | | < < | < < | | | 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 | static OtaState *otaLoadState(sqlite3ota *p){ const char *zSelect = "SELECT k, v FROM ota.ota_state"; OtaState *pRet = 0; sqlite3_stmt *pStmt = 0; int rc; int rc2; pRet = (OtaState*)otaMalloc(p, sizeof(OtaState)); if( pRet==0 ) return 0; rc = prepareAndCollectError(p->db, &pStmt, &p->zErrmsg, zSelect); while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){ switch( sqlite3_column_int(pStmt, 0) ){ case OTA_STATE_STAGE: pRet->eStage = sqlite3_column_int(pStmt, 1); if( pRet->eStage!=OTA_STAGE_OAL && pRet->eStage!=OTA_STAGE_CKPT ){ p->rc = SQLITE_CORRUPT; } break; case OTA_STATE_TBL: pRet->zTbl = otaStrndup((char*)sqlite3_column_text(pStmt, 1), &rc); break; case OTA_STATE_IDX: pRet->zIdx = otaStrndup((char*)sqlite3_column_text(pStmt, 1), &rc); break; case OTA_STATE_ROW: pRet->nRow = sqlite3_column_int(pStmt, 1); break; case OTA_STATE_PROGRESS: |
︙ | ︙ | |||
2750 2751 2752 2753 2754 2755 2756 | z += (n + 8 + 1); pFd->zWal = z; } else if( flags & SQLITE_OPEN_WAL ){ ota_file *pDb = otaFindMaindb(pOtaVfs, zName); if( pDb ){ if( pDb->pOta && pDb->pOta->eStage==OTA_STAGE_OAL ){ | | | 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 | z += (n + 8 + 1); pFd->zWal = z; } else if( flags & SQLITE_OPEN_WAL ){ ota_file *pDb = otaFindMaindb(pOtaVfs, zName); if( pDb ){ if( pDb->pOta && pDb->pOta->eStage==OTA_STAGE_OAL ){ char *zCopy = otaStrndup(zName, &rc); if( zCopy ){ int nCopy = strlen(zCopy); zCopy[nCopy-3] = 'o'; zOpen = (const char*)(pFd->zDel = zCopy); } pFd->pOta = pDb->pOta; } |
︙ | ︙ | |||
3021 3022 3023 3024 3025 3026 3027 | p->zVfsName = 0; } } /**************************************************************************/ | < | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 3007 3008 3009 3010 3011 3012 3013 3014 | p->zVfsName = 0; } } /**************************************************************************/ #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_OTA) */ |
Added ext/ota/test_ota.c.
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 | /* ** 2015 February 16 ** ** 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. ** ************************************************************************* */ #include "sqlite3.h" #if defined(SQLITE_TEST) #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_OTA) #include "sqlite3ota.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){ 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)); for(i=0; i<nArg; i++){ sqlite3_value *pIn = apVal[i]; const char *z = (const char*)sqlite3_value_text(pIn); Tcl_ListObjAppendElement(0, pScript, Tcl_NewStringObj(z, -1)); } if( TCL_OK==Tcl_EvalObjEx(interp, pScript, TCL_GLOBAL_ONLY) ){ const char *z = Tcl_GetStringResult(interp); sqlite3_result_text(pCtx, z, -1, SQLITE_TRANSIENT); }else{ Tcl_BackgroundError(interp); } Tcl_DecrRefCount(pScript); } static int test_sqlite3ota_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 }; int iMethod; if( objc!=2 ){ Tcl_WrongNumArgs(interp, 1, objv, "METHOD"); return TCL_ERROR; } if( Tcl_GetIndexFromObj(interp, objv[1], azMethod, "method", 0, &iMethod) ){ return TCL_ERROR; } switch( iMethod ){ case 0: /* step */ { int rc = sqlite3ota_step(pOta); Tcl_SetObjResult(interp, Tcl_NewStringObj(sqlite3ErrName(rc), -1)); break; } case 1: /* close */ { char *zErrmsg = 0; int rc; Tcl_DeleteCommand(interp, Tcl_GetString(objv[0])); rc = sqlite3ota_close(pOta, &zErrmsg); if( rc==SQLITE_OK || rc==SQLITE_DONE ){ Tcl_SetObjResult(interp, Tcl_NewStringObj(sqlite3ErrName(rc), -1)); assert( zErrmsg==0 ); }else{ Tcl_SetObjResult(interp, Tcl_NewStringObj(sqlite3ErrName(rc), -1)); if( zErrmsg ){ Tcl_AppendResult(interp, " - ", zErrmsg, 0); sqlite3_free(zErrmsg); } ret = TCL_ERROR; } break; } case 2: /* create_ota_delta */ { sqlite3 *db = sqlite3ota_db(pOta); int rc = sqlite3_create_function( db, "ota_delta", -1, SQLITE_UTF8, (void*)interp, test_ota_delta, 0, 0 ); Tcl_SetObjResult(interp, Tcl_NewStringObj(sqlite3ErrName(rc), -1)); ret = (rc==SQLITE_OK ? TCL_OK : TCL_ERROR); break; } default: /* seems unlikely */ assert( !"cannot happen" ); break; } return ret; } /* ** Tclcmd: sqlite3ota CMD <target-db> <ota-db> */ static int test_sqlite3ota( ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[] ){ sqlite3ota *pOta = 0; const char *zCmd; const char *zTarget; const char *zOta; if( objc!=4 ){ Tcl_WrongNumArgs(interp, 1, objv, "NAME TARGET-DB OTA-DB"); return TCL_ERROR; } zCmd = Tcl_GetString(objv[1]); zTarget = Tcl_GetString(objv[2]); zOta = Tcl_GetString(objv[3]); pOta = sqlite3ota_open(zTarget, zOta); Tcl_CreateObjCommand(interp, zCmd, test_sqlite3ota_cmd, (ClientData)pOta, 0); Tcl_SetObjResult(interp, objv[1]); return TCL_OK; } /* ** Tclcmd: sqlite3ota_create_vfs ?-default? NAME PARENT */ static int test_sqlite3ota_create_vfs( ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[] ){ const char *zName; const char *zParent; int rc; if( objc!=3 && objc!=4 ){ Tcl_WrongNumArgs(interp, 1, objv, "?-default? NAME PARENT"); return TCL_ERROR; } zName = Tcl_GetString(objv[objc-2]); zParent = Tcl_GetString(objv[objc-1]); if( zParent[0]=='\0' ) zParent = 0; rc = sqlite3ota_create_vfs(zName, zParent); if( rc!=SQLITE_OK ){ Tcl_SetObjResult(interp, Tcl_NewStringObj(sqlite3ErrName(rc), -1)); return TCL_ERROR; }else if( objc==4 ){ sqlite3_vfs *pVfs = sqlite3_vfs_find(zName); sqlite3_vfs_register(pVfs, 1); } Tcl_ResetResult(interp); return TCL_OK; } /* ** Tclcmd: sqlite3ota_destroy_vfs NAME */ static int test_sqlite3ota_destroy_vfs( ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[] ){ const char *zName; if( objc!=2 ){ Tcl_WrongNumArgs(interp, 1, objv, "NAME"); return TCL_ERROR; } zName = Tcl_GetString(objv[1]); sqlite3ota_destroy_vfs(zName); return TCL_OK; } int SqliteOta_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 }, }; int i; for(i=0; i<sizeof(aObjCmd)/sizeof(aObjCmd[0]); i++){ Tcl_CreateObjCommand(interp, aObjCmd[i].zName, aObjCmd[i].xProc, 0, 0); } return TCL_OK; } #else #include <tcl.h> int SqliteOta_Init(Tcl_Interp *interp){ return TCL_OK; } #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_OTA) */ #endif /* defined(SQLITE_TEST) */ |
Changes to main.mk.
︙ | ︙ | |||
61 62 63 64 65 66 67 | fts3_write.o func.o global.o hash.o \ icu.o insert.o journal.o legacy.o loadext.o \ main.o malloc.o mem0.o mem1.o mem2.o mem3.o mem5.o \ memjournal.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 \ | | | 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | fts3_write.o func.o global.o hash.o \ icu.o insert.o journal.o legacy.o loadext.o \ main.o malloc.o mem0.o mem1.o mem2.o mem3.o mem5.o \ memjournal.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 \ table.o threads.o tokenize.o trigger.o \ update.o userauth.o util.o vacuum.o \ vdbeapi.o vdbeaux.o vdbeblob.o vdbemem.o vdbesort.o \ vdbetrace.o wal.o walker.o where.o utf.o vtab.o |
︙ | ︙ | |||
337 338 339 340 341 342 343 | parse.c \ $(TOP)/ext/fts3/fts3.c \ $(TOP)/ext/fts3/fts3_aux.c \ $(TOP)/ext/fts3/fts3_expr.c \ $(TOP)/ext/fts3/fts3_tokenizer.c \ $(TOP)/ext/fts3/fts3_write.c \ $(TOP)/ext/async/sqlite3async.c \ | | | 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 | parse.c \ $(TOP)/ext/fts3/fts3.c \ $(TOP)/ext/fts3/fts3_aux.c \ $(TOP)/ext/fts3/fts3_expr.c \ $(TOP)/ext/fts3/fts3_tokenizer.c \ $(TOP)/ext/fts3/fts3_write.c \ $(TOP)/ext/async/sqlite3async.c \ $(TOP)/ext/ota/test_ota.c # Header files used by all library source files. # HDR = \ $(TOP)/src/btree.h \ $(TOP)/src/btreeInt.h \ $(TOP)/src/hash.h \ |
︙ | ︙ | |||
570 571 572 573 574 575 576 577 578 579 580 581 582 583 | $(TCCX) -DSQLITE_CORE -c $(TOP)/ext/fts3/fts3_write.c rtree.o: $(TOP)/ext/rtree/rtree.c $(HDR) $(EXTHDR) $(TCCX) -DSQLITE_CORE -c $(TOP)/ext/rtree/rtree.c userauth.o: $(TOP)/ext/userauth/userauth.c $(HDR) $(EXTHDR) $(TCCX) -DSQLITE_CORE -c $(TOP)/ext/userauth/userauth.c # Rules for building test programs and for running tests # tclsqlite3: $(TOP)/src/tclsqlite.c libsqlite3.a $(TCCX) $(TCL_FLAGS) -DTCLSH=1 -o tclsqlite3 \ $(TOP)/src/tclsqlite.c libsqlite3.a $(LIBTCL) $(THREADLIB) | > > > | 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 | $(TCCX) -DSQLITE_CORE -c $(TOP)/ext/fts3/fts3_write.c rtree.o: $(TOP)/ext/rtree/rtree.c $(HDR) $(EXTHDR) $(TCCX) -DSQLITE_CORE -c $(TOP)/ext/rtree/rtree.c userauth.o: $(TOP)/ext/userauth/userauth.c $(HDR) $(EXTHDR) $(TCCX) -DSQLITE_CORE -c $(TOP)/ext/userauth/userauth.c sqlite3ota.o: $(TOP)/ext/ota/sqlite3ota.c $(HDR) $(EXTHDR) $(TCCX) -DSQLITE_CORE -c $(TOP)/ext/ota/sqlite3ota.c # Rules for building test programs and for running tests # tclsqlite3: $(TOP)/src/tclsqlite.c libsqlite3.a $(TCCX) $(TCL_FLAGS) -DTCLSH=1 -o tclsqlite3 \ $(TOP)/src/tclsqlite.c libsqlite3.a $(LIBTCL) $(THREADLIB) |
︙ | ︙ |