Bug #95913 Commented lines deleted when applying CREATE VIEW
Submitted: 21 Jun 2019 8:04 Modified: 2 Oct 2019 10:03
Reporter: Clive Wickham Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Workbench: SQL Editor Severity:S3 (Non-critical)
Version:8.0.15, 8.0.16 OS:Windows (10)
Assigned to: CPU Architecture:Any
Tags: create view, deleted comments

[21 Jun 2019 8:04] Clive Wickham
Description:
When creating or altering a View in MySQL Workbench (MySQL Server 5.5), if one comments a line and then applies changes the comments are completely removed from the view definition. This is not desirable nor expected behaviour when developing a view and valuable SQL code can be lost (although the Undo facility does allow one to restore the lost changes).

How to repeat:
1. Select "Schemas" tab in sidebar.
2. Expand appropriate schema.
3. Right-click "Views" category and select "Create View...".
4. Paste the following into the SQL Editor...

   CREATE VIEW `example` AS
       SELECT 
           1 AS Test1,
           2 AS Test2/*,
           3 AS Test3,*/
           # 4 AS Test4
           -- 5 AS Test5,

5. Click the "Apply" button.
6. In the "Apply SQL Script to Database" window, click the "Apply" button, then the "Finish" button.
7. The SQL Editor now shows the following SQL code (with all comments removed)...

   CREATE 
       ALGORITHM = UNDEFINED 
       DEFINER = `abcde`@`%` 
       SQL SECURITY DEFINER
   VIEW `example` AS
       SELECT 1 AS `Test1`, 2 AS `Test2`

Suggested fix:
Leave comments in place and do not remove them automatically when applying a CREATE VIEW statement.
[21 Jun 2019 8:11] MySQL Verification Team
Hello Clive Wickham,

Thank you for the report.

regards,
Umesh
[2 Oct 2019 10:03] Mike Lischke
I misunderstood the bug description as being about our code formatter. But
actually this bug is about a behavior caused by the server. It's not
Workbench which strips out comments, it's the server. Try creating a view
with such a comment in the command line client and then do a `show create
view ...`, which will show you the code without comments (and line breaks
btw. which also are removed).

Hint: if you want to comment out parts only temporarily then don't use the view editor, which re-reads the view text from the server and formats it (and hence no longer has the temporarily commented out code). Instead use a plain SQL editor (but you may have to add a delimiter command then) which simply executes the SQL without re-reading what the server stored.