[MDEV-19728] Comments in SQL Created: 2019-06-11  Updated: 2019-06-12  Resolved: 2019-06-11

Status: Closed
Project: MariaDB Server
Component/s: N/A
Affects Version/s: 10.4.5
Fix Version/s: N/A

Type: Bug Priority: Major
Reporter: Wolfgang Draxler Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None
Environment:

Windows


Issue Links:
Duplicate
duplicates MDEV-12087 sql_mode=ORACLE: a new option to make... Open

 Description   

I have found the following problem:
When in a SQL-Statement there is a commentline and between the '--' and the text there is no ein space, then I get the error ERROR 1064 (42000)....

e.g.

select *
 from information_schema.columns
where TABLE_NAME = 'ALL_PLUGINS'
--and data_type = 'varchar'
;

Error:
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 'and data_type = 'varchar'' at line 4

select *
 from information_schema.columns
where TABLE_NAME = 'ALL_PLUGINS'
-- and data_type = 'varchar'
;

then I get no error and get the correct result.



 Comments   
Comment by Alice Sherepa [ 2019-06-11 ]

This is not a bug, a comment requires the second dash to be followed by at least one whitespace or control character (such as a space, tab, newline, and so on) (https://mariadb.com/kb/en/library/comment-syntax/ ) to prevent problems with negative numbers

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

Comment by Wolfgang Draxler [ 2019-06-11 ]

For numbers, this is also the case with the Oracle database.
Such as.

select---123345 from dual;
---12 
--------- 
-12

But if after the --a sign comes, then it's a comment. And so that is a bug. In Oracle mode at all (SET SESSION sql _ mode = ORACLE; )

Comment by Alice Sherepa [ 2019-06-11 ]

I am not sure what do you mean. It works the same way in Oracle mode.

MariaDB [test]> SET SESSION sql_mode = ORACLE;
Query OK, 0 rows affected (0.000 sec)
 
MariaDB [test]> select ---123345 from dual;
+-----------+
| ---123345 |
+-----------+
|   -123345 |
+-----------+
1 row in set (0.002 sec)
 
MariaDB [test]> select version();
+--------------------+
| version()          |
+--------------------+
| 10.4.5-MariaDB-log |
+--------------------+
1 row in set (0.000 sec)
 
MariaDB [test]> select --12--6---1 from dual;
+-------------+
| --12--6---1 |
+-------------+
|          17 |
+-------------+
1 row in set (0.000 sec)
 
MariaDB [test]> show variables like 'sql_mode';
+---------------+----------------------------------------------------------------------------------------------------------------------------------------------+
| Variable_name | Value                                                                                                                                        |
+---------------+----------------------------------------------------------------------------------------------------------------------------------------------+
| sql_mode      | PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ORACLE,NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS,NO_AUTO_CREATE_USER,SIMULTANEOUS_ASSIGNMENT |
+---------------+----------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.002 sec)

Comment by Wolfgang Draxler [ 2019-06-11 ]

by numbers works MariaDB and Oralce equal. That ist correct.
e.g.

select ---123345 from dual;

But what I mean is, that by characters is not equal
by my e.g.

--and data_type = 'varchar'

by MariaDB I get the error "ERROR 1064 (42000): ...."

by Oracle I get no error, because oracle interpret this is as a comment

Comment by Alice Sherepa [ 2019-06-11 ]

I see, you are right. There is a task to implement it - MDEV-12087.

Comment by Wolfgang Draxler [ 2019-06-12 ]

Thank you.

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