Skip to content

Commit

Permalink
Fix edge case in DB\SQL->schema(): PK not detected in PgSQL when the …
Browse files Browse the repository at this point in the history
…column is also a FK (bcosca/fatfree#1207)
  • Loading branch information
xfra35 committed Nov 6, 2020
1 parent bc8b384 commit 28e7e75
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions db/sql.php
Original file line number Diff line number Diff line change
Expand Up @@ -408,21 +408,22 @@ function schema($table,$fields=NULL,$ttl=0) {
foreach ($conv as $regex=>$type)
if (preg_match('/'.$regex.'/i',$row[$val[2]]))
break;
$rows[$row[$val[1]]]=[
'type'=>$row[$val[2]],
'pdo_type'=>$type,
'default'=>is_string($row[$val[3]])?
preg_replace('/^\s*([\'"])(.*)\1\s*/','\2',
$row[$val[3]]):$row[$val[3]],
'nullable'=>$row[$val[4]]==$val[5],
'pkey'=>$row[$val[6]]==$val[7],
'auto_inc'=>isset($val[8]) && isset($row[$val[8]])
? ($this->engine=='sqlite'?
(bool) preg_match(sprintf($val[9],$row[$val[1]]),
$row[$val[8]]):
($row[$val[8]]==$val[9])
) : NULL,
];
if (!isset($rows[$row[$val[1]]])) // handle duplicate rows in PgSQL
$rows[$row[$val[1]]]=[
'type'=>$row[$val[2]],
'pdo_type'=>$type,
'default'=>is_string($row[$val[3]])?
preg_replace('/^\s*([\'"])(.*)\1\s*/','\2',
$row[$val[3]]):$row[$val[3]],
'nullable'=>$row[$val[4]]==$val[5],
'pkey'=>$row[$val[6]]==$val[7],
'auto_inc'=>isset($val[8]) && isset($row[$val[8]])
? ($this->engine=='sqlite'?
(bool) preg_match(sprintf($val[9],$row[$val[1]]),
$row[$val[8]]):
($row[$val[8]]==$val[9])
) : NULL,
];
}
if ($fw->CACHE && $ttl)
// Save to cache backend
Expand Down

0 comments on commit 28e7e75

Please sign in to comment.