aboutsummaryrefslogtreecommitdiff
path: root/odb/pgsql/connection.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2011-08-28 16:07:38 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2011-08-28 16:07:38 +0200
commitb405fdd235a7dcb40423229af033abd4687c72b2 (patch)
tree6c0ba8a9732d5891990d302b98b4c44f924a78af /odb/pgsql/connection.cxx
parentae4b24d8d83a46dce969fd049a480bcaaeb0ad83 (diff)
Add support for creating connection from existing handle
This will allow for custom connection establishment and configuration.
Diffstat (limited to 'odb/pgsql/connection.cxx')
-rw-r--r--odb/pgsql/connection.cxx28
1 files changed, 21 insertions, 7 deletions
diff --git a/odb/pgsql/connection.cxx b/odb/pgsql/connection.cxx
index 0a23ed7..be88446 100644
--- a/odb/pgsql/connection.cxx
+++ b/odb/pgsql/connection.cxx
@@ -31,10 +31,7 @@ namespace odb
{
connection::
connection (database_type& db)
- : odb::connection (db),
- db_ (db),
- handle_ (0),
- statement_cache_ (new statement_cache_type (*this))
+ : odb::connection (db), db_ (db)
{
handle_ = PQconnectdb (db.conninfo ().c_str ());
@@ -48,16 +45,33 @@ namespace odb
throw database_exception (m);
}
- // Suppress server notifications to stdout.
- //
- PQsetNoticeProcessor (handle_, &odb_pgsql_process_notice, 0);
+ init ();
+ }
+
+ connection::
+ connection (database_type& db, PGconn* handle)
+ : odb::connection (db), db_ (db), handle_ (handle)
+ {
+ init ();
+ }
+ void connection::
+ init ()
+ {
// Establish whether date/time values are represented as
// 8-byte integers.
//
if (strcmp (PQparameterStatus (handle_, "integer_datetimes"), "on") != 0)
throw database_exception ("unsupported binary format for PostgreSQL "
"date-time SQL types");
+
+ // Suppress server notifications to stdout.
+ //
+ PQsetNoticeProcessor (handle_, &odb_pgsql_process_notice, 0);
+
+ // Create statement cache.
+ //
+ statement_cache_.reset (new statement_cache_type (*this));
}
connection::