これが機能しない原因を見つけることができますか?
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
int record_to_delete = [[[data objectAtIndex:indexPath.row] recordID] integerValue];
[data removeObjectAtIndex:indexPath.row];
[self.tableView deleteRowsAtIndexPaths:[NSMutableArray arrayWithObject:indexPath] withRowAnimation:YES];
//Delete from TABLENAME where CRITERIA1=VALUE1 (AND CRITERIA2=VALUE2...)
//Delete from Data where RecordID=xxx
sqlite3 *database;
if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {
NSString *sqlStatement = [NSString stringWithFormat:@"delete from Data where RecordID = %d",record_to_delete];
NSLog(@"Statement is: %@", sqlStatement);
sqlite3_stmt *compiledStatement;
NSLog(@"Statement");
if(sqlite3_prepare_v2(database, [sqlStatement UTF8String], -1, &compiledStatement, NULL) == SQLITE_OK){
}
NSLog(@"Deleting");
sqlite3_finalize(compiledStatement);
NSLog(@"Deleted");
}
sqlite3_close(database);
}
}
データベース ソフトウェアで実行すると、SQL ステートメントは正常に機能します。ただし、iPhone シミュレーターで実行すると、データベースから削除されません。どんな助けでも大歓迎です。申し訳ありませんが、これ以上具体的に言えません。
ありがとう
2013-03-18 18:45:07.211 Navigation[842:c07] Statement is: delete from Data where RecordID = 1
2013-03-18 18:45:07.212 Navigation[842:c07] Statement
2013-03-18 18:45:07.212 Navigation[842:c07] Deleting
2013-03-18 18:45:07.213 Navigation[842:c07] Deleted
更新:それを機能させることができました。私はちょうど行方不明でした。
sqlite3_step(compiledStatement)
とにかくありがとう。