We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 864e279 + 1c818f8 commit a42fe11Copy full SHA for a42fe11
MySQLdb/cursors.py
@@ -85,13 +85,22 @@ def __init__(self, connection):
85
86
def close(self):
87
"""Close the cursor. No further queries will be possible."""
88
- if self.connection is None or self.connection() is None:
89
- return
90
- while self.nextset():
91
- pass
92
- self.connection = None
93
- self.errorhandler = None
94
- self._result = None
+ try:
+ if self.connection is None or self.connection() is None:
+ return
+ while self.nextset():
+ pass
+ finally:
+ self.connection = None
95
+ self.errorhandler = None
96
+ self._result = None
97
+
98
+ def __enter__(self):
99
+ return self
100
101
+ def __exit__(self, *exc_info):
102
+ del exc_info
103
+ self.close()
104
105
def _check_executed(self):
106
if not self._executed:
0 commit comments