// file : odb/mysql/connection.hxx // author : Boris Kolpackov // copyright : Copyright (c) 2005-2011 Code Synthesis Tools CC // license : GNU GPL v2; see accompanying LICENSE file #ifndef ODB_MYSQL_CONNECTION_HXX #define ODB_MYSQL_CONNECTION_HXX #include #include #include // std::auto_ptr #include #include #include #include #include #include namespace odb { namespace mysql { class statement; class statement_cache; class LIBODB_MYSQL_EXPORT connection: public details::shared_base { public: typedef mysql::statement_cache statement_cache_type; typedef mysql::database database_type; virtual ~connection (); connection (database_type&); database_type& database () { return db_; } public: bool failed () const { return failed_; } void mark_failed () { failed_ = true; } // Ping the server to make sure the connection is still alive. Return // true if successful, mark the connection as failed and return false // otherwise. This function can also throw database_exception. // bool ping (); public: MYSQL* handle () { return handle_; } statement_cache_type& statement_cache () { return *statement_cache_; } public: statement* active () { return active_; } void active (statement* s) { active_ = s; if (s == 0 && stmt_handles_.size () > 0) free_stmt_handles (); } // Cancel and clear the active statement, if any. // void clear () { if (active_ != 0) clear_ (); } public: MYSQL_STMT* alloc_stmt_handle (); void free_stmt_handle (MYSQL_STMT*); private: connection (const connection&); connection& operator= (const connection&); private: void free_stmt_handles (); void clear_ (); private: database_type& db_; bool failed_; MYSQL mysql_; MYSQL* handle_; statement* active_; std::auto_ptr statement_cache_; typedef std::vector stmt_handles; stmt_handles stmt_handles_; }; } } #include #endif // ODB_MYSQL_CONNECTION_HXX