2011-10-06 52 views
0

我不能爲我的生活看到它可能是什麼?任何建議?謝謝SQLite更新語句執行時沒有錯誤,但表格行未更新?

(void)setRegId: (NSInteger) _regId 

{ 

NSInteger r_id = _regId; 
NSInteger row = 1; 

ret = sqlite3_open(dbName, &database); 
if (ret != SQLITE_OK) 
{ 
    printf("Error opening the db: %s\n", sqlite3_errmsg(database)); 
    sqlite3_close(database); 
    return; 
} 

sqlite3_stmt *compiledStatement = nil; 
if (compiledStatement == nil) { 
    const char *sql = "UPDATE RegDB Set id = ? Where rowindex = ?"; 

    if (sqlite3_prepare_v2(database, sql, -1, &compiledStatement, NULL) != SQLITE_OK) 
    { 
     NSLog(@"Error: failed to prepare compiledStatement with message '%s'.",sqlite3_errmsg(database)); 
     return; 
    } 
} 

sqlite3_bind_int(compiledStatement, 1, r_id); 
sqlite3_bind_int(compiledStatement, 2, row); 

int success = sqlite3_step(compiledStatement); 
if (success == SQLITE_ERROR){ 
    NSLog(@"Error: failed to update compiledStatement with message '%s'.", sqlite3_errmsg(database)); 
} 

sqlite3_finalize(compiledStatement); 

if(sqlite3_close(database) != SQLITE_OK) 
{ 
    NSLog(@"Error: failed to closed DB with message  '%s'.",sqlite3_errmsg(database)); 
    } 

     } 
+0

您是在模擬器還是在設備上進行調試,是否有可能保存更新,但在下一個版本上覆蓋.db文件? – meggar

+0

即時在設備上。我認爲這接近問題,因爲相同的代碼在單獨的項目中工作正常。我在應用程序在設備上運行時多次運行update方法,當我讀取數據庫的內容時,它們始終是Db中設置的默認值。感謝您的建議。 – null

回答

0

您需要檢查您是否都發送正確的更新聲明,並且您正確讀取結果。

嘗試記錄您的最終陳述(或至少變量r_idrow)。在Firefox中使用sqlite3或SQLiteManager來檢查數據庫中的更改。