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

Function tryToClone

modules/dasSQLITE/sqlite/shell.c:21212–21232  ·  view source on GitHub ↗

** Open a new database file named "zNewDb". Try to recover as much information ** as possible out of the main database (which might be corrupt) and write it ** into zNewDb. */

Source from the content-addressed store, hash-verified

21210** into zNewDb.
21211*/
21212static void tryToClone(ShellState *p, const char *zNewDb){
21213 int rc;
21214 sqlite3 *newDb = 0;
21215 if( access(zNewDb,0)==0 ){
21216 utf8_printf(stderr, "File \"%s\" already exists.\n", zNewDb);
21217 return;
21218 }
21219 rc = sqlite3_open(zNewDb, &newDb);
21220 if( rc ){
21221 utf8_printf(stderr, "Cannot create output database: %s\n",
21222 sqlite3_errmsg(newDb));
21223 }else{
21224 sqlite3_exec(p->db, "PRAGMA writable_schema=ON;", 0, 0, 0);
21225 sqlite3_exec(newDb, "BEGIN EXCLUSIVE;", 0, 0, 0);
21226 tryToCloneSchema(p, newDb, "type='table'", tryToCloneData);
21227 tryToCloneSchema(p, newDb, "type!='table'", 0);
21228 sqlite3_exec(newDb, "COMMIT;", 0, 0, 0);
21229 sqlite3_exec(p->db, "PRAGMA writable_schema=OFF;", 0, 0, 0);
21230 }
21231 close_db(newDb);
21232}
21233
21234/*
21235** Change the output file back to stdout.

Callers 1

do_meta_commandFunction · 0.85

Calls 5

accessFunction · 0.85
utf8_printfFunction · 0.85
sqlite3_execFunction · 0.85
tryToCloneSchemaFunction · 0.85
close_dbFunction · 0.85

Tested by

no test coverage detected