mirror of
https://github.com/sqlalchemy/sqlalchemy.git
synced 2026-05-06 08:56:51 -04:00
added explicit check for "==null()" to produce IS NULL, documnted "==None", "==null()", [ticket:187]
This commit is contained in:
+12
@@ -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:
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user