diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-04-07 14:15:43 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-04-16 13:35:55 -0400 |
commit | 2f617f56f2acdce00b88f746c403cf5ed66d4d27 (patch) | |
tree | 0962f2c43c1a361135ecdab933167fa0963ae58a /lib/sqlalchemy/engine/util.py | |
parent | bd303b10e2bf69169f07447c7272fc71ac931f10 (diff) | |
download | sqlalchemy-2f617f56f2acdce00b88f746c403cf5ed66d4d27.tar.gz |
Create initial 2.0 engine implementation
Implemented the SQLAlchemy 2 :func:`.future.create_engine` function which
is used for forwards compatibility with SQLAlchemy 2. This engine
features always-transactional behavior with autobegin.
Allow execution options per statement execution. This includes
that the before_execute() and after_execute() events now accept
an additional dictionary with these options, empty if not
passed; a legacy event decorator is added for backwards compatibility
which now also emits a deprecation warning.
Add some basic tests for execution, transactions, and
the new result object. Build out on a new testing fixture
that swaps in the future engine completely to start with.
Change-Id: I70e7338bb3f0ce22d2f702537d94bb249bd9fb0a
Fixes: #4644
Diffstat (limited to 'lib/sqlalchemy/engine/util.py')
-rw-r--r-- | lib/sqlalchemy/engine/util.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/sqlalchemy/engine/util.py b/lib/sqlalchemy/engine/util.py index d25927be2..8fb04646f 100644 --- a/lib/sqlalchemy/engine/util.py +++ b/lib/sqlalchemy/engine/util.py @@ -5,7 +5,9 @@ # This module is part of SQLAlchemy and is released under # the MIT License: http://www.opensource.org/licenses/mit-license.php +from .. import exc from .. import util +from ..util import collections_abc def connection_memoize(key): @@ -28,6 +30,8 @@ def connection_memoize(key): def py_fallback(): + # TODO: pass the Connection in so that there can be a standard + # method for warning on parameter format def _distill_params(multiparams, params): # noqa r"""Given arguments from the calling form \*multiparams, \**params, return a list of bind parameter structures, usually a list of @@ -40,6 +44,7 @@ def py_fallback(): if not multiparams: if params: + # TODO: parameter format deprecation warning return [params] else: return [] @@ -64,6 +69,7 @@ def py_fallback(): # execute(stmt, "value") return [[zero]] else: + # TODO: parameter format deprecation warning if hasattr(multiparams[0], "__iter__") and not hasattr( multiparams[0], "strip" ): @@ -74,6 +80,32 @@ def py_fallback(): return locals() +_no_tuple = () +_no_kw = util.immutabledict() + + +def _distill_params_20(params): + if params is None: + return _no_tuple, _no_kw, [] + elif isinstance(params, collections_abc.MutableSequence): # list + if params and not isinstance( + params[0], (collections_abc.Mapping, tuple) + ): + raise exc.ArgumentError( + "List argument must consist only of tuples or dictionaries" + ) + + # the tuple is needed atm by the C version of _distill_params... + return tuple(params), _no_kw, params + elif isinstance( + params, + (collections_abc.Sequence, collections_abc.Mapping), # tuple or dict + ): + return _no_tuple, params, [params] + else: + raise exc.ArgumentError("mapping or sequence expected for parameters") + + try: from sqlalchemy.cutils import _distill_params # noqa except ImportError: |