diff options
-rw-r--r-- | odb/oracle/connection.cxx | 1 | ||||
-rw-r--r-- | odb/oracle/connection.hxx | 18 | ||||
-rw-r--r-- | odb/oracle/connection.ixx | 30 | ||||
-rw-r--r-- | odb/oracle/database.hxx | 16 | ||||
-rw-r--r-- | odb/oracle/database.ixx | 26 | ||||
-rw-r--r-- | odb/oracle/makefile | 1 | ||||
-rw-r--r-- | odb/oracle/prepared-query.cxx | 16 | ||||
-rw-r--r-- | odb/oracle/prepared-query.hxx | 33 | ||||
-rw-r--r-- | odb/oracle/query.cxx | 19 | ||||
-rw-r--r-- | odb/oracle/query.hxx | 5 | ||||
-rw-r--r-- | odb/oracle/query.ixx | 6 | ||||
-rw-r--r-- | odb/oracle/statement.cxx | 36 | ||||
-rw-r--r-- | odb/oracle/statement.hxx | 43 |
13 files changed, 207 insertions, 43 deletions
diff --git a/odb/oracle/connection.cxx b/odb/oracle/connection.cxx index 1f87443..1194de9 100644 --- a/odb/oracle/connection.cxx +++ b/odb/oracle/connection.cxx @@ -139,6 +139,7 @@ namespace odb { // Deallocate prepared statements before we close the connection. // + prepared_map_.clear (); statement_cache_.reset (); } diff --git a/odb/oracle/connection.hxx b/odb/oracle/connection.hxx index f494a80..38be958 100644 --- a/odb/oracle/connection.hxx +++ b/odb/oracle/connection.hxx @@ -16,6 +16,7 @@ #include <odb/oracle/version.hxx> #include <odb/oracle/forward.hxx> +#include <odb/oracle/query.hxx> #include <odb/oracle/tracer.hxx> #include <odb/oracle/transaction-impl.hxx> #include <odb/oracle/auto-handle.hxx> @@ -60,6 +61,21 @@ namespace odb virtual unsigned long long execute (const char* statement, std::size_t length); + // Query preparation. + // + public: + template <typename T> + prepared_query<T> + prepare_query (const char* name, const char*); + + template <typename T> + prepared_query<T> + prepare_query (const char* name, const std::string&); + + template <typename T> + prepared_query<T> + prepare_query (const char* name, const query<T>&); + // SQL statement tracing. // public: @@ -138,6 +154,8 @@ namespace odb } } +#include <odb/oracle/connection.ixx> + #include <odb/post.hxx> #endif // ODB_ORACLE_CONNECTION_HXX diff --git a/odb/oracle/connection.ixx b/odb/oracle/connection.ixx new file mode 100644 index 0000000..9dcc818 --- /dev/null +++ b/odb/oracle/connection.ixx @@ -0,0 +1,30 @@ +// file : odb/oracle/connection.ixx +// copyright : Copyright (c) 2005-2012 Code Synthesis Tools CC +// license : ODB NCUEL; see accompanying LICENSE file + +namespace odb +{ + namespace oracle + { + template <typename T> + inline prepared_query<T> connection:: + prepare_query (const char* n, const char* q) + { + return prepare_query<T> (n, query<T> (q)); + } + + template <typename T> + inline prepared_query<T> connection:: + prepare_query (const char* n, const std::string& q) + { + return prepare_query<T> (n, query<T> (q)); + } + + template <typename T> + inline prepared_query<T> connection:: + prepare_query (const char* n, const query<T>& q) + { + return query_<T, id_oracle>::call (*this, n, q); + } + } +} diff --git a/odb/oracle/database.hxx b/odb/oracle/database.hxx index da98228..c03ce49 100644 --- a/odb/oracle/database.hxx +++ b/odb/oracle/database.hxx @@ -268,6 +268,22 @@ namespace odb result<T> query (const oracle::query<T>&); + // Query preparation. + // + template <typename T> + prepared_query<T> + prepare_query (const char* name, const char*); + + template <typename T> + prepared_query<T> + prepare_query (const char* name, const std::string&); + + template <typename T> + prepared_query<T> + prepare_query (const char* name, const oracle::query<T>&); + + // Transactions. + // public: virtual transaction_impl* begin (); diff --git a/odb/oracle/database.ixx b/odb/oracle/database.ixx index 6d60d1e..38594a1 100644 --- a/odb/oracle/database.ixx +++ b/odb/oracle/database.ixx @@ -2,6 +2,8 @@ // copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC // license : ODB NCUEL; see accompanying LICENSE file +#include <odb/oracle/transaction.hxx> + namespace odb { namespace oracle @@ -393,5 +395,29 @@ namespace odb // return query_<T, id_oracle>::call (*this, q); } + + template <typename T> + inline prepared_query<T> database:: + prepare_query (const char* n, const char* q) + { + return prepare_query<T> (n, oracle::query<T> (q)); + } + + template <typename T> + inline prepared_query<T> database:: + prepare_query (const char* n, const std::string& q) + { + return prepare_query<T> (n, oracle::query<T> (q)); + } + + template <typename T> + inline prepared_query<T> database:: + prepare_query (const char* n, const oracle::query<T>& q) + { + // Throws if not in transaction. + // + oracle::connection& c (transaction::current ().connection ()); + return c.prepare_query (n, q); + } } } diff --git a/odb/oracle/makefile b/odb/oracle/makefile index f270e17..34fda85 100644 --- a/odb/oracle/makefile +++ b/odb/oracle/makefile @@ -13,6 +13,7 @@ database.cxx \ error.cxx \ exceptions.cxx \ oracle-types.cxx \ +prepared-query.cxx \ query.cxx \ query-const-expr.cxx \ simple-object-statements.cxx \ diff --git a/odb/oracle/prepared-query.cxx b/odb/oracle/prepared-query.cxx new file mode 100644 index 0000000..6237f4a --- /dev/null +++ b/odb/oracle/prepared-query.cxx @@ -0,0 +1,16 @@ +// file : odb/oracle/prepared-query.cxx +// copyright : Copyright (c) 2005-2012 Code Synthesis Tools CC +// license : ODB NCUEL; see accompanying LICENSE file + +#include <odb/oracle/prepared-query.hxx> + +namespace odb +{ + namespace oracle + { + prepared_query_impl:: + ~prepared_query_impl () + { + } + } +} diff --git a/odb/oracle/prepared-query.hxx b/odb/oracle/prepared-query.hxx new file mode 100644 index 0000000..784509c --- /dev/null +++ b/odb/oracle/prepared-query.hxx @@ -0,0 +1,33 @@ +// file : odb/oracle/prepared-query.hxx +// copyright : Copyright (c) 2005-2012 Code Synthesis Tools CC +// license : ODB NCUEL; see accompanying LICENSE file + +#ifndef ODB_ORACLE_PREPARED_QUERY_HXX +#define ODB_ORACLE_PREPARED_QUERY_HXX + +#include <odb/pre.hxx> + +#include <odb/prepared-query.hxx> + +#include <odb/oracle/version.hxx> +#include <odb/oracle/query.hxx> + +#include <odb/oracle/details/export.hxx> + +namespace odb +{ + namespace oracle + { + struct LIBODB_ORACLE_EXPORT prepared_query_impl: odb::prepared_query_impl + { + virtual + ~prepared_query_impl (); + + oracle::query_base query; + }; + } +} + +#include <odb/post.hxx> + +#endif // ODB_ORACLE_PREPARED_QUERY_HXX diff --git a/odb/oracle/query.cxx b/odb/oracle/query.cxx index df6a629..59d8027 100644 --- a/odb/oracle/query.cxx +++ b/odb/oracle/query.cxx @@ -137,19 +137,12 @@ namespace odb p->bind (b); } - binding& query_base:: - parameters_binding () const + void query_base:: + init_parameters () const { - size_t n (parameters_.size ()); - binding& r (binding_); - - if (n == 0) - return r; - bool inc_ver (false); - bind* b (&bind_[0]); - for (size_t i (0); i < n; ++i) + for (size_t i (0); i < parameters_.size (); ++i) { query_param& p (*parameters_[i]); @@ -157,16 +150,14 @@ namespace odb { if (p.init ()) { - p.bind (b + i); + p.bind (&bind_[i]); inc_ver = true; } } } if (inc_ver) - r.version++; - - return r; + binding_.version++; } static bool diff --git a/odb/oracle/query.hxx b/odb/oracle/query.hxx index aaba740..0e753f3 100644 --- a/odb/oracle/query.hxx +++ b/odb/oracle/query.hxx @@ -192,6 +192,11 @@ namespace odb const char* clause_prefix () const; + // Initialize the by-reference parameters from bound variables. + // + void + init_parameters () const; + binding& parameters_binding () const; diff --git a/odb/oracle/query.ixx b/odb/oracle/query.ixx index 75e7bfe..611128c 100644 --- a/odb/oracle/query.ixx +++ b/odb/oracle/query.ixx @@ -6,6 +6,12 @@ namespace odb { namespace oracle { + inline binding& query_base:: + parameters_binding () const + { + return binding_; + } + template <typename T, database_type_id ID> inline void query_base:: append (val_bind<T> v, const char* conv) diff --git a/odb/oracle/statement.cxx b/odb/oracle/statement.cxx index 7eb65c1..ded8d29 100644 --- a/odb/oracle/statement.cxx +++ b/odb/oracle/statement.cxx @@ -192,14 +192,14 @@ namespace odb } statement:: - statement (connection& conn, const string& text) + statement (connection_type& conn, const string& text) : conn_ (conn), udata_ (0), usize_ (0) { init (text.c_str (), text.size ()); } statement:: - statement (connection& conn, const char* text) + statement (connection_type& conn, const char* text) : conn_ (conn), udata_ (0), usize_ (0) { init (text, strlen (text)); @@ -1090,14 +1090,14 @@ namespace odb // generic_statement:: - generic_statement (connection& conn, const string& text) + generic_statement (connection_type& conn, const string& text) : statement (conn, text), bound_ (false) { init (); } generic_statement:: - generic_statement (connection& conn, const char* text) + generic_statement (connection_type& conn, const char* text) : statement (conn, text), bound_ (false) { init (); @@ -1268,7 +1268,7 @@ namespace odb } select_statement:: - select_statement (connection& conn, + select_statement (connection_type& conn, const string& text, binding& param, binding& result, @@ -1285,7 +1285,7 @@ namespace odb } select_statement:: - select_statement (connection& conn, + select_statement (connection_type& conn, const char* text, binding& param, binding& result, @@ -1302,7 +1302,7 @@ namespace odb } select_statement:: - select_statement (connection& conn, + select_statement (connection_type& conn, const string& text, binding& result, size_t lob_prefetch_size) @@ -1317,7 +1317,7 @@ namespace odb } select_statement:: - select_statement (connection& conn, + select_statement (connection_type& conn, const char* text, binding& result, size_t lob_prefetch_size) @@ -1493,7 +1493,7 @@ namespace odb } insert_statement:: - insert_statement (connection& conn, + insert_statement (connection_type& conn, const string& text, binding& param, bool returning) @@ -1503,7 +1503,7 @@ namespace odb } insert_statement:: - insert_statement (connection& conn, + insert_statement (connection_type& conn, const char* text, binding& param, bool returning) @@ -1634,14 +1634,18 @@ namespace odb } update_statement:: - update_statement (connection& conn, const string& text, binding& param) + update_statement (connection_type& conn, + const string& text, + binding& param) : statement (conn, text) { bind_param (param.bind, param.count); } update_statement:: - update_statement (connection& conn, const char* text, binding& param) + update_statement (connection_type& conn, + const char* text, + binding& param) : statement (conn, text) { bind_param (param.bind, param.count); @@ -1700,14 +1704,18 @@ namespace odb } delete_statement:: - delete_statement (connection& conn, const string& text, binding& param) + delete_statement (connection_type& conn, + const string& text, + binding& param) : statement (conn, text) { bind_param (param.bind, param.count); } delete_statement:: - delete_statement (connection& conn, const char* text, binding& param) + delete_statement (connection_type& conn, + const char* text, + binding& param) : statement (conn, text) { bind_param (param.bind, param.count); diff --git a/odb/oracle/statement.hxx b/odb/oracle/statement.hxx index bedddbc..ea08ac0 100644 --- a/odb/oracle/statement.hxx +++ b/odb/oracle/statement.hxx @@ -16,6 +16,7 @@ #include <odb/oracle/version.hxx> #include <odb/oracle/binding.hxx> #include <odb/oracle/forward.hxx> +#include <odb/oracle/connection.hxx> #include <odb/oracle/oracle-fwd.hxx> #include <odb/oracle/auto-handle.hxx> @@ -28,6 +29,8 @@ namespace odb class LIBODB_ORACLE_EXPORT statement: public odb::statement { public: + typedef oracle::connection connection_type; + virtual ~statement () = 0; @@ -40,9 +43,15 @@ namespace odb virtual const char* text () const; + virtual connection_type& + connection () + { + return conn_; + } + protected: - statement (connection&, const std::string& text); - statement (connection&, const char* text); + statement (connection_type&, const std::string& text); + statement (connection_type&, const char* text); private: void @@ -98,7 +107,7 @@ namespace odb void* new_base = 0); protected: - connection& conn_; + connection_type& conn_; auto_handle<OCIStmt> stmt_; unbind* udata_; @@ -111,8 +120,8 @@ namespace odb virtual ~generic_statement (); - generic_statement (connection&, const std::string& text); - generic_statement (connection&, const char* text); + generic_statement (connection_type&, const std::string& text); + generic_statement (connection_type&, const char* text); unsigned long long execute (); @@ -136,24 +145,24 @@ namespace odb virtual ~select_statement (); - select_statement (connection& conn, + select_statement (connection_type& conn, const std::string& text, binding& param, binding& result, std::size_t lob_prefetch_size = 0); - select_statement (connection& conn, + select_statement (connection_type& conn, const char* text, binding& param, binding& result, std::size_t lob_prefetch_size = 0); - select_statement (connection& conn, + select_statement (connection_type& conn, const std::string& text, binding& result, std::size_t lob_prefetch_size = 0); - select_statement (connection& conn, + select_statement (connection_type& conn, const char* text, binding& result, std::size_t lob_prefetch_size = 0); @@ -212,12 +221,12 @@ namespace odb virtual ~insert_statement (); - insert_statement (connection& conn, + insert_statement (connection_type& conn, const std::string& text, binding& param, bool returning); - insert_statement (connection& conn, + insert_statement (connection_type& conn, const char* text, binding& param, bool returning); @@ -272,11 +281,13 @@ namespace odb virtual ~update_statement (); - update_statement (connection& conn, + update_statement (connection_type& conn, const std::string& text, binding& param); - update_statement (connection& conn, const char* text, binding& param); + update_statement (connection_type& conn, + const char* text, + binding& param); unsigned long long execute (); @@ -292,11 +303,13 @@ namespace odb virtual ~delete_statement (); - delete_statement (connection& conn, + delete_statement (connection_type& conn, const std::string& text, binding& param); - delete_statement (connection& conn, const char* text, binding& param); + delete_statement (connection_type& conn, + const char* text, + binding& param); unsigned long long execute (); |