mnpenner / 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

IFNULL(<Column Name>,<Value>) doesn't parsed properly #149

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Add query with where clause "where ifnull(col_name,'') <> '' "
2. This treat "," as expression separator and hence remove it from final list.

What is the expected output? What do you see instead?
"," should be part of subtree list as "operator" not "separator"

What version of the product are you using? On what operating system?
php-sql-parser-20140108.zip on Centos 6.5

Please provide any additional information below.
   'subTree' =>
  array (
    0 =>
    array (
      'expr_type' => 'expression',
      'base_expr' => 'COL_NAME , \\'NULL\\'',
      'sub_tree' =>
      array (
        0 =>
        array (
          'expr_type' => 'colref',
          'base_expr' => 'COL_NAME',
          'no_quotes' => 'COL_NAME',
          'sub_tree' => false,
        ),
        1 =>
        array (
          'expr_type' => 'const',
          'base_expr' => '\\'NULL\\'',
          'sub_tree' => false,
        ),
      ),
      'alias' => false,
    ),
  ),
   'expression' => '',
   'key' => 1,
   'token' => 'IFNULL',
   'tokenType' => 'function',
   'trim' => 'IFNULL',
   'upper' => 'IFNULL',
   'noQuotes' => NULL,
))

Original issue reported on code.google.com by rrmal...@gmail.com on 10 Sep 2014 at 7:28

GoogleCodeExporter commented 9 years ago
Please use the current version of the parser (see 
http://code.google.com/p/php-sql-parser/wiki/Downloads). The parameters of a 
function are always separated by comma, so the builder will recreate the 
statement correctly.

Here is the output of the current version:

[WHERE] => Array
        (
            [0] => Array
                (
                    [expr_type] => function
                    [base_expr] => ifnull
                    [sub_tree] => Array
                        (
                            [0] => Array
                                (
                                    [expr_type] => colref
                                    [base_expr] => col_name
                                    [no_quotes] => Array
                                        (
                                            [delim] => 
                                            [parts] => Array
                                                (
                                                    [0] => col_name
                                                )

                                        )

                                    [sub_tree] => 
                                )

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

                        )

                )

            [1] => Array
                (
                    [expr_type] => operator
                    [base_expr] => <>
                    [sub_tree] => 
                )

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

        )

As you can see, the function has a subtree with two elements, which are 
separated by comma implicitly.

Original comment by pho...@gmx.de on 11 Sep 2014 at 6:54