[2.0] More preparations to fix character casing issue. Reverted and completed ConditionalPrimary parsing and added more tests for this.
This commit is contained in:
parent
ebb432bfb8
commit
32069cc2b5
@ -10,5 +10,5 @@ namespace Doctrine\DBAL\Logging;
|
|||||||
*/
|
*/
|
||||||
interface SqlLogger
|
interface SqlLogger
|
||||||
{
|
{
|
||||||
public function logSql($sql, array $params = null);
|
function logSql($sql, array $params = null);
|
||||||
}
|
}
|
@ -39,8 +39,8 @@ class SingleTablePersister extends StandardEntityPersister
|
|||||||
parent::_prepareData($entity, $result, $isInsert);
|
parent::_prepareData($entity, $result, $isInsert);
|
||||||
// Populate the discriminator column
|
// Populate the discriminator column
|
||||||
if ($isInsert) {
|
if ($isInsert) {
|
||||||
$discColumn = $this->_class->discriminatorColumn;
|
$discColumn = $this->_class->getQuotedDiscriminatorColumnName($this->_platform);
|
||||||
$result[$this->_class->primaryTable['name']][$discColumn['name']] =
|
$result[$this->_class->getQuotedTableName($this->_platform)][$discColumn] =
|
||||||
$this->_class->discriminatorValue;
|
$this->_class->discriminatorValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -85,6 +85,8 @@ class StandardEntityPersister
|
|||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $_queuedInserts = array();
|
protected $_queuedInserts = array();
|
||||||
|
|
||||||
|
//protected $_rsm;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes a new instance of a class derived from AbstractEntityPersister
|
* Initializes a new instance of a class derived from AbstractEntityPersister
|
||||||
@ -484,7 +486,22 @@ class StandardEntityPersister
|
|||||||
|
|
||||||
$data = $joinColumnValues = array();
|
$data = $joinColumnValues = array();
|
||||||
|
|
||||||
|
/*if ($this->_rsm === null) {
|
||||||
|
$this->_rsm = array();
|
||||||
|
foreach ($this->_class->columnNames as $column) {
|
||||||
|
$this->_rsm[$this->_platform->getSqlResultCasing($column)] = $column;
|
||||||
|
}
|
||||||
|
foreach ($this->_class->associationMappings as $assoc) {
|
||||||
|
if ($assoc->isOwningSide && $assoc->isOneToOne()) {
|
||||||
|
foreach ($assoc->targetToSourceKeyColumns as $keyColumn) {
|
||||||
|
$this->_rsm[$this->_platform->getSqlResultCasing($keyColumn)] = $keyColumn;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
foreach ($result as $column => $value) {
|
foreach ($result as $column => $value) {
|
||||||
|
//$column = $this->_rsm[$column];
|
||||||
if (isset($this->_class->fieldNames[$column])) {
|
if (isset($this->_class->fieldNames[$column])) {
|
||||||
$fieldName = $this->_class->fieldNames[$column];
|
$fieldName = $this->_class->fieldNames[$column];
|
||||||
$data[$fieldName] = Type::getType($this->_class->fieldMappings[$fieldName]['type'])
|
$data[$fieldName] = Type::getType($this->_class->fieldMappings[$fieldName]['type'])
|
||||||
|
@ -631,7 +631,7 @@ class Parser
|
|||||||
$token = ($token) ?: $this->_lexer->lookahead;
|
$token = ($token) ?: $this->_lexer->lookahead;
|
||||||
|
|
||||||
if ( ! isset($this->_queryComponents[$identVariable])) {
|
if ( ! isset($this->_queryComponents[$identVariable])) {
|
||||||
$this->semanticalError("'$idVariable' is not defined", $token);
|
$this->semanticalError("'$identVariable' is not defined", $token);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate if identification variable nesting level is lower or equal than the current one
|
// Validate if identification variable nesting level is lower or equal than the current one
|
||||||
@ -1694,34 +1694,34 @@ class Parser
|
|||||||
public function ConditionalPrimary()
|
public function ConditionalPrimary()
|
||||||
{
|
{
|
||||||
$condPrimary = new AST\ConditionalPrimary;
|
$condPrimary = new AST\ConditionalPrimary;
|
||||||
|
|
||||||
if ($this->_lexer->isNextToken('(')) {
|
if ($this->_lexer->isNextToken('(')) {
|
||||||
// We need to inner inspect for a subselect (ArithmeticExpression)
|
// Peek beyond the matching closing paranthesis ')'
|
||||||
if ( ! $this->_isSubselect()) {
|
$numUnmatched = 1;
|
||||||
// Peek beyond and not until matching closing parenthesis
|
$peek = $this->_lexer->peek();
|
||||||
$peek = $this->_lexer->peek();
|
while ($numUnmatched > 0 && $peek !== null) {
|
||||||
$arithmeticOps = array("+", "-", "*", "/");
|
if ($peek['value'] == ')') {
|
||||||
$numUnmatched = 1;
|
--$numUnmatched;
|
||||||
|
} else if ($peek['value'] == '(') {
|
||||||
// While not found a closing matched parenthesis and a matched arithmetic operator
|
++$numUnmatched;
|
||||||
while ($numUnmatched > 0 && ! in_array($peek['value'], $arithmeticOps)) {
|
|
||||||
if ($peek['value'] == ')') {
|
|
||||||
--$numUnmatched;
|
|
||||||
} else if ($peek['value'] == '(') {
|
|
||||||
++$numUnmatched;
|
|
||||||
}
|
|
||||||
|
|
||||||
$peek = $this->_lexer->peek();
|
|
||||||
}
|
}
|
||||||
|
$peek = $this->_lexer->peek();
|
||||||
}
|
}
|
||||||
|
$this->_lexer->resetPeek();
|
||||||
// Check if unmatched parenthesis is > 0, then we found a matching arithmetic operator
|
|
||||||
if ($numUnmatched > 0) {
|
if (in_array($peek['value'], array("=", "<", "<=", "<>", ">", ">=", "!=")) ||
|
||||||
|
$peek['type'] === Lexer::T_NOT ||
|
||||||
|
$peek['type'] === Lexer::T_BETWEEN ||
|
||||||
|
$peek['type'] === Lexer::T_LIKE ||
|
||||||
|
$peek['type'] === Lexer::T_IN ||
|
||||||
|
$peek['type'] === Lexer::T_IS ||
|
||||||
|
$peek['type'] === Lexer::T_EXISTS) {
|
||||||
$condPrimary->simpleConditionalExpression = $this->SimpleConditionalExpression();
|
$condPrimary->simpleConditionalExpression = $this->SimpleConditionalExpression();
|
||||||
} else {
|
} else {
|
||||||
$this->match('(');
|
$this->match('(');
|
||||||
$condPrimary->conditionalExpression = $this->ConditionalExpression();
|
$conditionalExpression = $this->ConditionalExpression();
|
||||||
$this->match(')');
|
$this->match(')');
|
||||||
|
$condPrimary->conditionalExpression = $conditionalExpression;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$condPrimary->simpleConditionalExpression = $this->SimpleConditionalExpression();
|
$condPrimary->simpleConditionalExpression = $this->SimpleConditionalExpression();
|
||||||
@ -1961,7 +1961,7 @@ class Parser
|
|||||||
$terms[] = $this->_lexer->token['value'];
|
$terms[] = $this->_lexer->token['value'];
|
||||||
$terms[] = $this->ArithmeticTerm();
|
$terms[] = $this->ArithmeticTerm();
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AST\SimpleArithmeticExpression($terms);
|
return new AST\SimpleArithmeticExpression($terms);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2061,7 +2061,6 @@ class Parser
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* StringExpression ::= StringPrimary | "(" Subselect ")"
|
* StringExpression ::= StringPrimary | "(" Subselect ")"
|
||||||
|
@ -369,7 +369,7 @@ class UnitOfWork implements PropertyChangedListener
|
|||||||
public function computeChangeSets()
|
public function computeChangeSets()
|
||||||
{
|
{
|
||||||
// Compute changes for INSERTed entities first. This must always happen.
|
// Compute changes for INSERTed entities first. This must always happen.
|
||||||
foreach ($this->_entityInsertions as $oid => $entity) {
|
foreach ($this->_entityInsertions as $entity) {
|
||||||
$class = $this->_em->getClassMetadata(get_class($entity));
|
$class = $this->_em->getClassMetadata(get_class($entity));
|
||||||
$this->_computeEntityChanges($class, $entity);
|
$this->_computeEntityChanges($class, $entity);
|
||||||
// Look for changes in associations of the entity
|
// Look for changes in associations of the entity
|
||||||
@ -908,7 +908,6 @@ class UnitOfWork implements PropertyChangedListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->removeFromIdentityMap($entity);
|
$this->removeFromIdentityMap($entity);
|
||||||
$className = get_class($entity);
|
|
||||||
|
|
||||||
if (isset($this->_entityInsertions[$oid])) {
|
if (isset($this->_entityInsertions[$oid])) {
|
||||||
unset($this->_entityInsertions[$oid]);
|
unset($this->_entityInsertions[$oid]);
|
||||||
|
@ -383,6 +383,30 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testNestedExpressions()
|
||||||
|
{
|
||||||
|
$this->assertSqlGeneration(
|
||||||
|
"select u from Doctrine\Tests\Models\CMS\CmsUser u where u.id > 10 and u.id < 42 and ((u.id * 2) > 5)",
|
||||||
|
"SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_ WHERE c0_.id > 10 AND c0_.id < 42 AND ((c0_.id * 2) > 5)"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNestedExpressions2()
|
||||||
|
{
|
||||||
|
$this->assertSqlGeneration(
|
||||||
|
"select u from Doctrine\Tests\Models\CMS\CmsUser u where (u.id > 10) and (u.id < 42 and ((u.id * 2) > 5)) or u.id <> 42",
|
||||||
|
"SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_ WHERE (c0_.id > 10) AND (c0_.id < 42 AND ((c0_.id * 2) > 5)) OR c0_.id <> 42"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNestedExpressions3()
|
||||||
|
{
|
||||||
|
$this->assertSqlGeneration(
|
||||||
|
"select u from Doctrine\Tests\Models\CMS\CmsUser u where (u.id > 10) and (u.id between 1 and 10 or u.id in (1, 2, 3, 4, 5))",
|
||||||
|
"SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_ WHERE (c0_.id > 10) AND (c0_.id BETWEEN 1 AND 10 OR c0_.id IN (1, 2, 3, 4, 5))"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/* Not yet implemented, needs more thought
|
/* Not yet implemented, needs more thought
|
||||||
public function testSingleValuedAssociationFieldInWhere()
|
public function testSingleValuedAssociationFieldInWhere()
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user