From: Brion Vibber Date: Fri, 1 Aug 2008 21:00:24 +0000 (+0000) Subject: Don't die horribly from sql.php when making INSERT/DELETE/UPDATE/CREATE TABLE/etc... X-Git-Tag: 1.31.0-rc.0~46212 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/categories/modifier.php?a=commitdiff_plain;h=dff6e3ae0bd10b041f2b4dc2e899516c0607c6ae;p=lhc%2Fweb%2Fwiklou.git Don't die horribly from sql.php when making INSERT/DELETE/UPDATE/CREATE TABLE/etc calls that return 'true' instead of a result object. Code was attempting to handle this case by asking the result object for its db so we can ask for the affected row count -- obviously that doesn't do so good when the result is not an object. Changed Database::sourceStream() to send itself as the second parameter to the result-handling callback, so the callback knows which DB to check. --- diff --git a/includes/db/Database.php b/includes/db/Database.php index 885ede5463..2e3e0edccd 100644 --- a/includes/db/Database.php +++ b/includes/db/Database.php @@ -2177,7 +2177,7 @@ class Database { $cmd = $this->replaceVars( $cmd ); $res = $this->query( $cmd, __METHOD__ ); if ( $resultCallback ) { - call_user_func( $resultCallback, $res ); + call_user_func( $resultCallback, $res, $this ); } if ( false === $res ) { diff --git a/maintenance/sql.php b/maintenance/sql.php index 38c995acbe..ab6546b9e0 100644 --- a/maintenance/sql.php +++ b/maintenance/sql.php @@ -53,15 +53,15 @@ class SqlPromptPrinter { } } -function sqlPrintResult( $res ) { +function sqlPrintResult( $res, $db ) { if ( !$res ) { // Do nothing - } elseif ( $res->numRows() ) { + } elseif ( is_object( $res ) && $res->numRows() ) { while ( $row = $res->fetchObject() ) { print_r( $row ); } } else { - $affected = $res->db->affectedRows(); + $affected = $db->affectedRows(); echo "Query OK, $affected row(s) affected\n"; } }