我试图从我的SQLite数据库中检索Fixtures列表。日期存储为字符串,如" 2017-03-01 10:00:00"。以下是在日期范围内查找灯具的代码:
public static ArrayList<Fixture> getSavedFixtures(Context context, String date) {
UltraDbHelper mDbHelper = new UltraDbHelper(context);
SQLiteDatabase db = mDbHelper.getReadableDatabase();
ArrayList<Fixture> fixtures = new ArrayList<>();
String query = "SELECT * FROM " + FixtureEntry.TABLE_NAME + " WHERE " + FixtureEntry.COLUMN_FIXTURE_DATE + " BETWEEN '2017-03-01 00:00:00' AND '2017-04-10 23:00:59'";
Cursor cursor = db.rawQuery(query, null);
int idColumnIndex = cursor.getColumnIndex(FixtureEntry.COLUMN_FIXTURE_ID);
int dateColumnIndex = cursor.getColumnIndex(FixtureEntry.COLUMN_FIXTURE_DATE);
int statusColumnIndex = cursor.getColumnIndex(FixtureEntry.COLUMN_FIXTURE_STATUS);
int homeTeamColumnIndex = cursor.getColumnIndex(FixtureEntry.COLUMN_FIXTURE_HOME_TEAM);
int awayTeamColumnIndex = cursor.getColumnIndex(FixtureEntry.COLUMN_FIXTURE_AWAY_TEAM);
int homeGoalsColumnIndex = cursor.getColumnIndex(FixtureEntry.COLUMN_FIXTURE_BOME_GOALS);
int awayGoalsColumnIndex = cursor.getColumnIndex(FixtureEntry.COLUMN_FIXTURE_AWAY_GOALS);
int competitionColumnIndex = cursor.getColumnIndex(FixtureEntry.COLUMN_FIXTURE_COMPETITION);
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
Fixture item = new Fixture();
item.setFixtureId(cursor.getString(idColumnIndex));
item.setDate(cursor.getString(dateColumnIndex));
item.setStatus(cursor.getString(statusColumnIndex));
item.setHomeTeam(cursor.getString(homeTeamColumnIndex));
item.setAwayTeam(cursor.getString(awayTeamColumnIndex));
item.setHomeGoals(cursor.getString(homeGoalsColumnIndex));
item.setAwayGoals(cursor.getString(awayGoalsColumnIndex));
item.setCompetition(cursor.getString(competitionColumnIndex));
fixtures.add(item);
cursor.moveToNext();
}
cursor.close();
db.close();
return fixtures;
}
但它会返回0个灯具。任何想法如何解决这个问题?