I make the following query in SQLitemanager (SQL DB App for Android):
SELECT * FROM fahrer, fahrzeuge, nutzungsarten, fahrtenbuch WHERE fahrtenbuch.nutzungsart_id = nutzungsarten._id AND fahrtenbuch.fahrzeuge_id = fahrzeuge._id AND fahrtenbuch.fahrer_id = fahrer._id ORDER BY SUBSTR(fahrtenbuch.startdatum,7,4), SUBSTR(fahrtenbuch.startdatum,4,2), SUBSTR(fahrtenbuch.startdatum,1,2) ASC
The returned order is as expected. The date is correctly sorted by dd.mm.yyyy.
But when I execute the query in my DB-Helper class, the order is not the same.
In the DB-Helper class:
final String MY_QUERY = "SELECT * FROM fahrer, fahrzeuge, nutzungsarten, fahrtenbuch WHERE fahrtenbuch.nutzungsart_id = nutzungsarten._id AND fahrtenbuch.fahrzeuge_id = fahrzeuge._id AND fahrtenbuch.fahrer_id = fahrer._id ORDER BY SUBSTR(fahrtenbuch.startdatum,7,4), SUBSTR(fahrtenbuch.startdatum,4,2), SUBSTR(fahrtenbuch.startdatum,1,2) ASC";
return mDb.rawQuery(MY_QUERY, null);
In my activity:
Cursor curCSV = mDbHelper.fetchAllFahrtenbuchASC();
curCSV.moveToFirst();
while(curCSV.moveToNext())
{
System.out.println("Date of entry: " +curCSV.getString(18));
}
curCSV.close();
Does anyone know why this is not working?
This code:
skips over the first record.
Use instead: