1
0
mirror of synced 2025-01-20 15:31:40 +03:00
This commit is contained in:
zYne 2007-06-27 22:29:57 +00:00
parent f290439c52
commit e1979612c7
3 changed files with 47 additions and 14 deletions

View File

@ -928,7 +928,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
$subquery = $this->_conn->modifyLimitQuery($subquery, $this->parts['limit'], $this->parts['offset']); $subquery = $this->_conn->modifyLimitQuery($subquery, $this->parts['limit'], $this->parts['offset']);
$parts = Doctrine_Tokenizer::quoteExplode($subquery, ' ', "'", "'"); $parts = Doctrine_Tokenizer::quoteExplode($subquery, ' ', "'", "'");
//print_r($parts);
foreach ($parts as $k => $part) { foreach ($parts as $k => $part) {
if (strpos($part, "'") !== false) { if (strpos($part, "'") !== false) {
continue; continue;
@ -936,8 +936,43 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
if ($this->hasTableAlias($part)) { if ($this->hasTableAlias($part)) {
$parts[$k] = $this->generateNewTableAlias($part); $parts[$k] = $this->generateNewTableAlias($part);
continue;
} }
if (strpos($part, '.') == false) {
continue;
}
preg_match_all("/[a-zA-Z0-9_]+\.[a-z0-9_]+/i", $part, $m);
foreach ($m[0] as $match) {
$e = explode('.', $match);
$e[0] = $this->generateNewTableAlias($e[0]);
$parts[$k] = str_replace($match, implode('.', $e), $parts[$k]);
}
}
if ($driverName == 'mysql' || $driverName == 'pgsql') {
foreach ($parts as $k => $part) {
if (strpos($part, "'") !== false) {
continue;
}
if (strpos($part, '__') == false) {
continue;
}
preg_match_all("/[a-zA-Z0-9_]+\_\_[a-z0-9_]+/i", $part, $m);
foreach ($m[0] as $match) {
$e = explode('__', $match);
$e[0] = $this->generateNewTableAlias($e[0]);
$parts[$k] = str_replace($match, implode('__', $e), $parts[$k]);
}
}
}
/**
$separator = false; $separator = false;
if (strpos($part, '.') !== false) { if (strpos($part, '.') !== false) {
@ -958,8 +993,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
$e[0] = substr($e[0], 0, $pos) . $this->generateNewTableAlias($trimmed); $e[0] = substr($e[0], 0, $pos) . $this->generateNewTableAlias($trimmed);
$parts[$k] = implode($separator, $e); $parts[$k] = implode($separator, $e);
} }*/
}
$subquery = implode(' ', $parts); $subquery = implode(' ', $parts);
return $subquery; return $subquery;

View File

@ -52,7 +52,7 @@ class Doctrine_Query_MysqlSubqueryHaving_TestCase extends Doctrine_UnitTestCase
$this->dbh->pop(); $this->dbh->pop();
$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 HAVING a2__0 > 0 ORDER BY a2__0 LIMIT 5'); $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 HAVING a2__0 > 0 ORDER BY a2__0 DESC LIMIT 5');
} }
public function testGetLimitSubqueryWithHavingOnAggregateValuesIncorrectAlias() public function testGetLimitSubqueryWithHavingOnAggregateValuesIncorrectAlias()
@ -68,7 +68,6 @@ class Doctrine_Query_MysqlSubqueryHaving_TestCase extends Doctrine_UnitTestCase
$q->execute(); $q->execute();
$this->dbh->pop(); $this->dbh->pop();
$this->assertEqual($this->dbh->pop(), 'SELECT DISTINCT e2.id, COUNT(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 HAVING a2__0 > 0 ORDER BY a2__0 DESC LIMIT 5');
$this->assertEqual($this->dbh->pop(), 'SELECT DISTINCT e2.id, COUNT(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 HAVING a2__0 > 0 ORDER BY a2__0 LIMIT 5');
} }
} }