r95449 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r95448‎ | r95449 | r95450 >
Date:21:38, 24 August 2011
Author:reedy
Status:resolved (Comments)
Tags:
Comment:
Allow update to be passed an empty array for the WHERE condition
Modified paths:
  • /trunk/phase3/includes/db/Database.php (modified) (history)
  • /trunk/phase3/includes/db/DatabaseOracle.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/db/Database.php
@@ -1693,7 +1693,7 @@
16941694 $opts = $this->makeUpdateOptions( $options );
16951695 $sql = "UPDATE $opts $table SET " . $this->makeList( $values, LIST_SET );
16961696
1697 - if ( $conds != '*' ) {
 1697+ if ( $conds != '*' || ( is_array( $conds ) && count( $conds ) ) ) {
16981698 $sql .= " WHERE " . $this->makeList( $conds, LIST_AND );
16991699 }
17001700
Index: trunk/phase3/includes/db/DatabaseOracle.php
@@ -1194,7 +1194,7 @@
11951195 $sql .= $sqlSet;
11961196 }
11971197
1198 - if ( $conds != '*' ) {
 1198+ if ( $conds != '*' || ( is_array( $conds ) && count( $conds ) ) ) {
11991199 $conds = $this->wrapConditionsForWhere( $table, $conds );
12001200 $sql .= ' WHERE ' . $this->makeList( $conds, LIST_AND );
12011201 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r95497Followup r95449, fix the code to do what it was actually intended to doreedy17:47, 25 August 2011

Comments

#Comment by Catrope (talk | contribs)   17:36, 25 August 2011

This seems wrong? If $conds is an array, won't $conds != '*' be true?

#Comment by Reedy (talk | contribs)   17:42, 25 August 2011

The idea was to not build a WHERE if $conds is passed in as an empty array.

You're right though, that array() != '*'...

Swap it for?

if ( ( is_array( $conds ) && count( $conds ) ) || ( is_string( $conds ) && $conds != '*' ) {
/
#Comment by Catrope (talk | contribs)   17:45, 25 August 2011

Shorter by using strict comparison:

if ( $conds !== array() && $conds !== '*' ) {

Status & tagging log