From 192b534b95db07714dd392a4e0fd9759fdad8920 Mon Sep 17 00:00:00 2001 From: Madhura Jayaratne Date: Wed, 28 Sep 2011 15:30:13 +0530 Subject: [PATCH] bug #3356456 [interface] Interface problems for queries having LIMIT clauses --- ChangeLog | 1 + libraries/common.lib.php | 15 +++++++++++++++ libraries/display_tbl.lib.php | 25 +++++++++++++++++++------ 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 576bd5c428..04ce19b079 100644 --- a/ChangeLog +++ b/ChangeLog @@ -48,6 +48,7 @@ phpMyAdmin - ChangeLog + [import] Import GIS data from ESRI Shapefiles + [interface] 'Function based search' for GIS data + Support Drizzle database +- bug #3356456 [interface] Interface problems for queries having LIMIT clauses 3.4.6.0 (not yet released) - patch #3404173 InnoDB comment display with tooltips/aliases diff --git a/libraries/common.lib.php b/libraries/common.lib.php index 123666781c..2aabf6fb93 100644 --- a/libraries/common.lib.php +++ b/libraries/common.lib.php @@ -3709,4 +3709,19 @@ function PMA_getServerType() return $server_type; } +/** + * Analyzes the limit clause and return the start and length attributes of it. + * + * @param string $limit_clause limit clause + * + * @return array Start and length attributes of the limit clause + */ +function PMA_analyzeLimitClause($limit_clause) +{ + $start_and_length = explode(',', str_ireplace('LIMIT', '', $limit_clause)); + return array( + 'start' => trim($start_and_length[0]), + 'length' => trim($start_and_length[1]) + ); +} ?> diff --git a/libraries/display_tbl.lib.php b/libraries/display_tbl.lib.php index 75ddc56543..d088698ae8 100644 --- a/libraries/display_tbl.lib.php +++ b/libraries/display_tbl.lib.php @@ -2321,9 +2321,22 @@ function PMA_displayTable(&$dt_result, &$the_disp_mode, $analyzed_sql) } else { $selectstring = ''; } - $last_shown_rec = ($_SESSION['tmp_user_values']['max_rows'] == 'all' || $pos_next > $total) - ? $total - 1 - : $pos_next - 1; + + if (! empty($analyzed_sql[0]['limit_clause'])) { + $limit_data = PMA_analyzeLimitClause($analyzed_sql[0]['limit_clause']); + $first_shown_rec = $limit_data['start']; + if ($limit_data['length'] < $total) { + $last_shown_rec = $limit_data['start'] + $limit_data['length'] - 1; + } else { + $last_shown_rec = $limit_data['start'] + $total - 1; + } + } elseif ($_SESSION['tmp_user_values']['max_rows'] == 'all' || $pos_next > $total) { + $first_shown_rec = $_SESSION['tmp_user_values']['pos']; + $last_shown_rec = $total - 1; + } else { + $first_shown_rec = $_SESSION['tmp_user_values']['pos']; + $last_shown_rec = $pos_next - 1; + } if (PMA_Table::isView($db, $table) && $total == $GLOBALS['cfg']['MaxExactCountViews'] @@ -2337,7 +2350,7 @@ function PMA_displayTable(&$dt_result, &$the_disp_mode, $analyzed_sql) } $message = PMA_Message::success(__('Showing rows')); - $message->addMessage($_SESSION['tmp_user_values']['pos']); + $message->addMessage($first_shown_rec); if ($message_view_warning) { $message->addMessage('...', ' - '); $message->addMessage($message_view_warning); @@ -2382,7 +2395,7 @@ function PMA_displayTable(&$dt_result, &$the_disp_mode, $analyzed_sql) } } - if ($is_display['nav_bar'] == '1') { + if ($is_display['nav_bar'] == '1' && empty($analyzed_sql[0]['limit_clause'])) { PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query, 'top_direction_dropdown'); echo "\n"; } elseif (! isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') { @@ -2509,7 +2522,7 @@ function PMA_displayTable(&$dt_result, &$the_disp_mode, $analyzed_sql) // 5. ----- Displays the navigation bar at the bottom if required ----- - if ($is_display['nav_bar'] == '1') { + if ($is_display['nav_bar'] == '1' && empty($analyzed_sql[0]['limit_clause'])) { echo '
' . "\n"; PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query, 'bottom_direction_dropdown'); } elseif (! isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {