DB result iteration fix on empty result

get_table_json would throw exceptions when trying to iterate over a NONE result, ie SQL query returned empty result.
This commit is contained in:
Ingo Ratsdorf
2025-09-10 09:28:45 +12:00
parent 2b2ae516da
commit a94c6a291e

View File

@@ -199,8 +199,12 @@ def get_table_json(sql, sql_query):
mylog('verbose', ['[Database] - SQL ERROR: ', e])
return json_obj({}, []) # return empty object
result = {"data": [row_to_json(column_names, row) for row in rows]}
return json_obj(result, column_names)
if (rows):
result = {"data": [row_to_json(column_names, row) for row in rows]}
return json_obj(result, column_names)
else:
# the SQL query returned no rows
return json_obj({}, []) # return empty object
#-------------------------------------------------------------------------------