From 964520252ce6177d7f52a393f77ed899e362087a Mon Sep 17 00:00:00 2001 From: jakubvrana Date: Wed, 25 Jul 2007 19:54:56 +0000 Subject: [PATCH] Detect collation from charset git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@256 7c3ca157-0c34-0410-bff1-cbf682f78f5c --- database.inc.php | 8 ++++++-- functions.inc.php | 6 +++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/database.inc.php b/database.inc.php index ea52f10e..b13b2032 100644 --- a/database.inc.php +++ b/database.inc.php @@ -30,6 +30,7 @@ if ($_POST && !$error) { } page_header(strlen($_GET["db"]) ? lang('Alter database') . ": " . htmlspecialchars($_GET["db"]) : lang('Create database')); +$collations = collations(); if ($_POST) { echo "

" . lang('Unable to operate database') . ": " . htmlspecialchars($error) . "

\n"; @@ -39,8 +40,11 @@ if ($_POST) { $name = $_GET["db"]; $collate = array(); if (strlen($_GET["db"]) && ($result = $mysql->query("SHOW CREATE DATABASE " . idf_escape($_GET["db"])))) { - if (preg_match('~ COLLATE ([^ ]+)~', $mysql->result($result, 1), $match)) { + $create = $mysql->result($result, 1); + if (preg_match('~ COLLATE ([^ ]+)~', $create, $match)) { $collate = $match[1]; + } elseif (preg_match('~ CHARACTER SET ([^ ]+)~', $create, $match)) { + $collate = $collations[$match[1]][0]; } $result->free(); } @@ -50,7 +54,7 @@ if ($_POST) {

- + diff --git a/functions.inc.php b/functions.inc.php index 264531d0..86a36c0e 100644 --- a/functions.inc.php +++ b/functions.inc.php @@ -159,7 +159,11 @@ function collations() { $return = array(); $result = $mysql->query("SHOW COLLATION"); while ($row = $result->fetch_assoc()) { - $return[$row["Charset"]][] = $row["Collation"]; + if ($row["Default"] && $return[$row["Charset"]]) { + array_unshift($return[$row["Charset"]], $row["Collation"]); + } else { + $return[$row["Charset"]][] = $row["Collation"]; + } } $result->free(); return $return;