summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--modules/database/db_sql.cpp39
-rw-r--r--modules/extra/m_mysql.cpp3
2 files changed, 22 insertions, 20 deletions
diff --git a/modules/database/db_sql.cpp b/modules/database/db_sql.cpp
index b7d32c17c..da891e587 100644
--- a/modules/database/db_sql.cpp
+++ b/modules/database/db_sql.cpp
@@ -58,7 +58,6 @@ class DBSQL : public Module, public Pipe
SQLSQLInterface sqlinterface;
Anope::string prefix;
std::set<dynamic_reference<Serializable> > updated_items;
- bool quitting;
void RunBackground(const SQLQuery &q, SQLInterface *iface = NULL)
{
@@ -71,7 +70,7 @@ class DBSQL : public Module, public Pipe
Log() << "db_sql: Unable to execute query, is SQL configured correctly?";
}
}
- else if (!this->quitting)
+ else if (!quitting)
{
if (iface == NULL)
iface = &this->sqlinterface;
@@ -81,7 +80,7 @@ class DBSQL : public Module, public Pipe
this->sql->RunQuery(q);
}
- SQLQuery BuildInsert(const Anope::string &table, const Serialize::Data &data)
+ SQLQuery BuildInsert(const Anope::string &table, unsigned int id, const Serialize::Data &data)
{
if (this->sql)
{
@@ -90,15 +89,16 @@ class DBSQL : public Module, public Pipe
this->RunBackground(create_queries[i]);
}
- Anope::string query_text = "INSERT INTO `" + table + "` (";
+ 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 + "`,";
- query_text.erase(query_text.end() - 1);
- query_text += ") VALUES (";
+ query_text += ",`" + it->first + "`";
+ query_text += ") VALUES (" + stringify(id);
+ for (Serialize::Data::const_iterator it = data.begin(), it_end = data.end(); it != it_end; ++it)
+ query_text += ",@" + it->first + "@";
+ query_text += ") ON DUPLICATE KEY UPDATE ";
for (Serialize::Data::const_iterator it = data.begin(), it_end = data.end(); it != it_end; ++it)
- query_text += "@" + it->first + "@,";
+ query_text += "`" + it->first + "`=VALUES(`" + it->first + "`),";
query_text.erase(query_text.end() - 1);
- query_text += ")";
SQLQuery query(query_text);
for (Serialize::Data::const_iterator it = data.begin(), it_end = data.end(); it != it_end; ++it)
@@ -108,7 +108,7 @@ class DBSQL : public Module, public Pipe
}
public:
- DBSQL(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, DATABASE), sql("", ""), sqlinterface(this), quitting(false)
+ DBSQL(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, DATABASE), sql("", ""), sqlinterface(this)
{
this->SetAuthor("Anope");
@@ -118,12 +118,6 @@ class DBSQL : public Module, public Pipe
this->OnReload();
}
- ~DBSQL()
- {
- this->quitting = true;
- this->OnNotify();
- }
-
void OnNotify() anope_override
{
for (std::set<dynamic_reference<Serializable> >::iterator it = this->updated_items.begin(), it_end = this->updated_items.end(); it != it_end; ++it)
@@ -136,7 +130,7 @@ class DBSQL : public Module, public Pipe
continue;
obj->UpdateCache();
- SQLQuery insert = this->BuildInsert(this->prefix + obj->serialize_name(), obj->serialize());
+ SQLQuery insert = this->BuildInsert(this->prefix + obj->serialize_name(), obj->id, obj->serialize());
this->RunBackground(insert, new ResultSQLSQLInterface(this, obj));
}
}
@@ -176,7 +170,16 @@ class DBSQL : public Module, public Pipe
for (std::map<Anope::string, Anope::string>::const_iterator rit = row.begin(), rit_end = row.end(); rit != rit_end; ++rit)
data[rit->first] << rit->second;
- sb->Unserialize(NULL, data);
+ Serializable *obj = sb->Unserialize(NULL, data);
+ try
+ {
+ if (obj)
+ obj->id = convertTo<unsigned int>(res.Get(j, "id"));
+ }
+ catch (const ConvertException &)
+ {
+ Log() << "db_sql: Unable to convert id for object #" << j << " of type " << sb->GetName();
+ }
}
}
diff --git a/modules/extra/m_mysql.cpp b/modules/extra/m_mysql.cpp
index b5f0e4406..8a7c21e64 100644
--- a/modules/extra/m_mysql.cpp
+++ b/modules/extra/m_mysql.cpp
@@ -53,7 +53,7 @@ class MySQLResult : public SQLResult
{
unsigned num_fields = res ? mysql_num_fields(res) : 0;
- Log(LOG_DEBUG) << "SQL query " << this->finished_query << " returned " << num_fields << " fields";
+ /* It is not thread safe to log anything here using Log() now :( */
if (!num_fields)
return;
@@ -68,7 +68,6 @@ class MySQLResult : public SQLResult
for (unsigned field_count = 0; field_count < num_fields; ++field_count)
{
- Log(LOG_DEBUG) << "Field count " << field_count << " name is: " << (fields[field_count].name ? fields[field_count].name : "") << ", data is: " << (row[field_count] ? row[field_count] : "");
Anope::string column = (fields[field_count].name ? fields[field_count].name : "");
Anope::string data = (row[field_count] ? row[field_count] : "");