mirror of
https://github.com/mariadb-corporation/mariadb-connector-python.git
synced 2025-08-02 13:56:54 +00:00
Fix for CONPY-229:
Pass NULL/None values to converter.
This commit is contained in:
@ -412,7 +412,7 @@ static PyObject *ma_convert_value(MrdbCursor *self,
|
|||||||
PyObject *func;
|
PyObject *func;
|
||||||
PyObject *new_value= NULL;
|
PyObject *new_value= NULL;
|
||||||
|
|
||||||
if (!self->connection->converter || value == Py_None)
|
if (!self->connection->converter)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if ((func= PyDict_GetItem(self->connection->converter, key)) &&
|
if ((func= PyDict_GetItem(self->connection->converter, key)) &&
|
||||||
@ -431,17 +431,14 @@ field_fetch_fromtext(MrdbCursor *self, char *data, unsigned int column)
|
|||||||
MYSQL_TIME tm;
|
MYSQL_TIME tm;
|
||||||
unsigned long *length;
|
unsigned long *length;
|
||||||
enum enum_extended_field_type ext_type= mariadb_extended_field_type(&self->fields[column]);
|
enum enum_extended_field_type ext_type= mariadb_extended_field_type(&self->fields[column]);
|
||||||
|
uint16_t type= self->fields[column].type;
|
||||||
|
|
||||||
if (!data)
|
if (!data)
|
||||||
{
|
type= MYSQL_TYPE_NULL;
|
||||||
Py_INCREF(Py_None);
|
|
||||||
self->values[column]= Py_None;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
length= mysql_fetch_lengths(self->result);
|
length= mysql_fetch_lengths(self->result);
|
||||||
|
|
||||||
switch (self->fields[column].type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case MYSQL_TYPE_NULL:
|
case MYSQL_TYPE_NULL:
|
||||||
Py_INCREF(Py_None);
|
Py_INCREF(Py_None);
|
||||||
|
@ -252,6 +252,9 @@ void MrdbConnection_process_status_info(void *data, enum enum_mariadb_status_inf
|
|||||||
if (!strncmp(key->str, "character_set_client", key->length) &&
|
if (!strncmp(key->str, "character_set_client", key->length) &&
|
||||||
strncmp(val->str, "utf8mb4", val->length))
|
strncmp(val->str, "utf8mb4", val->length))
|
||||||
{
|
{
|
||||||
|
/* mariadb_throw_exception (PyUnicode_FormatV)
|
||||||
|
doesn't support string with length,
|
||||||
|
so we need a temporary variable */
|
||||||
char charset[128];
|
char charset[128];
|
||||||
|
|
||||||
memcpy(charset, val->str, val->length);
|
memcpy(charset, val->str, val->length);
|
||||||
|
@ -20,9 +20,16 @@ def long_minus(s):
|
|||||||
return s - 1
|
return s - 1
|
||||||
|
|
||||||
|
|
||||||
|
def none_to_string(s):
|
||||||
|
if s is None:
|
||||||
|
return "None"
|
||||||
|
return s
|
||||||
|
|
||||||
|
|
||||||
conversions = {
|
conversions = {
|
||||||
**{FIELD_TYPE.TIME: timedelta_to_time},
|
**{FIELD_TYPE.TIME: timedelta_to_time},
|
||||||
**{FIELD_TYPE.LONG: long_minus},
|
**{FIELD_TYPE.LONG: long_minus},
|
||||||
|
**{FIELD_TYPE.NULL: none_to_string},
|
||||||
**{FIELD_TYPE.LONGLONG: long_minus},
|
**{FIELD_TYPE.LONGLONG: long_minus},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,6 +59,16 @@ class TestConversion(unittest.TestCase):
|
|||||||
self.assertEqual(row[0], a - 1)
|
self.assertEqual(row[0], a - 1)
|
||||||
del cursor
|
del cursor
|
||||||
|
|
||||||
|
def test_convert_none(self):
|
||||||
|
cursor = self.connection.cursor()
|
||||||
|
cursor.execute("SELECT NULL")
|
||||||
|
row = cursor.fetchone()
|
||||||
|
self.assertEqual(row[0], "None")
|
||||||
|
cursor.execute("SELECT ?", (None,))
|
||||||
|
row = cursor.fetchone()
|
||||||
|
self.assertEqual(row[0], "None")
|
||||||
|
del cursor
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Reference in New Issue
Block a user