Skip to content

reference to function expression in count #15

@staabm

Description

@staabm

I am running the query 'SELECT count(email) from ada' thru this code:

        $queryString = 'SELECT count(email) from ada';

        $platform = Platform::get(Platform::MYSQL, '8.0'); // version defaults to x.x.99 when no patch number is given
        $session = new Session($platform);
        $parser = new Parser($session);

        // returns a Generator. will not parse anything if you don't iterate over it
        $commands = $parser->parse($queryString);
        foreach ($commands as [$command, $tokenList, $start, $end]) {
            // Parser does not throw exceptions. this allows to parse partially invalid code and not fail on first error
            if ($command instanceof SelectCommand) {
                $columns = $command->getColumns();
                foreach($columns as $i => $column) {
                    $expression = $column->getExpression();
                    if ($expression instanceof FunctionCall && $expression->getFunction()->getName() == BuiltInFunction::COUNT ) {
                        // $expression->
                    }
                }
            }
        }

which when hold with the debugger at // $expression gives me this $command:

grafik

from the command I have at hand, I can easily find the SimpleName of the table involved, and also the name of the arg passed to count. what I am missing is way to retrieve the raw count(email) expression, so I can combine the parser results with results of other tooling involved.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions