Improved MySQL 4.1 support

This commit is contained in:
Alexander M. Turek
2003-06-07 20:17:43 +00:00
parent 8d263edf44
commit a1875b0b77
9 changed files with 216 additions and 65 deletions

View File

@@ -8,6 +8,15 @@ $Source$
2003-06-07 Alexander M. Turek <rabus@users.sourceforge.net>
* libraries/common.lib.php3: Incremented required config.inc.php3 revision
number.
* tbl_addfield.php3, tbl_alter.php3, tbl_create.php3,
tbl_properties.inc.php3, tbl_properties_operations.php3,
tbl_properties_structure.php3, tbl_properties_table_info.php3,
libraries/mysql_charsets.lib.php3: Improved MySQL 4.1 support:
- phpMyAdmin is now able to assign / alter table and field charsets;
- The table structure page sometimes displayed "Array" in the charset
column;
- When altering the field type, the input box for the field length
sometimes had a strange default value.
2003-06-06 Marc Delisle <lem9@users.sourceforge.net>
* Documentation.html, config.inc.php3: new LimitChars behavior

View File

@@ -0,0 +1,42 @@
<?php
/* $Id$ */
// vim: expandtab sw=4 ts=4 sts=4:
if (!defined('PMA_MYSQL_CHARSETS_LIB_INCLUDED')){
define('PMA_MYSQL_CHARSETS_LIB_INCLUDED', 1);
$res = PMA_mysql_query('SHOW VARIABLES LIKE "character_sets";', $userlink)
or PMA_mysqlDie(PMA_mysql_error($userlink), 'SHOW VARIABLES LIKE "character sets";');
$row = PMA_mysql_fetch_row($res);
@mysql_free_result($res);
unset($res);
$charsets_tmp = explode(' ', $row[1]);
unset($row);
$mysql_charsets = array();
for ($i = 0; isset($charsets_tmp[$i]); $i++) {
if (strpos(' ' . $charsets_tmp[$i], '_')) {
$current = substr($charsets_tmp[$i], 0, strpos($charsets_tmp[$i], '_'));
} else {
$current = $charsets_tmp[$i];
}
if (!in_array($current, $mysql_charsets)) {
$mysql_charsets[] = $current;
}
}
unset($charsets_tmp);
unset($i);
unset($current);
if (PMA_PHP_INT_VERSION >= 40000) {
sort($mysql_charsets, SORT_STRING);
} else {
sort($mysql_charsets);
}
} // $__PMA_MYSQL_CHARSETS_LIB__
?>

View File

@@ -55,6 +55,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];
}
if ($field_default[$i] != '') {
if (strtoupper($field_default[$i]) == 'NULL') {

View File

@@ -55,6 +55,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];
}
if ($field_default[$i] != '') {
if (strtoupper($field_default[$i]) == 'NULL') {

View File

@@ -59,6 +59,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];
}
if ($field_default[$i] != '') {
if (strtoupper($field_default[$i]) == 'NULL') {
@@ -154,10 +156,14 @@ if (isset($submit)) {
$sql_query = 'CREATE TABLE ' . PMA_backquote($table) . ' (' . $sql_query . ')';
$query_cpy = 'CREATE TABLE ' . PMA_backquote($table) . ' (' . $query_cpy . "\n" . ')';
// Adds table type and comments (2 May 2001 - Robbat2)
// Adds table type, character set and comments
if (!empty($tbl_type) && ($tbl_type != 'Default')) {
$sql_query .= ' TYPE = ' . $tbl_type;
$query_cpy .= ' 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 >= 32300 && !empty($comment)) {
$sql_query .= ' COMMENT = \'' . PMA_sqlAddslashes($comment) . '\'';

View File

@@ -3,6 +3,11 @@
// vim: expandtab sw=4 ts=4 sts=4:
// Get available character sets (MySQL >= 4.1)
if (PMA_MYSQL_INT_VERSION >= 40100 && !defined('PMA_MYSQL_CHARSETS_LIB_INCLUDED')) {
include('./libraries/mysql_charsets.lib.php3');
}
?>
<?php if ($cfg['CtrlArrowsMoving']) { ?>
<!-- Set on key handler for moving using by Ctrl+arrows -->
@@ -79,6 +84,9 @@ $content_cells = array();
$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[] = $strAttr;
$header_cells[] = $strNull;
$header_cells[] = $strDefault . '**';
@@ -183,6 +191,9 @@ for ($i = 0 ; $i < $num_fields; $i++) {
// Cell index: If certain fields get left out, the counter shouldn't chage.
$ci = 0;
// Everytime a cell shall be left out the STRG-jumping feature, $ci_offset
// has to be incremented ($ci_offset++)
$ci_offset = -1;
if ($is_backup) {
$backup_field = (isset($true_selected) && $true_selected[$i] ? $true_selected[$i] : (isset($row) && isset($row['Field']) ? urlencode($row['Field']) : ''));
@@ -191,9 +202,9 @@ for ($i = 0 ; $i < $num_fields; $i++) {
$content_cells[$i][$ci] = '';
}
$content_cells[$i][$ci] .= "\n" . '<input id="field_' . $i . '_1" type="text" name="field_name[]" size="10" maxlength="64" value="' . (isset($row) && isset($row['Field']) ? str_replace('"', '&quot;', $row['Field']) : '') . '" class="textfield" />';
$content_cells[$i][$ci] .= "\n" . '<input id="field_' . $i . '_' . ($ci - $ci_offset) . '" type="text" name="field_name[]" size="10" maxlength="64" value="' . (isset($row) && isset($row['Field']) ? str_replace('"', '&quot;', $row['Field']) : '') . '" class="textfield" />';
$ci++;
$content_cells[$i][$ci] = '<select name="field_type[]" id="field_' . $i . '_2">' . "\n";
$content_cells[$i][$ci] = '<select name="field_type[]" id="field_' . $i . '_' . ($ci - $ci_offset) . '">' . "\n";
if (empty($row['Type'])) {
$row['Type'] = '';
@@ -211,13 +222,10 @@ for ($i = 0 ; $i < $num_fields; $i++) {
$type = eregi_replace('ZEROFILL', '', $type);
$type = eregi_replace('UNSIGNED', '', $type);
$length = $type;
$type = chop(eregi_replace('\\(.*\\)', '', $type));
if (!empty($type)) {
$length = eregi_replace("^$type\(", '', $length);
$length = eregi_replace('\)$', '', trim($length));
}
if ($length == $type) {
if (strpos($type, '(')) {
$length = chop(substr($type, (strpos($type, '(') + 1), (strpos($type, ')') - strpos($type, '(') - 1)));
$type = chop(substr($type, 0, strpos($type, '(')));
} else {
$length = '';
}
} // end if else
@@ -243,11 +251,9 @@ for ($i = 0 ; $i < $num_fields; $i++) {
$content_cells[$i][$ci] = '';
}
$content_cells[$i][$ci] .= "\n" . '<input id="field_' . $i . '_3" type="text" name="field_length[]" size="8" value="' . str_replace('"', '&quot;', $length) . '" class="textfield" />' . "\n";
$content_cells[$i][$ci] .= "\n" . '<input id="field_' . $i . '_' . ($ci - $ci_offset) . '" type="text" name="field_length[]" size="8" value="' . str_replace('"', '&quot;', $length) . '" class="textfield" />' . "\n";
$ci++;
$content_cells[$i][$ci] = '<select name="field_attribute[]" id="field_' . $i . '_4">' . "\n";
if (eregi('^(set|enum)$', $type)) {
$binary = 0;
$unsigned = 0;
@@ -257,6 +263,33 @@ for ($i = 0 ; $i < $num_fields; $i++) {
$unsigned = eregi('UNSIGNED', $row['Type'], $test_attribute2);
$zerofill = eregi('ZEROFILL', $row['Type'], $test_attribute3);
}
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'
) && !$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++;
}
$content_cells[$i][$ci] = '<select name="field_attribute[]" id="field_' . $i . '_' . ($ci - $ci_offset) . '">' . "\n";
$strAttribute = '';
if ($binary) {
$strAttribute = 'BINARY';
@@ -273,17 +306,17 @@ for ($i = 0 ; $i < $num_fields; $i++) {
}
for ($j = 0;$j < count($cfg['AttributeTypes']); $j++) {
$content_cells[$i][3] .= ' <option value="'. $cfg['AttributeTypes'][$j] . '"';
$content_cells[$i][$ci] .= ' <option value="'. $cfg['AttributeTypes'][$j] . '"';
if (strtoupper($strAttribute) == strtoupper($cfg['AttributeTypes'][$j])) {
$content_cells[$i][3] .= ' selected="selected"';
$content_cells[$i][$ci] .= ' selected="selected"';
}
$content_cells[$i][3] .= '>' . $cfg['AttributeTypes'][$j] . '</option>' . "\n";
$content_cells[$i][$ci] .= '>' . $cfg['AttributeTypes'][$j] . '</option>' . "\n";
}
$content_cells[$i][$ci] .= '</select>';
$ci++;
$content_cells[$i][$ci] = '<select name="field_null[]" id="field_' . $i . '_5">';
$content_cells[$i][$ci] = '<select name="field_null[]" id="field_' . $i . '_' . ($ci - $ci_offset) . '">';
if ((!isset($row) || empty($row['Null']) || $row['Null'] == 'NOT NULL') && $submit_null == FALSE) {
$content_cells[$i][$ci] .= "\n";
@@ -304,15 +337,15 @@ for ($i = 0 ; $i < $num_fields; $i++) {
}
if ($is_backup) {
$content_cells[$i][5] = "\n" . '<input type="hidden" name="field_default_orig[]" size="8" value="' . (isset($row) && isset($row['Default']) ? urlencode($row['Default']) : '') . '" />';
$content_cells[$i][$ci] = "\n" . '<input type="hidden" name="field_default_orig[]" size="8" value="' . (isset($row) && isset($row['Default']) ? urlencode($row['Default']) : '') . '" />';
} else {
$content_cells[$i][5] = "\n";
$content_cells[$i][$ci] = "\n";
}
$content_cells[$i][$ci] .= '<input id="field_' . $i . '_6" type="text" name="field_default[]" size="8" value="' . (isset($row) && isset($row['Default']) ? str_replace('"', '&quot;', $row['Default']) : '') . '" class="textfield" />';
$content_cells[$i][$ci] .= '<input id="field_' . $i . '_' . ($ci - $ci_offset) . '" type="text" name="field_default[]" size="8" value="' . (isset($row) && isset($row['Default']) ? str_replace('"', '&quot;', $row['Default']) : '') . '" class="textfield" />';
$ci++;
$content_cells[$i][$ci] = '<select name="field_extra[]" id="field_' . $i . '_7">';
$content_cells[$i][$ci] = '<select name="field_extra[]" id="field_' . $i . '_' . ($ci - $ci_offset) . '">';
if(!isset($row) || empty($row['Extra'])) {
$content_cells[$i][$ci] .= "\n";
@@ -329,13 +362,13 @@ for ($i = 0 ; $i < $num_fields; $i++) {
// garvin: comments
if ($cfgRelation['commwork']) {
$content_cells[$i][$ci] = '<input id="field_' . $i . '_7" type="text" name="field_comments[]" size="8" value="' . (isset($row) && isset($row['Field']) && is_array($comments_map) && isset($comments_map[$row['Field']]) ? htmlspecialchars($comments_map[$row['Field']]) : '') . '" class="textfield" />';
$content_cells[$i][$ci] = '<input id="field_' . $i . '_' . ($ci - $ci_offset) . '" type="text" name="field_comments[]" size="8" value="' . (isset($row) && isset($row['Field']) && is_array($comments_map) && isset($comments_map[$row['Field']]) ? htmlspecialchars($comments_map[$row['Field']]) : '') . '" class="textfield" />';
$ci++;
}
// garvin: MIME-types
if ($cfgRelation['mimework'] && $cfg['BrowseMIME'] && $cfgRelation['commwork']) {
$content_cells[$i][$ci] = '<select id="field_' . $i . '_8" size="1" name="field_mimetype[]">' . "\n";
$content_cells[$i][$ci] = '<select id="field_' . $i . '_' . ($ci - $ci_offset) . '" size="1" name="field_mimetype[]">' . "\n";
$content_cells[$i][$ci] .= ' <option value=""></option>' . "\n";
$content_cells[$i][$ci] .= ' <option value="auto">auto-detect</option>' . "\n";
@@ -350,7 +383,7 @@ for ($i = 0 ; $i < $num_fields; $i++) {
$content_cells[$i][$ci] .= '</select>';
$ci++;
$content_cells[$i][$ci] = '<select id="field_' . $i . '_9" size="1" name="field_transformation[]">' . "\n";
$content_cells[$i][$ci] = '<select id="field_' . $i . '_' . ($ci - $ci_offset) . '" size="1" name="field_transformation[]">' . "\n";
$content_cells[$i][$ci] .= ' <option value="" title="' . $strNone . '"></option>' . "\n";
if (is_array($available_mime['transformation'])) {
@reset($available_mime['transformation']);
@@ -365,7 +398,7 @@ for ($i = 0 ; $i < $num_fields; $i++) {
$content_cells[$i][$ci] .= '</select>';
$ci++;
$content_cells[$i][$ci] = '<input id="field_' . $i . '_10" type="text" name="field_transformation_options[]" size="8" value="' . (isset($row) && isset($row['Field']) && isset($mime_map[$row['Field']]['transformation_options']) ? htmlspecialchars($mime_map[$row['Field']]['transformation_options']) : '') . '" class="textfield" />';
$content_cells[$i][$ci] = '<input id="field_' . $i . '_' . ($ci - $ci_offset) . '" type="text" name="field_transformation_options[]" size="8" value="' . (isset($row) && isset($row['Field']) && isset($mime_map[$row['Field']]['transformation_options']) ? htmlspecialchars($mime_map[$row['Field']]['transformation_options']) : '') . '" class="textfield" />';
$ci++;
}
@@ -494,6 +527,10 @@ if ($action == 'tbl_create.php3' && PMA_MYSQL_INT_VERSION >= 32300) {
<td width="25">&nbsp;</td>
<td><?php echo $strTableType; ?>&nbsp;:</td>
<?php
if (PMA_MYSQL_INT_VERSION >= 40100) {
echo ' <td width="25">&nbsp;</td>' . "\n"
. ' <td>' . $strCharset . '&nbsp;:</td>' . "\n";
}
}
echo "\n";
?>
@@ -555,6 +592,17 @@ if ($action == 'tbl_create.php3' && PMA_MYSQL_INT_VERSION >= 32300) {
</select>
</td>
<?php
if (PMA_MYSQL_INT_VERSION >= 40100) {
echo ' <td width="25">&nbsp;</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"
. ' </td>' . "\n";
}
}
echo "\n";
?>

View File

@@ -17,6 +17,13 @@ $url_query .= '&amp;goto=tbl_properties_operations.php3&amp;back=tbl_properties_
require('./libraries/relation.lib.php3');
$cfgRelation = PMA_getRelationsParam();
/**
* Gets available MySQL charsets
*/
if (PMA_MYSQL_INT_VERSION >= 40100 && !defined('PMA_MYSQL_CHARSETS_LIB_INCLUDED')) {
include('./libraries/mysql_charsets.lib.php3');
}
/**
* Updates table comment, type and options if required
*/
@@ -32,6 +39,11 @@ if (isset($submittype)) {
$result = PMA_mysql_query($sql_query) or PMA_mysqlDie('', $sql_query, '', $err_url);
$message = $strSuccess;
}
if (isset($submitcharset)) {
$sql_query = 'ALTER TABLE ' . PMA_backquote($table) . ' CHARACTER SET = ' . $tbl_charset;
$result = PMA_mysql_query($sql_query) or PMA_mysqlDie('', $sql_query, '', $err_url);
$message = $strSuccess;
}
if (isset($submitoptions)) {
$sql_query = 'ALTER TABLE ' . PMA_backquote($table)
. (isset($pack_keys) ? ' pack_keys=1': ' pack_keys=0')
@@ -473,6 +485,29 @@ if (PMA_MYSQL_INT_VERSION >= 32322) {
<?php echo PMA_showMySQLDocu('Table_types', 'Table_types') . "\n"; ?>
</form>
</li>
<?php
if (PMA_MYSQL_INT_VERSION >= 40100) {
echo "\n"
. '<!-- Table character set -->' . "\n"
. ' <li>' . "\n"
. ' <form method="post" action="tbl_properties_operations.php3">' . "\n"
. PMA_generate_common_hidden_inputs($db, $table, 3)
. ' ' . $strCharset . '&nbsp;:&nbsp;' . "\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>&nbsp;' . "\n"
. ' <input type="submit" name="submitcharset" value="' . $strGo . '" style="vertical-align: middle" />&nbsp;' . "\n"
. ' </form>' . "\n"
. ' </li>' . "\n";
}
?>
<!-- Table options -->
<li style="vertical-align: top">

View File

@@ -140,8 +140,9 @@ while ($row = PMA_mysql_fetch_array($fields_rs)) {
}
// rabus: Devide charset from the rest of the type definition (MySQL >= 4.1)
if (PMA_MYSQL_INT_VERSION >= 40100 && (
substr($type, 0, 4) == 'char'
unset($field_charset);
if (PMA_MYSQL_INT_VERSION >= 40100) {
if ((substr($type, 0, 4) == 'char'
|| substr($type, 0, 7) == 'varchar'
|| substr($type, 0, 4) == 'text'
|| substr($type, 0, 8) == 'tinytext'
@@ -153,6 +154,11 @@ while ($row = PMA_mysql_fetch_array($fields_rs)) {
}
if (!empty($row['Collation'])) {
$field_charset = $row['Collation'];
} else {
$field_charset = '';
}
} else {
$field_charset = '';
}
}
@@ -508,7 +514,7 @@ if ($cfg['ShowStats']) {
<td bgcolor="<?php echo $bgcolor; ?>"><?php echo $strCharset; ?></td>
<td bgcolor="<?php echo $bgcolor; ?>" align="<?php echo $cell_align_left; ?>" nowrap="nowrap">
<?php
echo $showtable['Charset'];
echo $tbl_charset;
?>
</td>
</tr>

View File

@@ -14,6 +14,7 @@ if (PMA_MYSQL_INT_VERSION >= 32303) {
$table_info_result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url_0);
$showtable = PMA_mysql_fetch_array($table_info_result);
$tbl_type = strtoupper($showtable['Type']);
$tbl_charset = empty($showtable['Charset']) ? '' : $showtable['Charset'];
$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'] : '');