Skip to content
Browse files

Remove sql conversion from where clauses and update statements

  • Loading branch information...
1 parent 4042bc5 commit 16aa558292d8513c27add2dd7ed0574b3d6820db @jsor jsor committed
View
52 lib/Doctrine/ORM/Query/SqlWalker.php
@@ -97,17 +97,6 @@ class SqlWalker implements TreeWalker
* These should only be generated for SELECT queries, not for UPDATE/DELETE.
*/
private $_useSqlTableAliases = true;
-
- /**
- * Flag that indicates whether to pass columns through Type::convertToPHPValueSQL().
- * These should only be done for SELECT queries, not for UPDATE.
- */
- private $_useDbalTypeValueSql = true;
-
- /**
- * Holds the current columns type.
- */
- private $_currentColumnType;
/**
* The database platform abstraction.
@@ -421,7 +410,6 @@ public function walkSelectStatement(AST\SelectStatement $AST)
public function walkUpdateStatement(AST\UpdateStatement $AST)
{
$this->_useSqlTableAliases = false;
- $this->_useDbalTypeValueSql = false;
return $this->walkUpdateClause($AST->updateClause) . $this->walkWhereClause($AST->whereClause);
}
@@ -477,20 +465,11 @@ public function walkPathExpression($pathExpr)
$dqlAlias = $pathExpr->identificationVariable;
$class = $this->_queryComponents[$dqlAlias]['metadata'];
- $column = '';
-
if ($this->_useSqlTableAliases) {
- $column .= $this->walkIdentificationVariable($dqlAlias, $fieldName) . '.';
- }
-
- $column .= $class->getQuotedColumnName($fieldName, $this->_platform);
-
- if ($this->_useDbalTypeValueSql && isset($class->fieldMappings[$fieldName]['requireSQLConversion'])) {
- $type = Type::getType($class->getTypeOfField($fieldName));
- $column = $type->convertToPHPValueSQL($column, $this->_conn->getDatabasePlatform());
+ $sql .= $this->walkIdentificationVariable($dqlAlias, $fieldName) . '.';
}
- $sql .= $column;
+ $sql .= $class->getQuotedColumnName($fieldName, $this->_platform);
break;
case AST\PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION:
@@ -1429,18 +1408,7 @@ public function walkUpdateItem($updateItem)
switch (true) {
case ($newValue instanceof AST\Node):
- $currentColumnTypeBefore = $this->_currentColumnType;
- $this->_currentColumnType = null;
-
- if ($updateItem->pathExpression->type == AST\PathExpression::TYPE_STATE_FIELD) {
- $class = $this->_queryComponents[$updateItem->pathExpression->identificationVariable]['metadata'];
- if (isset($class->fieldMappings[$updateItem->pathExpression->field]['requireSQLConversion'])) {
- $this->_currentColumnType = $class->getTypeOfField($updateItem->pathExpression->field);
- }
- }
-
$sql .= $newValue->dispatch($this);
- $this->_currentColumnType = $currentColumnTypeBefore;
break;
case ($newValue === null):
@@ -1813,30 +1781,20 @@ public function walkLiteral($literal)
{
switch ($literal->type) {
case AST\Literal::STRING:
- $value = $this->_conn->quote($literal->value);
- break;
+ return $this->_conn->quote($literal->value);
case AST\Literal::BOOLEAN:
$bool = strtolower($literal->value) == 'true' ? true : false;
$boolVal = $this->_conn->getDatabasePlatform()->convertBooleans($bool);
- $value = $boolVal;
- break;
+ return $boolVal;
case AST\Literal::NUMERIC:
- $value = $literal->value;
- break;
+ return $literal->value;
default:
throw QueryException::invalidLiteral($literal);
}
-
- if ($this->_currentColumnType !== null) {
- $type = Type::getType($this->_currentColumnType);
- $value = $type->convertToDatabaseValueSQL($value, $this->_conn->getDatabasePlatform());
- }
-
- return $value;
}
/**
View
2 tests/Doctrine/Tests/DbalTypes/NegativeToPositiveType.php
@@ -29,6 +29,6 @@ public function convertToDatabaseValueSQL($sqlExpr, AbstractPlatform $platform)
public function convertToPHPValueSQL($sqlExpr, $platform)
{
- return '((' . $sqlExpr . ') * -1)';
+ return '-(' . $sqlExpr . ')';
}
}
View
5 tests/Doctrine/Tests/ORM/Functional/TypeValueSqlTest.php
@@ -46,7 +46,7 @@ public function testUpperCaseStringType()
$this->assertEquals('foo', $entity->lowerCaseString, 'Entity holds lowercase string');
$this->assertEquals('FOO', $this->_em->getConnection()->fetchColumn("select lowerCaseString from customtype_uppercases where id=".$entity->id.""), 'Database holds uppercase string');
}
-
+
public function testTypeValueSqlWithAssociations()
{
$parent = new CustomTypeParent();
@@ -90,12 +90,13 @@ public function testSelectDQL()
$this->_em->clear();
- $query = $this->_em->createQuery("SELECT p, p.customInteger, c from Doctrine\Tests\Models\CustomType\CustomTypeParent p JOIN p.child c where p.id = " . $parentId . " AND p.customInteger = -1");
+ $query = $this->_em->createQuery("SELECT p, p.customInteger, c from Doctrine\Tests\Models\CustomType\CustomTypeParent p JOIN p.child c where p.id = " . $parentId);
$result = $query->getResult();
$this->assertEquals(1, count($result));
$this->assertInstanceOf('Doctrine\Tests\Models\CustomType\CustomTypeParent', $result[0][0]);
+ $this->assertEquals(-1, $result[0][0]->customInteger);
$this->assertEquals(-1, $result[0]['customInteger']);
View
18 tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php
@@ -1345,7 +1345,7 @@ public function testCustomTypeValueSql()
$this->assertSqlGeneration(
'SELECT p.customInteger FROM Doctrine\Tests\Models\CustomType\CustomTypeParent p WHERE p.id = 1',
- 'SELECT ((c0_.customInteger) * -1) AS customInteger0 FROM customtype_parents c0_ WHERE c0_.id = 1'
+ 'SELECT -(c0_.customInteger) AS customInteger0 FROM customtype_parents c0_ WHERE c0_.id = 1'
);
}
@@ -1373,7 +1373,21 @@ public function testCustomTypeValueSqlForAllFields()
$this->assertSqlGeneration(
'SELECT p FROM Doctrine\Tests\Models\CustomType\CustomTypeParent p',
- 'SELECT c0_.id AS id0, ((c0_.customInteger) * -1) AS customInteger1 FROM customtype_parents c0_'
+ 'SELECT c0_.id AS id0, -(c0_.customInteger) AS customInteger1 FROM customtype_parents c0_'
+ );
+ }
+
+ public function testCustomTypeValueSqlForPartialObject()
+ {
+ if (DBALType::hasType('negative_to_positive')) {
+ DBALType::overrideType('negative_to_positive', 'Doctrine\Tests\DbalTypes\NegativeToPositiveType');
+ } else {
+ DBALType::addType('negative_to_positive', 'Doctrine\Tests\DbalTypes\NegativeToPositiveType');
+ }
+
+ $this->assertSqlGeneration(
+ 'SELECT partial p.{id, customInteger} FROM Doctrine\Tests\Models\CustomType\CustomTypeParent p',
+ 'SELECT c0_.id AS id0, -(c0_.customInteger) AS customInteger1 FROM customtype_parents c0_'
);
}
}
View
12 tests/Doctrine/Tests/ORM/Query/UpdateSqlGenerationTest.php
@@ -195,19 +195,11 @@ public function testSubselectTableAliasReferencing()
);
}
- public function testCustomTypeValueSql()
+ public function testCustomTypeValueSqlCompletelyIgnoredInUpdateStatements()
{
$this->assertSqlGeneration(
'UPDATE Doctrine\Tests\Models\CustomType\CustomTypeParent p SET p.customInteger = 1 WHERE p.id = 1',
- 'UPDATE customtype_parents SET customInteger = ABS(1) WHERE id = 1'
- );
- }
-
- public function testCustomTypeValueSqlIgnoresIdentifierColumns()
- {
- $this->assertSqlGeneration(
- 'UPDATE Doctrine\Tests\Models\CustomType\CustomTypeParent p SET p.id = 2 WHERE p.id = 1',
- 'UPDATE customtype_parents SET id = 2 WHERE id = 1'
+ 'UPDATE customtype_parents SET customInteger = 1 WHERE id = 1'
);
}
}

0 comments on commit 16aa558

Please sign in to comment.
Something went wrong with that request. Please try again.