diff --git a/ChangeLog b/ChangeLog index 4a0c3389e..c206d152c 100755 --- a/ChangeLog +++ b/ChangeLog @@ -9,6 +9,7 @@ $Source$ * merge patch 507338, thanks to Adam Ashley (fruitcak) * galician updates, thanks to Xosé Calvo. * czech* updates, thanks to Michal Cihar (nijel) + * sql.php3: bug 506558 (QBE returns unlimited rows) 2002-01-23 Olivier Müller * translated the last german words diff --git a/sql.php3 b/sql.php3 index d63e59e5f..510d5f5ac 100755 --- a/sql.php3 +++ b/sql.php3 @@ -198,8 +198,11 @@ else { // Do append a "LIMIT" clause? if (isset($pos) && (!$cfgShowAll || $session_max_rows != 'all') - && ($is_select && !($is_count || $is_export) && eregi(' FROM ', $sql_query)) - && !eregi(' LIMIT[ 0-9,]+$', $sql_query)) { + && $is_select + && !($is_count || $is_export) + && eregi('[[:space:]]FROM[[:space:]]', $sql_query) + && !eregi('[[:space:]]LIMIT[ 0-9,]+$', $sql_query)) { + $sql_limit_to_append = " LIMIT $pos, $cfgMaxRows"; if (eregi('(.*)( PROCEDURE (.*)| FOR UPDATE| LOCK IN SHARE MODE)$', $sql_query, $regs)) { $full_sql_query = $regs[1] . $sql_limit_to_append . $regs[2]; @@ -254,7 +257,14 @@ else { } else if ($is_select) { // reads only the from-part of the query... - $array = split(' from | FROM | order | ORDER | having | HAVING | limit | LIMIT | group by | GROUP BY', $sql_query); + $sp='[[:space:]]'; + $array = split( + $sp . 'from' . $sp .'|' . $sp . 'FROM' .$sp . + '|' . $sp .'order' . $sp . '|' . $sp . 'ORDER' . $sp . + '|' . $sp .'having' . $sp . '|' . $sp . 'HAVING' . $sp . + '|' . $sp .'limit' . $sp . '|' . $sp . 'LIMIT' . $sp . + '|' . $sp .'group' . $sp . 'by'. $sp . + '|' . $sp . 'GROUP' . $sp . 'BY' . $sp, $sql_query); if (!empty($array[1])) { // ... and makes a count(*) to count the entries $count_query = 'SELECT COUNT(*) AS count FROM ' . $array[1];