diff --git a/js/sql.js b/js/sql.js
index 126784d64..285df0f0d 100644
--- a/js/sql.js
+++ b/js/sql.js
@@ -155,14 +155,17 @@ $(document).ready(function() {
* @memberOf jQuery
* @name appendToggleSpan
*/
- $('')
- .html(PMA_messages['strToggleQueryBox'])
- .appendTo("#sqlqueryform");
+ // do not add this span more than once
+ if (! $('#sqlqueryform').find('span').is('#togglequerybox')) {
+ $('')
+ .html(PMA_messages['strToggleQueryBox'])
+ .appendTo("#sqlqueryform");
- // Attach the toggling of the query box visibility to a click
- $("#togglequerybox").live('click', function() {
- $(this).siblings().slideToggle("medium");
- })
+ // Attach the toggling of the query box visibility to a click
+ $("#togglequerybox").bind('click', function() {
+ $(this).siblings().slideToggle("medium");
+ })
+ }
/**
* Ajax Event handler for 'SQL Query Submit'
@@ -173,17 +176,29 @@ $(document).ready(function() {
*/
$("#sqlqueryform").live('submit', function(event) {
event.preventDefault();
-
+ $form = $(this);
PMA_ajaxShowMessage();
- $(this).append('');
+ if (! $form.find('input:hidden').is('#ajax_request_hidden')) {
+ $form.append('');
+ }
$.post($(this).attr('action'), $(this).serialize() , function(data) {
if(data.success == true) {
PMA_ajaxShowMessage(data.message);
+ // this happens if a USE command was typed
+ if (typeof data.reload != 'undefined') {
+ $form.find('input[name=db]').val(data.db);
+ // need to regenerate the whole upper part
+ $form.find('input[name=ajax_request]').remove();
+ $form.append('');
+ $.post('db_sql.php', $form.serialize(), function(data) {
+ $('body').html(data);
+ }); // end inner post
+ }
}
else if (data.success == false ) {
- PMA_ajaxShowMessage(data.error);
+ PMA_ajaxShowMessage(data.error, 50000);
}
else {
$("#sqlqueryresults").html(data);
diff --git a/sql.php b/sql.php
index 698ca8a52..898c8935e 100644
--- a/sql.php
+++ b/sql.php
@@ -677,7 +677,10 @@ if (0 == $num_rows || $is_affected) {
if(isset($GLOBALS['display_query'])) {
$extra_data['sql_query'] = PMA_showMessage(NULL, $GLOBALS['display_query']);
}
-
+ if ($GLOBALS['reload'] == 1) {
+ $extra_data['reload'] = 1;
+ $extra_data['db'] = $GLOBALS['db'];
+ }
PMA_ajaxResponse($message, $message->isSuccess(), (isset($extra_data) ? $extra_data : ''));
}