rickywu-posh / 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

Surround column aliases with backticks #101

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
php > require_once "php-sql-parser.php";
php > require_once "php-sql-creator.php";
php > $parser = new PHPSQLParser();
php > $tree = $parser->parse("SELECT tab.col AS `tab.col`, tab2.col AS 
`tab2.col` FROM tab, tab2");
php > $creator = new PHPSQLCreator();
php > var_dump($creator->create($tree));
string(62) "SELECT tab.col as tab.col,tab2.col as tab2.col FROM tab , tab2"

Ideally columns which were aliased going in would be aliased going out as well. 
Otherwise MySQL returns a data set whose column names are all 'col'. For my use 
case I'm just adding backticks around all column aliases in processAlias in 
php-sql-creator.php; not sure if that would lead to any problems down the road.

Original issue reported on code.google.com by noisecap...@gmail.com on 20 Nov 2013 at 9:35

GoogleCodeExporter commented 8 years ago
I try to split that within the parser. Every table, colref or alias should have 
a no_quotes property now, which contains the name without quotes. It doesn't 
work in all cases, I have to change this a little bit (i.e. `foo`.`bar` gives 
foo`.`bar). I'll create a test case and see, what is wrong.

Original comment by pho...@gmx.de on 21 Nov 2013 at 10:41

GoogleCodeExporter commented 8 years ago
The parser returns already the quoted column-reference since r433. It has not 
been included into the last download, try the bleeding edge on the SVN/trunc 
path (r566). 

Original comment by pho...@gmx.de on 21 Nov 2013 at 11:11

GoogleCodeExporter commented 8 years ago
Thanks! I wanted to say that this has been very useful for my work and I 
appreciate the effort put into this. I use it to automatically filter, sort and 
paginate our SQL queries, and so far it works great!

Original comment by noisecap...@gmail.com on 21 Nov 2013 at 3:25

GoogleCodeExporter commented 8 years ago
:-) Thank you for using the parser!!

Original comment by pho...@gmx.de on 22 Nov 2013 at 12:20