Skip to content

Support RF dotted dictionary access syntax #239

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/DatabaseLibrary/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from typing import List, Optional, Tuple

from robot.api import logger
from robot.utils.dotdict import DotDict

from .connection_manager import Connection
from .params_decorator import renamed_args
Expand Down Expand Up @@ -91,7 +92,7 @@ def query(
col_names = [c[0] for c in cur.description]
self._log_query_results(col_names, all_rows)
if return_dict:
return [dict(zip(col_names, row)) for row in all_rows]
return [DotDict(zip(col_names, row)) for row in all_rows]
return all_rows
except Exception as e:
self._rollback_and_raise(db_connection, no_transaction, e)
Expand Down
13 changes: 13 additions & 0 deletions test/tests/common_tests/basic_tests.robot
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,19 @@ Verify Query - Get results as a list of dictionaries
Should Be Equal As Strings ${value 1} Franz Allan
Should Be Equal As Strings ${value 2} Jerry

Return As Dictionary - Dotted Syntax
${output}= Query SELECT * FROM person return_dict=True
${field_names}= Get Dictionary Keys ${output}[0]
IF "FIRST_NAME" in $field_names
VAR ${field_name}= FIRST_NAME
ELSE IF "first_name" in $field_names
VAR ${field_name}= first_name
ELSE
FAIL Unexpected field name in dictionary
END
Should Be Equal As Strings ${output[0].${field_name}} Franz Allan
Should Be Equal As Strings ${output[1].${field_name}} Jerry

Verify Execute SQL String - Row Count person table
${output}= Execute SQL String SELECT COUNT(*) FROM person
Log ${output}
Expand Down