mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
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
This commit is contained in:
parent
b821505014
commit
729ef8fe58
2 changed files with 26 additions and 4 deletions
|
@ -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']);
|
||||
}
|
||||
|
||||
|
|
|
@ -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']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue