]> 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:15 +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

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 473e485a41d58fc0fac42cfc2be06c2f6112b147..9d10691d99774dd4e739785ea14e06c4a484664b 100644 (file)
@@ -188,12 +188,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 377310f642533be8c9008f87509a110fdb54ff79..ec6f7c035c2772dc464d6cbc21efb3fcb62fcbc1 100644 (file)
@@ -217,6 +217,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
@@ -247,7 +253,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)
@@ -263,7 +269,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)
 
 
@@ -315,6 +321,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)