【问题标题】:CocoaTouch - How To Delete Entry From SQL IssueCocoaTouch - 如何从 SQL 问题中删除条目
【发布时间】:2012-07-20 15:46:49
【问题描述】:

我的 SQL 语句有问题。我有一个 UITableView ,当用户选择一个项目时,他们会得到一个选项列表。删除条目目前正在返回:

2012-07-21 19:54:08.025 appName[25029:f803] *** Assertion failure in -[listSavedItemsViewController deleteEntryAtLocation:withField1:field1Value:andField2:field2Value:andField3:field3Value:andField4:field4Value:andField5:field5Value:andField6:field6Value:andField7:field7Value:andField8:field8Value:andField9:field9Value:andField10:field10Value:], /Users/Richard/Dropbox/**iOS Development**/App Development/turnAround/listSavedItemsViewController.m:133 2012-07-21 19:54:08.026 appName[25029:f803] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Error updating table.' *** First throw call stack: (0x159e022 0x172fcd6 0x1546a48 0xa762cb 0x7dbf 0x79fa 0x4b93f1 0x159fe99 0xe214e 0xe20e6 0x188ade 0x188fa7 0x188266 0x1073c0 0x1075e6 0xeddc4 0xe1634 0x1488ef5 0x1572195 0x14d6ff2 0x14d58da 0x14d4d84 0x14d4c9b 0x14877d8 0x148788a 0xdf626 0x2962 0x28d5) terminate called throwing an exception(lldb)

我使用的代码类似于 INSERTION 代码,但显然带有 DELETE 语句:

NSArray *strSplit = [cellText componentsSeparatedByString:@":"];
NSString *selectedOrderReference = [strSplit objectAtIndex:2];

NSString *sqlStatement = [NSString stringWithFormat:@"DELETE FROM '%@' WHERE '%@ = '%@')", turnAround, orderRef, selectedOrderReference];
NSLog(@"Clean: %@", sqlStatement);
char *err;
if (sqlite3_exec(turnAroundDB, [sqlStatement UTF8String], NULL, NULL, &err) != SQLITE_OK) {
    sqlite3_close(turnAroundDB);
    NSAssert(0, @"Error updating table.");
} else {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Deleted" 
                                                    message:@"Your entry has been successful deleted"
                                                   delegate:self 
                                          cancelButtonTitle:@"Done"
                                          otherButtonTitles:nil];
    [alert show];
    [alert release];
}

【问题讨论】:

    标签: iphone sql cocoa-touch sqlite


    【解决方案1】:

    我认为您在查询中缺少单引号:

    [NSString stringWithFormat:@"DELETE FROM '%@' WHERE '%@ = '%@')", turnAround, orderRef, selectedOrderReference];
    

    应该是

    [NSString stringWithFormat:@"DELETE FROM '%@' WHERE '%@' = '%@')", turnAround, orderRef, selectedOrderReference];
    

    您可能还希望在您的断言中更具描述性(例如添加查询或 sqlite 返回的错误),这样这样的事情可能会更加明显。

    【讨论】:

    • 对不起,我应该事先检查一下,我把引号弄乱了,没有正确替换它们!这没有任何区别,无论哪种方式,我仍然会遇到相同的错误。这是我的第一篇文章,刚刚注册,所以我会学习!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-21
    • 2013-06-21
    • 2021-10-14
    相关资源
    最近更新 更多