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);
|
||||
|
||||
if (isset($terms[1])) {
|
||||
if (isset($terms[1])) {
|
||||
$componentAlias = $terms[0];
|
||||
$field = $terms[1];
|
||||
} else {
|
||||
@ -445,7 +445,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
|
||||
*/
|
||||
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);
|
||||
|
||||
$match = current($matches);
|
||||
@ -1448,7 +1448,6 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
|
||||
. $table->getColumnName($table->getIdentifier())
|
||||
. ' = '
|
||||
. $assocAlias . '.' . $relation->getForeign();
|
||||
|
||||
}
|
||||
|
||||
$this->parts['from'][] = $queryPart;
|
||||
@ -1548,10 +1547,10 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
|
||||
return $table;
|
||||
}
|
||||
/**
|
||||
* count
|
||||
* fetches the count of the query
|
||||
*
|
||||
* This method executes the main query without all the
|
||||
* 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.
|
||||
*
|
||||
* Example:
|
||||
@ -1568,61 +1567,61 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
|
||||
* @param array $params an array of prepared statement parameters
|
||||
* @return integer the count of this query
|
||||
*/
|
||||
public function count($params = array())
|
||||
{
|
||||
$this->getQuery();
|
||||
public function count($params = array())
|
||||
{
|
||||
$this->getQuery();
|
||||
|
||||
// initialize temporary variables
|
||||
$where = $this->parts['where'];
|
||||
$having = $this->parts['having'];
|
||||
$groupby = $this->parts['groupby'];
|
||||
$map = reset($this->_aliasMap);
|
||||
$componentAlias = key($this->_aliasMap);
|
||||
$table = $map['table'];
|
||||
// initialize temporary variables
|
||||
$where = $this->parts['where'];
|
||||
$having = $this->parts['having'];
|
||||
$groupby = $this->parts['groupby'];
|
||||
$map = reset($this->_aliasMap);
|
||||
$componentAlias = key($this->_aliasMap);
|
||||
$table = $map['table'];
|
||||
|
||||
// build the query base
|
||||
$q = 'SELECT COUNT(DISTINCT ' . $this->getTableAlias($componentAlias)
|
||||
. '.' . implode(',', (array) $table->getIdentifier())
|
||||
. ') AS num_results';
|
||||
// build the query base
|
||||
$q = 'SELECT COUNT(DISTINCT ' . $this->getTableAlias($componentAlias)
|
||||
. '.' . implode(',', (array) $table->getIdentifier())
|
||||
. ') AS num_results';
|
||||
|
||||
foreach ($this->parts['select'] as $field) {
|
||||
if (strpos($field, '(') !== false) {
|
||||
$q .= ', ' . $field;
|
||||
}
|
||||
}
|
||||
foreach ($this->parts['select'] as $field) {
|
||||
if (strpos($field, '(') !== false) {
|
||||
$q .= ', ' . $field;
|
||||
}
|
||||
}
|
||||
|
||||
$q .= ' FROM ' . $this->buildFromPart();
|
||||
$q .= ' FROM ' . $this->buildFromPart();
|
||||
|
||||
// append column aggregation inheritance (if needed)
|
||||
$string = $this->applyInheritance();
|
||||
// append column aggregation inheritance (if needed)
|
||||
$string = $this->applyInheritance();
|
||||
|
||||
if ( ! empty($string)) {
|
||||
$where[] = $string;
|
||||
}
|
||||
// append conditions
|
||||
$q .= ( ! empty($where)) ? ' WHERE ' . implode(' AND ', $where) : '';
|
||||
$q .= ( ! empty($groupby)) ? ' GROUP BY ' . implode(', ', $groupby) : '';
|
||||
$q .= ( ! empty($having)) ? ' HAVING ' . implode(' AND ', $having): '';
|
||||
if ( ! empty($string)) {
|
||||
$where[] = $string;
|
||||
}
|
||||
// append conditions
|
||||
$q .= ( ! empty($where)) ? ' WHERE ' . implode(' AND ', $where) : '';
|
||||
$q .= ( ! empty($groupby)) ? ' GROUP BY ' . implode(', ', $groupby) : '';
|
||||
$q .= ( ! empty($having)) ? ' HAVING ' . implode(' AND ', $having): '';
|
||||
|
||||
if ( ! is_array($params)) {
|
||||
$params = array($params);
|
||||
}
|
||||
// append parameters
|
||||
$params = array_merge($this->_params['where'], $this->_params['having'], $params);
|
||||
if ( ! is_array($params)) {
|
||||
$params = array($params);
|
||||
}
|
||||
// append parameters
|
||||
$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) {
|
||||
$count = 0;
|
||||
foreach ($results as $result) {
|
||||
$count += $result['num_results'];
|
||||
}
|
||||
} else {
|
||||
$count = isset($results[0]) ? $results[0]['num_results']:0;
|
||||
}
|
||||
if (count($results) > 1) {
|
||||
$count = 0;
|
||||
foreach ($results as $result) {
|
||||
$count += $result['num_results'];
|
||||
}
|
||||
} else {
|
||||
$count = isset($results[0]) ? $results[0]['num_results']:0;
|
||||
}
|
||||
|
||||
return (int) $count;
|
||||
}
|
||||
return (int) $count;
|
||||
}
|
||||
|
||||
/**
|
||||
* query
|
||||
@ -1641,6 +1640,13 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
|
||||
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)
|
||||
{
|
||||
if ( ! $query) {
|
||||
@ -1649,6 +1655,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
|
||||
|
||||
$new = new Doctrine_Query();
|
||||
$new->_dqlParts = $query->_dqlParts;
|
||||
$new->_params = $query->_params;
|
||||
$new->_hydrationMode = $query->_hydrationMode;
|
||||
|
||||
return $new;
|
||||
|
Loading…
x
Reference in New Issue
Block a user