我在这里看到了有关阅读 user_version 的其他问题,这似乎对我来说效果很好。但是我尝试在 FMDB 中使用 sqlite 来设置我的版本号,但它没有设置。
_db = [self openDatabase];
[_db executeUpdate:[StudentController creationString]];
[_db executeUpdate:[ReadingController creationString]];
[_db executeUpdate:[SessionController creationString]];
NSLog(@"User version is %i", userVersion);
NSString *query = [NSString stringWithFormat:@"PRAGMA USER_VERSION = %i", userVersion];
[_db executeQuery:query];
我得到的输出是:
2014-01-16 22:16:25.438 MyApp[2810:1c103] User version is 2
2014-01-16 22:16:25.439 MyApp[2810:1c103] Query is PRAGMA USER_VERSION = 2
2014-01-16 22:18:09.272 MyApp[2810:1c103] Database copied and created
运行应用程序一段时间后,数据库保存和加载一切正常,我重新启动应用程序并读取版本号,然后调用此命令来检查版本号:
FMResultSet *ps = [_db executeQuery:@"PRAGMA USER_VERSION"];
NSDictionary *results = [[NSDictionary alloc] init];
while ([ps next]) {
results = [NSDictionary dictionaryWithDictionary:[ps resultDictionary]];
}
结果是一个结构良好的字典:
(lldb) po results
$0 = 0x09bf5770 {
"user_version" = 0;
}
(lldb)
我想知道:为什么没有为我设置用户版本号?
如果需要设置 PRAGMA user_version 使用:
[self.db setUserVersion:yourUserVersion]; // yourUserVersion is of uint32_t type
读取当前user_version用户
[self.db userVersion]; // returned value is of uint32_t type
FMDB 自 2013 年起对其进行了封装,因此您不必自己处理它。
文档:
http://ccgus.github.io/fmdb/html/Categories/FMDatabase+FMDatabaseAdditions.html
PS:@HalR 我认为您可以接受我的答案,因为它对于搜索“如何设置 user_version PRAGMA”的访问者可能更有用,并且它也可以通过更简洁的解决方案解决您的问题。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)