Version: current

     1 <?php
     2 /**
     3  *
     4  * @package sapphire
     5  * @subpackage model
     6  */
     7 class Double extends DBField {
     8
     9     function requireField() {
    10
    11         // HACK: MSSQL does not support double so we're usinf float instead
    12         // @todo This should go into MSSQLDatabase ideally somehow
    13         if(DB::getConn() instanceof MySQLDatabase) {
    14             DB::requireField($this->tableName, $this->name, "double");
    15         } else {
    16             DB::requireField($this->tableName, $this->name, "float");
    17         }
    18     }
    19
    20     function Nice() {
    21         return number_format($this->value, 2);
    22     }
    23
    24     /**
    25      * Returns the value to be set in the database to blank this field.
    26      * Usually it's a choice between null, 0, and ''
    27      */
    28     function nullValue() {
    29         return 0;
    30     }
    31
    32     /**
    33      * Return an encoding of the given value suitable for inclusion in a SQL statement.
    34      * If necessary, this should include quotes.
    35      */
    36     function prepValueForDB($value) {
    37         if($value === true) {
    38             return 1;
    39         }
    40         if(!$value || !is_numeric($value)) {
    41             if(strpos($value, '[') === false) {
    42                 return '0';
    43             } else {
    44                 return Convert::raw2sql($value);
    45             }
    46         } else {
    47             return Convert::raw2sql($value);
    48         }
    49     }
    50
    51 }

[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -