Open colorwlof opened 1 month ago
Hey there, @colorwlof! I'm here to help you out with any issues you're facing. Just give me a nudge if you need assistance with bug fixes, questions, or becoming a contributor.
The error Not an executable object
occurs because the SQL query generated or executed is not valid or executable. This can happen if the query syntax is incorrect or if the query does not conform to the expected SQL standards.
In your case, the SQL query seems to be correctly formatted. However, the issue might be related to how the query is being passed or executed. Ensure that the query passed to the agent.chat
method is a valid SQL query and that it uses authorized tables.
Here is an example of how to correctly pass a valid SQL query:
response = agent.chat("SELECT ELECTRY_NAME, METER_READING_READING FROM M_Y_ENERGYELECTRY WHERE BUILDING_NAME LIKE '%12号楼%' ORDER BY METER_READING_READING DESC LIMIT 5;")
print(response)
Additionally, make sure that the execute_direct_sql_query
method in the SQLConnector
class is used correctly. This method checks if the SQL query is safe before executing it:
def execute_direct_sql_query(self, sql_query):
if not self._is_sql_query_safe(sql_query):
raise MaliciousQueryError("Malicious query is generated in code")
return pd.read_sql(sql_query, self._connection)
Ensure that your SQL query does not contain any potentially malicious keywords such as INSERT
, UPDATE
, DELETE
, DROP
, EXEC
, ALTER
, or CREATE
. If any of these keywords are present, a MaliciousQueryError
will be raised [1][2].
By ensuring the query is valid and safe, you should be able to avoid the Not an executable object
error.
To continue the conversation, mention @dosu.
I have fixed it, sql_query=text(sql_query) , in sql.py , line 441
System Info
2.0.43
🐛 Describe the bug
code:
erro: Not an executable object: "\nSELECT \n ELECTRY_NAME,\n METER_READING_READING\nFROM \n M_Y_ENERGYELECTRY\nWHERE \n BUILDING_NAME LIKE '%12号楼%'\nORDER BY \n METER_READING_READING DESC\nLIMIT 5;\n"
debug:
result = {} sql_query = """ SELECT ELECTRY_NAME, METER_READING_READING FROM M_Y_ENERGYELECTRY WHERE BUILDING_NAME LIKE '%12号楼%' ORDER BY METER_READING_READING DESC LIMIT 5; """ top_meters_df = execute_sql_query(sql_query) if not top_meters_df.empty: result = {'type': 'dataframe', 'value': top_meters_df} else: result = {'type': 'string', 'value': 'No data found for Building 12 meters.'}