HASS-data-detective icon indicating copy to clipboard operation
HASS-data-detective copied to clipboard

Format limit to int to prevent errors if passing floats

Open robmarkcole opened this issue 4 years ago • 2 comments

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

robmarkcole avatar Feb 15 '20 07:02 robmarkcole

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)

boonhapus avatar Feb 22 '20 17:02 boonhapus

Can just add a type hint and convert to an int

robmarkcole avatar Dec 31 '20 04:12 robmarkcole