aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--odb/mssql/connection.cxx1
-rw-r--r--odb/mssql/connection.hxx18
-rw-r--r--odb/mssql/connection.ixx30
-rw-r--r--odb/mssql/database.hxx16
-rw-r--r--odb/mssql/database.ixx26
-rw-r--r--odb/mssql/makefile1
-rw-r--r--odb/mssql/prepared-query.cxx16
-rw-r--r--odb/mssql/prepared-query.hxx33
-rw-r--r--odb/mssql/query.cxx19
-rw-r--r--odb/mssql/query.hxx5
-rw-r--r--odb/mssql/query.ixx6
-rw-r--r--odb/mssql/statement.cxx24
-rw-r--r--odb/mssql/statement.hxx35
13 files changed, 191 insertions, 39 deletions
diff --git a/odb/mssql/connection.cxx b/odb/mssql/connection.cxx
index 3e750d5..808d560 100644
--- a/odb/mssql/connection.cxx
+++ b/odb/mssql/connection.cxx
@@ -103,6 +103,7 @@ namespace odb
{
// Deallocate prepared statements before we close the connection.
//
+ prepared_map_.clear ();
statement_cache_.reset ();
direct_stmt_.reset ();
diff --git a/odb/mssql/connection.hxx b/odb/mssql/connection.hxx
index 10cc4fc..2744f4f 100644
--- a/odb/mssql/connection.hxx
+++ b/odb/mssql/connection.hxx
@@ -17,6 +17,7 @@
#include <odb/mssql/mssql-fwd.hxx>
#include <odb/mssql/version.hxx>
#include <odb/mssql/forward.hxx>
+#include <odb/mssql/query.hxx>
#include <odb/mssql/tracer.hxx>
#include <odb/mssql/transaction-impl.hxx>
#include <odb/mssql/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:
@@ -135,6 +151,8 @@ namespace odb
}
}
+#include <odb/mssql/connection.ixx>
+
#include <odb/post.hxx>
#endif // ODB_MSSQL_CONNECTION_HXX
diff --git a/odb/mssql/connection.ixx b/odb/mssql/connection.ixx
new file mode 100644
index 0000000..c4c13a8
--- /dev/null
+++ b/odb/mssql/connection.ixx
@@ -0,0 +1,30 @@
+// file : odb/mssql/connection.ixx
+// copyright : Copyright (c) 2005-2012 Code Synthesis Tools CC
+// license : ODB NCUEL; see accompanying LICENSE file
+
+namespace odb
+{
+ namespace mssql
+ {
+ 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_mssql>::call (*this, n, q);
+ }
+ }
+}
diff --git a/odb/mssql/database.hxx b/odb/mssql/database.hxx
index 1bd419b..b64eccc 100644
--- a/odb/mssql/database.hxx
+++ b/odb/mssql/database.hxx
@@ -311,6 +311,22 @@ namespace odb
result<T>
query (const mssql::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 mssql::query<T>&);
+
+ // Transactions.
+ //
public:
virtual transaction_impl*
begin ();
diff --git a/odb/mssql/database.ixx b/odb/mssql/database.ixx
index d73332e..44ffe00 100644
--- a/odb/mssql/database.ixx
+++ b/odb/mssql/database.ixx
@@ -2,6 +2,8 @@
// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC
// license : ODB NCUEL; see accompanying LICENSE file
+#include <odb/mssql/transaction.hxx>
+
namespace odb
{
namespace mssql
@@ -393,5 +395,29 @@ namespace odb
//
return query_<T, id_mssql>::call (*this, q);
}
+
+ template <typename T>
+ inline prepared_query<T> database::
+ prepare_query (const char* n, const char* q)
+ {
+ return prepare_query<T> (n, mssql::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, mssql::query<T> (q));
+ }
+
+ template <typename T>
+ inline prepared_query<T> database::
+ prepare_query (const char* n, const mssql::query<T>& q)
+ {
+ // Throws if not in transaction.
+ //
+ mssql::connection& c (transaction::current ().connection ());
+ return c.prepare_query (n, q);
+ }
}
}
diff --git a/odb/mssql/makefile b/odb/mssql/makefile
index 51a9a62..fb87738 100644
--- a/odb/mssql/makefile
+++ b/odb/mssql/makefile
@@ -11,6 +11,7 @@ connection-factory.cxx \
database.cxx \
error.cxx \
exceptions.cxx \
+prepared-query.cxx \
query.cxx \
query-const-expr.cxx \
simple-object-statements.cxx \
diff --git a/odb/mssql/prepared-query.cxx b/odb/mssql/prepared-query.cxx
new file mode 100644
index 0000000..b54ea5b
--- /dev/null
+++ b/odb/mssql/prepared-query.cxx
@@ -0,0 +1,16 @@
+// file : odb/mssql/prepared-query.cxx
+// copyright : Copyright (c) 2005-2012 Code Synthesis Tools CC
+// license : ODB NCUEL; see accompanying LICENSE file
+
+#include <odb/mssql/prepared-query.hxx>
+
+namespace odb
+{
+ namespace mssql
+ {
+ prepared_query_impl::
+ ~prepared_query_impl ()
+ {
+ }
+ }
+}
diff --git a/odb/mssql/prepared-query.hxx b/odb/mssql/prepared-query.hxx
new file mode 100644
index 0000000..35a4774
--- /dev/null
+++ b/odb/mssql/prepared-query.hxx
@@ -0,0 +1,33 @@
+// file : odb/mssql/prepared-query.hxx
+// copyright : Copyright (c) 2005-2012 Code Synthesis Tools CC
+// license : ODB NCUEL; see accompanying LICENSE file
+
+#ifndef ODB_MSSQL_PREPARED_QUERY_HXX
+#define ODB_MSSQL_PREPARED_QUERY_HXX
+
+#include <odb/pre.hxx>
+
+#include <odb/prepared-query.hxx>
+
+#include <odb/mssql/version.hxx>
+#include <odb/mssql/query.hxx>
+
+#include <odb/mssql/details/export.hxx>
+
+namespace odb
+{
+ namespace mssql
+ {
+ struct LIBODB_MSSQL_EXPORT prepared_query_impl: odb::prepared_query_impl
+ {
+ virtual
+ ~prepared_query_impl ();
+
+ mssql::query_base query;
+ };
+ }
+}
+
+#include <odb/post.hxx>
+
+#endif // ODB_MSSQL_PREPARED_QUERY_HXX
diff --git a/odb/mssql/query.cxx b/odb/mssql/query.cxx
index a0371c7..a40bb23 100644
--- a/odb/mssql/query.cxx
+++ b/odb/mssql/query.cxx
@@ -136,19 +136,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]);
@@ -156,16 +149,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/mssql/query.hxx b/odb/mssql/query.hxx
index 08e3319..8b470b4 100644
--- a/odb/mssql/query.hxx
+++ b/odb/mssql/query.hxx
@@ -193,6 +193,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/mssql/query.ixx b/odb/mssql/query.ixx
index 18b856c..8683aa0 100644
--- a/odb/mssql/query.ixx
+++ b/odb/mssql/query.ixx
@@ -6,6 +6,12 @@ namespace odb
{
namespace mssql
{
+ 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/mssql/statement.cxx b/odb/mssql/statement.cxx
index 079d7f8..524fc06 100644
--- a/odb/mssql/statement.cxx
+++ b/odb/mssql/statement.cxx
@@ -95,14 +95,14 @@ namespace odb
//
statement::
- statement (connection& conn, const string& text)
+ statement (connection_type& conn, const string& text)
: conn_ (conn), text_copy_ (text), text_ (text_copy_.c_str ())
{
init (text_copy_.size ());
}
statement::
- statement (connection& conn, const char* text, bool copy)
+ statement (connection_type& conn, const char* text, bool copy)
: conn_ (conn)
{
size_t n;
@@ -700,7 +700,7 @@ namespace odb
}
select_statement::
- select_statement (connection& conn,
+ select_statement (connection_type& conn,
const string& t,
binding& param,
binding& result)
@@ -711,7 +711,7 @@ namespace odb
}
select_statement::
- select_statement (connection& conn,
+ select_statement (connection_type& conn,
const char* t,
binding& param,
binding& result,
@@ -723,14 +723,14 @@ namespace odb
}
select_statement::
- select_statement (connection& conn, const string& t, binding& result)
+ select_statement (connection_type& conn, const string& t, binding& result)
: statement (conn, t), result_ (result)
{
first_long_ = bind_result (result.bind, result.count);
}
select_statement::
- select_statement (connection& conn,
+ select_statement (connection_type& conn,
const char* t,
binding& result,
bool ct)
@@ -792,7 +792,7 @@ namespace odb
}
insert_statement::
- insert_statement (connection& conn,
+ insert_statement (connection_type& conn,
const string& t,
binding& param,
bool returning)
@@ -805,7 +805,7 @@ namespace odb
}
insert_statement::
- insert_statement (connection& conn,
+ insert_statement (connection_type& conn,
const char* t,
binding& param,
bool returning,
@@ -953,14 +953,14 @@ namespace odb
}
update_statement::
- update_statement (connection& conn, const string& t, binding& param)
+ update_statement (connection_type& conn, const string& t, binding& param)
: statement (conn, t)
{
bind_param (param.bind, param.count);
}
update_statement::
- update_statement (connection& conn,
+ update_statement (connection_type& conn,
const char* t,
binding& param,
bool ct)
@@ -1003,14 +1003,14 @@ namespace odb
}
delete_statement::
- delete_statement (connection& conn, const string& t, binding& param)
+ delete_statement (connection_type& conn, const string& t, binding& param)
: statement (conn, t)
{
bind_param (param.bind, param.count);
}
delete_statement::
- delete_statement (connection& conn,
+ delete_statement (connection_type& conn,
const char* t,
binding& param,
bool ct)
diff --git a/odb/mssql/statement.hxx b/odb/mssql/statement.hxx
index 86178e6..53e7c97 100644
--- a/odb/mssql/statement.hxx
+++ b/odb/mssql/statement.hxx
@@ -16,6 +16,7 @@
#include <odb/mssql/mssql-fwd.hxx>
#include <odb/mssql/version.hxx>
#include <odb/mssql/binding.hxx>
+#include <odb/mssql/connection.hxx>
#include <odb/mssql/auto-handle.hxx>
#include <odb/mssql/details/export.hxx>
@@ -29,6 +30,8 @@ namespace odb
class LIBODB_MSSQL_EXPORT statement: public odb::statement
{
public:
+ typedef mssql::connection connection_type;
+
virtual
~statement () = 0;
@@ -41,9 +44,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, bool copy_text);
+ statement (connection_type&, const std::string& text);
+ statement (connection_type&, const char* text, bool copy_text);
private:
void
@@ -73,7 +82,7 @@ namespace odb
void* new_base = 0);
protected:
- connection& conn_;
+ connection_type& conn_;
std::string text_copy_;
const char* text_;
auto_handle<SQL_HANDLE_STMT> stmt_;
@@ -89,22 +98,22 @@ namespace odb
// result binding, they should appear last in the statement
// text.
//
- select_statement (connection& conn,
+ select_statement (connection_type& conn,
const std::string& text,
binding& param,
binding& result);
- select_statement (connection& conn,
+ select_statement (connection_type& conn,
const char* text,
binding& param,
binding& result,
bool copy_text = true);
- select_statement (connection& conn,
+ select_statement (connection_type& conn,
const std::string& text,
binding& result);
- select_statement (connection& conn,
+ select_statement (connection_type& conn,
const char* text,
binding& result,
bool copy_text = true);
@@ -188,12 +197,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,
@@ -232,11 +241,11 @@ namespace odb
virtual
~update_statement ();
- update_statement (connection& conn,
+ update_statement (connection_type& conn,
const std::string& text,
binding& param);
- update_statement (connection& conn,
+ update_statement (connection_type& conn,
const char* text,
binding& param,
bool copy_text = true);
@@ -255,11 +264,11 @@ namespace odb
virtual
~delete_statement ();
- delete_statement (connection& conn,
+ delete_statement (connection_type& conn,
const std::string& text,
binding& param);
- delete_statement (connection& conn,
+ delete_statement (connection_type& conn,
const char* text,
binding& param,
bool copy_text = true);