Hi,
I've noticed that a couple of Decimal fields now always are highlighted as changing/being updated every time I do a dev/build.
They are 2 fields from Geocodable.php - Lat/Lng which I changed a while ago from from Floats to Decimal(9,6)
Current Code:
public function extraStatics() {
return array('db' => array(
'Lat' => 'Decimal(9,6)',
'Lng' => 'Decimal(9,6)'
));
}
Old code:
public function extraStatics() {
return array('db' => array(
'Lat' => 'Float',
'Lng' => 'Float
));
}
Since that change, every time I do a dev/build I get the following output from the build:
Building database mydb_ss using MySQL 5.5.9
Creating database tables
PageComment
SiteConfig
Field SiteConfig.Lat: changed to decimal(9,6) not null default 0 (from decimal(9,6) not null default 0.000000)
Field SiteConfig.Lng: changed to decimal(9,6) not null default 0 (from decimal(9,6) not null default 0.000000)
SiteTree
<snip>
Database build completed!
Note that I haven't change the DB Field types between rebuilds.
After a bit of investigation - I've found that the problem might be in Decimal.php. The way the field is created, it appears to be passing in a double where it was requiring a string equivalent of $defaultField in the requireField(...) method. So there is always a discrepancy between the DB's default value for the Decimal(9,6) field (0.000000) and what it is being compared with in Sapphire which defaults to "0".
The code that seems to work:
<?php
/**
* Represents a Decimal field.
* @package sapphire
* @subpackage model
*/
class Decimal extends DBField {
protected $wholeSize, $decimalSize, $defaultValue;
<snip>
function requireField() {
$beforeDecimal = $this->wholeSize - $this->decimalSize;
$formatString = "%" . $beforeDecimal . "." . $this->decimalSize . "f";
$defaultStr = sprintf($formatString, $this->defaultValue);
$parts=Array('datatype'=>'decimal', 'precision'=>"$this->wholeSize,$this->decimalSize", 'default'=>$defaultStr, 'arrayValue'=>$this->arrayValue);
$values=Array('type'=>'decimal', 'parts'=>$parts);
DB::requireField($this->tableName, $this->name, $values);
}
<snip>
public function nullValue() {
$beforeDecimal = $this->wholeSize - $this->decimalSize;
$formatString = "%" . $beforeDecimal . "." . $this->decimalSize . "f";
$nullValueStr = sprintf($formatString, (double)0);
return $nullValueStr;
}
<snip>
?>
So is this a genuine bug that needs to be reported? I'm trying to get the unit tests running to see if this change has broken anything else.
Thanks,
VWD.