forked from eduardocasas/MySQL-Connector-Cpp-Wrapper-Class
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmysqlconn_wrapper.h
60 lines (46 loc) · 1.34 KB
/
mysqlconn_wrapper.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
* File: mysqlconn_wrapper.h
* Author: Eduardo Casas (www.eduardocasas.com)
*
* Created on February 24, 2013, 5:07 PM
*/
#ifndef MYSQLCONN_WRAPPER_H
#define MYSQLCONN_WRAPPER_H
#include "mysql_connection.h"
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
using namespace std;
class MySQLConnWrapper
{
public:
/* Your MySQL server settings */
MySQLConnWrapper()
{
host = "tcp://127.0.0.1:3306";
user = "root";
password = "";
};
~MySQLConnWrapper();
void manageException(sql::SQLException& e);
void connect();
void switchDb(const string& db_name);
void prepare(const string& query);
void setInt(const int& num, const int& data);
void setString(const int& num, const string& data);
void execute(const string& query = "");
bool fetch();
string print(const string& field);
string print(const int& index);
private:
string host;
string user;
string password;
sql::Driver* driver;
sql::Connection* con;
sql::Statement* stmt;
sql::PreparedStatement* prep_stmt;
sql::ResultSet* res;
};
#endif /* MYSQLCONN_WRAPPER_H */