rickywu-posh/php-sql-parser

Alias for a function without parameters forgotten

Opened this issue · 0 comments

What steps will reproduce the problem?
1. Create a SQL query containing an aliased function without parameters (for 
example "SELECT NOW() AS today"
2. Parse it
3. Create SQL from parsed query

What is the expected output? What do you see instead?
I expect "SELECT NOW() AS today"
I see "SELECT NOW()"
The alias is forgotten. If my function has parameters (DATEDIFF for example), 
the alias is keeped.

What version of the product are you using? On what operating system?
SVN: $Id: PHPSQLParser.php 757 2013-12-16 09:54:05Z on linux

Please provide any additional information below.
In builders/FunctionBuilder.php, you wrote :
if ($parsed['sub_tree'] === false) {
    return $parsed['base_expr'] . "()";
}

You should have :
if ($parsed['sub_tree'] === false) {
    return $parsed['base_expr'] . "()". $this->buildAlias($parsed) . $this->buildDirection($parsed);;
}

Thanks !

Original issue reported on code.google.com by ludo.zeg...@gmail.com on 12 Dec 2014 at 8:09