diff --git a/js/makegrid.js b/js/makegrid.js index 66922efff4..3c4e27802f 100644 --- a/js/makegrid.js +++ b/js/makegrid.js @@ -1193,7 +1193,7 @@ function PMA_makegrid(t, enableResize, enableReorder, enableVisib, enableGridEdi if(data.success == true) { PMA_ajaxShowMessage(data.message); - // Generate new where clause again if the field + // Generate new where clause again if the column // can be truncated by MySQL and table does not have // primary/unique key if (data.isTruncatableField && !data.hasUniqueIdentifier) { diff --git a/tbl_replace.php b/tbl_replace.php index 4abaa1f281..5141a1310d 100644 --- a/tbl_replace.php +++ b/tbl_replace.php @@ -573,32 +573,9 @@ if ($GLOBALS['is_ajax_request'] == true) { $column_value = $_REQUEST['fields']['multi_edit'][0][0]; $column_meta_data = PMA_DBI_get_columns($db, $table, $column_name); - if (stripos($column_meta_data['Type'], 'smallint') !== false) { - - $extra_data['isTruncatableField'] = true; - $extra_data['hasUniqueIdentifier'] = hasPrimaryKeyOrUniqueKey($db, $table) - ? true - : false; - - // If table has unique identifier (primary/unique key), fetch the value - // of the field. (Yes, can be just round and return, but better need to - // retrieve the value really saved in the database when it is possible) - if ($extra_data['hasUniqueIdentifier']) { - - $sql_for_real_value = 'SELECT '. PMA_backquote($table) . '.' . PMA_backquote($column_name) - . ' FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) - . ' WHERE ' . $_REQUEST['where_clause'][0]; - - $extra_data['truncatableFieldValue'] = (PMA_DBI_fetch_value($sql_for_real_value) !== false) - ? PMA_DBI_fetch_value($sql_for_real_value) - : round($column_value); - - } else { - $extra_data['truncatableFieldValue'] = round($column_value); - } - - } - + PMA_verifyWhetherValueCanBeTruncatedAndAppendExtraData( + $db, $table, $column_name, $column_value, $column_meta_data, $extra_data + ); /**Get the total row count of the table*/ $extra_data['row_count'] = PMA_Table::countRecords($_REQUEST['db'], $_REQUEST['table']); @@ -647,7 +624,7 @@ exit; * * @return boolean */ -function hasPrimaryKeyOrUniqueKey($db, $table) { +function PMA_hasPrimaryKeyOrUniqueKey($db, $table) { $table_indexes = PMA_DBI_get_table_indexes($db, $table); @@ -661,4 +638,47 @@ function hasPrimaryKeyOrUniqueKey($db, $table) { } +/** + * Check whether inline edited value can be truncated or not, + * and add additional parameters for extra_data array if needed + * + * @param string $db Database name + * @param string $table Table name + * @param string $column_name Column name + * @param string $column_value Edited column value + * @param array $column_meta_data Column meta data + * @param array &$extra_data Extra data for ajax response + */ +function PMA_verifyWhetherValueCanBeTruncatedAndAppendExtraData( + $db, $table, $column_name, $column_value, $column_meta_data, &$extra_data +) { + + if (stripos($column_meta_data['Type'], 'smallint') !== false) { + + $extra_data['isTruncatableField'] = true; + $extra_data['hasUniqueIdentifier'] = PMA_hasPrimaryKeyOrUniqueKey($db, $table) + ? true + : false; + + // If table has unique identifier (primary/unique key), fetch the value + // of the field. (Yes, can be just round and return, but better need to + // retrieve the value really saved in the database when it is possible) + if ($extra_data['hasUniqueIdentifier']) { + + $sql_for_real_value = 'SELECT '. PMA_backquote($table) . '.' . PMA_backquote($column_name) + . ' FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) + . ' WHERE ' . $_REQUEST['where_clause'][0]; + + $extra_data['truncatableFieldValue'] = (PMA_DBI_fetch_value($sql_for_real_value) !== false) + ? PMA_DBI_fetch_value($sql_for_real_value) + : round($column_value); + + } else { + $extra_data['truncatableFieldValue'] = round($column_value); + } + + } + +} + ?>