00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #if !defined(MYSQLPP_CONNECTION_H)
00036 #define MYSQLPP_CONNECTION_H
00037
00038 #include "common.h"
00039
00040 #include "noexceptions.h"
00041 #include "options.h"
00042
00043 #include <string>
00044
00045 namespace mysqlpp {
00046
00047 #if !defined(DOXYGEN_IGNORE)
00048
00049 class MYSQLPP_EXPORT Query;
00050 class DBDriver;
00051 #endif
00052
00058
00059 class MYSQLPP_EXPORT Connection : public OptionalExceptions
00060 {
00061 private:
00066 typedef bool Connection::*private_bool_type;
00067
00068 public:
00072 Connection(bool te = true);
00073
00107 Connection(const char* db, const char* server = 0, const char* user = 0,
00108 const char* password = 0, unsigned int port = 0);
00109
00114 Connection(const Connection& other);
00115
00117 virtual ~Connection();
00118
00121 std::string client_version() const;
00122
00131 virtual bool connect(const char* db = 0, const char* server = 0,
00132 const char* user = 0, const char* password = 0,
00133 unsigned int port = 0);
00134
00138 bool connected() const;
00139
00146 ulonglong count_rows(const std::string& table);
00147
00153 bool create_db(const std::string& db);
00154
00156 void disconnect();
00157
00167 DBDriver* driver() { return driver_; }
00168
00174 bool drop_db(const std::string& db);
00175
00178 int errnum();
00179
00185 const char* error() const;
00186
00192 std::string ipc_info() const;
00193
00199 bool kill(unsigned long tid) const;
00200
00220 operator private_bool_type() const
00221 {
00222 return copacetic_ ? &Connection::copacetic_ : 0;
00223 }
00224
00227 Connection& operator=(const Connection& rhs);
00228
00235 bool ping();
00236
00239 int protocol_version() const;
00240
00251 Query query(const char* qstr = 0);
00252
00256 Query query(const std::string& qstr);
00257
00264 bool select_db(const std::string& db);
00265
00267 std::string server_version() const;
00268
00292 bool set_option(Option* o);
00293
00295 bool shutdown();
00296
00298 std::string server_status() const;
00299
00302 static bool thread_aware();
00303
00306 static void thread_end();
00307
00312 unsigned long thread_id();
00313
00333 static bool thread_start();
00334
00335 protected:
00339 void build_error_message(const char* core);
00340
00344 void copy(const Connection& other);
00345
00348 bool parse_ipc_method(const char* server, std::string& host,
00349 unsigned int& port, std::string& socket_name);
00350
00352 mutable std::string error_message_;
00353
00354 private:
00355 DBDriver* driver_;
00356 bool copacetic_;
00357 };
00358
00359
00360 }
00361
00362
00363 #include "tcp_connection.h"
00364 #include "uds_connection.h"
00365 #include "wnp_connection.h"
00366
00367 #endif // !defined(MYSQLPP_CONNECTION_H)
00368