GNU bug report logs - #37459
26.2; sql syntax highlight problem when escaping single quote

Previous Next

Package: emacs;

Reported by: ndame <emacsuser <at> freemail.hu>

Date: Thu, 19 Sep 2019 12:51:01 UTC

Severity: minor

Tags: fixed, patch

Found in version 26.2

Fixed in version 28.1

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 37459 in the body.
You can then email your comments to 37459 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#37459; Package emacs. (Thu, 19 Sep 2019 12:51:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to ndame <emacsuser <at> freemail.hu>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Thu, 19 Sep 2019 12:51:03 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: ndame <emacsuser <at> freemail.hu>
To: "bug-gnu-emacs <at> gnu.org" <bug-gnu-emacs <at> gnu.org>
Subject: 26.2; sql syntax highlight problem when escaping single quote
Date: Thu, 19 Sep 2019 12:39:33 +0000 (GMT)
[Message part 1 (text/plain, inline)]
If you try this simple sql

  insert into test (test) values ('test\'test')

then the string is not highlighted properly:

https://i.imgur.com/DE9TJUP.png

I guess it's a bug.
 
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#37459; Package emacs. (Fri, 20 Sep 2019 13:30:04 GMT) Full text and rfc822 format available.

Message #8 received at 37459 <at> debbugs.gnu.org (full text, mbox):

From: ndame <emacsuser <at> freemail.hu>
To: "37459 <at> debbugs.gnu.org" <37459 <at> debbugs.gnu.org>
Subject: Re: bug#37459: 26.2; sql syntax highlight problem when escaping
 single quote
Date: Fri, 20 Sep 2019 15:28:54 +0200 (CEST)
[Message part 1 (text/plain, inline)]
I poked around for the problem and found this in sql-mode Help:

  Note that SQL doesn't have an escape character unless you specify
  one.  If you specify backslash as escape character in SQL, you
  must tell Emacs.  Here's how to do that in your init file:

  (add-hook 'sql-mode-hook
            (lambda ()
              (modify-syntax-entry ?\\ "." sql-mode-syntax-table)))


And sure enough, the syntax of \ was punctuation.

However, adding the above add hook did nothing. The string
highlighting was still wrong.

It's because the suggestion is wrong, because it sets slash to
punctuation again.

Somebody who has access to the repo could simply fix that by changing
the syntax string in the example:

  (modify-syntax-entry ?\\ "\\" sql-mode-syntax-table)


So it worked, but then I realized there are different sql modes and
the default is ANSI, so I changed it to Mysql to test it, but that
didn't help either.

Then I checked the mysql syntax setting and backslash was missing
there too, though backslash is an escape character for mysql by
default:

  https://dev.mysql.com/doc/refman/8.0/en/string-literals.html

So I changed the syntax for mysql by adding backslash:

           :syntax-alist ((?# . "< b") (?\\ . "\\"))

and this fixed it.


There are 3 takeaways:

1. The incorrect example in sql-mode Help should be fixed.

2. Since backslash is an escape character in mysql it may be set as
   such by default if the user chooses mysql mode.

3. The user may not realize he is in an incorrect sql mode. Maybe when
   the user activates sql mode for the first time emacs should tell him
   that ansi is the default and ask him if he wants to change it?
   
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#37459; Package emacs. (Sat, 26 Oct 2019 15:54:02 GMT) Full text and rfc822 format available.

Message #11 received at 37459 <at> debbugs.gnu.org (full text, mbox):

From: Kristian Hole <kristian <at> hole.priv.no>
To: 37459 <at> debbugs.gnu.org
Subject: Re: bug#37459: Corrects sql-mode help about escape character syntax
Date: Sat, 26 Oct 2019 17:19:00 +0200
[Message part 1 (text/plain, inline)]

[Message part 2 (text/html, inline)]
[0001-Corrects-sql-mode-help-about-escape-character-syntax.patch (application/octet-stream, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#37459; Package emacs. (Sat, 26 Oct 2019 15:54:02 GMT) Full text and rfc822 format available.

Message #14 received at 37459 <at> debbugs.gnu.org (full text, mbox):

From: Kristian Hole <kristian <at> hole.priv.no>
To: 37459 <at> debbugs.gnu.org
Subject: Re: bug#37459: Adds backslash as escape character to mysql
 syntax-alist
Date: Sat, 26 Oct 2019 17:25:42 +0200
[Message part 1 (text/plain, inline)]
I've generated patches for takeaways (1) and (2)

Patch attached to previous message:
  Corrects sql-mode help about escape character syntax

  Changes the example from the incorrect use of
  punctuation rule, to the escape character rule (Bug#37459).

This patch:
  Adds backslash as escape character to mysql syntax-alist

  In MySQL syntax backslash denotes an escape sequence.
  This change adds backslash to the syntax-alist of
  MySQL in sql-mode as per (Bug#37459).
[Message part 2 (text/html, inline)]
[0002-Adds-backslash-as-escape-character-to-mysql-syntax-a.patch (application/octet-stream, attachment)]

Added tag(s) patch. Request was from Kristian Hole <kristian <at> hole.priv.no> to control <at> debbugs.gnu.org. (Mon, 28 Oct 2019 12:06:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#37459; Package emacs. (Fri, 22 Nov 2019 14:45:01 GMT) Full text and rfc822 format available.

Message #19 received at 37459 <at> debbugs.gnu.org (full text, mbox):

From: ndame <emacsuser <at> freemail.hu>
To: "37459 <at> debbugs.gnu.org" <37459 <at> debbugs.gnu.org>
Subject: Re: bug#37459: Acknowledgement (26.2; sql syntax highlight problem
 when escaping single quote)
Date: Fri, 22 Nov 2019 15:44:37 +0100 (CET)
[Message part 1 (text/plain, inline)]
Browsing sql.el I found this code:
 
;; MariaDB is a drop-in replacement for MySQL, so just make the
;; MariaDB variables aliases of the MySQL ones.
 
(defvaralias 'sql-mariadb-program 'sql-mysql-program)
(defvaralias 'sql-mariadb-options 'sql-mysql-options)
(defvaralias 'sql-mariadb-login-params 'sql-mysql-login-params)
 
 

If mariadb is a drop in mysql replacement then all mysql-related fixes
should apply to it too, though later in the code mariadb sets up syntax
independetly, so the same bug affects it which the patch here fixes.
The correct solution could be setting up a mariadb syntax variable
and alias it to the mysql syntax variable to avoid duplicating the same code:

 
(mariadb

:name "MariaDB"

:free-software t

:font-lock sql-mode-mariadb-font-lock-keywords

:sqli-program sql-mariadb-program

:sqli-options sql-mariadb-options

:sqli-login sql-mariadb-login-params

:sqli-comint-func sql-comint-mariadb

:list-all "SHOW TABLES;"

:list-table "DESCRIBE %s;"

:prompt-regexp "^MariaDB \\[.*]> "

:prompt-cont-regexp "^ [\"'`-]> "

:syntax-alist ((?# . "< b"))
:input-filter sql-remove-tabs-filter)



 
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#37459; Package emacs. (Mon, 20 Jan 2020 19:39:01 GMT) Full text and rfc822 format available.

Message #22 received at 37459 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Kangas <stefan <at> marxist.se>
To: Michael Mauger <michael <at> mauger.com>
Cc: Kristian Hole <kristian <at> hole.priv.no>, 37459 <at> debbugs.gnu.org
Subject: Re: bug#37459: Adds backslash as escape character to mysql
 syntax-alist
Date: Mon, 20 Jan 2020 20:37:58 +0100
Hi Michael,

Kristian Hole <kristian <at> hole.priv.no> writes:

> I've generated patches for takeaways (1) and (2) 
>
> Patch attached to previous message:
>   Corrects sql-mode help about escape character syntax
>
>   Changes the example from the incorrect use of
>   punctuation rule, to the escape character rule (Bug#37459).
>
> This patch:
>   Adds backslash as escape character to mysql syntax-alist
>
>   In MySQL syntax backslash denotes an escape sequence.
>   This change adds backslash to the syntax-alist of
>   MySQL in sql-mode as per (Bug#37459).

Could you please take a look at the below patch?  TIA.

Best regards,
Stefan Kangas

>
> From 4953d7bb249502fd8d87295b81bd381e70134fc0 Mon Sep 17 00:00:00 2001
> From: kahole <kristian <at> hole.priv.no>
> Date: Sat, 26 Oct 2019 17:08:17 +0200
> Subject: [PATCH 2/2] Adds backslash as escape character to mysql syntax-alist
>
> In MySQL syntax backslash denotes an escape sequence.
> This change adds backslash to the syntax-alist of
> MySQL in sql-mode as per (Bug#37459).
> ---
>  lisp/progmodes/sql.el | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/lisp/progmodes/sql.el b/lisp/progmodes/sql.el
> index f985157202..81e0d8cf89 100644
> --- a/lisp/progmodes/sql.el
> +++ b/lisp/progmodes/sql.el
> @@ -461,7 +461,7 @@ sql-product-alist
>       :prompt-regexp "^mysql> "
>       :prompt-length 6
>       :prompt-cont-regexp "^    -> "
> -     :syntax-alist ((?# . "< b"))
> +     :syntax-alist ((?# . "< b") (?\\ . "\\"))
>       :input-filter sql-remove-tabs-filter)
>  
>      (oracle





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#37459; Package emacs. (Sun, 09 Aug 2020 18:58:01 GMT) Full text and rfc822 format available.

Message #25 received at 37459 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Kristian Hole <kristian <at> hole.priv.no>
Cc: Michael Mauger <michael <at> mauger.com>, 37459 <at> debbugs.gnu.org
Subject: Re: bug#37459: Adds backslash as escape character to mysql
 syntax-alist
Date: Sun, 09 Aug 2020 20:57:28 +0200
Kristian Hole <kristian <at> hole.priv.no> writes:

> I've generated patches for takeaways (1) and (2) 
>
> Patch attached to previous message:
>   Corrects sql-mode help about escape character syntax
>
>   Changes the example from the incorrect use of
>   punctuation rule, to the escape character rule (Bug#37459).
>
> This patch:
>   Adds backslash as escape character to mysql syntax-alist
>
>   In MySQL syntax backslash denotes an escape sequence.
>   This change adds backslash to the syntax-alist of
>   MySQL in sql-mode as per (Bug#37459).

[...]

> -     :syntax-alist ((?# . "< b"))
> +     :syntax-alist ((?# . "< b") (?\\ . "\\"))
>       :input-filter sql-remove-tabs-filter)

I don't use mysql in sql mode, but this looks "obviously" correct, so
I've applied it to Emacs 28 (along with the doc fix).  Perhaps Michael
can chime in...

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Added tag(s) fixed. Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Sun, 09 Aug 2020 18:58:02 GMT) Full text and rfc822 format available.

bug marked as fixed in version 28.1, send any further explanations to 37459 <at> debbugs.gnu.org and ndame <emacsuser <at> freemail.hu> Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Sun, 09 Aug 2020 18:58:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#37459; Package emacs. (Sun, 09 Aug 2020 19:03:01 GMT) Full text and rfc822 format available.

Message #32 received at 37459 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Kristian Hole <kristian <at> hole.priv.no>
Cc: Michael Mauger <michael <at> mauger.com>, 37459 <at> debbugs.gnu.org
Subject: Re: bug#37459: Adds backslash as escape character to mysql
 syntax-alist
Date: Sun, 09 Aug 2020 21:02:22 +0200
Lars Ingebrigtsen <larsi <at> gnus.org> writes:

> I don't use mysql in sql mode, but this looks "obviously" correct, so
> I've applied it to Emacs 28 (along with the doc fix).  Perhaps Michael
> can chime in...

Or not?  Somebody has manually blacklisted my MTA, which only sends out
emails from me?

Well I have never!

  michael <at> mauger.com
    host mx.netidentity.com.cust.hostedemail.com [216.40.42.4]
    SMTP error from remote mail server after initial connection:
    554 5.7.1 Service unavailable; Client host [95.216.78.240] blocked using urbl.hostedemail.com; Your IP has been manually blacklisted


-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 07 Sep 2020 11:24:07 GMT) Full text and rfc822 format available.

This bug report was last modified 3 years and 225 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.