Remove sql conversion from where clauses and update statements
This commit is contained in:
parent
4042bc53ce
commit
16aa558292
@ -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 @@ class SqlWalker implements TreeWalker
|
||||
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 @@ class SqlWalker implements TreeWalker
|
||||
$dqlAlias = $pathExpr->identificationVariable;
|
||||
$class = $this->_queryComponents[$dqlAlias]['metadata'];
|
||||
|
||||
$column = '';
|
||||
|
||||
if ($this->_useSqlTableAliases) {
|
||||
$column .= $this->walkIdentificationVariable($dqlAlias, $fieldName) . '.';
|
||||
$sql .= $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 .= $column;
|
||||
$sql .= $class->getQuotedColumnName($fieldName, $this->_platform);
|
||||
break;
|
||||
|
||||
case AST\PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION:
|
||||
@ -1429,18 +1408,7 @@ class SqlWalker implements TreeWalker
|
||||
|
||||
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 @@ class SqlWalker implements TreeWalker
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -29,6 +29,6 @@ class NegativeToPositiveType extends Type
|
||||
|
||||
public function convertToPHPValueSQL($sqlExpr, $platform)
|
||||
{
|
||||
return '((' . $sqlExpr . ') * -1)';
|
||||
return '-(' . $sqlExpr . ')';
|
||||
}
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ class TypeValueSqlTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
$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 @@ class TypeValueSqlTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
|
||||
$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']);
|
||||
|
||||
|
@ -1345,7 +1345,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
|
||||
|
||||
$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 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
|
||||
|
||||
$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_'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -195,19 +195,11 @@ class UpdateSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
|
||||
);
|
||||
}
|
||||
|
||||
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'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user