diff options
author | om <om@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-07-22 16:30:03 +0000 |
---|---|---|
committer | om <om@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-07-22 16:30:03 +0000 |
commit | 0b92dc3d2b2d33c14944514c7957efc308a1c330 (patch) | |
tree | 93eef0d32cd22dccee2251b88e0fb583b6e294bb /src | |
parent | 0f4fa12f1ef4158297710551ad5bfcfc82e8df48 (diff) |
Make m_pgsql return the number of affected rows for an UPDATE or INSERT query.
Make m_testclient do an INSERT and test this :p
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@4517 e03df62e-2008-0410-955e-edbf42e46eb7
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 { |