From f3b6f4f8da5223fae0a1dd948d4266b2e49e317c Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Tue, 14 Mar 2017 12:00:56 -0400 Subject: Add "empty in" strategies; default to "static" The longstanding behavior of the :meth:`.Operators.in_` and :meth:`.Operators.not_in_` operators emitting a warning when the right-hand condition is an empty sequence has been revised; a new flag :paramref:`.create_engine.empty_in_strategy` allows an empty "IN" expression to generate a simple boolean expression, or to invoke the previous behavior of dis-equating the expression to itself, with or without a warning. The default behavior is now to emit the simple boolean expression, allowing an empty IN to be evaulated without any performance penalty. Change-Id: I65cc37f2d7cf65a59bf217136c42fee446929352 Fixes: #3907 --- lib/sqlalchemy/engine/default.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'lib/sqlalchemy/engine/default.py') diff --git a/lib/sqlalchemy/engine/default.py b/lib/sqlalchemy/engine/default.py index 18c3276f8..b8c2d2845 100644 --- a/lib/sqlalchemy/engine/default.py +++ b/lib/sqlalchemy/engine/default.py @@ -178,6 +178,7 @@ class DefaultDialect(interfaces.Dialect): supports_right_nested_joins=None, case_sensitive=True, supports_native_boolean=None, + empty_in_strategy='static', label_length=None, **kwargs): if not getattr(self, 'ported_sqla_06', True): @@ -207,6 +208,17 @@ class DefaultDialect(interfaces.Dialect): self.supports_native_boolean = supports_native_boolean self.case_sensitive = case_sensitive + self.empty_in_strategy = empty_in_strategy + if empty_in_strategy == 'static': + self._use_static_in = True + elif empty_in_strategy in ('dynamic', 'dynamic_warn'): + self._use_static_in = False + self._warn_on_empty_in = empty_in_strategy == 'dynamic_warn' + else: + raise exc.ArgumentError( + "empty_in_strategy may be 'static', " + "'dynamic', or 'dynamic_warn'") + if label_length and label_length > self.max_identifier_length: raise exc.ArgumentError( "Label length of %d is greater than this dialect's" -- cgit v1.2.1