diff --git a/import.php b/import.php
index 193a4260f1..70e471b07b 100644
--- a/import.php
+++ b/import.php
@@ -49,6 +49,12 @@ $_SESSION['Import_message']['go_back_url'] = null;
// default values
$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?
// (eg. non import, but query box/window run)
if (! empty($sql_query)) {
diff --git a/libraries/DisplayResults.class.php b/libraries/DisplayResults.class.php
index e045f8057e..b28786e615 100644
--- a/libraries/DisplayResults.class.php
+++ b/libraries/DisplayResults.class.php
@@ -485,6 +485,10 @@ class PMA_DisplayResults
*/
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')
|| $this->__get('_is_func') || $this->__get('_is_analyse'))
&& (count($analyzed_sql[0]['select_expr']) == 0)
@@ -954,8 +958,9 @@ class PMA_DisplayResults
// required to generate sort links that will remember whether the
// "Show all" button has been clicked
$sql_md5 = md5($this->__get('_sql_query'));
- $session_max_rows
- = $_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'];
+ $session_max_rows = $is_limited_display
+ ? 0
+ : $_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'];
$direction = isset($_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');
- if ($is_display['sort_lnk'] == '1') {
+ if (($is_display['sort_lnk'] == '1') && ! $is_limited_display) {
list($order_link, $sorted_headrer_html)
= $this->_getOrderLinkAndSortedHeaderHtml(
@@ -1426,7 +1431,7 @@ class PMA_DisplayResults
&& ($direction != self::DISP_DIR_HORIZONTAL_FLIPPED)
) {
$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) {
$tb = $tbl['table_true_name'];
$comments_map[$tb] = PMA_getComments($this->__get('_db'), $tb);
@@ -4298,6 +4303,9 @@ class PMA_DisplayResults
if ($is_display['nav_bar'] == '1') {
list($pos_next, $pos_prev) = $this->_getOffsets();
} // end if
+ if (!isset($analyzed_sql[0]['order_by_clause'])) {
+ $analyzed_sql[0]['order_by_clause'] = "";
+ }
// 1.3 Find the sort expression
// we need $sort_expression and $sort_expression_nodirection
diff --git a/libraries/Table.class.php b/libraries/Table.class.php
index 891240a1bf..c646f28eca 100644
--- a/libraries/Table.class.php
+++ b/libraries/Table.class.php
@@ -319,6 +319,11 @@ class PMA_Table
static public function sGetStatusInfo($db, $table, $info = null,
$force_read = false, $disable_error = false
) {
+
+ if ($_SESSION['is_multi_query']) {
+ $disable_error = true;
+ }
+
if (! isset(PMA_Table::$cache[$db][$table]) || $force_read) {
PMA_DBI_get_tables_full($db, $table);
}
diff --git a/libraries/relation.lib.php b/libraries/relation.lib.php
index 62a09809ee..4781511f47 100644
--- a/libraries/relation.lib.php
+++ b/libraries/relation.lib.php
@@ -517,7 +517,10 @@ function PMA_getForeigners($db, $table, $column = '', $source = 'both')
$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 '
. $common_functions->backquote($db) . '.' . $common_functions->backquote($table);
$show_create_table = PMA_DBI_fetch_value($show_create_table_query, 0, 1);
diff --git a/libraries/rte/rte_routines.lib.php b/libraries/rte/rte_routines.lib.php
index 89d0bddb84..8c13151c59 100644
--- a/libraries/rte/rte_routines.lib.php
+++ b/libraries/rte/rte_routines.lib.php
@@ -1267,22 +1267,7 @@ function PMA_RTN_handleExecute()
// Generate output
if ($outcome) {
- $message = __('Your SQL query has been executed successfully');
- if ($routine['item_type'] == 'PROCEDURE') {
- $message .= '
';
-
- // TODO : message need to be modified according to the
- // output from the routine
- $message .= sprintf(
- _ngettext(
- '%d row affected by the last statement inside the procedure',
- '%d rows affected by the last statement inside the procedure',
- $affected
- ),
- $affected
- );
- }
- $message = PMA_message::success($message);
+
// Pass the SQL queries through the "pretty printer"
$output = '';
$output .= PMA_SQP_formatHtml(PMA_SQP_parse(implode($queries)));
@@ -1331,6 +1316,7 @@ function PMA_RTN_handleExecute()
$output .= "";
$num_of_rusults_set_to_display++;
+ $affected = $num_rows;
}
@@ -1346,6 +1332,23 @@ function PMA_RTN_handleExecute()
$output .= "";
+ $message = __('Your SQL query has been executed successfully');
+ if ($routine['item_type'] == 'PROCEDURE') {
+ $message .= '
';
+
+ // TODO : message need to be modified according to the
+ // output from the routine
+ $message .= sprintf(
+ _ngettext(
+ '%d row affected by the last statement inside the procedure',
+ '%d rows affected by the last statement inside the procedure',
+ $affected
+ ),
+ $affected
+ );
+ }
+ $message = PMA_message::success($message);
+
if ($num_of_rusults_set_to_display == 0) {
$notice = __('MySQL returned an empty result set (i.e. zero rows).');
$output .= PMA_message::notice($notice)->getDisplay();
diff --git a/sql.php b/sql.php
index 5adb0f936a..5c2344e681 100644
--- a/sql.php
+++ b/sql.php
@@ -74,6 +74,10 @@ if (isset($_SESSION['profiling'])) {
$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
*/
@@ -911,12 +915,16 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) {
if (!empty($sql_data) && ($sql_data['valid_queries'] > 1)) {
+ $_SESSION['is_multi_query'] = true;
+
echo getTableHtmlForMultipleQueries(
$displayResultsObject, $db, $sql_data, $goto,
$pmaThemeImage, $text_dir, $printview, $url_query, $disp_mode, $sql_limit_to_append
);
} else {
+
+ $_SESSION['is_multi_query'] = false;
$displayResultsObject->setProperties(
$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) {
+ $_SESSION['is_multi_query'] = true;
+
echo getTableHtmlForMultipleQueries(
$displayResultsObject, $db, $sql_data, $goto,
$pmaThemeImage, $text_dir, $printview, $url_query, $disp_mode, $sql_limit_to_append
@@ -1089,6 +1099,8 @@ $(makeProfilingChart);
} 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,
@@ -1164,6 +1176,8 @@ $(makeProfilingChart);
}
} // end rows returned
+$_SESSION['is_multi_query'] = false;
+
/**
* Displays the footer
*/
@@ -1312,53 +1326,64 @@ function getTableHtmlForMultipleQueries(
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();
- $fields_meta = PMA_DBI_get_fields_meta($result);
+ $fields_meta = ($result !== false) ? PMA_DBI_get_fields_meta($result) : array();
$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?
- 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
- );
+ // Initialize needed params related to each query in multiquery statement
+ if (isset($sql_data['valid_sql'][$sql_no])) {
+
+ // '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);
+ }
+ $parsed_sql = PMA_SQP_parse($sql_data['valid_sql'][$sql_no]);
+ $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) {
@@ -1367,41 +1392,37 @@ function getTableHtmlForMultipleQueries(
$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) {
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
$disp_mode = 'nnnn000000';
$is_limited_display = true;
-
+
// Collect the tables
$table_html .= $displayResultsObject->getTable(
$result, $disp_mode, $analyzed_sql, $is_limited_display
);
- $sql_no++;
-
+
// Free the result to save the memory
PMA_DBI_free_result($result);
- if (! PMA_DBI_more_results()) {
- break;
- }
+ $sql_no++;
+
+ } while (PMA_DBI_more_results() && PMA_DBI_next_result());
- } while (PMA_DBI_next_result());
-
return $table_html;
}