Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format limit to int to prevent errors if passing floats #118

Open
robmarkcole opened this issue Feb 15, 2020 · 2 comments
Open

Format limit to int to prevent errors if passing floats #118

robmarkcole opened this issue Feb 15, 2020 · 2 comments
Assignees

Comments

@robmarkcole
Copy link
Owner

robmarkcole commented Feb 15, 2020

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 robmarkcole changed the title SQL error with MariaDB SQL error with MariaDB if pass float as limit Feb 15, 2020
@robmarkcole robmarkcole self-assigned this Feb 15, 2020
@boonhapus
Copy link

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)

@robmarkcole
Copy link
Owner Author

Can just add a type hint and convert to an int

@robmarkcole robmarkcole changed the title SQL error with MariaDB if pass float as limit Format limit to int to prevent errors if passing floats Dec 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants