]> git.joonet.de Git - adminer.git/commitdiff
PostgreSQL: Fix parsing of foreign keys with non-ASCII column names (thanks to Tomas...
authorJakub Vrana <jakub@vrana.cz>
Fri, 14 May 2021 04:21:09 +0000 (06:21 +0200)
committerJakub Vrana <jakub@vrana.cz>
Fri, 14 May 2021 04:21:09 +0000 (06:21 +0200)
adminer/drivers/pgsql.inc.php
adminer/drivers/sqlite.inc.php
adminer/include/functions.inc.php
changes.txt

index 296b8aa3e0d69ee111869a18244a7243dc81ee0a..caeda87514faa1814004151eaaf62efd1d58399d 100644 (file)
@@ -378,7 +378,7 @@ ORDER BY a.attnum"
                        $row["auto_increment"] = $row['attidentity'] || preg_match('~^nextval\(~i', $row["default"]);
                        $row["privileges"] = array("insert" => 1, "select" => 1, "update" => 1);
                        if (preg_match('~(.+)::[^,)]+(.*)~', $row["default"], $match)) {
-                               $row["default"] = ($match[1] == "NULL" ? null : (($match[1][0] == "'" ? idf_unescape($match[1]) : $match[1]) . $match[2]));
+                               $row["default"] = ($match[1] == "NULL" ? null : idf_unescape($match[1]) . $match[2]);
                        }
                        $return[$row["field"]] = $row;
                }
@@ -418,12 +418,12 @@ WHERE conrelid = (SELECT pc.oid FROM pg_class AS pc INNER JOIN pg_namespace AS p
 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['source'] = array_map('idf_unescape', array_map('trim', explode(',', $match[1])));
                                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['ns'] = idf_unescape($match2[2]);
+                                       $row['table'] = idf_unescape($match2[4]);
                                }
-                               $row['target'] = array_map('trim', explode(',', $match[3]));
+                               $row['target'] = array_map('idf_unescape', array_map('trim', explode(',', $match[3])));
                                $row['on_delete'] = (preg_match("~ON DELETE ($on_actions)~", $match[4], $match2) ? $match2[1] : 'NO ACTION');
                                $row['on_update'] = (preg_match("~ON UPDATE ($on_actions)~", $match[4], $match2) ? $match2[1] : 'NO ACTION');
                                $return[$row['conname']] = $row;
index da698fdd3446c50883e942a0fcf6fead6b239d71..e85fd31c2372d3ee0bcb933817f8be6666d3f67f 100644 (file)
@@ -140,7 +140,7 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
                                        }
                                        $return = array();
                                        foreach ($row as $key => $val) {
-                                               $return[($key[0] == '"' ? idf_unescape($key) : $key)] = $val;
+                                               $return[idf_unescape($key)] = $val;
                                        }
                                        return $return;
                                }
@@ -676,7 +676,7 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
                return array(
                        "Timing" => strtoupper($match[1]),
                        "Event" => strtoupper($match[2]) . ($of ? " OF" : ""),
-                       "Of" => ($of[0] == '`' || $of[0] == '"' ? idf_unescape($of) : $of),
+                       "Of" => idf_unescape($of),
                        "Trigger" => $name,
                        "Statement" => $match[4],
                );
index 476cf5ccf22fcb219a17458485ae4ecd0b20c50e..b33d82959d8471039538ec28325b2102c7c2d5b3 100644 (file)
@@ -29,6 +29,9 @@ function version() {
 * @return string
 */
 function idf_unescape($idf) {
+       if (!preg_match('~^[`\'"]~', $idf)) {
+               return $idf;
+       }
        $last = substr($idf, -1);
        return str_replace($last . $last, $last, substr($idf, 1, -1));
 }
index 6c4301eb10314630d7aa0b40c49439953a987b56..9622f194b1b90ef163ddb2e47688a539c1859fa8 100644 (file)
@@ -5,6 +5,7 @@ MySQL: Allow moving views to other DB and renaming DB with views (bug #783)
 MariaDB: Do not treat sequences as views (PR #416)
 PostgreSQL: Support UPDATE OF triggers (bug #789)
 PostgreSQL: Support triggers with more events (OR)
+PostgreSQL: Fix parsing of foreign keys with non-ASCII column names
 PostgreSQL < 10 PDO: Avoid displaying GENERATED ALWAYS BY IDENTITY everywhere (bug #785, regression from 4.7.9)
 SQLite: Fix displayed types (bug #784, regression from 4.8.0)