Skip to content

Commit

Permalink
Decimal support for PostgreSQL. #3171
Browse files Browse the repository at this point in the history
  • Loading branch information
uzyn committed Sep 28, 2013
1 parent 7fb51ab commit a1a3e70
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/Cake/Model/Datasource/Database/Postgres.php
Expand Up @@ -62,6 +62,7 @@ class Postgres extends DboSource {
'integer' => array('name' => 'integer', 'formatter' => 'intval'),
'biginteger' => array('name' => 'bigint', 'limit' => '20'),
'float' => array('name' => 'float', 'formatter' => 'floatval'),
'decimal' => array('name' => 'decimal', 'formatter' => 'floatval'),
'datetime' => array('name' => 'timestamp', '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 @@ -665,7 +666,7 @@ public function column($real) {
}

$floats = array(
'float', 'float4', 'float8', 'double', 'double precision', 'decimal', 'real', 'numeric'
'float', 'float4', 'float8', 'double', 'double precision', 'real'
);

switch (true) {
Expand All @@ -685,6 +686,8 @@ public function column($real) {
return 'text';
case (strpos($col, 'bytea') !== false):
return 'binary';
case ($col === 'decimal' || $col === 'numeric'):
return 'decimal';
case (in_array($col, $floats)):
return 'float';
default:
Expand Down
4 changes: 4 additions & 0 deletions lib/Cake/Test/Case/Model/Datasource/Database/PostgresTest.php
Expand Up @@ -295,6 +295,10 @@ public function testColumnParsing() {
$this->assertEquals('string', $this->Dbo2->column('character varying'));
$this->assertEquals('time', $this->Dbo2->column('time without time zone'));
$this->assertEquals('datetime', $this->Dbo2->column('timestamp without time zone'));
$this->assertEquals('decimal', $this->Dbo2->column('decimal'));
$this->assertEquals('decimal', $this->Dbo2->column('numeric'));
$this->assertEquals('float', $this->Dbo2->column('float'));
$this->assertEquals('float', $this->Dbo2->column('double precision'));

$result = $this->Dbo2->column('bigint');
$expected = 'biginteger';
Expand Down

0 comments on commit a1a3e70

Please sign in to comment.