Skip to content

Commit

Permalink
execute*() should return the number of affected rows.
Browse files Browse the repository at this point in the history
  • Loading branch information
kgaughan committed Oct 10, 2012
1 parent 8ab76c1 commit c9bc83d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
16 changes: 11 additions & 5 deletions dbkit.py
Expand Up @@ -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'

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
3 changes: 2 additions & 1 deletion tests/fakedb.py
Expand Up @@ -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
Expand All @@ -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')
Expand Down

0 comments on commit c9bc83d

Please sign in to comment.