summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/expression.py
diff options
context:
space:
mode:
authorAnts Aasma <ants.aasma@gmail.com>2007-10-16 22:57:05 +0000
committerAnts Aasma <ants.aasma@gmail.com>2007-10-16 22:57:05 +0000
commit6bbc7dd157faf5b513852286ba656fa6723cd2d6 (patch)
tree805fc72fd0053fa4eeedc1b72e9ab55651a177c2 /lib/sqlalchemy/sql/expression.py
parentcc0e7c796f61e17cb7050de0701905c65ce558eb (diff)
downloadsqlalchemy-6bbc7dd157faf5b513852286ba656fa6723cd2d6.tar.gz
change the in_ API to accept a sequence or a selectable [ticket:750]
Diffstat (limited to 'lib/sqlalchemy/sql/expression.py')
-rw-r--r--lib/sqlalchemy/sql/expression.py30
1 files changed, 18 insertions, 12 deletions
diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py
index 90c670ce3..73e23cc92 100644
--- a/lib/sqlalchemy/sql/expression.py
+++ b/lib/sqlalchemy/sql/expression.py
@@ -1222,24 +1222,30 @@ class _CompareMixin(ColumnOperators):
return self._in_impl(operators.in_op, operators.notin_op, *other)
def _in_impl(self, op, negate_op, *other):
- if len(other) == 0:
- return _Grouping(case([(self.__eq__(None), text('NULL'))], else_=text('0')).__eq__(text('1')))
- elif len(other) == 1:
- o = other[0]
- if _is_literal(o) or isinstance( o, _CompareMixin):
- return self.__eq__( o) #single item -> ==
- else:
- assert isinstance(o, Selectable)
- return self.__compare( op, o, negate=negate_op) #single selectable
-
+ # Handle old style *args argument passing
+ if len(other) != 1 or not isinstance(other[0], Selectable) and (not hasattr(other[0], '__iter__') or isinstance(other[0], basestring)):
+ util.warn_deprecated('passing in_ arguments as varargs is deprecated, in_ takes a single argument that is a sequence or a selectable')
+ seq_or_selectable = other
+ else:
+ seq_or_selectable = other[0]
+
+ if isinstance(seq_or_selectable, Selectable):
+ return self.__compare( op, seq_or_selectable, negate=negate_op)
+
+ # Handle non selectable arguments as sequences
args = []
- for o in other:
+ for o in seq_or_selectable:
if not _is_literal(o):
if not isinstance( o, _CompareMixin):
- raise exceptions.InvalidRequestError( "in() function accepts either non-selectable values, or a single selectable: "+repr(o) )
+ raise exceptions.InvalidRequestError( "in() function accepts either a list of non-selectable values, or a selectable: "+repr(o) )
else:
o = self._bind_param(o)
args.append(o)
+
+ if len(args) == 0:
+ # Special case handling for empty IN's
+ return _Grouping(case([(self.__eq__(None), text('NULL'))], else_=text('0')).__eq__(text('1')))
+
return self.__compare(op, ClauseList(*args).self_group(against=op), negate=negate_op)
def startswith(self, other):