]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Improve Oracle identifier length detection
authorFederico Caselli <cfederico87@gmail.com>
Sat, 26 Oct 2024 19:50:36 +0000 (21:50 +0200)
committerFederico Caselli <cfederico87@gmail.com>
Thu, 7 Nov 2024 19:54:35 +0000 (20:54 +0100)
Use the connection attribute ``max_identifier_length`` available
in oracledb since version 2.5 when determining the identifier length
in the Oracle dialect.

Fixes: #12032
Change-Id: If16db93e0df25776295bc521706dbad1cc541f4a
(cherry picked from commit 90bf575b81c5396b364908547551b6592a333bf7)

doc/build/changelog/unreleased_20/12032.rst [new file with mode: 0644]
lib/sqlalchemy/dialects/oracle/base.py
lib/sqlalchemy/dialects/oracle/oracledb.py

diff --git a/doc/build/changelog/unreleased_20/12032.rst b/doc/build/changelog/unreleased_20/12032.rst
new file mode 100644 (file)
index 0000000..5a40732
--- /dev/null
@@ -0,0 +1,7 @@
+.. change::
+    :tags: oracle, usecase
+    :tickets: 12032 
+
+    Use the connection attribute ``max_identifier_length`` available
+    in oracledb since version 2.5 when determining the identifier length
+    in the Oracle dialect.
index abf3645c76893e471475bcfa905023654ded7104..30b575140f2477260bbf429cfdb5767ce28a0a71 100644 (file)
@@ -176,12 +176,15 @@ To assist with this change and others, Oracle includes the concept of a
 actual server version in order to assist with migration of Oracle databases,
 and may be configured within the Oracle server itself. This compatibility
 version is retrieved using the query  ``SELECT value FROM v$parameter WHERE
-name = 'compatible';``.   The SQLAlchemy Oracle dialect, when tasked with
-determining the default max identifier length, will attempt to use this query
-upon first connect in order to determine the effective compatibility version of
-the server, which determines what the maximum allowed identifier length is for
-the server.  If the table is not available, the  server version information is
-used instead.
+name = 'compatible';``. 
+The SQLAlchemy Oracle dialect, when tasked with determining the default max
+identifier length, will use the ``max_identifier_length`` attribute available
+in the connection of the oracledb driver since version 2.5. When using an older
+version or cx_oracle SQLAlchemy will instead attempted to use the query
+mentioned above upon first connect in order to determine the effective
+compatibility version of the server, which determines what the maximum allowed
+identifier length is for the server. If the table is not available, the server
+version information is used instead.
 
 As of SQLAlchemy 1.4, the default max identifier length for the Oracle dialect
 is 128 characters.  Upon first connect, the compatibility version is detected
index 0667ed768e80fc4d5067c844d054cdb2854df69e..bdeb535e689e97874a74bde331c7613cb9295355 100644 (file)
@@ -221,6 +221,12 @@ class OracleDialect_oracledb(_cx_oracle.OracleDialect_cx_oracle):
             for fi, gti, bq in connection.connection.tpc_recover()
         ]
 
+    def _check_max_identifier_length(self, connection):
+        if self.oracledb_ver >= (2, 5):
+            return connection.connection.max_identifier_length
+        else:
+            super()._check_max_identifier_length(connection)
+
 
 class AsyncAdapt_oracledb_cursor(AsyncAdapt_dbapi_cursor):
     _cursor: AsyncCursor
@@ -251,7 +257,7 @@ class AsyncAdapt_oracledb_cursor(AsyncAdapt_dbapi_cursor):
             self._adapt_connection._handle_exception(error)
 
     async def _execute_async(self, operation, parameters):
-        # override to not use mutex, oracledb already has mutex
+        # override to not use mutex, oracledb already has mutex
 
         if parameters is None:
             result = await self._cursor.execute(operation)
@@ -267,7 +273,7 @@ class AsyncAdapt_oracledb_cursor(AsyncAdapt_dbapi_cursor):
         operation,
         seq_of_parameters,
     ):
-        # override to not use mutex, oracledb already has mutex
+        # override to not use mutex, oracledb already has mutex
         return await self._cursor.executemany(operation, seq_of_parameters)
 
     def __enter__(self):
@@ -325,6 +331,10 @@ class AsyncAdapt_oracledb_connection(AsyncAdapt_dbapi_connection):
     def stmtcachesize(self, value):
         self._connection.stmtcachesize = value
 
+    @property
+    def max_identifier_length(self):
+        return self._connection.max_identifier_length
+
     def cursor(self):
         return AsyncAdapt_oracledb_cursor(self)