0


我有这段代码可以返回 Long A 和 Long B 之间的所有行

public ArrayList<CashGame> getAllCashGamesByDates(Long startdate, Long enddate) {
    ArrayList<CashGame> cashgameList = new ArrayList<CashGame>();

    SQLiteDatabase db = this.getWritableDatabase();
    Cursor cursor= db.query(TABLE_CASHGAMES, new String[] { KEY_ID,
            KEY_NAME, KEY_BUYIN, KEY_RESULT, KEY_START, KEY_END, KEY_LOCATION },      startdate + ">=? AND " + enddate + " <?",
            new String[]{startdate.toString(), enddate.toString()} , null, null, null);

    // looping through all rows and adding to list
    if (cursor.moveToFirst()) {
        do {
            CashGame cashgame = new CashGame();
            cashgame.setId(Integer.parseInt(cursor.getString(0)));
            cashgame.setName(cursor.getString(1));
            cashgame.setBuyin(cursor.getDouble(2));
            cashgame.setResult(cursor.getDouble(3));
            cashgame.setStartDate(date = new Date(cursor.getLong(4)));
            cashgame.setEndDate(date = new Date(cursor.getLong(5)));
            cashgame.setLocation(cursor.getString(6));
            // Adding contact to list
            cashgameList.add(cashgame);
        } while (cursor.moveToNext());
    }

    db.close();
    // return contact list
    return cashgameList;
}

我想查询有问题,但我没有发现我犯的错误。希望有人看到!

4

1 回答 1

1

我会假设:

... startdate + ">=? AND " + enddate + " <?" ...

应该更多:

... "startdate>=? AND enddate<?" ...

编辑:

不知道如何理解你的 where 子句,但也许你的意思是:

... "startdate<=? AND enddate>?" ...

另一个编辑:

为什么不直接调用cursor.moveToNext()

 while (cursor.moveToNext()) {
     ...
 }
于 2012-04-24T13:42:38.270 回答