我的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];
}
答案 0 :(得分:0)
我认为您在查询中缺少单引号:
[NSString stringWithFormat:@"DELETE FROM '%@' WHERE '%@ = '%@')", turnAround, orderRef, selectedOrderReference];
应该是
[NSString stringWithFormat:@"DELETE FROM '%@' WHERE '%@' = '%@')", turnAround, orderRef, selectedOrderReference];
您可能还希望在断言中考虑更具描述性(例如添加查询或sqlite返回的错误),以便这样的事情可能会更加明显。