Anope IRC Services  Version 2.0
utils.cpp
Go to the documentation of this file.
1 #include "irc2sql.h"
2 
4 {
5  if (sql)
6  sql->Run(&sqlinterface, q);
7 }
8 
10 {
11  TableList.clear();
12  ProcedureList.clear();
13  EventList.clear();
14  if (!sql)
15  return;
16 
17  SQL::Result r = this->sql->RunQuery(this->sql->GetTables(prefix));
18  for (int i = 0; i < r.Rows(); ++i)
19  {
20  const std::map<Anope::string, Anope::string> &map = r.Row(i);
21  for (std::map<Anope::string, Anope::string>::const_iterator it = map.begin(); it != map.end(); ++it)
22  TableList.push_back(it->second);
23  }
24  query = "SHOW PROCEDURE STATUS WHERE `Db` = Database();";
25  r = this->sql->RunQuery(query);
26  for (int i = 0; i < r.Rows(); ++i)
27  {
28  ProcedureList.push_back(r.Get(i, "Name"));
29  }
30  query = "SHOW EVENTS WHERE `Db` = Database();";
31  r = this->sql->RunQuery(query);
32  for (int i = 0; i < r.Rows(); ++i)
33  {
34  EventList.push_back(r.Get(i, "Name"));
35  }
36 }
37 
38 bool IRC2SQL::HasTable(const Anope::string &table)
39 {
40  for (std::vector<Anope::string>::const_iterator it = TableList.begin(); it != TableList.end(); ++it)
41  if (*it == table)
42  return true;
43  return false;
44 }
45 
47 {
48  for (std::vector<Anope::string>::const_iterator it = ProcedureList.begin(); it != ProcedureList.end(); ++it)
49  if (*it == table)
50  return true;
51  return false;
52 }
53 
54 bool IRC2SQL::HasEvent(const Anope::string &table)
55 {
56  for (std::vector<Anope::string>::const_iterator it = EventList.begin(); it != EventList.end(); ++it)
57  if (*it == table)
58  return true;
59  return false;
60 }
61 
const std::map< Anope::string, Anope::string > & Row(size_t index) const
Definition: sql.h:157
std::vector< Anope::string > EventList
Definition: irc2sql.h:27
Anope::string prefix
Definition: irc2sql.h:28
MySQLInterface sqlinterface
Definition: irc2sql.h:25
std::vector< Anope::string > ProcedureList
Definition: irc2sql.h:27
ServiceReference< SQL::Provider > sql
Definition: irc2sql.h:24
Definition: sql.h:96
bool HasEvent(const Anope::string &table)
Definition: utils.cpp:54
SQL::Query query
Definition: irc2sql.h:26
bool HasProcedure(const Anope::string &table)
Definition: utils.cpp:46
std::vector< Anope::string > TableList
Definition: irc2sql.h:27
bool HasTable(const Anope::string &table)
Definition: utils.cpp:38
void RunQuery(const SQL::Query &q)
Definition: utils.cpp:3
void GetTables()
Definition: utils.cpp:9
int Rows() const
Definition: sql.h:155
const Anope::string Get(size_t index, const Anope::string &col) const
Definition: sql.h:169