Exemple #1
0
/* Step the indicated statement, handling errors SQLITE_BUSY (by
** retrying) and SQLITE_SCHEMA (by re-preparing and transferring
** bindings to the new statement).
** TODO(adam): We should extend this function so that it can work with
** statements declared locally, not only globally cached statements.
*/
static int sql_step_statement(fulltext_vtab *v, fulltext_statement iStmt,
                              sqlite3_stmt **ppStmt){
  int rc;
  sqlite3_stmt *s = *ppStmt;
  assert( iStmt<MAX_STMT );
  assert( s==v->pFulltextStatements[iStmt] );

  while( (rc=sqlite3_step(s))!=SQLITE_DONE && rc!=SQLITE_ROW ){
    sqlite3_stmt *pNewStmt;

    if( rc==SQLITE_BUSY ) continue;
    if( rc!=SQLITE_ERROR ) return rc;

    rc = sqlite3_reset(s);
    if( rc!=SQLITE_SCHEMA ) return SQLITE_ERROR;

    v->pFulltextStatements[iStmt] = NULL;   /* Still in s */
    rc = sql_get_statement(v, iStmt, &pNewStmt);
    if( rc!=SQLITE_OK ) goto err;
    *ppStmt = pNewStmt;

    rc = sqlite3_transfer_bindings(s, pNewStmt);
    if( rc!=SQLITE_OK ) goto err;

    rc = sqlite3_finalize(s);
    if( rc!=SQLITE_OK ) return rc;
    s = pNewStmt;
  }
  return rc;

 err:
  sqlite3_finalize(s);
  return rc;
}
Exemple #2
0
    int command::execute_all()
    {
        int rc = eexecute();
        if (rc != SQLITE_OK) return rc;

        char const* sql = tail_;

        while (strlen(sql) > 0) { // sqlite3_complete() is broken.
            sqlite3_stmt* old_stmt = stmt_;

            if ((rc = prepare_impl(sql)) != SQLITE_OK) return rc;

            if ((rc = sqlite3_transfer_bindings(old_stmt, stmt_)) != SQLITE_OK) return rc;

            finish_impl(old_stmt);

            if ((rc = eexecute()) != SQLITE_OK) return rc;

            sql = tail_;
        }

        return rc;
    }
Exemple #3
0
/*
** Rerun the compilation of a statement after a schema change.
** Return true if the statement was recompiled successfully.
** Return false if there is an error of some kind.
*/
int sqlite3Reprepare(Vdbe *p){
  int rc;
  Vdbe *pNew;
  const char *zSql;
  sqlite3 *db;
  
  zSql = sqlite3VdbeGetSql(p);
  if( zSql==0 ){
    return 0;
  }
  db = sqlite3VdbeDb(p);
  rc = sqlite3Prepare(db, zSql, -1, 0, (sqlite3_stmt**)&pNew, 0);
  if( rc ){
    assert( pNew==0 );
    return 0;
  }else{
    assert( pNew!=0 );
  }
  sqlite3VdbeSwap(pNew, p);
  sqlite3_transfer_bindings((sqlite3_stmt*)pNew, (sqlite3_stmt*)p);
  sqlite3VdbeResetStepResult(pNew);
  sqlite3VdbeFinalize(pNew);
  return 1;
}