This can be used for more control over the underlying transactions. Unlike
the context manager of, say, a file object, we can still use the object even
after the end of a given with block, as the context manager exit only ensures
we've committed to the database, not that we have closed the database.
Signed-off-by: Chris Larson <chris_larson@mentor.com>
def _execute(self, *query):
return self.cursor.execute(*query)
+ def __enter__(self):
+ self.cursor.__enter__()
+ return self
+
+ def __exit__(self, *excinfo):
+ self.cursor.__exit__(*excinfo)
+
def __getitem__(self, key):
data = self._execute("SELECT * from %s where key=?;" %
self.table, [key])