ANSI compliant quote strategy
This commit is contained in:
parent
eaf8fd3c34
commit
a165f63c8c
97
lib/Doctrine/ORM/Mapping/AnsiQuoteStrategy.php
Normal file
97
lib/Doctrine/ORM/Mapping/AnsiQuoteStrategy.php
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
<?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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ANSI compliant quote strategy, this strategy does not apply any quote.
|
||||||
|
* To use this strategy all mapped tables and columns should be ANSI compliant.
|
||||||
|
*
|
||||||
|
* @since 2.5
|
||||||
|
* @author Fabio B. Silva <fabio.bat.silva@gmail.com>
|
||||||
|
*/
|
||||||
|
class AnsiQuoteStrategy implements QuoteStrategy
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getColumnName($fieldName, ClassMetadata $class, AbstractPlatform $platform)
|
||||||
|
{
|
||||||
|
return $class->fieldMappings[$fieldName]['columnName'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getTableName(ClassMetadata $class, AbstractPlatform $platform)
|
||||||
|
{
|
||||||
|
return $class->table['name'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getSequenceName(array $definition, ClassMetadata $class, AbstractPlatform $platform)
|
||||||
|
{
|
||||||
|
return $definition['sequenceName'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getJoinColumnName(array $joinColumn, ClassMetadata $class, AbstractPlatform $platform)
|
||||||
|
{
|
||||||
|
return $joinColumn['name'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getReferencedJoinColumnName(array $joinColumn, ClassMetadata $class, AbstractPlatform $platform)
|
||||||
|
{
|
||||||
|
return $joinColumn['referencedColumnName'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getJoinTableName(array $association, ClassMetadata $class, AbstractPlatform $platform)
|
||||||
|
{
|
||||||
|
return $association['joinTable']['name'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getIdentifierColumnNames(ClassMetadata $class, AbstractPlatform $platform)
|
||||||
|
{
|
||||||
|
return $class->identifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getColumnAlias($columnName, $counter, AbstractPlatform $platform, ClassMetadata $class = null)
|
||||||
|
{
|
||||||
|
return $platform->getSQLResultCasing($columnName . $counter);
|
||||||
|
}
|
||||||
|
}
|
148
tests/Doctrine/Tests/ORM/Mapping/AnsiQuoteStrategyTest.php
Normal file
148
tests/Doctrine/Tests/ORM/Mapping/AnsiQuoteStrategyTest.php
Normal file
@ -0,0 +1,148 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Doctrine\Tests\ORM\Mapping;
|
||||||
|
|
||||||
|
use Doctrine\ORM\Mapping\AnsiQuoteStrategy;
|
||||||
|
use Doctrine\ORM\Mapping\ClassMetadata;
|
||||||
|
use Doctrine\Tests\OrmTestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group DDC-1845
|
||||||
|
* @group DDC-2459
|
||||||
|
*/
|
||||||
|
class AnsiQuoteStrategyTest extends OrmTestCase
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \Doctrine\ORM\Mapping\DefaultQuoteStrategy
|
||||||
|
*/
|
||||||
|
private $strategy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \Doctrine\DBAL\Platforms\AbstractPlatform
|
||||||
|
*/
|
||||||
|
private $platform;
|
||||||
|
|
||||||
|
protected function setUp()
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
$em = $this->_getTestEntityManager();
|
||||||
|
$this->platform = $em->getConnection()->getDatabasePlatform();
|
||||||
|
$this->strategy = new AnsiQuoteStrategy();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $className
|
||||||
|
* @return \Doctrine\ORM\Mapping\ClassMetadata
|
||||||
|
*/
|
||||||
|
private function createClassMetadata($className)
|
||||||
|
{
|
||||||
|
$class = new ClassMetadata($className);
|
||||||
|
$class->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService);
|
||||||
|
|
||||||
|
return $class;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetColumnName()
|
||||||
|
{
|
||||||
|
$class = $this->createClassMetadata('Doctrine\Tests\Models\CMS\CmsUser');
|
||||||
|
$class->mapField(array('fieldName' => 'name', 'columnName' => 'name'));
|
||||||
|
$class->mapField(array('fieldName' => 'id', 'columnName' => 'id', 'id' => true));
|
||||||
|
|
||||||
|
$this->assertEquals('id' ,$this->strategy->getColumnName('id', $class, $this->platform));
|
||||||
|
$this->assertEquals('name' ,$this->strategy->getColumnName('name', $class, $this->platform));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetTableName()
|
||||||
|
{
|
||||||
|
$class = $this->createClassMetadata('Doctrine\Tests\Models\CMS\CmsUser');
|
||||||
|
|
||||||
|
$class->setPrimaryTable(array('name'=>'cms_user'));
|
||||||
|
$this->assertEquals('cms_user' ,$this->strategy->getTableName($class, $this->platform));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testJoinTableName()
|
||||||
|
{
|
||||||
|
$class = $this->createClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress');
|
||||||
|
|
||||||
|
$class->mapManyToMany(array(
|
||||||
|
'fieldName' => 'user',
|
||||||
|
'targetEntity' => 'CmsUser',
|
||||||
|
'inversedBy' => 'users',
|
||||||
|
'joinTable' => array(
|
||||||
|
'name' => 'cmsaddress_cmsuser'
|
||||||
|
)
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->assertEquals('cmsaddress_cmsuser', $this->strategy->getJoinTableName($class->associationMappings['user'], $class, $this->platform));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testIdentifierColumnNames()
|
||||||
|
{
|
||||||
|
$class = $this->createClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress');
|
||||||
|
|
||||||
|
$class->mapField(array(
|
||||||
|
'id' => true,
|
||||||
|
'fieldName' => 'id',
|
||||||
|
'columnName' => 'id',
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->assertEquals(array('id'), $this->strategy->getIdentifierColumnNames($class, $this->platform));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testColumnAlias()
|
||||||
|
{
|
||||||
|
$this->assertEquals('columnName1', $this->strategy->getColumnAlias('columnName', 1, $this->platform));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testJoinColumnName()
|
||||||
|
{
|
||||||
|
$class = $this->createClassMetadata('Doctrine\Tests\Models\DDC117\DDC117ArticleDetails');
|
||||||
|
|
||||||
|
$class->mapOneToOne(array(
|
||||||
|
'id' => true,
|
||||||
|
'fieldName' => 'article',
|
||||||
|
'targetEntity' => 'Doctrine\Tests\Models\DDC117\DDC117Article',
|
||||||
|
'joinColumns' => array(array(
|
||||||
|
'name' => 'article'
|
||||||
|
)),
|
||||||
|
));
|
||||||
|
|
||||||
|
$joinColumn = $class->associationMappings['article']['joinColumns'][0];
|
||||||
|
$this->assertEquals('article',$this->strategy->getJoinColumnName($joinColumn, $class, $this->platform));
|
||||||
|
}
|
||||||
|
|
||||||
|
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, $this->platform));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetSequenceName()
|
||||||
|
{
|
||||||
|
$class = $this->createClassMetadata('Doctrine\Tests\Models\CMS\CmsUser');
|
||||||
|
$definition = array(
|
||||||
|
'sequenceName' => 'user_id_seq',
|
||||||
|
'allocationSize' => 1,
|
||||||
|
'initialValue' => 2
|
||||||
|
);
|
||||||
|
|
||||||
|
$class->setSequenceGeneratorDefinition($definition);
|
||||||
|
|
||||||
|
$this->assertEquals('user_id_seq',$this->strategy->getSequenceName($definition, $class, $this->platform));
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user