1
0
mirror of synced 2025-01-05 16:53:21 +03:00

refactored parameter stacking (Fixes #442).

This commit is contained in:
romanb 2007-09-02 09:28:38 +00:00
parent 0fdb229020
commit af2a83484f
6 changed files with 28 additions and 27 deletions

View File

@ -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
*/ */
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
} }
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
*/ */
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();
@ -1037,9 +1041,8 @@ class Doctrine_Hydrate extends Doctrine_Object implements Serializable
$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
$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.");
} }

View File

@ -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);

View File

@ -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
$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
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
} 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
*/ */
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
*/ */
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);

View File

@ -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;
} }

View File

@ -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);
} }
} }

View File

@ -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());