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

Doesn't parse DATE_ADD correctly #94

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
When parsing a query with DATE_ADD in it the parser does not parse the second 
parameter correctly. 

eg. SELECT DATE_ADD(NOW(), INTERVAL 1 MONTH) AS next_month

the following is the result of the parse:

[SELECT] => Array
        (
            [0] => Array
                (
                    [expr_type] => function
                    [alias] => Array
                        (
                            [as] => 1
                            [name] => next_month
                            [base_expr] => AS next_month
                        )

                    [base_expr] => DATE_ADD
                    [sub_tree] => Array
                        (
                            [0] => Array
                                (
                                    [expr_type] => function
                                    [base_expr] => NOW
                                    [sub_tree] => 
                                )

                            [1] => Array
                                (
                                    [expr_type] => function
                                    [base_expr] => INTERVAL
                                    [sub_tree] => 
                                )

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

                            [3] => Array
                                (
                                    [expr_type] => function
                                    [base_expr] => MONTH
                                    [sub_tree] => 
                                )

                        )

                )

        )

As you can see the parser has incorrectly split up the second parameter of the 
DATE_ADD function.

Original issue reported on code.google.com by i...@theorganicagency.com on 5 Jul 2013 at 12:19

GoogleCodeExporter commented 8 years ago
Ok, looks like this is sort of fixed in the latest version from SVN. The parser 
now outputs:

Array
(
    [SELECT] => Array
        (
            [0] => Array
                (
                    [expr_type] => function
                    [alias] => Array
                        (
                            [as] => 1
                            [name] => next_month
                            [base_expr] => AS next_month
                        )

                    [base_expr] => DATE_ADD
                    [sub_tree] => Array
                        (
                            [0] => Array
                                (
                                    [expr_type] => function
                                    [base_expr] => NOW
                                    [sub_tree] => 
                                )

                            [1] => Array
                                (
                                    [expr_type] => colref
                                    [base_expr] => INTERVAL
                                    [sub_tree] => 
                                )

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

                            [3] => Array
                                (
                                    [expr_type] => colref
                                    [base_expr] => MONTH
                                    [sub_tree] => 
                                )

                        )

                )

        )
)

however the creator joins the parts back together separated by columns.

Original comment by i...@theorganicagency.com on 5 Jul 2013 at 12:28

GoogleCodeExporter commented 8 years ago
Solved in r382.

Original comment by pho...@gmx.de on 24 Oct 2013 at 10:51