[odb-users] ORDER BY clause in ODB query language

Boris Kolpackov boris at codesynthesis.com
Thu Aug 27 08:14:09 EDT 2015


Hi Markus,

Markus Klemm <markus at markusklemm.net> writes:

> Is there a way to get a query with an ORDER BY clause with the typed
> checked, static, non-native ODB query language? The examples in the
> manual is using the database system-native query language e.g. a
> concatenated string.

Currently you have to spell "ORDER BY" as a string, though the column
can be specified as a C++ name:

db->query<person> ((query::first == "John") + "ORDER BY" + query::age);

We do plan to provide some syntactic sugar for this, though I am not
sure how much static type checking we will be able to do. For example,
should we assume if the C++ type provides operator<, then we can do
ORDER BY?


> That also makes it hard to use the ORDER BY clause because after
> the odb macro for the column, I need to concatenate the DESC/ASC
> clause but can’t due type mismatch.

This should work:

db->query<person> ((...) + "ORDER BY" + query::age + "ASC");

BTW, "the odb macro for the column" is not a macro, it is a proper
C++ variable name.

Boris



More information about the odb-users mailing list