For bug #3220370, generate UPDATE only for modified columns and avoid POSTing if not needed

This commit is contained in:
Marc Delisle
2011-03-23 07:47:24 -04:00
parent 2636f3b18e
commit 701a668d35

View File

@@ -778,6 +778,8 @@ $(document).ready(function() {
*/ */
var sql_query = 'UPDATE `' + window.parent.table + '` SET '; var sql_query = 'UPDATE `' + window.parent.table + '` SET ';
var need_to_post = false;
$input_siblings.each(function() { $input_siblings.each(function() {
/** @lends jQuery */ /** @lends jQuery */
/** /**
@@ -806,6 +808,7 @@ $(document).ready(function() {
if (is_null) { if (is_null) {
sql_query += ' `' + field_name + "`=NULL , "; sql_query += ' `' + field_name + "`=NULL , ";
need_to_post = true;
} else { } else {
if($this_field.is(":not(.relation, .enum, .set)")) { if($this_field.is(":not(.relation, .enum, .set)")) {
this_field_params[field_name] = $this_field.find('textarea').val(); this_field_params[field_name] = $this_field.find('textarea').val();
@@ -834,7 +837,10 @@ $(document).ready(function() {
$.extend(relation_fields, this_field_params); $.extend(relation_fields, this_field_params);
} }
} }
if (this_field_params[field_name] != $this_field.data('original_data')) {
sql_query += ' `' + field_name + "`='" + this_field_params[field_name].replace(/'/g, "''") + "' , "; sql_query += ' `' + field_name + "`='" + this_field_params[field_name].replace(/'/g, "''") + "' , ";
need_to_post = true;
}
} }
}) })
@@ -852,6 +858,11 @@ $(document).ready(function() {
*/ */
var transform_fields_list = $.param(transform_fields); var transform_fields_list = $.param(transform_fields);
// if inline_edit is successful, we need to go back to default view
var $del_hide=$(this).parent();
var $chg_submit=$(this);
if (need_to_post) {
// Make the Ajax post after setting all parameters // Make the Ajax post after setting all parameters
/** /**
* @var post_params Object containing parameters for the POST request * @var post_params Object containing parameters for the POST request
@@ -871,27 +882,45 @@ $(document).ready(function() {
'submit_type' : 'save' 'submit_type' : 'save'
}; };
// if inline_edit is successful, we need to go back to default view
var $del_hide=$(this).parent();
var $chg_submit=$(this);
$.post('tbl_replace.php', post_params, function(data) { $.post('tbl_replace.php', post_params, function(data) {
if(data.success == true) { if(data.success == true) {
// deleting the hide button if my query was successful PMA_ajaxShowMessage(data.message);
PMA_unInlineEditRow($del_hide, $chg_submit, $this_td, $input_siblings, data, disp_mode);
} else {
PMA_ajaxShowMessage(data.error);
};
}) // end $.post()
} else {
// no posting was done but still need to display the row
// in its previous format
PMA_unInlineEditRow($del_hide, $chg_submit, $this_td, $input_siblings, '', disp_mode);
}
}) // End After editing, clicking again should post data
}, 'top.frame_content') // end $(document).ready()
/**
* Visually put back the row in the state it was before entering Inline edit
*
* (when called in the situation where no posting was done, the data
* parameter is empty)
*/
function PMA_unInlineEditRow($del_hide, $chg_submit, $this_td, $input_siblings, data, disp_mode) {
// deleting the hide button
// remove <br><br><a> tags // remove <br><br><a> tags
for ( var i=0;i<=2;i++) { $del_hide.next().remove(); } for ( var i = 0; i <= 2; i++) {
$del_hide.next().remove();
}
if(disp_mode != 'vertical'){ if(disp_mode != 'vertical'){
$chg_submit.empty(); $chg_submit.empty();
$chg_submit.html('<span class="nowrap"></span>'); $chg_submit.html('<span class="nowrap"></span>');
$chg_submit.children('span.nowrap').text(PMA_messages['strInlineEdit']); $chg_submit.children('span.nowrap').text(PMA_messages['strInlineEdit']);
} } else {
else {
$chg_submit.children('span.nowrap').empty(); $chg_submit.children('span.nowrap').empty();
$chg_submit.children('span.nowrap').append(data_vt); $chg_submit.children('span.nowrap').append(data_vt);
} }
PMA_ajaxShowMessage(data.message);
// changing inline_edit_active to inline_edit_anchor // changing inline_edit_active to inline_edit_anchor
$this_td.removeClass('inline_edit_active').addClass('inline_edit_anchor'); $this_td.removeClass('inline_edit_active').addClass('inline_edit_anchor');
@@ -921,13 +950,13 @@ $(document).ready(function() {
if($this_sibling.is('.transformed')) { if($this_sibling.is('.transformed')) {
var field_name = getFieldName($this_sibling, disp_mode); var field_name = getFieldName($this_sibling, disp_mode);
if (typeof data.transformations != 'undefined') {
$.each(data.transformations, function(key, value) { $.each(data.transformations, function(key, value) {
if(key == field_name) { if(key == field_name) {
if($this_sibling.is('.text_plain, .application_octetstream')) { if($this_sibling.is('.text_plain, .application_octetstream')) {
new_html = value; new_html = value;
return false; return false;
} } else {
else {
var new_value = $this_sibling.find('textarea').val(); var new_value = $this_sibling.find('textarea').val();
new_html = $(value).append(new_value); new_html = $(value).append(new_value);
return false; return false;
@@ -936,14 +965,13 @@ $(document).ready(function() {
}) })
} }
} }
else { } else {
var new_html = ''; var new_html = '';
var new_value = ''; var new_value = '';
$test_element = $this_sibling.find('select'); $test_element = $this_sibling.find('select');
if ($test_element.length != 0) { if ($test_element.length != 0) {
new_value = $test_element.val(); new_value = $test_element.val();
} }
$test_element = $this_sibling.find('span.curr_value'); $test_element = $this_sibling.find('span.curr_value');
if ($test_element.length != 0) { if ($test_element.length != 0) {
new_value = $test_element.text(); new_value = $test_element.text();
@@ -951,12 +979,14 @@ $(document).ready(function() {
if($this_sibling.is('.relation')) { if($this_sibling.is('.relation')) {
var field_name = getFieldName($this_sibling, disp_mode); var field_name = getFieldName($this_sibling, disp_mode);
if (typeof data.relations != 'undefined') {
$.each(data.relations, function(key, value) { $.each(data.relations, function(key, value) {
if(key == field_name) { if(key == field_name) {
new_html = $(value).append(new_value); new_html = $(value).append(new_value);
return false; return false;
} }
}) })
}
} else if ($this_sibling.is('.enum')) { } else if ($this_sibling.is('.enum')) {
new_html = new_value; new_html = new_value;
} else if ($this_sibling.is('.set')) { } else if ($this_sibling.is('.set')) {
@@ -972,12 +1002,6 @@ $(document).ready(function() {
} }
}) })
} }
else {
PMA_ajaxShowMessage(data.error);
};
}) // end $.post()
}) // End After editing, clicking again should post data
}, 'top.frame_content') // end $(document).ready()
/** /**
* Starting from some th, change the class of all td under it * Starting from some th, change the class of all td under it