** 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. */
| 26302 | ** into zNewDb. |
| 26303 | */ |
| 26304 | static void tryToClone(ShellState *p, const char *zNewDb){ |
| 26305 | int rc; |
| 26306 | sqlite3 *newDb = 0; |
| 26307 | if( access(zNewDb,0)==0 ){ |
| 26308 | sqlite3_fprintf(stderr,"File \"%s\" already exists.\n", zNewDb); |
| 26309 | return; |
| 26310 | } |
| 26311 | rc = sqlite3_open(zNewDb, &newDb); |
| 26312 | if( rc ){ |
| 26313 | sqlite3_fprintf(stderr, |
| 26314 | "Cannot create output database: %s\n", sqlite3_errmsg(newDb)); |
| 26315 | }else{ |
| 26316 | sqlite3_exec(p->db, "PRAGMA writable_schema=ON;", 0, 0, 0); |
| 26317 | sqlite3_exec(newDb, "BEGIN EXCLUSIVE;", 0, 0, 0); |
| 26318 | tryToCloneSchema(p, newDb, "type='table'", tryToCloneData); |
| 26319 | tryToCloneSchema(p, newDb, "type!='table'", 0); |
| 26320 | sqlite3_exec(newDb, "COMMIT;", 0, 0, 0); |
| 26321 | sqlite3_exec(p->db, "PRAGMA writable_schema=OFF;", 0, 0, 0); |
| 26322 | } |
| 26323 | close_db(newDb); |
| 26324 | } |
| 26325 | |
| 26326 | #ifndef SQLITE_SHELL_FIDDLE |
| 26327 | /* |
no test coverage detected