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

php-sql-creator problem #66

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
hello,
   I try this:
   $sql= <some SELECT>
   $parser = new PHPSQLParser($sql);
   $creator = new PHPSQLCreator($parser->parsed);

and I verify if $creator->created  appeared to be $sql

example I.: I used: 
$sql = 'SELECT SUM (value)/ABS(2) as x FROM table';

What is the expected output? What do you see instead?

 php-sql-creator thrown the exception:
<b>Fatal error</b>:  Uncaught exception 'UnableToCreateSQLException' with 
message 'unknown expr_type in expression subtree[1] operator' in C:\Program 
Files\wamp\www\inclphp\sql_creator.php:412
Stack trace:
#0 C:\Program Files\wamp\www\inclphp\sql_creator.php(394): 
PHPSQLCreator-&gt;processSubTree(Array, ' ')
#1 C:\Program Files\wamp\www\inclphp\sql_creator.php(117): 
PHPSQLCreator-&gt;processSelectExpression(Array)
#2 C:\Program Files\wamp\www\inclphp\sql_creator.php(70): 
PHPSQLCreator-&gt;processSELECT(Array)
#3 C:\Program Files\wamp\www\inclphp\sql_creator.php(51): 
PHPSQLCreator-&gt;processSelectStatement(Array)
#4 C:\Program Files\wamp\www\inclphp\sql_creator.php(38): 
PHPSQLCreator-&gt;create(Array)
#5 C:\Program Files\wamp\www\inclphp\grid.php(764): 
PHPSQLCreator-&gt;__construct(Array)

What version of the product are you using? On what operating system?

   php-sql-parser-20120703.zip,PHP 5.1.4, Windows XP

Please provide any additional information below:

  I tried to fix it by new row into PHPSQLCreator->processSubTree function:
  ..
            foreach ($parsed['sub_tree'] as $k => $v) {
                $len = strlen($sql);
                $sql .= $this->processFunction($v);
                $sql .= $this->processOperator($v);  //new row
                $sql .= $this->processConstant($v);
                $sql .= $this->processSubQuery($v);
  ..

   then result was "SELECT SUM(value) / ABS(2) as x FROM table". This is OK.

   But this new row may not to be good idea.
   When I used (example II): $sql = 'SELECT SUM (value)/(ABS(2)) as x FROM table'; 

   result was "SELECT SUM(value) / (ABS(2))(2) as x FROM table". This isn't OK. '(2)' is extra substring.
   I don't know, if problem is in creator or in parser.

Thanks
Dominik

Original issue reported on code.google.com by galusdom...@gmail.com on 20 Jul 2012 at 1:39

GoogleCodeExporter commented 8 years ago
This seems to be a problem of the parser, there is no extra representation of 
the outer parenthesis within the parser result array. The base_expr contains 
(ABS(2)), which is wrong, it should be ABS only. But the array should have a 
hint for () too. Hm, let us see, how we can solve that.

Original comment by pho...@gmx.de on 8 Aug 2012 at 7:07

GoogleCodeExporter commented 8 years ago
Checkout REV 300, I have added the new expr_type "bracket_expression". A test 
case for your SQL statement works fine.

Original comment by pho...@gmx.de on 17 Aug 2012 at 12:40

GoogleCodeExporter commented 8 years ago
No response from user.

Original comment by pho...@gmx.de on 20 Aug 2012 at 10:24