]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Add fast_executemany property to asyncadapt aioodbc cursor
authorGeorg Sieber <georg.sieber@carvaloo.com>
Wed, 4 Mar 2026 23:24:44 +0000 (18:24 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 5 Mar 2026 01:32:13 +0000 (20:32 -0500)
Enhanced the ``aioodbc`` dialect to expose the ``fast_executemany``
attribute of the pyodbc cursor.   This allows the ``fast_executemany``
parameter to work with the ``mssql+aioodbc`` dialect.   Pull request
courtesy Georg Sieber.

Fixes: #13152
Closes: #13151
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/13151
Pull-request-sha: c25aa581afff6d49af74b3d7b58b9635a23556e9

Change-Id: I6f27600b509f4881769ecca944fc0939e26626e6

doc/build/changelog/unreleased_20/13152.rst [new file with mode: 0644]
lib/sqlalchemy/connectors/aioodbc.py
test/requirements.py

diff --git a/doc/build/changelog/unreleased_20/13152.rst b/doc/build/changelog/unreleased_20/13152.rst
new file mode 100644 (file)
index 0000000..47334ed
--- /dev/null
@@ -0,0 +1,8 @@
+.. change::
+    :tags: usecase, mssql
+    :tickets: 13152
+
+    Enhanced the ``aioodbc`` dialect to expose the ``fast_executemany``
+    attribute of the pyodbc cursor.   This allows the ``fast_executemany``
+    parameter to work with the ``mssql+aioodbc`` dialect.   Pull request
+    courtesy Georg Sieber.
index a0c7302dd6aad38f7c075e5dd7f4f147d90150f9..e1e4fba6194ee7204f7cbf8e8596b9128f8c3b25 100644 (file)
@@ -32,6 +32,14 @@ class AsyncAdapt_aioodbc_cursor(AsyncAdapt_dbapi_cursor):
         # how it's supposed to work
         # return await_(self._cursor.setinputsizes(*inputsizes))
 
+    @property
+    def fast_executemany(self):
+        return self._cursor._impl.fast_executemany
+
+    @fast_executemany.setter
+    def fast_executemany(self, value):
+        self._cursor._impl.fast_executemany = value
+
 
 class AsyncAdapt_aioodbc_ss_cursor(
     AsyncAdapt_aioodbc_cursor, AsyncAdapt_dbapi_ss_cursor
@@ -116,6 +124,7 @@ class AsyncAdapt_aioodbc_dbapi(AsyncAdapt_dbapi_module):
             "ProgrammingError",
             "InternalError",
             "NotSupportedError",
+            "SQL_DRIVER_NAME",
             "NUMBER",
             "STRING",
             "DATETIME",
@@ -124,6 +133,7 @@ class AsyncAdapt_aioodbc_dbapi(AsyncAdapt_dbapi_module):
             "BinaryNull",
             "SQL_VARCHAR",
             "SQL_WVARCHAR",
+            "SQL_DECIMAL",
         ):
             setattr(self, name, getattr(self.pyodbc, name))
 
index 164c407d5e9ae7ca3aaace5552b7e428c294fa24..0c11efa89857c4b7afb7e957aebe9ce73e79dd8b 100644 (file)
@@ -1817,12 +1817,23 @@ class DefaultRequirements(SuiteRequirements):
     @property
     def pyodbc_fast_executemany(self):
         def has_fastexecutemany(config):
-            if not against(config, "mssql+pyodbc"):
+            if not against(config, "mssql+pyodbc") and not against(
+                config, "mssql+aioodbc"
+            ):
                 return False
             if config.db.dialect._dbapi_version() < (4, 0, 19):
                 return False
             with config.db.connect() as conn:
-                drivername = conn.connection.driver_connection.getinfo(
+                driver_connection = conn.connection.driver_connection
+
+                # for aioodbc, instead of trying to await, just cheat and
+                # use the pyodbc connection
+                if hasattr(
+                    driver_connection, "__module__"
+                ) and driver_connection.__module__.startswith("aioodbc"):
+                    driver_connection = driver_connection._conn
+
+                drivername = driver_connection.getinfo(
                     config.db.dialect.dbapi.SQL_DRIVER_NAME
                 )
                 # on linux this is something like 'libmsodbcsql-13.1.so.9.2'.