[MDEV-15260] Changing delimiter after commented line in mysql client Created: 2018-02-09  Updated: 2023-04-27

Status: Confirmed
Project: MariaDB Server
Component/s: Scripts & Clients
Affects Version/s: 5.5.59, 10.2.12
Fix Version/s: 10.4

Type: Bug Priority: Minor
Reporter: Juha Pyy Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None
Environment:

Debian / Ubuntu


Attachments: File MariaDB mysql WITH comments option.log     File MariaDB mysql without comments option.log     File Oracle mysql.log     File broken comments with less invisible symbols.sql    

 Description   

Encountered an odd "You have an error in your SQL syntax" error while running a script into mysql client. After making sure there were no obvious errors or typos in our script, I finally found the culprits causing the error.

Seems like commented lines with white space before the comment mark "--" (or actually also "#") makes the command processing continue until a delimiter is encountered. But if trying to change the delimiter right after such commented line, the delimiter change is not executed and results in syntax error message when ("old") delimiter is finally encountered later.
Same happens with multi-line comments. There is no difference whether the comment block is actually on multiple lines or on a single line.

Expected result: DELIMITER command should be executed whether the previous line/command is commented out (with or without white space) or multi-line comment.

See attached files for a script with working and non-working cases, including workarounds at the end, and results when each segment of commands was executed in mysql client.

Also tested in Oracle mysql, which seems to behave differently with multi-line comments in that it doesn't require a delimiter after the end of the comment block in order for the delimiter change to work correctly. The white space problem is there as well, although it is not immediately visible if executing the commands just one line at a time.

Edit: The errors happen when --comments option is given to mysql client (either from command line or having "comments=1" in config file).



 Comments   
Comment by Alice Sherepa [ 2018-02-09 ]

Hi Juha, I guess you have some symbols, that are not visible there, in word DELIMITER (letter D)
this is copied from your file and returns syntax error:

 -- this comment is "broken"
DELIMITER $$
SELECT 'Not OK'$$
DELIMITER ;

please check again.
If I use the same commands, but writing down it by myself, not copy-paste, it works as expected

Comment by Elena Stepanova [ 2018-02-09 ]

In the fragment above, the invisible symbol is before the first `DELIMITER`. Hexdump or alike will help to see it.

Comment by Juha Pyy [ 2018-02-09 ]

Hi Alice, thanks for your reply.
You were right about the invisible symbols, there was some crap before the letter D in at least two of the cases. I've re-uploaded a cleaner version of the sql file.

It didn't matter whether I copy-pasted or wrote by hand, I still got the same result each time.
But since it works for you, I now thought there must be something in my config which is causing this. And there was! I've forgot I have put "comments=1" in .my.cnf, which seems to cause this behaviour.

Now I'm also able to replicate these cases in Oracle mysql as well, e.g.
mysql -uuser -p --comments

mysql>   -- comment whatever
    -> delimiter $$
    -> SELECT 'Not going to work now.'$$
    -> ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'delimiter $$SELECT 'Not going to work now.'$$' at line 2

This is how it now looks like for me:

  • with comments=0, all the "broken" cases do work in MariaDB mysql, but the white spaced case doesn't work in Oracle mysql (although after inputting the comment line, it first looks like it would work but fails eventually)
  • with comments=1, none of the "broken" cases work in MariaDB or Oracle mysql

Alice (or someone else), could you please try if you can replicate the issue now with the comments option?

Comment by Alice Sherepa [ 2018-02-12 ]

I get syntax errors with Mysql client option --comments (preserve comments in statements sent to the server).

1)line starts with "-- " - does not need delimiter in the end
2)In case, when we have something before the first symbol "-", like a space in the testcase " – ", or other symbols, it is treated as the start of the query and needs delimiter at the end.E.g.

MariaDB [(none)]> select -- kjkljb
    -> 1;
+---+
| 1 |
+---+
| 1 |
+---+
1 row in set (0.00 sec)

If this comment is followed by DELIMITER:

MariaDB [(none)]>  -- khklfd
    -> delimiter $$
    -> ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'delimiter $$' at line 2
 
MariaDB [(none)]>  -- this comment is broken
    -> DELIMITER $$
    -> SELECT 'Not OK'$$
    -> DELIMITER ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'DELIMITER $$SELECT 'Not OK'$$
DELIMITER' at line 2

3) In the case of /* ..........*/ it has to have delimiter in the end (for those cases, when it will be an executable comment )
If DELIMITER is changed after that, then the same situation as in the second case.

MariaDB [(none)]> /* this comment is also "broken" */ 
    -> delimiter !
    -> ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'delimiter !' at line 2

4)comments after DELIMITER - treated as a delimiter, not as a comment:
DELIMITER /* kknfksd */

Comment by Juha Pyy [ 2018-02-13 ]

Thanks Alice for the confirmation and clarifications.

Comment by Elena Stepanova [ 2018-10-05 ]

alice, do you consider any of the described cases to be wrong? If so, could you please indicate which are (and why) and move the bug report forward? Otherwise, you can close it.

Comment by Alice Sherepa [ 2018-10-05 ]

I switched to the another laptop and can not reproduce the same behavior. (it is also Ubuntu 16.04, but maybe some settings are different).

MariaDB [test]>           /* this*/
MariaDB [test]>     -- this
MariaDB [test]>  /* this  */;
ERROR: No query specified

The case 4, when comment starts right after "DELIMITER" clause - the warning should be returned (or it should be mentioned in the documentation) (the same applies to all reserved words,.. KB says, that delimiter should be distinct, but it is not checked, it expects the user to be reasonable.)

MariaDB [test]> delimiter --1
MariaDB [test]> select 1;
    -> --1
+---+
| 1 |
+---+
| 1 |
+---+
1 row in set (0.01 sec)
MariaDB [(none)]> delimiter  /*comment*/
MariaDB [(none)]> select 1 ;
    -> /*comment*/
+---+
| 1 |
+---+
| 1 |
+---+
1 row in set (0.00 sec)
 
MariaDB [(none)]> delimiter select
MariaDB [(none)]> select 1;
ERROR: No query specified
 
    -> select 
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '1' at line 1

Generated at Thu Feb 08 08:19:55 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.