Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix default null not being reflected by SqlServer

Apply patch from 'Josh Rehm' to fix null default values from being
stomped on when reflecting table schema.

Fixes #3615
  • Loading branch information...
commit 729ef8fe58b98a0b0ab96ae25b7aa55b061f2516 1 parent b821505
@markstory markstory authored
View
10 lib/Cake/Model/Datasource/Database/Sqlserver.php
@@ -216,14 +216,20 @@ public function describe($model) {
$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']);
}
View
20 lib/Cake/Test/Case/Model/Datasource/Database/SqlserverTest.php
@@ -448,7 +448,16 @@ public function testDescribe() {
'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 @@ public function testDescribe() {
'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']);
}
/**

0 comments on commit 729ef8f

Please sign in to comment.
Something went wrong with that request. Please try again.