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; break;
} }
$lock = $this->platform->appendLockHint($this->getLockTablesSql(), $lockMode); $lock = $this->getLockTablesSql($lockMode);
$where = ($conditionSql ? ' WHERE ' . $conditionSql : '') . ' '; $where = ($conditionSql ? ' WHERE ' . $conditionSql : '') . ' ';
$sql = 'SELECT 1 ' $sql = 'SELECT 1 '
. $lock . $lock
@ -1565,13 +1565,18 @@ class BasicEntityPersister
/** /**
* Gets the FROM and optionally JOIN conditions to lock the entity managed by this persister. * 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 * @return string
*/ */
protected function getLockTablesSql() protected function getLockTablesSql($lockMode)
{ {
return 'FROM ' return $this->platform->appendLockHint(
'FROM '
. $this->quoteStrategy->getTableName($this->class, $this->platform) . ' ' . $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); $alias = $this->getSQLTableAlias($this->class->name);
$sql = 'SELECT 1 ' $sql = 'SELECT 1 '
. $this->getLockTablesSql() . $this->getLockTablesSql(null)
. ' WHERE ' . $this->getSelectConditionSQL($criteria); . ' WHERE ' . $this->getSelectConditionSQL($criteria);
if ($filterSql = $this->generateFilterConditionSQL($this->class, $alias)) { 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. * {@inheritdoc}
*
* @return string
*/ */
public function getLockTablesSql() protected function getLockTablesSql($lockMode)
{ {
$joinSql = ''; $joinSql = '';
$identifierColumns = $this->class->getIdentifierColumnNames(); $identifierColumns = $this->class->getIdentifierColumnNames();
$baseTableAlias = $this->getSQLTableAlias($this->class->name); $baseTableAlias = $this->getSQLTableAlias($this->class->name);
$quotedTableName = $this->quoteStrategy->getTableName($this->class, $this->platform);
// INNER JOIN parent tables // INNER JOIN parent tables
foreach ($this->class->parentClasses as $parentClassName) { foreach ($this->class->parentClasses as $parentClassName) {
@ -412,7 +409,7 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
$joinSql .= implode(' AND ', $conditions); $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(); $sqlParts = array();
foreach ($identificationVarDecls as $identificationVariableDecl) { foreach ($identificationVarDecls as $identificationVariableDecl) {
$sql = $this->platform->appendLockHint( $sql = $this->walkRangeVariableDeclaration($identificationVariableDecl->rangeVariableDeclaration);
$this->walkRangeVariableDeclaration($identificationVariableDecl->rangeVariableDeclaration),
$this->query->getHint(Query::HINT_LOCK_MODE)
);
foreach ($identificationVariableDecl->joins as $join) { foreach ($identificationVariableDecl->joins as $join) {
$sql .= $this->walkJoin($join); $sql .= $this->walkJoin($join);
@ -846,8 +843,11 @@ class SqlWalker implements TreeWalker
$this->rootAliases[] = $dqlAlias; $this->rootAliases[] = $dqlAlias;
} }
$sql = $this->quoteStrategy->getTableName($class,$this->platform) . ' ' $sql = $this->platform->appendLockHint(
. $this->getSQLTableAlias($class->getTableName(), $dqlAlias); $this->quoteStrategy->getTableName($class, $this->platform) . ' ' .
$this->getSQLTableAlias($class->getTableName(), $dqlAlias),
$this->query->getHint(Query::HINT_LOCK_MODE)
);
if ($class->isInheritanceTypeJoined()) { if ($class->isInheritanceTypeJoined()) {
$sql .= $this->_generateClassTableInheritanceJoins($class, $dqlAlias); $sql .= $this->_generateClassTableInheritanceJoins($class, $dqlAlias);
@ -1439,10 +1439,7 @@ class SqlWalker implements TreeWalker
$sqlParts = array (); $sqlParts = array ();
foreach ($identificationVarDecls as $subselectIdVarDecl) { foreach ($identificationVarDecls as $subselectIdVarDecl) {
$sql = $this->platform->appendLockHint( $sql = $this->walkRangeVariableDeclaration($subselectIdVarDecl->rangeVariableDeclaration);
$this->walkRangeVariableDeclaration($subselectIdVarDecl->rangeVariableDeclaration),
$this->query->getHint(Query::HINT_LOCK_MODE)
);
foreach ($subselectIdVarDecl->joins as $join) { foreach ($subselectIdVarDecl->joins as $join) {
$sql .= $this->walkJoin($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 = ?" "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( $this->assertSqlGeneration(
"SELECT u.id FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE CONCAT(u.name, u.status, 's') = ?1", "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') = ?" "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( $this->assertSqlGeneration(
"SELECT CONCAT(u.id, u.name, u.status) FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = ?1", "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 = ?" "SELECT (c0_.id + c0_.name + c0_.status) AS sclr0 FROM cms_users c0_ WHERE c0_.id = ?"
);*/ );
$connMock->setDatabasePlatform($orgPlatform); $connMock->setDatabasePlatform($orgPlatform);
} }