diff options
author | Adam <Adam@anope.org> | 2012-09-30 20:26:40 -0400 |
---|---|---|
committer | Adam <Adam@anope.org> | 2012-09-30 20:30:27 -0400 |
commit | ad37bc9639304f78247d03e6a27fbc2c798926da (patch) | |
tree | 5ce4ddee3a761372069d02f28197e7ff9a009246 /modules/extra/m_mysql.cpp | |
parent | 56df1abdd89638355edcd65ff6f11f917bf63e5f (diff) |
Bug #1445 - Empty out columns in SQL we have no data for on
insert. This is caused from serialize() only setting a key on
certain conditions and otherwise doing nothing at all.
Diffstat (limited to 'modules/extra/m_mysql.cpp')
-rw-r--r-- | modules/extra/m_mysql.cpp | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/modules/extra/m_mysql.cpp b/modules/extra/m_mysql.cpp index 1e5ba79cf..6429b39ef 100644 --- a/modules/extra/m_mysql.cpp +++ b/modules/extra/m_mysql.cpp @@ -126,7 +126,7 @@ class MySQLService : public SQLProvider std::vector<SQLQuery> CreateTable(const Anope::string &table, const Serialize::Data &data) anope_override; - SQLQuery BuildInsert(const Anope::string &table, unsigned int id, const Serialize::Data &data); + SQLQuery BuildInsert(const Anope::string &table, unsigned int id, Serialize::Data &data); SQLQuery GetTables(const Anope::string &prefix) anope_override; @@ -408,8 +408,14 @@ std::vector<SQLQuery> MySQLService::CreateTable(const Anope::string &table, cons return queries; } -SQLQuery MySQLService::BuildInsert(const Anope::string &table, unsigned int id, const Serialize::Data &data) +SQLQuery MySQLService::BuildInsert(const Anope::string &table, unsigned int id, Serialize::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" && data.count(*it) == 0) + data[*it] << ""; + Anope::string query_text = "INSERT INTO `" + table + "` (`id`"; for (Serialize::Data::const_iterator it = data.begin(), it_end = data.end(); it != it_end; ++it) query_text += ",`" + it->first + "`"; |