Commit de2318dc authored by Benjamin Eberlei's avatar Benjamin Eberlei

DBAL-15 - Add methods for SQL function conversion of types between PHP and...

DBAL-15 - Add methods for SQL function conversion of types between PHP and database. Implementation inside ORM would now be necessary.
parent 9cd6df38
<?php <?php
/* /*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
...@@ -30,6 +28,7 @@ use Doctrine\DBAL\Platforms\AbstractPlatform, ...@@ -30,6 +28,7 @@ use Doctrine\DBAL\Platforms\AbstractPlatform,
* A Type object is obtained by calling the static {@link getType()} method. * A Type object is obtained by calling the static {@link getType()} method.
* *
* @author Roman Borschel <roman@code-factory.org> * @author Roman Borschel <roman@code-factory.org>
* @author Benjamin Eberlei <kontakt@beberlei.de>
* @since 2.0 * @since 2.0
*/ */
abstract class Type abstract class Type
...@@ -227,4 +226,43 @@ abstract class Type ...@@ -227,4 +226,43 @@ abstract class Type
$e = explode('\\', get_class($this)); $e = explode('\\', get_class($this));
return str_replace('Type', '', end($e)); return str_replace('Type', '', end($e));
} }
/**
* Does working with this column require SQL conversion functions?
*
* This is a metadata function that is required for example in the ORM.
* Usage of {@link convertToDatabaseValueSQL} and
* {@link convertToPHPValueSQL} works for any type and mostly
* does nothing. This method can additionally be used for optimization purposes.
*
* @return bool
*/
public function canRequireSQLConversion()
{
return false;
}
/**
* Modifies the SQL expression (identifier, parameter) to convert to a database value.
*
* @param string $sqlExpr
* @param AbstractPlatform $platform
* @return string
*/
public function convertToDatabaseValueSQL($sqlExpr, AbstractPlatform $platform)
{
return $sqlExpr;
}
/**
* Modifies the SQL expression (identifier, parameter) to convert to a PHP value.
*
* @param string $sqlExpr
* @param AbstractPlatform $platform
* @return string
*/
public function convertToPHPValueSQL($sqlExpr, $platform)
{
return $sqlExpr;
}
} }
\ No newline at end of file
...@@ -39,4 +39,11 @@ class StringTest extends \Doctrine\Tests\DbalTestCase ...@@ -39,4 +39,11 @@ class StringTest extends \Doctrine\Tests\DbalTestCase
{ {
$this->assertNull($this->_type->convertToPHPValue(null, $this->_platform)); $this->assertNull($this->_type->convertToPHPValue(null, $this->_platform));
} }
public function testSQLConversion()
{
$this->assertFalse($this->_type->canRequireSQLConversion(), "String type can never require SQL conversion to work.");
$this->assertEquals('t.foo', $this->_type->convertToDatabaseValueSQL('t.foo', $this->_platform));
$this->assertEquals('t.foo', $this->_type->convertToPHPValueSQL('t.foo', $this->_platform));
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment