我对 sqlite 的查询有一些奇怪的问题。当我的 firstvar 值介于 30000 和 100000 之间时,我的查询不会返回任何内容。但是当 var 低于 30000 且大于 100000 时,它会。它在我的 xcode 应用程序中与在 sqlite 浏览器中相同。
SELECT * FROM OFFERS WHERE price > firstvar AND price < secondvar
这是一些示例数据: http ://www.purespain.com/example%20data.png
所以当我执行查询时
SELECT * FROM OFFERS WHERE price > 40000 AND price < 300000
我没有输出,而有很多价格(prijs)应该符合标准的报价。
例如,当我表演时
SELECT * FROM OFFERS WHERE price > 140000 AND price < 300000
或 SELECT * FROM OFFERS where price > 0 AND price < 300000
然后我有正确的结果
执行查询的代码是:
-(NSMutableArray *)selectOffersWithOndergrens:(int)ondergrens andBovengrens:(int)bovengrens andSoort:(NSString *)soort{
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask , YES);
NSString *docpath = [path objectAtIndex:0];
dbPathString = [docpath stringByAppendingPathComponent:@"puurspanje.db"];
Offers = [[NSMutableArray alloc] init];
// Get all newsitems from the sqlite database
sqlite3_stmt *get_offers_stmt;
NSString *querysql = [[NSString alloc]init];
if (sqlite3_open([dbPathString UTF8String], &puurspanjeDB)==SQLITE_OK){
[Offers removeAllObjects];
if (![soort isEqual: @"alle"]){
querysql = [NSString stringWithFormat:@"SELECT * FROM OFFERS WHERE prijs > %d AND prijs < %d AND soort = (SELECT TYPE_ID FROM TYPES WHERE NAME LIKE '%@' )", ondergrens, bovengrens, soort];
}else{
querysql = [NSString stringWithFormat:@"SELECT * FROM OFFERS WHERE prijs > %d AND prijs < %d", ondergrens, bovengrens];
}
const char* query_sql = [querysql UTF8String];
if (sqlite3_prepare(puurspanjeDB, query_sql, -1, &get_offers_stmt, NULL)==SQLITE_OK) {
while (sqlite3_step(get_offers_stmt)==SQLITE_ROW) {
NSString *listing_ID = [[NSString alloc]initWithUTF8String:(const char *) sqlite3_column_text(get_offers_stmt, 1)];
NSString *titel = [[NSString alloc]initWithUTF8String:(const char * )sqlite3_column_text(get_offers_stmt, 2)];
NSString *omschrijving = [[NSString alloc]initWithUTF8String:(const char * )sqlite3_column_text(get_offers_stmt, 3)];
NSString *prijs = [[NSString alloc]initWithUTF8String:(const char * )sqlite3_column_text(get_offers_stmt, 4)];
NSString *referentie = [[NSString alloc]initWithUTF8String:(const char*)sqlite3_column_text(get_offers_stmt, 5)];
NSString *slaapkamer = [[NSString alloc]initWithUTF8String:(const char*)sqlite3_column_text(get_offers_stmt, 6)];
NSString *verdiep = [[NSString alloc]initWithUTF8String:(const char*)sqlite3_column_text(get_offers_stmt, 7)];
NSString *badkamers = [[NSString alloc]initWithUTF8String:(const char*)sqlite3_column_text(get_offers_stmt, 8)];
NSString *woonoppv = [[NSString alloc]initWithUTF8String:(const char*)sqlite3_column_text(get_offers_stmt, 9)];
NSString *perceeloppv = [[NSString alloc]initWithUTF8String:(const char*)sqlite3_column_text(get_offers_stmt, 10)];
NSString *kenmerken = [[NSString alloc]initWithUTF8String:(const char*)sqlite3_column_text(get_offers_stmt, 11)];
NSString *buurtkenmerken = [[NSString alloc]initWithUTF8String:(const char*)sqlite3_column_text(get_offers_stmt, 12)];
NSString *indeling = [[NSString alloc]initWithUTF8String:(const char*)sqlite3_column_text(get_offers_stmt, 13)];
NSString *hypotheek = [[NSString alloc]initWithUTF8String:(const char*)sqlite3_column_text(get_offers_stmt, 14)];
NSString *soort = [[NSString alloc]initWithUTF8String:(const char*)sqlite3_column_text(get_offers_stmt, 15)];
Offer *offer = [[Offer alloc]initWithListing_ID:listing_ID andTitel:titel andOmschrijving:omschrijving andPrijs:prijs andReferentie:referentie andSlaapkamers:slaapkamer andVerdiep:verdiep andBadkamers:badkamers andWoonoppv:woonoppv andPerceeloppv:perceeloppv andKenmerken:kenmerken andBuurtKenmerken:buurtkenmerken andIndeling:indeling andHypotheek:hypotheek andSoort:soort];
[Offers addObject:offer];
}
}
}
return Offers;
}
我不知道可能是什么原因。任何帮助表示赞赏。
乔纳斯