summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--MySQLdb/connections.py17
-rw-r--r--MySQLdb/converters.py7
-rw-r--r--MySQLdb/cursors.py16
-rw-r--r--MySQLdb/times.py9
-rw-r--r--_mysql.c22
-rw-r--r--setup_posix.py5
-rw-r--r--tests/test_MySQLdb_capabilities.py2
7 files changed, 53 insertions, 25 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):
"""
diff --git a/MySQLdb/converters.py b/MySQLdb/converters.py
index 491d49b..26c1f90 100644
--- a/MySQLdb/converters.py
+++ b/MySQLdb/converters.py
@@ -129,13 +129,16 @@ def char_array(s):
def array2Str(o, d):
return Thing2Literal(o.tostring(), d)
+def quote_tuple(t, d):
+ return "(%s)" % (','.join(escape_sequence(t, d)))
+
conversions = {
IntType: Thing2Str,
LongType: Long2Int,
FloatType: Float2Str,
NoneType: None2NULL,
- TupleType: escape_sequence,
- ListType: escape_sequence,
+ TupleType: quote_tuple,
+ ListType: quote_tuple,
DictType: escape_dict,
InstanceType: Instance2Str,
ArrayType: array2Str,
diff --git a/MySQLdb/cursors.py b/MySQLdb/cursors.py
index 7e5a887..348a586 100644
--- a/MySQLdb/cursors.py
+++ b/MySQLdb/cursors.py
@@ -26,7 +26,7 @@ restr = r"""
(?:
(?:\(
# ( - editor hightlighting helper
- [^)]*
+ .*
\))
|
'
@@ -180,7 +180,11 @@ class BaseCursor(object):
if isinstance(query, unicode):
query = query.encode(db.unicode_literal.charset)
if args is not None:
- query = query % db.literal(args)
+ if isinstance(args, dict):
+ query = query % dict((key, db.literal(item))
+ for key, item in args.iteritems())
+ else:
+ query = query % tuple([db.literal(item) for item in args])
try:
r = None
r = self._query(query)
@@ -236,7 +240,13 @@ class BaseCursor(object):
e = m.end(1)
qv = m.group(1)
try:
- q = [ qv % db.literal(a) for a in args ]
+ q = []
+ for a in args:
+ if isinstance(a, dict):
+ q.append(qv % dict((key, db.literal(item))
+ for key, item in a.iteritems()))
+ else:
+ q.append(qv % tuple([db.literal(item) for item in a]))
except TypeError, msg:
if msg.args[0] in ("not enough arguments for format string",
"not all arguments converted"):
diff --git a/MySQLdb/times.py b/MySQLdb/times.py
index f3a92d7..0ff7476 100644
--- a/MySQLdb/times.py
+++ b/MySQLdb/times.py
@@ -51,7 +51,12 @@ def DateTime_or_None(s):
try:
d, t = s.split(sep, 1)
- return datetime(*[ int(x) for x in d.split('-')+t.split(':') ])
+ if '.' in t:
+ t, ms = t.split('.',1)
+ ms = ms.ljust(6, '0')
+ else:
+ ms = 0
+ return datetime(*[ int(x) for x in d.split('-')+t.split(':')+[ms] ])
except (SystemExit, KeyboardInterrupt):
raise
except:
@@ -62,6 +67,7 @@ def TimeDelta_or_None(s):
h, m, s = s.split(':')
if '.' in s:
s, ms = s.split('.')
+ ms = ms.ljust(6, '0')
else:
ms = 0
h, m, s, ms = int(h), int(m), int(s), int(ms)
@@ -80,6 +86,7 @@ def Time_or_None(s):
h, m, s = s.split(':')
if '.' in s:
s, ms = s.split('.')
+ ms = ms.ljust(6, '0')
else:
ms = 0
h, m, s, ms = int(h), int(m), int(s), int(ms)
diff --git a/_mysql.c b/_mysql.c
index 6ebbb4e..5b81c79 100644
--- a/_mysql.c
+++ b/_mysql.c
@@ -899,7 +899,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\
@@ -2326,6 +2340,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,
diff --git a/setup_posix.py b/setup_posix.py
index f7cb588..cfcf33c 100644
--- a/setup_posix.py
+++ b/setup_posix.py
@@ -71,8 +71,9 @@ def get_config():
if i.startswith(compiler_flag('I')) ]
if static:
- extra_objects.append(os.path.join(
- library_dirs[0],'lib%s.a' % client))
+ extra_objects.append(os.path.join(library_dirs[0],'lib%s.a' % client))
+ if client in libraries:
+ libraries.remove(client)
name = "MySQL-python"
if enabled(options, 'embedded'):
diff --git a/tests/test_MySQLdb_capabilities.py b/tests/test_MySQLdb_capabilities.py
index ebec1e6..ead6982 100644
--- a/tests/test_MySQLdb_capabilities.py
+++ b/tests/test_MySQLdb_capabilities.py
@@ -77,7 +77,7 @@ class test_MySQLdb(capabilities.DatabaseTest):
try:
self.cursor.execute("describe some_non_existent_table");
except self.connection.ProgrammingError, msg:
- self.assertTrue(msg[0] == ER.NO_SUCH_TABLE)
+ self.assertEquals(msg[0], ER.NO_SUCH_TABLE)
def test_bug_3514287(self):
c = self.cursor