1
0
mirror of synced 2025-02-02 13:31:45 +03:00

Merge pull request #925 from deeky666/DDC-2310-2.4

[DDC-2310] [DDC-2675] [2.4] Fix SQL generation on table lock hint capable platforms
This commit is contained in:
Marco Pivetta 2014-11-12 00:31:13 +01:00
commit cfdef3bf19
4 changed files with 49 additions and 50 deletions

View File

@ -1550,7 +1550,7 @@ class BasicEntityPersister
break;
}
$lock = $this->platform->appendLockHint($this->getLockTablesSql(), $lockMode);
$lock = $this->getLockTablesSql($lockMode);
$where = ($conditionSql ? ' WHERE ' . $conditionSql : '') . ' ';
$sql = 'SELECT 1 '
. $lock
@ -1565,13 +1565,18 @@ class BasicEntityPersister
/**
* Gets the FROM and optionally JOIN conditions to lock the entity managed by this persister.
*
* @param integer $lockMode One of the Doctrine\DBAL\LockMode::* constants.
*
* @return string
*/
protected function getLockTablesSql()
protected function getLockTablesSql($lockMode)
{
return 'FROM '
return $this->platform->appendLockHint(
'FROM '
. $this->quoteStrategy->getTableName($this->class, $this->platform) . ' '
. $this->getSQLTableAlias($this->class->name);
. $this->getSQLTableAlias($this->class->name),
$lockMode
);
}
/**
@ -1910,7 +1915,7 @@ class BasicEntityPersister
$alias = $this->getSQLTableAlias($this->class->name);
$sql = 'SELECT 1 '
. $this->getLockTablesSql()
. $this->getLockTablesSql(null)
. ' WHERE ' . $this->getSelectConditionSQL($criteria);
if ($filterSql = $this->generateFilterConditionSQL($this->class, $alias)) {

View File

@ -387,16 +387,13 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
}
/**
* Get the FROM and optionally JOIN conditions to lock the entity managed by this persister.
*
* @return string
* {@inheritdoc}
*/
public function getLockTablesSql()
protected function getLockTablesSql($lockMode)
{
$joinSql = '';
$identifierColumns = $this->class->getIdentifierColumnNames();
$baseTableAlias = $this->getSQLTableAlias($this->class->name);
$quotedTableName = $this->quoteStrategy->getTableName($this->class, $this->platform);
// INNER JOIN parent tables
foreach ($this->class->parentClasses as $parentClassName) {
@ -412,7 +409,7 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
$joinSql .= implode(' AND ', $conditions);
}
return 'FROM ' . $quotedTableName . ' ' . $baseTableAlias . $joinSql;
return parent::getLockTablesSql($lockMode) . $joinSql;
}
/**

View File

@ -801,10 +801,7 @@ class SqlWalker implements TreeWalker
$sqlParts = array();
foreach ($identificationVarDecls as $identificationVariableDecl) {
$sql = $this->platform->appendLockHint(
$this->walkRangeVariableDeclaration($identificationVariableDecl->rangeVariableDeclaration),
$this->query->getHint(Query::HINT_LOCK_MODE)
);
$sql = $this->walkRangeVariableDeclaration($identificationVariableDecl->rangeVariableDeclaration);
foreach ($identificationVariableDecl->joins as $join) {
$sql .= $this->walkJoin($join);
@ -846,8 +843,11 @@ class SqlWalker implements TreeWalker
$this->rootAliases[] = $dqlAlias;
}
$sql = $this->quoteStrategy->getTableName($class,$this->platform) . ' '
. $this->getSQLTableAlias($class->getTableName(), $dqlAlias);
$sql = $this->platform->appendLockHint(
$this->quoteStrategy->getTableName($class, $this->platform) . ' ' .
$this->getSQLTableAlias($class->getTableName(), $dqlAlias),
$this->query->getHint(Query::HINT_LOCK_MODE)
);
if ($class->isInheritanceTypeJoined()) {
$sql .= $this->_generateClassTableInheritanceJoins($class, $dqlAlias);
@ -1439,10 +1439,7 @@ class SqlWalker implements TreeWalker
$sqlParts = array ();
foreach ($identificationVarDecls as $subselectIdVarDecl) {
$sql = $this->platform->appendLockHint(
$this->walkRangeVariableDeclaration($subselectIdVarDecl->rangeVariableDeclaration),
$this->query->getHint(Query::HINT_LOCK_MODE)
);
$sql = $this->walkRangeVariableDeclaration($subselectIdVarDecl->rangeVariableDeclaration);
foreach ($subselectIdVarDecl->joins as $join) {
$sql .= $this->walkJoin($join);

View File

@ -1990,7 +1990,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
"SELECT c0_.id || c0_.name || c0_.status AS sclr0 FROM cms_users c0_ WHERE c0_.id = ?"
);
/*$connMock->setDatabasePlatform(new \Doctrine\DBAL\Platforms\SQLServerPlatform());
$connMock->setDatabasePlatform(new \Doctrine\DBAL\Platforms\SQLServerPlatform());
$this->assertSqlGeneration(
"SELECT u.id FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE CONCAT(u.name, u.status, 's') = ?1",
"SELECT c0_.id AS id0 FROM cms_users c0_ WHERE (c0_.name + c0_.status + 's') = ?"
@ -1998,7 +1998,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
$this->assertSqlGeneration(
"SELECT CONCAT(u.id, u.name, u.status) FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = ?1",
"SELECT (c0_.id + c0_.name + c0_.status) AS sclr0 FROM cms_users c0_ WHERE c0_.id = ?"
);*/
);
$connMock->setDatabasePlatform($orgPlatform);
}