Commit 7386b2cc authored by Marco Pivetta's avatar Marco Pivetta

Merge branch 'hotfix/#662-datetime-tz-default-value-support'

Close #662
parents c1c33531 7a33aa26
......@@ -2239,9 +2239,9 @@ abstract class AbstractPlatform
if (isset($field['default'])) {
$default = " DEFAULT '".$field['default']."'";
if (isset($field['type'])) {
if (in_array((string)$field['type'], array("Integer", "BigInteger", "SmallInteger"))) {
if (in_array((string) $field['type'], array("Integer", "BigInteger", "SmallInteger"))) {
$default = " DEFAULT ".$field['default'];
} elseif ((string)$field['type'] == 'DateTime' && $field['default'] == $this->getCurrentTimestampSQL()) {
} elseif (in_array((string) $field['type'], array('DateTime', 'DateTimeTz')) && $field['default'] == $this->getCurrentTimestampSQL()) {
$default = " DEFAULT ".$this->getCurrentTimestampSQL();
} elseif ((string)$field['type'] == 'Time' && $field['default'] == $this->getCurrentTimeSQL()) {
$default = " DEFAULT ".$this->getCurrentTimeSQL();
......
......@@ -1458,7 +1458,7 @@ class SQLServerPlatform extends AbstractPlatform
return " DEFAULT " . $field['default'];
}
if ((string) $field['type'] == 'DateTime' && $field['default'] == $this->getCurrentTimestampSQL()) {
if (in_array((string) $field['type'], array('DateTime', 'DateTimeTz')) && $field['default'] == $this->getCurrentTimestampSQL()) {
return " DEFAULT " . $this->getCurrentTimestampSQL();
}
......
......@@ -440,6 +440,32 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
$this->markTestSkipped('Platform does not support Column comments.');
}
public function testGetDefaultValueDeclarationSQL()
{
// non-timestamp value will get single quotes
$field = array(
'type' => 'string',
'default' => 'non_timestamp'
);
$this->assertEquals(" DEFAULT 'non_timestamp'", $this->_platform->getDefaultValueDeclarationSQL($field));
}
public function testGetDefaultValueDeclarationSQLDateTime()
{
// timestamps on datetime types should not be quoted
foreach (array('datetime', 'datetimetz') as $type) {
$field = array(
'type' => Type::getType($type),
'default' => $this->_platform->getCurrentTimestampSQL()
);
$this->assertEquals(' DEFAULT ' . $this->_platform->getCurrentTimestampSQL(), $this->_platform->getDefaultValueDeclarationSQL($field));
}
}
/**
* @group DBAL-45
*/
......
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