Skip to content
This repository
Browse code

Add bigint support for postgres

  • Loading branch information...
commit 7bad865d6e4e89c114b04c14a92ac30599fb678b 1 parent ec35e31
Mark Story authored August 30, 2012
17  lib/Cake/Model/Datasource/Database/Postgres.php
@@ -59,6 +59,7 @@ class Postgres extends DboSource {
59 59
 		'string' => array('name' => 'varchar', 'limit' => '255'),
60 60
 		'text' => array('name' => 'text'),
61 61
 		'integer' => array('name' => 'integer', 'formatter' => 'intval'),
  62
+		'biginteger' => array('name' => 'bigint', 'limit' => '20'),
62 63
 		'float' => array('name' => 'float', 'formatter' => 'floatval'),
63 64
 		'datetime' => array('name' => 'timestamp', 'format' => 'Y-m-d H:i:s', 'formatter' => 'date'),
64 65
 		'timestamp' => array('name' => 'timestamp', 'format' => 'Y-m-d H:i:s', 'formatter' => 'date'),
@@ -637,6 +638,8 @@ public function column($real) {
637 638
 				return 'datetime';
638 639
 			case (strpos($col, 'time') === 0):
639 640
 				return 'time';
  641
+			case ($col == 'bigint'):
  642
+				return 'biginteger';
640 643
 			case (strpos($col, 'int') !== false && $col != 'interval'):
641 644
 				return 'integer';
642 645
 			case (strpos($col, 'char') !== false || $col == 'uuid'):
@@ -799,7 +802,19 @@ public function buildColumn($column) {
799 802
 		if (!isset($col['length']) && !isset($col['limit'])) {
800 803
 			unset($column['length']);
801 804
 		}
802  
-		$out = preg_replace('/integer\([0-9]+\)/', 'integer', parent::buildColumn($column));
  805
+		$out = parent::buildColumn($column);
  806
+
  807
+		$out = preg_replace(
  808
+			'/integer\([0-9]+\)/',
  809
+			'integer',
  810
+			$out
  811
+		);
  812
+		$out = preg_replace(
  813
+			'/bigint\([0-9]+\)/',
  814
+			'bigint',
  815
+			$out
  816
+		);
  817
+
803 818
 		$out = str_replace('integer serial', 'serial', $out);
804 819
 		if (strpos($out, 'timestamp DEFAULT')) {
805 820
 			if (isset($column['null']) && $column['null']) {
12  lib/Cake/Test/Case/Model/Datasource/Database/PostgresTest.php
@@ -307,6 +307,10 @@ public function testColumnParsing() {
307 307
 		$this->assertEquals('string', $this->Dbo2->column('character varying'));
308 308
 		$this->assertEquals('time', $this->Dbo2->column('time without time zone'));
309 309
 		$this->assertEquals('datetime', $this->Dbo2->column('timestamp without time zone'));
  310
+
  311
+		$result = $this->Dbo2->column('bigint');
  312
+		$expected = 'biginteger';
  313
+		$this->assertEquals($expected, $result);
310 314
 	}
311 315
 
312 316
 /**
@@ -530,6 +534,7 @@ public function testCakeSchema() {
530 534
 			id serial NOT NULL,
531 535
 			"varchar" character varying(40) NOT NULL,
532 536
 			"full_length" character varying NOT NULL,
  537
+			"huge_int" bigint NOT NULL,
533 538
 			"timestamp" timestamp without time zone,
534 539
 			"date" date,
535 540
 			CONSTRAINT test_data_types_pkey PRIMARY KEY (id)
@@ -541,12 +546,15 @@ public function testCakeSchema() {
541 546
 			'connection' => 'test',
542 547
 			'models' => array('DatatypeTest')
543 548
 		));
544  
-		$schema->tables = array('datatype_tests' => $result['tables']['missing']['datatype_tests']);
  549
+		$schema->tables = array(
  550
+			'datatype_tests' => $result['tables']['missing']['datatype_tests']
  551
+		);
545 552
 		$result = $db1->createSchema($schema, 'datatype_tests');
546 553
 
547 554
 		$this->assertNotRegExp('/timestamp DEFAULT/', $result);
548 555
 		$this->assertRegExp('/\"full_length\"\s*text\s.*,/', $result);
549  
-		$this->assertRegExp('/timestamp\s*,/', $result);
  556
+		$this->assertContains('timestamp ,', $result);
  557
+		$this->assertContains('"huge_int" bigint NOT NULL,', $result);
550 558
 
551 559
 		$db1->query('DROP TABLE ' . $db1->fullTableName('datatype_tests'));
552 560
 

0 notes on commit 7bad865

Please sign in to comment.
Something went wrong with that request. Please try again.