mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
Add bigint support for postgres
This commit is contained in:
parent
ec35e3158c
commit
7bad865d6e
2 changed files with 26 additions and 3 deletions
|
@ -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']) {
|
||||
|
|
|
@ -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'));
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue