]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Slightly changed behavior of IN operator for comparing to empty collections. Now...
authorAnts Aasma <ants.aasma@gmail.com>
Mon, 20 Oct 2008 20:41:09 +0000 (20:41 +0000)
committerAnts Aasma <ants.aasma@gmail.com>
Mon, 20 Oct 2008 20:41:09 +0000 (20:41 +0000)
CHANGES
lib/sqlalchemy/sql/expression.py
test/sql/query.py
test/sql/select.py

diff --git a/CHANGES b/CHANGES
index 60716cc3c93e05c496e6b05a5211e90851e0fd1c..12e14b7f13a9f29c66f72936d73ad7e4834f4f15 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -33,6 +33,11 @@ CHANGES
     - Removed "default_order_by()" method on all FromClause
       objects.
 
+    - Slightly changed behavior of IN operator for comparing to
+      empty collections. Now results in inequality comparison
+      against self. More portable, but breaks with stored
+      procedures that aren't pure functions.
+
 0.5.0rc2
 ========
 - orm
index b721e5884b7e4ae988f4f75fd241e38e34a5c4d9..cb2bcd6d606b43e50f50573d947b34922f9984f3 100644 (file)
@@ -1383,8 +1383,8 @@ class _CompareMixin(ColumnOperators):
             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')))
+            # Special case handling for empty IN's, behave like comparison against zero row selectable
+            return self != self
 
         return self.__compare(op, ClauseList(*args).self_group(against=op), negate=negate_op)
 
index c5b9b5d35c29db927ed19640650c5455da77b222..4d52c276498e3abcd5193ae94d5996843fc932fe 100644 (file)
@@ -550,7 +550,6 @@ class QueryTest(TestBase):
         finally:
             shadowed.drop(checkfirst=True)
 
-    @testing.fails_on('firebird', 'maxdb', 'oracle')
     def test_in_filtering(self):
         """test the behavior of the in_() function."""
 
@@ -591,6 +590,14 @@ class QueryTest(TestBase):
         r = s.execute(search_key=None).fetchall()
         assert len(r) == 0
 
+    @testing.fails_on('firebird', 'maxdb', 'oracle')
+    def test_in_filtering_advanced(self):
+        """test the behavior of the in_() function when comparing against an empty collection."""
+
+        users.insert().execute(user_id = 7, user_name = 'jack')
+        users.insert().execute(user_id = 8, user_name = 'fred')
+        users.insert().execute(user_id = 9, user_name = None)
+
         s = users.select(users.c.user_name.in_([]) == True)
         r = s.execute().fetchall()
         assert len(r) == 0
index 52aa151d9388ad1f51fcfa84fbef712966d39cf7..e959a79922e66676af39d3d22d305cecb7a591a9 100644 (file)
@@ -1185,7 +1185,7 @@ UNION SELECT mytable.myid FROM mytable WHERE mytable.myid = :myid_2)")
 
         # test empty in clause
         self.assert_compile(select([table1], table1.c.myid.in_([])),
-        "SELECT mytable.myid, mytable.name, mytable.description FROM mytable WHERE (CASE WHEN (mytable.myid IS NULL) THEN NULL ELSE 0 END = 1)")
+        "SELECT mytable.myid, mytable.name, mytable.description FROM mytable WHERE mytable.myid != mytable.myid")
 
         self.assert_compile(
             select([table1.c.myid.in_(select([table2.c.otherid]))]),