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

TSQL queries need type checking on conditions #261

Closed
goodmami opened this issue Dec 20, 2019 · 0 comments
Closed

TSQL queries need type checking on conditions #261

goodmami opened this issue Dec 20, 2019 · 0 comments
Milestone

Comments

@goodmami
Copy link
Member

TSQL select queries can take conditions in a where clause:

$ delphin select 'i-id where readings > 0 or i-input ~ "dog"'

Some operators (>, >=, <, <=) expect numeric values, others expect strings (~, !~), and some work for both (=, !=). Currently if a user uses an incorrect type, a TSQLSyntaxError is raised that explains the problem:

$ delphin select 'i-id where i-id ~ 1' mrs/
Traceback (most recent call last):
[...]
delphin.tsql.TSQLSyntaxError: 
  line 1
    1
TSQLSyntaxError: expected one of: a double-quoted string, a single-quoted string

While the error message could be improved, it is reasonable. But if the query is syntactically valid but the query's data type doesn't match that of the column in the database, a more cryptic error message is raised:

$ delphin select 'i-id where i-date ~ "jan"' mrs/
Traceback (most recent call last):
[...]
TypeError: expected string or bytes-like object

These errors would be easy to check before executing the query. We could also allow string and regex matches to work on the string form of the value, regardless of the column's datatype, but this wouldn't help with numeric comparisons on string columns.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant