]> granicus.if.org Git - icinga2/blob - lib/mysql_shim/mysqlinterface.hpp
Merge pull request #7185 from Icinga/bugfix/gelfwriter-wrong-log-facility
[icinga2] / lib / mysql_shim / mysqlinterface.hpp
1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
2
3 #ifndef MYSQLINTERFACE_H
4 #define MYSQLINTERFACE_H
5
6 #include "mysql_shim/mysql_shim_export.h"
7 #include <memory>
8 #include <mysql.h>
9
10 namespace icinga
11 {
12
13 struct MysqlInterface
14 {
15         MysqlInterface(const MysqlInterface&) = delete;
16         MysqlInterface& operator=(MysqlInterface&) = delete;
17
18         virtual void Destroy() = 0;
19
20         virtual my_ulonglong affected_rows(MYSQL *mysql) const = 0;
21         virtual void close(MYSQL *sock) const = 0;
22         virtual const char *error(MYSQL *mysql) const = 0;
23         virtual MYSQL_FIELD *fetch_field(MYSQL_RES *result) const = 0;
24         virtual unsigned long *fetch_lengths(MYSQL_RES *result) const = 0;
25         virtual MYSQL_ROW fetch_row(MYSQL_RES *result) const = 0;
26         virtual unsigned int field_count(MYSQL *mysql) const = 0;
27         virtual MYSQL_FIELD_OFFSET field_seek(MYSQL_RES *result,
28                 MYSQL_FIELD_OFFSET offset) const = 0;
29         virtual void free_result(MYSQL_RES *result) const = 0;
30         virtual MYSQL *init(MYSQL *mysql) const = 0;
31         virtual my_ulonglong insert_id(MYSQL *mysql) const = 0;
32         virtual int next_result(MYSQL *mysql) const = 0;
33         virtual int ping(MYSQL *mysql) const = 0;
34         virtual int query(MYSQL *mysql, const char *q) const = 0;
35         virtual MYSQL *real_connect(MYSQL *mysql, const char *host, const char *user, const char *passwd,
36                 const char *db, unsigned int port, const char *unix_socket, unsigned long clientflag) const = 0;
37         virtual unsigned long real_escape_string(MYSQL *mysql, char *to, const char *from, unsigned long length) const = 0;
38         virtual bool ssl_set(MYSQL *mysql, const char *key, const char *cert, const char *ca, const char *capath, const char *cipher) const = 0;
39         virtual MYSQL_RES *store_result(MYSQL *mysql) const = 0;
40         virtual unsigned int thread_safe() const = 0;
41
42 protected:
43         MysqlInterface() = default;
44         ~MysqlInterface() = default;
45 };
46
47 struct MysqlInterfaceDeleter
48 {
49         void operator()(MysqlInterface *ifc) const
50         {
51                 ifc->Destroy();
52         }
53 };
54
55 }
56
57 extern "C"
58 {
59         MYSQL_SHIM_EXPORT icinga::MysqlInterface *create_mysql_shim();
60 }
61
62 typedef icinga::MysqlInterface *(*create_mysql_shim_ptr)();
63
64 #endif /* MYSQLINTERFACE_H */