diff --git a/lib/Cake/Model/Datasource/Database/Sqlserver.php b/lib/Cake/Model/Datasource/Database/Sqlserver.php index 92f133674..941630c6c 100644 --- a/lib/Cake/Model/Datasource/Database/Sqlserver.php +++ b/lib/Cake/Model/Datasource/Database/Sqlserver.php @@ -216,14 +216,20 @@ class Sqlserver extends DboSource { $fields[$field] = array( 'type' => $this->column($column), 'null' => ($column->Null === 'YES' ? true : false), - 'default' => preg_replace("/^[(]{1,2}'?([^')]*)?'?[)]{1,2}$/", "$1", $column->Default), + 'default' => $column->Default, 'length' => $this->length($column), 'key' => ($column->Key == '1') ? 'primary' : false ); if ($fields[$field]['default'] === 'null') { $fields[$field]['default'] = null; - } else { + } + if ($fields[$field]['default'] !== null) { + $fields[$field]['default'] = preg_replace( + "/^[(]{1,2}'?([^')]*)?'?[)]{1,2}$/", + "$1", + $fields[$field]['default'] + ); $this->value($fields[$field]['default'], $fields[$field]['type']); } diff --git a/lib/Cake/Test/Case/Model/Datasource/Database/SqlserverTest.php b/lib/Cake/Test/Case/Model/Datasource/Database/SqlserverTest.php index 4c5fe5699..e2611699d 100644 --- a/lib/Cake/Test/Case/Model/Datasource/Database/SqlserverTest.php +++ b/lib/Cake/Test/Case/Model/Datasource/Database/SqlserverTest.php @@ -448,7 +448,16 @@ class SqlserverTest extends CakeTestCase { 'Length' => 72, 'Null' => 'NO', 'Size' => '' - ) + ), + (object)array( + 'Default' => null, + 'Field' => 'parent_id', + 'Key' => '0', + 'Type' => 'bigint', + 'Length' => 8, + 'Null' => 'YES', + 'Size' => '0', + ), )); $this->db->executeResultsStack = array($SqlserverTableDescription); $dummyModel = $this->model; @@ -478,9 +487,16 @@ class SqlserverTest extends CakeTestCase { 'default' => '', 'length' => 36, 'key' => 'primary' - ) + ), + 'parent_id' => array( + 'type' => 'biginteger', + 'null' => true, + 'default' => null, + 'length' => 8, + ), ); $this->assertEquals($expected, $result); + $this->assertSame($expected['parent_id'], $result['parent_id']); } /**