【问题标题】:delete SQLITE row UITABLEVIEW删除 SQLITE 行 UITABLEVIEW
【发布时间】:2013-03-19 03:47:01
【问题描述】:

你能发现任何会导致它无法工作的东西吗?

- (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)

还是谢谢。

【问题讨论】:

  • 已打开数据库?您能否将日志连同您的问题一起包含在内?
  • xcode 删除设备上的数据库对我来说是个新闻。

标签: iphone ios objective-c sqlite


【解决方案1】:

在 iOS 中,您没有对 app bundle 的写入权限。建议的方法是在第一次运行应用程序时将数据库复制到文档文件夹中,然后从那里管理数据库。

看这里:Unable to connect SQLite Database in iOS

【讨论】:

  • 如何将其复制到文件夹中?
  • 我添加了一个有用问题的链接。
  • 我很确定我的数据库已经打开了。因为一切都从数据库中显示出来。只是删除部分似乎不起作用。
  • 在您的情况下,您可以打开它,因此您具有读取权限但没有写入权限。答案解释了如何将数据库复制到文档文件夹中,试试吧。
猜你喜欢
  • 2017-09-30
  • 2023-04-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多