在FMDB中找不到主要标识
问题描述:
我正在使用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。
请提出好的建议......
答
创建一个类型为INTEGER PRIMARY KEY的字段名称为id
的列。插入一行时,您不需要为该字段插入任何值。
而且,仅供参考,release
的customer
对象以避免内存泄漏。
[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
答
您是否尝试过使用intForColumnIndex:0,而不是intForColumn?
“客户”表的结构是什么? – Ilanchezhian 2012-02-06 09:07:46
你的表中是否有名称为“id”的字段? – Ilanchezhian 2012-02-06 09:09:48
不..没有id的字段。它只有名字和姓氏。但我想要自动创建并自动递增的rowid。 – Myaaoonn 2012-02-06 09:19:39