From a1875b0b77b24f7ca648142caff06d6c590a520b Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Sat, 7 Jun 2003 20:17:43 +0000 Subject: [PATCH] Improved MySQL 4.1 support --- ChangeLog | 9 +++ libraries/mysql_charsets.lib.php3 | 42 +++++++++++++ tbl_addfield.php3 | 24 ++++---- tbl_alter.php3 | 16 ++--- tbl_create.php3 | 20 ++++--- tbl_properties.inc.php3 | 98 +++++++++++++++++++++++-------- tbl_properties_operations.php3 | 37 +++++++++++- tbl_properties_structure.php3 | 34 ++++++----- tbl_properties_table_info.php3 | 1 + 9 files changed, 216 insertions(+), 65 deletions(-) create mode 100644 libraries/mysql_charsets.lib.php3 diff --git a/ChangeLog b/ChangeLog index aa0780a7f..69df744da 100755 --- a/ChangeLog +++ b/ChangeLog @@ -8,6 +8,15 @@ $Source$ 2003-06-07 Alexander M. Turek * 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 * Documentation.html, config.inc.php3: new LimitChars behavior diff --git a/libraries/mysql_charsets.lib.php3 b/libraries/mysql_charsets.lib.php3 new file mode 100644 index 000000000..a6bd62f90 --- /dev/null +++ b/libraries/mysql_charsets.lib.php3 @@ -0,0 +1,42 @@ += 40000) { + sort($mysql_charsets, SORT_STRING); + } else { + sort($mysql_charsets); + } + +} // $__PMA_MYSQL_CHARSETS_LIB__ + +?> diff --git a/tbl_addfield.php3 b/tbl_addfield.php3 index 2e512d3e1..08d6fa432 100755 --- a/tbl_addfield.php3 +++ b/tbl_addfield.php3 @@ -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') { @@ -106,9 +108,9 @@ if (isset($submit)) { $result = PMA_mysql_query($sql_query) or $error_create = true; if ($error_create == false) { - + $sql_query_cpy = $sql_query . ';'; - + // Builds the primary keys statements and updates the table $primary = ''; if (isset($field_primary)) { @@ -126,7 +128,7 @@ if (isset($submit)) { $sql_query_cpy .= "\n" . $sql_query . ';'; } } // end if - + // Builds the indexes statements and updates the table $index = ''; if (isset($field_index)) { @@ -144,7 +146,7 @@ if (isset($submit)) { $sql_query_cpy .= "\n" . $sql_query . ';'; } } // end if - + // Builds the uniques statements and updates the table $unique = ''; if (isset($field_unique)) { @@ -162,8 +164,8 @@ if (isset($submit)) { $sql_query_cpy .= "\n" . $sql_query . ';'; } } // end if - - + + // Builds the fulltext statements and updates the table $fulltext = ''; if (PMA_MYSQL_INT_VERSION >= 32323 && isset($field_fulltext)) { @@ -179,13 +181,13 @@ if (isset($submit)) { $sql_query_cpy .= "\n" . $sql_query . ';'; } } // end if - + // garvin: If comments were sent, enable relation stuff require('./libraries/relation.lib.php3'); require('./libraries/transformations.lib.php3'); - + $cfgRelation = PMA_getRelationsParam(); - + // garvin: Update comment table, if a comment was set. if (isset($field_comments) && is_array($field_comments) && $cfgRelation['commwork']) { @reset($field_comments); @@ -193,7 +195,7 @@ if (isset($submit)) { PMA_setComment($db, $table, $field_name[$fieldindex], $fieldcomment); } } - + // garvin: Update comment table for mime types [MIME] if (isset($field_mimetype) && is_array($field_mimetype) && $cfgRelation['commwork'] && $cfgRelation['mimework'] && $cfg['BrowseMIME']) { @reset($field_mimetype); @@ -201,7 +203,7 @@ if (isset($submit)) { PMA_setMIME($db, $table, $field_name[$fieldindex], $mimetype, $field_transformation[$fieldindex], $field_transformation_options[$fieldindex]); } } - + // Go back to the structure sub-page $sql_query = $sql_query_cpy; unset($sql_query_cpy); diff --git a/tbl_alter.php3 b/tbl_alter.php3 index 662ee09a2..4d259a970 100755 --- a/tbl_alter.php3 +++ b/tbl_alter.php3 @@ -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') { @@ -83,13 +85,13 @@ if (isset($submit)) { if ($error_create == false) { $message = $strTable . ' ' . htmlspecialchars($table) . ' ' . $strHasBeenAltered; $btnDrop = 'Fake'; - + // garvin: If comments were sent, enable relation stuff require('./libraries/relation.lib.php3'); require('./libraries/transformations.lib.php3'); - + $cfgRelation = PMA_getRelationsParam(); - + // garvin: Update comment table, if a comment was set. if (isset($field_comments) && is_array($field_comments) && $cfgRelation['commwork']) { @reset($field_comments); @@ -97,7 +99,7 @@ if (isset($submit)) { PMA_setComment($db, $table, $field_name[$fieldindex], $fieldcomment, $field_orig[$fieldindex]); } } - + // garvin: Rename relations&display fields, if altered. if (($cfgRelation['displaywork'] || $cfgRelation['relwork']) && isset($field_orig) && is_array($field_orig)) { @reset($field_orig); @@ -123,7 +125,7 @@ if (isset($submit)) { $tb_rs = PMA_query_as_cu($table_query); unset($table_query); unset($tb_rs); - + $table_query = 'UPDATE ' . PMA_backquote($cfgRelation['relation']) . ' SET foreign_field = \'' . PMA_sqlAddslashes($field_name[$fieldindex]) . '\'' . ' WHERE foreign_db = \'' . PMA_sqlAddslashes($db) . '\'' @@ -136,7 +138,7 @@ if (isset($submit)) { } // end if fieldname has changed } // end while check fieldnames } // end if relations/display has to be changed - + // garvin: Update comment table for mime types [MIME] if (isset($field_mimetype) && is_array($field_mimetype) && $cfgRelation['commwork'] && $cfgRelation['mimework'] && $cfg['BrowseMIME']) { @reset($field_mimetype); @@ -144,7 +146,7 @@ if (isset($submit)) { PMA_setMIME($db, $table, $field_name[$fieldindex], $mimetype, $field_transformation[$fieldindex], $field_transformation_options[$fieldindex]); } } - + $active_page = 'tbl_properties_structure.php3'; include('./tbl_properties_structure.php3'); exit(); diff --git a/tbl_create.php3 b/tbl_create.php3 index 957209231..202ca5d97 100755 --- a/tbl_create.php3 +++ b/tbl_create.php3 @@ -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) . '\''; @@ -172,13 +178,13 @@ if (isset($submit)) { $sql_query = $query_cpy . ';'; unset($query_cpy); $message = $strTable . ' ' . htmlspecialchars($table) . ' ' . $strHasBeenCreated; - + // garvin: If comments were sent, enable relation stuff require('./libraries/relation.lib.php3'); require('./libraries/transformations.lib.php3'); - + $cfgRelation = PMA_getRelationsParam(); - + // garvin: Update comment table, if a comment was set. if (isset($field_comments) && is_array($field_comments) && $cfgRelation['commwork']) { @reset($field_comments); @@ -186,7 +192,7 @@ if (isset($submit)) { PMA_setComment($db, $table, $field_name[$fieldindex], $fieldcomment); } } - + // garvin: Update comment table for mime types [MIME] if (isset($field_mimetype) && is_array($field_mimetype) && $cfgRelation['commwork'] && $cfgRelation['mimework'] && $cfg['BrowseMIME']) { @reset($field_mimetype); @@ -194,7 +200,7 @@ if (isset($submit)) { PMA_setMIME($db, $table, $field_name[$fieldindex], $mimetype, $field_transformation[$fieldindex], $field_transformation_options[$fieldindex]); } } - + include('./' . $cfg['DefaultTabTable']); $abort = TRUE; exit(); diff --git a/tbl_properties.inc.php3 b/tbl_properties.inc.php3 index e9c9ab377..92f47ab9a 100755 --- a/tbl_properties.inc.php3 +++ b/tbl_properties.inc.php3 @@ -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'); +} + ?> @@ -79,6 +84,9 @@ $content_cells = array(); $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[] = $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" . ''; + $content_cells[$i][$ci] .= "\n" . ''; $ci++; - $content_cells[$i][$ci] = '' . "\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" . '' . "\n"; + $content_cells[$i][$ci] .= "\n" . '' . "\n"; $ci++; - $content_cells[$i][$ci] = '' . "\n" + . ' ' . "\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] .= ' ' . "\n"; + } + unset($j); + unset($real_charset); + $content_cells[$i][$ci] .= '' . "\n"; + $ci++; + } + + $content_cells[$i][$ci] = ''; $ci++; - $content_cells[$i][$ci] = ''; 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" . ''; + $content_cells[$i][$ci] = "\n" . ''; } else { - $content_cells[$i][5] = "\n"; + $content_cells[$i][$ci] = "\n"; } - $content_cells[$i][$ci] .= ''; + $content_cells[$i][$ci] .= ''; $ci++; - $content_cells[$i][$ci] = ''; 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] = ''; + $content_cells[$i][$ci] = ''; $ci++; } // garvin: MIME-types if ($cfgRelation['mimework'] && $cfg['BrowseMIME'] && $cfgRelation['commwork']) { - $content_cells[$i][$ci] = '' . "\n"; $content_cells[$i][$ci] .= ' ' . "\n"; $content_cells[$i][$ci] .= ' ' . "\n"; @@ -350,7 +383,7 @@ for ($i = 0 ; $i < $num_fields; $i++) { $content_cells[$i][$ci] .= ''; $ci++; - $content_cells[$i][$ci] = '' . "\n"; $content_cells[$i][$ci] .= ' ' . "\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] .= ''; $ci++; - $content_cells[$i][$ci] = ''; + $content_cells[$i][$ci] = ''; $ci++; } @@ -494,6 +527,10 @@ if ($action == 'tbl_create.php3' && PMA_MYSQL_INT_VERSION >= 32300) {    : = 40100) { + echo '  ' . "\n" + . ' ' . $strCharset . ' :' . "\n"; + } } echo "\n"; ?> @@ -555,6 +592,17 @@ if ($action == 'tbl_create.php3' && PMA_MYSQL_INT_VERSION >= 32300) { = 40100) { + echo '  ' . "\n" + . ' ' . "\n" + . ' ' . "\n" + . ' ' . "\n"; + } } echo "\n"; ?> @@ -606,4 +654,4 @@ if ($cfgRelation['commwork'] && $cfgRelation['mimework'] && $cfg['BrowseMIME'])
-
+
\ No newline at end of file diff --git a/tbl_properties_operations.php3 b/tbl_properties_operations.php3 index 3fa51a49e..f4cb8b191 100755 --- a/tbl_properties_operations.php3 +++ b/tbl_properties_operations.php3 @@ -17,6 +17,13 @@ $url_query .= '&goto=tbl_properties_operations.php3&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) { + = 40100) { + echo "\n" + . '' . "\n" + . '
  • ' . "\n" + . '
    ' . "\n" + . PMA_generate_common_hidden_inputs($db, $table, 3) + . ' ' . $strCharset . ' : ' . "\n" + . '  ' . "\n" + . '  ' . "\n" + . '
    ' . "\n" + . '
  • ' . "\n"; + } + + ?>
  • @@ -518,4 +553,4 @@ if (PMA_MYSQL_INT_VERSION >= 32322) { */ echo "\n"; require('./footer.inc.php3'); -?> +?> \ No newline at end of file diff --git a/tbl_properties_structure.php3 b/tbl_properties_structure.php3 index 9368623d5..c66d29501 100755 --- a/tbl_properties_structure.php3 +++ b/tbl_properties_structure.php3 @@ -140,19 +140,25 @@ 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' - || substr($type, 0, 7) == 'varchar' - || substr($type, 0, 4) == 'text' - || substr($type, 0, 8) == 'tinytext' - || substr($type, 0, 10) == 'mediumtext' - || substr($type, 0, 8) == 'longtext' - ) && !$binary) { - if (strpos($type, ' character set ')) { - $type = substr($type, 0, strpos($type, ' character set ')); - } - if (!empty($row['Collation'])) { - $field_charset = $row['Collation']; + 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' + || substr($type, 0, 10) == 'mediumtext' + || substr($type, 0, 8) == 'longtext' + ) && !$binary) { + if (strpos($type, ' character set ')) { + $type = substr($type, 0, strpos($type, ' character set ')); + } + if (!empty($row['Collation'])) { + $field_charset = $row['Collation']; + } else { + $field_charset = ''; + } + } else { + $field_charset = ''; } } @@ -508,7 +514,7 @@ if ($cfg['ShowStats']) { diff --git a/tbl_properties_table_info.php3 b/tbl_properties_table_info.php3 index a4abf8718..a69f8544c 100755 --- a/tbl_properties_table_info.php3 +++ b/tbl_properties_table_info.php3 @@ -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'] : '');