Skip to content

fix: foreign key defined #58

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tamagoage
Copy link

@tamagoage tamagoage commented Apr 28, 2025

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 the switch statement within the parseFieldOrKey method in CreateTableParser.php.
  • This new case simply executes return;, instructing the parser to stop processing the current definition line upon encountering the FOREIGN KEY keyword.

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.

@tamagoage tamagoage force-pushed the tamagoage/skip-foreign-key branch from cb3c426 to 6112306 Compare April 28, 2025 08:07
@tamagoage tamagoage force-pushed the tamagoage/skip-foreign-key branch from 6112306 to 7938ec3 Compare April 28, 2025 08:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant