Final fix

This commit is contained in:
Ingo Ratsdorf
2025-09-10 12:38:33 +12:00
parent 7f7b0a328f
commit ccec89f419

View File

@@ -193,16 +193,21 @@ def get_table_json(sql, sql_query):
""" """
try: try:
sql.execute(sql_query) sql.execute(sql_query)
column_names = [col[0] for col in sql.description]
rows = sql.fetchall() rows = sql.fetchall()
data = [row_to_json(column_names, row) for row in rows] if rows else [] if (rows):
return json_obj({"data": data}, column_names if rows else []) # We only return data if we actually got some out of SQLite
column_names = [col[0] for col in sql.description]
data = [row_to_json(column_names, row) for row in rows]
return json_obj({"data": data}, column_names)
except sqlite3.Error as e: except sqlite3.Error as e:
# SQLite error, e.g. malformed query
mylog('verbose', ['[Database] - SQL ERROR: ', e]) mylog('verbose', ['[Database] - SQL ERROR: ', e])
return json_obj({"data": []}, []) # return empty object
except Exception as e: except Exception as e:
# Catch-all for other exceptions, e.g. iteration error
mylog('verbose', ['[Database] - Unexpected ERROR: ', e]) mylog('verbose', ['[Database] - Unexpected ERROR: ', e])
return json_obj({"data": []}, [])
# In case of any error or no data, return empty object
return json_obj({"data": []}, [])
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
class json_obj: class json_obj: