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 comma in cast #294

Open
nicoder opened this issue Nov 6, 2018 · 1 comment
Open

Missing comma in cast #294

nicoder opened this issue Nov 6, 2018 · 1 comment

Comments

@nicoder
Copy link
Contributor

nicoder commented Nov 6, 2018

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 added a commit to nicoder/PHP-SQL-Parser that referenced this issue Nov 6, 2018
without this change, parsing and then re-creating a SQL query casting a
field as a decimal loses the comma in the decimal

for example `DECIMAL (16,2)` became `DECIMAL (16 2)`

added a `delim` in `ExpressionListProcessor`, when have a comma token,
as is done in `SelectProcessor#process`.

not sure if this is the right way to proceed,
and if it is it might need to be done in other places.
@nicoder
Copy link
Contributor Author

nicoder commented Nov 6, 2018

here is the pull request: #295

greenlion added a commit that referenced this issue Dec 23, 2018
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