Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request addresses an issue within the
CreateTableParser
in php-mysql-engine where encountering aFOREIGN KEY
constraint in aCREATE 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 aFOREIGN KEY
constraint is encountered (potentially after aCONSTRAINT
keyword), the parser incorrectly attempts to interpretFOREIGN KEY
as the start of a column definition. This subsequently leads to aVimeo\MysqlEngine\Parser\ParserException: Unsupported field type: (
when the parser encounters the opening parenthesis(
that typically follows theFOREIGN KEY
keyword.Changes:
case 'FOREIGN KEY':
has been added to theswitch
statement within theparseFieldOrKey
method inCreateTableParser.php
.return;
, instructing the parser to stop processing the current definition line upon encountering theFOREIGN KEY
keyword.Effect:
This change prevents the parser from attempting to parse the
FOREIGN KEY
constraint as a column definition, thus avoiding theUnsupported field type: (
error.CREATE TABLE
statements containingFOREIGN 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 theFOREIGN KEY
definition itself. Full support for parsing and potentially utilizing foreign key constraint information remains a potential area for future improvement.