]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_testclient.cpp
This module isn't supposed to be part of 2.0; it will be third-party until 2.1
[user/henk/code/inspircd.git] / src / modules / m_testclient.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2010 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15 #include "m_sqlv2.h"
16
17 class ModuleTestClient : public Module
18 {
19 private:
20
21
22 public:
23         ModuleTestClient()
24         {
25                 Implementation eventlist[] = { I_OnBackgroundTimer };
26                 ServerInstance->Modules->Attach(eventlist, this, 1);
27         }
28
29
30         virtual Version GetVersion()
31         {
32                 return Version("SQL test module", VF_VENDOR);
33         }
34
35         virtual void OnBackgroundTimer(time_t)
36         {
37                 ServiceProvider* prov = ServerInstance->Modules->FindService(SERVICE_DATA, "SQL");
38                 if (!prov)
39                         return;
40                 Module* target = prov->creator;
41
42                 if(target)
43                 {
44                         SQLrequest foo = SQLrequest(this, target, "foo",
45                                         SQLquery("UPDATE rawr SET foo = '?' WHERE bar = 42") % ServerInstance->Time());
46
47                         foo.Send();
48                         if (foo.cancel)
49                         {
50                                 ServerInstance->Logs->Log("m_testclient.so", DEBUG, "SQLrequest failed: %s", foo.error.Str());
51                         }
52                         else
53                         {
54                                 ServerInstance->Logs->Log("m_testclient.so", DEBUG, "Sent query, got given ID %lu", foo.id);
55                         }
56                 }
57         }
58
59         void OnRequest(Request& request)
60         {
61                 if(strcmp(SQLRESID, request.id) == 0)
62                 {
63                         ServerInstance->Logs->Log("m_testclient.so", DEBUG, "Got SQL result (%s)", request.id);
64
65                         SQLresult* res = (SQLresult*)&request;
66
67                         if (res->error.Id() == SQL_NO_ERROR)
68                         {
69                                 if(res->Cols())
70                                 {
71                                         ServerInstance->Logs->Log("m_testclient.so", DEBUG, "Got result with %d rows and %d columns", res->Rows(), res->Cols());
72
73                                         for (int r = 0; r < res->Rows(); r++)
74                                         {
75                                                 ServerInstance->Logs->Log("m_testclient.so", DEBUG, "Row %d:", r);
76
77                                                 for(int i = 0; i < res->Cols(); i++)
78                                                 {
79                                                         ServerInstance->Logs->Log("m_testclient.so", DEBUG, "\t[%s]: %s", res->ColName(i).c_str(), res->GetValue(r, i).d.c_str());
80                                                 }
81                                         }
82                                 }
83                                 else
84                                 {
85                                         ServerInstance->Logs->Log("m_testclient.so", DEBUG, "%d rows affected in query", res->Rows());
86                                 }
87                         }
88                         else
89                         {
90                                 ServerInstance->Logs->Log("m_testclient.so", DEBUG, "SQLrequest failed: %s", res->error.Str());
91                         }
92                 }
93
94                 ServerInstance->Logs->Log("m_testclient.so", DEBUG, "Got unsupported API version string: %s", request.id);
95         }
96
97         virtual ~ModuleTestClient()
98         {
99         }
100 };
101
102 MODULE_INIT(ModuleTestClient)
103