]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
added explicit check for "==null()" to produce IS NULL, documnted "==None", "==null...
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 24 May 2006 16:35:30 +0000 (16:35 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 24 May 2006 16:35:30 +0000 (16:35 +0000)
doc/build/content/sqlconstruction.txt
lib/sqlalchemy/sql.py

index 3e2bf6cf5f45277c70318719aca6fe3e0fc550e1..aa97687671afd5af6df5f06aca93fa86576ea94d 100644 (file)
@@ -274,6 +274,18 @@ Supported column operators so far are all the numerical comparison operators, i.
     # any custom operator
     select([users.c.user_name.op('||')('_category')])
 
+    # "null" comparison via == (converts to IS)
+    {sql}users.select(users.c.user_name==None).execute()
+    SELECT users.user_id, users.user_name, users.password 
+    FROM users 
+    WHERE users.user_name IS NULL
+
+    # or via explicit null() construct
+    {sql}users.select(users.c.user_name==null()).execute()
+    SELECT users.user_id, users.user_name, users.password 
+    FROM users 
+    WHERE users.user_name IS NULL
+
 #### Specifying the Engine {@name=engine}
 
 For queries that don't contain any tables, the SQLEngine can be specified to any constructed statement via the `engine` keyword parameter:
index fc0346b855f83cae4758553d0316a2046cf31a75..38866184f8ed423491646fbba225b3b60eb3da5f 100644 (file)
@@ -549,17 +549,16 @@ class CompareMixin(object):
     def _bind_param(self, obj):
         return BindParamClause('literal', obj, shortname=None, type=self.type)
     def _compare(self, operator, obj):
-        if _is_literal(obj):
-            if obj is None:
-                if operator == '=':
-                    return BooleanExpression(self._compare_self(), null(), 'IS')
-                elif operator == '!=':
-                    return BooleanExpression(self._compare_self(), null(), 'IS NOT')
-                else:
-                    raise exceptions.ArgumentError("Only '='/'!=' operators can be used with NULL")
+        if obj is None or isinstance(obj, Null):
+            if operator == '=':
+                return BooleanExpression(self._compare_self(), null(), 'IS')
+            elif operator == '!=':
+                return BooleanExpression(self._compare_self(), null(), 'IS NOT')
                 return BooleanExpression(self._compare_self(), null(), 'IS')
             else:
-                obj = self._bind_param(obj)
+                raise exceptions.ArgumentError("Only '='/'!=' operators can be used with NULL")
+        elif _is_literal(obj):
+            obj = self._bind_param(obj)
         return BooleanExpression(self._compare_self(), obj, operator, type=self._compare_type(obj))
     def _operate(self, operator, obj):
         if _is_literal(obj):