Skip to content

Commit

Permalink
feat: Use Fast Executemany Mode when using the PyODBC SQL Server dial…
Browse files Browse the repository at this point in the history
…ect, closes wireservices/csvkit#1114
  • Loading branch information
jpmckinney committed Oct 17, 2023
1 parent 4eca73d commit 95da375
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Unreleased
----------

* feat: Use `Fast Executemany Mode <https://docs.sqlalchemy.org/en/20/dialects/mssql.html#fast-executemany-mode>`_ when using the PyODBC SQL Server dialect.
* Add Python 3.12 support.
* Drop support for Python 3.6 (2021-12-23), 3.7 (2023-06-27).

Expand Down
7 changes: 6 additions & 1 deletion agatesql/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import datetime
import decimal
from urllib.parse import urlsplit

import agate
from sqlalchemy import Column, MetaData, Table, UniqueConstraint, create_engine, dialects
Expand Down Expand Up @@ -58,7 +59,11 @@ def get_engine_and_connection(connection_or_string=None):
connection = connection_or_string
return None, connection

engine = create_engine(connection_or_string)
kwargs = {}
if urlsplit(connection_or_string).scheme == 'mssql+pyodbc':
kwargs = {'fast_executemany': True}

engine = create_engine(connection_or_string, **kwargs)
connection = engine.connect()
return engine, connection

Expand Down

0 comments on commit 95da375

Please sign in to comment.