MCPcopy Create free account
hub / github.com/GaijinEntertainment/daScript / recoverWriteDataInit

Function recoverWriteDataInit

modules/dasSQLITE/sqlite/shell.c:15121–15159  ·  view source on GitHub ↗

** Initialize resources required in RECOVER_STATE_WRITING state - during which ** tables recovered from the schema of the input database are populated with ** recovered data. */

Source from the content-addressed store, hash-verified

15119** recovered data.
15120*/
15121static int recoverWriteDataInit(sqlite3_recover *p){
15122 RecoverStateW1 *p1 = &p->w1;
15123 RecoverTable *pTbl = 0;
15124 int nByte = 0;
15125
15126 /* Figure out the maximum number of columns for any table in the schema */
15127 assert( p1->nMax==0 );
15128 for(pTbl=p->pTblList; pTbl; pTbl=pTbl->pNext){
15129 if( pTbl->nCol>p1->nMax ) p1->nMax = pTbl->nCol;
15130 }
15131
15132 /* Allocate an array of (sqlite3_value*) in which to accumulate the values
15133 ** that will be written to the output database in a single row. */
15134 nByte = sizeof(sqlite3_value*) * (p1->nMax+1);
15135 p1->apVal = (sqlite3_value**)recoverMalloc(p, nByte);
15136 if( p1->apVal==0 ) return p->errCode;
15137
15138 /* Prepare the SELECT to loop through schema tables (pTbls) and the SELECT
15139 ** to loop through cells that appear to belong to a single table (pSel). */
15140 p1->pTbls = recoverPrepare(p, p->dbOut,
15141 "SELECT rootpage FROM recovery.schema "
15142 " WHERE type='table' AND (sql NOT LIKE 'create virtual%')"
15143 " ORDER BY (tbl_name='sqlite_sequence') ASC"
15144 );
15145 p1->pSel = recoverPrepare(p, p->dbOut,
15146 "WITH RECURSIVE pages(page) AS ("
15147 " SELECT ?1"
15148 " UNION"
15149 " SELECT child FROM sqlite_dbptr('getpage()'), pages "
15150 " WHERE pgno=page"
15151 ") "
15152 "SELECT page, cell, field, value "
15153 "FROM sqlite_dbdata('getpage()') d, pages p WHERE p.page=d.pgno "
15154 "UNION ALL "
15155 "SELECT 0, 0, 0, 0"
15156 );
15157
15158 return p->errCode;
15159}
15160
15161/*
15162** Clean up resources allocated by recoverWriteDataInit() (stuff in

Callers 1

recoverStepFunction · 0.85

Calls 3

assertFunction · 0.85
recoverMallocFunction · 0.85
recoverPrepareFunction · 0.85

Tested by

no test coverage detected