diff --git a/db_qbe.php b/db_qbe.php index e96d336e6a..0cb1b2df28 100644 --- a/db_qbe.php +++ b/db_qbe.php @@ -5,15 +5,16 @@ * * @package PhpMyAdmin */ -use PMA\libraries\SavedSearches; -use PMA\libraries\URL; + use PMA\libraries\Response; +use PMA\libraries\SavedSearches; +use PMA\libraries\Sql; +use PMA\libraries\URL; /** * requirements */ require_once 'libraries/common.inc.php'; -require_once 'libraries/sql.lib.php'; $response = Response::getInstance(); @@ -81,7 +82,7 @@ if (isset($_REQUEST['submit_sql']) && ! empty($sql_query)) { $message_to_display = true; } else { $goto = 'db_sql.php'; - PMA_executeQueryAndSendQueryResponse( + Sql::executeQueryAndSendQueryResponse( null, // analyzed_sql_results false, // is_gotofile $_REQUEST['db'], // db diff --git a/import.php b/import.php index 7b6a415483..c3ccffc57d 100644 --- a/import.php +++ b/import.php @@ -5,12 +5,14 @@ * * @package PhpMyAdmin */ -use PMA\libraries\Response; -use PMA\libraries\Encoding; -use PMA\libraries\plugins\ImportPlugin; -use PMA\libraries\File; -use PMA\libraries\URL; + use PMA\libraries\Bookmark; +use PMA\libraries\Encoding; +use PMA\libraries\File; +use PMA\libraries\plugins\ImportPlugin; +use PMA\libraries\Response; +use PMA\libraries\Sql; +use PMA\libraries\URL; /* Enable LOAD DATA LOCAL INFILE for LDI plugin */ if (isset($_POST['format']) && $_POST['format'] == 'ldi') { @@ -21,8 +23,6 @@ if (isset($_POST['format']) && $_POST['format'] == 'ldi') { * Get the variables sent or posted to this script and a core script */ require_once 'libraries/common.inc.php'; -require_once 'libraries/sql.lib.php'; -//require_once 'libraries/display_import_functions.lib.php'; if (isset($_REQUEST['show_as_php'])) { $GLOBALS['show_as_php'] = $_REQUEST['show_as_php']; @@ -695,7 +695,7 @@ if ($go_sql) { extract($analyzed_sql_results); // Check if User is allowed to issue a 'DROP DATABASE' Statement - if (PMA_hasNoRightsToDropDatabase( + if (Sql::hasNoRightsToDropDatabase( $analyzed_sql_results, $cfg['AllowUserDropDatabase'], $GLOBALS['is_superuser'] )) { PMA\libraries\Util::mysqlDie( @@ -711,7 +711,7 @@ if ($go_sql) { $table = $table_from_sql; } - $html_output .= PMA_executeQueryAndGetQueryResponse( + $html_output .= Sql::executeQueryAndGetQueryResponse( $analyzed_sql_results, // analyzed_sql_results false, // is_gotofile $db, // db @@ -733,12 +733,12 @@ if ($go_sql) { ); } - // sql_query_for_bookmark is not included in PMA_executeQueryAndGetQueryResponse + // sql_query_for_bookmark is not included in Sql::executeQueryAndGetQueryResponse // since only one bookmark has to be added for all the queries submitted through // the SQL tab if (! empty($_POST['bkm_label']) && ! empty($import_text)) { $cfgBookmark = Bookmark::getParams(); - PMA_storeTheQueryAsBookmark( + Sql::storeTheQueryAsBookmark( $db, $cfgBookmark['user'], $_REQUEST['sql_query'], $_POST['bkm_label'], isset($_POST['bkm_replace']) ? $_POST['bkm_replace'] : null @@ -753,7 +753,7 @@ if ($go_sql) { // Save a Bookmark with more than one queries (if Bookmark label given). if (! empty($_POST['bkm_label']) && ! empty($import_text)) { $cfgBookmark = Bookmark::getParams(); - PMA_storeTheQueryAsBookmark( + Sql::storeTheQueryAsBookmark( $db, $cfgBookmark['user'], $_REQUEST['sql_query'], $_POST['bkm_label'], isset($_POST['bkm_replace']) ? $_POST['bkm_replace'] : null diff --git a/libraries/DisplayResults.php b/libraries/DisplayResults.php index 25243ed960..a24dc28f68 100644 --- a/libraries/DisplayResults.php +++ b/libraries/DisplayResults.php @@ -10,6 +10,7 @@ namespace PMA\libraries; use PhpMyAdmin\SqlParser\Utils\Query; use PMA\libraries\plugins\transformations\Text_Plain_Link; use PMA\libraries\Sanitize; +use PMA\libraries\Sql; use PMA\libraries\Transformations; use PMA\libraries\URL; @@ -1428,7 +1429,7 @@ class DisplayResults . URL::getHiddenInputs( $this->__get('db'), $this->__get('table') ) - // to avoid calling PMA_handleSortOrder() later + // to avoid calling Sql::handleSortOrder() later . URL::getHiddenFields(array('sort_by_key' => '1')) . __('Sort by key') . ': ' . $dropdown . ''; + } + + return $dropdown; + } + + /** + * Get the HTML for the profiling table and accompanying chart if profiling is set. + * Otherwise returns null + * + * @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 + */ + public static function getHtmlForProfilingChart($url_query, $db, $profiling_results) + { + if (! empty($profiling_results)) { + $pma_token = $_SESSION[' PMA_token ']; + $url_query = isset($url_query) + ? $url_query + : URL::getCommon(array('db' => $db)); + + $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"; + list($detailed_table, $chart_json, $profiling_stats) + = self::analyzeAndGetTableHtmlForProfilingResults($profiling_results); + $profiling_table .= $detailed_table; + $profiling_table .= '
' . __('Order') + . '
' . __('State') + . Util::showMySQLDocu('general-thread-states') + . '
' . __('Time') + . '
' . "\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"; + $profiling_table .= self::getTableHtmlForProfilingSummaryByState( + $profiling_stats + ); + $profiling_table .= '
' . __('State') + . Util::showMySQLDocu('general-thread-states') + . '
' . __('Total Time') + . '
' . __('% Time') + . '
' . __('Calls') + . '
' . __('ΓΈ Time') + . '
' . "\n"; + + $profiling_table .= << + pma_token = '$pma_token'; + url_query = '$url_query'; + +EOT; + $profiling_table .= "
"; + $profiling_table .= "
"; + + //require_once 'libraries/chart.lib.php'; + $profiling_table .= '
'; + $profiling_table .= json_encode($chart_json); + $profiling_table .= '
'; + $profiling_table .= '
'; + $profiling_table .= '
'; + $profiling_table .= ''; + $profiling_table .= '
' . "\n"; + } else { + $profiling_table = null; + } + return $profiling_table; + } + + /** + * Function to get HTML for detailed profiling results table, profiling stats, and + * $chart_json for displaying the chart. + * + * @param array $profiling_results profiling results + * + * @return mixed + */ + public static function analyzeAndGetTableHtmlForProfilingResults( + $profiling_results + ) { + $profiling_stats = array( + 'total_time' => 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'])]['total_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 .= '' + . (Util::formatNumber($one_result['Duration'], 3, 1)) + . 's' + . $one_result['Duration'] . '' . "\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 + */ + public static function getTableHtmlForProfilingSummaryByState($profiling_stats) + { + $table = ''; + foreach ($profiling_stats['states'] as $name => $stats) { + $table .= ' ' . "\n"; + $table .= '' . $name . '' . "\n"; + $table .= '' + . Util::formatNumber($stats['total_time'], 3, 1) + . 's' + . $stats['total_time'] . '' . "\n"; + $table .= '' + . Util::formatNumber( + 100 * ($stats['total_time'] / $profiling_stats['total_time']), + 0, 2 + ) + . '%' . "\n"; + $table .= '' . $stats['calls'] . '' + . "\n"; + $table .= '' + . Util::formatNumber( + $stats['total_time'] / $stats['calls'], 3, 1 + ) + . 's' + . number_format($stats['total_time'] / $stats['calls'], 8, '.', '') + . '' . "\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 + * dropdown + * + * @param string $db current database + * @param string $table current table + * @param string $column current column + * @param string $curr_value currently selected value + * + * @return string $dropdown html for the dropdown + */ + public static function getHtmlForEnumColumnDropdown($db, $table, $column, $curr_value) + { + $values = self::getValuesForColumn($db, $table, $column); + $dropdown = ''; + $dropdown .= self::getHtmlForOptionsList($values, array($curr_value)); + $dropdown = ''; + return $dropdown; + } + + /** + * Get value of a column for a specific row (marked by $where_clause) + * + * @param string $db current database + * @param string $table current table + * @param string $column current column + * @param string $where_clause where clause to select a particular row + * + * @return string with value + */ + public static function getFullValuesForSetColumn($db, $table, $column, $where_clause) + { + $result = $GLOBALS['dbi']->fetchSingleRow( + "SELECT `$column` FROM `$db`.`$table` WHERE $where_clause" + ); + + return $result[$column]; + } + + /** + * Get the HTML for the set column dropdown + * During grid edit, if we have a set field, returns the html for the + * dropdown + * + * @param string $db current database + * @param string $table current table + * @param string $column current column + * @param string $curr_value currently selected value + * + * @return string $dropdown html for the set column + */ + public static function getHtmlForSetColumn($db, $table, $column, $curr_value) + { + $values = self::getValuesForColumn($db, $table, $column); + $dropdown = ''; + $full_values = + isset($_REQUEST['get_full_values']) ? $_REQUEST['get_full_values'] : false; + $where_clause = + isset($_REQUEST['where_clause']) ? $_REQUEST['where_clause'] : null; + + // If the $curr_value was truncated, we should + // fetch the correct full values from the table + if ($full_values && ! empty($where_clause)) { + $curr_value = self::getFullValuesForSetColumn( + $db, $table, $column, $where_clause + ); + } + + //converts characters of $curr_value to HTML entities + $converted_curr_value = htmlentities( + $curr_value, ENT_COMPAT, "UTF-8" + ); + + $selected_values = explode(',', $converted_curr_value); + + $dropdown .= self::getHtmlForOptionsList($values, $selected_values); + + $select_size = (sizeof($values) > 10) ? 10 : sizeof($values); + $dropdown = ''; + + return $dropdown; + } + + /** + * Get all the values for a enum column or set column in a table + * + * @param string $db current database + * @param string $table current table + * @param string $column current column + * + * @return array $values array containing the value list for the column + */ + public static function getValuesForColumn($db, $table, $column) + { + $field_info_query = $GLOBALS['dbi']->getColumnsSql($db, $table, $column); + + $field_info_result = $GLOBALS['dbi']->fetchResult( + $field_info_query, + null, + null, + null, + DatabaseInterface::QUERY_STORE + ); + + $values = Util::parseEnumSetValues($field_info_result[0]['Type']); + + return $values; + } + + /** + * Get HTML for options list + * + * @param array $values set of values + * @param array $selected_values currently selected values + * + * @return string $options HTML for options list + */ + public static function getHtmlForOptionsList($values, $selected_values) + { + $options = ''; + foreach ($values as $value) { + $options .= ''; - $dropdown .= PMA_getHtmlForOptionsList($values, array($curr_value)); - $dropdown = ''; - return $dropdown; -} - -/** - * Get value of a column for a specific row (marked by $where_clause) - * - * @param string $db current database - * @param string $table current table - * @param string $column current column - * @param string $where_clause where clause to select a particular row - * - * @return string with value - */ -function PMA_getFullValuesForSetColumn($db, $table, $column, $where_clause) -{ - $result = $GLOBALS['dbi']->fetchSingleRow( - "SELECT `$column` FROM `$db`.`$table` WHERE $where_clause" - ); - - return $result[$column]; -} - -/** - * Get the HTML for the set column dropdown - * During grid edit, if we have a set field, returns the html for the - * dropdown - * - * @param string $db current database - * @param string $table current table - * @param string $column current column - * @param string $curr_value currently selected value - * - * @return string $dropdown html for the set column - */ -function PMA_getHtmlForSetColumn($db, $table, $column, $curr_value) -{ - $values = PMA_getValuesForColumn($db, $table, $column); - $dropdown = ''; - $full_values = - isset($_REQUEST['get_full_values']) ? $_REQUEST['get_full_values'] : false; - $where_clause = - isset($_REQUEST['where_clause']) ? $_REQUEST['where_clause'] : null; - - // If the $curr_value was truncated, we should - // fetch the correct full values from the table - if ($full_values && ! empty($where_clause)) { - $curr_value = PMA_getFullValuesForSetColumn( - $db, $table, $column, $where_clause - ); - } - - //converts characters of $curr_value to HTML entities - $converted_curr_value = htmlentities( - $curr_value, ENT_COMPAT, "UTF-8" - ); - - $selected_values = explode(',', $converted_curr_value); - - $dropdown .= PMA_getHtmlForOptionsList($values, $selected_values); - - $select_size = (sizeof($values) > 10) ? 10 : sizeof($values); - $dropdown = ''; - - return $dropdown; -} - -/** - * Get all the values for a enum column or set column in a table - * - * @param string $db current database - * @param string $table current table - * @param string $column current column - * - * @return array $values array containing the value list for the column - */ -function PMA_getValuesForColumn($db, $table, $column) -{ - $field_info_query = $GLOBALS['dbi']->getColumnsSql($db, $table, $column); - - $field_info_result = $GLOBALS['dbi']->fetchResult( - $field_info_query, - null, - null, - null, - PMA\libraries\DatabaseInterface::QUERY_STORE - ); - - $values = PMA\libraries\Util::parseEnumSetValues($field_info_result[0]['Type']); - - return $values; -} - -/** - * Get HTML for options list - * - * @param array $values set of values - * @param array $selected_values currently selected values - * - * @return string $options HTML for options list - */ -function PMA_getHtmlForOptionsList($values, $selected_values) -{ - $options = ''; - foreach ($values as $value) { - $options .= '