Fixed default values being declared for integer column types when default = ''. Closes #5244

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7464 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
mark_story 2008-08-14 00:33:44 +00:00
parent 074ede4639
commit 9cb854b48e
2 changed files with 16 additions and 0 deletions

View file

@ -2324,6 +2324,11 @@ class DboSource extends DataSource {
}
$out .= '(' . $length . ')';
}
if (($column['type'] == 'integer' || $column['type'] == 'float' ) && isset($column['default']) && $column['default'] === '') {
$column['default'] = null;
}
if (isset($column['key']) && $column['key'] == 'primary' && $type == 'integer') {
$out .= ' ' . $this->columns['primary_key']['name'];
} elseif (isset($column['key']) && $column['key'] == 'primary') {

View file

@ -3313,6 +3313,17 @@ class DboSourceTest extends CakeTestCase {
$result = $this->testDb->buildColumn($data);
$expected = '`testName` DEFAULT NULL';
$this->assertEqual($result, $expected);
$data = array(
'name' => 'int_field',
'type' => 'integer',
'default' => '',
'null' => false,
);
$this->testDb->columns = array('integer' => array('name' => 'int', 'limit' => '11', 'formatter' => 'intval'), );
$result = $this->testDb->buildColumn($data);
$expected = '`int_field` int(11) NOT NULL';
$this->assertTrue($result, $expected);
}
/**
* testIntrospectType method