** This function is called to search the schema recovered from the ** sqlite_schema table of the (possibly) corrupt database as part ** of a ".recover" command. Specifically, for a table with root page ** iRoot and at least nCol columns. Additionally, if bIntkey is 0, the ** table must be a WITHOUT ROWID table, or if non-zero, not one of ** those. ** ** If a table is found, a (RecoverTable*) objec
| 17111 | ** the caller should write data to the orphans table. |
| 17112 | */ |
| 17113 | static RecoverTable *recoverFindTable( |
| 17114 | ShellState *pState, /* Shell state object */ |
| 17115 | int *pRc, /* IN/OUT: Error code */ |
| 17116 | int iRoot, /* Root page of table */ |
| 17117 | int bIntkey, /* True for an intkey table */ |
| 17118 | int nCol, /* Number of columns in table */ |
| 17119 | int *pbNoop /* OUT: True if iRoot is root of index */ |
| 17120 | ){ |
| 17121 | sqlite3_stmt *pStmt = 0; |
| 17122 | RecoverTable *pRet = 0; |
| 17123 | int bNoop = 0; |
| 17124 | const char *zSql = 0; |
| 17125 | const char *zName = 0; |
| 17126 | |
| 17127 | /* Search the recovered schema for an object with root page iRoot. */ |
| 17128 | shellPreparePrintf(pState->db, pRc, &pStmt, |
| 17129 | "SELECT type, name, sql FROM recovery.schema WHERE rootpage=%d", iRoot |
| 17130 | ); |
| 17131 | while( *pRc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){ |
| 17132 | const char *zType = (const char*)sqlite3_column_text(pStmt, 0); |
| 17133 | if( bIntkey==0 && sqlite3_stricmp(zType, "index")==0 ){ |
| 17134 | bNoop = 1; |
| 17135 | break; |
| 17136 | } |
| 17137 | if( sqlite3_stricmp(zType, "table")==0 ){ |
| 17138 | zName = (const char*)sqlite3_column_text(pStmt, 1); |
| 17139 | zSql = (const char*)sqlite3_column_text(pStmt, 2); |
| 17140 | pRet = recoverNewTable(pRc, zName, zSql, bIntkey, nCol); |
| 17141 | break; |
| 17142 | } |
| 17143 | } |
| 17144 | |
| 17145 | shellFinalize(pRc, pStmt); |
| 17146 | *pbNoop = bNoop; |
| 17147 | return pRet; |
| 17148 | } |
| 17149 | |
| 17150 | /* |
| 17151 | ** Return a RecoverTable object representing the orphans table. |
no test coverage detected