Skip to content

Commit fd21d47

Browse files
committed
BUG#28641350: mysqlx.result.Row objects cannot be printed directly
Printing a mysqlx.result.Row object shows the generic representation of a class in Python. This patch implements the __repr__ method in mysqlx.result.Row class so the row values are shown.
1 parent 64a5e8c commit fd21d47

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ v8.0.27
1313

1414
- WL#14689: Fallback conversion to str for types incompatible with MySQL
1515
- WL#14664: Allow SSPI Kerberos library usage with c-ext
16+
- BUG#28641350: mysqlx.result.Row objects cannot be printed directly
1617

1718
v8.0.26
1819
=======

lib/mysqlx/result.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,9 @@ def __init__(self, rs, fields):
766766
self._fields = fields
767767
self._resultset = rs
768768

769+
def __repr__(self):
770+
return repr(self._fields)
771+
769772
def __getitem__(self, index):
770773
"""Returns the value of a column by name or index.
771774

tests/test_mysqlx_crud.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2564,10 +2564,20 @@ def test_select(self):
25642564
"".format(table_name)).execute()
25652565

25662566
table = self.schema.get_table("test")
2567+
2568+
# test fetch_one()
2569+
result = table.select("age", "name").where("age = 21").execute()
2570+
row = result.fetch_one()
2571+
self.assertEqual(repr(row), repr([21, "Fred"]))
2572+
25672573
result = table.select().order_by("age DESC").execute()
25682574
rows = result.fetch_all()
25692575
self.assertEqual(4, len(rows))
25702576
self.assertEqual(67, rows[0]["age"])
2577+
self.assertEqual(
2578+
repr(rows),
2579+
repr([[67, "Betty"], [42, "Wilma"], [28, "Barney"], [21, "Fred"]])
2580+
)
25712581

25722582
result = table.select("age").where("age = 42").execute()
25732583
self.assertEqual(1, len(result.columns))

0 commit comments

Comments
 (0)