summaryrefslogtreecommitdiff
path: root/modules/database
diff options
context:
space:
mode:
Diffstat (limited to 'modules/database')
-rw-r--r--modules/database/db_flatfile.cpp22
-rw-r--r--modules/database/db_sql.cpp16
2 files changed, 30 insertions, 8 deletions
diff --git a/modules/database/db_flatfile.cpp b/modules/database/db_flatfile.cpp
index 09fde3242..a7e65f1cb 100644
--- a/modules/database/db_flatfile.cpp
+++ b/modules/database/db_flatfile.cpp
@@ -36,11 +36,12 @@ class LoadData : public Serialize::Data
{
public:
std::fstream *fs;
+ unsigned int id;
std::map<Anope::string, Anope::string> data;
std::stringstream ss;
bool read;
- LoadData() : fs(NULL), read(false) { }
+ LoadData() : fs(NULL), id(0), read(false) { }
std::iostream& operator[](const Anope::string &key) anope_override
{
@@ -48,7 +49,17 @@ class LoadData : public Serialize::Data
{
for (Anope::string token; std::getline(*this->fs, token.str());)
{
- if (token.find("DATA ") != 0)
+ if (token.find("ID ") == 0)
+ {
+ try
+ {
+ this->id = convertTo<unsigned int>(token.substr(3));
+ }
+ catch (const ConvertException &) { }
+
+ continue;
+ }
+ else if (token.find("DATA ") != 0)
break;
size_t sp = token.find(' ', 5); // Skip DATA
@@ -83,6 +94,7 @@ class LoadData : public Serialize::Data
void Reset()
{
+ id = 0;
read = false;
data.clear();
}
@@ -225,7 +237,9 @@ class DBFlatFile : public Module, public Pipe
fd.clear();
fd.seekg(pos[j]);
- stype->Unserialize(NULL, ld);
+ Serializable *obj = stype->Unserialize(NULL, ld);
+ if (obj != NULL)
+ obj->id = ld.id;
ld.Reset();
}
}
@@ -292,6 +306,8 @@ class DBFlatFile : public Module, public Pipe
continue;
*data.fs << "OBJECT " << s_type->GetName();
+ if (base->id)
+ *data.fs << "\nID " << base->id;
base->Serialize(data);
*data.fs << "\nEND\n";
}
diff --git a/modules/database/db_sql.cpp b/modules/database/db_sql.cpp
index 3bb0efde2..ab6a1b259 100644
--- a/modules/database/db_sql.cpp
+++ b/modules/database/db_sql.cpp
@@ -63,6 +63,7 @@ class DBSQL : public Module, public Pipe
bool shutting_down;
bool loading_databases;
bool loaded;
+ bool imported;
void RunBackground(const Query &q, Interface *iface = NULL)
{
@@ -86,7 +87,7 @@ class DBSQL : public Module, public Pipe
}
public:
- DBSQL(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, DATABASE), sql("", ""), sqlinterface(this), shutting_down(false), loading_databases(false), loaded(false)
+ DBSQL(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, DATABASE), sql("", ""), sqlinterface(this), shutting_down(false), loading_databases(false), loaded(false), imported(false)
{
this->SetAuthor("Anope");
@@ -121,17 +122,22 @@ class DBSQL : public Module, public Pipe
this->RunBackground(create[i]);
Query insert = this->sql->BuildInsert(this->prefix + s_type->GetName(), obj->id, data);
- if (this->loaded)
+ if (this->imported)
this->RunBackground(insert, new ResultSQLSQLInterface(this, obj));
else
- /* If we aren't loading these objects then we are importing them, so don't do asynchronous
- * queries in case for some reason the core has to shut down, it will cut short the import
+ {
+ /* On the first loop we may be importing objects from another database module, so don't do asynchronous
+ * queries in case the core has to shut down, it will cut short the import
*/
- this->sql->RunQuery(insert);
+ Result r = this->sql->RunQuery(insert);
+ if (r.GetID() > 0)
+ obj->id = r.GetID();
+ }
}
}
this->updated_items.clear();
+ this->imported = true;
}
void OnReload() anope_override