more collation stuff

This commit is contained in:
Alexander M. Turek
2004-04-17 03:07:15 +00:00
parent 4f2be967ed
commit 860282b789
12 changed files with 52 additions and 71 deletions

View File

@@ -7,8 +7,10 @@ $Source$
2004-04-17 Alexander M. Turek <me@derrabus.de> 2004-04-17 Alexander M. Turek <me@derrabus.de>
* db_create.php, db_details_structure.php, db_details_common.php, main.php, * db_create.php, db_details_structure.php, db_details_common.php, main.php,
libraries/mysql_charsets.lib.php: tbl_alter.php, tbl_create.php, tbl_properties.inc.php,
Added ability to set / alter collations on database level. 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. * tbl_alter.php: Charset information got lost when changing fields.
2004-04-16 Marc Delisle <lem9@users.sourceforge.net> 2004-04-16 Marc Delisle <lem9@users.sourceforge.net>

View File

@@ -27,7 +27,7 @@ $sql_query = 'CREATE DATABASE ' . PMA_backquote($db);
if (!empty($db_collation) && PMA_MYSQL_INT_VERSION >= 40101) { if (!empty($db_collation) && PMA_MYSQL_INT_VERSION >= 40101) {
list($db_charset) = explode('_', $db_collation); list($db_charset) = explode('_', $db_collation);
if (in_array($db_charset, $mysql_charsets) && in_array($db_collation, $mysql_collations[$db_charset])) { 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); unset($db_charset, $db_collation);
} }

View File

@@ -38,7 +38,7 @@ if (!isset($is_db) || !$is_db) {
*/ */
if (isset($submitcollation) && !empty($db_collation) && PMA_MYSQL_INT_VERSION >= 40101) { if (isset($submitcollation) && !empty($db_collation) && PMA_MYSQL_INT_VERSION >= 40101) {
list($db_charset) = explode('_', $db_collation); 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); $result = PMA_DBI_query($sql_query);
$message = $strSuccess; $message = $strSuccess;
unset($db_charset, $db_collation); unset($db_charset, $db_collation);

View File

@@ -705,9 +705,9 @@ if (PMA_MYSQL_INT_VERSION >= 40101) {
. ' <li>' . "\n" . ' <li>' . "\n"
. ' <form method="post" action="./db_details_structure.php">' . "\n" . ' <form method="post" action="./db_details_structure.php">' . "\n"
. PMA_generate_common_hidden_inputs($db, $table, 3) . PMA_generate_common_hidden_inputs($db, $table, 3)
. ' <label for="select_db_collation">' . $strCollation . '</label>&nbsp;:&nbsp;' . "\n"; . ' <label for="select_db_collation">' . $strCollation . '</label>&nbsp;:&nbsp;' . "\n"
PMA_printCharsetDropdownBox(PMA_CSDROPDOWN_COLLATION, 'db_collation', 'select_db_collation', $db_collation, FALSE, 3); . PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_COLLATION, 'db_collation', 'select_db_collation', $db_collation, FALSE, 3)
echo ' <input type="submit" name="submitcollation" value="' . $strGo . '" style="vertical-align: middle" />&nbsp;' . "\n" . ' <input type="submit" name="submitcollation" value="' . $strGo . '" style="vertical-align: middle" />&nbsp;' . "\n"
. ' </form>' . "\n" . ' </form>' . "\n"
. ' </li>' . "\n\n"; . ' </li>' . "\n\n";
} }

View File

@@ -255,7 +255,7 @@ if (PMA_MYSQL_INT_VERSION >= 40100){
define('PMA_CSDROPDOWN_COLLATION', 0); define('PMA_CSDROPDOWN_COLLATION', 0);
define('PMA_CSDROPDOWN_CHARSET', 1); 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; global $mysql_charsets, $mysql_charsets_descriptions, $mysql_collations;
if (empty($name)) { if (empty($name)) {
@@ -265,27 +265,35 @@ if (PMA_MYSQL_INT_VERSION >= 40100){
$name = 'character_set'; $name = 'character_set';
} }
} }
$spacer = ''; $spacer = '';
for ($i = 1; $i <= $indent; $i++) $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) { 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) { foreach ($mysql_charsets as $current_charset) {
$current_cs_descr = empty($mysql_charsets_descriptions[$current_charset]) ? $current_charset : $mysql_charsets_descriptions[$current_charset]; $current_cs_descr = empty($mysql_charsets_descriptions[$current_charset]) ? $current_charset : $mysql_charsets_descriptions[$current_charset];
if ($type == CS_DROPDOWN_COLLATION) { if ($type == PMA_CSDROPDOWN_COLLATION) {
echo $spacer . ' <optgroup label="' . $current_charset . '" title="' . $current_cs_descr . '">' . "\n"; $return_str .= $spacer . ' <optgroup label="' . $current_charset . '" title="' . $current_cs_descr . '">' . "\n";
foreach ($mysql_collations[$current_charset] as $current_collation) { 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 { } 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);
} }
} }

View File

@@ -305,7 +305,7 @@ if ($server > 0) {
. ' <input type="text" name="db" value="' . $db_to_create . '" maxlength="64" class="textfield" />' . "\n"; . ' <input type="text" name="db" value="' . $db_to_create . '" maxlength="64" class="textfield" />' . "\n";
if (PMA_MYSQL_INT_VERSION >= 40101) { if (PMA_MYSQL_INT_VERSION >= 40101) {
require_once('./libraries/mysql_charsets.lib.php'); 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" echo ' <input type="submit" value="' . $strCreate . '" />' . "\n"
. ' </form>' . "\n" . ' </form>' . "\n"

View File

@@ -52,8 +52,8 @@ if (isset($submit)) {
} }
if ($field_attribute[$i] != '') { if ($field_attribute[$i] != '') {
$query .= ' ' . $field_attribute[$i]; $query .= ' ' . $field_attribute[$i];
} else if (PMA_MYSQL_INT_VERSION >= 40100 && $field_charset[$i] != '') { } else if (PMA_MYSQL_INT_VERSION >= 40100 && $field_collation[$i] != '') {
$query .= ' CHARACTER SET ' . $field_charset[$i]; $query .= PMA_generateCharsetQueryPart($field_collation[$i]);
} }
if ($field_default[$i] != '') { if ($field_default[$i] != '') {
if (strtoupper($field_default[$i]) == 'NULL') { if (strtoupper($field_default[$i]) == 'NULL') {

View File

@@ -61,8 +61,8 @@ if (isset($submit)) {
} }
if ($field_attribute[$i] != '') { if ($field_attribute[$i] != '') {
$query .= ' ' . $field_attribute[$i]; $query .= ' ' . $field_attribute[$i];
} else if (PMA_MYSQL_INT_VERSION >= 40100 && !empty($field_charset[$i])) { } else if (PMA_MYSQL_INT_VERSION >= 40100 && !empty($field_collation[$i])) {
$query .= ' CHARACTER SET ' . $field_charset[$i]; $query .= PMA_generateCharsetQueryPart($field_collation[$i]);
} }
if ($field_default[$i] != '') { if ($field_default[$i] != '') {
if (strtoupper($field_default[$i]) == 'NULL') { if (strtoupper($field_default[$i]) == 'NULL') {
@@ -163,9 +163,9 @@ if (isset($submit)) {
$sql_query .= ' TYPE = ' . $tbl_type; $sql_query .= ' TYPE = ' . $tbl_type;
$query_cpy .= "\n" . 'TYPE = ' . $tbl_type; $query_cpy .= "\n" . 'TYPE = ' . $tbl_type;
} }
if (PMA_MYSQL_INT_VERSION >= 40100 && !empty($tbl_charset)) { if (PMA_MYSQL_INT_VERSION >= 40100 && !empty($tbl_collation)) {
$sql_query .= ' CHARACTER SET = ' . $tbl_charset; $sql_query .= PMA_generateCharsetQueryPart($tbl_collation);
$query_cpy .= "\n" . 'CHARACTER SET = ' . $tbl_charset; $query_cpy .= "\n" . PMA_generateCharsetQueryPart($tbl_collation);
} }
if (!empty($comment)) { if (!empty($comment)) {

View File

@@ -85,7 +85,7 @@ $header_cells[] = $strField;
$header_cells[] = $strType . '<br /><span style="font-weight: normal">' . PMA_showMySQLDocu('Reference', 'Column_types') . '</span>'; $header_cells[] = $strType . '<br /><span style="font-weight: normal">' . PMA_showMySQLDocu('Reference', 'Column_types') . '</span>';
$header_cells[] = $strLengthSet; $header_cells[] = $strLengthSet;
if (PMA_MYSQL_INT_VERSION >= 40100) { if (PMA_MYSQL_INT_VERSION >= 40100) {
$header_cells[] = $strCharset; $header_cells[] = $strCollation;
} }
$header_cells[] = $strAttr; $header_cells[] = $strAttr;
$header_cells[] = $strNull; $header_cells[] = $strNull;
@@ -230,7 +230,8 @@ for ($i = 0 ; $i < $num_fields; $i++) {
} // end if else } // end if else
// some types, for example longtext, are reported as // 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) { if (PMA_MYSQL_INT_VERSION >= 40100) {
$tmp = strpos($type, 'character set'); $tmp = strpos($type, 'character set');
if ($tmp) { if ($tmp) {
@@ -274,28 +275,9 @@ for ($i = 0 ; $i < $num_fields; $i++) {
} }
if (PMA_MYSQL_INT_VERSION >= 40100) { if (PMA_MYSQL_INT_VERSION >= 40100) {
$content_cells[$i][$ci] = '<select name="field_charset[]" id="field_' . $i . '_' . ($ci - $ci_offset) . '">' . "\n" $tmp_collation = empty($row['Collation']) ? NULL : $row['Collation'];
. ' <option value=""></option>' . "\n"; $content_cells[$i][$ci] = PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_COLLATION, 'field_collation[]', 'field_' . $i . '_' . ($ci - $ci_offset), $tmp_collation, FALSE);
if (!empty($row['Collation']) && ( unset($tmp_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";
$ci++; $ci++;
} }
@@ -543,7 +525,7 @@ if ($action == 'tbl_create.php') {
<?php <?php
if (PMA_MYSQL_INT_VERSION >= 40100) { if (PMA_MYSQL_INT_VERSION >= 40100) {
echo ' <td width="25">&nbsp;</td>' . "\n" echo ' <td width="25">&nbsp;</td>' . "\n"
. ' <td>' . $strCharset . '&nbsp;:</td>' . "\n"; . ' <td>' . $strCollation . '&nbsp;:</td>' . "\n";
} }
} }
echo "\n"; echo "\n";
@@ -608,12 +590,7 @@ if ($action == 'tbl_create.php') {
if (PMA_MYSQL_INT_VERSION >= 40100) { if (PMA_MYSQL_INT_VERSION >= 40100) {
echo ' <td width="25">&nbsp;</td>' . "\n" echo ' <td width="25">&nbsp;</td>' . "\n"
. ' <td>' . "\n" . ' <td>' . "\n"
. ' <select name="tbl_charset">' . "\n"; . PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_COLLATION, 'tbl_collation', NULL, NULL, FALSE, 3)
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"
. ' </td>' . "\n"; . ' </td>' . "\n";
} }
} }

View File

@@ -37,10 +37,11 @@ if (isset($submittype)) {
$result = PMA_DBI_query($sql_query); $result = PMA_DBI_query($sql_query);
$message = $strSuccess; $message = $strSuccess;
} }
if (isset($submitcharset)) { if (isset($submitcollation)) {
$sql_query = 'ALTER TABLE ' . PMA_backquote($table) . ' DEFAULT CHARACTER SET = ' . $tbl_charset; $sql_query = 'ALTER TABLE ' . PMA_backquote($table) . ' DEFAULT' . PMA_generateCharsetQueryPart($tbl_collation);
$result = PMA_DBI_query($sql_query); $result = PMA_DBI_query($sql_query);
$message = $strSuccess; $message = $strSuccess;
unset($tbl_collation);
} }
if (isset($submitoptions)) { if (isset($submitoptions)) {
$sql_query = 'ALTER TABLE ' . PMA_backquote($table) $sql_query = 'ALTER TABLE ' . PMA_backquote($table)
@@ -451,16 +452,9 @@ if ($cfgRelation['relwork'] && $tbl_type != "INNODB") {
. ' <li>' . "\n" . ' <li>' . "\n"
. ' <form method="post" action="tbl_properties_operations.php">' . "\n" . ' <form method="post" action="tbl_properties_operations.php">' . "\n"
. PMA_generate_common_hidden_inputs($db, $table, 3) . PMA_generate_common_hidden_inputs($db, $table, 3)
. ' ' . $strCharset . '&nbsp;:&nbsp;' . "\n" . ' ' . $strCollation . '&nbsp;:&nbsp;' . "\n"
. ' <select name="tbl_charset" style="vertical-align: middle">' . "\n"; . PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_COLLATION, 'tbl_collation', NULL, $tbl_collation, FALSE, 3)
$real_charset = strpos($tbl_charset, '_') ? substr($tbl_charset, 0, strpos($tbl_charset, '_')) : $tbl_charset; . ' <input type="submit" name="submitcollation" value="' . $strGo . '" style="vertical-align: middle" />&nbsp;' . "\n"
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>&nbsp;' . "\n"
. ' <input type="submit" name="submitcharset" value="' . $strGo . '" style="vertical-align: middle" />&nbsp;' . "\n"
. ' </form>' . "\n" . ' </form>' . "\n"
. ' </li>' . "\n"; . ' </li>' . "\n";
} }

View File

@@ -599,7 +599,7 @@ if ($cfg['ShowStats']) {
<td bgcolor="<?php echo $bgcolor; ?>"><?php echo $strCollation; ?></td> <td bgcolor="<?php echo $bgcolor; ?>"><?php echo $strCollation; ?></td>
<td bgcolor="<?php echo $bgcolor; ?>" align="<?php echo $cell_align_left; ?>" nowrap="nowrap"> <td bgcolor="<?php echo $bgcolor; ?>" align="<?php echo $cell_align_left; ?>" nowrap="nowrap">
<?php <?php
echo '<dfn title="' . PMA_getCollationDescr($tbl_charset) . '">' . $tbl_charset . '</dfn>'; echo '<dfn title="' . PMA_getCollationDescr($tbl_collation) . '">' . $tbl_collation . '</dfn>';
?> ?>
</td> </td>
</tr> </tr>

View File

@@ -18,7 +18,7 @@ PMA_checkParameters(array('db', 'table'));
$table_info_result = PMA_DBI_query('SHOW TABLE STATUS LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\';'); $table_info_result = PMA_DBI_query('SHOW TABLE STATUS LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\';');
$showtable = PMA_DBI_fetch_assoc($table_info_result); $showtable = PMA_DBI_fetch_assoc($table_info_result);
$tbl_type = strtoupper($showtable['Type']); $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); $table_info_num_rows = (isset($showtable['Rows']) ? $showtable['Rows'] : 0);
$show_comment = (isset($showtable['Comment']) ? $showtable['Comment'] : ''); $show_comment = (isset($showtable['Comment']) ? $showtable['Comment'] : '');
$auto_increment = (isset($showtable['Auto_increment']) ? $showtable['Auto_increment'] : ''); $auto_increment = (isset($showtable['Auto_increment']) ? $showtable['Auto_increment'] : '');