Skip to content

Commit

Permalink
Build User Varaiable Expression in FunctionBuilder (#340)
Browse files Browse the repository at this point in the history
Implement UserVariableBuilder in FunctionBuilder to build for custom variable.

This changes solve issues of subtree with user_variable expr_type

Solve this error while building parsed query.
Message: unknown [expr_type] = user_variable in "function subtree
  • Loading branch information
Aramics committed Feb 1, 2022
1 parent c20bc35 commit 6737695
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/PHPSQLParser/builders/FunctionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,12 @@ protected function buildSubQuery($parsed) {
$builder = new SubQueryBuilder();
return $builder->build($parsed);
}


protected function buildUserVariableExpression($parsed) {
$builder = new UserVariableBuilder();
return $builder->build($parsed);
}

public function build(array $parsed) {
if (($parsed['expr_type'] !== ExpressionType::AGGREGATE_FUNCTION)
&& ($parsed['expr_type'] !== ExpressionType::SIMPLE_FUNCTION)
Expand All @@ -114,6 +119,7 @@ public function build(array $parsed) {
$sql .= $this->buildReserved($v);
$sql .= $this->buildSelectBracketExpression($v);
$sql .= $this->buildSelectExpression($v);
$sql .= $this->buildUserVariableExpression($v);

if ($len == strlen($sql)) {
throw new UnableToCreateSQLException('function subtree', $k, $v, 'expr_type');
Expand Down

0 comments on commit 6737695

Please sign in to comment.