mirror of
https://github.com/anope/anope.git
synced 2026-06-23 07:06:38 +02:00
Pull table schemas from SQL on startup so we can alter the schemas if we need to, fixed sqlite to work again
This commit is contained in:
@@ -80,33 +80,6 @@ class DBSQL : public Module, public Pipe
|
||||
this->sql->RunQuery(q);
|
||||
}
|
||||
|
||||
SQLQuery BuildInsert(const Anope::string &table, unsigned int id, const Serialize::Data &data)
|
||||
{
|
||||
if (this->sql)
|
||||
{
|
||||
std::vector<SQLQuery> create_queries = this->sql->CreateTable(table, data);
|
||||
for (unsigned i = 0; i < create_queries.size(); ++i)
|
||||
this->RunBackground(create_queries[i]);
|
||||
}
|
||||
|
||||
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 += ") 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 + "`=VALUES(`" + it->first + "`),";
|
||||
query_text.erase(query_text.end() - 1);
|
||||
|
||||
SQLQuery query(query_text);
|
||||
for (Serialize::Data::const_iterator it = data.begin(), it_end = data.end(); it != it_end; ++it)
|
||||
query.setValue(it->first, it->second.astr());
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
public:
|
||||
DBSQL(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, DATABASE), sql("", ""), sqlinterface(this)
|
||||
{
|
||||
@@ -124,13 +97,20 @@ class DBSQL : public Module, public Pipe
|
||||
{
|
||||
dynamic_reference<Serializable> obj = *it;
|
||||
|
||||
if (obj)
|
||||
if (obj && this->sql)
|
||||
{
|
||||
if (obj->IsCached())
|
||||
continue;
|
||||
obj->UpdateCache();
|
||||
|
||||
SQLQuery insert = this->BuildInsert(this->prefix + obj->serialize_name(), obj->id, obj->serialize());
|
||||
const Serialize::Data &data = obj->serialize();
|
||||
|
||||
std::vector<SQLQuery> create = this->sql->CreateTable(this->prefix + obj->serialize_name(), data);
|
||||
for (unsigned i = 0; i < create.size(); ++i)
|
||||
this->RunBackground(create[i]);
|
||||
|
||||
|
||||
SQLQuery insert = this->sql->BuildInsert(this->prefix + obj->serialize_name(), obj->id, data);
|
||||
this->RunBackground(insert, new ResultSQLSQLInterface(this, obj));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user