]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/extra/m_sqlv2.h
Okay, this is getting towards working now. It just needs the API finishing...everythi...
[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         SQLerrorNum Id()
24         {
25                 return id;
26         }
27         
28         SQLerrorNum Id(SQLerrorNum i)
29         {
30                 id = i;
31                 return id;
32         }
33         
34         void Str(const std::string &s)
35         {
36                 str = s;
37         }
38         
39         const char* Str()
40         {
41                 if(str.length())
42                         return str.c_str();
43                 
44                 switch(id)
45                 {
46                         case NO_ERROR:
47                                 return "No error";
48                         case BAD_DBID:
49                                 return "Invalid database ID";
50                         case BAD_CONN:
51                                 return "Invalid connection";
52                         case QSEND_FAIL:
53                                 return "Sending query failed";
54                         default:
55                                 return "Unknown error";                         
56                 }
57         }
58 };
59
60 class SQLrequest : public Request
61 {
62 public:
63         std::string query;
64         std::string dbid;
65         bool pri;
66         unsigned long id;
67         SQLerror error;
68         
69         SQLrequest(Module* s, Module* d, const std::string &q, const std::string &id, bool p = false)
70         : Request(SQLREQID, s, d), query(q), dbid(id), pri(p), id(0)
71         {
72         }       
73 };
74
75 class SQLresult : public Request
76 {
77 public:
78         std::string query;
79         std::string dbid;
80         SQLerror error; 
81
82         SQLresult(Module* s, Module* d)
83         : Request(SQLRESID, s, d)
84         {
85                 
86         }
87         
88         virtual int Rows() = 0;
89 };
90
91 #endif