0

I get no result when using the below query however i do when i say "SELECT * FROM ORDER_HEADER". I have typed "SELECT * FROM ORDER_HEADER WHERE CUSTOMER = 1" in SqlLite Database Browser and gotten back the correct data. Why am i not receiving my row result? I have also tried SELECT * FROM ORDER_HEADER WHERE CUSTOMER = %d",1. Thank you for your help.

- (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];}

I'm pretty sure it has to do with the CUSTOMER column being a Numeric type? I tried saying "SELECT * FROM ORDER_HEADER WHERE ID = 1" and it worked where ID is an integer primary key datatype. That being said. What do i need to do to search by a Numeric datatype? Thanks again.

4

1 回答 1

0

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

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

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

于 2012-04-30T05:21:31.513 回答