levensailor / ciscoaxl

Python SDK for Cisco CUCM AXL API
https://pypi.org/project/ciscoaxl
MIT License
84 stars 42 forks source link

ucm.execute_sql_query can't run. #7

Open yuexp001 opened 4 years ago

yuexp001 commented 4 years ago

Hello I got an error message 'axl' object has no attribute 'execute_sql_query' when I try it run SQL query.

Insigna2020 commented 4 years ago

I have not tested it yet but it looks like the documentation have some typos. I can see on the code that if you need to execute a sql query, you will need to do "sql_query(your_query)" and if you need to update the database, you will need to use "sql_update(your_update_query)" both takes one argument. Code snippet from axl.py:

def sql_query(self, query):
    """
    Execute SQL query
    :param query: SQL Query to execute
    :return: result dictionary
    """
    try:
        return self.client.executeSQLQuery(query)["return"]
    except Fault as e:
        return e

def sql_update(self, query):
    """
    Execute SQL update
    :param query: SQL Update to execute
    :return: result dictionary
    """
    try:
        return self.client.executeSQLUpdate(query)["return"]
    except Fault as e:
        return e
Randle-Lanre commented 3 years ago

@yuexp001 @Insigna2020 did you later get a fix for this, there was some typos in the documentation and running

def sql_query(self, query):

kept returning 'NoneType' object is not iterable

htjmetcalf commented 3 years ago

I was able to work around this by adding the ['rows'] after my SQL statement. The issue is the return has a parent element called <rows></rows> We cannot iterate over the <return></return> tag because it only contains one item, which is <rows> but we can iterate over the <rows> element.

Also changed from Execute to Run in the Function Call.

I'll work on fixing this in the axl.py and forking it, but I've never done that before. Also, a quick note that this library is fantastic, and I am thankful for the time and effort that has gone into it.

Execute SQL Query

for sql in ucm.run_sql_query('select * from device where description like "Bart%"')['rows']:
    print(sql['name'])