From a881873f216c6311118449ee433ac6cfcd7904a6 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 19 Sep 2014 14:43:55 +0200 Subject: Call tracer::prepare() before actually preparing statement This way we give the user the ability to see an invalid statement that would cause the preparation step to fail. --- odb/oracle/statement.cxx | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/odb/oracle/statement.cxx b/odb/oracle/statement.cxx index 5ad867a..4032138 100644 --- a/odb/oracle/statement.cxx +++ b/odb/oracle/statement.cxx @@ -137,7 +137,7 @@ namespace odb statement:: ~statement () { - if (empty ()) + if (stmt_ == 0) return; { @@ -262,6 +262,21 @@ namespace odb if (*text == '\0') return; + { + odb::tracer* t; + if ((t = conn_.transaction_tracer ()) || + (t = conn_.tracer ()) || + (t = conn_.database ().tracer ())) + { + // Temporarily store the statement text in unbind data so that + // text() which may be called by the tracer can access it. + // + udata_ = reinterpret_cast (const_cast (text)); + t->prepare (conn_, *this); + udata_ = 0; + } + } + OCIError* err (conn_.error_handle ()); OCIStmt* handle (0); @@ -279,19 +294,16 @@ namespace odb translate_error (conn_, r); stmt_.reset (handle, OCI_STRLS_CACHE_DELETE, err); - - { - odb::tracer* t; - if ((t = conn_.transaction_tracer ()) || - (t = conn_.tracer ()) || - (t = conn_.database ().tracer ())) - t->prepare (conn_, *this); - } } const char* statement:: text () const { + if (stmt_ == 0) + // See init() above for details on what's going on here. + // + return udata_ != 0 ? reinterpret_cast (udata_) : ""; + OCIError* err (conn_.error_handle ()); OraText* s (0); -- cgit v1.1