From 61e6f0fded93f1e2105d7f4734b280712afe0c59 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 17 Nov 2011 11:31:00 +0200 Subject: Add connection, connection-factory implementations --- odb/mssql/connection.cxx | 110 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 odb/mssql/connection.cxx (limited to 'odb/mssql/connection.cxx') diff --git a/odb/mssql/connection.cxx b/odb/mssql/connection.cxx new file mode 100644 index 0000000..ff62c49 --- /dev/null +++ b/odb/mssql/connection.cxx @@ -0,0 +1,110 @@ +// file : odb/mssql/connection.cxx +// author : Constantin Michael +// copyright : Copyright (c) 2005-2011 Code Synthesis Tools CC +// license : ODB NCUEL; see accompanying LICENSE file + +//@@ disabled functionality + +//#include + +#include +#include +#include +//#include +//#include +//#include +#include + +using namespace std; + +namespace odb +{ + namespace mssql + { + connection:: + connection (database_type& db) + : odb::connection (db), + db_ (db), + state_ (state_disconnected) + // statement_cache_ (new statement_cache_type (*this)) + { + SQLRETURN r; + + // Allocate the connection handle. + // + { + SQLHANDLE h; + r = SQLAllocHandle (SQL_HANDLE_DBC, db_.environment (), &h); + + if (!SQL_SUCCEEDED (r)) + translate_error (db_.environment (), SQL_HANDLE_ENV); + + handle_.reset (h); + } + + // Connect. + // + { + SQLSMALLINT out_conn_str_size; + r = SQLDriverConnect (handle_, + 0, // Parent windows handle. + (SQLCHAR*) db_.connect_string ().c_str (), + SQL_NTS, + 0, // Output connection string buffer. + 0, // Size of output connection string buffer. + &out_conn_str_size, + SQL_DRIVER_NOPROMPT); + + if (!SQL_SUCCEEDED (r)) + // Still use the handle version of translate_error since there + // is no connection. + // + translate_error (handle_, SQL_HANDLE_DBC); + + state_ = state_connected; + } + + // If an exception is thrown after this line, we will not disconnect + // the connection. + // + } + + connection:: + connection (database_type& db, SQLHDBC handle) + : odb::connection (db), + db_ (db), + handle_ (handle), + state_ (state_connected) + // statement_cache_ (new statement_cache_type (*this)) + { + } + + connection:: + ~connection () + { + // Deallocate prepared statements before we close the connection. + // + //statement_cache_.reset (); + + if (state_ != state_disconnected) + SQLDisconnect (handle_); // Ignore any errors. + } + + transaction_impl* connection:: + begin () + { + //@@ + //return new transaction_impl (connection_ptr (inc_ref (this))); + return 0; + } + + unsigned long long connection:: + execute (const char* /*s*/, std::size_t /*n*/) + { + //@@ + //generic_statement st (*this, string (s, n)); + //return st.execute (); + return 0; + } + } +} -- cgit v1.1