Skip to content

Commit

Permalink
Add description attribute to ctds.Row
Browse files Browse the repository at this point in the history
  • Loading branch information
John-Anthony Owens committed Nov 10, 2020
1 parent 3eb8554 commit c22b562
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/ctds/cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -2846,6 +2846,20 @@ static PyObject* Row_getattro(PyObject* self, PyObject* attr)
return value;
}

static PyObject* Row_description_get(PyObject* self, void* closure)
{
struct Row* row = (struct Row*)self;
return ResultSetDescription_get_object(row->description);

UNUSED(closure);
}

static PyGetSetDef Row_getset[] = {
/* name, get, set, doc, closure */
{ (char*)"description", Row_description_get, NULL, (char*)s_Cursor_description_doc, NULL },
{ NULL, NULL, NULL, NULL, NULL }
};

static const char s_Row_dict_doc[] =
"dict()\n"
"\n"
Expand Down Expand Up @@ -2948,7 +2962,7 @@ PyTypeObject RowType = {
NULL, /* tp_iternext */
Row_methods, /* tp_methods */
NULL, /* tp_members */
NULL, /* tp_getset */
Row_getset, /* tp_getset */
NULL, /* tp_base */
NULL, /* tp_dict */
NULL, /* tp_descr_get */
Expand Down
19 changes: 19 additions & 0 deletions tests/test_cursor_row.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,25 @@ def test_attr(self):
else:
self.fail('row.attr lookup did not fail as expected') # pragma: nocover

def test_description(self):
with self.connect() as connection:
with connection.cursor() as cursor:
args = (1, 'two', 'three', 4)
cursor.execute(
'''
SELECT
:0 AS Col1,
:1 AS Col2,
:2 AS Col3,
:3 AS Col4
''',
args
)
description = cursor.description
row = cursor.fetchone()

self.assertTrue(row.description is description)

def test_dict(self):
with self.connect() as connection:
with connection.cursor() as cursor:
Expand Down

0 comments on commit c22b562

Please sign in to comment.