mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-09-20 00:16:55 +02:00
53f2f7a873
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@102460 467b73ca-7a2a-4603-9d3b-597d59a354a9
51 lines
1.1 KiB
PHP
51 lines
1.1 KiB
PHP
<?php
|
|
/**
|
|
*
|
|
* @package sapphire
|
|
* @subpackage model
|
|
*/
|
|
class Double extends DBField {
|
|
|
|
function requireField() {
|
|
|
|
// HACK: MSSQL does not support double so we're usinf float instead
|
|
// @todo This should go into MSSQLDatabase ideally somehow
|
|
if(DB::getConn() instanceof MySQLDatabase) {
|
|
DB::requireField($this->tableName, $this->name, "double");
|
|
} else {
|
|
DB::requireField($this->tableName, $this->name, "float");
|
|
}
|
|
}
|
|
|
|
function Nice() {
|
|
return number_format($this->value, 2);
|
|
}
|
|
|
|
/**
|
|
* Returns the value to be set in the database to blank this field.
|
|
* Usually it's a choice between null, 0, and ''
|
|
*/
|
|
function nullValue() {
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* Return an encoding of the given value suitable for inclusion in a SQL statement.
|
|
* If necessary, this should include quotes.
|
|
*/
|
|
function prepValueForDB($value) {
|
|
if($value === true) {
|
|
return 1;
|
|
}
|
|
if(!$value || !is_numeric($value)) {
|
|
if(strpos($value, '[') === false) {
|
|
return '0';
|
|
} else {
|
|
return Convert::raw2sql($value);
|
|
}
|
|
} else {
|
|
return Convert::raw2sql($value);
|
|
}
|
|
}
|
|
|
|
} |