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).
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.
'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__ );
}
$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 )