]> git.joonet.de Git - adminer.git/commitdiff
Optimize retrieving columns for schema
authorJakub Vrana <jakub@vrana.cz>
Mon, 31 Mar 2025 19:28:40 +0000 (21:28 +0200)
committerJakub Vrana <jakub@vrana.cz>
Mon, 31 Mar 2025 19:45:06 +0000 (21:45 +0200)
CHANGELOG.md
adminer/drivers/sqlite.inc.php
adminer/include/driver.inc.php
adminer/schema.inc.php

index de82434d7193eb4e1154d18b125e98aa7afcac34..4ec42e005edff5e8212acd2bfc58d2538b237988 100644 (file)
@@ -1,5 +1,6 @@
 ## Adminer dev
 - Export: Fix tar (regression from 5.0.3)
+- Optimize retrieving columns for schema
 - Elasticsearch: Make it work with Elasticsearch 8
 - CSS: Hide menu on mobile
 - CSS: Invert icons in dark mode
index 1a91ab4914304091d35040f734111cfd29793381..996a77fe8956cecc89b3c6904adebef8ea2f5ecb 100644 (file)
@@ -161,6 +161,16 @@ if (isset($_GET["sqlite"])) {
                        preg_match_all('~ CHECK *(\( *(((?>[^()]*[^() ])|(?1))*) *\))~', get_val("SELECT sql FROM sqlite_master WHERE type = 'table' AND name = " . q($table), 0, $this->conn), $matches); //! could be inside a comment
                        return array_combine($matches[2], $matches[2]);
                }
+
+               function allFields(): array {
+                       $return = array();
+                       foreach (tables_list() as $table => $type) {
+                               foreach (fields($table) as $field) {
+                                       $return[$table][] = $field;
+                               }
+                       }
+                       return $return;
+               }
        }
 
 
index 9452beaf571be92049fa0bfc7e5877537d9c7c82..ce02be8ae1734cd2f12500bb7d8506d5acee01ad 100644 (file)
@@ -249,6 +249,21 @@ FROM INFORMATION_SCHEMA.CHECK_CONSTRAINTS c
 JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS t ON c.CONSTRAINT_SCHEMA = t.CONSTRAINT_SCHEMA AND c.CONSTRAINT_NAME = t.CONSTRAINT_NAME
 WHERE c.CONSTRAINT_SCHEMA = " . q($_GET["ns"] != "" ? $_GET["ns"] : DB) . "
 AND t.TABLE_NAME = " . q($table) . "
-AND CHECK_CLAUSE NOT LIKE '% IS NOT NULL'"); // ignore default IS NOT NULL checks in PostrgreSQL
+AND CHECK_CLAUSE NOT LIKE '% IS NOT NULL'", $this->conn); // ignore default IS NOT NULL checks in PostrgreSQL
+       }
+
+       /** Get all fields in the current schema
+       * @return array<list<array{field:string, null:bool, type:string, length:?numeric-string, primary?:numeric-string}>>
+       */
+       function allFields(): array {
+               $return = array();
+               foreach (get_rows("SELECT TABLE_NAME AS tab, COLUMN_NAME AS field, IS_NULLABLE AS nullable, DATA_TYPE AS type, CHARACTER_MAXIMUM_LENGTH AS length" . (JUSH == 'sql' ? ", COLUMN_KEY = 'PRI' AS `primary`" : "") . "
+FROM INFORMATION_SCHEMA.COLUMNS
+WHERE TABLE_SCHEMA = " . q($_GET["ns"] != "" ? $_GET["ns"] : DB) . "
+ORDER BY TABLE_NAME, ORDINAL_POSITION", $this->conn) as $row) {
+                       $row["null"] = ($row["nullable"] == "YES");
+                       $return[$row["tab"]][] = $row;
+               }
+               return $return;
        }
 }
index b677514ba92baf6b3f7d512316ab6144bbacf5a2..f14616a2a9ef3b859da5321c5e17af12cce5691c 100644 (file)
@@ -19,16 +19,17 @@ $base_left = -1;
 $schema = array(); // table => array("fields" => array(name => field), "pos" => array(top, left), "references" => array(table => array(left => array(source, target))))
 $referenced = array(); // target_table => array(table => array(left => target_column))
 $lefts = array(); // float => bool
+$all_fields = driver()->allFields();
 foreach (table_status('', true) as $table => $table_status) {
        if (is_view($table_status)) {
                continue;
        }
        $pos = 0;
        $schema[$table]["fields"] = array();
-       foreach (fields($table) as $name => $field) {
+       foreach ($all_fields[$table] as $field) {
                $pos += 1.25;
                $field["pos"] = $pos;
-               $schema[$table]["fields"][$name] = $field;
+               $schema[$table]["fields"][$field["field"]] = $field;
        }
        $schema[$table]["pos"] = ($table_pos[$table] ?: array($top, 0));
        foreach (adminer()->foreignKeys($table) as $val) {
@@ -67,7 +68,7 @@ foreach ($schema as $name => $table) {
        echo script("qsl('div').onmousedown = schemaMousedown;");
 
        foreach ($table["fields"] as $field) {
-               $val = '<span' . type_class($field["type"]) . ' title="' . h($field["full_type"] . ($field["null"] ? " NULL" : '')) . '">' . h($field["field"]) . '</span>';
+               $val = '<span' . type_class($field["type"]) . ' title="' . h($field["type"] . ($field["length"] ? "($field[length])" : "") . ($field["null"] ? " NULL" : '')) . '">' . h($field["field"]) . '</span>';
                echo "<br>" . ($field["primary"] ? "<i>$val</i>" : $val);
        }