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
609 stars 159 forks source link

Missing comma in cast #294

Open nicoder opened 6 years ago

nicoder commented 6 years ago

hi,

If I parse a SQL query containing CAST (foo AS DECIMAL(16, 2)), and then create a query with the creator, it loses the comma in DECIMAL(16, 2)

test code :

<?php

namespace PHPSQLParser;

require_once dirname(__FILE__) . '/vendor/autoload.php';

$sql = 'SELECT CAST(a AS DECIMAL(16, 2)) AS f';
echo PHP_EOL . $sql;
$parser = new PHPSQLParser($sql, true);
$creator = new PHPSQLCreator($parser->parsed);
echo PHP_EOL . $creator->created;

output:

SELECT CAST(a AS DECIMAL(16, 2)) AS f
SELECT CAST(a AS DECIMAL (16 2)) AS f

I have tried to change the code to add a delim to fix this problem, but I am not sure at all it is the right way to go about this. I will open a pull request to show what I tried and would appreciate if someone who knows the codebase could have a look.

thanks!

nicoder commented 6 years ago

here is the pull request: https://github.com/greenlion/PHP-SQL-Parser/pull/295