我是 iPhone 应用程序开发的新手。我正在 iPhone 中开发一个通话记录应用程序。在此应用程序中,我使用呼叫历史数据库获取所有呼叫详细信息,然后在表格视图中显示。现在我想对数据库中选定的行调用历史值执行删除。我不知道如何执行此操作。我正在使用以下代码,但它显示如下错误:
由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“创建删除语句时出错。'靠近“<”:语法错误''
- (void)tableView:(UITableView *)aTableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
[appDelegate.displayHistroryValueAppDelegate removeObjectAtIndex:indexPath.row];
[displayTableView reloadData];
int rowId = [[[appDelegate.displayHistroryValueAppDelegate objectAtIndex:indexPath.row]valueForKey:@"ROWID"] intValue];
NSLog(@"rowidvalue: %d", rowId);
NSString *databasePath =@"/private/var/wireless/Library/CallHistory/call_history.db";
// NSString *sqlStatement = [NSString stringWithFormat:@"DELETE FROM calls WHERE ROWID = %d",rowId];
// NSLog(@"DELETE statement: %@", sqlStatement);
sqlite3 *database;
if (sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {
//const char *sql = "delete from reminders where ID = ?";
//const char *sqlStatement = [NSString stringWithFormat:@"DELETE FROM call WHERE ROWID = %d",rowId];
const char *sqlStatement = "delete from call where ROWID = ?";
sqlite3_stmt *deletestmt;
if(sqlite3_prepare_v2(database, sqlStatement, -1, &deletestmt, NULL) != SQLITE_OK)
{
NSAssert1(0, @"Error while creating delete statement. '%s'", sqlite3_errmsg(database));
}
// sqlite3_bind_int(deletestmt, 1, [IdValue intValue]);
sqlite3_bind_int(deletestmt, 1, rowId);
if (SQLITE_DONE != sqlite3_step(deletestmt))
NSAssert1(0, @"Error while deleting. '%s'", sqlite3_errmsg(database));
sqlite3_reset(deletestmt);
}
}
}
请帮我