diff --git a/ChangeLog b/ChangeLog index 021ce732c..889ae657d 100755 --- a/ChangeLog +++ b/ChangeLog @@ -7,8 +7,10 @@ $Source$ 2004-04-17 Alexander M. Turek * db_create.php, db_details_structure.php, db_details_common.php, main.php, - libraries/mysql_charsets.lib.php: - Added ability to set / alter collations on database level. + tbl_alter.php, tbl_create.php, tbl_properties.inc.php, + tbl_properties_operations.php, tbl_properties_structure.php, + tbl_properties_table_info.php, libraries/mysql_charsets.lib.php: + Added ability to set / alter collations for databases, tables and fields. * tbl_alter.php: Charset information got lost when changing fields. 2004-04-16 Marc Delisle diff --git a/db_create.php b/db_create.php index 653dbf71a..c2c25dc00 100644 --- a/db_create.php +++ b/db_create.php @@ -27,7 +27,7 @@ $sql_query = 'CREATE DATABASE ' . PMA_backquote($db); if (!empty($db_collation) && PMA_MYSQL_INT_VERSION >= 40101) { list($db_charset) = explode('_', $db_collation); if (in_array($db_charset, $mysql_charsets) && in_array($db_collation, $mysql_collations[$db_charset])) { - $sql_query .= ' DEFAULT CHARACTER SET ' . $db_charset . ($db_charset == $db_collation ? '' : ' COLLATE ' . $db_collation); + $sql_query .= ' DEFAULT' . PMA_generateCharsetQueryPart($db_collation); } unset($db_charset, $db_collation); } diff --git a/db_details_common.php b/db_details_common.php index 643710e4d..151d9c8c3 100644 --- a/db_details_common.php +++ b/db_details_common.php @@ -38,7 +38,7 @@ if (!isset($is_db) || !$is_db) { */ if (isset($submitcollation) && !empty($db_collation) && PMA_MYSQL_INT_VERSION >= 40101) { list($db_charset) = explode('_', $db_collation); - $sql_query = 'ALTER DATABASE ' . PMA_backquote($db) . ' DEFAULT CHARACTER SET ' . $db_charset . ($db_charset == $db_collation ? '' : ' COLLATE ' . $db_collation); + $sql_query = 'ALTER DATABASE ' . PMA_backquote($db) . ' DEFAULT' . PMA_generateCharsetQueryPart($db_collation); $result = PMA_DBI_query($sql_query); $message = $strSuccess; unset($db_charset, $db_collation); diff --git a/db_details_structure.php b/db_details_structure.php index 7a6387759..bf205a74d 100644 --- a/db_details_structure.php +++ b/db_details_structure.php @@ -705,9 +705,9 @@ if (PMA_MYSQL_INT_VERSION >= 40101) { . '
  • ' . "\n" . '
    ' . "\n" . PMA_generate_common_hidden_inputs($db, $table, 3) - . '  : ' . "\n"; - PMA_printCharsetDropdownBox(PMA_CSDROPDOWN_COLLATION, 'db_collation', 'select_db_collation', $db_collation, FALSE, 3); - echo '  ' . "\n" + . '  : ' . "\n" + . PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_COLLATION, 'db_collation', 'select_db_collation', $db_collation, FALSE, 3) + . '  ' . "\n" . '
    ' . "\n" . '
  • ' . "\n\n"; } diff --git a/libraries/mysql_charsets.lib.php b/libraries/mysql_charsets.lib.php index db02d5674..8a0b4c59a 100644 --- a/libraries/mysql_charsets.lib.php +++ b/libraries/mysql_charsets.lib.php @@ -255,7 +255,7 @@ if (PMA_MYSQL_INT_VERSION >= 40100){ define('PMA_CSDROPDOWN_COLLATION', 0); define('PMA_CSDROPDOWN_CHARSET', 1); - function PMA_printCharsetDropdownBox($type = PMA_CSDROPDOWN_COLLATION, $name = NULL, $id = NULL, $default = NULL, $label = TRUE, $indent = 0) { + function PMA_generateCharsetDropdownBox($type = PMA_CSDROPDOWN_COLLATION, $name = NULL, $id = NULL, $default = NULL, $label = TRUE, $indent = 0) { global $mysql_charsets, $mysql_charsets_descriptions, $mysql_collations; if (empty($name)) { @@ -265,27 +265,35 @@ if (PMA_MYSQL_INT_VERSION >= 40100){ $name = 'character_set'; } } + $spacer = ''; for ($i = 1; $i <= $indent; $i++) $spacer .= ' '; - - echo $spacer . '' . "\n"; if ($label) { - echo $spacer . ' ' . "\n"; + $return_str .= $spacer . ' ' . "\n"; } - echo $spacer . ' ' . "\n"; + $return_str .= $spacer . ' ' . "\n"; foreach ($mysql_charsets as $current_charset) { $current_cs_descr = empty($mysql_charsets_descriptions[$current_charset]) ? $current_charset : $mysql_charsets_descriptions[$current_charset]; - if ($type == CS_DROPDOWN_COLLATION) { - echo $spacer . ' ' . "\n"; + if ($type == PMA_CSDROPDOWN_COLLATION) { + $return_str .= $spacer . ' ' . "\n"; foreach ($mysql_collations[$current_charset] as $current_collation) { - echo $spacer . ' ' . "\n"; + $return_str .= $spacer . ' ' . "\n"; } - echo $spacer . ' ' . "\n"; + $return_str .= $spacer . ' ' . "\n"; } else { - echo $spacer . ' ' . "\n"; + $return_str .= $spacer . ' ' . "\n"; } } - echo $spacer . '' . "\n"; + $return_str .= $spacer . '' . "\n"; + + return $return_str; + } + + function PMA_generateCharsetQueryPart($collation) { + list($charset) = explode('_', $collation); + return ' CHARACTER SET ' . $charset . ($charset == $collation ? '' : ' COLLATE ' . $collation); } } diff --git a/main.php b/main.php index e102e552d..75e534999 100644 --- a/main.php +++ b/main.php @@ -305,7 +305,7 @@ if ($server > 0) { . ' ' . "\n"; if (PMA_MYSQL_INT_VERSION >= 40101) { require_once('./libraries/mysql_charsets.lib.php'); - PMA_printCharsetDropdownBox(PMA_CSDROPDOWN_COLLATION, 'db_collation', NULL, NULL, TRUE, 5); + echo PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_COLLATION, 'db_collation', NULL, NULL, TRUE, 5); } echo ' ' . "\n" . ' ' . "\n" diff --git a/tbl_alter.php b/tbl_alter.php index a10c2991d..4b12c848f 100644 --- a/tbl_alter.php +++ b/tbl_alter.php @@ -52,8 +52,8 @@ if (isset($submit)) { } if ($field_attribute[$i] != '') { $query .= ' ' . $field_attribute[$i]; - } else if (PMA_MYSQL_INT_VERSION >= 40100 && $field_charset[$i] != '') { - $query .= ' CHARACTER SET ' . $field_charset[$i]; + } else if (PMA_MYSQL_INT_VERSION >= 40100 && $field_collation[$i] != '') { + $query .= PMA_generateCharsetQueryPart($field_collation[$i]); } if ($field_default[$i] != '') { if (strtoupper($field_default[$i]) == 'NULL') { diff --git a/tbl_create.php b/tbl_create.php index b29798728..e47d2c737 100644 --- a/tbl_create.php +++ b/tbl_create.php @@ -61,8 +61,8 @@ if (isset($submit)) { } if ($field_attribute[$i] != '') { $query .= ' ' . $field_attribute[$i]; - } else if (PMA_MYSQL_INT_VERSION >= 40100 && !empty($field_charset[$i])) { - $query .= ' CHARACTER SET ' . $field_charset[$i]; + } else if (PMA_MYSQL_INT_VERSION >= 40100 && !empty($field_collation[$i])) { + $query .= PMA_generateCharsetQueryPart($field_collation[$i]); } if ($field_default[$i] != '') { if (strtoupper($field_default[$i]) == 'NULL') { @@ -163,9 +163,9 @@ if (isset($submit)) { $sql_query .= ' TYPE = ' . $tbl_type; $query_cpy .= "\n" . 'TYPE = ' . $tbl_type; } - if (PMA_MYSQL_INT_VERSION >= 40100 && !empty($tbl_charset)) { - $sql_query .= ' CHARACTER SET = ' . $tbl_charset; - $query_cpy .= "\n" . 'CHARACTER SET = ' . $tbl_charset; + if (PMA_MYSQL_INT_VERSION >= 40100 && !empty($tbl_collation)) { + $sql_query .= PMA_generateCharsetQueryPart($tbl_collation); + $query_cpy .= "\n" . PMA_generateCharsetQueryPart($tbl_collation); } if (!empty($comment)) { diff --git a/tbl_properties.inc.php b/tbl_properties.inc.php index 463bb8947..284b8c543 100644 --- a/tbl_properties.inc.php +++ b/tbl_properties.inc.php @@ -85,7 +85,7 @@ $header_cells[] = $strField; $header_cells[] = $strType . '
    ' . PMA_showMySQLDocu('Reference', 'Column_types') . ''; $header_cells[] = $strLengthSet; if (PMA_MYSQL_INT_VERSION >= 40100) { - $header_cells[] = $strCharset; + $header_cells[] = $strCollation; } $header_cells[] = $strAttr; $header_cells[] = $strNull; @@ -230,7 +230,8 @@ for ($i = 0 ; $i < $num_fields; $i++) { } // end if else // some types, for example longtext, are reported as - // "longtext character set latin7" when not latin1 + // "longtext character set latin7" when their charset and / or collation + // differs from the ones of the corresponding database. if (PMA_MYSQL_INT_VERSION >= 40100) { $tmp = strpos($type, 'character set'); if ($tmp) { @@ -274,28 +275,9 @@ for ($i = 0 ; $i < $num_fields; $i++) { } if (PMA_MYSQL_INT_VERSION >= 40100) { - $content_cells[$i][$ci] = '' . "\n"; + $tmp_collation = empty($row['Collation']) ? NULL : $row['Collation']; + $content_cells[$i][$ci] = PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_COLLATION, 'field_collation[]', 'field_' . $i . '_' . ($ci - $ci_offset), $tmp_collation, FALSE); + unset($tmp_collation); $ci++; } @@ -543,7 +525,7 @@ if ($action == 'tbl_create.php') { = 40100) { echo '  ' . "\n" - . ' ' . $strCharset . ' :' . "\n"; + . ' ' . $strCollation . ' :' . "\n"; } } echo "\n"; @@ -608,12 +590,7 @@ if ($action == 'tbl_create.php') { if (PMA_MYSQL_INT_VERSION >= 40100) { echo '  ' . "\n" . ' ' . "\n" - . ' ' . "\n" + . PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_COLLATION, 'tbl_collation', NULL, NULL, FALSE, 3) . ' ' . "\n"; } } diff --git a/tbl_properties_operations.php b/tbl_properties_operations.php index 093bb82b3..71fa027f6 100644 --- a/tbl_properties_operations.php +++ b/tbl_properties_operations.php @@ -37,10 +37,11 @@ if (isset($submittype)) { $result = PMA_DBI_query($sql_query); $message = $strSuccess; } -if (isset($submitcharset)) { - $sql_query = 'ALTER TABLE ' . PMA_backquote($table) . ' DEFAULT CHARACTER SET = ' . $tbl_charset; +if (isset($submitcollation)) { + $sql_query = 'ALTER TABLE ' . PMA_backquote($table) . ' DEFAULT' . PMA_generateCharsetQueryPart($tbl_collation); $result = PMA_DBI_query($sql_query); $message = $strSuccess; + unset($tbl_collation); } if (isset($submitoptions)) { $sql_query = 'ALTER TABLE ' . PMA_backquote($table) @@ -451,16 +452,9 @@ if ($cfgRelation['relwork'] && $tbl_type != "INNODB") { . '
  • ' . "\n" . '
    ' . "\n" . PMA_generate_common_hidden_inputs($db, $table, 3) - . ' ' . $strCharset . ' : ' . "\n" - . '  ' . "\n" - . '  ' . "\n" + . ' ' . $strCollation . ' : ' . "\n" + . PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_COLLATION, 'tbl_collation', NULL, $tbl_collation, FALSE, 3) + . '  ' . "\n" . '
    ' . "\n" . '
  • ' . "\n"; } diff --git a/tbl_properties_structure.php b/tbl_properties_structure.php index 1c09611a3..c21c787b9 100644 --- a/tbl_properties_structure.php +++ b/tbl_properties_structure.php @@ -599,7 +599,7 @@ if ($cfg['ShowStats']) { ' . $tbl_charset . ''; + echo '' . $tbl_collation . ''; ?> diff --git a/tbl_properties_table_info.php b/tbl_properties_table_info.php index 5cc062e3f..c6f537331 100644 --- a/tbl_properties_table_info.php +++ b/tbl_properties_table_info.php @@ -18,7 +18,7 @@ PMA_checkParameters(array('db', 'table')); $table_info_result = PMA_DBI_query('SHOW TABLE STATUS LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\';'); $showtable = PMA_DBI_fetch_assoc($table_info_result); $tbl_type = strtoupper($showtable['Type']); -$tbl_charset = empty($showtable['Collation']) ? '' : $showtable['Collation']; +$tbl_collation = empty($showtable['Collation']) ? '' : $showtable['Collation']; $table_info_num_rows = (isset($showtable['Rows']) ? $showtable['Rows'] : 0); $show_comment = (isset($showtable['Comment']) ? $showtable['Comment'] : ''); $auto_increment = (isset($showtable['Auto_increment']) ? $showtable['Auto_increment'] : '');