[2.0] Preparing to address character casing issue.
This commit is contained in:
parent
cf77048ee4
commit
ebb432bfb8
@ -36,6 +36,6 @@ class PDOConnection extends PDO implements Connection
|
|||||||
parent::__construct($dsn, $user, $password, $options);
|
parent::__construct($dsn, $user, $password, $options);
|
||||||
$this->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('Doctrine\DBAL\Driver\PDOStatement', array()));
|
$this->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('Doctrine\DBAL\Driver\PDOStatement', array()));
|
||||||
$this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
$this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||||
$this->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER);
|
//$this->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1544,6 +1544,12 @@ abstract class AbstractPlatform
|
|||||||
*/
|
*/
|
||||||
abstract public function getName();
|
abstract public function getName();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the character casing of a column in an SQL result set of this platform.
|
||||||
|
*
|
||||||
|
* @param string $column The column name for which to get the correct character casing.
|
||||||
|
* @return string The column name in the character casing used in SQL result sets.
|
||||||
|
*/
|
||||||
public function getSqlResultCasing($column)
|
public function getSqlResultCasing($column)
|
||||||
{
|
{
|
||||||
return $column;
|
return $column;
|
||||||
|
@ -501,6 +501,14 @@ END;';
|
|||||||
return $query;
|
return $query;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the character casing of a column in an SQL result set of this platform.
|
||||||
|
*
|
||||||
|
* Oracle returns all column names in SQL result sets in uppercase.
|
||||||
|
*
|
||||||
|
* @param string $column The column name for which to get the correct character casing.
|
||||||
|
* @return string The column name in the character casing used in SQL result sets.
|
||||||
|
*/
|
||||||
public function getSqlResultCasing($column)
|
public function getSqlResultCasing($column)
|
||||||
{
|
{
|
||||||
return strtoupper($column);
|
return strtoupper($column);
|
||||||
|
@ -747,6 +747,14 @@ class PostgreSqlPlatform extends AbstractPlatform
|
|||||||
return 'postgresql';
|
return 'postgresql';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the character casing of a column in an SQL result set.
|
||||||
|
*
|
||||||
|
* PostgreSQL returns all column names in SQL result sets in lowercase.
|
||||||
|
*
|
||||||
|
* @param string $column The column name for which to get the correct character casing.
|
||||||
|
* @return string The column name in the character casing used in SQL result sets.
|
||||||
|
*/
|
||||||
public function getSqlResultCasing($column)
|
public function getSqlResultCasing($column)
|
||||||
{
|
{
|
||||||
return strtolower($column);
|
return strtolower($column);
|
||||||
|
@ -530,7 +530,7 @@ class StandardEntityPersister
|
|||||||
$coll = new PersistentCollection(
|
$coll = new PersistentCollection(
|
||||||
$this->_em,
|
$this->_em,
|
||||||
$this->_em->getClassMetadata($assoc->targetEntityName),
|
$this->_em->getClassMetadata($assoc->targetEntityName),
|
||||||
new ArrayCollection);
|
/*$this->_class->reflFields[$field]->getValue($entity) ?:*/ new ArrayCollection);
|
||||||
$coll->setOwner($entity, $assoc);
|
$coll->setOwner($entity, $assoc);
|
||||||
$this->_class->reflFields[$field]->setValue($entity, $coll);
|
$this->_class->reflFields[$field]->setValue($entity, $coll);
|
||||||
if ($assoc->isLazilyFetched()) {
|
if ($assoc->isLazilyFetched()) {
|
||||||
|
@ -29,7 +29,7 @@ namespace Doctrine\ORM\Query;
|
|||||||
* reduce the size of serialized instances for more effective caching due to better (un-)serialization
|
* reduce the size of serialized instances for more effective caching due to better (un-)serialization
|
||||||
* performance.
|
* performance.
|
||||||
*
|
*
|
||||||
* Users should use the public methods.
|
* <b>Users should use the public methods.</b>
|
||||||
*
|
*
|
||||||
* @author Roman Borschel <roman@code-factory.org>
|
* @author Roman Borschel <roman@code-factory.org>
|
||||||
* @since 2.0
|
* @since 2.0
|
||||||
@ -40,7 +40,7 @@ class ResultSetMapping
|
|||||||
public $isMixed = false;
|
public $isMixed = false;
|
||||||
/** Maps alias names to ClassMetadata descriptors. */
|
/** Maps alias names to ClassMetadata descriptors. */
|
||||||
public $aliasMap = array();
|
public $aliasMap = array();
|
||||||
/** Maps alias names to related association mappings. */
|
/** Maps alias names to related association field names. */
|
||||||
public $relationMap = array();
|
public $relationMap = array();
|
||||||
/** Maps alias names to parent alias names. */
|
/** Maps alias names to parent alias names. */
|
||||||
public $parentAliasMap = array();
|
public $parentAliasMap = array();
|
||||||
@ -141,7 +141,7 @@ class ResultSetMapping
|
|||||||
* @param string $class The class name of the joined entity.
|
* @param string $class The class name of the joined entity.
|
||||||
* @param string $alias The unique alias to use for the joined entity.
|
* @param string $alias The unique alias to use for the joined entity.
|
||||||
* @param string $parentAlias The alias of the entity result that is the parent of this joined result.
|
* @param string $parentAlias The alias of the entity result that is the parent of this joined result.
|
||||||
* @param object $relation The association that connects the parent entity result with the joined entity result.
|
* @param object $relation The association field that connects the parent entity result with the joined entity result.
|
||||||
*/
|
*/
|
||||||
public function addJoinedEntityResult($class, $alias, $parentAlias, $relation)
|
public function addJoinedEntityResult($class, $alias, $parentAlias, $relation)
|
||||||
{
|
{
|
||||||
@ -154,7 +154,7 @@ class ResultSetMapping
|
|||||||
* Adds a scalar result mapping.
|
* Adds a scalar result mapping.
|
||||||
*
|
*
|
||||||
* @param string $columnName The name of the column in the SQL result set.
|
* @param string $columnName The name of the column in the SQL result set.
|
||||||
* @param string $alias The field alias with which the scalar result should be placed in the result structure.
|
* @param string $alias The result alias with which the scalar result should be placed in the result structure.
|
||||||
*/
|
*/
|
||||||
public function addScalarResult($columnName, $alias)
|
public function addScalarResult($columnName, $alias)
|
||||||
{
|
{
|
||||||
|
@ -471,6 +471,7 @@ class SqlWalker implements TreeWalker
|
|||||||
$sql .= ", $tblAlias." . $rootClass->getQuotedDiscriminatorColumnName($this->_platform)
|
$sql .= ", $tblAlias." . $rootClass->getQuotedDiscriminatorColumnName($this->_platform)
|
||||||
. ' AS ' . $columnAlias;
|
. ' AS ' . $columnAlias;
|
||||||
|
|
||||||
|
//$columnAlias = $this->_platform->getSqlResultCasing($columnAlias);
|
||||||
$this->_rsm->setDiscriminatorColumn($dqlAlias, $columnAlias);
|
$this->_rsm->setDiscriminatorColumn($dqlAlias, $columnAlias);
|
||||||
$this->_rsm->addMetaResult($dqlAlias, $columnAlias, $discrColumn['fieldName']);
|
$this->_rsm->addMetaResult($dqlAlias, $columnAlias, $discrColumn['fieldName']);
|
||||||
|
|
||||||
@ -489,6 +490,7 @@ class SqlWalker implements TreeWalker
|
|||||||
$columnAlias = $this->getSqlColumnAlias($srcColumn);
|
$columnAlias = $this->getSqlColumnAlias($srcColumn);
|
||||||
$sql .= ", $sqlTableAlias." . $assoc->getQuotedJoinColumnName($srcColumn, $this->_platform)
|
$sql .= ", $sqlTableAlias." . $assoc->getQuotedJoinColumnName($srcColumn, $this->_platform)
|
||||||
. ' AS ' . $columnAlias;
|
. ' AS ' . $columnAlias;
|
||||||
|
//$columnAlias = $this->_platform->getSqlResultCasing($columnAlias);
|
||||||
$this->_rsm->addMetaResult($dqlAlias, $columnAlias, $srcColumn);
|
$this->_rsm->addMetaResult($dqlAlias, $columnAlias, $srcColumn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -504,6 +506,7 @@ class SqlWalker implements TreeWalker
|
|||||||
foreach ($assoc->targetToSourceKeyColumns as $srcColumn) {
|
foreach ($assoc->targetToSourceKeyColumns as $srcColumn) {
|
||||||
$columnAlias = $this->getSqlColumnAlias($srcColumn);
|
$columnAlias = $this->getSqlColumnAlias($srcColumn);
|
||||||
$sql .= ', ' . $sqlTableAlias . '.' . $assoc->getQuotedJoinColumnName($srcColumn, $this->_platform) . ' AS ' . $columnAlias;
|
$sql .= ', ' . $sqlTableAlias . '.' . $assoc->getQuotedJoinColumnName($srcColumn, $this->_platform) . ' AS ' . $columnAlias;
|
||||||
|
//$columnAlias = $this->_platform->getSqlResultCasing($columnAlias);
|
||||||
$this->_rsm->addMetaResult($dqlAlias, $columnAlias, $srcColumn);
|
$this->_rsm->addMetaResult($dqlAlias, $columnAlias, $srcColumn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -745,6 +748,7 @@ class SqlWalker implements TreeWalker
|
|||||||
$columnAlias = $this->getSqlColumnAlias($class->columnNames[$fieldName]);
|
$columnAlias = $this->getSqlColumnAlias($class->columnNames[$fieldName]);
|
||||||
$sql .= $sqlTableAlias . '.' . $columnName . ' AS ' . $columnAlias;
|
$sql .= $sqlTableAlias . '.' . $columnName . ' AS ' . $columnAlias;
|
||||||
|
|
||||||
|
//$columnAlias = $this->_platform->getSqlResultCasing($columnAlias);
|
||||||
$this->_rsm->addFieldResult($dqlAlias, $columnAlias, $fieldName);
|
$this->_rsm->addFieldResult($dqlAlias, $columnAlias, $fieldName);
|
||||||
} else {
|
} else {
|
||||||
throw DoctrineException::updateMe(
|
throw DoctrineException::updateMe(
|
||||||
@ -761,6 +765,7 @@ class SqlWalker implements TreeWalker
|
|||||||
$columnAlias = 'sclr' . $this->_aliasCounter++;
|
$columnAlias = 'sclr' . $this->_aliasCounter++;
|
||||||
$sql .= $this->walkAggregateExpression($expr) . ' AS ' . $columnAlias;
|
$sql .= $this->walkAggregateExpression($expr) . ' AS ' . $columnAlias;
|
||||||
|
|
||||||
|
//$columnAlias = $this->_platform->getSqlResultCasing($columnAlias);
|
||||||
$this->_rsm->addScalarResult($columnAlias, $resultAlias);
|
$this->_rsm->addScalarResult($columnAlias, $resultAlias);
|
||||||
} else if ($expr instanceof AST\Subselect) {
|
} else if ($expr instanceof AST\Subselect) {
|
||||||
$sql .= $this->walkSubselect($expr);
|
$sql .= $this->walkSubselect($expr);
|
||||||
@ -774,6 +779,7 @@ class SqlWalker implements TreeWalker
|
|||||||
$columnAlias = 'sclr' . $this->_aliasCounter++;
|
$columnAlias = 'sclr' . $this->_aliasCounter++;
|
||||||
$sql .= $this->walkFunction($expr) . ' AS ' . $columnAlias;
|
$sql .= $this->walkFunction($expr) . ' AS ' . $columnAlias;
|
||||||
|
|
||||||
|
//$columnAlias = $this->_platform->getSqlResultCasing($columnAlias);
|
||||||
$this->_rsm->addScalarResult($columnAlias, $resultAlias);
|
$this->_rsm->addScalarResult($columnAlias, $resultAlias);
|
||||||
} else {
|
} else {
|
||||||
// IdentificationVariable
|
// IdentificationVariable
|
||||||
@ -801,6 +807,7 @@ class SqlWalker implements TreeWalker
|
|||||||
$sql .= $sqlTableAlias . '.' . $class->getQuotedColumnName($fieldName, $this->_platform)
|
$sql .= $sqlTableAlias . '.' . $class->getQuotedColumnName($fieldName, $this->_platform)
|
||||||
. ' AS ' . $columnAlias;
|
. ' AS ' . $columnAlias;
|
||||||
|
|
||||||
|
//$columnAlias = $this->_platform->getSqlResultCasing($columnAlias);
|
||||||
$this->_rsm->addFieldResult($dqlAlias, $columnAlias, $fieldName);
|
$this->_rsm->addFieldResult($dqlAlias, $columnAlias, $fieldName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -820,6 +827,7 @@ class SqlWalker implements TreeWalker
|
|||||||
$sql .= $sqlTableAlias . '.' . $subClass->getQuotedColumnName($fieldName, $this->_platform)
|
$sql .= $sqlTableAlias . '.' . $subClass->getQuotedColumnName($fieldName, $this->_platform)
|
||||||
. ' AS ' . $columnAlias;
|
. ' AS ' . $columnAlias;
|
||||||
|
|
||||||
|
//$columnAlias = $this->_platform->getSqlResultCasing($columnAlias);
|
||||||
$this->_rsm->addFieldResult($dqlAlias, $columnAlias, $fieldName);
|
$this->_rsm->addFieldResult($dqlAlias, $columnAlias, $fieldName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -205,7 +205,7 @@ class SchemaTool
|
|||||||
private function _gatherColumn($class, array $mapping, array &$options)
|
private function _gatherColumn($class, array $mapping, array &$options)
|
||||||
{
|
{
|
||||||
$column = array();
|
$column = array();
|
||||||
$column['name'] = $class->getQuotedColumnName($mapping['columnName'], $this->_platform);
|
$column['name'] = $class->getQuotedColumnName($mapping['fieldName'], $this->_platform);
|
||||||
$column['type'] = Type::getType($mapping['type']);
|
$column['type'] = Type::getType($mapping['type']);
|
||||||
$column['length'] = $mapping['length'];
|
$column['length'] = $mapping['length'];
|
||||||
$column['notnull'] = ! $mapping['nullable'];
|
$column['notnull'] = ! $mapping['nullable'];
|
||||||
|
@ -4,6 +4,7 @@ namespace Doctrine\Tests\ORM\Functional;
|
|||||||
|
|
||||||
use Doctrine\ORM\Query\ResultSetMapping;
|
use Doctrine\ORM\Query\ResultSetMapping;
|
||||||
use Doctrine\Tests\Models\CMS\CmsUser;
|
use Doctrine\Tests\Models\CMS\CmsUser;
|
||||||
|
use Doctrine\Tests\Models\CMS\CmsPhonenumber;
|
||||||
|
|
||||||
require_once __DIR__ . '/../../TestInit.php';
|
require_once __DIR__ . '/../../TestInit.php';
|
||||||
|
|
||||||
@ -17,6 +18,10 @@ class NativeQueryTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
|||||||
protected function setUp() {
|
protected function setUp() {
|
||||||
$this->useModelSet('cms');
|
$this->useModelSet('cms');
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
|
if ($this->_em->getConnection()->getDatabasePlatform()->getName() == 'oracle') {
|
||||||
|
$this->markTestSkipped('The ' . $testClass .' does not work with Oracle due to character casing.');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testBasicNativeQuery()
|
public function testBasicNativeQuery()
|
||||||
@ -27,6 +32,8 @@ class NativeQueryTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
|||||||
$user->status = 'dev';
|
$user->status = 'dev';
|
||||||
$this->_em->persist($user);
|
$this->_em->persist($user);
|
||||||
$this->_em->flush();
|
$this->_em->flush();
|
||||||
|
|
||||||
|
$this->_em->clear();
|
||||||
|
|
||||||
$rsm = new ResultSetMapping;
|
$rsm = new ResultSetMapping;
|
||||||
$rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u');
|
$rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u');
|
||||||
@ -42,5 +49,45 @@ class NativeQueryTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
|||||||
$this->assertTrue($users[0] instanceof CmsUser);
|
$this->assertTrue($users[0] instanceof CmsUser);
|
||||||
$this->assertEquals('Roman', $users[0]->name);
|
$this->assertEquals('Roman', $users[0]->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testJoinedNativeQuery()
|
||||||
|
{
|
||||||
|
$user = new CmsUser;
|
||||||
|
$user->name = 'Roman';
|
||||||
|
$user->username = 'romanb';
|
||||||
|
$user->status = 'dev';
|
||||||
|
|
||||||
|
$phone = new CmsPhonenumber;
|
||||||
|
$phone->phonenumber = 424242;
|
||||||
|
|
||||||
|
$user->addPhonenumber($phone);
|
||||||
|
|
||||||
|
$this->_em->persist($user);
|
||||||
|
$this->_em->flush();
|
||||||
|
|
||||||
|
$this->_em->clear();
|
||||||
|
|
||||||
|
$rsm = new ResultSetMapping;
|
||||||
|
$rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u');
|
||||||
|
$rsm->addFieldResult('u', 'id', 'id');
|
||||||
|
$rsm->addFieldResult('u', 'name', 'name');
|
||||||
|
$rsm->addFieldResult('u', 'status', 'status');
|
||||||
|
$rsm->addJoinedEntityResult('Doctrine\Tests\Models\CMS\CmsPhonenumber', 'p', 'u', 'phonenumbers');
|
||||||
|
$rsm->addFieldResult('p', 'phonenumber', 'phonenumber');
|
||||||
|
|
||||||
|
$query = $this->_em->createNativeQuery('SELECT id, name, status, phonenumber FROM cms_users INNER JOIN cms_phonenumbers ON id = user_id WHERE username = ?', $rsm);
|
||||||
|
$query->setParameter(1, 'romanb');
|
||||||
|
|
||||||
|
$users = $query->getResult();
|
||||||
|
$this->assertEquals(1, count($users));
|
||||||
|
$this->assertTrue($users[0] instanceof CmsUser);
|
||||||
|
$this->assertEquals('Roman', $users[0]->name);
|
||||||
|
$this->assertTrue($users[0]->getPhonenumbers() instanceof \Doctrine\ORM\PersistentCollection);
|
||||||
|
$this->assertEquals(1, count($users[0]->getPhonenumbers()));
|
||||||
|
$phones = $users[0]->getPhonenumbers();
|
||||||
|
$this->assertEquals(424242, $phones[0]->phonenumber);
|
||||||
|
$this->assertTrue($phones[0]->getUser() === $users[0]);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,6 +20,8 @@ class SingleTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
|||||||
$this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\RelatedEntity')
|
$this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\RelatedEntity')
|
||||||
));
|
));
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
var_dump($e->getMessage());
|
||||||
|
var_dump($e->getTraceAsString());
|
||||||
// Swallow all exceptions. We do not test the schema tool here.
|
// Swallow all exceptions. We do not test the schema tool here.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -111,7 +113,7 @@ class ParentEntity {
|
|||||||
private $id;
|
private $id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Column(type="string")
|
* @Column(name="DATA", type="string")
|
||||||
*/
|
*/
|
||||||
private $data;
|
private $data;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user