r96930 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96929‎ | r96930 | r96931 >
Date:00:19, 13 September 2011
Author:demon
Status:resolved (Comments)
Tags:
Comment:
Revert r87992 and followups r87998, r89028 (Support abstraction for 'NOT IN' SQL structure). Per discussion on CR and elsewhere...we're not 100% sold on the new format yet.

Changing the database api like this should be carefully thought out before we get stuck with it for 6 more years and end up hating it.
Modified paths:
  • /trunk/phase3/includes/db/Database.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialRecentchanges.php (modified) (history)
  • /trunk/phase3/tests/phpunit/includes/db/DatabaseTest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/phpunit/includes/db/DatabaseTest.php
@@ -90,34 +90,6 @@
9191 $sql );
9292 }
9393
94 - function testMakeNotInList() {
95 - $this->assertEquals(
96 - "field IN ('0','1')",
97 - $this->db->makeList( array(
98 - 'field' => array( 0, 1 )
99 - ), LIST_AND )
100 - );
101 - $this->assertEquals(
102 - "field NOT IN ('0','1')",
103 - $this->db->makeList( array(
104 - 'field!' => array( 0, 1 )
105 - ), LIST_AND )
106 - );
107 -
108 - // make sure an array with only one value use = or !=
109 - $this->assertEquals(
110 - "field = '777'",
111 - $this->db->makeList( array(
112 - 'field' => array( 777 )
113 - ), LIST_AND )
114 - );
115 - $this->assertEquals(
116 - "field != '888'",
117 - $this->db->makeList( array(
118 - 'field!' => array( 888 )
119 - ), LIST_AND )
120 - );
121 - }
12294 }
12395
12496
Index: trunk/phase3/includes/db/Database.php
@@ -1712,15 +1712,6 @@
17131713 * - LIST_SET: comma separated with field names, like a SET clause
17141714 * - LIST_NAMES: comma separated field names
17151715 *
1716 - * In LIST_AND or LIST_OR modes, you can suffix a field with an exclamation
1717 - * mark to generate a 'NOT IN' structure.
1718 - *
1719 - * Example:
1720 - * $db->makeList( array( 'field!' => array( 1,2,3 ) );
1721 - *
1722 - * outputs:
1723 - * 'field' NOT IN ('1', '2', '3' );
1724 -
17251716 * @return string
17261717 */
17271718 function makeList( $a, $mode = LIST_COMMA ) {
@@ -1744,13 +1735,6 @@
17451736 $first = false;
17461737 }
17471738
1748 - // Support 'NOT IN' by suffixing fieldname with an exclamation mark
1749 - $not = false;
1750 - if( substr($field,-1) == '!' ) {
1751 - $not = true;
1752 - $field = substr($field, 0, -1 );
1753 - }
1754 -
17551739 if ( ( $mode == LIST_AND || $mode == LIST_OR ) && is_numeric( $field ) ) {
17561740 $list .= "($value)";
17571741 } elseif ( ( $mode == LIST_SET ) && is_numeric( $field ) ) {
@@ -1763,12 +1747,9 @@
17641748 // Don't necessarily assume the single key is 0; we don't
17651749 // enforce linear numeric ordering on other arrays here.
17661750 $value = array_values( $value );
1767 -
1768 - $operator = $not ? ' != ' : ' = ';
1769 - $list .= $field . $operator . $this->addQuotes( $value[0] );
 1751+ $list .= $field . " = " . $this->addQuotes( $value[0] );
17701752 } else {
1771 - $operator = $not ? ' NOT IN ' : ' IN ';
1772 - $list .= $field . $operator . "(" . $this->makeList( $value ) . ")";
 1753+ $list .= $field . " IN (" . $this->makeList( $value ) . ") ";
17731754 }
17741755 } elseif ( $value === null ) {
17751756 if ( $mode == LIST_AND || $mode == LIST_OR ) {
Index: trunk/phase3/includes/specials/SpecialRecentchanges.php
@@ -325,24 +325,25 @@
326326
327327 # Namespace filtering
328328 if( $opts['namespace'] !== '' ) {
329 - $namespaces[] = $opts['namespace'];
 329+ $selectedNS = $dbr->addQuotes( $opts['namespace'] );
 330+ $operator = $opts['invert'] ? '!=' : '=';
 331+ $boolean = $opts['invert'] ? 'AND' : 'OR';
330332
331 - $inversionSuffix = $opts['invert'] ? '!' : '';
332 -
333 - if( $opts['associated'] ) {
334 - # namespace association (bug 2429)
335 - $namespaces[] = MWNamespace::getAssociated( $opts['namespace'] );
 333+ # namespace association (bug 2429)
 334+ if( !$opts['associated'] ) {
 335+ $condition = "rc_namespace $operator $selectedNS";
 336+ } else {
 337+ # Also add the associated namespace
 338+ $associatedNS = $dbr->addQuotes(
 339+ MWNamespace::getAssociated( $opts['namespace'] )
 340+ );
 341+ $condition = "(rc_namespace $operator $selectedNS "
 342+ . $boolean
 343+ . " rc_namespace $operator $associatedNS)";
336344 }
337345
338 - $condition = $dbr->makeList(
339 - array( 'rc_namespace' . $inversionSuffix
340 - => $namespaces ),
341 - LIST_AND
342 - );
343 -
344346 $conds[] = $condition;
345347 }
346 -
347348 return $conds;
348349 }
349350

Follow-up revisions

RevisionCommit summaryAuthorDate
r96932REL1_18: MFT r96930reedy00:33, 13 September 2011
r96950Fix revert artefact of r96930reedy10:59, 13 September 2011
r97036Partial revert r97035, followup r96930: make recentchanges tests pass againdemon03:31, 14 September 2011
r98703Followup r96930: also remove the documentation that describes the reverted be...catrope19:35, 2 October 2011
r102299Allow raw conditions on insertSelect, given that array syntax isn't always ex...platonides17:19, 7 November 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r87992Support abstraction for 'NOT IN' SQL structure...hashar15:39, 13 May 2011
r87998bug 2429 fix up index by using IN / NOT IN instead of (!= and !=)...hashar15:56, 13 May 2011
r89028* Fix db->makeList() spacing...hashar09:03, 28 May 2011

Comments

#Comment by Nikerabbit (talk | contribs)   05:45, 13 September 2011

This came a bit out of the blue.

#Comment by 😂 (talk | contribs)   17:42, 13 September 2011

Brion raised concerns at the initial commit, and I'm inclined to agree with him and Aaron. During our fixme triage yesterday, I expressed a desire to err on the side of caution and revert for now.

#Comment by Nikerabbit (talk | contribs)   06:34, 13 September 2011

[13-Sep-2011 06:32:41] PHP Notice: Undefined variable: not in /www/w/includes/db/Database.php on line 1757

#Comment by 😂 (talk | contribs)   17:40, 13 September 2011

Fixed in the followup.

Status & tagging log