1
0
mirror of synced 2024-12-12 22:36:02 +03:00

[2.0] Preparing to address character casing issue.

This commit is contained in:
romanb 2009-08-15 18:11:51 +00:00
parent cf77048ee4
commit ebb432bfb8
10 changed files with 87 additions and 8 deletions

View File

@ -36,6 +36,6 @@ class PDOConnection extends PDO implements Connection
parent::__construct($dsn, $user, $password, $options);
$this->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('Doctrine\DBAL\Driver\PDOStatement', array()));
$this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER);
//$this->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER);
}
}

View File

@ -1544,6 +1544,12 @@ abstract class AbstractPlatform
*/
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)
{
return $column;

View File

@ -501,6 +501,14 @@ END;';
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)
{
return strtoupper($column);

View File

@ -747,6 +747,14 @@ class PostgreSqlPlatform extends AbstractPlatform
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)
{
return strtolower($column);

View File

@ -530,7 +530,7 @@ class StandardEntityPersister
$coll = new PersistentCollection(
$this->_em,
$this->_em->getClassMetadata($assoc->targetEntityName),
new ArrayCollection);
/*$this->_class->reflFields[$field]->getValue($entity) ?:*/ new ArrayCollection);
$coll->setOwner($entity, $assoc);
$this->_class->reflFields[$field]->setValue($entity, $coll);
if ($assoc->isLazilyFetched()) {

View File

@ -29,7 +29,7 @@ namespace Doctrine\ORM\Query;
* reduce the size of serialized instances for more effective caching due to better (un-)serialization
* performance.
*
* Users should use the public methods.
* <b>Users should use the public methods.</b>
*
* @author Roman Borschel <roman@code-factory.org>
* @since 2.0
@ -40,7 +40,7 @@ class ResultSetMapping
public $isMixed = false;
/** Maps alias names to ClassMetadata descriptors. */
public $aliasMap = array();
/** Maps alias names to related association mappings. */
/** Maps alias names to related association field names. */
public $relationMap = array();
/** Maps alias names to parent alias names. */
public $parentAliasMap = array();
@ -141,7 +141,7 @@ class ResultSetMapping
* @param string $class The class name of 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 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)
{
@ -154,7 +154,7 @@ class ResultSetMapping
* Adds a scalar result mapping.
*
* @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)
{

View File

@ -471,6 +471,7 @@ class SqlWalker implements TreeWalker
$sql .= ", $tblAlias." . $rootClass->getQuotedDiscriminatorColumnName($this->_platform)
. ' AS ' . $columnAlias;
//$columnAlias = $this->_platform->getSqlResultCasing($columnAlias);
$this->_rsm->setDiscriminatorColumn($dqlAlias, $columnAlias);
$this->_rsm->addMetaResult($dqlAlias, $columnAlias, $discrColumn['fieldName']);
@ -489,6 +490,7 @@ class SqlWalker implements TreeWalker
$columnAlias = $this->getSqlColumnAlias($srcColumn);
$sql .= ", $sqlTableAlias." . $assoc->getQuotedJoinColumnName($srcColumn, $this->_platform)
. ' AS ' . $columnAlias;
//$columnAlias = $this->_platform->getSqlResultCasing($columnAlias);
$this->_rsm->addMetaResult($dqlAlias, $columnAlias, $srcColumn);
}
}
@ -504,6 +506,7 @@ class SqlWalker implements TreeWalker
foreach ($assoc->targetToSourceKeyColumns as $srcColumn) {
$columnAlias = $this->getSqlColumnAlias($srcColumn);
$sql .= ', ' . $sqlTableAlias . '.' . $assoc->getQuotedJoinColumnName($srcColumn, $this->_platform) . ' AS ' . $columnAlias;
//$columnAlias = $this->_platform->getSqlResultCasing($columnAlias);
$this->_rsm->addMetaResult($dqlAlias, $columnAlias, $srcColumn);
}
}
@ -745,6 +748,7 @@ class SqlWalker implements TreeWalker
$columnAlias = $this->getSqlColumnAlias($class->columnNames[$fieldName]);
$sql .= $sqlTableAlias . '.' . $columnName . ' AS ' . $columnAlias;
//$columnAlias = $this->_platform->getSqlResultCasing($columnAlias);
$this->_rsm->addFieldResult($dqlAlias, $columnAlias, $fieldName);
} else {
throw DoctrineException::updateMe(
@ -761,6 +765,7 @@ class SqlWalker implements TreeWalker
$columnAlias = 'sclr' . $this->_aliasCounter++;
$sql .= $this->walkAggregateExpression($expr) . ' AS ' . $columnAlias;
//$columnAlias = $this->_platform->getSqlResultCasing($columnAlias);
$this->_rsm->addScalarResult($columnAlias, $resultAlias);
} else if ($expr instanceof AST\Subselect) {
$sql .= $this->walkSubselect($expr);
@ -774,6 +779,7 @@ class SqlWalker implements TreeWalker
$columnAlias = 'sclr' . $this->_aliasCounter++;
$sql .= $this->walkFunction($expr) . ' AS ' . $columnAlias;
//$columnAlias = $this->_platform->getSqlResultCasing($columnAlias);
$this->_rsm->addScalarResult($columnAlias, $resultAlias);
} else {
// IdentificationVariable
@ -801,6 +807,7 @@ class SqlWalker implements TreeWalker
$sql .= $sqlTableAlias . '.' . $class->getQuotedColumnName($fieldName, $this->_platform)
. ' AS ' . $columnAlias;
//$columnAlias = $this->_platform->getSqlResultCasing($columnAlias);
$this->_rsm->addFieldResult($dqlAlias, $columnAlias, $fieldName);
}
@ -820,6 +827,7 @@ class SqlWalker implements TreeWalker
$sql .= $sqlTableAlias . '.' . $subClass->getQuotedColumnName($fieldName, $this->_platform)
. ' AS ' . $columnAlias;
//$columnAlias = $this->_platform->getSqlResultCasing($columnAlias);
$this->_rsm->addFieldResult($dqlAlias, $columnAlias, $fieldName);
}
}

View File

@ -205,7 +205,7 @@ class SchemaTool
private function _gatherColumn($class, array $mapping, array &$options)
{
$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['length'] = $mapping['length'];
$column['notnull'] = ! $mapping['nullable'];

View File

@ -4,6 +4,7 @@ namespace Doctrine\Tests\ORM\Functional;
use Doctrine\ORM\Query\ResultSetMapping;
use Doctrine\Tests\Models\CMS\CmsUser;
use Doctrine\Tests\Models\CMS\CmsPhonenumber;
require_once __DIR__ . '/../../TestInit.php';
@ -17,6 +18,10 @@ class NativeQueryTest extends \Doctrine\Tests\OrmFunctionalTestCase
protected function setUp() {
$this->useModelSet('cms');
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()
@ -27,6 +32,8 @@ class NativeQueryTest extends \Doctrine\Tests\OrmFunctionalTestCase
$user->status = 'dev';
$this->_em->persist($user);
$this->_em->flush();
$this->_em->clear();
$rsm = new ResultSetMapping;
$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->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]);
}
}

View File

@ -20,6 +20,8 @@ class SingleTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\RelatedEntity')
));
} catch (\Exception $e) {
var_dump($e->getMessage());
var_dump($e->getTraceAsString());
// Swallow all exceptions. We do not test the schema tool here.
}
}
@ -111,7 +113,7 @@ class ParentEntity {
private $id;
/**
* @Column(type="string")
* @Column(name="DATA", type="string")
*/
private $data;