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

Incorrect empty array returned for syntactically incorrect SELECT query #1814

Open
davidevico opened this issue Oct 2, 2023 · 2 comments
Open

Comments

@davidevico
Copy link

We have some code to dinamically generate a SQL-like string that we pass to AlaSQL to run. Sometimes the WHERE clause gets compiled with what would be incorrect SQL code. In that case, AlaSQL returns us an empty array, whereas we would expect a syntax error.

For example, you can reproduce this behavior in one of the JSFiddle found in the Readme: demo.
The sample defines a query on line 7
SELECT * FROM cities WHERE population < 3500000 ORDER BY population DESC
If you run the sample, this query correctly returns a couple of results in the right-hand panel.

Case 1: If you update the query to something like
SELECT * FROM cities WHERE hi
In the right-hand panel the result of this query is an empty array.

Case 2: If you remove the WHERE clause altogether
SELECT * FROM cities WHERE
You get a syntax error in the console, as expected:
Uncaught SyntaxError: Parse error on line 1: ... * FROM cities WHERE -----------------------^ Expecting 'LITERAL', 'BRALITERAL', 'LPAR', 'NUMBER', 'STRING', 'SHARP', 'DOLLAR', 'AT', 'VALUE', 'COLON', 'NOT', 'IF', 'PLUS', 'STAR', 'QUESTION', 'FIRST', 'LAST', 'CURRENT_TIMESTAMP', 'JAVASCRIPT', 'NEW', 'CAST', 'CONVERT', 'SUM', 'TOTAL', 'COUNT', 'MIN', 'MAX', 'AVG', 'AGGR', 'ARRAY', 'REPLACE', 'DATEADD', 'DATEDIFF', 'TIMESTAMPDIFF', 'INTERVAL', 'TRUE', 'FALSE', 'NSTRING', 'NULL', 'EXISTS', 'ARRAYLBRA', 'BRAQUESTION', 'CASE', 'TILDA', 'MINUS', 'ATLBRA', 'LCUR', got 'EOF' at _.parseError (alasql@2:2:243814) at fs.parse (alasql@2:2:239172) at L.parse (alasql@2:2:269078) at L.dexec (alasql@2:2:270683) at L.exec (alasql@2:2:270431) at L (alasql@2:2:1961) at ?editor_console=true:118:11

Case 3: If you update the query to something similar to this:
SELECT * FROM cities WHERE 'hi'
You get four records as a result, so it seems as if the WHERE condition is sintactically correct and no filter is applied.

Case 4: Updating the query to a mixed situation like the following
SELECT * FROM cities WHERE hi population < 3500000 ORDER BY population DESC
We get a similar syntax error to case 2, this is also what we would expect.

We would expect case 1 to throw a similar syntax error to case 2. Is this the expected behavior? Am I missing something?
Thanks!

@davidevico
Copy link
Author

Hi @mathiasrw, did you have a chance to review this issue?

@mathiasrw
Copy link
Member

Hi @davidevico

I would love to review and merge a PR for this, bur dont have time to dive deeper at the moment.

I dont think its hard to solve. The hard part is to dive into the code and find the right spot where we determine that the AST is including a reference to an undefined entity

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

2 participants