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/libraries/sql.lib.php b/libraries/sql.lib.php index f92d15e34e..dc69622922 100644 --- a/libraries/sql.lib.php +++ b/libraries/sql.lib.php @@ -648,4 +648,56 @@ 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 + * @param string $bkm_user the user creating the bookmark + */ +function PMA_getHtmlForBookmark($db, $goto, $bkm_sql_query, $bkm_user) +{ + $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 1f0fda58b8..81fb8d5f56 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( @@ -360,7 +349,14 @@ if (($_SESSION['tmp_user_values']['max_rows'] != 'all') } } -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); } @@ -481,21 +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`;" - /** - * 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()'); - 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)) @@ -1018,45 +999,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, $cfg['Bookmark']['user']); } // end bookmark support // Do print the page if required