Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/Components/JoinKeyword.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class JoinKeyword extends Component
* @var Condition[]
*/
public $on;
public $using;

/**
* @param Parser $parser The parser that serves as context.
Expand All @@ -85,10 +86,12 @@ public static function parse(Parser $parser, TokensList $list, array $options =
*
* 1 -----------------------[ expr ]----------------------> 2
*
* 2 ------------------------[ ON ]-----------------------> 3
* 2 ---------------------[ ON|USING ]--------------------> 3/4
*
* 3 --------------------[ conditions ]-------------------> 0
*
* 4 ----------------------[ columns ]--------------------> 0
*
* @var int $state
*/
$state = 0;
Expand Down Expand Up @@ -131,14 +134,19 @@ public static function parse(Parser $parser, TokensList $list, array $options =
$expr->expr = Expression::parse($parser, $list, array('field' => 'table'));
$state = 2;
} elseif ($state === 2) {
if (($token->type === Token::TYPE_KEYWORD) && ($token->value === 'ON')) {
$state = 3;
if (($token->type === Token::TYPE_KEYWORD) && ($token->value === 'ON' || $token->value === 'USING')) {
$state = $token->value === 'ON' ? 3 : 4;
}
} elseif ($state === 3) {
$expr->on = Condition::parse($parser, $list);
$ret[] = $expr;
$expr = new JoinKeyword();
$state = 0;
} elseif ($state === 4) {
$expr->using = ArrayObj::parse($parser, $list);
$ret[] = $expr;
$expr = new JoinKeyword();
$state = 0;
}

}
Expand Down