]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Improvements to the operation of the pymysql dialect on
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 21 Apr 2013 21:09:45 +0000 (17:09 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 21 Apr 2013 21:09:45 +0000 (17:09 -0400)
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

doc/build/changelog/changelog_08.rst
lib/sqlalchemy/dialects/mysql/base.py
lib/sqlalchemy/dialects/mysql/pymysql.py
test/sql/test_types.py

index 175eae66c4ba03f3094cce5a3763d9695815f858..a232499d61f186c18c7446996e1b8ba3e422ab5c 100644 (file)
@@ -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
index 4888398d9e69e54597b92bfa07551e32fe4ef899..b55bc109007c2b7457431be911207ce1d5e41f00 100644 (file)
@@ -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):
index 25e2dadd3cbfa444c9f570afb1b939d34923e628..ba48017ac9bc14063cca0b5698713b1b15f3a93d 100644 (file)
@@ -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
index 37c5039c78fe30ca5169f0b1ea89b5876fb65fa5..407869f154d9a77c979a1497de223601f0e6ee92 100644 (file)
@@ -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 \