我正在尝试使用以下函数更新表中的列:
-(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));
}
}当我运行这个函数时,一切正常,列也得到了更新。我之所以知道这一点,是因为我向数据库发出关于特定表的调用,并检查结果。问题是,当我调用同一个函数从另一个类读取表的条目时,我得到了不同的结果。
具体地说,当我调用:
AppDelegate* appDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
[appDelegate initViewController];在initViewController中,我调用同一个函数来读取表,并在更新之前获取列的条目。
为什么会发生这种情况?我可以提供更多的代码,如果需要。
https://stackoverflow.com/questions/53596431
复制相似问题