diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-02-03 12:04:51 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-02-03 12:04:51 -0500 |
commit | 8b08b1a35b85c24349226c34e6834f4f60db3c6f (patch) | |
tree | 5a9f2e63ecc8cb1983b301bb4cd62580bb151926 | |
parent | 37d1f8983ce4bfbfd517cf8db7a44ed785c8474f (diff) | |
download | sqlalchemy-8b08b1a35b85c24349226c34e6834f4f60db3c6f.tar.gz |
- Fixed bug which prevented MySQLdb-based dialects (e.g.
pymysql) from working in Py3K, where a check for "connection
charset" would fail due to Py3K's more strict value comparison
rules. The call in question wasn't taking the database
version into account in any case as the server version was
still None at that point, so the method overall has been
simplified to rely upon connection.character_set_name().
[ticket:2933]
-rw-r--r-- | doc/build/changelog/changelog_08.rst | 13 | ||||
-rw-r--r-- | lib/sqlalchemy/connectors/mysqldb.py | 43 | ||||
-rw-r--r-- | lib/sqlalchemy/dialects/mysql/pymysql.py | 1 | ||||
-rw-r--r-- | lib/sqlalchemy/sql/sqltypes.py | 1 | ||||
-rw-r--r-- | setup.cfg | 2 |
5 files changed, 27 insertions, 33 deletions
diff --git a/doc/build/changelog/changelog_08.rst b/doc/build/changelog/changelog_08.rst index c159089e2..58804899b 100644 --- a/doc/build/changelog/changelog_08.rst +++ b/doc/build/changelog/changelog_08.rst @@ -13,6 +13,19 @@ .. change:: :tags: bug, mysql + :tickets: 2933 + :versions: 0.9.3 + + Fixed bug which prevented MySQLdb-based dialects (e.g. + pymysql) from working in Py3K, where a check for "connection + charset" would fail due to Py3K's more strict value comparison + rules. The call in question wasn't taking the database + version into account in any case as the server version was + still None at that point, so the method overall has been + simplified to rely upon connection.character_set_name(). + + .. change:: + :tags: bug, mysql :pullreq: github:61 :versions: 0.9.2 diff --git a/lib/sqlalchemy/connectors/mysqldb.py b/lib/sqlalchemy/connectors/mysqldb.py index 33e59218b..e4efb2201 100644 --- a/lib/sqlalchemy/connectors/mysqldb.py +++ b/lib/sqlalchemy/connectors/mysqldb.py @@ -128,36 +128,17 @@ class MySQLDBConnector(Connector): def _detect_charset(self, connection): """Sniff out the character set in use for connection results.""" - # Note: MySQL-python 1.2.1c7 seems to ignore changes made - # on a connection via set_character_set() - if self.server_version_info < (4, 1, 0): - try: - return connection.connection.character_set_name() - except AttributeError: - # < 1.2.1 final MySQL-python drivers have no charset support. - # a query is needed. - pass - - # Prefer 'character_set_results' for the current connection over the - # value in the driver. SET NAMES or individual variable SETs will - # change the charset without updating the driver's view of the world. - # - # If it's decided that issuing that sort of SQL leaves you SOL, then - # this can prefer the driver value. - rs = connection.execute("SHOW VARIABLES LIKE 'character_set%%'") - opts = dict([(row[0], row[1]) for row in self._compat_fetchall(rs)]) - - if 'character_set_results' in opts: - return opts['character_set_results'] try: - return connection.connection.character_set_name() + # note: the SQL here would be + # "SHOW VARIABLES LIKE 'character_set%%'" + cset_name = connection.connection.character_set_name except AttributeError: - # Still no charset on < 1.2.1 final... - if 'character_set' in opts: - return opts['character_set'] - else: - util.warn( - "Could not detect the connection character set with this " - "combination of MySQL server and MySQL-python. " - "MySQL-python >= 1.2.2 is recommended. Assuming latin1.") - return 'latin1' + util.warn( + "No 'character_set_name' can be detected with " + "this MySQL-Python version; " + "please upgrade to a recent version of MySQL-Python. " + "Assuming latin1.") + return 'latin1' + else: + return cset_name() + diff --git a/lib/sqlalchemy/dialects/mysql/pymysql.py b/lib/sqlalchemy/dialects/mysql/pymysql.py index 74de09c4d..7989203cf 100644 --- a/lib/sqlalchemy/dialects/mysql/pymysql.py +++ b/lib/sqlalchemy/dialects/mysql/pymysql.py @@ -31,6 +31,7 @@ class MySQLDialect_pymysql(MySQLDialect_mysqldb): if py3k: supports_unicode_statements = True + @classmethod def dbapi(cls): return __import__('pymysql') diff --git a/lib/sqlalchemy/sql/sqltypes.py b/lib/sqlalchemy/sql/sqltypes.py index 61d906e1c..fee424e65 100644 --- a/lib/sqlalchemy/sql/sqltypes.py +++ b/lib/sqlalchemy/sql/sqltypes.py @@ -198,7 +198,6 @@ class String(Concatenable, TypeEngine): dialect.returns_unicode_strings and self.convert_unicode != 'force_nocheck' ) - if needs_convert: to_unicode = processors.to_unicode_processor_factory( dialect.encoding, self.unicode_error) @@ -37,7 +37,7 @@ mysql_jython=mysql+zxjdbc://scott:tiger@127.0.0.1:5432/test mysql=mysql://scott:tiger@127.0.0.1:3306/test mssql=mssql+pyodbc://scott:tiger@ms_2005 oursql=mysql+oursql://scott:tiger@127.0.0.1:3306/test -pymysql=mysql+pymysql://scott:tiger@127.0.0.1:3306/test?use_unicode=0&charset=utf8 +pymysql=mysql+pymysql://scott:tiger@127.0.0.1:3306/test oracle=oracle://scott:tiger@127.0.0.1:1521 oracle8=oracle://scott:tiger@127.0.0.1:1521/?use_ansi=0 maxdb=maxdb://MONA:RED@/maxdb1 |