X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fdb%2FDatabaseMssql.php;h=2b8f395f8f60c22c0fc7afda6d4f8873f6fc3da8;hb=8b1a78fa5e62923d6dea1f9fe578c46b2910155e;hp=a7bc6dd621c12beb53936d5b6c4488b193755f6e;hpb=8c3738e088f377642c540a0ccddb01b16ba7116b;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/db/DatabaseMssql.php b/includes/db/DatabaseMssql.php index a7bc6dd621..2b8f395f8f 100644 --- a/includes/db/DatabaseMssql.php +++ b/includes/db/DatabaseMssql.php @@ -518,7 +518,7 @@ class DatabaseMssql extends DatabaseBase { $row = $this->fetchRow( $res ); if ( isset( $row['EstimateRows'] ) ) { - $rows = $row['EstimateRows']; + $rows = (int)$row['EstimateRows']; } } @@ -812,64 +812,27 @@ class DatabaseMssql extends DatabaseBase { 'DatabaseBase::makeList called with incorrect parameters' ); } - $first = true; - $list = ''; + if ( $mode != LIST_NAMES ) { + // In MS SQL, values need to be specially encoded when they are + // inserted into binary fields. Perform this necessary encoding + // for the specified set of columns. + foreach ( array_keys( $a ) as $field ) { + if ( !isset( $binaryColumns[$field] ) ) { + continue; + } - foreach ( $a as $field => $value ) { - if ( $mode != LIST_NAMES && isset( $binaryColumns[$field] ) ) { - if ( is_array( $value ) ) { - foreach ( $value as &$v ) { + if ( is_array( $a[$field] ) ) { + foreach ( $a[$field] as &$v ) { $v = new MssqlBlob( $v ); } + unset( $v ); } else { - $value = new MssqlBlob( $value ); - } - } - - if ( !$first ) { - if ( $mode == LIST_AND ) { - $list .= ' AND '; - } elseif ( $mode == LIST_OR ) { - $list .= ' OR '; - } else { - $list .= ','; + $a[$field] = new MssqlBlob( $a[$field] ); } - } else { - $first = false; - } - - if ( ( $mode == LIST_AND || $mode == LIST_OR ) && is_numeric( $field ) ) { - $list .= "($value)"; - } elseif ( ( $mode == LIST_SET ) && is_numeric( $field ) ) { - $list .= "$value"; - } elseif ( ( $mode == LIST_AND || $mode == LIST_OR ) && is_array( $value ) ) { - if ( count( $value ) == 0 ) { - throw new MWException( __METHOD__ . ": empty input for field $field" ); - } elseif ( count( $value ) == 1 ) { - // Special-case single values, as IN isn't terribly efficient - // Don't necessarily assume the single key is 0; we don't - // enforce linear numeric ordering on other arrays here. - $value = array_values( $value ); - $list .= $field . " = " . $this->addQuotes( $value[0] ); - } else { - $list .= $field . " IN (" . $this->makeList( $value ) . ") "; - } - } elseif ( $value === null ) { - if ( $mode == LIST_AND || $mode == LIST_OR ) { - $list .= "$field IS "; - } elseif ( $mode == LIST_SET ) { - $list .= "$field = "; - } - $list .= 'NULL'; - } else { - if ( $mode == LIST_AND || $mode == LIST_OR || $mode == LIST_SET ) { - $list .= "$field = "; - } - $list .= $mode == LIST_NAMES ? $value : $this->addQuotes( $value ); } } - return $list; + return parent::makeList( $a, $mode ); } /** @@ -1131,7 +1094,7 @@ class DatabaseMssql extends DatabaseBase { } /** - * @param string $s + * @param string|Blob $s * @return string */ public function addQuotes( $s ) {