connection.h
Go to the documentation of this file.
/***********************************************************************
Copyright (c) 1998 by Kevin Atkinson, (c) 1999-2001 by MySQL AB, and
(c) 2004-2007 by Educational Technology Resources, Inc. Others may
also hold copyrights on code in this file. See the CREDITS.txt file
in the top directory of the distribution for details.
This file is part of MySQL++.
MySQL++ is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
MySQL++ is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public
License along with MySQL++; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
USA
***********************************************************************/
#if !defined(MYSQLPP_CONNECTION_H)
#define MYSQLPP_CONNECTION_H
#include "common.h"
#include "noexceptions.h"
#include "options.h"
#include <string>
namespace mysqlpp {
#if !defined(DOXYGEN_IGNORE)
// Make Doxygen ignore this
class MYSQLPP_EXPORT Query;
class DBDriver;
#endif
class MYSQLPP_EXPORT Connection : public OptionalExceptions
{
private:
typedef bool Connection::*private_bool_type;
public:
Connection(bool te = true);
Connection(const char* db, const char* server = 0, const char* user = 0,
const char* password = 0, unsigned int port = 0);
Connection(const Connection& other);
virtual ~Connection();
std::string client_version() const;
virtual bool connect(const char* db = 0, const char* server = 0,
const char* user = 0, const char* password = 0,
unsigned int port = 0);
bool connected() const;
ulonglong count_rows(const std::string& table);
bool create_db(const std::string& db);
void disconnect();
DBDriver* driver() { return driver_; }
bool drop_db(const std::string& db);
int errnum();
const char* error() const;
std::string ipc_info() const;
bool kill(unsigned long tid) const;
operator private_bool_type() const
{
return copacetic_ ? &Connection::copacetic_ : 0;
}
Connection& operator=(const Connection& rhs);
bool ping();
int protocol_version() const;
Query query(const char* qstr = 0);
Query query(const std::string& qstr);
bool select_db(const std::string& db);
std::string server_version() const;
bool set_option(Option* o);
bool shutdown();
std::string server_status() const;
static bool thread_aware();
static void thread_end();
unsigned long thread_id();
static bool thread_start();
protected:
void build_error_message(const char* core);
void copy(const Connection& other);
bool parse_ipc_method(const char* server, std::string& host,
unsigned int& port, std::string& socket_name);
mutable std::string error_message_;
private:
DBDriver* driver_;
bool copacetic_;
};
} // end namespace mysqlpp
// Not strictly required, but bring in our specialization subclasses
#include "tcp_connection.h"
#include "uds_connection.h"
#include "wnp_connection.h"
#endif // !defined(MYSQLPP_CONNECTION_H)
uds_connection.h
Declares the UnixDomainSocketConnection class.
tcp_connection.h
Declares the TCPConnection class.
mysqlpp::Connection::error_message_
std::string error_message_
MySQL++ specific error, if any.
Definition: connection.h:352
wnp_connection.h
Declares the WindowsNamedPipeConnection class.
mysqlpp::Connection
Manages the connection to the database server.
Definition: connection.h:59
mysqlpp::Option
Define abstract interface for all *Option subclasses.
Definition: options.h:57
mysqlpp::OptionalExceptions
Interface allowing a class to have optional exceptions.
Definition: noexceptions.h:71
common.h
This file includes top-level definitions for use both internal to the library, and outside it...
options.h
Declares the Option class hierarchy, used to implement connection options in Connection and DBDriver ...
mysqlpp::Connection::driver
DBDriver * driver()
Returns a reference to the current database driver.
Definition: connection.h:167
mysqlpp::Query
A class for building and executing SQL queries.
Definition: query.h:121
noexceptions.h
Declares interface that allows exceptions to be optional.
mysqlpp::DBDriver
Provides a thin abstraction layer over the underlying database client library.
Definition: dbdriver.h:57