Skip to content
Open
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
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."'");
}
}
}