[odb-users] Print SQL statement before they are sent to server

Quentin Deldycke quentindeldycke at gmail.com
Mon Sep 15 10:47:07 EDT 2014


Boris,

I implemented this class. But it sill fails without any error...
If i modify my request to remove most of my 'WHERE' i can see the different
queries.
But it still doesn't print when the execution fails!

Yes, i think it is best to print at both moments.

--
Deldycke Quentin


On 15 September 2014 16:21, Boris Kolpackov <boris at codesynthesis.com> wrote:

> 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