Miscellaneous profiling fixes
[lhc/web/wiklou.git] / includes / db / DatabaseMysql.php
index faa09ad..8708608 100644 (file)
@@ -133,7 +133,7 @@ class DatabaseMysql extends DatabaseBase {
                                substr( $password, 0, 3 ) . "..., error: " . $error . "\n" );
 
                        wfProfileOut( __METHOD__ );
-                       $this->reportConnectionError( $error );
+                       return $this->reportConnectionError( $error );
                }
 
                if ( $dbName != '' ) {
@@ -146,7 +146,7 @@ class DatabaseMysql extends DatabaseBase {
                                        "from client host " . wfHostname() . "\n" );
 
                                wfProfileOut( __METHOD__ );
-                               $this->reportConnectionError( "Error selecting database $dbName" );
+                               return $this->reportConnectionError( "Error selecting database $dbName" );
                        }
                }
 
@@ -203,7 +203,13 @@ class DatabaseMysql extends DatabaseBase {
                wfSuppressWarnings();
                $row = mysql_fetch_object( $res );
                wfRestoreWarnings();
-               if( $this->lastErrno() ) {
+
+               $errno = $this->lastErrno();
+               // Unfortunately, mysql_fetch_object does not reset the last errno.
+               // Only check for CR_SERVER_LOST and CR_UNKNOWN_ERROR, as
+               // these are the only errors mysql_fetch_object can cause.
+               // See http://dev.mysql.com/doc/refman/5.0/es/mysql-fetch-row.html.
+               if( $errno == 2000 || $errno == 2013 ) {
                        throw new DBUnexpectedError( $this, 'Error in fetchObject(): ' . htmlspecialchars( $this->lastError() ) );
                }
                return $row;
@@ -221,7 +227,13 @@ class DatabaseMysql extends DatabaseBase {
                wfSuppressWarnings();
                $row = mysql_fetch_array( $res );
                wfRestoreWarnings();
-               if ( $this->lastErrno() ) {
+
+               $errno = $this->lastErrno();
+               // Unfortunately, mysql_fetch_array does not reset the last errno.
+               // Only check for CR_SERVER_LOST and CR_UNKNOWN_ERROR, as
+               // these are the only errors mysql_fetch_object can cause.
+               // See http://dev.mysql.com/doc/refman/5.0/es/mysql-fetch-row.html.
+               if( $errno == 2000 || $errno == 2013 ) {
                        throw new DBUnexpectedError( $this, 'Error in fetchRow(): ' . htmlspecialchars( $this->lastError() ) );
                }
                return $row;
@@ -402,6 +414,7 @@ class DatabaseMysql extends DatabaseBase {
                # http://dev.mysql.com/doc/mysql/en/SHOW_INDEX.html
                $table = $this->tableName( $table );
                $index = $this->indexName( $index );
+
                $sql = 'SHOW INDEX FROM ' . $table;
                $res = $this->query( $sql, $fname );
 
@@ -416,7 +429,6 @@ class DatabaseMysql extends DatabaseBase {
                                $result[] = $row;
                        }
                }
-
                return empty( $result ) ? false : $result;
        }
 
@@ -793,7 +805,8 @@ class DatabaseMysql extends DatabaseBase {
         * @param $delVar string
         * @param $joinVar string
         * @param $conds array|string
-        * @param $fname bool
+        * @param bool|string $fname bool
+        * @throws DBUnexpectedError
         * @return bool|ResultWrapper
         */
        function deleteJoin( $delTable, $joinTable, $delVar, $joinVar, $conds, $fname = 'DatabaseBase::deleteJoin' ) {
@@ -939,13 +952,6 @@ class DatabaseMysql extends DatabaseBase {
 
 }
 
-/**
- * Legacy support: Database == DatabaseMysql
- *
- * @deprecated in 1.16
- */
-class Database extends DatabaseMysql {}
-
 /**
  * Utility class.
  * @ingroup Database