Skip to content

Commit

Permalink
CONPY-88
Browse files Browse the repository at this point in the history
Extended cursor->description:

The descriptor now contains 11 elements:
descriptor[8]: table name
descriptor[9]: original column name
descriptor[10]: original table name
  • Loading branch information
9EOR9 committed Jan 25, 2022
1 parent 63c8201 commit 4bcfd6a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
7 changes: 5 additions & 2 deletions mariadb/mariadb_cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -742,15 +742,18 @@ PyObject *MrdbCursor_description(MrdbCursor *self)
if (ext_type == EXT_TYPE_JSON)
self->fields[i].type= MYSQL_TYPE_JSON;

if (!(desc= Py_BuildValue("(sIIiIIOI)",
if (!(desc= Py_BuildValue("(sIIiIIOIsss)",
self->fields[i].name,
self->fields[i].type,
display_length,
packed_len >= 0 ? packed_len : -1,
precision,
decimals,
PyBool_FromLong(!IS_NOT_NULL(self->fields[i].flags)),
self->fields[i].flags)))
self->fields[i].flags,
self->fields[i].table,
self->fields[i].org_name,
self->fields[i].org_table)))
{
Py_XDECREF(obj);
mariadb_throw_exception(NULL, Mariadb_OperationalError, 0,
Expand Down
17 changes: 15 additions & 2 deletions testing/test/integration/test_dbapi20.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,12 +284,25 @@ def test_description(self):
self.assertEqual(len(cur.description), 1,
'cursor.description describes too many columns'
)
self.assertEqual(len(cur.description[0]), 8,
'cursor.description[x] tuples must have 8 elements'
self.assertEqual(len(cur.description[0]), 11,
'cursor.description[x] tuples must have 11 elements'
)
self.assertEqual(cur.description[0][0].lower(), 'name',
'cursor.description[x][0] must return column name'
)

# table name
self.assertEqual(cur.description[0][8].lower(), 'dbapi20test_booze',
'cursor.description[x][0] must return column name'
)
# original column name
self.assertEqual(cur.description[0][9].lower(), 'name',
'cursor.description[x][0] must return column name'
)
# original table name
self.assertEqual(cur.description[0][10].lower(), 'dbapi20test_booze',
'cursor.description[x][0] must return column name'
)
self.assertEqual(cur.description[0][1], self.driver.STRING,
'cursor.description[x][1] must return column type. Got %r'
% cur.description[0][1]
Expand Down

0 comments on commit 4bcfd6a

Please sign in to comment.