]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
use regexp to parse cx_oracle version string
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 9 May 2017 16:17:04 +0000 (12:17 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 22 Aug 2017 22:40:58 +0000 (18:40 -0400)
Fixed bug in cx_Oracle dialect where version string parsing would
fail for cx_Oracle version 6.0b1 due to the "b" character.  Version
string parsing is now via a regexp rather than a simple split.

Change-Id: I2af7172b0d7184e3ea3bd051e9fa8d6ca2a571cd
Fixes: #3975
(cherry picked from commit 50484eda7787c3e83c9c88c1841fc63b348ca23c)
(cherry picked from commit ab1eb8109221588c19d72c75af01ea4e8cd68e3f)

doc/build/changelog/unreleased_10/3975.rst [new file with mode: 0644]
lib/sqlalchemy/dialects/oracle/cx_oracle.py
test/dialect/test_oracle.py

diff --git a/doc/build/changelog/unreleased_10/3975.rst b/doc/build/changelog/unreleased_10/3975.rst
new file mode 100644 (file)
index 0000000..5782d02
--- /dev/null
@@ -0,0 +1,8 @@
+.. change:: 3975
+    :tags: bug, oracle
+    :versions: 1.2.0b1, 1.1.10
+    :tickets: 3975
+
+    Fixed bug in cx_Oracle dialect where version string parsing would
+    fail for cx_Oracle version 6.0b1 due to the "b" character.  Version
+    string parsing is now via a regexp rather than a simple split.
index fecaa0039fdfaf81a4924f7e55563fffa75bad99..085d83b5ff09edff3730d0127e1ff4bd54d1d427 100644 (file)
@@ -690,8 +690,8 @@ class OracleDialect_cx_oracle(OracleDialect):
         self._retry_on_12516 = _retry_on_12516
 
         if hasattr(self.dbapi, 'version'):
-            self.cx_oracle_ver = tuple([int(x) for x in
-                                        self.dbapi.version.split('.')])
+            self.cx_oracle_ver = self._parse_cx_oracle_ver(self.dbapi.version)
+
         else:
             self.cx_oracle_ver = (0, 0, 0)
 
@@ -766,6 +766,16 @@ class OracleDialect_cx_oracle(OracleDialect):
                 self.dbapi.BINARY: oracle.RAW(),
             }
 
+    def _parse_cx_oracle_ver(self, version):
+        m = re.match(r'(\d+)\.(\d+)(?:\.(\d+))?', version)
+        if m:
+            return tuple(
+                int(x)
+                for x in m.group(1, 2, 3)
+                if x is not None)
+        else:
+            return (0, 0, 0)
+
     @classmethod
     def dbapi(cls):
         import cx_Oracle
index 1a391642776431a1d64bd884a184d8bad00b4719..af1f09c049b1ed79e4345a9d1e09bbb74177504d 100644 (file)
@@ -21,6 +21,26 @@ import os
 from sqlalchemy import sql
 from sqlalchemy.testing.mock import Mock
 
+class DialectTest(fixtures.TestBase):
+    def test_cx_oracle_version_parse(self):
+        dialect = cx_oracle.OracleDialect_cx_oracle()
+
+        eq_(
+            dialect._parse_cx_oracle_ver("5.2"),
+            (5, 2)
+        )
+
+        eq_(
+            dialect._parse_cx_oracle_ver("5.0.1"),
+            (5, 0, 1)
+        )
+
+        eq_(
+            dialect._parse_cx_oracle_ver("6.0b1"),
+            (6, 0)
+        )
+
+
 class OutParamTest(fixtures.TestBase, AssertsExecutionResults):
     __only_on__ = 'oracle+cx_oracle'
     __backend__ = True
@@ -991,7 +1011,7 @@ drop synonym %(test_schema)s.local_table;
                             oracle_resolve_synonyms=True)
         self.assert_compile(parent.select(),
                 "SELECT %(test_schema)s_pt.id, "
-                "%(test_schema)s_pt.data FROM %(test_schema)s_pt" 
+                "%(test_schema)s_pt.data FROM %(test_schema)s_pt"
                  % {"test_schema": testing.config.test_schema})
         select([parent]).execute().fetchall()
 
@@ -2217,3 +2237,4 @@ class ServiceNameTest(fixtures.TestBase):
             create_engine, url_string,
             _initialize=False
         )
+