Commit af2a8348 authored by romanb's avatar romanb

refactored parameter stacking (Fixes #442).

parent 0fdb2290
...@@ -70,7 +70,9 @@ class Doctrine_Hydrate extends Doctrine_Object implements Serializable ...@@ -70,7 +70,9 @@ class Doctrine_Hydrate extends Doctrine_Object implements Serializable
/** /**
* @var array $params query input parameters * @var array $params query input parameters
*/ */
protected $_params = array(); protected $_params = array('where' => array(),
'set' => array(),
'having' => array());
/** /**
* @var Doctrine_Connection $conn Doctrine_Connection object * @var Doctrine_Connection $conn Doctrine_Connection object
*/ */
...@@ -688,7 +690,7 @@ class Doctrine_Hydrate extends Doctrine_Object implements Serializable ...@@ -688,7 +690,7 @@ class Doctrine_Hydrate extends Doctrine_Object implements Serializable
*/ */
public function getParams() public function getParams()
{ {
return $this->_params; return array_merge($this->_params['set'], $this->_params['where'], $this->_params['having']);
} }
/** /**
* setParams * setParams
...@@ -751,7 +753,7 @@ class Doctrine_Hydrate extends Doctrine_Object implements Serializable ...@@ -751,7 +753,7 @@ class Doctrine_Hydrate extends Doctrine_Object implements Serializable
} }
public function _execute($params) public function _execute($params)
{ {
$params = $this->_conn->convertBooleans(array_merge($this->_params, $params)); $params = $this->_conn->convertBooleans($params);
if ( ! $this->_view) { if ( ! $this->_view) {
$query = $this->getQuery($params); $query = $this->getQuery($params);
...@@ -783,6 +785,8 @@ class Doctrine_Hydrate extends Doctrine_Object implements Serializable ...@@ -783,6 +785,8 @@ class Doctrine_Hydrate extends Doctrine_Object implements Serializable
*/ */
public function execute($params = array(), $hydrationMode = null) public function execute($params = array(), $hydrationMode = null)
{ {
$params = array_merge($this->_params['set'], $this->_params['where'],
$this->_params['having'], $params);
if ($this->_cache) { if ($this->_cache) {
$cacheDriver = $this->getCacheDriver(); $cacheDriver = $this->getCacheDriver();
...@@ -1036,10 +1040,9 @@ class Doctrine_Hydrate extends Doctrine_Object implements Serializable ...@@ -1036,10 +1040,9 @@ class Doctrine_Hydrate extends Doctrine_Object implements Serializable
$oneToOne = false; $oneToOne = false;
$index = $driver->search($element, $array); $index = $driver->search($element, $array);
if ($index === false) { if ($index === false) {
$key = $map['map']; if (isset($map['map'])) {
$key = $map['map'];
if (isset($key)) {
if (isset($array[$key])) { if (isset($array[$key])) {
throw new Doctrine_Hydrate_Exception("Couldn't hydrate. Found non-unique key mapping."); throw new Doctrine_Hydrate_Exception("Couldn't hydrate. Found non-unique key mapping.");
} }
...@@ -1081,9 +1084,8 @@ class Doctrine_Hydrate extends Doctrine_Object implements Serializable ...@@ -1081,9 +1084,8 @@ class Doctrine_Hydrate extends Doctrine_Object implements Serializable
$index = $driver->search($element, $prev[$parent][$componentAlias]); $index = $driver->search($element, $prev[$parent][$componentAlias]);
if ($index === false) { if ($index === false) {
$key = $map['map']; if (isset($map['map'])) {
$key = $map['map'];
if (isset($key)) {
if (isset($prev[$parent][$componentAlias][$key])) { if (isset($prev[$parent][$componentAlias][$key])) {
throw new Doctrine_Hydrate_Exception("Couldn't hydrate. Found non-unique key mapping."); throw new Doctrine_Hydrate_Exception("Couldn't hydrate. Found non-unique key mapping.");
} }
......
...@@ -1519,7 +1519,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable ...@@ -1519,7 +1519,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
$params = array($params); $params = array($params);
} }
// append parameters // append parameters
$params = array_merge($this->_params, $params); $params = array_merge($this->_params['where'], $this->_params['having'], $params);
$results = $this->getConnection()->fetchAll($q, $params); $results = $this->getConnection()->fetchAll($q, $params);
......
...@@ -65,9 +65,9 @@ abstract class Doctrine_Query_Abstract extends Doctrine_Hydrate ...@@ -65,9 +65,9 @@ abstract class Doctrine_Query_Abstract extends Doctrine_Hydrate
public function addWhere($where, $params = array()) public function addWhere($where, $params = array())
{ {
if (is_array($params)) { if (is_array($params)) {
$this->_params = array_merge($this->_params, $params); $this->_params['where'] = array_merge($this->_params['where'], $params);
} else { } else {
$this->_params[] = $params; $this->_params['where'][] = $params;
} }
return $this->parseQueryPart('where', $where, true); return $this->parseQueryPart('where', $where, true);
} }
...@@ -93,7 +93,7 @@ abstract class Doctrine_Query_Abstract extends Doctrine_Hydrate ...@@ -93,7 +93,7 @@ abstract class Doctrine_Query_Abstract extends Doctrine_Hydrate
$a[] = $value; $a[] = $value;
} }
$this->_params = array_merge($this->_params, $params); $this->_params['where'] = array_merge($this->_params['where'], $params);
$where = $expr . ' IN (' . implode(', ', $a) . ')'; $where = $expr . ' IN (' . implode(', ', $a) . ')';
...@@ -121,9 +121,9 @@ abstract class Doctrine_Query_Abstract extends Doctrine_Hydrate ...@@ -121,9 +121,9 @@ abstract class Doctrine_Query_Abstract extends Doctrine_Hydrate
public function addHaving($having, $params = array()) public function addHaving($having, $params = array())
{ {
if (is_array($params)) { if (is_array($params)) {
$this->_params = array_merge($this->_params, $params); $this->_params['having'] = array_merge($this->_params['having'], $params);
} else { } else {
$this->_params[] = $params; $this->_params['having'][] = $params;
} }
return $this->parseQueryPart('having', $having, true); return $this->parseQueryPart('having', $having, true);
} }
...@@ -217,9 +217,9 @@ abstract class Doctrine_Query_Abstract extends Doctrine_Hydrate ...@@ -217,9 +217,9 @@ abstract class Doctrine_Query_Abstract extends Doctrine_Hydrate
} else { } else {
if ($params !== null) { if ($params !== null) {
if (is_array($params)) { if (is_array($params)) {
$this->_params = array_merge($this->_params, $params); $this->_params['set'] = array_merge($this->_params['set'], $params);
} else { } else {
$this->_params[] = $params; $this->_params['set'][] = $params;
} }
} }
return $this->parseQueryPart('set', $key . ' = ' . $value, true); return $this->parseQueryPart('set', $key . ' = ' . $value, true);
...@@ -279,11 +279,11 @@ abstract class Doctrine_Query_Abstract extends Doctrine_Hydrate ...@@ -279,11 +279,11 @@ abstract class Doctrine_Query_Abstract extends Doctrine_Hydrate
*/ */
public function where($where, $params = array()) public function where($where, $params = array())
{ {
//$this->_params = array(); $this->_params['where'] = array();
if (is_array($params)) { if (is_array($params)) {
$this->_params = $params; $this->_params['where'] = $params;
} else { } else {
$this->_params[] = $params; $this->_params['where'][] = $params;
} }
return $this->parseQueryPart('where', $where); return $this->parseQueryPart('where', $where);
...@@ -298,11 +298,11 @@ abstract class Doctrine_Query_Abstract extends Doctrine_Hydrate ...@@ -298,11 +298,11 @@ abstract class Doctrine_Query_Abstract extends Doctrine_Hydrate
*/ */
public function having($having, $params = array()) public function having($having, $params = array())
{ {
$this->_params = array(); $this->_params['having'] = array();
if (is_array($params)) { if (is_array($params)) {
$this->_params = $params; $this->_params['having'] = $params;
} else { } else {
$this->_params[] = $params; $this->_params['having'][] = $params;
} }
return $this->parseQueryPart('having', $having); return $this->parseQueryPart('having', $having);
......
...@@ -139,7 +139,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count ...@@ -139,7 +139,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
$class = get_class($this); $class = get_class($this);
// get the table of this class // get the table of this class
$this->_table = Doctrine_Manager::getInstance() $this->_table = Doctrine_Manager::getInstance()
->getTable(get_class($this)); ->getTable($class);
$exists = false; $exists = false;
} }
......
...@@ -110,7 +110,7 @@ abstract class Doctrine_Record_Abstract extends Doctrine_Access ...@@ -110,7 +110,7 @@ abstract class Doctrine_Record_Abstract extends Doctrine_Access
$conn = $this->_table->getConnection(); $conn = $this->_table->getConnection();
foreach ($map as $key => $value) { foreach ($map as $key => $value) {
$table = $conn->getTable($key); $table = $conn->getTable($key);
// $table->setOption('inheritanceMap', $value); $table->setOption('inheritanceMap', $value);
} }
} }
......
...@@ -74,7 +74,6 @@ $test->addTestCase(new Doctrine_Ticket330_TestCase()); ...@@ -74,7 +74,6 @@ $test->addTestCase(new Doctrine_Ticket330_TestCase());
$test->addTestCase(new Doctrine_TicketNjero_TestCase()); $test->addTestCase(new Doctrine_TicketNjero_TestCase());
// Connection drivers (not yet fully tested) // Connection drivers (not yet fully tested)
$test->addTestCase(new Doctrine_Connection_Pgsql_TestCase()); $test->addTestCase(new Doctrine_Connection_Pgsql_TestCase());
$test->addTestCase(new Doctrine_Connection_Oracle_TestCase()); $test->addTestCase(new Doctrine_Connection_Oracle_TestCase());
......
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