From b2f3ae5fcfdd8aa881c7abf20ffccdfc583a518a Mon Sep 17 00:00:00 2001 From: Sebastian Mendel Date: Sun, 1 Apr 2007 09:26:14 +0000 Subject: [PATCH] make $sql_query persistent (init it, never unset it, always assume it is set) --- import.php | 2 +- libraries/Table.class.php | 47 ++++++++++++++----------------- libraries/common.inc.php | 2 +- libraries/common.lib.php | 2 +- libraries/db_table_exists.lib.php | 4 +-- libraries/display_export.lib.php | 2 +- libraries/display_tbl.lib.php | 2 +- libraries/footer.inc.php | 2 +- libraries/import.lib.php | 2 +- libraries/sql_query_form.lib.php | 2 +- querywindow.php | 4 +-- server_engines.php | 1 - server_privileges.php | 6 ++-- sql.php | 9 +----- tbl_change.php | 6 ++-- tbl_create.php | 2 +- tbl_export.php | 2 +- tbl_relation.php | 5 ++-- tbl_row_action.php | 2 +- 19 files changed, 46 insertions(+), 58 deletions(-) diff --git a/import.php b/import.php index 30ee72102..9b1d70293 100644 --- a/import.php +++ b/import.php @@ -27,7 +27,7 @@ if (!empty($sql_query)) { $GLOBALS['reload'] = true; } - unset($sql_query); + $sql_query = ''; } elseif (!empty($sql_localfile)) { // run SQL file on server $local_import_file = $sql_localfile; diff --git a/libraries/Table.class.php b/libraries/Table.class.php index 8e851a3cc..a32805b77 100644 --- a/libraries/Table.class.php +++ b/libraries/Table.class.php @@ -549,10 +549,6 @@ class PMA_Table { { global $err_url; - if (! isset($GLOBALS['sql_query'])) { - $GLOBALS['sql_query'] = ''; - } - // set export settings we need $GLOBALS['sql_backquotes'] = 1; $GLOBALS['asfile'] = 1; @@ -581,7 +577,7 @@ class PMA_Table { require_once './libraries/export/sql.php'; $no_constraints_comments = true; - $GLOBALS['sql_constraints_query'] = ''; + $GLOBALS['sql_constraints_query'] = ''; $sql_structure = PMA_getTableDef($source_db, $source_table, "\n", $err_url); unset($no_constraints_comments); @@ -606,22 +602,22 @@ class PMA_Table { } /* no need to PMA_backquote() */ - if (isset($target_for_view)) { - // this a view definition; we just found the first db name - // that follows DEFINER VIEW - // so change it for the new db name - $parsed_sql[$i]['data'] = $target_for_view; - // then we have to find all references to the source db - // and change them to the target db, ensuring we stay into - // the $parsed_sql limits - $last = $parsed_sql['len'] - 1; - $backquoted_source_db = PMA_backquote($source_db); - for (++$i; $i <= $last; $i++) { - if ($parsed_sql[$i]['type'] == 'quote_backtick' && $parsed_sql[$i]['data'] == $backquoted_source_db) { + if (isset($target_for_view)) { + // this a view definition; we just found the first db name + // that follows DEFINER VIEW + // so change it for the new db name $parsed_sql[$i]['data'] = $target_for_view; - } - } - unset($last,$backquoted_source_db); + // then we have to find all references to the source db + // and change them to the target db, ensuring we stay into + // the $parsed_sql limits + $last = $parsed_sql['len'] - 1; + $backquoted_source_db = PMA_backquote($source_db); + for (++$i; $i <= $last; $i++) { + if ($parsed_sql[$i]['type'] == 'quote_backtick' && $parsed_sql[$i]['data'] == $backquoted_source_db) { + $parsed_sql[$i]['data'] = $target_for_view; + } + } + unset($last,$backquoted_source_db); } else { $parsed_sql[$i]['data'] = $target; } @@ -660,7 +656,7 @@ class PMA_Table { // find the first quote_backtick, it must be the source table name while ($parsed_sql[$i]['type'] != 'quote_backtick') { $i++; - // maybe someday we should guard against going over limit + // maybe someday we should guard against going over limit //if ($i == $parsed_sql['len']) { // break; //} @@ -686,15 +682,14 @@ class PMA_Table { // Generate query back $GLOBALS['sql_constraints_query'] = PMA_SQP_formatHtml($parsed_sql, 'query_only'); - if ($mode == 'one_table') { + if ($mode == 'one_table') { PMA_DBI_query($GLOBALS['sql_constraints_query']); - } + } $GLOBALS['sql_query'] .= "\n" . $GLOBALS['sql_constraints_query']; - if ($mode == 'one_table') { + if ($mode == 'one_table') { unset($GLOBALS['sql_constraints_query']); - } + } } - } else { $GLOBALS['sql_query'] = ''; } diff --git a/libraries/common.inc.php b/libraries/common.inc.php index 80d66350d..7910f91f9 100644 --- a/libraries/common.inc.php +++ b/libraries/common.inc.php @@ -426,7 +426,7 @@ if (PMA_isValid($_REQUEST['table'])) { * sql query to be executed * @global string $GLOBALS['sql_query'] */ -$GLOBALS['sql_query'] = null; +$GLOBALS['sql_query'] = ''; if (PMA_isValid($_REQUEST['sql_query'])) { $GLOBALS['sql_query'] = $_REQUEST['sql_query']; } diff --git a/libraries/common.lib.php b/libraries/common.lib.php index aa2ab1d8a..c6f5c14c0 100644 --- a/libraries/common.lib.php +++ b/libraries/common.lib.php @@ -985,7 +985,7 @@ function PMA_showMessage($message, $sql_query = null) // Checks if the table needs to be repaired after a TRUNCATE query. // @todo what about $GLOBALS['display_query']??? // @todo this is REALLY the wrong place to do this - very unexpected here - if (strlen($GLOBALS['table']) && isset($GLOBALS['sql_query']) + if (strlen($GLOBALS['table']) && $GLOBALS['sql_query'] == 'TRUNCATE TABLE ' . PMA_backquote($GLOBALS['table'])) { if (!isset($tbl_status)) { $result = @PMA_DBI_try_query('SHOW TABLE STATUS FROM ' . PMA_backquote($GLOBALS['db']) . ' LIKE \'' . PMA_sqlAddslashes($GLOBALS['table'], true) . '\''); diff --git a/libraries/db_table_exists.lib.php b/libraries/db_table_exists.lib.php index d7b71c9a2..8486cc7d7 100644 --- a/libraries/db_table_exists.lib.php +++ b/libraries/db_table_exists.lib.php @@ -24,7 +24,7 @@ if (empty($is_db)) { if (isset($message)) { $url_params['message'] = $message; } - if (isset($sql_query)) { + if (! empty($sql_query)) { $url_params['sql_query'] = $sql_query; } if (isset($show_as_php)) { @@ -72,7 +72,7 @@ if (empty($is_table) && !defined('PMA_SUBMIT_MULT')) { if (isset($message)) { $url_params['message'] = $message; } - if (isset($sql_query)) { + if (! empty($sql_query)) { $url_params['sql_query'] = $sql_query; } if (isset($display_query)) { diff --git a/libraries/display_export.lib.php b/libraries/display_export.lib.php index 6f2032487..5a8c42738 100644 --- a/libraries/display_export.lib.php +++ b/libraries/display_export.lib.php @@ -60,7 +60,7 @@ if (isset($single_table)) { echo '' . "\n"; -if (isset($sql_query)) { +if (! empty($sql_query)) { echo '' . "\n"; } echo PMA_pluginGetJavascript($export_list); diff --git a/libraries/display_tbl.lib.php b/libraries/display_tbl.lib.php index 6124a61a1..a5ceac105 100644 --- a/libraries/display_tbl.lib.php +++ b/libraries/display_tbl.lib.php @@ -1246,7 +1246,7 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) { $transform_options['wrapper_link'] = '?' . (isset($url_query) ? $url_query : '') . '&primary_key=' . (isset($unique_condition) ? $unique_condition : '') - . '&sql_query=' . (isset($sql_query) ? urlencode($url_sql_query) : '') + . '&sql_query=' . (empty($sql_query) ? '' : urlencode($url_sql_query)) . '&goto=' . (isset($sql_goto) ? urlencode($lnk_goto) : '') . '&transform_key=' . urlencode($meta->name); diff --git a/libraries/footer.inc.php b/libraries/footer.inc.php index 170374dea..5e3528523 100644 --- a/libraries/footer.inc.php +++ b/libraries/footer.inc.php @@ -88,7 +88,7 @@ if (window.parent.reload_querywindow) { window.parent.reload_querywindow( '', '', - ''); + ''); } 50000 || $executed_queries > 50 || $max_sql_len > 1000) { $sql_query = ''; $sql_query_disabled = TRUE; diff --git a/libraries/sql_query_form.lib.php b/libraries/sql_query_form.lib.php index 7c43217f8..9941a4850 100644 --- a/libraries/sql_query_form.lib.php +++ b/libraries/sql_query_form.lib.php @@ -74,7 +74,7 @@ function PMA_sqlQueryForm($query = true, $display_tab = false, $delimiter = ';') // query to show if (true === $query) { - $query = empty($GLOBALS['sql_query']) ? '' : $GLOBALS['sql_query']; + $query = $GLOBALS['sql_query']; } // set enctype to multipart for file uploads diff --git a/querywindow.php b/querywindow.php index 2c0e6890d..d1858e47d 100644 --- a/querywindow.php +++ b/querywindow.php @@ -135,7 +135,7 @@ if ($GLOBALS['cfg']['PropertiesIconic']) { $url_query = PMA_generate_common_url($db, $table); -if (PMA_isValid($sql_query)) { +if (! empty($sql_query)) { $show_query = 1; } @@ -160,7 +160,7 @@ if (! empty($show_query)) { } else { $query_to_display = ''; } -unset($sql_query); +$sql_query = ''; /** * start HTML output diff --git a/server_engines.php b/server_engines.php index fe1a5358f..97b156872 100644 --- a/server_engines.php +++ b/server_engines.php @@ -66,7 +66,6 @@ function PMA_generateEngineDetails($variables, $like = null) { } } PMA_DBI_free_result($res); - unset($res, $row, $sql_query); } if (empty($mysql_vars)) { diff --git a/server_privileges.php b/server_privileges.php index b844cd434..c45ff1a7a 100644 --- a/server_privileges.php +++ b/server_privileges.php @@ -724,7 +724,7 @@ if (!empty($change_copy)) { * (Changes / copies a user, part II) */ if (!empty($adduser_submit) || !empty($change_copy)) { - unset($sql_query); + $sql_query = ''; if ($pred_username == 'any') { $username = ''; } @@ -1712,7 +1712,7 @@ if ( empty( $adduser ) && ( ! isset( $checkprivs ) || ! strlen($checkprivs) ) ) $sql_query = 'SELECT * FROM `mysql`.`db`' . $user_host_condition . ' ORDER BY `Db` ASC'; $res = PMA_DBI_query( $sql_query ); - unset( $sql_query ); + $sql_query = ''; while ( $row = PMA_DBI_fetch_assoc( $res ) ) { if ( isset( $db_rights[$row['Db']] ) ) { @@ -1792,7 +1792,7 @@ if ( empty( $adduser ) && ( ! isset( $checkprivs ) || ! strlen($checkprivs) ) ) . $user_host_condition .' ORDER BY `Table_name` ASC;'; $res = PMA_DBI_query( $sql_query ); - unset( $sql_query ); + $sql_query = ''; while ( $row = PMA_DBI_fetch_assoc( $res ) ) { if ( isset( $db_rights[$row['Table_name']] ) ) { diff --git a/sql.php b/sql.php index 5eff555b3..da3a41649 100644 --- a/sql.php +++ b/sql.php @@ -57,7 +57,7 @@ if (isset($fields['dbase'])) { // Default to browse if no query set an we have table // (needed for browsing from DefaultTabTable) -if (! isset($sql_query) && strlen($table) && strlen($db)) { +if (empty($sql_query) && strlen($table) && strlen($db)) { require_once './libraries/bookmark.lib.php'; $book_sql_query = PMA_queryBookmarks($db, $GLOBALS['cfg']['Bookmark'], '\'' . PMA_sqlAddslashes($table) . '\'', @@ -228,13 +228,6 @@ if ($do_confirm) { } // end if $do_confirm -/** - * Executes the query and displays results - */ -if (!isset($sql_query)) { - $sql_query = ''; -} - // Defines some variables // A table has to be created or renamed -> left frame should be reloaded /** diff --git a/tbl_change.php b/tbl_change.php index f4aadcf43..3480665d0 100644 --- a/tbl_change.php +++ b/tbl_change.php @@ -31,7 +31,7 @@ if (isset($_REQUEST['dontlimitchars'])) { $dontlimitchars = $_REQUEST['dontlimitchars']; } /** - * @todo this one is badly named, it's really a WHERE condition + * @todo this one is badly named, it's really a WHERE condition * and exists even for tables not having a primary key or unique key */ if (isset($_REQUEST['primary_key'])) { @@ -209,7 +209,7 @@ document.onkeydown = onKeyDownArrowsHandler; - + ' . $strForeignKeyError . ' : ' . $master_field .'

' . PMA_showMySQLDocu('manual_Table_types', 'InnoDB_foreign_key_constraints') . "\n"; } - unset($sql_query, $tmp_error); + unset($tmp_error); + $sql_query = ''; } } // end foreach if (!empty($display_query)) { diff --git a/tbl_row_action.php b/tbl_row_action.php index 98a6d4a6a..abc5f849f 100644 --- a/tbl_row_action.php +++ b/tbl_row_action.php @@ -127,7 +127,7 @@ if (!empty($submit_mult)) { * Show result of multi submit operation */ // sql_query is not set when user does not confirm multi-delete - if ((!empty($submit_mult) || isset($mult_btn)) && isset($sql_query)) { + if ((!empty($submit_mult) || isset($mult_btn)) && ! empty($sql_query)) { $disp_message = $strSuccess; $disp_query = $sql_query; }