summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
diff options
context:
space:
mode:
authorAnts Aasma <ants.aasma@gmail.com>2008-09-02 20:02:02 +0000
committerAnts Aasma <ants.aasma@gmail.com>2008-09-02 20:02:02 +0000
commit920281ab55b407c9674759fa885797e1a9fff908 (patch)
tree296142024200a89939b3aa0269623ba87d975109 /lib/sqlalchemy
parentc164c174a5b1d2f081493ed34333f98a1503922a (diff)
downloadsqlalchemy-920281ab55b407c9674759fa885797e1a9fff908.tar.gz
Make Query.update and Query.delete return the amount of rows matched
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r--lib/sqlalchemy/orm/query.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py
index 6c20a1fe3..0abf477ad 100644
--- a/lib/sqlalchemy/orm/query.py
+++ b/lib/sqlalchemy/orm/query.py
@@ -1254,6 +1254,8 @@ class Query(object):
The expression evaluator currently doesn't account for differing string
collations between the database and Python.
+ Returns the number of rows deleted, excluding any cascades.
+
Warning - this currently doesn't account for any foreign key/relation cascades.
"""
#TODO: lots of duplication and ifs - probably needs to be refactored to strategies
@@ -1285,7 +1287,7 @@ class Query(object):
if self._autoflush:
session._autoflush()
- session.execute(delete_stmt)
+ result = session.execute(delete_stmt)
if synchronize_session == 'evaluate':
target_cls = self._mapper_zero().class_
@@ -1302,6 +1304,8 @@ class Query(object):
if identity_key in session.identity_map:
session._remove_newly_deleted(attributes.instance_state(session.identity_map[identity_key]))
+ return result.rowcount
+
def update(self, values, synchronize_session='expire'):
"""Perform a bulk update query.
@@ -1327,6 +1331,8 @@ class Query(object):
The expression evaluator currently doesn't account for differing string
collations between the database and Python.
+ Returns the number of rows matched by the update.
+
Warning - this currently doesn't account for any foreign key/relation cascades.
"""
@@ -1363,7 +1369,7 @@ class Query(object):
if self._autoflush:
session._autoflush()
- session.execute(update_stmt)
+ result = session.execute(update_stmt)
if synchronize_session == 'evaluate':
target_cls = self._mapper_zero().class_
@@ -1392,6 +1398,8 @@ class Query(object):
if identity_key in session.identity_map:
session.expire(session.identity_map[identity_key], values.keys())
+ return result.rowcount
+
def _compile_context(self, labels=True):
context = QueryContext(self)