1
0
mirror of synced 2025-03-06 04:46:13 +03:00

Merge pull request #7077 from lcobucci/fix-delete-bc-break

Fix BC-break on delete without alias DQL
This commit is contained in:
Marco Pivetta 2018-02-19 11:32:46 +01:00 committed by GitHub
commit 1f82a20312
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 26 deletions

View File

@ -22,6 +22,7 @@ namespace Doctrine\ORM\Query;
use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Query; use Doctrine\ORM\Query;
use Doctrine\ORM\Query\AST\Functions; use Doctrine\ORM\Query\AST\Functions;
use function strpos;
/** /**
* An LL(*) recursive-descent parser for the context-free grammar of the Doctrine Query Language. * An LL(*) recursive-descent parser for the context-free grammar of the Doctrine Query Language.
@ -303,7 +304,11 @@ class Parser
$lookaheadType = $this->lexer->lookahead['type']; $lookaheadType = $this->lexer->lookahead['type'];
// Short-circuit on first condition, usually types match // Short-circuit on first condition, usually types match
if ($lookaheadType !== $token) { if ($lookaheadType === $token) {
$this->lexer->moveNext();
return;
}
// If parameter is not identifier (1-99) must be exact match // If parameter is not identifier (1-99) must be exact match
if ($token < Lexer::T_IDENTIFIER) { if ($token < Lexer::T_IDENTIFIER) {
$this->syntaxError($this->lexer->getLiteral($token)); $this->syntaxError($this->lexer->getLiteral($token));
@ -318,7 +323,6 @@ class Parser
if ($token === Lexer::T_IDENTIFIER && $lookaheadType < Lexer::T_IDENTIFIER) { if ($token === Lexer::T_IDENTIFIER && $lookaheadType < Lexer::T_IDENTIFIER) {
$this->syntaxError($this->lexer->getLiteral($token)); $this->syntaxError($this->lexer->getLiteral($token));
} }
}
$this->lexer->moveNext(); $this->lexer->moveNext();
} }
@ -958,20 +962,20 @@ class Parser
if ($this->lexer->isNextToken(Lexer::T_FULLY_QUALIFIED_NAME)) { if ($this->lexer->isNextToken(Lexer::T_FULLY_QUALIFIED_NAME)) {
$this->match(Lexer::T_FULLY_QUALIFIED_NAME); $this->match(Lexer::T_FULLY_QUALIFIED_NAME);
$schemaName = $this->lexer->token['value']; return $this->lexer->token['value'];
} else if ($this->lexer->isNextToken(Lexer::T_IDENTIFIER)) {
$this->match(Lexer::T_IDENTIFIER);
$schemaName = $this->lexer->token['value'];
} else {
$this->match(Lexer::T_ALIASED_NAME);
list($namespaceAlias, $simpleClassName) = explode(':', $this->lexer->token['value']);
$schemaName = $this->em->getConfiguration()->getEntityNamespace($namespaceAlias) . '\\' . $simpleClassName;
} }
return $schemaName; if ($this->lexer->isNextToken(Lexer::T_IDENTIFIER)) {
$this->match(Lexer::T_IDENTIFIER);
return $this->lexer->token['value'];
}
$this->match(Lexer::T_ALIASED_NAME);
[$namespaceAlias, $simpleClassName] = explode(':', $this->lexer->token['value']);
return $this->em->getConfiguration()->getEntityNamespace($namespaceAlias) . '\\' . $simpleClassName;
} }
/** /**
@ -1280,7 +1284,9 @@ class Parser
$this->match(Lexer::T_AS); $this->match(Lexer::T_AS);
} }
$aliasIdentificationVariable = $this->AliasIdentificationVariable(); $aliasIdentificationVariable = $this->lexer->isNextToken(Lexer::T_IDENTIFIER)
? $this->AliasIdentificationVariable()
: 'alias_should_have_been_set';
$deleteClause->aliasIdentificationVariable = $aliasIdentificationVariable; $deleteClause->aliasIdentificationVariable = $aliasIdentificationVariable;
$class = $this->em->getClassMetadata($deleteClause->abstractSchemaName); $class = $this->em->getClassMetadata($deleteClause->abstractSchemaName);

View File

@ -36,6 +36,14 @@ class DeleteSqlGenerationTest extends OrmTestCase
} }
} }
public function testSupportsDeleteWithoutWhereAndAlias() : void
{
$this->assertSqlGeneration(
'DELETE FROM Doctrine\Tests\Models\CMS\CmsUser',
'DELETE FROM cms_users'
);
}
public function testSupportsDeleteWithoutWhereAndFrom() public function testSupportsDeleteWithoutWhereAndFrom()
{ {
$this->assertSqlGeneration( $this->assertSqlGeneration(