Add an API to query an ota handle for the total number of key/value operations performed so far.

FossilOrigin-Name: e3943fa7bbbfc5e16f73a494d8fa54d19e9cfcf9
This commit is contained in:
dan
2014-09-18 14:48:38 +00:00
parent bb03ae7c8a
commit 4caa8fbc1e
5 changed files with 42 additions and 13 deletions
+10 -2
View File
@@ -55,6 +55,7 @@ int main(int argc, char **argv){
sqlite3ota *pOta; /* OTA handle */
int nStep = 0; /* Maximum number of step() calls */
int rc;
sqlite3_int64 nProgress = 0;
/* Process command line arguments. Following this block local variables
** zTarget, zOta and nStep are all set. */
@@ -76,16 +77,23 @@ int main(int argc, char **argv){
** sqlite3ota_step() a maximum of nStep times. */
pOta = sqlite3ota_open(zTarget, zOta);
for(i=0; (nStep<=0 || i<nStep) && sqlite3ota_step(pOta)==SQLITE_OK; i++);
nProgress = sqlite3ota_progress(pOta);
rc = sqlite3ota_close(pOta, &zErrmsg);
/* Let the user know what happened. */
switch( rc ){
case SQLITE_OK:
fprintf(stdout, "SQLITE_OK: ota update incomplete\n");
fprintf(stdout,
"SQLITE_OK: ota update incomplete (%lld operations so far)\n",
nProgress
);
break;
case SQLITE_DONE:
fprintf(stdout, "SQLITE_DONE: ota update completed\n");
fprintf(stdout,
"SQLITE_DONE: ota update completed (%lld operations)\n",
nProgress
);
break;
default:
+16 -2
View File
@@ -49,6 +49,7 @@ struct OtaState {
char *zTbl;
char *zIdx;
int nRow;
sqlite3_int64 nProgress;
};
/*
@@ -93,6 +94,7 @@ struct sqlite3ota {
int rc; /* Value returned by last ota_step() call */
char *zErrmsg; /* Error message if rc!=SQLITE_OK */
int nStep; /* Rows processed for current object */
int nProgress; /* Rows processed for all objects */
OtaObjIter objiter;
};
@@ -881,6 +883,7 @@ int sqlite3ota_step(sqlite3ota *p){
int rc = sqlite3_step(pIter->pSelect);
if( rc==SQLITE_ROW ){
p->nStep++;
p->nProgress++;
return otaStep(p);
}
p->rc = sqlite3_reset(pIter->pSelect);
@@ -901,8 +904,8 @@ int sqlite3ota_step(sqlite3ota *p){
static void otaSaveTransactionState(sqlite3ota *p){
otaMPrintfExec(p,
"INSERT OR REPLACE INTO ota.ota_state(rowid, tbl, idx, row, progress)"
"VALUES(1, %Q, %Q, %d, NULL)",
p->objiter.zTbl, p->objiter.zIdx, p->nStep
"VALUES(1, %Q, %Q, %d, %lld)",
p->objiter.zTbl, p->objiter.zIdx, p->nStep, p->nProgress
);
}
@@ -942,6 +945,7 @@ static OtaState *otaLoadState(sqlite3ota *p){
pRet->zIdx = 0;
}
pRet->nRow = sqlite3_column_int(pStmt, 2);
pRet->nProgress = sqlite3_column_int64(pStmt, 3);
}
}else{
pRet = (OtaState*)sqlite3_malloc(sizeof(OtaState));
@@ -1075,6 +1079,7 @@ sqlite3ota *sqlite3ota_open(const char *zTarget, const char *zOta){
}
if( p->rc==SQLITE_OK ){
p->nProgress = pState->nProgress;
otaLoadTransactionState(p, pState);
}
@@ -1128,6 +1133,15 @@ int sqlite3ota_close(sqlite3ota *p, char **pzErrmsg){
return rc;
}
/*
** Return the total number of key-value operations (inserts, deletes or
** updates) that have been performed on the target database since the
** current OTA update was started.
*/
sqlite3_int64 sqlite3ota_progress(sqlite3ota *pOta){
return pOta->nProgress;
}
/**************************************************************************/
+7
View File
@@ -215,5 +215,12 @@ int sqlite3ota_step(sqlite3ota *pOta);
*/
int sqlite3ota_close(sqlite3ota *pOta, char **pzErrmsg);
/*
** Return the total number of key-value operations (inserts, deletes or
** updates) that have been performed on the target database since the
** current OTA update was started.
*/
sqlite3_int64 sqlite3ota_progress(sqlite3ota *pOta);
#endif /* _SQLITE3OTA_H */