summaryrefslogtreecommitdiff
path: root/src/modules/extra/m_sql.cpp
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2005-04-21 12:01:35 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2005-04-21 12:01:35 +0000
commitf7a0c180d8d6dc4618b53892c04ca7af64e0841e (patch)
tree706f0e0078aebc949b8c04a7f60895a307d50578 /src/modules/extra/m_sql.cpp
parentb973cb4a05ae940d3ae098eb01f54f89acf1e631 (diff)
Added header for m_sql with inherited Request class
Added simple API for m_sql git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@1149 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/modules/extra/m_sql.cpp')
-rw-r--r--src/modules/extra/m_sql.cpp66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/modules/extra/m_sql.cpp b/src/modules/extra/m_sql.cpp
index f7df3c27e..489f2ddd4 100644
--- a/src/modules/extra/m_sql.cpp
+++ b/src/modules/extra/m_sql.cpp
@@ -21,6 +21,7 @@
#include "users.h"
#include "channels.h"
#include "modules.h"
+#include "m_sql.h"
/* $ModDesc: m_filter with regexps */
/* $CompileFlags: -I/usr/local/include -I/usr/include -L/usr/local/lib/mysql -L/usr/lib/mysql -lmysqlclient */
@@ -215,6 +216,71 @@ class ModuleSQL : public Module
ConnectDatabases();
}
+ void ResultType(SQLRequest *r, SQLResult *res)
+ {
+ for (ConnectionList::iterator i = Connections.begin(); i != Connections.end(); i++)
+ {
+ if ((i->GetID() == r->GetConnID()) && (i->Enabled()))
+ {
+ bool xr = i->QueryResult(r->GetQuery());
+ if (!xr)
+ {
+ res->SetType(SQL_ERROR);
+ res->SetError(r->GetError());
+ return;
+ }
+ }
+ }
+ }
+
+ void CountType(SQLRequest *r, SQLResult* res)
+ {
+ for (ConnectionList::iterator i = Connections.begin(); i != Connections.end(); i++)
+ {
+ if ((i->GetID() == r->GetConnID()) && (i->Enabled()))
+ {
+ res->SetType(SQL_COUNT);
+ res->SetCount(i->QueryCount(r->GetQuery()));
+ return;
+ }
+ }
+ }
+
+ void RowType(SQLRequest *r, SQLResult* res)
+ {
+ for (ConnectionList::iterator i = Connections.begin(); i != Connections.end(); i++)
+ {
+ if ((i->GetID() == r->GetConnID()) && (i->Enabled()))
+ {
+ std::map<std::string,std::string> row = i->GetRow();
+ res->SetRow(row);
+ res->SetType(SQL_ROW);
+ if (!row.size())
+ res->SetType(SQL_END);
+ return;
+ }
+ }
+ }
+
+ char* OnRequest(Request* request)
+ {
+ SQLResult Result = new SQLResult();
+ SQLRequest *r = (SQLRequest*)request;
+ switch (r->GetRequest())
+ {
+ case SQL_RESULT:
+ ResultType(r,Result);
+ break;
+ case SQL_COUNT:
+ CountType(r,Result);
+ break;
+ case SQL_ROW:
+ RowType(r,Result);
+ break;
+ }
+ return Result;
+ }
+
ModuleSQL()
{
Srv = new Server();