From 0b92dc3d2b2d33c14944514c7957efc308a1c330 Mon Sep 17 00:00:00 2001 From: om Date: Sat, 22 Jul 2006 16:30:03 +0000 Subject: 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 --- src/modules/extra/m_pgsql.cpp | 18 ++++++++++++++---- src/modules/extra/m_testclient.cpp | 23 +++++++++++++++-------- 2 files changed, 29 insertions(+), 12 deletions(-) (limited to 'src/modules') 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 #include #include #include @@ -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 { -- cgit v1.2.3