2013-04-06 71 views
0

刪除行我使用此代碼爲這件事獲取故障而從數據庫

這是頭

#import "SQLAppDelegate.h" 
#import "RootViewController.h" 
#import "Coffee.h" 

static sqlite3 *database = nil; 
static sqlite3_stmt *deleteStmt = nil; 

@implementation SQLAppDelegate 

這是低於行刪除

- (void) removeCoffee:(NSNumber *)coffeeObj { 

    NSLog(@"coffeeObj%@",coffeeObj); 
    NSInteger myInteger = [coffeeObj integerValue]; 
    int i = [coffeeObj integerValue]; 
    NSLog(@"myInteger%d",myInteger); 
    NSLog(@"i%d",i); 
    // this print index number of the row which was selected 
    if(deleteStmt == nil) { 

     const char *sql = "delete from Coffee where coffeeID = ?"; 
    //coffeeID is primary key it will be like 0,1,2,3,4... 


     if(sqlite3_prepare_v2(database, sql, -1, &deleteStmt, NULL) != SQLITE_OK) 

//在方法中碰到問題結尾的錯誤

  NSAssert1(0, @"Error while creating delete statement. '%s'", sqlite3_errmsg(database)); 
    } 

    //When binding parameters, index starts from 1 and not zero. 
    sqlite3_bind_int(deleteStmt, 1, myInteger); 

    if (SQLITE_DONE != sqlite3_step(deleteStmt)) 
     NSAssert1(0, @"Error while deleting. '%s'", sqlite3_errmsg(database)); 

    sqlite3_reset(deleteStmt); 



    [coffeeArray removeObjectAtIndex:myInteger]; 
} 

因未捕獲異常'NSInternalInconsistencyException'而終止應用程序,原因:'創建刪除語句時出錯。 「出來的

請幫助我如何走出這個問題

+0

嘿,這不是完整的日誌有什麼後'出來? – satheeshwaran 2013-04-06 14:15:52

回答

0

假設你的意思是說,錯誤是‘內存不足’的,然後這通常意味着你還沒有真正打開的數據庫。確保database變量正在引用實際打開的數據庫連接。