mirror of
https://github.com/PyMySQL/mysqlclient.git
synced 2025-08-15 02:54:29 +08:00
More precise get_autocommit based on server_status.
This commit is contained in:
@ -240,21 +240,10 @@ class Connection(_mysql.connection):
|
|||||||
|
|
||||||
def autocommit(self, on):
|
def autocommit(self, on):
|
||||||
on = bool(on)
|
on = bool(on)
|
||||||
|
if self.get_autocommit() != on:
|
||||||
_mysql.connection.autocommit(self, on)
|
_mysql.connection.autocommit(self, on)
|
||||||
self._autocommit = on
|
self._autocommit = on
|
||||||
|
|
||||||
def get_autocommit(self):
|
|
||||||
if self._autocommit is None:
|
|
||||||
self._update_autocommit()
|
|
||||||
return self._autocommit
|
|
||||||
|
|
||||||
def _update_autocommit(self):
|
|
||||||
cursor = cursors.Cursor(self)
|
|
||||||
cursor.execute("SELECT @@AUTOCOMMIT")
|
|
||||||
row = cursor.fetchone()
|
|
||||||
self._autocommit = bool(row[0])
|
|
||||||
cursor.close()
|
|
||||||
|
|
||||||
def cursor(self, cursorclass=None):
|
def cursor(self, cursorclass=None):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
20
_mysql.c
20
_mysql.c
@ -893,6 +893,20 @@ _mysql_ConnectionObject_autocommit(
|
|||||||
return Py_None;
|
return Py_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char _mysql_ConnectionObject_get_autocommit__doc__[] =
|
||||||
|
"Get the autocommit mode. True when enable; False when disable.\n";
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_mysql_ConnectionObject_get_autocommit(
|
||||||
|
_mysql_ConnectionObject *self,
|
||||||
|
PyObject *args)
|
||||||
|
{
|
||||||
|
if (self->connection.server_status & SERVER_STATUS_AUTOCOMMIT) {
|
||||||
|
Py_RETURN_TRUE;
|
||||||
|
}
|
||||||
|
Py_RETURN_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
static char _mysql_ConnectionObject_commit__doc__[] =
|
static char _mysql_ConnectionObject_commit__doc__[] =
|
||||||
"Commits the current transaction\n\
|
"Commits the current transaction\n\
|
||||||
";
|
";
|
||||||
@ -2317,6 +2331,12 @@ static PyMethodDef _mysql_ConnectionObject_methods[] = {
|
|||||||
METH_VARARGS,
|
METH_VARARGS,
|
||||||
_mysql_ConnectionObject_autocommit__doc__
|
_mysql_ConnectionObject_autocommit__doc__
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"get_autocommit",
|
||||||
|
(PyCFunction)_mysql_ConnectionObject_get_autocommit,
|
||||||
|
METH_NOARGS,
|
||||||
|
_mysql_ConnectionObject_get_autocommit__doc__
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"commit",
|
"commit",
|
||||||
(PyCFunction)_mysql_ConnectionObject_commit,
|
(PyCFunction)_mysql_ConnectionObject_commit,
|
||||||
|
Reference in New Issue
Block a user