From 0b64ff7f72121b226a47acac5df303ad12e2ae49 Mon Sep 17 00:00:00 2001 From: Deven Bansod Date: Mon, 21 Dec 2015 13:53:03 +0530 Subject: [PATCH] Fix #11724 : live data edit of big sets is not working Signed-off-by: Deven Bansod --- js/makegrid.js | 12 +++++++++--- libraries/sql.lib.php | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/js/makegrid.js b/js/makegrid.js index 6e583655c0..f41ef3b9e1 100644 --- a/js/makegrid.js +++ b/js/makegrid.js @@ -795,7 +795,7 @@ function PMA_makegrid(t, enableResize, enableReorder, enableVisib, enableGridEdi } // if the select/editor is changed un-check the 'checkbox_null__'. - if ($td.is('.enum, .set:not(.truncated)')) { + if ($td.is('.enum, .set')) { $editArea.on('change', 'select', function (e) { $checkbox.prop('checked', false); }); @@ -925,7 +925,7 @@ function PMA_makegrid(t, enableResize, enableReorder, enableVisib, enableGridEdi $(g.cEdit).find('.edit_box').val($(this).val()); }); } - else if ($td.is('.set:not(.truncated)')) { + else if ($td.is('.set')) { //handle set fields $editArea.addClass('edit_area_loading'); @@ -943,6 +943,12 @@ function PMA_makegrid(t, enableResize, enableReorder, enableVisib, enableGridEdi 'curr_value' : curr_value }; + // if the data is truncated, get the full data + if ($td.is('.truncated')) { + post_params.get_full_values = true; + post_params.where_clause = PMA_urldecode(where_clause); + } + g.lastXHR = $.post('sql.php', post_params, function (data) { g.lastXHR = null; $editArea.removeClass('edit_area_loading'); @@ -1411,7 +1417,7 @@ function PMA_makegrid(t, enableResize, enableReorder, enableVisib, enableGridEdi } else { if ($this_field.is('.bit')) { this_field_params[field_name] = $(g.cEdit).find('.edit_box').val(); - } else if ($this_field.is('.set:not(.truncated)')) { + } else if ($this_field.is('.set')) { $test_element = $(g.cEdit).find('select'); this_field_params[field_name] = $test_element.map(function () { return $(this).val(); diff --git a/libraries/sql.lib.php b/libraries/sql.lib.php index aec8c8bda3..352800985b 100644 --- a/libraries/sql.lib.php +++ b/libraries/sql.lib.php @@ -396,6 +396,24 @@ function PMA_getHtmlForEnumColumnDropdown($db, $table, $column, $curr_value) return $dropdown; } +/** + * Get value of a column for a specific row (marked by $where_clause) + * + * @param string $db current database + * @param string $table current table + * @param string $column current column + * @param string $where_clause where clause to select a particular row + * + */ +function PMA_getFullValuesForSetColumn($db, $table, $column, $where_clause) +{ + $result = $GLOBALS['dbi']->fetchSingleRow( + "SELECT `$column` FROM `$db`.`$table` WHERE $where_clause" + ); + + return $result[$column]; +} + /** * Get the HTML for the set column dropdown * During grid edit, if we have a set field, returns the html for the @@ -412,6 +430,18 @@ function PMA_getHtmlForSetColumn($db, $table, $column, $curr_value) { $values = PMA_getValuesForColumn($db, $table, $column); $dropdown = ''; + $full_values = + isset($_REQUEST['get_full_values']) ? $_REQUEST['get_full_values'] : false; + $where_clause = + isset($_REQUEST['where_clause']) ? $_REQUEST['where_clause'] : null; + + // If the $curr_value was truncated, we should + // fetch the correct full values from the table + if ($full_values && ! empty($where_clause)) { + $curr_value = PMA_getFullValuesForSetColumn( + $db, $table, $column, $where_clause + ); + } //converts characters of $curr_value to HTML entities $converted_curr_value = htmlentities( @@ -419,6 +449,7 @@ function PMA_getHtmlForSetColumn($db, $table, $column, $curr_value) ); $selected_values = explode(',', $converted_curr_value); + $dropdown .= PMA_getHtmlForOptionsList($values, $selected_values); $select_size = (sizeof($values) > 10) ? 10 : sizeof($values); @@ -818,7 +849,9 @@ function PMA_getEnumOrSetValues($db, $table, $columnType) ); $response->addJSON('dropdown', $dropdown); } else { - $select = PMA_getHtmlForSetColumn($db, $table, $column, $curr_value); + $select = PMA_getHtmlForSetColumn( + $db, $table, $column, $curr_value + ); $response->addJSON('select', $select); } exit;