mercredi 28 janvier 2015

FMDB sqlite cannot update table on device but can update on simulator

I am new in iOS app. In my iPhone app, I have a database type sqlite (data.sqlite) and some tables in there (just call table: A, B, C,...) I got the problem when I try to update data to tables: table A can update successfully on simulator and iPhone device. But table B just can update on simulator, cannot update on iPhone device (after update, it show NEW data, but if really closed app - double click home button, and close app. And then open app again, the data is OLD data)


This code is for init database



- (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;
}


This code is for update



- (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];
}
}


I use the same code for update table A, and table A is update successfully on device and simulator. But table B get problem. Please help. Thank you.


Aucun commentaire:

Enregistrer un commentaire