我正在使用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。
请提出一些建议...
最佳答案
创建字段名为 id
且类型为 INTEGER PRIMARY KEY 的列。插入行时,您不需要为此字段插入任何值。
并且,仅供引用,释放
customer
对象以避免内存泄漏。
[customers addObject:customer];
NSLog(@"%d", customer.customerId);
[customer release];
关于objective-c - 在 FMDB 中找不到主 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9157727/