Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 202602

Summary: support: comments in source
Product: [Tools] Data Tools Reporter: Jeremy Lindop <jeremyl>
Component: SQL Query BuilderAssignee: Brian Payton <bpayton>
Status: RESOLVED FIXED QA Contact:
Severity: enhancement    
Priority: P3 CC: bpayton, drigby
Version: 1.5Keywords: helpwanted
Target Milestone: 1.7M5   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Bug Depends on: 215237    
Bug Blocks:    
Attachments:
Description Flags
K&R style comment formatting
none
SQLQuerySourceWriter add a space to leading multiline comment drigby: review?

Description Jeremy Lindop CLA 2007-09-07 05:56:34 EDT
The SQL Builder should be made to support comments inside SQL statements. It should be able to insert comments as well as to read and preserve existing comments inside SQL statements. Note that comments before or after a SQL statement are outside the scope of the current statement being edited by the SQL Builder.

Estimate: 8 days
Comment 1 Jeremy Lindop CLA 2008-01-14 11:46:56 EST
This is dependent on the SQL Query Parser correctly parsing both simple and bracketed comments (i.e. beginning with -- or bracketed inside /*  */).
215239
215237
Comment 2 Brian Fitzpatrick CLA 2008-10-24 13:05:07 EDT
Removing SQB: prefix on bug title at PMC request
Comment 3 Duncan Rigby CLA 2008-11-28 10:24:37 EST

The problem is when a Kennigan & Richie (open) comment is on the same line as a token (or unterminated on that line), the leading whitespace is truncated.
see ( RS/* )

The source string in the SQL builder model preservers the spacing but when statement is read from the model it loses the whitespace.

SELECT *
  FROM APP.CUSTOMERS/* This is where the leading whitespace of the K&R open commnent is removed */
  /* This is preserved */
   -- This is preserved
/* This is where the leading whitespace of the K&R open commnent is removed
    * 
    * 
    * This is preserved
    * 
    * 
    */
        WHERE CUSTOMERNUMBER > 103 AND CUSTOMERNUMBER < 120 -- This is preserved
Comment 4 Duncan Rigby CLA 2008-12-01 11:53:14 EST
org.eclipse.datatools.sqltools.parsers.sql.query.AbstractSQLQueryParser
populates the domain model with sqoToAppendComment.getSourceInfo().getComments().add(comment);, 
the (comment) is dreived using org.eclipse.datatools.sqltools.parsers.sql.AbstractSQLQueryParser.

The leading spaces are not preseverd, at best I will insert 1 space to stop the truncating and confusing look of lines where this has happend with K&R "/* */" style comments and is consitent with the "--" comment.
Comment 5 Duncan Rigby CLA 2008-12-01 12:12:06 EST
Created attachment 119174 [details]
K&R style comment formatting

This patchBZ202602.txt is to add 1 leading space to any K&R style ("/*  */") comment to visualy aid the format of the SQL statement ,when it is loaded/unloaded into the SQL Query Builder.
Comment 6 Brian Payton CLA 2008-12-01 20:32:27 EST
Hi Duncan,

Rather than modifying the parsing side of things, it would make more sense to change the SQL Source Writer.  Take a look at the 
appendComment(SQLComment comment, StringBuffer sb)
method in the SQLQuerySourceWriter class in the plugin org.eclipse.datatools.modelbase.sql.query.
Comment 7 Duncan Rigby CLA 2008-12-02 12:27:30 EST
Created attachment 119293 [details]
 SQLQuerySourceWriter  add a space to leading multiline comment

The example that follows has it's formatting preservedwhen entering or leaving the SQB Statement editor
Example:
UPDATE APP.TESTTABLE_LOOOOOOONGNAME
  SET C2_VARCHAR_LONGNAME = (
      SELECT C2_VARCHAR --<< WHAT HAPPENS HERE is ?
        FROM APP.TESTTABLE /* <<THIS IS WHERE IT HAPPENS */
        WHERE C1_INTEGER = 1), C3_CHAR_LOOOOOOOOOOONGNAME
         /* this is the first line  of comment
               * 2nd
               * 3rd
               */
                    = (
                        SELECT C3_CHAR -- << WHAT HAPPENS HERE is ?
                          FROM APP.TESTTABLE
                          WHERE C1_INTEGER = 1)
  WHERE C1_INTEGER_LONGNAME = 1
Comment 8 Brian Payton CLA 2009-01-23 22:35:57 EST
OK, looks good.  I'll check in the change.
Comment 9 Brian Payton CLA 2009-01-23 22:49:57 EST
Checked in the change, tagged to v200901241145 (DTP_1_6_2_Branch) and v200901241150 (HEAD).