2012-02-06 60 views
0

我正在使用FMDB。我執行以下代碼在FMDB中找不到主要標識

FMResultSet *results = [database executeQuery:@"select * from customer"]; 
while([results next]) 
{ 
    Customer *customer = [[Customer alloc] init]; 

    customer.customerId = [results intForColumn:@"id"]; 
    customer.firstName = [results stringForColumn:@"firstname"]; 
    customer.lastName = [results stringForColumn:@"lastname"]; 

    [customers addObject:customer]; 
    NSLog(@"%d", customer.customerId); 
} 

但我沒有獲取customerId值。我只想要自動遞增的rowid。

請提出好的建議......

+0

「客戶」表的結構是什麼? – Ilanchezhian 2012-02-06 09:07:46

+0

你的表中是否有名稱爲「id」的字段? – Ilanchezhian 2012-02-06 09:09:48

+0

不..沒有id的字段。它只有名字和姓氏。但我想要自動創建並自動遞增的rowid。 – Myaaoonn 2012-02-06 09:19:39

回答

1

創建一個類型爲INTEGER PRIMARY KEY的字段名稱爲id的列。插入一行時,您不需要爲該字段插入任何值。

More info

而且,僅供參考,releasecustomer對象以避免內存泄漏。

[customers addObject:customer]; 
NSLog(@"%d", customer.customerId); 
[customer release]; 
+0

謝謝..它的工作原理.. – Myaaoonn 2012-02-06 09:34:27

+0

如果它解決了你的問題,那麼如果你接受這個答案就太好了。 – Ilanchezhian 2012-02-06 09:53:12

0

您是否嘗試過使用intForColumnIndex:0,而不是intForColumn?