Skip to content
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

Missing data type aliases #355

Closed
xsist10 opened this issue May 13, 2022 · 1 comment
Closed

Missing data type aliases #355

xsist10 opened this issue May 13, 2022 · 1 comment

Comments

@xsist10
Copy link
Contributor

xsist10 commented May 13, 2022

MySQL has a lot of badly documented aliases for data types.

Example:

  CREATE TABLE `test_alias` (
      `a` INTEGER,
      `b` CHARACTER(10),
      `c` VARCHARACTER(10),
      `d` INT2,
      `e` INT3,
      `f` INT4,
      `g` INT8,
      `h` FLOAT4,
      `i` FLOAT8,
      `j` MIDDLEINT
  );
  
  SHOW CREATE TABLE test_alias \G
  *************************** 1. row ***************************
         Table: test
  Create Table: CREATE TABLE `test_alias` (
    `a` int DEFAULT NULL,
    `b` char(10) DEFAULT NULL,
    `c` varchar(10) DEFAULT NULL,
    `d` smallint DEFAULT NULL,
    `e` mediumint DEFAULT NULL,
    `f` int DEFAULT NULL,
    `g` bigint DEFAULT NULL,
    `h` float DEFAULT NULL,
    `i` double DEFAULT NULL,
    `j` mediumint DEFAULT NULL
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4

But ColumnDefinitionProcessor.php only supports a subset of them.

Parsing a CREATE TABLE query using one of these aliases results in the specific column being skipped and a warning message:

PHP Notice:  Undefined variable: prevCategory in /vendor/greenlion/php-sql-parser/src/PHPSQLParser/processors/ColumnDefinitionProcessor.php on line 370
@xsist10
Copy link
Contributor Author

xsist10 commented May 13, 2022

Working on a MR to fix this.

@xsist10 xsist10 closed this as completed Aug 11, 2022
xsist10 added a commit to xsist10/PHP-SQL-Parser that referenced this issue Dec 2, 2023
In an attempt to fix the character set issue introduced by me in
greenlion#355

This change separates out the CHARACTER check to do a look ahead
to see if the next keyword is SET and splits the logic appropriately.

An alternative would be to look back at the constructed expression
array ($expr) to see if a ExpressionType::DATA_TYPE has already been
defined.

This is an alternative fix to the fix proposed by
greenlion#366
greenlion pushed a commit that referenced this issue Dec 18, 2023
* Confusion between CHARACTER type and CHARACTER SET

In an attempt to fix the character set issue introduced by me in
#355

This change separates out the CHARACTER check to do a look ahead
to see if the next keyword is SET and splits the logic appropriately.

An alternative would be to look back at the constructed expression
array ($expr) to see if a ExpressionType::DATA_TYPE has already been
defined.

This is an alternative fix to the fix proposed by
#366

* Updated removed PHPUnit expect function.

* Added additional tests for explicit conditions.
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

No branches or pull requests

1 participant