我想使用 ORMLite 从我的数据库中查询项目列表。排序必须是一个位字段,然后是一个字段的可空性,然后是一个日期字段。这是我目前拥有的:
QueryBuilder<Task, Integer> queryBuilder = mTaskDao.queryBuilder();
queryBuilder
.orderBy("done", true)
.orderByRaw("visit_id is null desc")
.orderBy("duedate", true);
然而,当我对上述查询调用 getStatement()
时,它返回以下 SQL:
SELECT * FROM `task` ORDER BY visit_id is null
请注意,只有 orderByRaw 对 QueryBuilder 有影响。阅读 QueryBuilder code我看到方法 appendOrderBys
忽略非 RawOrderBy 语句,如果 orderByRaw 不为空的话。
理想情况下,它应该以正确的顺序生成 orderBy 和 orderByRaw。
目前我能想到的唯一解决方法是在 orderByRaw()
方法中设置我所有的 order by 子句。
最佳答案
Notice only orderByRaw had an effect on the QueryBuilder. Reading the QueryBuilder code I see method appendOrderBys ignores non RawOrderBy statements, if orderByRaw is non null.
是的。这看起来是 ORMLite 的限制现在。看起来它要么处理原始的要么处理非。在此处查看此代码,例如 757。
这根本没有记录它们是相互排斥的,我看不出为什么它们应该是。我添加了这个错误:
它的修复已 checkin 主干并于 2013 年 12 月 16 日在版本 4.48 中发布。
https://github.com/j256/ormlite-core/commit/36492cebc1506b0b75f3a6f72569ec25de776aec
关于java - ORMLite 混合 orderBy() 和 orderByRaw(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20468962/