Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
3090a9cc40
@ -53,7 +53,7 @@ $.ajaxPrefilter(function (options, originalOptions, jqXHR) {
|
||||
});
|
||||
|
||||
/**
|
||||
* Show notices for ENUM columns; add/hide the default value
|
||||
* Show notices for ENUM columns; add/hide the default value
|
||||
*
|
||||
*/
|
||||
function PMA_verifyColumnsProperties()
|
||||
@ -2279,6 +2279,13 @@ AJAX.registerOnload('functions.js', function () {
|
||||
.submit();
|
||||
}
|
||||
});
|
||||
|
||||
$('body')
|
||||
.off('click', 'input.preview_sql')
|
||||
.on('click', 'input.preview_sql', function () {
|
||||
var $form = $(this).closest('form');
|
||||
PMA_previewSQL($form);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@ -2989,6 +2996,11 @@ function indexEditorDialog(url, title, callback_success, callback_failure)
|
||||
}
|
||||
}); // end $.post()
|
||||
};
|
||||
button_options[PMA_messages.strPreviewSQL] = function () {
|
||||
// Funciton for Previewing SQL
|
||||
var $form = $('#index_frm');
|
||||
PMA_previewSQL($form);
|
||||
};
|
||||
button_options[PMA_messages.strCancel] = function () {
|
||||
$(this).dialog('close');
|
||||
};
|
||||
@ -4164,3 +4176,53 @@ function checkNumberOfFields() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests SQL for previewing before executing.
|
||||
*
|
||||
* @param jQuery Object $form Form containing query data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function PMA_previewSQL($form)
|
||||
{
|
||||
var form_url = $form.attr('action');
|
||||
var form_data = $form.serialize() +
|
||||
'&do_save_data=1' +
|
||||
'&preview_sql=1' +
|
||||
'&ajax_request=1';
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: form_url,
|
||||
data: form_data,
|
||||
success: function (response) {
|
||||
if (response.success) {
|
||||
var $dialog_content = $('<div/>')
|
||||
.append(response.sql_data);
|
||||
var button_options = {};
|
||||
button_options[PMA_messages.strClose] = function () {
|
||||
$(this).dialog('close');
|
||||
};
|
||||
var $response_dialog = $dialog_content.dialog({
|
||||
minWidth: 550,
|
||||
maxHeight: 400,
|
||||
modal: true,
|
||||
buttons: button_options,
|
||||
title: PMA_messages.strPreviewSQL,
|
||||
close: function () {
|
||||
$(this).remove();
|
||||
},
|
||||
open: function () {
|
||||
// Pretty SQL printing.
|
||||
PMA_highlightSQL($(this));
|
||||
}
|
||||
});
|
||||
} else {
|
||||
PMA_ajaxShowMessage(response.message);
|
||||
}
|
||||
},
|
||||
error: function () {
|
||||
PMA_ajaxShowMessage(PMA_messages.strErrorProcessingRequest);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -54,6 +54,9 @@ $js_messages['strAddIndex'] = __('Add Index');
|
||||
$js_messages['strEditIndex'] = __('Edit Index');
|
||||
$js_messages['strAddToIndex'] = __('Add %s column(s) to index');
|
||||
|
||||
/* For Preview SQL*/
|
||||
$js_messages['strPreviewSQL'] = __('Preview SQL');
|
||||
|
||||
/* Charts */
|
||||
/* l10n: Default label for the y-Axis of Charts */
|
||||
$js_messages['strYValues'] = __('Y Values');
|
||||
|
||||
@ -905,4 +905,31 @@ function PMA_mimeDefaultFunction($buffer)
|
||||
|
||||
return $buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays SQL query before executing.
|
||||
*
|
||||
* @param array|string $query_data Array containing queries or query itself
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function PMA_previewSQL($query_data)
|
||||
{
|
||||
$retval = '<div class="preview_sql">';
|
||||
if (is_array($query_data) && count($query_data) > 0) {
|
||||
foreach ($query_data as $query) {
|
||||
$retval .= PMA_Util::formatSql($query);
|
||||
}
|
||||
} else {
|
||||
if (! empty($query_data)) {
|
||||
$retval .= PMA_Util::formatSql($query_data);
|
||||
} else {
|
||||
$retval .= __('No change');
|
||||
}
|
||||
}
|
||||
$retval .= '</div>';
|
||||
$response = PMA_Response::getInstance();
|
||||
$response->addJSON('sql_data', $retval);
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
|
||||
@ -1603,8 +1603,10 @@ function PMA_getSumbitAndResetButtonForActionsPanel($tabindex, $tabindex_for_val
|
||||
. '<td colspan="3" class="right vmiddle">'
|
||||
. '<input type="submit" class="control_at_footer" value="' . __('Go') . '"'
|
||||
. ' tabindex="' . ($tabindex + $tabindex_for_value + 6) . '" id="buttonYes" />'
|
||||
. '<input type="reset" class="control_at_footer" value="' . __('Reset') . '"'
|
||||
. '<input type="button" class="preview_sql" value="' . __('Preview SQL') . '"'
|
||||
. ' tabindex="' . ($tabindex + $tabindex_for_value + 7) . '" />'
|
||||
. '<input type="reset" class="control_at_footer" value="' . __('Reset') . '"'
|
||||
. ' tabindex="' . ($tabindex + $tabindex_for_value + 8) . '" />'
|
||||
. '</td>';
|
||||
}
|
||||
|
||||
|
||||
@ -2479,7 +2479,7 @@ function PMA_updateColumns($db, $table)
|
||||
|
||||
$response = PMA_Response::getInstance();
|
||||
|
||||
if (count($changes) > 0) {
|
||||
if (count($changes) > 0 || isset($_REQUEST['preview_sql'])) {
|
||||
// Builds the primary keys statements and updates the table
|
||||
$key_query = '';
|
||||
/**
|
||||
@ -2504,6 +2504,12 @@ function PMA_updateColumns($db, $table)
|
||||
$sql_query = 'ALTER TABLE ' . PMA_Util::backquote($table) . ' ';
|
||||
$sql_query .= implode(', ', $changes) . $key_query;
|
||||
$sql_query .= ';';
|
||||
|
||||
// If there is a request for SQL previewing.
|
||||
if (isset($_REQUEST['preview_sql'])) {
|
||||
PMA_previewSQL(count($changes) > 0 ? $sql_query : '');
|
||||
}
|
||||
|
||||
$result = $GLOBALS['dbi']->tryQuery($sql_query);
|
||||
|
||||
if ($result !== false) {
|
||||
|
||||
@ -138,6 +138,7 @@ function PMA_getHtmlForTableConfigurations()
|
||||
function PMA_getHtmlForFooter()
|
||||
{
|
||||
$html = '<fieldset class="tblFooters">'
|
||||
. '<input type="button" class="preview_sql" value="' . __('Preview SQL') . '" />'
|
||||
. '<input type="submit" name="do_save_data" value="' . __('Save') . '" />'
|
||||
. '</fieldset>'
|
||||
. '<div id="properties_message"></div>'
|
||||
|
||||
@ -50,6 +50,11 @@ function PMA_handleCreateOrEditIndex($db, $table, $index)
|
||||
|
||||
$sql_query = PMA_getSqlQueryForIndexCreateOrEdit($db, $table, $index, $error);
|
||||
|
||||
// If there is a request for SQL previewing.
|
||||
if (isset($_REQUEST['preview_sql'])) {
|
||||
PMA_previewSQL($sql_query);
|
||||
}
|
||||
|
||||
if (! $error) {
|
||||
$GLOBALS['dbi']->query($sql_query);
|
||||
$message = PMA_Message::success(
|
||||
|
||||
@ -362,6 +362,7 @@ function PMA_getHtmlForCommonFormHeader($db, $table)
|
||||
function PMA_getHtmlForCommonFormFooter()
|
||||
{
|
||||
return '<fieldset class="tblFooters">'
|
||||
. '<input type="button" class="preview_sql" value="' . __('Preview SQL') . '" />'
|
||||
. '<input type="submit" value="' . __('Save') . '" />'
|
||||
. '</fieldset>'
|
||||
. '</form>';
|
||||
@ -877,15 +878,26 @@ function PMA_handleUpdatesForForeignKeys($destination_foreign_db,
|
||||
$destination_foreign_column, $options_array, $table, $existrel_foreign
|
||||
) {
|
||||
$html_output = '';
|
||||
$preview_sql_data = '';
|
||||
$display_query = '';
|
||||
$seen_error = false;
|
||||
$preview_sql = (isset($_REQUEST['preview_sql'])) ? true : false;
|
||||
foreach ($destination_foreign_db as $master_field_md5 => $foreign_db) {
|
||||
$html_output .= PMA_handleUpdateForForeignKey(
|
||||
list($html, $sql_data) = PMA_handleUpdateForForeignKey(
|
||||
$multi_edit_columns_name, $master_field_md5,
|
||||
$destination_foreign_table, $destination_foreign_column, $options_array,
|
||||
$existrel_foreign, $table, $seen_error, $display_query, $foreign_db
|
||||
$existrel_foreign, $table, $seen_error, $display_query, $foreign_db,
|
||||
$preview_sql
|
||||
);
|
||||
$html_output .= $html;
|
||||
$preview_sql_data .= $sql_data;
|
||||
} // end foreach
|
||||
|
||||
// If there is a request for SQL previewing.
|
||||
if ($preview_sql) {
|
||||
PMA_previewSQL($preview_sql_data);
|
||||
}
|
||||
|
||||
if (! empty($display_query) && ! $seen_error) {
|
||||
$GLOBALS['display_query'] = $display_query;
|
||||
$html_output = PMA_Util::getMessage(
|
||||
@ -910,14 +922,16 @@ function PMA_handleUpdatesForForeignKeys($destination_foreign_db,
|
||||
* @param bool &$seen_error whether seen error
|
||||
* @param string &$display_query display query
|
||||
* @param string $foreign_db foreign database
|
||||
* @param bool $preview_sql preview sql before executing
|
||||
*
|
||||
* @return string
|
||||
* @return array
|
||||
*/
|
||||
function PMA_handleUpdateForForeignKey($multi_edit_columns_name, $master_field_md5,
|
||||
$destination_foreign_table, $destination_foreign_column, $options_array,
|
||||
$existrel_foreign, $table, &$seen_error, &$display_query, $foreign_db
|
||||
$existrel_foreign, $table, &$seen_error, &$display_query, $foreign_db, $preview_sql
|
||||
) {
|
||||
$html_output = '';
|
||||
$preview_sql_data = '';
|
||||
$create = false;
|
||||
$drop = false;
|
||||
|
||||
@ -963,16 +977,21 @@ function PMA_handleUpdateForForeignKey($multi_edit_columns_name, $master_field_m
|
||||
$drop_query = PMA_getSQLToDropForeignKey(
|
||||
$table, $existrel_foreign[$master_field]['constraint']
|
||||
);
|
||||
$display_query .= $drop_query . "\n";
|
||||
$GLOBALS['dbi']->tryQuery($drop_query);
|
||||
$tmp_error_drop = $GLOBALS['dbi']->getError();
|
||||
|
||||
if (! empty($tmp_error_drop)) {
|
||||
$seen_error = true;
|
||||
$html_output .= PMA_Util::mysqlDie(
|
||||
$tmp_error_drop, $drop_query, false, '', false
|
||||
);
|
||||
return $html_output;
|
||||
if (! $preview_sql) {
|
||||
$display_query .= $drop_query . "\n";
|
||||
$GLOBALS['dbi']->tryQuery($drop_query);
|
||||
$tmp_error_drop = $GLOBALS['dbi']->getError();
|
||||
|
||||
if (! empty($tmp_error_drop)) {
|
||||
$seen_error = true;
|
||||
$html_output .= PMA_Util::mysqlDie(
|
||||
$tmp_error_drop, $drop_query, false, '', false
|
||||
);
|
||||
return $html_output;
|
||||
}
|
||||
} else {
|
||||
$preview_sql_data .= $drop_query . "\n";
|
||||
}
|
||||
}
|
||||
$tmp_error_create = false;
|
||||
@ -984,26 +1003,30 @@ function PMA_handleUpdateForForeignKey($multi_edit_columns_name, $master_field_m
|
||||
$options_array[$_REQUEST['on_update'][$master_field_md5]]
|
||||
);
|
||||
|
||||
$display_query .= $create_query . "\n";
|
||||
$GLOBALS['dbi']->tryQuery($create_query);
|
||||
$tmp_error_create = $GLOBALS['dbi']->getError();
|
||||
if (! empty($tmp_error_create)) {
|
||||
$seen_error = true;
|
||||
if (! $preview_sql) {
|
||||
$display_query .= $create_query . "\n";
|
||||
$GLOBALS['dbi']->tryQuery($create_query);
|
||||
$tmp_error_create = $GLOBALS['dbi']->getError();
|
||||
if (! empty($tmp_error_create)) {
|
||||
$seen_error = true;
|
||||
|
||||
if (substr($tmp_error_create, 1, 4) == '1005') {
|
||||
$message = PMA_Message::error(
|
||||
__('Error creating foreign key on %1$s (check data types)')
|
||||
);
|
||||
$message->addParam($master_field);
|
||||
$html_output .= $message->getDisplay();
|
||||
} else {
|
||||
$html_output .= PMA_Util::mysqlDie(
|
||||
$tmp_error_create, $create_query, false, '', false
|
||||
);
|
||||
if (substr($tmp_error_create, 1, 4) == '1005') {
|
||||
$message = PMA_Message::error(
|
||||
__('Error creating foreign key on %1$s (check data types)')
|
||||
);
|
||||
$message->addParam($master_field);
|
||||
$html_output .= $message->getDisplay();
|
||||
} else {
|
||||
$html_output .= PMA_Util::mysqlDie(
|
||||
$tmp_error_create, $create_query, false, '', false
|
||||
);
|
||||
}
|
||||
$html_output .= PMA_Util::showMySQLDocu(
|
||||
'InnoDB_foreign_key_constraints'
|
||||
) . "\n";
|
||||
}
|
||||
$html_output .= PMA_Util::showMySQLDocu(
|
||||
'InnoDB_foreign_key_constraints'
|
||||
) . "\n";
|
||||
} else {
|
||||
$preview_sql_data .= $create_query . "\n";
|
||||
}
|
||||
|
||||
// this is an alteration and the old constraint has been dropped
|
||||
@ -1023,11 +1046,15 @@ function PMA_handleUpdateForForeignKey($multi_edit_columns_name, $master_field_m
|
||||
$options_array[$existrel_foreign[$master_field]['on_delete']],
|
||||
$options_array[$existrel_foreign[$master_field]['on_update']]
|
||||
);
|
||||
$display_query .= $sql_query_recreate . "\n";
|
||||
$GLOBALS['dbi']->tryQuery($sql_query_recreate);
|
||||
if (! $preview_sql) {
|
||||
$display_query .= $sql_query_recreate . "\n";
|
||||
$GLOBALS['dbi']->tryQuery($sql_query_recreate);
|
||||
} else {
|
||||
$preview_sql_data .= $sql_query_recreate;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $html_output;
|
||||
return array($html_output, $preview_sql_data);
|
||||
}
|
||||
?>
|
||||
|
||||
@ -55,6 +55,11 @@ $action = 'tbl_create.php';
|
||||
*/
|
||||
if (isset($_REQUEST['do_save_data'])) {
|
||||
$sql_query = PMA_getTableCreationQuery($db, $table);
|
||||
|
||||
// If there is a request for SQL previewing.
|
||||
if (isset($_REQUEST['preview_sql'])) {
|
||||
PMA_previewSQL($sql_query);
|
||||
}
|
||||
// Executes the query
|
||||
$result = $GLOBALS['dbi']->tryQuery($sql_query);
|
||||
|
||||
|
||||
@ -244,7 +244,7 @@ unset($multi_edit_columns_name, $multi_edit_columns_prev, $multi_edit_funcs,
|
||||
// Builds the sql query
|
||||
if ($is_insert && count($value_sets) > 0) {
|
||||
$query = PMA_buildSqlQuery($is_insertignore, $query_fields, $value_sets);
|
||||
} elseif (empty($query)) {
|
||||
} elseif (empty($query) && ! isset($_REQUEST['preview_sql'])) {
|
||||
// No change -> move back to the calling script
|
||||
//
|
||||
// Note: logic passes here for inline edit
|
||||
@ -255,6 +255,11 @@ if ($is_insert && count($value_sets) > 0) {
|
||||
}
|
||||
unset($multi_edit_colummns, $is_insertignore);
|
||||
|
||||
// If there is a request for SQL previewing.
|
||||
if (isset($_REQUEST['preview_sql'])) {
|
||||
PMA_previewSQL($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the sql query and get the result, then move back to the calling
|
||||
* page
|
||||
|
||||
@ -1648,11 +1648,19 @@ class PMA_InsertEditTest extends PHPUnit_Framework_TestCase
|
||||
|
||||
$this->assertTag(
|
||||
PMA_getTagArray(
|
||||
'<input type="reset" class="control_at_footer" value="Reset" '
|
||||
'<input type="button" class="preview_sql" value="Preview SQL" '
|
||||
. 'tabindex="8" />'
|
||||
),
|
||||
$result
|
||||
);
|
||||
|
||||
$this->assertTag(
|
||||
PMA_getTagArray(
|
||||
'<input type="reset" class="control_at_footer" value="Reset" '
|
||||
. 'tabindex="9" />'
|
||||
),
|
||||
$result
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -262,11 +262,13 @@ select:hover {
|
||||
}
|
||||
|
||||
input[type=submit],
|
||||
input[type=button],
|
||||
button[type=submit]:not(.mult_submit) {
|
||||
font-weight: bold !important;
|
||||
}
|
||||
|
||||
input[type=submit],
|
||||
input[type=button],
|
||||
button[type=submit]:not(.mult_submit),
|
||||
input[type=reset],
|
||||
input[name=submit_reset],
|
||||
@ -288,6 +290,7 @@ input.button {
|
||||
}
|
||||
|
||||
input[type=submit]:hover,
|
||||
input[type=button]:hover,
|
||||
button[type=submit]:not(.mult_submit):hover,
|
||||
input[type=reset]:hover,
|
||||
input[name=submit_reset]:hover,
|
||||
@ -298,6 +301,7 @@ input.button:hover {
|
||||
}
|
||||
|
||||
input[type=submit]:active,
|
||||
input[type=button]:active,
|
||||
button[type=submit]:not(.mult_submit):active,
|
||||
input[type=reset]:active,
|
||||
input[name=submit_reset]:active,
|
||||
@ -317,7 +321,7 @@ textarea.char {
|
||||
height: <?php echo ceil($GLOBALS['cfg']['CharTextareaRows'] * 1.2); ?>em;
|
||||
}
|
||||
|
||||
fieldset {
|
||||
fieldset, .preview_sql {
|
||||
margin-top: 1em;
|
||||
border-radius: 4px 4px 0 0;
|
||||
-moz-border-radius: 4px 4px 0 0;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user