From af2a83484f84ebdf1991c5ced0bdc634d2f7b5a0 Mon Sep 17 00:00:00 2001 From: romanb Date: Sun, 2 Sep 2007 09:28:38 +0000 Subject: [PATCH] refactored parameter stacking (Fixes #442). --- lib/Doctrine/Hydrate.php | 22 ++++++++++++---------- lib/Doctrine/Query.php | 2 +- lib/Doctrine/Query/Abstract.php | 26 +++++++++++++------------- lib/Doctrine/Record.php | 2 +- lib/Doctrine/Record/Abstract.php | 2 +- tests/run.php | 1 - 6 files changed, 28 insertions(+), 27 deletions(-) diff --git a/lib/Doctrine/Hydrate.php b/lib/Doctrine/Hydrate.php index 10d3b66b6..72df1e3e7 100644 --- a/lib/Doctrine/Hydrate.php +++ b/lib/Doctrine/Hydrate.php @@ -70,7 +70,9 @@ class Doctrine_Hydrate extends Doctrine_Object implements Serializable /** * @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 */ @@ -688,7 +690,7 @@ class Doctrine_Hydrate extends Doctrine_Object implements Serializable */ public function getParams() { - return $this->_params; + return array_merge($this->_params['set'], $this->_params['where'], $this->_params['having']); } /** * setParams @@ -751,7 +753,7 @@ class Doctrine_Hydrate extends Doctrine_Object implements Serializable } public function _execute($params) { - $params = $this->_conn->convertBooleans(array_merge($this->_params, $params)); + $params = $this->_conn->convertBooleans($params); if ( ! $this->_view) { $query = $this->getQuery($params); @@ -783,6 +785,8 @@ class Doctrine_Hydrate extends Doctrine_Object implements Serializable */ public function execute($params = array(), $hydrationMode = null) { + $params = array_merge($this->_params['set'], $this->_params['where'], + $this->_params['having'], $params); if ($this->_cache) { $cacheDriver = $this->getCacheDriver(); @@ -1036,10 +1040,9 @@ class Doctrine_Hydrate extends Doctrine_Object implements Serializable $oneToOne = false; $index = $driver->search($element, $array); - if ($index === false) { - $key = $map['map']; - - if (isset($key)) { + if ($index === false) { + if (isset($map['map'])) { + $key = $map['map']; if (isset($array[$key])) { 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 $index = $driver->search($element, $prev[$parent][$componentAlias]); if ($index === false) { - $key = $map['map']; - - if (isset($key)) { + if (isset($map['map'])) { + $key = $map['map']; if (isset($prev[$parent][$componentAlias][$key])) { throw new Doctrine_Hydrate_Exception("Couldn't hydrate. Found non-unique key mapping."); } diff --git a/lib/Doctrine/Query.php b/lib/Doctrine/Query.php index 550894dc5..52bb3ce4a 100644 --- a/lib/Doctrine/Query.php +++ b/lib/Doctrine/Query.php @@ -1519,7 +1519,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable $params = array($params); } // append parameters - $params = array_merge($this->_params, $params); + $params = array_merge($this->_params['where'], $this->_params['having'], $params); $results = $this->getConnection()->fetchAll($q, $params); diff --git a/lib/Doctrine/Query/Abstract.php b/lib/Doctrine/Query/Abstract.php index 901f2a872..b96b5e149 100644 --- a/lib/Doctrine/Query/Abstract.php +++ b/lib/Doctrine/Query/Abstract.php @@ -65,9 +65,9 @@ abstract class Doctrine_Query_Abstract extends Doctrine_Hydrate public function addWhere($where, $params = array()) { if (is_array($params)) { - $this->_params = array_merge($this->_params, $params); + $this->_params['where'] = array_merge($this->_params['where'], $params); } else { - $this->_params[] = $params; + $this->_params['where'][] = $params; } return $this->parseQueryPart('where', $where, true); } @@ -93,7 +93,7 @@ abstract class Doctrine_Query_Abstract extends Doctrine_Hydrate $a[] = $value; } - $this->_params = array_merge($this->_params, $params); + $this->_params['where'] = array_merge($this->_params['where'], $params); $where = $expr . ' IN (' . implode(', ', $a) . ')'; @@ -121,9 +121,9 @@ abstract class Doctrine_Query_Abstract extends Doctrine_Hydrate public function addHaving($having, $params = array()) { if (is_array($params)) { - $this->_params = array_merge($this->_params, $params); + $this->_params['having'] = array_merge($this->_params['having'], $params); } else { - $this->_params[] = $params; + $this->_params['having'][] = $params; } return $this->parseQueryPart('having', $having, true); } @@ -217,9 +217,9 @@ abstract class Doctrine_Query_Abstract extends Doctrine_Hydrate } else { if ($params !== null) { if (is_array($params)) { - $this->_params = array_merge($this->_params, $params); + $this->_params['set'] = array_merge($this->_params['set'], $params); } else { - $this->_params[] = $params; + $this->_params['set'][] = $params; } } return $this->parseQueryPart('set', $key . ' = ' . $value, true); @@ -279,11 +279,11 @@ abstract class Doctrine_Query_Abstract extends Doctrine_Hydrate */ public function where($where, $params = array()) { - //$this->_params = array(); + $this->_params['where'] = array(); if (is_array($params)) { - $this->_params = $params; + $this->_params['where'] = $params; } else { - $this->_params[] = $params; + $this->_params['where'][] = $params; } return $this->parseQueryPart('where', $where); @@ -298,11 +298,11 @@ abstract class Doctrine_Query_Abstract extends Doctrine_Hydrate */ public function having($having, $params = array()) { - $this->_params = array(); + $this->_params['having'] = array(); if (is_array($params)) { - $this->_params = $params; + $this->_params['having'] = $params; } else { - $this->_params[] = $params; + $this->_params['having'][] = $params; } return $this->parseQueryPart('having', $having); diff --git a/lib/Doctrine/Record.php b/lib/Doctrine/Record.php index f9e195e6e..ba6eeafbd 100644 --- a/lib/Doctrine/Record.php +++ b/lib/Doctrine/Record.php @@ -139,7 +139,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count $class = get_class($this); // get the table of this class $this->_table = Doctrine_Manager::getInstance() - ->getTable(get_class($this)); + ->getTable($class); $exists = false; } diff --git a/lib/Doctrine/Record/Abstract.php b/lib/Doctrine/Record/Abstract.php index 59b1232fa..b610c6d3d 100644 --- a/lib/Doctrine/Record/Abstract.php +++ b/lib/Doctrine/Record/Abstract.php @@ -110,7 +110,7 @@ abstract class Doctrine_Record_Abstract extends Doctrine_Access $conn = $this->_table->getConnection(); foreach ($map as $key => $value) { $table = $conn->getTable($key); -// $table->setOption('inheritanceMap', $value); + $table->setOption('inheritanceMap', $value); } } diff --git a/tests/run.php b/tests/run.php index da67faa9f..a5fbd4c92 100644 --- a/tests/run.php +++ b/tests/run.php @@ -74,7 +74,6 @@ $test->addTestCase(new Doctrine_Ticket330_TestCase()); $test->addTestCase(new Doctrine_TicketNjero_TestCase()); - // Connection drivers (not yet fully tested) $test->addTestCase(new Doctrine_Connection_Pgsql_TestCase()); $test->addTestCase(new Doctrine_Connection_Oracle_TestCase());