From 914ad7ae1208c3886d4ae4e3f9fc2ccc8c3bb08f Mon Sep 17 00:00:00 2001 From: Garvin Hicking Date: Tue, 29 Jul 2003 09:58:59 +0000 Subject: [PATCH] multi-query statements --- ChangeLog | 12 ++++ Documentation.html | 14 +++++ config.inc.php3 | 27 +++++---- css/phpmyadmin.css.php3 | 2 +- libraries/common.lib.php3 | 2 +- libraries/config_import.lib.php3 | 8 +++ libraries/sqlparser.lib.php3 | 2 +- read_dump.php3 | 98 +++++++++++++++++++++++++++++--- 8 files changed, 143 insertions(+), 22 deletions(-) diff --git a/ChangeLog b/ChangeLog index 71583aa5c..c68ac7568 100755 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,18 @@ phpMyAdmin - Changelog $Id$ $Source$ +2003-07-29 Garvin Hicking + * Documentation.html, config.inc.php3, read_dump.php3, + css/phpmyadmin.css.php3, libraries/common.lib.php3, + libraries/config_import.lib.php3, libraries/sqlparser.lib.php3 + o Introduced $cfg['IgnoreMultiSubmitErrors'] to let PMA continue + execution of a multi-query statement even though single queries + may fail + o Introduced $cfg['VerboseMultiSubmit'] to let PMA show the result + of each query of a multi-query statement (taking some maximum + line/pieces amounts into account) + o changed formatting of syntax_comment to include some space + 2003-07-29 Marc Delisle * serbian: big update, thanks to Branislav Jovanoviæ and diff --git a/Documentation.html b/Documentation.html index 2778d336e..749ad83bc 100755 --- a/Documentation.html +++ b/Documentation.html @@ -1066,6 +1066,20 @@ $cfg['PmaAbsoluteUri'] = (!empty($_SERVER['HTTPS']) ? 'https' : 'http') . '://'

+
$cfg['IgnoreMultiSubmitErrors'] boolean
+
+ Define whether phpMyAdmin will continue executing a multi-query statement if one of the + queries fails. Default is to abort execution. +

+
+ +
$cfg['VerboseMultiSubmit'] boolean
+
+ Define whether phpMyAdmin will output the results of each query of a multi-query statement + embedded into the SQL output as inline comments. Defaults to TRUE. +

+
+
$cfg['LeftFrameLight'] boolean
Defines whether to use select-based menu and display only the current diff --git a/config.inc.php3 b/config.inc.php3 index ef9859bd4..ceb7cfdd3 100755 --- a/config.inc.php3 +++ b/config.inc.php3 @@ -188,17 +188,22 @@ unset($cfg['Servers'][0]); /** * Other core phpMyAdmin settings */ -$cfg['OBGzip'] = 'auto'; // use GZIP output buffering if possible (TRUE|FALSE|'auto') -$cfg['PersistentConnections'] = FALSE; // use persistent connections to MySQL database -$cfg['ExecTimeLimit'] = 300; // maximum execution time in seconds (0 for no limit) -$cfg['SkipLockedTables'] = FALSE; // mark used tables, make possible to show - // locked tables (since MySQL 3.23.30) -$cfg['ShowSQL'] = TRUE; // show SQL queries as run -$cfg['AllowUserDropDatabase'] = FALSE; // show a 'Drop database' link to normal users -$cfg['Confirm'] = TRUE; // confirm 'DROP TABLE' & 'DROP DATABASE' -$cfg['LoginCookieRecall'] = TRUE; // recall previous login in cookie auth. mode or not -$cfg['UseDbSearch'] = TRUE; // whether to enable the "database search" feature - // or not +$cfg['OBGzip'] = 'auto'; // use GZIP output buffering if possible (TRUE|FALSE|'auto') +$cfg['PersistentConnections'] = FALSE; // use persistent connections to MySQL database +$cfg['ExecTimeLimit'] = 300; // maximum execution time in seconds (0 for no limit) +$cfg['SkipLockedTables'] = FALSE; // mark used tables, make possible to show + // locked tables (since MySQL 3.23.30) +$cfg['ShowSQL'] = TRUE; // show SQL queries as run +$cfg['AllowUserDropDatabase'] = FALSE; // show a 'Drop database' link to normal users +$cfg['Confirm'] = TRUE; // confirm 'DROP TABLE' & 'DROP DATABASE' +$cfg['LoginCookieRecall'] = TRUE; // recall previous login in cookie auth. mode or not +$cfg['UseDbSearch'] = TRUE; // whether to enable the "database search" feature + // or not +$cfg['IgnoreMultiSubmitErrors'] = FALSE; // if set to true, PMA continues computing multiple-statement queries + // even if one of the queries failed +$cfg['VerboseMultiSubmit'] = TRUE; // if set to true, PMA will show the affected rows of EACH statement on + // multiple-statement queries. See the read_dump.php3 file for hardcoded + // defaults on how many queries a statement may contain! // Left frame setup $cfg['LeftFrameLight'] = TRUE; // use a select-based menu and display only the diff --git a/css/phpmyadmin.css.php3 b/css/phpmyadmin.css.php3 index 4126fcc97..e51fc726b 100644 --- a/css/phpmyadmin.css.php3 +++ b/css/phpmyadmin.css.php3 @@ -221,7 +221,7 @@ button.mult_submit { .print{font-family:arial;font-size:8pt;} .syntax {font-family: sans-serif; font-size: ;} -.syntax_comment {} +.syntax_comment { padding-left: 4pt; padding-right: 4pt;} .syntax_digit {} .syntax_digit_hex {} .syntax_digit_integer {} diff --git a/libraries/common.lib.php3 b/libraries/common.lib.php3 index 9f0d7cdab..f32984f60 100644 --- a/libraries/common.lib.php3 +++ b/libraries/common.lib.php3 @@ -135,7 +135,7 @@ h1 {font-family: sans-serif; font-size: large; font-weight: bold} * Includes compatibility code for older config.inc.php3 revisions * if necessary */ - if (!isset($cfg['FileRevision']) || (int) substr($cfg['FileRevision'], 13, 3) < 195) { + if (!isset($cfg['FileRevision']) || (int) substr($cfg['FileRevision'], 13, 3) < 197) { include('./libraries/config_import.lib.php3'); } diff --git a/libraries/config_import.lib.php3 b/libraries/config_import.lib.php3 index 1d64f9806..7a3bb1ded 100644 --- a/libraries/config_import.lib.php3 +++ b/libraries/config_import.lib.php3 @@ -277,6 +277,14 @@ if (!defined('PMA_CONFIG_IMPORT_LIB_INCLUDED')) { $cfg['UseDbSearch'] = TRUE; } + if (!isset($cfg['IgnoreMultiSubmitErrors'])) { + $cfg['IgnoreMultiSubmitErrors'] = FALSE; + } + + if (!isset($cfg['VerboseMultiSubmit'])) { + $cfg['VerboseMultiSubmit'] = TRUE; + } + if (!isset($cfg['LeftFrameLight'])) { if (isset($cfgLeftFrameLight)) { $cfg['LeftFrameLight'] = $cfgLeftFrameLight; diff --git a/libraries/sqlparser.lib.php3 b/libraries/sqlparser.lib.php3 index ad6856d15..f07f40a3b 100644 --- a/libraries/sqlparser.lib.php3 +++ b/libraries/sqlparser.lib.php3 @@ -1660,7 +1660,7 @@ if (!defined('PMA_SQP_LIB_INCLUDED')) { } break; case 'punct_queryend': - if (($typearr[3] != 'comment_mysql') && ($typearr[3] != 'comment_ansi')) { + if (($typearr[3] != 'comment_mysql') && ($typearr[3] != 'comment_ansi') && $typearr[3] != 'comment_c') { $after .= $html_line_break; $after .= $html_line_break; } diff --git a/read_dump.php3 b/read_dump.php3 index 406bbafba..692d0196d 100644 --- a/read_dump.php3 +++ b/read_dump.php3 @@ -173,18 +173,49 @@ if ($sql_query != '') { if ($pieces_count > 1) { $is_multiple = TRUE; } - + // Copy of the cleaned sql statement for display purpose only (see near the // beginning of "db_details.php3" & "tbl_properties.php3") - if ($sql_file != 'none' && $pieces_count > 10) { - // Be nice with bandwidth... - $sql_query_cpy = $sql_query = ''; + + // You can either + // * specify the amount of maximum pieces per query (having max_*_length set to 0!) or + // * specify the amount of maximum chars per query (having max_*_pieces set to 0!) + // - max_nofile_* is used for any queries submitted via copy&paste in the textarea + // - max_file_* is used for any file-submitted query + if (!$cfg['VerboseMultiSubmit']) { + // Here be the values if the Verbose-Mode (see config.inc.php3) is NOT activated + $max_nofile_length = 500; + $max_nofile_pieces = 0; + $max_file_length = 0; + $max_file_pieces = 10; } else { + // Values for verbose-mode + $max_nofile_length = 0; + $max_nofile_pieces = 50; + $max_file_length = 0; + $max_file_pieces = 50; + } + + if ($sql_file != 'none' && + ($max_file_length == 0 && ($pieces_count > $max_file_pieces)) + || + ($max_file_pieces == 0 && (strlen($sql_query) > $max_file_length))) { + // Be nice with bandwidth... + $sql_query_cpy = $sql_query = ''; + $save_bandwidth = TRUE; + $save_bandwidth_length = $max_file_length; + $save_bandwidth_pieces = $max_file_pieces; + } else { + $sql_query_cpy = implode(";\n", $pieces) . ';'; // Be nice with bandwidth... for now, an arbitrary limit of 500, // could be made configurable but probably not necessary - if (strlen($sql_query_cpy) > 500) { + if (($max_nofile_pieces == 0 && (strlen($sql_query_cpy) > $max_nofile_length)) + || ($max_nofile_length == 0 && $pieces_count > $max_nofile_pieces)) { $sql_query_cpy = $sql_query = ''; + $save_bandwidth = TRUE; + $save_bandwidth_length = $max_nofile_length; + $save_bandwidth_pieces = $max_nofile_pieces; } } @@ -203,6 +234,9 @@ if ($sql_query != '') { // Runs multiple queries else if (PMA_mysql_select_db($db)) { $mult = TRUE; + $info_msg = ''; + $info_count = 0; + for ($i = 0; $i < $pieces_count; $i++) { $a_sql_query = $pieces[$i]; if ($i == $pieces_count - 1 && eregi('^SELECT', $a_sql_query)) { @@ -211,15 +245,56 @@ if ($sql_query != '') { include('./sql.php3'); exit(); } + $result = PMA_mysql_query($a_sql_query); if ($result == FALSE) { // readdump failed - $my_die = $a_sql_query; - break; + if (isset($my_die) && $cfg['IgnoreMultiSubmitErrors']) { + $my_die[] = "\n\n" . $a_sql_query; + } elseif ($cfg['IgnoreMultiSubmitErrors']) { + $my_die = array(); + $my_die[] = $a_sql_query; + } else { + $my_die = $a_sql_query; + } + + if ($cfg['VerboseMultiSubmit']) { + $info_msg .= $a_sql_query . '; # ' . $strError . "\n"; + $info_count++; + } + + if (!$cfg['IgnoreMultiSubmitErrors']) { + break; + } + } else if ($cfg['VerboseMultiSubmit']) { + $a_num_rows = (int)@mysql_num_rows($result); + $a_aff_rows = (int)@mysql_affected_rows(); + if ($a_num_rows > 0) { + $a_rows = $a_num_rows; + $a_switch = $strRows . ': '; + } elseif ($a_aff_rows > 0) { + $a_rows = $a_aff_rows; + $a_switch = $strAffectedRows;; + } else { + $a_rows = ''; + $a_switch = $strEmptyResultSet; + } + + $info_msg .= $a_sql_query . "; # " . $a_switch . $a_rows . "\n"; + $info_count++; } + if (!isset($reload) && eregi('^(DROP|CREATE)[[:space:]]+(IF EXISTS[[:space:]]+)?(TABLE|DATABASE)[[:space:]]+(.+)', $a_sql_query)) { $reload = 1; } } // end for + + if ($cfg['VerboseMultiSubmit'] && strlen($info_msg) > 0 && + ((!isset($save_bandwidth) || $save_bandwidth == FALSE) || + ($save_bandwidth_pieces == 0 && strlen($sql_query) < $save_bandwidth_length) || + ($save_bandwidth_length == 0 && $info_count < $save_bandwidth_pieces))) { + $sql_query = $info_msg; + } + } // end else if } // end if (really run the query) unset($pieces); @@ -233,7 +308,14 @@ if ($sql_query != '') { if (isset($my_die)) { $js_to_run = 'functions.js'; include('./header.inc.php3'); - PMA_mysqlDie('', $my_die, '', $err_url . '&TEST'); + if (is_array($my_die)) { + while(list($key, $die_string) = each($my_die)) { + PMA_mysqlDie('', $die_string, '', $err_url, FALSE); + echo '
'; + } + } else { + PMA_mysqlDie('', $my_die, '', $err_url, TRUE); + } }