我在我的数据库上运行SQLite查询。 select查询工作正常,但是当我运行SQLite查询时没有生成错误,但它仍然没有更新我的数据库值。 功能如下:
@try {
NSFileManager *fileMgr = [NSFileManager defaultManager];
NSString *dbPath = [[[NSBundle mainBundle] resourcePath ]stringByAppendingPathComponent:@"bikeapp.sqlite"];
BOOL success = [fileMgr fileExistsAtPath:dbPath];
if(!success)
{
NSLog(@"Cannot locate database file '%@'.", dbPath);
}
if(!(sqlite3_open([dbPath UTF8String], &db) == SQLITE_OK))
{
NSLog(@"An error has occured.");
}
NSString *query = [NSString stringWithFormat:@"UPDATE bikes SET to_show = 0 where id = %ld",(long)bikeId];
//const char *sql = "UPDATE bikes SET to_show = 0 where id = 3";
const char *sql = [query UTF8String];
sqlite3_stmt *sqlStatement;
if(sqlite3_prepare(db, sql, -1, &sqlStatement, NULL) != SQLITE_OK)
{
NSLog(@"Problem with prepare statement");
}
if(sqlite3_step(sqlStatement))
{
return YES;
}else
return NO;
//
}
@catch (NSException *exception) {
NSLog(@"An exception occured: %@", [exception reason]);
}
代码运行时没有任何错误或异常,但它没有更新数据库中的值。直接在数据库上运行时的查询显示正在进行的更改。如果有人可以帮助我,我会很感激。感谢。