Skip to content

Commit

Permalink
Merge pull request #259 from joomla-framework/fix/php81-pgsql-defaults
Browse files Browse the repository at this point in the history
Only check types of postgres default values if set

The field default can be null. If that is the case then the preg_match gives a PHP deprecation warning in PHP 8.1.
  • Loading branch information
nibra authored Jan 9, 2022
2 parents 98709ee + 9bcf2fe commit b2535b1
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/Pgsql/PgsqlDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,16 +269,19 @@ public function getTableColumns($table, $typeOnly = true)
{
foreach ($fields as $field)
{
// Change Postgresql's NULL::* type with PHP's null one
if (preg_match('/^NULL::*/', $field->Default))
if ($field->Default !== null)
{
$field->Default = null;
}

// Normalise default values like datetime
if (preg_match('/^\'(.*)\'::.*/', $field->Default, $matches))
{
$field->Default = $matches[1];
// Change Postgresql's NULL::* type with PHP's null one
if (preg_match('/^NULL::*/', $field->Default))
{
$field->Default = null;
}

// Normalise default values like datetime
if (preg_match('/^\'(.*)\'::.*/', $field->Default, $matches))
{
$field->Default = $matches[1];
}
}

// Do some dirty translation to MySQL output.
Expand Down

0 comments on commit b2535b1

Please sign in to comment.