zzzprojects / sqlfiddle

http://sqlfiddle.com
MIT License
275 stars 52 forks source link

Comments not working properly in Oracle, WebSQL #58

Open plushy opened 11 years ago

plushy commented 11 years ago

The -- coments don't work properly if the comment is not followed by a query: http://sqlfiddle.com/#!4/ee7da/3121 http://sqlfiddle.com/#!7/04eca/159 Or if the commented out line contains ";": http://sqlfiddle.com/#!4/ee7da/3122 http://sqlfiddle.com/#!7/04eca/160 It seems to work fine for other databases but I only tested one version of each.

jakefeasel commented 11 years ago

Ah, yes this is because those comments are being executed by themselves. I may have to have a specific catch in there to handle this type of error. Thanks for the bug report!

plushy commented 11 years ago

Oh, it seems that I missed MySQL and it affects it as well. http://sqlfiddle.com/#!9/a2581/40 It also seems to give an error with c style comments for other db: http://sqlfiddle.com/#!1/6ccc5/878 So rather than catching error it would be great if the comments wouldn't be executed at all (that would also prevent empty results though those are rather a small thing).

jakefeasel commented 11 years ago

MySQL apparently doesn't like -- style comments with no space between the dashes and the comment. Compare this fiddle to yours, for example:

http://sqlfiddle.com/#!9/a2581/59 (vs. http://sqlfiddle.com/#!9/a2581/40)

The PostgreSQL error, the other MySQL error, and the other "c style" errors in Oracle and SQLite were due to my "simple" (read: stupid) batch parsing logic. I check for a statement delimiter at the end of each newline and break the statement there. This includes within comments. So, compare the two pg fiddles:

Mine: http://sqlfiddle.com/#!1/6ccc5/1054 Yours: http://sqlfiddle.com/#!1/6ccc5/878

As much as I would like to have a smarter statement parser.... it's just not going to happen. Such a thing would require far too much analysis of the statement and knowledge of the particularities of the given database. As it stands, people will simply have to live with my stupid parser and deal with not having trailing semi-colons in their fiddles. I've tried to mitigate this problem by letting people choose another statement separator (the little [ ; ] button under each panel).

This leaves the problem with running statements which are nothing but a comment. This is something I think I can fix by catching the specific error.

plushy commented 11 years ago

Is pg 9.1.8 okay? I can't load the examples here or any else fiddle with it. Hmm...

jakefeasel commented 11 years ago

There was some problem with it, not sure what. Restarting postgres fixed it. Thanks. (btw direct email might be easier if you see something like this again - admin at sqlfiddle dot com)