diff options
-rwxr-xr-x | ChangeLog | 6 | ||||
-rw-r--r-- | db_create.php | 2 | ||||
-rw-r--r-- | db_details_common.php | 2 | ||||
-rw-r--r-- | db_details_structure.php | 6 | ||||
-rw-r--r-- | libraries/mysql_charsets.lib.php | 30 | ||||
-rw-r--r-- | main.php | 2 | ||||
-rw-r--r-- | tbl_alter.php | 4 | ||||
-rw-r--r-- | tbl_create.php | 10 | ||||
-rw-r--r-- | tbl_properties.inc.php | 39 | ||||
-rw-r--r-- | tbl_properties_operations.php | 18 | ||||
-rw-r--r-- | tbl_properties_structure.php | 2 | ||||
-rw-r--r-- | tbl_properties_table_info.php | 2 |
12 files changed, 52 insertions, 71 deletions
@@ -7,8 +7,10 @@ $Source$ 2004-04-17 Alexander M. Turek <me@derrabus.de> * 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 <lem9@users.sourceforge.net> diff --git a/db_create.php b/db_create.php index 653dbf71ac..c2c25dc00c 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 643710e4d2..151d9c8c3c 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 7a63877591..bf205a74de 100644 --- a/db_details_structure.php +++ b/db_details_structure.php @@ -705,9 +705,9 @@ if (PMA_MYSQL_INT_VERSION >= 40101) { . ' <li>' . "\n" . ' <form method="post" action="./db_details_structure.php">' . "\n" . PMA_generate_common_hidden_inputs($db, $table, 3) - . ' <label for="select_db_collation">' . $strCollation . '</label> : ' . "\n"; - PMA_printCharsetDropdownBox(PMA_CSDROPDOWN_COLLATION, 'db_collation', 'select_db_collation', $db_collation, FALSE, 3); - echo ' <input type="submit" name="submitcollation" value="' . $strGo . '" style="vertical-align: middle" /> ' . "\n" + . ' <label for="select_db_collation">' . $strCollation . '</label> : ' . "\n" + . PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_COLLATION, 'db_collation', 'select_db_collation', $db_collation, FALSE, 3) + . ' <input type="submit" name="submitcollation" value="' . $strGo . '" style="vertical-align: middle" /> ' . "\n" . ' </form>' . "\n" . ' </li>' . "\n\n"; } diff --git a/libraries/mysql_charsets.lib.php b/libraries/mysql_charsets.lib.php index db02d5674b..8a0b4c59aa 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 . '<select name="' . htmlspecialchars($name) . '"' . (empty($id) ? '' : ' id="' . htmlspecialchars($id) . '"') . '>' . "\n"; + + $return_str = $spacer . '<select name="' . htmlspecialchars($name) . '"' . (empty($id) ? '' : ' id="' . htmlspecialchars($id) . '"') . '>' . "\n"; if ($label) { - echo $spacer . ' <option value="">' . ($ype == PMA_CSDROPDOWN_COLLATION ? $GLOBALS['strCollation'] : $GLOBALS['strCharset']) . '</option>' . "\n"; + $return_str .= $spacer . ' <option value="">' . ($ype == PMA_CSDROPDOWN_COLLATION ? $GLOBALS['strCollation'] : $GLOBALS['strCharset']) . '</option>' . "\n"; } - echo $spacer . ' <option value=""></option>' . "\n"; + $return_str .= $spacer . ' <option value=""></option>' . "\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 . ' <optgroup label="' . $current_charset . '" title="' . $current_cs_descr . '">' . "\n"; + if ($type == PMA_CSDROPDOWN_COLLATION) { + $return_str .= $spacer . ' <optgroup label="' . $current_charset . '" title="' . $current_cs_descr . '">' . "\n"; foreach ($mysql_collations[$current_charset] as $current_collation) { - echo $spacer . ' <option value="' . $current_collation . '" title="' . PMA_getCollationDescr($current_collation) . '"' . ($default == $current_collation ? ' selected="selected"' : '') . '>' . $current_collation . '</option>' . "\n"; + $return_str .= $spacer . ' <option value="' . $current_collation . '" title="' . PMA_getCollationDescr($current_collation) . '"' . ($default == $current_collation ? ' selected="selected"' : '') . '>' . $current_collation . '</option>' . "\n"; } - echo $spacer . ' </optgroup>' . "\n"; + $return_str .= $spacer . ' </optgroup>' . "\n"; } else { - echo $spacer . ' <option value="' . $current_charset . '" title="' . $current_cs_descr . '"' . ($default == $current_charset ? ' selected="selected"' : '') . '>' . $current_charset . '</option>' . "\n"; + $return_str .= $spacer . ' <option value="' . $current_charset . '" title="' . $current_cs_descr . '"' . ($default == $current_charset ? ' selected="selected"' : '') . '>' . $current_charset . '</option>' . "\n"; } } - echo $spacer . '</select>' . "\n"; + $return_str .= $spacer . '</select>' . "\n"; + + return $return_str; + } + + function PMA_generateCharsetQueryPart($collation) { + list($charset) = explode('_', $collation); + return ' CHARACTER SET ' . $charset . ($charset == $collation ? '' : ' COLLATE ' . $collation); } } @@ -305,7 +305,7 @@ if ($server > 0) { . ' <input type="text" name="db" value="' . $db_to_create . '" maxlength="64" class="textfield" />' . "\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 ' <input type="submit" value="' . $strCreate . '" />' . "\n" . ' </form>' . "\n" diff --git a/tbl_alter.php b/tbl_alter.php index a10c2991df..4b12c848fe 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 b29798728a..e47d2c7371 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 463bb8947c..284b8c543b 100644 --- a/tbl_properties.inc.php +++ b/tbl_properties.inc.php @@ -85,7 +85,7 @@ $header_cells[] = $strField; $header_cells[] = $strType . '<br /><span style="font-weight: normal">' . PMA_showMySQLDocu('Reference', 'Column_types') . '</span>'; $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] = '<select name="field_charset[]" id="field_' . $i . '_' . ($ci - $ci_offset) . '">' . "\n" - . ' <option value=""></option>' . "\n"; - if (!empty($row['Collation']) && ( - strtolower(substr($type, 0, 4)) == 'char' - || strtolower(substr($type, 0, 7)) == 'varchar' - || strtolower(substr($type, 0, 4)) == 'text' - || strtolower(substr($type, 0, 8)) == 'tinytext' - || strtolower(substr($type, 0, 10)) == 'mediumtext' - || strtolower(substr($type, 0, 8)) == 'longtext' - || strtolower(substr($type, 0, 3)) == 'set' - || strtolower(substr($type, 0, 4)) == 'enum' - ) && !$binary) { - $real_charset = strpos($row['Collation'], '_') ? substr($row['Collation'], 0, strpos($row['Collation'], '_')) : $row['Collation']; - } else { - $real_charset = ''; - } - for ($j = 0; isset($mysql_charsets[$j]); $j++) { - $content_cells[$i][$ci] .= ' <option value="' . $mysql_charsets[$j] . '"' . ($mysql_charsets[$j] == $real_charset ? ' selected="selected"' : '') . '>' . $mysql_charsets[$j] . '</option>' . "\n"; - } - unset($j); - unset($real_charset); - $content_cells[$i][$ci] .= '</select>' . "\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') { <?php if (PMA_MYSQL_INT_VERSION >= 40100) { echo ' <td width="25"> </td>' . "\n" - . ' <td>' . $strCharset . ' :</td>' . "\n"; + . ' <td>' . $strCollation . ' :</td>' . "\n"; } } echo "\n"; @@ -608,12 +590,7 @@ if ($action == 'tbl_create.php') { if (PMA_MYSQL_INT_VERSION >= 40100) { echo ' <td width="25"> </td>' . "\n" . ' <td>' . "\n" - . ' <select name="tbl_charset">' . "\n"; - for ($i = 0; isset($mysql_charsets[$i]); $i++) { - echo ' <option value="' . $mysql_charsets[$i] . '"' . ($mysql_charsets[$i] == 'latin1' ? ' selected="selected"' : '') . '>' . $mysql_charsets[$i] . '</option>' . "\n"; - } - unset($i); - echo ' </select>' . "\n" + . PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_COLLATION, 'tbl_collation', NULL, NULL, FALSE, 3) . ' </td>' . "\n"; } } diff --git a/tbl_properties_operations.php b/tbl_properties_operations.php index 093bb82b3a..71fa027f6f 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") { . ' <li>' . "\n" . ' <form method="post" action="tbl_properties_operations.php">' . "\n" . PMA_generate_common_hidden_inputs($db, $table, 3) - . ' ' . $strCharset . ' : ' . "\n" - . ' <select name="tbl_charset" style="vertical-align: middle">' . "\n"; - $real_charset = strpos($tbl_charset, '_') ? substr($tbl_charset, 0, strpos($tbl_charset, '_')) : $tbl_charset; - for ($i = 1; isset($mysql_charsets[$i]); $i++) { - echo ' <option value="' . $mysql_charsets[$i] . '"' . ($mysql_charsets[$i] == $real_charset ? ' selected="selected"' : '') . '>' . $mysql_charsets[$i] . '</option>' . "\n"; - } - unset($i); - unset($real_charset); - echo ' </select> ' . "\n" - . ' <input type="submit" name="submitcharset" value="' . $strGo . '" style="vertical-align: middle" /> ' . "\n" + . ' ' . $strCollation . ' : ' . "\n" + . PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_COLLATION, 'tbl_collation', NULL, $tbl_collation, FALSE, 3) + . ' <input type="submit" name="submitcollation" value="' . $strGo . '" style="vertical-align: middle" /> ' . "\n" . ' </form>' . "\n" . ' </li>' . "\n"; } diff --git a/tbl_properties_structure.php b/tbl_properties_structure.php index 1c09611a37..c21c787b92 100644 --- a/tbl_properties_structure.php +++ b/tbl_properties_structure.php @@ -599,7 +599,7 @@ if ($cfg['ShowStats']) { <td bgcolor="<?php echo $bgcolor; ?>"><?php echo $strCollation; ?></td> <td bgcolor="<?php echo $bgcolor; ?>" align="<?php echo $cell_align_left; ?>" nowrap="nowrap"> <?php - echo '<dfn title="' . PMA_getCollationDescr($tbl_charset) . '">' . $tbl_charset . '</dfn>'; + echo '<dfn title="' . PMA_getCollationDescr($tbl_collation) . '">' . $tbl_collation . '</dfn>'; ?> </td> </tr> diff --git a/tbl_properties_table_info.php b/tbl_properties_table_info.php index 5cc062e3fb..c6f5373319 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'] : ''); |