From fe02443ea71e42fefe0145ef4a1443415f42997f Mon Sep 17 00:00:00 2001 From: Jamie Cameron Date: Fri, 8 Jan 2010 14:04:46 -0800 Subject: [PATCH] Collation order field --- mysql/CHANGELOG | 2 ++ mysql/lang/en | 1 + mysql/mysql-lib.pl | 14 ++++++++++++++ mysql/newdb.cgi | 3 ++- mysql/newdb_form.cgi | 14 +++++++++++++- 5 files changed, 32 insertions(+), 2 deletions(-) diff --git a/mysql/CHANGELOG b/mysql/CHANGELOG index 693f3976c..ed24ecc21 100644 --- a/mysql/CHANGELOG +++ b/mysql/CHANGELOG @@ -88,3 +88,5 @@ MySQL stored procedures are now included in backups, where supported. Restores and imports from local files are now run as the Unix user configured for backups, rather than root. ---- Changes since 1.490 ---- The information_schema database is no longer included when backing up all databases, as it really just contains metadata. +---- Changes since 1.500 ---- +Added a collation order field to the database creation form. diff --git a/mysql/lang/en b/mysql/lang/en index 87ba070b1..605cc8ad5 100644 --- a/mysql/lang/en +++ b/mysql/lang/en @@ -428,6 +428,7 @@ newdb_table=Initial table newdb_none=None newdb_tname=Named newdb_charset=Character set +newdb_collation=Collation order newdb_str=with fields below newdb_err=Failed to create database newdb_edb=Missing or invalid database name diff --git a/mysql/mysql-lib.pl b/mysql/mysql-lib.pl index b441fe203..f622636b0 100755 --- a/mysql/mysql-lib.pl +++ b/mysql/mysql-lib.pl @@ -1234,6 +1234,20 @@ else { return sort { lc($a) cmp lc($b) } @rv; } +# list_collation_orders([db]) +# Returns a list of supported collation orders. Each row is an array ref of +# a code and character set it can work with. +sub list_collation_orders +{ +local @rv; +local $db = $_[0] || $master_db; +if ($mysql_version >= 5) { + local $d = &execute_sql($db, "show collation"); + @rv = map { [ $_->[0], $_->[1] ] } @{$d->{'data'}}; + } +return sort { lc($a) cmp lc($b) } @rv; +} + # list_system_variables() # Returns a list of all system variables, and their default values sub list_system_variables diff --git a/mysql/newdb.cgi b/mysql/newdb.cgi index 8f1fb32be..249a0e0ae 100755 --- a/mysql/newdb.cgi +++ b/mysql/newdb.cgi @@ -19,7 +19,8 @@ if (!$in{'table_def'}) { @sql = &parse_table_form([ ], $in{'table'}); } &execute_sql_logged($master_db, "create database "."estr($in{'db'}). - ($in{'charset'} ? " character set $in{'charset'}" : "")); + ($in{'charset'} ? " character set $in{'charset'}" : ""). + ($in{'collation'} ? " collate $in{'collation'}" : "")); &webmin_log("create", "db", $in{'db'}); if (@sql) { foreach $sql (@sql) { diff --git a/mysql/newdb_form.cgi b/mysql/newdb_form.cgi index da0b0c95c..e7b39e39a 100755 --- a/mysql/newdb_form.cgi +++ b/mysql/newdb_form.cgi @@ -15,10 +15,22 @@ print &ui_table_row($text{'newdb_db'}, if ($mysql_version >= 4.1) { # Character set option + @charsets = &list_character_sets(); + %csmap = map { $_->[0], $_->[1] } @charsets; print &ui_table_row($text{'newdb_charset'}, &ui_select("charset", undef, [ [ undef, "<$text{'default'}>" ], - &list_character_sets() ])); + @charsets ])); + } + +@coll = &list_collation_orders(); +if (@coll) { + # Collation order option + print &ui_table_row($text{'newdb_collation'}, + &ui_select("collation", undef, + [ [ undef, "<$text{'default'}>" ], + map { [ $_->[0], $_->[0]." (".$csmap{$_->[1]}.")" ] } + &list_collation_orders() ])); } # Initial table name