HASS-data-detective
HASS-data-detective copied to clipboard
Format limit to int to prevent errors if passing floats
Using detective with the MariaDB Hassio addon I get the following error on calling db.fetch_all_sensor_data(limit=1e9)
:
ProgrammingError: (MySQLdb._exceptions.ProgrammingError) (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '1000000000.0' at line 8")
[SQL:
SELECT domain, entity_id, state, last_changed, attributes
FROM states
WHERE
domain IN ('binary_sensor', 'sensor')
AND
state NOT IN ('unknown', 'unavailable')
ORDER BY last_changed DESC
LIMIT 1000000000.0
Using an int is fine. Add format passed values as int
It's never occurred to me to try, but I don't think this is valid in any SQL dialect. (Passing anything but an Integer to LIMIT/TOP/ROWNUM)
Can just add a type hint and convert to an int