问题描述
我想在我的代码中使用SQLite进行多个参数化插入.为此:
I want to do multiple parameterized inserts with SQLite in my code. For this :
我在循环之外有一个准备语句,如下所示:
I have a single prepare statement outside of my loop as :
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 提到:
The API docs for the function : https://www.sqlite.org/c3ref/bind_blob.htmlmention that :
sqlite3_reset()例程未清除绑定
Bindings are not cleared by the sqlite3_reset() routine
如果任何sqlite3_bind_()例程通过了一条准备好的语句,该语句具有最终确定后,结果是不确定的,并且可能有害.
If any sqlite3_bind_() routine is passed a prepared statement that hasbeen finalized, the result is undefined and probably harmful.
我真的很困惑如何在SQLite中使用参数化查询重复插入?
I am really confused as to how do I do repeated inserts with parameterized query in SQLite?
推荐答案
只需在sqlite3_step()
之后调用sqlite3_reset()
.
这篇关于在循环内使用sqlite3_bind_XXX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!