【发布时间】:2015-01-29 07:12:44
【问题描述】:
我是 iOS 应用程序的新手。在我的 iPhone 应用程序中,我有一个数据库类型 sqlite (data.sqlite) 和一些表(只需调用表:A、B、C、...) 当我尝试将数据更新到表时遇到问题:表 A 可以在模拟器和 iPhone 设备上成功更新。但是表B只能在模拟器上更新,不能在iPhone设备上更新(更新后,它显示新数据,但如果真的关闭应用程序-双击主页按钮,然后关闭应用程序。然后再次打开应用程序,数据是旧数据)
此代码用于初始化数据库
- (id)init {
self = [super init];
NSString *bundelFilePath = [[NSBundle mainBundle] pathForResource:@"data" ofType:@"sqlite"];
NSString *dbPath = [LIBRARY_DIR stringByAppendingPathComponent:@"data.sqlite"];
//New version
if ( ![[NSFileManager defaultManager] fileExistsAtPath:dbPath] ) {
[[NSFileManager defaultManager] copyItemAtPath:bundelFilePath toPath:dbPath error:nil];
_database = [FMDatabase databaseWithPath:dbPath];
[_database open];
}
return self;
}
此代码用于更新
- (void)updateDetails:(NSMutableArray *)details {
@synchronized(self) {
[_database beginTransaction];
for (int i = 0; i< details.count; i++) {
B *b = [details objectAtIndex:i];
NSString *sql = [NSString stringWithFormat:@"UPDATE B SET display_order=%d WHERE columnIdx=%d", i, b.colIdx];
[_database executeUpdate:sql];
}
[_database commit];
}
}
我使用相同的代码更新表 A,并且表 A 在设备和模拟器上成功更新。但表 B 有问题。请帮忙。谢谢。
【问题讨论】:
标签: ios sqlite sql-update device fmdb