fixed bug in Doctrine_Query::copy() - params were not copied
This commit is contained in:
parent
e9ba4504bf
commit
26ee84d5c8
@ -402,7 +402,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
|
|||||||
{
|
{
|
||||||
$terms = explode('.', $field);
|
$terms = explode('.', $field);
|
||||||
|
|
||||||
if (isset($terms[1])) {
|
if (isset($terms[1])) {
|
||||||
$componentAlias = $terms[0];
|
$componentAlias = $terms[0];
|
||||||
$field = $terms[1];
|
$field = $terms[1];
|
||||||
} else {
|
} else {
|
||||||
@ -445,7 +445,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
|
|||||||
*/
|
*/
|
||||||
public function getExpressionOwner($expr)
|
public function getExpressionOwner($expr)
|
||||||
{
|
{
|
||||||
if (strtoupper(substr(trim($expr, '( '), 0, 6)) !== 'SELECT') {
|
if (strtoupper(substr(trim($expr, '( '), 0, 6)) !== 'SELECT') {
|
||||||
preg_match_all("/[a-z0-9_]+\.[a-z0-9_]+[\.[a-z0-9]+]*/i", $expr, $matches);
|
preg_match_all("/[a-z0-9_]+\.[a-z0-9_]+[\.[a-z0-9]+]*/i", $expr, $matches);
|
||||||
|
|
||||||
$match = current($matches);
|
$match = current($matches);
|
||||||
@ -1448,7 +1448,6 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
|
|||||||
. $table->getColumnName($table->getIdentifier())
|
. $table->getColumnName($table->getIdentifier())
|
||||||
. ' = '
|
. ' = '
|
||||||
. $assocAlias . '.' . $relation->getForeign();
|
. $assocAlias . '.' . $relation->getForeign();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->parts['from'][] = $queryPart;
|
$this->parts['from'][] = $queryPart;
|
||||||
@ -1548,10 +1547,10 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
|
|||||||
return $table;
|
return $table;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* count
|
* count
|
||||||
* fetches the count of the query
|
* fetches the count of the query
|
||||||
*
|
*
|
||||||
* This method executes the main query without all the
|
* This method executes the main query without all the
|
||||||
* selected fields, ORDER BY part, LIMIT part and OFFSET part.
|
* selected fields, ORDER BY part, LIMIT part and OFFSET part.
|
||||||
*
|
*
|
||||||
* Example:
|
* Example:
|
||||||
@ -1568,61 +1567,61 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
|
|||||||
* @param array $params an array of prepared statement parameters
|
* @param array $params an array of prepared statement parameters
|
||||||
* @return integer the count of this query
|
* @return integer the count of this query
|
||||||
*/
|
*/
|
||||||
public function count($params = array())
|
public function count($params = array())
|
||||||
{
|
{
|
||||||
$this->getQuery();
|
$this->getQuery();
|
||||||
|
|
||||||
// initialize temporary variables
|
// initialize temporary variables
|
||||||
$where = $this->parts['where'];
|
$where = $this->parts['where'];
|
||||||
$having = $this->parts['having'];
|
$having = $this->parts['having'];
|
||||||
$groupby = $this->parts['groupby'];
|
$groupby = $this->parts['groupby'];
|
||||||
$map = reset($this->_aliasMap);
|
$map = reset($this->_aliasMap);
|
||||||
$componentAlias = key($this->_aliasMap);
|
$componentAlias = key($this->_aliasMap);
|
||||||
$table = $map['table'];
|
$table = $map['table'];
|
||||||
|
|
||||||
// build the query base
|
// build the query base
|
||||||
$q = 'SELECT COUNT(DISTINCT ' . $this->getTableAlias($componentAlias)
|
$q = 'SELECT COUNT(DISTINCT ' . $this->getTableAlias($componentAlias)
|
||||||
. '.' . implode(',', (array) $table->getIdentifier())
|
. '.' . implode(',', (array) $table->getIdentifier())
|
||||||
. ') AS num_results';
|
. ') AS num_results';
|
||||||
|
|
||||||
foreach ($this->parts['select'] as $field) {
|
foreach ($this->parts['select'] as $field) {
|
||||||
if (strpos($field, '(') !== false) {
|
if (strpos($field, '(') !== false) {
|
||||||
$q .= ', ' . $field;
|
$q .= ', ' . $field;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$q .= ' FROM ' . $this->buildFromPart();
|
$q .= ' FROM ' . $this->buildFromPart();
|
||||||
|
|
||||||
// append column aggregation inheritance (if needed)
|
// append column aggregation inheritance (if needed)
|
||||||
$string = $this->applyInheritance();
|
$string = $this->applyInheritance();
|
||||||
|
|
||||||
if ( ! empty($string)) {
|
if ( ! empty($string)) {
|
||||||
$where[] = $string;
|
$where[] = $string;
|
||||||
}
|
}
|
||||||
// append conditions
|
// append conditions
|
||||||
$q .= ( ! empty($where)) ? ' WHERE ' . implode(' AND ', $where) : '';
|
$q .= ( ! empty($where)) ? ' WHERE ' . implode(' AND ', $where) : '';
|
||||||
$q .= ( ! empty($groupby)) ? ' GROUP BY ' . implode(', ', $groupby) : '';
|
$q .= ( ! empty($groupby)) ? ' GROUP BY ' . implode(', ', $groupby) : '';
|
||||||
$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
|
// append parameters
|
||||||
$params = array_merge($this->_params['where'], $this->_params['having'], $params);
|
$params = array_merge($this->_params['where'], $this->_params['having'], $params);
|
||||||
|
|
||||||
$results = $this->getConnection()->fetchAll($q, $params);
|
$results = $this->getConnection()->fetchAll($q, $params);
|
||||||
|
|
||||||
if (count($results) > 1) {
|
if (count($results) > 1) {
|
||||||
$count = 0;
|
$count = 0;
|
||||||
foreach ($results as $result) {
|
foreach ($results as $result) {
|
||||||
$count += $result['num_results'];
|
$count += $result['num_results'];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$count = isset($results[0]) ? $results[0]['num_results']:0;
|
$count = isset($results[0]) ? $results[0]['num_results']:0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (int) $count;
|
return (int) $count;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* query
|
* query
|
||||||
@ -1641,6 +1640,13 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
|
|||||||
return $this->execute($params, $hydrationMode);
|
return $this->execute($params, $hydrationMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copies a Doctrine_Query object.
|
||||||
|
*
|
||||||
|
* @param Doctrine_Query Doctrine query instance.
|
||||||
|
* If ommited the instance itself will be used as source.
|
||||||
|
* @return Doctrine_Query Copy of the Doctrine_Query instance.
|
||||||
|
*/
|
||||||
public function copy(Doctrine_Query $query = null)
|
public function copy(Doctrine_Query $query = null)
|
||||||
{
|
{
|
||||||
if ( ! $query) {
|
if ( ! $query) {
|
||||||
@ -1649,6 +1655,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
|
|||||||
|
|
||||||
$new = new Doctrine_Query();
|
$new = new Doctrine_Query();
|
||||||
$new->_dqlParts = $query->_dqlParts;
|
$new->_dqlParts = $query->_dqlParts;
|
||||||
|
$new->_params = $query->_params;
|
||||||
$new->_hydrationMode = $query->_hydrationMode;
|
$new->_hydrationMode = $query->_hydrationMode;
|
||||||
|
|
||||||
return $new;
|
return $new;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user