Reputation: 97
I am trying to update a column in a table by using this function:
-(void)updateID:(NSString*)ID{
NSString *queryInsertAndUpdate =
[NSString stringWithFormat:
@"UPDATE mytable set ID = '%@' limit 1",ID];
const char* query=[queryInsertAndUpdate UTF8String];
sqlite3_stmt *stmt = nil;
sqlite3_exec(_database, "BEGIN EXCLUSIVE TRANSACTION", 0, 0, 0);
if (sqlite3_prepare_v2(_database, query, -1, &stmt, NULL) == SQLITE_OK) {
if(sqlite3_step(stmt) == SQLITE_DONE) {
NSLog(@"Query Executed");
} else {
NSLog(@"Query NOT Executed: %s", sqlite3_errmsg(_database));
}
sqlite3_finalize(stmt);
}else{
NSLog(@"Statement NOT Prepared: %s", sqlite3_errmsg(_database));
}
}
When I run this function everything works fine and the column gets updated. I know that because I make a call to the database about the specific table and I check the results. The thing is, when I call the same function that reads the entries of the table from another class, I get different results.
Specifically, when I call:
AppDelegate* appDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
[appDelegate initViewController];
inside initViewController
I call the same function that reads the table and I get the entry of the column before the update.
Why is this happening? I can provide more code if needed.
Upvotes: 0
Views: 45
Reputation: 51945
If you have a "BEGIN EXCLUSIVE TRANSACTION", then you also need to have a COMMIT TRANSACTION
Upvotes: 1