From 480f3062aaee4316bf3470af1d76332b29b568df Mon Sep 17 00:00:00 2001 From: Spun Nakandala Date: Mon, 17 Jun 2013 22:53:57 +0530 Subject: [PATCH 1/6] long if conditions transfered to the parser_analyzer.inc.php to initialize variables --- libraries/parse_analyze.inc.php | 25 +++++++++++++++++++++++++ sql.php | 15 ++------------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/libraries/parse_analyze.inc.php b/libraries/parse_analyze.inc.php index 78f58987dc..25373ed0cd 100644 --- a/libraries/parse_analyze.inc.php +++ b/libraries/parse_analyze.inc.php @@ -73,6 +73,31 @@ $is_count = isset($analyzed_sql[0]['queryflags']['is_count']); // check for a real SELECT ... FROM $is_select = isset($analyzed_sql[0]['queryflags']['select_from']); +// checks whether the sorting order should be remembered +if ($GLOBALS['cfg']['RememberSorting'] + && ! ($is_count || $is_export || $is_func || $is_analyse) + && isset($analyzed_sql[0]['select_expr']) + && (count($analyzed_sql[0]['select_expr']) == 0) + && isset($analyzed_sql[0]['queryflags']['select_from']) + && count($analyzed_sql[0]['table_ref']) == 1 +) { + $is_remember_sorting_order = true; +} else { + $is_remember_sorting_order = false; +} + +// checks whether a LIMIT clause should be added to the query +if (($_SESSION['tmp_user_values']['max_rows'] != 'all') + && ! ($is_count || $is_export || $is_func || $is_analyse) + && isset($analyzed_sql[0]['queryflags']['select_from']) + && ! isset($analyzed_sql[0]['queryflags']['offset']) + && empty($analyzed_sql[0]['limit_clause']) +) { + $is_append_limit_clause = true; +} else { + $is_append_limit_clause = false; +} + // If the query is a Select, extract the db and table names and modify // $db and $table, to have correct page headers, links and left frame. // db and table name may be enclosed with backquotes, db is optionnal, diff --git a/sql.php b/sql.php index 1f0fda58b8..ebc0e5a3ae 100644 --- a/sql.php +++ b/sql.php @@ -313,24 +313,13 @@ if (isset($_REQUEST['btnDrop']) && $_REQUEST['btnDrop'] == __('No')) { $full_sql_query = $sql_query; // Handle remembered sorting order, only for single table query -if ($GLOBALS['cfg']['RememberSorting'] - && ! ($is_count || $is_export || $is_func || $is_analyse) - && isset($analyzed_sql[0]['select_expr']) - && (count($analyzed_sql[0]['select_expr']) == 0) - && isset($analyzed_sql[0]['queryflags']['select_from']) - && count($analyzed_sql[0]['table_ref']) == 1 -) { +if ($is_remember_sorting_order) { PMA_handleSortOrder($db, $table, $analyzed_sql, $full_sql_query); } $sql_limit_to_append = ''; // Do append a "LIMIT" clause? -if (($_SESSION['tmp_user_values']['max_rows'] != 'all') - && ! ($is_count || $is_export || $is_func || $is_analyse) - && isset($analyzed_sql[0]['queryflags']['select_from']) - && ! isset($analyzed_sql[0]['queryflags']['offset']) - && empty($analyzed_sql[0]['limit_clause']) -) { +if ($is_append_limit_clause) { $sql_limit_to_append = ' LIMIT ' . $_SESSION['tmp_user_values']['pos'] . ', ' . $_SESSION['tmp_user_values']['max_rows'] . " "; $full_sql_query = PMA_getSqlWithLimitClause( From 9d654bc1727fc01a98c3b27e9fcf4a5d55f73776 Mon Sep 17 00:00:00 2001 From: Spun Nakandala Date: Mon, 17 Jun 2013 23:28:45 +0530 Subject: [PATCH 2/6] PMA_getHtmlForBookmark method added to the sql.lib.php --- libraries/sql.lib.php | 51 +++++++++++++++++++++++++++++++++++++++++++ sql.php | 41 +++------------------------------- 2 files changed, 54 insertions(+), 38 deletions(-) diff --git a/libraries/sql.lib.php b/libraries/sql.lib.php index f92d15e34e..f5bdc23400 100644 --- a/libraries/sql.lib.php +++ b/libraries/sql.lib.php @@ -648,4 +648,55 @@ function PMA_getHtmlForOptionsList($values, $selected_values) } return $options; } + +/** + * Get HTML for the Bookmark form + * + * @param string $db the current database + * @param string $goto goto page url + * @param string $bkm_sql_query the query to be bookmarked + */ +function PMA_getHtmlForBookmark($db, $goto, $bkm_sql_query) +{ + $html = '
'; + $html .= PMA_generate_common_hidden_inputs(); + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= '
'; + $html .= ''; + $html .= PMA_Util::getIcon( + 'b_bookmark.png', __('Bookmark this SQL query'), true + ); + $html .= ''; + $html .= '
'; + $html .= ''; + $html .= ''; + $html .= '
'; + $html .= '
'; + $html .= ''; + $html .= ''; + $html .= '
'; + $html .= '
'; + $html .= '
'; + $html .= '
'; + $html .= ''; + $html .= ''; + $html .= '
'; + $html .= '
'; + + return $html; +} ?> diff --git a/sql.php b/sql.php index ebc0e5a3ae..a9961f5364 100644 --- a/sql.php +++ b/sql.php @@ -1007,45 +1007,10 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { . PMA_generate_common_url($db, $table) . '&sql_query=' . urlencode($sql_query) . '&id_bookmark=1'; - - $html_output .= '
'; - $html_output .= PMA_generate_common_hidden_inputs(); - $html_output .= ''; - $html_output .= ''; - $html_output .= ''; - $html_output .= ''; - $html_output .= '
'; - $html_output .= ''; - $html_output .= PMA_Util::getIcon( - 'b_bookmark.png', __('Bookmark this SQL query'), true + $bkm_sql_query = urlencode( + isset($complete_query) ? $complete_query : $sql_query ); - $html_output .= ''; - $html_output .= '
'; - $html_output .= ''; - $html_output .= ''; - $html_output .= '
'; - $html_output .= '
'; - $html_output .= ''; - $html_output .= ''; - $html_output .= '
'; - $html_output .= '
'; - $html_output .= '
'; - $html_output .= '
'; - $html_output .= ''; - $html_output .= ''; - $html_output .= '
'; - $html_output .= '
'; + $html_output .= PMA_getHtmlForBookmark($db, $goto, $bkm_sql_query); } // end bookmark support // Do print the page if required From c1bd633a8a87d20b2de67cbfe36f52fff66818b6 Mon Sep 17 00:00:00 2001 From: Spun Nakandala Date: Tue, 18 Jun 2013 13:11:06 +0530 Subject: [PATCH 3/6] This bug is not relevant to the current master --- sql.php | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/sql.php b/sql.php index a9961f5364..2bb7ba19a9 100644 --- a/sql.php +++ b/sql.php @@ -472,18 +472,12 @@ if (isset($GLOBALS['show_as_php']) || ! empty($GLOBALS['validatequery'])) { // Checks if the current database has changed // This could happen if the user sends a query like "USE `database`;" - /** - * commented out auto-switching to active database - really required? - * bug #2558 win: table list disappears (mixed case db names) - * https://sourceforge.net/p/phpmyadmin/bugs/2558/ - * @todo RELEASE test and comit or rollback before release - $current_db = $GLOBALS['dbi']->fetchValue('SELECT DATABASE()'); + /*$current_db = $GLOBALS['dbi']->fetchValue('SELECT DATABASE()'); if ($db !== $current_db) { $db = $current_db; $reload = 1; } - unset($current_db); - */ + unset($current_db);*/ // tmpfile remove after convert encoding appended by Y.Kawada if (function_exists('PMA_Kanji_fileConv') From 4bc178bbd2bff1d66d737e92a8bbc7779077c4df Mon Sep 17 00:00:00 2001 From: Spun Nakandala Date: Tue, 18 Jun 2013 23:07:47 +0530 Subject: [PATCH 4/6] USE database reloads the respective database --- sql.php | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/sql.php b/sql.php index 2bb7ba19a9..6a0fa3f3fa 100644 --- a/sql.php +++ b/sql.php @@ -349,7 +349,14 @@ if ($is_append_limit_clause) { } } -if (strlen($db)) { +if (strlen($db)) { + // Checks if the current database has changed + // This could happen if the user sends a query like "USE `database`;" + $current_db = $GLOBALS['dbi']->fetchValue('SELECT DATABASE()'); + if ($db !== $current_db) { + $reload = 1; + } + unset($current_db); $GLOBALS['dbi']->selectDb($db); } @@ -470,15 +477,6 @@ if (isset($GLOBALS['show_as_php']) || ! empty($GLOBALS['validatequery'])) { $profiling_results = $GLOBALS['dbi']->fetchResult('SHOW PROFILE;'); } - // Checks if the current database has changed - // This could happen if the user sends a query like "USE `database`;" - /*$current_db = $GLOBALS['dbi']->fetchValue('SELECT DATABASE()'); - if ($db !== $current_db) { - $db = $current_db; - $reload = 1; - } - unset($current_db);*/ - // tmpfile remove after convert encoding appended by Y.Kawada if (function_exists('PMA_Kanji_fileConv') && (isset($textfile) && file_exists($textfile)) From e3298a12d3ef12f2c30fddf9194b9e0ab757987b Mon Sep 17 00:00:00 2001 From: Spun Nakandala Date: Wed, 19 Jun 2013 10:58:13 +0530 Subject: [PATCH 5/6] Error relating to the uninitialized variable $cfg corrected --- libraries/sql.lib.php | 5 +++-- sql.php | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/libraries/sql.lib.php b/libraries/sql.lib.php index f5bdc23400..dc69622922 100644 --- a/libraries/sql.lib.php +++ b/libraries/sql.lib.php @@ -655,8 +655,9 @@ function PMA_getHtmlForOptionsList($values, $selected_values) * @param string $db the current database * @param string $goto goto page url * @param string $bkm_sql_query the query to be bookmarked + * @param string $bkm_user the user creating the bookmark */ -function PMA_getHtmlForBookmark($db, $goto, $bkm_sql_query) +function PMA_getHtmlForBookmark($db, $goto, $bkm_sql_query, $bkm_user) { $html = '
'; $html .= ''; + . ' value="' . $bkm_user . '" />'; $html .= ''; diff --git a/sql.php b/sql.php index 6a0fa3f3fa..eae1bea97e 100644 --- a/sql.php +++ b/sql.php @@ -1002,7 +1002,8 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { $bkm_sql_query = urlencode( isset($complete_query) ? $complete_query : $sql_query ); - $html_output .= PMA_getHtmlForBookmark($db, $goto, $bkm_sql_query); + $bkm_user = $cfg['Bookmark']['user']; + $html_output .= PMA_getHtmlForBookmark($db, $goto, $bkm_sql_query, $bkm_user); } // end bookmark support // Do print the page if required From 93c2f414cddb8ab810fbaaae346073a8123dfda5 Mon Sep 17 00:00:00 2001 From: Spun Nakandala Date: Wed, 19 Jun 2013 17:52:57 +0530 Subject: [PATCH 6/6] removed the redundant variable $bkm_user --- sql.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sql.php b/sql.php index eae1bea97e..81fb8d5f56 100644 --- a/sql.php +++ b/sql.php @@ -1002,8 +1002,7 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { $bkm_sql_query = urlencode( isset($complete_query) ? $complete_query : $sql_query ); - $bkm_user = $cfg['Bookmark']['user']; - $html_output .= PMA_getHtmlForBookmark($db, $goto, $bkm_sql_query, $bkm_user); + $html_output .= PMA_getHtmlForBookmark($db, $goto, $bkm_sql_query, $cfg['Bookmark']['user']); } // end bookmark support // Do print the page if required