Skip to content

Commit

Permalink
Fix join with a subquery
Browse files Browse the repository at this point in the history
  • Loading branch information
rodion-k committed Feb 1, 2022
1 parent 7efa677 commit 45ce309
Showing 1 changed file with 26 additions and 33 deletions.
59 changes: 26 additions & 33 deletions src/SQLParser/Node/NodeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,38 +150,7 @@ public static function toObject(array $desc)
$expr->setTable($desc['table']);
}



$expr->setTable(str_replace('`', '', $desc['table']));
switch ($desc['join_type']) {
case 'CROSS':
$joinType = 'CROSS JOIN';
break;
case 'JOIN':
$joinType = 'JOIN';
break;
case 'LEFT':
$joinType = 'LEFT JOIN';
break;
case 'RIGHT':
$joinType = 'RIGHT JOIN';
break;
case 'INNER':
$joinType = 'INNER JOIN';
break;
case 'OUTER':
$joinType = 'OUTER JOIN';
break;
case 'NATURAL':
$joinType = 'NATURAL JOIN';
break;
case ',':
$joinType = ',';
break;
default:
throw new \Exception("Unexpected join type: '".$desc['join_type']."'");
}
$expr->setJoinType($joinType);
$expr->setJoinType(self::mapJoinType($desc['join_type']));

if (isset($desc['alias']['name'])) {
$expr->setAlias($desc['alias']['name']);
Expand Down Expand Up @@ -222,7 +191,7 @@ public static function toObject(array $desc)
$expr->setSubQuery(self::buildFromSubtree($desc['sub_tree']));

if (isset($desc['join_type'])) {
$expr->setJoinType($desc['join_type']);
$expr->setJoinType(self::mapJoinType($desc['join_type']));
}

if (isset($desc['alias']['name'])) {
Expand Down Expand Up @@ -908,4 +877,28 @@ public static function toSql($nodes, AbstractPlatform $platform, array $paramete

return $sql;
}

private static function mapJoinType(string $originalJoinType): string
{
switch ($originalJoinType) {
case 'CROSS':
return 'CROSS JOIN';
case 'JOIN':
return 'JOIN';
case 'LEFT':
return 'LEFT JOIN';
case 'RIGHT':
return 'RIGHT JOIN';
case 'INNER':
return 'INNER JOIN';
case 'OUTER':
return 'OUTER JOIN';
case 'NATURAL':
return 'NATURAL JOIN';
case ',':
return ',';
default:
throw new \Exception("Unexpected join type: '".$originalJoinType."'");
}
}
}

0 comments on commit 45ce309

Please sign in to comment.