If you are reusing the update statements you should call sqlite3_reset() on the statement right after use, a call to sqlite3_clear_bindings() might also be appropriate to make sure the assigned parameters are reset. You should then call sqlite3_finalize only when cleaning up. This might be your problem because if the statement is still being executed and you call sqlite3_finalize on it then execution will be interrupted. That said, you should most probably be reusing statements for efficiency if you are not already. For me it works like so:
static sqlite3_stmt *update_statement = nil;
-(void)performUpdateOnRow: (NSInteger)primaryKey {
if (update_statement == nil){
const char *sql = "UPDATE foo SET bar=?,baz=? WHERE pk=?";
if( sqlite3_prepare_v2(database, sql, -1, &update_statement, NULL) != SQLITE_OK ){
// Insert some serious error handling here!
}
}
sqlite3_bind_text(update_statement, 1, @"first", -1,SQLITE_TRANSIENT);
sqlite3_bind_text(update_statement, 2, @"second", -1,SQLITE_TRANSIENT);
sqlite3_bind_int(update_statement, 3, primaryKey);
sqlite3_step(update_statement);
sqlite3_reset(update_statement);
}