我有这段代码返回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;
}
我猜这个查询有问题,但我没有发现我犯的错误。 希望有人看到它!
答案 0 :(得分:1)
我认为这是:
... startdate + ">=? AND " + enddate + " <?" ...
应该更多:
... "startdate>=? AND enddate<?" ...
修改强>
不确定如何理解你的where子句,但也许你的意思是:
... "startdate<=? AND enddate>?" ...
另一个编辑:
为什么不调用cursor.moveToNext()
:
while (cursor.moveToNext()) {
...
}