Commit bb2ffc4f authored by Benjamin Eberlei's avatar Benjamin Eberlei

DBAL-26 - Fix nasty bug with null values in Date, DateTime, DateTimeTz and...

DBAL-26 - Fix nasty bug with null values in Date, DateTime, DateTimeTz and Time fields introduced with the DBAL-22 fix
parent 1442262d
...@@ -46,8 +46,11 @@ class DateTimeType extends Type ...@@ -46,8 +46,11 @@ class DateTimeType extends Type
public function convertToPHPValue($value, AbstractPlatform $platform) public function convertToPHPValue($value, AbstractPlatform $platform)
{ {
$val = ($value !== null) if (!$value) {
? \DateTime::createFromFormat($platform->getDateTimeFormatString(), $value) : null; return $value;
}
$val = \DateTime::createFromFormat($platform->getDateTimeFormatString(), $value);
if (!$val) { if (!$val) {
throw ConversionException::conversionFailed($value, $this->getName()); throw ConversionException::conversionFailed($value, $this->getName());
} }
......
...@@ -66,8 +66,11 @@ class DateTimeTzType extends Type ...@@ -66,8 +66,11 @@ class DateTimeTzType extends Type
public function convertToPHPValue($value, AbstractPlatform $platform) public function convertToPHPValue($value, AbstractPlatform $platform)
{ {
$val = ($value !== null) if (!$value) {
? \DateTime::createFromFormat($platform->getDateTimeTzFormatString(), $value) : null; return $value;
}
$val = \DateTime::createFromFormat($platform->getDateTimeTzFormatString(), $value);
if (!$val) { if (!$val) {
throw ConversionException::conversionFailed($value, $this->getName()); throw ConversionException::conversionFailed($value, $this->getName());
} }
......
...@@ -46,8 +46,11 @@ class DateType extends Type ...@@ -46,8 +46,11 @@ class DateType extends Type
public function convertToPHPValue($value, AbstractPlatform $platform) public function convertToPHPValue($value, AbstractPlatform $platform)
{ {
$val = ($value !== null) if (!$value) {
? \DateTime::createFromFormat('!'.$platform->getDateFormatString(), $value) : null; return $value;
}
$val = \DateTime::createFromFormat('!'.$platform->getDateFormatString(), $value);
if (!$val) { if (!$val) {
throw ConversionException::conversionFailed($value, $this->getName()); throw ConversionException::conversionFailed($value, $this->getName());
} }
......
...@@ -55,8 +55,11 @@ class TimeType extends Type ...@@ -55,8 +55,11 @@ class TimeType extends Type
*/ */
public function convertToPHPValue($value, AbstractPlatform $platform) public function convertToPHPValue($value, AbstractPlatform $platform)
{ {
$val = ($value !== null) if (!$value) {
? \DateTime::createFromFormat($platform->getTimeFormatString(), $value) : null; return $value;
}
$val = \DateTime::createFromFormat($platform->getTimeFormatString(), $value);
if (!$val) { if (!$val) {
throw ConversionException::conversionFailed($value, $this->getName()); throw ConversionException::conversionFailed($value, $this->getName());
} }
......
...@@ -67,4 +67,9 @@ class DateTest extends \Doctrine\Tests\DbalTestCase ...@@ -67,4 +67,9 @@ class DateTest extends \Doctrine\Tests\DbalTestCase
$this->setExpectedException('Doctrine\DBAL\Types\ConversionException'); $this->setExpectedException('Doctrine\DBAL\Types\ConversionException');
$this->_type->convertToPHPValue('abcdefg', $this->_platform); $this->_type->convertToPHPValue('abcdefg', $this->_platform);
} }
public function testNullConversion()
{
$this->assertNull($this->_type->convertToPHPValue(null, $this->_platform));
}
} }
\ No newline at end of file
...@@ -42,4 +42,9 @@ class DateTimeTest extends \Doctrine\Tests\DbalTestCase ...@@ -42,4 +42,9 @@ class DateTimeTest extends \Doctrine\Tests\DbalTestCase
$this->setExpectedException('Doctrine\DBAL\Types\ConversionException'); $this->setExpectedException('Doctrine\DBAL\Types\ConversionException');
$this->_type->convertToPHPValue('abcdefg', $this->_platform); $this->_type->convertToPHPValue('abcdefg', $this->_platform);
} }
public function testNullConversion()
{
$this->assertNull($this->_type->convertToPHPValue(null, $this->_platform));
}
} }
\ No newline at end of file
...@@ -42,4 +42,9 @@ class DateTimeTzTest extends \Doctrine\Tests\DbalTestCase ...@@ -42,4 +42,9 @@ class DateTimeTzTest extends \Doctrine\Tests\DbalTestCase
$this->setExpectedException('Doctrine\DBAL\Types\ConversionException'); $this->setExpectedException('Doctrine\DBAL\Types\ConversionException');
$this->_type->convertToPHPValue('abcdefg', $this->_platform); $this->_type->convertToPHPValue('abcdefg', $this->_platform);
} }
public function testNullConversion()
{
$this->assertNull($this->_type->convertToPHPValue(null, $this->_platform));
}
} }
\ No newline at end of file
...@@ -39,4 +39,9 @@ class TimeTest extends \Doctrine\Tests\DbalTestCase ...@@ -39,4 +39,9 @@ class TimeTest extends \Doctrine\Tests\DbalTestCase
$this->setExpectedException('Doctrine\DBAL\Types\ConversionException'); $this->setExpectedException('Doctrine\DBAL\Types\ConversionException');
$this->_type->convertToPHPValue('abcdefg', $this->_platform); $this->_type->convertToPHPValue('abcdefg', $this->_platform);
} }
public function testNullConversion()
{
$this->assertNull($this->_type->convertToPHPValue(null, $this->_platform));
}
} }
\ No newline at end of file
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