Bug #68504 Reformat SQL Query deletes inline code comments
Submitted: 27 Feb 2013 6:03 Modified: 27 Feb 2013 6:36
Reporter: Thom Landin Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Workbench: SQL Editor Severity:S3 (Non-critical)
Version:5.2.47 CE OS:Windows (7 x64 & x32)
Assigned to: CPU Architecture:Any
Tags: beautifier, comments, query, reformat, reformatter

[27 Feb 2013 6:03] Thom Landin
Description:
Reformatting SQL code in the SQL Editor causes commented lines to be deleted.  This is a WTF behavior.

How to repeat:
1. Insert a block of valid SQL statements in the editor
2. Invoke the Reformat SQL Query function via any of the available mechanisms (Edit menu, toolbar button, Utilities menu)
3. Comment out some lines with any of the comment characters (--, #, /* */)
4. Reformat the query again
5. The commented lines are deleted

Suggested fix:
Inline comments in SQL code are valuable for documentation, versioning, ease of maintenance, and are often used as a mechanism to easily enable and disable individual subexpressions in a larger block of common code -- for instance, for debugging purposes, or to avoid having to maintain two separate code files when a single complex query can serve two purposes by commenting or uncommenting an expression or two.

Deleting commented lines during SQL code reformatting punishes developers who use comments to make their code more understandable.  Shame on you!

The appropriate behavior for handling comments in a code reformatter is to either reindent the comment to the left margin, or reindent to the current block indent, or don't move it at all.  But don't reformat or parse any code within the commented line (keywords, expressions, objects, etc.).

These behaviors can (and should) be controlled via checkbox or radiobutton options in the Preferences panel in the SQL tab:

[ ] Retain inline comments in SQL code

( ) Comments always start at left margin
(o) Comments start at current block indent
( ) Comments retain relative position (no reindenting)

The last radiobutton option is for comments that appear at the end of a line of code.  The user probably doesn't want them to be displaced from the line of code they're associated with.
[27 Feb 2013 6:36] MySQL Verification Team
Hello Thom,

Thank you for the bug report, duplicate of http://bugs.mysql.com/bug.php?id=68000

Regards,
Umesh
[21 Feb 2017 17:25] James Bachelder
Bug 65523, Bug 68000, and Bug 68504 are all duplicates and still not fixed in MySQL Workbench 6.3 Version 6.3.8 build 1228 CE (64 bits) running on Win 10.