From: Georg Sieber Date: Wed, 4 Mar 2026 23:24:44 +0000 (-0500) Subject: Add fast_executemany property to asyncadapt aioodbc cursor X-Git-Tag: rel_2_1_0b2~34 X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=f09778c70050391ab77e97e8043083f6a5177038;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Add fast_executemany property to asyncadapt aioodbc cursor 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 --- diff --git a/doc/build/changelog/unreleased_20/13152.rst b/doc/build/changelog/unreleased_20/13152.rst new file mode 100644 index 0000000000..47334ed231 --- /dev/null +++ b/doc/build/changelog/unreleased_20/13152.rst @@ -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. diff --git a/lib/sqlalchemy/connectors/aioodbc.py b/lib/sqlalchemy/connectors/aioodbc.py index a0c7302dd6..e1e4fba619 100644 --- a/lib/sqlalchemy/connectors/aioodbc.py +++ b/lib/sqlalchemy/connectors/aioodbc.py @@ -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)) diff --git a/test/requirements.py b/test/requirements.py index 164c407d5e..0c11efa898 100644 --- a/test/requirements.py +++ b/test/requirements.py @@ -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'.