summaryrefslogtreecommitdiff
path: root/modules/extra/m_mysql.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'modules/extra/m_mysql.cpp')
-rw-r--r--modules/extra/m_mysql.cpp56
1 files changed, 29 insertions, 27 deletions
diff --git a/modules/extra/m_mysql.cpp b/modules/extra/m_mysql.cpp
index 83fc3b73e..0ec7f8989 100644
--- a/modules/extra/m_mysql.cpp
+++ b/modules/extra/m_mysql.cpp
@@ -284,10 +284,8 @@ class ModuleSQL : public Module, public Pipe
this->FinishedRequests.clear();
this->DThread->Unlock();
- for (std::deque<QueryResult>::const_iterator it = finishedRequests.begin(), it_end = finishedRequests.end(); it != it_end; ++it)
+ for (const auto &qr : finishedRequests)
{
- const QueryResult &qr = *it;
-
if (!qr.sqlinterface)
throw SQL::Exception("NULL qr.sqlinterface in MySQLPipe::OnNotify() ?");
@@ -389,12 +387,12 @@ std::vector<Query> MySQLService::CreateTable(const Anope::string &table, const D
{
Anope::string query_text = "CREATE TABLE `" + table + "` (`id` int(10) unsigned NOT NULL AUTO_INCREMENT,"
" `timestamp` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP";
- for (Data::Map::const_iterator it = data.data.begin(), it_end = data.data.end(); it != it_end; ++it)
+ for (const auto &[column, _] : data.data)
{
- known_cols.insert(it->first);
+ known_cols.insert(column);
- query_text += ", `" + it->first + "` ";
- if (data.GetType(it->first) == Serialize::Data::DT_INT)
+ query_text += ", `" + column + "` ";
+ if (data.GetType(column) == Serialize::Data::DT_INT)
query_text += "int(11)";
else
query_text += "text";
@@ -403,21 +401,23 @@ std::vector<Query> MySQLService::CreateTable(const Anope::string &table, const D
queries.push_back(query_text);
}
else
- for (Data::Map::const_iterator it = data.data.begin(), it_end = data.data.end(); it != it_end; ++it)
+ {
+ for (const auto &[column, _] : data.data)
{
- if (known_cols.count(it->first) > 0)
+ if (known_cols.count(column) > 0)
continue;
- known_cols.insert(it->first);
+ known_cols.insert(column);
- Anope::string query_text = "ALTER TABLE `" + table + "` ADD `" + it->first + "` ";
- if (data.GetType(it->first) == Serialize::Data::DT_INT)
+ Anope::string query_text = "ALTER TABLE `" + table + "` ADD `" + column + "` ";
+ if (data.GetType(column) == Serialize::Data::DT_INT)
query_text += "int(11)";
else
query_text += "text";
queries.push_back(query_text);
}
+ }
return queries;
}
@@ -425,27 +425,29 @@ std::vector<Query> MySQLService::CreateTable(const Anope::string &table, const D
Query MySQLService::BuildInsert(const Anope::string &table, unsigned int id, Data &data)
{
/* Empty columns not present in the data set */
- const std::set<Anope::string> &known_cols = this->active_schema[table];
- for (std::set<Anope::string>::iterator it = known_cols.begin(), it_end = known_cols.end(); it != it_end; ++it)
- if (*it != "id" && *it != "timestamp" && data.data.count(*it) == 0)
- data[*it] << "";
+ for (const auto &known_col : this->active_schema[table])
+ {
+ if (known_col != "id" && known_col != "timestamp" && data.data.count(known_col) == 0)
+ data[known_col] << "";
+ }
Anope::string query_text = "INSERT INTO `" + table + "` (`id`";
- for (Data::Map::const_iterator it = data.data.begin(), it_end = data.data.end(); it != it_end; ++it)
- query_text += ",`" + it->first + "`";
+
+ for (const auto &[field, _] : data.data)
+ query_text += ",`" + field + "`";
query_text += ") VALUES (" + stringify(id);
- for (Data::Map::const_iterator it = data.data.begin(), it_end = data.data.end(); it != it_end; ++it)
- query_text += ",@" + it->first + "@";
+ for (const auto &[field, _] : data.data)
+ query_text += ",@" + field + "@";
query_text += ") ON DUPLICATE KEY UPDATE ";
- for (Data::Map::const_iterator it = data.data.begin(), it_end = data.data.end(); it != it_end; ++it)
- query_text += "`" + it->first + "`=VALUES(`" + it->first + "`),";
+ for (const auto &[field, _] : data.data)
+ query_text += "`" + field + "`=VALUES(`" + field + "`),";
query_text.erase(query_text.end() - 1);
Query query(query_text);
- for (Data::Map::const_iterator it = data.data.begin(), it_end = data.data.end(); it != it_end; ++it)
+ for (auto &[field, value] : data.data)
{
Anope::string buf;
- *it->second >> buf;
+ *value >> buf;
bool escape = true;
if (buf.empty())
@@ -454,7 +456,7 @@ Query MySQLService::BuildInsert(const Anope::string &table, unsigned int id, Dat
escape = false;
}
- query.SetValue(it->first, buf, escape);
+ query.SetValue(field, buf, escape);
}
return query;
@@ -509,8 +511,8 @@ Anope::string MySQLService::BuildQuery(const Query &q)
{
Anope::string real_query = q.query;
- for (std::map<Anope::string, QueryData>::const_iterator it = q.parameters.begin(), it_end = q.parameters.end(); it != it_end; ++it)
- real_query = real_query.replace_all_cs("@" + it->first + "@", (it->second.escape ? ("'" + this->Escape(it->second.data) + "'") : it->second.data));
+ for (const auto &[name, value] : q.parameters)
+ real_query = real_query.replace_all_cs("@" + name + "@", (value.escape ? ("'" + this->Escape(value.data) + "'") : value.data));
return real_query;
}