]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/extra/m_sql.h
768551bf394edca62a11318cbc27537f09202f4d
[user/henk/code/inspircd.git] / src / modules / extra / m_sql.h
1 #ifndef __M_SQL_H__
2 #define __M_SQL_H__
3
4 #include <string>
5 #include <vector>
6
7 #define SQL_RESULT 1
8 #define SQL_COUNT  2
9 #define SQL_ROW    3
10 #define SQL_ERROR  4
11 #define SQL_END    5
12
13 // SQLRequest is inherited from a basic Request object
14 // so that we can neatly pass information around the
15 // system.
16
17 class SQLRequest : public Request
18 {
19  protected:
20         long conn_id;
21         int request_type;
22         std::string thisquery;
23  public:
24         void SetConnID(long id)
25         {
26                 conn_id = id;
27         }
28
29         long GetConnID(long id)
30         {
31                 return conn_id;
32         }
33
34         void SetQueryType(int t)
35         {
36                 request_type = t;
37         }
38
39         int GetQueryType(int t)
40         {
41                 return request_type;
42         }
43
44         void SetQuery(std::string query)
45         {
46                 thisquery = query;
47         }
48
49         std::string GetQuery()
50         {
51                 return thisquery;
52         }
53 };
54
55 // Upon completion, an SQLRequest returns an SQLResponse.
56
57 class SQLResponse
58 {
59  protected:
60         int resptype;
61         unsigned long count;
62         std::string error;
63         std::map<std::string,std::string> row;
64  public:
65         void SetRow(std::map<std::string,std::string> r)
66         {
67                 row = r;
68         }
69
70         std::string GetField(std::string field)
71         {
72                 std::map<std::string,std::string>::iterator iter = row.find(field);
73                 if (iter == row.end()) return "";
74                 return iter->second;
75         }
76
77         void SetType(int rt)
78         {
79                 resptype = rt;
80         }
81
82         void SetError(std::string err)
83         {
84                 error = err;
85         }
86
87         int GetType()
88         {
89                 return restype;
90         }
91
92         std::string GetError()
93         {
94                 return error;
95         }
96
97         void SetCount(unsigned long c)
98         {
99                 count = c;
100         }
101
102         unsigned long GetCount()
103         {
104                 return count;
105         }
106 };
107
108 #endif