我有SQLLite3更新功能的问题。我不知道我的查询是错误的还是我构建的函数有问题。
- (void)updateRowWithID:(NSString *)databaseItem AndWithColumnName:(NSString *)changeColumnName AndWithValue:(NSString *)changeValue
{
NSString * sql = [NSString stringWithFormat:@"UPDATE tblUsers SET %@ = %@ WHERE ID = %@", changeColumnName, changeValue, databaseItem];
sqlite3_stmt * statement;
if(sqlite3_open([[self path]UTF8String], &database) == SQLITE_OK)
{
const char *insert_stmt = [sql UTF8String];
NSLog(@"UPDATE: %@",sql);
// here it says the something wrong and the application crush.
if(sqlite3_prepare_v2(database, insert_stmt, -1, &statement, NULL) != SQLITE_OK)
{
NSAssert(0, @"ERROR ON INSERTING TO TABLE");
}
int success = sqlite3_step(statement);
if(success)
NSLog(@"Success");
}
}
这是粉碎日志:
2012-10-27 22:07:47.088 myapplication[21778:15803] *** Assertion failure in -[userData updateRowWithID:AndWithColumnName:AndWithValue:], /Users/user/myapplication/userData.m:47
2012-10-27 22:07:47.089 myapplication[21778:15803] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'ERROR ON INSERTING TO TABLE'
*** First throw call stack:
(0x1a70022 0x1600cd6 0x1a18a48 0x133f2cb 0xcfc8 0xfcab 0x1a71e99 0x9ab14e 0x9ab0e6 0xa51ade 0xa51fa7 0xa51266 0x9d03c0 0x9d05e6 0x9b6dc4 0x9aa634 0x224fef5 0x1a44195 0x19a8ff2 0x19a78da 0x19a6d84 0x19a6c9b 0x224e7d8 0x224e88a 0x9a8626 0x2835 0x2735 0x1)
terminate called throwing an exception(lldb)
请告诉我,我在这里做错了什么?
谢谢!