SQLite update statement performed without error, but table row not updated?
I cant for the life of me see what it could be? Any Advice? Thanks
(void)setRegId: (NSInteger) _regId
{
NSInteger r_id = _regId;
NSInteger row = 1;
ret = sqlite3_open(dbName, &database);
if (ret !开发者_如何学JAVA= SQLITE_OK)
{
printf("Error opening the db: %s\n", sqlite3_errmsg(database));
sqlite3_close(database);
return;
}
sqlite3_stmt *compiledStatement = nil;
if (compiledStatement == nil) {
const char *sql = "UPDATE RegDB Set id = ? Where rowindex = ?";
if (sqlite3_prepare_v2(database, sql, -1, &compiledStatement, NULL) != SQLITE_OK)
{
NSLog(@"Error: failed to prepare compiledStatement with message '%s'.",sqlite3_errmsg(database));
return;
}
}
sqlite3_bind_int(compiledStatement, 1, r_id);
sqlite3_bind_int(compiledStatement, 2, row);
int success = sqlite3_step(compiledStatement);
if (success == SQLITE_ERROR){
NSLog(@"Error: failed to update compiledStatement with message '%s'.", sqlite3_errmsg(database));
}
sqlite3_finalize(compiledStatement);
if(sqlite3_close(database) != SQLITE_OK)
{
NSLog(@"Error: failed to closed DB with message '%s'.",sqlite3_errmsg(database));
}
}
You need to check that you are both sending the correct update statement, and that you are correctly reading the result.
Try logging your final statement (or at least the variables r_id
and row
). Use sqlite3 or SQLiteManager with Firefox to check changes in the database.
精彩评论