yeshql icon indicating copy to clipboard operation
yeshql copied to clipboard

Colon in sql comments results in error

Open mihaigiurgeanu opened this issue 4 years ago • 3 comments

Parsing SQL that contains comments with colons results in error. Herer it is a sample of SQL to reproduce the error:

[yesh1|
  -- name:getUser :: (String)
  -- :userID :: Int
  -- :dd     :: String
  SELECT username /*comment: see xxxx */
  FROM users
  INNER JOIN ( SELECT * FROM XXCART WHERE DD = :dd)
  WHERE id = :userID
|]

mihaigiurgeanu avatar Mar 30 '20 22:03 mihaigiurgeanu

That's because YeshQL doesn't actually parse SQL - it can't, because that would require knowing which SQL dialect we're dealing with, and for most of them, also the current server configuration (most SQL DBMSes have configurable syntax; e.g., MySQL can be configured to accept different styles of commenting and quoting).

Hence, SQL syntax, including comment markers, are completely ignored, and YeshQL simply attempts to pick up anything that looks like its own syntax, which, by design, includes colons.

I'm not quite sure how to make this example work without making rather intrusive changes to the design, but if you have an idea, I'm all ears.

tdammers avatar Mar 31 '20 07:03 tdammers

I am thinking use some kind of heuristics instead of parsing the sql, but I am not very clear how it can be done.

mihaigiurgeanu avatar Mar 31 '20 16:03 mihaigiurgeanu

One way to do it would be to have some sort of escaping mechanism; then you could just write : to indicate a literal colon (which would also solve the problem that you cannot currently write PostgreSQL type annotations in your queries). Only downside with that is that legit \ also has to be escaped, which could cause multiple escaping hell. I still think it's a good idea though, so maybe I'll implement it (or if you want to volunteer, go ahead).

On Tue, Mar 31, 2020, 18:29 Mihai Giurgeanu [email protected] wrote:

I am thinking use some kind of heuristics instead of parsing the sql, but I am not very clear how it can be done.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/tdammers/yeshql/issues/12#issuecomment-606735417, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAK6HR43P3R35I633MGXQ7DRKIK7RANCNFSM4LXCGHPA .

tdammers avatar Mar 31 '20 17:03 tdammers