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 fe80324

Browse filesBrowse files
authored
Reimplement JSON support (PyMySQL#310)
1 parent bf77dd0 commit fe80324
Copy full SHA for fe80324

File tree

Expand file treeCollapse file tree

3 files changed

+6
-16
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+6
-16
lines changed

‎MySQLdb/_mysql.c

Copy file name to clipboardExpand all lines: MySQLdb/_mysql.c
+4-15Lines changed: 4 additions & 15 deletions
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

Copy file name to clipboardExpand all lines: MySQLdb/connections.py
+1-1Lines changed: 1 addition & 1 deletion
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

Copy file name to clipboardExpand all lines: MySQLdb/converters.py
+1Lines changed: 1 addition & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.