【发布时间】:2014-04-30 19:14:46
【问题描述】:
我正在尝试使用 SQLite 数据库的 user_version 功能。我无法实际设置 user_version,我不知道为什么。我尝试了各种执行查询以更新 user_version 的方法,并且在网上进行了广泛的搜索,现在完全不知所措。
这是我的查询字符串。
const std::string kSetUserVersion = "PRAGMA user_version = 1;";
这里是我尝试设置 user_version 的地方,但是我的结果仍然是 0。
// Set the user version and check it is correct.
sqlite3_exec(dbConnection->db_handle, kSetUserVersion.c_str(), nullptr, nullptr, &db_err); // <-- this is not working!
long currentVersion = sqlite3_exec(dbConnection->db_handle, kGetUserVersion.c_str(), nullptr, nullptr, &db_err);
// If the PRAGMA statement fails, no error returns and it fails silently, so having to add check to see if it has worked.
if (currentVersion != 1) // Setting the user_version has failed.
{
throw DatabaseAccessException(sqlite3_errmsg(dbConnection->db_handle));
}
非常感谢任何帮助。
【问题讨论】:
-
sqlite3_exec函数不返回查询结果,您必须使用回调来获取返回的结果数据。 -
是设置
user_version还是查询? -
两者。在这种情况下,理想情况下我想要做的就是设置它,但是我目前也在查询它以查看我是否已成功设置它。我最终需要在其他地方查询它以检查数据库的更新是否可用。