objective-c - 在 FMDB 中找不到主 ID

标签 objective-c ios

我正在使用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 的列。插入行时,您不需要为此字段插入任何值。

More info

并且,仅供引用,释放 customer 对象以避免内存泄漏。

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

关于objective-c - 在 FMDB 中找不到主 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9157727/

相关文章:

ios - 从 NSDate 对象获取 UTC 时间和本地时间

iphone - 为什么每次我尝试切换到第二个 View 时,iOS 模拟器版本 5.1 (272.21) 都会关闭?

加载时 iOS 8 Today 小部件不显示

ios - 尝试从对象[1]插入nil对象

objective-c - 如何按比例缩放 UIImageView?

ios - 如何在 ViewController 中设置文件路径?

ios - 如何使用 Swift 制作项目符号列表?

iphone - iOS 将数据从 tableview 传递到新 View

ios - 自动布局和线性方程

ios - 在 View 加载时设置 ScrollView 内容大小