多次執行預準備語句
執行語句後,呼叫 sqlite3_reset()
會將其恢復到原始狀態,以便可以重新執行。
通常,雖然語句本身保持不變,但引數會更改:
const char *sql = "INSERT INTO MyTable(ID, Name) VALUES (?, ?)";
sqlite3_stmt *stmt;
int err;
err = sqlite3_prepare_v2(db, sql, -1, &stmt, NULL);
if (err != SQLITE_OK) {
printf("prepare failed: %s\n", sqlite3_errmsg(db));
return /* failure */;
}
for (...) {
sqlite3_bind_int (stmt, 1, ...); /* ID */
sqlite3_bind_text(stmt, 2, ...); /* name */
err = sqlite3_step(stmt);
if (err != SQLITE_DONE) {
printf("execution failed: %s\n", sqlite3_errmsg(db));
sqlite3_finalize(stmt);
return /* failure */;
}
sqlite3_reset(stmt);
}
sqlite3_finalize(stmt);
return /* success */;