Skip to content
Browse files

make $sql_query persistent (init it, never unset it, always assume it…

… is set)
  • Loading branch information...
1 parent 0848d0f commit b2f3ae5fcfdd8aa881c7abf20ffccdfc583a518a Sebastian Mendel committed Apr 1, 2007
View
2 import.php
@@ -27,7 +27,7 @@
$GLOBALS['reload'] = true;
}
- unset($sql_query);
+ $sql_query = '';
} elseif (!empty($sql_localfile)) {
// run SQL file on server
$local_import_file = $sql_localfile;
View
47 libraries/Table.class.php
@@ -549,10 +549,6 @@ function moveCopy($source_db, $source_table, $target_db, $target_table, $what, $
{
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 @@ function moveCopy($source_db, $source_table, $target_db, $target_table, $what, $
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 @@ function moveCopy($source_db, $source_table, $target_db, $target_table, $what, $
}
/* 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 @@ function moveCopy($source_db, $source_table, $target_db, $target_table, $what, $
// 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 @@ function moveCopy($source_db, $source_table, $target_db, $target_table, $what, $
// 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'] = '';
}
View
2 libraries/common.inc.php
@@ -426,7 +426,7 @@
* 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'];
}
View
2 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) . '\'');
View
4 libraries/db_table_exists.lib.php
@@ -24,7 +24,7 @@
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 (isset($message)) {
$url_params['message'] = $message;
}
- if (isset($sql_query)) {
+ if (! empty($sql_query)) {
$url_params['sql_query'] = $sql_query;
}
if (isset($display_query)) {
View
2 libraries/display_export.lib.php
@@ -60,7 +60,7 @@ function PMA_exportIsActive($what, $val) {
echo '<input type="hidden" name="export_type" value="' . $export_type . '" />' . "\n";
-if (isset($sql_query)) {
+if (! empty($sql_query)) {
echo '<input type="hidden" name="sql_query" value="' . htmlspecialchars($sql_query) . '" />' . "\n";
}
echo PMA_pluginGetJavascript($export_list);
View
2 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 : '')
. '&amp;primary_key=' . (isset($unique_condition) ? $unique_condition : '')
- . '&amp;sql_query=' . (isset($sql_query) ? urlencode($url_sql_query) : '')
+ . '&amp;sql_query=' . (empty($sql_query) ? '' : urlencode($url_sql_query))
. '&amp;goto=' . (isset($sql_goto) ? urlencode($lnk_goto) : '')
. '&amp;transform_key=' . urlencode($meta->name);
View
2 libraries/footer.inc.php
@@ -88,7 +88,7 @@
window.parent.reload_querywindow(
'<?php echo PMA_escapeJsString(PMA_ifSetOr($GLOBALS['db'], '')) ?>',
'<?php echo PMA_escapeJsString(PMA_ifSetOr($GLOBALS['table'], '')) ?>',
- '<?php echo isset($GLOBALS['sql_query']) && ! defined('PMA_QUERY_TOO_BIG') ? PMA_escapeJsString($GLOBALS['sql_query']) : ''; ?>');
+ '<?php echo ! defined('PMA_QUERY_TOO_BIG') ? PMA_escapeJsString($GLOBALS['sql_query']) : ''; ?>');
}
<?php
}
View
2 libraries/import.lib.php
@@ -173,7 +173,7 @@ function PMA_importRunQuery($sql = '', $full = '', $controluser = false)
}
// check length of query unless we decided to pass it to sql.php
if (!$go_sql) {
- if ($cfg['VerboseMultiSubmit'] && !empty($sql_query)) {
+ if ($cfg['VerboseMultiSubmit'] && ! empty($sql_query)) {
if (strlen($sql_query) > 50000 || $executed_queries > 50 || $max_sql_len > 1000) {
$sql_query = '';
$sql_query_disabled = TRUE;
View
2 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
View
4 querywindow.php
@@ -135,7 +135,7 @@
$url_query = PMA_generate_common_url($db, $table);
-if (PMA_isValid($sql_query)) {
+if (! empty($sql_query)) {
$show_query = 1;
}
@@ -160,7 +160,7 @@
} else {
$query_to_display = '';
}
-unset($sql_query);
+$sql_query = '';
/**
* start HTML output
View
1 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)) {
View
6 server_privileges.php
@@ -724,7 +724,7 @@ function PMA_displayLoginInformationFields($mode = 'new', $indent = 0 ) {
* (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 @@ function PMA_displayLoginInformationFields($mode = 'new', $indent = 0 ) {
$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 @@ function PMA_displayLoginInformationFields($mode = 'new', $indent = 0 ) {
. $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']] ) ) {
View
9 sql.php
@@ -57,7 +57,7 @@
// 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 @@
} // 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
/**
View
6 tbl_change.php
@@ -31,7 +31,7 @@
$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 @@
<input type="hidden" name="repeat_cells" value="<?php echo isset($repeat_cells) ? $repeat_cells : ''; ?>" />
<input type="hidden" name="dontlimitchars" value="<?php echo (isset($dontlimitchars) ? $dontlimitchars : 0); ?>" />
<input type="hidden" name="err_url" value="<?php echo htmlspecialchars($err_url); ?>" />
- <input type="hidden" name="sql_query" value="<?php echo isset($sql_query) ? htmlspecialchars($sql_query) : ''; ?>" />
+ <input type="hidden" name="sql_query" value="<?php echo htmlspecialchars($sql_query); ?>" />
<?php
if (isset($primary_key_array)) {
foreach ($primary_key_array as $primary_key) {
@@ -270,7 +270,7 @@
if (isset($primary_key)) {
$url_params['primary_key'] = trim($primary_key);
}
-if (isset($sql_query)) {
+if (! empty($sql_query)) {
$url_params['sql_query'] = $sql_query;
}
View
2 tbl_create.php
@@ -231,7 +231,7 @@
. htmlspecialchars(PMA_backquote($db) . '.' . PMA_backquote($table))
. ' ' . $strHasBeenCreated;
$display_query = $sql_query;
- unset($sql_query);
+ $sql_query = '';
// do not switch to sql.php - as there is no row to be displayed on a new table
if ($cfg['DefaultTabTable'] === 'sql.php') {
View
2 tbl_export.php
@@ -24,7 +24,7 @@
// When we have some query, we need to remove LIMIT from that and possibly
// generate WHERE clause (if we are asked to export specific rows)
-if (isset($sql_query)) {
+if (! empty($sql_query)) {
// Parse query so we can work with tokens
$parsed_sql = PMA_SQP_parse($sql_query);
View
5 tbl_relation.php
@@ -212,7 +212,7 @@ function PMA_generate_dropdown($dropdown_question, $radio_name, $choices, $selec
}
} // end if... else....
- if (isset($sql_query)) {
+ if (! empty($sql_query)) {
$upd_rs = PMA_DBI_try_query($sql_query);
$tmp_error = PMA_DBI_getError();
if (! empty($tmp_error)) {
@@ -227,7 +227,8 @@ function PMA_generate_dropdown($dropdown_question, $radio_name, $choices, $selec
echo '<p class="warning">' . $strForeignKeyError . ' : ' . $master_field
.'</p>' . 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)) {
View
2 tbl_row_action.php
@@ -127,7 +127,7 @@
* 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;
}

0 comments on commit b2f3ae5

Please sign in to comment.
Something went wrong with that request. Please try again.