0

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 価格 > 0 AND 価格 < 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;

}

何が原因かわかりません。どんな助けでも大歓迎です。

ジョナス

4

1 に答える 1

0

その理由は、テキストを数値ではなくデータ型として選択し、テキストにスペースがあったため、結果が正常に表示されなかったためです。

于 2013-02-25T17:45:59.270 に答える