fix: foreign key defined
This pull request addresses an issue within the CreateTableParser in php-mysql-engine where encountering a FOREIGN KEY constraint in a CREATE TABLE statement causes a parser error. The main change aims to prevent this error by skipping the constraint definition.
Problem:
Currently, the parser lacks specific handling for FOREIGN KEY constraints within its main definition parsing logic (parseFieldOrKey method). When a FOREIGN KEY constraint is encountered (potentially after a CONSTRAINT keyword), the parser incorrectly attempts to interpret FOREIGN KEY as the start of a column definition. This subsequently leads to a Vimeo\MysqlEngine\Parser\ParserException: Unsupported field type: ( when the parser encounters the opening parenthesis ( that typically follows the FOREIGN KEY keyword.
Changes:
- A
case 'FOREIGN KEY':has been added to theswitchstatement within theparseFieldOrKeymethod inCreateTableParser.php. - This new case simply executes
return;, instructing the parser to stop processing the current definition line upon encountering theFOREIGN KEYkeyword.
Effect:
This change prevents the parser from attempting to parse the FOREIGN KEY constraint as a column definition, thus avoiding the Unsupported field type: ( error. CREATE TABLE statements containing FOREIGN KEY constraints can now be processed by the parser without halting due to this specific error.
Note / Limitation:
It is important to note that this change only skips the parsing of the FOREIGN KEY constraint to avoid the immediate error. It does not implement any logic to actually parse, store, or validate the details of the foreign key constraint (referenced table, columns, actions, etc.). The parser effectively ignores the FOREIGN KEY definition itself. Full support for parsing and potentially utilizing foreign key constraint information remains a potential area for future improvement.