gpt4 book ai didi

android - SQLiteQueryBuilder 反向排序顺序

转载 作者:IT王子 更新时间:2023-10-29 06:30:27 25 4
gpt4 key购买 nike

我使用 ContentProvider 和 SQLiteQueryBuilder :

    @Override
public Cursor query(Uri uri, String[] projection, String selection,
String[] selectionArgs, String sortOrder) {

SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
qb.setTables(NEWS_TABLE);

switch(sUriMatcher.match(uri)){
case NEWS_ITEM_ID: qb.appendWhere(KEY_ID+ "=" + uri.getPathSegments().get(1));
break;
default: break;
}

String orderBy;

if (TextUtils.isEmpty(sortOrder)) {
orderBy = KEY_DATE;
} else {
/* ______ WANT TO REVERSE IT HERE _____ */
orderBy = sortOrder;
}
Cursor c = qb.query(newsDB,
projection,
selection, selectionArgs,
null, null,
orderBy);

c.setNotificationUri(getContext().getContentResolver(), uri);

return c;
}

如何使用反向排序顺序进行查询?感谢您的帮助。

最佳答案

SQL 中的

ORDER BY 子句可能具有升序或降序。默认使用升序。要设置反向排序顺序,您需要将 DESC 关键字添加到 ORDER BY 子句的末尾。

if (TextUtils.isEmpty(sortOrder)) {
orderBy = KEY_DATE;
} else {
/* ______ WANT TO REVERSE IT HERE _____ */
orderBy = KEY_DATE + " DESC";
}

关于android - SQLiteQueryBuilder 反向排序顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6242412/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com