下面是我更新数据库记录的代码...
-(BOOL) addScoreInDatabase:(classname *)objGames
{
BOOL success;
sqlite3 *database;
const char *dbpath = [self.databasePath UTF8String];
if(sqlite3_open(dbpath, &database) == SQLITE_OK)
{
sqlite3_stmt *statement;
NSData *strJson = [objGames getJSON];
NSString *strContent = [[[[NSString alloc]
initWithData:strJson encoding:NSUTF8StringEncoding] stringByReplacingOccurrencesOfString:@"\\" withString:@""]stringByReplacingOccurrencesOfString:@"null" withString:@"\"\""];
NSLog(@"strcom %@",strContent);
NSString *query = [NSString stringWithFormat:@"UPDATE gamescore SET data ='%@' WHERE id = 1",strContent];
NSLog(@"query %@",query);
const char *sqlStatement = [query UTF8String];
if(sqlite3_prepare_v2(database, sqlStatement, -1, & statement, NULL) == SQLITE_OK)
{
if (sqlite3_step(statement) == SQLITE_DONE)
{
success = TRUE;
}
else
{
success = FALSE;
}
sqlite3_exec(database, "VACUUM;", 0, 0, nil);
}
sqlite3_finalize(statement);
sqlite3_close(database);
}
return success;
}
它不会进入if (sqlite3_step(statement) == SQLITE_DONE) 循环
结果查询是
UPDATE gamescore SET data ='{
"title" : "pacman",
"time" : "55",
"score" : "200",
"level" : "1"
}' WHERE id = 1
当我在 Sqlite Manager 中执行此查询时,它不会更新记录,而是显示类似这样的内容
谁能帮我更新我的记录?!..谢谢!