PHP-SQL-Parser
PHP-SQL-Parser copied to clipboard
PHPSQLCreator unknown [expr_type] = in-list in "expression subtree"
Found an issue with PHPSQLCreator when using in-list expression in expression's subtree.
$sql="SELECT name,IF(player_type IN ('National','International'), 'Recognized', 'Unrecognized') AS 'Status' from players"; $parser = new PHPSQLParser($sql, true); print_r($parser->parsed); $creator = new PHPSQLCreator($parser->parsed); echo $creator->created;
While Parsing we got the following array for the second column,
Array ( [expr_type] => function [alias] => Array ( [as] => 1 [name] => 'Status' [base_expr] => AS 'Status' [no_quotes] => Array ( [delim] => [parts] => Array ( [0] => Status )
)
[position] => 89
)
[base_expr] => IF
[sub_tree] => Array
(
[0] => Array
(
[expr_type] => expression
[base_expr] => player_type IN ('National','International')
[sub_tree] => Array
(
[0] => Array
(
[expr_type] => colref
[base_expr] => player_type
[no_quotes] => Array
(
[delim] =>
[parts] => Array
(
[0] => player_type
)
)
[sub_tree] =>
[position] => 15
)
[1] => Array
(
[expr_type] => operator
[base_expr] => IN
[sub_tree] =>
[position] => 27
)
[2] => Array
(
[expr_type] => in-list
[base_expr] => ('National','International')
[sub_tree] => Array
(
[0] => Array
(
[expr_type] => const
[base_expr] => 'National'
[sub_tree] =>
[position] => 31
)
[1] => Array
(
[expr_type] => const
[base_expr] => 'International'
[sub_tree] =>
[position] => 42
)
)
[position] => 30
)
)
[alias] =>
[position] => 15
)
PHPSQLCreator throws the following exception while trying to build from this array element,
exception 'PHPSQLParser\exceptions\UnableToCreateSQLException' with message 'unknown [expr_type] = in-list in "expression subtree" [2] '
I got a very similar error - did you follow up on this? Did you find a solution? Thank you!
in SubTreeBuilder.php is missing the protected function buildInList() so add the following method in it
protected function buildInList($parsed) {
$builder = new InListBuilder();
return $builder->build($parsed);
}