From f26337fb02c2f01382486407c2b3d7432df9bd37 Mon Sep 17 00:00:00 2001 From: Constantin Michael Date: Mon, 9 May 2011 16:45:31 +0200 Subject: Add connection and connection factory implementations --- odb/pgsql/connection.cxx | 87 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 odb/pgsql/connection.cxx (limited to 'odb/pgsql/connection.cxx') diff --git a/odb/pgsql/connection.cxx b/odb/pgsql/connection.cxx new file mode 100644 index 0000000..37f359f --- /dev/null +++ b/odb/pgsql/connection.cxx @@ -0,0 +1,87 @@ +// file : odb/pgsql/connection.cxx +// author : Constantin Michael +// copyright : Copyright (c) 2005-2011 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#include // std::bad_alloc +#include + +#include +#include +#include +#include + +using namespace std; + +namespace odb +{ + namespace pgsql + { + connection:: + connection (database_type& db) + : db_ (db), + handle_ (0) + // active_ (0), + // statement_cache_ (new statement_cache_type (*this)) + { + handle_ = PQconnectdb (db.conninfo ().c_str ()); + + if (handle_ == 0) + throw bad_alloc (); + else if (PQstatus (handle_) == CONNECTION_BAD) + { + std::string m (PQerrorMessage (handle_)); + PQfinish (handle_); + + throw database_exception (m); + } + } + + connection:: + ~connection () + { + // if (stmt_handles_.size () > 0) + // free_stmt_handles (); + + PQfinish (handle_); + } + + // void connection:: + // clear_ () + // { + // active_->cancel (); // Should clear itself from active_. + // } + + // MYSQL_STMT* connection:: + // alloc_stmt_handle () + // { + // MYSQL_STMT* stmt (mysql_stmt_init (handle_)); + + // if (stmt == 0) + // throw bad_alloc (); + + // return stmt; + // } + + // void connection:: + // free_stmt_handle (MYSQL_STMT* stmt) + // { + // if (active_ == 0) + // mysql_stmt_close (stmt); + // else + // stmt_handles_.push_back (stmt); + // } + + // void connection:: + // free_stmt_handles () + // { + // for (stmt_handles::iterator i (stmt_handles_.begin ()), + // e (stmt_handles_.end ()); i != e; ++i) + // { + // mysql_stmt_close (*i); + // } + + // stmt_handles_.clear (); + // } + } +} -- cgit v1.1