]> git.joonet.de Git - adminer.git/commitdiff
SQLite: Support generated columns
authorJakub Vrana <jakub@vrana.cz>
Fri, 7 Mar 2025 04:55:09 +0000 (05:55 +0100)
committerJakub Vrana <jakub@vrana.cz>
Fri, 7 Mar 2025 05:07:25 +0000 (06:07 +0100)
adminer/drivers/sqlite.inc.php
changes.txt

index 7c5f2647ba031662d58a9272c6973f89b1c35208..8d0e10d65dbd02857c25cd2c795ca33f0a297ec3 100644 (file)
@@ -146,6 +146,13 @@ if (isset($_GET["sqlite"])) {
                var $functions = array("hex", "length", "lower", "round", "unixepoch", "upper");
                var $grouping = array("avg", "count", "count distinct", "group_concat", "max", "min", "sum");
 
+               function __construct($connection) {
+                       parent::__construct($connection);
+                       if (min_version(3.31, 0, $connection)) {
+                               $this->generated = array("STORED", "VIRTUAL");
+                       }
+               }
+
                function structuredTypes() {
                        return array_keys($this->types[0]);
                }
@@ -255,7 +262,7 @@ if (isset($_GET["sqlite"])) {
                global $connection;
                $return = array();
                $primary = "";
-               foreach (get_rows("PRAGMA table_info(" . table($table) . ")") as $row) {
+               foreach (get_rows("PRAGMA table_" . (min_version(3.31) ? "x" : "") . "info(" . table($table) . ")") as $row) {
                        $name = $row["name"];
                        $type = strtolower($row["type"]);
                        $default = $row["dflt_value"];
@@ -278,13 +285,20 @@ if (isset($_GET["sqlite"])) {
                        }
                }
                $sql = $connection->result("SELECT sql FROM sqlite_master WHERE type = 'table' AND name = " . q($table));
-               preg_match_all('~(("[^"]*+")+|[a-z0-9_]+)\s+text\s+COLLATE\s+(\'[^\']+\'|\S+)~i', $sql, $matches, PREG_SET_ORDER);
+               $idf = '(("[^"]*+")+|[a-z0-9_]+)';
+               preg_match_all('~' . $idf . '\s+text\s+COLLATE\s+(\'[^\']+\'|\S+)~i', $sql, $matches, PREG_SET_ORDER);
                foreach ($matches as $match) {
                        $name = str_replace('""', '"', preg_replace('~^"|"$~', '', $match[1]));
                        if ($return[$name]) {
                                $return[$name]["collation"] = trim($match[3], "'");
                        }
                }
+               preg_match_all('~' . $idf . '\s.*GENERATED ALWAYS AS \((.+)\) (STORED|VIRTUAL)~i', $sql, $matches, PREG_SET_ORDER);
+               foreach ($matches as $match) {
+                       $name = str_replace('""', '"', preg_replace('~^"|"$~', '', $match[1]));
+                       $return[$name]["default"] = $match[3];
+                       $return[$name]["generated"] = strtoupper($match[4]);
+               }
                return $return;
        }
 
@@ -537,6 +551,9 @@ if (isset($_GET["sqlite"])) {
                        queries("BEGIN");
                }
                foreach ($fields as $key => $field) {
+                       if (preg_match('~GENERATED~', $field[3])) {
+                               unset($originals[array_search($field[0], $originals)]);
+                       }
                        $fields[$key] = "  " . implode($field);
                }
                $fields = array_merge($fields, array_filter($foreign));
index 68971e68bfee51481f1a623865b097d88ce975da..e707dd7a48d4f35cd7101a0681df66d56c0080bd 100644 (file)
@@ -15,6 +15,7 @@ PostgreSQL: Show accessible databases to non-owners (regression from 4.9.1)
 PostgreSQL: Skip editing generated columns
 PostgreSQL, MS SQL, Oracle: Hide table actions for information_schema
 SQLite: Support CHECK constraint
+SQLite: Support generated columns
 SQLite: Add command Check tables
 SQLite: Display all rows of variable values
 SQLite: Remove support for SQLite version 2