Merge pull request #4731 from tractorcow/pulls/3.2/fix-numeric-regeneration

BUG Prevent dev/build continually regenerating Number field type
This commit is contained in:
Daniel Hensby 2015-11-10 23:06:18 +00:00
commit 46eaee5be1
2 changed files with 10 additions and 3 deletions

View File

@ -407,15 +407,17 @@ class MySQLSchemaManager extends DBSchemaManager {
$precision = $values['precision'];
}
$defaultValue = '';
// Fix format of default value to match precision
if (isset($values['default']) && is_numeric($values['default'])) {
$decs = strpos($precision, ',') !== false
? (int) substr($precision, strpos($precision, ',') + 1)
: 0;
$defaultValue = ' default ' . number_format($values['default'], $decs, '.', '');
$values['default'] = number_format($values['default'], $decs, '.', '');
} else {
unset($values['default']);
}
return "decimal($precision) not null $defaultValue";
return "decimal($precision) not null" . $this->defaultClause($values);
}
/**

View File

@ -178,6 +178,11 @@ class DataObjectSchemaGenerationTest_DO extends DataObject implements TestOnly {
private static $db = array(
'Enum1' => 'Enum("A, B, C, D","")',
'Enum2' => 'Enum("A, B, C, D","A")',
'NumberField' => 'Decimal',
'FloatingField' => 'Decimal(10,3,1.1)',
'TextValue' => 'Varchar',
'Date' => 'SS_Datetime',
'MyNumber' => 'Int'
);
}