Skip to content
Permalink
Browse files

Add default value support for SQLServer

Support the ANSI SQL 'CURRENT_TIMESTAMP' value, as well as custom
datetime values. We don't currently support any SQLServer specific
functions.

Refs #9850
  • Loading branch information...
markstory committed Dec 8, 2016
1 parent 5cd5edc commit 54ab52c4519772d0303c7391c0ca9d5b1c13cafb
Showing with 18 additions and 1 deletion.
  1. +8 −1 src/Database/Schema/SqlserverSchema.php
  2. +10 −0 tests/TestCase/Database/Schema/SqlserverSchemaTest.php
@@ -407,7 +407,14 @@ public function columnSql(Table $table, $name)
unset($data['default']);
}
if (isset($data['default']) && $data['type'] !== 'datetime') {
if (isset($data['default']) &&
in_array($data['type'], ['timestamp', 'datetime']) &&
strtolower($data['default']) === 'current_timestamp'
) {
$out .= ' DEFAULT CURRENT_TIMESTAMP';
unset($data['default']);
}
if (isset($data['default'])) {
$default = is_bool($data['default']) ? (int)$data['default'] : $this->_driver->schemaValue($data['default']);
$out .= ' DEFAULT ' . $default;
}
@@ -628,6 +628,16 @@ public static function columnSqlProvider()
['type' => 'datetime'],
'[created] DATETIME'
],
[
'open_date',
['type' => 'datetime', 'null' => false, 'default' => '2016-12-07 23:04:00'],
'[open_date] DATETIME NOT NULL DEFAULT \'2016-12-07 23:04:00\''
],
[
'open_date',
['type' => 'datetime', 'null' => false, 'default' => 'current_timestamp'],
'[open_date] DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP'
],
// Date & Time
[
'start_date',

0 comments on commit 54ab52c

Please sign in to comment.
You can’t perform that action at this time.