AnCH Framework  0.1
Another C++ Hack Framework
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
connection.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 #ifndef _ANCH_SQL_CON_H_
21 #define _ANCH_SQL_CON_H_
22 
23 #include <functional>
24 
25 #include "sql/sqlException.hpp"
26 #include "sql/resultSet.hpp"
27 
28 
29 namespace anch {
30  namespace sql {
31 
43  std::string driver;
44 
46  std::string database;
47 
49  std::string hostname;
50 
52  int port;
53 
55  std::string user;
56 
58  std::string password;
59 
61  std::string application;
62  };
63 
73  class Connection {
74 
75  // Attributes +
76  protected:
79 
81  bool _valid;
82  // Attributes -
83 
84  // Constructors +
85  public:
91  Connection() throw(SqlException);
92 
96  Connection(const Connection&) = delete;
97  // Constructors -
98 
99  // Destructor +
100  public:
104  virtual ~Connection();
105  // Destructor -
106 
107  // Methods +
108  public:
115  void commit() throw(SqlException);
116 
123  void rollback() throw(SqlException);
124 
134  void setAutoCommit(bool autoCommit) throw(SqlException);
135 
145  ResultSet* query(const std::string& query) throw(SqlException);
146 
155  void queryMapRow(const std::string& sqlQuery, std::function<void(ResultSet&)> rowMapper) throw(SqlException);
156 
165  void queryExtract(const std::string& sqlQuery, std::function<void(ResultSet&)> resExtractor) throw(SqlException);
166 
174  uint64_t update(const std::string& query) throw(SqlException);
175 
176  protected:
186  virtual ResultSet* executeQuery(const std::string& query) throw(SqlException) = 0;
187 
197  virtual uint64_t executeUpdate(const std::string& query) throw(SqlException) = 0;
198 
204  virtual void sendCommit() throw(SqlException) = 0;
205 
211  virtual void sendRollback() throw(SqlException) = 0;
212 
220  virtual void toggleAutoCommit(bool autoCommit) throw(SqlException) = 0;
221  // Methods -
222 
223  // Accessors +
224  public:
230  inline bool isAutoCommit() const {
231  return _autoCommit;
232  }
233 
239  inline bool isValid() const {
240  return _valid;
241  }
242 
243  protected:
249  inline void setValid(bool valid) {
250  _valid = valid;
251  }
252  // Accessors -
253 
254  };
255 
256  }
257 }
258 
259 #endif // _ANCH_SQL_CON_H_
SQL database connection configuration.
Definition: connection.hpp:41
int port
Definition: connection.hpp:52
bool _autoCommit
Definition: connection.hpp:78
STL namespace.
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
std::string driver
Definition: connection.hpp:43
void setValid(bool valid)
Definition: connection.hpp:249
bool isValid() const
Definition: connection.hpp:239
std::string application
Definition: connection.hpp:61
std::string user
Definition: connection.hpp:55
bool _valid
Definition: connection.hpp:81
std::string hostname
Definition: connection.hpp:49
std::string password
Definition: connection.hpp:58
std::string database
Definition: connection.hpp:46