Revert r87992 and followups r87998, r89028 (Support abstraction for 'NOT IN' SQL...
authorChad Horohoe <demon@users.mediawiki.org>
Tue, 13 Sep 2011 00:19:04 +0000 (00:19 +0000)
committerChad Horohoe <demon@users.mediawiki.org>
Tue, 13 Sep 2011 00:19:04 +0000 (00:19 +0000)
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.

includes/db/Database.php
includes/specials/SpecialRecentchanges.php
tests/phpunit/includes/db/DatabaseTest.php

index 0c9bb8c..1a78a21 100644 (file)
@@ -1712,15 +1712,6 @@ abstract class DatabaseBase implements DatabaseType {
         *      - LIST_SET:            comma separated with field names, like a SET clause
         *      - LIST_NAMES:          comma separated field names
         *
-        * In LIST_AND or LIST_OR modes, you can suffix a field with an exclamation
-        * mark to generate a 'NOT IN' structure.
-        *
-        * Example:
-        *  $db->makeList( array( 'field!' => array( 1,2,3 ) );
-        *
-        *  outputs:
-        *    'field' NOT IN ('1', '2', '3' );
-
         * @return string
         */
        function makeList( $a, $mode = LIST_COMMA ) {
@@ -1744,13 +1735,6 @@ abstract class DatabaseBase implements DatabaseType {
                                $first = false;
                        }
 
-                       // Support 'NOT IN' by suffixing fieldname with an exclamation mark
-                       $not = false;
-                       if( substr($field,-1) == '!' ) {
-                               $not = true;
-                               $field = substr($field, 0, -1 );
-                       }
-
                        if ( ( $mode == LIST_AND || $mode == LIST_OR ) && is_numeric( $field ) ) {
                                $list .= "($value)";
                        } elseif ( ( $mode == LIST_SET ) && is_numeric( $field ) ) {
@@ -1763,12 +1747,9 @@ abstract class DatabaseBase implements DatabaseType {
                                        // Don't necessarily assume the single key is 0; we don't
                                        // enforce linear numeric ordering on other arrays here.
                                        $value = array_values( $value );
-
-                                       $operator = $not ? ' != ' : ' = ';
-                                       $list .= $field . $operator . $this->addQuotes( $value[0] );
+                                       $list .= $field . " = " . $this->addQuotes( $value[0] );
                                } else {
-                                       $operator = $not ? ' NOT IN ' : ' IN ';
-                                       $list .= $field . $operator . "(" . $this->makeList( $value ) . ")";
+                                       $list .= $field . " IN (" . $this->makeList( $value ) . ") ";
                                }
                        } elseif ( $value === null ) {
                                if ( $mode == LIST_AND || $mode == LIST_OR ) {
index 8b9e72a..e53f048 100644 (file)
@@ -325,24 +325,25 @@ class SpecialRecentChanges extends IncludableSpecialPage {
 
                # Namespace filtering
                if( $opts['namespace'] !== '' ) {
-                       $namespaces[] = $opts['namespace'];
+                       $selectedNS = $dbr->addQuotes( $opts['namespace'] );
+                       $operator = $opts['invert'] ? '!='  : '=';
+                       $boolean  = $opts['invert'] ? 'AND' : 'OR';
 
-                       $inversionSuffix = $opts['invert'] ? '!' : '';
-
-                       if( $opts['associated'] ) {
-                               # namespace association (bug 2429)
-                               $namespaces[] = MWNamespace::getAssociated( $opts['namespace'] );
+                       # namespace association (bug 2429)
+                       if( !$opts['associated'] ) {
+                               $condition = "rc_namespace $operator $selectedNS";
+                       } else {
+                               # Also add the associated namespace
+                               $associatedNS = $dbr->addQuotes(
+                                       MWNamespace::getAssociated( $opts['namespace'] )
+                               );
+                               $condition = "(rc_namespace $operator $selectedNS "
+                                                  . $boolean
+                                                  . " rc_namespace $operator $associatedNS)";
                        }
 
-                       $condition = $dbr->makeList(
-                               array( 'rc_namespace' . $inversionSuffix
-                                       => $namespaces ),
-                               LIST_AND
-                       );
-
                        $conds[] = $condition;
                }
-
                return $conds;
        }
 
index 6de510a..d480ac6 100644 (file)
@@ -90,34 +90,6 @@ class DatabaseTest extends MediaWikiTestCase {
                        $sql );
        }
 
-       function testMakeNotInList() {
-               $this->assertEquals(
-                       "field IN ('0','1')",
-                       $this->db->makeList( array(
-                               'field' => array( 0, 1 )
-                       ), LIST_AND )
-               );
-               $this->assertEquals(
-                       "field NOT IN ('0','1')",
-                       $this->db->makeList( array(
-                               'field!' => array( 0, 1 )
-                       ), LIST_AND )
-               );
-
-               // make sure an array with only one value use = or !=
-               $this->assertEquals(
-                       "field = '777'",
-                       $this->db->makeList( array(
-                               'field' => array( 777 )
-                       ), LIST_AND )
-               );
-               $this->assertEquals(
-                       "field != '888'",
-                       $this->db->makeList( array(
-                               'field!' => array( 888 )
-                       ), LIST_AND )
-               );
-       }
 }