Fixed an issue related to multiquery statements and routines modifications
This commit is contained in:
parent
b81935e05c
commit
4465c287c1
@ -49,6 +49,12 @@ $_SESSION['Import_message']['go_back_url'] = null;
|
|||||||
// default values
|
// default values
|
||||||
$GLOBALS['reload'] = false;
|
$GLOBALS['reload'] = false;
|
||||||
|
|
||||||
|
// Use to identify curren cycle is executing
|
||||||
|
// a multiquery statement or stored routine
|
||||||
|
if (!isset($_SESSION['is_multi_query'])) {
|
||||||
|
$_SESSION['is_multi_query'] = false;
|
||||||
|
}
|
||||||
|
|
||||||
// Are we just executing plain query or sql file?
|
// Are we just executing plain query or sql file?
|
||||||
// (eg. non import, but query box/window run)
|
// (eg. non import, but query box/window run)
|
||||||
if (! empty($sql_query)) {
|
if (! empty($sql_query)) {
|
||||||
|
|||||||
@ -485,6 +485,10 @@ class PMA_DisplayResults
|
|||||||
*/
|
*/
|
||||||
private function _isSelect($analyzed_sql)
|
private function _isSelect($analyzed_sql)
|
||||||
{
|
{
|
||||||
|
if (!isset($analyzed_sql[0]['select_expr'])) {
|
||||||
|
$analyzed_sql[0]['select_expr'] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
return ! ($this->__get('_is_count') || $this->__get('_is_export')
|
return ! ($this->__get('_is_count') || $this->__get('_is_export')
|
||||||
|| $this->__get('_is_func') || $this->__get('_is_analyse'))
|
|| $this->__get('_is_func') || $this->__get('_is_analyse'))
|
||||||
&& (count($analyzed_sql[0]['select_expr']) == 0)
|
&& (count($analyzed_sql[0]['select_expr']) == 0)
|
||||||
@ -954,8 +958,9 @@ class PMA_DisplayResults
|
|||||||
// required to generate sort links that will remember whether the
|
// required to generate sort links that will remember whether the
|
||||||
// "Show all" button has been clicked
|
// "Show all" button has been clicked
|
||||||
$sql_md5 = md5($this->__get('_sql_query'));
|
$sql_md5 = md5($this->__get('_sql_query'));
|
||||||
$session_max_rows
|
$session_max_rows = $is_limited_display
|
||||||
= $_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'];
|
? 0
|
||||||
|
: $_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'];
|
||||||
|
|
||||||
$direction = isset($_SESSION['tmp_user_values']['disp_direction'])
|
$direction = isset($_SESSION['tmp_user_values']['disp_direction'])
|
||||||
? $_SESSION['tmp_user_values']['disp_direction']
|
? $_SESSION['tmp_user_values']['disp_direction']
|
||||||
@ -1069,7 +1074,7 @@ class PMA_DisplayResults
|
|||||||
|
|
||||||
$vertical_display = $this->__get('_vertical_display');
|
$vertical_display = $this->__get('_vertical_display');
|
||||||
|
|
||||||
if ($is_display['sort_lnk'] == '1') {
|
if (($is_display['sort_lnk'] == '1') && ! $is_limited_display) {
|
||||||
|
|
||||||
list($order_link, $sorted_headrer_html)
|
list($order_link, $sorted_headrer_html)
|
||||||
= $this->_getOrderLinkAndSortedHeaderHtml(
|
= $this->_getOrderLinkAndSortedHeaderHtml(
|
||||||
@ -1426,7 +1431,7 @@ class PMA_DisplayResults
|
|||||||
&& ($direction != self::DISP_DIR_HORIZONTAL_FLIPPED)
|
&& ($direction != self::DISP_DIR_HORIZONTAL_FLIPPED)
|
||||||
) {
|
) {
|
||||||
$comments_map = array();
|
$comments_map = array();
|
||||||
if (isset($analyzed_sql[0]) && is_array($analyzed_sql[0])) {
|
if (isset($analyzed_sql[0]) && is_array($analyzed_sql[0]) && isset($analyzed_sql[0]['table_ref'])) {
|
||||||
foreach ($analyzed_sql[0]['table_ref'] as $tbl) {
|
foreach ($analyzed_sql[0]['table_ref'] as $tbl) {
|
||||||
$tb = $tbl['table_true_name'];
|
$tb = $tbl['table_true_name'];
|
||||||
$comments_map[$tb] = PMA_getComments($this->__get('_db'), $tb);
|
$comments_map[$tb] = PMA_getComments($this->__get('_db'), $tb);
|
||||||
@ -4298,6 +4303,9 @@ class PMA_DisplayResults
|
|||||||
if ($is_display['nav_bar'] == '1') {
|
if ($is_display['nav_bar'] == '1') {
|
||||||
list($pos_next, $pos_prev) = $this->_getOffsets();
|
list($pos_next, $pos_prev) = $this->_getOffsets();
|
||||||
} // end if
|
} // end if
|
||||||
|
if (!isset($analyzed_sql[0]['order_by_clause'])) {
|
||||||
|
$analyzed_sql[0]['order_by_clause'] = "";
|
||||||
|
}
|
||||||
|
|
||||||
// 1.3 Find the sort expression
|
// 1.3 Find the sort expression
|
||||||
// we need $sort_expression and $sort_expression_nodirection
|
// we need $sort_expression and $sort_expression_nodirection
|
||||||
|
|||||||
@ -319,6 +319,11 @@ class PMA_Table
|
|||||||
static public function sGetStatusInfo($db, $table, $info = null,
|
static public function sGetStatusInfo($db, $table, $info = null,
|
||||||
$force_read = false, $disable_error = false
|
$force_read = false, $disable_error = false
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
if ($_SESSION['is_multi_query']) {
|
||||||
|
$disable_error = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (! isset(PMA_Table::$cache[$db][$table]) || $force_read) {
|
if (! isset(PMA_Table::$cache[$db][$table]) || $force_read) {
|
||||||
PMA_DBI_get_tables_full($db, $table);
|
PMA_DBI_get_tables_full($db, $table);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -517,7 +517,10 @@ function PMA_getForeigners($db, $table, $column = '', $source = 'both')
|
|||||||
$foreign = PMA_DBI_fetch_result($rel_query, 'master_field', null, $GLOBALS['controllink']);
|
$foreign = PMA_DBI_fetch_result($rel_query, 'master_field', null, $GLOBALS['controllink']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($source == 'both' || $source == 'foreign') && strlen($table)) {
|
if (($source == 'both' || $source == 'foreign') && strlen($table)
|
||||||
|
&& isset($analyzed_sql[0]['foreign_keys'])
|
||||||
|
) {
|
||||||
|
|
||||||
$show_create_table_query = 'SHOW CREATE TABLE '
|
$show_create_table_query = 'SHOW CREATE TABLE '
|
||||||
. $common_functions->backquote($db) . '.' . $common_functions->backquote($table);
|
. $common_functions->backquote($db) . '.' . $common_functions->backquote($table);
|
||||||
$show_create_table = PMA_DBI_fetch_value($show_create_table_query, 0, 1);
|
$show_create_table = PMA_DBI_fetch_value($show_create_table_query, 0, 1);
|
||||||
|
|||||||
147
sql.php
147
sql.php
@ -74,6 +74,10 @@ if (isset($_SESSION['profiling'])) {
|
|||||||
$scripts->addFile('canvg/canvg.js');
|
$scripts->addFile('canvg/canvg.js');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!isset($_SESSION['is_multi_query'])) {
|
||||||
|
$_SESSION['is_multi_query'] = false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines the url to return to in case of error in a sql statement
|
* Defines the url to return to in case of error in a sql statement
|
||||||
*/
|
*/
|
||||||
@ -911,12 +915,16 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) {
|
|||||||
|
|
||||||
if (!empty($sql_data) && ($sql_data['valid_queries'] > 1)) {
|
if (!empty($sql_data) && ($sql_data['valid_queries'] > 1)) {
|
||||||
|
|
||||||
|
$_SESSION['is_multi_query'] = true;
|
||||||
|
|
||||||
echo getTableHtmlForMultipleQueries(
|
echo getTableHtmlForMultipleQueries(
|
||||||
$displayResultsObject, $db, $sql_data, $goto,
|
$displayResultsObject, $db, $sql_data, $goto,
|
||||||
$pmaThemeImage, $text_dir, $printview, $url_query, $disp_mode, $sql_limit_to_append
|
$pmaThemeImage, $text_dir, $printview, $url_query, $disp_mode, $sql_limit_to_append
|
||||||
);
|
);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
$_SESSION['is_multi_query'] = false;
|
||||||
|
|
||||||
$displayResultsObject->setProperties(
|
$displayResultsObject->setProperties(
|
||||||
$unlim_num_rows, $fields_meta, $is_count, $is_export, $is_func,
|
$unlim_num_rows, $fields_meta, $is_count, $is_export, $is_func,
|
||||||
@ -1082,6 +1090,8 @@ $(makeProfilingChart);
|
|||||||
|
|
||||||
if (!empty($sql_data) && ($sql_data['valid_queries'] > 1) || $is_procedure) {
|
if (!empty($sql_data) && ($sql_data['valid_queries'] > 1) || $is_procedure) {
|
||||||
|
|
||||||
|
$_SESSION['is_multi_query'] = true;
|
||||||
|
|
||||||
echo getTableHtmlForMultipleQueries(
|
echo getTableHtmlForMultipleQueries(
|
||||||
$displayResultsObject, $db, $sql_data, $goto,
|
$displayResultsObject, $db, $sql_data, $goto,
|
||||||
$pmaThemeImage, $text_dir, $printview, $url_query, $disp_mode, $sql_limit_to_append
|
$pmaThemeImage, $text_dir, $printview, $url_query, $disp_mode, $sql_limit_to_append
|
||||||
@ -1089,6 +1099,8 @@ $(makeProfilingChart);
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
$_SESSION['is_multi_query'] = false;
|
||||||
|
|
||||||
$displayResultsObject->setProperties(
|
$displayResultsObject->setProperties(
|
||||||
$unlim_num_rows, $fields_meta, $is_count, $is_export, $is_func,
|
$unlim_num_rows, $fields_meta, $is_count, $is_export, $is_func,
|
||||||
$is_analyse, $num_rows, $fields_cnt, $querytime, $pmaThemeImage, $text_dir,
|
$is_analyse, $num_rows, $fields_cnt, $querytime, $pmaThemeImage, $text_dir,
|
||||||
@ -1164,6 +1176,8 @@ $(makeProfilingChart);
|
|||||||
}
|
}
|
||||||
} // end rows returned
|
} // end rows returned
|
||||||
|
|
||||||
|
$_SESSION['is_multi_query'] = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Displays the footer
|
* Displays the footer
|
||||||
*/
|
*/
|
||||||
@ -1312,53 +1326,64 @@ function getTableHtmlForMultipleQueries(
|
|||||||
|
|
||||||
do {
|
do {
|
||||||
|
|
||||||
// Initialize needed params related to each query
|
$analyzed_sql = array();
|
||||||
|
$is_affected = false;
|
||||||
|
|
||||||
// Use query can change the database
|
|
||||||
if (stripos($sql_data['valid_sql'][$sql_no], "use ")) {
|
|
||||||
$db = PMA_getNewDatabase($sql_data['valid_sql'][$sql_no], $databases_array);
|
|
||||||
}
|
|
||||||
|
|
||||||
$table = PMA_getTableNameBySQL($sql_data['valid_sql'][$sql_no], $tables_array);
|
|
||||||
$result = PMA_DBI_store_result();
|
$result = PMA_DBI_store_result();
|
||||||
$fields_meta = PMA_DBI_get_fields_meta($result);
|
$fields_meta = ($result !== false) ? PMA_DBI_get_fields_meta($result) : array();
|
||||||
$fields_cnt = count($fields_meta);
|
$fields_cnt = count($fields_meta);
|
||||||
$parsed_sql = PMA_SQP_parse($sql_data['valid_sql'][$sql_no]);
|
|
||||||
|
|
||||||
$analyzed_sql = PMA_SQP_analyze($parsed_sql);
|
|
||||||
$is_select = isset($analyzed_sql[0]['queryflags']['select_from']);
|
|
||||||
$unlim_num_rows = PMA_Table::countRecords($db, $table, $force_exact = true);
|
|
||||||
$showtable = PMA_Table::sGetStatusInfo($db, $table, null, true);
|
|
||||||
$url_query = PMA_generate_common_url($db, $table);
|
|
||||||
|
|
||||||
list($is_group, $is_func, $is_count, $is_export, $is_analyse,
|
|
||||||
$is_explain, $is_delete, $is_affected, $is_insert, $is_replace,
|
|
||||||
$is_show, $is_maint)
|
|
||||||
= PMA_getDisplayPropertyParams(
|
|
||||||
$sql_data['valid_sql'][$sql_no], $is_select
|
|
||||||
);
|
|
||||||
|
|
||||||
// Handle remembered sorting order, only for single table query
|
|
||||||
if ($GLOBALS['cfg']['RememberSorting']
|
|
||||||
&& ! ($is_count || $is_export || $is_func || $is_analyse)
|
|
||||||
&& isset($analyzed_sql[0]['select_expr'])
|
|
||||||
&& (count($analyzed_sql[0]['select_expr']) == 0)
|
|
||||||
&& isset($analyzed_sql[0]['queryflags']['select_from'])
|
|
||||||
&& count($analyzed_sql[0]['table_ref']) == 1
|
|
||||||
) {
|
|
||||||
PMA_handleSortOrder($db, $table, $analyzed_sql, $sql_data['valid_sql'][$sql_no]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Do append a "LIMIT" clause?
|
// Initialize needed params related to each query in multiquery statement
|
||||||
if (($_SESSION['tmp_user_values']['max_rows'] != 'all')
|
if (isset($sql_data['valid_sql'][$sql_no])) {
|
||||||
&& ! ($is_count || $is_export || $is_func || $is_analyse)
|
|
||||||
&& isset($analyzed_sql[0]['queryflags']['select_from'])
|
// 'Use' query can change the database
|
||||||
&& ! isset($analyzed_sql[0]['queryflags']['offset'])
|
if (stripos($sql_data['valid_sql'][$sql_no], "use ")) {
|
||||||
&& empty($analyzed_sql[0]['limit_clause'])
|
$db = PMA_getNewDatabase($sql_data['valid_sql'][$sql_no], $databases_array);
|
||||||
) {
|
}
|
||||||
$sql_data['valid_sql'][$sql_no] = PMA_getSqlWithLimitClause(
|
$parsed_sql = PMA_SQP_parse($sql_data['valid_sql'][$sql_no]);
|
||||||
$sql_data['valid_sql'][$sql_no], $analyzed_sql, $sql_limit_to_append
|
$table = PMA_getTableNameBySQL($sql_data['valid_sql'][$sql_no], $tables_array);
|
||||||
);
|
|
||||||
|
$analyzed_sql = PMA_SQP_analyze($parsed_sql);
|
||||||
|
$is_select = isset($analyzed_sql[0]['queryflags']['select_from']);
|
||||||
|
$unlim_num_rows = PMA_Table::countRecords($db, $table, $force_exact = true);
|
||||||
|
$showtable = PMA_Table::sGetStatusInfo($db, $table, null, true);
|
||||||
|
$url_query = PMA_generate_common_url($db, $table);
|
||||||
|
|
||||||
|
list($is_group, $is_func, $is_count, $is_export, $is_analyse,
|
||||||
|
$is_explain, $is_delete, $is_affected, $is_insert, $is_replace,
|
||||||
|
$is_show, $is_maint)
|
||||||
|
= PMA_getDisplayPropertyParams(
|
||||||
|
$sql_data['valid_sql'][$sql_no], $is_select
|
||||||
|
);
|
||||||
|
|
||||||
|
// Handle remembered sorting order, only for single table query
|
||||||
|
if ($GLOBALS['cfg']['RememberSorting']
|
||||||
|
&& ! ($is_count || $is_export || $is_func || $is_analyse)
|
||||||
|
&& isset($analyzed_sql[0]['select_expr'])
|
||||||
|
&& (count($analyzed_sql[0]['select_expr']) == 0)
|
||||||
|
&& isset($analyzed_sql[0]['queryflags']['select_from'])
|
||||||
|
&& count($analyzed_sql[0]['table_ref']) == 1
|
||||||
|
) {
|
||||||
|
PMA_handleSortOrder($db, $table, $analyzed_sql, $sql_data['valid_sql'][$sql_no]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Do append a "LIMIT" clause?
|
||||||
|
if (($_SESSION['tmp_user_values']['max_rows'] != 'all')
|
||||||
|
&& ! ($is_count || $is_export || $is_func || $is_analyse)
|
||||||
|
&& isset($analyzed_sql[0]['queryflags']['select_from'])
|
||||||
|
&& ! isset($analyzed_sql[0]['queryflags']['offset'])
|
||||||
|
&& empty($analyzed_sql[0]['limit_clause'])
|
||||||
|
) {
|
||||||
|
$sql_data['valid_sql'][$sql_no] = PMA_getSqlWithLimitClause(
|
||||||
|
$sql_data['valid_sql'][$sql_no], $analyzed_sql, $sql_limit_to_append
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the needed properties related to executing sql query
|
||||||
|
$displayResultsObject->__set('_db', $db);
|
||||||
|
$displayResultsObject->__set('_table', $table);
|
||||||
|
$displayResultsObject->__set('_goto', $goto);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $is_affected) {
|
if (! $is_affected) {
|
||||||
@ -1367,41 +1392,37 @@ function getTableHtmlForMultipleQueries(
|
|||||||
$num_rows = @PMA_DBI_affected_rows();
|
$num_rows = @PMA_DBI_affected_rows();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isset($sql_data['valid_sql'][$sql_no])) {
|
||||||
|
|
||||||
|
$displayResultsObject->__set('_sql_query', $sql_data['valid_sql'][$sql_no]);
|
||||||
|
$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
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
if ($num_rows == 0) {
|
if ($num_rows == 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the needed properties related to executing sql query
|
|
||||||
$displayResultsObject->__set('_db', $db);
|
|
||||||
$displayResultsObject->__set('_table', $table);
|
|
||||||
$displayResultsObject->__set('_goto', $goto);
|
|
||||||
$displayResultsObject->__set('_sql_query', $sql_data['valid_sql'][$sql_no]);
|
|
||||||
|
|
||||||
$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
|
|
||||||
);
|
|
||||||
|
|
||||||
// With multiple results, operations are limied
|
// With multiple results, operations are limied
|
||||||
$disp_mode = 'nnnn000000';
|
$disp_mode = 'nnnn000000';
|
||||||
$is_limited_display = true;
|
$is_limited_display = true;
|
||||||
|
|
||||||
// Collect the tables
|
// Collect the tables
|
||||||
$table_html .= $displayResultsObject->getTable(
|
$table_html .= $displayResultsObject->getTable(
|
||||||
$result, $disp_mode, $analyzed_sql, $is_limited_display
|
$result, $disp_mode, $analyzed_sql, $is_limited_display
|
||||||
);
|
);
|
||||||
$sql_no++;
|
|
||||||
|
|
||||||
// Free the result to save the memory
|
// Free the result to save the memory
|
||||||
PMA_DBI_free_result($result);
|
PMA_DBI_free_result($result);
|
||||||
|
|
||||||
if (! PMA_DBI_more_results()) {
|
$sql_no++;
|
||||||
break;
|
|
||||||
}
|
} while (PMA_DBI_more_results() && PMA_DBI_next_result());
|
||||||
|
|
||||||
} while (PMA_DBI_next_result());
|
|
||||||
|
|
||||||
return $table_html;
|
return $table_html;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user