我正在嘗試將寬字串系結到 sqlite3 準備好的陳述句。我試圖遵循這個答案,但它沒有用
const auto sql_command = L"SELECT * FROM register_names WHERE name is ?VVV";
sqlite3_stmt *statement;
sqlite3_prepare16(db, sql_command, -1, &statement, NULL);
wstring p = ObjectAttributes->ObjectName->Buffer;
sqlite3_bind_text16(statement, 1, p.data(), -1, SQLITE_TRANSIENT);
printf("sql command: %s\n", sqlite3_sql(statement));
auto data = "Callback function called";
char *zErrMsg = nullptr;
auto rc = sqlite3_exec(db, sqlite3_sql(statement), callback, (void *) data, &zErrMsg);
我嘗試在 sqlite3_bind_text16 中使用 0 或 1,但我要么得到空字串,要么得到沒有替換的原始字串。我究竟做錯了什么?
uj5u.com熱心網友回復:
在您的 SQL 陳述句中,更改is為=,然后更改?VVV為?。
更重要的是,根據檔案,sqlite3_exec()這不是執行sqlite3_stmt您準備好的正確方法。您需要使用sqlite3_step()(and sqlite3_finalize()) 代替。
嘗試這個:
const auto sql_command = u"SELECT * FROM register_names WHERE name = ?";
sqlite3_stmt *statement;
auto rc = sqlite3_prepare16(db, sql_command, -1, &statement, NULL);
if (rc != SQLITE_OK) ...
rc = sqlite3_bind_text16(statement, 1, ObjectAttributes->ObjectName->Buffer, ObjectAttributes->ObjectName->Length, SQLITE_TRANSIENT);
if (rc != SQLITE_OK) ...
printf("sql command: %s\n", sqlite3_sql(statement));
while ((rc = sqlite3_step(statement)) == SQLITE_ROW)
{
// process row as needed using sqlite3_column_XXX() functions...
}
if (rc != SQLITE_DONE) ...
rc = sqlite3_finalize(statement);
if (rc != SQLITE_OK) ...
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/446892.html
