2012-02-06 61 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?