]> git.joonet.de Git - adminer.git/commitdiff
Always return array from table_status()
authorJakub Vrana <jakub@vrana.cz>
Wed, 26 Mar 2025 00:34:48 +0000 (01:34 +0100)
committerJakub Vrana <jakub@vrana.cz>
Wed, 26 Mar 2025 00:34:48 +0000 (01:34 +0100)
19 files changed:
adminer/create.inc.php
adminer/drivers/mssql.inc.php
adminer/drivers/mysql.inc.php
adminer/drivers/oracle.inc.php
adminer/drivers/pgsql.inc.php
adminer/drivers/sqlite.inc.php
adminer/include/adminer.inc.php
adminer/include/driver.inc.php
adminer/include/functions.inc.php
adminer/indexes.inc.php
adminer/view.inc.php
editor/include/adminer.inc.php
plugins/backward-keys.php
plugins/drivers/clickhouse.php
plugins/drivers/elastic.php
plugins/drivers/firebird.php
plugins/drivers/imap.php
plugins/drivers/mongo.php
plugins/drivers/simpledb.php

index 075fbf33c16efdc6e309f5856df527bebfaba23e..a5ff02190702e1df4e52caf4cbab9d96aada2578 100644 (file)
@@ -17,8 +17,8 @@ $orig_fields = array();
 $table_status = array();
 if ($TABLE != "") {
        $orig_fields = fields($TABLE);
-       $table_status = table_status($TABLE);
-       if (!$table_status) {
+       $table_status = table_status1($TABLE);
+       if (count($table_status) < 2) { // there's only the Name field
                $error = lang('No tables.');
        }
 }
index 31efda29d2923456ccb2f4ffbced80397bcbe2af..d6833bfd760337621a4d82dbb11d10b1627f6b79 100644 (file)
@@ -357,9 +357,6 @@ if (isset($_GET["mssql"])) {
 FROM sys.all_objects AS ao
 WHERE schema_id = SCHEMA_ID(" . q(get_schema()) . ") AND type IN ('S', 'U', 'V') " . ($name != "" ? "AND name = " . q($name) : "ORDER BY name")) as $row
                ) {
-                       if ($name != "") {
-                               return $row;
-                       }
                        $return[$row["Name"]] = $row;
                }
                return $return;
@@ -662,7 +659,7 @@ WHERE sys1.xtype = 'TR' AND sys2.name = " . q($table)) as $row
 
        function create_sql($table, $auto_increment, $style) {
                global $driver;
-               if (is_view(table_status($table))) {
+               if (is_view(table_status1($table))) {
                        $view = view($table);
                        return "CREATE VIEW " . table($table) . " AS $view[select]";
                }
index ef0c6a74ae29c4da47c50ef1c48acbe06209ef2b..58c544d852afc7723fe2eaa9e091f32c594e2ba6 100644 (file)
@@ -549,7 +549,7 @@ if (!defined('Adminer\DRIVER')) {
        /** Get table status
        * @param string
        * @param bool return only "Name", "Engine" and "Comment" fields
-       * @return array{Name:string, Engine:string, Comment:string, Oid:int, Rows:int, Collation:string, Auto_increment:int, Data_length:int, Index_length:int, Data_free:int}[] or only inner array with $name
+       * @return array{Name:string, Engine:string, Comment:string, Oid:int, Rows:int, Collation:string, Auto_increment:int, Data_length:int, Index_length:int, Data_free:int}[]
        */
        function table_status($name = "", $fast = false) {
                $return = array();
@@ -570,7 +570,6 @@ if (!defined('Adminer\DRIVER')) {
                        if ($name != "") {
                                // MariaDB: Table name is returned as lowercase on macOS, so we fix it here.
                                $row["Name"] = $name;
-                               return $row;
                        }
                        $return[$row["Name"]] = $row;
                }
index 587c51b2c793b9d770fd6888772bb1b4e0679175..4c8d490c41cb3bfbf4eeb66ed90eb817d0afb7a3 100644 (file)
@@ -298,9 +298,6 @@ ORDER BY 1"
 UNION SELECT view_name, 'view', 0, 0 FROM $view" . ($name != "" ? " WHERE view_name = $search" : "") . "
 ORDER BY 1") as $row
                ) {
-                       if ($name != "") {
-                               return $row;
-                       }
                        $return[$row["Name"]] = $row;
                }
                return $return;
index d4712a2d5feee0d8af35fb32a5d8d7de736c1c9d..bad69c47d59b7dce73fb7909631dfa49a6c49e35 100644 (file)
@@ -414,7 +414,7 @@ WHERE relkind IN ('r', 'm', 'v', 'f', 'p')
                ) {
                        $return[$row["Name"]] = $row;
                }
-               return ($name != "" ? $return[$name] : $return);
+               return $return;
        }
 
        function is_view($table_status) {
@@ -683,7 +683,7 @@ ORDER BY conkey, conname") as $row
 
        function drop_tables($tables) {
                foreach ($tables as $table) {
-                       $status = table_status($table);
+                       $status = table_status1($table);
                        if (!queries("DROP " . strtoupper($status["Engine"]) . " " . table($table))) {
                                return false;
                        }
@@ -693,7 +693,7 @@ ORDER BY conkey, conname") as $row
 
        function move_tables($tables, $views, $target) {
                foreach (array_merge($tables, $views) as $table) {
-                       $status = table_status($table);
+                       $status = table_status1($table);
                        if (!queries("ALTER " . strtoupper($status["Engine"]) . " " . table($table) . " SET SCHEMA " . idf_escape($target))) {
                                return false;
                        }
@@ -834,7 +834,7 @@ AND typelem = 0"
        function foreign_keys_sql($table) {
                $return = "";
 
-               $status = table_status($table);
+               $status = table_status1($table);
                $fkeys = foreign_keys($table);
                ksort($fkeys);
 
@@ -850,7 +850,7 @@ AND typelem = 0"
                $return_parts = array();
                $sequences = array();
 
-               $status = table_status($table);
+               $status = table_status1($table);
                if (is_view($status)) {
                        $view = view($table);
                        return rtrim("CREATE VIEW " . idf_escape($table) . " AS $view[select]", ";");
@@ -927,7 +927,7 @@ AND typelem = 0"
        }
 
        function trigger_sql($table) {
-               $status = table_status($table);
+               $status = table_status1($table);
                $return = "";
                foreach (triggers($table) as $trg_id => $trg) {
                        $trigger = trigger($trg_id, $status['Name']);
index 9d9f984cc5216f8b369a3603036544ed6fb88b1f..756644ac3df9a5d96d16ab8eb81c6ed4bc88c1bc 100644 (file)
@@ -233,7 +233,7 @@ if (isset($_GET["sqlite"])) {
                foreach (get_rows("SELECT * FROM sqlite_sequence", null, "") as $row) {
                        $return[$row["name"]]["Auto_increment"] = $row["seq"];
                }
-               return ($name != "" ? $return[$name] : $return);
+               return $return;
        }
 
        function is_view($table_status) {
index dc1b70971ff992126a1a350188e532707b37172c..b3745f629359021e3fc50cc8505df1c3826b3e99 100644 (file)
@@ -1051,7 +1051,7 @@ class Adminer {
        }
 
        /** Set up syntax highlight for code and <textarea>
-       * @param array[] result of table_status()
+       * @param array[] result of table_status('', true)
        */
        function syntaxHighlighting($tables) {
                global $connection;
index 5b99ac754024afe257babfe4bbd061625c77a91f..92aa2b9d662b08ffac3de345bfe8a791be78ea2b 100644 (file)
@@ -260,7 +260,7 @@ abstract class SqlDriver {
        }
 
        /** Check whether table supports indexes
-       * @param array result of table_status()
+       * @param array result of table_status1()
        * @return bool
        */
        function supportsIndex($table_status) {
index b3dbea5c72f733ef172251692d1d12aeca0e0f2f..0428d4f6125f7c3dd8d97828c9b5fb947c5edc15 100644 (file)
@@ -701,11 +701,11 @@ function friendly_url($val) {
 /** Get status of a single table and fall back to name on error
 * @param string
 * @param bool
-* @return array[] same as table_status()
+* @return array one element from table_status()
 */
 function table_status1($table, $fast = false) {
        $return = table_status($table, $fast);
-       return ($return ?: array("Name" => $table));
+       return ($return ? reset($return) : array("Name" => $table));
 }
 
 /** Find out foreign keys for each column
index c80e4ac466c942e3a87143a8a2fddc0305fcaed8..89586f0d911c3f9d21d66a5ed128a57e040a5e66 100644 (file)
@@ -3,7 +3,7 @@ namespace Adminer;
 
 $TABLE = $_GET["indexes"];
 $index_types = array("PRIMARY", "UNIQUE", "INDEX");
-$table_status = table_status($TABLE, true);
+$table_status = table_status1($TABLE, true);
 if (preg_match('~MyISAM|M?aria' . (min_version(5.6, '10.0.5') ? '|InnoDB' : '') . '~i', $table_status["Engine"])) {
        $index_types[] = "FULLTEXT";
 }
index 28bd40ecef84d6bc9325c3e1cf0b057fab1a088a..a0cd69d9fffbdfac7447b9eb92b9fa24bbc89722 100644 (file)
@@ -5,7 +5,7 @@ $TABLE = $_GET["view"];
 $row = $_POST;
 $orig_type = "VIEW";
 if (JUSH == "pgsql" && $TABLE != "") {
-       $status = table_status($TABLE);
+       $status = table_status1($TABLE);
        $orig_type = strtoupper($status["Engine"]);
 }
 
index 8608d10ea43a63f31205b94abe54f70cf1f8416b..6778772ce8f689bd8d93540e8f54a78832fe4c02 100644 (file)
@@ -127,7 +127,7 @@ ORDER BY ORDINAL_POSITION", null, "") as $row
                        $return[$row["TABLE_NAME"]]["keys"][$row["CONSTRAINT_NAME"]][$row["COLUMN_NAME"]] = $row["REFERENCED_COLUMN_NAME"];
                }
                foreach ($return as $key => $val) {
-                       $name = $this->tableName(table_status($key, true));
+                       $name = $this->tableName(table_status1($key, true));
                        if ($name != "") {
                                $search = preg_quote($tableName);
                                $separator = "(:|\\s*-)?\\s+";
@@ -660,7 +660,7 @@ ORDER BY ORDINAL_POSITION", null, "") as $row
                if (list($target, $id, $name) = $this->_foreignColumn(column_foreign_keys($table), $column)) {
                        $return = &$this->values[$target];
                        if ($return === null) {
-                               $table_status = table_status($target);
+                               $table_status = table_status1($target);
                                $return = ($table_status["Rows"] > 1000 ? "" : array("" => "") + get_key_vals("SELECT $id, $name FROM " . table($target) . " ORDER BY 2"));
                        }
                        if (!$return && $value !== null) {
index a0069ec3983468206bc48d0fb9d30c7676b643a4..06fc33a6bb113623865edeb985bc41501cd71509 100644 (file)
@@ -23,7 +23,7 @@ ORDER BY ORDINAL_POSITION", null, "") as $row
                        $return[$row["TABLE_NAME"]]["keys"][$row["CONSTRAINT_NAME"]][$row["COLUMN_NAME"]] = $row["REFERENCED_COLUMN_NAME"];
                }
                foreach ($return as $key => $val) {
-                       $name = Adminer\adminer()->tableName(Adminer\table_status($key, true));
+                       $name = Adminer\adminer()->tableName(Adminer\table_status1($key, true));
                        if ($name != "") {
                                $search = preg_quote($tableName);
                                $separator = '(:|\s*-)?\s+';
index 81eadd9e7745587d6bdbb07c84a6161c2dea9cc6..bba1e160081faabf90ca6307613ed85ca9033ea2 100644 (file)
@@ -309,9 +309,6 @@ if (isset($_GET["clickhouse"])) {
                                'Name' => $table['name'],
                                'Engine' => $table['engine'],
                        );
-                       if ($name === $table['name']) {
-                               return $return[$table['name']];
-                       }
                }
                return $return;
        }
index bb927dbdd915b1e0e646317cddca1aa84b699e6d..4899d87977c652187897f40548ebbeccd6546202 100644 (file)
@@ -384,16 +384,17 @@ if (isset($_GET["elastic"])) {
 
                if ($name != "") {
                        if (isset($stats["indices"][$name])) {
-                               return format_index_status($name, $stats["indices"][$name]);
+                               return array(format_index_status($name, $stats["indices"][$name]));
                        } else {
                                foreach ($aliases as $index_name => $index) {
                                        foreach ($index["aliases"] as $alias_name => $alias) {
                                                if ($alias_name == $name) {
-                                                       return format_alias_status($alias_name, $stats["indices"][$index_name]);
+                                                       return array(format_alias_status($alias_name, $stats["indices"][$index_name]));
                                                }
                                        }
                                }
                        }
+                       return array();
                }
 
                ksort($stats["indices"]);
index 03c06889080e32d7db543e95aa5ca72b04172630..e8a6d58a6c047684c39c874dae5f3adedbb9fb45 100644 (file)
@@ -184,16 +184,13 @@ if (isset($_GET["firebird"])) {
        function table_status($name = "", $fast = false) {
                $connection = connection();
                $return = array();
-               $data = tables_list();
+               $data = ($name != "" ? array($name => 1) : tables_list());
                foreach ($data as $index => $val) {
                        $index = trim($index);
                        $return[$index] = array(
                                'Name' => $index,
                                'Engine' => 'standard',
                        );
-                       if ($name == $index) {
-                               return $return[$index];
-                       }
                }
                return $return;
        }
index be130035543aee9c6db5420bcd4afff6819967b8..0d236a32175d1daee83a8a361bb0565932469527 100644 (file)
@@ -44,7 +44,7 @@ if (isset($_GET["imap"])) {
                                        preg_match_all('~"uid" = (\d+)~', $query, $matches);
                                        return imap_delete($this->imap, implode(",", $matches[1]), FT_UID);
                                } elseif (preg_match('~^SELECT COUNT\(\*\)\sFROM "(.+?)"~s', $query, $match)) {
-                                       $status = table_status($match[1]);
+                                       $status = table_status1($match[1]);
                                        return new Result(array(array($status["Rows"])));
                                } elseif (preg_match('~^SELECT (.+)\sFROM "(.+?)"(?:\sWHERE "uid" = (\d+))?.*?(?:\sLIMIT (\d+)(?:\sOFFSET (\d+))?)?~s', $query, $match)) {
                                        list(, $columns, $table, $uid, $limit, $offset) = $match;
@@ -233,11 +233,8 @@ if (isset($_GET["imap"])) {
        }
 
        function table_status($name = "", $fast = false) {
-               if ($name != "") {
-                       return connection()->table_status($name, $fast);
-               }
                $return = array();
-               foreach (tables_list() as $table => $type) {
+               foreach (($name != "" ? array($name => 1) : tables_list()) as $table => $type) {
                        $return[$table] = connection()->table_status($table, $fast);
                }
                return $return;
index 8a8d721fa282c9ec90f0d02438fa106b5f663014..fc7459682669a4018d2dcf8fd2fe9122d98210c5 100644 (file)
@@ -391,11 +391,8 @@ if (isset($_GET["mongo"])) {
 
        function table_status($name = "", $fast = false) {
                $return = array();
-               foreach (tables_list() as $table => $type) {
-                       $return[$table] = array("Name" => $table);
-                       if ($name == $table) {
-                               return $return[$table];
-                       }
+               foreach (($name != "" ? array($name => 1) : tables_list()) as $table => $type) {
+                       $return[$table] = array("Name" => $table, "Engine" => "");
                }
                return $return;
        }
index 28de7c93f64411544f5b85357cf7a1da9919f4f1..b154c675cc39493936b6fc2f870c30bbeff2c5ef 100644 (file)
@@ -316,9 +316,6 @@ if (isset($_GET["simpledb"])) {
                                        }
                                }
                        }
-                       if ($name != "") {
-                               return $row;
-                       }
                        $return[$table] = $row;
                }
                return $return;