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

Tab character causes a wrong parsing. #21

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Here an example query :
SELECT  SUM( 10 ) FROM account

There is a tab character before the SUM function. I've a class which use 
php-sql-parser to perform internal extra validation.

The example query causes my parser to fail.

But with this query where I've replaced tab character by a space :
SELECT  SUM( 10 ) FROM account
My parser doesn't fail.

Parser result with tab character :
    [SELECT] => Array
        (
            [0] => Array
                (
                    [expr_type] => expression
                    [alias] => `SUM( 10   as test`
                    [base_expr] => SUM( 10   as test
                    [sub_tree] => Array
                        (
                            [0] => Array
                                (
                                    [expr_type] => aggregate_function
                                    [base_expr] => SUM
                                    [sub_tree] => 
                                )

                            [1] => Array
                                (
                                    [expr_type] => colref
                                    [base_expr] => ( 10   as test
                                    [sub_tree] => 
                                )

                        )

                )

        )

Parser result with space character :
    [SELECT] => Array
        (
            [0] => Array
                (
                    [expr_type] => expression
                    [alias] => `test`
                    [base_expr] => SUM( 10 ) 
                    [sub_tree] => Array
                        (
                            [0] => Array
                                (
                                    [expr_type] => aggregate_function
                                    [base_expr] => SUM
                                    [sub_tree] => 
                                )

                            [1] => Array
                                (
                                    [expr_type] => const
                                    [base_expr] => ( 10 )
                                    [sub_tree] => 
                                )

                        )

                )

        )

Should this bug be fixed onto php-sql-parser or my own class ?

The fix would be to do a : str_replace("\t", ' ', $query);

Original issue reported on code.google.com by johnny.c...@gmail.com on 23 Jan 2012 at 11:07

GoogleCodeExporter commented 8 years ago
Solved in current version on http://www.phosco.info/php-sql-parser_current.zip

Original comment by pho...@gmx.de on 31 Jan 2012 at 10:21

GoogleCodeExporter commented 8 years ago
I confirm that code provided by "pho...@gmx.de" fixed my issue.

Original comment by johnny.c...@gmail.com on 7 Mar 2012 at 2:41

GoogleCodeExporter commented 8 years ago
Accepted fixed codebase.

Original comment by greenlion@gmail.com on 12 Mar 2012 at 10:53