From 2c6c072c1f5f19d1471feb43fa94bba0030e5fb6 Mon Sep 17 00:00:00 2001 From: om Date: Fri, 21 Jul 2006 08:37:42 +0000 Subject: 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 --- src/modules/extra/m_pgsql.cpp | 42 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) (limited to 'src/modules/extra/m_pgsql.cpp') 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 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"); } } } -- cgit v1.3.1-10-gc9f91