MySQL++  3.3.0
connection.h
Go to the documentation of this file.
1 
11 /***********************************************************************
12  Copyright (c) 1998 by Kevin Atkinson, (c) 1999-2001 by MySQL AB, and
13  (c) 2004-2007 by Educational Technology Resources, Inc. Others may
14  also hold copyrights on code in this file. See the CREDITS.txt file
15  in the top directory of the distribution for details.
16 
17  This file is part of MySQL++.
18 
19  MySQL++ is free software; you can redistribute it and/or modify it
20  under the terms of the GNU Lesser General Public License as published
21  by the Free Software Foundation; either version 2.1 of the License, or
22  (at your option) any later version.
23 
24  MySQL++ is distributed in the hope that it will be useful, but WITHOUT
25  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
26  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
27  License for more details.
28 
29  You should have received a copy of the GNU Lesser General Public
30  License along with MySQL++; if not, write to the Free Software
31  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
32  USA
33 ***********************************************************************/
34 
35 #if !defined(MYSQLPP_CONNECTION_H)
36 #define MYSQLPP_CONNECTION_H
37 
38 #include "common.h"
39 
40 #include "noexceptions.h"
41 #include "options.h"
42 
43 #include <string>
44 
45 namespace mysqlpp {
46 
47 #if !defined(DOXYGEN_IGNORE)
48 // Make Doxygen ignore this
49 class MYSQLPP_EXPORT Query;
50 class DBDriver;
51 #endif
52 
58 
59 class MYSQLPP_EXPORT Connection : public OptionalExceptions
60 {
61 private:
66  typedef bool Connection::*private_bool_type;
67 
68 public:
72  Connection(bool te = true);
73 
107  Connection(const char* db, const char* server = 0, const char* user = 0,
108  const char* password = 0, unsigned int port = 0);
109 
114  Connection(const Connection& other);
115 
117  virtual ~Connection();
118 
121  std::string client_version() const;
122 
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);
134 
138  bool connected() const;
139 
146  ulonglong count_rows(const std::string& table);
147 
153  bool create_db(const std::string& db);
154 
156  void disconnect();
157 
167  DBDriver* driver() { return driver_; }
168 
174  bool drop_db(const std::string& db);
175 
178  int errnum();
179 
185  const char* error() const;
186 
192  std::string ipc_info() const;
193 
199  bool kill(unsigned long tid) const;
200 
220  operator private_bool_type() const
221  {
222  return copacetic_ ? &Connection::copacetic_ : 0;
223  }
224 
227  Connection& operator=(const Connection& rhs);
228 
235  bool ping();
236 
239  int protocol_version() const;
240 
251  Query query(const char* qstr = 0);
252 
256  Query query(const std::string& qstr);
257 
264  bool select_db(const std::string& db);
265 
267  std::string server_version() const;
268 
292  bool set_option(Option* o);
293 
295  bool shutdown();
296 
298  std::string server_status() const;
299 
302  static bool thread_aware();
303 
306  static void thread_end();
307 
312  unsigned long thread_id();
313 
333  static bool thread_start();
334 
335 protected:
339  void build_error_message(const char* core);
340 
344  void copy(const Connection& other);
345 
348  bool parse_ipc_method(const char* server, std::string& host,
349  unsigned int& port, std::string& socket_name);
350 
352  mutable std::string error_message_;
353 
354 private:
355  DBDriver* driver_;
356  bool copacetic_;
357 };
358 
359 
360 } // end namespace mysqlpp
361 
362 // Not strictly required, but bring in our specialization subclasses
363 #include "tcp_connection.h"
364 #include "uds_connection.h"
365 #include "wnp_connection.h"
366 
367 #endif // !defined(MYSQLPP_CONNECTION_H)
368 
Manages the connection to the database server.
Definition: connection.h:60
DBDriver * driver()
Returns a reference to the current database driver.
Definition: connection.h:167
std::string error_message_
MySQL++ specific error, if any.
Definition: connection.h:352
Provides a thin abstraction layer over the underlying database client library.
Definition: dbdriver.h:58
Define abstract interface for all *Option subclasses.
Definition: options.h:58
Interface allowing a class to have optional exceptions.
Definition: noexceptions.h:72
A class for building and executing SQL queries.
Definition: query.h:124
This file includes top-level definitions for use both internal to the library, and outside it....
Declares interface that allows exceptions to be optional.
Declares the Option class hierarchy, used to implement connection options in Connection and DBDriver ...
Declares the TCPConnection class.
Declares the UnixDomainSocketConnection class.
Declares the WindowsNamedPipeConnection class.