+ SQLrequest req = SQLrequest(MyMod, SQLModule, dbid, SQLquery(""));
+ switch (qs)
+ {
+ case FIND_SOURCE:
+ if (res->Rows() && sourceid == -1 && !insert)
+ {
+ sourceid = atoi(res->GetValue(0,0).d.c_str());
+ req = SQLrequest(MyMod, SQLModule, dbid, SQLquery("SELECT id,actor FROM ircd_log_actors WHERE actor='?'") % nick);
+ if(req.Send())
+ {
+ insert = false;
+ qs = FIND_NICK;
+ active_queries[req.id] = this;
+ }
+ }
+ else if (res->Rows() && sourceid == -1 && insert)
+ {
+ req = SQLrequest(MyMod, SQLModule, dbid, SQLquery("SELECT id,actor FROM ircd_log_actors WHERE actor='?'") % source);
+ if(req.Send())
+ {
+ insert = false;
+ qs = FIND_SOURCE;
+ active_queries[req.id] = this;
+ }
+ }
+ else
+ {
+ req = SQLrequest(MyMod, SQLModule, dbid, SQLquery("INSERT INTO ircd_log_actors (actor) VALUES('?')") % source);
+ if(req.Send())
+ {
+ insert = true;
+ qs = FIND_SOURCE;
+ active_queries[req.id] = this;
+ }
+ }
+ break;
+
+ case FIND_NICK:
+ if (res->Rows() && nickid == -1 && !insert)
+ {
+ nickid = atoi(res->GetValue(0,0).d.c_str());
+ req = SQLrequest(MyMod, SQLModule, dbid, SQLquery("SELECT id,hostname FROM ircd_log_hosts WHERE hostname='?'") % hostname);
+ if(req.Send())
+ {
+ insert = false;
+ qs = FIND_HOST;
+ active_queries[req.id] = this;
+ }
+ }
+ else if (res->Rows() && nickid == -1 && insert)
+ {
+ req = SQLrequest(MyMod, SQLModule, dbid, SQLquery("SELECT id,actor FROM ircd_log_actors WHERE actor='?'") % nick);
+ if(req.Send())
+ {
+ insert = false;
+ qs = FIND_NICK;
+ active_queries[req.id] = this;
+ }
+ }
+ else
+ {
+ req = SQLrequest(MyMod, SQLModule, dbid, SQLquery("INSERT INTO ircd_log_actors (actor) VALUES('?')") % nick);
+ if(req.Send())
+ {
+ insert = true;
+ qs = FIND_NICK;
+ active_queries[req.id] = this;
+ }
+ }
+ break;
+
+ case FIND_HOST:
+ if (res->Rows() && hostid == -1 && !insert)
+ {
+ hostid = atoi(res->GetValue(0,0).d.c_str());
+ req = SQLrequest(MyMod, SQLModule, dbid,
+ SQLquery("INSERT INTO ircd_log (category_id,nick,host,source,dtime) VALUES('?','?','?','?','?')") % category % nickid % hostid % sourceid % date);
+ if(req.Send())
+ {
+ insert = true;
+ qs = DONE;
+ active_queries[req.id] = this;
+ }
+ }
+ else if (res->Rows() && hostid == -1 && insert)
+ {
+ req = SQLrequest(MyMod, SQLModule, dbid, SQLquery("SELECT id,hostname FROM ircd_log_hosts WHERE hostname='?'") % hostname);
+ if(req.Send())
+ {
+ insert = false;
+ qs = FIND_HOST;
+ active_queries[req.id] = this;
+ }
+ }
+ else
+ {
+ req = SQLrequest(MyMod, SQLModule, dbid, SQLquery("INSERT INTO ircd_log_hosts (hostname) VALUES('?')") % hostname);
+ if(req.Send())
+ {
+ insert = true;
+ qs = FIND_HOST;
+ active_queries[req.id] = this;
+ }
+ }
+ break;
+
+ case DONE:
+ std::map<unsigned long,QueryInfo*>::iterator x = active_queries.find(req.id);
+ if (x != active_queries.end())
+ {
+ delete x->second;
+ active_queries.erase(x);
+ }
+ break;
+ }