如何根据时间来排序光标 [英] How to sort a cursor based on a time string
问题描述
我的问题,如果很简单,我有code的这一部分。
My question if fairly simple, I have this segment of code
Cursor mCursor = this.getContentResolver().query(
PlayerContentProviderDB.CONTENT_URI, fulldataColumns, null, null,
Players.SCORE +" ASC");
这code,从一切我所看到的,应以升序排列光标基于Players.SCORE,但事实并非如此。
This code, from everything I've seen, should be sorting the cursor in ascending order based on Players.SCORE but it is not.
有关参考Players.SCORE总是会在格式结果字符串
MM:SS:msmsms(读分钟:秒:毫秒)。
For reference Players.SCORE will always be a string in the format
mm:ss:msmsms ( read minute:second:millisecond).
另外这里是code在我的ContentProvider查询方法
Also here is the code for the query method in my ContentProvider
public Cursor query(Uri uri, String[] projection, String selection,
String[] selectionArgs, String sortOrder) {
SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();
checkColumns(projection);
queryBuilder.setTables(PlayerContract.Players.PLAYERS_TABLE_NAME);
int uriType = sURIMatcher.match(uri);
switch (uriType) {
case ALL_SCORES:
break;
case SCORE_ID:
queryBuilder.appendWhere(PlayerContract.Players.ID + "="
+ uri.getLastPathSegment());
break;
default:
throw new IllegalArgumentException("Unknown URI: " + uri);
}
SQLiteDatabase db = this.dbHelper.getReadableDatabase();
Cursor cursor = queryBuilder.query(db, projection, selection,
selectionArgs, null, null, sortOrder);
// Notify potential listeners
cursor.setNotificationUri(getContext().getContentResolver(), uri);
return cursor;
我的问题是,为什么这剂code没有工作,我该如何解决?
My question is why dose this code not work and how can I fix it?
(这个code另一个有趣的现象是,我也试图限制语句添加到排序,我已经读了作品的结尾,但是我的是不是)
(Another interesting note about this code is that I am also trying to add a limit statement to the end of the sort, which I have read works, however mine is not)
推荐答案
我终于找到了这个问题的答案。事实证明我的code是正确的,但出于某种原因,我仍然对我的工作ContentProvider.query()被调用两次。一旦与正确的参数并再次用不正确的参数。(即:中将sortOrder == NULL)
I finally found the answer to this question. As it turns out my code was correct, however for some reason that I am still working on my ContentProvider.query() was being called twice. Once with the correct parameters and again with incorrect parameters.(i.e: sortOrder == null).
另外请注意,您可以按数字顺序为SQL不同排序整数和字符串不排序的一串数字
Also note that you can not sort a string of numbers in numerical order as sql sorts ints and strings differently
这篇关于如何根据时间来排序光标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!