From: Mike Bayer Date: Sun, 21 Apr 2013 21:09:45 +0000 (-0400) Subject: - Improvements to the operation of the pymysql dialect on X-Git-Tag: rel_0_8_1~11^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=23c744b54e94a0d003a7e7236af7868cc31a1161;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - Improvements to the operation of the pymysql dialect on Python 3, including some important decode/bytes steps. Issues remain with BLOB types due to driver issues. Courtesy Ben Trofatter. - start using util.py3k, we will eventually remove the sa2to3 fixer entirely --- diff --git a/doc/build/changelog/changelog_08.rst b/doc/build/changelog/changelog_08.rst index 175eae66c4..a232499d61 100644 --- a/doc/build/changelog/changelog_08.rst +++ b/doc/build/changelog/changelog_08.rst @@ -6,6 +6,15 @@ .. changelog:: :version: 0.8.1 + .. change:: + :tags: bug, mysql + :tickets: 2663 + + Improvements to the operation of the pymysql dialect on + Python 3, including some important decode/bytes steps. + Issues remain with BLOB types due to driver issues. + Courtesy Ben Trofatter. + .. change:: :tags: bug, orm :tickets: 2710 diff --git a/lib/sqlalchemy/dialects/mysql/base.py b/lib/sqlalchemy/dialects/mysql/base.py index 4888398d9e..b55bc10900 100644 --- a/lib/sqlalchemy/dialects/mysql/base.py +++ b/lib/sqlalchemy/dialects/mysql/base.py @@ -1932,11 +1932,8 @@ class MySQLDialect(default.DefaultDialect): cursor.execute('SELECT @@tx_isolation') val = cursor.fetchone()[0] cursor.close() - # Py3K - #if isinstance(val, bytes): - # val = val.decode() - # Py2K - # end Py2K + if util.py3k and isinstance(val, bytes): + val = val.decode() return val.upper().replace("-", " ") def do_commit(self, dbapi_connection): diff --git a/lib/sqlalchemy/dialects/mysql/pymysql.py b/lib/sqlalchemy/dialects/mysql/pymysql.py index 25e2dadd3c..ba48017ac9 100644 --- a/lib/sqlalchemy/dialects/mysql/pymysql.py +++ b/lib/sqlalchemy/dialects/mysql/pymysql.py @@ -22,27 +22,23 @@ the pymysql driver as well. """ from .mysqldb import MySQLDialect_mysqldb - +from ...util import py3k class MySQLDialect_pymysql(MySQLDialect_mysqldb): driver = 'pymysql' description_encoding = None - # Py3K - #supports_unicode_statements = True - # Py2K - # end Py2K + if py3k: + supports_unicode_statements = True @classmethod def dbapi(cls): return __import__('pymysql') - # Py3K - #def _extract_error_code(self, exception): - # if isinstance(exception.args[0], Exception): - # exception = exception.args[0] - # return exception.args[0] - # Py2K - # end Py2K + if py3k: + def _extract_error_code(self, exception): + if isinstance(exception.args[0], Exception): + exception = exception.args[0] + return exception.args[0] dialect = MySQLDialect_pymysql diff --git a/test/sql/test_types.py b/test/sql/test_types.py index 37c5039c78..407869f154 100644 --- a/test/sql/test_types.py +++ b/test/sql/test_types.py @@ -1,14 +1,13 @@ # coding: utf-8 from sqlalchemy.testing import eq_, assert_raises, assert_raises_message import decimal -import datetime, os, re +import datetime +import os from sqlalchemy import * -from sqlalchemy import exc, types, util, schema, dialects +from sqlalchemy import exc, types, util, dialects for name in dialects.__all__: __import__("sqlalchemy.dialects.%s" % name) from sqlalchemy.sql import operators, column, table -from sqlalchemy.testing import eq_ -import sqlalchemy.engine.url as url from sqlalchemy.engine import default from sqlalchemy.testing.schema import Table, Column from sqlalchemy import testing @@ -677,7 +676,7 @@ class UnicodeTest(fixtures.TestBase): if (testing.against('mssql+pyodbc') and not testing.db.dialect.freetds) \ - or testing.against('mssql+mxodbc'): + or testing.against('mssql+mxodbc'): eq_( testing.db.dialect.returns_unicode_strings, 'conditional' @@ -689,25 +688,12 @@ class UnicodeTest(fixtures.TestBase): ('charset' in testing.db.url.query) ) - elif testing.against('mysql+cymysql'): + elif testing.against('mysql+cymysql', 'mysql+pymssql'): eq_( testing.db.dialect.returns_unicode_strings, - # Py3K - #True - # Py2K - False - # end Py2K + True if util.py3k else False ) - elif testing.against('mysql+pymysql'): - eq_( - testing.db.dialect.returns_unicode_strings, - # Py3K - #True - # Py2K - False - # end Py2K - ) else: expected = (testing.db.name, testing.db.driver) in \