sql-parser
sql-parser copied to clipboard
Unable to parse table name
See: https://github.com/phpmyadmin/phpmyadmin/issues/16837
create table event(
eventID varchar(10) not null,
b char(30),
c varchar(20),
d TIME,
e Date,
f int,
g char(70),
h char(90),
primary key(eventID)
)
is the table is named event2 that will work
I'm afraid of that this issue couldn't be easily fixed, because the event keyword is a reserved keyword, the bug will also occur whenever we're creating a table, index or anything with a name identical to any of the options with number 6.
https://github.com/phpmyadmin/sql-parser/blob/eab0f935132c27447731a92fde496d5fa48ee4bf/src/Statements/CreateStatement.php#L55-L70
and it would be hard to fixed because of https://github.com/phpmyadmin/sql-parser/blob/eab0f935132c27447731a92fde496d5fa48ee4bf/src/Components/OptionsArray.php#L148-L160
that's why it will always throw a conflict error, these are my findings, I couldn't think of a not-breaking fix for this.
Thank you for the debug, maybe we can keep this one open for now
@williamdes / @iifawzi
I made some tests and some of the options are allowed while some others are not, and I can't really find any clear rule about how to distinguish them.
CREATE TABLE DATABASE(ID INT(11)); -- Refused by MySQL
CREATE TABLE EVENT(ID INT(11)); -- OK by MySQL
CREATE TABLE FUNCTION(ID INT(11)); -- OK by MySQL
CREATE TABLE INDEX(ID INT(11)); -- Refused by MySQL
CREATE TABLE UNIQUE INDEX(ID INT(11)); -- Refused by MySQL
CREATE TABLE FULLTEXT INDEX(ID INT(11)); -- Refused by MySQL
CREATE TABLE SPATIAL INDEX(ID INT(11)); -- Refused by MySQL
CREATE TABLE PROCEDURE(ID INT(11)); -- Refused by MySQL
CREATE TABLE SERVER(ID INT(11)); -- OK by MySQL
CREATE TABLE TABLE(ID INT(11)); -- Refused by MySQL
CREATE TABLE TABLESPACE(ID INT(11)); -- OK by MySQL
CREATE TABLE TRIGGER(ID INT(11)); -- Refused by MySQL
CREATE TABLE USER(ID INT(11)); -- OK by MySQL
CREATE TABLE VIEW(ID INT(11)); -- OK by MySQL
CREATE TABLE SCHEMA(ID INT(11)); -- Refused by MySQL
Would it be ok to create a whitelist of the allowed options and to not trigger an error if such whitelist exists + the option is part of it?
I am not really sure we should do that in this project, but maybe if it integrates well with the existing code base?
I don't know if I would be available to give it a try on a PR soon. I was just trying to find a workaround as even @iifawzi seemed to have no solution about it. If this solution is too hacky, then we need to find another one.
It's been two years, the project has evolved a lot, my knowledge in the project evolved too. So, my conclusion above might be totally outdated.