From e9ca48fe4ba3be42f2b76a7030ef70f89fec1aa9 Mon Sep 17 00:00:00 2001 From: Marc Delisle Date: Tue, 24 Jun 2003 12:07:05 +0000 Subject: [PATCH] bug 759568 row count, DISTINCT and MySQL 4 --- ChangeLog | 3 +++ sql.php3 | 12 +++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 98ac7db21..5099cede3 100755 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,9 @@ phpMyAdmin - Changelog $Id$ $Source$ +2003-06-24 Marc Delisle + * sql.php3, bug 759568, row count, DISTINCT and MySQL 4 + 2003-06-23 Marc Delisle * pdf_pages.php3: automatic layout start at 300,300 for better look on the dom-drag scratchboard diff --git a/sql.php3 b/sql.php3 index 9d469fc1b..b79f7e394 100755 --- a/sql.php3 +++ b/sql.php3 @@ -227,8 +227,7 @@ else { // "SELECT COUNT(...) FROM ... GROUP BY ..." $is_explain = $is_count = $is_export = $is_delete = $is_insert = $is_affected = $is_show = $is_maint = $is_analyse = $is_group = $is_func = FALSE; if ($is_select) { // see line 141 - $is_group = eregi('[[:space:]]+(GROUP[[:space:]]+BY|HAVING|SELECT[[:space:]]+DISTINCT)[[:space:]]+', $sql_query); - + $is_group = eregi('(GROUP[[:space:]]+BY|HAVING|SELECT[[:space:]]+DISTINCT)[[:space:]]+', $sql_query); $is_func = !$is_group && (eregi('[[:space:]]+(SUM|AVG|STD|STDDEV|MIN|MAX|BIT_OR|BIT_AND)\s*\(', $sql_query)); $is_count = !$is_group && (eregi('^SELECT[[:space:]]+COUNT\((.*\.+)?.*\)', $sql_query)); $is_export = (eregi('[[:space:]]+INTO[[:space:]]+OUTFILE[[:space:]]+', $sql_query)); @@ -355,13 +354,12 @@ else { // because SQL_CALC_FOUND_ROWS // is not quick on large InnoDB tables - if (!isset($analyzed_sql[0]['table_ref'][1]['table_name']) + if (!$is_group && !isset($analyzed_sql[0]['table_ref'][1]['table_name']) && (empty($analyzed_sql[0]['where_clause']) || $analyzed_sql[0]['where_clause'] == '1 ')) { // "just browsing" $unlim_num_rows = PMA_countRecords($db, $table, TRUE); - } else { // not "just browsing" if (PMA_MYSQL_INT_VERSION < 40000) { @@ -388,7 +386,11 @@ else { // add select expression after the SQL_CALC_FOUND_ROWS if (PMA_MYSQL_INT_VERSION >= 40000) { - $count_query .= $analyzed_sql[0]['select_expr_clause']; + if (eregi('DISTINCT(.*)', $sql_query)) { + $count_query .= 'DISTINCT ' . $analyzed_sql[0]['select_expr_clause']; + } else { + $count_query .= $analyzed_sql[0]['select_expr_clause']; + } }