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 255561 - Wrong color schema if use quote in sql
Summary: Wrong color schema if use quote in sql
Status: NEW
Alias: None
Product: db
Classification: Unclassified
Component: SQL Editor (show other bugs)
Version: 8.1
Hardware: All All
: P3 normal (vote)
Assignee: Libor Fischmeistr
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-09-25 10:29 UTC by h4kuna
Modified: 2015-09-26 19:22 UTC (History)
0 users

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments
sql-color (9.60 KB, image/png)
2015-09-25 10:29 UTC, h4kuna
Details

Note You need to log in before you can comment on or make changes to this bug.
Description h4kuna 2015-09-25 10:29:00 UTC
Created attachment 156424 [details]
sql-color

Hi,

I have a sql where is bad color. Wrong color is visible on image.

Example sql:
[code]
CREATE FUNCTION string_strip_tags(text)
  RETURNS text AS
$BODY$
    SELECT regexp_replace(regexp_replace($1, E'(?x)<[^>]*?(\s alt \s* = \s* ([\'"]) ([^>]*?) \2) [^>]*? >', E'\3'), E'(?x)(< [^>]*? >)', '', 'g');
$BODY$
  LANGUAGE sql VOLATILE
  COST 100;
[/code]

Both version works wrong.

Product Version: NetBeans IDE 8.0.2 (Build 201411181905)
Java: 1.7.0_79; OpenJDK 64-Bit Server VM 24.79-b02
Runtime: OpenJDK Runtime Environment 1.7.0_79-b14
System: Linux version 3.13.0-63-generic running on amd64; UTF-8; cs_CZ (nb)
User directory: /home/milan/.netbeans/8.0.2
Cache directory: /home/milan/.cache/netbeans/8.0.2


Product Version: NetBeans IDE 8.1 Beta (Build 201508041349) 
Java: 1.8.0_51; Java HotSpot(TM) 64-Bit Server VM 25.51-b03 
Runtime: Java(TM) SE Runtime Environment 1.8.0_51-b16 
System: Linux version 3.13.0-63-generic running on amd64; UTF-8; cs_CZ (nb) 
User directory: /home/milan/.netbeans/8.1beta 
Cache directory: /home/milan/.cache/netbeans/8.1beta


Here is o thread on forum http://forums.netbeans.org/viewtopic.php?p=166322
Comment 1 matthias42 2015-09-26 19:22:40 UTC
Retyping to Enhancement - reason:

The demostrated statement is not valid SQL. This is also documented in the postgresql documentation:

http://www.postgresql.org/docs/9.4/static/sql-syntax-lexical.html

"[...]4.1.2.2. String Constants with C-style Escapes

PostgreSQL also accepts "escape" string constants, which are an extension to the SQL standard.[...]

In this case the quoting rules run contrary to SQL-99 rules. SQL grammar defines, that escaping the quoting character is done by repeating it. So:

'' => empty string
'''' => string with a single quote

The backslash has no special meaning and this breaks your syntax highlighting (look at the last two colored characters).

This was raised as a bug for mysql, which is a bit more broken. For mysql this syntax can be used in "normal strings" (if I'm not mistaken this is a configuration option), than it gets to be real fun - the bug report asked for mysql specific behavior contradicting SQL standard.

Example:
'\'' => SQL-99: broken string (the string is not finished), for mysql this is a single quote
'\' => SQL-99: valid string with a single backslash, broken string on mysql


That request was closed as WONTFIX, as it is not parseable without server knowledge.

In this case it should be possible to change the lexer to support this. I would strongly advice against it.

The SQL can be rewritten to adhere more to SQL standard:

[code]
CREATE FUNCTION string_strip_tags(text)
  RETURNS text AS
$BODY$
    SELECT regexp_replace(regexp_replace($1, E'(?x)<[^>]*?(\\s alt \\s* = \\s* ([''"]) ([^>]*?) \\2) [^>]*? >', E'\\3'), E'(?x)(< [^>]*? >)', '', 'g');
$BODY$
  LANGUAGE sql VOLATILE
  COST 100;
[/code]

I changed two things:

1. I asume by \s you want to get the regexp escape sequence for white-space and \2 and \3 represent back-references, if so the documentation requires the backslashed to be doubled
2. I replace the sequence \' with the SQL conformant '' which is interpreted correctly according to documentation.