Skip to content

Commit

Permalink
Merge pull request #15 from derflocki/fix-select-order-by-columns
Browse files Browse the repository at this point in the history
added driverName == 'oci8' for properly detecting oracle DB in getLimitSubquery
  • Loading branch information
j0k3r committed Mar 24, 2016
2 parents eae2efc + de9f656 commit fab61b2
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/Doctrine/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -1409,15 +1409,15 @@ public function getLimitSubquery()
$driverName = $this->_conn->getAttribute(Doctrine_Core::ATTR_DRIVER_NAME);

// initialize the base of the subquery
if (($driverName == 'oracle' || $driverName == 'oci') && $this->_isOrderedByJoinedColumn()) {
if (($driverName == 'oracle' || $driverName == 'oci' || $driverName == 'oci8') && $this->_isOrderedByJoinedColumn()) {
$subquery = 'SELECT ';
} else {
$subquery = 'SELECT DISTINCT ';
}
$subquery .= $this->_conn->quoteIdentifier($primaryKey);

// pgsql & oracle need the order by fields to be preserved in select clause
if ($driverName == 'pgsql' || $driverName == 'oracle' || $driverName == 'oci' || $driverName == 'mssql' || $driverName == 'odbc') {
if ($driverName == 'pgsql' || $driverName == 'oracle' || $driverName == 'oci' || $driverName == 'oci8' || $driverName == 'mssql' || $driverName == 'odbc') {
foreach ($this->_sqlParts['orderby'] as $part) {
// Remove identifier quoting if it exists
$e = $this->_tokenizer->bracketExplode($part, ' ');
Expand Down Expand Up @@ -1500,7 +1500,7 @@ public function getLimitSubquery()
$subquery .= ( ! empty($having))? ' HAVING ' . implode(' AND ', $having) : '';
$subquery .= ( ! empty($orderby))? ' ORDER BY ' . implode(', ', $orderby) : '';

if (($driverName == 'oracle' || $driverName == 'oci') && $this->_isOrderedByJoinedColumn()) {
if (($driverName == 'oracle' || $driverName == 'oci' || $driverName == 'oci8') && $this->_isOrderedByJoinedColumn()) {
// When using "ORDER BY x.foo" where x.foo is a column of a joined table,
// we may get duplicate primary keys because all columns in ORDER BY must appear
// in the SELECT list when using DISTINCT. Hence we need to filter out the
Expand Down

0 comments on commit fab61b2

Please sign in to comment.