I’m using the following method to get data from a table:
Cursor c = ourDatabase.rawQuery("SELECT " + KEY_SWIMMERLAPS + " * "
+ KEY_SPONSOR + " AS result FROM " + DATABASE_TABLE, null);
I was wondering if this can be edited to sort the results by KEY_SWIMMERLAPS. I thought the following would work:
Cursor c = ourDatabase.rawQuery("SELECT " + KEY_SWIMMERLAPS + " * "
+ KEY_SPONSOR + " AS result FROM " + DATABASE_TABLE, KEY_SWIMMERLAPS + " DESC");
However, I get an error because KEY_SWIMMERLAPS is not a string:
The method rawQuery(String, String[]) in the type SQLiteDatabase is not applicable for the arguments (String, String)
You used the second argument on the
rawQuerymethod and expected to be used as an order clause. That is not the case. The second argument is used to provide values for?placeholders in your SQL query string. Using the following should do the trick: