Skip to content
Browse files

execute*() should return the number of affected rows.

  • Loading branch information...
1 parent 8ab76c1 commit c9bc83d0ce2a31f843507cb8089facbef4c96e5a @kgaughan committed
Showing with 13 additions and 6 deletions.
  1. +11 −5 dbkit.py
  2. +2 −1 tests/fakedb.py
View
16 dbkit.py
@@ -29,7 +29,7 @@
'unindent_statement', 'make_file_object_logger',
'null_logger', 'stderr_logger')
-__version__ = '0.1.3'
+__version__ = '0.1.4'
__author__ = 'Keith Gaughan'
__email__ = 'k@stereochro.me'
@@ -590,8 +590,11 @@ def wrapper(*args, **kwargs):
def execute(stmt, args=()):
- """Execute an SQL statement."""
- Context.current().execute(stmt, args).close()
+ """Execute an SQL statement. Returns the number of affected rows."""
+ cursor = Context.current().execute(stmt, args)
+ row_count = cursor.rowcount
+ cursor.close()
+ return row_count
def query(stmt, args=(), factory=None):
@@ -625,8 +628,11 @@ def query_column(stmt, args=()):
def execute_proc(procname, args=()):
- """Execute a stored procedure."""
- Context.current().execute_proc(procname, args).close()
+ """Execute a stored procedure. Returns the number of affected rows."""
+ cursor = Context.current().execute_proc(procname, args)
+ row_count = cursor.rowcount
+ cursor.close()
+ return row_count
def query_proc(procname, args=(), factory=None):
View
3 tests/fakedb.py
@@ -56,7 +56,7 @@ class Cursor(object):
A fake cursor.
"""
- __slots__ = ['connection', 'valid', 'result']
+ __slots__ = ['connection', 'valid', 'result', 'rowcount']
def __init__(self, connection):
self.connection = connection
@@ -66,6 +66,7 @@ def __init__(self, connection):
raise OperationalError()
connection.cursors += 1
self.valid = True
+ self.rowcount = -1
def close(self):
self.connection.session.append('cursor-close')

0 comments on commit c9bc83d

Please sign in to comment.
Something went wrong with that request. Please try again.