SQLite 编译语句何时'executed'
when does an sqlite compiled statement get 'executed'
我正在为sqlite api编写一个灯包装。
基本上,我很好奇/何时执行sqlite预先编译的语句...
当我去时:
char buffer[] = "INSERT INTO example VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7)";
sqlite3_stmt* stmt;
sqlite3_prepare_v2(mDb, buffer, strlen(buffer), &stmt, NULL);
for (unsigned i = 0; i < mVal; i++)
{
std::string id = getID();
sqlite3_bind_text(stmt, 1, id.c_str(), id.size(), SQLITE_STATIC);
sqlite3_bind_double(stmt, 2, getDouble());
sqlite3_bind_double(stmt, 3, getDouble());
sqlite3_bind_double(stmt, 4, getDouble());
sqlite3_bind_int(stmt, 5, getInt());
sqlite3_bind_int(stmt, 6, getInt());
sqlite3_bind_int(stmt, 7, getInt());
if (sqlite3_step(stmt) != SQLITE_DONE)
{
printf("Commit Failed!n");
}
sqlite3_reset(stmt);
}
sqlite3_finalize(stmt);
在什么时候执行实际的SQL?是在sqlite3_prepare_v2
的电话期间还是在第一个sqlite3_step
?
任何清晰度都非常感谢:)
欢呼
jarrett
根据sqlite3_prepare
的SQLite文档,我们看到:
要执行SQL查询,必须首先将其编译为字节代码程序 这些例程之一: sqlite3_prepare,sqlite3_prepare_v2,sqlite3_prepare16,sqlite3_prepare16_v2。
和sqlite3_step
:
在使用sqlite3_prepare_v2()或 sqlite3_prepare16_v2()或旧接口之一sqlite3_prepare()或 sqlite3_prepare16(),必须调用此功能一次或多次以评估 语句。
更多信息:
sqlite具有虚拟机,该虚拟机执行所有必要的操作以在所选数据库上执行您的代码。sqlite3_prepare
(及其家族)将您的SQL语句编译到可以在该虚拟机上执行的字节代码。另一方面,sqlite3_step
在VM中执行字节代码。
相关文章:
- 何时在引用或唯一指针上使用移动语义
- 何时提供默认参数作为模板参数
- C++-明确何时以及如何调用析构函数
- 在以唯一ptr为值的C++映射中,动态内存何时会被销毁
- 何时应通过引用传递矢量参数而不是按值传递矢量参数?
- 如果非动态变量被指针引用,何时超出范围?
- 类作用域的类型别名"using":[何时]方法中的用法可以先于类型别名?
- 何时定义QT_NO_CONTEXTMENU?
- 何时为派生类初始化 vptr?
- 如何知道何时调用删除以及何时调用 delete[] C++?
- 指针的 C++ 动态数组 - 何时需要使用它?
- 我应该在 C++ 中何时/为什么使用 STATIC?
- 变量的值何时可以在C++中意外更改?
- 调用方如何知道 VARIANT 中何时有十进制?
- 何时应在构造函数参数中使用 const C++?
- 我可以有一个 ELI5 作为参考和指针以及何时使用它们吗?
- async_write完成处理程序最早何时完成?
- 何时返回指针与返回对象的一般经验法则?
- 为什么我的编译器无法弄清楚这种转换,它何时存在?
- SQLite 编译语句何时'executed'