SMT-RAT  24.02
Toolbox for Strategic and Parallel Satisfiability-Modulo-Theories Solving
Database_mysqlpp.h
Go to the documentation of this file.
1 /**
2  * @file Database_mysqlpp.h
3  * @author Gereon Kremer <gereon.kremer@cs.rwth-aachen.de>
4  */
5 
6 #pragma once
7 
8 #define MYSQLPP_MYSQL_HEADERS_BURIED
9 #include <mysql++/mysql++.h>
10 #include <mysql++/sql_types.h>
11 
12 #include "../logging.h"
13 
14 namespace benchmax {
15 
16 class DBAL {
17  mysqlpp::Connection conn;
18 public:
19  typedef mysqlpp::sql_bigint_unsigned Index;
20  typedef mysqlpp::Query Statement;
21  typedef mysqlpp::StoreQueryResult Results;
22 
23  bool connect(const std::string& db, const std::string& host, const std::string& user, const std::string& password) {
24  return conn.connect(db.c_str(), host.c_str(), user.c_str(), password.c_str());
25  }
26  Statement prepare(const std::string& query) {
27  Statement s = conn.query(query);
28  s.parse();
29  return s;
30  }
31  template<typename... Args>
32  void execute(Statement& stmt, const Args&... args) {
33  stmt.execute(args...);
34  }
35  template<typename... Args>
36  Index insert(const std::string& query, const Args&... args) {
37  Statement s = prepare(query);
38  mysqlpp::SimpleResult res = s.execute(args...);
39  return res.insert_id();
40  }
41  template<typename... Args>
42  Results select(const std::string& query, const Args&... args) {
43  Statement s = prepare(query);
44  return s.store(args...);
45  }
46  std::size_t size(const Results& res) {
47  return res.size();
48  }
49  Index getIndex(const Results& res, const std::string& name) {
50  return res[0][name.c_str()];
51  }
52 };
53 
54 }
std::size_t size(const Results &res)
bool connect(const std::string &db, const std::string &host, const std::string &user, const std::string &password)
std::unique_ptr< sql::ResultSet > Results
Results type.
Statement prepare(const std::string &query)
std::unique_ptr< sql::Connection > conn
void execute(Statement &stmt, const Args &... args)
std::unique_ptr< sql::PreparedStatement > Statement
Statement type.
mysqlpp::sql_bigint_unsigned Index
mysqlpp::Query Statement
mysqlpp::StoreQueryResult Results
std::size_t Index
Indec type.
Index getIndex(const Results &res, const std::string &name)
Index insert(const std::string &query, const Args &... args)
mysqlpp::Connection conn
Results select(const std::string &query, const Args &... args)