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
86
87
88
89
90
91
|
#ifndef INSPIRCD_SQLAPI_2
#define INSPIRCD_SQLAPI_2
#define SQLREQID "SQLv2 Request"
#define SQLRESID "SQLv2 Result"
#define SQLSUCCESS "You shouldn't be reading this (success)"
#include <string>
#include "modules.h"
enum SQLerrorNum { NO_ERROR, BAD_DBID, BAD_CONN, QSEND_FAIL };
class SQLerror : public classbase
{
SQLerrorNum id;
std::string str;
public:
SQLerror(SQLerrorNum i = NO_ERROR, const std::string &s = "")
: id(i), str(s)
{
}
SQLerrorNum Id()
{
return id;
}
SQLerrorNum Id(SQLerrorNum i)
{
id = i;
return id;
}
void Str(const std::string &s)
{
str = s;
}
const char* Str()
{
if(str.length())
return str.c_str();
switch(id)
{
case NO_ERROR:
return "No error";
case BAD_DBID:
return "Invalid database ID";
case BAD_CONN:
return "Invalid connection";
case QSEND_FAIL:
return "Sending query failed";
default:
return "Unknown error";
}
}
};
class SQLrequest : public Request
{
public:
std::string query;
std::string dbid;
bool pri;
unsigned long id;
SQLerror error;
SQLrequest(Module* s, Module* d, const std::string &q, const std::string &id, bool p = false)
: Request(SQLREQID, s, d), query(q), dbid(id), pri(p), id(0)
{
}
};
class SQLresult : public Request
{
public:
std::string query;
std::string dbid;
SQLerror error;
SQLresult(Module* s, Module* d)
: Request(SQLRESID, s, d)
{
}
virtual int Rows() = 0;
};
#endif
|