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 7dd57dc

Browse filesBrowse files
committed
Merge https://github.com/farcepest/MySQLdb1 into merge-upstream
2 parents b739fb0 + 5ce7d5f commit 7dd57dc
Copy full SHA for 7dd57dc

File tree

Expand file treeCollapse file tree

10 files changed

+109
-26
lines changed
Filter options
Expand file treeCollapse file tree

10 files changed

+109
-26
lines changed

‎.gitignore

Copy file name to clipboardExpand all lines: .gitignore
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
*.zip
88
*.egg
99
*.egg-info/
10+
.tox/
1011
build/
1112
dist/

‎.travis.yml

Copy file name to clipboardExpand all lines: .travis.yml
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
language: python
22
python:
3-
- "2.5"
43
- "2.6"
54
- "2.7"
65
- "pypy"

‎MySQLdb/connections.py

Copy file name to clipboardExpand all lines: MySQLdb/connections.py
+17-2Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ class object, used to create cursors (keyword only)
139139
local_infile
140140
integer, non-zero enables LOAD LOCAL INFILE; zero disables
141141
142+
autocommit
143+
If False (default), autocommit is disabled.
144+
If True, autocommit is enabled.
145+
If None, autocommit isn't set and server default is used.
146+
142147
There are a number of undocumented, non-standard methods. See the
143148
documentation for the MySQL C API for some hints on what they do.
144149
@@ -182,6 +187,9 @@ class object, used to create cursors (keyword only)
182187

183188
kwargs2['client_flag'] = client_flag
184189

190+
# PEP-249 requires autocommit to be initially off
191+
autocommit = kwargs2.pop('autocommit', False)
192+
185193
super(Connection, self).__init__(*args, **kwargs2)
186194
self.cursorclass = cursorclass
187195
self.encoders = dict([ (k, v) for k, v in conv.items()
@@ -225,10 +233,15 @@ def string_decoder(s):
225233
self.encoders[types.UnicodeType] = unicode_literal
226234
self._transactional = self.server_capabilities & CLIENT.TRANSACTIONS
227235
if self._transactional:
228-
# PEP-249 requires autocommit to be initially off
229-
self.autocommit(False)
236+
if autocommit is not None:
237+
self.autocommit(autocommit)
230238
self.messages = []
231239

240+
def autocommit(self, on):
241+
on = bool(on)
242+
if self.get_autocommit() != on:
243+
_mysql.connection.autocommit(self, on)
244+
232245
def cursor(self, cursorclass=None):
233246
"""
234247
@@ -241,6 +254,8 @@ def cursor(self, cursorclass=None):
241254
return (cursorclass or self.cursorclass)(self)
242255

243256
def __enter__(self):
257+
if self.get_autocommit():
258+
self.query("BEGIN")
244259
return self.cursor()
245260

246261
def __exit__(self, exc, value, tb):

‎MySQLdb/converters.py

Copy file name to clipboardExpand all lines: MySQLdb/converters.py
+5-2Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,16 @@ def char_array(s):
129129
def array2Str(o, d):
130130
return Thing2Literal(o.tostring(), d)
131131

132+
def quote_tuple(t, d):
133+
return "(%s)" % (','.join(escape_sequence(t, d)))
134+
132135
conversions = {
133136
IntType: Thing2Str,
134137
LongType: Long2Int,
135138
FloatType: Float2Str,
136139
NoneType: None2NULL,
137-
TupleType: escape_sequence,
138-
ListType: escape_sequence,
140+
TupleType: quote_tuple,
141+
ListType: quote_tuple,
139142
DictType: escape_dict,
140143
InstanceType: Instance2Str,
141144
ArrayType: array2Str,

‎MySQLdb/cursors.py

Copy file name to clipboardExpand all lines: MySQLdb/cursors.py
+13-3Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
(?:
2727
(?:\(
2828
# ( - editor hightlighting helper
29-
[^)]*
29+
.*
3030
\))
3131
|
3232
'
@@ -180,7 +180,11 @@ def execute(self, query, args=None):
180180
if isinstance(query, unicode):
181181
query = query.encode(db.unicode_literal.charset)
182182
if args is not None:
183-
query = query % db.literal(args)
183+
if isinstance(args, dict):
184+
query = query % dict((key, db.literal(item))
185+
for key, item in args.iteritems())
186+
else:
187+
query = query % tuple([db.literal(item) for item in args])
184188
try:
185189
r = None
186190
r = self._query(query)
@@ -236,7 +240,13 @@ def executemany(self, query, args):
236240
e = m.end(1)
237241
qv = m.group(1)
238242
try:
239-
q = [ qv % db.literal(a) for a in args ]
243+
q = []
244+
for a in args:
245+
if isinstance(a, dict):
246+
q.append(qv % dict((key, db.literal(item))
247+
for key, item in a.iteritems()))
248+
else:
249+
q.append(qv % tuple([db.literal(item) for item in a]))
240250
except TypeError, msg:
241251
if msg.args[0] in ("not enough arguments for format string",
242252
"not all arguments converted"):

‎MySQLdb/times.py

Copy file name to clipboardExpand all lines: MySQLdb/times.py
+22-7Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,12 @@ def DateTime_or_None(s):
5151

5252
try:
5353
d, t = s.split(sep, 1)
54-
return datetime(*[ int(x) for x in d.split('-')+t.split(':') ])
54+
if '.' in t:
55+
t, ms = t.split('.',1)
56+
ms = ms.ljust(6, '0')
57+
else:
58+
ms = 0
59+
return datetime(*[ int(x) for x in d.split('-')+t.split(':')+[ms] ])
5560
except (SystemExit, KeyboardInterrupt):
5661
raise
5762
except:
@@ -60,9 +65,14 @@ def DateTime_or_None(s):
6065
def TimeDelta_or_None(s):
6166
try:
6267
h, m, s = s.split(':')
63-
h, m, s = int(h), int(m), float(s)
64-
td = timedelta(hours=abs(h), minutes=m, seconds=int(s),
65-
microseconds=int(math.modf(s)[0] * 1000000))
68+
if '.' in s:
69+
s, ms = s.split('.')
70+
ms = ms.ljust(6, '0')
71+
else:
72+
ms = 0
73+
h, m, s, ms = int(h), int(m), int(s), int(ms)
74+
td = timedelta(hours=abs(h), minutes=m, seconds=s,
75+
microseconds=ms)
6676
if h < 0:
6777
return -td
6878
else:
@@ -74,9 +84,14 @@ def TimeDelta_or_None(s):
7484
def Time_or_None(s):
7585
try:
7686
h, m, s = s.split(':')
77-
h, m, s = int(h), int(m), float(s)
78-
return time(hour=h, minute=m, second=int(s),
79-
microsecond=int(math.modf(s)[0] * 1000000))
87+
if '.' in s:
88+
s, ms = s.split('.')
89+
ms = ms.ljust(6, '0')
90+
else:
91+
ms = 0
92+
h, m, s, ms = int(h), int(m), int(s), int(ms)
93+
return time(hour=h, minute=m, second=s,
94+
microsecond=ms)
8095
except ValueError:
8196
return None
8297

‎_mysql.c

Copy file name to clipboardExpand all lines: _mysql.c
+36-8Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ static int _mysql_server_init_done = 0;
121121
/* According to https://dev.mysql.com/doc/refman/5.1/en/mysql-options.html
122122
The MYSQL_OPT_READ_TIMEOUT apear in the version 5.1.12 */
123123
#if MYSQL_VERSION_ID > 50112
124-
#define HAVE_MYSQL_OPT_READ_TIMEOUT 1
124+
#define HAVE_MYSQL_OPT_TIMEOUTS 1
125125
#endif
126126

127127
PyObject *
@@ -566,13 +566,15 @@ _mysql_ConnectionObject_Initialize(
566566
"read_default_file", "read_default_group",
567567
"client_flag", "ssl",
568568
"local_infile",
569-
#ifdef HAVE_MYSQL_OPT_READ_TIMEOUT
569+
#ifdef HAVE_MYSQL_OPT_TIMEOUTS
570570
"read_timeout",
571+
"write_timeout",
571572
#endif
572573
NULL } ;
573574
int connect_timeout = 0;
574-
#ifdef HAVE_MYSQL_OPT_READ_TIMEOUT
575+
#ifdef HAVE_MYSQL_OPT_TIMEOUTS
575576
int read_timeout = 0;
577+
int write_timeout = 0;
576578
#endif
577579
int compress = -1, named_pipe = -1, local_infile = -1;
578580
char *init_command=NULL,
@@ -584,8 +586,8 @@ _mysql_ConnectionObject_Initialize(
584586
check_server_init(-1);
585587

586588
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
587-
#ifdef HAVE_MYSQL_OPT_READ_TIMEOUT
588-
"|ssssisOiiisssiOii:connect",
589+
#ifdef HAVE_MYSQL_OPT_TIMEOUTS
590+
"|ssssisOiiisssiOiii:connect",
589591
#else
590592
"|ssssisOiiisssiOi:connect",
591593
#endif
@@ -598,8 +600,9 @@ _mysql_ConnectionObject_Initialize(
598600
&read_default_group,
599601
&client_flag, &ssl,
600602
&local_infile
601-
#ifdef HAVE_MYSQL_OPT_READ_TIMEOUT
603+
#ifdef HAVE_MYSQL_OPT_TIMEOUTS
602604
, &read_timeout
605+
, &write_timeout
603606
#endif
604607
))
605608
return -1;
@@ -636,12 +639,17 @@ _mysql_ConnectionObject_Initialize(
636639
mysql_options(&(self->connection), MYSQL_OPT_CONNECT_TIMEOUT,
637640
(char *)&timeout);
638641
}
639-
#ifdef HAVE_MYSQL_OPT_READ_TIMEOUT
642+
#ifdef HAVE_MYSQL_OPT_TIMEOUTS
640643
if (read_timeout) {
641644
unsigned int timeout = read_timeout;
642645
mysql_options(&(self->connection), MYSQL_OPT_READ_TIMEOUT,
643646
(char *)&timeout);
644647
}
648+
if (write_timeout) {
649+
unsigned int timeout = write_timeout;
650+
mysql_options(&(self->connection), MYSQL_OPT_WRITE_TIMEOUT,
651+
(char *)&timeout);
652+
}
645653
#endif
646654
if (compress != -1) {
647655
mysql_options(&(self->connection), MYSQL_OPT_COMPRESS, 0);
@@ -891,7 +899,21 @@ _mysql_ConnectionObject_autocommit(
891899
if (err) return _mysql_Exception(self);
892900
Py_INCREF(Py_None);
893901
return Py_None;
894-
}
902+
}
903+
904+
static char _mysql_ConnectionObject_get_autocommit__doc__[] =
905+
"Get the autocommit mode. True when enable; False when disable.\n";
906+
907+
static PyObject *
908+
_mysql_ConnectionObject_get_autocommit(
909+
_mysql_ConnectionObject *self,
910+
PyObject *args)
911+
{
912+
if (self->connection.server_status & SERVER_STATUS_AUTOCOMMIT) {
913+
Py_RETURN_TRUE;
914+
}
915+
Py_RETURN_FALSE;
916+
}
895917

896918
static char _mysql_ConnectionObject_commit__doc__[] =
897919
"Commits the current transaction\n\
@@ -2317,6 +2339,12 @@ static PyMethodDef _mysql_ConnectionObject_methods[] = {
23172339
METH_VARARGS,
23182340
_mysql_ConnectionObject_autocommit__doc__
23192341
},
2342+
{
2343+
"get_autocommit",
2344+
(PyCFunction)_mysql_ConnectionObject_get_autocommit,
2345+
METH_NOARGS,
2346+
_mysql_ConnectionObject_get_autocommit__doc__
2347+
},
23202348
{
23212349
"commit",
23222350
(PyCFunction)_mysql_ConnectionObject_commit,

‎setup_posix.py

Copy file name to clipboardExpand all lines: setup_posix.py
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,9 @@ def get_config():
7171
if i.startswith(compiler_flag('I')) ]
7272

7373
if static:
74-
extra_objects.append(os.path.join(
75-
library_dirs[0],'lib%s.a' % client))
74+
extra_objects.append(os.path.join(library_dirs[0],'lib%s.a' % client))
75+
if client in libraries:
76+
libraries.remove(client)
7677

7778
name = "MySQL-python"
7879
if enabled(options, 'embedded'):

‎tests/test_MySQLdb_capabilities.py

Copy file name to clipboardExpand all lines: tests/test_MySQLdb_capabilities.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def test_bug_2671682(self):
7777
try:
7878
self.cursor.execute("describe some_non_existent_table");
7979
except self.connection.ProgrammingError, msg:
80-
self.assertTrue(msg[0] == ER.NO_SUCH_TABLE)
80+
self.assertEquals(msg[0], ER.NO_SUCH_TABLE)
8181

8282
def test_bug_3514287(self):
8383
c = self.cursor

‎tox.ini

Copy file name to clipboard
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[tox]
2+
envlist = py25, py26, py27, py33
3+
4+
[testenv]
5+
setenv =
6+
TESTDB=travis.cnf
7+
commands =
8+
nosetests {posargs:-w tests -v}
9+
deps =
10+
ipdb
11+
nose

0 commit comments

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