From 4c912a6ae70d96c3d9c725bee0e1e3e907f40fe3 Mon Sep 17 00:00:00 2001 From: Spun Nakandala Date: Tue, 9 Jul 2013 11:29:48 +0530 Subject: [PATCH 01/24] added method PMA_sendResponseForGridEdit --- libraries/sql.lib.php | 15 +++++++++++++++ sql.php | 14 ++------------ 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/libraries/sql.lib.php b/libraries/sql.lib.php index 9f4e40e8a8..c004a1cbf8 100644 --- a/libraries/sql.lib.php +++ b/libraries/sql.lib.php @@ -1650,4 +1650,19 @@ function PMA_sendResponseForNoResultsReturned($analyzed_sql_results, $db, $table } exit(); } + +/** + * Function to send response for ajax grid edit + * + * @param object $result result of the executed query + * + * @return void + */ +function PMA_sendResponseForGridEdit($result) +{ + $row = $GLOBALS['dbi']->fetchRow($result); + $response = PMA_Response::getInstance(); + $response->addJSON('value', $row[0]); + exit; +} ?> diff --git a/sql.php b/sql.php index 53ce7ff605..a58dba2b93 100644 --- a/sql.php +++ b/sql.php @@ -230,13 +230,10 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { } else { $html_output=''; // At least one row is returned -> displays a table with results - //If we are retrieving the full value of a truncated field or the original + // If we are retrieving the full value of a truncated field or the original // value of a transformed field, show it here and exit if ($GLOBALS['grid_edit'] == true) { - $row = $GLOBALS['dbi']->fetchRow($result); - $response = PMA_Response::getInstance(); - $response->addJSON('value', $row[0]); - exit; + PMA_sendResponseForGridEdit($result); } if (isset($_REQUEST['ajax_request']) && isset($_REQUEST['table_maintenance'])) { @@ -483,11 +480,4 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { $response->addHTML($html_output); } // end rows returned -$_SESSION['is_multi_query'] = false; - - -if (! isset($_REQUEST['table_maintenance'])) { - exit; -} - ?> From bc055fe4b7321ac1c02c82cac460268ff9b482b7 Mon Sep 17 00:00:00 2001 From: Spun Nakandala Date: Tue, 9 Jul 2013 11:55:41 +0530 Subject: [PATCH 02/24] can be done only once --- sql.php | 35 ++++++++++++----------------------- 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/sql.php b/sql.php index a58dba2b93..016eb0921f 100644 --- a/sql.php +++ b/sql.php @@ -236,19 +236,24 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { PMA_sendResponseForGridEdit($result); } - if (isset($_REQUEST['ajax_request']) && isset($_REQUEST['table_maintenance'])) { + // Gets the list of fields properties + if (isset($result) && $result) { + $fields_meta = $GLOBALS['dbi']->getFieldsMeta($result); + $fields_cnt = count($fields_meta); + } + + // Should be initialized these parameters before parsing + $showtable = isset($showtable) ? $showtable : null; + $printview = isset($_REQUEST['printview']) ? $_REQUEST['printview'] : null; + $url_query = isset($url_query) ? $url_query : null; + + if (isset($_REQUEST['table_maintenance'])) { $response = PMA_Response::getInstance(); $header = $response->getHeader(); $scripts = $header->getScripts(); $scripts->addFile('makegrid.js'); $scripts->addFile('sql.js'); - // Gets the list of fields properties - if (isset($result) && $result) { - $fields_meta = $GLOBALS['dbi']->getFieldsMeta($result); - $fields_cnt = count($fields_meta); - } - if (empty($disp_mode)) { // see the "PMA_setDisplayMode()" function in // libraries/DisplayResults.class.php @@ -267,11 +272,6 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { ); } - // Should be initialized these parameters before parsing - $showtable = isset($showtable) ? $showtable : null; - $printview = isset($_REQUEST['printview']) ? $_REQUEST['printview'] : null; - $url_query = isset($url_query) ? $url_query : null; - if (!empty($sql_data) && ($sql_data['valid_queries'] > 1)) { $_SESSION['is_multi_query'] = true; @@ -343,12 +343,6 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { $cfgRelation = PMA_getRelationsParam(); } - // Gets the list of fields properties - if (isset($result) && $result) { - $fields_meta = $GLOBALS['dbi']->getFieldsMeta($result); - $fields_cnt = count($fields_meta); - } - //begin the sqlqueryresults div here. container div $html_output .= '
getDisplay(); } - // Should be initialized these parameters before parsing - $showtable = isset($showtable) ? $showtable : null; - $printview = isset($_REQUEST['printview']) ? $_REQUEST['printview'] : null; - $url_query = isset($url_query) ? $url_query : null; - if (! empty($sql_data) && ($sql_data['valid_queries'] > 1) || $is_procedure) { $_SESSION['is_multi_query'] = true; From 27859550cf5ef77fc1a5bf5e7a24f5434ac83a23 Mon Sep 17 00:00:00 2001 From: Spun Nakandala Date: Tue, 9 Jul 2013 14:17:08 +0530 Subject: [PATCH 03/24] added methods PMA_getHtmlForTableMaintenanceResponse, PMA_sendResponseOrGetHtmlForTableMaintenance --- libraries/sql.lib.php | 130 ++++++++++++++++++++++++++++++++++++++++++ sql.php | 70 +++++------------------ 2 files changed, 145 insertions(+), 55 deletions(-) diff --git a/libraries/sql.lib.php b/libraries/sql.lib.php index c004a1cbf8..734a03e2a1 100644 --- a/libraries/sql.lib.php +++ b/libraries/sql.lib.php @@ -1665,4 +1665,134 @@ function PMA_sendResponseForGridEdit($result) $response->addJSON('value', $row[0]); exit; } + +/** + * Function to get the html for the table maintenance response + * + * @param string $message message + * @param array $sql_data sql data + * @param object $displayResultsObject instance of the DisplayResult.class + * @param string $db database + * @param string $goto goto page url + * @param string $pmaThemeImage theme image uri + * @param string $text_dir + * @param bool $showtable show table + * @param string $url_query url query + * @param string $disp_mode display mode + * @param string $sql_limit_to_append sql limit to append + * @param object $result result of the executed query + * @param int $unlim_num_rows unlimited number of rows + * @param int $num_rows number of rows + * @param int $querytime query time + * @param array $analyzed_sql_results analyzed sql results + * + * @return string $html_output html for the table maintence response + */ +function PMA_getHtmlForTableMaintenanceResponse($message, $sql_data, + $displayResultsObject, $db, $goto, $pmaThemeImage, $text_dir, $showtable, + $url_query, $disp_mode, $sql_limit_to_append, $result, $unlim_num_rows, + $num_rows, $querytime, $analyzed_sql_results +) { + $printview = isset($_REQUEST['printview']) ? $_REQUEST['printview'] : null; + $html_output = ''; + + if (isset($message)) { + $message = PMA_Message::success($message); + $html_output .= PMA_Util::getMessage( + $message, $GLOBALS['sql_query'], 'success' + ); + } + + if (!empty($sql_data) && ($sql_data['valid_queries'] > 1)) { + $_SESSION['is_multi_query'] = true; + $html_output .= getTableHtmlForMultipleQueries( + $displayResultsObject, $db, $sql_data, $goto, + $pmaThemeImage, $text_dir, $printview, $url_query, + $disp_mode, $sql_limit_to_append, false + ); + } else { + $_SESSION['is_multi_query'] = false; + + if (isset($result) && $result) { + $fields_meta = $GLOBALS['dbi']->getFieldsMeta($result); + $fields_cnt = count($fields_meta); + } + + $displayResultsObject->setProperties( + $unlim_num_rows, $fields_meta, $analyzed_sql_results['is_count'], + $analyzed_sql_results['is_export'], $analyzed_sql_results['is_func'], + $analyzed_sql_results['is_analyse'], $num_rows, $fields_cnt, $querytime, + $pmaThemeImage, $text_dir, $analyzed_sql_results['is_maint'], + $analyzed_sql_results['is_explain'], $analyzed_sql_results['is_show'], + $showtable, $printview, $url_query, false + ); + + $html_output .= $displayResultsObject->getTable( + $result, $disp_mode, $analyzed_sql_results['analyzed_sql'] + ); + } + + return $html_output; +} + +/** + * Function to send html for the table maintenance or to get the html for the table + * maintenance case when handling multiple queries + * + * @param string $disp_mode display mode + * @param string $db database + * @param string $message message + * @param array $sql_data sql data + * @param object $displayResultsObject instance of DisplayResult.class + * @param string $goto goto page url + * @param string $pmaThemeImage theme image uri + * @param string $text_dir + * @param bool $showtable show table + * @param string $url_query url query + * @param string $sql_limit_to_append sql limit to append + * @param object $result result of the executed query + * @param int $unlim_num_rows unlimited number of rows + * @param int $num_rows number of rows + * @param int $querytime query time + * @param array $analyzed_sql_results analyzed sql results + * + * @return string $html_output html for the table maintence response + */ +function PMA_sendResponseOrGetHtmlForTableMaintenance($disp_mode, $db, $message, + $sql_data, $displayResultsObject, $goto, $pmaThemeImage, $text_dir, $showtable, + $url_query, $sql_limit_to_append, $result, $unlim_num_rows, $num_rows, + $querytime, $analyzed_sql_results) +{ + $response = PMA_Response::getInstance(); + $header = $response->getHeader(); + $scripts = $header->getScripts(); + $scripts->addFile('makegrid.js'); + $scripts->addFile('sql.js'); + + if (empty($disp_mode)) { + // see the "PMA_setDisplayMode()" function in + // libraries/DisplayResults.class.php + $disp_mode = 'urdr111101'; + } + + // hide edit and delete links for information_schema + if ($GLOBALS['dbi']->isSystemSchema($db)) { + $disp_mode = 'nnnn110111'; + } + + $html_output = PMA_getHtmlForTableMaintenanceResponse( + isset($message) ? $message : null, + isset($sql_data) ? $sql_data : null, + $displayResultsObject, $db, $goto, $pmaThemeImage, $text_dir, + $showtable, $url_query, $disp_mode, $sql_limit_to_append, $result, + $unlim_num_rows, $num_rows, $querytime, $analyzed_sql_results + ); + + if (!empty($sql_data) && ($sql_data['valid_queries'] > 1)) { + return $html_output; + } else { + $response->addHTML($html_output); + exit(); + } +} ?> diff --git a/sql.php b/sql.php index 016eb0921f..0d20ec7404 100644 --- a/sql.php +++ b/sql.php @@ -246,76 +246,36 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { $showtable = isset($showtable) ? $showtable : null; $printview = isset($_REQUEST['printview']) ? $_REQUEST['printview'] : null; $url_query = isset($url_query) ? $url_query : null; + + $response = PMA_Response::getInstance(); + $header = $response->getHeader(); + $scripts = $header->getScripts(); if (isset($_REQUEST['table_maintenance'])) { - $response = PMA_Response::getInstance(); - $header = $response->getHeader(); - $scripts = $header->getScripts(); - $scripts->addFile('makegrid.js'); - $scripts->addFile('sql.js'); - - if (empty($disp_mode)) { - // see the "PMA_setDisplayMode()" function in - // libraries/DisplayResults.class.php - $disp_mode = 'urdr111101'; - } - - // hide edit and delete links for information_schema - if ($GLOBALS['dbi']->isSystemSchema($db)) { - $disp_mode = 'nnnn110111'; - } - - if (isset($message)) { - $message = PMA_Message::success($message); - $html_output .= PMA_Util::getMessage( - $message, $GLOBALS['sql_query'], 'success' - ); - } - - if (!empty($sql_data) && ($sql_data['valid_queries'] > 1)) { - - $_SESSION['is_multi_query'] = true; - $html_output .= getTableHtmlForMultipleQueries( - $displayResultsObject, $db, $sql_data, $goto, - $pmaThemeImage, $text_dir, $printview, $url_query, - $disp_mode, $sql_limit_to_append, false - ); - } else { - $_SESSION['is_multi_query'] = false; - $displayResultsObject->setProperties( - $unlim_num_rows, $fields_meta, $is_count, $is_export, $is_func, - $is_analyse, $num_rows, $fields_cnt, $querytime, $pmaThemeImage, - $text_dir, $is_maint, $is_explain, $is_show, $showtable, - $printview, $url_query, false - ); - - $html_output .= $displayResultsObject->getTable( - $result, $disp_mode, $analyzed_sql - ); - $response = PMA_Response::getInstance(); - $response->addHTML($html_output); - exit(); - } + $html_output .= PMA_sendResponseOrGetHtmlForTableMaintenance( + isset($disp_mode) ? $disp_mode : null, $db, + isset($message) ? $message : null, + isset($sql_data) ? $sql_data : null, + $displayResultsObject, $goto, $pmaThemeImage, $text_dir, $showtable, + $url_query, $sql_limit_to_append, $result, $unlim_num_rows, $num_rows, + $querytime, $analyzed_sql_results + ); } // Displays the headers if (isset($show_query)) { unset($show_query); } + if (isset($_REQUEST['printview']) && $_REQUEST['printview'] == '1') { PMA_Util::checkParameters(array('db', 'full_sql_query')); - - $response = PMA_Response::getInstance(); - $header = $response->getHeader(); + $header->enablePrintView(); $html_output .= PMA_getHtmlForPrintViewHeader( $db, $full_sql_query, $num_rows ); } else { - $response = PMA_Response::getInstance(); - $header = $response->getHeader(); - $scripts = $header->getScripts(); $scripts->addFile('makegrid.js'); $scripts->addFile('sql.js'); @@ -383,6 +343,7 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { && trim($analyzed_sql[0]['select_expr_clause']) == '*' && PMA_Table::isUpdatableView($db, $table); $editable = $has_unique || $updatableView; + if (!empty($table) && ($GLOBALS['dbi']->isSystemSchema($db) || !$editable)) { $disp_mode = 'nnnn110111'; $msg = PMA_message::notice( @@ -465,7 +426,6 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { $html_output .= PMA_Util::getButton(); } // end print case $html_output .= '
'; // end sqlqueryresults div - $response = PMA_Response::getInstance(); $response->addHTML($html_output); } // end rows returned From f2b268b1372ca01f9f17bbc2bd595ad6ff2453cb Mon Sep 17 00:00:00 2001 From: Spun Nakandala Date: Tue, 9 Jul 2013 15:03:10 +0530 Subject: [PATCH 04/24] All the requests will be ajax --- sql.php | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/sql.php b/sql.php index 0d20ec7404..7d7cce1a28 100644 --- a/sql.php +++ b/sql.php @@ -268,35 +268,18 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { } if (isset($_REQUEST['printview']) && $_REQUEST['printview'] == '1') { - PMA_Util::checkParameters(array('db', 'full_sql_query')); - + PMA_Util::checkParameters(array('db', 'full_sql_query')); $header->enablePrintView(); - $html_output .= PMA_getHtmlForPrintViewHeader( $db, $full_sql_query, $num_rows ); } else { $scripts->addFile('makegrid.js'); $scripts->addFile('sql.js'); - - unset($message); - - if (! $GLOBALS['is_ajax_request']) { - if (strlen($table)) { - include 'libraries/tbl_common.inc.php'; - $url_query .= '&goto=tbl_sql.php&back=tbl_sql.php'; - include 'libraries/tbl_info.inc.php'; - } elseif (strlen($db)) { - include 'libraries/db_common.inc.php'; - include 'libraries/db_info.inc.php'; - } else { - include 'libraries/server_common.inc.php'; - } - } else { - //we don't need to buffer the output in getMessage here. - //set a global variable and check against it in the function - $GLOBALS['buffer_message'] = false; - } + unset($message); + //we don't need to buffer the output in getMessage here. + //set a global variable and check against it in the function + $GLOBALS['buffer_message'] = false; } if (strlen($db)) { From ebef06fa0df162a5852efab68fab9e7f36c600e3 Mon Sep 17 00:00:00 2001 From: Spun Nakandala Date: Tue, 9 Jul 2013 16:27:34 +0530 Subject: [PATCH 05/24] added method PMA_getHtmlForSqlQueryResults --- libraries/sql.lib.php | 36 +++++++++++++++ sql.php | 103 ++++++++++++++++++++++++------------------ 2 files changed, 95 insertions(+), 44 deletions(-) diff --git a/libraries/sql.lib.php b/libraries/sql.lib.php index 734a03e2a1..1146cdf9f9 100644 --- a/libraries/sql.lib.php +++ b/libraries/sql.lib.php @@ -1795,4 +1795,40 @@ function PMA_sendResponseOrGetHtmlForTableMaintenance($disp_mode, $db, $message, exit(); } } + + +/** + * Function to get html for the sql query results div + * + * @param string $previous_update_query_html html for the previously executed query + * @param string $profiling_chart_html html for profiling + * @param object $missing_unique_column_msg message for the missing unique column + * @param object $bookmark_created_msg message for bookmark creation + * @param string $table_html html for the table for displaying sql + * results + * @param string $index_problems_html html for displaying errors in indexes + * @param string $print_button_html html for the print button in printview + * + * @return string $html_output + */ +function PMA_getHtmlForSqlQueryResults($previous_update_query_html, + $profiling_chart_html, $missing_unique_column_msg, $bookmark_created_msg, + $table_html, $index_problems_html, $print_button_html +) { + //begin the sqlqueryresults div here. container div + $html_output = '
'; + $html_output .= isset($previous_update_query_html) + ? $previous_update_query_html : ''; + $html_output .= isset($profiling_chart_html) ? $profiling_chart_html : ''; + $html_output .= isset($missing_unique_column_msg) + ? $missing_unique_column_msg->getDisplay() : ''; + $html_output .= isset($bookmark_created_msg) + ? $bookmark_created_msg->getDisplay() : ''; + $html_output .= $table_html; + $html_output .= isset($index_problems_html) ? $index_problems_html : ''; + $html_output .= isset($print_button_html) ? $print_button_html : ''; + $html_output .= '
'; // end sqlqueryresults div + + return $html_output; +} ?> diff --git a/sql.php b/sql.php index 7d7cce1a28..692d6eec90 100644 --- a/sql.php +++ b/sql.php @@ -281,19 +281,29 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { //set a global variable and check against it in the function $GLOBALS['buffer_message'] = false; } - + + // Displays the results in a table + if (empty($disp_mode)) { + // see the "PMA_setDisplayMode()" function in + // libraries/DisplayResults.class.php + $disp_mode = 'urdr111101'; + } + if (strlen($db)) { $cfgRelation = PMA_getRelationsParam(); } - //begin the sqlqueryresults div here. container div - $html_output .= '
isSystemSchema($db) || !$editable)) { $disp_mode = 'nnnn110111'; - $msg = PMA_message::notice( + $missing_unique_column_msg = PMA_message::notice( __( 'Table %s does not contain a unique column.' . ' Grid edit, checkbox, Edit, Copy and Delete features' . ' are not available.' ) ); - $msg->addParam($table); - $html_output .= $msg->getDisplay(); + $missing_unique_column_msg->addParam($table); + } else { + $missing_unique_column_msg = null; } - + if (isset($_GET['label'])) { - $msg = PMA_message::success(__('Bookmark %s created')); - $msg->addParam($_GET['label']); - $html_output .= $msg->getDisplay(); + $bookmark_created_msg = PMA_message::success(__('Bookmark %s created')); + $bookmark_created_msg->addParam($_GET['label']); + } else { + $bookmark_created_msg = null; } if (! empty($sql_data) && ($sql_data['valid_queries'] > 1) || $is_procedure) { - $_SESSION['is_multi_query'] = true; - $html_output .= getTableHtmlForMultipleQueries( + $table_html = getTableHtmlForMultipleQueries( $displayResultsObject, $db, $sql_data, $goto, $pmaThemeImage, $text_dir, $printview, $url_query, $disp_mode, $sql_limit_to_append, $editable @@ -363,35 +366,38 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { $printview, $url_query, $editable ); - $html_output .= $displayResultsObject->getTable( + $table_html = $displayResultsObject->getTable( $result, $disp_mode, $analyzed_sql ); $GLOBALS['dbi']->freeResult($result); } - + // BEGIN INDEX CHECK See if indexes should be checked. if (isset($query_type) && $query_type == 'check_tbl' && isset($selected) && is_array($selected) ) { + $index_problems_html = ''; foreach ($selected as $idx => $tbl_name) { $check = PMA_Index::findDuplicates($tbl_name, $db); if (! empty($check)) { - $html_output .= sprintf( + $index_problems_html .= sprintf( __('Problems with indexes of table `%s`'), $tbl_name ); - $html_output .= $check; + $index_problems_html .= $check; } } - } // End INDEX CHECK - + } else { + $index_problems_html = null; + } + // Bookmark support if required if ($disp_mode[7] == '1' && (! empty($cfg['Bookmark']) && empty($_GET['id_bookmark'])) && ! empty($sql_query) ) { - $html_output .= "\n"; + $bookmark_support_html = "\n"; $goto = 'sql.php?' . PMA_generate_common_url($db, $table) . '&sql_query=' . urlencode($sql_query) @@ -399,17 +405,26 @@ 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( + $bookmark_support_html .= PMA_getHtmlForBookmark( $db, $goto, $bkm_sql_query, $cfg['Bookmark']['user'] ); - } // end bookmark support + } else { + $bookmark_support_html = null; + } // Do print the page if required if (isset($_REQUEST['printview']) && $_REQUEST['printview'] == '1') { - $html_output .= PMA_Util::getButton(); - } // end print case - $html_output .= '
'; // end sqlqueryresults div + $print_button_html = PMA_Util::getButton(); + } else { + $print_button_html = null; + } + + $html_output .= PMA_getHtmlForSqlQueryResults($previous_update_query_html, + $profiling_chart_html, $missing_unique_column_msg, $bookmark_created_msg, + $table_html, $index_problems_html, $print_button_html + ); + $response->addHTML($html_output); + } // end rows returned - ?> From e5f3f7e0aca9a62bf40b1d3831fe79d7378b7396 Mon Sep 17 00:00:00 2001 From: Spun Nakandala Date: Tue, 9 Jul 2013 18:05:17 +0530 Subject: [PATCH 06/24] added methods PMA_getHtmlForPrintButton, PMA_getHtmlForIndexesProblems, PMA_getMessageIfMissingColumnIndex, PMA_getHtmlForPreviousUpdateQuery, PMA_getHtmlForSqlQueryResultsTable, PMA_getBookmarkCreatedMessage --- libraries/sql.lib.php | 188 +++++++++++++++++++++++++++++++++++++++++- sql.php | 131 +++++++++-------------------- 2 files changed, 226 insertions(+), 93 deletions(-) diff --git a/libraries/sql.lib.php b/libraries/sql.lib.php index 1146cdf9f9..265bd20ee9 100644 --- a/libraries/sql.lib.php +++ b/libraries/sql.lib.php @@ -1806,14 +1806,14 @@ function PMA_sendResponseOrGetHtmlForTableMaintenance($disp_mode, $db, $message, * @param object $bookmark_created_msg message for bookmark creation * @param string $table_html html for the table for displaying sql * results - * @param string $index_problems_html html for displaying errors in indexes + * @param string $indexes_problems_html html for displaying errors in indexes * @param string $print_button_html html for the print button in printview * * @return string $html_output */ function PMA_getHtmlForSqlQueryResults($previous_update_query_html, $profiling_chart_html, $missing_unique_column_msg, $bookmark_created_msg, - $table_html, $index_problems_html, $print_button_html + $table_html, $indexes_problems_html, $print_button_html ) { //begin the sqlqueryresults div here. container div $html_output = '
'; @@ -1825,10 +1825,192 @@ function PMA_getHtmlForSqlQueryResults($previous_update_query_html, $html_output .= isset($bookmark_created_msg) ? $bookmark_created_msg->getDisplay() : ''; $html_output .= $table_html; - $html_output .= isset($index_problems_html) ? $index_problems_html : ''; + $html_output .= isset($indexes_problems_html) ? $index_problems_html : ''; $html_output .= isset($print_button_html) ? $print_button_html : ''; $html_output .= '
'; // end sqlqueryresults div return $html_output; } + +/** + * Returns a message for successful creation of a bookmark or null if a bookmark + * was not created + * + * @return object $bookmark_created_msg + */ +function PMA_getBookmarkCreatedMessage() +{ + if (isset($_GET['label'])) { + $bookmark_created_msg = PMA_message::success(__('Bookmark %s created')); + $bookmark_created_msg->addParam($_GET['label']); + } else { + $bookmark_created_msg = null; + } + + return $bookmark_created_msg; +} + +/** + * Function to get html for the sql query results table + * + * @param array $sql_data sql data + * @param object $displayResultsObject instance of DisplayResult.class + * @param string $db current database + * @param string $goto goto page url + * @param string $pmaThemeImage theme image uri + * @param string $text_dir + * @param string $url_query url query + * @param string $disp_mode display mode + * @param string $sql_limit_to_append sql limit to append + * @param bool $editable whether the result table is editable or not + * @param int $unlim_num_rows unlimited number of rows + * @param bool $showtable + * @param object $result result of the executed query + * @param int $querytime query execution time + * @param array $analyzed_sql_results analyzed sql results + * @param bool $is_procedure + * + * @return type + */ +function PMA_getHtmlForSqlQueryResultsTable($sql_data, $displayResultsObject, $db, + $goto, $pmaThemeImage, $text_dir, $url_query, $disp_mode, $sql_limit_to_append, + $editable, $unlim_num_rows, $num_rows, $showtable, $result, $querytime, + $analyzed_sql_results, $is_procedure +) { + $printview = isset($_REQUEST['printview']) ? $_REQUEST['printview'] : null; + if (! empty($sql_data) && ($sql_data['valid_queries'] > 1) || $is_procedure) { + $_SESSION['is_multi_query'] = true; + $table_html = getTableHtmlForMultipleQueries( + $displayResultsObject, $db, $sql_data, $goto, + $pmaThemeImage, $text_dir, $printview, $url_query, + $disp_mode, $sql_limit_to_append, $editable + ); + } else { + if (isset($result) && $result) { + $fields_meta = $GLOBALS['dbi']->getFieldsMeta($result); + $fields_cnt = count($fields_meta); + } + $_SESSION['is_multi_query'] = false; + $displayResultsObject->setProperties( + $unlim_num_rows, $fields_meta, $analyzed_sql_results['is_count'], + $analyzed_sql_results['is_export'], $analyzed_sql_results['is_func'], + $analyzed_sql_results['is_analyse'], $num_rows, + $fields_cnt, $querytime, $pmaThemeImage, $text_dir, + $analyzed_sql_results['is_maint'], $analyzed_sql_results['is_explain'], + $analyzed_sql_results['is_show'], $showtable,$printview, $url_query, + $editable + ); + + $table_html = $displayResultsObject->getTable( + $result, $disp_mode, $analyzed_sql_results['analyzed_sql'] + ); + $GLOBALS['dbi']->freeResult($result); + } + + return $table_html; +} + +/** + * Function to get html for the previous query if there is such. If not will return + * null + * + * @param type $disp_query + * @param type $showSql + * @param type $sql_data + * @param type $disp_message + * + * @return string $previous_update_query_html + */ +function PMA_getHtmlForPreviousUpdateQuery($disp_query, $showSql, $sql_data, + $disp_message +) { + // previous update query (from tbl_replace) + if (isset($disp_query) && ($showSql == true) && empty($sql_data)) { + $previous_update_query_html = PMA_Util::getMessage( + $disp_message, $disp_query, 'success' + ); + } else { + $previous_update_query_html = null; + } + + return $previous_update_query_html; +} + +/** + * To get the message if a column index is missing. If not will return null + * + * @param string $table current table + * @param string $db current database + * @param boolean $editable whether the results table can be editable or not + * @param string $disp_mode display mode + * + * @return object $message + */ +function PMA_getMessageIfMissingColumnIndex($table, $db, $editable, $disp_mode) +{ + if (!empty($table) && ($GLOBALS['dbi']->isSystemSchema($db) || !$editable)) { + $missing_unique_column_msg = PMA_message::notice( + __( + 'Table %s does not contain a unique column.' + . ' Grid edit, checkbox, Edit, Copy and Delete features' + . ' are not available.' + ) + ); + $missing_unique_column_msg->addParam($table); + } else { + $missing_unique_column_msg = null; + } + + return $missing_unique_column_msg; +} + +/** + * Function to get html to display problems in indexes + * + * @param string $query_type query type + * @param boolean $selected + * + * @return void + */ +function PMA_getHtmlForIndexesProblems($query_type, $selected) +{ + // BEGIN INDEX CHECK See if indexes should be checked. + if (isset($query_type) + && $query_type == 'check_tbl' + && isset($selected) + && is_array($selected) + ) { + $indexes_problems_html = ''; + foreach ($selected as $idx => $tbl_name) { + $check = PMA_Index::findDuplicates($tbl_name, $db); + if (! empty($check)) { + $indexes_problems_html .= sprintf( + __('Problems with indexes of table `%s`'), $tbl_name + ); + $indexes_problems_html .= $check; + } + } + } else { + $indexes_problems_html = null; + } + + return $indexes_problems_html; +} + +/** + * Function to get the html for the print button in printview + * + * @return string $print_button_html html for the print button + */ +function PMA_getHtmlForPrintButton() +{ + // Do print the page if required + if (isset($_REQUEST['printview']) && $_REQUEST['printview'] == '1') { + $print_button_html = PMA_Util::getButton(); + } else { + $print_button_html = null; + } + + return $print_button_html; +} ?> diff --git a/sql.php b/sql.php index 692d6eec90..86e222ebe5 100644 --- a/sql.php +++ b/sql.php @@ -244,7 +244,6 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { // Should be initialized these parameters before parsing $showtable = isset($showtable) ? $showtable : null; - $printview = isset($_REQUEST['printview']) ? $_REQUEST['printview'] : null; $url_query = isset($url_query) ? $url_query : null; $response = PMA_Response::getInstance(); @@ -262,7 +261,7 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { ); } - // Displays the headers + //Displays the headers if (isset($show_query)) { unset($show_query); } @@ -282,6 +281,21 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { $GLOBALS['buffer_message'] = false; } + // hide edit and delete links: + // - for information_schema + // - if the result set does not contain all the columns of a unique key + // and we are not just browing all the columns of an updatable view + $updatableView + = $justBrowsing + && trim($analyzed_sql[0]['select_expr_clause']) == '*' + && PMA_Table::isUpdatableView($db, $table); + + $has_unique = PMA_resultSetContainsUniqueKey( + $db, $table, $fields_meta + ); + + $editable = $has_unique || $updatableView; + // Displays the results in a table if (empty($disp_mode)) { // see the "PMA_setDisplayMode()" function in @@ -289,22 +303,19 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { $disp_mode = 'urdr111101'; } + if (!empty($table) && ($GLOBALS['dbi']->isSystemSchema($db) || !$editable)) { + $disp_mode = 'nnnn110111'; + } + if (strlen($db)) { $cfgRelation = PMA_getRelationsParam(); } - - $has_unique = PMA_resultSetContainsUniqueKey( - $db, $table, $fields_meta - ); - // previous update query (from tbl_replace) - if (isset($disp_query) && ($cfg['ShowSQL'] == true) && empty($sql_data)) { - $previous_update_query_html = PMA_Util::getMessage( - $disp_message, $disp_query, 'success' - ); - } else { - $previous_update_query_html = null; - } + $previous_update_query_html = PMA_getHtmlForPreviousUpdateQuery( + isset($disp_query) ? $disp_query : null, + $cfg['ShowSQL'], isset($sql_data) ? $sql_data : null, + isset($disp_message) ? $disp_message : null + ); if (isset($profiling_results)) { // pma_token/url_query needed for chart export @@ -318,79 +329,24 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { $profiling_chart_html = null; } - // hide edit and delete links: - // - for information_schema - // - if the result set does not contain all the columns of a unique key - // and we are not just browing all the columns of an updatable view - $updatableView - = $justBrowsing - && trim($analyzed_sql[0]['select_expr_clause']) == '*' - && PMA_Table::isUpdatableView($db, $table); + $missing_unique_column_msg = PMA_getMessageIfMissingColumnIndex($table, $db, + $editable, $disp_mode + ); - $editable = $has_unique || $updatableView; + $bookmark_created_msg = PMA_getBookmarkCreatedMessage(); - if (!empty($table) && ($GLOBALS['dbi']->isSystemSchema($db) || !$editable)) { - $disp_mode = 'nnnn110111'; - $missing_unique_column_msg = PMA_message::notice( - __( - 'Table %s does not contain a unique column.' - . ' Grid edit, checkbox, Edit, Copy and Delete features' - . ' are not available.' - ) - ); - $missing_unique_column_msg->addParam($table); - } else { - $missing_unique_column_msg = null; - } + $table_html = PMA_getHtmlForSqlQueryResultsTable( + isset($sql_data) ? $sql_data : null, $displayResultsObject, $db, $goto, + $pmaThemeImage, $text_dir, $url_query, $disp_mode, $sql_limit_to_append, + $editable, $unlim_num_rows, $num_rows, $showtable, $result, $querytime, + $analyzed_sql_results, $is_procedure + ); - if (isset($_GET['label'])) { - $bookmark_created_msg = PMA_message::success(__('Bookmark %s created')); - $bookmark_created_msg->addParam($_GET['label']); - } else { - $bookmark_created_msg = null; - } - - if (! empty($sql_data) && ($sql_data['valid_queries'] > 1) || $is_procedure) { - $_SESSION['is_multi_query'] = true; - $table_html = getTableHtmlForMultipleQueries( - $displayResultsObject, $db, $sql_data, $goto, - $pmaThemeImage, $text_dir, $printview, $url_query, - $disp_mode, $sql_limit_to_append, $editable - ); - } else { - $_SESSION['is_multi_query'] = false; - $displayResultsObject->setProperties( - $unlim_num_rows, $fields_meta, $is_count, $is_export, $is_func, - $is_analyse, $num_rows, $fields_cnt, $querytime, $pmaThemeImage, - $text_dir, $is_maint, $is_explain, $is_show, $showtable, - $printview, $url_query, $editable - ); - - $table_html = $displayResultsObject->getTable( - $result, $disp_mode, $analyzed_sql - ); - $GLOBALS['dbi']->freeResult($result); - } - // BEGIN INDEX CHECK See if indexes should be checked. - if (isset($query_type) - && $query_type == 'check_tbl' - && isset($selected) - && is_array($selected) - ) { - $index_problems_html = ''; - foreach ($selected as $idx => $tbl_name) { - $check = PMA_Index::findDuplicates($tbl_name, $db); - if (! empty($check)) { - $index_problems_html .= sprintf( - __('Problems with indexes of table `%s`'), $tbl_name - ); - $index_problems_html .= $check; - } - } - } else { - $index_problems_html = null; - } + $indexes_problems_html = PMA_getHtmlForIndexesProblems( + isset($query_type) ? $query_type : null, + isset($selected) ? $selected : null + ); // Bookmark support if required if ($disp_mode[7] == '1' @@ -412,16 +368,11 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { $bookmark_support_html = null; } - // Do print the page if required - if (isset($_REQUEST['printview']) && $_REQUEST['printview'] == '1') { - $print_button_html = PMA_Util::getButton(); - } else { - $print_button_html = null; - } + $print_button_html = PMA_getHtmlForPrintButton(); $html_output .= PMA_getHtmlForSqlQueryResults($previous_update_query_html, $profiling_chart_html, $missing_unique_column_msg, $bookmark_created_msg, - $table_html, $index_problems_html, $print_button_html + $table_html, $indexes_problems_html, $print_button_html ); $response->addHTML($html_output); From 9c14ce3ee8b52449d3bf381748a16f7188c058d6 Mon Sep 17 00:00:00 2001 From: Spun Nakandala Date: Tue, 9 Jul 2013 18:27:24 +0530 Subject: [PATCH 07/24] added method PMA_getHtmlForPrintView --- libraries/sql.lib.php | 17 +++++++++++++++++ sql.php | 21 ++++----------------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/libraries/sql.lib.php b/libraries/sql.lib.php index 265bd20ee9..52aa9c8e76 100644 --- a/libraries/sql.lib.php +++ b/libraries/sql.lib.php @@ -2013,4 +2013,21 @@ function PMA_getHtmlForPrintButton() return $print_button_html; } + +function PMA_getHtmlForPrintView($db, $full_sql_query, $num_rows) +{ + $response = PMA_Response::getInstance(); + $header = $response->getHeader(); + if (isset($_REQUEST['printview']) && $_REQUEST['printview'] == '1') { + PMA_Util::checkParameters(array('db', 'full_sql_query')); + $header->enablePrintView(); + $print_view_html = PMA_getHtmlForPrintViewHeader( + $db, $full_sql_query, $num_rows + ); + }else{ + $print_view_html = null; + } + + return $print_view_html; +} ?> diff --git a/sql.php b/sql.php index 86e222ebe5..de0a8bf89f 100644 --- a/sql.php +++ b/sql.php @@ -239,7 +239,6 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { // Gets the list of fields properties if (isset($result) && $result) { $fields_meta = $GLOBALS['dbi']->getFieldsMeta($result); - $fields_cnt = count($fields_meta); } // Should be initialized these parameters before parsing @@ -260,19 +259,8 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { $querytime, $analyzed_sql_results ); } - - //Displays the headers - if (isset($show_query)) { - unset($show_query); - } - if (isset($_REQUEST['printview']) && $_REQUEST['printview'] == '1') { - PMA_Util::checkParameters(array('db', 'full_sql_query')); - $header->enablePrintView(); - $html_output .= PMA_getHtmlForPrintViewHeader( - $db, $full_sql_query, $num_rows - ); - } else { + if (!isset($_REQUEST['printview']) || $_REQUEST['printview'] != '1') { $scripts->addFile('makegrid.js'); $scripts->addFile('sql.js'); unset($message); @@ -306,10 +294,9 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { if (!empty($table) && ($GLOBALS['dbi']->isSystemSchema($db) || !$editable)) { $disp_mode = 'nnnn110111'; } - - if (strlen($db)) { - $cfgRelation = PMA_getRelationsParam(); - } + + $print_view_html = PMA_getHtmlForPrintView($db, $full_sql_query, $num_rows); + $html_output .= isset($print_view_html) ? $print_view_html : ''; $previous_update_query_html = PMA_getHtmlForPreviousUpdateQuery( isset($disp_query) ? $disp_query : null, From 765a3e464a0b8d656e2b3e569829796db47e4d76 Mon Sep 17 00:00:00 2001 From: Spun Nakandala Date: Tue, 9 Jul 2013 19:32:33 +0530 Subject: [PATCH 08/24] changed PMA_getHtmlForBookmark function --- libraries/sql.lib.php | 123 +++++++++++++++++++++++++----------------- sql.php | 26 +++------ 2 files changed, 79 insertions(+), 70 deletions(-) diff --git a/libraries/sql.lib.php b/libraries/sql.lib.php index 52aa9c8e76..e132101e61 100644 --- a/libraries/sql.lib.php +++ b/libraries/sql.lib.php @@ -653,56 +653,77 @@ function PMA_getHtmlForOptionsList($values, $selected_values) } /** - * 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 to get html for bookmark support if bookmarks are enabled. Else will + * return null * - * @return void + * @param string $disp_mode display mode + * @param bool $cfgBookmark + * @param string $sql_query sql query + * @param string $db current database + * @param string $table current table + * @param string $complete_query complete query + * @param string $bkm_user bookmarking user + * + * @return string $html */ -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 .= '
'; - +function PMA_getHtmlForBookmark($disp_mode, $cfgBookmark, $sql_query, $db, $table, + $complete_query, $bkm_user +) { + if ($disp_mode[7] == '1' + && (! empty($cfgBookmark) && empty($_GET['id_bookmark'])) + && ! empty($sql_query) + ) { + $html = "\n"; + $goto = 'sql.php?' + . PMA_generate_common_url($db, $table) + . '&sql_query=' . urlencode($sql_query) + . '&id_bookmark=1'; + $bkm_sql_query = urlencode( + isset($complete_query) ? $complete_query : $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 .= '
'; + + } else { + $html = null; + } + return $html; } @@ -1807,13 +1828,14 @@ function PMA_sendResponseOrGetHtmlForTableMaintenance($disp_mode, $db, $message, * @param string $table_html html for the table for displaying sql * results * @param string $indexes_problems_html html for displaying errors in indexes + * @param string $bookmark_support_html html for displaying bookmark form * @param string $print_button_html html for the print button in printview * * @return string $html_output */ function PMA_getHtmlForSqlQueryResults($previous_update_query_html, $profiling_chart_html, $missing_unique_column_msg, $bookmark_created_msg, - $table_html, $indexes_problems_html, $print_button_html + $table_html, $indexes_problems_html, $bookmark_support_html, $print_button_html ) { //begin the sqlqueryresults div here. container div $html_output = '
'; @@ -1825,7 +1847,8 @@ function PMA_getHtmlForSqlQueryResults($previous_update_query_html, $html_output .= isset($bookmark_created_msg) ? $bookmark_created_msg->getDisplay() : ''; $html_output .= $table_html; - $html_output .= isset($indexes_problems_html) ? $index_problems_html : ''; + $html_output .= isset($indexes_problems_html) ? $indexes_problems_html : ''; + $html_output .= isset($bookmark_support_html) ? $bookmark_support_html : ''; $html_output .= isset($print_button_html) ? $print_button_html : ''; $html_output .= '
'; // end sqlqueryresults div diff --git a/sql.php b/sql.php index de0a8bf89f..f0840de860 100644 --- a/sql.php +++ b/sql.php @@ -335,31 +335,17 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { isset($selected) ? $selected : null ); - // Bookmark support if required - if ($disp_mode[7] == '1' - && (! empty($cfg['Bookmark']) && empty($_GET['id_bookmark'])) - && ! empty($sql_query) - ) { - $bookmark_support_html = "\n"; - $goto = 'sql.php?' - . PMA_generate_common_url($db, $table) - . '&sql_query=' . urlencode($sql_query) - . '&id_bookmark=1'; - $bkm_sql_query = urlencode( - isset($complete_query) ? $complete_query : $sql_query - ); - $bookmark_support_html .= PMA_getHtmlForBookmark( - $db, $goto, $bkm_sql_query, $cfg['Bookmark']['user'] - ); - } else { - $bookmark_support_html = null; - } + $bookmark_support_html = PMA_getHtmlForBookmark($disp_mode, + isset($cfg['Bookmark']) ? $cfg['Bookmark'] : '', $html_output, + $sql_limit_to_append, $err_url, $goto, $cfg['Bookmark']['user'] + ); $print_button_html = PMA_getHtmlForPrintButton(); $html_output .= PMA_getHtmlForSqlQueryResults($previous_update_query_html, $profiling_chart_html, $missing_unique_column_msg, $bookmark_created_msg, - $table_html, $indexes_problems_html, $print_button_html + $table_html, $indexes_problems_html, $bookmark_support_html, + $print_button_html ); $response->addHTML($html_output); From 419876ee4c37b9397be560042ad4955eadf736a5 Mon Sep 17 00:00:00 2001 From: Spun Nakandala Date: Tue, 9 Jul 2013 21:03:16 +0530 Subject: [PATCH 09/24] changed method PMA_getHtmlForProfilingChart --- libraries/sql.lib.php | 225 ++++++++++++++++++++++-------------------- sql.php | 14 +-- 2 files changed, 119 insertions(+), 120 deletions(-) diff --git a/libraries/sql.lib.php b/libraries/sql.lib.php index e132101e61..b89bfd6faa 100644 --- a/libraries/sql.lib.php +++ b/libraries/sql.lib.php @@ -426,133 +426,140 @@ function PMA_getHtmlForPrintViewHeader($db, $sql_query, $num_rows) } /** - * Get the HTML for the profiling table and accompanying chart + * Get the HTML for the profiling table and accompanying chart if profiling is set. + * Ptherwise returns null * - * @param string $url_query the url query - * @param string $pma_token the pma token + * @param string $url_query url query + * @param string $db current database * @param array $profiling_results array containing the profiling info * * @return string $profiling_table html for the profiling table and chart */ -function PMA_getHtmlForProfilingChart($url_query, $pma_token, $profiling_results) +function PMA_getHtmlForProfilingChart($url_query, $db, $profiling_results) { - $profiling_stats = array( - 'total_time' => 0, - 'states' => array(), - ); - $profiling_table = ''; - - $profiling_table .= '
' . __('Profiling') . '' . "\n"; - $profiling_table .= '
'; - $profiling_table .= '

' . __('Detailed profile') . '

'; - $profiling_table .= '' . "\n"; - $profiling_table .= ' ' . "\n"; - $profiling_table .= ' ' . "\n"; - $profiling_table .= ' ' . "\n"; - $profiling_table .= ' ' . "\n"; - $profiling_table .= ' ' . "\n"; - - $chart_json = Array(); - $i = 1; - foreach ($profiling_results as $one_result) { - if (isset($profiling_stats['states'][ucwords($one_result['Status'])])) { - $profiling_stats['states'][ucwords($one_result['Status'])]['time'] - += $one_result['Duration']; - $profiling_stats['states'][ucwords($one_result['Status'])]['calls']++; - } else { - $profiling_stats['states'][ucwords($one_result['Status'])] = array( - 'total_time' => $one_result['Duration'], - 'calls' => 1, - ); - } - $profiling_stats['total_time'] += $one_result['Duration']; + if (isset($profiling_results)) { + $pma_token = $_SESSION[' PMA_token ']; + $url_query = (isset($url_query) ? $url_query : PMA_generate_common_url($db)); + + $profiling_stats = array( + 'total_time' => 0, + 'states' => array(), + ); + $profiling_table = ''; + $profiling_table .= '
' . __('Profiling') . '' . "\n"; + $profiling_table .= '
'; + $profiling_table .= '

' . __('Detailed profile') . '

'; + $profiling_table .= '
' . __('Order') - . '
' . __('State') - . PMA_Util::showMySQLDocu( - 'general-thread-states', 'general-thread-states' - ) - . '
' . __('Time') - . '
' . "\n"; $profiling_table .= ' ' . "\n"; - $profiling_table .= '' . "\n"; - $profiling_table .= '' . "\n"; - $profiling_table .= '' . "\n"; - if (isset($chart_json[ucwords($one_result['Status'])])) { - $chart_json[ucwords($one_result['Status'])] - += $one_result['Duration']; - } else { - $chart_json[ucwords($one_result['Status'])] - = $one_result['Duration']; - } - } - - $profiling_table .= '
' . $i++ . '' . ucwords($one_result['Status']) . '' - . (PMA_Util::formatNumber($one_result['Duration'], 3, 1)) - . 's
' . "\n"; - $profiling_table .= '
'; - - $profiling_table .= '
'; - $profiling_table .= '

' . __('Summary by state') . '

'; - $profiling_table .= '' . "\n"; - $profiling_table .= ' ' . "\n"; - $profiling_table .= ' ' . "\n"; - $profiling_table .= ' ' . "\n"; - $profiling_table .= ' ' . "\n"; - $profiling_table .= ' ' . "\n"; - $profiling_table .= ' ' . "\n"; - $profiling_table .= ' ' . "\n"; - foreach ($profiling_stats['states'] as $name => $stats) { - $profiling_table .= ' ' . "\n"; - $profiling_table .= '' . "\n"; - $profiling_table .= '' . "\n"; - $profiling_table .= '' . "\n"; + $profiling_table .= ' ' . "\n"; + $profiling_table .= ' ' . "\n"; + $profiling_table .= ' ' . "\n"; + + $chart_json = Array(); + $i = 1; + foreach ($profiling_results as $one_result) { + if (isset($profiling_stats['states'][ucwords($one_result['Status'])])) { + $profiling_stats['states'][ucwords($one_result['Status'])]['time'] + += $one_result['Duration']; + $profiling_stats['states'][ucwords($one_result['Status'])]['calls']++; + } else { + $profiling_stats['states'][ucwords($one_result['Status'])] = array( + 'total_time' => $one_result['Duration'], + 'calls' => 1, + ); + } + $profiling_stats['total_time'] += $one_result['Duration']; + + $profiling_table .= ' ' . "\n"; + $profiling_table .= '' . "\n"; + $profiling_table .= '' . "\n"; + $profiling_table .= '' . "\n"; + if (isset($chart_json[ucwords($one_result['Status'])])) { + $chart_json[ucwords($one_result['Status'])] + += $one_result['Duration']; + } else { + $chart_json[ucwords($one_result['Status'])] + = $one_result['Duration']; + } + } + + $profiling_table .= '
' . __('State') - . PMA_Util::showMySQLDocu( - 'general-thread-states', 'general-thread-states' - ) - . '
' . __('Total Time') - . '
' . __('% Time') - . '
' . __('Calls') - . '
' . __('ø Time') - . '
' . $name . '' - . PMA_Util::formatNumber($stats['total_time'], 3, 1) - . 's' - . PMA_Util::formatNumber( - 100 * ($stats['total_time'] / $profiling_stats['total_time']), 0, 2 + $profiling_table .= ' ' . __('Order') + . '
' . __('State') + . PMA_Util::showMySQLDocu( + 'general-thread-states', 'general-thread-states' ) + . '
' . __('Time') + . '
' . $i++ . '' . ucwords($one_result['Status']) . '' + . (PMA_Util::formatNumber($one_result['Duration'], 3, 1)) + . 's
' . "\n"; + $profiling_table .= '
'; + + $profiling_table .= '
'; + $profiling_table .= '

' . __('Summary by state') . '

'; + $profiling_table .= '' . "\n"; + $profiling_table .= ' ' . "\n"; + $profiling_table .= ' ' . "\n"; + $profiling_table .= ' ' . "\n"; + $profiling_table .= ' ' . "\n"; + $profiling_table .= ' ' . "\n"; + $profiling_table .= ' ' . "\n"; + $profiling_table .= ' ' . "\n"; + foreach ($profiling_stats['states'] as $name => $stats) { + $profiling_table .= ' ' . "\n"; + $profiling_table .= '' . "\n"; + $profiling_table .= '' . "\n"; + $profiling_table .= '' . "\n"; - $profiling_table .= '' . "\n"; - $profiling_table .= '' . "\n"; - $profiling_table .= ' ' . "\n"; - } + $profiling_table .= '' . "\n"; + $profiling_table .= '' . "\n"; + $profiling_table .= ' ' . "\n"; + } - $profiling_table .= '
' . __('State') + . PMA_Util::showMySQLDocu( + 'general-thread-states', 'general-thread-states' + ) + . '
' . __('Total Time') + . '
' . __('% Time') + . '
' . __('Calls') + . '
' . __('ø Time') + . '
' . $name . '' + . PMA_Util::formatNumber($stats['total_time'], 3, 1) + . 's' + . PMA_Util::formatNumber( + 100 * ($stats['total_time'] / $profiling_stats['total_time']), 0, 2 + ) . '%' . $stats['calls'] . '' - . PMA_Util::formatNumber($stats['total_time'] / $stats['calls'], 3, 1) - . 's
' . $stats['calls'] . '' + . PMA_Util::formatNumber($stats['total_time'] / $stats['calls'], 3, 1) + . 's
' . "\n"; + $profiling_table .= '' . "\n"; - $profiling_table .= << pma_token = '$pma_token'; url_query = '$url_query'; EOT; - $profiling_table .= "
"; - - //require_once 'libraries/chart.lib.php'; - $profiling_table .= ''; - $profiling_table .= ''; - $profiling_table .= ''; - $profiling_table .= '
' . "\n"; + $profiling_table .= ""; + //require_once 'libraries/chart.lib.php'; + $profiling_table .= ''; + $profiling_table .= ''; + $profiling_table .= ''; + $profiling_table .= '' . "\n"; + } else { + $profiling_table = null; + } return $profiling_table; } diff --git a/sql.php b/sql.php index f0840de860..b27f10ab63 100644 --- a/sql.php +++ b/sql.php @@ -304,17 +304,9 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { isset($disp_message) ? $disp_message : null ); - if (isset($profiling_results)) { - // pma_token/url_query needed for chart export - $token = $_SESSION[' PMA_token ']; - $url = (isset($url_query) ? $url_query : PMA_generate_common_url($db)); - - $profiling_chart_html = PMA_getHtmlForProfilingChart( - $url, $token, $profiling_results - ); - } else { - $profiling_chart_html = null; - } + $profiling_chart_html = PMA_getHtmlForProfilingChart($disp_mode, $html_output, + isset($profiling_results) ? $profiling_results : null + ); $missing_unique_column_msg = PMA_getMessageIfMissingColumnIndex($table, $db, $editable, $disp_mode From 07cd7234cf073565263d6c0d654421e0dd01b33c Mon Sep 17 00:00:00 2001 From: Spun Nakandala Date: Tue, 9 Jul 2013 21:12:00 +0530 Subject: [PATCH 10/24] removed method PMA_getHtmlForPrintView and changed the method PMA_getHtmlForPrintViewHeader --- libraries/sql.lib.php | 88 ++++++++++++++++++++----------------------- sql.php | 6 ++- 2 files changed, 44 insertions(+), 50 deletions(-) diff --git a/libraries/sql.lib.php b/libraries/sql.lib.php index b89bfd6faa..2b6570aee8 100644 --- a/libraries/sql.lib.php +++ b/libraries/sql.lib.php @@ -381,7 +381,8 @@ function PMA_getHtmlForRelationalColumnDropdown($db, $table, $column, $curr_valu } /** - * Get the HTML for the header of the page in print view + * Get the HTML for the header of the page in print view if print view is selected. + * Otherwise returns null. * * @param string $db current database * @param string $sql_query current sql query @@ -391,38 +392,46 @@ function PMA_getHtmlForRelationalColumnDropdown($db, $table, $column, $curr_valu */ function PMA_getHtmlForPrintViewHeader($db, $sql_query, $num_rows) { - $hostname = ''; - if ( $GLOBALS['cfg']['Server']['verbose']) { - $hostname = $GLOBALS['cfg']['Server']['verbose']; - } else { - $hostname = $GLOBALS['cfg']['Server']['host']; - if (! empty( $GLOBALS['cfg']['Server']['port'])) { - $hostname .= $GLOBALS['cfg']['Server']['port']; + $response = PMA_Response::getInstance(); + $header = $response->getHeader(); + if (isset($_REQUEST['printview']) && $_REQUEST['printview'] == '1') { + PMA_Util::checkParameters(array('db', 'full_sql_query')); + $header->enablePrintView(); + $hostname = ''; + if ( $GLOBALS['cfg']['Server']['verbose']) { + $hostname = $GLOBALS['cfg']['Server']['verbose']; + } else { + $hostname = $GLOBALS['cfg']['Server']['host']; + if (! empty( $GLOBALS['cfg']['Server']['port'])) { + $hostname .= $GLOBALS['cfg']['Server']['port']; + } } + + $versions = "phpMyAdmin " . PMA_VERSION; + $versions .= " / "; + $versions .= "MySQL " . PMA_MYSQL_STR_VERSION; + + $print_view_header = ''; + $print_view_header .= "

" . __('SQL result') . "

"; + $print_view_header .= "

"; + $print_view_header .= "" . __('Host:') . " $hostname
"; + $print_view_header .= "" . __('Database:') . " " + . htmlspecialchars($db) . "
"; + $print_view_header .= "" . __('Generation Time:') . " " + . PMA_Util::localisedDate() . "
"; + $print_view_header .= "" . __('Generated by:') . " $versions
"; + $print_view_header .= "" . __('SQL query:') . " " + . htmlspecialchars($sql_query) . ";"; + if (isset($num_rows)) { + $print_view_header .= "
"; + $print_view_header .= "" . __('Rows:') . " $num_rows"; + } + $print_view_header .= "

"; + }else{ + $print_view_header = null; } - - $versions = "phpMyAdmin " . PMA_VERSION; - $versions .= " / "; - $versions .= "MySQL " . PMA_MYSQL_STR_VERSION; - - $header = ''; - $header .= "

" . __('SQL result') . "

"; - $header .= "

"; - $header .= "" . __('Host:') . " $hostname
"; - $header .= "" . __('Database:') . " " - . htmlspecialchars($db) . "
"; - $header .= "" . __('Generation Time:') . " " - . PMA_Util::localisedDate() . "
"; - $header .= "" . __('Generated by:') . " $versions
"; - $header .= "" . __('SQL query:') . " " - . htmlspecialchars($sql_query) . ";"; - if (isset($num_rows)) { - $header .= "
"; - $header .= "" . __('Rows:') . " $num_rows"; - } - $header .= "

"; - - return $header; + + return $print_view_header; } /** @@ -2043,21 +2052,4 @@ function PMA_getHtmlForPrintButton() return $print_button_html; } - -function PMA_getHtmlForPrintView($db, $full_sql_query, $num_rows) -{ - $response = PMA_Response::getInstance(); - $header = $response->getHeader(); - if (isset($_REQUEST['printview']) && $_REQUEST['printview'] == '1') { - PMA_Util::checkParameters(array('db', 'full_sql_query')); - $header->enablePrintView(); - $print_view_html = PMA_getHtmlForPrintViewHeader( - $db, $full_sql_query, $num_rows - ); - }else{ - $print_view_html = null; - } - - return $print_view_html; -} ?> diff --git a/sql.php b/sql.php index b27f10ab63..ce0c7d2b50 100644 --- a/sql.php +++ b/sql.php @@ -295,8 +295,10 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { $disp_mode = 'nnnn110111'; } - $print_view_html = PMA_getHtmlForPrintView($db, $full_sql_query, $num_rows); - $html_output .= isset($print_view_html) ? $print_view_html : ''; + $print_view_header_html = PMA_getHtmlForPrintViewHeader($db, $full_sql_query, + $num_rows + ); + $html_output .= isset($print_view_header_html) ? $print_view_header_html : ''; $previous_update_query_html = PMA_getHtmlForPreviousUpdateQuery( isset($disp_query) ? $disp_query : null, From 4acc14051e77b5f98803550d99f1456a6411c735 Mon Sep 17 00:00:00 2001 From: Spun Nakandala Date: Tue, 9 Jul 2013 21:35:26 +0530 Subject: [PATCH 11/24] error corrected --- sql.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/sql.php b/sql.php index ce0c7d2b50..ffadf9ba32 100644 --- a/sql.php +++ b/sql.php @@ -248,7 +248,7 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { $response = PMA_Response::getInstance(); $header = $response->getHeader(); $scripts = $header->getScripts(); - + if (isset($_REQUEST['table_maintenance'])) { $html_output .= PMA_sendResponseOrGetHtmlForTableMaintenance( isset($disp_mode) ? $disp_mode : null, $db, @@ -259,7 +259,7 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { $querytime, $analyzed_sql_results ); } - + if (!isset($_REQUEST['printview']) || $_REQUEST['printview'] != '1') { $scripts->addFile('makegrid.js'); $scripts->addFile('sql.js'); @@ -268,7 +268,7 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { //set a global variable and check against it in the function $GLOBALS['buffer_message'] = false; } - + // hide edit and delete links: // - for information_schema // - if the result set does not contain all the columns of a unique key @@ -289,8 +289,7 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { // see the "PMA_setDisplayMode()" function in // libraries/DisplayResults.class.php $disp_mode = 'urdr111101'; - } - + } if (!empty($table) && ($GLOBALS['dbi']->isSystemSchema($db) || !$editable)) { $disp_mode = 'nnnn110111'; } @@ -298,7 +297,6 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { $print_view_header_html = PMA_getHtmlForPrintViewHeader($db, $full_sql_query, $num_rows ); - $html_output .= isset($print_view_header_html) ? $print_view_header_html : ''; $previous_update_query_html = PMA_getHtmlForPreviousUpdateQuery( isset($disp_query) ? $disp_query : null, @@ -306,7 +304,7 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { isset($disp_message) ? $disp_message : null ); - $profiling_chart_html = PMA_getHtmlForProfilingChart($disp_mode, $html_output, + $profiling_chart_html = PMA_getHtmlForProfilingChart($disp_mode, $db, isset($profiling_results) ? $profiling_results : null ); @@ -330,12 +328,14 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { ); $bookmark_support_html = PMA_getHtmlForBookmark($disp_mode, - isset($cfg['Bookmark']) ? $cfg['Bookmark'] : '', $html_output, + isset($cfg['Bookmark']) ? $cfg['Bookmark'] : '', $sql_query, $sql_limit_to_append, $err_url, $goto, $cfg['Bookmark']['user'] ); $print_button_html = PMA_getHtmlForPrintButton(); + $html_output .= isset($print_view_header_html) ? $print_view_header_html : ''; + $html_output .= PMA_getHtmlForSqlQueryResults($previous_update_query_html, $profiling_chart_html, $missing_unique_column_msg, $bookmark_created_msg, $table_html, $indexes_problems_html, $bookmark_support_html, From 503df0a6a7df442a4292411e14a49339eb7ded79 Mon Sep 17 00:00:00 2001 From: Spun Nakandala Date: Tue, 9 Jul 2013 22:32:02 +0530 Subject: [PATCH 12/24] removed redundant methods --- libraries/sql.lib.php | 131 ------------------------------------------ sql.php | 56 +++++++++++------- 2 files changed, 34 insertions(+), 153 deletions(-) diff --git a/libraries/sql.lib.php b/libraries/sql.lib.php index 2b6570aee8..7df6584d90 100644 --- a/libraries/sql.lib.php +++ b/libraries/sql.lib.php @@ -1703,137 +1703,6 @@ function PMA_sendResponseForGridEdit($result) exit; } -/** - * Function to get the html for the table maintenance response - * - * @param string $message message - * @param array $sql_data sql data - * @param object $displayResultsObject instance of the DisplayResult.class - * @param string $db database - * @param string $goto goto page url - * @param string $pmaThemeImage theme image uri - * @param string $text_dir - * @param bool $showtable show table - * @param string $url_query url query - * @param string $disp_mode display mode - * @param string $sql_limit_to_append sql limit to append - * @param object $result result of the executed query - * @param int $unlim_num_rows unlimited number of rows - * @param int $num_rows number of rows - * @param int $querytime query time - * @param array $analyzed_sql_results analyzed sql results - * - * @return string $html_output html for the table maintence response - */ -function PMA_getHtmlForTableMaintenanceResponse($message, $sql_data, - $displayResultsObject, $db, $goto, $pmaThemeImage, $text_dir, $showtable, - $url_query, $disp_mode, $sql_limit_to_append, $result, $unlim_num_rows, - $num_rows, $querytime, $analyzed_sql_results -) { - $printview = isset($_REQUEST['printview']) ? $_REQUEST['printview'] : null; - $html_output = ''; - - if (isset($message)) { - $message = PMA_Message::success($message); - $html_output .= PMA_Util::getMessage( - $message, $GLOBALS['sql_query'], 'success' - ); - } - - if (!empty($sql_data) && ($sql_data['valid_queries'] > 1)) { - $_SESSION['is_multi_query'] = true; - $html_output .= getTableHtmlForMultipleQueries( - $displayResultsObject, $db, $sql_data, $goto, - $pmaThemeImage, $text_dir, $printview, $url_query, - $disp_mode, $sql_limit_to_append, false - ); - } else { - $_SESSION['is_multi_query'] = false; - - if (isset($result) && $result) { - $fields_meta = $GLOBALS['dbi']->getFieldsMeta($result); - $fields_cnt = count($fields_meta); - } - - $displayResultsObject->setProperties( - $unlim_num_rows, $fields_meta, $analyzed_sql_results['is_count'], - $analyzed_sql_results['is_export'], $analyzed_sql_results['is_func'], - $analyzed_sql_results['is_analyse'], $num_rows, $fields_cnt, $querytime, - $pmaThemeImage, $text_dir, $analyzed_sql_results['is_maint'], - $analyzed_sql_results['is_explain'], $analyzed_sql_results['is_show'], - $showtable, $printview, $url_query, false - ); - - $html_output .= $displayResultsObject->getTable( - $result, $disp_mode, $analyzed_sql_results['analyzed_sql'] - ); - } - - return $html_output; -} - -/** - * Function to send html for the table maintenance or to get the html for the table - * maintenance case when handling multiple queries - * - * @param string $disp_mode display mode - * @param string $db database - * @param string $message message - * @param array $sql_data sql data - * @param object $displayResultsObject instance of DisplayResult.class - * @param string $goto goto page url - * @param string $pmaThemeImage theme image uri - * @param string $text_dir - * @param bool $showtable show table - * @param string $url_query url query - * @param string $sql_limit_to_append sql limit to append - * @param object $result result of the executed query - * @param int $unlim_num_rows unlimited number of rows - * @param int $num_rows number of rows - * @param int $querytime query time - * @param array $analyzed_sql_results analyzed sql results - * - * @return string $html_output html for the table maintence response - */ -function PMA_sendResponseOrGetHtmlForTableMaintenance($disp_mode, $db, $message, - $sql_data, $displayResultsObject, $goto, $pmaThemeImage, $text_dir, $showtable, - $url_query, $sql_limit_to_append, $result, $unlim_num_rows, $num_rows, - $querytime, $analyzed_sql_results) -{ - $response = PMA_Response::getInstance(); - $header = $response->getHeader(); - $scripts = $header->getScripts(); - $scripts->addFile('makegrid.js'); - $scripts->addFile('sql.js'); - - if (empty($disp_mode)) { - // see the "PMA_setDisplayMode()" function in - // libraries/DisplayResults.class.php - $disp_mode = 'urdr111101'; - } - - // hide edit and delete links for information_schema - if ($GLOBALS['dbi']->isSystemSchema($db)) { - $disp_mode = 'nnnn110111'; - } - - $html_output = PMA_getHtmlForTableMaintenanceResponse( - isset($message) ? $message : null, - isset($sql_data) ? $sql_data : null, - $displayResultsObject, $db, $goto, $pmaThemeImage, $text_dir, - $showtable, $url_query, $disp_mode, $sql_limit_to_append, $result, - $unlim_num_rows, $num_rows, $querytime, $analyzed_sql_results - ); - - if (!empty($sql_data) && ($sql_data['valid_queries'] > 1)) { - return $html_output; - } else { - $response->addHTML($html_output); - exit(); - } -} - - /** * Function to get html for the sql query results div * diff --git a/sql.php b/sql.php index ffadf9ba32..e591a302a8 100644 --- a/sql.php +++ b/sql.php @@ -228,7 +228,6 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { ); } else { - $html_output=''; // At least one row is returned -> displays a table with results // If we are retrieving the full value of a truncated field or the original // value of a transformed field, show it here and exit @@ -248,27 +247,7 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { $response = PMA_Response::getInstance(); $header = $response->getHeader(); $scripts = $header->getScripts(); - - if (isset($_REQUEST['table_maintenance'])) { - $html_output .= PMA_sendResponseOrGetHtmlForTableMaintenance( - isset($disp_mode) ? $disp_mode : null, $db, - isset($message) ? $message : null, - isset($sql_data) ? $sql_data : null, - $displayResultsObject, $goto, $pmaThemeImage, $text_dir, $showtable, - $url_query, $sql_limit_to_append, $result, $unlim_num_rows, $num_rows, - $querytime, $analyzed_sql_results - ); - } - - if (!isset($_REQUEST['printview']) || $_REQUEST['printview'] != '1') { - $scripts->addFile('makegrid.js'); - $scripts->addFile('sql.js'); - unset($message); - //we don't need to buffer the output in getMessage here. - //set a global variable and check against it in the function - $GLOBALS['buffer_message'] = false; - } - + // hide edit and delete links: // - for information_schema // - if the result set does not contain all the columns of a unique key @@ -293,7 +272,38 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { if (!empty($table) && ($GLOBALS['dbi']->isSystemSchema($db) || !$editable)) { $disp_mode = 'nnnn110111'; } + + if (isset($_REQUEST['table_maintenance'])) { + $scripts->addFile('makegrid.js'); + $scripts->addFile('sql.js'); + if (isset($message)) { + $message = PMA_Message::success($message); + $table_maintenance_html = PMA_Util::getMessage( + $message, $GLOBALS['sql_query'], 'success' + ); + } + $table_maintenance_html .= PMA_getHtmlForSqlQueryResultsTable( + isset($sql_data) ? $sql_data : null, $displayResultsObject, $db, $goto, + $pmaThemeImage, $text_dir, $url_query, $disp_mode, $sql_limit_to_append, + false, $unlim_num_rows, $num_rows, $showtable, $result, $querytime, + $analyzed_sql_result, false + ); + if (empty($sql_data) || ($sql_data['valid_queries'] = 1)) { + $response->addHTML($html_output); + exit(); + } + } + + if (!isset($_REQUEST['printview']) || $_REQUEST['printview'] != '1') { + $scripts->addFile('makegrid.js'); + $scripts->addFile('sql.js'); + unset($message); + //we don't need to buffer the output in getMessage here. + //set a global variable and check against it in the function + $GLOBALS['buffer_message'] = false; + } + $print_view_header_html = PMA_getHtmlForPrintViewHeader($db, $full_sql_query, $num_rows ); @@ -334,6 +344,8 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { $print_button_html = PMA_getHtmlForPrintButton(); + $html_output = $table_maintenance_html; + $html_output .= isset($print_view_header_html) ? $print_view_header_html : ''; $html_output .= PMA_getHtmlForSqlQueryResults($previous_update_query_html, From cc6da648c79894d59a6b68e28a91f032d66b01b5 Mon Sep 17 00:00:00 2001 From: Spun Nakandala Date: Tue, 9 Jul 2013 22:38:04 +0530 Subject: [PATCH 13/24] error corrected --- sql.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/sql.php b/sql.php index e591a302a8..23d04c9926 100644 --- a/sql.php +++ b/sql.php @@ -290,7 +290,7 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { $analyzed_sql_result, false ); if (empty($sql_data) || ($sql_data['valid_queries'] = 1)) { - $response->addHTML($html_output); + $response->addHTML($table_maintenance_html); exit(); } } @@ -330,8 +330,7 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { $editable, $unlim_num_rows, $num_rows, $showtable, $result, $querytime, $analyzed_sql_results, $is_procedure ); - - + $indexes_problems_html = PMA_getHtmlForIndexesProblems( isset($query_type) ? $query_type : null, isset($selected) ? $selected : null @@ -354,7 +353,6 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { $print_button_html ); - $response->addHTML($html_output); - + $response->addHTML($html_output); } // end rows returned ?> From e96b7d6b2734ad11464abd71c16df808c3e92dd4 Mon Sep 17 00:00:00 2001 From: Spun Nakandala Date: Tue, 9 Jul 2013 23:05:24 +0530 Subject: [PATCH 14/24] error corrected --- sql.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sql.php b/sql.php index 23d04c9926..9363c16669 100644 --- a/sql.php +++ b/sql.php @@ -273,7 +273,7 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { $disp_mode = 'nnnn110111'; } - + if (isset($_REQUEST['table_maintenance'])) { $scripts->addFile('makegrid.js'); $scripts->addFile('sql.js'); @@ -287,7 +287,7 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { isset($sql_data) ? $sql_data : null, $displayResultsObject, $db, $goto, $pmaThemeImage, $text_dir, $url_query, $disp_mode, $sql_limit_to_append, false, $unlim_num_rows, $num_rows, $showtable, $result, $querytime, - $analyzed_sql_result, false + $analyzed_sql_results, false ); if (empty($sql_data) || ($sql_data['valid_queries'] = 1)) { $response->addHTML($table_maintenance_html); @@ -343,7 +343,7 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { $print_button_html = PMA_getHtmlForPrintButton(); - $html_output = $table_maintenance_html; + $html_output = isset($table_maintenance_html) ? $table_maintenance_html : ''; $html_output .= isset($print_view_header_html) ? $print_view_header_html : ''; From 18517902db32e15da26ed3fa1499e2d260770a53 Mon Sep 17 00:00:00 2001 From: Spun Nakandala Date: Tue, 9 Jul 2013 23:31:19 +0530 Subject: [PATCH 15/24] phpcs warnings and errors corrected --- libraries/sql.lib.php | 105 ++++++++++++++++++++++++------------------ 1 file changed, 59 insertions(+), 46 deletions(-) diff --git a/libraries/sql.lib.php b/libraries/sql.lib.php index 7df6584d90..ce50fd79d1 100644 --- a/libraries/sql.lib.php +++ b/libraries/sql.lib.php @@ -414,12 +414,14 @@ function PMA_getHtmlForPrintViewHeader($db, $sql_query, $num_rows) $print_view_header = ''; $print_view_header .= "

" . __('SQL result') . "

"; $print_view_header .= "

"; - $print_view_header .= "" . __('Host:') . " $hostname
"; + $print_view_header .= "" . __('Host:') + . " $hostname
"; $print_view_header .= "" . __('Database:') . " " . htmlspecialchars($db) . "
"; $print_view_header .= "" . __('Generation Time:') . " " . PMA_Util::localisedDate() . "
"; - $print_view_header .= "" . __('Generated by:') . " $versions
"; + $print_view_header .= "" . __('Generated by:') + . " $versions
"; $print_view_header .= "" . __('SQL query:') . " " . htmlspecialchars($sql_query) . ";"; if (isset($num_rows)) { @@ -427,7 +429,7 @@ function PMA_getHtmlForPrintViewHeader($db, $sql_query, $num_rows) $print_view_header .= "" . __('Rows:') . " $num_rows"; } $print_view_header .= "

"; - }else{ + } else { $print_view_header = null; } @@ -456,7 +458,8 @@ function PMA_getHtmlForProfilingChart($url_query, $db, $profiling_results) ); $profiling_table = ''; - $profiling_table .= '
' . __('Profiling') . '' . "\n"; + $profiling_table .= '
' . __('Profiling') + . '' . "\n"; $profiling_table .= '
'; $profiling_table .= '

' . __('Detailed profile') . '

'; $profiling_table .= '' . "\n"; @@ -476,9 +479,10 @@ function PMA_getHtmlForProfilingChart($url_query, $db, $profiling_results) $i = 1; foreach ($profiling_results as $one_result) { if (isset($profiling_stats['states'][ucwords($one_result['Status'])])) { - $profiling_stats['states'][ucwords($one_result['Status'])]['time'] + $states = $profiling_stats['states']; + $states[ucwords($one_result['Status'])]['time'] += $one_result['Duration']; - $profiling_stats['states'][ucwords($one_result['Status'])]['calls']++; + $states[ucwords($one_result['Status'])]['calls']++; } else { $profiling_stats['states'][ucwords($one_result['Status'])] = array( 'total_time' => $one_result['Duration'], @@ -489,7 +493,8 @@ function PMA_getHtmlForProfilingChart($url_query, $db, $profiling_results) $profiling_table .= ' ' . "\n"; $profiling_table .= '' . "\n"; - $profiling_table .= '' . "\n"; + $profiling_table .= '' . "\n"; $profiling_table .= '' . "\n"; $profiling_table .= '' . "\n"; - $profiling_table .= '' . "\n"; + $profiling_table .= '' + . "\n"; $profiling_table .= '' . "\n"; @@ -673,7 +682,7 @@ function PMA_getHtmlForOptionsList($values, $selected_values) * return null * * @param string $disp_mode display mode - * @param bool $cfgBookmark + * @param bool $cfgBookmark confguration setting for bookmarking * @param string $sql_query sql query * @param string $db current database * @param string $table current table @@ -695,10 +704,11 @@ function PMA_getHtmlForBookmark($disp_mode, $cfgBookmark, $sql_query, $db, $tabl . '&sql_query=' . urlencode($sql_query) . '&id_bookmark=1'; $bkm_sql_query = urlencode( - isset($complete_query) ? $complete_query : $sql_query + isset($complete_query) ? $complete_query : $sql_query ); $html = ''; $html .= PMA_generate_common_hidden_inputs(); $html .= ''; @@ -706,7 +716,8 @@ function PMA_getHtmlForBookmark($disp_mode, $cfgBookmark, $sql_query, $db, $tabl . ' value="' . htmlspecialchars($db) . '" />'; $html .= ''; - $html .= ''; $html .= '
'; @@ -1154,7 +1165,8 @@ function PMA_getDefaultSqlQueryForBrowse($db, $table) * * @return void */ -function PMA_handleQueryExecuteError($is_gotofile, $error) { +function PMA_handleQueryExecuteError($is_gotofile, $error) +{ if ($is_gotofile) { $message = PMA_Message::rawError($error); $response = PMA_Response::getInstance(); @@ -1281,8 +1293,8 @@ function PMA_hasCurrentDbChanged($db) * @param String $db current database * @param String $table current table * @param String $dropped_column dropped column if any - * @param bool $purge - * @param array $extra_data + * @param bool $purge whether purge set or not + * @param array $extra_data extra data * * @return array $extra_data */ @@ -1304,7 +1316,7 @@ function PMA_cleanupRelations($db, $table, $dropped_column, $purge, $extra_data) && strlen($table) ) { PMA_relationsCleanupColumn($db, $table, $dropped_column); - if(isset($extra_data)) { + if (isset($extra_data)) { // to refresh the list of indexes (Ajax mode) $extra_data['indexes_list'] = PMA_Index::getView($table, $db); } @@ -1331,8 +1343,7 @@ function PMA_cleanupRelations($db, $table, $dropped_column, $purge, $extra_data) function PMA_countQueryResults($num_rows, $is_select, $justBrowsing, $db, $table, $parsed_sql, $analyzed_sql_results ) { - if (!PMA_isAppendLimitClause($analyzed_sql_results)) - { + if (!PMA_isAppendLimitClause($analyzed_sql_results)) { // if we did not append a limit, set this to get a correct // "Showing rows..." message // $_SESSION['tmp_user_values']['max_rows'] = 'all'; @@ -1423,14 +1434,15 @@ function PMA_countQueryResults($num_rows, $is_select, $justBrowsing, /** * Function to handle all aspects relating to executing the query * - * @param array $analyzed_sql_results - * @param String $full_sql_query full sql query - * @param boolean $is_gotofile whether to go to a file - * @param String $db current database - * @param String $table current table - * @param boolean $find_real_end whether to find the real end - * @param String $import_text sql command - * @param String $bkm_user bookmarking user + * @param array $analyzed_sql_results analyzed sql results + * @param String $full_sql_query full sql query + * @param boolean $is_gotofile whether to go to a file + * @param String $db current database + * @param String $table current table + * @param boolean $find_real_end whether to find the real end + * @param String $import_text sql command + * @param String $bkm_user bookmarking user + * @param array $extra_data extra data * * @return mixed */ @@ -1458,8 +1470,8 @@ function PMA_executeTheQuery($analyzed_sql_results, $full_sql_query, $is_gotofil // If there are no errors and bookmarklabel was given, // store the query as a bookmark if (! empty($_POST['bkm_label']) && ! empty($import_text)) { - PMA_storeTheQueryAsBookmark($db, $bkm_user, - $import_text, $_POST['bkm_label'], + PMA_storeTheQueryAsBookmark( + $db, $bkm_user, $import_text, $_POST['bkm_label'], isset($_POST['bkm_replace']) ? $_POST['bkm_replace'] : null ); } // end store bookmarks @@ -1478,11 +1490,11 @@ function PMA_executeTheQuery($analyzed_sql_results, $full_sql_query, $is_gotofil } $justBrowsing = PMA_isJustBrowsing( - $analyzed_sql_results,isset($find_real_end) ? $find_real_end : null + $analyzed_sql_results, isset($find_real_end) ? $find_real_end : null ); - $unlim_num_rows = PMA_countQueryResults($num_rows, - $analyzed_sql_results['is_select'], $justBrowsing, $db, + $unlim_num_rows = PMA_countQueryResults( + $num_rows, $analyzed_sql_results['is_select'], $justBrowsing, $db, $table, $analyzed_sql_results['parsed_sql'], $analyzed_sql_results ); @@ -1537,7 +1549,7 @@ function PMA_deleteTransformationInfo($db, $table, $analyzed_sql) * @return string $message */ function PMA_getMessageForNoRowsReturned($message_to_show, $analyzed_sql_results, -$num_rows + $num_rows ) { if ($analyzed_sql_results['is_delete']) { $message = PMA_Message::getMessageForDeletedRows($num_rows); @@ -1607,7 +1619,7 @@ $num_rows * @return void */ function PMA_sendAjaxResponseForNoResultsReturned($message, $analyzed_sql, -$displayResultsObject, $showSql, $extra_data + $displayResultsObject, $showSql, $extra_data ) { /** * @todo find a better way to make getMessage() in Header.class.php @@ -1679,8 +1691,8 @@ function PMA_sendResponseForNoResultsReturned($analyzed_sql_results, $db, $table $num_rows ); if ($GLOBALS['is_ajax_request'] == true) { - PMA_sendAjaxResponseForNoResultsReturned($message, - $analyzed_sql_results['analyzed_sql'], + PMA_sendAjaxResponseForNoResultsReturned( + $message, $analyzed_sql_results['analyzed_sql'], $displayResultsObject, $cfg['ShowSQL'], isset($extra_data) ? $extra_data : null ); @@ -1766,17 +1778,18 @@ function PMA_getBookmarkCreatedMessage() * @param string $db current database * @param string $goto goto page url * @param string $pmaThemeImage theme image uri - * @param string $text_dir + * @param string $text_dir text directory * @param string $url_query url query * @param string $disp_mode display mode * @param string $sql_limit_to_append sql limit to append * @param bool $editable whether the result table is editable or not * @param int $unlim_num_rows unlimited number of rows - * @param bool $showtable + * @param int $num_rows number of rows + * @param bool $showtable whether to show table or not * @param object $result result of the executed query * @param int $querytime query execution time * @param array $analyzed_sql_results analyzed sql results - * @param bool $is_procedure + * @param bool $is_procedure whether it is a procedure call or not * * @return type */ @@ -1805,7 +1818,7 @@ function PMA_getHtmlForSqlQueryResultsTable($sql_data, $displayResultsObject, $d $analyzed_sql_results['is_analyse'], $num_rows, $fields_cnt, $querytime, $pmaThemeImage, $text_dir, $analyzed_sql_results['is_maint'], $analyzed_sql_results['is_explain'], - $analyzed_sql_results['is_show'], $showtable,$printview, $url_query, + $analyzed_sql_results['is_show'], $showtable, $printview, $url_query, $editable ); @@ -1822,10 +1835,10 @@ function PMA_getHtmlForSqlQueryResultsTable($sql_data, $displayResultsObject, $d * Function to get html for the previous query if there is such. If not will return * null * - * @param type $disp_query - * @param type $showSql - * @param type $sql_data - * @param type $disp_message + * @param string $disp_query display query + * @param bool $showSql whether to show sql + * @param array $sql_data sql data + * @param string $disp_message display message * * @return string $previous_update_query_html */ @@ -1876,7 +1889,7 @@ function PMA_getMessageIfMissingColumnIndex($table, $db, $editable, $disp_mode) * Function to get html to display problems in indexes * * @param string $query_type query type - * @param boolean $selected + * @param boolean $selected selected * * @return void */ From 5a261ac112147c9c5d47c94672d448f13fa3d72e Mon Sep 17 00:00:00 2001 From: Spun Nakandala Date: Wed, 10 Jul 2013 13:20:50 +0530 Subject: [PATCH 16/24] Missing PMA_ added --- libraries/sql.lib.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/sql.lib.php b/libraries/sql.lib.php index ce50fd79d1..3e862adfdf 100644 --- a/libraries/sql.lib.php +++ b/libraries/sql.lib.php @@ -78,7 +78,7 @@ function PMA_getTableNameBySQL($sql, $tables) * * @return string $table_html html content */ -function getTableHtmlForMultipleQueries( +function PMA_getTableHtmlForMultipleQueries( $displayResultsObject, $db, $sql_data, $goto, $pmaThemeImage, $text_dir, $printview, $url_query, $disp_mode, $sql_limit_to_append, $editable @@ -1801,7 +1801,7 @@ function PMA_getHtmlForSqlQueryResultsTable($sql_data, $displayResultsObject, $d $printview = isset($_REQUEST['printview']) ? $_REQUEST['printview'] : null; if (! empty($sql_data) && ($sql_data['valid_queries'] > 1) || $is_procedure) { $_SESSION['is_multi_query'] = true; - $table_html = getTableHtmlForMultipleQueries( + $table_html = PMA_getTableHtmlForMultipleQueries( $displayResultsObject, $db, $sql_data, $goto, $pmaThemeImage, $text_dir, $printview, $url_query, $disp_mode, $sql_limit_to_append, $editable From ec35836b41e4d3a2e596ac84286447fa37cc8c9c Mon Sep 17 00:00:00 2001 From: Spun Nakandala Date: Sun, 14 Jul 2013 12:53:13 +0530 Subject: [PATCH 17/24] print view bookmark form display error corrected --- sql.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sql.php b/sql.php index 9363c16669..7f74fadc9c 100644 --- a/sql.php +++ b/sql.php @@ -272,7 +272,9 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { if (!empty($table) && ($GLOBALS['dbi']->isSystemSchema($db) || !$editable)) { $disp_mode = 'nnnn110111'; } - + if ( isset($_REQUEST['printview']) && $_REQUEST['printview'] == '1') { + $disp_mode = 'nnnn000000'; + } if (isset($_REQUEST['table_maintenance'])) { $scripts->addFile('makegrid.js'); From 6e20974920b40a39d2cc5f74d43ad6e1bdfeba0e Mon Sep 17 00:00:00 2001 From: Spun Nakandala Date: Sun, 14 Jul 2013 13:55:30 +0530 Subject: [PATCH 18/24] extracted methods PMA_analyzeAndGetTableHtmlForProfilingResults, PMA_getTableHtmlForProfilingSummaryByState from PMA_getHtmlForProfilingChart --- libraries/sql.lib.php | 157 +++++++++++++++++++++++++----------------- 1 file changed, 93 insertions(+), 64 deletions(-) diff --git a/libraries/sql.lib.php b/libraries/sql.lib.php index 3e862adfdf..3fc25ade9d 100644 --- a/libraries/sql.lib.php +++ b/libraries/sql.lib.php @@ -452,12 +452,7 @@ function PMA_getHtmlForProfilingChart($url_query, $db, $profiling_results) $pma_token = $_SESSION[' PMA_token ']; $url_query = (isset($url_query) ? $url_query : PMA_generate_common_url($db)); - $profiling_stats = array( - 'total_time' => 0, - 'states' => array(), - ); $profiling_table = ''; - $profiling_table .= '
' . __('Profiling') . '' . "\n"; $profiling_table .= '
'; @@ -474,40 +469,9 @@ function PMA_getHtmlForProfilingChart($url_query, $db, $profiling_results) $profiling_table .= '
' . "\n"; $profiling_table .= ' ' . "\n"; - - $chart_json = Array(); - $i = 1; - foreach ($profiling_results as $one_result) { - if (isset($profiling_stats['states'][ucwords($one_result['Status'])])) { - $states = $profiling_stats['states']; - $states[ucwords($one_result['Status'])]['time'] - += $one_result['Duration']; - $states[ucwords($one_result['Status'])]['calls']++; - } else { - $profiling_stats['states'][ucwords($one_result['Status'])] = array( - 'total_time' => $one_result['Duration'], - 'calls' => 1, - ); - } - $profiling_stats['total_time'] += $one_result['Duration']; - - $profiling_table .= ' ' . "\n"; - $profiling_table .= '' . "\n"; - $profiling_table .= '' . "\n"; - $profiling_table .= '' . "\n"; - if (isset($chart_json[ucwords($one_result['Status'])])) { - $chart_json[ucwords($one_result['Status'])] - += $one_result['Duration']; - } else { - $chart_json[ucwords($one_result['Status'])] - = $one_result['Duration']; - } - } - + list($detailed_table, $chart_json, $profiling_stats) + = PMA_analyzeAndGetTableHtmlForProfilingResults($profiling_results); + $profiling_table .= $detailed_table; $profiling_table .= '
' . $i++ . '' . ucwords($one_result['Status']) . '' . ucwords($one_result['Status']) + . '' . (PMA_Util::formatNumber($one_result['Duration'], 3, 1)) . 's' . PMA_Util::formatNumber( - 100 * ($stats['total_time'] / $profiling_stats['total_time']), 0, 2 + 100 * ($stats['total_time'] / $profiling_stats['total_time']), + 0, 2 ) . '%' . $stats['calls'] . '' . $stats['calls'] . '' - . PMA_Util::formatNumber($stats['total_time'] / $stats['calls'], 3, 1) + . PMA_Util::formatNumber( + $stats['total_time'] / $stats['calls'], 3, 1 + ) . 's
' . __('Time') . '
' . $i++ . '' . ucwords($one_result['Status']) - . '' - . (PMA_Util::formatNumber($one_result['Duration'], 3, 1)) - . 's
' . "\n"; $profiling_table .= '
'; @@ -529,31 +493,9 @@ function PMA_getHtmlForProfilingChart($url_query, $db, $profiling_results) $profiling_table .= ' ' . __('ø Time') . '
' . "\n"; $profiling_table .= ' ' . "\n"; - foreach ($profiling_stats['states'] as $name => $stats) { - $profiling_table .= ' ' . "\n"; - $profiling_table .= '' . $name . '' . "\n"; - $profiling_table .= '' - . PMA_Util::formatNumber($stats['total_time'], 3, 1) - . 's' . "\n"; - $profiling_table .= '' - . PMA_Util::formatNumber( - 100 * ($stats['total_time'] / $profiling_stats['total_time']), - 0, 2 - ) - . '%' . "\n"; - $profiling_table .= '' . $stats['calls'] . '' - . "\n"; - $profiling_table .= '' - . PMA_Util::formatNumber( - $stats['total_time'] / $stats['calls'], 3, 1 - ) - . 's' . "\n"; - $profiling_table .= ' ' . "\n"; - } - + $profiling_table .= PMA_getTableHtmlForProfilingSummaryByState( + $profiling_stats + ); $profiling_table .= '' . "\n"; $profiling_table .= << 0, + 'states' => array(), + ); + $chart_json = Array(); + $i = 1; + $table = ''; + foreach ($profiling_results as $one_result) { + if (isset($profiling_stats['states'][ucwords($one_result['Status'])])) { + $states = $profiling_stats['states']; + $states[ucwords($one_result['Status'])]['time'] + += $one_result['Duration']; + $states[ucwords($one_result['Status'])]['calls']++; + } else { + $profiling_stats['states'][ucwords($one_result['Status'])] = array( + 'total_time' => $one_result['Duration'], + 'calls' => 1, + ); + } + $profiling_stats['total_time'] += $one_result['Duration']; + + $table .= ' ' . "\n"; + $table .= '' . $i++ . '' . "\n"; + $table .= '' . ucwords($one_result['Status']) + . '' . "\n"; + $table .= '' + . (PMA_Util::formatNumber($one_result['Duration'], 3, 1)) + . 's' . "\n"; + if (isset($chart_json[ucwords($one_result['Status'])])) { + $chart_json[ucwords($one_result['Status'])] + += $one_result['Duration']; + } else { + $chart_json[ucwords($one_result['Status'])] + = $one_result['Duration']; + } + } + return array($table, $chart_json, $profiling_stats); +} + +/** + * Function to get HTML for summary by state table + * + * @param array $profiling_stats profiling stats + * + * @return string $table html for the table + */ +function PMA_getTableHtmlForProfilingSummaryByState($profiling_stats) +{ + $table = ''; + foreach ($profiling_stats['states'] as $name => $stats) { + $table .= ' ' . "\n"; + $table .= '' . $name . '' . "\n"; + $table .= '' + . PMA_Util::formatNumber($stats['total_time'], 3, 1) + . 's' . "\n"; + $table .= '' + . PMA_Util::formatNumber( + 100 * ($stats['total_time'] / $profiling_stats['total_time']), + 0, 2 + ) + . '%' . "\n"; + $table .= '' . $stats['calls'] . '' + . "\n"; + $table .= '' + . PMA_Util::formatNumber( + $stats['total_time'] / $stats['calls'], 3, 1 + ) + . 's' . "\n"; + $table .= ' ' . "\n"; + } + return $table; +} + /** * Get the HTML for the enum column dropdown * During grid edit, if we have a enum field, returns the html for the From 3bbcd64df4dd784b4b47ce9b5c4c6e183ec947df Mon Sep 17 00:00:00 2001 From: Spun Nakandala Date: Sun, 14 Jul 2013 14:36:11 +0530 Subject: [PATCH 19/24] default $sql_limit_to_append transfered to the else condition. --- sql.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sql.php b/sql.php index 7f74fadc9c..8056842d7f 100644 --- a/sql.php +++ b/sql.php @@ -186,7 +186,6 @@ if (PMA_isRememberSortingOrder($analyzed_sql_results)) { PMA_handleSortOrder($db, $table, $analyzed_sql, $full_sql_query); } -$sql_limit_to_append = ''; // Do append a "LIMIT" clause? if (PMA_isAppendLimitClause($analyzed_sql_results)) { list($sql_limit_to_append, @@ -194,6 +193,8 @@ if (PMA_isAppendLimitClause($analyzed_sql_results)) { ) = PMA_appendLimitClause( $full_sql_query, $analyzed_sql, isset($display_query) ); +}else{ + $sql_limit_to_append = ''; } // Since multiple query execution is anyway handled, From c7feab8dc505f2d2f80ddd8c345e91175b1e4e21 Mon Sep 17 00:00:00 2001 From: Spun Nakandala Date: Sun, 14 Jul 2013 17:18:55 +0530 Subject: [PATCH 20/24] bookmarking error corrected --- sql.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sql.php b/sql.php index 8056842d7f..4b1987dcb0 100644 --- a/sql.php +++ b/sql.php @@ -341,7 +341,8 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { $bookmark_support_html = PMA_getHtmlForBookmark($disp_mode, isset($cfg['Bookmark']) ? $cfg['Bookmark'] : '', $sql_query, - $sql_limit_to_append, $err_url, $goto, $cfg['Bookmark']['user'] + $db, $table, isset($complete_query) ? $complete_query : $sql_query, + $cfg['Bookmark']['user'] ); $print_button_html = PMA_getHtmlForPrintButton(); From 116687e8730419bd8cf1a68c209aa614461b19f9 Mon Sep 17 00:00:00 2001 From: Spun Nakandala Date: Sun, 14 Jul 2013 17:29:42 +0530 Subject: [PATCH 21/24] phpcs coding standard violations corrected --- sql.php | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/sql.php b/sql.php index 4b1987dcb0..2ced2841e2 100644 --- a/sql.php +++ b/sql.php @@ -130,8 +130,8 @@ require_once 'libraries/parse_analyze.inc.php'; * into account this case. */ if (PMA_hasNoRightsToDropDatabase( - $analyzed_sql_results, $cfg['AllowUserDropDatabase'], $is_superuser) -) { + $analyzed_sql_results, $cfg['AllowUserDropDatabase'], $is_superuser +)) { PMA_Util::mysqlDie( __('"DROP DATABASE" statements are disabled.'), '', @@ -193,7 +193,7 @@ if (PMA_isAppendLimitClause($analyzed_sql_results)) { ) = PMA_appendLimitClause( $full_sql_query, $analyzed_sql, isset($display_query) ); -}else{ +} else { $sql_limit_to_append = ''; } @@ -223,7 +223,8 @@ list($result, $num_rows, $unlim_num_rows, $profiling_results, // No rows returned -> move back to the calling page if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { - PMA_sendResponseForNoResultsReturned($analyzed_sql_results, $db, $table, + PMA_sendResponseForNoResultsReturned( + $analyzed_sql_results, $db, $table, isset($message_to_show) ? $message_to_show : null, $num_rows, $displayResultsObject, $extra_data, $cfg ); @@ -293,8 +294,8 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { $analyzed_sql_results, false ); if (empty($sql_data) || ($sql_data['valid_queries'] = 1)) { - $response->addHTML($table_maintenance_html); - exit(); + $response->addHTML($table_maintenance_html); + exit(); } } @@ -307,8 +308,8 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { $GLOBALS['buffer_message'] = false; } - $print_view_header_html = PMA_getHtmlForPrintViewHeader($db, $full_sql_query, - $num_rows + $print_view_header_html = PMA_getHtmlForPrintViewHeader( + $db, $full_sql_query, $num_rows ); $previous_update_query_html = PMA_getHtmlForPreviousUpdateQuery( @@ -317,12 +318,12 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { isset($disp_message) ? $disp_message : null ); - $profiling_chart_html = PMA_getHtmlForProfilingChart($disp_mode, $db, - isset($profiling_results) ? $profiling_results : null + $profiling_chart_html = PMA_getHtmlForProfilingChart( + $disp_mode, $db, isset($profiling_results) ? $profiling_results : null ); - $missing_unique_column_msg = PMA_getMessageIfMissingColumnIndex($table, $db, - $editable, $disp_mode + $missing_unique_column_msg = PMA_getMessageIfMissingColumnIndex( + $table, $db, $editable, $disp_mode ); $bookmark_created_msg = PMA_getBookmarkCreatedMessage(); @@ -339,8 +340,8 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { isset($selected) ? $selected : null ); - $bookmark_support_html = PMA_getHtmlForBookmark($disp_mode, - isset($cfg['Bookmark']) ? $cfg['Bookmark'] : '', $sql_query, + $bookmark_support_html = PMA_getHtmlForBookmark( + $disp_mode, isset($cfg['Bookmark']) ? $cfg['Bookmark'] : '', $sql_query, $db, $table, isset($complete_query) ? $complete_query : $sql_query, $cfg['Bookmark']['user'] ); @@ -351,8 +352,9 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { $html_output .= isset($print_view_header_html) ? $print_view_header_html : ''; - $html_output .= PMA_getHtmlForSqlQueryResults($previous_update_query_html, - $profiling_chart_html, $missing_unique_column_msg, $bookmark_created_msg, + $html_output .= PMA_getHtmlForSqlQueryResults( + $previous_update_query_html, $profiling_chart_html, + $missing_unique_column_msg, $bookmark_created_msg, $table_html, $indexes_problems_html, $bookmark_support_html, $print_button_html ); From 6c9da035ffd126b4bff9bb7768c96f2a26b533bf Mon Sep 17 00:00:00 2001 From: Spun Nakandala Date: Sun, 14 Jul 2013 21:19:28 +0530 Subject: [PATCH 22/24] check for CALL transferred to the sql parser --- libraries/parse_analyze.inc.php | 15 ++++++++++++++- libraries/sqlparser.lib.php | 6 ++++++ sql.php | 11 ----------- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/libraries/parse_analyze.inc.php b/libraries/parse_analyze.inc.php index c8dab441a3..57cd7f7c02 100644 --- a/libraries/parse_analyze.inc.php +++ b/libraries/parse_analyze.inc.php @@ -74,6 +74,18 @@ $is_count = isset($analyzed_sql[0]['queryflags']['is_count']); // check for a real SELECT ... FROM $is_select = isset($analyzed_sql[0]['queryflags']['select_from']); +// check for CALL +// Since multiple query execution is anyway handled, +// ignore the WHERE clause of the first sql statement +// which might contain a phrase like 'call ' +if (isset($analyzed_sql[0]['queryflags']['is_procedure']) + && empty($analyzed_sql[0]['where_clause']) +) { + $is_procedure = true; +} else { + $is_procedure = false; +} + // aggregates all the results into one array $analyzed_sql_results = array( "parsed_sql" => $parsed_sql, @@ -92,7 +104,8 @@ $analyzed_sql_results = array( "is_group" => $is_group, "is_func" => $is_func, "is_count" => $is_count, - "is_select" => $is_select + "is_select" => $is_select, + "is_procedure" => $is_procedure ); diff --git a/libraries/sqlparser.lib.php b/libraries/sqlparser.lib.php index 46c34eddbe..d00a95bdb8 100644 --- a/libraries/sqlparser.lib.php +++ b/libraries/sqlparser.lib.php @@ -993,6 +993,7 @@ function PMA_SQP_analyze($arr) * ['queryflags']['is_func'] = 1; for the presence of SUM|AVG|STD|STDDEV * |MIN|MAX|BIT_OR|BIT_AND * ['queryflags']['is_count'] = 1; for the presence of SELECT COUNT + * ['queryflags']['is_procedure'] = 1; for the presence of CALL * * query clauses * ------------- @@ -1721,6 +1722,11 @@ function PMA_SQP_analyze($arr) if ($upper_data == 'OFFSET') { $subresult['queryflags']['offset'] = 1; } + + // for the presence of CALL + if ($upper_data == 'CALL') { + $subresult['queryflags']['is_procedure'] = 1; + } // if this is a real SELECT...FROM if ($upper_data == 'FROM' diff --git a/sql.php b/sql.php index 53ce7ff605..606989d9e0 100644 --- a/sql.php +++ b/sql.php @@ -196,17 +196,6 @@ if (PMA_isAppendLimitClause($analyzed_sql_results)) { ); } -// Since multiple query execution is anyway handled, -// ignore the WHERE clause of the first sql statement -// which might contain a phrase like 'call ' -if (preg_match("/\bcall\b/i", $full_sql_query) - && empty($analyzed_sql[0]['where_clause']) -) { - $is_procedure = true; -} else { - $is_procedure = false; -} - $reload = PMA_hasCurrentDbChanged($db); // Execute the query From c6ee63bd4ee5f3ea07b9aa8714800af19c4bbfa7 Mon Sep 17 00:00:00 2001 From: Marc Delisle Date: Sun, 14 Jul 2013 15:44:51 -0400 Subject: [PATCH 23/24] Fix typo --- libraries/sql.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/sql.lib.php b/libraries/sql.lib.php index 2f61bb3cd8..e32fb9c4e5 100644 --- a/libraries/sql.lib.php +++ b/libraries/sql.lib.php @@ -438,7 +438,7 @@ function PMA_getHtmlForPrintViewHeader($db, $sql_query, $num_rows) /** * Get the HTML for the profiling table and accompanying chart if profiling is set. - * Ptherwise returns null + * Otherwise returns null * * @param string $url_query url query * @param string $db current database From 22884539af3bdab9fdc37a7a5c27bd7e65684a35 Mon Sep 17 00:00:00 2001 From: Marc Delisle Date: Sun, 14 Jul 2013 15:55:44 -0400 Subject: [PATCH 24/24] No need for this to be a global variable --- libraries/common.inc.php | 12 ------------ sql.php | 2 +- 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/libraries/common.inc.php b/libraries/common.inc.php index 7855417285..522790e774 100644 --- a/libraries/common.inc.php +++ b/libraries/common.inc.php @@ -1103,18 +1103,6 @@ if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) { $GLOBALS['is_ajax_request'] = false; } -/** - * @global boolean $GLOBALS['grid_edit'] - * - * Set to true if this is a request made during an grid edit process. This - * request is made to retrieve the non-truncated/transformed values. - */ -if (isset($_REQUEST['grid_edit']) && $_REQUEST['grid_edit'] == true) { - $GLOBALS['grid_edit'] = true; -} else { - $GLOBALS['grid_edit'] = false; -} - if (isset($_REQUEST['GLOBALS']) || isset($_FILES['GLOBALS'])) { PMA_fatalError(__("GLOBALS overwrite attempt")); } diff --git a/sql.php b/sql.php index 2ced2841e2..9fc349acc3 100644 --- a/sql.php +++ b/sql.php @@ -233,7 +233,7 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { // At least one row is returned -> displays a table with results // If we are retrieving the full value of a truncated field or the original // value of a transformed field, show it here and exit - if ($GLOBALS['grid_edit'] == true) { + if ($_REQUEST['grid_edit'] == true) { PMA_sendResponseForGridEdit($result); }