** The implementation of a user-defined SQL function invoked by the ** sqlite_dbdata and sqlite_dbptr virtual table modules to access pages ** of the database being recovered. ** ** This function always takes a single integer argument. If the argument ** is zero, then the value returned is the number of pages in the db being ** recovered. If the argument is greater than zero, it is a page number.
| 14142 | ** SELECT getpage(4); -- return page 4 of db as a blob of data |
| 14143 | */ |
| 14144 | static void recoverGetPage( |
| 14145 | sqlite3_context *pCtx, |
| 14146 | int nArg, |
| 14147 | sqlite3_value **apArg |
| 14148 | ){ |
| 14149 | sqlite3_recover *p = (sqlite3_recover*)sqlite3_user_data(pCtx); |
| 14150 | i64 pgno = sqlite3_value_int64(apArg[0]); |
| 14151 | sqlite3_stmt *pStmt = 0; |
| 14152 | |
| 14153 | assert( nArg==1 ); |
| 14154 | if( pgno==0 ){ |
| 14155 | i64 nPg = recoverPageCount(p); |
| 14156 | sqlite3_result_int64(pCtx, nPg); |
| 14157 | return; |
| 14158 | }else{ |
| 14159 | if( p->pGetPage==0 ){ |
| 14160 | pStmt = p->pGetPage = recoverPreparePrintf( |
| 14161 | p, p->dbIn, "SELECT data FROM sqlite_dbpage(%Q) WHERE pgno=?", p->zDb |
| 14162 | ); |
| 14163 | }else if( p->errCode==SQLITE_OK ){ |
| 14164 | pStmt = p->pGetPage; |
| 14165 | } |
| 14166 | |
| 14167 | if( pStmt ){ |
| 14168 | sqlite3_bind_int64(pStmt, 1, pgno); |
| 14169 | if( SQLITE_ROW==sqlite3_step(pStmt) ){ |
| 14170 | const u8 *aPg; |
| 14171 | int nPg; |
| 14172 | assert( p->errCode==SQLITE_OK ); |
| 14173 | aPg = sqlite3_column_blob(pStmt, 0); |
| 14174 | nPg = sqlite3_column_bytes(pStmt, 0); |
| 14175 | if( pgno==1 && nPg==p->pgsz && 0==memcmp(p->pPage1Cache, aPg, nPg) ){ |
| 14176 | aPg = p->pPage1Disk; |
| 14177 | } |
| 14178 | sqlite3_result_blob(pCtx, aPg, nPg-p->nReserve, SQLITE_TRANSIENT); |
| 14179 | } |
| 14180 | recoverReset(p, pStmt); |
| 14181 | } |
| 14182 | } |
| 14183 | |
| 14184 | if( p->errCode ){ |
| 14185 | if( p->zErrMsg ) sqlite3_result_error(pCtx, p->zErrMsg, -1); |
| 14186 | sqlite3_result_error_code(pCtx, p->errCode); |
| 14187 | } |
| 14188 | } |
| 14189 | |
| 14190 | /* |
| 14191 | ** Find a string that is not found anywhere in z[]. Return a pointer |
nothing calls this directly
no test coverage detected