** This function is a no-op if recover handle p already contains an error ** (if p->errCode!=SQLITE_OK). ** ** Otherwise, argument zName must be the name of a table that has just been ** created in the output database. This function queries the output db ** for the schema of said table, and creates a RecoverTable object to ** store the schema in memory. The new RecoverTable object is linked into *
| 14500 | ** database. |
| 14501 | */ |
| 14502 | static void recoverAddTable( |
| 14503 | sqlite3_recover *p, |
| 14504 | const char *zName, /* Name of table created in output db */ |
| 14505 | i64 iRoot /* Root page of same table in INPUT db */ |
| 14506 | ){ |
| 14507 | sqlite3_stmt *pStmt = recoverPreparePrintf(p, p->dbOut, |
| 14508 | "PRAGMA table_xinfo(%Q)", zName |
| 14509 | ); |
| 14510 | |
| 14511 | if( pStmt ){ |
| 14512 | int iPk = -1; |
| 14513 | int iBind = 1; |
| 14514 | RecoverTable *pNew = 0; |
| 14515 | int nCol = 0; |
| 14516 | int nName = recoverStrlen(zName); |
| 14517 | int nByte = 0; |
| 14518 | while( sqlite3_step(pStmt)==SQLITE_ROW ){ |
| 14519 | nCol++; |
| 14520 | nByte += (sqlite3_column_bytes(pStmt, 1)+1); |
| 14521 | } |
| 14522 | nByte += sizeof(RecoverTable) + nCol*sizeof(RecoverColumn) + nName+1; |
| 14523 | recoverReset(p, pStmt); |
| 14524 | |
| 14525 | pNew = recoverMalloc(p, nByte); |
| 14526 | if( pNew ){ |
| 14527 | int i = 0; |
| 14528 | int iField = 0; |
| 14529 | char *csr = 0; |
| 14530 | pNew->aCol = (RecoverColumn*)&pNew[1]; |
| 14531 | pNew->zTab = csr = (char*)&pNew->aCol[nCol]; |
| 14532 | pNew->nCol = nCol; |
| 14533 | pNew->iRoot = iRoot; |
| 14534 | memcpy(csr, zName, nName); |
| 14535 | csr += nName+1; |
| 14536 | |
| 14537 | for(i=0; sqlite3_step(pStmt)==SQLITE_ROW; i++){ |
| 14538 | int iPKF = sqlite3_column_int(pStmt, 5); |
| 14539 | int n = sqlite3_column_bytes(pStmt, 1); |
| 14540 | const char *z = (const char*)sqlite3_column_text(pStmt, 1); |
| 14541 | const char *zType = (const char*)sqlite3_column_text(pStmt, 2); |
| 14542 | int eHidden = sqlite3_column_int(pStmt, 6); |
| 14543 | |
| 14544 | if( iPk==-1 && iPKF==1 && !sqlite3_stricmp("integer", zType) ) iPk = i; |
| 14545 | if( iPKF>1 ) iPk = -2; |
| 14546 | pNew->aCol[i].zCol = csr; |
| 14547 | pNew->aCol[i].eHidden = eHidden; |
| 14548 | if( eHidden==RECOVER_EHIDDEN_VIRTUAL ){ |
| 14549 | pNew->aCol[i].iField = -1; |
| 14550 | }else{ |
| 14551 | pNew->aCol[i].iField = iField++; |
| 14552 | } |
| 14553 | if( eHidden!=RECOVER_EHIDDEN_VIRTUAL |
| 14554 | && eHidden!=RECOVER_EHIDDEN_STORED |
| 14555 | ){ |
| 14556 | pNew->aCol[i].iBind = iBind++; |
| 14557 | } |
| 14558 | memcpy(csr, z, n); |
| 14559 | csr += (n+1); |
no test coverage detected