1
0
mirror of synced 2024-12-12 22:36:02 +03:00

[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:
romanb 2009-08-16 16:36:00 +00:00
parent ebb432bfb8
commit 32069cc2b5
6 changed files with 68 additions and 29 deletions

View File

@ -10,5 +10,5 @@ namespace Doctrine\DBAL\Logging;
*/
interface SqlLogger
{
public function logSql($sql, array $params = null);
function logSql($sql, array $params = null);
}

View File

@ -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;
}
}

View File

@ -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'])

View File

@ -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 ")"

View File

@ -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]);

View File

@ -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()
{