From 0e37272b9ab8f37ad2f3d37bf6a09c68e5117d02 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 7 Nov 2011 15:00:06 +0200 Subject: Add support for SQL statement tracing --- odb/pgsql/statement.cxx | 61 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 2 deletions(-) (limited to 'odb/pgsql/statement.cxx') diff --git a/odb/pgsql/statement.cxx b/odb/pgsql/statement.cxx index 049a00d..8a20456 100644 --- a/odb/pgsql/statement.cxx +++ b/odb/pgsql/statement.cxx @@ -9,6 +9,8 @@ #include +#include + #include #include #include @@ -68,6 +70,14 @@ namespace odb if (deallocated_) return; + { + odb::tracer* t; + if ((t = conn_.transaction_tracer ()) || + (t = conn_.tracer ()) || + (t = conn_.database ().tracer ())) + t->deallocate (conn_, *this); + } + string s ("deallocate \""); s += name_; s += "\""; @@ -79,17 +89,26 @@ namespace odb statement:: statement (connection& conn, const string& name, - const string& stmt, + const string& text, const Oid* types, size_t types_count) : conn_ (conn), name_ (name), + text_ (text), deallocated_ (false) { + { + odb::tracer* t; + if ((t = conn_.transaction_tracer ()) || + (t = conn_.tracer ()) || + (t = conn_.database ().tracer ())) + t->prepare (conn_, *this); + } + auto_handle h ( PQprepare (conn_.handle (), name_.c_str (), - stmt.c_str (), + text_.c_str (), static_cast (types_count), types)); @@ -102,6 +121,12 @@ namespace odb // } + const char* statement:: + text () const + { + return text_.c_str (); + } + void statement:: bind_param (native_binding& n, const binding& b) { @@ -384,6 +409,14 @@ namespace odb if (param_ != 0) bind_param (*native_param_, *param_); + { + odb::tracer* t; + if ((t = conn_.transaction_tracer ()) || + (t = conn_.tracer ()) || + (t = conn_.database ().tracer ())) + t->execute (conn_, *this); + } + bool in (native_param_ != 0); handle_.reset ( @@ -478,6 +511,14 @@ namespace odb { bind_param (native_param_, param_); + { + odb::tracer* t; + if ((t = conn_.transaction_tracer ()) || + (t = conn_.tracer ()) || + (t = conn_.database ().tracer ())) + t->execute (conn_, *this); + } + auto_handle h ( PQexecPrepared (conn_.handle (), name_.c_str (), @@ -570,6 +611,14 @@ namespace odb { bind_param (native_param_, param_); + { + odb::tracer* t; + if ((t = conn_.transaction_tracer ()) || + (t = conn_.tracer ()) || + (t = conn_.database ().tracer ())) + t->execute (conn_, *this); + } + auto_handle h ( PQexecPrepared (conn_.handle (), name_.c_str (), @@ -627,6 +676,14 @@ namespace odb if (param_ != 0) bind_param (native_param_, *param_); + { + odb::tracer* t; + if ((t = conn_.transaction_tracer ()) || + (t = conn_.tracer ()) || + (t = conn_.database ().tracer ())) + t->execute (conn_, *this); + } + auto_handle h ( PQexecPrepared (conn_.handle (), name_.c_str (), -- cgit v1.1