[odb-users] Print SQL statement before they are sent to server
Boris Kolpackov
boris at codesynthesis.com
Mon Sep 15 10:21:16 EDT 2014
Hi Quentin,
Quentin Deldycke <quentindeldycke at gmail.com> writes:
> I have a problem with a request where it fails with error: 1054.
> My request is quite complicated. And i would like to have a trace
> before it is sent to the server. Is this possible? I have enabled trace
> as in chapter 3.13. but it is not shown!
The reason it is not printed is because the error is probably detected
during preparation, not execution. And the default stderr_tracer only
traces statement executions.
So what you can do is create your own tracer that prints the statements
being prepared. Something along these lines:
#include <odb/tracer.hxx>
struct diag_tracer: odb::tracer
{
virtual void
prepare (odb::connection&, const odb::statement& s)
{
cerr << "PREPARE " << s.text () << endl;
}
virtual void
execute (odb::connection&, const char* statement)
{
cerr << statement << endl;
}
};
I've also added an entry to our TODO to support this with stderr_tracer
somehow since this is probably a fairly common scenario.
Boris
More information about the odb-users
mailing list