]> git.joonet.de Git - adminer.git/commitdiff
Use utf8mb4 on more places
authorJakub Vrana <jakub@vrana.cz>
Thu, 26 Jun 2014 11:22:35 +0000 (13:22 +0200)
committerJakub Vrana <jakub@vrana.cz>
Thu, 26 Jun 2014 11:38:50 +0000 (13:38 +0200)
adminer/drivers/mysql.inc.php
adminer/dump.inc.php
adminer/include/adminer.inc.php
adminer/include/functions.inc.php

index 91cdeb01ad96e3fd274bb05d4349b7ced01721d0..021db8a71ca36554eaba14a4e8e9399bb8c8c281 100644 (file)
@@ -292,9 +292,7 @@ if (!defined("DRIVER")) {
                $connection = new Min_DB;
                $credentials = $adminer->credentials();
                if ($connection->connect($credentials[0], $credentials[1], $credentials[2])) {
-                       $connection->set_charset( // available in MySQLi since PHP 5.0.5
-                               version_compare($connection->server_info, "5.5.3") > 0 ? "utf8mb4" : "utf8" // SHOW CHARSET would require an extra query
-                       );
+                       $connection->set_charset(charset($connection)); // available in MySQLi since PHP 5.0.5
                        $connection->query("SET sql_quote_show_create = 1, autocommit = 1");
                        return $connection;
                }
index 005ae6596b965478bc667fe3f59dac0cd99ac1a6..67032522f73275a5ca427da0532bb2e52c105235 100644 (file)
@@ -16,7 +16,7 @@ if ($_POST && !$error) {
        if ($is_sql) {
                echo "-- Adminer $VERSION " . $drivers[DRIVER] . " dump\n\n";
                if ($jush == "sql") {
-                       echo "SET NAMES utf8;
+                       echo "SET NAMES " . charset($connection) . ";
 SET time_zone = '+00:00';
 " . ($_POST["data_style"] ? "SET foreign_key_checks = 0;
 SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO';
index 2406334ed2488c4d569215878df8869689884f00..cc4c40d7f5b5d22202d188a78e34b1baa2a63e2f 100644 (file)
@@ -412,7 +412,7 @@ username.form['auth[driver]'].onchange();
        * @return array expressions to join by AND
        */
        function selectSearchProcess($fields, $indexes) {
-               global $jush;
+               global $connection, $jush;
                $return = array();
                foreach ($indexes as $i => $index) {
                        if ($index["type"] == "FULLTEXT" && $_GET["fulltext"][$i] != "") {
@@ -443,7 +443,8 @@ username.form['auth[driver]'].onchange();
                                                        && (!preg_match("~[\x80-\xFF]~", $val["val"]) || $is_text)
                                                ) {
                                                        $name = idf_escape($name);
-                                                       $cols[] = ($jush == "sql" && $is_text && !preg_match('~^utf8~', $field["collation"]) ? "CONVERT($name USING utf8)" : $name);
+                                                       $charset = charset($connection);
+                                                       $cols[] = ($jush == "sql" && $is_text && !preg_match("~^$charset" . "_~", $field["collation"]) ? "CONVERT($name USING $charset)" : $name);
                                                }
                                        }
                                        $return[] = ($cols ? "(" . implode("$cond OR ", $cols) . "$cond)" : "0");
index 86246ad8379bb15d50dc29ac2e9d53003895fd65..73a9d772143d1d6d9caa10621071e8587626f72b 100644 (file)
@@ -65,6 +65,14 @@ function bracket_escape($idf, $back = false) {
        return strtr($idf, ($back ? array_flip($trans) : $trans));
 }
 
+/** Get connection charset
+* @param Min_DB
+* @return string
+*/
+function charset($connection) {
+       return (version_compare($connection->server_info, "5.5.3") > 0 ? "utf8mb4" : "utf8"); // SHOW CHARSET would require an extra query
+}
+
 /** Escape for HTML
 * @param string
 * @return string
@@ -373,7 +381,7 @@ function unique_array($row, $indexes) {
 * @return string
 */
 function where($where, $fields = array()) {
-       global $jush;
+       global $connection, $jush;
        $return = array();
        $function_pattern = '(^[\w\(]+(' . str_replace("_", ".*", preg_quote(idf_escape("_"))) . ')?\)+$)'; //! columns looking like functions
        foreach ((array) $where["where"] as $key => $val) {
@@ -386,7 +394,7 @@ function where($where, $fields = array()) {
                        ) // LIKE because of floats but slow with ints, in MS SQL because of text
                ; //! enum and set
                if ($jush == "sql" && preg_match('~char|text~', $fields[$key]["type"]) && preg_match("~[^ -@]~", $val)) { // not just [a-z] to catch non-ASCII characters
-                       $return[] = "$column = " . q($val) . " COLLATE utf8_bin";
+                       $return[] = "$column = " . q($val) . " COLLATE " . charset($connection) . "_bin";
                }
        }
        foreach ((array) $where["null"] as $key) {