我正在更新數據庫中的條目,該語句工作並且代碼在數據庫中更新。一旦應用程序已關閉並重新打開,但數據庫尚未保存。它似乎創建一個臨時數據庫,然後不實際保存到應用程序正在讀取的數據庫。SQLite數據庫沒有保存在iOS上
這裏是我的代碼:
-(void)updateDatabase:(int)Level andPlayer:(int)questionID{
DataClass *obj=[DataClass getInstance];
//NSFileManager *filemgr = [NSFileManager defaultManager];
NSString* Database =[NSString stringWithFormat:@"levelProgress.db"];
NSString* databaseP = [[[NSBundle mainBundle]resourcePath]stringByAppendingPathComponent:Database];
databasePath = [[NSString alloc]initWithString:databaseP];
const char *dbpath = [databasePath UTF8String];
sqlite3_stmt *statement;
if (sqlite3_open(dbpath, &questionDB) == SQLITE_OK) {
NSString *querySQL = [NSString stringWithFormat:@"UPDATE levelProgress SET completed_questions=completed_questions+1 WHERE level=%d", obj.levelSelected];
const char *query_stmt = [querySQL UTF8String];
sqlite3_prepare_v2(questionDB, query_stmt, -1, &statement, NULL);
if(sqlite3_step(statement)==SQLITE_DONE){
NSLog(@"update worked");
}else{
NSLog(@"did not work");
}
sqlite3_finalize(statement);
sqlite3_close(questionDB);
}
}
任何幫助,將不勝感激。
您無法更新只讀文件。 – rmaddy