mirror of
https://github.com/PyMySQL/mysqlclient.git
synced 2025-08-15 11:10:58 +08:00
Reimplement JSON support (#310)
This commit is contained in:
@ -1138,7 +1138,7 @@ _mysql_field_to_python(
|
|||||||
v = PyUnicode_Decode(rowitem, length, encoding, NULL);
|
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);
|
//fprintf(stderr, "decoding with bytes\n", encoding);
|
||||||
v = PyBytes_FromStringAndSize(rowitem, length);
|
v = PyBytes_FromStringAndSize(rowitem, length);
|
||||||
}
|
}
|
||||||
@ -1146,7 +1146,7 @@ _mysql_field_to_python(
|
|||||||
//fprintf(stderr, "decoding with int\n", encoding);
|
//fprintf(stderr, "decoding with int\n", encoding);
|
||||||
v = PyInt_FromString(rowitem, NULL, 10);
|
v = PyInt_FromString(rowitem, NULL, 10);
|
||||||
}
|
}
|
||||||
else if (converter != Py_None) {
|
else {
|
||||||
//fprintf(stderr, "decoding with callback\n");
|
//fprintf(stderr, "decoding with callback\n");
|
||||||
//PyObject_Print(converter, stderr, 0);
|
//PyObject_Print(converter, stderr, 0);
|
||||||
//fprintf(stderr, "\n");
|
//fprintf(stderr, "\n");
|
||||||
@ -1158,17 +1158,7 @@ _mysql_field_to_python(
|
|||||||
#endif
|
#endif
|
||||||
rowitem,
|
rowitem,
|
||||||
(int)length);
|
(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 {
|
} else {
|
||||||
Py_INCREF(Py_None);
|
Py_INCREF(Py_None);
|
||||||
v = Py_None;
|
v = Py_None;
|
||||||
@ -1414,7 +1404,7 @@ _mysql_ConnectionObject_change_user(
|
|||||||
{
|
{
|
||||||
char *user, *pwd=NULL, *db=NULL;
|
char *user, *pwd=NULL, *db=NULL;
|
||||||
int r;
|
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",
|
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|ss:change_user",
|
||||||
kwlist, &user, &pwd, &db))
|
kwlist, &user, &pwd, &db))
|
||||||
@ -1424,8 +1414,7 @@ _mysql_ConnectionObject_change_user(
|
|||||||
r = mysql_change_user(&(self->connection), user, pwd, db);
|
r = mysql_change_user(&(self->connection), user, pwd, db);
|
||||||
Py_END_ALLOW_THREADS
|
Py_END_ALLOW_THREADS
|
||||||
if (r) return _mysql_Exception(self);
|
if (r) return _mysql_Exception(self);
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static char _mysql_ConnectionObject_character_set_name__doc__[] =
|
static char _mysql_ConnectionObject_character_set_name__doc__[] =
|
||||||
|
@ -183,7 +183,7 @@ class Connection(_mysql.connection):
|
|||||||
|
|
||||||
if use_unicode:
|
if use_unicode:
|
||||||
for t in (FIELD_TYPE.STRING, FIELD_TYPE.VAR_STRING, FIELD_TYPE.VARCHAR, FIELD_TYPE.TINY_BLOB,
|
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.converter[t] = _bytes_or_str
|
||||||
|
|
||||||
self.encoders[unicode] = unicode_literal
|
self.encoders[unicode] = unicode_literal
|
||||||
|
@ -129,4 +129,5 @@ conversions = {
|
|||||||
FIELD_TYPE.STRING: bytes,
|
FIELD_TYPE.STRING: bytes,
|
||||||
FIELD_TYPE.VAR_STRING: bytes,
|
FIELD_TYPE.VAR_STRING: bytes,
|
||||||
FIELD_TYPE.VARCHAR: bytes,
|
FIELD_TYPE.VARCHAR: bytes,
|
||||||
|
FIELD_TYPE.JSON: bytes,
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user