1
0
Fork 0
mirror of synced 2025-04-03 13:23:37 +03:00
This commit is contained in:
zYne 2007-05-24 17:46:32 +00:00
parent df773520d6
commit 755f30f642
2 changed files with 27 additions and 25 deletions

View file

@ -66,7 +66,7 @@ class Doctrine_Hydrate
/** /**
* @var Doctrine_Connection $conn Doctrine_Connection object * @var Doctrine_Connection $conn Doctrine_Connection object
*/ */
protected $conn; protected $_conn;
/** /**
* @var Doctrine_View $_view Doctrine_View object, when set this object will use the * @var Doctrine_View $_view Doctrine_View object, when set this object will use the
* the query given by the view object for object population * the query given by the view object for object population
@ -94,11 +94,6 @@ class Doctrine_Hydrate
* and values as sql aliases * and values as sql aliases
*/ */
protected $aggregateMap = array(); protected $aggregateMap = array();
/**
* @var Doctrine_Hydrate_Alias $aliasHandler handles the creation and storage of table aliases and
* binds the aliases to component aliases / paths
*/
protected $aliasHandler;
/** /**
* @var array $parts SQL query string parts * @var array $parts SQL query string parts
*/ */
@ -136,7 +131,7 @@ class Doctrine_Hydrate
if ( ! ($connection instanceof Doctrine_Connection)) { if ( ! ($connection instanceof Doctrine_Connection)) {
$connection = Doctrine_Manager::getInstance()->getCurrentConnection(); $connection = Doctrine_Manager::getInstance()->getCurrentConnection();
} }
$this->conn = $connection; $this->_conn = $connection;
} }
public function generateNewAlias($alias) public function generateNewAlias($alias)
{ {
@ -262,10 +257,16 @@ class Doctrine_Hydrate
} }
/** /**
* copyAliases * copyAliases
* copy aliases from another Hydrate object
* *
* @return void * this method is needed by DQL subqueries which need the aliases
* of the parent query
*
* @param Doctrine_Hydrate $query the query object from which the
* aliases are copied from
* @return Doctrine_Hydrate this object
*/ */
public function copyAliases($query) public function copyAliases(Doctrine_Hydrate $query)
{ {
$this->shortAliases = $query->shortAliases; $this->shortAliases = $query->shortAliases;
@ -273,6 +274,7 @@ class Doctrine_Hydrate
} }
/** /**
* createSubquery * createSubquery
* creates a subquery
* *
* @return Doctrine_Hydrate * @return Doctrine_Hydrate
*/ */
@ -353,7 +355,7 @@ class Doctrine_Hydrate
*/ */
public function getConnection() public function getConnection()
{ {
return $this->conn; return $this->_conn;
} }
/** /**
* setView * setView
@ -443,7 +445,7 @@ class Doctrine_Hydrate
*/ */
public function execute($params = array(), $return = Doctrine::FETCH_RECORD) public function execute($params = array(), $return = Doctrine::FETCH_RECORD)
{ {
$params = $this->conn->convertBooleans(array_merge($this->params, $params)); $params = $this->_conn->convertBooleans(array_merge($this->params, $params));
$params = $this->convertEnums($params); $params = $this->convertEnums($params);
if ( ! $this->_view) { if ( ! $this->_view) {
@ -453,16 +455,16 @@ class Doctrine_Hydrate
} }
if ($this->isLimitSubqueryUsed() && if ($this->isLimitSubqueryUsed() &&
$this->conn->getDBH()->getAttribute(Doctrine::ATTR_DRIVER_NAME) !== 'mysql') { $this->_conn->getDBH()->getAttribute(Doctrine::ATTR_DRIVER_NAME) !== 'mysql') {
$params = array_merge($params, $params); $params = array_merge($params, $params);
} }
if ($this->type !== self::SELECT) { if ($this->type !== self::SELECT) {
return $this->conn->exec($query, $params); return $this->_conn->exec($query, $params);
} }
$stmt = $this->conn->execute($query, $params); $stmt = $this->_conn->execute($query, $params);
$array = (array) $this->parseData($stmt); $array = (array) $this->parseData($stmt);
if (empty($this->_aliasMap)) { if (empty($this->_aliasMap)) {
throw new Doctrine_Hydrate_Exception("Couldn't execute query. Component alias map was empty."); throw new Doctrine_Hydrate_Exception("Couldn't execute query. Component alias map was empty.");

View file

@ -379,7 +379,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
$argStr = substr($func, ($pos + 1), -1); $argStr = substr($func, ($pos + 1), -1);
$args = explode(',', $argStr); $args = explode(',', $argStr);
$func = call_user_func_array(array($this->conn->expression, $name), $args); $func = call_user_func_array(array($this->_conn->expression, $name), $args);
if(substr($func, 0, 1) !== '(') { if(substr($func, 0, 1) !== '(') {
$pos = strpos($func, '('); $pos = strpos($func, '(');
@ -641,10 +641,10 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
$subquery = $this->getLimitSubquery(); $subquery = $this->getLimitSubquery();
switch (strtolower($this->conn->getName())) { switch (strtolower($this->_conn->getName())) {
case 'mysql': case 'mysql':
// mysql doesn't support LIMIT in subqueries // mysql doesn't support LIMIT in subqueries
$list = $this->conn->execute($subquery, $params)->fetchAll(PDO::FETCH_COLUMN); $list = $this->_conn->execute($subquery, $params)->fetchAll(PDO::FETCH_COLUMN);
$subquery = implode(', ', $list); $subquery = implode(', ', $list);
break; break;
case 'pgsql': case 'pgsql':
@ -670,7 +670,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
$q .= ( ! empty($this->parts['orderby']))? ' ORDER BY ' . implode(', ', $this->parts['orderby']) : ''; $q .= ( ! empty($this->parts['orderby']))? ' ORDER BY ' . implode(', ', $this->parts['orderby']) : '';
if ($modifyLimit) { if ($modifyLimit) {
$q = $this->conn->modifyLimitQuery($q, $this->parts['limit'], $this->parts['offset']); $q = $this->_conn->modifyLimitQuery($q, $this->parts['limit'], $this->parts['offset']);
} }
// return to the previous state // return to the previous state
@ -710,7 +710,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
// initialize the base of the subquery // initialize the base of the subquery
$subquery = 'SELECT DISTINCT ' . $primaryKey; $subquery = 'SELECT DISTINCT ' . $primaryKey;
if ($this->conn->getDBH()->getAttribute(PDO::ATTR_DRIVER_NAME) == 'pgsql') { if ($this->_conn->getDBH()->getAttribute(PDO::ATTR_DRIVER_NAME) == 'pgsql') {
// pgsql needs the order by fields to be preserved in select clause // pgsql needs the order by fields to be preserved in select clause
foreach ($this->parts['orderby'] as $part) { foreach ($this->parts['orderby'] as $part) {
@ -746,7 +746,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
$subquery .= ( ! empty($this->parts['orderby']))? ' ORDER BY ' . implode(', ', $this->parts['orderby']) : ''; $subquery .= ( ! empty($this->parts['orderby']))? ' ORDER BY ' . implode(', ', $this->parts['orderby']) : '';
// add driver specific limit clause // add driver specific limit clause
$subquery = $this->conn->modifyLimitQuery($subquery, $this->parts['limit'], $this->parts['offset']); $subquery = $this->_conn->modifyLimitQuery($subquery, $this->parts['limit'], $this->parts['offset']);
$parts = Doctrine_Tokenizer::quoteExplode($subquery, ' ', "'", "'"); $parts = Doctrine_Tokenizer::quoteExplode($subquery, ' ', "'", "'");
@ -972,8 +972,8 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
$localAlias = $this->getShortAlias($parent, $table->getTableName()); $localAlias = $this->getShortAlias($parent, $table->getTableName());
$foreignAlias = $this->getShortAlias($componentAlias, $relation->getTable()->getTableName()); $foreignAlias = $this->getShortAlias($componentAlias, $relation->getTable()->getTableName());
$localSql = $this->conn->quoteIdentifier($table->getTableName()) . ' ' . $localAlias; $localSql = $this->_conn->quoteIdentifier($table->getTableName()) . ' ' . $localAlias;
$foreignSql = $this->conn->quoteIdentifier($relation->getTable()->getTableName()) . ' ' . $foreignAlias; $foreignSql = $this->_conn->quoteIdentifier($relation->getTable()->getTableName()) . ' ' . $foreignAlias;
$map = $relation->getTable()->inheritanceMap; $map = $relation->getTable()->inheritanceMap;
@ -1063,16 +1063,16 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
public function loadRoot($name, $componentAlias) public function loadRoot($name, $componentAlias)
{ {
// get the connection for the component // get the connection for the component
$this->conn = Doctrine_Manager::getInstance() $this->_conn = Doctrine_Manager::getInstance()
->getConnectionForComponent($name); ->getConnectionForComponent($name);
$table = $this->conn->getTable($name); $table = $this->_conn->getTable($name);
$tableName = $table->getTableName(); $tableName = $table->getTableName();
// get the short alias for this table // get the short alias for this table
$tableAlias = $this->getShortAlias($componentAlias, $tableName); $tableAlias = $this->getShortAlias($componentAlias, $tableName);
// quote table name // quote table name
$queryPart = $this->conn->quoteIdentifier($tableName); $queryPart = $this->_conn->quoteIdentifier($tableName);
if ($this->type === self::SELECT) { if ($this->type === self::SELECT) {
$queryPart .= ' ' . $tableAlias; $queryPart .= ' ' . $tableAlias;