diff options
| author | mike bayer <mike_mp@zzzcomputing.com> | 2021-03-16 20:39:30 +0000 |
|---|---|---|
| committer | Gerrit Code Review <gerrit@ci3.zzzcomputing.com> | 2021-03-16 20:39:30 +0000 |
| commit | 4a827330616a90b1fa0a10f86d8e7cb6e92047ba (patch) | |
| tree | 53a27b9a85e48a76b36112fa62a846031b382021 /lib | |
| parent | e1e0c7b08362c5ca9f178d292ce683a9ed7d5126 (diff) | |
| parent | 8945b82f5261b2c815634d33c78608252ddbd878 (diff) | |
| download | sqlalchemy-4a827330616a90b1fa0a10f86d8e7cb6e92047ba.tar.gz | |
Merge "Turn off pyodbc setinputsizes() by default"
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/sqlalchemy/connectors/pyodbc.py | 11 | ||||
| -rw-r--r-- | lib/sqlalchemy/dialects/mssql/pyodbc.py | 19 | ||||
| -rw-r--r-- | lib/sqlalchemy/engine/events.py | 11 |
3 files changed, 38 insertions, 3 deletions
diff --git a/lib/sqlalchemy/connectors/pyodbc.py b/lib/sqlalchemy/connectors/pyodbc.py index aa14cd9aa..ddff62db6 100644 --- a/lib/sqlalchemy/connectors/pyodbc.py +++ b/lib/sqlalchemy/connectors/pyodbc.py @@ -24,16 +24,19 @@ class PyODBCConnector(Connector): supports_native_decimal = True default_paramstyle = "named" - use_setinputsizes = True + use_setinputsizes = False # for non-DSN connections, this *may* be used to # hold the desired driver name pyodbc_driver_name = None - def __init__(self, supports_unicode_binds=None, **kw): + def __init__( + self, supports_unicode_binds=None, use_setinputsizes=False, **kw + ): super(PyODBCConnector, self).__init__(**kw) if supports_unicode_binds is not None: self.supports_unicode_binds = supports_unicode_binds + self.use_setinputsizes = use_setinputsizes @classmethod def dbapi(cls): @@ -163,6 +166,10 @@ class PyODBCConnector(Connector): # for the subsequent values if you don't pass a tuple which fails # for types such as pyodbc.SQL_WLONGVARCHAR, which is the datatype # that ticket #5649 is targeting. + + # NOTE: as of #6058, this won't be called if the use_setinputsizes flag + # is False, or if no types were specified in list_of_tuples + cursor.setinputsizes( [ (dbtype, None, None) diff --git a/lib/sqlalchemy/dialects/mssql/pyodbc.py b/lib/sqlalchemy/dialects/mssql/pyodbc.py index 96ac2dff7..ba4fc84ec 100644 --- a/lib/sqlalchemy/dialects/mssql/pyodbc.py +++ b/lib/sqlalchemy/dialects/mssql/pyodbc.py @@ -56,7 +56,7 @@ Other keywords interpreted by the Pyodbc dialect to be passed to ``authentication``. Note that in order for the dialect to recognize these keywords (including the ``driver`` keyword above) they must be all lowercase. -Multiple additional keyword arguments must be separated by an +Multiple additional keyword arguments must be separated by an ampersand (``&``), not a semicolon:: engine = create_engine( @@ -158,6 +158,23 @@ driver in order to use this flag:: `fast executemany <https://github.com/mkleehammer/pyodbc/wiki/Features-beyond-the-DB-API#fast_executemany>`_ - on github +.. _mssql_pyodbc_setinputsizes: + +Setinputsizes Support +----------------------- + +The pyodbc ``cursor.setinputsizes()`` method can be used if necessary. To +enable this hook, pass ``use_setinputsizes=True`` to :func:`_sa.create_engine`:: + + engine = create_engine("mssql+pyodbc://...", use_setinputsizes=True) + +The behavior of the hook can then be customized, as may be necessary +particularly if fast_executemany is in use, via the +:meth:`.DialectEvents.do_setinputsizes` hook. See that method for usage +examples. + +.. versionchanged:: 1.4.1 The pyodbc dialects will not use setinputsizes + unless ``use_setinputsizes=True`` is passed. """ # noqa diff --git a/lib/sqlalchemy/engine/events.py b/lib/sqlalchemy/engine/events.py index fb8e5aeb2..c6e27c03c 100644 --- a/lib/sqlalchemy/engine/events.py +++ b/lib/sqlalchemy/engine/events.py @@ -796,6 +796,17 @@ class DialectEvents(event.Events): the flag ``use_setinputsizes=True``. Dialects which use this include cx_Oracle, pg8000, asyncpg, and pyodbc dialects. + .. note:: + + For use with pyodbc, the ``use_setinputsizes`` flag + must be passed to the dialect, e.g.:: + + create_engine("mssql+pyodbc://...", use_setinputsizes=True) + + .. seealso:: + + :ref:`mssql_pyodbc_setinputsizes` + .. versionadded:: 1.2.9 .. seealso:: |
