AnCH Framework  0.1
Another C++ Hack Framework
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
mysqlConnection.hpp
1 /*
2  ANCH Framework: ANother C++ Hack is a C++ framework based on C++11 standard
3  Copyright (C) 2012 Vincent Lachenal
4 
5  This file is part of ANCH Framework.
6 
7  ANCH Framework is free software: you can redistribute it and/or modify
8  it under the terms of the GNU Lesser General Public License as published by
9  the Free Software Foundation, either version 3 of the License, or
10  (at your option) any later version.
11 
12  ANCH Framework is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public License
18  along with ANCH Framework. If not, see <http://www.gnu.org/licenses/>.
19 */
20 #ifdef ANCH_SQL_MYSQL
21 #ifndef _ANCH_SQL_MYCON_H_
22 #define _ANCH_SQL_MYCON_H_
23 
24 #include <string>
25 #include <functional>
26 
27 #include "sql/connection.hpp"
28 
29 #include "mysql.h"
30 
31 namespace anch {
32  namespace sql {
33 
43  class MySQLConnection: public Connection {
44 
45  // Attributes +
46  private:
48  MYSQL _mysql;
49  // Attributes -
50 
51  // Constructors +
52  public:
65  MySQLConnection(const std::string& host,
66  const std::string& user,
67  const std::string& password,
68  const std::string& database,
69  int port,
70  const std::string& app = "AnCH")
71  throw(SqlException);
72 
81  throw(SqlException);
82 
87  throw(SqlException);
88  // Constructors -
89 
90  // Destructor +
94  virtual ~MySQLConnection() noexcept;
95  // Destructor -
96 
97  // Methods +
98  protected:
108  virtual ResultSet* executeQuery(const std::string& query) throw(SqlException) override;
109 
119  virtual uint64_t executeUpdate(const std::string& query) throw(SqlException) override;
120 
126  virtual void sendCommit() throw(SqlException) override;
127 
133  virtual void sendRollback() throw(SqlException) override;
134 
142  virtual void toggleAutoCommit(bool autoCommit) throw(SqlException) override;
143  // Methods -
144 
145  };
146 
147  }
148 }
149 
150 #endif // _ANCH_SQL_MYCON_H_
151 #endif // ANCH_SQL_MYSQL
virtual void toggleAutoCommit(bool autoCommit) override
Definition: mysqlConnection.cpp:171
SQL database connection configuration.
Definition: connection.hpp:41
virtual ResultSet * executeQuery(const std::string &query) override
Definition: mysqlConnection.cpp:177
virtual uint64_t executeUpdate(const std::string &query) override
Definition: mysqlConnection.cpp:200
SQL exception.
Definition: sqlException.hpp:39
SQL result representation.
Definition: resultSet.hpp:44
AnCH framework base namespace.
Definition: base64.hpp:28
SQL connection virtual class.
Definition: connection.hpp:73
virtual void sendRollback() override
Definition: mysqlConnection.cpp:163
MySQL connection.
Definition: mysqlConnection.hpp:43
ResultSet * query(const std::string &query)
Definition: connection.cpp:61
virtual ~MySQLConnection() noexcept
Definition: mysqlConnection.cpp:148
MySQLConnection(const std::string &host, const std::string &user, const std::string &password, const std::string &database, int port, const std::string &app="AnCH")
Definition: mysqlConnection.cpp:74
virtual void sendCommit() override
Definition: mysqlConnection.cpp:155