dbsrgits / sql-translator

SQL::Translator (SQLFairy)
http://sqlfairy.sourceforge.net/
82 stars 90 forks source link

SQL::Translator::Parser::MySQL doesn't accept 'character set' after 'create database' #101

Open borisdaeppen opened 6 years ago

borisdaeppen commented 6 years ago

This statement:

sqlt-graph -f MySQL -o fail.png -t png fail.sql

produces the following error:

       ERROR (line 3): Invalid statement: Was expecting comment, or use, or
                       set, or drop, or create, or alter, or insert, or
                       delimiter, or empty statement
Error: translate: Error with parser 'SQL::Translator::Parser::MySQL':  no results at ~/perl5/perlbrew/perls/perl-5.22.4/bin/sqlt-graph line 195.

The following SQL was used to produce the error:

SET NAMES 'utf8';
CREATE DATABASE example CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
USE example;

CREATE TABLE articel (
    id INTEGER NOT NULL AUTO_INCREMENT,
    name VARCHAR(255) NOT NULL
) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

When I remove CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci from the create statement, it parses just fine.

Note: The character set for the table does not produce an error.

According to https://dev.mysql.com/doc/refman/5.7/en/charset-database.html the used syntax for a character set in create should be valid.

borisdaeppen commented 6 years ago

I'll might give it a try and create a patch, if someone with a good amount of background knowledge on MySQL (or somebody from the devs of sqlfairy) can confirm that this is a valid issue.