diff options
author | Adam <Adam@anope.org> | 2014-01-03 19:54:14 -0500 |
---|---|---|
committer | Adam <Adam@anope.org> | 2014-01-03 19:54:14 -0500 |
commit | e1ce6174cee90b71dc461be39d2bf20965ff69e0 (patch) | |
tree | 6f8788ab40a533f3ae791f30cfe4a1f94fadf193 /modules/extra/stats/irc2sql/utils.cpp | |
parent | 2781b6946daa82b88b08cdd6ab3c6478f7c70aa1 (diff) |
Move modules/stats under extras because it depends on m_mysql, update its config a bit to look similar to all of the other config files
Diffstat (limited to 'modules/extra/stats/irc2sql/utils.cpp')
-rw-r--r-- | modules/extra/stats/irc2sql/utils.cpp | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/modules/extra/stats/irc2sql/utils.cpp b/modules/extra/stats/irc2sql/utils.cpp new file mode 100644 index 000000000..0c35b13fa --- /dev/null +++ b/modules/extra/stats/irc2sql/utils.cpp @@ -0,0 +1,61 @@ +#include "irc2sql.h" + +void IRC2SQL::RunQuery(const SQL::Query &q) +{ + if (sql) + sql->Run(&sqlinterface, q); +} + +void IRC2SQL::GetTables() +{ + TableList.clear(); + ProcedureList.clear(); + EventList.clear(); + if (!sql) + return; + + SQL::Result r = this->sql->RunQuery(this->sql->GetTables(prefix)); + for (int i = 0; i < r.Rows(); ++i) + { + const std::map<Anope::string, Anope::string> &map = r.Row(i); + for (std::map<Anope::string, Anope::string>::const_iterator it = map.begin(); it != map.end(); ++it) + TableList.push_back(it->second); + } + query = "SHOW PROCEDURE STATUS WHERE `Db` = Database();"; + r = this->sql->RunQuery(query); + for (int i = 0; i < r.Rows(); ++i) + { + ProcedureList.push_back(r.Get(i, "Name")); + } + query = "SHOW EVENTS WHERE `Db` = Database();"; + r = this->sql->RunQuery(query); + for (int i = 0; i < r.Rows(); ++i) + { + EventList.push_back(r.Get(i, "Name")); + } +} + +bool IRC2SQL::HasTable(const Anope::string &table) +{ + for (std::vector<Anope::string>::const_iterator it = TableList.begin(); it != TableList.end(); ++it) + if (*it == table) + return true; + return false; +} + +bool IRC2SQL::HasProcedure(const Anope::string &table) +{ + for (std::vector<Anope::string>::const_iterator it = ProcedureList.begin(); it != ProcedureList.end(); ++it) + if (*it == table) + return true; + return false; +} + +bool IRC2SQL::HasEvent(const Anope::string &table) +{ + for (std::vector<Anope::string>::const_iterator it = EventList.begin(); it != EventList.end(); ++it) + if (*it == table) + return true; + return false; +} + |