Support with statement by adding __enter__ and __exit__ to Cursor and Connection classes
parent
a1b87626ab
commit
e6a25206ee
|
|
@ -441,6 +441,12 @@ class Connection(object):
|
||||||
def cursor(self):
|
def cursor(self):
|
||||||
return Cursor(self, self._converters)
|
return Cursor(self, self._converters)
|
||||||
|
|
||||||
|
def __enter__(self):
|
||||||
|
return self
|
||||||
|
|
||||||
|
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||||
|
self.close()
|
||||||
|
|
||||||
# DB-API 2.0 Cursor Object
|
# DB-API 2.0 Cursor Object
|
||||||
class Cursor(object):
|
class Cursor(object):
|
||||||
|
|
||||||
|
|
@ -594,6 +600,12 @@ class Cursor(object):
|
||||||
def setoutputsize(self, size, column=None):
|
def setoutputsize(self, size, column=None):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def __enter__(self):
|
||||||
|
return self
|
||||||
|
|
||||||
|
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||||
|
self.close()
|
||||||
|
|
||||||
def _unknownSqlTypeConverter(rs, col):
|
def _unknownSqlTypeConverter(rs, col):
|
||||||
return rs.getObject(col)
|
return rs.getObject(col)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue