ORMLite mixing orderBy() and orderByRaw()

I want to query a list of items from my database using ORMLite. The ordering must be a bit field, then the nullability of a field, then a date field. Here is what I have at the moment:

 QueryBuilder<Task, Integer> queryBuilder = mTaskDao.queryBuilder();
        queryBuilder
        .orderBy("done", true)
        .orderByRaw("visit_id is null desc")
        .orderBy("duedate", true);

When I call getStatement() on the above query however, it returns the following SQL:

SELECT * FROM `task` ORDER BY visit_id is null

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.

Ideally it should have generated the orderBy and orderByRaw in correct order.

Only workaround I can think of for now is to set all my order by clauses in the orderByRaw() method.

Answers


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.

Yeah. This looks to be a limitation of ORMLite right now. It seems like it either handles the raw or the non. See this code here around like 757.

https://github.com/j256/ormlite-core/blob/e11db21da474e9e0d4004cd83fa9f71c3d4e66e3/src/main/java/com/j256/ormlite/stmt/QueryBuilder.java#L757

This is not documented at all that they are mutually exclusive and I can see no reason why they should be. I've added this bug:

https://sourceforge.net/p/ormlite/bugs/161/

A fix for it has been checked into trunk and was released on 12/16/2013 in version 4.48.

https://github.com/j256/ormlite-core/commit/36492cebc1506b0b75f3a6f72569ec25de776aec


Need Your Help

Implementing fixed position in javascript causes jitter in Safari when scrolling

javascript jquery safari scroll

Fixed position does not work for my use case because it is fixed to the browser window and you can get in a state where the text is off your screen to the right and you can not get to it. Anyways, ...

Custom UIAlertView with Custom Buttons

iphone objective-c ios ios4 uialertview

I need to show a Custom UIAlertView which is going to have an image as a background and two Custom Buttons which will be not the regular UIAlertView Buttons. These buttons will be customized as wel...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.