- //ServerInstance->Log(DEBUG, "Looks like we have a result to process!");
-
- /* Grab the request we're processing */
- SQLrequest& query = queue.front();
-
- Instance->Log(DEBUG, "ID is %lu", query.id);
-
- /* Get a pointer to the module we're about to return the result to */
- Module* to = query.GetSource();
-
- /* Fetch the result.. */
- PGresult* result = PQgetResult(sql);
-
- /* PgSQL would allow a query string to be sent which has multiple
- * queries in it, this isn't portable across database backends and
- * we don't want modules doing it. But just in case we make sure we
- * drain any results there are and just use the last one.
- * If the module devs are behaving there will only be one result.
- */
- while (PGresult* temp = PQgetResult(sql))
- {
- PQclear(result);
- result = temp;
- }
-
- if(to)
- {
- /* ..and the result */
- PgSQLresult reply(us, to, query.id, result);
-
- /* Fix by brain, make sure the original query gets sent back in the reply */
- reply.query = query.query.q;
-
- Instance->Log(DEBUG, "Got result, status code: %s; error message: %s", PQresStatus(PQresultStatus(result)), PQresultErrorMessage(result));
-
- switch(PQresultStatus(result))
- {
- case PGRES_EMPTY_QUERY:
- case PGRES_BAD_RESPONSE:
- case PGRES_FATAL_ERROR:
- reply.error.Id(QREPLY_FAIL);
- reply.error.Str(PQresultErrorMessage(result));
- default:;
- /* No action, other values are not errors */
- }
-
- reply.Send();
-
- /* PgSQLresult's destructor will free the PGresult */
- }
- else
- {
- /* If the client module is unloaded partway through a query then the provider will set
- * the pointer to NULL. We cannot just cancel the query as the result will still come
- * through at some point...and it could get messy if we play with invalid pointers...
- */
- Instance->Log(DEBUG, "Looks like we're handling a zombie query from a module which unloaded before it got a result..fun. ID: %lu", query.id);
- PQclear(result);
- }
-
- qinprog = false;
- queue.pop();
- DoConnectedPoll();