mirror of
https://github.com/inspircd/inspircd.git
synced 2025-04-21 07:21:27 -04:00
API header and client module updates for new multi-parameter query request. Needs proper implementation in m_pgsql and documentation
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@4471 e03df62e-2008-0410-955e-edbf42e46eb7
This commit is contained in:
parent
7fcb5797a6
commit
2c6c072c1f
@ -101,7 +101,7 @@ public:
|
|||||||
|
|
||||||
void push(const SQLrequest &q)
|
void push(const SQLrequest &q)
|
||||||
{
|
{
|
||||||
log(DEBUG, "QueryQueue::push(): Adding %s query to queue: %s", ((q.pri) ? "priority" : "non-priority"), q.query.c_str());
|
log(DEBUG, "QueryQueue::push(): Adding %s query to queue: %s", ((q.pri) ? "priority" : "non-priority"), q.query.q.c_str());
|
||||||
|
|
||||||
if(q.pri)
|
if(q.pri)
|
||||||
priority.push_back(q);
|
priority.push_back(q);
|
||||||
@ -506,7 +506,7 @@ public:
|
|||||||
SQLrequest* req = (SQLrequest*)request;
|
SQLrequest* req = (SQLrequest*)request;
|
||||||
ConnMap::iterator iter;
|
ConnMap::iterator iter;
|
||||||
|
|
||||||
log(DEBUG, "Got query: '%s' on id '%s'", req->query.c_str(), req->dbid.c_str());
|
log(DEBUG, "Got query: '%s' with %d replacement parameters on id '%s'", req->query.q.c_str(), req->query.p.size(), req->dbid.c_str());
|
||||||
|
|
||||||
if((iter = connections.find(req->dbid)) != connections.end())
|
if((iter = connections.find(req->dbid)) != connections.end())
|
||||||
{
|
{
|
||||||
@ -941,16 +941,42 @@ SQLerror SQLConn::DoQuery(const SQLrequest &req)
|
|||||||
{
|
{
|
||||||
if(!qinprog)
|
if(!qinprog)
|
||||||
{
|
{
|
||||||
if(PQsendQuery(sql, req.query.c_str()))
|
/* Parse the command string and dispatch it */
|
||||||
|
|
||||||
|
/* A list of offsets into the original string of the '?' characters we're substituting */
|
||||||
|
std::vector<unsigned int> insertlocs;
|
||||||
|
|
||||||
|
for(unsigned int i = 0; i < req.query.q.length(); i++)
|
||||||
{
|
{
|
||||||
log(DEBUG, "Dispatched query: %s", req.query.c_str());
|
if(req.query.q[i] == '?')
|
||||||
qinprog = true;
|
{
|
||||||
return SQLerror();
|
insertlocs.push_back(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
char* query = new char[(req.query.q.length()*2)+1];
|
||||||
|
int error = 0;
|
||||||
|
|
||||||
|
// PQescapeStringConn(sql, query, req.query.q.c_str(), req.query.q.length(), error);
|
||||||
|
|
||||||
|
if(error == 0)
|
||||||
|
{
|
||||||
|
if(PQsendQuery(sql, query))
|
||||||
|
{
|
||||||
|
log(DEBUG, "Dispatched query: %s", query);
|
||||||
|
qinprog = true;
|
||||||
|
return SQLerror();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
log(DEBUG, "Failed to dispatch query: %s", PQerrorMessage(sql));
|
||||||
|
return SQLerror(QSEND_FAIL, PQerrorMessage(sql));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
log(DEBUG, "Failed to dispatch query: %s", PQerrorMessage(sql));
|
log(DEBUG, "Failed to escape query string");
|
||||||
return SQLerror(QSEND_FAIL, PQerrorMessage(sql));
|
return SQLerror(QSEND_FAIL, "Couldn't escape query string");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,22 @@
|
|||||||
#ifndef INSPIRCD_SQLAPI_2
|
#ifndef INSPIRCD_SQLAPI_2
|
||||||
#define INSPIRCD_SQLAPI_2
|
#define INSPIRCD_SQLAPI_2
|
||||||
|
|
||||||
#define SQLREQID "SQLv2 Request"
|
|
||||||
#define SQLRESID "SQLv2 Result"
|
|
||||||
#define SQLSUCCESS "You shouldn't be reading this (success)"
|
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include "modules.h"
|
#include "modules.h"
|
||||||
|
|
||||||
|
/* This is the voodoo magic which lets us pass multiple parameters
|
||||||
|
* to the SQLrequest constructor..voodoo...
|
||||||
|
*/
|
||||||
|
#define SQLreq(a, b, c, d, e...) SQLrequest(a, b, c, (SQLquery(d), ##e))
|
||||||
|
|
||||||
|
#define SQLREQID "SQLv2 Request"
|
||||||
|
#define SQLRESID "SQLv2 Result"
|
||||||
|
#define SQLSUCCESS "You shouldn't be reading this (success)"
|
||||||
|
|
||||||
enum SQLerrorNum { NO_ERROR, BAD_DBID, BAD_CONN, QSEND_FAIL };
|
enum SQLerrorNum { NO_ERROR, BAD_DBID, BAD_CONN, QSEND_FAIL };
|
||||||
|
typedef std::vector<std::string> ParamL;
|
||||||
|
|
||||||
class SQLexception : public ModuleException
|
class SQLexception : public ModuleException
|
||||||
{
|
{
|
||||||
@ -69,20 +75,56 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class SQLquery
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
std::string q;
|
||||||
|
ParamL p;
|
||||||
|
|
||||||
|
SQLquery(const std::string &query)
|
||||||
|
: q(query)
|
||||||
|
{
|
||||||
|
log(DEBUG, "SQLquery constructor: %s", q.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
SQLquery(const std::string &query, const ParamL ¶ms)
|
||||||
|
: q(query), p(params)
|
||||||
|
{
|
||||||
|
log(DEBUG, "SQLquery constructor with %d params: %s", p.size(), q.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
SQLquery& operator,(const std::string &foo)
|
||||||
|
{
|
||||||
|
p.push_back(foo);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
SQLquery& operator%(const std::string &foo)
|
||||||
|
{
|
||||||
|
p.push_back(foo);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
class SQLrequest : public Request
|
class SQLrequest : public Request
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
std::string query;
|
SQLquery query;
|
||||||
std::string dbid;
|
std::string dbid;
|
||||||
bool pri;
|
bool pri;
|
||||||
unsigned long id;
|
unsigned long id;
|
||||||
SQLerror error;
|
SQLerror error;
|
||||||
|
|
||||||
SQLrequest(Module* s, Module* d, const std::string &q, const std::string &id, bool p = false)
|
SQLrequest(Module* s, Module* d, const std::string &databaseid, const SQLquery &q)
|
||||||
: Request(SQLREQID, s, d), query(q), dbid(id), pri(p), id(0)
|
: Request(SQLREQID, s, d), query(q), dbid(databaseid), pri(false), id(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Priority(bool p = true)
|
||||||
|
{
|
||||||
|
pri = p;
|
||||||
|
}
|
||||||
|
|
||||||
void SetSource(Module* mod)
|
void SetSource(Module* mod)
|
||||||
{
|
{
|
||||||
source = mod;
|
source = mod;
|
||||||
|
@ -35,7 +35,7 @@ public:
|
|||||||
|
|
||||||
if(target)
|
if(target)
|
||||||
{
|
{
|
||||||
SQLrequest foo(this, target, "SELECT foo, bar FROM rawr", "foo");
|
SQLrequest foo = SQLreq(this, target, "foo", "SELECT foo, bar FROM ?", "rawr");
|
||||||
|
|
||||||
if(foo.Send())
|
if(foo.Send())
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user