MCPcopy Create free account
hub / github.com/GaijinEntertainment/daScript / recoverTransferSettings

Function recoverTransferSettings

modules/dasSQLITE/sqlite/shell.c:14361–14413  ·  view source on GitHub ↗

** Transfer the following settings from the input database to the output ** database: ** ** + page-size, ** + auto-vacuum settings, ** + database encoding, ** + user-version (PRAGMA user_version), and ** + application-id (PRAGMA application_id), and */

Source from the content-addressed store, hash-verified

14359** + application-id (PRAGMA application_id), and
14360*/
14361static void recoverTransferSettings(sqlite3_recover *p){
14362 const char *aPragma[] = {
14363 "encoding",
14364 "page_size",
14365 "auto_vacuum",
14366 "user_version",
14367 "application_id"
14368 };
14369 int ii;
14370
14371 /* Truncate the output database to 0 pages in size. This is done by
14372 ** opening a new, empty, temp db, then using the backup API to clobber
14373 ** any existing output db with a copy of it. */
14374 if( p->errCode==SQLITE_OK ){
14375 sqlite3 *db2 = 0;
14376 int rc = sqlite3_open("", &db2);
14377 if( rc!=SQLITE_OK ){
14378 recoverDbError(p, db2);
14379 return;
14380 }
14381
14382 for(ii=0; ii<(int)(sizeof(aPragma)/sizeof(aPragma[0])); ii++){
14383 const char *zPrag = aPragma[ii];
14384 sqlite3_stmt *p1 = 0;
14385 p1 = recoverPreparePrintf(p, p->dbIn, "PRAGMA %Q.%s", p->zDb, zPrag);
14386 if( p->errCode==SQLITE_OK && sqlite3_step(p1)==SQLITE_ROW ){
14387 const char *zArg = (const char*)sqlite3_column_text(p1, 0);
14388 char *z2 = recoverMPrintf(p, "PRAGMA %s = %Q", zPrag, zArg);
14389 recoverSqlCallback(p, z2);
14390 recoverExec(p, db2, z2);
14391 sqlite3_free(z2);
14392 if( zArg==0 ){
14393 recoverError(p, SQLITE_NOMEM, 0);
14394 }
14395 }
14396 recoverFinalize(p, p1);
14397 }
14398 recoverExec(p, db2, "CREATE TABLE t1(a); DROP TABLE t1;");
14399
14400 if( p->errCode==SQLITE_OK ){
14401 sqlite3 *db = p->dbOut;
14402 sqlite3_backup *pBackup = sqlite3_backup_init(db, "main", db2, "main");
14403 if( pBackup ){
14404 sqlite3_backup_step(pBackup, -1);
14405 p->errCode = sqlite3_backup_finish(pBackup);
14406 }else{
14407 recoverDbError(p, db);
14408 }
14409 }
14410
14411 sqlite3_close(db2);
14412 }
14413}
14414
14415/*
14416** This function is a no-op if recover handle p already contains an error

Callers 1

recoverStepFunction · 0.85

Calls 7

recoverDbErrorFunction · 0.85
recoverPreparePrintfFunction · 0.85
recoverMPrintfFunction · 0.85
recoverSqlCallbackFunction · 0.85
recoverExecFunction · 0.85
recoverErrorFunction · 0.85
recoverFinalizeFunction · 0.85

Tested by

no test coverage detected