0


LongAとLongBの間のすべての行を返すこのコードがあります

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 に答える