From fb883e2a7411e75974b31cea18f6a61dd5644313 Mon Sep 17 00:00:00 2001 From: reinvantveer Date: Thu, 26 May 2022 19:50:50 +0200 Subject: [PATCH] return field label instead of name, which contains any alias instead of the source. Fixes https://github.com/baztian/jaydebeapi/issues/81 Fixes https://github.com/baztian/jaydebeapi/issues/169 Signed-off-by: reinvantveer --- jaydebeapi/__init__.py | 2 +- test/test_integration.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/jaydebeapi/__init__.py b/jaydebeapi/__init__.py index a890c3d..54693ed 100644 --- a/jaydebeapi/__init__.py +++ b/jaydebeapi/__init__.py @@ -488,7 +488,7 @@ def description(self): dbapi_type = None else: dbapi_type = DBAPITypeObject._map_jdbc_type_to_dbapi(jdbc_type) - col_desc = ( m.getColumnName(col), + col_desc = ( m.getColumnLabel(col), dbapi_type, size, size, diff --git a/test/test_integration.py b/test/test_integration.py index e795339..78c8d69 100644 --- a/test/test_integration.py +++ b/test/test_integration.py @@ -79,6 +79,13 @@ def test_execute_and_fetch_no_data(self): result = cursor.fetchall() self.assertEqual(result, []) + def test_execute_and_fetch_alias(self): + with self.conn.cursor() as cursor: + stmt = "select ACCOUNT_ID as `a_id` from ACCOUNT" + cursor.execute(stmt) + field_names = cursor.description + self.assertEqual(field_names[0], 'a_id') + def test_execute_and_fetch(self): with self.conn.cursor() as cursor: cursor.execute("select ACCOUNT_ID, ACCOUNT_NO, BALANCE, BLOCKING " \