aboutsummaryrefslogtreecommitdiff
path: root/odb/mysql/connection.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2010-06-04 16:45:36 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2010-06-04 16:45:36 +0200
commitfcfe083c7a6d12eb4b6b88eea4a5ebbfc4d36995 (patch)
treeba60af2863d425e8be78749558c73910ab2f921d /odb/mysql/connection.cxx
parent073918a2f4bff3a6f12cfd722db50e3fb0a6db0d (diff)
Initial implementation
Diffstat (limited to 'odb/mysql/connection.cxx')
-rw-r--r--odb/mysql/connection.cxx44
1 files changed, 44 insertions, 0 deletions
diff --git a/odb/mysql/connection.cxx b/odb/mysql/connection.cxx
new file mode 100644
index 0000000..9edb814
--- /dev/null
+++ b/odb/mysql/connection.cxx
@@ -0,0 +1,44 @@
+// file : odb/mysql/connection.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#include <new> // std::bad_alloc
+
+#include <odb/mysql/database.hxx>
+#include <odb/mysql/connection.hxx>
+#include <odb/mysql/exceptions.hxx>
+
+namespace odb
+{
+ namespace mysql
+ {
+ connection::
+ connection (database& db)
+ : handle_ (&mysql_)
+ {
+ if (mysql_init (handle_) == 0)
+ throw std::bad_alloc ();
+
+ if (mysql_real_connect (handle_,
+ db.host (),
+ db.user (),
+ db.passwd (),
+ db.db (),
+ db.port (),
+ db.socket (),
+ db.client_flags ()) == 0)
+ {
+ database_exception e (handle_);
+ mysql_close (handle_);
+ throw e;
+ }
+ }
+
+ connection::
+ ~connection ()
+ {
+ mysql_close (handle_);
+ }
+ }
+}