Bug #121967 SHOW CREATE LIBRARY emits non-replayable dollar-quoted syntax

Submitted: 28 Nov 10:02
Reporter: QiFan Liu Email Updates:
Status: Open Impact on me:
None 
Category:MySQL Server: Stored Routines Severity:S3 (Non-critical)
Version:9.7.2 OS:Linux
Assigned to: CPU Architecture:x86
Tags: dollar quoting, javascript, SHOW CREATE LIBRARY

[28 Nov 10:02] QiFan Liu
Description:
SHOW CREATE LIBRARY can emit invalid CREATE syntax when the library body ends in '$'.

For the body '// $', SHOW CREATE LIBRARY emits:

CREATE LIBRARY `lib1`
    LANGUAGE JAVASCRIPT
AS $$// $$$

Replaying this definition fails because the first two trailing dollar signs close the dollar-quoted body, leaving a stray '$':

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '$' at line 3

SHOW CREATE output for an accepted library should be valid CREATE syntax and recreate the same body. A control body ending in 'x' is emitted as AS $$// x$$ and replays successfully.

How to repeat:
CREATE DATABASE db1;
USE db1;

CREATE LIBRARY lib1 LANGUAGE JAVASCRIPT AS '// $';
SHOW CREATE LIBRARY lib1;
-- Emits: AS $$// $$$

DROP LIBRARY lib1;

CREATE LIBRARY `lib1`
    LANGUAGE JAVASCRIPT
AS $$// $$$;
-- Fails with ERROR 1064 (42000) near '$' at line 3

-- Control:
CREATE LIBRARY lib2 LANGUAGE JAVASCRIPT AS '// x';
SHOW CREATE LIBRARY lib2;
-- Emits: AS $$// x$$

DROP LIBRARY lib2;

CREATE LIBRARY `lib2`
    LANGUAGE JAVASCRIPT
AS $$// x$$;
-- Succeeds

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.037 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.