diff options
-rw-r--r-- | doc/build/changelog/changelog_11.rst | 9 | ||||
-rw-r--r-- | lib/sqlalchemy/dialects/oracle/cx_oracle.py | 14 | ||||
-rw-r--r-- | test/dialect/test_oracle.py | 21 |
3 files changed, 42 insertions, 2 deletions
diff --git a/doc/build/changelog/changelog_11.rst b/doc/build/changelog/changelog_11.rst index f284b5b00..c591b483f 100644 --- a/doc/build/changelog/changelog_11.rst +++ b/doc/build/changelog/changelog_11.rst @@ -21,6 +21,15 @@ .. changelog:: :version: 1.1.10 + .. change:: 3975 + :tags: bug, oracle + :versions: 1.2.0b1 + :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. + .. change:: 3980 :tags: bug, ext :versions: 1.2.0b1 diff --git a/lib/sqlalchemy/dialects/oracle/cx_oracle.py b/lib/sqlalchemy/dialects/oracle/cx_oracle.py index 93b6987ac..c28414245 100644 --- a/lib/sqlalchemy/dialects/oracle/cx_oracle.py +++ b/lib/sqlalchemy/dialects/oracle/cx_oracle.py @@ -709,8 +709,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) @@ -778,6 +778,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 diff --git a/test/dialect/test_oracle.py b/test/dialect/test_oracle.py index f6e1e14c7..3219a1b6d 100644 --- a/test/dialect/test_oracle.py +++ b/test/dialect/test_oracle.py @@ -24,6 +24,26 @@ 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 @@ -2260,3 +2280,4 @@ class ServiceNameTest(fixtures.TestBase): create_engine, url_string, _initialize=False ) + |