summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/expression.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2008-02-08 22:57:45 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2008-02-08 22:57:45 +0000
commit842934f40cba8a6d5266c0f86306c8c1f067dd0f (patch)
tree36fc1f816467546c9ea9e6e1661b041d1b906c9a /lib/sqlalchemy/sql/expression.py
parent1b228e848183b34046fc2ef34206344f88876f3a (diff)
downloadsqlalchemy-842934f40cba8a6d5266c0f86306c8c1f067dd0f.tar.gz
- added generative where(<criterion>) method to delete()
and update() constructs which return a new object with criterion joined to existing criterion via AND, just like select().where(). - compile assertions use assertEquals()
Diffstat (limited to 'lib/sqlalchemy/sql/expression.py')
-rw-r--r--lib/sqlalchemy/sql/expression.py35
1 files changed, 33 insertions, 2 deletions
diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py
index 5c8008f3d..79eb1759d 100644
--- a/lib/sqlalchemy/sql/expression.py
+++ b/lib/sqlalchemy/sql/expression.py
@@ -2178,6 +2178,9 @@ class _Exists(_UnaryExpression):
return e
def where(self, clause):
+ """return a new exists() construct with the given expression added to its WHERE clause, joined
+ to the existing clause via AND, if any."""
+
e = self._clone()
e.element = self.element.where(clause).self_group()
return e
@@ -3493,7 +3496,10 @@ class Insert(_UpdateBase):
class Update(_UpdateBase):
def __init__(self, table, whereclause, values=None, inline=False, **kwargs):
self.table = table
- self._whereclause = whereclause
+ if whereclause:
+ self._whereclause = _literal_as_text(whereclause)
+ else:
+ self._whereclause = None
self.inline = inline
self.parameters = self._process_colparams(values)
@@ -3509,6 +3515,17 @@ class Update(_UpdateBase):
self._whereclause = clone(self._whereclause)
self.parameters = self.parameters.copy()
+ def where(self, whereclause):
+ """return a new update() construct with the given expression added to its WHERE clause, joined
+ to the existing clause via AND, if any."""
+
+ s = self._clone()
+ if s._whereclause is not None:
+ s._whereclause = and_(s._whereclause, _literal_as_text(whereclause))
+ else:
+ s._whereclause = _literal_as_text(whereclause)
+ return s
+
def values(self, v):
if len(v) == 0:
return self
@@ -3523,7 +3540,10 @@ class Update(_UpdateBase):
class Delete(_UpdateBase):
def __init__(self, table, whereclause):
self.table = table
- self._whereclause = whereclause
+ if whereclause:
+ self._whereclause = _literal_as_text(whereclause)
+ else:
+ self._whereclause = None
def get_children(self, **kwargs):
if self._whereclause is not None:
@@ -3531,6 +3551,17 @@ class Delete(_UpdateBase):
else:
return ()
+ def where(self, whereclause):
+ """return a new delete() construct with the given expression added to its WHERE clause, joined
+ to the existing clause via AND, if any."""
+
+ s = self._clone()
+ if s._whereclause is not None:
+ s._whereclause = and_(s._whereclause, _literal_as_text(whereclause))
+ else:
+ s._whereclause = _literal_as_text(whereclause)
+ return s
+
def _copy_internals(self, clone=_clone):
self._whereclause = clone(self._whereclause)