Merge "rdbms: avoid strange uses of empty()"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Fri, 2 Mar 2018 19:13:58 +0000 (19:13 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Fri, 2 Mar 2018 19:13:58 +0000 (19:13 +0000)
1  2 
includes/libs/rdbms/database/Database.php
includes/libs/rdbms/database/DatabaseMysqlBase.php

@@@ -1435,27 -1435,14 +1435,27 @@@ abstract class Database implements IDat
                list( $startOpts, $useIndex, $preLimitTail, $postLimitTail, $ignoreIndex ) =
                        $this->makeSelectOptions( $options );
  
 -              if ( !empty( $conds ) ) {
 -                      if ( is_array( $conds ) ) {
 -                              $conds = $this->makeList( $conds, self::LIST_AND );
 -                      }
 +              if ( is_array( $conds ) ) {
 +                      $conds = $this->makeList( $conds, self::LIST_AND );
 +              }
 +
 +              if ( $conds === null || $conds === false ) {
 +                      $this->queryLogger->warning(
 +                              __METHOD__
 +                              . ' called from '
 +                              . $fname
 +                              . ' with incorrect parameters: $conds must be a string or an array'
 +                      );
 +                      $conds = '';
 +              }
 +
 +              if ( $conds === '' ) {
 +                      $sql = "SELECT $startOpts $vars $from $useIndex $ignoreIndex $preLimitTail";
 +              } elseif ( is_string( $conds ) ) {
                        $sql = "SELECT $startOpts $vars $from $useIndex $ignoreIndex " .
                                "WHERE $conds $preLimitTail";
                } else {
 -                      $sql = "SELECT $startOpts $vars $from $useIndex $ignoreIndex $preLimitTail";
 +                      throw new DBUnexpectedError( $this, __METHOD__ . ' called with incorrect parameters' );
                }
  
                if ( isset( $options['LIMIT'] ) ) {
                }
  
                // We can't separate explicit JOIN clauses with ',', use ' ' for those
-               $implicitJoins = !empty( $ret ) ? implode( ',', $ret ) : "";
-               $explicitJoins = !empty( $retJOIN ) ? implode( ' ', $retJOIN ) : "";
+               $implicitJoins = $ret ? implode( ',', $ret ) : "";
+               $explicitJoins = $retJOIN ? implode( ' ', $retJOIN ) : "";
  
                // Compile our final table clause
                return implode( ' ', [ $implicitJoins, $explicitJoins ] );
@@@ -527,16 -527,13 +527,16 @@@ abstract class DatabaseMysqlBase extend
                // checking if the target table has an auto-increment column that
                // isn't set in $varMap, that seems unlikely to be worth the extra
                // complexity.
 -              return ( (int)$row->innodb_autoinc_lock_mode === 0 );
 +              return (
 +                      in_array( 'NO_AUTO_COLUMNS', $insertOptions ) ||
 +                      (int)$row->innodb_autoinc_lock_mode === 0
 +              );
        }
  
        /**
         * @return stdClass Process cached row
         */
 -      private function getReplicationSafetyInfo() {
 +      protected function getReplicationSafetyInfo() {
                if ( $this->replicationInfoRow === null ) {
                        $this->replicationInfoRow = $this->selectRow(
                                false,
                        }
                }
  
-               return empty( $result ) ? false : $result;
+               return $result ?: false;
        }
  
        /**