1
0
mirror of synced 2025-01-29 19:41:45 +03:00

Fix quoting in BasicEntityPersister::_updateTable and BasicEntityPersister::delete. Added 6 tests for quoting of table names in different update, delete and inheritance scenario combinations

This commit is contained in:
Benjamin Eberlei 2010-10-30 19:33:20 +02:00
parent bf79168952
commit 515ef33665
3 changed files with 66 additions and 20 deletions

View File

@ -273,7 +273,10 @@ class BasicEntityPersister
$updateData = $this->_prepareUpdateData($entity); $updateData = $this->_prepareUpdateData($entity);
$tableName = $this->_class->table['name']; $tableName = $this->_class->table['name'];
if (isset($updateData[$tableName]) && $updateData[$tableName]) { if (isset($updateData[$tableName]) && $updateData[$tableName]) {
$this->_updateTable($entity, $tableName, $updateData[$tableName], $this->_class->isVersioned); $this->_updateTable(
$entity, $this->_class->getQuotedTableName($this->_platform),
$updateData[$tableName], $this->_class->isVersioned
);
} }
} }
@ -282,11 +285,11 @@ class BasicEntityPersister
* The UPDATE can optionally be versioned, which requires the entity to have a version field. * The UPDATE can optionally be versioned, which requires the entity to have a version field.
* *
* @param object $entity The entity object being updated. * @param object $entity The entity object being updated.
* @param string $tableName The name of the table to apply the UPDATE on. * @param string $quotedTableName The quoted name of the table to apply the UPDATE on.
* @param array $updateData The map of columns to update (column => value). * @param array $updateData The map of columns to update (column => value).
* @param boolean $versioned Whether the UPDATE should be versioned. * @param boolean $versioned Whether the UPDATE should be versioned.
*/ */
protected final function _updateTable($entity, $tableName, array $updateData, $versioned = false) protected final function _updateTable($entity, $quotedTableName, array $updateData, $versioned = false)
{ {
$set = $params = $types = array(); $set = $params = $types = array();
@ -322,7 +325,7 @@ class BasicEntityPersister
$types[] = $this->_class->fieldMappings[$versionField]['type']; $types[] = $this->_class->fieldMappings[$versionField]['type'];
} }
$sql = "UPDATE $tableName SET " . implode(', ', $set) $sql = "UPDATE $quotedTableName SET " . implode(', ', $set)
. ' WHERE ' . implode(' = ? AND ', $where) . ' = ?'; . ' WHERE ' . implode(' = ? AND ', $where) . ' = ?';
$result = $this->_conn->executeUpdate($sql, $params, $types); $result = $this->_conn->executeUpdate($sql, $params, $types);
@ -386,7 +389,7 @@ class BasicEntityPersister
$this->deleteJoinTableRecords($identifier); $this->deleteJoinTableRecords($identifier);
$id = array_combine($this->_class->getIdentifierColumnNames(), $identifier); $id = array_combine($this->_class->getIdentifierColumnNames(), $identifier);
$this->_conn->delete($this->_class->table['name'], $id); $this->_conn->delete($this->_class->getQuotedTableName($this->_platform), $id);
} }
/** /**

View File

@ -35,9 +35,18 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
/** /**
* Map that maps column names to the table names that own them. * Map that maps column names to the table names that own them.
* This is mainly a temporary cache, used during a single request. * This is mainly a temporary cache, used during a single request.
*
* @var array
*/ */
private $_owningTableMap = array(); private $_owningTableMap = array();
/**
* Map of table to quoted table names.
*
* @var array
*/
private $_quotedTableMap = array();
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
@ -74,18 +83,16 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
*/ */
public function getOwningTable($fieldName) public function getOwningTable($fieldName)
{ {
if ( ! isset($this->_owningTableMap[$fieldName])) { if (!isset($this->_owningTableMap[$fieldName])) {
if (isset($this->_class->associationMappings[$fieldName]['inherited'])) { if (isset($this->_class->associationMappings[$fieldName]['inherited'])) {
$this->_owningTableMap[$fieldName] = $this->_em->getClassMetadata( $cm = $this->_em->getClassMetadata($this->_class->associationMappings[$fieldName]['inherited']);
$this->_class->associationMappings[$fieldName]['inherited']
)->table['name'];
} else if (isset($this->_class->fieldMappings[$fieldName]['inherited'])) { } else if (isset($this->_class->fieldMappings[$fieldName]['inherited'])) {
$this->_owningTableMap[$fieldName] = $this->_em->getClassMetadata( $cm = $this->_em->getClassMetadata($this->_class->fieldMappings[$fieldName]['inherited']);
$this->_class->fieldMappings[$fieldName]['inherited']
)->table['name'];
} else { } else {
$this->_owningTableMap[$fieldName] = $this->_class->table['name']; $cm = $this->_class;
} }
$this->_owningTableMap[$fieldName] = $cm->table['name'];
$this->_quotedTableMap[$cm->table['name']] = $cm->getQuotedTableName($this->_platform);
} }
return $this->_owningTableMap[$fieldName]; return $this->_owningTableMap[$fieldName];
@ -191,12 +198,12 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
if ($updateData) { if ($updateData) {
foreach ($updateData as $tableName => $data) { foreach ($updateData as $tableName => $data) {
$this->_updateTable($entity, $tableName, $data, $isVersioned && $versionedTable == $tableName); $this->_updateTable($entity, $this->_quotedTableMap[$tableName], $data, $isVersioned && $versionedTable == $tableName);
} }
// Make sure the table with the version column is updated even if no columns on that // Make sure the table with the version column is updated even if no columns on that
// table were affected. // table were affected.
if ($isVersioned && ! isset($updateData[$versionedTable])) { if ($isVersioned && ! isset($updateData[$versionedTable])) {
$this->_updateTable($entity, $versionedTable, array(), true); $this->_updateTable($entity, $this->_quotedTableMap[$versionedTable], array(), true);
} }
} }
} }

View File

@ -15,9 +15,9 @@ class DDC832Test extends \Doctrine\Tests\OrmFunctionalTestCase
parent::setUp(); parent::setUp();
try { try {
$this->_schemaTool->createSchema(array( $this->_schemaTool->createSchema(array(
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC832Like'),
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC832JoinedIndex'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC832JoinedIndex'),
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC832JoinedTreeIndex'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC832JoinedTreeIndex'),
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC832Like'),
)); ));
} catch(\Exception $e) { } catch(\Exception $e) {
@ -55,7 +55,12 @@ class DDC832Test extends \Doctrine\Tests\OrmFunctionalTestCase
*/ */
public function testQuotedTableJoinedUpdate() public function testQuotedTableJoinedUpdate()
{ {
$this->markTestIncomplete('Not written yet.'); $index = new DDC832JoinedIndex("test");
$this->_em->persist($index);
$this->_em->flush();
$index->name = "asdf";
$this->_em->flush();
} }
/** /**
@ -63,7 +68,38 @@ class DDC832Test extends \Doctrine\Tests\OrmFunctionalTestCase
*/ */
public function testQuotedTableJoinedRemove() public function testQuotedTableJoinedRemove()
{ {
$this->markTestIncomplete('Not written yet.'); $index = new DDC832JoinedIndex("test");
$this->_em->persist($index);
$this->_em->flush();
$this->_em->remove($index);
$this->_em->flush();
}
/**
* @group DDC-832
*/
public function testQuotedTableJoinedChildUpdate()
{
$index = new DDC832JoinedTreeIndex("test", 1, 2);
$this->_em->persist($index);
$this->_em->flush();
$index->name = "asdf";
$this->_em->flush();
}
/**
* @group DDC-832
*/
public function testQuotedTableJoinedChildRemove()
{
$index = new DDC832JoinedTreeIndex("test", 1, 2);
$this->_em->persist($index);
$this->_em->flush();
$this->_em->remove($index);
$this->_em->flush();
} }
} }
@ -74,7 +110,7 @@ class DDC832Test extends \Doctrine\Tests\OrmFunctionalTestCase
class DDC832Like class DDC832Like
{ {
/** /**
* @Id @Column(type="string") @GeneratedValue * @Id @Column(type="integer") @GeneratedValue
*/ */
public $id; public $id;
@ -103,7 +139,7 @@ class DDC832Like
class DDC832JoinedIndex class DDC832JoinedIndex
{ {
/** /**
* @Id @Column(type="string") @GeneratedValue * @Id @Column(type="integer") @GeneratedValue
*/ */
public $id; public $id;