我有这个问题....下面的代码不会产生错误,但表不会提交更改!我已经控制了所有日志,所有值都是正确的,并且所有 If 测试都很好,但是 db 上的值没有改变。有人有想法吗?谢谢!!
- (void) saveData {
//database file system
NSFileManager *fileMgr = [NSFileManager defaultManager];
NSString *dbPath = [[[NSBundle mainBundle] resourcePath ]stringByAppendingPathComponent:@"enduroRace.sqlite"];
BOOL success = [fileMgr fileExistsAtPath:dbPath];
if(!success)
{
NSLog(@"unable to load db: '%@'.", dbPath);
}
//apro database
sqlite3 *db;
if(!(sqlite3_open([dbPath UTF8String], &db) == SQLITE_OK))
{
NSLog(@"unable to open DB");
}
//inizio query
sqlite3_stmt *statement;
NSString *querySQL = @"UPDATE setting SET delay=?";
const char *query_stmt = [querySQL UTF8String];
if (sqlite3_prepare_v2(db, query_stmt, -1, &statement, NULL) == SQLITE_OK) {
int valoreAttuale = [[sharedClass sharedController] ritardoMusic];
sqlite3_bind_int(statement, 1,valoreAttuale);
}
if (sqlite3_step(statement) != SQLITE_DONE)
{
NSLog(@"Error...");
}
sqlite3_finalize(statement);
sqlite3_close(db);
}