From 9f297c3140c26522ca2cfd659f49069d2acacfb3 Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Thu, 10 May 2012 21:18:09 -0300 Subject: [PATCH 01/37] first tests for DefaultQuoteStrategy --- lib/Doctrine/ORM/Configuration.php | 30 ++++ .../ORM/Mapping/DefaultQuoteStrategy.php | 138 ++++++++++++++++++ lib/Doctrine/ORM/Mapping/QuoteStrategy.php | 49 +++++++ .../Tests/ORM/Mapping/QuoteStrategyTest.php | 106 ++++++++++++++ 4 files changed, 323 insertions(+) create mode 100644 lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php create mode 100644 lib/Doctrine/ORM/Mapping/QuoteStrategy.php create mode 100644 tests/Doctrine/Tests/ORM/Mapping/QuoteStrategyTest.php diff --git a/lib/Doctrine/ORM/Configuration.php b/lib/Doctrine/ORM/Configuration.php index 840ae01b4..015dce5ca 100644 --- a/lib/Doctrine/ORM/Configuration.php +++ b/lib/Doctrine/ORM/Configuration.php @@ -629,4 +629,34 @@ class Configuration extends \Doctrine\DBAL\Configuration return $this->_attributes['namingStrategy']; } + + /** + * Set quote strategy class. + * + * @since 2.4 + * @param string $namingStrategy + */ + public function setQuoteStrategyClassName($className) + { + $quoteStrategy = 'Doctrine\Mapping\AbstractQuoteStrategy'; + + if ($className !== $quoteStrategy && ! is_subclass_of($className, $quoteStrategy)) { + throw new \InvalidArgumentException("Invalid quote strategy class"); + } + + $this->_attributes['quoteStrategyClassName'] = $namingStrategy; + } + + /** + * Get quote strategy class. + * + * @since 2.4 + * @return string + */ + public function getQuoteStrategyClassName() + { + return isset($this->_attributes['quoteStrategyClassName']) + ? $this->_attributes['quoteStrategyClassName'] + : 'Doctrine\Mapping\DefaultQuoteStrategy'; + } } diff --git a/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php b/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php new file mode 100644 index 000000000..8a8d2bbe9 --- /dev/null +++ b/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php @@ -0,0 +1,138 @@ +. + */ + +namespace Doctrine\ORM\Mapping; + + +/** + * A set of rules for determining the physical column, alias and table quotes + * + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @link www.doctrine-project.org + * @since 2.4 + * @author Fabio B. Silva + */ +class DefaultQuoteStrategy extends QuoteStrategy +{ + + public function isQuotedIdentifier($identifier) + { + return strlen($identifier) > 0 && $identifier[0] === '`'; + } + + public function getUnquotedIdentifier($identifier) + { + return trim($identifier, '`'); + } + + /** + * @param string $fieldName + * @param ClassMetadata $class + * @return string + */ + public function getColumnName($fieldName, ClassMetadata $class) + { + return isset($class->fieldMappings[$fieldName]['quoted']) + ? $this->platform->quoteIdentifier($class->fieldMappings[$fieldName]['columnName']) + : $class->fieldMappings[$fieldName]['columnName']; + } + + /** + * Gets the (possibly quoted) primary table name of this class for safe use + * in an SQL statement. + * + * @param ClassMetadata $class + * @return string + */ + public function getTableName(ClassMetadata $class) + { + return isset($class->table['quoted']) + ? $this->platform->quoteIdentifier($class->table['name']) + : $class->table['name']; + } + + /** + * Gets the (possibly quoted) name of the join table. + * + * @param ClassMetadata $class + * @return string + */ + public function getJoinTableName($relation, ClassMetadata $class) + { + $assoc = $class->associationMappings[$relation]; + return isset($assoc['joinTable']['quoted']) + ? $this->platform->quoteIdentifier($assoc['joinTable']['name']) + : $assoc['joinTable']['name']; + } + + /** + * Gets the (possibly quoted) identifier column names for safe use in an SQL statement. + * + * @param ClassMetadata $class + * @return array + */ + public function getIdentifierColumnNames(ClassMetadata $class) + { + $quotedColumnNames = array(); + + foreach ($class->identifier as $fieldName) { + if (isset($this->fieldMappings[$fieldName])) { + $quotedColumnNames[] = $this->getColumnName($fieldName, $class); + + continue; + } + + // Association defined as Id field + $platform = $this->platform; + $joinColumns = $class->associationMappings[$fieldName]['joinColumns']; + $assocQuotedColumnNames = array_map( + function ($joinColumn) use ($platform) { + return isset($joinColumn['quoted']) + ? $platform->quoteIdentifier($joinColumn['name']) + : $joinColumn['name']; + }, + $joinColumns + ); + + $quotedColumnNames = array_merge($quotedColumnNames, $assocQuotedColumnNames); + } + + return $quotedColumnNames; + } + + /** + * @param string $columnName + * @param string $counter + * @param ClassMetadata $class + * @return string + */ + public function getColumnAlias($columnName, $counter, ClassMetadata $class = null) + { + // 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. + // And strip non alphanumeric characters + $columnName = $columnName . $counter; + $columnName = substr($columnName, -$this->platform->getMaxIdentifierLength()); + $columnName = preg_replace('/[^A-Za-z0-9_]/', '', $columnName); + + return $this->platform->getSQLResultCasing($columnName); + } + +} \ No newline at end of file diff --git a/lib/Doctrine/ORM/Mapping/QuoteStrategy.php b/lib/Doctrine/ORM/Mapping/QuoteStrategy.php new file mode 100644 index 000000000..366efb877 --- /dev/null +++ b/lib/Doctrine/ORM/Mapping/QuoteStrategy.php @@ -0,0 +1,49 @@ +. + */ + +namespace Doctrine\ORM\Mapping; + +use Doctrine\ORM\Mapping\ClassMetadata; +use Doctrine\DBAL\Platforms\AbstractPlatform; + +/** + * A set of rules for determining the physical column, alias and table quotes + * + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @link www.doctrine-project.org + * @since 2.4 + * @author Fabio B. Silva + */ +abstract class QuoteStrategy +{ + /** + * @var \Doctrine\DBAL\Platforms\AbstractPlatform + */ + protected $platform; + + /** + * @param AbstractPlatform $platform + */ + public function __construct(AbstractPlatform $platform) + { + $this->platform = $platform; + } + +} \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Mapping/QuoteStrategyTest.php b/tests/Doctrine/Tests/ORM/Mapping/QuoteStrategyTest.php new file mode 100644 index 000000000..38bc4de21 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/QuoteStrategyTest.php @@ -0,0 +1,106 @@ +_getTestEntityManager(); + $this->strategy = new DefaultQuoteStrategy($em->getConnection()->getDatabasePlatform()); + } + + + /** + * @param string $className + * @return \Doctrine\ORM\Mapping\ClassMetadata + */ + private function createClassMetadata($className) + { + $cm = new ClassMetadata($className); + $cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService); + + return $cm; + } + + + public function testIsQuotedIdentifier() + { + $this->assertTrue($this->strategy->isQuotedIdentifier('`table_name`')); + $this->assertFalse($this->strategy->isQuotedIdentifier('table_name')); + $this->assertFalse($this->strategy->isQuotedIdentifier(null)); + $this->assertFalse($this->strategy->isQuotedIdentifier('')); + } + + public function testGetUnquotedIdentifier() + { + $this->assertEquals('table_name' ,$this->strategy->getUnquotedIdentifier('`table_name`')); + $this->assertEquals('table_name' ,$this->strategy->getUnquotedIdentifier('table_name')); + } + + public function testGetColumnName() + { + $cm = $this->createClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + $cm->mapField(array('fieldName' => 'name', 'columnName' => '`name`')); + $cm->mapField(array('fieldName' => 'id', 'columnName' => 'id')); + + $this->assertEquals('id' ,$this->strategy->getColumnName('id', $cm)); + $this->assertEquals('"name"' ,$this->strategy->getColumnName('name', $cm)); + } + + public function testGetTableName() + { + $cm = $this->createClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + $cm->setPrimaryTable(array('name'=>'`cms_user`')); + $this->assertEquals('"cms_user"' ,$this->strategy->getTableName($cm)); + + $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + $cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService); + $cm->setPrimaryTable(array('name'=>'cms_user')); + $this->assertEquals('cms_user' ,$this->strategy->getTableName($cm)); + } + + public function testJoinTableName() + { + $cm = $this->createClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress'); + $cm->mapManyToMany(array( + 'fieldName' => 'user', + 'targetEntity' => 'CmsUser', + 'inversedBy' => 'users', + 'joinTable' => array( + 'name' => '`cmsaddress_cmsuser`' + ) + ) + ); + $this->assertEquals('"cmsaddress_cmsuser"', $this->strategy->getJoinTableName('user', $cm)); + + $cm = $this->createClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress'); + $cm->mapManyToMany(array( + 'fieldName' => 'user', + 'targetEntity' => 'CmsUser', + 'inversedBy' => 'users', + 'joinTable' => array( + 'name' => 'cmsaddress_cmsuser' + ) + ) + ); + $this->assertEquals('cmsaddress_cmsuser', $this->strategy->getJoinTableName('user', $cm)); + + } +} \ No newline at end of file From 2b4c29e4f29ef914a929ac35598bc8adb70f94df Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Wed, 30 May 2012 15:28:03 -0300 Subject: [PATCH 02/37] tests for default strategy --- .../ORM/Mapping/DefaultQuoteStrategy.php | 25 +++++-- .../Tests/ORM/Mapping/QuoteStrategyTest.php | 70 ++++++++++++++++--- 2 files changed, 80 insertions(+), 15 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php b/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php index 8a8d2bbe9..a2a49f1b4 100644 --- a/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php +++ b/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php @@ -32,17 +32,31 @@ namespace Doctrine\ORM\Mapping; class DefaultQuoteStrategy extends QuoteStrategy { + /** + * Checks if the given identifier is quoted + * + * @param string $identifier + * @return string + */ public function isQuotedIdentifier($identifier) { return strlen($identifier) > 0 && $identifier[0] === '`'; } + /** + * Gets the uquoted column name. + * + * @param string $identifier + * @return string + */ public function getUnquotedIdentifier($identifier) { return trim($identifier, '`'); } /** + * Gets the (possibly quoted) column name for safe use in an SQL statement. + * * @param string $fieldName * @param ClassMetadata $class * @return string @@ -55,8 +69,7 @@ class DefaultQuoteStrategy extends QuoteStrategy } /** - * Gets the (possibly quoted) primary table name of this class for safe use - * in an SQL statement. + * Gets the (possibly quoted) primary table name for safe use in an SQL statement. * * @param ClassMetadata $class * @return string @@ -93,7 +106,7 @@ class DefaultQuoteStrategy extends QuoteStrategy $quotedColumnNames = array(); foreach ($class->identifier as $fieldName) { - if (isset($this->fieldMappings[$fieldName])) { + if (isset($class->fieldMappings[$fieldName])) { $quotedColumnNames[] = $this->getColumnName($fieldName, $class); continue; @@ -118,8 +131,10 @@ class DefaultQuoteStrategy extends QuoteStrategy } /** - * @param string $columnName - * @param string $counter + * Gets the column alias. + * + * @param string $columnName + * @param integer $counter * @param ClassMetadata $class * @return string */ diff --git a/tests/Doctrine/Tests/ORM/Mapping/QuoteStrategyTest.php b/tests/Doctrine/Tests/ORM/Mapping/QuoteStrategyTest.php index 38bc4de21..e541f890d 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/QuoteStrategyTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/QuoteStrategyTest.php @@ -9,7 +9,7 @@ use Doctrine\ORM\Mapping\ClassMetadata; require_once __DIR__ . '/../../TestInit.php'; /** - * @group DDC-1719 + * @group DDC-1845 */ class QuoteStrategyTest extends \Doctrine\Tests\OrmTestCase { @@ -78,20 +78,19 @@ class QuoteStrategyTest extends \Doctrine\Tests\OrmTestCase public function testJoinTableName() { - $cm = $this->createClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress'); - $cm->mapManyToMany(array( + $cm1 = $this->createClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress'); + $cm2 = $this->createClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress'); + + $cm1->mapManyToMany(array( 'fieldName' => 'user', 'targetEntity' => 'CmsUser', 'inversedBy' => 'users', 'joinTable' => array( - 'name' => '`cmsaddress_cmsuser`' - ) + 'name' => '`cmsaddress_cmsuser`' ) - ); - $this->assertEquals('"cmsaddress_cmsuser"', $this->strategy->getJoinTableName('user', $cm)); + )); - $cm = $this->createClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress'); - $cm->mapManyToMany(array( + $cm2->mapManyToMany(array( 'fieldName' => 'user', 'targetEntity' => 'CmsUser', 'inversedBy' => 'users', @@ -100,7 +99,58 @@ class QuoteStrategyTest extends \Doctrine\Tests\OrmTestCase ) ) ); - $this->assertEquals('cmsaddress_cmsuser', $this->strategy->getJoinTableName('user', $cm)); + $this->assertEquals('"cmsaddress_cmsuser"', $this->strategy->getJoinTableName('user', $cm1)); + $this->assertEquals('cmsaddress_cmsuser', $this->strategy->getJoinTableName('user', $cm2)); + + } + + public function testIdentifierColumnNames() + { + $cm1 = $this->createClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress'); + $cm2 = $this->createClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress'); + + $cm1->mapField(array( + 'id' => true, + 'fieldName' => 'id', + 'columnName' => '`id`', + )); + + $cm2->mapField(array( + 'id' => true, + 'fieldName' => 'id', + 'columnName' => 'id', + )); + + $this->assertEquals(array('"id"'), $this->strategy->getIdentifierColumnNames($cm1)); + $this->assertEquals(array('id'), $this->strategy->getIdentifierColumnNames($cm2)); + } + + + public function testColumnAlias() + { + $i = 0; + $this->assertEquals('columnName0', $this->strategy->getColumnAlias('columnName', $i++)); + $this->assertEquals('column_name1', $this->strategy->getColumnAlias('column_name', $i++)); + $this->assertEquals('COLUMN_NAME2', $this->strategy->getColumnAlias('COLUMN_NAME', $i++)); + $this->assertEquals('COLUMNNAME3', $this->strategy->getColumnAlias('COLUMN-NAME-', $i++)); + } + + public function testQuoteJoinColumnNames() + { + $this->markTestIncomplete(); + + $cm = $this->createClassMetadata('Doctrine\Tests\Models\DDC117\DDC117ArticleDetails'); + + $cm->mapOneToOne(array( + 'id' => true, + 'fieldName' => 'article', + 'targetEntity' => 'Doctrine\Tests\Models\DDC117\DDC117Article', + 'joinColumns' => array(array( + 'name' => '`article`' + )), + )); + + $this->assertEquals(array('"article"'), $this->strategy->getIdentifierColumnNames($cm)); } } \ No newline at end of file From 1bcda5147a890a8f419eb333df69852bd4f6b307 Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Thu, 31 May 2012 18:03:01 -0300 Subject: [PATCH 03/37] inject quote strategy into sql walker --- lib/Doctrine/ORM/Configuration.php | 6 +- lib/Doctrine/ORM/EntityManager.php | 25 +- lib/Doctrine/ORM/Query/SqlWalker.php | 467 +++++++++++++++------------ 3 files changed, 283 insertions(+), 215 deletions(-) diff --git a/lib/Doctrine/ORM/Configuration.php b/lib/Doctrine/ORM/Configuration.php index 015dce5ca..3f37f479f 100644 --- a/lib/Doctrine/ORM/Configuration.php +++ b/lib/Doctrine/ORM/Configuration.php @@ -634,11 +634,11 @@ class Configuration extends \Doctrine\DBAL\Configuration * Set quote strategy class. * * @since 2.4 - * @param string $namingStrategy + * @param string $className */ public function setQuoteStrategyClassName($className) { - $quoteStrategy = 'Doctrine\Mapping\AbstractQuoteStrategy'; + $quoteStrategy = 'Doctrine\ORM\Mapping\AbstractQuoteStrategy'; if ($className !== $quoteStrategy && ! is_subclass_of($className, $quoteStrategy)) { throw new \InvalidArgumentException("Invalid quote strategy class"); @@ -657,6 +657,6 @@ class Configuration extends \Doctrine\DBAL\Configuration { return isset($this->_attributes['quoteStrategyClassName']) ? $this->_attributes['quoteStrategyClassName'] - : 'Doctrine\Mapping\DefaultQuoteStrategy'; + : 'Doctrine\ORM\Mapping\DefaultQuoteStrategy'; } } diff --git a/lib/Doctrine/ORM/EntityManager.php b/lib/Doctrine/ORM/EntityManager.php index d8ef431ab..28ddd5695 100644 --- a/lib/Doctrine/ORM/EntityManager.php +++ b/lib/Doctrine/ORM/EntityManager.php @@ -62,6 +62,13 @@ class EntityManager implements ObjectManager */ private $metadataFactory; + /** + * The quote strategy. + * + * @var \Doctrine\ORM\Mapping\QuoteStrategy. + */ + private $quoteStrategy; + /** * The EntityRepository instances. * @@ -132,9 +139,11 @@ class EntityManager implements ObjectManager $this->config = $config; $this->eventManager = $eventManager; - $metadataFactoryClassName = $config->getClassMetadataFactoryName(); - - $this->metadataFactory = new $metadataFactoryClassName; + $quoteStrategyClassName = $config->getQuoteStrategyClassName(); + $metadataFactoryClassName = $config->getClassMetadataFactoryName(); + + $this->quoteStrategy = new $quoteStrategyClassName($conn->getDatabasePlatform()); + $this->metadataFactory = new $metadataFactoryClassName; $this->metadataFactory->setEntityManager($this); $this->metadataFactory->setCacheDriver($this->config->getMetadataCacheImpl()); @@ -167,6 +176,16 @@ class EntityManager implements ObjectManager return $this->metadataFactory; } + /** + * Gets the quote strategy. + * + * @return \Doctrine\ORM\Mapping\QuoteStrategy + */ + public function getQuoteStrategy() + { + return $this->quoteStrategy; + } + /** * Gets an ExpressionBuilder used for object-oriented construction of query expressions. * diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index 2d034ddcd..920703149 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -47,82 +47,131 @@ class SqlWalker implements TreeWalker /** * @var ResultSetMapping */ - private $_rsm; + private $rsm; - /** Counters for generating unique column aliases, table aliases and parameter indexes. */ - private $_aliasCounter = 0; - private $_tableAliasCounter = 0; - private $_scalarResultCounter = 1; - private $_sqlParamIndex = 0; + /** + * Counters for generating unique column aliases. + * + * @var integer + */ + private $aliasCounter = 0; + + /** + * Counters for generating unique table aliases. + * + * @var integer + */ + private $tableAliasCounter = 0; + + /** + * Counters for generating unique scalar result. + * + * @var integer + */ + private $scalarResultCounter = 1; + + /** + * Counters for generating unique parameter indexes. + * + * @var integer + */ + private $sqlParamIndex = 0; /** * @var ParserResult */ - private $_parserResult; + private $parserResult; /** * @var EntityManager */ - private $_em; + private $em; /** * @var \Doctrine\DBAL\Connection */ - private $_conn; + private $conn; /** * @var AbstractQuery */ - private $_query; + private $query; - private $_tableAliasMap = array(); + /** + * @var array + */ + private $tableAliasMap = array(); - /** Map from result variable names to their SQL column alias names. */ - private $_scalarResultAliasMap = array(); + /** + * Map from result variable names to their SQL column alias names. + * + * @var array + */ + private $scalarResultAliasMap = array(); /** * Map from DQL-Alias + Field-Name to SQL Column Alias * * @var array */ - private $_scalarFields = array(); + private $scalarFields = array(); - /** Map of all components/classes that appear in the DQL query. */ - private $_queryComponents; + /** + * Map of all components/classes that appear in the DQL query. + * + * @var array + */ + private $queryComponents; - /** A list of classes that appear in non-scalar SelectExpressions. */ - private $_selectedClasses = array(); + /** + * A list of classes that appear in non-scalar SelectExpressions. + * + * @var array + */ + private $selectedClasses = array(); /** * The DQL alias of the root class of the currently traversed query. + * + * @var array */ - private $_rootAliases = array(); + private $rootAliases = array(); /** * Flag that indicates whether to generate SQL table aliases in the SQL. * These should only be generated for SELECT queries, not for UPDATE/DELETE. + * + * @var boolean */ - private $_useSqlTableAliases = true; + private $useSqlTableAliases = true; /** * The database platform abstraction. * * @var AbstractPlatform */ - private $_platform; + private $platform; + + /** + * The quote strategy. + * + * @var \Doctrine\ORM\Mapping\QuoteStrategy + */ + private $quoteStrategy; /** * {@inheritDoc} */ public function __construct($query, $parserResult, array $queryComponents) { - $this->_query = $query; - $this->_parserResult = $parserResult; - $this->_queryComponents = $queryComponents; - $this->_rsm = $parserResult->getResultSetMapping(); - $this->_em = $query->getEntityManager(); - $this->_conn = $this->_em->getConnection(); - $this->_platform = $this->_conn->getDatabasePlatform(); + $this->query = $query; + $this->parserResult = $parserResult; + $this->queryComponents = $queryComponents; + $this->rsm = $parserResult->getResultSetMapping(); + $this->em = $query->getEntityManager(); + $this->conn = $this->em->getConnection(); + $this->quoteStrategy = $this->em->getQuoteStrategy(); + $this->platform = $this->conn->getDatabasePlatform(); } /** @@ -132,7 +181,7 @@ class SqlWalker implements TreeWalker */ public function getQuery() { - return $this->_query; + return $this->query; } /** @@ -142,7 +191,7 @@ class SqlWalker implements TreeWalker */ public function getConnection() { - return $this->_conn; + return $this->conn; } /** @@ -152,7 +201,7 @@ class SqlWalker implements TreeWalker */ public function getEntityManager() { - return $this->_em; + return $this->em; } /** @@ -163,7 +212,7 @@ class SqlWalker implements TreeWalker */ public function getQueryComponent($dqlAlias) { - return $this->_queryComponents[$dqlAlias]; + return $this->queryComponents[$dqlAlias]; } /** @@ -175,14 +224,14 @@ class SqlWalker implements TreeWalker { switch (true) { case ($AST instanceof AST\DeleteStatement): - $primaryClass = $this->_em->getClassMetadata($AST->deleteClause->abstractSchemaName); + $primaryClass = $this->em->getClassMetadata($AST->deleteClause->abstractSchemaName); return ($primaryClass->isInheritanceTypeJoined()) ? new Exec\MultiTableDeleteExecutor($AST, $this) : new Exec\SingleTableDeleteUpdateExecutor($AST, $this); case ($AST instanceof AST\UpdateStatement): - $primaryClass = $this->_em->getClassMetadata($AST->updateClause->abstractSchemaName); + $primaryClass = $this->em->getClassMetadata($AST->updateClause->abstractSchemaName); return ($primaryClass->isInheritanceTypeJoined()) ? new Exec\MultiTableUpdateExecutor($AST, $this) @@ -204,11 +253,11 @@ class SqlWalker implements TreeWalker { $tableName .= ($dqlAlias) ? '@[' . $dqlAlias . ']' : ''; - if ( ! isset($this->_tableAliasMap[$tableName])) { - $this->_tableAliasMap[$tableName] = strtolower(substr($tableName, 0, 1)) . $this->_tableAliasCounter++ . '_'; + if ( ! isset($this->tableAliasMap[$tableName])) { + $this->tableAliasMap[$tableName] = strtolower(substr($tableName, 0, 1)) . $this->tableAliasCounter++ . '_'; } - return $this->_tableAliasMap[$tableName]; + return $this->tableAliasMap[$tableName]; } /** @@ -224,7 +273,7 @@ class SqlWalker implements TreeWalker { $tableName .= ($dqlAlias) ? '@[' . $dqlAlias . ']' : ''; - $this->_tableAliasMap[$tableName] = $alias; + $this->tableAliasMap[$tableName] = $alias; return $alias; } @@ -239,8 +288,8 @@ class SqlWalker implements TreeWalker { // 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->platform->getSQLResultCasing( + substr($columnName . $this->aliasCounter++, -$this->platform->getMaxIdentifierLength()) ); } @@ -260,16 +309,16 @@ class SqlWalker implements TreeWalker // INNER JOIN parent class tables foreach ($class->parentClasses as $parentClassName) { - $parentClass = $this->_em->getClassMetadata($parentClassName); + $parentClass = $this->em->getClassMetadata($parentClassName); $tableAlias = $this->getSQLTableAlias($parentClass->getTableName(), $dqlAlias); // If this is a joined association we must use left joins to preserve the correct result. - $sql .= isset($this->_queryComponents[$dqlAlias]['relation']) ? ' LEFT ' : ' INNER '; - $sql .= 'JOIN ' . $parentClass->getQuotedTableName($this->_platform) . ' ' . $tableAlias . ' ON '; + $sql .= isset($this->queryComponents[$dqlAlias]['relation']) ? ' LEFT ' : ' INNER '; + $sql .= 'JOIN ' . $parentClass->getQuotedTableName($this->platform) . ' ' . $tableAlias . ' ON '; $sqlParts = array(); - foreach ($class->getQuotedIdentifierColumnNames($this->_platform) as $columnName) { + foreach ($class->getQuotedIdentifierColumnNames($this->platform) as $columnName) { $sqlParts[] = $baseTableAlias . '.' . $columnName . ' = ' . $tableAlias . '.' . $columnName; } @@ -282,20 +331,20 @@ class SqlWalker implements TreeWalker } // Ignore subclassing inclusion if partial objects is disallowed - if ($this->_query->getHint(Query::HINT_FORCE_PARTIAL_LOAD)) { + if ($this->query->getHint(Query::HINT_FORCE_PARTIAL_LOAD)) { return $sql; } // LEFT JOIN child class tables foreach ($class->subClasses as $subClassName) { - $subClass = $this->_em->getClassMetadata($subClassName); + $subClass = $this->em->getClassMetadata($subClassName); $tableAlias = $this->getSQLTableAlias($subClass->getTableName(), $dqlAlias); - $sql .= ' LEFT JOIN ' . $subClass->getQuotedTableName($this->_platform) . ' ' . $tableAlias . ' ON '; + $sql .= ' LEFT JOIN ' . $subClass->getQuotedTableName($this->platform) . ' ' . $tableAlias . ' ON '; $sqlParts = array(); - foreach ($subClass->getQuotedIdentifierColumnNames($this->_platform) as $columnName) { + foreach ($subClass->getQuotedIdentifierColumnNames($this->platform) as $columnName) { $sqlParts[] = $baseTableAlias . '.' . $columnName . ' = ' . $tableAlias . '.' . $columnName; } @@ -309,16 +358,16 @@ class SqlWalker implements TreeWalker { $sqlParts = array(); - foreach ($this->_selectedClasses as $selectedClass) { + foreach ($this->selectedClasses as $selectedClass) { $dqlAlias = $selectedClass['dqlAlias']; - $qComp = $this->_queryComponents[$dqlAlias]; + $qComp = $this->queryComponents[$dqlAlias]; if ( ! isset($qComp['relation']['orderBy'])) continue; foreach ($qComp['relation']['orderBy'] as $fieldName => $orientation) { - $columnName = $qComp['metadata']->getQuotedColumnName($fieldName, $this->_platform); + $columnName = $qComp['metadata']->getQuotedColumnName($fieldName, $this->platform); $tableName = ($qComp['metadata']->isInheritanceTypeJoined()) - ? $this->_em->getUnitOfWork()->getEntityPersister($qComp['metadata']->name)->getOwningTable($fieldName) + ? $this->em->getUnitOfWork()->getEntityPersister($qComp['metadata']->name)->getOwningTable($fieldName) : $qComp['metadata']->getTableName(); $sqlParts[] = $this->getSQLTableAlias($tableName, $dqlAlias) . '.' . $columnName . ' ' . $orientation; @@ -339,11 +388,11 @@ class SqlWalker implements TreeWalker $sqlParts = array(); foreach ($dqlAliases as $dqlAlias) { - $class = $this->_queryComponents[$dqlAlias]['metadata']; + $class = $this->queryComponents[$dqlAlias]['metadata']; if ( ! $class->isInheritanceTypeSingleTable()) continue; - $conn = $this->_em->getConnection(); + $conn = $this->em->getConnection(); $values = array(); if ($class->discriminatorValue !== null) { // discrimnators can be 0 @@ -351,10 +400,10 @@ class SqlWalker implements TreeWalker } foreach ($class->subClasses as $subclassName) { - $values[] = $conn->quote($this->_em->getClassMetadata($subclassName)->discriminatorValue); + $values[] = $conn->quote($this->em->getClassMetadata($subclassName)->discriminatorValue); } - $sqlParts[] = (($this->_useSqlTableAliases) ? $this->getSQLTableAlias($class->getTableName(), $dqlAlias) . '.' : '') + $sqlParts[] = (($this->useSqlTableAliases) ? $this->getSQLTableAlias($class->getTableName(), $dqlAlias) . '.' : '') . $class->discriminatorColumn['name'] . ' IN (' . implode(', ', $values) . ')'; } @@ -373,7 +422,7 @@ class SqlWalker implements TreeWalker */ private function generateFilterConditionSQL(ClassMetadata $targetEntity, $targetTableAlias) { - if (!$this->_em->hasFilters()) { + if (!$this->em->hasFilters()) { return ''; } @@ -390,7 +439,7 @@ class SqlWalker implements TreeWalker case ClassMetadata::INHERITANCE_TYPE_SINGLE_TABLE: // With STI the table will only be queried once, make sure that the filters // are added to the root entity - $targetEntity = $this->_em->getClassMetadata($targetEntity->rootEntityName); + $targetEntity = $this->em->getClassMetadata($targetEntity->rootEntityName); break; default: //@todo: throw exception? @@ -399,7 +448,7 @@ class SqlWalker implements TreeWalker } $filterClauses = array(); - foreach ($this->_em->getFilters()->getEnabledFilters() as $filter) { + foreach ($this->em->getFilters()->getEnabledFilters() as $filter) { if ('' !== $filterExpr = $filter->addFilterConstraint($targetEntity, $targetTableAlias)) { $filterClauses[] = '(' . $filterExpr . ')'; } @@ -426,22 +475,22 @@ class SqlWalker implements TreeWalker $sql .= ' ORDER BY ' . $orderBySql; } - $sql = $this->_platform->modifyLimitQuery( - $sql, $this->_query->getMaxResults(), $this->_query->getFirstResult() + $sql = $this->platform->modifyLimitQuery( + $sql, $this->query->getMaxResults(), $this->query->getFirstResult() ); - if (($lockMode = $this->_query->getHint(Query::HINT_LOCK_MODE)) !== false) { + if (($lockMode = $this->query->getHint(Query::HINT_LOCK_MODE)) !== false) { switch ($lockMode) { case LockMode::PESSIMISTIC_READ: - $sql .= ' ' . $this->_platform->getReadLockSQL(); + $sql .= ' ' . $this->platform->getReadLockSQL(); break; case LockMode::PESSIMISTIC_WRITE: - $sql .= ' ' . $this->_platform->getWriteLockSQL(); + $sql .= ' ' . $this->platform->getWriteLockSQL(); break; case LockMode::OPTIMISTIC: - foreach ($this->_selectedClasses as $selectedClass) { + foreach ($this->selectedClasses as $selectedClass) { if ( ! $selectedClass['class']->isVersioned) { throw \Doctrine\ORM\OptimisticLockException::lockFailed($selectedClass['class']->name); } @@ -466,7 +515,7 @@ class SqlWalker implements TreeWalker */ public function walkUpdateStatement(AST\UpdateStatement $AST) { - $this->_useSqlTableAliases = false; + $this->useSqlTableAliases = false; return $this->walkUpdateClause($AST->updateClause) . $this->walkWhereClause($AST->whereClause); @@ -480,7 +529,7 @@ class SqlWalker implements TreeWalker */ public function walkDeleteStatement(AST\DeleteStatement $AST) { - $this->_useSqlTableAliases = false; + $this->useSqlTableAliases = false; return $this->walkDeleteClause($AST->deleteClause) . $this->walkWhereClause($AST->whereClause); @@ -495,11 +544,11 @@ class SqlWalker implements TreeWalker */ public function walkEntityIdentificationVariable($identVariable) { - $class = $this->_queryComponents[$identVariable]['metadata']; + $class = $this->queryComponents[$identVariable]['metadata']; $tableAlias = $this->getSQLTableAlias($class->getTableName(), $identVariable); $sqlParts = array(); - foreach ($class->getQuotedIdentifierColumnNames($this->_platform) as $columnName) { + foreach ($class->getQuotedIdentifierColumnNames($this->platform) as $columnName) { $sqlParts[] = $tableAlias . '.' . $columnName; } @@ -515,13 +564,13 @@ class SqlWalker implements TreeWalker */ public function walkIdentificationVariable($identificationVariable, $fieldName = null) { - $class = $this->_queryComponents[$identificationVariable]['metadata']; + $class = $this->queryComponents[$identificationVariable]['metadata']; if ( $fieldName !== null && $class->isInheritanceTypeJoined() && isset($class->fieldMappings[$fieldName]['inherited']) ) { - $class = $this->_em->getClassMetadata($class->fieldMappings[$fieldName]['inherited']); + $class = $this->em->getClassMetadata($class->fieldMappings[$fieldName]['inherited']); } return $this->getSQLTableAlias($class->getTableName(), $identificationVariable); @@ -541,13 +590,13 @@ class SqlWalker implements TreeWalker case AST\PathExpression::TYPE_STATE_FIELD: $fieldName = $pathExpr->field; $dqlAlias = $pathExpr->identificationVariable; - $class = $this->_queryComponents[$dqlAlias]['metadata']; + $class = $this->queryComponents[$dqlAlias]['metadata']; - if ($this->_useSqlTableAliases) { + if ($this->useSqlTableAliases) { $sql .= $this->walkIdentificationVariable($dqlAlias, $fieldName) . '.'; } - $sql .= $class->getQuotedColumnName($fieldName, $this->_platform); + $sql .= $class->getQuotedColumnName($fieldName, $this->platform); break; case AST\PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION: @@ -555,10 +604,10 @@ class SqlWalker implements TreeWalker // Just use the foreign key, i.e. u.group_id $fieldName = $pathExpr->field; $dqlAlias = $pathExpr->identificationVariable; - $class = $this->_queryComponents[$dqlAlias]['metadata']; + $class = $this->queryComponents[$dqlAlias]['metadata']; if (isset($class->associationMappings[$fieldName]['inherited'])) { - $class = $this->_em->getClassMetadata($class->associationMappings[$fieldName]['inherited']); + $class = $this->em->getClassMetadata($class->associationMappings[$fieldName]['inherited']); } $assoc = $class->associationMappings[$fieldName]; @@ -572,7 +621,7 @@ class SqlWalker implements TreeWalker throw QueryException::associationPathCompositeKeyNotSupported(); } - if ($this->_useSqlTableAliases) { + if ($this->useSqlTableAliases) { $sql .= $this->getSQLTableAlias($class->getTableName(), $dqlAlias) . '.'; } @@ -597,44 +646,44 @@ class SqlWalker implements TreeWalker $sql = 'SELECT ' . (($selectClause->isDistinct) ? 'DISTINCT ' : ''); $sqlSelectExpressions = array_filter(array_map(array($this, 'walkSelectExpression'), $selectClause->selectExpressions)); - if ($this->_query->getHint(Query::HINT_INTERNAL_ITERATION) == true && $selectClause->isDistinct) { - $this->_query->setHint(self::HINT_DISTINCT, true); + if ($this->query->getHint(Query::HINT_INTERNAL_ITERATION) == true && $selectClause->isDistinct) { + $this->query->setHint(self::HINT_DISTINCT, true); } - $addMetaColumns = ! $this->_query->getHint(Query::HINT_FORCE_PARTIAL_LOAD) && - $this->_query->getHydrationMode() == Query::HYDRATE_OBJECT + $addMetaColumns = ! $this->query->getHint(Query::HINT_FORCE_PARTIAL_LOAD) && + $this->query->getHydrationMode() == Query::HYDRATE_OBJECT || - $this->_query->getHydrationMode() != Query::HYDRATE_OBJECT && - $this->_query->getHint(Query::HINT_INCLUDE_META_COLUMNS); + $this->query->getHydrationMode() != Query::HYDRATE_OBJECT && + $this->query->getHint(Query::HINT_INCLUDE_META_COLUMNS); - foreach ($this->_selectedClasses as $selectedClass) { + foreach ($this->selectedClasses as $selectedClass) { $class = $selectedClass['class']; $dqlAlias = $selectedClass['dqlAlias']; $resultAlias = $selectedClass['resultAlias']; // Register as entity or joined entity result - if ($this->_queryComponents[$dqlAlias]['relation'] === null) { - $this->_rsm->addEntityResult($class->name, $dqlAlias, $resultAlias); + if ($this->queryComponents[$dqlAlias]['relation'] === null) { + $this->rsm->addEntityResult($class->name, $dqlAlias, $resultAlias); } else { - $this->_rsm->addJoinedEntityResult( + $this->rsm->addJoinedEntityResult( $class->name, $dqlAlias, - $this->_queryComponents[$dqlAlias]['parent'], - $this->_queryComponents[$dqlAlias]['relation']['fieldName'] + $this->queryComponents[$dqlAlias]['parent'], + $this->queryComponents[$dqlAlias]['relation']['fieldName'] ); } if ($class->isInheritanceTypeSingleTable() || $class->isInheritanceTypeJoined()) { // Add discriminator columns to SQL - $rootClass = $this->_em->getClassMetadata($class->rootEntityName); + $rootClass = $this->em->getClassMetadata($class->rootEntityName); $tblAlias = $this->getSQLTableAlias($rootClass->getTableName(), $dqlAlias); $discrColumn = $rootClass->discriminatorColumn; $columnAlias = $this->getSQLColumnAlias($discrColumn['name']); $sqlSelectExpressions[] = $tblAlias . '.' . $discrColumn['name'] . ' AS ' . $columnAlias; - $this->_rsm->setDiscriminatorColumn($dqlAlias, $columnAlias); - $this->_rsm->addMetaResult($dqlAlias, $columnAlias, $discrColumn['fieldName']); + $this->rsm->setDiscriminatorColumn($dqlAlias, $columnAlias); + $this->rsm->addMetaResult($dqlAlias, $columnAlias, $discrColumn['fieldName']); } // Add foreign key columns to SQL, if necessary @@ -650,7 +699,7 @@ class SqlWalker implements TreeWalker continue; } - $owningClass = (isset($assoc['inherited'])) ? $this->_em->getClassMetadata($assoc['inherited']) : $class; + $owningClass = (isset($assoc['inherited'])) ? $this->em->getClassMetadata($assoc['inherited']) : $class; $sqlTableAlias = $this->getSQLTableAlias($owningClass->getTableName(), $dqlAlias); foreach ($assoc['targetToSourceKeyColumns'] as $srcColumn) { @@ -658,7 +707,7 @@ class SqlWalker implements TreeWalker $sqlSelectExpressions[] = $sqlTableAlias . '.' . $srcColumn . ' AS ' . $columnAlias; - $this->_rsm->addMetaResult($dqlAlias, $columnAlias, $srcColumn, (isset($assoc['id']) && $assoc['id'] === true)); + $this->rsm->addMetaResult($dqlAlias, $columnAlias, $srcColumn, (isset($assoc['id']) && $assoc['id'] === true)); } } @@ -669,7 +718,7 @@ class SqlWalker implements TreeWalker // Add foreign key columns of subclasses foreach ($class->subClasses as $subClassName) { - $subClass = $this->_em->getClassMetadata($subClassName); + $subClass = $this->em->getClassMetadata($subClassName); $sqlTableAlias = $this->getSQLTableAlias($subClass->getTableName(), $dqlAlias); foreach ($subClass->associationMappings as $assoc) { @@ -683,7 +732,7 @@ class SqlWalker implements TreeWalker $sqlSelectExpressions[] = $sqlTableAlias . '.' . $srcColumn . ' AS ' . $columnAlias; - $this->_rsm->addMetaResult($dqlAlias, $columnAlias, $srcColumn); + $this->rsm->addMetaResult($dqlAlias, $columnAlias, $srcColumn); } } } @@ -715,17 +764,17 @@ class SqlWalker implements TreeWalker $alias = $identificationVariableDecl->indexBy->simpleStateFieldPathExpression->identificationVariable; $field = $identificationVariableDecl->indexBy->simpleStateFieldPathExpression->field; - if (isset($this->_scalarFields[$alias][$field])) { - $this->_rsm->addIndexByScalar($this->_scalarFields[$alias][$field]); + if (isset($this->scalarFields[$alias][$field])) { + $this->rsm->addIndexByScalar($this->scalarFields[$alias][$field]); } else { - $this->_rsm->addIndexBy( + $this->rsm->addIndexBy( $identificationVariableDecl->indexBy->simpleStateFieldPathExpression->identificationVariable, $identificationVariableDecl->indexBy->simpleStateFieldPathExpression->field ); } } - $sqlParts[] = $this->_platform->appendLockHint($sql, $this->_query->getHint(Query::HINT_LOCK_MODE)); + $sqlParts[] = $this->platform->appendLockHint($sql, $this->query->getHint(Query::HINT_LOCK_MODE)); } return ' FROM ' . implode(', ', $sqlParts); @@ -738,12 +787,12 @@ class SqlWalker implements TreeWalker */ public function walkRangeVariableDeclaration($rangeVariableDeclaration) { - $class = $this->_em->getClassMetadata($rangeVariableDeclaration->abstractSchemaName); + $class = $this->em->getClassMetadata($rangeVariableDeclaration->abstractSchemaName); $dqlAlias = $rangeVariableDeclaration->aliasIdentificationVariable; - $this->_rootAliases[] = $dqlAlias; + $this->rootAliases[] = $dqlAlias; - $sql = $class->getQuotedTableName($this->_platform) . ' ' + $sql = $class->getQuotedTableName($this->platform) . ' ' . $this->getSQLTableAlias($class->getTableName(), $dqlAlias); if ($class->isInheritanceTypeJoined()) { @@ -766,10 +815,10 @@ class SqlWalker implements TreeWalker $joinedDqlAlias = $joinAssociationDeclaration->aliasIdentificationVariable; $indexBy = $joinAssociationDeclaration->indexBy; - $relation = $this->_queryComponents[$joinedDqlAlias]['relation']; - $targetClass = $this->_em->getClassMetadata($relation['targetEntity']); - $sourceClass = $this->_em->getClassMetadata($relation['sourceEntity']); - $targetTableName = $targetClass->getQuotedTableName($this->_platform); + $relation = $this->queryComponents[$joinedDqlAlias]['relation']; + $targetClass = $this->em->getClassMetadata($relation['targetEntity']); + $sourceClass = $this->em->getClassMetadata($relation['sourceEntity']); + $targetTableName = $targetClass->getQuotedTableName($this->platform); $targetTableAlias = $this->getSQLTableAlias($targetClass->getTableName(), $joinedDqlAlias); $sourceTableAlias = $this->getSQLTableAlias($sourceClass->getTableName(), $associationPathExpression->identificationVariable); @@ -777,7 +826,7 @@ class SqlWalker implements TreeWalker // Ensure we got the owning side, since it has all mapping info $assoc = ( ! $relation['isOwningSide']) ? $targetClass->associationMappings[$relation['mappedBy']] : $relation; - if ($this->_query->getHint(Query::HINT_INTERNAL_ITERATION) == true && (!$this->_query->getHint(self::HINT_DISTINCT) || isset($this->_selectedClasses[$joinedDqlAlias]))) { + if ($this->query->getHint(Query::HINT_INTERNAL_ITERATION) == true && (!$this->query->getHint(self::HINT_DISTINCT) || isset($this->selectedClasses[$joinedDqlAlias]))) { if ($relation['type'] == ClassMetadata::ONE_TO_MANY || $relation['type'] == ClassMetadata::MANY_TO_MANY) { throw QueryException::iterateWithFetchJoinNotAllowed($assoc); } @@ -794,7 +843,7 @@ class SqlWalker implements TreeWalker if ($relation['isOwningSide']) { $quotedTargetColumn = ($targetClass->containsForeignIdentifier && !isset($targetClass->fieldNames[$targetColumn])) ? $targetColumn // Join columns cannot be quoted. - : $targetClass->getQuotedColumnName($targetClass->fieldNames[$targetColumn], $this->_platform); + : $targetClass->getQuotedColumnName($targetClass->fieldNames[$targetColumn], $this->platform); $conditions[] = $sourceTableAlias . '.' . $sourceColumn . ' = ' . $targetTableAlias . '.' . $quotedTargetColumn; @@ -803,7 +852,7 @@ class SqlWalker implements TreeWalker $quotedTargetColumn = ($sourceClass->containsForeignIdentifier && !isset($sourceClass->fieldNames[$targetColumn])) ? $targetColumn // Join columns cannot be quoted. - : $sourceClass->getQuotedColumnName($sourceClass->fieldNames[$targetColumn], $this->_platform); + : $sourceClass->getQuotedColumnName($sourceClass->fieldNames[$targetColumn], $this->platform); $conditions[] = $sourceTableAlias . '.' . $quotedTargetColumn . ' = ' . $targetTableAlias . '.' . $sourceColumn; } @@ -829,7 +878,7 @@ class SqlWalker implements TreeWalker // Join relation table $joinTable = $assoc['joinTable']; $joinTableAlias = $this->getSQLTableAlias($joinTable['name'], $joinedDqlAlias); - $joinTableName = $sourceClass->getQuotedJoinTableName($assoc, $this->_platform); + $joinTableName = $sourceClass->getQuotedJoinTableName($assoc, $this->platform); $conditions = array(); $relationColumns = ($relation['isOwningSide']) @@ -839,7 +888,7 @@ class SqlWalker implements TreeWalker foreach ($relationColumns as $relationColumn => $sourceColumn) { $quotedTargetColumn = ($sourceClass->containsForeignIdentifier && !isset($sourceClass->fieldNames[$sourceColumn])) ? $sourceColumn // Join columns cannot be quoted. - : $sourceClass->getQuotedColumnName($sourceClass->fieldNames[$sourceColumn], $this->_platform); + : $sourceClass->getQuotedColumnName($sourceClass->fieldNames[$sourceColumn], $this->platform); $conditions[] = $sourceTableAlias . '.' . $quotedTargetColumn . ' = ' . $joinTableAlias . '.' . $relationColumn; } @@ -857,7 +906,7 @@ class SqlWalker implements TreeWalker foreach ($relationColumns as $relationColumn => $targetColumn) { $quotedTargetColumn = ($targetClass->containsForeignIdentifier && !isset($targetClass->fieldNames[$targetColumn])) ? $targetColumn // Join columns cannot be quoted. - : $targetClass->getQuotedColumnName($targetClass->fieldNames[$targetColumn], $this->_platform); + : $targetClass->getQuotedColumnName($targetClass->fieldNames[$targetColumn], $this->platform); $conditions[] = $targetTableAlias . '.' . $quotedTargetColumn . ' = ' . $joinTableAlias . '.' . $relationColumn; } @@ -888,12 +937,12 @@ class SqlWalker implements TreeWalker // Apply the indexes if ($indexBy) { // For Many-To-One or One-To-One associations this obviously makes no sense, but is ignored silently. - $this->_rsm->addIndexBy( + $this->rsm->addIndexBy( $indexBy->simpleStateFieldPathExpression->identificationVariable, $indexBy->simpleStateFieldPathExpression->field ); } else if (isset($relation['indexBy'])) { - $this->_rsm->addIndexBy($joinedDqlAlias, $relation['indexBy']); + $this->rsm->addIndexBy($joinedDqlAlias, $relation['indexBy']); } return $sql; @@ -937,7 +986,7 @@ class SqlWalker implements TreeWalker $expr = $orderByItem->expression; $sql = ($expr instanceof AST\Node) ? $expr->dispatch($this) - : $this->walkResultVariable($this->_queryComponents[$expr]['token']['value']); + : $this->walkResultVariable($this->queryComponents[$expr]['token']['value']); return $sql . ' ' . strtoupper($orderByItem->type); } @@ -983,7 +1032,7 @@ class SqlWalker implements TreeWalker $sql .= ' AND (' . $this->walkConditionalExpression($condExpr) . ')'; } break; - } + } return $sql; } @@ -1044,11 +1093,11 @@ class SqlWalker implements TreeWalker public function walkNullIfExpression($nullIfExpression) { $firstExpression = is_string($nullIfExpression->firstExpression) - ? $this->_conn->quote($nullIfExpression->firstExpression) + ? $this->conn->quote($nullIfExpression->firstExpression) : $this->walkSimpleArithmeticExpression($nullIfExpression->firstExpression); $secondExpression = is_string($nullIfExpression->secondExpression) - ? $this->_conn->quote($nullIfExpression->secondExpression) + ? $this->conn->quote($nullIfExpression->secondExpression) : $this->walkSimpleArithmeticExpression($nullIfExpression->secondExpression); return 'NULLIF(' . $firstExpression . ', ' . $secondExpression . ')'; @@ -1114,16 +1163,16 @@ class SqlWalker implements TreeWalker $fieldName = $expr->field; $dqlAlias = $expr->identificationVariable; - $qComp = $this->_queryComponents[$dqlAlias]; + $qComp = $this->queryComponents[$dqlAlias]; $class = $qComp['metadata']; $resultAlias = $selectExpression->fieldIdentificationVariable ?: $fieldName; $tableName = ($class->isInheritanceTypeJoined()) - ? $this->_em->getUnitOfWork()->getEntityPersister($class->name)->getOwningTable($fieldName) + ? $this->em->getUnitOfWork()->getEntityPersister($class->name)->getOwningTable($fieldName) : $class->getTableName(); $sqlTableAlias = $this->getSQLTableAlias($tableName, $dqlAlias); - $columnName = $class->getQuotedColumnName($fieldName, $this->_platform); + $columnName = $class->getQuotedColumnName($fieldName, $this->platform); $columnAlias = $this->getSQLColumnAlias($class->fieldMappings[$fieldName]['columnName']); $col = $sqlTableAlias . '.' . $columnName; @@ -1132,16 +1181,16 @@ class SqlWalker implements TreeWalker if (isset($class->fieldMappings[$fieldName]['requireSQLConversion'])) { $type = Type::getType($fieldType); - $col = $type->convertToPHPValueSQL($col, $this->_conn->getDatabasePlatform()); + $col = $type->convertToPHPValueSQL($col, $this->conn->getDatabasePlatform()); } $sql .= $col . ' AS ' . $columnAlias; - $this->_scalarResultAliasMap[$resultAlias] = $columnAlias; + $this->scalarResultAliasMap[$resultAlias] = $columnAlias; if ( ! $hidden) { - $this->_rsm->addScalarResult($columnAlias, $resultAlias, $fieldType); - $this->_scalarFields[$dqlAlias][$fieldName] = $columnAlias; + $this->rsm->addScalarResult($columnAlias, $resultAlias, $fieldType); + $this->scalarFields[$dqlAlias][$fieldName] = $columnAlias; } break; @@ -1157,29 +1206,29 @@ class SqlWalker implements TreeWalker case ($expr instanceof AST\GeneralCaseExpression): case ($expr instanceof AST\SimpleCaseExpression): $columnAlias = $this->getSQLColumnAlias('sclr'); - $resultAlias = $selectExpression->fieldIdentificationVariable ?: $this->_scalarResultCounter++; + $resultAlias = $selectExpression->fieldIdentificationVariable ?: $this->scalarResultCounter++; $sql .= $expr->dispatch($this) . ' AS ' . $columnAlias; - $this->_scalarResultAliasMap[$resultAlias] = $columnAlias; + $this->scalarResultAliasMap[$resultAlias] = $columnAlias; if ( ! $hidden) { // We cannot resolve field type here; assume 'string'. - $this->_rsm->addScalarResult($columnAlias, $resultAlias, 'string'); + $this->rsm->addScalarResult($columnAlias, $resultAlias, 'string'); } break; case ($expr instanceof AST\Subselect): $columnAlias = $this->getSQLColumnAlias('sclr'); - $resultAlias = $selectExpression->fieldIdentificationVariable ?: $this->_scalarResultCounter++; + $resultAlias = $selectExpression->fieldIdentificationVariable ?: $this->scalarResultCounter++; $sql .= '(' . $this->walkSubselect($expr) . ') AS ' . $columnAlias; - $this->_scalarResultAliasMap[$resultAlias] = $columnAlias; + $this->scalarResultAliasMap[$resultAlias] = $columnAlias; if ( ! $hidden) { // We cannot resolve field type here; assume 'string'. - $this->_rsm->addScalarResult($columnAlias, $resultAlias, 'string'); + $this->rsm->addScalarResult($columnAlias, $resultAlias, 'string'); } break; @@ -1193,12 +1242,12 @@ class SqlWalker implements TreeWalker $partialFieldSet = array(); } - $queryComp = $this->_queryComponents[$dqlAlias]; + $queryComp = $this->queryComponents[$dqlAlias]; $class = $queryComp['metadata']; $resultAlias = $selectExpression->fieldIdentificationVariable ?: null; - if ( ! isset($this->_selectedClasses[$dqlAlias])) { - $this->_selectedClasses[$dqlAlias] = array( + if ( ! isset($this->selectedClasses[$dqlAlias])) { + $this->selectedClasses[$dqlAlias] = array( 'class' => $class, 'dqlAlias' => $dqlAlias, 'resultAlias' => $resultAlias @@ -1214,34 +1263,34 @@ class SqlWalker implements TreeWalker } $tableName = (isset($mapping['inherited'])) - ? $this->_em->getClassMetadata($mapping['inherited'])->getTableName() + ? $this->em->getClassMetadata($mapping['inherited'])->getTableName() : $class->getTableName(); $sqlTableAlias = $this->getSQLTableAlias($tableName, $dqlAlias); $columnAlias = $this->getSQLColumnAlias($mapping['columnName']); - $quotedColumnName = $class->getQuotedColumnName($fieldName, $this->_platform); + $quotedColumnName = $class->getQuotedColumnName($fieldName, $this->platform); $col = $sqlTableAlias . '.' . $quotedColumnName; if (isset($class->fieldMappings[$fieldName]['requireSQLConversion'])) { $type = Type::getType($class->getTypeOfField($fieldName)); - $col = $type->convertToPHPValueSQL($col, $this->_platform); + $col = $type->convertToPHPValueSQL($col, $this->platform); } $sqlParts[] = $col . ' AS '. $columnAlias; - $this->_scalarResultAliasMap[$resultAlias][] = $columnAlias; + $this->scalarResultAliasMap[$resultAlias][] = $columnAlias; - $this->_rsm->addFieldResult($dqlAlias, $columnAlias, $fieldName, $class->name); + $this->rsm->addFieldResult($dqlAlias, $columnAlias, $fieldName, $class->name); } // Add any additional fields of subclasses (excluding inherited fields) // 1) on Single Table Inheritance: always, since its marginal overhead // 2) on Class Table Inheritance only if partial objects are disallowed, // since it requires outer joining subtables. - if ($class->isInheritanceTypeSingleTable() || ! $this->_query->getHint(Query::HINT_FORCE_PARTIAL_LOAD)) { + if ($class->isInheritanceTypeSingleTable() || ! $this->query->getHint(Query::HINT_FORCE_PARTIAL_LOAD)) { foreach ($class->subClasses as $subClassName) { - $subClass = $this->_em->getClassMetadata($subClassName); + $subClass = $this->em->getClassMetadata($subClassName); $sqlTableAlias = $this->getSQLTableAlias($subClass->getTableName(), $dqlAlias); foreach ($subClass->fieldMappings as $fieldName => $mapping) { @@ -1250,20 +1299,20 @@ class SqlWalker implements TreeWalker } $columnAlias = $this->getSQLColumnAlias($mapping['columnName']); - $quotedColumnName = $subClass->getQuotedColumnName($fieldName, $this->_platform); + $quotedColumnName = $subClass->getQuotedColumnName($fieldName, $this->platform); $col = $sqlTableAlias . '.' . $quotedColumnName; if (isset($subClass->fieldMappings[$fieldName]['requireSQLConversion'])) { $type = Type::getType($subClass->getTypeOfField($fieldName)); - $col = $type->convertToPHPValueSQL($col, $this->_platform); + $col = $type->convertToPHPValueSQL($col, $this->platform); } $sqlParts[] = $col . ' AS ' . $columnAlias; - $this->_scalarResultAliasMap[$resultAlias][] = $columnAlias; + $this->scalarResultAliasMap[$resultAlias][] = $columnAlias; - $this->_rsm->addFieldResult($dqlAlias, $columnAlias, $fieldName, $subClassName); + $this->rsm->addFieldResult($dqlAlias, $columnAlias, $fieldName, $subClassName); } } } @@ -1293,11 +1342,11 @@ class SqlWalker implements TreeWalker */ public function walkSubselect($subselect) { - $useAliasesBefore = $this->_useSqlTableAliases; - $rootAliasesBefore = $this->_rootAliases; + $useAliasesBefore = $this->useSqlTableAliases; + $rootAliasesBefore = $this->rootAliases; - $this->_rootAliases = array(); // reset the rootAliases for the subselect - $this->_useSqlTableAliases = true; + $this->rootAliases = array(); // reset the rootAliases for the subselect + $this->useSqlTableAliases = true; $sql = $this->walkSimpleSelectClause($subselect->simpleSelectClause); $sql .= $this->walkSubselectFromClause($subselect->subselectFromClause); @@ -1307,8 +1356,8 @@ class SqlWalker implements TreeWalker $sql .= $subselect->havingClause ? $this->walkHavingClause($subselect->havingClause) : ''; $sql .= $subselect->orderByClause ? $this->walkOrderByClause($subselect->orderByClause) : ''; - $this->_rootAliases = $rootAliasesBefore; // put the main aliases back - $this->_useSqlTableAliases = $useAliasesBefore; + $this->rootAliases = $rootAliasesBefore; // put the main aliases back + $this->useSqlTableAliases = $useAliasesBefore; return $sql; } @@ -1331,7 +1380,7 @@ class SqlWalker implements TreeWalker $sql .= $this->walkJoin($join); } - $sqlParts[] = $this->_platform->appendLockHint($sql, $this->_query->getHint(Query::HINT_LOCK_MODE)); + $sqlParts[] = $this->platform->appendLockHint($sql, $this->query->getHint(Query::HINT_LOCK_MODE)); } return ' FROM ' . implode(', ', $sqlParts); @@ -1366,16 +1415,16 @@ class SqlWalker implements TreeWalker break; case ($expr instanceof AST\AggregateExpression): - $alias = $simpleSelectExpression->fieldIdentificationVariable ?: $this->_scalarResultCounter++; + $alias = $simpleSelectExpression->fieldIdentificationVariable ?: $this->scalarResultCounter++; $sql .= $this->walkAggregateExpression($expr) . ' AS dctrn__' . $alias; break; case ($expr instanceof AST\Subselect): - $alias = $simpleSelectExpression->fieldIdentificationVariable ?: $this->_scalarResultCounter++; + $alias = $simpleSelectExpression->fieldIdentificationVariable ?: $this->scalarResultCounter++; - $columnAlias = 'sclr' . $this->_aliasCounter++; - $this->_scalarResultAliasMap[$alias] = $columnAlias; + $columnAlias = 'sclr' . $this->aliasCounter++; + $this->scalarResultAliasMap[$alias] = $columnAlias; $sql .= '(' . $this->walkSubselect($expr) . ') AS ' . $columnAlias; break; @@ -1390,10 +1439,10 @@ class SqlWalker implements TreeWalker case ($expr instanceof AST\CoalesceExpression): case ($expr instanceof AST\GeneralCaseExpression): case ($expr instanceof AST\SimpleCaseExpression): - $alias = $simpleSelectExpression->fieldIdentificationVariable ?: $this->_scalarResultCounter++; + $alias = $simpleSelectExpression->fieldIdentificationVariable ?: $this->scalarResultCounter++; $columnAlias = $this->getSQLColumnAlias('sclr'); - $this->_scalarResultAliasMap[$alias] = $columnAlias; + $this->scalarResultAliasMap[$alias] = $columnAlias; $sql .= $expr->dispatch($this) . ' AS ' . $columnAlias; break; @@ -1449,21 +1498,21 @@ class SqlWalker implements TreeWalker } // ResultVariable - if (isset($this->_queryComponents[$groupByItem]['resultVariable'])) { + if (isset($this->queryComponents[$groupByItem]['resultVariable'])) { return $this->walkResultVariable($groupByItem); } // IdentificationVariable $sqlParts = array(); - foreach ($this->_queryComponents[$groupByItem]['metadata']->fieldNames as $field) { + foreach ($this->queryComponents[$groupByItem]['metadata']->fieldNames as $field) { $item = new AST\PathExpression(AST\PathExpression::TYPE_STATE_FIELD, $groupByItem, $field); $item->type = AST\PathExpression::TYPE_STATE_FIELD; $sqlParts[] = $this->walkPathExpression($item); } - foreach ($this->_queryComponents[$groupByItem]['metadata']->associationMappings as $mapping) { + foreach ($this->queryComponents[$groupByItem]['metadata']->associationMappings as $mapping) { if ($mapping['isOwningSide'] && $mapping['type'] & ClassMetadataInfo::TO_ONE) { $item = new AST\PathExpression(AST\PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION, $groupByItem, $mapping['fieldName']); $item->type = AST\PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION; @@ -1483,12 +1532,12 @@ class SqlWalker implements TreeWalker */ public function walkDeleteClause(AST\DeleteClause $deleteClause) { - $class = $this->_em->getClassMetadata($deleteClause->abstractSchemaName); + $class = $this->em->getClassMetadata($deleteClause->abstractSchemaName); $tableName = $class->getTableName(); - $sql = 'DELETE FROM ' . $class->getQuotedTableName($this->_platform); + $sql = 'DELETE FROM ' . $class->getQuotedTableName($this->platform); $this->setSQLTableAlias($tableName, $tableName, $deleteClause->aliasIdentificationVariable); - $this->_rootAliases[] = $deleteClause->aliasIdentificationVariable; + $this->rootAliases[] = $deleteClause->aliasIdentificationVariable; return $sql; } @@ -1501,12 +1550,12 @@ class SqlWalker implements TreeWalker */ public function walkUpdateClause($updateClause) { - $class = $this->_em->getClassMetadata($updateClause->abstractSchemaName); + $class = $this->em->getClassMetadata($updateClause->abstractSchemaName); $tableName = $class->getTableName(); - $sql = 'UPDATE ' . $class->getQuotedTableName($this->_platform); + $sql = 'UPDATE ' . $class->getQuotedTableName($this->platform); $this->setSQLTableAlias($tableName, $tableName, $updateClause->aliasIdentificationVariable); - $this->_rootAliases[] = $updateClause->aliasIdentificationVariable; + $this->rootAliases[] = $updateClause->aliasIdentificationVariable; $sql .= ' SET ' . implode(', ', array_map(array($this, 'walkUpdateItem'), $updateClause->updateItems)); @@ -1521,8 +1570,8 @@ class SqlWalker implements TreeWalker */ public function walkUpdateItem($updateItem) { - $useTableAliasesBefore = $this->_useSqlTableAliases; - $this->_useSqlTableAliases = false; + $useTableAliasesBefore = $this->useSqlTableAliases; + $this->useSqlTableAliases = false; $sql = $this->walkPathExpression($updateItem->pathExpression) . ' = '; $newValue = $updateItem->newValue; @@ -1537,11 +1586,11 @@ class SqlWalker implements TreeWalker break; default: - $sql .= $this->_conn->quote($newValue); + $sql .= $this->conn->quote($newValue); break; } - $this->_useSqlTableAliases = $useTableAliasesBefore; + $this->useSqlTableAliases = $useTableAliasesBefore; return $sql; } @@ -1556,12 +1605,12 @@ class SqlWalker implements TreeWalker public function walkWhereClause($whereClause) { $condSql = null !== $whereClause ? $this->walkConditionalExpression($whereClause->conditionalExpression) : ''; - $discrSql = $this->_generateDiscriminatorColumnConditionSql($this->_rootAliases); + $discrSql = $this->_generateDiscriminatorColumnConditionSql($this->rootAliases); - if ($this->_em->hasFilters()) { + if ($this->em->hasFilters()) { $filterClauses = array(); - foreach ($this->_rootAliases as $dqlAlias) { - $class = $this->_queryComponents[$dqlAlias]['metadata']; + foreach ($this->rootAliases as $dqlAlias) { + $class = $this->queryComponents[$dqlAlias]['metadata']; $tableAlias = $this->getSQLTableAlias($class->table['name'], $dqlAlias); if ($filterExpr = $this->generateFilterConditionSQL($class, $tableAlias)) { @@ -1689,7 +1738,7 @@ class SqlWalker implements TreeWalker $fieldName = $collPathExpr->field; $dqlAlias = $collPathExpr->identificationVariable; - $class = $this->_queryComponents[$dqlAlias]['metadata']; + $class = $this->queryComponents[$dqlAlias]['metadata']; switch (true) { // InputParameter @@ -1710,24 +1759,24 @@ class SqlWalker implements TreeWalker $assoc = $class->associationMappings[$fieldName]; if ($assoc['type'] == ClassMetadata::ONE_TO_MANY) { - $targetClass = $this->_em->getClassMetadata($assoc['targetEntity']); + $targetClass = $this->em->getClassMetadata($assoc['targetEntity']); $targetTableAlias = $this->getSQLTableAlias($targetClass->getTableName()); $sourceTableAlias = $this->getSQLTableAlias($class->getTableName(), $dqlAlias); - $sql .= $targetClass->getQuotedTableName($this->_platform) . ' ' . $targetTableAlias . ' WHERE '; + $sql .= $targetClass->getQuotedTableName($this->platform) . ' ' . $targetTableAlias . ' WHERE '; $owningAssoc = $targetClass->associationMappings[$assoc['mappedBy']]; $sqlParts = array(); foreach ($owningAssoc['targetToSourceKeyColumns'] as $targetColumn => $sourceColumn) { - $targetColumn = $class->getQuotedColumnName($class->fieldNames[$targetColumn], $this->_platform); + $targetColumn = $class->getQuotedColumnName($class->fieldNames[$targetColumn], $this->platform); $sqlParts[] = $sourceTableAlias . '.' . $targetColumn . ' = ' . $targetTableAlias . '.' . $sourceColumn; } - foreach ($targetClass->getQuotedIdentifierColumnNames($this->_platform) as $targetColumnName) { + foreach ($targetClass->getQuotedIdentifierColumnNames($this->platform) as $targetColumnName) { if (isset($dqlParamKey)) { - $this->_parserResult->addParameterMapping($dqlParamKey, $this->_sqlParamIndex++); + $this->parserResult->addParameterMapping($dqlParamKey, $this->sqlParamIndex++); } $sqlParts[] = $targetTableAlias . '.' . $targetColumnName . ' = ' . $entitySql; @@ -1735,7 +1784,7 @@ class SqlWalker implements TreeWalker $sql .= implode(' AND ', $sqlParts); } else { // many-to-many - $targetClass = $this->_em->getClassMetadata($assoc['targetEntity']); + $targetClass = $this->em->getClassMetadata($assoc['targetEntity']); $owningAssoc = $assoc['isOwningSide'] ? $assoc : $targetClass->associationMappings[$assoc['mappedBy']]; $joinTable = $owningAssoc['joinTable']; @@ -1746,8 +1795,8 @@ class SqlWalker implements TreeWalker $sourceTableAlias = $this->getSQLTableAlias($class->getTableName(), $dqlAlias); // join to target table - $sql .= $targetClass->getQuotedJoinTableName($owningAssoc, $this->_platform) . ' ' . $joinTableAlias - . ' INNER JOIN ' . $targetClass->getQuotedTableName($this->_platform) . ' ' . $targetTableAlias . ' ON '; + $sql .= $targetClass->getQuotedJoinTableName($owningAssoc, $this->platform) . ' ' . $joinTableAlias + . ' INNER JOIN ' . $targetClass->getQuotedTableName($this->platform) . ' ' . $targetTableAlias . ' ON '; // join conditions $joinColumns = $assoc['isOwningSide'] ? $joinTable['inverseJoinColumns'] : $joinTable['joinColumns']; @@ -1756,7 +1805,7 @@ class SqlWalker implements TreeWalker foreach ($joinColumns as $joinColumn) { $targetColumn = $targetClass->getQuotedColumnName( $targetClass->fieldNames[$joinColumn['referencedColumnName']], - $this->_platform + $this->platform ); $joinSqlParts[] = $joinTableAlias . '.' . $joinColumn['name'] . ' = ' . $targetTableAlias . '.' . $targetColumn; @@ -1771,15 +1820,15 @@ class SqlWalker implements TreeWalker foreach ($joinColumns as $joinColumn) { $targetColumn = $class->getQuotedColumnName( $class->fieldNames[$joinColumn['referencedColumnName']], - $this->_platform + $this->platform ); $sqlParts[] = $joinTableAlias . '.' . $joinColumn['name'] . ' = ' . $sourceTableAlias . '.' . $targetColumn; } - foreach ($targetClass->getQuotedIdentifierColumnNames($this->_platform) as $targetColumnName) { + foreach ($targetClass->getQuotedIdentifierColumnNames($this->platform) as $targetColumnName) { if (isset($dqlParamKey)) { - $this->_parserResult->addParameterMapping($dqlParamKey, $this->_sqlParamIndex++); + $this->parserResult->addParameterMapping($dqlParamKey, $this->sqlParamIndex++); } $sqlParts[] = $targetTableAlias . '.' . $targetColumnName . ' = ' . $entitySql; @@ -1818,7 +1867,7 @@ class SqlWalker implements TreeWalker if ($innerExpr instanceof AST\InputParameter) { $dqlParamKey = $innerExpr->name; - $this->_parserResult->addParameterMapping($dqlParamKey, $this->_sqlParamIndex++); + $this->parserResult->addParameterMapping($dqlParamKey, $this->sqlParamIndex++); $sql .= ' ?'; } else { $sql .= $this->walkPathExpression($innerExpr); @@ -1859,13 +1908,13 @@ class SqlWalker implements TreeWalker $sql = ''; $dqlAlias = $instanceOfExpr->identificationVariable; - $discrClass = $class = $this->_queryComponents[$dqlAlias]['metadata']; - + $discrClass = $class = $this->queryComponents[$dqlAlias]['metadata']; + if ($class->discriminatorColumn) { - $discrClass = $this->_em->getClassMetadata($class->rootEntityName); + $discrClass = $this->em->getClassMetadata($class->rootEntityName); } - if ($this->_useSqlTableAliases) { + if ($this->useSqlTableAliases) { $sql .= $this->getSQLTableAlias($discrClass->getTableName(), $dqlAlias) . '.'; } @@ -1877,8 +1926,8 @@ class SqlWalker implements TreeWalker if ($parameter instanceof AST\InputParameter) { // We need to modify the parameter value to be its correspondent mapped value $dqlParamKey = $parameter->name; - $dqlParam = $this->_query->getParameter($dqlParamKey); - $paramValue = $this->_query->processParameterValue($dqlParam->getValue()); + $dqlParam = $this->query->getParameter($dqlParamKey); + $paramValue = $this->query->processParameterValue($dqlParam->getValue()); if ( ! ($paramValue instanceof \Doctrine\ORM\Mapping\ClassMetadata)) { throw QueryException::invalidParameterType('ClassMetadata', get_class($paramValue)); @@ -1887,11 +1936,11 @@ class SqlWalker implements TreeWalker $entityClassName = $paramValue->name; } else { // Get name from ClassMetadata to resolve aliases. - $entityClassName = $this->_em->getClassMetadata($parameter)->name; + $entityClassName = $this->em->getClassMetadata($parameter)->name; } if ($entityClassName == $class->name) { - $sqlParameterList[] = $this->_conn->quote($class->discriminatorValue); + $sqlParameterList[] = $this->conn->quote($class->discriminatorValue); } else { $discrMap = array_flip($class->discriminatorMap); @@ -1899,7 +1948,7 @@ class SqlWalker implements TreeWalker throw QueryException::instanceOfUnrelatedClass($entityClassName, $class->rootEntityName); } - $sqlParameterList[] = $this->_conn->quote($discrMap[$entityClassName]); + $sqlParameterList[] = $this->conn->quote($discrMap[$entityClassName]); } } @@ -1931,11 +1980,11 @@ class SqlWalker implements TreeWalker { switch ($literal->type) { case AST\Literal::STRING: - return $this->_conn->quote($literal->value); + return $this->conn->quote($literal->value); case AST\Literal::BOOLEAN: $bool = strtolower($literal->value) == 'true' ? true : false; - $boolVal = $this->_conn->getDatabasePlatform()->convertBooleans($bool); + $boolVal = $this->conn->getDatabasePlatform()->convertBooleans($bool); return $boolVal; @@ -1979,7 +2028,7 @@ class SqlWalker implements TreeWalker if ($likeExpr->stringPattern instanceof AST\InputParameter) { $inputParam = $likeExpr->stringPattern; $dqlParamKey = $inputParam->name; - $this->_parserResult->addParameterMapping($dqlParamKey, $this->_sqlParamIndex++); + $this->parserResult->addParameterMapping($dqlParamKey, $this->sqlParamIndex++); $sql .= '?'; } elseif ($likeExpr->stringPattern instanceof AST\Functions\FunctionNode ) { $sql .= $this->walkFunction($likeExpr->stringPattern); @@ -2021,13 +2070,13 @@ class SqlWalker implements TreeWalker $sql .= ($leftExpr instanceof AST\Node) ? $leftExpr->dispatch($this) - : (is_numeric($leftExpr) ? $leftExpr : $this->_conn->quote($leftExpr)); + : (is_numeric($leftExpr) ? $leftExpr : $this->conn->quote($leftExpr)); $sql .= ' ' . $compExpr->operator . ' '; $sql .= ($rightExpr instanceof AST\Node) ? $rightExpr->dispatch($this) - : (is_numeric($rightExpr) ? $rightExpr : $this->_conn->quote($rightExpr)); + : (is_numeric($rightExpr) ? $rightExpr : $this->conn->quote($rightExpr)); return $sql; } @@ -2040,7 +2089,7 @@ class SqlWalker implements TreeWalker */ public function walkInputParameter($inputParam) { - $this->_parserResult->addParameterMapping($inputParam->name, $this->_sqlParamIndex++); + $this->parserResult->addParameterMapping($inputParam->name, $this->sqlParamIndex++); return '?'; } @@ -2082,8 +2131,8 @@ class SqlWalker implements TreeWalker public function walkArithmeticTerm($term) { if (is_string($term)) { - return (isset($this->_queryComponents[$term])) - ? $this->walkResultVariable($this->_queryComponents[$term]['token']['value']) + return (isset($this->queryComponents[$term])) + ? $this->walkResultVariable($this->queryComponents[$term]['token']['value']) : $term; } @@ -2147,7 +2196,7 @@ class SqlWalker implements TreeWalker public function walkStringPrimary($stringPrimary) { return (is_string($stringPrimary)) - ? $this->_conn->quote($stringPrimary) + ? $this->conn->quote($stringPrimary) : $stringPrimary->dispatch($this); } @@ -2159,7 +2208,7 @@ class SqlWalker implements TreeWalker */ public function walkResultVariable($resultVariable) { - $resultAlias = $this->_scalarResultAliasMap[$resultVariable]; + $resultAlias = $this->scalarResultAliasMap[$resultVariable]; if (is_array($resultAlias)) { return implode(', ', $resultAlias); From d49a968d554e5ec464305b704b6be62db8ecd9fb Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Thu, 31 May 2012 18:37:51 -0300 Subject: [PATCH 04/37] tests for DDC-1719 --- lib/Doctrine/ORM/EntityManager.php | 11 ++-- .../ORM/Mapping/DefaultQuoteStrategy.php | 38 +++--------- lib/Doctrine/ORM/Mapping/QuoteStrategy.php | 59 +++++++++++++++++++ .../ORM/Persisters/BasicEntityPersister.php | 22 ++++--- lib/Doctrine/ORM/Query/SqlWalker.php | 6 +- .../BasicEntityPersisterTypeValueSqlTest.php | 12 ++++ .../ORM/Query/SelectSqlGenerationTest.php | 21 +++++++ 7 files changed, 120 insertions(+), 49 deletions(-) diff --git a/lib/Doctrine/ORM/EntityManager.php b/lib/Doctrine/ORM/EntityManager.php index 28ddd5695..de81cdc2f 100644 --- a/lib/Doctrine/ORM/EntityManager.php +++ b/lib/Doctrine/ORM/EntityManager.php @@ -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; } diff --git a/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php b/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php index a2a49f1b4..07b74f0a5 100644 --- a/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php +++ b/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php @@ -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) { diff --git a/lib/Doctrine/ORM/Mapping/QuoteStrategy.php b/lib/Doctrine/ORM/Mapping/QuoteStrategy.php index 366efb877..ee7c24819 100644 --- a/lib/Doctrine/ORM/Mapping/QuoteStrategy.php +++ b/lib/Doctrine/ORM/Mapping/QuoteStrategy.php @@ -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); + } \ No newline at end of file diff --git a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php index d51e2fe51..b94ecfad7 100644 --- a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php @@ -170,6 +170,13 @@ class BasicEntityPersister */ protected $_sqlTableAliases = array(); + /** + * The quote strategy. + * + * @var \Doctrine\ORM\Mapping\QuoteStrategy + */ + private $quoteStrategy; + /** * Initializes a new BasicEntityPersister 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++); } /** diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index 920703149..06f0c4abe 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -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++); } /** diff --git a/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterTypeValueSqlTest.php b/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterTypeValueSqlTest.php index f31fb2b2f..344ca12f9 100644 --- a/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterTypeValueSqlTest.php +++ b/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterTypeValueSqlTest.php @@ -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)); + } } diff --git a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php index 09fc39b9d..ae7cd7a52 100644 --- a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php +++ b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php @@ -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' + ); + } + } From db53b8651cf2b8848b8ca24201aa3a1d2ca0b9b7 Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Thu, 31 May 2012 19:10:34 -0300 Subject: [PATCH 05/37] apply quote strategy at sqlwalker --- .../ORM/Mapping/DefaultQuoteStrategy.php | 9 ++-- lib/Doctrine/ORM/Mapping/QuoteStrategy.php | 2 +- lib/Doctrine/ORM/Query/SqlWalker.php | 46 ++++++++----------- .../Tests/ORM/Mapping/QuoteStrategyTest.php | 4 +- 4 files changed, 27 insertions(+), 34 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php b/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php index 07b74f0a5..a887d407e 100644 --- a/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php +++ b/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php @@ -71,12 +71,11 @@ class DefaultQuoteStrategy extends QuoteStrategy /** * {@inheritdoc} */ - public function getJoinTableName($relation, ClassMetadata $class) + public function getJoinTableName(array $association, ClassMetadata $class) { - $assoc = $class->associationMappings[$relation]; - return isset($assoc['joinTable']['quoted']) - ? $this->platform->quoteIdentifier($assoc['joinTable']['name']) - : $assoc['joinTable']['name']; + return isset($association['joinTable']['quoted']) + ? $this->platform->quoteIdentifier($association['joinTable']['name']) + : $association['joinTable']['name']; } /** diff --git a/lib/Doctrine/ORM/Mapping/QuoteStrategy.php b/lib/Doctrine/ORM/Mapping/QuoteStrategy.php index ee7c24819..4d42c4460 100644 --- a/lib/Doctrine/ORM/Mapping/QuoteStrategy.php +++ b/lib/Doctrine/ORM/Mapping/QuoteStrategy.php @@ -85,7 +85,7 @@ abstract class QuoteStrategy * @param ClassMetadata $class * @return string */ - abstract public function getJoinTableName($relation, ClassMetadata $class); + abstract public function getJoinTableName(array $association, ClassMetadata $class); /** * Gets the (possibly quoted) identifier column names for safe use in an SQL statement. diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index 06f0c4abe..b705834e3 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -310,11 +310,11 @@ class SqlWalker implements TreeWalker // If this is a joined association we must use left joins to preserve the correct result. $sql .= isset($this->queryComponents[$dqlAlias]['relation']) ? ' LEFT ' : ' INNER '; - $sql .= 'JOIN ' . $parentClass->getQuotedTableName($this->platform) . ' ' . $tableAlias . ' ON '; + $sql .= 'JOIN ' . $this->quoteStrategy->getTableName($parentClass) . ' ' . $tableAlias . ' ON '; $sqlParts = array(); - foreach ($class->getQuotedIdentifierColumnNames($this->platform) as $columnName) { + foreach ($this->quoteStrategy->getIdentifierColumnNames($class) as $columnName) { $sqlParts[] = $baseTableAlias . '.' . $columnName . ' = ' . $tableAlias . '.' . $columnName; } @@ -336,11 +336,11 @@ class SqlWalker implements TreeWalker $subClass = $this->em->getClassMetadata($subClassName); $tableAlias = $this->getSQLTableAlias($subClass->getTableName(), $dqlAlias); - $sql .= ' LEFT JOIN ' . $subClass->getQuotedTableName($this->platform) . ' ' . $tableAlias . ' ON '; + $sql .= ' LEFT JOIN ' . $this->quoteStrategy->getTableName($subClass) . ' ' . $tableAlias . ' ON '; $sqlParts = array(); - foreach ($subClass->getQuotedIdentifierColumnNames($this->platform) as $columnName) { + foreach ($this->quoteStrategy->getIdentifierColumnNames($subClass) as $columnName) { $sqlParts[] = $baseTableAlias . '.' . $columnName . ' = ' . $tableAlias . '.' . $columnName; } @@ -361,7 +361,7 @@ class SqlWalker implements TreeWalker if ( ! isset($qComp['relation']['orderBy'])) continue; foreach ($qComp['relation']['orderBy'] as $fieldName => $orientation) { - $columnName = $qComp['metadata']->getQuotedColumnName($fieldName, $this->platform); + $columnName = $this->quoteStrategy->getColumnName($fieldName, $qComp['metadata']); $tableName = ($qComp['metadata']->isInheritanceTypeJoined()) ? $this->em->getUnitOfWork()->getEntityPersister($qComp['metadata']->name)->getOwningTable($fieldName) : $qComp['metadata']->getTableName(); @@ -544,7 +544,7 @@ class SqlWalker implements TreeWalker $tableAlias = $this->getSQLTableAlias($class->getTableName(), $identVariable); $sqlParts = array(); - foreach ($class->getQuotedIdentifierColumnNames($this->platform) as $columnName) { + foreach ($this->quoteStrategy->getIdentifierColumnNames($class) as $columnName) { $sqlParts[] = $tableAlias . '.' . $columnName; } @@ -592,7 +592,7 @@ class SqlWalker implements TreeWalker $sql .= $this->walkIdentificationVariable($dqlAlias, $fieldName) . '.'; } - $sql .= $class->getQuotedColumnName($fieldName, $this->platform); + $sql .= $this->quoteStrategy->getColumnName($fieldName, $class); break; case AST\PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION: @@ -1168,7 +1168,7 @@ class SqlWalker implements TreeWalker : $class->getTableName(); $sqlTableAlias = $this->getSQLTableAlias($tableName, $dqlAlias); - $columnName = $class->getQuotedColumnName($fieldName, $this->platform); + $columnName = $this->quoteStrategy->getColumnName($fieldName, $class); $columnAlias = $this->getSQLColumnAlias($class->fieldMappings[$fieldName]['columnName']); $col = $sqlTableAlias . '.' . $columnName; @@ -1264,7 +1264,7 @@ class SqlWalker implements TreeWalker $sqlTableAlias = $this->getSQLTableAlias($tableName, $dqlAlias); $columnAlias = $this->getSQLColumnAlias($mapping['columnName']); - $quotedColumnName = $class->getQuotedColumnName($fieldName, $this->platform); + $quotedColumnName = $this->quoteStrategy->getColumnName($fieldName, $class); $col = $sqlTableAlias . '.' . $quotedColumnName; @@ -1295,7 +1295,7 @@ class SqlWalker implements TreeWalker } $columnAlias = $this->getSQLColumnAlias($mapping['columnName']); - $quotedColumnName = $subClass->getQuotedColumnName($fieldName, $this->platform); + $quotedColumnName = $this->quoteStrategy->getColumnName($fieldName, $subClass); $col = $sqlTableAlias . '.' . $quotedColumnName; @@ -1530,7 +1530,7 @@ class SqlWalker implements TreeWalker { $class = $this->em->getClassMetadata($deleteClause->abstractSchemaName); $tableName = $class->getTableName(); - $sql = 'DELETE FROM ' . $class->getQuotedTableName($this->platform); + $sql = 'DELETE FROM ' . $this->quoteStrategy->getTableName($class); $this->setSQLTableAlias($tableName, $tableName, $deleteClause->aliasIdentificationVariable); $this->rootAliases[] = $deleteClause->aliasIdentificationVariable; @@ -1548,7 +1548,7 @@ class SqlWalker implements TreeWalker { $class = $this->em->getClassMetadata($updateClause->abstractSchemaName); $tableName = $class->getTableName(); - $sql = 'UPDATE ' . $class->getQuotedTableName($this->platform); + $sql = 'UPDATE ' . $this->quoteStrategy->getTableName($class); $this->setSQLTableAlias($tableName, $tableName, $updateClause->aliasIdentificationVariable); $this->rootAliases[] = $updateClause->aliasIdentificationVariable; @@ -1759,18 +1759,18 @@ class SqlWalker implements TreeWalker $targetTableAlias = $this->getSQLTableAlias($targetClass->getTableName()); $sourceTableAlias = $this->getSQLTableAlias($class->getTableName(), $dqlAlias); - $sql .= $targetClass->getQuotedTableName($this->platform) . ' ' . $targetTableAlias . ' WHERE '; + $sql .= $this->quoteStrategy->getTableName($targetClass) . ' ' . $targetTableAlias . ' WHERE '; $owningAssoc = $targetClass->associationMappings[$assoc['mappedBy']]; $sqlParts = array(); foreach ($owningAssoc['targetToSourceKeyColumns'] as $targetColumn => $sourceColumn) { - $targetColumn = $class->getQuotedColumnName($class->fieldNames[$targetColumn], $this->platform); + $targetColumn = $this->quoteStrategy->getColumnName($class->fieldNames[$targetColumn], $class); $sqlParts[] = $sourceTableAlias . '.' . $targetColumn . ' = ' . $targetTableAlias . '.' . $sourceColumn; } - foreach ($targetClass->getQuotedIdentifierColumnNames($this->platform) as $targetColumnName) { + foreach ($this->quoteStrategy->getIdentifierColumnNames($targetClass) as $targetColumnName) { if (isset($dqlParamKey)) { $this->parserResult->addParameterMapping($dqlParamKey, $this->sqlParamIndex++); } @@ -1791,18 +1791,15 @@ class SqlWalker implements TreeWalker $sourceTableAlias = $this->getSQLTableAlias($class->getTableName(), $dqlAlias); // join to target table - $sql .= $targetClass->getQuotedJoinTableName($owningAssoc, $this->platform) . ' ' . $joinTableAlias - . ' INNER JOIN ' . $targetClass->getQuotedTableName($this->platform) . ' ' . $targetTableAlias . ' ON '; + $sql .= $this->quoteStrategy->getJoinTableName($owningAssoc, $targetClass) . ' ' . $joinTableAlias + . ' INNER JOIN ' . $this->quoteStrategy->getTableName($targetClass) . ' ' . $targetTableAlias . ' ON '; // join conditions $joinColumns = $assoc['isOwningSide'] ? $joinTable['inverseJoinColumns'] : $joinTable['joinColumns']; $joinSqlParts = array(); foreach ($joinColumns as $joinColumn) { - $targetColumn = $targetClass->getQuotedColumnName( - $targetClass->fieldNames[$joinColumn['referencedColumnName']], - $this->platform - ); + $targetColumn = $this->quoteStrategy->getColumnName($targetClass->fieldNames[$joinColumn['referencedColumnName']], $targetClass); $joinSqlParts[] = $joinTableAlias . '.' . $joinColumn['name'] . ' = ' . $targetTableAlias . '.' . $targetColumn; } @@ -1814,15 +1811,12 @@ class SqlWalker implements TreeWalker $sqlParts = array(); foreach ($joinColumns as $joinColumn) { - $targetColumn = $class->getQuotedColumnName( - $class->fieldNames[$joinColumn['referencedColumnName']], - $this->platform - ); + $targetColumn = $this->quoteStrategy->getColumnName($class->fieldNames[$joinColumn['referencedColumnName']], $class); $sqlParts[] = $joinTableAlias . '.' . $joinColumn['name'] . ' = ' . $sourceTableAlias . '.' . $targetColumn; } - foreach ($targetClass->getQuotedIdentifierColumnNames($this->platform) as $targetColumnName) { + foreach ($this->quoteStrategy->getIdentifierColumnNames($targetClass) as $targetColumnName) { if (isset($dqlParamKey)) { $this->parserResult->addParameterMapping($dqlParamKey, $this->sqlParamIndex++); } diff --git a/tests/Doctrine/Tests/ORM/Mapping/QuoteStrategyTest.php b/tests/Doctrine/Tests/ORM/Mapping/QuoteStrategyTest.php index e541f890d..3f5c66f20 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/QuoteStrategyTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/QuoteStrategyTest.php @@ -100,8 +100,8 @@ class QuoteStrategyTest extends \Doctrine\Tests\OrmTestCase ) ); - $this->assertEquals('"cmsaddress_cmsuser"', $this->strategy->getJoinTableName('user', $cm1)); - $this->assertEquals('cmsaddress_cmsuser', $this->strategy->getJoinTableName('user', $cm2)); + $this->assertEquals('"cmsaddress_cmsuser"', $this->strategy->getJoinTableName($cm1->associationMappings['user'], $cm1)); + $this->assertEquals('cmsaddress_cmsuser', $this->strategy->getJoinTableName($cm2->associationMappings['user'], $cm2)); } From 505bdb9c032a2034ed5d4489a8b2680d2b798b85 Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Fri, 1 Jun 2012 14:57:01 -0300 Subject: [PATCH 06/37] missing files --- .../Tests/Models/DDC1719/DDC1719Entity.php | 32 +++++++ .../ORM/Functional/Ticket/DDC1719Test.php | 90 +++++++++++++++++++ 2 files changed, 122 insertions(+) create mode 100644 tests/Doctrine/Tests/Models/DDC1719/DDC1719Entity.php create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1719Test.php diff --git a/tests/Doctrine/Tests/Models/DDC1719/DDC1719Entity.php b/tests/Doctrine/Tests/Models/DDC1719/DDC1719Entity.php new file mode 100644 index 000000000..3bc5cf9ef --- /dev/null +++ b/tests/Doctrine/Tests/Models/DDC1719/DDC1719Entity.php @@ -0,0 +1,32 @@ +value = $value; + } + +} \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1719Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1719Test.php new file mode 100644 index 000000000..cab55c609 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1719Test.php @@ -0,0 +1,90 @@ +markTestIncomplete(); + + parent::setUp(); + try { + $this->_schemaTool->createSchema(array( + $this->_em->getClassMetadata(self::CLASS_NAME), + )); + } catch(\Exception $e) { + } + } + + public function testCreateRetreaveUpdateDelete() + { + $e1 = new DDC1719Entity('Bar 1'); + $e2 = new DDC1719Entity('Foo 1'); + + // Create + $this->_em->persist($e1); + $this->_em->persist($e2); + $this->_em->flush(); + $this->_em->clear(); + + $e1Id = $e1->id; + $e2Id = $e2->id; + + // Retreave + $e1 = $this->_em->find(self::CLASS_NAME, $e1Id); + $e2 = $this->_em->find(self::CLASS_NAME, $e2Id); + + $this->assertInstanceOf(self::CLASS_NAME, $e1); + $this->assertInstanceOf(self::CLASS_NAME, $e2); + + $this->assertEquals($e1Id, $e1->id); + $this->assertEquals($e2Id, $e2->id); + + $this->assertEquals('Bar 1', $e1->value); + $this->assertEquals('Foo 1', $e2->value); + + $e1->value = 'Bar 2'; + $e2->value = 'Foo 2'; + + // Update + $this->_em->persist($e1); + $this->_em->persist($e2); + $this->_em->flush(); + + $this->assertEquals('Bar 2', $e1->value); + $this->assertEquals('Foo 2', $e2->value); + + $this->assertInstanceOf(self::CLASS_NAME, $e1); + $this->assertInstanceOf(self::CLASS_NAME, $e2); + + $this->assertEquals($e1Id, $e1->id); + $this->assertEquals($e2Id, $e2->id); + + $this->assertEquals('Bar 2', $e1->value); + $this->assertEquals('Foo 2', $e2->value); + + // Delete + $this->_em->remove($e1); + $this->_em->remove($e2); + $this->_em->flush(); + + + $e1 = $this->_em->find(self::CLASS_NAME, $e1Id); + $e2 = $this->_em->find(self::CLASS_NAME, $e2Id); + + $this->assertNull($e1); + $this->assertNull($e2); + } + +} \ No newline at end of file From 5d665b59a18e24539bb186c9edb0458455bd49af Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Fri, 1 Jun 2012 15:57:41 -0300 Subject: [PATCH 07/37] remove getQuotedIdentifierColumnNames --- .gitignore | 5 +++ .../ORM/Mapping/ClassMetadataInfo.php | 36 ------------------- 2 files changed, 5 insertions(+), 36 deletions(-) diff --git a/.gitignore b/.gitignore index a91841777..13f4debc8 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,8 @@ lib/Doctrine/DBAL /.settings/ .buildpath .project +/.AppleDouble/ +/tests/.AppleDouble/ +/bin/.AppleDouble/ +/lib/.AppleDouble/ +/tools/.AppleDouble/ \ No newline at end of file diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php index 8434e49b2..b086c1785 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php @@ -2643,42 +2643,6 @@ class ClassMetadataInfo implements ClassMetadata return $this->name; } - /** - * Gets the (possibly quoted) identifier column names for safe use in an SQL statement. - * - * @param AbstractPlatform $platform - * @return array - */ - public function getQuotedIdentifierColumnNames($platform) - { - $quotedColumnNames = array(); - - foreach ($this->identifier as $idProperty) { - if (isset($this->fieldMappings[$idProperty])) { - $quotedColumnNames[] = isset($this->fieldMappings[$idProperty]['quoted']) - ? $platform->quoteIdentifier($this->fieldMappings[$idProperty]['columnName']) - : $this->fieldMappings[$idProperty]['columnName']; - - continue; - } - - // Association defined as Id field - $joinColumns = $this->associationMappings[$idProperty]['joinColumns']; - $assocQuotedColumnNames = array_map( - function ($joinColumn) { - return isset($joinColumn['quoted']) - ? $platform->quoteIdentifier($joinColumn['name']) - : $joinColumn['name']; - }, - $joinColumns - ); - - $quotedColumnNames = array_merge($quotedColumnNames, $assocQuotedColumnNames); - } - - return $quotedColumnNames; - } - /** * Gets the (possibly quoted) column name of a mapped field for safe use * in an SQL statement. From 2af7b3fd38557fa71838d07d53744c386fc16eb4 Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Fri, 1 Jun 2012 16:40:36 -0300 Subject: [PATCH 08/37] use quote strategy in BasicEntityPersister --- .../ORM/Persisters/BasicEntityPersister.php | 50 +++++++++---------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php index b94ecfad7..e7937685f 100644 --- a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php @@ -289,9 +289,9 @@ class BasicEntityPersister protected function fetchVersionValue($versionedClass, $id) { $versionField = $versionedClass->versionField; - $identifier = $versionedClass->getIdentifierColumnNames(); + $identifier = $this->quoteStrategy->getIdentifierColumnNames($versionedClass); - $versionFieldColumnName = $versionedClass->getQuotedColumnName($versionField, $this->_platform); + $versionFieldColumnName = $this->quoteStrategy->getColumnName($versionField, $versionedClass); //FIXME: Order with composite keys might not be correct $sql = 'SELECT ' . $versionFieldColumnName @@ -323,7 +323,7 @@ class BasicEntityPersister if (isset($updateData[$tableName]) && $updateData[$tableName]) { $this->_updateTable( - $entity, $this->_class->getQuotedTableName($this->_platform), + $entity, $this->quoteStrategy->getTableName($this->_class), $updateData[$tableName], $this->_class->isVersioned ); @@ -352,7 +352,7 @@ class BasicEntityPersister $placeholder = '?'; if (isset($this->_class->fieldNames[$columnName])) { - $column = $this->_class->getQuotedColumnName($this->_class->fieldNames[$columnName], $this->_platform); + $column = $this->quoteStrategy->getColumnName($this->_class->fieldNames[$columnName], $this->_class); if (isset($this->_class->fieldMappings[$this->_class->fieldNames[$columnName]]['requireSQLConversion'])) { $type = Type::getType($this->_columnTypes[$columnName]); @@ -375,7 +375,7 @@ class BasicEntityPersister $params[] = $id[$idField]; $types[] = $targetMapping->fieldMappings[$targetMapping->identifier[0]]['type']; } else { - $where[] = $this->_class->getQuotedColumnName($idField, $this->_platform); + $where[] = $this->quoteStrategy->getColumnName($idField, $this->_class); $params[] = $id[$idField]; $types[] = $this->_class->fieldMappings[$idField]['type']; } @@ -384,7 +384,7 @@ class BasicEntityPersister if ($versioned) { $versionField = $this->_class->versionField; $versionFieldType = $this->_class->fieldMappings[$versionField]['type']; - $versionColumn = $this->_class->getQuotedColumnName($versionField, $this->_platform); + $versionColumn = $this->quoteStrategy->getColumnName($versionField, $this->_class); if ($versionFieldType == Type::INTEGER) { $set[] = $versionColumn . ' = ' . $versionColumn . ' + 1'; @@ -439,13 +439,13 @@ class BasicEntityPersister if ( ! isset($mapping['isOnDeleteCascade'])) { $this->_conn->delete( - $this->_class->getQuotedJoinTableName($mapping, $this->_platform), + $this->quoteStrategy->getJoinTableName($mapping, $this->_class), array_combine($keys, $identifier) ); if ($selfReferential) { $this->_conn->delete( - $this->_class->getQuotedJoinTableName($mapping, $this->_platform), + $this->quoteStrategy->getJoinTableName($mapping, $this->_class), array_combine($otherKeys, $identifier) ); } @@ -469,8 +469,8 @@ class BasicEntityPersister $identifier = $this->_em->getUnitOfWork()->getEntityIdentifier($entity); $this->deleteJoinTableRecords($identifier); - $id = array_combine($this->_class->getIdentifierColumnNames(), $identifier); - $this->_conn->delete($this->_class->getQuotedTableName($this->_platform), $id); + $id = array_combine($this->quoteStrategy->getIdentifierColumnNames($this->_class), $identifier); + $this->_conn->delete($this->quoteStrategy->getTableName($this->_class), $id); } /** @@ -816,7 +816,7 @@ class BasicEntityPersister $sourceClass = $this->_em->getClassMetadata($assoc['sourceEntity']); if ($assoc['isOwningSide']) { - $quotedJoinTable = $sourceClass->getQuotedJoinTableName($assoc, $this->_platform); + $quotedJoinTable = $this->quoteStrategy->getJoinTableName($assoc, $sourceClass); foreach ($assoc['relationToSourceKeyColumns'] as $relationKeyColumn => $sourceKeyColumn) { if ($sourceClass->containsForeignIdentifier) { @@ -839,7 +839,7 @@ class BasicEntityPersister } } else { $owningAssoc = $this->_em->getClassMetadata($assoc['targetEntity'])->associationMappings[$assoc['mappedBy']]; - $quotedJoinTable = $sourceClass->getQuotedJoinTableName($owningAssoc, $this->_platform); + $quotedJoinTable = $this->quoteStrategy->getJoinTableName($owningAssoc, $sourceClass); // TRICKY: since the association is inverted source and target are flipped foreach ($owningAssoc['relationToTargetKeyColumns'] as $relationKeyColumn => $sourceKeyColumn) { @@ -909,7 +909,7 @@ class BasicEntityPersister } return $this->_platform->modifyLimitQuery('SELECT ' . $this->_getSelectColumnListSQL() - . $this->_platform->appendLockHint(' FROM ' . $this->_class->getQuotedTableName($this->_platform) . ' ' + . $this->_platform->appendLockHint(' FROM ' . $this->quoteStrategy->getTableName($this->_class) . ' ' . $alias, $lockMode) . $this->_selectJoinSql . $joinSql . ($conditionSql ? ' WHERE ' . $conditionSql : '') @@ -942,7 +942,7 @@ class BasicEntityPersister $this->_getSQLTableAlias($this->_class->fieldMappings[$fieldName]['inherited']) : $baseTableAlias; - $columnName = $this->_class->getQuotedColumnName($fieldName, $this->_platform); + $columnName = $this->quoteStrategy->getColumnName($fieldName, $this->_class); $orderBySql .= $orderBySql ? ', ' : ' ORDER BY '; $orderBySql .= $tableAlias . '.' . $columnName . ' ' . $orientation; @@ -1020,7 +1020,7 @@ class BasicEntityPersister if ($assoc['isOwningSide']) { $this->_selectJoinSql .= ' ' . $this->getJoinSQLForJoinColumns($assoc['joinColumns']); - $this->_selectJoinSql .= ' ' . $eagerEntity->getQuotedTableName($this->_platform) . ' ' . $this->_getSQLTableAlias($eagerEntity->name, $assocAlias) .' ON '; + $this->_selectJoinSql .= ' ' . $this->quoteStrategy->getTableName($eagerEntity) . ' ' . $this->_getSQLTableAlias($eagerEntity->name, $assocAlias) .' ON '; $tableAlias = $this->_getSQLTableAlias($assoc['targetEntity'], $assocAlias); foreach ($assoc['sourceToTargetKeyColumns'] as $sourceCol => $targetCol) { @@ -1041,7 +1041,7 @@ class BasicEntityPersister $owningAssoc = $eagerEntity->getAssociationMapping($assoc['mappedBy']); $this->_selectJoinSql .= ' LEFT JOIN'; - $this->_selectJoinSql .= ' ' . $eagerEntity->getQuotedTableName($this->_platform) . ' ' + $this->_selectJoinSql .= ' ' . $this->quoteStrategy->getTableName($eagerEntity) . ' ' . $this->_getSQLTableAlias($eagerEntity->name, $assocAlias) . ' ON '; foreach ($owningAssoc['sourceToTargetKeyColumns'] as $sourceCol => $targetCol) { @@ -1107,7 +1107,7 @@ class BasicEntityPersister $joinClauses = $owningAssoc['relationToSourceKeyColumns']; } - $joinTableName = $this->_class->getQuotedJoinTableName($owningAssoc, $this->_platform); + $joinTableName = $this->quoteStrategy->getJoinTableName($owningAssoc, $this->_class); $joinSql = ''; foreach ($joinClauses as $joinTableColumn => $sourceColumn) { @@ -1116,7 +1116,7 @@ class BasicEntityPersister if ($this->_class->containsForeignIdentifier && ! isset($this->_class->fieldNames[$sourceColumn])) { $quotedColumn = $sourceColumn; // join columns cannot be quoted } else { - $quotedColumn = $this->_class->getQuotedColumnName($this->_class->fieldNames[$sourceColumn], $this->_platform); + $quotedColumn = $this->quoteStrategy->getColumnName($this->_class->fieldNames[$sourceColumn], $this->_class); } $joinSql .= $this->_getSQLTableAlias($this->_class->name) . '.' . $quotedColumn . ' = ' @@ -1139,8 +1139,8 @@ class BasicEntityPersister if (empty($columns)) { $insertSql = $this->_platform->getEmptyIdentityInsertSQL( - $this->_class->getQuotedTableName($this->_platform), - $this->_class->getQuotedColumnName($this->_class->identifier[0], $this->_platform) + $this->quoteStrategy->getTableName($this->_class), + $this->quoteStrategy->getColumnName($this->_class->identifier[0], $this->_class) ); } else { $columns = array_unique($columns); @@ -1159,7 +1159,7 @@ class BasicEntityPersister $values[] = $placeholder; } - $insertSql = 'INSERT INTO ' . $this->_class->getQuotedTableName($this->_platform) + $insertSql = 'INSERT INTO ' . $this->quoteStrategy->getTableName($this->_class) . ' (' . implode(', ', $columns) . ') VALUES (' . implode(', ', $values) . ')'; } @@ -1195,7 +1195,7 @@ class BasicEntityPersister } } } else if ($this->_class->generatorType != ClassMetadata::GENERATOR_TYPE_IDENTITY || $this->_class->identifier[0] != $name) { - $columns[] = $this->_class->getQuotedColumnName($name, $this->_platform); + $columns[] = $this->quoteStrategy->getColumnName($name, $this->_class); $this->_columnTypes[$name] = $this->_class->fieldMappings[$name]['type']; } } @@ -1214,7 +1214,7 @@ class BasicEntityPersister protected function _getSelectColumnSQL($field, ClassMetadata $class, $alias = 'r') { $sql = $this->_getSQLTableAlias($class->name, $alias == 'r' ? '' : $alias) - . '.' . $class->getQuotedColumnName($field, $this->_platform); + . '.' . $this->quoteStrategy->getColumnName($field, $class); $columnAlias = $this->getSQLColumnAlias($class->columnNames[$field]); $this->_rsm->addFieldResult($alias, $columnAlias, $field); @@ -1284,7 +1284,7 @@ class BasicEntityPersister */ protected function getLockTablesSql() { - return 'FROM ' . $this->_class->getQuotedTableName($this->_platform) . ' ' + return 'FROM ' . $this->quoteStrategy->getTableName($this->_class) . ' ' . $this->_getSQLTableAlias($this->_class->name); } @@ -1313,7 +1313,7 @@ class BasicEntityPersister ? $this->_class->fieldMappings[$field]['inherited'] : $this->_class->name; - $conditionSql .= $this->_getSQLTableAlias($className) . '.' . $this->_class->getQuotedColumnName($field, $this->_platform); + $conditionSql .= $this->_getSQLTableAlias($className) . '.' . $this->quoteStrategy->getColumnName($field, $this->_class); if (isset($this->_class->fieldMappings[$field]['requireSQLConversion'])) { $type = Type::getType($this->_class->getTypeOfField($field)); From 7f64474f3e92dfe92f2724be1414ef917b0e0176 Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Fri, 1 Jun 2012 20:44:26 -0300 Subject: [PATCH 09/37] use quote strategy in persister --- .../AbstractCollectionPersister.php | 14 +++++++++--- .../AbstractEntityInheritancePersister.php | 2 +- .../ORM/Persisters/BasicEntityPersister.php | 6 ++--- .../Persisters/JoinedSubclassPersister.php | 8 +++---- .../ORM/Persisters/ManyToManyPersister.php | 22 +++++++++---------- 5 files changed, 30 insertions(+), 22 deletions(-) diff --git a/lib/Doctrine/ORM/Persisters/AbstractCollectionPersister.php b/lib/Doctrine/ORM/Persisters/AbstractCollectionPersister.php index 6f612c9fb..6ae07bc3f 100644 --- a/lib/Doctrine/ORM/Persisters/AbstractCollectionPersister.php +++ b/lib/Doctrine/ORM/Persisters/AbstractCollectionPersister.php @@ -45,6 +45,13 @@ abstract class AbstractCollectionPersister */ protected $_uow; + /** + * The quote strategy. + * + * @var \Doctrine\ORM\Mapping\QuoteStrategy + */ + protected $quoteStrategy; + /** * Initializes a new instance of a class derived from AbstractCollectionPersister. * @@ -52,9 +59,10 @@ abstract class AbstractCollectionPersister */ public function __construct(EntityManager $em) { - $this->_em = $em; - $this->_uow = $em->getUnitOfWork(); - $this->_conn = $em->getConnection(); + $this->_em = $em; + $this->_uow = $em->getUnitOfWork(); + $this->_conn = $em->getConnection(); + $this->quoteStrategy = $em->getQuoteStrategy(); } /** diff --git a/lib/Doctrine/ORM/Persisters/AbstractEntityInheritancePersister.php b/lib/Doctrine/ORM/Persisters/AbstractEntityInheritancePersister.php index 13d7dece5..3153c4064 100644 --- a/lib/Doctrine/ORM/Persisters/AbstractEntityInheritancePersister.php +++ b/lib/Doctrine/ORM/Persisters/AbstractEntityInheritancePersister.php @@ -61,7 +61,7 @@ abstract class AbstractEntityInheritancePersister extends BasicEntityPersister protected function _getSelectColumnSQL($field, ClassMetadata $class, $alias = 'r') { $columnName = $class->columnNames[$field]; - $sql = $this->_getSQLTableAlias($class->name, $alias == 'r' ? '' : $alias) . '.' . $class->getQuotedColumnName($field, $this->_platform); + $sql = $this->_getSQLTableAlias($class->name, $alias == 'r' ? '' : $alias) . '.' . $this->quoteStrategy->getColumnName($field, $class); $columnAlias = $this->getSQLColumnAlias($columnName); $this->_rsm->addFieldResult($alias, $columnAlias, $field, $class->name); diff --git a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php index e7937685f..e0809fa7b 100644 --- a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php @@ -175,7 +175,7 @@ class BasicEntityPersister * * @var \Doctrine\ORM\Mapping\QuoteStrategy */ - private $quoteStrategy; + protected $quoteStrategy; /** * Initializes a new BasicEntityPersister that uses the given EntityManager @@ -295,7 +295,7 @@ class BasicEntityPersister //FIXME: Order with composite keys might not be correct $sql = 'SELECT ' . $versionFieldColumnName - . ' FROM ' . $versionedClass->getQuotedTableName($this->_platform) + . ' FROM ' . $this->quoteStrategy->getTableName($versionedClass) . ' WHERE ' . implode(' = ? AND ', $identifier) . ' = ?'; $value = $this->_conn->fetchColumn($sql, array_values((array)$id)); @@ -469,7 +469,7 @@ class BasicEntityPersister $identifier = $this->_em->getUnitOfWork()->getEntityIdentifier($entity); $this->deleteJoinTableRecords($identifier); - $id = array_combine($this->quoteStrategy->getIdentifierColumnNames($this->_class), $identifier); + $id = array_combine($this->_class->getIdentifierColumnNames(), $identifier); $this->_conn->delete($this->quoteStrategy->getTableName($this->_class), $id); } diff --git a/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php b/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php index 3b8fb1e33..9ac129f8e 100644 --- a/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php +++ b/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php @@ -105,7 +105,7 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister $tableName = $cm->getTableName(); $this->_owningTableMap[$fieldName] = $tableName; - $this->_quotedTableMap[$tableName] = $cm->getQuotedTableName($this->_platform); + $this->_quotedTableMap[$tableName] = $this->quoteStrategy->getTableName($cm); return $tableName; } @@ -225,7 +225,7 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister // Make sure the table with the version column is updated even if no columns on that // table were affected. if ($isVersioned && ! isset($updateData[$versionedTable])) { - $this->_updateTable($entity, $versionedClass->getQuotedTableName($this->_platform), array(), true); + $this->_updateTable($entity, $this->quoteStrategy->getTableName($versionedClass), array(), true); $id = $this->_em->getUnitOfWork()->getEntityIdentifier($entity); $this->assignDefaultVersionValue($entity, $id); @@ -247,11 +247,11 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister // delete the row from the root table. Cascades do the rest. if ($this->_platform->supportsForeignKeyConstraints()) { $this->_conn->delete( - $this->_em->getClassMetadata($this->_class->rootEntityName)->getQuotedTableName($this->_platform), $id + $this->quoteStrategy->getTableName($this->_em->getClassMetadata($this->_class->rootEntityName)), $id ); } else { // Delete from all tables individually, starting from this class' table up to the root table. - $this->_conn->delete($this->_class->getQuotedTableName($this->_platform), $id); + $this->_conn->delete($this->quoteStrategy->getTableName($this->_class), $id); foreach ($this->_class->parentClasses as $parentClass) { $this->_conn->delete( diff --git a/lib/Doctrine/ORM/Persisters/ManyToManyPersister.php b/lib/Doctrine/ORM/Persisters/ManyToManyPersister.php index 4c3b269a3..f0e57ea20 100644 --- a/lib/Doctrine/ORM/Persisters/ManyToManyPersister.php +++ b/lib/Doctrine/ORM/Persisters/ManyToManyPersister.php @@ -78,11 +78,10 @@ class ManyToManyPersister extends AbstractCollectionPersister */ protected function _getInsertRowSQL(PersistentCollection $coll) { - $mapping = $coll->getMapping(); - $columns = $mapping['joinTableColumns']; - $class = $this->_em->getClassMetadata(get_class($coll->getOwner())); - - $joinTable = $class->getQuotedJoinTableName($mapping, $this->_conn->getDatabasePlatform()); + $mapping = $coll->getMapping(); + $columns = $mapping['joinTableColumns']; + $class = $this->_em->getClassMetadata(get_class($coll->getOwner())); + $joinTable = $this->quoteStrategy->getJoinTableName($mapping, $class); return 'INSERT INTO ' . $joinTable . ' (' . implode(', ', $columns) . ')' . ' VALUES (' . implode(', ', array_fill(0, count($columns), '?')) . ')'; @@ -150,10 +149,11 @@ class ManyToManyPersister extends AbstractCollectionPersister */ protected function _getDeleteSQL(PersistentCollection $coll) { - $class = $this->_em->getClassMetadata(get_class($coll->getOwner())); - $mapping = $coll->getMapping(); + $class = $this->_em->getClassMetadata(get_class($coll->getOwner())); + $mapping = $coll->getMapping(); + $joinTable = $this->quoteStrategy->getJoinTableName($mapping, $class); - return 'DELETE FROM ' . $class->getQuotedJoinTableName($mapping, $this->_conn->getDatabasePlatform()) + return 'DELETE FROM ' . $joinTable . ' WHERE ' . implode(' = ? AND ', array_keys($mapping['relationToSourceKeyColumns'])) . ' = ?'; } @@ -224,7 +224,7 @@ class ManyToManyPersister extends AbstractCollectionPersister } $sql = 'SELECT COUNT(*)' - . ' FROM ' . $class->getQuotedJoinTableName($mapping, $this->_conn->getDatabasePlatform()) . ' t' + . ' FROM ' . $this->quoteStrategy->getJoinTableName($mapping, $class) . ' t' . $joinTargetEntitySQL . ' WHERE ' . implode(' AND ', $whereClauses); @@ -326,7 +326,7 @@ class ManyToManyPersister extends AbstractCollectionPersister $targetId = $uow->getEntityIdentifier($element); } - $quotedJoinTable = $sourceClass->getQuotedJoinTableName($mapping, $this->_conn->getDatabasePlatform()); + $quotedJoinTable = $this->quoteStrategy->getJoinTableName($mapping, $sourceClass); $whereClauses = array(); $params = array(); @@ -387,7 +387,7 @@ class ManyToManyPersister extends AbstractCollectionPersister $joinTargetEntitySQL = ''; if ($filterSql = $this->generateFilterConditionSQL($targetClass, 'te')) { $joinTargetEntitySQL = ' JOIN ' - . $targetClass->getQuotedTableName($this->_conn->getDatabasePlatform()) . ' te' + . $this->quoteStrategy->getTableName($targetClass) . ' te' . ' ON'; $joinTargetEntitySQLClauses = array(); From 36296a390653cb705705a6b879b4370a4f504776 Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Mon, 4 Jun 2012 12:52:56 -0300 Subject: [PATCH 10/37] use quote strategy in JoinedSubclassPersister --- .../ORM/Persisters/JoinedSubclassPersister.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php b/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php index 9ac129f8e..458bcc61e 100644 --- a/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php +++ b/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php @@ -255,7 +255,7 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister foreach ($this->_class->parentClasses as $parentClass) { $this->_conn->delete( - $this->_em->getClassMetadata($parentClass)->getQuotedTableName($this->_platform), $id + $this->quoteStrategy->getTableName($this->_em->getClassMetadata($parentClass)), $id ); } } @@ -321,7 +321,7 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister foreach ($this->_class->parentClasses as $parentClassName) { $parentClass = $this->_em->getClassMetadata($parentClassName); $tableAlias = $this->_getSQLTableAlias($parentClassName); - $joinSql .= ' INNER JOIN ' . $parentClass->getQuotedTableName($this->_platform) . ' ' . $tableAlias . ' ON '; + $joinSql .= ' INNER JOIN ' . $this->quoteStrategy->getTableName($parentClass) . ' ' . $tableAlias . ' ON '; $first = true; foreach ($idColumns as $idColumn) { @@ -361,7 +361,7 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister } // Add LEFT JOIN - $joinSql .= ' LEFT JOIN ' . $subClass->getQuotedTableName($this->_platform) . ' ' . $tableAlias . ' ON '; + $joinSql .= ' LEFT JOIN ' . $this->quoteStrategy->getTableName($subClass) . ' ' . $tableAlias . ' ON '; $first = true; foreach ($idColumns as $idColumn) { @@ -400,7 +400,7 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister } return $this->_platform->modifyLimitQuery('SELECT ' . $this->_selectColumnListSql - . ' FROM ' . $this->_class->getQuotedTableName($this->_platform) . ' ' . $baseTableAlias + . ' FROM ' . $this->quoteStrategy->getTableName($this->_class) . ' ' . $baseTableAlias . $joinSql . ($conditionSql != '' ? ' WHERE ' . $conditionSql : '') . $orderBySql, $limit, $offset) . $lockSql; @@ -422,7 +422,7 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister foreach ($this->_class->parentClasses as $parentClassName) { $parentClass = $this->_em->getClassMetadata($parentClassName); $tableAlias = $this->_getSQLTableAlias($parentClassName); - $joinSql .= ' INNER JOIN ' . $parentClass->getQuotedTableName($this->_platform) . ' ' . $tableAlias . ' ON '; + $joinSql .= ' INNER JOIN ' . $this->quoteStrategy->getTableName($parentClass) . ' ' . $tableAlias . ' ON '; $first = true; foreach ($idColumns as $idColumn) { @@ -432,7 +432,7 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister } } - return 'FROM ' . $this->_class->getQuotedTableName($this->_platform) . ' ' . $baseTableAlias . $joinSql; + return 'FROM ' .$this->quoteStrategy->getTableName($this->_class) . ' ' . $baseTableAlias . $joinSql; } /* Ensure this method is never called. This persister overrides _getSelectEntitiesSQL directly. */ @@ -463,7 +463,7 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister } } else if ($this->_class->name != $this->_class->rootEntityName || ! $this->_class->isIdGeneratorIdentity() || $this->_class->identifier[0] != $name) { - $columns[] = $this->_class->getQuotedColumnName($name, $this->_platform); + $columns[] = $this->quoteStrategy->getColumnName($name, $this->_class); } } From dcd19bba225fba3843ea4bc7b41d02454a627d0c Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Mon, 4 Jun 2012 12:58:51 -0300 Subject: [PATCH 11/37] use quote strategy in OneToManyPersister --- lib/Doctrine/ORM/Persisters/ManyToManyPersister.php | 2 +- lib/Doctrine/ORM/Persisters/OneToManyPersister.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Doctrine/ORM/Persisters/ManyToManyPersister.php b/lib/Doctrine/ORM/Persisters/ManyToManyPersister.php index f0e57ea20..dbbadadf0 100644 --- a/lib/Doctrine/ORM/Persisters/ManyToManyPersister.php +++ b/lib/Doctrine/ORM/Persisters/ManyToManyPersister.php @@ -45,7 +45,7 @@ class ManyToManyPersister extends AbstractCollectionPersister $mapping = $coll->getMapping(); $class = $this->_em->getClassMetadata(get_class($coll->getOwner())); - return 'DELETE FROM ' . $class->getQuotedJoinTableName($mapping, $this->_conn->getDatabasePlatform()) + return 'DELETE FROM ' . $this->quoteStrategy->getJoinTableName($mapping, $class) . ' WHERE ' . implode(' = ? AND ', $mapping['joinTableColumns']) . ' = ?'; } diff --git a/lib/Doctrine/ORM/Persisters/OneToManyPersister.php b/lib/Doctrine/ORM/Persisters/OneToManyPersister.php index ab586f3a3..ee807e210 100644 --- a/lib/Doctrine/ORM/Persisters/OneToManyPersister.php +++ b/lib/Doctrine/ORM/Persisters/OneToManyPersister.php @@ -45,7 +45,7 @@ class OneToManyPersister extends AbstractCollectionPersister $mapping = $coll->getMapping(); $class = $this->_em->getClassMetadata($mapping['targetEntity']); - return 'DELETE FROM ' . $class->getQuotedTableName($this->_conn->getDatabasePlatform()) + return 'DELETE FROM ' . $this->quoteStrategy->getTableName($class) . ' WHERE ' . implode('= ? AND ', $class->getIdentifierColumnNames()) . ' = ?'; } @@ -127,7 +127,7 @@ class OneToManyPersister extends AbstractCollectionPersister } $sql = 'SELECT count(*)' - . ' FROM ' . $targetClass->getQuotedTableName($this->_conn->getDatabasePlatform()) . ' t' + . ' FROM ' . $this->quoteStrategy->getTableName($targetClass) . ' t' . ' WHERE ' . implode(' AND ', $whereClauses); return $this->_conn->fetchColumn($sql, $params); @@ -204,7 +204,7 @@ class OneToManyPersister extends AbstractCollectionPersister $mapping = $coll->getMapping(); $class = $this->_em->getClassMetadata($mapping['targetEntity']); - $sql = 'DELETE FROM ' . $class->getQuotedTableName($this->_conn->getDatabasePlatform()) + $sql = 'DELETE FROM ' . $this->quoteStrategy->getTableName($class) . ' WHERE ' . implode('= ? AND ', $class->getIdentifierColumnNames()) . ' = ?'; return (bool) $this->_conn->executeUpdate($sql, $this->_getDeleteRowSQLParameters($coll, $element)); From 851d17f940f6018d51ec8478b35f7a2eefff998a Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Mon, 4 Jun 2012 13:01:24 -0300 Subject: [PATCH 12/37] use quote strategy in SingleTablePersister --- lib/Doctrine/ORM/Persisters/SingleTablePersister.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Persisters/SingleTablePersister.php b/lib/Doctrine/ORM/Persisters/SingleTablePersister.php index 5b2ce205b..d8bb9f658 100644 --- a/lib/Doctrine/ORM/Persisters/SingleTablePersister.php +++ b/lib/Doctrine/ORM/Persisters/SingleTablePersister.php @@ -36,7 +36,7 @@ class SingleTablePersister extends AbstractEntityInheritancePersister /** {@inheritdoc} */ protected function _getDiscriminatorColumnTableName() { - return $this->_class->getTableName(); + return $this->quoteStrategy->getTableName($this->_class); } /** {@inheritdoc} */ From 4ef3d99770db76d5a934aced23380ca104de05af Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Mon, 4 Jun 2012 14:26:05 -0300 Subject: [PATCH 13/37] use quote strategy in SizeFunction, MultiTableDeleteExecutor, MultiTableUpdateExecutor, and SchemaTool --- .../ORM/Mapping/ClassMetadataInfo.php | 36 +++++++ .../ORM/Query/AST/Functions/SizeFunction.php | 30 +++--- .../Query/Exec/MultiTableDeleteExecutor.php | 21 ++-- .../Query/Exec/MultiTableUpdateExecutor.php | 24 ++--- lib/Doctrine/ORM/Tools/SchemaTool.php | 95 ++++++++++--------- 5 files changed, 125 insertions(+), 81 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php index b086c1785..8434e49b2 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php @@ -2643,6 +2643,42 @@ class ClassMetadataInfo implements ClassMetadata return $this->name; } + /** + * Gets the (possibly quoted) identifier column names for safe use in an SQL statement. + * + * @param AbstractPlatform $platform + * @return array + */ + public function getQuotedIdentifierColumnNames($platform) + { + $quotedColumnNames = array(); + + foreach ($this->identifier as $idProperty) { + if (isset($this->fieldMappings[$idProperty])) { + $quotedColumnNames[] = isset($this->fieldMappings[$idProperty]['quoted']) + ? $platform->quoteIdentifier($this->fieldMappings[$idProperty]['columnName']) + : $this->fieldMappings[$idProperty]['columnName']; + + continue; + } + + // Association defined as Id field + $joinColumns = $this->associationMappings[$idProperty]['joinColumns']; + $assocQuotedColumnNames = array_map( + function ($joinColumn) { + return isset($joinColumn['quoted']) + ? $platform->quoteIdentifier($joinColumn['name']) + : $joinColumn['name']; + }, + $joinColumns + ); + + $quotedColumnNames = array_merge($quotedColumnNames, $assocQuotedColumnNames); + } + + return $quotedColumnNames; + } + /** * Gets the (possibly quoted) column name of a mapped field for safe use * in an SQL statement. diff --git a/lib/Doctrine/ORM/Query/AST/Functions/SizeFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/SizeFunction.php index e2ed4f95d..b8f83bed0 100644 --- a/lib/Doctrine/ORM/Query/AST/Functions/SizeFunction.php +++ b/lib/Doctrine/ORM/Query/AST/Functions/SizeFunction.php @@ -42,21 +42,21 @@ class SizeFunction extends FunctionNode */ public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) { - $platform = $sqlWalker->getConnection()->getDatabasePlatform(); - $dqlAlias = $this->collectionPathExpression->identificationVariable; - $assocField = $this->collectionPathExpression->field; + $quoteStrategy = $sqlWalker->getEntityManager()->getQuoteStrategy(); + $dqlAlias = $this->collectionPathExpression->identificationVariable; + $assocField = $this->collectionPathExpression->field; - $qComp = $sqlWalker->getQueryComponent($dqlAlias); - $class = $qComp['metadata']; - $assoc = $class->associationMappings[$assocField]; - $sql = 'SELECT COUNT(*) FROM '; + $qComp = $sqlWalker->getQueryComponent($dqlAlias); + $class = $qComp['metadata']; + $assoc = $class->associationMappings[$assocField]; + $sql = 'SELECT COUNT(*) FROM '; if ($assoc['type'] == \Doctrine\ORM\Mapping\ClassMetadata::ONE_TO_MANY) { - $targetClass = $sqlWalker->getEntityManager()->getClassMetadata($assoc['targetEntity']); - $targetTableAlias = $sqlWalker->getSQLTableAlias($targetClass->getTableName()); - $sourceTableAlias = $sqlWalker->getSQLTableAlias($class->getTableName(), $dqlAlias); + $targetClass = $sqlWalker->getEntityManager()->getClassMetadata($assoc['targetEntity']); + $targetTableAlias = $sqlWalker->getSQLTableAlias($targetClass->getTableName()); + $sourceTableAlias = $sqlWalker->getSQLTableAlias($class->getTableName(), $dqlAlias); - $sql .= $targetClass->getQuotedTableName($platform) . ' ' . $targetTableAlias . ' WHERE '; + $sql .= $quoteStrategy->getTableName($targetClass) . ' ' . $targetTableAlias . ' WHERE '; $owningAssoc = $targetClass->associationMappings[$assoc['mappedBy']]; @@ -67,7 +67,7 @@ class SizeFunction extends FunctionNode $sql .= $targetTableAlias . '.' . $sourceColumn . ' = ' - . $sourceTableAlias . '.' . $class->getQuotedColumnName($class->fieldNames[$targetColumn], $platform); + . $sourceTableAlias . '.' . $quoteStrategy->getColumnName($class->fieldNames[$targetColumn], $class); } } else { // many-to-many $targetClass = $sqlWalker->getEntityManager()->getClassMetadata($assoc['targetEntity']); @@ -80,7 +80,7 @@ class SizeFunction extends FunctionNode $sourceTableAlias = $sqlWalker->getSQLTableAlias($class->getTableName(), $dqlAlias); // join to target table - $sql .= $targetClass->getQuotedJoinTableName($owningAssoc, $platform) . ' ' . $joinTableAlias . ' WHERE '; + $sql .= $quoteStrategy->getJoinTableName($owningAssoc, $targetClass) . ' ' . $joinTableAlias . ' WHERE '; $joinColumns = $assoc['isOwningSide'] ? $joinTable['joinColumns'] @@ -91,8 +91,8 @@ class SizeFunction extends FunctionNode foreach ($joinColumns as $joinColumn) { if ($first) $first = false; else $sql .= ' AND '; - $sourceColumnName = $class->getQuotedColumnName( - $class->fieldNames[$joinColumn['referencedColumnName']], $platform + $sourceColumnName = $quoteStrategy->getColumnName( + $class->fieldNames[$joinColumn['referencedColumnName']], $class ); $sql .= $joinTableAlias . '.' . $joinColumn['name'] diff --git a/lib/Doctrine/ORM/Query/Exec/MultiTableDeleteExecutor.php b/lib/Doctrine/ORM/Query/Exec/MultiTableDeleteExecutor.php index 02cc8a54b..5bb37834b 100644 --- a/lib/Doctrine/ORM/Query/Exec/MultiTableDeleteExecutor.php +++ b/lib/Doctrine/ORM/Query/Exec/MultiTableDeleteExecutor.php @@ -47,17 +47,18 @@ class MultiTableDeleteExecutor extends AbstractSqlExecutor */ public function __construct(AST\Node $AST, $sqlWalker) { - $em = $sqlWalker->getEntityManager(); - $conn = $em->getConnection(); - $platform = $conn->getDatabasePlatform(); + $em = $sqlWalker->getEntityManager(); + $conn = $em->getConnection(); + $platform = $conn->getDatabasePlatform(); + $quoteStrategy = $em->getQuoteStrategy(); - $primaryClass = $em->getClassMetadata($AST->deleteClause->abstractSchemaName); - $primaryDqlAlias = $AST->deleteClause->aliasIdentificationVariable; - $rootClass = $em->getClassMetadata($primaryClass->rootEntityName); + $primaryClass = $em->getClassMetadata($AST->deleteClause->abstractSchemaName); + $primaryDqlAlias = $AST->deleteClause->aliasIdentificationVariable; + $rootClass = $em->getClassMetadata($primaryClass->rootEntityName); - $tempTable = $platform->getTemporaryTableName($rootClass->getTemporaryIdTableName()); - $idColumnNames = $rootClass->getIdentifierColumnNames(); - $idColumnList = implode(', ', $idColumnNames); + $tempTable = $platform->getTemporaryTableName($rootClass->getTemporaryIdTableName()); + $idColumnNames = $rootClass->getIdentifierColumnNames(); + $idColumnList = implode(', ', $idColumnNames); // 1. Create an INSERT INTO temptable ... SELECT identifiers WHERE $AST->getWhereClause() $sqlWalker->setSQLTableAlias($primaryClass->getTableName(), 't0', $primaryDqlAlias); @@ -80,7 +81,7 @@ class MultiTableDeleteExecutor extends AbstractSqlExecutor // 3. Create and store DELETE statements $classNames = array_merge($primaryClass->parentClasses, array($primaryClass->name), $primaryClass->subClasses); foreach (array_reverse($classNames) as $className) { - $tableName = $em->getClassMetadata($className)->getQuotedTableName($platform); + $tableName = $quoteStrategy->getTableName($em->getClassMetadata($className)); $this->_sqlStatements[] = 'DELETE FROM ' . $tableName . ' WHERE (' . $idColumnList . ') IN (' . $idSubselect . ')'; } diff --git a/lib/Doctrine/ORM/Query/Exec/MultiTableUpdateExecutor.php b/lib/Doctrine/ORM/Query/Exec/MultiTableUpdateExecutor.php index 575e6dfb8..9f18ff8e8 100644 --- a/lib/Doctrine/ORM/Query/Exec/MultiTableUpdateExecutor.php +++ b/lib/Doctrine/ORM/Query/Exec/MultiTableUpdateExecutor.php @@ -50,20 +50,20 @@ class MultiTableUpdateExecutor extends AbstractSqlExecutor */ public function __construct(AST\Node $AST, $sqlWalker) { - $em = $sqlWalker->getEntityManager(); - $conn = $em->getConnection(); - $platform = $conn->getDatabasePlatform(); + $em = $sqlWalker->getEntityManager(); + $conn = $em->getConnection(); + $platform = $conn->getDatabasePlatform(); + $quoteStrategy = $em->getQuoteStrategy(); - $updateClause = $AST->updateClause; + $updateClause = $AST->updateClause; + $primaryClass = $sqlWalker->getEntityManager()->getClassMetadata($updateClause->abstractSchemaName); + $rootClass = $em->getClassMetadata($primaryClass->rootEntityName); - $primaryClass = $sqlWalker->getEntityManager()->getClassMetadata($updateClause->abstractSchemaName); - $rootClass = $em->getClassMetadata($primaryClass->rootEntityName); + $updateItems = $updateClause->updateItems; - $updateItems = $updateClause->updateItems; - - $tempTable = $platform->getTemporaryTableName($rootClass->getTemporaryIdTableName()); - $idColumnNames = $rootClass->getIdentifierColumnNames(); - $idColumnList = implode(', ', $idColumnNames); + $tempTable = $platform->getTemporaryTableName($rootClass->getTemporaryIdTableName()); + $idColumnNames = $rootClass->getIdentifierColumnNames(); + $idColumnList = implode(', ', $idColumnNames); // 1. Create an INSERT INTO temptable ... SELECT identifiers WHERE $AST->getWhereClause() $sqlWalker->setSQLTableAlias($primaryClass->getTableName(), 't0', $updateClause->aliasIdentificationVariable); @@ -86,7 +86,7 @@ class MultiTableUpdateExecutor extends AbstractSqlExecutor foreach (array_reverse($classNames) as $className) { $affected = false; $class = $em->getClassMetadata($className); - $updateSql = 'UPDATE ' . $class->getQuotedTableName($platform) . ' SET '; + $updateSql = 'UPDATE ' . $quoteStrategy->getTableName($class) . ' SET '; foreach ($updateItems as $updateItem) { $field = $updateItem->pathExpression->field; diff --git a/lib/Doctrine/ORM/Tools/SchemaTool.php b/lib/Doctrine/ORM/Tools/SchemaTool.php index 3955b8c3d..d3cc44407 100644 --- a/lib/Doctrine/ORM/Tools/SchemaTool.php +++ b/lib/Doctrine/ORM/Tools/SchemaTool.php @@ -47,12 +47,19 @@ class SchemaTool /** * @var \Doctrine\ORM\EntityManager */ - private $_em; + private $em; /** * @var \Doctrine\DBAL\Platforms\AbstractPlatform */ - private $_platform; + private $platform; + + /** + * The quote strategy. + * + * @var \Doctrine\ORM\Mapping\QuoteStrategy + */ + protected $quoteStrategy; /** * Initializes a new SchemaTool instance that uses the connection of the @@ -62,8 +69,9 @@ class SchemaTool */ public function __construct(EntityManager $em) { - $this->_em = $em; - $this->_platform = $em->getConnection()->getDatabasePlatform(); + $this->em = $em; + $this->quoteStrategy = $em->getQuoteStrategy(); + $this->platform = $em->getConnection()->getDatabasePlatform(); } /** @@ -76,7 +84,7 @@ class SchemaTool public function createSchema(array $classes) { $createSchemaSql = $this->getCreateSchemaSql($classes); - $conn = $this->_em->getConnection(); + $conn = $this->em->getConnection(); foreach ($createSchemaSql as $sql) { try { @@ -97,7 +105,7 @@ class SchemaTool public function getCreateSchemaSql(array $classes) { $schema = $this->getSchemaFromMetadata($classes); - return $schema->toSql($this->_platform); + return $schema->toSql($this->platform); } /** @@ -124,23 +132,22 @@ class SchemaTool */ public function getSchemaFromMetadata(array $classes) { - $processedClasses = array(); // Reminder for processed classes, used for hierarchies + // Reminder for processed classes, used for hierarchies + $processedClasses = array(); + $eventManager = $this->em->getEventManager(); + $schemaManager = $this->em->getConnection()->getSchemaManager(); + $metadataSchemaConfig = $schemaManager->createSchemaConfig(); - $sm = $this->_em->getConnection()->getSchemaManager(); - $metadataSchemaConfig = $sm->createSchemaConfig(); $metadataSchemaConfig->setExplicitForeignKeyIndexes(false); $schema = new Schema(array(), array(), $metadataSchemaConfig); - $evm = $this->_em->getEventManager(); - foreach ($classes as $class) { if ($this->processingNotRequired($class, $processedClasses)) { continue; } - $table = $schema->createTable($class->getQuotedTableName($this->_platform)); - - $columns = array(); // table columns + $table = $schema->createTable($this->quoteStrategy->getTableName($class)); + $columns = array(); // table columns if ($class->isInheritanceTypeSingleTable()) { $columns = $this->_gatherColumns($class, $table); @@ -156,7 +163,7 @@ class SchemaTool } foreach ($class->subClasses as $subClassName) { - $subClass = $this->_em->getClassMetadata($subClassName); + $subClass = $this->em->getClassMetadata($subClassName); $this->_gatherColumns($subClass, $table); $this->_gatherRelationsSql($subClass, $table, $schema); $processedClasses[$subClassName] = true; @@ -166,7 +173,7 @@ class SchemaTool $pkColumns = array(); foreach ($class->fieldMappings as $fieldName => $mapping) { if ( ! isset($mapping['inherited'])) { - $columnName = $class->getQuotedColumnName($mapping['fieldName'], $this->_platform); + $columnName = $this->quoteStrategy->getColumnName($mapping['fieldName'], $class); $this->_gatherColumn($class, $mapping, $table); if ($class->isIdentifier($fieldName)) { @@ -185,7 +192,7 @@ class SchemaTool /* @var \Doctrine\ORM\Mapping\ClassMetadata $class */ $idMapping = $class->fieldMappings[$class->identifier[0]]; $this->_gatherColumn($class, $idMapping, $table); - $columnName = $class->getQuotedColumnName($class->identifier[0], $this->_platform); + $columnName = $this->quoteStrategy->getColumnName($class->identifier[0], $class); // TODO: This seems rather hackish, can we optimize it? $table->getColumn($columnName)->setAutoincrement(false); @@ -193,7 +200,7 @@ class SchemaTool // Add a FK constraint on the ID column $table->addUnnamedForeignKeyConstraint( - $this->_em->getClassMetadata($class->rootEntityName)->getQuotedTableName($this->_platform), + $this->quoteStrategy->getTableName($this->em->getClassMetadata($class->rootEntityName)), array($columnName), array($columnName), array('onDelete' => 'CASCADE') ); } @@ -210,7 +217,7 @@ class SchemaTool $pkColumns = array(); foreach ($class->identifier as $identifierField) { if (isset($class->fieldMappings[$identifierField])) { - $pkColumns[] = $class->getQuotedColumnName($identifierField, $this->_platform); + $pkColumns[] = $this->quoteStrategy->getColumnName($identifierField, $class); } else if (isset($class->associationMappings[$identifierField])) { /* @var $assoc \Doctrine\ORM\Mapping\OneToOne */ $assoc = $class->associationMappings[$identifierField]; @@ -255,17 +262,17 @@ class SchemaTool } } - if ($evm->hasListeners(ToolEvents::postGenerateSchemaTable)) { - $evm->dispatchEvent(ToolEvents::postGenerateSchemaTable, new GenerateSchemaTableEventArgs($class, $schema, $table)); + if ($eventManager->hasListeners(ToolEvents::postGenerateSchemaTable)) { + $eventManager->dispatchEvent(ToolEvents::postGenerateSchemaTable, new GenerateSchemaTableEventArgs($class, $schema, $table)); } } - if ( ! $this->_platform->supportsSchemas() && ! $this->_platform->canEmulateSchemas() ) { + if ( ! $this->platform->supportsSchemas() && ! $this->platform->canEmulateSchemas() ) { $schema->visit(new RemoveNamespacedAssets()); } - if ($evm->hasListeners(ToolEvents::postGenerateSchema)) { - $evm->dispatchEvent(ToolEvents::postGenerateSchema, new GenerateSchemaEventArgs($this->_em, $schema)); + if ($eventManager->hasListeners(ToolEvents::postGenerateSchema)) { + $eventManager->dispatchEvent(ToolEvents::postGenerateSchema, new GenerateSchemaEventArgs($this->em, $schema)); } return $schema; @@ -321,7 +328,7 @@ class SchemaTool $column = $this->_gatherColumn($class, $mapping, $table); if ($class->isIdentifier($mapping['fieldName'])) { - $pkColumns[] = $class->getQuotedColumnName($mapping['fieldName'], $this->_platform); + $pkColumns[] = $this->quoteStrategy->getColumnName($mapping['fieldName'], $class); } } @@ -344,7 +351,7 @@ class SchemaTool */ private function _gatherColumn($class, array $mapping, $table) { - $columnName = $class->getQuotedColumnName($mapping['fieldName'], $this->_platform); + $columnName = $this->quoteStrategy->getColumnName($mapping['fieldName'], $class); $columnType = $mapping['type']; $options = array(); @@ -417,7 +424,7 @@ class SchemaTool continue; } - $foreignClass = $this->_em->getClassMetadata($mapping['targetEntity']); + $foreignClass = $this->em->getClassMetadata($mapping['targetEntity']); if ($mapping['type'] & ClassMetadata::TO_ONE && $mapping['isOwningSide']) { $primaryKeyColumns = $uniqueConstraints = array(); // PK is unnecessary for this relation-type @@ -434,7 +441,7 @@ class SchemaTool // create join table $joinTable = $mapping['joinTable']; - $theJoinTable = $schema->createTable($foreignClass->getQuotedJoinTableName($mapping, $this->_platform)); + $theJoinTable = $schema->createTable($this->quoteStrategy->getJoinTableName($mapping, $foreignClass)); $primaryKeyColumns = $uniqueConstraints = array(); @@ -477,7 +484,7 @@ class SchemaTool foreach ($class->getIdentifierFieldNames() as $fieldName) { if ($class->hasAssociation($fieldName) && $class->getSingleAssociationJoinColumnName($fieldName) == $referencedColumnName) { return $this->getDefiningClass( - $this->_em->getClassMetadata($class->associationMappings[$fieldName]['targetEntity']), + $this->em->getClassMetadata($class->associationMappings[$fieldName]['targetEntity']), $class->getSingleAssociationReferencedJoinColumnName($fieldName) ); } @@ -499,10 +506,10 @@ class SchemaTool */ private function _gatherRelationJoinColumns($joinColumns, $theJoinTable, $class, $mapping, &$primaryKeyColumns, &$uniqueConstraints) { - $localColumns = array(); - $foreignColumns = array(); - $fkOptions = array(); - $foreignTableName = $class->getQuotedTableName($this->_platform); + $localColumns = array(); + $foreignColumns = array(); + $fkOptions = array(); + $foreignTableName = $this->quoteStrategy->getTableName($class); foreach ($joinColumns as $joinColumn) { $columnName = $joinColumn['name']; @@ -572,7 +579,7 @@ class SchemaTool public function dropSchema(array $classes) { $dropSchemaSql = $this->getDropSchemaSQL($classes); - $conn = $this->_em->getConnection(); + $conn = $this->em->getConnection(); foreach ($dropSchemaSql as $sql) { try { @@ -591,7 +598,7 @@ class SchemaTool public function dropDatabase() { $dropSchemaSql = $this->getDropDatabaseSQL(); - $conn = $this->_em->getConnection(); + $conn = $this->em->getConnection(); foreach ($dropSchemaSql as $sql) { $conn->executeQuery($sql); @@ -605,10 +612,10 @@ class SchemaTool */ public function getDropDatabaseSQL() { - $sm = $this->_em->getConnection()->getSchemaManager(); + $sm = $this->em->getConnection()->getSchemaManager(); $schema = $sm->createSchema(); - $visitor = new \Doctrine\DBAL\Schema\Visitor\DropSchemaSqlCollector($this->_platform); + $visitor = new \Doctrine\DBAL\Schema\Visitor\DropSchemaSqlCollector($this->platform); /* @var $schema \Doctrine\DBAL\Schema\Schema */ $schema->visit($visitor); return $visitor->getQueries(); @@ -622,10 +629,10 @@ class SchemaTool */ public function getDropSchemaSQL(array $classes) { - $visitor = new \Doctrine\DBAL\Schema\Visitor\DropSchemaSqlCollector($this->_platform); + $visitor = new \Doctrine\DBAL\Schema\Visitor\DropSchemaSqlCollector($this->platform); $schema = $this->getSchemaFromMetadata($classes); - $sm = $this->_em->getConnection()->getSchemaManager(); + $sm = $this->em->getConnection()->getSchemaManager(); $fullSchema = $sm->createSchema(); foreach ($fullSchema->getTables() as $table) { if (!$schema->hasTable($table->getName())) { @@ -643,7 +650,7 @@ class SchemaTool } } - if ($this->_platform->supportsSequences()) { + if ($this->platform->supportsSequences()) { foreach ($schema->getSequences() as $sequence) { $visitor->acceptSequence($sequence); } @@ -676,7 +683,7 @@ class SchemaTool public function updateSchema(array $classes, $saveMode=false) { $updateSchemaSql = $this->getUpdateSchemaSql($classes, $saveMode); - $conn = $this->_em->getConnection(); + $conn = $this->em->getConnection(); foreach ($updateSchemaSql as $sql) { $conn->executeQuery($sql); @@ -695,7 +702,7 @@ class SchemaTool */ public function getUpdateSchemaSql(array $classes, $saveMode=false) { - $sm = $this->_em->getConnection()->getSchemaManager(); + $sm = $this->em->getConnection()->getSchemaManager(); $fromSchema = $sm->createSchema(); $toSchema = $this->getSchemaFromMetadata($classes); @@ -704,9 +711,9 @@ class SchemaTool $schemaDiff = $comparator->compare($fromSchema, $toSchema); if ($saveMode) { - return $schemaDiff->toSaveSql($this->_platform); + return $schemaDiff->toSaveSql($this->platform); } else { - return $schemaDiff->toSql($this->_platform); + return $schemaDiff->toSql($this->platform); } } } From fabfb6629344a083181f71ba9d80e2a2ed945004 Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Mon, 4 Jun 2012 14:34:35 -0300 Subject: [PATCH 14/37] deprecated metadata quote methods --- lib/Doctrine/ORM/Configuration.php | 2 +- lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/Doctrine/ORM/Configuration.php b/lib/Doctrine/ORM/Configuration.php index 3f37f479f..67dcc5ba7 100644 --- a/lib/Doctrine/ORM/Configuration.php +++ b/lib/Doctrine/ORM/Configuration.php @@ -638,7 +638,7 @@ class Configuration extends \Doctrine\DBAL\Configuration */ public function setQuoteStrategyClassName($className) { - $quoteStrategy = 'Doctrine\ORM\Mapping\AbstractQuoteStrategy'; + $quoteStrategy = 'Doctrine\ORM\Mapping\QuoteStrategy'; if ($className !== $quoteStrategy && ! is_subclass_of($className, $quoteStrategy)) { throw new \InvalidArgumentException("Invalid quote strategy class"); diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php index 8434e49b2..d93d86214 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php @@ -2646,6 +2646,8 @@ class ClassMetadataInfo implements ClassMetadata /** * Gets the (possibly quoted) identifier column names for safe use in an SQL statement. * + * @deprecated Deprecated since version 2.3 in favor of \Doctrine\ORM\Mapping\QuoteStrategy + * * @param AbstractPlatform $platform * @return array */ @@ -2680,8 +2682,9 @@ class ClassMetadataInfo implements ClassMetadata } /** - * Gets the (possibly quoted) column name of a mapped field for safe use - * in an SQL statement. + * Gets the (possibly quoted) column name of a mapped field for safe use in an SQL statement. + * + * @deprecated Deprecated since version 2.3 in favor of \Doctrine\ORM\Mapping\QuoteStrategy * * @param string $field * @param AbstractPlatform $platform @@ -2695,8 +2698,9 @@ class ClassMetadataInfo implements ClassMetadata } /** - * Gets the (possibly quoted) primary table name of this class for safe use - * in an SQL statement. + * Gets the (possibly quoted) primary table name of this class for safe use in an SQL statement. + * + * @deprecated Deprecated since version 2.3 in favor of \Doctrine\ORM\Mapping\QuoteStrategy * * @param AbstractPlatform $platform * @return string @@ -2709,6 +2713,8 @@ class ClassMetadataInfo implements ClassMetadata /** * Gets the (possibly quoted) name of the join table. * + * @deprecated Deprecated since version 2.3 in favor of \Doctrine\ORM\Mapping\QuoteStrategy + * * @param AbstractPlatform $platform * @return string */ From 8fec73673d056b443147e60ad7ed466d5cb71513 Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Mon, 4 Jun 2012 15:16:20 -0300 Subject: [PATCH 15/37] fix DDC-1719 in persiter and query level --- lib/Doctrine/ORM/Configuration.php | 4 ++-- lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php | 5 +++++ lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php | 3 +-- lib/Doctrine/ORM/Mapping/QuoteStrategy.php | 5 ++--- lib/Doctrine/ORM/Persisters/BasicEntityPersister.php | 2 +- lib/Doctrine/ORM/Tools/SchemaTool.php | 3 ++- tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1719Test.php | 2 -- tests/Doctrine/Tests/ORM/Mapping/QuoteStrategyTest.php | 2 -- 8 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/Doctrine/ORM/Configuration.php b/lib/Doctrine/ORM/Configuration.php index 67dcc5ba7..a0c1da563 100644 --- a/lib/Doctrine/ORM/Configuration.php +++ b/lib/Doctrine/ORM/Configuration.php @@ -633,7 +633,7 @@ class Configuration extends \Doctrine\DBAL\Configuration /** * Set quote strategy class. * - * @since 2.4 + * @since 2.3 * @param string $className */ public function setQuoteStrategyClassName($className) @@ -650,7 +650,7 @@ class Configuration extends \Doctrine\DBAL\Configuration /** * Get quote strategy class. * - * @since 2.4 + * @since 2.3 * @return string */ public function getQuoteStrategyClassName() diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php index d93d86214..24131d17e 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php @@ -1379,6 +1379,11 @@ class ClassMetadataInfo implements ClassMetadata if (empty($joinColumn['referencedColumnName'])) { $joinColumn['referencedColumnName'] = $this->namingStrategy->referenceColumnName(); } + if ($joinColumn['name'][0] == '`') { + $joinColumn['name'] = trim($joinColumn['name'], '`'); + $joinColumn['quoted'] = true; + } + $mapping['sourceToTargetKeyColumns'][$joinColumn['name']] = $joinColumn['referencedColumnName']; $mapping['joinColumnFieldNames'][$joinColumn['name']] = isset($joinColumn['fieldName']) ? $joinColumn['fieldName'] : $joinColumn['name']; diff --git a/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php b/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php index a887d407e..763e8784d 100644 --- a/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php +++ b/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php @@ -1,5 +1,4 @@ . */ diff --git a/lib/Doctrine/ORM/Mapping/QuoteStrategy.php b/lib/Doctrine/ORM/Mapping/QuoteStrategy.php index 4d42c4460..a7b7798dd 100644 --- a/lib/Doctrine/ORM/Mapping/QuoteStrategy.php +++ b/lib/Doctrine/ORM/Mapping/QuoteStrategy.php @@ -1,5 +1,4 @@ . */ @@ -28,7 +27,7 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; * * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @link www.doctrine-project.org - * @since 2.4 + * @since 2.3 * @author Fabio B. Silva */ abstract class QuoteStrategy diff --git a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php index e0809fa7b..6ff0568cf 100644 --- a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php @@ -469,7 +469,7 @@ class BasicEntityPersister $identifier = $this->_em->getUnitOfWork()->getEntityIdentifier($entity); $this->deleteJoinTableRecords($identifier); - $id = array_combine($this->_class->getIdentifierColumnNames(), $identifier); + $id = array_combine($this->quoteStrategy->getIdentifierColumnNames($this->_class), $identifier); $this->_conn->delete($this->quoteStrategy->getTableName($this->_class), $id); } diff --git a/lib/Doctrine/ORM/Tools/SchemaTool.php b/lib/Doctrine/ORM/Tools/SchemaTool.php index d3cc44407..1f69e0057 100644 --- a/lib/Doctrine/ORM/Tools/SchemaTool.php +++ b/lib/Doctrine/ORM/Tools/SchemaTool.php @@ -217,7 +217,7 @@ class SchemaTool $pkColumns = array(); foreach ($class->identifier as $identifierField) { if (isset($class->fieldMappings[$identifierField])) { - $pkColumns[] = $this->quoteStrategy->getColumnName($identifierField, $class); + $pkColumns[] = $class->getColumnName($identifierField); } else if (isset($class->associationMappings[$identifierField])) { /* @var $assoc \Doctrine\ORM\Mapping\OneToOne */ $assoc = $class->associationMappings[$identifierField]; @@ -226,6 +226,7 @@ class SchemaTool } } } + if (!$table->hasIndex('primary')) { $table->setPrimaryKey($pkColumns); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1719Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1719Test.php index cab55c609..1d5a2065b 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1719Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1719Test.php @@ -16,8 +16,6 @@ class DDC1719Test extends \Doctrine\Tests\OrmFunctionalTestCase protected function setUp() { - $this->markTestIncomplete(); - parent::setUp(); try { $this->_schemaTool->createSchema(array( diff --git a/tests/Doctrine/Tests/ORM/Mapping/QuoteStrategyTest.php b/tests/Doctrine/Tests/ORM/Mapping/QuoteStrategyTest.php index 3f5c66f20..50b87c159 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/QuoteStrategyTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/QuoteStrategyTest.php @@ -138,8 +138,6 @@ class QuoteStrategyTest extends \Doctrine\Tests\OrmTestCase public function testQuoteJoinColumnNames() { - $this->markTestIncomplete(); - $cm = $this->createClassMetadata('Doctrine\Tests\Models\DDC117\DDC117ArticleDetails'); $cm->mapOneToOne(array( From f335f231455dd696a7d7fa5c4f31ed143d5b88aa Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Mon, 4 Jun 2012 16:56:46 -0300 Subject: [PATCH 16/37] tests for quoted columns metadata --- .../ORM/Mapping/ClassMetadataInfo.php | 34 +++++++++ .../ORM/Mapping/DefaultQuoteStrategy.php | 20 +---- lib/Doctrine/ORM/Mapping/QuoteStrategy.php | 18 ----- tests/Doctrine/Tests/Models/Quote/Address.php | 30 ++++++++ tests/Doctrine/Tests/Models/Quote/Group.php | 29 ++++++++ tests/Doctrine/Tests/Models/Quote/Phone.php | 24 ++++++ .../SimpleEntity.php} | 10 +-- tests/Doctrine/Tests/Models/Quote/User.php | 61 +++++++++++++++ .../ORM/Functional/Ticket/DDC1719Test.php | 8 +- .../ORM/Mapping/ClassMetadataFactoryTest.php | 74 +++++++++++++++++++ .../Tests/ORM/Mapping/QuoteStrategyTest.php | 16 ---- .../BasicEntityPersisterTypeValueSqlTest.php | 4 +- .../ORM/Query/SelectSqlGenerationTest.php | 12 +-- 13 files changed, 270 insertions(+), 70 deletions(-) create mode 100644 tests/Doctrine/Tests/Models/Quote/Address.php create mode 100644 tests/Doctrine/Tests/Models/Quote/Group.php create mode 100644 tests/Doctrine/Tests/Models/Quote/Phone.php rename tests/Doctrine/Tests/Models/{DDC1719/DDC1719Entity.php => Quote/SimpleEntity.php} (56%) create mode 100644 tests/Doctrine/Tests/Models/Quote/User.php diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php index 24131d17e..69d8c20cc 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php @@ -1373,17 +1373,25 @@ class ClassMetadataInfo implements ClassMetadata $uniqueContraintColumns[] = $joinColumn['name']; } } + if (empty($joinColumn['name'])) { $joinColumn['name'] = $this->namingStrategy->joinColumnName($mapping['fieldName']); } + if (empty($joinColumn['referencedColumnName'])) { $joinColumn['referencedColumnName'] = $this->namingStrategy->referenceColumnName(); } + if ($joinColumn['name'][0] == '`') { $joinColumn['name'] = trim($joinColumn['name'], '`'); $joinColumn['quoted'] = true; } + if ($joinColumn['referencedColumnName'][0] == '`') { + $joinColumn['referencedColumnName'] = trim($joinColumn['referencedColumnName'], '`'); + $joinColumn['quoted'] = true; + } + $mapping['sourceToTargetKeyColumns'][$joinColumn['name']] = $joinColumn['referencedColumnName']; $mapping['joinColumnFieldNames'][$joinColumn['name']] = isset($joinColumn['fieldName']) ? $joinColumn['fieldName'] : $joinColumn['name']; @@ -1464,12 +1472,25 @@ class ClassMetadataInfo implements ClassMetadata if (empty($joinColumn['name'])) { $joinColumn['name'] = $this->namingStrategy->joinKeyColumnName($mapping['sourceEntity'], $joinColumn['referencedColumnName']); } + if (empty($joinColumn['referencedColumnName'])) { $joinColumn['referencedColumnName'] = $this->namingStrategy->referenceColumnName(); } + + if ($joinColumn['name'][0] == '`') { + $joinColumn['name'] = trim($joinColumn['name'], '`'); + $joinColumn['quoted'] = true; + } + + if ($joinColumn['referencedColumnName'][0] == '`') { + $joinColumn['referencedColumnName'] = trim($joinColumn['referencedColumnName'], '`'); + $joinColumn['quoted'] = true; + } + if (isset($joinColumn['onDelete']) && strtolower($joinColumn['onDelete']) == 'cascade') { $mapping['isOnDeleteCascade'] = true; } + $mapping['relationToSourceKeyColumns'][$joinColumn['name']] = $joinColumn['referencedColumnName']; $mapping['joinTableColumns'][] = $joinColumn['name']; } @@ -1478,12 +1499,25 @@ class ClassMetadataInfo implements ClassMetadata if (empty($inverseJoinColumn['name'])) { $inverseJoinColumn['name'] = $this->namingStrategy->joinKeyColumnName($mapping['targetEntity'], $inverseJoinColumn['referencedColumnName']); } + if (empty($inverseJoinColumn['referencedColumnName'])) { $inverseJoinColumn['referencedColumnName'] = $this->namingStrategy->referenceColumnName(); } + + if ($inverseJoinColumn['name'][0] == '`') { + $inverseJoinColumn['name'] = trim($inverseJoinColumn['name'], '`'); + $inverseJoinColumn['quoted'] = true; + } + + if ($inverseJoinColumn['referencedColumnName'][0] == '`') { + $inverseJoinColumn['referencedColumnName'] = trim($inverseJoinColumn['referencedColumnName'], '`'); + $inverseJoinColumn['quoted'] = true; + } + if (isset($inverseJoinColumn['onDelete']) && strtolower($inverseJoinColumn['onDelete']) == 'cascade') { $mapping['isOnDeleteCascade'] = true; } + $mapping['relationToTargetKeyColumns'][$inverseJoinColumn['name']] = $inverseJoinColumn['referencedColumnName']; $mapping['joinTableColumns'][] = $inverseJoinColumn['name']; } diff --git a/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php b/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php index 763e8784d..3e09f1929 100644 --- a/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php +++ b/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php @@ -23,30 +23,12 @@ namespace Doctrine\ORM\Mapping; /** * A set of rules for determining the physical column, alias and table quotes * - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link www.doctrine-project.org - * @since 2.4 + * @since 2.3 * @author Fabio B. Silva */ class DefaultQuoteStrategy extends QuoteStrategy { - /** - * {@inheritdoc} - */ - public function isQuotedIdentifier($identifier) - { - return strlen($identifier) > 0 && $identifier[0] === '`'; - } - - /** - * {@inheritdoc} - */ - public function getUnquotedIdentifier($identifier) - { - return trim($identifier, '`'); - } - /** * {@inheritdoc} */ diff --git a/lib/Doctrine/ORM/Mapping/QuoteStrategy.php b/lib/Doctrine/ORM/Mapping/QuoteStrategy.php index a7b7798dd..5882783ad 100644 --- a/lib/Doctrine/ORM/Mapping/QuoteStrategy.php +++ b/lib/Doctrine/ORM/Mapping/QuoteStrategy.php @@ -25,8 +25,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; /** * A set of rules for determining the physical column, alias and table quotes * - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link www.doctrine-project.org * @since 2.3 * @author Fabio B. Silva */ @@ -45,22 +43,6 @@ 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. * diff --git a/tests/Doctrine/Tests/Models/Quote/Address.php b/tests/Doctrine/Tests/Models/Quote/Address.php new file mode 100644 index 000000000..3597687d5 --- /dev/null +++ b/tests/Doctrine/Tests/Models/Quote/Address.php @@ -0,0 +1,30 @@ +phones = new ArrayCollection; + $this->groups = new ArrayCollection; + } + +} diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1719Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1719Test.php index 1d5a2065b..93b3458e6 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1719Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1719Test.php @@ -2,7 +2,7 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; -use Doctrine\Tests\Models\DDC1719\DDC1719Entity; +use Doctrine\Tests\Models\Quote\SimpleEntity; require_once __DIR__ . '/../../../TestInit.php'; @@ -12,7 +12,7 @@ require_once __DIR__ . '/../../../TestInit.php'; class DDC1719Test extends \Doctrine\Tests\OrmFunctionalTestCase { - const CLASS_NAME = '\Doctrine\Tests\Models\DDC1719\DDC1719Entity'; + const CLASS_NAME = '\Doctrine\Tests\Models\Quote\SimpleEntity'; protected function setUp() { @@ -27,8 +27,8 @@ class DDC1719Test extends \Doctrine\Tests\OrmFunctionalTestCase public function testCreateRetreaveUpdateDelete() { - $e1 = new DDC1719Entity('Bar 1'); - $e2 = new DDC1719Entity('Foo 1'); + $e1 = new SimpleEntity('Bar 1'); + $e2 = new SimpleEntity('Foo 1'); // Create $this->_em->persist($e1); diff --git a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php index 2a2f46ce3..f72659336 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php @@ -243,6 +243,80 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase $cm1->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_AUTO); return $cm1; } + + /** + * @group DDC-1845 + */ + public function testQuoteMetadata() + { + $cmf = new ClassMetadataFactory(); + $driver = $this->createAnnotationDriver(array(__DIR__ . '/../../Models/Quote/')); + $em = $this->_createEntityManager($driver); + $cmf->setEntityManager($em); + + + $userMetadata = $cmf->getMetadataFor('Doctrine\Tests\Models\Quote\User'); + $phoneMetadata = $cmf->getMetadataFor('Doctrine\Tests\Models\Quote\Phone'); + $groupMetadata = $cmf->getMetadataFor('Doctrine\Tests\Models\Quote\Group'); + $addressMetadata = $cmf->getMetadataFor('Doctrine\Tests\Models\Quote\Address'); + + + // Phone Class Metadata + $this->assertTrue($phoneMetadata->fieldMappings['number']['quoted']); + $this->assertEquals('phone-number', $phoneMetadata->fieldMappings['number']['columnName']); + + $user = $phoneMetadata->associationMappings['user']; + $this->assertTrue($user['joinColumns'][0]['quoted']); + $this->assertEquals('user-id', $user['joinColumns'][0]['name']); + $this->assertEquals('user-id', $user['joinColumns'][0]['referencedColumnName']); + + + + // User Class Metadata + $this->assertTrue($groupMetadata->fieldMappings['id']['quoted']); + $this->assertTrue($groupMetadata->fieldMappings['name']['quoted']); + + $this->assertEquals('user-id', $userMetadata->fieldMappings['id']['columnName']); + $this->assertEquals('user-name', $userMetadata->fieldMappings['name']['columnName']); + + + + // Address Class Metadata + $this->assertTrue($addressMetadata->fieldMappings['id']['quoted']); + $this->assertTrue($addressMetadata->fieldMappings['zip']['quoted']); + + $this->assertEquals('address-id', $addressMetadata->fieldMappings['id']['columnName']); + $this->assertEquals('address-zip', $addressMetadata->fieldMappings['zip']['columnName']); + + $user = $addressMetadata->associationMappings['user']; + $this->assertTrue($user['joinColumns'][0]['quoted']); + $this->assertEquals('user-id', $user['joinColumns'][0]['name']); + $this->assertEquals('user-id', $user['joinColumns'][0]['referencedColumnName']); + + + + // User Class Metadata + $this->assertTrue($userMetadata->fieldMappings['id']['quoted']); + $this->assertTrue($userMetadata->fieldMappings['name']['quoted']); + + $this->assertEquals('user-id', $userMetadata->fieldMappings['id']['columnName']); + $this->assertEquals('user-name', $userMetadata->fieldMappings['name']['columnName']); + + + $address = $userMetadata->associationMappings['address']; + $this->assertTrue($address['joinColumns'][0]['quoted']); + $this->assertEquals('address-id', $address['joinColumns'][0]['name']); + $this->assertEquals('address-id', $address['joinColumns'][0]['referencedColumnName']); + + $groups = $userMetadata->associationMappings['groups']; + $this->assertTrue($groups['joinTable']['joinColumns'][0]['quoted']); + $this->assertEquals('user-id', $groups['joinTable']['joinColumns'][0]['name']); + $this->assertEquals('user-id', $groups['joinTable']['joinColumns'][0]['referencedColumnName']); + + $this->assertTrue($groups['joinTable']['inverseJoinColumns'][0]['quoted']); + $this->assertEquals('group-id', $groups['joinTable']['inverseJoinColumns'][0]['name']); + $this->assertEquals('group-id', $groups['joinTable']['inverseJoinColumns'][0]['referencedColumnName']); + } } /* Test subject class with overriden factory method for mocking purposes */ diff --git a/tests/Doctrine/Tests/ORM/Mapping/QuoteStrategyTest.php b/tests/Doctrine/Tests/ORM/Mapping/QuoteStrategyTest.php index 50b87c159..4e832060b 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/QuoteStrategyTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/QuoteStrategyTest.php @@ -26,7 +26,6 @@ class QuoteStrategyTest extends \Doctrine\Tests\OrmTestCase $this->strategy = new DefaultQuoteStrategy($em->getConnection()->getDatabasePlatform()); } - /** * @param string $className * @return \Doctrine\ORM\Mapping\ClassMetadata @@ -39,21 +38,6 @@ class QuoteStrategyTest extends \Doctrine\Tests\OrmTestCase return $cm; } - - public function testIsQuotedIdentifier() - { - $this->assertTrue($this->strategy->isQuotedIdentifier('`table_name`')); - $this->assertFalse($this->strategy->isQuotedIdentifier('table_name')); - $this->assertFalse($this->strategy->isQuotedIdentifier(null)); - $this->assertFalse($this->strategy->isQuotedIdentifier('')); - } - - public function testGetUnquotedIdentifier() - { - $this->assertEquals('table_name' ,$this->strategy->getUnquotedIdentifier('`table_name`')); - $this->assertEquals('table_name' ,$this->strategy->getUnquotedIdentifier('table_name')); - } - public function testGetColumnName() { $cm = $this->createClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); diff --git a/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterTypeValueSqlTest.php b/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterTypeValueSqlTest.php index 344ca12f9..fa1d7530a 100644 --- a/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterTypeValueSqlTest.php +++ b/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterTypeValueSqlTest.php @@ -82,10 +82,10 @@ class BasicEntityPersisterTypeValueSqlTest extends \Doctrine\Tests\OrmTestCase */ public function testStripNonAlphanumericCharactersFromSelectColumnListSQL() { - $persister = new BasicEntityPersister($this->_em, $this->_em->getClassMetadata('Doctrine\Tests\Models\DDC1719\DDC1719Entity')); + $persister = new BasicEntityPersister($this->_em, $this->_em->getClassMetadata('Doctrine\Tests\Models\Quote\SimpleEntity')); $method = new \ReflectionMethod($persister, '_getSelectColumnListSQL'); $method->setAccessible(true); - $this->assertEquals('t0."entity-id" AS entityid1, t0."entity-value" AS entityvalue2', $method->invoke($persister)); + $this->assertEquals('t0."simple-entity-id" AS simpleentityid1, t0."simple-entity-value" AS simpleentityvalue2', $method->invoke($persister)); } } diff --git a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php index ae7cd7a52..3a6e349dd 100644 --- a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php +++ b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php @@ -1647,18 +1647,18 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase 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_' + 'SELECT e FROM Doctrine\Tests\Models\Quote\SimpleEntity e', + 'SELECT d0_."simple-entity-id" AS simpleentityid0, d0_."simple-entity-value" AS simpleentityvalue1 FROM "ddc-1719-simple-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' + 'SELECT e.value FROM Doctrine\Tests\Models\Quote\SimpleEntity e ORDER BY e.value', + 'SELECT d0_."simple-entity-value" AS simpleentityvalue0 FROM "ddc-1719-simple-entity" d0_ ORDER BY d0_."simple-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' + 'SELECT TRIM(e.value) FROM Doctrine\Tests\Models\Quote\SimpleEntity e ORDER BY e.value', + 'SELECT TRIM(d0_."simple-entity-value") AS sclr0 FROM "ddc-1719-simple-entity" d0_ ORDER BY d0_."simple-entity-value" ASC' ); } From 0e9c76abf86399986479f5bd3e67ba852e0d883f Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Mon, 4 Jun 2012 17:03:22 -0300 Subject: [PATCH 17/37] revert wrong commit --- .gitignore | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.gitignore b/.gitignore index 13f4debc8..a91841777 100644 --- a/.gitignore +++ b/.gitignore @@ -9,8 +9,3 @@ lib/Doctrine/DBAL /.settings/ .buildpath .project -/.AppleDouble/ -/tests/.AppleDouble/ -/bin/.AppleDouble/ -/lib/.AppleDouble/ -/tools/.AppleDouble/ \ No newline at end of file From 2b8e24fb090aa0f9cc845e7f51c325ebb7af99f5 Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Mon, 4 Jun 2012 17:08:43 -0300 Subject: [PATCH 18/37] revert wrong commit --- lib/Doctrine/ORM/Persisters/SingleTablePersister.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Persisters/SingleTablePersister.php b/lib/Doctrine/ORM/Persisters/SingleTablePersister.php index d8bb9f658..5b2ce205b 100644 --- a/lib/Doctrine/ORM/Persisters/SingleTablePersister.php +++ b/lib/Doctrine/ORM/Persisters/SingleTablePersister.php @@ -36,7 +36,7 @@ class SingleTablePersister extends AbstractEntityInheritancePersister /** {@inheritdoc} */ protected function _getDiscriminatorColumnTableName() { - return $this->quoteStrategy->getTableName($this->_class); + return $this->_class->getTableName(); } /** {@inheritdoc} */ From 7215c1a3b1bf66c00be3c63720827b4cb3fdaf2c Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Mon, 4 Jun 2012 17:18:03 -0300 Subject: [PATCH 19/37] test join table quote --- tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php index f72659336..d36c366d0 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php @@ -309,7 +309,9 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase $this->assertEquals('address-id', $address['joinColumns'][0]['referencedColumnName']); $groups = $userMetadata->associationMappings['groups']; + $this->assertTrue($groups['joinTable']['quoted']); $this->assertTrue($groups['joinTable']['joinColumns'][0]['quoted']); + $this->assertEquals('quote-users-groups', $groups['joinTable']['name']); $this->assertEquals('user-id', $groups['joinTable']['joinColumns'][0]['name']); $this->assertEquals('user-id', $groups['joinTable']['joinColumns'][0]['referencedColumnName']); From a75c672ee73569d09d13d513134f3c30e5fecb72 Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Tue, 5 Jun 2012 17:10:44 -0300 Subject: [PATCH 20/37] fix sequence and join columns --- .../ORM/Mapping/ClassMetadataFactory.php | 35 ++++-- .../ORM/Mapping/ClassMetadataInfo.php | 10 +- .../ORM/Mapping/DefaultQuoteStrategy.php | 31 +++++ lib/Doctrine/ORM/Mapping/QuoteStrategy.php | 19 +++ .../ORM/Persisters/BasicEntityPersister.php | 7 +- lib/Doctrine/ORM/Tools/SchemaTool.php | 21 ++-- tests/Doctrine/Tests/Models/Quote/Group.php | 11 ++ .../ORM/Functional/Ticket/DDC1151Test.php | 4 +- .../ORM/Functional/Ticket/DDC1360Test.php | 2 +- .../ORM/Functional/Ticket/DDC1843Test.php | 111 ++++++++++++++++++ .../ORM/Mapping/ClassMetadataFactoryTest.php | 6 +- 11 files changed, 229 insertions(+), 28 deletions(-) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1843Test.php diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php index 1bfa99d74..c0bb0c66d 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php @@ -648,23 +648,40 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface // For PostgreSQL IDENTITY (SERIAL) we need a sequence name. It defaults to // __seq in PostgreSQL for SERIAL columns. // Not pretty but necessary and the simplest solution that currently works. - $seqName = $this->targetPlatform instanceof Platforms\PostgreSQLPlatform ? - $class->getTableName() . '_' . $class->columnNames[$class->identifier[0]] . '_seq' : - null; - $class->setIdGenerator(new \Doctrine\ORM\Id\IdentityGenerator($seqName)); + $sequenceName = null; + if($this->targetPlatform instanceof Platforms\PostgreSQLPlatform) { + $fieldName = $class->getSingleIdentifierFieldName(); + $columnName = $class->getSingleIdentifierColumnName(); + $quoted = isset($class->fieldMappings[$fieldName]['quoted']) || isset($class->table['quoted']); + $sequenceName = $class->getTableName() . '_' . $columnName . '_seq'; + $definition = array( + 'sequenceName' => $this->targetPlatform->fixSchemaElementName($sequenceName) + ); + if ($quoted) { + $definition['quoted'] = true; + } + $sequenceName = $this->em->getQuoteStrategy()->getSequenceName($definition, $class); + } + $class->setIdGenerator(new \Doctrine\ORM\Id\IdentityGenerator($sequenceName)); break; case ClassMetadata::GENERATOR_TYPE_SEQUENCE: // If there is no sequence definition yet, create a default definition $definition = $class->sequenceGeneratorDefinition; if ( ! $definition) { - $sequenceName = $class->getTableName() . '_' . $class->getSingleIdentifierColumnName() . '_seq'; - $definition['sequenceName'] = $this->targetPlatform->fixSchemaElementName($sequenceName); - $definition['allocationSize'] = 1; - $definition['initialValue'] = 1; + $fieldName = $class->getSingleIdentifierFieldName(); + $columnName = $class->getSingleIdentifierColumnName(); + $quoted = isset($class->fieldMappings[$fieldName]['quoted']) || isset($class->table['quoted']); + $sequenceName = $class->getTableName() . '_' . $columnName . '_seq'; + $definition['sequenceName'] = $this->targetPlatform->fixSchemaElementName($sequenceName); + $definition['allocationSize'] = 1; + $definition['initialValue'] = 1; + if ($quoted) { + $definition['quoted'] = true; + } $class->setSequenceGeneratorDefinition($definition); } $sequenceGenerator = new \Doctrine\ORM\Id\SequenceGenerator( - $definition['sequenceName'], + $this->em->getQuoteStrategy()->getSequenceName($definition, $class), $definition['allocationSize'] ); $class->setIdGenerator($sequenceGenerator); diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php index 69d8c20cc..5e860be10 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php @@ -2567,9 +2567,10 @@ class ClassMetadataInfo implements ClassMetadata * The definition must have the following structure: * * array( - * 'sequenceName' => 'name', + * 'sequenceName' => 'name', * 'allocationSize' => 20, - * 'initialValue' => 1 + * 'initialValue' => 1 + * 'quoted' => 1 * ) * * @@ -2577,6 +2578,11 @@ class ClassMetadataInfo implements ClassMetadata */ public function setSequenceGeneratorDefinition(array $definition) { + if (isset($definition['name']) && $definition['name'] == '`') { + $definition['name'] = trim($definition['name'], '`'); + $definition['quoted'] = true; + } + $this->sequenceGeneratorDefinition = $definition; } diff --git a/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php b/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php index 3e09f1929..f1c6fa5d2 100644 --- a/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php +++ b/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php @@ -49,6 +49,37 @@ class DefaultQuoteStrategy extends QuoteStrategy : $class->table['name']; } + /** + * {@inheritdoc} + */ + public function getSequenceName(array $definition, ClassMetadata $class) + { + return isset($definition['quoted']) + ? $this->platform->quoteSingleIdentifier($definition['sequenceName']) + : $definition['sequenceName']; + } + + /** + * {@inheritdoc} + */ + public function getJoinColumnName($columnName, array $association, ClassMetadata $class) + { + if( !isset($association['joinColumns'])) { + return $columnName; + } + + foreach ($association['joinColumns'] as $joinColumn) { + if($joinColumn['name'] === $columnName) { + if (isset($joinColumn['quoted'])) { + return $this->platform->quoteIdentifier($columnName); + } + return $columnName; + } + } + + return $columnName; + } + /** * {@inheritdoc} */ diff --git a/lib/Doctrine/ORM/Mapping/QuoteStrategy.php b/lib/Doctrine/ORM/Mapping/QuoteStrategy.php index 5882783ad..aacf1c03d 100644 --- a/lib/Doctrine/ORM/Mapping/QuoteStrategy.php +++ b/lib/Doctrine/ORM/Mapping/QuoteStrategy.php @@ -60,14 +60,33 @@ abstract class QuoteStrategy */ abstract public function getTableName(ClassMetadata $class); + /** + * Gets the (possibly quoted) sequence name for safe use in an SQL statement. + * + * @param array $definition + * @param ClassMetadata $class + * @return string + */ + abstract public function getSequenceName(array $definition, ClassMetadata $class); + /** * Gets the (possibly quoted) name of the join table. * + * @param array $association * @param ClassMetadata $class * @return string */ abstract public function getJoinTableName(array $association, ClassMetadata $class); + /** + * Gets the (possibly quoted) join column name. + * + * @param array $association + * @param ClassMetadata $class + * @return string + */ + abstract public function getJoinColumnName($columnName, array $association, ClassMetadata $class); + /** * Gets the (possibly quoted) identifier column names for safe use in an SQL statement. * diff --git a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php index 6ff0568cf..400d0f77e 100644 --- a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php @@ -1080,10 +1080,11 @@ class BasicEntityPersister foreach ($assoc['targetToSourceKeyColumns'] as $srcColumn) { if ($columnList) $columnList .= ', '; + $quotedColumn = $this->quoteStrategy->getJoinColumnName($srcColumn, $assoc, $this->_class); $resultColumnName = $this->getSQLColumnAlias($srcColumn); $columnList .= $this->_getSQLTableAlias($class->name, ($alias == 'r' ? '' : $alias) ) - . '.' . $srcColumn . ' AS ' . $resultColumnName; - $this->_rsm->addMetaResult($alias, $resultColumnName, $srcColumn, isset($assoc['id']) && $assoc['id'] === true); + . '.' . $quotedColumn . ' AS ' . $resultColumnName; + $this->_rsm->addMetaResult($alias, $resultColumnName, $quotedColumn, isset($assoc['id']) && $assoc['id'] === true); } } @@ -1191,7 +1192,7 @@ class BasicEntityPersister if ($assoc['isOwningSide'] && $assoc['type'] & ClassMetadata::TO_ONE) { foreach ($assoc['targetToSourceKeyColumns'] as $sourceCol) { - $columns[] = $sourceCol; + $columns[] = $this->quoteStrategy->getJoinColumnName($sourceCol, $assoc, $this->_class); } } } else if ($this->_class->generatorType != ClassMetadata::GENERATOR_TYPE_IDENTITY || $this->_class->identifier[0] != $name) { diff --git a/lib/Doctrine/ORM/Tools/SchemaTool.php b/lib/Doctrine/ORM/Tools/SchemaTool.php index 1f69e0057..04796e6d3 100644 --- a/lib/Doctrine/ORM/Tools/SchemaTool.php +++ b/lib/Doctrine/ORM/Tools/SchemaTool.php @@ -217,12 +217,12 @@ class SchemaTool $pkColumns = array(); foreach ($class->identifier as $identifierField) { if (isset($class->fieldMappings[$identifierField])) { - $pkColumns[] = $class->getColumnName($identifierField); + $pkColumns[] = $this->quoteStrategy->getColumnName($identifierField, $class); } else if (isset($class->associationMappings[$identifierField])) { /* @var $assoc \Doctrine\ORM\Mapping\OneToOne */ $assoc = $class->associationMappings[$identifierField]; foreach ($assoc['joinColumns'] as $joinColumn) { - $pkColumns[] = $joinColumn['name']; + $pkColumns[] = $this->quoteStrategy->getJoinColumnName($joinColumn['name'], $assoc, $class); } } } @@ -252,11 +252,11 @@ class SchemaTool $processedClasses[$class->name] = true; if ($class->isIdGeneratorSequence() && $class->name == $class->rootEntityName) { - $seqDef = $class->sequenceGeneratorDefinition; - - if (!$schema->hasSequence($seqDef['sequenceName'])) { + $seqDef = $class->sequenceGeneratorDefinition; + $quotedName = $this->quoteStrategy->getSequenceName($seqDef, $class); + if ( ! $schema->hasSequence($quotedName)) { $schema->createSequence( - $seqDef['sequenceName'], + $quotedName, $seqDef['allocationSize'], $seqDef['initialValue'] ); @@ -523,9 +523,10 @@ class SchemaTool ); } - $primaryKeyColumns[] = $columnName; - $localColumns[] = $columnName; - $foreignColumns[] = $joinColumn['referencedColumnName']; + $primaryKeyColumns[] = $columnName; + $localColumns[] = $columnName; + $foreignColumns[] = $joinColumn['referencedColumnName']; + $quotedColumnName = $this->quoteStrategy->getJoinColumnName($columnName, $mapping, $class); if ( ! $theJoinTable->hasColumn($joinColumn['name'])) { // Only add the column to the table if it does not exist already. @@ -551,7 +552,7 @@ class SchemaTool $columnOptions['precision'] = $fieldMapping['precision']; } - $theJoinTable->addColumn($columnName, $fieldMapping['type'], $columnOptions); + $theJoinTable->addColumn($quotedColumnName, $fieldMapping['type'], $columnOptions); } if (isset($joinColumn['unique']) && $joinColumn['unique'] == true) { diff --git a/tests/Doctrine/Tests/Models/Quote/Group.php b/tests/Doctrine/Tests/Models/Quote/Group.php index 1540a1d02..2117f4b69 100644 --- a/tests/Doctrine/Tests/Models/Quote/Group.php +++ b/tests/Doctrine/Tests/Models/Quote/Group.php @@ -21,9 +21,20 @@ class Group */ public $name; + /** + * @ManyToOne(targetEntity="Group", cascade={"persist"}) + * @JoinColumn(name="`parent-id`", referencedColumnName="`group-id`") + */ + public $parent; + /** * @ManyToMany(targetEntity="User", mappedBy="groups") */ public $users; + public function __construct($name = null, Group $parent = null) + { + $this->name = $name; + $this->parent = $parent; + } } \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1151Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1151Test.php index 51a2d4555..fe975f69d 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1151Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1151Test.php @@ -25,8 +25,8 @@ class DDC1151Test extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertEquals("CREATE INDEX IDX_88A3259AC5AD08A ON ddc1151user_ddc1151group (ddc1151user_id)", $sql[2]); $this->assertEquals("CREATE INDEX IDX_88A32597357E0B1 ON ddc1151user_ddc1151group (ddc1151group_id)", $sql[3]); $this->assertEquals("CREATE TABLE \"Group\" (id INT NOT NULL, PRIMARY KEY(id))", $sql[4]); - $this->assertEquals("CREATE SEQUENCE User_id_seq INCREMENT BY 1 MINVALUE 1 START 1", $sql[5]); - $this->assertEquals("CREATE SEQUENCE Group_id_seq INCREMENT BY 1 MINVALUE 1 START 1", $sql[6]); + $this->assertEquals("CREATE SEQUENCE \"User_id_seq\" INCREMENT BY 1 MINVALUE 1 START 1", $sql[5]); + $this->assertEquals("CREATE SEQUENCE \"Group_id_seq\" INCREMENT BY 1 MINVALUE 1 START 1", $sql[6]); $this->assertEquals("ALTER TABLE ddc1151user_ddc1151group ADD CONSTRAINT FK_88A3259AC5AD08A FOREIGN KEY (ddc1151user_id) REFERENCES \"User\" (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE", $sql[7]); $this->assertEquals("ALTER TABLE ddc1151user_ddc1151group ADD CONSTRAINT FK_88A32597357E0B1 FOREIGN KEY (ddc1151group_id) REFERENCES \"Group\" (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE", $sql[8]); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1360Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1360Test.php index f95f77eb4..38f5837e5 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1360Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1360Test.php @@ -21,7 +21,7 @@ class DDC1360Test extends OrmFunctionalTestCase $this->assertEquals(array( 'CREATE TABLE "user"."user" (id INT NOT NULL, PRIMARY KEY(id))', - 'CREATE SEQUENCE "user".user_id_seq INCREMENT BY 1 MINVALUE 1 START 1', + 'CREATE SEQUENCE "user"."user_id_seq" INCREMENT BY 1 MINVALUE 1 START 1', ), $sql); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1843Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1843Test.php new file mode 100644 index 000000000..4b28f66e2 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1843Test.php @@ -0,0 +1,111 @@ +markTestIncomplete(); + parent::setUp(); + + $this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger); + + try { + $this->_schemaTool->createSchema(array( + $this->_em->getClassMetadata(self::CLASS_NAME), + )); + } catch(\Exception $e) { + $this->fail($e->getMessage()); + } + } + + public function testCreateRetreaveUpdateDelete() + { + + $e1 = new Group('Parent Bar 1'); + $e2 = new Group('Parent Foo 2'); + + $this->_em->persist($e1); + $this->_em->persist($e2); + $this->_em->flush(); + + $e3 = new Group('Bar 3', $e1); + $e4 = new Group('Foo 4', $e2); + + // Create + $this->_em->persist($e3); + $this->_em->persist($e4); + $this->_em->flush(); + $this->_em->clear(); + + $e1Id = $e1->id; + $e2Id = $e2->id; + $e3Id = $e3->id; + $e4Id = $e4->id; + + // Retreave + $e1 = $this->_em->find(self::CLASS_NAME, $e1Id); + $e2 = $this->_em->find(self::CLASS_NAME, $e2Id); + $e3 = $this->_em->find(self::CLASS_NAME, $e3Id); + $e4 = $this->_em->find(self::CLASS_NAME, $e4Id); + + $this->assertInstanceOf(self::CLASS_NAME, $e1); + $this->assertInstanceOf(self::CLASS_NAME, $e2); + $this->assertInstanceOf(self::CLASS_NAME, $e3); + $this->assertInstanceOf(self::CLASS_NAME, $e4); + + $this->assertEquals($e1Id, $e1->id); + $this->assertEquals($e2Id, $e2->id); + $this->assertEquals($e3Id, $e3->id); + $this->assertEquals($e4Id, $e4->id); + + return; + + $this->assertEquals('Bar 1', $e1->value); + $this->assertEquals('Foo 1', $e2->value); + + $e1->value = 'Bar 2'; + $e2->value = 'Foo 2'; + + // Update + $this->_em->persist($e1); + $this->_em->persist($e2); + $this->_em->flush(); + + $this->assertEquals('Bar 2', $e1->value); + $this->assertEquals('Foo 2', $e2->value); + + $this->assertInstanceOf(self::CLASS_NAME, $e1); + $this->assertInstanceOf(self::CLASS_NAME, $e2); + + $this->assertEquals($e1Id, $e1->id); + $this->assertEquals($e2Id, $e2->id); + + $this->assertEquals('Bar 2', $e1->value); + $this->assertEquals('Foo 2', $e2->value); + + // Delete + $this->_em->remove($e1); + $this->_em->remove($e2); + $this->_em->flush(); + + + $e1 = $this->_em->find(self::CLASS_NAME, $e1Id); + $e2 = $this->_em->find(self::CLASS_NAME, $e2Id); + + $this->assertNull($e1); + $this->assertNull($e2); + } + +} \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php index d36c366d0..f1654dcfd 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php @@ -272,13 +272,17 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase - // User Class Metadata + // User Group Metadata $this->assertTrue($groupMetadata->fieldMappings['id']['quoted']); $this->assertTrue($groupMetadata->fieldMappings['name']['quoted']); $this->assertEquals('user-id', $userMetadata->fieldMappings['id']['columnName']); $this->assertEquals('user-name', $userMetadata->fieldMappings['name']['columnName']); + $user = $groupMetadata->associationMappings['parent']; + $this->assertTrue($user['joinColumns'][0]['quoted']); + $this->assertEquals('parent-id', $user['joinColumns'][0]['name']); + $this->assertEquals('group-id', $user['joinColumns'][0]['referencedColumnName']); // Address Class Metadata From 2afe24f51c4515107bd0fdf243ff18204056087b Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Wed, 6 Jun 2012 13:14:20 -0300 Subject: [PATCH 21/37] start to work in xxToOne quote --- .gitignore | 5 ++ .../ORM/Mapping/DefaultQuoteStrategy.php | 23 ++++++++- lib/Doctrine/ORM/Mapping/QuoteStrategy.php | 9 ++++ lib/Doctrine/ORM/Tools/SchemaTool.php | 18 ++++--- tests/Doctrine/Tests/Models/Quote/Group.php | 2 + tests/Doctrine/Tests/Models/Quote/User.php | 3 +- .../ORM/Functional/Ticket/DDC1843Test.php | 51 ++++++++++++++----- 7 files changed, 88 insertions(+), 23 deletions(-) diff --git a/.gitignore b/.gitignore index a91841777..265037d31 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,8 @@ lib/Doctrine/DBAL /.settings/ .buildpath .project +/.AppleDouble/ +/bin/.AppleDouble/ +/lib/.AppleDouble/ +/tests/.AppleDouble/ +/tools/.AppleDouble/ \ No newline at end of file diff --git a/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php b/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php index f1c6fa5d2..9ab835a31 100644 --- a/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php +++ b/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php @@ -64,7 +64,7 @@ class DefaultQuoteStrategy extends QuoteStrategy */ public function getJoinColumnName($columnName, array $association, ClassMetadata $class) { - if( !isset($association['joinColumns'])) { + if( ! isset($association['joinColumns'])) { return $columnName; } @@ -80,6 +80,27 @@ class DefaultQuoteStrategy extends QuoteStrategy return $columnName; } + /** + * {@inheritdoc} + */ + public function getReferencedJoinColumnName($columnName, array $association, ClassMetadata $class) + { + if( ! isset($association['joinColumns'])) { + return $columnName; + } + + foreach ($association['joinColumns'] as $joinColumn) { + if($joinColumn['referencedColumnName'] === $columnName) { + if (isset($joinColumn['quoted'])) { + return $this->platform->quoteIdentifier($columnName); + } + return $columnName; + } + } + + return $columnName; + } + /** * {@inheritdoc} */ diff --git a/lib/Doctrine/ORM/Mapping/QuoteStrategy.php b/lib/Doctrine/ORM/Mapping/QuoteStrategy.php index aacf1c03d..c994b5139 100644 --- a/lib/Doctrine/ORM/Mapping/QuoteStrategy.php +++ b/lib/Doctrine/ORM/Mapping/QuoteStrategy.php @@ -87,6 +87,15 @@ abstract class QuoteStrategy */ abstract public function getJoinColumnName($columnName, array $association, ClassMetadata $class); + /** + * Gets the (possibly quoted) join column name. + * + * @param array $association + * @param ClassMetadata $class + * @return string + */ + abstract public function getReferencedJoinColumnName($columnName, array $association, ClassMetadata $class); + /** * Gets the (possibly quoted) identifier column names for safe use in an SQL statement. * diff --git a/lib/Doctrine/ORM/Tools/SchemaTool.php b/lib/Doctrine/ORM/Tools/SchemaTool.php index 04796e6d3..70e5d3224 100644 --- a/lib/Doctrine/ORM/Tools/SchemaTool.php +++ b/lib/Doctrine/ORM/Tools/SchemaTool.php @@ -513,8 +513,10 @@ class SchemaTool $foreignTableName = $this->quoteStrategy->getTableName($class); foreach ($joinColumns as $joinColumn) { - $columnName = $joinColumn['name']; - list($definingClass, $referencedFieldName) = $this->getDefiningClass($class, $joinColumn['referencedColumnName']); + $columnName = $joinColumn['name']; + $referencedColumnName = $joinColumn['referencedColumnName']; + + list($definingClass, $referencedFieldName) = $this->getDefiningClass($class, $referencedColumnName); if (!$definingClass) { throw new \Doctrine\ORM\ORMException( @@ -523,12 +525,14 @@ class SchemaTool ); } - $primaryKeyColumns[] = $columnName; - $localColumns[] = $columnName; - $foreignColumns[] = $joinColumn['referencedColumnName']; $quotedColumnName = $this->quoteStrategy->getJoinColumnName($columnName, $mapping, $class); + $quotedRefColumnName = $this->quoteStrategy->getReferencedJoinColumnName($referencedColumnName, $mapping, $class); - if ( ! $theJoinTable->hasColumn($joinColumn['name'])) { + $primaryKeyColumns[] = $quotedColumnName; + $localColumns[] = $quotedColumnName; + $foreignColumns[] = $quotedRefColumnName; + + if ( ! $theJoinTable->hasColumn($quotedColumnName)) { // Only add the column to the table if it does not exist already. // It might exist already if the foreign key is mapped into a regular // property as well. @@ -556,7 +560,7 @@ class SchemaTool } if (isset($joinColumn['unique']) && $joinColumn['unique'] == true) { - $uniqueConstraints[] = array('columns' => array($columnName)); + $uniqueConstraints[] = array('columns' => array($quotedColumnName)); } if (isset($joinColumn['onDelete'])) { diff --git a/tests/Doctrine/Tests/Models/Quote/Group.php b/tests/Doctrine/Tests/Models/Quote/Group.php index 2117f4b69..c653b6974 100644 --- a/tests/Doctrine/Tests/Models/Quote/Group.php +++ b/tests/Doctrine/Tests/Models/Quote/Group.php @@ -22,6 +22,8 @@ class Group public $name; /** + * @var Group + * * @ManyToOne(targetEntity="Group", cascade={"persist"}) * @JoinColumn(name="`parent-id`", referencedColumnName="`group-id`") */ diff --git a/tests/Doctrine/Tests/Models/Quote/User.php b/tests/Doctrine/Tests/Models/Quote/User.php index 33d1c0bcd..7d485aabe 100644 --- a/tests/Doctrine/Tests/Models/Quote/User.php +++ b/tests/Doctrine/Tests/Models/Quote/User.php @@ -40,7 +40,8 @@ class User * joinColumns={ * @JoinColumn( * name="`user-id`", - * referencedColumnName="`user-id`") + * referencedColumnName="`user-id`" + * ) * }, * inverseJoinColumns={ * @JoinColumn( diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1843Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1843Test.php index 4b28f66e2..9ee846cbd 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1843Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1843Test.php @@ -16,14 +16,16 @@ class DDC1843Test extends \Doctrine\Tests\OrmFunctionalTestCase protected function setUp() { - $this->markTestIncomplete(); parent::setUp(); - $this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger); + //$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger); try { $this->_schemaTool->createSchema(array( - $this->_em->getClassMetadata(self::CLASS_NAME), + //$this->_em->getClassMetadata('Doctrine\Tests\Models\Quote\User'), + $this->_em->getClassMetadata('Doctrine\Tests\Models\Quote\Group'), + //$this->_em->getClassMetadata('Doctrine\Tests\Models\Quote\Phone'), + //$this->_em->getClassMetadata('Doctrine\Tests\Models\Quote\Address'), )); } catch(\Exception $e) { $this->fail($e->getMessage()); @@ -70,42 +72,63 @@ class DDC1843Test extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertEquals($e3Id, $e3->id); $this->assertEquals($e4Id, $e4->id); - return; - $this->assertEquals('Bar 1', $e1->value); - $this->assertEquals('Foo 1', $e2->value); + $this->assertEquals('Parent Bar 1', $e1->name); + $this->assertEquals('Parent Foo 2', $e2->name); + $this->assertEquals('Bar 3', $e3->name); + $this->assertEquals('Foo 4', $e4->name); - $e1->value = 'Bar 2'; - $e2->value = 'Foo 2'; + $e1->name = 'Parent Bar 11'; + $e2->name = 'Parent Foo 22'; + $e3->name = 'Bar 33'; + $e4->name = 'Foo 44'; // Update $this->_em->persist($e1); $this->_em->persist($e2); + $this->_em->persist($e3); + $this->_em->persist($e4); $this->_em->flush(); - $this->assertEquals('Bar 2', $e1->value); - $this->assertEquals('Foo 2', $e2->value); + $this->assertEquals('Parent Bar 11', $e1->name); + $this->assertEquals('Parent Foo 22', $e2->name); + $this->assertEquals('Bar 33', $e3->name); + $this->assertEquals('Foo 44', $e4->name); $this->assertInstanceOf(self::CLASS_NAME, $e1); $this->assertInstanceOf(self::CLASS_NAME, $e2); + $this->assertInstanceOf(self::CLASS_NAME, $e3); + $this->assertInstanceOf(self::CLASS_NAME, $e4); $this->assertEquals($e1Id, $e1->id); $this->assertEquals($e2Id, $e2->id); + $this->assertEquals($e3Id, $e3->id); + $this->assertEquals($e4Id, $e4->id); - $this->assertEquals('Bar 2', $e1->value); - $this->assertEquals('Foo 2', $e2->value); + $this->assertEquals('Parent Bar 11', $e1->name); + $this->assertEquals('Parent Foo 22', $e2->name); + $this->assertEquals('Bar 33', $e3->name); + $this->assertEquals('Foo 44', $e4->name); + + $this->markTestIncomplete(); // Delete $this->_em->remove($e1); $this->_em->remove($e2); + $this->_em->remove($e3); + $this->_em->remove($e4); $this->_em->flush(); - $e1 = $this->_em->find(self::CLASS_NAME, $e1Id); - $e2 = $this->_em->find(self::CLASS_NAME, $e2Id); + $this->assertInstanceOf(self::CLASS_NAME, $e1); + $this->assertInstanceOf(self::CLASS_NAME, $e2); + $this->assertInstanceOf(self::CLASS_NAME, $e3); + $this->assertInstanceOf(self::CLASS_NAME, $e4); $this->assertNull($e1); $this->assertNull($e2); + $this->assertNull($e3); + $this->assertNull($e4); } } \ No newline at end of file From 46ec26e7455016cf6f7d49fb4354b3791df0f8c3 Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Wed, 6 Jun 2012 13:17:08 -0300 Subject: [PATCH 22/37] revert wrong commit --- .gitignore | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.gitignore b/.gitignore index 265037d31..a91841777 100644 --- a/.gitignore +++ b/.gitignore @@ -9,8 +9,3 @@ lib/Doctrine/DBAL /.settings/ .buildpath .project -/.AppleDouble/ -/bin/.AppleDouble/ -/lib/.AppleDouble/ -/tests/.AppleDouble/ -/tools/.AppleDouble/ \ No newline at end of file From debc6e4993234bb4fd98a705202a5721ddab948a Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Mon, 11 Jun 2012 14:21:07 -0300 Subject: [PATCH 23/37] change QuoteStrategy#getJoinColumnName to use join column --- .gitignore | 5 +++ .../ORM/Mapping/DefaultQuoteStrategy.php | 38 ++++--------------- lib/Doctrine/ORM/Mapping/QuoteStrategy.php | 8 ++-- .../ORM/Persisters/BasicEntityPersister.php | 16 ++++---- lib/Doctrine/ORM/Tools/SchemaTool.php | 11 ++---- .../Tests/ORM/Mapping/QuoteStrategyTest.php | 2 +- 6 files changed, 30 insertions(+), 50 deletions(-) diff --git a/.gitignore b/.gitignore index a91841777..265037d31 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,8 @@ lib/Doctrine/DBAL /.settings/ .buildpath .project +/.AppleDouble/ +/bin/.AppleDouble/ +/lib/.AppleDouble/ +/tests/.AppleDouble/ +/tools/.AppleDouble/ \ No newline at end of file diff --git a/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php b/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php index 9ab835a31..076d98b2a 100644 --- a/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php +++ b/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php @@ -62,43 +62,21 @@ class DefaultQuoteStrategy extends QuoteStrategy /** * {@inheritdoc} */ - public function getJoinColumnName($columnName, array $association, ClassMetadata $class) + public function getJoinColumnName(array $joinColumn, ClassMetadata $class) { - if( ! isset($association['joinColumns'])) { - return $columnName; - } - - foreach ($association['joinColumns'] as $joinColumn) { - if($joinColumn['name'] === $columnName) { - if (isset($joinColumn['quoted'])) { - return $this->platform->quoteIdentifier($columnName); - } - return $columnName; - } - } - - return $columnName; + return isset($joinColumn['quoted']) + ? $this->platform->quoteIdentifier($joinColumn['name']) + : $joinColumn['name']; } /** * {@inheritdoc} */ - public function getReferencedJoinColumnName($columnName, array $association, ClassMetadata $class) + public function getReferencedJoinColumnName(array $joinColumn, ClassMetadata $class) { - if( ! isset($association['joinColumns'])) { - return $columnName; - } - - foreach ($association['joinColumns'] as $joinColumn) { - if($joinColumn['referencedColumnName'] === $columnName) { - if (isset($joinColumn['quoted'])) { - return $this->platform->quoteIdentifier($columnName); - } - return $columnName; - } - } - - return $columnName; + return isset($joinColumn['quoted']) + ? $this->platform->quoteIdentifier($joinColumn['referencedColumnName']) + : $joinColumn['referencedColumnName']; } /** diff --git a/lib/Doctrine/ORM/Mapping/QuoteStrategy.php b/lib/Doctrine/ORM/Mapping/QuoteStrategy.php index c994b5139..9e16999d8 100644 --- a/lib/Doctrine/ORM/Mapping/QuoteStrategy.php +++ b/lib/Doctrine/ORM/Mapping/QuoteStrategy.php @@ -81,20 +81,20 @@ abstract class QuoteStrategy /** * Gets the (possibly quoted) join column name. * - * @param array $association + * @param array $joinColumn * @param ClassMetadata $class * @return string */ - abstract public function getJoinColumnName($columnName, array $association, ClassMetadata $class); + abstract public function getJoinColumnName(array $joinColumn, ClassMetadata $class); /** * Gets the (possibly quoted) join column name. * - * @param array $association + * @param array $joinColumn * @param ClassMetadata $class * @return string */ - abstract public function getReferencedJoinColumnName($columnName, array $association, ClassMetadata $class); + abstract public function getReferencedJoinColumnName(array $joinColumn, ClassMetadata $class); /** * Gets the (possibly quoted) identifier column names for safe use in an SQL statement. diff --git a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php index 400d0f77e..021c8692e 100644 --- a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php @@ -1077,13 +1077,14 @@ class BasicEntityPersister $columnList = ''; if ($assoc['isOwningSide'] && $assoc['type'] & ClassMetadata::TO_ONE) { - foreach ($assoc['targetToSourceKeyColumns'] as $srcColumn) { + foreach ($assoc['joinColumns'] as $joinColumn) { + if ($columnList) $columnList .= ', '; - $quotedColumn = $this->quoteStrategy->getJoinColumnName($srcColumn, $assoc, $this->_class); - $resultColumnName = $this->getSQLColumnAlias($srcColumn); - $columnList .= $this->_getSQLTableAlias($class->name, ($alias == 'r' ? '' : $alias) ) - . '.' . $quotedColumn . ' AS ' . $resultColumnName; + $quotedColumn = $this->quoteStrategy->getJoinColumnName($joinColumn, $this->_class); + $resultColumnName = $this->getSQLColumnAlias($joinColumn['name']); + $columnList .= $this->_getSQLTableAlias($class->name, ($alias == 'r' ? '' : $alias) ) + . '.' . $quotedColumn . ' AS ' . $resultColumnName; $this->_rsm->addMetaResult($alias, $resultColumnName, $quotedColumn, isset($assoc['id']) && $assoc['id'] === true); } } @@ -1189,10 +1190,9 @@ class BasicEntityPersister if (isset($this->_class->associationMappings[$name])) { $assoc = $this->_class->associationMappings[$name]; - if ($assoc['isOwningSide'] && $assoc['type'] & ClassMetadata::TO_ONE) { - foreach ($assoc['targetToSourceKeyColumns'] as $sourceCol) { - $columns[] = $this->quoteStrategy->getJoinColumnName($sourceCol, $assoc, $this->_class); + foreach ($assoc['joinColumns'] as $joinColumn) { + $columns[] = $this->quoteStrategy->getJoinColumnName($joinColumn, $this->_class); } } } else if ($this->_class->generatorType != ClassMetadata::GENERATOR_TYPE_IDENTITY || $this->_class->identifier[0] != $name) { diff --git a/lib/Doctrine/ORM/Tools/SchemaTool.php b/lib/Doctrine/ORM/Tools/SchemaTool.php index 70e5d3224..1ef28f1cb 100644 --- a/lib/Doctrine/ORM/Tools/SchemaTool.php +++ b/lib/Doctrine/ORM/Tools/SchemaTool.php @@ -36,7 +36,6 @@ use Doctrine\ORM\ORMException, * * @link www.doctrine-project.org * @since 2.0 - * @version $Revision$ * @author Guilherme Blanco * @author Jonathan Wage * @author Roman Borschel @@ -222,7 +221,7 @@ class SchemaTool /* @var $assoc \Doctrine\ORM\Mapping\OneToOne */ $assoc = $class->associationMappings[$identifierField]; foreach ($assoc['joinColumns'] as $joinColumn) { - $pkColumns[] = $this->quoteStrategy->getJoinColumnName($joinColumn['name'], $assoc, $class); + $pkColumns[] = $this->quoteStrategy->getJoinColumnName($joinColumn, $class); } } } @@ -513,10 +512,8 @@ class SchemaTool $foreignTableName = $this->quoteStrategy->getTableName($class); foreach ($joinColumns as $joinColumn) { - $columnName = $joinColumn['name']; - $referencedColumnName = $joinColumn['referencedColumnName']; - list($definingClass, $referencedFieldName) = $this->getDefiningClass($class, $referencedColumnName); + list($definingClass, $referencedFieldName) = $this->getDefiningClass($class, $joinColumn['referencedColumnName']); if (!$definingClass) { throw new \Doctrine\ORM\ORMException( @@ -525,8 +522,8 @@ class SchemaTool ); } - $quotedColumnName = $this->quoteStrategy->getJoinColumnName($columnName, $mapping, $class); - $quotedRefColumnName = $this->quoteStrategy->getReferencedJoinColumnName($referencedColumnName, $mapping, $class); + $quotedColumnName = $this->quoteStrategy->getJoinColumnName($joinColumn, $class); + $quotedRefColumnName = $this->quoteStrategy->getReferencedJoinColumnName($joinColumn, $class); $primaryKeyColumns[] = $quotedColumnName; $localColumns[] = $quotedColumnName; diff --git a/tests/Doctrine/Tests/ORM/Mapping/QuoteStrategyTest.php b/tests/Doctrine/Tests/ORM/Mapping/QuoteStrategyTest.php index 4e832060b..b56222e2b 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/QuoteStrategyTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/QuoteStrategyTest.php @@ -120,7 +120,7 @@ class QuoteStrategyTest extends \Doctrine\Tests\OrmTestCase $this->assertEquals('COLUMNNAME3', $this->strategy->getColumnAlias('COLUMN-NAME-', $i++)); } - public function testQuoteJoinColumnNames() + public function testQuoteIdentifierJoinColumns() { $cm = $this->createClassMetadata('Doctrine\Tests\Models\DDC117\DDC117ArticleDetails'); From ad380e3ac6a6c0a739dffe534c8b7d8a43eda74b Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Mon, 11 Jun 2012 14:32:50 -0300 Subject: [PATCH 24/37] test join column and referenced join columns quote --- .../Tests/ORM/Mapping/QuoteStrategyTest.php | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/Mapping/QuoteStrategyTest.php b/tests/Doctrine/Tests/ORM/Mapping/QuoteStrategyTest.php index b56222e2b..bc4313101 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/QuoteStrategyTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/QuoteStrategyTest.php @@ -135,4 +135,38 @@ class QuoteStrategyTest extends \Doctrine\Tests\OrmTestCase $this->assertEquals(array('"article"'), $this->strategy->getIdentifierColumnNames($cm)); } + + public function testJoinColumnName() + { + $cm = $this->createClassMetadata('Doctrine\Tests\Models\DDC117\DDC117ArticleDetails'); + + $cm->mapOneToOne(array( + 'id' => true, + 'fieldName' => 'article', + 'targetEntity' => 'Doctrine\Tests\Models\DDC117\DDC117Article', + 'joinColumns' => array(array( + 'name' => '`article`' + )), + )); + + $joinColumn = $cm->associationMappings['article']['joinColumns'][0]; + $this->assertEquals('"article"',$this->strategy->getJoinColumnName($joinColumn, $cm)); + } + + public function testReferencedJoinColumnName() + { + $cm = $this->createClassMetadata('Doctrine\Tests\Models\DDC117\DDC117ArticleDetails'); + + $cm->mapOneToOne(array( + 'id' => true, + 'fieldName' => 'article', + 'targetEntity' => 'Doctrine\Tests\Models\DDC117\DDC117Article', + 'joinColumns' => array(array( + 'name' => '`article`' + )), + )); + + $joinColumn = $cm->associationMappings['article']['joinColumns'][0]; + $this->assertEquals('"id"',$this->strategy->getReferencedJoinColumnName($joinColumn, $cm)); + } } \ No newline at end of file From 7807d6806c969113ff41a028ffa2a306fc889f63 Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Mon, 11 Jun 2012 15:43:10 -0300 Subject: [PATCH 25/37] fix delete join table not owning side --- .../ORM/Persisters/BasicEntityPersister.php | 23 ++++++++++--------- .../ORM/Functional/Ticket/DDC1843Test.php | 22 +++++++++++------- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php index 021c8692e..8ca2c299b 100644 --- a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php @@ -420,11 +420,16 @@ class BasicEntityPersister // @Todo this only covers scenarios with no inheritance or of the same level. Is there something // like self-referential relationship between different levels of an inheritance hierachy? I hope not! $selfReferential = ($mapping['targetEntity'] == $mapping['sourceEntity']); + $otherKeys = array(); + $keys = array(); if ( ! $mapping['isOwningSide']) { - $relatedClass = $this->_em->getClassMetadata($mapping['targetEntity']); - $mapping = $relatedClass->associationMappings[$mapping['mappedBy']]; - $keys = array_keys($mapping['relationToTargetKeyColumns']); + $relatedClass = $this->_em->getClassMetadata($mapping['targetEntity']); + $mapping = $relatedClass->associationMappings[$mapping['mappedBy']]; + + foreach ($mapping['joinTable']['inverseJoinColumns'] as $joinColumn) { + $keys[] = $this->quoteStrategy->getJoinColumnName($joinColumn, $relatedClass); + } if ($selfReferential) { $otherKeys = array_keys($mapping['relationToSourceKeyColumns']); @@ -438,16 +443,12 @@ class BasicEntityPersister } if ( ! isset($mapping['isOnDeleteCascade'])) { - $this->_conn->delete( - $this->quoteStrategy->getJoinTableName($mapping, $this->_class), - array_combine($keys, $identifier) - ); + + $joinTableName = $this->quoteStrategy->getJoinTableName($mapping, $this->_class); + $this->_conn->delete($joinTableName, array_combine($keys, $identifier)); if ($selfReferential) { - $this->_conn->delete( - $this->quoteStrategy->getJoinTableName($mapping, $this->_class), - array_combine($otherKeys, $identifier) - ); + $this->_conn->delete($joinTableName,array_combine($otherKeys, $identifier)); } } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1843Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1843Test.php index 9ee846cbd..9f6a17ab4 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1843Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1843Test.php @@ -22,10 +22,10 @@ class DDC1843Test extends \Doctrine\Tests\OrmFunctionalTestCase try { $this->_schemaTool->createSchema(array( - //$this->_em->getClassMetadata('Doctrine\Tests\Models\Quote\User'), + $this->_em->getClassMetadata('Doctrine\Tests\Models\Quote\User'), $this->_em->getClassMetadata('Doctrine\Tests\Models\Quote\Group'), - //$this->_em->getClassMetadata('Doctrine\Tests\Models\Quote\Phone'), - //$this->_em->getClassMetadata('Doctrine\Tests\Models\Quote\Address'), + $this->_em->getClassMetadata('Doctrine\Tests\Models\Quote\Phone'), + $this->_em->getClassMetadata('Doctrine\Tests\Models\Quote\Address'), )); } catch(\Exception $e) { $this->fail($e->getMessage()); @@ -110,14 +110,14 @@ class DDC1843Test extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertEquals('Bar 33', $e3->name); $this->assertEquals('Foo 44', $e4->name); - $this->markTestIncomplete(); - // Delete - $this->_em->remove($e1); - $this->_em->remove($e2); - $this->_em->remove($e3); $this->_em->remove($e4); + $this->_em->remove($e3); + $this->_em->remove($e2); + $this->_em->remove($e1); + $this->_em->flush(); + $this->_em->clear(); $this->assertInstanceOf(self::CLASS_NAME, $e1); @@ -125,6 +125,12 @@ class DDC1843Test extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertInstanceOf(self::CLASS_NAME, $e3); $this->assertInstanceOf(self::CLASS_NAME, $e4); + // Retreave + $e1 = $this->_em->find(self::CLASS_NAME, $e1Id); + $e2 = $this->_em->find(self::CLASS_NAME, $e2Id); + $e3 = $this->_em->find(self::CLASS_NAME, $e3Id); + $e4 = $this->_em->find(self::CLASS_NAME, $e4Id); + $this->assertNull($e1); $this->assertNull($e2); $this->assertNull($e3); From 51f29cddb9b0b4c041748df8c372bc1c906d9623 Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Mon, 11 Jun 2012 15:58:47 -0300 Subject: [PATCH 26/37] fix delete join table --- .../ORM/Persisters/BasicEntityPersister.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php index 8ca2c299b..da938d39f 100644 --- a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php @@ -432,13 +432,20 @@ class BasicEntityPersister } if ($selfReferential) { - $otherKeys = array_keys($mapping['relationToSourceKeyColumns']); + foreach ($mapping['joinTable']['joinColumns'] as $joinColumn) { + $otherKeys[] = $this->quoteStrategy->getJoinColumnName($joinColumn, $relatedClass); + } } } else { - $keys = array_keys($mapping['relationToSourceKeyColumns']); + + foreach ($mapping['joinTable']['joinColumns'] as $joinColumn) { + $keys[] = $this->quoteStrategy->getJoinColumnName($joinColumn, $this->_class); + } if ($selfReferential) { - $otherKeys = array_keys($mapping['relationToTargetKeyColumns']); + foreach ($mapping['joinTable']['inverseJoinColumns'] as $joinColumn) { + $otherKeys[] = $this->quoteStrategy->getJoinColumnName($joinColumn, $this->_class); + } } } From cd806b83db61c9671bd30c1beeb3c02e11e3b32f Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Mon, 11 Jun 2012 17:41:00 -0300 Subject: [PATCH 27/37] fix DDC-142 persist OneToOne --- .../ORM/Persisters/BasicEntityPersister.php | 19 +++++- tests/Doctrine/Tests/Models/Quote/Address.php | 24 +++++++ tests/Doctrine/Tests/Models/Quote/User.php | 25 +++++++- .../ORM/Functional/Ticket/DDC142Test.php | 63 +++++++++++++++++++ .../ORM/Functional/Ticket/DDC1843Test.php | 46 +++++++------- 5 files changed, 149 insertions(+), 28 deletions(-) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/DDC142Test.php diff --git a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php index da938d39f..01e7b6106 100644 --- a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php @@ -132,6 +132,15 @@ class BasicEntityPersister */ protected $_columnTypes = array(); + /** + * The map of quoted column names. + * + * @var array + * @see _prepareInsertData($entity) + * @see _prepareUpdateData($entity) + */ + protected $quotedColumns = array(); + /** * The INSERT SQL statement used for entities handled by this persister. * This SQL is only generated once per request, if at all. @@ -358,6 +367,8 @@ class BasicEntityPersister $type = Type::getType($this->_columnTypes[$columnName]); $placeholder = $type->convertToDatabaseValueSQL('?', $this->_platform); } + } else if(isset($this->quotedColumns[$columnName])) { + $column = $this->quotedColumns[$columnName]; } $set[] = $column . ' = ' . $placeholder; @@ -546,7 +557,13 @@ class BasicEntityPersister $targetClass = $this->_em->getClassMetadata($assoc['targetEntity']); $owningTable = $this->getOwningTable($field); - foreach ($assoc['sourceToTargetKeyColumns'] as $sourceColumn => $targetColumn) { + foreach ($assoc['joinColumns'] as $joinColumn) { + $sourceColumn = $joinColumn['name']; + $targetColumn = $joinColumn['referencedColumnName']; + + $quotedColumn = $this->quoteStrategy->getJoinColumnName($joinColumn, $this->_class); + $this->quotedColumns[$sourceColumn] = $quotedColumn; + if ($newVal === null) { $result[$owningTable][$sourceColumn] = null; } else if ($targetClass->containsForeignIdentifier) { diff --git a/tests/Doctrine/Tests/Models/Quote/Address.php b/tests/Doctrine/Tests/Models/Quote/Address.php index 3597687d5..58e303f13 100644 --- a/tests/Doctrine/Tests/Models/Quote/Address.php +++ b/tests/Doctrine/Tests/Models/Quote/Address.php @@ -27,4 +27,28 @@ class Address */ public $user; + + public function setUser(User $user) { + if ($this->user !== $user) { + $this->user = $user; + $user->setAddress($this); + } + } + + + public function getId() + { + return $this->id; + } + + public function getZip() + { + return $this->zip; + } + + public function getUser() + { + return $this->user; + } + } \ No newline at end of file diff --git a/tests/Doctrine/Tests/Models/Quote/User.php b/tests/Doctrine/Tests/Models/Quote/User.php index 7d485aabe..72715d783 100644 --- a/tests/Doctrine/Tests/Models/Quote/User.php +++ b/tests/Doctrine/Tests/Models/Quote/User.php @@ -10,7 +10,6 @@ use Doctrine\Common\Collections\ArrayCollection; */ class User { - /** * @Id * @GeneratedValue @@ -30,7 +29,7 @@ class User /** * @JoinColumn(name="`address-id`", referencedColumnName="`address-id`") - * @OneToOne(targetEntity="Address", mappedBy="user", cascade={"persist"}) + * @OneToOne(targetEntity="Address", mappedBy="user", cascade={"persist"}, fetch="EAGER") */ public $address; @@ -59,4 +58,26 @@ class User $this->groups = new ArrayCollection; } + + public function getPhones() + { + return $this->phones; + } + + public function getAddress() + { + return $this->address; + } + + public function getGroups() + { + return $this->groups; + } + + public function setAddress(Address $address) { + if ($this->address !== $address) { + $this->address = $address; + $address->setUser($this); + } + } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC142Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC142Test.php new file mode 100644 index 000000000..923d495f4 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC142Test.php @@ -0,0 +1,63 @@ +_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger); + + try { + $this->_schemaTool->createSchema(array( + $this->_em->getClassMetadata('Doctrine\Tests\Models\Quote\User'), + $this->_em->getClassMetadata('Doctrine\Tests\Models\Quote\Group'), + $this->_em->getClassMetadata('Doctrine\Tests\Models\Quote\Phone'), + $this->_em->getClassMetadata('Doctrine\Tests\Models\Quote\Address'), + )); + } catch(\Exception $e) { + //$this->fail($e->getMessage()); + } + + } + + public function testCreateRetreaveUpdateDelete() + { + + $user = new User; + $user->name = 'FabioBatSilva'; + $this->_em->persist($user); + + $address = new Address; + $address->zip = '12345'; + $this->_em->persist($address); + + $this->_em->flush(); + + $addressRef = $this->_em->getReference('Doctrine\Tests\Models\Quote\Address', $address->getId()); + + $user->setAddress($addressRef); + + $this->_em->flush(); + $this->_em->clear(); + + $this->assertNotNull($user->id); + $this->markTestIncomplete(); + + $user = $this->_em->find('Doctrine\Tests\Models\Quote\User', $user->id); + + } + +} \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1843Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1843Test.php index 9f6a17ab4..15cfd5903 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1843Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1843Test.php @@ -7,19 +7,16 @@ use Doctrine\Tests\Models\Quote\Group; require_once __DIR__ . '/../../../TestInit.php'; /** + * @group DDC-1845 * @group DDC-1843 */ class DDC1843Test extends \Doctrine\Tests\OrmFunctionalTestCase { - const CLASS_NAME = '\Doctrine\Tests\Models\Quote\Group'; - protected function setUp() { parent::setUp(); - //$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger); - try { $this->_schemaTool->createSchema(array( $this->_em->getClassMetadata('Doctrine\Tests\Models\Quote\User'), @@ -28,7 +25,6 @@ class DDC1843Test extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->getClassMetadata('Doctrine\Tests\Models\Quote\Address'), )); } catch(\Exception $e) { - $this->fail($e->getMessage()); } } @@ -57,15 +53,15 @@ class DDC1843Test extends \Doctrine\Tests\OrmFunctionalTestCase $e4Id = $e4->id; // Retreave - $e1 = $this->_em->find(self::CLASS_NAME, $e1Id); - $e2 = $this->_em->find(self::CLASS_NAME, $e2Id); - $e3 = $this->_em->find(self::CLASS_NAME, $e3Id); - $e4 = $this->_em->find(self::CLASS_NAME, $e4Id); + $e1 = $this->_em->find('Doctrine\Tests\Models\Quote\Group', $e1Id); + $e2 = $this->_em->find('Doctrine\Tests\Models\Quote\Group', $e2Id); + $e3 = $this->_em->find('Doctrine\Tests\Models\Quote\Group', $e3Id); + $e4 = $this->_em->find('Doctrine\Tests\Models\Quote\Group', $e4Id); - $this->assertInstanceOf(self::CLASS_NAME, $e1); - $this->assertInstanceOf(self::CLASS_NAME, $e2); - $this->assertInstanceOf(self::CLASS_NAME, $e3); - $this->assertInstanceOf(self::CLASS_NAME, $e4); + $this->assertInstanceOf('Doctrine\Tests\Models\Quote\Group', $e1); + $this->assertInstanceOf('Doctrine\Tests\Models\Quote\Group', $e2); + $this->assertInstanceOf('Doctrine\Tests\Models\Quote\Group', $e3); + $this->assertInstanceOf('Doctrine\Tests\Models\Quote\Group', $e4); $this->assertEquals($e1Id, $e1->id); $this->assertEquals($e2Id, $e2->id); @@ -95,10 +91,10 @@ class DDC1843Test extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertEquals('Bar 33', $e3->name); $this->assertEquals('Foo 44', $e4->name); - $this->assertInstanceOf(self::CLASS_NAME, $e1); - $this->assertInstanceOf(self::CLASS_NAME, $e2); - $this->assertInstanceOf(self::CLASS_NAME, $e3); - $this->assertInstanceOf(self::CLASS_NAME, $e4); + $this->assertInstanceOf('Doctrine\Tests\Models\Quote\Group', $e1); + $this->assertInstanceOf('Doctrine\Tests\Models\Quote\Group', $e2); + $this->assertInstanceOf('Doctrine\Tests\Models\Quote\Group', $e3); + $this->assertInstanceOf('Doctrine\Tests\Models\Quote\Group', $e4); $this->assertEquals($e1Id, $e1->id); $this->assertEquals($e2Id, $e2->id); @@ -120,16 +116,16 @@ class DDC1843Test extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->clear(); - $this->assertInstanceOf(self::CLASS_NAME, $e1); - $this->assertInstanceOf(self::CLASS_NAME, $e2); - $this->assertInstanceOf(self::CLASS_NAME, $e3); - $this->assertInstanceOf(self::CLASS_NAME, $e4); + $this->assertInstanceOf('Doctrine\Tests\Models\Quote\Group', $e1); + $this->assertInstanceOf('Doctrine\Tests\Models\Quote\Group', $e2); + $this->assertInstanceOf('Doctrine\Tests\Models\Quote\Group', $e3); + $this->assertInstanceOf('Doctrine\Tests\Models\Quote\Group', $e4); // Retreave - $e1 = $this->_em->find(self::CLASS_NAME, $e1Id); - $e2 = $this->_em->find(self::CLASS_NAME, $e2Id); - $e3 = $this->_em->find(self::CLASS_NAME, $e3Id); - $e4 = $this->_em->find(self::CLASS_NAME, $e4Id); + $e1 = $this->_em->find('Doctrine\Tests\Models\Quote\Group', $e1Id); + $e2 = $this->_em->find('Doctrine\Tests\Models\Quote\Group', $e2Id); + $e3 = $this->_em->find('Doctrine\Tests\Models\Quote\Group', $e3Id); + $e4 = $this->_em->find('Doctrine\Tests\Models\Quote\Group', $e4Id); $this->assertNull($e1); $this->assertNull($e2); From e0a236a9af18519f94512aa4f073d2f287e6ed91 Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Mon, 11 Jun 2012 18:21:22 -0300 Subject: [PATCH 28/37] fix DDC-142 load OneToOne EAGER --- .../ORM/Persisters/BasicEntityPersister.php | 5 ++- .../ORM/Functional/Ticket/DDC142Test.php | 40 +++++++++++++++---- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php index 01e7b6106..befc5af92 100644 --- a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php @@ -1048,7 +1048,10 @@ class BasicEntityPersister $this->_selectJoinSql .= ' ' . $this->quoteStrategy->getTableName($eagerEntity) . ' ' . $this->_getSQLTableAlias($eagerEntity->name, $assocAlias) .' ON '; $tableAlias = $this->_getSQLTableAlias($assoc['targetEntity'], $assocAlias); - foreach ($assoc['sourceToTargetKeyColumns'] as $sourceCol => $targetCol) { + foreach ($assoc['joinColumns'] as $joinColumn) { + $sourceCol = $this->quoteStrategy->getJoinColumnName($joinColumn, $this->_class); + $targetCol = $this->quoteStrategy->getReferencedJoinColumnName($joinColumn, $this->_class); + if ( ! $first) { $this->_selectJoinSql .= ' AND '; } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC142Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC142Test.php index 923d495f4..6965c6e3b 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC142Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC142Test.php @@ -18,8 +18,6 @@ class DDC142Test extends \Doctrine\Tests\OrmFunctionalTestCase { parent::setUp(); - //$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger); - try { $this->_schemaTool->createSchema(array( $this->_em->getClassMetadata('Doctrine\Tests\Models\Quote\User'), @@ -28,9 +26,7 @@ class DDC142Test extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->getClassMetadata('Doctrine\Tests\Models\Quote\Address'), )); } catch(\Exception $e) { - //$this->fail($e->getMessage()); } - } public function testCreateRetreaveUpdateDelete() @@ -53,11 +49,41 @@ class DDC142Test extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->flush(); $this->_em->clear(); - $this->assertNotNull($user->id); - $this->markTestIncomplete(); + $id = $user->id; + $this->assertNotNull($id); - $user = $this->_em->find('Doctrine\Tests\Models\Quote\User', $user->id); + + $user = $this->_em->find('Doctrine\Tests\Models\Quote\User', $id); + $address = $user->getAddress(); + $this->assertInstanceOf('Doctrine\Tests\Models\Quote\User', $user); + $this->assertInstanceOf('Doctrine\Tests\Models\Quote\Address', $user->getAddress()); + + $this->assertEquals('FabioBatSilva', $user->name); + $this->assertEquals('12345', $address->zip); + + + $user->name = 'FabioBatSilva1'; + $user->address = null; + + $this->_em->persist($user); + $this->_em->remove($address); + $this->_em->flush(); + $this->_em->clear(); + + + $user = $this->_em->find('Doctrine\Tests\Models\Quote\User', $id); + $this->assertInstanceOf('Doctrine\Tests\Models\Quote\User', $user); + $this->assertNull($user->getAddress()); + + $this->assertEquals('FabioBatSilva1', $user->name); + + + $this->_em->remove($user); + $this->_em->flush(); + $this->_em->clear(); + + $this->assertNull($this->_em->find('Doctrine\Tests\Models\Quote\User', $id)); } } \ No newline at end of file From b6b35d9482e37bba7f7670d7ee371eb9ea8c3b9c Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Mon, 11 Jun 2012 19:10:38 -0300 Subject: [PATCH 29/37] test quote join variable --- lib/Doctrine/ORM/Query/SqlWalker.php | 43 ++++++++----------- .../ORM/Query/SelectSqlGenerationTest.php | 36 +++++++++++++++- 2 files changed, 53 insertions(+), 26 deletions(-) diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index b705834e3..481118efd 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -835,22 +835,17 @@ class SqlWalker implements TreeWalker case ($assoc['type'] & ClassMetadata::TO_ONE): $conditions = array(); - foreach ($assoc['sourceToTargetKeyColumns'] as $sourceColumn => $targetColumn) { - if ($relation['isOwningSide']) { - $quotedTargetColumn = ($targetClass->containsForeignIdentifier && !isset($targetClass->fieldNames[$targetColumn])) - ? $targetColumn // Join columns cannot be quoted. - : $targetClass->getQuotedColumnName($targetClass->fieldNames[$targetColumn], $this->platform); + foreach ($assoc['joinColumns'] as $joinColumn) { + $quotedSourceColumn = $this->quoteStrategy->getJoinColumnName($joinColumn, $targetClass, $this->platform); + $quotedTargetColumn = $this->quoteStrategy->getReferencedJoinColumnName($joinColumn, $targetClass, $this->platform); - $conditions[] = $sourceTableAlias . '.' . $sourceColumn . ' = ' . $targetTableAlias . '.' . $quotedTargetColumn; + if ($relation['isOwningSide']) { + $conditions[] = $sourceTableAlias . '.' . $quotedSourceColumn . ' = ' . $targetTableAlias . '.' . $quotedTargetColumn; continue; } - $quotedTargetColumn = ($sourceClass->containsForeignIdentifier && !isset($sourceClass->fieldNames[$targetColumn])) - ? $targetColumn // Join columns cannot be quoted. - : $sourceClass->getQuotedColumnName($sourceClass->fieldNames[$targetColumn], $this->platform); - - $conditions[] = $sourceTableAlias . '.' . $quotedTargetColumn . ' = ' . $targetTableAlias . '.' . $sourceColumn; + $conditions[] = $sourceTableAlias . '.' . $quotedTargetColumn . ' = ' . $targetTableAlias . '.' . $quotedSourceColumn; } // Apply remaining inheritance restrictions @@ -878,15 +873,14 @@ class SqlWalker implements TreeWalker $conditions = array(); $relationColumns = ($relation['isOwningSide']) - ? $assoc['relationToSourceKeyColumns'] - : $assoc['relationToTargetKeyColumns']; + ? $assoc['joinTable']['joinColumns'] + : $assoc['joinTable']['inverseJoinColumns']; - foreach ($relationColumns as $relationColumn => $sourceColumn) { - $quotedTargetColumn = ($sourceClass->containsForeignIdentifier && !isset($sourceClass->fieldNames[$sourceColumn])) - ? $sourceColumn // Join columns cannot be quoted. - : $sourceClass->getQuotedColumnName($sourceClass->fieldNames[$sourceColumn], $this->platform); + foreach ($relationColumns as $joinColumn) { + $quotedSourceColumn = $this->quoteStrategy->getJoinColumnName($joinColumn, $targetClass, $this->platform); + $quotedTargetColumn = $this->quoteStrategy->getReferencedJoinColumnName($joinColumn, $targetClass, $this->platform); - $conditions[] = $sourceTableAlias . '.' . $quotedTargetColumn . ' = ' . $joinTableAlias . '.' . $relationColumn; + $conditions[] = $sourceTableAlias . '.' . $quotedTargetColumn . ' = ' . $joinTableAlias . '.' . $quotedSourceColumn; } $sql .= $joinTableName . ' ' . $joinTableAlias . ' ON ' . implode(' AND ', $conditions); @@ -896,15 +890,14 @@ class SqlWalker implements TreeWalker $conditions = array(); $relationColumns = ($relation['isOwningSide']) - ? $assoc['relationToTargetKeyColumns'] - : $assoc['relationToSourceKeyColumns']; + ? $assoc['joinTable']['inverseJoinColumns'] + : $assoc['joinTable']['joinColumns']; - foreach ($relationColumns as $relationColumn => $targetColumn) { - $quotedTargetColumn = ($targetClass->containsForeignIdentifier && !isset($targetClass->fieldNames[$targetColumn])) - ? $targetColumn // Join columns cannot be quoted. - : $targetClass->getQuotedColumnName($targetClass->fieldNames[$targetColumn], $this->platform); + foreach ($relationColumns as $joinColumn) { + $quotedSourceColumn = $this->quoteStrategy->getJoinColumnName($joinColumn, $targetClass, $this->platform); + $quotedTargetColumn = $this->quoteStrategy->getReferencedJoinColumnName($joinColumn, $targetClass, $this->platform); - $conditions[] = $targetTableAlias . '.' . $quotedTargetColumn . ' = ' . $joinTableAlias . '.' . $relationColumn; + $conditions[] = $targetTableAlias . '.' . $quotedTargetColumn . ' = ' . $joinTableAlias . '.' . $quotedSourceColumn; } // Apply remaining inheritance restrictions diff --git a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php index 3a6e349dd..fa5b06d82 100644 --- a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php +++ b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php @@ -1662,8 +1662,42 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase ); } -} + /** + * @group DDC-1845 + */ + public function testQuotedWalkJoinVariableDeclaration() + { + $this->assertSqlGeneration( + 'SELECT u, a FROM Doctrine\Tests\Models\Quote\User u JOIN u.address a', + 'SELECT q0_."user-id" AS userid0, q0_."user-name" AS username1, q1_."address-id" AS addressid2, q1_."address-zip" AS addresszip3 FROM "quote-user" q0_ INNER JOIN "quote-address" q1_ ON q0_."address-id" = q1_."address-id"' + ); + $this->assertSqlGeneration( + 'SELECT u, p FROM Doctrine\Tests\Models\Quote\User u JOIN u.phones p', + 'SELECT q0_."user-id" AS userid0, q0_."user-name" AS username1, q1_."phone-number" AS phonenumber2 FROM "quote-user" q0_ INNER JOIN "quote-phone" q1_ ON q0_."user-id" = q1_."user-id"' + ); + + $this->assertSqlGeneration( + 'SELECT u, g FROM Doctrine\Tests\Models\Quote\User u JOIN u.groups g', + 'SELECT q0_."user-id" AS userid0, q0_."user-name" AS username1, q1_."group-id" AS groupid2, q1_."group-name" AS groupname3 FROM "quote-user" q0_ INNER JOIN "quote-users-groups" q2_ ON q0_."user-id" = q2_."user-id" INNER JOIN "quote-group" q1_ ON q1_."group-id" = q2_."group-id"' + ); + + $this->assertSqlGeneration( + 'SELECT a, u FROM Doctrine\Tests\Models\Quote\Address a JOIN a.user u', + 'SELECT q0_."address-id" AS addressid0, q0_."address-zip" AS addresszip1, q1_."user-id" AS userid2, q1_."user-name" AS username3 FROM "quote-address" q0_ INNER JOIN "quote-user" q1_ ON q0_."user-id" = q1_."user-id"' + ); + + $this->assertSqlGeneration( + 'SELECT g, u FROM Doctrine\Tests\Models\Quote\Group g JOIN g.users u', + 'SELECT q0_."group-id" AS groupid0, q0_."group-name" AS groupname1, q1_."user-id" AS userid2, q1_."user-name" AS username3 FROM "quote-group" q0_ INNER JOIN "quote-users-groups" q2_ ON q0_."group-id" = q2_."group-id" INNER JOIN "quote-user" q1_ ON q1_."user-id" = q2_."user-id"' + ); + + $this->assertSqlGeneration( + 'SELECT g, p FROM Doctrine\Tests\Models\Quote\Group g JOIN g.parent p', + 'SELECT q0_."group-id" AS groupid0, q0_."group-name" AS groupname1, q1_."group-id" AS groupid2, q1_."group-name" AS groupname3 FROM "quote-group" q0_ INNER JOIN "quote-group" q1_ ON q0_."parent-id" = q1_."group-id"' + ); + } +} class MyAbsFunction extends \Doctrine\ORM\Query\AST\Functions\FunctionNode { From 85b6f8dc2ff45d8e3333d49db459bd44bb5f8212 Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Mon, 11 Jun 2012 20:14:17 -0300 Subject: [PATCH 30/37] change quote strategy to interface --- lib/Doctrine/ORM/Configuration.php | 29 ++++---- lib/Doctrine/ORM/EntityManager.php | 24 +------ .../ORM/Mapping/ClassMetadataFactory.php | 4 +- .../ORM/Mapping/DefaultQuoteStrategy.php | 39 +++++----- lib/Doctrine/ORM/Mapping/QuoteStrategy.php | 40 +++++------ .../AbstractCollectionPersister.php | 10 ++- .../AbstractEntityInheritancePersister.php | 2 +- .../ORM/Persisters/BasicEntityPersister.php | 72 +++++++++---------- .../Persisters/JoinedSubclassPersister.php | 22 +++--- .../ORM/Persisters/ManyToManyPersister.php | 12 ++-- .../ORM/Persisters/OneToManyPersister.php | 6 +- .../ORM/Query/AST/Functions/SizeFunction.php | 11 +-- .../Query/Exec/MultiTableDeleteExecutor.php | 4 +- .../Query/Exec/MultiTableUpdateExecutor.php | 4 +- lib/Doctrine/ORM/Query/SqlWalker.php | 44 ++++++------ lib/Doctrine/ORM/Tools/SchemaTool.php | 30 ++++---- .../Tests/ORM/Mapping/QuoteStrategyTest.php | 38 +++++----- 17 files changed, 189 insertions(+), 202 deletions(-) diff --git a/lib/Doctrine/ORM/Configuration.php b/lib/Doctrine/ORM/Configuration.php index a0c1da563..afdfd5e17 100644 --- a/lib/Doctrine/ORM/Configuration.php +++ b/lib/Doctrine/ORM/Configuration.php @@ -26,6 +26,7 @@ use Doctrine\Common\Cache\Cache, Doctrine\ORM\Mapping\Driver\Driver, Doctrine\ORM\Mapping\Driver\AnnotationDriver, Doctrine\ORM\Mapping\NamingStrategy, + Doctrine\ORM\Mapping\QuoteStrategy, Doctrine\ORM\Mapping\DefaultNamingStrategy; /** @@ -631,32 +632,28 @@ class Configuration extends \Doctrine\DBAL\Configuration } /** - * Set quote strategy class. + * Set quote strategy. * * @since 2.3 - * @param string $className + * @param Doctrine\ORM\Mapping\QuoteStrategy $quoteStrategy */ - public function setQuoteStrategyClassName($className) + public function setQuoteStrategy(QuoteStrategy $quoteStrategy) { - $quoteStrategy = 'Doctrine\ORM\Mapping\QuoteStrategy'; - - if ($className !== $quoteStrategy && ! is_subclass_of($className, $quoteStrategy)) { - throw new \InvalidArgumentException("Invalid quote strategy class"); - } - - $this->_attributes['quoteStrategyClassName'] = $namingStrategy; + $this->_attributes['quoteStrategy'] = $namingStrategy; } /** - * Get quote strategy class. + * Get quote strategy. * * @since 2.3 - * @return string + * @return Doctrine\ORM\Mapping\QuoteStrategy */ - public function getQuoteStrategyClassName() + public function getQuoteStrategy() { - return isset($this->_attributes['quoteStrategyClassName']) - ? $this->_attributes['quoteStrategyClassName'] - : 'Doctrine\ORM\Mapping\DefaultQuoteStrategy'; + if ( ! isset($this->_attributes['quoteStrategy'])) { + $this->_attributes['quoteStrategy'] = new \Doctrine\ORM\Mapping\DefaultQuoteStrategy(); + } + + return $this->_attributes['quoteStrategy']; } } diff --git a/lib/Doctrine/ORM/EntityManager.php b/lib/Doctrine/ORM/EntityManager.php index de81cdc2f..d8ef431ab 100644 --- a/lib/Doctrine/ORM/EntityManager.php +++ b/lib/Doctrine/ORM/EntityManager.php @@ -62,13 +62,6 @@ class EntityManager implements ObjectManager */ private $metadataFactory; - /** - * The quote strategy. - * - * @var \Doctrine\ORM\Mapping\QuoteStrategy. - */ - private $quoteStrategy; - /** * The EntityRepository instances. * @@ -140,7 +133,7 @@ class EntityManager implements ObjectManager $this->eventManager = $eventManager; $metadataFactoryClassName = $config->getClassMetadataFactoryName(); - + $this->metadataFactory = new $metadataFactoryClassName; $this->metadataFactory->setEntityManager($this); $this->metadataFactory->setCacheDriver($this->config->getMetadataCacheImpl()); @@ -174,21 +167,6 @@ class EntityManager implements ObjectManager return $this->metadataFactory; } - /** - * Gets the quote strategy. - * - * @return \Doctrine\ORM\Mapping\QuoteStrategy - */ - public function getQuoteStrategy() - { - if ($this->quoteStrategy === null) { - $className = $this->getConfiguration()->getQuoteStrategyClassName(); - $this->quoteStrategy = new $className($this->getConnection()->getDatabasePlatform()); - } - - return $this->quoteStrategy; - } - /** * Gets an ExpressionBuilder used for object-oriented construction of query expressions. * diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php index c0bb0c66d..02792b98d 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php @@ -660,7 +660,7 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface if ($quoted) { $definition['quoted'] = true; } - $sequenceName = $this->em->getQuoteStrategy()->getSequenceName($definition, $class); + $sequenceName = $this->em->getConfiguration()->getQuoteStrategy()->getSequenceName($definition, $class, $this->targetPlatform); } $class->setIdGenerator(new \Doctrine\ORM\Id\IdentityGenerator($sequenceName)); break; @@ -681,7 +681,7 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface $class->setSequenceGeneratorDefinition($definition); } $sequenceGenerator = new \Doctrine\ORM\Id\SequenceGenerator( - $this->em->getQuoteStrategy()->getSequenceName($definition, $class), + $this->em->getConfiguration()->getQuoteStrategy()->getSequenceName($definition, $class, $this->targetPlatform), $definition['allocationSize'] ); $class->setIdGenerator($sequenceGenerator); diff --git a/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php b/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php index 076d98b2a..1470c0629 100644 --- a/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php +++ b/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php @@ -19,6 +19,8 @@ namespace Doctrine\ORM\Mapping; +use Doctrine\ORM\Mapping\ClassMetadata; +use Doctrine\DBAL\Platforms\AbstractPlatform; /** * A set of rules for determining the physical column, alias and table quotes @@ -26,85 +28,84 @@ namespace Doctrine\ORM\Mapping; * @since 2.3 * @author Fabio B. Silva */ -class DefaultQuoteStrategy extends QuoteStrategy +class DefaultQuoteStrategy implements QuoteStrategy { /** * {@inheritdoc} */ - public function getColumnName($fieldName, ClassMetadata $class) + public function getColumnName($fieldName, ClassMetadata $class, AbstractPlatform $platform) { return isset($class->fieldMappings[$fieldName]['quoted']) - ? $this->platform->quoteIdentifier($class->fieldMappings[$fieldName]['columnName']) + ? $platform->quoteIdentifier($class->fieldMappings[$fieldName]['columnName']) : $class->fieldMappings[$fieldName]['columnName']; } /** * {@inheritdoc} */ - public function getTableName(ClassMetadata $class) + public function getTableName(ClassMetadata $class, AbstractPlatform $platform) { return isset($class->table['quoted']) - ? $this->platform->quoteIdentifier($class->table['name']) + ? $platform->quoteIdentifier($class->table['name']) : $class->table['name']; } /** * {@inheritdoc} */ - public function getSequenceName(array $definition, ClassMetadata $class) + public function getSequenceName(array $definition, ClassMetadata $class, AbstractPlatform $platform) { return isset($definition['quoted']) - ? $this->platform->quoteSingleIdentifier($definition['sequenceName']) + ? $platform->quoteIdentifier($definition['sequenceName']) : $definition['sequenceName']; } /** * {@inheritdoc} */ - public function getJoinColumnName(array $joinColumn, ClassMetadata $class) + public function getJoinColumnName(array $joinColumn, ClassMetadata $class, AbstractPlatform $platform) { return isset($joinColumn['quoted']) - ? $this->platform->quoteIdentifier($joinColumn['name']) + ? $platform->quoteIdentifier($joinColumn['name']) : $joinColumn['name']; } /** * {@inheritdoc} */ - public function getReferencedJoinColumnName(array $joinColumn, ClassMetadata $class) + public function getReferencedJoinColumnName(array $joinColumn, ClassMetadata $class, AbstractPlatform $platform) { return isset($joinColumn['quoted']) - ? $this->platform->quoteIdentifier($joinColumn['referencedColumnName']) + ? $platform->quoteIdentifier($joinColumn['referencedColumnName']) : $joinColumn['referencedColumnName']; } /** * {@inheritdoc} */ - public function getJoinTableName(array $association, ClassMetadata $class) + public function getJoinTableName(array $association, ClassMetadata $class, AbstractPlatform $platform) { return isset($association['joinTable']['quoted']) - ? $this->platform->quoteIdentifier($association['joinTable']['name']) + ? $platform->quoteIdentifier($association['joinTable']['name']) : $association['joinTable']['name']; } /** * {@inheritdoc} */ - public function getIdentifierColumnNames(ClassMetadata $class) + public function getIdentifierColumnNames(ClassMetadata $class, AbstractPlatform $platform) { $quotedColumnNames = array(); foreach ($class->identifier as $fieldName) { if (isset($class->fieldMappings[$fieldName])) { - $quotedColumnNames[] = $this->getColumnName($fieldName, $class); + $quotedColumnNames[] = $this->getColumnName($fieldName, $class, $platform); continue; } // Association defined as Id field - $platform = $this->platform; $joinColumns = $class->associationMappings[$fieldName]['joinColumns']; $assocQuotedColumnNames = array_map( function ($joinColumn) use ($platform) { @@ -124,16 +125,16 @@ class DefaultQuoteStrategy extends QuoteStrategy /** * {@inheritdoc} */ - public function getColumnAlias($columnName, $counter, ClassMetadata $class = null) + public function getColumnAlias($columnName, $counter, AbstractPlatform $platform, ClassMetadata $class = null) { // 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. // And strip non alphanumeric characters $columnName = $columnName . $counter; - $columnName = substr($columnName, -$this->platform->getMaxIdentifierLength()); + $columnName = substr($columnName, -$platform->getMaxIdentifierLength()); $columnName = preg_replace('/[^A-Za-z0-9_]/', '', $columnName); - return $this->platform->getSQLResultCasing($columnName); + return $platform->getSQLResultCasing($columnName); } } \ No newline at end of file diff --git a/lib/Doctrine/ORM/Mapping/QuoteStrategy.php b/lib/Doctrine/ORM/Mapping/QuoteStrategy.php index 9e16999d8..9e698db22 100644 --- a/lib/Doctrine/ORM/Mapping/QuoteStrategy.php +++ b/lib/Doctrine/ORM/Mapping/QuoteStrategy.php @@ -23,95 +23,91 @@ use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\DBAL\Platforms\AbstractPlatform; /** - * A set of rules for determining the physical column, alias and table quotes + * A set of rules for determining the column, alias and table quotes * * @since 2.3 * @author Fabio B. Silva */ -abstract class QuoteStrategy +interface QuoteStrategy { - /** - * @var \Doctrine\DBAL\Platforms\AbstractPlatform - */ - protected $platform; - - /** - * @param AbstractPlatform $platform - */ - public function __construct(AbstractPlatform $platform) - { - $this->platform = $platform; - } /** * Gets the (possibly quoted) column name for safe use in an SQL statement. * * @param string $fieldName * @param ClassMetadata $class + * @param AbstractPlatform $platform * @return string */ - abstract public function getColumnName($fieldName, ClassMetadata $class); + function getColumnName($fieldName, ClassMetadata $class, AbstractPlatform $platform); /** * Gets the (possibly quoted) primary table name for safe use in an SQL statement. * * @param ClassMetadata $class + * @param AbstractPlatform $platform * @return string */ - abstract public function getTableName(ClassMetadata $class); + function getTableName(ClassMetadata $class, AbstractPlatform $platform); /** * Gets the (possibly quoted) sequence name for safe use in an SQL statement. * * @param array $definition * @param ClassMetadata $class + * @param AbstractPlatform $platform * @return string */ - abstract public function getSequenceName(array $definition, ClassMetadata $class); + function getSequenceName(array $definition, ClassMetadata $class, AbstractPlatform $platform); /** * Gets the (possibly quoted) name of the join table. * * @param array $association * @param ClassMetadata $class + * @param AbstractPlatform $platform * @return string */ - abstract public function getJoinTableName(array $association, ClassMetadata $class); + function getJoinTableName(array $association, ClassMetadata $class, AbstractPlatform $platform); /** * Gets the (possibly quoted) join column name. * * @param array $joinColumn * @param ClassMetadata $class + * @param AbstractPlatform $platform * @return string */ - abstract public function getJoinColumnName(array $joinColumn, ClassMetadata $class); + function getJoinColumnName(array $joinColumn, ClassMetadata $class, AbstractPlatform $platform); /** * Gets the (possibly quoted) join column name. * * @param array $joinColumn * @param ClassMetadata $class + * @param AbstractPlatform $platform * @return string */ - abstract public function getReferencedJoinColumnName(array $joinColumn, ClassMetadata $class); + function getReferencedJoinColumnName(array $joinColumn, ClassMetadata $class, AbstractPlatform $platform); /** * Gets the (possibly quoted) identifier column names for safe use in an SQL statement. * * @param ClassMetadata $class + * @param AbstractPlatform $platform * @return array */ - abstract public function getIdentifierColumnNames(ClassMetadata $class); + function getIdentifierColumnNames(ClassMetadata $class, AbstractPlatform $platform); /** * Gets the column alias. * * @param string $columnName * @param integer $counter + * @param AbstractPlatform $platform * @param ClassMetadata $class * @return string */ - abstract public function getColumnAlias($columnName, $counter, ClassMetadata $class = null); + function getColumnAlias($columnName, $counter, AbstractPlatform $platform, ClassMetadata $class = null); } \ No newline at end of file diff --git a/lib/Doctrine/ORM/Persisters/AbstractCollectionPersister.php b/lib/Doctrine/ORM/Persisters/AbstractCollectionPersister.php index 6ae07bc3f..2728918c0 100644 --- a/lib/Doctrine/ORM/Persisters/AbstractCollectionPersister.php +++ b/lib/Doctrine/ORM/Persisters/AbstractCollectionPersister.php @@ -45,6 +45,13 @@ abstract class AbstractCollectionPersister */ protected $_uow; + /** + * The database platform. + * + * @var \Doctrine\DBAL\Platforms\AbstractPlatform + */ + protected $platform; + /** * The quote strategy. * @@ -62,7 +69,8 @@ abstract class AbstractCollectionPersister $this->_em = $em; $this->_uow = $em->getUnitOfWork(); $this->_conn = $em->getConnection(); - $this->quoteStrategy = $em->getQuoteStrategy(); + $this->platform = $this->_conn->getDatabasePlatform(); + $this->quoteStrategy = $em->getConfiguration()->getQuoteStrategy(); } /** diff --git a/lib/Doctrine/ORM/Persisters/AbstractEntityInheritancePersister.php b/lib/Doctrine/ORM/Persisters/AbstractEntityInheritancePersister.php index 3153c4064..19e77a4e7 100644 --- a/lib/Doctrine/ORM/Persisters/AbstractEntityInheritancePersister.php +++ b/lib/Doctrine/ORM/Persisters/AbstractEntityInheritancePersister.php @@ -61,7 +61,7 @@ abstract class AbstractEntityInheritancePersister extends BasicEntityPersister protected function _getSelectColumnSQL($field, ClassMetadata $class, $alias = 'r') { $columnName = $class->columnNames[$field]; - $sql = $this->_getSQLTableAlias($class->name, $alias == 'r' ? '' : $alias) . '.' . $this->quoteStrategy->getColumnName($field, $class); + $sql = $this->_getSQLTableAlias($class->name, $alias == 'r' ? '' : $alias) . '.' . $this->quoteStrategy->getColumnName($field, $class, $this->_platform); $columnAlias = $this->getSQLColumnAlias($columnName); $this->_rsm->addFieldResult($alias, $columnAlias, $field, $class->name); diff --git a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php index befc5af92..34ed11050 100644 --- a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php @@ -198,8 +198,8 @@ class BasicEntityPersister $this->_em = $em; $this->_class = $class; $this->_conn = $em->getConnection(); - $this->quoteStrategy = $em->getQuoteStrategy(); $this->_platform = $this->_conn->getDatabasePlatform(); + $this->quoteStrategy = $em->getConfiguration()->getQuoteStrategy(); } /** @@ -298,13 +298,13 @@ class BasicEntityPersister protected function fetchVersionValue($versionedClass, $id) { $versionField = $versionedClass->versionField; - $identifier = $this->quoteStrategy->getIdentifierColumnNames($versionedClass); + $identifier = $this->quoteStrategy->getIdentifierColumnNames($versionedClass, $this->_platform); - $versionFieldColumnName = $this->quoteStrategy->getColumnName($versionField, $versionedClass); + $versionFieldColumnName = $this->quoteStrategy->getColumnName($versionField, $versionedClass, $this->_platform); //FIXME: Order with composite keys might not be correct $sql = 'SELECT ' . $versionFieldColumnName - . ' FROM ' . $this->quoteStrategy->getTableName($versionedClass) + . ' FROM ' . $this->quoteStrategy->getTableName($versionedClass, $this->_platform) . ' WHERE ' . implode(' = ? AND ', $identifier) . ' = ?'; $value = $this->_conn->fetchColumn($sql, array_values((array)$id)); @@ -332,7 +332,7 @@ class BasicEntityPersister if (isset($updateData[$tableName]) && $updateData[$tableName]) { $this->_updateTable( - $entity, $this->quoteStrategy->getTableName($this->_class), + $entity, $this->quoteStrategy->getTableName($this->_class, $this->_platform), $updateData[$tableName], $this->_class->isVersioned ); @@ -361,7 +361,7 @@ class BasicEntityPersister $placeholder = '?'; if (isset($this->_class->fieldNames[$columnName])) { - $column = $this->quoteStrategy->getColumnName($this->_class->fieldNames[$columnName], $this->_class); + $column = $this->quoteStrategy->getColumnName($this->_class->fieldNames[$columnName], $this->_class, $this->_platform); if (isset($this->_class->fieldMappings[$this->_class->fieldNames[$columnName]]['requireSQLConversion'])) { $type = Type::getType($this->_columnTypes[$columnName]); @@ -386,7 +386,7 @@ class BasicEntityPersister $params[] = $id[$idField]; $types[] = $targetMapping->fieldMappings[$targetMapping->identifier[0]]['type']; } else { - $where[] = $this->quoteStrategy->getColumnName($idField, $this->_class); + $where[] = $this->quoteStrategy->getColumnName($idField, $this->_class, $this->_platform); $params[] = $id[$idField]; $types[] = $this->_class->fieldMappings[$idField]['type']; } @@ -395,7 +395,7 @@ class BasicEntityPersister if ($versioned) { $versionField = $this->_class->versionField; $versionFieldType = $this->_class->fieldMappings[$versionField]['type']; - $versionColumn = $this->quoteStrategy->getColumnName($versionField, $this->_class); + $versionColumn = $this->quoteStrategy->getColumnName($versionField, $this->_class, $this->_platform); if ($versionFieldType == Type::INTEGER) { $set[] = $versionColumn . ' = ' . $versionColumn . ' + 1'; @@ -439,30 +439,30 @@ class BasicEntityPersister $mapping = $relatedClass->associationMappings[$mapping['mappedBy']]; foreach ($mapping['joinTable']['inverseJoinColumns'] as $joinColumn) { - $keys[] = $this->quoteStrategy->getJoinColumnName($joinColumn, $relatedClass); + $keys[] = $this->quoteStrategy->getJoinColumnName($joinColumn, $relatedClass, $this->_platform); } if ($selfReferential) { foreach ($mapping['joinTable']['joinColumns'] as $joinColumn) { - $otherKeys[] = $this->quoteStrategy->getJoinColumnName($joinColumn, $relatedClass); + $otherKeys[] = $this->quoteStrategy->getJoinColumnName($joinColumn, $relatedClass, $this->_platform); } } } else { foreach ($mapping['joinTable']['joinColumns'] as $joinColumn) { - $keys[] = $this->quoteStrategy->getJoinColumnName($joinColumn, $this->_class); + $keys[] = $this->quoteStrategy->getJoinColumnName($joinColumn, $this->_class, $this->_platform); } if ($selfReferential) { foreach ($mapping['joinTable']['inverseJoinColumns'] as $joinColumn) { - $otherKeys[] = $this->quoteStrategy->getJoinColumnName($joinColumn, $this->_class); + $otherKeys[] = $this->quoteStrategy->getJoinColumnName($joinColumn, $this->_class, $this->_platform); } } } if ( ! isset($mapping['isOnDeleteCascade'])) { - $joinTableName = $this->quoteStrategy->getJoinTableName($mapping, $this->_class); + $joinTableName = $this->quoteStrategy->getJoinTableName($mapping, $this->_class, $this->_platform); $this->_conn->delete($joinTableName, array_combine($keys, $identifier)); if ($selfReferential) { @@ -488,8 +488,8 @@ class BasicEntityPersister $identifier = $this->_em->getUnitOfWork()->getEntityIdentifier($entity); $this->deleteJoinTableRecords($identifier); - $id = array_combine($this->quoteStrategy->getIdentifierColumnNames($this->_class), $identifier); - $this->_conn->delete($this->quoteStrategy->getTableName($this->_class), $id); + $id = array_combine($this->quoteStrategy->getIdentifierColumnNames($this->_class, $this->_platform), $identifier); + $this->_conn->delete($this->quoteStrategy->getTableName($this->_class, $this->_platform), $id); } /** @@ -561,7 +561,7 @@ class BasicEntityPersister $sourceColumn = $joinColumn['name']; $targetColumn = $joinColumn['referencedColumnName']; - $quotedColumn = $this->quoteStrategy->getJoinColumnName($joinColumn, $this->_class); + $quotedColumn = $this->quoteStrategy->getJoinColumnName($joinColumn, $this->_class, $this->_platform); $this->quotedColumns[$sourceColumn] = $quotedColumn; if ($newVal === null) { @@ -841,7 +841,7 @@ class BasicEntityPersister $sourceClass = $this->_em->getClassMetadata($assoc['sourceEntity']); if ($assoc['isOwningSide']) { - $quotedJoinTable = $this->quoteStrategy->getJoinTableName($assoc, $sourceClass); + $quotedJoinTable = $this->quoteStrategy->getJoinTableName($assoc, $sourceClass, $this->_platform); foreach ($assoc['relationToSourceKeyColumns'] as $relationKeyColumn => $sourceKeyColumn) { if ($sourceClass->containsForeignIdentifier) { @@ -864,7 +864,7 @@ class BasicEntityPersister } } else { $owningAssoc = $this->_em->getClassMetadata($assoc['targetEntity'])->associationMappings[$assoc['mappedBy']]; - $quotedJoinTable = $this->quoteStrategy->getJoinTableName($owningAssoc, $sourceClass); + $quotedJoinTable = $this->quoteStrategy->getJoinTableName($owningAssoc, $sourceClass, $this->_platform); // TRICKY: since the association is inverted source and target are flipped foreach ($owningAssoc['relationToTargetKeyColumns'] as $relationKeyColumn => $sourceKeyColumn) { @@ -934,7 +934,7 @@ class BasicEntityPersister } return $this->_platform->modifyLimitQuery('SELECT ' . $this->_getSelectColumnListSQL() - . $this->_platform->appendLockHint(' FROM ' . $this->quoteStrategy->getTableName($this->_class) . ' ' + . $this->_platform->appendLockHint(' FROM ' . $this->quoteStrategy->getTableName($this->_class, $this->_platform) . ' ' . $alias, $lockMode) . $this->_selectJoinSql . $joinSql . ($conditionSql ? ' WHERE ' . $conditionSql : '') @@ -967,7 +967,7 @@ class BasicEntityPersister $this->_getSQLTableAlias($this->_class->fieldMappings[$fieldName]['inherited']) : $baseTableAlias; - $columnName = $this->quoteStrategy->getColumnName($fieldName, $this->_class); + $columnName = $this->quoteStrategy->getColumnName($fieldName, $this->_class, $this->_platform); $orderBySql .= $orderBySql ? ', ' : ' ORDER BY '; $orderBySql .= $tableAlias . '.' . $columnName . ' ' . $orientation; @@ -1045,12 +1045,12 @@ class BasicEntityPersister if ($assoc['isOwningSide']) { $this->_selectJoinSql .= ' ' . $this->getJoinSQLForJoinColumns($assoc['joinColumns']); - $this->_selectJoinSql .= ' ' . $this->quoteStrategy->getTableName($eagerEntity) . ' ' . $this->_getSQLTableAlias($eagerEntity->name, $assocAlias) .' ON '; + $this->_selectJoinSql .= ' ' . $this->quoteStrategy->getTableName($eagerEntity, $this->_platform) . ' ' . $this->_getSQLTableAlias($eagerEntity->name, $assocAlias) .' ON '; $tableAlias = $this->_getSQLTableAlias($assoc['targetEntity'], $assocAlias); foreach ($assoc['joinColumns'] as $joinColumn) { - $sourceCol = $this->quoteStrategy->getJoinColumnName($joinColumn, $this->_class); - $targetCol = $this->quoteStrategy->getReferencedJoinColumnName($joinColumn, $this->_class); + $sourceCol = $this->quoteStrategy->getJoinColumnName($joinColumn, $this->_class, $this->_platform); + $targetCol = $this->quoteStrategy->getReferencedJoinColumnName($joinColumn, $this->_class, $this->_platform); if ( ! $first) { $this->_selectJoinSql .= ' AND '; @@ -1069,7 +1069,7 @@ class BasicEntityPersister $owningAssoc = $eagerEntity->getAssociationMapping($assoc['mappedBy']); $this->_selectJoinSql .= ' LEFT JOIN'; - $this->_selectJoinSql .= ' ' . $this->quoteStrategy->getTableName($eagerEntity) . ' ' + $this->_selectJoinSql .= ' ' . $this->quoteStrategy->getTableName($eagerEntity, $this->_platform) . ' ' . $this->_getSQLTableAlias($eagerEntity->name, $assocAlias) . ' ON '; foreach ($owningAssoc['sourceToTargetKeyColumns'] as $sourceCol => $targetCol) { @@ -1109,7 +1109,7 @@ class BasicEntityPersister if ($columnList) $columnList .= ', '; - $quotedColumn = $this->quoteStrategy->getJoinColumnName($joinColumn, $this->_class); + $quotedColumn = $this->quoteStrategy->getJoinColumnName($joinColumn, $this->_class, $this->_platform); $resultColumnName = $this->getSQLColumnAlias($joinColumn['name']); $columnList .= $this->_getSQLTableAlias($class->name, ($alias == 'r' ? '' : $alias) ) . '.' . $quotedColumn . ' AS ' . $resultColumnName; @@ -1137,7 +1137,7 @@ class BasicEntityPersister $joinClauses = $owningAssoc['relationToSourceKeyColumns']; } - $joinTableName = $this->quoteStrategy->getJoinTableName($owningAssoc, $this->_class); + $joinTableName = $this->quoteStrategy->getJoinTableName($owningAssoc, $this->_class, $this->_platform); $joinSql = ''; foreach ($joinClauses as $joinTableColumn => $sourceColumn) { @@ -1146,7 +1146,7 @@ class BasicEntityPersister if ($this->_class->containsForeignIdentifier && ! isset($this->_class->fieldNames[$sourceColumn])) { $quotedColumn = $sourceColumn; // join columns cannot be quoted } else { - $quotedColumn = $this->quoteStrategy->getColumnName($this->_class->fieldNames[$sourceColumn], $this->_class); + $quotedColumn = $this->quoteStrategy->getColumnName($this->_class->fieldNames[$sourceColumn], $this->_class, $this->_platform); } $joinSql .= $this->_getSQLTableAlias($this->_class->name) . '.' . $quotedColumn . ' = ' @@ -1169,8 +1169,8 @@ class BasicEntityPersister if (empty($columns)) { $insertSql = $this->_platform->getEmptyIdentityInsertSQL( - $this->quoteStrategy->getTableName($this->_class), - $this->quoteStrategy->getColumnName($this->_class->identifier[0], $this->_class) + $this->quoteStrategy->getTableName($this->_class, $this->_platform), + $this->quoteStrategy->getColumnName($this->_class->identifier[0], $this->_class, $this->_platform) ); } else { $columns = array_unique($columns); @@ -1189,7 +1189,7 @@ class BasicEntityPersister $values[] = $placeholder; } - $insertSql = 'INSERT INTO ' . $this->quoteStrategy->getTableName($this->_class) + $insertSql = 'INSERT INTO ' . $this->quoteStrategy->getTableName($this->_class, $this->_platform) . ' (' . implode(', ', $columns) . ') VALUES (' . implode(', ', $values) . ')'; } @@ -1220,11 +1220,11 @@ class BasicEntityPersister $assoc = $this->_class->associationMappings[$name]; if ($assoc['isOwningSide'] && $assoc['type'] & ClassMetadata::TO_ONE) { foreach ($assoc['joinColumns'] as $joinColumn) { - $columns[] = $this->quoteStrategy->getJoinColumnName($joinColumn, $this->_class); + $columns[] = $this->quoteStrategy->getJoinColumnName($joinColumn, $this->_class, $this->_platform); } } } else if ($this->_class->generatorType != ClassMetadata::GENERATOR_TYPE_IDENTITY || $this->_class->identifier[0] != $name) { - $columns[] = $this->quoteStrategy->getColumnName($name, $this->_class); + $columns[] = $this->quoteStrategy->getColumnName($name, $this->_class, $this->_platform); $this->_columnTypes[$name] = $this->_class->fieldMappings[$name]['type']; } } @@ -1243,7 +1243,7 @@ class BasicEntityPersister protected function _getSelectColumnSQL($field, ClassMetadata $class, $alias = 'r') { $sql = $this->_getSQLTableAlias($class->name, $alias == 'r' ? '' : $alias) - . '.' . $this->quoteStrategy->getColumnName($field, $class); + . '.' . $this->quoteStrategy->getColumnName($field, $class, $this->_platform); $columnAlias = $this->getSQLColumnAlias($class->columnNames[$field]); $this->_rsm->addFieldResult($alias, $columnAlias, $field); @@ -1313,7 +1313,7 @@ class BasicEntityPersister */ protected function getLockTablesSql() { - return 'FROM ' . $this->quoteStrategy->getTableName($this->_class) . ' ' + return 'FROM ' . $this->quoteStrategy->getTableName($this->_class, $this->_platform) . ' ' . $this->_getSQLTableAlias($this->_class->name); } @@ -1342,7 +1342,7 @@ class BasicEntityPersister ? $this->_class->fieldMappings[$field]['inherited'] : $this->_class->name; - $conditionSql .= $this->_getSQLTableAlias($className) . '.' . $this->quoteStrategy->getColumnName($field, $this->_class); + $conditionSql .= $this->_getSQLTableAlias($className) . '.' . $this->quoteStrategy->getColumnName($field, $this->_class, $this->_platform); if (isset($this->_class->fieldMappings[$field]['requireSQLConversion'])) { $type = Type::getType($this->_class->getTypeOfField($field)); @@ -1610,7 +1610,7 @@ class BasicEntityPersister */ public function getSQLColumnAlias($columnName) { - return $this->quoteStrategy->getColumnAlias($columnName, $this->_sqlAliasCounter++); + return $this->quoteStrategy->getColumnAlias($columnName, $this->_sqlAliasCounter++, $this->_platform); } /** diff --git a/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php b/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php index 458bcc61e..b41fbaede 100644 --- a/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php +++ b/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php @@ -105,7 +105,7 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister $tableName = $cm->getTableName(); $this->_owningTableMap[$fieldName] = $tableName; - $this->_quotedTableMap[$tableName] = $this->quoteStrategy->getTableName($cm); + $this->_quotedTableMap[$tableName] = $this->quoteStrategy->getTableName($cm, $this->_platform); return $tableName; } @@ -225,7 +225,7 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister // Make sure the table with the version column is updated even if no columns on that // table were affected. if ($isVersioned && ! isset($updateData[$versionedTable])) { - $this->_updateTable($entity, $this->quoteStrategy->getTableName($versionedClass), array(), true); + $this->_updateTable($entity, $this->quoteStrategy->getTableName($versionedClass, $this->_platform), array(), true); $id = $this->_em->getUnitOfWork()->getEntityIdentifier($entity); $this->assignDefaultVersionValue($entity, $id); @@ -247,15 +247,15 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister // delete the row from the root table. Cascades do the rest. if ($this->_platform->supportsForeignKeyConstraints()) { $this->_conn->delete( - $this->quoteStrategy->getTableName($this->_em->getClassMetadata($this->_class->rootEntityName)), $id + $this->quoteStrategy->getTableName($this->_em->getClassMetadata($this->_class->rootEntityName), $this->_platform), $id ); } else { // Delete from all tables individually, starting from this class' table up to the root table. - $this->_conn->delete($this->quoteStrategy->getTableName($this->_class), $id); + $this->_conn->delete($this->quoteStrategy->getTableName($this->_class, $this->_platform), $id); foreach ($this->_class->parentClasses as $parentClass) { $this->_conn->delete( - $this->quoteStrategy->getTableName($this->_em->getClassMetadata($parentClass)), $id + $this->quoteStrategy->getTableName($this->_em->getClassMetadata($parentClass), $this->_platform), $id ); } } @@ -321,7 +321,7 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister foreach ($this->_class->parentClasses as $parentClassName) { $parentClass = $this->_em->getClassMetadata($parentClassName); $tableAlias = $this->_getSQLTableAlias($parentClassName); - $joinSql .= ' INNER JOIN ' . $this->quoteStrategy->getTableName($parentClass) . ' ' . $tableAlias . ' ON '; + $joinSql .= ' INNER JOIN ' . $this->quoteStrategy->getTableName($parentClass, $this->_platform) . ' ' . $tableAlias . ' ON '; $first = true; foreach ($idColumns as $idColumn) { @@ -361,7 +361,7 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister } // Add LEFT JOIN - $joinSql .= ' LEFT JOIN ' . $this->quoteStrategy->getTableName($subClass) . ' ' . $tableAlias . ' ON '; + $joinSql .= ' LEFT JOIN ' . $this->quoteStrategy->getTableName($subClass, $this->_platform) . ' ' . $tableAlias . ' ON '; $first = true; foreach ($idColumns as $idColumn) { @@ -400,7 +400,7 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister } return $this->_platform->modifyLimitQuery('SELECT ' . $this->_selectColumnListSql - . ' FROM ' . $this->quoteStrategy->getTableName($this->_class) . ' ' . $baseTableAlias + . ' FROM ' . $this->quoteStrategy->getTableName($this->_class, $this->_platform) . ' ' . $baseTableAlias . $joinSql . ($conditionSql != '' ? ' WHERE ' . $conditionSql : '') . $orderBySql, $limit, $offset) . $lockSql; @@ -422,7 +422,7 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister foreach ($this->_class->parentClasses as $parentClassName) { $parentClass = $this->_em->getClassMetadata($parentClassName); $tableAlias = $this->_getSQLTableAlias($parentClassName); - $joinSql .= ' INNER JOIN ' . $this->quoteStrategy->getTableName($parentClass) . ' ' . $tableAlias . ' ON '; + $joinSql .= ' INNER JOIN ' . $this->quoteStrategy->getTableName($parentClass, $this->_platform) . ' ' . $tableAlias . ' ON '; $first = true; foreach ($idColumns as $idColumn) { @@ -432,7 +432,7 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister } } - return 'FROM ' .$this->quoteStrategy->getTableName($this->_class) . ' ' . $baseTableAlias . $joinSql; + return 'FROM ' .$this->quoteStrategy->getTableName($this->_class, $this->_platform) . ' ' . $baseTableAlias . $joinSql; } /* Ensure this method is never called. This persister overrides _getSelectEntitiesSQL directly. */ @@ -463,7 +463,7 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister } } else if ($this->_class->name != $this->_class->rootEntityName || ! $this->_class->isIdGeneratorIdentity() || $this->_class->identifier[0] != $name) { - $columns[] = $this->quoteStrategy->getColumnName($name, $this->_class); + $columns[] = $this->quoteStrategy->getColumnName($name, $this->_class, $this->_platform); } } diff --git a/lib/Doctrine/ORM/Persisters/ManyToManyPersister.php b/lib/Doctrine/ORM/Persisters/ManyToManyPersister.php index dbbadadf0..c65652644 100644 --- a/lib/Doctrine/ORM/Persisters/ManyToManyPersister.php +++ b/lib/Doctrine/ORM/Persisters/ManyToManyPersister.php @@ -45,7 +45,7 @@ class ManyToManyPersister extends AbstractCollectionPersister $mapping = $coll->getMapping(); $class = $this->_em->getClassMetadata(get_class($coll->getOwner())); - return 'DELETE FROM ' . $this->quoteStrategy->getJoinTableName($mapping, $class) + return 'DELETE FROM ' . $this->quoteStrategy->getJoinTableName($mapping, $class, $this->platform) . ' WHERE ' . implode(' = ? AND ', $mapping['joinTableColumns']) . ' = ?'; } @@ -81,7 +81,7 @@ class ManyToManyPersister extends AbstractCollectionPersister $mapping = $coll->getMapping(); $columns = $mapping['joinTableColumns']; $class = $this->_em->getClassMetadata(get_class($coll->getOwner())); - $joinTable = $this->quoteStrategy->getJoinTableName($mapping, $class); + $joinTable = $this->quoteStrategy->getJoinTableName($mapping, $class, $this->platform); return 'INSERT INTO ' . $joinTable . ' (' . implode(', ', $columns) . ')' . ' VALUES (' . implode(', ', array_fill(0, count($columns), '?')) . ')'; @@ -151,7 +151,7 @@ class ManyToManyPersister extends AbstractCollectionPersister { $class = $this->_em->getClassMetadata(get_class($coll->getOwner())); $mapping = $coll->getMapping(); - $joinTable = $this->quoteStrategy->getJoinTableName($mapping, $class); + $joinTable = $this->quoteStrategy->getJoinTableName($mapping, $class, $this->platform); return 'DELETE FROM ' . $joinTable . ' WHERE ' . implode(' = ? AND ', array_keys($mapping['relationToSourceKeyColumns'])) . ' = ?'; @@ -224,7 +224,7 @@ class ManyToManyPersister extends AbstractCollectionPersister } $sql = 'SELECT COUNT(*)' - . ' FROM ' . $this->quoteStrategy->getJoinTableName($mapping, $class) . ' t' + . ' FROM ' . $this->quoteStrategy->getJoinTableName($mapping, $class, $this->platform) . ' t' . $joinTargetEntitySQL . ' WHERE ' . implode(' AND ', $whereClauses); @@ -326,7 +326,7 @@ class ManyToManyPersister extends AbstractCollectionPersister $targetId = $uow->getEntityIdentifier($element); } - $quotedJoinTable = $this->quoteStrategy->getJoinTableName($mapping, $sourceClass); + $quotedJoinTable = $this->quoteStrategy->getJoinTableName($mapping, $sourceClass, $this->platform); $whereClauses = array(); $params = array(); @@ -387,7 +387,7 @@ class ManyToManyPersister extends AbstractCollectionPersister $joinTargetEntitySQL = ''; if ($filterSql = $this->generateFilterConditionSQL($targetClass, 'te')) { $joinTargetEntitySQL = ' JOIN ' - . $this->quoteStrategy->getTableName($targetClass) . ' te' + . $this->quoteStrategy->getTableName($targetClass, $this->platform) . ' te' . ' ON'; $joinTargetEntitySQLClauses = array(); diff --git a/lib/Doctrine/ORM/Persisters/OneToManyPersister.php b/lib/Doctrine/ORM/Persisters/OneToManyPersister.php index ee807e210..aa0208fea 100644 --- a/lib/Doctrine/ORM/Persisters/OneToManyPersister.php +++ b/lib/Doctrine/ORM/Persisters/OneToManyPersister.php @@ -45,7 +45,7 @@ class OneToManyPersister extends AbstractCollectionPersister $mapping = $coll->getMapping(); $class = $this->_em->getClassMetadata($mapping['targetEntity']); - return 'DELETE FROM ' . $this->quoteStrategy->getTableName($class) + return 'DELETE FROM ' . $this->quoteStrategy->getTableName($class, $this->platform) . ' WHERE ' . implode('= ? AND ', $class->getIdentifierColumnNames()) . ' = ?'; } @@ -127,7 +127,7 @@ class OneToManyPersister extends AbstractCollectionPersister } $sql = 'SELECT count(*)' - . ' FROM ' . $this->quoteStrategy->getTableName($targetClass) . ' t' + . ' FROM ' . $this->quoteStrategy->getTableName($targetClass, $this->platform) . ' t' . ' WHERE ' . implode(' AND ', $whereClauses); return $this->_conn->fetchColumn($sql, $params); @@ -204,7 +204,7 @@ class OneToManyPersister extends AbstractCollectionPersister $mapping = $coll->getMapping(); $class = $this->_em->getClassMetadata($mapping['targetEntity']); - $sql = 'DELETE FROM ' . $this->quoteStrategy->getTableName($class) + $sql = 'DELETE FROM ' . $this->quoteStrategy->getTableName($class, $this->platform) . ' WHERE ' . implode('= ? AND ', $class->getIdentifierColumnNames()) . ' = ?'; return (bool) $this->_conn->executeUpdate($sql, $this->_getDeleteRowSQLParameters($coll, $element)); diff --git a/lib/Doctrine/ORM/Query/AST/Functions/SizeFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/SizeFunction.php index b8f83bed0..bffff29f1 100644 --- a/lib/Doctrine/ORM/Query/AST/Functions/SizeFunction.php +++ b/lib/Doctrine/ORM/Query/AST/Functions/SizeFunction.php @@ -42,7 +42,8 @@ class SizeFunction extends FunctionNode */ public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) { - $quoteStrategy = $sqlWalker->getEntityManager()->getQuoteStrategy(); + $platform = $sqlWalker->getEntityManager()->getConnection()->getDatabasePlatform(); + $quoteStrategy = $sqlWalker->getEntityManager()->getConfiguration()->getQuoteStrategy(); $dqlAlias = $this->collectionPathExpression->identificationVariable; $assocField = $this->collectionPathExpression->field; @@ -56,7 +57,7 @@ class SizeFunction extends FunctionNode $targetTableAlias = $sqlWalker->getSQLTableAlias($targetClass->getTableName()); $sourceTableAlias = $sqlWalker->getSQLTableAlias($class->getTableName(), $dqlAlias); - $sql .= $quoteStrategy->getTableName($targetClass) . ' ' . $targetTableAlias . ' WHERE '; + $sql .= $quoteStrategy->getTableName($targetClass, $platform) . ' ' . $targetTableAlias . ' WHERE '; $owningAssoc = $targetClass->associationMappings[$assoc['mappedBy']]; @@ -67,7 +68,7 @@ class SizeFunction extends FunctionNode $sql .= $targetTableAlias . '.' . $sourceColumn . ' = ' - . $sourceTableAlias . '.' . $quoteStrategy->getColumnName($class->fieldNames[$targetColumn], $class); + . $sourceTableAlias . '.' . $quoteStrategy->getColumnName($class->fieldNames[$targetColumn], $class, $platform); } } else { // many-to-many $targetClass = $sqlWalker->getEntityManager()->getClassMetadata($assoc['targetEntity']); @@ -80,7 +81,7 @@ class SizeFunction extends FunctionNode $sourceTableAlias = $sqlWalker->getSQLTableAlias($class->getTableName(), $dqlAlias); // join to target table - $sql .= $quoteStrategy->getJoinTableName($owningAssoc, $targetClass) . ' ' . $joinTableAlias . ' WHERE '; + $sql .= $quoteStrategy->getJoinTableName($owningAssoc, $targetClass, $platform) . ' ' . $joinTableAlias . ' WHERE '; $joinColumns = $assoc['isOwningSide'] ? $joinTable['joinColumns'] @@ -92,7 +93,7 @@ class SizeFunction extends FunctionNode if ($first) $first = false; else $sql .= ' AND '; $sourceColumnName = $quoteStrategy->getColumnName( - $class->fieldNames[$joinColumn['referencedColumnName']], $class + $class->fieldNames[$joinColumn['referencedColumnName']], $class, $platform ); $sql .= $joinTableAlias . '.' . $joinColumn['name'] diff --git a/lib/Doctrine/ORM/Query/Exec/MultiTableDeleteExecutor.php b/lib/Doctrine/ORM/Query/Exec/MultiTableDeleteExecutor.php index 5bb37834b..d40b37edc 100644 --- a/lib/Doctrine/ORM/Query/Exec/MultiTableDeleteExecutor.php +++ b/lib/Doctrine/ORM/Query/Exec/MultiTableDeleteExecutor.php @@ -50,7 +50,7 @@ class MultiTableDeleteExecutor extends AbstractSqlExecutor $em = $sqlWalker->getEntityManager(); $conn = $em->getConnection(); $platform = $conn->getDatabasePlatform(); - $quoteStrategy = $em->getQuoteStrategy(); + $quoteStrategy = $em->getConfiguration()->getQuoteStrategy(); $primaryClass = $em->getClassMetadata($AST->deleteClause->abstractSchemaName); $primaryDqlAlias = $AST->deleteClause->aliasIdentificationVariable; @@ -81,7 +81,7 @@ class MultiTableDeleteExecutor extends AbstractSqlExecutor // 3. Create and store DELETE statements $classNames = array_merge($primaryClass->parentClasses, array($primaryClass->name), $primaryClass->subClasses); foreach (array_reverse($classNames) as $className) { - $tableName = $quoteStrategy->getTableName($em->getClassMetadata($className)); + $tableName = $quoteStrategy->getTableName($em->getClassMetadata($className), $platform); $this->_sqlStatements[] = 'DELETE FROM ' . $tableName . ' WHERE (' . $idColumnList . ') IN (' . $idSubselect . ')'; } diff --git a/lib/Doctrine/ORM/Query/Exec/MultiTableUpdateExecutor.php b/lib/Doctrine/ORM/Query/Exec/MultiTableUpdateExecutor.php index 9f18ff8e8..7dc3fed82 100644 --- a/lib/Doctrine/ORM/Query/Exec/MultiTableUpdateExecutor.php +++ b/lib/Doctrine/ORM/Query/Exec/MultiTableUpdateExecutor.php @@ -53,7 +53,7 @@ class MultiTableUpdateExecutor extends AbstractSqlExecutor $em = $sqlWalker->getEntityManager(); $conn = $em->getConnection(); $platform = $conn->getDatabasePlatform(); - $quoteStrategy = $em->getQuoteStrategy(); + $quoteStrategy = $em->getConfiguration()->getQuoteStrategy(); $updateClause = $AST->updateClause; $primaryClass = $sqlWalker->getEntityManager()->getClassMetadata($updateClause->abstractSchemaName); @@ -86,7 +86,7 @@ class MultiTableUpdateExecutor extends AbstractSqlExecutor foreach (array_reverse($classNames) as $className) { $affected = false; $class = $em->getClassMetadata($className); - $updateSql = 'UPDATE ' . $quoteStrategy->getTableName($class) . ' SET '; + $updateSql = 'UPDATE ' . $quoteStrategy->getTableName($class, $platform) . ' SET '; foreach ($updateItems as $updateItem) { $field = $updateItem->pathExpression->field; diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index 481118efd..ffc39ab59 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -170,8 +170,8 @@ class SqlWalker implements TreeWalker $this->rsm = $parserResult->getResultSetMapping(); $this->em = $query->getEntityManager(); $this->conn = $this->em->getConnection(); - $this->quoteStrategy = $this->em->getQuoteStrategy(); $this->platform = $this->conn->getDatabasePlatform(); + $this->quoteStrategy = $this->em->getConfiguration()->getQuoteStrategy(); } /** @@ -286,7 +286,7 @@ class SqlWalker implements TreeWalker */ public function getSQLColumnAlias($columnName) { - return $this->quoteStrategy->getColumnAlias($columnName, $this->aliasCounter++); + return $this->quoteStrategy->getColumnAlias($columnName, $this->aliasCounter++, $this->platform); } /** @@ -310,11 +310,11 @@ class SqlWalker implements TreeWalker // If this is a joined association we must use left joins to preserve the correct result. $sql .= isset($this->queryComponents[$dqlAlias]['relation']) ? ' LEFT ' : ' INNER '; - $sql .= 'JOIN ' . $this->quoteStrategy->getTableName($parentClass) . ' ' . $tableAlias . ' ON '; + $sql .= 'JOIN ' . $this->quoteStrategy->getTableName($parentClass, $this->platform) . ' ' . $tableAlias . ' ON '; $sqlParts = array(); - foreach ($this->quoteStrategy->getIdentifierColumnNames($class) as $columnName) { + foreach ($this->quoteStrategy->getIdentifierColumnNames($class, $this->platform) as $columnName) { $sqlParts[] = $baseTableAlias . '.' . $columnName . ' = ' . $tableAlias . '.' . $columnName; } @@ -336,11 +336,11 @@ class SqlWalker implements TreeWalker $subClass = $this->em->getClassMetadata($subClassName); $tableAlias = $this->getSQLTableAlias($subClass->getTableName(), $dqlAlias); - $sql .= ' LEFT JOIN ' . $this->quoteStrategy->getTableName($subClass) . ' ' . $tableAlias . ' ON '; + $sql .= ' LEFT JOIN ' . $this->quoteStrategy->getTableName($subClass, $this->platform) . ' ' . $tableAlias . ' ON '; $sqlParts = array(); - foreach ($this->quoteStrategy->getIdentifierColumnNames($subClass) as $columnName) { + foreach ($this->quoteStrategy->getIdentifierColumnNames($subClass, $this->platform) as $columnName) { $sqlParts[] = $baseTableAlias . '.' . $columnName . ' = ' . $tableAlias . '.' . $columnName; } @@ -361,7 +361,7 @@ class SqlWalker implements TreeWalker if ( ! isset($qComp['relation']['orderBy'])) continue; foreach ($qComp['relation']['orderBy'] as $fieldName => $orientation) { - $columnName = $this->quoteStrategy->getColumnName($fieldName, $qComp['metadata']); + $columnName = $this->quoteStrategy->getColumnName($fieldName, $qComp['metadata'], $this->platform); $tableName = ($qComp['metadata']->isInheritanceTypeJoined()) ? $this->em->getUnitOfWork()->getEntityPersister($qComp['metadata']->name)->getOwningTable($fieldName) : $qComp['metadata']->getTableName(); @@ -544,7 +544,7 @@ class SqlWalker implements TreeWalker $tableAlias = $this->getSQLTableAlias($class->getTableName(), $identVariable); $sqlParts = array(); - foreach ($this->quoteStrategy->getIdentifierColumnNames($class) as $columnName) { + foreach ($this->quoteStrategy->getIdentifierColumnNames($class, $this->platform) as $columnName) { $sqlParts[] = $tableAlias . '.' . $columnName; } @@ -592,7 +592,7 @@ class SqlWalker implements TreeWalker $sql .= $this->walkIdentificationVariable($dqlAlias, $fieldName) . '.'; } - $sql .= $this->quoteStrategy->getColumnName($fieldName, $class); + $sql .= $this->quoteStrategy->getColumnName($fieldName, $class, $this->platform); break; case AST\PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION: @@ -1161,7 +1161,7 @@ class SqlWalker implements TreeWalker : $class->getTableName(); $sqlTableAlias = $this->getSQLTableAlias($tableName, $dqlAlias); - $columnName = $this->quoteStrategy->getColumnName($fieldName, $class); + $columnName = $this->quoteStrategy->getColumnName($fieldName, $class, $this->platform); $columnAlias = $this->getSQLColumnAlias($class->fieldMappings[$fieldName]['columnName']); $col = $sqlTableAlias . '.' . $columnName; @@ -1257,7 +1257,7 @@ class SqlWalker implements TreeWalker $sqlTableAlias = $this->getSQLTableAlias($tableName, $dqlAlias); $columnAlias = $this->getSQLColumnAlias($mapping['columnName']); - $quotedColumnName = $this->quoteStrategy->getColumnName($fieldName, $class); + $quotedColumnName = $this->quoteStrategy->getColumnName($fieldName, $class, $this->platform); $col = $sqlTableAlias . '.' . $quotedColumnName; @@ -1288,7 +1288,7 @@ class SqlWalker implements TreeWalker } $columnAlias = $this->getSQLColumnAlias($mapping['columnName']); - $quotedColumnName = $this->quoteStrategy->getColumnName($fieldName, $subClass); + $quotedColumnName = $this->quoteStrategy->getColumnName($fieldName, $subClass, $this->platform); $col = $sqlTableAlias . '.' . $quotedColumnName; @@ -1523,7 +1523,7 @@ class SqlWalker implements TreeWalker { $class = $this->em->getClassMetadata($deleteClause->abstractSchemaName); $tableName = $class->getTableName(); - $sql = 'DELETE FROM ' . $this->quoteStrategy->getTableName($class); + $sql = 'DELETE FROM ' . $this->quoteStrategy->getTableName($class, $this->platform); $this->setSQLTableAlias($tableName, $tableName, $deleteClause->aliasIdentificationVariable); $this->rootAliases[] = $deleteClause->aliasIdentificationVariable; @@ -1541,7 +1541,7 @@ class SqlWalker implements TreeWalker { $class = $this->em->getClassMetadata($updateClause->abstractSchemaName); $tableName = $class->getTableName(); - $sql = 'UPDATE ' . $this->quoteStrategy->getTableName($class); + $sql = 'UPDATE ' . $this->quoteStrategy->getTableName($class, $this->platform); $this->setSQLTableAlias($tableName, $tableName, $updateClause->aliasIdentificationVariable); $this->rootAliases[] = $updateClause->aliasIdentificationVariable; @@ -1752,18 +1752,18 @@ class SqlWalker implements TreeWalker $targetTableAlias = $this->getSQLTableAlias($targetClass->getTableName()); $sourceTableAlias = $this->getSQLTableAlias($class->getTableName(), $dqlAlias); - $sql .= $this->quoteStrategy->getTableName($targetClass) . ' ' . $targetTableAlias . ' WHERE '; + $sql .= $this->quoteStrategy->getTableName($targetClass, $this->platform) . ' ' . $targetTableAlias . ' WHERE '; $owningAssoc = $targetClass->associationMappings[$assoc['mappedBy']]; $sqlParts = array(); foreach ($owningAssoc['targetToSourceKeyColumns'] as $targetColumn => $sourceColumn) { - $targetColumn = $this->quoteStrategy->getColumnName($class->fieldNames[$targetColumn], $class); + $targetColumn = $this->quoteStrategy->getColumnName($class->fieldNames[$targetColumn], $class, $this->platform); $sqlParts[] = $sourceTableAlias . '.' . $targetColumn . ' = ' . $targetTableAlias . '.' . $sourceColumn; } - foreach ($this->quoteStrategy->getIdentifierColumnNames($targetClass) as $targetColumnName) { + foreach ($this->quoteStrategy->getIdentifierColumnNames($targetClass, $this->platform) as $targetColumnName) { if (isset($dqlParamKey)) { $this->parserResult->addParameterMapping($dqlParamKey, $this->sqlParamIndex++); } @@ -1784,15 +1784,15 @@ class SqlWalker implements TreeWalker $sourceTableAlias = $this->getSQLTableAlias($class->getTableName(), $dqlAlias); // join to target table - $sql .= $this->quoteStrategy->getJoinTableName($owningAssoc, $targetClass) . ' ' . $joinTableAlias - . ' INNER JOIN ' . $this->quoteStrategy->getTableName($targetClass) . ' ' . $targetTableAlias . ' ON '; + $sql .= $this->quoteStrategy->getJoinTableName($owningAssoc, $targetClass, $this->platform) . ' ' . $joinTableAlias + . ' INNER JOIN ' . $this->quoteStrategy->getTableName($targetClass, $this->platform) . ' ' . $targetTableAlias . ' ON '; // join conditions $joinColumns = $assoc['isOwningSide'] ? $joinTable['inverseJoinColumns'] : $joinTable['joinColumns']; $joinSqlParts = array(); foreach ($joinColumns as $joinColumn) { - $targetColumn = $this->quoteStrategy->getColumnName($targetClass->fieldNames[$joinColumn['referencedColumnName']], $targetClass); + $targetColumn = $this->quoteStrategy->getColumnName($targetClass->fieldNames[$joinColumn['referencedColumnName']], $targetClass, $this->platform); $joinSqlParts[] = $joinTableAlias . '.' . $joinColumn['name'] . ' = ' . $targetTableAlias . '.' . $targetColumn; } @@ -1804,12 +1804,12 @@ class SqlWalker implements TreeWalker $sqlParts = array(); foreach ($joinColumns as $joinColumn) { - $targetColumn = $this->quoteStrategy->getColumnName($class->fieldNames[$joinColumn['referencedColumnName']], $class); + $targetColumn = $this->quoteStrategy->getColumnName($class->fieldNames[$joinColumn['referencedColumnName']], $class, $this->platform); $sqlParts[] = $joinTableAlias . '.' . $joinColumn['name'] . ' = ' . $sourceTableAlias . '.' . $targetColumn; } - foreach ($this->quoteStrategy->getIdentifierColumnNames($targetClass) as $targetColumnName) { + foreach ($this->quoteStrategy->getIdentifierColumnNames($targetClass, $this->platform) as $targetColumnName) { if (isset($dqlParamKey)) { $this->parserResult->addParameterMapping($dqlParamKey, $this->sqlParamIndex++); } diff --git a/lib/Doctrine/ORM/Tools/SchemaTool.php b/lib/Doctrine/ORM/Tools/SchemaTool.php index 1ef28f1cb..f92825ce4 100644 --- a/lib/Doctrine/ORM/Tools/SchemaTool.php +++ b/lib/Doctrine/ORM/Tools/SchemaTool.php @@ -58,7 +58,7 @@ class SchemaTool * * @var \Doctrine\ORM\Mapping\QuoteStrategy */ - protected $quoteStrategy; + private $quoteStrategy; /** * Initializes a new SchemaTool instance that uses the connection of the @@ -69,8 +69,8 @@ class SchemaTool public function __construct(EntityManager $em) { $this->em = $em; - $this->quoteStrategy = $em->getQuoteStrategy(); $this->platform = $em->getConnection()->getDatabasePlatform(); + $this->quoteStrategy = $em->getConfiguration()->getQuoteStrategy(); } /** @@ -145,7 +145,7 @@ class SchemaTool continue; } - $table = $schema->createTable($this->quoteStrategy->getTableName($class)); + $table = $schema->createTable($this->quoteStrategy->getTableName($class, $this->platform)); $columns = array(); // table columns if ($class->isInheritanceTypeSingleTable()) { @@ -172,7 +172,7 @@ class SchemaTool $pkColumns = array(); foreach ($class->fieldMappings as $fieldName => $mapping) { if ( ! isset($mapping['inherited'])) { - $columnName = $this->quoteStrategy->getColumnName($mapping['fieldName'], $class); + $columnName = $this->quoteStrategy->getColumnName($mapping['fieldName'], $class, $this->platform); $this->_gatherColumn($class, $mapping, $table); if ($class->isIdentifier($fieldName)) { @@ -191,7 +191,7 @@ class SchemaTool /* @var \Doctrine\ORM\Mapping\ClassMetadata $class */ $idMapping = $class->fieldMappings[$class->identifier[0]]; $this->_gatherColumn($class, $idMapping, $table); - $columnName = $this->quoteStrategy->getColumnName($class->identifier[0], $class); + $columnName = $this->quoteStrategy->getColumnName($class->identifier[0], $class, $this->platform); // TODO: This seems rather hackish, can we optimize it? $table->getColumn($columnName)->setAutoincrement(false); @@ -199,7 +199,7 @@ class SchemaTool // Add a FK constraint on the ID column $table->addUnnamedForeignKeyConstraint( - $this->quoteStrategy->getTableName($this->em->getClassMetadata($class->rootEntityName)), + $this->quoteStrategy->getTableName($this->em->getClassMetadata($class->rootEntityName), $this->platform), array($columnName), array($columnName), array('onDelete' => 'CASCADE') ); } @@ -216,12 +216,12 @@ class SchemaTool $pkColumns = array(); foreach ($class->identifier as $identifierField) { if (isset($class->fieldMappings[$identifierField])) { - $pkColumns[] = $this->quoteStrategy->getColumnName($identifierField, $class); + $pkColumns[] = $this->quoteStrategy->getColumnName($identifierField, $class, $this->platform); } else if (isset($class->associationMappings[$identifierField])) { /* @var $assoc \Doctrine\ORM\Mapping\OneToOne */ $assoc = $class->associationMappings[$identifierField]; foreach ($assoc['joinColumns'] as $joinColumn) { - $pkColumns[] = $this->quoteStrategy->getJoinColumnName($joinColumn, $class); + $pkColumns[] = $this->quoteStrategy->getJoinColumnName($joinColumn, $class, $this->platform); } } } @@ -252,7 +252,7 @@ class SchemaTool if ($class->isIdGeneratorSequence() && $class->name == $class->rootEntityName) { $seqDef = $class->sequenceGeneratorDefinition; - $quotedName = $this->quoteStrategy->getSequenceName($seqDef, $class); + $quotedName = $this->quoteStrategy->getSequenceName($seqDef, $class, $this->platform); if ( ! $schema->hasSequence($quotedName)) { $schema->createSequence( $quotedName, @@ -328,7 +328,7 @@ class SchemaTool $column = $this->_gatherColumn($class, $mapping, $table); if ($class->isIdentifier($mapping['fieldName'])) { - $pkColumns[] = $this->quoteStrategy->getColumnName($mapping['fieldName'], $class); + $pkColumns[] = $this->quoteStrategy->getColumnName($mapping['fieldName'], $class, $this->platform); } } @@ -351,7 +351,7 @@ class SchemaTool */ private function _gatherColumn($class, array $mapping, $table) { - $columnName = $this->quoteStrategy->getColumnName($mapping['fieldName'], $class); + $columnName = $this->quoteStrategy->getColumnName($mapping['fieldName'], $class, $this->platform); $columnType = $mapping['type']; $options = array(); @@ -441,7 +441,7 @@ class SchemaTool // create join table $joinTable = $mapping['joinTable']; - $theJoinTable = $schema->createTable($this->quoteStrategy->getJoinTableName($mapping, $foreignClass)); + $theJoinTable = $schema->createTable($this->quoteStrategy->getJoinTableName($mapping, $foreignClass, $this->platform)); $primaryKeyColumns = $uniqueConstraints = array(); @@ -509,7 +509,7 @@ class SchemaTool $localColumns = array(); $foreignColumns = array(); $fkOptions = array(); - $foreignTableName = $this->quoteStrategy->getTableName($class); + $foreignTableName = $this->quoteStrategy->getTableName($class, $this->platform); foreach ($joinColumns as $joinColumn) { @@ -522,8 +522,8 @@ class SchemaTool ); } - $quotedColumnName = $this->quoteStrategy->getJoinColumnName($joinColumn, $class); - $quotedRefColumnName = $this->quoteStrategy->getReferencedJoinColumnName($joinColumn, $class); + $quotedColumnName = $this->quoteStrategy->getJoinColumnName($joinColumn, $class, $this->platform); + $quotedRefColumnName = $this->quoteStrategy->getReferencedJoinColumnName($joinColumn, $class, $this->platform); $primaryKeyColumns[] = $quotedColumnName; $localColumns[] = $quotedColumnName; diff --git a/tests/Doctrine/Tests/ORM/Mapping/QuoteStrategyTest.php b/tests/Doctrine/Tests/ORM/Mapping/QuoteStrategyTest.php index bc4313101..577c7a26e 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/QuoteStrategyTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/QuoteStrategyTest.php @@ -19,11 +19,17 @@ class QuoteStrategyTest extends \Doctrine\Tests\OrmTestCase */ private $strategy; + /** + * @var \Doctrine\DBAL\Platforms\AbstractPlatform + */ + private $platform; + protected function setUp() { parent::setUp(); $em = $this->_getTestEntityManager(); - $this->strategy = new DefaultQuoteStrategy($em->getConnection()->getDatabasePlatform()); + $this->platform = $em->getConnection()->getDatabasePlatform(); + $this->strategy = new DefaultQuoteStrategy(); } /** @@ -44,20 +50,20 @@ class QuoteStrategyTest extends \Doctrine\Tests\OrmTestCase $cm->mapField(array('fieldName' => 'name', 'columnName' => '`name`')); $cm->mapField(array('fieldName' => 'id', 'columnName' => 'id')); - $this->assertEquals('id' ,$this->strategy->getColumnName('id', $cm)); - $this->assertEquals('"name"' ,$this->strategy->getColumnName('name', $cm)); + $this->assertEquals('id' ,$this->strategy->getColumnName('id', $cm, $this->platform)); + $this->assertEquals('"name"' ,$this->strategy->getColumnName('name', $cm, $this->platform)); } public function testGetTableName() { $cm = $this->createClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); $cm->setPrimaryTable(array('name'=>'`cms_user`')); - $this->assertEquals('"cms_user"' ,$this->strategy->getTableName($cm)); + $this->assertEquals('"cms_user"' ,$this->strategy->getTableName($cm, $this->platform)); $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); $cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService); $cm->setPrimaryTable(array('name'=>'cms_user')); - $this->assertEquals('cms_user' ,$this->strategy->getTableName($cm)); + $this->assertEquals('cms_user' ,$this->strategy->getTableName($cm, $this->platform)); } public function testJoinTableName() @@ -84,8 +90,8 @@ class QuoteStrategyTest extends \Doctrine\Tests\OrmTestCase ) ); - $this->assertEquals('"cmsaddress_cmsuser"', $this->strategy->getJoinTableName($cm1->associationMappings['user'], $cm1)); - $this->assertEquals('cmsaddress_cmsuser', $this->strategy->getJoinTableName($cm2->associationMappings['user'], $cm2)); + $this->assertEquals('"cmsaddress_cmsuser"', $this->strategy->getJoinTableName($cm1->associationMappings['user'], $cm1, $this->platform)); + $this->assertEquals('cmsaddress_cmsuser', $this->strategy->getJoinTableName($cm2->associationMappings['user'], $cm2, $this->platform)); } @@ -106,18 +112,18 @@ class QuoteStrategyTest extends \Doctrine\Tests\OrmTestCase 'columnName' => 'id', )); - $this->assertEquals(array('"id"'), $this->strategy->getIdentifierColumnNames($cm1)); - $this->assertEquals(array('id'), $this->strategy->getIdentifierColumnNames($cm2)); + $this->assertEquals(array('"id"'), $this->strategy->getIdentifierColumnNames($cm1, $this->platform)); + $this->assertEquals(array('id'), $this->strategy->getIdentifierColumnNames($cm2, $this->platform)); } public function testColumnAlias() { $i = 0; - $this->assertEquals('columnName0', $this->strategy->getColumnAlias('columnName', $i++)); - $this->assertEquals('column_name1', $this->strategy->getColumnAlias('column_name', $i++)); - $this->assertEquals('COLUMN_NAME2', $this->strategy->getColumnAlias('COLUMN_NAME', $i++)); - $this->assertEquals('COLUMNNAME3', $this->strategy->getColumnAlias('COLUMN-NAME-', $i++)); + $this->assertEquals('columnName0', $this->strategy->getColumnAlias('columnName', $i++, $this->platform)); + $this->assertEquals('column_name1', $this->strategy->getColumnAlias('column_name', $i++, $this->platform)); + $this->assertEquals('COLUMN_NAME2', $this->strategy->getColumnAlias('COLUMN_NAME', $i++, $this->platform)); + $this->assertEquals('COLUMNNAME3', $this->strategy->getColumnAlias('COLUMN-NAME-', $i++, $this->platform)); } public function testQuoteIdentifierJoinColumns() @@ -133,7 +139,7 @@ class QuoteStrategyTest extends \Doctrine\Tests\OrmTestCase )), )); - $this->assertEquals(array('"article"'), $this->strategy->getIdentifierColumnNames($cm)); + $this->assertEquals(array('"article"'), $this->strategy->getIdentifierColumnNames($cm, $this->platform)); } public function testJoinColumnName() @@ -150,7 +156,7 @@ class QuoteStrategyTest extends \Doctrine\Tests\OrmTestCase )); $joinColumn = $cm->associationMappings['article']['joinColumns'][0]; - $this->assertEquals('"article"',$this->strategy->getJoinColumnName($joinColumn, $cm)); + $this->assertEquals('"article"',$this->strategy->getJoinColumnName($joinColumn, $cm, $this->platform)); } public function testReferencedJoinColumnName() @@ -167,6 +173,6 @@ class QuoteStrategyTest extends \Doctrine\Tests\OrmTestCase )); $joinColumn = $cm->associationMappings['article']['joinColumns'][0]; - $this->assertEquals('"id"',$this->strategy->getReferencedJoinColumnName($joinColumn, $cm)); + $this->assertEquals('"id"',$this->strategy->getReferencedJoinColumnName($joinColumn, $cm, $this->platform)); } } \ No newline at end of file From ea690489d750e17245d284bc92504dc1238ad308 Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Mon, 11 Jun 2012 21:38:55 -0300 Subject: [PATCH 31/37] revert wrong change --- .gitignore | 5 ----- lib/vendor/doctrine-common | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 265037d31..a91841777 100644 --- a/.gitignore +++ b/.gitignore @@ -9,8 +9,3 @@ lib/Doctrine/DBAL /.settings/ .buildpath .project -/.AppleDouble/ -/bin/.AppleDouble/ -/lib/.AppleDouble/ -/tests/.AppleDouble/ -/tools/.AppleDouble/ \ No newline at end of file diff --git a/lib/vendor/doctrine-common b/lib/vendor/doctrine-common index 4ac23ae87..cc04744bc 160000 --- a/lib/vendor/doctrine-common +++ b/lib/vendor/doctrine-common @@ -1 +1 @@ -Subproject commit 4ac23ae8737fe7b95a7dd0f1346dbd48c7a503b0 +Subproject commit cc04744bcf5a4743c46fae0487ac7a093a722856 From ab9ff813fc20e897348225484fa3b60abf15538a Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Mon, 11 Jun 2012 21:46:04 -0300 Subject: [PATCH 32/37] revert submodule change --- lib/vendor/doctrine-common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vendor/doctrine-common b/lib/vendor/doctrine-common index cc04744bc..4ac23ae87 160000 --- a/lib/vendor/doctrine-common +++ b/lib/vendor/doctrine-common @@ -1 +1 @@ -Subproject commit cc04744bcf5a4743c46fae0487ac7a093a722856 +Subproject commit 4ac23ae8737fe7b95a7dd0f1346dbd48c7a503b0 From 49f9d185deaa084301d6f9c736de363b93254e6a Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Tue, 12 Jun 2012 09:47:40 -0300 Subject: [PATCH 33/37] Fix CS and test configuration --- lib/Doctrine/ORM/Configuration.php | 2 +- .../ORM/Mapping/DefaultQuoteStrategy.php | 8 ++++---- .../Tests/ORM/Mapping/QuoteStrategyTest.php | 19 +++++++++++++++++++ 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/lib/Doctrine/ORM/Configuration.php b/lib/Doctrine/ORM/Configuration.php index afdfd5e17..74367a90a 100644 --- a/lib/Doctrine/ORM/Configuration.php +++ b/lib/Doctrine/ORM/Configuration.php @@ -639,7 +639,7 @@ class Configuration extends \Doctrine\DBAL\Configuration */ public function setQuoteStrategy(QuoteStrategy $quoteStrategy) { - $this->_attributes['quoteStrategy'] = $namingStrategy; + $this->_attributes['quoteStrategy'] = $quoteStrategy; } /** diff --git a/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php b/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php index 1470c0629..6d779f0e5 100644 --- a/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php +++ b/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php @@ -47,8 +47,8 @@ class DefaultQuoteStrategy implements QuoteStrategy public function getTableName(ClassMetadata $class, AbstractPlatform $platform) { return isset($class->table['quoted']) - ? $platform->quoteIdentifier($class->table['name']) - : $class->table['name']; + ? $platform->quoteIdentifier($class->table['name']) + : $class->table['name']; } /** @@ -57,8 +57,8 @@ class DefaultQuoteStrategy implements QuoteStrategy public function getSequenceName(array $definition, ClassMetadata $class, AbstractPlatform $platform) { return isset($definition['quoted']) - ? $platform->quoteIdentifier($definition['sequenceName']) - : $definition['sequenceName']; + ? $platform->quoteIdentifier($definition['sequenceName']) + : $definition['sequenceName']; } /** diff --git a/tests/Doctrine/Tests/ORM/Mapping/QuoteStrategyTest.php b/tests/Doctrine/Tests/ORM/Mapping/QuoteStrategyTest.php index 577c7a26e..23f02b451 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/QuoteStrategyTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/QuoteStrategyTest.php @@ -44,6 +44,20 @@ class QuoteStrategyTest extends \Doctrine\Tests\OrmTestCase return $cm; } + public function testConfiguration() + { + $em = $this->_getTestEntityManager(); + $config = $em->getConfiguration(); + + $this->assertInstanceOf('Doctrine\ORM\Mapping\QuoteStrategy', $config->getQuoteStrategy()); + $this->assertInstanceOf('Doctrine\ORM\Mapping\DefaultQuoteStrategy', $config->getQuoteStrategy()); + + $config->setQuoteStrategy(new MyQuoteStrategy()); + + $this->assertInstanceOf('Doctrine\ORM\Mapping\QuoteStrategy', $config->getQuoteStrategy()); + $this->assertInstanceOf('Doctrine\Tests\ORM\Mapping\MyQuoteStrategy', $config->getQuoteStrategy()); + } + public function testGetColumnName() { $cm = $this->createClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); @@ -175,4 +189,9 @@ class QuoteStrategyTest extends \Doctrine\Tests\OrmTestCase $joinColumn = $cm->associationMappings['article']['joinColumns'][0]; $this->assertEquals('"id"',$this->strategy->getReferencedJoinColumnName($joinColumn, $cm, $this->platform)); } +} + +class MyQuoteStrategy extends \Doctrine\ORM\Mapping\DefaultQuoteStrategy +{ + } \ No newline at end of file From b9d94e7bf0c0d6dd57d1eb04a36f499c2400c8ba Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Tue, 12 Jun 2012 17:47:00 -0300 Subject: [PATCH 34/37] add DefaultQuoteStrategy use statement --- lib/Doctrine/ORM/Configuration.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/ORM/Configuration.php b/lib/Doctrine/ORM/Configuration.php index 74367a90a..ff7ea63da 100644 --- a/lib/Doctrine/ORM/Configuration.php +++ b/lib/Doctrine/ORM/Configuration.php @@ -25,8 +25,9 @@ use Doctrine\Common\Cache\Cache, Doctrine\Common\Annotations\AnnotationReader, Doctrine\ORM\Mapping\Driver\Driver, Doctrine\ORM\Mapping\Driver\AnnotationDriver, - Doctrine\ORM\Mapping\NamingStrategy, Doctrine\ORM\Mapping\QuoteStrategy, + Doctrine\ORM\Mapping\DefaultQuoteStrategy, + Doctrine\ORM\Mapping\NamingStrategy, Doctrine\ORM\Mapping\DefaultNamingStrategy; /** @@ -651,7 +652,7 @@ class Configuration extends \Doctrine\DBAL\Configuration public function getQuoteStrategy() { if ( ! isset($this->_attributes['quoteStrategy'])) { - $this->_attributes['quoteStrategy'] = new \Doctrine\ORM\Mapping\DefaultQuoteStrategy(); + $this->_attributes['quoteStrategy'] = new DefaultQuoteStrategy(); } return $this->_attributes['quoteStrategy']; From 65efda425fc63d9121d2191ba62f5a148fe4e9fc Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Mon, 18 Jun 2012 15:24:52 -0300 Subject: [PATCH 35/37] Fix CS --- .../ORM/Mapping/ClassMetadataFactory.php | 18 +++++-- .../ORM/Mapping/ClassMetadataInfo.php | 48 +++++++++---------- .../ORM/Mapping/DefaultQuoteStrategy.php | 4 +- lib/Doctrine/ORM/Mapping/QuoteStrategy.php | 1 - .../ORM/Persisters/BasicEntityPersister.php | 10 ++-- 5 files changed, 47 insertions(+), 34 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php index 02792b98d..6c68f5b2a 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php @@ -649,37 +649,47 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface //
__seq in PostgreSQL for SERIAL columns. // Not pretty but necessary and the simplest solution that currently works. $sequenceName = null; + if($this->targetPlatform instanceof Platforms\PostgreSQLPlatform) { $fieldName = $class->getSingleIdentifierFieldName(); $columnName = $class->getSingleIdentifierColumnName(); $quoted = isset($class->fieldMappings[$fieldName]['quoted']) || isset($class->table['quoted']); $sequenceName = $class->getTableName() . '_' . $columnName . '_seq'; - $definition = array( + $definition = array( 'sequenceName' => $this->targetPlatform->fixSchemaElementName($sequenceName) ); + if ($quoted) { $definition['quoted'] = true; } + $sequenceName = $this->em->getConfiguration()->getQuoteStrategy()->getSequenceName($definition, $class, $this->targetPlatform); } + $class->setIdGenerator(new \Doctrine\ORM\Id\IdentityGenerator($sequenceName)); break; case ClassMetadata::GENERATOR_TYPE_SEQUENCE: // If there is no sequence definition yet, create a default definition $definition = $class->sequenceGeneratorDefinition; + if ( ! $definition) { $fieldName = $class->getSingleIdentifierFieldName(); $columnName = $class->getSingleIdentifierColumnName(); $quoted = isset($class->fieldMappings[$fieldName]['quoted']) || isset($class->table['quoted']); $sequenceName = $class->getTableName() . '_' . $columnName . '_seq'; - $definition['sequenceName'] = $this->targetPlatform->fixSchemaElementName($sequenceName); - $definition['allocationSize'] = 1; - $definition['initialValue'] = 1; + $definition = array( + 'sequenceName' => $this->targetPlatform->fixSchemaElementName($sequenceName), + 'allocationSize' => 1, + 'initialValue' => 1, + ); + if ($quoted) { $definition['quoted'] = true; } + $class->setSequenceGeneratorDefinition($definition); } + $sequenceGenerator = new \Doctrine\ORM\Id\SequenceGenerator( $this->em->getConfiguration()->getQuoteStrategy()->getSequenceName($definition, $class, $this->targetPlatform), $definition['allocationSize'] diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php index 5e860be10..246a2c9f2 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php @@ -1181,11 +1181,11 @@ class ClassMetadataInfo implements ClassMetadata // Complete fieldName and columnName mapping if ( ! isset($mapping['columnName'])) { $mapping['columnName'] = $this->namingStrategy->propertyToColumnName($mapping['fieldName']); - } else { - if ($mapping['columnName'][0] == '`') { - $mapping['columnName'] = trim($mapping['columnName'], '`'); - $mapping['quoted'] = true; - } + } + + if ($mapping['columnName'][0] === '`') { + $mapping['columnName'] = trim($mapping['columnName'], '`'); + $mapping['quoted'] = true; } $this->columnNames[$mapping['fieldName']] = $mapping['columnName']; @@ -1295,8 +1295,8 @@ class ClassMetadataInfo implements ClassMetadata // Mandatory and optional attributes for either side if ( ! $mapping['mappedBy']) { if (isset($mapping['joinTable']) && $mapping['joinTable']) { - if (isset($mapping['joinTable']['name']) && $mapping['joinTable']['name'][0] == '`') { - $mapping['joinTable']['name'] = trim($mapping['joinTable']['name'], '`'); + if (isset($mapping['joinTable']['name']) && $mapping['joinTable']['name'][0] === '`') { + $mapping['joinTable']['name'] = trim($mapping['joinTable']['name'], '`'); $mapping['joinTable']['quoted'] = true; } } @@ -1382,14 +1382,14 @@ class ClassMetadataInfo implements ClassMetadata $joinColumn['referencedColumnName'] = $this->namingStrategy->referenceColumnName(); } - if ($joinColumn['name'][0] == '`') { + if ($joinColumn['name'][0] === '`') { $joinColumn['name'] = trim($joinColumn['name'], '`'); $joinColumn['quoted'] = true; } - if ($joinColumn['referencedColumnName'][0] == '`') { - $joinColumn['referencedColumnName'] = trim($joinColumn['referencedColumnName'], '`'); - $joinColumn['quoted'] = true; + if ($joinColumn['referencedColumnName'][0] === '`') { + $joinColumn['referencedColumnName'] = trim($joinColumn['referencedColumnName'], '`'); + $joinColumn['quoted'] = true; } $mapping['sourceToTargetKeyColumns'][$joinColumn['name']] = $joinColumn['referencedColumnName']; @@ -1477,14 +1477,14 @@ class ClassMetadataInfo implements ClassMetadata $joinColumn['referencedColumnName'] = $this->namingStrategy->referenceColumnName(); } - if ($joinColumn['name'][0] == '`') { + if ($joinColumn['name'][0] === '`') { $joinColumn['name'] = trim($joinColumn['name'], '`'); $joinColumn['quoted'] = true; } - if ($joinColumn['referencedColumnName'][0] == '`') { - $joinColumn['referencedColumnName'] = trim($joinColumn['referencedColumnName'], '`'); - $joinColumn['quoted'] = true; + if ($joinColumn['referencedColumnName'][0] === '`') { + $joinColumn['referencedColumnName'] = trim($joinColumn['referencedColumnName'], '`'); + $joinColumn['quoted'] = true; } if (isset($joinColumn['onDelete']) && strtolower($joinColumn['onDelete']) == 'cascade') { @@ -1504,14 +1504,14 @@ class ClassMetadataInfo implements ClassMetadata $inverseJoinColumn['referencedColumnName'] = $this->namingStrategy->referenceColumnName(); } - if ($inverseJoinColumn['name'][0] == '`') { + if ($inverseJoinColumn['name'][0] === '`') { $inverseJoinColumn['name'] = trim($inverseJoinColumn['name'], '`'); $inverseJoinColumn['quoted'] = true; } - if ($inverseJoinColumn['referencedColumnName'][0] == '`') { - $inverseJoinColumn['referencedColumnName'] = trim($inverseJoinColumn['referencedColumnName'], '`'); - $inverseJoinColumn['quoted'] = true; + if ($inverseJoinColumn['referencedColumnName'][0] === '`') { + $inverseJoinColumn['referencedColumnName'] = trim($inverseJoinColumn['referencedColumnName'], '`'); + $inverseJoinColumn['quoted'] = true; } if (isset($inverseJoinColumn['onDelete']) && strtolower($inverseJoinColumn['onDelete']) == 'cascade') { @@ -1984,12 +1984,12 @@ class ClassMetadataInfo implements ClassMetadata public function setPrimaryTable(array $table) { if (isset($table['name'])) { - if ($table['name'][0] == '`') { - $this->table['name'] = str_replace("`", "", $table['name']); - $this->table['quoted'] = true; - } else { - $this->table['name'] = $table['name']; + if ($table['name'][0] === '`') { + $table['name'] = trim($table['name'], '`'); + $this->table['quoted'] = true; } + + $this->table['name'] = $table['name']; } if (isset($table['indexes'])) { diff --git a/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php b/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php index 6d779f0e5..b5a6fc4f1 100644 --- a/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php +++ b/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php @@ -30,7 +30,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; */ class DefaultQuoteStrategy implements QuoteStrategy { - /** * {@inheritdoc} */ @@ -108,7 +107,8 @@ class DefaultQuoteStrategy implements QuoteStrategy // Association defined as Id field $joinColumns = $class->associationMappings[$fieldName]['joinColumns']; $assocQuotedColumnNames = array_map( - function ($joinColumn) use ($platform) { + function ($joinColumn) use ($platform) + { return isset($joinColumn['quoted']) ? $platform->quoteIdentifier($joinColumn['name']) : $joinColumn['name']; diff --git a/lib/Doctrine/ORM/Mapping/QuoteStrategy.php b/lib/Doctrine/ORM/Mapping/QuoteStrategy.php index 9e698db22..52e846d99 100644 --- a/lib/Doctrine/ORM/Mapping/QuoteStrategy.php +++ b/lib/Doctrine/ORM/Mapping/QuoteStrategy.php @@ -30,7 +30,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; */ interface QuoteStrategy { - /** * Gets the (possibly quoted) column name for safe use in an SQL statement. * diff --git a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php index 34ed11050..31b761b62 100644 --- a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php @@ -463,6 +463,7 @@ class BasicEntityPersister if ( ! isset($mapping['isOnDeleteCascade'])) { $joinTableName = $this->quoteStrategy->getJoinTableName($mapping, $this->_class, $this->_platform); + $this->_conn->delete($joinTableName, array_combine($keys, $identifier)); if ($selfReferential) { @@ -486,9 +487,11 @@ class BasicEntityPersister public function delete($entity) { $identifier = $this->_em->getUnitOfWork()->getEntityIdentifier($entity); + $this->deleteJoinTableRecords($identifier); $id = array_combine($this->quoteStrategy->getIdentifierColumnNames($this->_class, $this->_platform), $identifier); + $this->_conn->delete($this->quoteStrategy->getTableName($this->_class, $this->_platform), $id); } @@ -558,10 +561,10 @@ class BasicEntityPersister $owningTable = $this->getOwningTable($field); foreach ($assoc['joinColumns'] as $joinColumn) { - $sourceColumn = $joinColumn['name']; - $targetColumn = $joinColumn['referencedColumnName']; - + $sourceColumn = $joinColumn['name']; + $targetColumn = $joinColumn['referencedColumnName']; $quotedColumn = $this->quoteStrategy->getJoinColumnName($joinColumn, $this->_class, $this->_platform); + $this->quotedColumns[$sourceColumn] = $quotedColumn; if ($newVal === null) { @@ -1113,6 +1116,7 @@ class BasicEntityPersister $resultColumnName = $this->getSQLColumnAlias($joinColumn['name']); $columnList .= $this->_getSQLTableAlias($class->name, ($alias == 'r' ? '' : $alias) ) . '.' . $quotedColumn . ' AS ' . $resultColumnName; + $this->_rsm->addMetaResult($alias, $resultColumnName, $quotedColumn, isset($assoc['id']) && $assoc['id'] === true); } } From 7800a7ef3f04091a86189335c399de3ddf2e082b Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Mon, 18 Jun 2012 15:31:20 -0300 Subject: [PATCH 36/37] wrong indentation --- lib/Doctrine/ORM/Query/SqlWalker.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index ffc39ab59..13c2b5df0 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -1021,7 +1021,7 @@ class SqlWalker implements TreeWalker $sql .= ' AND (' . $this->walkConditionalExpression($condExpr) . ')'; } break; - } + } return $sql; } From ca4862aabc1154a66b6938c783aaf0d1d60465df Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Sat, 23 Jun 2012 14:19:47 -0300 Subject: [PATCH 37/37] Fix CS --- .../ORM/Mapping/ClassMetadataFactory.php | 22 ++++++++++++------- .../ORM/Persisters/BasicEntityPersister.php | 15 ++++++------- lib/Doctrine/ORM/Tools/SchemaTool.php | 8 +++---- 3 files changed, 25 insertions(+), 20 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php index 6c68f5b2a..378f1cc98 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php @@ -385,12 +385,12 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface $class->validateLifecycleCallbacks($this->getReflectionService()); // verify inheritance - if (!$class->isMappedSuperclass && !$class->isInheritanceTypeNone()) { - if (!$parent) { + if ( ! $class->isMappedSuperclass && !$class->isInheritanceTypeNone()) { + if ( ! $parent) { if (count($class->discriminatorMap) == 0) { throw MappingException::missingDiscriminatorMap($class->name); } - if (!$class->discriminatorColumn) { + if ( ! $class->discriminatorColumn) { throw MappingException::missingDiscriminatorColumn($class->name); } } else if ($parent && !$class->reflClass->isAbstract() && !in_array($class->name, array_values($class->discriminatorMap))) { @@ -562,7 +562,7 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface private function addInheritedNamedQueries(ClassMetadata $subClass, ClassMetadata $parentClass) { foreach ($parentClass->namedQueries as $name => $query) { - if (!isset ($subClass->namedQueries[$name])) { + if ( ! isset ($subClass->namedQueries[$name])) { $subClass->addNamedQuery(array( 'name' => $query['name'], 'query' => $query['query'] @@ -581,7 +581,7 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface private function addInheritedNamedNativeQueries(ClassMetadata $subClass, ClassMetadata $parentClass) { foreach ($parentClass->namedNativeQueries as $name => $query) { - if (!isset ($subClass->namedNativeQueries[$name])) { + if ( ! isset ($subClass->namedNativeQueries[$name])) { $subClass->addNamedNativeQuery(array( 'name' => $query['name'], 'query' => $query['query'], @@ -603,7 +603,7 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface private function addInheritedSqlResultSetMappings(ClassMetadata $subClass, ClassMetadata $parentClass) { foreach ($parentClass->sqlResultSetMappings as $name => $mapping) { - if (!isset ($subClass->sqlResultSetMappings[$name])) { + if ( ! isset ($subClass->sqlResultSetMappings[$name])) { $entities = array(); foreach ($mapping['entities'] as $entity) { $entities[] = array( @@ -650,7 +650,7 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface // Not pretty but necessary and the simplest solution that currently works. $sequenceName = null; - if($this->targetPlatform instanceof Platforms\PostgreSQLPlatform) { + if ($this->targetPlatform instanceof Platforms\PostgreSQLPlatform) { $fieldName = $class->getSingleIdentifierFieldName(); $columnName = $class->getSingleIdentifierColumnName(); $quoted = isset($class->fieldMappings[$fieldName]['quoted']) || isset($class->table['quoted']); @@ -668,6 +668,7 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface $class->setIdGenerator(new \Doctrine\ORM\Id\IdentityGenerator($sequenceName)); break; + case ClassMetadata::GENERATOR_TYPE_SEQUENCE: // If there is no sequence definition yet, create a default definition $definition = $class->sequenceGeneratorDefinition; @@ -696,23 +697,28 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface ); $class->setIdGenerator($sequenceGenerator); break; + case ClassMetadata::GENERATOR_TYPE_NONE: $class->setIdGenerator(new \Doctrine\ORM\Id\AssignedGenerator()); break; + case ClassMetadata::GENERATOR_TYPE_UUID: $class->setIdGenerator(new \Doctrine\ORM\Id\UuidGenerator()); break; + case ClassMetadata::GENERATOR_TYPE_TABLE: throw new ORMException("TableGenerator not yet implemented."); break; + case ClassMetadata::GENERATOR_TYPE_CUSTOM: $definition = $class->customGeneratorDefinition; - if (!class_exists($definition['class'])) { + if ( ! class_exists($definition['class'])) { throw new ORMException("Can't instantiate custom generator : " . $definition['class']); } $class->setIdGenerator(new $definition['class']); break; + default: throw new ORMException("Unknown generator type: " . $class->generatorType); } diff --git a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php index 31b761b62..7ccc7e663 100644 --- a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php @@ -367,7 +367,7 @@ class BasicEntityPersister $type = Type::getType($this->_columnTypes[$columnName]); $placeholder = $type->convertToDatabaseValueSQL('?', $this->_platform); } - } else if(isset($this->quotedColumns[$columnName])) { + } else if (isset($this->quotedColumns[$columnName])) { $column = $this->quotedColumns[$columnName]; } @@ -467,7 +467,7 @@ class BasicEntityPersister $this->_conn->delete($joinTableName, array_combine($keys, $identifier)); if ($selfReferential) { - $this->_conn->delete($joinTableName,array_combine($otherKeys, $identifier)); + $this->_conn->delete($joinTableName, array_combine($otherKeys, $identifier)); } } } @@ -1105,23 +1105,22 @@ class BasicEntityPersister */ protected function _getSelectColumnAssociationSQL($field, $assoc, ClassMetadata $class, $alias = 'r') { - $columnList = ''; + $columnList = array(); if ($assoc['isOwningSide'] && $assoc['type'] & ClassMetadata::TO_ONE) { - foreach ($assoc['joinColumns'] as $joinColumn) { - if ($columnList) $columnList .= ', '; + foreach ($assoc['joinColumns'] as $joinColumn) { $quotedColumn = $this->quoteStrategy->getJoinColumnName($joinColumn, $this->_class, $this->_platform); $resultColumnName = $this->getSQLColumnAlias($joinColumn['name']); - $columnList .= $this->_getSQLTableAlias($class->name, ($alias == 'r' ? '' : $alias) ) + $columnList[] = $this->_getSQLTableAlias($class->name, ($alias == 'r' ? '' : $alias) ) . '.' . $quotedColumn . ' AS ' . $resultColumnName; $this->_rsm->addMetaResult($alias, $resultColumnName, $quotedColumn, isset($assoc['id']) && $assoc['id'] === true); } } - return $columnList; + return implode(', ', $columnList); } /** @@ -1598,7 +1597,7 @@ class BasicEntityPersister { // if one of the join columns is nullable, return left join foreach ($joinColumns as $joinColumn) { - if (!isset($joinColumn['nullable']) || $joinColumn['nullable']) { + if ( ! isset($joinColumn['nullable']) || $joinColumn['nullable']) { return 'LEFT JOIN'; } } diff --git a/lib/Doctrine/ORM/Tools/SchemaTool.php b/lib/Doctrine/ORM/Tools/SchemaTool.php index f92825ce4..23a361e97 100644 --- a/lib/Doctrine/ORM/Tools/SchemaTool.php +++ b/lib/Doctrine/ORM/Tools/SchemaTool.php @@ -226,7 +226,7 @@ class SchemaTool } } - if (!$table->hasIndex('primary')) { + if ( ! $table->hasIndex('primary')) { $table->setPrimaryKey($pkColumns); } @@ -290,7 +290,7 @@ class SchemaTool { $discrColumn = $class->discriminatorColumn; - if (!isset($discrColumn['type']) || (strtolower($discrColumn['type']) == 'string' && $discrColumn['length'] === null)) { + if ( ! isset($discrColumn['type']) || (strtolower($discrColumn['type']) == 'string' && $discrColumn['length'] === null)) { $discrColumn['type'] = 'string'; $discrColumn['length'] = 255; } @@ -515,7 +515,7 @@ class SchemaTool list($definingClass, $referencedFieldName) = $this->getDefiningClass($class, $joinColumn['referencedColumnName']); - if (!$definingClass) { + if ( ! $definingClass) { throw new \Doctrine\ORM\ORMException( "Column name `".$joinColumn['referencedColumnName']."` referenced for relation from ". $mapping['sourceEntity'] . " towards ". $mapping['targetEntity'] . " does not exist." @@ -638,7 +638,7 @@ class SchemaTool $sm = $this->em->getConnection()->getSchemaManager(); $fullSchema = $sm->createSchema(); foreach ($fullSchema->getTables() as $table) { - if (!$schema->hasTable($table->getName())) { + if ( ! $schema->hasTable($table->getName())) { foreach ($table->getForeignKeys() as $foreignKey) { /* @var $foreignKey \Doctrine\DBAL\Schema\ForeignKeyConstraint */ if ($schema->hasTable($foreignKey->getForeignTableName())) {