问题描述
我想不区分大小写从ORMLite DAO情况下,命令我的数据对象。
I want to order my data objects from an ORMLite DAO case insensitively.
目前我使用下面的sqlite的code灵敏为了我的主人项目情况:
Currently I am using the following sqlite code to order my owner items case sensitively:
ownerDao.queryBuilder().orderBy("Name", true).query();
我看here这sqlite的按订单支持不区分大小写具有以下原始SQL:
I see here that sqlite supports case insensitive "order by" with the following raw SQL:
SELECT * FROM owner ORDER BY Name COLLATE NOCASE
任何简单的方法(更容易比调用 queryRaw()
)添加所需的后缀?
可能的替代解决方案是设置上的以 TEXT COLLATE NOCASE
Could an alternative solution be to set the columnDefinition
property on the DatabaseField annotation to TEXT COLLATE NOCASE
?
推荐答案
我想你想要的是使用。它看起来是这样的:
I think what you want is to use the QueryBuilder.orderByRaw(String)
method. It would look something like:
ownerDao.queryBuilder().orderByRaw("Name COLLATE NOCASE").query();
注意原始字符串做的不的包含 ORDER BY
字符串的一部分。引述javadocs:
Notice the raw string does not contain the ORDER BY
part of the string. To quote the javadocs:
按订单的条款添加原始SQL的SQL查询语句。这不应该包括ORDER BY。
的 TEXT COLLATE NOCASE
columnDefinition
可能的工作,虽然我没有使用,在所有的经验。
The TEXT COLLATE NOCASE
columnDefinition
might work although I don't have any experience with using that at all.
另外,我的不的使用的OrderBy(姓名COLLATE NOCASE,真)
答案,因为通常的试图逃跑列名和引号是放错了地方。
Also, I would not use the orderBy("Name COLLATE NOCASE", true)
answer since typically ORMLite tries to escape the column names and the quotes would be in the wrong place.
这篇关于不区分大小写为了通过与Android的ormlite和SQLite的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!