I've got an android app using a local sqlite database.
private SQLiteDatabase mDb;
when I run this query I get my Cursor over rows with pid equal to id, as desired:
mDb.query(true, PT_TABLE, new String[] {KEY_PID, KEY_TID}, KEY_PID+" = "+id, null, null, null, null, null);
when I run the following query, aiming to get that same result set, ordered by pid I get "android.database.sqlite.SQLiteException: datatype mismatch"
mDb.query(true, PT_TABLE, new String[] {KEY_PID, KEY_TID}, KEY_PID+" = "+id, null, null, null, null, KEY_PID+" DESC");
Any ideas?
Verify that the data type of each pair of joined fields in the query is the same. If not, change the data type of one of the joined fields to match the data type of the other so you don't get the mismatch error.
The “Type mismatch in expression” message comes up occasionally when you try to create a new Access query or run a query that you have just changed. It means that the fields that you use in one of your links connecting your tables are of different types.
A VBA Type Mismatch Error occurs when you try to assign a value between two different variable types. The error appears as “run-time error 13 – Type mismatch”. For example, if you try to place text in a Long integer variable or you try to place text in a Date variable.
Sometimes, while writing code, programmers may ask that a value be stored in a variable that is not typed correctly, such as putting a number with fractions into a variable that is expecting only an integer. In such circumstances, the result is a type-mismatch error.
It looks like you got just a little mixed up. According to the SQLiteDatabase.query
documentation, the last argument is the LIMIT
clause. The second to last is the ORDER BY
clause.
Cursor query (boolean distinct, String table, String[] columns, String selection, String[] selectionArgs, String groupBy, String having, String orderBy, // <-- ORDER BY String limit)
EDIT
But, there is also another SQLiteDatabase.query
where ORDER BY
would be last
Cursor query (String table, String[] columns, String selection, String[] selectionArgs, String groupBy, String having, String orderBy)
This worked for me
String filter = MySQLiteHelper.JOB_ID + "=" + Integer.toString(jobID); String orderBy = MySQLiteHelper.LOG_TIME + " DESC"; Cursor cursor = database.query(MySQLiteHelper.LOG_TABLE_NAME, logTableColumns, filter, null, null, null, orderBy);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With