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

Query parser doesn't ignore embedded comments #239

Open
jgallagher opened this issue Apr 4, 2024 · 0 comments
Open

Query parser doesn't ignore embedded comments #239

jgallagher opened this issue Apr 4, 2024 · 0 comments

Comments

@jgallagher
Copy link

Hi! I tried to give cornucopia a spin with some fairly involved queries, and got some strange errors back. I think the cause is that I tried to use a query with several comments embedded in it, and cornucopia seems to try to parse those as SQL, which can throw all kinds of things off. Some simple examples based on this query (which is obviously fine):

--! foo
SELECT :foo::int8;

If we add a comment with a colon, cornucopia no longer realizes that :foo is a bind parameter:

--! foo
SELECT
  -- comment with a colon:
  :foo::int8;
Error:   × Couldn't prepare query: db error: ERROR: at or near ":": syntax error
  │ DETAIL: source SQL:
  │ SELECT
  │   -- comment with a colon:
  │   :foo::int8
  │   ^
  │ HINT: try \h SELECT
   ╭─[queries/rack.sql:1:1]
 1 │ --! foo
   ·     ─┬─
   ·      ╰── error occurs near this location
 2 │ SELECT
   ╰────

If we add a comment with a semicolon, cornucopia thinks that ends the query:

--! foo
SELECT
  -- comment with a semicolon; then more comment text
  :foo::int8;
Error:   × Couldn't parse queries
   ╭─[queries/rack.sql:2:1]
 2 │ SELECT
 3 │   -- comment with a semicolon; then more comment text
   ·                                ┬
   ·                                ╰── unexpected token
 4 │   :foo::int8;
   ╰────
  help: found 't' but one of end of input, - was expected

I took a very brief look at parse_sql_query, but am not familiar enough with chumsky to suggest a fix - sorry!

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

1 participant