Go to the documentation of this file.
35 #if !defined(MYSQLPP_CONNECTION_H)
36 #define MYSQLPP_CONNECTION_H
47 #if !defined(DOXYGEN_IGNORE)
49 class MYSQLPP_EXPORT Query;
59 class MYSQLPP_EXPORT Connection :
public OptionalExceptions
66 typedef bool Connection::*private_bool_type;
72 Connection(
bool te =
true);
107 Connection(
const char* db,
const char* server = 0,
const char* user = 0,
108 const char* password = 0,
unsigned int port = 0);
114 Connection(
const Connection& other);
117 virtual ~Connection();
121 std::string client_version()
const;
131 virtual bool connect(
const char* db = 0,
const char* server = 0,
132 const char* user = 0,
const char* password = 0,
133 unsigned int port = 0);
138 bool connected()
const;
146 ulonglong count_rows(
const std::string& table);
153 bool create_db(
const std::string& db);
167 DBDriver* driver() {
return driver_; }
174 bool drop_db(
const std::string& db);
185 const char* error()
const;
192 std::string ipc_info()
const;
199 bool kill(
unsigned long tid)
const;
220 operator private_bool_type()
const
222 return copacetic_ ? &Connection::copacetic_ : 0;
227 Connection& operator=(
const Connection& rhs);
239 int protocol_version()
const;
251 Query query(
const char* qstr = 0);
256 Query query(
const std::string& qstr);
264 bool select_db(
const std::string& db);
267 std::string server_version()
const;
292 bool set_option(
Option* o);
298 std::string server_status()
const;
302 static bool thread_aware();
306 static void thread_end();
312 unsigned long thread_id();
333 static bool thread_start();
339 void build_error_message(
const char* core);
348 bool parse_ipc_method(
const char* server, std::string& host,
349 unsigned int& port, std::string& socket_name);
352 mutable std::string error_message_;
367 #endif // !defined(MYSQLPP_CONNECTION_H)
ulonglong count_rows(const std::string &table)
Returns the number of rows in a table.
Definition: connection.cpp:135
bool kill(unsigned long tid)
Kill a MySQL server thread.
Definition: dbdriver.h:436
Connection & operator=(const Connection &rhs)
Copy an existing Connection object's state into this object.
Definition: connection.cpp:207
int errnum()
Return last MySQL error number associated with this connection.
Definition: dbdriver.h:236
bool ping()
"Pings" the MySQL database
Definition: dbdriver.h:507
Define abstract interface for all *Option subclasses.
Definition: options.h:78
void disconnect()
Drop the connection to the database server.
Definition: connection.cpp:160
static bool is_socket(const char *path, std::string *error=0)
Check that the given path names a Unix domain socket and that we have read-write permission for it.
Definition: uds_connection.cpp:67
void build_error_message(const char *core)
Build an error message in the standard form used whenever one of the methods can't succeed because we...
Definition: connection.cpp:80
static bool is_wnp(const char *server)
Check that given string denotes a Windows named pipe connection to MySQL.
Definition: wnp_connection.cpp:62
std::string ipc_info()
Get information about the IPC connection to the database server.
Definition: dbdriver.h:407
std::string client_version() const
Get database client library version.
Definition: dbdriver.h:138
Manages the connection to the database server.
Definition: connection.h:81
bool set_option(Option *o)
Sets a connection option.
Definition: dbdriver.cpp:283
void set_exceptions(bool e) const
Sets the exception state to a particular value.
Definition: noexceptions.h:141
const char * error()
Return error message for last MySQL error associated with this connection.
Definition: dbdriver.h:227
Declares the WindowsNamedPipeConnection class.
bool parse_ipc_method(const char *server, std::string &host, unsigned int &port, std::string &socket_name)
Extract elements from the server parameter in formats suitable for passing to DBDriver::connect().
Definition: connection.cpp:215
Exception thrown when you pass an unrecognized option to Connection::set_option().
Definition: exceptions.h:227
Declares the Option class hierarchy, used to implement connection options in Connection and DBDriver ...
std::string server_version() const
Get the database server's version string.
Definition: connection.cpp:316
StoreQueryResult set type for "store" queries.
Definition: result.h:231
A class for building and executing SQL queries.
Definition: query.h:143
Defines a class for building and executing SQL queries.
static bool thread_start()
Tells the underlying database driver that the current thread is now using its services.
Definition: connection.cpp:387
unsigned long thread_id()
Returns the database server's thread ID for this connection.
Definition: connection.cpp:380
Provides a thin abstraction layer over the underlying database client library.
Definition: dbdriver.h:79
unsigned long thread_id()
Returns the MySQL server thread ID for this connection.
Definition: dbdriver.h:685
std::string error_message_
MySQL++ specific error, if any.
Definition: connection.h:396
const char * error() const
Return error message for last error associated with this connection.
Definition: connection.cpp:185
bool shutdown()
Ask database server to shut down.
Definition: connection.cpp:341
static bool parse_address(std::string &addr, unsigned int &port, std::string &error)
Break the given TCP/IP address up into a separate address and port form.
Definition: tcp_connection.cpp:76
Connection(bool te=true)
Create object without connecting to the database server.
Definition: connection.cpp:38
Query query(const char *qstr=0)
Return a new query object.
Definition: connection.cpp:270
void copy(const DBDriver &other)
Establish a new connection as a copy of an existing one.
Definition: dbdriver.cpp:121
std::string server_version()
Get the database server's version number.
Definition: dbdriver.h:562
bool connect(const MYSQL &mysql)
Establish a new connection using the same parameters as an existing connection.
Definition: dbdriver.cpp:82
static bool thread_aware()
Returns true if both MySQL++ and database driver we're using were compiled with thread awareness.
Definition: connection.cpp:366
Declares the DBDriver class.
bool connected() const
Return true if we have an active connection to the database server.
Definition: dbdriver.h:166
bool ping()
"Pings" the database server
Definition: connection.cpp:247
bool set_option(Option *o)
Sets a connection option.
Definition: connection.cpp:323
static void thread_end()
Tells the underlying MySQL C API library that this thread is done using the library.
Definition: dbdriver.h:674
std::string server_status()
Returns the database server's status.
Definition: dbdriver.h:638
std::string client_version() const
Get version of library underpinning the current database driver.
Definition: connection.cpp:89
virtual ~Connection()
Destroy object.
Definition: connection.cpp:72
Declares interface that allows exceptions to be optional.
Exception thrown when there is a problem related to the database server connection.
Definition: exceptions.h:350
bool select_db(const std::string &db)
Change to a different database managed by the database server we are connected to.
Definition: connection.cpp:284
bool shutdown()
Ask database server to shut down.
Definition: dbdriver.cpp:332
Declares classes for holding information about SQL query results.
bool drop_db(const std::string &db)
Asks the database server to drop (destroy) a database.
Definition: connection.cpp:168
Declares the Connection class.
This file includes top-level definitions for use both internal to the library, and outside it....
Declares the UnixDomainSocketConnection class.
bool connected() const
Returns true if connection was established successfully.
Definition: connection.cpp:119
StoreQueryResult store()
Execute a query that can return a result set.
Definition: query.cpp:511
static void thread_end()
Tells the underlying database driver that this thread is done using the library.
Definition: connection.cpp:373
Declares the TCPConnection class.
virtual bool connect(const char *db=0, const char *server=0, const char *user=0, const char *password=0, unsigned int port=0)
Connect to database after object is created.
Definition: connection.cpp:96
Exception thrown when the program tries to select a new database and the database server refuses for ...
Definition: exceptions.h:381
Interface allowing a class to have optional exceptions.
Definition: noexceptions.h:92
bool create_db(const std::string &db)
Ask the database server to create a database.
Definition: connection.cpp:150
void disconnect()
Drop the connection to the database server.
Definition: dbdriver.cpp:134
int protocol_version()
Returns version number of MySQL protocol this connection is using.
Definition: dbdriver.h:517
bool kill(unsigned long tid) const
Kill a database server thread.
Definition: connection.cpp:199
static bool thread_aware()
Returns true if MySQL++ and the underlying MySQL C API library were both compiled with thread awarene...
Definition: dbdriver.cpp:352
bool select_db(const char *db)
Asks the database server to switch to a different database.
Definition: dbdriver.h:553
int errnum()
Return last error number associated with this connection.
Definition: connection.cpp:178
static bool thread_start()
Tells the underlying C API library that the current thread will be using the library's services.
Definition: dbdriver.h:709
bool throw_exceptions() const
Returns true if exceptions are enabled.
Definition: noexceptions.h:134
void copy(const Connection &other)
Establish a new connection as a copy of an existing one.
Definition: connection.cpp:126
std::string server_status() const
Returns information about database server's status.
Definition: connection.cpp:309
bool exec()
Execute a built-up query.
Definition: query.h:317
std::string ipc_info() const
Get information about the IPC connection to the database server.
Definition: connection.cpp:192
int protocol_version() const
Returns version number of the protocol the database driver uses to communicate with the server.
Definition: connection.cpp:263