Preparations for Oracle database abstraction update. Take II.
authorJure Kajzer <freakolowsky@users.mediawiki.org>
Tue, 19 May 2009 16:58:56 +0000 (16:58 +0000)
committerJure Kajzer <freakolowsky@users.mediawiki.org>
Tue, 19 May 2009 16:58:56 +0000 (16:58 +0000)
Replaced hardcoded LIMIT clauses with database function (except in maintenance).
Created unionQueries in Database and overloaded it in DatabaseOracle (not commited yet).
Replaced all UNION clauses with function calls (except in maintenance).

includes/db/Database.php
includes/specials/SpecialRecentchanges.php
includes/specials/SpecialRecentchangeslinked.php

index 8d3d25a..f5c482e 100644 (file)
@@ -1828,6 +1828,19 @@ class Database {
                return $this->limitResult($sql, $num, 0);
        }
 
+       /**
+        * Construct a UNION query
+        * This is used for providing overload point for other DB abstractions
+        * not compatible with the MySQL syntax.
+        * @param $sqls Array: SQL statements to combine
+        * @param $all Boolean: use UNION ALL
+        * @return String: SQL fragment
+        */
+       function unionQueries($sqls, $all) {
+               $glue = $all ? ') UNION ALL (' : ') UNION (';
+               return '('.implode( $glue, $sqls ) . ')';
+       }
+
        /**
         * Returns an SQL expression for a simple conditional.
         * Uses IF on MySQL.
index 2972a7f..f842cba 100644 (file)
@@ -328,7 +328,8 @@ class SpecialRecentChanges extends SpecialPage {
                                        'USE INDEX' =>  array('recentchanges' => 'new_name_timestamp') ),
                                $join_conds );
                        # Join the two fast queries, and sort the result set
-                       $sql = "($sqlNew) UNION ($sqlOld) ORDER BY rc_timestamp DESC LIMIT $limit";
+                       $sql = $dbr->unionQueries(array($sqlNew, $sqlOld), false).' ORDER BY rc_timestamp DESC';
+                       $sql = $dbr->limitResult($sql, $limit, false);
                        $res = $dbr->query( $sql, __METHOD__ );
                }
 
index 82aa5b9..38f79db 100644 (file)
@@ -155,9 +155,10 @@ class SpecialRecentchangeslinked extends SpecialRecentchanges {
                        $sql = $subsql[0];
                else {
                        // need to resort and relimit after union
-                       $sql = "(" . implode( ") UNION (", $subsql ) . ") ORDER BY rc_timestamp DESC LIMIT {$limit}";
+                       $sql = $dbr->unionQueries($subsql, false).' ORDER BY rc_timestamp DESC';
+                       $sql = $dbr->limitResult($sql, $limit, false);
                }
-
+               
                $res = $dbr->query( $sql, __METHOD__ );
 
                if( $res->numRows() == 0 )