]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/extra/m_sqlv2.h
XHTML 1.1 spec validation and charset
[user/henk/code/inspircd.git] / src / modules / extra / m_sqlv2.h
1 #ifndef INSPIRCD_SQLAPI_2
2 #define INSPIRCD_SQLAPI_2
3
4 #define SQLREQID "SQLv2 Request"
5 #define SQLRESID "SQLv2 Result"
6 #define SQLSUCCESS "You shouldn't be reading this (success)"
7
8 #include <string>
9 #include "modules.h"
10
11 enum SQLerrorNum { NO_ERROR, BAD_DBID, BAD_CONN, QSEND_FAIL };
12
13 class SQLerror : public classbase
14 {
15         SQLerrorNum id;
16         std::string str;
17 public:
18         SQLerror(SQLerrorNum i = NO_ERROR, const std::string &s = "")
19         : id(i), str(s)
20         {       
21         }
22         
23         void Id(SQLerrorNum i)
24         {
25                 id = i;
26         }
27         
28         void Str(const std::string &s)
29         {
30                 str = s;
31         }
32         
33         const char* Str()
34         {
35                 if(str.length())
36                         return str.c_str();
37                 
38                 switch(id)
39                 {
40                         case NO_ERROR:
41                                 return "No error";
42                         case BAD_DBID:
43                                 return "Invalid database ID";
44                         case BAD_CONN:
45                                 return "Invalid connection";
46                         case QSEND_FAIL:
47                                 return "Sending query failed";
48                         default:
49                                 return "Unknown error";                         
50                 }
51         }
52 };
53
54 class SQLrequest : public Request
55 {
56 public:
57         std::string query;
58         std::string dbid;
59         bool pri;
60         SQLerror error;
61         
62         SQLrequest(Module* s, Module* d, const std::string &q, const std::string &id, bool p = false)
63         : Request(SQLREQID, s, d), query(q), dbid(id), pri(p)
64         {
65         }       
66 };
67
68 class SQLresult : public Request
69 {
70         
71 public:
72         SQLresult(Module* s, Module* d)
73         : Request(SQLRESID, s, d)
74         {
75                 
76         }
77         
78         virtual int Rows()
79         {
80                 return 0;
81         }
82 };
83
84 #endif