- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在尝试使用 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()
返回值是状态/错误代码,而不是查询的值。
要获取查询结果值,有两个主要选项:
使用 sqlite3_prepare_v2()
,sqlite_step()
用于 SQLITE_ROW
并使用例如访问数据sqlite3_column_int()
,使用 sqlite3_finalize()
完成准备好的查询。
提供回调函数作为您的 sqlite3_exec()
的第三个参数以捕获值。参见例如例如:Proper use of callback function of sqlite3 in C++
关于c++ - 无法在 SQLite 中设置 user_version,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23386180/
我在我的 ios 应用程序中使用 sqlite Db。我想获取 sqlite 数据库的 user_version。我使用以下代码设置 user_version。但是我无法将值设置为数据库 user_v
我正在尝试使用 SQLite 数据库的 user_version 功能。我无法实际设置 user_version,我不确定为什么。我尝试了各种执行查询以更新 user_version 的方法,并在网上
我在这里看到了关于读取 user_version 的其他问题,这对我来说似乎工作正常。但是我试图在 FMDB 中使用 sqlite 来设置我的版本号,但它没有设置。 _db = [self openD
我有这个代码: -(int)queryUserVersion: (sqlite3*) db { // get current database version of schema st
我想做的是从我的 SQLite 数据库加载并设置 user_version (PRAGMA user_version)。我正在使用 Entity Framework ,但如果我不能通过它来完成,那么我
这是我使用 SQLite 的第一个项目,在尝试进行半自动模式迁移时,我想使用 stackoverflow 上许多其他答案所建议的 user_version pragma。 我正尝试在 Golang 中
我正在尝试检查 sqlite 数据库的 user_version。我有一个管理工具来升级版本,但我不明白 pragma 语句的语法。我期待测试 if 语句中的值。有人可以提供代码示例吗?当我在我的 O
我是一名优秀的程序员,十分优秀!