From fcc4355c4b80e6598aa93dc7f8f40f80e979582c Mon Sep 17 00:00:00 2001 From: brain Date: Sat, 22 Jul 2006 13:30:34 +0000 Subject: I hate the fucking mysql devs. Craq smoking bastards. Upon Insert, number of rows is the number of rows effected but the number of columns is 0????? Add check to MySQLreply::Rows() to ensure the user doesnt see N rows and 0 columns! git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@4510 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/modules/extra/m_mysql.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src/modules/extra/m_mysql.cpp') diff --git a/src/modules/extra/m_mysql.cpp b/src/modules/extra/m_mysql.cpp index acfdf8214..38c3b4c93 100644 --- a/src/modules/extra/m_mysql.cpp +++ b/src/modules/extra/m_mysql.cpp @@ -254,16 +254,14 @@ class MySQLresult : public SQLresult } rows++; } - cols = field_count; mysql_free_result(res); } - log(DEBUG, "Created new MySQL result; %d rows, %d columns", rows, cols); + log(DEBUG, "Created new MySQL result; %d rows, %d columns", rows, colnames.size()); } MySQLresult(Module* self, Module* to, SQLerror e, unsigned int id) : SQLresult(self, to, id), currentrow(0) { rows = 0; - cols = 0; error = e; log(DEBUG,"Created new MySQLresult of error type"); } @@ -274,12 +272,18 @@ class MySQLresult : public SQLresult virtual int Rows() { - return rows; + /* An INSERT can return 0 columns, but N rows. This is unsafe to + * allow the user to 'see'. Go figure. I hate you, MySQL devs. + */ + if (colnames.size()) + return rows; + else + return 0; } virtual int Cols() { - return cols; + return colnames.size(); } virtual std::string ColName(int column) @@ -308,7 +312,7 @@ class MySQLresult : public SQLresult virtual SQLfield GetValue(int row, int column) { - if ((row >= 0) && (row < rows) && (column >= 0) && (column < cols)) + if ((row >= 0) && (row < rows) && (column >= 0) && (column < Cols())) { return fieldlists[row][column]; } -- cgit v1.3.1-10-gc9f91