Browse Source

Decimal support for PostgreSQL. #3171

U-Zyn Chua 12 years ago
parent
commit
a1a3e70039

+ 4 - 1
lib/Cake/Model/Datasource/Database/Postgres.php

@@ -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'),
@@ -665,7 +666,7 @@ class Postgres extends DboSource {
 		}
 
 		$floats = array(
-			'float', 'float4', 'float8', 'double', 'double precision', 'decimal', 'real', 'numeric'
+			'float', 'float4', 'float8', 'double', 'double precision', 'real'
 		);
 
 		switch (true) {
@@ -685,6 +686,8 @@ class Postgres extends DboSource {
 				return 'text';
 			case (strpos($col, 'bytea') !== false):
 				return 'binary';
+			case ($col === 'decimal' || $col === 'numeric'):
+				return 'decimal';
 			case (in_array($col, $floats)):
 				return 'float';
 			default:

+ 4 - 0
lib/Cake/Test/Case/Model/Datasource/Database/PostgresTest.php

@@ -295,6 +295,10 @@ class PostgresTest extends CakeTestCase {
 		$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';