/ Check-in [ef08ecce]
Login

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 Unified Diffs Ignore Whitespace Patch

Changes to ext/ota/sqlite3ota.c.

2644
2645
2646
2647
2648
2649
2650
2651


2652


2653
2654
2655
2656
2657
2658
2659

  return p;
}

/*
** Return the database handle used by pOta.
*/
sqlite3 *sqlite3ota_db(sqlite3ota *pOta){


  return (pOta ? pOta->dbMain : 0);


}


/*
** If the error code currently stored in the OTA handle is SQLITE_CONSTRAINT,
** then edit any error message string so as to remove all occurrences of
** the pattern "ota_imp_[0-9]*".







|
>
>
|
>
>







2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663

  return p;
}

/*
** Return the database handle used by pOta.
*/
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,
** then edit any error message string so as to remove all occurrences of
** the pattern "ota_imp_[0-9]*".

Changes to ext/ota/sqlite3ota.h.

246
247
248
249
250
251
252
253


254
255
256
257



258
259




260
261
262
263


264
265
266
267
268
269
270
271
272
273
274
275
276
** SQLite's built-in VFSs, including the multiplexor VFS. However it does
** not work out of the box with zipvfs. Refer to the comment describing
** 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.


**
** 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 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.


**
**   * 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.
*/
sqlite3 *sqlite3ota_db(sqlite3ota*);

/*
** Do some work towards applying the OTA update to the target db. 
**
** Return SQLITE_DONE if the update has been completely applied, or 
** SQLITE_OK if no error occurs but there remains work to do to apply
** the OTA update. If an error does occur, some other error code is 







|
>
>

|
<
<
>
>
>
|

>
>
>
>

<
|
<
>
>



|

|







246
247
248
249
250
251
252
253
254
255
256
257


258
259
260
261
262
263
264
265
266
267

268

269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
** SQLite's built-in VFSs, including the multiplexor VFS. However it does
** not work out of the box with zipvfs. Refer to the comment describing
** the zipvfs_create_vfs() API below for details on using OTA with zipvfs.
*/
sqlite3ota *sqlite3ota_open(const char *zTarget, const char *zOta);

/*
** 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:
**
**   * 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, 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 the target database handle.
*/
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 
** SQLITE_OK if no error occurs but there remains work to do to apply
** the OTA update. If an error does occur, some other error code is 

Changes to ext/ota/test_ota.c.

90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
...
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
        }
        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;
    }
................................................................................
  sqlite3 *db;

  if( objc!=1 ){
    Tcl_WrongNumArgs(interp, 1, objv, "");
    return TCL_ERROR;
  }

  db = sqlite3ota_db(0);
  if( db!=0 ){
    Tcl_AppendResult(interp, "sqlite3ota_db(0)!=0", 0);
    return TCL_ERROR;
  }

  return TCL_OK;
}

int SqliteOta_Init(Tcl_Interp *interp){ 







|







 







|

|







90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
...
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
        }
        ret = TCL_ERROR;
      }
      break;
    }

    case 2: /* create_ota_delta */ {
      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);
      break;
    }
................................................................................
  sqlite3 *db;

  if( objc!=1 ){
    Tcl_WrongNumArgs(interp, 1, objv, "");
    return TCL_ERROR;
  }

  db = sqlite3ota_db(0, 0);
  if( db!=0 ){
    Tcl_AppendResult(interp, "sqlite3ota_db(0, 0)!=0", 0);
    return TCL_ERROR;
  }

  return TCL_OK;
}

int SqliteOta_Init(Tcl_Interp *interp){