]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- [bug] pyodbc-based dialects now parse the
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 4 Dec 2011 18:29:29 +0000 (13:29 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 4 Dec 2011 18:29:29 +0000 (13:29 -0500)
pyodbc accurately as far as observed
pyodbc strings, including such gems
as "py3-3.0.1-beta4" [ticket:2318]
- [bug] use new pyodbc version detection for
_need_decimal_fix option, [ticket:2318]

CHANGES
lib/sqlalchemy/connectors/pyodbc.py
lib/sqlalchemy/dialects/mssql/pyodbc.py
test/dialect/test_pyodbc.py [new file with mode: 0644]

diff --git a/CHANGES b/CHANGES
index 15a2e2a0167b5fbf9a94b2d2264ac6a61364b91d..12d4826ef7fa45ca737a94cb1e221b0e4d0450a5 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -174,6 +174,12 @@ CHANGES
     wasn't implementing the sort properly, replaced
     with the existing sort algorithm
 
+- pyodbc
+   - [bug] pyodbc-based dialects now parse the 
+     pyodbc accurately as far as observed
+     pyodbc strings, including such gems
+     as "py3-3.0.1-beta4" [ticket:2318]
+
 - postgresql
    - [bug] Postgresql dialect memoizes that an ENUM of a 
      particular name was processed
@@ -199,6 +205,9 @@ CHANGES
     use snapshot isolation instead :) )
     [ticket:2336]
 
+  - [bug] use new pyodbc version detection for
+    _need_decimal_fix option, [ticket:2318]
+
 - mysql
   - [bug] Unicode adjustments allow latest pymysql 
     (post 0.4) to pass 100% on Python 2.
index 562cf927352d7ca56e72c8958f8e77b24b34109b..b90846de00b1cae05785cf7a8c0a64405e2883dd 100644 (file)
@@ -126,6 +126,23 @@ class PyODBCConnector(Connector):
         # run other initialization which asks for user name, etc.
         super(PyODBCConnector, self).initialize(connection)
 
+    def _dbapi_version(self):
+        if not self.dbapi:
+            return ()
+        return self._parse_dbapi_version(self.dbapi.version)
+
+    def _parse_dbapi_version(self, vers):
+        m = re.match(
+                r'(?:py.*-)?([\d\.]+)(?:-(\w+))?',
+                vers
+            )
+        if not m:
+            return ()
+        vers = tuple([int(x) for x in m.group(1).split(".")])
+        if m.group(2):
+            vers += (m.group(2),)
+        return vers
+
     def _get_server_version_info(self, connection):
         dbapi_con = connection.connection
         version = []
index 9b88dce2ab3b618dbe63f1020c7a18e946b91ac1..529cdac509cdc1cb6d963106c11b124abffd799a 100644 (file)
@@ -216,6 +216,6 @@ class MSDialect_pyodbc(PyODBCConnector, MSDialect):
         self.use_scope_identity = self.dbapi and \
                         hasattr(self.dbapi.Cursor, 'nextset')
         self._need_decimal_fix = self.dbapi and \
-                                tuple(self.dbapi.version.split(".")) < (2, 1, 8)
+                            self._dbapi_version() < (2, 1, 8)
 
 dialect = MSDialect_pyodbc
diff --git a/test/dialect/test_pyodbc.py b/test/dialect/test_pyodbc.py
new file mode 100644 (file)
index 0000000..c2aec72
--- /dev/null
@@ -0,0 +1,17 @@
+from test.lib.testing import eq_
+from sqlalchemy.connectors import pyodbc
+from test.lib import fixtures
+
+class PyODBCTest(fixtures.TestBase):
+    def test_pyodbc_version(self):
+        connector = pyodbc.PyODBCConnector()
+        for vers, expected in [
+            ('2.1.8', (2, 1, 8)),
+            ("py3-3.0.1-beta4", (3, 0, 1, 'beta4')),
+            ("10.15.17", (10, 15, 17)),
+            ("crap.crap.crap", ()),
+        ]:
+            eq_(
+                connector._parse_dbapi_version(vers), 
+                expected
+            )
\ No newline at end of file