** 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. */
| 15456 | ** into zNewDb. |
| 15457 | */ |
| 15458 | static void tryToClone(ShellState *p, const char *zNewDb){ |
| 15459 | int rc; |
| 15460 | sqlite3 *newDb = 0; |
| 15461 | if( access(zNewDb,0)==0 ){ |
| 15462 | utf8_printf(stderr, "File \"%s\" already exists.\n", zNewDb); |
| 15463 | return; |
| 15464 | } |
| 15465 | rc = sqlite3_open(zNewDb, &newDb); |
| 15466 | if( rc ){ |
| 15467 | utf8_printf(stderr, "Cannot create output database: %s\n", |
| 15468 | sqlite3_errmsg(newDb)); |
| 15469 | }else{ |
| 15470 | sqlite3_exec(p->db, "PRAGMA writable_schema=ON;", 0, 0, 0); |
| 15471 | sqlite3_exec(newDb, "BEGIN EXCLUSIVE;", 0, 0, 0); |
| 15472 | tryToCloneSchema(p, newDb, "type='table'", tryToCloneData); |
| 15473 | tryToCloneSchema(p, newDb, "type!='table'", 0); |
| 15474 | sqlite3_exec(newDb, "COMMIT;", 0, 0, 0); |
| 15475 | sqlite3_exec(p->db, "PRAGMA writable_schema=OFF;", 0, 0, 0); |
| 15476 | } |
| 15477 | close_db(newDb); |
| 15478 | } |
| 15479 | |
| 15480 | /* |
| 15481 | ** Change the output file back to stdout. |
no test coverage detected