diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2010-06-04 16:45:36 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2010-06-04 16:45:36 +0200 |
commit | fcfe083c7a6d12eb4b6b88eea4a5ebbfc4d36995 (patch) | |
tree | ba60af2863d425e8be78749558c73910ab2f921d /odb/mysql/database.hxx | |
parent | 073918a2f4bff3a6f12cfd722db50e3fb0a6db0d (diff) |
Initial implementation
Diffstat (limited to 'odb/mysql/database.hxx')
-rw-r--r-- | odb/mysql/database.hxx | 160 |
1 files changed, 160 insertions, 0 deletions
diff --git a/odb/mysql/database.hxx b/odb/mysql/database.hxx new file mode 100644 index 0000000..be939a7 --- /dev/null +++ b/odb/mysql/database.hxx @@ -0,0 +1,160 @@ +// file : odb/mysql/database.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_MYSQL_DATABASE_HXX +#define ODB_MYSQL_DATABASE_HXX + +#include <string> +#include <memory> // std::auto_ptr + +#include <mysql/mysql.h> + +#include <odb/shared-ptr.hxx> +#include <odb/database.hxx> + +#include <odb/mysql/forward.hxx> +#include <odb/mysql/connection.hxx> +#include <odb/mysql/connection-factory.hxx> +#include <odb/mysql/transaction-impl.hxx> + +namespace odb +{ + namespace mysql + { + class database: public odb::database + { + public: + typedef mysql::connection connection_type; + + public: + // In MySQL NULL and empty string are treated as the same value + // for all the arguments except passwd and socket. + // + database (const char* user, + const char* passwd, + const char* db, + const char* host = 0, + unsigned int port = 0, + const char* socket = 0, + unsigned long client_flags = 0, + std::auto_ptr<connection_factory> = + std::auto_ptr<connection_factory> (0)); + + database (const std::string& user, + const std::string& passwd, + const std::string& db, + const std::string& host = "", + unsigned int port = 0, + const std::string* socket = 0, + unsigned long client_flags = 0, + std::auto_ptr<connection_factory> = + std::auto_ptr<connection_factory> (0)); + + database (const std::string& user, + const std::string* passwd, + const std::string& db, + const std::string& host = "", + unsigned int port = 0, + const std::string* socket = 0, + unsigned long client_flags = 0, + std::auto_ptr<connection_factory> = + std::auto_ptr<connection_factory> (0)); + + database (const std::string& user, + const std::string& passwd, + const std::string& db, + const std::string& host, + unsigned int port, + const std::string& socket, + unsigned long client_flags = 0, + std::auto_ptr<connection_factory> = + std::auto_ptr<connection_factory> (0)); + + database (const std::string& user, + const std::string* passwd, + const std::string& db, + const std::string& host, + unsigned int port, + const std::string& socket, + unsigned long client_flags = 0, + std::auto_ptr<connection_factory> = + std::auto_ptr<connection_factory> (0)); + + public: + const char* + user () const + { + return user_.c_str (); + } + + const char* + passwd () const + { + return passwd_; + } + + const char* + db () const + { + return db_.c_str (); + } + + const char* + host () const + { + return host_.c_str (); + } + + unsigned int + port () const + { + return port_; + } + + const char* + socket () const + { + return socket_; + } + + unsigned long + client_flags () const + { + return client_flags_; + } + + public: + virtual transaction_impl* + begin_transaction (); + + virtual transaction_impl* + begin_transaction (session&); + + public: + shared_ptr<connection_type> + connection (); + + public: + virtual + ~database (); + + private: + const std::string user_; + const std::string passwd_str_; + const char* passwd_; + const std::string db_; + const std::string host_; + unsigned int port_; + const std::string socket_str_; + const char* socket_; + unsigned long client_flags_; + std::auto_ptr<connection_factory> factory_; + }; + } +} + +#include <odb/mysql/database.ixx> + +#endif // ODB_MYSQL_DATABASE_HXX |