From c1c50b59441e60c2b2e2c4872e255162400c493b Mon Sep 17 00:00:00 2001 From: Madhura Jayaratne Date: Wed, 29 Jan 2014 23:06:43 +0530 Subject: [PATCH 1/2] Revert e8fa9e533565e, ea0ad9d41c1726 and f36fbfd4c6fde Signed-off-by: Madhura Jayaratne --- libraries/Util.class.php | 60 +------------------ libraries/sql.lib.php | 51 +++++++++++++++- test/classes/PMA_Header_test.php | 1 - test/libraries/PMA_insert_edit_test.php | 3 - test/libraries/PMA_server_binlog_test.php | 9 +-- test/libraries/PMA_server_privileges_test.php | 4 -- 6 files changed, 52 insertions(+), 76 deletions(-) diff --git a/libraries/Util.class.php b/libraries/Util.class.php index 4d61ee71ea..8ff48770b2 100644 --- a/libraries/Util.class.php +++ b/libraries/Util.class.php @@ -1012,17 +1012,7 @@ class PMA_Util $sql_query = ''; } } - - if (isset($GLOBALS['db']) && isset($GLOBALS['table'])){ - // Parse and analyze the query - $analyzed_sql_results = PMA_SQP_getParserAnalyzeMap( - $sql_query, $GLOBALS['db']); - - // Synchronize message(query) with table - self::handleSortOrder($GLOBALS['db'], $GLOBALS['table'], - $analyzed_sql_results, $sql_query); - } - + if (isset($GLOBALS['using_bookmark_message'])) { $retval .= $GLOBALS['using_bookmark_message']->getDisplay(); unset($GLOBALS['using_bookmark_message']); @@ -4371,54 +4361,6 @@ class PMA_Util return $value . '.000000'; } } - - /** - * Handle remembered sorting order, only for single table query - * - * @param string $db database name - * @param string $table table name - * @param array &$analyzed_sql_results the analyzed query results - * @param string &$full_sql_query SQL query - * - * @return void - */ - public static function handleSortOrder( - $db, $table, &$analyzed_sql_results, &$full_sql_query - ) { - $pmatable = new PMA_Table($table, $db); - if (empty($analyzed_sql_results['analyzed_sql'][0]['order_by_clause']) - && isset($GLOBALS['default_query']) && $GLOBALS['default_query']) { - $sorted_col = $pmatable->getUiProp(PMA_Table::PROP_SORTED_COLUMN); - if ($sorted_col) { - //remove the tablename from retrieved preference - //to get just the column name and the sort order - $sorted_col = str_replace( - PMA_Util::backquote($table) . '.', '', $sorted_col - ); - // retrieve the remembered sorting order for current table - $sql_order_to_append = ' ORDER BY ' . $sorted_col . ' '; - $full_sql_query - = $analyzed_sql_results['analyzed_sql'][0]['section_before_limit'] - . $sql_order_to_append - . $analyzed_sql_results['analyzed_sql'][0]['limit_clause'] - . ' ' - . $analyzed_sql_results['analyzed_sql'][0]['section_after_limit']; - - // update the $analyzed_sql - $analyzed_sql_results['analyzed_sql'][0]['section_before_limit'] - .= $sql_order_to_append; - $analyzed_sql_results['analyzed_sql'][0]['order_by_clause'] - = $sorted_col; - } - } else { - // store the remembered table into session - $pmatable->setUiProp( - PMA_Table::PROP_SORTED_COLUMN, - $analyzed_sql_results['analyzed_sql'][0]['order_by_clause'] - ); - } - } - } ?> diff --git a/libraries/sql.lib.php b/libraries/sql.lib.php index 8577970245..5da0ac94b2 100644 --- a/libraries/sql.lib.php +++ b/libraries/sql.lib.php @@ -140,7 +140,7 @@ function PMA_getTableHtmlForMultipleQueries( && isset($analyzed_sql[0]['queryflags']['select_from']) && count($analyzed_sql[0]['table_ref']) == 1 ) { - PMA_Util::handleSortOrder( + PMA_handleSortOrder( $db, $table, $analyzed_sql, @@ -214,6 +214,52 @@ function PMA_getTableHtmlForMultipleQueries( return $table_html; } +/** + * Handle remembered sorting order, only for single table query + * + * @param string $db database name + * @param string $table table name + * @param array &$analyzed_sql_results the analyzed query results + * @param string &$full_sql_query SQL query + * + * @return void + */ +function PMA_handleSortOrder( + $db, $table, &$analyzed_sql_results, &$full_sql_query +) { + $pmatable = new PMA_Table($table, $db); + if (empty($analyzed_sql_results['analyzed_sql'][0]['order_by_clause'])) { + $sorted_col = $pmatable->getUiProp(PMA_Table::PROP_SORTED_COLUMN); + if ($sorted_col) { + //remove the tablename from retrieved preference + //to get just the column name and the sort order + $sorted_col = str_replace( + PMA_Util::backquote($table) . '.', '', $sorted_col + ); + // retrieve the remembered sorting order for current table + $sql_order_to_append = ' ORDER BY ' . $sorted_col . ' '; + $full_sql_query + = $analyzed_sql_results['analyzed_sql'][0]['section_before_limit'] + . $sql_order_to_append + . $analyzed_sql_results['analyzed_sql'][0]['limit_clause'] + . ' ' + . $analyzed_sql_results['analyzed_sql'][0]['section_after_limit']; + + // update the $analyzed_sql + $analyzed_sql_results['analyzed_sql'][0]['section_before_limit'] + .= $sql_order_to_append; + $analyzed_sql_results['analyzed_sql'][0]['order_by_clause'] + = $sorted_col; + } + } else { + // store the remembered table into session + $pmatable->setUiProp( + PMA_Table::PROP_SORTED_COLUMN, + $analyzed_sql_results['analyzed_sql'][0]['order_by_clause'] + ); + } +} + /** * Append limit clause to SQL query * @@ -1125,7 +1171,6 @@ function PMA_appendLimitClause($full_sql_query, $analyzed_sql, $display_query) */ function PMA_getDefaultSqlQueryForBrowse($db, $table) { - $GLOBALS['default_query'] = true; include_once 'libraries/bookmark.lib.php'; $book_sql_query = PMA_Bookmark_get( $db, @@ -2236,7 +2281,7 @@ function PMA_executeQueryAndSendQueryResponse($analyzed_sql_results, if (PMA_isRememberSortingOrder($analyzed_sql_results) && ! isset($analyzed_sql_results['analyzed_sql'][0]['queryflags']['union']) ) { - PMA_Util::handleSortOrder($db, $table, $analyzed_sql_results, $full_sql_query); + PMA_handleSortOrder($db, $table, $analyzed_sql_results, $full_sql_query); } // Do append a "LIMIT" clause? diff --git a/test/classes/PMA_Header_test.php b/test/classes/PMA_Header_test.php index 78ae08ce4a..04f194b390 100644 --- a/test/classes/PMA_Header_test.php +++ b/test/classes/PMA_Header_test.php @@ -55,7 +55,6 @@ class PMA_Header_Test extends PHPUnit_Framework_TestCase $GLOBALS['PMA_Config']->enableBc(); $GLOBALS['cfg']['Server']['verbose'] = 'verbose host'; $GLOBALS['cfg']['Server']['pmadb'] = ''; - $GLOBALS['default_query'] = true; } /** diff --git a/test/libraries/PMA_insert_edit_test.php b/test/libraries/PMA_insert_edit_test.php index 77df46a43f..2a27bfb9ae 100644 --- a/test/libraries/PMA_insert_edit_test.php +++ b/test/libraries/PMA_insert_edit_test.php @@ -50,9 +50,6 @@ class PMA_InsertEditTest extends PHPUnit_Framework_TestCase $GLOBALS['text_dir'] = 'ltr'; $GLOBALS['db'] = 'db'; $GLOBALS['table'] = 'table'; - $GLOBALS['cfg']['Server']['pmadb'] = 'pmadb'; - $GLOBALS['cfg']['Server']['table_uiprefs'] = 'table_uiprefs'; - $GLOBALS['cfg']['Server']['user'] = 'user'; } /** diff --git a/test/libraries/PMA_server_binlog_test.php b/test/libraries/PMA_server_binlog_test.php index 36daed383a..66d6304138 100644 --- a/test/libraries/PMA_server_binlog_test.php +++ b/test/libraries/PMA_server_binlog_test.php @@ -51,13 +51,10 @@ class PMA_ServerBinlog_Test extends PHPUnit_Framework_TestCase $GLOBALS['cfg']['ShowSQL'] = true; $GLOBALS['cfg']['TableNavigationLinksMode'] = 'icons'; $GLOBALS['cfg']['LimitChars'] = 100; - $GLOBALS['cfg']['Server']['pmadb'] = 'pmadb'; - $GLOBALS['cfg']['Server']['table_uiprefs'] = 'table_uiprefs'; - $GLOBALS['cfg']['Server']['user'] = 'user'; - + $GLOBALS['table'] = "table"; $GLOBALS['pmaThemeImage'] = 'image'; - + //$_SESSION $_SESSION['PMA_Theme'] = PMA_Theme::load('./themes/pmahomme'); $_SESSION['PMA_Theme'] = new PMA_Theme(); @@ -141,7 +138,7 @@ class PMA_ServerBinlog_Test extends PHPUnit_Framework_TestCase $count = 3; //expects functions - $dbi->expects($this->exactly(2))->method('query') + $dbi->expects($this->once())->method('query') ->will($this->returnValue($result)); $dbi->expects($this->once())->method('numRows') diff --git a/test/libraries/PMA_server_privileges_test.php b/test/libraries/PMA_server_privileges_test.php index 1562879d76..ac126454a1 100644 --- a/test/libraries/PMA_server_privileges_test.php +++ b/test/libraries/PMA_server_privileges_test.php @@ -65,8 +65,6 @@ class PMA_ServerPrivileges_Test extends PHPUnit_Framework_TestCase $GLOBALS['cfg']['NavigationTreeDefaultTabTable'] = "db_structure.php"; $GLOBALS['cfg']['Confirm'] = "Confirm"; $GLOBALS['cfg']['ShowHint'] = true; - $GLOBALS['cfg']['Server']['table_uiprefs'] = 'table_uiprefs'; - $GLOBALS['cfg']['Server']['user'] = 'user'; $GLOBALS['cfgRelation'] = array(); $GLOBALS['cfgRelation']['menuswork'] = false; @@ -78,8 +76,6 @@ class PMA_ServerPrivileges_Test extends PHPUnit_Framework_TestCase $GLOBALS['username'] = "username"; $GLOBALS['collation_connection'] = "collation_connection"; $GLOBALS['text_dir'] = "text_dir"; - $GLOBALS['default_query'] = true; - //$_POST $_POST['pred_password'] = 'none'; //$_SESSION From 212a7e5a7e249f18c6c4daa56be801edc176d789 Mon Sep 17 00:00:00 2001 From: Madhura Jayaratne Date: Wed, 29 Jan 2014 23:15:58 +0530 Subject: [PATCH 2/2] Fix bug #4245 Signed-off-by: Madhura Jayaratne --- libraries/sql.lib.php | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/libraries/sql.lib.php b/libraries/sql.lib.php index 5da0ac94b2..811a8e4309 100644 --- a/libraries/sql.lib.php +++ b/libraries/sql.lib.php @@ -2266,24 +2266,23 @@ function PMA_executeQueryAndSendQueryResponse($analyzed_sql_results, include 'libraries/DisplayResults.class.php'; - $displayResultsObject = new PMA_DisplayResults( - $GLOBALS['db'], $GLOBALS['table'], $GLOBALS['goto'], $GLOBALS['sql_query'] - ); - - $displayResultsObject->setConfigParamsForDisplayTable(); - - // assign default full_sql_query - $full_sql_query = $sql_query; - // Handle remembered sorting order, only for single table query // Handling is not required when it's a union query // (the parser never sets the 'union' key to 0) if (PMA_isRememberSortingOrder($analyzed_sql_results) && ! isset($analyzed_sql_results['analyzed_sql'][0]['queryflags']['union']) ) { - PMA_handleSortOrder($db, $table, $analyzed_sql_results, $full_sql_query); + PMA_handleSortOrder($db, $table, $analyzed_sql_results, $sql_query); } + $displayResultsObject = new PMA_DisplayResults( + $GLOBALS['db'], $GLOBALS['table'], $GLOBALS['goto'], $sql_query + ); + $displayResultsObject->setConfigParamsForDisplayTable(); + + // assign default full_sql_query + $full_sql_query = $sql_query; + // Do append a "LIMIT" clause? if (PMA_isAppendLimitClause($analyzed_sql_results)) { list($sql_limit_to_append,