Skip to content

Commit 9aedf1c

Browse files
committed
Handle dicts in check_text_params
1 parent b0366fa commit 9aedf1c

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

mariadb/cursors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ def execute(self, statement: str, data: Sequence = (), buffered=None):
296296

297297
# if one of the provided parameters has byte or datetime value,
298298
# we don't use text protocol
299-
if self._check_text_types() == True:
299+
if data and self._check_text_types() == True:
300300
self._text = False
301301

302302
if self._text:

mariadb/mariadb_cursor.c

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -653,18 +653,20 @@ PyObject *MrdbCursor_InitResultSet(MrdbCursor *self)
653653
self->result= NULL;
654654
}
655655

656-
if (Mrdb_GetFieldInfo(self))
657-
return NULL;
658-
659-
if (!(self->values= (PyObject**)PyMem_RawCalloc(self->field_count, sizeof(PyObject *))))
660-
return NULL;
661-
if (!self->parseinfo.is_text)
662-
mysql_stmt_attr_set(self->stmt, STMT_ATTR_CB_RESULT, field_fetch_callback);
663-
664656
if (self->field_count)
665657
{
666-
self->row_count= CURSOR_NUM_ROWS(self);
667-
self->affected_rows= 0;
658+
if (Mrdb_GetFieldInfo(self))
659+
{
660+
return NULL;
661+
}
662+
663+
if (!(self->values= (PyObject**)PyMem_RawCalloc(self->field_count, sizeof(PyObject *))))
664+
return NULL;
665+
if (!self->parseinfo.is_text)
666+
mysql_stmt_attr_set(self->stmt, STMT_ATTR_CB_RESULT, field_fetch_callback);
667+
668+
self->row_count= CURSOR_NUM_ROWS(self);
669+
self->affected_rows= 0;
668670
} else {
669671
self->row_count= self->affected_rows= CURSOR_AFFECTED_ROWS(self);
670672
}
@@ -1284,6 +1286,7 @@ static PyObject *
12841286
MrdbCursor_check_text_types(MrdbCursor *self)
12851287
{
12861288
PyDateTime_IMPORT;
1289+
Py_ssize_t ofs= 0;
12871290

12881291
if (!self || !self->data || !self->parseinfo.paramcount)
12891292
{
@@ -1292,7 +1295,14 @@ MrdbCursor_check_text_types(MrdbCursor *self)
12921295

12931296
for (uint32_t i= 0; i < self->parseinfo.paramcount; i++)
12941297
{
1295-
PyObject *obj= ListOrTuple_GetItem(self->data, i);
1298+
PyObject *obj;
1299+
1300+
if (PyDict_Check(self->data))
1301+
{
1302+
PyDict_Next(self->data, &ofs, NULL, &obj);
1303+
}
1304+
else
1305+
obj= ListOrTuple_GetItem(self->data, i);
12961306
if (PyBytes_Check(obj) ||
12971307
PyByteArray_Check(obj) ||
12981308
PyDate_Check(obj))

0 commit comments

Comments
 (0)