diff options
author | Andy Dustman <farcepest@gmail.com> | 2013-11-21 11:57:32 -0800 |
---|---|---|
committer | Andy Dustman <farcepest@gmail.com> | 2013-11-21 11:57:32 -0800 |
commit | 95ae115c7d6b49dadec06af943ab03bef04f52fa (patch) | |
tree | 4db1628ba792ae82b41f2c6cd25f618c2161be6d | |
parent | 9b0b59f1bbe0029757b9b15d1c71586eaca1109c (diff) | |
parent | 2204283605e8c450223965eda8d8f357d5fe4c90 (diff) | |
download | mysqldb1-95ae115c7d6b49dadec06af943ab03bef04f52fa.tar.gz |
Merge pull request #32 from methane/autocommit
More precise get_autocommit based on server_status.
-rw-r--r-- | MySQLdb/connections.py | 17 | ||||
-rw-r--r-- | _mysql.c | 22 |
2 files changed, 23 insertions, 16 deletions
diff --git a/MySQLdb/connections.py b/MySQLdb/connections.py index 40a6150..908706a 100644 --- a/MySQLdb/connections.py +++ b/MySQLdb/connections.py @@ -232,7 +232,6 @@ class Connection(_mysql.connection): self.encoders[types.StringType] = string_literal self.encoders[types.UnicodeType] = unicode_literal self._transactional = self.server_capabilities & CLIENT.TRANSACTIONS - self._autocommit = None if self._transactional: if autocommit is not None: self.autocommit(autocommit) @@ -240,20 +239,8 @@ class Connection(_mysql.connection): def autocommit(self, on): on = bool(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() + if self.get_autocommit() != on: + _mysql.connection.autocommit(self, on) 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, |