diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/modules/extra/m_pgsql.cpp | 18 | ||||
-rw-r--r-- | src/modules/extra/m_testclient.cpp | 23 |
2 files changed, 29 insertions, 12 deletions
diff --git a/src/modules/extra/m_pgsql.cpp b/src/modules/extra/m_pgsql.cpp index f9de9f516..7b452e7c6 100644 --- a/src/modules/extra/m_pgsql.cpp +++ b/src/modules/extra/m_pgsql.cpp @@ -15,6 +15,7 @@ * --------------------------------------------------- */ +#include <cstdlib> #include <sstream> #include <string> #include <deque> @@ -205,6 +206,8 @@ class PgSQLresult : public SQLresult { PGresult* res; int currentrow; + int rows; + int cols; SQLfieldList* fieldlist; SQLfieldMap* fieldmap; @@ -212,10 +215,10 @@ public: PgSQLresult(Module* self, Module* to, unsigned long id, PGresult* result) : SQLresult(self, to, id), res(result), currentrow(0), fieldlist(NULL), fieldmap(NULL) { - int rows = PQntuples(res); - int cols = PQnfields(res); + rows = PQntuples(res); + cols = PQnfields(res); - log(DEBUG, "Created new PgSQL result; %d rows, %d columns", rows, cols); + log(DEBUG, "Created new PgSQL result; %d rows, %d columns, %s affected", rows, cols, PQcmdTuples(res)); } ~PgSQLresult() @@ -225,7 +228,14 @@ public: virtual int Rows() { - return PQntuples(res); + if(!cols && !rows) + { + return atoi(PQcmdTuples(res)); + } + else + { + return rows; + } } virtual int Cols() diff --git a/src/modules/extra/m_testclient.cpp b/src/modules/extra/m_testclient.cpp index d5f2fc0d6..0df1f8c59 100644 --- a/src/modules/extra/m_testclient.cpp +++ b/src/modules/extra/m_testclient.cpp @@ -35,7 +35,7 @@ public: if(target) { - SQLrequest foo = SQLreq(this, target, "foo", "SELECT foo, bar FROM ?", "rawr"); + SQLrequest foo = SQLreq(this, target, "foo", "UPDATE rawr SET foo = '?' WHERE bar = 42", ConvToStr(time(NULL))); if(foo.Send()) { @@ -58,17 +58,24 @@ public: if (res->error.Id() == NO_ERROR) { - log(DEBUG, "Got result with %d rows and %d columns", res->Rows(), res->Cols()); - - for (int r = 0; r < res->Rows(); r++) + if(res->Cols()) { - log(DEBUG, "Row %d:", r); - - for(int i = 0; i < res->Cols(); i++) + log(DEBUG, "Got result with %d rows and %d columns", res->Rows(), res->Cols()); + + for (int r = 0; r < res->Rows(); r++) { - log(DEBUG, "\t[%s]: %s", res->ColName(i).c_str(), res->GetValue(r, i).d.c_str()); + log(DEBUG, "Row %d:", r); + + for(int i = 0; i < res->Cols(); i++) + { + log(DEBUG, "\t[%s]: %s", res->ColName(i).c_str(), res->GetValue(r, i).d.c_str()); + } } } + else + { + log(DEBUG, "%d rows affected in query", res->Rows()); + } } else { |