Skip to content

Commit fe80324

Browse files
authored
Reimplement JSON support (PyMySQL#310)
1 parent bf77dd0 commit fe80324

File tree

3 files changed

+6
-16
lines changed

3 files changed

+6
-16
lines changed

MySQLdb/_mysql.c

+4-15
Original file line numberDiff line numberDiff line change
@@ -1138,15 +1138,15 @@ _mysql_field_to_python(
11381138
v = PyUnicode_Decode(rowitem, length, encoding, NULL);
11391139
}
11401140
}
1141-
else if (converter == (PyObject*)&PyBytes_Type) {
1141+
else if (converter == (PyObject*)&PyBytes_Type || converter == Py_None) {
11421142
//fprintf(stderr, "decoding with bytes\n", encoding);
11431143
v = PyBytes_FromStringAndSize(rowitem, length);
11441144
}
11451145
else if (converter == (PyObject*)&PyInt_Type) {
11461146
//fprintf(stderr, "decoding with int\n", encoding);
11471147
v = PyInt_FromString(rowitem, NULL, 10);
11481148
}
1149-
else if (converter != Py_None) {
1149+
else {
11501150
//fprintf(stderr, "decoding with callback\n");
11511151
//PyObject_Print(converter, stderr, 0);
11521152
//fprintf(stderr, "\n");
@@ -1158,17 +1158,7 @@ _mysql_field_to_python(
11581158
#endif
11591159
rowitem,
11601160
(int)length);
1161-
} else {
1162-
//fprintf(stderr, "converter=None\n");
1163-
#ifdef IS_PY3K
1164-
if (!binary) {
1165-
v = PyUnicode_FromStringAndSize(rowitem, (int)length);
1166-
} else
1167-
#endif
1168-
v = PyBytes_FromStringAndSize(rowitem, (int)length);
11691161
}
1170-
if (!v)
1171-
return NULL;
11721162
} else {
11731163
Py_INCREF(Py_None);
11741164
v = Py_None;
@@ -1414,7 +1404,7 @@ _mysql_ConnectionObject_change_user(
14141404
{
14151405
char *user, *pwd=NULL, *db=NULL;
14161406
int r;
1417-
static char *kwlist[] = { "user", "passwd", "db", NULL } ;
1407+
static char *kwlist[] = { "user", "passwd", "db", NULL } ;
14181408

14191409
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|ss:change_user",
14201410
kwlist, &user, &pwd, &db))
@@ -1424,8 +1414,7 @@ _mysql_ConnectionObject_change_user(
14241414
r = mysql_change_user(&(self->connection), user, pwd, db);
14251415
Py_END_ALLOW_THREADS
14261416
if (r) return _mysql_Exception(self);
1427-
Py_INCREF(Py_None);
1428-
return Py_None;
1417+
Py_RETURN_NONE;
14291418
}
14301419

14311420
static char _mysql_ConnectionObject_character_set_name__doc__[] =

MySQLdb/connections.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def unicode_literal(u, dummy=None):
183183

184184
if use_unicode:
185185
for t in (FIELD_TYPE.STRING, FIELD_TYPE.VAR_STRING, FIELD_TYPE.VARCHAR, FIELD_TYPE.TINY_BLOB,
186-
FIELD_TYPE.MEDIUM_BLOB, FIELD_TYPE.LONG_BLOB, FIELD_TYPE.BLOB):
186+
FIELD_TYPE.MEDIUM_BLOB, FIELD_TYPE.LONG_BLOB, FIELD_TYPE.BLOB, FIELD_TYPE.JSON):
187187
self.converter[t] = _bytes_or_str
188188

189189
self.encoders[unicode] = unicode_literal

MySQLdb/converters.py

+1
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,5 @@ def quote_tuple(t, d):
129129
FIELD_TYPE.STRING: bytes,
130130
FIELD_TYPE.VAR_STRING: bytes,
131131
FIELD_TYPE.VARCHAR: bytes,
132+
FIELD_TYPE.JSON: bytes,
132133
}

0 commit comments

Comments
 (0)