summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2013-04-21 17:09:45 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2013-04-21 17:09:45 -0400
commit23c744b54e94a0d003a7e7236af7868cc31a1161 (patch)
treebdf0bf1708f30f34eb2db757040e00c1ecfda64f
parentd5af821b5d564141451f5534a0bb922508e89e70 (diff)
downloadsqlalchemy-23c744b54e94a0d003a7e7236af7868cc31a1161.tar.gz
- 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
-rw-r--r--doc/build/changelog/changelog_08.rst9
-rw-r--r--lib/sqlalchemy/dialects/mysql/base.py7
-rw-r--r--lib/sqlalchemy/dialects/mysql/pymysql.py20
-rw-r--r--test/sql/test_types.py26
4 files changed, 25 insertions, 37 deletions
diff --git a/doc/build/changelog/changelog_08.rst b/doc/build/changelog/changelog_08.rst
index 175eae66c..a232499d6 100644
--- a/doc/build/changelog/changelog_08.rst
+++ b/doc/build/changelog/changelog_08.rst
@@ -7,6 +7,15 @@
: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 4888398d9..b55bc1090 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 25e2dadd3..ba48017ac 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 37c5039c7..407869f15 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 \