Commit 501e8e91 authored by zYne's avatar zYne

--no commit message

--no commit message
parent e1979612
...@@ -858,40 +858,29 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable ...@@ -858,40 +858,29 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
$driverName = $this->_conn->getAttribute(Doctrine::ATTR_DRIVER_NAME); $driverName = $this->_conn->getAttribute(Doctrine::ATTR_DRIVER_NAME);
// pgsql needs the order by fields to be preserved in select clause
/** if ($driverName == 'pgsql') {
foreach ($this->parts['orderby'] as $part) { foreach ($this->parts['orderby'] as $part) {
$part = trim($part); $part = trim($part);
$e = Doctrine_Tokenizer::bracketExplode($part, ' '); $e = Doctrine_Tokenizer::bracketExplode($part, ' ');
$part = trim($e[0]); $part = trim($e[0]);
$aggregate = false; if (strpos($part, '.') === false) {
continue;
foreach ($this->parts['select'] as $select) {
$e = explode(' AS ', trim($select));
if (count($e) > 1) {
if ($part === $e[1]) {
$part = $select;
$aggregate = true;
break;
}
} }
}
// don't add functions
// don't add primarykey column (its already in the select clause) if (strpos($part, '(') !== false) {
if ($part !== $primaryKey) { continue;
if ($driverName == 'mysql') { }
if ($aggregate) {
$subquery .= ', ' . $part; // don't add primarykey column (its already in the select clause)
} if ($part !== $primaryKey) {
} elseif ($driverName == 'pgsql') {
// pgsql needs the order by fields to be preserved in select clause
$subquery .= ', ' . $part; $subquery .= ', ' . $part;
} }
} }
} }
*/
if ($driverName == 'mysql' || $driverName == 'pgsql') { if ($driverName == 'mysql' || $driverName == 'pgsql') {
foreach ($this->_expressionMap as $dqlAlias => $expr) { foreach ($this->_expressionMap as $dqlAlias => $expr) {
if (isset($expr[1])) { if (isset($expr[1])) {
...@@ -933,13 +922,13 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable ...@@ -933,13 +922,13 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
if (strpos($part, "'") !== false) { if (strpos($part, "'") !== false) {
continue; continue;
} }
if ($this->hasTableAlias($part)) { if ($this->hasTableAlias($part)) {
$parts[$k] = $this->generateNewTableAlias($part); $parts[$k] = $this->generateNewTableAlias($part);
continue; continue;
} }
if (strpos($part, '.') == false) { if (strpos($part, '.') === false) {
continue; continue;
} }
preg_match_all("/[a-zA-Z0-9_]+\.[a-z0-9_]+/i", $part, $m); preg_match_all("/[a-zA-Z0-9_]+\.[a-z0-9_]+/i", $part, $m);
...@@ -971,29 +960,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable ...@@ -971,29 +960,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
} }
} }
} }
/**
$separator = false;
if (strpos($part, '.') !== false) {
$separator = '.';
}
if ($driverName == 'mysql' || $driverName == 'pgsql') {
if (strpos($part, '__') !== false) {
$separator = '__';
}
}
if ($separator) {
$e = explode($separator, $part);
$trimmed = ltrim($e[0], '( ');
$pos = strpos($e[0], $trimmed);
$e[0] = substr($e[0], 0, $pos) . $this->generateNewTableAlias($trimmed);
$parts[$k] = implode($separator, $e);
}*/
$subquery = implode(' ', $parts); $subquery = implode(' ', $parts);
return $subquery; return $subquery;
......
...@@ -37,7 +37,7 @@ class Doctrine_Query_PgsqlSubquery_TestCase extends Doctrine_UnitTestCase ...@@ -37,7 +37,7 @@ class Doctrine_Query_PgsqlSubquery_TestCase extends Doctrine_UnitTestCase
$this->dbh = new Doctrine_Adapter_Mock('pgsql'); $this->dbh = new Doctrine_Adapter_Mock('pgsql');
$this->conn = Doctrine_Manager::getInstance()->openConnection($this->dbh); $this->conn = Doctrine_Manager::getInstance()->openConnection($this->dbh);
} }
/**
public function testGetLimitSubqueryWithOrderByOnAggregateValues() public function testGetLimitSubqueryWithOrderByOnAggregateValues()
{ {
$q = new Doctrine_Query(); $q = new Doctrine_Query();
...@@ -49,9 +49,11 @@ class Doctrine_Query_PgsqlSubquery_TestCase extends Doctrine_UnitTestCase ...@@ -49,9 +49,11 @@ class Doctrine_Query_PgsqlSubquery_TestCase extends Doctrine_UnitTestCase
$q->execute(); $q->execute();
$this->dbh->pop(); $this->assertEqual($this->dbh->pop(), 'SELECT e.id AS e__id, e.name AS e__name, COUNT(DISTINCT a.id) AS a__0 FROM entity e LEFT JOIN album a ON e.id = a.user_id WHERE e.id IN '
. '(SELECT doctrine_subquery_alias.id FROM '
. '(SELECT DISTINCT e2.id, COUNT(DISTINCT a2.id) AS a2__0 FROM entity e2 LEFT JOIN album a2 ON e2.id = a2.user_id WHERE (e2.type = 0) GROUP BY e2.id ORDER BY a2__0 LIMIT 5) '
. 'AS doctrine_subquery_alias) AND (e.type = 0) GROUP BY e.id ORDER BY a__0');
$this->assertEqual($this->dbh->pop(), 'SELECT DISTINCT e2.id, COUNT(DISTINCT a2.id) AS a2__0 FROM entity e2 LEFT JOIN album a2 ON e2.id = a2.user_id WHERE (e2.type = 0) GROUP BY e2.id ORDER BY a2__0 LIMIT 5');
} }
public function testGetLimitSubqueryWithOrderByOnAggregateValuesAndColumns() public function testGetLimitSubqueryWithOrderByOnAggregateValuesAndColumns()
...@@ -65,9 +67,7 @@ class Doctrine_Query_PgsqlSubquery_TestCase extends Doctrine_UnitTestCase ...@@ -65,9 +67,7 @@ class Doctrine_Query_PgsqlSubquery_TestCase extends Doctrine_UnitTestCase
$q->execute(); $q->execute();
$this->dbh->pop(); $this->assertEqual($this->dbh->pop(), 'SELECT e.id AS e__id, e.name AS e__name, COUNT(DISTINCT a.id) AS a__0 FROM entity e LEFT JOIN album a ON e.id = a.user_id WHERE e.id IN (SELECT doctrine_subquery_alias.id FROM (SELECT DISTINCT e2.id, e2.name, COUNT(DISTINCT a2.id) AS a2__0 FROM entity e2 LEFT JOIN album a2 ON e2.id = a2.user_id WHERE (e2.type = 0) GROUP BY e2.id ORDER BY a2__0, e2.name LIMIT 5) AS doctrine_subquery_alias) AND (e.type = 0) GROUP BY e.id ORDER BY a__0, e.name');
$this->assertEqual($this->dbh->pop(), 'SELECT DISTINCT e2.id, COUNT(DISTINCT a2.id) AS a2__0, e2.name FROM entity e2 LEFT JOIN album a2 ON e2.id = a2.user_id WHERE (e2.type = 0) GROUP BY e2.id ORDER BY a2__0, e2.name LIMIT 5');
} }
*/
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment