From 484160eb4ed560eeda97c94a42dd8e31431ab251 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Wed, 24 Jan 2024 12:34:03 +0000 Subject: Shuffle modules around a bit. --- modules/irc2sql/utils.cpp | 68 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 modules/irc2sql/utils.cpp (limited to 'modules/irc2sql/utils.cpp') diff --git a/modules/irc2sql/utils.cpp b/modules/irc2sql/utils.cpp new file mode 100644 index 000000000..9c260fcaa --- /dev/null +++ b/modules/irc2sql/utils.cpp @@ -0,0 +1,68 @@ +/* + * + * (C) 2013-2024 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +#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 &map = r.Row(i); + for (std::map::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::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::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::const_iterator it = EventList.begin(); it != EventList.end(); ++it) + if (*it == table) + return true; + return false; +} -- cgit