2012-10-27 62 views
0

我有SQLLite3更新函數的問題。我不知道我的查詢是錯誤的還是我構建的函數有問題。應用程序不斷崩潰與NSInternalInconsistencyException錯誤sqlite3更新

- (void)updateRowWithID:(NSString *)databaseItem AndWithColumnName:(NSString *)changeColumnName AndWithValue:(NSString *)changeValue 
{ 
    NSString * sql = [NSString stringWithFormat:@"UPDATE tblUsers SET %@ = %@ WHERE ID = %@", changeColumnName, changeValue, databaseItem]; 

    sqlite3_stmt * statement; 
    if(sqlite3_open([[self path]UTF8String], &database) == SQLITE_OK) 
    { 
     const char *insert_stmt = [sql UTF8String]; 

     NSLog(@"UPDATE: %@",sql); 

     // here it says the something wrong and the application crush. 
     if(sqlite3_prepare_v2(database, insert_stmt, -1, &statement, NULL) != SQLITE_OK) 
     { 
      NSAssert(0, @"ERROR ON INSERTING TO TABLE"); 
     } 
     int success = sqlite3_step(statement); 
     if(success) 
      NSLog(@"Success"); 
    } 
} 

這是美眉日誌:

2012-10-27 22:07:47.088 myapplication[21778:15803] *** Assertion failure in -[userData updateRowWithID:AndWithColumnName:AndWithValue:], /Users/user/myapplication/userData.m:47 
2012-10-27 22:07:47.089 myapplication[21778:15803] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'ERROR ON INSERTING TO TABLE' 
*** First throw call stack: 
(0x1a70022 0x1600cd6 0x1a18a48 0x133f2cb 0xcfc8 0xfcab 0x1a71e99 0x9ab14e 0x9ab0e6 0xa51ade 0xa51fa7 0xa51266 0x9d03c0 0x9d05e6 0x9b6dc4 0x9aa634 0x224fef5 0x1a44195 0x19a8ff2 0x19a78da 0x19a6d84 0x19a6c9b 0x224e7d8 0x224e88a 0x9a8626 0x2835 0x2735 0x1) 
terminate called throwing an exception(lldb) 

請告訴我,我究竟錯在這裏做什麼?

謝謝!

+1

那麼,'sqlite3_prepare_v2()'的返回值是什麼?那會告訴你出了什麼問題。 –

回答

1

致電sqlite3_errmsg()找出問題所在。

表或列名可能是錯誤的,或者由於path中的文件不存在而導致數據庫爲空。