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

ORDER clause expressions are not parsed #61

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
If I parse query like this: 

SELECT lcase(dummy.b) FROM dummy ORDER BY dummy.a, LCASE(dummy.b)

in SELECT I get this:

  ["SELECT"]=>
  array(1) {
    [0]=>
    array(4) {
      ["expr_type"]=>
      string(8) "function"
      ["alias"]=>
      bool(false)
      ["base_expr"]=>
      string(5) "lcase"
      ["sub_tree"]=>
      array(1) {
        [0]=>
        array(3) {
          ["expr_type"]=>
          string(6) "colref"
          ["base_expr"]=>
          string(7) "dummy.b"
          ["sub_tree"]=>
          bool(false)
        }
      }
    }
  }

but in ORDER BY I get only this:

  ["ORDER"]=>
  array(2) {
    [0]=>
    array(3) {
      ["type"]=>
      string(10) "expression"
      ["base_expr"]=>
      string(7) "dummy.a"
      ["direction"]=>
      string(3) "ASC"
    }
    [1]=>
    array(3) {
      ["type"]=>
      string(10) "expression"
      ["base_expr"]=>
      string(14) "LCASE(dummy.b)"
      ["direction"]=>
      string(3) "ASC"
    }
  }

 i.e. ORDER components are not parsed, functions not identified, and it's hard to tell what's going on there. Older versions of the parser produced this:

  ["ORDER"]=>
  array(2) {
    [0]=>
    array(4) {
      ["type"]=>
      string(10) "expression"
      ["base_expr"]=>
      string(7) "dummy.a"
      ["direction"]=>
      string(3) "ASC"
      ["sub_tree"]=>
      array(1) {
        [0]=>
        array(4) {
          ["expr_type"]=>
          string(6) "colref"
          ["alias"]=>
          string(9) "`dummy.a`"
          ["base_expr"]=>
          string(7) "dummy.a"
          ["sub_tree"]=>
          bool(false)
        }
      }
    }
    [1]=>
    array(4) {
      ["type"]=>
      string(10) "expression"
      ["base_expr"]=>
      string(14) "LCASE(dummy.b)"
      ["direction"]=>
      string(3) "ASC"
      ["sub_tree"]=>
      array(1) {
        [0]=>
        array(4) {
          ["expr_type"]=>
          string(10) "expression"
          ["alias"]=>
          string(16) "`LCASE(dummy.b)`"
          ["base_expr"]=>
          string(14) "LCASE(dummy.b)"
          ["sub_tree"]=>
          array(2) {
            [0]=>
            array(3) {
              ["expr_type"]=>
              string(8) "function"
              ["base_expr"]=>
              string(5) "LCASE"
              ["sub_tree"]=>
              bool(false)
            }
            [1]=>
            array(3) {
              ["expr_type"]=>
              string(10) "expression"
              ["base_expr"]=>
              string(9) "(dummy.b)"
              ["sub_tree"]=>
              array(1) {
                [0]=>
                array(3) {
                  ["expr_type"]=>
                  string(6) "colref"
                  ["base_expr"]=>
                  string(7) "dummy.b"
                  ["sub_tree"]=>
                  bool(false)
                }
              }
            }
          }
        }
      }
    }

which is much more useful. Can it be brought back?

Original issue reported on code.google.com by smalys...@gmail.com on 13 Jun 2012 at 1:07

GoogleCodeExporter commented 9 years ago
I have fixed your problem, see REV 287.

Original comment by pho...@gmx.de on 14 Jun 2012 at 7:03