diff options
author | INADA Naoki <songofacandy@gmail.com> | 2013-10-02 02:10:02 +0900 |
---|---|---|
committer | INADA Naoki <songofacandy@gmail.com> | 2013-10-02 02:10:02 +0900 |
commit | 3dbf035fa5866364a53e17b79172746fe7e9b11e (patch) | |
tree | d30b9429d3bec3afaf735621b8134dc4e8687c6e | |
parent | c8b2744ea2b1e4419b7e3d93928e92c95f366815 (diff) | |
download | mysqldb1-3dbf035fa5866364a53e17b79172746fe7e9b11e.tar.gz |
More precise get_autocommit based on server_status.
-rw-r--r-- | MySQLdb/connections.py | 15 | ||||
-rw-r--r-- | _mysql.c | 22 |
2 files changed, 23 insertions, 14 deletions
diff --git a/MySQLdb/connections.py b/MySQLdb/connections.py index 40a6150..0c529f7 100644 --- a/MySQLdb/connections.py +++ b/MySQLdb/connections.py @@ -240,21 +240,10 @@ class Connection(_mysql.connection): def autocommit(self, on): on = bool(on) - _mysql.connection.autocommit(self, on) + if self.get_autocommit() != on: + _mysql.connection.autocommit(self, 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): """ @@ -891,7 +891,21 @@ _mysql_ConnectionObject_autocommit( if (err) return _mysql_Exception(self); Py_INCREF(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__[] = "Commits the current transaction\n\ @@ -2318,6 +2332,12 @@ static PyMethodDef _mysql_ConnectionObject_methods[] = { _mysql_ConnectionObject_autocommit__doc__ }, { + "get_autocommit", + (PyCFunction)_mysql_ConnectionObject_get_autocommit, + METH_NOARGS, + _mysql_ConnectionObject_get_autocommit__doc__ + }, + { "commit", (PyCFunction)_mysql_ConnectionObject_commit, METH_VARARGS, |