Index: ext/ota/sqlite3ota.c ================================================================== --- ext/ota/sqlite3ota.c +++ ext/ota/sqlite3ota.c @@ -2646,12 +2646,16 @@ } /* ** Return the database handle used by pOta. */ -sqlite3 *sqlite3ota_db(sqlite3ota *pOta){ - return (pOta ? pOta->dbMain : 0); +sqlite3 *sqlite3ota_db(sqlite3ota *pOta, int bOta){ + sqlite3 *db = 0; + if( pOta ){ + db = (bOta ? pOta->dbOta : pOta->dbMain); + } + return db; } /* ** If the error code currently stored in the OTA handle is SQLITE_CONSTRAINT, Index: ext/ota/sqlite3ota.h ================================================================== --- ext/ota/sqlite3ota.h +++ ext/ota/sqlite3ota.h @@ -248,27 +248,34 @@ ** the zipvfs_create_vfs() API below for details on using OTA with zipvfs. */ sqlite3ota *sqlite3ota_open(const char *zTarget, const char *zOta); /* -** Obtain the underlying database handle used by the OTA extension. +** Internally, each OTA connection uses a separate SQLite database +** connection to access the target and ota update databases. This +** API allows the application direct access to these database handles. +** +** The first argument passed to this function must be a valid, open, OTA +** handle. The second argument should be passed zero to access the target +** database handle, or non-zero to access the ota update database handle. +** Accessing the underlying database handles may be useful in the +** following scenarios: ** -** The only argument passed to this function must be a valid, open, OTA -** handle. This function returns the database handle used by OTA for all -** operations on the target and source databases. This may be useful in -** two scenarios: +** * If any target tables are virtual tables, it may be necessary to +** call sqlite3_create_module() on the target database handle to +** register the required virtual table implementations. ** ** * If the data_xxx tables in the OTA source database are virtual -** tables, or if any of the tables being updated are virtual tables, -** the application may need to call sqlite3_create_module() on -** the db handle to register the required virtual table implementations. +** tables, the application may need to call sqlite3_create_module() on +** the ota update db handle to any required virtual table +** implementations. ** ** * If the application uses the "ota_delta()" feature described above, ** it must use sqlite3_create_function() or similar to register the -** ota_delta() implementation with OTA. +** ota_delta() implementation with the target database handle. */ -sqlite3 *sqlite3ota_db(sqlite3ota*); +sqlite3 *sqlite3ota_db(sqlite3ota*, int bOta); /* ** Do some work towards applying the OTA update to the target db. ** ** Return SQLITE_DONE if the update has been completely applied, or Index: ext/ota/test_ota.c ================================================================== --- ext/ota/test_ota.c +++ ext/ota/test_ota.c @@ -92,11 +92,11 @@ } break; } case 2: /* create_ota_delta */ { - sqlite3 *db = sqlite3ota_db(pOta); + sqlite3 *db = sqlite3ota_db(pOta, 0); 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); @@ -209,13 +209,13 @@ if( objc!=1 ){ Tcl_WrongNumArgs(interp, 1, objv, ""); return TCL_ERROR; } - db = sqlite3ota_db(0); + db = sqlite3ota_db(0, 0); if( db!=0 ){ - Tcl_AppendResult(interp, "sqlite3ota_db(0)!=0", 0); + Tcl_AppendResult(interp, "sqlite3ota_db(0, 0)!=0", 0); return TCL_ERROR; } return TCL_OK; }