From 1de6fed32a36a840864dafb433fc09f24e835c71 Mon Sep 17 00:00:00 2001 From: Jakub Vrana Date: Fri, 20 Dec 2013 18:43:14 -0800 Subject: [PATCH] PostgreSQL: Allow escaped table name in foreign key (bug #333) --- adminer/drivers/pgsql.inc.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/adminer/drivers/pgsql.inc.php b/adminer/drivers/pgsql.inc.php index e6c4ba23..732d6524 100644 --- a/adminer/drivers/pgsql.inc.php +++ b/adminer/drivers/pgsql.inc.php @@ -321,10 +321,9 @@ AND contype = 'f'::char ORDER BY conkey, conname") as $row) { if (preg_match('~FOREIGN KEY\s*\((.+)\)\s*REFERENCES (.+)\((.+)\)(.*)$~iA', $row['definition'], $match)) { $row['source'] = array_map('trim', explode(',', $match[1])); - $row['table'] = $match[2]; - if (preg_match('~(.+)\.(.+)~', $match[2], $match2)) { - $row['ns'] = $match2[1]; - $row['table'] = $match2[2]; + if (preg_match('~^(("([^"]|"")+"|[^"]+)\.)?"?("([^"]|"")+"|[^"]+)$~', $match[2], $match2)) { + $row['ns'] = str_replace('""', '"', preg_replace('~^"(.+)"$~', '\1', $match2[2])); + $row['table'] = str_replace('""', '"', preg_replace('~^"(.+)"$~', '\1', $match2[4])); } $row['target'] = array_map('trim', explode(',', $match[3])); $row['on_delete'] = (preg_match("~ON DELETE ($on_actions)~", $match[4], $match2) ? $match2[1] : 'NO ACTION');