** This function is a no-op if recover handle p already contains an error ** (if p->errCode!=SQLITE_OK). A copy of the error code is returned in ** this case. ** ** Otherwise, an attempt is made to open the output database, attach ** and create the schema of the temporary database used to store ** intermediate data, and to register all required user functions and ** virtual table modules with the
| 14427 | ** error code returned. |
| 14428 | */ |
| 14429 | static int recoverOpenOutput(sqlite3_recover *p){ |
| 14430 | struct Func { |
| 14431 | const char *zName; |
| 14432 | int nArg; |
| 14433 | void (*xFunc)(sqlite3_context*,int,sqlite3_value **); |
| 14434 | } aFunc[] = { |
| 14435 | { "getpage", 1, recoverGetPage }, |
| 14436 | { "page_is_used", 1, recoverPageIsUsed }, |
| 14437 | { "read_i32", 2, recoverReadI32 }, |
| 14438 | { "escape_crnl", 1, recoverEscapeCrnl }, |
| 14439 | }; |
| 14440 | |
| 14441 | const int flags = SQLITE_OPEN_URI|SQLITE_OPEN_CREATE|SQLITE_OPEN_READWRITE; |
| 14442 | sqlite3 *db = 0; /* New database handle */ |
| 14443 | int ii; /* For iterating through aFunc[] */ |
| 14444 | |
| 14445 | assert( p->dbOut==0 ); |
| 14446 | |
| 14447 | if( sqlite3_open_v2(p->zUri, &db, flags, 0) ){ |
| 14448 | recoverDbError(p, db); |
| 14449 | } |
| 14450 | |
| 14451 | /* Register the sqlite_dbdata and sqlite_dbptr virtual table modules. |
| 14452 | ** These two are registered with the output database handle - this |
| 14453 | ** module depends on the input handle supporting the sqlite_dbpage |
| 14454 | ** virtual table only. */ |
| 14455 | if( p->errCode==SQLITE_OK ){ |
| 14456 | p->errCode = sqlite3_dbdata_init(db, 0, 0); |
| 14457 | } |
| 14458 | |
| 14459 | /* Register the custom user-functions with the output handle. */ |
| 14460 | for(ii=0; |
| 14461 | p->errCode==SQLITE_OK && ii<(int)(sizeof(aFunc)/sizeof(aFunc[0])); |
| 14462 | ii++){ |
| 14463 | p->errCode = sqlite3_create_function(db, aFunc[ii].zName, |
| 14464 | aFunc[ii].nArg, SQLITE_UTF8, (void*)p, aFunc[ii].xFunc, 0, 0 |
| 14465 | ); |
| 14466 | } |
| 14467 | |
| 14468 | p->dbOut = db; |
| 14469 | return p->errCode; |
| 14470 | } |
| 14471 | |
| 14472 | /* |
| 14473 | ** Attach the auxiliary database 'recovery' to the output database handle. |
no test coverage detected