diff --git a/lib/Doctrine/DBAL/Logging/SqlLogger.php b/lib/Doctrine/DBAL/Logging/SqlLogger.php index e06b4a259..9ce9bd4f5 100644 --- a/lib/Doctrine/DBAL/Logging/SqlLogger.php +++ b/lib/Doctrine/DBAL/Logging/SqlLogger.php @@ -10,5 +10,5 @@ namespace Doctrine\DBAL\Logging; */ interface SqlLogger { - public function logSql($sql, array $params = null); + function logSql($sql, array $params = null); } \ No newline at end of file diff --git a/lib/Doctrine/ORM/Persisters/SingleTablePersister.php b/lib/Doctrine/ORM/Persisters/SingleTablePersister.php index d709d5732..e9abb23be 100644 --- a/lib/Doctrine/ORM/Persisters/SingleTablePersister.php +++ b/lib/Doctrine/ORM/Persisters/SingleTablePersister.php @@ -39,8 +39,8 @@ class SingleTablePersister extends StandardEntityPersister parent::_prepareData($entity, $result, $isInsert); // Populate the discriminator column if ($isInsert) { - $discColumn = $this->_class->discriminatorColumn; - $result[$this->_class->primaryTable['name']][$discColumn['name']] = + $discColumn = $this->_class->getQuotedDiscriminatorColumnName($this->_platform); + $result[$this->_class->getQuotedTableName($this->_platform)][$discColumn] = $this->_class->discriminatorValue; } } diff --git a/lib/Doctrine/ORM/Persisters/StandardEntityPersister.php b/lib/Doctrine/ORM/Persisters/StandardEntityPersister.php index adcbca924..09cbedcb4 100644 --- a/lib/Doctrine/ORM/Persisters/StandardEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/StandardEntityPersister.php @@ -85,6 +85,8 @@ class StandardEntityPersister * @var array */ protected $_queuedInserts = array(); + + //protected $_rsm; /** * Initializes a new instance of a class derived from AbstractEntityPersister @@ -484,7 +486,22 @@ class StandardEntityPersister $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) { + //$column = $this->_rsm[$column]; if (isset($this->_class->fieldNames[$column])) { $fieldName = $this->_class->fieldNames[$column]; $data[$fieldName] = Type::getType($this->_class->fieldMappings[$fieldName]['type']) diff --git a/lib/Doctrine/ORM/Query/Parser.php b/lib/Doctrine/ORM/Query/Parser.php index 97f47f1cd..0d56b8510 100644 --- a/lib/Doctrine/ORM/Query/Parser.php +++ b/lib/Doctrine/ORM/Query/Parser.php @@ -631,7 +631,7 @@ class Parser $token = ($token) ?: $this->_lexer->lookahead; 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 @@ -1694,34 +1694,34 @@ class Parser public function ConditionalPrimary() { $condPrimary = new AST\ConditionalPrimary; - + if ($this->_lexer->isNextToken('(')) { - // We need to inner inspect for a subselect (ArithmeticExpression) - if ( ! $this->_isSubselect()) { - // Peek beyond and not until matching closing parenthesis - $peek = $this->_lexer->peek(); - $arithmeticOps = array("+", "-", "*", "/"); - $numUnmatched = 1; - - // While not found a closing matched parenthesis and a matched arithmetic operator - while ($numUnmatched > 0 && ! in_array($peek['value'], $arithmeticOps)) { - if ($peek['value'] == ')') { - --$numUnmatched; - } else if ($peek['value'] == '(') { - ++$numUnmatched; - } - - $peek = $this->_lexer->peek(); + // Peek beyond the matching closing paranthesis ')' + $numUnmatched = 1; + $peek = $this->_lexer->peek(); + while ($numUnmatched > 0 && $peek !== null) { + if ($peek['value'] == ')') { + --$numUnmatched; + } else if ($peek['value'] == '(') { + ++$numUnmatched; } + $peek = $this->_lexer->peek(); } - - // Check if unmatched parenthesis is > 0, then we found a matching arithmetic operator - if ($numUnmatched > 0) { + $this->_lexer->resetPeek(); + + 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(); } else { $this->match('('); - $condPrimary->conditionalExpression = $this->ConditionalExpression(); + $conditionalExpression = $this->ConditionalExpression(); $this->match(')'); + $condPrimary->conditionalExpression = $conditionalExpression; } } else { $condPrimary->simpleConditionalExpression = $this->SimpleConditionalExpression(); @@ -1961,7 +1961,7 @@ class Parser $terms[] = $this->_lexer->token['value']; $terms[] = $this->ArithmeticTerm(); } - + return new AST\SimpleArithmeticExpression($terms); } @@ -2061,7 +2061,6 @@ class Parser break; } } - /** * StringExpression ::= StringPrimary | "(" Subselect ")" diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index e098831ea..5fd7c9ca4 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -369,7 +369,7 @@ class UnitOfWork implements PropertyChangedListener public function computeChangeSets() { // 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)); $this->_computeEntityChanges($class, $entity); // Look for changes in associations of the entity @@ -908,7 +908,6 @@ class UnitOfWork implements PropertyChangedListener } $this->removeFromIdentityMap($entity); - $className = get_class($entity); if (isset($this->_entityInsertions[$oid])) { unset($this->_entityInsertions[$oid]); diff --git a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php index 4ba78ce6f..182c0d441 100644 --- a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php +++ b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php @@ -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 public function testSingleValuedAssociationFieldInWhere() {