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

Creator: Fails when logic expression is in select #88

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Attempt to create an SQL string with a source that has
[SELECT] => Array
        (
            [0] => Array
                (
                    [expr_type] => bracket_expression
                    [alias] =>
                    [base_expr] => (some_field = 'string')
                    [sub_tree] => Array
                        (
                            [0] => Array
                                (
                                    [expr_type] => colref
                                    [base_expr] => some_field
                                    [sub_tree] =>
                                    [position] => 8
                                )

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

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

                        )

                    [position] => 7
                )

        )
or any other logic expression.

What is the expected output? What do you see instead?
Expected result is an SQL string.
Actual result is
PHP Fatal error:  Uncaught exception 'UnableToCreateSQLException' with message 
'unknown expr_type in SELECT[0] bracket_expression' in 
projects/PHP-SQL-Parser/php-sql-creator.php:124
Stack trace:
#0 projects/PHP-SQL-Parser/php-sql-creator.php(72): 
PHPSQLCreator->processSELECT(Array)
#1 projects/PHP-SQL-Parser/php-sql-creator.php(53): 
PHPSQLCreator->processSelectStatement(Array)
#2 projects/PHP-SQL-Parser/php-sql-creator.php(40): PHPSQLCreator->create(Array)
#3 projects/PHP-SQL-Parser/example.php(18): PHPSQLCreator->__construct(Array)
#4 {main}
  thrown in projects/PHP-SQL-Parser/php-sql-creator.php on line 124

What version of the product are you using? On what operating system?
php-sql-parser-20120822.zip, Debian

Please provide any additional information below.
Attached file includes example that causes error.

Not using parentheses (select some_field = 'string' from table;) still produces 
an error:
PHP Fatal error:  Uncaught exception 'UnableToCreateSQLException' with message 
'unknown expr_type in expression subtree[0] colref' in 
projects/PHP-SQL-Parser/php-sql-creator.php:452
Stack trace:
#0 projects/PHP-SQL-Parser/php-sql-creator.php(424): 
PHPSQLCreator->processSubTree(Array, ' ')
#1 projects/PHP-SQL-Parser/php-sql-creator.php(119): 
PHPSQLCreator->processSelectExpression(Array)
#2 projects/PHP-SQL-Parser/php-sql-creator.php(72): 
PHPSQLCreator->processSELECT(Array)
#3 projects/PHP-SQL-Parser/php-sql-creator.php(53): 
PHPSQLCreator->processSelectStatement(Array)
#4 projects/PHP-SQL-Parser/php-sql-creator.php(40): PHPSQLCreator->create(Array)
#5 projects/PHP-SQL-Parser/example.php(8): PHPSQLCreator->__construct(Array)
#6 {main}
  thrown in projects/PHP-SQL-Parser/php-sql-creator.php on line 452

Original issue reported on code.google.com by swe...@gmail.com on 16 Jan 2013 at 6:33

Attachments:

GoogleCodeExporter commented 8 years ago
I have added a call to processSelectBracketExpression(), which handles 
bracket_expressions right.

Original comment by pho...@gmx.de on 23 Oct 2013 at 8:23