Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add bigint support for postgres

  • Loading branch information...
commit 7bad865d6e4e89c114b04c14a92ac30599fb678b 1 parent ec35e31
@markstory markstory authored
View
17 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 @@ public function column($real) {
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 @@ public function buildColumn($column) {
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']) {
View
12 lib/Cake/Test/Case/Model/Datasource/Database/PostgresTest.php
@@ -307,6 +307,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'));
+
+ $result = $this->Dbo2->column('bigint');
+ $expected = 'biginteger';
+ $this->assertEquals($expected, $result);
}
/**
@@ -530,6 +534,7 @@ public function testCakeSchema() {
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 @@ public function testCakeSchema() {
'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'));

0 comments on commit 7bad865

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