SQLite 编译语句何时'executed'

when does an sqlite compiled statement get 'executed'

本文关键字:executed 何时 编译 语句 SQLite      更新时间:2023-10-16

我正在为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中执行字节代码。