2011-11-27 165 views
1

從SQLite數據庫檢索整數值時遇到問題。我有一個Integer存儲在數據庫中的疾病。在我的疾病類中,我宣佈它爲NSNumber * sickid。從SQlite數據庫檢索整數值

從數據庫讀取時,我做

NSNumber *illid = [NSNumber numberWithInt:(int)sqlite3_column_text(compiledStatement, 0)]; 
.......... 
[listContent addObject:[Illness illnessWithid:illid illness:illness defn:definition]]; 

其中的listContent是NSMutable陣列。

現在,我將疾病對象傳遞給另一個類,並嘗試檢索疾病查詢數據庫。

NSNumber *myno = illness.illnessid; 
NSInteger illid = [myno integerValue]; 

但這個illid不是存儲在db中的整數值。我需要幫助!

回答

0

您正在將SQLite數據庫中的值作爲char *並試圖將其顯式轉換爲int。這不可能。作爲替代方案,直接將值作爲int即可。

改變這一行...

NSNumber *illid = [NSNumber numberWithInt:(int)sqlite3_column_text(compiledStatement, 0)]; 

到...

NSNumber *illid = [NSNumber numberWithInt:sqlite3_column_int(compiledStatement, 0)]; 
+0

太感謝你了!它像一個魅力! – user1065969