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

Parsing insert queries with functions trims commas #450

Closed
gachowy opened this issue May 31, 2023 · 6 comments
Closed

Parsing insert queries with functions trims commas #450

gachowy opened this issue May 31, 2023 · 6 comments
Assignees
Labels
Milestone

Comments

@gachowy
Copy link

gachowy commented May 31, 2023

Hello,

I discovered that there could be something wrong with parsing commas in MySQL functions like concat or replace.

When I'm trying to parse, and fetch values, or rebuild INSERT queries, which contains some concat, or replace, it 'eats' all commas, which makes output queries as invalid.

Sample parsed queries:

INSERT INTO `some_table` VALUES (replace('something_camel_case','_', ''));
INSERT INTO `some_table` VALUES (concat('value1', 'value2', 'value3'));

Output queries:

INSERT INTO `some_table` VALUES (replace('something_camel_case''_' ''));
INSERT INTO `some_table` VALUES (concat('value1' 'value2' 'value3'));

Version: 5.7.0
PHP: 8.2.6

Code example:

<?php

use PhpMyAdmin\SqlParser\Parser;
use PhpMyAdmin\SqlParser\Statements\InsertStatement;

require_once __DIR__ . '/vendor/autoload.php';

$inputQueries = "
INSERT INTO `some_table` VALUES (replace('something_camel_case','_', ''));
INSERT INTO `some_table` VALUES (concat('value1', 'value2', 'value3'));
";

$parser = new Parser($inputQueries);

foreach ($parser->statements as $statement) {
    if ($statement instanceof InsertStatement) {
        var_dump($statement->values[0]->raw[0]);
    }
    var_dump($statement->build());
}
@williamdes
Copy link
Member

Is 5.8.0 (aka 5.8.x branch) also affected?
Please about #452 and other ones, if possible send them to the QA branch: 5.latest.x
I will do it for #452 in order to have the phpdoc fixed in 5.8

@gachowy
Copy link
Author

gachowy commented Jun 1, 2023

@williamdes seems like newer/dev versions also affected - still the same issue :)

@williamdes williamdes added this to the 5.8.0 milestone Jun 1, 2023
@williamdes
Copy link
Member

Okay, let's try to fix it before #449
Are you using sql-parser for a project ?

@Tithugues
Copy link
Contributor

Here is a proposal for a fix: #474

@williamdes
Copy link
Member

Hi @gachowy
Can you confirm 5.8 fixes the issue for you?

@gachowy
Copy link
Author

gachowy commented Jun 12, 2023

Hello, @williamdes - it seems fixed in 5.8.
Thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants