Skip to content

Reimplement JSON support #310

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 4 additions & 15 deletions MySQLdb/_mysql.c
Original file line number Diff line number Diff line change
Expand Up @@ -1138,15 +1138,15 @@ _mysql_field_to_python(
v = PyUnicode_Decode(rowitem, length, encoding, NULL);
}
}
else if (converter == (PyObject*)&PyBytes_Type) {
else if (converter == (PyObject*)&PyBytes_Type || converter == Py_None) {
//fprintf(stderr, "decoding with bytes\n", encoding);
v = PyBytes_FromStringAndSize(rowitem, length);
}
else if (converter == (PyObject*)&PyInt_Type) {
//fprintf(stderr, "decoding with int\n", encoding);
v = PyInt_FromString(rowitem, NULL, 10);
}
else if (converter != Py_None) {
else {
//fprintf(stderr, "decoding with callback\n");
//PyObject_Print(converter, stderr, 0);
//fprintf(stderr, "\n");
Expand All @@ -1158,17 +1158,7 @@ _mysql_field_to_python(
#endif
rowitem,
(int)length);
} else {
//fprintf(stderr, "converter=None\n");
#ifdef IS_PY3K
if (!binary) {
v = PyUnicode_FromStringAndSize(rowitem, (int)length);
} else
#endif
v = PyBytes_FromStringAndSize(rowitem, (int)length);
}
if (!v)
return NULL;
} else {
Py_INCREF(Py_None);
v = Py_None;
Expand Down Expand Up @@ -1414,7 +1404,7 @@ _mysql_ConnectionObject_change_user(
{
char *user, *pwd=NULL, *db=NULL;
int r;
static char *kwlist[] = { "user", "passwd", "db", NULL } ;
static char *kwlist[] = { "user", "passwd", "db", NULL } ;

if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|ss:change_user",
kwlist, &user, &pwd, &db))
Expand All @@ -1424,8 +1414,7 @@ _mysql_ConnectionObject_change_user(
r = mysql_change_user(&(self->connection), user, pwd, db);
Py_END_ALLOW_THREADS
if (r) return _mysql_Exception(self);
Py_INCREF(Py_None);
return Py_None;
Py_RETURN_NONE;
}

static char _mysql_ConnectionObject_character_set_name__doc__[] =
Expand Down
2 changes: 1 addition & 1 deletion MySQLdb/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def unicode_literal(u, dummy=None):

if use_unicode:
for t in (FIELD_TYPE.STRING, FIELD_TYPE.VAR_STRING, FIELD_TYPE.VARCHAR, FIELD_TYPE.TINY_BLOB,
FIELD_TYPE.MEDIUM_BLOB, FIELD_TYPE.LONG_BLOB, FIELD_TYPE.BLOB):
FIELD_TYPE.MEDIUM_BLOB, FIELD_TYPE.LONG_BLOB, FIELD_TYPE.BLOB, FIELD_TYPE.JSON):
self.converter[t] = _bytes_or_str

self.encoders[unicode] = unicode_literal
Expand Down
1 change: 1 addition & 0 deletions MySQLdb/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,5 @@ def quote_tuple(t, d):
FIELD_TYPE.STRING: bytes,
FIELD_TYPE.VAR_STRING: bytes,
FIELD_TYPE.VARCHAR: bytes,
FIELD_TYPE.JSON: bytes,
}