sanjosh / php-sql-parser

Automatically exported from code.google.com/p/php-sql-parser
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Support for expressions in ORDER BY clause #141

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
This works fine:
SELECT f FROM t ORDER BY f-0.0

But this fails on create:
SELECT f FROM t ORDER BY (f-0.0)

This isn't a problem for me since the first statement works fine, just 
something I noticed.

To reproduce, I wrote this script:

require_once "src/PHPSQLParser/PHPSQLParser.php";
require_once "src/PHPSQLParser/PHPSQLCreator.php";
$parser = new PHPSQLParser\PHPSQLParser();
$creator = new PHPSQLParser\PHPSQLCreator();
$x = $parser->parse("SELECT f FROM t ORDER BY (f-0.0)");
var_dump($creator->create($x));

Stack trace:
PHP Fatal error:  Uncaught exception 
'PHPSQLParser\exceptions\UnableToCreateSQLException' with message 'unknown 
[expr_type] = bracket_expression in "ORDER" [0] ' in 
/home/george/Projects/git/PHP-SQL-Parser/src/PHPSQLParser/builders/OrderByBuilde
r.php:100
Stack trace:
#0 
/home/george/Projects/git/PHP-SQL-Parser/src/PHPSQLParser/builders/SelectStateme
ntBuilder.php(89): PHPSQLParser\builders\OrderByBuilder->build(Array)
#1 
/home/george/Projects/git/PHP-SQL-Parser/src/PHPSQLParser/builders/SelectStateme
ntBuilder.php(115): 
PHPSQLParser\builders\SelectStatementBuilder->buildORDER(Array)
#2 
/home/george/Projects/git/PHP-SQL-Parser/src/PHPSQLParser/PHPSQLCreator.php(90):
 PHPSQLParser\builders\SelectStatementBuilder->build(Array)
#3 /home/george/Projects/git/PHP-SQL-Parser/test.php(7): 
PHPSQLParser\PHPSQLCreator->create(Array)
#4 {main}
  thrown in /home/george/Projects/git/PHP-SQL-Parser/src/PHPSQLParser/builders/OrderByBuilder.php on line 100

This is testing against the master branch of the git repository

Original issue reported on code.google.com by noisecap...@gmail.com on 22 May 2014 at 3:52

GoogleCodeExporter commented 8 years ago
I have added some code in r1359 to handle that.

Original comment by pho...@gmx.de on 23 May 2014 at 1:25