forked from pschlan/cron-job.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMySQL.h
85 lines (69 loc) · 1.88 KB
/
MySQL.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
* chronos, the cron-job.org execution daemon
* Copyright (C) 2017 Patrick Schlangen <[email protected]>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
*/
#ifndef _MYSQL_H_
#define _MYSQL_H_
#include <memory>
#include <stdio.h>
#include <string>
#include <stdexcept>
#include <stdarg.h>
#include <mysql.h>
namespace Chronos
{
class MySQL_DB;
class MySQL_Result
{
private:
MySQL_Result(MYSQL_RES *res);
MySQL_Result(const MySQL_Result &other) = delete;
MySQL_Result(MySQL_Result &&other) = delete;
MySQL_Result &operator=(const MySQL_Result &other) = delete;
MySQL_Result &operator=(MySQL_Result &&other) = delete;
public:
~MySQL_Result();
public:
MYSQL_ROW fetchRow();
MYSQL_FIELD *fetchFields();
my_ulonglong numRows();
my_ulonglong numFields();
private:
MYSQL_RES *result = nullptr;
friend class MySQL_DB;
};
class MySQL_DB
{
public:
MySQL_DB(const std::string &strHost,
const std::string &strUser,
const std::string &strPass,
const std::string &strDB,
const std::string &strSocket = {});
~MySQL_DB();
private:
MySQL_DB(const MySQL_DB &other) = delete;
MySQL_DB(MySQL_DB &&other) = delete;
MySQL_DB &operator=(const MySQL_DB &other) = delete;
MySQL_DB &operator=(MySQL_DB &&other) = delete;
public:
std::unique_ptr<MySQL_Result> query(const char *strQuery, ...);
my_ulonglong insertId();
my_ulonglong affectedRows();
static void libInit();
static void libCleanup();
private:
void connect();
private:
MYSQL *handle = nullptr;
std::string strHost, strUser, strPass, strDB, strSocket;
time_t lastQuery = 0;
};
};
#endif