limiting the regex to consume only words in default value in PostgreSQL after ::

added tests showing the old behavior was broken.
This commit is contained in:
Humberto Pereira 2018-10-18 17:16:29 -04:00
parent 5b57a1e926
commit 23e38aeaf0
2 changed files with 21 additions and 1 deletions

View file

@ -251,7 +251,7 @@ class Postgres extends DboSource {
'default' => preg_replace(
"/^'(.*)'$/",
"$1",
preg_replace('/::.*/', '', $c->default)
preg_replace('/::[\w\s]+/', '', $c->default)
),
'length' => $length,
);

View file

@ -1218,4 +1218,24 @@ class PostgresTest extends CakeTestCase {
$this->assertEquals('"col1" uuid', $result);
}
/**
* Test that postgres describes default columns with functions correctly.
*
* @return void
*/
public function testDescribeFunctionDefault() {
$db = $this->Dbo;
$db->execute('CREATE TABLE test_function_default_describe (id integer PRIMARY KEY, year int default date_part(\'year\'::text, now()))');
$data = $db->describe('test_function_default_describe');
$expected = array(
'type' => 'integer',
'null' => true,
'default' => 'date_part(\'year\', now())',
'length' => null,
);
$this->assertSame($expected, $data['year']);
$db->execute('DROP TABLE test_function_default_describe');
}
}