** 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. */
| 21210 | ** into zNewDb. |
| 21211 | */ |
| 21212 | static 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. |
no test coverage detected