[Sqlalchemy-tickets] Issue #4158: pyodbc SQL Server cursor.fast_executemany (zzzeek/sqlalchemy)
Brought to you by:
zzzeek
From: Danny H. <iss...@bi...> - 2018-01-09 19:59:13
|
New issue 4158: pyodbc SQL Server cursor.fast_executemany https://bitbucket.org/zzzeek/sqlalchemy/issues/4158/pyodbc-sql-server-cursorfast_executemany Danny Hollandmoritz: Hi, pyodbc implemented a different execute_many handling for native Microsoft ODBC drivers, which greatly speeds up bulk inserts. (https://github.com/mkleehammer/pyodbc/issues/120) To use it, "fast_executemany" needs to be set to True on the pyodbc cursor instance. At the moment sqlalchemy does not use this flag. To be able to use this feature with sqlalchemy, i changed dialects.mssql.pyodbc.MSExecutionContext_pyodbc to: ``` #!python class MSExecutionContext_pyodbc(MSExecutionContext): _embedded_scope_identity = False def create_cursor(self): if self._use_server_side_cursor(): self._is_server_side = True return self.create_server_side_cursor() else: self._is_server_side = False cursor = self._dbapi_connection.cursor() cursor.fast_executemany = True return cursor def pre_exec(self): """where appropriate, issue "select scope_identity()" in the same statement. ``` But i am sure, there is a better solution for this. (e.g. as a connection string parameter when initiating a sqlalchemy engine) Would it be possible to implement the usage of pyodbc's fast_executemany natively for the pyodbc mssql dialect? Greetings Danny |