(bug 20256) Fixed SQL errors on Special:Recentchanges and Special:Recentchangeslinked...
authorMax Semenik <maxsem@users.mediawiki.org>
Sat, 17 Oct 2009 12:23:23 +0000 (12:23 +0000)
committerMax Semenik <maxsem@users.mediawiki.org>
Sat, 17 Oct 2009 12:23:23 +0000 (12:23 +0000)
RELEASE-NOTES
includes/db/Database.php
includes/db/DatabaseSqlite.php
includes/specials/SpecialRecentchanges.php
includes/specials/SpecialRecentchangeslinked.php

index 9b0713c..6fefee4 100644 (file)
@@ -562,6 +562,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * (bug 21116) MediaWiki:Templatesused, MediaWiki:Templatesusedpreview and
   MediaWiki:Templatesusedsection now support plural
 * (bug 21079) There is no more line wrapping between label and field in Special:Log
+* (bug 20256) Fixed SQL errors on Special:Recentchanges and Special:Recentchangeslinked
+  on SQLite backend
 
 == API changes in 1.16 ==
 
index 34e33db..c8deb33 100644 (file)
@@ -1695,6 +1695,15 @@ abstract class DatabaseBase {
                return $this->limitResult( $sql, $num, 0 );
        }
 
+       /**
+        * Returns true if current database backend supports ORDER BY or LIMIT for separate subqueries 
+        * within the UNION construct.
+        * @return Boolean
+        */
+       function unionSupportsOrderAndLimit() {
+               return true; // True for almost every DB supported
+       }
+
        /**
         * Construct a UNION query
         * This is used for providing overload point for other DB abstractions
index 1eb4910..e9fe549 100644 (file)
@@ -299,6 +299,15 @@ class DatabaseSqlite extends DatabaseBase {
                return - 1;
        }
 
+       function unionSupportsOrderAndLimit() {
+               return false;
+       }
+
+       function unionQueries( $sqls, $all ) {
+               $glue = $all ? ' UNION ALL ' : ' UNION ';
+               return implode( $glue, $sqls );
+       }
+
        function wasDeadlock() {
                return $this->lastErrno() == SQLITE_BUSY;
        }
index 85ace3c..1d38e57 100644 (file)
@@ -306,7 +306,11 @@ class SpecialRecentChanges extends SpecialPage {
                // Is there either one namespace selected or excluded?
                // Tag filtering also has a better index.
                // Also, if this is "all" or main namespace, just use timestamp index.
-               if( is_null($namespace) || $invert || $opts['tagfilter'] ) {
+               if( is_null($namespace)
+                       || $invert
+                       || $opts['tagfilter'] 
+                       || !$dbr->unionSupportsOrderAndLimit() )
+               {
                        $res = $dbr->select( $tables, '*', $conds, __METHOD__,
                                array( 'ORDER BY' => 'rc_timestamp DESC', 'LIMIT' => $limit ) +
                                $query_options,
index a5bd098..d84ffa3 100644 (file)
@@ -144,19 +144,30 @@ class SpecialRecentchangeslinked extends SpecialRecentchanges {
                                }
                        }
 
-                       $subsql[] = $dbr->selectSQLText( 
+                       if( $dbr->unionSupportsOrderAndLimit())
+                               $order = array( 'ORDER BY' => 'rc_timestamp DESC' );
+                       else
+                               $order = array();
+
+                       
+                       $query = $dbr->selectSQLText( 
                                array_merge( $tables, array( $link_table ) ), 
                                $select, 
                                $conds + $subconds,
                                __METHOD__, 
-                               array( 'ORDER BY' => 'rc_timestamp DESC', 'LIMIT' => $limit ) + $query_options,
+                               $order + $query_options,
                                $join_conds + array( $link_table => array( 'INNER JOIN', $subjoin ) )
                        );
+                       
+                       if( $dbr->unionSupportsOrderAndLimit())
+                               $query = $dbr->limitResult( $query, $limit );
+
+                       $subsql[] = $query;
                }
 
                if( count($subsql) == 0 )
                        return false; // should never happen
-               if( count($subsql) == 1 )
+               if( count($subsql) == 1 && $dbr->unionSupportsOrderAndLimit() )
                        $sql = $subsql[0];
                else {
                        // need to resort and relimit after union