FMDB 用于从 iPhone 应用程序的数据库中读取数据
我正在使用以下代码从客户表中读取记录。由于某种原因,返回的结果集始终为空。
-(NSMutableArray *) getCustomers
{
NSMutableArray *customers = [[NSMutableArray alloc] init];
NSString *databaseName = @"Customers.db";
NSArray *documentsPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [documentsPath objectAtIndex:0];
NSString *databasePath = [documentsDir stringByAppendingPathComponent:databaseName];
FMDatabase *db = [FMDatabase databaseWithPath:databasePath];
if(![db open])
{
return nil;
}
FMResultSet *results = [db executeQuery:@"SELECT * FROM customers"];
while([results next])
{
Customer *customer = [[Customer alloc] init];
customer.firstName = [results stringForColumn:@"firstname"];
customer.lastName = [results stringForColumn:@"lastname"];
[customers addObject:customer];
}
[db close];
return customers;
}
我已多次检查数据库,它显示了数据,但由于某种原因 FMDB 无法检索它!
I am using the following code to read the records from the customers table. For some reason the resultset returned is always empty.
-(NSMutableArray *) getCustomers
{
NSMutableArray *customers = [[NSMutableArray alloc] init];
NSString *databaseName = @"Customers.db";
NSArray *documentsPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [documentsPath objectAtIndex:0];
NSString *databasePath = [documentsDir stringByAppendingPathComponent:databaseName];
FMDatabase *db = [FMDatabase databaseWithPath:databasePath];
if(![db open])
{
return nil;
}
FMResultSet *results = [db executeQuery:@"SELECT * FROM customers"];
while([results next])
{
Customer *customer = [[Customer alloc] init];
customer.firstName = [results stringForColumn:@"firstname"];
customer.lastName = [results stringForColumn:@"lastname"];
[customers addObject:customer];
}
[db close];
return customers;
}
I have checked in the database multiple times and it shows the data but for some reason the FMDB is not able to retrieve it!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将数据库日志错误设置为 true,这将显示您登录控制台,您可以在其中找到问题。
set db log errors to true, this will show you log in console where you can find the problem.