我试图像这样更新表中的条目:
NSFileManager *fileMgr=[NSFileManager defaultManager];
NSString *dbPath=[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"quizDB.sqlite"];
if ([fileMgr fileExistsAtPath:dbPath]) {
NSLog(@"DB does exist!");//displayed
}
const char *dbpath = [dbPath UTF8String];
sqlite3_stmt *updateStmt;
if (sqlite3_open(dbpath, &contactDB) == SQLITE_OK)
{
NSLog(@"%i",id_quiz);//displayed, in a test case it display 1 which is a quiz ID in the table
NSString *querySql=[NSString stringWithFormat:@"Update quiz set etat=1 where id=\"%i\"",id_quiz];
const char*sql=[querySql UTF8String];
sqlite3_prepare_v2(contactDB, sql, -1, &updateStmt, NULL);
if(SQLITE_DONE != sqlite3_step(updateStmt))
{
NSAssert1(0, @"Error while updating. '%s'", sqlite3_errmsg(contactDB));
}
else{
sqlite3_reset(updateStmt);
NSLog(@"Update done successfully!");//this is also displayed, i guess everything is ok then and the entry is updated
}
sqlite3_finalize(updateStmt);
sqlite3_close(contactDB);
}
在日志中,我收到消息:Update done successfully!
所以我认为一切正常,但是当我在 Mozilla Firefox 的 SQLite 管理器中检查数据库时,该条目没有更新。我错过了什么吗?感谢帮助