diff --git a/MySQLdb/_mysql.c b/MySQLdb/_mysql.c index 53e57f85..84714170 100644 --- a/MySQLdb/_mysql.c +++ b/MySQLdb/_mysql.c @@ -1138,7 +1138,7 @@ _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); } @@ -1146,7 +1146,7 @@ _mysql_field_to_python( //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"); @@ -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; @@ -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)) @@ -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__[] = diff --git a/MySQLdb/connections.py b/MySQLdb/connections.py index e902912f..29cc4f32 100644 --- a/MySQLdb/connections.py +++ b/MySQLdb/connections.py @@ -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 diff --git a/MySQLdb/converters.py b/MySQLdb/converters.py index f0d01786..9b9cb8be 100644 --- a/MySQLdb/converters.py +++ b/MySQLdb/converters.py @@ -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, }