1
0
mirror of synced 2024-12-13 14:56:01 +03:00
This commit is contained in:
zYne 2007-05-15 22:13:59 +00:00
parent 6a7130be55
commit 2592739f2d
2 changed files with 20 additions and 17 deletions

View File

@ -88,7 +88,7 @@ class Doctrine_Query2 extends Doctrine_Hydrate2 implements Countable
*/
public static function create()
{
return new Doctrine_Query();
return new Doctrine_Query2();
}
/**
* isSubquery
@ -604,7 +604,7 @@ class Doctrine_Query2 extends Doctrine_Hydrate2 implements Countable
if ( ! in_array($e[3], $this->subqueryAliases) &&
! in_array($e[2], $this->subqueryAliases)) {
continue;
}
}
}
$subquery .= ' ' . $part;
@ -789,8 +789,8 @@ class Doctrine_Query2 extends Doctrine_Hydrate2 implements Countable
$path = $e[0];
}
$tmp = explode(' ', $path);
$componentAlias = (count($tmp) > 1) ? end($tmp) : false;
$tmp = explode(' ', $path);
$originalAlias = (count($tmp) > 1) ? end($tmp) : null;
$e = preg_split("/[.:]/", $tmp[0], -1);
@ -814,26 +814,28 @@ class Doctrine_Query2 extends Doctrine_Hydrate2 implements Countable
$delimeter = substr($fullPath, $length, 1);
// if an alias is not given use the current path as an alias identifier
if (strlen($prevPath) !== $fullLength || ! $componentAlias) {
if (strlen($prevPath) === $fullLength && isset($originalAlias)) {
$componentAlias = $originalAlias;
} else {
$componentAlias = $prevPath;
}
if ( ! isset($table)) {
// process the root of the path
$table = $this->loadRoot($name, $componentAlias);
} else {
$join = ($delimeter == ':') ? 'INNER JOIN ' : 'LEFT JOIN ';
$relation = $table->getRelation($name);
$this->_aliasMap[$componentAlias] = array('table' => $relation->getTable(),
'parent' => $parent,
'relation' => $relation);
if( ! $relation->isOneToOne()) {
if ( ! $relation->isOneToOne()) {
$this->needsSubquery = true;
}
$localAlias = $this->getShortAlias($parent, $table->getTableName());
$foreignAlias = $this->getShortAlias($componentAlias, $relation->getTable()->getTableName());
$localSql = $this->conn->quoteIdentifier($table->getTableName()) . ' ' . $localAlias;
@ -880,6 +882,7 @@ class Doctrine_Query2 extends Doctrine_Hydrate2 implements Countable
}
} else {
$queryPart = $join . $foreignSql
. ' ON ' . $localAlias . '.'
. $relation->getLocal() . ' = ' . $foreignAlias . '.' . $relation->getForeign()
@ -913,6 +916,7 @@ class Doctrine_Query2 extends Doctrine_Hydrate2 implements Countable
$this->pendingAggregates = array();
}
}
$parent = $prevPath;
}
return end($this->_aliasMap);
}
@ -1020,7 +1024,7 @@ class Doctrine_Query2 extends Doctrine_Hydrate2 implements Countable
*/
public function query($query, $params = array())
{
$this->_parser->parseQuery($query);
$this->parseQuery($query);
return $this->execute($params);
}

View File

@ -192,11 +192,11 @@ class Doctrine_Query_Limit_TestCase extends Doctrine_UnitTestCase
$q->from('User.Phonenumber');
$q->where('User.name = ?');
$q->limit(5);
print $q;
$users = $q->execute(array('zYne'));
$this->assertEqual($users->count(), 1);
$this->connection->flush();
//$this->connection->flush();
}
public function testLimitWithManyToManyColumnAggInheritanceLeftJoin()
{
@ -204,7 +204,6 @@ class Doctrine_Query_Limit_TestCase extends Doctrine_UnitTestCase
$q->from('User.Group')->limit(5);
$users = $q->execute();
$this->assertEqual($users->count(), 5);
@ -219,7 +218,8 @@ class Doctrine_Query_Limit_TestCase extends Doctrine_UnitTestCase
$user3->Group = $user->Group;
$this->assertEqual($user->Group[0]->name, "Action Actors");
$this->assertEqual(count($user->Group), 3);
$this->connection->flush();
$this->assertEqual($user->Group[0]->name, "Action Actors");
@ -236,8 +236,8 @@ class Doctrine_Query_Limit_TestCase extends Doctrine_UnitTestCase
$this->assertEqual($users->count(), 3);
$this->connection->clear();
$q = new Doctrine_Query();
$q->from("User")->where("User.Group.id = ?")->orderby("User.id DESC");
$q = new Doctrine_Query2();
$q->from('User')->where('User.Group.id = ?')->orderby('User.id DESC');
$users = $q->execute(array($user->Group[1]->id));
$this->assertEqual($users->count(), 3);
@ -287,6 +287,5 @@ class Doctrine_Query_Limit_TestCase extends Doctrine_UnitTestCase
$this->assertEqual($q->getQuery(),
"SELECT p.id AS p__id, p.name AS p__name FROM photo p LEFT JOIN phototag p2 ON p.id = p2.photo_id LEFT JOIN tag t ON t.id = p2.tag_id WHERE p.id IN (SELECT DISTINCT p3.id FROM photo p3 LEFT JOIN phototag p4 ON p3.id = p4.photo_id LEFT JOIN tag t2 ON t2.id = p4.tag_id WHERE t2.id = ? ORDER BY p3.id DESC LIMIT 100) AND t.id = ? ORDER BY p.id DESC");
}
}
?>