Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3dbf035

Browse filesBrowse files
committed
More precise get_autocommit based on server_status.
1 parent c8b2744 commit 3dbf035
Copy full SHA for 3dbf035

File tree

Expand file treeCollapse file tree

2 files changed

+23
-14
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+23
-14
lines changed

‎MySQLdb/connections.py

Copy file name to clipboardExpand all lines: MySQLdb/connections.py
+2-13Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -240,21 +240,10 @@ def string_decoder(s):
240240

241241
def autocommit(self, on):
242242
on = bool(on)
243-
_mysql.connection.autocommit(self, on)
243+
if self.get_autocommit() != on:
244+
_mysql.connection.autocommit(self, on)
244245
self._autocommit = on
245246

246-
def get_autocommit(self):
247-
if self._autocommit is None:
248-
self._update_autocommit()
249-
return self._autocommit
250-
251-
def _update_autocommit(self):
252-
cursor = cursors.Cursor(self)
253-
cursor.execute("SELECT @@AUTOCOMMIT")
254-
row = cursor.fetchone()
255-
self._autocommit = bool(row[0])
256-
cursor.close()
257-
258247
def cursor(self, cursorclass=None):
259248
"""
260249

‎_mysql.c

Copy file name to clipboardExpand all lines: _mysql.c
+21-1Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,21 @@ _mysql_ConnectionObject_autocommit(
891891
if (err) return _mysql_Exception(self);
892892
Py_INCREF(Py_None);
893893
return Py_None;
894-
}
894+
}
895+
896+
static char _mysql_ConnectionObject_get_autocommit__doc__[] =
897+
"Get the autocommit mode. True when enable; False when disable.\n";
898+
899+
static PyObject *
900+
_mysql_ConnectionObject_get_autocommit(
901+
_mysql_ConnectionObject *self,
902+
PyObject *args)
903+
{
904+
if (self->connection.server_status & SERVER_STATUS_AUTOCOMMIT) {
905+
Py_RETURN_TRUE;
906+
}
907+
Py_RETURN_FALSE;
908+
}
895909

896910
static char _mysql_ConnectionObject_commit__doc__[] =
897911
"Commits the current transaction\n\
@@ -2317,6 +2331,12 @@ static PyMethodDef _mysql_ConnectionObject_methods[] = {
23172331
METH_VARARGS,
23182332
_mysql_ConnectionObject_autocommit__doc__
23192333
},
2334+
{
2335+
"get_autocommit",
2336+
(PyCFunction)_mysql_ConnectionObject_get_autocommit,
2337+
METH_NOARGS,
2338+
_mysql_ConnectionObject_get_autocommit__doc__
2339+
},
23202340
{
23212341
"commit",
23222342
(PyCFunction)_mysql_ConnectionObject_commit,

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.