Merge "Use utf8 charset for searchindex MySQL table"
[lhc/web/wiklou.git] / includes / db / DatabaseMssql.php
index 82b0e5a..240a097 100644 (file)
@@ -96,7 +96,7 @@ class DatabaseMssql extends DatabaseBase {
 
                $connectionInfo = array();
 
-               if( $dbName ) {
+               if ( $dbName ) {
                        $connectionInfo['Database'] = $dbName;
                }
 
@@ -109,7 +109,7 @@ class DatabaseMssql extends DatabaseBase {
                $ntAuthPassTest = strtolower( $password );
 
                // Decide which auth scenerio to use
-               if( $ntAuthPassTest == 'ntauth' && $ntAuthUserTest == 'ntauth' ) {
+               if ( $ntAuthPassTest == 'ntauth' && $ntAuthUserTest == 'ntauth' ) {
                        // Don't add credentials to $connectionInfo
                } else {
                        $connectionInfo['UID'] = $user;
@@ -297,7 +297,7 @@ class DatabaseMssql extends DatabaseBase {
         *                                                 (e.g. array( 'page' => array('LEFT JOIN','page_latest=rev_id') )
         * @return Mixed: database result resource (feed to Database::fetchObject or whatever), or false on failure
         */
-       function select( $table, $vars, $conds = '', $fname = 'DatabaseMssql::select', $options = array(), $join_conds = array() )
+       function select( $table, $vars, $conds = '', $fname = __METHOD__, $options = array(), $join_conds = array() )
        {
                $sql = $this->selectSQLText( $table, $vars, $conds, $fname, $options, $join_conds );
                if ( isset( $options['EXPLAIN'] ) ) {
@@ -322,7 +322,7 @@ class DatabaseMssql extends DatabaseBase {
         *                    (e.g. array( 'page' => array('LEFT JOIN','page_latest=rev_id') )
         * @return string, the SQL text
         */
-       function selectSQLText( $table, $vars, $conds = '', $fname = 'DatabaseMssql::select', $options = array(), $join_conds = array() ) {
+       function selectSQLText( $table, $vars, $conds = '', $fname = __METHOD__, $options = array(), $join_conds = array() ) {
                if ( isset( $options['EXPLAIN'] ) ) {
                        unset( $options['EXPLAIN'] );
                }
@@ -337,14 +337,16 @@ class DatabaseMssql extends DatabaseBase {
         * Takes same arguments as Database::select()
         * @return int
         */
-       function estimateRowCount( $table, $vars = '*', $conds = '', $fname = 'DatabaseMssql::estimateRowCount', $options = array() ) {
+       function estimateRowCount( $table, $vars = '*', $conds = '', $fname = __METHOD__, $options = array() ) {
                $options['EXPLAIN'] = true;// http://msdn2.microsoft.com/en-us/library/aa259203.aspx
                $res = $this->select( $table, $vars, $conds, $fname, $options );
 
                $rows = -1;
                if ( $res ) {
                        $row = $this->fetchRow( $res );
-                       if ( isset( $row['EstimateRows'] ) ) $rows = $row['EstimateRows'];
+                       if ( isset( $row['EstimateRows'] ) ) {
+                               $rows = $row['EstimateRows'];
+                       }
                }
                return $rows;
        }
@@ -354,7 +356,7 @@ class DatabaseMssql extends DatabaseBase {
         * If errors are explicitly ignored, returns NULL on failure
         * @return array|bool|null
         */
-       function indexInfo( $table, $index, $fname = 'DatabaseMssql::indexExists' ) {
+       function indexInfo( $table, $index, $fname = __METHOD__ ) {
                # This does not return the same info as MYSQL would, but that's OK because MediaWiki never uses the
                # returned value except to check for the existance of indexes.
                $sql = "sp_helpindex '" . $table . "'";
@@ -399,7 +401,7 @@ class DatabaseMssql extends DatabaseBase {
         * @throws DBQueryError
         * @return bool
         */
-       function insert( $table, $arrToInsert, $fname = 'DatabaseMssql::insert', $options = array() ) {
+       function insert( $table, $arrToInsert, $fname = __METHOD__, $options = array() ) {
                # No rows to insert, easy just return now
                if ( !count( $arrToInsert ) ) {
                        return true;
@@ -421,7 +423,7 @@ class DatabaseMssql extends DatabaseBase {
                $identity = null;
                $tableRaw = preg_replace( '#\[([^\]]*)\]#', '$1', $table ); // strip matching square brackets from table name
                $res = $this->doQuery( "SELECT NAME AS idColumn FROM SYS.IDENTITY_COLUMNS WHERE OBJECT_NAME(OBJECT_ID)='{$tableRaw}'" );
-               if( $res && $res->numrows() ) {
+               if ( $res && $res->numrows() ) {
                        // There is an identity for this table.
                        $identity = array_pop( $res->fetch( SQLSRV_FETCH_ASSOC ) );
                }
@@ -434,11 +436,11 @@ class DatabaseMssql extends DatabaseBase {
                        $identityClause = '';
 
                        // if we have an identity column
-                       if( $identity ) {
+                       if ( $identity ) {
                                // iterate through
                                foreach ( $a as $k => $v ) {
                                        if ( $k == $identity ) {
-                                               if( !is_null( $v ) ) {
+                                               if ( !is_null( $v ) ) {
                                                        // there is a value being passed to us, we need to turn on and off inserted identity
                                                        $sqlPre = "SET IDENTITY_INSERT $table ON;";
                                                        $sqlPost = ";SET IDENTITY_INSERT $table OFF;";
@@ -537,7 +539,7 @@ class DatabaseMssql extends DatabaseBase {
         * @throws DBQueryError
         * @return null|ResultWrapper
         */
-       function insertSelect( $destTable, $srcTable, $varMap, $conds, $fname = 'DatabaseMssql::insertSelect',
+       function insertSelect( $destTable, $srcTable, $varMap, $conds, $fname = __METHOD__,
                $insertOptions = array(), $selectOptions = array() ) {
                $ret = parent::insertSelect( $destTable, $srcTable, $varMap, $conds, $fname, $insertOptions, $selectOptions );
 
@@ -652,7 +654,7 @@ class DatabaseMssql extends DatabaseBase {
        /**
         * @return string wikitext of a link to the server software's web site
         */
-       public static function getSoftwareLink() {
+       public function getSoftwareLink() {
                return "[http://www.microsoft.com/sql/ MS SQL Server]";
        }
 
@@ -672,7 +674,7 @@ class DatabaseMssql extends DatabaseBase {
                $res = sqlsrv_query( $this->mConn, "SELECT * FROM information_schema.tables
                        WHERE table_type='BASE TABLE' AND table_name = '$table'" );
                if ( $res === false ) {
-                       print( "Error in tableExists query: " . $this->getErrors() );
+                       print "Error in tableExists query: " . $this->getErrors();
                        return false;
                }
                if ( sqlsrv_fetch( $res ) ) {
@@ -686,12 +688,12 @@ class DatabaseMssql extends DatabaseBase {
         * Query whether a given column exists in the mediawiki schema
         * @return bool
         */
-       function fieldExists( $table, $field, $fname = 'DatabaseMssql::fieldExists' ) {
+       function fieldExists( $table, $field, $fname = __METHOD__ ) {
                $table = $this->tableName( $table );
                $res = sqlsrv_query( $this->mConn, "SELECT DATA_TYPE FROM INFORMATION_SCHEMA.Columns
                        WHERE TABLE_NAME = '$table' AND COLUMN_NAME = '$field'" );
                if ( $res === false ) {
-                       print( "Error in fieldExists query: " . $this->getErrors() );
+                       print "Error in fieldExists query: " . $this->getErrors();
                        return false;
                }
                if ( sqlsrv_fetch( $res ) ) {
@@ -706,7 +708,7 @@ class DatabaseMssql extends DatabaseBase {
                $res = sqlsrv_query( $this->mConn, "SELECT * FROM INFORMATION_SCHEMA.Columns
                        WHERE TABLE_NAME = '$table' AND COLUMN_NAME = '$field'" );
                if ( $res === false ) {
-                       print( "Error in fieldInfo query: " . $this->getErrors() );
+                       print "Error in fieldInfo query: " . $this->getErrors();
                        return false;
                }
                $meta = $this->fetchRow( $res );
@@ -719,7 +721,7 @@ class DatabaseMssql extends DatabaseBase {
        /**
         * Begin a transaction, committing any previously open transaction
         */
-       protected function doBegin( $fname = 'DatabaseMssql::begin' ) {
+       protected function doBegin( $fname = __METHOD__ ) {
                sqlsrv_begin_transaction( $this->mConn );
                $this->mTrxLevel = 1;
        }
@@ -727,7 +729,7 @@ class DatabaseMssql extends DatabaseBase {
        /**
         * End a transaction
         */
-       protected function doCommit( $fname = 'DatabaseMssql::commit' ) {
+       protected function doCommit( $fname = __METHOD__ ) {
                sqlsrv_commit( $this->mConn );
                $this->mTrxLevel = 0;
        }
@@ -736,7 +738,7 @@ class DatabaseMssql extends DatabaseBase {
         * Rollback a transaction.
         * No-op on non-transactional databases.
         */
-       protected function doRollback( $fname = 'DatabaseMssql::rollback' ) {
+       protected function doRollback( $fname = __METHOD__ ) {
                sqlsrv_rollback( $this->mConn );
                $this->mTrxLevel = 0;
        }
@@ -1009,7 +1011,7 @@ class MssqlResult {
 
                $rows = sqlsrv_fetch_array( $queryresult, SQLSRV_FETCH_ASSOC );
 
-               foreach( $rows as $row ) {
+               foreach ( $rows as $row ) {
                        if ( $row !== null ) {
                                foreach ( $row as $k => $v ) {
                                        if ( is_object( $v ) && method_exists( $v, 'format' ) ) {// DateTime Object
@@ -1047,7 +1049,7 @@ class MssqlResult {
                                $arrNum[] = $value;
                        }
                }
-               switch( $mode ) {
+               switch ( $mode ) {
                        case SQLSRV_FETCH_ASSOC:
                                $ret = $this->mRows[$this->mCursor];
                                break;