1
0
mirror of synced 2024-12-13 22:56:04 +03:00
This commit is contained in:
zYne 2007-05-24 18:00:35 +00:00
parent 2ce1c5f483
commit b6dcef0eee
3 changed files with 49 additions and 16 deletions

View File

@ -189,16 +189,32 @@ class Doctrine_Hydrate
return $alias; return $alias;
} }
/**
* getAliases
* returns all aliases
*
* @return array
*/
public function getAliases() public function getAliases()
{ {
return $this->shortAliases; return $this->shortAliases;
} }
public function addAlias($tableAlias, $componentAlias) /**
* addTableAlias
* adds an alias for table and associates it with given component alias
*
* @param string $componentAlias the alias for the query component associated with given tableAlias
* @param string $tableAlias the table alias to be added
* @return Doctrine_Hydrate
*/
public function addTableAlias($tableAlias, $componentAlias)
{ {
$this->shortAliases[$tableAlias] = $componentAlias; $this->shortAliases[$tableAlias] = $componentAlias;
return $this;
} }
/** /**
* getShortAlias * getTableAlias
* some database such as Oracle need the identifier lengths to be < ~30 chars * some database such as Oracle need the identifier lengths to be < ~30 chars
* hence Doctrine creates as short identifier aliases as possible * hence Doctrine creates as short identifier aliases as possible
* *
@ -209,7 +225,7 @@ class Doctrine_Hydrate
* @param string $tableName the table name from which the table alias is being created * @param string $tableName the table name from which the table alias is being created
* @return string the generated / fetched short alias * @return string the generated / fetched short alias
*/ */
public function getShortAlias($componentAlias, $tableName = null) public function getTableAlias($componentAlias, $tableName = null)
{ {
$alias = array_search($componentAlias, $this->shortAliases); $alias = array_search($componentAlias, $this->shortAliases);
@ -223,17 +239,23 @@ class Doctrine_Hydrate
return $this->generateShortAlias($componentAlias, $tableName); return $this->generateShortAlias($componentAlias, $tableName);
} }
/**
public function getTableAlias($componentAlias) * addQueryPart
{ * adds a query part in the query part array
return $this->getShortAlias($componentAlias); *
} * @param string $name the name of the query part to be added
* @param string $part query part string
* @throws Doctrine_Hydrate_Exception if trying to add unknown query part
* @return Doctrine_Hydrate this object
*/
public function addQueryPart($name, $part) public function addQueryPart($name, $part)
{ {
if ( ! isset($this->parts[$name])) { if ( ! isset($this->parts[$name])) {
throw new Doctrine_Hydrate_Exception('Unknown query part ' . $name); throw new Doctrine_Hydrate_Exception('Unknown query part ' . $name);
} }
$this->parts[$name][] = $part; $this->parts[$name][] = $part;
return $this;
} }
public function getDeclaration($name) public function getDeclaration($name)
{ {
@ -243,6 +265,15 @@ class Doctrine_Hydrate
return $this->_aliasMap[$name]; return $this->_aliasMap[$name];
} }
/**
* setQueryPart
* sets a query part in the query part array
*
* @param string $name the name of the query part to be set
* @param string $part query part string
* @throws Doctrine_Hydrate_Exception if trying to set unknown query part
* @return Doctrine_Hydrate this object
*/
public function setQueryPart($name, $part) public function setQueryPart($name, $part)
{ {
if ( ! isset($this->parts[$name])) { if ( ! isset($this->parts[$name])) {
@ -254,6 +285,8 @@ class Doctrine_Hydrate
} else { } else {
$this->parts[$name] = $part; $this->parts[$name] = $part;
} }
return $this;
} }
/** /**
* copyAliases * copyAliases

View File

@ -653,7 +653,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
break; break;
} }
$field = $this->getShortAlias($rootAlias) . '.' . $table->getIdentifier(); $field = $this->getTableAlias($rootAlias) . '.' . $table->getIdentifier();
// only append the subquery if it actually contains something // only append the subquery if it actually contains something
if ($subquery !== '') { if ($subquery !== '') {
@ -704,7 +704,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
$componentAlias = key($this->_aliasMap); $componentAlias = key($this->_aliasMap);
// get short alias // get short alias
$alias = $this->getShortAlias($componentAlias); $alias = $this->getTableAlias($componentAlias);
$primaryKey = $alias . '.' . $table->getIdentifier(); $primaryKey = $alias . '.' . $table->getIdentifier();
// initialize the base of the subquery // initialize the base of the subquery
@ -970,8 +970,8 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
$this->needsSubquery = true; $this->needsSubquery = true;
} }
$localAlias = $this->getShortAlias($parent, $table->getTableName()); $localAlias = $this->getTableAlias($parent, $table->getTableName());
$foreignAlias = $this->getShortAlias($componentAlias, $relation->getTable()->getTableName()); $foreignAlias = $this->getTableAlias($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;
@ -992,7 +992,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
$assocPath = $prevPath . '.' . $asf->getComponentName(); $assocPath = $prevPath . '.' . $asf->getComponentName();
$assocAlias = $this->getShortAlias($assocPath, $asf->getTableName()); $assocAlias = $this->getTableAlias($assocPath, $asf->getTableName());
$queryPart = $join . $assocTableName . ' ' . $assocAlias . ' ON ' . $localAlias . '.' $queryPart = $join . $assocTableName . ' ' . $assocAlias . ' ON ' . $localAlias . '.'
. $table->getIdentifier() . ' = ' . $table->getIdentifier() . ' = '
@ -1070,7 +1070,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
$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->getTableAlias($componentAlias, $tableName);
// quote table name // quote table name
$queryPart = $this->_conn->quoteIdentifier($tableName); $queryPart = $this->_conn->quoteIdentifier($tableName);
@ -1115,7 +1115,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
$table = $map['table']; $table = $map['table'];
// build the query base // build the query base
$q = 'SELECT COUNT(DISTINCT ' . $this->getShortAlias($table->getTableName()) $q = 'SELECT COUNT(DISTINCT ' . $this->getTableAlias($table->getTableName())
. '.' . $table->getIdentifier() . '.' . $table->getIdentifier()
. ') FROM ' . $this->buildFromPart(); . ') FROM ' . $this->buildFromPart();

View File

@ -257,7 +257,7 @@ class Doctrine_RawSql extends Doctrine_Query_Abstract
'parent' => $parent, 'parent' => $parent,
'relation' => $relation); 'relation' => $relation);
} }
$this->addAlias($tableAlias, $componentAlias); $this->addTableAlias($tableAlias, $componentAlias);
$parent = $currPath; $parent = $currPath;
} }