在循环中使用 sqlite3_bind_XXX
Using sqlite3_bind_XXX inside a loop
我想在我的代码中使用 SQLite 执行多个参数化插入。为此:
我在循环之外有一个准备语句:
error = sqlite3_prepare(connection, insert_sql, strlen(insert_sql), &stmt, NULL);
我想在循环中插入:
while ( not reached end of datafile ) {
// Insert into server table
sqlite3_bind_int(stmt, 1, id1);
sqlite3_bind_double(stmt, 2, latitude);
sqlite3_bind_double(stmt, 3, longitude);
sqlite3_step(stmt);
}
函数的 API 文档:https://www.sqlite.org/c3ref/bind_blob.html
提到:
sqlite3_step() has been called more recently than sqlite3_reset(), then the call will return SQLITE_MISUSE
Bindings are not cleared by the sqlite3_reset() routine
If any sqlite3_bind_() routine is passed a prepared statement that has
been finalized, the result is undefined and probably harmful.
我真的很困惑如何在 SQLite 中使用参数化查询进行重复插入?
只需在 sqlite3_step()
之后调用 sqlite3_reset()
。
我想在我的代码中使用 SQLite 执行多个参数化插入。为此:
我在循环之外有一个准备语句:
error = sqlite3_prepare(connection, insert_sql, strlen(insert_sql), &stmt, NULL);
我想在循环中插入:
while ( not reached end of datafile ) {
// Insert into server table
sqlite3_bind_int(stmt, 1, id1);
sqlite3_bind_double(stmt, 2, latitude);
sqlite3_bind_double(stmt, 3, longitude);
sqlite3_step(stmt);
}
函数的 API 文档:https://www.sqlite.org/c3ref/bind_blob.html 提到:
sqlite3_step() has been called more recently than sqlite3_reset(), then the call will return SQLITE_MISUSE
Bindings are not cleared by the sqlite3_reset() routine
If any sqlite3_bind_() routine is passed a prepared statement that has been finalized, the result is undefined and probably harmful.
我真的很困惑如何在 SQLite 中使用参数化查询进行重复插入?
只需在 sqlite3_step()
之后调用 sqlite3_reset()
。