Fixed warnings on table structure page and table data page

This commit is contained in:
Lionel Laffineur 2023-12-03 23:04:42 +01:00
parent 4deb8a4085
commit 5f7daff1e0
6 changed files with 132 additions and 106 deletions

View file

@ -544,6 +544,11 @@ if (!defined("DRIVER")) {
$return = array();
foreach (get_rows("SHOW FULL COLUMNS FROM " . table($table)) as $row) {
preg_match('~^([^( ]+)(?:\((.+)\))?( unsigned)?( zerofill)?$~', $row["Type"], $match);
for ($i = 0; $i < 5; $i++) {
if (isset($match[$i]) === false) {
$match[$i] = null;
}
}
$return[$row["Field"]] = array(
"field" => $row["Field"],
"full_type" => $row["Type"],

View file

@ -398,6 +398,7 @@ class Adminer {
}
}
$change_next = "this.parentNode.firstChild.onchange();";
if (isset($_GET["where"])) {
foreach (array_merge((array) $_GET["where"], array(array())) as $i => $val) {
if (!$val || ("$val[col]$val[val]" != "" && in_array($val["op"], $this->operators))) {
echo "<div>" . select_input(
@ -415,6 +416,7 @@ class Adminer {
echo "</div>\n";
}
}
}
echo "</div></fieldset>\n";
}
@ -427,6 +429,7 @@ class Adminer {
function selectOrderPrint($order, $columns, $indexes) {
print_fieldset("sort", lang('Sort'), $order);
$i = 0;
if (isset($_GET["order"])) {
foreach ((array) $_GET["order"] as $key => $val) {
if ($val != "") {
echo "<div>" . select_input(" name='order[$i]'", $columns, $val, "selectFieldChange");
@ -437,6 +440,7 @@ class Adminer {
$i++;
}
}
}
echo "<div>" . select_input(" name='order[$i]'", $columns, "", "selectAddRow");
echo checkbox("desc[$i]", 1, false, lang('descending'));
echo " <input type='image' src='../adminer/static/cross.gif' class='jsonly icon' title='", h(lang('Remove')), "' alt='x'>";
@ -526,6 +530,7 @@ class Adminer {
global $functions, $grouping;
$select = array(); // select expressions, empty for *
$group = array(); // expressions without aggregation - will be used for GROUP BY if an aggregation function is used
if (isset($_GET["columns"])) {
foreach ((array) $_GET["columns"] as $key => $val) {
if ($val["fun"] == "count" || ($val["col"] != "" && (!$val["fun"] || in_array($val["fun"], $functions) || in_array($val["fun"], $grouping)))) {
$select[$key] = apply_sql_function($val["fun"], ($val["col"] != "" ? idf_escape($val["col"]) : "*"));
@ -534,6 +539,7 @@ class Adminer {
}
}
}
}
return array($select, $group);
}
@ -550,6 +556,7 @@ class Adminer {
$return[] = "MATCH (" . implode(", ", array_map('idf_escape', $index["columns"])) . ") AGAINST (" . q($_GET["fulltext"][$i]) . (isset($_GET["boolean"][$i]) ? " IN BOOLEAN MODE" : "") . ")";
}
}
if (isset($_GET["where"])) {
foreach ((array) $_GET["where"] as $key => $val) {
if ("$val[col]$val[val]" != "" && in_array($val["op"], $this->operators)) {
$prefix = "";
@ -586,6 +593,7 @@ class Adminer {
}
}
}
}
return $return;
}
@ -596,6 +604,7 @@ class Adminer {
*/
function selectOrderProcess($fields, $indexes) {
$return = array();
if (isset($_GET["order"])) {
foreach ((array) $_GET["order"] as $key => $val) {
if ($val != "") {
$return[] = (preg_match('~^((COUNT\(DISTINCT |[A-Z0-9_]+\()(`(?:[^`]|``)+`|"(?:[^"]|"")+")\)|COUNT\(\*\))$~', $val) ? $val : idf_escape($val)) //! MS SQL uses []
@ -603,6 +612,7 @@ class Adminer {
;
}
}
}
return $return;
}

View file

@ -80,7 +80,7 @@ var thousandsSeparator = '<?php echo js_escape(lang(',')); ?>';
echo '<a href="' . h($link . "&db=" . urlencode(DB) . (support("scheme") ? "&ns=" : "")) . '">' . h(DB) . '</a> &raquo; ';
}
if (is_array($breadcrumb)) {
if ($_GET["ns"] != "") {
if (isset($_GET["ns"]) && $_GET["ns"] != "") {
echo '<a href="' . h(substr(ME, 0, -1)) . '">' . h($_GET["ns"]) . '</a> &raquo; ';
}
foreach ($breadcrumb as $key => $val) {

View file

@ -47,7 +47,7 @@ function get_driver($id) {
$query = $adminer->selectQueryBuild($select, $where, $group, $order, $limit, $page);
if (!$query) {
$query = "SELECT" . limit(
($_GET["page"] != "last" && $limit != "" && $group && $is_group && $jush == "sql" ? "SQL_CALC_FOUND_ROWS " : "") . implode(", ", $select) . "\nFROM " . table($table),
(isset($_GET["page"]) && $_GET["page"] != "last" && $limit != "" && $group && $is_group && $jush == "sql" ? "SQL_CALC_FOUND_ROWS " : "") . implode(", ", $select) . "\nFROM " . table($table),
($where ? "\nWHERE " . implode(" AND ", $where) : "") . ($group && $is_group ? "\nGROUP BY " . implode(", ", $group) : "") . ($order ? "\nORDER BY " . implode(", ", $order) : ""),
($limit != "" ? +$limit : null),
($page ? $limit * $page : 0),

View file

@ -14,7 +14,7 @@ include "./include/tmpfile.inc.php";
$enum_length = "'(?:''|[^'\\\\]|\\\\.)*'";
$inout = "IN|OUT|INOUT";
if (isset($_GET["select"]) && ($_POST["edit"] || $_POST["clone"]) && !$_POST["save"]) {
if (isset($_GET["select"]) && ((isset($_POST["edit"]) && $_POST["edit"]) || (isset($_POST["clone"]) && $_POST["clone"])) && (isset($_POST["save"]) || !$_POST["save"])) {
$_GET["edit"] = $_GET["select"];
}
if (isset($_GET["callf"])) {

View file

@ -4,8 +4,12 @@ $table_status = table_status1($TABLE);
$indexes = indexes($TABLE);
$fields = fields($TABLE);
$foreign_keys = column_foreign_keys($TABLE);
$oid = $table_status["Oid"];
parse_str($_COOKIE["adminer_import"], $adminer_import);
$oid = (isset($table_status["Oid"]) ? $table_status["Oid"] : null);
if (isset($_COOKIE["adminer_import"])) {
parse_str($_COOKIE["adminer_import"], $adminer_import);
} else {
$adminer_import = [];
}
$rights = array(); // privilege => 0
$columns = array(); // selectable columns
@ -22,12 +26,12 @@ foreach ($fields as $key => $field) {
}
list($select, $group) = $adminer->selectColumnsProcess($columns, $indexes);
$is_group = count($group) < count($select) || strstr($select[0], "DISTINCT");
$is_group = count($group) < count($select) || (isset($select[0]) && strstr($select[0], "DISTINCT"));
$where = $adminer->selectSearchProcess($fields, $indexes);
$order = $adminer->selectOrderProcess($fields, $indexes);
$limit = $adminer->selectLimitProcess();
if ($_GET["val"] && is_ajax()) {
if (isset($_GET["val"]) && $_GET["val"] && is_ajax()) {
header("Content-Type: text/plain; charset=utf-8");
foreach ($_GET["val"] as $unique_idf => $row) {
$as = convert_field($fields[key($row)]);
@ -225,6 +229,7 @@ if (is_ajax()) {
$set = null;
if (isset($rights["insert"]) || !support("table")) {
$set = "";
if (isset($_GET["where"])) {
foreach ((array) $_GET["where"] as $val) {
if ($foreign_keys[$val["col"]] && count($foreign_keys[$val["col"]]) == 1 && ($val["op"] == "="
|| (!$val["op"] && !preg_match('~[_%]~', $val["val"])) // LIKE in Editor
@ -232,6 +237,7 @@ if (isset($rights["insert"]) || !support("table")) {
$set .= "&set" . urlencode("[" . bracket_escape($val["col"]) . "]") . "=" . urlencode($val["val"]);
}
}
}
}
$adminer->selectLinks($table_status, $set);
@ -253,7 +259,7 @@ if (!$columns && support("table")) {
$adminer->selectActionPrint($indexes);
echo "</form>\n";
$page = $_GET["page"];
$page = (isset($_GET["page"]) ? $_GET["page"] : null);
if ($page == "last") {
$found_rows = $connection->result(count_rows($TABLE, $where, $is_group, $group));
$page = floor(max(0, $found_rows - 1) / $limit);
@ -301,7 +307,7 @@ if (!$columns && support("table")) {
}
// use count($rows) without LIMIT, COUNT(*) without grouping, FOUND_ROWS otherwise (slowest)
if ($_GET["page"] != "last" && $limit != "" && $group && $is_group && $jush == "sql") {
if (isset($_GET["page"]) && $_GET["page"] != "last" && $limit != "" && $group && $is_group && $jush == "sql") {
$found_rows = $connection->result(" SELECT FOUND_ROWS()"); // space to allow mysql.trace_mode
}
@ -316,7 +322,7 @@ if (!$columns && support("table")) {
echo "<thead><tr>" . (!$group && $select
? ""
: "<td><input type='checkbox' id='all-page' class='jsonly'>" . script("qs('#all-page').onclick = partial(formCheck, /check/);", "")
. " <a href='" . h($_GET["modify"] ? remove_from_uri("modify") : $_SERVER["REQUEST_URI"] . "&modify=1") . "' title='" . lang('Modify') . "' class='edit-all'>" . lang('Modify') . "</a>");
. " <a href='" . h(isset($_GET["modify"]) && $_GET["modify"] ? remove_from_uri("modify") : $_SERVER["REQUEST_URI"] . "&modify=1") . "' title='" . lang('Modify') . "' class='edit-all'>" . lang('Modify') . "</a>");
$names = array();
$functions = array();
reset($select);
@ -333,7 +339,7 @@ if (!$columns && support("table")) {
$href = remove_from_uri('(order|desc)[^=]*|page') . '&order%5B0%5D=' . urlencode($key);
$desc = "&desc%5B0%5D=1";
echo "<th id='th[" . h(bracket_escape($key)) . "]'>" . script("mixin(qsl('th'), {onmouseover: partial(columnMouse), onmouseout: partial(columnMouse, ' hidden')});", "");
echo '<a href="' . h($href . ($order[0] == $column || $order[0] == $key || (!$order && $is_group && $group[0] == $column) ? $desc : '')) . '">'; // $order[0] == $key - COUNT(*)
echo '<a href="' . h($href . ((isset($order[0]) && $order[0] == $column) || (isset($order[0]) && $order[0] == $key) || (!$order && $is_group && $group[0] == $column) ? $desc : '')) . '">'; // $order[0] == $key - COUNT(*)
echo apply_sql_function($val["fun"] ?? null, $name) . "</a>"; //! columns looking like functions
echo "<span class='column hidden'>";
echo "<a href='" . h($href . $desc) . "' title='" . lang('descending') . "' class='text'> ↓</a>";
@ -349,7 +355,7 @@ if (!$columns && support("table")) {
}
$lengths = array();
if ($_GET["modify"]) {
if (isset($_GET["modify"]) && $_GET["modify"]) {
foreach ($rows as $row) {
foreach ($row as $key => $val) {
$lengths[$key] = max($lengths[$key], min(40, strlen(utf8_decode($val))));
@ -386,7 +392,7 @@ if (!$columns && support("table")) {
$unique_idf .= "&" . ($val !== null ? urlencode("where[" . bracket_escape($key) . "]") . "=" . urlencode($val === false ? "f" : $val) : "null%5B%5D=" . urlencode($key));
}
echo "<tr" . odd() . ">" . (!$group && $select ? "" : "<td>"
. checkbox("check[]", substr($unique_idf, 1), in_array(substr($unique_idf, 1), (array) $_POST["check"]))
. checkbox("check[]", substr($unique_idf, 1), in_array(substr($unique_idf, 1), (array) (isset($_POST["check"]) ? $_POST["check"] : null)))
. ($is_group || information_schema(DB) ? "" : " <a href='" . h(ME . "edit=" . urlencode($TABLE) . $unique_idf) . "' class='edit' title='" . lang('edit') . "'>" . lang('edit') . "</a>")
);
@ -403,6 +409,7 @@ if (!$columns && support("table")) {
$link = ME . 'download=' . urlencode($TABLE) . '&field=' . urlencode($key) . $unique_idf;
}
if (!$link && $val !== null) { // link related items
if (isset($foreign_keys[$key])) {
foreach ((array) $foreign_keys[$key] as $foreign_key) {
if (count($foreign_keys[$key]) == 1 || end($foreign_key["source"]) == $key) {
$link = "";
@ -419,6 +426,7 @@ if (!$columns && support("table")) {
}
}
}
}
if ($key == "COUNT(*)") { //! columns looking like functions
$link = ME . "select=" . urlencode($TABLE);
$i = 0;
@ -441,7 +449,7 @@ if (!$columns && support("table")) {
$editable = !is_array($row[$key]) && is_utf8($val) && $rows[$n][$key] == $row[$key] && !$functions[$key];
$text = preg_match('~text|lob~', $field["type"] ?? null);
echo "<td id='$id'";
if (($_GET["modify"] && $editable) || $value !== null) {
if ((isset($_GET["modify"]) && $_GET["modify"] && $editable) || $value !== null) {
$h_value = h($value !== null ? $value : $row[$key]);
echo ">" . ($text ? "<textarea name='$id' cols='30' rows='" . (substr_count($row[$key], "\n") + 1) . "'>$h_value</textarea>" : "<input name='$id' value='$h_value' size='$lengths[$key]'>");
} else {
@ -471,7 +479,8 @@ if (!$columns && support("table")) {
if (!is_ajax()) {
if ($rows || $page) {
$exact_count = true;
if ($_GET["page"] != "last") {
$found_rows = null;
if (isset($_GET["page"]) && $_GET["page"] != "last") {
if ($limit == "" || (count($rows) < $limit && ($rows || !$page))) {
$found_rows = ($page ? $page * $limit : 0) + count($rows);
} elseif ($jush != "sql" || !$is_group) {
@ -536,8 +545,8 @@ if (!$columns && support("table")) {
if ($adminer->selectCommandPrint()) {
?>
<fieldset<?php echo ($_GET["modify"] ? '' : ' class="jsonly"'); ?>><legend><?php echo lang('Modify'); ?></legend><div>
<input type="submit" value="<?php echo lang('Save'); ?>"<?php echo ($_GET["modify"] ? '' : ' title="' . lang('Ctrl+click on a value to modify it.') . '"'); ?>>
<fieldset<?php echo (isset($_GET["modify"]) && $_GET["modify"] ? '' : ' class="jsonly"'); ?>><legend><?php echo lang('Modify'); ?></legend><div>
<input type="submit" value="<?php echo lang('Save'); ?>"<?php echo (isset($_GET["modify"]) && $_GET["modify"] ? '' : ' title="' . lang('Ctrl+click on a value to modify it.') . '"'); ?>>
</div></fieldset>
<fieldset><legend><?php echo lang('Selected'); ?> <span id="selected"></span></legend><div>
<input type="submit" name="edit" value="<?php echo lang('Edit'); ?>">
@ -548,17 +557,19 @@ if (!$columns && support("table")) {
}
$format = $adminer->dumpFormat();
if (isset($_GET["columns"])) {
foreach ((array) $_GET["columns"] as $column) {
if ($column["fun"]) {
unset($format['sql']);
break;
}
}
}
if ($format) {
print_fieldset("export", lang('Export') . " <span id='selected2'></span>");
$output = $adminer->dumpOutput();
echo ($output ? html_select("output", $output, $adminer_import["output"]) . " " : "");
echo html_select("format", $format, $adminer_import["format"]);
echo ($output ? html_select("output", $output, (isset($adminer_import["output"]) ? $adminer_import["output"] : null)) . " " : "");
echo html_select("format", $format, (isset($adminer_import["format"]) ? $adminer_import["format"] : null));
echo " <input type='submit' name='export' value='" . lang('Export') . "'>\n";
echo "</div></fieldset>\n";
}
@ -574,7 +585,7 @@ if (!$columns && support("table")) {
echo script("qsl('a').onclick = partial(toggle, 'import');", "");
echo "<span id='import' class='hidden'>: ";
echo "<input type='file' name='csv_file'> ";
echo html_select("separator", array("csv" => "CSV,", "csv;" => "CSV;", "tsv" => "TSV"), $adminer_import["format"], 1); // 1 - select
echo html_select("separator", array("csv" => "CSV,", "csv;" => "CSV;", "tsv" => "TSV"), (isset($adminer_import["format"]) ? $adminer_import["format"] : null), 1); // 1 - select
echo " <input type='submit' name='import' value='" . lang('Import') . "'>";
echo "</span>";
echo "</div>";