summaryrefslogtreecommitdiff
path: root/modules/extra
diff options
context:
space:
mode:
Diffstat (limited to 'modules/extra')
-rw-r--r--modules/extra/m_mysql.cpp10
-rw-r--r--modules/extra/m_sqlite.cpp10
-rw-r--r--modules/extra/sql.h2
3 files changed, 17 insertions, 5 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 + "`";
diff --git a/modules/extra/m_sqlite.cpp b/modules/extra/m_sqlite.cpp
index 136e9d0dc..3df0a25d9 100644
--- a/modules/extra/m_sqlite.cpp
+++ b/modules/extra/m_sqlite.cpp
@@ -48,7 +48,7 @@ class SQLiteService : 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);
@@ -253,8 +253,14 @@ std::vector<SQLQuery> SQLiteService::CreateTable(const Anope::string &table, con
return queries;
}
-SQLQuery SQLiteService::BuildInsert(const Anope::string &table, unsigned int id, const Serialize::Data &data)
+SQLQuery SQLiteService::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 = "REPLACE INTO `" + table + "` (";
if (id > 0)
query_text += "`id`,";
diff --git a/modules/extra/sql.h b/modules/extra/sql.h
index 7e10c7150..89686bfe8 100644
--- a/modules/extra/sql.h
+++ b/modules/extra/sql.h
@@ -130,7 +130,7 @@ class SQLProvider : public Service
virtual std::vector<SQLQuery> CreateTable(const Anope::string &table, const Serialize::Data &data) = 0;
- virtual SQLQuery BuildInsert(const Anope::string &table, unsigned int id, const Serialize::Data &data) = 0;
+ virtual SQLQuery BuildInsert(const Anope::string &table, unsigned int id, Serialize::Data &data) = 0;
virtual SQLQuery GetTables(const Anope::string &prefix) = 0;