Decimal support for MySQL. #3171

This commit is contained in:
U-Zyn Chua 2013-09-28 09:23:46 +08:00
parent cc5795c67d
commit 7fb51ab50f
2 changed files with 10 additions and 2 deletions

View file

@ -112,6 +112,7 @@ class Mysql extends DboSource {
'biginteger' => array('name' => 'bigint', 'limit' => '20'),
'integer' => array('name' => 'int', 'limit' => '11', 'formatter' => 'intval'),
'float' => array('name' => 'float', 'formatter' => 'floatval'),
'decimal' => array('name' => 'decimal', 'formatter' => 'floatval'),
'datetime' => array('name' => 'datetime', 'format' => 'Y-m-d H:i:s', 'formatter' => 'date'),
'timestamp' => array('name' => 'timestamp', 'format' => 'Y-m-d H:i:s', 'formatter' => 'date'),
'time' => array('name' => 'time', 'format' => 'H:i:s', 'formatter' => 'date'),
@ -763,9 +764,12 @@ class Mysql extends DboSource {
if (strpos($col, 'blob') !== false || $col === 'binary') {
return 'binary';
}
if (strpos($col, 'float') !== false || strpos($col, 'double') !== false || strpos($col, 'decimal') !== false) {
if (strpos($col, 'float') !== false || strpos($col, 'double') !== false) {
return 'float';
}
if (strpos($col, 'decimal') !== false) {
return 'decimal';
}
if (strpos($col, 'enum') !== false) {
return "enum($vals)";
}

View file

@ -543,8 +543,12 @@ class MysqlTest extends CakeTestCase {
$expected = 'float';
$this->assertEquals($expected, $result);
$result = $this->Dbo->column('decimal');
$expected = 'decimal';
$this->assertEquals($expected, $result);
$result = $this->Dbo->column('decimal(14,7) unsigned');
$expected = 'float';
$expected = 'decimal';
$this->assertEquals($expected, $result);
}