Commit f0d74ea1 authored by doctrine's avatar doctrine

Fixed: Column aggregation inheritance not working on PGSQL

parent 035d8de3
......@@ -148,7 +148,7 @@ class Doctrine_DQL_Parser {
$q .= implode(", ",$a);
$this->applyInheritance();
if( ! empty($this->where))
$q .= " WHERE ".implode(" && ",$this->where);
$q .= " WHERE ".implode(" AND ",$this->where);
if( ! empty($this->orderby))
$q .= " ORDER BY ".implode(", ",$this->orderby);
......@@ -177,12 +177,12 @@ class Doctrine_DQL_Parser {
$q .= implode(", ",$a);
$this->applyInheritance();
if( ! empty($this->where))
$q .= " WHERE ".implode(" && ",$this->where);
$q .= " WHERE ".implode(" AND ",$this->where);
if( ! empty($this->orderby))
$q .= " ORDER BY ".implode(", ",$this->orderby);
if( ! empty($this->limit) && ! empty($this->offset))
if( ! empty($this->limit) AND ! empty($this->offset))
$q = $this->session->modifyLimitQuery($q,$this->limit,$this->offset);
return $q;
......@@ -215,7 +215,7 @@ class Doctrine_DQL_Parser {
foreach($map as $field=>$value) {
$b[] = $tname.".$field = $value";
}
if( ! empty($b)) $a[] = implode(" && ",$b);
if( ! empty($b)) $a[] = implode(" AND ",$b);
}
if( ! empty($a)) $c[] = implode(" || ",$a);
}
......@@ -439,7 +439,7 @@ class Doctrine_DQL_Parser {
case "order":
$p = $part;
$i = $k+1;
if(isset($e[$i]) && strtolower($e[$i]) == "by") {
if(isset($e[$i]) AND strtolower($e[$i]) == "by") {
$parts[$part] = array();
}
break;
......@@ -592,7 +592,7 @@ class Doctrine_DQL_Parser {
foreach($parts as $part) {
$ret[] = $this->parseWhere($part);
}
$r = implode(" && ",$ret);
$r = implode(" AND ",$ret);
} else {
$parts = self::bracketExplode($str," || ","(",")");
if(count($parts) > 1) {
......@@ -618,7 +618,7 @@ class Doctrine_DQL_Parser {
* @param string $e2 the second bracket, usually ')'
*/
public static function bracketTrim($str,$e1,$e2) {
if(substr($str,0,1) == $e1 && substr($str,-1) == $e2)
if(substr($str,0,1) == $e1 AND substr($str,-1) == $e2)
return substr($str,1,-1);
else
return $str;
......@@ -626,10 +626,10 @@ class Doctrine_DQL_Parser {
/**
* bracketExplode
* usage:
* $str = (age < 20 && age > 18) && email LIKE 'John@example.com'
* now exploding $str with parameters $d = ' && ', $e1 = '(' and $e2 = ')'
* $str = (age < 20 AND age > 18) AND email LIKE 'John@example.com'
* now exploding $str with parameters $d = ' AND ', $e1 = '(' and $e2 = ')'
* would return an array:
* array("(age < 20 && age > 18)", "email LIKE 'John@example.com'")
* array("(age < 20 AND age > 18)", "email LIKE 'John@example.com'")
*
* @param string $str
* @param string $d the delimeter which explodes the string
......@@ -672,7 +672,7 @@ class Doctrine_DQL_Parser {
$reference = implode(".",$a);
$objTable = $this->session->getTable(end($a));
$where = $objTable->getTableName().".".$field." ".$operator." ".$value;
if(count($a) > 1 && isset($a[1])) {
if(count($a) > 1 AND isset($a[1])) {
$root = $a[0];
$fk = $this->tnames[$root]->getForeignKey($a[1]);
if($fk instanceof Doctrine_Association) {
......
......@@ -442,7 +442,7 @@ class Doctrine_Table extends Doctrine_Configurable {
*/
final public function find($id = null) {
if($id !== null) {
$query = $this->query." WHERE ".implode(" = ? && ",$this->primaryKeys)." = ?";
$query = $this->query." WHERE ".implode(" = ? AND ",$this->primaryKeys)." = ?";
$query = $this->applyInheritance($query);
$params = array_merge(array($id), array_values($this->inheritanceMap));
......@@ -465,8 +465,8 @@ class Doctrine_Table extends Doctrine_Configurable {
foreach($this->inheritanceMap as $field => $value) {
$a[] = $field." = ?";
}
$i = implode(" && ",$a);
$where .= " && $i";
$i = implode(" AND ",$a);
$where .= " AND $i";
}
return $where;
}
......
......@@ -72,7 +72,7 @@ class Doctrine_DQL_ParserTestCase extends Doctrine_UnitTestCase {
$users = $graph->query("FROM User, User.Phonenumber-l WHERE User.Phonenumber.phonenumber LIKE '%123%'");
$this->assertEqual(trim($graph->getQuery()),
"SELECT entity.id AS User__id, phonenumber.id AS Phonenumber__id FROM entity LEFT JOIN phonenumber ON entity.id = phonenumber.entity_id WHERE (phonenumber.phonenumber LIKE '%123%') && (entity.type = 0)");
"SELECT entity.id AS User__id, phonenumber.id AS Phonenumber__id FROM entity LEFT JOIN phonenumber ON entity.id = phonenumber.entity_id WHERE (phonenumber.phonenumber LIKE '%123%') AND (entity.type = 0)");
$count = $this->session->getDBH()->count();
......@@ -143,7 +143,7 @@ class Doctrine_DQL_ParserTestCase extends Doctrine_UnitTestCase {
$users = $graph->query("FROM User, User.Email");
$this->assertEqual(trim($graph->getQuery()),
"SELECT entity.id AS User__id, email.id AS Email__id FROM entity, email WHERE (entity.email_id = email.id) && (entity.type = 0)");
"SELECT entity.id AS User__id, email.id AS Email__id FROM entity, email WHERE (entity.email_id = email.id) AND (entity.type = 0)");
$this->assertEqual($users->count(),8);
......@@ -153,32 +153,32 @@ class Doctrine_DQL_ParserTestCase extends Doctrine_UnitTestCase {
$this->assertEqual($users->count(),8);
$users = $graph->query("FROM User WHERE User.name LIKE '%Jack%'");
$this->assertTrue($graph->getQuery() == "SELECT entity.id AS User__id FROM entity WHERE (entity.name LIKE '%Jack%') && (entity.type = 0)");
$this->assertTrue($graph->getQuery() == "SELECT entity.id AS User__id FROM entity WHERE (entity.name LIKE '%Jack%') AND (entity.type = 0)");
$this->assertEqual($users->count(),0);
$users = $graph->query("FROM User ORDER BY User.name ASC, User.Email.address");
$this->assertEqual(trim($graph->getQuery()),
"SELECT entity.id AS User__id FROM entity, email WHERE (entity.email_id = email.id) && (entity.type = 0) ORDER BY entity.name ASC, email.address");
"SELECT entity.id AS User__id FROM entity, email WHERE (entity.email_id = email.id) AND (entity.type = 0) ORDER BY entity.name ASC, email.address");
$this->assertEqual($users->count(),8);
$this->assertTrue($users[0]->name == "Arnold Schwarzenegger");
$users = $graph->query("FROM User WHERE User.Phonenumber.phonenumber REGEXP '[123]'");
$this->assertEqual(trim($graph->getQuery()),
"SELECT entity.id AS User__id FROM entity LEFT JOIN phonenumber ON entity.id = phonenumber.entity_id WHERE (phonenumber.phonenumber REGEXP '[123]') && (entity.type = 0)");
"SELECT entity.id AS User__id FROM entity LEFT JOIN phonenumber ON entity.id = phonenumber.entity_id WHERE (phonenumber.phonenumber REGEXP '[123]') AND (entity.type = 0)");
$this->assertEqual($users->count(),8);
$users = $graph->query("FROM User WHERE User.Group.name = 'Action Actors'");
$this->assertEqual(trim($graph->getQuery()),
"SELECT entity.id AS User__id FROM entity WHERE (entity.id IN (SELECT user_id FROM groupuser WHERE group_id IN (SELECT entity.id AS Group__id FROM entity WHERE (entity.name = 'Action Actors') && (entity.type = 1)))) && (entity.type = 0)");
"SELECT entity.id AS User__id FROM entity WHERE (entity.id IN (SELECT user_id FROM groupuser WHERE group_id IN (SELECT entity.id AS Group__id FROM entity WHERE (entity.name = 'Action Actors') AND (entity.type = 1)))) AND (entity.type = 0)");
$this->assertTrue($users instanceof Doctrine_Collection);
$this->assertEqual($users->count(),1);
$users = $graph->query("FROM User WHERE User.Group.Phonenumber.phonenumber LIKE '123 123'");
$this->assertEqual(trim($graph->getQuery()),
"SELECT entity.id AS User__id FROM entity WHERE (entity.id IN (SELECT user_id FROM groupuser WHERE group_id IN (SELECT entity.id AS Group__id FROM entity, phonenumber WHERE (phonenumber.phonenumber LIKE '123 123') && (entity.type = 1)))) && (entity.type = 0)");
"SELECT entity.id AS User__id FROM entity WHERE (entity.id IN (SELECT user_id FROM groupuser WHERE group_id IN (SELECT entity.id AS Group__id FROM entity, phonenumber WHERE (phonenumber.phonenumber LIKE '123 123') AND (entity.type = 1)))) AND (entity.type = 0)");
$this->assertTrue($users instanceof Doctrine_Collection);
$this->assertEqual($users->count(),1);
......
......@@ -85,7 +85,7 @@ class Doctrine_TableTestCase extends Doctrine_UnitTestCase {
$this->assertFalse($this->objTable->isNewEntry());
}
public function testApplyInheritance() {
$this->assertEqual($this->objTable->applyInheritance("id = 3"), "id = 3 && type = ?");
$this->assertEqual($this->objTable->applyInheritance("id = 3"), "id = 3 AND type = ?");
}
}
?>
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