diff --git a/ChangeLog b/ChangeLog index 42c0c8824..ed3a3fb57 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11,6 +11,10 @@ $Source$ I find it faster this way, please tell me if you prefer the old dialog method and why. * tbl_change.php: bug #1038401, tabbing from value to value + * sql.php: detect this case: + SELECT DISTINCT x AS foo, y AS bar FROM sometable + and count rows correctly (in MySQL 3), + thanks to Matthias Pigulla (mp@webfactory.de) 2004-10-13 Michal Čihař * libraries/fpdf/fpdf.php: Updated to 1.52. diff --git a/sql.php b/sql.php index 3ca2eb2df..a4b0a1e8e 100644 --- a/sql.php +++ b/sql.php @@ -437,13 +437,20 @@ else { } else { // n o t " j u s t b r o w s i n g " if (PMA_MYSQL_INT_VERSION < 40000) { - // TODO: detect DISTINCT in the parser - if (stristr($sql_query, 'DISTINCT')) { - $count_what = 'DISTINCT ' . $analyzed_sql[0]['select_expr_clause']; - } else { - $count_what = '*'; - } + // detect this case: + // SELECT DISTINCT x AS foo, y AS bar FROM sometable + + if (isset($analyzed_sql[0]['queryflags']['distinct'])) { + $count_what = 'DISTINCT '; + $first_expr = TRUE; + foreach($analyzed_sql[0]['select_expr'] as $part) { + $count_what .= (!$first_expr ? ', ' : '') . $part['expr']; + $first_expr = FALSE; + } + } else { + $count_what = '*'; + } $count_query = 'SELECT COUNT(' . $count_what . ') AS count'; }