[odb-users] Constructing native queries without a where clause
fails (sqlite)
Feisal Ahmad
feisal.ahmad at ps-tech.com
Mon Mar 17 10:49:58 EDT 2014
Hi Boris,
Thanks, that did the trick.
By the way, the reason I asked about printing the query is that
statement tracing didn't show the final statement as an exception is
thrown already. I found the clause function going through the source
code, but I couldn't find the point where the full query is put together
(specifically I was interested in the list of columns of the SELECT).
Feisal
On 3/14/2014 8:09, Boris Kolpackov wrote:
> 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