This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 155167

Summary: Code formatting, folding and bracket matching
Product: db Reporter: Roman Mostyka <romanmostyka>
Component: SQL EditorAssignee: Libor Fischmeistr <lfischmeistr>
Status: NEW ---    
Severity: blocker CC: davidvc, javatlacati, nbphpuser
Priority: P3 Keywords: NETFIX
Version: 6.x   
Hardware: All   
OS: All   
Issue Type: ENHANCEMENT Exception Reporter:
Bug Depends on: 193557    
Bug Blocks:    
Attachments: add bracket matching
add SQL-99 escape handling to lexer

Description Roman Mostyka 2008-12-10 17:37:44 UTC
Add code formatting, folding and bracket matching for SQL editor.
Comment 1 Jiri Rechtacek 2009-10-16 14:05:11 UTC
Reassigned to new owner.
Comment 2 matthias42 2012-05-17 11:06:17 UTC
*** Bug 146553 has been marked as a duplicate of this bug. ***
Comment 3 matthias42 2012-05-17 11:06:30 UTC
*** Bug 185452 has been marked as a duplicate of this bug. ***
Comment 4 matthias42 2012-05-19 20:48:12 UTC
Created attachment 119649 [details]
add bracket matching
Comment 5 matthias42 2012-05-19 20:48:59 UTC
Created attachment 119650 [details]
add SQL-99 escape handling to lexer
Comment 6 matthias42 2012-05-19 20:51:35 UTC
The last two patches can only be applied after the changes started in bug #193557 are applied. I'll have a look at code formatting next.
Comment 7 Jaroslav Havlin 2012-06-18 13:59:53 UTC
I've tested the proposed bracket matching, and it seems to contain a bug.
If SQL editor contains a word whose first and last letters are the same (e.g. "samples"), and the cursor is at the beginning or end of the word, this pair of letters is highlighted (I guess it is not intentional).

Why have you decided to implement a custom bracket matcher? Do you think the the default one is not sufficient (http://hg.netbeans.org/core-main/rev/dbca6e992987)?


I think that escape handling is a non-standard feature of MySQL (if I am wrong please correct me). Cannot it cause problems when writing SQL for other databases?

Thank you very much.
Comment 8 matthias42 2012-06-26 19:59:08 UTC
Hey, thanks for your feedback! Your right there is a bug in the bracket matcher. 

The bracket matching differs in the respect, that different things are matched. I intended this behavior:

- match round brackets outside identifiers and strings
- match quoting characters:
  - ' for strings
  - `" and the pair [] for identifiers

The changed quote handling in the lexer is correct for the SQL-99 standard. There is no backslash to escape special meaning, but doubling the character to be protected (which is only the used quoting symbol). See

http://savage.net.au/SQL/sql-99.bnf.html#doublequote%20symbol

and 

http://savage.net.au/SQL/sql-99.bnf.html#quote%20symbol

Before any of the two patches can be applied, they need another round (please give some feedback, if your interested). The backet matched needs to be bugfixed and the lexer change should get another fix to mark partly quoted identiefiers as errors (same as the string error marking).

The lexer change is needed, because else a structure like "'identifier''with_embedded_quotes'" is cut into two tokens:
"'identifier'" and "'with_embedded_quotes'" which is wrong. In the current situation the token sequence is mainly used for syntax highlighting, in which this is not a problem, but the correct token would be the complete sequence "'identifier''with_embedded_quotes'".
Comment 9 matthias42 2012-07-12 19:42:37 UTC
Comment on attachment 119650 [details]
add SQL-99 escape handling to lexer

Moved patch to bug #183478 (it does not really belong here)
Comment 10 Jaroslav Havlin 2013-02-12 12:42:33 UTC
http://hg.netbeans.org/core-main/rev/bc7d23461f89
The patch was applied. Thank you, Matthias!
Comment 11 Quality Engineering 2013-02-14 02:19:38 UTC
Integrated into 'main-golden', will be available in build *201302132300* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/bc7d23461f89
User: Jaroslav Havlin <jhavlin@netbeans.org>
Log: #155167: Braces matcher for SQL editor
Comment 12 matthias42 2014-09-18 18:21:36 UTC
Because I was just wondering whether this can be closed - remaining are:

- Code folding
- Code formating

Both depend on a sql parser - at least at the current point I don't see another coherent possibility with structural knowledge.
Comment 13 matthias42 2016-01-04 18:04:52 UTC
*** Bug 257354 has been marked as a duplicate of this bug. ***