문제
로컬 SQLITE 데이터베이스를 사용하는 Android 앱이 있습니다.
private SQLiteDatabase mDb;
이 쿼리를 실행하면 원하는대로 ID와 동일한 PID를 가진 행 커서를 얻습니다.
mDb.query(true, PT_TABLE, new String[] {KEY_PID, KEY_TID},
KEY_PID+" = "+id, null, null, null, null, null);
다음 쿼리를 실행하면 PID I GET가 주문한 동일한 결과 세트를 얻기 위해 "Android.database.sqlite.sqliteexception : 데이터 유형 불일치"
mDb.query(true, PT_TABLE, new String[] {KEY_PID, KEY_TID},
KEY_PID+" = "+id, null, null, null, null, KEY_PID+" DESC");
어떤 아이디어?
해결책
당신이 조금 섞인 것 같습니다. 에 따르면 SQLiteDatabase.query
문서화, 마지막 인수는입니다 LIMIT
절. 두 번째는 마지막입니다 ORDER BY
절.
Cursor query (boolean distinct,
String table,
String[] columns,
String selection,
String[] selectionArgs,
String groupBy,
String having,
String orderBy, // <-- ORDER BY
String limit)
편집하다
그러나 다른 것도 있습니다 SQLiteDatabase.query
어디 ORDER BY
마지막이 될 것입니다
Cursor query (String table,
String[] columns,
String selection,
String[] selectionArgs,
String groupBy,
String having,
String orderBy)
다른 팁
이것은 나를 위해 효과가있었습니다
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);
KEY_PID + " = " + "'" + id + "'"
Orderby는 쿼리의 두 번째 마지막 매개 변수이기 때문에; 귀하의 질문은 다음과 같습니다
mDb.query(true, PT_TABLE, new String[] {KEY_PID, KEY_TID},
KEY_PID+" = "+id, null, null, null, KEY_PID+" DESC", null);
내가 당신의 문제를 정확하게 이해한다면, 이것을 시도하십시오.
String[] columns = new String[] {KEY_PID, KEY_TID};
String where = KEY_PID + " = " + Integer.toString(id);
String orderBy = KEY_PID + " DESC";
Cursor cursor = mDb.query(PT_TABLE, columns, where, null, null, null, orderBy);
제휴하지 않습니다 StackOverflow