[odb-users] Order, Group by and Where in a view simultaneously
Markus Klemm
markus at markusklemm.net
Tue Sep 15 05:23:26 EDT 2015
In addition to Bruce Cresantas old question, I've got a question e.g. feature request: I know how to use a view for aggregate functions, and everything works, except when I also want to order that results and at the same moment have a where clause too. Because AFAIK I have to choose where to set the (?) placeholder in the views query pragma. Either I place it before the group-by clause for a where clause or behind for the order-by clause. Either way one gets a syntax expcetion from the server.
Because I think that could be a nontrivial problem for ODB because of the SQL syntax ordering; I guess this is rather a feature request.
It's not a big deal because I can use a compile-time static order-by clause in the view, but as many details, it's nice to have.
Or is there something I missed in the manual?
Example:
#pragma db view object(measurement) object(order) query((?) + "GROUP BY" + order::order_number)
class measurement_view{
public:
int32_t order_number;
#pragma db column("count(" + measurement::measurement_id + ")")
std::size_t count;
};
}
void get(std::unique_ptr<odb::database> db){
odb::session s;
odb::transaction t(db->begin());
t.tracer(odb::stderr_tracer);
typedef odb::query<measurement_view> query_t;
query_t query(query_t::measurement::tests_passed == false);
query += query_t("ORDER BY" + odb::query<measurement_view>::order::order_number + "DESC");
odb::result<measurement_view> result(db->query<measurement_view>(query));
}
Regards
Markus Klemm
More information about the odb-users
mailing list