This commit is contained in:
parent
fb29ca0b07
commit
44809328f0
@ -162,6 +162,14 @@ class Doctrine_Hydrate2
|
|||||||
}
|
}
|
||||||
$this->parts[$name][] = $part;
|
$this->parts[$name][] = $part;
|
||||||
}
|
}
|
||||||
|
public function getDeclaration($name)
|
||||||
|
{
|
||||||
|
if ( ! isset($this->_aliasMap[$name])) {
|
||||||
|
throw new Doctrine_Hydrate_Exception('Unknown component alias ' . $name);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->_aliasMap[$name];
|
||||||
|
}
|
||||||
public function setQueryPart($name, $part)
|
public function setQueryPart($name, $part)
|
||||||
{
|
{
|
||||||
if ( ! isset($this->parts[$name])) {
|
if ( ! isset($this->parts[$name])) {
|
||||||
|
@ -454,7 +454,7 @@ class Doctrine_Query2 extends Doctrine_Hydrate2 implements Countable
|
|||||||
|
|
||||||
if ( ! empty($e2)) {
|
if ( ! empty($e2)) {
|
||||||
$parser = new Doctrine_Query_JoinCondition($this);
|
$parser = new Doctrine_Query_JoinCondition($this);
|
||||||
$part .= ' AND ' . $parser->parse(implode(' AND ', $e2));
|
$part .= ' AND ' . $parser->_parse(implode(' AND ', $e2));
|
||||||
}
|
}
|
||||||
|
|
||||||
$q .= ' ' . $part;
|
$q .= ' ' . $part;
|
||||||
@ -949,42 +949,61 @@ class Doctrine_Query2 extends Doctrine_Hydrate2 implements Countable
|
|||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* count
|
* count
|
||||||
|
* fetches the count of the query
|
||||||
|
*
|
||||||
|
* This method executes the main query without all the
|
||||||
|
* selected fields, ORDER BY part, LIMIT part and OFFSET part.
|
||||||
*
|
*
|
||||||
* @param array $params
|
* Example:
|
||||||
* @return integer
|
* Main query:
|
||||||
|
* SELECT u.*, p.phonenumber FROM User u
|
||||||
|
* LEFT JOIN u.Phonenumber p
|
||||||
|
* WHERE p.phonenumber = '123 123' LIMIT 10
|
||||||
|
*
|
||||||
|
* The query this method executes:
|
||||||
|
* SELECT COUNT(DISTINCT u.id) FROM User u
|
||||||
|
* LEFT JOIN u.Phonenumber p
|
||||||
|
* WHERE p.phonenumber = '123 123'
|
||||||
|
*
|
||||||
|
* @param array $params an array of prepared statement parameters
|
||||||
|
* @return integer the count of this query
|
||||||
*/
|
*/
|
||||||
public function count($params = array())
|
public function count($params = array())
|
||||||
{
|
{
|
||||||
$oldParts = $this->parts;
|
// initialize temporary variables
|
||||||
|
$where = $this->parts['where'];
|
||||||
$join = $this->join;
|
$having = $this->parts['having'];
|
||||||
$where = $this->where;
|
$map = reset($this->_aliasMap);
|
||||||
$having = $this->having;
|
$componentAlias = key($this->_aliasMap);
|
||||||
$table = reset($this->tables);
|
$table = $map['table'];
|
||||||
|
|
||||||
|
// build the query base
|
||||||
$q = 'SELECT COUNT(DISTINCT ' . $this->aliasHandler->getShortAlias($table->getTableName())
|
$q = 'SELECT COUNT(DISTINCT ' . $this->aliasHandler->getShortAlias($table->getTableName())
|
||||||
. '.' . $table->getIdentifier()
|
. '.' . $table->getIdentifier()
|
||||||
. ') FROM ' . $table->getTableName() . ' ' . $this->aliasHandler->getShortAlias($table->getTableName());
|
. ') FROM ' . $this->buildFromPart();
|
||||||
|
|
||||||
foreach($join as $j) {
|
// append column aggregation inheritance (if needed)
|
||||||
$q .= ' '.implode(' ',$j);
|
|
||||||
}
|
|
||||||
$string = $this->applyInheritance();
|
$string = $this->applyInheritance();
|
||||||
|
|
||||||
if ( ! empty($string)) {
|
if ( ! empty($string)) {
|
||||||
$where[] = $string;
|
$where[] = $string;
|
||||||
}
|
}
|
||||||
|
// append conditions
|
||||||
$q .= ( ! empty($where)) ? ' WHERE ' . implode(' AND ', $where) : '';
|
$q .= ( ! empty($where)) ? ' WHERE ' . implode(' AND ', $where) : '';
|
||||||
$q .= ( ! empty($having)) ? ' HAVING ' . implode(' AND ', $having): '';
|
$q .= ( ! empty($having)) ? ' HAVING ' . implode(' AND ', $having): '';
|
||||||
|
|
||||||
if( ! is_array($params)) {
|
if ( ! is_array($params)) {
|
||||||
$params = array($params);
|
$params = array($params);
|
||||||
}
|
}
|
||||||
|
// append parameters
|
||||||
$params = array_merge($this->params, $params);
|
$params = array_merge($this->params, $params);
|
||||||
|
|
||||||
return (int) $this->getConnection()->fetchOne($q, $params);
|
return (int) $this->getConnection()->fetchOne($q, $params);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
* isLimitSubqueryUsed
|
||||||
|
* whether or not limit subquery algorithm is used
|
||||||
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function isLimitSubqueryUsed() {
|
public function isLimitSubqueryUsed() {
|
||||||
@ -1100,6 +1119,31 @@ class Doctrine_Query2 extends Doctrine_Hydrate2 implements Countable
|
|||||||
{
|
{
|
||||||
return $this->getParser('select')->parse($select);
|
return $this->getParser('select')->parse($select);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* delete
|
||||||
|
* sets the query type to DELETE
|
||||||
|
*
|
||||||
|
* @return Doctrine_Query
|
||||||
|
*/
|
||||||
|
public function delete()
|
||||||
|
{
|
||||||
|
$this->type = self::DELETE;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* update
|
||||||
|
* sets the UPDATE part of the query
|
||||||
|
*
|
||||||
|
* @param string $update DQL UPDATE part
|
||||||
|
* @return Doctrine_Query
|
||||||
|
*/
|
||||||
|
public function update($update)
|
||||||
|
{
|
||||||
|
$this->type = self::UPDATE;
|
||||||
|
|
||||||
|
return $this->getParser('from')->parse($update);
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* from
|
* from
|
||||||
* sets the FROM part of the query
|
* sets the FROM part of the query
|
||||||
|
Loading…
x
Reference in New Issue
Block a user