summaryrefslogtreecommitdiff
path: root/src/modules/extra/m_sqlv2.h
blob: 5faa76cc2c2102c19cd8f34d6c6b5507e2133899 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#ifndef INSPIRCD_SQLAPI_2
#define INSPIRCD_SQLAPI_2

#define SQLREQID "SQLv2 Request"
#define SQLRESID "SQLv2 Result"
#define SQLSUCCESS "You shouldn't be reading this (success)"

#include <string>
#include "modules.h"

enum SQLerrorNum { NO_ERROR, BAD_DBID, BAD_CONN, QSEND_FAIL };

class SQLerror
{
	SQLerrorNum id;
	std::string str;
public:
	SQLerror(SQLerrorNum i = NO_ERROR, const std::string &s = "")
	: id(i), str(s)
	{	
	}
	
	void Id(SQLerrorNum i)
	{
		id = i;
	}
	
	void Str(const std::string &s)
	{
		str = s;
	}
	
	const char* Str()
	{
		if(str.length())
			return str.c_str();
		
		switch(id)
		{
			case NO_ERROR:
				return "No error";
			case BAD_DBID:
				return "Invalid database ID";
			case BAD_CONN:
				return "Invalid connection";
			case QSEND_FAIL:
				return "Sending query failed";
			default:
				return "Unknown error";				
		}
	}
};

class SQLrequest : public Request
{
public:
	std::string query;
	std::string dbid;
	bool pri;
	SQLerror error;
	
	SQLrequest(Module* s, Module* d, const std::string &q, const std::string &id, bool p = false)
	: Request(SQLREQID, s, d), query(q), dbid(id), pri(p)
	{
	}	
};

class SQLresult : public Request
{
	
public:
	SQLresult(Module* s, Module* d)
	: Request(SQLRESID, s, d)
	{
		
	}
	
	virtual int Rows()
	{
		return 0;
	}
};

#endif