1
0
mirror of synced 2025-01-18 22:41:43 +03:00

tests for DDC-1719

This commit is contained in:
Fabio B. Silva 2012-05-31 18:37:51 -03:00
parent 1bcda5147a
commit d49a968d55
7 changed files with 120 additions and 49 deletions

View File

@ -139,11 +139,9 @@ class EntityManager implements ObjectManager
$this->config = $config;
$this->eventManager = $eventManager;
$quoteStrategyClassName = $config->getQuoteStrategyClassName();
$metadataFactoryClassName = $config->getClassMetadataFactoryName();
$metadataFactoryClassName = $config->getClassMetadataFactoryName();
$this->quoteStrategy = new $quoteStrategyClassName($conn->getDatabasePlatform());
$this->metadataFactory = new $metadataFactoryClassName;
$this->metadataFactory = new $metadataFactoryClassName;
$this->metadataFactory->setEntityManager($this);
$this->metadataFactory->setCacheDriver($this->config->getMetadataCacheImpl());
@ -183,6 +181,11 @@ class EntityManager implements ObjectManager
*/
public function getQuoteStrategy()
{
if ($this->quoteStrategy === null) {
$className = $this->getConfiguration()->getQuoteStrategyClassName();
$this->quoteStrategy = new $className($this->getConnection()->getDatabasePlatform());
}
return $this->quoteStrategy;
}

View File

@ -33,10 +33,7 @@ class DefaultQuoteStrategy extends QuoteStrategy
{
/**
* Checks if the given identifier is quoted
*
* @param string $identifier
* @return string
* {@inheritdoc}
*/
public function isQuotedIdentifier($identifier)
{
@ -44,10 +41,7 @@ class DefaultQuoteStrategy extends QuoteStrategy
}
/**
* Gets the uquoted column name.
*
* @param string $identifier
* @return string
* {@inheritdoc}
*/
public function getUnquotedIdentifier($identifier)
{
@ -55,11 +49,7 @@ class DefaultQuoteStrategy extends QuoteStrategy
}
/**
* Gets the (possibly quoted) column name for safe use in an SQL statement.
*
* @param string $fieldName
* @param ClassMetadata $class
* @return string
* {@inheritdoc}
*/
public function getColumnName($fieldName, ClassMetadata $class)
{
@ -69,10 +59,7 @@ class DefaultQuoteStrategy extends QuoteStrategy
}
/**
* Gets the (possibly quoted) primary table name for safe use in an SQL statement.
*
* @param ClassMetadata $class
* @return string
* {@inheritdoc}
*/
public function getTableName(ClassMetadata $class)
{
@ -82,10 +69,7 @@ class DefaultQuoteStrategy extends QuoteStrategy
}
/**
* Gets the (possibly quoted) name of the join table.
*
* @param ClassMetadata $class
* @return string
* {@inheritdoc}
*/
public function getJoinTableName($relation, ClassMetadata $class)
{
@ -96,10 +80,7 @@ class DefaultQuoteStrategy extends QuoteStrategy
}
/**
* Gets the (possibly quoted) identifier column names for safe use in an SQL statement.
*
* @param ClassMetadata $class
* @return array
* {@inheritdoc}
*/
public function getIdentifierColumnNames(ClassMetadata $class)
{
@ -131,12 +112,7 @@ class DefaultQuoteStrategy extends QuoteStrategy
}
/**
* Gets the column alias.
*
* @param string $columnName
* @param integer $counter
* @param ClassMetadata $class
* @return string
* {@inheritdoc}
*/
public function getColumnAlias($columnName, $counter, ClassMetadata $class = null)
{

View File

@ -46,4 +46,63 @@ abstract class QuoteStrategy
$this->platform = $platform;
}
/**
* Checks if the given identifier is quoted
*
* @param string $identifier
* @return string
*/
abstract public function isQuotedIdentifier($identifier);
/**
* Gets the uquoted column name.
*
* @param string $identifier
* @return string
*/
abstract public function getUnquotedIdentifier($identifier);
/**
* Gets the (possibly quoted) column name for safe use in an SQL statement.
*
* @param string $fieldName
* @param ClassMetadata $class
* @return string
*/
abstract public function getColumnName($fieldName, ClassMetadata $class);
/**
* Gets the (possibly quoted) primary table name for safe use in an SQL statement.
*
* @param ClassMetadata $class
* @return string
*/
abstract public function getTableName(ClassMetadata $class);
/**
* Gets the (possibly quoted) name of the join table.
*
* @param ClassMetadata $class
* @return string
*/
abstract public function getJoinTableName($relation, ClassMetadata $class);
/**
* Gets the (possibly quoted) identifier column names for safe use in an SQL statement.
*
* @param ClassMetadata $class
* @return array
*/
abstract public function getIdentifierColumnNames(ClassMetadata $class);
/**
* Gets the column alias.
*
* @param string $columnName
* @param integer $counter
* @param ClassMetadata $class
* @return string
*/
abstract public function getColumnAlias($columnName, $counter, ClassMetadata $class = null);
}

View File

@ -170,6 +170,13 @@ class BasicEntityPersister
*/
protected $_sqlTableAliases = array();
/**
* The quote strategy.
*
* @var \Doctrine\ORM\Mapping\QuoteStrategy
*/
private $quoteStrategy;
/**
* Initializes a new <tt>BasicEntityPersister</tt> that uses the given EntityManager
* and persists instances of the class described by the given ClassMetadata descriptor.
@ -179,10 +186,11 @@ class BasicEntityPersister
*/
public function __construct(EntityManager $em, ClassMetadata $class)
{
$this->_em = $em;
$this->_class = $class;
$this->_conn = $em->getConnection();
$this->_platform = $this->_conn->getDatabasePlatform();
$this->_em = $em;
$this->_class = $class;
$this->_conn = $em->getConnection();
$this->quoteStrategy = $em->getQuoteStrategy();
$this->_platform = $this->_conn->getDatabasePlatform();
}
/**
@ -1573,11 +1581,7 @@ class BasicEntityPersister
*/
public function getSQLColumnAlias($columnName)
{
// Trim the column alias to the maximum identifier length of the platform.
// If the alias is to long, characters are cut off from the beginning.
return $this->_platform->getSQLResultCasing(
substr($columnName . $this->_sqlAliasCounter++, -$this->_platform->getMaxIdentifierLength())
);
return $this->quoteStrategy->getColumnAlias($columnName, $this->_sqlAliasCounter++);
}
/**

View File

@ -286,11 +286,7 @@ class SqlWalker implements TreeWalker
*/
public function getSQLColumnAlias($columnName)
{
// Trim the column alias to the maximum identifier length of the platform.
// If the alias is to long, characters are cut off from the beginning.
return $this->platform->getSQLResultCasing(
substr($columnName . $this->aliasCounter++, -$this->platform->getMaxIdentifierLength())
);
return $this->quoteStrategy->getColumnAlias($columnName, $this->aliasCounter++);
}
/**

View File

@ -76,4 +76,16 @@ class BasicEntityPersisterTypeValueSqlTest extends \Doctrine\Tests\OrmTestCase
$this->assertEquals('t0.customInteger = ABS(?) AND t0.child_id = ?', $sql);
}
/**
* @group DDC-1719
*/
public function testStripNonAlphanumericCharactersFromSelectColumnListSQL()
{
$persister = new BasicEntityPersister($this->_em, $this->_em->getClassMetadata('Doctrine\Tests\Models\DDC1719\DDC1719Entity'));
$method = new \ReflectionMethod($persister, '_getSelectColumnListSQL');
$method->setAccessible(true);
$this->assertEquals('t0."entity-id" AS entityid1, t0."entity-value" AS entityvalue2', $method->invoke($persister));
}
}

View File

@ -1641,6 +1641,27 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
);
}
/**
* @group DDC-1719
*/
public function testStripNonAlphanumericCharactersFromAlias()
{
$this->assertSqlGeneration(
'SELECT e FROM Doctrine\Tests\Models\DDC1719\DDC1719Entity e',
'SELECT d0_."entity-id" AS entityid0, d0_."entity-value" AS entityvalue1 FROM "ddc-1719-entity" d0_'
);
$this->assertSqlGeneration(
'SELECT e.value FROM Doctrine\Tests\Models\DDC1719\DDC1719Entity e ORDER BY e.value',
'SELECT d0_."entity-value" AS entityvalue0 FROM "ddc-1719-entity" d0_ ORDER BY d0_."entity-value" ASC'
);
$this->assertSqlGeneration(
'SELECT TRIM(e.value) FROM Doctrine\Tests\Models\DDC1719\DDC1719Entity e ORDER BY e.value',
'SELECT TRIM(d0_."entity-value") AS sclr0 FROM "ddc-1719-entity" d0_ ORDER BY d0_."entity-value" ASC'
);
}
}