Remove charset methods.
authorJan Schneider <jan@horde.org>
Tue, 30 Nov 2010 14:41:59 +0000 (15:41 +0100)
committerJan Schneider <jan@horde.org>
Tue, 30 Nov 2010 14:41:59 +0000 (15:41 +0100)
They are only implemented in the MySQL drivers anyway and using SET
NAMES causes more problems than it solves. Actually it breaks the
current share driver.

framework/Db/lib/Horde/Db/Adapter/Base.php
framework/Db/lib/Horde/Db/Adapter/Mysql.php
framework/Db/lib/Horde/Db/Adapter/Mysql/Schema.php
framework/Db/lib/Horde/Db/Adapter/Mysqli.php
framework/Db/lib/Horde/Db/Adapter/Pdo/Mysql.php
framework/Db/test/Horde/Db/Adapter/MysqlTest.php
framework/Db/test/Horde/Db/Adapter/MysqliTest.php
framework/Db/test/Horde/Db/Adapter/Pdo/MysqlTest.php

index 1348f5a..adaec96 100644 (file)
@@ -108,10 +108,7 @@ abstract class Horde_Db_Adapter_Base implements Horde_Db_Adapter
     /**
      * Constructor.
      *
-     * @param array $config  Configuration options and optional objects:
-     * <pre>
-     * 'charset' - (string) TODO
-     * </pre>
+     * @param array $config  Configuration options and optional objects.
      */
     public function __construct($config)
     {
@@ -121,11 +118,6 @@ abstract class Horde_Db_Adapter_Base implements Horde_Db_Adapter
         $this->_cache = new Horde_Support_Stub();
         $this->_logger = new Horde_Support_Stub();
 
-        // Default to UTF-8
-        if (!isset($config['charset'])) {
-            $config['charset'] = 'UTF-8';
-        }
-
         $this->_config  = $config;
         $this->_runtime = 0;
 
index 3f11e42..2ad4ccc 100644 (file)
@@ -101,11 +101,6 @@ class Horde_Db_Adapter_Mysql extends Horde_Db_Adapter_Base
 
         $this->_connection = $mysql;
         $this->_active     = true;
-
-        // Set the default charset. http://dev.mysql.com/doc/refman/5.1/en/charset-connection.html
-        if (!empty($config['charset'])) {
-            $this->setCharset($config['charset']);
-        }
     }
 
     /**
index 005ce34..66ab22e 100644 (file)
@@ -131,54 +131,6 @@ class Horde_Db_Adapter_Mysql_Schema extends Horde_Db_Adapter_Base_Schema
     }
 
     /**
-     * Returns the database character set that query results are in
-     *
-     * @return string
-     */
-    public function getCharset()
-    {
-        return $this->showVariable('character_set_results');
-    }
-
-    /**
-     * Set the client and result charset.
-     *
-     * @param string $charset  The character set to use for client queries and results.
-     */
-    public function setCharset($charset)
-    {
-        $charset = $this->_mysqlCharsetName($charset);
-        $this->execute('SET NAMES ' . $this->quoteString($charset));
-    }
-
-    /**
-     * Get the MySQL name of a given character set.
-     *
-     * @param string $charset
-     * @return string MySQL-normalized charset.
-     */
-    public function _mysqlCharsetName($charset)
-    {
-        $charset = strtolower(preg_replace(array('/[^a-zA-Z0-9]/', '/iso8859(\d)/'), array('', 'latin$1'), $charset));
-        $validCharsets = $this->selectValues('SHOW CHARACTER SET');
-        if (!in_array($charset, $validCharsets)) {
-            throw new Horde_Db_Exception($charset . ' is not supported by MySQL');
-        }
-
-        return $charset;
-    }
-
-    /**
-     * Returns the database collation strategy
-     *
-     * @return string
-     */
-    public function getCollation()
-    {
-        return $this->showVariable('collation_database');
-    }
-
-    /**
      * List of tables for the db
      *
      * @param   string  $name
@@ -271,10 +223,13 @@ class Horde_Db_Adapter_Mysql_Schema extends Horde_Db_Adapter_Base_Schema
      * @param   string  $name
      * @param   array   $options
      */
-    public function endTable($name, $options=array())
+    public function endTable($name, $options = array())
     {
-        $opts = array('options' => 'ENGINE=InnoDB DEFAULT CHARSET=' . $this->getCharset());
-        return parent::endTable($name, array_merge($opts, $options));
+        $opts = 'ENGINE=InnoDB';
+        if (!empty($options['charset'])) {
+            $opts .=' DEFAULT CHARSET=' . $options['charset'];
+        }
+        return parent::endTable($name, array_merge(array('options' => $opts), $options));
     }
 
     /**
index a8c2f9d..185e6c3 100644 (file)
@@ -149,12 +149,6 @@ class Horde_Db_Adapter_Mysqli extends Horde_Db_Adapter_Base
 
         $this->_connection = $mysqli;
         $this->_active     = true;
-
-        // Set the default charset. http://dev.mysql.com/doc/refman/5.1/en/charset-connection.html
-        if (!empty($config['charset'])) {
-            $this->setCharset($config['charset']);
-        }
-
         $this->_hasMysqliFetchAll = function_exists('mysqli_fetch_all');
     }
 
index 938172d..250d8ab 100644 (file)
@@ -63,11 +63,6 @@ class Horde_Db_Adapter_Pdo_Mysql extends Horde_Db_Adapter_Pdo_Base
         parent::connect();
 
         // ? $this->_connection->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
-
-        // Set the default charset. http://dev.mysql.com/doc/refman/5.1/en/charset-connection.html
-        if (!empty($this->_config['charset'])) {
-            $this->setCharset($this->_config['charset']);
-        }
     }
 
 
index 00cb5f4..0824044 100644 (file)
@@ -128,11 +128,6 @@ class Horde_Db_Adapter_MysqlTest extends PHPUnit_Framework_TestCase
         $this->assertTrue($this->_conn->supportsCountDistinct());
     }
 
-    public function testGetCharset()
-    {
-        $this->assertEquals('utf8', strtolower($this->_conn->getCharset()));
-    }
-
 
     /*##########################################################################
     # Database Statements
index fe92d4b..6fac38d 100644 (file)
@@ -128,11 +128,6 @@ class Horde_Db_Adapter_MysqliTest extends PHPUnit_Framework_TestCase
         $this->assertTrue($this->_conn->supportsCountDistinct());
     }
 
-    public function testGetCharset()
-    {
-        $this->assertEquals('utf8', strtolower($this->_conn->getCharset()));
-    }
-
 
     /*##########################################################################
     # Database Statements
index 0a47344..f0f7b94 100644 (file)
@@ -128,11 +128,6 @@ class Horde_Db_Adapter_Pdo_MysqlTest extends PHPUnit_Framework_TestCase
         $this->assertTrue($this->_conn->supportsCountDistinct());
     }
 
-    public function testGetCharset()
-    {
-        $this->assertEquals('utf8', strtolower($this->_conn->getCharset()));
-    }
-
 
     /*##########################################################################
     # Database Statements