I have an SQLite database with 4 columns. I inserted a date/time values in COLUMN_DATE as milliseconds with the "System.currentTimeMillis()" method and I want to query the SQLite database to get all rows between 2 specific dates also represented as milliseconds. This query must include rows with these 2 specific dates too.
Here is my SQLite database:
public static final String CREATE_SQL = "create table " + TABLE_NAME + "(" + COLUMN_ID + " integer primary key autoincrement, " +
COLUMN_DATE + " integer not null, " + COLUMN_STATUS + " text not null, " + COLUMN_TOTAL + " text not null);";
And here is the database with inserted values:
I want to query the SQLite database by 1578530800000 (ID=2) as a start date and 1578698202000 (ID=5) as an end date and get all rows between those specific dates including those dates itself. Means I want table marked with a red rectangle as a result.
I tried to query the database but never got what I expected. Here is my query example:
String[] projection = {Wdatabase.COLUMN_ID, Wdatabase.COLUMN_DATE, Wdatabase.COLUMN_STATUS, Wdatabase.COLUMN_TOTAL};
String selection = Wdatabase.COLUMN_DATE + " >= " + startDate + " AND " + Wdatabase.COLUMN_DATE +" <= " + endDate;
Cursor r = Objects.requireNonNull(getActivity()).getContentResolver().query(DbProvider.CONTENT_URI, projection, selection, null, null, null);
Can anyone explain to me what is wrong here?
Here is my cursor with logs:
while (r.moveToNext()) {
Log.i("Arguments", "CursorId: " + r.getInt(0));
Log.i("Arguments", "CursorDate: " + r.getLong(1));
Log.i("Arguments", "CursorStatus: " + r.getString(2));
Log.i("Arguments", "CursorTotal: " + r.getString(3));
}