Merge "(bug 36819) Lowercase be,csb,cu,dsb,hsb,rue,sgs,szl"
[lhc/web/wiklou.git] / includes / db / DatabaseMysql.php
index 4bde72b..1d03073 100644 (file)
@@ -2,6 +2,21 @@
 /**
  * This is the MySQL database abstraction layer.
  *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
  * @file
  * @ingroup Database
  */
@@ -23,7 +38,7 @@ class DatabaseMysql extends DatabaseBase {
        }
 
        /**
-        * @param $sql
+        * @param $sql string
         * @return resource
         */
        protected function doQuery( $sql ) {
@@ -36,10 +51,10 @@ class DatabaseMysql extends DatabaseBase {
        }
 
        /**
-        * @param $server
-        * @param $user
-        * @param $password
-        * @param $dbName
+        * @param $server string
+        * @param $user string
+        * @param $password string
+        * @param $dbName string
         * @return bool
         * @throws DBConnectionError
         */
@@ -98,14 +113,14 @@ class DatabaseMysql extends DatabaseBase {
                $phpError = $this->restoreErrorHandler();
                # Always log connection errors
                if ( !$this->mConn ) {
-                       $error = $this->lastError();
+                       $error = $phpError;
                        if ( !$error ) {
-                               $error = $phpError;
+                               $error = $this->lastError();
                        }
                        wfLogDBError( "Error connecting to {$this->mServer}: $error\n" );
                        wfDebug( "DB connection error\n" );
                        wfDebug( "Server: $server, User: $user, Password: " .
-                               substr( $password, 0, 3 ) . "..., error: " . mysql_error() . "\n" );
+                               substr( $password, 0, 3 ) . "..., error: " . $error . "\n" );
                }
 
                wfProfileOut("dbconnect-$server");
@@ -154,20 +169,12 @@ class DatabaseMysql extends DatabaseBase {
        /**
         * @return bool
         */
-       function close() {
-               $this->mOpened = false;
-               if ( $this->mConn ) {
-                       if ( $this->trxLevel() ) {
-                               $this->commit();
-                       }
-                       return mysql_close( $this->mConn );
-               } else {
-                       return true;
-               }
+       protected function closeConnection() {
+               return mysql_close( $this->mConn );
        }
 
        /**
-        * @param $res
+        * @param $res ResultWrapper
         * @throws DBUnexpectedError
         */
        function freeResult( $res ) {
@@ -183,7 +190,7 @@ class DatabaseMysql extends DatabaseBase {
        }
 
        /**
-        * @param $res
+        * @param $res ResultWrapper
         * @return object|stdClass
         * @throws DBUnexpectedError
         */
@@ -201,7 +208,7 @@ class DatabaseMysql extends DatabaseBase {
        }
 
        /**
-        * @param $res
+        * @param $res ResultWrapper
         * @return array
         * @throws DBUnexpectedError
         */
@@ -220,7 +227,7 @@ class DatabaseMysql extends DatabaseBase {
 
        /**
         * @throws DBUnexpectedError
-        * @param $res
+        * @param $res ResultWrapper
         * @return int
         */
        function numRows( $res ) {
@@ -237,7 +244,7 @@ class DatabaseMysql extends DatabaseBase {
        }
 
        /**
-        * @param $res
+        * @param $res ResultWrapper
         * @return int
         */
        function numFields( $res ) {
@@ -248,8 +255,8 @@ class DatabaseMysql extends DatabaseBase {
        }
 
        /**
-        * @param $res
-        * @param $n
+        * @param $res ResultWrapper
+        * @param $n string
         * @return string
         */
        function fieldName( $res, $n ) {
@@ -267,7 +274,7 @@ class DatabaseMysql extends DatabaseBase {
        }
 
        /**
-        * @param $res
+        * @param $res ResultWrapper
         * @param $row
         * @return bool
         */
@@ -318,9 +325,9 @@ class DatabaseMysql extends DatabaseBase {
        }
 
        /**
-        * @param $table
+        * @param $table string
         * @param $uniqueIndexes
-        * @param $rows
+        * @param $rows array
         * @param $fname string
         * @return ResultWrapper
         */
@@ -382,10 +389,10 @@ class DatabaseMysql extends DatabaseBase {
         * Get information about an index into an object
         * Returns false if the index does not exist
         *
-        * @param $table
-        * @param $index
+        * @param $table string
+        * @param $index string
         * @param $fname string
-        * @return false|array
+        * @return bool|array|null False or null on failure
         */
        function indexInfo( $table, $index, $fname = 'DatabaseMysql::indexInfo' ) {
                # SHOW INDEX works in MySQL 3.23.58, but SHOW INDEXES does not.
@@ -511,6 +518,7 @@ class DatabaseMysql extends DatabaseBase {
         * @return bool|int
         */
        function getLagFromProcesslist() {
+               wfDeprecated( __METHOD__, '1.19' );
                $res = $this->query( 'SHOW PROCESSLIST', __METHOD__ );
                if( !$res ) {
                        return false;
@@ -557,7 +565,7 @@ class DatabaseMysql extends DatabaseBase {
 
                # Commit any open transactions
                if ( $this->mTrxLevel ) {
-                       $this->commit();
+                       $this->commit( __METHOD__ );
                }
 
                if ( !is_null( $this->mFakeSlaveLag ) ) {
@@ -584,7 +592,7 @@ class DatabaseMysql extends DatabaseBase {
        /**
         * Get the position of the master from SHOW SLAVE STATUS
         *
-        * @return MySQLMasterPos|false
+        * @return MySQLMasterPos|bool
         */
        function getSlavePos() {
                if ( !is_null( $this->mFakeSlaveLag ) ) {
@@ -605,7 +613,7 @@ class DatabaseMysql extends DatabaseBase {
        /**
         * Get the position of the master from SHOW MASTER STATUS
         *
-        * @return MySQLMasterPos|false
+        * @return MySQLMasterPos|bool
         */
        function getMasterPos() {
                if ( $this->mFakeMaster ) {
@@ -669,9 +677,33 @@ class DatabaseMysql extends DatabaseBase {
                }
        }
 
+       public function streamStatementEnd( &$sql, &$newLine ) {
+               if ( strtoupper( substr( $newLine, 0, 9 ) ) == 'DELIMITER' ) {
+                       preg_match( '/^DELIMITER\s+(\S+)/' , $newLine, $m );
+                       $this->delimiter = $m[1];
+                       $newLine = '';
+               }
+               return parent::streamStatementEnd( $sql, $newLine );
+       }
+
        /**
-        * @param $lockName
-        * @param $method
+        * Check to see if a named lock is available. This is non-blocking.
+        *
+        * @param $lockName String: name of lock to poll
+        * @param $method String: name of method calling us
+        * @return Boolean
+        * @since 1.20
+        */
+       public function lockIsFree( $lockName, $method ) {
+               $lockName = $this->addQuotes( $lockName );
+               $result = $this->query( "SELECT IS_FREE_LOCK($lockName) AS lockstatus", $method );
+               $row = $this->fetchObject( $result );
+               return ( $row->lockstatus == 1 );
+       }
+
+       /**
+        * @param $lockName string
+        * @param $method string
         * @param $timeout int
         * @return bool
         */
@@ -690,21 +722,21 @@ class DatabaseMysql extends DatabaseBase {
 
        /**
         * FROM MYSQL DOCS: http://dev.mysql.com/doc/refman/5.0/en/miscellaneous-functions.html#function_release-lock
-        * @param $lockName
+        * @param $lockName string
         * @param $method string
-        * @return
+        * @return bool
         */
        public function unlock( $lockName, $method ) {
                $lockName = $this->addQuotes( $lockName );
                $result = $this->query( "SELECT RELEASE_LOCK($lockName) as lockstatus", $method );
                $row = $this->fetchObject( $result );
-               return $row->lockstatus;
+               return ( $row->lockstatus == 1 );
        }
 
        /**
-        * @param $read
-        * @param $write
-        * @param $method
+        * @param $read array
+        * @param $write array
+        * @param $method string
         * @param $lowPriority bool
         */
        public function lockTables( $read, $write, $method, $lowPriority = true ) {
@@ -761,13 +793,13 @@ class DatabaseMysql extends DatabaseBase {
 
        /**
         * DELETE where the condition is a join. MySql uses multi-table deletes.
-        * @param $delTable
-        * @param $joinTable
-        * @param $delVar
-        * @param $joinVar
+        * @param $delTable string
+        * @param $joinTable string
+        * @param $delVar string
+        * @param $joinVar string
         * @param $conds array|string
         * @param $fname bool
-        * @return bool|\ResultWrapper
+        * @return bool|ResultWrapper
         */
        function deleteJoin( $delTable, $joinTable, $delVar, $joinVar, $conds, $fname = 'DatabaseBase::deleteJoin' ) {
                if ( !$conds ) {
@@ -850,7 +882,7 @@ class DatabaseMysql extends DatabaseBase {
        /**
         * List all tables on the database
         *
-        * @param $prefix Only show tables with this prefix, e.g. mw_
+        * @param $prefix string Only show tables with this prefix, e.g. mw_
         * @param $fname String: calling function name
         * @return array
         */