[odb-users] Constructing native queries without a where clause
fails (sqlite)
Boris Kolpackov
boris at codesynthesis.com
Fri Mar 14 09:09:33 EDT 2014
Hi Feisal,
Feisal Ahmad <feisal.ahmad at ps-tech.com> writes:
> sq_query selectAll;
> result r = m_db->query<T>(selectAll + " LIMIT " +
> sq_query::_val(maxResults) + " OFFSET " + sq_query::_val(first));
We are not recognizing LIMIT and OFFSET as special prefixes yet
(on the TODO list though) so what you can do for now is this:
sq_query selectAll (true);
result r = m_db->query<T>(selectAll + " LIMIT " +
sq_query::_val(maxResults) + " OFFSET " + sq_query::_val(first));
You also don't have to add spaces around LIMIT and OFFSET, ODB will
do it for you. So here is how I would write this query:
result r = m_db->query<T>(sq_query(true) +
"LIMIT" + sq_query::_val(maxResults) +
"OFFSET" + sq_query::_val(first));
> Also, any help on converting the constructed query to a string for
> debugging would be very welcome.
You can get the WHERE clause (and the rest) using the clause()
function:
sq_query q (sq_query(true) +
"LIMIT" + sq_query::_val(maxResults) +
"OFFSET" + sq_query::_val(first));
cerr << q.clause () << endl;
If you want to see the whole statement, then statement tracing
is probably the most convenient way:
t.trace (odb::stderr_tracer);
Boris
More information about the odb-users
mailing list