r102299 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r102298‎ | r102299 | r102300 >
Date:17:19, 7 November 2011
Author:platonides
Status:ok (Comments)
Tags:
Comment:
Allow raw conditions on insertSelect, given that array syntax isn't always expressive enough (r96930)
Modified paths:
  • /trunk/phase3/includes/db/Database.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/db/Database.php
@@ -2531,7 +2531,10 @@
25322532 " FROM $srcTable $useIndex ";
25332533
25342534 if ( $conds != '*' ) {
2535 - $sql .= ' WHERE ' . $this->makeList( $conds, LIST_AND );
 2535+ if ( is_array( $conds ) ) {
 2536+ $conds = $this->makeList( $conds, LIST_AND );
 2537+ }
 2538+ $sql .= " WHERE $conds";
25362539 }
25372540
25382541 $sql .= " $tailOpts";

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r96930Revert r87992 and followups r87998, r89028 (Support abstraction for 'NOT IN' ...demon00:19, 13 September 2011

Comments

#Comment by Nikerabbit (talk | contribs)   08:23, 8 November 2011

What part of it isn't expressive enough? Can't one do array( "any sql here" )?

#Comment by Platonides (talk | contribs)   16:03, 8 November 2011

No. That's not free sql, but a field value. So using $db->makeList(array("foo is not in ( 'a', 'b') ")); you get

'foo is not in ( \'a\', \'b\') '

not the expected SQL.

Abstraction for NOT IN was added in r87992, but removed in r96930.

So instead of array("oi_sha1!" => $badKeys) I have to use this ugly code

 count ( $badKeys ) ? "oi_sha1 NOT IN (" . $db->makeList( $badKeys ) . ")" : "*"

plus this change to allow free SQL text. :(

Status & tagging log