gpt4 book ai didi

c++ - 在 Sqlite C++ 中插入以下语句

转载 作者:行者123 更新时间:2023-11-28 02:51:24 29 4
gpt4 key购买 nike

我目前正在使用 SQlite 客户端,它使用以下查询将项目添加到表中

INSERT INTO "main"."MyTable" ("urn","total") VALUES (?1,?2)
Parameters:
param 1 (text): sdsdds
param 2 (integer): 23

现在我正在将其翻译成 C++

const char *sqlInsert = "INSERT INTO main.MyTable VALUES(`abc`, 12);";
rc = sqlite3_exec(db, sqlInsert, NULL, NULL, &error);
if (rc)
{
cerr << "Error executing SQLite3 statement: " << sqlite3_errmsg(db) << endl << endl;
sqlite3_free(error);
}
else
{
cout << "Inserted a value into MyTable." << endl << endl;
}

不过好像插入的sqlite语句是无效的。关于我可能做错了什么的任何建议?将上述内容转换为准备好的语句的示例将不胜感激

最佳答案

使用 '' 单引号来引用字符串文字。 (使用 ` ` 反引号来引用标识符,例如表名和列名。)

如果你想对文字使用 ? 占位符,你可以。将 sqlite3_exec() 替换为 sqlite3_prepare_v2(),然后是 sqlite3_bind_...()sqlite3_step()

关于c++ - 在 Sqlite C++ 中插入以下语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22955437/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com