From: Jure Kajzer Date: Tue, 19 May 2009 16:58:56 +0000 (+0000) Subject: Preparations for Oracle database abstraction update. Take II. X-Git-Tag: 1.31.0-rc.0~41739 X-Git-Url: https://git.heureux-cyclage.org/?a=commitdiff_plain;h=95f953b5c30b28f5d0d30950700da70d805155c9;p=lhc%2Fweb%2Fwiklou.git Preparations for Oracle database abstraction update. Take II. 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). --- diff --git a/includes/db/Database.php b/includes/db/Database.php index 8d3d25a7b3..f5c482e384 100644 --- a/includes/db/Database.php +++ b/includes/db/Database.php @@ -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. diff --git a/includes/specials/SpecialRecentchanges.php b/includes/specials/SpecialRecentchanges.php index 2972a7fb83..f842cbae4f 100644 --- a/includes/specials/SpecialRecentchanges.php +++ b/includes/specials/SpecialRecentchanges.php @@ -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__ ); } diff --git a/includes/specials/SpecialRecentchangeslinked.php b/includes/specials/SpecialRecentchangeslinked.php index 82aa5b98e3..38f79dbca1 100644 --- a/includes/specials/SpecialRecentchangeslinked.php +++ b/includes/specials/SpecialRecentchangeslinked.php @@ -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 )