1
0
mirror of https://github.com/vrana/adminer.git synced 2025-08-06 14:46:36 +02:00

Always return array from table_status()

This commit is contained in:
Jakub Vrana
2025-03-26 01:34:48 +01:00
parent cd207238b7
commit cccc784da4
19 changed files with 28 additions and 49 deletions

View File

@@ -17,8 +17,8 @@ $orig_fields = array();
$table_status = array(); $table_status = array();
if ($TABLE != "") { if ($TABLE != "") {
$orig_fields = fields($TABLE); $orig_fields = fields($TABLE);
$table_status = table_status($TABLE); $table_status = table_status1($TABLE);
if (!$table_status) { if (count($table_status) < 2) { // there's only the Name field
$error = lang('No tables.'); $error = lang('No tables.');
} }
} }

View File

@@ -357,9 +357,6 @@ if (isset($_GET["mssql"])) {
FROM sys.all_objects AS ao 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 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[$row["Name"]] = $row;
} }
return $return; return $return;
@@ -662,7 +659,7 @@ WHERE sys1.xtype = 'TR' AND sys2.name = " . q($table)) as $row
function create_sql($table, $auto_increment, $style) { function create_sql($table, $auto_increment, $style) {
global $driver; global $driver;
if (is_view(table_status($table))) { if (is_view(table_status1($table))) {
$view = view($table); $view = view($table);
return "CREATE VIEW " . table($table) . " AS $view[select]"; return "CREATE VIEW " . table($table) . " AS $view[select]";
} }

View File

@@ -549,7 +549,7 @@ if (!defined('Adminer\DRIVER')) {
/** Get table status /** Get table status
* @param string * @param string
* @param bool return only "Name", "Engine" and "Comment" fields * @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) { function table_status($name = "", $fast = false) {
$return = array(); $return = array();
@@ -570,7 +570,6 @@ if (!defined('Adminer\DRIVER')) {
if ($name != "") { if ($name != "") {
// MariaDB: Table name is returned as lowercase on macOS, so we fix it here. // MariaDB: Table name is returned as lowercase on macOS, so we fix it here.
$row["Name"] = $name; $row["Name"] = $name;
return $row;
} }
$return[$row["Name"]] = $row; $return[$row["Name"]] = $row;
} }

View File

@@ -298,9 +298,6 @@ ORDER BY 1"
UNION SELECT view_name, 'view', 0, 0 FROM $view" . ($name != "" ? " WHERE view_name = $search" : "") . " UNION SELECT view_name, 'view', 0, 0 FROM $view" . ($name != "" ? " WHERE view_name = $search" : "") . "
ORDER BY 1") as $row ORDER BY 1") as $row
) { ) {
if ($name != "") {
return $row;
}
$return[$row["Name"]] = $row; $return[$row["Name"]] = $row;
} }
return $return; return $return;

View File

@@ -414,7 +414,7 @@ WHERE relkind IN ('r', 'm', 'v', 'f', 'p')
) { ) {
$return[$row["Name"]] = $row; $return[$row["Name"]] = $row;
} }
return ($name != "" ? $return[$name] : $return); return $return;
} }
function is_view($table_status) { function is_view($table_status) {
@@ -683,7 +683,7 @@ ORDER BY conkey, conname") as $row
function drop_tables($tables) { function drop_tables($tables) {
foreach ($tables as $table) { foreach ($tables as $table) {
$status = table_status($table); $status = table_status1($table);
if (!queries("DROP " . strtoupper($status["Engine"]) . " " . table($table))) { if (!queries("DROP " . strtoupper($status["Engine"]) . " " . table($table))) {
return false; return false;
} }
@@ -693,7 +693,7 @@ ORDER BY conkey, conname") as $row
function move_tables($tables, $views, $target) { function move_tables($tables, $views, $target) {
foreach (array_merge($tables, $views) as $table) { 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))) { if (!queries("ALTER " . strtoupper($status["Engine"]) . " " . table($table) . " SET SCHEMA " . idf_escape($target))) {
return false; return false;
} }
@@ -834,7 +834,7 @@ AND typelem = 0"
function foreign_keys_sql($table) { function foreign_keys_sql($table) {
$return = ""; $return = "";
$status = table_status($table); $status = table_status1($table);
$fkeys = foreign_keys($table); $fkeys = foreign_keys($table);
ksort($fkeys); ksort($fkeys);
@@ -850,7 +850,7 @@ AND typelem = 0"
$return_parts = array(); $return_parts = array();
$sequences = array(); $sequences = array();
$status = table_status($table); $status = table_status1($table);
if (is_view($status)) { if (is_view($status)) {
$view = view($table); $view = view($table);
return rtrim("CREATE VIEW " . idf_escape($table) . " AS $view[select]", ";"); return rtrim("CREATE VIEW " . idf_escape($table) . " AS $view[select]", ";");
@@ -927,7 +927,7 @@ AND typelem = 0"
} }
function trigger_sql($table) { function trigger_sql($table) {
$status = table_status($table); $status = table_status1($table);
$return = ""; $return = "";
foreach (triggers($table) as $trg_id => $trg) { foreach (triggers($table) as $trg_id => $trg) {
$trigger = trigger($trg_id, $status['Name']); $trigger = trigger($trg_id, $status['Name']);

View File

@@ -233,7 +233,7 @@ if (isset($_GET["sqlite"])) {
foreach (get_rows("SELECT * FROM sqlite_sequence", null, "") as $row) { foreach (get_rows("SELECT * FROM sqlite_sequence", null, "") as $row) {
$return[$row["name"]]["Auto_increment"] = $row["seq"]; $return[$row["name"]]["Auto_increment"] = $row["seq"];
} }
return ($name != "" ? $return[$name] : $return); return $return;
} }
function is_view($table_status) { function is_view($table_status) {

View File

@@ -1051,7 +1051,7 @@ class Adminer {
} }
/** Set up syntax highlight for code and <textarea> /** Set up syntax highlight for code and <textarea>
* @param array[] result of table_status() * @param array[] result of table_status('', true)
*/ */
function syntaxHighlighting($tables) { function syntaxHighlighting($tables) {
global $connection; global $connection;

View File

@@ -260,7 +260,7 @@ abstract class SqlDriver {
} }
/** Check whether table supports indexes /** Check whether table supports indexes
* @param array result of table_status() * @param array result of table_status1()
* @return bool * @return bool
*/ */
function supportsIndex($table_status) { function supportsIndex($table_status) {

View File

@@ -701,11 +701,11 @@ function friendly_url($val) {
/** Get status of a single table and fall back to name on error /** Get status of a single table and fall back to name on error
* @param string * @param string
* @param bool * @param bool
* @return array[] same as table_status() * @return array one element from table_status()
*/ */
function table_status1($table, $fast = false) { function table_status1($table, $fast = false) {
$return = table_status($table, $fast); $return = table_status($table, $fast);
return ($return ?: array("Name" => $table)); return ($return ? reset($return) : array("Name" => $table));
} }
/** Find out foreign keys for each column /** Find out foreign keys for each column

View File

@@ -3,7 +3,7 @@ namespace Adminer;
$TABLE = $_GET["indexes"]; $TABLE = $_GET["indexes"];
$index_types = array("PRIMARY", "UNIQUE", "INDEX"); $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"])) { if (preg_match('~MyISAM|M?aria' . (min_version(5.6, '10.0.5') ? '|InnoDB' : '') . '~i', $table_status["Engine"])) {
$index_types[] = "FULLTEXT"; $index_types[] = "FULLTEXT";
} }

View File

@@ -5,7 +5,7 @@ $TABLE = $_GET["view"];
$row = $_POST; $row = $_POST;
$orig_type = "VIEW"; $orig_type = "VIEW";
if (JUSH == "pgsql" && $TABLE != "") { if (JUSH == "pgsql" && $TABLE != "") {
$status = table_status($TABLE); $status = table_status1($TABLE);
$orig_type = strtoupper($status["Engine"]); $orig_type = strtoupper($status["Engine"]);
} }

View 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"]; $return[$row["TABLE_NAME"]]["keys"][$row["CONSTRAINT_NAME"]][$row["COLUMN_NAME"]] = $row["REFERENCED_COLUMN_NAME"];
} }
foreach ($return as $key => $val) { foreach ($return as $key => $val) {
$name = $this->tableName(table_status($key, true)); $name = $this->tableName(table_status1($key, true));
if ($name != "") { if ($name != "") {
$search = preg_quote($tableName); $search = preg_quote($tableName);
$separator = "(:|\\s*-)?\\s+"; $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)) { if (list($target, $id, $name) = $this->_foreignColumn(column_foreign_keys($table), $column)) {
$return = &$this->values[$target]; $return = &$this->values[$target];
if ($return === null) { 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")); $return = ($table_status["Rows"] > 1000 ? "" : array("" => "") + get_key_vals("SELECT $id, $name FROM " . table($target) . " ORDER BY 2"));
} }
if (!$return && $value !== null) { if (!$return && $value !== null) {

View 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"]; $return[$row["TABLE_NAME"]]["keys"][$row["CONSTRAINT_NAME"]][$row["COLUMN_NAME"]] = $row["REFERENCED_COLUMN_NAME"];
} }
foreach ($return as $key => $val) { 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 != "") { if ($name != "") {
$search = preg_quote($tableName); $search = preg_quote($tableName);
$separator = '(:|\s*-)?\s+'; $separator = '(:|\s*-)?\s+';

View File

@@ -309,9 +309,6 @@ if (isset($_GET["clickhouse"])) {
'Name' => $table['name'], 'Name' => $table['name'],
'Engine' => $table['engine'], 'Engine' => $table['engine'],
); );
if ($name === $table['name']) {
return $return[$table['name']];
}
} }
return $return; return $return;
} }

View File

@@ -384,16 +384,17 @@ if (isset($_GET["elastic"])) {
if ($name != "") { if ($name != "") {
if (isset($stats["indices"][$name])) { if (isset($stats["indices"][$name])) {
return format_index_status($name, $stats["indices"][$name]); return array(format_index_status($name, $stats["indices"][$name]));
} else { } else {
foreach ($aliases as $index_name => $index) { foreach ($aliases as $index_name => $index) {
foreach ($index["aliases"] as $alias_name => $alias) { foreach ($index["aliases"] as $alias_name => $alias) {
if ($alias_name == $name) { 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"]); ksort($stats["indices"]);

View File

@@ -184,16 +184,13 @@ if (isset($_GET["firebird"])) {
function table_status($name = "", $fast = false) { function table_status($name = "", $fast = false) {
$connection = connection(); $connection = connection();
$return = array(); $return = array();
$data = tables_list(); $data = ($name != "" ? array($name => 1) : tables_list());
foreach ($data as $index => $val) { foreach ($data as $index => $val) {
$index = trim($index); $index = trim($index);
$return[$index] = array( $return[$index] = array(
'Name' => $index, 'Name' => $index,
'Engine' => 'standard', 'Engine' => 'standard',
); );
if ($name == $index) {
return $return[$index];
}
} }
return $return; return $return;
} }

View File

@@ -44,7 +44,7 @@ if (isset($_GET["imap"])) {
preg_match_all('~"uid" = (\d+)~', $query, $matches); preg_match_all('~"uid" = (\d+)~', $query, $matches);
return imap_delete($this->imap, implode(",", $matches[1]), FT_UID); return imap_delete($this->imap, implode(",", $matches[1]), FT_UID);
} elseif (preg_match('~^SELECT COUNT\(\*\)\sFROM "(.+?)"~s', $query, $match)) { } 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"]))); return new Result(array(array($status["Rows"])));
} elseif (preg_match('~^SELECT (.+)\sFROM "(.+?)"(?:\sWHERE "uid" = (\d+))?.*?(?:\sLIMIT (\d+)(?:\sOFFSET (\d+))?)?~s', $query, $match)) { } elseif (preg_match('~^SELECT (.+)\sFROM "(.+?)"(?:\sWHERE "uid" = (\d+))?.*?(?:\sLIMIT (\d+)(?:\sOFFSET (\d+))?)?~s', $query, $match)) {
list(, $columns, $table, $uid, $limit, $offset) = $match; list(, $columns, $table, $uid, $limit, $offset) = $match;
@@ -233,11 +233,8 @@ if (isset($_GET["imap"])) {
} }
function table_status($name = "", $fast = false) { function table_status($name = "", $fast = false) {
if ($name != "") {
return connection()->table_status($name, $fast);
}
$return = array(); $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[$table] = connection()->table_status($table, $fast);
} }
return $return; return $return;

View File

@@ -391,11 +391,8 @@ if (isset($_GET["mongo"])) {
function table_status($name = "", $fast = false) { function table_status($name = "", $fast = false) {
$return = array(); $return = array();
foreach (tables_list() as $table => $type) { foreach (($name != "" ? array($name => 1) : tables_list()) as $table => $type) {
$return[$table] = array("Name" => $table); $return[$table] = array("Name" => $table, "Engine" => "");
if ($name == $table) {
return $return[$table];
}
} }
return $return; return $return;
} }

View File

@@ -316,9 +316,6 @@ if (isset($_GET["simpledb"])) {
} }
} }
} }
if ($name != "") {
return $row;
}
$return[$table] = $row; $return[$table] = $row;
} }
return $return; return $return;