Index: trunk/phase3/includes/db/Database.php |
— | — | @@ -1829,6 +1829,19 @@ |
1830 | 1830 | } |
1831 | 1831 | |
1832 | 1832 | /** |
| 1833 | + * Construct a UNION query |
| 1834 | + * This is used for providing overload point for other DB abstractions |
| 1835 | + * not compatible with the MySQL syntax. |
| 1836 | + * @param $sqls Array: SQL statements to combine |
| 1837 | + * @param $all Boolean: use UNION ALL |
| 1838 | + * @return String: SQL fragment |
| 1839 | + */ |
| 1840 | + function unionQueries($sqls, $all) { |
| 1841 | + $glue = $all ? ') UNION ALL (' : ') UNION ('; |
| 1842 | + return '('.implode( $glue, $sqls ) . ')'; |
| 1843 | + } |
| 1844 | + |
| 1845 | + /** |
1833 | 1846 | * Returns an SQL expression for a simple conditional. |
1834 | 1847 | * Uses IF on MySQL. |
1835 | 1848 | * |
Index: trunk/phase3/includes/specials/SpecialRecentchangeslinked.php |
— | — | @@ -155,9 +155,10 @@ |
156 | 156 | $sql = $subsql[0]; |
157 | 157 | else { |
158 | 158 | // need to resort and relimit after union |
159 | | - $sql = "(" . implode( ") UNION (", $subsql ) . ") ORDER BY rc_timestamp DESC LIMIT {$limit}"; |
| 159 | + $sql = $dbr->unionQueries($subsql, false).' ORDER BY rc_timestamp DESC'; |
| 160 | + $sql = $dbr->limitResult($sql, $limit, false); |
160 | 161 | } |
161 | | - |
| 162 | + |
162 | 163 | $res = $dbr->query( $sql, __METHOD__ ); |
163 | 164 | |
164 | 165 | if( $res->numRows() == 0 ) |
Index: trunk/phase3/includes/specials/SpecialRecentchanges.php |
— | — | @@ -328,7 +328,8 @@ |
329 | 329 | 'USE INDEX' => array('recentchanges' => 'new_name_timestamp') ), |
330 | 330 | $join_conds ); |
331 | 331 | # Join the two fast queries, and sort the result set |
332 | | - $sql = "($sqlNew) UNION ($sqlOld) ORDER BY rc_timestamp DESC LIMIT $limit"; |
| 332 | + $sql = $dbr->unionQueries(array($sqlNew, $sqlOld), false).' ORDER BY rc_timestamp DESC'; |
| 333 | + $sql = $dbr->limitResult($sql, $limit, false); |
333 | 334 | $res = $dbr->query( $sql, __METHOD__ ); |
334 | 335 | } |
335 | 336 | |