2012-07-21 37 views
0

我有一個SQL語句的問題。我有一個UITableView,當用戶選擇一個項目時,他們得到一個選項列表。刪除條目當前回來了這一點:CocoaTouch - 如何從SQL中刪除條目問題

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)

我使用的代碼是用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

我想你錯過在查詢單引號:

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

應該

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

你可能也想看看在你的斷言中是否更具描述性(如添加查詢或sqlite返回的錯誤),以便這樣的事情可能會更加明顯。

+0

對不起,我應該檢查一下,我正在亂搞引號,並沒有正確替換它們!它沒有任何區別我仍然得到同樣的錯誤。 這是我的第一篇文章,只是註冊,所以我會學習! – RichAppz 2012-07-23 17:51:42