Skip to content
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

SQL_Query Return Dict #21

Open
JFK344 opened this issue Nov 17, 2021 · 1 comment
Open

SQL_Query Return Dict #21

JFK344 opened this issue Nov 17, 2021 · 1 comment

Comments

@JFK344
Copy link

JFK344 commented Nov 17, 2021

Wold be nice if SQL Query would return Dict and not unserialized Data. This makes it run:

This is a Function outside of the axl class:

def element_list_to_ordered_dict(elements):
    return [OrderedDict((element.tag, element.text) for element in row) for row in elements]

This replaces the existing function:

    def sql_query(self, query):
        axl_resp = self.client.executeSQLQuery(sql=query)
        try:
            value = element_list_to_ordered_dict(serialize_object(axl_resp)["return"]["rows"])
            jsonList = []    
            for i in range(len(value)):
                jsonList.append(json.loads(json.dumps(value[i])))
            return jsonList

        except KeyError:
            # single tuple response
            value = element_list_to_ordered_dict(serialize_object(axl_resp)["return"]["row"])
            jsonList = []   
            for i in range(len(value)):
                jsonList.append(json.loads(json.dumps(value[i])))
            return jsonList

        except TypeError:
            # no SQL tuples
            return serialize_object(axl_resp)["return"]

Required Libs:

from zeep.helpers import serialize_object
from collections import OrderedDict
@Yoxcy
Copy link

Yoxcy commented Feb 11, 2023

Input:

for sql in ucm.run_sql_query('run sql select * from device'):
print(sql.name)

Output:

print(sql.name)

AttributeError: 'str' object has no attribute 'name'

How to fix this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants