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

Function recoverInsertStmt

modules/dasSQLITE/sqlite/shell.c:14749–14815  ·  view source on GitHub ↗

** This function is a no-op if recover handle p already contains an error ** (if p->errCode!=SQLITE_OK). In this case it returns NULL. ** ** Otherwise, if the recover handle is configured to create an output ** database (was created by sqlite3_recover_init()), then this function ** prepares and returns an SQL statement to INSERT a new record into table ** pTab, assuming the first nField fields of

Source from the content-addressed store, hash-verified

14747** free the statement handle using sqlite3_finalize().
14748*/
14749static sqlite3_stmt *recoverInsertStmt(
14750 sqlite3_recover *p,
14751 RecoverTable *pTab,
14752 int nField
14753){
14754 sqlite3_stmt *pRet = 0;
14755 const char *zSep = "";
14756 const char *zSqlSep = "";
14757 char *zSql = 0;
14758 char *zFinal = 0;
14759 char *zBind = 0;
14760 int ii;
14761 int bSql = p->xSql ? 1 : 0;
14762
14763 if( nField<=0 ) return 0;
14764
14765 assert( nField<=pTab->nCol );
14766
14767 zSql = recoverMPrintf(p, "INSERT OR IGNORE INTO %Q(", pTab->zTab);
14768
14769 if( pTab->iRowidBind ){
14770 assert( pTab->bIntkey );
14771 zSql = recoverMPrintf(p, "%z_rowid_", zSql);
14772 if( bSql ){
14773 zBind = recoverMPrintf(p, "%zquote(?%d)", zBind, pTab->iRowidBind);
14774 }else{
14775 zBind = recoverMPrintf(p, "%z?%d", zBind, pTab->iRowidBind);
14776 }
14777 zSqlSep = "||', '||";
14778 zSep = ", ";
14779 }
14780
14781 for(ii=0; ii<nField; ii++){
14782 int eHidden = pTab->aCol[ii].eHidden;
14783 if( eHidden!=RECOVER_EHIDDEN_VIRTUAL
14784 && eHidden!=RECOVER_EHIDDEN_STORED
14785 ){
14786 assert( pTab->aCol[ii].iField>=0 && pTab->aCol[ii].iBind>=1 );
14787 zSql = recoverMPrintf(p, "%z%s%Q", zSql, zSep, pTab->aCol[ii].zCol);
14788
14789 if( bSql ){
14790 zBind = recoverMPrintf(p,
14791 "%z%sescape_crnl(quote(?%d))", zBind, zSqlSep, pTab->aCol[ii].iBind
14792 );
14793 zSqlSep = "||', '||";
14794 }else{
14795 zBind = recoverMPrintf(p, "%z%s?%d", zBind, zSep, pTab->aCol[ii].iBind);
14796 }
14797 zSep = ", ";
14798 }
14799 }
14800
14801 if( bSql ){
14802 zFinal = recoverMPrintf(p, "SELECT %Q || ') VALUES (' || %s || ')'",
14803 zSql, zBind
14804 );
14805 }else{
14806 zFinal = recoverMPrintf(p, "%s) VALUES (%s)", zSql, zBind);

Callers 1

recoverWriteDataStepFunction · 0.85

Calls 3

assertFunction · 0.85
recoverMPrintfFunction · 0.85
recoverPrepareFunction · 0.85

Tested by

no test coverage detected