diff --git a/ChangeLog b/ChangeLog index 4ddbaba7d..36a644ac9 100755 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,12 @@ phpMyAdmin - Changelog $Id$ $Source$ +2004-01-02 Alexander M. Turek + * libraries/mysql_charsets.lib.php, libraries/sqlparser.lib.php: + MySQL collations are now parsed and highlighted. + * libraries/export/sql.php: Include charset / collation information in db + export. + 2004-01-02 Marc Delisle * db_details_structure.php: bug 868996, debug code still in place, thanks to Matthias Fichtner (mfichtner) diff --git a/libraries/export/sql.php b/libraries/export/sql.php index 3a2c1d7a1..19a1f8859 100644 --- a/libraries/export/sql.php +++ b/libraries/export/sql.php @@ -80,7 +80,17 @@ function PMA_exportDBCreate($db) { if (isset($GLOBALS['drop_database'])) { if (!PMA_exportOutputHandler('DROP DATABASE ' . (isset($GLOBALS['use_backquotes']) ? PMA_backquote($db) : $db) . ';' . $crlf)) return FALSE; } - if (!PMA_exportOutputHandler('CREATE DATABASE ' . (isset($GLOBALS['use_backquotes']) ? PMA_backquote($db) : $db) . ';' . $crlf)) return FALSE; + $create_query = 'CREATE DATABASE ' . (isset($GLOBALS['use_backquotes']) ? PMA_backquote($db) : $db); + if (PMA_MYSQL_INT_VERSION >= 40101) { + $collation = PMA_getDbCollation($db); + if (strpos($collation, '_')) { + $create_query .= ' DEFAULT CHARACTER SET ' . substr($collation, 0, strpos($collation, '_')) . ' COLLATE ' . $collation; + } else { + $create_query .= ' DEFAULT CHARACTER SET ' . $collation; + } + } + $create_query .= ';' . $crlf; + if (!PMA_exportOutputHandler($create_query)) return FALSE; return PMA_exportOutputHandler('USE ' . $db . ';' . $crlf); } diff --git a/libraries/mysql_charsets.lib.php b/libraries/mysql_charsets.lib.php index 4d044e115..bb042ef2d 100644 --- a/libraries/mysql_charsets.lib.php +++ b/libraries/mysql_charsets.lib.php @@ -19,24 +19,26 @@ if (PMA_MYSQL_INT_VERSION >= 40100){ $res = PMA_mysql_query('SHOW COLLATION;', $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), 'SHOW COLLATION;'); + $mysql_charsets_count = count($mysql_charsets); sort($mysql_charsets, SORT_STRING); $mysql_collations = array_flip($mysql_charsets); - $mysql_default_collations = array();; + $mysql_default_collations = $mysql_collations_flat = array();; while ($row = PMA_mysql_fetch_array($res, MYSQL_ASSOC)) { if (!is_array($mysql_collations[$row['Charset']])) { $mysql_collations[$row['Charset']] = array($row['Collation']); } else { $mysql_collations[$row['Charset']][] = $row['Collation']; } + $mysql_collations_flat[] = $row['Collation']; if ((isset($row['D']) && $row['D'] == 'Y') || (isset($row['Default']) && $row['Default'] == 'Yes')) { $mysql_default_collations[$row['Charset']] = $row['Collation']; } } - $mysql_collations_count = 0; + $mysql_collations_count = count($mysql_collations_flat); + sort($mysql_collations_flat, SORT_STRING); foreach($mysql_collations AS $key => $value) { - $mysql_collations_count += count($mysql_collations[$key]); sort($mysql_collations[$key], SORT_STRING); reset($mysql_collations[$key]); } diff --git a/libraries/sqlparser.lib.php b/libraries/sqlparser.lib.php index fe89a949f..bcba595a3 100644 --- a/libraries/sqlparser.lib.php +++ b/libraries/sqlparser.lib.php @@ -52,6 +52,9 @@ if ($is_minimum_common == FALSE) { require_once('./libraries/mysql_charsets.lib.php'); if (!isset($mysql_charsets)) { $mysql_charsets = array(); + $mysql_charsets_count = 0; + $mysql_collations_flat = array(); + $mysql_collations_count = 0; } if (!defined('DEBUG_TIMING')) { @@ -191,6 +194,9 @@ if ($is_minimum_common == FALSE) { * @global integer MySQL column types count * @global integer MySQL function names count * @global array List of available character sets + * @global array List of available collations + * @global integer Character sets count + * @global integer Collations count * * @access public */ @@ -199,7 +205,7 @@ if ($is_minimum_common == FALSE) { global $cfg; global $PMA_SQPdata_column_attrib, $PMA_SQPdata_reserved_word, $PMA_SQPdata_column_type, $PMA_SQPdata_function_name, $PMA_SQPdata_column_attrib_cnt, $PMA_SQPdata_reserved_word_cnt, $PMA_SQPdata_column_type_cnt, $PMA_SQPdata_function_name_cnt; - global $mysql_charsets; + global $mysql_charsets, $mysql_collations_flat, $mysql_charsets_count, $mysql_collations_count; // rabus: Convert all line feeds to Unix style $sql = str_replace("\r\n", "\n", $sql); @@ -623,7 +629,8 @@ if ($is_minimum_common == FALSE) { ) && PMA_STR_binarySearchInArr($d_cur, $mysql_charsets, count($mysql_charsets))) { $t_suffix = '_charset'; } - } elseif (PMA_STR_binarySearchInArr($d_cur, $mysql_charsets, count($mysql_charsets))) { + } elseif (PMA_STR_binarySearchInArr($d_cur, $mysql_charsets, $mysql_charsets_count) + || PMA_STR_binarySearchInArr($d_cur, $mysql_collations_flat, $mysql_collations_count)) { $t_suffix = '_charset'; } else { // Do nothing