summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2012-09-22 16:14:58 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2012-09-22 16:14:58 -0400
commit1ceda8c23c277fd68bc159962f276d20cfa7bbf1 (patch)
tree438967fd83e543786556bc401f09b1c926cc89c2
parent03cb8ce548a99b97852c25f2fec26ed611afbb5c (diff)
downloadsqlalchemy-1ceda8c23c277fd68bc159962f276d20cfa7bbf1.tar.gz
- [bug] Added missing operators is_(), isnot()
to the ColumnOperators base, so that these long-available operators are present as methods like all the other operators. [ticket:2544]
-rw-r--r--CHANGES5
-rw-r--r--lib/sqlalchemy/sql/expression.py2
-rw-r--r--lib/sqlalchemy/sql/operators.py30
-rw-r--r--test/sql/test_operators.py10
4 files changed, 47 insertions, 0 deletions
diff --git a/CHANGES b/CHANGES
index 3b600d5be..ee9f2da57 100644
--- a/CHANGES
+++ b/CHANGES
@@ -811,6 +811,11 @@ are also present in 0.8.
here, so this has been re-instated and of
course tested. [ticket:2558]
+ - [bug] Added missing operators is_(), isnot()
+ to the ColumnOperators base, so that these long-available
+ operators are present as methods like all
+ the other operators. [ticket:2544]
+
- engine
- [bug] Fixed bug whereby
a disconnect detect + dispose that occurs
diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py
index 6b8010601..50f8061a6 100644
--- a/lib/sqlalchemy/sql/expression.py
+++ b/lib/sqlalchemy/sql/expression.py
@@ -2105,6 +2105,8 @@ class _DefaultColumnComparator(operators.ColumnOperators):
"nullsfirst_op": (_scalar, nullsfirst),
"nullslast_op": (_scalar, nullslast),
"in_op": (_in_impl, operators.notin_op),
+ "is_": (_boolean_compare, operators.is_),
+ "isnot": (_boolean_compare, operators.isnot),
"collate": (_collate_impl,),
"match_op": (_match_impl,),
"distinct_op": (_distinct_impl,),
diff --git a/lib/sqlalchemy/sql/operators.py b/lib/sqlalchemy/sql/operators.py
index 38936231d..ad9fa4668 100644
--- a/lib/sqlalchemy/sql/operators.py
+++ b/lib/sqlalchemy/sql/operators.py
@@ -368,6 +368,36 @@ class ColumnOperators(Operators):
"""
return self.operate(in_op, other)
+ def is_(self, other):
+ """Implement the ``IS`` operator.
+
+ Normally, ``IS`` is generated automatically when comparing to a
+ value of ``None``, which resolves to ``NULL``. However, explicit
+ usage of ``IS`` may be desirable if comparing to boolean values
+ on certain platforms.
+
+ .. versionadded:: 0.7.9
+
+ .. seealso:: :meth:`.ColumnOperators.isnot`
+
+ """
+ return self.operate(is_, other)
+
+ def isnot(self, other):
+ """Implement the ``IS NOT`` operator.
+
+ Normally, ``IS NOT`` is generated automatically when comparing to a
+ value of ``None``, which resolves to ``NULL``. However, explicit
+ usage of ``IS NOT`` may be desirable if comparing to boolean values
+ on certain platforms.
+
+ .. versionadded:: 0.7.9
+
+ .. seealso:: :meth:`.ColumnOperators.is_`
+
+ """
+ return self.operate(isnot, other)
+
def startswith(self, other, **kwargs):
"""Implement the ``startwith`` operator.
diff --git a/test/sql/test_operators.py b/test/sql/test_operators.py
index 4f5659791..a6c99be43 100644
--- a/test/sql/test_operators.py
+++ b/test/sql/test_operators.py
@@ -28,6 +28,10 @@ class DefaultColumnComparatorTest(fixtures.TestBase):
BinaryExpression(left, right, operator)
)
+ assert operator(left, right).compare(
+ BinaryExpression(left, right, operator)
+ )
+
def test_desc(self):
self._do_scalar_test(operators.desc_op, desc)
@@ -37,6 +41,12 @@ class DefaultColumnComparatorTest(fixtures.TestBase):
def test_plus(self):
self._do_operate_test(operators.add)
+ def test_is(self):
+ self._do_operate_test(operators.is_)
+
+ def test_isnot(self):
+ self._do_operate_test(operators.isnot)
+
def test_no_getitem(self):
assert_raises_message(
NotImplementedError,