-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathcpp_sql.h
More file actions
54 lines (40 loc) · 1.7 KB
/
cpp_sql.h
File metadata and controls
54 lines (40 loc) · 1.7 KB
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
//
// Created by winter on 2019/7/17.
//
#include <memory>
#include "mysql_connection.h"
#include "cppconn/driver.h"
#include "cppconn/exception.h"
#include "cppconn/resultset.h"
#include "cppconn/statement.h"
#include "cppconn/prepared_statement.h"
#include "sql_handler.h"
struct CppSql : public ColumnLabelSqlHandler {
void Init(std::unique_ptr<sql::Statement> _stmt) {
stmt = std::move(_stmt);
}
virtual void ExecuteQuery(const std::string &sql) {
res.reset(stmt->executeQuery(sql));
};
virtual int32_t ExecuteUpdate(const std::string &sql) {
return stmt->executeUpdate(sql);
}
virtual bool Next() {
auto b = res->next();
if (!b) {
res.release();
}
return b;
}
virtual size_t GetFetchSize() { return res->getFetchSize(); }
virtual size_t GetRow() { return res->rowsCount(); }
virtual bool GetBoolean(const std::string& column_label) const { return res->getBoolean(column_label); }
virtual long double GetDouble(const std::string& column_label) const { return res->getDouble(column_label); }
virtual int32_t GetInt(const std::string& column_label) const {return res->getInt(column_label);}
virtual uint32_t GetUInt(const std::string& column_label) const {return res->getUInt(column_label);}
virtual int64_t GetInt64(const std::string& column_label) const {return res->getInt64(column_label);}
virtual uint64_t GetUInt64(const std::string& column_label) const {return res->getUInt64(column_label);}
virtual std::string GetString(const std::string& column_label) const {return res->getString(column_label);}
std::unique_ptr<sql::Statement> stmt;
std::unique_ptr<sql::ResultSet> res;
};