From aeb15317e040b1f7a074744714afc687dbae7bd0 Mon Sep 17 00:00:00 2001 From: mdipierro Date: Fri, 9 Aug 2013 11:05:52 -0500 Subject: [PATCH] smarted BELONGS, thanks Jonathan --- VERSION | 2 +- gluon/dal.py | 17 +++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/VERSION b/VERSION index 1a02ba1c..06fa786f 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -Version 2.6.0-development+timestamp.2013.08.09.04.48.26 +Version 2.6.0-development+timestamp.2013.08.09.11.04.59 diff --git a/gluon/dal.py b/gluon/dal.py index 97589908..bafc4e86 100644 --- a/gluon/dal.py +++ b/gluon/dal.py @@ -1263,12 +1263,17 @@ class BaseAdapter(ConnectionPool): return '(%s OR %s)' % (self.expand(first), self.expand(second)) def BELONGS(self, first, second): - if isinstance(second, str): - return '(%s IN (%s))' % (self.expand(first), second[:-1]) - elif not second: - return '(1=0)' - items = ','.join(self.expand(item, first.type) for item in second) - return '(%s IN (%s))' % (self.expand(first), items) + if isinstance(second, str): + return '(%s IN (%s))' % (self.expand(first), second[:-1]) + if not second: + return '(1=0)' + if isinstance(second, (list,tuple,frozenset)): + second = set(second) # remove duplicates, make mutable + if isinstance(second, set) and None in second: + second = second.remove(None) + return self.OR(self.EQ(first, None), self.BELONGS(first, second)) + items = ','.join(self.expand(item, first.type) for item in second) + return '(%s IN (%s))' % (self.expand(first), items) def REGEXP(self, first, second): "regular expression operator"