Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

last_row_count and last_row_id added to context.

  • Loading branch information...
commit 339705de4fbb2e8bb7d3019b7642b82a12675bef 1 parent c9bc83d
@kgaughan authored
Showing with 11 additions and 1 deletion.
  1. +10 −1 dbkit.py
  2. +1 −0  tests/test_dbkit.py
View
11 dbkit.py
@@ -91,7 +91,9 @@ def __len__(self):
class Context(object):
"""A database connection context."""
- __slots__ = ('_mdr', '_depth', 'logger', 'default_factory') + _EXCEPTIONS
+ __slots__ = (
+ '_mdr', '_depth', 'logger', 'default_factory',
+ 'last_row_count', 'last_row_id') + _EXCEPTIONS
stack = _ContextStack()
def __init__(self, module, mdr):
@@ -103,6 +105,8 @@ def __init__(self, module, mdr):
self._depth = 0
self.logger = null_logger
self.default_factory = tuple_set
+ self.last_row_count = None
+ self.last_row_id = None
# Copy driver module's exception references.
for exc in _EXCEPTIONS:
setattr(self, exc, getattr(module, exc))
@@ -155,7 +159,12 @@ def cursor(self):
cursor = self._mdr.cursor()
try:
yield cursor
+ if cursor.rowcount != -1:
+ self.last_row_count = cursor.rowcount
+ self.last_row_id = getattr(cursor, 'lastrowid', None)
except:
+ self.last_row_count = None
+ self.last_row_id = None
cursor.close()
raise
View
1  tests/test_dbkit.py
@@ -41,6 +41,7 @@ def setup():
dbkit.execute(SCHEMA)
with dbkit.transaction():
dbkit.execute(TEST_DATA)
+ assert ctx.last_row_count == 1
return ctx
Please sign in to comment.
Something went wrong with that request. Please try again.