// file : odb/mysql/database.hxx // author : Boris Kolpackov // copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC // license : GNU GPL v2; see accompanying LICENSE file #ifndef ODB_MYSQL_DATABASE_HXX #define ODB_MYSQL_DATABASE_HXX #include #include #include // std::auto_ptr #include // std::ostream #include #include #include #include #include #include #include #include namespace odb { namespace mysql { class transaction_impl; class LIBODB_MYSQL_EXPORT database: public odb::database { 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 = std::auto_ptr (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 = std::auto_ptr (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 = std::auto_ptr (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 = std::auto_ptr (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 = std::auto_ptr (0)); // Extract the database parameters from the command line. The // following options are recognized: // // --user // --password // --database // --host // --port // --socket // --options-file // // For more information, see the output of the print_usage() function // below. If erase is true, the above options are removed from the // argv array and the argc count is updated accordingly. This // constructor may throw the cli_exception exception. // database (int& argc, char* argv[], bool erase = false, unsigned long client_flags = 0, std::auto_ptr = std::auto_ptr (0)); static void print_usage (std::ostream&); public: const char* user () const { return user_.c_str (); } const char* password () 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: transaction_impl* begin (); public: connection_ptr connection (); public: virtual ~database (); protected: virtual odb::connection* connection_ (); private: std::string user_; std::string passwd_str_; const char* passwd_; std::string db_; std::string host_; unsigned int port_; std::string socket_str_; const char* socket_; unsigned long client_flags_; std::auto_ptr factory_; }; } } #include #include #endif // ODB_MYSQL_DATABASE_HXX