added explicit check for "==null()" to produce IS NULL, documnted "==None", "==null()", [ticket:187]

This commit is contained in:
Mike Bayer
2006-05-24 16:35:30 +00:00
parent 5156d5141a
commit 4fc3a06486
2 changed files with 20 additions and 9 deletions
+12
View 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:
+8 -9
View 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):