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.
1 parent bf0ef58 commit a72a2abCopy full SHA for a72a2ab
MySQLdb/connections.py
@@ -216,6 +216,20 @@ def query(self, query):
216
query = bytes(query)
217
_mysql.connection.query(self, query)
218
219
+ def __enter__(self):
220
+ from warnings import warn
221
+ warn("context interface will be changed. Use explicit conn.commit() or conn.rollback().",
222
+ DeprecationWarning, 2)
223
+ if self.get_autocommit():
224
+ self.query("BEGIN")
225
+ return self.cursor()
226
+
227
+ def __exit__(self, exc, value, tb):
228
+ if exc:
229
+ self.rollback()
230
+ else:
231
+ self.commit()
232
233
def _bytes_literal(self, bs):
234
assert isinstance(bs, (bytes, bytearray))
235
x = self.string_literal(bs) # x is escaped and quoted bytes
0 commit comments