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
601 stars 156 forks source link

Valid query is parsed and re-created as invalid query (SQL function arguments stripped) #351

Open carlomanf opened 2 years ago

carlomanf commented 2 years ago

The below code example attempts to parse a valid SQL query and re-create it. $this->creator and $this->parser are instances of the creator and parser.

Upon the query being re-created, the arguments of the round function are stripped, causing an SQL error.

This is a similar issue to #348 but with a different query.

var_dump(
  $this->creator->create(
    $this->parser->parse(
      "SELECT table_name AS 'name', engine AS 'engine', round( ( data_length / 1024 / 1024 ), 2 ) 'data', round( ( index_length / 1024 / 1024 ), 2 ) 'index' FROM information_schema.TABLES WHERE table_schema = 'mydb' ORDER BY name ASC;"
    )
  )
);
exit;

Tested with v4.4.0