Merge pull request #12653 from begnini/fix_describe_pgsql_function

limiting the regex to consume only words in default value in pgsql
This commit is contained in:
Mark Story 2018-10-21 02:30:44 +00:00 committed by GitHub
commit 2bdc04e53c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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');
}
}