/ Check-in [ef08ecce]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Update the sqlite3ota_db() API to account for the fact that each OTA handle now uses two SQLite database handles.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | ota-update
Files: files | file ages | folders
SHA1: ef08ecceb7e237a01af6cc3141dccee09ffe9ae3
User & Date: dan 2015-02-23 15:02:13
Context
2015-02-23
15:41
Change SQLITE_FCNTL_ZIPVFS_PAGER to SQLITE_FCNTL_ZIPVFS. check-in: f7865b94 user: dan tags: ota-update
15:02
Update the sqlite3ota_db() API to account for the fact that each OTA handle now uses two SQLite database handles. check-in: ef08ecce user: dan tags: ota-update
12:22
Improve tests for resuming ota updates following power failures. Fix a problem revealed by the same. check-in: 1cb675e5 user: dan tags: ota-update
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/ota/sqlite3ota.c.

  2644   2644   
  2645   2645     return p;
  2646   2646   }
  2647   2647   
  2648   2648   /*
  2649   2649   ** Return the database handle used by pOta.
  2650   2650   */
  2651         -sqlite3 *sqlite3ota_db(sqlite3ota *pOta){
  2652         -  return (pOta ? pOta->dbMain : 0);
         2651  +sqlite3 *sqlite3ota_db(sqlite3ota *pOta, int bOta){
         2652  +  sqlite3 *db = 0;
         2653  +  if( pOta ){
         2654  +    db = (bOta ? pOta->dbOta : pOta->dbMain);
         2655  +  }
         2656  +  return db;
  2653   2657   }
  2654   2658   
  2655   2659   
  2656   2660   /*
  2657   2661   ** If the error code currently stored in the OTA handle is SQLITE_CONSTRAINT,
  2658   2662   ** then edit any error message string so as to remove all occurrences of
  2659   2663   ** the pattern "ota_imp_[0-9]*".

Changes to ext/ota/sqlite3ota.h.

   246    246   ** SQLite's built-in VFSs, including the multiplexor VFS. However it does
   247    247   ** not work out of the box with zipvfs. Refer to the comment describing
   248    248   ** the zipvfs_create_vfs() API below for details on using OTA with zipvfs.
   249    249   */
   250    250   sqlite3ota *sqlite3ota_open(const char *zTarget, const char *zOta);
   251    251   
   252    252   /*
   253         -** Obtain the underlying database handle used by the OTA extension.
          253  +** Internally, each OTA connection uses a separate SQLite database 
          254  +** connection to access the target and ota update databases. This
          255  +** API allows the application direct access to these database handles.
   254    256   **
   255         -** The only argument passed to this function must be a valid, open, OTA
   256         -** handle. This function returns the database handle used by OTA for all
   257         -** operations on the target and source databases. This may be useful in 
   258         -** two scenarios:
          257  +** The first argument passed to this function must be a valid, open, OTA
          258  +** handle. The second argument should be passed zero to access the target
          259  +** database handle, or non-zero to access the ota update database handle.
          260  +** Accessing the underlying database handles may be useful in the
          261  +** following scenarios:
          262  +**
          263  +**   * If any target tables are virtual tables, it may be necessary to
          264  +**     call sqlite3_create_module() on the target database handle to 
          265  +**     register the required virtual table implementations.
   259    266   **
   260    267   **   * If the data_xxx tables in the OTA source database are virtual 
   261         -**     tables, or if any of the tables being updated are virtual tables,
   262         -**     the application may need to call sqlite3_create_module() on
   263         -**     the db handle to register the required virtual table implementations.
          268  +**     tables, the application may need to call sqlite3_create_module() on
          269  +**     the ota update db handle to any required virtual table
          270  +**     implementations.
   264    271   **
   265    272   **   * If the application uses the "ota_delta()" feature described above,
   266    273   **     it must use sqlite3_create_function() or similar to register the
   267         -**     ota_delta() implementation with OTA.
          274  +**     ota_delta() implementation with the target database handle.
   268    275   */
   269         -sqlite3 *sqlite3ota_db(sqlite3ota*);
          276  +sqlite3 *sqlite3ota_db(sqlite3ota*, int bOta);
   270    277   
   271    278   /*
   272    279   ** Do some work towards applying the OTA update to the target db. 
   273    280   **
   274    281   ** Return SQLITE_DONE if the update has been completely applied, or 
   275    282   ** SQLITE_OK if no error occurs but there remains work to do to apply
   276    283   ** the OTA update. If an error does occur, some other error code is 

Changes to ext/ota/test_ota.c.

    90     90           }
    91     91           ret = TCL_ERROR;
    92     92         }
    93     93         break;
    94     94       }
    95     95   
    96     96       case 2: /* create_ota_delta */ {
    97         -      sqlite3 *db = sqlite3ota_db(pOta);
           97  +      sqlite3 *db = sqlite3ota_db(pOta, 0);
    98     98         int rc = sqlite3_create_function(
    99     99             db, "ota_delta", -1, SQLITE_UTF8, (void*)interp, test_ota_delta, 0, 0
   100    100         );
   101    101         Tcl_SetObjResult(interp, Tcl_NewStringObj(sqlite3ErrName(rc), -1));
   102    102         ret = (rc==SQLITE_OK ? TCL_OK : TCL_ERROR);
   103    103         break;
   104    104       }
................................................................................
   207    207     sqlite3 *db;
   208    208   
   209    209     if( objc!=1 ){
   210    210       Tcl_WrongNumArgs(interp, 1, objv, "");
   211    211       return TCL_ERROR;
   212    212     }
   213    213   
   214         -  db = sqlite3ota_db(0);
          214  +  db = sqlite3ota_db(0, 0);
   215    215     if( db!=0 ){
   216         -    Tcl_AppendResult(interp, "sqlite3ota_db(0)!=0", 0);
          216  +    Tcl_AppendResult(interp, "sqlite3ota_db(0, 0)!=0", 0);
   217    217       return TCL_ERROR;
   218    218     }
   219    219   
   220    220     return TCL_OK;
   221    221   }
   222    222   
   223    223   int SqliteOta_Init(Tcl_Interp *interp){