mirror of
https://github.com/PyMySQL/mysqlclient.git
synced 2025-08-15 02:54:29 +08:00
Cursor supports context manager interface
This commit is contained in:
@ -85,13 +85,22 @@ class BaseCursor(object):
|
|||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
"""Close the cursor. No further queries will be possible."""
|
"""Close the cursor. No further queries will be possible."""
|
||||||
if self.connection is None or self.connection() is None:
|
try:
|
||||||
return
|
if self.connection is None or self.connection() is None:
|
||||||
while self.nextset():
|
return
|
||||||
pass
|
while self.nextset():
|
||||||
self.connection = None
|
pass
|
||||||
self.errorhandler = None
|
finally:
|
||||||
self._result = None
|
self.connection = None
|
||||||
|
self.errorhandler = None
|
||||||
|
self._result = None
|
||||||
|
|
||||||
|
def __enter__(self):
|
||||||
|
return self
|
||||||
|
|
||||||
|
def __exit__(self, *exc_info):
|
||||||
|
del exc_info
|
||||||
|
self.close()
|
||||||
|
|
||||||
def _check_executed(self):
|
def _check_executed(self):
|
||||||
if not self._executed:
|
if not self._executed:
|
||||||
|
Reference in New Issue
Block a user