Bug #5115 Erronious Syntax Error when comment placed inside of "create table"
Submitted: 19 Aug 2004 20:16 Modified: 20 Aug 2004 11:27
Reporter: Bryce Simonds Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Command-line Clients Severity:S3 (Non-critical)
Version:4.0.20a-nt OS:Windows (Windows NT 4.0 SP6)
Assigned to: Ramil Kalimullin CPU Architecture:Any

[19 Aug 2004 20:16] Bryce Simonds
Description:
When attempting to create a table with a multi line embeded comment, MySQL user client does not correctly handle the multi line comment and reports a syntax error when attempting to automate using a file.  Typing in by hand with comment does not allow statement to be completed, and client must be exited with ^C.

How to repeat:
The following is the table being created:
(Removing the multiline comment will correct the issue)

-- List of US state names and abbreviations.
CREATE TABLE IF NOT EXISTS t_ref_USStates
(
    state_id TINYINT UNSIGNED NOT NULL AUTO_INCREMENT,	-- Unique ID
    name     VARCHAR(32) NOT NULL,			-- State name
    abbr     CHAR(4) NOT NULL,			-- State abbreviation
    type     CHAR(1) NOT NULL DEFAULT 's',		-- See below comment

    /*
     * t_ref_USStates.type tells us what type of state we're dealing with:
     * 's' == Normal US state
     * 'p' == US Provence (e.g. Guam)
     * 'm' == Military state
     */

    PRIMARY KEY (state_id),
    INDEX (abbr)
);

Suggested fix:
A work around is to move the multiline comment outside of the CREATE TABLE definition.

This is more of a cosmetic issue, but comments should be treated as white space in the lexing/parsing stages.
[19 Aug 2004 20:22] Bryce Simonds
Alternatively the comment can be converted to multiple end of line comments and this will also correct the issue.
[19 Aug 2004 21:52] MySQL Verification Team
Hi,

c:\mysql\bin>mysql -uroot test
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4 to server version: 4.0.20a-debug

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> -- List of US state names and abbreviations.
mysql> CREATE TABLE IF NOT EXISTS t_ref_USStates
    -> (
    ->     state_id TINYINT UNSIGNED NOT NULL AUTO_INCREMENT,   -- Unique ID
    ->     name     VARCHAR(32) NOT NULL,                       -- State name
    ->     abbr     CHAR(4) NOT NULL,                   -- State abbreviation
    ->     type     CHAR(1) NOT NULL DEFAULT 's',               -- See below comment
    ->
    ->     /*
    ->      * t_ref_USStates.type tells us what type of state we are dealing with:
    ->      * 's' == Normal US state
    ->      * 'p' == US Provence (e.g. Guam)
    ->      * 'm' == Military state
    ->      */
    ->
    ->     PRIMARY KEY (state_id),
    ->     INDEX (abbr)
    -> );
Query OK, 0 rows affected (0.11 sec)

The issue here is the <we're> part then the client expects the another closing ' 
symbol. I changed for <we are> for to work. So the bug is that inside a
multi line comment all the comments symbols should be ignored.
[20 Aug 2004 11:27] Ramil Kalimullin
Thank you for your bug report. This issue has been committed to our
source repository of that product and will be incorporated into the
next release.

If necessary, you can access the source repository and build the latest
available version, including the bugfix, yourself. More information 
about accessing the source trees is available at
    http://www.mysql.com/doc/en/Installing_source_tree.html