From 30c9b2d066716c27832369160f70d1b2543bdfa6 Mon Sep 17 00:00:00 2001 From: Deven Bansod Date: Thu, 28 May 2015 05:05:21 +0530 Subject: [PATCH 1/6] RFE#726 - Batch changing column collations Signed-off-by: Deven Bansod --- js/messages.php | 10 ++++++++++ js/tbl_operations.js | 27 +++++++++++++++++++++++++-- libraries/operations.lib.php | 33 +++++++++++++++++++++++++++++++++ tbl_operations.php | 10 ++++++++++ 4 files changed, 78 insertions(+), 2 deletions(-) diff --git a/js/messages.php b/js/messages.php index 81a58304d5..fe15a0f43f 100644 --- a/js/messages.php +++ b/js/messages.php @@ -73,6 +73,16 @@ $js_messages['strChangeColumnCollation'] = __( . '' . __('Garbled Data') . '.' . '

' . __('Are you sure you wish to change the collation and convert the data?'); +$js_messages['strChangeAllColumnCollationsWarning'] = __( + 'Through this operation, MySQL attempts to map the data values between collations. ' + . 'If the character sets are incompatible, ' + . 'there may be data loss and this lost data may NOT be recoverable simply ' + . 'by changing back the column collation(s).' + . ' To convert existing data, it is suggested to use the column(s) editing feature ' + . '(the "Change" Link) on the table structure page. ' +) +. '

' +. __('Are you sure you wish to change all the column collations and convert the data?'); /* For modal dialog buttons */ $js_messages['strSaveAndClose'] = __('Save & Close'); diff --git a/js/tbl_operations.js b/js/tbl_operations.js index 9665eb2d9b..781f0d5b83 100644 --- a/js/tbl_operations.js +++ b/js/tbl_operations.js @@ -78,10 +78,35 @@ AJAX.registerOnload('tbl_operations.js', function () { event.stopPropagation(); var $form = $(this); var $tblNameField = $form.find('input[name=new_name]'); + var $tblCollationField = $form.find('select[name=tbl_collation]'); + var collationOrigValue = $('select[name="tbl_collation"] option[selected]').val(); + var $changeAllColumnCollationsCheckBox = $('#checkbox_change_all_collations'); + var question = PMA_messages.strChangeAllColumnCollationsWarning; + if ($tblNameField.val() !== $tblNameField[0].defaultValue) { // reload page and navigation if the table has been renamed PMA_prepareForAjaxRequest($form); var tbl = $tblNameField.val(); + + if ($tblCollationField.val() !== collationOrigValue && $changeAllColumnCollationsCheckBox.is(':checked')) { + $form.PMA_confirm(question, $form.attr('action'), function (url) { + submitOptionsForm(); + }); + } else { + submitOptionsForm(); + } + } else { + + if ($tblCollationField.val() !== collationOrigValue && $changeAllColumnCollationsCheckBox.is(':checked')) { + $form.PMA_confirm(question, $form.attr('action'), function (url) { + $form.removeClass('ajax').submit().addClass('ajax'); + }); + } else { + $form.removeClass('ajax').submit().addClass('ajax'); + } + } + + function submitOptionsForm() { $.post($form.attr('action'), $form.serialize(), function (data) { if (typeof data !== 'undefined' && data.success === true) { PMA_commonParams.set('table', tbl); @@ -93,8 +118,6 @@ AJAX.registerOnload('tbl_operations.js', function () { PMA_ajaxShowMessage(data.error, false); } }); // end $.post() - } else { - $form.removeClass('ajax').submit().addClass('ajax'); } }); diff --git a/libraries/operations.lib.php b/libraries/operations.lib.php index f6da1846a5..b1baf47675 100644 --- a/libraries/operations.lib.php +++ b/libraries/operations.lib.php @@ -981,6 +981,15 @@ function PMA_getTableOptionFieldset($comment, $tbl_collation, . '' . ''; + // Change all Column collations + $html_output .= '' + . '' + . '' + . ''; + if ($is_myisam_or_aria || $is_isam) { $html_output .= PMA_getHtmlForPackKeys($pack_keys); } // end if (MYISAM|ISAM) @@ -1904,6 +1913,30 @@ function PMA_AdjustPrivileges_copyTable($oldDb, $oldTable, $newDb, $newTable) } +/** + * Change all collations and character sets of all columns in table + * + * @param string $db Database name + * @param string $table Table name + * @param string $tbl_collation Collation Name + * + * @return void + */ +function PMA_changeAllColumnsCollation($db, $table, $tbl_collation) +{ + $GLOBALS['dbi']->selectDb($db); + + $change_all_collations_query = 'ALTER TABLE ' . $table + . ' CONVERT TO'; + + list($charset) = explode('_', $tbl_collation); + + $change_all_collations_query .= ' CHARACTER SET ' . $charset + . ($charset == $tbl_collation ? '' : ' COLLATE ' . $tbl_collation); + + $GLOBALS['dbi']->query($change_all_collations_query); +} + /** * Move or copy a table * diff --git a/tbl_operations.php b/tbl_operations.php index 686df60abf..ed99ceac46 100644 --- a/tbl_operations.php +++ b/tbl_operations.php @@ -178,6 +178,16 @@ if (isset($_REQUEST['submitoptions'])) { unset($table_alters); $warning_messages = PMA_getWarningMessagesArray(); } + + if (isset($_REQUEST['tbl_collation']) + && ! empty($_REQUEST['tbl_collation']) + && isset($_REQUEST['change_all_collations']) + && ! empty($_REQUEST['change_all_collations']) + ) { + PMA_changeAllColumnsCollation( + $GLOBALS['db'], $GLOBALS['table'], $_REQUEST['tbl_collation'] + ); + } } /** * Reordering the table has been requested by the user From 9e101a407d9ded90077c03e0bb86a4d05dfbe456 Mon Sep 17 00:00:00 2001 From: Marc Delisle Date: Tue, 9 Jun 2015 07:50:01 -0400 Subject: [PATCH 2/6] Fix implicit conversion Signed-off-by: Marc Delisle --- libraries/Console.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/Console.class.php b/libraries/Console.class.php index 1b3b86ccd6..4074effce1 100644 --- a/libraries/Console.class.php +++ b/libraries/Console.class.php @@ -164,7 +164,7 @@ class PMA_Console $output = ''; $_sql_history = PMA_getHistory($GLOBALS['cfg']['Server']['user']); - if ($_sql_history) { + if (! empty($_sql_history)) { foreach (array_reverse($_sql_history) as $record) { $isSelect = preg_match( '@^SELECT[[:space:]]+@i', $record['sqlquery'] From a37b8fc79c3078716a228ece472558bdebeb1ec1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=B8rge=20Holm-Wennberg?= Date: Tue, 9 Jun 2015 13:19:44 +0200 Subject: [PATCH 3/6] =?UTF-8?q?Translated=20using=20Weblate=20(Norwegian?= =?UTF-8?q?=20Bokm=C3=A5l)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently translated at 60.0% (1865 of 3107 strings) [CI skip] --- po/nb.po | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/po/nb.po b/po/nb.po index 946c810722..8c462a3a62 100644 --- a/po/nb.po +++ b/po/nb.po @@ -4,8 +4,8 @@ msgstr "" "Project-Id-Version: phpMyAdmin 4.5.0-dev\n" "Report-Msgid-Bugs-To: phpmyadmin-devel@lists.sourceforge.net\n" "POT-Creation-Date: 2015-05-31 07:27-0400\n" -"PO-Revision-Date: 2015-06-04 19:48+0200\n" -"Last-Translator: Kurt Eilertsen \n" +"PO-Revision-Date: 2015-06-09 13:19+0200\n" +"Last-Translator: Børge Holm-Wennberg \n" "Language-Team: Norwegian Bokmål " "\n" "Language: nb\n" @@ -7563,7 +7563,7 @@ msgstr "" #: libraries/config/messages.inc.php:658 #: libraries/display_create_database.lib.php:31 msgid "Database name" -msgstr "Ddatabasenavn" +msgstr "Databasenavn" #: libraries/config/messages.inc.php:660 #, fuzzy From f215ba6e21c9088f80ee31996dea5e91aa82c586 Mon Sep 17 00:00:00 2001 From: Isaac Bennetch Date: Tue, 9 Jun 2015 08:32:49 -0400 Subject: [PATCH 4/6] ChangeLog for RFE 726 Signed-off-by: Isaac Bennetch --- ChangeLog | 1 + 1 file changed, 1 insertion(+) diff --git a/ChangeLog b/ChangeLog index efd612a7cb..69e7b8d8fb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -53,6 +53,7 @@ phpMyAdmin - ChangeLog + rfe Remove support for Shift + Click on function name to apply to all rows in insert/edit page + rfe #1634 Don't group tables in tree if the result has only one group - bug #4946 When hide table structure actions is false, action should be in a row ++ rfe #726 Batch changing the collation of each column in a table 4.4.10.0 (not yet released) - bug #4950 Issues in database selection for replication From 37df4b7715c285fc2aabe03c79fba801e4627c1e Mon Sep 17 00:00:00 2001 From: Marc Delisle Date: Tue, 9 Jun 2015 17:08:14 -0400 Subject: [PATCH 5/6] Fix loose comparison Signed-off-by: Marc Delisle --- libraries/insert_edit.lib.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libraries/insert_edit.lib.php b/libraries/insert_edit.lib.php index ec805ab8b9..e29fb5f75a 100644 --- a/libraries/insert_edit.lib.php +++ b/libraries/insert_edit.lib.php @@ -1497,10 +1497,11 @@ function PMA_getAfterInsertDropDown($where_clause, $after_insert, $found_unique_ $where_clause = array($where_clause); } for ($i = 0, $nb = count($where_clause); $i < $nb; $i++) { - $is_numeric = preg_match( + // preg_match() returns 1 if there is a match + $is_numeric = (preg_match( '@^[\s]*`[^`]*`[\.]`[^`]*` = [0-9]+@', $where_clause[$i] - ); + ) == 1); if ($is_numeric == true) { break; } From 0eb78a8ff2f04bdbe1dcf3f51d070cdc70635af1 Mon Sep 17 00:00:00 2001 From: Marc Delisle Date: Tue, 9 Jun 2015 17:22:34 -0400 Subject: [PATCH 6/6] Use strict comparison Signed-off-by: Marc Delisle --- libraries/insert_edit.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/insert_edit.lib.php b/libraries/insert_edit.lib.php index e29fb5f75a..f2394e82c3 100644 --- a/libraries/insert_edit.lib.php +++ b/libraries/insert_edit.lib.php @@ -1502,7 +1502,7 @@ function PMA_getAfterInsertDropDown($where_clause, $after_insert, $found_unique_ '@^[\s]*`[^`]*`[\.]`[^`]*` = [0-9]+@', $where_clause[$i] ) == 1); - if ($is_numeric == true) { + if ($is_numeric === true) { break; } }