From 7bad865d6e4e89c114b04c14a92ac30599fb678b Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 30 Aug 2012 12:39:14 +0100 Subject: [PATCH] Add bigint support for postgres --- lib/Cake/Model/Datasource/Database/Postgres.php | 17 ++++++++++++++++- .../Model/Datasource/Database/PostgresTest.php | 12 ++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/lib/Cake/Model/Datasource/Database/Postgres.php b/lib/Cake/Model/Datasource/Database/Postgres.php index 74da3465b..7e16edb5b 100644 --- a/lib/Cake/Model/Datasource/Database/Postgres.php +++ b/lib/Cake/Model/Datasource/Database/Postgres.php @@ -59,6 +59,7 @@ class Postgres extends DboSource { 'string' => array('name' => 'varchar', 'limit' => '255'), 'text' => array('name' => 'text'), 'integer' => array('name' => 'integer', 'formatter' => 'intval'), + 'biginteger' => array('name' => 'bigint', 'limit' => '20'), 'float' => array('name' => 'float', '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'), @@ -637,6 +638,8 @@ class Postgres extends DboSource { return 'datetime'; case (strpos($col, 'time') === 0): return 'time'; + case ($col == 'bigint'): + return 'biginteger'; case (strpos($col, 'int') !== false && $col != 'interval'): return 'integer'; case (strpos($col, 'char') !== false || $col == 'uuid'): @@ -799,7 +802,19 @@ class Postgres extends DboSource { if (!isset($col['length']) && !isset($col['limit'])) { unset($column['length']); } - $out = preg_replace('/integer\([0-9]+\)/', 'integer', parent::buildColumn($column)); + $out = parent::buildColumn($column); + + $out = preg_replace( + '/integer\([0-9]+\)/', + 'integer', + $out + ); + $out = preg_replace( + '/bigint\([0-9]+\)/', + 'bigint', + $out + ); + $out = str_replace('integer serial', 'serial', $out); if (strpos($out, 'timestamp DEFAULT')) { if (isset($column['null']) && $column['null']) { diff --git a/lib/Cake/Test/Case/Model/Datasource/Database/PostgresTest.php b/lib/Cake/Test/Case/Model/Datasource/Database/PostgresTest.php index 2046e6b19..154920262 100644 --- a/lib/Cake/Test/Case/Model/Datasource/Database/PostgresTest.php +++ b/lib/Cake/Test/Case/Model/Datasource/Database/PostgresTest.php @@ -307,6 +307,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')); + + $result = $this->Dbo2->column('bigint'); + $expected = 'biginteger'; + $this->assertEquals($expected, $result); } /** @@ -530,6 +534,7 @@ class PostgresTest extends CakeTestCase { id serial NOT NULL, "varchar" character varying(40) NOT NULL, "full_length" character varying NOT NULL, + "huge_int" bigint NOT NULL, "timestamp" timestamp without time zone, "date" date, CONSTRAINT test_data_types_pkey PRIMARY KEY (id) @@ -541,12 +546,15 @@ class PostgresTest extends CakeTestCase { 'connection' => 'test', 'models' => array('DatatypeTest') )); - $schema->tables = array('datatype_tests' => $result['tables']['missing']['datatype_tests']); + $schema->tables = array( + 'datatype_tests' => $result['tables']['missing']['datatype_tests'] + ); $result = $db1->createSchema($schema, 'datatype_tests'); $this->assertNotRegExp('/timestamp DEFAULT/', $result); $this->assertRegExp('/\"full_length\"\s*text\s.*,/', $result); - $this->assertRegExp('/timestamp\s*,/', $result); + $this->assertContains('timestamp ,', $result); + $this->assertContains('"huge_int" bigint NOT NULL,', $result); $db1->query('DROP TABLE ' . $db1->fullTableName('datatype_tests'));