FMResultSet参数化查询不返回结果xcode

时间:2012-04-30 04:57:31

标签: xcode

使用以下查询时没有结果,但是当我说“SELECT * FROM ORDER_HEADER”时,我会这样做。我在SqlLite数据库浏览器中输入了“SELECT * FROM ORDER_HEADER WHERE CUSTOMER = 1”并获得了正确的数据。为什么我没有收到行结果? 我也尝试过SELECT * FROM ORDER_HEADER WHERE CUSTOMER =%d“,1。感谢您的帮助。

- (void)viewDidLoad{

[super viewDidLoad];

[super viewDidLoad];
salesOrders = [[NSMutableArray alloc] init];
NSString *databasePath = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"MobilePDQ"];
FMDatabase *db  = [[FMDatabase alloc] initWithPath:databasePath];
[db open];
FMResultSet *fResult = [db executeQueryWithFormat:@"SELECT * FROM ORDER_HEADER WHERE CUSTOMER = %d",1];
NSLog ( @"has results: %@", [fResult hasAnotherRow] ? @"YES" : @"NO" );
while([fResult next])
{
    SalesOrderHeaderController *salesOrder = [SalesOrderHeaderController alloc];
    salesOrder.salesOrderID = [fResult intForColumn:@"ID"];
    salesOrder.creationDate = [fResult stringForColumn:@"CREATION_DATE"];
    [salesOrders addObject:salesOrder];
}
[db close];}

我很确定它与CUSTOMER列是一个数字类型有什么关系?我试着说“SELECT * FROM ORDER_HEADER WHERE ID = 1”,它的工作原理是ID是一个整数主键数据类型。话虽如此。通过Numeric数据类型搜索需要做什么?再次感谢。

1 个答案:

答案 0 :(得分:0)

您似乎在数据库名称中缺少.sqlite。检查db是否打开。也请尝试此查询

[db executeQueryWithFormat:@"SELECT * FROM ORDER_HEADER WHERE CUSTOMER = ?",[NSnumber numberWithInt:1]];

您的问题可能已得到解决。