summaryrefslogtreecommitdiff
path: root/src/modules/extra/m_pgsql.cpp
diff options
context:
space:
mode:
authorom <om@e03df62e-2008-0410-955e-edbf42e46eb7>2006-07-21 08:37:42 +0000
committerom <om@e03df62e-2008-0410-955e-edbf42e46eb7>2006-07-21 08:37:42 +0000
commit2c6c072c1f5f19d1471feb43fa94bba0030e5fb6 (patch)
treeef8a94f1495cffad286323c3b959c93463d54ab7 /src/modules/extra/m_pgsql.cpp
parent7fcb5797a6b98757d766997a1f4e48bf1eee8042 (diff)
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
Diffstat (limited to 'src/modules/extra/m_pgsql.cpp')
-rw-r--r--src/modules/extra/m_pgsql.cpp42
1 files changed, 34 insertions, 8 deletions
diff --git a/src/modules/extra/m_pgsql.cpp b/src/modules/extra/m_pgsql.cpp
index c67ca0854..39849271d 100644
--- a/src/modules/extra/m_pgsql.cpp
+++ b/src/modules/extra/m_pgsql.cpp
@@ -101,7 +101,7 @@ public:
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)
priority.push_back(q);
@@ -506,7 +506,7 @@ public:
SQLrequest* req = (SQLrequest*)request;
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())
{
@@ -941,16 +941,42 @@ SQLerror SQLConn::DoQuery(const SQLrequest &req)
{
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++)
+ {
+ if(req.query.q[i] == '?')
+ {
+ 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)
{
- log(DEBUG, "Dispatched query: %s", req.query.c_str());
- qinprog = true;
- return SQLerror();
+ 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
{
- log(DEBUG, "Failed to dispatch query: %s", PQerrorMessage(sql));
- return SQLerror(QSEND_FAIL, PQerrorMessage(sql));
+ log(DEBUG, "Failed to escape query string");
+ return SQLerror(QSEND_FAIL, "Couldn't escape query string");
}
}
}