** 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, attempt to populate temporary table "recovery.schema" with the ** parts of the database schema that can be extracted from the input database. ** ** If no error occurs, SQLITE_OK is returned. Otherwise, an error code ** and
| 14312 | ** the database schema cannot be recovered due to corruption. |
| 14313 | */ |
| 14314 | static int recoverCacheSchema(sqlite3_recover *p){ |
| 14315 | return recoverExec(p, p->dbOut, |
| 14316 | "WITH RECURSIVE pages(p) AS (" |
| 14317 | " SELECT 1" |
| 14318 | " UNION" |
| 14319 | " SELECT child FROM sqlite_dbptr('getpage()'), pages WHERE pgno=p" |
| 14320 | ")" |
| 14321 | "INSERT INTO recovery.schema SELECT" |
| 14322 | " max(CASE WHEN field=0 THEN value ELSE NULL END)," |
| 14323 | " max(CASE WHEN field=1 THEN value ELSE NULL END)," |
| 14324 | " max(CASE WHEN field=2 THEN value ELSE NULL END)," |
| 14325 | " max(CASE WHEN field=3 THEN value ELSE NULL END)," |
| 14326 | " max(CASE WHEN field=4 THEN value ELSE NULL END)" |
| 14327 | "FROM sqlite_dbdata('getpage()') WHERE pgno IN (" |
| 14328 | " SELECT p FROM pages" |
| 14329 | ") GROUP BY pgno, cell" |
| 14330 | ); |
| 14331 | } |
| 14332 | |
| 14333 | /* |
| 14334 | ** If this recover handle is not in SQL callback mode (i.e. was not created |
no test coverage detected