Skip to content

Commit

Permalink
Decimal support for MySQL. #3171
Browse files Browse the repository at this point in the history
  • Loading branch information
uzyn committed Sep 28, 2013
1 parent cc5795c commit 7fb51ab
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/Cake/Model/Datasource/Database/Mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down Expand Up @@ -763,9 +764,12 @@ public function column($real) {
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)";
}
Expand Down
6 changes: 5 additions & 1 deletion lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -543,8 +543,12 @@ public function testColumn() {
$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);
}

Expand Down

0 comments on commit 7fb51ab

Please sign in to comment.