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