Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

data type mismatch error when using ORDER BY

Tags:

android

sqlite

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?

like image 575
Bee Avatar asked May 04 '09 03:05

Bee


People also ask

How do I fix data type mismatch?

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.

What is data type mismatch in criteria expression?

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.

What is type mismatch error in VBA?

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.

What is type mismatch in programming?

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.


2 Answers

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) 
like image 106
outis Avatar answered Oct 03 '22 02:10

outis


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); 
like image 44
Sandip Jadhav Avatar answered Oct 03 '22 01:10

Sandip Jadhav