Skip to content

Commit

Permalink
Merge pull request #72 from moufmouf/oracle_aliases
Browse files Browse the repository at this point in the history
Subquery aliases in Oracle don't accept the AS keyword
  • Loading branch information
moufmouf authored Aug 3, 2020
2 parents fda2a02 + 6afd03a commit d4940bd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/SQLParser/Node/SubQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public function toSql(array $parameters, AbstractPlatform $platform, int $indent
}
$sql .= '('.$this->subQuery->toSql($parameters, $platform, $indent, $conditionsMode, $extrapolateParameters).')';
if ($this->alias) {
$sql .= ' AS '.$platform->quoteSingleIdentifier($this->alias);
$sql .= ' '.$platform->quoteSingleIdentifier($this->alias);
}
if ($this->refClause) {
$sql .= ' ON ';
Expand Down
3 changes: 3 additions & 0 deletions tests/Mouf/Database/MagicQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ public function testStandardSelect()

$sql = 'SELECT COUNT(*) FROM (SELECT DISTINCT states.country_id, states.code FROM states)';
$this->assertEquals($sql, self::simplifySql($magicQuery->build($sql)));

$sql = 'SELECT COUNT(*) AS cnt FROM (SELECT id FROM country) subquery';
$this->assertEquals($sql, self::simplifySql($magicQuery->build($sql)));
}

/**
Expand Down

0 comments on commit d4940bd

Please sign in to comment.