Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/phpmyadmin/phpmyadmin int…
Browse files Browse the repository at this point in the history
…o server_refactor2
  • Loading branch information
xmujay committed Jul 16, 2013
2 parents e274220 + 55746b5 commit 0aeead0
Show file tree
Hide file tree
Showing 41 changed files with 955 additions and 685 deletions.
5 changes: 5 additions & 0 deletions libraries/operations.lib.php
Expand Up @@ -377,6 +377,11 @@ function PMA_getSqlQueryAndCreateDbBeforeCopy()
$GLOBALS['dbi']->query($local_query);
$GLOBALS['db'] = $original_db;

// Set the SQL mode to NO_AUTO_VALUE_ON_ZERO to prevent MySQL from creating
// export statements it cannot import
$sql_set_mode = "SET SQL_MODE='NO_AUTO_VALUE_ON_ZERO'";
PMA_DBI_query($sql_set_mode);

// rebuild the database list because PMA_Table::moveCopy
// checks in this list if the target db exists
$GLOBALS['pma']->databases->build();
Expand Down
70 changes: 70 additions & 0 deletions libraries/server_status_advisor.lib.php
@@ -0,0 +1,70 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */

/**
* functions for displaying server status sub item: advisor
*
* @usedby server_status_advisor.php
*
* @package PhpMyAdmin
*/
if (! defined('PHPMYADMIN')) {
exit;
}

/**
* Returns html with Advisor
*
* @return string
*/
function PMA_getHtmlForAdvisor()
{
$output = '<a href="#openAdvisorInstructions">';
$output .= PMA_Util::getIcon('b_help.png', __('Instructions'));
$output .= '</a>';
$output .= '<div id="statustabs_advisor"></div>';
$output .= '<div id="advisorInstructionsDialog" style="display:none;">';
$output .= '<p>';
$output .= __(
'The Advisor system can provide recommendations '
. 'on server variables by analyzing the server status variables.'
);
$output .= '</p>';
$output .= '<p>';
$output .= __(
'Do note however that this system provides recommendations '
. 'based on simple calculations and by rule of thumb which may '
. 'not necessarily apply to your system.'
);
$output .= '</p>';
$output .= '<p>';
$output .= __(
'Prior to changing any of the configuration, be sure to know '
. 'what you are changing (by reading the documentation) and how '
. 'to undo the change. Wrong tuning can have a very negative '
. 'effect on performance.'
);
$output .= '</p>';
$output .= '<p>';
$output .= __(
'The best way to tune your system would be to change only one '
. 'setting at a time, observe or benchmark your database, and undo '
. 'the change if there was no clearly measurable improvement.'
);
$output .= '</p>';
$output .= '</div>';
$output .= '<div id="advisorData" style="display:none;">';
$advisor = new Advisor();
$output .= htmlspecialchars(
json_encode(
$advisor->run()
)
);
$output .= '</div>';

return $output;
}

?>


191 changes: 180 additions & 11 deletions libraries/sql.lib.php
Expand Up @@ -69,7 +69,6 @@ function PMA_getTableNameBySQL($sql, $tables)
* @param array $sql_data information about SQL statement
* @param string $goto URL to go back in case of errors
* @param string $pmaThemeImage path for theme images directory
* @param string $text_dir text direction
* @param string $printview whether printview is enabled
* @param string $url_query URL query
* @param array $disp_mode the display mode
Expand All @@ -80,7 +79,7 @@ function PMA_getTableNameBySQL($sql, $tables)
*/
function PMA_getTableHtmlForMultipleQueries(
$displayResultsObject, $db, $sql_data, $goto, $pmaThemeImage,
$text_dir, $printview, $url_query, $disp_mode, $sql_limit_to_append,
$printview, $url_query, $disp_mode, $sql_limit_to_append,
$editable
) {
$table_html = '';
Expand Down Expand Up @@ -187,8 +186,8 @@ function PMA_getTableHtmlForMultipleQueries(
$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
$GLOBALS['text_dir'], $is_maint, $is_explain, $is_show,
$showtable, $printview, $url_query, $editable
);
}

Expand Down Expand Up @@ -1808,7 +1807,6 @@ function PMA_getBookmarkCreatedMessage()
* @param string $db current database
* @param string $goto goto page url
* @param string $pmaThemeImage theme image uri
* @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
Expand All @@ -1819,21 +1817,22 @@ function PMA_getBookmarkCreatedMessage()
* @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 whether it is a procedure call or not
*
* @return type
*/
function PMA_getHtmlForSqlQueryResultsTable($sql_data, $displayResultsObject, $db,
$goto, $pmaThemeImage, $text_dir, $url_query, $disp_mode, $sql_limit_to_append,
$goto, $pmaThemeImage, $url_query, $disp_mode, $sql_limit_to_append,
$editable, $unlim_num_rows, $num_rows, $showtable, $result, $querytime,
$analyzed_sql_results, $is_procedure
$analyzed_sql_results
) {
$printview = isset($_REQUEST['printview']) ? $_REQUEST['printview'] : null;
if (! empty($sql_data) && ($sql_data['valid_queries'] > 1) || $is_procedure) {
if (! empty($sql_data) && ($sql_data['valid_queries'] > 1)
|| $analyzed_sql_results['is_procedure']
) {
$_SESSION['is_multi_query'] = true;
$table_html = PMA_getTableHtmlForMultipleQueries(
$displayResultsObject, $db, $sql_data, $goto,
$pmaThemeImage, $text_dir, $printview, $url_query,
$pmaThemeImage, $printview, $url_query,
$disp_mode, $sql_limit_to_append, $editable
);
} else {
Expand All @@ -1846,7 +1845,7 @@ function PMA_getHtmlForSqlQueryResultsTable($sql_data, $displayResultsObject, $d
$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,
$fields_cnt, $querytime, $pmaThemeImage, $GLOBALS['text_dir'],
$analyzed_sql_results['is_maint'], $analyzed_sql_results['is_explain'],
$analyzed_sql_results['is_show'], $showtable, $printview, $url_query,
$editable
Expand Down Expand Up @@ -1964,4 +1963,174 @@ function PMA_getHtmlForPrintButton()

return $print_button_html;
}

/**
* Function to display results when the executed query returns non empty results
*
* @param array $result executed query results
* @param bool $justBrowsing whether just browsing or not
* @param array $analyzed_sql_results analysed sql results
* @param string $db current database
* @param string $table current table
* @param string $disp_mode display mode
* @param string $message message to show
* @param array $sql_data sql data
* @param object $displayResultsObject Instance of DisplyResults.class
* @param string $goto goto page url
* @param string $pmaThemeImage uri of the theme image
* @param string $sql_limit_to_append sql limit to append
* @param int $unlim_num_rows unlimited number of rows
* @param int $num_rows number of rows
* @param int $querytime query time
* @param string $full_sql_query full sql query
* @param string $disp_query display query
* @param string $disp_message display message
* @param array $profiling_results profiling results
* @param string $query_type query type
* @param bool $selected selected
* @param string $sql_query sql query
* @param string $complete_query complete sql query
* @param array $cfg configuration
*
* @return void
*/
function PMA_sendResponseForResultsReturned($result, $justBrowsing,
$analyzed_sql_results, $db, $table, $disp_mode, $message, $sql_data,
$displayResultsObject, $goto, $pmaThemeImage, $sql_limit_to_append,
$unlim_num_rows, $num_rows, $querytime, $full_sql_query, $disp_query,
$disp_message, $profiling_results, $query_type, $selected, $sql_query,
$complete_query, $cfg
) {
// If we are retrieving the full value of a truncated field or the original
// value of a transformed field, show it here
if (isset($_REQUEST['grid_edit']) && $_REQUEST['grid_edit'] == true) {
PMA_sendResponseForGridEdit($result);
}

// Gets the list of fields properties
if (isset($result) && $result) {
$fields_meta = $GLOBALS['dbi']->getFieldsMeta($result);
}

// Should be initialized these parameters before parsing
$showtable = isset($showtable) ? $showtable : null;
$url_query = isset($url_query) ? $url_query : null;

$response = PMA_Response::getInstance();
$header = $response->getHeader();
$scripts = $header->getScripts();

// 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_results['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
// libraries/DisplayResults.class.php
$disp_mode = 'urdr111101';
}
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');
$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, $url_query, $disp_mode, $sql_limit_to_append,
false, $unlim_num_rows, $num_rows, $showtable, $result, $querytime,
$analyzed_sql_results, false
);
if (empty($sql_data) || ($sql_data['valid_queries'] = 1)) {
$response->addHTML($table_maintenance_html);
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
);

$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
);

$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
);

$bookmark_created_msg = PMA_getBookmarkCreatedMessage();

$table_html = PMA_getHtmlForSqlQueryResultsTable(
isset($sql_data) ? $sql_data : null, $displayResultsObject, $db, $goto,
$pmaThemeImage, $url_query, $disp_mode, $sql_limit_to_append,
$editable, $unlim_num_rows, $num_rows, $showtable, $result, $querytime,
$analyzed_sql_results
);

$indexes_problems_html = PMA_getHtmlForIndexesProblems(
isset($query_type) ? $query_type : null,
isset($selected) ? $selected : null
);

$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']
);

$print_button_html = PMA_getHtmlForPrintButton();

$html_output = isset($table_maintenance_html) ? $table_maintenance_html : '';

$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,
$print_button_html
);

$response->addHTML($html_output);

exit();
}
?>
4 changes: 2 additions & 2 deletions libraries/sqlparser.lib.php
Expand Up @@ -1667,7 +1667,7 @@ function PMA_SQP_analyze($arr)
$in_limit = false;
$after_limit = true;

// for the presnece of PROCEDURE ANALYSE
// for the presence of PROCEDURE ANALYSE
if (isset($subresult['queryflags']['select_from'])
&& $subresult['queryflags']['select_from'] == 1
&& ($i + 1) < $size
Expand All @@ -1678,7 +1678,7 @@ function PMA_SQP_analyze($arr)
}
}

// for the presnece of INTO OUTFILE
// for the presence of INTO OUTFILE
if ($upper_data == 'INTO'
&& isset($subresult['queryflags']['select_from'])
&& $subresult['queryflags']['select_from'] == 1
Expand Down

0 comments on commit 0aeead0

Please sign in to comment.