greenlion / PHP-SQL-Parser

A pure PHP SQL (non validating) parser w/ focus on MySQL dialect of SQL
BSD 3-Clause "New" or "Revised" License
604 stars 156 forks source link

Missing data type aliases #355

Closed xsist10 closed 2 years ago

xsist10 commented 2 years ago

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 commented 2 years ago

Working on a MR to fix this.