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