Browse files

Merge pull request #372 from FabioBatSilva/DDC-1845

[DDC-1845] QuoteStrategy
  • Loading branch information...
2 parents 3dd3eca + ca4862a commit cb72219b118c158c9b5344c4b81ff2b1a9149ab0 @guilhermeblanco guilhermeblanco committed Jun 25, 2012
Showing with 1,817 additions and 465 deletions.
  1. +28 −0 lib/Doctrine/ORM/Configuration.php
  2. +49 −16 lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php
  3. +69 −18 lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php
  4. +140 −0 lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php
  5. +112 −0 lib/Doctrine/ORM/Mapping/QuoteStrategy.php
  6. +19 −3 lib/Doctrine/ORM/Persisters/AbstractCollectionPersister.php
  7. +1 −1 lib/Doctrine/ORM/Persisters/AbstractEntityInheritancePersister.php
  8. +97 −61 lib/Doctrine/ORM/Persisters/BasicEntityPersister.php
  9. +11 −11 lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php
  10. +12 −12 lib/Doctrine/ORM/Persisters/ManyToManyPersister.php
  11. +3 −3 lib/Doctrine/ORM/Persisters/OneToManyPersister.php
  12. +16 −15 lib/Doctrine/ORM/Query/AST/Functions/SizeFunction.php
  13. +11 −10 lib/Doctrine/ORM/Query/Exec/MultiTableDeleteExecutor.php
  14. +12 −12 lib/Doctrine/ORM/Query/Exec/MultiTableUpdateExecutor.php
  15. +270 −238 lib/Doctrine/ORM/Query/SqlWalker.php
  16. +71 −61 lib/Doctrine/ORM/Tools/SchemaTool.php
  17. +54 −0 tests/Doctrine/Tests/Models/Quote/Address.php
  18. +42 −0 tests/Doctrine/Tests/Models/Quote/Group.php
  19. +24 −0 tests/Doctrine/Tests/Models/Quote/Phone.php
  20. +32 −0 tests/Doctrine/Tests/Models/Quote/SimpleEntity.php
  21. +83 −0 tests/Doctrine/Tests/Models/Quote/User.php
  22. +2 −2 tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1151Test.php
  23. +1 −1 tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1360Test.php
  24. +89 −0 tests/Doctrine/Tests/ORM/Functional/Ticket/DDC142Test.php
  25. +88 −0 tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1719Test.php
  26. +136 −0 tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1843Test.php
  27. +80 −0 tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php
  28. +197 −0 tests/Doctrine/Tests/ORM/Mapping/QuoteStrategyTest.php
  29. +12 −0 tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterTypeValueSqlTest.php
  30. +56 −1 tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php
View
28 lib/Doctrine/ORM/Configuration.php
@@ -25,6 +25,8 @@
Doctrine\Common\Annotations\AnnotationReader,
Doctrine\ORM\Mapping\Driver\Driver,
Doctrine\ORM\Mapping\Driver\AnnotationDriver,
+ Doctrine\ORM\Mapping\QuoteStrategy,
+ Doctrine\ORM\Mapping\DefaultQuoteStrategy,
Doctrine\ORM\Mapping\NamingStrategy,
Doctrine\ORM\Mapping\DefaultNamingStrategy;
@@ -629,4 +631,30 @@ public function getNamingStrategy()
return $this->_attributes['namingStrategy'];
}
+
+ /**
+ * Set quote strategy.
+ *
+ * @since 2.3
+ * @param Doctrine\ORM\Mapping\QuoteStrategy $quoteStrategy
+ */
+ public function setQuoteStrategy(QuoteStrategy $quoteStrategy)
+ {
+ $this->_attributes['quoteStrategy'] = $quoteStrategy;
+ }
+
+ /**
+ * Get quote strategy.
+ *
+ * @since 2.3
+ * @return Doctrine\ORM\Mapping\QuoteStrategy
+ */
+ public function getQuoteStrategy()
+ {
+ if ( ! isset($this->_attributes['quoteStrategy'])) {
+ $this->_attributes['quoteStrategy'] = new DefaultQuoteStrategy();
+ }
+
+ return $this->_attributes['quoteStrategy'];
+ }
}
View
65 lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php
@@ -385,12 +385,12 @@ protected function validateRuntimeMetadata($class, $parent)
$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 @@ private function addInheritedRelations(ClassMetadata $subClass, ClassMetadata $p
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 @@ private function addInheritedNamedQueries(ClassMetadata $subClass, ClassMetadata
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 @@ private function addInheritedNamedNativeQueries(ClassMetadata $subClass, ClassMe
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(
@@ -648,44 +648,77 @@ private function completeIdGeneratorMapping(ClassMetadataInfo $class)
// For PostgreSQL IDENTITY (SERIAL) we need a sequence name. It defaults to
// <table>_<column>_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->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) {
- $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 = array(
+ 'sequenceName' => $this->targetPlatform->fixSchemaElementName($sequenceName),
+ 'allocationSize' => 1,
+ 'initialValue' => 1,
+ );
+
+ if ($quoted) {
+ $definition['quoted'] = true;
+ }
+
$class->setSequenceGeneratorDefinition($definition);
}
+
$sequenceGenerator = new \Doctrine\ORM\Id\SequenceGenerator(
- $definition['sequenceName'],
+ $this->em->getConfiguration()->getQuoteStrategy()->getSequenceName($definition, $class, $this->targetPlatform),
$definition['allocationSize']
);
$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);
}
View
87 lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php
@@ -1181,11 +1181,11 @@ protected function _validateAndCompleteFieldMapping(array &$mapping)
// 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 @@ protected function _validateAndCompleteAssociationMapping(array $mapping)
// 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;
}
}
@@ -1373,12 +1373,25 @@ protected function _validateAndCompleteOneToOneMapping(array $mapping)
$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'];
@@ -1459,12 +1472,25 @@ protected function _validateAndCompleteManyToManyMapping(array $mapping)
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'];
}
@@ -1473,12 +1499,25 @@ protected function _validateAndCompleteManyToManyMapping(array $mapping)
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'];
}
@@ -1945,12 +1984,12 @@ public function setTableName($tableName)
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'])) {
@@ -2528,16 +2567,22 @@ public function setCustomGeneratorDefinition(array $definition)
* The definition must have the following structure:
* <code>
* array(
- * 'sequenceName' => 'name',
+ * 'sequenceName' => 'name',
* 'allocationSize' => 20,
- * 'initialValue' => 1
+ * 'initialValue' => 1
+ * 'quoted' => 1
* )
* </code>
*
* @param array $definition
*/
public function setSequenceGeneratorDefinition(array $definition)
{
+ if (isset($definition['name']) && $definition['name'] == '`') {
+ $definition['name'] = trim($definition['name'], '`');
+ $definition['quoted'] = true;
+ }
+
$this->sequenceGeneratorDefinition = $definition;
}
@@ -2646,6 +2691,8 @@ public function getName()
/**
* 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 +2727,9 @@ function ($joinColumn) {
}
/**
- * 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 +2743,9 @@ public function getQuotedColumnName($field, $platform)
}
/**
- * 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 +2758,8 @@ public function getQuotedTableName($platform)
/**
* 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
*/
View
140 lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php
@@ -0,0 +1,140 @@
+<?php
+/*
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * and is licensed under the MIT license. For more information, see
+ * <http://www.doctrine-project.org>.
+ */
+
+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
+ *
+ * @since 2.3
+ * @author Fabio B. Silva <fabio.bat.silva@gmail.com>
+ */
+class DefaultQuoteStrategy implements QuoteStrategy
+{
+ /**
+ * {@inheritdoc}
+ */
+ public function getColumnName($fieldName, ClassMetadata $class, AbstractPlatform $platform)
+ {
+ return isset($class->fieldMappings[$fieldName]['quoted'])
+ ? $platform->quoteIdentifier($class->fieldMappings[$fieldName]['columnName'])
+ : $class->fieldMappings[$fieldName]['columnName'];
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getTableName(ClassMetadata $class, AbstractPlatform $platform)
+ {
+ return isset($class->table['quoted'])
+ ? $platform->quoteIdentifier($class->table['name'])
+ : $class->table['name'];
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getSequenceName(array $definition, ClassMetadata $class, AbstractPlatform $platform)
+ {
+ return isset($definition['quoted'])
+ ? $platform->quoteIdentifier($definition['sequenceName'])
+ : $definition['sequenceName'];
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getJoinColumnName(array $joinColumn, ClassMetadata $class, AbstractPlatform $platform)
+ {
+ return isset($joinColumn['quoted'])
+ ? $platform->quoteIdentifier($joinColumn['name'])
+ : $joinColumn['name'];
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getReferencedJoinColumnName(array $joinColumn, ClassMetadata $class, AbstractPlatform $platform)
+ {
+ return isset($joinColumn['quoted'])
+ ? $platform->quoteIdentifier($joinColumn['referencedColumnName'])
+ : $joinColumn['referencedColumnName'];
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getJoinTableName(array $association, ClassMetadata $class, AbstractPlatform $platform)
+ {
+ return isset($association['joinTable']['quoted'])
+ ? $platform->quoteIdentifier($association['joinTable']['name'])
+ : $association['joinTable']['name'];
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getIdentifierColumnNames(ClassMetadata $class, AbstractPlatform $platform)
+ {
+ $quotedColumnNames = array();
+
+ foreach ($class->identifier as $fieldName) {
+ if (isset($class->fieldMappings[$fieldName])) {
+ $quotedColumnNames[] = $this->getColumnName($fieldName, $class, $platform);
+
+ continue;
+ }
+
+ // Association defined as Id field
+ $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;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ 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, -$platform->getMaxIdentifierLength());
+ $columnName = preg_replace('/[^A-Za-z0-9_]/', '', $columnName);
+
+ return $platform->getSQLResultCasing($columnName);
+ }
+
+}
View
112 lib/Doctrine/ORM/Mapping/QuoteStrategy.php
@@ -0,0 +1,112 @@
+<?php
+/*
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * and is licensed under the MIT license. For more information, see
+ * <http://www.doctrine-project.org>.
+ */
+
+namespace Doctrine\ORM\Mapping;
+
+use Doctrine\ORM\Mapping\ClassMetadata;
+use Doctrine\DBAL\Platforms\AbstractPlatform;
+
+/**
+ * A set of rules for determining the column, alias and table quotes
+ *
+ * @since 2.3
+ * @author Fabio B. Silva <fabio.bat.silva@gmail.com>
+ */
+interface QuoteStrategy
+{
+ /**
+ * Gets the (possibly quoted) column name for safe use in an SQL statement.
+ *
+ * @param string $fieldName
+ * @param ClassMetadata $class
+ * @param AbstractPlatform $platform
+ * @return string
+ */
+ 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
+ */
+ 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
+ */
+ 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
+ */
+ 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
+ */
+ 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
+ */
+ 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
+ */
+ function getIdentifierColumnNames(ClassMetadata $class, AbstractPlatform $platform);
+
+ /**
+ * Gets the column alias.
+ *
+ * @param string $columnName
+ * @param integer $counter
+ * @param AbstractPlatform $platform
+ * @param ClassMetadata $class
+ * @return string
+ */
+ function getColumnAlias($columnName, $counter, AbstractPlatform $platform, ClassMetadata $class = null);
+
+}
View
22 lib/Doctrine/ORM/Persisters/AbstractCollectionPersister.php
@@ -46,15 +46,31 @@
protected $_uow;
/**
+ * The database platform.
+ *
+ * @var \Doctrine\DBAL\Platforms\AbstractPlatform
+ */
+ protected $platform;
+
+ /**
+ * The quote strategy.
+ *
+ * @var \Doctrine\ORM\Mapping\QuoteStrategy
+ */
+ protected $quoteStrategy;
+
+ /**
* Initializes a new instance of a class derived from AbstractCollectionPersister.
*
* @param \Doctrine\ORM\EntityManager $em
*/
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->platform = $this->_conn->getDatabasePlatform();
+ $this->quoteStrategy = $em->getConfiguration()->getQuoteStrategy();
}
/**
View
2 lib/Doctrine/ORM/Persisters/AbstractEntityInheritancePersister.php
@@ -61,7 +61,7 @@ protected function _prepareInsertData($entity)
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, $this->_platform);
$columnAlias = $this->getSQLColumnAlias($columnName);
$this->_rsm->addFieldResult($alias, $columnAlias, $field, $class->name);
View
158 lib/Doctrine/ORM/Persisters/BasicEntityPersister.php
@@ -133,6 +133,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.
*
@@ -171,6 +180,13 @@ class BasicEntityPersister
protected $_sqlTableAliases = array();
/**
+ * The quote strategy.
+ *
+ * @var \Doctrine\ORM\Mapping\QuoteStrategy
+ */
+ protected $quoteStrategy;
+
+ /**
* Initializes a new <tt>BasicEntityPersister</tt> that uses the given EntityManager
* and persists instances of the class described by the given ClassMetadata descriptor.
*
@@ -179,10 +195,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->_platform = $this->_conn->getDatabasePlatform();
+ $this->quoteStrategy = $em->getConfiguration()->getQuoteStrategy();
}
/**
@@ -281,13 +298,13 @@ protected function assignDefaultVersionValue($entity, $id)
protected function fetchVersionValue($versionedClass, $id)
{
$versionField = $versionedClass->versionField;
- $identifier = $versionedClass->getIdentifierColumnNames();
+ $identifier = $this->quoteStrategy->getIdentifierColumnNames($versionedClass, $this->_platform);
- $versionFieldColumnName = $versionedClass->getQuotedColumnName($versionField, $this->_platform);
+ $versionFieldColumnName = $this->quoteStrategy->getColumnName($versionField, $versionedClass, $this->_platform);
//FIXME: Order with composite keys might not be correct
$sql = 'SELECT ' . $versionFieldColumnName
- . ' FROM ' . $versionedClass->getQuotedTableName($this->_platform)
+ . ' FROM ' . $this->quoteStrategy->getTableName($versionedClass, $this->_platform)
. ' WHERE ' . implode(' = ? AND ', $identifier) . ' = ?';
$value = $this->_conn->fetchColumn($sql, array_values((array)$id));
@@ -315,7 +332,7 @@ public function update($entity)
if (isset($updateData[$tableName]) && $updateData[$tableName]) {
$this->_updateTable(
- $entity, $this->_class->getQuotedTableName($this->_platform),
+ $entity, $this->quoteStrategy->getTableName($this->_class, $this->_platform),
$updateData[$tableName], $this->_class->isVersioned
);
@@ -344,12 +361,14 @@ public function update($entity)
$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, $this->_platform);
if (isset($this->_class->fieldMappings[$this->_class->fieldNames[$columnName]]['requireSQLConversion'])) {
$type = Type::getType($this->_columnTypes[$columnName]);
$placeholder = $type->convertToDatabaseValueSQL('?', $this->_platform);
}
+ } else if (isset($this->quotedColumns[$columnName])) {
+ $column = $this->quotedColumns[$columnName];
}
$set[] = $column . ' = ' . $placeholder;
@@ -367,7 +386,7 @@ public function update($entity)
$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, $this->_platform);
$params[] = $id[$idField];
$types[] = $this->_class->fieldMappings[$idField]['type'];
}
@@ -376,7 +395,7 @@ public function update($entity)
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, $this->_platform);
if ($versionFieldType == Type::INTEGER) {
$set[] = $versionColumn . ' = ' . $versionColumn . ' + 1';
@@ -412,34 +431,43 @@ protected function deleteJoinTableRecords($identifier)
// @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, $this->_platform);
+ }
if ($selfReferential) {
- $otherKeys = array_keys($mapping['relationToSourceKeyColumns']);
+ foreach ($mapping['joinTable']['joinColumns'] as $joinColumn) {
+ $otherKeys[] = $this->quoteStrategy->getJoinColumnName($joinColumn, $relatedClass, $this->_platform);
+ }
}
} else {
- $keys = array_keys($mapping['relationToSourceKeyColumns']);
+
+ foreach ($mapping['joinTable']['joinColumns'] as $joinColumn) {
+ $keys[] = $this->quoteStrategy->getJoinColumnName($joinColumn, $this->_class, $this->_platform);
+ }
if ($selfReferential) {
- $otherKeys = array_keys($mapping['relationToTargetKeyColumns']);
+ foreach ($mapping['joinTable']['inverseJoinColumns'] as $joinColumn) {
+ $otherKeys[] = $this->quoteStrategy->getJoinColumnName($joinColumn, $this->_class, $this->_platform);
+ }
}
}
if ( ! isset($mapping['isOnDeleteCascade'])) {
- $this->_conn->delete(
- $this->_class->getQuotedJoinTableName($mapping, $this->_platform),
- array_combine($keys, $identifier)
- );
+
+ $joinTableName = $this->quoteStrategy->getJoinTableName($mapping, $this->_class, $this->_platform);
+
+ $this->_conn->delete($joinTableName, array_combine($keys, $identifier));
if ($selfReferential) {
- $this->_conn->delete(
- $this->_class->getQuotedJoinTableName($mapping, $this->_platform),
- array_combine($otherKeys, $identifier)
- );
+ $this->_conn->delete($joinTableName, array_combine($otherKeys, $identifier));
}
}
}
@@ -459,10 +487,12 @@ protected function deleteJoinTableRecords($identifier)
public function delete($entity)
{
$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, $this->_platform), $identifier);
+
+ $this->_conn->delete($this->quoteStrategy->getTableName($this->_class, $this->_platform), $id);
}
/**
@@ -530,7 +560,13 @@ protected function _prepareUpdateData($entity)
$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->_platform);
+
+ $this->quotedColumns[$sourceColumn] = $quotedColumn;
+
if ($newVal === null) {
$result[$owningTable][$sourceColumn] = null;
} else if ($targetClass->containsForeignIdentifier) {
@@ -808,7 +844,7 @@ private function getManyToManyStatement(array $assoc, $sourceEntity, $offset = n
$sourceClass = $this->_em->getClassMetadata($assoc['sourceEntity']);
if ($assoc['isOwningSide']) {
- $quotedJoinTable = $sourceClass->getQuotedJoinTableName($assoc, $this->_platform);
+ $quotedJoinTable = $this->quoteStrategy->getJoinTableName($assoc, $sourceClass, $this->_platform);
foreach ($assoc['relationToSourceKeyColumns'] as $relationKeyColumn => $sourceKeyColumn) {
if ($sourceClass->containsForeignIdentifier) {
@@ -831,7 +867,7 @@ private function getManyToManyStatement(array $assoc, $sourceEntity, $offset = n
}
} else {
$owningAssoc = $this->_em->getClassMetadata($assoc['targetEntity'])->associationMappings[$assoc['mappedBy']];
- $quotedJoinTable = $sourceClass->getQuotedJoinTableName($owningAssoc, $this->_platform);
+ $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) {
@@ -901,7 +937,7 @@ protected function _getSelectEntitiesSQL(array $criteria, $assoc = null, $lockMo
}
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, $this->_platform) . ' '
. $alias, $lockMode)
. $this->_selectJoinSql . $joinSql
. ($conditionSql ? ' WHERE ' . $conditionSql : '')
@@ -934,7 +970,7 @@ protected function _getSelectEntitiesSQL(array $criteria, $assoc = null, $lockMo
$this->_getSQLTableAlias($this->_class->fieldMappings[$fieldName]['inherited'])
: $baseTableAlias;
- $columnName = $this->_class->getQuotedColumnName($fieldName, $this->_platform);
+ $columnName = $this->quoteStrategy->getColumnName($fieldName, $this->_class, $this->_platform);
$orderBySql .= $orderBySql ? ', ' : ' ORDER BY ';
$orderBySql .= $tableAlias . '.' . $columnName . ' ' . $orientation;
@@ -1012,10 +1048,13 @@ protected function _getSelectColumnListSQL()
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->_platform) . ' ' . $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, $this->_platform);
+ $targetCol = $this->quoteStrategy->getReferencedJoinColumnName($joinColumn, $this->_class, $this->_platform);
+
if ( ! $first) {
$this->_selectJoinSql .= ' AND ';
}
@@ -1033,7 +1072,7 @@ protected function _getSelectColumnListSQL()
$owningAssoc = $eagerEntity->getAssociationMapping($assoc['mappedBy']);
$this->_selectJoinSql .= ' LEFT JOIN';
- $this->_selectJoinSql .= ' ' . $eagerEntity->getQuotedTableName($this->_platform) . ' '
+ $this->_selectJoinSql .= ' ' . $this->quoteStrategy->getTableName($eagerEntity, $this->_platform) . ' '
. $this->_getSQLTableAlias($eagerEntity->name, $assocAlias) . ' ON ';
foreach ($owningAssoc['sourceToTargetKeyColumns'] as $sourceCol => $targetCol) {
@@ -1066,20 +1105,22 @@ protected function _getSelectColumnListSQL()
*/
protected function _getSelectColumnAssociationSQL($field, $assoc, ClassMetadata $class, $alias = 'r')
{
- $columnList = '';
+ $columnList = array();
if ($assoc['isOwningSide'] && $assoc['type'] & ClassMetadata::TO_ONE) {
- foreach ($assoc['targetToSourceKeyColumns'] as $srcColumn) {
- if ($columnList) $columnList .= ', ';
- $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);
+ 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) )
+ . '.' . $quotedColumn . ' AS ' . $resultColumnName;
+
+ $this->_rsm->addMetaResult($alias, $resultColumnName, $quotedColumn, isset($assoc['id']) && $assoc['id'] === true);
}
}
- return $columnList;
+ return implode(', ', $columnList);
}
/**
@@ -1099,7 +1140,7 @@ protected function _getSelectManyToManyJoinSQL(array $manyToMany)
$joinClauses = $owningAssoc['relationToSourceKeyColumns'];
}
- $joinTableName = $this->_class->getQuotedJoinTableName($owningAssoc, $this->_platform);
+ $joinTableName = $this->quoteStrategy->getJoinTableName($owningAssoc, $this->_class, $this->_platform);
$joinSql = '';
foreach ($joinClauses as $joinTableColumn => $sourceColumn) {
@@ -1108,7 +1149,7 @@ protected function _getSelectManyToManyJoinSQL(array $manyToMany)
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, $this->_platform);
}
$joinSql .= $this->_getSQLTableAlias($this->_class->name) . '.' . $quotedColumn . ' = '
@@ -1131,8 +1172,8 @@ protected function _getInsertSQL()
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->_platform),
+ $this->quoteStrategy->getColumnName($this->_class->identifier[0], $this->_class, $this->_platform)
);
} else {
$columns = array_unique($columns);
@@ -1151,7 +1192,7 @@ protected function _getInsertSQL()
$values[] = $placeholder;
}
- $insertSql = 'INSERT INTO ' . $this->_class->getQuotedTableName($this->_platform)
+ $insertSql = 'INSERT INTO ' . $this->quoteStrategy->getTableName($this->_class, $this->_platform)
. ' (' . implode(', ', $columns) . ') VALUES (' . implode(', ', $values) . ')';
}
@@ -1180,14 +1221,13 @@ protected function _getInsertColumnList()
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[] = $sourceCol;
+ foreach ($assoc['joinColumns'] as $joinColumn) {
+ $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->_class->getQuotedColumnName($name, $this->_platform);
+ $columns[] = $this->quoteStrategy->getColumnName($name, $this->_class, $this->_platform);
$this->_columnTypes[$name] = $this->_class->fieldMappings[$name]['type'];
}
}
@@ -1206,7 +1246,7 @@ protected function _getInsertColumnList()
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, $this->_platform);
$columnAlias = $this->getSQLColumnAlias($class->columnNames[$field]);
$this->_rsm->addFieldResult($alias, $columnAlias, $field);
@@ -1276,7 +1316,7 @@ public function lock(array $criteria, $lockMode)
*/
protected function getLockTablesSql()
{
- return 'FROM ' . $this->_class->getQuotedTableName($this->_platform) . ' '
+ return 'FROM ' . $this->quoteStrategy->getTableName($this->_class, $this->_platform) . ' '
. $this->_getSQLTableAlias($this->_class->name);
}
@@ -1305,7 +1345,7 @@ protected function _getSelectConditionSQL(array $criteria, $assoc = null)
? $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, $this->_platform);
if (isset($this->_class->fieldMappings[$field]['requireSQLConversion'])) {
$type = Type::getType($this->_class->getTypeOfField($field));
@@ -1557,7 +1597,7 @@ protected function getJoinSQLForJoinColumns($joinColumns)
{
// 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';
}
}
@@ -1573,11 +1613,7 @@ protected function getJoinSQLForJoinColumns($joinColumns)
*/
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++, $this->_platform);
}
/**
View
22 lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php
@@ -105,7 +105,7 @@ public function getOwningTable($fieldName)
$tableName = $cm->getTableName();
$this->_owningTableMap[$fieldName] = $tableName;
- $this->_quotedTableMap[$tableName] = $cm->getQuotedTableName($this->_platform);
+ $this->_quotedTableMap[$tableName] = $this->quoteStrategy->getTableName($cm, $this->_platform);
return $tableName;
}
@@ -225,7 +225,7 @@ public function update($entity)
// 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, $this->_platform), array(), true);
$id = $this->_em->getUnitOfWork()->getEntityIdentifier($entity);
$this->assignDefaultVersionValue($entity, $id);
@@ -247,15 +247,15 @@ public function delete($entity)
// 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), $this->_platform), $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, $this->_platform), $id);
foreach ($this->_class->parentClasses as $parentClass) {
$this->_conn->delete(
- $this->_em->getClassMetadata($parentClass)->getQuotedTableName($this->_platform), $id
+ $this->quoteStrategy->getTableName($this->_em->getClassMetadata($parentClass), $this->_platform), $id
);
}
}
@@ -321,7 +321,7 @@ protected function _getSelectEntitiesSQL(array $criteria, $assoc = null, $lockMo
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, $this->_platform) . ' ' . $tableAlias . ' ON ';
$first = true;
foreach ($idColumns as $idColumn) {
@@ -361,7 +361,7 @@ protected function _getSelectEntitiesSQL(array $criteria, $assoc = null, $lockMo
}
// Add LEFT JOIN
- $joinSql .= ' LEFT JOIN ' . $subClass->getQuotedTableName($this->_platform) . ' ' . $tableAlias . ' ON ';
+ $joinSql .= ' LEFT JOIN ' . $this->quoteStrategy->getTableName($subClass, $this->_platform) . ' ' . $tableAlias . ' ON ';
$first = true;
foreach ($idColumns as $idColumn) {
@@ -400,7 +400,7 @@ protected function _getSelectEntitiesSQL(array $criteria, $assoc = null, $lockMo
}
return $this->_platform->modifyLimitQuery('SELECT ' . $this->_selectColumnListSql
- . ' FROM ' . $this->_class->getQuotedTableName($this->_platform) . ' ' . $baseTableAlias
+ . ' FROM ' . $this->quoteStrategy->getTableName($this->_class, $this->_platform) . ' ' . $baseTableAlias
. $joinSql
. ($conditionSql != '' ? ' WHERE ' . $conditionSql : '') . $orderBySql, $limit, $offset)
. $lockSql;
@@ -422,7 +422,7 @@ public function getLockTablesSql()
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, $this->_platform) . ' ' . $tableAlias . ' ON ';
$first = true;
foreach ($idColumns as $idColumn) {
@@ -432,7 +432,7 @@ public function getLockTablesSql()
}
}
- return 'FROM ' . $this->_class->getQuotedTableName($this->_platform) . ' ' . $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 @@ protected function _getInsertColumnList()
}
} 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, $this->_platform);
}
}
View
24 lib/Doctrine/ORM/Persisters/ManyToManyPersister.php
@@ -43,7 +43,7 @@ protected function _getDeleteRowSQL(PersistentCollection $coll)
$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, $this->platform)
. ' WHERE ' . implode(' = ? AND ', $mapping['joinTableColumns']) . ' = ?';
}
@@ -76,11 +76,10 @@ protected function _getUpdateRowSQL(PersistentCollection $coll)
*/
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, $this->platform);
return 'INSERT INTO ' . $joinTable . ' (' . implode(', ', $columns) . ')'
. ' VALUES (' . implode(', ', array_fill(0, count($columns), '?')) . ')';
@@ -148,10 +147,11 @@ private function _collectJoinTableColumnParameters(PersistentCollection $coll, $
*/
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, $this->platform);
- return 'DELETE FROM ' . $class->getQuotedJoinTableName($mapping, $this->_conn->getDatabasePlatform())
+ return 'DELETE FROM ' . $joinTable
. ' WHERE ' . implode(' = ? AND ', array_keys($mapping['relationToSourceKeyColumns'])) . ' = ?';
}
@@ -222,7 +222,7 @@ public function count(PersistentCollection $coll)
}
$sql = 'SELECT COUNT(*)'
- . ' FROM ' . $class->getQuotedJoinTableName($mapping, $this->_conn->getDatabasePlatform()) . ' t'
+ . ' FROM ' . $this->quoteStrategy->getJoinTableName($mapping, $class, $this->platform) . ' t'
. $joinTargetEntitySQL
. ' WHERE ' . implode(' AND ', $whereClauses);
@@ -324,7 +324,7 @@ private function getJoinTableRestrictions(PersistentCollection $coll, $element,
$targetId = $uow->getEntityIdentifier($element);
}
- $quotedJoinTable = $sourceClass->getQuotedJoinTableName($mapping, $this->_conn->getDatabasePlatform());
+ $quotedJoinTable = $this->quoteStrategy->getJoinTableName($mapping, $sourceClass, $this->platform);
$whereClauses = array();
$params = array();
@@ -385,7 +385,7 @@ public function getFilterSql($mapping)
$joinTargetEntitySQL = '';
if ($filterSql = $this->generateFilterConditionSQL($targetClass, 'te')) {
$joinTargetEntitySQL = ' JOIN '
- . $targetClass->getQuotedTableName($this->_conn->getDatabasePlatform()) . ' te'
+ . $this->quoteStrategy->getTableName($targetClass, $this->platform) . ' te'
. ' ON';
$joinTargetEntitySQLClauses = array();
View
6 lib/Doctrine/ORM/Persisters/OneToManyPersister.php
@@ -45,7 +45,7 @@ protected function _getDeleteRowSQL(PersistentCollection $coll)
$mapping = $coll->getMapping();
$class = $this->_em->getClassMetadata($mapping['targetEntity']);
- return 'DELETE FROM ' . $class->getQuotedTableName($this->_conn->getDatabasePlatform())
+ return 'DELETE FROM ' . $this->quoteStrategy->getTableName($class, $this->platform)
. ' WHERE ' . implode('= ? AND ', $class->getIdentifierColumnNames()) . ' = ?';
}
@@ -127,7 +127,7 @@ public function count(PersistentCollection $coll)
}
$sql = 'SELECT count(*)'
- . ' FROM ' . $targetClass->getQuotedTableName($this->_conn->getDatabasePlatform()) . ' t'
+ . ' FROM ' . $this->quoteStrategy->getTableName($targetClass, $this->platform) . ' t'
. ' WHERE ' . implode(' AND ', $whereClauses);
return $this->_conn->fetchColumn($sql, $params);
@@ -204,7 +204,7 @@ public function removeElement(PersistentCollection $coll, $element)
$mapping = $coll->getMapping();
$class = $this->_em->getClassMetadata($mapping['targetEntity']);
- $sql = 'DELETE FROM ' . $class->getQuotedTableName($this->_conn->getDatabasePlatform())
+ $sql = 'DELETE FROM ' . $this->quoteStrategy->getTableName($class, $this->platform)
. ' WHERE ' . implode('= ? AND ', $class->getIdentifierColumnNames()) . ' = ?';
return (bool) $this->_conn->executeUpdate($sql, $this->_getDeleteRowSQLParameters($coll, $element));
View
31 lib/Doctrine/ORM/Query/AST/Functions/SizeFunction.php
@@ -42,21 +42,22 @@ class SizeFunction extends FunctionNode
*/
public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker)
{
- $platform = $sqlWalker->getConnection()->getDatabasePlatform();
- $dqlAlias = $this->collectionPathExpression->identificationVariable;
- $assocField = $this->collectionPathExpression->field;
+ $platform = $sqlWalker->getEntityManager()->getConnection()->getDatabasePlatform();
+ $quoteStrategy = $sqlWalker->getEntityManager()->getConfiguration()->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, $platform) . ' ' . $targetTableAlias . ' WHERE ';
$owningAssoc = $targetClass->associationMappings[$assoc['mappedBy']];
@@ -67,7 +68,7 @@ public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker)
$sql .= $targetTableAlias . '.' . $sourceColumn
. ' = '
- . $sourceTableAlias . '.' . $class->getQuotedColumnName($class->fieldNames[$targetColumn], $platform);
+ . $sourceTableAlias . '.' . $quoteStrategy->getColumnName($class->fieldNames[$targetColumn], $class, $platform);
}
} else { // many-to-many
$targetClass = $sqlWalker->getEntityManager()->getClassMetadata($assoc['targetEntity']);
@@ -80,7 +81,7 @@ public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker)
$sourceTableAlias = $sqlWalker->getSQLTableAlias($class->getTableName(), $dqlAlias);
// join to target table
- $sql .= $targetClass->getQuotedJoinTableName($owningAssoc, $platform) . ' ' . $joinTableAlias . ' WHERE ';
+ $sql .= $quoteStrategy->getJoinTableName($owningAssoc, $targetClass, $platform) . ' ' . $joinTableAlias . ' WHERE ';
$joinColumns = $assoc['isOwningSide']
? $joinTable['joinColumns']
@@ -91,8 +92,8 @@ public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker)
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, $platform
);
$sql .= $joinTableAlias . '.' . $joinColumn['name']
View
21 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->getConfiguration()->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 @@ public function __construct(AST\Node $AST, $sqlWalker)
// 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), $platform);
$this->_sqlStatements[] = 'DELETE FROM ' . $tableName
. ' WHERE (' . $idColumnList . ') IN (' . $idSubselect . ')';
}
View
24 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->getConfiguration()->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 @@ public function __construct(AST\Node $AST, $sqlWalker)
foreach (array_reverse($classNames) as $className) {
$affected = false;
$class = $em->getClassMetadata($className);
- $updateSql = 'UPDATE ' . $class->getQuotedTableName($platform) . ' SET ';
+ $updateSql = 'UPDATE ' . $quoteStrategy->getTableName($class, $platform) . ' SET ';
foreach ($updateItems as $updateItem) {
$field = $updateItem->pathExpression->field;
View
508 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->platform = $this->conn->getDatabasePlatform();
+ $this->quoteStrategy = $this->em->getConfiguration()->getQuoteStrategy();
}
/**
@@ -132,7 +181,7 @@ public function __construct($query, $parserResult, array $queryComponents)
*/
public function getQuery()
{
- return $this->_query;
+ return $this->query;
}
/**
@@ -142,7 +191,7 @@ public function getQuery()
*/
public function getConnection()
{
- return $this->_conn;
+ return $this->conn;
}
/**
@@ -152,7 +201,7 @@ public function getConnection()
*/
public function getEntityManager()
{
- return $this->_em;
+ return $this->em;
}
/**
@@ -163,7 +212,7 @@ public function getEntityManager()
*/
public function getQueryComponent($dqlAlias)
{
- return $this->_queryComponents[$dqlAlias];
+ return $this->queryComponents[$dqlAlias];
}
/**
@@ -175,14 +224,14 @@ public function getExecutor($AST)
{
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 @@ public function getSQLTableAlias($tableName, $dqlAlias = '')
{
$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];
}