PHP-SQL-Parser icon indicating copy to clipboard operation
PHP-SQL-Parser copied to clipboard

Missing comma in cast

Open nicoder opened this issue 6 years ago • 1 comments

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 avatar Nov 06 '18 16:11 nicoder

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

nicoder avatar Nov 06 '18 16:11 nicoder